blob: 4ff7a11b18385f3e062201f3fba22591e5399ad8 [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/mcbsp.c
3 *
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Samuel Ortiz <samuel.ortiz@nokia.com>
6 *
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * Multichannel mode not supported.
13 */
14
15#include <linux/module.h>
16#include <linux/init.h>
17#include <linux/device.h>
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030018#include <linux/platform_device.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010019#include <linux/wait.h>
20#include <linux/completion.h>
21#include <linux/interrupt.h>
22#include <linux/err.h>
Russell Kingf8ce2542006-01-07 16:15:52 +000023#include <linux/clk.h>
Tony Lindgren04fbf6a2007-02-12 10:50:53 -080024#include <linux/delay.h>
Eduardo Valentinfb78d802008-07-03 12:24:39 +030025#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010026
Tony Lindgrence491cf2009-10-20 09:40:47 -070027#include <plat/dma.h>
28#include <plat/mcbsp.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029
Eero Nurkkalad912fa92010-02-22 12:21:11 +000030#include "../mach-omap2/cm-regbits-34xx.h"
31
Chandra Shekharb4b58f52008-10-08 10:01:39 +030032struct omap_mcbsp **mcbsp_ptr;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080033int omap_mcbsp_count, omap_mcbsp_cache_size;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030034
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080035void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030036{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080037 if (cpu_class_is_omap1()) {
38 ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)] = (u16)val;
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080039 __raw_writew((u16)val, mcbsp->io_base + reg);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080040 } else if (cpu_is_omap2420()) {
41 ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)] = (u16)val;
42 __raw_writew((u16)val, mcbsp->io_base + reg);
43 } else {
44 ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)] = val;
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080045 __raw_writel(val, mcbsp->io_base + reg);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080046 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030047}
48
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080049int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030050{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080051 if (cpu_class_is_omap1()) {
52 return !from_cache ? __raw_readw(mcbsp->io_base + reg) :
53 ((u16 *)mcbsp->reg_cache)[reg / sizeof(u16)];
54 } else if (cpu_is_omap2420()) {
55 return !from_cache ? __raw_readw(mcbsp->io_base + reg) :
56 ((u16 *)mcbsp->reg_cache)[reg / sizeof(u32)];
57 } else {
58 return !from_cache ? __raw_readl(mcbsp->io_base + reg) :
59 ((u32 *)mcbsp->reg_cache)[reg / sizeof(u32)];
60 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030061}
62
Eero Nurkkalad912fa92010-02-22 12:21:11 +000063#ifdef CONFIG_ARCH_OMAP3
64void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
65{
66 __raw_writel(val, mcbsp->st_data->io_base_st + reg);
67}
68
69int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg)
70{
71 return __raw_readl(mcbsp->st_data->io_base_st + reg);
72}
73#endif
74
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080075#define MCBSP_READ(mcbsp, reg) \
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080076 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080077#define MCBSP_WRITE(mcbsp, reg, val) \
78 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080079#define MCBSP_READ_CACHE(mcbsp, reg) \
80 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030081
82#define omap_mcbsp_check_valid_id(id) (id < omap_mcbsp_count)
83#define id_to_mcbsp_ptr(id) mcbsp_ptr[id];
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010084
Eero Nurkkalad912fa92010-02-22 12:21:11 +000085#define MCBSP_ST_READ(mcbsp, reg) \
86 omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
87#define MCBSP_ST_WRITE(mcbsp, reg, val) \
88 omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
89
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010090static void omap_mcbsp_dump_reg(u8 id)
91{
Chandra Shekharb4b58f52008-10-08 10:01:39 +030092 struct omap_mcbsp *mcbsp = id_to_mcbsp_ptr(id);
93
94 dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id);
95 dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080096 MCBSP_READ(mcbsp, DRR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030097 dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080098 MCBSP_READ(mcbsp, DRR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030099 dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800100 MCBSP_READ(mcbsp, DXR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300101 dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800102 MCBSP_READ(mcbsp, DXR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300103 dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800104 MCBSP_READ(mcbsp, SPCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300105 dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800106 MCBSP_READ(mcbsp, SPCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300107 dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800108 MCBSP_READ(mcbsp, RCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300109 dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800110 MCBSP_READ(mcbsp, RCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300111 dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800112 MCBSP_READ(mcbsp, XCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300113 dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800114 MCBSP_READ(mcbsp, XCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300115 dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800116 MCBSP_READ(mcbsp, SRGR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300117 dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800118 MCBSP_READ(mcbsp, SRGR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300119 dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800120 MCBSP_READ(mcbsp, PCR0));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300121 dev_dbg(mcbsp->dev, "***********************\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100122}
123
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700124static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100125{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400126 struct omap_mcbsp *mcbsp_tx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700127 u16 irqst_spcr2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100128
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800129 irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700130 dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100131
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700132 if (irqst_spcr2 & XSYNC_ERR) {
133 dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n",
134 irqst_spcr2);
135 /* Writing zero to XSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000136 MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700137 } else {
138 complete(&mcbsp_tx->tx_irq_completion);
139 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300140
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100141 return IRQ_HANDLED;
142}
143
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700144static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100145{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400146 struct omap_mcbsp *mcbsp_rx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700147 u16 irqst_spcr1;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100148
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800149 irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700150 dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100151
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700152 if (irqst_spcr1 & RSYNC_ERR) {
153 dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n",
154 irqst_spcr1);
155 /* Writing zero to RSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000156 MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700157 } else {
158 complete(&mcbsp_rx->tx_irq_completion);
159 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300160
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100161 return IRQ_HANDLED;
162}
163
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100164static void omap_mcbsp_tx_dma_callback(int lch, u16 ch_status, void *data)
165{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400166 struct omap_mcbsp *mcbsp_dma_tx = data;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100167
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300168 dev_dbg(mcbsp_dma_tx->dev, "TX DMA callback : 0x%x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800169 MCBSP_READ(mcbsp_dma_tx, SPCR2));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100170
171 /* We can free the channels */
172 omap_free_dma(mcbsp_dma_tx->dma_tx_lch);
173 mcbsp_dma_tx->dma_tx_lch = -1;
174
175 complete(&mcbsp_dma_tx->tx_dma_completion);
176}
177
178static void omap_mcbsp_rx_dma_callback(int lch, u16 ch_status, void *data)
179{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400180 struct omap_mcbsp *mcbsp_dma_rx = data;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100181
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300182 dev_dbg(mcbsp_dma_rx->dev, "RX DMA callback : 0x%x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800183 MCBSP_READ(mcbsp_dma_rx, SPCR2));
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100184
185 /* We can free the channels */
186 omap_free_dma(mcbsp_dma_rx->dma_rx_lch);
187 mcbsp_dma_rx->dma_rx_lch = -1;
188
189 complete(&mcbsp_dma_rx->rx_dma_completion);
190}
191
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100192/*
193 * omap_mcbsp_config simply write a config to the
194 * appropriate McBSP.
195 * You either call this function or set the McBSP registers
196 * by yourself before calling omap_mcbsp_start().
197 */
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300198void omap_mcbsp_config(unsigned int id, const struct omap_mcbsp_reg_cfg *config)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100199{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300200 struct omap_mcbsp *mcbsp;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100201
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300202 if (!omap_mcbsp_check_valid_id(id)) {
203 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
204 return;
205 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300206 mcbsp = id_to_mcbsp_ptr(id);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300207
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300208 dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n",
209 mcbsp->id, mcbsp->phys_base);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100210
211 /* We write the given config */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800212 MCBSP_WRITE(mcbsp, SPCR2, config->spcr2);
213 MCBSP_WRITE(mcbsp, SPCR1, config->spcr1);
214 MCBSP_WRITE(mcbsp, RCR2, config->rcr2);
215 MCBSP_WRITE(mcbsp, RCR1, config->rcr1);
216 MCBSP_WRITE(mcbsp, XCR2, config->xcr2);
217 MCBSP_WRITE(mcbsp, XCR1, config->xcr1);
218 MCBSP_WRITE(mcbsp, SRGR2, config->srgr2);
219 MCBSP_WRITE(mcbsp, SRGR1, config->srgr1);
220 MCBSP_WRITE(mcbsp, MCR2, config->mcr2);
221 MCBSP_WRITE(mcbsp, MCR1, config->mcr1);
222 MCBSP_WRITE(mcbsp, PCR0, config->pcr0);
Syed Rafiuddina5b92cc2009-07-28 18:57:10 +0530223 if (cpu_is_omap2430() || cpu_is_omap34xx() || cpu_is_omap44xx()) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800224 MCBSP_WRITE(mcbsp, XCCR, config->xccr);
225 MCBSP_WRITE(mcbsp, RCCR, config->rccr);
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200226 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100227}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300228EXPORT_SYMBOL(omap_mcbsp_config);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100229
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -0800230#ifdef CONFIG_ARCH_OMAP3
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000231static void omap_st_on(struct omap_mcbsp *mcbsp)
232{
233 unsigned int w;
234
235 /*
236 * Sidetone uses McBSP ICLK - which must not idle when sidetones
237 * are enabled or sidetones start sounding ugly.
238 */
239 w = cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE);
240 w &= ~(1 << (mcbsp->id - 2));
241 cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE);
242
243 /* Enable McBSP Sidetone */
244 w = MCBSP_READ(mcbsp, SSELCR);
245 MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
246
247 w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
248 MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w & ~(ST_AUTOIDLE));
249
250 /* Enable Sidetone from Sidetone Core */
251 w = MCBSP_ST_READ(mcbsp, SSELCR);
252 MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN);
253}
254
255static void omap_st_off(struct omap_mcbsp *mcbsp)
256{
257 unsigned int w;
258
259 w = MCBSP_ST_READ(mcbsp, SSELCR);
260 MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
261
262 w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
263 MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w | ST_AUTOIDLE);
264
265 w = MCBSP_READ(mcbsp, SSELCR);
266 MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
267
268 w = cm_read_mod_reg(OMAP3430_PER_MOD, CM_AUTOIDLE);
269 w |= 1 << (mcbsp->id - 2);
270 cm_write_mod_reg(w, OMAP3430_PER_MOD, CM_AUTOIDLE);
271}
272
273static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
274{
275 u16 val, i;
276
277 val = MCBSP_ST_READ(mcbsp, SYSCONFIG);
278 MCBSP_ST_WRITE(mcbsp, SYSCONFIG, val & ~(ST_AUTOIDLE));
279
280 val = MCBSP_ST_READ(mcbsp, SSELCR);
281
282 if (val & ST_COEFFWREN)
283 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
284
285 MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN);
286
287 for (i = 0; i < 128; i++)
288 MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]);
289
290 i = 0;
291
292 val = MCBSP_ST_READ(mcbsp, SSELCR);
293 while (!(val & ST_COEFFWRDONE) && (++i < 1000))
294 val = MCBSP_ST_READ(mcbsp, SSELCR);
295
296 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
297
298 if (i == 1000)
299 dev_err(mcbsp->dev, "McBSP FIR load error!\n");
300}
301
302static void omap_st_chgain(struct omap_mcbsp *mcbsp)
303{
304 u16 w;
305 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
306
307 w = MCBSP_ST_READ(mcbsp, SYSCONFIG);
308 MCBSP_ST_WRITE(mcbsp, SYSCONFIG, w & ~(ST_AUTOIDLE));
309
310 w = MCBSP_ST_READ(mcbsp, SSELCR);
311
312 MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \
313 ST_CH1GAIN(st_data->ch1gain));
314}
315
316int omap_st_set_chgain(unsigned int id, int channel, s16 chgain)
317{
318 struct omap_mcbsp *mcbsp;
319 struct omap_mcbsp_st_data *st_data;
320 int ret = 0;
321
322 if (!omap_mcbsp_check_valid_id(id)) {
323 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
324 return -ENODEV;
325 }
326
327 mcbsp = id_to_mcbsp_ptr(id);
328 st_data = mcbsp->st_data;
329
330 if (!st_data)
331 return -ENOENT;
332
333 spin_lock_irq(&mcbsp->lock);
334 if (channel == 0)
335 st_data->ch0gain = chgain;
336 else if (channel == 1)
337 st_data->ch1gain = chgain;
338 else
339 ret = -EINVAL;
340
341 if (st_data->enabled)
342 omap_st_chgain(mcbsp);
343 spin_unlock_irq(&mcbsp->lock);
344
345 return ret;
346}
347EXPORT_SYMBOL(omap_st_set_chgain);
348
349int omap_st_get_chgain(unsigned int id, int channel, s16 *chgain)
350{
351 struct omap_mcbsp *mcbsp;
352 struct omap_mcbsp_st_data *st_data;
353 int ret = 0;
354
355 if (!omap_mcbsp_check_valid_id(id)) {
356 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
357 return -ENODEV;
358 }
359
360 mcbsp = id_to_mcbsp_ptr(id);
361 st_data = mcbsp->st_data;
362
363 if (!st_data)
364 return -ENOENT;
365
366 spin_lock_irq(&mcbsp->lock);
367 if (channel == 0)
368 *chgain = st_data->ch0gain;
369 else if (channel == 1)
370 *chgain = st_data->ch1gain;
371 else
372 ret = -EINVAL;
373 spin_unlock_irq(&mcbsp->lock);
374
375 return ret;
376}
377EXPORT_SYMBOL(omap_st_get_chgain);
378
379static int omap_st_start(struct omap_mcbsp *mcbsp)
380{
381 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
382
383 if (st_data && st_data->enabled && !st_data->running) {
384 omap_st_fir_write(mcbsp, st_data->taps);
385 omap_st_chgain(mcbsp);
386
387 if (!mcbsp->free) {
388 omap_st_on(mcbsp);
389 st_data->running = 1;
390 }
391 }
392
393 return 0;
394}
395
396int omap_st_enable(unsigned int id)
397{
398 struct omap_mcbsp *mcbsp;
399 struct omap_mcbsp_st_data *st_data;
400
401 if (!omap_mcbsp_check_valid_id(id)) {
402 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
403 return -ENODEV;
404 }
405
406 mcbsp = id_to_mcbsp_ptr(id);
407 st_data = mcbsp->st_data;
408
409 if (!st_data)
410 return -ENODEV;
411
412 spin_lock_irq(&mcbsp->lock);
413 st_data->enabled = 1;
414 omap_st_start(mcbsp);
415 spin_unlock_irq(&mcbsp->lock);
416
417 return 0;
418}
419EXPORT_SYMBOL(omap_st_enable);
420
421static int omap_st_stop(struct omap_mcbsp *mcbsp)
422{
423 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
424
425 if (st_data && st_data->running) {
426 if (!mcbsp->free) {
427 omap_st_off(mcbsp);
428 st_data->running = 0;
429 }
430 }
431
432 return 0;
433}
434
435int omap_st_disable(unsigned int id)
436{
437 struct omap_mcbsp *mcbsp;
438 struct omap_mcbsp_st_data *st_data;
439 int ret = 0;
440
441 if (!omap_mcbsp_check_valid_id(id)) {
442 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
443 return -ENODEV;
444 }
445
446 mcbsp = id_to_mcbsp_ptr(id);
447 st_data = mcbsp->st_data;
448
449 if (!st_data)
450 return -ENODEV;
451
452 spin_lock_irq(&mcbsp->lock);
453 omap_st_stop(mcbsp);
454 st_data->enabled = 0;
455 spin_unlock_irq(&mcbsp->lock);
456
457 return ret;
458}
459EXPORT_SYMBOL(omap_st_disable);
460
461int omap_st_is_enabled(unsigned int id)
462{
463 struct omap_mcbsp *mcbsp;
464 struct omap_mcbsp_st_data *st_data;
465
466 if (!omap_mcbsp_check_valid_id(id)) {
467 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
468 return -ENODEV;
469 }
470
471 mcbsp = id_to_mcbsp_ptr(id);
472 st_data = mcbsp->st_data;
473
474 if (!st_data)
475 return -ENODEV;
476
477
478 return st_data->enabled;
479}
480EXPORT_SYMBOL(omap_st_is_enabled);
481
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300482/*
483 * omap_mcbsp_set_tx_threshold configures how to deal
484 * with transmit threshold. the threshold value and handler can be
485 * configure in here.
486 */
487void omap_mcbsp_set_tx_threshold(unsigned int id, u16 threshold)
488{
489 struct omap_mcbsp *mcbsp;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300490
491 if (!cpu_is_omap34xx())
492 return;
493
494 if (!omap_mcbsp_check_valid_id(id)) {
495 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
496 return;
497 }
498 mcbsp = id_to_mcbsp_ptr(id);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300499
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800500 MCBSP_WRITE(mcbsp, THRSH2, threshold);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300501}
502EXPORT_SYMBOL(omap_mcbsp_set_tx_threshold);
503
504/*
505 * omap_mcbsp_set_rx_threshold configures how to deal
506 * with receive threshold. the threshold value and handler can be
507 * configure in here.
508 */
509void omap_mcbsp_set_rx_threshold(unsigned int id, u16 threshold)
510{
511 struct omap_mcbsp *mcbsp;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300512
513 if (!cpu_is_omap34xx())
514 return;
515
516 if (!omap_mcbsp_check_valid_id(id)) {
517 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
518 return;
519 }
520 mcbsp = id_to_mcbsp_ptr(id);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300521
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800522 MCBSP_WRITE(mcbsp, THRSH1, threshold);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300523}
524EXPORT_SYMBOL(omap_mcbsp_set_rx_threshold);
Eduardo Valentina1a56f52009-08-20 16:18:11 +0300525
526/*
527 * omap_mcbsp_get_max_tx_thres just return the current configured
528 * maximum threshold for transmission
529 */
530u16 omap_mcbsp_get_max_tx_threshold(unsigned int id)
531{
532 struct omap_mcbsp *mcbsp;
533
534 if (!omap_mcbsp_check_valid_id(id)) {
535 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
536 return -ENODEV;
537 }
538 mcbsp = id_to_mcbsp_ptr(id);
539
540 return mcbsp->max_tx_thres;
541}
542EXPORT_SYMBOL(omap_mcbsp_get_max_tx_threshold);
543
544/*
545 * omap_mcbsp_get_max_rx_thres just return the current configured
546 * maximum threshold for reception
547 */
548u16 omap_mcbsp_get_max_rx_threshold(unsigned int id)
549{
550 struct omap_mcbsp *mcbsp;
551
552 if (!omap_mcbsp_check_valid_id(id)) {
553 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
554 return -ENODEV;
555 }
556 mcbsp = id_to_mcbsp_ptr(id);
557
558 return mcbsp->max_rx_thres;
559}
560EXPORT_SYMBOL(omap_mcbsp_get_max_rx_threshold);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300561
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200562#define MCBSP2_FIFO_SIZE 0x500 /* 1024 + 256 locations */
563#define MCBSP1345_FIFO_SIZE 0x80 /* 128 locations */
564/*
565 * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
566 */
567u16 omap_mcbsp_get_tx_delay(unsigned int id)
568{
569 struct omap_mcbsp *mcbsp;
570 u16 buffstat;
571
572 if (!omap_mcbsp_check_valid_id(id)) {
573 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
574 return -ENODEV;
575 }
576 mcbsp = id_to_mcbsp_ptr(id);
577
578 /* Returns the number of free locations in the buffer */
579 buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
580
581 /* Number of slots are different in McBSP ports */
582 if (mcbsp->id == 2)
583 return MCBSP2_FIFO_SIZE - buffstat;
584 else
585 return MCBSP1345_FIFO_SIZE - buffstat;
586}
587EXPORT_SYMBOL(omap_mcbsp_get_tx_delay);
588
589/*
590 * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
591 * to reach the threshold value (when the DMA will be triggered to read it)
592 */
593u16 omap_mcbsp_get_rx_delay(unsigned int id)
594{
595 struct omap_mcbsp *mcbsp;
596 u16 buffstat, threshold;
597
598 if (!omap_mcbsp_check_valid_id(id)) {
599 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
600 return -ENODEV;
601 }
602 mcbsp = id_to_mcbsp_ptr(id);
603
604 /* Returns the number of used locations in the buffer */
605 buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
606 /* RX threshold */
607 threshold = MCBSP_READ(mcbsp, THRSH1);
608
609 /* Return the number of location till we reach the threshold limit */
610 if (threshold <= buffstat)
611 return 0;
612 else
613 return threshold - buffstat;
614}
615EXPORT_SYMBOL(omap_mcbsp_get_rx_delay);
616
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300617/*
618 * omap_mcbsp_get_dma_op_mode just return the current configured
619 * operating mode for the mcbsp channel
620 */
621int omap_mcbsp_get_dma_op_mode(unsigned int id)
622{
623 struct omap_mcbsp *mcbsp;
624 int dma_op_mode;
625
626 if (!omap_mcbsp_check_valid_id(id)) {
627 printk(KERN_ERR "%s: Invalid id (%u)\n", __func__, id + 1);
628 return -ENODEV;
629 }
630 mcbsp = id_to_mcbsp_ptr(id);
631
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300632 dma_op_mode = mcbsp->dma_op_mode;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300633
634 return dma_op_mode;
635}
636EXPORT_SYMBOL(omap_mcbsp_get_dma_op_mode);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300637
638static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp)
639{
640 /*
641 * Enable wakup behavior, smart idle and all wakeups
642 * REVISIT: some wakeups may be unnecessary
643 */
644 if (cpu_is_omap34xx()) {
645 u16 syscon;
646
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800647 syscon = MCBSP_READ(mcbsp, SYSCON);
Eero Nurkkala2ba93f82009-08-20 16:18:17 +0300648 syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
Eduardo Valentind99a7452009-08-20 16:18:18 +0300649
Eero Nurkkalafa3935b2009-08-20 16:18:19 +0300650 if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) {
651 syscon |= (ENAWAKEUP | SIDLEMODE(0x02) |
652 CLOCKACTIVITY(0x02));
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800653 MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
Eero Nurkkalafa3935b2009-08-20 16:18:19 +0300654 } else {
Eduardo Valentind99a7452009-08-20 16:18:18 +0300655 syscon |= SIDLEMODE(0x01);
Eero Nurkkalafa3935b2009-08-20 16:18:19 +0300656 }
Eduardo Valentind99a7452009-08-20 16:18:18 +0300657
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800658 MCBSP_WRITE(mcbsp, SYSCON, syscon);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300659 }
660}
661
662static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp)
663{
664 /*
665 * Disable wakup behavior, smart idle and all wakeups
666 */
667 if (cpu_is_omap34xx()) {
668 u16 syscon;
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300669
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800670 syscon = MCBSP_READ(mcbsp, SYSCON);
Eero Nurkkala2ba93f82009-08-20 16:18:17 +0300671 syscon &= ~(ENAWAKEUP | SIDLEMODE(0x03) | CLOCKACTIVITY(0x03));
Eero Nurkkala72cc6d72009-08-20 16:18:20 +0300672 /*
673 * HW bug workaround - If no_idle mode is taken, we need to
674 * go to smart_idle before going to always_idle, or the
675 * device will not hit retention anymore.
676 */
677 syscon |= SIDLEMODE(0x02);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800678 MCBSP_WRITE(mcbsp, SYSCON, syscon);
Eero Nurkkala72cc6d72009-08-20 16:18:20 +0300679
680 syscon &= ~(SIDLEMODE(0x03));
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800681 MCBSP_WRITE(mcbsp, SYSCON, syscon);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300682
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800683 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300684 }
685}
686#else
687static inline void omap34xx_mcbsp_request(struct omap_mcbsp *mcbsp) {}
688static inline void omap34xx_mcbsp_free(struct omap_mcbsp *mcbsp) {}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000689static inline void omap_st_start(struct omap_mcbsp *mcbsp) {}
690static inline void omap_st_stop(struct omap_mcbsp *mcbsp) {}
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300691#endif
692
Tony Lindgren120db2c2006-04-02 17:46:27 +0100693/*
694 * We can choose between IRQ based or polled IO.
695 * This needs to be called before omap_mcbsp_request().
696 */
697int omap_mcbsp_set_io_type(unsigned int id, omap_mcbsp_io_type_t io_type)
698{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300699 struct omap_mcbsp *mcbsp;
700
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300701 if (!omap_mcbsp_check_valid_id(id)) {
702 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
703 return -ENODEV;
704 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300705 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100706
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300707 spin_lock(&mcbsp->lock);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100708
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300709 if (!mcbsp->free) {
710 dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
711 mcbsp->id);
712 spin_unlock(&mcbsp->lock);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100713 return -EINVAL;
714 }
715
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300716 mcbsp->io_type = io_type;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100717
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300718 spin_unlock(&mcbsp->lock);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100719
720 return 0;
721}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300722EXPORT_SYMBOL(omap_mcbsp_set_io_type);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100723
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100724int omap_mcbsp_request(unsigned int id)
725{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300726 struct omap_mcbsp *mcbsp;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800727 void *reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100728 int err;
729
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300730 if (!omap_mcbsp_check_valid_id(id)) {
731 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
732 return -ENODEV;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100733 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300734 mcbsp = id_to_mcbsp_ptr(id);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300735
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800736 reg_cache = kzalloc(omap_mcbsp_cache_size, GFP_KERNEL);
737 if (!reg_cache) {
738 return -ENOMEM;
739 }
740
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300741 spin_lock(&mcbsp->lock);
742 if (!mcbsp->free) {
743 dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
744 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800745 err = -EBUSY;
746 goto err_kfree;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100747 }
748
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300749 mcbsp->free = 0;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800750 mcbsp->reg_cache = reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300751 spin_unlock(&mcbsp->lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100752
Russell Kingb820ce42009-01-23 10:26:46 +0000753 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request)
754 mcbsp->pdata->ops->request(id);
755
756 clk_enable(mcbsp->iclk);
757 clk_enable(mcbsp->fclk);
758
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300759 /* Do procedure specific to omap34xx arch, if applicable */
760 omap34xx_mcbsp_request(mcbsp);
761
Jarkko Nikula5a070552008-10-08 10:01:41 +0300762 /*
763 * Make sure that transmitter, receiver and sample-rate generator are
764 * not running before activating IRQs.
765 */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800766 MCBSP_WRITE(mcbsp, SPCR1, 0);
767 MCBSP_WRITE(mcbsp, SPCR2, 0);
Jarkko Nikula5a070552008-10-08 10:01:41 +0300768
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300769 if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) {
Tony Lindgren120db2c2006-04-02 17:46:27 +0100770 /* We need to get IRQs here */
Jarkko Nikula5a070552008-10-08 10:01:41 +0300771 init_completion(&mcbsp->tx_irq_completion);
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300772 err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler,
773 0, "McBSP", (void *)mcbsp);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100774 if (err != 0) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300775 dev_err(mcbsp->dev, "Unable to request TX IRQ %d "
776 "for McBSP%d\n", mcbsp->tx_irq,
777 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800778 goto err_clk_disable;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100779 }
780
Jarkko Nikula5a070552008-10-08 10:01:41 +0300781 init_completion(&mcbsp->rx_irq_completion);
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300782 err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler,
783 0, "McBSP", (void *)mcbsp);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100784 if (err != 0) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300785 dev_err(mcbsp->dev, "Unable to request RX IRQ %d "
786 "for McBSP%d\n", mcbsp->rx_irq,
787 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800788 goto err_free_irq;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100789 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100790 }
791
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100792 return 0;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800793err_free_irq:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800794 free_irq(mcbsp->tx_irq, (void *)mcbsp);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800795err_clk_disable:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800796 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800797 mcbsp->pdata->ops->free(id);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800798
799 /* Do procedure specific to omap34xx arch, if applicable */
800 omap34xx_mcbsp_free(mcbsp);
801
802 clk_disable(mcbsp->fclk);
803 clk_disable(mcbsp->iclk);
804
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800805 spin_lock(&mcbsp->lock);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800806 mcbsp->free = 1;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800807 mcbsp->reg_cache = NULL;
808err_kfree:
809 spin_unlock(&mcbsp->lock);
810 kfree(reg_cache);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800811
812 return err;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100813}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300814EXPORT_SYMBOL(omap_mcbsp_request);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100815
816void omap_mcbsp_free(unsigned int id)
817{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300818 struct omap_mcbsp *mcbsp;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800819 void *reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300820
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300821 if (!omap_mcbsp_check_valid_id(id)) {
822 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100823 return;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100824 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300825 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren120db2c2006-04-02 17:46:27 +0100826
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300827 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
828 mcbsp->pdata->ops->free(id);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300829
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300830 /* Do procedure specific to omap34xx arch, if applicable */
831 omap34xx_mcbsp_free(mcbsp);
832
Russell Kingb820ce42009-01-23 10:26:46 +0000833 clk_disable(mcbsp->fclk);
834 clk_disable(mcbsp->iclk);
835
836 if (mcbsp->io_type == OMAP_MCBSP_IRQ_IO) {
837 /* Free IRQs */
838 free_irq(mcbsp->rx_irq, (void *)mcbsp);
839 free_irq(mcbsp->tx_irq, (void *)mcbsp);
840 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100841
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800842 reg_cache = mcbsp->reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100843
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800844 spin_lock(&mcbsp->lock);
845 if (mcbsp->free)
846 dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
847 else
848 mcbsp->free = 1;
849 mcbsp->reg_cache = NULL;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300850 spin_unlock(&mcbsp->lock);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800851
852 if (reg_cache)
853 kfree(reg_cache);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100854}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300855EXPORT_SYMBOL(omap_mcbsp_free);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100856
857/*
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300858 * Here we start the McBSP, by enabling transmitter, receiver or both.
859 * If no transmitter or receiver is active prior calling, then sample-rate
860 * generator and frame sync are started.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100861 */
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300862void omap_mcbsp_start(unsigned int id, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100863{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300864 struct omap_mcbsp *mcbsp;
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300865 int idle;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100866 u16 w;
867
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300868 if (!omap_mcbsp_check_valid_id(id)) {
869 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100870 return;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300871 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300872 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100873
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000874 if (cpu_is_omap34xx())
875 omap_st_start(mcbsp);
876
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800877 mcbsp->rx_word_length = (MCBSP_READ_CACHE(mcbsp, RCR1) >> 5) & 0x7;
878 mcbsp->tx_word_length = (MCBSP_READ_CACHE(mcbsp, XCR1) >> 5) & 0x7;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100879
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800880 idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
881 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300882
883 if (idle) {
884 /* Start the sample generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800885 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800886 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300887 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100888
889 /* Enable transmitter and receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300890 tx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800891 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800892 MCBSP_WRITE(mcbsp, SPCR2, w | tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100893
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300894 rx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800895 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800896 MCBSP_WRITE(mcbsp, SPCR1, w | rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100897
Eduardo Valentin44a63112009-08-20 16:18:09 +0300898 /*
899 * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
900 * REVISIT: 100us may give enough time for two CLKSRG, however
901 * due to some unknown PM related, clock gating etc. reason it
902 * is now at 500us.
903 */
904 udelay(500);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100905
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300906 if (idle) {
907 /* Start frame sync */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800908 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800909 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300910 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100911
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300912 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
913 /* Release the transmitter and receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800914 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300915 w &= ~(tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800916 MCBSP_WRITE(mcbsp, XCCR, w);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800917 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300918 w &= ~(rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800919 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300920 }
921
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100922 /* Dump McBSP Regs */
923 omap_mcbsp_dump_reg(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100924}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300925EXPORT_SYMBOL(omap_mcbsp_start);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100926
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300927void omap_mcbsp_stop(unsigned int id, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100928{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300929 struct omap_mcbsp *mcbsp;
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300930 int idle;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100931 u16 w;
932
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300933 if (!omap_mcbsp_check_valid_id(id)) {
934 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100935 return;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300936 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100937
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300938 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100939
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300940 /* Reset transmitter */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300941 tx &= 1;
942 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800943 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300944 w |= (tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800945 MCBSP_WRITE(mcbsp, XCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300946 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800947 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800948 MCBSP_WRITE(mcbsp, SPCR2, w & ~tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100949
950 /* Reset receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300951 rx &= 1;
952 if (cpu_is_omap2430() || cpu_is_omap34xx()) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800953 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulaa93d4ed2009-10-14 09:56:35 -0700954 w |= (rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800955 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300956 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800957 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800958 MCBSP_WRITE(mcbsp, SPCR1, w & ~rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100959
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800960 idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
961 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300962
963 if (idle) {
964 /* Reset the sample rate generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800965 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800966 MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300967 }
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000968
969 if (cpu_is_omap34xx())
970 omap_st_stop(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100971}
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300972EXPORT_SYMBOL(omap_mcbsp_stop);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100973
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100974/* polled mcbsp i/o operations */
975int omap_mcbsp_pollwrite(unsigned int id, u16 buf)
976{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300977 struct omap_mcbsp *mcbsp;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300978
979 if (!omap_mcbsp_check_valid_id(id)) {
980 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
981 return -ENODEV;
982 }
983
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300984 mcbsp = id_to_mcbsp_ptr(id);
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300985
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800986 MCBSP_WRITE(mcbsp, DXR1, buf);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100987 /* if frame sync error - clear the error */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800988 if (MCBSP_READ(mcbsp, SPCR2) & XSYNC_ERR) {
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100989 /* clear error */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000990 MCBSP_WRITE(mcbsp, SPCR2, MCBSP_READ_CACHE(mcbsp, SPCR2));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100991 /* resend */
992 return -1;
993 } else {
994 /* wait for transmit confirmation */
995 int attemps = 0;
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800996 while (!(MCBSP_READ(mcbsp, SPCR2) & XRDY)) {
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +0100997 if (attemps++ > 1000) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800998 MCBSP_WRITE(mcbsp, SPCR2,
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800999 MCBSP_READ_CACHE(mcbsp, SPCR2) &
1000 (~XRST));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001001 udelay(10);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001002 MCBSP_WRITE(mcbsp, SPCR2,
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001003 MCBSP_READ_CACHE(mcbsp, SPCR2) |
1004 (XRST));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001005 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001006 dev_err(mcbsp->dev, "Could not write to"
1007 " McBSP%d Register\n", mcbsp->id);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001008 return -2;
1009 }
1010 }
1011 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001012
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001013 return 0;
1014}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001015EXPORT_SYMBOL(omap_mcbsp_pollwrite);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001016
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001017int omap_mcbsp_pollread(unsigned int id, u16 *buf)
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001018{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001019 struct omap_mcbsp *mcbsp;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001020
1021 if (!omap_mcbsp_check_valid_id(id)) {
1022 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1023 return -ENODEV;
1024 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001025 mcbsp = id_to_mcbsp_ptr(id);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001026
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001027 /* if frame sync error - clear the error */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001028 if (MCBSP_READ(mcbsp, SPCR1) & RSYNC_ERR) {
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001029 /* clear error */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +00001030 MCBSP_WRITE(mcbsp, SPCR1, MCBSP_READ_CACHE(mcbsp, SPCR1));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001031 /* resend */
1032 return -1;
1033 } else {
1034 /* wait for recieve confirmation */
1035 int attemps = 0;
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001036 while (!(MCBSP_READ(mcbsp, SPCR1) & RRDY)) {
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001037 if (attemps++ > 1000) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001038 MCBSP_WRITE(mcbsp, SPCR1,
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001039 MCBSP_READ_CACHE(mcbsp, SPCR1) &
1040 (~RRST));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001041 udelay(10);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001042 MCBSP_WRITE(mcbsp, SPCR1,
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001043 MCBSP_READ_CACHE(mcbsp, SPCR1) |
1044 (RRST));
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001045 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001046 dev_err(mcbsp->dev, "Could not read from"
1047 " McBSP%d Register\n", mcbsp->id);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001048 return -2;
1049 }
1050 }
1051 }
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001052 *buf = MCBSP_READ(mcbsp, DRR1);
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001053
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001054 return 0;
1055}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001056EXPORT_SYMBOL(omap_mcbsp_pollread);
Tony Lindgrenbb13b5f2005-07-10 19:58:18 +01001057
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001058/*
1059 * IRQ based word transmission.
1060 */
1061void omap_mcbsp_xmit_word(unsigned int id, u32 word)
1062{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001063 struct omap_mcbsp *mcbsp;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001064 omap_mcbsp_word_length word_length;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001065
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001066 if (!omap_mcbsp_check_valid_id(id)) {
1067 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001068 return;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001069 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001070
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001071 mcbsp = id_to_mcbsp_ptr(id);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001072 word_length = mcbsp->tx_word_length;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001073
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001074 wait_for_completion(&mcbsp->tx_irq_completion);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001075
1076 if (word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001077 MCBSP_WRITE(mcbsp, DXR2, word >> 16);
1078 MCBSP_WRITE(mcbsp, DXR1, word & 0xffff);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001079}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001080EXPORT_SYMBOL(omap_mcbsp_xmit_word);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001081
1082u32 omap_mcbsp_recv_word(unsigned int id)
1083{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001084 struct omap_mcbsp *mcbsp;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001085 u16 word_lsb, word_msb = 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001086 omap_mcbsp_word_length word_length;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001087
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001088 if (!omap_mcbsp_check_valid_id(id)) {
1089 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1090 return -ENODEV;
1091 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001092 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001093
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001094 word_length = mcbsp->rx_word_length;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001095
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001096 wait_for_completion(&mcbsp->rx_irq_completion);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001097
1098 if (word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001099 word_msb = MCBSP_READ(mcbsp, DRR2);
1100 word_lsb = MCBSP_READ(mcbsp, DRR1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001101
1102 return (word_lsb | (word_msb << 16));
1103}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001104EXPORT_SYMBOL(omap_mcbsp_recv_word);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001105
Tony Lindgren120db2c2006-04-02 17:46:27 +01001106int omap_mcbsp_spi_master_xmit_word_poll(unsigned int id, u32 word)
1107{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001108 struct omap_mcbsp *mcbsp;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001109 omap_mcbsp_word_length tx_word_length;
1110 omap_mcbsp_word_length rx_word_length;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001111 u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0;
1112
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001113 if (!omap_mcbsp_check_valid_id(id)) {
1114 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1115 return -ENODEV;
1116 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001117 mcbsp = id_to_mcbsp_ptr(id);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001118 tx_word_length = mcbsp->tx_word_length;
1119 rx_word_length = mcbsp->rx_word_length;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001120
Tony Lindgren120db2c2006-04-02 17:46:27 +01001121 if (tx_word_length != rx_word_length)
1122 return -EINVAL;
1123
1124 /* First we wait for the transmitter to be ready */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001125 spcr2 = MCBSP_READ(mcbsp, SPCR2);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001126 while (!(spcr2 & XRDY)) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001127 spcr2 = MCBSP_READ(mcbsp, SPCR2);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001128 if (attempts++ > 1000) {
1129 /* We must reset the transmitter */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001130 MCBSP_WRITE(mcbsp, SPCR2,
1131 MCBSP_READ_CACHE(mcbsp, SPCR2) & (~XRST));
Tony Lindgren120db2c2006-04-02 17:46:27 +01001132 udelay(10);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001133 MCBSP_WRITE(mcbsp, SPCR2,
1134 MCBSP_READ_CACHE(mcbsp, SPCR2) | XRST);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001135 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001136 dev_err(mcbsp->dev, "McBSP%d transmitter not "
1137 "ready\n", mcbsp->id);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001138 return -EAGAIN;
1139 }
1140 }
1141
1142 /* Now we can push the data */
1143 if (tx_word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001144 MCBSP_WRITE(mcbsp, DXR2, word >> 16);
1145 MCBSP_WRITE(mcbsp, DXR1, word & 0xffff);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001146
1147 /* We wait for the receiver to be ready */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001148 spcr1 = MCBSP_READ(mcbsp, SPCR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001149 while (!(spcr1 & RRDY)) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001150 spcr1 = MCBSP_READ(mcbsp, SPCR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001151 if (attempts++ > 1000) {
1152 /* We must reset the receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001153 MCBSP_WRITE(mcbsp, SPCR1,
1154 MCBSP_READ_CACHE(mcbsp, SPCR1) & (~RRST));
Tony Lindgren120db2c2006-04-02 17:46:27 +01001155 udelay(10);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001156 MCBSP_WRITE(mcbsp, SPCR1,
1157 MCBSP_READ_CACHE(mcbsp, SPCR1) | RRST);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001158 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001159 dev_err(mcbsp->dev, "McBSP%d receiver not "
1160 "ready\n", mcbsp->id);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001161 return -EAGAIN;
1162 }
1163 }
1164
1165 /* Receiver is ready, let's read the dummy data */
1166 if (rx_word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001167 word_msb = MCBSP_READ(mcbsp, DRR2);
1168 word_lsb = MCBSP_READ(mcbsp, DRR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001169
1170 return 0;
1171}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001172EXPORT_SYMBOL(omap_mcbsp_spi_master_xmit_word_poll);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001173
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001174int omap_mcbsp_spi_master_recv_word_poll(unsigned int id, u32 *word)
Tony Lindgren120db2c2006-04-02 17:46:27 +01001175{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001176 struct omap_mcbsp *mcbsp;
Russell Kingd592dd12008-09-04 14:25:42 +01001177 u32 clock_word = 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001178 omap_mcbsp_word_length tx_word_length;
1179 omap_mcbsp_word_length rx_word_length;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001180 u16 spcr2, spcr1, attempts = 0, word_lsb, word_msb = 0;
1181
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001182 if (!omap_mcbsp_check_valid_id(id)) {
1183 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1184 return -ENODEV;
1185 }
1186
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001187 mcbsp = id_to_mcbsp_ptr(id);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001188
1189 tx_word_length = mcbsp->tx_word_length;
1190 rx_word_length = mcbsp->rx_word_length;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001191
Tony Lindgren120db2c2006-04-02 17:46:27 +01001192 if (tx_word_length != rx_word_length)
1193 return -EINVAL;
1194
1195 /* First we wait for the transmitter to be ready */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001196 spcr2 = MCBSP_READ(mcbsp, SPCR2);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001197 while (!(spcr2 & XRDY)) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001198 spcr2 = MCBSP_READ(mcbsp, SPCR2);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001199 if (attempts++ > 1000) {
1200 /* We must reset the transmitter */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001201 MCBSP_WRITE(mcbsp, SPCR2,
1202 MCBSP_READ_CACHE(mcbsp, SPCR2) & (~XRST));
Tony Lindgren120db2c2006-04-02 17:46:27 +01001203 udelay(10);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001204 MCBSP_WRITE(mcbsp, SPCR2,
1205 MCBSP_READ_CACHE(mcbsp, SPCR2) | XRST);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001206 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001207 dev_err(mcbsp->dev, "McBSP%d transmitter not "
1208 "ready\n", mcbsp->id);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001209 return -EAGAIN;
1210 }
1211 }
1212
1213 /* We first need to enable the bus clock */
1214 if (tx_word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001215 MCBSP_WRITE(mcbsp, DXR2, clock_word >> 16);
1216 MCBSP_WRITE(mcbsp, DXR1, clock_word & 0xffff);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001217
1218 /* We wait for the receiver to be ready */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001219 spcr1 = MCBSP_READ(mcbsp, SPCR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001220 while (!(spcr1 & RRDY)) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001221 spcr1 = MCBSP_READ(mcbsp, SPCR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001222 if (attempts++ > 1000) {
1223 /* We must reset the receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001224 MCBSP_WRITE(mcbsp, SPCR1,
1225 MCBSP_READ_CACHE(mcbsp, SPCR1) & (~RRST));
Tony Lindgren120db2c2006-04-02 17:46:27 +01001226 udelay(10);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -08001227 MCBSP_WRITE(mcbsp, SPCR1,
1228 MCBSP_READ_CACHE(mcbsp, SPCR1) | RRST);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001229 udelay(10);
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001230 dev_err(mcbsp->dev, "McBSP%d receiver not "
1231 "ready\n", mcbsp->id);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001232 return -EAGAIN;
1233 }
1234 }
1235
1236 /* Receiver is ready, there is something for us */
1237 if (rx_word_length > OMAP_MCBSP_WORD_16)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -08001238 word_msb = MCBSP_READ(mcbsp, DRR2);
1239 word_lsb = MCBSP_READ(mcbsp, DRR1);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001240
1241 word[0] = (word_lsb | (word_msb << 16));
1242
1243 return 0;
1244}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001245EXPORT_SYMBOL(omap_mcbsp_spi_master_recv_word_poll);
Tony Lindgren120db2c2006-04-02 17:46:27 +01001246
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001247/*
1248 * Simple DMA based buffer rx/tx routines.
1249 * Nothing fancy, just a single buffer tx/rx through DMA.
1250 * The DMA resources are released once the transfer is done.
1251 * For anything fancier, you should use your own customized DMA
1252 * routines and callbacks.
1253 */
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001254int omap_mcbsp_xmit_buffer(unsigned int id, dma_addr_t buffer,
1255 unsigned int length)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001256{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001257 struct omap_mcbsp *mcbsp;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001258 int dma_tx_ch;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001259 int src_port = 0;
1260 int dest_port = 0;
1261 int sync_dev = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001262
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001263 if (!omap_mcbsp_check_valid_id(id)) {
1264 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1265 return -ENODEV;
1266 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001267 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001268
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001269 if (omap_request_dma(mcbsp->dma_tx_sync, "McBSP TX",
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001270 omap_mcbsp_tx_dma_callback,
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001271 mcbsp,
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001272 &dma_tx_ch)) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001273 dev_err(mcbsp->dev, " Unable to request DMA channel for "
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001274 "McBSP%d TX. Trying IRQ based TX\n",
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001275 mcbsp->id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001276 return -EAGAIN;
1277 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001278 mcbsp->dma_tx_lch = dma_tx_ch;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001279
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001280 dev_err(mcbsp->dev, "McBSP%d TX DMA on channel %d\n", mcbsp->id,
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001281 dma_tx_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001282
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001283 init_completion(&mcbsp->tx_dma_completion);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001284
Tony Lindgren120db2c2006-04-02 17:46:27 +01001285 if (cpu_class_is_omap1()) {
1286 src_port = OMAP_DMA_PORT_TIPB;
1287 dest_port = OMAP_DMA_PORT_EMIFF;
1288 }
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001289 if (cpu_class_is_omap2())
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001290 sync_dev = mcbsp->dma_tx_sync;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001291
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001292 omap_set_dma_transfer_params(mcbsp->dma_tx_lch,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001293 OMAP_DMA_DATA_TYPE_S16,
1294 length >> 1, 1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001295 OMAP_DMA_SYNC_ELEMENT,
Tony Lindgren120db2c2006-04-02 17:46:27 +01001296 sync_dev, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001297
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001298 omap_set_dma_dest_params(mcbsp->dma_tx_lch,
Tony Lindgren120db2c2006-04-02 17:46:27 +01001299 src_port,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001300 OMAP_DMA_AMODE_CONSTANT,
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001301 mcbsp->phys_base + OMAP_MCBSP_REG_DXR1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001302 0, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001303
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001304 omap_set_dma_src_params(mcbsp->dma_tx_lch,
Tony Lindgren120db2c2006-04-02 17:46:27 +01001305 dest_port,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001306 OMAP_DMA_AMODE_POST_INC,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001307 buffer,
1308 0, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001309
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001310 omap_start_dma(mcbsp->dma_tx_lch);
1311 wait_for_completion(&mcbsp->tx_dma_completion);
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001312
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001313 return 0;
1314}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001315EXPORT_SYMBOL(omap_mcbsp_xmit_buffer);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001316
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001317int omap_mcbsp_recv_buffer(unsigned int id, dma_addr_t buffer,
1318 unsigned int length)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001319{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001320 struct omap_mcbsp *mcbsp;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001321 int dma_rx_ch;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001322 int src_port = 0;
1323 int dest_port = 0;
1324 int sync_dev = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001325
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001326 if (!omap_mcbsp_check_valid_id(id)) {
1327 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
1328 return -ENODEV;
1329 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001330 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001331
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001332 if (omap_request_dma(mcbsp->dma_rx_sync, "McBSP RX",
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001333 omap_mcbsp_rx_dma_callback,
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001334 mcbsp,
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001335 &dma_rx_ch)) {
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001336 dev_err(mcbsp->dev, "Unable to request DMA channel for "
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001337 "McBSP%d RX. Trying IRQ based RX\n",
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001338 mcbsp->id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001339 return -EAGAIN;
1340 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001341 mcbsp->dma_rx_lch = dma_rx_ch;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001342
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001343 dev_err(mcbsp->dev, "McBSP%d RX DMA on channel %d\n", mcbsp->id,
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001344 dma_rx_ch);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001345
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001346 init_completion(&mcbsp->rx_dma_completion);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001347
Tony Lindgren120db2c2006-04-02 17:46:27 +01001348 if (cpu_class_is_omap1()) {
1349 src_port = OMAP_DMA_PORT_TIPB;
1350 dest_port = OMAP_DMA_PORT_EMIFF;
1351 }
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001352 if (cpu_class_is_omap2())
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001353 sync_dev = mcbsp->dma_rx_sync;
Tony Lindgren120db2c2006-04-02 17:46:27 +01001354
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001355 omap_set_dma_transfer_params(mcbsp->dma_rx_lch,
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001356 OMAP_DMA_DATA_TYPE_S16,
1357 length >> 1, 1,
1358 OMAP_DMA_SYNC_ELEMENT,
1359 sync_dev, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001360
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001361 omap_set_dma_src_params(mcbsp->dma_rx_lch,
Tony Lindgren120db2c2006-04-02 17:46:27 +01001362 src_port,
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001363 OMAP_DMA_AMODE_CONSTANT,
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001364 mcbsp->phys_base + OMAP_MCBSP_REG_DRR1,
Tony Lindgren1a8bfa12005-11-10 14:26:50 +00001365 0, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001366
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001367 omap_set_dma_dest_params(mcbsp->dma_rx_lch,
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001368 dest_port,
1369 OMAP_DMA_AMODE_POST_INC,
1370 buffer,
1371 0, 0);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001372
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001373 omap_start_dma(mcbsp->dma_rx_lch);
1374 wait_for_completion(&mcbsp->rx_dma_completion);
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001375
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001376 return 0;
1377}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001378EXPORT_SYMBOL(omap_mcbsp_recv_buffer);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001379
1380/*
1381 * SPI wrapper.
1382 * Since SPI setup is much simpler than the generic McBSP one,
1383 * this wrapper just need an omap_mcbsp_spi_cfg structure as an input.
1384 * Once this is done, you can call omap_mcbsp_start().
1385 */
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001386void omap_mcbsp_set_spi_mode(unsigned int id,
1387 const struct omap_mcbsp_spi_cfg *spi_cfg)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001388{
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001389 struct omap_mcbsp *mcbsp;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001390 struct omap_mcbsp_reg_cfg mcbsp_cfg;
1391
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001392 if (!omap_mcbsp_check_valid_id(id)) {
1393 printk(KERN_ERR "%s: Invalid id (%d)\n", __func__, id + 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001394 return;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001395 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001396 mcbsp = id_to_mcbsp_ptr(id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001397
1398 memset(&mcbsp_cfg, 0, sizeof(struct omap_mcbsp_reg_cfg));
1399
1400 /* SPI has only one frame */
1401 mcbsp_cfg.rcr1 |= (RWDLEN1(spi_cfg->word_length) | RFRLEN1(0));
1402 mcbsp_cfg.xcr1 |= (XWDLEN1(spi_cfg->word_length) | XFRLEN1(0));
1403
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001404 /* Clock stop mode */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001405 if (spi_cfg->clk_stp_mode == OMAP_MCBSP_CLK_STP_MODE_NO_DELAY)
1406 mcbsp_cfg.spcr1 |= (1 << 12);
1407 else
1408 mcbsp_cfg.spcr1 |= (3 << 11);
1409
1410 /* Set clock parities */
1411 if (spi_cfg->rx_clock_polarity == OMAP_MCBSP_CLK_RISING)
1412 mcbsp_cfg.pcr0 |= CLKRP;
1413 else
1414 mcbsp_cfg.pcr0 &= ~CLKRP;
1415
1416 if (spi_cfg->tx_clock_polarity == OMAP_MCBSP_CLK_RISING)
1417 mcbsp_cfg.pcr0 &= ~CLKXP;
1418 else
1419 mcbsp_cfg.pcr0 |= CLKXP;
1420
1421 /* Set SCLKME to 0 and CLKSM to 1 */
1422 mcbsp_cfg.pcr0 &= ~SCLKME;
1423 mcbsp_cfg.srgr2 |= CLKSM;
1424
1425 /* Set FSXP */
1426 if (spi_cfg->fsx_polarity == OMAP_MCBSP_FS_ACTIVE_HIGH)
1427 mcbsp_cfg.pcr0 &= ~FSXP;
1428 else
1429 mcbsp_cfg.pcr0 |= FSXP;
1430
1431 if (spi_cfg->spi_mode == OMAP_MCBSP_SPI_MASTER) {
1432 mcbsp_cfg.pcr0 |= CLKXM;
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001433 mcbsp_cfg.srgr1 |= CLKGDV(spi_cfg->clk_div - 1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001434 mcbsp_cfg.pcr0 |= FSXM;
1435 mcbsp_cfg.srgr2 &= ~FSGM;
1436 mcbsp_cfg.xcr2 |= XDATDLY(1);
1437 mcbsp_cfg.rcr2 |= RDATDLY(1);
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001438 } else {
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001439 mcbsp_cfg.pcr0 &= ~CLKXM;
1440 mcbsp_cfg.srgr1 |= CLKGDV(1);
1441 mcbsp_cfg.pcr0 &= ~FSXM;
1442 mcbsp_cfg.xcr2 &= ~XDATDLY(3);
1443 mcbsp_cfg.rcr2 &= ~RDATDLY(3);
1444 }
1445
1446 mcbsp_cfg.xcr2 &= ~XPHASE;
1447 mcbsp_cfg.rcr2 &= ~RPHASE;
1448
1449 omap_mcbsp_config(id, &mcbsp_cfg);
1450}
Eduardo Valentinfb78d802008-07-03 12:24:39 +03001451EXPORT_SYMBOL(omap_mcbsp_set_spi_mode);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001452
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001453#ifdef CONFIG_ARCH_OMAP3
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001454#define max_thres(m) (mcbsp->pdata->buffer_size)
1455#define valid_threshold(m, val) ((val) <= max_thres(m))
1456#define THRESHOLD_PROP_BUILDER(prop) \
1457static ssize_t prop##_show(struct device *dev, \
1458 struct device_attribute *attr, char *buf) \
1459{ \
1460 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
1461 \
1462 return sprintf(buf, "%u\n", mcbsp->prop); \
1463} \
1464 \
1465static ssize_t prop##_store(struct device *dev, \
1466 struct device_attribute *attr, \
1467 const char *buf, size_t size) \
1468{ \
1469 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
1470 unsigned long val; \
1471 int status; \
1472 \
1473 status = strict_strtoul(buf, 0, &val); \
1474 if (status) \
1475 return status; \
1476 \
1477 if (!valid_threshold(mcbsp, val)) \
1478 return -EDOM; \
1479 \
1480 mcbsp->prop = val; \
1481 return size; \
1482} \
1483 \
1484static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
1485
1486THRESHOLD_PROP_BUILDER(max_tx_thres);
1487THRESHOLD_PROP_BUILDER(max_rx_thres);
1488
Jarkko Nikula9b300502009-08-24 17:45:50 +03001489static const char *dma_op_modes[] = {
1490 "element", "threshold", "frame",
1491};
1492
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001493static ssize_t dma_op_mode_show(struct device *dev,
1494 struct device_attribute *attr, char *buf)
1495{
1496 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +03001497 int dma_op_mode, i = 0;
1498 ssize_t len = 0;
1499 const char * const *s;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001500
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001501 dma_op_mode = mcbsp->dma_op_mode;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001502
Jarkko Nikula9b300502009-08-24 17:45:50 +03001503 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
1504 if (dma_op_mode == i)
1505 len += sprintf(buf + len, "[%s] ", *s);
1506 else
1507 len += sprintf(buf + len, "%s ", *s);
1508 }
1509 len += sprintf(buf + len, "\n");
1510
1511 return len;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001512}
1513
1514static ssize_t dma_op_mode_store(struct device *dev,
1515 struct device_attribute *attr,
1516 const char *buf, size_t size)
1517{
1518 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +03001519 const char * const *s;
1520 int i = 0;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001521
Jarkko Nikula9b300502009-08-24 17:45:50 +03001522 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++)
1523 if (sysfs_streq(buf, *s))
1524 break;
1525
1526 if (i == ARRAY_SIZE(dma_op_modes))
1527 return -EINVAL;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001528
1529 spin_lock_irq(&mcbsp->lock);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001530 if (!mcbsp->free) {
1531 size = -EBUSY;
1532 goto unlock;
1533 }
Jarkko Nikula9b300502009-08-24 17:45:50 +03001534 mcbsp->dma_op_mode = i;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001535
1536unlock:
1537 spin_unlock_irq(&mcbsp->lock);
1538
1539 return size;
1540}
1541
1542static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
1543
Eero Nurkkalad912fa92010-02-22 12:21:11 +00001544static ssize_t st_taps_show(struct device *dev,
1545 struct device_attribute *attr, char *buf)
1546{
1547 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
1548 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
1549 ssize_t status = 0;
1550 int i;
1551
1552 spin_lock_irq(&mcbsp->lock);
1553 for (i = 0; i < st_data->nr_taps; i++)
1554 status += sprintf(&buf[status], (i ? ", %d" : "%d"),
1555 st_data->taps[i]);
1556 if (i)
1557 status += sprintf(&buf[status], "\n");
1558 spin_unlock_irq(&mcbsp->lock);
1559
1560 return status;
1561}
1562
1563static ssize_t st_taps_store(struct device *dev,
1564 struct device_attribute *attr,
1565 const char *buf, size_t size)
1566{
1567 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
1568 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
1569 int val, tmp, status, i = 0;
1570
1571 spin_lock_irq(&mcbsp->lock);
1572 memset(st_data->taps, 0, sizeof(st_data->taps));
1573 st_data->nr_taps = 0;
1574
1575 do {
1576 status = sscanf(buf, "%d%n", &val, &tmp);
1577 if (status < 0 || status == 0) {
1578 size = -EINVAL;
1579 goto out;
1580 }
1581 if (val < -32768 || val > 32767) {
1582 size = -EINVAL;
1583 goto out;
1584 }
1585 st_data->taps[i++] = val;
1586 buf += tmp;
1587 if (*buf != ',')
1588 break;
1589 buf++;
1590 } while (1);
1591
1592 st_data->nr_taps = i;
1593
1594out:
1595 spin_unlock_irq(&mcbsp->lock);
1596
1597 return size;
1598}
1599
1600static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
1601
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001602static const struct attribute *additional_attrs[] = {
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001603 &dev_attr_max_tx_thres.attr,
1604 &dev_attr_max_rx_thres.attr,
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001605 &dev_attr_dma_op_mode.attr,
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001606 NULL,
1607};
1608
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001609static const struct attribute_group additional_attr_group = {
1610 .attrs = (struct attribute **)additional_attrs,
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001611};
1612
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001613static inline int __devinit omap_additional_add(struct device *dev)
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001614{
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001615 return sysfs_create_group(&dev->kobj, &additional_attr_group);
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001616}
1617
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001618static inline void __devexit omap_additional_remove(struct device *dev)
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001619{
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001620 sysfs_remove_group(&dev->kobj, &additional_attr_group);
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001621}
1622
Eero Nurkkalad912fa92010-02-22 12:21:11 +00001623static const struct attribute *sidetone_attrs[] = {
1624 &dev_attr_st_taps.attr,
1625 NULL,
1626};
1627
1628static const struct attribute_group sidetone_attr_group = {
1629 .attrs = (struct attribute **)sidetone_attrs,
1630};
1631
1632int __devinit omap_st_add(struct omap_mcbsp *mcbsp)
1633{
1634 struct omap_mcbsp_platform_data *pdata = mcbsp->pdata;
1635 struct omap_mcbsp_st_data *st_data;
1636 int err;
1637
1638 st_data = kzalloc(sizeof(*mcbsp->st_data), GFP_KERNEL);
1639 if (!st_data) {
1640 err = -ENOMEM;
1641 goto err1;
1642 }
1643
1644 st_data->io_base_st = ioremap(pdata->phys_base_st, SZ_4K);
1645 if (!st_data->io_base_st) {
1646 err = -ENOMEM;
1647 goto err2;
1648 }
1649
1650 err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
1651 if (err)
1652 goto err3;
1653
1654 mcbsp->st_data = st_data;
1655 return 0;
1656
1657err3:
1658 iounmap(st_data->io_base_st);
1659err2:
1660 kfree(st_data);
1661err1:
1662 return err;
1663
1664}
1665
1666static void __devexit omap_st_remove(struct omap_mcbsp *mcbsp)
1667{
1668 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
1669
1670 if (st_data) {
1671 sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
1672 iounmap(st_data->io_base_st);
1673 kfree(st_data);
1674 }
1675}
1676
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001677static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp)
1678{
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001679 mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001680 if (cpu_is_omap34xx()) {
1681 mcbsp->max_tx_thres = max_thres(mcbsp);
1682 mcbsp->max_rx_thres = max_thres(mcbsp);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +03001683 /*
1684 * REVISIT: Set dmap_op_mode to THRESHOLD as default
1685 * for mcbsp2 instances.
1686 */
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001687 if (omap_additional_add(mcbsp->dev))
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001688 dev_warn(mcbsp->dev,
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001689 "Unable to create additional controls\n");
Eero Nurkkalad912fa92010-02-22 12:21:11 +00001690
1691 if (mcbsp->id == 2 || mcbsp->id == 3)
1692 if (omap_st_add(mcbsp))
1693 dev_warn(mcbsp->dev,
1694 "Unable to create sidetone controls\n");
1695
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001696 } else {
1697 mcbsp->max_tx_thres = -EINVAL;
1698 mcbsp->max_rx_thres = -EINVAL;
1699 }
1700}
1701
1702static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp)
1703{
Eero Nurkkalad912fa92010-02-22 12:21:11 +00001704 if (cpu_is_omap34xx()) {
Eduardo Valentin4c8200a2009-08-20 16:18:13 +03001705 omap_additional_remove(mcbsp->dev);
Eero Nurkkalad912fa92010-02-22 12:21:11 +00001706
1707 if (mcbsp->id == 2 || mcbsp->id == 3)
1708 omap_st_remove(mcbsp);
1709 }
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001710}
1711#else
1712static inline void __devinit omap34xx_device_init(struct omap_mcbsp *mcbsp) {}
1713static inline void __devexit omap34xx_device_exit(struct omap_mcbsp *mcbsp) {}
Tony Lindgrena8eb7ca2010-02-12 12:26:48 -08001714#endif /* CONFIG_ARCH_OMAP3 */
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001715
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001716/*
1717 * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
1718 * 730 has only 2 McBSP, and both of them are MPU peripherals.
1719 */
Uwe Kleine-König25cef222008-10-08 10:01:39 +03001720static int __devinit omap_mcbsp_probe(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001721{
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001722 struct omap_mcbsp_platform_data *pdata = pdev->dev.platform_data;
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001723 struct omap_mcbsp *mcbsp;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001724 int id = pdev->id - 1;
1725 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001726
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001727 if (!pdata) {
1728 dev_err(&pdev->dev, "McBSP device initialized without"
1729 "platform data\n");
1730 ret = -EINVAL;
1731 goto exit;
1732 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001733
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001734 dev_dbg(&pdev->dev, "Initializing OMAP McBSP (%d).\n", pdev->id);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001735
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001736 if (id >= omap_mcbsp_count) {
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001737 dev_err(&pdev->dev, "Invalid McBSP device id (%d)\n", id);
1738 ret = -EINVAL;
1739 goto exit;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001740 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001741
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001742 mcbsp = kzalloc(sizeof(struct omap_mcbsp), GFP_KERNEL);
1743 if (!mcbsp) {
1744 ret = -ENOMEM;
1745 goto exit;
1746 }
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001747
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001748 spin_lock_init(&mcbsp->lock);
1749 mcbsp->id = id + 1;
1750 mcbsp->free = 1;
1751 mcbsp->dma_tx_lch = -1;
1752 mcbsp->dma_rx_lch = -1;
1753
1754 mcbsp->phys_base = pdata->phys_base;
1755 mcbsp->io_base = ioremap(pdata->phys_base, SZ_4K);
1756 if (!mcbsp->io_base) {
Russell Kingd592dd12008-09-04 14:25:42 +01001757 ret = -ENOMEM;
1758 goto err_ioremap;
1759 }
1760
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001761 /* Default I/O is IRQ based */
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001762 mcbsp->io_type = OMAP_MCBSP_IRQ_IO;
1763 mcbsp->tx_irq = pdata->tx_irq;
1764 mcbsp->rx_irq = pdata->rx_irq;
1765 mcbsp->dma_rx_sync = pdata->dma_rx_sync;
1766 mcbsp->dma_tx_sync = pdata->dma_tx_sync;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001767
Russell Kingb820ce42009-01-23 10:26:46 +00001768 mcbsp->iclk = clk_get(&pdev->dev, "ick");
1769 if (IS_ERR(mcbsp->iclk)) {
1770 ret = PTR_ERR(mcbsp->iclk);
1771 dev_err(&pdev->dev, "unable to get ick: %d\n", ret);
1772 goto err_iclk;
1773 }
Stanley.Miao06151152009-01-29 08:57:12 -08001774
Russell Kingb820ce42009-01-23 10:26:46 +00001775 mcbsp->fclk = clk_get(&pdev->dev, "fck");
1776 if (IS_ERR(mcbsp->fclk)) {
1777 ret = PTR_ERR(mcbsp->fclk);
1778 dev_err(&pdev->dev, "unable to get fck: %d\n", ret);
1779 goto err_fclk;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001780 }
1781
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001782 mcbsp->pdata = pdata;
1783 mcbsp->dev = &pdev->dev;
Russell Kingb820ce42009-01-23 10:26:46 +00001784 mcbsp_ptr[id] = mcbsp;
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001785 platform_set_drvdata(pdev, mcbsp);
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001786
1787 /* Initialize mcbsp properties for OMAP34XX if needed / applicable */
1788 omap34xx_device_init(mcbsp);
1789
Russell Kingd592dd12008-09-04 14:25:42 +01001790 return 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001791
Russell Kingb820ce42009-01-23 10:26:46 +00001792err_fclk:
1793 clk_put(mcbsp->iclk);
1794err_iclk:
Chandra Shekharb4b58f52008-10-08 10:01:39 +03001795 iounmap(mcbsp->io_base);
Russell Kingd592dd12008-09-04 14:25:42 +01001796err_ioremap:
Russell Kingb820ce42009-01-23 10:26:46 +00001797 kfree(mcbsp);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001798exit:
1799 return ret;
1800}
1801
Uwe Kleine-König25cef222008-10-08 10:01:39 +03001802static int __devexit omap_mcbsp_remove(struct platform_device *pdev)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001803{
1804 struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
1805
1806 platform_set_drvdata(pdev, NULL);
1807 if (mcbsp) {
1808
1809 if (mcbsp->pdata && mcbsp->pdata->ops &&
1810 mcbsp->pdata->ops->free)
1811 mcbsp->pdata->ops->free(mcbsp->id);
1812
Eduardo Valentina1a56f52009-08-20 16:18:11 +03001813 omap34xx_device_exit(mcbsp);
1814
Russell Kingb820ce42009-01-23 10:26:46 +00001815 clk_disable(mcbsp->fclk);
1816 clk_disable(mcbsp->iclk);
1817 clk_put(mcbsp->fclk);
1818 clk_put(mcbsp->iclk);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001819
Russell Kingd592dd12008-09-04 14:25:42 +01001820 iounmap(mcbsp->io_base);
1821
Russell Kingb820ce42009-01-23 10:26:46 +00001822 mcbsp->fclk = NULL;
1823 mcbsp->iclk = NULL;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001824 mcbsp->free = 0;
1825 mcbsp->dev = NULL;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001826 }
1827
1828 return 0;
1829}
1830
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001831static struct platform_driver omap_mcbsp_driver = {
1832 .probe = omap_mcbsp_probe,
Uwe Kleine-König25cef222008-10-08 10:01:39 +03001833 .remove = __devexit_p(omap_mcbsp_remove),
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001834 .driver = {
1835 .name = "omap-mcbsp",
1836 },
1837};
1838
1839int __init omap_mcbsp_init(void)
1840{
1841 /* Register the McBSP driver */
1842 return platform_driver_register(&omap_mcbsp_driver);
1843}