2008-01-12 01:15:26 +08:00
|
|
|
/*
|
|
|
|
* Freescale SSI ALSA SoC Digital Audio Interface (DAI) driver
|
|
|
|
*
|
|
|
|
* Author: Timur Tabi <timur@freescale.com>
|
|
|
|
*
|
2010-03-18 04:15:21 +08:00
|
|
|
* Copyright 2007-2010 Freescale Semiconductor, Inc.
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public License
|
|
|
|
* version 2. This program is licensed "as is" without any warranty of any
|
|
|
|
* kind, whether express or implied.
|
2013-07-27 19:31:53 +08:00
|
|
|
*
|
|
|
|
*
|
|
|
|
* Some notes why imx-pcm-fiq is used instead of DMA on some boards:
|
|
|
|
*
|
|
|
|
* 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
|
|
|
|
* was developed with always sends GPIO status data in slot 12 which
|
|
|
|
* 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.
|
|
|
|
* Reading and writing AC97 registers is another challenge. The core
|
|
|
|
* 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.
|
2008-01-12 01:15:26 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
2012-03-16 16:56:42 +08:00
|
|
|
#include <linux/io.h>
|
2008-01-12 01:15:26 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/interrupt.h>
|
2012-03-29 10:53:41 +08:00
|
|
|
#include <linux/clk.h>
|
2017-04-06 03:44:06 +08:00
|
|
|
#include <linux/ctype.h>
|
2008-01-12 01:15:26 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/delay.h>
|
2017-11-21 06:16:07 +08:00
|
|
|
#include <linux/mutex.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>
|
2013-12-12 18:44:45 +08:00
|
|
|
#include <linux/spinlock.h>
|
2014-04-15 19:02:02 +08:00
|
|
|
#include <linux/of.h>
|
2012-03-16 16:56:42 +08:00
|
|
|
#include <linux/of_address.h>
|
|
|
|
#include <linux/of_irq.h>
|
2010-03-18 04:15:21 +08:00
|
|
|
#include <linux/of_platform.h>
|
2008-01-12 01:15:26 +08:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/soc.h>
|
2013-04-03 17:06:04 +08:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2008-01-12 01:15:26 +08:00
|
|
|
|
|
|
|
#include "fsl_ssi.h"
|
2012-03-16 16:56:43 +08:00
|
|
|
#include "imx-pcm.h"
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2018-02-13 06:03:09 +08:00
|
|
|
/* Define RX and TX to index ssi->regvals array; Can be 0 or 1 only */
|
|
|
|
#define RX 0
|
|
|
|
#define TX 1
|
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
|
|
|
* FSLSSI_I2S_FORMATS: audio formats supported by the SSI
|
|
|
|
*
|
|
|
|
* The SSI has a limitation in that the samples must be in the same byte
|
|
|
|
* order as the host CPU. This is because when multiple bytes are written
|
|
|
|
* to the STX register, the bytes and bits must be written in the same
|
|
|
|
* order. The STX is a shift register, so all the bits need to be aligned
|
|
|
|
* (bit-endianness must match byte-endianness). Processors typically write
|
|
|
|
* the bits within a byte in the same order that the bytes of a word are
|
|
|
|
* written in. So if the host CPU is big-endian, then only big-endian
|
|
|
|
* samples will be written to STX properly.
|
|
|
|
*/
|
|
|
|
#ifdef __BIG_ENDIAN
|
2017-12-18 10:52:04 +08:00
|
|
|
#define FSLSSI_I2S_FORMATS \
|
|
|
|
(SNDRV_PCM_FMTBIT_S8 | \
|
|
|
|
SNDRV_PCM_FMTBIT_S16_BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S18_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_BE)
|
2008-01-12 01:15:26 +08:00
|
|
|
#else
|
2017-12-18 10:52:04 +08:00
|
|
|
#define FSLSSI_I2S_FORMATS \
|
|
|
|
(SNDRV_PCM_FMTBIT_S8 | \
|
|
|
|
SNDRV_PCM_FMTBIT_S16_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S18_3LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE)
|
2008-01-12 01:15:26 +08:00
|
|
|
#endif
|
|
|
|
|
2017-12-18 10:52:04 +08:00
|
|
|
#define FSLSSI_SIER_DBG_RX_FLAGS \
|
|
|
|
(SSI_SIER_RFF0_EN | \
|
|
|
|
SSI_SIER_RLS_EN | \
|
|
|
|
SSI_SIER_RFS_EN | \
|
|
|
|
SSI_SIER_ROE0_EN | \
|
|
|
|
SSI_SIER_RFRC_EN)
|
|
|
|
#define FSLSSI_SIER_DBG_TX_FLAGS \
|
|
|
|
(SSI_SIER_TFE0_EN | \
|
|
|
|
SSI_SIER_TLS_EN | \
|
|
|
|
SSI_SIER_TFS_EN | \
|
|
|
|
SSI_SIER_TUE0_EN | \
|
|
|
|
SSI_SIER_TFRC_EN)
|
2013-12-20 21:11:30 +08:00
|
|
|
|
|
|
|
enum fsl_ssi_type {
|
|
|
|
FSL_SSI_MCP8610,
|
|
|
|
FSL_SSI_MX21,
|
2013-12-20 21:11:31 +08:00
|
|
|
FSL_SSI_MX35,
|
2013-12-20 21:11:30 +08:00
|
|
|
FSL_SSI_MX51,
|
|
|
|
};
|
|
|
|
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals {
|
2013-12-20 21:11:33 +08:00
|
|
|
u32 sier;
|
|
|
|
u32 srcr;
|
|
|
|
u32 stcr;
|
|
|
|
u32 scr;
|
|
|
|
};
|
|
|
|
|
2015-09-18 11:09:12 +08:00
|
|
|
static bool fsl_ssi_readable_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
2017-12-18 10:52:03 +08:00
|
|
|
case REG_SSI_SACCEN:
|
|
|
|
case REG_SSI_SACCDIS:
|
2015-09-18 11:09:12 +08:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool fsl_ssi_volatile_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
2017-12-18 10:52:03 +08:00
|
|
|
case REG_SSI_STX0:
|
|
|
|
case REG_SSI_STX1:
|
|
|
|
case REG_SSI_SRX0:
|
|
|
|
case REG_SSI_SRX1:
|
|
|
|
case REG_SSI_SISR:
|
|
|
|
case REG_SSI_SFCSR:
|
|
|
|
case REG_SSI_SACNT:
|
|
|
|
case REG_SSI_SACADD:
|
|
|
|
case REG_SSI_SACDAT:
|
|
|
|
case REG_SSI_SATAG:
|
|
|
|
case REG_SSI_SACCST:
|
|
|
|
case REG_SSI_SOR:
|
2015-09-18 11:09:12 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-21 04:31:48 +08:00
|
|
|
static bool fsl_ssi_precious_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
2017-12-18 10:52:03 +08:00
|
|
|
case REG_SSI_SRX0:
|
|
|
|
case REG_SSI_SRX1:
|
|
|
|
case REG_SSI_SISR:
|
|
|
|
case REG_SSI_SACADD:
|
|
|
|
case REG_SSI_SACDAT:
|
|
|
|
case REG_SSI_SATAG:
|
2015-12-21 04:31:48 +08:00
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 11:09:12 +08:00
|
|
|
static bool fsl_ssi_writeable_reg(struct device *dev, unsigned int reg)
|
|
|
|
{
|
|
|
|
switch (reg) {
|
2017-12-18 10:52:03 +08:00
|
|
|
case REG_SSI_SRX0:
|
|
|
|
case REG_SSI_SRX1:
|
|
|
|
case REG_SSI_SACCST:
|
2015-09-18 11:09:12 +08:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-27 16:24:25 +08:00
|
|
|
static const struct regmap_config fsl_ssi_regconfig = {
|
2017-12-18 10:52:03 +08:00
|
|
|
.max_register = REG_SSI_SACCDIS,
|
2014-05-27 16:24:25 +08:00
|
|
|
.reg_bits = 32,
|
|
|
|
.val_bits = 32,
|
|
|
|
.reg_stride = 4,
|
|
|
|
.val_format_endian = REGMAP_ENDIAN_NATIVE,
|
2017-12-18 10:52:03 +08:00
|
|
|
.num_reg_defaults_raw = REG_SSI_SACCDIS / sizeof(uint32_t) + 1,
|
2015-09-18 11:09:12 +08:00
|
|
|
.readable_reg = fsl_ssi_readable_reg,
|
|
|
|
.volatile_reg = fsl_ssi_volatile_reg,
|
2015-12-21 04:31:48 +08:00
|
|
|
.precious_reg = fsl_ssi_precious_reg,
|
2015-09-18 11:09:12 +08:00
|
|
|
.writeable_reg = fsl_ssi_writeable_reg,
|
2016-09-20 03:30:28 +08:00
|
|
|
.cache_type = REGCACHE_FLAT,
|
2014-05-27 16:24:25 +08:00
|
|
|
};
|
2009-03-27 00:42:38 +08:00
|
|
|
|
2014-05-27 16:24:18 +08:00
|
|
|
struct fsl_ssi_soc_data {
|
|
|
|
bool imx;
|
2016-01-19 03:07:44 +08:00
|
|
|
bool imx21regs; /* imx21-class SSI - no SACC{ST,EN,DIS} regs */
|
2014-05-27 16:24:18 +08:00
|
|
|
bool offline_config;
|
|
|
|
u32 sisr_write_mask;
|
|
|
|
};
|
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
2017-12-18 10:52:00 +08:00
|
|
|
* fsl_ssi: per-SSI private data
|
2008-01-12 01:15:26 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* @regs: Pointer to the regmap registers
|
2008-01-12 01:15:26 +08:00
|
|
|
* @irq: IRQ of this SSI
|
2014-05-27 16:24:24 +08:00
|
|
|
* @cpu_dai_drv: CPU DAI driver for this device
|
|
|
|
*
|
|
|
|
* @dai_fmt: DAI configuration this device is currently used with
|
2017-12-18 10:52:09 +08:00
|
|
|
* @i2s_net: I2S and Network mode configurations of SCR register
|
2014-05-27 16:24:24 +08:00
|
|
|
* @use_dma: DMA is used or FIQ with stream filter
|
2017-12-18 10:52:02 +08:00
|
|
|
* @use_dual_fifo: DMA with support for dual FIFO mode
|
|
|
|
* @has_ipg_clk_name: If "ipg" is in the clock name list of device tree
|
|
|
|
* @fifo_depth: Depth of the SSI FIFOs
|
|
|
|
* @slot_width: Width of each DAI slot
|
|
|
|
* @slots: Number of slots
|
2017-12-18 10:52:08 +08:00
|
|
|
* @regvals: Specific RX/TX register settings
|
2014-05-27 16:24:24 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* @clk: Clock source to access register
|
|
|
|
* @baudclk: Clock source to generate bit and frame-sync clocks
|
2014-05-27 16:24:24 +08:00
|
|
|
* @baudclk_streams: Active streams that are using baudclk
|
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* @regcache_sfcsr: Cache sfcsr register value during suspend and resume
|
|
|
|
* @regcache_sacnt: Cache sacnt register value during suspend and resume
|
|
|
|
*
|
2014-05-27 16:24:24 +08:00
|
|
|
* @dma_params_tx: DMA transmit parameters
|
|
|
|
* @dma_params_rx: DMA receive parameters
|
|
|
|
* @ssi_phys: physical address of the SSI registers
|
|
|
|
*
|
|
|
|
* @fiq_params: FIQ stream filtering parameters
|
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* @pdev: Pointer to pdev when using fsl-ssi as sound card (ppc only)
|
|
|
|
* TODO: Should be replaced with simple-sound-card
|
2014-05-27 16:24:24 +08:00
|
|
|
*
|
|
|
|
* @dbg_stats: Debugging statistics
|
|
|
|
*
|
2015-08-12 14:38:18 +08:00
|
|
|
* @soc: SoC specific data
|
2017-12-18 10:52:02 +08:00
|
|
|
* @dev: Pointer to &pdev->dev
|
|
|
|
*
|
|
|
|
* @fifo_watermark: The FIFO watermark setting. Notifies DMA when there are
|
|
|
|
* @fifo_watermark or fewer words in TX fifo or
|
|
|
|
* @fifo_watermark or more empty words in RX fifo.
|
|
|
|
* @dma_maxburst: Max number of words to transfer in one go. So far,
|
|
|
|
* this is always the same as fifo_watermark.
|
2017-01-04 02:22:57 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* @ac97_reg_lock: Mutex lock to serialize AC97 register access operations
|
2008-01-12 01:15:26 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi {
|
2014-05-27 16:24:25 +08:00
|
|
|
struct regmap *regs;
|
2015-01-14 20:48:59 +08:00
|
|
|
int irq;
|
2010-03-18 04:15:21 +08:00
|
|
|
struct snd_soc_dai_driver cpu_dai_drv;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2014-05-27 16:24:24 +08:00
|
|
|
unsigned int dai_fmt;
|
2017-12-18 10:52:09 +08:00
|
|
|
u8 i2s_net;
|
2013-07-27 19:31:53 +08:00
|
|
|
bool use_dma;
|
2013-11-13 22:55:26 +08:00
|
|
|
bool use_dual_fifo;
|
2014-09-16 10:13:16 +08:00
|
|
|
bool has_ipg_clk_name;
|
2014-05-27 16:24:24 +08:00
|
|
|
unsigned int fifo_depth;
|
2017-09-14 11:07:09 +08:00
|
|
|
unsigned int slot_width;
|
|
|
|
unsigned int slots;
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals regvals[2];
|
2014-05-27 16:24:24 +08:00
|
|
|
|
2012-03-29 10:53:41 +08:00
|
|
|
struct clk *clk;
|
2014-05-27 16:24:24 +08:00
|
|
|
struct clk *baudclk;
|
2014-05-27 16:24:23 +08:00
|
|
|
unsigned int baudclk_streams;
|
2014-05-27 16:24:24 +08:00
|
|
|
|
2015-09-18 11:09:12 +08:00
|
|
|
u32 regcache_sfcsr;
|
2015-12-21 04:30:25 +08:00
|
|
|
u32 regcache_sacnt;
|
2015-09-18 11:09:12 +08:00
|
|
|
|
2013-04-03 17:06:04 +08:00
|
|
|
struct snd_dmaengine_dai_dma_data dma_params_tx;
|
|
|
|
struct snd_dmaengine_dai_dma_data dma_params_rx;
|
2014-05-27 16:24:24 +08:00
|
|
|
dma_addr_t ssi_phys;
|
|
|
|
|
2013-07-27 19:31:53 +08:00
|
|
|
struct imx_pcm_fiq_params fiq_params;
|
2014-05-27 16:24:24 +08:00
|
|
|
|
|
|
|
struct platform_device *pdev;
|
2012-03-16 16:56:43 +08:00
|
|
|
|
2014-04-28 18:54:43 +08:00
|
|
|
struct fsl_ssi_dbg dbg_stats;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2014-05-27 16:24:18 +08:00
|
|
|
const struct fsl_ssi_soc_data *soc;
|
2016-05-03 20:13:57 +08:00
|
|
|
struct device *dev;
|
2017-01-04 02:22:57 +08:00
|
|
|
|
|
|
|
u32 fifo_watermark;
|
|
|
|
u32 dma_maxburst;
|
2017-11-21 06:16:07 +08:00
|
|
|
|
|
|
|
struct mutex ac97_reg_lock;
|
2013-12-20 21:11:30 +08:00
|
|
|
};
|
2014-04-28 18:54:48 +08:00
|
|
|
|
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* SoC specific data
|
2014-04-28 18:54:48 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Notes:
|
|
|
|
* 1) SSI in earlier SoCS has critical bits in control registers that
|
|
|
|
* cannot be changed after SSI starts running -- a software reset
|
|
|
|
* (set SSIEN to 0) is required to change their values. So adding
|
|
|
|
* an offline_config flag for these SoCs.
|
|
|
|
* 2) SDMA is available since imx35. However, imx35 does not support
|
|
|
|
* DMA bits changing when SSI is running, so set offline_config.
|
|
|
|
* 3) imx51 and later versions support register configurations when
|
|
|
|
* SSI is running (SSIEN); For these versions, DMA needs to be
|
|
|
|
* configured before SSI sends DMA request to avoid an undefined
|
|
|
|
* DMA request on the SDMA side.
|
2014-04-28 18:54:48 +08:00
|
|
|
*/
|
|
|
|
|
2014-05-27 16:24:18 +08:00
|
|
|
static struct fsl_ssi_soc_data fsl_ssi_mpc8610 = {
|
|
|
|
.imx = false,
|
|
|
|
.offline_config = true,
|
2017-12-18 10:52:03 +08:00
|
|
|
.sisr_write_mask = SSI_SISR_RFRC | SSI_SISR_TFRC |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SISR_ROE0 | SSI_SISR_ROE1 |
|
|
|
|
SSI_SISR_TUE0 | SSI_SISR_TUE1,
|
2014-05-27 16:24:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct fsl_ssi_soc_data fsl_ssi_imx21 = {
|
|
|
|
.imx = true,
|
2016-01-19 03:07:44 +08:00
|
|
|
.imx21regs = true,
|
2014-05-27 16:24:18 +08:00
|
|
|
.offline_config = true,
|
|
|
|
.sisr_write_mask = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct fsl_ssi_soc_data fsl_ssi_imx35 = {
|
|
|
|
.imx = true,
|
|
|
|
.offline_config = true,
|
2017-12-18 10:52:03 +08:00
|
|
|
.sisr_write_mask = SSI_SISR_RFRC | SSI_SISR_TFRC |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SISR_ROE0 | SSI_SISR_ROE1 |
|
|
|
|
SSI_SISR_TUE0 | SSI_SISR_TUE1,
|
2014-05-27 16:24:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct fsl_ssi_soc_data fsl_ssi_imx51 = {
|
|
|
|
.imx = true,
|
|
|
|
.offline_config = false,
|
2017-12-18 10:52:03 +08:00
|
|
|
.sisr_write_mask = SSI_SISR_ROE0 | SSI_SISR_ROE1 |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SISR_TUE0 | SSI_SISR_TUE1,
|
2014-05-27 16:24:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct of_device_id fsl_ssi_ids[] = {
|
|
|
|
{ .compatible = "fsl,mpc8610-ssi", .data = &fsl_ssi_mpc8610 },
|
|
|
|
{ .compatible = "fsl,imx51-ssi", .data = &fsl_ssi_imx51 },
|
|
|
|
{ .compatible = "fsl,imx35-ssi", .data = &fsl_ssi_imx35 },
|
|
|
|
{ .compatible = "fsl,imx21-ssi", .data = &fsl_ssi_imx21 },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, fsl_ssi_ids);
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static bool fsl_ssi_is_ac97(struct fsl_ssi *ssi)
|
2014-05-27 16:24:18 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
return (ssi->dai_fmt & SND_SOC_DAIFMT_FORMAT_MASK) ==
|
2015-09-16 17:13:19 +08:00
|
|
|
SND_SOC_DAIFMT_AC97;
|
2014-04-28 18:54:48 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static bool fsl_ssi_is_i2s_master(struct fsl_ssi *ssi)
|
2014-05-27 16:24:20 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
return (ssi->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) ==
|
2014-05-27 16:24:20 +08:00
|
|
|
SND_SOC_DAIFMT_CBS_CFS;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static bool fsl_ssi_is_i2s_cbm_cfs(struct fsl_ssi *ssi)
|
2014-08-04 23:08:07 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
return (ssi->dai_fmt & SND_SOC_DAIFMT_MASTER_MASK) ==
|
2014-08-04 23:08:07 +08:00
|
|
|
SND_SOC_DAIFMT_CBM_CFS;
|
|
|
|
}
|
2017-12-18 10:52:02 +08:00
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Interrupt handler to gather states
|
2008-01-12 01:15:26 +08:00
|
|
|
*/
|
|
|
|
static irqreturn_t fsl_ssi_isr(int irq, void *dev_id)
|
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = dev_id;
|
|
|
|
struct regmap *regs = ssi->regs;
|
2008-01-12 01:15:26 +08:00
|
|
|
__be32 sisr;
|
2013-12-20 21:11:31 +08:00
|
|
|
__be32 sisr2;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SISR, &sisr);
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
sisr2 = sisr & ssi->soc->sisr_write_mask;
|
2008-01-12 01:15:26 +08:00
|
|
|
/* Clear the bits that we set */
|
|
|
|
if (sisr2)
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SISR, sisr2);
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_dbg_isr(&ssi->dbg_stats, sisr);
|
2013-12-20 21:11:29 +08:00
|
|
|
|
2014-04-28 18:54:43 +08:00
|
|
|
return IRQ_HANDLED;
|
2013-12-20 21:11:29 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/**
|
|
|
|
* Enable or disable all rx/tx config flags at once
|
2013-12-20 21:11:33 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_rxtx_config(struct fsl_ssi *ssi, bool enable)
|
2013-12-20 21:11:33 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals *vals = ssi->regvals;
|
2013-12-20 21:11:33 +08:00
|
|
|
|
|
|
|
if (enable) {
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SIER,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier | vals[TX].sier,
|
|
|
|
vals[RX].sier | vals[TX].sier);
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCR,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].srcr | vals[TX].srcr,
|
|
|
|
vals[RX].srcr | vals[TX].srcr);
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_STCR,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].stcr | vals[TX].stcr,
|
|
|
|
vals[RX].stcr | vals[TX].stcr);
|
2013-12-20 21:11:33 +08:00
|
|
|
} else {
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCR,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].srcr | vals[TX].srcr, 0);
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_STCR,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].stcr | vals[TX].stcr, 0);
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SIER,
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier | vals[TX].sier, 0);
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/**
|
|
|
|
* Clear remaining data in the FIFO to avoid dirty data or channel slipping
|
2016-05-03 20:14:00 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_fifo_clear(struct fsl_ssi *ssi, bool is_rx)
|
2016-05-03 20:14:00 +08:00
|
|
|
{
|
2017-12-18 10:52:10 +08:00
|
|
|
bool tx = !is_rx;
|
|
|
|
|
|
|
|
regmap_update_bits(ssi->regs, REG_SSI_SOR,
|
|
|
|
SSI_SOR_xX_CLR(tx), SSI_SOR_xX_CLR(tx));
|
2016-05-03 20:14:00 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/**
|
2014-04-28 18:54:42 +08:00
|
|
|
* Calculate the bits that have to be disabled for the current stream that is
|
|
|
|
* getting disabled. This keeps the bits enabled that are necessary for the
|
|
|
|
* second stream to work if 'stream_active' is true.
|
|
|
|
*
|
|
|
|
* Detailed calculation:
|
|
|
|
* These are the values that need to be active after disabling. For non-active
|
|
|
|
* second stream, this is 0:
|
|
|
|
* vals_stream * !!stream_active
|
|
|
|
*
|
|
|
|
* The following computes the overall differences between the setup for the
|
|
|
|
* to-disable stream and the active stream, a simple XOR:
|
|
|
|
* vals_disable ^ (vals_stream * !!(stream_active))
|
|
|
|
*
|
|
|
|
* The full expression adds a mask on all values we care about
|
|
|
|
*/
|
|
|
|
#define fsl_ssi_disable_val(vals_disable, vals_stream, stream_active) \
|
|
|
|
((vals_disable) & \
|
|
|
|
((vals_disable) ^ ((vals_stream) * (u32)!!(stream_active))))
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/**
|
|
|
|
* Enable or disable SSI configuration.
|
2013-12-20 21:11:33 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_config(struct fsl_ssi *ssi, bool enable,
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals *vals)
|
2013-12-20 21:11:33 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals *avals;
|
2014-05-27 16:24:25 +08:00
|
|
|
int nr_active_streams;
|
2017-12-18 10:52:07 +08:00
|
|
|
u32 scr;
|
2014-04-28 18:54:42 +08:00
|
|
|
int keep_active;
|
|
|
|
|
2017-12-18 10:52:07 +08:00
|
|
|
regmap_read(regs, REG_SSI_SCR, &scr);
|
2014-05-27 16:24:25 +08:00
|
|
|
|
2017-12-18 10:52:07 +08:00
|
|
|
nr_active_streams = !!(scr & SSI_SCR_TE) + !!(scr & SSI_SCR_RE);
|
2014-05-27 16:24:25 +08:00
|
|
|
|
2014-04-28 18:54:42 +08:00
|
|
|
if (nr_active_streams - 1 > 0)
|
|
|
|
keep_active = 1;
|
|
|
|
else
|
|
|
|
keep_active = 0;
|
2013-12-20 21:11:33 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Get the opposite direction to keep its values untouched */
|
2017-12-18 10:52:08 +08:00
|
|
|
if (&ssi->regvals[RX] == vals)
|
|
|
|
avals = &ssi->regvals[TX];
|
2013-12-20 21:11:33 +08:00
|
|
|
else
|
2017-12-18 10:52:08 +08:00
|
|
|
avals = &ssi->regvals[RX];
|
2013-12-20 21:11:33 +08:00
|
|
|
|
|
|
|
if (!enable) {
|
2017-12-18 10:52:02 +08:00
|
|
|
/*
|
|
|
|
* To keep the other stream safe, exclude shared bits between
|
|
|
|
* both streams, and get safe bits to disable current stream
|
|
|
|
*/
|
2014-04-28 18:54:42 +08:00
|
|
|
u32 scr = fsl_ssi_disable_val(vals->scr, avals->scr,
|
2017-12-18 10:52:04 +08:00
|
|
|
keep_active);
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Safely disable SCR register for the stream */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR, scr, 0);
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* For cases where online configuration is not supported,
|
|
|
|
* 1) Enable all necessary bits of both streams when 1st stream starts
|
|
|
|
* even if the opposite stream will not start
|
|
|
|
* 2) Disable all remaining bits of both streams when last stream ends
|
2013-12-20 21:11:33 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->offline_config) {
|
2017-12-18 10:52:04 +08:00
|
|
|
if ((enable && !nr_active_streams) || (!enable && !keep_active))
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_rxtx_config(ssi, enable);
|
2013-12-20 21:11:33 +08:00
|
|
|
|
|
|
|
goto config_done;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Online configure single direction while SSI is running */
|
2013-12-20 21:11:33 +08:00
|
|
|
if (enable) {
|
2017-12-18 10:52:03 +08:00
|
|
|
fsl_ssi_fifo_clear(ssi, vals->scr & SSI_SCR_RE);
|
2016-05-03 20:14:00 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCR, vals->srcr, vals->srcr);
|
|
|
|
regmap_update_bits(regs, REG_SSI_STCR, vals->stcr, vals->stcr);
|
|
|
|
regmap_update_bits(regs, REG_SSI_SIER, vals->sier, vals->sier);
|
2013-12-20 21:11:33 +08:00
|
|
|
} else {
|
|
|
|
u32 sier;
|
|
|
|
u32 srcr;
|
|
|
|
u32 stcr;
|
|
|
|
|
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* To keep the other stream safe, exclude shared bits between
|
|
|
|
* both streams, and get safe bits to disable current stream
|
2013-12-20 21:11:33 +08:00
|
|
|
*/
|
2014-04-28 18:54:42 +08:00
|
|
|
sier = fsl_ssi_disable_val(vals->sier, avals->sier,
|
2017-12-18 10:52:04 +08:00
|
|
|
keep_active);
|
2014-04-28 18:54:42 +08:00
|
|
|
srcr = fsl_ssi_disable_val(vals->srcr, avals->srcr,
|
2017-12-18 10:52:04 +08:00
|
|
|
keep_active);
|
2014-04-28 18:54:42 +08:00
|
|
|
stcr = fsl_ssi_disable_val(vals->stcr, avals->stcr,
|
2017-12-18 10:52:04 +08:00
|
|
|
keep_active);
|
2013-12-20 21:11:33 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Safely disable other control registers for the stream */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCR, srcr, 0);
|
|
|
|
regmap_update_bits(regs, REG_SSI_STCR, stcr, 0);
|
|
|
|
regmap_update_bits(regs, REG_SSI_SIER, sier, 0);
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
config_done:
|
|
|
|
/* Enabling of subunits is done after configuration */
|
2016-05-03 20:13:59 +08:00
|
|
|
if (enable) {
|
2017-12-18 10:52:02 +08:00
|
|
|
/*
|
|
|
|
* Start DMA before setting TE to avoid FIFO underrun
|
|
|
|
* which may cause a channel slip or a channel swap
|
|
|
|
*
|
|
|
|
* TODO: FIQ cases might also need this upon testing
|
|
|
|
*/
|
2017-12-18 10:52:03 +08:00
|
|
|
if (ssi->use_dma && (vals->scr & SSI_SCR_TE)) {
|
2016-05-03 20:13:59 +08:00
|
|
|
int i;
|
|
|
|
int max_loop = 100;
|
2017-12-18 10:52:02 +08:00
|
|
|
|
|
|
|
/* Enable SSI first to send TX DMA request */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SCR_SSIEN, SSI_SCR_SSIEN);
|
2017-12-18 10:52:02 +08:00
|
|
|
|
|
|
|
/* Busy wait until TX FIFO not empty -- DMA working */
|
2016-05-03 20:13:59 +08:00
|
|
|
for (i = 0; i < max_loop; i++) {
|
|
|
|
u32 sfcsr;
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SFCSR, &sfcsr);
|
|
|
|
if (SSI_SFCSR_TFCNT0(sfcsr))
|
2016-05-03 20:13:59 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i == max_loop) {
|
2017-12-18 10:52:00 +08:00
|
|
|
dev_err(ssi->dev,
|
2016-05-03 20:13:59 +08:00
|
|
|
"Timeout waiting TX FIFO filling\n");
|
|
|
|
}
|
|
|
|
}
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Enable all remaining bits */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR, vals->scr, vals->scr);
|
2016-05-03 20:13:59 +08:00
|
|
|
}
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_rx_config(struct fsl_ssi *ssi, bool enable)
|
2013-12-20 21:11:33 +08:00
|
|
|
{
|
2017-12-18 10:52:08 +08:00
|
|
|
fsl_ssi_config(ssi, enable, &ssi->regvals[RX]);
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_tx_ac97_saccst_setup(struct fsl_ssi *ssi)
|
2017-11-22 07:54:26 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2017-11-22 07:54:26 +08:00
|
|
|
|
|
|
|
/* no SACC{ST,EN,DIS} regs on imx21-class SSI */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->soc->imx21regs) {
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Disable all channel slots */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACCDIS, 0xff);
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Enable slots 3 & 4 -- PCM Playback Left & Right channels */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACCEN, 0x300);
|
2017-11-22 07:54:26 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_tx_config(struct fsl_ssi *ssi, bool enable)
|
2013-12-20 21:11:33 +08:00
|
|
|
{
|
2017-11-22 07:54:26 +08:00
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* SACCST might be modified via AC Link by a CODEC if it sends
|
|
|
|
* extra bits in their SLOTREQ requests, which'll accidentally
|
|
|
|
* send valid data to slots other than normal playback slots.
|
2017-11-22 07:54:26 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* To be safe, configure SACCST right before TX starts.
|
2017-11-22 07:54:26 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
if (enable && fsl_ssi_is_ac97(ssi))
|
|
|
|
fsl_ssi_tx_ac97_saccst_setup(ssi);
|
2017-11-22 07:54:26 +08:00
|
|
|
|
2017-12-18 10:52:08 +08:00
|
|
|
fsl_ssi_config(ssi, enable, &ssi->regvals[TX]);
|
2013-12-20 21:11:33 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/**
|
|
|
|
* Cache critical bits of SIER, SRCR, STCR and SCR to later set them safely
|
2013-12-20 21:11:34 +08:00
|
|
|
*/
|
2017-12-18 10:52:08 +08:00
|
|
|
static void fsl_ssi_setup_regvals(struct fsl_ssi *ssi)
|
2013-12-20 21:11:34 +08:00
|
|
|
{
|
2017-12-18 10:52:08 +08:00
|
|
|
struct fsl_ssi_regvals *vals = ssi->regvals;
|
2013-12-20 21:11:34 +08:00
|
|
|
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier = SSI_SIER_RFF0_EN;
|
|
|
|
vals[RX].srcr = SSI_SRCR_RFEN0;
|
|
|
|
vals[RX].scr = 0;
|
|
|
|
vals[TX].sier = SSI_SIER_TFE0_EN;
|
|
|
|
vals[TX].stcr = SSI_STCR_TFEN0;
|
|
|
|
vals[TX].scr = 0;
|
2013-12-20 21:11:34 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* AC97 has already enabled SSIEN, RE and TE, so ignore them */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!fsl_ssi_is_ac97(ssi)) {
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].scr = SSI_SCR_SSIEN | SSI_SCR_RE;
|
|
|
|
vals[TX].scr = SSI_SCR_SSIEN | SSI_SCR_TE;
|
2013-12-20 21:11:34 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->use_dma) {
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier |= SSI_SIER_RDMAE;
|
|
|
|
vals[TX].sier |= SSI_SIER_TDMAE;
|
2013-12-20 21:11:34 +08:00
|
|
|
} else {
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier |= SSI_SIER_RIE;
|
|
|
|
vals[TX].sier |= SSI_SIER_TIE;
|
2013-12-20 21:11:34 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:08 +08:00
|
|
|
vals[RX].sier |= FSLSSI_SIER_DBG_RX_FLAGS;
|
|
|
|
vals[TX].sier |= FSLSSI_SIER_DBG_TX_FLAGS;
|
2013-12-20 21:11:34 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static void fsl_ssi_setup_ac97(struct fsl_ssi *ssi)
|
2013-11-20 17:04:15 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2013-11-20 17:04:15 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Setup the clock control register */
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_write(regs, REG_SSI_STCCR, SSI_SxCCR_WL(17) | SSI_SxCCR_DC(13));
|
|
|
|
regmap_write(regs, REG_SSI_SRCCR, SSI_SxCCR_WL(17) | SSI_SxCCR_DC(13));
|
2013-11-20 17:04:15 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Enable AC97 mode and startup the SSI */
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACNT, SSI_SACNT_AC97EN | SSI_SACNT_FV);
|
2016-01-19 03:07:44 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* AC97 has to communicate with codec before starting a stream */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SCR_SSIEN | SSI_SCR_TE | SSI_SCR_RE,
|
|
|
|
SSI_SCR_SSIEN | SSI_SCR_TE | SSI_SCR_RE);
|
2013-11-20 17:04:15 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SOR, SSI_SOR_WAIT(3));
|
2013-11-20 17:04:15 +08:00
|
|
|
}
|
|
|
|
|
2008-11-19 06:11:38 +08:00
|
|
|
static int fsl_ssi_startup(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-01-12 01:15:26 +08:00
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(rtd->cpu_dai);
|
2014-09-16 10:13:16 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ret = clk_prepare_enable(ssi->clk);
|
2014-09-16 10:13:16 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/*
|
|
|
|
* When using dual fifo mode, it is safer to ensure an even period
|
2013-11-13 22:55:26 +08:00
|
|
|
* size. If appearing to an odd number while DMA always starts its
|
|
|
|
* task from fifo0, fifo1 would be neglected at the end of each
|
|
|
|
* period. But SSI would still access fifo1 with an invalid data.
|
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->use_dual_fifo)
|
2013-11-13 22:55:26 +08:00
|
|
|
snd_pcm_hw_constraint_step(substream->runtime, 0,
|
2017-12-18 10:52:04 +08:00
|
|
|
SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2);
|
2013-11-13 22:55:26 +08:00
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-16 10:13:16 +08:00
|
|
|
static void fsl_ssi_shutdown(struct snd_pcm_substream *substream,
|
2017-12-18 10:52:04 +08:00
|
|
|
struct snd_soc_dai *dai)
|
2014-09-16 10:13:16 +08:00
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(rtd->cpu_dai);
|
2014-09-16 10:13:16 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
clk_disable_unprepare(ssi->clk);
|
2014-09-16 10:13:16 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 18:54:52 +08:00
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Configure Digital Audio Interface bit clock
|
2014-04-28 18:54:52 +08:00
|
|
|
*
|
|
|
|
* Note: This function can be only called when using SSI as DAI master
|
|
|
|
*
|
|
|
|
* Quick instruction for parameters:
|
2017-09-14 11:07:09 +08:00
|
|
|
* freq: Output BCLK frequency = samplerate * slots * slot_width
|
|
|
|
* (In 2-channel I2S Master mode, slot_width is fixed 32)
|
2014-04-28 18:54:52 +08:00
|
|
|
*/
|
2014-05-27 16:24:20 +08:00
|
|
|
static int fsl_ssi_set_bclk(struct snd_pcm_substream *substream,
|
2017-12-18 10:52:06 +08:00
|
|
|
struct snd_soc_dai *dai,
|
2017-12-18 10:52:04 +08:00
|
|
|
struct snd_pcm_hw_params *hw_params)
|
2014-04-28 18:54:52 +08:00
|
|
|
{
|
2017-12-18 10:52:10 +08:00
|
|
|
bool tx2, tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
|
2017-12-18 10:52:06 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
|
|
|
int synchronous = ssi->cpu_dai_drv.symmetric_rates, ret;
|
2014-04-28 18:54:52 +08:00
|
|
|
u32 pm = 999, div2, psr, stccr, mask, afreq, factor, i;
|
2014-05-27 16:24:21 +08:00
|
|
|
unsigned long clkrate, baudrate, tmprate;
|
2017-09-14 11:07:09 +08:00
|
|
|
unsigned int slots = params_channels(hw_params);
|
|
|
|
unsigned int slot_width = 32;
|
2014-04-28 18:54:52 +08:00
|
|
|
u64 sub, savesub = 100000;
|
2014-05-27 16:24:20 +08:00
|
|
|
unsigned int freq;
|
2014-05-27 16:24:23 +08:00
|
|
|
bool baudclk_is_used;
|
2014-05-27 16:24:20 +08:00
|
|
|
|
2017-09-14 11:07:09 +08:00
|
|
|
/* Override slots and slot_width if being specifically set... */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->slots)
|
|
|
|
slots = ssi->slots;
|
2017-09-14 11:07:09 +08:00
|
|
|
/* ...but keep 32 bits if slots is 2 -- I2S Master mode */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->slot_width && slots != 2)
|
|
|
|
slot_width = ssi->slot_width;
|
2017-09-14 11:07:09 +08:00
|
|
|
|
|
|
|
/* Generate bit clock based on the slot number and slot width */
|
|
|
|
freq = slots * slot_width * params_rate(hw_params);
|
2014-04-28 18:54:52 +08:00
|
|
|
|
|
|
|
/* Don't apply it to any non-baudclk circumstance */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->baudclk))
|
2014-04-28 18:54:52 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2016-05-03 20:13:56 +08:00
|
|
|
/*
|
|
|
|
* Hardware limitation: The bclk rate must be
|
|
|
|
* never greater than 1/5 IPG clock rate
|
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
if (freq * 5 > clk_get_rate(ssi->clk)) {
|
2017-12-18 10:52:06 +08:00
|
|
|
dev_err(dai->dev, "bitclk > ipgclk / 5\n");
|
2016-05-03 20:13:56 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
baudclk_is_used = ssi->baudclk_streams & ~(BIT(substream->stream));
|
2014-05-27 16:24:23 +08:00
|
|
|
|
2014-04-28 18:54:52 +08:00
|
|
|
/* It should be already enough to divide clock by setting pm alone */
|
|
|
|
psr = 0;
|
|
|
|
div2 = 0;
|
|
|
|
|
|
|
|
factor = (div2 + 1) * (7 * psr + 1) * 2;
|
|
|
|
|
|
|
|
for (i = 0; i < 255; i++) {
|
2015-03-05 13:05:04 +08:00
|
|
|
tmprate = freq * factor * (i + 1);
|
2014-05-27 16:24:23 +08:00
|
|
|
|
|
|
|
if (baudclk_is_used)
|
2017-12-18 10:52:00 +08:00
|
|
|
clkrate = clk_get_rate(ssi->baudclk);
|
2014-05-27 16:24:23 +08:00
|
|
|
else
|
2017-12-18 10:52:00 +08:00
|
|
|
clkrate = clk_round_rate(ssi->baudclk, tmprate);
|
2014-04-28 18:54:52 +08:00
|
|
|
|
2014-06-13 20:42:40 +08:00
|
|
|
clkrate /= factor;
|
|
|
|
afreq = clkrate / (i + 1);
|
2014-04-28 18:54:52 +08:00
|
|
|
|
|
|
|
if (freq == afreq)
|
|
|
|
sub = 0;
|
|
|
|
else if (freq / afreq == 1)
|
|
|
|
sub = freq - afreq;
|
|
|
|
else if (afreq / freq == 1)
|
|
|
|
sub = afreq - freq;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Calculate the fraction */
|
|
|
|
sub *= 100000;
|
|
|
|
do_div(sub, freq);
|
|
|
|
|
2015-07-03 18:39:36 +08:00
|
|
|
if (sub < savesub && !(i == 0 && psr == 0 && div2 == 0)) {
|
2014-04-28 18:54:52 +08:00
|
|
|
baudrate = tmprate;
|
|
|
|
savesub = sub;
|
|
|
|
pm = i;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We are lucky */
|
|
|
|
if (savesub == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* No proper pm found if it is still remaining the initial value */
|
|
|
|
if (pm == 999) {
|
2017-12-18 10:52:06 +08:00
|
|
|
dev_err(dai->dev, "failed to handle the required sysclk\n");
|
2014-04-28 18:54:52 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
stccr = SSI_SxCCR_PM(pm + 1) | (div2 ? SSI_SxCCR_DIV2 : 0) |
|
|
|
|
(psr ? SSI_SxCCR_PSR : 0);
|
2017-12-18 10:52:04 +08:00
|
|
|
mask = SSI_SxCCR_PM_MASK | SSI_SxCCR_DIV2 | SSI_SxCCR_PSR;
|
2014-04-28 18:54:52 +08:00
|
|
|
|
2017-12-18 10:52:10 +08:00
|
|
|
/* STCCR is used for RX in synchronous mode */
|
|
|
|
tx2 = tx || synchronous;
|
|
|
|
regmap_update_bits(regs, REG_SSI_SxCCR(tx2), mask, stccr);
|
2014-04-28 18:54:52 +08:00
|
|
|
|
2014-05-27 16:24:23 +08:00
|
|
|
if (!baudclk_is_used) {
|
2017-12-18 10:52:00 +08:00
|
|
|
ret = clk_set_rate(ssi->baudclk, baudrate);
|
2014-04-28 18:54:52 +08:00
|
|
|
if (ret) {
|
2017-12-18 10:52:06 +08:00
|
|
|
dev_err(dai->dev, "failed to set baudclk rate\n");
|
2014-04-28 18:54:52 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Configure SSI based on PCM hardware parameters
|
2008-01-12 01:15:26 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Notes:
|
|
|
|
* 1) SxCCR.WL bits are critical bits that require SSI to be temporarily
|
|
|
|
* disabled on offline_config SoCs. Even for online configurable SoCs
|
|
|
|
* running in synchronous mode (both TX and RX use STCCR), it is not
|
|
|
|
* safe to re-configure them when both two streams start running.
|
|
|
|
* 2) SxCCR.PM, SxCCR.DIV2 and SxCCR.PSR bits will be configured in the
|
|
|
|
* fsl_ssi_set_bclk() if SSI is the DAI clock master.
|
2008-01-12 01:15:26 +08:00
|
|
|
*/
|
2009-02-06 07:56:02 +08:00
|
|
|
static int fsl_ssi_hw_params(struct snd_pcm_substream *substream,
|
2017-12-18 10:52:04 +08:00
|
|
|
struct snd_pcm_hw_params *hw_params,
|
2017-12-18 10:52:06 +08:00
|
|
|
struct snd_soc_dai *dai)
|
2008-01-12 01:15:26 +08:00
|
|
|
{
|
2017-12-18 10:52:10 +08:00
|
|
|
bool tx2, tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
|
2017-12-18 10:52:06 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2013-12-02 23:29:03 +08:00
|
|
|
unsigned int channels = params_channels(hw_params);
|
2015-11-24 15:32:09 +08:00
|
|
|
unsigned int sample_size = params_width(hw_params);
|
2017-12-18 10:52:03 +08:00
|
|
|
u32 wl = SSI_SxCCR_WL(sample_size);
|
2014-05-27 16:24:20 +08:00
|
|
|
int ret;
|
2017-12-18 10:52:07 +08:00
|
|
|
u32 scr;
|
2014-05-27 16:24:25 +08:00
|
|
|
int enabled;
|
|
|
|
|
2017-12-18 10:52:07 +08:00
|
|
|
regmap_read(regs, REG_SSI_SCR, &scr);
|
|
|
|
enabled = scr & SSI_SCR_SSIEN;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2011-09-14 01:59:37 +08:00
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* SSI is properly configured if it is enabled and running in
|
|
|
|
* the synchronous mode; Note that AC97 mode is an exception
|
|
|
|
* that should set separate configurations for STCCR and SRCCR
|
|
|
|
* despite running in the synchronous mode.
|
2011-09-14 01:59:37 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
if (enabled && ssi->cpu_dai_drv.symmetric_rates)
|
2011-09-14 01:59:37 +08:00
|
|
|
return 0;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_i2s_master(ssi)) {
|
2017-12-18 10:52:06 +08:00
|
|
|
ret = fsl_ssi_set_bclk(substream, dai, hw_params);
|
2014-05-27 16:24:20 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2014-05-27 16:24:23 +08:00
|
|
|
|
|
|
|
/* Do not enable the clock if it is already enabled */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!(ssi->baudclk_streams & BIT(substream->stream))) {
|
|
|
|
ret = clk_prepare_enable(ssi->baudclk);
|
2014-05-27 16:24:23 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->baudclk_streams |= BIT(substream->stream);
|
2014-05-27 16:24:23 +08:00
|
|
|
}
|
2014-05-27 16:24:20 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!fsl_ssi_is_ac97(ssi)) {
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Normal + Network mode to send 16-bit data in 32-bit frames */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_i2s_cbm_cfs(ssi) && sample_size == 16)
|
2018-02-13 06:03:10 +08:00
|
|
|
ssi->i2s_net = SSI_SCR_I2S_MODE_NORMAL | SSI_SCR_NET;
|
|
|
|
|
|
|
|
/* Use Normal mode to send mono data at 1st slot of 2 slots */
|
|
|
|
if (channels == 1)
|
|
|
|
ssi->i2s_net = SSI_SCR_I2S_MODE_NORMAL;
|
2014-08-04 23:08:07 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR,
|
2018-02-13 06:03:10 +08:00
|
|
|
SSI_SCR_I2S_NET_MASK, ssi->i2s_net);
|
2014-08-04 23:08:07 +08:00
|
|
|
}
|
|
|
|
|
2011-09-14 01:59:37 +08:00
|
|
|
/* In synchronous mode, the SSI uses STCCR for capture */
|
2017-12-18 10:52:10 +08:00
|
|
|
tx2 = tx || ssi->cpu_dai_drv.symmetric_rates;
|
|
|
|
regmap_update_bits(regs, REG_SSI_SxCCR(tx2), SSI_SxCCR_WL_MASK, wl);
|
2008-01-12 01:15:26 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-27 16:24:23 +08:00
|
|
|
static int fsl_ssi_hw_free(struct snd_pcm_substream *substream,
|
2017-12-18 10:52:06 +08:00
|
|
|
struct snd_soc_dai *dai)
|
2014-05-27 16:24:23 +08:00
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(rtd->cpu_dai);
|
2014-05-27 16:24:23 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_i2s_master(ssi) &&
|
2017-12-18 10:52:04 +08:00
|
|
|
ssi->baudclk_streams & BIT(substream->stream)) {
|
2017-12-18 10:52:00 +08:00
|
|
|
clk_disable_unprepare(ssi->baudclk);
|
|
|
|
ssi->baudclk_streams &= ~BIT(substream->stream);
|
2014-05-27 16:24:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-19 02:38:09 +08:00
|
|
|
static int _fsl_ssi_set_dai_fmt(struct device *dev,
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi, unsigned int fmt)
|
2013-12-12 18:44:45 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2013-12-12 18:44:45 +08:00
|
|
|
u32 strcr = 0, stcr, srcr, scr, mask;
|
2014-03-15 20:44:09 +08:00
|
|
|
u8 wm;
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->dai_fmt = fmt;
|
2014-04-28 18:54:48 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_i2s_master(ssi) && IS_ERR(ssi->baudclk)) {
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "missing baudclk for master mode\n");
|
2014-05-27 16:24:23 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:08 +08:00
|
|
|
fsl_ssi_setup_regvals(ssi);
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SCR, &scr);
|
|
|
|
scr &= ~(SSI_SCR_SYN | SSI_SCR_I2S_MODE_MASK);
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Synchronize frame sync clock for TE to avoid data slipping */
|
2017-12-18 10:52:03 +08:00
|
|
|
scr |= SSI_SCR_SYNC_TX_FS;
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
mask = SSI_STCR_TXBIT0 | SSI_STCR_TFDIR | SSI_STCR_TXDIR |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_STCR_TSCKP | SSI_STCR_TFSI | SSI_STCR_TFSL | SSI_STCR_TEFS;
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_STCR, &stcr);
|
|
|
|
regmap_read(regs, REG_SSI_SRCR, &srcr);
|
2014-05-27 16:24:25 +08:00
|
|
|
stcr &= ~mask;
|
|
|
|
srcr &= ~mask;
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Use Network mode as default */
|
2017-12-18 10:52:09 +08:00
|
|
|
ssi->i2s_net = SSI_SCR_NET;
|
2013-12-12 18:44:45 +08:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_STCCR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCCR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(2));
|
2013-12-12 18:44:45 +08:00
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
2014-08-04 23:08:07 +08:00
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
2013-12-12 18:44:45 +08:00
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
2017-12-18 10:52:09 +08:00
|
|
|
ssi->i2s_net |= SSI_SCR_I2S_MODE_MASTER;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2017-12-18 10:52:09 +08:00
|
|
|
ssi->i2s_net |= SSI_SCR_I2S_MODE_SLAVE;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Data on rising edge of bclk, frame low, 1clk before data */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr |= SSI_STCR_TFSI | SSI_STCR_TSCKP |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
/* Data on rising edge of bclk, frame high */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr |= SSI_STCR_TXBIT0 | SSI_STCR_TSCKP;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
/* Data on rising edge of bclk, frame high, 1clk before data */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP |
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_STCR_TXBIT0 | SSI_STCR_TEFS;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_DSP_B:
|
|
|
|
/* Data on rising edge of bclk, frame high */
|
2017-12-18 10:52:04 +08:00
|
|
|
strcr |= SSI_STCR_TFSL | SSI_STCR_TSCKP | SSI_STCR_TXBIT0;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
2014-03-15 20:44:09 +08:00
|
|
|
case SND_SOC_DAIFMT_AC97:
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Data on falling edge of bclk, frame high, 1clk before data */
|
2017-12-18 10:52:09 +08:00
|
|
|
ssi->i2s_net |= SSI_SCR_I2S_MODE_NORMAL;
|
2014-03-15 20:44:09 +08:00
|
|
|
break;
|
2013-12-12 18:44:45 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-12-18 10:52:09 +08:00
|
|
|
scr |= ssi->i2s_net;
|
2013-12-12 18:44:45 +08:00
|
|
|
|
|
|
|
/* DAI clock inversion */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_NB_NF:
|
|
|
|
/* Nothing to do for both normal cases */
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_NF:
|
|
|
|
/* Invert bit clock */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr ^= SSI_STCR_TSCKP;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_NB_IF:
|
|
|
|
/* Invert frame clock */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr ^= SSI_STCR_TFSI;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
/* Invert both clocks */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr ^= SSI_STCR_TSCKP;
|
|
|
|
strcr ^= SSI_STCR_TFSI;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* DAI clock master masks */
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Output bit and frame sync clocks */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr |= SSI_STCR_TFDIR | SSI_STCR_TXDIR;
|
|
|
|
scr |= SSI_SCR_SYS_CLK_EN;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Input bit or frame sync clocks */
|
2017-12-18 10:52:03 +08:00
|
|
|
scr &= ~SSI_SCR_SYS_CLK_EN;
|
2013-12-12 18:44:45 +08:00
|
|
|
break;
|
2014-08-04 23:08:07 +08:00
|
|
|
case SND_SOC_DAIFMT_CBM_CFS:
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Input bit clock but output frame sync clock */
|
2017-12-18 10:52:03 +08:00
|
|
|
strcr &= ~SSI_STCR_TXDIR;
|
|
|
|
strcr |= SSI_STCR_TFDIR;
|
|
|
|
scr &= ~SSI_SCR_SYS_CLK_EN;
|
2014-08-04 23:08:07 +08:00
|
|
|
break;
|
2013-12-12 18:44:45 +08:00
|
|
|
default:
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!fsl_ssi_is_ac97(ssi))
|
2015-08-05 23:29:02 +08:00
|
|
|
return -EINVAL;
|
2013-12-12 18:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
stcr |= strcr;
|
|
|
|
srcr |= strcr;
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Set SYN mode and clear RXDIR bit when using SYN or AC97 mode */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->cpu_dai_drv.symmetric_rates || fsl_ssi_is_ac97(ssi)) {
|
2017-12-18 10:52:03 +08:00
|
|
|
srcr &= ~SSI_SRCR_RXDIR;
|
|
|
|
scr |= SSI_SCR_SYN;
|
2013-12-12 18:44:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_STCR, stcr);
|
|
|
|
regmap_write(regs, REG_SSI_SRCR, srcr);
|
|
|
|
regmap_write(regs, REG_SSI_SCR, scr);
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
wm = ssi->fifo_watermark;
|
2014-03-15 20:44:09 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SFCSR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SFCSR_TFWM0(wm) | SSI_SFCSR_RFWM0(wm) |
|
|
|
|
SSI_SFCSR_TFWM1(wm) | SSI_SFCSR_RFWM1(wm));
|
2014-03-15 20:44:09 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->use_dual_fifo) {
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SRCR,
|
|
|
|
SSI_SRCR_RFEN1, SSI_SRCR_RFEN1);
|
|
|
|
regmap_update_bits(regs, REG_SSI_STCR,
|
|
|
|
SSI_STCR_TFEN1, SSI_STCR_TFEN1);
|
|
|
|
regmap_update_bits(regs, REG_SSI_SCR,
|
|
|
|
SSI_SCR_TCH_EN, SSI_SCR_TCH_EN);
|
2014-03-15 20:44:09 +08:00
|
|
|
}
|
|
|
|
|
2015-09-16 17:13:19 +08:00
|
|
|
if ((fmt & SND_SOC_DAIFMT_FORMAT_MASK) == SND_SOC_DAIFMT_AC97)
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_setup_ac97(ssi);
|
2014-03-15 20:44:09 +08:00
|
|
|
|
2013-12-12 18:44:45 +08:00
|
|
|
return 0;
|
2014-05-27 16:24:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Configure Digital Audio Interface (DAI) Format
|
2014-05-27 16:24:19 +08:00
|
|
|
*/
|
2017-12-18 10:52:06 +08:00
|
|
|
static int fsl_ssi_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
|
2014-05-27 16:24:19 +08:00
|
|
|
{
|
2017-12-18 10:52:06 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2014-05-27 16:24:19 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* AC97 configured DAIFMT earlier in the probe() */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi))
|
2017-11-22 07:55:14 +08:00
|
|
|
return 0;
|
|
|
|
|
2017-12-18 10:52:06 +08:00
|
|
|
return _fsl_ssi_set_dai_fmt(dai->dev, ssi, fmt);
|
2013-12-12 18:44:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Set TDM slot number and slot width
|
2013-12-12 18:44:45 +08:00
|
|
|
*/
|
2017-12-18 10:52:06 +08:00
|
|
|
static int fsl_ssi_set_dai_tdm_slot(struct snd_soc_dai *dai, u32 tx_mask,
|
2017-12-18 10:52:04 +08:00
|
|
|
u32 rx_mask, int slots, int slot_width)
|
2013-12-12 18:44:45 +08:00
|
|
|
{
|
2017-12-18 10:52:06 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2017-12-18 10:52:00 +08:00
|
|
|
struct regmap *regs = ssi->regs;
|
2013-12-12 18:44:45 +08:00
|
|
|
u32 val;
|
|
|
|
|
2017-09-14 11:07:09 +08:00
|
|
|
/* The word length should be 8, 10, 12, 16, 18, 20, 22 or 24 */
|
|
|
|
if (slot_width & 1 || slot_width < 8 || slot_width > 24) {
|
2017-12-18 10:52:06 +08:00
|
|
|
dev_err(dai->dev, "invalid slot width: %d\n", slot_width);
|
2017-09-14 11:07:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2013-12-12 18:44:45 +08:00
|
|
|
/* The slot number should be >= 2 if using Network mode or I2S mode */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SCR, &val);
|
|
|
|
val &= SSI_SCR_I2S_MODE_MASK | SSI_SCR_NET;
|
2013-12-12 18:44:45 +08:00
|
|
|
if (val && slots < 2) {
|
2017-12-18 10:52:06 +08:00
|
|
|
dev_err(dai->dev, "slot number should be >= 2 in I2S or NET\n");
|
2013-12-12 18:44:45 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_STCCR,
|
|
|
|
SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(slots));
|
|
|
|
regmap_update_bits(regs, REG_SSI_SRCCR,
|
|
|
|
SSI_SxCCR_DC_MASK, SSI_SxCCR_DC(slots));
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Save SSIEN bit of the SCR register */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SCR, &val);
|
|
|
|
val &= SSI_SCR_SSIEN;
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Temporarily enable SSI to allow SxMSKs to be configurable */
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR, SSI_SCR_SSIEN, SSI_SCR_SSIEN);
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_STMSK, ~tx_mask);
|
|
|
|
regmap_write(regs, REG_SSI_SRMSK, ~rx_mask);
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Restore the value of SSIEN bit */
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SCR, SSI_SCR_SSIEN, val);
|
2013-12-12 18:44:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->slot_width = slot_width;
|
|
|
|
ssi->slots = slots;
|
2017-09-14 11:07:09 +08:00
|
|
|
|
2013-12-12 18:44:45 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
2017-12-18 10:52:02 +08:00
|
|
|
* Start or stop SSI and corresponding DMA transaction.
|
2008-01-12 01:15:26 +08:00
|
|
|
*
|
|
|
|
* The DMA channel is in external master start and pause mode, which
|
|
|
|
* means the SSI completely controls the flow of data.
|
|
|
|
*/
|
2008-11-19 06:11:38 +08:00
|
|
|
static int fsl_ssi_trigger(struct snd_pcm_substream *substream, int cmd,
|
|
|
|
struct snd_soc_dai *dai)
|
2008-01-12 01:15:26 +08:00
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(rtd->cpu_dai);
|
|
|
|
struct regmap *regs = ssi->regs;
|
2013-08-19 23:06:00 +08:00
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2014-05-23 13:38:56 +08:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2008-01-12 01:15:26 +08:00
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2009-03-26 07:20:37 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_tx_config(ssi, true);
|
2009-03-26 07:20:37 +08:00
|
|
|
else
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_rx_config(ssi, true);
|
2008-01-12 01:15:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2014-05-23 13:38:56 +08:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2008-01-12 01:15:26 +08:00
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_tx_config(ssi, false);
|
2008-01-12 01:15:26 +08:00
|
|
|
else
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_rx_config(ssi, false);
|
2008-01-12 01:15:26 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Clear corresponding FIFO */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi)) {
|
2013-12-20 21:11:35 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SOR, SSI_SOR_TX_CLR);
|
2013-12-20 21:11:35 +08:00
|
|
|
else
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SOR, SSI_SOR_RX_CLR);
|
2013-12-20 21:11:35 +08:00
|
|
|
}
|
2013-08-19 23:06:00 +08:00
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-16 01:19:58 +08:00
|
|
|
static int fsl_ssi_dai_probe(struct snd_soc_dai *dai)
|
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = snd_soc_dai_get_drvdata(dai);
|
2013-04-16 01:19:58 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->imx && ssi->use_dma) {
|
|
|
|
dai->playback_dma_data = &ssi->dma_params_tx;
|
|
|
|
dai->capture_dma_data = &ssi->dma_params_rx;
|
2013-04-16 01:19:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
static const struct snd_soc_dai_ops fsl_ssi_dai_ops = {
|
2017-12-18 10:52:04 +08:00
|
|
|
.startup = fsl_ssi_startup,
|
|
|
|
.shutdown = fsl_ssi_shutdown,
|
|
|
|
.hw_params = fsl_ssi_hw_params,
|
|
|
|
.hw_free = fsl_ssi_hw_free,
|
|
|
|
.set_fmt = fsl_ssi_set_dai_fmt,
|
|
|
|
.set_tdm_slot = fsl_ssi_set_dai_tdm_slot,
|
|
|
|
.trigger = fsl_ssi_trigger,
|
2009-03-03 09:41:00 +08:00
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_dai_driver fsl_ssi_dai_template = {
|
2013-04-16 01:19:58 +08:00
|
|
|
.probe = fsl_ssi_dai_probe,
|
2008-01-12 01:15:26 +08:00
|
|
|
.playback = {
|
2014-07-30 11:10:29 +08:00
|
|
|
.stream_name = "CPU-Playback",
|
2013-12-02 23:29:03 +08:00
|
|
|
.channels_min = 1,
|
2016-05-03 20:13:55 +08:00
|
|
|
.channels_max = 32,
|
2017-04-06 03:44:05 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
2008-01-12 01:15:26 +08:00
|
|
|
.formats = FSLSSI_I2S_FORMATS,
|
|
|
|
},
|
|
|
|
.capture = {
|
2014-07-30 11:10:29 +08:00
|
|
|
.stream_name = "CPU-Capture",
|
2013-12-02 23:29:03 +08:00
|
|
|
.channels_min = 1,
|
2016-05-03 20:13:55 +08:00
|
|
|
.channels_max = 32,
|
2017-04-06 03:44:05 +08:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
2008-01-12 01:15:26 +08:00
|
|
|
.formats = FSLSSI_I2S_FORMATS,
|
|
|
|
},
|
2009-03-03 09:41:00 +08:00
|
|
|
.ops = &fsl_ssi_dai_ops,
|
2008-01-12 01:15:26 +08:00
|
|
|
};
|
|
|
|
|
2013-03-21 18:32:04 +08:00
|
|
|
static const struct snd_soc_component_driver fsl_ssi_component = {
|
2017-12-18 10:52:04 +08:00
|
|
|
.name = "fsl-ssi",
|
2013-03-21 18:32:04 +08:00
|
|
|
};
|
|
|
|
|
2013-08-19 23:05:58 +08:00
|
|
|
static struct snd_soc_dai_driver fsl_ssi_ac97_dai = {
|
2014-11-11 05:41:52 +08:00
|
|
|
.bus_control = true,
|
2015-08-05 23:22:53 +08:00
|
|
|
.probe = fsl_ssi_dai_probe,
|
2013-08-19 23:05:58 +08:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "AC97 Playback",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_8000_48000,
|
2017-11-28 06:34:44 +08:00
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16 | SNDRV_PCM_FMTBIT_S20,
|
2013-08-19 23:05:58 +08:00
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "AC97 Capture",
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = SNDRV_PCM_RATE_48000,
|
2017-11-28 06:34:44 +08:00
|
|
|
/* 16-bit capture is broken (errata ERR003778) */
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S20,
|
2013-08-19 23:05:58 +08:00
|
|
|
},
|
2013-12-20 21:11:35 +08:00
|
|
|
.ops = &fsl_ssi_dai_ops,
|
2013-08-19 23:05:58 +08:00
|
|
|
};
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
static struct fsl_ssi *fsl_ac97_data;
|
2013-08-19 23:05:58 +08:00
|
|
|
|
2013-09-13 17:52:17 +08:00
|
|
|
static void fsl_ssi_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
|
2017-12-18 10:52:04 +08:00
|
|
|
unsigned short val)
|
2013-08-19 23:05:58 +08:00
|
|
|
{
|
2014-05-27 16:24:25 +08:00
|
|
|
struct regmap *regs = fsl_ac97_data->regs;
|
2013-08-19 23:05:58 +08:00
|
|
|
unsigned int lreg;
|
|
|
|
unsigned int lval;
|
2015-08-05 23:21:35 +08:00
|
|
|
int ret;
|
2013-08-19 23:05:58 +08:00
|
|
|
|
|
|
|
if (reg > 0x7f)
|
|
|
|
return;
|
|
|
|
|
2017-11-21 06:16:07 +08:00
|
|
|
mutex_lock(&fsl_ac97_data->ac97_reg_lock);
|
|
|
|
|
2015-08-05 23:21:35 +08:00
|
|
|
ret = clk_prepare_enable(fsl_ac97_data->clk);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("ac97 write clk_prepare_enable failed: %d\n",
|
|
|
|
ret);
|
2017-11-21 06:16:07 +08:00
|
|
|
goto ret_unlock;
|
2015-08-05 23:21:35 +08:00
|
|
|
}
|
2013-08-19 23:05:58 +08:00
|
|
|
|
|
|
|
lreg = reg << 12;
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACADD, lreg);
|
2013-08-19 23:05:58 +08:00
|
|
|
|
|
|
|
lval = val << 4;
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACDAT, lval);
|
2013-08-19 23:05:58 +08:00
|
|
|
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SACNT,
|
|
|
|
SSI_SACNT_RDWR_MASK, SSI_SACNT_WR);
|
2013-08-19 23:05:58 +08:00
|
|
|
udelay(100);
|
2015-08-05 23:21:35 +08:00
|
|
|
|
|
|
|
clk_disable_unprepare(fsl_ac97_data->clk);
|
2017-11-21 06:16:07 +08:00
|
|
|
|
|
|
|
ret_unlock:
|
|
|
|
mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
|
2013-08-19 23:05:58 +08:00
|
|
|
}
|
|
|
|
|
2013-09-13 17:52:17 +08:00
|
|
|
static unsigned short fsl_ssi_ac97_read(struct snd_ac97 *ac97,
|
2017-12-18 10:52:04 +08:00
|
|
|
unsigned short reg)
|
2013-08-19 23:05:58 +08:00
|
|
|
{
|
2014-05-27 16:24:25 +08:00
|
|
|
struct regmap *regs = fsl_ac97_data->regs;
|
2017-11-21 06:16:07 +08:00
|
|
|
unsigned short val = 0;
|
2014-05-27 16:24:25 +08:00
|
|
|
u32 reg_val;
|
2013-08-19 23:05:58 +08:00
|
|
|
unsigned int lreg;
|
2015-08-05 23:21:35 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-11-21 06:16:07 +08:00
|
|
|
mutex_lock(&fsl_ac97_data->ac97_reg_lock);
|
|
|
|
|
2015-08-05 23:21:35 +08:00
|
|
|
ret = clk_prepare_enable(fsl_ac97_data->clk);
|
|
|
|
if (ret) {
|
2017-12-18 10:52:04 +08:00
|
|
|
pr_err("ac97 read clk_prepare_enable failed: %d\n", ret);
|
2017-11-21 06:16:07 +08:00
|
|
|
goto ret_unlock;
|
2015-08-05 23:21:35 +08:00
|
|
|
}
|
2013-08-19 23:05:58 +08:00
|
|
|
|
|
|
|
lreg = (reg & 0x7f) << 12;
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACADD, lreg);
|
2017-12-18 10:52:04 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SACNT,
|
|
|
|
SSI_SACNT_RDWR_MASK, SSI_SACNT_RD);
|
2013-08-19 23:05:58 +08:00
|
|
|
|
|
|
|
udelay(100);
|
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SACDAT, ®_val);
|
2014-05-27 16:24:25 +08:00
|
|
|
val = (reg_val >> 4) & 0xffff;
|
2013-08-19 23:05:58 +08:00
|
|
|
|
2015-08-05 23:21:35 +08:00
|
|
|
clk_disable_unprepare(fsl_ac97_data->clk);
|
|
|
|
|
2017-11-21 06:16:07 +08:00
|
|
|
ret_unlock:
|
|
|
|
mutex_unlock(&fsl_ac97_data->ac97_reg_lock);
|
2013-08-19 23:05:58 +08:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_ac97_bus_ops fsl_ssi_ac97_ops = {
|
2017-12-18 10:52:04 +08:00
|
|
|
.read = fsl_ssi_ac97_read,
|
|
|
|
.write = fsl_ssi_ac97_write,
|
2013-08-19 23:05:58 +08:00
|
|
|
};
|
|
|
|
|
2008-01-12 01:15:26 +08:00
|
|
|
/**
|
2010-03-18 04:15:21 +08:00
|
|
|
* Make every character in a string lower-case
|
2008-01-12 01:15:26 +08:00
|
|
|
*/
|
2010-03-18 04:15:21 +08:00
|
|
|
static void make_lowercase(char *s)
|
|
|
|
{
|
2017-04-06 03:44:06 +08:00
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
for (; *s; s++)
|
|
|
|
*s = tolower(*s);
|
2010-03-18 04:15:21 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 18:54:45 +08:00
|
|
|
static int fsl_ssi_imx_probe(struct platform_device *pdev,
|
2017-12-18 10:52:04 +08:00
|
|
|
struct fsl_ssi *ssi, void __iomem *iomem)
|
2014-04-28 18:54:45 +08:00
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2017-12-18 10:52:01 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2014-04-28 18:54:46 +08:00
|
|
|
u32 dmas[4];
|
2014-04-28 18:54:45 +08:00
|
|
|
int ret;
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Backward compatible for a DT without ipg clock name assigned */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->has_ipg_clk_name)
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->clk = devm_clk_get(dev, "ipg");
|
2014-09-16 10:13:16 +08:00
|
|
|
else
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->clk = devm_clk_get(dev, NULL);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->clk)) {
|
|
|
|
ret = PTR_ERR(ssi->clk);
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "failed to get clock: %d\n", ret);
|
2014-04-28 18:54:45 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Enable the clock since regmap will not handle it in this case */
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->has_ipg_clk_name) {
|
|
|
|
ret = clk_prepare_enable(ssi->clk);
|
2014-09-16 10:13:16 +08:00
|
|
|
if (ret) {
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_err(dev, "clk_prepare_enable failed: %d\n", ret);
|
2014-09-16 10:13:16 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2014-04-28 18:54:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Do not error out for slave cases that live without a baud clock */
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->baudclk = devm_clk_get(dev, "baud");
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->baudclk))
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_dbg(dev, "failed to get baud clock: %ld\n",
|
2017-12-18 10:52:00 +08:00
|
|
|
PTR_ERR(ssi->baudclk));
|
2014-04-28 18:54:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->dma_params_tx.maxburst = ssi->dma_maxburst;
|
|
|
|
ssi->dma_params_rx.maxburst = ssi->dma_maxburst;
|
2017-12-18 10:52:03 +08:00
|
|
|
ssi->dma_params_tx.addr = ssi->ssi_phys + REG_SSI_STX0;
|
|
|
|
ssi->dma_params_rx.addr = ssi->ssi_phys + REG_SSI_SRX0;
|
2014-04-28 18:54:45 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Set to dual FIFO mode according to the SDMA sciprt */
|
2015-03-05 05:48:30 +08:00
|
|
|
ret = of_property_read_u32_array(np, "dmas", dmas, 4);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->use_dma && !ret && dmas[2] == IMX_DMATYPE_SSI_DUAL) {
|
|
|
|
ssi->use_dual_fifo = true;
|
2017-12-18 10:52:02 +08:00
|
|
|
/*
|
|
|
|
* Use even numbers to avoid channel swap due to SDMA
|
|
|
|
* script design
|
2014-04-28 18:54:45 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->dma_params_tx.maxburst &= ~0x1;
|
|
|
|
ssi->dma_params_rx.maxburst &= ~0x1;
|
2014-04-28 18:54:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->use_dma) {
|
2014-04-28 18:54:47 +08:00
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Some boards use an incompatible codec. Use imx-fiq-pcm-audio
|
|
|
|
* to get it working, as DMA is not possible in this situation.
|
2014-04-28 18:54:47 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->fiq_params.irq = ssi->irq;
|
|
|
|
ssi->fiq_params.base = iomem;
|
|
|
|
ssi->fiq_params.dma_params_rx = &ssi->dma_params_rx;
|
|
|
|
ssi->fiq_params.dma_params_tx = &ssi->dma_params_tx;
|
2014-04-28 18:54:47 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ret = imx_pcm_fiq_init(pdev, &ssi->fiq_params);
|
2014-04-28 18:54:47 +08:00
|
|
|
if (ret)
|
|
|
|
goto error_pcm;
|
|
|
|
} else {
|
2015-06-23 18:23:53 +08:00
|
|
|
ret = imx_pcm_dma_init(pdev, IMX_SSI_DMABUF_SIZE);
|
2014-04-28 18:54:47 +08:00
|
|
|
if (ret)
|
|
|
|
goto error_pcm;
|
|
|
|
}
|
|
|
|
|
2014-04-28 18:54:45 +08:00
|
|
|
return 0;
|
2014-04-28 18:54:47 +08:00
|
|
|
|
|
|
|
error_pcm:
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->has_ipg_clk_name)
|
|
|
|
clk_disable_unprepare(ssi->clk);
|
2017-12-18 10:52:04 +08:00
|
|
|
|
2014-04-28 18:54:47 +08:00
|
|
|
return ret;
|
2014-04-28 18:54:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:04 +08:00
|
|
|
static void fsl_ssi_imx_clean(struct platform_device *pdev, struct fsl_ssi *ssi)
|
2014-04-28 18:54:45 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->use_dma)
|
2014-04-28 18:54:47 +08:00
|
|
|
imx_pcm_fiq_exit(pdev);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi->has_ipg_clk_name)
|
|
|
|
clk_disable_unprepare(ssi->clk);
|
2014-04-28 18:54:45 +08:00
|
|
|
}
|
|
|
|
|
2012-12-07 22:26:16 +08:00
|
|
|
static int fsl_ssi_probe(struct platform_device *pdev)
|
2008-01-12 01:15:26 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi;
|
2008-01-12 01:15:26 +08:00
|
|
|
int ret = 0;
|
2010-08-20 04:26:58 +08:00
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2017-12-18 10:52:01 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2013-12-20 21:11:30 +08:00
|
|
|
const struct of_device_id *of_id;
|
2010-03-18 04:15:21 +08:00
|
|
|
const char *p, *sprop;
|
2018-02-12 05:53:21 +08:00
|
|
|
const __be32 *iprop;
|
2015-04-10 18:12:29 +08:00
|
|
|
struct resource *res;
|
2014-05-27 16:24:25 +08:00
|
|
|
void __iomem *iomem;
|
2010-03-18 04:15:21 +08:00
|
|
|
char name[64];
|
2016-01-19 03:07:44 +08:00
|
|
|
struct regmap_config regconfig = fsl_ssi_regconfig;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
of_id = of_match_device(fsl_ssi_ids, dev);
|
2014-05-27 16:24:18 +08:00
|
|
|
if (!of_id || !of_id->data)
|
2013-12-20 21:11:30 +08:00
|
|
|
return -EINVAL;
|
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi = devm_kzalloc(dev, sizeof(*ssi), GFP_KERNEL);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!ssi)
|
2010-03-18 04:15:21 +08:00
|
|
|
return -ENOMEM;
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->soc = of_id->data;
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->dev = dev;
|
2014-05-27 16:24:18 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Check if being used in AC97 mode */
|
2014-05-27 16:24:19 +08:00
|
|
|
sprop = of_get_property(np, "fsl,mode", NULL);
|
|
|
|
if (sprop) {
|
|
|
|
if (!strcmp(sprop, "ac97-slave"))
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->dai_fmt = SND_SOC_DAIFMT_AC97;
|
2014-05-27 16:24:19 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Select DMA or FIQ */
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->use_dma = !of_property_read_bool(np, "fsl,fiq-stream-filter");
|
2013-07-27 19:31:53 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi)) {
|
|
|
|
memcpy(&ssi->cpu_dai_drv, &fsl_ssi_ac97_dai,
|
2017-12-18 10:52:04 +08:00
|
|
|
sizeof(fsl_ssi_ac97_dai));
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ac97_data = ssi;
|
2013-08-19 23:05:58 +08:00
|
|
|
} else {
|
2017-12-18 10:52:00 +08:00
|
|
|
memcpy(&ssi->cpu_dai_drv, &fsl_ssi_dai_template,
|
2013-08-19 23:05:58 +08:00
|
|
|
sizeof(fsl_ssi_dai_template));
|
|
|
|
}
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->cpu_dai_drv.name = dev_name(dev);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2015-04-10 18:12:29 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2017-12-18 10:52:01 +08:00
|
|
|
iomem = devm_ioremap_resource(dev, res);
|
2015-04-10 18:12:29 +08:00
|
|
|
if (IS_ERR(iomem))
|
|
|
|
return PTR_ERR(iomem);
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->ssi_phys = res->start;
|
2014-05-27 16:24:25 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->imx21regs) {
|
2017-12-18 10:52:02 +08:00
|
|
|
/* No SACC{ST,EN,DIS} regs in imx21-class SSI */
|
2017-12-18 10:52:03 +08:00
|
|
|
regconfig.max_register = REG_SSI_SRMSK;
|
2016-09-30 02:22:52 +08:00
|
|
|
regconfig.num_reg_defaults_raw =
|
2017-12-18 10:52:03 +08:00
|
|
|
REG_SSI_SRMSK / sizeof(uint32_t) + 1;
|
2016-01-19 03:07:44 +08:00
|
|
|
}
|
|
|
|
|
2014-09-16 10:13:16 +08:00
|
|
|
ret = of_property_match_string(np, "clock-names", "ipg");
|
|
|
|
if (ret < 0) {
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->has_ipg_clk_name = false;
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->regs = devm_regmap_init_mmio(dev, iomem, ®config);
|
2014-09-16 10:13:16 +08:00
|
|
|
} else {
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->has_ipg_clk_name = true;
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->regs = devm_regmap_init_mmio_clk(dev, "ipg", iomem,
|
|
|
|
®config);
|
2014-09-16 10:13:16 +08:00
|
|
|
}
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->regs)) {
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "failed to init register map\n");
|
2017-12-18 10:52:00 +08:00
|
|
|
return PTR_ERR(ssi->regs);
|
2014-05-27 16:24:25 +08:00
|
|
|
}
|
2011-08-17 06:47:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->irq = platform_get_irq(pdev, 0);
|
|
|
|
if (ssi->irq < 0) {
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_err(dev, "no irq for node %s\n", pdev->name);
|
2017-12-18 10:52:00 +08:00
|
|
|
return ssi->irq;
|
2011-08-17 06:47:45 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Set software limitations for synchronous mode */
|
2013-12-03 18:38:07 +08:00
|
|
|
if (!of_find_property(np, "fsl,ssi-asynchronous", NULL)) {
|
2017-12-18 10:52:00 +08:00
|
|
|
if (!fsl_ssi_is_ac97(ssi)) {
|
|
|
|
ssi->cpu_dai_drv.symmetric_rates = 1;
|
|
|
|
ssi->cpu_dai_drv.symmetric_samplebits = 1;
|
2017-11-28 06:34:44 +08:00
|
|
|
}
|
2015-08-05 23:24:10 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->cpu_dai_drv.symmetric_channels = 1;
|
2013-12-03 18:38:07 +08:00
|
|
|
}
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Fetch FIFO depth; Set to 8 for older DT without this property */
|
2010-08-07 01:16:12 +08:00
|
|
|
iprop = of_get_property(np, "fsl,fifo-depth", NULL);
|
|
|
|
if (iprop)
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->fifo_depth = be32_to_cpup(iprop);
|
2010-08-07 01:16:12 +08:00
|
|
|
else
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->fifo_depth = 8;
|
2010-08-07 01:16:12 +08:00
|
|
|
|
2017-01-04 02:22:57 +08:00
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Configure TX and RX DMA watermarks -- when to send a DMA request
|
2017-01-04 02:22:57 +08:00
|
|
|
*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Values should be tested to avoid FIFO under/over run. Set maxburst
|
|
|
|
* to fifo_watermark to maxiumize DMA transaction to reduce overhead.
|
2017-01-04 02:22:57 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
switch (ssi->fifo_depth) {
|
2017-01-04 02:22:57 +08:00
|
|
|
case 15:
|
|
|
|
/*
|
2017-12-18 10:52:02 +08:00
|
|
|
* Set to 8 as a balanced configuration -- When TX FIFO has 8
|
|
|
|
* empty slots, send a DMA request to fill these 8 slots. The
|
|
|
|
* remaining 7 slots should be able to allow DMA to finish the
|
|
|
|
* transaction before TX FIFO underruns; Same applies to RX.
|
|
|
|
*
|
|
|
|
* Tested with cases running at 48kHz @ 16 bits x 16 channels
|
2017-01-04 02:22:57 +08:00
|
|
|
*/
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->fifo_watermark = 8;
|
|
|
|
ssi->dma_maxburst = 8;
|
2017-01-04 02:22:57 +08:00
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
default:
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Safely use old watermark configurations for older chips */
|
2017-12-18 10:52:00 +08:00
|
|
|
ssi->fifo_watermark = ssi->fifo_depth - 2;
|
|
|
|
ssi->dma_maxburst = ssi->fifo_depth - 2;
|
2017-01-04 02:22:57 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_set_drvdata(dev, ssi);
|
2014-04-28 18:54:47 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->imx) {
|
|
|
|
ret = fsl_ssi_imx_probe(pdev, ssi, iomem);
|
2014-04-28 18:54:45 +08:00
|
|
|
if (ret)
|
2014-12-02 05:57:14 +08:00
|
|
|
return ret;
|
2013-12-20 21:11:31 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi)) {
|
|
|
|
mutex_init(&ssi->ac97_reg_lock);
|
2017-11-21 06:14:55 +08:00
|
|
|
ret = snd_soc_set_ac97_ops_of_reset(&fsl_ssi_ac97_ops, pdev);
|
|
|
|
if (ret) {
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "failed to set AC'97 ops\n");
|
2017-11-21 06:14:55 +08:00
|
|
|
goto error_ac97_ops;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
ret = devm_snd_soc_register_component(dev, &fsl_ssi_component,
|
2017-12-18 10:52:00 +08:00
|
|
|
&ssi->cpu_dai_drv, 1);
|
2014-04-28 18:54:47 +08:00
|
|
|
if (ret) {
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_err(dev, "failed to register DAI: %d\n", ret);
|
2014-04-28 18:54:47 +08:00
|
|
|
goto error_asoc_register;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->use_dma) {
|
2017-12-18 10:52:01 +08:00
|
|
|
ret = devm_request_irq(dev, ssi->irq, fsl_ssi_isr, 0,
|
|
|
|
dev_name(dev), ssi);
|
2013-08-19 23:06:01 +08:00
|
|
|
if (ret < 0) {
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "failed to claim irq %u\n", ssi->irq);
|
2015-04-10 01:56:41 +08:00
|
|
|
goto error_asoc_register;
|
2013-08-19 23:06:01 +08:00
|
|
|
}
|
2012-03-16 16:56:43 +08:00
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
ret = fsl_ssi_debugfs_create(&ssi->dbg_stats, dev);
|
2013-12-20 21:11:29 +08:00
|
|
|
if (ret)
|
2015-04-10 01:56:41 +08:00
|
|
|
goto error_asoc_register;
|
2012-03-16 16:56:43 +08:00
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/* Bypass it if using newer DT bindings of ASoC machine drivers */
|
2014-04-28 18:54:48 +08:00
|
|
|
if (!of_get_property(np, "codec-handle", NULL))
|
2012-03-16 16:56:43 +08:00
|
|
|
goto done;
|
|
|
|
|
2017-12-18 10:52:02 +08:00
|
|
|
/*
|
|
|
|
* Backward compatible for older bindings by manually triggering the
|
|
|
|
* machine driver's probe(). Use /compatible property, including the
|
|
|
|
* address of CPU DAI driver structure, as the name of machine driver.
|
2010-03-18 04:15:21 +08:00
|
|
|
*/
|
2012-03-09 00:59:46 +08:00
|
|
|
sprop = of_get_property(of_find_node_by_path("/"), "compatible", NULL);
|
|
|
|
/* Sometimes the compatible name has a "fsl," prefix, so we strip it. */
|
2010-03-18 04:15:21 +08:00
|
|
|
p = strrchr(sprop, ',');
|
|
|
|
if (p)
|
|
|
|
sprop = p + 1;
|
|
|
|
snprintf(name, sizeof(name), "snd-soc-%s", sprop);
|
|
|
|
make_lowercase(name);
|
|
|
|
|
2017-12-18 10:52:01 +08:00
|
|
|
ssi->pdev = platform_device_register_data(dev, name, 0, NULL, 0);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->pdev)) {
|
|
|
|
ret = PTR_ERR(ssi->pdev);
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_err(dev, "failed to register platform: %d\n", ret);
|
2014-04-28 18:54:47 +08:00
|
|
|
goto error_sound_card;
|
2008-12-04 03:26:35 +08:00
|
|
|
}
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2012-03-16 16:56:43 +08:00
|
|
|
done:
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->dai_fmt)
|
2017-12-18 10:52:01 +08:00
|
|
|
_fsl_ssi_set_dai_fmt(dev, ssi, ssi->dai_fmt);
|
2014-05-27 16:24:19 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi)) {
|
2015-08-05 23:26:44 +08:00
|
|
|
u32 ssi_idx;
|
|
|
|
|
|
|
|
ret = of_property_read_u32(np, "cell-index", &ssi_idx);
|
|
|
|
if (ret) {
|
2017-12-18 10:52:05 +08:00
|
|
|
dev_err(dev, "failed to get SSI index property\n");
|
2015-08-05 23:26:44 +08:00
|
|
|
goto error_sound_card;
|
|
|
|
}
|
|
|
|
|
2017-12-18 10:52:04 +08:00
|
|
|
ssi->pdev = platform_device_register_data(NULL, "ac97-codec",
|
|
|
|
ssi_idx, NULL, 0);
|
2017-12-18 10:52:00 +08:00
|
|
|
if (IS_ERR(ssi->pdev)) {
|
|
|
|
ret = PTR_ERR(ssi->pdev);
|
2017-12-18 10:52:01 +08:00
|
|
|
dev_err(dev,
|
2015-08-05 23:26:44 +08:00
|
|
|
"failed to register AC97 codec platform: %d\n",
|
|
|
|
ret);
|
|
|
|
goto error_sound_card;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
return 0;
|
2010-08-04 06:55:28 +08:00
|
|
|
|
2014-04-28 18:54:47 +08:00
|
|
|
error_sound_card:
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_debugfs_remove(&ssi->dbg_stats);
|
2014-04-28 18:54:47 +08:00
|
|
|
error_asoc_register:
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi))
|
2017-11-21 06:14:55 +08:00
|
|
|
snd_soc_set_ac97_ops(NULL);
|
|
|
|
error_ac97_ops:
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi))
|
|
|
|
mutex_destroy(&ssi->ac97_reg_lock);
|
2017-11-21 06:16:07 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->imx)
|
|
|
|
fsl_ssi_imx_clean(pdev, ssi);
|
2011-08-17 06:47:45 +08:00
|
|
|
|
2010-08-04 06:55:28 +08:00
|
|
|
return ret;
|
2008-01-12 01:15:26 +08:00
|
|
|
}
|
|
|
|
|
2010-08-20 04:26:58 +08:00
|
|
|
static int fsl_ssi_remove(struct platform_device *pdev)
|
2008-01-12 01:15:26 +08:00
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = dev_get_drvdata(&pdev->dev);
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
fsl_ssi_debugfs_remove(&ssi->dbg_stats);
|
2013-12-20 21:11:29 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->pdev)
|
|
|
|
platform_device_unregister(ssi->pdev);
|
2014-04-28 18:54:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (ssi->soc->imx)
|
|
|
|
fsl_ssi_imx_clean(pdev, ssi);
|
2014-04-28 18:54:45 +08:00
|
|
|
|
2017-12-18 10:52:00 +08:00
|
|
|
if (fsl_ssi_is_ac97(ssi)) {
|
2015-08-05 23:25:31 +08:00
|
|
|
snd_soc_set_ac97_ops(NULL);
|
2017-12-18 10:52:00 +08:00
|
|
|
mutex_destroy(&ssi->ac97_reg_lock);
|
2017-11-21 06:16:07 +08:00
|
|
|
}
|
2015-08-05 23:25:31 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
return 0;
|
2008-01-12 01:15:26 +08:00
|
|
|
}
|
2010-03-18 04:15:21 +08:00
|
|
|
|
2015-09-18 11:09:12 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int fsl_ssi_suspend(struct device *dev)
|
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = dev_get_drvdata(dev);
|
|
|
|
struct regmap *regs = ssi->regs;
|
2015-09-18 11:09:12 +08:00
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_read(regs, REG_SSI_SFCSR, &ssi->regcache_sfcsr);
|
|
|
|
regmap_read(regs, REG_SSI_SACNT, &ssi->regcache_sacnt);
|
2015-09-18 11:09:12 +08:00
|
|
|
|
|
|
|
regcache_cache_only(regs, true);
|
|
|
|
regcache_mark_dirty(regs);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fsl_ssi_resume(struct device *dev)
|
|
|
|
{
|
2017-12-18 10:52:00 +08:00
|
|
|
struct fsl_ssi *ssi = dev_get_drvdata(dev);
|
|
|
|
struct regmap *regs = ssi->regs;
|
2015-09-18 11:09:12 +08:00
|
|
|
|
|
|
|
regcache_cache_only(regs, false);
|
|
|
|
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_update_bits(regs, REG_SSI_SFCSR,
|
2017-12-18 10:52:04 +08:00
|
|
|
SSI_SFCSR_RFWM1_MASK | SSI_SFCSR_TFWM1_MASK |
|
|
|
|
SSI_SFCSR_RFWM0_MASK | SSI_SFCSR_TFWM0_MASK,
|
|
|
|
ssi->regcache_sfcsr);
|
2017-12-18 10:52:03 +08:00
|
|
|
regmap_write(regs, REG_SSI_SACNT, ssi->regcache_sacnt);
|
2015-09-18 11:09:12 +08:00
|
|
|
|
|
|
|
return regcache_sync(regs);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PM_SLEEP */
|
|
|
|
|
|
|
|
static const struct dev_pm_ops fsl_ssi_pm = {
|
|
|
|
SET_SYSTEM_SLEEP_PM_OPS(fsl_ssi_suspend, fsl_ssi_resume)
|
|
|
|
};
|
|
|
|
|
2011-02-23 12:05:04 +08:00
|
|
|
static struct platform_driver fsl_ssi_driver = {
|
2010-03-18 04:15:21 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "fsl-ssi-dai",
|
|
|
|
.of_match_table = fsl_ssi_ids,
|
2015-09-18 11:09:12 +08:00
|
|
|
.pm = &fsl_ssi_pm,
|
2010-03-18 04:15:21 +08:00
|
|
|
},
|
|
|
|
.probe = fsl_ssi_probe,
|
|
|
|
.remove = fsl_ssi_remove,
|
|
|
|
};
|
2008-01-12 01:15:26 +08:00
|
|
|
|
2011-11-25 10:10:55 +08:00
|
|
|
module_platform_driver(fsl_ssi_driver);
|
2009-03-06 07:23:37 +08:00
|
|
|
|
2013-07-21 03:16:01 +08:00
|
|
|
MODULE_ALIAS("platform:fsl-ssi-dai");
|
2008-01-12 01:15:26 +08:00
|
|
|
MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
|
|
|
|
MODULE_DESCRIPTION("Freescale Synchronous Serial Interface (SSI) ASoC Driver");
|
2010-03-18 04:15:21 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|