static int ak5558_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { struct snd_soc_component *component = dai->component; struct ak5558_priv *ak5558 = snd_soc_component_get_drvdata(component); u8 bits; int pcm_width = max(params_physical_width(params), ak5558->slot_width); /* set master/slave audio interface */ bits = snd_soc_component_read32(component, AK5558_02_CONTROL1); bits &= ~AK5558_BITS; switch (pcm_width) { case 16: bits |= AK5558_DIF_24BIT_MODE; break; case 32: bits |= AK5558_DIF_32BIT_MODE; break; default: return -EINVAL; } snd_soc_component_update_bits(component, AK5558_02_CONTROL1, AK5558_BITS, bits); return 0; }
/** * snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config * @substream: PCM substream * @params: hw_params * @slave_config: DMA slave config * * This function can be used to initialize a dma_slave_config from a substream * and hw_params in a dmaengine based PCM driver implementation. */ int snd_hwparams_to_dma_slave_config(const struct snd_pcm_substream *substream, const struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config) { enum dma_slave_buswidth buswidth; int bits; bits = params_physical_width(params); if (bits < 8 || bits > 64) return -EINVAL; else if (bits == 8) buswidth = DMA_SLAVE_BUSWIDTH_1_BYTE; else if (bits == 16) buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES; else if (bits == 24) buswidth = DMA_SLAVE_BUSWIDTH_3_BYTES; else if (bits <= 32) buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES; else buswidth = DMA_SLAVE_BUSWIDTH_8_BYTES; if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { slave_config->direction = DMA_MEM_TO_DEV; slave_config->dst_addr_width = buswidth; } else { slave_config->direction = DMA_DEV_TO_MEM; slave_config->src_addr_width = buswidth; } slave_config->device_fc = false; return 0; }