blob: ec6f81e06d394a7dcd6a7e98182be1f7099901b9 [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
Jarkko Nikula05228c32008-10-08 10:01:40 +030046#define OMAP2430_MCBSP3_BASE 0x4808c000
47#define OMAP2430_MCBSP4_BASE 0x4808e000
48#define OMAP2430_MCBSP5_BASE 0x48096000
Russell Kinga09e64f2008-08-05 16:14:15 +010049
50#define OMAP34XX_MCBSP1_BASE 0x48074000
51#define OMAP34XX_MCBSP2_BASE 0x49022000
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +030052#define OMAP34XX_MCBSP3_BASE 0x49024000
53#define OMAP34XX_MCBSP4_BASE 0x49026000
54#define OMAP34XX_MCBSP5_BASE 0x48096000
Russell Kinga09e64f2008-08-05 16:14:15 +010055
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +053056#define OMAP44XX_MCBSP1_BASE 0x49022000
57#define OMAP44XX_MCBSP2_BASE 0x49024000
58#define OMAP44XX_MCBSP3_BASE 0x49026000
59#define OMAP44XX_MCBSP4_BASE 0x48074000
60
Russell Kinga09e64f2008-08-05 16:14:15 +010061#if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX) || defined(CONFIG_ARCH_OMAP730)
62
63#define OMAP_MCBSP_REG_DRR2 0x00
64#define OMAP_MCBSP_REG_DRR1 0x02
65#define OMAP_MCBSP_REG_DXR2 0x04
66#define OMAP_MCBSP_REG_DXR1 0x06
67#define OMAP_MCBSP_REG_SPCR2 0x08
68#define OMAP_MCBSP_REG_SPCR1 0x0a
69#define OMAP_MCBSP_REG_RCR2 0x0c
70#define OMAP_MCBSP_REG_RCR1 0x0e
71#define OMAP_MCBSP_REG_XCR2 0x10
72#define OMAP_MCBSP_REG_XCR1 0x12
73#define OMAP_MCBSP_REG_SRGR2 0x14
74#define OMAP_MCBSP_REG_SRGR1 0x16
75#define OMAP_MCBSP_REG_MCR2 0x18
76#define OMAP_MCBSP_REG_MCR1 0x1a
77#define OMAP_MCBSP_REG_RCERA 0x1c
78#define OMAP_MCBSP_REG_RCERB 0x1e
79#define OMAP_MCBSP_REG_XCERA 0x20
80#define OMAP_MCBSP_REG_XCERB 0x22
81#define OMAP_MCBSP_REG_PCR0 0x24
82#define OMAP_MCBSP_REG_RCERC 0x26
83#define OMAP_MCBSP_REG_RCERD 0x28
84#define OMAP_MCBSP_REG_XCERC 0x2A
85#define OMAP_MCBSP_REG_XCERD 0x2C
86#define OMAP_MCBSP_REG_RCERE 0x2E
87#define OMAP_MCBSP_REG_RCERF 0x30
88#define OMAP_MCBSP_REG_XCERE 0x32
89#define OMAP_MCBSP_REG_XCERF 0x34
90#define OMAP_MCBSP_REG_RCERG 0x36
91#define OMAP_MCBSP_REG_RCERH 0x38
92#define OMAP_MCBSP_REG_XCERG 0x3A
93#define OMAP_MCBSP_REG_XCERH 0x3C
94
Tony Lindgren3127f8f2009-01-15 13:09:54 +020095/* Dummy defines, these are not available on omap1 */
96#define OMAP_MCBSP_REG_XCCR 0x00
97#define OMAP_MCBSP_REG_RCCR 0x00
98
Russell Kinga09e64f2008-08-05 16:14:15 +010099#define AUDIO_MCBSP_DATAWRITE (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DXR1)
100#define AUDIO_MCBSP_DATAREAD (OMAP1510_MCBSP1_BASE + OMAP_MCBSP_REG_DRR1)
101
102#define AUDIO_MCBSP OMAP_MCBSP1
103#define AUDIO_DMA_TX OMAP_DMA_MCBSP1_TX
104#define AUDIO_DMA_RX OMAP_DMA_MCBSP1_RX
105
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530106#elif defined(CONFIG_ARCH_OMAP24XX) || defined(CONFIG_ARCH_OMAP34XX) || \
107 defined(CONFIG_ARCH_OMAP4)
Russell Kinga09e64f2008-08-05 16:14:15 +0100108
109#define OMAP_MCBSP_REG_DRR2 0x00
110#define OMAP_MCBSP_REG_DRR1 0x04
111#define OMAP_MCBSP_REG_DXR2 0x08
112#define OMAP_MCBSP_REG_DXR1 0x0C
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300113#define OMAP_MCBSP_REG_DRR 0x00
114#define OMAP_MCBSP_REG_DXR 0x08
Russell Kinga09e64f2008-08-05 16:14:15 +0100115#define OMAP_MCBSP_REG_SPCR2 0x10
116#define OMAP_MCBSP_REG_SPCR1 0x14
117#define OMAP_MCBSP_REG_RCR2 0x18
118#define OMAP_MCBSP_REG_RCR1 0x1C
119#define OMAP_MCBSP_REG_XCR2 0x20
120#define OMAP_MCBSP_REG_XCR1 0x24
121#define OMAP_MCBSP_REG_SRGR2 0x28
122#define OMAP_MCBSP_REG_SRGR1 0x2C
123#define OMAP_MCBSP_REG_MCR2 0x30
124#define OMAP_MCBSP_REG_MCR1 0x34
125#define OMAP_MCBSP_REG_RCERA 0x38
126#define OMAP_MCBSP_REG_RCERB 0x3C
127#define OMAP_MCBSP_REG_XCERA 0x40
128#define OMAP_MCBSP_REG_XCERB 0x44
129#define OMAP_MCBSP_REG_PCR0 0x48
130#define OMAP_MCBSP_REG_RCERC 0x4C
131#define OMAP_MCBSP_REG_RCERD 0x50
132#define OMAP_MCBSP_REG_XCERC 0x54
133#define OMAP_MCBSP_REG_XCERD 0x58
134#define OMAP_MCBSP_REG_RCERE 0x5C
135#define OMAP_MCBSP_REG_RCERF 0x60
136#define OMAP_MCBSP_REG_XCERE 0x64
137#define OMAP_MCBSP_REG_XCERF 0x68
138#define OMAP_MCBSP_REG_RCERG 0x6C
139#define OMAP_MCBSP_REG_RCERH 0x70
140#define OMAP_MCBSP_REG_XCERG 0x74
141#define OMAP_MCBSP_REG_XCERH 0x78
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300142#define OMAP_MCBSP_REG_SYSCON 0x8C
143#define OMAP_MCBSP_REG_XCCR 0xAC
144#define OMAP_MCBSP_REG_RCCR 0xB0
Russell Kinga09e64f2008-08-05 16:14:15 +0100145
146#define AUDIO_MCBSP_DATAWRITE (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DXR1)
147#define AUDIO_MCBSP_DATAREAD (OMAP24XX_MCBSP2_BASE + OMAP_MCBSP_REG_DRR1)
148
149#define AUDIO_MCBSP OMAP_MCBSP2
150#define AUDIO_DMA_TX OMAP24XX_DMA_MCBSP2_TX
151#define AUDIO_DMA_RX OMAP24XX_DMA_MCBSP2_RX
152
153#endif
154
Russell Kinga09e64f2008-08-05 16:14:15 +0100155/************************** McBSP SPCR1 bit definitions ***********************/
156#define RRST 0x0001
157#define RRDY 0x0002
158#define RFULL 0x0004
159#define RSYNC_ERR 0x0008
160#define RINTM(value) ((value)<<4) /* bits 4:5 */
161#define ABIS 0x0040
162#define DXENA 0x0080
163#define CLKSTP(value) ((value)<<11) /* bits 11:12 */
164#define RJUST(value) ((value)<<13) /* bits 13:14 */
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300165#define ALB 0x8000
Russell Kinga09e64f2008-08-05 16:14:15 +0100166#define DLB 0x8000
167
168/************************** McBSP SPCR2 bit definitions ***********************/
169#define XRST 0x0001
170#define XRDY 0x0002
171#define XEMPTY 0x0004
172#define XSYNC_ERR 0x0008
173#define XINTM(value) ((value)<<4) /* bits 4:5 */
174#define GRST 0x0040
175#define FRST 0x0080
176#define SOFT 0x0100
177#define FREE 0x0200
178
179/************************** McBSP PCR bit definitions *************************/
180#define CLKRP 0x0001
181#define CLKXP 0x0002
182#define FSRP 0x0004
183#define FSXP 0x0008
184#define DR_STAT 0x0010
185#define DX_STAT 0x0020
186#define CLKS_STAT 0x0040
187#define SCLKME 0x0080
188#define CLKRM 0x0100
189#define CLKXM 0x0200
190#define FSRM 0x0400
191#define FSXM 0x0800
192#define RIOEN 0x1000
193#define XIOEN 0x2000
194#define IDLE_EN 0x4000
195
196/************************** McBSP RCR1 bit definitions ************************/
197#define RWDLEN1(value) ((value)<<5) /* Bits 5:7 */
198#define RFRLEN1(value) ((value)<<8) /* Bits 8:14 */
199
200/************************** McBSP XCR1 bit definitions ************************/
201#define XWDLEN1(value) ((value)<<5) /* Bits 5:7 */
202#define XFRLEN1(value) ((value)<<8) /* Bits 8:14 */
203
204/*************************** McBSP RCR2 bit definitions ***********************/
205#define RDATDLY(value) (value) /* Bits 0:1 */
206#define RFIG 0x0004
207#define RCOMPAND(value) ((value)<<3) /* Bits 3:4 */
208#define RWDLEN2(value) ((value)<<5) /* Bits 5:7 */
209#define RFRLEN2(value) ((value)<<8) /* Bits 8:14 */
210#define RPHASE 0x8000
211
212/*************************** McBSP XCR2 bit definitions ***********************/
213#define XDATDLY(value) (value) /* Bits 0:1 */
214#define XFIG 0x0004
215#define XCOMPAND(value) ((value)<<3) /* Bits 3:4 */
216#define XWDLEN2(value) ((value)<<5) /* Bits 5:7 */
217#define XFRLEN2(value) ((value)<<8) /* Bits 8:14 */
218#define XPHASE 0x8000
219
220/************************* McBSP SRGR1 bit definitions ************************/
221#define CLKGDV(value) (value) /* Bits 0:7 */
222#define FWID(value) ((value)<<8) /* Bits 8:15 */
223
224/************************* McBSP SRGR2 bit definitions ************************/
225#define FPER(value) (value) /* Bits 0:11 */
226#define FSGM 0x1000
227#define CLKSM 0x2000
228#define CLKSP 0x4000
229#define GSYNC 0x8000
230
231/************************* McBSP MCR1 bit definitions *************************/
232#define RMCM 0x0001
233#define RCBLK(value) ((value)<<2) /* Bits 2:4 */
234#define RPABLK(value) ((value)<<5) /* Bits 5:6 */
235#define RPBBLK(value) ((value)<<7) /* Bits 7:8 */
236
237/************************* McBSP MCR2 bit definitions *************************/
238#define XMCM(value) (value) /* Bits 0:1 */
239#define XCBLK(value) ((value)<<2) /* Bits 2:4 */
240#define XPABLK(value) ((value)<<5) /* Bits 5:6 */
241#define XPBBLK(value) ((value)<<7) /* Bits 7:8 */
242
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300243/*********************** McBSP XCCR bit definitions *************************/
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200244#define EXTCLKGATE 0x8000
245#define PPCONNECT 0x4000
246#define DXENDLY(value) ((value)<<12) /* Bits 12:13 */
247#define XFULL_CYCLE 0x0800
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300248#define DILB 0x0020
249#define XDMAEN 0x0008
250#define XDISABLE 0x0001
251
252/********************** McBSP RCCR bit definitions *************************/
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200253#define RFULL_CYCLE 0x0800
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300254#define RDMAEN 0x0008
255#define RDISABLE 0x0001
256
257/********************** McBSP SYSCONFIG bit definitions ********************/
258#define SOFTRST 0x0002
Russell Kinga09e64f2008-08-05 16:14:15 +0100259
260/* we don't do multichannel for now */
261struct omap_mcbsp_reg_cfg {
262 u16 spcr2;
263 u16 spcr1;
264 u16 rcr2;
265 u16 rcr1;
266 u16 xcr2;
267 u16 xcr1;
268 u16 srgr2;
269 u16 srgr1;
270 u16 mcr2;
271 u16 mcr1;
272 u16 pcr0;
273 u16 rcerc;
274 u16 rcerd;
275 u16 xcerc;
276 u16 xcerd;
277 u16 rcere;
278 u16 rcerf;
279 u16 xcere;
280 u16 xcerf;
281 u16 rcerg;
282 u16 rcerh;
283 u16 xcerg;
284 u16 xcerh;
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200285 u16 xccr;
286 u16 rccr;
Russell Kinga09e64f2008-08-05 16:14:15 +0100287};
288
289typedef enum {
290 OMAP_MCBSP1 = 0,
291 OMAP_MCBSP2,
292 OMAP_MCBSP3,
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300293 OMAP_MCBSP4,
294 OMAP_MCBSP5
Russell Kinga09e64f2008-08-05 16:14:15 +0100295} omap_mcbsp_id;
296
297typedef int __bitwise omap_mcbsp_io_type_t;
298#define OMAP_MCBSP_IRQ_IO ((__force omap_mcbsp_io_type_t) 1)
299#define OMAP_MCBSP_POLL_IO ((__force omap_mcbsp_io_type_t) 2)
300
301typedef enum {
302 OMAP_MCBSP_WORD_8 = 0,
303 OMAP_MCBSP_WORD_12,
304 OMAP_MCBSP_WORD_16,
305 OMAP_MCBSP_WORD_20,
306 OMAP_MCBSP_WORD_24,
307 OMAP_MCBSP_WORD_32,
308} omap_mcbsp_word_length;
309
310typedef enum {
311 OMAP_MCBSP_CLK_RISING = 0,
312 OMAP_MCBSP_CLK_FALLING,
313} omap_mcbsp_clk_polarity;
314
315typedef enum {
316 OMAP_MCBSP_FS_ACTIVE_HIGH = 0,
317 OMAP_MCBSP_FS_ACTIVE_LOW,
318} omap_mcbsp_fs_polarity;
319
320typedef enum {
321 OMAP_MCBSP_CLK_STP_MODE_NO_DELAY = 0,
322 OMAP_MCBSP_CLK_STP_MODE_DELAY,
323} omap_mcbsp_clk_stp_mode;
324
325
326/******* SPI specific mode **********/
327typedef enum {
328 OMAP_MCBSP_SPI_MASTER = 0,
329 OMAP_MCBSP_SPI_SLAVE,
330} omap_mcbsp_spi_mode;
331
332struct omap_mcbsp_spi_cfg {
333 omap_mcbsp_spi_mode spi_mode;
334 omap_mcbsp_clk_polarity rx_clock_polarity;
335 omap_mcbsp_clk_polarity tx_clock_polarity;
336 omap_mcbsp_fs_polarity fsx_polarity;
337 u8 clk_div;
338 omap_mcbsp_clk_stp_mode clk_stp_mode;
339 omap_mcbsp_word_length word_length;
340};
341
342/* Platform specific configuration */
343struct omap_mcbsp_ops {
344 void (*request)(unsigned int);
345 void (*free)(unsigned int);
Russell Kinga09e64f2008-08-05 16:14:15 +0100346};
347
348struct omap_mcbsp_platform_data {
Russell King65846902008-09-03 23:46:18 +0100349 unsigned long phys_base;
Russell Kinga09e64f2008-08-05 16:14:15 +0100350 u8 dma_rx_sync, dma_tx_sync;
351 u16 rx_irq, tx_irq;
352 struct omap_mcbsp_ops *ops;
Russell Kinga09e64f2008-08-05 16:14:15 +0100353};
354
355struct omap_mcbsp {
356 struct device *dev;
Russell King65846902008-09-03 23:46:18 +0100357 unsigned long phys_base;
Russell Kingd592dd12008-09-04 14:25:42 +0100358 void __iomem *io_base;
Russell Kinga09e64f2008-08-05 16:14:15 +0100359 u8 id;
360 u8 free;
361 omap_mcbsp_word_length rx_word_length;
362 omap_mcbsp_word_length tx_word_length;
363
364 omap_mcbsp_io_type_t io_type; /* IRQ or poll */
365 /* IRQ based TX/RX */
366 int rx_irq;
367 int tx_irq;
368
369 /* DMA stuff */
370 u8 dma_rx_sync;
371 short dma_rx_lch;
372 u8 dma_tx_sync;
373 short dma_tx_lch;
374
375 /* Completion queues */
376 struct completion tx_irq_completion;
377 struct completion rx_irq_completion;
378 struct completion tx_dma_completion;
379 struct completion rx_dma_completion;
380
381 /* Protect the field .free, while checking if the mcbsp is in use */
382 spinlock_t lock;
383 struct omap_mcbsp_platform_data *pdata;
Russell Kingb820ce42009-01-23 10:26:46 +0000384 struct clk *iclk;
385 struct clk *fclk;
Russell Kinga09e64f2008-08-05 16:14:15 +0100386};
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300387extern struct omap_mcbsp **mcbsp_ptr;
388extern int omap_mcbsp_count;
Russell Kinga09e64f2008-08-05 16:14:15 +0100389
390int omap_mcbsp_init(void);
391void omap_mcbsp_register_board_cfg(struct omap_mcbsp_platform_data *config,
392 int size);
393void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg * config);
394int omap_mcbsp_request(unsigned int id);
395void omap_mcbsp_free(unsigned int id);
396void omap_mcbsp_start(unsigned int id);
397void omap_mcbsp_stop(unsigned int id);
398void omap_mcbsp_xmit_word(unsigned int id, u32 word);
399u32 omap_mcbsp_recv_word(unsigned int id);
400
401int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
402int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer, unsigned int length);
403int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word);
404int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 * word);
405
406
407/* SPI specific API */
408void omap_mcbsp_set_spi_mode(unsigned int id, const struct omap_mcbsp_spi_cfg * spi_cfg);
409
410/* Polled read/write functions */
411int omap_mcbsp_pollread(unsigned int id, u16 * buf);
412int omap_mcbsp_pollwrite(unsigned int id, u16 buf);
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300413int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type);
Russell Kinga09e64f2008-08-05 16:14:15 +0100414
415#endif