kahlua.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. /*
  2. * Initialisation code for Cyrix/NatSemi VSA1 softaudio
  3. *
  4. * (C) Copyright 2003 Red Hat Inc <alan@lxorguk.ukuu.org.uk>
  5. *
  6. * XpressAudio(tm) is used on the Cyrix MediaGX (now NatSemi Geode) systems.
  7. * The older version (VSA1) provides fairly good soundblaster emulation
  8. * although there are a couple of bugs: large DMA buffers break record,
  9. * and the MPU event handling seems suspect. VSA2 allows the native driver
  10. * to control the AC97 audio engine directly and requires a different driver.
  11. *
  12. * Thanks to National Semiconductor for providing the needed information
  13. * on the XpressAudio(tm) internals.
  14. *
  15. * This program is free software; you can redistribute it and/or modify it
  16. * under the terms of the GNU General Public License as published by the
  17. * Free Software Foundation; either version 2, or (at your option) any
  18. * later version.
  19. *
  20. * This program is distributed in the hope that it will be useful, but
  21. * WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  23. * General Public License for more details.
  24. *
  25. * TO DO:
  26. * Investigate whether we can portably support Cognac (5520) in the
  27. * same manner.
  28. */
  29. #include <linux/delay.h>
  30. #include <linux/init.h>
  31. #include <linux/module.h>
  32. #include <linux/pci.h>
  33. #include <linux/slab.h>
  34. #include "sound_config.h"
  35. #include "sb.h"
  36. /*
  37. * Read a soundblaster compatible mixer register.
  38. * In this case we are actually reading an SMI trap
  39. * not real hardware.
  40. */
  41. static u8 mixer_read(unsigned long io, u8 reg)
  42. {
  43. outb(reg, io + 4);
  44. udelay(20);
  45. reg = inb(io + 5);
  46. udelay(20);
  47. return reg;
  48. }
  49. static int probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  50. {
  51. struct address_info *hw_config;
  52. unsigned long base;
  53. void __iomem *mem;
  54. unsigned long io;
  55. u16 map;
  56. u8 irq, dma8, dma16;
  57. int oldquiet;
  58. extern int sb_be_quiet;
  59. base = pci_resource_start(pdev, 0);
  60. if(base == 0UL)
  61. return 1;
  62. mem = ioremap(base, 128);
  63. if (!mem)
  64. return 1;
  65. map = readw(mem + 0x18); /* Read the SMI enables */
  66. iounmap(mem);
  67. /* Map bits
  68. 0:1 * 0x20 + 0x200 = sb base
  69. 2 sb enable
  70. 3 adlib enable
  71. 5 MPU enable 0x330
  72. 6 MPU enable 0x300
  73. The other bits may be used internally so must be masked */
  74. io = 0x220 + 0x20 * (map & 3);
  75. if(map & (1<<2))
  76. printk(KERN_INFO "kahlua: XpressAudio at 0x%lx\n", io);
  77. else
  78. return 1;
  79. if(map & (1<<5))
  80. printk(KERN_INFO "kahlua: MPU at 0x300\n");
  81. else if(map & (1<<6))
  82. printk(KERN_INFO "kahlua: MPU at 0x330\n");
  83. irq = mixer_read(io, 0x80) & 0x0F;
  84. dma8 = mixer_read(io, 0x81);
  85. // printk("IRQ=%x MAP=%x DMA=%x\n", irq, map, dma8);
  86. if(dma8 & 0x20)
  87. dma16 = 5;
  88. else if(dma8 & 0x40)
  89. dma16 = 6;
  90. else if(dma8 & 0x80)
  91. dma16 = 7;
  92. else
  93. {
  94. printk(KERN_ERR "kahlua: No 16bit DMA enabled.\n");
  95. return 1;
  96. }
  97. if(dma8 & 0x01)
  98. dma8 = 0;
  99. else if(dma8 & 0x02)
  100. dma8 = 1;
  101. else if(dma8 & 0x08)
  102. dma8 = 3;
  103. else
  104. {
  105. printk(KERN_ERR "kahlua: No 8bit DMA enabled.\n");
  106. return 1;
  107. }
  108. if(irq & 1)
  109. irq = 9;
  110. else if(irq & 2)
  111. irq = 5;
  112. else if(irq & 4)
  113. irq = 7;
  114. else if(irq & 8)
  115. irq = 10;
  116. else
  117. {
  118. printk(KERN_ERR "kahlua: SB IRQ not set.\n");
  119. return 1;
  120. }
  121. printk(KERN_INFO "kahlua: XpressAudio on IRQ %d, DMA %d, %d\n",
  122. irq, dma8, dma16);
  123. hw_config = kzalloc(sizeof(struct address_info), GFP_KERNEL);
  124. if(hw_config == NULL)
  125. {
  126. printk(KERN_ERR "kahlua: out of memory.\n");
  127. return 1;
  128. }
  129. pci_set_drvdata(pdev, hw_config);
  130. hw_config->io_base = io;
  131. hw_config->irq = irq;
  132. hw_config->dma = dma8;
  133. hw_config->dma2 = dma16;
  134. hw_config->name = "Cyrix XpressAudio";
  135. hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ;
  136. if (!request_region(io, 16, "soundblaster"))
  137. goto err_out_free;
  138. if(sb_dsp_detect(hw_config, 0, 0, NULL)==0)
  139. {
  140. printk(KERN_ERR "kahlua: audio not responding.\n");
  141. release_region(io, 16);
  142. goto err_out_free;
  143. }
  144. oldquiet = sb_be_quiet;
  145. sb_be_quiet = 1;
  146. if(sb_dsp_init(hw_config, THIS_MODULE))
  147. {
  148. sb_be_quiet = oldquiet;
  149. goto err_out_free;
  150. }
  151. sb_be_quiet = oldquiet;
  152. return 0;
  153. err_out_free:
  154. kfree(hw_config);
  155. return 1;
  156. }
  157. static void remove_one(struct pci_dev *pdev)
  158. {
  159. struct address_info *hw_config = pci_get_drvdata(pdev);
  160. sb_dsp_unload(hw_config, 0);
  161. kfree(hw_config);
  162. }
  163. MODULE_AUTHOR("Alan Cox");
  164. MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio");
  165. MODULE_LICENSE("GPL");
  166. /*
  167. * 5530 only. The 5510/5520 decode is different.
  168. */
  169. static const struct pci_device_id id_tbl[] = {
  170. { PCI_VDEVICE(CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO), 0 },
  171. { }
  172. };
  173. MODULE_DEVICE_TABLE(pci, id_tbl);
  174. static struct pci_driver kahlua_driver = {
  175. .name = "kahlua",
  176. .id_table = id_tbl,
  177. .probe = probe_one,
  178. .remove = remove_one,
  179. };
  180. static int __init kahlua_init_module(void)
  181. {
  182. printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n");
  183. return pci_register_driver(&kahlua_driver);
  184. }
  185. static void kahlua_cleanup_module(void)
  186. {
  187. pci_unregister_driver(&kahlua_driver);
  188. }
  189. module_init(kahlua_init_module);
  190. module_exit(kahlua_cleanup_module);