opl3sa2.c 30 KB

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