19 #include <linux/module.h>
20 #include <linux/device.h>
21 #include <linux/slab.h>
41 #define DAVINCI_MCASP_PID_REG 0x00
42 #define DAVINCI_MCASP_PWREMUMGT_REG 0x04
44 #define DAVINCI_MCASP_PFUNC_REG 0x10
45 #define DAVINCI_MCASP_PDIR_REG 0x14
46 #define DAVINCI_MCASP_PDOUT_REG 0x18
47 #define DAVINCI_MCASP_PDSET_REG 0x1c
49 #define DAVINCI_MCASP_PDCLR_REG 0x20
51 #define DAVINCI_MCASP_TLGC_REG 0x30
52 #define DAVINCI_MCASP_TLMR_REG 0x34
54 #define DAVINCI_MCASP_GBLCTL_REG 0x44
55 #define DAVINCI_MCASP_AMUTE_REG 0x48
56 #define DAVINCI_MCASP_LBCTL_REG 0x4c
58 #define DAVINCI_MCASP_TXDITCTL_REG 0x50
60 #define DAVINCI_MCASP_GBLCTLR_REG 0x60
61 #define DAVINCI_MCASP_RXMASK_REG 0x64
62 #define DAVINCI_MCASP_RXFMT_REG 0x68
63 #define DAVINCI_MCASP_RXFMCTL_REG 0x6c
65 #define DAVINCI_MCASP_ACLKRCTL_REG 0x70
66 #define DAVINCI_MCASP_AHCLKRCTL_REG 0x74
67 #define DAVINCI_MCASP_RXTDM_REG 0x78
68 #define DAVINCI_MCASP_EVTCTLR_REG 0x7c
70 #define DAVINCI_MCASP_RXSTAT_REG 0x80
71 #define DAVINCI_MCASP_RXTDMSLOT_REG 0x84
72 #define DAVINCI_MCASP_RXCLKCHK_REG 0x88
73 #define DAVINCI_MCASP_REVTCTL_REG 0x8c
75 #define DAVINCI_MCASP_GBLCTLX_REG 0xa0
76 #define DAVINCI_MCASP_TXMASK_REG 0xa4
77 #define DAVINCI_MCASP_TXFMT_REG 0xa8
78 #define DAVINCI_MCASP_TXFMCTL_REG 0xac
80 #define DAVINCI_MCASP_ACLKXCTL_REG 0xb0
81 #define DAVINCI_MCASP_AHCLKXCTL_REG 0xb4
82 #define DAVINCI_MCASP_TXTDM_REG 0xb8
83 #define DAVINCI_MCASP_EVTCTLX_REG 0xbc
85 #define DAVINCI_MCASP_TXSTAT_REG 0xc0
86 #define DAVINCI_MCASP_TXTDMSLOT_REG 0xc4
87 #define DAVINCI_MCASP_TXCLKCHK_REG 0xc8
88 #define DAVINCI_MCASP_XEVTCTL_REG 0xcc
91 #define DAVINCI_MCASP_DITCSRA_REG 0x100
93 #define DAVINCI_MCASP_DITCSRB_REG 0x118
95 #define DAVINCI_MCASP_DITUDRA_REG 0x130
97 #define DAVINCI_MCASP_DITUDRB_REG 0x148
100 #define DAVINCI_MCASP_XRSRCTL_BASE_REG 0x180
101 #define DAVINCI_MCASP_XRSRCTL_REG(n) (DAVINCI_MCASP_XRSRCTL_BASE_REG + \
105 #define DAVINCI_MCASP_TXBUF_REG 0x200
107 #define DAVINCI_MCASP_RXBUF_REG 0x280
110 #define DAVINCI_MCASP_WFIFOCTL (0x1010)
111 #define DAVINCI_MCASP_WFIFOSTS (0x1014)
112 #define DAVINCI_MCASP_RFIFOCTL (0x1018)
113 #define DAVINCI_MCASP_RFIFOSTS (0x101C)
114 #define MCASP_VER3_WFIFOCTL (0x1000)
115 #define MCASP_VER3_WFIFOSTS (0x1004)
116 #define MCASP_VER3_RFIFOCTL (0x1008)
117 #define MCASP_VER3_RFIFOSTS (0x100C)
123 #define MCASP_FREE BIT(0)
124 #define MCASP_SOFT BIT(1)
129 #define AXR(n) (1<<n)
130 #define PFUNC_AMUTE BIT(25)
131 #define ACLKX BIT(26)
132 #define AHCLKX BIT(27)
134 #define ACLKR BIT(29)
135 #define AHCLKR BIT(30)
141 #define AXR(n) (1<<n)
142 #define PDIR_AMUTE BIT(25)
143 #define ACLKX BIT(26)
144 #define AHCLKX BIT(27)
146 #define ACLKR BIT(29)
147 #define AHCLKR BIT(30)
160 #define TXROT(val) (val)
162 #define TXSSZ(val) (val<<4)
163 #define TXPBIT(val) (val<<8)
164 #define TXPAD(val) (val<<13)
165 #define TXORD BIT(15)
166 #define FSXDLY(val) (val<<16)
171 #define RXROT(val) (val)
173 #define RXSSZ(val) (val<<4)
174 #define RXPBIT(val) (val<<8)
175 #define RXPAD(val) (val<<13)
176 #define RXORD BIT(15)
177 #define FSRDLY(val) (val<<16)
182 #define FSXPOL BIT(0)
184 #define FSXDUR BIT(4)
185 #define FSXMOD(val) (val<<7)
190 #define FSRPOL BIT(0)
192 #define FSRDUR BIT(4)
193 #define FSRMOD(val) (val<<7)
198 #define ACLKXDIV(val) (val)
199 #define ACLKXE BIT(5)
200 #define TX_ASYNC BIT(6)
201 #define ACLKXPOL BIT(7)
206 #define ACLKRDIV(val) (val)
207 #define ACLKRE BIT(5)
208 #define RX_ASYNC BIT(6)
209 #define ACLKRPOL BIT(7)
215 #define AHCLKXDIV(val) (val)
216 #define AHCLKXPOL BIT(14)
217 #define AHCLKXE BIT(15)
223 #define AHCLKRDIV(val) (val)
224 #define AHCLKRPOL BIT(14)
225 #define AHCLKRE BIT(15)
230 #define MODE(val) (val)
231 #define DISMOD (val)(val<<2)
232 #define TXSTATE BIT(4)
233 #define RXSTATE BIT(5)
240 #define LBGENMODE(val) (val<<2)
245 #define TXTDMS(n) (1<<n)
250 #define RXTDMS(n) (1<<n)
255 #define RXCLKRST BIT(0)
256 #define RXHCLKRST BIT(1)
257 #define RXSERCLR BIT(2)
258 #define RXSMRST BIT(3)
259 #define RXFSRST BIT(4)
260 #define TXCLKRST BIT(8)
261 #define TXHCLKRST BIT(9)
262 #define TXSERCLR BIT(10)
263 #define TXSMRST BIT(11)
264 #define TXFSRST BIT(12)
269 #define MUTENA(val) (val)
270 #define MUTEINPOL BIT(2)
271 #define MUTEINENA BIT(3)
272 #define MUTEIN BIT(4)
275 #define MUTEFSR BIT(7)
276 #define MUTEFSX BIT(8)
277 #define MUTEBADCLKR BIT(9)
278 #define MUTEBADCLKX BIT(10)
279 #define MUTERXDMAERR BIT(11)
280 #define MUTETXDMAERR BIT(12)
285 #define RXDATADMADIS BIT(0)
290 #define TXDATADMADIS BIT(0)
295 #define FIFO_ENABLE BIT(16)
296 #define NUMEVT_MASK (0xFF << 8)
297 #define NUMDMA_MASK (0xFF)
299 #define DAVINCI_MCASP_NUM_SERIALIZER 16
316 static inline void mcasp_set_reg(
void __iomem *reg,
u32 val)
321 static inline u32 mcasp_get_reg(
void __iomem *reg)
330 mcasp_set_bits(regs, val);
334 for (i = 0; i < 1000; i++) {
335 if ((mcasp_get_reg(regs) & val) == val)
339 if (i == 1000 && ((mcasp_get_reg(regs) & val) != val))
399 mcasp_clr_bits(dev->
base +
401 mcasp_set_bits(dev->
base +
416 mcasp_clr_bits(dev->
base +
418 mcasp_set_bits(dev->
base +
448 mcasp_clr_bits(dev->
base +
462 mcasp_clr_bits(dev->
base +
470 static int davinci_mcasp_set_dai_fmt(
struct snd_soc_dai *cpu_dai,
563 switch (channel_size) {
704 for (i = 0; i < active_slots; i++)
788 davinci_hw_common_param(dev, substream->
stream);
795 davinci_hw_dit_param(dev);
797 davinci_hw_param(dev, substream->
stream);
824 dma_params->
acnt = 4;
829 davinci_config_channel_size(dev, word_length);
844 ret = pm_runtime_get_sync(dev->
dev);
846 dev_err(dev->
dev,
"pm_runtime_get_sync() failed\n");
847 davinci_mcasp_start(dev, substream->
stream);
851 davinci_mcasp_stop(dev, substream->
stream);
852 ret = pm_runtime_put_sync(dev->
dev);
854 dev_err(dev->
dev,
"pm_runtime_put_sync() failed\n");
859 davinci_mcasp_stop(dev, substream->
stream);
874 snd_soc_dai_set_dma_data(dai, substream, dev->
dma_params);
879 .startup = davinci_mcasp_startup,
880 .trigger = davinci_mcasp_trigger,
881 .hw_params = davinci_mcasp_hw_params,
882 .set_fmt = davinci_mcasp_set_dai_fmt,
886 #define DAVINCI_MCASP_PCM_FMTS (SNDRV_PCM_FMTBIT_S8 | \
887 SNDRV_PCM_FMTBIT_U8 | \
888 SNDRV_PCM_FMTBIT_S16_LE | \
889 SNDRV_PCM_FMTBIT_U16_LE | \
890 SNDRV_PCM_FMTBIT_S32_LE | \
891 SNDRV_PCM_FMTBIT_U32_LE)
895 .name =
"davinci-mcasp.0",
908 .ops = &davinci_mcasp_dai_ops,
919 .ops = &davinci_mcasp_dai_ops,
926 .compatible =
"ti,dm646x-mcasp-audio",
930 .compatible =
"ti,da830-mcasp-audio",
934 .compatible =
"ti,omap2-mcasp-audio",
949 const u32 *of_serial_dir32;
954 if (pdev->
dev.platform_data) {
955 pdata = pdev->
dev.platform_data;
972 ret = of_property_read_u32(np,
"op-mode", &val);
976 ret = of_property_read_u32(np,
"tdm-slots", &val);
980 ret = of_property_read_u32(np,
"num-serializer", &val);
988 "num-serializer(%d) != serial-dir size(%d)\n",
994 if (of_serial_dir32) {
996 (
sizeof(*of_serial_dir) * val),
998 if (!of_serial_dir) {
1009 ret = of_property_read_u32(np,
"tx-num-evt", &val);
1013 ret = of_property_read_u32(np,
"rx-num-evt", &val);
1017 ret = of_property_read_u32(np,
"sram-size-playback", &val);
1021 ret = of_property_read_u32(np,
"sram-size-capture", &val);
1029 dev_err(&pdev->
dev,
"Error populating platform data, err %d\n",
1044 if (!pdev->
dev.platform_data && !pdev->
dev.of_node) {
1045 dev_err(&pdev->
dev,
"No platform data supplied\n");
1054 pdata = davinci_mcasp_set_pdata_from_of(pdev);
1067 resource_size(mem), pdev->
name);
1069 dev_err(&pdev->
dev,
"Audio region already claimed\n");
1075 ret = pm_runtime_get_sync(&pdev->
dev);
1077 dev_err(&pdev->
dev,
"pm_runtime_get_sync() failed\n");
1085 goto err_release_clk;
1110 goto err_release_clk;
1126 goto err_release_clk;
1134 goto err_release_clk;
1138 dev_err(&pdev->
dev,
"register PCM failed: %d\n", ret);
1139 goto err_unregister_dai;
1147 pm_runtime_put_sync(&pdev->
dev);
1148 pm_runtime_disable(&pdev->
dev);
1158 pm_runtime_put_sync(&pdev->
dev);
1159 pm_runtime_disable(&pdev->
dev);
1165 .probe = davinci_mcasp_probe,
1166 .remove = davinci_mcasp_remove,
1168 .name =
"davinci-mcasp",