Lines Matching +full:dai +full:- +full:tdm +full:- +full:slot +full:- +full:width
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
11 #include <sound/soc-dai.h>
13 #include "axg-tdm.h"
35 int axg_tdm_set_tdm_slots(struct snd_soc_dai *dai, u32 *tx_mask, in axg_tdm_set_tdm_slots() argument
39 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_set_tdm_slots()
40 struct axg_tdm_stream *tx = snd_soc_dai_dma_data_get_playback(dai); in axg_tdm_set_tdm_slots()
41 struct axg_tdm_stream *rx = snd_soc_dai_dma_data_get_capture(dai); in axg_tdm_set_tdm_slots()
48 /* We should at least have a slot for a valid interface */ in axg_tdm_set_tdm_slots()
50 dev_err(dai->dev, "interface has no slot\n"); in axg_tdm_set_tdm_slots()
51 return -EINVAL; in axg_tdm_set_tdm_slots()
54 iface->slots = slots; in axg_tdm_set_tdm_slots()
74 dev_err(dai->dev, "unsupported slot width: %d\n", slot_width); in axg_tdm_set_tdm_slots()
75 return -EINVAL; in axg_tdm_set_tdm_slots()
78 iface->slot_width = slot_width; in axg_tdm_set_tdm_slots()
80 /* Amend the dai driver and let dpcm merge do its job */ in axg_tdm_set_tdm_slots()
82 tx->mask = tx_mask; in axg_tdm_set_tdm_slots()
83 dai->driver->playback.channels_max = tx_slots; in axg_tdm_set_tdm_slots()
84 dai->driver->playback.formats = fmt; in axg_tdm_set_tdm_slots()
88 rx->mask = rx_mask; in axg_tdm_set_tdm_slots()
89 dai->driver->capture.channels_max = rx_slots; in axg_tdm_set_tdm_slots()
90 dai->driver->capture.formats = fmt; in axg_tdm_set_tdm_slots()
97 static int axg_tdm_iface_set_sysclk(struct snd_soc_dai *dai, int clk_id, in axg_tdm_iface_set_sysclk() argument
100 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_set_sysclk()
101 int ret = -ENOTSUPP; in axg_tdm_iface_set_sysclk()
104 if (!iface->mclk) { in axg_tdm_iface_set_sysclk()
105 dev_warn(dai->dev, "master clock not provided\n"); in axg_tdm_iface_set_sysclk()
107 ret = clk_set_rate(iface->mclk, freq); in axg_tdm_iface_set_sysclk()
109 iface->mclk_rate = freq; in axg_tdm_iface_set_sysclk()
116 static int axg_tdm_iface_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) in axg_tdm_iface_set_fmt() argument
118 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_set_fmt()
122 if (!iface->mclk) { in axg_tdm_iface_set_fmt()
123 dev_err(dai->dev, "cpu clock master: mclk missing\n"); in axg_tdm_iface_set_fmt()
124 return -ENODEV; in axg_tdm_iface_set_fmt()
133 dev_err(dai->dev, "only CBS_CFS and CBM_CFM are supported\n"); in axg_tdm_iface_set_fmt()
136 return -EINVAL; in axg_tdm_iface_set_fmt()
139 iface->fmt = fmt; in axg_tdm_iface_set_fmt()
144 struct snd_soc_dai *dai) in axg_tdm_iface_startup() argument
146 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_startup()
148 snd_soc_dai_get_dma_data(dai, substream); in axg_tdm_iface_startup()
151 if (!axg_tdm_slots_total(ts->mask)) { in axg_tdm_iface_startup()
152 dev_err(dai->dev, "interface has not slots\n"); in axg_tdm_iface_startup()
153 return -EINVAL; in axg_tdm_iface_startup()
157 if (snd_soc_component_active(dai->component)) { in axg_tdm_iface_startup()
158 ret = snd_pcm_hw_constraint_single(substream->runtime, in axg_tdm_iface_startup()
160 iface->rate); in axg_tdm_iface_startup()
162 dev_err(dai->dev, in axg_tdm_iface_startup()
173 struct snd_soc_dai *dai) in axg_tdm_iface_set_stream() argument
175 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_set_stream()
176 struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); in axg_tdm_iface_set_stream()
178 unsigned int width = params_width(params); in axg_tdm_iface_set_stream() local
181 iface->rate = params_rate(params); in axg_tdm_iface_set_stream()
184 if (axg_tdm_slots_total(ts->mask) < channels) { in axg_tdm_iface_set_stream()
185 dev_err(dai->dev, "not enough slots for channels\n"); in axg_tdm_iface_set_stream()
186 return -EINVAL; in axg_tdm_iface_set_stream()
189 if (iface->slot_width < width) { in axg_tdm_iface_set_stream()
190 dev_err(dai->dev, "incompatible slots width for stream\n"); in axg_tdm_iface_set_stream()
191 return -EINVAL; in axg_tdm_iface_set_stream()
195 ts->physical_width = params_physical_width(params); in axg_tdm_iface_set_stream()
196 ts->width = params_width(params); in axg_tdm_iface_set_stream()
197 ts->channels = params_channels(params); in axg_tdm_iface_set_stream()
202 static int axg_tdm_iface_set_lrclk(struct snd_soc_dai *dai, in axg_tdm_iface_set_lrclk() argument
205 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_set_lrclk()
209 ret = clk_set_rate(iface->lrclk, params_rate(params)); in axg_tdm_iface_set_lrclk()
211 dev_err(dai->dev, "setting sample clock failed: %d\n", ret); in axg_tdm_iface_set_lrclk()
215 switch (iface->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in axg_tdm_iface_set_lrclk()
235 return -EINVAL; in axg_tdm_iface_set_lrclk()
238 ret = clk_set_duty_cycle(iface->lrclk, ratio_num, 2); in axg_tdm_iface_set_lrclk()
240 dev_err(dai->dev, in axg_tdm_iface_set_lrclk()
246 ret = clk_set_phase(iface->lrclk, in axg_tdm_iface_set_lrclk()
247 axg_tdm_lrclk_invert(iface->fmt) ? 180 : 0); in axg_tdm_iface_set_lrclk()
249 dev_err(dai->dev, in axg_tdm_iface_set_lrclk()
257 static int axg_tdm_iface_set_sclk(struct snd_soc_dai *dai, in axg_tdm_iface_set_sclk() argument
260 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_set_sclk()
264 srate = iface->slots * iface->slot_width * params_rate(params); in axg_tdm_iface_set_sclk()
266 if (!iface->mclk_rate) { in axg_tdm_iface_set_sclk()
268 clk_set_rate(iface->mclk, 4 * srate); in axg_tdm_iface_set_sclk()
271 if (iface->mclk_rate % srate) { in axg_tdm_iface_set_sclk()
272 dev_err(dai->dev, in axg_tdm_iface_set_sclk()
274 srate, iface->mclk_rate); in axg_tdm_iface_set_sclk()
275 return -EINVAL; in axg_tdm_iface_set_sclk()
279 ret = clk_set_rate(iface->sclk, srate); in axg_tdm_iface_set_sclk()
281 dev_err(dai->dev, "setting bit clock failed: %d\n", ret); in axg_tdm_iface_set_sclk()
286 ret = clk_set_phase(iface->sclk, in axg_tdm_iface_set_sclk()
287 axg_tdm_sclk_invert(iface->fmt) ? 0 : 180); in axg_tdm_iface_set_sclk()
289 dev_err(dai->dev, "setting bit clock phase failed: %d\n", ret); in axg_tdm_iface_set_sclk()
298 struct snd_soc_dai *dai) in axg_tdm_iface_hw_params() argument
300 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_hw_params()
303 switch (iface->fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in axg_tdm_iface_hw_params()
307 if (iface->slots > 2) { in axg_tdm_iface_hw_params()
308 dev_err(dai->dev, "bad slot number for format: %d\n", in axg_tdm_iface_hw_params()
309 iface->slots); in axg_tdm_iface_hw_params()
310 return -EINVAL; in axg_tdm_iface_hw_params()
319 dev_err(dai->dev, "unsupported dai format\n"); in axg_tdm_iface_hw_params()
320 return -EINVAL; in axg_tdm_iface_hw_params()
323 ret = axg_tdm_iface_set_stream(substream, params, dai); in axg_tdm_iface_hw_params()
327 if ((iface->fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) == in axg_tdm_iface_hw_params()
329 ret = axg_tdm_iface_set_sclk(dai, params); in axg_tdm_iface_hw_params()
333 ret = axg_tdm_iface_set_lrclk(dai, params); in axg_tdm_iface_hw_params()
342 struct snd_soc_dai *dai) in axg_tdm_iface_hw_free() argument
344 struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); in axg_tdm_iface_hw_free()
353 struct snd_soc_dai *dai) in axg_tdm_iface_prepare() argument
355 struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream); in axg_tdm_iface_prepare()
361 static int axg_tdm_iface_remove_dai(struct snd_soc_dai *dai) in axg_tdm_iface_remove_dai() argument
366 struct axg_tdm_stream *ts = snd_soc_dai_dma_data_get(dai, stream); in axg_tdm_iface_remove_dai()
375 static int axg_tdm_iface_probe_dai(struct snd_soc_dai *dai) in axg_tdm_iface_probe_dai() argument
377 struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai); in axg_tdm_iface_probe_dai()
383 if (!snd_soc_dai_get_widget(dai, stream)) in axg_tdm_iface_probe_dai()
388 axg_tdm_iface_remove_dai(dai); in axg_tdm_iface_probe_dai()
389 return -ENOMEM; in axg_tdm_iface_probe_dai()
391 snd_soc_dai_dma_data_set(dai, stream, ts); in axg_tdm_iface_probe_dai()
408 /* TDM Backend DAIs */
411 .name = "TDM Pad",
430 .name = "TDM Loopback",
454 ret = clk_prepare_enable(iface->mclk); in axg_tdm_iface_set_bias_level()
459 clk_disable_unprepare(iface->mclk); in axg_tdm_iface_set_bias_level()
487 { .compatible = "amlogic,axg-tdm-iface", },
494 struct device *dev = &pdev->dev; in axg_tdm_iface_probe()
501 return -ENOMEM; in axg_tdm_iface_probe()
505 * Duplicate dai driver: depending on the slot masks configuration in axg_tdm_iface_probe()
506 * We'll change the number of channel provided by DAI stream, so dpcm in axg_tdm_iface_probe()
512 return -ENOMEM; in axg_tdm_iface_probe()
519 iface->sclk = devm_clk_get(dev, "sclk"); in axg_tdm_iface_probe()
520 if (IS_ERR(iface->sclk)) in axg_tdm_iface_probe()
521 return dev_err_probe(dev, PTR_ERR(iface->sclk), "failed to get sclk\n"); in axg_tdm_iface_probe()
524 iface->lrclk = devm_clk_get(dev, "lrclk"); in axg_tdm_iface_probe()
525 if (IS_ERR(iface->lrclk)) in axg_tdm_iface_probe()
526 return dev_err_probe(dev, PTR_ERR(iface->lrclk), "failed to get lrclk\n"); in axg_tdm_iface_probe()
529 * mclk maybe be missing when the cpu dai is in slave mode and in axg_tdm_iface_probe()
532 * throw an error if the cpu dai is master and mclk is missing in axg_tdm_iface_probe()
534 iface->mclk = devm_clk_get_optional(dev, "mclk"); in axg_tdm_iface_probe()
535 if (IS_ERR(iface->mclk)) in axg_tdm_iface_probe()
536 return dev_err_probe(dev, PTR_ERR(iface->mclk), "failed to get mclk\n"); in axg_tdm_iface_probe()
546 .name = "axg-tdm-iface",
552 MODULE_DESCRIPTION("Amlogic AXG TDM interface driver");