1 // SPDX-License-Identifier: GPL-2.0-only
3 * omap-mcbsp.c -- OMAP ALSA SoC DAI driver using McBSP port
5 * Copyright (C) 2008 Nokia Corporation
7 * Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
8 * Peter Ujfalusi <peter.ujfalusi@ti.com>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/device.h>
14 #include <linux/pm_runtime.h>
16 #include <linux/of_device.h>
17 #include <sound/core.h>
18 #include <sound/pcm.h>
19 #include <sound/pcm_params.h>
20 #include <sound/initval.h>
21 #include <sound/soc.h>
22 #include <sound/dmaengine_pcm.h>
24 #include "omap-mcbsp-priv.h"
25 #include "omap-mcbsp.h"
28 #define OMAP_MCBSP_RATES (SNDRV_PCM_RATE_8000_96000)
31 OMAP_MCBSP_WORD_8
= 0,
39 static void omap_mcbsp_dump_reg(struct omap_mcbsp
*mcbsp
)
41 dev_dbg(mcbsp
->dev
, "**** McBSP%d regs ****\n", mcbsp
->id
);
42 dev_dbg(mcbsp
->dev
, "DRR2: 0x%04x\n", MCBSP_READ(mcbsp
, DRR2
));
43 dev_dbg(mcbsp
->dev
, "DRR1: 0x%04x\n", MCBSP_READ(mcbsp
, DRR1
));
44 dev_dbg(mcbsp
->dev
, "DXR2: 0x%04x\n", MCBSP_READ(mcbsp
, DXR2
));
45 dev_dbg(mcbsp
->dev
, "DXR1: 0x%04x\n", MCBSP_READ(mcbsp
, DXR1
));
46 dev_dbg(mcbsp
->dev
, "SPCR2: 0x%04x\n", MCBSP_READ(mcbsp
, SPCR2
));
47 dev_dbg(mcbsp
->dev
, "SPCR1: 0x%04x\n", MCBSP_READ(mcbsp
, SPCR1
));
48 dev_dbg(mcbsp
->dev
, "RCR2: 0x%04x\n", MCBSP_READ(mcbsp
, RCR2
));
49 dev_dbg(mcbsp
->dev
, "RCR1: 0x%04x\n", MCBSP_READ(mcbsp
, RCR1
));
50 dev_dbg(mcbsp
->dev
, "XCR2: 0x%04x\n", MCBSP_READ(mcbsp
, XCR2
));
51 dev_dbg(mcbsp
->dev
, "XCR1: 0x%04x\n", MCBSP_READ(mcbsp
, XCR1
));
52 dev_dbg(mcbsp
->dev
, "SRGR2: 0x%04x\n", MCBSP_READ(mcbsp
, SRGR2
));
53 dev_dbg(mcbsp
->dev
, "SRGR1: 0x%04x\n", MCBSP_READ(mcbsp
, SRGR1
));
54 dev_dbg(mcbsp
->dev
, "PCR0: 0x%04x\n", MCBSP_READ(mcbsp
, PCR0
));
55 dev_dbg(mcbsp
->dev
, "***********************\n");
58 static int omap2_mcbsp_set_clks_src(struct omap_mcbsp
*mcbsp
, u8 fck_src_id
)
64 if (fck_src_id
== MCBSP_CLKS_PAD_SRC
)
66 else if (fck_src_id
== MCBSP_CLKS_PRCM_SRC
)
71 fck_src
= clk_get(mcbsp
->dev
, src
);
72 if (IS_ERR(fck_src
)) {
73 dev_err(mcbsp
->dev
, "CLKS: could not clk_get() %s\n", src
);
77 pm_runtime_put_sync(mcbsp
->dev
);
79 r
= clk_set_parent(mcbsp
->fclk
, fck_src
);
81 dev_err(mcbsp
->dev
, "CLKS: could not clk_set_parent() to %s\n",
87 pm_runtime_get_sync(mcbsp
->dev
);
94 static irqreturn_t
omap_mcbsp_irq_handler(int irq
, void *data
)
96 struct omap_mcbsp
*mcbsp
= data
;
99 irqst
= MCBSP_READ(mcbsp
, IRQST
);
100 dev_dbg(mcbsp
->dev
, "IRQ callback : 0x%x\n", irqst
);
102 if (irqst
& RSYNCERREN
)
103 dev_err(mcbsp
->dev
, "RX Frame Sync Error!\n");
105 dev_dbg(mcbsp
->dev
, "RX Frame Sync\n");
107 dev_dbg(mcbsp
->dev
, "RX End Of Frame\n");
109 dev_dbg(mcbsp
->dev
, "RX Buffer Threshold Reached\n");
110 if (irqst
& RUNDFLEN
)
111 dev_err(mcbsp
->dev
, "RX Buffer Underflow!\n");
113 dev_err(mcbsp
->dev
, "RX Buffer Overflow!\n");
115 if (irqst
& XSYNCERREN
)
116 dev_err(mcbsp
->dev
, "TX Frame Sync Error!\n");
118 dev_dbg(mcbsp
->dev
, "TX Frame Sync\n");
120 dev_dbg(mcbsp
->dev
, "TX End Of Frame\n");
122 dev_dbg(mcbsp
->dev
, "TX Buffer threshold Reached\n");
123 if (irqst
& XUNDFLEN
)
124 dev_err(mcbsp
->dev
, "TX Buffer Underflow!\n");
126 dev_err(mcbsp
->dev
, "TX Buffer Overflow!\n");
127 if (irqst
& XEMPTYEOFEN
)
128 dev_dbg(mcbsp
->dev
, "TX Buffer empty at end of frame\n");
130 MCBSP_WRITE(mcbsp
, IRQST
, irqst
);
135 static irqreturn_t
omap_mcbsp_tx_irq_handler(int irq
, void *data
)
137 struct omap_mcbsp
*mcbsp
= data
;
140 irqst_spcr2
= MCBSP_READ(mcbsp
, SPCR2
);
141 dev_dbg(mcbsp
->dev
, "TX IRQ callback : 0x%x\n", irqst_spcr2
);
143 if (irqst_spcr2
& XSYNC_ERR
) {
144 dev_err(mcbsp
->dev
, "TX Frame Sync Error! : 0x%x\n",
146 /* Writing zero to XSYNC_ERR clears the IRQ */
147 MCBSP_WRITE(mcbsp
, SPCR2
, MCBSP_READ_CACHE(mcbsp
, SPCR2
));
153 static irqreturn_t
omap_mcbsp_rx_irq_handler(int irq
, void *data
)
155 struct omap_mcbsp
*mcbsp
= data
;
158 irqst_spcr1
= MCBSP_READ(mcbsp
, SPCR1
);
159 dev_dbg(mcbsp
->dev
, "RX IRQ callback : 0x%x\n", irqst_spcr1
);
161 if (irqst_spcr1
& RSYNC_ERR
) {
162 dev_err(mcbsp
->dev
, "RX Frame Sync Error! : 0x%x\n",
164 /* Writing zero to RSYNC_ERR clears the IRQ */
165 MCBSP_WRITE(mcbsp
, SPCR1
, MCBSP_READ_CACHE(mcbsp
, SPCR1
));
172 * omap_mcbsp_config simply write a config to the
174 * You either call this function or set the McBSP registers
175 * by yourself before calling omap_mcbsp_start().
177 static void omap_mcbsp_config(struct omap_mcbsp
*mcbsp
,
178 const struct omap_mcbsp_reg_cfg
*config
)
180 dev_dbg(mcbsp
->dev
, "Configuring McBSP%d phys_base: 0x%08lx\n",
181 mcbsp
->id
, mcbsp
->phys_base
);
183 /* We write the given config */
184 MCBSP_WRITE(mcbsp
, SPCR2
, config
->spcr2
);
185 MCBSP_WRITE(mcbsp
, SPCR1
, config
->spcr1
);
186 MCBSP_WRITE(mcbsp
, RCR2
, config
->rcr2
);
187 MCBSP_WRITE(mcbsp
, RCR1
, config
->rcr1
);
188 MCBSP_WRITE(mcbsp
, XCR2
, config
->xcr2
);
189 MCBSP_WRITE(mcbsp
, XCR1
, config
->xcr1
);
190 MCBSP_WRITE(mcbsp
, SRGR2
, config
->srgr2
);
191 MCBSP_WRITE(mcbsp
, SRGR1
, config
->srgr1
);
192 MCBSP_WRITE(mcbsp
, MCR2
, config
->mcr2
);
193 MCBSP_WRITE(mcbsp
, MCR1
, config
->mcr1
);
194 MCBSP_WRITE(mcbsp
, PCR0
, config
->pcr0
);
195 if (mcbsp
->pdata
->has_ccr
) {
196 MCBSP_WRITE(mcbsp
, XCCR
, config
->xccr
);
197 MCBSP_WRITE(mcbsp
, RCCR
, config
->rccr
);
199 /* Enable wakeup behavior */
200 if (mcbsp
->pdata
->has_wakeup
)
201 MCBSP_WRITE(mcbsp
, WAKEUPEN
, XRDYEN
| RRDYEN
);
203 /* Enable TX/RX sync error interrupts by default */
205 MCBSP_WRITE(mcbsp
, IRQEN
, RSYNCERREN
| XSYNCERREN
|
206 RUNDFLEN
| ROVFLEN
| XUNDFLEN
| XOVFLEN
);
210 * omap_mcbsp_dma_reg_params - returns the address of mcbsp data register
211 * @mcbsp: omap_mcbsp struct for the McBSP instance
212 * @stream: Stream direction (playback/capture)
214 * Returns the address of mcbsp data transmit register or data receive register
215 * to be used by DMA for transferring/receiving data
217 static int omap_mcbsp_dma_reg_params(struct omap_mcbsp
*mcbsp
,
222 if (stream
== SNDRV_PCM_STREAM_PLAYBACK
) {
223 if (mcbsp
->pdata
->reg_size
== 2)
224 data_reg
= OMAP_MCBSP_REG_DXR1
;
226 data_reg
= OMAP_MCBSP_REG_DXR
;
228 if (mcbsp
->pdata
->reg_size
== 2)
229 data_reg
= OMAP_MCBSP_REG_DRR1
;
231 data_reg
= OMAP_MCBSP_REG_DRR
;
234 return mcbsp
->phys_dma_base
+ data_reg
* mcbsp
->pdata
->reg_step
;
238 * omap_mcbsp_set_rx_threshold configures the transmit threshold in words.
239 * The threshold parameter is 1 based, and it is converted (threshold - 1)
240 * for the THRSH2 register.
242 static void omap_mcbsp_set_tx_threshold(struct omap_mcbsp
*mcbsp
, u16 threshold
)
244 if (threshold
&& threshold
<= mcbsp
->max_tx_thres
)
245 MCBSP_WRITE(mcbsp
, THRSH2
, threshold
- 1);
249 * omap_mcbsp_set_rx_threshold configures the receive threshold in words.
250 * The threshold parameter is 1 based, and it is converted (threshold - 1)
251 * for the THRSH1 register.
253 static void omap_mcbsp_set_rx_threshold(struct omap_mcbsp
*mcbsp
, u16 threshold
)
255 if (threshold
&& threshold
<= mcbsp
->max_rx_thres
)
256 MCBSP_WRITE(mcbsp
, THRSH1
, threshold
- 1);
260 * omap_mcbsp_get_tx_delay returns the number of used slots in the McBSP FIFO
262 static u16
omap_mcbsp_get_tx_delay(struct omap_mcbsp
*mcbsp
)
266 /* Returns the number of free locations in the buffer */
267 buffstat
= MCBSP_READ(mcbsp
, XBUFFSTAT
);
269 /* Number of slots are different in McBSP ports */
270 return mcbsp
->pdata
->buffer_size
- buffstat
;
274 * omap_mcbsp_get_rx_delay returns the number of free slots in the McBSP FIFO
275 * to reach the threshold value (when the DMA will be triggered to read it)
277 static u16
omap_mcbsp_get_rx_delay(struct omap_mcbsp
*mcbsp
)
279 u16 buffstat
, threshold
;
281 /* Returns the number of used locations in the buffer */
282 buffstat
= MCBSP_READ(mcbsp
, RBUFFSTAT
);
284 threshold
= MCBSP_READ(mcbsp
, THRSH1
);
286 /* Return the number of location till we reach the threshold limit */
287 if (threshold
<= buffstat
)
290 return threshold
- buffstat
;
293 static int omap_mcbsp_request(struct omap_mcbsp
*mcbsp
)
298 reg_cache
= kzalloc(mcbsp
->reg_cache_size
, GFP_KERNEL
);
302 spin_lock(&mcbsp
->lock
);
304 dev_err(mcbsp
->dev
, "McBSP%d is currently in use\n", mcbsp
->id
);
310 mcbsp
->reg_cache
= reg_cache
;
311 spin_unlock(&mcbsp
->lock
);
313 if(mcbsp
->pdata
->ops
&& mcbsp
->pdata
->ops
->request
)
314 mcbsp
->pdata
->ops
->request(mcbsp
->id
- 1);
317 * Make sure that transmitter, receiver and sample-rate generator are
318 * not running before activating IRQs.
320 MCBSP_WRITE(mcbsp
, SPCR1
, 0);
321 MCBSP_WRITE(mcbsp
, SPCR2
, 0);
324 err
= request_irq(mcbsp
->irq
, omap_mcbsp_irq_handler
, 0,
325 "McBSP", (void *)mcbsp
);
327 dev_err(mcbsp
->dev
, "Unable to request IRQ\n");
328 goto err_clk_disable
;
331 err
= request_irq(mcbsp
->tx_irq
, omap_mcbsp_tx_irq_handler
, 0,
332 "McBSP TX", (void *)mcbsp
);
334 dev_err(mcbsp
->dev
, "Unable to request TX IRQ\n");
335 goto err_clk_disable
;
338 err
= request_irq(mcbsp
->rx_irq
, omap_mcbsp_rx_irq_handler
, 0,
339 "McBSP RX", (void *)mcbsp
);
341 dev_err(mcbsp
->dev
, "Unable to request RX IRQ\n");
348 free_irq(mcbsp
->tx_irq
, (void *)mcbsp
);
350 if(mcbsp
->pdata
->ops
&& mcbsp
->pdata
->ops
->free
)
351 mcbsp
->pdata
->ops
->free(mcbsp
->id
- 1);
353 /* Disable wakeup behavior */
354 if (mcbsp
->pdata
->has_wakeup
)
355 MCBSP_WRITE(mcbsp
, WAKEUPEN
, 0);
357 spin_lock(&mcbsp
->lock
);
359 mcbsp
->reg_cache
= NULL
;
361 spin_unlock(&mcbsp
->lock
);
367 static void omap_mcbsp_free(struct omap_mcbsp
*mcbsp
)
371 if(mcbsp
->pdata
->ops
&& mcbsp
->pdata
->ops
->free
)
372 mcbsp
->pdata
->ops
->free(mcbsp
->id
- 1);
374 /* Disable wakeup behavior */
375 if (mcbsp
->pdata
->has_wakeup
)
376 MCBSP_WRITE(mcbsp
, WAKEUPEN
, 0);
378 /* Disable interrupt requests */
380 MCBSP_WRITE(mcbsp
, IRQEN
, 0);
383 free_irq(mcbsp
->irq
, (void *)mcbsp
);
385 free_irq(mcbsp
->rx_irq
, (void *)mcbsp
);
386 free_irq(mcbsp
->tx_irq
, (void *)mcbsp
);
389 reg_cache
= mcbsp
->reg_cache
;
392 * Select CLKS source from internal source unconditionally before
393 * marking the McBSP port as free.
394 * If the external clock source via MCBSP_CLKS pin has been selected the
395 * system will refuse to enter idle if the CLKS pin source is not reset
396 * back to internal source.
399 omap2_mcbsp_set_clks_src(mcbsp
, MCBSP_CLKS_PRCM_SRC
);
401 spin_lock(&mcbsp
->lock
);
403 dev_err(mcbsp
->dev
, "McBSP%d was not reserved\n", mcbsp
->id
);
406 mcbsp
->reg_cache
= NULL
;
407 spin_unlock(&mcbsp
->lock
);
413 * Here we start the McBSP, by enabling transmitter, receiver or both.
414 * If no transmitter or receiver is active prior calling, then sample-rate
415 * generator and frame sync are started.
417 static void omap_mcbsp_start(struct omap_mcbsp
*mcbsp
, int stream
)
419 int tx
= (stream
== SNDRV_PCM_STREAM_PLAYBACK
);
425 omap_mcbsp_st_start(mcbsp
);
427 /* Only enable SRG, if McBSP is master */
428 w
= MCBSP_READ_CACHE(mcbsp
, PCR0
);
429 if (w
& (FSXM
| FSRM
| CLKXM
| CLKRM
))
430 enable_srg
= !((MCBSP_READ_CACHE(mcbsp
, SPCR2
) |
431 MCBSP_READ_CACHE(mcbsp
, SPCR1
)) & 1);
434 /* Start the sample generator */
435 w
= MCBSP_READ_CACHE(mcbsp
, SPCR2
);
436 MCBSP_WRITE(mcbsp
, SPCR2
, w
| (1 << 6));
439 /* Enable transmitter and receiver */
441 w
= MCBSP_READ_CACHE(mcbsp
, SPCR2
);
442 MCBSP_WRITE(mcbsp
, SPCR2
, w
| tx
);
445 w
= MCBSP_READ_CACHE(mcbsp
, SPCR1
);
446 MCBSP_WRITE(mcbsp
, SPCR1
, w
| rx
);
449 * Worst case: CLKSRG*2 = 8000khz: (1/8000) * 2 * 2 usec
450 * REVISIT: 100us may give enough time for two CLKSRG, however
451 * due to some unknown PM related, clock gating etc. reason it
457 /* Start frame sync */
458 w
= MCBSP_READ_CACHE(mcbsp
, SPCR2
);
459 MCBSP_WRITE(mcbsp
, SPCR2
, w
| (1 << 7));
462 if (mcbsp
->pdata
->has_ccr
) {
463 /* Release the transmitter and receiver */
464 w
= MCBSP_READ_CACHE(mcbsp
, XCCR
);
465 w
&= ~(tx
? XDISABLE
: 0);
466 MCBSP_WRITE(mcbsp
, XCCR
, w
);
467 w
= MCBSP_READ_CACHE(mcbsp
, RCCR
);
468 w
&= ~(rx
? RDISABLE
: 0);
469 MCBSP_WRITE(mcbsp
, RCCR
, w
);
472 /* Dump McBSP Regs */
473 omap_mcbsp_dump_reg(mcbsp
);
476 static void omap_mcbsp_stop(struct omap_mcbsp
*mcbsp
, int stream
)
478 int tx
= (stream
== SNDRV_PCM_STREAM_PLAYBACK
);
483 /* Reset transmitter */
485 if (mcbsp
->pdata
->has_ccr
) {
486 w
= MCBSP_READ_CACHE(mcbsp
, XCCR
);
487 w
|= (tx
? XDISABLE
: 0);
488 MCBSP_WRITE(mcbsp
, XCCR
, w
);
490 w
= MCBSP_READ_CACHE(mcbsp
, SPCR2
);
491 MCBSP_WRITE(mcbsp
, SPCR2
, w
& ~tx
);
495 if (mcbsp
->pdata
->has_ccr
) {
496 w
= MCBSP_READ_CACHE(mcbsp
, RCCR
);
497 w
|= (rx
? RDISABLE
: 0);
498 MCBSP_WRITE(mcbsp
, RCCR
, w
);
500 w
= MCBSP_READ_CACHE(mcbsp
, SPCR1
);
501 MCBSP_WRITE(mcbsp
, SPCR1
, w
& ~rx
);
503 idle
= !((MCBSP_READ_CACHE(mcbsp
, SPCR2
) |
504 MCBSP_READ_CACHE(mcbsp
, SPCR1
)) & 1);
507 /* Reset the sample rate generator */
508 w
= MCBSP_READ_CACHE(mcbsp
, SPCR2
);
509 MCBSP_WRITE(mcbsp
, SPCR2
, w
& ~(1 << 6));
513 omap_mcbsp_st_stop(mcbsp
);
516 #define max_thres(m) (mcbsp->pdata->buffer_size)
517 #define valid_threshold(m, val) ((val) <= max_thres(m))
518 #define THRESHOLD_PROP_BUILDER(prop) \
519 static ssize_t prop##_show(struct device *dev, \
520 struct device_attribute *attr, char *buf) \
522 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
524 return sprintf(buf, "%u\n", mcbsp->prop); \
527 static ssize_t prop##_store(struct device *dev, \
528 struct device_attribute *attr, \
529 const char *buf, size_t size) \
531 struct omap_mcbsp *mcbsp = dev_get_drvdata(dev); \
535 status = kstrtoul(buf, 0, &val); \
539 if (!valid_threshold(mcbsp, val)) \
546 static DEVICE_ATTR(prop, 0644, prop##_show, prop##_store)
548 THRESHOLD_PROP_BUILDER(max_tx_thres
);
549 THRESHOLD_PROP_BUILDER(max_rx_thres
);
551 static const char * const dma_op_modes
[] = {
552 "element", "threshold",
555 static ssize_t
dma_op_mode_show(struct device
*dev
,
556 struct device_attribute
*attr
, char *buf
)
558 struct omap_mcbsp
*mcbsp
= dev_get_drvdata(dev
);
559 int dma_op_mode
, i
= 0;
561 const char * const *s
;
563 dma_op_mode
= mcbsp
->dma_op_mode
;
565 for (s
= &dma_op_modes
[i
]; i
< ARRAY_SIZE(dma_op_modes
); s
++, i
++) {
566 if (dma_op_mode
== i
)
567 len
+= sprintf(buf
+ len
, "[%s] ", *s
);
569 len
+= sprintf(buf
+ len
, "%s ", *s
);
571 len
+= sprintf(buf
+ len
, "\n");
576 static ssize_t
dma_op_mode_store(struct device
*dev
,
577 struct device_attribute
*attr
, const char *buf
,
580 struct omap_mcbsp
*mcbsp
= dev_get_drvdata(dev
);
583 i
= sysfs_match_string(dma_op_modes
, buf
);
587 spin_lock_irq(&mcbsp
->lock
);
592 mcbsp
->dma_op_mode
= i
;
595 spin_unlock_irq(&mcbsp
->lock
);
600 static DEVICE_ATTR_RW(dma_op_mode
);
602 static const struct attribute
*additional_attrs
[] = {
603 &dev_attr_max_tx_thres
.attr
,
604 &dev_attr_max_rx_thres
.attr
,
605 &dev_attr_dma_op_mode
.attr
,
609 static const struct attribute_group additional_attr_group
= {
610 .attrs
= (struct attribute
**)additional_attrs
,
614 * McBSP1 and McBSP3 are directly mapped on 1610 and 1510.
615 * 730 has only 2 McBSP, and both of them are MPU peripherals.
617 static int omap_mcbsp_init(struct platform_device
*pdev
)
619 struct omap_mcbsp
*mcbsp
= platform_get_drvdata(pdev
);
620 struct resource
*res
;
623 spin_lock_init(&mcbsp
->lock
);
626 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "mpu");
628 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
630 mcbsp
->io_base
= devm_ioremap_resource(&pdev
->dev
, res
);
631 if (IS_ERR(mcbsp
->io_base
))
632 return PTR_ERR(mcbsp
->io_base
);
634 mcbsp
->phys_base
= res
->start
;
635 mcbsp
->reg_cache_size
= resource_size(res
);
637 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "dma");
639 mcbsp
->phys_dma_base
= mcbsp
->phys_base
;
641 mcbsp
->phys_dma_base
= res
->start
;
644 * OMAP1, 2 uses two interrupt lines: TX, RX
645 * OMAP2430, OMAP3 SoC have combined IRQ line as well.
646 * OMAP4 and newer SoC only have the combined IRQ line.
647 * Use the combined IRQ if available since it gives better debugging
650 mcbsp
->irq
= platform_get_irq_byname(pdev
, "common");
651 if (mcbsp
->irq
== -ENXIO
) {
652 mcbsp
->tx_irq
= platform_get_irq_byname(pdev
, "tx");
654 if (mcbsp
->tx_irq
== -ENXIO
) {
655 mcbsp
->irq
= platform_get_irq(pdev
, 0);
658 mcbsp
->rx_irq
= platform_get_irq_byname(pdev
, "rx");
663 if (!pdev
->dev
.of_node
) {
664 res
= platform_get_resource_byname(pdev
, IORESOURCE_DMA
, "tx");
666 dev_err(&pdev
->dev
, "invalid tx DMA channel\n");
669 mcbsp
->dma_req
[0] = res
->start
;
670 mcbsp
->dma_data
[0].filter_data
= &mcbsp
->dma_req
[0];
672 res
= platform_get_resource_byname(pdev
, IORESOURCE_DMA
, "rx");
674 dev_err(&pdev
->dev
, "invalid rx DMA channel\n");
677 mcbsp
->dma_req
[1] = res
->start
;
678 mcbsp
->dma_data
[1].filter_data
= &mcbsp
->dma_req
[1];
680 mcbsp
->dma_data
[0].filter_data
= "tx";
681 mcbsp
->dma_data
[1].filter_data
= "rx";
684 mcbsp
->dma_data
[0].addr
= omap_mcbsp_dma_reg_params(mcbsp
,
685 SNDRV_PCM_STREAM_PLAYBACK
);
686 mcbsp
->dma_data
[1].addr
= omap_mcbsp_dma_reg_params(mcbsp
,
687 SNDRV_PCM_STREAM_CAPTURE
);
689 mcbsp
->fclk
= clk_get(&pdev
->dev
, "fck");
690 if (IS_ERR(mcbsp
->fclk
)) {
691 ret
= PTR_ERR(mcbsp
->fclk
);
692 dev_err(mcbsp
->dev
, "unable to get fck: %d\n", ret
);
696 mcbsp
->dma_op_mode
= MCBSP_DMA_MODE_ELEMENT
;
697 if (mcbsp
->pdata
->buffer_size
) {
699 * Initially configure the maximum thresholds to a safe value.
700 * The McBSP FIFO usage with these values should not go under
702 * If the whole FIFO without safety buffer is used, than there
703 * is a possibility that the DMA will be not able to push the
704 * new data on time, causing channel shifts in runtime.
706 mcbsp
->max_tx_thres
= max_thres(mcbsp
) - 0x10;
707 mcbsp
->max_rx_thres
= max_thres(mcbsp
) - 0x10;
709 ret
= sysfs_create_group(&mcbsp
->dev
->kobj
,
710 &additional_attr_group
);
713 "Unable to create additional controls\n");
718 ret
= omap_mcbsp_st_init(pdev
);
725 if (mcbsp
->pdata
->buffer_size
)
726 sysfs_remove_group(&mcbsp
->dev
->kobj
, &additional_attr_group
);
728 clk_put(mcbsp
->fclk
);
733 * Stream DMA parameters. DMA request line and port address are set runtime
734 * since they are different between OMAP1 and later OMAPs
736 static void omap_mcbsp_set_threshold(struct snd_pcm_substream
*substream
,
737 unsigned int packet_size
)
739 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
740 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
741 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
744 /* No need to proceed further if McBSP does not have FIFO */
745 if (mcbsp
->pdata
->buffer_size
== 0)
749 * Configure McBSP threshold based on either:
750 * packet_size, when the sDMA is in packet mode, or based on the
751 * period size in THRESHOLD mode, otherwise use McBSP threshold = 1
759 /* Configure McBSP internal buffer usage */
760 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
761 omap_mcbsp_set_tx_threshold(mcbsp
, words
);
763 omap_mcbsp_set_rx_threshold(mcbsp
, words
);
766 static int omap_mcbsp_hwrule_min_buffersize(struct snd_pcm_hw_params
*params
,
767 struct snd_pcm_hw_rule
*rule
)
769 struct snd_interval
*buffer_size
= hw_param_interval(params
,
770 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
);
771 struct snd_interval
*channels
= hw_param_interval(params
,
772 SNDRV_PCM_HW_PARAM_CHANNELS
);
773 struct omap_mcbsp
*mcbsp
= rule
->private;
774 struct snd_interval frames
;
777 snd_interval_any(&frames
);
778 size
= mcbsp
->pdata
->buffer_size
;
780 frames
.min
= size
/ channels
->min
;
782 return snd_interval_refine(buffer_size
, &frames
);
785 static int omap_mcbsp_dai_startup(struct snd_pcm_substream
*substream
,
786 struct snd_soc_dai
*cpu_dai
)
788 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
791 if (!cpu_dai
->active
)
792 err
= omap_mcbsp_request(mcbsp
);
795 * OMAP3 McBSP FIFO is word structured.
796 * McBSP2 has 1024 + 256 = 1280 word long buffer,
797 * McBSP1,3,4,5 has 128 word long buffer
798 * This means that the size of the FIFO depends on the sample format.
799 * For example on McBSP3:
800 * 16bit samples: size is 128 * 2 = 256 bytes
801 * 32bit samples: size is 128 * 4 = 512 bytes
802 * It is simpler to place constraint for buffer and period based on
804 * McBSP3 as example again (16 or 32 bit samples):
805 * 1 channel (mono): size is 128 frames (128 words)
806 * 2 channels (stereo): size is 128 / 2 = 64 frames (2 * 64 words)
807 * 4 channels: size is 128 / 4 = 32 frames (4 * 32 words)
809 if (mcbsp
->pdata
->buffer_size
) {
811 * Rule for the buffer size. We should not allow
812 * smaller buffer than the FIFO size to avoid underruns.
813 * This applies only for the playback stream.
815 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
816 snd_pcm_hw_rule_add(substream
->runtime
, 0,
817 SNDRV_PCM_HW_PARAM_BUFFER_SIZE
,
818 omap_mcbsp_hwrule_min_buffersize
,
820 SNDRV_PCM_HW_PARAM_CHANNELS
, -1);
822 /* Make sure, that the period size is always even */
823 snd_pcm_hw_constraint_step(substream
->runtime
, 0,
824 SNDRV_PCM_HW_PARAM_PERIOD_SIZE
, 2);
830 static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream
*substream
,
831 struct snd_soc_dai
*cpu_dai
)
833 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
834 int tx
= (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
);
835 int stream1
= tx
? SNDRV_PCM_STREAM_PLAYBACK
: SNDRV_PCM_STREAM_CAPTURE
;
836 int stream2
= tx
? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
838 if (mcbsp
->latency
[stream2
])
839 pm_qos_update_request(&mcbsp
->pm_qos_req
,
840 mcbsp
->latency
[stream2
]);
841 else if (mcbsp
->latency
[stream1
])
842 pm_qos_remove_request(&mcbsp
->pm_qos_req
);
844 mcbsp
->latency
[stream1
] = 0;
846 if (!cpu_dai
->active
) {
847 omap_mcbsp_free(mcbsp
);
848 mcbsp
->configured
= 0;
852 static int omap_mcbsp_dai_prepare(struct snd_pcm_substream
*substream
,
853 struct snd_soc_dai
*cpu_dai
)
855 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
856 struct pm_qos_request
*pm_qos_req
= &mcbsp
->pm_qos_req
;
857 int tx
= (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
);
858 int stream1
= tx
? SNDRV_PCM_STREAM_PLAYBACK
: SNDRV_PCM_STREAM_CAPTURE
;
859 int stream2
= tx
? SNDRV_PCM_STREAM_CAPTURE
: SNDRV_PCM_STREAM_PLAYBACK
;
860 int latency
= mcbsp
->latency
[stream2
];
862 /* Prevent omap hardware from hitting off between FIFO fills */
863 if (!latency
|| mcbsp
->latency
[stream1
] < latency
)
864 latency
= mcbsp
->latency
[stream1
];
866 if (pm_qos_request_active(pm_qos_req
))
867 pm_qos_update_request(pm_qos_req
, latency
);
869 pm_qos_add_request(pm_qos_req
, PM_QOS_CPU_DMA_LATENCY
, latency
);
874 static int omap_mcbsp_dai_trigger(struct snd_pcm_substream
*substream
, int cmd
,
875 struct snd_soc_dai
*cpu_dai
)
877 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
880 case SNDRV_PCM_TRIGGER_START
:
881 case SNDRV_PCM_TRIGGER_RESUME
:
882 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE
:
884 omap_mcbsp_start(mcbsp
, substream
->stream
);
887 case SNDRV_PCM_TRIGGER_STOP
:
888 case SNDRV_PCM_TRIGGER_SUSPEND
:
889 case SNDRV_PCM_TRIGGER_PAUSE_PUSH
:
890 omap_mcbsp_stop(mcbsp
, substream
->stream
);
900 static snd_pcm_sframes_t
omap_mcbsp_dai_delay(
901 struct snd_pcm_substream
*substream
,
902 struct snd_soc_dai
*dai
)
904 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
905 struct snd_soc_dai
*cpu_dai
= rtd
->cpu_dai
;
906 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
908 snd_pcm_sframes_t delay
;
910 /* No need to proceed further if McBSP does not have FIFO */
911 if (mcbsp
->pdata
->buffer_size
== 0)
914 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
915 fifo_use
= omap_mcbsp_get_tx_delay(mcbsp
);
917 fifo_use
= omap_mcbsp_get_rx_delay(mcbsp
);
920 * Divide the used locations with the channel count to get the
921 * FIFO usage in samples (don't care about partial samples in the
924 delay
= fifo_use
/ substream
->runtime
->channels
;
929 static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream
*substream
,
930 struct snd_pcm_hw_params
*params
,
931 struct snd_soc_dai
*cpu_dai
)
933 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
934 struct omap_mcbsp_reg_cfg
*regs
= &mcbsp
->cfg_regs
;
935 struct snd_dmaengine_dai_dma_data
*dma_data
;
936 int wlen
, channels
, wpf
;
938 unsigned int format
, div
, framesize
, master
;
939 unsigned int buffer_size
= mcbsp
->pdata
->buffer_size
;
941 dma_data
= snd_soc_dai_get_dma_data(cpu_dai
, substream
);
942 channels
= params_channels(params
);
944 switch (params_format(params
)) {
945 case SNDRV_PCM_FORMAT_S16_LE
:
948 case SNDRV_PCM_FORMAT_S32_LE
:
957 if (mcbsp
->dma_op_mode
== MCBSP_DMA_MODE_THRESHOLD
) {
958 int period_words
, max_thrsh
;
961 period_words
= params_period_bytes(params
) / (wlen
/ 8);
962 if (substream
->stream
== SNDRV_PCM_STREAM_PLAYBACK
)
963 max_thrsh
= mcbsp
->max_tx_thres
;
965 max_thrsh
= mcbsp
->max_rx_thres
;
967 * Use sDMA packet mode if McBSP is in threshold mode:
968 * If period words less than the FIFO size the packet
969 * size is set to the number of period words, otherwise
970 * Look for the biggest threshold value which divides
971 * the period size evenly.
973 divider
= period_words
/ max_thrsh
;
974 if (period_words
% max_thrsh
)
976 while (period_words
% divider
&&
977 divider
< period_words
)
979 if (divider
== period_words
)
982 pkt_size
= period_words
/ divider
;
983 } else if (channels
> 1) {
984 /* Use packet mode for non mono streams */
988 latency
= (buffer_size
- pkt_size
) / channels
;
989 latency
= latency
* USEC_PER_SEC
/
990 (params
->rate_num
/ params
->rate_den
);
991 mcbsp
->latency
[substream
->stream
] = latency
;
993 omap_mcbsp_set_threshold(substream
, pkt_size
);
996 dma_data
->maxburst
= pkt_size
;
998 if (mcbsp
->configured
) {
999 /* McBSP already configured by another stream */
1003 regs
->rcr2
&= ~(RPHASE
| RFRLEN2(0x7f) | RWDLEN2(7));
1004 regs
->xcr2
&= ~(RPHASE
| XFRLEN2(0x7f) | XWDLEN2(7));
1005 regs
->rcr1
&= ~(RFRLEN1(0x7f) | RWDLEN1(7));
1006 regs
->xcr1
&= ~(XFRLEN1(0x7f) | XWDLEN1(7));
1007 format
= mcbsp
->fmt
& SND_SOC_DAIFMT_FORMAT_MASK
;
1009 if (channels
== 2 && (format
== SND_SOC_DAIFMT_I2S
||
1010 format
== SND_SOC_DAIFMT_LEFT_J
)) {
1011 /* Use dual-phase frames */
1012 regs
->rcr2
|= RPHASE
;
1013 regs
->xcr2
|= XPHASE
;
1014 /* Set 1 word per (McBSP) frame for phase1 and phase2 */
1016 regs
->rcr2
|= RFRLEN2(wpf
- 1);
1017 regs
->xcr2
|= XFRLEN2(wpf
- 1);
1020 regs
->rcr1
|= RFRLEN1(wpf
- 1);
1021 regs
->xcr1
|= XFRLEN1(wpf
- 1);
1023 switch (params_format(params
)) {
1024 case SNDRV_PCM_FORMAT_S16_LE
:
1025 /* Set word lengths */
1026 regs
->rcr2
|= RWDLEN2(OMAP_MCBSP_WORD_16
);
1027 regs
->rcr1
|= RWDLEN1(OMAP_MCBSP_WORD_16
);
1028 regs
->xcr2
|= XWDLEN2(OMAP_MCBSP_WORD_16
);
1029 regs
->xcr1
|= XWDLEN1(OMAP_MCBSP_WORD_16
);
1031 case SNDRV_PCM_FORMAT_S32_LE
:
1032 /* Set word lengths */
1033 regs
->rcr2
|= RWDLEN2(OMAP_MCBSP_WORD_32
);
1034 regs
->rcr1
|= RWDLEN1(OMAP_MCBSP_WORD_32
);
1035 regs
->xcr2
|= XWDLEN2(OMAP_MCBSP_WORD_32
);
1036 regs
->xcr1
|= XWDLEN1(OMAP_MCBSP_WORD_32
);
1039 /* Unsupported PCM format */
1043 /* In McBSP master modes, FRAME (i.e. sample rate) is generated
1044 * by _counting_ BCLKs. Calculate frame size in BCLKs */
1045 master
= mcbsp
->fmt
& SND_SOC_DAIFMT_MASTER_MASK
;
1046 if (master
== SND_SOC_DAIFMT_CBS_CFS
) {
1047 div
= mcbsp
->clk_div
? mcbsp
->clk_div
: 1;
1048 framesize
= (mcbsp
->in_freq
/ div
) / params_rate(params
);
1050 if (framesize
< wlen
* channels
) {
1051 printk(KERN_ERR
"%s: not enough bandwidth for desired rate and "
1052 "channels\n", __func__
);
1056 framesize
= wlen
* channels
;
1058 /* Set FS period and length in terms of bit clock periods */
1059 regs
->srgr2
&= ~FPER(0xfff);
1060 regs
->srgr1
&= ~FWID(0xff);
1062 case SND_SOC_DAIFMT_I2S
:
1063 case SND_SOC_DAIFMT_LEFT_J
:
1064 regs
->srgr2
|= FPER(framesize
- 1);
1065 regs
->srgr1
|= FWID((framesize
>> 1) - 1);
1067 case SND_SOC_DAIFMT_DSP_A
:
1068 case SND_SOC_DAIFMT_DSP_B
:
1069 regs
->srgr2
|= FPER(framesize
- 1);
1070 regs
->srgr1
|= FWID(0);
1074 omap_mcbsp_config(mcbsp
, &mcbsp
->cfg_regs
);
1076 mcbsp
->configured
= 1;
1082 * This must be called before _set_clkdiv and _set_sysclk since McBSP register
1083 * cache is initialized here
1085 static int omap_mcbsp_dai_set_dai_fmt(struct snd_soc_dai
*cpu_dai
,
1088 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
1089 struct omap_mcbsp_reg_cfg
*regs
= &mcbsp
->cfg_regs
;
1090 bool inv_fs
= false;
1092 if (mcbsp
->configured
)
1096 memset(regs
, 0, sizeof(*regs
));
1097 /* Generic McBSP register settings */
1098 regs
->spcr2
|= XINTM(3) | FREE
;
1099 regs
->spcr1
|= RINTM(3);
1100 /* RFIG and XFIG are not defined in 2430 and on OMAP3+ */
1101 if (!mcbsp
->pdata
->has_ccr
) {
1106 /* Configure XCCR/RCCR only for revisions which have ccr registers */
1107 if (mcbsp
->pdata
->has_ccr
) {
1108 regs
->xccr
= DXENDLY(1) | XDMAEN
| XDISABLE
;
1109 regs
->rccr
= RFULL_CYCLE
| RDMAEN
| RDISABLE
;
1112 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1113 case SND_SOC_DAIFMT_I2S
:
1114 /* 1-bit data delay */
1115 regs
->rcr2
|= RDATDLY(1);
1116 regs
->xcr2
|= XDATDLY(1);
1118 case SND_SOC_DAIFMT_LEFT_J
:
1119 /* 0-bit data delay */
1120 regs
->rcr2
|= RDATDLY(0);
1121 regs
->xcr2
|= XDATDLY(0);
1122 regs
->spcr1
|= RJUST(2);
1123 /* Invert FS polarity configuration */
1126 case SND_SOC_DAIFMT_DSP_A
:
1127 /* 1-bit data delay */
1128 regs
->rcr2
|= RDATDLY(1);
1129 regs
->xcr2
|= XDATDLY(1);
1130 /* Invert FS polarity configuration */
1133 case SND_SOC_DAIFMT_DSP_B
:
1134 /* 0-bit data delay */
1135 regs
->rcr2
|= RDATDLY(0);
1136 regs
->xcr2
|= XDATDLY(0);
1137 /* Invert FS polarity configuration */
1141 /* Unsupported data format */
1145 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1146 case SND_SOC_DAIFMT_CBS_CFS
:
1147 /* McBSP master. Set FS and bit clocks as outputs */
1148 regs
->pcr0
|= FSXM
| FSRM
|
1150 /* Sample rate generator drives the FS */
1151 regs
->srgr2
|= FSGM
;
1153 case SND_SOC_DAIFMT_CBM_CFS
:
1154 /* McBSP slave. FS clock as output */
1155 regs
->srgr2
|= FSGM
;
1156 regs
->pcr0
|= FSXM
| FSRM
;
1158 case SND_SOC_DAIFMT_CBM_CFM
:
1162 /* Unsupported master/slave configuration */
1166 /* Set bit clock (CLKX/CLKR) and FS polarities */
1167 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1168 case SND_SOC_DAIFMT_NB_NF
:
1171 * FS active low. TX data driven on falling edge of bit clock
1172 * and RX data sampled on rising edge of bit clock.
1174 regs
->pcr0
|= FSXP
| FSRP
|
1177 case SND_SOC_DAIFMT_NB_IF
:
1178 regs
->pcr0
|= CLKXP
| CLKRP
;
1180 case SND_SOC_DAIFMT_IB_NF
:
1181 regs
->pcr0
|= FSXP
| FSRP
;
1183 case SND_SOC_DAIFMT_IB_IF
:
1189 regs
->pcr0
^= FSXP
| FSRP
;
1194 static int omap_mcbsp_dai_set_clkdiv(struct snd_soc_dai
*cpu_dai
,
1195 int div_id
, int div
)
1197 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
1198 struct omap_mcbsp_reg_cfg
*regs
= &mcbsp
->cfg_regs
;
1200 if (div_id
!= OMAP_MCBSP_CLKGDV
)
1203 mcbsp
->clk_div
= div
;
1204 regs
->srgr1
&= ~CLKGDV(0xff);
1205 regs
->srgr1
|= CLKGDV(div
- 1);
1210 static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai
*cpu_dai
,
1211 int clk_id
, unsigned int freq
,
1214 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(cpu_dai
);
1215 struct omap_mcbsp_reg_cfg
*regs
= &mcbsp
->cfg_regs
;
1218 if (mcbsp
->active
) {
1219 if (freq
== mcbsp
->in_freq
)
1225 mcbsp
->in_freq
= freq
;
1226 regs
->srgr2
&= ~CLKSM
;
1227 regs
->pcr0
&= ~SCLKME
;
1230 case OMAP_MCBSP_SYSCLK_CLK
:
1231 regs
->srgr2
|= CLKSM
;
1233 case OMAP_MCBSP_SYSCLK_CLKS_FCLK
:
1234 if (mcbsp_omap1()) {
1238 err
= omap2_mcbsp_set_clks_src(mcbsp
,
1239 MCBSP_CLKS_PRCM_SRC
);
1241 case OMAP_MCBSP_SYSCLK_CLKS_EXT
:
1242 if (mcbsp_omap1()) {
1246 err
= omap2_mcbsp_set_clks_src(mcbsp
,
1247 MCBSP_CLKS_PAD_SRC
);
1250 case OMAP_MCBSP_SYSCLK_CLKX_EXT
:
1251 regs
->srgr2
|= CLKSM
;
1252 regs
->pcr0
|= SCLKME
;
1254 * If McBSP is master but yet the CLKX/CLKR pin drives the SRG,
1255 * disable output on those pins. This enables to inject the
1256 * reference clock through CLKX/CLKR. For this to work
1257 * set_dai_sysclk() _needs_ to be called after set_dai_fmt().
1259 regs
->pcr0
&= ~CLKXM
;
1261 case OMAP_MCBSP_SYSCLK_CLKR_EXT
:
1262 regs
->pcr0
|= SCLKME
;
1263 /* Disable ouput on CLKR pin in master mode */
1264 regs
->pcr0
&= ~CLKRM
;
1273 static const struct snd_soc_dai_ops mcbsp_dai_ops
= {
1274 .startup
= omap_mcbsp_dai_startup
,
1275 .shutdown
= omap_mcbsp_dai_shutdown
,
1276 .prepare
= omap_mcbsp_dai_prepare
,
1277 .trigger
= omap_mcbsp_dai_trigger
,
1278 .delay
= omap_mcbsp_dai_delay
,
1279 .hw_params
= omap_mcbsp_dai_hw_params
,
1280 .set_fmt
= omap_mcbsp_dai_set_dai_fmt
,
1281 .set_clkdiv
= omap_mcbsp_dai_set_clkdiv
,
1282 .set_sysclk
= omap_mcbsp_dai_set_dai_sysclk
,
1285 static int omap_mcbsp_probe(struct snd_soc_dai
*dai
)
1287 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(dai
);
1289 pm_runtime_enable(mcbsp
->dev
);
1291 snd_soc_dai_init_dma_data(dai
,
1292 &mcbsp
->dma_data
[SNDRV_PCM_STREAM_PLAYBACK
],
1293 &mcbsp
->dma_data
[SNDRV_PCM_STREAM_CAPTURE
]);
1298 static int omap_mcbsp_remove(struct snd_soc_dai
*dai
)
1300 struct omap_mcbsp
*mcbsp
= snd_soc_dai_get_drvdata(dai
);
1302 pm_runtime_disable(mcbsp
->dev
);
1307 static struct snd_soc_dai_driver omap_mcbsp_dai
= {
1308 .probe
= omap_mcbsp_probe
,
1309 .remove
= omap_mcbsp_remove
,
1313 .rates
= OMAP_MCBSP_RATES
,
1314 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
1319 .rates
= OMAP_MCBSP_RATES
,
1320 .formats
= SNDRV_PCM_FMTBIT_S16_LE
| SNDRV_PCM_FMTBIT_S32_LE
,
1322 .ops
= &mcbsp_dai_ops
,
1325 static const struct snd_soc_component_driver omap_mcbsp_component
= {
1326 .name
= "omap-mcbsp",
1329 static struct omap_mcbsp_platform_data omap2420_pdata
= {
1334 static struct omap_mcbsp_platform_data omap2430_pdata
= {
1340 static struct omap_mcbsp_platform_data omap3_pdata
= {
1347 static struct omap_mcbsp_platform_data omap4_pdata
= {
1354 static const struct of_device_id omap_mcbsp_of_match
[] = {
1356 .compatible
= "ti,omap2420-mcbsp",
1357 .data
= &omap2420_pdata
,
1360 .compatible
= "ti,omap2430-mcbsp",
1361 .data
= &omap2430_pdata
,
1364 .compatible
= "ti,omap3-mcbsp",
1365 .data
= &omap3_pdata
,
1368 .compatible
= "ti,omap4-mcbsp",
1369 .data
= &omap4_pdata
,
1373 MODULE_DEVICE_TABLE(of
, omap_mcbsp_of_match
);
1375 static int asoc_mcbsp_probe(struct platform_device
*pdev
)
1377 struct omap_mcbsp_platform_data
*pdata
= dev_get_platdata(&pdev
->dev
);
1378 struct omap_mcbsp
*mcbsp
;
1379 const struct of_device_id
*match
;
1382 match
= of_match_device(omap_mcbsp_of_match
, &pdev
->dev
);
1384 struct device_node
*node
= pdev
->dev
.of_node
;
1385 struct omap_mcbsp_platform_data
*pdata_quirk
= pdata
;
1388 pdata
= devm_kzalloc(&pdev
->dev
,
1389 sizeof(struct omap_mcbsp_platform_data
),
1394 memcpy(pdata
, match
->data
, sizeof(*pdata
));
1395 if (!of_property_read_u32(node
, "ti,buffer-size", &buffer_size
))
1396 pdata
->buffer_size
= buffer_size
;
1398 pdata
->force_ick_on
= pdata_quirk
->force_ick_on
;
1399 } else if (!pdata
) {
1400 dev_err(&pdev
->dev
, "missing platform data.\n");
1403 mcbsp
= devm_kzalloc(&pdev
->dev
, sizeof(struct omap_mcbsp
), GFP_KERNEL
);
1407 mcbsp
->id
= pdev
->id
;
1408 mcbsp
->pdata
= pdata
;
1409 mcbsp
->dev
= &pdev
->dev
;
1410 platform_set_drvdata(pdev
, mcbsp
);
1412 ret
= omap_mcbsp_init(pdev
);
1416 if (mcbsp
->pdata
->reg_size
== 2) {
1417 omap_mcbsp_dai
.playback
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
1418 omap_mcbsp_dai
.capture
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
1421 ret
= devm_snd_soc_register_component(&pdev
->dev
,
1422 &omap_mcbsp_component
,
1423 &omap_mcbsp_dai
, 1);
1427 return sdma_pcm_platform_register(&pdev
->dev
, "tx", "rx");
1430 static int asoc_mcbsp_remove(struct platform_device
*pdev
)
1432 struct omap_mcbsp
*mcbsp
= platform_get_drvdata(pdev
);
1434 if (mcbsp
->pdata
->ops
&& mcbsp
->pdata
->ops
->free
)
1435 mcbsp
->pdata
->ops
->free(mcbsp
->id
);
1437 if (pm_qos_request_active(&mcbsp
->pm_qos_req
))
1438 pm_qos_remove_request(&mcbsp
->pm_qos_req
);
1440 if (mcbsp
->pdata
->buffer_size
)
1441 sysfs_remove_group(&mcbsp
->dev
->kobj
, &additional_attr_group
);
1443 omap_mcbsp_st_cleanup(pdev
);
1445 clk_put(mcbsp
->fclk
);
1450 static struct platform_driver asoc_mcbsp_driver
= {
1452 .name
= "omap-mcbsp",
1453 .of_match_table
= omap_mcbsp_of_match
,
1456 .probe
= asoc_mcbsp_probe
,
1457 .remove
= asoc_mcbsp_remove
,
1460 module_platform_driver(asoc_mcbsp_driver
);
1462 MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@bitmer.com>");
1463 MODULE_DESCRIPTION("OMAP I2S SoC Interface");
1464 MODULE_LICENSE("GPL");
1465 MODULE_ALIAS("platform:omap-mcbsp");