pas2_card.c 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * sound/oss/pas2_card.c
  3. *
  4. * Detection routine for the Pro Audio Spectrum cards.
  5. */
  6. #include <linux/init.h>
  7. #include <linux/interrupt.h>
  8. #include <linux/module.h>
  9. #include <linux/spinlock.h>
  10. #include "sound_config.h"
  11. #include "pas2.h"
  12. #include "sb.h"
  13. static unsigned char dma_bits[] = {
  14. 4, 1, 2, 3, 0, 5, 6, 7
  15. };
  16. static unsigned char irq_bits[] = {
  17. 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11
  18. };
  19. static unsigned char sb_irq_bits[] = {
  20. 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20,
  21. 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0
  22. };
  23. static unsigned char sb_dma_bits[] = {
  24. 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0
  25. };
  26. /*
  27. * The Address Translation code is used to convert I/O register addresses to
  28. * be relative to the given base -register
  29. */
  30. int pas_translate_code = 0;
  31. static int pas_intr_mask;
  32. static int pas_irq;
  33. static int pas_sb_base;
  34. DEFINE_SPINLOCK(pas_lock);
  35. #ifndef CONFIG_PAS_JOYSTICK
  36. static bool joystick;
  37. #else
  38. static bool joystick = 1;
  39. #endif
  40. #ifdef SYMPHONY_PAS
  41. static bool symphony = 1;
  42. #else
  43. static bool symphony;
  44. #endif
  45. #ifdef BROKEN_BUS_CLOCK
  46. static bool broken_bus_clock = 1;
  47. #else
  48. static bool broken_bus_clock;
  49. #endif
  50. static struct address_info cfg;
  51. static struct address_info cfg2;
  52. char pas_model = 0;
  53. static char *pas_model_names[] = {
  54. "",
  55. "Pro AudioSpectrum+",
  56. "CDPC",
  57. "Pro AudioSpectrum 16",
  58. "Pro AudioSpectrum 16D"
  59. };
  60. /*
  61. * pas_read() and pas_write() are equivalents of inb and outb
  62. * These routines perform the I/O address translation required
  63. * to support other than the default base address
  64. */
  65. unsigned char pas_read(int ioaddr)
  66. {
  67. return inb(ioaddr + pas_translate_code);
  68. }
  69. void pas_write(unsigned char data, int ioaddr)
  70. {
  71. outb((data), ioaddr + pas_translate_code);
  72. }
  73. /******************* Begin of the Interrupt Handler ********************/
  74. static irqreturn_t pasintr(int irq, void *dev_id)
  75. {
  76. int status;
  77. status = pas_read(0x0B89);
  78. pas_write(status, 0x0B89); /* Clear interrupt */
  79. if (status & 0x08)
  80. {
  81. pas_pcm_interrupt(status, 1);
  82. status &= ~0x08;
  83. }
  84. if (status & 0x10)
  85. {
  86. pas_midi_interrupt();
  87. status &= ~0x10;
  88. }
  89. return IRQ_HANDLED;
  90. }
  91. int pas_set_intr(int mask)
  92. {
  93. if (!mask)
  94. return 0;
  95. pas_intr_mask |= mask;
  96. pas_write(pas_intr_mask, 0x0B8B);
  97. return 0;
  98. }
  99. int pas_remove_intr(int mask)
  100. {
  101. if (!mask)
  102. return 0;
  103. pas_intr_mask &= ~mask;
  104. pas_write(pas_intr_mask, 0x0B8B);
  105. return 0;
  106. }
  107. /******************* End of the Interrupt handler **********************/
  108. /******************* Begin of the Initialization Code ******************/
  109. static int __init config_pas_hw(struct address_info *hw_config)
  110. {
  111. char ok = 1;
  112. unsigned int_ptrs; /* scsi/sound interrupt pointers */
  113. pas_irq = hw_config->irq;
  114. pas_write(0x00, 0x0B8B);
  115. pas_write(0x36, 0x138B);
  116. pas_write(0x36, 0x1388);
  117. pas_write(0, 0x1388);
  118. pas_write(0x74, 0x138B);
  119. pas_write(0x74, 0x1389);
  120. pas_write(0, 0x1389);
  121. pas_write(0x80 | 0x40 | 0x20 | 1, 0x0B8A);
  122. pas_write(0x80 | 0x20 | 0x10 | 0x08 | 0x01, 0xF8A);
  123. pas_write(0x01 | 0x02 | 0x04 | 0x10 /*
  124. * |
  125. * 0x80
  126. */ , 0xB88);
  127. pas_write(0x80 | (joystick ? 0x40 : 0), 0xF388);
  128. if (pas_irq < 0 || pas_irq > 15)
  129. {
  130. printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
  131. hw_config->irq=-1;
  132. ok = 0;
  133. }
  134. else
  135. {
  136. int_ptrs = pas_read(0xF38A);
  137. int_ptrs = (int_ptrs & 0xf0) | irq_bits[pas_irq];
  138. pas_write(int_ptrs, 0xF38A);
  139. if (!irq_bits[pas_irq])
  140. {
  141. printk(KERN_ERR "PAS16: Invalid IRQ %d", pas_irq);
  142. hw_config->irq=-1;
  143. ok = 0;
  144. }
  145. else
  146. {
  147. if (request_irq(pas_irq, pasintr, 0, "PAS16",hw_config) < 0) {
  148. printk(KERN_ERR "PAS16: Cannot allocate IRQ %d\n",pas_irq);
  149. hw_config->irq=-1;
  150. ok = 0;
  151. }
  152. }
  153. }
  154. if (hw_config->dma < 0 || hw_config->dma > 7)
  155. {
  156. printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
  157. hw_config->dma=-1;
  158. ok = 0;
  159. }
  160. else
  161. {
  162. pas_write(dma_bits[hw_config->dma], 0xF389);
  163. if (!dma_bits[hw_config->dma])
  164. {
  165. printk(KERN_ERR "PAS16: Invalid DMA selection %d", hw_config->dma);
  166. hw_config->dma=-1;
  167. ok = 0;
  168. }
  169. else
  170. {
  171. if (sound_alloc_dma(hw_config->dma, "PAS16"))
  172. {
  173. printk(KERN_ERR "pas2_card.c: Can't allocate DMA channel\n");
  174. hw_config->dma=-1;
  175. ok = 0;
  176. }
  177. }
  178. }
  179. /*
  180. * This fixes the timing problems of the PAS due to the Symphony chipset
  181. * as per Media Vision. Only define this if your PAS doesn't work correctly.
  182. */
  183. if(symphony)
  184. {
  185. outb((0x05), 0xa8);
  186. outb((0x60), 0xa9);
  187. }
  188. if(broken_bus_clock)
  189. pas_write(0x01 | 0x10 | 0x20 | 0x04, 0x8388);
  190. else
  191. /*
  192. * pas_write(0x01, 0x8388);
  193. */
  194. pas_write(0x01 | 0x10 | 0x20, 0x8388);
  195. pas_write(0x18, 0x838A); /* ??? */
  196. pas_write(0x20 | 0x01, 0x0B8A); /* Mute off, filter = 17.897 kHz */
  197. pas_write(8, 0xBF8A);
  198. mix_write(0x80 | 5, 0x078B);
  199. mix_write(5, 0x078B);
  200. {
  201. struct address_info *sb_config;
  202. sb_config = &cfg2;
  203. if (sb_config->io_base)
  204. {
  205. unsigned char irq_dma;
  206. /*
  207. * Turn on Sound Blaster compatibility
  208. * bit 1 = SB emulation
  209. * bit 0 = MPU401 emulation (CDPC only :-( )
  210. */
  211. pas_write(0x02, 0xF788);
  212. /*
  213. * "Emulation address"
  214. */
  215. pas_write((sb_config->io_base >> 4) & 0x0f, 0xF789);
  216. pas_sb_base = sb_config->io_base;
  217. if (!sb_dma_bits[sb_config->dma])
  218. printk(KERN_ERR "PAS16 Warning: Invalid SB DMA %d\n\n", sb_config->dma);
  219. if (!sb_irq_bits[sb_config->irq])
  220. printk(KERN_ERR "PAS16 Warning: Invalid SB IRQ %d\n\n", sb_config->irq);
  221. irq_dma = sb_dma_bits[sb_config->dma] |
  222. sb_irq_bits[sb_config->irq];
  223. pas_write(irq_dma, 0xFB8A);
  224. }
  225. else
  226. pas_write(0x00, 0xF788);
  227. }
  228. if (!ok)
  229. printk(KERN_WARNING "PAS16: Driver not enabled\n");
  230. return ok;
  231. }
  232. static int __init detect_pas_hw(struct address_info *hw_config)
  233. {
  234. unsigned char board_id, foo;
  235. /*
  236. * WARNING: Setting an option like W:1 or so that disables warm boot reset
  237. * of the card will screw up this detect code something fierce. Adding code
  238. * to handle this means possibly interfering with other cards on the bus if
  239. * you have something on base port 0x388. SO be forewarned.
  240. */
  241. outb((0xBC), 0x9A01); /* Activate first board */
  242. outb((hw_config->io_base >> 2), 0x9A01); /* Set base address */
  243. pas_translate_code = hw_config->io_base - 0x388;
  244. pas_write(1, 0xBF88); /* Select one wait states */
  245. board_id = pas_read(0x0B8B);
  246. if (board_id == 0xff)
  247. return 0;
  248. /*
  249. * We probably have a PAS-series board, now check for a PAS16-series board
  250. * by trying to change the board revision bits. PAS16-series hardware won't
  251. * let you do this - the bits are read-only.
  252. */
  253. foo = board_id ^ 0xe0;
  254. pas_write(foo, 0x0B8B);
  255. foo = pas_read(0x0B8B);
  256. pas_write(board_id, 0x0B8B);
  257. if (board_id != foo)
  258. return 0;
  259. pas_model = pas_read(0xFF88);
  260. return pas_model;
  261. }
  262. static void __init attach_pas_card(struct address_info *hw_config)
  263. {
  264. pas_irq = hw_config->irq;
  265. if (detect_pas_hw(hw_config))
  266. {
  267. if ((pas_model = pas_read(0xFF88)))
  268. {
  269. char temp[100];
  270. if (pas_model < 0 ||
  271. pas_model >= ARRAY_SIZE(pas_model_names)) {
  272. printk(KERN_ERR "pas2 unrecognized model.\n");
  273. return;
  274. }
  275. sprintf(temp,
  276. "%s rev %d", pas_model_names[(int) pas_model],
  277. pas_read(0x2789));
  278. conf_printf(temp, hw_config);
  279. }
  280. if (config_pas_hw(hw_config))
  281. {
  282. pas_pcm_init(hw_config);
  283. pas_midi_init();
  284. pas_init_mixer();
  285. }
  286. }
  287. }
  288. static inline int __init probe_pas(struct address_info *hw_config)
  289. {
  290. return detect_pas_hw(hw_config);
  291. }
  292. static void __exit unload_pas(struct address_info *hw_config)
  293. {
  294. extern int pas_audiodev;
  295. extern int pas2_mididev;
  296. if (hw_config->dma>0)
  297. sound_free_dma(hw_config->dma);
  298. if (hw_config->irq>0)
  299. free_irq(hw_config->irq, hw_config);
  300. if(pas_audiodev!=-1)
  301. sound_unload_mixerdev(audio_devs[pas_audiodev]->mixer_dev);
  302. if(pas2_mididev!=-1)
  303. sound_unload_mididev(pas2_mididev);
  304. if(pas_audiodev!=-1)
  305. sound_unload_audiodev(pas_audiodev);
  306. }
  307. static int __initdata io = -1;
  308. static int __initdata irq = -1;
  309. static int __initdata dma = -1;
  310. static int __initdata dma16 = -1; /* Set this for modules that need it */
  311. static int __initdata sb_io = 0;
  312. static int __initdata sb_irq = -1;
  313. static int __initdata sb_dma = -1;
  314. static int __initdata sb_dma16 = -1;
  315. module_param_hw(io, int, ioport, 0);
  316. module_param_hw(irq, int, irq, 0);
  317. module_param_hw(dma, int, dma, 0);
  318. module_param_hw(dma16, int, dma, 0);
  319. module_param_hw(sb_io, int, ioport, 0);
  320. module_param_hw(sb_irq, int, irq, 0);
  321. module_param_hw(sb_dma, int, dma, 0);
  322. module_param_hw(sb_dma16, int, dma, 0);
  323. module_param(joystick, bool, 0);
  324. module_param(symphony, bool, 0);
  325. module_param(broken_bus_clock, bool, 0);
  326. MODULE_LICENSE("GPL");
  327. static int __init init_pas2(void)
  328. {
  329. printk(KERN_INFO "Pro Audio Spectrum driver Copyright (C) by Hannu Savolainen 1993-1996\n");
  330. cfg.io_base = io;
  331. cfg.irq = irq;
  332. cfg.dma = dma;
  333. cfg.dma2 = dma16;
  334. cfg2.io_base = sb_io;
  335. cfg2.irq = sb_irq;
  336. cfg2.dma = sb_dma;
  337. cfg2.dma2 = sb_dma16;
  338. if (cfg.io_base == -1 || cfg.dma == -1 || cfg.irq == -1) {
  339. printk(KERN_INFO "I/O, IRQ, DMA and type are mandatory\n");
  340. return -EINVAL;
  341. }
  342. if (!probe_pas(&cfg))
  343. return -ENODEV;
  344. attach_pas_card(&cfg);
  345. return 0;
  346. }
  347. static void __exit cleanup_pas2(void)
  348. {
  349. unload_pas(&cfg);
  350. }
  351. module_init(init_pas2);
  352. module_exit(cleanup_pas2);
  353. #ifndef MODULE
  354. static int __init setup_pas2(char *str)
  355. {
  356. /* io, irq, dma, dma2, sb_io, sb_irq, sb_dma, sb_dma2 */
  357. int ints[9];
  358. str = get_options(str, ARRAY_SIZE(ints), ints);
  359. io = ints[1];
  360. irq = ints[2];
  361. dma = ints[3];
  362. dma16 = ints[4];
  363. sb_io = ints[5];
  364. sb_irq = ints[6];
  365. sb_dma = ints[7];
  366. sb_dma16 = ints[8];
  367. return 1;
  368. }
  369. __setup("pas2=", setup_pas2);
  370. #endif