sb_card.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. /*
  2. * sound/oss/sb_card.c
  3. *
  4. * Detection routine for the ISA Sound Blaster and compatible 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/slab.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 = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  128. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  129. return -ENOMEM;
  130. }
  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 = kzalloc(sizeof(struct sb_card_config), GFP_KERNEL)) == NULL) {
  226. printk(KERN_ERR "sb: Error: Could not allocate memory\n");
  227. return -ENOMEM;
  228. }
  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. sb_pnp_devices++;
  240. return sb_register_oss(scc, &sbmo);
  241. }
  242. static void sb_pnp_remove(struct pnp_card_link *card)
  243. {
  244. struct sb_card_config *scc = pnp_get_card_drvdata(card);
  245. if(!scc)
  246. return;
  247. printk(KERN_INFO "sb: PnP: Removing %s\n", scc->card_id);
  248. sb_unload(scc);
  249. }
  250. static struct pnp_card_driver sb_pnp_driver = {
  251. .name = "OSS SndBlstr", /* 16 character limit */
  252. .id_table = sb_pnp_card_table,
  253. .probe = sb_pnp_probe,
  254. .remove = sb_pnp_remove,
  255. };
  256. MODULE_DEVICE_TABLE(pnp_card, sb_pnp_card_table);
  257. #endif /* CONFIG_PNP */
  258. static void sb_unregister_all(void)
  259. {
  260. #ifdef CONFIG_PNP
  261. if (pnp_registered)
  262. pnp_unregister_card_driver(&sb_pnp_driver);
  263. #endif
  264. }
  265. static int __init sb_init(void)
  266. {
  267. int lres = 0;
  268. int pres = 0;
  269. printk(KERN_INFO "sb: Init: Starting Probe...\n");
  270. if(io != -1 && irq != -1 && dma != -1) {
  271. printk(KERN_INFO "sb: Probing legacy card with io=%x, "\
  272. "irq=%d, dma=%d, dma16=%d\n",io, irq, dma, dma16);
  273. lres = sb_init_legacy();
  274. } else if((io != -1 || irq != -1 || dma != -1) ||
  275. (!pnp && (io == -1 && irq == -1 && dma == -1)))
  276. printk(KERN_ERR "sb: Error: At least io, irq, and dma "\
  277. "must be set for legacy cards.\n");
  278. #ifdef CONFIG_PNP
  279. if(pnp) {
  280. int err = pnp_register_card_driver(&sb_pnp_driver);
  281. if (!err)
  282. pnp_registered = 1;
  283. pres = sb_pnp_devices;
  284. }
  285. #endif
  286. printk(KERN_INFO "sb: Init: Done\n");
  287. /* If either PnP or Legacy registered a card then return
  288. * success */
  289. if (pres == 0 && lres <= 0) {
  290. sb_unregister_all();
  291. return -ENODEV;
  292. }
  293. return 0;
  294. }
  295. static void __exit sb_exit(void)
  296. {
  297. printk(KERN_INFO "sb: Unloading...\n");
  298. /* Unload legacy card */
  299. if (legacy) {
  300. printk (KERN_INFO "sb: Unloading legacy card\n");
  301. sb_unload(legacy);
  302. }
  303. sb_unregister_all();
  304. vfree(smw_free);
  305. smw_free = NULL;
  306. }
  307. module_init(sb_init);
  308. module_exit(sb_exit);