2 * sound/soc/omap/mcbsp.h
4 * OMAP Multi-Channel Buffered Serial Port
6 * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
7 * Peter Ujfalusi <peter.ujfalusi@ti.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #ifndef __ASOC_MCBSP_H
25 #define __ASOC_MCBSP_H
27 #ifdef CONFIG_ARCH_OMAP1
28 #define mcbsp_omap1() 1
30 #define mcbsp_omap1() 0
33 #include <sound/dmaengine_pcm.h>
35 /* McBSP register numbers. Register address offset = num * reg_step */
37 /* Common registers */
38 OMAP_MCBSP_REG_SPCR2
= 4,
66 /* OMAP1-OMAP2420 registers */
67 OMAP_MCBSP_REG_DRR2
= 0,
72 /* OMAP2430 and onwards */
73 OMAP_MCBSP_REG_DRR
= 0,
74 OMAP_MCBSP_REG_DXR
= 2,
75 OMAP_MCBSP_REG_SYSCON
= 35,
76 OMAP_MCBSP_REG_THRSH2
,
77 OMAP_MCBSP_REG_THRSH1
,
78 OMAP_MCBSP_REG_IRQST
= 40,
80 OMAP_MCBSP_REG_WAKEUPEN
,
83 OMAP_MCBSP_REG_XBUFFSTAT
,
84 OMAP_MCBSP_REG_RBUFFSTAT
,
85 OMAP_MCBSP_REG_SSELCR
,
88 /* OMAP3 sidetone control registers */
89 #define OMAP_ST_REG_REV 0x00
90 #define OMAP_ST_REG_SYSCONFIG 0x10
91 #define OMAP_ST_REG_IRQSTATUS 0x18
92 #define OMAP_ST_REG_IRQENABLE 0x1C
93 #define OMAP_ST_REG_SGAINCR 0x24
94 #define OMAP_ST_REG_SFIRCR 0x28
95 #define OMAP_ST_REG_SSELCR 0x2C
97 /************************** McBSP SPCR1 bit definitions ***********************/
101 #define RSYNC_ERR BIT(3)
102 #define RINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
105 #define CLKSTP(value) (((value) & 0x3) << 11) /* bits 11:12 */
106 #define RJUST(value) (((value) & 0x3) << 13) /* bits 13:14 */
110 /************************** McBSP SPCR2 bit definitions ***********************/
113 #define XEMPTY BIT(2)
114 #define XSYNC_ERR BIT(3)
115 #define XINTM(value) (((value) & 0x3) << 4) /* bits 4:5 */
121 /************************** McBSP PCR bit definitions *************************/
126 #define DR_STAT BIT(4)
127 #define DX_STAT BIT(5)
128 #define CLKS_STAT BIT(6)
129 #define SCLKME BIT(7)
134 #define RIOEN BIT(12)
135 #define XIOEN BIT(13)
136 #define IDLE_EN BIT(14)
138 /************************** McBSP RCR1 bit definitions ************************/
139 #define RWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
140 #define RFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
142 /************************** McBSP XCR1 bit definitions ************************/
143 #define XWDLEN1(value) (((value) & 0x7) << 5) /* Bits 5:7 */
144 #define XFRLEN1(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
146 /*************************** McBSP RCR2 bit definitions ***********************/
147 #define RDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
149 #define RCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
150 #define RWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
151 #define RFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
152 #define RPHASE BIT(15)
154 /*************************** McBSP XCR2 bit definitions ***********************/
155 #define XDATDLY(value) ((value) & 0x3) /* Bits 0:1 */
157 #define XCOMPAND(value) (((value) & 0x3) << 3) /* Bits 3:4 */
158 #define XWDLEN2(value) (((value) & 0x7) << 5) /* Bits 5:7 */
159 #define XFRLEN2(value) (((value) & 0x7f) << 8) /* Bits 8:14 */
160 #define XPHASE BIT(15)
162 /************************* McBSP SRGR1 bit definitions ************************/
163 #define CLKGDV(value) ((value) & 0x7f) /* Bits 0:7 */
164 #define FWID(value) (((value) & 0xff) << 8) /* Bits 8:15 */
166 /************************* McBSP SRGR2 bit definitions ************************/
167 #define FPER(value) ((value) & 0x0fff) /* Bits 0:11 */
169 #define CLKSM BIT(13)
170 #define CLKSP BIT(14)
171 #define GSYNC BIT(15)
173 /************************* McBSP MCR1 bit definitions *************************/
175 #define RCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
176 #define RPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
177 #define RPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
179 /************************* McBSP MCR2 bit definitions *************************/
180 #define XMCM(value) ((value) & 0x3) /* Bits 0:1 */
181 #define XCBLK(value) (((value) & 0x7) << 2) /* Bits 2:4 */
182 #define XPABLK(value) (((value) & 0x3) << 5) /* Bits 5:6 */
183 #define XPBBLK(value) (((value) & 0x3) << 7) /* Bits 7:8 */
185 /*********************** McBSP XCCR bit definitions *************************/
186 #define XDISABLE BIT(0)
187 #define XDMAEN BIT(3)
189 #define XFULL_CYCLE BIT(11)
190 #define DXENDLY(value) (((value) & 0x3) << 12) /* Bits 12:13 */
191 #define PPCONNECT BIT(14)
192 #define EXTCLKGATE BIT(15)
194 /********************** McBSP RCCR bit definitions *************************/
195 #define RDISABLE BIT(0)
196 #define RDMAEN BIT(3)
197 #define RFULL_CYCLE BIT(11)
199 /********************** McBSP SYSCONFIG bit definitions ********************/
200 #define SOFTRST BIT(1)
201 #define ENAWAKEUP BIT(2)
202 #define SIDLEMODE(value) (((value) & 0x3) << 3)
203 #define CLOCKACTIVITY(value) (((value) & 0x3) << 8)
205 /********************** McBSP SSELCR bit definitions ***********************/
206 #define SIDETONEEN BIT(10)
208 /********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
209 #define ST_AUTOIDLE BIT(0)
211 /********************** McBSP Sidetone SGAINCR bit definitions *************/
212 #define ST_CH0GAIN(value) ((value) & 0xffff) /* Bits 0:15 */
213 #define ST_CH1GAIN(value) (((value) & 0xffff) << 16) /* Bits 16:31 */
215 /********************** McBSP Sidetone SFIRCR bit definitions **************/
216 #define ST_FIRCOEFF(value) ((value) & 0xffff) /* Bits 0:15 */
218 /********************** McBSP Sidetone SSELCR bit definitions **************/
219 #define ST_SIDETONEEN BIT(0)
220 #define ST_COEFFWREN BIT(1)
221 #define ST_COEFFWRDONE BIT(2)
223 /********************** McBSP DMA operating modes **************************/
224 #define MCBSP_DMA_MODE_ELEMENT 0
225 #define MCBSP_DMA_MODE_THRESHOLD 1
227 /********************** McBSP WAKEUPEN/IRQST/IRQEN bit definitions *********/
228 #define RSYNCERREN BIT(0)
229 #define RFSREN BIT(1)
230 #define REOFEN BIT(2)
231 #define RRDYEN BIT(3)
232 #define RUNDFLEN BIT(4)
233 #define ROVFLEN BIT(5)
234 #define XSYNCERREN BIT(7)
235 #define XFSXEN BIT(8)
236 #define XEOFEN BIT(9)
237 #define XRDYEN BIT(10)
238 #define XUNDFLEN BIT(11)
239 #define XOVFLEN BIT(12)
240 #define XEMPTYEOFEN BIT(14)
242 /* Clock signal muxing options */
243 #define CLKR_SRC_CLKR 0 /* CLKR signal is from the CLKR pin */
244 #define CLKR_SRC_CLKX 1 /* CLKR signal is from the CLKX pin */
245 #define FSR_SRC_FSR 2 /* FSR signal is from the FSR pin */
246 #define FSR_SRC_FSX 3 /* FSR signal is from the FSX pin */
248 /* McBSP functional clock sources */
249 #define MCBSP_CLKS_PRCM_SRC 0
250 #define MCBSP_CLKS_PAD_SRC 1
252 /* we don't do multichannel for now */
253 struct omap_mcbsp_reg_cfg
{
281 struct omap_mcbsp_st_data
{
282 void __iomem
*io_base_st
;
285 s16 taps
[128]; /* Sidetone filter coefficients */
286 int nr_taps
; /* Number of filter coefficients in use */
295 unsigned long phys_base
;
296 unsigned long phys_dma_base
;
297 void __iomem
*io_base
;
300 * Flags indicating is the bus already activated and configured by
311 /* Protect the field .free, while checking if the mcbsp is in use */
312 struct omap_mcbsp_platform_data
*pdata
;
313 struct omap_mcbsp_st_data
*st_data
;
314 struct omap_mcbsp_reg_cfg cfg_regs
;
315 struct snd_dmaengine_dai_dma_data dma_data
[2];
316 unsigned int dma_req
[2];
324 unsigned int in_freq
;
329 void omap_mcbsp_config(struct omap_mcbsp
*mcbsp
,
330 const struct omap_mcbsp_reg_cfg
*config
);
331 void omap_mcbsp_set_tx_threshold(struct omap_mcbsp
*mcbsp
, u16 threshold
);
332 void omap_mcbsp_set_rx_threshold(struct omap_mcbsp
*mcbsp
, u16 threshold
);
333 u16
omap_mcbsp_get_tx_delay(struct omap_mcbsp
*mcbsp
);
334 u16
omap_mcbsp_get_rx_delay(struct omap_mcbsp
*mcbsp
);
335 int omap_mcbsp_get_dma_op_mode(struct omap_mcbsp
*mcbsp
);
336 int omap_mcbsp_request(struct omap_mcbsp
*mcbsp
);
337 void omap_mcbsp_free(struct omap_mcbsp
*mcbsp
);
338 void omap_mcbsp_start(struct omap_mcbsp
*mcbsp
, int tx
, int rx
);
339 void omap_mcbsp_stop(struct omap_mcbsp
*mcbsp
, int tx
, int rx
);
341 /* McBSP functional clock source changing function */
342 int omap2_mcbsp_set_clks_src(struct omap_mcbsp
*mcbsp
, u8 fck_src_id
);
344 /* Sidetone specific API */
345 int omap_st_set_chgain(struct omap_mcbsp
*mcbsp
, int channel
, s16 chgain
);
346 int omap_st_get_chgain(struct omap_mcbsp
*mcbsp
, int channel
, s16
*chgain
);
347 int omap_st_enable(struct omap_mcbsp
*mcbsp
);
348 int omap_st_disable(struct omap_mcbsp
*mcbsp
);
349 int omap_st_is_enabled(struct omap_mcbsp
*mcbsp
);
351 int omap_mcbsp_init(struct platform_device
*pdev
);
352 void omap_mcbsp_sysfs_remove(struct omap_mcbsp
*mcbsp
);
354 #endif /* __ASOC_MCBSP_H */