^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * The driver for the Yamaha's DS1/DS1E cards
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "ymfpci.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <sound/mpu401.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <sound/opl3.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) MODULE_DESCRIPTION("Yamaha DS-1 PCI");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) MODULE_SUPPORTED_DEVICE("{{Yamaha,YMF724},"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) "{Yamaha,YMF724F},"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) "{Yamaha,YMF740},"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) "{Yamaha,YMF740C},"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) "{Yamaha,YMF744},"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) "{Yamaha,YMF754}}");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static long fm_port[SNDRV_CARDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static long mpu_port[SNDRV_CARDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #ifdef SUPPORT_JOYSTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) static long joystick_port[SNDRV_CARDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static bool rear_switch[SNDRV_CARDS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) module_param_array(index, int, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) MODULE_PARM_DESC(index, "Index value for the Yamaha DS-1 PCI soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) module_param_array(id, charp, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) MODULE_PARM_DESC(id, "ID string for the Yamaha DS-1 PCI soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) module_param_array(enable, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) MODULE_PARM_DESC(enable, "Enable Yamaha DS-1 soundcard.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) module_param_hw_array(mpu_port, long, ioport, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) MODULE_PARM_DESC(mpu_port, "MPU-401 Port.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) module_param_hw_array(fm_port, long, ioport, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) MODULE_PARM_DESC(fm_port, "FM OPL-3 Port.");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) #ifdef SUPPORT_JOYSTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) module_param_hw_array(joystick_port, long, ioport, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) MODULE_PARM_DESC(joystick_port, "Joystick port address");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) module_param_array(rear_switch, bool, NULL, 0444);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) MODULE_PARM_DESC(rear_switch, "Enable shared rear/line-in switch");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) static const struct pci_device_id snd_ymfpci_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) { PCI_VDEVICE(YAMAHA, 0x0004), 0, }, /* YMF724 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) { PCI_VDEVICE(YAMAHA, 0x000d), 0, }, /* YMF724F */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) { PCI_VDEVICE(YAMAHA, 0x000a), 0, }, /* YMF740 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) { PCI_VDEVICE(YAMAHA, 0x000c), 0, }, /* YMF740C */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) { PCI_VDEVICE(YAMAHA, 0x0010), 0, }, /* YMF744 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) { PCI_VDEVICE(YAMAHA, 0x0012), 0, }, /* YMF754 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { 0, }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) MODULE_DEVICE_TABLE(pci, snd_ymfpci_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) #ifdef SUPPORT_JOYSTICK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) static int snd_ymfpci_create_gameport(struct snd_ymfpci *chip, int dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) int legacy_ctrl, int legacy_ctrl2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) struct gameport *gp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) struct resource *r = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) int io_port = joystick_port[dev];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) if (!io_port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) if (chip->pci->device >= 0x0010) { /* YMF 744/754 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) if (io_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) /* auto-detect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) if (!(io_port = pci_resource_start(chip->pci, 2)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) if (io_port == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) /* auto-detect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) for (io_port = 0x201; io_port <= 0x205; io_port++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) if (io_port == 0x203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) if ((r = request_region(io_port, 1, "YMFPCI gameport")) != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) if (!r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) dev_err(chip->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) "no gameport ports available\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) switch (io_port) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) case 0x201: legacy_ctrl2 |= 0 << 6; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) case 0x202: legacy_ctrl2 |= 1 << 6; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) case 0x204: legacy_ctrl2 |= 2 << 6; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) case 0x205: legacy_ctrl2 |= 3 << 6; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) dev_err(chip->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) "invalid joystick port %#x", io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) if (!r && !(r = request_region(io_port, 1, "YMFPCI gameport"))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) dev_err(chip->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) "joystick port %#x is in use.\n", io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) return -EBUSY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) chip->gameport = gp = gameport_allocate_port();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if (!gp) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) dev_err(chip->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) "cannot allocate memory for gameport\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) release_and_free_resource(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) gameport_set_name(gp, "Yamaha YMF Gameport");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) gameport_set_dev_parent(gp, &chip->pci->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) gp->io = io_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) gameport_set_port_data(gp, r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (chip->pci->device >= 0x0010) /* YMF 744/754 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) pci_write_config_word(chip->pci, PCIR_DSXG_JOYBASE, io_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) pci_write_config_word(chip->pci, PCIR_DSXG_LEGACY, legacy_ctrl | YMFPCI_LEGACY_JPEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) pci_write_config_word(chip->pci, PCIR_DSXG_ELEGACY, legacy_ctrl2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) gameport_register_port(chip->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) void snd_ymfpci_free_gameport(struct snd_ymfpci *chip)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) if (chip->gameport) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) struct resource *r = gameport_get_port_data(chip->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) gameport_unregister_port(chip->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) chip->gameport = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) release_and_free_resource(r);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static inline int snd_ymfpci_create_gameport(struct snd_ymfpci *chip, int dev, int l, int l2) { return -ENOSYS; }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) void snd_ymfpci_free_gameport(struct snd_ymfpci *chip) { }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) #endif /* SUPPORT_JOYSTICK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) static int snd_card_ymfpci_probe(struct pci_dev *pci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) const struct pci_device_id *pci_id)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static int dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct snd_card *card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct resource *fm_res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) struct resource *mpu_res = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) struct snd_ymfpci *chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) struct snd_opl3 *opl3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) const char *str, *model;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) u16 legacy_ctrl, legacy_ctrl2, old_legacy_ctrl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) if (dev >= SNDRV_CARDS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) if (!enable[dev]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) dev++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) return -ENOENT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 0, &card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) switch (pci_id->device) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) case 0x0004: str = "YMF724"; model = "DS-1"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) case 0x000d: str = "YMF724F"; model = "DS-1"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) case 0x000a: str = "YMF740"; model = "DS-1L"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) case 0x000c: str = "YMF740C"; model = "DS-1L"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) case 0x0010: str = "YMF744"; model = "DS-1S"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) case 0x0012: str = "YMF754"; model = "DS-1E"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) default: model = str = "???"; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) legacy_ctrl = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) legacy_ctrl2 = 0x0800; /* SBEN = 0, SMOD = 01, LAD = 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) if (pci_id->device >= 0x0010) { /* YMF 744/754 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if (fm_port[dev] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) /* auto-detect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) fm_port[dev] = pci_resource_start(pci, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) if (fm_port[dev] > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) legacy_ctrl |= YMFPCI_LEGACY_FMEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) pci_write_config_word(pci, PCIR_DSXG_FMBASE, fm_port[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) if (mpu_port[dev] == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /* auto-detect */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) mpu_port[dev] = pci_resource_start(pci, 1) + 0x20;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) if (mpu_port[dev] > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) legacy_ctrl |= YMFPCI_LEGACY_MEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) pci_write_config_word(pci, PCIR_DSXG_MPU401BASE, mpu_port[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) switch (fm_port[dev]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) case 0x388: legacy_ctrl2 |= 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) case 0x398: legacy_ctrl2 |= 1; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) case 0x3a0: legacy_ctrl2 |= 2; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) case 0x3a8: legacy_ctrl2 |= 3; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) default: fm_port[dev] = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) if (fm_port[dev] > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) (fm_res = request_region(fm_port[dev], 4, "YMFPCI OPL3")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) legacy_ctrl |= YMFPCI_LEGACY_FMEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) legacy_ctrl2 &= ~YMFPCI_LEGACY2_FMIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) fm_port[dev] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) switch (mpu_port[dev]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) case 0x330: legacy_ctrl2 |= 0 << 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) case 0x300: legacy_ctrl2 |= 1 << 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) case 0x332: legacy_ctrl2 |= 2 << 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) case 0x334: legacy_ctrl2 |= 3 << 4; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) default: mpu_port[dev] = 0; break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) if (mpu_port[dev] > 0 &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) (mpu_res = request_region(mpu_port[dev], 2, "YMFPCI MPU401")) != NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) legacy_ctrl |= YMFPCI_LEGACY_MEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) legacy_ctrl2 &= ~YMFPCI_LEGACY2_MPUIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) mpu_port[dev] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) if (mpu_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) legacy_ctrl |= YMFPCI_LEGACY_MIEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) legacy_ctrl2 |= YMFPCI_LEGACY2_IMOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) pci_read_config_word(pci, PCIR_DSXG_LEGACY, &old_legacy_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) pci_write_config_word(pci, PCIR_DSXG_ELEGACY, legacy_ctrl2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) if ((err = snd_ymfpci_create(card, pci,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) old_legacy_ctrl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) &chip)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) release_and_free_resource(mpu_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) release_and_free_resource(fm_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) chip->fm_res = fm_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) chip->mpu_res = mpu_res;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) card->private_data = chip;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) strcpy(card->driver, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) sprintf(card->shortname, "Yamaha %s (%s)", model, str);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) sprintf(card->longname, "%s at 0x%lx, irq %i",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) card->shortname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) chip->reg_area_phys,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) chip->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) err = snd_ymfpci_pcm(chip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) err = snd_ymfpci_pcm_spdif(chip, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) err = snd_ymfpci_mixer(chip, rear_switch[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) if (chip->ac97->ext_id & AC97_EI_SDAC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) err = snd_ymfpci_pcm_4ch(chip, 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) err = snd_ymfpci_pcm2(chip, 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) err = snd_ymfpci_timer(chip, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) if (chip->mpu_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) mpu_port[dev],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) MPU401_INFO_INTEGRATED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) MPU401_INFO_IRQ_HOOK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) -1, &chip->rawmidi)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) dev_warn(card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) "cannot initialize MPU401 at 0x%lx, skipping...\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) mpu_port[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) if (chip->fm_res) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) if ((err = snd_opl3_create(card,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) fm_port[dev],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) fm_port[dev] + 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) OPL3_HW_OPL3, 1, &opl3)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) dev_warn(card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) "cannot initialize FM OPL3 at 0x%lx, skipping...\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) fm_port[dev]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) legacy_ctrl &= ~YMFPCI_LEGACY_FMEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) } else if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) dev_err(card->dev, "cannot create opl3 hwdep\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) snd_ymfpci_create_gameport(chip, dev, legacy_ctrl, legacy_ctrl2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) err = snd_card_register(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) goto free_card;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) pci_set_drvdata(pci, card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) dev++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) free_card:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) snd_card_free(card);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) static void snd_card_ymfpci_remove(struct pci_dev *pci)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) snd_card_free(pci_get_drvdata(pci));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) static struct pci_driver ymfpci_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) .name = KBUILD_MODNAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) .id_table = snd_ymfpci_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) .probe = snd_card_ymfpci_probe,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) .remove = snd_card_ymfpci_remove,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) #ifdef CONFIG_PM_SLEEP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) .pm = &snd_ymfpci_pm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) module_pci_driver(ymfpci_driver);