Lines Matching +full:pclk +full:- +full:sample

1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
13 #include "axg-tdm-formatter.h"
19 struct clk *pclk; member
33 unsigned int ch = ts->channels; in axg_tdm_formatter_set_channel_masks()
53 if ((BIT(i + k) & ts->mask[j]) && ch) { in axg_tdm_formatter_set_channel_masks()
55 ch -= 1; in axg_tdm_formatter_set_channel_masks()
68 return -EINVAL; in axg_tdm_formatter_set_channel_masks()
82 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_enable()
87 if (formatter->enabled) in axg_tdm_formatter_enable()
104 ret = reset_control_reset(formatter->reset); in axg_tdm_formatter_enable()
113 invert = axg_tdm_sclk_invert(ts->iface->fmt); in axg_tdm_formatter_enable()
114 ret = clk_set_phase(formatter->sclk, invert ? 0 : 180); in axg_tdm_formatter_enable()
119 ret = formatter->drv->ops->prepare(formatter->map, in axg_tdm_formatter_enable()
120 formatter->drv->quirks, in axg_tdm_formatter_enable()
121 formatter->stream); in axg_tdm_formatter_enable()
126 ret = clk_prepare_enable(formatter->sclk); in axg_tdm_formatter_enable()
130 ret = clk_prepare_enable(formatter->lrclk); in axg_tdm_formatter_enable()
132 clk_disable_unprepare(formatter->sclk); in axg_tdm_formatter_enable()
137 formatter->drv->ops->enable(formatter->map); in axg_tdm_formatter_enable()
138 formatter->enabled = true; in axg_tdm_formatter_enable()
146 if (!formatter->enabled) in axg_tdm_formatter_disable()
149 formatter->drv->ops->disable(formatter->map); in axg_tdm_formatter_disable()
150 clk_disable_unprepare(formatter->lrclk); in axg_tdm_formatter_disable()
151 clk_disable_unprepare(formatter->sclk); in axg_tdm_formatter_disable()
152 formatter->enabled = false; in axg_tdm_formatter_disable()
157 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_attach()
160 mutex_lock(&ts->lock); in axg_tdm_formatter_attach()
163 if (ts->ready) { in axg_tdm_formatter_attach()
171 list_add_tail(&formatter->list, &ts->formatter_list); in axg_tdm_formatter_attach()
173 mutex_unlock(&ts->lock); in axg_tdm_formatter_attach()
179 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_dettach()
181 mutex_lock(&ts->lock); in axg_tdm_formatter_dettach()
182 list_del(&formatter->list); in axg_tdm_formatter_dettach()
183 mutex_unlock(&ts->lock); in axg_tdm_formatter_dettach()
191 struct axg_tdm_stream *ts = formatter->drv->ops->get_stream(w); in axg_tdm_formatter_power_up()
200 return -ENODEV; in axg_tdm_formatter_power_up()
203 ret = clk_prepare_enable(formatter->pclk); in axg_tdm_formatter_power_up()
208 ret = clk_set_parent(formatter->sclk_sel, ts->iface->sclk); in axg_tdm_formatter_power_up()
212 /* Reparent the sample clock to the TDM interface */ in axg_tdm_formatter_power_up()
213 ret = clk_set_parent(formatter->lrclk_sel, ts->iface->lrclk); in axg_tdm_formatter_power_up()
217 formatter->stream = ts; in axg_tdm_formatter_power_up()
225 clk_disable_unprepare(formatter->pclk); in axg_tdm_formatter_power_up()
232 clk_disable_unprepare(formatter->pclk); in axg_tdm_formatter_power_down()
233 formatter->stream = NULL; in axg_tdm_formatter_power_down()
240 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm); in axg_tdm_formatter_event()
254 dev_err(c->dev, "Unexpected event %d\n", event); in axg_tdm_formatter_event()
255 return -EINVAL; in axg_tdm_formatter_event()
264 struct device *dev = &pdev->dev; in axg_tdm_formatter_probe()
272 return -ENODEV; in axg_tdm_formatter_probe()
277 return -ENOMEM; in axg_tdm_formatter_probe()
279 formatter->drv = drv; in axg_tdm_formatter_probe()
285 formatter->map = devm_regmap_init_mmio(dev, regs, drv->regmap_cfg); in axg_tdm_formatter_probe()
286 if (IS_ERR(formatter->map)) { in axg_tdm_formatter_probe()
288 PTR_ERR(formatter->map)); in axg_tdm_formatter_probe()
289 return PTR_ERR(formatter->map); in axg_tdm_formatter_probe()
293 formatter->pclk = devm_clk_get(dev, "pclk"); in axg_tdm_formatter_probe()
294 if (IS_ERR(formatter->pclk)) in axg_tdm_formatter_probe()
295 return dev_err_probe(dev, PTR_ERR(formatter->pclk), "failed to get pclk\n"); in axg_tdm_formatter_probe()
298 formatter->sclk = devm_clk_get(dev, "sclk"); in axg_tdm_formatter_probe()
299 if (IS_ERR(formatter->sclk)) in axg_tdm_formatter_probe()
300 return dev_err_probe(dev, PTR_ERR(formatter->sclk), "failed to get sclk\n"); in axg_tdm_formatter_probe()
302 /* Formatter sample clock */ in axg_tdm_formatter_probe()
303 formatter->lrclk = devm_clk_get(dev, "lrclk"); in axg_tdm_formatter_probe()
304 if (IS_ERR(formatter->lrclk)) in axg_tdm_formatter_probe()
305 return dev_err_probe(dev, PTR_ERR(formatter->lrclk), "failed to get lrclk\n"); in axg_tdm_formatter_probe()
308 formatter->sclk_sel = devm_clk_get(dev, "sclk_sel"); in axg_tdm_formatter_probe()
309 if (IS_ERR(formatter->sclk_sel)) in axg_tdm_formatter_probe()
310 return dev_err_probe(dev, PTR_ERR(formatter->sclk_sel), "failed to get sclk_sel\n"); in axg_tdm_formatter_probe()
312 /* Formatter sample clock input multiplexer */ in axg_tdm_formatter_probe()
313 formatter->lrclk_sel = devm_clk_get(dev, "lrclk_sel"); in axg_tdm_formatter_probe()
314 if (IS_ERR(formatter->lrclk_sel)) in axg_tdm_formatter_probe()
315 return dev_err_probe(dev, PTR_ERR(formatter->lrclk_sel), in axg_tdm_formatter_probe()
319 formatter->reset = devm_reset_control_get_optional_exclusive(dev, NULL); in axg_tdm_formatter_probe()
320 if (IS_ERR(formatter->reset)) in axg_tdm_formatter_probe()
321 return dev_err_probe(dev, PTR_ERR(formatter->reset), "failed to get reset\n"); in axg_tdm_formatter_probe()
323 return devm_snd_soc_register_component(dev, drv->component_drv, in axg_tdm_formatter_probe()
333 mutex_lock(&ts->lock); in axg_tdm_stream_start()
334 ts->ready = true; in axg_tdm_stream_start()
337 list_for_each_entry(formatter, &ts->formatter_list, list) { in axg_tdm_stream_start()
346 mutex_unlock(&ts->lock); in axg_tdm_stream_start()
355 mutex_lock(&ts->lock); in axg_tdm_stream_stop()
356 ts->ready = false; in axg_tdm_stream_stop()
359 list_for_each_entry(formatter, &ts->formatter_list, list) { in axg_tdm_stream_stop()
363 mutex_unlock(&ts->lock); in axg_tdm_stream_stop()
373 INIT_LIST_HEAD(&ts->formatter_list); in axg_tdm_stream_alloc()
374 mutex_init(&ts->lock); in axg_tdm_stream_alloc()
375 ts->iface = iface; in axg_tdm_stream_alloc()
389 WARN_ON(!list_empty(&ts->formatter_list)); in axg_tdm_stream_free()
390 mutex_destroy(&ts->lock); in axg_tdm_stream_free()
401 /* Clock are already enabled - skipping */ in axg_tdm_stream_set_cont_clocks()
402 if (ts->clk_enabled) in axg_tdm_stream_set_cont_clocks()
405 ret = clk_prepare_enable(ts->iface->mclk); in axg_tdm_stream_set_cont_clocks()
409 ret = clk_prepare_enable(ts->iface->sclk); in axg_tdm_stream_set_cont_clocks()
413 ret = clk_prepare_enable(ts->iface->lrclk); in axg_tdm_stream_set_cont_clocks()
417 ts->clk_enabled = true; in axg_tdm_stream_set_cont_clocks()
421 /* Clocks are already disabled - skipping */ in axg_tdm_stream_set_cont_clocks()
422 if (!ts->clk_enabled) in axg_tdm_stream_set_cont_clocks()
425 clk_disable_unprepare(ts->iface->lrclk); in axg_tdm_stream_set_cont_clocks()
427 clk_disable_unprepare(ts->iface->sclk); in axg_tdm_stream_set_cont_clocks()
429 clk_disable_unprepare(ts->iface->mclk); in axg_tdm_stream_set_cont_clocks()
430 ts->clk_enabled = false; in axg_tdm_stream_set_cont_clocks()