opti92x-ad1848.c 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. card-opti92x-ad1848.c - driver for OPTi 82c92x based soundcards.
  4. Copyright (C) 1998-2000 by Massimo Piccioni <[email protected]>
  5. Part of this code was developed at the Italian Ministry of Air Defence,
  6. Sixth Division (oh, che pace ...), Rome.
  7. Thanks to Maria Grazia Pollarini, Salvatore Vassallo.
  8. */
  9. #include <linux/init.h>
  10. #include <linux/err.h>
  11. #include <linux/isa.h>
  12. #include <linux/delay.h>
  13. #include <linux/pnp.h>
  14. #include <linux/module.h>
  15. #include <linux/io.h>
  16. #include <asm/dma.h>
  17. #include <sound/core.h>
  18. #include <sound/tlv.h>
  19. #include <sound/wss.h>
  20. #include <sound/mpu401.h>
  21. #include <sound/opl3.h>
  22. #ifndef OPTi93X
  23. #include <sound/opl4.h>
  24. #endif
  25. #define SNDRV_LEGACY_FIND_FREE_IOPORT
  26. #define SNDRV_LEGACY_FIND_FREE_IRQ
  27. #define SNDRV_LEGACY_FIND_FREE_DMA
  28. #include <sound/initval.h>
  29. MODULE_AUTHOR("Massimo Piccioni <[email protected]>");
  30. MODULE_LICENSE("GPL");
  31. #ifdef OPTi93X
  32. MODULE_DESCRIPTION("OPTi93X");
  33. #else /* OPTi93X */
  34. #ifdef CS4231
  35. MODULE_DESCRIPTION("OPTi92X - CS4231");
  36. #else /* CS4231 */
  37. MODULE_DESCRIPTION("OPTi92X - AD1848");
  38. #endif /* CS4231 */
  39. #endif /* OPTi93X */
  40. static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
  41. static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
  42. //static bool enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
  43. #ifdef CONFIG_PNP
  44. static bool isapnp = true; /* Enable ISA PnP detection */
  45. #endif
  46. static long port = SNDRV_DEFAULT_PORT1; /* 0x530,0xe80,0xf40,0x604 */
  47. static long mpu_port = SNDRV_DEFAULT_PORT1; /* 0x300,0x310,0x320,0x330 */
  48. static long fm_port = SNDRV_DEFAULT_PORT1; /* 0x388 */
  49. static int irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10,11 */
  50. static int mpu_irq = SNDRV_DEFAULT_IRQ1; /* 5,7,9,10 */
  51. static int dma1 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
  52. #if defined(CS4231) || defined(OPTi93X)
  53. static int dma2 = SNDRV_DEFAULT_DMA1; /* 0,1,3 */
  54. #endif /* CS4231 || OPTi93X */
  55. module_param(index, int, 0444);
  56. MODULE_PARM_DESC(index, "Index value for opti9xx based soundcard.");
  57. module_param(id, charp, 0444);
  58. MODULE_PARM_DESC(id, "ID string for opti9xx based soundcard.");
  59. //module_param(enable, bool, 0444);
  60. //MODULE_PARM_DESC(enable, "Enable opti9xx soundcard.");
  61. #ifdef CONFIG_PNP
  62. module_param(isapnp, bool, 0444);
  63. MODULE_PARM_DESC(isapnp, "Enable ISA PnP detection for specified soundcard.");
  64. #endif
  65. module_param_hw(port, long, ioport, 0444);
  66. MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
  67. module_param_hw(mpu_port, long, ioport, 0444);
  68. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
  69. module_param_hw(fm_port, long, ioport, 0444);
  70. MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
  71. module_param_hw(irq, int, irq, 0444);
  72. MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
  73. module_param_hw(mpu_irq, int, irq, 0444);
  74. MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
  75. module_param_hw(dma1, int, dma, 0444);
  76. MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
  77. #if defined(CS4231) || defined(OPTi93X)
  78. module_param_hw(dma2, int, dma, 0444);
  79. MODULE_PARM_DESC(dma2, "2nd dma # for opti9xx driver.");
  80. #endif /* CS4231 || OPTi93X */
  81. #define OPTi9XX_HW_82C928 1
  82. #define OPTi9XX_HW_82C929 2
  83. #define OPTi9XX_HW_82C924 3
  84. #define OPTi9XX_HW_82C925 4
  85. #define OPTi9XX_HW_82C930 5
  86. #define OPTi9XX_HW_82C931 6
  87. #define OPTi9XX_HW_82C933 7
  88. #define OPTi9XX_HW_LAST OPTi9XX_HW_82C933
  89. #define OPTi9XX_MC_REG(n) n
  90. #ifdef OPTi93X
  91. #define OPTi93X_STATUS 0x02
  92. #define OPTi93X_PORT(chip, r) ((chip)->port + OPTi93X_##r)
  93. #define OPTi93X_IRQ_PLAYBACK 0x04
  94. #define OPTi93X_IRQ_CAPTURE 0x08
  95. #endif /* OPTi93X */
  96. struct snd_opti9xx {
  97. unsigned short hardware;
  98. unsigned char password;
  99. char name[7];
  100. unsigned long mc_base;
  101. struct resource *res_mc_base;
  102. unsigned long mc_base_size;
  103. #ifdef OPTi93X
  104. unsigned long mc_indir_index;
  105. struct resource *res_mc_indir;
  106. #endif /* OPTi93X */
  107. struct snd_wss *codec;
  108. unsigned long pwd_reg;
  109. spinlock_t lock;
  110. long wss_base;
  111. int irq;
  112. };
  113. static int snd_opti9xx_pnp_is_probed;
  114. #ifdef CONFIG_PNP
  115. static const struct pnp_card_device_id snd_opti9xx_pnpids[] = {
  116. #ifndef OPTi93X
  117. /* OPTi 82C924 */
  118. { .id = "OPT0924",
  119. .devs = { { "OPT0000" }, { "OPT0002" }, { "OPT0005" } },
  120. .driver_data = 0x0924 },
  121. /* OPTi 82C925 */
  122. { .id = "OPT0925",
  123. .devs = { { "OPT9250" }, { "OPT0002" }, { "OPT0005" } },
  124. .driver_data = 0x0925 },
  125. #else
  126. /* OPTi 82C931/3 */
  127. { .id = "OPT0931", .devs = { { "OPT9310" }, { "OPT0002" } },
  128. .driver_data = 0x0931 },
  129. #endif /* OPTi93X */
  130. { .id = "" }
  131. };
  132. MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
  133. #endif /* CONFIG_PNP */
  134. #define DEV_NAME KBUILD_MODNAME
  135. static const char * const snd_opti9xx_names[] = {
  136. "unknown",
  137. "82C928", "82C929",
  138. "82C924", "82C925",
  139. "82C930", "82C931", "82C933"
  140. };
  141. static int snd_opti9xx_init(struct snd_opti9xx *chip,
  142. unsigned short hardware)
  143. {
  144. static const int opti9xx_mc_size[] = {7, 7, 10, 10, 2, 2, 2};
  145. chip->hardware = hardware;
  146. strcpy(chip->name, snd_opti9xx_names[hardware]);
  147. spin_lock_init(&chip->lock);
  148. chip->irq = -1;
  149. #ifndef OPTi93X
  150. #ifdef CONFIG_PNP
  151. if (isapnp && chip->mc_base)
  152. /* PnP resource gives the least 10 bits */
  153. chip->mc_base |= 0xc00;
  154. else
  155. #endif /* CONFIG_PNP */
  156. {
  157. chip->mc_base = 0xf8c;
  158. chip->mc_base_size = opti9xx_mc_size[hardware];
  159. }
  160. #else
  161. chip->mc_base_size = opti9xx_mc_size[hardware];
  162. #endif
  163. switch (hardware) {
  164. #ifndef OPTi93X
  165. case OPTi9XX_HW_82C928:
  166. case OPTi9XX_HW_82C929:
  167. chip->password = (hardware == OPTi9XX_HW_82C928) ? 0xe2 : 0xe3;
  168. chip->pwd_reg = 3;
  169. break;
  170. case OPTi9XX_HW_82C924:
  171. case OPTi9XX_HW_82C925:
  172. chip->password = 0xe5;
  173. chip->pwd_reg = 3;
  174. break;
  175. #else /* OPTi93X */
  176. case OPTi9XX_HW_82C930:
  177. case OPTi9XX_HW_82C931:
  178. case OPTi9XX_HW_82C933:
  179. chip->mc_base = (hardware == OPTi9XX_HW_82C930) ? 0xf8f : 0xf8d;
  180. if (!chip->mc_indir_index)
  181. chip->mc_indir_index = 0xe0e;
  182. chip->password = 0xe4;
  183. chip->pwd_reg = 0;
  184. break;
  185. #endif /* OPTi93X */
  186. default:
  187. snd_printk(KERN_ERR "chip %d not supported\n", hardware);
  188. return -ENODEV;
  189. }
  190. return 0;
  191. }
  192. static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
  193. unsigned char reg)
  194. {
  195. unsigned long flags;
  196. unsigned char retval = 0xff;
  197. spin_lock_irqsave(&chip->lock, flags);
  198. outb(chip->password, chip->mc_base + chip->pwd_reg);
  199. switch (chip->hardware) {
  200. #ifndef OPTi93X
  201. case OPTi9XX_HW_82C924:
  202. case OPTi9XX_HW_82C925:
  203. if (reg > 7) {
  204. outb(reg, chip->mc_base + 8);
  205. outb(chip->password, chip->mc_base + chip->pwd_reg);
  206. retval = inb(chip->mc_base + 9);
  207. break;
  208. }
  209. fallthrough;
  210. case OPTi9XX_HW_82C928:
  211. case OPTi9XX_HW_82C929:
  212. retval = inb(chip->mc_base + reg);
  213. break;
  214. #else /* OPTi93X */
  215. case OPTi9XX_HW_82C930:
  216. case OPTi9XX_HW_82C931:
  217. case OPTi9XX_HW_82C933:
  218. outb(reg, chip->mc_indir_index);
  219. outb(chip->password, chip->mc_base + chip->pwd_reg);
  220. retval = inb(chip->mc_indir_index + 1);
  221. break;
  222. #endif /* OPTi93X */
  223. default:
  224. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  225. }
  226. spin_unlock_irqrestore(&chip->lock, flags);
  227. return retval;
  228. }
  229. static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
  230. unsigned char value)
  231. {
  232. unsigned long flags;
  233. spin_lock_irqsave(&chip->lock, flags);
  234. outb(chip->password, chip->mc_base + chip->pwd_reg);
  235. switch (chip->hardware) {
  236. #ifndef OPTi93X
  237. case OPTi9XX_HW_82C924:
  238. case OPTi9XX_HW_82C925:
  239. if (reg > 7) {
  240. outb(reg, chip->mc_base + 8);
  241. outb(chip->password, chip->mc_base + chip->pwd_reg);
  242. outb(value, chip->mc_base + 9);
  243. break;
  244. }
  245. fallthrough;
  246. case OPTi9XX_HW_82C928:
  247. case OPTi9XX_HW_82C929:
  248. outb(value, chip->mc_base + reg);
  249. break;
  250. #else /* OPTi93X */
  251. case OPTi9XX_HW_82C930:
  252. case OPTi9XX_HW_82C931:
  253. case OPTi9XX_HW_82C933:
  254. outb(reg, chip->mc_indir_index);
  255. outb(chip->password, chip->mc_base + chip->pwd_reg);
  256. outb(value, chip->mc_indir_index + 1);
  257. break;
  258. #endif /* OPTi93X */
  259. default:
  260. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  261. }
  262. spin_unlock_irqrestore(&chip->lock, flags);
  263. }
  264. static inline void snd_opti9xx_write_mask(struct snd_opti9xx *chip,
  265. unsigned char reg, unsigned char value, unsigned char mask)
  266. {
  267. unsigned char oldval = snd_opti9xx_read(chip, reg);
  268. snd_opti9xx_write(chip, reg, (oldval & ~mask) | (value & mask));
  269. }
  270. static int snd_opti9xx_configure(struct snd_opti9xx *chip,
  271. long port,
  272. int irq, int dma1, int dma2,
  273. long mpu_port, int mpu_irq)
  274. {
  275. unsigned char wss_base_bits;
  276. unsigned char irq_bits;
  277. unsigned char dma_bits;
  278. unsigned char mpu_port_bits = 0;
  279. unsigned char mpu_irq_bits;
  280. switch (chip->hardware) {
  281. #ifndef OPTi93X
  282. case OPTi9XX_HW_82C924:
  283. /* opti 929 mode (?), OPL3 clock output, audio enable */
  284. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
  285. /* enable wave audio */
  286. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  287. fallthrough;
  288. case OPTi9XX_HW_82C925:
  289. /* enable WSS mode */
  290. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  291. /* OPL3 FM synthesis */
  292. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
  293. /* disable Sound Blaster IRQ and DMA */
  294. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  295. #ifdef CS4231
  296. /* cs4231/4248 fix enabled */
  297. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  298. #else
  299. /* cs4231/4248 fix disabled */
  300. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
  301. #endif /* CS4231 */
  302. break;
  303. case OPTi9XX_HW_82C928:
  304. case OPTi9XX_HW_82C929:
  305. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  306. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
  307. /*
  308. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
  309. */
  310. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  311. #ifdef CS4231
  312. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  313. #else
  314. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
  315. #endif /* CS4231 */
  316. break;
  317. #else /* OPTi93X */
  318. case OPTi9XX_HW_82C931:
  319. /* disable 3D sound (set GPIO1 as output, low) */
  320. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(20), 0x04, 0x0c);
  321. fallthrough;
  322. case OPTi9XX_HW_82C933:
  323. /*
  324. * The BTC 1817DW has QS1000 wavetable which is connected
  325. * to the serial digital input of the OPTI931.
  326. */
  327. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
  328. /*
  329. * This bit sets OPTI931 to automaticaly select FM
  330. * or digital input signal.
  331. */
  332. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
  333. fallthrough;
  334. case OPTi9XX_HW_82C930:
  335. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
  336. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
  337. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
  338. (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
  339. 0x34);
  340. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
  341. break;
  342. #endif /* OPTi93X */
  343. default:
  344. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  345. return -EINVAL;
  346. }
  347. /* PnP resource says it decodes only 10 bits of address */
  348. switch (port & 0x3ff) {
  349. case 0x130:
  350. chip->wss_base = 0x530;
  351. wss_base_bits = 0x00;
  352. break;
  353. case 0x204:
  354. chip->wss_base = 0x604;
  355. wss_base_bits = 0x03;
  356. break;
  357. case 0x280:
  358. chip->wss_base = 0xe80;
  359. wss_base_bits = 0x01;
  360. break;
  361. case 0x340:
  362. chip->wss_base = 0xf40;
  363. wss_base_bits = 0x02;
  364. break;
  365. default:
  366. snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port);
  367. goto __skip_base;
  368. }
  369. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  370. __skip_base:
  371. switch (irq) {
  372. //#ifdef OPTi93X
  373. case 5:
  374. irq_bits = 0x05;
  375. break;
  376. //#endif /* OPTi93X */
  377. case 7:
  378. irq_bits = 0x01;
  379. break;
  380. case 9:
  381. irq_bits = 0x02;
  382. break;
  383. case 10:
  384. irq_bits = 0x03;
  385. break;
  386. case 11:
  387. irq_bits = 0x04;
  388. break;
  389. default:
  390. snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
  391. goto __skip_resources;
  392. }
  393. switch (dma1) {
  394. case 0:
  395. dma_bits = 0x01;
  396. break;
  397. case 1:
  398. dma_bits = 0x02;
  399. break;
  400. case 3:
  401. dma_bits = 0x03;
  402. break;
  403. default:
  404. snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
  405. goto __skip_resources;
  406. }
  407. #if defined(CS4231) || defined(OPTi93X)
  408. if (dma1 == dma2) {
  409. snd_printk(KERN_ERR "don't want to share dmas\n");
  410. return -EBUSY;
  411. }
  412. switch (dma2) {
  413. case 0:
  414. case 1:
  415. break;
  416. default:
  417. snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
  418. goto __skip_resources;
  419. }
  420. dma_bits |= 0x04;
  421. #endif /* CS4231 || OPTi93X */
  422. #ifndef OPTi93X
  423. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  424. #else /* OPTi93X */
  425. snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
  426. #endif /* OPTi93X */
  427. __skip_resources:
  428. if (chip->hardware > OPTi9XX_HW_82C928) {
  429. switch (mpu_port) {
  430. case 0:
  431. case -1:
  432. break;
  433. case 0x300:
  434. mpu_port_bits = 0x03;
  435. break;
  436. case 0x310:
  437. mpu_port_bits = 0x02;
  438. break;
  439. case 0x320:
  440. mpu_port_bits = 0x01;
  441. break;
  442. case 0x330:
  443. mpu_port_bits = 0x00;
  444. break;
  445. default:
  446. snd_printk(KERN_WARNING
  447. "MPU-401 port 0x%lx not valid\n", mpu_port);
  448. goto __skip_mpu;
  449. }
  450. switch (mpu_irq) {
  451. case 5:
  452. mpu_irq_bits = 0x02;
  453. break;
  454. case 7:
  455. mpu_irq_bits = 0x03;
  456. break;
  457. case 9:
  458. mpu_irq_bits = 0x00;
  459. break;
  460. case 10:
  461. mpu_irq_bits = 0x01;
  462. break;
  463. default:
  464. snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
  465. mpu_irq);
  466. goto __skip_mpu;
  467. }
  468. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
  469. (mpu_port <= 0) ? 0x00 :
  470. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  471. 0xf8);
  472. }
  473. __skip_mpu:
  474. return 0;
  475. }
  476. #ifdef OPTi93X
  477. static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
  478. static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
  479. static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
  480. static const struct snd_kcontrol_new snd_opti93x_controls[] = {
  481. WSS_DOUBLE("Master Playback Switch", 0,
  482. OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
  483. WSS_DOUBLE_TLV("Master Playback Volume", 0,
  484. OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
  485. db_scale_5bit_3db_step),
  486. WSS_DOUBLE_TLV("PCM Playback Volume", 0,
  487. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
  488. db_scale_5bit),
  489. WSS_DOUBLE_TLV("FM Playback Volume", 0,
  490. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
  491. db_scale_4bit_12db_max),
  492. WSS_DOUBLE("Line Playback Switch", 0,
  493. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  494. WSS_DOUBLE_TLV("Line Playback Volume", 0,
  495. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
  496. db_scale_4bit_12db_max),
  497. WSS_DOUBLE("Mic Playback Switch", 0,
  498. OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
  499. WSS_DOUBLE_TLV("Mic Playback Volume", 0,
  500. OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
  501. db_scale_4bit_12db_max),
  502. WSS_DOUBLE_TLV("CD Playback Volume", 0,
  503. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
  504. db_scale_4bit_12db_max),
  505. WSS_DOUBLE("Aux Playback Switch", 0,
  506. OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
  507. WSS_DOUBLE_TLV("Aux Playback Volume", 0,
  508. OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
  509. db_scale_4bit_12db_max),
  510. };
  511. static int snd_opti93x_mixer(struct snd_wss *chip)
  512. {
  513. struct snd_card *card;
  514. unsigned int idx;
  515. struct snd_ctl_elem_id id1, id2;
  516. int err;
  517. if (snd_BUG_ON(!chip || !chip->pcm))
  518. return -EINVAL;
  519. card = chip->card;
  520. strcpy(card->mixername, chip->pcm->name);
  521. memset(&id1, 0, sizeof(id1));
  522. memset(&id2, 0, sizeof(id2));
  523. id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  524. /* reassign AUX0 switch to CD */
  525. strcpy(id1.name, "Aux Playback Switch");
  526. strcpy(id2.name, "CD Playback Switch");
  527. err = snd_ctl_rename_id(card, &id1, &id2);
  528. if (err < 0) {
  529. snd_printk(KERN_ERR "Cannot rename opti93x control\n");
  530. return err;
  531. }
  532. /* reassign AUX1 switch to FM */
  533. strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
  534. strcpy(id2.name, "FM Playback Switch");
  535. err = snd_ctl_rename_id(card, &id1, &id2);
  536. if (err < 0) {
  537. snd_printk(KERN_ERR "Cannot rename opti93x control\n");
  538. return err;
  539. }
  540. /* remove AUX1 volume */
  541. strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
  542. snd_ctl_remove_id(card, &id1);
  543. /* Replace WSS volume controls with OPTi93x volume controls */
  544. id1.index = 0;
  545. for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
  546. strcpy(id1.name, snd_opti93x_controls[idx].name);
  547. snd_ctl_remove_id(card, &id1);
  548. err = snd_ctl_add(card,
  549. snd_ctl_new1(&snd_opti93x_controls[idx], chip));
  550. if (err < 0)
  551. return err;
  552. }
  553. return 0;
  554. }
  555. static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
  556. {
  557. struct snd_opti9xx *chip = dev_id;
  558. struct snd_wss *codec = chip->codec;
  559. unsigned char status;
  560. if (!codec)
  561. return IRQ_HANDLED;
  562. status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
  563. if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
  564. snd_pcm_period_elapsed(codec->playback_substream);
  565. if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
  566. snd_wss_overrange(codec);
  567. snd_pcm_period_elapsed(codec->capture_substream);
  568. }
  569. outb(0x00, OPTi93X_PORT(codec, STATUS));
  570. return IRQ_HANDLED;
  571. }
  572. #endif /* OPTi93X */
  573. static int snd_opti9xx_read_check(struct snd_card *card,
  574. struct snd_opti9xx *chip)
  575. {
  576. unsigned char value;
  577. #ifdef OPTi93X
  578. unsigned long flags;
  579. #endif
  580. chip->res_mc_base =
  581. devm_request_region(card->dev, chip->mc_base,
  582. chip->mc_base_size, "OPTi9xx MC");
  583. if (!chip->res_mc_base)
  584. return -EBUSY;
  585. #ifndef OPTi93X
  586. value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
  587. if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
  588. if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
  589. return 0;
  590. #else /* OPTi93X */
  591. chip->res_mc_indir =
  592. devm_request_region(card->dev, chip->mc_indir_index, 2,
  593. "OPTi93x MC");
  594. if (!chip->res_mc_indir)
  595. return -EBUSY;
  596. spin_lock_irqsave(&chip->lock, flags);
  597. outb(chip->password, chip->mc_base + chip->pwd_reg);
  598. outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
  599. spin_unlock_irqrestore(&chip->lock, flags);
  600. value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
  601. snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
  602. if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
  603. return 0;
  604. devm_release_resource(card->dev, chip->res_mc_indir);
  605. chip->res_mc_indir = NULL;
  606. #endif /* OPTi93X */
  607. devm_release_resource(card->dev, chip->res_mc_base);
  608. chip->res_mc_base = NULL;
  609. return -ENODEV;
  610. }
  611. static int snd_card_opti9xx_detect(struct snd_card *card,
  612. struct snd_opti9xx *chip)
  613. {
  614. int i, err;
  615. #ifndef OPTi93X
  616. for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
  617. #else
  618. for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
  619. #endif
  620. err = snd_opti9xx_init(chip, i);
  621. if (err < 0)
  622. return err;
  623. err = snd_opti9xx_read_check(card, chip);
  624. if (err == 0)
  625. return 1;
  626. #ifdef OPTi93X
  627. chip->mc_indir_index = 0;
  628. #endif
  629. }
  630. return -ENODEV;
  631. }
  632. #ifdef CONFIG_PNP
  633. static int snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
  634. struct pnp_card_link *card,
  635. const struct pnp_card_device_id *pid)
  636. {
  637. struct pnp_dev *pdev;
  638. int err;
  639. struct pnp_dev *devmpu;
  640. #ifndef OPTi93X
  641. struct pnp_dev *devmc;
  642. #endif
  643. pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
  644. if (pdev == NULL)
  645. return -EBUSY;
  646. err = pnp_activate_dev(pdev);
  647. if (err < 0) {
  648. snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
  649. return err;
  650. }
  651. #ifdef OPTi93X
  652. port = pnp_port_start(pdev, 0) - 4;
  653. fm_port = pnp_port_start(pdev, 1) + 8;
  654. /* adjust mc_indir_index - some cards report it at 0xe?d,
  655. other at 0xe?c but it really is always at 0xe?e */
  656. chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0xe;
  657. #else
  658. devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
  659. if (devmc == NULL)
  660. return -EBUSY;
  661. err = pnp_activate_dev(devmc);
  662. if (err < 0) {
  663. snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err);
  664. return err;
  665. }
  666. port = pnp_port_start(pdev, 1);
  667. fm_port = pnp_port_start(pdev, 2) + 8;
  668. /*
  669. * The MC(0) is never accessed and card does not
  670. * include it in the PnP resource range. OPTI93x include it.
  671. */
  672. chip->mc_base = pnp_port_start(devmc, 0) - 1;
  673. chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
  674. #endif /* OPTi93X */
  675. irq = pnp_irq(pdev, 0);
  676. dma1 = pnp_dma(pdev, 0);
  677. #if defined(CS4231) || defined(OPTi93X)
  678. dma2 = pnp_dma(pdev, 1);
  679. #endif /* CS4231 || OPTi93X */
  680. devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
  681. if (devmpu && mpu_port > 0) {
  682. err = pnp_activate_dev(devmpu);
  683. if (err < 0) {
  684. snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
  685. mpu_port = -1;
  686. } else {
  687. mpu_port = pnp_port_start(devmpu, 0);
  688. mpu_irq = pnp_irq(devmpu, 0);
  689. }
  690. }
  691. return pid->driver_data;
  692. }
  693. #endif /* CONFIG_PNP */
  694. static int snd_opti9xx_probe(struct snd_card *card)
  695. {
  696. static const long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  697. int error;
  698. int xdma2;
  699. struct snd_opti9xx *chip = card->private_data;
  700. struct snd_wss *codec;
  701. struct snd_rawmidi *rmidi;
  702. struct snd_hwdep *synth;
  703. #if defined(CS4231) || defined(OPTi93X)
  704. xdma2 = dma2;
  705. #else
  706. xdma2 = -1;
  707. #endif
  708. if (port == SNDRV_AUTO_PORT) {
  709. port = snd_legacy_find_free_ioport(possible_ports, 4);
  710. if (port < 0) {
  711. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  712. return -EBUSY;
  713. }
  714. }
  715. error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
  716. mpu_port, mpu_irq);
  717. if (error)
  718. return error;
  719. error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2,
  720. #ifdef OPTi93X
  721. WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
  722. #else
  723. WSS_HW_DETECT, 0,
  724. #endif
  725. &codec);
  726. if (error < 0)
  727. return error;
  728. chip->codec = codec;
  729. error = snd_wss_pcm(codec, 0);
  730. if (error < 0)
  731. return error;
  732. error = snd_wss_mixer(codec);
  733. if (error < 0)
  734. return error;
  735. #ifdef OPTi93X
  736. error = snd_opti93x_mixer(codec);
  737. if (error < 0)
  738. return error;
  739. #endif
  740. #ifdef CS4231
  741. error = snd_wss_timer(codec, 0);
  742. if (error < 0)
  743. return error;
  744. #endif
  745. #ifdef OPTi93X
  746. error = devm_request_irq(card->dev, irq, snd_opti93x_interrupt,
  747. 0, DEV_NAME" - WSS", chip);
  748. if (error < 0) {
  749. snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
  750. return error;
  751. }
  752. #endif
  753. chip->irq = irq;
  754. card->sync_irq = chip->irq;
  755. strcpy(card->driver, chip->name);
  756. sprintf(card->shortname, "OPTi %s", card->driver);
  757. #if defined(CS4231) || defined(OPTi93X)
  758. snprintf(card->longname, sizeof(card->longname),
  759. "%s, %s at 0x%lx, irq %d, dma %d&%d",
  760. card->shortname, codec->pcm->name,
  761. chip->wss_base + 4, irq, dma1, xdma2);
  762. #else
  763. snprintf(card->longname, sizeof(card->longname),
  764. "%s, %s at 0x%lx, irq %d, dma %d",
  765. card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
  766. dma1);
  767. #endif /* CS4231 || OPTi93X */
  768. if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
  769. rmidi = NULL;
  770. else {
  771. error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  772. mpu_port, 0, mpu_irq, &rmidi);
  773. if (error)
  774. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
  775. mpu_port);
  776. }
  777. if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
  778. struct snd_opl3 *opl3 = NULL;
  779. #ifndef OPTi93X
  780. if (chip->hardware == OPTi9XX_HW_82C928 ||
  781. chip->hardware == OPTi9XX_HW_82C929 ||
  782. chip->hardware == OPTi9XX_HW_82C924) {
  783. struct snd_opl4 *opl4;
  784. /* assume we have an OPL4 */
  785. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
  786. 0x20, 0x20);
  787. if (snd_opl4_create(card, fm_port, fm_port - 8,
  788. 2, &opl3, &opl4) < 0) {
  789. /* no luck, use OPL3 instead */
  790. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
  791. 0x00, 0x20);
  792. }
  793. }
  794. #endif /* !OPTi93X */
  795. if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
  796. OPL3_HW_AUTO, 0, &opl3) < 0) {
  797. snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
  798. fm_port, fm_port + 4 - 1);
  799. }
  800. if (opl3) {
  801. error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
  802. if (error < 0)
  803. return error;
  804. }
  805. }
  806. return snd_card_register(card);
  807. }
  808. static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
  809. {
  810. struct snd_card *card;
  811. int err;
  812. err = snd_devm_card_new(pdev, index, id, THIS_MODULE,
  813. sizeof(struct snd_opti9xx), &card);
  814. if (err < 0)
  815. return err;
  816. *cardp = card;
  817. return 0;
  818. }
  819. static int snd_opti9xx_isa_match(struct device *devptr,
  820. unsigned int dev)
  821. {
  822. #ifdef CONFIG_PNP
  823. if (snd_opti9xx_pnp_is_probed)
  824. return 0;
  825. if (isapnp)
  826. return 0;
  827. #endif
  828. return 1;
  829. }
  830. static int snd_opti9xx_isa_probe(struct device *devptr,
  831. unsigned int dev)
  832. {
  833. struct snd_card *card;
  834. int error;
  835. static const long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
  836. #ifdef OPTi93X
  837. static const int possible_irqs[] = {5, 9, 10, 11, 7, -1};
  838. #else
  839. static const int possible_irqs[] = {9, 10, 11, 7, -1};
  840. #endif /* OPTi93X */
  841. static const int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
  842. static const int possible_dma1s[] = {3, 1, 0, -1};
  843. #if defined(CS4231) || defined(OPTi93X)
  844. static const int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
  845. #endif /* CS4231 || OPTi93X */
  846. if (mpu_port == SNDRV_AUTO_PORT) {
  847. mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2);
  848. if (mpu_port < 0) {
  849. snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
  850. return -EBUSY;
  851. }
  852. }
  853. if (irq == SNDRV_AUTO_IRQ) {
  854. irq = snd_legacy_find_free_irq(possible_irqs);
  855. if (irq < 0) {
  856. snd_printk(KERN_ERR "unable to find a free IRQ\n");
  857. return -EBUSY;
  858. }
  859. }
  860. if (mpu_irq == SNDRV_AUTO_IRQ) {
  861. mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs);
  862. if (mpu_irq < 0) {
  863. snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
  864. return -EBUSY;
  865. }
  866. }
  867. if (dma1 == SNDRV_AUTO_DMA) {
  868. dma1 = snd_legacy_find_free_dma(possible_dma1s);
  869. if (dma1 < 0) {
  870. snd_printk(KERN_ERR "unable to find a free DMA1\n");
  871. return -EBUSY;
  872. }
  873. }
  874. #if defined(CS4231) || defined(OPTi93X)
  875. if (dma2 == SNDRV_AUTO_DMA) {
  876. dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4]);
  877. if (dma2 < 0) {
  878. snd_printk(KERN_ERR "unable to find a free DMA2\n");
  879. return -EBUSY;
  880. }
  881. }
  882. #endif
  883. error = snd_opti9xx_card_new(devptr, &card);
  884. if (error < 0)
  885. return error;
  886. error = snd_card_opti9xx_detect(card, card->private_data);
  887. if (error < 0)
  888. return error;
  889. error = snd_opti9xx_probe(card);
  890. if (error < 0)
  891. return error;
  892. dev_set_drvdata(devptr, card);
  893. return 0;
  894. }
  895. #ifdef CONFIG_PM
  896. static int snd_opti9xx_suspend(struct snd_card *card)
  897. {
  898. struct snd_opti9xx *chip = card->private_data;
  899. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  900. chip->codec->suspend(chip->codec);
  901. return 0;
  902. }
  903. static int snd_opti9xx_resume(struct snd_card *card)
  904. {
  905. struct snd_opti9xx *chip = card->private_data;
  906. int error, xdma2;
  907. #if defined(CS4231) || defined(OPTi93X)
  908. xdma2 = dma2;
  909. #else
  910. xdma2 = -1;
  911. #endif
  912. error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
  913. mpu_port, mpu_irq);
  914. if (error)
  915. return error;
  916. chip->codec->resume(chip->codec);
  917. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  918. return 0;
  919. }
  920. static int snd_opti9xx_isa_suspend(struct device *dev, unsigned int n,
  921. pm_message_t state)
  922. {
  923. return snd_opti9xx_suspend(dev_get_drvdata(dev));
  924. }
  925. static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n)
  926. {
  927. return snd_opti9xx_resume(dev_get_drvdata(dev));
  928. }
  929. #endif
  930. static struct isa_driver snd_opti9xx_driver = {
  931. .match = snd_opti9xx_isa_match,
  932. .probe = snd_opti9xx_isa_probe,
  933. #ifdef CONFIG_PM
  934. .suspend = snd_opti9xx_isa_suspend,
  935. .resume = snd_opti9xx_isa_resume,
  936. #endif
  937. .driver = {
  938. .name = DEV_NAME
  939. },
  940. };
  941. #ifdef CONFIG_PNP
  942. static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
  943. const struct pnp_card_device_id *pid)
  944. {
  945. struct snd_card *card;
  946. int error, hw;
  947. struct snd_opti9xx *chip;
  948. if (snd_opti9xx_pnp_is_probed)
  949. return -EBUSY;
  950. if (! isapnp)
  951. return -ENODEV;
  952. error = snd_opti9xx_card_new(&pcard->card->dev, &card);
  953. if (error < 0)
  954. return error;
  955. chip = card->private_data;
  956. hw = snd_card_opti9xx_pnp(chip, pcard, pid);
  957. switch (hw) {
  958. case 0x0924:
  959. hw = OPTi9XX_HW_82C924;
  960. break;
  961. case 0x0925:
  962. hw = OPTi9XX_HW_82C925;
  963. break;
  964. case 0x0931:
  965. hw = OPTi9XX_HW_82C931;
  966. break;
  967. default:
  968. return -ENODEV;
  969. }
  970. error = snd_opti9xx_init(chip, hw);
  971. if (error)
  972. return error;
  973. error = snd_opti9xx_read_check(card, chip);
  974. if (error) {
  975. snd_printk(KERN_ERR "OPTI chip not found\n");
  976. return error;
  977. }
  978. error = snd_opti9xx_probe(card);
  979. if (error < 0)
  980. return error;
  981. pnp_set_card_drvdata(pcard, card);
  982. snd_opti9xx_pnp_is_probed = 1;
  983. return 0;
  984. }
  985. static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
  986. {
  987. snd_opti9xx_pnp_is_probed = 0;
  988. }
  989. #ifdef CONFIG_PM
  990. static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
  991. pm_message_t state)
  992. {
  993. return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
  994. }
  995. static int snd_opti9xx_pnp_resume(struct pnp_card_link *pcard)
  996. {
  997. return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
  998. }
  999. #endif
  1000. static struct pnp_card_driver opti9xx_pnpc_driver = {
  1001. .flags = PNP_DRIVER_RES_DISABLE,
  1002. .name = DEV_NAME,
  1003. .id_table = snd_opti9xx_pnpids,
  1004. .probe = snd_opti9xx_pnp_probe,
  1005. .remove = snd_opti9xx_pnp_remove,
  1006. #ifdef CONFIG_PM
  1007. .suspend = snd_opti9xx_pnp_suspend,
  1008. .resume = snd_opti9xx_pnp_resume,
  1009. #endif
  1010. };
  1011. #endif
  1012. #ifdef OPTi93X
  1013. #define CHIP_NAME "82C93x"
  1014. #else
  1015. #define CHIP_NAME "82C92x"
  1016. #endif
  1017. static int __init alsa_card_opti9xx_init(void)
  1018. {
  1019. #ifdef CONFIG_PNP
  1020. pnp_register_card_driver(&opti9xx_pnpc_driver);
  1021. if (snd_opti9xx_pnp_is_probed)
  1022. return 0;
  1023. pnp_unregister_card_driver(&opti9xx_pnpc_driver);
  1024. #endif
  1025. return isa_register_driver(&snd_opti9xx_driver, 1);
  1026. }
  1027. static void __exit alsa_card_opti9xx_exit(void)
  1028. {
  1029. if (!snd_opti9xx_pnp_is_probed) {
  1030. isa_unregister_driver(&snd_opti9xx_driver);
  1031. return;
  1032. }
  1033. #ifdef CONFIG_PNP
  1034. pnp_unregister_card_driver(&opti9xx_pnpc_driver);
  1035. #endif
  1036. }
  1037. module_init(alsa_card_opti9xx_init)
  1038. module_exit(alsa_card_opti9xx_exit)