]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - arch/arm/plat-omap/include/plat/mcbsp.h
648344a89a94c969dfd6185d49006936831d5976
[karo-tx-linux.git] / arch / arm / plat-omap / include / plat / mcbsp.h
1 /*
2  * arch/arm/plat-omap/include/mach/mcbsp.h
3  *
4  * Defines for Multi-Channel Buffered Serial Port
5  *
6  * Copyright (C) 2002 RidgeRun, Inc.
7  * Author: Steve Johnson
8  *
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.
13  *
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.
18  *
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
22  *
23  */
24 #ifndef __ASM_ARCH_OMAP_MCBSP_H
25 #define __ASM_ARCH_OMAP_MCBSP_H
26
27 #include <linux/spinlock.h>
28
29 #include <mach/hardware.h>
30 #include <plat/clock.h>
31
32 /* macro for building platform_device for McBSP ports */
33 #define OMAP_MCBSP_PLATFORM_DEVICE(port_nr)             \
34 static struct platform_device omap_mcbsp##port_nr = {   \
35         .name   = "omap-mcbsp-dai",                     \
36         .id     = port_nr - 1,                  \
37 }
38
39 #define MCBSP_CONFIG_TYPE2      0x2
40 #define MCBSP_CONFIG_TYPE3      0x3
41 #define MCBSP_CONFIG_TYPE4      0x4
42
43 #define OMAP7XX_MCBSP1_BASE     0xfffb1000
44 #define OMAP7XX_MCBSP2_BASE     0xfffb1800
45
46 #define OMAP1510_MCBSP1_BASE    0xe1011800
47 #define OMAP1510_MCBSP2_BASE    0xfffb1000
48 #define OMAP1510_MCBSP3_BASE    0xe1017000
49
50 #define OMAP1610_MCBSP1_BASE    0xe1011800
51 #define OMAP1610_MCBSP2_BASE    0xfffb1000
52 #define OMAP1610_MCBSP3_BASE    0xe1017000
53
54 /* McBSP register numbers. Register address offset = num * reg_step */
55 enum {
56         /* Common registers */
57         OMAP_MCBSP_REG_SPCR2 = 4,
58         OMAP_MCBSP_REG_SPCR1,
59         OMAP_MCBSP_REG_RCR2,
60         OMAP_MCBSP_REG_RCR1,
61         OMAP_MCBSP_REG_XCR2,
62         OMAP_MCBSP_REG_XCR1,
63         OMAP_MCBSP_REG_SRGR2,
64         OMAP_MCBSP_REG_SRGR1,
65         OMAP_MCBSP_REG_MCR2,
66         OMAP_MCBSP_REG_MCR1,
67         OMAP_MCBSP_REG_RCERA,
68         OMAP_MCBSP_REG_RCERB,
69         OMAP_MCBSP_REG_XCERA,
70         OMAP_MCBSP_REG_XCERB,
71         OMAP_MCBSP_REG_PCR0,
72         OMAP_MCBSP_REG_RCERC,
73         OMAP_MCBSP_REG_RCERD,
74         OMAP_MCBSP_REG_XCERC,
75         OMAP_MCBSP_REG_XCERD,
76         OMAP_MCBSP_REG_RCERE,
77         OMAP_MCBSP_REG_RCERF,
78         OMAP_MCBSP_REG_XCERE,
79         OMAP_MCBSP_REG_XCERF,
80         OMAP_MCBSP_REG_RCERG,
81         OMAP_MCBSP_REG_RCERH,
82         OMAP_MCBSP_REG_XCERG,
83         OMAP_MCBSP_REG_XCERH,
84
85         /* OMAP1-OMAP2420 registers */
86         OMAP_MCBSP_REG_DRR2 = 0,
87         OMAP_MCBSP_REG_DRR1,
88         OMAP_MCBSP_REG_DXR2,
89         OMAP_MCBSP_REG_DXR1,
90
91         /* OMAP2430 and onwards */
92         OMAP_MCBSP_REG_DRR = 0,
93         OMAP_MCBSP_REG_DXR = 2,
94         OMAP_MCBSP_REG_SYSCON = 35,
95         OMAP_MCBSP_REG_THRSH2,
96         OMAP_MCBSP_REG_THRSH1,
97         OMAP_MCBSP_REG_IRQST = 40,
98         OMAP_MCBSP_REG_IRQEN,
99         OMAP_MCBSP_REG_WAKEUPEN,
100         OMAP_MCBSP_REG_XCCR,
101         OMAP_MCBSP_REG_RCCR,
102         OMAP_MCBSP_REG_XBUFFSTAT,
103         OMAP_MCBSP_REG_RBUFFSTAT,
104         OMAP_MCBSP_REG_SSELCR,
105 };
106
107 /* OMAP3 sidetone control registers */
108 #define OMAP_ST_REG_REV         0x00
109 #define OMAP_ST_REG_SYSCONFIG   0x10
110 #define OMAP_ST_REG_IRQSTATUS   0x18
111 #define OMAP_ST_REG_IRQENABLE   0x1C
112 #define OMAP_ST_REG_SGAINCR     0x24
113 #define OMAP_ST_REG_SFIRCR      0x28
114 #define OMAP_ST_REG_SSELCR      0x2C
115
116 /************************** McBSP SPCR1 bit definitions ***********************/
117 #define RRST                    0x0001
118 #define RRDY                    0x0002
119 #define RFULL                   0x0004
120 #define RSYNC_ERR               0x0008
121 #define RINTM(value)            ((value)<<4)    /* bits 4:5 */
122 #define ABIS                    0x0040
123 #define DXENA                   0x0080
124 #define CLKSTP(value)           ((value)<<11)   /* bits 11:12 */
125 #define RJUST(value)            ((value)<<13)   /* bits 13:14 */
126 #define ALB                     0x8000
127 #define DLB                     0x8000
128
129 /************************** McBSP SPCR2 bit definitions ***********************/
130 #define XRST            0x0001
131 #define XRDY            0x0002
132 #define XEMPTY          0x0004
133 #define XSYNC_ERR       0x0008
134 #define XINTM(value)    ((value)<<4)            /* bits 4:5 */
135 #define GRST            0x0040
136 #define FRST            0x0080
137 #define SOFT            0x0100
138 #define FREE            0x0200
139
140 /************************** McBSP PCR bit definitions *************************/
141 #define CLKRP           0x0001
142 #define CLKXP           0x0002
143 #define FSRP            0x0004
144 #define FSXP            0x0008
145 #define DR_STAT         0x0010
146 #define DX_STAT         0x0020
147 #define CLKS_STAT       0x0040
148 #define SCLKME          0x0080
149 #define CLKRM           0x0100
150 #define CLKXM           0x0200
151 #define FSRM            0x0400
152 #define FSXM            0x0800
153 #define RIOEN           0x1000
154 #define XIOEN           0x2000
155 #define IDLE_EN         0x4000
156
157 /************************** McBSP RCR1 bit definitions ************************/
158 #define RWDLEN1(value)          ((value)<<5)    /* Bits 5:7 */
159 #define RFRLEN1(value)          ((value)<<8)    /* Bits 8:14 */
160
161 /************************** McBSP XCR1 bit definitions ************************/
162 #define XWDLEN1(value)          ((value)<<5)    /* Bits 5:7 */
163 #define XFRLEN1(value)          ((value)<<8)    /* Bits 8:14 */
164
165 /*************************** McBSP RCR2 bit definitions ***********************/
166 #define RDATDLY(value)          (value)         /* Bits 0:1 */
167 #define RFIG                    0x0004
168 #define RCOMPAND(value)         ((value)<<3)    /* Bits 3:4 */
169 #define RWDLEN2(value)          ((value)<<5)    /* Bits 5:7 */
170 #define RFRLEN2(value)          ((value)<<8)    /* Bits 8:14 */
171 #define RPHASE                  0x8000
172
173 /*************************** McBSP XCR2 bit definitions ***********************/
174 #define XDATDLY(value)          (value)         /* Bits 0:1 */
175 #define XFIG                    0x0004
176 #define XCOMPAND(value)         ((value)<<3)    /* Bits 3:4 */
177 #define XWDLEN2(value)          ((value)<<5)    /* Bits 5:7 */
178 #define XFRLEN2(value)          ((value)<<8)    /* Bits 8:14 */
179 #define XPHASE                  0x8000
180
181 /************************* McBSP SRGR1 bit definitions ************************/
182 #define CLKGDV(value)           (value)         /* Bits 0:7 */
183 #define FWID(value)             ((value)<<8)    /* Bits 8:15 */
184
185 /************************* McBSP SRGR2 bit definitions ************************/
186 #define FPER(value)             (value)         /* Bits 0:11 */
187 #define FSGM                    0x1000
188 #define CLKSM                   0x2000
189 #define CLKSP                   0x4000
190 #define GSYNC                   0x8000
191
192 /************************* McBSP MCR1 bit definitions *************************/
193 #define RMCM                    0x0001
194 #define RCBLK(value)            ((value)<<2)    /* Bits 2:4 */
195 #define RPABLK(value)           ((value)<<5)    /* Bits 5:6 */
196 #define RPBBLK(value)           ((value)<<7)    /* Bits 7:8 */
197
198 /************************* McBSP MCR2 bit definitions *************************/
199 #define XMCM(value)             (value)         /* Bits 0:1 */
200 #define XCBLK(value)            ((value)<<2)    /* Bits 2:4 */
201 #define XPABLK(value)           ((value)<<5)    /* Bits 5:6 */
202 #define XPBBLK(value)           ((value)<<7)    /* Bits 7:8 */
203
204 /*********************** McBSP XCCR bit definitions *************************/
205 #define EXTCLKGATE              0x8000
206 #define PPCONNECT               0x4000
207 #define DXENDLY(value)          ((value)<<12)   /* Bits 12:13 */
208 #define XFULL_CYCLE             0x0800
209 #define DILB                    0x0020
210 #define XDMAEN                  0x0008
211 #define XDISABLE                0x0001
212
213 /********************** McBSP RCCR bit definitions *************************/
214 #define RFULL_CYCLE             0x0800
215 #define RDMAEN                  0x0008
216 #define RDISABLE                0x0001
217
218 /********************** McBSP SYSCONFIG bit definitions ********************/
219 #define CLOCKACTIVITY(value)    ((value)<<8)
220 #define SIDLEMODE(value)        ((value)<<3)
221 #define ENAWAKEUP               0x0004
222 #define SOFTRST                 0x0002
223
224 /********************** McBSP SSELCR bit definitions ***********************/
225 #define SIDETONEEN              0x0400
226
227 /********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
228 #define ST_AUTOIDLE             0x0001
229
230 /********************** McBSP Sidetone SGAINCR bit definitions *************/
231 #define ST_CH1GAIN(value)       ((value<<16))   /* Bits 16:31 */
232 #define ST_CH0GAIN(value)       (value)         /* Bits 0:15 */
233
234 /********************** McBSP Sidetone SFIRCR bit definitions **************/
235 #define ST_FIRCOEFF(value)      (value)         /* Bits 0:15 */
236
237 /********************** McBSP Sidetone SSELCR bit definitions **************/
238 #define ST_COEFFWRDONE          0x0004
239 #define ST_COEFFWREN            0x0002
240 #define ST_SIDETONEEN           0x0001
241
242 /********************** McBSP DMA operating modes **************************/
243 #define MCBSP_DMA_MODE_ELEMENT          0
244 #define MCBSP_DMA_MODE_THRESHOLD        1
245 #define MCBSP_DMA_MODE_FRAME            2
246
247 /********************** McBSP WAKEUPEN bit definitions *********************/
248 #define XEMPTYEOFEN             0x4000
249 #define XRDYEN                  0x0400
250 #define XEOFEN                  0x0200
251 #define XFSXEN                  0x0100
252 #define XSYNCERREN              0x0080
253 #define RRDYEN                  0x0008
254 #define REOFEN                  0x0004
255 #define RFSREN                  0x0002
256 #define RSYNCERREN              0x0001
257
258 /* CLKR signal muxing options */
259 #define CLKR_SRC_CLKR           0
260 #define CLKR_SRC_CLKX           1
261
262 /* FSR signal muxing options */
263 #define FSR_SRC_FSR             0
264 #define FSR_SRC_FSX             1
265
266 /* McBSP functional clock sources */
267 #define MCBSP_CLKS_PRCM_SRC     0
268 #define MCBSP_CLKS_PAD_SRC      1
269
270 /* we don't do multichannel for now */
271 struct omap_mcbsp_reg_cfg {
272         u16 spcr2;
273         u16 spcr1;
274         u16 rcr2;
275         u16 rcr1;
276         u16 xcr2;
277         u16 xcr1;
278         u16 srgr2;
279         u16 srgr1;
280         u16 mcr2;
281         u16 mcr1;
282         u16 pcr0;
283         u16 rcerc;
284         u16 rcerd;
285         u16 xcerc;
286         u16 xcerd;
287         u16 rcere;
288         u16 rcerf;
289         u16 xcere;
290         u16 xcerf;
291         u16 rcerg;
292         u16 rcerh;
293         u16 xcerg;
294         u16 xcerh;
295         u16 xccr;
296         u16 rccr;
297 };
298
299 typedef enum {
300         OMAP_MCBSP_WORD_8 = 0,
301         OMAP_MCBSP_WORD_12,
302         OMAP_MCBSP_WORD_16,
303         OMAP_MCBSP_WORD_20,
304         OMAP_MCBSP_WORD_24,
305         OMAP_MCBSP_WORD_32,
306 } omap_mcbsp_word_length;
307
308 /* Platform specific configuration */
309 struct omap_mcbsp_ops {
310         void (*request)(unsigned int);
311         void (*free)(unsigned int);
312         int (*set_clks_src)(u8, u8);
313 };
314
315 struct omap_mcbsp_platform_data {
316         struct omap_mcbsp_ops *ops;
317         u16 buffer_size;
318         u8 reg_size;
319         u8 reg_step;
320
321         /* McBSP platform and instance specific features */
322         bool has_wakeup; /* Wakeup capability */
323         bool has_ccr; /* Transceiver has configuration control registers */
324 };
325
326 struct omap_mcbsp_st_data {
327         void __iomem *io_base_st;
328         bool running;
329         bool enabled;
330         s16 taps[128];  /* Sidetone filter coefficients */
331         int nr_taps;    /* Number of filter coefficients in use */
332         s16 ch0gain;
333         s16 ch1gain;
334 };
335
336 struct omap_mcbsp {
337         struct device *dev;
338         unsigned long phys_base;
339         unsigned long phys_dma_base;
340         void __iomem *io_base;
341         u8 id;
342         u8 free;
343
344         int rx_irq;
345         int tx_irq;
346
347         /* DMA stuff */
348         u8 dma_rx_sync;
349         u8 dma_tx_sync;
350
351         /* Protect the field .free, while checking if the mcbsp is in use */
352         spinlock_t lock;
353         struct omap_mcbsp_platform_data *pdata;
354         struct clk *fclk;
355 #ifdef CONFIG_ARCH_OMAP3
356         struct omap_mcbsp_st_data *st_data;
357 #endif
358         int dma_op_mode;
359         u16 max_tx_thres;
360         u16 max_rx_thres;
361         void *reg_cache;
362         int reg_cache_size;
363 };
364
365 /**
366  * omap_mcbsp_dev_attr - OMAP McBSP device attributes for omap_hwmod
367  * @sidetone: name of the sidetone device
368  */
369 struct omap_mcbsp_dev_attr {
370         const char *sidetone;
371 };
372
373 extern struct omap_mcbsp **mcbsp_ptr;
374 extern int omap_mcbsp_count;
375
376 #define omap_mcbsp_check_valid_id(id)   (id < omap_mcbsp_count)
377 #define id_to_mcbsp_ptr(id)             mcbsp_ptr[id];
378
379 int omap_mcbsp_init(void);
380 void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
381 void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
382 void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
383 u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
384 u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
385 u16 omap_mcbsp_get_fifo_size(unsigned int id);
386 u16 omap_mcbsp_get_tx_delay(unsigned int id);
387 u16 omap_mcbsp_get_rx_delay(unsigned int id);
388 int omap_mcbsp_get_dma_op_mode(unsigned int id);
389 int omap_mcbsp_request(unsigned int id);
390 void omap_mcbsp_free(unsigned int id);
391 void omap_mcbsp_start(unsigned int id, int tx, int rx);
392 void omap_mcbsp_stop(unsigned int id, int tx, int rx);
393
394 /* McBSP functional clock source changing function */
395 extern int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id);
396
397 /* McBSP signal muxing API */
398 void omap2_mcbsp1_mux_clkr_src(u8 mux);
399 void omap2_mcbsp1_mux_fsr_src(u8 mux);
400
401 int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream);
402 int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream);
403
404 #ifdef CONFIG_ARCH_OMAP3
405 /* Sidetone specific API */
406 int omap_st_set_chgain(unsigned int id, int channel, s16 chgain);
407 int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain);
408 int omap_st_enable(unsigned int id);
409 int omap_st_disable(unsigned int id);
410 int omap_st_is_enabled(unsigned int id);
411 #else
412 static inline int omap_st_set_chgain(unsigned int id, int channel,
413                                      s16 chgain) { return 0; }
414 static inline int omap_st_get_chgain(unsigned int id, int channel,
415                                      s16 *chgain) { return 0; }
416 static inline int omap_st_enable(unsigned int id) { return 0; }
417 static inline int omap_st_disable(unsigned int id) { return 0; }
418 static inline int omap_st_is_enabled(unsigned int id) {  return 0; }
419 #endif
420
421 #endif