aica.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. *
  4. * Copyright Adrian McMenamin 2005, 2006, 2007
  5. * <adrian@mcmen.demon.co.uk>
  6. * Requires firmware (BSD licenced) available from:
  7. * http://linuxdc.cvs.sourceforge.net/linuxdc/linux-sh-dc/sound/oss/aica/firmware/
  8. * or the maintainer
  9. */
  10. #include <linux/init.h>
  11. #include <linux/jiffies.h>
  12. #include <linux/slab.h>
  13. #include <linux/time.h>
  14. #include <linux/wait.h>
  15. #include <linux/module.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/firmware.h>
  18. #include <linux/timer.h>
  19. #include <linux/delay.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/io.h>
  22. #include <sound/core.h>
  23. #include <sound/control.h>
  24. #include <sound/pcm.h>
  25. #include <sound/initval.h>
  26. #include <sound/info.h>
  27. #include <asm/dma.h>
  28. #include <mach/sysasic.h>
  29. #include "aica.h"
  30. MODULE_AUTHOR("Adrian McMenamin <adrian@mcmen.demon.co.uk>");
  31. MODULE_DESCRIPTION("Dreamcast AICA sound (pcm) driver");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("{{Yamaha/SEGA, AICA}}");
  34. MODULE_FIRMWARE("aica_firmware.bin");
  35. /* module parameters */
  36. #define CARD_NAME "AICA"
  37. static int index = -1;
  38. static char *id;
  39. static bool enable = 1;
  40. module_param(index, int, 0444);
  41. MODULE_PARM_DESC(index, "Index value for " CARD_NAME " soundcard.");
  42. module_param(id, charp, 0444);
  43. MODULE_PARM_DESC(id, "ID string for " CARD_NAME " soundcard.");
  44. module_param(enable, bool, 0644);
  45. MODULE_PARM_DESC(enable, "Enable " CARD_NAME " soundcard.");
  46. /* Simple platform device */
  47. static struct platform_device *pd;
  48. static struct resource aica_memory_space[2] = {
  49. {
  50. .name = "AICA ARM CONTROL",
  51. .start = ARM_RESET_REGISTER,
  52. .flags = IORESOURCE_MEM,
  53. .end = ARM_RESET_REGISTER + 3,
  54. },
  55. {
  56. .name = "AICA Sound RAM",
  57. .start = SPU_MEMORY_BASE,
  58. .flags = IORESOURCE_MEM,
  59. .end = SPU_MEMORY_BASE + 0x200000 - 1,
  60. },
  61. };
  62. /* SPU specific functions */
  63. /* spu_write_wait - wait for G2-SH FIFO to clear */
  64. static void spu_write_wait(void)
  65. {
  66. int time_count;
  67. time_count = 0;
  68. while (1) {
  69. if (!(readl(G2_FIFO) & 0x11))
  70. break;
  71. /* To ensure hardware failure doesn't wedge kernel */
  72. time_count++;
  73. if (time_count > 0x10000) {
  74. snd_printk
  75. ("WARNING: G2 FIFO appears to be blocked.\n");
  76. break;
  77. }
  78. }
  79. }
  80. /* spu_memset - write to memory in SPU address space */
  81. static void spu_memset(u32 toi, u32 what, int length)
  82. {
  83. int i;
  84. unsigned long flags;
  85. if (snd_BUG_ON(length % 4))
  86. return;
  87. for (i = 0; i < length; i++) {
  88. if (!(i % 8))
  89. spu_write_wait();
  90. local_irq_save(flags);
  91. writel(what, toi + SPU_MEMORY_BASE);
  92. local_irq_restore(flags);
  93. toi++;
  94. }
  95. }
  96. /* spu_memload - write to SPU address space */
  97. static void spu_memload(u32 toi, const void *from, int length)
  98. {
  99. unsigned long flags;
  100. const u32 *froml = from;
  101. u32 __iomem *to = (u32 __iomem *) (SPU_MEMORY_BASE + toi);
  102. int i;
  103. u32 val;
  104. length = DIV_ROUND_UP(length, 4);
  105. spu_write_wait();
  106. for (i = 0; i < length; i++) {
  107. if (!(i % 8))
  108. spu_write_wait();
  109. val = *froml;
  110. local_irq_save(flags);
  111. writel(val, to);
  112. local_irq_restore(flags);
  113. froml++;
  114. to++;
  115. }
  116. }
  117. /* spu_disable - set spu registers to stop sound output */
  118. static void spu_disable(void)
  119. {
  120. int i;
  121. unsigned long flags;
  122. u32 regval;
  123. spu_write_wait();
  124. regval = readl(ARM_RESET_REGISTER);
  125. regval |= 1;
  126. spu_write_wait();
  127. local_irq_save(flags);
  128. writel(regval, ARM_RESET_REGISTER);
  129. local_irq_restore(flags);
  130. for (i = 0; i < 64; i++) {
  131. spu_write_wait();
  132. regval = readl(SPU_REGISTER_BASE + (i * 0x80));
  133. regval = (regval & ~0x4000) | 0x8000;
  134. spu_write_wait();
  135. local_irq_save(flags);
  136. writel(regval, SPU_REGISTER_BASE + (i * 0x80));
  137. local_irq_restore(flags);
  138. }
  139. }
  140. /* spu_enable - set spu registers to enable sound output */
  141. static void spu_enable(void)
  142. {
  143. unsigned long flags;
  144. u32 regval = readl(ARM_RESET_REGISTER);
  145. regval &= ~1;
  146. spu_write_wait();
  147. local_irq_save(flags);
  148. writel(regval, ARM_RESET_REGISTER);
  149. local_irq_restore(flags);
  150. }
  151. /*
  152. * Halt the sound processor, clear the memory,
  153. * load some default ARM7 code, and then restart ARM7
  154. */
  155. static void spu_reset(void)
  156. {
  157. unsigned long flags;
  158. spu_disable();
  159. spu_memset(0, 0, 0x200000 / 4);
  160. /* Put ARM7 in endless loop */
  161. local_irq_save(flags);
  162. __raw_writel(0xea000002, SPU_MEMORY_BASE);
  163. local_irq_restore(flags);
  164. spu_enable();
  165. }
  166. /* aica_chn_start - write to spu to start playback */
  167. static void aica_chn_start(void)
  168. {
  169. unsigned long flags;
  170. spu_write_wait();
  171. local_irq_save(flags);
  172. writel(AICA_CMD_KICK | AICA_CMD_START, (u32 *) AICA_CONTROL_POINT);
  173. local_irq_restore(flags);
  174. }
  175. /* aica_chn_halt - write to spu to halt playback */
  176. static void aica_chn_halt(void)
  177. {
  178. unsigned long flags;
  179. spu_write_wait();
  180. local_irq_save(flags);
  181. writel(AICA_CMD_KICK | AICA_CMD_STOP, (u32 *) AICA_CONTROL_POINT);
  182. local_irq_restore(flags);
  183. }
  184. /* ALSA code below */
  185. static const struct snd_pcm_hardware snd_pcm_aica_playback_hw = {
  186. .info = (SNDRV_PCM_INFO_NONINTERLEAVED),
  187. .formats =
  188. (SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_S16_LE |
  189. SNDRV_PCM_FMTBIT_IMA_ADPCM),
  190. .rates = SNDRV_PCM_RATE_8000_48000,
  191. .rate_min = 8000,
  192. .rate_max = 48000,
  193. .channels_min = 1,
  194. .channels_max = 2,
  195. .buffer_bytes_max = AICA_BUFFER_SIZE,
  196. .period_bytes_min = AICA_PERIOD_SIZE,
  197. .period_bytes_max = AICA_PERIOD_SIZE,
  198. .periods_min = AICA_PERIOD_NUMBER,
  199. .periods_max = AICA_PERIOD_NUMBER,
  200. };
  201. static int aica_dma_transfer(int channels, int buffer_size,
  202. struct snd_pcm_substream *substream)
  203. {
  204. int q, err, period_offset;
  205. struct snd_card_aica *dreamcastcard;
  206. struct snd_pcm_runtime *runtime;
  207. unsigned long flags;
  208. err = 0;
  209. dreamcastcard = substream->pcm->private_data;
  210. period_offset = dreamcastcard->clicks;
  211. period_offset %= (AICA_PERIOD_NUMBER / channels);
  212. runtime = substream->runtime;
  213. for (q = 0; q < channels; q++) {
  214. local_irq_save(flags);
  215. err = dma_xfer(AICA_DMA_CHANNEL,
  216. (unsigned long) (runtime->dma_area +
  217. (AICA_BUFFER_SIZE * q) /
  218. channels +
  219. AICA_PERIOD_SIZE *
  220. period_offset),
  221. AICA_CHANNEL0_OFFSET + q * CHANNEL_OFFSET +
  222. AICA_PERIOD_SIZE * period_offset,
  223. buffer_size / channels, AICA_DMA_MODE);
  224. if (unlikely(err < 0)) {
  225. local_irq_restore(flags);
  226. break;
  227. }
  228. dma_wait_for_completion(AICA_DMA_CHANNEL);
  229. local_irq_restore(flags);
  230. }
  231. return err;
  232. }
  233. static void startup_aica(struct snd_card_aica *dreamcastcard)
  234. {
  235. spu_memload(AICA_CHANNEL0_CONTROL_OFFSET,
  236. dreamcastcard->channel, sizeof(struct aica_channel));
  237. aica_chn_start();
  238. }
  239. static void run_spu_dma(struct work_struct *work)
  240. {
  241. int buffer_size;
  242. struct snd_pcm_runtime *runtime;
  243. struct snd_card_aica *dreamcastcard;
  244. dreamcastcard =
  245. container_of(work, struct snd_card_aica, spu_dma_work);
  246. runtime = dreamcastcard->substream->runtime;
  247. if (unlikely(dreamcastcard->dma_check == 0)) {
  248. buffer_size =
  249. frames_to_bytes(runtime, runtime->buffer_size);
  250. if (runtime->channels > 1)
  251. dreamcastcard->channel->flags |= 0x01;
  252. aica_dma_transfer(runtime->channels, buffer_size,
  253. dreamcastcard->substream);
  254. startup_aica(dreamcastcard);
  255. dreamcastcard->clicks =
  256. buffer_size / (AICA_PERIOD_SIZE * runtime->channels);
  257. return;
  258. } else {
  259. aica_dma_transfer(runtime->channels,
  260. AICA_PERIOD_SIZE * runtime->channels,
  261. dreamcastcard->substream);
  262. snd_pcm_period_elapsed(dreamcastcard->substream);
  263. dreamcastcard->clicks++;
  264. if (unlikely(dreamcastcard->clicks >= AICA_PERIOD_NUMBER))
  265. dreamcastcard->clicks %= AICA_PERIOD_NUMBER;
  266. mod_timer(&dreamcastcard->timer, jiffies + 1);
  267. }
  268. }
  269. static void aica_period_elapsed(struct timer_list *t)
  270. {
  271. struct snd_card_aica *dreamcastcard = from_timer(dreamcastcard,
  272. t, timer);
  273. struct snd_pcm_substream *substream = dreamcastcard->substream;
  274. /*timer function - so cannot sleep */
  275. int play_period;
  276. struct snd_pcm_runtime *runtime;
  277. runtime = substream->runtime;
  278. dreamcastcard = substream->pcm->private_data;
  279. /* Have we played out an additional period? */
  280. play_period =
  281. frames_to_bytes(runtime,
  282. readl
  283. (AICA_CONTROL_CHANNEL_SAMPLE_NUMBER)) /
  284. AICA_PERIOD_SIZE;
  285. if (play_period == dreamcastcard->current_period) {
  286. /* reschedule the timer */
  287. mod_timer(&(dreamcastcard->timer), jiffies + 1);
  288. return;
  289. }
  290. if (runtime->channels > 1)
  291. dreamcastcard->current_period = play_period;
  292. if (unlikely(dreamcastcard->dma_check == 0))
  293. dreamcastcard->dma_check = 1;
  294. schedule_work(&(dreamcastcard->spu_dma_work));
  295. }
  296. static void spu_begin_dma(struct snd_pcm_substream *substream)
  297. {
  298. struct snd_card_aica *dreamcastcard;
  299. struct snd_pcm_runtime *runtime;
  300. runtime = substream->runtime;
  301. dreamcastcard = substream->pcm->private_data;
  302. /*get the queue to do the work */
  303. schedule_work(&(dreamcastcard->spu_dma_work));
  304. mod_timer(&dreamcastcard->timer, jiffies + 4);
  305. }
  306. static int snd_aicapcm_pcm_open(struct snd_pcm_substream
  307. *substream)
  308. {
  309. struct snd_pcm_runtime *runtime;
  310. struct aica_channel *channel;
  311. struct snd_card_aica *dreamcastcard;
  312. if (!enable)
  313. return -ENOENT;
  314. dreamcastcard = substream->pcm->private_data;
  315. channel = kmalloc(sizeof(struct aica_channel), GFP_KERNEL);
  316. if (!channel)
  317. return -ENOMEM;
  318. /* set defaults for channel */
  319. channel->sfmt = SM_8BIT;
  320. channel->cmd = AICA_CMD_START;
  321. channel->vol = dreamcastcard->master_volume;
  322. channel->pan = 0x80;
  323. channel->pos = 0;
  324. channel->flags = 0; /* default to mono */
  325. dreamcastcard->channel = channel;
  326. runtime = substream->runtime;
  327. runtime->hw = snd_pcm_aica_playback_hw;
  328. spu_enable();
  329. dreamcastcard->clicks = 0;
  330. dreamcastcard->current_period = 0;
  331. dreamcastcard->dma_check = 0;
  332. return 0;
  333. }
  334. static int snd_aicapcm_pcm_close(struct snd_pcm_substream
  335. *substream)
  336. {
  337. struct snd_card_aica *dreamcastcard = substream->pcm->private_data;
  338. flush_work(&(dreamcastcard->spu_dma_work));
  339. del_timer(&dreamcastcard->timer);
  340. dreamcastcard->substream = NULL;
  341. kfree(dreamcastcard->channel);
  342. spu_disable();
  343. return 0;
  344. }
  345. static int snd_aicapcm_pcm_prepare(struct snd_pcm_substream
  346. *substream)
  347. {
  348. struct snd_card_aica *dreamcastcard = substream->pcm->private_data;
  349. if ((substream->runtime)->format == SNDRV_PCM_FORMAT_S16_LE)
  350. dreamcastcard->channel->sfmt = SM_16BIT;
  351. dreamcastcard->channel->freq = substream->runtime->rate;
  352. dreamcastcard->substream = substream;
  353. return 0;
  354. }
  355. static int snd_aicapcm_pcm_trigger(struct snd_pcm_substream
  356. *substream, int cmd)
  357. {
  358. switch (cmd) {
  359. case SNDRV_PCM_TRIGGER_START:
  360. spu_begin_dma(substream);
  361. break;
  362. case SNDRV_PCM_TRIGGER_STOP:
  363. aica_chn_halt();
  364. break;
  365. default:
  366. return -EINVAL;
  367. }
  368. return 0;
  369. }
  370. static unsigned long snd_aicapcm_pcm_pointer(struct snd_pcm_substream
  371. *substream)
  372. {
  373. return readl(AICA_CONTROL_CHANNEL_SAMPLE_NUMBER);
  374. }
  375. static const struct snd_pcm_ops snd_aicapcm_playback_ops = {
  376. .open = snd_aicapcm_pcm_open,
  377. .close = snd_aicapcm_pcm_close,
  378. .prepare = snd_aicapcm_pcm_prepare,
  379. .trigger = snd_aicapcm_pcm_trigger,
  380. .pointer = snd_aicapcm_pcm_pointer,
  381. };
  382. /* TO DO: set up to handle more than one pcm instance */
  383. static int __init snd_aicapcmchip(struct snd_card_aica
  384. *dreamcastcard, int pcm_index)
  385. {
  386. struct snd_pcm *pcm;
  387. int err;
  388. /* AICA has no capture ability */
  389. err =
  390. snd_pcm_new(dreamcastcard->card, "AICA PCM", pcm_index, 1, 0,
  391. &pcm);
  392. if (unlikely(err < 0))
  393. return err;
  394. pcm->private_data = dreamcastcard;
  395. strcpy(pcm->name, "AICA PCM");
  396. snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
  397. &snd_aicapcm_playback_ops);
  398. /* Allocate the DMA buffers */
  399. snd_pcm_set_managed_buffer_all(pcm,
  400. SNDRV_DMA_TYPE_CONTINUOUS,
  401. NULL,
  402. AICA_BUFFER_SIZE,
  403. AICA_BUFFER_SIZE);
  404. return 0;
  405. }
  406. /* Mixer controls */
  407. #define aica_pcmswitch_info snd_ctl_boolean_mono_info
  408. static int aica_pcmswitch_get(struct snd_kcontrol *kcontrol,
  409. struct snd_ctl_elem_value *ucontrol)
  410. {
  411. ucontrol->value.integer.value[0] = 1; /* TO DO: Fix me */
  412. return 0;
  413. }
  414. static int aica_pcmswitch_put(struct snd_kcontrol *kcontrol,
  415. struct snd_ctl_elem_value *ucontrol)
  416. {
  417. if (ucontrol->value.integer.value[0] == 1)
  418. return 0; /* TO DO: Fix me */
  419. else
  420. aica_chn_halt();
  421. return 0;
  422. }
  423. static int aica_pcmvolume_info(struct snd_kcontrol *kcontrol,
  424. struct snd_ctl_elem_info *uinfo)
  425. {
  426. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  427. uinfo->count = 1;
  428. uinfo->value.integer.min = 0;
  429. uinfo->value.integer.max = 0xFF;
  430. return 0;
  431. }
  432. static int aica_pcmvolume_get(struct snd_kcontrol *kcontrol,
  433. struct snd_ctl_elem_value *ucontrol)
  434. {
  435. struct snd_card_aica *dreamcastcard;
  436. dreamcastcard = kcontrol->private_data;
  437. if (unlikely(!dreamcastcard->channel))
  438. return -ETXTBSY; /* we've not yet been set up */
  439. ucontrol->value.integer.value[0] = dreamcastcard->channel->vol;
  440. return 0;
  441. }
  442. static int aica_pcmvolume_put(struct snd_kcontrol *kcontrol,
  443. struct snd_ctl_elem_value *ucontrol)
  444. {
  445. struct snd_card_aica *dreamcastcard;
  446. unsigned int vol;
  447. dreamcastcard = kcontrol->private_data;
  448. if (unlikely(!dreamcastcard->channel))
  449. return -ETXTBSY;
  450. vol = ucontrol->value.integer.value[0];
  451. if (vol > 0xff)
  452. return -EINVAL;
  453. if (unlikely(dreamcastcard->channel->vol == vol))
  454. return 0;
  455. dreamcastcard->channel->vol = ucontrol->value.integer.value[0];
  456. dreamcastcard->master_volume = ucontrol->value.integer.value[0];
  457. spu_memload(AICA_CHANNEL0_CONTROL_OFFSET,
  458. dreamcastcard->channel, sizeof(struct aica_channel));
  459. return 1;
  460. }
  461. static const struct snd_kcontrol_new snd_aica_pcmswitch_control = {
  462. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  463. .name = "PCM Playback Switch",
  464. .index = 0,
  465. .info = aica_pcmswitch_info,
  466. .get = aica_pcmswitch_get,
  467. .put = aica_pcmswitch_put
  468. };
  469. static const struct snd_kcontrol_new snd_aica_pcmvolume_control = {
  470. .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
  471. .name = "PCM Playback Volume",
  472. .index = 0,
  473. .info = aica_pcmvolume_info,
  474. .get = aica_pcmvolume_get,
  475. .put = aica_pcmvolume_put
  476. };
  477. static int load_aica_firmware(void)
  478. {
  479. int err;
  480. const struct firmware *fw_entry;
  481. spu_reset();
  482. err = request_firmware(&fw_entry, "aica_firmware.bin", &pd->dev);
  483. if (unlikely(err))
  484. return err;
  485. /* write firmware into memory */
  486. spu_disable();
  487. spu_memload(0, fw_entry->data, fw_entry->size);
  488. spu_enable();
  489. release_firmware(fw_entry);
  490. return err;
  491. }
  492. static int add_aicamixer_controls(struct snd_card_aica *dreamcastcard)
  493. {
  494. int err;
  495. err = snd_ctl_add
  496. (dreamcastcard->card,
  497. snd_ctl_new1(&snd_aica_pcmvolume_control, dreamcastcard));
  498. if (unlikely(err < 0))
  499. return err;
  500. err = snd_ctl_add
  501. (dreamcastcard->card,
  502. snd_ctl_new1(&snd_aica_pcmswitch_control, dreamcastcard));
  503. if (unlikely(err < 0))
  504. return err;
  505. return 0;
  506. }
  507. static int snd_aica_remove(struct platform_device *devptr)
  508. {
  509. struct snd_card_aica *dreamcastcard;
  510. dreamcastcard = platform_get_drvdata(devptr);
  511. if (unlikely(!dreamcastcard))
  512. return -ENODEV;
  513. snd_card_free(dreamcastcard->card);
  514. kfree(dreamcastcard);
  515. return 0;
  516. }
  517. static int snd_aica_probe(struct platform_device *devptr)
  518. {
  519. int err;
  520. struct snd_card_aica *dreamcastcard;
  521. dreamcastcard = kzalloc(sizeof(struct snd_card_aica), GFP_KERNEL);
  522. if (unlikely(!dreamcastcard))
  523. return -ENOMEM;
  524. err = snd_card_new(&devptr->dev, index, SND_AICA_DRIVER,
  525. THIS_MODULE, 0, &dreamcastcard->card);
  526. if (unlikely(err < 0)) {
  527. kfree(dreamcastcard);
  528. return err;
  529. }
  530. strcpy(dreamcastcard->card->driver, "snd_aica");
  531. strcpy(dreamcastcard->card->shortname, SND_AICA_DRIVER);
  532. strcpy(dreamcastcard->card->longname,
  533. "Yamaha AICA Super Intelligent Sound Processor for SEGA Dreamcast");
  534. /* Prepare to use the queue */
  535. INIT_WORK(&(dreamcastcard->spu_dma_work), run_spu_dma);
  536. timer_setup(&dreamcastcard->timer, aica_period_elapsed, 0);
  537. /* Load the PCM 'chip' */
  538. err = snd_aicapcmchip(dreamcastcard, 0);
  539. if (unlikely(err < 0))
  540. goto freedreamcast;
  541. /* Add basic controls */
  542. err = add_aicamixer_controls(dreamcastcard);
  543. if (unlikely(err < 0))
  544. goto freedreamcast;
  545. /* Register the card with ALSA subsystem */
  546. err = snd_card_register(dreamcastcard->card);
  547. if (unlikely(err < 0))
  548. goto freedreamcast;
  549. platform_set_drvdata(devptr, dreamcastcard);
  550. snd_printk
  551. ("ALSA Driver for Yamaha AICA Super Intelligent Sound Processor\n");
  552. return 0;
  553. freedreamcast:
  554. snd_card_free(dreamcastcard->card);
  555. kfree(dreamcastcard);
  556. return err;
  557. }
  558. static struct platform_driver snd_aica_driver = {
  559. .probe = snd_aica_probe,
  560. .remove = snd_aica_remove,
  561. .driver = {
  562. .name = SND_AICA_DRIVER,
  563. },
  564. };
  565. static int __init aica_init(void)
  566. {
  567. int err;
  568. err = platform_driver_register(&snd_aica_driver);
  569. if (unlikely(err < 0))
  570. return err;
  571. pd = platform_device_register_simple(SND_AICA_DRIVER, -1,
  572. aica_memory_space, 2);
  573. if (IS_ERR(pd)) {
  574. platform_driver_unregister(&snd_aica_driver);
  575. return PTR_ERR(pd);
  576. }
  577. /* Load the firmware */
  578. return load_aica_firmware();
  579. }
  580. static void __exit aica_exit(void)
  581. {
  582. platform_device_unregister(pd);
  583. platform_driver_unregister(&snd_aica_driver);
  584. /* Kill any sound still playing and reset ARM7 to safe state */
  585. spu_reset();
  586. }
  587. module_init(aica_init);
  588. module_exit(aica_exit);