blob: 820973666f34c0bf83997444d1cc30a2afab50f4 [file] [log] [blame]
Eduardo Valentin44ec9a32008-07-03 12:24:40 +03001/*
2 * linux/arch/arm/mach-omap1/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 Valentin44ec9a32008-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>
23#include <plat/mux.h>
24#include <plat/cpu.h>
25#include <plat/mcbsp.h>
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030026
27#define DPS_RSTCT2_PER_EN (1 << 0)
28#define DSP_RSTCT2_WD_PER_EN (1 << 1)
29
Russell Kingb820ce42009-01-23 10:26:46 +000030static int dsp_use;
31static struct clk *api_clk;
32static struct clk *dsp_clk;
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030033
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030034static void omap1_mcbsp_request(unsigned int id)
35{
36 /*
37 * On 1510, 1610 and 1710, McBSP1 and McBSP3
38 * are DSP public peripherals.
39 */
40 if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
Russell Kingb820ce42009-01-23 10:26:46 +000041 if (dsp_use++ == 0) {
Arun KSd53eb732009-04-23 21:11:07 -060042 api_clk = clk_get(NULL, "api_ck");
43 dsp_clk = clk_get(NULL, "dsp_ck");
Russell Kingb820ce42009-01-23 10:26:46 +000044 if (!IS_ERR(api_clk) && !IS_ERR(dsp_clk)) {
45 clk_enable(api_clk);
46 clk_enable(dsp_clk);
47
Russell Kingb820ce42009-01-23 10:26:46 +000048 /*
49 * DSP external peripheral reset
50 * FIXME: This should be moved to dsp code
51 */
52 __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
53 DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
54 }
55 }
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030056 }
57}
58
59static void omap1_mcbsp_free(unsigned int id)
60{
Russell Kingb820ce42009-01-23 10:26:46 +000061 if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
62 if (--dsp_use == 0) {
Russell Kingb820ce42009-01-23 10:26:46 +000063 if (!IS_ERR(api_clk)) {
64 clk_disable(api_clk);
65 clk_put(api_clk);
66 }
67 if (!IS_ERR(dsp_clk)) {
68 clk_disable(dsp_clk);
69 clk_put(dsp_clk);
70 }
71 }
72 }
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030073}
74
75static struct omap_mcbsp_ops omap1_mcbsp_ops = {
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030076 .request = omap1_mcbsp_request,
77 .free = omap1_mcbsp_free,
78};
79
Alistair Buxtonbf1cb7e2009-09-22 06:49:35 +010080#if defined(CONFIG_ARCH_OMAP730) || defined(CONFIG_ARCH_OMAP850)
Alistair Buxton7c006922009-09-22 10:02:58 +010081static struct omap_mcbsp_platform_data omap7xx_mcbsp_pdata[] = {
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030082 {
Alistair Buxton7c006922009-09-22 10:02:58 +010083 .phys_base = OMAP7XX_MCBSP1_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030084 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
85 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
Alistair Buxton372b1c32009-09-18 04:09:39 +010086 .rx_irq = INT_7XX_McBSP1RX,
87 .tx_irq = INT_7XX_McBSP1TX,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030088 .ops = &omap1_mcbsp_ops,
89 },
90 {
Alistair Buxton7c006922009-09-22 10:02:58 +010091 .phys_base = OMAP7XX_MCBSP2_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030092 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
93 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
Alistair Buxton372b1c32009-09-18 04:09:39 +010094 .rx_irq = INT_7XX_McBSP2RX,
95 .tx_irq = INT_7XX_McBSP2TX,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +030096 .ops = &omap1_mcbsp_ops,
97 },
98};
Alistair Buxton7c006922009-09-22 10:02:58 +010099#define OMAP7XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap7xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800100#define OMAP7XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300101#else
Alistair Buxton7c006922009-09-22 10:02:58 +0100102#define omap7xx_mcbsp_pdata NULL
103#define OMAP7XX_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800104#define OMAP7XX_MCBSP_REG_NUM 0
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300105#endif
106
107#ifdef CONFIG_ARCH_OMAP15XX
108static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
109 {
Russell King65846902008-09-03 23:46:18 +0100110 .phys_base = OMAP1510_MCBSP1_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300111 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
112 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
113 .rx_irq = INT_McBSP1RX,
114 .tx_irq = INT_McBSP1TX,
115 .ops = &omap1_mcbsp_ops,
Stanley.Miao06151152009-01-29 08:57:12 -0800116 },
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300117 {
Russell King65846902008-09-03 23:46:18 +0100118 .phys_base = OMAP1510_MCBSP2_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300119 .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
120 .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
121 .rx_irq = INT_1510_SPI_RX,
122 .tx_irq = INT_1510_SPI_TX,
123 .ops = &omap1_mcbsp_ops,
124 },
125 {
Russell King65846902008-09-03 23:46:18 +0100126 .phys_base = OMAP1510_MCBSP3_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300127 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
128 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
129 .rx_irq = INT_McBSP3RX,
130 .tx_irq = INT_McBSP3TX,
131 .ops = &omap1_mcbsp_ops,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300132 },
133};
134#define OMAP15XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap15xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800135#define OMAP15XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300136#else
137#define omap15xx_mcbsp_pdata NULL
138#define OMAP15XX_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800139#define OMAP15XX_MCBSP_REG_NUM 0
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300140#endif
141
142#ifdef CONFIG_ARCH_OMAP16XX
143static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
144 {
Russell King65846902008-09-03 23:46:18 +0100145 .phys_base = OMAP1610_MCBSP1_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300146 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
147 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
148 .rx_irq = INT_McBSP1RX,
149 .tx_irq = INT_McBSP1TX,
150 .ops = &omap1_mcbsp_ops,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300151 },
152 {
Russell King65846902008-09-03 23:46:18 +0100153 .phys_base = OMAP1610_MCBSP2_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300154 .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
155 .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
156 .rx_irq = INT_1610_McBSP2_RX,
157 .tx_irq = INT_1610_McBSP2_TX,
158 .ops = &omap1_mcbsp_ops,
159 },
160 {
Russell King65846902008-09-03 23:46:18 +0100161 .phys_base = OMAP1610_MCBSP3_BASE,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300162 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
163 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
164 .rx_irq = INT_McBSP3RX,
165 .tx_irq = INT_McBSP3TX,
166 .ops = &omap1_mcbsp_ops,
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300167 },
168};
169#define OMAP16XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap16xx_mcbsp_pdata)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800170#define OMAP16XX_MCBSP_REG_NUM (OMAP_MCBSP_REG_XCERH / sizeof(u16) + 1)
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300171#else
172#define omap16xx_mcbsp_pdata NULL
173#define OMAP16XX_MCBSP_PDATA_SZ 0
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800174#define OMAP16XX_MCBSP_REG_NUM 0
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300175#endif
176
Aaro Koskinene6f16822010-11-18 19:59:47 +0200177static int __init omap1_mcbsp_init(void)
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300178{
Tony Lindgren7f9187c2010-12-10 09:46:24 -0800179 if (!cpu_class_is_omap1())
180 return -ENODEV;
181
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800182 if (cpu_is_omap7xx()) {
Alistair Buxton7c006922009-09-22 10:02:58 +0100183 omap_mcbsp_count = OMAP7XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800184 omap_mcbsp_cache_size = OMAP7XX_MCBSP_REG_NUM * sizeof(u16);
185 } else if (cpu_is_omap15xx()) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300186 omap_mcbsp_count = OMAP15XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800187 omap_mcbsp_cache_size = OMAP15XX_MCBSP_REG_NUM * sizeof(u16);
188 } else if (cpu_is_omap16xx()) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300189 omap_mcbsp_count = OMAP16XX_MCBSP_PDATA_SZ;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800190 omap_mcbsp_cache_size = OMAP16XX_MCBSP_REG_NUM * sizeof(u16);
191 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300192
193 mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
194 GFP_KERNEL);
195 if (!mcbsp_ptr)
196 return -ENOMEM;
197
Alistair Buxtonbf1cb7e2009-09-22 06:49:35 +0100198 if (cpu_is_omap7xx())
Alistair Buxton7c006922009-09-22 10:02:58 +0100199 omap_mcbsp_register_board_cfg(omap7xx_mcbsp_pdata,
200 OMAP7XX_MCBSP_PDATA_SZ);
Eduardo Valentin44ec9a32008-07-03 12:24:40 +0300201
202 if (cpu_is_omap15xx())
203 omap_mcbsp_register_board_cfg(omap15xx_mcbsp_pdata,
204 OMAP15XX_MCBSP_PDATA_SZ);
205
206 if (cpu_is_omap16xx())
207 omap_mcbsp_register_board_cfg(omap16xx_mcbsp_pdata,
208 OMAP16XX_MCBSP_PDATA_SZ);
209
210 return omap_mcbsp_init();
211}
212
213arch_initcall(omap1_mcbsp_init);