Lines Matching full:saif
22 #include "mxs-saif.h"
30 * SAIF is a little different with other normal SOC DAIs on clock using.
32 * For MXS, two SAIF modules are instantiated on-chip.
33 * Each SAIF has a set of clock pins and can be operating in master
36 * other SAIF, in slave mode, receives clocking from the master SAIF.
39 * We abstract this as each saif has a master, the master could be
40 * itself or other saifs. In the generic saif driver, saif does not need
41 * to know the different clkmux. Saif only needs to know who is its master
50 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_set_dai_sysclk() local
54 saif->mclk = freq; in mxs_saif_set_dai_sysclk()
63 * Since SAIF may work on EXTMASTER mode, IOW, it's working BITCLK&LRCLK
64 * is provided by other SAIF, we provide a interface here to get its master
68 static inline struct mxs_saif *mxs_saif_get_master(struct mxs_saif * saif) in mxs_saif_get_master() argument
70 return mxs_saif[saif->master_id]; in mxs_saif_get_master()
74 * Set SAIF clock and MCLK
76 static int mxs_saif_set_clk(struct mxs_saif *saif, in mxs_saif_set_clk() argument
84 dev_dbg(saif->dev, "mclk %d rate %d\n", mclk, rate); in mxs_saif_set_clk()
86 /* Set master saif to generate proper clock */ in mxs_saif_set_clk()
87 master_saif = mxs_saif_get_master(saif); in mxs_saif_set_clk()
91 dev_dbg(saif->dev, "master saif%d\n", master_saif->id); in mxs_saif_set_clk()
95 dev_err(saif->dev, in mxs_saif_set_clk()
96 "can not change clock, master saif%d(rate %d) is ongoing\n", in mxs_saif_set_clk()
106 * Set SAIF clock in mxs_saif_set_clk()
108 * The SAIF clock should be either 384*fs or 512*fs. in mxs_saif_set_clk()
109 * If MCLK is used, the SAIF clk ratio needs to match mclk ratio. in mxs_saif_set_clk()
110 * For 256x, 128x, 64x, and 32x sub-rates, set saif clk as 512*fs. in mxs_saif_set_clk()
111 * For 192x, 96x, and 48x sub-rates, set saif clk as 384*fs. in mxs_saif_set_clk()
113 * If MCLK is not used, we just set saif clk to 512*fs. in mxs_saif_set_clk()
137 /* SAIF MCLK should be a sub-rate of 512x or 384x */ in mxs_saif_set_clk()
206 struct mxs_saif *saif = mxs_saif[saif_id]; in mxs_saif_put_mclk() local
209 if (!saif) in mxs_saif_put_mclk()
212 stat = __raw_readl(saif->base + SAIF_STAT); in mxs_saif_put_mclk()
214 dev_err(saif->dev, "error: busy\n"); in mxs_saif_put_mclk()
218 clk_disable_unprepare(saif->clk); in mxs_saif_put_mclk()
222 saif->base + SAIF_CTRL + MXS_SET_ADDR); in mxs_saif_put_mclk()
224 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_put_mclk()
226 saif->mclk_in_use = 0; in mxs_saif_put_mclk()
235 * by saif.
240 struct mxs_saif *saif = mxs_saif[saif_id]; in mxs_saif_get_mclk() local
245 if (!saif) in mxs_saif_get_mclk()
250 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_get_mclk()
254 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_get_mclk()
256 master_saif = mxs_saif_get_master(saif); in mxs_saif_get_mclk()
257 if (saif != master_saif) { in mxs_saif_get_mclk()
258 dev_err(saif->dev, "can not get mclk from a non-master saif\n"); in mxs_saif_get_mclk()
262 stat = __raw_readl(saif->base + SAIF_STAT); in mxs_saif_get_mclk()
264 dev_err(saif->dev, "error: busy\n"); in mxs_saif_get_mclk()
268 saif->mclk_in_use = 1; in mxs_saif_get_mclk()
269 ret = mxs_saif_set_clk(saif, mclk, rate); in mxs_saif_get_mclk()
273 ret = clk_prepare_enable(saif->clk); in mxs_saif_get_mclk()
279 saif->base + SAIF_CTRL + MXS_SET_ADDR); in mxs_saif_get_mclk()
286 * SAIF DAI format configuration.
293 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_set_dai_fmt() local
295 stat = __raw_readl(saif->base + SAIF_STAT); in mxs_saif_set_dai_fmt()
304 if (saif->id != saif->master_id) { in mxs_saif_set_dai_fmt()
306 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_set_dai_fmt()
308 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_set_dai_fmt()
311 scr0 = __raw_readl(saif->base + SAIF_CTRL); in mxs_saif_set_dai_fmt()
354 * Note: We simply just support master mode since SAIF TX can only in mxs_saif_set_dai_fmt()
357 * Saif internally could be slave when working on EXTMASTER mode. in mxs_saif_set_dai_fmt()
362 if (saif->id == saif->master_id) in mxs_saif_set_dai_fmt()
367 __raw_writel(scr | scr0, saif->base + SAIF_CTRL); in mxs_saif_set_dai_fmt()
379 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_startup() local
383 saif->fifo_underrun = 0; in mxs_saif_startup()
384 saif->fifo_overrun = 0; in mxs_saif_startup()
388 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_startup()
392 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_startup()
394 ret = clk_prepare(saif->clk); in mxs_saif_startup()
404 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_shutdown() local
406 clk_unprepare(saif->clk); in mxs_saif_shutdown()
417 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_hw_params() local
422 master_saif = mxs_saif_get_master(saif); in mxs_saif_hw_params()
427 if (!saif->mclk && saif->mclk_in_use) { in mxs_saif_hw_params()
432 stat = __raw_readl(saif->base + SAIF_STAT); in mxs_saif_hw_params()
433 if (!saif->mclk_in_use && (stat & BM_SAIF_STAT_BUSY)) { in mxs_saif_hw_params()
439 * Set saif clk based on sample rate. in mxs_saif_hw_params()
440 * If mclk is used, we also set mclk, if not, saif->mclk is in mxs_saif_hw_params()
443 ret = mxs_saif_set_clk(saif, saif->mclk, params_rate(params)); in mxs_saif_hw_params()
449 if (saif != master_saif) { in mxs_saif_hw_params()
451 * Set an initial clock rate for the saif internal logic to work in mxs_saif_hw_params()
453 * that uses the other saif's BITCLK&LRCLK but it still needs a in mxs_saif_hw_params()
457 ret = clk_enable(saif->clk); in mxs_saif_hw_params()
461 ret = clk_set_rate(saif->clk, 24000000); in mxs_saif_hw_params()
462 clk_disable(saif->clk); in mxs_saif_hw_params()
471 scr = __raw_readl(saif->base + SAIF_CTRL); in mxs_saif_hw_params()
500 __raw_writel(scr, saif->base + SAIF_CTRL); in mxs_saif_hw_params()
507 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_prepare() local
511 saif->base + SAIF_CTRL + MXS_SET_ADDR); in mxs_saif_prepare()
519 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai); in mxs_saif_trigger() local
524 master_saif = mxs_saif_get_master(saif); in mxs_saif_trigger()
532 if (saif->state == MXS_SAIF_STATE_RUNNING) in mxs_saif_trigger()
539 dev_err(saif->dev, "Failed to enable master clock\n"); in mxs_saif_trigger()
544 * If the saif's master is not itself, we also need to enable in mxs_saif_trigger()
547 if (saif != master_saif) { in mxs_saif_trigger()
548 ret = clk_enable(saif->clk); in mxs_saif_trigger()
550 dev_err(saif->dev, "Failed to enable master clock\n"); in mxs_saif_trigger()
556 saif->base + SAIF_CTRL + MXS_SET_ADDR); in mxs_saif_trigger()
565 * write data to saif data register to trigger in mxs_saif_trigger()
571 __raw_writel(0, saif->base + SAIF_DATA); in mxs_saif_trigger()
572 __raw_writel(0, saif->base + SAIF_DATA); in mxs_saif_trigger()
575 * read data from saif data register to trigger in mxs_saif_trigger()
581 __raw_readl(saif->base + SAIF_DATA); in mxs_saif_trigger()
582 __raw_readl(saif->base + SAIF_DATA); in mxs_saif_trigger()
586 saif->state = MXS_SAIF_STATE_RUNNING; in mxs_saif_trigger()
588 dev_dbg(saif->dev, "CTRL 0x%x STAT 0x%x\n", in mxs_saif_trigger()
589 __raw_readl(saif->base + SAIF_CTRL), in mxs_saif_trigger()
590 __raw_readl(saif->base + SAIF_STAT)); in mxs_saif_trigger()
599 if (saif->state == MXS_SAIF_STATE_STOPPED) in mxs_saif_trigger()
614 if (saif != master_saif) { in mxs_saif_trigger()
616 saif->base + SAIF_CTRL + MXS_CLR_ADDR); in mxs_saif_trigger()
618 clk_disable(saif->clk); in mxs_saif_trigger()
622 saif->state = MXS_SAIF_STATE_STOPPED; in mxs_saif_trigger()
648 .name = "mxs-saif",
665 .name = "mxs-saif",
671 struct mxs_saif *saif = dev_id; in mxs_saif_irq() local
674 stat = __raw_readl(saif->base + SAIF_STAT); in mxs_saif_irq()
680 dev_dbg(saif->dev, "underrun!!! %d\n", ++saif->fifo_underrun); in mxs_saif_irq()
682 saif->base + SAIF_STAT + MXS_CLR_ADDR); in mxs_saif_irq()
686 dev_dbg(saif->dev, "overrun!!! %d\n", ++saif->fifo_overrun); in mxs_saif_irq()
688 saif->base + SAIF_STAT + MXS_CLR_ADDR); in mxs_saif_irq()
691 dev_dbg(saif->dev, "SAIF_CTRL %x SAIF_STAT %x\n", in mxs_saif_irq()
692 __raw_readl(saif->base + SAIF_CTRL), in mxs_saif_irq()
693 __raw_readl(saif->base + SAIF_STAT)); in mxs_saif_irq()
700 struct mxs_saif *saif = platform_get_drvdata(pdev); in mxs_saif_mclk_init() local
706 __clk_get_name(saif->clk), 0, in mxs_saif_mclk_init()
707 saif->base + SAIF_CTRL, in mxs_saif_mclk_init()
728 struct mxs_saif *saif; in mxs_saif_probe() local
732 saif = devm_kzalloc(&pdev->dev, sizeof(*saif), GFP_KERNEL); in mxs_saif_probe()
733 if (!saif) in mxs_saif_probe()
736 ret = of_alias_get_id(np, "saif"); in mxs_saif_probe()
740 saif->id = ret; in mxs_saif_probe()
742 if (saif->id >= ARRAY_SIZE(mxs_saif)) { in mxs_saif_probe()
743 dev_err(&pdev->dev, "get wrong saif id\n"); in mxs_saif_probe()
748 * If there is no "fsl,saif-master" phandle, it's a saif in mxs_saif_probe()
752 master = of_parse_phandle(np, "fsl,saif-master", 0); in mxs_saif_probe()
754 saif->master_id = saif->id; in mxs_saif_probe()
756 ret = of_alias_get_id(master, "saif"); in mxs_saif_probe()
761 saif->master_id = ret; in mxs_saif_probe()
763 if (saif->master_id >= ARRAY_SIZE(mxs_saif)) { in mxs_saif_probe()
769 mxs_saif[saif->id] = saif; in mxs_saif_probe()
771 saif->clk = devm_clk_get(&pdev->dev, NULL); in mxs_saif_probe()
772 if (IS_ERR(saif->clk)) { in mxs_saif_probe()
773 ret = PTR_ERR(saif->clk); in mxs_saif_probe()
779 saif->base = devm_platform_ioremap_resource(pdev, 0); in mxs_saif_probe()
780 if (IS_ERR(saif->base)) in mxs_saif_probe()
781 return PTR_ERR(saif->base); in mxs_saif_probe()
787 saif->dev = &pdev->dev; in mxs_saif_probe()
789 dev_name(&pdev->dev), saif); in mxs_saif_probe()
795 platform_set_drvdata(pdev, saif); in mxs_saif_probe()
798 if (saif->id == 0) { in mxs_saif_probe()
821 { .compatible = "fsl,imx28-saif", },
830 .name = "mxs-saif",
838 MODULE_DESCRIPTION("MXS ASoC SAIF driver");
840 MODULE_ALIAS("platform:mxs-saif");