2009-11-25 23:41:04 +08:00
|
|
|
/*
|
|
|
|
* imx-ssi.c -- ALSA Soc Audio Layer
|
|
|
|
*
|
|
|
|
* Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
|
|
|
|
*
|
|
|
|
* This code is based on code copyrighted by Freescale,
|
|
|
|
* Liam Girdwood, Javier Martin and probably others.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* The i.MX SSI core has some nasty limitations in AC97 mode. While most
|
|
|
|
* sane processor vendors have a FIFO per AC97 slot, the i.MX has only
|
|
|
|
* one FIFO which combines all valid receive slots. We cannot even select
|
|
|
|
* which slots we want to receive. The WM9712 with which this driver
|
2011-03-31 09:57:33 +08:00
|
|
|
* was developed with always sends GPIO status data in slot 12 which
|
2009-11-25 23:41:04 +08:00
|
|
|
* we receive in our (PCM-) data stream. The only chance we have is to
|
|
|
|
* manually skip this data in the FIQ handler. With sampling rates different
|
|
|
|
* from 48000Hz not every frame has valid receive data, so the ratio
|
|
|
|
* between pcm data and GPIO status data changes. Our FIQ handler is not
|
|
|
|
* able to handle this, hence this driver only works with 48000Hz sampling
|
|
|
|
* rate.
|
2010-07-13 17:27:58 +08:00
|
|
|
* Reading and writing AC97 registers is another challenge. The core
|
2009-11-25 23:41:04 +08:00
|
|
|
* provides us status bits when the read register is updated with *another*
|
|
|
|
* value. When we read the same register two times (and the register still
|
|
|
|
* contains the same value) these status bits are not set. We work
|
|
|
|
* around this by not polling these bits but only wait a fixed delay.
|
2012-03-16 16:56:38 +08:00
|
|
|
*
|
2009-11-25 23:41:04 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
2012-08-24 21:14:29 +08:00
|
|
|
#include <linux/platform_data/asoc-imx-ssi.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
#include "imx-ssi.h"
|
|
|
|
|
|
|
|
#define SSI_SACNT_DEFAULT (SSI_SACNT_AC97EN | SSI_SACNT_FV)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSI Network Mode or TDM slots configuration.
|
|
|
|
* Should only be called when port is inactive (i.e. SSIEN = 0).
|
|
|
|
*/
|
|
|
|
static int imx_ssi_set_dai_tdm_slot(struct snd_soc_dai *cpu_dai,
|
|
|
|
unsigned int tx_mask, unsigned int rx_mask, int slots, int slot_width)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
u32 sccr;
|
|
|
|
|
|
|
|
sccr = readl(ssi->base + SSI_STCCR);
|
|
|
|
sccr &= ~SSI_STCCR_DC_MASK;
|
|
|
|
sccr |= SSI_STCCR_DC(slots - 1);
|
|
|
|
writel(sccr, ssi->base + SSI_STCCR);
|
|
|
|
|
|
|
|
sccr = readl(ssi->base + SSI_SRCCR);
|
|
|
|
sccr &= ~SSI_STCCR_DC_MASK;
|
|
|
|
sccr |= SSI_STCCR_DC(slots - 1);
|
|
|
|
writel(sccr, ssi->base + SSI_SRCCR);
|
|
|
|
|
|
|
|
writel(tx_mask, ssi->base + SSI_STMSK);
|
|
|
|
writel(rx_mask, ssi->base + SSI_SRMSK);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSI DAI format configuration.
|
|
|
|
* Should only be called when port is inactive (i.e. SSIEN = 0).
|
|
|
|
*/
|
|
|
|
static int imx_ssi_set_dai_fmt(struct snd_soc_dai *cpu_dai, unsigned int fmt)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
u32 strcr = 0, scr;
|
|
|
|
|
|
|
|
scr = readl(ssi->base + SSI_SCR) & ~(SSI_SCR_SYN | SSI_SCR_NET);
|
|
|
|
|
|
|
|
/* DAI mode */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
/* data on rising edge of bclk, frame low 1clk before data */
|
|
|
|
strcr |= SSI_STCR_TFSI | SSI_STCR_TEFS | SSI_STCR_TXBIT0;
|
|
|
|
scr |= SSI_SCR_NET;
|
2010-05-27 16:58:54 +08:00
|
|
|
if (ssi->flags & IMX_SSI_USE_I2S_SLAVE) {
|
|
|
|
scr &= ~SSI_I2S_MODE_MASK;
|
|
|
|
scr |= SSI_SCR_I2S_MODE_SLAVE;
|
|
|
|
}
|
2009-11-25 23:41:04 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
/* data on rising edge of bclk, frame high with data */
|
|
|
|
strcr |= SSI_STCR_TXBIT0;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
|
|
|
/* data on rising edge of bclk, frame high with data */
|
2011-03-01 22:02:06 +08:00
|
|
|
strcr |= SSI_STCR_TFSL | SSI_STCR_TXBIT0;
|
2009-11-25 23:41:04 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
/* data on rising edge of bclk, frame high 1clk before data */
|
2012-02-23 22:43:18 +08:00
|
|
|
strcr |= SSI_STCR_TFSL | SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
|
2009-11-25 23:41:04 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DAI clock inversion */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
strcr |= SSI_STCR_TFSI;
|
|
|
|
strcr &= ~SSI_STCR_TSCKP;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
strcr &= ~(SSI_STCR_TSCKP | SSI_STCR_TFSI);
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF:
|
|
|
|
strcr |= SSI_STCR_TFSI | SSI_STCR_TSCKP;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
strcr &= ~SSI_STCR_TFSI;
|
|
|
|
strcr |= SSI_STCR_TSCKP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DAI clock master masks */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
2010-01-12 00:56:19 +08:00
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2009-11-25 23:41:04 +08:00
|
|
|
break;
|
2010-01-12 00:56:19 +08:00
|
|
|
default:
|
|
|
|
/* Master mode not implemented, needs handling of clocks. */
|
|
|
|
return -EINVAL;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
strcr |= SSI_STCR_TFEN0;
|
|
|
|
|
2010-05-27 16:58:54 +08:00
|
|
|
if (ssi->flags & IMX_SSI_NET)
|
|
|
|
scr |= SSI_SCR_NET;
|
|
|
|
if (ssi->flags & IMX_SSI_SYN)
|
|
|
|
scr |= SSI_SCR_SYN;
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
writel(strcr, ssi->base + SSI_STCR);
|
|
|
|
writel(strcr, ssi->base + SSI_SRCR);
|
|
|
|
writel(scr, ssi->base + SSI_SCR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSI system clock configuration.
|
|
|
|
* Should only be called when port is inactive (i.e. SSIEN = 0).
|
|
|
|
*/
|
|
|
|
static int imx_ssi_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
|
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
u32 scr;
|
|
|
|
|
|
|
|
scr = readl(ssi->base + SSI_SCR);
|
|
|
|
|
|
|
|
switch (clk_id) {
|
|
|
|
case IMX_SSP_SYS_CLK:
|
|
|
|
if (dir == SND_SOC_CLOCK_OUT)
|
|
|
|
scr |= SSI_SCR_SYS_CLK_EN;
|
|
|
|
else
|
|
|
|
scr &= ~SSI_SCR_SYS_CLK_EN;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(scr, ssi->base + SSI_SCR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* SSI Clock dividers
|
|
|
|
* Should only be called when port is inactive (i.e. SSIEN = 0).
|
|
|
|
*/
|
|
|
|
static int imx_ssi_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,
|
|
|
|
int div_id, int div)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
u32 stccr, srccr;
|
|
|
|
|
|
|
|
stccr = readl(ssi->base + SSI_STCCR);
|
|
|
|
srccr = readl(ssi->base + SSI_SRCCR);
|
|
|
|
|
|
|
|
switch (div_id) {
|
|
|
|
case IMX_SSI_TX_DIV_2:
|
|
|
|
stccr &= ~SSI_STCCR_DIV2;
|
|
|
|
stccr |= div;
|
|
|
|
break;
|
|
|
|
case IMX_SSI_TX_DIV_PSR:
|
|
|
|
stccr &= ~SSI_STCCR_PSR;
|
|
|
|
stccr |= div;
|
|
|
|
break;
|
|
|
|
case IMX_SSI_TX_DIV_PM:
|
|
|
|
stccr &= ~0xff;
|
|
|
|
stccr |= SSI_STCCR_PM(div);
|
|
|
|
break;
|
|
|
|
case IMX_SSI_RX_DIV_2:
|
|
|
|
stccr &= ~SSI_STCCR_DIV2;
|
|
|
|
stccr |= div;
|
|
|
|
break;
|
|
|
|
case IMX_SSI_RX_DIV_PSR:
|
|
|
|
stccr &= ~SSI_STCCR_PSR;
|
|
|
|
stccr |= div;
|
|
|
|
break;
|
|
|
|
case IMX_SSI_RX_DIV_PM:
|
|
|
|
stccr &= ~0xff;
|
|
|
|
stccr |= SSI_STCCR_PM(div);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(stccr, ssi->base + SSI_STCCR);
|
|
|
|
writel(srccr, ssi->base + SSI_SRCCR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-22 17:49:05 +08:00
|
|
|
static int imx_ssi_startup(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *cpu_dai)
|
|
|
|
{
|
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
|
|
|
struct imx_pcm_dma_params *dma_data;
|
|
|
|
|
|
|
|
/* Tx/Rx config */
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
dma_data = &ssi->dma_params_tx;
|
|
|
|
else
|
|
|
|
dma_data = &ssi->dma_params_rx;
|
|
|
|
|
|
|
|
snd_soc_dai_set_dma_data(cpu_dai, substream, dma_data);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
/*
|
|
|
|
* Should only be called when port is inactive (i.e. SSIEN = 0),
|
|
|
|
* although can be called multiple times by upper layers.
|
|
|
|
*/
|
|
|
|
static int imx_ssi_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *cpu_dai)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(cpu_dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
u32 reg, sccr;
|
|
|
|
|
|
|
|
/* Tx/Rx config */
|
2012-02-22 17:49:05 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2009-11-25 23:41:04 +08:00
|
|
|
reg = SSI_STCCR;
|
2012-02-22 17:49:05 +08:00
|
|
|
else
|
2009-11-25 23:41:04 +08:00
|
|
|
reg = SSI_SRCCR;
|
|
|
|
|
2010-08-23 14:54:02 +08:00
|
|
|
if (ssi->flags & IMX_SSI_SYN)
|
|
|
|
reg = SSI_STCCR;
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
sccr = readl(ssi->base + reg) & ~SSI_STCCR_WL_MASK;
|
|
|
|
|
|
|
|
/* DAI data (word) size */
|
|
|
|
switch (params_format(params)) {
|
|
|
|
case SNDRV_PCM_FORMAT_S16_LE:
|
|
|
|
sccr |= SSI_SRCCR_WL(16);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S20_3LE:
|
|
|
|
sccr |= SSI_SRCCR_WL(20);
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_FORMAT_S24_LE:
|
|
|
|
sccr |= SSI_SRCCR_WL(24);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(sccr, ssi->base + reg);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct imx_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
unsigned int sier_bits, sier;
|
|
|
|
unsigned int scr;
|
|
|
|
|
|
|
|
scr = readl(ssi->base + SSI_SCR);
|
|
|
|
sier = readl(ssi->base + SSI_SIER);
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
if (ssi->flags & IMX_SSI_DMA)
|
|
|
|
sier_bits = SSI_SIER_TDMAE;
|
|
|
|
else
|
|
|
|
sier_bits = SSI_SIER_TIE | SSI_SIER_TFE0_EN;
|
|
|
|
} else {
|
|
|
|
if (ssi->flags & IMX_SSI_DMA)
|
|
|
|
sier_bits = SSI_SIER_RDMAE;
|
|
|
|
else
|
|
|
|
sier_bits = SSI_SIER_RIE | SSI_SIER_RFF0_EN;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
scr |= SSI_SCR_TE;
|
|
|
|
else
|
|
|
|
scr |= SSI_SCR_RE;
|
|
|
|
sier |= sier_bits;
|
|
|
|
|
|
|
|
if (++ssi->enabled == 1)
|
|
|
|
scr |= SSI_SCR_SSIEN;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
scr &= ~SSI_SCR_TE;
|
|
|
|
else
|
|
|
|
scr &= ~SSI_SCR_RE;
|
|
|
|
sier &= ~sier_bits;
|
|
|
|
|
|
|
|
if (--ssi->enabled == 0)
|
|
|
|
scr &= ~SSI_SCR_SSIEN;
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(ssi->flags & IMX_SSI_USE_AC97))
|
|
|
|
/* rx/tx are always enabled to access ac97 registers */
|
|
|
|
writel(scr, ssi->base + SSI_SCR);
|
|
|
|
|
|
|
|
writel(sier, ssi->base + SSI_SIER);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = {
|
2012-02-22 17:49:05 +08:00
|
|
|
.startup = imx_ssi_startup,
|
2009-11-25 23:41:04 +08:00
|
|
|
.hw_params = imx_ssi_hw_params,
|
|
|
|
.set_fmt = imx_ssi_set_dai_fmt,
|
|
|
|
.set_clkdiv = imx_ssi_set_dai_clkdiv,
|
|
|
|
.set_sysclk = imx_ssi_set_dai_sysclk,
|
|
|
|
.set_tdm_slot = imx_ssi_set_dai_tdm_slot,
|
|
|
|
.trigger = imx_ssi_trigger,
|
|
|
|
};
|
|
|
|
|
2010-11-05 00:05:42 +08:00
|
|
|
static int imx_ssi_dai_probe(struct snd_soc_dai *dai)
|
|
|
|
{
|
|
|
|
struct imx_ssi *ssi = dev_get_drvdata(dai->dev);
|
|
|
|
uint32_t val;
|
|
|
|
|
|
|
|
snd_soc_dai_set_drvdata(dai, ssi);
|
|
|
|
|
|
|
|
val = SSI_SFCSR_TFWM0(ssi->dma_params_tx.burstsize) |
|
|
|
|
SSI_SFCSR_RFWM0(ssi->dma_params_rx.burstsize);
|
|
|
|
writel(val, ssi->base + SSI_SFCSR);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_dai_driver imx_ssi_dai = {
|
2010-11-05 00:05:42 +08:00
|
|
|
.probe = imx_ssi_dai_probe,
|
2010-03-18 04:15:21 +08:00
|
|
|
.playback = {
|
2012-09-06 08:30:10 +08:00
|
|
|
.channels_min = 1,
|
2010-03-18 04:15:21 +08:00
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_96000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
},
|
|
|
|
.capture = {
|
2012-09-06 08:30:10 +08:00
|
|
|
.channels_min = 1,
|
2010-03-18 04:15:21 +08:00
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_96000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
},
|
|
|
|
.ops = &imx_ssi_pcm_dai_ops,
|
2009-11-25 23:41:04 +08:00
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_dai_driver imx_ac97_dai = {
|
|
|
|
.probe = imx_ssi_dai_probe,
|
2009-11-25 23:41:04 +08:00
|
|
|
.ac97_control = 1,
|
|
|
|
.playback = {
|
|
|
|
.stream_name = "AC97 Playback",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_48000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "AC97 Capture",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_48000,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
},
|
|
|
|
.ops = &imx_ssi_pcm_dai_ops,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void setup_channel_to_ac97(struct imx_ssi *imx_ssi)
|
|
|
|
{
|
|
|
|
void __iomem *base = imx_ssi->base;
|
|
|
|
|
|
|
|
writel(0x0, base + SSI_SCR);
|
|
|
|
writel(0x0, base + SSI_STCR);
|
|
|
|
writel(0x0, base + SSI_SRCR);
|
|
|
|
|
|
|
|
writel(SSI_SCR_SYN | SSI_SCR_NET, base + SSI_SCR);
|
|
|
|
|
|
|
|
writel(SSI_SFCSR_RFWM0(8) |
|
|
|
|
SSI_SFCSR_TFWM0(8) |
|
|
|
|
SSI_SFCSR_RFWM1(8) |
|
|
|
|
SSI_SFCSR_TFWM1(8), base + SSI_SFCSR);
|
|
|
|
|
|
|
|
writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_STCCR);
|
|
|
|
writel(SSI_STCCR_WL(16) | SSI_STCCR_DC(12), base + SSI_SRCCR);
|
|
|
|
|
|
|
|
writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN, base + SSI_SCR);
|
|
|
|
writel(SSI_SOR_WAIT(3), base + SSI_SOR);
|
|
|
|
|
|
|
|
writel(SSI_SCR_SYN | SSI_SCR_NET | SSI_SCR_SSIEN |
|
|
|
|
SSI_SCR_TE | SSI_SCR_RE,
|
|
|
|
base + SSI_SCR);
|
|
|
|
|
|
|
|
writel(SSI_SACNT_DEFAULT, base + SSI_SACNT);
|
|
|
|
writel(0xff, base + SSI_SACCDIS);
|
|
|
|
writel(0x300, base + SSI_SACCEN);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct imx_ssi *ac97_ssi;
|
|
|
|
|
|
|
|
static void imx_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
|
|
|
|
unsigned short val)
|
|
|
|
{
|
|
|
|
struct imx_ssi *imx_ssi = ac97_ssi;
|
|
|
|
void __iomem *base = imx_ssi->base;
|
|
|
|
unsigned int lreg;
|
|
|
|
unsigned int lval;
|
|
|
|
|
|
|
|
if (reg > 0x7f)
|
|
|
|
return;
|
|
|
|
|
|
|
|
pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
|
|
|
|
|
|
|
|
lreg = reg << 12;
|
|
|
|
writel(lreg, base + SSI_SACADD);
|
|
|
|
|
|
|
|
lval = val << 4;
|
|
|
|
writel(lval , base + SSI_SACDAT);
|
|
|
|
|
|
|
|
writel(SSI_SACNT_DEFAULT | SSI_SACNT_WR, base + SSI_SACNT);
|
|
|
|
udelay(100);
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned short imx_ssi_ac97_read(struct snd_ac97 *ac97,
|
|
|
|
unsigned short reg)
|
|
|
|
{
|
|
|
|
struct imx_ssi *imx_ssi = ac97_ssi;
|
|
|
|
void __iomem *base = imx_ssi->base;
|
|
|
|
|
|
|
|
unsigned short val = -1;
|
|
|
|
unsigned int lreg;
|
|
|
|
|
|
|
|
lreg = (reg & 0x7f) << 12 ;
|
|
|
|
writel(lreg, base + SSI_SACADD);
|
|
|
|
writel(SSI_SACNT_DEFAULT | SSI_SACNT_RD, base + SSI_SACNT);
|
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
|
|
|
|
val = (readl(base + SSI_SACDAT) >> 4) & 0xffff;
|
|
|
|
|
|
|
|
pr_debug("%s: 0x%02x 0x%04x\n", __func__, reg, val);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_ssi_ac97_reset(struct snd_ac97 *ac97)
|
|
|
|
{
|
|
|
|
struct imx_ssi *imx_ssi = ac97_ssi;
|
|
|
|
|
|
|
|
if (imx_ssi->ac97_reset)
|
|
|
|
imx_ssi->ac97_reset(ac97);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void imx_ssi_ac97_warm_reset(struct snd_ac97 *ac97)
|
|
|
|
{
|
|
|
|
struct imx_ssi *imx_ssi = ac97_ssi;
|
|
|
|
|
|
|
|
if (imx_ssi->ac97_warm_reset)
|
|
|
|
imx_ssi->ac97_warm_reset(ac97);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct snd_ac97_bus_ops soc_ac97_ops = {
|
|
|
|
.read = imx_ssi_ac97_read,
|
|
|
|
.write = imx_ssi_ac97_write,
|
|
|
|
.reset = imx_ssi_ac97_reset,
|
|
|
|
.warm_reset = imx_ssi_ac97_warm_reset
|
|
|
|
};
|
|
|
|
EXPORT_SYMBOL_GPL(soc_ac97_ops);
|
|
|
|
|
|
|
|
static int imx_ssi_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct resource *res;
|
|
|
|
struct imx_ssi *ssi;
|
|
|
|
struct imx_ssi_platform_data *pdata = pdev->dev.platform_data;
|
|
|
|
int ret = 0;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai_driver *dai;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-07-28 01:32:10 +08:00
|
|
|
ssi = devm_kzalloc(&pdev->dev, sizeof(*ssi), GFP_KERNEL);
|
2009-11-25 23:41:04 +08:00
|
|
|
if (!ssi)
|
|
|
|
return -ENOMEM;
|
2010-03-18 04:15:21 +08:00
|
|
|
dev_set_drvdata(&pdev->dev, ssi);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
if (pdata) {
|
|
|
|
ssi->ac97_reset = pdata->ac97_reset;
|
|
|
|
ssi->ac97_warm_reset = pdata->ac97_warm_reset;
|
|
|
|
ssi->flags = pdata->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssi->irq = platform_get_irq(pdev, 0);
|
|
|
|
|
2012-07-28 01:32:10 +08:00
|
|
|
ssi->clk = devm_clk_get(&pdev->dev, NULL);
|
2009-11-25 23:41:04 +08:00
|
|
|
if (IS_ERR(ssi->clk)) {
|
|
|
|
ret = PTR_ERR(ssi->clk);
|
|
|
|
dev_err(&pdev->dev, "Cannot get the clock: %d\n",
|
|
|
|
ret);
|
|
|
|
goto failed_clk;
|
|
|
|
}
|
2012-05-26 04:27:20 +08:00
|
|
|
clk_prepare_enable(ssi->clk);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!res) {
|
|
|
|
ret = -ENODEV;
|
|
|
|
goto failed_get_resource;
|
|
|
|
}
|
|
|
|
|
2013-01-21 18:09:26 +08:00
|
|
|
ssi->base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(ssi->base)) {
|
|
|
|
ret = PTR_ERR(ssi->base);
|
2012-07-28 01:32:10 +08:00
|
|
|
goto failed_register;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ssi->flags & IMX_SSI_USE_AC97) {
|
|
|
|
if (ac97_ssi) {
|
2012-08-01 01:34:07 +08:00
|
|
|
dev_err(&pdev->dev, "AC'97 SSI already registered\n");
|
2009-11-25 23:41:04 +08:00
|
|
|
ret = -EBUSY;
|
2012-07-28 01:32:10 +08:00
|
|
|
goto failed_register;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
|
|
|
ac97_ssi = ssi;
|
|
|
|
setup_channel_to_ac97(ssi);
|
2010-03-18 04:15:21 +08:00
|
|
|
dai = &imx_ac97_dai;
|
2009-11-25 23:41:04 +08:00
|
|
|
} else
|
2010-03-18 04:15:21 +08:00
|
|
|
dai = &imx_ssi_dai;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
writel(0x0, ssi->base + SSI_SIER);
|
|
|
|
|
|
|
|
ssi->dma_params_rx.dma_addr = res->start + SSI_SRX0;
|
|
|
|
ssi->dma_params_tx.dma_addr = res->start + SSI_STX0;
|
|
|
|
|
2012-03-03 23:19:49 +08:00
|
|
|
ssi->dma_params_tx.burstsize = 6;
|
2011-03-01 22:02:06 +08:00
|
|
|
ssi->dma_params_rx.burstsize = 4;
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "tx0");
|
|
|
|
if (res)
|
|
|
|
ssi->dma_params_tx.dma = res->start;
|
|
|
|
|
|
|
|
res = platform_get_resource_byname(pdev, IORESOURCE_DMA, "rx0");
|
|
|
|
if (res)
|
|
|
|
ssi->dma_params_rx.dma = res->start;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
platform_set_drvdata(pdev, ssi);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
ret = snd_soc_register_dai(&pdev->dev, dai);
|
2009-11-25 23:41:04 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "register DAI failed\n");
|
|
|
|
goto failed_register;
|
|
|
|
}
|
|
|
|
|
2010-11-05 00:05:42 +08:00
|
|
|
ssi->soc_platform_pdev_fiq = platform_device_alloc("imx-fiq-pcm-audio", pdev->id);
|
2010-11-25 15:13:09 +08:00
|
|
|
if (!ssi->soc_platform_pdev_fiq) {
|
|
|
|
ret = -ENOMEM;
|
2010-11-05 00:05:42 +08:00
|
|
|
goto failed_pdev_fiq_alloc;
|
2010-11-25 15:13:09 +08:00
|
|
|
}
|
|
|
|
|
2010-11-05 00:05:42 +08:00
|
|
|
platform_set_drvdata(ssi->soc_platform_pdev_fiq, ssi);
|
|
|
|
ret = platform_device_add(ssi->soc_platform_pdev_fiq);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to add platform device\n");
|
|
|
|
goto failed_pdev_fiq_add;
|
|
|
|
}
|
|
|
|
|
|
|
|
ssi->soc_platform_pdev = platform_device_alloc("imx-pcm-audio", pdev->id);
|
2010-11-25 15:13:09 +08:00
|
|
|
if (!ssi->soc_platform_pdev) {
|
|
|
|
ret = -ENOMEM;
|
2010-03-18 04:15:21 +08:00
|
|
|
goto failed_pdev_alloc;
|
2010-11-25 15:13:09 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
platform_set_drvdata(ssi->soc_platform_pdev, ssi);
|
|
|
|
ret = platform_device_add(ssi->soc_platform_pdev);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to add platform device\n");
|
|
|
|
goto failed_pdev_add;
|
|
|
|
}
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
failed_pdev_add:
|
|
|
|
platform_device_put(ssi->soc_platform_pdev);
|
|
|
|
failed_pdev_alloc:
|
2010-11-25 15:13:09 +08:00
|
|
|
platform_device_del(ssi->soc_platform_pdev_fiq);
|
2010-11-05 00:05:42 +08:00
|
|
|
failed_pdev_fiq_add:
|
|
|
|
platform_device_put(ssi->soc_platform_pdev_fiq);
|
|
|
|
failed_pdev_fiq_alloc:
|
2010-03-18 04:15:21 +08:00
|
|
|
snd_soc_unregister_dai(&pdev->dev);
|
2009-11-25 23:41:04 +08:00
|
|
|
failed_register:
|
|
|
|
release_mem_region(res->start, resource_size(res));
|
|
|
|
failed_get_resource:
|
2012-05-26 04:27:20 +08:00
|
|
|
clk_disable_unprepare(ssi->clk);
|
2009-11-25 23:41:04 +08:00
|
|
|
failed_clk:
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:26:16 +08:00
|
|
|
static int imx_ssi_remove(struct platform_device *pdev)
|
2009-11-25 23:41:04 +08:00
|
|
|
{
|
|
|
|
struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
struct imx_ssi *ssi = platform_get_drvdata(pdev);
|
|
|
|
|
2010-11-25 15:13:09 +08:00
|
|
|
platform_device_unregister(ssi->soc_platform_pdev);
|
|
|
|
platform_device_unregister(ssi->soc_platform_pdev_fiq);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
snd_soc_unregister_dai(&pdev->dev);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
if (ssi->flags & IMX_SSI_USE_AC97)
|
|
|
|
ac97_ssi = NULL;
|
|
|
|
|
|
|
|
release_mem_region(res->start, resource_size(res));
|
2012-05-26 04:27:20 +08:00
|
|
|
clk_disable_unprepare(ssi->clk);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver imx_ssi_driver = {
|
|
|
|
.probe = imx_ssi_probe,
|
2012-12-07 22:26:16 +08:00
|
|
|
.remove = imx_ssi_remove,
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
.driver = {
|
2010-10-01 04:46:14 +08:00
|
|
|
.name = "imx-ssi",
|
2009-11-25 23:41:04 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-24 15:03:50 +08:00
|
|
|
module_platform_driver(imx_ssi_driver);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
/* Module information */
|
|
|
|
MODULE_AUTHOR("Sascha Hauer, <s.hauer@pengutronix.de>");
|
|
|
|
MODULE_DESCRIPTION("i.MX I2S/ac97 SoC Interface");
|
|
|
|
MODULE_LICENSE("GPL");
|
2011-06-23 04:21:49 +08:00
|
|
|
MODULE_ALIAS("platform:imx-ssi");
|