opl3sa2.c 32 KB

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