sscape.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336
  1. /*
  2. * Low-level ALSA driver for the ENSONIQ SoundScape
  3. * Copyright (c) by Chris Rankin
  4. *
  5. * This driver was written in part using information obtained from
  6. * the OSS/Free SoundScape driver, written by Hannu Savolainen.
  7. *
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. */
  23. #include <linux/init.h>
  24. #include <linux/err.h>
  25. #include <linux/isa.h>
  26. #include <linux/delay.h>
  27. #include <linux/firmware.h>
  28. #include <linux/pnp.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/moduleparam.h>
  31. #include <asm/dma.h>
  32. #include <sound/core.h>
  33. #include <sound/wss.h>
  34. #include <sound/mpu401.h>
  35. #include <sound/initval.h>
  36. MODULE_AUTHOR("Chris Rankin");
  37. MODULE_DESCRIPTION("ENSONIQ SoundScape driver");
  38. MODULE_LICENSE("GPL");
  39. MODULE_FIRMWARE("sndscape.co0");
  40. MODULE_FIRMWARE("sndscape.co1");
  41. MODULE_FIRMWARE("sndscape.co2");
  42. MODULE_FIRMWARE("sndscape.co3");
  43. MODULE_FIRMWARE("sndscape.co4");
  44. MODULE_FIRMWARE("scope.cod");
  45. static int index[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IDX;
  46. static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR;
  47. static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
  48. static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
  49. static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
  50. static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
  51. static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
  52. static int dma2[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
  53. module_param_array(index, int, NULL, 0444);
  54. MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
  55. module_param_array(id, charp, NULL, 0444);
  56. MODULE_PARM_DESC(id, "Description for SoundScape card");
  57. module_param_array(port, long, NULL, 0444);
  58. MODULE_PARM_DESC(port, "Port # for SoundScape driver.");
  59. module_param_array(wss_port, long, NULL, 0444);
  60. MODULE_PARM_DESC(wss_port, "WSS Port # for SoundScape driver.");
  61. module_param_array(irq, int, NULL, 0444);
  62. MODULE_PARM_DESC(irq, "IRQ # for SoundScape driver.");
  63. module_param_array(mpu_irq, int, NULL, 0444);
  64. MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver.");
  65. module_param_array(dma, int, NULL, 0444);
  66. MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
  67. module_param_array(dma2, int, NULL, 0444);
  68. MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver.");
  69. #ifdef CONFIG_PNP
  70. static int isa_registered;
  71. static int pnp_registered;
  72. static struct pnp_card_device_id sscape_pnpids[] = {
  73. { .id = "ENS3081", .devs = { { "ENS0000" } } }, /* Soundscape PnP */
  74. { .id = "ENS4081", .devs = { { "ENS1011" } } }, /* VIVO90 */
  75. { .id = "" } /* end */
  76. };
  77. MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
  78. #endif
  79. #define HOST_CTRL_IO(i) ((i) + 2)
  80. #define HOST_DATA_IO(i) ((i) + 3)
  81. #define ODIE_ADDR_IO(i) ((i) + 4)
  82. #define ODIE_DATA_IO(i) ((i) + 5)
  83. #define CODEC_IO(i) ((i) + 8)
  84. #define IC_ODIE 1
  85. #define IC_OPUS 2
  86. #define RX_READY 0x01
  87. #define TX_READY 0x02
  88. #define CMD_ACK 0x80
  89. #define CMD_SET_MIDI_VOL 0x84
  90. #define CMD_GET_MIDI_VOL 0x85
  91. #define CMD_XXX_MIDI_VOL 0x86
  92. #define CMD_SET_EXTMIDI 0x8a
  93. #define CMD_GET_EXTMIDI 0x8b
  94. #define CMD_SET_MT32 0x8c
  95. #define CMD_GET_MT32 0x8d
  96. enum GA_REG {
  97. GA_INTSTAT_REG = 0,
  98. GA_INTENA_REG,
  99. GA_DMAA_REG,
  100. GA_DMAB_REG,
  101. GA_INTCFG_REG,
  102. GA_DMACFG_REG,
  103. GA_CDCFG_REG,
  104. GA_SMCFGA_REG,
  105. GA_SMCFGB_REG,
  106. GA_HMCTL_REG
  107. };
  108. #define DMA_8BIT 0x80
  109. enum card_type {
  110. MEDIA_FX, /* Sequoia S-1000 */
  111. SSCAPE, /* Sequoia S-2000 */
  112. SSCAPE_PNP,
  113. SSCAPE_VIVO,
  114. };
  115. struct soundscape {
  116. spinlock_t lock;
  117. unsigned io_base;
  118. int ic_type;
  119. enum card_type type;
  120. struct resource *io_res;
  121. struct resource *wss_res;
  122. struct snd_wss *chip;
  123. struct snd_mpu401 *mpu;
  124. unsigned char midi_vol;
  125. };
  126. #define INVALID_IRQ ((unsigned)-1)
  127. static inline struct soundscape *get_card_soundscape(struct snd_card *c)
  128. {
  129. return (struct soundscape *) (c->private_data);
  130. }
  131. /*
  132. * Allocates some kernel memory that we can use for DMA.
  133. * I think this means that the memory has to map to
  134. * contiguous pages of physical memory.
  135. */
  136. static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf, unsigned long size)
  137. {
  138. if (buf) {
  139. if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(),
  140. size, buf) < 0) {
  141. snd_printk(KERN_ERR "sscape: Failed to allocate "
  142. "%lu bytes for DMA\n",
  143. size);
  144. return NULL;
  145. }
  146. }
  147. return buf;
  148. }
  149. /*
  150. * Release the DMA-able kernel memory ...
  151. */
  152. static void free_dmabuf(struct snd_dma_buffer *buf)
  153. {
  154. if (buf && buf->area)
  155. snd_dma_free_pages(buf);
  156. }
  157. /*
  158. * This function writes to the SoundScape's control registers,
  159. * but doesn't do any locking. It's up to the caller to do that.
  160. * This is why this function is "unsafe" ...
  161. */
  162. static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsigned char val)
  163. {
  164. outb(reg, ODIE_ADDR_IO(io_base));
  165. outb(val, ODIE_DATA_IO(io_base));
  166. }
  167. /*
  168. * Write to the SoundScape's control registers, and do the
  169. * necessary locking ...
  170. */
  171. static void sscape_write(struct soundscape *s, enum GA_REG reg, unsigned char val)
  172. {
  173. unsigned long flags;
  174. spin_lock_irqsave(&s->lock, flags);
  175. sscape_write_unsafe(s->io_base, reg, val);
  176. spin_unlock_irqrestore(&s->lock, flags);
  177. }
  178. /*
  179. * Read from the SoundScape's control registers, but leave any
  180. * locking to the caller. This is why the function is "unsafe" ...
  181. */
  182. static inline unsigned char sscape_read_unsafe(unsigned io_base, enum GA_REG reg)
  183. {
  184. outb(reg, ODIE_ADDR_IO(io_base));
  185. return inb(ODIE_DATA_IO(io_base));
  186. }
  187. /*
  188. * Puts the SoundScape into "host" mode, as compared to "MIDI" mode
  189. */
  190. static inline void set_host_mode_unsafe(unsigned io_base)
  191. {
  192. outb(0x0, HOST_CTRL_IO(io_base));
  193. }
  194. /*
  195. * Puts the SoundScape into "MIDI" mode, as compared to "host" mode
  196. */
  197. static inline void set_midi_mode_unsafe(unsigned io_base)
  198. {
  199. outb(0x3, HOST_CTRL_IO(io_base));
  200. }
  201. /*
  202. * Read the SoundScape's host-mode control register, but leave
  203. * any locking issues to the caller ...
  204. */
  205. static inline int host_read_unsafe(unsigned io_base)
  206. {
  207. int data = -1;
  208. if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0) {
  209. data = inb(HOST_DATA_IO(io_base));
  210. }
  211. return data;
  212. }
  213. /*
  214. * Read the SoundScape's host-mode control register, performing
  215. * a limited amount of busy-waiting if the register isn't ready.
  216. * Also leaves all locking-issues to the caller ...
  217. */
  218. static int host_read_ctrl_unsafe(unsigned io_base, unsigned timeout)
  219. {
  220. int data;
  221. while (((data = host_read_unsafe(io_base)) < 0) && (timeout != 0)) {
  222. udelay(100);
  223. --timeout;
  224. } /* while */
  225. return data;
  226. }
  227. /*
  228. * Write to the SoundScape's host-mode control registers, but
  229. * leave any locking issues to the caller ...
  230. */
  231. static inline int host_write_unsafe(unsigned io_base, unsigned char data)
  232. {
  233. if ((inb(HOST_CTRL_IO(io_base)) & TX_READY) != 0) {
  234. outb(data, HOST_DATA_IO(io_base));
  235. return 1;
  236. }
  237. return 0;
  238. }
  239. /*
  240. * Write to the SoundScape's host-mode control registers, performing
  241. * a limited amount of busy-waiting if the register isn't ready.
  242. * Also leaves all locking-issues to the caller ...
  243. */
  244. static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
  245. unsigned timeout)
  246. {
  247. int err;
  248. while (!(err = host_write_unsafe(io_base, data)) && (timeout != 0)) {
  249. udelay(100);
  250. --timeout;
  251. } /* while */
  252. return err;
  253. }
  254. /*
  255. * Check that the MIDI subsystem is operational. If it isn't,
  256. * then we will hang the computer if we try to use it ...
  257. *
  258. * NOTE: This check is based upon observation, not documentation.
  259. */
  260. static inline int verify_mpu401(const struct snd_mpu401 * mpu)
  261. {
  262. return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
  263. }
  264. /*
  265. * This is apparently the standard way to initailise an MPU-401
  266. */
  267. static inline void initialise_mpu401(const struct snd_mpu401 * mpu)
  268. {
  269. outb(0, MPU401D(mpu));
  270. }
  271. /*
  272. * Tell the SoundScape to activate the AD1845 chip (I think).
  273. * The AD1845 detection fails if we *don't* do this, so I
  274. * think that this is a good idea ...
  275. */
  276. static inline void activate_ad1845_unsafe(unsigned io_base)
  277. {
  278. sscape_write_unsafe(io_base, GA_HMCTL_REG, (sscape_read_unsafe(io_base, GA_HMCTL_REG) & 0xcf) | 0x10);
  279. sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
  280. }
  281. /*
  282. * Do the necessary ALSA-level cleanup to deallocate our driver ...
  283. */
  284. static void soundscape_free(struct snd_card *c)
  285. {
  286. struct soundscape *sscape = get_card_soundscape(c);
  287. release_and_free_resource(sscape->io_res);
  288. release_and_free_resource(sscape->wss_res);
  289. free_dma(sscape->chip->dma1);
  290. }
  291. /*
  292. * Tell the SoundScape to begin a DMA tranfer using the given channel.
  293. * All locking issues are left to the caller.
  294. */
  295. static inline void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
  296. {
  297. sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) | 0x01);
  298. sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) & 0xfe);
  299. }
  300. /*
  301. * Wait for a DMA transfer to complete. This is a "limited busy-wait",
  302. * and all locking issues are left to the caller.
  303. */
  304. static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned timeout)
  305. {
  306. while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
  307. udelay(100);
  308. --timeout;
  309. } /* while */
  310. return (sscape_read_unsafe(io_base, reg) & 0x01);
  311. }
  312. /*
  313. * Wait for the On-Board Processor to return its start-up
  314. * acknowledgement sequence. This wait is too long for
  315. * us to perform "busy-waiting", and so we must sleep.
  316. * This in turn means that we must not be holding any
  317. * spinlocks when we call this function.
  318. */
  319. static int obp_startup_ack(struct soundscape *s, unsigned timeout)
  320. {
  321. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  322. do {
  323. unsigned long flags;
  324. int x;
  325. spin_lock_irqsave(&s->lock, flags);
  326. x = host_read_unsafe(s->io_base);
  327. spin_unlock_irqrestore(&s->lock, flags);
  328. if (x == 0xfe || x == 0xff)
  329. return 1;
  330. msleep(10);
  331. } while (time_before(jiffies, end_time));
  332. return 0;
  333. }
  334. /*
  335. * Wait for the host to return its start-up acknowledgement
  336. * sequence. This wait is too long for us to perform
  337. * "busy-waiting", and so we must sleep. This in turn means
  338. * that we must not be holding any spinlocks when we call
  339. * this function.
  340. */
  341. static int host_startup_ack(struct soundscape *s, unsigned timeout)
  342. {
  343. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  344. do {
  345. unsigned long flags;
  346. int x;
  347. spin_lock_irqsave(&s->lock, flags);
  348. x = host_read_unsafe(s->io_base);
  349. spin_unlock_irqrestore(&s->lock, flags);
  350. if (x == 0xfe)
  351. return 1;
  352. msleep(10);
  353. } while (time_before(jiffies, end_time));
  354. return 0;
  355. }
  356. /*
  357. * Upload a byte-stream into the SoundScape using DMA channel A.
  358. */
  359. static int upload_dma_data(struct soundscape *s,
  360. const unsigned char *data,
  361. size_t size)
  362. {
  363. unsigned long flags;
  364. struct snd_dma_buffer dma;
  365. int ret;
  366. if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024)))
  367. return -ENOMEM;
  368. spin_lock_irqsave(&s->lock, flags);
  369. /*
  370. * Reset the board ...
  371. */
  372. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f);
  373. /*
  374. * Enable the DMA channels and configure them ...
  375. */
  376. sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT);
  377. sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
  378. /*
  379. * Take the board out of reset ...
  380. */
  381. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80);
  382. /*
  383. * Upload the firmware to the SoundScape
  384. * board through the DMA channel ...
  385. */
  386. while (size != 0) {
  387. unsigned long len;
  388. len = min(size, dma.bytes);
  389. memcpy(dma.area, data, len);
  390. data += len;
  391. size -= len;
  392. snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
  393. sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
  394. if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
  395. /*
  396. * Don't forget to release this spinlock we're holding ...
  397. */
  398. spin_unlock_irqrestore(&s->lock, flags);
  399. snd_printk(KERN_ERR
  400. "sscape: DMA upload has timed out\n");
  401. ret = -EAGAIN;
  402. goto _release_dma;
  403. }
  404. } /* while */
  405. set_host_mode_unsafe(s->io_base);
  406. outb(0x0, s->io_base);
  407. /*
  408. * Boot the board ... (I think)
  409. */
  410. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40);
  411. spin_unlock_irqrestore(&s->lock, flags);
  412. /*
  413. * If all has gone well, then the board should acknowledge
  414. * the new upload and tell us that it has rebooted OK. We
  415. * give it 5 seconds (max) ...
  416. */
  417. ret = 0;
  418. if (!obp_startup_ack(s, 5000)) {
  419. snd_printk(KERN_ERR "sscape: No response "
  420. "from on-board processor after upload\n");
  421. ret = -EAGAIN;
  422. } else if (!host_startup_ack(s, 5000)) {
  423. snd_printk(KERN_ERR
  424. "sscape: SoundScape failed to initialise\n");
  425. ret = -EAGAIN;
  426. }
  427. _release_dma:
  428. /*
  429. * NOTE!!! We are NOT holding any spinlocks at this point !!!
  430. */
  431. sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70));
  432. free_dmabuf(&dma);
  433. return ret;
  434. }
  435. /*
  436. * Upload the bootblock(?) into the SoundScape. The only
  437. * purpose of this block of code seems to be to tell
  438. * us which version of the microcode we should be using.
  439. */
  440. static int sscape_upload_bootblock(struct snd_card *card)
  441. {
  442. struct soundscape *sscape = get_card_soundscape(card);
  443. unsigned long flags;
  444. const struct firmware *init_fw = NULL;
  445. int data = 0;
  446. int ret;
  447. ret = request_firmware(&init_fw, "scope.cod", card->dev);
  448. if (ret < 0) {
  449. snd_printk(KERN_ERR "sscape: Error loading scope.cod");
  450. return ret;
  451. }
  452. ret = upload_dma_data(sscape, init_fw->data, init_fw->size);
  453. release_firmware(init_fw);
  454. spin_lock_irqsave(&sscape->lock, flags);
  455. if (ret == 0)
  456. data = host_read_ctrl_unsafe(sscape->io_base, 100);
  457. if (data & 0x10)
  458. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f);
  459. spin_unlock_irqrestore(&sscape->lock, flags);
  460. data &= 0xf;
  461. if (ret == 0 && data > 7) {
  462. snd_printk(KERN_ERR
  463. "sscape: timeout reading firmware version\n");
  464. ret = -EAGAIN;
  465. }
  466. return (ret == 0) ? data : ret;
  467. }
  468. /*
  469. * Upload the microcode into the SoundScape.
  470. */
  471. static int sscape_upload_microcode(struct snd_card *card, int version)
  472. {
  473. struct soundscape *sscape = get_card_soundscape(card);
  474. const struct firmware *init_fw = NULL;
  475. char name[14];
  476. int err;
  477. snprintf(name, sizeof(name), "sndscape.co%d", version);
  478. err = request_firmware(&init_fw, name, card->dev);
  479. if (err < 0) {
  480. snd_printk(KERN_ERR "sscape: Error loading sndscape.co%d",
  481. version);
  482. return err;
  483. }
  484. err = upload_dma_data(sscape, init_fw->data, init_fw->size);
  485. if (err == 0)
  486. snd_printk(KERN_INFO "sscape: MIDI firmware loaded %d KBs\n",
  487. init_fw->size >> 10);
  488. release_firmware(init_fw);
  489. return err;
  490. }
  491. /*
  492. * Mixer control for the SoundScape's MIDI device.
  493. */
  494. static int sscape_midi_info(struct snd_kcontrol *ctl,
  495. struct snd_ctl_elem_info *uinfo)
  496. {
  497. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  498. uinfo->count = 1;
  499. uinfo->value.integer.min = 0;
  500. uinfo->value.integer.max = 127;
  501. return 0;
  502. }
  503. static int sscape_midi_get(struct snd_kcontrol *kctl,
  504. struct snd_ctl_elem_value *uctl)
  505. {
  506. struct snd_wss *chip = snd_kcontrol_chip(kctl);
  507. struct snd_card *card = chip->card;
  508. register struct soundscape *s = get_card_soundscape(card);
  509. unsigned long flags;
  510. spin_lock_irqsave(&s->lock, flags);
  511. uctl->value.integer.value[0] = s->midi_vol;
  512. spin_unlock_irqrestore(&s->lock, flags);
  513. return 0;
  514. }
  515. static int sscape_midi_put(struct snd_kcontrol *kctl,
  516. struct snd_ctl_elem_value *uctl)
  517. {
  518. struct snd_wss *chip = snd_kcontrol_chip(kctl);
  519. struct snd_card *card = chip->card;
  520. register struct soundscape *s = get_card_soundscape(card);
  521. unsigned long flags;
  522. int change;
  523. spin_lock_irqsave(&s->lock, flags);
  524. /*
  525. * We need to put the board into HOST mode before we
  526. * can send any volume-changing HOST commands ...
  527. */
  528. set_host_mode_unsafe(s->io_base);
  529. /*
  530. * To successfully change the MIDI volume setting, you seem to
  531. * have to write a volume command, write the new volume value,
  532. * and then perform another volume-related command. Perhaps the
  533. * first command is an "open" and the second command is a "close"?
  534. */
  535. if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) {
  536. change = 0;
  537. goto __skip_change;
  538. }
  539. change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
  540. && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100)
  541. && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100));
  542. s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127;
  543. __skip_change:
  544. /*
  545. * Take the board out of HOST mode and back into MIDI mode ...
  546. */
  547. set_midi_mode_unsafe(s->io_base);
  548. spin_unlock_irqrestore(&s->lock, flags);
  549. return change;
  550. }
  551. static struct snd_kcontrol_new midi_mixer_ctl = {
  552. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  553. .name = "MIDI",
  554. .info = sscape_midi_info,
  555. .get = sscape_midi_get,
  556. .put = sscape_midi_put
  557. };
  558. /*
  559. * The SoundScape can use two IRQs from a possible set of four.
  560. * These IRQs are encoded as bit patterns so that they can be
  561. * written to the control registers.
  562. */
  563. static unsigned __devinit get_irq_config(int sscape_type, int irq)
  564. {
  565. static const int valid_irq[] = { 9, 5, 7, 10 };
  566. static const int old_irq[] = { 9, 7, 5, 15 };
  567. unsigned cfg;
  568. if (sscape_type == MEDIA_FX) {
  569. for (cfg = 0; cfg < ARRAY_SIZE(old_irq); ++cfg)
  570. if (irq == old_irq[cfg])
  571. return cfg;
  572. } else {
  573. for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg)
  574. if (irq == valid_irq[cfg])
  575. return cfg;
  576. }
  577. return INVALID_IRQ;
  578. }
  579. /*
  580. * Perform certain arcane port-checks to see whether there
  581. * is a SoundScape board lurking behind the given ports.
  582. */
  583. static int __devinit detect_sscape(struct soundscape *s, long wss_io)
  584. {
  585. unsigned long flags;
  586. unsigned d;
  587. int retval = 0;
  588. spin_lock_irqsave(&s->lock, flags);
  589. /*
  590. * The following code is lifted from the original OSS driver,
  591. * and as I don't have a datasheet I cannot really comment
  592. * on what it is doing...
  593. */
  594. if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0)
  595. goto _done;
  596. d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0;
  597. if ((d & 0x80) != 0)
  598. goto _done;
  599. if (d == 0)
  600. s->ic_type = IC_ODIE;
  601. else if ((d & 0x60) != 0)
  602. s->ic_type = IC_OPUS;
  603. else
  604. goto _done;
  605. outb(0xfa, ODIE_ADDR_IO(s->io_base));
  606. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a)
  607. goto _done;
  608. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  609. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e)
  610. goto _done;
  611. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  612. d = inb(ODIE_DATA_IO(s->io_base));
  613. if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
  614. goto _done;
  615. if (s->ic_type == IC_OPUS)
  616. activate_ad1845_unsafe(s->io_base);
  617. if (s->type == SSCAPE_VIVO)
  618. wss_io += 4;
  619. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  620. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
  621. /* wait for WSS codec */
  622. for (d = 0; d < 500; d++) {
  623. if ((inb(wss_io) & 0x80) == 0)
  624. break;
  625. spin_unlock_irqrestore(&s->lock, flags);
  626. msleep(1);
  627. spin_lock_irqsave(&s->lock, flags);
  628. }
  629. if ((inb(wss_io) & 0x80) != 0)
  630. goto _done;
  631. if (inb(wss_io + 2) == 0xff)
  632. goto _done;
  633. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  634. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d);
  635. if ((inb(wss_io) & 0x80) != 0)
  636. s->type = MEDIA_FX;
  637. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  638. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
  639. /* wait for WSS codec */
  640. for (d = 0; d < 500; d++) {
  641. if ((inb(wss_io) & 0x80) == 0)
  642. break;
  643. spin_unlock_irqrestore(&s->lock, flags);
  644. msleep(1);
  645. spin_lock_irqsave(&s->lock, flags);
  646. }
  647. /*
  648. * SoundScape successfully detected!
  649. */
  650. retval = 1;
  651. _done:
  652. spin_unlock_irqrestore(&s->lock, flags);
  653. return retval;
  654. }
  655. /*
  656. * ALSA callback function, called when attempting to open the MIDI device.
  657. * Check that the MIDI firmware has been loaded, because we don't want
  658. * to crash the machine. Also check that someone isn't using the hardware
  659. * IOCTL device.
  660. */
  661. static int mpu401_open(struct snd_mpu401 * mpu)
  662. {
  663. if (!verify_mpu401(mpu)) {
  664. snd_printk(KERN_ERR "sscape: MIDI disabled, "
  665. "please load firmware\n");
  666. return -ENODEV;
  667. }
  668. return 0;
  669. }
  670. /*
  671. * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
  672. */
  673. static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq)
  674. {
  675. struct soundscape *sscape = get_card_soundscape(card);
  676. struct snd_rawmidi *rawmidi;
  677. int err;
  678. if ((err = snd_mpu401_uart_new(card, devnum,
  679. MPU401_HW_MPU401,
  680. port, MPU401_INFO_INTEGRATED,
  681. irq, IRQF_DISABLED,
  682. &rawmidi)) == 0) {
  683. struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data;
  684. mpu->open_input = mpu401_open;
  685. mpu->open_output = mpu401_open;
  686. mpu->private_data = sscape;
  687. sscape->mpu = mpu;
  688. initialise_mpu401(mpu);
  689. }
  690. return err;
  691. }
  692. /*
  693. * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
  694. * is very much like a CS4231, with a few extra bits. We will
  695. * try to support at least some of the extra bits by overriding
  696. * some of the CS4231 callback.
  697. */
  698. static int __devinit create_ad1845(struct snd_card *card, unsigned port,
  699. int irq, int dma1, int dma2)
  700. {
  701. register struct soundscape *sscape = get_card_soundscape(card);
  702. struct snd_wss *chip;
  703. int err;
  704. if (sscape->type == SSCAPE_VIVO)
  705. port += 4;
  706. err = snd_wss_create(card, port, -1, irq, dma1, dma2,
  707. WSS_HW_DETECT, WSS_HWSHARE_DMA1, &chip);
  708. if (!err) {
  709. unsigned long flags;
  710. struct snd_pcm *pcm;
  711. /*
  712. * It turns out that the PLAYBACK_ENABLE bit is set
  713. * by the lowlevel driver ...
  714. *
  715. #define AD1845_IFACE_CONFIG \
  716. (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE)
  717. snd_wss_mce_up(chip);
  718. spin_lock_irqsave(&chip->reg_lock, flags);
  719. snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG);
  720. spin_unlock_irqrestore(&chip->reg_lock, flags);
  721. snd_wss_mce_down(chip);
  722. */
  723. if (sscape->type != SSCAPE_VIVO) {
  724. /*
  725. * The input clock frequency on the SoundScape must
  726. * be 14.31818 MHz, because we must set this register
  727. * to get the playback to sound correct ...
  728. */
  729. snd_wss_mce_up(chip);
  730. spin_lock_irqsave(&chip->reg_lock, flags);
  731. snd_wss_out(chip, AD1845_CLOCK, 0x20);
  732. spin_unlock_irqrestore(&chip->reg_lock, flags);
  733. snd_wss_mce_down(chip);
  734. }
  735. err = snd_wss_pcm(chip, 0, &pcm);
  736. if (err < 0) {
  737. snd_printk(KERN_ERR "sscape: No PCM device "
  738. "for AD1845 chip\n");
  739. goto _error;
  740. }
  741. err = snd_wss_mixer(chip);
  742. if (err < 0) {
  743. snd_printk(KERN_ERR "sscape: No mixer device "
  744. "for AD1845 chip\n");
  745. goto _error;
  746. }
  747. if (chip->hardware != WSS_HW_AD1848) {
  748. err = snd_wss_timer(chip, 0, NULL);
  749. if (err < 0) {
  750. snd_printk(KERN_ERR "sscape: No timer device "
  751. "for AD1845 chip\n");
  752. goto _error;
  753. }
  754. }
  755. if (sscape->type != SSCAPE_VIVO) {
  756. err = snd_ctl_add(card,
  757. snd_ctl_new1(&midi_mixer_ctl, chip));
  758. if (err < 0) {
  759. snd_printk(KERN_ERR "sscape: Could not create "
  760. "MIDI mixer control\n");
  761. goto _error;
  762. }
  763. }
  764. sscape->chip = chip;
  765. }
  766. _error:
  767. return err;
  768. }
  769. /*
  770. * Create an ALSA soundcard entry for the SoundScape, using
  771. * the given list of port, IRQ and DMA resources.
  772. */
  773. static int __devinit create_sscape(int dev, struct snd_card *card)
  774. {
  775. struct soundscape *sscape = get_card_soundscape(card);
  776. unsigned dma_cfg;
  777. unsigned irq_cfg;
  778. unsigned mpu_irq_cfg;
  779. struct resource *io_res;
  780. struct resource *wss_res;
  781. unsigned long flags;
  782. int err;
  783. const char *name;
  784. /*
  785. * Grab IO ports that we will need to probe so that we
  786. * can detect and control this hardware ...
  787. */
  788. io_res = request_region(port[dev], 8, "SoundScape");
  789. if (!io_res) {
  790. snd_printk(KERN_ERR
  791. "sscape: can't grab port 0x%lx\n", port[dev]);
  792. return -EBUSY;
  793. }
  794. wss_res = NULL;
  795. if (sscape->type == SSCAPE_VIVO) {
  796. wss_res = request_region(wss_port[dev], 4, "SoundScape");
  797. if (!wss_res) {
  798. snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n",
  799. wss_port[dev]);
  800. err = -EBUSY;
  801. goto _release_region;
  802. }
  803. }
  804. /*
  805. * Grab one DMA channel ...
  806. */
  807. err = request_dma(dma[dev], "SoundScape");
  808. if (err < 0) {
  809. snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]);
  810. goto _release_region;
  811. }
  812. spin_lock_init(&sscape->lock);
  813. sscape->io_res = io_res;
  814. sscape->wss_res = wss_res;
  815. sscape->io_base = port[dev];
  816. if (!detect_sscape(sscape, wss_port[dev])) {
  817. printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
  818. sscape->io_base);
  819. err = -ENODEV;
  820. goto _release_dma;
  821. }
  822. switch (sscape->type) {
  823. case MEDIA_FX:
  824. name = "MediaFX/SoundFX";
  825. break;
  826. case SSCAPE:
  827. name = "Soundscape";
  828. break;
  829. case SSCAPE_PNP:
  830. name = "Soundscape PnP";
  831. break;
  832. case SSCAPE_VIVO:
  833. name = "Soundscape VIVO";
  834. break;
  835. default:
  836. name = "unknown Soundscape";
  837. break;
  838. }
  839. printk(KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
  840. name, sscape->io_base, irq[dev], dma[dev]);
  841. /*
  842. * Check that the user didn't pass us garbage data ...
  843. */
  844. irq_cfg = get_irq_config(sscape->type, irq[dev]);
  845. if (irq_cfg == INVALID_IRQ) {
  846. snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
  847. return -ENXIO;
  848. }
  849. mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]);
  850. if (mpu_irq_cfg == INVALID_IRQ) {
  851. snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
  852. return -ENXIO;
  853. }
  854. /*
  855. * Tell the on-board devices where their resources are (I think -
  856. * I can't be sure without a datasheet ... So many magic values!)
  857. */
  858. spin_lock_irqsave(&sscape->lock, flags);
  859. sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */
  860. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
  861. sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
  862. /*
  863. * Enable and configure the DMA channels ...
  864. */
  865. sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
  866. dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70);
  867. sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
  868. sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
  869. mpu_irq_cfg |= mpu_irq_cfg << 2;
  870. sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg);
  871. sscape_write_unsafe(sscape->io_base,
  872. GA_CDCFG_REG, 0x09 | DMA_8BIT
  873. | (dma[dev] << 4) | (irq_cfg << 1));
  874. spin_unlock_irqrestore(&sscape->lock, flags);
  875. /*
  876. * We have now enabled the codec chip, and so we should
  877. * detect the AD1845 device ...
  878. */
  879. err = create_ad1845(card, wss_port[dev], irq[dev],
  880. dma[dev], dma2[dev]);
  881. if (err < 0) {
  882. snd_printk(KERN_ERR
  883. "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
  884. wss_port[dev], irq[dev]);
  885. goto _release_dma;
  886. }
  887. strcpy(card->driver, "SoundScape");
  888. strcpy(card->shortname, name);
  889. snprintf(card->longname, sizeof(card->longname),
  890. "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
  891. name, sscape->chip->port, sscape->chip->irq,
  892. sscape->chip->dma1, sscape->chip->dma2);
  893. #define MIDI_DEVNUM 0
  894. if (sscape->type != SSCAPE_VIVO) {
  895. err = sscape_upload_bootblock(card);
  896. if (err >= 0)
  897. err = sscape_upload_microcode(card, err);
  898. if (err == 0) {
  899. err = create_mpu401(card, MIDI_DEVNUM, port[dev],
  900. mpu_irq[dev]);
  901. if (err < 0) {
  902. snd_printk(KERN_ERR "sscape: Failed to create "
  903. "MPU-401 device at 0x%lx\n",
  904. port[dev]);
  905. goto _release_dma;
  906. }
  907. /*
  908. * Enable the master IRQ ...
  909. */
  910. sscape_write(sscape, GA_INTENA_REG, 0x80);
  911. /*
  912. * Initialize mixer
  913. */
  914. spin_lock_irqsave(&sscape->lock, flags);
  915. sscape->midi_vol = 0;
  916. host_write_ctrl_unsafe(sscape->io_base,
  917. CMD_SET_MIDI_VOL, 100);
  918. host_write_ctrl_unsafe(sscape->io_base,
  919. sscape->midi_vol, 100);
  920. host_write_ctrl_unsafe(sscape->io_base,
  921. CMD_XXX_MIDI_VOL, 100);
  922. host_write_ctrl_unsafe(sscape->io_base,
  923. sscape->midi_vol, 100);
  924. host_write_ctrl_unsafe(sscape->io_base,
  925. CMD_SET_EXTMIDI, 100);
  926. host_write_ctrl_unsafe(sscape->io_base,
  927. 0, 100);
  928. host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
  929. set_midi_mode_unsafe(sscape->io_base);
  930. spin_unlock_irqrestore(&sscape->lock, flags);
  931. }
  932. }
  933. /*
  934. * Now that we have successfully created this sound card,
  935. * it is safe to store the pointer.
  936. * NOTE: we only register the sound card's "destructor"
  937. * function now that our "constructor" has completed.
  938. */
  939. card->private_free = soundscape_free;
  940. return 0;
  941. _release_dma:
  942. free_dma(dma[dev]);
  943. _release_region:
  944. release_and_free_resource(wss_res);
  945. release_and_free_resource(io_res);
  946. return err;
  947. }
  948. static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
  949. {
  950. /*
  951. * Make sure we were given ALL of the other parameters.
  952. */
  953. if (port[i] == SNDRV_AUTO_PORT)
  954. return 0;
  955. if (irq[i] == SNDRV_AUTO_IRQ ||
  956. mpu_irq[i] == SNDRV_AUTO_IRQ ||
  957. dma[i] == SNDRV_AUTO_DMA) {
  958. printk(KERN_INFO
  959. "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n");
  960. return 0;
  961. }
  962. return 1;
  963. }
  964. static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
  965. {
  966. struct snd_card *card;
  967. struct soundscape *sscape;
  968. int ret;
  969. ret = snd_card_create(index[dev], id[dev], THIS_MODULE,
  970. sizeof(struct soundscape), &card);
  971. if (ret < 0)
  972. return ret;
  973. sscape = get_card_soundscape(card);
  974. sscape->type = SSCAPE;
  975. dma[dev] &= 0x03;
  976. snd_card_set_dev(card, pdev);
  977. ret = create_sscape(dev, card);
  978. if (ret < 0)
  979. goto _release_card;
  980. if ((ret = snd_card_register(card)) < 0) {
  981. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  982. goto _release_card;
  983. }
  984. dev_set_drvdata(pdev, card);
  985. return 0;
  986. _release_card:
  987. snd_card_free(card);
  988. return ret;
  989. }
  990. static int __devexit snd_sscape_remove(struct device *devptr, unsigned int dev)
  991. {
  992. snd_card_free(dev_get_drvdata(devptr));
  993. dev_set_drvdata(devptr, NULL);
  994. return 0;
  995. }
  996. #define DEV_NAME "sscape"
  997. static struct isa_driver snd_sscape_driver = {
  998. .match = snd_sscape_match,
  999. .probe = snd_sscape_probe,
  1000. .remove = __devexit_p(snd_sscape_remove),
  1001. /* FIXME: suspend/resume */
  1002. .driver = {
  1003. .name = DEV_NAME
  1004. },
  1005. };
  1006. #ifdef CONFIG_PNP
  1007. static inline int __devinit get_next_autoindex(int i)
  1008. {
  1009. while (i < SNDRV_CARDS && port[i] != SNDRV_AUTO_PORT)
  1010. ++i;
  1011. return i;
  1012. }
  1013. static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
  1014. const struct pnp_card_device_id *pid)
  1015. {
  1016. static int idx = 0;
  1017. struct pnp_dev *dev;
  1018. struct snd_card *card;
  1019. struct soundscape *sscape;
  1020. int ret;
  1021. /*
  1022. * Allow this function to fail *quietly* if all the ISA PnP
  1023. * devices were configured using module parameters instead.
  1024. */
  1025. if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS)
  1026. return -ENOSPC;
  1027. /*
  1028. * We have found a candidate ISA PnP card. Now we
  1029. * have to check that it has the devices that we
  1030. * expect it to have.
  1031. */
  1032. /*
  1033. * Check that we still have room for another sound card ...
  1034. */
  1035. dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  1036. if (! dev)
  1037. return -ENODEV;
  1038. if (!pnp_is_active(dev)) {
  1039. if (pnp_activate_dev(dev) < 0) {
  1040. snd_printk(KERN_INFO "sscape: device is inactive\n");
  1041. return -EBUSY;
  1042. }
  1043. }
  1044. /*
  1045. * Create a new ALSA sound card entry, in anticipation
  1046. * of detecting our hardware ...
  1047. */
  1048. ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
  1049. sizeof(struct soundscape), &card);
  1050. if (ret < 0)
  1051. return ret;
  1052. sscape = get_card_soundscape(card);
  1053. /*
  1054. * Identify card model ...
  1055. */
  1056. if (!strncmp("ENS4081", pid->id, 7))
  1057. sscape->type = SSCAPE_VIVO;
  1058. else
  1059. sscape->type = SSCAPE_PNP;
  1060. /*
  1061. * Read the correct parameters off the ISA PnP bus ...
  1062. */
  1063. port[idx] = pnp_port_start(dev, 0);
  1064. irq[idx] = pnp_irq(dev, 0);
  1065. mpu_irq[idx] = pnp_irq(dev, 1);
  1066. dma[idx] = pnp_dma(dev, 0) & 0x03;
  1067. if (sscape->type == SSCAPE_PNP) {
  1068. dma2[idx] = dma[idx];
  1069. wss_port[idx] = CODEC_IO(port[idx]);
  1070. } else {
  1071. wss_port[idx] = pnp_port_start(dev, 1);
  1072. dma2[idx] = pnp_dma(dev, 1);
  1073. }
  1074. snd_card_set_dev(card, &pcard->card->dev);
  1075. ret = create_sscape(idx, card);
  1076. if (ret < 0)
  1077. goto _release_card;
  1078. if ((ret = snd_card_register(card)) < 0) {
  1079. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  1080. goto _release_card;
  1081. }
  1082. pnp_set_card_drvdata(pcard, card);
  1083. ++idx;
  1084. return 0;
  1085. _release_card:
  1086. snd_card_free(card);
  1087. return ret;
  1088. }
  1089. static void __devexit sscape_pnp_remove(struct pnp_card_link * pcard)
  1090. {
  1091. snd_card_free(pnp_get_card_drvdata(pcard));
  1092. pnp_set_card_drvdata(pcard, NULL);
  1093. }
  1094. static struct pnp_card_driver sscape_pnpc_driver = {
  1095. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1096. .name = "sscape",
  1097. .id_table = sscape_pnpids,
  1098. .probe = sscape_pnp_detect,
  1099. .remove = __devexit_p(sscape_pnp_remove),
  1100. };
  1101. #endif /* CONFIG_PNP */
  1102. static int __init sscape_init(void)
  1103. {
  1104. int err;
  1105. err = isa_register_driver(&snd_sscape_driver, SNDRV_CARDS);
  1106. #ifdef CONFIG_PNP
  1107. if (!err)
  1108. isa_registered = 1;
  1109. err = pnp_register_card_driver(&sscape_pnpc_driver);
  1110. if (!err)
  1111. pnp_registered = 1;
  1112. if (isa_registered)
  1113. err = 0;
  1114. #endif
  1115. return err;
  1116. }
  1117. static void __exit sscape_exit(void)
  1118. {
  1119. #ifdef CONFIG_PNP
  1120. if (pnp_registered)
  1121. pnp_unregister_card_driver(&sscape_pnpc_driver);
  1122. if (isa_registered)
  1123. #endif
  1124. isa_unregister_driver(&snd_sscape_driver);
  1125. }
  1126. module_init(sscape_init);
  1127. module_exit(sscape_exit);