blob: 4c9c999dfa4a5a02657069ddf9c0c27bef258df9 [file] [log] [blame]
Eduardo Valentin78673bc2008-07-03 12:24:40 +03001/*
2 * linux/arch/arm/mach-omap2/mcbsp.c
3 *
4 * Copyright (C) 2008 Instituto Nokia de Tecnologia
5 * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Multichannel mode not supported.
12 */
13#include <linux/module.h>
14#include <linux/init.h>
15#include <linux/clk.h>
16#include <linux/err.h>
17#include <linux/io.h>
18#include <linux/platform_device.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090019#include <linux/slab.h>
Eduardo Valentin78673bc2008-07-03 12:24:40 +030020
Tony Lindgrendd7667a2009-01-15 13:09:51 +020021#include <mach/irqs.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070022#include <plat/dma.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070023#include <plat/cpu.h>
24#include <plat/mcbsp.h>
Paul Walmsleycf4c87a2010-10-08 11:40:19 -060025#include <plat/control.h>
Eduardo Valentin78673bc2008-07-03 12:24:40 +030026
Paul Walmsleycf4c87a2010-10-08 11:40:19 -060027/* McBSP internal signal muxing functions */
28
29void omap2_mcbsp1_mux_clkr_src(u8 mux)
30{
31 u32 v;
32
33 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
34 if (mux == CLKR_SRC_CLKR)
35 v &= OMAP2_MCBSP1_CLKR_MASK;
36 else if (mux == CLKR_SRC_CLKX)
37 v |= OMAP2_MCBSP1_CLKR_MASK;
38 omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
39}
40EXPORT_SYMBOL(omap2_mcbsp1_mux_clkr_src);
41
42void omap2_mcbsp1_mux_fsr_src(u8 mux)
43{
44 u32 v;
45
46 v = omap_ctrl_readl(OMAP2_CONTROL_DEVCONF0);
47 if (mux == FSR_SRC_FSR)
48 v &= OMAP2_MCBSP1_FSR_MASK;
49 else if (mux == FSR_SRC_FSX)
50 v |= OMAP2_MCBSP1_FSR_MASK;
51 omap_ctrl_writel(v, OMAP2_CONTROL_DEVCONF0);
52}
53EXPORT_SYMBOL(omap2_mcbsp1_mux_fsr_src);
54
55/* Platform data */
Eduardo Valentin78673bc2008-07-03 12:24:40 +030056
Jarkko Nikula05228c32008-10-08 10:01:40 +030057#ifdef CONFIG_ARCH_OMAP2420
58static struct omap_mcbsp_platform_data omap2420_mcbsp_pdata[] = {
Eduardo Valentin78673bc2008-07-03 12:24:40 +030059 {
Russell King65846902008-09-03 23:46:18 +010060 .phys_base = OMAP24XX_MCBSP1_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +030061 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
62 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
63 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
64 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Eduardo Valentin78673bc2008-07-03 12:24:40 +030065 },
66 {
Russell King65846902008-09-03 23:46:18 +010067 .phys_base = OMAP24XX_MCBSP2_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +030068 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
69 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
70 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
71 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Eduardo Valentin78673bc2008-07-03 12:24:40 +030072 },
73};
Jarkko Nikula05228c32008-10-08 10:01:40 +030074#define OMAP2420_MCBSP_PDATA_SZ ARRAY_SIZE(omap2420_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080075#define OMAP2420_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Eduardo Valentin78673bc2008-07-03 12:24:40 +030076#else
Jarkko Nikula05228c32008-10-08 10:01:40 +030077#define omap2420_mcbsp_pdata NULL
78#define OMAP2420_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080079#define OMAP2420_MCBSP_REG_NUM 0
Jarkko Nikula05228c32008-10-08 10:01:40 +030080#endif
81
82#ifdef CONFIG_ARCH_OMAP2430
83static struct omap_mcbsp_platform_data omap2430_mcbsp_pdata[] = {
84 {
85 .phys_base = OMAP24XX_MCBSP1_BASE,
86 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
87 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
88 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
89 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +030090 },
91 {
92 .phys_base = OMAP24XX_MCBSP2_BASE,
93 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
94 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
95 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
96 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +030097 },
98 {
99 .phys_base = OMAP2430_MCBSP3_BASE,
100 .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX,
101 .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX,
102 .rx_irq = INT_24XX_MCBSP3_IRQ_RX,
103 .tx_irq = INT_24XX_MCBSP3_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300104 },
105 {
106 .phys_base = OMAP2430_MCBSP4_BASE,
107 .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX,
108 .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX,
109 .rx_irq = INT_24XX_MCBSP4_IRQ_RX,
110 .tx_irq = INT_24XX_MCBSP4_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300111 },
112 {
113 .phys_base = OMAP2430_MCBSP5_BASE,
114 .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX,
115 .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX,
116 .rx_irq = INT_24XX_MCBSP5_IRQ_RX,
117 .tx_irq = INT_24XX_MCBSP5_IRQ_TX,
Jarkko Nikula05228c32008-10-08 10:01:40 +0300118 },
119};
120#define OMAP2430_MCBSP_PDATA_SZ ARRAY_SIZE(omap2430_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800121#define OMAP2430_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Jarkko Nikula05228c32008-10-08 10:01:40 +0300122#else
123#define omap2430_mcbsp_pdata NULL
124#define OMAP2430_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800125#define OMAP2430_MCBSP_REG_NUM 0
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300126#endif
127
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800128#ifdef CONFIG_ARCH_OMAP3
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300129static struct omap_mcbsp_platform_data omap34xx_mcbsp_pdata[] = {
130 {
Russell King65846902008-09-03 23:46:18 +0100131 .phys_base = OMAP34XX_MCBSP1_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300132 .dma_rx_sync = OMAP24XX_DMA_MCBSP1_RX,
133 .dma_tx_sync = OMAP24XX_DMA_MCBSP1_TX,
134 .rx_irq = INT_24XX_MCBSP1_IRQ_RX,
135 .tx_irq = INT_24XX_MCBSP1_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300136 .buffer_size = 0x80, /* The FIFO has 128 locations */
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300137 },
138 {
Russell King65846902008-09-03 23:46:18 +0100139 .phys_base = OMAP34XX_MCBSP2_BASE,
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000140 .phys_base_st = OMAP34XX_MCBSP2_ST_BASE,
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300141 .dma_rx_sync = OMAP24XX_DMA_MCBSP2_RX,
142 .dma_tx_sync = OMAP24XX_DMA_MCBSP2_TX,
143 .rx_irq = INT_24XX_MCBSP2_IRQ_RX,
144 .tx_irq = INT_24XX_MCBSP2_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300145 .buffer_size = 0x500, /* The FIFO has 1024 + 256 locations */
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300146 },
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300147 {
148 .phys_base = OMAP34XX_MCBSP3_BASE,
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000149 .phys_base_st = OMAP34XX_MCBSP3_ST_BASE,
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300150 .dma_rx_sync = OMAP24XX_DMA_MCBSP3_RX,
151 .dma_tx_sync = OMAP24XX_DMA_MCBSP3_TX,
152 .rx_irq = INT_24XX_MCBSP3_IRQ_RX,
153 .tx_irq = INT_24XX_MCBSP3_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300154 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300155 },
156 {
157 .phys_base = OMAP34XX_MCBSP4_BASE,
158 .dma_rx_sync = OMAP24XX_DMA_MCBSP4_RX,
159 .dma_tx_sync = OMAP24XX_DMA_MCBSP4_TX,
160 .rx_irq = INT_24XX_MCBSP4_IRQ_RX,
161 .tx_irq = INT_24XX_MCBSP4_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300162 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300163 },
164 {
165 .phys_base = OMAP34XX_MCBSP5_BASE,
166 .dma_rx_sync = OMAP24XX_DMA_MCBSP5_RX,
167 .dma_tx_sync = OMAP24XX_DMA_MCBSP5_TX,
168 .rx_irq = INT_24XX_MCBSP5_IRQ_RX,
169 .tx_irq = INT_24XX_MCBSP5_IRQ_TX,
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300170 .buffer_size = 0x80, /* The FIFO has 128 locations */
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300171 },
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300172};
173#define OMAP34XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap34xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800174#define OMAP34XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300175#else
176#define omap34xx_mcbsp_pdata NULL
177#define OMAP34XX_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800178#define OMAP34XX_MCBSP_REG_NUM 0
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300179#endif
180
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530181static struct omap_mcbsp_platform_data omap44xx_mcbsp_pdata[] = {
182 {
183 .phys_base = OMAP44XX_MCBSP1_BASE,
184 .dma_rx_sync = OMAP44XX_DMA_MCBSP1_RX,
185 .dma_tx_sync = OMAP44XX_DMA_MCBSP1_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500186 .tx_irq = OMAP44XX_IRQ_MCBSP1,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530187 },
188 {
189 .phys_base = OMAP44XX_MCBSP2_BASE,
190 .dma_rx_sync = OMAP44XX_DMA_MCBSP2_RX,
191 .dma_tx_sync = OMAP44XX_DMA_MCBSP2_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500192 .tx_irq = OMAP44XX_IRQ_MCBSP2,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530193 },
194 {
195 .phys_base = OMAP44XX_MCBSP3_BASE,
196 .dma_rx_sync = OMAP44XX_DMA_MCBSP3_RX,
197 .dma_tx_sync = OMAP44XX_DMA_MCBSP3_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500198 .tx_irq = OMAP44XX_IRQ_MCBSP3,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530199 },
200 {
201 .phys_base = OMAP44XX_MCBSP4_BASE,
202 .dma_rx_sync = OMAP44XX_DMA_MCBSP4_RX,
203 .dma_tx_sync = OMAP44XX_DMA_MCBSP4_TX,
Jorge Eduardo Candelaria9319b9d2010-05-12 12:18:39 -0500204 .tx_irq = OMAP44XX_IRQ_MCBSP4,
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530205 },
206};
207#define OMAP44XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap44xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800208#define OMAP44XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_RCCR / sizeof(u32) + 1)
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530209
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300210static int __init omap2_mcbsp_init(void)
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300211{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800212 if (cpu_is_omap2420()) {
Jarkko Nikula05228c32008-10-08 10:01:40 +0300213 omap_mcbsp_count = OMAP2420_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800214 omap_mcbsp_cache_size = OMAP2420_MCBSP_REG_NUM * sizeof(u16);
215 } else if (cpu_is_omap2430()) {
Jarkko Nikula05228c32008-10-08 10:01:40 +0300216 omap_mcbsp_count = OMAP2430_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800217 omap_mcbsp_cache_size = OMAP2430_MCBSP_REG_NUM * sizeof(u32);
218 } else if (cpu_is_omap34xx()) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300219 omap_mcbsp_count = OMAP34XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800220 omap_mcbsp_cache_size = OMAP34XX_MCBSP_REG_NUM * sizeof(u32);
221 } else if (cpu_is_omap44xx()) {
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530222 omap_mcbsp_count = OMAP44XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800223 omap_mcbsp_cache_size = OMAP44XX_MCBSP_REG_NUM * sizeof(u32);
224 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300225
226 mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
227 GFP_KERNEL);
228 if (!mcbsp_ptr)
229 return -ENOMEM;
230
Jarkko Nikula05228c32008-10-08 10:01:40 +0300231 if (cpu_is_omap2420())
232 omap_mcbsp_register_board_cfg(omap2420_mcbsp_pdata,
233 OMAP2420_MCBSP_PDATA_SZ);
234 if (cpu_is_omap2430())
235 omap_mcbsp_register_board_cfg(omap2430_mcbsp_pdata,
236 OMAP2430_MCBSP_PDATA_SZ);
Chandra Shekhar9c8e3a02008-10-08 10:01:40 +0300237 if (cpu_is_omap34xx())
238 omap_mcbsp_register_board_cfg(omap34xx_mcbsp_pdata,
239 OMAP34XX_MCBSP_PDATA_SZ);
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530240 if (cpu_is_omap44xx())
241 omap_mcbsp_register_board_cfg(omap44xx_mcbsp_pdata,
242 OMAP44XX_MCBSP_PDATA_SZ);
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300243
Eduardo Valentin78673bc2008-07-03 12:24:40 +0300244 return omap_mcbsp_init();
245}
246arch_initcall(omap2_mcbsp_init);