blob: f4e7980324e086f94b14231d7bc78b58f7a901bc [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
27#include <linux/completion.h>
28#include <linux/spinlock.h>
29
30#include <mach/hardware.h>
31#include <mach/clock.h>
32
33#define OMAP730_MCBSP1_BASE 0xfffb1000
34#define OMAP730_MCBSP2_BASE 0xfffb1800
35
36#define OMAP1510_MCBSP1_BASE 0xe1011800
37#define OMAP1510_MCBSP2_BASE 0xfffb1000
38#define OMAP1510_MCBSP3_BASE 0xe1017000
39
40#define OMAP1610_MCBSP1_BASE 0xe1011800
41#define OMAP1610_MCBSP2_BASE 0xfffb1000
42#define OMAP1610_MCBSP3_BASE 0xe1017000
43
44#define OMAP24XX_MCBSP1_BASE 0x48074000
45#define OMAP24XX_MCBSP2_BASE 0x48076000
46
47#define OMAP34XX_MCBSP1_BASE 0x48074000
48#define OMAP34XX_MCBSP2_BASE 0x49022000
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +030049#define OMAP34XX_MCBSP3_BASE 0x49024000
50#define OMAP34XX_MCBSP4_BASE 0x49026000
51#define OMAP34XX_MCBSP5_BASE 0x48096000
Russell Kinga09e64f2008-08-05 16:14:15 +010052
53#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730)
54
55#define OMAP_MCBSP_REG_DRR2 0x00
56#define OMAP_MCBSP_REG_DRR1 0x02
57#define OMAP_MCBSP_REG_DXR2 0x04
58#define OMAP_MCBSP_REG_DXR1 0x06
59#define OMAP_MCBSP_REG_SPCR2 0x08
60#define OMAP_MCBSP_REG_SPCR1 0x0a
61#define OMAP_MCBSP_REG_RCR2 0x0c
62#define OMAP_MCBSP_REG_RCR1 0x0e
63#define OMAP_MCBSP_REG_XCR2 0x10
64#define OMAP_MCBSP_REG_XCR1 0x12
65#define OMAP_MCBSP_REG_SRGR2 0x14
66#define OMAP_MCBSP_REG_SRGR1 0x16
67#define OMAP_MCBSP_REG_MCR2 0x18
68#define OMAP_MCBSP_REG_MCR1 0x1a
69#define OMAP_MCBSP_REG_RCERA 0x1c
70#define OMAP_MCBSP_REG_RCERB 0x1e
71#define OMAP_MCBSP_REG_XCERA 0x20
72#define OMAP_MCBSP_REG_XCERB 0x22
73#define OMAP_MCBSP_REG_PCR0 0x24
74#define OMAP_MCBSP_REG_RCERC 0x26
75#define OMAP_MCBSP_REG_RCERD 0x28
76#define OMAP_MCBSP_REG_XCERC 0x2A
77#define OMAP_MCBSP_REG_XCERD 0x2C
78#define OMAP_MCBSP_REG_RCERE 0x2E
79#define OMAP_MCBSP_REG_RCERF 0x30
80#define OMAP_MCBSP_REG_XCERE 0x32
81#define OMAP_MCBSP_REG_XCERF 0x34
82#define OMAP_MCBSP_REG_RCERG 0x36
83#define OMAP_MCBSP_REG_RCERH 0x38
84#define OMAP_MCBSP_REG_XCERG 0x3A
85#define OMAP_MCBSP_REG_XCERH 0x3C
86
Russell Kinga09e64f2008-08-05 16:14:15 +010087#define AUDIO_MCBSP_DATAWRITE (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
88#define AUDIO_MCBSP_DATAREAD (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
89
90#define AUDIO_MCBSP OMAP_MCBSP1
91#define AUDIO_DMA_TX OMAP_DMA_MCBSP1_TX
92#define AUDIO_DMA_RX OMAP_DMA_MCBSP1_RX
93
Chandra Shekharb4b58f52008-10-08 10:01:39 +030094#elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX)
Russell Kinga09e64f2008-08-05 16:14:15 +010095
96#define OMAP_MCBSP_REG_DRR2 0x00
97#define OMAP_MCBSP_REG_DRR1 0x04
98#define OMAP_MCBSP_REG_DXR2 0x08
99#define OMAP_MCBSP_REG_DXR1 0x0C
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300100#define OMAP_MCBSP_REG_DRR 0x00
101#define OMAP_MCBSP_REG_DXR 0x08
Russell Kinga09e64f2008-08-05 16:14:15 +0100102#define OMAP_MCBSP_REG_SPCR2 0x10
103#define OMAP_MCBSP_REG_SPCR1 0x14
104#define OMAP_MCBSP_REG_RCR2 0x18
105#define OMAP_MCBSP_REG_RCR1 0x1C
106#define OMAP_MCBSP_REG_XCR2 0x20
107#define OMAP_MCBSP_REG_XCR1 0x24
108#define OMAP_MCBSP_REG_SRGR2 0x28
109#define OMAP_MCBSP_REG_SRGR1 0x2C
110#define OMAP_MCBSP_REG_MCR2 0x30
111#define OMAP_MCBSP_REG_MCR1 0x34
112#define OMAP_MCBSP_REG_RCERA 0x38
113#define OMAP_MCBSP_REG_RCERB 0x3C
114#define OMAP_MCBSP_REG_XCERA 0x40
115#define OMAP_MCBSP_REG_XCERB 0x44
116#define OMAP_MCBSP_REG_PCR0 0x48
117#define OMAP_MCBSP_REG_RCERC 0x4C
118#define OMAP_MCBSP_REG_RCERD 0x50
119#define OMAP_MCBSP_REG_XCERC 0x54
120#define OMAP_MCBSP_REG_XCERD 0x58
121#define OMAP_MCBSP_REG_RCERE 0x5C
122#define OMAP_MCBSP_REG_RCERF 0x60
123#define OMAP_MCBSP_REG_XCERE 0x64
124#define OMAP_MCBSP_REG_XCERF 0x68
125#define OMAP_MCBSP_REG_RCERG 0x6C
126#define OMAP_MCBSP_REG_RCERH 0x70
127#define OMAP_MCBSP_REG_XCERG 0x74
128#define OMAP_MCBSP_REG_XCERH 0x78
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300129#define OMAP_MCBSP_REG_SYSCON 0x8C
130#define OMAP_MCBSP_REG_XCCR 0xAC
131#define OMAP_MCBSP_REG_RCCR 0xB0
Russell Kinga09e64f2008-08-05 16:14:15 +0100132
133#define AUDIO_MCBSP_DATAWRITE (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
134#define AUDIO_MCBSP_DATAREAD (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
135
136#define AUDIO_MCBSP OMAP_MCBSP2
137#define AUDIO_DMA_TX OMAP24XX_DMA_MCBSP2_TX
138#define AUDIO_DMA_RX OMAP24XX_DMA_MCBSP2_RX
139
140#endif
141
Russell Kinga09e64f2008-08-05 16:14:15 +0100142/************************** McBSP SPCR1 bit definitions ***********************/
143#define RRST 0x0001
144#define RRDY 0x0002
145#define RFULL 0x0004
146#define RSYNC_ERR 0x0008
147#define RINTM(value) ((value)<<4) /* bits 4:5 */
148#define ABIS 0x0040
149#define DXENA 0x0080
150#define CLKSTP(value) ((value)<<11) /* bits 11:12 */
151#define RJUST(value) ((value)<<13) /* bits 13:14 */
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300152#define ALB 0x8000
Russell Kinga09e64f2008-08-05 16:14:15 +0100153#define DLB 0x8000
154
155/************************** McBSP SPCR2 bit definitions ***********************/
156#define XRST 0x0001
157#define XRDY 0x0002
158#define XEMPTY 0x0004
159#define XSYNC_ERR 0x0008
160#define XINTM(value) ((value)<<4) /* bits 4:5 */
161#define GRST 0x0040
162#define FRST 0x0080
163#define SOFT 0x0100
164#define FREE 0x0200
165
166/************************** McBSP PCR bit definitions *************************/
167#define CLKRP 0x0001
168#define CLKXP 0x0002
169#define FSRP 0x0004
170#define FSXP 0x0008
171#define DR_STAT 0x0010
172#define DX_STAT 0x0020
173#define CLKS_STAT 0x0040
174#define SCLKME 0x0080
175#define CLKRM 0x0100
176#define CLKXM 0x0200
177#define FSRM 0x0400
178#define FSXM 0x0800
179#define RIOEN 0x1000
180#define XIOEN 0x2000
181#define IDLE_EN 0x4000
182
183/************************** McBSP RCR1 bit definitions ************************/
184#define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
185#define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
186
187/************************** McBSP XCR1 bit definitions ************************/
188#define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
189#define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
190
191/*************************** McBSP RCR2 bit definitions ***********************/
192#define RDATDLY(value) (value) /* Bits 0:1 */
193#define RFIG 0x0004
194#define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
195#define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
196#define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
197#define RPHASE 0x8000
198
199/*************************** McBSP XCR2 bit definitions ***********************/
200#define XDATDLY(value) (value) /* Bits 0:1 */
201#define XFIG 0x0004
202#define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
203#define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
204#define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
205#define XPHASE 0x8000
206
207/************************* McBSP SRGR1 bit definitions ************************/
208#define CLKGDV(value) (value) /* Bits 0:7 */
209#define FWID(value) ((value)<<8) /* Bits 8:15 */
210
211/************************* McBSP SRGR2 bit definitions ************************/
212#define FPER(value) (value) /* Bits 0:11 */
213#define FSGM 0x1000
214#define CLKSM 0x2000
215#define CLKSP 0x4000
216#define GSYNC 0x8000
217
218/************************* McBSP MCR1 bit definitions *************************/
219#define RMCM 0x0001
220#define RCBLK(value) ((value)<<2) /* Bits 2:4 */
221#define RPABLK(value) ((value)<<5) /* Bits 5:6 */
222#define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
223
224/************************* McBSP MCR2 bit definitions *************************/
225#define XMCM(value) (value) /* Bits 0:1 */
226#define XCBLK(value) ((value)<<2) /* Bits 2:4 */
227#define XPABLK(value) ((value)<<5) /* Bits 5:6 */
228#define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
229
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300230/*********************** McBSP XCCR bit definitions *************************/
231#define DILB 0x0020
232#define XDMAEN 0x0008
233#define XDISABLE 0x0001
234
235/********************** McBSP RCCR bit definitions *************************/
236#define RDMAEN 0x0008
237#define RDISABLE 0x0001
238
239/********************** McBSP SYSCONFIG bit definitions ********************/
240#define SOFTRST 0x0002
Russell Kinga09e64f2008-08-05 16:14:15 +0100241
242/* we don't do multichannel for now */
243struct omap_mcbsp_reg_cfg {
244 u16 spcr2;
245 u16 spcr1;
246 u16 rcr2;
247 u16 rcr1;
248 u16 xcr2;
249 u16 xcr1;
250 u16 srgr2;
251 u16 srgr1;
252 u16 mcr2;
253 u16 mcr1;
254 u16 pcr0;
255 u16 rcerc;
256 u16 rcerd;
257 u16 xcerc;
258 u16 xcerd;
259 u16 rcere;
260 u16 rcerf;
261 u16 xcere;
262 u16 xcerf;
263 u16 rcerg;
264 u16 rcerh;
265 u16 xcerg;
266 u16 xcerh;
267};
268
269typedef enum {
270 OMAP_MCBSP1 = 0,
271 OMAP_MCBSP2,
272 OMAP_MCBSP3,
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300273 OMAP_MCBSP4,
274 OMAP_MCBSP5
Russell Kinga09e64f2008-08-05 16:14:15 +0100275} omap_mcbsp_id;
276
277typedef int __bitwise omap_mcbsp_io_type_t;
278#define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
279#define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
280
281typedef enum {
282 OMAP_MCBSP_WORD_8 = 0,
283 OMAP_MCBSP_WORD_12,
284 OMAP_MCBSP_WORD_16,
285 OMAP_MCBSP_WORD_20,
286 OMAP_MCBSP_WORD_24,
287 OMAP_MCBSP_WORD_32,
288} omap_mcbsp_word_length;
289
290typedef enum {
291 OMAP_MCBSP_CLK_RISING = 0,
292 OMAP_MCBSP_CLK_FALLING,
293} omap_mcbsp_clk_polarity;
294
295typedef enum {
296 OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
297 OMAP_MCBSP_FS_ACTIVE_LOW,
298} omap_mcbsp_fs_polarity;
299
300typedef enum {
301 OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
302 OMAP_MCBSP_CLK_STP_MODE_DELAY,
303} omap_mcbsp_clk_stp_mode;
304
305
306/******* SPI specific mode **********/
307typedef enum {
308 OMAP_MCBSP_SPI_MASTER = 0,
309 OMAP_MCBSP_SPI_SLAVE,
310} omap_mcbsp_spi_mode;
311
312struct omap_mcbsp_spi_cfg {
313 omap_mcbsp_spi_mode spi_mode;
314 omap_mcbsp_clk_polarity rx_clock_polarity;
315 omap_mcbsp_clk_polarity tx_clock_polarity;
316 omap_mcbsp_fs_polarity fsx_polarity;
317 u8 clk_div;
318 omap_mcbsp_clk_stp_mode clk_stp_mode;
319 omap_mcbsp_word_length word_length;
320};
321
322/* Platform specific configuration */
323struct omap_mcbsp_ops {
324 void (*request)(unsigned int);
325 void (*free)(unsigned int);
Russell Kinga09e64f2008-08-05 16:14:15 +0100326};
327
328struct omap_mcbsp_platform_data {
Russell King65846902008-09-03 23:46:18 +0100329 unsigned long phys_base;
Russell Kinga09e64f2008-08-05 16:14:15 +0100330 u8 dma_rx_sync, dma_tx_sync;
331 u16 rx_irq, tx_irq;
332 struct omap_mcbsp_ops *ops;
333 char const *clk_name;
334};
335
336struct omap_mcbsp {
337 struct device *dev;
Russell King65846902008-09-03 23:46:18 +0100338 unsigned long phys_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;
342 omap_mcbsp_word_length rx_word_length;
343 omap_mcbsp_word_length tx_word_length;
344
345 omap_mcbsp_io_type_t io_type; /* IRQ or poll */
346 /* IRQ based TX/RX */
347 int rx_irq;
348 int tx_irq;
349
350 /* DMA stuff */
351 u8 dma_rx_sync;
352 short dma_rx_lch;
353 u8 dma_tx_sync;
354 short dma_tx_lch;
355
356 /* Completion queues */
357 struct completion tx_irq_completion;
358 struct completion rx_irq_completion;
359 struct completion tx_dma_completion;
360 struct completion rx_dma_completion;
361
362 /* Protect the field .free, while checking if the mcbsp is in use */
363 spinlock_t lock;
364 struct omap_mcbsp_platform_data *pdata;
365 struct clk *clk;
366};
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300367extern struct omap_mcbsp **mcbsp_ptr;
368extern int omap_mcbsp_count;
Russell Kinga09e64f2008-08-05 16:14:15 +0100369
370int omap_mcbsp_init(void);
371void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
372 int size);
373void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
374int omap_mcbsp_request(unsigned int id);
375void omap_mcbsp_free(unsigned int id);
376void omap_mcbsp_start(unsigned int id);
377void omap_mcbsp_stop(unsigned int id);
378void omap_mcbsp_xmit_word(unsigned int id, u32 word);
379u32 omap_mcbsp_recv_word(unsigned int id);
380
381int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
382int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
383int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
384int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
385
386
387/* SPI specific API */
388void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
389
390/* Polled read/write functions */
391int omap_mcbsp_pollread(unsigned int id, u16 * buf);
392int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300393int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
Russell Kinga09e64f2008-08-05 16:14:15 +0100394
395#endif