Lines Matching +full:imx8mq +full:- +full:iomuxc
1 // SPDX-License-Identifier: GPL-2.0+
5 // Copyright 2012-2015 Freescale Semiconductor, Inc.
23 #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h>
27 #include "imx-pcm.h"
45 * fsl_sai_dir_is_synced - Check if stream is synced by the opposite stream
59 return !sai->synchronous[dir] && sai->synchronous[adir]; in fsl_sai_dir_is_synced()
66 if (sai->is_pdm_mode) { in fsl_sai_get_pins_state()
69 state = pinctrl_lookup_state(sai->pinctrl, "dsd512"); in fsl_sai_get_pins_state()
73 state = pinctrl_lookup_state(sai->pinctrl, "dsd"); in fsl_sai_get_pins_state()
77 state = pinctrl_lookup_state(sai->pinctrl, "pcm_b2m"); in fsl_sai_get_pins_state()
82 state = pinctrl_lookup_state(sai->pinctrl, "default"); in fsl_sai_get_pins_state()
90 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_isr()
91 struct device *dev = &sai->pdev->dev; in fsl_sai_isr()
103 regmap_read(sai->regmap, FSL_SAI_TCSR(ofs), &xcsr); in fsl_sai_isr()
130 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), flags | xcsr); in fsl_sai_isr()
134 regmap_read(sai->regmap, FSL_SAI_RCSR(ofs), &xcsr); in fsl_sai_isr()
161 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), flags | xcsr); in fsl_sai_isr()
172 sai->slots = slots; in fsl_sai_set_dai_tdm_slot()
173 sai->slot_width = slot_width; in fsl_sai_set_dai_tdm_slot()
183 sai->bclk_ratio = ratio; in fsl_sai_set_dai_bclk_ratio()
192 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_set_dai_sysclk_tr()
209 return -EINVAL; in fsl_sai_set_dai_sysclk_tr()
212 regmap_update_bits(sai->regmap, FSL_SAI_xCR2(tx, ofs), in fsl_sai_set_dai_sysclk_tr()
223 fsl_asoc_reparent_pll_clocks(dai->dev, sai->mclk_clk[clk_id], in fsl_sai_set_mclk_rate()
224 sai->pll8k_clk, sai->pll11k_clk, freq); in fsl_sai_set_mclk_rate()
226 ret = clk_set_rate(sai->mclk_clk[clk_id], freq); in fsl_sai_set_mclk_rate()
228 dev_err(dai->dev, "failed to set clock rate (%u): %d\n", freq, ret); in fsl_sai_set_mclk_rate()
244 dev_err(cpu_dai->dev, "Unknown clock id: %d\n", clk_id); in fsl_sai_set_dai_sysclk()
245 return -EINVAL; in fsl_sai_set_dai_sysclk()
248 if (IS_ERR_OR_NULL(sai->mclk_clk[clk_id])) { in fsl_sai_set_dai_sysclk()
249 dev_err(cpu_dai->dev, "Unassigned clock: %d\n", clk_id); in fsl_sai_set_dai_sysclk()
250 return -EINVAL; in fsl_sai_set_dai_sysclk()
253 if (sai->mclk_streams == 0) { in fsl_sai_set_dai_sysclk()
262 dev_err(cpu_dai->dev, "Cannot set tx sysclk: %d\n", ret); in fsl_sai_set_dai_sysclk()
268 dev_err(cpu_dai->dev, "Cannot set rx sysclk: %d\n", ret); in fsl_sai_set_dai_sysclk()
277 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_set_dai_fmt_tr()
280 if (!sai->is_lsb_first) in fsl_sai_set_dai_fmt_tr()
283 sai->is_pdm_mode = false; in fsl_sai_set_dai_fmt_tr()
312 sai->is_dsp_mode = true; in fsl_sai_set_dai_fmt_tr()
320 sai->is_dsp_mode = true; in fsl_sai_set_dai_fmt_tr()
325 sai->is_pdm_mode = true; in fsl_sai_set_dai_fmt_tr()
330 return -EINVAL; in fsl_sai_set_dai_fmt_tr()
352 return -EINVAL; in fsl_sai_set_dai_fmt_tr()
360 sai->is_consumer_mode = false; in fsl_sai_set_dai_fmt_tr()
363 sai->is_consumer_mode = true; in fsl_sai_set_dai_fmt_tr()
367 sai->is_consumer_mode = false; in fsl_sai_set_dai_fmt_tr()
371 sai->is_consumer_mode = true; in fsl_sai_set_dai_fmt_tr()
374 return -EINVAL; in fsl_sai_set_dai_fmt_tr()
377 regmap_update_bits(sai->regmap, FSL_SAI_xCR2(tx, ofs), in fsl_sai_set_dai_fmt_tr()
379 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_set_dai_fmt_tr()
392 dev_err(cpu_dai->dev, "Cannot set tx format: %d\n", ret); in fsl_sai_set_dai_fmt()
398 dev_err(cpu_dai->dev, "Cannot set rx format: %d\n", ret); in fsl_sai_set_dai_fmt()
406 unsigned int reg, ofs = sai->soc_data->reg_offset; in fsl_sai_set_bclk()
412 bool support_1_1_ratio = sai->verid.version >= 0x0301; in fsl_sai_set_bclk()
415 if (sai->is_consumer_mode) in fsl_sai_set_bclk()
423 id = sai->soc_data->mclk0_is_mclk1 ? 1 : 0; in fsl_sai_set_bclk()
428 clk_rate = clk_get_rate(sai->mclk_clk[id]); in fsl_sai_set_bclk()
440 diff = abs((long)clk_rate - ratio * freq); in fsl_sai_set_bclk()
449 dev_dbg(dai->dev, in fsl_sai_set_bclk()
456 sai->mclk_id[tx] = id; in fsl_sai_set_bclk()
465 dev_err(dai->dev, "failed to derive required %cx rate: %d\n", in fsl_sai_set_bclk()
467 return -EINVAL; in fsl_sai_set_bclk()
470 dev_dbg(dai->dev, "best fit: clock id=%d, div=%d, deviation =%d\n", in fsl_sai_set_bclk()
471 sai->mclk_id[tx], savediv, bestdiff); in fsl_sai_set_bclk()
485 else if (!sai->synchronous[dir]) in fsl_sai_set_bclk()
490 regmap_update_bits(sai->regmap, reg, FSL_SAI_CR2_MSEL_MASK, in fsl_sai_set_bclk()
491 FSL_SAI_CR2_MSEL(sai->mclk_id[tx])); in fsl_sai_set_bclk()
494 regmap_update_bits(sai->regmap, reg, in fsl_sai_set_bclk()
498 regmap_update_bits(sai->regmap, reg, in fsl_sai_set_bclk()
500 savediv / 2 - 1); in fsl_sai_set_bclk()
502 if (sai->soc_data->max_register >= FSL_SAI_MCTL) { in fsl_sai_set_bclk()
504 regmap_update_bits(sai->regmap, FSL_SAI_MCTL, in fsl_sai_set_bclk()
516 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_hw_params()
517 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_sai_hw_params()
520 struct fsl_sai_dl_cfg *dl_cfg = sai->dl_cfg; in fsl_sai_hw_params()
523 int dl_cfg_cnt = sai->dl_cfg_cnt; in fsl_sai_hw_params()
533 if (sai->slot_width) in fsl_sai_hw_params()
534 slot_width = sai->slot_width; in fsl_sai_hw_params()
536 if (sai->slots) in fsl_sai_hw_params()
537 slots = sai->slots; in fsl_sai_hw_params()
538 else if (sai->bclk_ratio) in fsl_sai_hw_params()
539 slots = sai->bclk_ratio / slot_width; in fsl_sai_hw_params()
547 if (sai->is_pdm_mode) { in fsl_sai_hw_params()
560 dev_err(cpu_dai->dev, "channel not supported\n"); in fsl_sai_hw_params()
561 return -EINVAL; in fsl_sai_hw_params()
564 bclk = params_rate(params) * (sai->bclk_ratio ? sai->bclk_ratio : slots * slot_width); in fsl_sai_hw_params()
566 if (!IS_ERR_OR_NULL(sai->pinctrl)) { in fsl_sai_hw_params()
567 sai->pins_state = fsl_sai_get_pins_state(sai, bclk); in fsl_sai_hw_params()
568 if (!IS_ERR_OR_NULL(sai->pins_state)) { in fsl_sai_hw_params()
569 ret = pinctrl_select_state(sai->pinctrl, sai->pins_state); in fsl_sai_hw_params()
571 dev_err(cpu_dai->dev, "failed to set proper pins state: %d\n", ret); in fsl_sai_hw_params()
577 if (!sai->is_consumer_mode) { in fsl_sai_hw_params()
583 if (!(sai->mclk_streams & BIT(substream->stream))) { in fsl_sai_hw_params()
584 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[tx]]); in fsl_sai_hw_params()
588 sai->mclk_streams |= BIT(substream->stream); in fsl_sai_hw_params()
592 if (!sai->is_dsp_mode && !sai->is_pdm_mode) in fsl_sai_hw_params()
598 if (sai->is_lsb_first || sai->is_pdm_mode) in fsl_sai_hw_params()
601 val_cr5 |= FSL_SAI_CR5_FBT(word_width - 1); in fsl_sai_hw_params()
605 /* Set to output mode to avoid tri-stated data pins */ in fsl_sai_hw_params()
615 if (!sai->is_consumer_mode && fsl_sai_dir_is_synced(sai, adir)) { in fsl_sai_hw_params()
616 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(!tx, ofs), in fsl_sai_hw_params()
620 regmap_update_bits(sai->regmap, FSL_SAI_xCR5(!tx, ofs), in fsl_sai_hw_params()
627 * - Can't used for singel dataline/FIFO case except the FIFO0 in fsl_sai_hw_params()
628 * - Can't used for multi dataline/FIFO case except the enabled FIFOs in fsl_sai_hw_params()
633 if (hweight8(dl_cfg[dl_cfg_idx].mask[tx]) <= 1 || sai->is_multi_fifo_dma) in fsl_sai_hw_params()
634 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_hw_params()
637 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_hw_params()
640 dma_params = tx ? &sai->dma_params_tx : &sai->dma_params_rx; in fsl_sai_hw_params()
641 dma_params->addr = sai->res->start + FSL_SAI_xDR0(tx) + in fsl_sai_hw_params()
644 if (sai->is_multi_fifo_dma) { in fsl_sai_hw_params()
645 sai->audio_config[tx].words_per_fifo = min(slots, channels); in fsl_sai_hw_params()
647 sai->audio_config[tx].n_fifos_dst = pins; in fsl_sai_hw_params()
648 sai->audio_config[tx].stride_fifos_dst = dl_cfg[dl_cfg_idx].next_off[tx]; in fsl_sai_hw_params()
650 sai->audio_config[tx].n_fifos_src = pins; in fsl_sai_hw_params()
651 sai->audio_config[tx].stride_fifos_src = dl_cfg[dl_cfg_idx].next_off[tx]; in fsl_sai_hw_params()
653 dma_params->maxburst = sai->audio_config[tx].words_per_fifo * pins; in fsl_sai_hw_params()
654 dma_params->peripheral_config = &sai->audio_config[tx]; in fsl_sai_hw_params()
655 dma_params->peripheral_size = sizeof(sai->audio_config[tx]); in fsl_sai_hw_params()
657 watermark = tx ? (sai->soc_data->fifo_depth - dma_params->maxburst) : in fsl_sai_hw_params()
658 (dma_params->maxburst - 1); in fsl_sai_hw_params()
659 regmap_update_bits(sai->regmap, FSL_SAI_xCR1(tx, ofs), in fsl_sai_hw_params()
660 FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth), in fsl_sai_hw_params()
665 for (i = 0; i < sai->soc_data->pins; i++) { in fsl_sai_hw_params()
666 trce_mask = (1 << (i + 1)) - 1; in fsl_sai_hw_params()
671 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx, ofs), in fsl_sai_hw_params()
675 regmap_update_bits(sai->regmap, FSL_SAI_xCR4(tx, ofs), in fsl_sai_hw_params()
679 regmap_update_bits(sai->regmap, FSL_SAI_xCR5(tx, ofs), in fsl_sai_hw_params()
682 regmap_write(sai->regmap, FSL_SAI_xMR(tx), in fsl_sai_hw_params()
683 ~0UL - ((1 << min(channels, slots)) - 1)); in fsl_sai_hw_params()
692 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_sai_hw_free()
693 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_hw_free()
695 regmap_update_bits(sai->regmap, FSL_SAI_xCR3(tx, ofs), in fsl_sai_hw_free()
698 if (!sai->is_consumer_mode && in fsl_sai_hw_free()
699 sai->mclk_streams & BIT(substream->stream)) { in fsl_sai_hw_free()
700 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[tx]]); in fsl_sai_hw_free()
701 sai->mclk_streams &= ~BIT(substream->stream); in fsl_sai_hw_free()
709 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_config_disable()
713 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_config_disable()
719 regmap_read(sai->regmap, FSL_SAI_xCSR(tx, ofs), &xcsr); in fsl_sai_config_disable()
720 } while (--count && xcsr & FSL_SAI_CSR_TERE); in fsl_sai_config_disable()
722 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_config_disable()
732 if (!sai->is_consumer_mode) { in fsl_sai_config_disable()
734 regmap_write(sai->regmap, FSL_SAI_xCSR(tx, ofs), FSL_SAI_CSR_SR); in fsl_sai_config_disable()
736 regmap_write(sai->regmap, FSL_SAI_xCSR(tx, ofs), 0); in fsl_sai_config_disable()
744 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_trigger()
746 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_sai_trigger()
756 regmap_update_bits(sai->regmap, FSL_SAI_TCR2(ofs), FSL_SAI_CR2_SYNC, in fsl_sai_trigger()
757 sai->synchronous[TX] ? FSL_SAI_CR2_SYNC : 0); in fsl_sai_trigger()
758 regmap_update_bits(sai->regmap, FSL_SAI_RCR2(ofs), FSL_SAI_CR2_SYNC, in fsl_sai_trigger()
759 sai->synchronous[RX] ? FSL_SAI_CR2_SYNC : 0); in fsl_sai_trigger()
769 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
772 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
786 regmap_update_bits(sai->regmap, FSL_SAI_xCSR((!tx), ofs), in fsl_sai_trigger()
789 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
795 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
797 regmap_update_bits(sai->regmap, FSL_SAI_xCSR(tx, ofs), in fsl_sai_trigger()
801 regmap_read(sai->regmap, FSL_SAI_xCSR(!tx, ofs), &xcsr); in fsl_sai_trigger()
821 return -EINVAL; in fsl_sai_trigger()
831 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_sai_startup()
838 if (sai->soc_data->use_edma) in fsl_sai_startup()
839 snd_pcm_hw_constraint_step(substream->runtime, 0, in fsl_sai_startup()
841 tx ? sai->dma_params_tx.maxburst : in fsl_sai_startup()
842 sai->dma_params_rx.maxburst); in fsl_sai_startup()
844 ret = snd_pcm_hw_constraint_list(substream->runtime, 0, in fsl_sai_startup()
863 struct fsl_sai *sai = dev_get_drvdata(cpu_dai->dev); in fsl_sai_dai_probe()
864 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_dai_probe()
867 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_dai_probe()
868 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_dai_probe()
870 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), 0); in fsl_sai_dai_probe()
871 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), 0); in fsl_sai_dai_probe()
873 regmap_update_bits(sai->regmap, FSL_SAI_TCR1(ofs), in fsl_sai_dai_probe()
874 FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth), in fsl_sai_dai_probe()
875 sai->soc_data->fifo_depth - FSL_SAI_MAXBURST_TX); in fsl_sai_dai_probe()
876 regmap_update_bits(sai->regmap, FSL_SAI_RCR1(ofs), in fsl_sai_dai_probe()
877 FSL_SAI_CR1_RFW_MASK(sai->soc_data->fifo_depth), in fsl_sai_dai_probe()
878 FSL_SAI_MAXBURST_RX - 1); in fsl_sai_dai_probe()
880 snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params_tx, in fsl_sai_dai_probe()
881 &sai->dma_params_rx); in fsl_sai_dai_probe()
889 struct device *dev = &sai->pdev->dev; in fsl_sai_dai_resume()
892 if (!IS_ERR_OR_NULL(sai->pinctrl) && !IS_ERR_OR_NULL(sai->pins_state)) { in fsl_sai_dai_resume()
893 ret = pinctrl_select_state(sai->pinctrl, sai->pins_state); in fsl_sai_dai_resume()
906 .stream_name = "CPU-Playback",
915 .stream_name = "CPU-Capture",
927 .name = "fsl-sai",
983 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_readable_reg()
1039 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_volatile_reg()
1082 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_writeable_reg()
1129 unsigned char ofs = sai->soc_data->reg_offset; in fsl_sai_check_version()
1136 ret = regmap_read(sai->regmap, FSL_SAI_VERID, &val); in fsl_sai_check_version()
1142 sai->verid.version = val & in fsl_sai_check_version()
1144 sai->verid.feature = val & FSL_SAI_VERID_FEATURE_MASK; in fsl_sai_check_version()
1146 ret = regmap_read(sai->regmap, FSL_SAI_PARAM, &val); in fsl_sai_check_version()
1153 sai->param.slot_num = 1 << in fsl_sai_check_version()
1157 sai->param.fifo_depth = 1 << in fsl_sai_check_version()
1161 sai->param.dataline = val & FSL_SAI_PARAM_DLN_MASK; in fsl_sai_check_version()
1176 offset = nbidx - fbidx - 1; in fsl_sai_calc_dl_off()
1178 return (offset < 0 || offset >= (FSL_SAI_DL_NUM - 1) ? 0 : offset); in fsl_sai_calc_dl_off()
1195 struct platform_device *pdev = sai->pdev; in fsl_sai_read_dlcfg()
1196 struct device_node *np = pdev->dev.of_node; in fsl_sai_read_dlcfg()
1197 struct device *dev = &pdev->dev; in fsl_sai_read_dlcfg()
1211 return -EINVAL; in fsl_sai_read_dlcfg()
1216 cfg = devm_kzalloc(&pdev->dev, (num_cfg + 1) * sizeof(*cfg), GFP_KERNEL); in fsl_sai_read_dlcfg()
1218 return -ENOMEM; in fsl_sai_read_dlcfg()
1221 soc_dl = BIT(sai->soc_data->pins) - 1; in fsl_sai_read_dlcfg()
1223 cfg[0].pins[0] = sai->soc_data->pins; in fsl_sai_read_dlcfg()
1228 cfg[0].pins[1] = sai->soc_data->pins; in fsl_sai_read_dlcfg()
1241 return -EINVAL; in fsl_sai_read_dlcfg()
1245 return -EINVAL; in fsl_sai_read_dlcfg()
1249 return -EINVAL; in fsl_sai_read_dlcfg()
1253 return -EINVAL; in fsl_sai_read_dlcfg()
1273 sai->dl_cfg = cfg; in fsl_sai_read_dlcfg()
1274 sai->dl_cfg_cnt = num_cfg + 1; in fsl_sai_read_dlcfg()
1283 struct device_node *np = pdev->dev.of_node; in fsl_sai_probe()
1284 struct device *dev = &pdev->dev; in fsl_sai_probe()
1295 return -ENOMEM; in fsl_sai_probe()
1297 sai->pdev = pdev; in fsl_sai_probe()
1298 sai->soc_data = of_device_get_match_data(dev); in fsl_sai_probe()
1300 sai->is_lsb_first = of_property_read_bool(np, "lsb-first"); in fsl_sai_probe()
1302 base = devm_platform_get_and_ioremap_resource(pdev, 0, &sai->res); in fsl_sai_probe()
1306 if (sai->soc_data->reg_offset == 8) { in fsl_sai_probe()
1313 sai->regmap = devm_regmap_init_mmio(dev, base, &fsl_sai_regmap_config); in fsl_sai_probe()
1314 if (IS_ERR(sai->regmap)) { in fsl_sai_probe()
1316 return PTR_ERR(sai->regmap); in fsl_sai_probe()
1319 sai->bus_clk = devm_clk_get(dev, "bus"); in fsl_sai_probe()
1321 if (IS_ERR(sai->bus_clk) && PTR_ERR(sai->bus_clk) != -EPROBE_DEFER) in fsl_sai_probe()
1322 sai->bus_clk = devm_clk_get(dev, "sai"); in fsl_sai_probe()
1323 if (IS_ERR(sai->bus_clk)) { in fsl_sai_probe()
1325 PTR_ERR(sai->bus_clk)); in fsl_sai_probe()
1326 /* -EPROBE_DEFER */ in fsl_sai_probe()
1327 return PTR_ERR(sai->bus_clk); in fsl_sai_probe()
1332 sai->mclk_clk[i] = devm_clk_get(dev, tmp); in fsl_sai_probe()
1333 if (IS_ERR(sai->mclk_clk[i])) { in fsl_sai_probe()
1335 i, PTR_ERR(sai->mclk_clk[i])); in fsl_sai_probe()
1336 sai->mclk_clk[i] = NULL; in fsl_sai_probe()
1340 if (sai->soc_data->mclk0_is_mclk1) in fsl_sai_probe()
1341 sai->mclk_clk[0] = sai->mclk_clk[1]; in fsl_sai_probe()
1343 sai->mclk_clk[0] = sai->bus_clk; in fsl_sai_probe()
1345 fsl_asoc_get_pll_clocks(&pdev->dev, &sai->pll8k_clk, in fsl_sai_probe()
1346 &sai->pll11k_clk); in fsl_sai_probe()
1350 if (!sai->soc_data->use_edma && !ret && dmas[2] == IMX_DMATYPE_MULTI_SAI) in fsl_sai_probe()
1351 sai->is_multi_fifo_dma = true; in fsl_sai_probe()
1365 np->name, sai); in fsl_sai_probe()
1371 memcpy(&sai->cpu_dai_drv, &fsl_sai_dai_template, in fsl_sai_probe()
1375 sai->synchronous[RX] = true; in fsl_sai_probe()
1376 sai->synchronous[TX] = false; in fsl_sai_probe()
1377 sai->cpu_dai_drv.symmetric_rate = 1; in fsl_sai_probe()
1378 sai->cpu_dai_drv.symmetric_channels = 1; in fsl_sai_probe()
1379 sai->cpu_dai_drv.symmetric_sample_bits = 1; in fsl_sai_probe()
1381 if (of_find_property(np, "fsl,sai-synchronous-rx", NULL) && in fsl_sai_probe()
1382 of_find_property(np, "fsl,sai-asynchronous", NULL)) { in fsl_sai_probe()
1385 return -EINVAL; in fsl_sai_probe()
1388 if (of_find_property(np, "fsl,sai-synchronous-rx", NULL)) { in fsl_sai_probe()
1390 sai->synchronous[RX] = false; in fsl_sai_probe()
1391 sai->synchronous[TX] = true; in fsl_sai_probe()
1392 } else if (of_find_property(np, "fsl,sai-asynchronous", NULL)) { in fsl_sai_probe()
1394 sai->synchronous[RX] = false; in fsl_sai_probe()
1395 sai->synchronous[TX] = false; in fsl_sai_probe()
1396 sai->cpu_dai_drv.symmetric_rate = 0; in fsl_sai_probe()
1397 sai->cpu_dai_drv.symmetric_channels = 0; in fsl_sai_probe()
1398 sai->cpu_dai_drv.symmetric_sample_bits = 0; in fsl_sai_probe()
1401 if (of_find_property(np, "fsl,sai-mclk-direction-output", NULL) && in fsl_sai_probe()
1402 of_device_is_compatible(np, "fsl,imx6ul-sai")) { in fsl_sai_probe()
1403 gpr = syscon_regmap_lookup_by_compatible("fsl,imx6ul-iomuxc-gpr"); in fsl_sai_probe()
1405 dev_err(dev, "cannot find iomuxc registers\n"); in fsl_sai_probe()
1417 sai->dma_params_rx.addr = sai->res->start + FSL_SAI_RDR0; in fsl_sai_probe()
1418 sai->dma_params_tx.addr = sai->res->start + FSL_SAI_TDR0; in fsl_sai_probe()
1419 sai->dma_params_rx.maxburst = FSL_SAI_MAXBURST_RX; in fsl_sai_probe()
1420 sai->dma_params_tx.maxburst = FSL_SAI_MAXBURST_TX; in fsl_sai_probe()
1422 sai->pinctrl = devm_pinctrl_get(&pdev->dev); in fsl_sai_probe()
1442 if (of_find_property(np, "fsl,sai-mclk-direction-output", NULL) && in fsl_sai_probe()
1443 sai->soc_data->max_register >= FSL_SAI_MCTL) { in fsl_sai_probe()
1444 regmap_update_bits(sai->regmap, FSL_SAI_MCTL, in fsl_sai_probe()
1449 if (ret < 0 && ret != -ENOSYS) in fsl_sai_probe()
1456 if (sai->soc_data->use_imx_pcm) { in fsl_sai_probe()
1460 dev_err(dev, "Error: You must enable the imx-pcm-dma support!\n"); in fsl_sai_probe()
1470 &sai->cpu_dai_drv, 1); in fsl_sai_probe()
1487 pm_runtime_disable(&pdev->dev); in fsl_sai_remove()
1488 if (!pm_runtime_status_suspended(&pdev->dev)) in fsl_sai_remove()
1489 fsl_sai_runtime_suspend(&pdev->dev); in fsl_sai_remove()
1583 { .compatible = "fsl,vf610-sai", .data = &fsl_sai_vf610_data },
1584 { .compatible = "fsl,imx6sx-sai", .data = &fsl_sai_imx6sx_data },
1585 { .compatible = "fsl,imx6ul-sai", .data = &fsl_sai_imx6sx_data },
1586 { .compatible = "fsl,imx7ulp-sai", .data = &fsl_sai_imx7ulp_data },
1587 { .compatible = "fsl,imx8mq-sai", .data = &fsl_sai_imx8mq_data },
1588 { .compatible = "fsl,imx8qm-sai", .data = &fsl_sai_imx8qm_data },
1589 { .compatible = "fsl,imx8mm-sai", .data = &fsl_sai_imx8mm_data },
1590 { .compatible = "fsl,imx8mp-sai", .data = &fsl_sai_imx8mp_data },
1591 { .compatible = "fsl,imx8ulp-sai", .data = &fsl_sai_imx8ulp_data },
1592 { .compatible = "fsl,imx8mn-sai", .data = &fsl_sai_imx8mp_data },
1601 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) in fsl_sai_runtime_suspend()
1602 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_suspend()
1604 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) in fsl_sai_runtime_suspend()
1605 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_suspend()
1607 clk_disable_unprepare(sai->bus_clk); in fsl_sai_runtime_suspend()
1609 if (sai->soc_data->flags & PMQOS_CPU_LATENCY) in fsl_sai_runtime_suspend()
1610 cpu_latency_qos_remove_request(&sai->pm_qos_req); in fsl_sai_runtime_suspend()
1612 regcache_cache_only(sai->regmap, true); in fsl_sai_runtime_suspend()
1620 unsigned int ofs = sai->soc_data->reg_offset; in fsl_sai_runtime_resume()
1623 ret = clk_prepare_enable(sai->bus_clk); in fsl_sai_runtime_resume()
1629 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) { in fsl_sai_runtime_resume()
1630 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_resume()
1635 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) { in fsl_sai_runtime_resume()
1636 ret = clk_prepare_enable(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_resume()
1641 if (sai->soc_data->flags & PMQOS_CPU_LATENCY) in fsl_sai_runtime_resume()
1642 cpu_latency_qos_add_request(&sai->pm_qos_req, 0); in fsl_sai_runtime_resume()
1644 regcache_cache_only(sai->regmap, false); in fsl_sai_runtime_resume()
1645 regcache_mark_dirty(sai->regmap); in fsl_sai_runtime_resume()
1646 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_runtime_resume()
1647 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), FSL_SAI_CSR_SR); in fsl_sai_runtime_resume()
1649 regmap_write(sai->regmap, FSL_SAI_TCSR(ofs), 0); in fsl_sai_runtime_resume()
1650 regmap_write(sai->regmap, FSL_SAI_RCSR(ofs), 0); in fsl_sai_runtime_resume()
1652 ret = regcache_sync(sai->regmap); in fsl_sai_runtime_resume()
1659 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_CAPTURE)) in fsl_sai_runtime_resume()
1660 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[0]]); in fsl_sai_runtime_resume()
1662 if (sai->mclk_streams & BIT(SNDRV_PCM_STREAM_PLAYBACK)) in fsl_sai_runtime_resume()
1663 clk_disable_unprepare(sai->mclk_clk[sai->mclk_id[1]]); in fsl_sai_runtime_resume()
1665 clk_disable_unprepare(sai->bus_clk); in fsl_sai_runtime_resume()
1681 .name = "fsl-sai",
1690 MODULE_ALIAS("platform:fsl-sai");