sscape.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357
  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/io.h>
  26. #include <linux/isa.h>
  27. #include <linux/delay.h>
  28. #include <linux/firmware.h>
  29. #include <linux/pnp.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/module.h>
  32. #include <asm/dma.h>
  33. #include <sound/core.h>
  34. #include <sound/wss.h>
  35. #include <sound/mpu401.h>
  36. #include <sound/initval.h>
  37. MODULE_AUTHOR("Chris Rankin");
  38. MODULE_DESCRIPTION("ENSONIQ SoundScape driver");
  39. MODULE_LICENSE("GPL");
  40. MODULE_FIRMWARE("sndscape.co0");
  41. MODULE_FIRMWARE("sndscape.co1");
  42. MODULE_FIRMWARE("sndscape.co2");
  43. MODULE_FIRMWARE("sndscape.co3");
  44. MODULE_FIRMWARE("sndscape.co4");
  45. MODULE_FIRMWARE("scope.cod");
  46. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  47. static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  48. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  49. static long wss_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  50. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  51. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  52. static int dma[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
  53. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;
  54. static bool joystick[SNDRV_CARDS];
  55. module_param_array(index, int, NULL, 0444);
  56. MODULE_PARM_DESC(index, "Index number for SoundScape soundcard");
  57. module_param_array(id, charp, NULL, 0444);
  58. MODULE_PARM_DESC(id, "Description for SoundScape card");
  59. module_param_array(port, long, NULL, 0444);
  60. MODULE_PARM_DESC(port, "Port # for SoundScape driver.");
  61. module_param_array(wss_port, long, NULL, 0444);
  62. MODULE_PARM_DESC(wss_port, "WSS Port # for SoundScape driver.");
  63. module_param_array(irq, int, NULL, 0444);
  64. MODULE_PARM_DESC(irq, "IRQ # for SoundScape driver.");
  65. module_param_array(mpu_irq, int, NULL, 0444);
  66. MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver.");
  67. module_param_array(dma, int, NULL, 0444);
  68. MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
  69. module_param_array(dma2, int, NULL, 0444);
  70. MODULE_PARM_DESC(dma2, "DMA2 # for SoundScape driver.");
  71. module_param_array(joystick, bool, NULL, 0444);
  72. MODULE_PARM_DESC(joystick, "Enable gameport.");
  73. #ifdef CONFIG_PNP
  74. static int isa_registered;
  75. static int pnp_registered;
  76. static struct pnp_card_device_id sscape_pnpids[] = {
  77. { .id = "ENS3081", .devs = { { "ENS0000" } } }, /* Soundscape PnP */
  78. { .id = "ENS4081", .devs = { { "ENS1011" } } }, /* VIVO90 */
  79. { .id = "" } /* end */
  80. };
  81. MODULE_DEVICE_TABLE(pnp_card, sscape_pnpids);
  82. #endif
  83. #define HOST_CTRL_IO(i) ((i) + 2)
  84. #define HOST_DATA_IO(i) ((i) + 3)
  85. #define ODIE_ADDR_IO(i) ((i) + 4)
  86. #define ODIE_DATA_IO(i) ((i) + 5)
  87. #define CODEC_IO(i) ((i) + 8)
  88. #define IC_ODIE 1
  89. #define IC_OPUS 2
  90. #define RX_READY 0x01
  91. #define TX_READY 0x02
  92. #define CMD_ACK 0x80
  93. #define CMD_SET_MIDI_VOL 0x84
  94. #define CMD_GET_MIDI_VOL 0x85
  95. #define CMD_XXX_MIDI_VOL 0x86
  96. #define CMD_SET_EXTMIDI 0x8a
  97. #define CMD_GET_EXTMIDI 0x8b
  98. #define CMD_SET_MT32 0x8c
  99. #define CMD_GET_MT32 0x8d
  100. enum GA_REG {
  101. GA_INTSTAT_REG = 0,
  102. GA_INTENA_REG,
  103. GA_DMAA_REG,
  104. GA_DMAB_REG,
  105. GA_INTCFG_REG,
  106. GA_DMACFG_REG,
  107. GA_CDCFG_REG,
  108. GA_SMCFGA_REG,
  109. GA_SMCFGB_REG,
  110. GA_HMCTL_REG
  111. };
  112. #define DMA_8BIT 0x80
  113. enum card_type {
  114. MEDIA_FX, /* Sequoia S-1000 */
  115. SSCAPE, /* Sequoia S-2000 */
  116. SSCAPE_PNP,
  117. SSCAPE_VIVO,
  118. };
  119. struct soundscape {
  120. spinlock_t lock;
  121. unsigned io_base;
  122. int ic_type;
  123. enum card_type type;
  124. struct resource *io_res;
  125. struct resource *wss_res;
  126. struct snd_wss *chip;
  127. unsigned char midi_vol;
  128. };
  129. #define INVALID_IRQ ((unsigned)-1)
  130. static inline struct soundscape *get_card_soundscape(struct snd_card *c)
  131. {
  132. return (struct soundscape *) (c->private_data);
  133. }
  134. /*
  135. * Allocates some kernel memory that we can use for DMA.
  136. * I think this means that the memory has to map to
  137. * contiguous pages of physical memory.
  138. */
  139. static struct snd_dma_buffer *get_dmabuf(struct snd_dma_buffer *buf,
  140. unsigned long size)
  141. {
  142. if (buf) {
  143. if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV,
  144. snd_dma_isa_data(),
  145. size, buf) < 0) {
  146. snd_printk(KERN_ERR "sscape: Failed to allocate "
  147. "%lu bytes for DMA\n",
  148. size);
  149. return NULL;
  150. }
  151. }
  152. return buf;
  153. }
  154. /*
  155. * Release the DMA-able kernel memory ...
  156. */
  157. static void free_dmabuf(struct snd_dma_buffer *buf)
  158. {
  159. if (buf && buf->area)
  160. snd_dma_free_pages(buf);
  161. }
  162. /*
  163. * This function writes to the SoundScape's control registers,
  164. * but doesn't do any locking. It's up to the caller to do that.
  165. * This is why this function is "unsafe" ...
  166. */
  167. static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg,
  168. unsigned char val)
  169. {
  170. outb(reg, ODIE_ADDR_IO(io_base));
  171. outb(val, ODIE_DATA_IO(io_base));
  172. }
  173. /*
  174. * Write to the SoundScape's control registers, and do the
  175. * necessary locking ...
  176. */
  177. static void sscape_write(struct soundscape *s, enum GA_REG reg,
  178. unsigned char val)
  179. {
  180. unsigned long flags;
  181. spin_lock_irqsave(&s->lock, flags);
  182. sscape_write_unsafe(s->io_base, reg, val);
  183. spin_unlock_irqrestore(&s->lock, flags);
  184. }
  185. /*
  186. * Read from the SoundScape's control registers, but leave any
  187. * locking to the caller. This is why the function is "unsafe" ...
  188. */
  189. static inline unsigned char sscape_read_unsafe(unsigned io_base,
  190. enum GA_REG reg)
  191. {
  192. outb(reg, ODIE_ADDR_IO(io_base));
  193. return inb(ODIE_DATA_IO(io_base));
  194. }
  195. /*
  196. * Puts the SoundScape into "host" mode, as compared to "MIDI" mode
  197. */
  198. static inline void set_host_mode_unsafe(unsigned io_base)
  199. {
  200. outb(0x0, HOST_CTRL_IO(io_base));
  201. }
  202. /*
  203. * Puts the SoundScape into "MIDI" mode, as compared to "host" mode
  204. */
  205. static inline void set_midi_mode_unsafe(unsigned io_base)
  206. {
  207. outb(0x3, HOST_CTRL_IO(io_base));
  208. }
  209. /*
  210. * Read the SoundScape's host-mode control register, but leave
  211. * any locking issues to the caller ...
  212. */
  213. static inline int host_read_unsafe(unsigned io_base)
  214. {
  215. int data = -1;
  216. if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0)
  217. data = inb(HOST_DATA_IO(io_base));
  218. return data;
  219. }
  220. /*
  221. * Read the SoundScape's host-mode control register, performing
  222. * a limited amount of busy-waiting if the register isn't ready.
  223. * Also leaves all locking-issues to the caller ...
  224. */
  225. static int host_read_ctrl_unsafe(unsigned io_base, unsigned timeout)
  226. {
  227. int data;
  228. while (((data = host_read_unsafe(io_base)) < 0) && (timeout != 0)) {
  229. udelay(100);
  230. --timeout;
  231. } /* while */
  232. return data;
  233. }
  234. /*
  235. * Write to the SoundScape's host-mode control registers, but
  236. * leave any locking issues to the caller ...
  237. */
  238. static inline int host_write_unsafe(unsigned io_base, unsigned char data)
  239. {
  240. if ((inb(HOST_CTRL_IO(io_base)) & TX_READY) != 0) {
  241. outb(data, HOST_DATA_IO(io_base));
  242. return 1;
  243. }
  244. return 0;
  245. }
  246. /*
  247. * Write to the SoundScape's host-mode control registers, performing
  248. * a limited amount of busy-waiting if the register isn't ready.
  249. * Also leaves all locking-issues to the caller ...
  250. */
  251. static int host_write_ctrl_unsafe(unsigned io_base, unsigned char data,
  252. unsigned timeout)
  253. {
  254. int err;
  255. while (!(err = host_write_unsafe(io_base, data)) && (timeout != 0)) {
  256. udelay(100);
  257. --timeout;
  258. } /* while */
  259. return err;
  260. }
  261. /*
  262. * Check that the MIDI subsystem is operational. If it isn't,
  263. * then we will hang the computer if we try to use it ...
  264. *
  265. * NOTE: This check is based upon observation, not documentation.
  266. */
  267. static inline int verify_mpu401(const struct snd_mpu401 *mpu)
  268. {
  269. return ((inb(MPU401C(mpu)) & 0xc0) == 0x80);
  270. }
  271. /*
  272. * This is apparently the standard way to initailise an MPU-401
  273. */
  274. static inline void initialise_mpu401(const struct snd_mpu401 *mpu)
  275. {
  276. outb(0, MPU401D(mpu));
  277. }
  278. /*
  279. * Tell the SoundScape to activate the AD1845 chip (I think).
  280. * The AD1845 detection fails if we *don't* do this, so I
  281. * think that this is a good idea ...
  282. */
  283. static void activate_ad1845_unsafe(unsigned io_base)
  284. {
  285. unsigned char val = sscape_read_unsafe(io_base, GA_HMCTL_REG);
  286. sscape_write_unsafe(io_base, GA_HMCTL_REG, (val & 0xcf) | 0x10);
  287. sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
  288. }
  289. /*
  290. * Do the necessary ALSA-level cleanup to deallocate our driver ...
  291. */
  292. static void soundscape_free(struct snd_card *c)
  293. {
  294. struct soundscape *sscape = get_card_soundscape(c);
  295. release_and_free_resource(sscape->io_res);
  296. release_and_free_resource(sscape->wss_res);
  297. free_dma(sscape->chip->dma1);
  298. }
  299. /*
  300. * Tell the SoundScape to begin a DMA tranfer using the given channel.
  301. * All locking issues are left to the caller.
  302. */
  303. static void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
  304. {
  305. sscape_write_unsafe(io_base, reg,
  306. sscape_read_unsafe(io_base, reg) | 0x01);
  307. sscape_write_unsafe(io_base, reg,
  308. sscape_read_unsafe(io_base, reg) & 0xfe);
  309. }
  310. /*
  311. * Wait for a DMA transfer to complete. This is a "limited busy-wait",
  312. * and all locking issues are left to the caller.
  313. */
  314. static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg,
  315. unsigned timeout)
  316. {
  317. while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
  318. udelay(100);
  319. --timeout;
  320. } /* while */
  321. return sscape_read_unsafe(io_base, reg) & 0x01;
  322. }
  323. /*
  324. * Wait for the On-Board Processor to return its start-up
  325. * acknowledgement sequence. This wait is too long for
  326. * us to perform "busy-waiting", and so we must sleep.
  327. * This in turn means that we must not be holding any
  328. * spinlocks when we call this function.
  329. */
  330. static int obp_startup_ack(struct soundscape *s, unsigned timeout)
  331. {
  332. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  333. do {
  334. unsigned long flags;
  335. int x;
  336. spin_lock_irqsave(&s->lock, flags);
  337. x = host_read_unsafe(s->io_base);
  338. spin_unlock_irqrestore(&s->lock, flags);
  339. if (x == 0xfe || x == 0xff)
  340. return 1;
  341. msleep(10);
  342. } while (time_before(jiffies, end_time));
  343. return 0;
  344. }
  345. /*
  346. * Wait for the host to return its start-up acknowledgement
  347. * sequence. This wait is too long for us to perform
  348. * "busy-waiting", and so we must sleep. This in turn means
  349. * that we must not be holding any spinlocks when we call
  350. * this function.
  351. */
  352. static int host_startup_ack(struct soundscape *s, unsigned timeout)
  353. {
  354. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  355. do {
  356. unsigned long flags;
  357. int x;
  358. spin_lock_irqsave(&s->lock, flags);
  359. x = host_read_unsafe(s->io_base);
  360. spin_unlock_irqrestore(&s->lock, flags);
  361. if (x == 0xfe)
  362. return 1;
  363. msleep(10);
  364. } while (time_before(jiffies, end_time));
  365. return 0;
  366. }
  367. /*
  368. * Upload a byte-stream into the SoundScape using DMA channel A.
  369. */
  370. static int upload_dma_data(struct soundscape *s, const unsigned char *data,
  371. size_t size)
  372. {
  373. unsigned long flags;
  374. struct snd_dma_buffer dma;
  375. int ret;
  376. unsigned char val;
  377. if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024)))
  378. return -ENOMEM;
  379. spin_lock_irqsave(&s->lock, flags);
  380. /*
  381. * Reset the board ...
  382. */
  383. val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
  384. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val & 0x3f);
  385. /*
  386. * Enable the DMA channels and configure them ...
  387. */
  388. val = (s->chip->dma1 << 4) | DMA_8BIT;
  389. sscape_write_unsafe(s->io_base, GA_DMAA_REG, val);
  390. sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
  391. /*
  392. * Take the board out of reset ...
  393. */
  394. val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
  395. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x80);
  396. /*
  397. * Upload the firmware to the SoundScape
  398. * board through the DMA channel ...
  399. */
  400. while (size != 0) {
  401. unsigned long len;
  402. len = min(size, dma.bytes);
  403. memcpy(dma.area, data, len);
  404. data += len;
  405. size -= len;
  406. snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
  407. sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
  408. if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
  409. /*
  410. * Don't forget to release this spinlock we're holding
  411. */
  412. spin_unlock_irqrestore(&s->lock, flags);
  413. snd_printk(KERN_ERR
  414. "sscape: DMA upload has timed out\n");
  415. ret = -EAGAIN;
  416. goto _release_dma;
  417. }
  418. } /* while */
  419. set_host_mode_unsafe(s->io_base);
  420. outb(0x0, s->io_base);
  421. /*
  422. * Boot the board ... (I think)
  423. */
  424. val = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
  425. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, val | 0x40);
  426. spin_unlock_irqrestore(&s->lock, flags);
  427. /*
  428. * If all has gone well, then the board should acknowledge
  429. * the new upload and tell us that it has rebooted OK. We
  430. * give it 5 seconds (max) ...
  431. */
  432. ret = 0;
  433. if (!obp_startup_ack(s, 5000)) {
  434. snd_printk(KERN_ERR "sscape: No response "
  435. "from on-board processor after upload\n");
  436. ret = -EAGAIN;
  437. } else if (!host_startup_ack(s, 5000)) {
  438. snd_printk(KERN_ERR
  439. "sscape: SoundScape failed to initialise\n");
  440. ret = -EAGAIN;
  441. }
  442. _release_dma:
  443. /*
  444. * NOTE!!! We are NOT holding any spinlocks at this point !!!
  445. */
  446. sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70));
  447. free_dmabuf(&dma);
  448. return ret;
  449. }
  450. /*
  451. * Upload the bootblock(?) into the SoundScape. The only
  452. * purpose of this block of code seems to be to tell
  453. * us which version of the microcode we should be using.
  454. */
  455. static int sscape_upload_bootblock(struct snd_card *card)
  456. {
  457. struct soundscape *sscape = get_card_soundscape(card);
  458. unsigned long flags;
  459. const struct firmware *init_fw = NULL;
  460. int data = 0;
  461. int ret;
  462. ret = request_firmware(&init_fw, "scope.cod", card->dev);
  463. if (ret < 0) {
  464. snd_printk(KERN_ERR "sscape: Error loading scope.cod");
  465. return ret;
  466. }
  467. ret = upload_dma_data(sscape, init_fw->data, init_fw->size);
  468. release_firmware(init_fw);
  469. spin_lock_irqsave(&sscape->lock, flags);
  470. if (ret == 0)
  471. data = host_read_ctrl_unsafe(sscape->io_base, 100);
  472. if (data & 0x10)
  473. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f);
  474. spin_unlock_irqrestore(&sscape->lock, flags);
  475. data &= 0xf;
  476. if (ret == 0 && data > 7) {
  477. snd_printk(KERN_ERR
  478. "sscape: timeout reading firmware version\n");
  479. ret = -EAGAIN;
  480. }
  481. return (ret == 0) ? data : ret;
  482. }
  483. /*
  484. * Upload the microcode into the SoundScape.
  485. */
  486. static int sscape_upload_microcode(struct snd_card *card, int version)
  487. {
  488. struct soundscape *sscape = get_card_soundscape(card);
  489. const struct firmware *init_fw = NULL;
  490. char name[14];
  491. int err;
  492. snprintf(name, sizeof(name), "sndscape.co%d", version);
  493. err = request_firmware(&init_fw, name, card->dev);
  494. if (err < 0) {
  495. snd_printk(KERN_ERR "sscape: Error loading sndscape.co%d",
  496. version);
  497. return err;
  498. }
  499. err = upload_dma_data(sscape, init_fw->data, init_fw->size);
  500. if (err == 0)
  501. snd_printk(KERN_INFO "sscape: MIDI firmware loaded %d KBs\n",
  502. init_fw->size >> 10);
  503. release_firmware(init_fw);
  504. return err;
  505. }
  506. /*
  507. * Mixer control for the SoundScape's MIDI device.
  508. */
  509. static int sscape_midi_info(struct snd_kcontrol *ctl,
  510. struct snd_ctl_elem_info *uinfo)
  511. {
  512. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  513. uinfo->count = 1;
  514. uinfo->value.integer.min = 0;
  515. uinfo->value.integer.max = 127;
  516. return 0;
  517. }
  518. static int sscape_midi_get(struct snd_kcontrol *kctl,
  519. struct snd_ctl_elem_value *uctl)
  520. {
  521. struct snd_wss *chip = snd_kcontrol_chip(kctl);
  522. struct snd_card *card = chip->card;
  523. register struct soundscape *s = get_card_soundscape(card);
  524. unsigned long flags;
  525. spin_lock_irqsave(&s->lock, flags);
  526. uctl->value.integer.value[0] = s->midi_vol;
  527. spin_unlock_irqrestore(&s->lock, flags);
  528. return 0;
  529. }
  530. static int sscape_midi_put(struct snd_kcontrol *kctl,
  531. struct snd_ctl_elem_value *uctl)
  532. {
  533. struct snd_wss *chip = snd_kcontrol_chip(kctl);
  534. struct snd_card *card = chip->card;
  535. struct soundscape *s = get_card_soundscape(card);
  536. unsigned long flags;
  537. int change;
  538. unsigned char new_val;
  539. spin_lock_irqsave(&s->lock, flags);
  540. new_val = uctl->value.integer.value[0] & 127;
  541. /*
  542. * We need to put the board into HOST mode before we
  543. * can send any volume-changing HOST commands ...
  544. */
  545. set_host_mode_unsafe(s->io_base);
  546. /*
  547. * To successfully change the MIDI volume setting, you seem to
  548. * have to write a volume command, write the new volume value,
  549. * and then perform another volume-related command. Perhaps the
  550. * first command is an "open" and the second command is a "close"?
  551. */
  552. if (s->midi_vol == new_val) {
  553. change = 0;
  554. goto __skip_change;
  555. }
  556. change = host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
  557. && host_write_ctrl_unsafe(s->io_base, new_val, 100)
  558. && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100)
  559. && host_write_ctrl_unsafe(s->io_base, new_val, 100);
  560. s->midi_vol = new_val;
  561. __skip_change:
  562. /*
  563. * Take the board out of HOST mode and back into MIDI mode ...
  564. */
  565. set_midi_mode_unsafe(s->io_base);
  566. spin_unlock_irqrestore(&s->lock, flags);
  567. return change;
  568. }
  569. static struct snd_kcontrol_new midi_mixer_ctl = {
  570. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  571. .name = "MIDI",
  572. .info = sscape_midi_info,
  573. .get = sscape_midi_get,
  574. .put = sscape_midi_put
  575. };
  576. /*
  577. * The SoundScape can use two IRQs from a possible set of four.
  578. * These IRQs are encoded as bit patterns so that they can be
  579. * written to the control registers.
  580. */
  581. static unsigned get_irq_config(int sscape_type, int irq)
  582. {
  583. static const int valid_irq[] = { 9, 5, 7, 10 };
  584. static const int old_irq[] = { 9, 7, 5, 15 };
  585. unsigned cfg;
  586. if (sscape_type == MEDIA_FX) {
  587. for (cfg = 0; cfg < ARRAY_SIZE(old_irq); ++cfg)
  588. if (irq == old_irq[cfg])
  589. return cfg;
  590. } else {
  591. for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg)
  592. if (irq == valid_irq[cfg])
  593. return cfg;
  594. }
  595. return INVALID_IRQ;
  596. }
  597. /*
  598. * Perform certain arcane port-checks to see whether there
  599. * is a SoundScape board lurking behind the given ports.
  600. */
  601. static int detect_sscape(struct soundscape *s, long wss_io)
  602. {
  603. unsigned long flags;
  604. unsigned d;
  605. int retval = 0;
  606. spin_lock_irqsave(&s->lock, flags);
  607. /*
  608. * The following code is lifted from the original OSS driver,
  609. * and as I don't have a datasheet I cannot really comment
  610. * on what it is doing...
  611. */
  612. if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0)
  613. goto _done;
  614. d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0;
  615. if ((d & 0x80) != 0)
  616. goto _done;
  617. if (d == 0)
  618. s->ic_type = IC_ODIE;
  619. else if ((d & 0x60) != 0)
  620. s->ic_type = IC_OPUS;
  621. else
  622. goto _done;
  623. outb(0xfa, ODIE_ADDR_IO(s->io_base));
  624. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a)
  625. goto _done;
  626. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  627. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e)
  628. goto _done;
  629. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  630. d = inb(ODIE_DATA_IO(s->io_base));
  631. if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
  632. goto _done;
  633. if (s->ic_type == IC_OPUS)
  634. activate_ad1845_unsafe(s->io_base);
  635. if (s->type == SSCAPE_VIVO)
  636. wss_io += 4;
  637. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
  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. if ((inb(wss_io) & 0x80) != 0)
  648. goto _done;
  649. if (inb(wss_io + 2) == 0xff)
  650. goto _done;
  651. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  652. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d);
  653. if ((inb(wss_io) & 0x80) != 0)
  654. s->type = MEDIA_FX;
  655. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG);
  656. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
  657. /* wait for WSS codec */
  658. for (d = 0; d < 500; d++) {
  659. if ((inb(wss_io) & 0x80) == 0)
  660. break;
  661. spin_unlock_irqrestore(&s->lock, flags);
  662. msleep(1);
  663. spin_lock_irqsave(&s->lock, flags);
  664. }
  665. /*
  666. * SoundScape successfully detected!
  667. */
  668. retval = 1;
  669. _done:
  670. spin_unlock_irqrestore(&s->lock, flags);
  671. return retval;
  672. }
  673. /*
  674. * ALSA callback function, called when attempting to open the MIDI device.
  675. * Check that the MIDI firmware has been loaded, because we don't want
  676. * to crash the machine. Also check that someone isn't using the hardware
  677. * IOCTL device.
  678. */
  679. static int mpu401_open(struct snd_mpu401 *mpu)
  680. {
  681. if (!verify_mpu401(mpu)) {
  682. snd_printk(KERN_ERR "sscape: MIDI disabled, "
  683. "please load firmware\n");
  684. return -ENODEV;
  685. }
  686. return 0;
  687. }
  688. /*
  689. * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
  690. */
  691. static int create_mpu401(struct snd_card *card, int devnum,
  692. unsigned long port, int irq)
  693. {
  694. struct soundscape *sscape = get_card_soundscape(card);
  695. struct snd_rawmidi *rawmidi;
  696. int err;
  697. err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port,
  698. MPU401_INFO_INTEGRATED, irq, &rawmidi);
  699. if (err == 0) {
  700. struct snd_mpu401 *mpu = rawmidi->private_data;
  701. mpu->open_input = mpu401_open;
  702. mpu->open_output = mpu401_open;
  703. mpu->private_data = sscape;
  704. initialise_mpu401(mpu);
  705. }
  706. return err;
  707. }
  708. /*
  709. * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
  710. * is very much like a CS4231, with a few extra bits. We will
  711. * try to support at least some of the extra bits by overriding
  712. * some of the CS4231 callback.
  713. */
  714. static int create_ad1845(struct snd_card *card, unsigned port,
  715. int irq, int dma1, int dma2)
  716. {
  717. register struct soundscape *sscape = get_card_soundscape(card);
  718. struct snd_wss *chip;
  719. int err;
  720. int codec_type = WSS_HW_DETECT;
  721. switch (sscape->type) {
  722. case MEDIA_FX:
  723. case SSCAPE:
  724. /*
  725. * There are some freak examples of early Soundscape cards
  726. * with CS4231 instead of AD1848/CS4248. Unfortunately, the
  727. * CS4231 works only in CS4248 compatibility mode on
  728. * these cards so force it.
  729. */
  730. if (sscape->ic_type != IC_OPUS)
  731. codec_type = WSS_HW_AD1848;
  732. break;
  733. case SSCAPE_VIVO:
  734. port += 4;
  735. break;
  736. default:
  737. break;
  738. }
  739. err = snd_wss_create(card, port, -1, irq, dma1, dma2,
  740. codec_type, WSS_HWSHARE_DMA1, &chip);
  741. if (!err) {
  742. unsigned long flags;
  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);
  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);
  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 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 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 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_new(pdev, 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. ret = create_sscape(dev, card);
  1004. if (ret < 0)
  1005. goto _release_card;
  1006. ret = snd_card_register(card);
  1007. if (ret < 0) {
  1008. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  1009. goto _release_card;
  1010. }
  1011. dev_set_drvdata(pdev, card);
  1012. return 0;
  1013. _release_card:
  1014. snd_card_free(card);
  1015. return ret;
  1016. }
  1017. static int snd_sscape_remove(struct device *devptr, unsigned int dev)
  1018. {
  1019. snd_card_free(dev_get_drvdata(devptr));
  1020. return 0;
  1021. }
  1022. #define DEV_NAME "sscape"
  1023. static struct isa_driver snd_sscape_driver = {
  1024. .match = snd_sscape_match,
  1025. .probe = snd_sscape_probe,
  1026. .remove = snd_sscape_remove,
  1027. /* FIXME: suspend/resume */
  1028. .driver = {
  1029. .name = DEV_NAME
  1030. },
  1031. };
  1032. #ifdef CONFIG_PNP
  1033. static inline int get_next_autoindex(int i)
  1034. {
  1035. while (i < SNDRV_CARDS && port[i] != SNDRV_AUTO_PORT)
  1036. ++i;
  1037. return i;
  1038. }
  1039. static int sscape_pnp_detect(struct pnp_card_link *pcard,
  1040. const struct pnp_card_device_id *pid)
  1041. {
  1042. static int idx = 0;
  1043. struct pnp_dev *dev;
  1044. struct snd_card *card;
  1045. struct soundscape *sscape;
  1046. int ret;
  1047. /*
  1048. * Allow this function to fail *quietly* if all the ISA PnP
  1049. * devices were configured using module parameters instead.
  1050. */
  1051. idx = get_next_autoindex(idx);
  1052. if (idx >= SNDRV_CARDS)
  1053. return -ENOSPC;
  1054. /*
  1055. * Check that we still have room for another sound card ...
  1056. */
  1057. dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  1058. if (!dev)
  1059. return -ENODEV;
  1060. if (!pnp_is_active(dev)) {
  1061. if (pnp_activate_dev(dev) < 0) {
  1062. snd_printk(KERN_INFO "sscape: device is inactive\n");
  1063. return -EBUSY;
  1064. }
  1065. }
  1066. /*
  1067. * Create a new ALSA sound card entry, in anticipation
  1068. * of detecting our hardware ...
  1069. */
  1070. ret = snd_card_new(&pcard->card->dev,
  1071. index[idx], id[idx], THIS_MODULE,
  1072. sizeof(struct soundscape), &card);
  1073. if (ret < 0)
  1074. return ret;
  1075. sscape = get_card_soundscape(card);
  1076. /*
  1077. * Identify card model ...
  1078. */
  1079. if (!strncmp("ENS4081", pid->id, 7))
  1080. sscape->type = SSCAPE_VIVO;
  1081. else
  1082. sscape->type = SSCAPE_PNP;
  1083. /*
  1084. * Read the correct parameters off the ISA PnP bus ...
  1085. */
  1086. port[idx] = pnp_port_start(dev, 0);
  1087. irq[idx] = pnp_irq(dev, 0);
  1088. mpu_irq[idx] = pnp_irq(dev, 1);
  1089. dma[idx] = pnp_dma(dev, 0) & 0x03;
  1090. if (sscape->type == SSCAPE_PNP) {
  1091. dma2[idx] = dma[idx];
  1092. wss_port[idx] = CODEC_IO(port[idx]);
  1093. } else {
  1094. wss_port[idx] = pnp_port_start(dev, 1);
  1095. dma2[idx] = pnp_dma(dev, 1);
  1096. }
  1097. ret = create_sscape(idx, card);
  1098. if (ret < 0)
  1099. goto _release_card;
  1100. ret = snd_card_register(card);
  1101. if (ret < 0) {
  1102. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  1103. goto _release_card;
  1104. }
  1105. pnp_set_card_drvdata(pcard, card);
  1106. ++idx;
  1107. return 0;
  1108. _release_card:
  1109. snd_card_free(card);
  1110. return ret;
  1111. }
  1112. static void sscape_pnp_remove(struct pnp_card_link *pcard)
  1113. {
  1114. snd_card_free(pnp_get_card_drvdata(pcard));
  1115. pnp_set_card_drvdata(pcard, NULL);
  1116. }
  1117. static struct pnp_card_driver sscape_pnpc_driver = {
  1118. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1119. .name = "sscape",
  1120. .id_table = sscape_pnpids,
  1121. .probe = sscape_pnp_detect,
  1122. .remove = sscape_pnp_remove,
  1123. };
  1124. #endif /* CONFIG_PNP */
  1125. static int __init sscape_init(void)
  1126. {
  1127. int err;
  1128. err = isa_register_driver(&snd_sscape_driver, SNDRV_CARDS);
  1129. #ifdef CONFIG_PNP
  1130. if (!err)
  1131. isa_registered = 1;
  1132. err = pnp_register_card_driver(&sscape_pnpc_driver);
  1133. if (!err)
  1134. pnp_registered = 1;
  1135. if (isa_registered)
  1136. err = 0;
  1137. #endif
  1138. return err;
  1139. }
  1140. static void __exit sscape_exit(void)
  1141. {
  1142. #ifdef CONFIG_PNP
  1143. if (pnp_registered)
  1144. pnp_unregister_card_driver(&sscape_pnpc_driver);
  1145. if (isa_registered)
  1146. #endif
  1147. isa_unregister_driver(&snd_sscape_driver);
  1148. }
  1149. module_init(sscape_init);
  1150. module_exit(sscape_exit);