opti92x-ad1848.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207
  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_hw(port, long, ioport, 0444);
  82. MODULE_PARM_DESC(port, "WSS port # for opti9xx driver.");
  83. module_param_hw(mpu_port, long, ioport, 0444);
  84. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for opti9xx driver.");
  85. module_param_hw(fm_port, long, ioport, 0444);
  86. MODULE_PARM_DESC(fm_port, "FM port # for opti9xx driver.");
  87. module_param_hw(irq, int, irq, 0444);
  88. MODULE_PARM_DESC(irq, "WSS irq # for opti9xx driver.");
  89. module_param_hw(mpu_irq, int, irq, 0444);
  90. MODULE_PARM_DESC(mpu_irq, "MPU-401 irq # for opti9xx driver.");
  91. module_param_hw(dma1, int, dma, 0444);
  92. MODULE_PARM_DESC(dma1, "1st dma # for opti9xx driver.");
  93. #if defined(CS4231) || defined(OPTi93X)
  94. module_param_hw(dma2, int, dma, 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 const 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. static inline void snd_opti9xx_write_mask(struct snd_opti9xx *chip,
  279. unsigned char reg, unsigned char value, unsigned char mask)
  280. {
  281. unsigned char oldval = snd_opti9xx_read(chip, reg);
  282. snd_opti9xx_write(chip, reg, (oldval & ~mask) | (value & mask));
  283. }
  284. static int snd_opti9xx_configure(struct snd_opti9xx *chip,
  285. long port,
  286. int irq, int dma1, int dma2,
  287. long mpu_port, int mpu_irq)
  288. {
  289. unsigned char wss_base_bits;
  290. unsigned char irq_bits;
  291. unsigned char dma_bits;
  292. unsigned char mpu_port_bits = 0;
  293. unsigned char mpu_irq_bits;
  294. switch (chip->hardware) {
  295. #ifndef OPTi93X
  296. case OPTi9XX_HW_82C924:
  297. /* opti 929 mode (?), OPL3 clock output, audio enable */
  298. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0xf0, 0xfc);
  299. /* enable wave audio */
  300. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x02);
  301. case OPTi9XX_HW_82C925:
  302. /* enable WSS mode */
  303. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  304. /* OPL3 FM synthesis */
  305. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
  306. /* disable Sound Blaster IRQ and DMA */
  307. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xf0, 0xff);
  308. #ifdef CS4231
  309. /* cs4231/4248 fix enabled */
  310. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  311. #else
  312. /* cs4231/4248 fix disabled */
  313. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
  314. #endif /* CS4231 */
  315. break;
  316. case OPTi9XX_HW_82C928:
  317. case OPTi9XX_HW_82C929:
  318. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), 0x80, 0x80);
  319. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2), 0x00, 0x20);
  320. /*
  321. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0xa2, 0xae);
  322. */
  323. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x00, 0x0c);
  324. #ifdef CS4231
  325. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x02, 0x02);
  326. #else
  327. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x00, 0x02);
  328. #endif /* CS4231 */
  329. break;
  330. #else /* OPTi93X */
  331. case OPTi9XX_HW_82C931:
  332. /* disable 3D sound (set GPIO1 as output, low) */
  333. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(20), 0x04, 0x0c);
  334. case OPTi9XX_HW_82C933: /* FALL THROUGH */
  335. /*
  336. * The BTC 1817DW has QS1000 wavetable which is connected
  337. * to the serial digital input of the OPTI931.
  338. */
  339. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(21), 0x82, 0xff);
  340. /*
  341. * This bit sets OPTI931 to automaticaly select FM
  342. * or digital input signal.
  343. */
  344. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(26), 0x01, 0x01);
  345. case OPTi9XX_HW_82C930: /* FALL THROUGH */
  346. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6), 0x02, 0x03);
  347. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(3), 0x00, 0xff);
  348. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(4), 0x10 |
  349. (chip->hardware == OPTi9XX_HW_82C930 ? 0x00 : 0x04),
  350. 0x34);
  351. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(5), 0x20, 0xbf);
  352. break;
  353. #endif /* OPTi93X */
  354. default:
  355. snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
  356. return -EINVAL;
  357. }
  358. /* PnP resource says it decodes only 10 bits of address */
  359. switch (port & 0x3ff) {
  360. case 0x130:
  361. chip->wss_base = 0x530;
  362. wss_base_bits = 0x00;
  363. break;
  364. case 0x204:
  365. chip->wss_base = 0x604;
  366. wss_base_bits = 0x03;
  367. break;
  368. case 0x280:
  369. chip->wss_base = 0xe80;
  370. wss_base_bits = 0x01;
  371. break;
  372. case 0x340:
  373. chip->wss_base = 0xf40;
  374. wss_base_bits = 0x02;
  375. break;
  376. default:
  377. snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", port);
  378. goto __skip_base;
  379. }
  380. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
  381. __skip_base:
  382. switch (irq) {
  383. //#ifdef OPTi93X
  384. case 5:
  385. irq_bits = 0x05;
  386. break;
  387. //#endif /* OPTi93X */
  388. case 7:
  389. irq_bits = 0x01;
  390. break;
  391. case 9:
  392. irq_bits = 0x02;
  393. break;
  394. case 10:
  395. irq_bits = 0x03;
  396. break;
  397. case 11:
  398. irq_bits = 0x04;
  399. break;
  400. default:
  401. snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
  402. goto __skip_resources;
  403. }
  404. switch (dma1) {
  405. case 0:
  406. dma_bits = 0x01;
  407. break;
  408. case 1:
  409. dma_bits = 0x02;
  410. break;
  411. case 3:
  412. dma_bits = 0x03;
  413. break;
  414. default:
  415. snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
  416. goto __skip_resources;
  417. }
  418. #if defined(CS4231) || defined(OPTi93X)
  419. if (dma1 == dma2) {
  420. snd_printk(KERN_ERR "don't want to share dmas\n");
  421. return -EBUSY;
  422. }
  423. switch (dma2) {
  424. case 0:
  425. case 1:
  426. break;
  427. default:
  428. snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
  429. goto __skip_resources;
  430. }
  431. dma_bits |= 0x04;
  432. #endif /* CS4231 || OPTi93X */
  433. #ifndef OPTi93X
  434. outb(irq_bits << 3 | dma_bits, chip->wss_base);
  435. #else /* OPTi93X */
  436. snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
  437. #endif /* OPTi93X */
  438. __skip_resources:
  439. if (chip->hardware > OPTi9XX_HW_82C928) {
  440. switch (mpu_port) {
  441. case 0:
  442. case -1:
  443. break;
  444. case 0x300:
  445. mpu_port_bits = 0x03;
  446. break;
  447. case 0x310:
  448. mpu_port_bits = 0x02;
  449. break;
  450. case 0x320:
  451. mpu_port_bits = 0x01;
  452. break;
  453. case 0x330:
  454. mpu_port_bits = 0x00;
  455. break;
  456. default:
  457. snd_printk(KERN_WARNING
  458. "MPU-401 port 0x%lx not valid\n", mpu_port);
  459. goto __skip_mpu;
  460. }
  461. switch (mpu_irq) {
  462. case 5:
  463. mpu_irq_bits = 0x02;
  464. break;
  465. case 7:
  466. mpu_irq_bits = 0x03;
  467. break;
  468. case 9:
  469. mpu_irq_bits = 0x00;
  470. break;
  471. case 10:
  472. mpu_irq_bits = 0x01;
  473. break;
  474. default:
  475. snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
  476. mpu_irq);
  477. goto __skip_mpu;
  478. }
  479. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
  480. (mpu_port <= 0) ? 0x00 :
  481. 0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
  482. 0xf8);
  483. }
  484. __skip_mpu:
  485. return 0;
  486. }
  487. #ifdef OPTi93X
  488. static const DECLARE_TLV_DB_SCALE(db_scale_5bit_3db_step, -9300, 300, 0);
  489. static const DECLARE_TLV_DB_SCALE(db_scale_5bit, -4650, 150, 0);
  490. static const DECLARE_TLV_DB_SCALE(db_scale_4bit_12db_max, -3300, 300, 0);
  491. static struct snd_kcontrol_new snd_opti93x_controls[] = {
  492. WSS_DOUBLE("Master Playback Switch", 0,
  493. OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
  494. WSS_DOUBLE_TLV("Master Playback Volume", 0,
  495. OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1,
  496. db_scale_5bit_3db_step),
  497. WSS_DOUBLE_TLV("PCM Playback Volume", 0,
  498. CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1,
  499. db_scale_5bit),
  500. WSS_DOUBLE_TLV("FM Playback Volume", 0,
  501. CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1,
  502. db_scale_4bit_12db_max),
  503. WSS_DOUBLE("Line Playback Switch", 0,
  504. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
  505. WSS_DOUBLE_TLV("Line Playback Volume", 0,
  506. CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1,
  507. db_scale_4bit_12db_max),
  508. WSS_DOUBLE("Mic Playback Switch", 0,
  509. OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
  510. WSS_DOUBLE_TLV("Mic Playback Volume", 0,
  511. OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1,
  512. db_scale_4bit_12db_max),
  513. WSS_DOUBLE_TLV("CD Playback Volume", 0,
  514. CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1,
  515. db_scale_4bit_12db_max),
  516. WSS_DOUBLE("Aux Playback Switch", 0,
  517. OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
  518. WSS_DOUBLE_TLV("Aux Playback Volume", 0,
  519. OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1,
  520. db_scale_4bit_12db_max),
  521. };
  522. static int snd_opti93x_mixer(struct snd_wss *chip)
  523. {
  524. struct snd_card *card;
  525. unsigned int idx;
  526. struct snd_ctl_elem_id id1, id2;
  527. int err;
  528. if (snd_BUG_ON(!chip || !chip->pcm))
  529. return -EINVAL;
  530. card = chip->card;
  531. strcpy(card->mixername, chip->pcm->name);
  532. memset(&id1, 0, sizeof(id1));
  533. memset(&id2, 0, sizeof(id2));
  534. id1.iface = id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  535. /* reassign AUX0 switch to CD */
  536. strcpy(id1.name, "Aux Playback Switch");
  537. strcpy(id2.name, "CD Playback Switch");
  538. err = snd_ctl_rename_id(card, &id1, &id2);
  539. if (err < 0) {
  540. snd_printk(KERN_ERR "Cannot rename opti93x control\n");
  541. return err;
  542. }
  543. /* reassign AUX1 switch to FM */
  544. strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
  545. strcpy(id2.name, "FM Playback Switch");
  546. err = snd_ctl_rename_id(card, &id1, &id2);
  547. if (err < 0) {
  548. snd_printk(KERN_ERR "Cannot rename opti93x control\n");
  549. return err;
  550. }
  551. /* remove AUX1 volume */
  552. strcpy(id1.name, "Aux Playback Volume"); id1.index = 1;
  553. snd_ctl_remove_id(card, &id1);
  554. /* Replace WSS volume controls with OPTi93x volume controls */
  555. id1.index = 0;
  556. for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
  557. strcpy(id1.name, snd_opti93x_controls[idx].name);
  558. snd_ctl_remove_id(card, &id1);
  559. err = snd_ctl_add(card,
  560. snd_ctl_new1(&snd_opti93x_controls[idx], chip));
  561. if (err < 0)
  562. return err;
  563. }
  564. return 0;
  565. }
  566. static irqreturn_t snd_opti93x_interrupt(int irq, void *dev_id)
  567. {
  568. struct snd_opti9xx *chip = dev_id;
  569. struct snd_wss *codec = chip->codec;
  570. unsigned char status;
  571. if (!codec)
  572. return IRQ_HANDLED;
  573. status = snd_opti9xx_read(chip, OPTi9XX_MC_REG(11));
  574. if ((status & OPTi93X_IRQ_PLAYBACK) && codec->playback_substream)
  575. snd_pcm_period_elapsed(codec->playback_substream);
  576. if ((status & OPTi93X_IRQ_CAPTURE) && codec->capture_substream) {
  577. snd_wss_overrange(codec);
  578. snd_pcm_period_elapsed(codec->capture_substream);
  579. }
  580. outb(0x00, OPTi93X_PORT(codec, STATUS));
  581. return IRQ_HANDLED;
  582. }
  583. #endif /* OPTi93X */
  584. static int snd_opti9xx_read_check(struct snd_opti9xx *chip)
  585. {
  586. unsigned char value;
  587. #ifdef OPTi93X
  588. unsigned long flags;
  589. #endif
  590. chip->res_mc_base = request_region(chip->mc_base, chip->mc_base_size,
  591. "OPTi9xx MC");
  592. if (chip->res_mc_base == NULL)
  593. return -EBUSY;
  594. #ifndef OPTi93X
  595. value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(1));
  596. if (value != 0xff && value != inb(chip->mc_base + OPTi9XX_MC_REG(1)))
  597. if (value == snd_opti9xx_read(chip, OPTi9XX_MC_REG(1)))
  598. return 0;
  599. #else /* OPTi93X */
  600. chip->res_mc_indir = request_region(chip->mc_indir_index, 2,
  601. "OPTi93x MC");
  602. if (chip->res_mc_indir == NULL)
  603. return -EBUSY;
  604. spin_lock_irqsave(&chip->lock, flags);
  605. outb(chip->password, chip->mc_base + chip->pwd_reg);
  606. outb(((chip->mc_indir_index & 0x1f0) >> 4), chip->mc_base);
  607. spin_unlock_irqrestore(&chip->lock, flags);
  608. value = snd_opti9xx_read(chip, OPTi9XX_MC_REG(7));
  609. snd_opti9xx_write(chip, OPTi9XX_MC_REG(7), 0xff - value);
  610. if (snd_opti9xx_read(chip, OPTi9XX_MC_REG(7)) == 0xff - value)
  611. return 0;
  612. release_and_free_resource(chip->res_mc_indir);
  613. chip->res_mc_indir = NULL;
  614. #endif /* OPTi93X */
  615. release_and_free_resource(chip->res_mc_base);
  616. chip->res_mc_base = NULL;
  617. return -ENODEV;
  618. }
  619. static int snd_card_opti9xx_detect(struct snd_card *card,
  620. struct snd_opti9xx *chip)
  621. {
  622. int i, err;
  623. #ifndef OPTi93X
  624. for (i = OPTi9XX_HW_82C928; i < OPTi9XX_HW_82C930; i++) {
  625. #else
  626. for (i = OPTi9XX_HW_82C931; i >= OPTi9XX_HW_82C930; i--) {
  627. #endif
  628. err = snd_opti9xx_init(chip, i);
  629. if (err < 0)
  630. return err;
  631. err = snd_opti9xx_read_check(chip);
  632. if (err == 0)
  633. return 1;
  634. #ifdef OPTi93X
  635. chip->mc_indir_index = 0;
  636. #endif
  637. }
  638. return -ENODEV;
  639. }
  640. #ifdef CONFIG_PNP
  641. static int snd_card_opti9xx_pnp(struct snd_opti9xx *chip,
  642. struct pnp_card_link *card,
  643. const struct pnp_card_device_id *pid)
  644. {
  645. struct pnp_dev *pdev;
  646. int err;
  647. struct pnp_dev *devmpu;
  648. #ifndef OPTi93X
  649. struct pnp_dev *devmc;
  650. #endif
  651. pdev = pnp_request_card_device(card, pid->devs[0].id, NULL);
  652. if (pdev == NULL)
  653. return -EBUSY;
  654. err = pnp_activate_dev(pdev);
  655. if (err < 0) {
  656. snd_printk(KERN_ERR "AUDIO pnp configure failure: %d\n", err);
  657. return err;
  658. }
  659. #ifdef OPTi93X
  660. port = pnp_port_start(pdev, 0) - 4;
  661. fm_port = pnp_port_start(pdev, 1) + 8;
  662. /* adjust mc_indir_index - some cards report it at 0xe?d,
  663. other at 0xe?c but it really is always at 0xe?e */
  664. chip->mc_indir_index = (pnp_port_start(pdev, 3) & ~0xf) | 0xe;
  665. #else
  666. devmc = pnp_request_card_device(card, pid->devs[2].id, NULL);
  667. if (devmc == NULL)
  668. return -EBUSY;
  669. err = pnp_activate_dev(devmc);
  670. if (err < 0) {
  671. snd_printk(KERN_ERR "MC pnp configure failure: %d\n", err);
  672. return err;
  673. }
  674. port = pnp_port_start(pdev, 1);
  675. fm_port = pnp_port_start(pdev, 2) + 8;
  676. /*
  677. * The MC(0) is never accessed and card does not
  678. * include it in the PnP resource range. OPTI93x include it.
  679. */
  680. chip->mc_base = pnp_port_start(devmc, 0) - 1;
  681. chip->mc_base_size = pnp_port_len(devmc, 0) + 1;
  682. #endif /* OPTi93X */
  683. irq = pnp_irq(pdev, 0);
  684. dma1 = pnp_dma(pdev, 0);
  685. #if defined(CS4231) || defined(OPTi93X)
  686. dma2 = pnp_dma(pdev, 1);
  687. #endif /* CS4231 || OPTi93X */
  688. devmpu = pnp_request_card_device(card, pid->devs[1].id, NULL);
  689. if (devmpu && mpu_port > 0) {
  690. err = pnp_activate_dev(devmpu);
  691. if (err < 0) {
  692. snd_printk(KERN_ERR "MPU401 pnp configure failure\n");
  693. mpu_port = -1;
  694. } else {
  695. mpu_port = pnp_port_start(devmpu, 0);
  696. mpu_irq = pnp_irq(devmpu, 0);
  697. }
  698. }
  699. return pid->driver_data;
  700. }
  701. #endif /* CONFIG_PNP */
  702. static void snd_card_opti9xx_free(struct snd_card *card)
  703. {
  704. struct snd_opti9xx *chip = card->private_data;
  705. if (chip) {
  706. #ifdef OPTi93X
  707. if (chip->irq > 0) {
  708. disable_irq(chip->irq);
  709. free_irq(chip->irq, chip);
  710. }
  711. release_and_free_resource(chip->res_mc_indir);
  712. #endif
  713. release_and_free_resource(chip->res_mc_base);
  714. }
  715. }
  716. static int snd_opti9xx_probe(struct snd_card *card)
  717. {
  718. static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
  719. int error;
  720. int xdma2;
  721. struct snd_opti9xx *chip = card->private_data;
  722. struct snd_wss *codec;
  723. struct snd_rawmidi *rmidi;
  724. struct snd_hwdep *synth;
  725. #if defined(CS4231) || defined(OPTi93X)
  726. xdma2 = dma2;
  727. #else
  728. xdma2 = -1;
  729. #endif
  730. if (port == SNDRV_AUTO_PORT) {
  731. port = snd_legacy_find_free_ioport(possible_ports, 4);
  732. if (port < 0) {
  733. snd_printk(KERN_ERR "unable to find a free WSS port\n");
  734. return -EBUSY;
  735. }
  736. }
  737. error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
  738. mpu_port, mpu_irq);
  739. if (error)
  740. return error;
  741. error = snd_wss_create(card, chip->wss_base + 4, -1, irq, dma1, xdma2,
  742. #ifdef OPTi93X
  743. WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
  744. #else
  745. WSS_HW_DETECT, 0,
  746. #endif
  747. &codec);
  748. if (error < 0)
  749. return error;
  750. chip->codec = codec;
  751. error = snd_wss_pcm(codec, 0);
  752. if (error < 0)
  753. return error;
  754. error = snd_wss_mixer(codec);
  755. if (error < 0)
  756. return error;
  757. #ifdef OPTi93X
  758. error = snd_opti93x_mixer(codec);
  759. if (error < 0)
  760. return error;
  761. #endif
  762. #ifdef CS4231
  763. error = snd_wss_timer(codec, 0);
  764. if (error < 0)
  765. return error;
  766. #endif
  767. #ifdef OPTi93X
  768. error = request_irq(irq, snd_opti93x_interrupt,
  769. 0, DEV_NAME" - WSS", chip);
  770. if (error < 0) {
  771. snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
  772. return error;
  773. }
  774. #endif
  775. chip->irq = irq;
  776. strcpy(card->driver, chip->name);
  777. sprintf(card->shortname, "OPTi %s", card->driver);
  778. #if defined(CS4231) || defined(OPTi93X)
  779. snprintf(card->longname, sizeof(card->longname),
  780. "%s, %s at 0x%lx, irq %d, dma %d&%d",
  781. card->shortname, codec->pcm->name,
  782. chip->wss_base + 4, irq, dma1, xdma2);
  783. #else
  784. snprintf(card->longname, sizeof(card->longname),
  785. "%s, %s at 0x%lx, irq %d, dma %d",
  786. card->shortname, codec->pcm->name, chip->wss_base + 4, irq,
  787. dma1);
  788. #endif /* CS4231 || OPTi93X */
  789. if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
  790. rmidi = NULL;
  791. else {
  792. error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  793. mpu_port, 0, mpu_irq, &rmidi);
  794. if (error)
  795. snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
  796. mpu_port);
  797. }
  798. if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
  799. struct snd_opl3 *opl3 = NULL;
  800. #ifndef OPTi93X
  801. if (chip->hardware == OPTi9XX_HW_82C928 ||
  802. chip->hardware == OPTi9XX_HW_82C929 ||
  803. chip->hardware == OPTi9XX_HW_82C924) {
  804. struct snd_opl4 *opl4;
  805. /* assume we have an OPL4 */
  806. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
  807. 0x20, 0x20);
  808. if (snd_opl4_create(card, fm_port, fm_port - 8,
  809. 2, &opl3, &opl4) < 0) {
  810. /* no luck, use OPL3 instead */
  811. snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
  812. 0x00, 0x20);
  813. }
  814. }
  815. #endif /* !OPTi93X */
  816. if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
  817. OPL3_HW_AUTO, 0, &opl3) < 0) {
  818. snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
  819. fm_port, fm_port + 4 - 1);
  820. }
  821. if (opl3) {
  822. error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
  823. if (error < 0)
  824. return error;
  825. }
  826. }
  827. return snd_card_register(card);
  828. }
  829. static int snd_opti9xx_card_new(struct device *pdev, struct snd_card **cardp)
  830. {
  831. struct snd_card *card;
  832. int err;
  833. err = snd_card_new(pdev, index, id, THIS_MODULE,
  834. sizeof(struct snd_opti9xx), &card);
  835. if (err < 0)
  836. return err;
  837. card->private_free = snd_card_opti9xx_free;
  838. *cardp = card;
  839. return 0;
  840. }
  841. static int snd_opti9xx_isa_match(struct device *devptr,
  842. unsigned int dev)
  843. {
  844. #ifdef CONFIG_PNP
  845. if (snd_opti9xx_pnp_is_probed)
  846. return 0;
  847. if (isapnp)
  848. return 0;
  849. #endif
  850. return 1;
  851. }
  852. static int snd_opti9xx_isa_probe(struct device *devptr,
  853. unsigned int dev)
  854. {
  855. struct snd_card *card;
  856. int error;
  857. static long possible_mpu_ports[] = {0x300, 0x310, 0x320, 0x330, -1};
  858. #ifdef OPTi93X
  859. static int possible_irqs[] = {5, 9, 10, 11, 7, -1};
  860. #else
  861. static int possible_irqs[] = {9, 10, 11, 7, -1};
  862. #endif /* OPTi93X */
  863. static int possible_mpu_irqs[] = {5, 9, 10, 7, -1};
  864. static int possible_dma1s[] = {3, 1, 0, -1};
  865. #if defined(CS4231) || defined(OPTi93X)
  866. static int possible_dma2s[][2] = {{1,-1}, {0,-1}, {-1,-1}, {0,-1}};
  867. #endif /* CS4231 || OPTi93X */
  868. if (mpu_port == SNDRV_AUTO_PORT) {
  869. if ((mpu_port = snd_legacy_find_free_ioport(possible_mpu_ports, 2)) < 0) {
  870. snd_printk(KERN_ERR "unable to find a free MPU401 port\n");
  871. return -EBUSY;
  872. }
  873. }
  874. if (irq == SNDRV_AUTO_IRQ) {
  875. if ((irq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  876. snd_printk(KERN_ERR "unable to find a free IRQ\n");
  877. return -EBUSY;
  878. }
  879. }
  880. if (mpu_irq == SNDRV_AUTO_IRQ) {
  881. if ((mpu_irq = snd_legacy_find_free_irq(possible_mpu_irqs)) < 0) {
  882. snd_printk(KERN_ERR "unable to find a free MPU401 IRQ\n");
  883. return -EBUSY;
  884. }
  885. }
  886. if (dma1 == SNDRV_AUTO_DMA) {
  887. if ((dma1 = snd_legacy_find_free_dma(possible_dma1s)) < 0) {
  888. snd_printk(KERN_ERR "unable to find a free DMA1\n");
  889. return -EBUSY;
  890. }
  891. }
  892. #if defined(CS4231) || defined(OPTi93X)
  893. if (dma2 == SNDRV_AUTO_DMA) {
  894. if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
  895. snd_printk(KERN_ERR "unable to find a free DMA2\n");
  896. return -EBUSY;
  897. }
  898. }
  899. #endif
  900. error = snd_opti9xx_card_new(devptr, &card);
  901. if (error < 0)
  902. return error;
  903. if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
  904. snd_card_free(card);
  905. return error;
  906. }
  907. if ((error = snd_opti9xx_probe(card)) < 0) {
  908. snd_card_free(card);
  909. return error;
  910. }
  911. dev_set_drvdata(devptr, card);
  912. return 0;
  913. }
  914. static int snd_opti9xx_isa_remove(struct device *devptr,
  915. unsigned int dev)
  916. {
  917. snd_card_free(dev_get_drvdata(devptr));
  918. return 0;
  919. }
  920. #ifdef CONFIG_PM
  921. static int snd_opti9xx_suspend(struct snd_card *card)
  922. {
  923. struct snd_opti9xx *chip = card->private_data;
  924. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  925. chip->codec->suspend(chip->codec);
  926. return 0;
  927. }
  928. static int snd_opti9xx_resume(struct snd_card *card)
  929. {
  930. struct snd_opti9xx *chip = card->private_data;
  931. int error, xdma2;
  932. #if defined(CS4231) || defined(OPTi93X)
  933. xdma2 = dma2;
  934. #else
  935. xdma2 = -1;
  936. #endif
  937. error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
  938. mpu_port, mpu_irq);
  939. if (error)
  940. return error;
  941. chip->codec->resume(chip->codec);
  942. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  943. return 0;
  944. }
  945. static int snd_opti9xx_isa_suspend(struct device *dev, unsigned int n,
  946. pm_message_t state)
  947. {
  948. return snd_opti9xx_suspend(dev_get_drvdata(dev));
  949. }
  950. static int snd_opti9xx_isa_resume(struct device *dev, unsigned int n)
  951. {
  952. return snd_opti9xx_resume(dev_get_drvdata(dev));
  953. }
  954. #endif
  955. static struct isa_driver snd_opti9xx_driver = {
  956. .match = snd_opti9xx_isa_match,
  957. .probe = snd_opti9xx_isa_probe,
  958. .remove = snd_opti9xx_isa_remove,
  959. #ifdef CONFIG_PM
  960. .suspend = snd_opti9xx_isa_suspend,
  961. .resume = snd_opti9xx_isa_resume,
  962. #endif
  963. .driver = {
  964. .name = DEV_NAME
  965. },
  966. };
  967. #ifdef CONFIG_PNP
  968. static int snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
  969. const struct pnp_card_device_id *pid)
  970. {
  971. struct snd_card *card;
  972. int error, hw;
  973. struct snd_opti9xx *chip;
  974. if (snd_opti9xx_pnp_is_probed)
  975. return -EBUSY;
  976. if (! isapnp)
  977. return -ENODEV;
  978. error = snd_opti9xx_card_new(&pcard->card->dev, &card);
  979. if (error < 0)
  980. return error;
  981. chip = card->private_data;
  982. hw = snd_card_opti9xx_pnp(chip, pcard, pid);
  983. switch (hw) {
  984. case 0x0924:
  985. hw = OPTi9XX_HW_82C924;
  986. break;
  987. case 0x0925:
  988. hw = OPTi9XX_HW_82C925;
  989. break;
  990. case 0x0931:
  991. hw = OPTi9XX_HW_82C931;
  992. break;
  993. default:
  994. snd_card_free(card);
  995. return -ENODEV;
  996. }
  997. if ((error = snd_opti9xx_init(chip, hw))) {
  998. snd_card_free(card);
  999. return error;
  1000. }
  1001. error = snd_opti9xx_read_check(chip);
  1002. if (error) {
  1003. snd_printk(KERN_ERR "OPTI chip not found\n");
  1004. snd_card_free(card);
  1005. return error;
  1006. }
  1007. if ((error = snd_opti9xx_probe(card)) < 0) {
  1008. snd_card_free(card);
  1009. return error;
  1010. }
  1011. pnp_set_card_drvdata(pcard, card);
  1012. snd_opti9xx_pnp_is_probed = 1;
  1013. return 0;
  1014. }
  1015. static void snd_opti9xx_pnp_remove(struct pnp_card_link *pcard)
  1016. {
  1017. snd_card_free(pnp_get_card_drvdata(pcard));
  1018. pnp_set_card_drvdata(pcard, NULL);
  1019. snd_opti9xx_pnp_is_probed = 0;
  1020. }
  1021. #ifdef CONFIG_PM
  1022. static int snd_opti9xx_pnp_suspend(struct pnp_card_link *pcard,
  1023. pm_message_t state)
  1024. {
  1025. return snd_opti9xx_suspend(pnp_get_card_drvdata(pcard));
  1026. }
  1027. static int snd_opti9xx_pnp_resume(struct pnp_card_link *pcard)
  1028. {
  1029. return snd_opti9xx_resume(pnp_get_card_drvdata(pcard));
  1030. }
  1031. #endif
  1032. static struct pnp_card_driver opti9xx_pnpc_driver = {
  1033. .flags = PNP_DRIVER_RES_DISABLE,
  1034. .name = DEV_NAME,
  1035. .id_table = snd_opti9xx_pnpids,
  1036. .probe = snd_opti9xx_pnp_probe,
  1037. .remove = snd_opti9xx_pnp_remove,
  1038. #ifdef CONFIG_PM
  1039. .suspend = snd_opti9xx_pnp_suspend,
  1040. .resume = snd_opti9xx_pnp_resume,
  1041. #endif
  1042. };
  1043. #endif
  1044. #ifdef OPTi93X
  1045. #define CHIP_NAME "82C93x"
  1046. #else
  1047. #define CHIP_NAME "82C92x"
  1048. #endif
  1049. static int __init alsa_card_opti9xx_init(void)
  1050. {
  1051. #ifdef CONFIG_PNP
  1052. pnp_register_card_driver(&opti9xx_pnpc_driver);
  1053. if (snd_opti9xx_pnp_is_probed)
  1054. return 0;
  1055. pnp_unregister_card_driver(&opti9xx_pnpc_driver);
  1056. #endif
  1057. return isa_register_driver(&snd_opti9xx_driver, 1);
  1058. }
  1059. static void __exit alsa_card_opti9xx_exit(void)
  1060. {
  1061. if (!snd_opti9xx_pnp_is_probed) {
  1062. isa_unregister_driver(&snd_opti9xx_driver);
  1063. return;
  1064. }
  1065. #ifdef CONFIG_PNP
  1066. pnp_unregister_card_driver(&opti9xx_pnpc_driver);
  1067. #endif
  1068. }
  1069. module_init(alsa_card_opti9xx_init)
  1070. module_exit(alsa_card_opti9xx_exit)