Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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