trix.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. /*
  2. * sound/oss/trix.c
  3. *
  4. * Low level driver for the MediaTrix AudioTrix Pro
  5. * (MT-0002-PC Control Chip)
  6. *
  7. *
  8. * Copyright (C) by Hannu Savolainen 1993-1997
  9. *
  10. * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
  11. * Version 2 (June 1991). See the "COPYING" file distributed with this software
  12. * for more info.
  13. *
  14. * Changes
  15. * Alan Cox Modularisation, cleanup.
  16. * Christoph Hellwig Adapted to module_init/module_exit
  17. * Arnaldo C. de Melo Got rid of attach_uart401
  18. */
  19. #include <linux/init.h>
  20. #include <linux/module.h>
  21. #include "sound_config.h"
  22. #include "sb.h"
  23. #include "sound_firmware.h"
  24. #include "ad1848.h"
  25. #include "mpu401.h"
  26. #include "trix_boot.h"
  27. static int mpu;
  28. static int joystick;
  29. static unsigned char trix_read(int addr)
  30. {
  31. outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
  32. return inb(0x391); /* MT-0002-PC ASIC data */
  33. }
  34. static void trix_write(int addr, int data)
  35. {
  36. outb(((unsigned char) addr), 0x390); /* MT-0002-PC ASIC address */
  37. outb(((unsigned char) data), 0x391); /* MT-0002-PC ASIC data */
  38. }
  39. static void download_boot(int base)
  40. {
  41. int i = 0, n = trix_boot_len;
  42. if (trix_boot_len == 0)
  43. return;
  44. trix_write(0xf8, 0x00); /* ??????? */
  45. outb((0x01), base + 6); /* Clear the internal data pointer */
  46. outb((0x00), base + 6); /* Restart */
  47. /*
  48. * Write the boot code to the RAM upload/download register.
  49. * Each write increments the internal data pointer.
  50. */
  51. outb((0x01), base + 6); /* Clear the internal data pointer */
  52. outb((0x1A), 0x390); /* Select RAM download/upload port */
  53. for (i = 0; i < n; i++)
  54. outb((trix_boot[i]), 0x391);
  55. for (i = n; i < 10016; i++) /* Clear up to first 16 bytes of data RAM */
  56. outb((0x00), 0x391);
  57. outb((0x00), base + 6); /* Reset */
  58. outb((0x50), 0x390); /* ?????? */
  59. }
  60. static int trix_set_wss_port(struct address_info *hw_config)
  61. {
  62. unsigned char addr_bits;
  63. if (trix_read(0x15) != 0x71) /* No ASIC signature */
  64. {
  65. MDB(printk(KERN_ERR "No AudioTrix ASIC signature found\n"));
  66. return 0;
  67. }
  68. /*
  69. * Reset some registers.
  70. */
  71. trix_write(0x13, 0);
  72. trix_write(0x14, 0);
  73. /*
  74. * Configure the ASIC to place the codec to the proper I/O location
  75. */
  76. switch (hw_config->io_base)
  77. {
  78. case 0x530:
  79. addr_bits = 0;
  80. break;
  81. case 0x604:
  82. addr_bits = 1;
  83. break;
  84. case 0xE80:
  85. addr_bits = 2;
  86. break;
  87. case 0xF40:
  88. addr_bits = 3;
  89. break;
  90. default:
  91. return 0;
  92. }
  93. trix_write(0x19, (trix_read(0x19) & 0x03) | addr_bits);
  94. return 1;
  95. }
  96. /*
  97. * Probe and attach routines for the Windows Sound System mode of
  98. * AudioTrix Pro
  99. */
  100. static int __init init_trix_wss(struct address_info *hw_config)
  101. {
  102. static unsigned char dma_bits[4] = {
  103. 1, 2, 0, 3
  104. };
  105. struct resource *ports;
  106. int config_port = hw_config->io_base + 0;
  107. int dma1 = hw_config->dma, dma2 = hw_config->dma2;
  108. int old_num_mixers = num_mixers;
  109. u8 config, bits;
  110. int ret;
  111. switch(hw_config->irq) {
  112. case 7:
  113. bits = 8;
  114. break;
  115. case 9:
  116. bits = 0x10;
  117. break;
  118. case 10:
  119. bits = 0x18;
  120. break;
  121. case 11:
  122. bits = 0x20;
  123. break;
  124. default:
  125. printk(KERN_ERR "AudioTrix: Bad WSS IRQ %d\n", hw_config->irq);
  126. return 0;
  127. }
  128. switch (dma1) {
  129. case 0:
  130. case 1:
  131. case 3:
  132. break;
  133. default:
  134. printk(KERN_ERR "AudioTrix: Bad WSS DMA %d\n", dma1);
  135. return 0;
  136. }
  137. switch (dma2) {
  138. case -1:
  139. case 0:
  140. case 1:
  141. case 3:
  142. break;
  143. default:
  144. printk(KERN_ERR "AudioTrix: Bad capture DMA %d\n", dma2);
  145. return 0;
  146. }
  147. /*
  148. * Check if the IO port returns valid signature. The original MS Sound
  149. * system returns 0x04 while some cards (AudioTrix Pro for example)
  150. * return 0x00.
  151. */
  152. ports = request_region(hw_config->io_base + 4, 4, "ad1848");
  153. if (!ports) {
  154. printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
  155. return 0;
  156. }
  157. if (!request_region(hw_config->io_base, 4, "MSS config")) {
  158. printk(KERN_ERR "AudioTrix: MSS I/O port conflict (%x)\n", hw_config->io_base);
  159. release_region(hw_config->io_base + 4, 4);
  160. return 0;
  161. }
  162. if (!trix_set_wss_port(hw_config))
  163. goto fail;
  164. config = inb(hw_config->io_base + 3);
  165. if ((config & 0x3f) != 0x00)
  166. {
  167. MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x\n", hw_config->io_base));
  168. goto fail;
  169. }
  170. /*
  171. * Check that DMA0 is not in use with a 8 bit board.
  172. */
  173. if (dma1 == 0 && config & 0x80)
  174. {
  175. printk(KERN_ERR "AudioTrix: Can't use DMA0 with a 8 bit card slot\n");
  176. goto fail;
  177. }
  178. if (hw_config->irq > 9 && config & 0x80)
  179. {
  180. printk(KERN_ERR "AudioTrix: Can't use IRQ%d with a 8 bit card slot\n", hw_config->irq);
  181. goto fail;
  182. }
  183. ret = ad1848_detect(ports, NULL, hw_config->osp);
  184. if (!ret)
  185. goto fail;
  186. if (joystick==1)
  187. trix_write(0x15, 0x80);
  188. /*
  189. * Set the IRQ and DMA addresses.
  190. */
  191. outb((bits | 0x40), config_port);
  192. if (dma2 == -1 || dma2 == dma1)
  193. {
  194. bits |= dma_bits[dma1];
  195. dma2 = dma1;
  196. }
  197. else
  198. {
  199. unsigned char tmp;
  200. tmp = trix_read(0x13) & ~30;
  201. trix_write(0x13, tmp | 0x80 | (dma1 << 4));
  202. tmp = trix_read(0x14) & ~30;
  203. trix_write(0x14, tmp | 0x80 | (dma2 << 4));
  204. }
  205. outb((bits), config_port); /* Write IRQ+DMA setup */
  206. hw_config->slots[0] = ad1848_init("AudioTrix Pro", ports,
  207. hw_config->irq,
  208. dma1,
  209. dma2,
  210. 0,
  211. hw_config->osp,
  212. THIS_MODULE);
  213. if (num_mixers > old_num_mixers) /* Mixer got installed */
  214. {
  215. AD1848_REROUTE(SOUND_MIXER_LINE1, SOUND_MIXER_LINE); /* Line in */
  216. AD1848_REROUTE(SOUND_MIXER_LINE2, SOUND_MIXER_CD);
  217. AD1848_REROUTE(SOUND_MIXER_LINE3, SOUND_MIXER_SYNTH); /* OPL4 */
  218. AD1848_REROUTE(SOUND_MIXER_SPEAKER, SOUND_MIXER_ALTPCM); /* SB */
  219. }
  220. return 1;
  221. fail:
  222. release_region(hw_config->io_base, 4);
  223. release_region(hw_config->io_base + 4, 4);
  224. return 0;
  225. }
  226. static int __init probe_trix_sb(struct address_info *hw_config)
  227. {
  228. int tmp;
  229. unsigned char conf;
  230. extern int sb_be_quiet;
  231. int old_quiet;
  232. static signed char irq_translate[] = {
  233. -1, -1, -1, 0, 1, 2, -1, 3
  234. };
  235. if (trix_boot_len == 0)
  236. return 0; /* No boot code -> no fun */
  237. if ((hw_config->io_base & 0xffffff8f) != 0x200)
  238. return 0;
  239. tmp = hw_config->irq;
  240. if (tmp > 7)
  241. return 0;
  242. if (irq_translate[tmp] == -1)
  243. return 0;
  244. tmp = hw_config->dma;
  245. if (tmp != 1 && tmp != 3)
  246. return 0;
  247. if (!request_region(hw_config->io_base, 16, "soundblaster")) {
  248. printk(KERN_ERR "AudioTrix: SB I/O port conflict (%x)\n", hw_config->io_base);
  249. return 0;
  250. }
  251. conf = 0x84; /* DMA and IRQ enable */
  252. conf |= hw_config->io_base & 0x70; /* I/O address bits */
  253. conf |= irq_translate[hw_config->irq];
  254. if (hw_config->dma == 3)
  255. conf |= 0x08;
  256. trix_write(0x1b, conf);
  257. download_boot(hw_config->io_base);
  258. hw_config->name = "AudioTrix SB";
  259. if (!sb_dsp_detect(hw_config, 0, 0, NULL)) {
  260. release_region(hw_config->io_base, 16);
  261. return 0;
  262. }
  263. hw_config->driver_use_1 = SB_NO_MIDI | SB_NO_MIXER | SB_NO_RECORDING;
  264. /* Prevent false alarms */
  265. old_quiet = sb_be_quiet;
  266. sb_be_quiet = 1;
  267. sb_dsp_init(hw_config, THIS_MODULE);
  268. sb_be_quiet = old_quiet;
  269. return 1;
  270. }
  271. static int __init probe_trix_mpu(struct address_info *hw_config)
  272. {
  273. unsigned char conf;
  274. static int irq_bits[] = {
  275. -1, -1, -1, 1, 2, 3, -1, 4, -1, 5
  276. };
  277. if (hw_config->irq > 9)
  278. {
  279. printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
  280. return 0;
  281. }
  282. if (irq_bits[hw_config->irq] == -1)
  283. {
  284. printk(KERN_ERR "AudioTrix: Bad MPU IRQ %d\n", hw_config->irq);
  285. return 0;
  286. }
  287. switch (hw_config->io_base)
  288. {
  289. case 0x330:
  290. conf = 0x00;
  291. break;
  292. case 0x370:
  293. conf = 0x04;
  294. break;
  295. case 0x3b0:
  296. conf = 0x08;
  297. break;
  298. case 0x3f0:
  299. conf = 0x0c;
  300. break;
  301. default:
  302. return 0; /* Invalid port */
  303. }
  304. conf |= irq_bits[hw_config->irq] << 4;
  305. trix_write(0x19, (trix_read(0x19) & 0x83) | conf);
  306. hw_config->name = "AudioTrix Pro";
  307. return probe_uart401(hw_config, THIS_MODULE);
  308. }
  309. static void __exit unload_trix_wss(struct address_info *hw_config)
  310. {
  311. int dma2 = hw_config->dma2;
  312. if (dma2 == -1)
  313. dma2 = hw_config->dma;
  314. release_region(0x390, 2);
  315. release_region(hw_config->io_base, 4);
  316. ad1848_unload(hw_config->io_base + 4,
  317. hw_config->irq,
  318. hw_config->dma,
  319. dma2,
  320. 0);
  321. sound_unload_audiodev(hw_config->slots[0]);
  322. }
  323. static inline void __exit unload_trix_mpu(struct address_info *hw_config)
  324. {
  325. unload_uart401(hw_config);
  326. }
  327. static inline void __exit unload_trix_sb(struct address_info *hw_config)
  328. {
  329. sb_dsp_unload(hw_config, mpu);
  330. }
  331. static struct address_info cfg;
  332. static struct address_info cfg2;
  333. static struct address_info cfg_mpu;
  334. static int sb;
  335. static int fw_load;
  336. static int __initdata io = -1;
  337. static int __initdata irq = -1;
  338. static int __initdata dma = -1;
  339. static int __initdata dma2 = -1; /* Set this for modules that need it */
  340. static int __initdata sb_io = -1;
  341. static int __initdata sb_dma = -1;
  342. static int __initdata sb_irq = -1;
  343. static int __initdata mpu_io = -1;
  344. static int __initdata mpu_irq = -1;
  345. module_param(io, int, 0);
  346. module_param(irq, int, 0);
  347. module_param(dma, int, 0);
  348. module_param(dma2, int, 0);
  349. module_param(sb_io, int, 0);
  350. module_param(sb_dma, int, 0);
  351. module_param(sb_irq, int, 0);
  352. module_param(mpu_io, int, 0);
  353. module_param(mpu_irq, int, 0);
  354. module_param(joystick, bool, 0);
  355. static int __init init_trix(void)
  356. {
  357. printk(KERN_INFO "MediaTrix audio driver Copyright (C) by Hannu Savolainen 1993-1996\n");
  358. cfg.io_base = io;
  359. cfg.irq = irq;
  360. cfg.dma = dma;
  361. cfg.dma2 = dma2;
  362. cfg2.io_base = sb_io;
  363. cfg2.irq = sb_irq;
  364. cfg2.dma = sb_dma;
  365. cfg_mpu.io_base = mpu_io;
  366. cfg_mpu.irq = mpu_irq;
  367. if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
  368. printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
  369. return -EINVAL;
  370. }
  371. if (cfg2.io_base != -1 && (cfg2.irq == -1 || cfg2.dma == -1)) {
  372. printk(KERN_INFO "CONFIG_SB_IRQ and CONFIG_SB_DMA must be specified if SB_IO is set.\n");
  373. return -EINVAL;
  374. }
  375. if (cfg_mpu.io_base != -1 && cfg_mpu.irq == -1) {
  376. printk(KERN_INFO "CONFIG_MPU_IRQ must be specified if MPU_IO is set.\n");
  377. return -EINVAL;
  378. }
  379. if (!trix_boot)
  380. {
  381. fw_load = 1;
  382. trix_boot_len = mod_firmware_load("/etc/sound/trxpro.bin",
  383. (char **) &trix_boot);
  384. }
  385. if (!request_region(0x390, 2, "AudioTrix")) {
  386. printk(KERN_ERR "AudioTrix: Config port I/O conflict\n");
  387. return -ENODEV;
  388. }
  389. if (!init_trix_wss(&cfg)) {
  390. release_region(0x390, 2);
  391. return -ENODEV;
  392. }
  393. /*
  394. * We must attach in the right order to get the firmware
  395. * loaded up in time.
  396. */
  397. if (cfg2.io_base != -1) {
  398. sb = probe_trix_sb(&cfg2);
  399. }
  400. if (cfg_mpu.io_base != -1)
  401. mpu = probe_trix_mpu(&cfg_mpu);
  402. return 0;
  403. }
  404. static void __exit cleanup_trix(void)
  405. {
  406. if (fw_load && trix_boot)
  407. vfree(trix_boot);
  408. if (sb)
  409. unload_trix_sb(&cfg2);
  410. if (mpu)
  411. unload_trix_mpu(&cfg_mpu);
  412. unload_trix_wss(&cfg);
  413. }
  414. module_init(init_trix);
  415. module_exit(cleanup_trix);
  416. #ifndef MODULE
  417. static int __init setup_trix (char *str)
  418. {
  419. /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, mpu_io, mpu_irq */
  420. int ints[9];
  421. str = get_options(str, ARRAY_SIZE(ints), ints);
  422. io = ints[1];
  423. irq = ints[2];
  424. dma = ints[3];
  425. dma2 = ints[4];
  426. sb_io = ints[5];
  427. sb_irq = ints[6];
  428. sb_dma = ints[6];
  429. mpu_io = ints[7];
  430. mpu_irq = ints[8];
  431. return 1;
  432. }
  433. __setup("trix=", setup_trix);
  434. #endif
  435. MODULE_LICENSE("GPL");