sb_card.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /*
  2. * sound/oss/sb_card.c
  3. *
  4. * Detection routine for the ISA Sound Blaster and compatable sound
  5. * cards.
  6. *
  7. * This file is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
  8. * Version 2 (June 1991). See the "COPYING" file distributed with this
  9. * software for more info.
  10. *
  11. * This is a complete rewrite of the detection routines. This was
  12. * prompted by the PnP API change during v2.5 and the ugly state the
  13. * code was in.
  14. *
  15. * Copyright (C) by Paul Laufer 2002. Based on code originally by
  16. * Hannu Savolainen which was modified by many others over the
  17. * years. Authors specifically mentioned in the previous version were:
  18. * Daniel Stone, Alessandro Zummo, Jeff Garzik, Arnaldo Carvalho de
  19. * Melo, Daniel Church, and myself.
  20. *
  21. * 02-05-2003 Original Release, Paul Laufer <paul@laufernet.com>
  22. * 02-07-2003 Bug made it into first release. Take two.
  23. */
  24. #include <linux/config.h>
  25. #include <linux/module.h>
  26. #include <linux/moduleparam.h>
  27. #include <linux/init.h>
  28. #include "sound_config.h"
  29. #include "sb_mixer.h"
  30. #include "sb.h"
  31. #ifdef CONFIG_PNP
  32. #include <linux/pnp.h>
  33. #endif /* CONFIG_PNP */
  34. #include "sb_card.h"
  35. MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
  36. MODULE_LICENSE("GPL");
  37. extern void *smw_free;
  38. static int __initdata mpu_io = 0;
  39. static int __initdata io = -1;
  40. static int __initdata irq = -1;
  41. static int __initdata dma = -1;
  42. static int __initdata dma16 = -1;
  43. static int __initdata type = 0; /* Can set this to a specific card type */
  44. static int __initdata esstype = 0; /* ESS chip type */
  45. static int __initdata acer = 0; /* Do acer notebook init? */
  46. static int __initdata sm_games = 0; /* Logitech soundman games? */
  47. static struct sb_card_config *legacy = NULL;
  48. #ifdef CONFIG_PNP
  49. static int __initdata pnp = 1;
  50. /*
  51. static int __initdata uart401 = 0;
  52. */
  53. #else
  54. static int __initdata pnp = 0;
  55. #endif
  56. module_param(io, int, 000);
  57. MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
  58. module_param(irq, int, 000);
  59. MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
  60. module_param(dma, int, 000);
  61. MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
  62. module_param(dma16, int, 000);
  63. MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
  64. module_param(mpu_io, int, 000);
  65. MODULE_PARM_DESC(mpu_io, "MPU base address");
  66. module_param(type, int, 000);
  67. MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
  68. "work with pnp)");
  69. module_param(sm_games, int, 000);
  70. MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
  71. "(doesn't work with pnp)");
  72. module_param(esstype, int, 000);
  73. MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
  74. module_param(acer, int, 000);
  75. MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
  76. "(doesn't work with pnp)");
  77. #ifdef CONFIG_PNP
  78. module_param(pnp, int, 000);
  79. MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
  80. "Default is 1.\n");
  81. /* Not done yet.... */
  82. /*
  83. module_param(uart401, int, 000);
  84. MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
  85. "the mpu on some clones");
  86. */
  87. #endif /* CONFIG_PNP */
  88. /* OSS subsystem card registration shared by PnP and legacy routines */
  89. static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
  90. {
  91. if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
  92. printk(KERN_ERR "sb: ports busy.\n");
  93. kfree(scc);
  94. return -EBUSY;
  95. }
  96. if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
  97. release_region(scc->conf.io_base, 16);
  98. printk(KERN_ERR "sb: Failed DSP Detect.\n");
  99. kfree(scc);
  100. return -ENODEV;
  101. }
  102. if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
  103. printk(KERN_ERR "sb: Failed DSP init.\n");
  104. kfree(scc);
  105. return -ENODEV;
  106. }
  107. if(scc->mpucnf.io_base > 0) {
  108. scc->mpu = 1;
  109. printk(KERN_INFO "sb: Turning on MPU\n");
  110. if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
  111. scc->mpu = 0;
  112. }
  113. return 1;
  114. }
  115. static void sb_unload(struct sb_card_config *scc)
  116. {
  117. sb_dsp_unload(&scc->conf, 0);
  118. if(scc->mpu)
  119. unload_sbmpu(&scc->mpucnf);
  120. kfree(scc);
  121. }
  122. /* Register legacy card with OSS subsystem */
  123. static int sb_init_legacy(void)
  124. {
  125. struct sb_module_options sbmo = {0};
  126. if((legacy = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  127. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  128. return -ENOMEM;
  129. }
  130. memset(legacy, 0, sizeof(struct sb_card_config));
  131. legacy->conf.io_base = io;
  132. legacy->conf.irq = irq;
  133. legacy->conf.dma = dma;
  134. legacy->conf.dma2 = dma16;
  135. legacy->conf.card_subtype = type;
  136. legacy->mpucnf.io_base = mpu_io;
  137. legacy->mpucnf.irq = -1;
  138. legacy->mpucnf.dma = -1;
  139. legacy->mpucnf.dma2 = -1;
  140. sbmo.esstype = esstype;
  141. sbmo.sm_games = sm_games;
  142. sbmo.acer = acer;
  143. return sb_register_oss(legacy, &sbmo);
  144. }
  145. #ifdef CONFIG_PNP
  146. /* Populate the OSS subsystem structures with information from PnP */
  147. static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
  148. {
  149. scc->conf.io_base = -1;
  150. scc->conf.irq = -1;
  151. scc->conf.dma = -1;
  152. scc->conf.dma2 = -1;
  153. scc->mpucnf.io_base = -1;
  154. scc->mpucnf.irq = -1;
  155. scc->mpucnf.dma = -1;
  156. scc->mpucnf.dma2 = -1;
  157. /* All clones layout their PnP tables differently and some use
  158. different logical devices for the MPU */
  159. if(!strncmp("CTL",scc->card_id,3)) {
  160. scc->conf.io_base = pnp_port_start(dev,0);
  161. scc->conf.irq = pnp_irq(dev,0);
  162. scc->conf.dma = pnp_dma(dev,0);
  163. scc->conf.dma2 = pnp_dma(dev,1);
  164. scc->mpucnf.io_base = pnp_port_start(dev,1);
  165. return;
  166. }
  167. if(!strncmp("tBA",scc->card_id,3)) {
  168. scc->conf.io_base = pnp_port_start(dev,0);
  169. scc->conf.irq = pnp_irq(dev,0);
  170. scc->conf.dma = pnp_dma(dev,0);
  171. scc->conf.dma2 = pnp_dma(dev,1);
  172. return;
  173. }
  174. if(!strncmp("ESS",scc->card_id,3)) {
  175. scc->conf.io_base = pnp_port_start(dev,0);
  176. scc->conf.irq = pnp_irq(dev,0);
  177. scc->conf.dma = pnp_dma(dev,0);
  178. scc->conf.dma2 = pnp_dma(dev,1);
  179. scc->mpucnf.io_base = pnp_port_start(dev,2);
  180. return;
  181. }
  182. if(!strncmp("CMI",scc->card_id,3)) {
  183. scc->conf.io_base = pnp_port_start(dev,0);
  184. scc->conf.irq = pnp_irq(dev,0);
  185. scc->conf.dma = pnp_dma(dev,0);
  186. scc->conf.dma2 = pnp_dma(dev,1);
  187. return;
  188. }
  189. if(!strncmp("RWB",scc->card_id,3)) {
  190. scc->conf.io_base = pnp_port_start(dev,0);
  191. scc->conf.irq = pnp_irq(dev,0);
  192. scc->conf.dma = pnp_dma(dev,0);
  193. return;
  194. }
  195. if(!strncmp("ALS",scc->card_id,3)) {
  196. if(!strncmp("ALS0007",scc->card_id,7)) {
  197. scc->conf.io_base = pnp_port_start(dev,0);
  198. scc->conf.irq = pnp_irq(dev,0);
  199. scc->conf.dma = pnp_dma(dev,0);
  200. } else {
  201. scc->conf.io_base = pnp_port_start(dev,0);
  202. scc->conf.irq = pnp_irq(dev,0);
  203. scc->conf.dma = pnp_dma(dev,1);
  204. scc->conf.dma2 = pnp_dma(dev,0);
  205. }
  206. return;
  207. }
  208. if(!strncmp("RTL",scc->card_id,3)) {
  209. scc->conf.io_base = pnp_port_start(dev,0);
  210. scc->conf.irq = pnp_irq(dev,0);
  211. scc->conf.dma = pnp_dma(dev,1);
  212. scc->conf.dma2 = pnp_dma(dev,0);
  213. }
  214. }
  215. /* Probe callback function for the PnP API */
  216. static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
  217. {
  218. struct sb_card_config *scc;
  219. struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
  220. struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
  221. if(!dev){
  222. return -EBUSY;
  223. }
  224. if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  225. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  226. return -ENOMEM;
  227. }
  228. memset(scc, 0, sizeof(struct sb_card_config));
  229. printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
  230. "%s, Device PnP id = %s\n", card->card->name, card_id->id,
  231. dev->id->id);
  232. scc->card_id = card_id->id;
  233. scc->dev_id = dev->id->id;
  234. sb_dev2cfg(dev, scc);
  235. printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
  236. "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
  237. scc->conf.dma, scc->conf.dma2);
  238. pnp_set_card_drvdata(card, scc);
  239. return sb_register_oss(scc, &sbmo);
  240. }
  241. static void sb_pnp_remove(struct pnp_card_link *card)
  242. {
  243. struct sb_card_config *scc = pnp_get_card_drvdata(card);
  244. if(!scc)
  245. return;
  246. printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
  247. sb_unload(scc);
  248. }
  249. static struct pnp_card_driver sb_pnp_driver = {
  250. .name = "OSS SndBlstr", /* 16 character limit */
  251. .id_table = sb_pnp_card_table,
  252. .probe = sb_pnp_probe,
  253. .remove = sb_pnp_remove,
  254. };
  255. MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
  256. #endif /* CONFIG_PNP */
  257. static int __init sb_init(void)
  258. {
  259. int lres = 0;
  260. int pres = 0;
  261. printk(KERN_INFO "sb: Init: Starting Probe...\n");
  262. if(io != -1 && irq != -1 && dma != -1) {
  263. printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
  264. "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
  265. lres = sb_init_legacy();
  266. } else if((io != -1 || irq != -1 || dma != -1) ||
  267. (!pnp && (io == -1 && irq == -1 && dma == -1)))
  268. printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
  269. "must be set for legacy cards.\n");
  270. #ifdef CONFIG_PNP
  271. if(pnp) {
  272. pres = pnp_register_card_driver(&sb_pnp_driver);
  273. }
  274. #endif
  275. printk(KERN_INFO "sb: Init: Done\n");
  276. /* If either PnP or Legacy registered a card then return
  277. * success */
  278. if (pres <= 0 && lres <= 0) {
  279. #ifdef CONFIG_PNP
  280. pnp_unregister_card_driver(&sb_pnp_driver);
  281. #endif
  282. return -ENODEV;
  283. }
  284. return 0;
  285. }
  286. static void __exit sb_exit(void)
  287. {
  288. printk(KERN_INFO "sb: Unloading...\n");
  289. /* Unload legacy card */
  290. if (legacy) {
  291. printk (KERN_INFO "sb: Unloading legacy card\n");
  292. sb_unload(legacy);
  293. }
  294. #ifdef CONFIG_PNP
  295. pnp_unregister_card_driver(&sb_pnp_driver);
  296. #endif
  297. if (smw_free) {
  298. vfree(smw_free);
  299. smw_free = NULL;
  300. }
  301. }
  302. module_init(sb_init);
  303. module_exit(sb_exit);