pas2_card.c 9.3 KB

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