1 // SPDX-License-Identifier: GPL-2.0-or-later 1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 2 /* 3 * Driver for Yamaha OPL3-SA[2,3] soundcards 3 * Driver for Yamaha OPL3-SA[2,3] soundcards 4 * Copyright (c) by Jaroslav Kysela <perex@pe 4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz> 5 */ 5 */ 6 6 7 #include <linux/init.h> 7 #include <linux/init.h> 8 #include <linux/err.h> 8 #include <linux/err.h> 9 #include <linux/isa.h> 9 #include <linux/isa.h> 10 #include <linux/interrupt.h> 10 #include <linux/interrupt.h> 11 #include <linux/pm.h> 11 #include <linux/pm.h> 12 #include <linux/pnp.h> 12 #include <linux/pnp.h> 13 #include <linux/module.h> 13 #include <linux/module.h> 14 #include <linux/io.h> 14 #include <linux/io.h> 15 #include <sound/core.h> 15 #include <sound/core.h> 16 #include <sound/wss.h> 16 #include <sound/wss.h> 17 #include <sound/mpu401.h> 17 #include <sound/mpu401.h> 18 #include <sound/opl3.h> 18 #include <sound/opl3.h> 19 #include <sound/initval.h> 19 #include <sound/initval.h> 20 #include <sound/tlv.h> 20 #include <sound/tlv.h> 21 21 22 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz 22 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 23 MODULE_DESCRIPTION("Yamaha OPL3SA2+"); 23 MODULE_DESCRIPTION("Yamaha OPL3SA2+"); 24 MODULE_LICENSE("GPL"); 24 MODULE_LICENSE("GPL"); >> 25 MODULE_SUPPORTED_DEVICE("{{Yamaha,YMF719E-S}," >> 26 "{Genius,Sound Maker 3DX}," >> 27 "{Yamaha,OPL3SA3}," >> 28 "{Intel,AL440LX sound}," >> 29 "{NeoMagic,MagicWave 3DX}}"); 25 30 26 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_ 31 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 27 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_S 32 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 28 static bool enable[SNDRV_CARDS] = SNDRV_DEFAUL 33 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */ 29 #ifdef CONFIG_PNP 34 #ifdef CONFIG_PNP 30 static bool isapnp[SNDRV_CARDS] = {[0 ... (SND 35 static bool isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; 31 #endif 36 #endif 32 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_ 37 static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0xf86,0x370,0x100 */ 33 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAU 38 static long sb_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */ 34 static long wss_port[SNDRV_CARDS] = SNDRV_DEFA 39 static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x530,0xe80,0xf40,0x604 */ 35 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAU 40 static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x388 */ 36 static long midi_port[SNDRV_CARDS] = SNDRV_DEF 41 static long midi_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;/* 0x330,0x300 */ 37 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IR 42 static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 0,1,3,5,9,11,12,15 */ 38 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_D 43 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ 39 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_D 44 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3,5,6,7 */ 40 static int opl3sa3_ymode[SNDRV_CARDS]; /* 0, 45 static int opl3sa3_ymode[SNDRV_CARDS]; /* 0,1,2,3 */ /*SL Added*/ 41 46 42 module_param_array(index, int, NULL, 0444); 47 module_param_array(index, int, NULL, 0444); 43 MODULE_PARM_DESC(index, "Index value for OPL3- 48 MODULE_PARM_DESC(index, "Index value for OPL3-SA soundcard."); 44 module_param_array(id, charp, NULL, 0444); 49 module_param_array(id, charp, NULL, 0444); 45 MODULE_PARM_DESC(id, "ID string for OPL3-SA so 50 MODULE_PARM_DESC(id, "ID string for OPL3-SA soundcard."); 46 module_param_array(enable, bool, NULL, 0444); 51 module_param_array(enable, bool, NULL, 0444); 47 MODULE_PARM_DESC(enable, "Enable OPL3-SA sound 52 MODULE_PARM_DESC(enable, "Enable OPL3-SA soundcard."); 48 #ifdef CONFIG_PNP 53 #ifdef CONFIG_PNP 49 module_param_array(isapnp, bool, NULL, 0444); 54 module_param_array(isapnp, bool, NULL, 0444); 50 MODULE_PARM_DESC(isapnp, "PnP detection for sp 55 MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard."); 51 #endif 56 #endif 52 module_param_hw_array(port, long, ioport, NULL 57 module_param_hw_array(port, long, ioport, NULL, 0444); 53 MODULE_PARM_DESC(port, "Port # for OPL3-SA dri 58 MODULE_PARM_DESC(port, "Port # for OPL3-SA driver."); 54 module_param_hw_array(sb_port, long, ioport, N 59 module_param_hw_array(sb_port, long, ioport, NULL, 0444); 55 MODULE_PARM_DESC(sb_port, "SB port # for OPL3- 60 MODULE_PARM_DESC(sb_port, "SB port # for OPL3-SA driver."); 56 module_param_hw_array(wss_port, long, ioport, 61 module_param_hw_array(wss_port, long, ioport, NULL, 0444); 57 MODULE_PARM_DESC(wss_port, "WSS port # for OPL 62 MODULE_PARM_DESC(wss_port, "WSS port # for OPL3-SA driver."); 58 module_param_hw_array(fm_port, long, ioport, N 63 module_param_hw_array(fm_port, long, ioport, NULL, 0444); 59 MODULE_PARM_DESC(fm_port, "FM port # for OPL3- 64 MODULE_PARM_DESC(fm_port, "FM port # for OPL3-SA driver."); 60 module_param_hw_array(midi_port, long, ioport, 65 module_param_hw_array(midi_port, long, ioport, NULL, 0444); 61 MODULE_PARM_DESC(midi_port, "MIDI port # for O 66 MODULE_PARM_DESC(midi_port, "MIDI port # for OPL3-SA driver."); 62 module_param_hw_array(irq, int, irq, NULL, 044 67 module_param_hw_array(irq, int, irq, NULL, 0444); 63 MODULE_PARM_DESC(irq, "IRQ # for OPL3-SA drive 68 MODULE_PARM_DESC(irq, "IRQ # for OPL3-SA driver."); 64 module_param_hw_array(dma1, int, dma, NULL, 04 69 module_param_hw_array(dma1, int, dma, NULL, 0444); 65 MODULE_PARM_DESC(dma1, "DMA1 # for OPL3-SA dri 70 MODULE_PARM_DESC(dma1, "DMA1 # for OPL3-SA driver."); 66 module_param_hw_array(dma2, int, dma, NULL, 04 71 module_param_hw_array(dma2, int, dma, NULL, 0444); 67 MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA dri 72 MODULE_PARM_DESC(dma2, "DMA2 # for OPL3-SA driver."); 68 module_param_array(opl3sa3_ymode, int, NULL, 0 73 module_param_array(opl3sa3_ymode, int, NULL, 0444); 69 MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size 74 MODULE_PARM_DESC(opl3sa3_ymode, "Speaker size selection for 3D Enhancement mode: Desktop/Large Notebook/Small Notebook/HiFi."); 70 75 71 #ifdef CONFIG_PNP 76 #ifdef CONFIG_PNP 72 static int isa_registered; 77 static int isa_registered; 73 static int pnp_registered; 78 static int pnp_registered; 74 static int pnpc_registered; 79 static int pnpc_registered; 75 #endif 80 #endif 76 81 77 /* control ports */ 82 /* control ports */ 78 #define OPL3SA2_PM_CTRL 0x01 83 #define OPL3SA2_PM_CTRL 0x01 79 #define OPL3SA2_SYS_CTRL 0x02 84 #define OPL3SA2_SYS_CTRL 0x02 80 #define OPL3SA2_IRQ_CONFIG 0x03 85 #define OPL3SA2_IRQ_CONFIG 0x03 81 #define OPL3SA2_IRQ_STATUS 0x04 86 #define OPL3SA2_IRQ_STATUS 0x04 82 #define OPL3SA2_DMA_CONFIG 0x06 87 #define OPL3SA2_DMA_CONFIG 0x06 83 #define OPL3SA2_MASTER_LEFT 0x07 88 #define OPL3SA2_MASTER_LEFT 0x07 84 #define OPL3SA2_MASTER_RIGHT 0x08 89 #define OPL3SA2_MASTER_RIGHT 0x08 85 #define OPL3SA2_MIC 0x09 90 #define OPL3SA2_MIC 0x09 86 #define OPL3SA2_MISC 0x0A 91 #define OPL3SA2_MISC 0x0A 87 92 88 /* opl3sa3 only */ 93 /* opl3sa3 only */ 89 #define OPL3SA3_DGTL_DOWN 0x12 94 #define OPL3SA3_DGTL_DOWN 0x12 90 #define OPL3SA3_ANLG_DOWN 0x13 95 #define OPL3SA3_ANLG_DOWN 0x13 91 #define OPL3SA3_WIDE 0x14 96 #define OPL3SA3_WIDE 0x14 92 #define OPL3SA3_BASS 0x15 97 #define OPL3SA3_BASS 0x15 93 #define OPL3SA3_TREBLE 0x16 98 #define OPL3SA3_TREBLE 0x16 94 99 95 /* power management bits */ 100 /* power management bits */ 96 #define OPL3SA2_PM_ADOWN 0x20 101 #define OPL3SA2_PM_ADOWN 0x20 97 #define OPL3SA2_PM_PSV 0x04 102 #define OPL3SA2_PM_PSV 0x04 98 #define OPL3SA2_PM_PDN 0x02 103 #define OPL3SA2_PM_PDN 0x02 99 #define OPL3SA2_PM_PDX 0x01 104 #define OPL3SA2_PM_PDX 0x01 100 105 101 #define OPL3SA2_PM_D0 0x00 106 #define OPL3SA2_PM_D0 0x00 102 #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3 107 #define OPL3SA2_PM_D3 (OPL3SA2_PM_ADOWN|OPL3SA2_PM_PSV|OPL3SA2_PM_PDN|OPL3SA2_PM_PDX) 103 108 104 struct snd_opl3sa2 { 109 struct snd_opl3sa2 { 105 int version; /* 2 or 3 */ 110 int version; /* 2 or 3 */ 106 unsigned long port; /* control por 111 unsigned long port; /* control port */ 107 struct resource *res_port; /* control 112 struct resource *res_port; /* control port resource */ 108 int irq; 113 int irq; 109 int single_dma; 114 int single_dma; 110 spinlock_t reg_lock; 115 spinlock_t reg_lock; 111 struct snd_card *card; << 112 struct snd_hwdep *synth; 116 struct snd_hwdep *synth; 113 struct snd_rawmidi *rmidi; 117 struct snd_rawmidi *rmidi; 114 struct snd_wss *wss; 118 struct snd_wss *wss; 115 unsigned char ctlregs[0x20]; 119 unsigned char ctlregs[0x20]; 116 int ymode; /* SL added */ 120 int ymode; /* SL added */ 117 struct snd_kcontrol *master_switch; 121 struct snd_kcontrol *master_switch; 118 struct snd_kcontrol *master_volume; 122 struct snd_kcontrol *master_volume; 119 }; 123 }; 120 124 121 #define PFX "opl3sa2: " 125 #define PFX "opl3sa2: " 122 126 123 #ifdef CONFIG_PNP 127 #ifdef CONFIG_PNP 124 128 125 static const struct pnp_device_id snd_opl3sa2_ 129 static const struct pnp_device_id snd_opl3sa2_pnpbiosids[] = { 126 { .id = "YMH0021" }, 130 { .id = "YMH0021" }, 127 { .id = "NMX2210" }, /* Gateway Sol 131 { .id = "NMX2210" }, /* Gateway Solo 2500 */ 128 { .id = "" } /* end */ 132 { .id = "" } /* end */ 129 }; 133 }; 130 134 131 MODULE_DEVICE_TABLE(pnp, snd_opl3sa2_pnpbiosid 135 MODULE_DEVICE_TABLE(pnp, snd_opl3sa2_pnpbiosids); 132 136 133 static const struct pnp_card_device_id snd_opl 137 static const struct pnp_card_device_id snd_opl3sa2_pnpids[] = { 134 /* Yamaha YMF719E-S (Genius Sound Make 138 /* Yamaha YMF719E-S (Genius Sound Maker 3DX) */ 135 { .id = "YMH0020", .devs = { { "YMH002 139 { .id = "YMH0020", .devs = { { "YMH0021" } } }, 136 /* Yamaha OPL3-SA3 (integrated on Inte 140 /* Yamaha OPL3-SA3 (integrated on Intel's Pentium II AL440LX motherboard) */ 137 { .id = "YMH0030", .devs = { { "YMH002 141 { .id = "YMH0030", .devs = { { "YMH0021" } } }, 138 /* Yamaha OPL3-SA2 */ 142 /* Yamaha OPL3-SA2 */ 139 { .id = "YMH0800", .devs = { { "YMH002 143 { .id = "YMH0800", .devs = { { "YMH0021" } } }, 140 /* Yamaha OPL3-SA2 */ 144 /* Yamaha OPL3-SA2 */ 141 { .id = "YMH0801", .devs = { { "YMH002 145 { .id = "YMH0801", .devs = { { "YMH0021" } } }, 142 /* NeoMagic MagicWave 3DX */ 146 /* NeoMagic MagicWave 3DX */ 143 { .id = "NMX2200", .devs = { { "YMH221 147 { .id = "NMX2200", .devs = { { "YMH2210" } } }, 144 /* NeoMagic MagicWave 3D */ 148 /* NeoMagic MagicWave 3D */ 145 { .id = "NMX2200", .devs = { { "NMX221 149 { .id = "NMX2200", .devs = { { "NMX2210" } } }, 146 /* --- */ 150 /* --- */ 147 { .id = "" } /* end */ 151 { .id = "" } /* end */ 148 }; 152 }; 149 153 150 MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpi 154 MODULE_DEVICE_TABLE(pnp_card, snd_opl3sa2_pnpids); 151 155 152 #endif /* CONFIG_PNP */ 156 #endif /* CONFIG_PNP */ 153 157 154 158 155 /* read control port (w/o spinlock) */ 159 /* read control port (w/o spinlock) */ 156 static unsigned char __snd_opl3sa2_read(struct 160 static unsigned char __snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) 157 { 161 { 158 unsigned char result; 162 unsigned char result; 159 #if 0 163 #if 0 160 outb(0x1d, port); /* password */ 164 outb(0x1d, port); /* password */ 161 dev_dbg(chip->card->dev, "read [0x%lx] !! 165 printk(KERN_DEBUG "read [0x%lx] = 0x%x\n", port, inb(port)); 162 #endif 166 #endif 163 outb(reg, chip->port); /* register */ 167 outb(reg, chip->port); /* register */ 164 result = inb(chip->port + 1); 168 result = inb(chip->port + 1); 165 #if 0 169 #if 0 166 dev_dbg(chip->card->dev, "read [0x%lx] !! 170 printk(KERN_DEBUG "read [0x%lx] = 0x%x [0x%x]\n", 167 port, result, inb(port)); 171 port, result, inb(port)); 168 #endif 172 #endif 169 return result; 173 return result; 170 } 174 } 171 175 172 /* read control port (with spinlock) */ 176 /* read control port (with spinlock) */ 173 static unsigned char snd_opl3sa2_read(struct s 177 static unsigned char snd_opl3sa2_read(struct snd_opl3sa2 *chip, unsigned char reg) 174 { 178 { 175 unsigned long flags; 179 unsigned long flags; 176 unsigned char result; 180 unsigned char result; 177 181 178 spin_lock_irqsave(&chip->reg_lock, fla 182 spin_lock_irqsave(&chip->reg_lock, flags); 179 result = __snd_opl3sa2_read(chip, reg) 183 result = __snd_opl3sa2_read(chip, reg); 180 spin_unlock_irqrestore(&chip->reg_lock 184 spin_unlock_irqrestore(&chip->reg_lock, flags); 181 return result; 185 return result; 182 } 186 } 183 187 184 /* write control port (w/o spinlock) */ 188 /* write control port (w/o spinlock) */ 185 static void __snd_opl3sa2_write(struct snd_opl 189 static void __snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) 186 { 190 { 187 #if 0 191 #if 0 188 outb(0x1d, port); /* password */ 192 outb(0x1d, port); /* password */ 189 #endif 193 #endif 190 outb(reg, chip->port); /* register */ 194 outb(reg, chip->port); /* register */ 191 outb(value, chip->port + 1); 195 outb(value, chip->port + 1); 192 chip->ctlregs[reg] = value; 196 chip->ctlregs[reg] = value; 193 } 197 } 194 198 195 /* write control port (with spinlock) */ 199 /* write control port (with spinlock) */ 196 static void snd_opl3sa2_write(struct snd_opl3s 200 static void snd_opl3sa2_write(struct snd_opl3sa2 *chip, unsigned char reg, unsigned char value) 197 { 201 { 198 unsigned long flags; 202 unsigned long flags; 199 spin_lock_irqsave(&chip->reg_lock, fla 203 spin_lock_irqsave(&chip->reg_lock, flags); 200 __snd_opl3sa2_write(chip, reg, value); 204 __snd_opl3sa2_write(chip, reg, value); 201 spin_unlock_irqrestore(&chip->reg_lock 205 spin_unlock_irqrestore(&chip->reg_lock, flags); 202 } 206 } 203 207 204 static int snd_opl3sa2_detect(struct snd_card 208 static int snd_opl3sa2_detect(struct snd_card *card) 205 { 209 { 206 struct snd_opl3sa2 *chip = card->priva 210 struct snd_opl3sa2 *chip = card->private_data; 207 unsigned long port; 211 unsigned long port; 208 unsigned char tmp, tmp1; 212 unsigned char tmp, tmp1; 209 char str[2]; 213 char str[2]; 210 214 211 port = chip->port; 215 port = chip->port; 212 chip->res_port = devm_request_region(c !! 216 if ((chip->res_port = request_region(port, 2, "OPL3-SA control")) == NULL) { 213 " !! 217 snd_printk(KERN_ERR PFX "can't grab port 0x%lx\n", port); 214 if (!chip->res_port) { << 215 dev_err(card->dev, "can't grab << 216 return -EBUSY; 218 return -EBUSY; 217 } 219 } >> 220 /* >> 221 snd_printk(KERN_DEBUG "REG 0A = 0x%x\n", >> 222 snd_opl3sa2_read(chip, 0x0a)); >> 223 */ 218 chip->version = 0; 224 chip->version = 0; 219 tmp = snd_opl3sa2_read(chip, OPL3SA2_M 225 tmp = snd_opl3sa2_read(chip, OPL3SA2_MISC); 220 if (tmp == 0xff) { 226 if (tmp == 0xff) { 221 dev_dbg(card->dev, "OPL3-SA [0 !! 227 snd_printd("OPL3-SA [0x%lx] detect = 0x%x\n", port, tmp); 222 return -ENODEV; 228 return -ENODEV; 223 } 229 } 224 switch (tmp & 0x07) { 230 switch (tmp & 0x07) { 225 case 0x01: 231 case 0x01: 226 chip->version = 2; /* YMF711 * 232 chip->version = 2; /* YMF711 */ 227 break; 233 break; 228 default: 234 default: 229 chip->version = 3; 235 chip->version = 3; 230 /* 0x02 - standard */ 236 /* 0x02 - standard */ 231 /* 0x03 - YM715B */ 237 /* 0x03 - YM715B */ 232 /* 0x04 - YM719 - OPL-SA4? */ 238 /* 0x04 - YM719 - OPL-SA4? */ 233 /* 0x05 - OPL3-SA3 - Libretto 239 /* 0x05 - OPL3-SA3 - Libretto 100 */ 234 /* 0x07 - unknown - Neomagic M 240 /* 0x07 - unknown - Neomagic MagicWave 3D */ 235 break; 241 break; 236 } 242 } 237 str[0] = chip->version + ''; 243 str[0] = chip->version + ''; 238 str[1] = 0; 244 str[1] = 0; 239 strcat(card->shortname, str); 245 strcat(card->shortname, str); 240 snd_opl3sa2_write(chip, OPL3SA2_MISC, 246 snd_opl3sa2_write(chip, OPL3SA2_MISC, tmp ^ 7); 241 tmp1 = snd_opl3sa2_read(chip, OPL3SA2_ !! 247 if ((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MISC)) != tmp) { 242 if (tmp1 != tmp) { !! 248 snd_printd("OPL3-SA [0x%lx] detect (1) = 0x%x (0x%x)\n", port, tmp, tmp1); 243 dev_dbg(card->dev, "OPL3-SA [0 << 244 return -ENODEV; 249 return -ENODEV; 245 } 250 } 246 /* try if the MIC register is accessib 251 /* try if the MIC register is accessible */ 247 tmp = snd_opl3sa2_read(chip, OPL3SA2_M 252 tmp = snd_opl3sa2_read(chip, OPL3SA2_MIC); 248 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0 253 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x8a); 249 tmp1 = snd_opl3sa2_read(chip, OPL3SA2_ !! 254 if (((tmp1 = snd_opl3sa2_read(chip, OPL3SA2_MIC)) & 0x9f) != 0x8a) { 250 if ((tmp1 & 0x9f) != 0x8a) { !! 255 snd_printd("OPL3-SA [0x%lx] detect (2) = 0x%x (0x%x)\n", port, tmp, tmp1); 251 dev_dbg(card->dev, "OPL3-SA [0 << 252 return -ENODEV; 256 return -ENODEV; 253 } 257 } 254 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0 258 snd_opl3sa2_write(chip, OPL3SA2_MIC, 0x9f); 255 /* initialization */ 259 /* initialization */ 256 /* Power Management - full on */ 260 /* Power Management - full on */ 257 snd_opl3sa2_write(chip, OPL3SA2_PM_CTR 261 snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0); 258 if (chip->version > 2) { 262 if (chip->version > 2) { 259 /* ymode is bits 4&5 (of 0 to 263 /* ymode is bits 4&5 (of 0 to 7) on all but opl3sa2 versions */ 260 snd_opl3sa2_write(chip, OPL3SA 264 snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, (chip->ymode << 4)); 261 } else { 265 } else { 262 /* default for opl3sa2 version 266 /* default for opl3sa2 versions */ 263 snd_opl3sa2_write(chip, OPL3SA 267 snd_opl3sa2_write(chip, OPL3SA2_SYS_CTRL, 0x00); 264 } 268 } 265 snd_opl3sa2_write(chip, OPL3SA2_IRQ_CO 269 snd_opl3sa2_write(chip, OPL3SA2_IRQ_CONFIG, 0x0d); /* Interrupt Channel Configuration - IRQ A = OPL3 + MPU + WSS */ 266 if (chip->single_dma) { 270 if (chip->single_dma) { 267 snd_opl3sa2_write(chip, OPL3SA 271 snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x03); /* DMA Configuration - DMA A = WSS-R + WSS-P */ 268 } else { 272 } else { 269 snd_opl3sa2_write(chip, OPL3SA 273 snd_opl3sa2_write(chip, OPL3SA2_DMA_CONFIG, 0x21); /* DMA Configuration - DMA B = WSS-R, DMA A = WSS-P */ 270 } 274 } 271 snd_opl3sa2_write(chip, OPL3SA2_MISC, 275 snd_opl3sa2_write(chip, OPL3SA2_MISC, 0x80 | (tmp & 7)); /* Miscellaneous - default */ 272 if (chip->version > 2) { 276 if (chip->version > 2) { 273 snd_opl3sa2_write(chip, OPL3SA 277 snd_opl3sa2_write(chip, OPL3SA3_DGTL_DOWN, 0x00); /* Digital Block Partial Power Down - default */ 274 snd_opl3sa2_write(chip, OPL3SA 278 snd_opl3sa2_write(chip, OPL3SA3_ANLG_DOWN, 0x00); /* Analog Block Partial Power Down - default */ 275 } 279 } 276 return 0; 280 return 0; 277 } 281 } 278 282 279 static irqreturn_t snd_opl3sa2_interrupt(int i 283 static irqreturn_t snd_opl3sa2_interrupt(int irq, void *dev_id) 280 { 284 { 281 unsigned short status; 285 unsigned short status; 282 struct snd_card *card = dev_id; 286 struct snd_card *card = dev_id; 283 struct snd_opl3sa2 *chip; 287 struct snd_opl3sa2 *chip; 284 int handled = 0; 288 int handled = 0; 285 289 286 if (card == NULL) 290 if (card == NULL) 287 return IRQ_NONE; 291 return IRQ_NONE; 288 292 289 chip = card->private_data; 293 chip = card->private_data; 290 status = snd_opl3sa2_read(chip, OPL3SA 294 status = snd_opl3sa2_read(chip, OPL3SA2_IRQ_STATUS); 291 295 292 if (status & 0x20) { 296 if (status & 0x20) { 293 handled = 1; 297 handled = 1; 294 snd_opl3_interrupt(chip->synth 298 snd_opl3_interrupt(chip->synth); 295 } 299 } 296 300 297 if ((status & 0x10) && chip->rmidi != 301 if ((status & 0x10) && chip->rmidi != NULL) { 298 handled = 1; 302 handled = 1; 299 snd_mpu401_uart_interrupt(irq, 303 snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); 300 } 304 } 301 305 302 if (status & 0x07) { /* TI,CI,PI */ 306 if (status & 0x07) { /* TI,CI,PI */ 303 handled = 1; 307 handled = 1; 304 snd_wss_interrupt(irq, chip->w 308 snd_wss_interrupt(irq, chip->wss); 305 } 309 } 306 310 307 if (status & 0x40) { /* hardware volum 311 if (status & 0x40) { /* hardware volume change */ 308 handled = 1; 312 handled = 1; 309 /* reading from Master Lch reg 313 /* reading from Master Lch register at 0x07 clears this bit */ 310 snd_opl3sa2_read(chip, OPL3SA2 314 snd_opl3sa2_read(chip, OPL3SA2_MASTER_RIGHT); 311 snd_opl3sa2_read(chip, OPL3SA2 315 snd_opl3sa2_read(chip, OPL3SA2_MASTER_LEFT); 312 if (chip->master_switch && chi 316 if (chip->master_switch && chip->master_volume) { 313 snd_ctl_notify(card, S 317 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, 314 &chip- 318 &chip->master_switch->id); 315 snd_ctl_notify(card, S 319 snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_VALUE, 316 &chip- 320 &chip->master_volume->id); 317 } 321 } 318 } 322 } 319 return IRQ_RETVAL(handled); 323 return IRQ_RETVAL(handled); 320 } 324 } 321 325 322 #define OPL3SA2_SINGLE(xname, xindex, reg, shi 326 #define OPL3SA2_SINGLE(xname, xindex, reg, shift, mask, invert) \ 323 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 327 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 324 .info = snd_wss_info_single, \ 328 .info = snd_wss_info_single, \ 325 .get = snd_opl3sa2_get_single, .put = snd_op 329 .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \ 326 .private_value = reg | (shift << 8) | (mask 330 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) } 327 #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, 331 #define OPL3SA2_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \ 328 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 332 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 329 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 333 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 330 .name = xname, .index = xindex, \ 334 .name = xname, .index = xindex, \ 331 .info = snd_wss_info_single, \ 335 .info = snd_wss_info_single, \ 332 .get = snd_opl3sa2_get_single, .put = snd_op 336 .get = snd_opl3sa2_get_single, .put = snd_opl3sa2_put_single, \ 333 .private_value = reg | (shift << 8) | (mask 337 .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \ 334 .tlv = { .p = (xtlv) } } 338 .tlv = { .p = (xtlv) } } 335 339 336 static int snd_opl3sa2_get_single(struct snd_k 340 static int snd_opl3sa2_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 337 { 341 { 338 struct snd_opl3sa2 *chip = snd_kcontro 342 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 339 unsigned long flags; 343 unsigned long flags; 340 int reg = kcontrol->private_value & 0x 344 int reg = kcontrol->private_value & 0xff; 341 int shift = (kcontrol->private_value > 345 int shift = (kcontrol->private_value >> 8) & 0xff; 342 int mask = (kcontrol->private_value >> 346 int mask = (kcontrol->private_value >> 16) & 0xff; 343 int invert = (kcontrol->private_value 347 int invert = (kcontrol->private_value >> 24) & 0xff; 344 348 345 spin_lock_irqsave(&chip->reg_lock, fla 349 spin_lock_irqsave(&chip->reg_lock, flags); 346 ucontrol->value.integer.value[0] = (ch 350 ucontrol->value.integer.value[0] = (chip->ctlregs[reg] >> shift) & mask; 347 spin_unlock_irqrestore(&chip->reg_lock 351 spin_unlock_irqrestore(&chip->reg_lock, flags); 348 if (invert) 352 if (invert) 349 ucontrol->value.integer.value[ 353 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 350 return 0; 354 return 0; 351 } 355 } 352 356 353 static int snd_opl3sa2_put_single(struct snd_k 357 static int snd_opl3sa2_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 354 { 358 { 355 struct snd_opl3sa2 *chip = snd_kcontro 359 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 356 unsigned long flags; 360 unsigned long flags; 357 int reg = kcontrol->private_value & 0x 361 int reg = kcontrol->private_value & 0xff; 358 int shift = (kcontrol->private_value > 362 int shift = (kcontrol->private_value >> 8) & 0xff; 359 int mask = (kcontrol->private_value >> 363 int mask = (kcontrol->private_value >> 16) & 0xff; 360 int invert = (kcontrol->private_value 364 int invert = (kcontrol->private_value >> 24) & 0xff; 361 int change; 365 int change; 362 unsigned short val, oval; 366 unsigned short val, oval; 363 367 364 val = (ucontrol->value.integer.value[0 368 val = (ucontrol->value.integer.value[0] & mask); 365 if (invert) 369 if (invert) 366 val = mask - val; 370 val = mask - val; 367 val <<= shift; 371 val <<= shift; 368 spin_lock_irqsave(&chip->reg_lock, fla 372 spin_lock_irqsave(&chip->reg_lock, flags); 369 oval = chip->ctlregs[reg]; 373 oval = chip->ctlregs[reg]; 370 val = (oval & ~(mask << shift)) | val; 374 val = (oval & ~(mask << shift)) | val; 371 change = val != oval; 375 change = val != oval; 372 __snd_opl3sa2_write(chip, reg, val); 376 __snd_opl3sa2_write(chip, reg, val); 373 spin_unlock_irqrestore(&chip->reg_lock 377 spin_unlock_irqrestore(&chip->reg_lock, flags); 374 return change; 378 return change; 375 } 379 } 376 380 377 #define OPL3SA2_DOUBLE(xname, xindex, left_reg 381 #define OPL3SA2_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \ 378 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = 382 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \ 379 .info = snd_wss_info_double, \ 383 .info = snd_wss_info_double, \ 380 .get = snd_opl3sa2_get_double, .put = snd_op 384 .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \ 381 .private_value = left_reg | (right_reg << 8) 385 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) } 382 #define OPL3SA2_DOUBLE_TLV(xname, xindex, left 386 #define OPL3SA2_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \ 383 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 387 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 384 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | 388 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \ 385 .name = xname, .index = xindex, \ 389 .name = xname, .index = xindex, \ 386 .info = snd_wss_info_double, \ 390 .info = snd_wss_info_double, \ 387 .get = snd_opl3sa2_get_double, .put = snd_op 391 .get = snd_opl3sa2_get_double, .put = snd_opl3sa2_put_double, \ 388 .private_value = left_reg | (right_reg << 8) 392 .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \ 389 .tlv = { .p = (xtlv) } } 393 .tlv = { .p = (xtlv) } } 390 394 391 static int snd_opl3sa2_get_double(struct snd_k 395 static int snd_opl3sa2_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 392 { 396 { 393 struct snd_opl3sa2 *chip = snd_kcontro 397 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 394 unsigned long flags; 398 unsigned long flags; 395 int left_reg = kcontrol->private_value 399 int left_reg = kcontrol->private_value & 0xff; 396 int right_reg = (kcontrol->private_val 400 int right_reg = (kcontrol->private_value >> 8) & 0xff; 397 int shift_left = (kcontrol->private_va 401 int shift_left = (kcontrol->private_value >> 16) & 0x07; 398 int shift_right = (kcontrol->private_v 402 int shift_right = (kcontrol->private_value >> 19) & 0x07; 399 int mask = (kcontrol->private_value >> 403 int mask = (kcontrol->private_value >> 24) & 0xff; 400 int invert = (kcontrol->private_value 404 int invert = (kcontrol->private_value >> 22) & 1; 401 405 402 spin_lock_irqsave(&chip->reg_lock, fla 406 spin_lock_irqsave(&chip->reg_lock, flags); 403 ucontrol->value.integer.value[0] = (ch 407 ucontrol->value.integer.value[0] = (chip->ctlregs[left_reg] >> shift_left) & mask; 404 ucontrol->value.integer.value[1] = (ch 408 ucontrol->value.integer.value[1] = (chip->ctlregs[right_reg] >> shift_right) & mask; 405 spin_unlock_irqrestore(&chip->reg_lock 409 spin_unlock_irqrestore(&chip->reg_lock, flags); 406 if (invert) { 410 if (invert) { 407 ucontrol->value.integer.value[ 411 ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0]; 408 ucontrol->value.integer.value[ 412 ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1]; 409 } 413 } 410 return 0; 414 return 0; 411 } 415 } 412 416 413 static int snd_opl3sa2_put_double(struct snd_k 417 static int snd_opl3sa2_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 414 { 418 { 415 struct snd_opl3sa2 *chip = snd_kcontro 419 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 416 unsigned long flags; 420 unsigned long flags; 417 int left_reg = kcontrol->private_value 421 int left_reg = kcontrol->private_value & 0xff; 418 int right_reg = (kcontrol->private_val 422 int right_reg = (kcontrol->private_value >> 8) & 0xff; 419 int shift_left = (kcontrol->private_va 423 int shift_left = (kcontrol->private_value >> 16) & 0x07; 420 int shift_right = (kcontrol->private_v 424 int shift_right = (kcontrol->private_value >> 19) & 0x07; 421 int mask = (kcontrol->private_value >> 425 int mask = (kcontrol->private_value >> 24) & 0xff; 422 int invert = (kcontrol->private_value 426 int invert = (kcontrol->private_value >> 22) & 1; 423 int change; 427 int change; 424 unsigned short val1, val2, oval1, oval 428 unsigned short val1, val2, oval1, oval2; 425 429 426 val1 = ucontrol->value.integer.value[0 430 val1 = ucontrol->value.integer.value[0] & mask; 427 val2 = ucontrol->value.integer.value[1 431 val2 = ucontrol->value.integer.value[1] & mask; 428 if (invert) { 432 if (invert) { 429 val1 = mask - val1; 433 val1 = mask - val1; 430 val2 = mask - val2; 434 val2 = mask - val2; 431 } 435 } 432 val1 <<= shift_left; 436 val1 <<= shift_left; 433 val2 <<= shift_right; 437 val2 <<= shift_right; 434 spin_lock_irqsave(&chip->reg_lock, fla 438 spin_lock_irqsave(&chip->reg_lock, flags); 435 if (left_reg != right_reg) { 439 if (left_reg != right_reg) { 436 oval1 = chip->ctlregs[left_reg 440 oval1 = chip->ctlregs[left_reg]; 437 oval2 = chip->ctlregs[right_re 441 oval2 = chip->ctlregs[right_reg]; 438 val1 = (oval1 & ~(mask << shif 442 val1 = (oval1 & ~(mask << shift_left)) | val1; 439 val2 = (oval2 & ~(mask << shif 443 val2 = (oval2 & ~(mask << shift_right)) | val2; 440 change = val1 != oval1 || val2 444 change = val1 != oval1 || val2 != oval2; 441 __snd_opl3sa2_write(chip, left 445 __snd_opl3sa2_write(chip, left_reg, val1); 442 __snd_opl3sa2_write(chip, righ 446 __snd_opl3sa2_write(chip, right_reg, val2); 443 } else { 447 } else { 444 oval1 = chip->ctlregs[left_reg 448 oval1 = chip->ctlregs[left_reg]; 445 val1 = (oval1 & ~((mask << shi 449 val1 = (oval1 & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; 446 change = val1 != oval1; 450 change = val1 != oval1; 447 __snd_opl3sa2_write(chip, left 451 __snd_opl3sa2_write(chip, left_reg, val1); 448 } 452 } 449 spin_unlock_irqrestore(&chip->reg_lock 453 spin_unlock_irqrestore(&chip->reg_lock, flags); 450 return change; 454 return change; 451 } 455 } 452 456 453 static const DECLARE_TLV_DB_SCALE(db_scale_mas 457 static const DECLARE_TLV_DB_SCALE(db_scale_master, -3000, 200, 0); 454 static const DECLARE_TLV_DB_SCALE(db_scale_5bi 458 static const DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0); 455 459 456 static const struct snd_kcontrol_new snd_opl3s 460 static const struct snd_kcontrol_new snd_opl3sa2_controls[] = { 457 OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x 461 OPL3SA2_DOUBLE("Master Playback Switch", 0, 0x07, 0x08, 7, 7, 1, 1), 458 OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0 462 OPL3SA2_DOUBLE_TLV("Master Playback Volume", 0, 0x07, 0x08, 0, 0, 15, 1, 459 db_scale_master), 463 db_scale_master), 460 OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 464 OPL3SA2_SINGLE("Mic Playback Switch", 0, 0x09, 7, 1, 1), 461 OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0 465 OPL3SA2_SINGLE_TLV("Mic Playback Volume", 0, 0x09, 0, 31, 1, 462 db_scale_5bit_12db_max), 466 db_scale_5bit_12db_max), 463 OPL3SA2_SINGLE("ZV Port Switch", 0, 0x02, 0, 1 467 OPL3SA2_SINGLE("ZV Port Switch", 0, 0x02, 0, 1, 0), 464 }; 468 }; 465 469 466 static const struct snd_kcontrol_new snd_opl3s 470 static const struct snd_kcontrol_new snd_opl3sa2_tone_controls[] = { 467 OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0 471 OPL3SA2_DOUBLE("3D Control - Wide", 0, 0x14, 0x14, 4, 0, 7, 0), 468 OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 472 OPL3SA2_DOUBLE("Tone Control - Bass", 0, 0x15, 0x15, 4, 0, 7, 0), 469 OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x1 473 OPL3SA2_DOUBLE("Tone Control - Treble", 0, 0x16, 0x16, 4, 0, 7, 0) 470 }; 474 }; 471 475 472 static void snd_opl3sa2_master_free(struct snd 476 static void snd_opl3sa2_master_free(struct snd_kcontrol *kcontrol) 473 { 477 { 474 struct snd_opl3sa2 *chip = snd_kcontro 478 struct snd_opl3sa2 *chip = snd_kcontrol_chip(kcontrol); 475 chip->master_switch = NULL; 479 chip->master_switch = NULL; 476 chip->master_volume = NULL; 480 chip->master_volume = NULL; 477 } 481 } 478 482 479 static int snd_opl3sa2_mixer(struct snd_card * 483 static int snd_opl3sa2_mixer(struct snd_card *card) 480 { 484 { 481 struct snd_opl3sa2 *chip = card->priva 485 struct snd_opl3sa2 *chip = card->private_data; 482 struct snd_ctl_elem_id id1, id2; 486 struct snd_ctl_elem_id id1, id2; 483 struct snd_kcontrol *kctl; 487 struct snd_kcontrol *kctl; 484 unsigned int idx; 488 unsigned int idx; 485 int err; 489 int err; 486 490 487 memset(&id1, 0, sizeof(id1)); 491 memset(&id1, 0, sizeof(id1)); 488 memset(&id2, 0, sizeof(id2)); 492 memset(&id2, 0, sizeof(id2)); 489 id1.iface = id2.iface = SNDRV_CTL_ELEM 493 id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 490 /* reassign AUX0 to CD */ 494 /* reassign AUX0 to CD */ 491 strcpy(id1.name, "Aux Playback Switch" 495 strcpy(id1.name, "Aux Playback Switch"); 492 strcpy(id2.name, "CD Playback Switch") 496 strcpy(id2.name, "CD Playback Switch"); 493 err = snd_ctl_rename_id(card, &id1, &i !! 497 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { 494 if (err < 0) { !! 498 snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); 495 dev_err(card->dev, "Cannot ren << 496 return err; 499 return err; 497 } 500 } 498 strcpy(id1.name, "Aux Playback Volume" 501 strcpy(id1.name, "Aux Playback Volume"); 499 strcpy(id2.name, "CD Playback Volume") 502 strcpy(id2.name, "CD Playback Volume"); 500 err = snd_ctl_rename_id(card, &id1, &i !! 503 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { 501 if (err < 0) { !! 504 snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); 502 dev_err(card->dev, "Cannot ren << 503 return err; 505 return err; 504 } 506 } 505 /* reassign AUX1 to FM */ 507 /* reassign AUX1 to FM */ 506 strcpy(id1.name, "Aux Playback Switch" 508 strcpy(id1.name, "Aux Playback Switch"); id1.index = 1; 507 strcpy(id2.name, "FM Playback Switch") 509 strcpy(id2.name, "FM Playback Switch"); 508 err = snd_ctl_rename_id(card, &id1, &i !! 510 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { 509 if (err < 0) { !! 511 snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); 510 dev_err(card->dev, "Cannot ren << 511 return err; 512 return err; 512 } 513 } 513 strcpy(id1.name, "Aux Playback Volume" 514 strcpy(id1.name, "Aux Playback Volume"); 514 strcpy(id2.name, "FM Playback Volume") 515 strcpy(id2.name, "FM Playback Volume"); 515 err = snd_ctl_rename_id(card, &id1, &i !! 516 if ((err = snd_ctl_rename_id(card, &id1, &id2)) < 0) { 516 if (err < 0) { !! 517 snd_printk(KERN_ERR "Cannot rename opl3sa2 control\n"); 517 dev_err(card->dev, "Cannot ren << 518 return err; 518 return err; 519 } 519 } 520 /* add OPL3SA2 controls */ 520 /* add OPL3SA2 controls */ 521 for (idx = 0; idx < ARRAY_SIZE(snd_opl 521 for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_controls); idx++) { 522 kctl = snd_ctl_new1(&snd_opl3s !! 522 if ((err = snd_ctl_add(card, kctl = snd_ctl_new1(&snd_opl3sa2_controls[idx], chip))) < 0) 523 err = snd_ctl_add(card, kctl); << 524 if (err < 0) << 525 return err; 523 return err; 526 switch (idx) { 524 switch (idx) { 527 case 0: chip->master_switch = 525 case 0: chip->master_switch = kctl; kctl->private_free = snd_opl3sa2_master_free; break; 528 case 1: chip->master_volume = 526 case 1: chip->master_volume = kctl; kctl->private_free = snd_opl3sa2_master_free; break; 529 } 527 } 530 } 528 } 531 if (chip->version > 2) { 529 if (chip->version > 2) { 532 for (idx = 0; idx < ARRAY_SIZE !! 530 for (idx = 0; idx < ARRAY_SIZE(snd_opl3sa2_tone_controls); idx++) 533 err = snd_ctl_add(card !! 531 if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_opl3sa2_tone_controls[idx], chip))) < 0) 534 if (err < 0) << 535 return err; 532 return err; 536 } << 537 } 533 } 538 return 0; 534 return 0; 539 } 535 } 540 536 541 /* Power Management support functions */ 537 /* Power Management support functions */ 542 #ifdef CONFIG_PM 538 #ifdef CONFIG_PM 543 static int snd_opl3sa2_suspend(struct snd_card 539 static int snd_opl3sa2_suspend(struct snd_card *card, pm_message_t state) 544 { 540 { 545 if (card) { 541 if (card) { 546 struct snd_opl3sa2 *chip = car 542 struct snd_opl3sa2 *chip = card->private_data; 547 543 548 snd_power_change_state(card, S 544 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 549 chip->wss->suspend(chip->wss); 545 chip->wss->suspend(chip->wss); 550 /* power down */ 546 /* power down */ 551 snd_opl3sa2_write(chip, OPL3SA 547 snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D3); 552 } 548 } 553 549 554 return 0; 550 return 0; 555 } 551 } 556 552 557 static int snd_opl3sa2_resume(struct snd_card 553 static int snd_opl3sa2_resume(struct snd_card *card) 558 { 554 { 559 struct snd_opl3sa2 *chip; 555 struct snd_opl3sa2 *chip; 560 int i; 556 int i; 561 557 562 if (!card) 558 if (!card) 563 return 0; 559 return 0; 564 560 565 chip = card->private_data; 561 chip = card->private_data; 566 /* power up */ 562 /* power up */ 567 snd_opl3sa2_write(chip, OPL3SA2_PM_CTR 563 snd_opl3sa2_write(chip, OPL3SA2_PM_CTRL, OPL3SA2_PM_D0); 568 564 569 /* restore registers */ 565 /* restore registers */ 570 for (i = 2; i <= 0x0a; i++) { 566 for (i = 2; i <= 0x0a; i++) { 571 if (i != OPL3SA2_IRQ_STATUS) 567 if (i != OPL3SA2_IRQ_STATUS) 572 snd_opl3sa2_write(chip 568 snd_opl3sa2_write(chip, i, chip->ctlregs[i]); 573 } 569 } 574 if (chip->version > 2) { 570 if (chip->version > 2) { 575 for (i = 0x12; i <= 0x16; i++) 571 for (i = 0x12; i <= 0x16; i++) 576 snd_opl3sa2_write(chip 572 snd_opl3sa2_write(chip, i, chip->ctlregs[i]); 577 } 573 } 578 /* restore wss */ 574 /* restore wss */ 579 chip->wss->resume(chip->wss); 575 chip->wss->resume(chip->wss); 580 576 581 snd_power_change_state(card, SNDRV_CTL 577 snd_power_change_state(card, SNDRV_CTL_POWER_D0); 582 return 0; 578 return 0; 583 } 579 } 584 #endif /* CONFIG_PM */ 580 #endif /* CONFIG_PM */ 585 581 586 #ifdef CONFIG_PNP 582 #ifdef CONFIG_PNP 587 static int snd_opl3sa2_pnp(int dev, struct snd 583 static int snd_opl3sa2_pnp(int dev, struct snd_opl3sa2 *chip, 588 struct pnp_dev *pde 584 struct pnp_dev *pdev) 589 { 585 { 590 if (pnp_activate_dev(pdev) < 0) { 586 if (pnp_activate_dev(pdev) < 0) { 591 dev_err(chip->card->dev, "PnP !! 587 snd_printk(KERN_ERR "PnP configure failure (out of resources?)\n"); 592 return -EBUSY; 588 return -EBUSY; 593 } 589 } 594 sb_port[dev] = pnp_port_start(pdev, 0) 590 sb_port[dev] = pnp_port_start(pdev, 0); 595 wss_port[dev] = pnp_port_start(pdev, 1 591 wss_port[dev] = pnp_port_start(pdev, 1); 596 fm_port[dev] = pnp_port_start(pdev, 2) 592 fm_port[dev] = pnp_port_start(pdev, 2); 597 midi_port[dev] = pnp_port_start(pdev, 593 midi_port[dev] = pnp_port_start(pdev, 3); 598 port[dev] = pnp_port_start(pdev, 4); 594 port[dev] = pnp_port_start(pdev, 4); 599 dma1[dev] = pnp_dma(pdev, 0); 595 dma1[dev] = pnp_dma(pdev, 0); 600 dma2[dev] = pnp_dma(pdev, 1); 596 dma2[dev] = pnp_dma(pdev, 1); 601 irq[dev] = pnp_irq(pdev, 0); 597 irq[dev] = pnp_irq(pdev, 0); 602 dev_dbg(chip->card->dev, "%sPnP OPL3-S !! 598 snd_printdd("%sPnP OPL3-SA: sb port=0x%lx, wss port=0x%lx, fm port=0x%lx, midi port=0x%lx\n", 603 pnp_device_is_pnpbios(pdev) ? 599 pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", sb_port[dev], wss_port[dev], fm_port[dev], midi_port[dev]); 604 dev_dbg(chip->card->dev, "%sPnP OPL3-S !! 600 snd_printdd("%sPnP OPL3-SA: control port=0x%lx, dma1=%i, dma2=%i, irq=%i\n", 605 pnp_device_is_pnpbios(pdev) ? 601 pnp_device_is_pnpbios(pdev) ? "BIOS" : "ISA", port[dev], dma1[dev], dma2[dev], irq[dev]); 606 return 0; 602 return 0; 607 } 603 } 608 #endif /* CONFIG_PNP */ 604 #endif /* CONFIG_PNP */ 609 605 >> 606 static void snd_opl3sa2_free(struct snd_card *card) >> 607 { >> 608 struct snd_opl3sa2 *chip = card->private_data; >> 609 if (chip->irq >= 0) >> 610 free_irq(chip->irq, card); >> 611 release_and_free_resource(chip->res_port); >> 612 } >> 613 610 static int snd_opl3sa2_card_new(struct device 614 static int snd_opl3sa2_card_new(struct device *pdev, int dev, 611 struct snd_car 615 struct snd_card **cardp) 612 { 616 { 613 struct snd_card *card; 617 struct snd_card *card; 614 struct snd_opl3sa2 *chip; 618 struct snd_opl3sa2 *chip; 615 int err; 619 int err; 616 620 617 err = snd_devm_card_new(pdev, index[de !! 621 err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE, 618 sizeof(struct !! 622 sizeof(struct snd_opl3sa2), &card); 619 if (err < 0) 623 if (err < 0) 620 return err; 624 return err; 621 strcpy(card->driver, "OPL3SA2"); 625 strcpy(card->driver, "OPL3SA2"); 622 strcpy(card->shortname, "Yamaha OPL3-S 626 strcpy(card->shortname, "Yamaha OPL3-SA"); 623 chip = card->private_data; 627 chip = card->private_data; 624 spin_lock_init(&chip->reg_lock); 628 spin_lock_init(&chip->reg_lock); 625 chip->irq = -1; 629 chip->irq = -1; >> 630 card->private_free = snd_opl3sa2_free; 626 *cardp = card; 631 *cardp = card; 627 return 0; 632 return 0; 628 } 633 } 629 634 630 static int snd_opl3sa2_probe(struct snd_card * 635 static int snd_opl3sa2_probe(struct snd_card *card, int dev) 631 { 636 { 632 int xirq, xdma1, xdma2; 637 int xirq, xdma1, xdma2; 633 struct snd_opl3sa2 *chip; 638 struct snd_opl3sa2 *chip; 634 struct snd_wss *wss; 639 struct snd_wss *wss; 635 struct snd_opl3 *opl3; 640 struct snd_opl3 *opl3; 636 int err; 641 int err; 637 642 638 /* initialise this card from supplied 643 /* initialise this card from supplied (or default) parameter*/ 639 chip = card->private_data; 644 chip = card->private_data; 640 chip->card = card; << 641 chip->ymode = opl3sa3_ymode[dev] & 0x0 645 chip->ymode = opl3sa3_ymode[dev] & 0x03 ; 642 chip->port = port[dev]; 646 chip->port = port[dev]; 643 xirq = irq[dev]; 647 xirq = irq[dev]; 644 xdma1 = dma1[dev]; 648 xdma1 = dma1[dev]; 645 xdma2 = dma2[dev]; 649 xdma2 = dma2[dev]; 646 if (xdma2 < 0) 650 if (xdma2 < 0) 647 chip->single_dma = 1; 651 chip->single_dma = 1; 648 err = snd_opl3sa2_detect(card); 652 err = snd_opl3sa2_detect(card); 649 if (err < 0) 653 if (err < 0) 650 return err; 654 return err; 651 err = devm_request_irq(card->dev, xirq !! 655 err = request_irq(xirq, snd_opl3sa2_interrupt, 0, 652 "OPL3-SA2", car !! 656 "OPL3-SA2", card); 653 if (err) { 657 if (err) { 654 dev_err(card->dev, "can't grab !! 658 snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq); 655 return -ENODEV; 659 return -ENODEV; 656 } 660 } 657 chip->irq = xirq; 661 chip->irq = xirq; 658 card->sync_irq = chip->irq; 662 card->sync_irq = chip->irq; 659 err = snd_wss_create(card, 663 err = snd_wss_create(card, 660 wss_port[dev] + 4 664 wss_port[dev] + 4, -1, 661 xirq, xdma1, xdma 665 xirq, xdma1, xdma2, 662 WSS_HW_OPL3SA2, W 666 WSS_HW_OPL3SA2, WSS_HWSHARE_IRQ, &wss); 663 if (err < 0) { 667 if (err < 0) { 664 dev_dbg(card->dev, "Oops, WSS !! 668 snd_printd("Oops, WSS not detected at 0x%lx\n", wss_port[dev] + 4); 665 return err; 669 return err; 666 } 670 } 667 chip->wss = wss; 671 chip->wss = wss; 668 err = snd_wss_pcm(wss, 0); 672 err = snd_wss_pcm(wss, 0); 669 if (err < 0) 673 if (err < 0) 670 return err; 674 return err; 671 err = snd_wss_mixer(wss); 675 err = snd_wss_mixer(wss); 672 if (err < 0) 676 if (err < 0) 673 return err; 677 return err; 674 err = snd_opl3sa2_mixer(card); 678 err = snd_opl3sa2_mixer(card); 675 if (err < 0) 679 if (err < 0) 676 return err; 680 return err; 677 err = snd_wss_timer(wss, 0); 681 err = snd_wss_timer(wss, 0); 678 if (err < 0) 682 if (err < 0) 679 return err; 683 return err; 680 if (fm_port[dev] >= 0x340 && fm_port[d 684 if (fm_port[dev] >= 0x340 && fm_port[dev] < 0x400) { 681 err = snd_opl3_create(card, fm !! 685 if ((err = snd_opl3_create(card, fm_port[dev], 682 fm_port[ !! 686 fm_port[dev] + 2, 683 OPL3_HW_ !! 687 OPL3_HW_OPL3, 0, &opl3)) < 0) 684 if (err < 0) << 685 return err; 688 return err; 686 err = snd_opl3_timer_new(opl3, !! 689 if ((err = snd_opl3_timer_new(opl3, 1, 2)) < 0) 687 if (err < 0) << 688 return err; 690 return err; 689 err = snd_opl3_hwdep_new(opl3, !! 691 if ((err = snd_opl3_hwdep_new(opl3, 0, 1, &chip->synth)) < 0) 690 if (err < 0) << 691 return err; 692 return err; 692 } 693 } 693 if (midi_port[dev] >= 0x300 && midi_po 694 if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { 694 err = snd_mpu401_uart_new(card !! 695 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, 695 midi !! 696 midi_port[dev], 696 MPU4 !! 697 MPU401_INFO_IRQ_HOOK, -1, 697 &chi !! 698 &chip->rmidi)) < 0) 698 if (err < 0) << 699 return err; 699 return err; 700 } 700 } 701 sprintf(card->longname, "%s at 0x%lx, 701 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 702 card->shortname, chip->port, x 702 card->shortname, chip->port, xirq, xdma1); 703 if (xdma2 >= 0) 703 if (xdma2 >= 0) 704 sprintf(card->longname + strle 704 sprintf(card->longname + strlen(card->longname), "&%d", xdma2); 705 705 706 return snd_card_register(card); 706 return snd_card_register(card); 707 } 707 } 708 708 709 #ifdef CONFIG_PNP 709 #ifdef CONFIG_PNP 710 static int snd_opl3sa2_pnp_detect(struct pnp_d 710 static int snd_opl3sa2_pnp_detect(struct pnp_dev *pdev, 711 const struct 711 const struct pnp_device_id *id) 712 { 712 { 713 static int dev; 713 static int dev; 714 int err; 714 int err; 715 struct snd_card *card; 715 struct snd_card *card; 716 716 717 if (pnp_device_is_isapnp(pdev)) 717 if (pnp_device_is_isapnp(pdev)) 718 return -ENOENT; /* we have ano 718 return -ENOENT; /* we have another procedure - card */ 719 for (; dev < SNDRV_CARDS; dev++) { 719 for (; dev < SNDRV_CARDS; dev++) { 720 if (enable[dev] && isapnp[dev] 720 if (enable[dev] && isapnp[dev]) 721 break; 721 break; 722 } 722 } 723 if (dev >= SNDRV_CARDS) 723 if (dev >= SNDRV_CARDS) 724 return -ENODEV; 724 return -ENODEV; 725 725 726 err = snd_opl3sa2_card_new(&pdev->dev, 726 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); 727 if (err < 0) 727 if (err < 0) 728 return err; 728 return err; 729 err = snd_opl3sa2_pnp(dev, card->priva !! 729 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 730 if (err < 0) !! 730 snd_card_free(card); 731 return err; 731 return err; 732 err = snd_opl3sa2_probe(card, dev); !! 732 } 733 if (err < 0) !! 733 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { >> 734 snd_card_free(card); 734 return err; 735 return err; >> 736 } 735 pnp_set_drvdata(pdev, card); 737 pnp_set_drvdata(pdev, card); 736 dev++; 738 dev++; 737 return 0; 739 return 0; 738 } 740 } 739 741 >> 742 static void snd_opl3sa2_pnp_remove(struct pnp_dev *pdev) >> 743 { >> 744 snd_card_free(pnp_get_drvdata(pdev)); >> 745 } >> 746 740 #ifdef CONFIG_PM 747 #ifdef CONFIG_PM 741 static int snd_opl3sa2_pnp_suspend(struct pnp_ 748 static int snd_opl3sa2_pnp_suspend(struct pnp_dev *pdev, pm_message_t state) 742 { 749 { 743 return snd_opl3sa2_suspend(pnp_get_drv 750 return snd_opl3sa2_suspend(pnp_get_drvdata(pdev), state); 744 } 751 } 745 static int snd_opl3sa2_pnp_resume(struct pnp_d 752 static int snd_opl3sa2_pnp_resume(struct pnp_dev *pdev) 746 { 753 { 747 return snd_opl3sa2_resume(pnp_get_drvd 754 return snd_opl3sa2_resume(pnp_get_drvdata(pdev)); 748 } 755 } 749 #endif 756 #endif 750 757 751 static struct pnp_driver opl3sa2_pnp_driver = 758 static struct pnp_driver opl3sa2_pnp_driver = { 752 .name = "snd-opl3sa2-pnpbios", 759 .name = "snd-opl3sa2-pnpbios", 753 .id_table = snd_opl3sa2_pnpbiosids, 760 .id_table = snd_opl3sa2_pnpbiosids, 754 .probe = snd_opl3sa2_pnp_detect, 761 .probe = snd_opl3sa2_pnp_detect, >> 762 .remove = snd_opl3sa2_pnp_remove, 755 #ifdef CONFIG_PM 763 #ifdef CONFIG_PM 756 .suspend = snd_opl3sa2_pnp_suspend, 764 .suspend = snd_opl3sa2_pnp_suspend, 757 .resume = snd_opl3sa2_pnp_resume, 765 .resume = snd_opl3sa2_pnp_resume, 758 #endif 766 #endif 759 }; 767 }; 760 768 761 static int snd_opl3sa2_pnp_cdetect(struct pnp_ 769 static int snd_opl3sa2_pnp_cdetect(struct pnp_card_link *pcard, 762 const struc 770 const struct pnp_card_device_id *id) 763 { 771 { 764 static int dev; 772 static int dev; 765 struct pnp_dev *pdev; 773 struct pnp_dev *pdev; 766 int err; 774 int err; 767 struct snd_card *card; 775 struct snd_card *card; 768 776 769 pdev = pnp_request_card_device(pcard, 777 pdev = pnp_request_card_device(pcard, id->devs[0].id, NULL); 770 if (pdev == NULL) { 778 if (pdev == NULL) { 771 dev_err(&pcard->card->dev, "ca !! 779 snd_printk(KERN_ERR PFX "can't get pnp device from id '%s'\n", 772 id->devs[0].id); 780 id->devs[0].id); 773 return -EBUSY; 781 return -EBUSY; 774 } 782 } 775 for (; dev < SNDRV_CARDS; dev++) { 783 for (; dev < SNDRV_CARDS; dev++) { 776 if (enable[dev] && isapnp[dev] 784 if (enable[dev] && isapnp[dev]) 777 break; 785 break; 778 } 786 } 779 if (dev >= SNDRV_CARDS) 787 if (dev >= SNDRV_CARDS) 780 return -ENODEV; 788 return -ENODEV; 781 789 782 err = snd_opl3sa2_card_new(&pdev->dev, 790 err = snd_opl3sa2_card_new(&pdev->dev, dev, &card); 783 if (err < 0) 791 if (err < 0) 784 return err; 792 return err; 785 err = snd_opl3sa2_pnp(dev, card->priva !! 793 if ((err = snd_opl3sa2_pnp(dev, card->private_data, pdev)) < 0) { 786 if (err < 0) !! 794 snd_card_free(card); 787 return err; 795 return err; 788 err = snd_opl3sa2_probe(card, dev); !! 796 } 789 if (err < 0) !! 797 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { >> 798 snd_card_free(card); 790 return err; 799 return err; >> 800 } 791 pnp_set_card_drvdata(pcard, card); 801 pnp_set_card_drvdata(pcard, card); 792 dev++; 802 dev++; 793 return 0; 803 return 0; 794 } 804 } 795 805 >> 806 static void snd_opl3sa2_pnp_cremove(struct pnp_card_link *pcard) >> 807 { >> 808 snd_card_free(pnp_get_card_drvdata(pcard)); >> 809 pnp_set_card_drvdata(pcard, NULL); >> 810 } >> 811 796 #ifdef CONFIG_PM 812 #ifdef CONFIG_PM 797 static int snd_opl3sa2_pnp_csuspend(struct pnp 813 static int snd_opl3sa2_pnp_csuspend(struct pnp_card_link *pcard, pm_message_t state) 798 { 814 { 799 return snd_opl3sa2_suspend(pnp_get_car 815 return snd_opl3sa2_suspend(pnp_get_card_drvdata(pcard), state); 800 } 816 } 801 static int snd_opl3sa2_pnp_cresume(struct pnp_ 817 static int snd_opl3sa2_pnp_cresume(struct pnp_card_link *pcard) 802 { 818 { 803 return snd_opl3sa2_resume(pnp_get_card 819 return snd_opl3sa2_resume(pnp_get_card_drvdata(pcard)); 804 } 820 } 805 #endif 821 #endif 806 822 807 static struct pnp_card_driver opl3sa2_pnpc_dri 823 static struct pnp_card_driver opl3sa2_pnpc_driver = { 808 .flags = PNP_DRIVER_RES_DISABLE, 824 .flags = PNP_DRIVER_RES_DISABLE, 809 .name = "snd-opl3sa2-cpnp", 825 .name = "snd-opl3sa2-cpnp", 810 .id_table = snd_opl3sa2_pnpids, 826 .id_table = snd_opl3sa2_pnpids, 811 .probe = snd_opl3sa2_pnp_cdetect, 827 .probe = snd_opl3sa2_pnp_cdetect, >> 828 .remove = snd_opl3sa2_pnp_cremove, 812 #ifdef CONFIG_PM 829 #ifdef CONFIG_PM 813 .suspend = snd_opl3sa2_pnp_csuspend, 830 .suspend = snd_opl3sa2_pnp_csuspend, 814 .resume = snd_opl3sa2_pnp_cresume, 831 .resume = snd_opl3sa2_pnp_cresume, 815 #endif 832 #endif 816 }; 833 }; 817 #endif /* CONFIG_PNP */ 834 #endif /* CONFIG_PNP */ 818 835 819 static int snd_opl3sa2_isa_match(struct device 836 static int snd_opl3sa2_isa_match(struct device *pdev, 820 unsigned int 837 unsigned int dev) 821 { 838 { 822 if (!enable[dev]) 839 if (!enable[dev]) 823 return 0; 840 return 0; 824 #ifdef CONFIG_PNP 841 #ifdef CONFIG_PNP 825 if (isapnp[dev]) 842 if (isapnp[dev]) 826 return 0; 843 return 0; 827 #endif 844 #endif 828 if (port[dev] == SNDRV_AUTO_PORT) { 845 if (port[dev] == SNDRV_AUTO_PORT) { 829 dev_err(pdev, "specify port\n" !! 846 snd_printk(KERN_ERR PFX "specify port\n"); 830 return 0; 847 return 0; 831 } 848 } 832 if (wss_port[dev] == SNDRV_AUTO_PORT) 849 if (wss_port[dev] == SNDRV_AUTO_PORT) { 833 dev_err(pdev, "specify wss_por !! 850 snd_printk(KERN_ERR PFX "specify wss_port\n"); 834 return 0; 851 return 0; 835 } 852 } 836 if (fm_port[dev] == SNDRV_AUTO_PORT) { 853 if (fm_port[dev] == SNDRV_AUTO_PORT) { 837 dev_err(pdev, "specify fm_port !! 854 snd_printk(KERN_ERR PFX "specify fm_port\n"); 838 return 0; 855 return 0; 839 } 856 } 840 if (midi_port[dev] == SNDRV_AUTO_PORT) 857 if (midi_port[dev] == SNDRV_AUTO_PORT) { 841 dev_err(pdev, "specify midi_po !! 858 snd_printk(KERN_ERR PFX "specify midi_port\n"); 842 return 0; 859 return 0; 843 } 860 } 844 return 1; 861 return 1; 845 } 862 } 846 863 847 static int snd_opl3sa2_isa_probe(struct device 864 static int snd_opl3sa2_isa_probe(struct device *pdev, 848 unsigned int 865 unsigned int dev) 849 { 866 { 850 struct snd_card *card; 867 struct snd_card *card; 851 int err; 868 int err; 852 869 853 err = snd_opl3sa2_card_new(pdev, dev, 870 err = snd_opl3sa2_card_new(pdev, dev, &card); 854 if (err < 0) 871 if (err < 0) 855 return err; 872 return err; 856 err = snd_opl3sa2_probe(card, dev); !! 873 if ((err = snd_opl3sa2_probe(card, dev)) < 0) { 857 if (err < 0) !! 874 snd_card_free(card); 858 return err; 875 return err; >> 876 } 859 dev_set_drvdata(pdev, card); 877 dev_set_drvdata(pdev, card); 860 return 0; 878 return 0; 861 } 879 } 862 880 >> 881 static int snd_opl3sa2_isa_remove(struct device *devptr, >> 882 unsigned int dev) >> 883 { >> 884 snd_card_free(dev_get_drvdata(devptr)); >> 885 return 0; >> 886 } >> 887 863 #ifdef CONFIG_PM 888 #ifdef CONFIG_PM 864 static int snd_opl3sa2_isa_suspend(struct devi 889 static int snd_opl3sa2_isa_suspend(struct device *dev, unsigned int n, 865 pm_message_ 890 pm_message_t state) 866 { 891 { 867 return snd_opl3sa2_suspend(dev_get_drv 892 return snd_opl3sa2_suspend(dev_get_drvdata(dev), state); 868 } 893 } 869 894 870 static int snd_opl3sa2_isa_resume(struct devic 895 static int snd_opl3sa2_isa_resume(struct device *dev, unsigned int n) 871 { 896 { 872 return snd_opl3sa2_resume(dev_get_drvd 897 return snd_opl3sa2_resume(dev_get_drvdata(dev)); 873 } 898 } 874 #endif 899 #endif 875 900 876 #define DEV_NAME "opl3sa2" 901 #define DEV_NAME "opl3sa2" 877 902 878 static struct isa_driver snd_opl3sa2_isa_drive 903 static struct isa_driver snd_opl3sa2_isa_driver = { 879 .match = snd_opl3sa2_isa_matc 904 .match = snd_opl3sa2_isa_match, 880 .probe = snd_opl3sa2_isa_prob 905 .probe = snd_opl3sa2_isa_probe, >> 906 .remove = snd_opl3sa2_isa_remove, 881 #ifdef CONFIG_PM 907 #ifdef CONFIG_PM 882 .suspend = snd_opl3sa2_isa_susp 908 .suspend = snd_opl3sa2_isa_suspend, 883 .resume = snd_opl3sa2_isa_resu 909 .resume = snd_opl3sa2_isa_resume, 884 #endif 910 #endif 885 .driver = { 911 .driver = { 886 .name = DEV_NAME 912 .name = DEV_NAME 887 }, 913 }, 888 }; 914 }; 889 915 890 static int __init alsa_card_opl3sa2_init(void) 916 static int __init alsa_card_opl3sa2_init(void) 891 { 917 { 892 int err; 918 int err; 893 919 894 err = isa_register_driver(&snd_opl3sa2 920 err = isa_register_driver(&snd_opl3sa2_isa_driver, SNDRV_CARDS); 895 #ifdef CONFIG_PNP 921 #ifdef CONFIG_PNP 896 if (!err) 922 if (!err) 897 isa_registered = 1; 923 isa_registered = 1; 898 924 899 err = pnp_register_driver(&opl3sa2_pnp 925 err = pnp_register_driver(&opl3sa2_pnp_driver); 900 if (!err) 926 if (!err) 901 pnp_registered = 1; 927 pnp_registered = 1; 902 928 903 err = pnp_register_card_driver(&opl3sa 929 err = pnp_register_card_driver(&opl3sa2_pnpc_driver); 904 if (!err) 930 if (!err) 905 pnpc_registered = 1; 931 pnpc_registered = 1; 906 932 907 if (isa_registered || pnp_registered) 933 if (isa_registered || pnp_registered) 908 err = 0; 934 err = 0; 909 #endif 935 #endif 910 return err; 936 return err; 911 } 937 } 912 938 913 static void __exit alsa_card_opl3sa2_exit(void 939 static void __exit alsa_card_opl3sa2_exit(void) 914 { 940 { 915 #ifdef CONFIG_PNP 941 #ifdef CONFIG_PNP 916 if (pnpc_registered) 942 if (pnpc_registered) 917 pnp_unregister_card_driver(&op 943 pnp_unregister_card_driver(&opl3sa2_pnpc_driver); 918 if (pnp_registered) 944 if (pnp_registered) 919 pnp_unregister_driver(&opl3sa2 945 pnp_unregister_driver(&opl3sa2_pnp_driver); 920 if (isa_registered) 946 if (isa_registered) 921 #endif 947 #endif 922 isa_unregister_driver(&snd_opl 948 isa_unregister_driver(&snd_opl3sa2_isa_driver); 923 } 949 } 924 950 925 module_init(alsa_card_opl3sa2_init) 951 module_init(alsa_card_opl3sa2_init) 926 module_exit(alsa_card_opl3sa2_exit) 952 module_exit(alsa_card_opl3sa2_exit) 927 953
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.