opl3sa2.c 30 KB

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