pas2_card.c 9.4 KB

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