sb_card.c 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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 pnp_registered;
  50. static int __initdata pnp = 1;
  51. /*
  52. static int __initdata uart401 = 0;
  53. */
  54. #else
  55. static int __initdata pnp = 0;
  56. #endif
  57. module_param(io, int, 000);
  58. MODULE_PARM_DESC(io, "Soundblaster i/o base address (0x220,0x240,0x260,0x280)");
  59. module_param(irq, int, 000);
  60. MODULE_PARM_DESC(irq, "IRQ (5,7,9,10)");
  61. module_param(dma, int, 000);
  62. MODULE_PARM_DESC(dma, "8-bit DMA channel (0,1,3)");
  63. module_param(dma16, int, 000);
  64. MODULE_PARM_DESC(dma16, "16-bit DMA channel (5,6,7)");
  65. module_param(mpu_io, int, 000);
  66. MODULE_PARM_DESC(mpu_io, "MPU base address");
  67. module_param(type, int, 000);
  68. MODULE_PARM_DESC(type, "You can set this to specific card type (doesn't " \
  69. "work with pnp)");
  70. module_param(sm_games, int, 000);
  71. MODULE_PARM_DESC(sm_games, "Enable support for Logitech soundman games " \
  72. "(doesn't work with pnp)");
  73. module_param(esstype, int, 000);
  74. MODULE_PARM_DESC(esstype, "ESS chip type (doesn't work with pnp)");
  75. module_param(acer, int, 000);
  76. MODULE_PARM_DESC(acer, "Set this to detect cards in some ACER notebooks "\
  77. "(doesn't work with pnp)");
  78. #ifdef CONFIG_PNP
  79. module_param(pnp, int, 000);
  80. MODULE_PARM_DESC(pnp, "Went set to 0 will disable detection using PnP. "\
  81. "Default is 1.\n");
  82. /* Not done yet.... */
  83. /*
  84. module_param(uart401, int, 000);
  85. MODULE_PARM_DESC(uart401, "When set to 1, will attempt to detect and enable"\
  86. "the mpu on some clones");
  87. */
  88. #endif /* CONFIG_PNP */
  89. /* OSS subsystem card registration shared by PnP and legacy routines */
  90. static int sb_register_oss(struct sb_card_config *scc, struct sb_module_options *sbmo)
  91. {
  92. if (!request_region(scc->conf.io_base, 16, "soundblaster")) {
  93. printk(KERN_ERR "sb: ports busy.\n");
  94. kfree(scc);
  95. return -EBUSY;
  96. }
  97. if (!sb_dsp_detect(&scc->conf, 0, 0, sbmo)) {
  98. release_region(scc->conf.io_base, 16);
  99. printk(KERN_ERR "sb: Failed DSP Detect.\n");
  100. kfree(scc);
  101. return -ENODEV;
  102. }
  103. if(!sb_dsp_init(&scc->conf, THIS_MODULE)) {
  104. printk(KERN_ERR "sb: Failed DSP init.\n");
  105. kfree(scc);
  106. return -ENODEV;
  107. }
  108. if(scc->mpucnf.io_base > 0) {
  109. scc->mpu = 1;
  110. printk(KERN_INFO "sb: Turning on MPU\n");
  111. if(!probe_sbmpu(&scc->mpucnf, THIS_MODULE))
  112. scc->mpu = 0;
  113. }
  114. return 1;
  115. }
  116. static void sb_unload(struct sb_card_config *scc)
  117. {
  118. sb_dsp_unload(&scc->conf, 0);
  119. if(scc->mpu)
  120. unload_sbmpu(&scc->mpucnf);
  121. kfree(scc);
  122. }
  123. /* Register legacy card with OSS subsystem */
  124. static int __init sb_init_legacy(void)
  125. {
  126. struct sb_module_options sbmo = {0};
  127. if((legacy = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  128. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  129. return -ENOMEM;
  130. }
  131. memset(legacy, 0, sizeof(struct sb_card_config));
  132. legacy->conf.io_base = io;
  133. legacy->conf.irq = irq;
  134. legacy->conf.dma = dma;
  135. legacy->conf.dma2 = dma16;
  136. legacy->conf.card_subtype = type;
  137. legacy->mpucnf.io_base = mpu_io;
  138. legacy->mpucnf.irq = -1;
  139. legacy->mpucnf.dma = -1;
  140. legacy->mpucnf.dma2 = -1;
  141. sbmo.esstype = esstype;
  142. sbmo.sm_games = sm_games;
  143. sbmo.acer = acer;
  144. return sb_register_oss(legacy, &sbmo);
  145. }
  146. #ifdef CONFIG_PNP
  147. /* Populate the OSS subsystem structures with information from PnP */
  148. static void sb_dev2cfg(struct pnp_dev *dev, struct sb_card_config *scc)
  149. {
  150. scc->conf.io_base = -1;
  151. scc->conf.irq = -1;
  152. scc->conf.dma = -1;
  153. scc->conf.dma2 = -1;
  154. scc->mpucnf.io_base = -1;
  155. scc->mpucnf.irq = -1;
  156. scc->mpucnf.dma = -1;
  157. scc->mpucnf.dma2 = -1;
  158. /* All clones layout their PnP tables differently and some use
  159. different logical devices for the MPU */
  160. if(!strncmp("CTL",scc->card_id,3)) {
  161. scc->conf.io_base = pnp_port_start(dev,0);
  162. scc->conf.irq = pnp_irq(dev,0);
  163. scc->conf.dma = pnp_dma(dev,0);
  164. scc->conf.dma2 = pnp_dma(dev,1);
  165. scc->mpucnf.io_base = pnp_port_start(dev,1);
  166. return;
  167. }
  168. if(!strncmp("tBA",scc->card_id,3)) {
  169. scc->conf.io_base = pnp_port_start(dev,0);
  170. scc->conf.irq = pnp_irq(dev,0);
  171. scc->conf.dma = pnp_dma(dev,0);
  172. scc->conf.dma2 = pnp_dma(dev,1);
  173. return;
  174. }
  175. if(!strncmp("ESS",scc->card_id,3)) {
  176. scc->conf.io_base = pnp_port_start(dev,0);
  177. scc->conf.irq = pnp_irq(dev,0);
  178. scc->conf.dma = pnp_dma(dev,0);
  179. scc->conf.dma2 = pnp_dma(dev,1);
  180. scc->mpucnf.io_base = pnp_port_start(dev,2);
  181. return;
  182. }
  183. if(!strncmp("CMI",scc->card_id,3)) {
  184. scc->conf.io_base = pnp_port_start(dev,0);
  185. scc->conf.irq = pnp_irq(dev,0);
  186. scc->conf.dma = pnp_dma(dev,0);
  187. scc->conf.dma2 = pnp_dma(dev,1);
  188. return;
  189. }
  190. if(!strncmp("RWB",scc->card_id,3)) {
  191. scc->conf.io_base = pnp_port_start(dev,0);
  192. scc->conf.irq = pnp_irq(dev,0);
  193. scc->conf.dma = pnp_dma(dev,0);
  194. return;
  195. }
  196. if(!strncmp("ALS",scc->card_id,3)) {
  197. if(!strncmp("ALS0007",scc->card_id,7)) {
  198. scc->conf.io_base = pnp_port_start(dev,0);
  199. scc->conf.irq = pnp_irq(dev,0);
  200. scc->conf.dma = pnp_dma(dev,0);
  201. } else {
  202. scc->conf.io_base = pnp_port_start(dev,0);
  203. scc->conf.irq = pnp_irq(dev,0);
  204. scc->conf.dma = pnp_dma(dev,1);
  205. scc->conf.dma2 = pnp_dma(dev,0);
  206. }
  207. return;
  208. }
  209. if(!strncmp("RTL",scc->card_id,3)) {
  210. scc->conf.io_base = pnp_port_start(dev,0);
  211. scc->conf.irq = pnp_irq(dev,0);
  212. scc->conf.dma = pnp_dma(dev,1);
  213. scc->conf.dma2 = pnp_dma(dev,0);
  214. }
  215. }
  216. static unsigned int sb_pnp_devices;
  217. /* Probe callback function for the PnP API */
  218. static int sb_pnp_probe(struct pnp_card_link *card, const struct pnp_card_device_id *card_id)
  219. {
  220. struct sb_card_config *scc;
  221. struct sb_module_options sbmo = {0}; /* Default to 0 for PnP */
  222. struct pnp_dev *dev = pnp_request_card_device(card, card_id->devs[0].id, NULL);
  223. if(!dev){
  224. return -EBUSY;
  225. }
  226. if((scc = kmalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  227. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  228. return -ENOMEM;
  229. }
  230. memset(scc, 0, sizeof(struct sb_card_config));
  231. printk(KERN_INFO "sb: PnP: Found Card Named = \"%s\", Card PnP id = " \
  232. "%s, Device PnP id = %s\n", card->card->name, card_id->id,
  233. dev->id->id);
  234. scc->card_id = card_id->id;
  235. scc->dev_id = dev->id->id;
  236. sb_dev2cfg(dev, scc);
  237. printk(KERN_INFO "sb: PnP: Detected at: io=0x%x, irq=%d, " \
  238. "dma=%d, dma16=%d\n", scc->conf.io_base, scc->conf.irq,
  239. scc->conf.dma, scc->conf.dma2);
  240. pnp_set_card_drvdata(card, scc);
  241. sb_pnp_devices++;
  242. return sb_register_oss(scc, &sbmo);
  243. }
  244. static void sb_pnp_remove(struct pnp_card_link *card)
  245. {
  246. struct sb_card_config *scc = pnp_get_card_drvdata(card);
  247. if(!scc)
  248. return;
  249. printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
  250. sb_unload(scc);
  251. }
  252. static struct pnp_card_driver sb_pnp_driver = {
  253. .name = "OSS SndBlstr", /* 16 character limit */
  254. .id_table = sb_pnp_card_table,
  255. .probe = sb_pnp_probe,
  256. .remove = sb_pnp_remove,
  257. };
  258. MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
  259. #endif /* CONFIG_PNP */
  260. static void __init_or_module sb_unregister_all(void)
  261. {
  262. #ifdef CONFIG_PNP
  263. if (pnp_registered)
  264. pnp_unregister_card_driver(&sb_pnp_driver);
  265. #endif
  266. }
  267. static int __init sb_init(void)
  268. {
  269. int lres = 0;
  270. int pres = 0;
  271. printk(KERN_INFO "sb: Init: Starting Probe...\n");
  272. if(io != -1 && irq != -1 && dma != -1) {
  273. printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
  274. "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
  275. lres = sb_init_legacy();
  276. } else if((io != -1 || irq != -1 || dma != -1) ||
  277. (!pnp && (io == -1 && irq == -1 && dma == -1)))
  278. printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
  279. "must be set for legacy cards.\n");
  280. #ifdef CONFIG_PNP
  281. if(pnp) {
  282. int err = pnp_register_card_driver(&sb_pnp_driver);
  283. if (!err)
  284. pnp_registered = 1;
  285. pres = sb_pnp_devices;
  286. }
  287. #endif
  288. printk(KERN_INFO "sb: Init: Done\n");
  289. /* If either PnP or Legacy registered a card then return
  290. * success */
  291. if (pres == 0 && lres <= 0) {
  292. sb_unregister_all();
  293. return -ENODEV;
  294. }
  295. return 0;
  296. }
  297. static void __exit sb_exit(void)
  298. {
  299. printk(KERN_INFO "sb: Unloading...\n");
  300. /* Unload legacy card */
  301. if (legacy) {
  302. printk (KERN_INFO "sb: Unloading legacy card\n");
  303. sb_unload(legacy);
  304. }
  305. sb_unregister_all();
  306. vfree(smw_free);
  307. smw_free = NULL;
  308. }
  309. module_init(sb_init);
  310. module_exit(sb_exit);