1 /* SPDX-License-Identifier: GPL-2.0 */
3 * OMAP Multi-Channel Buffered Serial Port
5 * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
6 * Peter Ujfalusi <peter.ujfalusi@ti.com>
9 #ifndef __OMAP_MCBSP_PRIV_H__
10 #define __OMAP_MCBSP_PRIV_H__
12 #include <linux/platform_data/asoc-ti-mcbsp.h>
14 #ifdef CONFIG_ARCH_OMAP1
15 #define mcbsp_omap1() 1
17 #define mcbsp_omap1() 0
20 /* McBSP register numbers. Register address offset = num * reg_step */
22 /* Common registers */
23 OMAP_MCBSP_REG_SPCR2
= 4,
51 /* OMAP1-OMAP2420 registers */
52 OMAP_MCBSP_REG_DRR2
= 0,
57 /* OMAP2430 and onwards */
58 OMAP_MCBSP_REG_DRR
= 0,
59 OMAP_MCBSP_REG_DXR
= 2,
60 OMAP_MCBSP_REG_SYSCON
= 35,
61 OMAP_MCBSP_REG_THRSH2
,
62 OMAP_MCBSP_REG_THRSH1
,
63 OMAP_MCBSP_REG_IRQST
= 40,
65 OMAP_MCBSP_REG_WAKEUPEN
,
68 OMAP_MCBSP_REG_XBUFFSTAT
,
69 OMAP_MCBSP_REG_RBUFFSTAT
,
70 OMAP_MCBSP_REG_SSELCR
,
73 /************************** McBSP SPCR1 bit definitions ***********************/
77 #define RSYNC_ERR BIT(3)
78 #define RINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
81 #define CLKSTP(value) (((value) & 0x3) << 11) /* bits 11:12 */
82 #define RJUST(value) (((value) & 0x3) << 13) /* bits 13:14 */
86 /************************** McBSP SPCR2 bit definitions ***********************/
90 #define XSYNC_ERR BIT(3)
91 #define XINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
97 /************************** McBSP PCR bit definitions *************************/
102 #define DR_STAT BIT(4)
103 #define DX_STAT BIT(5)
104 #define CLKS_STAT BIT(6)
105 #define SCLKME BIT(7)
110 #define RIOEN BIT(12)
111 #define XIOEN BIT(13)
112 #define IDLE_EN BIT(14)
114 /************************** McBSP RCR1 bit definitions ************************/
115 #define RWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
116 #define RFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
118 /************************** McBSP XCR1 bit definitions ************************/
119 #define XWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
120 #define XFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
122 /*************************** McBSP RCR2 bit definitions ***********************/
123 #define RDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
125 #define RCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
126 #define RWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
127 #define RFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
128 #define RPHASE BIT(15)
130 /*************************** McBSP XCR2 bit definitions ***********************/
131 #define XDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
133 #define XCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
134 #define XWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
135 #define XFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
136 #define XPHASE BIT(15)
138 /************************* McBSP SRGR1 bit definitions ************************/
139 #define CLKGDV(value) ((value) & 0x7f) /* Bits 0:7 */
140 #define FWID(value) (((value) & 0xff) << 8) /* Bits 8:15 */
142 /************************* McBSP SRGR2 bit definitions ************************/
143 #define FPER(value) ((value) & 0x0fff) /* Bits 0:11 */
145 #define CLKSM BIT(13)
146 #define CLKSP BIT(14)
147 #define GSYNC BIT(15)
149 /************************* McBSP MCR1 bit definitions *************************/
151 #define RCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
152 #define RPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
153 #define RPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
155 /************************* McBSP MCR2 bit definitions *************************/
156 #define XMCM(value) ((value) & 0x3) /* Bits 0:1 */
157 #define XCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
158 #define XPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
159 #define XPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
161 /*********************** McBSP XCCR bit definitions *************************/
162 #define XDISABLE BIT(0)
163 #define XDMAEN BIT(3)
165 #define XFULL_CYCLE BIT(11)
166 #define DXENDLY(value) (((value) & 0x3) << 12) /* Bits 12:13 */
167 #define PPCONNECT BIT(14)
168 #define EXTCLKGATE BIT(15)
170 /********************** McBSP RCCR bit definitions *************************/
171 #define RDISABLE BIT(0)
172 #define RDMAEN BIT(3)
173 #define RFULL_CYCLE BIT(11)
175 /********************** McBSP SYSCONFIG bit definitions ********************/
176 #define SOFTRST BIT(1)
177 #define ENAWAKEUP BIT(2)
178 #define SIDLEMODE(value) (((value) & 0x3) << 3)
179 #define CLOCKACTIVITY(value) (((value) & 0x3) << 8)
181 /********************** McBSP DMA operating modes **************************/
182 #define MCBSP_DMA_MODE_ELEMENT 0
183 #define MCBSP_DMA_MODE_THRESHOLD 1
185 /********************** McBSP WAKEUPEN/IRQST/IRQEN bit definitions *********/
186 #define RSYNCERREN BIT(0)
187 #define RFSREN BIT(1)
188 #define REOFEN BIT(2)
189 #define RRDYEN BIT(3)
190 #define RUNDFLEN BIT(4)
191 #define ROVFLEN BIT(5)
192 #define XSYNCERREN BIT(7)
193 #define XFSXEN BIT(8)
194 #define XEOFEN BIT(9)
195 #define XRDYEN BIT(10)
196 #define XUNDFLEN BIT(11)
197 #define XOVFLEN BIT(12)
198 #define XEMPTYEOFEN BIT(14)
200 /* Clock signal muxing options */
201 #define CLKR_SRC_CLKR 0 /* CLKR signal is from the CLKR pin */
202 #define CLKR_SRC_CLKX 1 /* CLKR signal is from the CLKX pin */
203 #define FSR_SRC_FSR 2 /* FSR signal is from the FSR pin */
204 #define FSR_SRC_FSX 3 /* FSR signal is from the FSX pin */
206 /* McBSP functional clock sources */
207 #define MCBSP_CLKS_PRCM_SRC 0
208 #define MCBSP_CLKS_PAD_SRC 1
210 /* we don't do multichannel for now */
211 struct omap_mcbsp_reg_cfg
{
239 struct omap_mcbsp_st_data
;
245 unsigned long phys_base
;
246 unsigned long phys_dma_base
;
247 void __iomem
*io_base
;
250 * Flags indicating is the bus already activated and configured by
261 /* Protect the field .free, while checking if the mcbsp is in use */
262 struct omap_mcbsp_platform_data
*pdata
;
263 struct omap_mcbsp_st_data
*st_data
;
264 struct omap_mcbsp_reg_cfg cfg_regs
;
265 struct snd_dmaengine_dai_dma_data dma_data
[2];
266 unsigned int dma_req
[2];
274 unsigned int in_freq
;
275 unsigned int latency
[2];
279 struct pm_qos_request pm_qos_req
;
282 static inline void omap_mcbsp_write(struct omap_mcbsp
*mcbsp
, u16 reg
, u32 val
)
284 void __iomem
*addr
= mcbsp
->io_base
+ reg
* mcbsp
->pdata
->reg_step
;
286 if (mcbsp
->pdata
->reg_size
== 2) {
287 ((u16
*)mcbsp
->reg_cache
)[reg
] = (u16
)val
;
288 writew_relaxed((u16
)val
, addr
);
290 ((u32
*)mcbsp
->reg_cache
)[reg
] = val
;
291 writel_relaxed(val
, addr
);
295 static inline int omap_mcbsp_read(struct omap_mcbsp
*mcbsp
, u16 reg
,
298 void __iomem
*addr
= mcbsp
->io_base
+ reg
* mcbsp
->pdata
->reg_step
;
300 if (mcbsp
->pdata
->reg_size
== 2) {
301 return !from_cache
? readw_relaxed(addr
) :
302 ((u16
*)mcbsp
->reg_cache
)[reg
];
304 return !from_cache
? readl_relaxed(addr
) :
305 ((u32
*)mcbsp
->reg_cache
)[reg
];
309 #define MCBSP_READ(mcbsp, reg) \
310 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
311 #define MCBSP_WRITE(mcbsp, reg, val) \
312 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
313 #define MCBSP_READ_CACHE(mcbsp, reg) \
314 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
317 /* Sidetone specific API */
318 int omap_mcbsp_st_init(struct platform_device
*pdev
);
319 void omap_mcbsp_st_cleanup(struct platform_device
*pdev
);
321 int omap_mcbsp_st_start(struct omap_mcbsp
*mcbsp
);
322 int omap_mcbsp_st_stop(struct omap_mcbsp
*mcbsp
);
324 #endif /* __OMAP_MCBSP_PRIV_H__ */