sb_card.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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 = 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. static unsigned int sb_pnp_devices;
  216. /* Probe callback function for the PnP API */
  217. static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
  218. {
  219. struct sb_card_config *scc;
  220. struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
  221. struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
  222. if(!dev){
  223. return -EBUSY;
  224. }
  225. if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  226. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  227. return -ENOMEM;
  228. }
  229. memset(scc, 0, sizeof(struct sb_card_config));
  230. printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
  231. "%s, Device PnP id = %s\n", card->card->name, card_id->id,
  232. dev->id->id);
  233. scc->card_id = card_id->id;
  234. scc->dev_id = dev->id->id;
  235. sb_dev2cfg(dev, scc);
  236. printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
  237. "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
  238. scc->conf.dma, scc->conf.dma2);
  239. pnp_set_card_drvdata(card, scc);
  240. sb_pnp_devices++;
  241. return sb_register_oss(scc, &sbmo);
  242. }
  243. static void sb_pnp_remove(struct pnp_card_link *card)
  244. {
  245. struct sb_card_config *scc = pnp_get_card_drvdata(card);
  246. if(!scc)
  247. return;
  248. printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
  249. sb_unload(scc);
  250. }
  251. static struct pnp_card_driver sb_pnp_driver = {
  252. .name = "OSS SndBlstr", /* 16 character limit */
  253. .id_table = sb_pnp_card_table,
  254. .probe = sb_pnp_probe,
  255. .remove = sb_pnp_remove,
  256. };
  257. MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
  258. #endif /* CONFIG_PNP */
  259. static void __init_or_module sb_unregister_all(void)
  260. {
  261. #ifdef CONFIG_PNP
  262. if (pnp_registered)
  263. pnp_unregister_card_driver(&sb_pnp_driver);
  264. #endif
  265. }
  266. static int __init sb_init(void)
  267. {
  268. int lres = 0;
  269. int pres = 0;
  270. printk(KERN_INFO "sb: Init: Starting Probe...\n");
  271. if(io != -1 && irq != -1 && dma != -1) {
  272. printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
  273. "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
  274. lres = sb_init_legacy();
  275. } else if((io != -1 || irq != -1 || dma != -1) ||
  276. (!pnp && (io == -1 && irq == -1 && dma == -1)))
  277. printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
  278. "must be set for legacy cards.\n");
  279. #ifdef CONFIG_PNP
  280. if(pnp) {
  281. int err = pnp_register_card_driver(&sb_pnp_driver);
  282. if (!err)
  283. pnp_registered = 1;
  284. pres = sb_pnp_devices;
  285. }
  286. #endif
  287. printk(KERN_INFO "sb: Init: Done\n");
  288. /* If either PnP or Legacy registered a card then return
  289. * success */
  290. if (pres == 0 && lres <= 0) {
  291. sb_unregister_all();
  292. return -ENODEV;
  293. }
  294. return 0;
  295. }
  296. static void __exit sb_exit(void)
  297. {
  298. printk(KERN_INFO "sb: Unloading...\n");
  299. /* Unload legacy card */
  300. if (legacy) {
  301. printk (KERN_INFO "sb: Unloading legacy card\n");
  302. sb_unload(legacy);
  303. }
  304. sb_unregister_all();
  305. vfree(smw_free);
  306. smw_free = NULL;
  307. }
  308. module_init(sb_init);
  309. module_exit(sb_exit);