Lines Matching refs:sai

51 static inline bool fsl_sai_dir_is_synced(struct fsl_sai *sai, int dir)  in fsl_sai_dir_is_synced()  argument
56 return !sai->synchronous[dir] && sai->synchronous[adir]; in fsl_sai_dir_is_synced()
61 struct fsl_sai *sai = (struct fsl_sai *)devid; in fsl_sai_isr() local
62 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_isr()
63 struct device *dev = &sai->pdev->dev; in fsl_sai_isr()
75 regmap_read(sai->regmap, FSL_SAI_TCSR(ofs), &xcsr); in fsl_sai_isr()
105 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), flags | xcsr); in fsl_sai_isr()
109 regmap_read(sai->regmap, FSL_SAI_RCSR(ofs), &xcsr); in fsl_sai_isr()
139 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), flags | xcsr); in fsl_sai_isr()
148 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_set_dai_tdm_slot() local
150 sai->slots = slots; in fsl_sai_set_dai_tdm_slot()
151 sai->slot_width = slot_width; in fsl_sai_set_dai_tdm_slot()
159 struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai); in fsl_sai_set_dai_bclk_ratio() local
161 sai->bclk_ratio = ratio; in fsl_sai_set_dai_bclk_ratio()
169 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_set_dai_sysclk_tr() local
170 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_set_dai_sysclk_tr()
190 regmap_update_bits(sai->regmap, FSL_SAI_xCR2(tx, ofs), in fsl_sai_set_dai_sysclk_tr()
220 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_set_dai_fmt_tr() local
221 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_set_dai_fmt_tr()
224 if (!sai->is_lsb_first) in fsl_sai_set_dai_fmt_tr()
255 sai->is_dsp_mode = true; in fsl_sai_set_dai_fmt_tr()
263 sai->is_dsp_mode = true; in fsl_sai_set_dai_fmt_tr()
298 sai->is_consumer_mode = false; in fsl_sai_set_dai_fmt_tr()
301 sai->is_consumer_mode = true; in fsl_sai_set_dai_fmt_tr()
305 sai->is_consumer_mode = false; in fsl_sai_set_dai_fmt_tr()
309 sai->is_consumer_mode = true; in fsl_sai_set_dai_fmt_tr()
315 regmap_update_bits(sai->regmap, FSL_SAI_xCR2(tx, ofs), in fsl_sai_set_dai_fmt_tr()
317 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_set_dai_fmt_tr()
343 struct fsl_sai *sai = snd_soc_dai_get_drvdata(dai); in fsl_sai_set_bclk() local
344 unsigned int reg, ofs = sai->soc_data->reg_offset; in fsl_sai_set_bclk()
350 bool support_1_1_ratio = sai->verid.version >= 0x0301; in fsl_sai_set_bclk()
353 if (sai->is_consumer_mode) in fsl_sai_set_bclk()
361 id = sai->soc_data->mclk0_is_mclk1 ? 1 : 0; in fsl_sai_set_bclk()
366 clk_rate = clk_get_rate(sai->mclk_clk[id]); in fsl_sai_set_bclk()
394 sai->mclk_id[tx] = id; in fsl_sai_set_bclk()
409 sai->mclk_id[tx], savediv, bestdiff); in fsl_sai_set_bclk()
421 if (fsl_sai_dir_is_synced(sai, adir)) in fsl_sai_set_bclk()
423 else if (!sai->synchronous[dir]) in fsl_sai_set_bclk()
428 regmap_update_bits(sai->regmap, reg, FSL_SAI_CR2_MSEL_MASK, in fsl_sai_set_bclk()
429 FSL_SAI_CR2_MSEL(sai->mclk_id[tx])); in fsl_sai_set_bclk()
432 regmap_update_bits(sai->regmap, reg, in fsl_sai_set_bclk()
436 regmap_update_bits(sai->regmap, reg, in fsl_sai_set_bclk()
447 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_hw_params() local
448 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_hw_params()
459 if (sai->slots) in fsl_sai_hw_params()
460 slots = sai->slots; in fsl_sai_hw_params()
462 if (sai->slot_width) in fsl_sai_hw_params()
463 slot_width = sai->slot_width; in fsl_sai_hw_params()
467 if (!sai->is_consumer_mode) { in fsl_sai_hw_params()
468 if (sai->bclk_ratio) in fsl_sai_hw_params()
470 sai->bclk_ratio * in fsl_sai_hw_params()
480 if (!(sai->mclk_streams & BIT(substream->stream))) { in fsl_sai_hw_params()
481 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[tx]]); in fsl_sai_hw_params()
485 sai->mclk_streams |= BIT(substream->stream); in fsl_sai_hw_params()
489 if (!sai->is_dsp_mode) in fsl_sai_hw_params()
495 if (sai->is_lsb_first) in fsl_sai_hw_params()
512 if (!sai->is_consumer_mode && fsl_sai_dir_is_synced(sai, adir)) { in fsl_sai_hw_params()
513 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(!tx, ofs), in fsl_sai_hw_params()
517 regmap_update_bits(sai->regmap, FSL_SAI_xCR5(!tx, ofs), in fsl_sai_hw_params()
522 if (sai->soc_data->pins > 1) in fsl_sai_hw_params()
523 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_hw_params()
526 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx, ofs), in fsl_sai_hw_params()
529 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_hw_params()
533 regmap_update_bits(sai->regmap, FSL_SAI_xCR5(tx, ofs), in fsl_sai_hw_params()
536 regmap_write(sai->regmap, FSL_SAI_xMR(tx), in fsl_sai_hw_params()
545 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_hw_free() local
547 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_hw_free()
549 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx, ofs), in fsl_sai_hw_free()
552 if (!sai->is_consumer_mode && in fsl_sai_hw_free()
553 sai->mclk_streams & BIT(substream->stream)) { in fsl_sai_hw_free()
554 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[tx]]); in fsl_sai_hw_free()
555 sai->mclk_streams &= ~BIT(substream->stream); in fsl_sai_hw_free()
561 static void fsl_sai_config_disable(struct fsl_sai *sai, int dir) in fsl_sai_config_disable() argument
563 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_config_disable()
567 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_config_disable()
573 regmap_read(sai->regmap, FSL_SAI_xCSR(tx, ofs), &xcsr); in fsl_sai_config_disable()
576 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_config_disable()
586 if (!sai->is_consumer_mode) { in fsl_sai_config_disable()
588 regmap_write(sai->regmap, FSL_SAI_xCSR(tx, ofs), FSL_SAI_CSR_SR); in fsl_sai_config_disable()
590 regmap_write(sai->regmap, FSL_SAI_xCSR(tx, ofs), 0); in fsl_sai_config_disable()
597 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_trigger() local
598 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_trigger()
610 regmap_update_bits(sai->regmap, FSL_SAI_TCR2(ofs), FSL_SAI_CR2_SYNC, in fsl_sai_trigger()
611 sai->synchronous[TX] ? FSL_SAI_CR2_SYNC : 0); in fsl_sai_trigger()
612 regmap_update_bits(sai->regmap, FSL_SAI_RCR2(ofs), FSL_SAI_CR2_SYNC, in fsl_sai_trigger()
613 sai->synchronous[RX] ? FSL_SAI_CR2_SYNC : 0); in fsl_sai_trigger()
623 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
626 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
639 if (fsl_sai_dir_is_synced(sai, adir)) in fsl_sai_trigger()
640 regmap_update_bits(sai->regmap, FSL_SAI_xCSR((!tx), ofs), in fsl_sai_trigger()
643 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
649 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
651 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
655 regmap_read(sai->regmap, FSL_SAI_xCSR(!tx, ofs), &xcsr); in fsl_sai_trigger()
661 if (fsl_sai_dir_is_synced(sai, adir) && !(xcsr & FSL_SAI_CSR_FRDE)) in fsl_sai_trigger()
662 fsl_sai_config_disable(sai, adir); in fsl_sai_trigger()
670 if (!fsl_sai_dir_is_synced(sai, dir) || !(xcsr & FSL_SAI_CSR_FRDE)) in fsl_sai_trigger()
671 fsl_sai_config_disable(sai, dir); in fsl_sai_trigger()
684 struct fsl_sai *sai = snd_soc_dai_get_drvdata(cpu_dai); in fsl_sai_startup() local
692 if (sai->soc_data->use_edma) in fsl_sai_startup()
695 tx ? sai->dma_params_tx.maxburst : in fsl_sai_startup()
696 sai->dma_params_rx.maxburst); in fsl_sai_startup()
717 struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); in fsl_sai_dai_probe() local
718 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_dai_probe()
721 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_dai_probe()
722 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_dai_probe()
724 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), 0); in fsl_sai_dai_probe()
725 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), 0); in fsl_sai_dai_probe()
727 regmap_update_bits(sai->regmap, FSL_SAI_TCR1(ofs), in fsl_sai_dai_probe()
728 FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth), in fsl_sai_dai_probe()
729 sai->soc_data->fifo_depth - FSL_SAI_MAXBURST_TX); in fsl_sai_dai_probe()
730 regmap_update_bits(sai->regmap, FSL_SAI_RCR1(ofs), in fsl_sai_dai_probe()
731 FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth), in fsl_sai_dai_probe()
734 snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params_tx, in fsl_sai_dai_probe()
735 &sai->dma_params_rx); in fsl_sai_dai_probe()
817 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_readable_reg() local
818 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_readable_reg()
873 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_volatile_reg() local
874 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_volatile_reg()
916 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_writeable_reg() local
917 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_writeable_reg()
963 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_check_version() local
964 unsigned char ofs = sai->soc_data->reg_offset; in fsl_sai_check_version()
971 ret = regmap_read(sai->regmap, FSL_SAI_VERID, &val); in fsl_sai_check_version()
977 sai->verid.version = val & in fsl_sai_check_version()
979 sai->verid.feature = val & FSL_SAI_VERID_FEATURE_MASK; in fsl_sai_check_version()
981 ret = regmap_read(sai->regmap, FSL_SAI_PARAM, &val); in fsl_sai_check_version()
988 sai->param.slot_num = 1 << in fsl_sai_check_version()
992 sai->param.fifo_depth = 1 << in fsl_sai_check_version()
996 sai->param.dataline = val & FSL_SAI_PARAM_DLN_MASK; in fsl_sai_check_version()
1007 struct fsl_sai *sai; in fsl_sai_probe() local
1015 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); in fsl_sai_probe()
1016 if (!sai) in fsl_sai_probe()
1019 sai->pdev = pdev; in fsl_sai_probe()
1020 sai->soc_data = of_device_get_match_data(&pdev->dev); in fsl_sai_probe()
1022 sai->is_lsb_first = of_property_read_bool(np, "lsb-first"); in fsl_sai_probe()
1028 if (sai->soc_data->reg_offset == 8) { in fsl_sai_probe()
1035 sai->regmap = devm_regmap_init_mmio(&pdev->dev, base, &fsl_sai_regmap_config); in fsl_sai_probe()
1036 if (IS_ERR(sai->regmap)) { in fsl_sai_probe()
1038 return PTR_ERR(sai->regmap); in fsl_sai_probe()
1041 sai->bus_clk = devm_clk_get(&pdev->dev, "bus"); in fsl_sai_probe()
1043 if (IS_ERR(sai->bus_clk) && PTR_ERR(sai->bus_clk) != -EPROBE_DEFER) in fsl_sai_probe()
1044 sai->bus_clk = devm_clk_get(&pdev->dev, "sai"); in fsl_sai_probe()
1045 if (IS_ERR(sai->bus_clk)) { in fsl_sai_probe()
1047 PTR_ERR(sai->bus_clk)); in fsl_sai_probe()
1049 return PTR_ERR(sai->bus_clk); in fsl_sai_probe()
1054 sai->mclk_clk[i] = devm_clk_get(&pdev->dev, tmp); in fsl_sai_probe()
1055 if (IS_ERR(sai->mclk_clk[i])) { in fsl_sai_probe()
1057 i + 1, PTR_ERR(sai->mclk_clk[i])); in fsl_sai_probe()
1058 sai->mclk_clk[i] = NULL; in fsl_sai_probe()
1062 if (sai->soc_data->mclk0_is_mclk1) in fsl_sai_probe()
1063 sai->mclk_clk[0] = sai->mclk_clk[1]; in fsl_sai_probe()
1065 sai->mclk_clk[0] = sai->bus_clk; in fsl_sai_probe()
1072 np->name, sai); in fsl_sai_probe()
1078 memcpy(&sai->cpu_dai_drv, &fsl_sai_dai_template, in fsl_sai_probe()
1082 sai->synchronous[RX] = true; in fsl_sai_probe()
1083 sai->synchronous[TX] = false; in fsl_sai_probe()
1084 sai->cpu_dai_drv.symmetric_rate = 1; in fsl_sai_probe()
1085 sai->cpu_dai_drv.symmetric_channels = 1; in fsl_sai_probe()
1086 sai->cpu_dai_drv.symmetric_sample_bits = 1; in fsl_sai_probe()
1097 sai->synchronous[RX] = false; in fsl_sai_probe()
1098 sai->synchronous[TX] = true; in fsl_sai_probe()
1101 sai->synchronous[RX] = false; in fsl_sai_probe()
1102 sai->synchronous[TX] = false; in fsl_sai_probe()
1103 sai->cpu_dai_drv.symmetric_rate = 0; in fsl_sai_probe()
1104 sai->cpu_dai_drv.symmetric_channels = 0; in fsl_sai_probe()
1105 sai->cpu_dai_drv.symmetric_sample_bits = 0; in fsl_sai_probe()
1124 sai->dma_params_rx.addr = res->start + FSL_SAI_RDR0; in fsl_sai_probe()
1125 sai->dma_params_tx.addr = res->start + FSL_SAI_TDR0; in fsl_sai_probe()
1126 sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; in fsl_sai_probe()
1127 sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; in fsl_sai_probe()
1129 platform_set_drvdata(pdev, sai); in fsl_sai_probe()
1150 sai->soc_data->max_register >= FSL_SAI_MCTL) { in fsl_sai_probe()
1151 regmap_update_bits(sai->regmap, FSL_SAI_MCTL, in fsl_sai_probe()
1163 if (sai->soc_data->use_imx_pcm) { in fsl_sai_probe()
1174 &sai->cpu_dai_drv, 1); in fsl_sai_probe()
1303 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_runtime_suspend() local
1305 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) in fsl_sai_runtime_suspend()
1306 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_suspend()
1308 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) in fsl_sai_runtime_suspend()
1309 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_suspend()
1311 clk_disable_unprepare(sai->bus_clk); in fsl_sai_runtime_suspend()
1313 if (sai->soc_data->flags & PMQOS_CPU_LATENCY) in fsl_sai_runtime_suspend()
1314 cpu_latency_qos_remove_request(&sai->pm_qos_req); in fsl_sai_runtime_suspend()
1316 regcache_cache_only(sai->regmap, true); in fsl_sai_runtime_suspend()
1323 struct fsl_sai *sai = dev_get_drvdata(dev); in fsl_sai_runtime_resume() local
1324 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_runtime_resume()
1327 ret = clk_prepare_enable(sai->bus_clk); in fsl_sai_runtime_resume()
1333 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) { in fsl_sai_runtime_resume()
1334 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_resume()
1339 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) { in fsl_sai_runtime_resume()
1340 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_resume()
1345 if (sai->soc_data->flags & PMQOS_CPU_LATENCY) in fsl_sai_runtime_resume()
1346 cpu_latency_qos_add_request(&sai->pm_qos_req, 0); in fsl_sai_runtime_resume()
1348 regcache_cache_only(sai->regmap, false); in fsl_sai_runtime_resume()
1349 regcache_mark_dirty(sai->regmap); in fsl_sai_runtime_resume()
1350 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_runtime_resume()
1351 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_runtime_resume()
1353 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), 0); in fsl_sai_runtime_resume()
1354 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), 0); in fsl_sai_runtime_resume()
1356 ret = regcache_sync(sai->regmap); in fsl_sai_runtime_resume()
1363 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) in fsl_sai_runtime_resume()
1364 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_resume()
1366 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) in fsl_sai_runtime_resume()
1367 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_resume()
1369 clk_disable_unprepare(sai->bus_clk); in fsl_sai_runtime_resume()