2008-07-30 14:12:04 -04:00
|
|
|
/*
|
|
|
|
* pxa-ssp.c -- ALSA Soc Audio Layer
|
|
|
|
*
|
|
|
|
* Copyright 2005,2008 Wolfson Microelectronics PLC.
|
|
|
|
* Author: Liam Girdwood
|
|
|
|
* Mark Brown <broonie@opensource.wolfsonmicro.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* o Test network mode for > 16bit sample size
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 04:04:11 -04:00
|
|
|
#include <linux/slab.h>
|
2008-07-30 14:12:04 -04:00
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/io.h>
|
2010-11-22 20:12:15 -05:00
|
|
|
#include <linux/pxa2xx_ssp.h>
|
2013-08-12 04:42:38 -04:00
|
|
|
#include <linux/of.h>
|
2013-08-12 04:42:39 -04:00
|
|
|
#include <linux/dmaengine.h>
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2009-02-03 15:18:26 -05:00
|
|
|
#include <asm/irq.h>
|
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/pxa2xx-lib.h>
|
2013-08-12 04:42:39 -04:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
#include <mach/hardware.h>
|
|
|
|
|
2010-08-13 09:55:27 -04:00
|
|
|
#include "../../arm/pxa2xx-pcm.h"
|
2008-07-30 14:12:04 -04:00
|
|
|
#include "pxa-ssp.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSP audio private data
|
|
|
|
*/
|
|
|
|
struct ssp_priv {
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
unsigned int sysclk;
|
|
|
|
int dai_fmt;
|
|
|
|
#ifdef CONFIG_PM
|
2010-02-09 06:46:01 -05:00
|
|
|
uint32_t cr0;
|
|
|
|
uint32_t cr1;
|
|
|
|
uint32_t to;
|
|
|
|
uint32_t psp;
|
2008-07-30 14:12:04 -04:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static void dump_registers(struct ssp_device *ssp)
|
|
|
|
{
|
|
|
|
dev_dbg(&ssp->pdev->dev, "SSCR0 0x%08x SSCR1 0x%08x SSTO 0x%08x\n",
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_read_reg(ssp, SSCR0), pxa_ssp_read_reg(ssp, SSCR1),
|
|
|
|
pxa_ssp_read_reg(ssp, SSTO));
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
dev_dbg(&ssp->pdev->dev, "SSPSP 0x%08x SSSR 0x%08x SSACD 0x%08x\n",
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_read_reg(ssp, SSPSP), pxa_ssp_read_reg(ssp, SSSR),
|
|
|
|
pxa_ssp_read_reg(ssp, SSACD));
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
static void pxa_ssp_enable(struct ssp_device *ssp)
|
2010-02-09 06:46:01 -05:00
|
|
|
{
|
|
|
|
uint32_t sscr0;
|
|
|
|
|
|
|
|
sscr0 = __raw_readl(ssp->mmio_base + SSCR0) | SSCR0_SSE;
|
|
|
|
__raw_writel(sscr0, ssp->mmio_base + SSCR0);
|
|
|
|
}
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
static void pxa_ssp_disable(struct ssp_device *ssp)
|
2010-02-09 06:46:01 -05:00
|
|
|
{
|
|
|
|
uint32_t sscr0;
|
|
|
|
|
|
|
|
sscr0 = __raw_readl(ssp->mmio_base + SSCR0) & ~SSCR0_SSE;
|
|
|
|
__raw_writel(sscr0, ssp->mmio_base + SSCR0);
|
|
|
|
}
|
|
|
|
|
2012-05-07 03:34:24 -04:00
|
|
|
static void pxa_ssp_set_dma_params(struct ssp_device *ssp, int width4,
|
2013-08-12 04:42:39 -04:00
|
|
|
int out, struct snd_dmaengine_dai_dma_data *dma)
|
2009-04-23 05:05:38 -04:00
|
|
|
{
|
2013-08-12 04:42:39 -04:00
|
|
|
dma->addr_width = width4 ? DMA_SLAVE_BUSWIDTH_4_BYTES :
|
|
|
|
DMA_SLAVE_BUSWIDTH_2_BYTES;
|
|
|
|
dma->maxburst = 16;
|
|
|
|
dma->addr = ssp->phys_base + SSDR;
|
2009-04-23 05:05:38 -04:00
|
|
|
}
|
|
|
|
|
2008-11-18 17:11:38 -05:00
|
|
|
static int pxa_ssp_startup(struct snd_pcm_substream *substream,
|
2010-03-17 16:15:21 -04:00
|
|
|
struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2013-08-12 04:42:39 -04:00
|
|
|
struct snd_dmaengine_dai_dma_data *dma;
|
2008-07-30 14:12:04 -04:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!cpu_dai->active) {
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_enable(ssp->clk);
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_disable(ssp);
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
2009-04-23 05:05:38 -04:00
|
|
|
|
2013-08-12 04:42:39 -04:00
|
|
|
dma = kzalloc(sizeof(struct snd_dmaengine_dai_dma_data), GFP_KERNEL);
|
2012-05-07 03:34:24 -04:00
|
|
|
if (!dma)
|
|
|
|
return -ENOMEM;
|
2013-08-12 04:42:40 -04:00
|
|
|
|
|
|
|
dma->filter_data = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
|
|
|
|
&ssp->drcmr_tx : &ssp->drcmr_rx;
|
|
|
|
|
2013-08-12 04:42:39 -04:00
|
|
|
snd_soc_dai_set_dma_data(cpu_dai, substream, dma);
|
2010-03-22 05:11:15 -04:00
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-11-18 17:11:38 -05:00
|
|
|
static void pxa_ssp_shutdown(struct snd_pcm_substream *substream,
|
2010-03-17 16:15:21 -04:00
|
|
|
struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
if (!cpu_dai->active) {
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_disable(ssp);
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_disable(ssp->clk);
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
2009-04-23 05:05:38 -04:00
|
|
|
|
2010-03-22 05:11:15 -04:00
|
|
|
kfree(snd_soc_dai_get_dma_data(cpu_dai, substream));
|
|
|
|
snd_soc_dai_set_dma_data(cpu_dai, substream, NULL);
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
2008-12-03 13:21:52 -05:00
|
|
|
static int pxa_ssp_suspend(struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
if (!cpu_dai->active)
|
2010-03-08 15:21:04 -05:00
|
|
|
clk_enable(ssp->clk);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2010-02-09 06:46:01 -05:00
|
|
|
priv->cr0 = __raw_readl(ssp->mmio_base + SSCR0);
|
|
|
|
priv->cr1 = __raw_readl(ssp->mmio_base + SSCR1);
|
|
|
|
priv->to = __raw_readl(ssp->mmio_base + SSTO);
|
|
|
|
priv->psp = __raw_readl(ssp->mmio_base + SSPSP);
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_disable(ssp);
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_disable(ssp->clk);
|
2008-07-30 14:12:04 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-12-03 13:21:52 -05:00
|
|
|
static int pxa_ssp_resume(struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
|
|
|
uint32_t sssr = SSSR_ROR | SSSR_TUR | SSSR_BCE;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_enable(ssp->clk);
|
|
|
|
|
|
|
|
__raw_writel(sssr, ssp->mmio_base + SSSR);
|
|
|
|
__raw_writel(priv->cr0 & ~SSCR0_SSE, ssp->mmio_base + SSCR0);
|
|
|
|
__raw_writel(priv->cr1, ssp->mmio_base + SSCR1);
|
|
|
|
__raw_writel(priv->to, ssp->mmio_base + SSTO);
|
|
|
|
__raw_writel(priv->psp, ssp->mmio_base + SSPSP);
|
2010-02-02 05:45:27 -05:00
|
|
|
|
|
|
|
if (cpu_dai->active)
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_enable(ssp);
|
2010-02-02 05:45:27 -05:00
|
|
|
else
|
2010-03-08 15:21:04 -05:00
|
|
|
clk_disable(ssp->clk);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define pxa_ssp_suspend NULL
|
|
|
|
#define pxa_ssp_resume NULL
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ssp_set_clkdiv - set SSP clock divider
|
|
|
|
* @div: serial clock rate divider
|
|
|
|
*/
|
2010-05-05 10:11:15 -04:00
|
|
|
static void pxa_ssp_set_scr(struct ssp_device *ssp, u32 div)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-05-05 10:11:15 -04:00
|
|
|
u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
|
2009-04-17 05:39:38 -04:00
|
|
|
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA25x_SSP) {
|
2009-04-17 05:39:38 -04:00
|
|
|
sscr0 &= ~0x0000ff00;
|
|
|
|
sscr0 |= ((div - 2)/2) << 8; /* 2..512 */
|
|
|
|
} else {
|
|
|
|
sscr0 &= ~0x000fff00;
|
|
|
|
sscr0 |= (div - 1) << 8; /* 1..4096 */
|
|
|
|
}
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0);
|
2009-04-17 05:39:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-05-05 10:11:15 -04:00
|
|
|
* pxa_ssp_get_clkdiv - get SSP clock divider
|
2009-04-17 05:39:38 -04:00
|
|
|
*/
|
2010-05-05 10:11:15 -04:00
|
|
|
static u32 pxa_ssp_get_scr(struct ssp_device *ssp)
|
2009-04-17 05:39:38 -04:00
|
|
|
{
|
2010-05-05 10:11:15 -04:00
|
|
|
u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
|
2009-04-17 05:39:38 -04:00
|
|
|
u32 div;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA25x_SSP)
|
2009-04-17 05:39:38 -04:00
|
|
|
div = ((sscr0 >> 8) & 0xff) * 2 + 2;
|
|
|
|
else
|
|
|
|
div = ((sscr0 >> 8) & 0xfff) + 1;
|
|
|
|
return div;
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the SSP ports SYSCLK.
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
int val;
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
u32 sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
|
2009-03-04 15:16:57 -05:00
|
|
|
~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
dev_dbg(&ssp->pdev->dev,
|
2009-05-27 20:08:39 -04:00
|
|
|
"pxa_ssp_set_dai_sysclk id: %d, clk_id %d, freq %u\n",
|
2008-07-30 14:12:04 -04:00
|
|
|
cpu_dai->id, clk_id, freq);
|
|
|
|
|
|
|
|
switch (clk_id) {
|
|
|
|
case PXA_SSP_CLK_NET_PLL:
|
|
|
|
sscr0 |= SSCR0_MOD;
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_PLL:
|
|
|
|
/* Internal PLL is fixed */
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA25x_SSP)
|
2008-07-30 14:12:04 -04:00
|
|
|
priv->sysclk = 1843200;
|
|
|
|
else
|
|
|
|
priv->sysclk = 13000000;
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_EXT:
|
|
|
|
priv->sysclk = freq;
|
|
|
|
sscr0 |= SSCR0_ECS;
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_NET:
|
|
|
|
priv->sysclk = freq;
|
|
|
|
sscr0 |= SSCR0_NCS | SSCR0_MOD;
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_AUDIO:
|
|
|
|
priv->sysclk = 0;
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_set_scr(ssp, 1);
|
2009-03-04 15:16:57 -05:00
|
|
|
sscr0 |= SSCR0_ACS;
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The SSP clock must be disabled when changing SSP clock mode
|
|
|
|
* on PXA2xx. On PXA3xx it must be enabled when doing so. */
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type != PXA3xx_SSP)
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_disable(ssp->clk);
|
2010-05-05 10:11:15 -04:00
|
|
|
val = pxa_ssp_read_reg(ssp, SSCR0) | sscr0;
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, val);
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type != PXA3xx_SSP)
|
2010-02-09 06:46:01 -05:00
|
|
|
clk_enable(ssp->clk);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the SSP clock dividers.
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
|
|
|
|
int div_id, int div)
|
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
switch (div_id) {
|
|
|
|
case PXA_SSP_AUDIO_DIV_ACDS:
|
2010-05-05 10:11:15 -04:00
|
|
|
val = (pxa_ssp_read_reg(ssp, SSACD) & ~0x7) | SSACD_ACDS(div);
|
|
|
|
pxa_ssp_write_reg(ssp, SSACD, val);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case PXA_SSP_AUDIO_DIV_SCDB:
|
2010-05-05 10:11:15 -04:00
|
|
|
val = pxa_ssp_read_reg(ssp, SSACD);
|
2008-07-30 14:12:04 -04:00
|
|
|
val &= ~SSACD_SCDB;
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA3xx_SSP)
|
2008-07-30 14:12:04 -04:00
|
|
|
val &= ~SSACD_SCDX8;
|
|
|
|
switch (div) {
|
|
|
|
case PXA_SSP_CLK_SCDB_1:
|
|
|
|
val |= SSACD_SCDB;
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_SCDB_4:
|
|
|
|
break;
|
|
|
|
case PXA_SSP_CLK_SCDB_8:
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA3xx_SSP)
|
2008-07-30 14:12:04 -04:00
|
|
|
val |= SSACD_SCDX8;
|
|
|
|
else
|
|
|
|
return -EINVAL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSACD, val);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case PXA_SSP_DIV_SCR:
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_set_scr(ssp, div);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure the PLL frequency pxa27x and (afaik - pxa320 only)
|
|
|
|
*/
|
2009-09-05 13:52:16 -04:00
|
|
|
static int pxa_ssp_set_dai_pll(struct snd_soc_dai *cpu_dai, int pll_id,
|
|
|
|
int source, unsigned int freq_in, unsigned int freq_out)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2010-05-05 10:11:15 -04:00
|
|
|
u32 ssacd = pxa_ssp_read_reg(ssp, SSACD) & ~0x70;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA3xx_SSP)
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSACDD, 0);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
switch (freq_out) {
|
|
|
|
case 5622000:
|
|
|
|
break;
|
|
|
|
case 11345000:
|
|
|
|
ssacd |= (0x1 << 4);
|
|
|
|
break;
|
|
|
|
case 12235000:
|
|
|
|
ssacd |= (0x2 << 4);
|
|
|
|
break;
|
|
|
|
case 14857000:
|
|
|
|
ssacd |= (0x3 << 4);
|
|
|
|
break;
|
|
|
|
case 32842000:
|
|
|
|
ssacd |= (0x4 << 4);
|
|
|
|
break;
|
|
|
|
case 48000000:
|
|
|
|
ssacd |= (0x5 << 4);
|
|
|
|
break;
|
|
|
|
case 0:
|
|
|
|
/* Disable */
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
/* PXA3xx has a clock ditherer which can be used to generate
|
|
|
|
* a wider range of frequencies - calculate a value for it.
|
|
|
|
*/
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA3xx_SSP) {
|
2008-07-30 14:12:04 -04:00
|
|
|
u32 val;
|
|
|
|
u64 tmp = 19968;
|
|
|
|
tmp *= 1000000;
|
|
|
|
do_div(tmp, freq_out);
|
|
|
|
val = tmp;
|
|
|
|
|
2009-08-18 14:18:35 -04:00
|
|
|
val = (val << 16) | 64;
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSACDD, val);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
ssacd |= (0x6 << 4);
|
|
|
|
|
|
|
|
dev_dbg(&ssp->pdev->dev,
|
2009-05-27 20:08:39 -04:00
|
|
|
"Using SSACDD %x to supply %uHz\n",
|
2008-07-30 14:12:04 -04:00
|
|
|
val, freq_out);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSACD, ssacd);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the active slots in TDM/Network mode
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
|
2009-06-15 20:44:31 -04:00
|
|
|
unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
u32 sscr0;
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
|
2009-06-15 20:44:31 -04:00
|
|
|
sscr0 &= ~(SSCR0_MOD | SSCR0_SlotsPerFrm(8) | SSCR0_EDSS | SSCR0_DSS);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2009-06-15 20:44:31 -04:00
|
|
|
/* set slot width */
|
|
|
|
if (slot_width > 16)
|
|
|
|
sscr0 |= SSCR0_EDSS | SSCR0_DataSize(slot_width - 16);
|
|
|
|
else
|
|
|
|
sscr0 |= SSCR0_DataSize(slot_width);
|
|
|
|
|
|
|
|
if (slots > 1) {
|
|
|
|
/* enable network mode */
|
|
|
|
sscr0 |= SSCR0_MOD;
|
|
|
|
|
|
|
|
/* set number of active slots */
|
|
|
|
sscr0 |= SSCR0_SlotsPerFrm(slots);
|
|
|
|
|
|
|
|
/* set active slot mask */
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSTSA, tx_mask);
|
|
|
|
pxa_ssp_write_reg(ssp, SSRSA, rx_mask);
|
2009-06-15 20:44:31 -04:00
|
|
|
}
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Tristate the SSP DAI lines
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_set_dai_tristate(struct snd_soc_dai *cpu_dai,
|
|
|
|
int tristate)
|
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
u32 sscr1;
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
|
2008-07-30 14:12:04 -04:00
|
|
|
if (tristate)
|
|
|
|
sscr1 &= ~SSCR1_TTE;
|
|
|
|
else
|
|
|
|
sscr1 |= SSCR1_TTE;
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSCR1, sscr1);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the SSP DAI format.
|
|
|
|
* The SSP Port must be inactive before calling this function as the
|
|
|
|
* physical interface format is changed.
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_set_dai_fmt(struct snd_soc_dai *cpu_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2010-08-13 09:55:35 -04:00
|
|
|
u32 sscr0, sscr1, sspsp, scfr;
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2009-03-10 11:41:00 -04:00
|
|
|
/* check if we need to change anything at all */
|
|
|
|
if (priv->dai_fmt == fmt)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* we can only change the settings if the port is not in use */
|
2010-05-05 10:11:15 -04:00
|
|
|
if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE) {
|
2009-03-10 11:41:00 -04:00
|
|
|
dev_err(&ssp->pdev->dev,
|
|
|
|
"can't change hardware dai format: stream is in use");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
/* reset port settings */
|
2010-05-05 10:11:15 -04:00
|
|
|
sscr0 = pxa_ssp_read_reg(ssp, SSCR0) &
|
2010-08-13 09:55:35 -04:00
|
|
|
~(SSCR0_ECS | SSCR0_NCS | SSCR0_MOD | SSCR0_ACS);
|
2008-07-30 14:12:04 -04:00
|
|
|
sscr1 = SSCR1_RxTresh(8) | SSCR1_TxTresh(7);
|
|
|
|
sspsp = 0;
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2010-08-13 09:55:35 -04:00
|
|
|
sscr1 |= SSCR1_SCLKDIR | SSCR1_SFRMDIR | SSCR1_SCFR;
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
2010-08-13 09:55:35 -04:00
|
|
|
sscr1 |= SSCR1_SCLKDIR | SSCR1_SCFR;
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2009-06-10 14:23:24 -04:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
sspsp |= SSPSP_SFRMP;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF:
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
sspsp |= SSPSP_SCMODE(2);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
sspsp |= SSPSP_SCMODE(2) | SSPSP_SFRMP;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
2009-03-12 06:27:49 -04:00
|
|
|
sscr0 |= SSCR0_PSP;
|
2008-07-30 14:12:04 -04:00
|
|
|
sscr1 |= SSCR1_RWOT | SSCR1_TRAIL;
|
2009-03-13 10:26:08 -04:00
|
|
|
/* See hw_params() */
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
sspsp |= SSPSP_FSRT;
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
|
|
|
sscr0 |= SSCR0_MOD | SSCR0_PSP;
|
|
|
|
sscr1 |= SSCR1_TRAIL | SSCR1_RWOT;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0);
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR1, sscr1);
|
|
|
|
pxa_ssp_write_reg(ssp, SSPSP, sspsp);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2010-08-13 09:55:35 -04:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
|
|
|
scfr = pxa_ssp_read_reg(ssp, SSCR1) | SSCR1_SCFR;
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR1, scfr);
|
|
|
|
|
|
|
|
while (pxa_ssp_read_reg(ssp, SSSR) & SSSR_BSY)
|
|
|
|
cpu_relax();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
dump_registers(ssp);
|
|
|
|
|
|
|
|
/* Since we are configuring the timings for the format by hand
|
|
|
|
* we have to defer some things until hw_params() where we
|
|
|
|
* know parameters like the sample size.
|
|
|
|
*/
|
|
|
|
priv->dai_fmt = fmt;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set the SSP audio DMA parameters and sample size.
|
|
|
|
* Can be called multiple times by oss emulation.
|
|
|
|
*/
|
|
|
|
static int pxa_ssp_hw_params(struct snd_pcm_substream *substream,
|
2008-11-18 17:11:38 -05:00
|
|
|
struct snd_pcm_hw_params *params,
|
2010-03-17 16:15:21 -04:00
|
|
|
struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2009-04-23 05:05:38 -04:00
|
|
|
int chn = params_channels(params);
|
2008-07-30 14:12:04 -04:00
|
|
|
u32 sscr0;
|
|
|
|
u32 sspsp;
|
|
|
|
int width = snd_pcm_format_physical_width(params_format(params));
|
2010-05-05 10:11:15 -04:00
|
|
|
int ttsa = pxa_ssp_read_reg(ssp, SSTSA) & 0xf;
|
2013-08-12 04:42:39 -04:00
|
|
|
struct snd_dmaengine_dai_dma_data *dma_data;
|
2010-03-22 05:11:15 -04:00
|
|
|
|
2010-03-17 16:15:21 -04:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
2009-03-19 04:32:01 -04:00
|
|
|
/* Network mode with one active slot (ttsa == 1) can be used
|
|
|
|
* to force 16-bit frame width on the wire (for S16_LE), even
|
|
|
|
* with two channels. Use 16-bit DMA transfers for this case.
|
|
|
|
*/
|
2012-05-07 03:34:24 -04:00
|
|
|
pxa_ssp_set_dma_params(ssp,
|
|
|
|
((chn == 2) && (ttsa != 1)) || (width == 32),
|
|
|
|
substream->stream == SNDRV_PCM_STREAM_PLAYBACK, dma_data);
|
2010-03-22 05:11:15 -04:00
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
/* we can only change the settings if the port is not in use */
|
2010-05-05 10:11:15 -04:00
|
|
|
if (pxa_ssp_read_reg(ssp, SSCR0) & SSCR0_SSE)
|
2008-07-30 14:12:04 -04:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
/* clear selected SSP bits */
|
2010-05-05 10:11:15 -04:00
|
|
|
sscr0 = pxa_ssp_read_reg(ssp, SSCR0) & ~(SSCR0_DSS | SSCR0_EDSS);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
/* bit size */
|
|
|
|
switch (params_format(params)) {
|
|
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type == PXA3xx_SSP)
|
2008-07-30 14:12:04 -04:00
|
|
|
sscr0 |= SSCR0_FPCKE;
|
|
|
|
sscr0 |= SSCR0_DataSize(16);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S24_LE:
|
|
|
|
sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(8));
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S32_LE:
|
|
|
|
sscr0 |= (SSCR0_EDSS | SSCR0_DataSize(16));
|
|
|
|
break;
|
|
|
|
}
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
switch (priv->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
2010-05-05 10:11:15 -04:00
|
|
|
sspsp = pxa_ssp_read_reg(ssp, SSPSP);
|
2009-03-12 06:27:49 -04:00
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
if ((pxa_ssp_get_scr(ssp) == 4) && (width == 16)) {
|
2009-03-12 06:27:49 -04:00
|
|
|
/* This is a special case where the bitclk is 64fs
|
|
|
|
* and we're not dealing with 2*32 bits of audio
|
|
|
|
* samples.
|
|
|
|
*
|
|
|
|
* The SSP values used for that are all found out by
|
|
|
|
* trying and failing a lot; some of the registers
|
|
|
|
* needed for that mode are only available on PXA3xx.
|
|
|
|
*/
|
2012-06-03 22:41:04 -04:00
|
|
|
if (ssp->type != PXA3xx_SSP)
|
2009-03-12 06:27:49 -04:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
sspsp |= SSPSP_SFRMWDTH(width * 2);
|
|
|
|
sspsp |= SSPSP_SFRMDLY(width * 4);
|
|
|
|
sspsp |= SSPSP_EDMYSTOP(3);
|
|
|
|
sspsp |= SSPSP_DMYSTOP(3);
|
|
|
|
sspsp |= SSPSP_DMYSTRT(1);
|
2009-03-13 10:26:08 -04:00
|
|
|
} else {
|
|
|
|
/* The frame width is the width the LRCLK is
|
|
|
|
* asserted for; the delay is expressed in
|
|
|
|
* half cycle units. We need the extra cycle
|
|
|
|
* because the data starts clocking out one BCLK
|
|
|
|
* after LRCLK changes polarity.
|
|
|
|
*/
|
|
|
|
sspsp |= SSPSP_SFRMWDTH(width + 1);
|
|
|
|
sspsp |= SSPSP_SFRMDLY((width + 1) * 2);
|
|
|
|
sspsp |= SSPSP_DMYSTRT(1);
|
|
|
|
}
|
2009-03-12 06:27:49 -04:00
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_write_reg(ssp, SSPSP, sspsp);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2009-03-12 06:27:49 -04:00
|
|
|
/* When we use a network mode, we always require TDM slots
|
2008-07-30 14:12:04 -04:00
|
|
|
* - complain loudly and fail if they've not been set up yet.
|
|
|
|
*/
|
2009-03-19 04:32:01 -04:00
|
|
|
if ((sscr0 & SSCR0_MOD) && !ttsa) {
|
2008-07-30 14:12:04 -04:00
|
|
|
dev_err(&ssp->pdev->dev, "No TDM timeslot configured\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_registers(ssp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-19 04:12:53 -04:00
|
|
|
static void pxa_ssp_set_running_bit(struct snd_pcm_substream *substream,
|
|
|
|
struct ssp_device *ssp, int value)
|
|
|
|
{
|
|
|
|
uint32_t sscr0 = pxa_ssp_read_reg(ssp, SSCR0);
|
|
|
|
uint32_t sscr1 = pxa_ssp_read_reg(ssp, SSCR1);
|
|
|
|
uint32_t sspsp = pxa_ssp_read_reg(ssp, SSPSP);
|
|
|
|
uint32_t sssr = pxa_ssp_read_reg(ssp, SSSR);
|
|
|
|
|
|
|
|
if (value && (sscr0 & SSCR0_SSE))
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0 & ~SSCR0_SSE);
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
if (value)
|
|
|
|
sscr1 |= SSCR1_TSRE;
|
|
|
|
else
|
|
|
|
sscr1 &= ~SSCR1_TSRE;
|
|
|
|
} else {
|
|
|
|
if (value)
|
|
|
|
sscr1 |= SSCR1_RSRE;
|
|
|
|
else
|
|
|
|
sscr1 &= ~SSCR1_RSRE;
|
|
|
|
}
|
|
|
|
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR1, sscr1);
|
|
|
|
|
|
|
|
if (value) {
|
|
|
|
pxa_ssp_write_reg(ssp, SSSR, sssr);
|
|
|
|
pxa_ssp_write_reg(ssp, SSPSP, sspsp);
|
|
|
|
pxa_ssp_write_reg(ssp, SSCR0, sscr0 | SSCR0_SSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-18 17:11:38 -05:00
|
|
|
static int pxa_ssp_trigger(struct snd_pcm_substream *substream, int cmd,
|
2010-03-17 16:15:21 -04:00
|
|
|
struct snd_soc_dai *cpu_dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
|
|
|
int ret = 0;
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(cpu_dai);
|
2010-02-09 06:46:01 -05:00
|
|
|
struct ssp_device *ssp = priv->ssp;
|
2008-07-30 14:12:04 -04:00
|
|
|
int val;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_enable(ssp);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2012-03-19 04:12:53 -04:00
|
|
|
pxa_ssp_set_running_bit(substream, ssp, 1);
|
2010-05-05 10:11:15 -04:00
|
|
|
val = pxa_ssp_read_reg(ssp, SSSR);
|
|
|
|
pxa_ssp_write_reg(ssp, SSSR, val);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2012-03-19 04:12:53 -04:00
|
|
|
pxa_ssp_set_running_bit(substream, ssp, 1);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2012-03-19 04:12:53 -04:00
|
|
|
pxa_ssp_set_running_bit(substream, ssp, 0);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_disable(ssp);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
2012-03-19 04:12:53 -04:00
|
|
|
pxa_ssp_set_running_bit(substream, ssp, 0);
|
2008-07-30 14:12:04 -04:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
dump_registers(ssp);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-17 16:15:21 -04:00
|
|
|
static int pxa_ssp_probe(struct snd_soc_dai *dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2013-08-12 04:42:38 -04:00
|
|
|
struct device *dev = dai->dev;
|
2008-07-30 14:12:04 -04:00
|
|
|
struct ssp_priv *priv;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
priv = kzalloc(sizeof(struct ssp_priv), GFP_KERNEL);
|
|
|
|
if (!priv)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2013-08-12 04:42:38 -04:00
|
|
|
if (dev->of_node) {
|
|
|
|
struct device_node *ssp_handle;
|
|
|
|
|
|
|
|
ssp_handle = of_parse_phandle(dev->of_node, "port", 0);
|
|
|
|
if (!ssp_handle) {
|
|
|
|
dev_err(dev, "unable to get 'port' phandle\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
priv->ssp = pxa_ssp_request_of(ssp_handle, "SoC audio");
|
|
|
|
if (priv->ssp == NULL) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_priv;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
priv->ssp = pxa_ssp_request(dai->id + 1, "SoC audio");
|
|
|
|
if (priv->ssp == NULL) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto err_priv;
|
|
|
|
}
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
|
|
|
|
2009-04-15 14:24:45 -04:00
|
|
|
priv->dai_fmt = (unsigned int) -1;
|
2010-03-17 16:15:21 -04:00
|
|
|
snd_soc_dai_set_drvdata(dai, priv);
|
2008-07-30 14:12:04 -04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_priv:
|
|
|
|
kfree(priv);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-17 16:15:21 -04:00
|
|
|
static int pxa_ssp_remove(struct snd_soc_dai *dai)
|
2008-07-30 14:12:04 -04:00
|
|
|
{
|
2010-03-17 16:15:21 -04:00
|
|
|
struct ssp_priv *priv = snd_soc_dai_get_drvdata(dai);
|
|
|
|
|
2010-05-05 10:11:15 -04:00
|
|
|
pxa_ssp_free(priv->ssp);
|
2010-08-25 04:59:11 -04:00
|
|
|
kfree(priv);
|
2010-03-17 16:15:21 -04:00
|
|
|
return 0;
|
2008-07-30 14:12:04 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define PXA_SSP_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
|
|
|
|
SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
|
2012-03-07 21:02:36 -05:00
|
|
|
SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
|
|
|
|
SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
|
2008-07-30 14:12:04 -04:00
|
|
|
SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
|
|
|
|
|
|
|
|
#define PXA_SSP_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE)
|
|
|
|
|
2011-11-23 05:40:40 -05:00
|
|
|
static const struct snd_soc_dai_ops pxa_ssp_dai_ops = {
|
2009-03-02 20:41:00 -05:00
|
|
|
.startup = pxa_ssp_startup,
|
|
|
|
.shutdown = pxa_ssp_shutdown,
|
|
|
|
.trigger = pxa_ssp_trigger,
|
|
|
|
.hw_params = pxa_ssp_hw_params,
|
|
|
|
.set_sysclk = pxa_ssp_set_dai_sysclk,
|
|
|
|
.set_clkdiv = pxa_ssp_set_dai_clkdiv,
|
|
|
|
.set_pll = pxa_ssp_set_dai_pll,
|
|
|
|
.set_fmt = pxa_ssp_set_dai_fmt,
|
|
|
|
.set_tdm_slot = pxa_ssp_set_dai_tdm_slot,
|
|
|
|
.set_tristate = pxa_ssp_set_dai_tristate,
|
|
|
|
};
|
|
|
|
|
2010-03-17 16:15:21 -04:00
|
|
|
static struct snd_soc_dai_driver pxa_ssp_dai = {
|
2008-07-30 14:12:04 -04:00
|
|
|
.probe = pxa_ssp_probe,
|
|
|
|
.remove = pxa_ssp_remove,
|
|
|
|
.suspend = pxa_ssp_suspend,
|
|
|
|
.resume = pxa_ssp_resume,
|
|
|
|
.playback = {
|
|
|
|
.channels_min = 1,
|
2009-09-25 08:30:26 -04:00
|
|
|
.channels_max = 8,
|
2008-07-30 14:12:04 -04:00
|
|
|
.rates = PXA_SSP_RATES,
|
|
|
|
.formats = PXA_SSP_FORMATS,
|
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.channels_min = 1,
|
2009-09-25 08:30:26 -04:00
|
|
|
.channels_max = 8,
|
2008-07-30 14:12:04 -04:00
|
|
|
.rates = PXA_SSP_RATES,
|
|
|
|
.formats = PXA_SSP_FORMATS,
|
|
|
|
},
|
2009-03-02 20:41:00 -05:00
|
|
|
.ops = &pxa_ssp_dai_ops,
|
2010-03-17 16:15:21 -04:00
|
|
|
};
|
|
|
|
|
2013-03-21 06:34:12 -04:00
|
|
|
static const struct snd_soc_component_driver pxa_ssp_component = {
|
|
|
|
.name = "pxa-ssp",
|
|
|
|
};
|
|
|
|
|
2013-08-12 04:42:38 -04:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id pxa_ssp_of_ids[] = {
|
|
|
|
{ .compatible = "mrvl,pxa-ssp-dai" },
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2012-12-07 09:26:17 -05:00
|
|
|
static int asoc_ssp_probe(struct platform_device *pdev)
|
2010-03-17 16:15:21 -04:00
|
|
|
{
|
2013-03-21 06:34:12 -04:00
|
|
|
return snd_soc_register_component(&pdev->dev, &pxa_ssp_component,
|
|
|
|
&pxa_ssp_dai, 1);
|
2010-03-17 16:15:21 -04:00
|
|
|
}
|
|
|
|
|
2012-12-07 09:26:17 -05:00
|
|
|
static int asoc_ssp_remove(struct platform_device *pdev)
|
2010-03-17 16:15:21 -04:00
|
|
|
{
|
2013-03-21 06:34:12 -04:00
|
|
|
snd_soc_unregister_component(&pdev->dev);
|
2010-03-17 16:15:21 -04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver asoc_ssp_driver = {
|
|
|
|
.driver = {
|
2013-08-12 04:42:38 -04:00
|
|
|
.name = "pxa-ssp-dai",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.of_match_table = of_match_ptr(pxa_ssp_of_ids),
|
2008-07-30 14:12:04 -04:00
|
|
|
},
|
2010-03-17 16:15:21 -04:00
|
|
|
|
|
|
|
.probe = asoc_ssp_probe,
|
2012-12-07 09:26:17 -05:00
|
|
|
.remove = asoc_ssp_remove,
|
2008-07-30 14:12:04 -04:00
|
|
|
};
|
|
|
|
|
2011-11-24 21:13:37 -05:00
|
|
|
module_platform_driver(asoc_ssp_driver);
|
2008-12-03 14:26:35 -05:00
|
|
|
|
2008-07-30 14:12:04 -04:00
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
|
|
|
|
MODULE_DESCRIPTION("PXA SSP/PCM SoC Interface");
|
|
|
|
MODULE_LICENSE("GPL");
|