aica.c 16 KB

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