sscape.c 33 KB

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