opti92x-ad1848.c 30 KB

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