opl3sa2.c 30 KB

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