snd_ps3.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206
  1. /*
  2. * Audio support for PS3
  3. * Copyright (C) 2007 Sony Computer Entertainment Inc.
  4. * All rights reserved.
  5. * Copyright 2006, 2007 Sony Corporation
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; version 2 of the Licence.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/init.h>
  21. #include <linux/slab.h>
  22. #include <linux/io.h>
  23. #include <linux/interrupt.h>
  24. #include <sound/core.h>
  25. #include <sound/initval.h>
  26. #include <sound/pcm.h>
  27. #include <sound/asound.h>
  28. #include <sound/memalloc.h>
  29. #include <sound/pcm_params.h>
  30. #include <sound/control.h>
  31. #include <linux/dmapool.h>
  32. #include <linux/dma-mapping.h>
  33. #include <asm/firmware.h>
  34. #include <asm/dma.h>
  35. #include <asm/lv1call.h>
  36. #include <asm/ps3.h>
  37. #include <asm/ps3av.h>
  38. #include "snd_ps3_reg.h"
  39. #include "snd_ps3.h"
  40. MODULE_LICENSE("GPL v2");
  41. MODULE_DESCRIPTION("PS3 sound driver");
  42. MODULE_AUTHOR("Sony Computer Entertainment Inc.");
  43. /* module entries */
  44. static int __init snd_ps3_init(void);
  45. static void __exit snd_ps3_exit(void);
  46. /* ALSA snd driver ops */
  47. static int snd_ps3_pcm_open(struct snd_pcm_substream *substream);
  48. static int snd_ps3_pcm_close(struct snd_pcm_substream *substream);
  49. static int snd_ps3_pcm_prepare(struct snd_pcm_substream *substream);
  50. static int snd_ps3_pcm_trigger(struct snd_pcm_substream *substream,
  51. int cmd);
  52. static snd_pcm_uframes_t snd_ps3_pcm_pointer(struct snd_pcm_substream
  53. *substream);
  54. static int snd_ps3_pcm_hw_params(struct snd_pcm_substream *substream,
  55. struct snd_pcm_hw_params *hw_params);
  56. static int snd_ps3_pcm_hw_free(struct snd_pcm_substream *substream);
  57. /* ps3_system_bus_driver entries */
  58. static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev);
  59. static int snd_ps3_driver_remove(struct ps3_system_bus_device *dev);
  60. /* address setup */
  61. static int snd_ps3_map_mmio(void);
  62. static void snd_ps3_unmap_mmio(void);
  63. static int snd_ps3_allocate_irq(void);
  64. static void snd_ps3_free_irq(void);
  65. static void snd_ps3_audio_set_base_addr(uint64_t ioaddr_start);
  66. /* interrupt handler */
  67. static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id);
  68. /* set sampling rate/format */
  69. static int snd_ps3_set_avsetting(struct snd_pcm_substream *substream);
  70. /* take effect parameter change */
  71. static int snd_ps3_change_avsetting(struct snd_ps3_card_info *card);
  72. /* initialize avsetting and take it effect */
  73. static int snd_ps3_init_avsetting(struct snd_ps3_card_info *card);
  74. /* setup dma */
  75. static int snd_ps3_program_dma(struct snd_ps3_card_info *card,
  76. enum snd_ps3_dma_filltype filltype);
  77. static void snd_ps3_wait_for_dma_stop(struct snd_ps3_card_info *card);
  78. static dma_addr_t v_to_bus(struct snd_ps3_card_info *, void *vaddr, int ch);
  79. module_init(snd_ps3_init);
  80. module_exit(snd_ps3_exit);
  81. /*
  82. * global
  83. */
  84. static struct snd_ps3_card_info the_card;
  85. static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY;
  86. module_param_named(start_delay, snd_ps3_start_delay, uint, 0644);
  87. MODULE_PARM_DESC(start_delay, "time to insert silent data in milisec");
  88. static int index = SNDRV_DEFAULT_IDX1;
  89. static char *id = SNDRV_DEFAULT_STR1;
  90. module_param(index, int, 0444);
  91. MODULE_PARM_DESC(index, "Index value for PS3 soundchip.");
  92. module_param(id, charp, 0444);
  93. MODULE_PARM_DESC(id, "ID string for PS3 soundchip.");
  94. /*
  95. * PS3 audio register access
  96. */
  97. static inline u32 read_reg(unsigned int reg)
  98. {
  99. return in_be32(the_card.mapped_mmio_vaddr + reg);
  100. }
  101. static inline void write_reg(unsigned int reg, u32 val)
  102. {
  103. out_be32(the_card.mapped_mmio_vaddr + reg, val);
  104. }
  105. static inline void update_reg(unsigned int reg, u32 or_val)
  106. {
  107. u32 newval = read_reg(reg) | or_val;
  108. write_reg(reg, newval);
  109. }
  110. static inline void update_mask_reg(unsigned int reg, u32 mask, u32 or_val)
  111. {
  112. u32 newval = (read_reg(reg) & mask) | or_val;
  113. write_reg(reg, newval);
  114. }
  115. /*
  116. * ALSA defs
  117. */
  118. static const struct snd_pcm_hardware snd_ps3_pcm_hw = {
  119. .info = (SNDRV_PCM_INFO_MMAP |
  120. SNDRV_PCM_INFO_NONINTERLEAVED |
  121. SNDRV_PCM_INFO_MMAP_VALID),
  122. .formats = (SNDRV_PCM_FMTBIT_S16_BE |
  123. SNDRV_PCM_FMTBIT_S24_BE),
  124. .rates = (SNDRV_PCM_RATE_44100 |
  125. SNDRV_PCM_RATE_48000 |
  126. SNDRV_PCM_RATE_88200 |
  127. SNDRV_PCM_RATE_96000),
  128. .rate_min = 44100,
  129. .rate_max = 96000,
  130. .channels_min = 2, /* stereo only */
  131. .channels_max = 2,
  132. .buffer_bytes_max = PS3_AUDIO_FIFO_SIZE * 64,
  133. /* interrupt by four stages */
  134. .period_bytes_min = PS3_AUDIO_FIFO_STAGE_SIZE * 4,
  135. .period_bytes_max = PS3_AUDIO_FIFO_STAGE_SIZE * 4,
  136. .periods_min = 16,
  137. .periods_max = 32, /* buffer_size_max/ period_bytes_max */
  138. .fifo_size = PS3_AUDIO_FIFO_SIZE
  139. };
  140. static struct snd_pcm_ops snd_ps3_pcm_spdif_ops =
  141. {
  142. .open = snd_ps3_pcm_open,
  143. .close = snd_ps3_pcm_close,
  144. .prepare = snd_ps3_pcm_prepare,
  145. .ioctl = snd_pcm_lib_ioctl,
  146. .trigger = snd_ps3_pcm_trigger,
  147. .pointer = snd_ps3_pcm_pointer,
  148. .hw_params = snd_ps3_pcm_hw_params,
  149. .hw_free = snd_ps3_pcm_hw_free
  150. };
  151. static int snd_ps3_verify_dma_stop(struct snd_ps3_card_info *card,
  152. int count, int force_stop)
  153. {
  154. int dma_ch, done, retries, stop_forced = 0;
  155. uint32_t status;
  156. for (dma_ch = 0; dma_ch < 8; dma_ch ++) {
  157. retries = count;
  158. do {
  159. status = read_reg(PS3_AUDIO_KICK(dma_ch)) &
  160. PS3_AUDIO_KICK_STATUS_MASK;
  161. switch (status) {
  162. case PS3_AUDIO_KICK_STATUS_DONE:
  163. case PS3_AUDIO_KICK_STATUS_NOTIFY:
  164. case PS3_AUDIO_KICK_STATUS_CLEAR:
  165. case PS3_AUDIO_KICK_STATUS_ERROR:
  166. done = 1;
  167. break;
  168. default:
  169. done = 0;
  170. udelay(10);
  171. }
  172. } while (!done && --retries);
  173. if (!retries && force_stop) {
  174. pr_info("%s: DMA ch %d is not stopped.",
  175. __func__, dma_ch);
  176. /* last resort. force to stop dma.
  177. * NOTE: this cause DMA done interrupts
  178. */
  179. update_reg(PS3_AUDIO_CONFIG, PS3_AUDIO_CONFIG_CLEAR);
  180. stop_forced = 1;
  181. }
  182. }
  183. return stop_forced;
  184. }
  185. /*
  186. * wait for all dma is done.
  187. * NOTE: caller should reset card->running before call.
  188. * If not, the interrupt handler will re-start DMA,
  189. * then DMA is never stopped.
  190. */
  191. static void snd_ps3_wait_for_dma_stop(struct snd_ps3_card_info *card)
  192. {
  193. int stop_forced;
  194. /*
  195. * wait for the last dma is done
  196. */
  197. /*
  198. * expected maximum DMA done time is 5.7ms + something (DMA itself).
  199. * 5.7ms is from 16bit/sample 2ch 44.1Khz; the time next
  200. * DMA kick event would occur.
  201. */
  202. stop_forced = snd_ps3_verify_dma_stop(card, 700, 1);
  203. /*
  204. * clear outstanding interrupts.
  205. */
  206. update_reg(PS3_AUDIO_INTR_0, 0);
  207. update_reg(PS3_AUDIO_AX_IS, 0);
  208. /*
  209. *revert CLEAR bit since it will not reset automatically after DMA stop
  210. */
  211. if (stop_forced)
  212. update_mask_reg(PS3_AUDIO_CONFIG, ~PS3_AUDIO_CONFIG_CLEAR, 0);
  213. /* ensure the hardware sees changes */
  214. wmb();
  215. }
  216. static void snd_ps3_kick_dma(struct snd_ps3_card_info *card)
  217. {
  218. update_reg(PS3_AUDIO_KICK(0), PS3_AUDIO_KICK_REQUEST);
  219. /* ensure the hardware sees the change */
  220. wmb();
  221. }
  222. /*
  223. * convert virtual addr to ioif bus addr.
  224. */
  225. static dma_addr_t v_to_bus(struct snd_ps3_card_info *card,
  226. void * paddr,
  227. int ch)
  228. {
  229. return card->dma_start_bus_addr[ch] +
  230. (paddr - card->dma_start_vaddr[ch]);
  231. };
  232. /*
  233. * increment ring buffer pointer.
  234. * NOTE: caller must hold write spinlock
  235. */
  236. static void snd_ps3_bump_buffer(struct snd_ps3_card_info *card,
  237. enum snd_ps3_ch ch, size_t byte_count,
  238. int stage)
  239. {
  240. if (!stage)
  241. card->dma_last_transfer_vaddr[ch] =
  242. card->dma_next_transfer_vaddr[ch];
  243. card->dma_next_transfer_vaddr[ch] += byte_count;
  244. if ((card->dma_start_vaddr[ch] + (card->dma_buffer_size / 2)) <=
  245. card->dma_next_transfer_vaddr[ch]) {
  246. card->dma_next_transfer_vaddr[ch] = card->dma_start_vaddr[ch];
  247. }
  248. }
  249. /*
  250. * setup dmac to send data to audio and attenuate samples on the ring buffer
  251. */
  252. static int snd_ps3_program_dma(struct snd_ps3_card_info *card,
  253. enum snd_ps3_dma_filltype filltype)
  254. {
  255. /* this dmac does not support over 4G */
  256. uint32_t dma_addr;
  257. int fill_stages, dma_ch, stage;
  258. enum snd_ps3_ch ch;
  259. uint32_t ch0_kick_event = 0; /* initialize to mute gcc */
  260. void *start_vaddr;
  261. unsigned long irqsave;
  262. int silent = 0;
  263. switch (filltype) {
  264. case SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL:
  265. silent = 1;
  266. /* intentionally fall thru */
  267. case SND_PS3_DMA_FILLTYPE_FIRSTFILL:
  268. ch0_kick_event = PS3_AUDIO_KICK_EVENT_ALWAYS;
  269. break;
  270. case SND_PS3_DMA_FILLTYPE_SILENT_RUNNING:
  271. silent = 1;
  272. /* intentionally fall thru */
  273. case SND_PS3_DMA_FILLTYPE_RUNNING:
  274. ch0_kick_event = PS3_AUDIO_KICK_EVENT_SERIALOUT0_EMPTY;
  275. break;
  276. }
  277. snd_ps3_verify_dma_stop(card, 700, 0);
  278. fill_stages = 4;
  279. spin_lock_irqsave(&card->dma_lock, irqsave);
  280. for (ch = 0; ch < 2; ch++) {
  281. start_vaddr = card->dma_next_transfer_vaddr[0];
  282. for (stage = 0; stage < fill_stages; stage ++) {
  283. dma_ch = stage * 2 + ch;
  284. if (silent)
  285. dma_addr = card->null_buffer_start_dma_addr;
  286. else
  287. dma_addr =
  288. v_to_bus(card,
  289. card->dma_next_transfer_vaddr[ch],
  290. ch);
  291. write_reg(PS3_AUDIO_SOURCE(dma_ch),
  292. (PS3_AUDIO_SOURCE_TARGET_SYSTEM_MEMORY |
  293. dma_addr));
  294. /* dst: fixed to 3wire#0 */
  295. if (ch == 0)
  296. write_reg(PS3_AUDIO_DEST(dma_ch),
  297. (PS3_AUDIO_DEST_TARGET_AUDIOFIFO |
  298. PS3_AUDIO_AO_3W_LDATA(0)));
  299. else
  300. write_reg(PS3_AUDIO_DEST(dma_ch),
  301. (PS3_AUDIO_DEST_TARGET_AUDIOFIFO |
  302. PS3_AUDIO_AO_3W_RDATA(0)));
  303. /* count always 1 DMA block (1/2 stage = 128 bytes) */
  304. write_reg(PS3_AUDIO_DMASIZE(dma_ch), 0);
  305. /* bump pointer if needed */
  306. if (!silent)
  307. snd_ps3_bump_buffer(card, ch,
  308. PS3_AUDIO_DMAC_BLOCK_SIZE,
  309. stage);
  310. /* kick event */
  311. if (dma_ch == 0)
  312. write_reg(PS3_AUDIO_KICK(dma_ch),
  313. ch0_kick_event);
  314. else
  315. write_reg(PS3_AUDIO_KICK(dma_ch),
  316. PS3_AUDIO_KICK_EVENT_AUDIO_DMA(dma_ch
  317. - 1) |
  318. PS3_AUDIO_KICK_REQUEST);
  319. }
  320. }
  321. /* ensure the hardware sees the change */
  322. wmb();
  323. spin_unlock_irqrestore(&card->dma_lock, irqsave);
  324. return 0;
  325. }
  326. /*
  327. * audio mute on/off
  328. * mute_on : 0 output enabled
  329. * 1 mute
  330. */
  331. static int snd_ps3_mute(int mute_on)
  332. {
  333. return ps3av_audio_mute(mute_on);
  334. }
  335. /*
  336. * PCM operators
  337. */
  338. static int snd_ps3_pcm_open(struct snd_pcm_substream *substream)
  339. {
  340. struct snd_pcm_runtime *runtime = substream->runtime;
  341. struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream);
  342. int pcm_index;
  343. pcm_index = substream->pcm->device;
  344. /* to retrieve substream/runtime in interrupt handler */
  345. card->substream = substream;
  346. runtime->hw = snd_ps3_pcm_hw;
  347. card->start_delay = snd_ps3_start_delay;
  348. /* mute off */
  349. snd_ps3_mute(0); /* this function sleep */
  350. snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
  351. PS3_AUDIO_FIFO_STAGE_SIZE * 4 * 2);
  352. return 0;
  353. };
  354. static int snd_ps3_pcm_hw_params(struct snd_pcm_substream *substream,
  355. struct snd_pcm_hw_params *hw_params)
  356. {
  357. size_t size;
  358. /* alloc transport buffer */
  359. size = params_buffer_bytes(hw_params);
  360. snd_pcm_lib_malloc_pages(substream, size);
  361. return 0;
  362. };
  363. static int snd_ps3_delay_to_bytes(struct snd_pcm_substream *substream,
  364. unsigned int delay_ms)
  365. {
  366. int ret;
  367. int rate ;
  368. rate = substream->runtime->rate;
  369. ret = snd_pcm_format_size(substream->runtime->format,
  370. rate * delay_ms / 1000)
  371. * substream->runtime->channels;
  372. pr_debug(KERN_ERR "%s: time=%d rate=%d bytes=%ld, frames=%d, ret=%d\n",
  373. __func__,
  374. delay_ms,
  375. rate,
  376. snd_pcm_format_size(substream->runtime->format, rate),
  377. rate * delay_ms / 1000,
  378. ret);
  379. return ret;
  380. };
  381. static int snd_ps3_pcm_prepare(struct snd_pcm_substream *substream)
  382. {
  383. struct snd_pcm_runtime *runtime = substream->runtime;
  384. struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream);
  385. unsigned long irqsave;
  386. if (!snd_ps3_set_avsetting(substream)) {
  387. /* some parameter changed */
  388. write_reg(PS3_AUDIO_AX_IE,
  389. PS3_AUDIO_AX_IE_ASOBEIE(0) |
  390. PS3_AUDIO_AX_IE_ASOBUIE(0));
  391. /*
  392. * let SPDIF device re-lock with SPDIF signal,
  393. * start with some silence
  394. */
  395. card->silent = snd_ps3_delay_to_bytes(substream,
  396. card->start_delay) /
  397. (PS3_AUDIO_FIFO_STAGE_SIZE * 4); /* every 4 times */
  398. }
  399. /* restart ring buffer pointer */
  400. spin_lock_irqsave(&card->dma_lock, irqsave);
  401. {
  402. card->dma_buffer_size = runtime->dma_bytes;
  403. card->dma_last_transfer_vaddr[SND_PS3_CH_L] =
  404. card->dma_next_transfer_vaddr[SND_PS3_CH_L] =
  405. card->dma_start_vaddr[SND_PS3_CH_L] =
  406. runtime->dma_area;
  407. card->dma_start_bus_addr[SND_PS3_CH_L] = runtime->dma_addr;
  408. card->dma_last_transfer_vaddr[SND_PS3_CH_R] =
  409. card->dma_next_transfer_vaddr[SND_PS3_CH_R] =
  410. card->dma_start_vaddr[SND_PS3_CH_R] =
  411. runtime->dma_area + (runtime->dma_bytes / 2);
  412. card->dma_start_bus_addr[SND_PS3_CH_R] =
  413. runtime->dma_addr + (runtime->dma_bytes / 2);
  414. pr_debug("%s: vaddr=%p bus=%#llx\n", __func__,
  415. card->dma_start_vaddr[SND_PS3_CH_L],
  416. card->dma_start_bus_addr[SND_PS3_CH_L]);
  417. }
  418. spin_unlock_irqrestore(&card->dma_lock, irqsave);
  419. /* ensure the hardware sees the change */
  420. mb();
  421. return 0;
  422. };
  423. static int snd_ps3_pcm_trigger(struct snd_pcm_substream *substream,
  424. int cmd)
  425. {
  426. struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream);
  427. int ret = 0;
  428. switch (cmd) {
  429. case SNDRV_PCM_TRIGGER_START:
  430. /* clear outstanding interrupts */
  431. update_reg(PS3_AUDIO_AX_IS, 0);
  432. spin_lock(&card->dma_lock);
  433. {
  434. card->running = 1;
  435. }
  436. spin_unlock(&card->dma_lock);
  437. snd_ps3_program_dma(card,
  438. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  439. snd_ps3_kick_dma(card);
  440. while (read_reg(PS3_AUDIO_KICK(7)) &
  441. PS3_AUDIO_KICK_STATUS_MASK) {
  442. udelay(1);
  443. }
  444. snd_ps3_program_dma(card, SND_PS3_DMA_FILLTYPE_SILENT_RUNNING);
  445. snd_ps3_kick_dma(card);
  446. break;
  447. case SNDRV_PCM_TRIGGER_STOP:
  448. spin_lock(&card->dma_lock);
  449. {
  450. card->running = 0;
  451. }
  452. spin_unlock(&card->dma_lock);
  453. snd_ps3_wait_for_dma_stop(card);
  454. break;
  455. default:
  456. break;
  457. }
  458. return ret;
  459. };
  460. /*
  461. * report current pointer
  462. */
  463. static snd_pcm_uframes_t snd_ps3_pcm_pointer(
  464. struct snd_pcm_substream *substream)
  465. {
  466. struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream);
  467. size_t bytes;
  468. snd_pcm_uframes_t ret;
  469. spin_lock(&card->dma_lock);
  470. {
  471. bytes = (size_t)(card->dma_last_transfer_vaddr[SND_PS3_CH_L] -
  472. card->dma_start_vaddr[SND_PS3_CH_L]);
  473. }
  474. spin_unlock(&card->dma_lock);
  475. ret = bytes_to_frames(substream->runtime, bytes * 2);
  476. return ret;
  477. };
  478. static int snd_ps3_pcm_hw_free(struct snd_pcm_substream *substream)
  479. {
  480. int ret;
  481. ret = snd_pcm_lib_free_pages(substream);
  482. return ret;
  483. };
  484. static int snd_ps3_pcm_close(struct snd_pcm_substream *substream)
  485. {
  486. /* mute on */
  487. snd_ps3_mute(1);
  488. return 0;
  489. };
  490. static void snd_ps3_audio_fixup(struct snd_ps3_card_info *card)
  491. {
  492. /*
  493. * avsetting driver seems to never change the followings
  494. * so, init them here once
  495. */
  496. /* no dma interrupt needed */
  497. write_reg(PS3_AUDIO_INTR_EN_0, 0);
  498. /* use every 4 buffer empty interrupt */
  499. update_mask_reg(PS3_AUDIO_AX_IC,
  500. PS3_AUDIO_AX_IC_AASOIMD_MASK,
  501. PS3_AUDIO_AX_IC_AASOIMD_EVERY4);
  502. /* enable 3wire clocks */
  503. update_mask_reg(PS3_AUDIO_AO_3WMCTRL,
  504. ~(PS3_AUDIO_AO_3WMCTRL_ASOBCLKD_DISABLED |
  505. PS3_AUDIO_AO_3WMCTRL_ASOLRCKD_DISABLED),
  506. 0);
  507. update_reg(PS3_AUDIO_AO_3WMCTRL,
  508. PS3_AUDIO_AO_3WMCTRL_ASOPLRCK_DEFAULT);
  509. }
  510. /*
  511. * av setting
  512. * NOTE: calling this function may generate audio interrupt.
  513. */
  514. static int snd_ps3_change_avsetting(struct snd_ps3_card_info *card)
  515. {
  516. int ret, retries, i;
  517. pr_debug("%s: start\n", __func__);
  518. ret = ps3av_set_audio_mode(card->avs.avs_audio_ch,
  519. card->avs.avs_audio_rate,
  520. card->avs.avs_audio_width,
  521. card->avs.avs_audio_format,
  522. card->avs.avs_audio_source);
  523. /*
  524. * Reset the following unwanted settings:
  525. */
  526. /* disable all 3wire buffers */
  527. update_mask_reg(PS3_AUDIO_AO_3WMCTRL,
  528. ~(PS3_AUDIO_AO_3WMCTRL_ASOEN(0) |
  529. PS3_AUDIO_AO_3WMCTRL_ASOEN(1) |
  530. PS3_AUDIO_AO_3WMCTRL_ASOEN(2) |
  531. PS3_AUDIO_AO_3WMCTRL_ASOEN(3)),
  532. 0);
  533. wmb(); /* ensure the hardware sees the change */
  534. /* wait for actually stopped */
  535. retries = 1000;
  536. while ((read_reg(PS3_AUDIO_AO_3WMCTRL) &
  537. (PS3_AUDIO_AO_3WMCTRL_ASORUN(0) |
  538. PS3_AUDIO_AO_3WMCTRL_ASORUN(1) |
  539. PS3_AUDIO_AO_3WMCTRL_ASORUN(2) |
  540. PS3_AUDIO_AO_3WMCTRL_ASORUN(3))) &&
  541. --retries) {
  542. udelay(1);
  543. }
  544. /* reset buffer pointer */
  545. for (i = 0; i < 4; i++) {
  546. update_reg(PS3_AUDIO_AO_3WCTRL(i),
  547. PS3_AUDIO_AO_3WCTRL_ASOBRST_RESET);
  548. udelay(10);
  549. }
  550. wmb(); /* ensure the hardware actually start resetting */
  551. /* enable 3wire#0 buffer */
  552. update_reg(PS3_AUDIO_AO_3WMCTRL, PS3_AUDIO_AO_3WMCTRL_ASOEN(0));
  553. /* In 24bit mode,ALSA inserts a zero byte at first byte of per sample */
  554. update_mask_reg(PS3_AUDIO_AO_3WCTRL(0),
  555. ~PS3_AUDIO_AO_3WCTRL_ASODF,
  556. PS3_AUDIO_AO_3WCTRL_ASODF_LSB);
  557. update_mask_reg(PS3_AUDIO_AO_SPDCTRL(0),
  558. ~PS3_AUDIO_AO_SPDCTRL_SPODF,
  559. PS3_AUDIO_AO_SPDCTRL_SPODF_LSB);
  560. /* ensure all the setting above is written back to register */
  561. wmb();
  562. /* avsetting driver altered AX_IE, caller must reset it if you want */
  563. pr_debug("%s: end\n", __func__);
  564. return ret;
  565. }
  566. static int snd_ps3_init_avsetting(struct snd_ps3_card_info *card)
  567. {
  568. int ret;
  569. pr_debug("%s: start\n", __func__);
  570. card->avs.avs_audio_ch = PS3AV_CMD_AUDIO_NUM_OF_CH_2;
  571. card->avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K;
  572. card->avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16;
  573. card->avs.avs_audio_format = PS3AV_CMD_AUDIO_FORMAT_PCM;
  574. card->avs.avs_audio_source = PS3AV_CMD_AUDIO_SOURCE_SERIAL;
  575. memcpy(card->avs.avs_cs_info, ps3av_mode_cs_info, 8);
  576. ret = snd_ps3_change_avsetting(card);
  577. snd_ps3_audio_fixup(card);
  578. /* to start to generate SPDIF signal, fill data */
  579. snd_ps3_program_dma(card, SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  580. snd_ps3_kick_dma(card);
  581. pr_debug("%s: end\n", __func__);
  582. return ret;
  583. }
  584. /*
  585. * set sampling rate according to the substream
  586. */
  587. static int snd_ps3_set_avsetting(struct snd_pcm_substream *substream)
  588. {
  589. struct snd_ps3_card_info *card = snd_pcm_substream_chip(substream);
  590. struct snd_ps3_avsetting_info avs;
  591. int ret;
  592. avs = card->avs;
  593. pr_debug("%s: called freq=%d width=%d\n", __func__,
  594. substream->runtime->rate,
  595. snd_pcm_format_width(substream->runtime->format));
  596. pr_debug("%s: before freq=%d width=%d\n", __func__,
  597. card->avs.avs_audio_rate, card->avs.avs_audio_width);
  598. /* sample rate */
  599. switch (substream->runtime->rate) {
  600. case 44100:
  601. avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_44K;
  602. break;
  603. case 48000:
  604. avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_48K;
  605. break;
  606. case 88200:
  607. avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_88K;
  608. break;
  609. case 96000:
  610. avs.avs_audio_rate = PS3AV_CMD_AUDIO_FS_96K;
  611. break;
  612. default:
  613. pr_info("%s: invalid rate %d\n", __func__,
  614. substream->runtime->rate);
  615. return 1;
  616. }
  617. /* width */
  618. switch (snd_pcm_format_width(substream->runtime->format)) {
  619. case 16:
  620. avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_16;
  621. break;
  622. case 24:
  623. avs.avs_audio_width = PS3AV_CMD_AUDIO_WORD_BITS_24;
  624. break;
  625. default:
  626. pr_info("%s: invalid width %d\n", __func__,
  627. snd_pcm_format_width(substream->runtime->format));
  628. return 1;
  629. }
  630. memcpy(avs.avs_cs_info, ps3av_mode_cs_info, 8);
  631. if (memcmp(&card->avs, &avs, sizeof(avs))) {
  632. pr_debug("%s: after freq=%d width=%d\n", __func__,
  633. card->avs.avs_audio_rate, card->avs.avs_audio_width);
  634. card->avs = avs;
  635. snd_ps3_change_avsetting(card);
  636. ret = 0;
  637. } else
  638. ret = 1;
  639. /* check CS non-audio bit and mute accordingly */
  640. if (avs.avs_cs_info[0] & 0x02)
  641. ps3av_audio_mute_analog(1); /* mute if non-audio */
  642. else
  643. ps3av_audio_mute_analog(0);
  644. return ret;
  645. }
  646. /*
  647. * SPDIF status bits controls
  648. */
  649. static int snd_ps3_spdif_mask_info(struct snd_kcontrol *kcontrol,
  650. struct snd_ctl_elem_info *uinfo)
  651. {
  652. uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
  653. uinfo->count = 1;
  654. return 0;
  655. }
  656. /* FIXME: ps3av_set_audio_mode() assumes only consumer mode */
  657. static int snd_ps3_spdif_cmask_get(struct snd_kcontrol *kcontrol,
  658. struct snd_ctl_elem_value *ucontrol)
  659. {
  660. memset(ucontrol->value.iec958.status, 0xff, 8);
  661. return 0;
  662. }
  663. static int snd_ps3_spdif_pmask_get(struct snd_kcontrol *kcontrol,
  664. struct snd_ctl_elem_value *ucontrol)
  665. {
  666. return 0;
  667. }
  668. static int snd_ps3_spdif_default_get(struct snd_kcontrol *kcontrol,
  669. struct snd_ctl_elem_value *ucontrol)
  670. {
  671. memcpy(ucontrol->value.iec958.status, ps3av_mode_cs_info, 8);
  672. return 0;
  673. }
  674. static int snd_ps3_spdif_default_put(struct snd_kcontrol *kcontrol,
  675. struct snd_ctl_elem_value *ucontrol)
  676. {
  677. if (memcmp(ps3av_mode_cs_info, ucontrol->value.iec958.status, 8)) {
  678. memcpy(ps3av_mode_cs_info, ucontrol->value.iec958.status, 8);
  679. return 1;
  680. }
  681. return 0;
  682. }
  683. static struct snd_kcontrol_new spdif_ctls[] = {
  684. {
  685. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  686. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  687. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
  688. .info = snd_ps3_spdif_mask_info,
  689. .get = snd_ps3_spdif_cmask_get,
  690. },
  691. {
  692. .access = SNDRV_CTL_ELEM_ACCESS_READ,
  693. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  694. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,PRO_MASK),
  695. .info = snd_ps3_spdif_mask_info,
  696. .get = snd_ps3_spdif_pmask_get,
  697. },
  698. {
  699. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  700. .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
  701. .info = snd_ps3_spdif_mask_info,
  702. .get = snd_ps3_spdif_default_get,
  703. .put = snd_ps3_spdif_default_put,
  704. },
  705. };
  706. static int snd_ps3_map_mmio(void)
  707. {
  708. the_card.mapped_mmio_vaddr =
  709. ioremap(the_card.ps3_dev->m_region->bus_addr,
  710. the_card.ps3_dev->m_region->len);
  711. if (!the_card.mapped_mmio_vaddr) {
  712. pr_info("%s: ioremap 0 failed p=%#lx l=%#lx \n",
  713. __func__, the_card.ps3_dev->m_region->lpar_addr,
  714. the_card.ps3_dev->m_region->len);
  715. return -ENXIO;
  716. }
  717. return 0;
  718. };
  719. static void snd_ps3_unmap_mmio(void)
  720. {
  721. iounmap(the_card.mapped_mmio_vaddr);
  722. the_card.mapped_mmio_vaddr = NULL;
  723. }
  724. static int snd_ps3_allocate_irq(void)
  725. {
  726. int ret;
  727. u64 lpar_addr, lpar_size;
  728. u64 __iomem *mapped;
  729. /* FIXME: move this to device_init (H/W probe) */
  730. /* get irq outlet */
  731. ret = lv1_gpu_device_map(1, &lpar_addr, &lpar_size);
  732. if (ret) {
  733. pr_info("%s: device map 1 failed %d\n", __func__,
  734. ret);
  735. return -ENXIO;
  736. }
  737. mapped = ioremap(lpar_addr, lpar_size);
  738. if (!mapped) {
  739. pr_info("%s: ioremap 1 failed \n", __func__);
  740. return -ENXIO;
  741. }
  742. the_card.audio_irq_outlet = in_be64(mapped);
  743. iounmap(mapped);
  744. ret = lv1_gpu_device_unmap(1);
  745. if (ret)
  746. pr_info("%s: unmap 1 failed\n", __func__);
  747. /* irq */
  748. ret = ps3_irq_plug_setup(PS3_BINDING_CPU_ANY,
  749. the_card.audio_irq_outlet,
  750. &the_card.irq_no);
  751. if (ret) {
  752. pr_info("%s:ps3_alloc_irq failed (%d)\n", __func__, ret);
  753. return ret;
  754. }
  755. ret = request_irq(the_card.irq_no, snd_ps3_interrupt, IRQF_DISABLED,
  756. SND_PS3_DRIVER_NAME, &the_card);
  757. if (ret) {
  758. pr_info("%s: request_irq failed (%d)\n", __func__, ret);
  759. goto cleanup_irq;
  760. }
  761. return 0;
  762. cleanup_irq:
  763. ps3_irq_plug_destroy(the_card.irq_no);
  764. return ret;
  765. };
  766. static void snd_ps3_free_irq(void)
  767. {
  768. free_irq(the_card.irq_no, &the_card);
  769. ps3_irq_plug_destroy(the_card.irq_no);
  770. }
  771. static void snd_ps3_audio_set_base_addr(uint64_t ioaddr_start)
  772. {
  773. uint64_t val;
  774. int ret;
  775. val = (ioaddr_start & (0x0fUL << 32)) >> (32 - 20) |
  776. (0x03UL << 24) |
  777. (0x0fUL << 12) |
  778. (PS3_AUDIO_IOID);
  779. ret = lv1_gpu_attribute(0x100, 0x007, val, 0, 0);
  780. if (ret)
  781. pr_info("%s: gpu_attribute failed %d\n", __func__,
  782. ret);
  783. }
  784. static int __init snd_ps3_driver_probe(struct ps3_system_bus_device *dev)
  785. {
  786. int i, ret;
  787. u64 lpar_addr, lpar_size;
  788. BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1));
  789. BUG_ON(dev->match_id != PS3_MATCH_ID_SOUND);
  790. the_card.ps3_dev = dev;
  791. ret = ps3_open_hv_device(dev);
  792. if (ret)
  793. return -ENXIO;
  794. /* setup MMIO */
  795. ret = lv1_gpu_device_map(2, &lpar_addr, &lpar_size);
  796. if (ret) {
  797. pr_info("%s: device map 2 failed %d\n", __func__, ret);
  798. goto clean_open;
  799. }
  800. ps3_mmio_region_init(dev, dev->m_region, lpar_addr, lpar_size,
  801. PAGE_SHIFT);
  802. ret = snd_ps3_map_mmio();
  803. if (ret)
  804. goto clean_dev_map;
  805. /* setup DMA area */
  806. ps3_dma_region_init(dev, dev->d_region,
  807. PAGE_SHIFT, /* use system page size */
  808. 0, /* dma type; not used */
  809. NULL,
  810. _ALIGN_UP(SND_PS3_DMA_REGION_SIZE, PAGE_SIZE));
  811. dev->d_region->ioid = PS3_AUDIO_IOID;
  812. ret = ps3_dma_region_create(dev->d_region);
  813. if (ret) {
  814. pr_info("%s: region_create\n", __func__);
  815. goto clean_mmio;
  816. }
  817. snd_ps3_audio_set_base_addr(dev->d_region->bus_addr);
  818. /* CONFIG_SND_PS3_DEFAULT_START_DELAY */
  819. the_card.start_delay = snd_ps3_start_delay;
  820. /* irq */
  821. if (snd_ps3_allocate_irq()) {
  822. ret = -ENXIO;
  823. goto clean_dma_region;
  824. }
  825. /* create card instance */
  826. ret = snd_card_create(index, id, THIS_MODULE, 0, &the_card.card);
  827. if (ret < 0)
  828. goto clean_irq;
  829. strcpy(the_card.card->driver, "PS3");
  830. strcpy(the_card.card->shortname, "PS3");
  831. strcpy(the_card.card->longname, "PS3 sound");
  832. /* create control elements */
  833. for (i = 0; i < ARRAY_SIZE(spdif_ctls); i++) {
  834. ret = snd_ctl_add(the_card.card,
  835. snd_ctl_new1(&spdif_ctls[i], &the_card));
  836. if (ret < 0)
  837. goto clean_card;
  838. }
  839. /* create PCM devices instance */
  840. /* NOTE:this driver works assuming pcm:substream = 1:1 */
  841. ret = snd_pcm_new(the_card.card,
  842. "SPDIF",
  843. 0, /* instance index, will be stored pcm.device*/
  844. 1, /* output substream */
  845. 0, /* input substream */
  846. &(the_card.pcm));
  847. if (ret)
  848. goto clean_card;
  849. the_card.pcm->private_data = &the_card;
  850. strcpy(the_card.pcm->name, "SPDIF");
  851. /* set pcm ops */
  852. snd_pcm_set_ops(the_card.pcm, SNDRV_PCM_STREAM_PLAYBACK,
  853. &snd_ps3_pcm_spdif_ops);
  854. the_card.pcm->info_flags = SNDRV_PCM_INFO_NONINTERLEAVED;
  855. /* pre-alloc PCM DMA buffer*/
  856. ret = snd_pcm_lib_preallocate_pages_for_all(the_card.pcm,
  857. SNDRV_DMA_TYPE_DEV,
  858. &dev->core,
  859. SND_PS3_PCM_PREALLOC_SIZE,
  860. SND_PS3_PCM_PREALLOC_SIZE);
  861. if (ret < 0) {
  862. pr_info("%s: prealloc failed\n", __func__);
  863. goto clean_card;
  864. }
  865. /*
  866. * allocate null buffer
  867. * its size should be lager than PS3_AUDIO_FIFO_STAGE_SIZE * 2
  868. * PAGE_SIZE is enogh
  869. */
  870. if (!(the_card.null_buffer_start_vaddr =
  871. dma_alloc_coherent(&the_card.ps3_dev->core,
  872. PAGE_SIZE,
  873. &the_card.null_buffer_start_dma_addr,
  874. GFP_KERNEL))) {
  875. pr_info("%s: nullbuffer alloc failed\n", __func__);
  876. goto clean_preallocate;
  877. }
  878. pr_debug("%s: null vaddr=%p dma=%#llx\n", __func__,
  879. the_card.null_buffer_start_vaddr,
  880. the_card.null_buffer_start_dma_addr);
  881. /* set default sample rate/word width */
  882. snd_ps3_init_avsetting(&the_card);
  883. /* register the card */
  884. snd_card_set_dev(the_card.card, &dev->core);
  885. ret = snd_card_register(the_card.card);
  886. if (ret < 0)
  887. goto clean_dma_map;
  888. pr_info("%s started. start_delay=%dms\n",
  889. the_card.card->longname, the_card.start_delay);
  890. return 0;
  891. clean_dma_map:
  892. dma_free_coherent(&the_card.ps3_dev->core,
  893. PAGE_SIZE,
  894. the_card.null_buffer_start_vaddr,
  895. the_card.null_buffer_start_dma_addr);
  896. clean_preallocate:
  897. snd_pcm_lib_preallocate_free_for_all(the_card.pcm);
  898. clean_card:
  899. snd_card_free(the_card.card);
  900. clean_irq:
  901. snd_ps3_free_irq();
  902. clean_dma_region:
  903. ps3_dma_region_free(dev->d_region);
  904. clean_mmio:
  905. snd_ps3_unmap_mmio();
  906. clean_dev_map:
  907. lv1_gpu_device_unmap(2);
  908. clean_open:
  909. ps3_close_hv_device(dev);
  910. /*
  911. * there is no destructor function to pcm.
  912. * midlayer automatically releases if the card removed
  913. */
  914. return ret;
  915. }; /* snd_ps3_probe */
  916. /* called when module removal */
  917. static int snd_ps3_driver_remove(struct ps3_system_bus_device *dev)
  918. {
  919. int ret;
  920. pr_info("%s:start id=%d\n", __func__, dev->match_id);
  921. if (dev->match_id != PS3_MATCH_ID_SOUND)
  922. return -ENXIO;
  923. /*
  924. * ctl and preallocate buffer will be freed in
  925. * snd_card_free
  926. */
  927. ret = snd_card_free(the_card.card);
  928. if (ret)
  929. pr_info("%s: ctl freecard=%d\n", __func__, ret);
  930. dma_free_coherent(&dev->core,
  931. PAGE_SIZE,
  932. the_card.null_buffer_start_vaddr,
  933. the_card.null_buffer_start_dma_addr);
  934. ps3_dma_region_free(dev->d_region);
  935. snd_ps3_free_irq();
  936. snd_ps3_unmap_mmio();
  937. lv1_gpu_device_unmap(2);
  938. ps3_close_hv_device(dev);
  939. pr_info("%s:end id=%d\n", __func__, dev->match_id);
  940. return 0;
  941. } /* snd_ps3_remove */
  942. static struct ps3_system_bus_driver snd_ps3_bus_driver_info = {
  943. .match_id = PS3_MATCH_ID_SOUND,
  944. .probe = snd_ps3_driver_probe,
  945. .remove = snd_ps3_driver_remove,
  946. .shutdown = snd_ps3_driver_remove,
  947. .core = {
  948. .name = SND_PS3_DRIVER_NAME,
  949. .owner = THIS_MODULE,
  950. },
  951. };
  952. /*
  953. * Interrupt handler
  954. */
  955. static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id)
  956. {
  957. uint32_t port_intr;
  958. int underflow_occured = 0;
  959. struct snd_ps3_card_info *card = dev_id;
  960. if (!card->running) {
  961. update_reg(PS3_AUDIO_AX_IS, 0);
  962. update_reg(PS3_AUDIO_INTR_0, 0);
  963. return IRQ_HANDLED;
  964. }
  965. port_intr = read_reg(PS3_AUDIO_AX_IS);
  966. /*
  967. *serial buffer empty detected (every 4 times),
  968. *program next dma and kick it
  969. */
  970. if (port_intr & PS3_AUDIO_AX_IE_ASOBEIE(0)) {
  971. write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBEIE(0));
  972. if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) {
  973. write_reg(PS3_AUDIO_AX_IS, port_intr);
  974. underflow_occured = 1;
  975. }
  976. if (card->silent) {
  977. /* we are still in silent time */
  978. snd_ps3_program_dma(card,
  979. (underflow_occured) ?
  980. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL :
  981. SND_PS3_DMA_FILLTYPE_SILENT_RUNNING);
  982. snd_ps3_kick_dma(card);
  983. card->silent --;
  984. } else {
  985. snd_ps3_program_dma(card,
  986. (underflow_occured) ?
  987. SND_PS3_DMA_FILLTYPE_FIRSTFILL :
  988. SND_PS3_DMA_FILLTYPE_RUNNING);
  989. snd_ps3_kick_dma(card);
  990. snd_pcm_period_elapsed(card->substream);
  991. }
  992. } else if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) {
  993. write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBUIE(0));
  994. /*
  995. * serial out underflow, but buffer empty not detected.
  996. * in this case, fill fifo with 0 to recover. After
  997. * filling dummy data, serial automatically start to
  998. * consume them and then will generate normal buffer
  999. * empty interrupts.
  1000. * If both buffer underflow and buffer empty are occured,
  1001. * it is better to do nomal data transfer than empty one
  1002. */
  1003. snd_ps3_program_dma(card,
  1004. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  1005. snd_ps3_kick_dma(card);
  1006. snd_ps3_program_dma(card,
  1007. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  1008. snd_ps3_kick_dma(card);
  1009. }
  1010. /* clear interrupt cause */
  1011. return IRQ_HANDLED;
  1012. };
  1013. /*
  1014. * module/subsystem initialize/terminate
  1015. */
  1016. static int __init snd_ps3_init(void)
  1017. {
  1018. int ret;
  1019. if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
  1020. return -ENXIO;
  1021. memset(&the_card, 0, sizeof(the_card));
  1022. spin_lock_init(&the_card.dma_lock);
  1023. /* register systembus DRIVER, this calls our probe() func */
  1024. ret = ps3_system_bus_driver_register(&snd_ps3_bus_driver_info);
  1025. return ret;
  1026. }
  1027. static void __exit snd_ps3_exit(void)
  1028. {
  1029. ps3_system_bus_driver_unregister(&snd_ps3_bus_driver_info);
  1030. }
  1031. MODULE_ALIAS(PS3_MODULE_ALIAS_SOUND);