sb_card.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353
  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/module.h>
  25. #include <linux/moduleparam.h>
  26. #include <linux/init.h>
  27. #include "sound_config.h"
  28. #include "sb_mixer.h"
  29. #include "sb.h"
  30. #ifdef CONFIG_PNP
  31. #include <linux/pnp.h>
  32. #endif /* CONFIG_PNP */
  33. #include "sb_card.h"
  34. MODULE_DESCRIPTION("OSS Soundblaster ISA PnP and legacy sound driver");
  35. MODULE_LICENSE("GPL");
  36. extern void *smw_free;
  37. static int __initdata mpu_io = 0;
  38. static int __initdata io = -1;
  39. static int __initdata irq = -1;
  40. static int __initdata dma = -1;
  41. static int __initdata dma16 = -1;
  42. static int __initdata type = 0; /* Can set this to a specific card type */
  43. static int __initdata esstype = 0; /* ESS chip type */
  44. static int __initdata acer = 0; /* Do acer notebook init? */
  45. static int __initdata sm_games = 0; /* Logitech soundman games? */
  46. static struct sb_card_config *legacy = NULL;
  47. #ifdef CONFIG_PNP
  48. static int pnp_registered;
  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 __init sb_init_legacy(void)
  124. {
  125. struct sb_module_options sbmo = {0};
  126. if((legacy = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  127. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  128. return -ENOMEM;
  129. }
  130. legacy->conf.io_base = io;
  131. legacy->conf.irq = irq;
  132. legacy->conf.dma = dma;
  133. legacy->conf.dma2 = dma16;
  134. legacy->conf.card_subtype = type;
  135. legacy->mpucnf.io_base = mpu_io;
  136. legacy->mpucnf.irq = -1;
  137. legacy->mpucnf.dma = -1;
  138. legacy->mpucnf.dma2 = -1;
  139. sbmo.esstype = esstype;
  140. sbmo.sm_games = sm_games;
  141. sbmo.acer = acer;
  142. return sb_register_oss(legacy, &sbmo);
  143. }
  144. #ifdef CONFIG_PNP
  145. /* Populate the OSS subsystem structures with information from PnP */
  146. static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
  147. {
  148. scc->conf.io_base = -1;
  149. scc->conf.irq = -1;
  150. scc->conf.dma = -1;
  151. scc->conf.dma2 = -1;
  152. scc->mpucnf.io_base = -1;
  153. scc->mpucnf.irq = -1;
  154. scc->mpucnf.dma = -1;
  155. scc->mpucnf.dma2 = -1;
  156. /* All clones layout their PnP tables differently and some use
  157. different logical devices for the MPU */
  158. if(!strncmp("CTL",scc->card_id,3)) {
  159. scc->conf.io_base = pnp_port_start(dev,0);
  160. scc->conf.irq = pnp_irq(dev,0);
  161. scc->conf.dma = pnp_dma(dev,0);
  162. scc->conf.dma2 = pnp_dma(dev,1);
  163. scc->mpucnf.io_base = pnp_port_start(dev,1);
  164. return;
  165. }
  166. if(!strncmp("tBA",scc->card_id,3)) {
  167. scc->conf.io_base = pnp_port_start(dev,0);
  168. scc->conf.irq = pnp_irq(dev,0);
  169. scc->conf.dma = pnp_dma(dev,0);
  170. scc->conf.dma2 = pnp_dma(dev,1);
  171. return;
  172. }
  173. if(!strncmp("ESS",scc->card_id,3)) {
  174. scc->conf.io_base = pnp_port_start(dev,0);
  175. scc->conf.irq = pnp_irq(dev,0);
  176. scc->conf.dma = pnp_dma(dev,0);
  177. scc->conf.dma2 = pnp_dma(dev,1);
  178. scc->mpucnf.io_base = pnp_port_start(dev,2);
  179. return;
  180. }
  181. if(!strncmp("CMI",scc->card_id,3)) {
  182. scc->conf.io_base = pnp_port_start(dev,0);
  183. scc->conf.irq = pnp_irq(dev,0);
  184. scc->conf.dma = pnp_dma(dev,0);
  185. scc->conf.dma2 = pnp_dma(dev,1);
  186. return;
  187. }
  188. if(!strncmp("RWB",scc->card_id,3)) {
  189. scc->conf.io_base = pnp_port_start(dev,0);
  190. scc->conf.irq = pnp_irq(dev,0);
  191. scc->conf.dma = pnp_dma(dev,0);
  192. return;
  193. }
  194. if(!strncmp("ALS",scc->card_id,3)) {
  195. if(!strncmp("ALS0007",scc->card_id,7)) {
  196. scc->conf.io_base = pnp_port_start(dev,0);
  197. scc->conf.irq = pnp_irq(dev,0);
  198. scc->conf.dma = pnp_dma(dev,0);
  199. } else {
  200. scc->conf.io_base = pnp_port_start(dev,0);
  201. scc->conf.irq = pnp_irq(dev,0);
  202. scc->conf.dma = pnp_dma(dev,1);
  203. scc->conf.dma2 = pnp_dma(dev,0);
  204. }
  205. return;
  206. }
  207. if(!strncmp("RTL",scc->card_id,3)) {
  208. scc->conf.io_base = pnp_port_start(dev,0);
  209. scc->conf.irq = pnp_irq(dev,0);
  210. scc->conf.dma = pnp_dma(dev,1);
  211. scc->conf.dma2 = pnp_dma(dev,0);
  212. }
  213. }
  214. static unsigned int sb_pnp_devices;
  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 = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  225. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  226. return -ENOMEM;
  227. }
  228. printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
  229. "%s, Device PnP id = %s\n", card->card->name, card_id->id,
  230. dev->id->id);
  231. scc->card_id = card_id->id;
  232. scc->dev_id = dev->id->id;
  233. sb_dev2cfg(dev, scc);
  234. printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
  235. "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
  236. scc->conf.dma, scc->conf.dma2);
  237. pnp_set_card_drvdata(card, scc);
  238. sb_pnp_devices++;
  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 void __init_or_module sb_unregister_all(void)
  258. {
  259. #ifdef CONFIG_PNP
  260. if (pnp_registered)
  261. pnp_unregister_card_driver(&sb_pnp_driver);
  262. #endif
  263. }
  264. static int __init sb_init(void)
  265. {
  266. int lres = 0;
  267. int pres = 0;
  268. printk(KERN_INFO "sb: Init: Starting Probe...\n");
  269. if(io != -1 && irq != -1 && dma != -1) {
  270. printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
  271. "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
  272. lres = sb_init_legacy();
  273. } else if((io != -1 || irq != -1 || dma != -1) ||
  274. (!pnp && (io == -1 && irq == -1 && dma == -1)))
  275. printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
  276. "must be set for legacy cards.\n");
  277. #ifdef CONFIG_PNP
  278. if(pnp) {
  279. int err = pnp_register_card_driver(&sb_pnp_driver);
  280. if (!err)
  281. pnp_registered = 1;
  282. pres = sb_pnp_devices;
  283. }
  284. #endif
  285. printk(KERN_INFO "sb: Init: Done\n");
  286. /* If either PnP or Legacy registered a card then return
  287. * success */
  288. if (pres == 0 && lres <= 0) {
  289. sb_unregister_all();
  290. return -ENODEV;
  291. }
  292. return 0;
  293. }
  294. static void __exit sb_exit(void)
  295. {
  296. printk(KERN_INFO "sb: Unloading...\n");
  297. /* Unload legacy card */
  298. if (legacy) {
  299. printk (KERN_INFO "sb: Unloading legacy card\n");
  300. sb_unload(legacy);
  301. }
  302. sb_unregister_all();
  303. vfree(smw_free);
  304. smw_free = NULL;
  305. }
  306. module_init(sb_init);
  307. module_exit(sb_exit);