pas2_card.c 9.3 KB

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