Lines Matching refs:tdm

136 static inline u32 jh7110_tdm_readl(struct jh7110_tdm_dev *tdm, u16 reg)  in jh7110_tdm_readl()  argument
138 return readl_relaxed(tdm->tdm_base + reg); in jh7110_tdm_readl()
141 static inline void jh7110_tdm_writel(struct jh7110_tdm_dev *tdm, u16 reg, u32 val) in jh7110_tdm_writel() argument
143 writel_relaxed(val, tdm->tdm_base + reg); in jh7110_tdm_writel()
146 static void jh7110_tdm_save_context(struct jh7110_tdm_dev *tdm, in jh7110_tdm_save_context() argument
150 tdm->saved_pcmtxcr = jh7110_tdm_readl(tdm, TDM_PCMTXCR); in jh7110_tdm_save_context()
152 tdm->saved_pcmrxcr = jh7110_tdm_readl(tdm, TDM_PCMRXCR); in jh7110_tdm_save_context()
155 static void jh7110_tdm_start(struct jh7110_tdm_dev *tdm, in jh7110_tdm_start() argument
160 data = jh7110_tdm_readl(tdm, TDM_PCMGBCR); in jh7110_tdm_start()
161 jh7110_tdm_writel(tdm, TDM_PCMGBCR, data | PCMGBCR_ENABLE); in jh7110_tdm_start()
165 jh7110_tdm_writel(tdm, TDM_PCMTXCR, tdm->saved_pcmtxcr | PCMTXCR_TXEN); in jh7110_tdm_start()
167 jh7110_tdm_writel(tdm, TDM_PCMRXCR, tdm->saved_pcmrxcr | PCMRXCR_RXEN); in jh7110_tdm_start()
170 static void jh7110_tdm_stop(struct jh7110_tdm_dev *tdm, in jh7110_tdm_stop() argument
176 val = jh7110_tdm_readl(tdm, TDM_PCMTXCR); in jh7110_tdm_stop()
178 jh7110_tdm_writel(tdm, TDM_PCMTXCR, val); in jh7110_tdm_stop()
180 val = jh7110_tdm_readl(tdm, TDM_PCMRXCR); in jh7110_tdm_stop()
182 jh7110_tdm_writel(tdm, TDM_PCMRXCR, val); in jh7110_tdm_stop()
186 static int jh7110_tdm_syncdiv(struct jh7110_tdm_dev *tdm) in jh7110_tdm_syncdiv() argument
190 if (tdm->rx.sl >= tdm->tx.sl) in jh7110_tdm_syncdiv()
191 sl = tdm->rx.sl; in jh7110_tdm_syncdiv()
193 sl = tdm->tx.sl; in jh7110_tdm_syncdiv()
195 if (tdm->rx.sscale >= tdm->tx.sscale) in jh7110_tdm_syncdiv()
196 sscale = tdm->rx.sscale; in jh7110_tdm_syncdiv()
198 sscale = tdm->tx.sscale; in jh7110_tdm_syncdiv()
200 syncdiv = tdm->pcmclk / tdm->samplerate - 1; in jh7110_tdm_syncdiv()
203 dev_err(tdm->dev, "Failed to set syncdiv!\n"); in jh7110_tdm_syncdiv()
207 if (tdm->syncm == TDM_SYNCM_LONG && in jh7110_tdm_syncdiv()
208 (tdm->rx.sscale <= 1 || tdm->tx.sscale <= 1) && in jh7110_tdm_syncdiv()
210 dev_err(tdm->dev, "Wrong syncdiv! It must be (syncdiv+1) > max[tx.sl, rx.sl]\n"); in jh7110_tdm_syncdiv()
214 jh7110_tdm_writel(tdm, TDM_PCMDIV, syncdiv); in jh7110_tdm_syncdiv()
218 static int jh7110_tdm_config(struct jh7110_tdm_dev *tdm, in jh7110_tdm_config() argument
224 ret = jh7110_tdm_syncdiv(tdm); in jh7110_tdm_config()
228 datarx = (tdm->rx.ifl << IFL_BIT) | in jh7110_tdm_config()
229 (tdm->rx.wl << WL_BIT) | in jh7110_tdm_config()
230 (tdm->rx.sscale << SSCALE_BIT) | in jh7110_tdm_config()
231 (tdm->rx.sl << SL_BIT) | in jh7110_tdm_config()
232 (tdm->rx.lrj << LRJ_BIT); in jh7110_tdm_config()
234 datatx = (tdm->tx.ifl << IFL_BIT) | in jh7110_tdm_config()
235 (tdm->tx.wl << WL_BIT) | in jh7110_tdm_config()
236 (tdm->tx.sscale << SSCALE_BIT) | in jh7110_tdm_config()
237 (tdm->tx.sl << SL_BIT) | in jh7110_tdm_config()
238 (tdm->tx.lrj << LRJ_BIT); in jh7110_tdm_config()
241 jh7110_tdm_writel(tdm, TDM_PCMTXCR, datatx); in jh7110_tdm_config()
243 jh7110_tdm_writel(tdm, TDM_PCMRXCR, datarx); in jh7110_tdm_config()
248 static void jh7110_tdm_clk_disable(struct jh7110_tdm_dev *tdm) in jh7110_tdm_clk_disable() argument
250 clk_bulk_disable_unprepare(ARRAY_SIZE(tdm->clks), tdm->clks); in jh7110_tdm_clk_disable()
253 static int jh7110_tdm_clk_enable(struct jh7110_tdm_dev *tdm) in jh7110_tdm_clk_enable() argument
257 ret = clk_bulk_prepare_enable(ARRAY_SIZE(tdm->clks), tdm->clks); in jh7110_tdm_clk_enable()
259 dev_err(tdm->dev, "Failed to enable tdm clocks\n"); in jh7110_tdm_clk_enable()
263 ret = reset_control_deassert(tdm->resets); in jh7110_tdm_clk_enable()
265 dev_err(tdm->dev, "Failed to deassert tdm resets\n"); in jh7110_tdm_clk_enable()
270 ret = clk_set_parent(tdm->clks[5].clk, tdm->clks[4].clk); in jh7110_tdm_clk_enable()
272 dev_err(tdm->dev, "Can't set extern clock source for clk_tdm\n"); in jh7110_tdm_clk_enable()
279 clk_bulk_disable_unprepare(ARRAY_SIZE(tdm->clks), tdm->clks); in jh7110_tdm_clk_enable()
286 struct jh7110_tdm_dev *tdm = dev_get_drvdata(dev); in jh7110_tdm_runtime_suspend() local
288 jh7110_tdm_clk_disable(tdm); in jh7110_tdm_runtime_suspend()
294 struct jh7110_tdm_dev *tdm = dev_get_drvdata(dev); in jh7110_tdm_runtime_resume() local
296 return jh7110_tdm_clk_enable(tdm); in jh7110_tdm_runtime_resume()
301 struct jh7110_tdm_dev *tdm = dev_get_drvdata(dev); in jh7110_tdm_system_suspend() local
304 tdm->saved_pcmgbcr = jh7110_tdm_readl(tdm, TDM_PCMGBCR); in jh7110_tdm_system_suspend()
305 tdm->saved_pcmdiv = jh7110_tdm_readl(tdm, TDM_PCMDIV); in jh7110_tdm_system_suspend()
312 struct jh7110_tdm_dev *tdm = dev_get_drvdata(dev); in jh7110_tdm_system_resume() local
315 jh7110_tdm_writel(tdm, TDM_PCMGBCR, tdm->saved_pcmgbcr); in jh7110_tdm_system_resume()
316 jh7110_tdm_writel(tdm, TDM_PCMDIV, tdm->saved_pcmdiv); in jh7110_tdm_system_resume()
340 struct jh7110_tdm_dev *tdm = snd_soc_dai_get_drvdata(dai); in jh7110_tdm_hw_params() local
349 tdm->samplerate = params_rate(params); in jh7110_tdm_hw_params()
350 tdm->pcmclk = params_channels(params) * tdm->samplerate * data_width; in jh7110_tdm_hw_params()
366 dev_err(tdm->dev, "tdm: unsupported PCM fmt"); in jh7110_tdm_hw_params()
379 dev_err(tdm->dev, "channel not supported\n"); in jh7110_tdm_hw_params()
384 tdm->tx.wl = chan_wl; in jh7110_tdm_hw_params()
385 tdm->tx.sl = chan_sl; in jh7110_tdm_hw_params()
386 tdm->tx.sscale = chan_nr; in jh7110_tdm_hw_params()
387 tdm->play_dma_data.addr_width = dma_bus_width; in jh7110_tdm_hw_params()
388 dma_data = &tdm->play_dma_data; in jh7110_tdm_hw_params()
390 tdm->rx.wl = chan_wl; in jh7110_tdm_hw_params()
391 tdm->rx.sl = chan_sl; in jh7110_tdm_hw_params()
392 tdm->rx.sscale = chan_nr; in jh7110_tdm_hw_params()
393 tdm->capture_dma_data.addr_width = dma_bus_width; in jh7110_tdm_hw_params()
394 dma_data = &tdm->capture_dma_data; in jh7110_tdm_hw_params()
399 ret = jh7110_tdm_config(tdm, substream); in jh7110_tdm_hw_params()
403 jh7110_tdm_save_context(tdm, substream); in jh7110_tdm_hw_params()
410 struct jh7110_tdm_dev *tdm = snd_soc_dai_get_drvdata(dai); in jh7110_tdm_trigger() local
417 jh7110_tdm_start(tdm, substream); in jh7110_tdm_trigger()
423 jh7110_tdm_stop(tdm, substream); in jh7110_tdm_trigger()
436 struct jh7110_tdm_dev *tdm = snd_soc_dai_get_drvdata(cpu_dai); in jh7110_tdm_set_dai_fmt() local
443 tdm->ms_mode = TDM_AS_MASTER; in jh7110_tdm_set_dai_fmt()
447 tdm->ms_mode = TDM_AS_SLAVE; in jh7110_tdm_set_dai_fmt()
453 dev_dbg(tdm->dev, "dwc : Invalid clock provider format\n"); in jh7110_tdm_set_dai_fmt()
457 gbcr = (tdm->clkpolity << CLKPOL_BIT) | in jh7110_tdm_set_dai_fmt()
458 (tdm->elm << ELM_BIT) | in jh7110_tdm_set_dai_fmt()
459 (tdm->syncm << SYNCM_BIT) | in jh7110_tdm_set_dai_fmt()
460 (tdm->ms_mode << MS_BIT); in jh7110_tdm_set_dai_fmt()
461 jh7110_tdm_writel(tdm, TDM_PCMGBCR, gbcr); in jh7110_tdm_set_dai_fmt()
468 struct jh7110_tdm_dev *tdm = snd_soc_dai_get_drvdata(dai); in jh7110_tdm_dai_probe() local
470 snd_soc_dai_init_dma_data(dai, &tdm->play_dma_data, &tdm->capture_dma_data); in jh7110_tdm_dai_probe()
471 snd_soc_dai_set_drvdata(dai, tdm); in jh7110_tdm_dai_probe()
530 static void jh7110_tdm_init_params(struct jh7110_tdm_dev *tdm) in jh7110_tdm_init_params() argument
532 tdm->clkpolity = TDM_TX_RASING_RX_FALLING; in jh7110_tdm_init_params()
533 tdm->elm = TDM_ELM_LATE; in jh7110_tdm_init_params()
534 tdm->syncm = TDM_SYNCM_SHORT; in jh7110_tdm_init_params()
536 tdm->rx.ifl = TDM_FIFO_HALF; in jh7110_tdm_init_params()
537 tdm->tx.ifl = TDM_FIFO_HALF; in jh7110_tdm_init_params()
538 tdm->rx.wl = TDM_16BIT_WORD_LEN; in jh7110_tdm_init_params()
539 tdm->tx.wl = TDM_16BIT_WORD_LEN; in jh7110_tdm_init_params()
540 tdm->rx.sscale = 2; in jh7110_tdm_init_params()
541 tdm->tx.sscale = 2; in jh7110_tdm_init_params()
542 tdm->rx.lrj = TDM_LEFT_JUSTIFT; in jh7110_tdm_init_params()
543 tdm->tx.lrj = TDM_LEFT_JUSTIFT; in jh7110_tdm_init_params()
545 tdm->play_dma_data.addr = JH7110_TDM_FIFO; in jh7110_tdm_init_params()
546 tdm->play_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; in jh7110_tdm_init_params()
547 tdm->play_dma_data.fifo_size = JH7110_TDM_FIFO_DEPTH / 2; in jh7110_tdm_init_params()
548 tdm->play_dma_data.maxburst = 16; in jh7110_tdm_init_params()
550 tdm->capture_dma_data.addr = JH7110_TDM_FIFO; in jh7110_tdm_init_params()
551 tdm->capture_dma_data.addr_width = DMA_SLAVE_BUSWIDTH_2_BYTES; in jh7110_tdm_init_params()
552 tdm->capture_dma_data.fifo_size = JH7110_TDM_FIFO_DEPTH / 2; in jh7110_tdm_init_params()
553 tdm->capture_dma_data.maxburst = 8; in jh7110_tdm_init_params()
557 struct jh7110_tdm_dev *tdm) in jh7110_tdm_clk_reset_get() argument
561 tdm->clks[0].id = "mclk_inner"; in jh7110_tdm_clk_reset_get()
562 tdm->clks[1].id = "tdm_ahb"; in jh7110_tdm_clk_reset_get()
563 tdm->clks[2].id = "tdm_apb"; in jh7110_tdm_clk_reset_get()
564 tdm->clks[3].id = "tdm_internal"; in jh7110_tdm_clk_reset_get()
565 tdm->clks[4].id = "tdm_ext"; in jh7110_tdm_clk_reset_get()
566 tdm->clks[5].id = "tdm"; in jh7110_tdm_clk_reset_get()
568 ret = devm_clk_bulk_get(&pdev->dev, ARRAY_SIZE(tdm->clks), tdm->clks); in jh7110_tdm_clk_reset_get()
574 tdm->resets = devm_reset_control_array_get_exclusive(&pdev->dev); in jh7110_tdm_clk_reset_get()
575 if (IS_ERR(tdm->resets)) { in jh7110_tdm_clk_reset_get()
577 return PTR_ERR(tdm->resets); in jh7110_tdm_clk_reset_get()
585 struct jh7110_tdm_dev *tdm; in jh7110_tdm_probe() local
588 tdm = devm_kzalloc(&pdev->dev, sizeof(*tdm), GFP_KERNEL); in jh7110_tdm_probe()
589 if (!tdm) in jh7110_tdm_probe()
592 tdm->tdm_base = devm_platform_ioremap_resource(pdev, 0); in jh7110_tdm_probe()
593 if (IS_ERR(tdm->tdm_base)) in jh7110_tdm_probe()
594 return PTR_ERR(tdm->tdm_base); in jh7110_tdm_probe()
596 tdm->dev = &pdev->dev; in jh7110_tdm_probe()
598 ret = jh7110_tdm_clk_reset_get(pdev, tdm); in jh7110_tdm_probe()
604 jh7110_tdm_init_params(tdm); in jh7110_tdm_probe()
606 dev_set_drvdata(&pdev->dev, tdm); in jh7110_tdm_probe()