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> 142aceefefSIan Molton #include <linux/module.h> 152aceefefSIan Molton #include <linux/kernel.h> 162aceefefSIan Molton #include <linux/device.h> 172aceefefSIan Molton #include <sound/core.h> 182aceefefSIan Molton #include <sound/pcm.h> 192aceefefSIan Molton #include <sound/ac97_codec.h> 202aceefefSIan Molton #include <sound/initval.h> 212aceefefSIan Molton #include <sound/soc.h> 222aceefefSIan Molton 2301e097d6SMark Brown #include "wm9705.h" 2401e097d6SMark Brown 256e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID 0x574d4c05 266e0b73a0SLars-Peter Clausen #define WM9705_VENDOR_ID_MASK 0xffffffff 276e0b73a0SLars-Peter Clausen 282aceefefSIan Molton /* 292aceefefSIan Molton * WM9705 register cache 302aceefefSIan Molton */ 312aceefefSIan Molton static const u16 wm9705_reg[] = { 322aceefefSIan Molton 0x6150, 0x8000, 0x8000, 0x8000, /* 0x0 */ 332aceefefSIan Molton 0x0000, 0x8000, 0x8008, 0x8008, /* 0x8 */ 342aceefefSIan Molton 0x8808, 0x8808, 0x8808, 0x8808, /* 0x10 */ 352aceefefSIan Molton 0x8808, 0x0000, 0x8000, 0x0000, /* 0x18 */ 362aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x000f, /* 0x20 */ 372aceefefSIan Molton 0x0605, 0x0000, 0xbb80, 0x0000, /* 0x28 */ 382aceefefSIan Molton 0x0000, 0xbb80, 0x0000, 0x0000, /* 0x30 */ 392aceefefSIan Molton 0x0000, 0x2000, 0x0000, 0x0000, /* 0x38 */ 402aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x40 */ 412aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x48 */ 422aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x50 */ 432aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x58 */ 442aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x60 */ 452aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x68 */ 462aceefefSIan Molton 0x0000, 0x0808, 0x0000, 0x0006, /* 0x70 */ 472aceefefSIan Molton 0x0000, 0x0000, 0x574d, 0x4c05, /* 0x78 */ 482aceefefSIan Molton }; 492aceefefSIan Molton 502aceefefSIan Molton static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = { 512aceefefSIan Molton SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1), 522aceefefSIan Molton SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1), 532aceefefSIan Molton SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), 542aceefefSIan Molton SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1), 552aceefefSIan Molton SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), 562aceefefSIan Molton SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1), 572aceefefSIan Molton SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), 582aceefefSIan Molton SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), 592aceefefSIan Molton SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1), 602aceefefSIan Molton SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1), 612aceefefSIan Molton SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1), 622aceefefSIan Molton SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1), 632aceefefSIan Molton SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1), 642aceefefSIan Molton SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0), 65927b0aeaSIan Molton SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0), 66927b0aeaSIan Molton SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), 672aceefefSIan Molton }; 682aceefefSIan Molton 692aceefefSIan Molton static const char *wm9705_mic[] = {"Mic 1", "Mic 2"}; 702aceefefSIan Molton static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC", 712aceefefSIan Molton "Line", "Stereo Mix", "Mono Mix", "Phone"}; 722aceefefSIan Molton 7309981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_mic, 7409981dcbSTakashi Iwai AC97_GENERAL_PURPOSE, 8, wm9705_mic); 7509981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_l, 7609981dcbSTakashi Iwai AC97_REC_SEL, 8, wm9705_rec_sel); 7709981dcbSTakashi Iwai static SOC_ENUM_SINGLE_DECL(wm9705_enum_rec_r, 7809981dcbSTakashi Iwai AC97_REC_SEL, 0, wm9705_rec_sel); 792aceefefSIan Molton 802aceefefSIan Molton /* Headphone Mixer */ 812aceefefSIan Molton static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = { 822aceefefSIan Molton SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1), 832aceefefSIan Molton SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1), 842aceefefSIan Molton SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1), 852aceefefSIan Molton SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1), 862aceefefSIan Molton SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1), 872aceefefSIan Molton }; 882aceefefSIan Molton 892aceefefSIan Molton /* Mic source */ 902aceefefSIan Molton static const struct snd_kcontrol_new wm9705_mic_src_controls = 912aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_mic); 922aceefefSIan Molton 932aceefefSIan Molton /* Capture source */ 942aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectl_controls = 952aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_l); 962aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectr_controls = 972aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_r); 982aceefefSIan Molton 992aceefefSIan Molton /* DAPM widgets */ 1002aceefefSIan Molton static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = { 1012aceefefSIan Molton SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0, 1022aceefefSIan Molton &wm9705_mic_src_controls), 1032aceefefSIan Molton SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, 1042aceefefSIan Molton &wm9705_capture_selectl_controls), 1052aceefefSIan Molton SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, 1062aceefefSIan Molton &wm9705_capture_selectr_controls), 1072aceefefSIan Molton SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", 1082aceefefSIan Molton SND_SOC_NOPM, 0, 0), 1092aceefefSIan Molton SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", 1102aceefefSIan Molton SND_SOC_NOPM, 0, 0), 1112aceefefSIan Molton SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0, 1122aceefefSIan Molton &wm9705_hp_mixer_controls[0], 1132aceefefSIan Molton ARRAY_SIZE(wm9705_hp_mixer_controls)), 1142aceefefSIan Molton SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 1152aceefefSIan Molton SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), 1162aceefefSIan Molton SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), 1172aceefefSIan Molton SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1182aceefefSIan Molton SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1192aceefefSIan Molton SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1202aceefefSIan Molton SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1212aceefefSIan Molton SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1222aceefefSIan Molton SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1232aceefefSIan Molton SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1242aceefefSIan Molton SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1252aceefefSIan Molton SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1262aceefefSIan Molton SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1272aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTL"), 1282aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTR"), 1292aceefefSIan Molton SND_SOC_DAPM_OUTPUT("LOUT"), 1302aceefefSIan Molton SND_SOC_DAPM_OUTPUT("ROUT"), 1312aceefefSIan Molton SND_SOC_DAPM_OUTPUT("MONOOUT"), 1322aceefefSIan Molton SND_SOC_DAPM_INPUT("PHONE"), 1332aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINL"), 1342aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINR"), 1352aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINL"), 1362aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINR"), 1372aceefefSIan Molton SND_SOC_DAPM_INPUT("PCBEEP"), 1382aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC1"), 1392aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC2"), 1402aceefefSIan Molton }; 1412aceefefSIan Molton 1422aceefefSIan Molton /* Audio map 1432aceefefSIan Molton * WM9705 has no switches to disable the route from the inputs to the HP mixer 1442aceefefSIan Molton * so in order to prevent active inputs from forcing the audio outputs to be 1452aceefefSIan Molton * constantly enabled, we use the mutes on those inputs to simulate such 1462aceefefSIan Molton * controls. 1472aceefefSIan Molton */ 14897a58d6eSLu Guanqun static const struct snd_soc_dapm_route wm9705_audio_map[] = { 1492aceefefSIan Molton /* HP mixer */ 1502aceefefSIan Molton {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"}, 1512aceefefSIan Molton {"HP Mixer", "CD Playback Switch", "CD PGA"}, 1522aceefefSIan Molton {"HP Mixer", "Mic Playback Switch", "Mic PGA"}, 1532aceefefSIan Molton {"HP Mixer", "Phone Playback Switch", "Phone PGA"}, 1542aceefefSIan Molton {"HP Mixer", "Line Playback Switch", "Line PGA"}, 1552aceefefSIan Molton {"HP Mixer", NULL, "Left DAC"}, 1562aceefefSIan Molton {"HP Mixer", NULL, "Right DAC"}, 1572aceefefSIan Molton 1582aceefefSIan Molton /* mono mixer */ 1592aceefefSIan Molton {"Mono Mixer", NULL, "HP Mixer"}, 1602aceefefSIan Molton 1612aceefefSIan Molton /* outputs */ 1622aceefefSIan Molton {"Headphone PGA", NULL, "HP Mixer"}, 1632aceefefSIan Molton {"HPOUTL", NULL, "Headphone PGA"}, 1642aceefefSIan Molton {"HPOUTR", NULL, "Headphone PGA"}, 1652aceefefSIan Molton {"Line out PGA", NULL, "HP Mixer"}, 1662aceefefSIan Molton {"LOUT", NULL, "Line out PGA"}, 1672aceefefSIan Molton {"ROUT", NULL, "Line out PGA"}, 1682aceefefSIan Molton {"Mono PGA", NULL, "Mono Mixer"}, 1692aceefefSIan Molton {"MONOOUT", NULL, "Mono PGA"}, 1702aceefefSIan Molton 1712aceefefSIan Molton /* inputs */ 1722aceefefSIan Molton {"CD PGA", NULL, "CDINL"}, 1732aceefefSIan Molton {"CD PGA", NULL, "CDINR"}, 1742aceefefSIan Molton {"Line PGA", NULL, "LINEINL"}, 1752aceefefSIan Molton {"Line PGA", NULL, "LINEINR"}, 1762aceefefSIan Molton {"Phone PGA", NULL, "PHONE"}, 1772aceefefSIan Molton {"Mic Source", "Mic 1", "MIC1"}, 1782aceefefSIan Molton {"Mic Source", "Mic 2", "MIC2"}, 1792aceefefSIan Molton {"Mic PGA", NULL, "Mic Source"}, 1802aceefefSIan Molton {"PCBEEP PGA", NULL, "PCBEEP"}, 1812aceefefSIan Molton 1822aceefefSIan Molton /* Left capture selector */ 1832aceefefSIan Molton {"Left Capture Source", "Mic", "Mic Source"}, 1842aceefefSIan Molton {"Left Capture Source", "CD", "CDINL"}, 1852aceefefSIan Molton {"Left Capture Source", "Line", "LINEINL"}, 1862aceefefSIan Molton {"Left Capture Source", "Stereo Mix", "HP Mixer"}, 1872aceefefSIan Molton {"Left Capture Source", "Mono Mix", "HP Mixer"}, 1882aceefefSIan Molton {"Left Capture Source", "Phone", "PHONE"}, 1892aceefefSIan Molton 1902aceefefSIan Molton /* Right capture source */ 1912aceefefSIan Molton {"Right Capture Source", "Mic", "Mic Source"}, 1922aceefefSIan Molton {"Right Capture Source", "CD", "CDINR"}, 1932aceefefSIan Molton {"Right Capture Source", "Line", "LINEINR"}, 1942aceefefSIan Molton {"Right Capture Source", "Stereo Mix", "HP Mixer"}, 1952aceefefSIan Molton {"Right Capture Source", "Mono Mix", "HP Mixer"}, 1962aceefefSIan Molton {"Right Capture Source", "Phone", "PHONE"}, 1972aceefefSIan Molton 1982aceefefSIan Molton {"ADC PGA", NULL, "Left Capture Source"}, 1992aceefefSIan Molton {"ADC PGA", NULL, "Right Capture Source"}, 2002aceefefSIan Molton 2012aceefefSIan Molton /* ADC's */ 2022aceefefSIan Molton {"Left ADC", NULL, "ADC PGA"}, 2032aceefefSIan Molton {"Right ADC", NULL, "ADC PGA"}, 2042aceefefSIan Molton }; 2052aceefefSIan Molton 2062aceefefSIan Molton /* We use a register cache to enhance read performance. */ 2072aceefefSIan Molton static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg) 2082aceefefSIan Molton { 209358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 2102aceefefSIan Molton u16 *cache = codec->reg_cache; 2112aceefefSIan Molton 2122aceefefSIan Molton switch (reg) { 2132aceefefSIan Molton case AC97_RESET: 2142aceefefSIan Molton case AC97_VENDOR_ID1: 2152aceefefSIan Molton case AC97_VENDOR_ID2: 216358a8bb5SLars-Peter Clausen return soc_ac97_ops->read(ac97, reg); 2172aceefefSIan Molton default: 2182aceefefSIan Molton reg = reg >> 1; 2192aceefefSIan Molton 2202aceefefSIan Molton if (reg >= (ARRAY_SIZE(wm9705_reg))) 2212aceefefSIan Molton return -EIO; 2222aceefefSIan Molton 2232aceefefSIan Molton return cache[reg]; 2242aceefefSIan Molton } 2252aceefefSIan Molton } 2262aceefefSIan Molton 2272aceefefSIan Molton static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, 2282aceefefSIan Molton unsigned int val) 2292aceefefSIan Molton { 230358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 2312aceefefSIan Molton u16 *cache = codec->reg_cache; 2322aceefefSIan Molton 233358a8bb5SLars-Peter Clausen soc_ac97_ops->write(ac97, reg, val); 2342aceefefSIan Molton reg = reg >> 1; 2352aceefefSIan Molton if (reg < (ARRAY_SIZE(wm9705_reg))) 2362aceefefSIan Molton cache[reg] = val; 2372aceefefSIan Molton 2382aceefefSIan Molton return 0; 2392aceefefSIan Molton } 2402aceefefSIan Molton 2412aceefefSIan Molton static int ac97_prepare(struct snd_pcm_substream *substream, 2422aceefefSIan Molton struct snd_soc_dai *dai) 2432aceefefSIan Molton { 244e6968a17SMark Brown struct snd_soc_codec *codec = dai->codec; 2452aceefefSIan Molton int reg; 2462aceefefSIan Molton u16 vra; 2472aceefefSIan Molton 2482aceefefSIan Molton vra = ac97_read(codec, AC97_EXTENDED_STATUS); 2492aceefefSIan Molton ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); 2502aceefefSIan Molton 2512aceefefSIan Molton if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 2522aceefefSIan Molton reg = AC97_PCM_FRONT_DAC_RATE; 2532aceefefSIan Molton else 2542aceefefSIan Molton reg = AC97_PCM_LR_ADC_RATE; 2552aceefefSIan Molton 256019ec505SFabio Estevam return ac97_write(codec, reg, substream->runtime->rate); 2572aceefefSIan Molton } 2582aceefefSIan Molton 2592aceefefSIan Molton #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ 2602aceefefSIan Molton SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ 2612aceefefSIan Molton SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ 2622aceefefSIan Molton SNDRV_PCM_RATE_48000) 2632aceefefSIan Molton 26485e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9705_dai_ops = { 2656335d055SEric Miao .prepare = ac97_prepare, 2666335d055SEric Miao }; 2676335d055SEric Miao 268f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm9705_dai[] = { 2692aceefefSIan Molton { 270f0fba2adSLiam Girdwood .name = "wm9705-hifi", 2712aceefefSIan Molton .playback = { 2722aceefefSIan Molton .stream_name = "HiFi Playback", 2732aceefefSIan Molton .channels_min = 1, 2742aceefefSIan Molton .channels_max = 2, 2752aceefefSIan Molton .rates = WM9705_AC97_RATES, 27633f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS, 2772aceefefSIan Molton }, 2782aceefefSIan Molton .capture = { 2792aceefefSIan Molton .stream_name = "HiFi Capture", 2802aceefefSIan Molton .channels_min = 1, 2812aceefefSIan Molton .channels_max = 2, 2822aceefefSIan Molton .rates = WM9705_AC97_RATES, 28333f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS, 2842aceefefSIan Molton }, 2856335d055SEric Miao .ops = &wm9705_dai_ops, 2862aceefefSIan Molton }, 2872aceefefSIan Molton { 288f0fba2adSLiam Girdwood .name = "wm9705-aux", 2892aceefefSIan Molton .playback = { 2902aceefefSIan Molton .stream_name = "Aux Playback", 2912aceefefSIan Molton .channels_min = 1, 2922aceefefSIan Molton .channels_max = 1, 2932aceefefSIan Molton .rates = WM9705_AC97_RATES, 2942aceefefSIan Molton .formats = SNDRV_PCM_FMTBIT_S16_LE, 2952aceefefSIan Molton }, 2962aceefefSIan Molton } 2972aceefefSIan Molton }; 2982aceefefSIan Molton 2990a11b168SMark Brown #ifdef CONFIG_PM 30084b315eeSLars-Peter Clausen static int wm9705_soc_suspend(struct snd_soc_codec *codec) 3010a11b168SMark Brown { 302358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 303358a8bb5SLars-Peter Clausen 304358a8bb5SLars-Peter Clausen soc_ac97_ops->write(ac97, AC97_POWERDOWN, 0xffff); 3050a11b168SMark Brown 3060a11b168SMark Brown return 0; 3070a11b168SMark Brown } 3080a11b168SMark Brown 309f0fba2adSLiam Girdwood static int wm9705_soc_resume(struct snd_soc_codec *codec) 3100a11b168SMark Brown { 311358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 3120a11b168SMark Brown int i, ret; 3130a11b168SMark Brown u16 *cache = codec->reg_cache; 3140a11b168SMark Brown 3156e0b73a0SLars-Peter Clausen ret = snd_ac97_reset(ac97, true, WM9705_VENDOR_ID, 3166e0b73a0SLars-Peter Clausen WM9705_VENDOR_ID_MASK); 3179cf766f6SLars-Peter Clausen if (ret < 0) 3180a11b168SMark Brown return ret; 3190a11b168SMark Brown 3200a11b168SMark Brown for (i = 2; i < ARRAY_SIZE(wm9705_reg) << 1; i += 2) { 321358a8bb5SLars-Peter Clausen soc_ac97_ops->write(ac97, i, cache[i>>1]); 3220a11b168SMark Brown } 3230a11b168SMark Brown 3240a11b168SMark Brown return 0; 3250a11b168SMark Brown } 3260a11b168SMark Brown #else 3270a11b168SMark Brown #define wm9705_soc_suspend NULL 3280a11b168SMark Brown #define wm9705_soc_resume NULL 3290a11b168SMark Brown #endif 3300a11b168SMark Brown 331f0fba2adSLiam Girdwood static int wm9705_soc_probe(struct snd_soc_codec *codec) 3322aceefefSIan Molton { 333358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97; 3342aceefefSIan Molton 3356e0b73a0SLars-Peter Clausen ac97 = snd_soc_new_ac97_codec(codec, WM9705_VENDOR_ID, 3366e0b73a0SLars-Peter Clausen WM9705_VENDOR_ID_MASK); 337358a8bb5SLars-Peter Clausen if (IS_ERR(ac97)) { 3389cf766f6SLars-Peter Clausen dev_err(codec->dev, "Failed to register AC97 codec\n"); 3396e0b73a0SLars-Peter Clausen return PTR_ERR(ac97); 3402aceefefSIan Molton } 3412aceefefSIan Molton 342f8d71be5SLars-Peter Clausen snd_soc_codec_set_drvdata(codec, ac97); 3432aceefefSIan Molton 3442aceefefSIan Molton return 0; 3452aceefefSIan Molton } 3462aceefefSIan Molton 347f0fba2adSLiam Girdwood static int wm9705_soc_remove(struct snd_soc_codec *codec) 3482aceefefSIan Molton { 349358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97 = snd_soc_codec_get_drvdata(codec); 350358a8bb5SLars-Peter Clausen 351358a8bb5SLars-Peter Clausen snd_soc_free_ac97_codec(ac97); 3522aceefefSIan Molton return 0; 3532aceefefSIan Molton } 3542aceefefSIan Molton 355f0fba2adSLiam Girdwood static struct snd_soc_codec_driver soc_codec_dev_wm9705 = { 3562aceefefSIan Molton .probe = wm9705_soc_probe, 3572aceefefSIan Molton .remove = wm9705_soc_remove, 3580a11b168SMark Brown .suspend = wm9705_soc_suspend, 3590a11b168SMark Brown .resume = wm9705_soc_resume, 360f0fba2adSLiam Girdwood .read = ac97_read, 361f0fba2adSLiam Girdwood .write = ac97_write, 362e5eec34cSDimitris Papastamos .reg_cache_size = ARRAY_SIZE(wm9705_reg), 363f0fba2adSLiam Girdwood .reg_word_size = sizeof(u16), 364f0fba2adSLiam Girdwood .reg_cache_step = 2, 365f0fba2adSLiam Girdwood .reg_cache_default = wm9705_reg, 366d7cabb08SLars-Peter Clausen 367d7cabb08SLars-Peter Clausen .controls = wm9705_snd_ac97_controls, 368d7cabb08SLars-Peter Clausen .num_controls = ARRAY_SIZE(wm9705_snd_ac97_controls), 36997a58d6eSLu Guanqun .dapm_widgets = wm9705_dapm_widgets, 37097a58d6eSLu Guanqun .num_dapm_widgets = ARRAY_SIZE(wm9705_dapm_widgets), 37197a58d6eSLu Guanqun .dapm_routes = wm9705_audio_map, 37297a58d6eSLu Guanqun .num_dapm_routes = ARRAY_SIZE(wm9705_audio_map), 3732aceefefSIan Molton }; 374f0fba2adSLiam Girdwood 3757a79e94eSBill Pemberton static int wm9705_probe(struct platform_device *pdev) 376f0fba2adSLiam Girdwood { 377f0fba2adSLiam Girdwood return snd_soc_register_codec(&pdev->dev, 378f0fba2adSLiam Girdwood &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai)); 379f0fba2adSLiam Girdwood } 380f0fba2adSLiam Girdwood 3817a79e94eSBill Pemberton static int wm9705_remove(struct platform_device *pdev) 382f0fba2adSLiam Girdwood { 383f0fba2adSLiam Girdwood snd_soc_unregister_codec(&pdev->dev); 384f0fba2adSLiam Girdwood return 0; 385f0fba2adSLiam Girdwood } 386f0fba2adSLiam Girdwood 387f0fba2adSLiam Girdwood static struct platform_driver wm9705_codec_driver = { 388f0fba2adSLiam Girdwood .driver = { 389f0fba2adSLiam Girdwood .name = "wm9705-codec", 390f0fba2adSLiam Girdwood }, 391f0fba2adSLiam Girdwood 392f0fba2adSLiam Girdwood .probe = wm9705_probe, 3937a79e94eSBill Pemberton .remove = wm9705_remove, 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