kahlua.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * Initialisation code for Cyrix/NatSemi VSA1 softaudio
  3. *
  4. * (C) Copyright 2003 Red Hat Inc <alan@redhat.com>
  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 "sound_config.h"
  34. #include "sb.h"
  35. /*
  36. * Read a soundblaster compatible mixer register.
  37. * In this case we are actually reading an SMI trap
  38. * not real hardware.
  39. */
  40. static u8 __devinit mixer_read(unsigned long io, u8 reg)
  41. {
  42. outb(reg, io + 4);
  43. udelay(20);
  44. reg = inb(io + 5);
  45. udelay(20);
  46. return reg;
  47. }
  48. static int __devinit probe_one(struct pci_dev *pdev, const struct pci_device_id *ent)
  49. {
  50. struct address_info *hw_config;
  51. unsigned long base;
  52. void __iomem *mem;
  53. unsigned long io;
  54. u16 map;
  55. u8 irq, dma8, dma16;
  56. int oldquiet;
  57. extern int sb_be_quiet;
  58. base = pci_resource_start(pdev, 0);
  59. if(base == 0UL)
  60. return 1;
  61. mem = ioremap(base, 128);
  62. if(mem == 0UL)
  63. return 1;
  64. map = readw(mem + 0x18); /* Read the SMI enables */
  65. iounmap(mem);
  66. /* Map bits
  67. 0:1 * 0x20 + 0x200 = sb base
  68. 2 sb enable
  69. 3 adlib enable
  70. 5 MPU enable 0x330
  71. 6 MPU enable 0x300
  72. The other bits may be used internally so must be masked */
  73. io = 0x220 + 0x20 * (map & 3);
  74. if(map & (1<<2))
  75. printk(KERN_INFO "kahlua: XpressAudio at 0x%lx\n", io);
  76. else
  77. return 1;
  78. if(map & (1<<5))
  79. printk(KERN_INFO "kahlua: MPU at 0x300\n");
  80. else if(map & (1<<6))
  81. printk(KERN_INFO "kahlua: MPU at 0x330\n");
  82. irq = mixer_read(io, 0x80) & 0x0F;
  83. dma8 = mixer_read(io, 0x81);
  84. // printk("IRQ=%x MAP=%x DMA=%x\n", irq, map, dma8);
  85. if(dma8 & 0x20)
  86. dma16 = 5;
  87. else if(dma8 & 0x40)
  88. dma16 = 6;
  89. else if(dma8 & 0x80)
  90. dma16 = 7;
  91. else
  92. {
  93. printk(KERN_ERR "kahlua: No 16bit DMA enabled.\n");
  94. return 1;
  95. }
  96. if(dma8 & 0x01)
  97. dma8 = 0;
  98. else if(dma8 & 0x02)
  99. dma8 = 1;
  100. else if(dma8 & 0x08)
  101. dma8 = 3;
  102. else
  103. {
  104. printk(KERN_ERR "kahlua: No 8bit DMA enabled.\n");
  105. return 1;
  106. }
  107. if(irq & 1)
  108. irq = 9;
  109. else if(irq & 2)
  110. irq = 5;
  111. else if(irq & 4)
  112. irq = 7;
  113. else if(irq & 8)
  114. irq = 10;
  115. else
  116. {
  117. printk(KERN_ERR "kahlua: SB IRQ not set.\n");
  118. return 1;
  119. }
  120. printk(KERN_INFO "kahlua: XpressAudio on IRQ %d, DMA %d, %d\n",
  121. irq, dma8, dma16);
  122. hw_config = kzalloc(sizeof(struct address_info), GFP_KERNEL);
  123. if(hw_config == NULL)
  124. {
  125. printk(KERN_ERR "kahlua: out of memory.\n");
  126. return 1;
  127. }
  128. pci_set_drvdata(pdev, hw_config);
  129. hw_config->io_base = io;
  130. hw_config->irq = irq;
  131. hw_config->dma = dma8;
  132. hw_config->dma2 = dma16;
  133. hw_config->name = "Cyrix XpressAudio";
  134. hw_config->driver_use_1 = SB_NO_MIDI | SB_PCI_IRQ;
  135. if (!request_region(io, 16, "soundblaster"))
  136. goto err_out_free;
  137. if(sb_dsp_detect(hw_config, 0, 0, NULL)==0)
  138. {
  139. printk(KERN_ERR "kahlua: audio not responding.\n");
  140. release_region(io, 16);
  141. goto err_out_free;
  142. }
  143. oldquiet = sb_be_quiet;
  144. sb_be_quiet = 1;
  145. if(sb_dsp_init(hw_config, THIS_MODULE))
  146. {
  147. sb_be_quiet = oldquiet;
  148. goto err_out_free;
  149. }
  150. sb_be_quiet = oldquiet;
  151. return 0;
  152. err_out_free:
  153. pci_set_drvdata(pdev, NULL);
  154. kfree(hw_config);
  155. return 1;
  156. }
  157. static void __devexit 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. pci_set_drvdata(pdev, NULL);
  162. kfree(hw_config);
  163. }
  164. MODULE_AUTHOR("Alan Cox");
  165. MODULE_DESCRIPTION("Kahlua VSA1 PCI Audio");
  166. MODULE_LICENSE("GPL");
  167. /*
  168. * 5530 only. The 5510/5520 decode is different.
  169. */
  170. static struct pci_device_id id_tbl[] = {
  171. { PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5530_AUDIO, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
  172. { }
  173. };
  174. MODULE_DEVICE_TABLE(pci, id_tbl);
  175. static struct pci_driver kahlua_driver = {
  176. .name = "kahlua",
  177. .id_table = id_tbl,
  178. .probe = probe_one,
  179. .remove = __devexit_p(remove_one),
  180. };
  181. static int __init kahlua_init_module(void)
  182. {
  183. printk(KERN_INFO "Cyrix Kahlua VSA1 XpressAudio support (c) Copyright 2003 Red Hat Inc\n");
  184. return pci_register_driver(&kahlua_driver);
  185. }
  186. static void __devexit kahlua_cleanup_module(void)
  187. {
  188. pci_unregister_driver(&kahlua_driver);
  189. }
  190. module_init(kahlua_init_module);
  191. module_exit(kahlua_cleanup_module);