27 #include <linux/module.h>
52 static int snd_ps3_start_delay = CONFIG_SND_PS3_DEFAULT_START_DELAY;
71 return in_be32(the_card.mapped_mmio_vaddr + reg);
75 out_be32(the_card.mapped_mmio_vaddr + reg, val);
77 static inline void update_reg(
unsigned int reg,
u32 or_val)
82 static inline void update_mask_reg(
unsigned int reg,
u32 mask,
u32 or_val)
120 int count,
int force_stop)
125 for (dma_ch = 0; dma_ch < 8; dma_ch++) {
141 }
while (!done && --retries);
142 if (!retries && force_stop) {
143 pr_info(
"%s: DMA ch %d is not stopped.",
173 stop_forced = snd_ps3_verify_dma_stop(card, 700, 1);
233 int fill_stages,
dma_ch, stage;
237 unsigned long irqsave;
256 snd_ps3_verify_dma_stop(card, 700, 0);
259 for (ch = 0; ch < 2; ch++) {
261 for (stage = 0; stage < fill_stages; stage++) {
262 dma_ch = stage * 2 + ch;
289 snd_ps3_bump_buffer(card, ch,
306 spin_unlock_irqrestore(&card->
dma_lock, irqsave);
318 int underflow_occured = 0;
336 underflow_occured = 1;
340 snd_ps3_program_dma(card,
341 (underflow_occured) ?
344 snd_ps3_kick_dma(card);
347 snd_ps3_program_dma(card,
348 (underflow_occured) ?
351 snd_ps3_kick_dma(card);
365 snd_ps3_program_dma(card,
367 snd_ps3_kick_dma(card);
368 snd_ps3_program_dma(card,
370 snd_ps3_kick_dma(card);
381 static int snd_ps3_mute(
int mute_on)
396 card->
avs.avs_audio_rate,
397 card->
avs.avs_audio_width,
398 card->
avs.avs_audio_format,
399 card->
avs.avs_audio_source);
424 for (i = 0; i < 4; i++) {
460 pr_debug(
"%s: called freq=%d width=%d\n", __func__,
464 pr_debug(
"%s: before freq=%d width=%d\n", __func__,
465 card->
avs.avs_audio_rate, card->
avs.avs_audio_width);
468 switch (substream->
runtime->rate) {
482 pr_info(
"%s: invalid rate %d\n", __func__,
496 pr_info(
"%s: invalid width %d\n", __func__,
503 if (
memcmp(&card->
avs, &avs,
sizeof(avs))) {
504 pr_debug(
"%s: after freq=%d width=%d\n", __func__,
505 card->
avs.avs_audio_rate, card->
avs.avs_audio_width);
508 snd_ps3_change_avsetting(card);
514 if (avs.avs_cs_info[0] & 0x02)
531 pcm_index = substream->
pcm->device;
535 runtime->
hw = snd_ps3_pcm_hw;
573 unsigned int delay_ms)
578 rate = substream->
runtime->rate;
580 rate * delay_ms / 1000)
581 * substream->
runtime->channels;
583 pr_debug(
"%s: time=%d rate=%d bytes=%ld, frames=%d, ret=%d\n",
588 rate * delay_ms / 1000,
598 unsigned long irqsave;
600 if (!snd_ps3_set_avsetting(substream)) {
609 card->
silent = snd_ps3_delay_to_bytes(substream,
632 pr_debug(
"%s: vaddr=%p bus=%#llx\n", __func__,
637 spin_unlock_irqrestore(&card->
dma_lock, irqsave);
662 snd_ps3_program_dma(card,
664 snd_ps3_kick_dma(card);
670 snd_ps3_kick_dma(card);
679 snd_ps3_wait_for_dma_stop(card);
706 ret = bytes_to_frames(substream->
runtime, bytes * 2);
714 static int snd_ps3_spdif_mask_info(
struct snd_kcontrol *kcontrol,
723 static int snd_ps3_spdif_cmask_get(
struct snd_kcontrol *kcontrol,
730 static int snd_ps3_spdif_pmask_get(
struct snd_kcontrol *kcontrol,
736 static int snd_ps3_spdif_default_get(
struct snd_kcontrol *kcontrol,
743 static int snd_ps3_spdif_default_put(
struct snd_kcontrol *kcontrol,
758 .info = snd_ps3_spdif_mask_info,
759 .get = snd_ps3_spdif_cmask_get,
765 .info = snd_ps3_spdif_mask_info,
766 .get = snd_ps3_spdif_pmask_get,
771 .info = snd_ps3_spdif_mask_info,
772 .get = snd_ps3_spdif_default_get,
773 .put = snd_ps3_spdif_default_put,
777 static struct snd_pcm_ops snd_ps3_pcm_spdif_ops = {
778 .open = snd_ps3_pcm_open,
779 .close = snd_ps3_pcm_close,
781 .hw_params = snd_ps3_pcm_hw_params,
782 .hw_free = snd_ps3_pcm_hw_free,
783 .prepare = snd_ps3_pcm_prepare,
784 .trigger = snd_ps3_pcm_trigger,
785 .pointer = snd_ps3_pcm_pointer,
789 static int __devinit snd_ps3_map_mmio(
void)
791 the_card.mapped_mmio_vaddr =
792 ioremap(the_card.ps3_dev->m_region->bus_addr,
793 the_card.ps3_dev->m_region->len);
795 if (!the_card.mapped_mmio_vaddr) {
796 pr_info(
"%s: ioremap 0 failed p=%#lx l=%#lx \n",
797 __func__, the_card.ps3_dev->m_region->lpar_addr,
798 the_card.ps3_dev->m_region->len);
805 static void snd_ps3_unmap_mmio(
void)
807 iounmap(the_card.mapped_mmio_vaddr);
808 the_card.mapped_mmio_vaddr =
NULL;
811 static int __devinit snd_ps3_allocate_irq(
void)
814 u64 lpar_addr, lpar_size;
820 ret = lv1_gpu_device_map(1, &lpar_addr, &lpar_size);
822 pr_info(
"%s: device map 1 failed %d\n", __func__,
827 mapped =
ioremap(lpar_addr, lpar_size);
829 pr_info(
"%s: ioremap 1 failed \n", __func__);
833 the_card.audio_irq_outlet = in_be64(mapped);
836 ret = lv1_gpu_device_unmap(1);
838 pr_info(
"%s: unmap 1 failed\n", __func__);
842 the_card.audio_irq_outlet,
845 pr_info(
"%s:ps3_alloc_irq failed (%d)\n", __func__, ret);
849 ret =
request_irq(the_card.irq_no, snd_ps3_interrupt, 0,
852 pr_info(
"%s: request_irq failed (%d)\n", __func__, ret);
863 static void snd_ps3_free_irq(
void)
865 free_irq(the_card.irq_no, &the_card);
874 val = (ioaddr_start & (0x0fUL << 32)) >> (32 - 20) |
879 ret = lv1_gpu_attribute(0x100, 0x007, val);
881 pr_info(
"%s: gpu_attribute failed %d\n", __func__,
920 ret = snd_ps3_change_avsetting(card);
922 snd_ps3_audio_fixup(card);
926 snd_ps3_kick_dma(card);
934 u64 lpar_addr, lpar_size;
936 BUG_ON(!firmware_has_feature(FW_FEATURE_PS3_LV1));
939 the_card.ps3_dev =
dev;
947 ret = lv1_gpu_device_map(2, &lpar_addr, &lpar_size);
949 pr_info(
"%s: device map 2 failed %d\n", __func__, ret);
955 ret = snd_ps3_map_mmio();
969 pr_info(
"%s: region_create\n", __func__);
973 snd_ps3_audio_set_base_addr(dev->
d_region->bus_addr);
976 the_card.start_delay = snd_ps3_start_delay;
979 if (snd_ps3_allocate_irq()) {
981 goto clean_dma_region;
989 strcpy(the_card.card->driver,
"PS3");
990 strcpy(the_card.card->shortname,
"PS3");
991 strcpy(the_card.card->longname,
"PS3 sound");
994 for (i = 0; i <
ARRAY_SIZE(spdif_ctls); i++) {
1012 the_card.pcm->private_data = &the_card;
1013 strcpy(the_card.pcm->name,
"SPDIF");
1017 &snd_ps3_pcm_spdif_ops);
1027 pr_info(
"%s: prealloc failed\n", __func__);
1036 the_card.null_buffer_start_vaddr =
1039 &the_card.null_buffer_start_dma_addr,
1041 if (!the_card.null_buffer_start_vaddr) {
1042 pr_info(
"%s: nullbuffer alloc failed\n", __func__);
1044 goto clean_preallocate;
1046 pr_debug(
"%s: null vaddr=%p dma=%#llx\n", __func__,
1047 the_card.null_buffer_start_vaddr,
1048 the_card.null_buffer_start_dma_addr);
1050 snd_ps3_init_avsetting(&the_card);
1058 pr_info(
"%s started. start_delay=%dms\n",
1059 the_card.card->longname, the_card.start_delay);
1065 the_card.null_buffer_start_vaddr,
1066 the_card.null_buffer_start_dma_addr);
1076 snd_ps3_unmap_mmio();
1078 lv1_gpu_device_unmap(2);
1102 pr_info(
"%s: ctl freecard=%d\n", __func__, ret);
1106 the_card.null_buffer_start_vaddr,
1107 the_card.null_buffer_start_dma_addr);
1112 snd_ps3_unmap_mmio();
1114 lv1_gpu_device_unmap(2);
1122 .probe = snd_ps3_driver_probe,
1123 .remove = snd_ps3_driver_remove,
1124 .shutdown = snd_ps3_driver_remove,
1135 static int __init snd_ps3_init(
void)
1139 if (!firmware_has_feature(FW_FEATURE_PS3_LV1))
1142 memset(&the_card, 0,
sizeof(the_card));
1152 static void __exit snd_ps3_exit(
void)