blob: afb8d4f1bedfac70eb98492ce5b4c023bb9d0752 [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
Peter Ujfalusi71e822e2012-01-26 12:47:22 +02002 * sound/soc/omap/mcbsp.c
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01003 *
4 * Copyright (C) 2004 Nokia Corporation
5 * Author: Samuel Ortiz <samuel.ortiz@nokia.com>
6 *
Peter Ujfalusi71e822e2012-01-26 12:47:22 +02007 * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
8 * Peter Ujfalusi <peter.ujfalusi@ti.com>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2 as
12 * published by the Free Software Foundation.
13 *
14 * Multichannel mode not supported.
15 */
16
17#include <linux/module.h>
18#include <linux/init.h>
19#include <linux/device.h>
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +030020#include <linux/platform_device.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010021#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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090026#include <linux/slab.h>
Peter Ujfalusif1991312012-08-16 16:41:00 +030027#include <linux/pm_runtime.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010028
Arnd Bergmann22037472012-08-24 15:21:06 +020029#include <linux/platform_data/asoc-ti-mcbsp.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030
Tony Lindgren7d7e1eb2012-08-27 17:43:01 -070031#include <plat/cpu.h>
32
Peter Ujfalusi219f4312012-02-03 13:11:47 +020033#include "mcbsp.h"
34
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070035static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030036{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030037 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
38
39 if (mcbsp->pdata->reg_size == 2) {
40 ((u16 *)mcbsp->reg_cache)[reg] = (u16)val;
41 __raw_writew((u16)val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080042 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030043 ((u32 *)mcbsp->reg_cache)[reg] = val;
44 __raw_writel(val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080045 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030046}
47
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070048static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030049{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030050 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
51
52 if (mcbsp->pdata->reg_size == 2) {
53 return !from_cache ? __raw_readw(addr) :
54 ((u16 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080055 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030056 return !from_cache ? __raw_readl(addr) :
57 ((u32 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080058 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030059}
60
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070061static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000062{
63 __raw_writel(val, mcbsp->st_data->io_base_st + reg);
64}
65
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070066static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000067{
68 return __raw_readl(mcbsp->st_data->io_base_st + reg);
69}
Eero Nurkkalad912fa92010-02-22 12:21:11 +000070
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080071#define MCBSP_READ(mcbsp, reg) \
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080072 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080073#define MCBSP_WRITE(mcbsp, reg, val) \
74 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080075#define MCBSP_READ_CACHE(mcbsp, reg) \
76 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030077
Eero Nurkkalad912fa92010-02-22 12:21:11 +000078#define MCBSP_ST_READ(mcbsp, reg) \
79 omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
80#define MCBSP_ST_WRITE(mcbsp, reg, val) \
81 omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
82
Peter Ujfalusi45656b42012-02-14 18:20:58 +020083static void omap_mcbsp_dump_reg(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010084{
Chandra Shekharb4b58f52008-10-08 10:01:39 +030085 dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id);
86 dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080087 MCBSP_READ(mcbsp, DRR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030088 dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080089 MCBSP_READ(mcbsp, DRR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030090 dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080091 MCBSP_READ(mcbsp, DXR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030092 dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080093 MCBSP_READ(mcbsp, DXR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030094 dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080095 MCBSP_READ(mcbsp, SPCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030096 dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080097 MCBSP_READ(mcbsp, SPCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030098 dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080099 MCBSP_READ(mcbsp, RCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300100 dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800101 MCBSP_READ(mcbsp, RCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300102 dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800103 MCBSP_READ(mcbsp, XCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300104 dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800105 MCBSP_READ(mcbsp, XCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300106 dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800107 MCBSP_READ(mcbsp, SRGR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300108 dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800109 MCBSP_READ(mcbsp, SRGR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300110 dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800111 MCBSP_READ(mcbsp, PCR0));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300112 dev_dbg(mcbsp->dev, "***********************\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100113}
114
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200115static irqreturn_t omap_mcbsp_irq_handler(int irq, void *dev_id)
116{
117 struct omap_mcbsp *mcbsp = dev_id;
118 u16 irqst;
119
120 irqst = MCBSP_READ(mcbsp, IRQST);
121 dev_dbg(mcbsp->dev, "IRQ callback : 0x%x\n", irqst);
122
123 if (irqst & RSYNCERREN)
124 dev_err(mcbsp->dev, "RX Frame Sync Error!\n");
125 if (irqst & RFSREN)
126 dev_dbg(mcbsp->dev, "RX Frame Sync\n");
127 if (irqst & REOFEN)
128 dev_dbg(mcbsp->dev, "RX End Of Frame\n");
129 if (irqst & RRDYEN)
130 dev_dbg(mcbsp->dev, "RX Buffer Threshold Reached\n");
131 if (irqst & RUNDFLEN)
132 dev_err(mcbsp->dev, "RX Buffer Underflow!\n");
133 if (irqst & ROVFLEN)
134 dev_err(mcbsp->dev, "RX Buffer Overflow!\n");
135
136 if (irqst & XSYNCERREN)
137 dev_err(mcbsp->dev, "TX Frame Sync Error!\n");
138 if (irqst & XFSXEN)
139 dev_dbg(mcbsp->dev, "TX Frame Sync\n");
140 if (irqst & XEOFEN)
141 dev_dbg(mcbsp->dev, "TX End Of Frame\n");
142 if (irqst & XRDYEN)
143 dev_dbg(mcbsp->dev, "TX Buffer threshold Reached\n");
144 if (irqst & XUNDFLEN)
145 dev_err(mcbsp->dev, "TX Buffer Underflow!\n");
146 if (irqst & XOVFLEN)
147 dev_err(mcbsp->dev, "TX Buffer Overflow!\n");
148 if (irqst & XEMPTYEOFEN)
149 dev_dbg(mcbsp->dev, "TX Buffer empty at end of frame\n");
150
151 MCBSP_WRITE(mcbsp, IRQST, irqst);
152
153 return IRQ_HANDLED;
154}
155
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700156static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100157{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400158 struct omap_mcbsp *mcbsp_tx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700159 u16 irqst_spcr2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100160
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800161 irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700162 dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100163
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700164 if (irqst_spcr2 & XSYNC_ERR) {
165 dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n",
166 irqst_spcr2);
167 /* Writing zero to XSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000168 MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700169 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300170
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100171 return IRQ_HANDLED;
172}
173
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700174static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100175{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400176 struct omap_mcbsp *mcbsp_rx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700177 u16 irqst_spcr1;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100178
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800179 irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700180 dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100181
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700182 if (irqst_spcr1 & RSYNC_ERR) {
183 dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n",
184 irqst_spcr1);
185 /* Writing zero to RSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000186 MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700187 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300188
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100189 return IRQ_HANDLED;
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 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200198void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
199 const struct omap_mcbsp_reg_cfg *config)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100200{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300201 dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n",
202 mcbsp->id, mcbsp->phys_base);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100203
204 /* We write the given config */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800205 MCBSP_WRITE(mcbsp, SPCR2, config->spcr2);
206 MCBSP_WRITE(mcbsp, SPCR1, config->spcr1);
207 MCBSP_WRITE(mcbsp, RCR2, config->rcr2);
208 MCBSP_WRITE(mcbsp, RCR1, config->rcr1);
209 MCBSP_WRITE(mcbsp, XCR2, config->xcr2);
210 MCBSP_WRITE(mcbsp, XCR1, config->xcr1);
211 MCBSP_WRITE(mcbsp, SRGR2, config->srgr2);
212 MCBSP_WRITE(mcbsp, SRGR1, config->srgr1);
213 MCBSP_WRITE(mcbsp, MCR2, config->mcr2);
214 MCBSP_WRITE(mcbsp, MCR1, config->mcr1);
215 MCBSP_WRITE(mcbsp, PCR0, config->pcr0);
Jarkko Nikula88408232011-09-26 10:45:41 +0300216 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800217 MCBSP_WRITE(mcbsp, XCCR, config->xccr);
218 MCBSP_WRITE(mcbsp, RCCR, config->rccr);
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200219 }
Peter Ujfalusi08905d82012-03-05 11:27:40 +0200220 /* Enable wakeup behavior */
221 if (mcbsp->pdata->has_wakeup)
222 MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200223
224 /* Enable TX/RX sync error interrupts by default */
225 if (mcbsp->irq)
226 MCBSP_WRITE(mcbsp, IRQEN, RSYNCERREN | XSYNCERREN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100227}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100228
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530229/**
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530230 * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
231 * @id - mcbsp id
232 * @stream - indicates the direction of data flow (rx or tx)
233 *
234 * Returns the address of mcbsp data transmit register or data receive register
235 * to be used by DMA for transferring/receiving data based on the value of
236 * @stream for the requested mcbsp given by @id
237 */
Peter Ujfalusib8fb4902012-02-14 15:41:29 +0200238static int omap_mcbsp_dma_reg_params(struct omap_mcbsp *mcbsp,
239 unsigned int stream)
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530240{
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530241 int data_reg;
242
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300243 if (mcbsp->pdata->reg_size == 2) {
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530244 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300245 data_reg = OMAP_MCBSP_REG_DRR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530246 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300247 data_reg = OMAP_MCBSP_REG_DXR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530248 } else {
249 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300250 data_reg = OMAP_MCBSP_REG_DRR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530251 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300252 data_reg = OMAP_MCBSP_REG_DXR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530253 }
254
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300255 return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530256}
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530257
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000258static void omap_st_on(struct omap_mcbsp *mcbsp)
259{
260 unsigned int w;
261
Jarkko Nikula1743d142011-09-26 10:45:44 +0300262 if (mcbsp->pdata->enable_st_clock)
263 mcbsp->pdata->enable_st_clock(mcbsp->id, 1);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000264
265 /* Enable McBSP Sidetone */
266 w = MCBSP_READ(mcbsp, SSELCR);
267 MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
268
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000269 /* Enable Sidetone from Sidetone Core */
270 w = MCBSP_ST_READ(mcbsp, SSELCR);
271 MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN);
272}
273
274static void omap_st_off(struct omap_mcbsp *mcbsp)
275{
276 unsigned int w;
277
278 w = MCBSP_ST_READ(mcbsp, SSELCR);
279 MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
280
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000281 w = MCBSP_READ(mcbsp, SSELCR);
282 MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
283
Jarkko Nikula1743d142011-09-26 10:45:44 +0300284 if (mcbsp->pdata->enable_st_clock)
285 mcbsp->pdata->enable_st_clock(mcbsp->id, 0);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000286}
287
288static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
289{
290 u16 val, i;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000291
292 val = MCBSP_ST_READ(mcbsp, SSELCR);
293
294 if (val & ST_COEFFWREN)
295 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
296
297 MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN);
298
299 for (i = 0; i < 128; i++)
300 MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]);
301
302 i = 0;
303
304 val = MCBSP_ST_READ(mcbsp, SSELCR);
305 while (!(val & ST_COEFFWRDONE) && (++i < 1000))
306 val = MCBSP_ST_READ(mcbsp, SSELCR);
307
308 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
309
310 if (i == 1000)
311 dev_err(mcbsp->dev, "McBSP FIR load error!\n");
312}
313
314static void omap_st_chgain(struct omap_mcbsp *mcbsp)
315{
316 u16 w;
317 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000318
319 w = MCBSP_ST_READ(mcbsp, SSELCR);
320
321 MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \
322 ST_CH1GAIN(st_data->ch1gain));
323}
324
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200325int omap_st_set_chgain(struct omap_mcbsp *mcbsp, int channel, s16 chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000326{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200327 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000328 int ret = 0;
329
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000330 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}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000347
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200348int omap_st_get_chgain(struct omap_mcbsp *mcbsp, int channel, s16 *chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000349{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200350 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000351 int ret = 0;
352
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000353 if (!st_data)
354 return -ENOENT;
355
356 spin_lock_irq(&mcbsp->lock);
357 if (channel == 0)
358 *chgain = st_data->ch0gain;
359 else if (channel == 1)
360 *chgain = st_data->ch1gain;
361 else
362 ret = -EINVAL;
363 spin_unlock_irq(&mcbsp->lock);
364
365 return ret;
366}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000367
368static int omap_st_start(struct omap_mcbsp *mcbsp)
369{
370 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
371
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200372 if (st_data->enabled && !st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000373 omap_st_fir_write(mcbsp, st_data->taps);
374 omap_st_chgain(mcbsp);
375
376 if (!mcbsp->free) {
377 omap_st_on(mcbsp);
378 st_data->running = 1;
379 }
380 }
381
382 return 0;
383}
384
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200385int omap_st_enable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000386{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200387 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000388
389 if (!st_data)
390 return -ENODEV;
391
392 spin_lock_irq(&mcbsp->lock);
393 st_data->enabled = 1;
394 omap_st_start(mcbsp);
395 spin_unlock_irq(&mcbsp->lock);
396
397 return 0;
398}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000399
400static int omap_st_stop(struct omap_mcbsp *mcbsp)
401{
402 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
403
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200404 if (st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000405 if (!mcbsp->free) {
406 omap_st_off(mcbsp);
407 st_data->running = 0;
408 }
409 }
410
411 return 0;
412}
413
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200414int omap_st_disable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000415{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200416 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000417 int ret = 0;
418
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000419 if (!st_data)
420 return -ENODEV;
421
422 spin_lock_irq(&mcbsp->lock);
423 omap_st_stop(mcbsp);
424 st_data->enabled = 0;
425 spin_unlock_irq(&mcbsp->lock);
426
427 return ret;
428}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000429
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200430int omap_st_is_enabled(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000431{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200432 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000433
434 if (!st_data)
435 return -ENODEV;
436
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000437 return st_data->enabled;
438}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000439
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300440/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300441 * omap_mcbsp_set_rx_threshold configures the transmit threshold in words.
442 * The threshold parameter is 1 based, and it is converted (threshold - 1)
443 * for the THRSH2 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300444 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200445void omap_mcbsp_set_tx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300446{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300447 if (mcbsp->pdata->buffer_size == 0)
448 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300449
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300450 if (threshold && threshold <= mcbsp->max_tx_thres)
451 MCBSP_WRITE(mcbsp, THRSH2, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300452}
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300453
454/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300455 * omap_mcbsp_set_rx_threshold configures the receive threshold in words.
456 * The threshold parameter is 1 based, and it is converted (threshold - 1)
457 * for the THRSH1 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300458 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200459void omap_mcbsp_set_rx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300460{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300461 if (mcbsp->pdata->buffer_size == 0)
462 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300463
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300464 if (threshold && threshold <= mcbsp->max_rx_thres)
465 MCBSP_WRITE(mcbsp, THRSH1, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300466}
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300467
468/*
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200469 * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
470 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200471u16 omap_mcbsp_get_tx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200472{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200473 u16 buffstat;
474
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300475 if (mcbsp->pdata->buffer_size == 0)
476 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200477
478 /* Returns the number of free locations in the buffer */
479 buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
480
481 /* Number of slots are different in McBSP ports */
Peter Ujfalusif10b8ad2010-06-03 07:39:34 +0300482 return mcbsp->pdata->buffer_size - buffstat;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200483}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200484
485/*
486 * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
487 * to reach the threshold value (when the DMA will be triggered to read it)
488 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200489u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200490{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200491 u16 buffstat, threshold;
492
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300493 if (mcbsp->pdata->buffer_size == 0)
494 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200495
496 /* Returns the number of used locations in the buffer */
497 buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
498 /* RX threshold */
499 threshold = MCBSP_READ(mcbsp, THRSH1);
500
501 /* Return the number of location till we reach the threshold limit */
502 if (threshold <= buffstat)
503 return 0;
504 else
505 return threshold - buffstat;
506}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200507
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200508int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100509{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800510 void *reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100511 int err;
512
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300513 reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800514 if (!reg_cache) {
515 return -ENOMEM;
516 }
517
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300518 spin_lock(&mcbsp->lock);
519 if (!mcbsp->free) {
520 dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
521 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800522 err = -EBUSY;
523 goto err_kfree;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100524 }
525
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800526 mcbsp->free = false;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800527 mcbsp->reg_cache = reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300528 spin_unlock(&mcbsp->lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100529
Russell Kingb820ce42009-01-23 10:26:46 +0000530 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200531 mcbsp->pdata->ops->request(mcbsp->id - 1);
Russell Kingb820ce42009-01-23 10:26:46 +0000532
Jarkko Nikula5a070552008-10-08 10:01:41 +0300533 /*
534 * Make sure that transmitter, receiver and sample-rate generator are
535 * not running before activating IRQs.
536 */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800537 MCBSP_WRITE(mcbsp, SPCR1, 0);
538 MCBSP_WRITE(mcbsp, SPCR2, 0);
Jarkko Nikula5a070552008-10-08 10:01:41 +0300539
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200540 if (mcbsp->irq) {
541 err = request_irq(mcbsp->irq, omap_mcbsp_irq_handler, 0,
542 "McBSP", (void *)mcbsp);
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000543 if (err != 0) {
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200544 dev_err(mcbsp->dev, "Unable to request IRQ\n");
545 goto err_clk_disable;
546 }
547 } else {
548 err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, 0,
549 "McBSP TX", (void *)mcbsp);
550 if (err != 0) {
551 dev_err(mcbsp->dev, "Unable to request TX IRQ\n");
552 goto err_clk_disable;
553 }
554
555 err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler, 0,
556 "McBSP RX", (void *)mcbsp);
557 if (err != 0) {
558 dev_err(mcbsp->dev, "Unable to request RX IRQ\n");
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000559 goto err_free_irq;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100560 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100561 }
562
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100563 return 0;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800564err_free_irq:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800565 free_irq(mcbsp->tx_irq, (void *)mcbsp);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800566err_clk_disable:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800567 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200568 mcbsp->pdata->ops->free(mcbsp->id - 1);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800569
Jarkko Nikula1a645882011-09-26 10:45:40 +0300570 /* Disable wakeup behavior */
571 if (mcbsp->pdata->has_wakeup)
572 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800573
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800574 spin_lock(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800575 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800576 mcbsp->reg_cache = NULL;
577err_kfree:
578 spin_unlock(&mcbsp->lock);
579 kfree(reg_cache);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800580
581 return err;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100582}
583
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200584void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100585{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800586 void *reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300587
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300588 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200589 mcbsp->pdata->ops->free(mcbsp->id - 1);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300590
Jarkko Nikula1a645882011-09-26 10:45:40 +0300591 /* Disable wakeup behavior */
592 if (mcbsp->pdata->has_wakeup)
593 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300594
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200595 /* Disable interrupt requests */
596 if (mcbsp->irq)
597 MCBSP_WRITE(mcbsp, IRQEN, 0);
598
599 if (mcbsp->irq) {
600 free_irq(mcbsp->irq, (void *)mcbsp);
601 } else {
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000602 free_irq(mcbsp->rx_irq, (void *)mcbsp);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200603 free_irq(mcbsp->tx_irq, (void *)mcbsp);
604 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100605
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800606 reg_cache = mcbsp->reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100607
Peter Ujfalusie3866152012-03-05 11:32:27 +0200608 /*
609 * Select CLKS source from internal source unconditionally before
610 * marking the McBSP port as free.
611 * If the external clock source via MCBSP_CLKS pin has been selected the
612 * system will refuse to enter idle if the CLKS pin source is not reset
613 * back to internal source.
614 */
615 if (!cpu_class_is_omap1())
616 omap2_mcbsp_set_clks_src(mcbsp, MCBSP_CLKS_PRCM_SRC);
617
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800618 spin_lock(&mcbsp->lock);
619 if (mcbsp->free)
620 dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
621 else
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800622 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800623 mcbsp->reg_cache = NULL;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300624 spin_unlock(&mcbsp->lock);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800625
626 if (reg_cache)
627 kfree(reg_cache);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100628}
629
630/*
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300631 * Here we start the McBSP, by enabling transmitter, receiver or both.
632 * If no transmitter or receiver is active prior calling, then sample-rate
633 * generator and frame sync are started.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100634 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200635void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100636{
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000637 int enable_srg = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100638 u16 w;
639
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300640 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000641 omap_st_start(mcbsp);
642
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000643 /* Only enable SRG, if McBSP is master */
644 w = MCBSP_READ_CACHE(mcbsp, PCR0);
645 if (w & (FSXM | FSRM | CLKXM | CLKRM))
646 enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
647 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300648
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000649 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300650 /* Start the sample generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800651 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800652 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300653 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100654
655 /* Enable transmitter and receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300656 tx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800657 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800658 MCBSP_WRITE(mcbsp, SPCR2, w | tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100659
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300660 rx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800661 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800662 MCBSP_WRITE(mcbsp, SPCR1, w | rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100663
Eduardo Valentin44a63112009-08-20 16:18:09 +0300664 /*
665 * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
666 * REVISIT: 100us may give enough time for two CLKSRG, however
667 * due to some unknown PM related, clock gating etc. reason it
668 * is now at 500us.
669 */
670 udelay(500);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100671
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000672 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300673 /* Start frame sync */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800674 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800675 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300676 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100677
Jarkko Nikula88408232011-09-26 10:45:41 +0300678 if (mcbsp->pdata->has_ccr) {
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300679 /* Release the transmitter and receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800680 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300681 w &= ~(tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800682 MCBSP_WRITE(mcbsp, XCCR, w);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800683 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300684 w &= ~(rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800685 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300686 }
687
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688 /* Dump McBSP Regs */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200689 omap_mcbsp_dump_reg(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100690}
691
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200692void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100693{
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300694 int idle;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100695 u16 w;
696
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300697 /* Reset transmitter */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300698 tx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300699 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800700 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300701 w |= (tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800702 MCBSP_WRITE(mcbsp, XCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300703 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800704 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800705 MCBSP_WRITE(mcbsp, SPCR2, w & ~tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100706
707 /* Reset receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300708 rx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300709 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800710 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulaa93d4ed2009-10-14 09:56:35 -0700711 w |= (rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800712 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300713 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800714 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800715 MCBSP_WRITE(mcbsp, SPCR1, w & ~rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100716
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800717 idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
718 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300719
720 if (idle) {
721 /* Reset the sample rate generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800722 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800723 MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300724 }
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000725
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300726 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000727 omap_st_stop(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100728}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100729
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200730int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id)
Paul Walmsley69d042d2011-07-01 08:52:25 +0000731{
Peter Ujfalusif1991312012-08-16 16:41:00 +0300732 struct clk *fck_src;
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300733 const char *src;
Peter Ujfalusif1991312012-08-16 16:41:00 +0300734 int r;
Paul Walmsley69d042d2011-07-01 08:52:25 +0000735
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300736 if (fck_src_id == MCBSP_CLKS_PAD_SRC)
Peter Ujfalusif1991312012-08-16 16:41:00 +0300737 src = "pad_fck";
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300738 else if (fck_src_id == MCBSP_CLKS_PRCM_SRC)
Peter Ujfalusif1991312012-08-16 16:41:00 +0300739 src = "prcm_fck";
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300740 else
741 return -EINVAL;
742
Peter Ujfalusif1991312012-08-16 16:41:00 +0300743 fck_src = clk_get(mcbsp->dev, src);
744 if (IS_ERR(fck_src)) {
745 dev_err(mcbsp->dev, "CLKS: could not clk_get() %s\n", src);
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200746 return -EINVAL;
747 }
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300748
Peter Ujfalusif1991312012-08-16 16:41:00 +0300749 pm_runtime_put_sync(mcbsp->dev);
750
751 r = clk_set_parent(mcbsp->fclk, fck_src);
752 if (r) {
753 dev_err(mcbsp->dev, "CLKS: could not clk_set_parent() to %s\n",
754 src);
755 clk_put(fck_src);
756 return r;
757 }
758
759 pm_runtime_get_sync(mcbsp->dev);
760
761 clk_put(fck_src);
762
763 return 0;
764
Paul Walmsley69d042d2011-07-01 08:52:25 +0000765}
Paul Walmsley69d042d2011-07-01 08:52:25 +0000766
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300767#define max_thres(m) (mcbsp->pdata->buffer_size)
768#define valid_threshold(m, val) ((val) <= max_thres(m))
769#define THRESHOLD_PROP_BUILDER(prop) \
770static ssize_t prop##_show(struct device *dev, \
771 struct device_attribute *attr, char *buf) \
772{ \
773 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
774 \
775 return sprintf(buf, "%u\n", mcbsp->prop); \
776} \
777 \
778static ssize_t prop##_store(struct device *dev, \
779 struct device_attribute *attr, \
780 const char *buf, size_t size) \
781{ \
782 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
783 unsigned long val; \
784 int status; \
785 \
786 status = strict_strtoul(buf, 0, &val); \
787 if (status) \
788 return status; \
789 \
790 if (!valid_threshold(mcbsp, val)) \
791 return -EDOM; \
792 \
793 mcbsp->prop = val; \
794 return size; \
795} \
796 \
797static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
798
799THRESHOLD_PROP_BUILDER(max_tx_thres);
800THRESHOLD_PROP_BUILDER(max_rx_thres);
801
Jarkko Nikula9b300502009-08-24 17:45:50 +0300802static const char *dma_op_modes[] = {
Peter Ujfalusi09fa37a2012-03-15 12:29:49 +0200803 "element", "threshold",
Jarkko Nikula9b300502009-08-24 17:45:50 +0300804};
805
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300806static ssize_t dma_op_mode_show(struct device *dev,
807 struct device_attribute *attr, char *buf)
808{
809 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300810 int dma_op_mode, i = 0;
811 ssize_t len = 0;
812 const char * const *s;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300813
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300814 dma_op_mode = mcbsp->dma_op_mode;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300815
Jarkko Nikula9b300502009-08-24 17:45:50 +0300816 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
817 if (dma_op_mode == i)
818 len += sprintf(buf + len, "[%s] ", *s);
819 else
820 len += sprintf(buf + len, "%s ", *s);
821 }
822 len += sprintf(buf + len, "\n");
823
824 return len;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300825}
826
827static ssize_t dma_op_mode_store(struct device *dev,
828 struct device_attribute *attr,
829 const char *buf, size_t size)
830{
831 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300832 const char * const *s;
833 int i = 0;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300834
Jarkko Nikula9b300502009-08-24 17:45:50 +0300835 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++)
836 if (sysfs_streq(buf, *s))
837 break;
838
839 if (i == ARRAY_SIZE(dma_op_modes))
840 return -EINVAL;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300841
842 spin_lock_irq(&mcbsp->lock);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300843 if (!mcbsp->free) {
844 size = -EBUSY;
845 goto unlock;
846 }
Jarkko Nikula9b300502009-08-24 17:45:50 +0300847 mcbsp->dma_op_mode = i;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300848
849unlock:
850 spin_unlock_irq(&mcbsp->lock);
851
852 return size;
853}
854
855static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
856
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300857static const struct attribute *additional_attrs[] = {
858 &dev_attr_max_tx_thres.attr,
859 &dev_attr_max_rx_thres.attr,
860 &dev_attr_dma_op_mode.attr,
861 NULL,
862};
863
864static const struct attribute_group additional_attr_group = {
865 .attrs = (struct attribute **)additional_attrs,
866};
867
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000868static ssize_t st_taps_show(struct device *dev,
869 struct device_attribute *attr, char *buf)
870{
871 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
872 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
873 ssize_t status = 0;
874 int i;
875
876 spin_lock_irq(&mcbsp->lock);
877 for (i = 0; i < st_data->nr_taps; i++)
878 status += sprintf(&buf[status], (i ? ", %d" : "%d"),
879 st_data->taps[i]);
880 if (i)
881 status += sprintf(&buf[status], "\n");
882 spin_unlock_irq(&mcbsp->lock);
883
884 return status;
885}
886
887static ssize_t st_taps_store(struct device *dev,
888 struct device_attribute *attr,
889 const char *buf, size_t size)
890{
891 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
892 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
893 int val, tmp, status, i = 0;
894
895 spin_lock_irq(&mcbsp->lock);
896 memset(st_data->taps, 0, sizeof(st_data->taps));
897 st_data->nr_taps = 0;
898
899 do {
900 status = sscanf(buf, "%d%n", &val, &tmp);
901 if (status < 0 || status == 0) {
902 size = -EINVAL;
903 goto out;
904 }
905 if (val < -32768 || val > 32767) {
906 size = -EINVAL;
907 goto out;
908 }
909 st_data->taps[i++] = val;
910 buf += tmp;
911 if (*buf != ',')
912 break;
913 buf++;
914 } while (1);
915
916 st_data->nr_taps = i;
917
918out:
919 spin_unlock_irq(&mcbsp->lock);
920
921 return size;
922}
923
924static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
925
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000926static const struct attribute *sidetone_attrs[] = {
927 &dev_attr_st_taps.attr,
928 NULL,
929};
930
931static const struct attribute_group sidetone_attr_group = {
932 .attrs = (struct attribute **)sidetone_attrs,
933};
934
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300935static int __devinit omap_st_add(struct omap_mcbsp *mcbsp,
936 struct resource *res)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000937{
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000938 struct omap_mcbsp_st_data *st_data;
939 int err;
940
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200941 st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL);
942 if (!st_data)
943 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000944
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200945 st_data->io_base_st = devm_ioremap(mcbsp->dev, res->start,
946 resource_size(res));
947 if (!st_data->io_base_st)
948 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000949
950 err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
951 if (err)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200952 return err;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000953
954 mcbsp->st_data = st_data;
955 return 0;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000956}
957
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100958/*
959 * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
960 * 730 has only 2 McBSP, and both of them are MPU peripherals.
961 */
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200962int __devinit omap_mcbsp_init(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100963{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200964 struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800965 struct resource *res;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300966 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100967
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300968 spin_lock_init(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800969 mcbsp->free = true;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300970
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800971 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
972 if (!res) {
973 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
974 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200975 dev_err(mcbsp->dev, "invalid memory resource\n");
976 return -ENOMEM;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800977 }
978 }
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200979 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
980 dev_name(&pdev->dev))) {
981 dev_err(mcbsp->dev, "memory region already claimed\n");
982 return -ENODEV;
983 }
984
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800985 mcbsp->phys_base = res->start;
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300986 mcbsp->reg_cache_size = resource_size(res);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200987 mcbsp->io_base = devm_ioremap(&pdev->dev, res->start,
988 resource_size(res));
989 if (!mcbsp->io_base)
990 return -ENOMEM;
Russell Kingd592dd12008-09-04 14:25:42 +0100991
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800992 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
993 if (!res)
994 mcbsp->phys_dma_base = mcbsp->phys_base;
995 else
996 mcbsp->phys_dma_base = res->start;
997
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200998 /*
999 * OMAP1, 2 uses two interrupt lines: TX, RX
1000 * OMAP2430, OMAP3 SoC have combined IRQ line as well.
1001 * OMAP4 and newer SoC only have the combined IRQ line.
1002 * Use the combined IRQ if available since it gives better debugging
1003 * possibilities.
1004 */
1005 mcbsp->irq = platform_get_irq_byname(pdev, "common");
1006 if (mcbsp->irq == -ENXIO) {
1007 mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx");
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001008
Peter Ujfalusi35d210f2012-03-19 17:05:39 +02001009 if (mcbsp->tx_irq == -ENXIO) {
1010 mcbsp->irq = platform_get_irq(pdev, 0);
1011 mcbsp->tx_irq = 0;
1012 } else {
1013 mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx");
1014 mcbsp->irq = 0;
1015 }
Peter Ujfalusi73c95222012-03-07 11:15:37 +02001016 }
Kishon Vijay Abraham Icb7e9de2011-02-24 15:16:50 +05301017
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001018 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1019 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001020 dev_err(&pdev->dev, "invalid rx DMA channel\n");
1021 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001022 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001023 /* RX DMA request number, and port address configuration */
1024 mcbsp->dma_data[1].name = "Audio Capture";
1025 mcbsp->dma_data[1].dma_req = res->start;
1026 mcbsp->dma_data[1].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 1);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001027
1028 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1029 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001030 dev_err(&pdev->dev, "invalid tx DMA channel\n");
1031 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001032 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001033 /* TX DMA request number, and port address configuration */
1034 mcbsp->dma_data[0].name = "Audio Playback";
1035 mcbsp->dma_data[0].dma_req = res->start;
1036 mcbsp->dma_data[0].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 0);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001037
Russell Kingb820ce42009-01-23 10:26:46 +00001038 mcbsp->fclk = clk_get(&pdev->dev, "fck");
1039 if (IS_ERR(mcbsp->fclk)) {
1040 ret = PTR_ERR(mcbsp->fclk);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001041 dev_err(mcbsp->dev, "unable to get fck: %d\n", ret);
1042 return ret;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001043 }
1044
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001045 mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
1046 if (mcbsp->pdata->buffer_size) {
1047 /*
1048 * Initially configure the maximum thresholds to a safe value.
1049 * The McBSP FIFO usage with these values should not go under
1050 * 16 locations.
1051 * If the whole FIFO without safety buffer is used, than there
1052 * is a possibility that the DMA will be not able to push the
1053 * new data on time, causing channel shifts in runtime.
1054 */
1055 mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10;
1056 mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10;
1057
1058 ret = sysfs_create_group(&mcbsp->dev->kobj,
1059 &additional_attr_group);
1060 if (ret) {
1061 dev_err(mcbsp->dev,
1062 "Unable to create additional controls\n");
1063 goto err_thres;
1064 }
1065 } else {
1066 mcbsp->max_tx_thres = -EINVAL;
1067 mcbsp->max_rx_thres = -EINVAL;
1068 }
1069
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001070 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone");
1071 if (res) {
1072 ret = omap_st_add(mcbsp, res);
1073 if (ret) {
1074 dev_err(mcbsp->dev,
1075 "Unable to create sidetone controls\n");
1076 goto err_st;
1077 }
1078 }
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +03001079
Russell Kingd592dd12008-09-04 14:25:42 +01001080 return 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001081
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001082err_st:
1083 if (mcbsp->pdata->buffer_size)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001084 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001085err_thres:
1086 clk_put(mcbsp->fclk);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001087 return ret;
1088}
1089
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001090void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001091{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001092 if (mcbsp->pdata->buffer_size)
1093 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001094
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001095 if (mcbsp->st_data)
1096 sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001097}