sscape.c 32 KB

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