2009-01-16 18:04:18 +07:00
|
|
|
/*
|
|
|
|
* wm9705.c -- ALSA Soc WM9705 codec support
|
|
|
|
*
|
|
|
|
* Copyright 2008 Ian Molton <spyro@f2s.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; Version 2 of the License only.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2017-09-14 02:37:22 +07:00
|
|
|
#include <linux/mfd/wm97xx.h>
|
2009-01-16 18:04:18 +07:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/device.h>
|
2016-10-21 15:27:07 +07:00
|
|
|
#include <linux/regmap.h>
|
2009-01-16 18:04:18 +07:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/ac97_codec.h>
|
2017-09-14 02:37:22 +07:00
|
|
|
#include <sound/ac97/codec.h>
|
|
|
|
#include <sound/ac97/compat.h>
|
2009-01-16 18:04:18 +07:00
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
2015-07-22 02:53:04 +07:00
|
|
|
#define WM9705_VENDOR_ID 0x574d4c05
|
|
|
|
#define WM9705_VENDOR_ID_MASK 0xffffffff
|
|
|
|
|
2017-09-14 02:37:21 +07:00
|
|
|
struct wm9705_priv {
|
|
|
|
struct snd_ac97 *ac97;
|
2017-09-14 02:37:22 +07:00
|
|
|
struct wm97xx_platform_data *mfd_pdata;
|
2017-09-14 02:37:21 +07:00
|
|
|
};
|
|
|
|
|
2016-10-21 15:27:07 +07:00
|
|
|
static const struct reg_default wm9705_reg_defaults[] = {
|
|
|
|
{ 0x02, 0x8000 },
|
|
|
|
{ 0x04, 0x8000 },
|
|
|
|
{ 0x06, 0x8000 },
|
|
|
|
{ 0x0a, 0x8000 },
|
|
|
|
{ 0x0c, 0x8008 },
|
|
|
|
{ 0x0e, 0x8008 },
|
|
|
|
{ 0x10, 0x8808 },
|
|
|
|
{ 0x12, 0x8808 },
|
|
|
|
{ 0x14, 0x8808 },
|
|
|
|
{ 0x16, 0x8808 },
|
|
|
|
{ 0x18, 0x8808 },
|
|
|
|
{ 0x1a, 0x0000 },
|
|
|
|
{ 0x1c, 0x8000 },
|
|
|
|
{ 0x20, 0x0000 },
|
|
|
|
{ 0x22, 0x0000 },
|
|
|
|
{ 0x26, 0x000f },
|
|
|
|
{ 0x28, 0x0605 },
|
|
|
|
{ 0x2a, 0x0000 },
|
|
|
|
{ 0x2c, 0xbb80 },
|
|
|
|
{ 0x32, 0xbb80 },
|
|
|
|
{ 0x34, 0x2000 },
|
|
|
|
{ 0x5a, 0x0000 },
|
|
|
|
{ 0x5c, 0x0000 },
|
|
|
|
{ 0x72, 0x0808 },
|
|
|
|
{ 0x74, 0x0000 },
|
|
|
|
{ 0x76, 0x0006 },
|
|
|
|
{ 0x78, 0x0000 },
|
|
|
|
{ 0x7a, 0x0000 },
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct regmap_config wm9705_regmap_config = {
|
|
|
|
.reg_bits = 16,
|
|
|
|
.reg_stride = 2,
|
|
|
|
.val_bits = 16,
|
|
|
|
.max_register = 0x7e,
|
|
|
|
.cache_type = REGCACHE_RBTREE,
|
|
|
|
|
|
|
|
.volatile_reg = regmap_ac97_default_volatile,
|
|
|
|
|
|
|
|
.reg_defaults = wm9705_reg_defaults,
|
|
|
|
.num_reg_defaults = ARRAY_SIZE(wm9705_reg_defaults),
|
2009-01-16 18:04:18 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = {
|
|
|
|
SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
|
|
|
|
SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
|
|
|
|
SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
|
|
|
|
SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
|
|
|
|
SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
|
|
|
|
SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
|
|
|
|
SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
|
|
|
|
SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
|
|
|
|
SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1),
|
|
|
|
SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1),
|
|
|
|
SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1),
|
|
|
|
SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1),
|
|
|
|
SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1),
|
|
|
|
SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0),
|
2009-01-20 00:23:11 +07:00
|
|
|
SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0),
|
|
|
|
SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1),
|
2009-01-16 18:04:18 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *wm9705_mic[] = {"Mic 1", "Mic 2"};
|
|
|
|
static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC",
|
|
|
|
"Line", "Stereo Mix", "Mono Mix", "Phone"};
|
|
|
|
|
2014-02-18 16:47:00 +07:00
|
|
|
static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic,
|
|
|
|
AC97_GENERAL_PURPOSE, 8, wm9705_mic);
|
|
|
|
static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l,
|
|
|
|
AC97_REC_SEL, 8, wm9705_rec_sel);
|
|
|
|
static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r,
|
|
|
|
AC97_REC_SEL, 0, wm9705_rec_sel);
|
2009-01-16 18:04:18 +07:00
|
|
|
|
|
|
|
/* Headphone Mixer */
|
|
|
|
static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = {
|
|
|
|
SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
|
|
|
|
SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1),
|
|
|
|
SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1),
|
|
|
|
SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1),
|
|
|
|
SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Mic source */
|
|
|
|
static const struct snd_kcontrol_new wm9705_mic_src_controls =
|
|
|
|
SOC_DAPM_ENUM("Route", wm9705_enum_mic);
|
|
|
|
|
|
|
|
/* Capture source */
|
|
|
|
static const struct snd_kcontrol_new wm9705_capture_selectl_controls =
|
|
|
|
SOC_DAPM_ENUM("Route", wm9705_enum_rec_l);
|
|
|
|
static const struct snd_kcontrol_new wm9705_capture_selectr_controls =
|
|
|
|
SOC_DAPM_ENUM("Route", wm9705_enum_rec_r);
|
|
|
|
|
|
|
|
/* DAPM widgets */
|
|
|
|
static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = {
|
|
|
|
SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0,
|
|
|
|
&wm9705_mic_src_controls),
|
|
|
|
SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
|
|
|
|
&wm9705_capture_selectl_controls),
|
|
|
|
SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
|
|
|
|
&wm9705_capture_selectr_controls),
|
|
|
|
SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
|
|
|
|
SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
|
|
|
|
SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0,
|
|
|
|
&wm9705_hp_mixer_controls[0],
|
|
|
|
ARRAY_SIZE(wm9705_hp_mixer_controls)),
|
|
|
|
SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
|
|
|
|
SND_SOC_DAPM_OUTPUT("HPOUTL"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("HPOUTR"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("LOUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("ROUT"),
|
|
|
|
SND_SOC_DAPM_OUTPUT("MONOOUT"),
|
|
|
|
SND_SOC_DAPM_INPUT("PHONE"),
|
|
|
|
SND_SOC_DAPM_INPUT("LINEINL"),
|
|
|
|
SND_SOC_DAPM_INPUT("LINEINR"),
|
|
|
|
SND_SOC_DAPM_INPUT("CDINL"),
|
|
|
|
SND_SOC_DAPM_INPUT("CDINR"),
|
|
|
|
SND_SOC_DAPM_INPUT("PCBEEP"),
|
|
|
|
SND_SOC_DAPM_INPUT("MIC1"),
|
|
|
|
SND_SOC_DAPM_INPUT("MIC2"),
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Audio map
|
|
|
|
* WM9705 has no switches to disable the route from the inputs to the HP mixer
|
|
|
|
* so in order to prevent active inputs from forcing the audio outputs to be
|
|
|
|
* constantly enabled, we use the mutes on those inputs to simulate such
|
|
|
|
* controls.
|
|
|
|
*/
|
2011-03-30 20:53:13 +07:00
|
|
|
static const struct snd_soc_dapm_route wm9705_audio_map[] = {
|
2009-01-16 18:04:18 +07:00
|
|
|
/* HP mixer */
|
|
|
|
{"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"},
|
|
|
|
{"HP Mixer", "CD Playback Switch", "CD PGA"},
|
|
|
|
{"HP Mixer", "Mic Playback Switch", "Mic PGA"},
|
|
|
|
{"HP Mixer", "Phone Playback Switch", "Phone PGA"},
|
|
|
|
{"HP Mixer", "Line Playback Switch", "Line PGA"},
|
|
|
|
{"HP Mixer", NULL, "Left DAC"},
|
|
|
|
{"HP Mixer", NULL, "Right DAC"},
|
|
|
|
|
|
|
|
/* mono mixer */
|
|
|
|
{"Mono Mixer", NULL, "HP Mixer"},
|
|
|
|
|
|
|
|
/* outputs */
|
|
|
|
{"Headphone PGA", NULL, "HP Mixer"},
|
|
|
|
{"HPOUTL", NULL, "Headphone PGA"},
|
|
|
|
{"HPOUTR", NULL, "Headphone PGA"},
|
|
|
|
{"Line out PGA", NULL, "HP Mixer"},
|
|
|
|
{"LOUT", NULL, "Line out PGA"},
|
|
|
|
{"ROUT", NULL, "Line out PGA"},
|
|
|
|
{"Mono PGA", NULL, "Mono Mixer"},
|
|
|
|
{"MONOOUT", NULL, "Mono PGA"},
|
|
|
|
|
|
|
|
/* inputs */
|
|
|
|
{"CD PGA", NULL, "CDINL"},
|
|
|
|
{"CD PGA", NULL, "CDINR"},
|
|
|
|
{"Line PGA", NULL, "LINEINL"},
|
|
|
|
{"Line PGA", NULL, "LINEINR"},
|
|
|
|
{"Phone PGA", NULL, "PHONE"},
|
|
|
|
{"Mic Source", "Mic 1", "MIC1"},
|
|
|
|
{"Mic Source", "Mic 2", "MIC2"},
|
|
|
|
{"Mic PGA", NULL, "Mic Source"},
|
|
|
|
{"PCBEEP PGA", NULL, "PCBEEP"},
|
|
|
|
|
|
|
|
/* Left capture selector */
|
|
|
|
{"Left Capture Source", "Mic", "Mic Source"},
|
|
|
|
{"Left Capture Source", "CD", "CDINL"},
|
|
|
|
{"Left Capture Source", "Line", "LINEINL"},
|
|
|
|
{"Left Capture Source", "Stereo Mix", "HP Mixer"},
|
|
|
|
{"Left Capture Source", "Mono Mix", "HP Mixer"},
|
|
|
|
{"Left Capture Source", "Phone", "PHONE"},
|
|
|
|
|
|
|
|
/* Right capture source */
|
|
|
|
{"Right Capture Source", "Mic", "Mic Source"},
|
|
|
|
{"Right Capture Source", "CD", "CDINR"},
|
|
|
|
{"Right Capture Source", "Line", "LINEINR"},
|
|
|
|
{"Right Capture Source", "Stereo Mix", "HP Mixer"},
|
|
|
|
{"Right Capture Source", "Mono Mix", "HP Mixer"},
|
|
|
|
{"Right Capture Source", "Phone", "PHONE"},
|
|
|
|
|
|
|
|
{"ADC PGA", NULL, "Left Capture Source"},
|
|
|
|
{"ADC PGA", NULL, "Right Capture Source"},
|
|
|
|
|
|
|
|
/* ADC's */
|
|
|
|
{"Left ADC", NULL, "ADC PGA"},
|
|
|
|
{"Right ADC", NULL, "ADC PGA"},
|
|
|
|
};
|
|
|
|
|
|
|
|
static int ac97_prepare(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_soc_dai *dai)
|
|
|
|
{
|
2012-04-04 21:58:16 +07:00
|
|
|
struct snd_soc_codec *codec = dai->codec;
|
2009-01-16 18:04:18 +07:00
|
|
|
int reg;
|
|
|
|
|
2016-10-21 15:27:08 +07:00
|
|
|
snd_soc_update_bits(codec, AC97_EXTENDED_STATUS, 0x1, 0x1);
|
2009-01-16 18:04:18 +07:00
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
reg = AC97_PCM_FRONT_DAC_RATE;
|
|
|
|
else
|
|
|
|
reg = AC97_PCM_LR_ADC_RATE;
|
|
|
|
|
2016-10-21 15:27:08 +07:00
|
|
|
return snd_soc_write(codec, reg, substream->runtime->rate);
|
2009-01-16 18:04:18 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
#define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \
|
|
|
|
SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
|
|
|
|
SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
|
|
|
|
SNDRV_PCM_RATE_48000)
|
|
|
|
|
2011-11-23 17:40:40 +07:00
|
|
|
static const struct snd_soc_dai_ops wm9705_dai_ops = {
|
2009-03-03 08:41:00 +07:00
|
|
|
.prepare = ac97_prepare,
|
|
|
|
};
|
|
|
|
|
2010-03-18 03:15:21 +07:00
|
|
|
static struct snd_soc_dai_driver wm9705_dai[] = {
|
2009-01-16 18:04:18 +07:00
|
|
|
{
|
2010-03-18 03:15:21 +07:00
|
|
|
.name = "wm9705-hifi",
|
2009-01-16 18:04:18 +07:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "HiFi Playback",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = WM9705_AC97_RATES,
|
2009-05-02 18:24:55 +07:00
|
|
|
.formats = SND_SOC_STD_AC97_FMTS,
|
2009-01-16 18:04:18 +07:00
|
|
|
},
|
|
|
|
.capture = {
|
|
|
|
.stream_name = "HiFi Capture",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.rates = WM9705_AC97_RATES,
|
2009-05-02 18:24:55 +07:00
|
|
|
.formats = SND_SOC_STD_AC97_FMTS,
|
2009-01-16 18:04:18 +07:00
|
|
|
},
|
2009-03-03 08:41:00 +07:00
|
|
|
.ops = &wm9705_dai_ops,
|
2009-01-16 18:04:18 +07:00
|
|
|
},
|
|
|
|
{
|
2010-03-18 03:15:21 +07:00
|
|
|
.name = "wm9705-aux",
|
2009-01-16 18:04:18 +07:00
|
|
|
.playback = {
|
|
|
|
.stream_name = "Aux Playback",
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 1,
|
|
|
|
.rates = WM9705_AC97_RATES,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-04-02 21:49:41 +07:00
|
|
|
#ifdef CONFIG_PM
|
2011-12-02 16:18:28 +07:00
|
|
|
static int wm9705_soc_suspend(struct snd_soc_codec *codec)
|
2009-04-02 21:49:41 +07:00
|
|
|
{
|
2016-10-21 15:27:07 +07:00
|
|
|
regcache_cache_bypass(codec->component.regmap, true);
|
2016-10-21 15:27:08 +07:00
|
|
|
snd_soc_write(codec, AC97_POWERDOWN, 0xffff);
|
2016-10-21 15:27:07 +07:00
|
|
|
regcache_cache_bypass(codec->component.regmap, false);
|
2009-04-02 21:49:41 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-03-18 03:15:21 +07:00
|
|
|
static int wm9705_soc_resume(struct snd_soc_codec *codec)
|
2009-04-02 21:49:41 +07:00
|
|
|
{
|
2017-09-14 02:37:21 +07:00
|
|
|
struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
|
2016-10-21 15:27:07 +07:00
|
|
|
int ret;
|
2009-04-02 21:49:41 +07:00
|
|
|
|
2017-09-14 02:37:21 +07:00
|
|
|
ret = snd_ac97_reset(wm9705->ac97, true, WM9705_VENDOR_ID,
|
2015-07-22 02:53:04 +07:00
|
|
|
WM9705_VENDOR_ID_MASK);
|
2014-10-31 03:01:03 +07:00
|
|
|
if (ret < 0)
|
2009-04-02 21:49:41 +07:00
|
|
|
return ret;
|
|
|
|
|
2016-10-21 15:27:07 +07:00
|
|
|
regcache_sync(codec->component.regmap);
|
2009-04-02 21:49:41 +07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define wm9705_soc_suspend NULL
|
|
|
|
#define wm9705_soc_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2010-03-18 03:15:21 +07:00
|
|
|
static int wm9705_soc_probe(struct snd_soc_codec *codec)
|
2009-01-16 18:04:18 +07:00
|
|
|
{
|
2017-09-14 02:37:21 +07:00
|
|
|
struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
|
2016-10-21 15:27:07 +07:00
|
|
|
struct regmap *regmap;
|
|
|
|
int ret;
|
2009-01-16 18:04:18 +07:00
|
|
|
|
2017-09-14 02:37:22 +07:00
|
|
|
if (wm9705->mfd_pdata) {
|
|
|
|
wm9705->ac97 = wm9705->mfd_pdata->ac97;
|
|
|
|
regmap = wm9705->mfd_pdata->regmap;
|
|
|
|
} else {
|
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
|
|
|
wm9705->ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID,
|
|
|
|
WM9705_VENDOR_ID_MASK);
|
|
|
|
if (IS_ERR(wm9705->ac97)) {
|
|
|
|
dev_err(codec->dev, "Failed to register AC97 codec\n");
|
|
|
|
return PTR_ERR(wm9705->ac97);
|
|
|
|
}
|
|
|
|
|
|
|
|
regmap = regmap_init_ac97(wm9705->ac97, &wm9705_regmap_config);
|
|
|
|
if (IS_ERR(regmap)) {
|
|
|
|
ret = PTR_ERR(regmap);
|
|
|
|
goto err_free_ac97_codec;
|
|
|
|
}
|
|
|
|
#endif
|
2016-10-21 15:27:07 +07:00
|
|
|
}
|
|
|
|
|
2017-09-14 02:37:21 +07:00
|
|
|
snd_soc_codec_set_drvdata(codec, wm9705->ac97);
|
2016-10-21 15:27:07 +07:00
|
|
|
snd_soc_codec_init_regmap(codec, regmap);
|
2009-01-16 18:04:18 +07:00
|
|
|
|
|
|
|
return 0;
|
2016-10-21 15:27:07 +07:00
|
|
|
err_free_ac97_codec:
|
2017-09-14 02:37:21 +07:00
|
|
|
snd_soc_free_ac97_codec(wm9705->ac97);
|
2016-10-21 15:27:07 +07:00
|
|
|
return ret;
|
2009-01-16 18:04:18 +07:00
|
|
|
}
|
|
|
|
|
2010-03-18 03:15:21 +07:00
|
|
|
static int wm9705_soc_remove(struct snd_soc_codec *codec)
|
2009-01-16 18:04:18 +07:00
|
|
|
{
|
2017-09-14 02:37:22 +07:00
|
|
|
#ifdef CONFIG_SND_SOC_AC97_BUS
|
2017-09-14 02:37:21 +07:00
|
|
|
struct wm9705_priv *wm9705 = snd_soc_codec_get_drvdata(codec);
|
2014-11-11 04:41:53 +07:00
|
|
|
|
2017-09-14 02:37:22 +07:00
|
|
|
if (!wm9705->mfd_pdata) {
|
|
|
|
snd_soc_codec_exit_regmap(codec);
|
|
|
|
snd_soc_free_ac97_codec(wm9705->ac97);
|
|
|
|
}
|
|
|
|
#endif
|
2009-01-16 18:04:18 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-01 04:52:27 +07:00
|
|
|
static const struct snd_soc_codec_driver soc_codec_dev_wm9705 = {
|
2009-01-16 18:04:18 +07:00
|
|
|
.probe = wm9705_soc_probe,
|
|
|
|
.remove = wm9705_soc_remove,
|
2009-04-02 21:49:41 +07:00
|
|
|
.suspend = wm9705_soc_suspend,
|
|
|
|
.resume = wm9705_soc_resume,
|
2014-10-31 03:01:04 +07:00
|
|
|
|
2016-08-08 16:35:34 +07:00
|
|
|
.component_driver = {
|
|
|
|
.controls = wm9705_snd_ac97_controls,
|
|
|
|
.num_controls = ARRAY_SIZE(wm9705_snd_ac97_controls),
|
|
|
|
.dapm_widgets = wm9705_dapm_widgets,
|
|
|
|
.num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets),
|
|
|
|
.dapm_routes = wm9705_audio_map,
|
|
|
|
.num_dapm_routes = ARRAY_SIZE(wm9705_audio_map),
|
|
|
|
},
|
2010-03-18 03:15:21 +07:00
|
|
|
};
|
|
|
|
|
2012-12-07 21:26:37 +07:00
|
|
|
static int wm9705_probe(struct platform_device *pdev)
|
2010-03-18 03:15:21 +07:00
|
|
|
{
|
2017-09-14 02:37:21 +07:00
|
|
|
struct wm9705_priv *wm9705;
|
|
|
|
|
|
|
|
wm9705 = devm_kzalloc(&pdev->dev, sizeof(*wm9705), GFP_KERNEL);
|
|
|
|
if (wm9705 == NULL)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-09-14 02:37:22 +07:00
|
|
|
wm9705->mfd_pdata = dev_get_platdata(&pdev->dev);
|
2017-09-14 02:37:21 +07:00
|
|
|
platform_set_drvdata(pdev, wm9705);
|
|
|
|
|
2010-03-18 03:15:21 +07:00
|
|
|
return snd_soc_register_codec(&pdev->dev,
|
|
|
|
&soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai));
|
|
|
|
}
|
|
|
|
|
2012-12-07 21:26:37 +07:00
|
|
|
static int wm9705_remove(struct platform_device *pdev)
|
2010-03-18 03:15:21 +07:00
|
|
|
{
|
|
|
|
snd_soc_unregister_codec(&pdev->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver wm9705_codec_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "wm9705-codec",
|
|
|
|
},
|
|
|
|
|
|
|
|
.probe = wm9705_probe,
|
2012-12-07 21:26:37 +07:00
|
|
|
.remove = wm9705_remove,
|
2009-01-16 18:04:18 +07:00
|
|
|
};
|
2010-03-18 03:15:21 +07:00
|
|
|
|
2011-11-24 05:52:08 +07:00
|
|
|
module_platform_driver(wm9705_codec_driver);
|
2009-01-16 18:04:18 +07:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("ASoC WM9705 driver");
|
|
|
|
MODULE_AUTHOR("Ian Molton");
|
|
|
|
MODULE_LICENSE("GPL v2");
|