xref: /openbmc/linux/sound/soc/codecs/wm9705.c (revision 28f89849)
12aceefefSIan Molton /*
22aceefefSIan Molton  * wm9705.c  --  ALSA Soc WM9705 codec support
32aceefefSIan Molton  *
42aceefefSIan Molton  * Copyright 2008 Ian Molton <spyro@f2s.com>
52aceefefSIan Molton  *
62aceefefSIan Molton  *  This program is free software; you can redistribute  it and/or modify it
72aceefefSIan Molton  *  under  the terms of  the GNU General  Public License as published by the
82aceefefSIan Molton  *  Free Software Foundation; Version 2 of the  License only.
92aceefefSIan Molton  *
102aceefefSIan Molton  */
112aceefefSIan Molton 
122aceefefSIan Molton #include <linux/init.h>
135a0e3ad6STejun Heo #include <linux/slab.h>
14aaafcfedSRobert Jarzmik #include <linux/mfd/wm97xx.h>
152aceefefSIan Molton #include <linux/module.h>
162aceefefSIan Molton #include <linux/kernel.h>
172aceefefSIan Molton #include <linux/device.h>
18206964e8SLars-Peter Clausen #include <linux/regmap.h>
192aceefefSIan Molton #include <sound/core.h>
202aceefefSIan Molton #include <sound/pcm.h>
212aceefefSIan Molton #include <sound/ac97_codec.h>
22aaafcfedSRobert Jarzmik #include <sound/ac97/codec.h>
23aaafcfedSRobert Jarzmik #include <sound/ac97/compat.h>
242aceefefSIan Molton #include <sound/initval.h>
252aceefefSIan Molton #include <sound/soc.h>
262aceefefSIan Molton 
276e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID 0x574d4c05
286e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID_MASK 0xffffffff
296e0b73a0SLars-Peter Clausen 
30c6e46e52SRobert Jarzmik struct wm9705_priv {
31c6e46e52SRobert Jarzmik 	struct snd_ac97 *ac97;
32aaafcfedSRobert Jarzmik 	struct wm97xx_platform_data *mfd_pdata;
33c6e46e52SRobert Jarzmik };
34c6e46e52SRobert Jarzmik 
35206964e8SLars-Peter Clausen static const struct reg_default wm9705_reg_defaults[] = {
36206964e8SLars-Peter Clausen 	{ 0x02, 0x8000 },
37206964e8SLars-Peter Clausen 	{ 0x04, 0x8000 },
38206964e8SLars-Peter Clausen 	{ 0x06, 0x8000 },
39206964e8SLars-Peter Clausen 	{ 0x0a, 0x8000 },
40206964e8SLars-Peter Clausen 	{ 0x0c, 0x8008 },
41206964e8SLars-Peter Clausen 	{ 0x0e, 0x8008 },
42206964e8SLars-Peter Clausen 	{ 0x10, 0x8808 },
43206964e8SLars-Peter Clausen 	{ 0x12, 0x8808 },
44206964e8SLars-Peter Clausen 	{ 0x14, 0x8808 },
45206964e8SLars-Peter Clausen 	{ 0x16, 0x8808 },
46206964e8SLars-Peter Clausen 	{ 0x18, 0x8808 },
47206964e8SLars-Peter Clausen 	{ 0x1a, 0x0000 },
48206964e8SLars-Peter Clausen 	{ 0x1c, 0x8000 },
49206964e8SLars-Peter Clausen 	{ 0x20, 0x0000 },
50206964e8SLars-Peter Clausen 	{ 0x22, 0x0000 },
51206964e8SLars-Peter Clausen 	{ 0x26, 0x000f },
52206964e8SLars-Peter Clausen 	{ 0x28, 0x0605 },
53206964e8SLars-Peter Clausen 	{ 0x2a, 0x0000 },
54206964e8SLars-Peter Clausen 	{ 0x2c, 0xbb80 },
55206964e8SLars-Peter Clausen 	{ 0x32, 0xbb80 },
56206964e8SLars-Peter Clausen 	{ 0x34, 0x2000 },
57206964e8SLars-Peter Clausen 	{ 0x5a, 0x0000 },
58206964e8SLars-Peter Clausen 	{ 0x5c, 0x0000 },
59206964e8SLars-Peter Clausen 	{ 0x72, 0x0808 },
60206964e8SLars-Peter Clausen 	{ 0x74, 0x0000 },
61206964e8SLars-Peter Clausen 	{ 0x76, 0x0006 },
62206964e8SLars-Peter Clausen 	{ 0x78, 0x0000 },
63206964e8SLars-Peter Clausen 	{ 0x7a, 0x0000 },
64206964e8SLars-Peter Clausen };
65206964e8SLars-Peter Clausen 
66206964e8SLars-Peter Clausen static const struct regmap_config wm9705_regmap_config = {
67206964e8SLars-Peter Clausen 	.reg_bits = 16,
68206964e8SLars-Peter Clausen 	.reg_stride = 2,
69206964e8SLars-Peter Clausen 	.val_bits = 16,
70206964e8SLars-Peter Clausen 	.max_register = 0x7e,
71206964e8SLars-Peter Clausen 	.cache_type = REGCACHE_RBTREE,
72206964e8SLars-Peter Clausen 
73206964e8SLars-Peter Clausen 	.volatile_reg = regmap_ac97_default_volatile,
74206964e8SLars-Peter Clausen 
75206964e8SLars-Peter Clausen 	.reg_defaults = wm9705_reg_defaults,
76206964e8SLars-Peter Clausen 	.num_reg_defaults = ARRAY_SIZE(wm9705_reg_defaults),
772aceefefSIan Molton };
782aceefefSIan Molton 
792aceefefSIan Molton static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = {
802aceefefSIan Molton 	SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
812aceefefSIan Molton 	SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
822aceefefSIan Molton 	SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
832aceefefSIan Molton 	SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
842aceefefSIan Molton 	SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
852aceefefSIan Molton 	SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
862aceefefSIan Molton 	SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
872aceefefSIan Molton 	SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
882aceefefSIan Molton 	SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1),
892aceefefSIan Molton 	SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1),
902aceefefSIan Molton 	SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1),
912aceefefSIan Molton 	SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1),
922aceefefSIan Molton 	SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1),
932aceefefSIan Molton 	SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0),
94927b0aeaSIan Molton 	SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0),
95927b0aeaSIan Molton 	SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1),
962aceefefSIan Molton };
972aceefefSIan Molton 
982aceefefSIan Molton static const char *wm9705_mic[] = {"Mic 1", "Mic 2"};
992aceefefSIan Molton static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC",
1002aceefefSIan Molton 	"Line", "Stereo Mix", "Mono Mix", "Phone"};
1012aceefefSIan Molton 
10209981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic,
10309981dcbSTakashi Iwai 			    AC97_GENERAL_PURPOSE, 8, wm9705_mic);
10409981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l,
10509981dcbSTakashi Iwai 			    AC97_REC_SEL, 8, wm9705_rec_sel);
10609981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r,
10709981dcbSTakashi Iwai 			    AC97_REC_SEL, 0, wm9705_rec_sel);
1082aceefefSIan Molton 
1092aceefefSIan Molton /* Headphone Mixer */
1102aceefefSIan Molton static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = {
1112aceefefSIan Molton 	SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
1122aceefefSIan Molton 	SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1),
1132aceefefSIan Molton 	SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1),
1142aceefefSIan Molton 	SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1),
1152aceefefSIan Molton 	SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1),
1162aceefefSIan Molton };
1172aceefefSIan Molton 
1182aceefefSIan Molton /* Mic source */
1192aceefefSIan Molton static const struct snd_kcontrol_new wm9705_mic_src_controls =
1202aceefefSIan Molton 	SOC_DAPM_ENUM("Route", wm9705_enum_mic);
1212aceefefSIan Molton 
1222aceefefSIan Molton /* Capture source */
1232aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectl_controls =
1242aceefefSIan Molton 	SOC_DAPM_ENUM("Route", wm9705_enum_rec_l);
1252aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectr_controls =
1262aceefefSIan Molton 	SOC_DAPM_ENUM("Route", wm9705_enum_rec_r);
1272aceefefSIan Molton 
1282aceefefSIan Molton /* DAPM widgets */
1292aceefefSIan Molton static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = {
1302aceefefSIan Molton 	SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0,
1312aceefefSIan Molton 		&wm9705_mic_src_controls),
1322aceefefSIan Molton 	SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
1332aceefefSIan Molton 		&wm9705_capture_selectl_controls),
1342aceefefSIan Molton 	SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
1352aceefefSIan Molton 		&wm9705_capture_selectr_controls),
1362aceefefSIan Molton 	SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
1372aceefefSIan Molton 		SND_SOC_NOPM, 0, 0),
1382aceefefSIan Molton 	SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
1392aceefefSIan Molton 		SND_SOC_NOPM, 0, 0),
1402aceefefSIan Molton 	SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0,
1412aceefefSIan Molton 		&wm9705_hp_mixer_controls[0],
1422aceefefSIan Molton 		ARRAY_SIZE(wm9705_hp_mixer_controls)),
1432aceefefSIan Molton 	SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
1442aceefefSIan Molton 	SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
1452aceefefSIan Molton 	SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
1462aceefefSIan Molton 	SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1472aceefefSIan Molton 	SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1482aceefefSIan Molton 	SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1492aceefefSIan Molton 	SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1502aceefefSIan Molton 	SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1512aceefefSIan Molton 	SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1522aceefefSIan Molton 	SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1532aceefefSIan Molton 	SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1542aceefefSIan Molton 	SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1552aceefefSIan Molton 	SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1562aceefefSIan Molton 	SND_SOC_DAPM_OUTPUT("HPOUTL"),
1572aceefefSIan Molton 	SND_SOC_DAPM_OUTPUT("HPOUTR"),
1582aceefefSIan Molton 	SND_SOC_DAPM_OUTPUT("LOUT"),
1592aceefefSIan Molton 	SND_SOC_DAPM_OUTPUT("ROUT"),
1602aceefefSIan Molton 	SND_SOC_DAPM_OUTPUT("MONOOUT"),
1612aceefefSIan Molton 	SND_SOC_DAPM_INPUT("PHONE"),
1622aceefefSIan Molton 	SND_SOC_DAPM_INPUT("LINEINL"),
1632aceefefSIan Molton 	SND_SOC_DAPM_INPUT("LINEINR"),
1642aceefefSIan Molton 	SND_SOC_DAPM_INPUT("CDINL"),
1652aceefefSIan Molton 	SND_SOC_DAPM_INPUT("CDINR"),
1662aceefefSIan Molton 	SND_SOC_DAPM_INPUT("PCBEEP"),
1672aceefefSIan Molton 	SND_SOC_DAPM_INPUT("MIC1"),
1682aceefefSIan Molton 	SND_SOC_DAPM_INPUT("MIC2"),
1692aceefefSIan Molton };
1702aceefefSIan Molton 
1712aceefefSIan Molton /* Audio map
1722aceefefSIan Molton  * WM9705 has no switches to disable the route from the inputs to the HP mixer
1732aceefefSIan Molton  * so in order to prevent active inputs from forcing the audio outputs to be
1742aceefefSIan Molton  * constantly enabled, we use the mutes on those inputs to simulate such
1752aceefefSIan Molton  * controls.
1762aceefefSIan Molton  */
17797a58d6eSLu Guanqun static const struct snd_soc_dapm_route wm9705_audio_map[] = {
1782aceefefSIan Molton 	/* HP mixer */
1792aceefefSIan Molton 	{"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"},
1802aceefefSIan Molton 	{"HP Mixer", "CD Playback Switch", "CD PGA"},
1812aceefefSIan Molton 	{"HP Mixer", "Mic Playback Switch", "Mic PGA"},
1822aceefefSIan Molton 	{"HP Mixer", "Phone Playback Switch", "Phone PGA"},
1832aceefefSIan Molton 	{"HP Mixer", "Line Playback Switch", "Line PGA"},
1842aceefefSIan Molton 	{"HP Mixer", NULL, "Left DAC"},
1852aceefefSIan Molton 	{"HP Mixer", NULL, "Right DAC"},
1862aceefefSIan Molton 
1872aceefefSIan Molton 	/* mono mixer */
1882aceefefSIan Molton 	{"Mono Mixer", NULL, "HP Mixer"},
1892aceefefSIan Molton 
1902aceefefSIan Molton 	/* outputs */
1912aceefefSIan Molton 	{"Headphone PGA", NULL, "HP Mixer"},
1922aceefefSIan Molton 	{"HPOUTL", NULL, "Headphone PGA"},
1932aceefefSIan Molton 	{"HPOUTR", NULL, "Headphone PGA"},
1942aceefefSIan Molton 	{"Line out PGA", NULL, "HP Mixer"},
1952aceefefSIan Molton 	{"LOUT", NULL, "Line out PGA"},
1962aceefefSIan Molton 	{"ROUT", NULL, "Line out PGA"},
1972aceefefSIan Molton 	{"Mono PGA", NULL, "Mono Mixer"},
1982aceefefSIan Molton 	{"MONOOUT", NULL, "Mono PGA"},
1992aceefefSIan Molton 
2002aceefefSIan Molton 	/* inputs */
2012aceefefSIan Molton 	{"CD PGA", NULL, "CDINL"},
2022aceefefSIan Molton 	{"CD PGA", NULL, "CDINR"},
2032aceefefSIan Molton 	{"Line PGA", NULL, "LINEINL"},
2042aceefefSIan Molton 	{"Line PGA", NULL, "LINEINR"},
2052aceefefSIan Molton 	{"Phone PGA", NULL, "PHONE"},
2062aceefefSIan Molton 	{"Mic Source", "Mic 1", "MIC1"},
2072aceefefSIan Molton 	{"Mic Source", "Mic 2", "MIC2"},
2082aceefefSIan Molton 	{"Mic PGA", NULL, "Mic Source"},
2092aceefefSIan Molton 	{"PCBEEP PGA", NULL, "PCBEEP"},
2102aceefefSIan Molton 
2112aceefefSIan Molton 	/* Left capture selector */
2122aceefefSIan Molton 	{"Left Capture Source", "Mic", "Mic Source"},
2132aceefefSIan Molton 	{"Left Capture Source", "CD", "CDINL"},
2142aceefefSIan Molton 	{"Left Capture Source", "Line", "LINEINL"},
2152aceefefSIan Molton 	{"Left Capture Source", "Stereo Mix", "HP Mixer"},
2162aceefefSIan Molton 	{"Left Capture Source", "Mono Mix", "HP Mixer"},
2172aceefefSIan Molton 	{"Left Capture Source", "Phone", "PHONE"},
2182aceefefSIan Molton 
2192aceefefSIan Molton 	/* Right capture source */
2202aceefefSIan Molton 	{"Right Capture Source", "Mic", "Mic Source"},
2212aceefefSIan Molton 	{"Right Capture Source", "CD", "CDINR"},
2222aceefefSIan Molton 	{"Right Capture Source", "Line", "LINEINR"},
2232aceefefSIan Molton 	{"Right Capture Source", "Stereo Mix", "HP Mixer"},
2242aceefefSIan Molton 	{"Right Capture Source", "Mono Mix", "HP Mixer"},
2252aceefefSIan Molton 	{"Right Capture Source", "Phone", "PHONE"},
2262aceefefSIan Molton 
2272aceefefSIan Molton 	{"ADC PGA", NULL, "Left Capture Source"},
2282aceefefSIan Molton 	{"ADC PGA", NULL, "Right Capture Source"},
2292aceefefSIan Molton 
2302aceefefSIan Molton 	/* ADC's */
2312aceefefSIan Molton 	{"Left ADC",  NULL, "ADC PGA"},
2322aceefefSIan Molton 	{"Right ADC", NULL, "ADC PGA"},
2332aceefefSIan Molton };
2342aceefefSIan Molton 
2352aceefefSIan Molton static int ac97_prepare(struct snd_pcm_substream *substream,
2362aceefefSIan Molton 			struct snd_soc_dai *dai)
2372aceefefSIan Molton {
23828f89849SKuninori Morimoto 	struct snd_soc_component *component = dai->component;
2392aceefefSIan Molton 	int reg;
2402aceefefSIan Molton 
24128f89849SKuninori Morimoto 	snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x1, 0x1);
2422aceefefSIan Molton 
2432aceefefSIan Molton 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2442aceefefSIan Molton 		reg = AC97_PCM_FRONT_DAC_RATE;
2452aceefefSIan Molton 	else
2462aceefefSIan Molton 		reg = AC97_PCM_LR_ADC_RATE;
2472aceefefSIan Molton 
24828f89849SKuninori Morimoto 	return snd_soc_component_write(component, reg, substream->runtime->rate);
2492aceefefSIan Molton }
2502aceefefSIan Molton 
2512aceefefSIan Molton #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \
2522aceefefSIan Molton 			SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
2532aceefefSIan Molton 			SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
2542aceefefSIan Molton 			SNDRV_PCM_RATE_48000)
2552aceefefSIan Molton 
25685e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9705_dai_ops = {
2576335d055SEric Miao 	.prepare	= ac97_prepare,
2586335d055SEric Miao };
2596335d055SEric Miao 
260f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm9705_dai[] = {
2612aceefefSIan Molton 	{
262f0fba2adSLiam Girdwood 		.name = "wm9705-hifi",
2632aceefefSIan Molton 		.playback = {
2642aceefefSIan Molton 			.stream_name = "HiFi Playback",
2652aceefefSIan Molton 			.channels_min = 1,
2662aceefefSIan Molton 			.channels_max = 2,
2672aceefefSIan Molton 			.rates = WM9705_AC97_RATES,
26833f503c9SMark Brown 			.formats = SND_SOC_STD_AC97_FMTS,
2692aceefefSIan Molton 		},
2702aceefefSIan Molton 		.capture = {
2712aceefefSIan Molton 			.stream_name = "HiFi Capture",
2722aceefefSIan Molton 			.channels_min = 1,
2732aceefefSIan Molton 			.channels_max = 2,
2742aceefefSIan Molton 			.rates = WM9705_AC97_RATES,
27533f503c9SMark Brown 			.formats = SND_SOC_STD_AC97_FMTS,
2762aceefefSIan Molton 		},
2776335d055SEric Miao 		.ops = &wm9705_dai_ops,
2782aceefefSIan Molton 	},
2792aceefefSIan Molton 	{
280f0fba2adSLiam Girdwood 		.name = "wm9705-aux",
2812aceefefSIan Molton 		.playback = {
2822aceefefSIan Molton 			.stream_name = "Aux Playback",
2832aceefefSIan Molton 			.channels_min = 1,
2842aceefefSIan Molton 			.channels_max = 1,
2852aceefefSIan Molton 			.rates = WM9705_AC97_RATES,
2862aceefefSIan Molton 			.formats = SNDRV_PCM_FMTBIT_S16_LE,
2872aceefefSIan Molton 		},
2882aceefefSIan Molton 	}
2892aceefefSIan Molton };
2902aceefefSIan Molton 
2910a11b168SMark Brown #ifdef CONFIG_PM
29228f89849SKuninori Morimoto static int wm9705_soc_suspend(struct snd_soc_component *component)
2930a11b168SMark Brown {
29428f89849SKuninori Morimoto 	regcache_cache_bypass(component->regmap, true);
29528f89849SKuninori Morimoto 	snd_soc_component_write(component, AC97_POWERDOWN, 0xffff);
29628f89849SKuninori Morimoto 	regcache_cache_bypass(component->regmap, false);
2970a11b168SMark Brown 
2980a11b168SMark Brown 	return 0;
2990a11b168SMark Brown }
3000a11b168SMark Brown 
30128f89849SKuninori Morimoto static int wm9705_soc_resume(struct snd_soc_component *component)
3020a11b168SMark Brown {
30328f89849SKuninori Morimoto 	struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
304206964e8SLars-Peter Clausen 	int ret;
3050a11b168SMark Brown 
306c6e46e52SRobert Jarzmik 	ret = snd_ac97_reset(wm9705->ac97, true, WM9705_VENDOR_ID,
3076e0b73a0SLars-Peter Clausen 		WM9705_VENDOR_ID_MASK);
3089cf766f6SLars-Peter Clausen 	if (ret < 0)
3090a11b168SMark Brown 		return ret;
3100a11b168SMark Brown 
31128f89849SKuninori Morimoto 	snd_soc_component_cache_sync(component);
3120a11b168SMark Brown 
3130a11b168SMark Brown 	return 0;
3140a11b168SMark Brown }
3150a11b168SMark Brown #else
3160a11b168SMark Brown #define wm9705_soc_suspend NULL
3170a11b168SMark Brown #define wm9705_soc_resume NULL
3180a11b168SMark Brown #endif
3190a11b168SMark Brown 
32028f89849SKuninori Morimoto static int wm9705_soc_probe(struct snd_soc_component *component)
3212aceefefSIan Molton {
32228f89849SKuninori Morimoto 	struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
323206964e8SLars-Peter Clausen 	struct regmap *regmap;
3242aceefefSIan Molton 
325aaafcfedSRobert Jarzmik 	if (wm9705->mfd_pdata) {
326aaafcfedSRobert Jarzmik 		wm9705->ac97 = wm9705->mfd_pdata->ac97;
327aaafcfedSRobert Jarzmik 		regmap = wm9705->mfd_pdata->regmap;
328aaafcfedSRobert Jarzmik 	} else {
329aaafcfedSRobert Jarzmik #ifdef CONFIG_SND_SOC_AC97_BUS
33028f89849SKuninori Morimoto 		wm9705->ac97 = snd_soc_new_ac97_component(component, WM9705_VENDOR_ID,
3316e0b73a0SLars-Peter Clausen 						      WM9705_VENDOR_ID_MASK);
332c6e46e52SRobert Jarzmik 		if (IS_ERR(wm9705->ac97)) {
33328f89849SKuninori Morimoto 			dev_err(component->dev, "Failed to register AC97 codec\n");
334c6e46e52SRobert Jarzmik 			return PTR_ERR(wm9705->ac97);
3352aceefefSIan Molton 		}
3362aceefefSIan Molton 
337c6e46e52SRobert Jarzmik 		regmap = regmap_init_ac97(wm9705->ac97, &wm9705_regmap_config);
338206964e8SLars-Peter Clausen 		if (IS_ERR(regmap)) {
33928f89849SKuninori Morimoto 			snd_soc_free_ac97_component(wm9705->ac97);
3406bd25aaeSRobert Jarzmik 			return PTR_ERR(regmap);
341206964e8SLars-Peter Clausen 		}
342aaafcfedSRobert Jarzmik #endif
343aaafcfedSRobert Jarzmik 	}
344206964e8SLars-Peter Clausen 
34528f89849SKuninori Morimoto 	snd_soc_component_set_drvdata(component, wm9705->ac97);
34628f89849SKuninori Morimoto 	snd_soc_component_init_regmap(component, regmap);
3472aceefefSIan Molton 
3482aceefefSIan Molton 	return 0;
3492aceefefSIan Molton }
3502aceefefSIan Molton 
35128f89849SKuninori Morimoto static void wm9705_soc_remove(struct snd_soc_component *component)
3522aceefefSIan Molton {
353aaafcfedSRobert Jarzmik #ifdef CONFIG_SND_SOC_AC97_BUS
35428f89849SKuninori Morimoto 	struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
355358a8bb5SLars-Peter Clausen 
356aaafcfedSRobert Jarzmik 	if (!wm9705->mfd_pdata) {
35728f89849SKuninori Morimoto 		snd_soc_component_exit_regmap(component);
35828f89849SKuninori Morimoto 		snd_soc_free_ac97_component(wm9705->ac97);
359aaafcfedSRobert Jarzmik 	}
360aaafcfedSRobert Jarzmik #endif
3612aceefefSIan Molton }
3622aceefefSIan Molton 
36328f89849SKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm9705 = {
3642aceefefSIan Molton 	.probe			= wm9705_soc_probe,
3652aceefefSIan Molton 	.remove			= wm9705_soc_remove,
3660a11b168SMark Brown 	.suspend		= wm9705_soc_suspend,
3670a11b168SMark Brown 	.resume			= wm9705_soc_resume,
368d7cabb08SLars-Peter Clausen 	.controls		= wm9705_snd_ac97_controls,
369d7cabb08SLars-Peter Clausen 	.num_controls		= ARRAY_SIZE(wm9705_snd_ac97_controls),
37097a58d6eSLu Guanqun 	.dapm_widgets		= wm9705_dapm_widgets,
37197a58d6eSLu Guanqun 	.num_dapm_widgets	= ARRAY_SIZE(wm9705_dapm_widgets),
37297a58d6eSLu Guanqun 	.dapm_routes		= wm9705_audio_map,
37397a58d6eSLu Guanqun 	.num_dapm_routes	= ARRAY_SIZE(wm9705_audio_map),
37428f89849SKuninori Morimoto 	.idle_bias_on		= 1,
37528f89849SKuninori Morimoto 	.use_pmdown_time	= 1,
37628f89849SKuninori Morimoto 	.endianness		= 1,
37728f89849SKuninori Morimoto 	.non_legacy_dai_naming	= 1,
3782aceefefSIan Molton };
379f0fba2adSLiam Girdwood 
3807a79e94eSBill Pemberton static int wm9705_probe(struct platform_device *pdev)
381f0fba2adSLiam Girdwood {
382c6e46e52SRobert Jarzmik 	struct wm9705_priv *wm9705;
383c6e46e52SRobert Jarzmik 
384c6e46e52SRobert Jarzmik 	wm9705 = devm_kzalloc(&pdev->dev, sizeof(*wm9705), GFP_KERNEL);
385c6e46e52SRobert Jarzmik 	if (wm9705 == NULL)
386c6e46e52SRobert Jarzmik 		return -ENOMEM;
387c6e46e52SRobert Jarzmik 
388aaafcfedSRobert Jarzmik 	wm9705->mfd_pdata = dev_get_platdata(&pdev->dev);
389c6e46e52SRobert Jarzmik 	platform_set_drvdata(pdev, wm9705);
390c6e46e52SRobert Jarzmik 
39128f89849SKuninori Morimoto 	return devm_snd_soc_register_component(&pdev->dev,
39228f89849SKuninori Morimoto 			&soc_component_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai));
393f0fba2adSLiam Girdwood }
394f0fba2adSLiam Girdwood 
395f0fba2adSLiam Girdwood static struct platform_driver wm9705_codec_driver = {
396f0fba2adSLiam Girdwood 	.driver = {
397f0fba2adSLiam Girdwood 			.name = "wm9705-codec",
398f0fba2adSLiam Girdwood 	},
399f0fba2adSLiam Girdwood 
400f0fba2adSLiam Girdwood 	.probe = wm9705_probe,
401f0fba2adSLiam Girdwood };
402f0fba2adSLiam Girdwood 
4035bbcc3c0SMark Brown module_platform_driver(wm9705_codec_driver);
4042aceefefSIan Molton 
4052aceefefSIan Molton MODULE_DESCRIPTION("ASoC WM9705 driver");
4062aceefefSIan Molton MODULE_AUTHOR("Ian Molton");
4072aceefefSIan Molton MODULE_LICENSE("GPL v2");
408