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 #include <sound/soc-dapm.h> 232aceefefSIan Molton 2401e097d6SMark Brown #include "wm9705.h" 2501e097d6SMark Brown 262aceefefSIan Molton /* 272aceefefSIan Molton * WM9705 register cache 282aceefefSIan Molton */ 292aceefefSIan Molton static const u16 wm9705_reg[] = { 302aceefefSIan Molton 0x6150, 0x8000, 0x8000, 0x8000, /* 0x0 */ 312aceefefSIan Molton 0x0000, 0x8000, 0x8008, 0x8008, /* 0x8 */ 322aceefefSIan Molton 0x8808, 0x8808, 0x8808, 0x8808, /* 0x10 */ 332aceefefSIan Molton 0x8808, 0x0000, 0x8000, 0x0000, /* 0x18 */ 342aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x000f, /* 0x20 */ 352aceefefSIan Molton 0x0605, 0x0000, 0xbb80, 0x0000, /* 0x28 */ 362aceefefSIan Molton 0x0000, 0xbb80, 0x0000, 0x0000, /* 0x30 */ 372aceefefSIan Molton 0x0000, 0x2000, 0x0000, 0x0000, /* 0x38 */ 382aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x40 */ 392aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x48 */ 402aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x50 */ 412aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x58 */ 422aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x60 */ 432aceefefSIan Molton 0x0000, 0x0000, 0x0000, 0x0000, /* 0x68 */ 442aceefefSIan Molton 0x0000, 0x0808, 0x0000, 0x0006, /* 0x70 */ 452aceefefSIan Molton 0x0000, 0x0000, 0x574d, 0x4c05, /* 0x78 */ 462aceefefSIan Molton }; 472aceefefSIan Molton 482aceefefSIan Molton static const struct snd_kcontrol_new wm9705_snd_ac97_controls[] = { 492aceefefSIan Molton SOC_DOUBLE("Master Playback Volume", AC97_MASTER, 8, 0, 31, 1), 502aceefefSIan Molton SOC_SINGLE("Master Playback Switch", AC97_MASTER, 15, 1, 1), 512aceefefSIan Molton SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), 522aceefefSIan Molton SOC_SINGLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 1, 1), 532aceefefSIan Molton SOC_DOUBLE("PCM Playback Volume", AC97_PCM, 8, 0, 31, 1), 542aceefefSIan Molton SOC_SINGLE("PCM Playback Switch", AC97_PCM, 15, 1, 1), 552aceefefSIan Molton SOC_SINGLE("Mono Playback Volume", AC97_MASTER_MONO, 0, 31, 1), 562aceefefSIan Molton SOC_SINGLE("Mono Playback Switch", AC97_MASTER_MONO, 15, 1, 1), 572aceefefSIan Molton SOC_SINGLE("PCBeep Playback Volume", AC97_PC_BEEP, 1, 15, 1), 582aceefefSIan Molton SOC_SINGLE("Phone Playback Volume", AC97_PHONE, 0, 31, 1), 592aceefefSIan Molton SOC_DOUBLE("Line Playback Volume", AC97_LINE, 8, 0, 31, 1), 602aceefefSIan Molton SOC_DOUBLE("CD Playback Volume", AC97_CD, 8, 0, 31, 1), 612aceefefSIan Molton SOC_SINGLE("Mic Playback Volume", AC97_MIC, 0, 31, 1), 622aceefefSIan Molton SOC_SINGLE("Mic 20dB Boost Switch", AC97_MIC, 6, 1, 0), 63927b0aeaSIan Molton SOC_DOUBLE("Capture Volume", AC97_REC_GAIN, 8, 0, 15, 0), 64927b0aeaSIan Molton SOC_SINGLE("Capture Switch", AC97_REC_GAIN, 15, 1, 1), 652aceefefSIan Molton }; 662aceefefSIan Molton 672aceefefSIan Molton static const char *wm9705_mic[] = {"Mic 1", "Mic 2"}; 682aceefefSIan Molton static const char *wm9705_rec_sel[] = {"Mic", "CD", "NC", "NC", 692aceefefSIan Molton "Line", "Stereo Mix", "Mono Mix", "Phone"}; 702aceefefSIan Molton 712aceefefSIan Molton static const struct soc_enum wm9705_enum_mic = 722aceefefSIan Molton SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 8, 2, wm9705_mic); 732aceefefSIan Molton static const struct soc_enum wm9705_enum_rec_l = 742aceefefSIan Molton SOC_ENUM_SINGLE(AC97_REC_SEL, 8, 8, wm9705_rec_sel); 752aceefefSIan Molton static const struct soc_enum wm9705_enum_rec_r = 762aceefefSIan Molton SOC_ENUM_SINGLE(AC97_REC_SEL, 0, 8, wm9705_rec_sel); 772aceefefSIan Molton 782aceefefSIan Molton /* Headphone Mixer */ 792aceefefSIan Molton static const struct snd_kcontrol_new wm9705_hp_mixer_controls[] = { 802aceefefSIan Molton SOC_DAPM_SINGLE("PCBeep Playback Switch", AC97_PC_BEEP, 15, 1, 1), 812aceefefSIan Molton SOC_DAPM_SINGLE("CD Playback Switch", AC97_CD, 15, 1, 1), 822aceefefSIan Molton SOC_DAPM_SINGLE("Mic Playback Switch", AC97_MIC, 15, 1, 1), 832aceefefSIan Molton SOC_DAPM_SINGLE("Phone Playback Switch", AC97_PHONE, 15, 1, 1), 842aceefefSIan Molton SOC_DAPM_SINGLE("Line Playback Switch", AC97_LINE, 15, 1, 1), 852aceefefSIan Molton }; 862aceefefSIan Molton 872aceefefSIan Molton /* Mic source */ 882aceefefSIan Molton static const struct snd_kcontrol_new wm9705_mic_src_controls = 892aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_mic); 902aceefefSIan Molton 912aceefefSIan Molton /* Capture source */ 922aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectl_controls = 932aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_l); 942aceefefSIan Molton static const struct snd_kcontrol_new wm9705_capture_selectr_controls = 952aceefefSIan Molton SOC_DAPM_ENUM("Route", wm9705_enum_rec_r); 962aceefefSIan Molton 972aceefefSIan Molton /* DAPM widgets */ 982aceefefSIan Molton static const struct snd_soc_dapm_widget wm9705_dapm_widgets[] = { 992aceefefSIan Molton SND_SOC_DAPM_MUX("Mic Source", SND_SOC_NOPM, 0, 0, 1002aceefefSIan Molton &wm9705_mic_src_controls), 1012aceefefSIan Molton SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, 1022aceefefSIan Molton &wm9705_capture_selectl_controls), 1032aceefefSIan Molton SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, 1042aceefefSIan Molton &wm9705_capture_selectr_controls), 1052aceefefSIan Molton SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", 1062aceefefSIan Molton SND_SOC_NOPM, 0, 0), 1072aceefefSIan Molton SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", 1082aceefefSIan Molton SND_SOC_NOPM, 0, 0), 1092aceefefSIan Molton SND_SOC_DAPM_MIXER_NAMED_CTL("HP Mixer", SND_SOC_NOPM, 0, 0, 1102aceefefSIan Molton &wm9705_hp_mixer_controls[0], 1112aceefefSIan Molton ARRAY_SIZE(wm9705_hp_mixer_controls)), 1122aceefefSIan Molton SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 1132aceefefSIan Molton SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), 1142aceefefSIan Molton SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), 1152aceefefSIan Molton SND_SOC_DAPM_PGA("Headphone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1162aceefefSIan Molton SND_SOC_DAPM_PGA("Speaker PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1172aceefefSIan Molton SND_SOC_DAPM_PGA("Line PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1182aceefefSIan Molton SND_SOC_DAPM_PGA("Line out PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1192aceefefSIan Molton SND_SOC_DAPM_PGA("Mono PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1202aceefefSIan Molton SND_SOC_DAPM_PGA("Phone PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1212aceefefSIan Molton SND_SOC_DAPM_PGA("Mic PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1222aceefefSIan Molton SND_SOC_DAPM_PGA("PCBEEP PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1232aceefefSIan Molton SND_SOC_DAPM_PGA("CD PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1242aceefefSIan Molton SND_SOC_DAPM_PGA("ADC PGA", SND_SOC_NOPM, 0, 0, NULL, 0), 1252aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTL"), 1262aceefefSIan Molton SND_SOC_DAPM_OUTPUT("HPOUTR"), 1272aceefefSIan Molton SND_SOC_DAPM_OUTPUT("LOUT"), 1282aceefefSIan Molton SND_SOC_DAPM_OUTPUT("ROUT"), 1292aceefefSIan Molton SND_SOC_DAPM_OUTPUT("MONOOUT"), 1302aceefefSIan Molton SND_SOC_DAPM_INPUT("PHONE"), 1312aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINL"), 1322aceefefSIan Molton SND_SOC_DAPM_INPUT("LINEINR"), 1332aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINL"), 1342aceefefSIan Molton SND_SOC_DAPM_INPUT("CDINR"), 1352aceefefSIan Molton SND_SOC_DAPM_INPUT("PCBEEP"), 1362aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC1"), 1372aceefefSIan Molton SND_SOC_DAPM_INPUT("MIC2"), 1382aceefefSIan Molton }; 1392aceefefSIan Molton 1402aceefefSIan Molton /* Audio map 1412aceefefSIan Molton * WM9705 has no switches to disable the route from the inputs to the HP mixer 1422aceefefSIan Molton * so in order to prevent active inputs from forcing the audio outputs to be 1432aceefefSIan Molton * constantly enabled, we use the mutes on those inputs to simulate such 1442aceefefSIan Molton * controls. 1452aceefefSIan Molton */ 1462aceefefSIan Molton static const struct snd_soc_dapm_route audio_map[] = { 1472aceefefSIan Molton /* HP mixer */ 1482aceefefSIan Molton {"HP Mixer", "PCBeep Playback Switch", "PCBEEP PGA"}, 1492aceefefSIan Molton {"HP Mixer", "CD Playback Switch", "CD PGA"}, 1502aceefefSIan Molton {"HP Mixer", "Mic Playback Switch", "Mic PGA"}, 1512aceefefSIan Molton {"HP Mixer", "Phone Playback Switch", "Phone PGA"}, 1522aceefefSIan Molton {"HP Mixer", "Line Playback Switch", "Line PGA"}, 1532aceefefSIan Molton {"HP Mixer", NULL, "Left DAC"}, 1542aceefefSIan Molton {"HP Mixer", NULL, "Right DAC"}, 1552aceefefSIan Molton 1562aceefefSIan Molton /* mono mixer */ 1572aceefefSIan Molton {"Mono Mixer", NULL, "HP Mixer"}, 1582aceefefSIan Molton 1592aceefefSIan Molton /* outputs */ 1602aceefefSIan Molton {"Headphone PGA", NULL, "HP Mixer"}, 1612aceefefSIan Molton {"HPOUTL", NULL, "Headphone PGA"}, 1622aceefefSIan Molton {"HPOUTR", NULL, "Headphone PGA"}, 1632aceefefSIan Molton {"Line out PGA", NULL, "HP Mixer"}, 1642aceefefSIan Molton {"LOUT", NULL, "Line out PGA"}, 1652aceefefSIan Molton {"ROUT", NULL, "Line out PGA"}, 1662aceefefSIan Molton {"Mono PGA", NULL, "Mono Mixer"}, 1672aceefefSIan Molton {"MONOOUT", NULL, "Mono PGA"}, 1682aceefefSIan Molton 1692aceefefSIan Molton /* inputs */ 1702aceefefSIan Molton {"CD PGA", NULL, "CDINL"}, 1712aceefefSIan Molton {"CD PGA", NULL, "CDINR"}, 1722aceefefSIan Molton {"Line PGA", NULL, "LINEINL"}, 1732aceefefSIan Molton {"Line PGA", NULL, "LINEINR"}, 1742aceefefSIan Molton {"Phone PGA", NULL, "PHONE"}, 1752aceefefSIan Molton {"Mic Source", "Mic 1", "MIC1"}, 1762aceefefSIan Molton {"Mic Source", "Mic 2", "MIC2"}, 1772aceefefSIan Molton {"Mic PGA", NULL, "Mic Source"}, 1782aceefefSIan Molton {"PCBEEP PGA", NULL, "PCBEEP"}, 1792aceefefSIan Molton 1802aceefefSIan Molton /* Left capture selector */ 1812aceefefSIan Molton {"Left Capture Source", "Mic", "Mic Source"}, 1822aceefefSIan Molton {"Left Capture Source", "CD", "CDINL"}, 1832aceefefSIan Molton {"Left Capture Source", "Line", "LINEINL"}, 1842aceefefSIan Molton {"Left Capture Source", "Stereo Mix", "HP Mixer"}, 1852aceefefSIan Molton {"Left Capture Source", "Mono Mix", "HP Mixer"}, 1862aceefefSIan Molton {"Left Capture Source", "Phone", "PHONE"}, 1872aceefefSIan Molton 1882aceefefSIan Molton /* Right capture source */ 1892aceefefSIan Molton {"Right Capture Source", "Mic", "Mic Source"}, 1902aceefefSIan Molton {"Right Capture Source", "CD", "CDINR"}, 1912aceefefSIan Molton {"Right Capture Source", "Line", "LINEINR"}, 1922aceefefSIan Molton {"Right Capture Source", "Stereo Mix", "HP Mixer"}, 1932aceefefSIan Molton {"Right Capture Source", "Mono Mix", "HP Mixer"}, 1942aceefefSIan Molton {"Right Capture Source", "Phone", "PHONE"}, 1952aceefefSIan Molton 1962aceefefSIan Molton {"ADC PGA", NULL, "Left Capture Source"}, 1972aceefefSIan Molton {"ADC PGA", NULL, "Right Capture Source"}, 1982aceefefSIan Molton 1992aceefefSIan Molton /* ADC's */ 2002aceefefSIan Molton {"Left ADC", NULL, "ADC PGA"}, 2012aceefefSIan Molton {"Right ADC", NULL, "ADC PGA"}, 2022aceefefSIan Molton }; 2032aceefefSIan Molton 2042aceefefSIan Molton static int wm9705_add_widgets(struct snd_soc_codec *codec) 2052aceefefSIan Molton { 2062aceefefSIan Molton snd_soc_dapm_new_controls(codec, wm9705_dapm_widgets, 2072aceefefSIan Molton ARRAY_SIZE(wm9705_dapm_widgets)); 2082aceefefSIan Molton snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); 2092aceefefSIan Molton 2102aceefefSIan Molton return 0; 2112aceefefSIan Molton } 2122aceefefSIan Molton 2132aceefefSIan Molton /* We use a register cache to enhance read performance. */ 2142aceefefSIan Molton static unsigned int ac97_read(struct snd_soc_codec *codec, unsigned int reg) 2152aceefefSIan Molton { 2162aceefefSIan Molton u16 *cache = codec->reg_cache; 2172aceefefSIan Molton 2182aceefefSIan Molton switch (reg) { 2192aceefefSIan Molton case AC97_RESET: 2202aceefefSIan Molton case AC97_VENDOR_ID1: 2212aceefefSIan Molton case AC97_VENDOR_ID2: 2222aceefefSIan Molton return soc_ac97_ops.read(codec->ac97, reg); 2232aceefefSIan Molton default: 2242aceefefSIan Molton reg = reg >> 1; 2252aceefefSIan Molton 2262aceefefSIan Molton if (reg >= (ARRAY_SIZE(wm9705_reg))) 2272aceefefSIan Molton return -EIO; 2282aceefefSIan Molton 2292aceefefSIan Molton return cache[reg]; 2302aceefefSIan Molton } 2312aceefefSIan Molton } 2322aceefefSIan Molton 2332aceefefSIan Molton static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, 2342aceefefSIan Molton unsigned int val) 2352aceefefSIan Molton { 2362aceefefSIan Molton u16 *cache = codec->reg_cache; 2372aceefefSIan Molton 2382aceefefSIan Molton soc_ac97_ops.write(codec->ac97, reg, val); 2392aceefefSIan Molton reg = reg >> 1; 2402aceefefSIan Molton if (reg < (ARRAY_SIZE(wm9705_reg))) 2412aceefefSIan Molton cache[reg] = val; 2422aceefefSIan Molton 2432aceefefSIan Molton return 0; 2442aceefefSIan Molton } 2452aceefefSIan Molton 2462aceefefSIan Molton static int ac97_prepare(struct snd_pcm_substream *substream, 2472aceefefSIan Molton struct snd_soc_dai *dai) 2482aceefefSIan Molton { 2492aceefefSIan Molton struct snd_pcm_runtime *runtime = substream->runtime; 2502aceefefSIan Molton struct snd_soc_pcm_runtime *rtd = substream->private_data; 251f0fba2adSLiam Girdwood struct snd_soc_codec *codec = rtd->codec; 2522aceefefSIan Molton int reg; 2532aceefefSIan Molton u16 vra; 2542aceefefSIan Molton 2552aceefefSIan Molton vra = ac97_read(codec, AC97_EXTENDED_STATUS); 2562aceefefSIan Molton ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); 2572aceefefSIan Molton 2582aceefefSIan Molton if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 2592aceefefSIan Molton reg = AC97_PCM_FRONT_DAC_RATE; 2602aceefefSIan Molton else 2612aceefefSIan Molton reg = AC97_PCM_LR_ADC_RATE; 2622aceefefSIan Molton 2632aceefefSIan Molton return ac97_write(codec, reg, runtime->rate); 2642aceefefSIan Molton } 2652aceefefSIan Molton 2662aceefefSIan Molton #define WM9705_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | \ 2672aceefefSIan Molton SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \ 2682aceefefSIan Molton SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ 2692aceefefSIan Molton SNDRV_PCM_RATE_48000) 2702aceefefSIan Molton 2716335d055SEric Miao static struct snd_soc_dai_ops wm9705_dai_ops = { 2726335d055SEric Miao .prepare = ac97_prepare, 2736335d055SEric Miao }; 2746335d055SEric Miao 275f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm9705_dai[] = { 2762aceefefSIan Molton { 277f0fba2adSLiam Girdwood .name = "wm9705-hifi", 2782aceefefSIan Molton .ac97_control = 1, 2792aceefefSIan Molton .playback = { 2802aceefefSIan Molton .stream_name = "HiFi Playback", 2812aceefefSIan Molton .channels_min = 1, 2822aceefefSIan Molton .channels_max = 2, 2832aceefefSIan Molton .rates = WM9705_AC97_RATES, 28433f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS, 2852aceefefSIan Molton }, 2862aceefefSIan Molton .capture = { 2872aceefefSIan Molton .stream_name = "HiFi Capture", 2882aceefefSIan Molton .channels_min = 1, 2892aceefefSIan Molton .channels_max = 2, 2902aceefefSIan Molton .rates = WM9705_AC97_RATES, 29133f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS, 2922aceefefSIan Molton }, 2936335d055SEric Miao .ops = &wm9705_dai_ops, 2942aceefefSIan Molton }, 2952aceefefSIan Molton { 296f0fba2adSLiam Girdwood .name = "wm9705-aux", 2972aceefefSIan Molton .playback = { 2982aceefefSIan Molton .stream_name = "Aux Playback", 2992aceefefSIan Molton .channels_min = 1, 3002aceefefSIan Molton .channels_max = 1, 3012aceefefSIan Molton .rates = WM9705_AC97_RATES, 3022aceefefSIan Molton .formats = SNDRV_PCM_FMTBIT_S16_LE, 3032aceefefSIan Molton }, 3042aceefefSIan Molton } 3052aceefefSIan Molton }; 3062aceefefSIan Molton 3072aceefefSIan Molton static int wm9705_reset(struct snd_soc_codec *codec) 3082aceefefSIan Molton { 3092aceefefSIan Molton if (soc_ac97_ops.reset) { 3102aceefefSIan Molton soc_ac97_ops.reset(codec->ac97); 3112aceefefSIan Molton if (ac97_read(codec, 0) == wm9705_reg[0]) 3122aceefefSIan Molton return 0; /* Success */ 3132aceefefSIan Molton } 3142aceefefSIan Molton 3152aceefefSIan Molton return -EIO; 3162aceefefSIan Molton } 3172aceefefSIan Molton 3180a11b168SMark Brown #ifdef CONFIG_PM 319f0fba2adSLiam Girdwood static int wm9705_soc_suspend(struct snd_soc_codec *codec, pm_message_t msg) 3200a11b168SMark Brown { 3210a11b168SMark Brown soc_ac97_ops.write(codec->ac97, AC97_POWERDOWN, 0xffff); 3220a11b168SMark Brown 3230a11b168SMark Brown return 0; 3240a11b168SMark Brown } 3250a11b168SMark Brown 326f0fba2adSLiam Girdwood static int wm9705_soc_resume(struct snd_soc_codec *codec) 3270a11b168SMark Brown { 3280a11b168SMark Brown int i, ret; 3290a11b168SMark Brown u16 *cache = codec->reg_cache; 3300a11b168SMark Brown 3310a11b168SMark Brown ret = wm9705_reset(codec); 3320a11b168SMark Brown if (ret < 0) { 3330a11b168SMark Brown printk(KERN_ERR "could not reset AC97 codec\n"); 3340a11b168SMark Brown return ret; 3350a11b168SMark Brown } 3360a11b168SMark Brown 3370a11b168SMark Brown for (i = 2; i < ARRAY_SIZE(wm9705_reg) << 1; i += 2) { 3380a11b168SMark Brown soc_ac97_ops.write(codec->ac97, i, cache[i>>1]); 3390a11b168SMark Brown } 3400a11b168SMark Brown 3410a11b168SMark Brown return 0; 3420a11b168SMark Brown } 3430a11b168SMark Brown #else 3440a11b168SMark Brown #define wm9705_soc_suspend NULL 3450a11b168SMark Brown #define wm9705_soc_resume NULL 3460a11b168SMark Brown #endif 3470a11b168SMark Brown 348f0fba2adSLiam Girdwood static int wm9705_soc_probe(struct snd_soc_codec *codec) 3492aceefefSIan Molton { 3502aceefefSIan Molton int ret = 0; 3512aceefefSIan Molton 3522aceefefSIan Molton printk(KERN_INFO "WM9705 SoC Audio Codec\n"); 3532aceefefSIan Molton 3542aceefefSIan Molton ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); 3552aceefefSIan Molton if (ret < 0) { 3562aceefefSIan Molton printk(KERN_ERR "wm9705: failed to register AC97 codec\n"); 357f0fba2adSLiam Girdwood return ret; 3582aceefefSIan Molton } 3592aceefefSIan Molton 3602aceefefSIan Molton ret = wm9705_reset(codec); 3612aceefefSIan Molton if (ret) 3622aceefefSIan Molton goto reset_err; 3632aceefefSIan Molton 3642aceefefSIan Molton snd_soc_add_controls(codec, wm9705_snd_ac97_controls, 3652aceefefSIan Molton ARRAY_SIZE(wm9705_snd_ac97_controls)); 3662aceefefSIan Molton wm9705_add_widgets(codec); 3672aceefefSIan Molton 3682aceefefSIan Molton return 0; 3692aceefefSIan Molton 370a22eaf4cSTakashi Iwai reset_err: 3712aceefefSIan Molton snd_soc_free_ac97_codec(codec); 3722aceefefSIan Molton return ret; 3732aceefefSIan Molton } 3742aceefefSIan Molton 375f0fba2adSLiam Girdwood static int wm9705_soc_remove(struct snd_soc_codec *codec) 3762aceefefSIan Molton { 3772aceefefSIan Molton snd_soc_free_ac97_codec(codec); 3782aceefefSIan Molton return 0; 3792aceefefSIan Molton } 3802aceefefSIan Molton 381f0fba2adSLiam Girdwood static struct snd_soc_codec_driver soc_codec_dev_wm9705 = { 3822aceefefSIan Molton .probe = wm9705_soc_probe, 3832aceefefSIan Molton .remove = wm9705_soc_remove, 3840a11b168SMark Brown .suspend = wm9705_soc_suspend, 3850a11b168SMark Brown .resume = wm9705_soc_resume, 386f0fba2adSLiam Girdwood .read = ac97_read, 387f0fba2adSLiam Girdwood .write = ac97_write, 388e5eec34cSDimitris Papastamos .reg_cache_size = ARRAY_SIZE(wm9705_reg), 389f0fba2adSLiam Girdwood .reg_word_size = sizeof(u16), 390f0fba2adSLiam Girdwood .reg_cache_step = 2, 391f0fba2adSLiam Girdwood .reg_cache_default = wm9705_reg, 3922aceefefSIan Molton }; 393f0fba2adSLiam Girdwood 394f0fba2adSLiam Girdwood static __devinit int wm9705_probe(struct platform_device *pdev) 395f0fba2adSLiam Girdwood { 396f0fba2adSLiam Girdwood return snd_soc_register_codec(&pdev->dev, 397f0fba2adSLiam Girdwood &soc_codec_dev_wm9705, wm9705_dai, ARRAY_SIZE(wm9705_dai)); 398f0fba2adSLiam Girdwood } 399f0fba2adSLiam Girdwood 400f0fba2adSLiam Girdwood static int __devexit wm9705_remove(struct platform_device *pdev) 401f0fba2adSLiam Girdwood { 402f0fba2adSLiam Girdwood snd_soc_unregister_codec(&pdev->dev); 403f0fba2adSLiam Girdwood return 0; 404f0fba2adSLiam Girdwood } 405f0fba2adSLiam Girdwood 406f0fba2adSLiam Girdwood static struct platform_driver wm9705_codec_driver = { 407f0fba2adSLiam Girdwood .driver = { 408f0fba2adSLiam Girdwood .name = "wm9705-codec", 409f0fba2adSLiam Girdwood .owner = THIS_MODULE, 410f0fba2adSLiam Girdwood }, 411f0fba2adSLiam Girdwood 412f0fba2adSLiam Girdwood .probe = wm9705_probe, 413f0fba2adSLiam Girdwood .remove = __devexit_p(wm9705_remove), 414f0fba2adSLiam Girdwood }; 415f0fba2adSLiam Girdwood 416f0fba2adSLiam Girdwood static int __init wm9705_init(void) 417f0fba2adSLiam Girdwood { 418f0fba2adSLiam Girdwood return platform_driver_register(&wm9705_codec_driver); 419f0fba2adSLiam Girdwood } 420f0fba2adSLiam Girdwood module_init(wm9705_init); 421f0fba2adSLiam Girdwood 422f0fba2adSLiam Girdwood static void __exit wm9705_exit(void) 423f0fba2adSLiam Girdwood { 424f0fba2adSLiam Girdwood platform_driver_unregister(&wm9705_codec_driver); 425f0fba2adSLiam Girdwood } 426f0fba2adSLiam Girdwood module_exit(wm9705_exit); 4272aceefefSIan Molton 4282aceefefSIan Molton MODULE_DESCRIPTION("ASoC WM9705 driver"); 4292aceefefSIan Molton MODULE_AUTHOR("Ian Molton"); 4302aceefefSIan Molton MODULE_LICENSE("GPL v2"); 431