Skip to content

Commit a5a8903

Browse files
jbrun3tbroonie
authored andcommitted
ASoC: meson: axg-tdm: add continuous clock support
Some devices may need the clocks running, even while paused. Add support for this use case. Signed-off-by: Jerome Brunet <jbrunet@baylibre.com> Link: https://lore.kernel.org/r/20240426152946.3078805-5-jbrunet@baylibre.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent f949ed4 commit a5a8903

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

sound/soc/meson/axg-tdm-formatter.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,46 @@ void axg_tdm_stream_free(struct axg_tdm_stream *ts)
392392
}
393393
EXPORT_SYMBOL_GPL(axg_tdm_stream_free);
394394

395+
int axg_tdm_stream_set_cont_clocks(struct axg_tdm_stream *ts,
396+
unsigned int fmt)
397+
{
398+
int ret = 0;
399+
400+
if (fmt & SND_SOC_DAIFMT_CONT) {
401+
/* Clock are already enabled - skipping */
402+
if (ts->clk_enabled)
403+
return 0;
404+
405+
ret = clk_prepare_enable(ts->iface->mclk);
406+
if (ret)
407+
return ret;
408+
409+
ret = clk_prepare_enable(ts->iface->sclk);
410+
if (ret)
411+
goto err_sclk;
412+
413+
ret = clk_prepare_enable(ts->iface->lrclk);
414+
if (ret)
415+
goto err_lrclk;
416+
417+
ts->clk_enabled = true;
418+
return 0;
419+
}
420+
421+
/* Clocks are already disabled - skipping */
422+
if (!ts->clk_enabled)
423+
return 0;
424+
425+
clk_disable_unprepare(ts->iface->lrclk);
426+
err_lrclk:
427+
clk_disable_unprepare(ts->iface->sclk);
428+
err_sclk:
429+
clk_disable_unprepare(ts->iface->mclk);
430+
ts->clk_enabled = false;
431+
return ret;
432+
}
433+
EXPORT_SYMBOL_GPL(axg_tdm_stream_set_cont_clocks);
434+
395435
MODULE_DESCRIPTION("Amlogic AXG TDM formatter driver");
396436
MODULE_AUTHOR("Jerome Brunet <jbrunet@baylibre.com>");
397437
MODULE_LICENSE("GPL v2");

sound/soc/meson/axg-tdm-interface.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ static int axg_tdm_iface_hw_params(struct snd_pcm_substream *substream,
309309
struct snd_soc_dai *dai)
310310
{
311311
struct axg_tdm_iface *iface = snd_soc_dai_get_drvdata(dai);
312+
struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
312313
int ret;
313314

314315
switch (iface->fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
@@ -346,7 +347,19 @@ static int axg_tdm_iface_hw_params(struct snd_pcm_substream *substream,
346347
return ret;
347348
}
348349

349-
return 0;
350+
ret = axg_tdm_stream_set_cont_clocks(ts, iface->fmt);
351+
if (ret)
352+
dev_err(dai->dev, "failed to apply continuous clock setting\n");
353+
354+
return ret;
355+
}
356+
357+
static int axg_tdm_iface_hw_free(struct snd_pcm_substream *substream,
358+
struct snd_soc_dai *dai)
359+
{
360+
struct axg_tdm_stream *ts = snd_soc_dai_get_dma_data(dai, substream);
361+
362+
return axg_tdm_stream_set_cont_clocks(ts, 0);
350363
}
351364

352365
static int axg_tdm_iface_trigger(struct snd_pcm_substream *substream,
@@ -417,6 +430,7 @@ static const struct snd_soc_dai_ops axg_tdm_iface_ops = {
417430
.set_fmt = axg_tdm_iface_set_fmt,
418431
.startup = axg_tdm_iface_startup,
419432
.hw_params = axg_tdm_iface_hw_params,
433+
.hw_free = axg_tdm_iface_hw_free,
420434
.trigger = axg_tdm_iface_trigger,
421435
};
422436

sound/soc/meson/axg-tdm.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ struct axg_tdm_stream {
5858
unsigned int physical_width;
5959
u32 *mask;
6060
bool ready;
61+
62+
/* For continuous clock tracking */
63+
bool clk_enabled;
6164
};
6265

6366
struct axg_tdm_stream *axg_tdm_stream_alloc(struct axg_tdm_iface *iface);
6467
void axg_tdm_stream_free(struct axg_tdm_stream *ts);
6568
int axg_tdm_stream_start(struct axg_tdm_stream *ts);
6669
void axg_tdm_stream_stop(struct axg_tdm_stream *ts);
70+
int axg_tdm_stream_set_cont_clocks(struct axg_tdm_stream *ts,
71+
unsigned int fmt);
6772

6873
static inline int axg_tdm_stream_reset(struct axg_tdm_stream *ts)
6974
{

0 commit comments

Comments
 (0)