2007-07-31 16:18:44 +00:00
|
|
|
/*
|
|
|
|
* CS4270 ALSA SoC (ASoC) codec driver
|
|
|
|
*
|
|
|
|
* Author: Timur Tabi <timur@freescale.com>
|
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* Copyright 2007-2009 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.
|
2007-07-31 16:18:44 +00:00
|
|
|
*
|
|
|
|
* This is an ASoC device driver for the Cirrus Logic CS4270 codec.
|
|
|
|
*
|
|
|
|
* Current features/limitations:
|
|
|
|
*
|
2009-03-08 16:51:52 +00:00
|
|
|
* - Software mode is supported. Stand-alone mode is not supported.
|
|
|
|
* - Only I2C is supported, not SPI
|
|
|
|
* - Support for master and slave mode
|
|
|
|
* - The machine driver's 'startup' function must call
|
|
|
|
* cs4270_set_dai_sysclk() with the value of MCLK.
|
|
|
|
* - Only I2S and left-justified modes are supported
|
2009-05-05 23:26:01 +00:00
|
|
|
* - Power management is supported
|
2007-07-31 16:18:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2007-07-31 16:18:44 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <linux/i2c.h>
|
2009-05-05 23:26:01 +00:00
|
|
|
#include <linux/delay.h>
|
2009-11-30 16:56:11 +00:00
|
|
|
#include <linux/regulator/consumer.h>
|
2012-07-25 13:28:34 +00:00
|
|
|
#include <linux/of_device.h>
|
2012-07-25 13:28:35 +00:00
|
|
|
#include <linux/of_gpio.h>
|
2007-07-31 16:18:44 +00:00
|
|
|
|
2007-12-18 14:42:53 +00:00
|
|
|
/*
|
|
|
|
* The codec isn't really big-endian or little-endian, since the I2S
|
|
|
|
* interface requires data to be sent serially with the MSbit first.
|
|
|
|
* However, to support BE and LE I2S devices, we specify both here. That
|
|
|
|
* way, ALSA will always match the bit patterns.
|
|
|
|
*/
|
|
|
|
#define CS4270_FORMATS (SNDRV_PCM_FMTBIT_S8 | \
|
|
|
|
SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_3BE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE)
|
|
|
|
|
|
|
|
/* CS4270 registers addresses */
|
|
|
|
#define CS4270_CHIPID 0x01 /* Chip ID */
|
|
|
|
#define CS4270_PWRCTL 0x02 /* Power Control */
|
|
|
|
#define CS4270_MODE 0x03 /* Mode Control */
|
|
|
|
#define CS4270_FORMAT 0x04 /* Serial Format, ADC/DAC Control */
|
|
|
|
#define CS4270_TRANS 0x05 /* Transition Control */
|
|
|
|
#define CS4270_MUTE 0x06 /* Mute Control */
|
|
|
|
#define CS4270_VOLA 0x07 /* DAC Channel A Volume Control */
|
|
|
|
#define CS4270_VOLB 0x08 /* DAC Channel B Volume Control */
|
|
|
|
|
|
|
|
#define CS4270_FIRSTREG 0x01
|
|
|
|
#define CS4270_LASTREG 0x08
|
|
|
|
#define CS4270_NUMREGS (CS4270_LASTREG - CS4270_FIRSTREG + 1)
|
2009-05-05 09:25:00 +00:00
|
|
|
#define CS4270_I2C_INCR 0x80
|
2007-08-01 10:22:07 +00:00
|
|
|
|
2007-12-18 14:42:53 +00:00
|
|
|
/* Bit masks for the CS4270 registers */
|
|
|
|
#define CS4270_CHIPID_ID 0xF0
|
|
|
|
#define CS4270_CHIPID_REV 0x0F
|
|
|
|
#define CS4270_PWRCTL_FREEZE 0x80
|
|
|
|
#define CS4270_PWRCTL_PDN_ADC 0x20
|
|
|
|
#define CS4270_PWRCTL_PDN_DAC 0x02
|
|
|
|
#define CS4270_PWRCTL_PDN 0x01
|
2009-05-05 23:26:01 +00:00
|
|
|
#define CS4270_PWRCTL_PDN_ALL \
|
|
|
|
(CS4270_PWRCTL_PDN_ADC | CS4270_PWRCTL_PDN_DAC | CS4270_PWRCTL_PDN)
|
2007-12-18 14:42:53 +00:00
|
|
|
#define CS4270_MODE_SPEED_MASK 0x30
|
|
|
|
#define CS4270_MODE_1X 0x00
|
|
|
|
#define CS4270_MODE_2X 0x10
|
|
|
|
#define CS4270_MODE_4X 0x20
|
|
|
|
#define CS4270_MODE_SLAVE 0x30
|
|
|
|
#define CS4270_MODE_DIV_MASK 0x0E
|
|
|
|
#define CS4270_MODE_DIV1 0x00
|
|
|
|
#define CS4270_MODE_DIV15 0x02
|
|
|
|
#define CS4270_MODE_DIV2 0x04
|
|
|
|
#define CS4270_MODE_DIV3 0x06
|
|
|
|
#define CS4270_MODE_DIV4 0x08
|
|
|
|
#define CS4270_MODE_POPGUARD 0x01
|
|
|
|
#define CS4270_FORMAT_FREEZE_A 0x80
|
|
|
|
#define CS4270_FORMAT_FREEZE_B 0x40
|
|
|
|
#define CS4270_FORMAT_LOOPBACK 0x20
|
|
|
|
#define CS4270_FORMAT_DAC_MASK 0x18
|
|
|
|
#define CS4270_FORMAT_DAC_LJ 0x00
|
|
|
|
#define CS4270_FORMAT_DAC_I2S 0x08
|
|
|
|
#define CS4270_FORMAT_DAC_RJ16 0x18
|
|
|
|
#define CS4270_FORMAT_DAC_RJ24 0x10
|
|
|
|
#define CS4270_FORMAT_ADC_MASK 0x01
|
|
|
|
#define CS4270_FORMAT_ADC_LJ 0x00
|
|
|
|
#define CS4270_FORMAT_ADC_I2S 0x01
|
|
|
|
#define CS4270_TRANS_ONE_VOL 0x80
|
|
|
|
#define CS4270_TRANS_SOFT 0x40
|
|
|
|
#define CS4270_TRANS_ZERO 0x20
|
|
|
|
#define CS4270_TRANS_INV_ADC_A 0x08
|
|
|
|
#define CS4270_TRANS_INV_ADC_B 0x10
|
|
|
|
#define CS4270_TRANS_INV_DAC_A 0x02
|
|
|
|
#define CS4270_TRANS_INV_DAC_B 0x04
|
|
|
|
#define CS4270_TRANS_DEEMPH 0x01
|
|
|
|
#define CS4270_MUTE_AUTO 0x20
|
|
|
|
#define CS4270_MUTE_ADC_A 0x08
|
|
|
|
#define CS4270_MUTE_ADC_B 0x10
|
|
|
|
#define CS4270_MUTE_POLARITY 0x04
|
|
|
|
#define CS4270_MUTE_DAC_A 0x01
|
|
|
|
#define CS4270_MUTE_DAC_B 0x02
|
|
|
|
|
2011-01-10 19:28:32 +00:00
|
|
|
/* Power-on default values for the registers
|
|
|
|
*
|
|
|
|
* This array contains the power-on default values of the registers, with the
|
|
|
|
* exception of the "CHIPID" register (01h). The lower four bits of that
|
|
|
|
* register contain the hardware revision, so it is treated as volatile.
|
|
|
|
*/
|
2012-09-10 04:57:03 +00:00
|
|
|
static const struct reg_default cs4270_reg_defaults[] = {
|
|
|
|
{ 2, 0x00 },
|
|
|
|
{ 3, 0x30 },
|
|
|
|
{ 4, 0x00 },
|
|
|
|
{ 5, 0x60 },
|
|
|
|
{ 6, 0x20 },
|
|
|
|
{ 7, 0x00 },
|
|
|
|
{ 8, 0x00 },
|
2011-01-10 19:28:32 +00:00
|
|
|
};
|
|
|
|
|
2009-11-30 16:56:11 +00:00
|
|
|
static const char *supply_names[] = {
|
|
|
|
"va", "vd", "vlc"
|
|
|
|
};
|
|
|
|
|
2009-01-23 22:31:19 +00:00
|
|
|
/* Private data for the CS4270 */
|
|
|
|
struct cs4270_private {
|
2012-09-10 04:57:03 +00:00
|
|
|
struct regmap *regmap;
|
2009-01-23 22:31:19 +00:00
|
|
|
unsigned int mclk; /* Input frequency of the MCLK pin */
|
|
|
|
unsigned int mode; /* The mode (I2S or left-justified) */
|
2009-02-25 13:37:21 +00:00
|
|
|
unsigned int slave_mode;
|
2009-04-24 14:37:45 +00:00
|
|
|
unsigned int manual_mute;
|
2009-11-30 16:56:11 +00:00
|
|
|
|
|
|
|
/* power domain regulators */
|
|
|
|
struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
|
2009-01-23 22:31:19 +00:00
|
|
|
};
|
|
|
|
|
2013-08-11 11:29:07 +00:00
|
|
|
static const struct snd_soc_dapm_widget cs4270_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_INPUT("AINL"),
|
|
|
|
SND_SOC_DAPM_INPUT("AINR"),
|
|
|
|
|
|
|
|
SND_SOC_DAPM_OUTPUT("AOUTL"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("AOUTR"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route cs4270_dapm_routes[] = {
|
|
|
|
{ "Capture", NULL, "AINA" },
|
|
|
|
{ "Capture", NULL, "AINB" },
|
|
|
|
|
|
|
|
{ "AOUTA", NULL, "Playback" },
|
|
|
|
{ "AOUTB", NULL, "Playback" },
|
|
|
|
};
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
|
|
|
* struct cs4270_mode_ratios - clock ratio tables
|
|
|
|
* @ratio: the ratio of MCLK to the sample rate
|
|
|
|
* @speed_mode: the Speed Mode bits to set in the Mode Control register for
|
|
|
|
* this ratio
|
|
|
|
* @mclk: the Ratio Select bits to set in the Mode Control register for this
|
|
|
|
* ratio
|
2007-12-18 14:42:53 +00:00
|
|
|
*
|
|
|
|
* The data for this chart is taken from Table 5 of the CS4270 reference
|
|
|
|
* manual.
|
|
|
|
*
|
|
|
|
* This table is used to determine how to program the Mode Control register.
|
|
|
|
* It is also used by cs4270_set_dai_sysclk() to tell ALSA which sampling
|
|
|
|
* rates the CS4270 currently supports.
|
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* @speed_mode is the corresponding bit pattern to be written to the
|
2007-12-18 14:42:53 +00:00
|
|
|
* MODE bits of the Mode Control Register
|
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* @mclk is the corresponding bit pattern to be wirten to the MCLK bits of
|
2007-12-18 14:42:53 +00:00
|
|
|
* the Mode Control Register.
|
|
|
|
*
|
|
|
|
* In situations where a single ratio is represented by multiple speed
|
|
|
|
* modes, we favor the slowest speed. E.g, for a ratio of 128, we pick
|
|
|
|
* double-speed instead of quad-speed. However, the CS4270 errata states
|
2009-01-30 17:14:49 +00:00
|
|
|
* that divide-By-1.5 can cause failures, so we avoid that mode where
|
2007-12-18 14:42:53 +00:00
|
|
|
* possible.
|
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* Errata: There is an errata for the CS4270 where divide-by-1.5 does not
|
|
|
|
* work if Vd is 3.3V. If this effects you, select the
|
2007-12-18 14:42:53 +00:00
|
|
|
* CONFIG_SND_SOC_CS4270_VD33_ERRATA Kconfig option, and the driver will
|
|
|
|
* never select any sample rates that require divide-by-1.5.
|
|
|
|
*/
|
2009-01-30 17:14:49 +00:00
|
|
|
struct cs4270_mode_ratios {
|
2007-12-18 14:42:53 +00:00
|
|
|
unsigned int ratio;
|
|
|
|
u8 speed_mode;
|
|
|
|
u8 mclk;
|
2009-01-30 17:14:49 +00:00
|
|
|
};
|
|
|
|
|
2009-02-02 20:50:45 +00:00
|
|
|
static struct cs4270_mode_ratios cs4270_mode_ratios[] = {
|
2007-12-18 14:42:53 +00:00
|
|
|
{64, CS4270_MODE_4X, CS4270_MODE_DIV1},
|
|
|
|
#ifndef CONFIG_SND_SOC_CS4270_VD33_ERRATA
|
|
|
|
{96, CS4270_MODE_4X, CS4270_MODE_DIV15},
|
|
|
|
#endif
|
|
|
|
{128, CS4270_MODE_2X, CS4270_MODE_DIV1},
|
|
|
|
{192, CS4270_MODE_4X, CS4270_MODE_DIV3},
|
|
|
|
{256, CS4270_MODE_1X, CS4270_MODE_DIV1},
|
|
|
|
{384, CS4270_MODE_2X, CS4270_MODE_DIV3},
|
|
|
|
{512, CS4270_MODE_1X, CS4270_MODE_DIV2},
|
|
|
|
{768, CS4270_MODE_1X, CS4270_MODE_DIV3},
|
|
|
|
{1024, CS4270_MODE_1X, CS4270_MODE_DIV4}
|
|
|
|
};
|
|
|
|
|
|
|
|
/* The number of MCLK/LRCK ratios supported by the CS4270 */
|
|
|
|
#define NUM_MCLK_RATIOS ARRAY_SIZE(cs4270_mode_ratios)
|
2007-08-01 10:22:07 +00:00
|
|
|
|
2012-09-10 04:57:03 +00:00
|
|
|
static bool cs4270_reg_is_readable(struct device *dev, unsigned int reg)
|
2011-01-10 19:28:32 +00:00
|
|
|
{
|
|
|
|
return (reg >= CS4270_FIRSTREG) && (reg <= CS4270_LASTREG);
|
|
|
|
}
|
|
|
|
|
2012-09-10 04:57:03 +00:00
|
|
|
static bool cs4270_reg_is_volatile(struct device *dev, unsigned int reg)
|
2011-01-10 19:28:32 +00:00
|
|
|
{
|
|
|
|
/* Unreadable registers are considered volatile */
|
|
|
|
if ((reg < CS4270_FIRSTREG) || (reg > CS4270_LASTREG))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return reg == CS4270_CHIPID;
|
|
|
|
}
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
|
|
|
* cs4270_set_dai_sysclk - determine the CS4270 samples rates.
|
|
|
|
* @codec_dai: the codec DAI
|
|
|
|
* @clk_id: the clock ID (ignored)
|
|
|
|
* @freq: the MCLK input frequency
|
|
|
|
* @dir: the clock direction (ignored)
|
2007-08-01 10:22:07 +00:00
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* This function is used to tell the codec driver what the input MCLK
|
|
|
|
* frequency is.
|
2007-08-01 10:22:07 +00:00
|
|
|
*
|
|
|
|
* The value of MCLK is used to determine which sample rates are supported
|
|
|
|
* by the CS4270. The ratio of MCLK / Fs must be equal to one of nine
|
2009-01-30 17:14:49 +00:00
|
|
|
* supported values - 64, 96, 128, 192, 256, 384, 512, 768, and 1024.
|
2007-08-01 10:22:07 +00:00
|
|
|
*
|
|
|
|
* This function calculates the nine ratios and determines which ones match
|
|
|
|
* a standard sample rate. If there's a match, then it is added to the list
|
2009-01-30 17:14:49 +00:00
|
|
|
* of supported sample rates.
|
2007-08-01 10:22:07 +00:00
|
|
|
*
|
|
|
|
* This function must be called by the machine driver's 'startup' function,
|
|
|
|
* otherwise the list of supported sample rates will not be available in
|
|
|
|
* time for ALSA.
|
2010-01-15 16:36:48 +00:00
|
|
|
*
|
|
|
|
* For setups with variable MCLKs, pass 0 as 'freq' argument. This will cause
|
|
|
|
* theoretically possible sample rates to be enabled. Call it again with a
|
|
|
|
* proper value set one the external clock is set (most probably you would do
|
|
|
|
* that from a machine's driver 'hw_param' hook.
|
2007-08-01 10:22:07 +00:00
|
|
|
*/
|
2008-07-07 15:07:52 +00:00
|
|
|
static int cs4270_set_dai_sysclk(struct snd_soc_dai *codec_dai,
|
2007-08-01 10:22:07 +00:00
|
|
|
int clk_id, unsigned int freq, int dir)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2007-08-01 10:22:07 +00:00
|
|
|
|
|
|
|
cs4270->mclk = freq;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
|
|
|
* cs4270_set_dai_fmt - configure the codec for the selected audio format
|
|
|
|
* @codec_dai: the codec DAI
|
|
|
|
* @format: a SND_SOC_DAIFMT_x value indicating the data format
|
2007-08-01 10:22:07 +00:00
|
|
|
*
|
|
|
|
* This function takes a bitmask of SND_SOC_DAIFMT_x bits and programs the
|
|
|
|
* codec accordingly.
|
|
|
|
*
|
|
|
|
* Currently, this function only supports SND_SOC_DAIFMT_I2S and
|
|
|
|
* SND_SOC_DAIFMT_LEFT_J. The CS4270 codec also supports right-justified
|
|
|
|
* data for playback only, but ASoC currently does not support different
|
|
|
|
* formats for playback vs. record.
|
|
|
|
*/
|
2008-07-07 15:07:52 +00:00
|
|
|
static int cs4270_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
2007-08-01 10:22:07 +00:00
|
|
|
unsigned int format)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = codec_dai->codec;
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2007-08-01 10:22:07 +00:00
|
|
|
|
2009-02-25 13:37:21 +00:00
|
|
|
/* set DAI format */
|
2007-08-01 10:22:07 +00:00
|
|
|
switch (format & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
cs4270->mode = format & SND_SOC_DAIFMT_FORMAT_MASK;
|
|
|
|
break;
|
|
|
|
default:
|
2009-02-02 21:08:29 +00:00
|
|
|
dev_err(codec->dev, "invalid dai format\n");
|
2011-10-05 23:29:56 +00:00
|
|
|
return -EINVAL;
|
2007-08-01 10:22:07 +00:00
|
|
|
}
|
|
|
|
|
2009-02-25 13:37:21 +00:00
|
|
|
/* set master/slave audio interface */
|
|
|
|
switch (format & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_CBS_CFS:
|
|
|
|
cs4270->slave_mode = 1;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
cs4270->slave_mode = 0;
|
|
|
|
break;
|
|
|
|
default:
|
2009-02-28 12:21:03 +00:00
|
|
|
/* all other modes are unsupported by the hardware */
|
2011-10-05 23:29:56 +00:00
|
|
|
dev_err(codec->dev, "Unknown master/slave configuration\n");
|
|
|
|
return -EINVAL;
|
2009-02-25 13:37:21 +00:00
|
|
|
}
|
|
|
|
|
2011-10-05 23:29:56 +00:00
|
|
|
return 0;
|
2007-08-01 10:22:07 +00:00
|
|
|
}
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
|
|
|
* cs4270_hw_params - program the CS4270 with the given hardware parameters.
|
|
|
|
* @substream: the audio stream
|
|
|
|
* @params: the hardware parameters to set
|
|
|
|
* @dai: the SOC DAI (ignored)
|
2007-07-31 16:18:44 +00:00
|
|
|
*
|
2009-01-30 17:14:49 +00:00
|
|
|
* This function programs the hardware with the values provided.
|
|
|
|
* Specifically, the sample rate and the data format.
|
|
|
|
*
|
|
|
|
* The .ops functions are used to provide board-specific data, like input
|
|
|
|
* frequencies, to this driver. This function takes that information,
|
2007-07-31 16:18:44 +00:00
|
|
|
* combines it with the hardware parameters provided, and programs the
|
|
|
|
* hardware accordingly.
|
|
|
|
*/
|
|
|
|
static int cs4270_hw_params(struct snd_pcm_substream *substream,
|
2008-11-18 22:11:38 +00:00
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
2007-07-31 16:18:44 +00:00
|
|
|
{
|
2012-04-04 14:58:16 +00:00
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2008-04-17 16:58:34 +00:00
|
|
|
int ret;
|
2007-07-31 16:18:44 +00:00
|
|
|
unsigned int i;
|
|
|
|
unsigned int rate;
|
|
|
|
unsigned int ratio;
|
|
|
|
int reg;
|
|
|
|
|
|
|
|
/* Figure out which MCLK/LRCK ratio to use */
|
|
|
|
|
|
|
|
rate = params_rate(params); /* Sampling rate, in Hz */
|
|
|
|
ratio = cs4270->mclk / rate; /* MCLK/LRCK ratio */
|
|
|
|
|
2007-08-01 10:22:07 +00:00
|
|
|
for (i = 0; i < NUM_MCLK_RATIOS; i++) {
|
2007-12-18 14:42:53 +00:00
|
|
|
if (cs4270_mode_ratios[i].ratio == ratio)
|
2007-07-31 16:18:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2007-08-01 10:22:07 +00:00
|
|
|
if (i == NUM_MCLK_RATIOS) {
|
2007-07-31 16:18:44 +00:00
|
|
|
/* We did not find a matching ratio */
|
2009-02-02 21:08:29 +00:00
|
|
|
dev_err(codec->dev, "could not find matching ratio\n");
|
2007-07-31 16:18:44 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
/* Set the sample rate */
|
2007-07-31 16:18:44 +00:00
|
|
|
|
|
|
|
reg = snd_soc_read(codec, CS4270_MODE);
|
|
|
|
reg &= ~(CS4270_MODE_SPEED_MASK | CS4270_MODE_DIV_MASK);
|
2009-02-25 13:37:21 +00:00
|
|
|
reg |= cs4270_mode_ratios[i].mclk;
|
|
|
|
|
|
|
|
if (cs4270->slave_mode)
|
|
|
|
reg |= CS4270_MODE_SLAVE;
|
|
|
|
else
|
|
|
|
reg |= cs4270_mode_ratios[i].speed_mode;
|
2007-07-31 16:18:44 +00:00
|
|
|
|
|
|
|
ret = snd_soc_write(codec, CS4270_MODE, reg);
|
|
|
|
if (ret < 0) {
|
2009-02-02 21:08:29 +00:00
|
|
|
dev_err(codec->dev, "i2c write failed\n");
|
2007-07-31 16:18:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
/* Set the DAI format */
|
2007-07-31 16:18:44 +00:00
|
|
|
|
|
|
|
reg = snd_soc_read(codec, CS4270_FORMAT);
|
|
|
|
reg &= ~(CS4270_FORMAT_DAC_MASK | CS4270_FORMAT_ADC_MASK);
|
|
|
|
|
|
|
|
switch (cs4270->mode) {
|
|
|
|
case SND_SOC_DAIFMT_I2S:
|
|
|
|
reg |= CS4270_FORMAT_DAC_I2S | CS4270_FORMAT_ADC_I2S;
|
|
|
|
break;
|
|
|
|
case SND_SOC_DAIFMT_LEFT_J:
|
|
|
|
reg |= CS4270_FORMAT_DAC_LJ | CS4270_FORMAT_ADC_LJ;
|
|
|
|
break;
|
|
|
|
default:
|
2009-02-02 21:08:29 +00:00
|
|
|
dev_err(codec->dev, "unknown dai format\n");
|
2007-07-31 16:18:44 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = snd_soc_write(codec, CS4270_FORMAT, reg);
|
|
|
|
if (ret < 0) {
|
2009-02-02 21:08:29 +00:00
|
|
|
dev_err(codec->dev, "i2c write failed\n");
|
2007-07-31 16:18:44 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
2009-04-24 14:37:45 +00:00
|
|
|
* cs4270_dai_mute - enable/disable the CS4270 external mute
|
2009-01-30 17:14:49 +00:00
|
|
|
* @dai: the SOC DAI
|
|
|
|
* @mute: 0 = disable mute, 1 = enable mute
|
2007-07-31 16:18:44 +00:00
|
|
|
*
|
|
|
|
* This function toggles the mute bits in the MUTE register. The CS4270's
|
|
|
|
* mute capability is intended for external muting circuitry, so if the
|
|
|
|
* board does not have the MUTEA or MUTEB pins connected to such circuitry,
|
|
|
|
* then this function will do nothing.
|
|
|
|
*/
|
2009-04-24 14:37:45 +00:00
|
|
|
static int cs4270_dai_mute(struct snd_soc_dai *dai, int mute)
|
2007-07-31 16:18:44 +00:00
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2007-07-31 16:18:44 +00:00
|
|
|
int reg6;
|
|
|
|
|
|
|
|
reg6 = snd_soc_read(codec, CS4270_MUTE);
|
|
|
|
|
|
|
|
if (mute)
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
reg6 |= CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B;
|
2009-04-24 14:37:45 +00:00
|
|
|
else {
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
reg6 &= ~(CS4270_MUTE_DAC_A | CS4270_MUTE_DAC_B);
|
2009-04-24 14:37:45 +00:00
|
|
|
reg6 |= cs4270->manual_mute;
|
|
|
|
}
|
2007-07-31 16:18:44 +00:00
|
|
|
|
|
|
|
return snd_soc_write(codec, CS4270_MUTE, reg6);
|
|
|
|
}
|
|
|
|
|
2009-04-24 14:37:45 +00:00
|
|
|
/**
|
|
|
|
* cs4270_soc_put_mute - put callback for the 'Master Playback switch'
|
|
|
|
* alsa control.
|
|
|
|
* @kcontrol: mixer control
|
|
|
|
* @ucontrol: control element information
|
|
|
|
*
|
|
|
|
* This function basically passes the arguments on to the generic
|
|
|
|
* snd_soc_put_volsw() function and saves the mute information in
|
|
|
|
* our private data structure. This is because we want to prevent
|
|
|
|
* cs4270_dai_mute() neglecting the user's decision to manually
|
|
|
|
* mute the codec's output.
|
|
|
|
*
|
|
|
|
* Returns 0 for success.
|
|
|
|
*/
|
|
|
|
static int cs4270_soc_put_mute(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
|
|
|
{
|
|
|
|
struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2009-04-24 14:37:45 +00:00
|
|
|
int left = !ucontrol->value.integer.value[0];
|
|
|
|
int right = !ucontrol->value.integer.value[1];
|
|
|
|
|
|
|
|
cs4270->manual_mute = (left ? CS4270_MUTE_DAC_A : 0) |
|
|
|
|
(right ? CS4270_MUTE_DAC_B : 0);
|
|
|
|
|
|
|
|
return snd_soc_put_volsw(kcontrol, ucontrol);
|
|
|
|
}
|
|
|
|
|
2007-07-31 16:18:44 +00:00
|
|
|
/* A list of non-DAPM controls that the CS4270 supports */
|
|
|
|
static const struct snd_kcontrol_new cs4270_snd_controls[] = {
|
|
|
|
SOC_DOUBLE_R("Master Playback Volume",
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
CS4270_VOLA, CS4270_VOLB, 0, 0xFF, 1),
|
|
|
|
SOC_SINGLE("Digital Sidetone Switch", CS4270_FORMAT, 5, 1, 0),
|
|
|
|
SOC_SINGLE("Soft Ramp Switch", CS4270_TRANS, 6, 1, 0),
|
|
|
|
SOC_SINGLE("Zero Cross Switch", CS4270_TRANS, 5, 1, 0),
|
2009-10-29 01:24:32 +00:00
|
|
|
SOC_SINGLE("De-emphasis filter", CS4270_TRANS, 0, 1, 0),
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
SOC_SINGLE("Popguard Switch", CS4270_MODE, 0, 1, 1),
|
|
|
|
SOC_SINGLE("Auto-Mute Switch", CS4270_MUTE, 5, 1, 0),
|
2009-04-24 14:37:45 +00:00
|
|
|
SOC_DOUBLE("Master Capture Switch", CS4270_MUTE, 3, 4, 1, 1),
|
|
|
|
SOC_DOUBLE_EXT("Master Playback Switch", CS4270_MUTE, 0, 1, 1, 1,
|
|
|
|
snd_soc_get_volsw, cs4270_soc_put_mute),
|
2007-07-31 16:18:44 +00:00
|
|
|
};
|
|
|
|
|
2011-11-23 10:40:40 +00:00
|
|
|
static const struct snd_soc_dai_ops cs4270_dai_ops = {
|
2009-03-03 01:41:00 +00:00
|
|
|
.hw_params = cs4270_hw_params,
|
|
|
|
.set_sysclk = cs4270_set_dai_sysclk,
|
|
|
|
.set_fmt = cs4270_set_dai_fmt,
|
2009-04-24 14:37:45 +00:00
|
|
|
.digital_mute = cs4270_dai_mute,
|
2009-03-03 01:41:00 +00:00
|
|
|
};
|
|
|
|
|
2010-10-06 23:18:17 +00:00
|
|
|
static struct snd_soc_dai_driver cs4270_dai = {
|
2010-03-17 20:15:21 +00:00
|
|
|
.name = "cs4270-hifi",
|
2009-01-23 22:31:19 +00:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "Playback",
|
2012-09-18 16:03:54 +00:00
|
|
|
.channels_min = 2,
|
2009-01-23 22:31:19 +00:00
|
|
|
.channels_max = 2,
|
2010-03-17 20:15:21 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 4000,
|
|
|
|
.rate_max = 216000,
|
2009-01-23 22:31:19 +00:00
|
|
|
.formats = CS4270_FORMATS,
|
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "Capture",
|
2012-09-18 16:03:54 +00:00
|
|
|
.channels_min = 2,
|
2009-01-23 22:31:19 +00:00
|
|
|
.channels_max = 2,
|
2010-03-17 20:15:21 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS,
|
|
|
|
.rate_min = 4000,
|
|
|
|
.rate_max = 216000,
|
2009-01-23 22:31:19 +00:00
|
|
|
.formats = CS4270_FORMATS,
|
|
|
|
},
|
2009-03-03 01:41:00 +00:00
|
|
|
.ops = &cs4270_dai_ops,
|
2009-01-23 22:31:19 +00:00
|
|
|
};
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
|
|
|
* cs4270_probe - ASoC probe function
|
|
|
|
* @pdev: platform device
|
|
|
|
*
|
|
|
|
* This function is called when ASoC has all the pieces it needs to
|
|
|
|
* instantiate a sound driver.
|
2009-01-29 20:28:37 +00:00
|
|
|
*/
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cs4270_probe(struct snd_soc_codec *codec)
|
2009-01-29 20:28:37 +00:00
|
|
|
{
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2012-09-10 04:53:12 +00:00
|
|
|
int ret;
|
2009-01-29 20:28:37 +00:00
|
|
|
|
2011-01-10 19:28:32 +00:00
|
|
|
/* Tell ASoC what kind of I/O to use to read the registers. ASoC will
|
|
|
|
* then do the I2C transactions itself.
|
|
|
|
*/
|
2012-09-10 04:57:03 +00:00
|
|
|
ret = snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
|
2007-07-31 16:18:44 +00:00
|
|
|
if (ret < 0) {
|
2011-01-10 19:28:32 +00:00
|
|
|
dev_err(codec->dev, "failed to set cache I/O (ret=%i)\n", ret);
|
2010-03-17 20:15:21 +00:00
|
|
|
return ret;
|
2009-01-23 22:31:19 +00:00
|
|
|
}
|
|
|
|
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
/* Disable auto-mute. This feature appears to be buggy. In some
|
|
|
|
* situations, auto-mute will not deactivate when it should, so we want
|
|
|
|
* this feature disabled by default. An application (e.g. alsactl) can
|
|
|
|
* re-enabled it by using the controls.
|
|
|
|
*/
|
2011-01-10 19:28:32 +00:00
|
|
|
ret = snd_soc_update_bits(codec, CS4270_MUTE, CS4270_MUTE_AUTO, 0);
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
if (ret < 0) {
|
2010-03-17 20:15:21 +00:00
|
|
|
dev_err(codec->dev, "i2c write failed\n");
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable automatic volume control. The hardware enables, and it
|
|
|
|
* causes volume change commands to be delayed, sometimes until after
|
|
|
|
* playback has started. An application (e.g. alsactl) can
|
|
|
|
* re-enabled it by using the controls.
|
|
|
|
*/
|
2011-01-10 19:28:32 +00:00
|
|
|
ret = snd_soc_update_bits(codec, CS4270_TRANS,
|
|
|
|
CS4270_TRANS_SOFT | CS4270_TRANS_ZERO, 0);
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
if (ret < 0) {
|
2010-03-17 20:15:21 +00:00
|
|
|
dev_err(codec->dev, "i2c write failed\n");
|
ASoC: add additional controls to the CS4270 codec driver
Update the CS4270 codec driver to allow applications to use the mixer to
control Digital Loopback, Soft Ramp, Zero Cross, Popguard, and Auto-Mute.
Soft Ramp, Zero Cross, and Auto-Mute are disabled by the driver when it first
initializes the hardware, but these features either don't work or interfere
with normal ALSA behavior. However, they can now be re-enabled by an
application if desired.
Remove CONFIG_SND_SOC_CS4270_HWMUTE and always allow ASoC to control the mute
bits. The driver previously and erroneously assumed that these bits
control only external muting circuitry, but they also control internal
muting circuitry, so they should always be used.
Signed-off-by: Timur Tabi <timur@freescale.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
2009-02-03 17:09:32 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies),
|
|
|
|
cs4270->supplies);
|
2007-07-31 16:18:44 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/**
|
2010-03-17 20:15:21 +00:00
|
|
|
* cs4270_remove - ASoC remove function
|
|
|
|
* @pdev: platform device
|
2009-01-30 17:14:49 +00:00
|
|
|
*
|
2010-03-17 20:15:21 +00:00
|
|
|
* This function is the counterpart to cs4270_probe().
|
2009-01-30 17:14:49 +00:00
|
|
|
*/
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cs4270_remove(struct snd_soc_codec *codec)
|
2009-01-23 22:31:19 +00:00
|
|
|
{
|
2010-03-17 20:15:21 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2009-01-23 22:31:19 +00:00
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies), cs4270->supplies);
|
2009-01-23 22:31:19 +00:00
|
|
|
|
|
|
|
return 0;
|
2009-01-23 00:23:39 +00:00
|
|
|
};
|
|
|
|
|
2009-05-05 23:26:01 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
|
|
|
|
/* This suspend/resume implementation can handle both - a simple standby
|
|
|
|
* where the codec remains powered, and a full suspend, where the voltage
|
|
|
|
* domain the codec is connected to is teared down and/or any other hardware
|
|
|
|
* reset condition is asserted.
|
|
|
|
*
|
|
|
|
* The codec's own power saving features are enabled in the suspend callback,
|
|
|
|
* and all registers are written back to the hardware when resuming.
|
|
|
|
*/
|
|
|
|
|
2011-12-02 09:18:28 +00:00
|
|
|
static int cs4270_soc_suspend(struct snd_soc_codec *codec)
|
2009-08-05 18:50:43 +00:00
|
|
|
{
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2009-11-30 16:56:11 +00:00
|
|
|
int reg, ret;
|
2009-08-05 18:50:43 +00:00
|
|
|
|
2009-11-30 16:56:11 +00:00
|
|
|
reg = snd_soc_read(codec, CS4270_PWRCTL) | CS4270_PWRCTL_PDN_ALL;
|
|
|
|
if (reg < 0)
|
|
|
|
return reg;
|
|
|
|
|
|
|
|
ret = snd_soc_write(codec, CS4270_PWRCTL, reg);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
regulator_bulk_disable(ARRAY_SIZE(cs4270->supplies),
|
|
|
|
cs4270->supplies);
|
|
|
|
|
|
|
|
return 0;
|
2009-08-05 18:50:43 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
static int cs4270_soc_resume(struct snd_soc_codec *codec)
|
2009-08-05 18:50:43 +00:00
|
|
|
{
|
2010-04-14 06:35:19 +00:00
|
|
|
struct cs4270_private *cs4270 = snd_soc_codec_get_drvdata(codec);
|
2012-03-19 16:15:43 +00:00
|
|
|
int reg, ret;
|
2009-05-05 23:26:01 +00:00
|
|
|
|
2012-03-19 16:15:43 +00:00
|
|
|
ret = regulator_bulk_enable(ARRAY_SIZE(cs4270->supplies),
|
|
|
|
cs4270->supplies);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2009-11-30 16:56:11 +00:00
|
|
|
|
2009-05-05 23:26:01 +00:00
|
|
|
/* In case the device was put to hard reset during sleep, we need to
|
|
|
|
* wait 500ns here before any I2C communication. */
|
|
|
|
ndelay(500);
|
|
|
|
|
|
|
|
/* first restore the entire register cache ... */
|
2012-09-10 04:57:03 +00:00
|
|
|
regcache_sync(cs4270->regmap);
|
2009-05-05 23:26:01 +00:00
|
|
|
|
|
|
|
/* ... then disable the power-down bits */
|
|
|
|
reg = snd_soc_read(codec, CS4270_PWRCTL);
|
|
|
|
reg &= ~CS4270_PWRCTL_PDN_ALL;
|
|
|
|
|
|
|
|
return snd_soc_write(codec, CS4270_PWRCTL, reg);
|
|
|
|
}
|
|
|
|
#else
|
2009-08-05 18:50:43 +00:00
|
|
|
#define cs4270_soc_suspend NULL
|
|
|
|
#define cs4270_soc_resume NULL
|
2009-05-05 23:26:01 +00:00
|
|
|
#endif /* CONFIG_PM */
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
/*
|
2011-05-25 07:53:12 +00:00
|
|
|
* ASoC codec driver structure
|
2010-03-17 20:15:21 +00:00
|
|
|
*/
|
2011-01-10 19:28:32 +00:00
|
|
|
static const struct snd_soc_codec_driver soc_codec_device_cs4270 = {
|
|
|
|
.probe = cs4270_probe,
|
|
|
|
.remove = cs4270_remove,
|
|
|
|
.suspend = cs4270_soc_suspend,
|
|
|
|
.resume = cs4270_soc_resume,
|
2012-09-10 04:48:11 +00:00
|
|
|
|
|
|
|
.controls = cs4270_snd_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(cs4270_snd_controls),
|
2013-08-11 11:29:07 +00:00
|
|
|
.dapm_widgets = cs4270_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(cs4270_dapm_widgets),
|
|
|
|
.dapm_routes = cs4270_dapm_routes,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(cs4270_dapm_routes),
|
2010-03-17 20:15:21 +00:00
|
|
|
};
|
|
|
|
|
2012-07-25 13:28:34 +00:00
|
|
|
/*
|
|
|
|
* cs4270_of_match - the device tree bindings
|
|
|
|
*/
|
|
|
|
static const struct of_device_id cs4270_of_match[] = {
|
|
|
|
{ .compatible = "cirrus,cs4270", },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, cs4270_of_match);
|
|
|
|
|
2012-09-10 04:57:03 +00:00
|
|
|
static const struct regmap_config cs4270_regmap = {
|
|
|
|
.reg_bits = 8,
|
|
|
|
.val_bits = 8,
|
|
|
|
.max_register = CS4270_LASTREG,
|
|
|
|
.reg_defaults = cs4270_reg_defaults,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(cs4270_reg_defaults),
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
|
|
|
|
.readable_reg = cs4270_reg_is_readable,
|
|
|
|
.volatile_reg = cs4270_reg_is_volatile,
|
|
|
|
};
|
|
|
|
|
2010-03-17 20:15:21 +00:00
|
|
|
/**
|
|
|
|
* cs4270_i2c_probe - initialize the I2C interface of the CS4270
|
|
|
|
* @i2c_client: the I2C client object
|
|
|
|
* @id: the I2C device ID (ignored)
|
|
|
|
*
|
|
|
|
* This function is called whenever the I2C subsystem finds a device that
|
|
|
|
* matches the device ID given via a prior call to i2c_add_driver().
|
|
|
|
*/
|
|
|
|
static int cs4270_i2c_probe(struct i2c_client *i2c_client,
|
|
|
|
const struct i2c_device_id *id)
|
|
|
|
{
|
2012-07-25 13:28:35 +00:00
|
|
|
struct device_node *np = i2c_client->dev.of_node;
|
2010-03-17 20:15:21 +00:00
|
|
|
struct cs4270_private *cs4270;
|
2012-09-10 04:57:03 +00:00
|
|
|
unsigned int val;
|
2012-09-10 04:53:12 +00:00
|
|
|
int ret, i;
|
|
|
|
|
|
|
|
cs4270 = devm_kzalloc(&i2c_client->dev, sizeof(struct cs4270_private),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!cs4270) {
|
|
|
|
dev_err(&i2c_client->dev, "could not allocate codec\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get the power supply regulators */
|
|
|
|
for (i = 0; i < ARRAY_SIZE(supply_names); i++)
|
|
|
|
cs4270->supplies[i].supply = supply_names[i];
|
|
|
|
|
|
|
|
ret = devm_regulator_bulk_get(&i2c_client->dev,
|
|
|
|
ARRAY_SIZE(cs4270->supplies),
|
|
|
|
cs4270->supplies);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
2010-03-17 20:15:21 +00:00
|
|
|
|
2012-07-25 13:28:35 +00:00
|
|
|
/* See if we have a way to bring the codec out of reset */
|
|
|
|
if (np) {
|
|
|
|
enum of_gpio_flags flags;
|
|
|
|
int gpio = of_get_named_gpio_flags(np, "reset-gpio", 0, &flags);
|
|
|
|
|
|
|
|
if (gpio_is_valid(gpio)) {
|
|
|
|
ret = devm_gpio_request_one(&i2c_client->dev, gpio,
|
|
|
|
flags & OF_GPIO_ACTIVE_LOW ?
|
|
|
|
GPIOF_OUT_INIT_LOW : GPIOF_OUT_INIT_HIGH,
|
|
|
|
"cs4270 reset");
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-10 04:57:03 +00:00
|
|
|
cs4270->regmap = devm_regmap_init_i2c(i2c_client, &cs4270_regmap);
|
|
|
|
if (IS_ERR(cs4270->regmap))
|
|
|
|
return PTR_ERR(cs4270->regmap);
|
2010-03-17 20:15:21 +00:00
|
|
|
|
2012-09-10 04:57:03 +00:00
|
|
|
/* Verify that we have a CS4270 */
|
|
|
|
ret = regmap_read(cs4270->regmap, CS4270_CHIPID, &val);
|
2010-03-17 20:15:21 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&i2c_client->dev, "failed to read i2c at addr %X\n",
|
|
|
|
i2c_client->addr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
/* The top four bits of the chip ID should be 1100. */
|
2012-09-10 04:57:03 +00:00
|
|
|
if ((val & 0xF0) != 0xC0) {
|
2010-03-17 20:15:21 +00:00
|
|
|
dev_err(&i2c_client->dev, "device at addr %X is not a CS4270\n",
|
|
|
|
i2c_client->addr);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_info(&i2c_client->dev, "found device at i2c address %X\n",
|
|
|
|
i2c_client->addr);
|
2012-09-10 04:57:03 +00:00
|
|
|
dev_info(&i2c_client->dev, "hardware revision %X\n", val & 0xF);
|
2010-03-17 20:15:21 +00:00
|
|
|
|
|
|
|
i2c_set_clientdata(i2c_client, cs4270);
|
|
|
|
|
|
|
|
ret = snd_soc_register_codec(&i2c_client->dev,
|
|
|
|
&soc_codec_device_cs4270, &cs4270_dai, 1);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cs4270_i2c_remove - remove an I2C device
|
|
|
|
* @i2c_client: the I2C client object
|
|
|
|
*
|
|
|
|
* This function is the counterpart to cs4270_i2c_probe().
|
|
|
|
*/
|
|
|
|
static int cs4270_i2c_remove(struct i2c_client *i2c_client)
|
|
|
|
{
|
|
|
|
snd_soc_unregister_codec(&i2c_client->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* cs4270_id - I2C device IDs supported by this driver
|
|
|
|
*/
|
2011-03-04 07:22:03 +00:00
|
|
|
static const struct i2c_device_id cs4270_id[] = {
|
2010-03-17 20:15:21 +00:00
|
|
|
{"cs4270", 0},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(i2c, cs4270_id);
|
|
|
|
|
2009-01-30 17:14:49 +00:00
|
|
|
/*
|
|
|
|
* cs4270_i2c_driver - I2C device identification
|
|
|
|
*
|
|
|
|
* This structure tells the I2C subsystem how to identify and support a
|
|
|
|
* given I2C device type.
|
|
|
|
*/
|
2009-01-23 00:23:39 +00:00
|
|
|
static struct i2c_driver cs4270_i2c_driver = {
|
|
|
|
.driver = {
|
2012-02-24 14:09:38 +00:00
|
|
|
.name = "cs4270",
|
2009-01-23 00:23:39 +00:00
|
|
|
.owner = THIS_MODULE,
|
2012-07-25 13:28:34 +00:00
|
|
|
.of_match_table = cs4270_of_match,
|
2009-01-23 00:23:39 +00:00
|
|
|
},
|
|
|
|
.id_table = cs4270_id,
|
|
|
|
.probe = cs4270_i2c_probe,
|
2009-01-23 22:31:19 +00:00
|
|
|
.remove = cs4270_i2c_remove,
|
2009-01-23 00:23:39 +00:00
|
|
|
};
|
2007-07-31 16:18:44 +00:00
|
|
|
|
2012-08-06 11:55:41 +00:00
|
|
|
module_i2c_driver(cs4270_i2c_driver);
|
2008-12-08 19:17:58 +00:00
|
|
|
|
2007-07-31 16:18:44 +00:00
|
|
|
MODULE_AUTHOR("Timur Tabi <timur@freescale.com>");
|
|
|
|
MODULE_DESCRIPTION("Cirrus Logic CS4270 ALSA SoC Codec Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|