2 * arch/arm/plat-omap/include/mach/mcbsp.h
4 * Defines for Multi-Channel Buffered Serial Port
6 * Copyright (C) 2002 RidgeRun, Inc.
7 * Author: Steve Johnson
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 __ASM_ARCH_OMAP_MCBSP_H
25 #define __ASM_ARCH_OMAP_MCBSP_H
27 #include <linux/completion.h>
28 #include <linux/spinlock.h>
30 #include <mach/hardware.h>
31 #include <plat/clock.h>
33 /* macro for building platform_device for McBSP ports */
34 #define OMAP_MCBSP_PLATFORM_DEVICE(port_nr) \
35 static struct platform_device omap_mcbsp##port_nr = { \
36 .name = "omap-mcbsp-dai", \
37 .id = OMAP_MCBSP##port_nr, \
40 #define OMAP7XX_MCBSP1_BASE 0xfffb1000
41 #define OMAP7XX_MCBSP2_BASE 0xfffb1800
43 #define OMAP1510_MCBSP1_BASE 0xe1011800
44 #define OMAP1510_MCBSP2_BASE 0xfffb1000
45 #define OMAP1510_MCBSP3_BASE 0xe1017000
47 #define OMAP1610_MCBSP1_BASE 0xe1011800
48 #define OMAP1610_MCBSP2_BASE 0xfffb1000
49 #define OMAP1610_MCBSP3_BASE 0xe1017000
51 #define OMAP24XX_MCBSP1_BASE 0x48074000
52 #define OMAP24XX_MCBSP2_BASE 0x48076000
53 #define OMAP2430_MCBSP3_BASE 0x4808c000
54 #define OMAP2430_MCBSP4_BASE 0x4808e000
55 #define OMAP2430_MCBSP5_BASE 0x48096000
57 #define OMAP34XX_MCBSP1_BASE 0x48074000
58 #define OMAP34XX_MCBSP2_BASE 0x49022000
59 #define OMAP34XX_MCBSP2_ST_BASE 0x49028000
60 #define OMAP34XX_MCBSP3_BASE 0x49024000
61 #define OMAP34XX_MCBSP3_ST_BASE 0x4902A000
62 #define OMAP34XX_MCBSP3_BASE 0x49024000
63 #define OMAP34XX_MCBSP4_BASE 0x49026000
64 #define OMAP34XX_MCBSP5_BASE 0x48096000
66 #define OMAP44XX_MCBSP1_BASE 0x40122000
67 #define OMAP44XX_MCBSP1_DMA_BASE 0x49022000
68 #define OMAP44XX_MCBSP2_BASE 0x40124000
69 #define OMAP44XX_MCBSP2_DMA_BASE 0x49024000
70 #define OMAP44XX_MCBSP3_BASE 0x40126000
71 #define OMAP44XX_MCBSP3_DMA_BASE 0x49026000
72 #define OMAP44XX_MCBSP4_BASE 0x48096000
74 #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
76 #define OMAP_MCBSP_REG_DRR2 0x00
77 #define OMAP_MCBSP_REG_DRR1 0x02
78 #define OMAP_MCBSP_REG_DXR2 0x04
79 #define OMAP_MCBSP_REG_DXR1 0x06
80 #define OMAP_MCBSP_REG_SPCR2 0x08
81 #define OMAP_MCBSP_REG_SPCR1 0x0a
82 #define OMAP_MCBSP_REG_RCR2 0x0c
83 #define OMAP_MCBSP_REG_RCR1 0x0e
84 #define OMAP_MCBSP_REG_XCR2 0x10
85 #define OMAP_MCBSP_REG_XCR1 0x12
86 #define OMAP_MCBSP_REG_SRGR2 0x14
87 #define OMAP_MCBSP_REG_SRGR1 0x16
88 #define OMAP_MCBSP_REG_MCR2 0x18
89 #define OMAP_MCBSP_REG_MCR1 0x1a
90 #define OMAP_MCBSP_REG_RCERA 0x1c
91 #define OMAP_MCBSP_REG_RCERB 0x1e
92 #define OMAP_MCBSP_REG_XCERA 0x20
93 #define OMAP_MCBSP_REG_XCERB 0x22
94 #define OMAP_MCBSP_REG_PCR0 0x24
95 #define OMAP_MCBSP_REG_RCERC 0x26
96 #define OMAP_MCBSP_REG_RCERD 0x28
97 #define OMAP_MCBSP_REG_XCERC 0x2A
98 #define OMAP_MCBSP_REG_XCERD 0x2C
99 #define OMAP_MCBSP_REG_RCERE 0x2E
100 #define OMAP_MCBSP_REG_RCERF 0x30
101 #define OMAP_MCBSP_REG_XCERE 0x32
102 #define OMAP_MCBSP_REG_XCERF 0x34
103 #define OMAP_MCBSP_REG_RCERG 0x36
104 #define OMAP_MCBSP_REG_RCERH 0x38
105 #define OMAP_MCBSP_REG_XCERG 0x3A
106 #define OMAP_MCBSP_REG_XCERH 0x3C
108 /* Dummy defines, these are not available on omap1 */
109 #define OMAP_MCBSP_REG_XCCR 0x00
110 #define OMAP_MCBSP_REG_RCCR 0x00
114 #define OMAP_MCBSP_REG_DRR2 0x00
115 #define OMAP_MCBSP_REG_DRR1 0x04
116 #define OMAP_MCBSP_REG_DXR2 0x08
117 #define OMAP_MCBSP_REG_DXR1 0x0C
118 #define OMAP_MCBSP_REG_DRR 0x00
119 #define OMAP_MCBSP_REG_DXR 0x08
120 #define OMAP_MCBSP_REG_SPCR2 0x10
121 #define OMAP_MCBSP_REG_SPCR1 0x14
122 #define OMAP_MCBSP_REG_RCR2 0x18
123 #define OMAP_MCBSP_REG_RCR1 0x1C
124 #define OMAP_MCBSP_REG_XCR2 0x20
125 #define OMAP_MCBSP_REG_XCR1 0x24
126 #define OMAP_MCBSP_REG_SRGR2 0x28
127 #define OMAP_MCBSP_REG_SRGR1 0x2C
128 #define OMAP_MCBSP_REG_MCR2 0x30
129 #define OMAP_MCBSP_REG_MCR1 0x34
130 #define OMAP_MCBSP_REG_RCERA 0x38
131 #define OMAP_MCBSP_REG_RCERB 0x3C
132 #define OMAP_MCBSP_REG_XCERA 0x40
133 #define OMAP_MCBSP_REG_XCERB 0x44
134 #define OMAP_MCBSP_REG_PCR0 0x48
135 #define OMAP_MCBSP_REG_RCERC 0x4C
136 #define OMAP_MCBSP_REG_RCERD 0x50
137 #define OMAP_MCBSP_REG_XCERC 0x54
138 #define OMAP_MCBSP_REG_XCERD 0x58
139 #define OMAP_MCBSP_REG_RCERE 0x5C
140 #define OMAP_MCBSP_REG_RCERF 0x60
141 #define OMAP_MCBSP_REG_XCERE 0x64
142 #define OMAP_MCBSP_REG_XCERF 0x68
143 #define OMAP_MCBSP_REG_RCERG 0x6C
144 #define OMAP_MCBSP_REG_RCERH 0x70
145 #define OMAP_MCBSP_REG_XCERG 0x74
146 #define OMAP_MCBSP_REG_XCERH 0x78
147 #define OMAP_MCBSP_REG_SYSCON 0x8C
148 #define OMAP_MCBSP_REG_THRSH2 0x90
149 #define OMAP_MCBSP_REG_THRSH1 0x94
150 #define OMAP_MCBSP_REG_IRQST 0xA0
151 #define OMAP_MCBSP_REG_IRQEN 0xA4
152 #define OMAP_MCBSP_REG_WAKEUPEN 0xA8
153 #define OMAP_MCBSP_REG_XCCR 0xAC
154 #define OMAP_MCBSP_REG_RCCR 0xB0
155 #define OMAP_MCBSP_REG_XBUFFSTAT 0xB4
156 #define OMAP_MCBSP_REG_RBUFFSTAT 0xB8
157 #define OMAP_MCBSP_REG_SSELCR 0xBC
159 #define OMAP_ST_REG_REV 0x00
160 #define OMAP_ST_REG_SYSCONFIG 0x10
161 #define OMAP_ST_REG_IRQSTATUS 0x18
162 #define OMAP_ST_REG_IRQENABLE 0x1C
163 #define OMAP_ST_REG_SGAINCR 0x24
164 #define OMAP_ST_REG_SFIRCR 0x28
165 #define OMAP_ST_REG_SSELCR 0x2C
169 /************************** McBSP SPCR1 bit definitions ***********************/
173 #define RSYNC_ERR 0x0008
174 #define RINTM(value) ((value)<<4) /* bits 4:5 */
177 #define CLKSTP(value) ((value)<<11) /* bits 11:12 */
178 #define RJUST(value) ((value)<<13) /* bits 13:14 */
182 /************************** McBSP SPCR2 bit definitions ***********************/
185 #define XEMPTY 0x0004
186 #define XSYNC_ERR 0x0008
187 #define XINTM(value) ((value)<<4) /* bits 4:5 */
193 /************************** McBSP PCR bit definitions *************************/
198 #define DR_STAT 0x0010
199 #define DX_STAT 0x0020
200 #define CLKS_STAT 0x0040
201 #define SCLKME 0x0080
208 #define IDLE_EN 0x4000
210 /************************** McBSP RCR1 bit definitions ************************/
211 #define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
212 #define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
214 /************************** McBSP XCR1 bit definitions ************************/
215 #define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
216 #define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
218 /*************************** McBSP RCR2 bit definitions ***********************/
219 #define RDATDLY(value) (value) /* Bits 0:1 */
221 #define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
222 #define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
223 #define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
224 #define RPHASE 0x8000
226 /*************************** McBSP XCR2 bit definitions ***********************/
227 #define XDATDLY(value) (value) /* Bits 0:1 */
229 #define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
230 #define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
231 #define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
232 #define XPHASE 0x8000
234 /************************* McBSP SRGR1 bit definitions ************************/
235 #define CLKGDV(value) (value) /* Bits 0:7 */
236 #define FWID(value) ((value)<<8) /* Bits 8:15 */
238 /************************* McBSP SRGR2 bit definitions ************************/
239 #define FPER(value) (value) /* Bits 0:11 */
245 /************************* McBSP MCR1 bit definitions *************************/
247 #define RCBLK(value) ((value)<<2) /* Bits 2:4 */
248 #define RPABLK(value) ((value)<<5) /* Bits 5:6 */
249 #define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
251 /************************* McBSP MCR2 bit definitions *************************/
252 #define XMCM(value) (value) /* Bits 0:1 */
253 #define XCBLK(value) ((value)<<2) /* Bits 2:4 */
254 #define XPABLK(value) ((value)<<5) /* Bits 5:6 */
255 #define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
257 /*********************** McBSP XCCR bit definitions *************************/
258 #define EXTCLKGATE 0x8000
259 #define PPCONNECT 0x4000
260 #define DXENDLY(value) ((value)<<12) /* Bits 12:13 */
261 #define XFULL_CYCLE 0x0800
263 #define XDMAEN 0x0008
264 #define XDISABLE 0x0001
266 /********************** McBSP RCCR bit definitions *************************/
267 #define RFULL_CYCLE 0x0800
268 #define RDMAEN 0x0008
269 #define RDISABLE 0x0001
271 /********************** McBSP SYSCONFIG bit definitions ********************/
272 #define CLOCKACTIVITY(value) ((value)<<8)
273 #define SIDLEMODE(value) ((value)<<3)
274 #define ENAWAKEUP 0x0004
275 #define SOFTRST 0x0002
277 /********************** McBSP SSELCR bit definitions ***********************/
278 #define SIDETONEEN 0x0400
280 /********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
281 #define ST_AUTOIDLE 0x0001
283 /********************** McBSP Sidetone SGAINCR bit definitions *************/
284 #define ST_CH1GAIN(value) ((value<<16)) /* Bits 16:31 */
285 #define ST_CH0GAIN(value) (value) /* Bits 0:15 */
287 /********************** McBSP Sidetone SFIRCR bit definitions **************/
288 #define ST_FIRCOEFF(value) (value) /* Bits 0:15 */
290 /********************** McBSP Sidetone SSELCR bit definitions **************/
291 #define ST_COEFFWRDONE 0x0004
292 #define ST_COEFFWREN 0x0002
293 #define ST_SIDETONEEN 0x0001
295 /********************** McBSP DMA operating modes **************************/
296 #define MCBSP_DMA_MODE_ELEMENT 0
297 #define MCBSP_DMA_MODE_THRESHOLD 1
298 #define MCBSP_DMA_MODE_FRAME 2
300 /********************** McBSP WAKEUPEN bit definitions *********************/
301 #define XEMPTYEOFEN 0x4000
302 #define XRDYEN 0x0400
303 #define XEOFEN 0x0200
304 #define XFSXEN 0x0100
305 #define XSYNCERREN 0x0080
306 #define RRDYEN 0x0008
307 #define REOFEN 0x0004
308 #define RFSREN 0x0002
309 #define RSYNCERREN 0x0001
311 /* CLKR signal muxing options */
312 #define CLKR_SRC_CLKR 0
313 #define CLKR_SRC_CLKX 1
315 /* FSR signal muxing options */
316 #define FSR_SRC_FSR 0
317 #define FSR_SRC_FSX 1
319 /* McBSP functional clock sources */
320 #define MCBSP_CLKS_PRCM_SRC 0
321 #define MCBSP_CLKS_PAD_SRC 1
323 /* we don't do multichannel for now */
324 struct omap_mcbsp_reg_cfg {
360 typedef int __bitwise omap_mcbsp_io_type_t;
361 #define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
362 #define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
365 OMAP_MCBSP_WORD_8 = 0,
371 } omap_mcbsp_word_length;
374 OMAP_MCBSP_CLK_RISING = 0,
375 OMAP_MCBSP_CLK_FALLING,
376 } omap_mcbsp_clk_polarity;
379 OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
380 OMAP_MCBSP_FS_ACTIVE_LOW,
381 } omap_mcbsp_fs_polarity;
384 OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
385 OMAP_MCBSP_CLK_STP_MODE_DELAY,
386 } omap_mcbsp_clk_stp_mode;
389 /******* SPI specific mode **********/
391 OMAP_MCBSP_SPI_MASTER = 0,
392 OMAP_MCBSP_SPI_SLAVE,
393 } omap_mcbsp_spi_mode;
395 struct omap_mcbsp_spi_cfg {
396 omap_mcbsp_spi_mode spi_mode;
397 omap_mcbsp_clk_polarity rx_clock_polarity;
398 omap_mcbsp_clk_polarity tx_clock_polarity;
399 omap_mcbsp_fs_polarity fsx_polarity;
401 omap_mcbsp_clk_stp_mode clk_stp_mode;
402 omap_mcbsp_word_length word_length;
405 /* Platform specific configuration */
406 struct omap_mcbsp_ops {
407 void (*request)(unsigned int);
408 void (*free)(unsigned int);
409 int (*set_clks_src)(u8, u8);
412 struct omap_mcbsp_platform_data {
413 unsigned long phys_base;
414 u8 dma_rx_sync, dma_tx_sync;
416 struct omap_mcbsp_ops *ops;
417 #ifdef CONFIG_ARCH_OMAP3
418 /* Sidetone block for McBSP 2 and 3 */
419 unsigned long phys_base_st;
424 struct omap_mcbsp_st_data {
425 void __iomem *io_base_st;
428 s16 taps[128]; /* Sidetone filter coefficients */
429 int nr_taps; /* Number of filter coefficients in use */
436 unsigned long phys_base;
437 unsigned long phys_dma_base;
438 void __iomem *io_base;
441 omap_mcbsp_word_length rx_word_length;
442 omap_mcbsp_word_length tx_word_length;
444 omap_mcbsp_io_type_t io_type; /* IRQ or poll */
445 /* IRQ based TX/RX */
455 /* Completion queues */
456 struct completion tx_irq_completion;
457 struct completion rx_irq_completion;
458 struct completion tx_dma_completion;
459 struct completion rx_dma_completion;
461 /* Protect the field .free, while checking if the mcbsp is in use */
463 struct omap_mcbsp_platform_data *pdata;
466 #ifdef CONFIG_ARCH_OMAP3
467 struct omap_mcbsp_st_data *st_data;
474 extern struct omap_mcbsp **mcbsp_ptr;
475 extern int omap_mcbsp_count, omap_mcbsp_cache_size;
477 #define omap_mcbsp_check_valid_id(id) (id < omap_mcbsp_count)
478 #define id_to_mcbsp_ptr(id) mcbsp_ptr[id];
480 int omap_mcbsp_init(void);
481 void omap_mcbsp_register_board_cfg(struct resource *res, int res_count,
482 struct omap_mcbsp_platform_data *config, int size);
483 void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
484 #ifdef CONFIG_ARCH_OMAP3
485 void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
486 void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
487 u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
488 u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
489 u16 omap_mcbsp_get_fifo_size(unsigned int id);
490 u16 omap_mcbsp_get_tx_delay(unsigned int id);
491 u16 omap_mcbsp_get_rx_delay(unsigned int id);
492 int omap_mcbsp_get_dma_op_mode(unsigned int id);
494 static inline void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
496 static inline void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
498 static inline u16 omap_mcbsp_get_max_tx_threshold(unsigned int id) { return 0; }
499 static inline u16 omap_mcbsp_get_max_rx_threshold(unsigned int id) { return 0; }
500 static inline u16 omap_mcbsp_get_fifo_size(unsigned int id) { return 0; }
501 static inline u16 omap_mcbsp_get_tx_delay(unsigned int id) { return 0; }
502 static inline u16 omap_mcbsp_get_rx_delay(unsigned int id) { return 0; }
503 static inline int omap_mcbsp_get_dma_op_mode(unsigned int id) { return 0; }
505 int omap_mcbsp_request(unsigned int id);
506 void omap_mcbsp_free(unsigned int id);
507 void omap_mcbsp_start(unsigned int id, int tx, int rx);
508 void omap_mcbsp_stop(unsigned int id, int tx, int rx);
509 void omap_mcbsp_xmit_word(unsigned int id, u32 word);
510 u32 omap_mcbsp_recv_word(unsigned int id);
512 int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
513 int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
514 int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
515 int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
518 /* McBSP functional clock source changing function */
519 extern int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id);
520 /* SPI specific API */
521 void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
523 /* Polled read/write functions */
524 int omap_mcbsp_pollread(unsigned int id, u16 * buf);
525 int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
526 int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
528 /* McBSP signal muxing API */
529 void omap2_mcbsp1_mux_clkr_src(u8 mux);
530 void omap2_mcbsp1_mux_fsr_src(u8 mux);
532 #ifdef CONFIG_ARCH_OMAP3
533 /* Sidetone specific API */
534 int omap_st_set_chgain(unsigned int id, int channel, s16 chgain);
535 int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain);
536 int omap_st_enable(unsigned int id);
537 int omap_st_disable(unsigned int id);
538 int omap_st_is_enabled(unsigned int id);
540 static inline int omap_st_set_chgain(unsigned int id, int channel,
541 s16 chgain) { return 0; }
542 static inline int omap_st_get_chgain(unsigned int id, int channel,
543 s16 *chgain) { return 0; }
544 static inline int omap_st_enable(unsigned int id) { return 0; }
545 static inline int omap_st_disable(unsigned int id) { return 0; }
546 static inline int omap_st_is_enabled(unsigned int id) { return 0; }