Lines Matching +full:invert +full:- +full:enable
1 // SPDX-License-Identifier: (GPL-2.0 OR MIT)
13 #include "axg-tdm-formatter.h"
33 unsigned int val, ch = ts->channels; in axg_tdm_formatter_set_channel_masks()
43 mask = ts->mask[i]; in axg_tdm_formatter_set_channel_masks()
49 ch -= 1; in axg_tdm_formatter_set_channel_masks()
63 return -EINVAL; in axg_tdm_formatter_set_channel_masks()
72 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_enable()
73 bool invert; in axg_tdm_formatter_enable() local
77 if (formatter->enabled) in axg_tdm_formatter_enable()
94 ret = reset_control_reset(formatter->reset); in axg_tdm_formatter_enable()
101 * invert it before the formatter. in axg_tdm_formatter_enable()
103 invert = axg_tdm_sclk_invert(ts->iface->fmt); in axg_tdm_formatter_enable()
104 ret = clk_set_phase(formatter->sclk, invert ? 0 : 180); in axg_tdm_formatter_enable()
109 ret = formatter->drv->ops->prepare(formatter->map, in axg_tdm_formatter_enable()
110 formatter->drv->quirks, in axg_tdm_formatter_enable()
111 formatter->stream); in axg_tdm_formatter_enable()
115 /* Enable the signal clocks feeding the formatter */ in axg_tdm_formatter_enable()
116 ret = clk_prepare_enable(formatter->sclk); in axg_tdm_formatter_enable()
120 ret = clk_prepare_enable(formatter->lrclk); in axg_tdm_formatter_enable()
122 clk_disable_unprepare(formatter->sclk); in axg_tdm_formatter_enable()
126 /* Finally, actually enable the formatter */ in axg_tdm_formatter_enable()
127 formatter->drv->ops->enable(formatter->map); in axg_tdm_formatter_enable()
128 formatter->enabled = true; in axg_tdm_formatter_enable()
136 if (!formatter->enabled) in axg_tdm_formatter_disable()
139 formatter->drv->ops->disable(formatter->map); in axg_tdm_formatter_disable()
140 clk_disable_unprepare(formatter->lrclk); in axg_tdm_formatter_disable()
141 clk_disable_unprepare(formatter->sclk); in axg_tdm_formatter_disable()
142 formatter->enabled = false; in axg_tdm_formatter_disable()
147 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_attach()
150 mutex_lock(&ts->lock); in axg_tdm_formatter_attach()
153 if (ts->ready) { in axg_tdm_formatter_attach()
156 pr_err("failed to enable formatter\n"); in axg_tdm_formatter_attach()
161 list_add_tail(&formatter->list, &ts->formatter_list); in axg_tdm_formatter_attach()
163 mutex_unlock(&ts->lock); in axg_tdm_formatter_attach()
169 struct axg_tdm_stream *ts = formatter->stream; in axg_tdm_formatter_dettach()
171 mutex_lock(&ts->lock); in axg_tdm_formatter_dettach()
172 list_del(&formatter->list); in axg_tdm_formatter_dettach()
173 mutex_unlock(&ts->lock); in axg_tdm_formatter_dettach()
181 struct axg_tdm_stream *ts = formatter->drv->ops->get_stream(w); in axg_tdm_formatter_power_up()
190 return -ENODEV; in axg_tdm_formatter_power_up()
193 ret = clk_prepare_enable(formatter->pclk); in axg_tdm_formatter_power_up()
198 ret = clk_set_parent(formatter->sclk_sel, ts->iface->sclk); in axg_tdm_formatter_power_up()
203 ret = clk_set_parent(formatter->lrclk_sel, ts->iface->lrclk); in axg_tdm_formatter_power_up()
207 formatter->stream = ts; in axg_tdm_formatter_power_up()
215 clk_disable_unprepare(formatter->pclk); in axg_tdm_formatter_power_up()
222 clk_disable_unprepare(formatter->pclk); in axg_tdm_formatter_power_down()
223 formatter->stream = NULL; in axg_tdm_formatter_power_down()
230 struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm); in axg_tdm_formatter_event()
244 dev_err(c->dev, "Unexpected event %d\n", event); in axg_tdm_formatter_event()
245 return -EINVAL; in axg_tdm_formatter_event()
254 struct device *dev = &pdev->dev; in axg_tdm_formatter_probe()
263 return -ENODEV; in axg_tdm_formatter_probe()
268 return -ENOMEM; in axg_tdm_formatter_probe()
270 formatter->drv = drv; in axg_tdm_formatter_probe()
276 formatter->map = devm_regmap_init_mmio(dev, regs, drv->regmap_cfg); in axg_tdm_formatter_probe()
277 if (IS_ERR(formatter->map)) { in axg_tdm_formatter_probe()
279 PTR_ERR(formatter->map)); in axg_tdm_formatter_probe()
280 return PTR_ERR(formatter->map); in axg_tdm_formatter_probe()
284 formatter->pclk = devm_clk_get(dev, "pclk"); in axg_tdm_formatter_probe()
285 if (IS_ERR(formatter->pclk)) { in axg_tdm_formatter_probe()
286 ret = PTR_ERR(formatter->pclk); in axg_tdm_formatter_probe()
287 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
293 formatter->sclk = devm_clk_get(dev, "sclk"); in axg_tdm_formatter_probe()
294 if (IS_ERR(formatter->sclk)) { in axg_tdm_formatter_probe()
295 ret = PTR_ERR(formatter->sclk); in axg_tdm_formatter_probe()
296 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
302 formatter->lrclk = devm_clk_get(dev, "lrclk"); in axg_tdm_formatter_probe()
303 if (IS_ERR(formatter->lrclk)) { in axg_tdm_formatter_probe()
304 ret = PTR_ERR(formatter->lrclk); in axg_tdm_formatter_probe()
305 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
311 formatter->sclk_sel = devm_clk_get(dev, "sclk_sel"); in axg_tdm_formatter_probe()
312 if (IS_ERR(formatter->sclk_sel)) { in axg_tdm_formatter_probe()
313 ret = PTR_ERR(formatter->sclk_sel); in axg_tdm_formatter_probe()
314 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
320 formatter->lrclk_sel = devm_clk_get(dev, "lrclk_sel"); in axg_tdm_formatter_probe()
321 if (IS_ERR(formatter->lrclk_sel)) { in axg_tdm_formatter_probe()
322 ret = PTR_ERR(formatter->lrclk_sel); in axg_tdm_formatter_probe()
323 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
329 formatter->reset = devm_reset_control_get_optional_exclusive(dev, NULL); in axg_tdm_formatter_probe()
330 if (IS_ERR(formatter->reset)) { in axg_tdm_formatter_probe()
331 ret = PTR_ERR(formatter->reset); in axg_tdm_formatter_probe()
332 if (ret != -EPROBE_DEFER) in axg_tdm_formatter_probe()
337 return devm_snd_soc_register_component(dev, drv->component_drv, in axg_tdm_formatter_probe()
347 mutex_lock(&ts->lock); in axg_tdm_stream_start()
348 ts->ready = true; in axg_tdm_stream_start()
351 list_for_each_entry(formatter, &ts->formatter_list, list) { in axg_tdm_stream_start()
360 mutex_unlock(&ts->lock); in axg_tdm_stream_start()
369 mutex_lock(&ts->lock); in axg_tdm_stream_stop()
370 ts->ready = false; in axg_tdm_stream_stop()
373 list_for_each_entry(formatter, &ts->formatter_list, list) { in axg_tdm_stream_stop()
377 mutex_unlock(&ts->lock); in axg_tdm_stream_stop()
387 INIT_LIST_HEAD(&ts->formatter_list); in axg_tdm_stream_alloc()
388 mutex_init(&ts->lock); in axg_tdm_stream_alloc()
389 ts->iface = iface; in axg_tdm_stream_alloc()
403 WARN_ON(!list_empty(&ts->formatter_list)); in axg_tdm_stream_free()
404 mutex_destroy(&ts->lock); in axg_tdm_stream_free()