~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/sound/isa/opl3sa2.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /sound/isa/opl3sa2.c (Architecture mips) and /sound/isa/opl3sa2.c (Architecture sparc)


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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php