sscape.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  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] __devinitdata = SNDRV_DEFAULT_IDX;
  46. static char* id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_STR;
  47. static long port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
  48. static long wss_port[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PORT;
  49. static int irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
  50. static int mpu_irq[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_IRQ;
  51. static int dma[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
  52. static int dma2[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_DMA;
  53. static bool joystick[SNDRV_CARDS] __devinitdata;
  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, unsigned long size)
  139. {
  140. if (buf) {
  141. if (snd_dma_alloc_pages_fallback(SNDRV_DMA_TYPE_DEV, snd_dma_isa_data(),
  142. size, buf) < 0) {
  143. snd_printk(KERN_ERR "sscape: Failed to allocate "
  144. "%lu bytes for DMA\n",
  145. size);
  146. return NULL;
  147. }
  148. }
  149. return buf;
  150. }
  151. /*
  152. * Release the DMA-able kernel memory ...
  153. */
  154. static void free_dmabuf(struct snd_dma_buffer *buf)
  155. {
  156. if (buf && buf->area)
  157. snd_dma_free_pages(buf);
  158. }
  159. /*
  160. * This function writes to the SoundScape's control registers,
  161. * but doesn't do any locking. It's up to the caller to do that.
  162. * This is why this function is "unsafe" ...
  163. */
  164. static inline void sscape_write_unsafe(unsigned io_base, enum GA_REG reg, unsigned char val)
  165. {
  166. outb(reg, ODIE_ADDR_IO(io_base));
  167. outb(val, ODIE_DATA_IO(io_base));
  168. }
  169. /*
  170. * Write to the SoundScape's control registers, and do the
  171. * necessary locking ...
  172. */
  173. static void sscape_write(struct soundscape *s, enum GA_REG reg, 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, enum GA_REG reg)
  185. {
  186. outb(reg, ODIE_ADDR_IO(io_base));
  187. return inb(ODIE_DATA_IO(io_base));
  188. }
  189. /*
  190. * Puts the SoundScape into "host" mode, as compared to "MIDI" mode
  191. */
  192. static inline void set_host_mode_unsafe(unsigned io_base)
  193. {
  194. outb(0x0, HOST_CTRL_IO(io_base));
  195. }
  196. /*
  197. * Puts the SoundScape into "MIDI" mode, as compared to "host" mode
  198. */
  199. static inline void set_midi_mode_unsafe(unsigned io_base)
  200. {
  201. outb(0x3, HOST_CTRL_IO(io_base));
  202. }
  203. /*
  204. * Read the SoundScape's host-mode control register, but leave
  205. * any locking issues to the caller ...
  206. */
  207. static inline int host_read_unsafe(unsigned io_base)
  208. {
  209. int data = -1;
  210. if ((inb(HOST_CTRL_IO(io_base)) & RX_READY) != 0) {
  211. data = inb(HOST_DATA_IO(io_base));
  212. }
  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 inline void activate_ad1845_unsafe(unsigned io_base)
  279. {
  280. sscape_write_unsafe(io_base, GA_HMCTL_REG, (sscape_read_unsafe(io_base, GA_HMCTL_REG) & 0xcf) | 0x10);
  281. sscape_write_unsafe(io_base, GA_CDCFG_REG, 0x80);
  282. }
  283. /*
  284. * Do the necessary ALSA-level cleanup to deallocate our driver ...
  285. */
  286. static void soundscape_free(struct snd_card *c)
  287. {
  288. struct soundscape *sscape = get_card_soundscape(c);
  289. release_and_free_resource(sscape->io_res);
  290. release_and_free_resource(sscape->wss_res);
  291. free_dma(sscape->chip->dma1);
  292. }
  293. /*
  294. * Tell the SoundScape to begin a DMA tranfer using the given channel.
  295. * All locking issues are left to the caller.
  296. */
  297. static inline void sscape_start_dma_unsafe(unsigned io_base, enum GA_REG reg)
  298. {
  299. sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) | 0x01);
  300. sscape_write_unsafe(io_base, reg, sscape_read_unsafe(io_base, reg) & 0xfe);
  301. }
  302. /*
  303. * Wait for a DMA transfer to complete. This is a "limited busy-wait",
  304. * and all locking issues are left to the caller.
  305. */
  306. static int sscape_wait_dma_unsafe(unsigned io_base, enum GA_REG reg, unsigned timeout)
  307. {
  308. while (!(sscape_read_unsafe(io_base, reg) & 0x01) && (timeout != 0)) {
  309. udelay(100);
  310. --timeout;
  311. } /* while */
  312. return (sscape_read_unsafe(io_base, reg) & 0x01);
  313. }
  314. /*
  315. * Wait for the On-Board Processor to return its start-up
  316. * acknowledgement sequence. This wait is too long for
  317. * us to perform "busy-waiting", and so we must sleep.
  318. * This in turn means that we must not be holding any
  319. * spinlocks when we call this function.
  320. */
  321. static int obp_startup_ack(struct soundscape *s, unsigned timeout)
  322. {
  323. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  324. do {
  325. unsigned long flags;
  326. int x;
  327. spin_lock_irqsave(&s->lock, flags);
  328. x = host_read_unsafe(s->io_base);
  329. spin_unlock_irqrestore(&s->lock, flags);
  330. if (x == 0xfe || x == 0xff)
  331. return 1;
  332. msleep(10);
  333. } while (time_before(jiffies, end_time));
  334. return 0;
  335. }
  336. /*
  337. * Wait for the host to return its start-up acknowledgement
  338. * sequence. This wait is too long for us to perform
  339. * "busy-waiting", and so we must sleep. This in turn means
  340. * that we must not be holding any spinlocks when we call
  341. * this function.
  342. */
  343. static int host_startup_ack(struct soundscape *s, unsigned timeout)
  344. {
  345. unsigned long end_time = jiffies + msecs_to_jiffies(timeout);
  346. do {
  347. unsigned long flags;
  348. int x;
  349. spin_lock_irqsave(&s->lock, flags);
  350. x = host_read_unsafe(s->io_base);
  351. spin_unlock_irqrestore(&s->lock, flags);
  352. if (x == 0xfe)
  353. return 1;
  354. msleep(10);
  355. } while (time_before(jiffies, end_time));
  356. return 0;
  357. }
  358. /*
  359. * Upload a byte-stream into the SoundScape using DMA channel A.
  360. */
  361. static int upload_dma_data(struct soundscape *s,
  362. const unsigned char *data,
  363. size_t size)
  364. {
  365. unsigned long flags;
  366. struct snd_dma_buffer dma;
  367. int ret;
  368. if (!get_dmabuf(&dma, PAGE_ALIGN(32 * 1024)))
  369. return -ENOMEM;
  370. spin_lock_irqsave(&s->lock, flags);
  371. /*
  372. * Reset the board ...
  373. */
  374. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f);
  375. /*
  376. * Enable the DMA channels and configure them ...
  377. */
  378. sscape_write_unsafe(s->io_base, GA_DMAA_REG, (s->chip->dma1 << 4) | DMA_8BIT);
  379. sscape_write_unsafe(s->io_base, GA_DMAB_REG, 0x20);
  380. /*
  381. * Take the board out of reset ...
  382. */
  383. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x80);
  384. /*
  385. * Upload the firmware to the SoundScape
  386. * board through the DMA channel ...
  387. */
  388. while (size != 0) {
  389. unsigned long len;
  390. len = min(size, dma.bytes);
  391. memcpy(dma.area, data, len);
  392. data += len;
  393. size -= len;
  394. snd_dma_program(s->chip->dma1, dma.addr, len, DMA_MODE_WRITE);
  395. sscape_start_dma_unsafe(s->io_base, GA_DMAA_REG);
  396. if (!sscape_wait_dma_unsafe(s->io_base, GA_DMAA_REG, 5000)) {
  397. /*
  398. * Don't forget to release this spinlock we're holding ...
  399. */
  400. spin_unlock_irqrestore(&s->lock, flags);
  401. snd_printk(KERN_ERR
  402. "sscape: DMA upload has timed out\n");
  403. ret = -EAGAIN;
  404. goto _release_dma;
  405. }
  406. } /* while */
  407. set_host_mode_unsafe(s->io_base);
  408. outb(0x0, s->io_base);
  409. /*
  410. * Boot the board ... (I think)
  411. */
  412. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, sscape_read_unsafe(s->io_base, GA_HMCTL_REG) | 0x40);
  413. spin_unlock_irqrestore(&s->lock, flags);
  414. /*
  415. * If all has gone well, then the board should acknowledge
  416. * the new upload and tell us that it has rebooted OK. We
  417. * give it 5 seconds (max) ...
  418. */
  419. ret = 0;
  420. if (!obp_startup_ack(s, 5000)) {
  421. snd_printk(KERN_ERR "sscape: No response "
  422. "from on-board processor after upload\n");
  423. ret = -EAGAIN;
  424. } else if (!host_startup_ack(s, 5000)) {
  425. snd_printk(KERN_ERR
  426. "sscape: SoundScape failed to initialise\n");
  427. ret = -EAGAIN;
  428. }
  429. _release_dma:
  430. /*
  431. * NOTE!!! We are NOT holding any spinlocks at this point !!!
  432. */
  433. sscape_write(s, GA_DMAA_REG, (s->ic_type == IC_OPUS ? 0x40 : 0x70));
  434. free_dmabuf(&dma);
  435. return ret;
  436. }
  437. /*
  438. * Upload the bootblock(?) into the SoundScape. The only
  439. * purpose of this block of code seems to be to tell
  440. * us which version of the microcode we should be using.
  441. */
  442. static int sscape_upload_bootblock(struct snd_card *card)
  443. {
  444. struct soundscape *sscape = get_card_soundscape(card);
  445. unsigned long flags;
  446. const struct firmware *init_fw = NULL;
  447. int data = 0;
  448. int ret;
  449. ret = request_firmware(&init_fw, "scope.cod", card->dev);
  450. if (ret < 0) {
  451. snd_printk(KERN_ERR "sscape: Error loading scope.cod");
  452. return ret;
  453. }
  454. ret = upload_dma_data(sscape, init_fw->data, init_fw->size);
  455. release_firmware(init_fw);
  456. spin_lock_irqsave(&sscape->lock, flags);
  457. if (ret == 0)
  458. data = host_read_ctrl_unsafe(sscape->io_base, 100);
  459. if (data & 0x10)
  460. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2f);
  461. spin_unlock_irqrestore(&sscape->lock, flags);
  462. data &= 0xf;
  463. if (ret == 0 && data > 7) {
  464. snd_printk(KERN_ERR
  465. "sscape: timeout reading firmware version\n");
  466. ret = -EAGAIN;
  467. }
  468. return (ret == 0) ? data : ret;
  469. }
  470. /*
  471. * Upload the microcode into the SoundScape.
  472. */
  473. static int sscape_upload_microcode(struct snd_card *card, int version)
  474. {
  475. struct soundscape *sscape = get_card_soundscape(card);
  476. const struct firmware *init_fw = NULL;
  477. char name[14];
  478. int err;
  479. snprintf(name, sizeof(name), "sndscape.co%d", version);
  480. err = request_firmware(&init_fw, name, card->dev);
  481. if (err < 0) {
  482. snd_printk(KERN_ERR "sscape: Error loading sndscape.co%d",
  483. version);
  484. return err;
  485. }
  486. err = upload_dma_data(sscape, init_fw->data, init_fw->size);
  487. if (err == 0)
  488. snd_printk(KERN_INFO "sscape: MIDI firmware loaded %d KBs\n",
  489. init_fw->size >> 10);
  490. release_firmware(init_fw);
  491. return err;
  492. }
  493. /*
  494. * Mixer control for the SoundScape's MIDI device.
  495. */
  496. static int sscape_midi_info(struct snd_kcontrol *ctl,
  497. struct snd_ctl_elem_info *uinfo)
  498. {
  499. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  500. uinfo->count = 1;
  501. uinfo->value.integer.min = 0;
  502. uinfo->value.integer.max = 127;
  503. return 0;
  504. }
  505. static int sscape_midi_get(struct snd_kcontrol *kctl,
  506. struct snd_ctl_elem_value *uctl)
  507. {
  508. struct snd_wss *chip = snd_kcontrol_chip(kctl);
  509. struct snd_card *card = chip->card;
  510. register struct soundscape *s = get_card_soundscape(card);
  511. unsigned long flags;
  512. spin_lock_irqsave(&s->lock, flags);
  513. uctl->value.integer.value[0] = s->midi_vol;
  514. spin_unlock_irqrestore(&s->lock, flags);
  515. return 0;
  516. }
  517. static int sscape_midi_put(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. int change;
  525. spin_lock_irqsave(&s->lock, flags);
  526. /*
  527. * We need to put the board into HOST mode before we
  528. * can send any volume-changing HOST commands ...
  529. */
  530. set_host_mode_unsafe(s->io_base);
  531. /*
  532. * To successfully change the MIDI volume setting, you seem to
  533. * have to write a volume command, write the new volume value,
  534. * and then perform another volume-related command. Perhaps the
  535. * first command is an "open" and the second command is a "close"?
  536. */
  537. if (s->midi_vol == ((unsigned char) uctl->value.integer. value[0] & 127)) {
  538. change = 0;
  539. goto __skip_change;
  540. }
  541. change = (host_write_ctrl_unsafe(s->io_base, CMD_SET_MIDI_VOL, 100)
  542. && host_write_ctrl_unsafe(s->io_base, ((unsigned char) uctl->value.integer. value[0]) & 127, 100)
  543. && host_write_ctrl_unsafe(s->io_base, CMD_XXX_MIDI_VOL, 100));
  544. s->midi_vol = (unsigned char) uctl->value.integer.value[0] & 127;
  545. __skip_change:
  546. /*
  547. * Take the board out of HOST mode and back into MIDI mode ...
  548. */
  549. set_midi_mode_unsafe(s->io_base);
  550. spin_unlock_irqrestore(&s->lock, flags);
  551. return change;
  552. }
  553. static struct snd_kcontrol_new midi_mixer_ctl = {
  554. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  555. .name = "MIDI",
  556. .info = sscape_midi_info,
  557. .get = sscape_midi_get,
  558. .put = sscape_midi_put
  559. };
  560. /*
  561. * The SoundScape can use two IRQs from a possible set of four.
  562. * These IRQs are encoded as bit patterns so that they can be
  563. * written to the control registers.
  564. */
  565. static unsigned __devinit get_irq_config(int sscape_type, int irq)
  566. {
  567. static const int valid_irq[] = { 9, 5, 7, 10 };
  568. static const int old_irq[] = { 9, 7, 5, 15 };
  569. unsigned cfg;
  570. if (sscape_type == MEDIA_FX) {
  571. for (cfg = 0; cfg < ARRAY_SIZE(old_irq); ++cfg)
  572. if (irq == old_irq[cfg])
  573. return cfg;
  574. } else {
  575. for (cfg = 0; cfg < ARRAY_SIZE(valid_irq); ++cfg)
  576. if (irq == valid_irq[cfg])
  577. return cfg;
  578. }
  579. return INVALID_IRQ;
  580. }
  581. /*
  582. * Perform certain arcane port-checks to see whether there
  583. * is a SoundScape board lurking behind the given ports.
  584. */
  585. static int __devinit detect_sscape(struct soundscape *s, long wss_io)
  586. {
  587. unsigned long flags;
  588. unsigned d;
  589. int retval = 0;
  590. spin_lock_irqsave(&s->lock, flags);
  591. /*
  592. * The following code is lifted from the original OSS driver,
  593. * and as I don't have a datasheet I cannot really comment
  594. * on what it is doing...
  595. */
  596. if ((inb(HOST_CTRL_IO(s->io_base)) & 0x78) != 0)
  597. goto _done;
  598. d = inb(ODIE_ADDR_IO(s->io_base)) & 0xf0;
  599. if ((d & 0x80) != 0)
  600. goto _done;
  601. if (d == 0)
  602. s->ic_type = IC_ODIE;
  603. else if ((d & 0x60) != 0)
  604. s->ic_type = IC_OPUS;
  605. else
  606. goto _done;
  607. outb(0xfa, ODIE_ADDR_IO(s->io_base));
  608. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0a)
  609. goto _done;
  610. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  611. if ((inb(ODIE_ADDR_IO(s->io_base)) & 0x9f) != 0x0e)
  612. goto _done;
  613. outb(0xfe, ODIE_ADDR_IO(s->io_base));
  614. d = inb(ODIE_DATA_IO(s->io_base));
  615. if (s->type != SSCAPE_VIVO && (d & 0x9f) != 0x0e)
  616. goto _done;
  617. if (s->ic_type == IC_OPUS)
  618. activate_ad1845_unsafe(s->io_base);
  619. if (s->type == SSCAPE_VIVO)
  620. wss_io += 4;
  621. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  622. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
  623. /* wait for WSS codec */
  624. for (d = 0; d < 500; d++) {
  625. if ((inb(wss_io) & 0x80) == 0)
  626. break;
  627. spin_unlock_irqrestore(&s->lock, flags);
  628. msleep(1);
  629. spin_lock_irqsave(&s->lock, flags);
  630. }
  631. if ((inb(wss_io) & 0x80) != 0)
  632. goto _done;
  633. if (inb(wss_io + 2) == 0xff)
  634. goto _done;
  635. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  636. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d);
  637. if ((inb(wss_io) & 0x80) != 0)
  638. s->type = MEDIA_FX;
  639. d = sscape_read_unsafe(s->io_base, GA_HMCTL_REG) & 0x3f;
  640. sscape_write_unsafe(s->io_base, GA_HMCTL_REG, d | 0xc0);
  641. /* wait for WSS codec */
  642. for (d = 0; d < 500; d++) {
  643. if ((inb(wss_io) & 0x80) == 0)
  644. break;
  645. spin_unlock_irqrestore(&s->lock, flags);
  646. msleep(1);
  647. spin_lock_irqsave(&s->lock, flags);
  648. }
  649. /*
  650. * SoundScape successfully detected!
  651. */
  652. retval = 1;
  653. _done:
  654. spin_unlock_irqrestore(&s->lock, flags);
  655. return retval;
  656. }
  657. /*
  658. * ALSA callback function, called when attempting to open the MIDI device.
  659. * Check that the MIDI firmware has been loaded, because we don't want
  660. * to crash the machine. Also check that someone isn't using the hardware
  661. * IOCTL device.
  662. */
  663. static int mpu401_open(struct snd_mpu401 * mpu)
  664. {
  665. if (!verify_mpu401(mpu)) {
  666. snd_printk(KERN_ERR "sscape: MIDI disabled, "
  667. "please load firmware\n");
  668. return -ENODEV;
  669. }
  670. return 0;
  671. }
  672. /*
  673. * Initialse an MPU-401 subdevice for MIDI support on the SoundScape.
  674. */
  675. static int __devinit create_mpu401(struct snd_card *card, int devnum, unsigned long port, int irq)
  676. {
  677. struct soundscape *sscape = get_card_soundscape(card);
  678. struct snd_rawmidi *rawmidi;
  679. int err;
  680. if ((err = snd_mpu401_uart_new(card, devnum,
  681. MPU401_HW_MPU401,
  682. port, MPU401_INFO_INTEGRATED,
  683. irq, IRQF_DISABLED,
  684. &rawmidi)) == 0) {
  685. struct snd_mpu401 *mpu = (struct snd_mpu401 *) rawmidi->private_data;
  686. mpu->open_input = mpu401_open;
  687. mpu->open_output = mpu401_open;
  688. mpu->private_data = sscape;
  689. initialise_mpu401(mpu);
  690. }
  691. return err;
  692. }
  693. /*
  694. * Create an AD1845 PCM subdevice on the SoundScape. The AD1845
  695. * is very much like a CS4231, with a few extra bits. We will
  696. * try to support at least some of the extra bits by overriding
  697. * some of the CS4231 callback.
  698. */
  699. static int __devinit create_ad1845(struct snd_card *card, unsigned port,
  700. int irq, int dma1, int dma2)
  701. {
  702. register struct soundscape *sscape = get_card_soundscape(card);
  703. struct snd_wss *chip;
  704. int err;
  705. int codec_type = WSS_HW_DETECT;
  706. switch (sscape->type) {
  707. case MEDIA_FX:
  708. case SSCAPE:
  709. /*
  710. * There are some freak examples of early Soundscape cards
  711. * with CS4231 instead of AD1848/CS4248. Unfortunately, the
  712. * CS4231 works only in CS4248 compatibility mode on
  713. * these cards so force it.
  714. */
  715. if (sscape->ic_type != IC_OPUS)
  716. codec_type = WSS_HW_AD1848;
  717. break;
  718. case SSCAPE_VIVO:
  719. port += 4;
  720. break;
  721. default:
  722. break;
  723. }
  724. err = snd_wss_create(card, port, -1, irq, dma1, dma2,
  725. codec_type, WSS_HWSHARE_DMA1, &chip);
  726. if (!err) {
  727. unsigned long flags;
  728. struct snd_pcm *pcm;
  729. /*
  730. * It turns out that the PLAYBACK_ENABLE bit is set
  731. * by the lowlevel driver ...
  732. *
  733. #define AD1845_IFACE_CONFIG \
  734. (CS4231_AUTOCALIB | CS4231_RECORD_ENABLE | CS4231_PLAYBACK_ENABLE)
  735. snd_wss_mce_up(chip);
  736. spin_lock_irqsave(&chip->reg_lock, flags);
  737. snd_wss_out(chip, CS4231_IFACE_CTRL, AD1845_IFACE_CONFIG);
  738. spin_unlock_irqrestore(&chip->reg_lock, flags);
  739. snd_wss_mce_down(chip);
  740. */
  741. if (sscape->type != SSCAPE_VIVO) {
  742. /*
  743. * The input clock frequency on the SoundScape must
  744. * be 14.31818 MHz, because we must set this register
  745. * to get the playback to sound correct ...
  746. */
  747. snd_wss_mce_up(chip);
  748. spin_lock_irqsave(&chip->reg_lock, flags);
  749. snd_wss_out(chip, AD1845_CLOCK, 0x20);
  750. spin_unlock_irqrestore(&chip->reg_lock, flags);
  751. snd_wss_mce_down(chip);
  752. }
  753. err = snd_wss_pcm(chip, 0, &pcm);
  754. if (err < 0) {
  755. snd_printk(KERN_ERR "sscape: No PCM device "
  756. "for AD1845 chip\n");
  757. goto _error;
  758. }
  759. err = snd_wss_mixer(chip);
  760. if (err < 0) {
  761. snd_printk(KERN_ERR "sscape: No mixer device "
  762. "for AD1845 chip\n");
  763. goto _error;
  764. }
  765. if (chip->hardware != WSS_HW_AD1848) {
  766. err = snd_wss_timer(chip, 0, NULL);
  767. if (err < 0) {
  768. snd_printk(KERN_ERR "sscape: No timer device "
  769. "for AD1845 chip\n");
  770. goto _error;
  771. }
  772. }
  773. if (sscape->type != SSCAPE_VIVO) {
  774. err = snd_ctl_add(card,
  775. snd_ctl_new1(&midi_mixer_ctl, chip));
  776. if (err < 0) {
  777. snd_printk(KERN_ERR "sscape: Could not create "
  778. "MIDI mixer control\n");
  779. goto _error;
  780. }
  781. }
  782. sscape->chip = chip;
  783. }
  784. _error:
  785. return err;
  786. }
  787. /*
  788. * Create an ALSA soundcard entry for the SoundScape, using
  789. * the given list of port, IRQ and DMA resources.
  790. */
  791. static int __devinit create_sscape(int dev, struct snd_card *card)
  792. {
  793. struct soundscape *sscape = get_card_soundscape(card);
  794. unsigned dma_cfg;
  795. unsigned irq_cfg;
  796. unsigned mpu_irq_cfg;
  797. struct resource *io_res;
  798. struct resource *wss_res;
  799. unsigned long flags;
  800. int err;
  801. int val;
  802. const char *name;
  803. /*
  804. * Grab IO ports that we will need to probe so that we
  805. * can detect and control this hardware ...
  806. */
  807. io_res = request_region(port[dev], 8, "SoundScape");
  808. if (!io_res) {
  809. snd_printk(KERN_ERR
  810. "sscape: can't grab port 0x%lx\n", port[dev]);
  811. return -EBUSY;
  812. }
  813. wss_res = NULL;
  814. if (sscape->type == SSCAPE_VIVO) {
  815. wss_res = request_region(wss_port[dev], 4, "SoundScape");
  816. if (!wss_res) {
  817. snd_printk(KERN_ERR "sscape: can't grab port 0x%lx\n",
  818. wss_port[dev]);
  819. err = -EBUSY;
  820. goto _release_region;
  821. }
  822. }
  823. /*
  824. * Grab one DMA channel ...
  825. */
  826. err = request_dma(dma[dev], "SoundScape");
  827. if (err < 0) {
  828. snd_printk(KERN_ERR "sscape: can't grab DMA %d\n", dma[dev]);
  829. goto _release_region;
  830. }
  831. spin_lock_init(&sscape->lock);
  832. sscape->io_res = io_res;
  833. sscape->wss_res = wss_res;
  834. sscape->io_base = port[dev];
  835. if (!detect_sscape(sscape, wss_port[dev])) {
  836. printk(KERN_ERR "sscape: hardware not detected at 0x%x\n",
  837. sscape->io_base);
  838. err = -ENODEV;
  839. goto _release_dma;
  840. }
  841. switch (sscape->type) {
  842. case MEDIA_FX:
  843. name = "MediaFX/SoundFX";
  844. break;
  845. case SSCAPE:
  846. name = "Soundscape";
  847. break;
  848. case SSCAPE_PNP:
  849. name = "Soundscape PnP";
  850. break;
  851. case SSCAPE_VIVO:
  852. name = "Soundscape VIVO";
  853. break;
  854. default:
  855. name = "unknown Soundscape";
  856. break;
  857. }
  858. printk(KERN_INFO "sscape: %s card detected at 0x%x, using IRQ %d, DMA %d\n",
  859. name, sscape->io_base, irq[dev], dma[dev]);
  860. /*
  861. * Check that the user didn't pass us garbage data ...
  862. */
  863. irq_cfg = get_irq_config(sscape->type, irq[dev]);
  864. if (irq_cfg == INVALID_IRQ) {
  865. snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", irq[dev]);
  866. return -ENXIO;
  867. }
  868. mpu_irq_cfg = get_irq_config(sscape->type, mpu_irq[dev]);
  869. if (mpu_irq_cfg == INVALID_IRQ) {
  870. snd_printk(KERN_ERR "sscape: Invalid IRQ %d\n", mpu_irq[dev]);
  871. return -ENXIO;
  872. }
  873. /*
  874. * Tell the on-board devices where their resources are (I think -
  875. * I can't be sure without a datasheet ... So many magic values!)
  876. */
  877. spin_lock_irqsave(&sscape->lock, flags);
  878. sscape_write_unsafe(sscape->io_base, GA_INTENA_REG, 0x00); /* disable */
  879. sscape_write_unsafe(sscape->io_base, GA_SMCFGA_REG, 0x2e);
  880. sscape_write_unsafe(sscape->io_base, GA_SMCFGB_REG, 0x00);
  881. /*
  882. * Enable and configure the DMA channels ...
  883. */
  884. sscape_write_unsafe(sscape->io_base, GA_DMACFG_REG, 0x50);
  885. dma_cfg = (sscape->ic_type == IC_OPUS ? 0x40 : 0x70);
  886. sscape_write_unsafe(sscape->io_base, GA_DMAA_REG, dma_cfg);
  887. sscape_write_unsafe(sscape->io_base, GA_DMAB_REG, 0x20);
  888. mpu_irq_cfg |= mpu_irq_cfg << 2;
  889. val = sscape_read_unsafe(sscape->io_base, GA_HMCTL_REG) & 0xF7;
  890. if (joystick[dev])
  891. val |= 8;
  892. sscape_write_unsafe(sscape->io_base, GA_HMCTL_REG, val | 0x10);
  893. sscape_write_unsafe(sscape->io_base, GA_INTCFG_REG, 0xf0 | mpu_irq_cfg);
  894. sscape_write_unsafe(sscape->io_base,
  895. GA_CDCFG_REG, 0x09 | DMA_8BIT
  896. | (dma[dev] << 4) | (irq_cfg << 1));
  897. spin_unlock_irqrestore(&sscape->lock, flags);
  898. /*
  899. * We have now enabled the codec chip, and so we should
  900. * detect the AD1845 device ...
  901. */
  902. err = create_ad1845(card, wss_port[dev], irq[dev],
  903. dma[dev], dma2[dev]);
  904. if (err < 0) {
  905. snd_printk(KERN_ERR
  906. "sscape: No AD1845 device at 0x%lx, IRQ %d\n",
  907. wss_port[dev], irq[dev]);
  908. goto _release_dma;
  909. }
  910. strcpy(card->driver, "SoundScape");
  911. strcpy(card->shortname, name);
  912. snprintf(card->longname, sizeof(card->longname),
  913. "%s at 0x%lx, IRQ %d, DMA1 %d, DMA2 %d\n",
  914. name, sscape->chip->port, sscape->chip->irq,
  915. sscape->chip->dma1, sscape->chip->dma2);
  916. #define MIDI_DEVNUM 0
  917. if (sscape->type != SSCAPE_VIVO) {
  918. err = sscape_upload_bootblock(card);
  919. if (err >= 0)
  920. err = sscape_upload_microcode(card, err);
  921. if (err == 0) {
  922. err = create_mpu401(card, MIDI_DEVNUM, port[dev],
  923. mpu_irq[dev]);
  924. if (err < 0) {
  925. snd_printk(KERN_ERR "sscape: Failed to create "
  926. "MPU-401 device at 0x%lx\n",
  927. port[dev]);
  928. goto _release_dma;
  929. }
  930. /*
  931. * Enable the master IRQ ...
  932. */
  933. sscape_write(sscape, GA_INTENA_REG, 0x80);
  934. /*
  935. * Initialize mixer
  936. */
  937. spin_lock_irqsave(&sscape->lock, flags);
  938. sscape->midi_vol = 0;
  939. host_write_ctrl_unsafe(sscape->io_base,
  940. CMD_SET_MIDI_VOL, 100);
  941. host_write_ctrl_unsafe(sscape->io_base,
  942. sscape->midi_vol, 100);
  943. host_write_ctrl_unsafe(sscape->io_base,
  944. CMD_XXX_MIDI_VOL, 100);
  945. host_write_ctrl_unsafe(sscape->io_base,
  946. sscape->midi_vol, 100);
  947. host_write_ctrl_unsafe(sscape->io_base,
  948. CMD_SET_EXTMIDI, 100);
  949. host_write_ctrl_unsafe(sscape->io_base,
  950. 0, 100);
  951. host_write_ctrl_unsafe(sscape->io_base, CMD_ACK, 100);
  952. set_midi_mode_unsafe(sscape->io_base);
  953. spin_unlock_irqrestore(&sscape->lock, flags);
  954. }
  955. }
  956. /*
  957. * Now that we have successfully created this sound card,
  958. * it is safe to store the pointer.
  959. * NOTE: we only register the sound card's "destructor"
  960. * function now that our "constructor" has completed.
  961. */
  962. card->private_free = soundscape_free;
  963. return 0;
  964. _release_dma:
  965. free_dma(dma[dev]);
  966. _release_region:
  967. release_and_free_resource(wss_res);
  968. release_and_free_resource(io_res);
  969. return err;
  970. }
  971. static int __devinit snd_sscape_match(struct device *pdev, unsigned int i)
  972. {
  973. /*
  974. * Make sure we were given ALL of the other parameters.
  975. */
  976. if (port[i] == SNDRV_AUTO_PORT)
  977. return 0;
  978. if (irq[i] == SNDRV_AUTO_IRQ ||
  979. mpu_irq[i] == SNDRV_AUTO_IRQ ||
  980. dma[i] == SNDRV_AUTO_DMA) {
  981. printk(KERN_INFO
  982. "sscape: insufficient parameters, need IO, IRQ, MPU-IRQ and DMA\n");
  983. return 0;
  984. }
  985. return 1;
  986. }
  987. static int __devinit snd_sscape_probe(struct device *pdev, unsigned int dev)
  988. {
  989. struct snd_card *card;
  990. struct soundscape *sscape;
  991. int ret;
  992. ret = snd_card_create(index[dev], id[dev], THIS_MODULE,
  993. sizeof(struct soundscape), &card);
  994. if (ret < 0)
  995. return ret;
  996. sscape = get_card_soundscape(card);
  997. sscape->type = SSCAPE;
  998. dma[dev] &= 0x03;
  999. snd_card_set_dev(card, pdev);
  1000. ret = create_sscape(dev, card);
  1001. if (ret < 0)
  1002. goto _release_card;
  1003. if ((ret = snd_card_register(card)) < 0) {
  1004. snd_printk(KERN_ERR "sscape: Failed to register sound card\n");
  1005. goto _release_card;
  1006. }
  1007. dev_set_drvdata(pdev, card);
  1008. return 0;
  1009. _release_card:
  1010. snd_card_free(card);
  1011. return ret;
  1012. }
  1013. static int __devexit snd_sscape_remove(struct device *devptr, unsigned int dev)
  1014. {
  1015. snd_card_free(dev_get_drvdata(devptr));
  1016. dev_set_drvdata(devptr, NULL);
  1017. return 0;
  1018. }
  1019. #define DEV_NAME "sscape"
  1020. static struct isa_driver snd_sscape_driver = {
  1021. .match = snd_sscape_match,
  1022. .probe = snd_sscape_probe,
  1023. .remove = __devexit_p(snd_sscape_remove),
  1024. /* FIXME: suspend/resume */
  1025. .driver = {
  1026. .name = DEV_NAME
  1027. },
  1028. };
  1029. #ifdef CONFIG_PNP
  1030. static inline int __devinit get_next_autoindex(int i)
  1031. {
  1032. while (i < SNDRV_CARDS && port[i] != SNDRV_AUTO_PORT)
  1033. ++i;
  1034. return i;
  1035. }
  1036. static int __devinit sscape_pnp_detect(struct pnp_card_link *pcard,
  1037. const struct pnp_card_device_id *pid)
  1038. {
  1039. static int idx = 0;
  1040. struct pnp_dev *dev;
  1041. struct snd_card *card;
  1042. struct soundscape *sscape;
  1043. int ret;
  1044. /*
  1045. * Allow this function to fail *quietly* if all the ISA PnP
  1046. * devices were configured using module parameters instead.
  1047. */
  1048. if ((idx = get_next_autoindex(idx)) >= SNDRV_CARDS)
  1049. return -ENOSPC;
  1050. /*
  1051. * We have found a candidate ISA PnP card. Now we
  1052. * have to check that it has the devices that we
  1053. * expect it to have.
  1054. */
  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. if ((ret = snd_card_register(card)) < 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 __devexit 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 = __devexit_p(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);