1b886d83cSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
22aceefefSIan Molton /*
32aceefefSIan Molton * wm9705.c -- ALSA Soc WM9705 codec support
42aceefefSIan Molton *
52aceefefSIan Molton * Copyright 2008 Ian Molton <spyro@f2s.com>
62aceefefSIan Molton */
72aceefefSIan Molton
82aceefefSIan Molton #include <linux/init.h>
95a0e3ad6STejun Heo #include <linux/slab.h>
10aaafcfedSRobert Jarzmik #include <linux/mfd/wm97xx.h>
112aceefefSIan Molton #include <linux/module.h>
122aceefefSIan Molton #include <linux/kernel.h>
132aceefefSIan Molton #include <linux/device.h>
14206964e8SLars-Peter Clausen #include <linux/regmap.h>
152aceefefSIan Molton #include <sound/core.h>
162aceefefSIan Molton #include <sound/pcm.h>
172aceefefSIan Molton #include <sound/ac97_codec.h>
18aaafcfedSRobert Jarzmik #include <sound/ac97/codec.h>
19aaafcfedSRobert Jarzmik #include <sound/ac97/compat.h>
202aceefefSIan Molton #include <sound/initval.h>
212aceefefSIan Molton #include <sound/soc.h>
222aceefefSIan Molton
236e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID 0x574d4c05
246e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID_MASK 0xffffffff
256e0b73a0SLars-Peter Clausen
26c6e46e52SRobert Jarzmik struct wm9705_priv {
27c6e46e52SRobert Jarzmik struct snd_ac97 *ac97;
28aaafcfedSRobert Jarzmik struct wm97xx_platform_data *mfd_pdata;
29c6e46e52SRobert Jarzmik };
30c6e46e52SRobert Jarzmik
31206964e8SLars-Peter Clausen static const struct reg_default wm9705_reg_defaults[] = {
32206964e8SLars-Peter Clausen { 0x02, 0x8000 },
33206964e8SLars-Peter Clausen { 0x04, 0x8000 },
34206964e8SLars-Peter Clausen { 0x06, 0x8000 },
35206964e8SLars-Peter Clausen { 0x0a, 0x8000 },
36206964e8SLars-Peter Clausen { 0x0c, 0x8008 },
37206964e8SLars-Peter Clausen { 0x0e, 0x8008 },
38206964e8SLars-Peter Clausen { 0x10, 0x8808 },
39206964e8SLars-Peter Clausen { 0x12, 0x8808 },
40206964e8SLars-Peter Clausen { 0x14, 0x8808 },
41206964e8SLars-Peter Clausen { 0x16, 0x8808 },
42206964e8SLars-Peter Clausen { 0x18, 0x8808 },
43206964e8SLars-Peter Clausen { 0x1a, 0x0000 },
44206964e8SLars-Peter Clausen { 0x1c, 0x8000 },
45206964e8SLars-Peter Clausen { 0x20, 0x0000 },
46206964e8SLars-Peter Clausen { 0x22, 0x0000 },
47206964e8SLars-Peter Clausen { 0x26, 0x000f },
48206964e8SLars-Peter Clausen { 0x28, 0x0605 },
49206964e8SLars-Peter Clausen { 0x2a, 0x0000 },
50206964e8SLars-Peter Clausen { 0x2c, 0xbb80 },
51206964e8SLars-Peter Clausen { 0x32, 0xbb80 },
52206964e8SLars-Peter Clausen { 0x34, 0x2000 },
53206964e8SLars-Peter Clausen { 0x5a, 0x0000 },
54206964e8SLars-Peter Clausen { 0x5c, 0x0000 },
55206964e8SLars-Peter Clausen { 0x72, 0x0808 },
56206964e8SLars-Peter Clausen { 0x74, 0x0000 },
57206964e8SLars-Peter Clausen { 0x76, 0x0006 },
58206964e8SLars-Peter Clausen { 0x78, 0x0000 },
59206964e8SLars-Peter Clausen { 0x7a, 0x0000 },
60206964e8SLars-Peter Clausen };
61206964e8SLars-Peter Clausen
62206964e8SLars-Peter Clausen static const struct regmap_config wm9705_regmap_config = {
63206964e8SLars-Peter Clausen .reg_bits = 16,
64206964e8SLars-Peter Clausen .reg_stride = 2,
65206964e8SLars-Peter Clausen .val_bits = 16,
66206964e8SLars-Peter Clausen .max_register = 0x7e,
67*7e510925SMark Brown .cache_type = REGCACHE_MAPLE,
68206964e8SLars-Peter Clausen
69206964e8SLars-Peter Clausen .volatile_reg = regmap_ac97_default_volatile,
70206964e8SLars-Peter Clausen
71206964e8SLars-Peter Clausen .reg_defaults = wm9705_reg_defaults,
72206964e8SLars-Peter Clausen .num_reg_defaults = ARRAY_SIZE(wm9705_reg_defaults),
732aceefefSIan Molton };
742aceefefSIan Molton
752aceefefSIan Molton static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = {
762aceefefSIan Molton SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1),
772aceefefSIan Molton SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1),
782aceefefSIan Molton SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
792aceefefSIan Molton SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1),
802aceefefSIan Molton SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1),
812aceefefSIan Molton SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1),
822aceefefSIan Molton SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1),
832aceefefSIan Molton SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
842aceefefSIan Molton SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1),
852aceefefSIan Molton SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1),
862aceefefSIan Molton SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1),
872aceefefSIan Molton SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1),
882aceefefSIan Molton SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1),
892aceefefSIan Molton SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0),
90927b0aeaSIan Molton SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0),
91927b0aeaSIan Molton SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1),
922aceefefSIan Molton };
932aceefefSIan Molton
942aceefefSIan Molton static const char *wm9705_mic[] = {"Mic 1", "Mic 2"};
952aceefefSIan Molton static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC",
962aceefefSIan Molton "Line", "Stereo Mix", "Mono Mix", "Phone"};
972aceefefSIan Molton
9809981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic,
9909981dcbSTakashi Iwai AC97_GENERAL_PURPOSE, 8, wm9705_mic);
10009981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l,
10109981dcbSTakashi Iwai AC97_REC_SEL, 8, wm9705_rec_sel);
10209981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r,
10309981dcbSTakashi Iwai AC97_REC_SEL, 0, wm9705_rec_sel);
1042aceefefSIan Molton
1052aceefefSIan Molton /* Headphone Mixer */
1062aceefefSIan Molton static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = {
1072aceefefSIan Molton SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1),
1082aceefefSIan Molton SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1),
1092aceefefSIan Molton SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1),
1102aceefefSIan Molton SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1),
1112aceefefSIan Molton SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1),
1122aceefefSIan Molton };
1132aceefefSIan Molton
1142aceefefSIan Molton /* Mic source */
1152aceefefSIan Molton static const struct snd_kcontrol_new wm9705_mic_src_controls =
1162aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_mic);
1172aceefefSIan Molton
1182aceefefSIan Molton /* Capture source */
1192aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectl_controls =
1202aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_l);
1212aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectr_controls =
1222aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_r);
1232aceefefSIan Molton
1242aceefefSIan Molton /* DAPM widgets */
1252aceefefSIan Molton static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = {
1262aceefefSIan Molton SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0,
1272aceefefSIan Molton &wm9705_mic_src_controls),
1282aceefefSIan Molton SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
1292aceefefSIan Molton &wm9705_capture_selectl_controls),
1302aceefefSIan Molton SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
1312aceefefSIan Molton &wm9705_capture_selectr_controls),
1322aceefefSIan Molton SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback",
1332aceefefSIan Molton SND_SOC_NOPM, 0, 0),
1342aceefefSIan Molton SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback",
1352aceefefSIan Molton SND_SOC_NOPM, 0, 0),
1362aceefefSIan Molton SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0,
1372aceefefSIan Molton &wm9705_hp_mixer_controls[0],
1382aceefefSIan Molton ARRAY_SIZE(wm9705_hp_mixer_controls)),
1392aceefefSIan Molton SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
1402aceefefSIan Molton SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0),
1412aceefefSIan Molton SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0),
1422aceefefSIan Molton SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1432aceefefSIan Molton SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1442aceefefSIan Molton SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1452aceefefSIan Molton SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1462aceefefSIan Molton SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1472aceefefSIan Molton SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1482aceefefSIan Molton SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1492aceefefSIan Molton SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1502aceefefSIan Molton SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1512aceefefSIan Molton SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0),
1522aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTL"),
1532aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTR"),
1542aceefefSIan Molton SND_SOC_DAPM_OUTPUT("LOUT"),
1552aceefefSIan Molton SND_SOC_DAPM_OUTPUT("ROUT"),
1562aceefefSIan Molton SND_SOC_DAPM_OUTPUT("MONOOUT"),
1572aceefefSIan Molton SND_SOC_DAPM_INPUT("PHONE"),
1582aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINL"),
1592aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINR"),
1602aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINL"),
1612aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINR"),
1622aceefefSIan Molton SND_SOC_DAPM_INPUT("PCBEEP"),
1632aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC1"),
1642aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC2"),
1652aceefefSIan Molton };
1662aceefefSIan Molton
1672aceefefSIan Molton /* Audio map
1682aceefefSIan Molton * WM9705 has no switches to disable the route from the inputs to the HP mixer
1692aceefefSIan Molton * so in order to prevent active inputs from forcing the audio outputs to be
1702aceefefSIan Molton * constantly enabled, we use the mutes on those inputs to simulate such
1712aceefefSIan Molton * controls.
1722aceefefSIan Molton */
17397a58d6eSLu Guanqun static const struct snd_soc_dapm_route wm9705_audio_map[] = {
1742aceefefSIan Molton /* HP mixer */
1752aceefefSIan Molton {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"},
1762aceefefSIan Molton {"HP Mixer", "CD Playback Switch", "CD PGA"},
1772aceefefSIan Molton {"HP Mixer", "Mic Playback Switch", "Mic PGA"},
1782aceefefSIan Molton {"HP Mixer", "Phone Playback Switch", "Phone PGA"},
1792aceefefSIan Molton {"HP Mixer", "Line Playback Switch", "Line PGA"},
1802aceefefSIan Molton {"HP Mixer", NULL, "Left DAC"},
1812aceefefSIan Molton {"HP Mixer", NULL, "Right DAC"},
1822aceefefSIan Molton
1832aceefefSIan Molton /* mono mixer */
1842aceefefSIan Molton {"Mono Mixer", NULL, "HP Mixer"},
1852aceefefSIan Molton
1862aceefefSIan Molton /* outputs */
1872aceefefSIan Molton {"Headphone PGA", NULL, "HP Mixer"},
1882aceefefSIan Molton {"HPOUTL", NULL, "Headphone PGA"},
1892aceefefSIan Molton {"HPOUTR", NULL, "Headphone PGA"},
1902aceefefSIan Molton {"Line out PGA", NULL, "HP Mixer"},
1912aceefefSIan Molton {"LOUT", NULL, "Line out PGA"},
1922aceefefSIan Molton {"ROUT", NULL, "Line out PGA"},
1932aceefefSIan Molton {"Mono PGA", NULL, "Mono Mixer"},
1942aceefefSIan Molton {"MONOOUT", NULL, "Mono PGA"},
1952aceefefSIan Molton
1962aceefefSIan Molton /* inputs */
1972aceefefSIan Molton {"CD PGA", NULL, "CDINL"},
1982aceefefSIan Molton {"CD PGA", NULL, "CDINR"},
1992aceefefSIan Molton {"Line PGA", NULL, "LINEINL"},
2002aceefefSIan Molton {"Line PGA", NULL, "LINEINR"},
2012aceefefSIan Molton {"Phone PGA", NULL, "PHONE"},
2022aceefefSIan Molton {"Mic Source", "Mic 1", "MIC1"},
2032aceefefSIan Molton {"Mic Source", "Mic 2", "MIC2"},
2042aceefefSIan Molton {"Mic PGA", NULL, "Mic Source"},
2052aceefefSIan Molton {"PCBEEP PGA", NULL, "PCBEEP"},
2062aceefefSIan Molton
2072aceefefSIan Molton /* Left capture selector */
2082aceefefSIan Molton {"Left Capture Source", "Mic", "Mic Source"},
2092aceefefSIan Molton {"Left Capture Source", "CD", "CDINL"},
2102aceefefSIan Molton {"Left Capture Source", "Line", "LINEINL"},
2112aceefefSIan Molton {"Left Capture Source", "Stereo Mix", "HP Mixer"},
2122aceefefSIan Molton {"Left Capture Source", "Mono Mix", "HP Mixer"},
2132aceefefSIan Molton {"Left Capture Source", "Phone", "PHONE"},
2142aceefefSIan Molton
2152aceefefSIan Molton /* Right capture source */
2162aceefefSIan Molton {"Right Capture Source", "Mic", "Mic Source"},
2172aceefefSIan Molton {"Right Capture Source", "CD", "CDINR"},
2182aceefefSIan Molton {"Right Capture Source", "Line", "LINEINR"},
2192aceefefSIan Molton {"Right Capture Source", "Stereo Mix", "HP Mixer"},
2202aceefefSIan Molton {"Right Capture Source", "Mono Mix", "HP Mixer"},
2212aceefefSIan Molton {"Right Capture Source", "Phone", "PHONE"},
2222aceefefSIan Molton
2232aceefefSIan Molton {"ADC PGA", NULL, "Left Capture Source"},
2242aceefefSIan Molton {"ADC PGA", NULL, "Right Capture Source"},
2252aceefefSIan Molton
2262aceefefSIan Molton /* ADC's */
2272aceefefSIan Molton {"Left ADC", NULL, "ADC PGA"},
2282aceefefSIan Molton {"Right ADC", NULL, "ADC PGA"},
2292aceefefSIan Molton };
2302aceefefSIan Molton
ac97_prepare(struct snd_pcm_substream * substream,struct snd_soc_dai * dai)2312aceefefSIan Molton static int ac97_prepare(struct snd_pcm_substream *substream,
2322aceefefSIan Molton struct snd_soc_dai *dai)
2332aceefefSIan Molton {
23428f89849SKuninori Morimoto struct snd_soc_component *component = dai->component;
2352aceefefSIan Molton int reg;
2362aceefefSIan Molton
23728f89849SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x1, 0x1);
2382aceefefSIan Molton
2392aceefefSIan Molton if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
2402aceefefSIan Molton reg = AC97_PCM_FRONT_DAC_RATE;
2412aceefefSIan Molton else
2422aceefefSIan Molton reg = AC97_PCM_LR_ADC_RATE;
2432aceefefSIan Molton
24428f89849SKuninori Morimoto return snd_soc_component_write(component, reg, substream->runtime->rate);
2452aceefefSIan Molton }
2462aceefefSIan Molton
2472aceefefSIan Molton #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \
2482aceefefSIan Molton SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
2492aceefefSIan Molton SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
2502aceefefSIan Molton SNDRV_PCM_RATE_48000)
2512aceefefSIan Molton
25285e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9705_dai_ops = {
2536335d055SEric Miao .prepare = ac97_prepare,
2546335d055SEric Miao };
2556335d055SEric Miao
256f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm9705_dai[] = {
2572aceefefSIan Molton {
258f0fba2adSLiam Girdwood .name = "wm9705-hifi",
2592aceefefSIan Molton .playback = {
2602aceefefSIan Molton .stream_name = "HiFi Playback",
2612aceefefSIan Molton .channels_min = 1,
2622aceefefSIan Molton .channels_max = 2,
2632aceefefSIan Molton .rates = WM9705_AC97_RATES,
26433f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS,
2652aceefefSIan Molton },
2662aceefefSIan Molton .capture = {
2672aceefefSIan Molton .stream_name = "HiFi Capture",
2682aceefefSIan Molton .channels_min = 1,
2692aceefefSIan Molton .channels_max = 2,
2702aceefefSIan Molton .rates = WM9705_AC97_RATES,
27133f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS,
2722aceefefSIan Molton },
2736335d055SEric Miao .ops = &wm9705_dai_ops,
2742aceefefSIan Molton },
2752aceefefSIan Molton {
276f0fba2adSLiam Girdwood .name = "wm9705-aux",
2772aceefefSIan Molton .playback = {
2782aceefefSIan Molton .stream_name = "Aux Playback",
2792aceefefSIan Molton .channels_min = 1,
2802aceefefSIan Molton .channels_max = 1,
2812aceefefSIan Molton .rates = WM9705_AC97_RATES,
2822aceefefSIan Molton .formats = SNDRV_PCM_FMTBIT_S16_LE,
2832aceefefSIan Molton },
2842aceefefSIan Molton }
2852aceefefSIan Molton };
2862aceefefSIan Molton
2870a11b168SMark Brown #ifdef CONFIG_PM
wm9705_soc_suspend(struct snd_soc_component * component)28828f89849SKuninori Morimoto static int wm9705_soc_suspend(struct snd_soc_component *component)
2890a11b168SMark Brown {
29028f89849SKuninori Morimoto regcache_cache_bypass(component->regmap, true);
29128f89849SKuninori Morimoto snd_soc_component_write(component, AC97_POWERDOWN, 0xffff);
29228f89849SKuninori Morimoto regcache_cache_bypass(component->regmap, false);
2930a11b168SMark Brown
2940a11b168SMark Brown return 0;
2950a11b168SMark Brown }
2960a11b168SMark Brown
wm9705_soc_resume(struct snd_soc_component * component)29728f89849SKuninori Morimoto static int wm9705_soc_resume(struct snd_soc_component *component)
2980a11b168SMark Brown {
29928f89849SKuninori Morimoto struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
300206964e8SLars-Peter Clausen int ret;
3010a11b168SMark Brown
302c6e46e52SRobert Jarzmik ret = snd_ac97_reset(wm9705->ac97, true, WM9705_VENDOR_ID,
3036e0b73a0SLars-Peter Clausen WM9705_VENDOR_ID_MASK);
3049cf766f6SLars-Peter Clausen if (ret < 0)
3050a11b168SMark Brown return ret;
3060a11b168SMark Brown
30728f89849SKuninori Morimoto snd_soc_component_cache_sync(component);
3080a11b168SMark Brown
3090a11b168SMark Brown return 0;
3100a11b168SMark Brown }
3110a11b168SMark Brown #else
3120a11b168SMark Brown #define wm9705_soc_suspend NULL
3130a11b168SMark Brown #define wm9705_soc_resume NULL
3140a11b168SMark Brown #endif
3150a11b168SMark Brown
wm9705_soc_probe(struct snd_soc_component * component)31628f89849SKuninori Morimoto static int wm9705_soc_probe(struct snd_soc_component *component)
3172aceefefSIan Molton {
31828f89849SKuninori Morimoto struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
319206964e8SLars-Peter Clausen struct regmap *regmap;
3202aceefefSIan Molton
321aaafcfedSRobert Jarzmik if (wm9705->mfd_pdata) {
322aaafcfedSRobert Jarzmik wm9705->ac97 = wm9705->mfd_pdata->ac97;
323aaafcfedSRobert Jarzmik regmap = wm9705->mfd_pdata->regmap;
324576ce407SArnd Bergmann } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) {
32528f89849SKuninori Morimoto wm9705->ac97 = snd_soc_new_ac97_component(component, WM9705_VENDOR_ID,
3266e0b73a0SLars-Peter Clausen WM9705_VENDOR_ID_MASK);
327c6e46e52SRobert Jarzmik if (IS_ERR(wm9705->ac97)) {
32828f89849SKuninori Morimoto dev_err(component->dev, "Failed to register AC97 codec\n");
329c6e46e52SRobert Jarzmik return PTR_ERR(wm9705->ac97);
3302aceefefSIan Molton }
3312aceefefSIan Molton
332c6e46e52SRobert Jarzmik regmap = regmap_init_ac97(wm9705->ac97, &wm9705_regmap_config);
333206964e8SLars-Peter Clausen if (IS_ERR(regmap)) {
33428f89849SKuninori Morimoto snd_soc_free_ac97_component(wm9705->ac97);
3356bd25aaeSRobert Jarzmik return PTR_ERR(regmap);
336206964e8SLars-Peter Clausen }
337576ce407SArnd Bergmann } else {
338576ce407SArnd Bergmann return -ENXIO;
339aaafcfedSRobert Jarzmik }
340206964e8SLars-Peter Clausen
34128f89849SKuninori Morimoto snd_soc_component_set_drvdata(component, wm9705->ac97);
34228f89849SKuninori Morimoto snd_soc_component_init_regmap(component, regmap);
3432aceefefSIan Molton
3442aceefefSIan Molton return 0;
3452aceefefSIan Molton }
3462aceefefSIan Molton
wm9705_soc_remove(struct snd_soc_component * component)34728f89849SKuninori Morimoto static void wm9705_soc_remove(struct snd_soc_component *component)
3482aceefefSIan Molton {
34928f89849SKuninori Morimoto struct wm9705_priv *wm9705 = snd_soc_component_get_drvdata(component);
350358a8bb5SLars-Peter Clausen
351576ce407SArnd Bergmann if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9705->mfd_pdata) {
35228f89849SKuninori Morimoto snd_soc_component_exit_regmap(component);
35328f89849SKuninori Morimoto snd_soc_free_ac97_component(wm9705->ac97);
354aaafcfedSRobert Jarzmik }
3552aceefefSIan Molton }
3562aceefefSIan Molton
35728f89849SKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm9705 = {
3582aceefefSIan Molton .probe = wm9705_soc_probe,
3592aceefefSIan Molton .remove = wm9705_soc_remove,
3600a11b168SMark Brown .suspend = wm9705_soc_suspend,
3610a11b168SMark Brown .resume = wm9705_soc_resume,
362d7cabb08SLars-Peter Clausen .controls = wm9705_snd_ac97_controls,
363d7cabb08SLars-Peter Clausen .num_controls = ARRAY_SIZE(wm9705_snd_ac97_controls),
36497a58d6eSLu Guanqun .dapm_widgets = wm9705_dapm_widgets,
36597a58d6eSLu Guanqun .num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets),
36697a58d6eSLu Guanqun .dapm_routes = wm9705_audio_map,
36797a58d6eSLu Guanqun .num_dapm_routes = ARRAY_SIZE(wm9705_audio_map),
36828f89849SKuninori Morimoto .idle_bias_on = 1,
36928f89849SKuninori Morimoto .use_pmdown_time = 1,
37028f89849SKuninori Morimoto .endianness = 1,
3712aceefefSIan Molton };
372f0fba2adSLiam Girdwood
wm9705_probe(struct platform_device * pdev)3737a79e94eSBill Pemberton static int wm9705_probe(struct platform_device *pdev)
374f0fba2adSLiam Girdwood {
375c6e46e52SRobert Jarzmik struct wm9705_priv *wm9705;
376c6e46e52SRobert Jarzmik
377c6e46e52SRobert Jarzmik wm9705 = devm_kzalloc(&pdev->dev, sizeof(*wm9705), GFP_KERNEL);
378c6e46e52SRobert Jarzmik if (wm9705 == NULL)
379c6e46e52SRobert Jarzmik return -ENOMEM;
380c6e46e52SRobert Jarzmik
381aaafcfedSRobert Jarzmik wm9705->mfd_pdata = dev_get_platdata(&pdev->dev);
382c6e46e52SRobert Jarzmik platform_set_drvdata(pdev, wm9705);
383c6e46e52SRobert Jarzmik
38428f89849SKuninori Morimoto return devm_snd_soc_register_component(&pdev->dev,
38528f89849SKuninori Morimoto &soc_component_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai));
386f0fba2adSLiam Girdwood }
387f0fba2adSLiam Girdwood
388f0fba2adSLiam Girdwood static struct platform_driver wm9705_codec_driver = {
389f0fba2adSLiam Girdwood .driver = {
390f0fba2adSLiam Girdwood .name = "wm9705-codec",
391f0fba2adSLiam Girdwood },
392f0fba2adSLiam Girdwood
393f0fba2adSLiam Girdwood .probe = wm9705_probe,
394f0fba2adSLiam Girdwood };
395f0fba2adSLiam Girdwood
3965bbcc3c0SMark Brown module_platform_driver(wm9705_codec_driver);
3972aceefefSIan Molton
3982aceefefSIan Molton MODULE_DESCRIPTION("ASoC WM9705 driver");
3992aceefefSIan Molton MODULE_AUTHOR("Ian Molton");
4002aceefefSIan Molton MODULE_LICENSE("GPL v2");
401