2011-06-16 03:29:23 +08:00
|
|
|
/*
|
|
|
|
* Audio Codec driver supporting:
|
|
|
|
* AD1835A, AD1836, AD1837A, AD1838A, AD1839A
|
2009-08-13 11:59:32 +08:00
|
|
|
*
|
2011-06-16 03:29:23 +08:00
|
|
|
* Copyright 2009-2011 Analog Devices Inc.
|
2009-08-13 11:59:32 +08:00
|
|
|
*
|
2011-06-16 03:29:23 +08:00
|
|
|
* Licensed under the GPL-2 or later.
|
2009-08-13 11:59:32 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-08-13 11:59:32 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
#include <sound/tlv.h>
|
|
|
|
#include <linux/spi/spi.h>
|
2012-09-13 18:04:51 +08:00
|
|
|
#include <linux/regmap.h>
|
|
|
|
|
2009-08-13 11:59:32 +08:00
|
|
|
#include "ad1836.h"
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
enum ad1836_type {
|
|
|
|
AD1835,
|
|
|
|
AD1836,
|
|
|
|
AD1838,
|
|
|
|
};
|
|
|
|
|
2009-08-13 11:59:32 +08:00
|
|
|
/* codec private data */
|
|
|
|
struct ad1836_priv {
|
2011-06-06 19:38:38 +08:00
|
|
|
enum ad1836_type type;
|
2012-09-13 18:04:51 +08:00
|
|
|
struct regmap *regmap;
|
2009-08-13 11:59:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AD1836 volume/mute/de-emphasis etc. controls
|
|
|
|
*/
|
|
|
|
static const char *ad1836_deemp[] = {"None", "44.1kHz", "32kHz", "48kHz"};
|
|
|
|
|
|
|
|
static const struct soc_enum ad1836_deemp_enum =
|
|
|
|
SOC_ENUM_SINGLE(AD1836_DAC_CTRL1, 8, 4, ad1836_deemp);
|
|
|
|
|
2011-06-06 19:38:36 +08:00
|
|
|
#define AD1836_DAC_VOLUME(x) \
|
|
|
|
SOC_DOUBLE_R("DAC" #x " Playback Volume", AD1836_DAC_L_VOL(x), \
|
|
|
|
AD1836_DAC_R_VOL(x), 0, 0x3FF, 0)
|
|
|
|
|
|
|
|
#define AD1836_DAC_SWITCH(x) \
|
|
|
|
SOC_DOUBLE("DAC" #x " Playback Switch", AD1836_DAC_CTRL2, \
|
|
|
|
AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1)
|
|
|
|
|
|
|
|
#define AD1836_ADC_SWITCH(x) \
|
|
|
|
SOC_DOUBLE("ADC" #x " Capture Switch", AD1836_ADC_CTRL2, \
|
|
|
|
AD1836_MUTE_LEFT(x), AD1836_MUTE_RIGHT(x), 1, 1)
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_kcontrol_new ad183x_dac_controls[] = {
|
2011-06-06 19:38:36 +08:00
|
|
|
AD1836_DAC_VOLUME(1),
|
2011-06-06 19:38:38 +08:00
|
|
|
AD1836_DAC_SWITCH(1),
|
2011-06-06 19:38:36 +08:00
|
|
|
AD1836_DAC_VOLUME(2),
|
2011-06-06 19:38:38 +08:00
|
|
|
AD1836_DAC_SWITCH(2),
|
2011-06-06 19:38:36 +08:00
|
|
|
AD1836_DAC_VOLUME(3),
|
2011-06-06 19:38:38 +08:00
|
|
|
AD1836_DAC_SWITCH(3),
|
|
|
|
AD1836_DAC_VOLUME(4),
|
|
|
|
AD1836_DAC_SWITCH(4),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_widget ad183x_dac_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_OUTPUT("DAC1OUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("DAC2OUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("DAC3OUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("DAC4OUT"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route ad183x_dac_routes[] = {
|
|
|
|
{ "DAC1OUT", NULL, "DAC" },
|
|
|
|
{ "DAC2OUT", NULL, "DAC" },
|
|
|
|
{ "DAC3OUT", NULL, "DAC" },
|
|
|
|
{ "DAC4OUT", NULL, "DAC" },
|
|
|
|
};
|
2009-08-13 11:59:32 +08:00
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_kcontrol_new ad183x_adc_controls[] = {
|
2011-06-06 19:38:36 +08:00
|
|
|
AD1836_ADC_SWITCH(1),
|
|
|
|
AD1836_ADC_SWITCH(2),
|
2011-06-06 19:38:38 +08:00
|
|
|
AD1836_ADC_SWITCH(3),
|
|
|
|
};
|
2009-08-13 11:59:32 +08:00
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_soc_dapm_widget ad183x_adc_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_INPUT("ADC1IN"),
|
|
|
|
SND_SOC_DAPM_INPUT("ADC2IN"),
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_soc_dapm_route ad183x_adc_routes[] = {
|
|
|
|
{ "ADC", NULL, "ADC1IN" },
|
|
|
|
{ "ADC", NULL, "ADC2IN" },
|
|
|
|
};
|
2009-08-13 11:59:32 +08:00
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_kcontrol_new ad183x_controls[] = {
|
2009-08-13 11:59:32 +08:00
|
|
|
/* ADC high-pass filter */
|
|
|
|
SOC_SINGLE("ADC High Pass Filter Switch", AD1836_ADC_CTRL1,
|
|
|
|
AD1836_ADC_HIGHPASS_FILTER, 1, 0),
|
|
|
|
|
|
|
|
/* DAC de-emphasis */
|
|
|
|
SOC_ENUM("Playback Deemphasis", ad1836_deemp_enum),
|
|
|
|
};
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_soc_dapm_widget ad183x_dapm_widgets[] = {
|
2009-08-13 11:59:32 +08:00
|
|
|
SND_SOC_DAPM_DAC("DAC", "Playback", AD1836_DAC_CTRL1,
|
|
|
|
AD1836_DAC_POWERDOWN, 1),
|
|
|
|
SND_SOC_DAPM_ADC("ADC", "Capture", SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_SUPPLY("ADC_PWR", AD1836_ADC_CTRL1,
|
|
|
|
AD1836_ADC_POWERDOWN, 1, NULL, 0),
|
|
|
|
};
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct snd_soc_dapm_route ad183x_dapm_routes[] = {
|
2009-08-13 11:59:32 +08:00
|
|
|
{ "DAC", NULL, "ADC_PWR" },
|
|
|
|
{ "ADC", NULL, "ADC_PWR" },
|
|
|
|
};
|
|
|
|
|
2011-06-06 19:38:40 +08:00
|
|
|
static const DECLARE_TLV_DB_SCALE(ad1836_in_tlv, 0, 300, 0);
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new ad1836_controls[] = {
|
2011-06-07 13:02:59 +08:00
|
|
|
SOC_DOUBLE_TLV("ADC2 Capture Volume", AD1836_ADC_CTRL1, 3, 0, 4, 0,
|
2011-06-06 19:38:40 +08:00
|
|
|
ad1836_in_tlv),
|
|
|
|
};
|
|
|
|
|
2009-08-13 11:59:32 +08:00
|
|
|
/*
|
|
|
|
* DAI ops entries
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int ad1836_set_dai_fmt(struct snd_soc_dai *codec_dai,
|
|
|
|
unsigned int fmt)
|
|
|
|
{
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
|
|
|
|
/* at present, we support adc aux mode to interface with
|
|
|
|
* blackfin sport tdm mode
|
|
|
|
*/
|
|
|
|
case SND_SOC_DAIFMT_DSP_A:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
|
|
|
|
case SND_SOC_DAIFMT_IB_IF:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
|
|
|
|
/* ALCLK,ABCLK are both output, AD1836 can only be master */
|
|
|
|
case SND_SOC_DAIFMT_CBM_CFM:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad1836_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2012-09-13 18:04:51 +08:00
|
|
|
struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(dai->codec);
|
2009-08-13 11:59:32 +08:00
|
|
|
int word_len = 0;
|
|
|
|
|
|
|
|
/* bit size */
|
2014-01-09 02:37:22 +08:00
|
|
|
switch (params_width(params)) {
|
|
|
|
case 16:
|
2011-06-06 19:38:35 +08:00
|
|
|
word_len = AD1836_WORD_LEN_16;
|
2009-08-13 11:59:32 +08:00
|
|
|
break;
|
2014-01-09 02:37:22 +08:00
|
|
|
case 20:
|
2011-06-06 19:38:35 +08:00
|
|
|
word_len = AD1836_WORD_LEN_20;
|
2009-08-13 11:59:32 +08:00
|
|
|
break;
|
2014-01-09 02:37:22 +08:00
|
|
|
case 24:
|
|
|
|
case 32:
|
2011-06-06 19:38:35 +08:00
|
|
|
word_len = AD1836_WORD_LEN_24;
|
2009-08-13 11:59:32 +08:00
|
|
|
break;
|
2013-12-23 20:41:39 +08:00
|
|
|
default:
|
|
|
|
return -EINVAL;
|
2009-08-13 11:59:32 +08:00
|
|
|
}
|
|
|
|
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_update_bits(ad1836->regmap, AD1836_DAC_CTRL1,
|
|
|
|
AD1836_DAC_WORD_LEN_MASK,
|
2011-06-06 19:38:35 +08:00
|
|
|
word_len << AD1836_DAC_WORD_LEN_OFFSET);
|
2009-08-13 11:59:32 +08:00
|
|
|
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
|
|
|
|
AD1836_ADC_WORD_LEN_MASK,
|
2011-06-06 19:38:35 +08:00
|
|
|
word_len << AD1836_ADC_WORD_OFFSET);
|
2009-08-13 11:59:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-11-23 18:40:40 +08:00
|
|
|
static const struct snd_soc_dai_ops ad1836_dai_ops = {
|
2009-08-13 11:59:32 +08:00
|
|
|
.hw_params = ad1836_hw_params,
|
|
|
|
.set_fmt = ad1836_set_dai_fmt,
|
|
|
|
};
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
#define AD183X_DAI(_name, num_dacs, num_adcs) \
|
|
|
|
{ \
|
|
|
|
.name = _name "-hifi", \
|
|
|
|
.playback = { \
|
|
|
|
.stream_name = "Playback", \
|
|
|
|
.channels_min = 2, \
|
|
|
|
.channels_max = (num_dacs) * 2, \
|
|
|
|
.rates = SNDRV_PCM_RATE_48000, \
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \
|
|
|
|
}, \
|
|
|
|
.capture = { \
|
|
|
|
.stream_name = "Capture", \
|
|
|
|
.channels_min = 2, \
|
|
|
|
.channels_max = (num_adcs) * 2, \
|
|
|
|
.rates = SNDRV_PCM_RATE_48000, \
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S16_LE | \
|
|
|
|
SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S24_LE, \
|
|
|
|
}, \
|
|
|
|
.ops = &ad1836_dai_ops, \
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_dai_driver ad183x_dais[] = {
|
|
|
|
[AD1835] = AD183X_DAI("ad1835", 4, 1),
|
|
|
|
[AD1836] = AD183X_DAI("ad1836", 3, 2),
|
|
|
|
[AD1838] = AD183X_DAI("ad1838", 3, 1),
|
2009-08-13 11:59:32 +08:00
|
|
|
};
|
|
|
|
|
2011-06-16 03:29:22 +08:00
|
|
|
#ifdef CONFIG_PM
|
2011-12-02 17:18:28 +08:00
|
|
|
static int ad1836_suspend(struct snd_soc_codec *codec)
|
2011-06-16 03:29:22 +08:00
|
|
|
{
|
2012-09-13 18:04:51 +08:00
|
|
|
struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
|
2011-06-16 03:29:22 +08:00
|
|
|
/* reset clock control mode */
|
2012-09-13 18:04:51 +08:00
|
|
|
return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
|
2011-06-16 03:29:22 +08:00
|
|
|
AD1836_ADC_SERFMT_MASK, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ad1836_resume(struct snd_soc_codec *codec)
|
|
|
|
{
|
2012-09-13 18:04:51 +08:00
|
|
|
struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
|
2011-06-16 03:29:22 +08:00
|
|
|
/* restore clock control mode */
|
2012-09-13 18:04:51 +08:00
|
|
|
return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
|
2011-06-16 03:29:22 +08:00
|
|
|
AD1836_ADC_SERFMT_MASK, AD1836_ADC_AUX);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define ad1836_suspend NULL
|
|
|
|
#define ad1836_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int ad1836_probe(struct snd_soc_codec *codec)
|
2009-08-13 11:59:32 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
|
2010-11-05 21:53:46 +08:00
|
|
|
struct snd_soc_dapm_context *dapm = &codec->dapm;
|
2011-06-06 19:38:38 +08:00
|
|
|
int num_dacs, num_adcs;
|
2010-03-18 04:15:21 +08:00
|
|
|
int ret = 0;
|
2011-06-06 19:38:38 +08:00
|
|
|
int i;
|
|
|
|
|
|
|
|
num_dacs = ad183x_dais[ad1836->type].playback.channels_max / 2;
|
|
|
|
num_adcs = ad183x_dais[ad1836->type].capture.channels_max / 2;
|
2009-08-13 11:59:32 +08:00
|
|
|
|
|
|
|
/* default setting for ad1836 */
|
|
|
|
/* de-emphasis: 48kHz, power-on dac */
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_DAC_CTRL1, 0x300);
|
2009-08-13 11:59:32 +08:00
|
|
|
/* unmute dac channels */
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_DAC_CTRL2, 0x0);
|
2009-08-13 11:59:32 +08:00
|
|
|
/* high-pass filter enable, power-on adc */
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_ADC_CTRL1, 0x100);
|
2009-08-13 11:59:32 +08:00
|
|
|
/* unmute adc channles, adc aux mode */
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_ADC_CTRL2, 0x180);
|
2009-08-13 11:59:32 +08:00
|
|
|
/* volume */
|
2011-06-06 19:38:38 +08:00
|
|
|
for (i = 1; i <= num_dacs; ++i) {
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_DAC_L_VOL(i), 0x3FF);
|
|
|
|
regmap_write(ad1836->regmap, AD1836_DAC_R_VOL(i), 0x3FF);
|
2011-06-06 19:38:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ad1836->type == AD1836) {
|
|
|
|
/* left/right diff:PGA/MUX */
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x3A);
|
2012-02-04 01:43:09 +08:00
|
|
|
ret = snd_soc_add_codec_controls(codec, ad1836_controls,
|
2011-06-06 19:38:40 +08:00
|
|
|
ARRAY_SIZE(ad1836_controls));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-06-06 19:38:38 +08:00
|
|
|
} else {
|
2012-09-13 18:04:51 +08:00
|
|
|
regmap_write(ad1836->regmap, AD1836_ADC_CTRL3, 0x00);
|
2011-06-06 19:38:38 +08:00
|
|
|
}
|
|
|
|
|
2012-02-04 01:43:09 +08:00
|
|
|
ret = snd_soc_add_codec_controls(codec, ad183x_dac_controls, num_dacs * 2);
|
2011-06-06 19:38:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2012-02-04 01:43:09 +08:00
|
|
|
ret = snd_soc_add_codec_controls(codec, ad183x_adc_controls, num_adcs);
|
2011-06-06 19:38:38 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_new_controls(dapm, ad183x_dac_dapm_widgets, num_dacs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_new_controls(dapm, ad183x_adc_dapm_widgets, num_adcs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_add_routes(dapm, ad183x_dac_routes, num_dacs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
ret = snd_soc_dapm_add_routes(dapm, ad183x_adc_routes, num_adcs);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-08-13 11:59:32 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* power down chip */
|
2010-03-18 04:15:21 +08:00
|
|
|
static int ad1836_remove(struct snd_soc_codec *codec)
|
2009-08-13 11:59:32 +08:00
|
|
|
{
|
2012-09-13 18:04:51 +08:00
|
|
|
struct ad1836_priv *ad1836 = snd_soc_codec_get_drvdata(codec);
|
2010-03-18 04:15:21 +08:00
|
|
|
/* reset clock control mode */
|
2012-09-13 18:04:51 +08:00
|
|
|
return regmap_update_bits(ad1836->regmap, AD1836_ADC_CTRL2,
|
2011-06-06 19:38:37 +08:00
|
|
|
AD1836_ADC_SERFMT_MASK, 0);
|
2009-08-13 11:59:32 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_codec_driver soc_codec_dev_ad1836 = {
|
2011-06-16 03:29:20 +08:00
|
|
|
.probe = ad1836_probe,
|
|
|
|
.remove = ad1836_remove,
|
2011-06-16 03:29:22 +08:00
|
|
|
.suspend = ad1836_suspend,
|
|
|
|
.resume = ad1836_resume,
|
2011-06-06 19:38:38 +08:00
|
|
|
|
|
|
|
.controls = ad183x_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(ad183x_controls),
|
|
|
|
.dapm_widgets = ad183x_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(ad183x_dapm_widgets),
|
|
|
|
.dapm_routes = ad183x_dapm_routes,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(ad183x_dapm_routes),
|
2010-03-18 04:15:21 +08:00
|
|
|
};
|
|
|
|
|
2012-09-13 18:04:51 +08:00
|
|
|
static const struct reg_default ad1836_reg_defaults[] = {
|
|
|
|
{ AD1836_DAC_CTRL1, 0x0000 },
|
|
|
|
{ AD1836_DAC_CTRL2, 0x0000 },
|
|
|
|
{ AD1836_DAC_L_VOL(0), 0x0000 },
|
|
|
|
{ AD1836_DAC_R_VOL(0), 0x0000 },
|
|
|
|
{ AD1836_DAC_L_VOL(1), 0x0000 },
|
|
|
|
{ AD1836_DAC_R_VOL(1), 0x0000 },
|
|
|
|
{ AD1836_DAC_L_VOL(2), 0x0000 },
|
|
|
|
{ AD1836_DAC_R_VOL(2), 0x0000 },
|
|
|
|
{ AD1836_DAC_L_VOL(3), 0x0000 },
|
|
|
|
{ AD1836_DAC_R_VOL(3), 0x0000 },
|
|
|
|
{ AD1836_ADC_CTRL1, 0x0000 },
|
|
|
|
{ AD1836_ADC_CTRL2, 0x0000 },
|
|
|
|
{ AD1836_ADC_CTRL3, 0x0000 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config ad1836_regmap_config = {
|
|
|
|
.val_bits = 12,
|
|
|
|
.reg_bits = 4,
|
|
|
|
.read_flag_mask = 0x08,
|
|
|
|
|
|
|
|
.max_register = AD1836_ADC_CTRL3,
|
|
|
|
.reg_defaults = ad1836_reg_defaults,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(ad1836_reg_defaults),
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
};
|
|
|
|
|
2012-12-07 22:26:37 +08:00
|
|
|
static int ad1836_spi_probe(struct spi_device *spi)
|
2010-03-18 04:15:21 +08:00
|
|
|
{
|
|
|
|
struct ad1836_priv *ad1836;
|
|
|
|
int ret;
|
|
|
|
|
2011-12-26 20:50:02 +08:00
|
|
|
ad1836 = devm_kzalloc(&spi->dev, sizeof(struct ad1836_priv),
|
|
|
|
GFP_KERNEL);
|
2010-03-18 04:15:21 +08:00
|
|
|
if (ad1836 == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-09-13 18:04:51 +08:00
|
|
|
ad1836->regmap = devm_regmap_init_spi(spi, &ad1836_regmap_config);
|
|
|
|
if (IS_ERR(ad1836->regmap))
|
|
|
|
return PTR_ERR(ad1836->regmap);
|
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
ad1836->type = spi_get_device_id(spi)->driver_data;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
spi_set_drvdata(spi, ad1836);
|
|
|
|
|
|
|
|
ret = snd_soc_register_codec(&spi->dev,
|
2011-06-06 19:38:38 +08:00
|
|
|
&soc_codec_dev_ad1836, &ad183x_dais[ad1836->type], 1);
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:26:37 +08:00
|
|
|
static int ad1836_spi_remove(struct spi_device *spi)
|
2010-03-18 04:15:21 +08:00
|
|
|
{
|
|
|
|
snd_soc_unregister_codec(&spi->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
2011-12-26 20:50:02 +08:00
|
|
|
|
2011-06-06 19:38:38 +08:00
|
|
|
static const struct spi_device_id ad1836_ids[] = {
|
|
|
|
{ "ad1835", AD1835 },
|
|
|
|
{ "ad1836", AD1836 },
|
|
|
|
{ "ad1837", AD1835 },
|
|
|
|
{ "ad1838", AD1838 },
|
|
|
|
{ "ad1839", AD1838 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(spi, ad1836_ids);
|
2010-03-18 04:15:21 +08:00
|
|
|
|
|
|
|
static struct spi_driver ad1836_spi_driver = {
|
|
|
|
.driver = {
|
2011-06-16 03:29:21 +08:00
|
|
|
.name = "ad1836",
|
2010-03-18 04:15:21 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = ad1836_spi_probe,
|
2012-12-07 22:26:37 +08:00
|
|
|
.remove = ad1836_spi_remove,
|
2011-06-06 19:38:38 +08:00
|
|
|
.id_table = ad1836_ids,
|
2009-08-13 11:59:32 +08:00
|
|
|
};
|
|
|
|
|
2012-08-27 19:30:28 +08:00
|
|
|
module_spi_driver(ad1836_spi_driver);
|
2009-08-13 11:59:32 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC ad1836 driver");
|
|
|
|
MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|