aica.c 17 KB

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