snd_ps3.c 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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=%#lx\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. the_card.card = snd_card_new(index, id, THIS_MODULE, 0);
  827. if (!the_card.card) {
  828. ret = -ENXIO;
  829. goto clean_irq;
  830. }
  831. strcpy(the_card.card->driver, "PS3");
  832. strcpy(the_card.card->shortname, "PS3");
  833. strcpy(the_card.card->longname, "PS3 sound");
  834. /* create control elements */
  835. for (i = 0; i < ARRAY_SIZE(spdif_ctls); i++) {
  836. ret = snd_ctl_add(the_card.card,
  837. snd_ctl_new1(&spdif_ctls[i], &the_card));
  838. if (ret < 0)
  839. goto clean_card;
  840. }
  841. /* create PCM devices instance */
  842. /* NOTE:this driver works assuming pcm:substream = 1:1 */
  843. ret = snd_pcm_new(the_card.card,
  844. "SPDIF",
  845. 0, /* instance index, will be stored pcm.device*/
  846. 1, /* output substream */
  847. 0, /* input substream */
  848. &(the_card.pcm));
  849. if (ret)
  850. goto clean_card;
  851. the_card.pcm->private_data = &the_card;
  852. strcpy(the_card.pcm->name, "SPDIF");
  853. /* set pcm ops */
  854. snd_pcm_set_ops(the_card.pcm, SNDRV_PCM_STREAM_PLAYBACK,
  855. &snd_ps3_pcm_spdif_ops);
  856. the_card.pcm->info_flags = SNDRV_PCM_INFO_NONINTERLEAVED;
  857. /* pre-alloc PCM DMA buffer*/
  858. ret = snd_pcm_lib_preallocate_pages_for_all(the_card.pcm,
  859. SNDRV_DMA_TYPE_DEV,
  860. &dev->core,
  861. SND_PS3_PCM_PREALLOC_SIZE,
  862. SND_PS3_PCM_PREALLOC_SIZE);
  863. if (ret < 0) {
  864. pr_info("%s: prealloc failed\n", __func__);
  865. goto clean_card;
  866. }
  867. /*
  868. * allocate null buffer
  869. * its size should be lager than PS3_AUDIO_FIFO_STAGE_SIZE * 2
  870. * PAGE_SIZE is enogh
  871. */
  872. if (!(the_card.null_buffer_start_vaddr =
  873. dma_alloc_coherent(&the_card.ps3_dev->core,
  874. PAGE_SIZE,
  875. &the_card.null_buffer_start_dma_addr,
  876. GFP_KERNEL))) {
  877. pr_info("%s: nullbuffer alloc failed\n", __func__);
  878. goto clean_preallocate;
  879. }
  880. pr_debug("%s: null vaddr=%p dma=%#lx\n", __func__,
  881. the_card.null_buffer_start_vaddr,
  882. the_card.null_buffer_start_dma_addr);
  883. /* set default sample rate/word width */
  884. snd_ps3_init_avsetting(&the_card);
  885. /* register the card */
  886. snd_card_set_dev(the_card.card, &dev->core);
  887. ret = snd_card_register(the_card.card);
  888. if (ret < 0)
  889. goto clean_dma_map;
  890. pr_info("%s started. start_delay=%dms\n",
  891. the_card.card->longname, the_card.start_delay);
  892. return 0;
  893. clean_dma_map:
  894. dma_free_coherent(&the_card.ps3_dev->core,
  895. PAGE_SIZE,
  896. the_card.null_buffer_start_vaddr,
  897. the_card.null_buffer_start_dma_addr);
  898. clean_preallocate:
  899. snd_pcm_lib_preallocate_free_for_all(the_card.pcm);
  900. clean_card:
  901. snd_card_free(the_card.card);
  902. clean_irq:
  903. snd_ps3_free_irq();
  904. clean_dma_region:
  905. ps3_dma_region_free(dev->d_region);
  906. clean_mmio:
  907. snd_ps3_unmap_mmio();
  908. clean_dev_map:
  909. lv1_gpu_device_unmap(2);
  910. clean_open:
  911. ps3_close_hv_device(dev);
  912. /*
  913. * there is no destructor function to pcm.
  914. * midlayer automatically releases if the card removed
  915. */
  916. return ret;
  917. }; /* snd_ps3_probe */
  918. /* called when module removal */
  919. static int snd_ps3_driver_remove(struct ps3_system_bus_device *dev)
  920. {
  921. int ret;
  922. pr_info("%s:start id=%d\n", __func__, dev->match_id);
  923. if (dev->match_id != PS3_MATCH_ID_SOUND)
  924. return -ENXIO;
  925. /*
  926. * ctl and preallocate buffer will be freed in
  927. * snd_card_free
  928. */
  929. ret = snd_card_free(the_card.card);
  930. if (ret)
  931. pr_info("%s: ctl freecard=%d\n", __func__, ret);
  932. dma_free_coherent(&dev->core,
  933. PAGE_SIZE,
  934. the_card.null_buffer_start_vaddr,
  935. the_card.null_buffer_start_dma_addr);
  936. ps3_dma_region_free(dev->d_region);
  937. snd_ps3_free_irq();
  938. snd_ps3_unmap_mmio();
  939. lv1_gpu_device_unmap(2);
  940. ps3_close_hv_device(dev);
  941. pr_info("%s:end id=%d\n", __func__, dev->match_id);
  942. return 0;
  943. } /* snd_ps3_remove */
  944. static struct ps3_system_bus_driver snd_ps3_bus_driver_info = {
  945. .match_id = PS3_MATCH_ID_SOUND,
  946. .probe = snd_ps3_driver_probe,
  947. .remove = snd_ps3_driver_remove,
  948. .shutdown = snd_ps3_driver_remove,
  949. .core = {
  950. .name = SND_PS3_DRIVER_NAME,
  951. .owner = THIS_MODULE,
  952. },
  953. };
  954. /*
  955. * Interrupt handler
  956. */
  957. static irqreturn_t snd_ps3_interrupt(int irq, void *dev_id)
  958. {
  959. uint32_t port_intr;
  960. int underflow_occured = 0;
  961. struct snd_ps3_card_info *card = dev_id;
  962. if (!card->running) {
  963. update_reg(PS3_AUDIO_AX_IS, 0);
  964. update_reg(PS3_AUDIO_INTR_0, 0);
  965. return IRQ_HANDLED;
  966. }
  967. port_intr = read_reg(PS3_AUDIO_AX_IS);
  968. /*
  969. *serial buffer empty detected (every 4 times),
  970. *program next dma and kick it
  971. */
  972. if (port_intr & PS3_AUDIO_AX_IE_ASOBEIE(0)) {
  973. write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBEIE(0));
  974. if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) {
  975. write_reg(PS3_AUDIO_AX_IS, port_intr);
  976. underflow_occured = 1;
  977. }
  978. if (card->silent) {
  979. /* we are still in silent time */
  980. snd_ps3_program_dma(card,
  981. (underflow_occured) ?
  982. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL :
  983. SND_PS3_DMA_FILLTYPE_SILENT_RUNNING);
  984. snd_ps3_kick_dma(card);
  985. card->silent --;
  986. } else {
  987. snd_ps3_program_dma(card,
  988. (underflow_occured) ?
  989. SND_PS3_DMA_FILLTYPE_FIRSTFILL :
  990. SND_PS3_DMA_FILLTYPE_RUNNING);
  991. snd_ps3_kick_dma(card);
  992. snd_pcm_period_elapsed(card->substream);
  993. }
  994. } else if (port_intr & PS3_AUDIO_AX_IE_ASOBUIE(0)) {
  995. write_reg(PS3_AUDIO_AX_IS, PS3_AUDIO_AX_IE_ASOBUIE(0));
  996. /*
  997. * serial out underflow, but buffer empty not detected.
  998. * in this case, fill fifo with 0 to recover. After
  999. * filling dummy data, serial automatically start to
  1000. * consume them and then will generate normal buffer
  1001. * empty interrupts.
  1002. * If both buffer underflow and buffer empty are occured,
  1003. * it is better to do nomal data transfer than empty one
  1004. */
  1005. snd_ps3_program_dma(card,
  1006. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  1007. snd_ps3_kick_dma(card);
  1008. snd_ps3_program_dma(card,
  1009. SND_PS3_DMA_FILLTYPE_SILENT_FIRSTFILL);
  1010. snd_ps3_kick_dma(card);
  1011. }
  1012. /* clear interrupt cause */
  1013. return IRQ_HANDLED;
  1014. };
  1015. /*
  1016. * module/subsystem initialize/terminate
  1017. */
  1018. static int __init snd_ps3_init(void)
  1019. {
  1020. int ret;
  1021. if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
  1022. return -ENXIO;
  1023. memset(&the_card, 0, sizeof(the_card));
  1024. spin_lock_init(&the_card.dma_lock);
  1025. /* register systembus DRIVER, this calls our probe() func */
  1026. ret = ps3_system_bus_driver_register(&snd_ps3_bus_driver_info);
  1027. return ret;
  1028. }
  1029. static void __exit snd_ps3_exit(void)
  1030. {
  1031. ps3_system_bus_driver_unregister(&snd_ps3_bus_driver_info);
  1032. }
  1033. MODULE_ALIAS(PS3_MODULE_ALIAS_SOUND);