blob: 6afbc26cef70b27ee596a28d1d274ab56a34841b [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
Tony Lindgrence491cf2009-10-20 09:40:47 -070029#include <plat/mcbsp.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010030
Peter Ujfalusi219f4312012-02-03 13:11:47 +020031#include "mcbsp.h"
32
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070033static void omap_mcbsp_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030034{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030035 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
36
37 if (mcbsp->pdata->reg_size == 2) {
38 ((u16 *)mcbsp->reg_cache)[reg] = (u16)val;
39 __raw_writew((u16)val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080040 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030041 ((u32 *)mcbsp->reg_cache)[reg] = val;
42 __raw_writel(val, addr);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080043 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030044}
45
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070046static int omap_mcbsp_read(struct omap_mcbsp *mcbsp, u16 reg, bool from_cache)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030047{
Jarkko Nikulacdc715142011-09-26 10:45:39 +030048 void __iomem *addr = mcbsp->io_base + reg * mcbsp->pdata->reg_step;
49
50 if (mcbsp->pdata->reg_size == 2) {
51 return !from_cache ? __raw_readw(addr) :
52 ((u16 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080053 } else {
Jarkko Nikulacdc715142011-09-26 10:45:39 +030054 return !from_cache ? __raw_readl(addr) :
55 ((u32 *)mcbsp->reg_cache)[reg];
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080056 }
Chandra Shekharb4b58f52008-10-08 10:01:39 +030057}
58
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070059static void omap_mcbsp_st_write(struct omap_mcbsp *mcbsp, u16 reg, u32 val)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000060{
61 __raw_writel(val, mcbsp->st_data->io_base_st + reg);
62}
63
Manjunath Kondaiah Gb0a330d2010-10-08 10:00:19 -070064static int omap_mcbsp_st_read(struct omap_mcbsp *mcbsp, u16 reg)
Eero Nurkkalad912fa92010-02-22 12:21:11 +000065{
66 return __raw_readl(mcbsp->st_data->io_base_st + reg);
67}
Eero Nurkkalad912fa92010-02-22 12:21:11 +000068
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080069#define MCBSP_READ(mcbsp, reg) \
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080070 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 0)
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080071#define MCBSP_WRITE(mcbsp, reg, val) \
72 omap_mcbsp_write(mcbsp, OMAP_MCBSP_REG_##reg, val)
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -080073#define MCBSP_READ_CACHE(mcbsp, reg) \
74 omap_mcbsp_read(mcbsp, OMAP_MCBSP_REG_##reg, 1)
Chandra Shekharb4b58f52008-10-08 10:01:39 +030075
Eero Nurkkalad912fa92010-02-22 12:21:11 +000076#define MCBSP_ST_READ(mcbsp, reg) \
77 omap_mcbsp_st_read(mcbsp, OMAP_ST_REG_##reg)
78#define MCBSP_ST_WRITE(mcbsp, reg, val) \
79 omap_mcbsp_st_write(mcbsp, OMAP_ST_REG_##reg, val)
80
Peter Ujfalusi45656b42012-02-14 18:20:58 +020081static void omap_mcbsp_dump_reg(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010082{
Chandra Shekharb4b58f52008-10-08 10:01:39 +030083 dev_dbg(mcbsp->dev, "**** McBSP%d regs ****\n", mcbsp->id);
84 dev_dbg(mcbsp->dev, "DRR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080085 MCBSP_READ(mcbsp, DRR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030086 dev_dbg(mcbsp->dev, "DRR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080087 MCBSP_READ(mcbsp, DRR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030088 dev_dbg(mcbsp->dev, "DXR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080089 MCBSP_READ(mcbsp, DXR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030090 dev_dbg(mcbsp->dev, "DXR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080091 MCBSP_READ(mcbsp, DXR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030092 dev_dbg(mcbsp->dev, "SPCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080093 MCBSP_READ(mcbsp, SPCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030094 dev_dbg(mcbsp->dev, "SPCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080095 MCBSP_READ(mcbsp, SPCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030096 dev_dbg(mcbsp->dev, "RCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080097 MCBSP_READ(mcbsp, RCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +030098 dev_dbg(mcbsp->dev, "RCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -080099 MCBSP_READ(mcbsp, RCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300100 dev_dbg(mcbsp->dev, "XCR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800101 MCBSP_READ(mcbsp, XCR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300102 dev_dbg(mcbsp->dev, "XCR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800103 MCBSP_READ(mcbsp, XCR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300104 dev_dbg(mcbsp->dev, "SRGR2: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800105 MCBSP_READ(mcbsp, SRGR2));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300106 dev_dbg(mcbsp->dev, "SRGR1: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800107 MCBSP_READ(mcbsp, SRGR1));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300108 dev_dbg(mcbsp->dev, "PCR0: 0x%04x\n",
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800109 MCBSP_READ(mcbsp, PCR0));
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300110 dev_dbg(mcbsp->dev, "***********************\n");
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100111}
112
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200113static irqreturn_t omap_mcbsp_irq_handler(int irq, void *dev_id)
114{
115 struct omap_mcbsp *mcbsp = dev_id;
116 u16 irqst;
117
118 irqst = MCBSP_READ(mcbsp, IRQST);
119 dev_dbg(mcbsp->dev, "IRQ callback : 0x%x\n", irqst);
120
121 if (irqst & RSYNCERREN)
122 dev_err(mcbsp->dev, "RX Frame Sync Error!\n");
123 if (irqst & RFSREN)
124 dev_dbg(mcbsp->dev, "RX Frame Sync\n");
125 if (irqst & REOFEN)
126 dev_dbg(mcbsp->dev, "RX End Of Frame\n");
127 if (irqst & RRDYEN)
128 dev_dbg(mcbsp->dev, "RX Buffer Threshold Reached\n");
129 if (irqst & RUNDFLEN)
130 dev_err(mcbsp->dev, "RX Buffer Underflow!\n");
131 if (irqst & ROVFLEN)
132 dev_err(mcbsp->dev, "RX Buffer Overflow!\n");
133
134 if (irqst & XSYNCERREN)
135 dev_err(mcbsp->dev, "TX Frame Sync Error!\n");
136 if (irqst & XFSXEN)
137 dev_dbg(mcbsp->dev, "TX Frame Sync\n");
138 if (irqst & XEOFEN)
139 dev_dbg(mcbsp->dev, "TX End Of Frame\n");
140 if (irqst & XRDYEN)
141 dev_dbg(mcbsp->dev, "TX Buffer threshold Reached\n");
142 if (irqst & XUNDFLEN)
143 dev_err(mcbsp->dev, "TX Buffer Underflow!\n");
144 if (irqst & XOVFLEN)
145 dev_err(mcbsp->dev, "TX Buffer Overflow!\n");
146 if (irqst & XEMPTYEOFEN)
147 dev_dbg(mcbsp->dev, "TX Buffer empty at end of frame\n");
148
149 MCBSP_WRITE(mcbsp, IRQST, irqst);
150
151 return IRQ_HANDLED;
152}
153
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700154static irqreturn_t omap_mcbsp_tx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100155{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400156 struct omap_mcbsp *mcbsp_tx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700157 u16 irqst_spcr2;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100158
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800159 irqst_spcr2 = MCBSP_READ(mcbsp_tx, SPCR2);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700160 dev_dbg(mcbsp_tx->dev, "TX IRQ callback : 0x%x\n", irqst_spcr2);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100161
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700162 if (irqst_spcr2 & XSYNC_ERR) {
163 dev_err(mcbsp_tx->dev, "TX Frame Sync Error! : 0x%x\n",
164 irqst_spcr2);
165 /* Writing zero to XSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000166 MCBSP_WRITE(mcbsp_tx, SPCR2, MCBSP_READ_CACHE(mcbsp_tx, SPCR2));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700167 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300168
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100169 return IRQ_HANDLED;
170}
171
Linus Torvalds0cd61b62006-10-06 10:53:39 -0700172static irqreturn_t omap_mcbsp_rx_irq_handler(int irq, void *dev_id)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100173{
Jeff Garzike8f2af12007-10-26 05:40:25 -0400174 struct omap_mcbsp *mcbsp_rx = dev_id;
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700175 u16 irqst_spcr1;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100176
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800177 irqst_spcr1 = MCBSP_READ(mcbsp_rx, SPCR1);
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700178 dev_dbg(mcbsp_rx->dev, "RX IRQ callback : 0x%x\n", irqst_spcr1);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100179
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700180 if (irqst_spcr1 & RSYNC_ERR) {
181 dev_err(mcbsp_rx->dev, "RX Frame Sync Error! : 0x%x\n",
182 irqst_spcr1);
183 /* Writing zero to RSYNC_ERR clears the IRQ */
Janusz Krzysztofik0841cb82010-02-23 15:50:38 +0000184 MCBSP_WRITE(mcbsp_rx, SPCR1, MCBSP_READ_CACHE(mcbsp_rx, SPCR1));
Eero Nurkkalad6d834b2009-05-25 11:08:42 -0700185 }
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300186
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100187 return IRQ_HANDLED;
188}
189
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100190/*
191 * omap_mcbsp_config simply write a config to the
192 * appropriate McBSP.
193 * You either call this function or set the McBSP registers
194 * by yourself before calling omap_mcbsp_start().
195 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200196void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
197 const struct omap_mcbsp_reg_cfg *config)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100198{
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300199 dev_dbg(mcbsp->dev, "Configuring McBSP%d phys_base: 0x%08lx\n",
200 mcbsp->id, mcbsp->phys_base);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100201
202 /* We write the given config */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800203 MCBSP_WRITE(mcbsp, SPCR2, config->spcr2);
204 MCBSP_WRITE(mcbsp, SPCR1, config->spcr1);
205 MCBSP_WRITE(mcbsp, RCR2, config->rcr2);
206 MCBSP_WRITE(mcbsp, RCR1, config->rcr1);
207 MCBSP_WRITE(mcbsp, XCR2, config->xcr2);
208 MCBSP_WRITE(mcbsp, XCR1, config->xcr1);
209 MCBSP_WRITE(mcbsp, SRGR2, config->srgr2);
210 MCBSP_WRITE(mcbsp, SRGR1, config->srgr1);
211 MCBSP_WRITE(mcbsp, MCR2, config->mcr2);
212 MCBSP_WRITE(mcbsp, MCR1, config->mcr1);
213 MCBSP_WRITE(mcbsp, PCR0, config->pcr0);
Jarkko Nikula88408232011-09-26 10:45:41 +0300214 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800215 MCBSP_WRITE(mcbsp, XCCR, config->xccr);
216 MCBSP_WRITE(mcbsp, RCCR, config->rccr);
Tony Lindgren3127f8f2009-01-15 13:09:54 +0200217 }
Peter Ujfalusi08905d82012-03-05 11:27:40 +0200218 /* Enable wakeup behavior */
219 if (mcbsp->pdata->has_wakeup)
220 MCBSP_WRITE(mcbsp, WAKEUPEN, XRDYEN | RRDYEN);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200221
222 /* Enable TX/RX sync error interrupts by default */
223 if (mcbsp->irq)
224 MCBSP_WRITE(mcbsp, IRQEN, RSYNCERREN | XSYNCERREN);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100225}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100226
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530227/**
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530228 * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
229 * @id - mcbsp id
230 * @stream - indicates the direction of data flow (rx or tx)
231 *
232 * Returns the address of mcbsp data transmit register or data receive register
233 * to be used by DMA for transferring/receiving data based on the value of
234 * @stream for the requested mcbsp given by @id
235 */
Peter Ujfalusib8fb4902012-02-14 15:41:29 +0200236static int omap_mcbsp_dma_reg_params(struct omap_mcbsp *mcbsp,
237 unsigned int stream)
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530238{
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530239 int data_reg;
240
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300241 if (mcbsp->pdata->reg_size == 2) {
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530242 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300243 data_reg = OMAP_MCBSP_REG_DRR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530244 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300245 data_reg = OMAP_MCBSP_REG_DXR1;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530246 } else {
247 if (stream)
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300248 data_reg = OMAP_MCBSP_REG_DRR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530249 else
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300250 data_reg = OMAP_MCBSP_REG_DXR;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530251 }
252
Jarkko Nikulacdc715142011-09-26 10:45:39 +0300253 return mcbsp->phys_dma_base + data_reg * mcbsp->pdata->reg_step;
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530254}
Kishon Vijay Abraham I9504ba62011-02-24 15:16:55 +0530255
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000256static void omap_st_on(struct omap_mcbsp *mcbsp)
257{
258 unsigned int w;
259
Jarkko Nikula1743d142011-09-26 10:45:44 +0300260 if (mcbsp->pdata->enable_st_clock)
261 mcbsp->pdata->enable_st_clock(mcbsp->id, 1);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000262
263 /* Enable McBSP Sidetone */
264 w = MCBSP_READ(mcbsp, SSELCR);
265 MCBSP_WRITE(mcbsp, SSELCR, w | SIDETONEEN);
266
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000267 /* Enable Sidetone from Sidetone Core */
268 w = MCBSP_ST_READ(mcbsp, SSELCR);
269 MCBSP_ST_WRITE(mcbsp, SSELCR, w | ST_SIDETONEEN);
270}
271
272static void omap_st_off(struct omap_mcbsp *mcbsp)
273{
274 unsigned int w;
275
276 w = MCBSP_ST_READ(mcbsp, SSELCR);
277 MCBSP_ST_WRITE(mcbsp, SSELCR, w & ~(ST_SIDETONEEN));
278
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000279 w = MCBSP_READ(mcbsp, SSELCR);
280 MCBSP_WRITE(mcbsp, SSELCR, w & ~(SIDETONEEN));
281
Jarkko Nikula1743d142011-09-26 10:45:44 +0300282 if (mcbsp->pdata->enable_st_clock)
283 mcbsp->pdata->enable_st_clock(mcbsp->id, 0);
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000284}
285
286static void omap_st_fir_write(struct omap_mcbsp *mcbsp, s16 *fir)
287{
288 u16 val, i;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000289
290 val = MCBSP_ST_READ(mcbsp, SSELCR);
291
292 if (val & ST_COEFFWREN)
293 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
294
295 MCBSP_ST_WRITE(mcbsp, SSELCR, val | ST_COEFFWREN);
296
297 for (i = 0; i < 128; i++)
298 MCBSP_ST_WRITE(mcbsp, SFIRCR, fir[i]);
299
300 i = 0;
301
302 val = MCBSP_ST_READ(mcbsp, SSELCR);
303 while (!(val & ST_COEFFWRDONE) && (++i < 1000))
304 val = MCBSP_ST_READ(mcbsp, SSELCR);
305
306 MCBSP_ST_WRITE(mcbsp, SSELCR, val & ~(ST_COEFFWREN));
307
308 if (i == 1000)
309 dev_err(mcbsp->dev, "McBSP FIR load error!\n");
310}
311
312static void omap_st_chgain(struct omap_mcbsp *mcbsp)
313{
314 u16 w;
315 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000316
317 w = MCBSP_ST_READ(mcbsp, SSELCR);
318
319 MCBSP_ST_WRITE(mcbsp, SGAINCR, ST_CH0GAIN(st_data->ch0gain) | \
320 ST_CH1GAIN(st_data->ch1gain));
321}
322
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200323int omap_st_set_chgain(struct omap_mcbsp *mcbsp, int channel, s16 chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000324{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200325 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000326 int ret = 0;
327
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000328 if (!st_data)
329 return -ENOENT;
330
331 spin_lock_irq(&mcbsp->lock);
332 if (channel == 0)
333 st_data->ch0gain = chgain;
334 else if (channel == 1)
335 st_data->ch1gain = chgain;
336 else
337 ret = -EINVAL;
338
339 if (st_data->enabled)
340 omap_st_chgain(mcbsp);
341 spin_unlock_irq(&mcbsp->lock);
342
343 return ret;
344}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000345
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200346int omap_st_get_chgain(struct omap_mcbsp *mcbsp, int channel, s16 *chgain)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000347{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200348 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000349 int ret = 0;
350
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000351 if (!st_data)
352 return -ENOENT;
353
354 spin_lock_irq(&mcbsp->lock);
355 if (channel == 0)
356 *chgain = st_data->ch0gain;
357 else if (channel == 1)
358 *chgain = st_data->ch1gain;
359 else
360 ret = -EINVAL;
361 spin_unlock_irq(&mcbsp->lock);
362
363 return ret;
364}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000365
366static int omap_st_start(struct omap_mcbsp *mcbsp)
367{
368 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
369
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200370 if (st_data->enabled && !st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000371 omap_st_fir_write(mcbsp, st_data->taps);
372 omap_st_chgain(mcbsp);
373
374 if (!mcbsp->free) {
375 omap_st_on(mcbsp);
376 st_data->running = 1;
377 }
378 }
379
380 return 0;
381}
382
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200383int omap_st_enable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000384{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200385 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000386
387 if (!st_data)
388 return -ENODEV;
389
390 spin_lock_irq(&mcbsp->lock);
391 st_data->enabled = 1;
392 omap_st_start(mcbsp);
393 spin_unlock_irq(&mcbsp->lock);
394
395 return 0;
396}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000397
398static int omap_st_stop(struct omap_mcbsp *mcbsp)
399{
400 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
401
Peter Ujfalusi58db1dc2012-02-23 15:40:55 +0200402 if (st_data->running) {
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000403 if (!mcbsp->free) {
404 omap_st_off(mcbsp);
405 st_data->running = 0;
406 }
407 }
408
409 return 0;
410}
411
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200412int omap_st_disable(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000413{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200414 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000415 int ret = 0;
416
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000417 if (!st_data)
418 return -ENODEV;
419
420 spin_lock_irq(&mcbsp->lock);
421 omap_st_stop(mcbsp);
422 st_data->enabled = 0;
423 spin_unlock_irq(&mcbsp->lock);
424
425 return ret;
426}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000427
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200428int omap_st_is_enabled(struct omap_mcbsp *mcbsp)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000429{
Peter Ujfalusie2002ab2012-02-23 15:38:37 +0200430 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000431
432 if (!st_data)
433 return -ENODEV;
434
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000435 return st_data->enabled;
436}
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000437
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300438/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300439 * omap_mcbsp_set_rx_threshold configures the transmit threshold in words.
440 * The threshold parameter is 1 based, and it is converted (threshold - 1)
441 * for the THRSH2 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300442 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200443void omap_mcbsp_set_tx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300444{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300445 if (mcbsp->pdata->buffer_size == 0)
446 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300447
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300448 if (threshold && threshold <= mcbsp->max_tx_thres)
449 MCBSP_WRITE(mcbsp, THRSH2, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300450}
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300451
452/*
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300453 * omap_mcbsp_set_rx_threshold configures the receive threshold in words.
454 * The threshold parameter is 1 based, and it is converted (threshold - 1)
455 * for the THRSH1 register.
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300456 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200457void omap_mcbsp_set_rx_threshold(struct omap_mcbsp *mcbsp, u16 threshold)
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300458{
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300459 if (mcbsp->pdata->buffer_size == 0)
460 return;
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300461
Peter Ujfalusi451fd822010-06-03 07:39:33 +0300462 if (threshold && threshold <= mcbsp->max_rx_thres)
463 MCBSP_WRITE(mcbsp, THRSH1, threshold - 1);
Eduardo Valentin7aa9ff52009-08-20 16:18:10 +0300464}
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300465
466/*
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200467 * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
468 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200469u16 omap_mcbsp_get_tx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200470{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200471 u16 buffstat;
472
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300473 if (mcbsp->pdata->buffer_size == 0)
474 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200475
476 /* Returns the number of free locations in the buffer */
477 buffstat = MCBSP_READ(mcbsp, XBUFFSTAT);
478
479 /* Number of slots are different in McBSP ports */
Peter Ujfalusif10b8ad2010-06-03 07:39:34 +0300480 return mcbsp->pdata->buffer_size - buffstat;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200481}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200482
483/*
484 * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
485 * to reach the threshold value (when the DMA will be triggered to read it)
486 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200487u16 omap_mcbsp_get_rx_delay(struct omap_mcbsp *mcbsp)
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200488{
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200489 u16 buffstat, threshold;
490
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300491 if (mcbsp->pdata->buffer_size == 0)
492 return 0;
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200493
494 /* Returns the number of used locations in the buffer */
495 buffstat = MCBSP_READ(mcbsp, RBUFFSTAT);
496 /* RX threshold */
497 threshold = MCBSP_READ(mcbsp, THRSH1);
498
499 /* Return the number of location till we reach the threshold limit */
500 if (threshold <= buffstat)
501 return 0;
502 else
503 return threshold - buffstat;
504}
Peter Ujfalusi7dc976e2010-03-03 15:08:08 +0200505
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200506int omap_mcbsp_request(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100507{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800508 void *reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100509 int err;
510
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +0300511 reg_cache = kzalloc(mcbsp->reg_cache_size, GFP_KERNEL);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800512 if (!reg_cache) {
513 return -ENOMEM;
514 }
515
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300516 spin_lock(&mcbsp->lock);
517 if (!mcbsp->free) {
518 dev_err(mcbsp->dev, "McBSP%d is currently in use\n",
519 mcbsp->id);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800520 err = -EBUSY;
521 goto err_kfree;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100522 }
523
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800524 mcbsp->free = false;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800525 mcbsp->reg_cache = reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300526 spin_unlock(&mcbsp->lock);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100527
Russell Kingb820ce42009-01-23 10:26:46 +0000528 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->request)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200529 mcbsp->pdata->ops->request(mcbsp->id - 1);
Russell Kingb820ce42009-01-23 10:26:46 +0000530
Jarkko Nikula5a070552008-10-08 10:01:41 +0300531 /*
532 * Make sure that transmitter, receiver and sample-rate generator are
533 * not running before activating IRQs.
534 */
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800535 MCBSP_WRITE(mcbsp, SPCR1, 0);
536 MCBSP_WRITE(mcbsp, SPCR2, 0);
Jarkko Nikula5a070552008-10-08 10:01:41 +0300537
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200538 if (mcbsp->irq) {
539 err = request_irq(mcbsp->irq, omap_mcbsp_irq_handler, 0,
540 "McBSP", (void *)mcbsp);
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000541 if (err != 0) {
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200542 dev_err(mcbsp->dev, "Unable to request IRQ\n");
543 goto err_clk_disable;
544 }
545 } else {
546 err = request_irq(mcbsp->tx_irq, omap_mcbsp_tx_irq_handler, 0,
547 "McBSP TX", (void *)mcbsp);
548 if (err != 0) {
549 dev_err(mcbsp->dev, "Unable to request TX IRQ\n");
550 goto err_clk_disable;
551 }
552
553 err = request_irq(mcbsp->rx_irq, omap_mcbsp_rx_irq_handler, 0,
554 "McBSP RX", (void *)mcbsp);
555 if (err != 0) {
556 dev_err(mcbsp->dev, "Unable to request RX IRQ\n");
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000557 goto err_free_irq;
Tony Lindgren120db2c2006-04-02 17:46:27 +0100558 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100559 }
560
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100561 return 0;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800562err_free_irq:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800563 free_irq(mcbsp->tx_irq, (void *)mcbsp);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800564err_clk_disable:
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800565 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200566 mcbsp->pdata->ops->free(mcbsp->id - 1);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800567
Jarkko Nikula1a645882011-09-26 10:45:40 +0300568 /* Disable wakeup behavior */
569 if (mcbsp->pdata->has_wakeup)
570 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800571
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800572 spin_lock(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800573 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800574 mcbsp->reg_cache = NULL;
575err_kfree:
576 spin_unlock(&mcbsp->lock);
577 kfree(reg_cache);
Janusz Krzysztofik1866b542010-01-08 10:29:04 -0800578
579 return err;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100580}
581
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200582void omap_mcbsp_free(struct omap_mcbsp *mcbsp)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100583{
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800584 void *reg_cache;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300585
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300586 if (mcbsp->pdata && mcbsp->pdata->ops && mcbsp->pdata->ops->free)
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200587 mcbsp->pdata->ops->free(mcbsp->id - 1);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300588
Jarkko Nikula1a645882011-09-26 10:45:40 +0300589 /* Disable wakeup behavior */
590 if (mcbsp->pdata->has_wakeup)
591 MCBSP_WRITE(mcbsp, WAKEUPEN, 0);
Eero Nurkkala2122fdc2009-08-20 16:18:15 +0300592
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200593 /* Disable interrupt requests */
594 if (mcbsp->irq)
595 MCBSP_WRITE(mcbsp, IRQEN, 0);
596
597 if (mcbsp->irq) {
598 free_irq(mcbsp->irq, (void *)mcbsp);
599 } else {
Jarkko Nikulabafe2722011-06-14 11:23:52 +0000600 free_irq(mcbsp->rx_irq, (void *)mcbsp);
Peter Ujfalusi35d210f2012-03-19 17:05:39 +0200601 free_irq(mcbsp->tx_irq, (void *)mcbsp);
602 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100603
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800604 reg_cache = mcbsp->reg_cache;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100605
Peter Ujfalusie3866152012-03-05 11:32:27 +0200606 /*
607 * Select CLKS source from internal source unconditionally before
608 * marking the McBSP port as free.
609 * If the external clock source via MCBSP_CLKS pin has been selected the
610 * system will refuse to enter idle if the CLKS pin source is not reset
611 * back to internal source.
612 */
613 if (!cpu_class_is_omap1())
614 omap2_mcbsp_set_clks_src(mcbsp, MCBSP_CLKS_PRCM_SRC);
615
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800616 spin_lock(&mcbsp->lock);
617 if (mcbsp->free)
618 dev_err(mcbsp->dev, "McBSP%d was not reserved\n", mcbsp->id);
619 else
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800620 mcbsp->free = true;
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800621 mcbsp->reg_cache = NULL;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300622 spin_unlock(&mcbsp->lock);
Janusz Krzysztofikc8c99692010-02-15 10:03:33 -0800623
624 if (reg_cache)
625 kfree(reg_cache);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100626}
627
628/*
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300629 * Here we start the McBSP, by enabling transmitter, receiver or both.
630 * If no transmitter or receiver is active prior calling, then sample-rate
631 * generator and frame sync are started.
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100632 */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200633void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100634{
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000635 int enable_srg = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100636 u16 w;
637
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300638 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000639 omap_st_start(mcbsp);
640
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000641 /* Only enable SRG, if McBSP is master */
642 w = MCBSP_READ_CACHE(mcbsp, PCR0);
643 if (w & (FSXM | FSRM | CLKXM | CLKRM))
644 enable_srg = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
645 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300646
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000647 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300648 /* Start the sample generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800649 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800650 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300651 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100652
653 /* Enable transmitter and receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300654 tx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800655 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800656 MCBSP_WRITE(mcbsp, SPCR2, w | tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100657
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300658 rx &= 1;
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800659 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800660 MCBSP_WRITE(mcbsp, SPCR1, w | rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100661
Eduardo Valentin44a63112009-08-20 16:18:09 +0300662 /*
663 * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
664 * REVISIT: 100us may give enough time for two CLKSRG, however
665 * due to some unknown PM related, clock gating etc. reason it
666 * is now at 500us.
667 */
668 udelay(500);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100669
Peter Ujfalusice3f0542010-08-31 08:11:44 +0000670 if (enable_srg) {
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300671 /* Start frame sync */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800672 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800673 MCBSP_WRITE(mcbsp, SPCR2, w | (1 << 7));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300674 }
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100675
Jarkko Nikula88408232011-09-26 10:45:41 +0300676 if (mcbsp->pdata->has_ccr) {
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300677 /* Release the transmitter and receiver */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800678 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300679 w &= ~(tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800680 MCBSP_WRITE(mcbsp, XCCR, w);
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800681 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300682 w &= ~(rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800683 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300684 }
685
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100686 /* Dump McBSP Regs */
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200687 omap_mcbsp_dump_reg(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100688}
689
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200690void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100691{
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300692 int idle;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100693 u16 w;
694
Eduardo Valentinfb78d802008-07-03 12:24:39 +0300695 /* Reset transmitter */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300696 tx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300697 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800698 w = MCBSP_READ_CACHE(mcbsp, XCCR);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300699 w |= (tx ? XDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800700 MCBSP_WRITE(mcbsp, XCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300701 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800702 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800703 MCBSP_WRITE(mcbsp, SPCR2, w & ~tx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100704
705 /* Reset receiver */
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300706 rx &= 1;
Jarkko Nikula88408232011-09-26 10:45:41 +0300707 if (mcbsp->pdata->has_ccr) {
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800708 w = MCBSP_READ_CACHE(mcbsp, RCCR);
Jarkko Nikulaa93d4ed2009-10-14 09:56:35 -0700709 w |= (rx ? RDISABLE : 0);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800710 MCBSP_WRITE(mcbsp, RCCR, w);
Jarkko Nikulad09a2af2009-08-23 12:24:27 +0300711 }
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800712 w = MCBSP_READ_CACHE(mcbsp, SPCR1);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800713 MCBSP_WRITE(mcbsp, SPCR1, w & ~rx);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100714
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800715 idle = !((MCBSP_READ_CACHE(mcbsp, SPCR2) |
716 MCBSP_READ_CACHE(mcbsp, SPCR1)) & 1);
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300717
718 if (idle) {
719 /* Reset the sample rate generator */
Janusz Krzysztofik96fbd742010-02-15 10:03:33 -0800720 w = MCBSP_READ_CACHE(mcbsp, SPCR2);
Janusz Krzysztofik8ea32002010-02-15 10:03:32 -0800721 MCBSP_WRITE(mcbsp, SPCR2, w & ~(1 << 6));
Jarkko Nikulac12abc02009-08-07 09:59:47 +0300722 }
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000723
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300724 if (mcbsp->st_data)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000725 omap_st_stop(mcbsp);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100726}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100727
Peter Ujfalusi45656b42012-02-14 18:20:58 +0200728int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id)
Paul Walmsley69d042d2011-07-01 08:52:25 +0000729{
Peter Ujfalusif1991312012-08-16 16:41:00 +0300730 struct clk *fck_src;
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300731 const char *src;
Peter Ujfalusif1991312012-08-16 16:41:00 +0300732 int r;
Paul Walmsley69d042d2011-07-01 08:52:25 +0000733
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300734 if (fck_src_id == MCBSP_CLKS_PAD_SRC)
Peter Ujfalusif1991312012-08-16 16:41:00 +0300735 src = "pad_fck";
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300736 else if (fck_src_id == MCBSP_CLKS_PRCM_SRC)
Peter Ujfalusif1991312012-08-16 16:41:00 +0300737 src = "prcm_fck";
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300738 else
739 return -EINVAL;
740
Peter Ujfalusif1991312012-08-16 16:41:00 +0300741 fck_src = clk_get(mcbsp->dev, src);
742 if (IS_ERR(fck_src)) {
743 dev_err(mcbsp->dev, "CLKS: could not clk_get() %s\n", src);
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300744 return -EINVAL;
Peter Ujfalusif1991312012-08-16 16:41:00 +0300745 }
746
747 pm_runtime_put_sync(mcbsp->dev);
748
749 r = clk_set_parent(mcbsp->fclk, fck_src);
750 if (r) {
751 dev_err(mcbsp->dev, "CLKS: could not clk_set_parent() to %s\n",
752 src);
753 clk_put(fck_src);
754 return r;
755 }
756
757 pm_runtime_get_sync(mcbsp->dev);
758
759 clk_put(fck_src);
760
761 return 0;
762
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300763}
Jarkko Nikula09d28d22011-09-26 10:45:48 +0300764
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200765int omap_mcbsp_6pin_src_mux(struct omap_mcbsp *mcbsp, u8 mux)
Paul Walmsley69d042d2011-07-01 08:52:25 +0000766{
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200767 const char *signal, *src;
Peter Ujfalusi5788c622012-03-08 13:34:16 +0200768
769 if (mcbsp->pdata->mux_signal)
770 return -EINVAL;
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300771
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200772 switch (mux) {
773 case CLKR_SRC_CLKR:
774 signal = "clkr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300775 src = "clkr";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200776 break;
777 case CLKR_SRC_CLKX:
778 signal = "clkr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300779 src = "clkx";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200780 break;
781 case FSR_SRC_FSR:
782 signal = "fsr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300783 src = "fsr";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200784 break;
785 case FSR_SRC_FSX:
786 signal = "fsr";
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300787 src = "fsx";
Peter Ujfalusicd1f08c2012-03-08 11:01:37 +0200788 break;
789 default:
790 return -EINVAL;
791 }
Jarkko Nikula7bc0c4b2011-09-26 10:45:49 +0300792
Peter Ujfalusi5788c622012-03-08 13:34:16 +0200793 return mcbsp->pdata->mux_signal(mcbsp->dev, signal, src);
Paul Walmsley69d042d2011-07-01 08:52:25 +0000794}
Paul Walmsley69d042d2011-07-01 08:52:25 +0000795
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +0300796#define max_thres(m) (mcbsp->pdata->buffer_size)
797#define valid_threshold(m, val) ((val) <= max_thres(m))
798#define THRESHOLD_PROP_BUILDER(prop) \
799static ssize_t prop##_show(struct device *dev, \
800 struct device_attribute *attr, char *buf) \
801{ \
802 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
803 \
804 return sprintf(buf, "%u\n", mcbsp->prop); \
805} \
806 \
807static ssize_t prop##_store(struct device *dev, \
808 struct device_attribute *attr, \
809 const char *buf, size_t size) \
810{ \
811 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
812 unsigned long val; \
813 int status; \
814 \
815 status = strict_strtoul(buf, 0, &val); \
816 if (status) \
817 return status; \
818 \
819 if (!valid_threshold(mcbsp, val)) \
820 return -EDOM; \
821 \
822 mcbsp->prop = val; \
823 return size; \
824} \
825 \
826static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store);
827
828THRESHOLD_PROP_BUILDER(max_tx_thres);
829THRESHOLD_PROP_BUILDER(max_rx_thres);
830
Jarkko Nikula9b300502009-08-24 17:45:50 +0300831static const char *dma_op_modes[] = {
Peter Ujfalusi09fa37a2012-03-15 12:29:49 +0200832 "element", "threshold",
Jarkko Nikula9b300502009-08-24 17:45:50 +0300833};
834
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300835static ssize_t dma_op_mode_show(struct device *dev,
836 struct device_attribute *attr, char *buf)
837{
838 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300839 int dma_op_mode, i = 0;
840 ssize_t len = 0;
841 const char * const *s;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300842
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300843 dma_op_mode = mcbsp->dma_op_mode;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300844
Jarkko Nikula9b300502009-08-24 17:45:50 +0300845 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++) {
846 if (dma_op_mode == i)
847 len += sprintf(buf + len, "[%s] ", *s);
848 else
849 len += sprintf(buf + len, "%s ", *s);
850 }
851 len += sprintf(buf + len, "\n");
852
853 return len;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300854}
855
856static ssize_t dma_op_mode_store(struct device *dev,
857 struct device_attribute *attr,
858 const char *buf, size_t size)
859{
860 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
Jarkko Nikula9b300502009-08-24 17:45:50 +0300861 const char * const *s;
862 int i = 0;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300863
Jarkko Nikula9b300502009-08-24 17:45:50 +0300864 for (s = &dma_op_modes[i]; i < ARRAY_SIZE(dma_op_modes); s++, i++)
865 if (sysfs_streq(buf, *s))
866 break;
867
868 if (i == ARRAY_SIZE(dma_op_modes))
869 return -EINVAL;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300870
871 spin_lock_irq(&mcbsp->lock);
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300872 if (!mcbsp->free) {
873 size = -EBUSY;
874 goto unlock;
875 }
Jarkko Nikula9b300502009-08-24 17:45:50 +0300876 mcbsp->dma_op_mode = i;
Peter Ujfalusi98cb20e2009-08-20 16:18:14 +0300877
878unlock:
879 spin_unlock_irq(&mcbsp->lock);
880
881 return size;
882}
883
884static DEVICE_ATTR(dma_op_mode, 0644, dma_op_mode_show, dma_op_mode_store);
885
Jarkko Nikula7bba67a2011-09-26 10:45:42 +0300886static const struct attribute *additional_attrs[] = {
887 &dev_attr_max_tx_thres.attr,
888 &dev_attr_max_rx_thres.attr,
889 &dev_attr_dma_op_mode.attr,
890 NULL,
891};
892
893static const struct attribute_group additional_attr_group = {
894 .attrs = (struct attribute **)additional_attrs,
895};
896
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000897static ssize_t st_taps_show(struct device *dev,
898 struct device_attribute *attr, char *buf)
899{
900 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
901 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
902 ssize_t status = 0;
903 int i;
904
905 spin_lock_irq(&mcbsp->lock);
906 for (i = 0; i < st_data->nr_taps; i++)
907 status += sprintf(&buf[status], (i ? ", %d" : "%d"),
908 st_data->taps[i]);
909 if (i)
910 status += sprintf(&buf[status], "\n");
911 spin_unlock_irq(&mcbsp->lock);
912
913 return status;
914}
915
916static ssize_t st_taps_store(struct device *dev,
917 struct device_attribute *attr,
918 const char *buf, size_t size)
919{
920 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev);
921 struct omap_mcbsp_st_data *st_data = mcbsp->st_data;
922 int val, tmp, status, i = 0;
923
924 spin_lock_irq(&mcbsp->lock);
925 memset(st_data->taps, 0, sizeof(st_data->taps));
926 st_data->nr_taps = 0;
927
928 do {
929 status = sscanf(buf, "%d%n", &val, &tmp);
930 if (status < 0 || status == 0) {
931 size = -EINVAL;
932 goto out;
933 }
934 if (val < -32768 || val > 32767) {
935 size = -EINVAL;
936 goto out;
937 }
938 st_data->taps[i++] = val;
939 buf += tmp;
940 if (*buf != ',')
941 break;
942 buf++;
943 } while (1);
944
945 st_data->nr_taps = i;
946
947out:
948 spin_unlock_irq(&mcbsp->lock);
949
950 return size;
951}
952
953static DEVICE_ATTR(st_taps, 0644, st_taps_show, st_taps_store);
954
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000955static const struct attribute *sidetone_attrs[] = {
956 &dev_attr_st_taps.attr,
957 NULL,
958};
959
960static const struct attribute_group sidetone_attr_group = {
961 .attrs = (struct attribute **)sidetone_attrs,
962};
963
Jarkko Nikulaf821eec2011-09-26 10:45:45 +0300964static int __devinit omap_st_add(struct omap_mcbsp *mcbsp,
965 struct resource *res)
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000966{
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000967 struct omap_mcbsp_st_data *st_data;
968 int err;
969
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200970 st_data = devm_kzalloc(mcbsp->dev, sizeof(*mcbsp->st_data), GFP_KERNEL);
971 if (!st_data)
972 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000973
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200974 st_data->io_base_st = devm_ioremap(mcbsp->dev, res->start,
975 resource_size(res));
976 if (!st_data->io_base_st)
977 return -ENOMEM;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000978
979 err = sysfs_create_group(&mcbsp->dev->kobj, &sidetone_attr_group);
980 if (err)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200981 return err;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000982
983 mcbsp->st_data = st_data;
984 return 0;
Eero Nurkkalad912fa92010-02-22 12:21:11 +0000985}
986
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100987/*
988 * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
989 * 730 has only 2 McBSP, and both of them are MPU peripherals.
990 */
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200991int __devinit omap_mcbsp_init(struct platform_device *pdev)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100992{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +0200993 struct omap_mcbsp *mcbsp = platform_get_drvdata(pdev);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -0800994 struct resource *res;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +0300995 int ret = 0;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +0100996
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300997 spin_lock_init(&mcbsp->lock);
Shubhrajyoti D6722a722010-12-07 16:25:41 -0800998 mcbsp->free = true;
Chandra Shekharb4b58f52008-10-08 10:01:39 +0300999
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001000 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mpu");
1001 if (!res) {
1002 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1003 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001004 dev_err(mcbsp->dev, "invalid memory resource\n");
1005 return -ENOMEM;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001006 }
1007 }
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001008 if (!devm_request_mem_region(&pdev->dev, res->start, resource_size(res),
1009 dev_name(&pdev->dev))) {
1010 dev_err(mcbsp->dev, "memory region already claimed\n");
1011 return -ENODEV;
1012 }
1013
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001014 mcbsp->phys_base = res->start;
Jarkko Nikulaac6747ca2011-09-26 10:45:43 +03001015 mcbsp->reg_cache_size = resource_size(res);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001016 mcbsp->io_base = devm_ioremap(&pdev->dev, res->start,
1017 resource_size(res));
1018 if (!mcbsp->io_base)
1019 return -ENOMEM;
Russell Kingd592dd12008-09-04 14:25:42 +01001020
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001021 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dma");
1022 if (!res)
1023 mcbsp->phys_dma_base = mcbsp->phys_base;
1024 else
1025 mcbsp->phys_dma_base = res->start;
1026
Peter Ujfalusi35d210f2012-03-19 17:05:39 +02001027 /*
1028 * OMAP1, 2 uses two interrupt lines: TX, RX
1029 * OMAP2430, OMAP3 SoC have combined IRQ line as well.
1030 * OMAP4 and newer SoC only have the combined IRQ line.
1031 * Use the combined IRQ if available since it gives better debugging
1032 * possibilities.
1033 */
1034 mcbsp->irq = platform_get_irq_byname(pdev, "common");
1035 if (mcbsp->irq == -ENXIO) {
1036 mcbsp->tx_irq = platform_get_irq_byname(pdev, "tx");
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001037
Peter Ujfalusi35d210f2012-03-19 17:05:39 +02001038 if (mcbsp->tx_irq == -ENXIO) {
1039 mcbsp->irq = platform_get_irq(pdev, 0);
1040 mcbsp->tx_irq = 0;
1041 } else {
1042 mcbsp->rx_irq = platform_get_irq_byname(pdev, "rx");
1043 mcbsp->irq = 0;
1044 }
Peter Ujfalusi73c95222012-03-07 11:15:37 +02001045 }
Kishon Vijay Abraham Icb7e9de2011-02-24 15:16:50 +05301046
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001047 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx");
1048 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001049 dev_err(&pdev->dev, "invalid rx DMA channel\n");
1050 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001051 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001052 /* RX DMA request number, and port address configuration */
1053 mcbsp->dma_data[1].name = "Audio Capture";
1054 mcbsp->dma_data[1].dma_req = res->start;
1055 mcbsp->dma_data[1].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 1);
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001056
1057 res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx");
1058 if (!res) {
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001059 dev_err(&pdev->dev, "invalid tx DMA channel\n");
1060 return -ENODEV;
Kishon Vijay Abraham I3cf32bb2011-02-24 12:51:45 -08001061 }
Peter Ujfalusib8fb4902012-02-14 15:41:29 +02001062 /* TX DMA request number, and port address configuration */
1063 mcbsp->dma_data[0].name = "Audio Playback";
1064 mcbsp->dma_data[0].dma_req = res->start;
1065 mcbsp->dma_data[0].port_addr = omap_mcbsp_dma_reg_params(mcbsp, 0);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001066
Russell Kingb820ce42009-01-23 10:26:46 +00001067 mcbsp->fclk = clk_get(&pdev->dev, "fck");
1068 if (IS_ERR(mcbsp->fclk)) {
1069 ret = PTR_ERR(mcbsp->fclk);
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001070 dev_err(mcbsp->dev, "unable to get fck: %d\n", ret);
1071 return ret;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001072 }
1073
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001074 mcbsp->dma_op_mode = MCBSP_DMA_MODE_ELEMENT;
1075 if (mcbsp->pdata->buffer_size) {
1076 /*
1077 * Initially configure the maximum thresholds to a safe value.
1078 * The McBSP FIFO usage with these values should not go under
1079 * 16 locations.
1080 * If the whole FIFO without safety buffer is used, than there
1081 * is a possibility that the DMA will be not able to push the
1082 * new data on time, causing channel shifts in runtime.
1083 */
1084 mcbsp->max_tx_thres = max_thres(mcbsp) - 0x10;
1085 mcbsp->max_rx_thres = max_thres(mcbsp) - 0x10;
1086
1087 ret = sysfs_create_group(&mcbsp->dev->kobj,
1088 &additional_attr_group);
1089 if (ret) {
1090 dev_err(mcbsp->dev,
1091 "Unable to create additional controls\n");
1092 goto err_thres;
1093 }
1094 } else {
1095 mcbsp->max_tx_thres = -EINVAL;
1096 mcbsp->max_rx_thres = -EINVAL;
1097 }
1098
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001099 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "sidetone");
1100 if (res) {
1101 ret = omap_st_add(mcbsp, res);
1102 if (ret) {
1103 dev_err(mcbsp->dev,
1104 "Unable to create sidetone controls\n");
1105 goto err_st;
1106 }
1107 }
Eduardo Valentina1a56f5f2009-08-20 16:18:11 +03001108
Russell Kingd592dd12008-09-04 14:25:42 +01001109 return 0;
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001110
Jarkko Nikulaf821eec2011-09-26 10:45:45 +03001111err_st:
1112 if (mcbsp->pdata->buffer_size)
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001113 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Jarkko Nikula7bba67a2011-09-26 10:45:42 +03001114err_thres:
1115 clk_put(mcbsp->fclk);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001116 return ret;
1117}
1118
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001119void __devexit omap_mcbsp_sysfs_remove(struct omap_mcbsp *mcbsp)
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001120{
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001121 if (mcbsp->pdata->buffer_size)
1122 sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
Eduardo Valentinbc5d0c82008-07-03 12:24:39 +03001123
Peter Ujfalusi2ee65952012-02-14 14:52:42 +02001124 if (mcbsp->st_data)
1125 sysfs_remove_group(&mcbsp->dev->kobj, &sidetone_attr_group);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001126}