13 #include <linux/module.h>
14 #include <linux/device.h>
15 #include <linux/slab.h>
50 #define DAVINCI_MCBSP_DRR_REG 0x00
51 #define DAVINCI_MCBSP_DXR_REG 0x04
52 #define DAVINCI_MCBSP_SPCR_REG 0x08
53 #define DAVINCI_MCBSP_RCR_REG 0x0c
54 #define DAVINCI_MCBSP_XCR_REG 0x10
55 #define DAVINCI_MCBSP_SRGR_REG 0x14
56 #define DAVINCI_MCBSP_PCR_REG 0x24
58 #define DAVINCI_MCBSP_SPCR_RRST (1 << 0)
59 #define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4)
60 #define DAVINCI_MCBSP_SPCR_XRST (1 << 16)
61 #define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20)
62 #define DAVINCI_MCBSP_SPCR_GRST (1 << 22)
63 #define DAVINCI_MCBSP_SPCR_FRST (1 << 23)
64 #define DAVINCI_MCBSP_SPCR_FREE (1 << 25)
66 #define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5)
67 #define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8)
68 #define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16)
69 #define DAVINCI_MCBSP_RCR_RFIG (1 << 18)
70 #define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21)
71 #define DAVINCI_MCBSP_RCR_RFRLEN2(v) ((v) << 24)
72 #define DAVINCI_MCBSP_RCR_RPHASE BIT(31)
74 #define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5)
75 #define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8)
76 #define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16)
77 #define DAVINCI_MCBSP_XCR_XFIG (1 << 18)
78 #define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21)
79 #define DAVINCI_MCBSP_XCR_XFRLEN2(v) ((v) << 24)
80 #define DAVINCI_MCBSP_XCR_XPHASE BIT(31)
82 #define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8)
83 #define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16)
84 #define DAVINCI_MCBSP_SRGR_FSGM (1 << 28)
85 #define DAVINCI_MCBSP_SRGR_CLKSM BIT(29)
87 #define DAVINCI_MCBSP_PCR_CLKRP (1 << 0)
88 #define DAVINCI_MCBSP_PCR_CLKXP (1 << 1)
89 #define DAVINCI_MCBSP_PCR_FSRP (1 << 2)
90 #define DAVINCI_MCBSP_PCR_FSXP (1 << 3)
91 #define DAVINCI_MCBSP_PCR_SCLKME (1 << 7)
92 #define DAVINCI_MCBSP_PCR_CLKRM (1 << 8)
93 #define DAVINCI_MCBSP_PCR_CLKXM (1 << 9)
94 #define DAVINCI_MCBSP_PCR_FSRM (1 << 10)
95 #define DAVINCI_MCBSP_PCR_FSXM (1 << 11)
194 toggle_clock(dev, playback);
206 if (platform->
driver->ops->trigger) {
207 int ret = platform->
driver->ops->trigger(substream,
225 toggle_clock(dev, playback);
228 if (platform->
driver->ops->trigger) {
229 int ret = platform->
driver->ops->trigger(substream,
256 toggle_clock(dev, playback);
259 #define DEFAULT_BITPERSAMPLE 16
261 static int davinci_i2s_set_dai_fmt(
struct snd_soc_dai *cpu_dai,
405 static int davinci_i2s_dai_set_clkdiv(
struct snd_soc_dai *cpu_dai,
425 int mcbsp_word_length, master;
426 unsigned int rcr, xcr, srgr,
clk_div,
freq, framesize;
429 unsigned element_cnt = 1;
443 mcbsp_word_length = asp_word_length[
fmt];
455 framesize = (freq / (--
clk_div)) /
458 }
while (((framesize < 33) || (framesize > 4095)) &&
464 clk_div = freq / (mcbsp_word_length * 16) /
485 pr_debug(
"%s - %d FWID set: re-read srgr = %X\n",
486 __func__, __LINE__, snd_interval_value(i) - 1);
516 fmt = double_fmt[
fmt];
537 mcbsp_word_length = asp_word_length[
fmt];
564 pr_debug(
"%s - %d srgr=%X\n", __func__, __LINE__, srgr);
565 pr_debug(
"%s - %d xcr=%X\n", __func__, __LINE__, xcr);
566 pr_debug(
"%s - %d rcr=%X\n", __func__, __LINE__, rcr);
575 davinci_mcbsp_stop(dev, playback);
590 davinci_mcbsp_start(dev, substream);
595 davinci_mcbsp_stop(dev, playback);
608 snd_soc_dai_set_dma_data(dai, substream, dev->
dma_params);
617 davinci_mcbsp_stop(dev, playback);
620 #define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
623 .startup = davinci_i2s_startup,
624 .shutdown = davinci_i2s_shutdown,
625 .prepare = davinci_i2s_prepare,
626 .trigger = davinci_i2s_trigger,
627 .hw_params = davinci_i2s_hw_params,
628 .set_fmt = davinci_i2s_set_dai_fmt,
629 .set_clkdiv = davinci_i2s_dai_set_clkdiv,
644 .ops = &davinci_i2s_dai_ops,
667 dev_err(&pdev->
dev,
"McBSP region already claimed\n");
693 if (IS_ERR(dev->
clk))
701 goto err_release_clk;
715 goto err_release_clk;
723 goto err_release_clk;
732 goto err_release_clk;
736 dev_err(&pdev->
dev,
"register PCM failed: %d\n", ret);
737 goto err_unregister_dai;
765 .probe = davinci_i2s_probe,
766 .remove = davinci_i2s_remove,
768 .name =
"davinci-mcbsp",