blob: 34835e8a9160ce16b1d074a1f8495d1124e5eac8 [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>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010027
Tony Lindgrence491cf2009-10-20 09:40:47 -070028#include <plat/mcbsp.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029
Peter Ujfalusi219f4312012-02-03 13:11:47 +020030#include "mcbsp.h"
31
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070032static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030033{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030034 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
35
36 if (mcbsp->pdata->reg_size == 2) {
37 ((u16 *)mcbsp->reg_cache)[reg] = (u16)val;
38 __raw_writew((u16)val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080039 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030040 ((u32 *)mcbsp->reg_cache)[reg] = val;
41 __raw_writel(val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080042 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030043}
44
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070045static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030046{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030047 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
48
49 if (mcbsp->pdata->reg_size == 2) {
50 return !from_cache ? __raw_readw(addr) :
51 ((u16 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080052 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030053 return !from_cache ? __raw_readl(addr) :
54 ((u32 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080055 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030056}
57
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070058static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000059{
60 __raw_writel(val, mcbsp->st_data->io_base_st + reg);
61}
62
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070063static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000064{
65 return __raw_readl(mcbsp->st_data->io_base_st + reg);
66}
Eero Nurkkalad912fa92010-02-22 12:21:11 +000067
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080068#define MCBSP_READ(mcbsp, reg) \
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080069 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080070#define MCBSP_WRITE(mcbsp, reg, val) \
71 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080072#define MCBSP_READ_CACHE(mcbsp, reg) \
73 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030074
Eero Nurkkalad912fa92010-02-22 12:21:11 +000075#define MCBSP_ST_READ(mcbsp, reg) \
76 omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
77#define MCBSP_ST_WRITE(mcbsp, reg, val) \
78 omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
79
Peter Ujfalusi45656b42012-02-14 18:20:58 +020080static void omap_mcbsp_dump_reg(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010081{
Chandra Shekharb4b58f52008-10-08 10:01:39 +030082 dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id);
83 dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080084 MCBSP_READ(mcbsp, DRR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030085 dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080086 MCBSP_READ(mcbsp, DRR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030087 dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080088 MCBSP_READ(mcbsp, DXR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030089 dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080090 MCBSP_READ(mcbsp, DXR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030091 dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080092 MCBSP_READ(mcbsp, SPCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030093 dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080094 MCBSP_READ(mcbsp, SPCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030095 dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080096 MCBSP_READ(mcbsp, RCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030097 dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080098 MCBSP_READ(mcbsp, RCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030099 dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800100 MCBSP_READ(mcbsp, XCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300101 dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800102 MCBSP_READ(mcbsp, XCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300103 dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800104 MCBSP_READ(mcbsp, SRGR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300105 dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800106 MCBSP_READ(mcbsp, SRGR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300107 dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800108 MCBSP_READ(mcbsp, PCR0));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300109 dev_dbg(mcbsp->dev, "***********************\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100110}
111
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200112static irqreturn_t omap_mcbsp_irq_handler(int irq, void *dev_id)
113{
114 struct omap_mcbsp *mcbsp = dev_id;
115 u16 irqst;
116
117 irqst = MCBSP_READ(mcbsp, IRQST);
118 dev_dbg(mcbsp->dev, "IRQ callback : 0x%x\n", irqst);
119
120 if (irqst & RSYNCERREN)
121 dev_err(mcbsp->dev, "RX Frame Sync Error!\n");
122 if (irqst & RFSREN)
123 dev_dbg(mcbsp->dev, "RX Frame Sync\n");
124 if (irqst & REOFEN)
125 dev_dbg(mcbsp->dev, "RX End Of Frame\n");
126 if (irqst & RRDYEN)
127 dev_dbg(mcbsp->dev, "RX Buffer Threshold Reached\n");
128 if (irqst & RUNDFLEN)
129 dev_err(mcbsp->dev, "RX Buffer Underflow!\n");
130 if (irqst & ROVFLEN)
131 dev_err(mcbsp->dev, "RX Buffer Overflow!\n");
132
133 if (irqst & XSYNCERREN)
134 dev_err(mcbsp->dev, "TX Frame Sync Error!\n");
135 if (irqst & XFSXEN)
136 dev_dbg(mcbsp->dev, "TX Frame Sync\n");
137 if (irqst & XEOFEN)
138 dev_dbg(mcbsp->dev, "TX End Of Frame\n");
139 if (irqst & XRDYEN)
140 dev_dbg(mcbsp->dev, "TX Buffer threshold Reached\n");
141 if (irqst & XUNDFLEN)
142 dev_err(mcbsp->dev, "TX Buffer Underflow!\n");
143 if (irqst & XOVFLEN)
144 dev_err(mcbsp->dev, "TX Buffer Overflow!\n");
145 if (irqst & XEMPTYEOFEN)
146 dev_dbg(mcbsp->dev, "TX Buffer empty at end of frame\n");
147
148 MCBSP_WRITE(mcbsp, IRQST, irqst);
149
150 return IRQ_HANDLED;
151}
152
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700153static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100154{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400155 struct omap_mcbsp *mcbsp_tx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700156 u16 irqst_spcr2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100157
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800158 irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700159 dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100160
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700161 if (irqst_spcr2 & XSYNC_ERR) {
162 dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n",
163 irqst_spcr2);
164 /* Writing zero to XSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000165 MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700166 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300167
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100168 return IRQ_HANDLED;
169}
170
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700171static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100172{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400173 struct omap_mcbsp *mcbsp_rx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700174 u16 irqst_spcr1;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100175
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800176 irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700177 dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100178
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700179 if (irqst_spcr1 & RSYNC_ERR) {
180 dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n",
181 irqst_spcr1);
182 /* Writing zero to RSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000183 MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700184 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300185
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100186 return IRQ_HANDLED;
187}
188
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100189/*
190 * omap_mcbsp_config simply write a config to the
191 * appropriate McBSP.
192 * You either call this function or set the McBSP registers
193 * by yourself before calling omap_mcbsp_start().
194 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200195void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
196 const struct omap_mcbsp_reg_cfg *config)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100197{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300198 dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n",
199 mcbsp->id, mcbsp->phys_base);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100200
201 /* We write the given config */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800202 MCBSP_WRITE(mcbsp, SPCR2, config->spcr2);
203 MCBSP_WRITE(mcbsp, SPCR1, config->spcr1);
204 MCBSP_WRITE(mcbsp, RCR2, config->rcr2);
205 MCBSP_WRITE(mcbsp, RCR1, config->rcr1);
206 MCBSP_WRITE(mcbsp, XCR2, config->xcr2);
207 MCBSP_WRITE(mcbsp, XCR1, config->xcr1);
208 MCBSP_WRITE(mcbsp, SRGR2, config->srgr2);
209 MCBSP_WRITE(mcbsp, SRGR1, config->srgr1);
210 MCBSP_WRITE(mcbsp, MCR2, config->mcr2);
211 MCBSP_WRITE(mcbsp, MCR1, config->mcr1);
212 MCBSP_WRITE(mcbsp, PCR0, config->pcr0);
Jarkko Nikula88408232011-09-26 10:45:41 +0300213 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800214 MCBSP_WRITE(mcbsp, XCCR, config->xccr);
215 MCBSP_WRITE(mcbsp, RCCR, config->rccr);
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200216 }
Peter Ujfalusi08905d82012-03-05 11:27:40 +0200217 /* Enable wakeup behavior */
218 if (mcbsp->pdata->has_wakeup)
219 MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200220
221 /* Enable TX/RX sync error interrupts by default */
222 if (mcbsp->irq)
223 MCBSP_WRITE(mcbsp, IRQEN, RSYNCERREN | XSYNCERREN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100224}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530226/**
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530227 * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
228 * @id - mcbsp id
229 * @stream - indicates the direction of data flow (rx or tx)
230 *
231 * Returns the address of mcbsp data transmit register or data receive register
232 * to be used by DMA for transferring/receiving data based on the value of
233 * @stream for the requested mcbsp given by @id
234 */
Peter Ujfalusib8fb4902012-02-14 15:41:29 +0200235static int omap_mcbsp_dma_reg_params(struct omap_mcbsp *mcbsp,
236 unsigned int stream)
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530237{
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530238 int data_reg;
239
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300240 if (mcbsp->pdata->reg_size == 2) {
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530241 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300242 data_reg = OMAP_MCBSP_REG_DRR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530243 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300244 data_reg = OMAP_MCBSP_REG_DXR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530245 } else {
246 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300247 data_reg = OMAP_MCBSP_REG_DRR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530248 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300249 data_reg = OMAP_MCBSP_REG_DXR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530250 }
251
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300252 return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530253}
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530254
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000255static void omap_st_on(struct omap_mcbsp *mcbsp)
256{
257 unsigned int w;
258
Jarkko Nikula1743d142011-09-26 10:45:44 +0300259 if (mcbsp->pdata->enable_st_clock)
260 mcbsp->pdata->enable_st_clock(mcbsp->id, 1);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000261
262 /* Enable McBSP Sidetone */
263 w = MCBSP_READ(mcbsp, SSELCR);
264 MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
265
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000266 /* Enable Sidetone from Sidetone Core */
267 w = MCBSP_ST_READ(mcbsp, SSELCR);
268 MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN);
269}
270
271static void omap_st_off(struct omap_mcbsp *mcbsp)
272{
273 unsigned int w;
274
275 w = MCBSP_ST_READ(mcbsp, SSELCR);
276 MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
277
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000278 w = MCBSP_READ(mcbsp, SSELCR);
279 MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
280
Jarkko Nikula1743d142011-09-26 10:45:44 +0300281 if (mcbsp->pdata->enable_st_clock)
282 mcbsp->pdata->enable_st_clock(mcbsp->id, 0);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000283}
284
285static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
286{
287 u16 val, i;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000288
289 val = MCBSP_ST_READ(mcbsp, SSELCR);
290
291 if (val & ST_COEFFWREN)
292 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
293
294 MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN);
295
296 for (i = 0; i < 128; i++)
297 MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]);
298
299 i = 0;
300
301 val = MCBSP_ST_READ(mcbsp, SSELCR);
302 while (!(val & ST_COEFFWRDONE) && (++i < 1000))
303 val = MCBSP_ST_READ(mcbsp, SSELCR);
304
305 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
306
307 if (i == 1000)
308 dev_err(mcbsp->dev, "McBSP FIR load error!\n");
309}
310
311static void omap_st_chgain(struct omap_mcbsp *mcbsp)
312{
313 u16 w;
314 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000315
316 w = MCBSP_ST_READ(mcbsp, SSELCR);
317
318 MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \
319 ST_CH1GAIN(st_data->ch1gain));
320}
321
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200322int omap_st_set_chgain(struct omap_mcbsp *mcbsp, int channel, s16 chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000323{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200324 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000325 int ret = 0;
326
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000327 if (!st_data)
328 return -ENOENT;
329
330 spin_lock_irq(&mcbsp->lock);
331 if (channel == 0)
332 st_data->ch0gain = chgain;
333 else if (channel == 1)
334 st_data->ch1gain = chgain;
335 else
336 ret = -EINVAL;
337
338 if (st_data->enabled)
339 omap_st_chgain(mcbsp);
340 spin_unlock_irq(&mcbsp->lock);
341
342 return ret;
343}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000344
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200345int omap_st_get_chgain(struct omap_mcbsp *mcbsp, int channel, s16 *chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000346{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200347 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000348 int ret = 0;
349
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000350 if (!st_data)
351 return -ENOENT;
352
353 spin_lock_irq(&mcbsp->lock);
354 if (channel == 0)
355 *chgain = st_data->ch0gain;
356 else if (channel == 1)
357 *chgain = st_data->ch1gain;
358 else
359 ret = -EINVAL;
360 spin_unlock_irq(&mcbsp->lock);
361
362 return ret;
363}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000364
365static int omap_st_start(struct omap_mcbsp *mcbsp)
366{
367 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
368
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200369 if (st_data->enabled && !st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000370 omap_st_fir_write(mcbsp, st_data->taps);
371 omap_st_chgain(mcbsp);
372
373 if (!mcbsp->free) {
374 omap_st_on(mcbsp);
375 st_data->running = 1;
376 }
377 }
378
379 return 0;
380}
381
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200382int omap_st_enable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000383{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200384 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000385
386 if (!st_data)
387 return -ENODEV;
388
389 spin_lock_irq(&mcbsp->lock);
390 st_data->enabled = 1;
391 omap_st_start(mcbsp);
392 spin_unlock_irq(&mcbsp->lock);
393
394 return 0;
395}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000396
397static int omap_st_stop(struct omap_mcbsp *mcbsp)
398{
399 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
400
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200401 if (st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000402 if (!mcbsp->free) {
403 omap_st_off(mcbsp);
404 st_data->running = 0;
405 }
406 }
407
408 return 0;
409}
410
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200411int omap_st_disable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000412{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200413 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000414 int ret = 0;
415
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000416 if (!st_data)
417 return -ENODEV;
418
419 spin_lock_irq(&mcbsp->lock);
420 omap_st_stop(mcbsp);
421 st_data->enabled = 0;
422 spin_unlock_irq(&mcbsp->lock);
423
424 return ret;
425}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000426
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200427int omap_st_is_enabled(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000428{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200429 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000430
431 if (!st_data)
432 return -ENODEV;
433
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000434 return st_data->enabled;
435}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000436
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300437/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300438 * omap_mcbsp_set_rx_threshold configures the transmit threshold in words.
439 * The threshold parameter is 1 based, and it is converted (threshold - 1)
440 * for the THRSH2 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300441 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200442void omap_mcbsp_set_tx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300443{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300444 if (mcbsp->pdata->buffer_size == 0)
445 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300446
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300447 if (threshold && threshold <= mcbsp->max_tx_thres)
448 MCBSP_WRITE(mcbsp, THRSH2, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300449}
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300450
451/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300452 * omap_mcbsp_set_rx_threshold configures the receive threshold in words.
453 * The threshold parameter is 1 based, and it is converted (threshold - 1)
454 * for the THRSH1 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300455 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200456void omap_mcbsp_set_rx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300457{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300458 if (mcbsp->pdata->buffer_size == 0)
459 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300460
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300461 if (threshold && threshold <= mcbsp->max_rx_thres)
462 MCBSP_WRITE(mcbsp, THRSH1, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300463}
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300464
465/*
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200466 * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
467 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200468u16 omap_mcbsp_get_tx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200469{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200470 u16 buffstat;
471
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300472 if (mcbsp->pdata->buffer_size == 0)
473 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200474
475 /* Returns the number of free locations in the buffer */
476 buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
477
478 /* Number of slots are different in McBSP ports */
Peter Ujfalusif10b8ad2010-06-03 07:39:34 +0300479 return mcbsp->pdata->buffer_size - buffstat;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200480}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200481
482/*
483 * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
484 * to reach the threshold value (when the DMA will be triggered to read it)
485 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200486u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200487{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200488 u16 buffstat, threshold;
489
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300490 if (mcbsp->pdata->buffer_size == 0)
491 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200492
493 /* Returns the number of used locations in the buffer */
494 buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
495 /* RX threshold */
496 threshold = MCBSP_READ(mcbsp, THRSH1);
497
498 /* Return the number of location till we reach the threshold limit */
499 if (threshold <= buffstat)
500 return 0;
501 else
502 return threshold - buffstat;
503}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200504
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200505int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100506{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800507 void *reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100508 int err;
509
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300510 reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800511 if (!reg_cache) {
512 return -ENOMEM;
513 }
514
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300515 spin_lock(&mcbsp->lock);
516 if (!mcbsp->free) {
517 dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
518 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800519 err = -EBUSY;
520 goto err_kfree;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100521 }
522
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800523 mcbsp->free = false;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800524 mcbsp->reg_cache = reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300525 spin_unlock(&mcbsp->lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100526
Russell Kingb820ce42009-01-23 10:26:46 +0000527 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200528 mcbsp->pdata->ops->request(mcbsp->id - 1);
Russell Kingb820ce42009-01-23 10:26:46 +0000529
Jarkko Nikula5a070552008-10-08 10:01:41 +0300530 /*
531 * Make sure that transmitter, receiver and sample-rate generator are
532 * not running before activating IRQs.
533 */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800534 MCBSP_WRITE(mcbsp, SPCR1, 0);
535 MCBSP_WRITE(mcbsp, SPCR2, 0);
Jarkko Nikula5a070552008-10-08 10:01:41 +0300536
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200537 if (mcbsp->irq) {
538 err = request_irq(mcbsp->irq, omap_mcbsp_irq_handler, 0,
539 "McBSP", (void *)mcbsp);
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000540 if (err != 0) {
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200541 dev_err(mcbsp->dev, "Unable to request IRQ\n");
542 goto err_clk_disable;
543 }
544 } else {
545 err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, 0,
546 "McBSP TX", (void *)mcbsp);
547 if (err != 0) {
548 dev_err(mcbsp->dev, "Unable to request TX IRQ\n");
549 goto err_clk_disable;
550 }
551
552 err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler, 0,
553 "McBSP RX", (void *)mcbsp);
554 if (err != 0) {
555 dev_err(mcbsp->dev, "Unable to request RX IRQ\n");
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000556 goto err_free_irq;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100557 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100558 }
559
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100560 return 0;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800561err_free_irq:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800562 free_irq(mcbsp->tx_irq, (void *)mcbsp);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800563err_clk_disable:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800564 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200565 mcbsp->pdata->ops->free(mcbsp->id - 1);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800566
Jarkko Nikula1a645882011-09-26 10:45:40 +0300567 /* Disable wakeup behavior */
568 if (mcbsp->pdata->has_wakeup)
569 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800570
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800571 spin_lock(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800572 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800573 mcbsp->reg_cache = NULL;
574err_kfree:
575 spin_unlock(&mcbsp->lock);
576 kfree(reg_cache);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800577
578 return err;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100579}
580
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200581void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100582{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800583 void *reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300584
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300585 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200586 mcbsp->pdata->ops->free(mcbsp->id - 1);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300587
Jarkko Nikula1a645882011-09-26 10:45:40 +0300588 /* Disable wakeup behavior */
589 if (mcbsp->pdata->has_wakeup)
590 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300591
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200592 /* Disable interrupt requests */
593 if (mcbsp->irq)
594 MCBSP_WRITE(mcbsp, IRQEN, 0);
595
596 if (mcbsp->irq) {
597 free_irq(mcbsp->irq, (void *)mcbsp);
598 } else {
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000599 free_irq(mcbsp->rx_irq, (void *)mcbsp);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200600 free_irq(mcbsp->tx_irq, (void *)mcbsp);
601 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100602
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800603 reg_cache = mcbsp->reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100604
Peter Ujfalusie3866152012-03-05 11:32:27 +0200605 /*
606 * Select CLKS source from internal source unconditionally before
607 * marking the McBSP port as free.
608 * If the external clock source via MCBSP_CLKS pin has been selected the
609 * system will refuse to enter idle if the CLKS pin source is not reset
610 * back to internal source.
611 */
612 if (!cpu_class_is_omap1())
613 omap2_mcbsp_set_clks_src(mcbsp, MCBSP_CLKS_PRCM_SRC);
614
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800615 spin_lock(&mcbsp->lock);
616 if (mcbsp->free)
617 dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
618 else
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800619 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800620 mcbsp->reg_cache = NULL;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300621 spin_unlock(&mcbsp->lock);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800622
623 if (reg_cache)
624 kfree(reg_cache);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100625}
626
627/*
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300628 * Here we start the McBSP, by enabling transmitter, receiver or both.
629 * If no transmitter or receiver is active prior calling, then sample-rate
630 * generator and frame sync are started.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100631 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200632void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100633{
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000634 int enable_srg = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100635 u16 w;
636
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300637 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000638 omap_st_start(mcbsp);
639
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000640 /* Only enable SRG, if McBSP is master */
641 w = MCBSP_READ_CACHE(mcbsp, PCR0);
642 if (w & (FSXM | FSRM | CLKXM | CLKRM))
643 enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
644 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300645
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000646 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300647 /* Start the sample generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800648 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800649 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300650 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100651
652 /* Enable transmitter and receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300653 tx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800654 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800655 MCBSP_WRITE(mcbsp, SPCR2, w | tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100656
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300657 rx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800658 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800659 MCBSP_WRITE(mcbsp, SPCR1, w | rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100660
Eduardo Valentin44a63112009-08-20 16:18:09 +0300661 /*
662 * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
663 * REVISIT: 100us may give enough time for two CLKSRG, however
664 * due to some unknown PM related, clock gating etc. reason it
665 * is now at 500us.
666 */
667 udelay(500);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100668
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000669 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300670 /* Start frame sync */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800671 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800672 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300673 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100674
Jarkko Nikula88408232011-09-26 10:45:41 +0300675 if (mcbsp->pdata->has_ccr) {
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300676 /* Release the transmitter and receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800677 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300678 w &= ~(tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800679 MCBSP_WRITE(mcbsp, XCCR, w);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800680 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300681 w &= ~(rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800682 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300683 }
684
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100685 /* Dump McBSP Regs */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200686 omap_mcbsp_dump_reg(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100687}
688
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200689void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100690{
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300691 int idle;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100692 u16 w;
693
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300694 /* Reset transmitter */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300695 tx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300696 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800697 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300698 w |= (tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800699 MCBSP_WRITE(mcbsp, XCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300700 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800701 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800702 MCBSP_WRITE(mcbsp, SPCR2, w & ~tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100703
704 /* Reset receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300705 rx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300706 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800707 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulaa93d4ed2009-10-14 09:56:35 -0700708 w |= (rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800709 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300710 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800711 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800712 MCBSP_WRITE(mcbsp, SPCR1, w & ~rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100713
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800714 idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
715 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300716
717 if (idle) {
718 /* Reset the sample rate generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800719 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800720 MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300721 }
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000722
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300723 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000724 omap_st_stop(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100725}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100726
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200727int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id)
Paul Walmsley69d042d2011-07-01 08:52:25 +0000728{
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300729 const char *src;
Paul Walmsley69d042d2011-07-01 08:52:25 +0000730
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300731 if (fck_src_id == MCBSP_CLKS_PAD_SRC)
732 src = "clks_ext";
733 else if (fck_src_id == MCBSP_CLKS_PRCM_SRC)
734 src = "clks_fclk";
735 else
736 return -EINVAL;
737
738 if (mcbsp->pdata->set_clk_src)
739 return mcbsp->pdata->set_clk_src(mcbsp->dev, mcbsp->fclk, src);
740 else
741 return -EINVAL;
742}
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300743
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200744int omap_mcbsp_6pin_src_mux(struct omap_mcbsp *mcbsp, u8 mux)
Paul Walmsley69d042d2011-07-01 08:52:25 +0000745{
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200746 const char *signal, *src;
Peter Ujfalusi5788c622012-03-08 13:34:16 +0200747
748 if (mcbsp->pdata->mux_signal)
749 return -EINVAL;
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300750
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200751 switch (mux) {
752 case CLKR_SRC_CLKR:
753 signal = "clkr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300754 src = "clkr";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200755 break;
756 case CLKR_SRC_CLKX:
757 signal = "clkr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300758 src = "clkx";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200759 break;
760 case FSR_SRC_FSR:
761 signal = "fsr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300762 src = "fsr";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200763 break;
764 case FSR_SRC_FSX:
765 signal = "fsr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300766 src = "fsx";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200767 break;
768 default:
769 return -EINVAL;
770 }
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300771
Peter Ujfalusi5788c622012-03-08 13:34:16 +0200772 return mcbsp->pdata->mux_signal(mcbsp->dev, signal, src);
Paul Walmsley69d042d2011-07-01 08:52:25 +0000773}
Paul Walmsley69d042d2011-07-01 08:52:25 +0000774
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300775#define max_thres(m) (mcbsp->pdata->buffer_size)
776#define valid_threshold(m, val) ((val) <= max_thres(m))
777#define THRESHOLD_PROP_BUILDER(prop) \
778static ssize_t prop##_show(struct device *dev, \
779 struct device_attribute *attr, char *buf) \
780{ \
781 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
782 \
783 return sprintf(buf, "%u\n", mcbsp->prop); \
784} \
785 \
786static ssize_t prop##_store(struct device *dev, \
787 struct device_attribute *attr, \
788 const char *buf, size_t size) \
789{ \
790 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
791 unsigned long val; \
792 int status; \
793 \
794 status = strict_strtoul(buf, 0, &val); \
795 if (status) \
796 return status; \
797 \
798 if (!valid_threshold(mcbsp, val)) \
799 return -EDOM; \
800 \
801 mcbsp->prop = val; \
802 return size; \
803} \
804 \
805static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
806
807THRESHOLD_PROP_BUILDER(max_tx_thres);
808THRESHOLD_PROP_BUILDER(max_rx_thres);
809
Jarkko Nikula9b300502009-08-24 17:45:50 +0300810static const char *dma_op_modes[] = {
Peter Ujfalusi09fa37a2012-03-15 12:29:49 +0200811 "element", "threshold",
Jarkko Nikula9b300502009-08-24 17:45:50 +0300812};
813
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300814static ssize_t dma_op_mode_show(struct device *dev,
815 struct device_attribute *attr, char *buf)
816{
817 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300818 int dma_op_mode, i = 0;
819 ssize_t len = 0;
820 const char * const *s;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300821
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300822 dma_op_mode = mcbsp->dma_op_mode;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300823
Jarkko Nikula9b300502009-08-24 17:45:50 +0300824 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
825 if (dma_op_mode == i)
826 len += sprintf(buf + len, "[%s] ", *s);
827 else
828 len += sprintf(buf + len, "%s ", *s);
829 }
830 len += sprintf(buf + len, "\n");
831
832 return len;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300833}
834
835static ssize_t dma_op_mode_store(struct device *dev,
836 struct device_attribute *attr,
837 const char *buf, size_t size)
838{
839 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300840 const char * const *s;
841 int i = 0;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300842
Jarkko Nikula9b300502009-08-24 17:45:50 +0300843 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++)
844 if (sysfs_streq(buf, *s))
845 break;
846
847 if (i == ARRAY_SIZE(dma_op_modes))
848 return -EINVAL;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300849
850 spin_lock_irq(&mcbsp->lock);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300851 if (!mcbsp->free) {
852 size = -EBUSY;
853 goto unlock;
854 }
Jarkko Nikula9b300502009-08-24 17:45:50 +0300855 mcbsp->dma_op_mode = i;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300856
857unlock:
858 spin_unlock_irq(&mcbsp->lock);
859
860 return size;
861}
862
863static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
864
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300865static const struct attribute *additional_attrs[] = {
866 &dev_attr_max_tx_thres.attr,
867 &dev_attr_max_rx_thres.attr,
868 &dev_attr_dma_op_mode.attr,
869 NULL,
870};
871
872static const struct attribute_group additional_attr_group = {
873 .attrs = (struct attribute **)additional_attrs,
874};
875
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000876static ssize_t st_taps_show(struct device *dev,
877 struct device_attribute *attr, char *buf)
878{
879 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
880 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
881 ssize_t status = 0;
882 int i;
883
884 spin_lock_irq(&mcbsp->lock);
885 for (i = 0; i < st_data->nr_taps; i++)
886 status += sprintf(&buf[status], (i ? ", %d" : "%d"),
887 st_data->taps[i]);
888 if (i)
889 status += sprintf(&buf[status], "\n");
890 spin_unlock_irq(&mcbsp->lock);
891
892 return status;
893}
894
895static ssize_t st_taps_store(struct device *dev,
896 struct device_attribute *attr,
897 const char *buf, size_t size)
898{
899 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
900 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
901 int val, tmp, status, i = 0;
902
903 spin_lock_irq(&mcbsp->lock);
904 memset(st_data->taps, 0, sizeof(st_data->taps));
905 st_data->nr_taps = 0;
906
907 do {
908 status = sscanf(buf, "%d%n", &val, &tmp);
909 if (status < 0 || status == 0) {
910 size = -EINVAL;
911 goto out;
912 }
913 if (val < -32768 || val > 32767) {
914 size = -EINVAL;
915 goto out;
916 }
917 st_data->taps[i++] = val;
918 buf += tmp;
919 if (*buf != ',')
920 break;
921 buf++;
922 } while (1);
923
924 st_data->nr_taps = i;
925
926out:
927 spin_unlock_irq(&mcbsp->lock);
928
929 return size;
930}
931
932static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
933
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000934static const struct attribute *sidetone_attrs[] = {
935 &dev_attr_st_taps.attr,
936 NULL,
937};
938
939static const struct attribute_group sidetone_attr_group = {
940 .attrs = (struct attribute **)sidetone_attrs,
941};
942
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300943static int __devinit omap_st_add(struct omap_mcbsp *mcbsp,
944 struct resource *res)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000945{
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000946 struct omap_mcbsp_st_data *st_data;
947 int err;
948
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200949 st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL);
950 if (!st_data)
951 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000952
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200953 st_data->io_base_st = devm_ioremap(mcbsp->dev, res->start,
954 resource_size(res));
955 if (!st_data->io_base_st)
956 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000957
958 err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
959 if (err)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200960 return err;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000961
962 mcbsp->st_data = st_data;
963 return 0;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000964}
965
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100966/*
967 * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
968 * 730 has only 2 McBSP, and both of them are MPU peripherals.
969 */
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200970int __devinit omap_mcbsp_init(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100971{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200972 struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800973 struct resource *res;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300974 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100975
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300976 spin_lock_init(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800977 mcbsp->free = true;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300978
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800979 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
980 if (!res) {
981 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
982 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200983 dev_err(mcbsp->dev, "invalid memory resource\n");
984 return -ENOMEM;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800985 }
986 }
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200987 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
988 dev_name(&pdev->dev))) {
989 dev_err(mcbsp->dev, "memory region already claimed\n");
990 return -ENODEV;
991 }
992
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800993 mcbsp->phys_base = res->start;
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300994 mcbsp->reg_cache_size = resource_size(res);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200995 mcbsp->io_base = devm_ioremap(&pdev->dev, res->start,
996 resource_size(res));
997 if (!mcbsp->io_base)
998 return -ENOMEM;
Russell Kingd592dd12008-09-04 14:25:42 +0100999
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001000 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
1001 if (!res)
1002 mcbsp->phys_dma_base = mcbsp->phys_base;
1003 else
1004 mcbsp->phys_dma_base = res->start;
1005
Peter Ujfalusi35d210f2012-03-19 17:05:39 +02001006 /*
1007 * OMAP1, 2 uses two interrupt lines: TX, RX
1008 * OMAP2430, OMAP3 SoC have combined IRQ line as well.
1009 * OMAP4 and newer SoC only have the combined IRQ line.
1010 * Use the combined IRQ if available since it gives better debugging
1011 * possibilities.
1012 */
1013 mcbsp->irq = platform_get_irq_byname(pdev, "common");
1014 if (mcbsp->irq == -ENXIO) {
1015 mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx");
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001016
Peter Ujfalusi35d210f2012-03-19 17:05:39 +02001017 if (mcbsp->tx_irq == -ENXIO) {
1018 mcbsp->irq = platform_get_irq(pdev, 0);
1019 mcbsp->tx_irq = 0;
1020 } else {
1021 mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx");
1022 mcbsp->irq = 0;
1023 }
Peter Ujfalusi73c95222012-03-07 11:15:37 +02001024 }
Kishon Vijay Abraham Icb7e9de2011-02-24 15:16:50 +05301025
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001026 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1027 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001028 dev_err(&pdev->dev, "invalid rx DMA channel\n");
1029 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001030 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001031 /* RX DMA request number, and port address configuration */
1032 mcbsp->dma_data[1].name = "Audio Capture";
1033 mcbsp->dma_data[1].dma_req = res->start;
1034 mcbsp->dma_data[1].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 1);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001035
1036 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1037 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001038 dev_err(&pdev->dev, "invalid tx DMA channel\n");
1039 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001040 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001041 /* TX DMA request number, and port address configuration */
1042 mcbsp->dma_data[0].name = "Audio Playback";
1043 mcbsp->dma_data[0].dma_req = res->start;
1044 mcbsp->dma_data[0].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 0);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001045
Russell Kingb820ce42009-01-23 10:26:46 +00001046 mcbsp->fclk = clk_get(&pdev->dev, "fck");
1047 if (IS_ERR(mcbsp->fclk)) {
1048 ret = PTR_ERR(mcbsp->fclk);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001049 dev_err(mcbsp->dev, "unable to get fck: %d\n", ret);
1050 return ret;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001051 }
1052
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001053 mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
1054 if (mcbsp->pdata->buffer_size) {
1055 /*
1056 * Initially configure the maximum thresholds to a safe value.
1057 * The McBSP FIFO usage with these values should not go under
1058 * 16 locations.
1059 * If the whole FIFO without safety buffer is used, than there
1060 * is a possibility that the DMA will be not able to push the
1061 * new data on time, causing channel shifts in runtime.
1062 */
1063 mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10;
1064 mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10;
1065
1066 ret = sysfs_create_group(&mcbsp->dev->kobj,
1067 &additional_attr_group);
1068 if (ret) {
1069 dev_err(mcbsp->dev,
1070 "Unable to create additional controls\n");
1071 goto err_thres;
1072 }
1073 } else {
1074 mcbsp->max_tx_thres = -EINVAL;
1075 mcbsp->max_rx_thres = -EINVAL;
1076 }
1077
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001078 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone");
1079 if (res) {
1080 ret = omap_st_add(mcbsp, res);
1081 if (ret) {
1082 dev_err(mcbsp->dev,
1083 "Unable to create sidetone controls\n");
1084 goto err_st;
1085 }
1086 }
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +03001087
Russell Kingd592dd12008-09-04 14:25:42 +01001088 return 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001089
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001090err_st:
1091 if (mcbsp->pdata->buffer_size)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001092 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001093err_thres:
1094 clk_put(mcbsp->fclk);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001095 return ret;
1096}
1097
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001098void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001099{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001100 if (mcbsp->pdata->buffer_size)
1101 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001102
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001103 if (mcbsp->st_data)
1104 sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001105}