sc6000.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715
  1. /*
  2. * Driver for Gallant SC-6000 soundcard. This card is also known as
  3. * Audio Excel DSP 16 or Zoltrix AV302.
  4. * These cards use CompuMedia ASC-9308 chip + AD1848 codec.
  5. * SC-6600 and SC-7000 cards are also supported. They are based on
  6. * CompuMedia ASC-9408 chip and CS4231 codec.
  7. *
  8. * Copyright (C) 2007 Krzysztof Helt <krzysztof.h1@wp.pl>
  9. *
  10. * I don't have documentation for this card. I used the driver
  11. * for OSS/Free included in the kernel source as reference.
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 2 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program; if not, write to the Free Software
  25. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  26. */
  27. #include <linux/module.h>
  28. #include <linux/delay.h>
  29. #include <linux/isa.h>
  30. #include <linux/io.h>
  31. #include <asm/dma.h>
  32. #include <sound/core.h>
  33. #include <sound/wss.h>
  34. #include <sound/opl3.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/control.h>
  37. #define SNDRV_LEGACY_FIND_FREE_IRQ
  38. #define SNDRV_LEGACY_FIND_FREE_DMA
  39. #include <sound/initval.h>
  40. MODULE_AUTHOR("Krzysztof Helt");
  41. MODULE_DESCRIPTION("Gallant SC-6000");
  42. MODULE_LICENSE("GPL");
  43. MODULE_SUPPORTED_DEVICE("{{Gallant, SC-6000},"
  44. "{AudioExcel, Audio Excel DSP 16},"
  45. "{Zoltrix, AV302}}");
  46. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  47. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  48. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  49. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220, 0x240 */
  50. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5, 7, 9, 10, 11 */
  51. static long mss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x530, 0xe80 */
  52. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  53. /* 0x300, 0x310, 0x320, 0x330 */
  54. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5, 7, 9, 10, 0 */
  55. static int dma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0, 1, 3 */
  56. static bool joystick[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = false };
  57. module_param_array(index, int, NULL, 0444);
  58. MODULE_PARM_DESC(index, "Index value for sc-6000 based soundcard.");
  59. module_param_array(id, charp, NULL, 0444);
  60. MODULE_PARM_DESC(id, "ID string for sc-6000 based soundcard.");
  61. module_param_array(enable, bool, NULL, 0444);
  62. MODULE_PARM_DESC(enable, "Enable sc-6000 based soundcard.");
  63. module_param_array(port, long, NULL, 0444);
  64. MODULE_PARM_DESC(port, "Port # for sc-6000 driver.");
  65. module_param_array(mss_port, long, NULL, 0444);
  66. MODULE_PARM_DESC(mss_port, "MSS Port # for sc-6000 driver.");
  67. module_param_array(mpu_port, long, NULL, 0444);
  68. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for sc-6000 driver.");
  69. module_param_array(irq, int, NULL, 0444);
  70. MODULE_PARM_DESC(irq, "IRQ # for sc-6000 driver.");
  71. module_param_array(mpu_irq, int, NULL, 0444);
  72. MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for sc-6000 driver.");
  73. module_param_array(dma, int, NULL, 0444);
  74. MODULE_PARM_DESC(dma, "DMA # for sc-6000 driver.");
  75. module_param_array(joystick, bool, NULL, 0444);
  76. MODULE_PARM_DESC(joystick, "Enable gameport.");
  77. /*
  78. * Commands of SC6000's DSP (SBPRO+special).
  79. * Some of them are COMMAND_xx, in the future they may change.
  80. */
  81. #define WRITE_MDIRQ_CFG 0x50 /* Set M&I&DRQ mask (the real config) */
  82. #define COMMAND_52 0x52 /* */
  83. #define READ_HARD_CFG 0x58 /* Read Hardware Config (I/O base etc) */
  84. #define COMMAND_5C 0x5c /* */
  85. #define COMMAND_60 0x60 /* */
  86. #define COMMAND_66 0x66 /* */
  87. #define COMMAND_6C 0x6c /* */
  88. #define COMMAND_6E 0x6e /* */
  89. #define COMMAND_88 0x88 /* Unknown command */
  90. #define DSP_INIT_MSS 0x8c /* Enable Microsoft Sound System mode */
  91. #define COMMAND_C5 0xc5 /* */
  92. #define GET_DSP_VERSION 0xe1 /* Get DSP Version */
  93. #define GET_DSP_COPYRIGHT 0xe3 /* Get DSP Copyright */
  94. /*
  95. * Offsets of SC6000 DSP I/O ports. The offset is added to base I/O port
  96. * to have the actual I/O port.
  97. * Register permissions are:
  98. * (wo) == Write Only
  99. * (ro) == Read Only
  100. * (w-) == Write
  101. * (r-) == Read
  102. */
  103. #define DSP_RESET 0x06 /* offset of DSP RESET (wo) */
  104. #define DSP_READ 0x0a /* offset of DSP READ (ro) */
  105. #define DSP_WRITE 0x0c /* offset of DSP WRITE (w-) */
  106. #define DSP_COMMAND 0x0c /* offset of DSP COMMAND (w-) */
  107. #define DSP_STATUS 0x0c /* offset of DSP STATUS (r-) */
  108. #define DSP_DATAVAIL 0x0e /* offset of DSP DATA AVAILABLE (ro) */
  109. #define PFX "sc6000: "
  110. #define DRV_NAME "SC-6000"
  111. /* hardware dependent functions */
  112. /*
  113. * sc6000_irq_to_softcfg - Decode irq number into cfg code.
  114. */
  115. static unsigned char sc6000_irq_to_softcfg(int irq)
  116. {
  117. unsigned char val = 0;
  118. switch (irq) {
  119. case 5:
  120. val = 0x28;
  121. break;
  122. case 7:
  123. val = 0x8;
  124. break;
  125. case 9:
  126. val = 0x10;
  127. break;
  128. case 10:
  129. val = 0x18;
  130. break;
  131. case 11:
  132. val = 0x20;
  133. break;
  134. default:
  135. break;
  136. }
  137. return val;
  138. }
  139. /*
  140. * sc6000_dma_to_softcfg - Decode dma number into cfg code.
  141. */
  142. static unsigned char sc6000_dma_to_softcfg(int dma)
  143. {
  144. unsigned char val = 0;
  145. switch (dma) {
  146. case 0:
  147. val = 1;
  148. break;
  149. case 1:
  150. val = 2;
  151. break;
  152. case 3:
  153. val = 3;
  154. break;
  155. default:
  156. break;
  157. }
  158. return val;
  159. }
  160. /*
  161. * sc6000_mpu_irq_to_softcfg - Decode MPU-401 irq number into cfg code.
  162. */
  163. static unsigned char sc6000_mpu_irq_to_softcfg(int mpu_irq)
  164. {
  165. unsigned char val = 0;
  166. switch (mpu_irq) {
  167. case 5:
  168. val = 4;
  169. break;
  170. case 7:
  171. val = 0x44;
  172. break;
  173. case 9:
  174. val = 0x84;
  175. break;
  176. case 10:
  177. val = 0xc4;
  178. break;
  179. default:
  180. break;
  181. }
  182. return val;
  183. }
  184. static int sc6000_wait_data(char __iomem *vport)
  185. {
  186. int loop = 1000;
  187. unsigned char val = 0;
  188. do {
  189. val = ioread8(vport + DSP_DATAVAIL);
  190. if (val & 0x80)
  191. return 0;
  192. cpu_relax();
  193. } while (loop--);
  194. return -EAGAIN;
  195. }
  196. static int sc6000_read(char __iomem *vport)
  197. {
  198. if (sc6000_wait_data(vport))
  199. return -EBUSY;
  200. return ioread8(vport + DSP_READ);
  201. }
  202. static int sc6000_write(char __iomem *vport, int cmd)
  203. {
  204. unsigned char val;
  205. int loop = 500000;
  206. do {
  207. val = ioread8(vport + DSP_STATUS);
  208. /*
  209. * DSP ready to receive data if bit 7 of val == 0
  210. */
  211. if (!(val & 0x80)) {
  212. iowrite8(cmd, vport + DSP_COMMAND);
  213. return 0;
  214. }
  215. cpu_relax();
  216. } while (loop--);
  217. snd_printk(KERN_ERR "DSP Command (0x%x) timeout.\n", cmd);
  218. return -EIO;
  219. }
  220. static int sc6000_dsp_get_answer(char __iomem *vport, int command,
  221. char *data, int data_len)
  222. {
  223. int len = 0;
  224. if (sc6000_write(vport, command)) {
  225. snd_printk(KERN_ERR "CMD 0x%x: failed!\n", command);
  226. return -EIO;
  227. }
  228. do {
  229. int val = sc6000_read(vport);
  230. if (val < 0)
  231. break;
  232. data[len++] = val;
  233. } while (len < data_len);
  234. /*
  235. * If no more data available, return to the caller, no error if len>0.
  236. * We have no other way to know when the string is finished.
  237. */
  238. return len ? len : -EIO;
  239. }
  240. static int sc6000_dsp_reset(char __iomem *vport)
  241. {
  242. iowrite8(1, vport + DSP_RESET);
  243. udelay(10);
  244. iowrite8(0, vport + DSP_RESET);
  245. udelay(20);
  246. if (sc6000_read(vport) == 0xaa)
  247. return 0;
  248. return -ENODEV;
  249. }
  250. /* detection and initialization */
  251. static int sc6000_hw_cfg_write(char __iomem *vport, const int *cfg)
  252. {
  253. if (sc6000_write(vport, COMMAND_6C) < 0) {
  254. snd_printk(KERN_WARNING "CMD 0x%x: failed!\n", COMMAND_6C);
  255. return -EIO;
  256. }
  257. if (sc6000_write(vport, COMMAND_5C) < 0) {
  258. snd_printk(KERN_ERR "CMD 0x%x: failed!\n", COMMAND_5C);
  259. return -EIO;
  260. }
  261. if (sc6000_write(vport, cfg[0]) < 0) {
  262. snd_printk(KERN_ERR "DATA 0x%x: failed!\n", cfg[0]);
  263. return -EIO;
  264. }
  265. if (sc6000_write(vport, cfg[1]) < 0) {
  266. snd_printk(KERN_ERR "DATA 0x%x: failed!\n", cfg[1]);
  267. return -EIO;
  268. }
  269. if (sc6000_write(vport, COMMAND_C5) < 0) {
  270. snd_printk(KERN_ERR "CMD 0x%x: failed!\n", COMMAND_C5);
  271. return -EIO;
  272. }
  273. return 0;
  274. }
  275. static int sc6000_cfg_write(char __iomem *vport, unsigned char softcfg)
  276. {
  277. if (sc6000_write(vport, WRITE_MDIRQ_CFG)) {
  278. snd_printk(KERN_ERR "CMD 0x%x: failed!\n", WRITE_MDIRQ_CFG);
  279. return -EIO;
  280. }
  281. if (sc6000_write(vport, softcfg)) {
  282. snd_printk(KERN_ERR "sc6000_cfg_write: failed!\n");
  283. return -EIO;
  284. }
  285. return 0;
  286. }
  287. static int sc6000_setup_board(char __iomem *vport, int config)
  288. {
  289. int loop = 10;
  290. do {
  291. if (sc6000_write(vport, COMMAND_88)) {
  292. snd_printk(KERN_ERR "CMD 0x%x: failed!\n",
  293. COMMAND_88);
  294. return -EIO;
  295. }
  296. } while ((sc6000_wait_data(vport) < 0) && loop--);
  297. if (sc6000_read(vport) < 0) {
  298. snd_printk(KERN_ERR "sc6000_read after CMD 0x%x: failed\n",
  299. COMMAND_88);
  300. return -EIO;
  301. }
  302. if (sc6000_cfg_write(vport, config))
  303. return -ENODEV;
  304. return 0;
  305. }
  306. static int sc6000_init_mss(char __iomem *vport, int config,
  307. char __iomem *vmss_port, int mss_config)
  308. {
  309. if (sc6000_write(vport, DSP_INIT_MSS)) {
  310. snd_printk(KERN_ERR "sc6000_init_mss [0x%x]: failed!\n",
  311. DSP_INIT_MSS);
  312. return -EIO;
  313. }
  314. msleep(10);
  315. if (sc6000_cfg_write(vport, config))
  316. return -EIO;
  317. iowrite8(mss_config, vmss_port);
  318. return 0;
  319. }
  320. static void sc6000_hw_cfg_encode(char __iomem *vport, int *cfg,
  321. long xport, long xmpu,
  322. long xmss_port, int joystick)
  323. {
  324. cfg[0] = 0;
  325. cfg[1] = 0;
  326. if (xport == 0x240)
  327. cfg[0] |= 1;
  328. if (xmpu != SNDRV_AUTO_PORT) {
  329. cfg[0] |= (xmpu & 0x30) >> 2;
  330. cfg[1] |= 0x20;
  331. }
  332. if (xmss_port == 0xe80)
  333. cfg[0] |= 0x10;
  334. cfg[0] |= 0x40; /* always set */
  335. if (!joystick)
  336. cfg[0] |= 0x02;
  337. cfg[1] |= 0x80; /* enable WSS system */
  338. cfg[1] &= ~0x40; /* disable IDE */
  339. snd_printd("hw cfg %x, %x\n", cfg[0], cfg[1]);
  340. }
  341. static int sc6000_init_board(char __iomem *vport,
  342. char __iomem *vmss_port, int dev)
  343. {
  344. char answer[15];
  345. char version[2];
  346. int mss_config = sc6000_irq_to_softcfg(irq[dev]) |
  347. sc6000_dma_to_softcfg(dma[dev]);
  348. int config = mss_config |
  349. sc6000_mpu_irq_to_softcfg(mpu_irq[dev]);
  350. int err;
  351. int old = 0;
  352. err = sc6000_dsp_reset(vport);
  353. if (err < 0) {
  354. snd_printk(KERN_ERR "sc6000_dsp_reset: failed!\n");
  355. return err;
  356. }
  357. memset(answer, 0, sizeof(answer));
  358. err = sc6000_dsp_get_answer(vport, GET_DSP_COPYRIGHT, answer, 15);
  359. if (err <= 0) {
  360. snd_printk(KERN_ERR "sc6000_dsp_copyright: failed!\n");
  361. return -ENODEV;
  362. }
  363. /*
  364. * My SC-6000 card return "SC-6000" in DSPCopyright, so
  365. * if we have something different, we have to be warned.
  366. */
  367. if (strncmp("SC-6000", answer, 7))
  368. snd_printk(KERN_WARNING "Warning: non SC-6000 audio card!\n");
  369. if (sc6000_dsp_get_answer(vport, GET_DSP_VERSION, version, 2) < 2) {
  370. snd_printk(KERN_ERR "sc6000_dsp_version: failed!\n");
  371. return -ENODEV;
  372. }
  373. printk(KERN_INFO PFX "Detected model: %s, DSP version %d.%d\n",
  374. answer, version[0], version[1]);
  375. /* set configuration */
  376. sc6000_write(vport, COMMAND_5C);
  377. if (sc6000_read(vport) < 0)
  378. old = 1;
  379. if (!old) {
  380. int cfg[2];
  381. sc6000_hw_cfg_encode(vport, &cfg[0], port[dev], mpu_port[dev],
  382. mss_port[dev], joystick[dev]);
  383. if (sc6000_hw_cfg_write(vport, cfg) < 0) {
  384. snd_printk(KERN_ERR "sc6000_hw_cfg_write: failed!\n");
  385. return -EIO;
  386. }
  387. }
  388. err = sc6000_setup_board(vport, config);
  389. if (err < 0) {
  390. snd_printk(KERN_ERR "sc6000_setup_board: failed!\n");
  391. return -ENODEV;
  392. }
  393. sc6000_dsp_reset(vport);
  394. if (!old) {
  395. sc6000_write(vport, COMMAND_60);
  396. sc6000_write(vport, 0x02);
  397. sc6000_dsp_reset(vport);
  398. }
  399. err = sc6000_setup_board(vport, config);
  400. if (err < 0) {
  401. snd_printk(KERN_ERR "sc6000_setup_board: failed!\n");
  402. return -ENODEV;
  403. }
  404. err = sc6000_init_mss(vport, config, vmss_port, mss_config);
  405. if (err < 0) {
  406. snd_printk(KERN_ERR "Cannot initialize "
  407. "Microsoft Sound System mode.\n");
  408. return -ENODEV;
  409. }
  410. return 0;
  411. }
  412. static int snd_sc6000_mixer(struct snd_wss *chip)
  413. {
  414. struct snd_card *card = chip->card;
  415. struct snd_ctl_elem_id id1, id2;
  416. int err;
  417. memset(&id1, 0, sizeof(id1));
  418. memset(&id2, 0, sizeof(id2));
  419. id1.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  420. id2.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
  421. /* reassign AUX0 to FM */
  422. strcpy(id1.name, "Aux Playback Switch");
  423. strcpy(id2.name, "FM Playback Switch");
  424. err = snd_ctl_rename_id(card, &id1, &id2);
  425. if (err < 0)
  426. return err;
  427. strcpy(id1.name, "Aux Playback Volume");
  428. strcpy(id2.name, "FM Playback Volume");
  429. err = snd_ctl_rename_id(card, &id1, &id2);
  430. if (err < 0)
  431. return err;
  432. /* reassign AUX1 to CD */
  433. strcpy(id1.name, "Aux Playback Switch"); id1.index = 1;
  434. strcpy(id2.name, "CD Playback Switch");
  435. err = snd_ctl_rename_id(card, &id1, &id2);
  436. if (err < 0)
  437. return err;
  438. strcpy(id1.name, "Aux Playback Volume");
  439. strcpy(id2.name, "CD Playback Volume");
  440. err = snd_ctl_rename_id(card, &id1, &id2);
  441. if (err < 0)
  442. return err;
  443. return 0;
  444. }
  445. static int snd_sc6000_match(struct device *devptr, unsigned int dev)
  446. {
  447. if (!enable[dev])
  448. return 0;
  449. if (port[dev] == SNDRV_AUTO_PORT) {
  450. printk(KERN_ERR PFX "specify IO port\n");
  451. return 0;
  452. }
  453. if (mss_port[dev] == SNDRV_AUTO_PORT) {
  454. printk(KERN_ERR PFX "specify MSS port\n");
  455. return 0;
  456. }
  457. if (port[dev] != 0x220 && port[dev] != 0x240) {
  458. printk(KERN_ERR PFX "Port must be 0x220 or 0x240\n");
  459. return 0;
  460. }
  461. if (mss_port[dev] != 0x530 && mss_port[dev] != 0xe80) {
  462. printk(KERN_ERR PFX "MSS port must be 0x530 or 0xe80\n");
  463. return 0;
  464. }
  465. if (irq[dev] != SNDRV_AUTO_IRQ && !sc6000_irq_to_softcfg(irq[dev])) {
  466. printk(KERN_ERR PFX "invalid IRQ %d\n", irq[dev]);
  467. return 0;
  468. }
  469. if (dma[dev] != SNDRV_AUTO_DMA && !sc6000_dma_to_softcfg(dma[dev])) {
  470. printk(KERN_ERR PFX "invalid DMA %d\n", dma[dev]);
  471. return 0;
  472. }
  473. if (mpu_port[dev] != SNDRV_AUTO_PORT &&
  474. (mpu_port[dev] & ~0x30L) != 0x300) {
  475. printk(KERN_ERR PFX "invalid MPU-401 port %lx\n",
  476. mpu_port[dev]);
  477. return 0;
  478. }
  479. if (mpu_port[dev] != SNDRV_AUTO_PORT &&
  480. mpu_irq[dev] != SNDRV_AUTO_IRQ && mpu_irq[dev] != 0 &&
  481. !sc6000_mpu_irq_to_softcfg(mpu_irq[dev])) {
  482. printk(KERN_ERR PFX "invalid MPU-401 IRQ %d\n", mpu_irq[dev]);
  483. return 0;
  484. }
  485. return 1;
  486. }
  487. static int snd_sc6000_probe(struct device *devptr, unsigned int dev)
  488. {
  489. static int possible_irqs[] = { 5, 7, 9, 10, 11, -1 };
  490. static int possible_dmas[] = { 1, 3, 0, -1 };
  491. int err;
  492. int xirq = irq[dev];
  493. int xdma = dma[dev];
  494. struct snd_card *card;
  495. struct snd_wss *chip;
  496. struct snd_opl3 *opl3;
  497. char __iomem **vport;
  498. char __iomem *vmss_port;
  499. err = snd_card_new(devptr, index[dev], id[dev], THIS_MODULE,
  500. sizeof(vport), &card);
  501. if (err < 0)
  502. return err;
  503. vport = card->private_data;
  504. if (xirq == SNDRV_AUTO_IRQ) {
  505. xirq = snd_legacy_find_free_irq(possible_irqs);
  506. if (xirq < 0) {
  507. snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
  508. err = -EBUSY;
  509. goto err_exit;
  510. }
  511. }
  512. if (xdma == SNDRV_AUTO_DMA) {
  513. xdma = snd_legacy_find_free_dma(possible_dmas);
  514. if (xdma < 0) {
  515. snd_printk(KERN_ERR PFX "unable to find a free DMA\n");
  516. err = -EBUSY;
  517. goto err_exit;
  518. }
  519. }
  520. if (!request_region(port[dev], 0x10, DRV_NAME)) {
  521. snd_printk(KERN_ERR PFX
  522. "I/O port region is already in use.\n");
  523. err = -EBUSY;
  524. goto err_exit;
  525. }
  526. *vport = devm_ioport_map(devptr, port[dev], 0x10);
  527. if (*vport == NULL) {
  528. snd_printk(KERN_ERR PFX
  529. "I/O port cannot be iomaped.\n");
  530. err = -EBUSY;
  531. goto err_unmap1;
  532. }
  533. /* to make it marked as used */
  534. if (!request_region(mss_port[dev], 4, DRV_NAME)) {
  535. snd_printk(KERN_ERR PFX
  536. "SC-6000 port I/O port region is already in use.\n");
  537. err = -EBUSY;
  538. goto err_unmap1;
  539. }
  540. vmss_port = devm_ioport_map(devptr, mss_port[dev], 4);
  541. if (!vmss_port) {
  542. snd_printk(KERN_ERR PFX
  543. "MSS port I/O cannot be iomaped.\n");
  544. err = -EBUSY;
  545. goto err_unmap2;
  546. }
  547. snd_printd("Initializing BASE[0x%lx] IRQ[%d] DMA[%d] MIRQ[%d]\n",
  548. port[dev], xirq, xdma,
  549. mpu_irq[dev] == SNDRV_AUTO_IRQ ? 0 : mpu_irq[dev]);
  550. err = sc6000_init_board(*vport, vmss_port, dev);
  551. if (err < 0)
  552. goto err_unmap2;
  553. err = snd_wss_create(card, mss_port[dev] + 4, -1, xirq, xdma, -1,
  554. WSS_HW_DETECT, 0, &chip);
  555. if (err < 0)
  556. goto err_unmap2;
  557. err = snd_wss_pcm(chip, 0);
  558. if (err < 0) {
  559. snd_printk(KERN_ERR PFX
  560. "error creating new WSS PCM device\n");
  561. goto err_unmap2;
  562. }
  563. err = snd_wss_mixer(chip);
  564. if (err < 0) {
  565. snd_printk(KERN_ERR PFX "error creating new WSS mixer\n");
  566. goto err_unmap2;
  567. }
  568. err = snd_sc6000_mixer(chip);
  569. if (err < 0) {
  570. snd_printk(KERN_ERR PFX "the mixer rewrite failed\n");
  571. goto err_unmap2;
  572. }
  573. if (snd_opl3_create(card,
  574. 0x388, 0x388 + 2,
  575. OPL3_HW_AUTO, 0, &opl3) < 0) {
  576. snd_printk(KERN_ERR PFX "no OPL device at 0x%x-0x%x ?\n",
  577. 0x388, 0x388 + 2);
  578. } else {
  579. err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
  580. if (err < 0)
  581. goto err_unmap2;
  582. }
  583. if (mpu_port[dev] != SNDRV_AUTO_PORT) {
  584. if (mpu_irq[dev] == SNDRV_AUTO_IRQ)
  585. mpu_irq[dev] = -1;
  586. if (snd_mpu401_uart_new(card, 0,
  587. MPU401_HW_MPU401,
  588. mpu_port[dev], 0,
  589. mpu_irq[dev], NULL) < 0)
  590. snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n",
  591. mpu_port[dev]);
  592. }
  593. strcpy(card->driver, DRV_NAME);
  594. strcpy(card->shortname, "SC-6000");
  595. sprintf(card->longname, "Gallant SC-6000 at 0x%lx, irq %d, dma %d",
  596. mss_port[dev], xirq, xdma);
  597. err = snd_card_register(card);
  598. if (err < 0)
  599. goto err_unmap2;
  600. dev_set_drvdata(devptr, card);
  601. return 0;
  602. err_unmap2:
  603. sc6000_setup_board(*vport, 0);
  604. release_region(mss_port[dev], 4);
  605. err_unmap1:
  606. release_region(port[dev], 0x10);
  607. err_exit:
  608. snd_card_free(card);
  609. return err;
  610. }
  611. static int snd_sc6000_remove(struct device *devptr, unsigned int dev)
  612. {
  613. struct snd_card *card = dev_get_drvdata(devptr);
  614. char __iomem **vport = card->private_data;
  615. if (sc6000_setup_board(*vport, 0) < 0)
  616. snd_printk(KERN_WARNING "sc6000_setup_board failed on exit!\n");
  617. release_region(port[dev], 0x10);
  618. release_region(mss_port[dev], 4);
  619. snd_card_free(card);
  620. return 0;
  621. }
  622. static struct isa_driver snd_sc6000_driver = {
  623. .match = snd_sc6000_match,
  624. .probe = snd_sc6000_probe,
  625. .remove = snd_sc6000_remove,
  626. /* FIXME: suspend/resume */
  627. .driver = {
  628. .name = DRV_NAME,
  629. },
  630. };
  631. module_isa_driver(snd_sc6000_driver, SNDRV_CARDS);