19 #include <linux/module.h>
24 #include <linux/slab.h>
28 #include <linux/time.h>
37 #include <mach/hardware.h>
62 static int mxs_saif_set_dai_sysclk(
struct snd_soc_dai *cpu_dai,
63 int clk_id,
unsigned int freq,
int dir)
65 struct mxs_saif *
saif = snd_soc_dai_get_drvdata(cpu_dai);
83 static inline struct mxs_saif *mxs_saif_get_master(
struct mxs_saif * saif)
91 static int mxs_saif_set_clk(
struct mxs_saif *saif,
97 struct mxs_saif *master_saif;
99 dev_dbg(saif->
dev,
"mclk %d rate %d\n", mclk, rate);
102 master_saif = mxs_saif_get_master(saif);
111 "can not change clock, master saif%d(rate %d) is ongoing\n",
130 clk_prepare_enable(master_saif->
clk);
133 if (mclk % 32 == 0) {
136 }
else if (mclk % 48 == 0) {
141 clk_disable_unprepare(master_saif->
clk);
149 clk_disable_unprepare(master_saif->
clk);
167 switch (mclk / rate) {
209 struct mxs_saif *saif = mxs_saif[saif_id];
221 clk_disable_unprepare(saif->
clk);
242 struct mxs_saif *saif = mxs_saif[saif_id];
245 struct mxs_saif *master_saif;
258 master_saif = mxs_saif_get_master(saif);
259 if (saif != master_saif) {
260 dev_err(saif->
dev,
"can not get mclk from a non-master saif\n");
271 ret = mxs_saif_set_clk(saif, mclk, rate);
275 ret = clk_prepare_enable(saif->
clk);
290 static int mxs_saif_set_dai_fmt(
struct snd_soc_dai *cpu_dai,
unsigned int fmt)
294 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
370 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
371 snd_soc_dai_set_dma_data(cpu_dai, substream, &saif->
dma_param);
396 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
397 struct mxs_saif *master_saif;
401 master_saif = mxs_saif_get_master(saif);
412 if (stat & BM_SAIF_STAT_BUSY) {
424 dev_err(cpu_dai->
dev,
"unable to get proper clk\n");
430 if (saif != master_saif) {
483 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
495 struct mxs_saif *saif = snd_soc_dai_get_drvdata(cpu_dai);
496 struct mxs_saif *master_saif;
499 master_saif = mxs_saif_get_master(saif);
518 if (saif != master_saif) {
552 dev_dbg(master_saif->
dev,
"CTRL 0x%x STAT 0x%x\n",
571 if (saif != master_saif) {
588 #define MXS_SAIF_RATES SNDRV_PCM_RATE_8000_192000
589 #define MXS_SAIF_FORMATS \
590 (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
591 SNDRV_PCM_FMTBIT_S24_LE)
594 .startup = mxs_saif_startup,
595 .trigger = mxs_saif_trigger,
596 .prepare = mxs_saif_prepare,
597 .hw_params = mxs_saif_hw_params,
598 .set_sysclk = mxs_saif_set_dai_sysclk,
599 .set_fmt = mxs_saif_set_dai_fmt,
606 snd_soc_dai_set_drvdata(dai, saif);
613 .probe = mxs_saif_dai_probe,
626 .ops = &mxs_saif_dai_ops,
631 struct mxs_saif *saif =
dev_id;
651 dev_dbg(saif->
dev,
"SAIF_CTRL %x SAIF_STAT %x\n",
662 struct mxs_saif *
saif;
695 pdata = pdev->
dev.platform_data;
707 mxs_saif[saif->
id] =
saif;
709 pinctrl = devm_pinctrl_get_select_default(&pdev->
dev);
710 if (IS_ERR(pinctrl)) {
711 ret = PTR_ERR(pinctrl);
716 if (IS_ERR(saif->
clk)) {
717 ret = PTR_ERR(saif->
clk);
718 dev_err(&pdev->
dev,
"Cannot get the clock: %d\n",
737 ret = of_property_read_u32(np,
"fsl,saif-dma-channel",
740 dev_err(&pdev->
dev,
"failed to get dma channel\n");
750 dev_err(&pdev->
dev,
"failed to get irq resource: %d\n",
756 ret = devm_request_irq(&pdev->
dev, saif->
irq, mxs_saif_irq, 0,
759 dev_err(&pdev->
dev,
"failed to request irq\n");
766 dev_err(&pdev->
dev,
"failed to get dma irq resource: %d\n",
771 platform_set_drvdata(pdev, saif);
781 dev_err(&pdev->
dev,
"register PCM failed: %d\n", ret);
782 goto failed_pdev_alloc;
802 { .compatible =
"fsl,imx28-saif", },
808 .probe = mxs_saif_probe,
814 .of_match_table = mxs_saif_dt_ids,