Lines Matching full:sai

3  * STM32 ALSA SoC Digital Audio Interface (SAI) driver.
56 #define STM_SAI_HAS_EXT_SYNC(x) (!STM_SAI_IS_F4(sai->pdata))
65 * struct stm32_sai_sub_data - private data of SAI sub block (block A or B)
67 * @regmap: SAI register map pointer
68 * @regmap_config: SAI sub block register map configuration pointer
73 * @pdata: SAI block parent data pointer
75 * @sai_ck: kernel clock feeding the SAI clock generator
76 * @sai_mclk: master clock from SAI mclk provider
77 * @phys_addr: SAI registers physical base address
78 * @mclk_rate: SAI block master clock frequency (Hz). set at init
79 * @id: SAI sub block id corresponding to sub-block A or B
80 * @dir: SAI block direction (playback or capture). set at init
81 * @master: SAI block mode flag. (true=master, false=slave) set at init
82 * @spdif: SAI S/PDIF iec60958 mode flag. set at init
83 * @fmt: SAI block format. relevant only for custom protocols. set at init
84 * @sync: SAI block synchronization mode. (none, internal or external)
85 * @synco: SAI block ext sync source (provider setting). (none, sub-block A/B)
86 * @synci: SAI block ext sync source (client setting). (SAI sync provider index)
186 static int stm32_sai_sub_reg_up(struct stm32_sai_sub_data *sai, in stm32_sai_sub_reg_up() argument
192 ret = clk_enable(sai->pdata->pclk); in stm32_sai_sub_reg_up()
196 ret = regmap_update_bits(sai->regmap, reg, mask, val); in stm32_sai_sub_reg_up()
198 clk_disable(sai->pdata->pclk); in stm32_sai_sub_reg_up()
203 static int stm32_sai_sub_reg_wr(struct stm32_sai_sub_data *sai, in stm32_sai_sub_reg_wr() argument
209 ret = clk_enable(sai->pdata->pclk); in stm32_sai_sub_reg_wr()
213 ret = regmap_write_bits(sai->regmap, reg, mask, val); in stm32_sai_sub_reg_wr()
215 clk_disable(sai->pdata->pclk); in stm32_sai_sub_reg_wr()
220 static int stm32_sai_sub_reg_rd(struct stm32_sai_sub_data *sai, in stm32_sai_sub_reg_rd() argument
225 ret = clk_enable(sai->pdata->pclk); in stm32_sai_sub_reg_rd()
229 ret = regmap_read(sai->regmap, reg, val); in stm32_sai_sub_reg_rd()
231 clk_disable(sai->pdata->pclk); in stm32_sai_sub_reg_rd()
272 struct stm32_sai_sub_data *sai = snd_kcontrol_chip(kcontrol); in snd_pcm_iec958_get() local
274 mutex_lock(&sai->ctrl_lock); in snd_pcm_iec958_get()
275 memcpy(uctl->value.iec958.status, sai->iec958.status, 4); in snd_pcm_iec958_get()
276 mutex_unlock(&sai->ctrl_lock); in snd_pcm_iec958_get()
284 struct stm32_sai_sub_data *sai = snd_kcontrol_chip(kcontrol); in snd_pcm_iec958_put() local
286 mutex_lock(&sai->ctrl_lock); in snd_pcm_iec958_put()
287 memcpy(sai->iec958.status, uctl->value.iec958.status, 4); in snd_pcm_iec958_put()
288 mutex_unlock(&sai->ctrl_lock); in snd_pcm_iec958_put()
312 static int stm32_sai_get_clk_div(struct stm32_sai_sub_data *sai, in stm32_sai_get_clk_div() argument
316 int version = sai->pdata->conf.version; in stm32_sai_get_clk_div()
321 dev_err(&sai->pdev->dev, "Divider %d out of range\n", div); in stm32_sai_get_clk_div()
324 dev_dbg(&sai->pdev->dev, "SAI divider %d\n", div); in stm32_sai_get_clk_div()
327 dev_dbg(&sai->pdev->dev, in stm32_sai_get_clk_div()
334 static int stm32_sai_set_clk_div(struct stm32_sai_sub_data *sai, in stm32_sai_set_clk_div() argument
337 int version = sai->pdata->conf.version; in stm32_sai_set_clk_div()
341 dev_err(&sai->pdev->dev, "Divider %d out of range\n", div); in stm32_sai_set_clk_div()
347 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, mask, cr1); in stm32_sai_set_clk_div()
349 dev_err(&sai->pdev->dev, "Failed to update CR1 register\n"); in stm32_sai_set_clk_div()
354 static int stm32_sai_set_parent_clock(struct stm32_sai_sub_data *sai, in stm32_sai_set_parent_clock() argument
357 struct platform_device *pdev = sai->pdev; in stm32_sai_set_parent_clock()
358 struct clk *parent_clk = sai->pdata->clk_x8k; in stm32_sai_set_parent_clock()
362 parent_clk = sai->pdata->clk_x11k; in stm32_sai_set_parent_clock()
364 ret = clk_set_parent(sai->sai_ck, parent_clk); in stm32_sai_set_parent_clock()
377 struct stm32_sai_sub_data *sai = mclk->sai_data; in stm32_sai_mclk_round_rate() local
380 div = stm32_sai_get_clk_div(sai, *prate, rate); in stm32_sai_mclk_round_rate()
401 struct stm32_sai_sub_data *sai = mclk->sai_data; in stm32_sai_mclk_set_rate() local
404 div = stm32_sai_get_clk_div(sai, parent_rate, rate); in stm32_sai_mclk_set_rate()
408 ret = stm32_sai_set_clk_div(sai, div); in stm32_sai_mclk_set_rate()
420 struct stm32_sai_sub_data *sai = mclk->sai_data; in stm32_sai_mclk_enable() local
422 dev_dbg(&sai->pdev->dev, "Enable master clock\n"); in stm32_sai_mclk_enable()
424 return stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_mclk_enable()
431 struct stm32_sai_sub_data *sai = mclk->sai_data; in stm32_sai_mclk_disable() local
433 dev_dbg(&sai->pdev->dev, "Disable master clock\n"); in stm32_sai_mclk_disable()
435 stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, SAI_XCR1_MCKEN, 0); in stm32_sai_mclk_disable()
446 static int stm32_sai_add_mclk_provider(struct stm32_sai_sub_data *sai) in stm32_sai_add_mclk_provider() argument
450 struct device *dev = &sai->pdev->dev; in stm32_sai_add_mclk_provider()
451 const char *pname = __clk_get_name(sai->sai_ck); in stm32_sai_add_mclk_provider()
473 STM_SAI_IS_SUB_A(sai) ? strcat(p, "a_mclk") : strcat(p, "b_mclk"); in stm32_sai_add_mclk_provider()
476 mclk->sai_data = sai; in stm32_sai_add_mclk_provider()
480 ret = devm_clk_hw_register(&sai->pdev->dev, hw); in stm32_sai_add_mclk_provider()
485 sai->sai_mclk = hw->clk; in stm32_sai_add_mclk_provider()
493 struct stm32_sai_sub_data *sai = (struct stm32_sai_sub_data *)devid; in stm32_sai_isr() local
494 struct platform_device *pdev = sai->pdev; in stm32_sai_isr()
498 stm32_sai_sub_reg_rd(sai, STM_SAI_IMR_REGX, &imr); in stm32_sai_isr()
499 stm32_sai_sub_reg_rd(sai, STM_SAI_SR_REGX, &sr); in stm32_sai_isr()
505 stm32_sai_sub_reg_wr(sai, STM_SAI_CLRFR_REGX, SAI_XCLRFR_MASK, in stm32_sai_isr()
508 if (!sai->substream) { in stm32_sai_isr()
515 STM_SAI_IS_PLAYBACK(sai) ? "underrun" : "overrun"); in stm32_sai_isr()
540 spin_lock(&sai->irq_lock); in stm32_sai_isr()
541 if (status != SNDRV_PCM_STATE_RUNNING && sai->substream) in stm32_sai_isr()
542 snd_pcm_stop_xrun(sai->substream); in stm32_sai_isr()
543 spin_unlock(&sai->irq_lock); in stm32_sai_isr()
551 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_sysclk() local
554 if (dir == SND_SOC_CLOCK_OUT && sai->sai_mclk) { in stm32_sai_set_sysclk()
555 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_set_sysclk()
564 if (sai->mclk_rate) { in stm32_sai_set_sysclk()
565 clk_rate_exclusive_put(sai->sai_mclk); in stm32_sai_set_sysclk()
566 sai->mclk_rate = 0; in stm32_sai_set_sysclk()
572 ret = stm32_sai_set_parent_clock(sai, freq); in stm32_sai_set_sysclk()
576 ret = clk_set_rate_exclusive(sai->sai_mclk, freq); in stm32_sai_set_sysclk()
585 dev_dbg(cpu_dai->dev, "SAI MCLK frequency is %uHz\n", freq); in stm32_sai_set_sysclk()
586 sai->mclk_rate = freq; in stm32_sai_set_sysclk()
595 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_dai_tdm_slot() local
598 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_set_dai_tdm_slot()
623 if (STM_SAI_IS_PLAYBACK(sai)) { in stm32_sai_set_dai_tdm_slot()
624 sai->slot_mask = tx_mask; in stm32_sai_set_dai_tdm_slot()
628 if (STM_SAI_IS_CAPTURE(sai)) { in stm32_sai_set_dai_tdm_slot()
629 sai->slot_mask = rx_mask; in stm32_sai_set_dai_tdm_slot()
635 stm32_sai_sub_reg_up(sai, STM_SAI_SLOTR_REGX, slotr_mask, slotr); in stm32_sai_set_dai_tdm_slot()
637 sai->slot_width = slot_width; in stm32_sai_set_dai_tdm_slot()
638 sai->slots = slots; in stm32_sai_set_dai_tdm_slot()
645 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_dai_fmt() local
657 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_set_dai_fmt()
717 stm32_sai_sub_reg_up(sai, STM_SAI_FRCR_REGX, frcr_mask, frcr); in stm32_sai_set_dai_fmt()
724 sai->master = false; in stm32_sai_set_dai_fmt()
727 sai->master = true; in stm32_sai_set_dai_fmt()
735 /* Set slave mode if sub-block is synchronized with another SAI */ in stm32_sai_set_dai_fmt()
736 if (sai->sync) { in stm32_sai_set_dai_fmt()
737 dev_dbg(cpu_dai->dev, "Synchronized SAI configured as slave\n"); in stm32_sai_set_dai_fmt()
739 sai->master = false; in stm32_sai_set_dai_fmt()
745 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, cr1_mask, cr1); in stm32_sai_set_dai_fmt()
751 sai->fmt = fmt; in stm32_sai_set_dai_fmt()
759 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_startup() local
763 spin_lock_irqsave(&sai->irq_lock, flags); in stm32_sai_startup()
764 sai->substream = substream; in stm32_sai_startup()
765 spin_unlock_irqrestore(&sai->irq_lock, flags); in stm32_sai_startup()
767 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_startup()
775 ret = clk_prepare_enable(sai->sai_ck); in stm32_sai_startup()
782 stm32_sai_sub_reg_wr(sai, STM_SAI_CLRFR_REGX, in stm32_sai_startup()
786 if (STM_SAI_IS_CAPTURE(sai)) { in stm32_sai_startup()
787 stm32_sai_sub_reg_rd(sai, STM_SAI_CR2_REGX, &cr2); in stm32_sai_startup()
792 if (sai->master) in stm32_sai_startup()
797 stm32_sai_sub_reg_up(sai, STM_SAI_IMR_REGX, in stm32_sai_startup()
807 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_config() local
812 * SAI fifo threshold is set to half fifo, to keep enough space in stm32_sai_set_config()
815 stm32_sai_sub_reg_wr(sai, STM_SAI_CR2_REGX, in stm32_sai_set_config()
821 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_set_config()
822 sai->spdif_frm_cnt = 0; in stm32_sai_set_config()
844 if ((sai->slots == 2) && (params_channels(params) == 1)) in stm32_sai_set_config()
847 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, cr1_mask, cr1); in stm32_sai_set_config()
858 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_slots() local
861 stm32_sai_sub_reg_rd(sai, STM_SAI_SLOTR_REGX, &slotr); in stm32_sai_set_slots()
869 sai->slot_width = sai->data_size; in stm32_sai_set_slots()
871 if (sai->slot_width < sai->data_size) { in stm32_sai_set_slots()
874 sai->data_size); in stm32_sai_set_slots()
879 if (!sai->slots) in stm32_sai_set_slots()
880 sai->slots = 2; in stm32_sai_set_slots()
883 stm32_sai_sub_reg_up(sai, STM_SAI_SLOTR_REGX, in stm32_sai_set_slots()
885 SAI_XSLOTR_NBSLOT_SET((sai->slots - 1))); in stm32_sai_set_slots()
889 sai->slot_mask = (1 << sai->slots) - 1; in stm32_sai_set_slots()
890 stm32_sai_sub_reg_up(sai, in stm32_sai_set_slots()
892 SAI_XSLOTR_SLOTEN_SET(sai->slot_mask)); in stm32_sai_set_slots()
896 sai->slots, sai->slot_width); in stm32_sai_set_slots()
903 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_set_frame() local
907 format = sai->fmt & SND_SOC_DAIFMT_FORMAT_MASK; in stm32_sai_set_frame()
908 sai->fs_length = sai->slot_width * sai->slots; in stm32_sai_set_frame()
910 fs_active = sai->fs_length / 2; in stm32_sai_set_frame()
915 frcr = SAI_XFRCR_FRL_SET((sai->fs_length - 1)); in stm32_sai_set_frame()
920 sai->fs_length, fs_active); in stm32_sai_set_frame()
922 stm32_sai_sub_reg_up(sai, STM_SAI_FRCR_REGX, frcr_mask, frcr); in stm32_sai_set_frame()
924 if ((sai->fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_LSB) { in stm32_sai_set_frame()
925 offset = sai->slot_width - sai->data_size; in stm32_sai_set_frame()
927 stm32_sai_sub_reg_up(sai, STM_SAI_SLOTR_REGX, in stm32_sai_set_frame()
933 static void stm32_sai_init_iec958_status(struct stm32_sai_sub_data *sai) in stm32_sai_init_iec958_status() argument
935 unsigned char *cs = sai->iec958.status; in stm32_sai_init_iec958_status()
943 static void stm32_sai_set_iec958_status(struct stm32_sai_sub_data *sai, in stm32_sai_set_iec958_status() argument
950 mutex_lock(&sai->ctrl_lock); in stm32_sai_set_iec958_status()
953 sai->iec958.status[3] = IEC958_AES3_CON_FS_22050; in stm32_sai_set_iec958_status()
956 sai->iec958.status[3] = IEC958_AES3_CON_FS_44100; in stm32_sai_set_iec958_status()
959 sai->iec958.status[3] = IEC958_AES3_CON_FS_88200; in stm32_sai_set_iec958_status()
962 sai->iec958.status[3] = IEC958_AES3_CON_FS_176400; in stm32_sai_set_iec958_status()
965 sai->iec958.status[3] = IEC958_AES3_CON_FS_24000; in stm32_sai_set_iec958_status()
968 sai->iec958.status[3] = IEC958_AES3_CON_FS_48000; in stm32_sai_set_iec958_status()
971 sai->iec958.status[3] = IEC958_AES3_CON_FS_96000; in stm32_sai_set_iec958_status()
974 sai->iec958.status[3] = IEC958_AES3_CON_FS_192000; in stm32_sai_set_iec958_status()
977 sai->iec958.status[3] = IEC958_AES3_CON_FS_32000; in stm32_sai_set_iec958_status()
980 sai->iec958.status[3] = IEC958_AES3_CON_FS_NOTID; in stm32_sai_set_iec958_status()
983 mutex_unlock(&sai->ctrl_lock); in stm32_sai_set_iec958_status()
989 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_configure_clock() local
995 if (!sai->sai_mclk) { in stm32_sai_configure_clock()
996 ret = stm32_sai_set_parent_clock(sai, rate); in stm32_sai_configure_clock()
1000 sai_clk_rate = clk_get_rate(sai->sai_ck); in stm32_sai_configure_clock()
1002 if (STM_SAI_IS_F4(sai->pdata)) { in stm32_sai_configure_clock()
1010 if (!sai->mclk_rate) in stm32_sai_configure_clock()
1013 if (2 * sai_clk_rate >= 3 * sai->mclk_rate) { in stm32_sai_configure_clock()
1014 div = stm32_sai_get_clk_div(sai, sai_clk_rate, in stm32_sai_configure_clock()
1015 2 * sai->mclk_rate); in stm32_sai_configure_clock()
1029 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_configure_clock()
1030 div = stm32_sai_get_clk_div(sai, sai_clk_rate, in stm32_sai_configure_clock()
1035 if (sai->mclk_rate) { in stm32_sai_configure_clock()
1036 mclk_ratio = sai->mclk_rate / rate; in stm32_sai_configure_clock()
1046 stm32_sai_sub_reg_up(sai, in stm32_sai_configure_clock()
1050 div = stm32_sai_get_clk_div(sai, sai_clk_rate, in stm32_sai_configure_clock()
1051 sai->mclk_rate); in stm32_sai_configure_clock()
1056 den = sai->fs_length * params_rate(params); in stm32_sai_configure_clock()
1057 div = stm32_sai_get_clk_div(sai, sai_clk_rate, in stm32_sai_configure_clock()
1065 return stm32_sai_set_clk_div(sai, div); in stm32_sai_configure_clock()
1072 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_hw_params() local
1075 sai->data_size = params_width(params); in stm32_sai_hw_params()
1077 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_hw_params()
1080 stm32_sai_set_iec958_status(sai, substream->runtime); in stm32_sai_hw_params()
1092 if (sai->master) in stm32_sai_hw_params()
1101 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_trigger() local
1108 dev_dbg(cpu_dai->dev, "Enable DMA and SAI\n"); in stm32_sai_trigger()
1110 stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_trigger()
1113 /* Enable SAI */ in stm32_sai_trigger()
1114 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_trigger()
1122 dev_dbg(cpu_dai->dev, "Disable DMA and SAI\n"); in stm32_sai_trigger()
1124 stm32_sai_sub_reg_up(sai, STM_SAI_IMR_REGX, in stm32_sai_trigger()
1127 stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_trigger()
1131 ret = stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, in stm32_sai_trigger()
1137 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) in stm32_sai_trigger()
1138 sai->spdif_frm_cnt = 0; in stm32_sai_trigger()
1150 struct stm32_sai_sub_data *sai = snd_soc_dai_get_drvdata(cpu_dai); in stm32_sai_shutdown() local
1153 stm32_sai_sub_reg_up(sai, STM_SAI_IMR_REGX, SAI_XIMR_MASK, 0); in stm32_sai_shutdown()
1155 clk_disable_unprepare(sai->sai_ck); in stm32_sai_shutdown()
1157 spin_lock_irqsave(&sai->irq_lock, flags); in stm32_sai_shutdown()
1158 sai->substream = NULL; in stm32_sai_shutdown()
1159 spin_unlock_irqrestore(&sai->irq_lock, flags); in stm32_sai_shutdown()
1165 struct stm32_sai_sub_data *sai = dev_get_drvdata(cpu_dai->dev); in stm32_sai_pcm_new() local
1168 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) { in stm32_sai_pcm_new()
1169 dev_dbg(&sai->pdev->dev, "%s: register iec controls", __func__); in stm32_sai_pcm_new()
1171 return snd_ctl_add(rtd->pcm->card, snd_ctl_new1(&knew, sai)); in stm32_sai_pcm_new()
1179 struct stm32_sai_sub_data *sai = dev_get_drvdata(cpu_dai->dev); in stm32_sai_dai_probe() local
1182 sai->cpu_dai = cpu_dai; in stm32_sai_dai_probe()
1184 sai->dma_params.addr = (dma_addr_t)(sai->phys_addr + STM_SAI_DR_REGX); in stm32_sai_dai_probe()
1190 sai->dma_params.maxburst = 4; in stm32_sai_dai_probe()
1191 if (sai->pdata->conf.fifo_size < 8) in stm32_sai_dai_probe()
1192 sai->dma_params.maxburst = 1; in stm32_sai_dai_probe()
1194 sai->dma_params.addr_width = DMA_SLAVE_BUSWIDTH_UNDEFINED; in stm32_sai_dai_probe()
1196 if (STM_SAI_IS_PLAYBACK(sai)) in stm32_sai_dai_probe()
1197 snd_soc_dai_init_dma_data(cpu_dai, &sai->dma_params, NULL); in stm32_sai_dai_probe()
1199 snd_soc_dai_init_dma_data(cpu_dai, NULL, &sai->dma_params); in stm32_sai_dai_probe()
1202 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) in stm32_sai_dai_probe()
1206 if (STM_SAI_IS_CAPTURE(sai)) in stm32_sai_dai_probe()
1210 if (sai->sync == SAI_SYNC_EXTERNAL) { in stm32_sai_dai_probe()
1212 ret = sai->pdata->set_sync(sai->pdata, sai->np_sync_provider, in stm32_sai_dai_probe()
1213 sai->synco, sai->synci); in stm32_sai_dai_probe()
1219 cr1 |= SAI_XCR1_SYNCEN_SET(sai->sync); in stm32_sai_dai_probe()
1221 return stm32_sai_sub_reg_up(sai, STM_SAI_CR1_REGX, cr1_mask, cr1); in stm32_sai_dai_probe()
1254 struct stm32_sai_sub_data *sai = dev_get_drvdata(cpu_dai->dev); in stm32_sai_pcm_process_spdif() local
1258 unsigned int frm_cnt = sai->spdif_frm_cnt; in stm32_sai_pcm_process_spdif()
1268 if (sai->iec958.status[byte] & mask) in stm32_sai_pcm_process_spdif()
1278 sai->spdif_frm_cnt = frm_cnt; in stm32_sai_pcm_process_spdif()
1348 .name = "stm32-sai",
1353 { .compatible = "st,stm32-sai-sub-a",
1355 { .compatible = "st,stm32-sai-sub-b",
1362 struct stm32_sai_sub_data *sai) in stm32_sai_sub_parse_of() argument
1377 sai->phys_addr = res->start; in stm32_sai_sub_parse_of()
1379 sai->regmap_config = &stm32_sai_sub_regmap_config_f4; in stm32_sai_sub_parse_of()
1381 if (STM_SAI_HAS_PDM(sai) && STM_SAI_IS_SUB_A(sai)) in stm32_sai_sub_parse_of()
1382 sai->regmap_config = &stm32_sai_sub_regmap_config_h7; in stm32_sai_sub_parse_of()
1386 * can lead to circular locking issue with sai master clock provider. in stm32_sai_sub_parse_of()
1389 sai->regmap = devm_regmap_init_mmio(&pdev->dev, base, in stm32_sai_sub_parse_of()
1390 sai->regmap_config); in stm32_sai_sub_parse_of()
1391 if (IS_ERR(sai->regmap)) in stm32_sai_sub_parse_of()
1392 return dev_err_probe(&pdev->dev, PTR_ERR(sai->regmap), in stm32_sai_sub_parse_of()
1397 sai->dir = SNDRV_PCM_STREAM_PLAYBACK; in stm32_sai_sub_parse_of()
1399 sai->dir = SNDRV_PCM_STREAM_CAPTURE; in stm32_sai_sub_parse_of()
1406 sai->spdif = false; in stm32_sai_sub_parse_of()
1408 if (!STM_SAI_HAS_SPDIF(sai) || in stm32_sai_sub_parse_of()
1409 sai->dir == SNDRV_PCM_STREAM_CAPTURE) { in stm32_sai_sub_parse_of()
1413 stm32_sai_init_iec958_status(sai); in stm32_sai_sub_parse_of()
1414 sai->spdif = true; in stm32_sai_sub_parse_of()
1415 sai->master = true; in stm32_sai_sub_parse_of()
1426 sai->sync = SAI_SYNC_NONE; in stm32_sai_sub_parse_of()
1434 sai->np_sync_provider = of_get_parent(args.np); in stm32_sai_sub_parse_of()
1435 if (!sai->np_sync_provider) { in stm32_sai_sub_parse_of()
1442 sai->sync = SAI_SYNC_INTERNAL; in stm32_sai_sub_parse_of()
1443 if (sai->np_sync_provider != sai->pdata->pdev->dev.of_node) { in stm32_sai_sub_parse_of()
1444 if (!STM_SAI_HAS_EXT_SYNC(sai)) { in stm32_sai_sub_parse_of()
1450 sai->sync = SAI_SYNC_EXTERNAL; in stm32_sai_sub_parse_of()
1452 sai->synci = args.args[0]; in stm32_sai_sub_parse_of()
1453 if (sai->synci < 1 || in stm32_sai_sub_parse_of()
1454 (sai->synci > (SAI_GCR_SYNCIN_MAX + 1))) { in stm32_sai_sub_parse_of()
1455 dev_err(&pdev->dev, "Wrong SAI index\n"); in stm32_sai_sub_parse_of()
1461 "st,stm32-sai-sub-a") >= 0) in stm32_sai_sub_parse_of()
1462 sai->synco = STM_SAI_SYNC_OUT_A; in stm32_sai_sub_parse_of()
1465 "st,stm32-sai-sub-b") >= 0) in stm32_sai_sub_parse_of()
1466 sai->synco = STM_SAI_SYNC_OUT_B; in stm32_sai_sub_parse_of()
1468 if (!sai->synco) { in stm32_sai_sub_parse_of()
1469 dev_err(&pdev->dev, "Unknown SAI sub-block\n"); in stm32_sai_sub_parse_of()
1480 sai->sai_ck = devm_clk_get(&pdev->dev, "sai_ck"); in stm32_sai_sub_parse_of()
1481 if (IS_ERR(sai->sai_ck)) in stm32_sai_sub_parse_of()
1482 return dev_err_probe(&pdev->dev, PTR_ERR(sai->sai_ck), in stm32_sai_sub_parse_of()
1485 ret = clk_prepare(sai->pdata->pclk); in stm32_sai_sub_parse_of()
1489 if (STM_SAI_IS_F4(sai->pdata)) in stm32_sai_sub_parse_of()
1494 ret = stm32_sai_add_mclk_provider(sai); in stm32_sai_sub_parse_of()
1498 sai->sai_mclk = devm_clk_get_optional(&pdev->dev, "MCLK"); in stm32_sai_sub_parse_of()
1499 if (IS_ERR(sai->sai_mclk)) in stm32_sai_sub_parse_of()
1500 return PTR_ERR(sai->sai_mclk); in stm32_sai_sub_parse_of()
1508 struct stm32_sai_sub_data *sai; in stm32_sai_sub_probe() local
1512 sai = devm_kzalloc(&pdev->dev, sizeof(*sai), GFP_KERNEL); in stm32_sai_sub_probe()
1513 if (!sai) in stm32_sai_sub_probe()
1516 sai->id = (uintptr_t)device_get_match_data(&pdev->dev); in stm32_sai_sub_probe()
1518 sai->pdev = pdev; in stm32_sai_sub_probe()
1519 mutex_init(&sai->ctrl_lock); in stm32_sai_sub_probe()
1520 spin_lock_init(&sai->irq_lock); in stm32_sai_sub_probe()
1521 platform_set_drvdata(pdev, sai); in stm32_sai_sub_probe()
1523 sai->pdata = dev_get_drvdata(pdev->dev.parent); in stm32_sai_sub_probe()
1524 if (!sai->pdata) { in stm32_sai_sub_probe()
1529 ret = stm32_sai_sub_parse_of(pdev, sai); in stm32_sai_sub_probe()
1533 if (STM_SAI_IS_PLAYBACK(sai)) in stm32_sai_sub_probe()
1534 sai->cpu_dai_drv = stm32_sai_playback_dai; in stm32_sai_sub_probe()
1536 sai->cpu_dai_drv = stm32_sai_capture_dai; in stm32_sai_sub_probe()
1537 sai->cpu_dai_drv.name = dev_name(&pdev->dev); in stm32_sai_sub_probe()
1539 ret = devm_request_irq(&pdev->dev, sai->pdata->irq, stm32_sai_isr, in stm32_sai_sub_probe()
1540 IRQF_SHARED, dev_name(&pdev->dev), sai); in stm32_sai_sub_probe()
1546 if (STM_SAI_PROTOCOL_IS_SPDIF(sai)) in stm32_sai_sub_probe()
1554 &sai->cpu_dai_drv, 1); in stm32_sai_sub_probe()
1567 struct stm32_sai_sub_data *sai = dev_get_drvdata(&pdev->dev); in stm32_sai_sub_remove() local
1569 clk_unprepare(sai->pdata->pclk); in stm32_sai_sub_remove()
1578 struct stm32_sai_sub_data *sai = dev_get_drvdata(dev); in stm32_sai_sub_suspend() local
1581 ret = clk_enable(sai->pdata->pclk); in stm32_sai_sub_suspend()
1585 regcache_cache_only(sai->regmap, true); in stm32_sai_sub_suspend()
1586 regcache_mark_dirty(sai->regmap); in stm32_sai_sub_suspend()
1588 clk_disable(sai->pdata->pclk); in stm32_sai_sub_suspend()
1595 struct stm32_sai_sub_data *sai = dev_get_drvdata(dev); in stm32_sai_sub_resume() local
1598 ret = clk_enable(sai->pdata->pclk); in stm32_sai_sub_resume()
1602 regcache_cache_only(sai->regmap, false); in stm32_sai_sub_resume()
1603 ret = regcache_sync(sai->regmap); in stm32_sai_sub_resume()
1605 clk_disable(sai->pdata->pclk); in stm32_sai_sub_resume()
1617 .name = "st,stm32-sai-sub",
1627 MODULE_DESCRIPTION("STM32 Soc SAI sub-block Interface");
1629 MODULE_ALIAS("platform:st,stm32-sai-sub");