2 * linux/arch/arm/mach-omap1/mcbsp.c
4 * Copyright (C) 2008 Instituto Nokia de Tecnologia
5 * Contact: Eduardo Valentin <eduardo.valentin@indt.org.br>
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.
11 * Multichannel mode not supported.
13 #include <linux/module.h>
14 #include <linux/init.h>
15 #include <linux/clk.h>
16 #include <linux/err.h>
18 #include <linux/platform_device.h>
21 #include <mach/irqs.h>
24 #include <mach/mcbsp.h>
25 #include <mach/dsp_common.h>
27 #define DPS_RSTCT2_PER_EN (1 << 0)
28 #define DSP_RSTCT2_WD_PER_EN (1 << 1)
30 struct mcbsp_internal_clk {
36 #if defined(CONFIG_ARCH_OMAP15XX) || defined(CONFIG_ARCH_OMAP16XX)
37 static void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
39 const char *clk_names[] = { "dsp_ck", "api_ck", "dspxor_ck" };
42 mclk->n_childs = ARRAY_SIZE(clk_names);
43 mclk->childs = kzalloc(mclk->n_childs * sizeof(struct clk *),
46 for (i = 0; i < mclk->n_childs; i++) {
47 /* We fake a platform device to get correct device id */
48 struct platform_device pdev;
50 pdev.dev.bus = &platform_bus_type;
51 pdev.id = mclk->clk.id;
52 mclk->childs[i] = clk_get(&pdev.dev, clk_names[i]);
53 if (IS_ERR(mclk->childs[i]))
54 printk(KERN_ERR "Could not get clock %s (%d).\n",
55 clk_names[i], mclk->clk.id);
59 static int omap_mcbsp_clk_enable(struct clk *clk)
61 struct mcbsp_internal_clk *mclk = container_of(clk,
62 struct mcbsp_internal_clk, clk);
65 for (i = 0; i < mclk->n_childs; i++)
66 clk_enable(mclk->childs[i]);
70 static void omap_mcbsp_clk_disable(struct clk *clk)
72 struct mcbsp_internal_clk *mclk = container_of(clk,
73 struct mcbsp_internal_clk, clk);
76 for (i = 0; i < mclk->n_childs; i++)
77 clk_disable(mclk->childs[i]);
80 static struct mcbsp_internal_clk omap_mcbsp_clks[] = {
85 .enable = omap_mcbsp_clk_enable,
86 .disable = omap_mcbsp_clk_disable,
93 .enable = omap_mcbsp_clk_enable,
94 .disable = omap_mcbsp_clk_disable,
99 #define omap_mcbsp_clks_size ARRAY_SIZE(omap_mcbsp_clks)
101 #define omap_mcbsp_clks_size 0
102 static struct mcbsp_internal_clk __initdata *omap_mcbsp_clks;
103 static inline void omap_mcbsp_clk_init(struct mcbsp_internal_clk *mclk)
107 static void omap1_mcbsp_request(unsigned int id)
110 * On 1510, 1610 and 1710, McBSP1 and McBSP3
111 * are DSP public peripherals.
113 if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3) {
114 omap_dsp_request_mem();
116 * DSP external peripheral reset
117 * FIXME: This should be moved to dsp code
119 __raw_writew(__raw_readw(DSP_RSTCT2) | DPS_RSTCT2_PER_EN |
120 DSP_RSTCT2_WD_PER_EN, DSP_RSTCT2);
124 static void omap1_mcbsp_free(unsigned int id)
126 if (id == OMAP_MCBSP1 || id == OMAP_MCBSP3)
127 omap_dsp_release_mem();
130 static struct omap_mcbsp_ops omap1_mcbsp_ops = {
131 .request = omap1_mcbsp_request,
132 .free = omap1_mcbsp_free,
135 #ifdef CONFIG_ARCH_OMAP730
136 static struct omap_mcbsp_platform_data omap730_mcbsp_pdata[] = {
138 .phys_base = OMAP730_MCBSP1_BASE,
139 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
140 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
141 .rx_irq = INT_730_McBSP1RX,
142 .tx_irq = INT_730_McBSP1TX,
143 .ops = &omap1_mcbsp_ops,
146 .phys_base = OMAP730_MCBSP2_BASE,
147 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
148 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
149 .rx_irq = INT_730_McBSP2RX,
150 .tx_irq = INT_730_McBSP2TX,
151 .ops = &omap1_mcbsp_ops,
154 #define OMAP730_MCBSP_PDATA_SZ ARRAY_SIZE(omap730_mcbsp_pdata)
156 #define omap730_mcbsp_pdata NULL
157 #define OMAP730_MCBSP_PDATA_SZ 0
160 #ifdef CONFIG_ARCH_OMAP15XX
161 static struct omap_mcbsp_platform_data omap15xx_mcbsp_pdata[] = {
163 .phys_base = OMAP1510_MCBSP1_BASE,
164 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
165 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
166 .rx_irq = INT_McBSP1RX,
167 .tx_irq = INT_McBSP1TX,
168 .ops = &omap1_mcbsp_ops,
169 .clk_name = "mcbsp_clk",
172 .phys_base = OMAP1510_MCBSP2_BASE,
173 .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
174 .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
175 .rx_irq = INT_1510_SPI_RX,
176 .tx_irq = INT_1510_SPI_TX,
177 .ops = &omap1_mcbsp_ops,
180 .phys_base = OMAP1510_MCBSP3_BASE,
181 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
182 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
183 .rx_irq = INT_McBSP3RX,
184 .tx_irq = INT_McBSP3TX,
185 .ops = &omap1_mcbsp_ops,
186 .clk_name = "mcbsp_clk",
189 #define OMAP15XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap15xx_mcbsp_pdata)
191 #define omap15xx_mcbsp_pdata NULL
192 #define OMAP15XX_MCBSP_PDATA_SZ 0
195 #ifdef CONFIG_ARCH_OMAP16XX
196 static struct omap_mcbsp_platform_data omap16xx_mcbsp_pdata[] = {
198 .phys_base = OMAP1610_MCBSP1_BASE,
199 .dma_rx_sync = OMAP_DMA_MCBSP1_RX,
200 .dma_tx_sync = OMAP_DMA_MCBSP1_TX,
201 .rx_irq = INT_McBSP1RX,
202 .tx_irq = INT_McBSP1TX,
203 .ops = &omap1_mcbsp_ops,
204 .clk_name = "mcbsp_clk",
207 .phys_base = OMAP1610_MCBSP2_BASE,
208 .dma_rx_sync = OMAP_DMA_MCBSP2_RX,
209 .dma_tx_sync = OMAP_DMA_MCBSP2_TX,
210 .rx_irq = INT_1610_McBSP2_RX,
211 .tx_irq = INT_1610_McBSP2_TX,
212 .ops = &omap1_mcbsp_ops,
215 .phys_base = OMAP1610_MCBSP3_BASE,
216 .dma_rx_sync = OMAP_DMA_MCBSP3_RX,
217 .dma_tx_sync = OMAP_DMA_MCBSP3_TX,
218 .rx_irq = INT_McBSP3RX,
219 .tx_irq = INT_McBSP3TX,
220 .ops = &omap1_mcbsp_ops,
221 .clk_name = "mcbsp_clk",
224 #define OMAP16XX_MCBSP_PDATA_SZ ARRAY_SIZE(omap16xx_mcbsp_pdata)
226 #define omap16xx_mcbsp_pdata NULL
227 #define OMAP16XX_MCBSP_PDATA_SZ 0
230 int __init omap1_mcbsp_init(void)
234 for (i = 0; i < omap_mcbsp_clks_size; i++) {
235 if (cpu_is_omap15xx() || cpu_is_omap16xx()) {
236 omap_mcbsp_clk_init(&omap_mcbsp_clks[i]);
237 clk_register(&omap_mcbsp_clks[i].clk);
241 if (cpu_is_omap730())
242 omap_mcbsp_count = OMAP730_MCBSP_PDATA_SZ;
243 if (cpu_is_omap15xx())
244 omap_mcbsp_count = OMAP15XX_MCBSP_PDATA_SZ;
245 if (cpu_is_omap16xx())
246 omap_mcbsp_count = OMAP16XX_MCBSP_PDATA_SZ;
248 mcbsp_ptr = kzalloc(omap_mcbsp_count * sizeof(struct omap_mcbsp *),
253 if (cpu_is_omap730())
254 omap_mcbsp_register_board_cfg(omap730_mcbsp_pdata,
255 OMAP730_MCBSP_PDATA_SZ);
257 if (cpu_is_omap15xx())
258 omap_mcbsp_register_board_cfg(omap15xx_mcbsp_pdata,
259 OMAP15XX_MCBSP_PDATA_SZ);
261 if (cpu_is_omap16xx())
262 omap_mcbsp_register_board_cfg(omap16xx_mcbsp_pdata,
263 OMAP16XX_MCBSP_PDATA_SZ);
265 return omap_mcbsp_init();
268 arch_initcall(omap1_mcbsp_init);