sscape.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359
  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] = 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, IRQF_DISABLED,
  698. &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 __devinit 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. struct snd_pcm *pcm;
  744. if (sscape->type != SSCAPE_VIVO) {
  745. /*
  746. * The input clock frequency on the SoundScape must
  747. * be 14.31818 MHz, because we must set this register
  748. * to get the playback to sound correct ...
  749. */
  750. snd_wss_mce_up(chip);
  751. spin_lock_irqsave(&chip->reg_lock, flags);
  752. snd_wss_out(chip, AD1845_CLOCK, 0x20);
  753. spin_unlock_irqrestore(&chip->reg_lock, flags);
  754. snd_wss_mce_down(chip);
  755. }
  756. err = snd_wss_pcm(chip, 0, &pcm);
  757. if (err < 0) {
  758. snd_printk(KERN_ERR "sscape: No PCM device "
  759. "for AD1845 chip\n");
  760. goto _error;
  761. }
  762. err = snd_wss_mixer(chip);
  763. if (err < 0) {
  764. snd_printk(KERN_ERR "sscape: No mixer device "
  765. "for AD1845 chip\n");
  766. goto _error;
  767. }
  768. if (chip->hardware != WSS_HW_AD1848) {
  769. err = snd_wss_timer(chip, 0, NULL);
  770. if (err < 0) {
  771. snd_printk(KERN_ERR "sscape: No timer device "
  772. "for AD1845 chip\n");
  773. goto _error;
  774. }
  775. }
  776. if (sscape->type != SSCAPE_VIVO) {
  777. err = snd_ctl_add(card,
  778. snd_ctl_new1(&midi_mixer_ctl, chip));
  779. if (err < 0) {
  780. snd_printk(KERN_ERR "sscape: Could not create "
  781. "MIDI mixer control\n");
  782. goto _error;
  783. }
  784. }
  785. sscape->chip = chip;
  786. }
  787. _error:
  788. return err;
  789. }
  790. /*
  791. * Create an ALSA soundcard entry for the SoundScape, using
  792. * the given list of port, IRQ and DMA resources.
  793. */
  794. static int __devinit create_sscape(int dev, struct snd_card *card)
  795. {
  796. struct soundscape *sscape = get_card_soundscape(card);
  797. unsigned dma_cfg;
  798. unsigned irq_cfg;
  799. unsigned mpu_irq_cfg;
  800. struct resource *io_res;
  801. struct resource *wss_res;
  802. unsigned long flags;
  803. int err;
  804. int val;
  805. const char *name;
  806. /*
  807. * Grab IO ports that we will need to probe so that we
  808. * can detect and control this hardware ...
  809. */
  810. io_res = request_region(port[dev], 8, "SoundScape");
  811. if (!io_res) {
  812. snd_printk(KERN_ERR
  813. "sscape: can't grab port 0x%lx\n", port[dev]);
  814. return -EBUSY;
  815. }
  816. wss_res = NULL;
  817. if (sscape->type == SSCAPE_VIVO) {
  818. wss_res = request_region(wss_port[dev], 4, "SoundScape");
  819. if (!wss_res) {
  820. snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n",
  821. wss_port[dev]);
  822. err = -EBUSY;
  823. goto _release_region;
  824. }
  825. }
  826. /*
  827. * Grab one DMA channel ...
  828. */
  829. err = request_dma(dma[dev], "SoundScape");
  830. if (err < 0) {
  831. snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]);
  832. goto _release_region;
  833. }
  834. spin_lock_init(&sscape->lock);
  835. sscape->io_res = io_res;
  836. sscape->wss_res = wss_res;
  837. sscape->io_base = port[dev];
  838. if (!detect_sscape(sscape, wss_port[dev])) {
  839. printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
  840. sscape->io_base);
  841. err = -ENODEV;
  842. goto _release_dma;
  843. }
  844. switch (sscape->type) {
  845. case MEDIA_FX:
  846. name = "MediaFX/SoundFX";
  847. break;
  848. case SSCAPE:
  849. name = "Soundscape";
  850. break;
  851. case SSCAPE_PNP:
  852. name = "Soundscape PnP";
  853. break;
  854. case SSCAPE_VIVO:
  855. name = "Soundscape VIVO";
  856. break;
  857. default:
  858. name = "unknown Soundscape";
  859. break;
  860. }
  861. printk(KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
  862. name, sscape->io_base, irq[dev], dma[dev]);
  863. /*
  864. * Check that the user didn't pass us garbage data ...
  865. */
  866. irq_cfg = get_irq_config(sscape->type, irq[dev]);
  867. if (irq_cfg == INVALID_IRQ) {
  868. snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
  869. return -ENXIO;
  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. return -ENXIO;
  875. }
  876. /*
  877. * Tell the on-board devices where their resources are (I think -
  878. * I can't be sure without a datasheet ... So many magic values!)
  879. */
  880. spin_lock_irqsave(&sscape->lock, flags);
  881. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
  882. sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
  883. /*
  884. * Enable and configure the DMA channels ...
  885. */
  886. sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
  887. dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70);
  888. sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
  889. sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
  890. mpu_irq_cfg |= mpu_irq_cfg << 2;
  891. val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7;
  892. if (joystick[dev])
  893. val |= 8;
  894. sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10);
  895. sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg);
  896. sscape_write_unsafe(sscape->io_base,
  897. GA_CDCFG_REG, 0x09 | DMA_8BIT
  898. | (dma[dev] << 4) | (irq_cfg << 1));
  899. /*
  900. * Enable the master IRQ ...
  901. */
  902. sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x80);
  903. spin_unlock_irqrestore(&sscape->lock, flags);
  904. /*
  905. * We have now enabled the codec chip, and so we should
  906. * detect the AD1845 device ...
  907. */
  908. err = create_ad1845(card, wss_port[dev], irq[dev],
  909. dma[dev], dma2[dev]);
  910. if (err < 0) {
  911. snd_printk(KERN_ERR
  912. "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
  913. wss_port[dev], irq[dev]);
  914. goto _release_dma;
  915. }
  916. strcpy(card->driver, "SoundScape");
  917. strcpy(card->shortname, name);
  918. snprintf(card->longname, sizeof(card->longname),
  919. "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
  920. name, sscape->chip->port, sscape->chip->irq,
  921. sscape->chip->dma1, sscape->chip->dma2);
  922. #define MIDI_DEVNUM 0
  923. if (sscape->type != SSCAPE_VIVO) {
  924. err = sscape_upload_bootblock(card);
  925. if (err >= 0)
  926. err = sscape_upload_microcode(card, err);
  927. if (err == 0) {
  928. err = create_mpu401(card, MIDI_DEVNUM, port[dev],
  929. mpu_irq[dev]);
  930. if (err < 0) {
  931. snd_printk(KERN_ERR "sscape: Failed to create "
  932. "MPU-401 device at 0x%lx\n",
  933. port[dev]);
  934. goto _release_dma;
  935. }
  936. /*
  937. * Initialize mixer
  938. */
  939. spin_lock_irqsave(&sscape->lock, flags);
  940. sscape->midi_vol = 0;
  941. host_write_ctrl_unsafe(sscape->io_base,
  942. CMD_SET_MIDI_VOL, 100);
  943. host_write_ctrl_unsafe(sscape->io_base,
  944. sscape->midi_vol, 100);
  945. host_write_ctrl_unsafe(sscape->io_base,
  946. CMD_XXX_MIDI_VOL, 100);
  947. host_write_ctrl_unsafe(sscape->io_base,
  948. sscape->midi_vol, 100);
  949. host_write_ctrl_unsafe(sscape->io_base,
  950. CMD_SET_EXTMIDI, 100);
  951. host_write_ctrl_unsafe(sscape->io_base,
  952. 0, 100);
  953. host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
  954. set_midi_mode_unsafe(sscape->io_base);
  955. spin_unlock_irqrestore(&sscape->lock, flags);
  956. }
  957. }
  958. /*
  959. * Now that we have successfully created this sound card,
  960. * it is safe to store the pointer.
  961. * NOTE: we only register the sound card's "destructor"
  962. * function now that our "constructor" has completed.
  963. */
  964. card->private_free = soundscape_free;
  965. return 0;
  966. _release_dma:
  967. free_dma(dma[dev]);
  968. _release_region:
  969. release_and_free_resource(wss_res);
  970. release_and_free_resource(io_res);
  971. return err;
  972. }
  973. static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
  974. {
  975. /*
  976. * Make sure we were given ALL of the other parameters.
  977. */
  978. if (port[i] == SNDRV_AUTO_PORT)
  979. return 0;
  980. if (irq[i] == SNDRV_AUTO_IRQ ||
  981. mpu_irq[i] == SNDRV_AUTO_IRQ ||
  982. dma[i] == SNDRV_AUTO_DMA) {
  983. printk(KERN_INFO
  984. "sscape: insufficient parameters, "
  985. "need IO, IRQ, MPU-IRQ and DMA\n");
  986. return 0;
  987. }
  988. return 1;
  989. }
  990. static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
  991. {
  992. struct snd_card *card;
  993. struct soundscape *sscape;
  994. int ret;
  995. ret = snd_card_create(index[dev], id[dev], THIS_MODULE,
  996. sizeof(struct soundscape), &card);
  997. if (ret < 0)
  998. return ret;
  999. sscape = get_card_soundscape(card);
  1000. sscape->type = SSCAPE;
  1001. dma[dev] &= 0x03;
  1002. snd_card_set_dev(card, pdev);
  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 __devexit snd_sscape_remove(struct device *devptr, unsigned int dev)
  1018. {
  1019. snd_card_free(dev_get_drvdata(devptr));
  1020. dev_set_drvdata(devptr, NULL);
  1021. return 0;
  1022. }
  1023. #define DEV_NAME "sscape"
  1024. static struct isa_driver snd_sscape_driver = {
  1025. .match = snd_sscape_match,
  1026. .probe = snd_sscape_probe,
  1027. .remove = __devexit_p(snd_sscape_remove),
  1028. /* FIXME: suspend/resume */
  1029. .driver = {
  1030. .name = DEV_NAME
  1031. },
  1032. };
  1033. #ifdef CONFIG_PNP
  1034. static inline int __devinit get_next_autoindex(int i)
  1035. {
  1036. while (i < SNDRV_CARDS && port[i] != SNDRV_AUTO_PORT)
  1037. ++i;
  1038. return i;
  1039. }
  1040. static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
  1041. const struct pnp_card_device_id *pid)
  1042. {
  1043. static int idx = 0;
  1044. struct pnp_dev *dev;
  1045. struct snd_card *card;
  1046. struct soundscape *sscape;
  1047. int ret;
  1048. /*
  1049. * Allow this function to fail *quietly* if all the ISA PnP
  1050. * devices were configured using module parameters instead.
  1051. */
  1052. idx = get_next_autoindex(idx);
  1053. if (idx >= SNDRV_CARDS)
  1054. return -ENOSPC;
  1055. /*
  1056. * Check that we still have room for another sound card ...
  1057. */
  1058. dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  1059. if (!dev)
  1060. return -ENODEV;
  1061. if (!pnp_is_active(dev)) {
  1062. if (pnp_activate_dev(dev) < 0) {
  1063. snd_printk(KERN_INFO "sscape: device is inactive\n");
  1064. return -EBUSY;
  1065. }
  1066. }
  1067. /*
  1068. * Create a new ALSA sound card entry, in anticipation
  1069. * of detecting our hardware ...
  1070. */
  1071. ret = snd_card_create(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. snd_card_set_dev(card, &pcard->card->dev);
  1098. ret = create_sscape(idx, card);
  1099. if (ret < 0)
  1100. goto _release_card;
  1101. ret = snd_card_register(card);
  1102. if (ret < 0) {
  1103. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  1104. goto _release_card;
  1105. }
  1106. pnp_set_card_drvdata(pcard, card);
  1107. ++idx;
  1108. return 0;
  1109. _release_card:
  1110. snd_card_free(card);
  1111. return ret;
  1112. }
  1113. static void __devexit sscape_pnp_remove(struct pnp_card_link * pcard)
  1114. {
  1115. snd_card_free(pnp_get_card_drvdata(pcard));
  1116. pnp_set_card_drvdata(pcard, NULL);
  1117. }
  1118. static struct pnp_card_driver sscape_pnpc_driver = {
  1119. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1120. .name = "sscape",
  1121. .id_table = sscape_pnpids,
  1122. .probe = sscape_pnp_detect,
  1123. .remove = __devexit_p(sscape_pnp_remove),
  1124. };
  1125. #endif /* CONFIG_PNP */
  1126. static int __init sscape_init(void)
  1127. {
  1128. int err;
  1129. err = isa_register_driver(&snd_sscape_driver, SNDRV_CARDS);
  1130. #ifdef CONFIG_PNP
  1131. if (!err)
  1132. isa_registered = 1;
  1133. err = pnp_register_card_driver(&sscape_pnpc_driver);
  1134. if (!err)
  1135. pnp_registered = 1;
  1136. if (isa_registered)
  1137. err = 0;
  1138. #endif
  1139. return err;
  1140. }
  1141. static void __exit sscape_exit(void)
  1142. {
  1143. #ifdef CONFIG_PNP
  1144. if (pnp_registered)
  1145. pnp_unregister_card_driver(&sscape_pnpc_driver);
  1146. if (isa_registered)
  1147. #endif
  1148. isa_unregister_driver(&snd_sscape_driver);
  1149. }
  1150. module_init(sscape_init);
  1151. module_exit(sscape_exit);