sscape.c 33 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358
  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_hw_array(port, long, ioport, NULL, 0444);
  60. MODULE_PARM_DESC(port, "Port # for SoundScape driver.");
  61. module_param_hw_array(wss_port, long, ioport, NULL, 0444);
  62. MODULE_PARM_DESC(wss_port, "WSS Port # for SoundScape driver.");
  63. module_param_hw_array(irq, int, irq, NULL, 0444);
  64. MODULE_PARM_DESC(irq, "IRQ # for SoundScape driver.");
  65. module_param_hw_array(mpu_irq, int, irq, NULL, 0444);
  66. MODULE_PARM_DESC(mpu_irq, "MPU401 IRQ # for SoundScape driver.");
  67. module_param_hw_array(dma, int, dma, NULL, 0444);
  68. MODULE_PARM_DESC(dma, "DMA # for SoundScape driver.");
  69. module_param_hw_array(dma2, int, dma, 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 const 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 %zu 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 const 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);