blob: 5d657d96269de82d68958b74da14bf1b3a9e2387 [file] [log] [blame]
Russell Kinga09e64f2008-08-05 16:14:15 +01001/*
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
Russell Kinga09e64f2008-08-05 16:14:15 +010027#include <linux/spinlock.h>
Jarkko Nikula51672552011-09-26 10:45:46 +030028#include <linux/clk.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010029
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000030/* macro for building platform_device for McBSP ports */
31#define OMAP_MCBSP_PLATFORM_DEVICE(port_nr) \
32static struct platform_device omap_mcbsp##port_nr = { \
33 .name = "omap-mcbsp-dai", \
Jarkko Nikulafd1ee392011-07-01 08:52:27 +000034 .id = port_nr - 1, \
Liam Girdwoodf0fba2a2010-03-17 20:15:21 +000035}
36
Charulatha V37801b32011-02-24 12:51:46 -080037#define MCBSP_CONFIG_TYPE2 0x2
Charulatha Vdc48e5f2011-02-24 15:16:49 +053038#define MCBSP_CONFIG_TYPE3 0x3
Kishon Vijay Abraham Icb7e9de2011-02-24 15:16:50 +053039#define MCBSP_CONFIG_TYPE4 0x4
Charulatha V37801b32011-02-24 12:51:46 -080040
Alistair Buxton7c006922009-09-22 10:02:58 +010041#define OMAP7XX_MCBSP1_BASE 0xfffb1000
42#define OMAP7XX_MCBSP2_BASE 0xfffb1800
Russell Kinga09e64f2008-08-05 16:14:15 +010043
44#define OMAP1510_MCBSP1_BASE 0xe1011800
45#define OMAP1510_MCBSP2_BASE 0xfffb1000
46#define OMAP1510_MCBSP3_BASE 0xe1017000
47
48#define OMAP1610_MCBSP1_BASE 0xe1011800
49#define OMAP1610_MCBSP2_BASE 0xfffb1000
50#define OMAP1610_MCBSP3_BASE 0xe1017000
51
Jarkko Nikulacdc715142011-09-26 10:45:39 +030052/* McBSP register numbers. Register address offset = num * reg_step */
53enum {
54 /* Common registers */
55 OMAP_MCBSP_REG_SPCR2 = 4,
56 OMAP_MCBSP_REG_SPCR1,
57 OMAP_MCBSP_REG_RCR2,
58 OMAP_MCBSP_REG_RCR1,
59 OMAP_MCBSP_REG_XCR2,
60 OMAP_MCBSP_REG_XCR1,
61 OMAP_MCBSP_REG_SRGR2,
62 OMAP_MCBSP_REG_SRGR1,
63 OMAP_MCBSP_REG_MCR2,
64 OMAP_MCBSP_REG_MCR1,
65 OMAP_MCBSP_REG_RCERA,
66 OMAP_MCBSP_REG_RCERB,
67 OMAP_MCBSP_REG_XCERA,
68 OMAP_MCBSP_REG_XCERB,
69 OMAP_MCBSP_REG_PCR0,
70 OMAP_MCBSP_REG_RCERC,
71 OMAP_MCBSP_REG_RCERD,
72 OMAP_MCBSP_REG_XCERC,
73 OMAP_MCBSP_REG_XCERD,
74 OMAP_MCBSP_REG_RCERE,
75 OMAP_MCBSP_REG_RCERF,
76 OMAP_MCBSP_REG_XCERE,
77 OMAP_MCBSP_REG_XCERF,
78 OMAP_MCBSP_REG_RCERG,
79 OMAP_MCBSP_REG_RCERH,
80 OMAP_MCBSP_REG_XCERG,
81 OMAP_MCBSP_REG_XCERH,
Russell Kinga09e64f2008-08-05 16:14:15 +010082
Jarkko Nikulacdc715142011-09-26 10:45:39 +030083 /* OMAP1-OMAP2420 registers */
84 OMAP_MCBSP_REG_DRR2 = 0,
85 OMAP_MCBSP_REG_DRR1,
86 OMAP_MCBSP_REG_DXR2,
87 OMAP_MCBSP_REG_DXR1,
Russell Kinga09e64f2008-08-05 16:14:15 +010088
Jarkko Nikulacdc715142011-09-26 10:45:39 +030089 /* OMAP2430 and onwards */
90 OMAP_MCBSP_REG_DRR = 0,
91 OMAP_MCBSP_REG_DXR = 2,
92 OMAP_MCBSP_REG_SYSCON = 35,
93 OMAP_MCBSP_REG_THRSH2,
94 OMAP_MCBSP_REG_THRSH1,
95 OMAP_MCBSP_REG_IRQST = 40,
96 OMAP_MCBSP_REG_IRQEN,
97 OMAP_MCBSP_REG_WAKEUPEN,
98 OMAP_MCBSP_REG_XCCR,
99 OMAP_MCBSP_REG_RCCR,
100 OMAP_MCBSP_REG_XBUFFSTAT,
101 OMAP_MCBSP_REG_RBUFFSTAT,
102 OMAP_MCBSP_REG_SSELCR,
103};
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200104
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300105/* OMAP3 sidetone control registers */
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000106#define OMAP_ST_REG_REV 0x00
107#define OMAP_ST_REG_SYSCONFIG 0x10
108#define OMAP_ST_REG_IRQSTATUS 0x18
109#define OMAP_ST_REG_IRQENABLE 0x1C
110#define OMAP_ST_REG_SGAINCR 0x24
111#define OMAP_ST_REG_SFIRCR 0x28
112#define OMAP_ST_REG_SSELCR 0x2C
Russell Kinga09e64f2008-08-05 16:14:15 +0100113
Russell Kinga09e64f2008-08-05 16:14:15 +0100114/************************** McBSP SPCR1 bit definitions ***********************/
115#define RRST 0x0001
116#define RRDY 0x0002
117#define RFULL 0x0004
118#define RSYNC_ERR 0x0008
119#define RINTM(value) ((value)<<4) /* bits 4:5 */
120#define ABIS 0x0040
121#define DXENA 0x0080
122#define CLKSTP(value) ((value)<<11) /* bits 11:12 */
123#define RJUST(value) ((value)<<13) /* bits 13:14 */
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300124#define ALB 0x8000
Russell Kinga09e64f2008-08-05 16:14:15 +0100125#define DLB 0x8000
126
127/************************** McBSP SPCR2 bit definitions ***********************/
128#define XRST 0x0001
129#define XRDY 0x0002
130#define XEMPTY 0x0004
131#define XSYNC_ERR 0x0008
132#define XINTM(value) ((value)<<4) /* bits 4:5 */
133#define GRST 0x0040
134#define FRST 0x0080
135#define SOFT 0x0100
136#define FREE 0x0200
137
138/************************** McBSP PCR bit definitions *************************/
139#define CLKRP 0x0001
140#define CLKXP 0x0002
141#define FSRP 0x0004
142#define FSXP 0x0008
143#define DR_STAT 0x0010
144#define DX_STAT 0x0020
145#define CLKS_STAT 0x0040
146#define SCLKME 0x0080
147#define CLKRM 0x0100
148#define CLKXM 0x0200
149#define FSRM 0x0400
150#define FSXM 0x0800
151#define RIOEN 0x1000
152#define XIOEN 0x2000
153#define IDLE_EN 0x4000
154
155/************************** McBSP RCR1 bit definitions ************************/
156#define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
157#define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
158
159/************************** McBSP XCR1 bit definitions ************************/
160#define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
161#define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
162
163/*************************** McBSP RCR2 bit definitions ***********************/
164#define RDATDLY(value) (value) /* Bits 0:1 */
165#define RFIG 0x0004
166#define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
167#define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
168#define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
169#define RPHASE 0x8000
170
171/*************************** McBSP XCR2 bit definitions ***********************/
172#define XDATDLY(value) (value) /* Bits 0:1 */
173#define XFIG 0x0004
174#define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
175#define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
176#define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
177#define XPHASE 0x8000
178
179/************************* McBSP SRGR1 bit definitions ************************/
180#define CLKGDV(value) (value) /* Bits 0:7 */
181#define FWID(value) ((value)<<8) /* Bits 8:15 */
182
183/************************* McBSP SRGR2 bit definitions ************************/
184#define FPER(value) (value) /* Bits 0:11 */
185#define FSGM 0x1000
186#define CLKSM 0x2000
187#define CLKSP 0x4000
188#define GSYNC 0x8000
189
190/************************* McBSP MCR1 bit definitions *************************/
191#define RMCM 0x0001
192#define RCBLK(value) ((value)<<2) /* Bits 2:4 */
193#define RPABLK(value) ((value)<<5) /* Bits 5:6 */
194#define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
195
196/************************* McBSP MCR2 bit definitions *************************/
197#define XMCM(value) (value) /* Bits 0:1 */
198#define XCBLK(value) ((value)<<2) /* Bits 2:4 */
199#define XPABLK(value) ((value)<<5) /* Bits 5:6 */
200#define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
201
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300202/*********************** McBSP XCCR bit definitions *************************/
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200203#define EXTCLKGATE 0x8000
204#define PPCONNECT 0x4000
205#define DXENDLY(value) ((value)<<12) /* Bits 12:13 */
206#define XFULL_CYCLE 0x0800
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300207#define DILB 0x0020
208#define XDMAEN 0x0008
209#define XDISABLE 0x0001
210
211/********************** McBSP RCCR bit definitions *************************/
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200212#define RFULL_CYCLE 0x0800
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300213#define RDMAEN 0x0008
214#define RDISABLE 0x0001
215
216/********************** McBSP SYSCONFIG bit definitions ********************/
Eero Nurkkala2ba93f82009-08-20 16:18:17 +0300217#define CLOCKACTIVITY(value) ((value)<<8)
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300218#define SIDLEMODE(value) ((value)<<3)
219#define ENAWAKEUP 0x0004
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300220#define SOFTRST 0x0002
Russell Kinga09e64f2008-08-05 16:14:15 +0100221
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000222/********************** McBSP SSELCR bit definitions ***********************/
223#define SIDETONEEN 0x0400
224
225/********************** McBSP Sidetone SYSCONFIG bit definitions ***********/
226#define ST_AUTOIDLE 0x0001
227
228/********************** McBSP Sidetone SGAINCR bit definitions *************/
229#define ST_CH1GAIN(value) ((value<<16)) /* Bits 16:31 */
230#define ST_CH0GAIN(value) (value) /* Bits 0:15 */
231
232/********************** McBSP Sidetone SFIRCR bit definitions **************/
233#define ST_FIRCOEFF(value) (value) /* Bits 0:15 */
234
235/********************** McBSP Sidetone SSELCR bit definitions **************/
236#define ST_COEFFWRDONE 0x0004
237#define ST_COEFFWREN 0x0002
238#define ST_SIDETONEEN 0x0001
239
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300240/********************** McBSP DMA operating modes **************************/
241#define MCBSP_DMA_MODE_ELEMENT 0
242#define MCBSP_DMA_MODE_THRESHOLD 1
243#define MCBSP_DMA_MODE_FRAME 2
244
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300245/********************** McBSP WAKEUPEN bit definitions *********************/
246#define XEMPTYEOFEN 0x4000
247#define XRDYEN 0x0400
248#define XEOFEN 0x0200
249#define XFSXEN 0x0100
250#define XSYNCERREN 0x0080
251#define RRDYEN 0x0008
252#define REOFEN 0x0004
253#define RFSREN 0x0002
254#define RSYNCERREN 0x0001
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300255
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600256/* CLKR signal muxing options */
257#define CLKR_SRC_CLKR 0
258#define CLKR_SRC_CLKX 1
259
260/* FSR signal muxing options */
261#define FSR_SRC_FSR 0
262#define FSR_SRC_FSX 1
263
Paul Walmsleyd1358652010-10-08 11:40:19 -0600264/* McBSP functional clock sources */
Jarkko Nikulae4cc41d2010-10-08 11:40:21 -0600265#define MCBSP_CLKS_PRCM_SRC 0
266#define MCBSP_CLKS_PAD_SRC 1
Paul Walmsleyd1358652010-10-08 11:40:19 -0600267
Russell Kinga09e64f2008-08-05 16:14:15 +0100268/* we don't do multichannel for now */
269struct omap_mcbsp_reg_cfg {
270 u16 spcr2;
271 u16 spcr1;
272 u16 rcr2;
273 u16 rcr1;
274 u16 xcr2;
275 u16 xcr1;
276 u16 srgr2;
277 u16 srgr1;
278 u16 mcr2;
279 u16 mcr1;
280 u16 pcr0;
281 u16 rcerc;
282 u16 rcerd;
283 u16 xcerc;
284 u16 xcerd;
285 u16 rcere;
286 u16 rcerf;
287 u16 xcere;
288 u16 xcerf;
289 u16 rcerg;
290 u16 rcerh;
291 u16 xcerg;
292 u16 xcerh;
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200293 u16 xccr;
294 u16 rccr;
Russell Kinga09e64f2008-08-05 16:14:15 +0100295};
296
297typedef enum {
Russell Kinga09e64f2008-08-05 16:14:15 +0100298 OMAP_MCBSP_WORD_8 = 0,
299 OMAP_MCBSP_WORD_12,
300 OMAP_MCBSP_WORD_16,
301 OMAP_MCBSP_WORD_20,
302 OMAP_MCBSP_WORD_24,
303 OMAP_MCBSP_WORD_32,
304} omap_mcbsp_word_length;
305
Russell Kinga09e64f2008-08-05 16:14:15 +0100306/* Platform specific configuration */
307struct omap_mcbsp_ops {
308 void (*request)(unsigned int);
309 void (*free)(unsigned int);
Paul Walmsleyd1358652010-10-08 11:40:19 -0600310 int (*set_clks_src)(u8, u8);
Russell Kinga09e64f2008-08-05 16:14:15 +0100311};
312
313struct omap_mcbsp_platform_data {
Russell Kinga09e64f2008-08-05 16:14:15 +0100314 struct omap_mcbsp_ops *ops;
Kishon Vijay Abraham I64bcbd32011-02-24 15:16:52 +0530315 u16 buffer_size;
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300316 u8 reg_size;
317 u8 reg_step;
Jarkko Nikula1a645882011-09-26 10:45:40 +0300318
319 /* McBSP platform and instance specific features */
320 bool has_wakeup; /* Wakeup capability */
Jarkko Nikula88408232011-09-26 10:45:41 +0300321 bool has_ccr; /* Transceiver has configuration control registers */
Jarkko Nikula1743d142011-09-26 10:45:44 +0300322 int (*enable_st_clock)(unsigned int, bool);
Russell Kinga09e64f2008-08-05 16:14:15 +0100323};
324
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000325struct omap_mcbsp_st_data {
326 void __iomem *io_base_st;
327 bool running;
328 bool enabled;
329 s16 taps[128]; /* Sidetone filter coefficients */
330 int nr_taps; /* Number of filter coefficients in use */
331 s16 ch0gain;
332 s16 ch1gain;
333};
334
Russell Kinga09e64f2008-08-05 16:14:15 +0100335struct omap_mcbsp {
336 struct device *dev;
Russell King65846902008-09-03 23:46:18 +0100337 unsigned long phys_base;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800338 unsigned long phys_dma_base;
Russell Kingd592dd12008-09-04 14:25:42 +0100339 void __iomem *io_base;
Russell Kinga09e64f2008-08-05 16:14:15 +0100340 u8 id;
341 u8 free;
Russell Kinga09e64f2008-08-05 16:14:15 +0100342
Russell Kinga09e64f2008-08-05 16:14:15 +0100343 int rx_irq;
344 int tx_irq;
345
346 /* DMA stuff */
347 u8 dma_rx_sync;
Russell Kinga09e64f2008-08-05 16:14:15 +0100348 u8 dma_tx_sync;
Russell Kinga09e64f2008-08-05 16:14:15 +0100349
350 /* Protect the field .free, while checking if the mcbsp is in use */
351 spinlock_t lock;
352 struct omap_mcbsp_platform_data *pdata;
Russell Kingb820ce42009-01-23 10:26:46 +0000353 struct clk *fclk;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000354 struct omap_mcbsp_st_data *st_data;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300355 int dma_op_mode;
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300356 u16 max_tx_thres;
357 u16 max_rx_thres;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800358 void *reg_cache;
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300359 int reg_cache_size;
Russell Kinga09e64f2008-08-05 16:14:15 +0100360};
Kishon Vijay Abraham I8b1906f2011-02-24 15:16:51 +0530361
362/**
363 * omap_mcbsp_dev_attr - OMAP McBSP device attributes for omap_hwmod
364 * @sidetone: name of the sidetone device
365 */
366struct omap_mcbsp_dev_attr {
367 const char *sidetone;
368};
369
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300370extern struct omap_mcbsp **mcbsp_ptr;
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300371extern int omap_mcbsp_count;
Russell Kinga09e64f2008-08-05 16:14:15 +0100372
Paul Walmsleyd1358652010-10-08 11:40:19 -0600373#define omap_mcbsp_check_valid_id(id) (id < omap_mcbsp_count)
374#define id_to_mcbsp_ptr(id) mcbsp_ptr[id];
375
Russell Kinga09e64f2008-08-05 16:14:15 +0100376int omap_mcbsp_init(void);
Russell Kinga09e64f2008-08-05 16:14:15 +0100377void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300378void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold);
379void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold);
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300380u16 omap_mcbsp_get_max_tx_threshold(unsigned int id);
381u16 omap_mcbsp_get_max_rx_threshold(unsigned int id);
Peter Ujfalusi0acce822010-06-03 07:39:32 +0300382u16 omap_mcbsp_get_fifo_size(unsigned int id);
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200383u16 omap_mcbsp_get_tx_delay(unsigned int id);
384u16 omap_mcbsp_get_rx_delay(unsigned int id);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300385int omap_mcbsp_get_dma_op_mode(unsigned int id);
Russell Kinga09e64f2008-08-05 16:14:15 +0100386int omap_mcbsp_request(unsigned int id);
387void omap_mcbsp_free(unsigned int id);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300388void omap_mcbsp_start(unsigned int id, int tx, int rx);
389void omap_mcbsp_stop(unsigned int id, int tx, int rx);
Russell Kinga09e64f2008-08-05 16:14:15 +0100390
Paul Walmsleyd1358652010-10-08 11:40:19 -0600391/* McBSP functional clock source changing function */
392extern int omap2_mcbsp_set_clks_src(u8 id, u8 fck_src_id);
Russell Kinga09e64f2008-08-05 16:14:15 +0100393
Paul Walmsleycf4c87a2010-10-08 11:40:19 -0600394/* McBSP signal muxing API */
395void omap2_mcbsp1_mux_clkr_src(u8 mux);
396void omap2_mcbsp1_mux_fsr_src(u8 mux);
397
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530398int omap_mcbsp_dma_ch_params(unsigned int id, unsigned int stream);
399int omap_mcbsp_dma_reg_params(unsigned int id, unsigned int stream);
400
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000401/* Sidetone specific API */
402int omap_st_set_chgain(unsigned int id, int channel, s16 chgain);
403int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain);
404int omap_st_enable(unsigned int id);
405int omap_st_disable(unsigned int id);
406int omap_st_is_enabled(unsigned int id);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000407
Russell Kinga09e64f2008-08-05 16:14:15 +0100408#endif