12874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later 283ac08c0SLiam Girdwood /* 383ac08c0SLiam Girdwood * wm9713.c -- ALSA Soc WM9713 codec support 483ac08c0SLiam Girdwood * 5656baaebSMark Brown * Copyright 2006-10 Wolfson Microelectronics PLC. 6d331124dSLiam Girdwood * Author: Liam Girdwood <lrg@slimlogic.co.uk> 783ac08c0SLiam Girdwood * 883ac08c0SLiam Girdwood * Features:- 983ac08c0SLiam Girdwood * 1083ac08c0SLiam Girdwood * o Support for AC97 Codec, Voice DAC and Aux DAC 1183ac08c0SLiam Girdwood * o Support for DAPM 1283ac08c0SLiam Girdwood */ 1383ac08c0SLiam Girdwood 1483ac08c0SLiam Girdwood #include <linux/init.h> 155a0e3ad6STejun Heo #include <linux/slab.h> 169bd400caSRobert Jarzmik #include <linux/mfd/wm97xx.h> 1783ac08c0SLiam Girdwood #include <linux/module.h> 1883ac08c0SLiam Girdwood #include <linux/device.h> 19700dadfeSRobert Jarzmik #include <linux/regmap.h> 2083ac08c0SLiam Girdwood #include <sound/core.h> 2183ac08c0SLiam Girdwood #include <sound/pcm.h> 2283ac08c0SLiam Girdwood #include <sound/ac97_codec.h> 239bd400caSRobert Jarzmik #include <sound/ac97/codec.h> 249bd400caSRobert Jarzmik #include <sound/ac97/compat.h> 2583ac08c0SLiam Girdwood #include <sound/initval.h> 2683ac08c0SLiam Girdwood #include <sound/pcm_params.h> 27e03a8d2cSMark Brown #include <sound/tlv.h> 2883ac08c0SLiam Girdwood #include <sound/soc.h> 2983ac08c0SLiam Girdwood 3083ac08c0SLiam Girdwood #include "wm9713.h" 3183ac08c0SLiam Girdwood 32310398f5SLars-Peter Clausen #define WM9713_VENDOR_ID 0x574d4c13 33310398f5SLars-Peter Clausen #define WM9713_VENDOR_ID_MASK 0xffffffff 34310398f5SLars-Peter Clausen 3583ac08c0SLiam Girdwood struct wm9713_priv { 36358a8bb5SLars-Peter Clausen struct snd_ac97 *ac97; 3783ac08c0SLiam Girdwood u32 pll_in; /* PLL input frequency */ 38cf1f2ebeSLars-Peter Clausen unsigned int hp_mixer[2]; 39cf1f2ebeSLars-Peter Clausen struct mutex lock; 409bd400caSRobert Jarzmik struct wm97xx_platform_data *mfd_pdata; 4183ac08c0SLiam Girdwood }; 4283ac08c0SLiam Girdwood 43cf1f2ebeSLars-Peter Clausen #define HPL_MIXER 0 44cf1f2ebeSLars-Peter Clausen #define HPR_MIXER 1 4583ac08c0SLiam Girdwood 4683ac08c0SLiam Girdwood static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; 4783ac08c0SLiam Girdwood static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; 4883ac08c0SLiam Girdwood static const char *wm9713_rec_src[] = 4983ac08c0SLiam Girdwood {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker", 5083ac08c0SLiam Girdwood "Mono Out", "Zh"}; 5183ac08c0SLiam Girdwood static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; 5283ac08c0SLiam Girdwood static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; 53a7f0b839SMatt Reimer static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv"}; 5483ac08c0SLiam Girdwood static const char *wm9713_spk_pga[] = 5583ac08c0SLiam Girdwood {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid", 5683ac08c0SLiam Girdwood "Speaker Vmid", "Inv Vmid"}; 5783ac08c0SLiam Girdwood static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone", 5883ac08c0SLiam Girdwood "Headphone Vmid"}; 5983ac08c0SLiam Girdwood static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"}; 6083ac08c0SLiam Girdwood static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"}; 6183ac08c0SLiam Girdwood static const char *wm9713_dac_inv[] = 6283ac08c0SLiam Girdwood {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone", 6383ac08c0SLiam Girdwood "Headphone Mono", "NC", "Vmid"}; 6483ac08c0SLiam Girdwood static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"}; 6583ac08c0SLiam Girdwood static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"}; 6683ac08c0SLiam Girdwood static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"}; 6783ac08c0SLiam Girdwood static const char *wm9713_micb_select[] = {"MPB", "MPA"}; 6883ac08c0SLiam Girdwood 6983ac08c0SLiam Girdwood static const struct soc_enum wm9713_enum[] = { 7083ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */ 7183ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */ 7283ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */ 7383ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */ 7483ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/ 7583ac08c0SLiam Girdwood SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */ 7683ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/ 7783ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */ 7883ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */ 7983ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */ 8083ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */ 8183ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */ 8283ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */ 8383ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */ 8483ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */ 8583ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */ 8683ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */ 8783ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */ 8883ac08c0SLiam Girdwood SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */ 895bc39b50SLars-Peter Clausen SOC_ENUM_SINGLE_VIRT(2, wm9713_micb_select), /* mic selection 19 */ 9083ac08c0SLiam Girdwood }; 9183ac08c0SLiam Girdwood 92e03a8d2cSMark Brown static const DECLARE_TLV_DB_SCALE(out_tlv, -4650, 150, 0); 93e03a8d2cSMark Brown static const DECLARE_TLV_DB_SCALE(main_tlv, -3450, 150, 0); 94e03a8d2cSMark Brown static const DECLARE_TLV_DB_SCALE(misc_tlv, -1500, 300, 0); 955092e76bSLars-Peter Clausen static const DECLARE_TLV_DB_RANGE(mic_tlv, 96e03a8d2cSMark Brown 0, 2, TLV_DB_SCALE_ITEM(1200, 600, 0), 975092e76bSLars-Peter Clausen 3, 3, TLV_DB_SCALE_ITEM(3000, 0, 0) 985092e76bSLars-Peter Clausen ); 99e03a8d2cSMark Brown 10083ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = { 101e03a8d2cSMark Brown SOC_DOUBLE_TLV("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1, out_tlv), 10283ac08c0SLiam Girdwood SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1), 103e03a8d2cSMark Brown SOC_DOUBLE_TLV("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1, 104e03a8d2cSMark Brown out_tlv), 10583ac08c0SLiam Girdwood SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1), 106e03a8d2cSMark Brown SOC_DOUBLE_TLV("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1, main_tlv), 107e03a8d2cSMark Brown SOC_DOUBLE_TLV("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1, main_tlv), 108e03a8d2cSMark Brown SOC_SINGLE_TLV("Mic 1 Volume", AC97_MIC, 8, 31, 1, main_tlv), 109e03a8d2cSMark Brown SOC_SINGLE_TLV("Mic 2 Volume", AC97_MIC, 0, 31, 1, main_tlv), 110e03a8d2cSMark Brown SOC_SINGLE_TLV("Mic 1 Preamp Volume", AC97_3D_CONTROL, 10, 3, 0, mic_tlv), 111e03a8d2cSMark Brown SOC_SINGLE_TLV("Mic 2 Preamp Volume", AC97_3D_CONTROL, 12, 3, 0, mic_tlv), 11283ac08c0SLiam Girdwood 11383ac08c0SLiam Girdwood SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), 11483ac08c0SLiam Girdwood SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), 11583ac08c0SLiam Girdwood 11683ac08c0SLiam Girdwood SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), 11783ac08c0SLiam Girdwood SOC_ENUM("Capture Volume Steps", wm9713_enum[5]), 11883ac08c0SLiam Girdwood SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0), 11983ac08c0SLiam Girdwood SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), 12083ac08c0SLiam Girdwood 121e03a8d2cSMark Brown SOC_SINGLE_TLV("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1, misc_tlv), 12283ac08c0SLiam Girdwood SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), 12383ac08c0SLiam Girdwood SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), 12483ac08c0SLiam Girdwood 12583ac08c0SLiam Girdwood SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), 12683ac08c0SLiam Girdwood SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), 12783ac08c0SLiam Girdwood SOC_SINGLE("ALC Decay Time", AC97_CODEC_CLASS_REV, 4, 15, 0), 12883ac08c0SLiam Girdwood SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), 12983ac08c0SLiam Girdwood SOC_ENUM("ALC Function", wm9713_enum[6]), 13083ac08c0SLiam Girdwood SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), 13183ac08c0SLiam Girdwood SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), 13283ac08c0SLiam Girdwood SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), 13383ac08c0SLiam Girdwood SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), 13483ac08c0SLiam Girdwood SOC_ENUM("ALC NG Type", wm9713_enum[17]), 13583ac08c0SLiam Girdwood SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), 13683ac08c0SLiam Girdwood 13783ac08c0SLiam Girdwood SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0), 13883ac08c0SLiam Girdwood SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), 13983ac08c0SLiam Girdwood 14083ac08c0SLiam Girdwood SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1), 14183ac08c0SLiam Girdwood SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0), 142e03a8d2cSMark Brown SOC_SINGLE_TLV("Out4 Playback Volume", AC97_MASTER_MONO, 8, 31, 1, out_tlv), 14383ac08c0SLiam Girdwood 14483ac08c0SLiam Girdwood SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1), 14583ac08c0SLiam Girdwood SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0), 146e03a8d2cSMark Brown SOC_SINGLE_TLV("Out3 Playback Volume", AC97_MASTER_MONO, 0, 31, 1, out_tlv), 14783ac08c0SLiam Girdwood 148e03a8d2cSMark Brown SOC_SINGLE_TLV("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1, main_tlv), 14983ac08c0SLiam Girdwood SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1), 15083ac08c0SLiam Girdwood SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0), 151e03a8d2cSMark Brown SOC_SINGLE_TLV("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1, out_tlv), 15283ac08c0SLiam Girdwood 153e03a8d2cSMark Brown SOC_SINGLE_TLV("Headphone Mixer Beep Playback Volume", AC97_AUX, 12, 7, 1, 154e03a8d2cSMark Brown misc_tlv), 155e03a8d2cSMark Brown SOC_SINGLE_TLV("Speaker Mixer Beep Playback Volume", AC97_AUX, 8, 7, 1, 156e03a8d2cSMark Brown misc_tlv), 157e03a8d2cSMark Brown SOC_SINGLE_TLV("Mono Mixer Beep Playback Volume", AC97_AUX, 4, 7, 1, misc_tlv), 15883ac08c0SLiam Girdwood 159e03a8d2cSMark Brown SOC_SINGLE_TLV("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1, 160e03a8d2cSMark Brown misc_tlv), 16183ac08c0SLiam Girdwood SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1), 16283ac08c0SLiam Girdwood SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1), 16383ac08c0SLiam Girdwood 164e03a8d2cSMark Brown SOC_SINGLE_TLV("Headphone Mixer Aux Playback Volume", AC97_REC_SEL, 12, 7, 1, 165e03a8d2cSMark Brown misc_tlv), 166e03a8d2cSMark Brown 167e03a8d2cSMark Brown SOC_SINGLE_TLV("Speaker Mixer Voice Playback Volume", AC97_PCM, 8, 7, 1, 168e03a8d2cSMark Brown misc_tlv), 169e03a8d2cSMark Brown SOC_SINGLE_TLV("Speaker Mixer Aux Playback Volume", AC97_REC_SEL, 8, 7, 1, 170e03a8d2cSMark Brown misc_tlv), 171e03a8d2cSMark Brown 172e03a8d2cSMark Brown SOC_SINGLE_TLV("Mono Mixer Voice Playback Volume", AC97_PCM, 4, 7, 1, 173e03a8d2cSMark Brown misc_tlv), 174e03a8d2cSMark Brown SOC_SINGLE_TLV("Mono Mixer Aux Playback Volume", AC97_REC_SEL, 4, 7, 1, 175e03a8d2cSMark Brown misc_tlv), 176e03a8d2cSMark Brown 17783ac08c0SLiam Girdwood SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1), 17883ac08c0SLiam Girdwood SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1), 17983ac08c0SLiam Girdwood 18083ac08c0SLiam Girdwood SOC_ENUM("Bass Control", wm9713_enum[16]), 18183ac08c0SLiam Girdwood SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), 18283ac08c0SLiam Girdwood SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), 18383ac08c0SLiam Girdwood SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), 18483ac08c0SLiam Girdwood SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), 18583ac08c0SLiam Girdwood SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), 18683ac08c0SLiam Girdwood 18783ac08c0SLiam Girdwood SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), 18883ac08c0SLiam Girdwood SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), 18983ac08c0SLiam Girdwood SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), 19083ac08c0SLiam Girdwood }; 19183ac08c0SLiam Girdwood 1926bbcb459SMark Brown static int wm9713_voice_shutdown(struct snd_soc_dapm_widget *w, 1936bbcb459SMark Brown struct snd_kcontrol *kcontrol, int event) 1946bbcb459SMark Brown { 1958ea99bc6SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); 1966bbcb459SMark Brown 197fb2e3e70STakashi Iwai if (WARN_ON(event != SND_SOC_DAPM_PRE_PMD)) 198fb2e3e70STakashi Iwai return -EINVAL; 1996bbcb459SMark Brown 2006bbcb459SMark Brown /* Gracefully shut down the voice interface. */ 2018ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0f00, 0x0200); 2026bbcb459SMark Brown schedule_timeout_interruptible(msecs_to_jiffies(1)); 2038ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0f00, 0x0f00); 2048ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0x1000, 0x1000); 2056bbcb459SMark Brown 2066bbcb459SMark Brown return 0; 2076bbcb459SMark Brown } 2086bbcb459SMark Brown 209cf1f2ebeSLars-Peter Clausen static const unsigned int wm9713_mixer_mute_regs[] = { 210cf1f2ebeSLars-Peter Clausen AC97_PC_BEEP, 211cf1f2ebeSLars-Peter Clausen AC97_MASTER_TONE, 212cf1f2ebeSLars-Peter Clausen AC97_PHONE, 213cf1f2ebeSLars-Peter Clausen AC97_REC_SEL, 214cf1f2ebeSLars-Peter Clausen AC97_PCM, 215cf1f2ebeSLars-Peter Clausen AC97_AUX, 216cf1f2ebeSLars-Peter Clausen }; 2176bbcb459SMark Brown 21883ac08c0SLiam Girdwood /* We have to create a fake left and right HP mixers because 21983ac08c0SLiam Girdwood * the codec only has a single control that is shared by both channels. 22083ac08c0SLiam Girdwood * This makes it impossible to determine the audio path using the current 22183ac08c0SLiam Girdwood * register map, thus we add a new (virtual) register to help determine the 22283ac08c0SLiam Girdwood * audio route within the device. 22383ac08c0SLiam Girdwood */ 224cf1f2ebeSLars-Peter Clausen static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol, 225cf1f2ebeSLars-Peter Clausen struct snd_ctl_elem_value *ucontrol) 22683ac08c0SLiam Girdwood { 227cf1f2ebeSLars-Peter Clausen struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 2288ea99bc6SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); 2298ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 23087a8b286STakashi Iwai unsigned int val = ucontrol->value.integer.value[0]; 231cf1f2ebeSLars-Peter Clausen struct soc_mixer_control *mc = 232cf1f2ebeSLars-Peter Clausen (struct soc_mixer_control *)kcontrol->private_value; 233cf1f2ebeSLars-Peter Clausen unsigned int mixer, mask, shift, old; 23491cd0008SFabio Estevam struct snd_soc_dapm_update update = {}; 235cf1f2ebeSLars-Peter Clausen bool change; 23683ac08c0SLiam Girdwood 237cf1f2ebeSLars-Peter Clausen mixer = mc->shift >> 8; 238cf1f2ebeSLars-Peter Clausen shift = mc->shift & 0xff; 239cf1f2ebeSLars-Peter Clausen mask = (1 << shift); 24083ac08c0SLiam Girdwood 241cf1f2ebeSLars-Peter Clausen mutex_lock(&wm9713->lock); 242cf1f2ebeSLars-Peter Clausen old = wm9713->hp_mixer[mixer]; 24387a8b286STakashi Iwai if (ucontrol->value.integer.value[0]) 244cf1f2ebeSLars-Peter Clausen wm9713->hp_mixer[mixer] |= mask; 24583ac08c0SLiam Girdwood else 246cf1f2ebeSLars-Peter Clausen wm9713->hp_mixer[mixer] &= ~mask; 24783ac08c0SLiam Girdwood 248cf1f2ebeSLars-Peter Clausen change = old != wm9713->hp_mixer[mixer]; 249cf1f2ebeSLars-Peter Clausen if (change) { 250cf1f2ebeSLars-Peter Clausen update.kcontrol = kcontrol; 251cf1f2ebeSLars-Peter Clausen update.reg = wm9713_mixer_mute_regs[shift]; 252cf1f2ebeSLars-Peter Clausen update.mask = 0x8000; 253cf1f2ebeSLars-Peter Clausen if ((wm9713->hp_mixer[0] & mask) || 254cf1f2ebeSLars-Peter Clausen (wm9713->hp_mixer[1] & mask)) 255cf1f2ebeSLars-Peter Clausen update.val = 0x0; 25683ac08c0SLiam Girdwood else 257cf1f2ebeSLars-Peter Clausen update.val = 0x8000; 25883ac08c0SLiam Girdwood 259cf1f2ebeSLars-Peter Clausen snd_soc_dapm_mixer_update_power(dapm, kcontrol, val, 260cf1f2ebeSLars-Peter Clausen &update); 261cf1f2ebeSLars-Peter Clausen } 26283ac08c0SLiam Girdwood 263cf1f2ebeSLars-Peter Clausen mutex_unlock(&wm9713->lock); 26483ac08c0SLiam Girdwood 265cf1f2ebeSLars-Peter Clausen return change; 266cf1f2ebeSLars-Peter Clausen } 26783ac08c0SLiam Girdwood 268cf1f2ebeSLars-Peter Clausen static int wm9713_hp_mixer_get(struct snd_kcontrol *kcontrol, 269cf1f2ebeSLars-Peter Clausen struct snd_ctl_elem_value *ucontrol) 270cf1f2ebeSLars-Peter Clausen { 271cf1f2ebeSLars-Peter Clausen struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); 2728ea99bc6SKuninori Morimoto struct snd_soc_component *component = snd_soc_dapm_to_component(dapm); 2738ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 274cf1f2ebeSLars-Peter Clausen struct soc_mixer_control *mc = 275cf1f2ebeSLars-Peter Clausen (struct soc_mixer_control *)kcontrol->private_value; 276cf1f2ebeSLars-Peter Clausen unsigned int mixer, shift; 277cf1f2ebeSLars-Peter Clausen 278cf1f2ebeSLars-Peter Clausen mixer = mc->shift >> 8; 279cf1f2ebeSLars-Peter Clausen shift = mc->shift & 0xff; 280cf1f2ebeSLars-Peter Clausen 28187a8b286STakashi Iwai ucontrol->value.integer.value[0] = 282cf1f2ebeSLars-Peter Clausen (wm9713->hp_mixer[mixer] >> shift) & 1; 28383ac08c0SLiam Girdwood 28483ac08c0SLiam Girdwood return 0; 28583ac08c0SLiam Girdwood } 28683ac08c0SLiam Girdwood 287cf1f2ebeSLars-Peter Clausen #define WM9713_HP_MIXER_CTRL(xname, xmixer, xshift) { \ 288cf1f2ebeSLars-Peter Clausen .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ 289cf1f2ebeSLars-Peter Clausen .info = snd_soc_info_volsw, \ 290cf1f2ebeSLars-Peter Clausen .get = wm9713_hp_mixer_get, .put = wm9713_hp_mixer_put, \ 291cf1f2ebeSLars-Peter Clausen .private_value = SOC_DOUBLE_VALUE(SND_SOC_NOPM, \ 292cf1f2ebeSLars-Peter Clausen xshift, xmixer, 1, 0, 0) \ 293cf1f2ebeSLars-Peter Clausen } 294cf1f2ebeSLars-Peter Clausen 29583ac08c0SLiam Girdwood /* Left Headphone Mixers */ 29683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { 297cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER, 5), 298cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER, 4), 299cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 3), 300cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 2), 301cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER, 1), 302cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER, 0), 30383ac08c0SLiam Girdwood }; 30483ac08c0SLiam Girdwood 30583ac08c0SLiam Girdwood /* Right Headphone Mixers */ 30683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { 307cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER, 5), 308cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER, 4), 309cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 3), 310cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 2), 311cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER, 1), 312cf1f2ebeSLars-Peter Clausen WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER, 0), 31383ac08c0SLiam Girdwood }; 31483ac08c0SLiam Girdwood 31583ac08c0SLiam Girdwood /* headphone capture mux */ 31683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls = 31783ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[1]); 31883ac08c0SLiam Girdwood 31983ac08c0SLiam Girdwood /* headphone mic mux */ 32083ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls = 32183ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[0]); 32283ac08c0SLiam Girdwood 32383ac08c0SLiam Girdwood /* Speaker Mixer */ 32483ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { 325d355c82aSJaroslav Kysela SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1), 32683ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1), 32783ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1), 32883ac08c0SLiam Girdwood SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), 32983ac08c0SLiam Girdwood SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1), 33083ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1), 33183ac08c0SLiam Girdwood }; 33283ac08c0SLiam Girdwood 33383ac08c0SLiam Girdwood /* Mono Mixer */ 33483ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { 335d355c82aSJaroslav Kysela SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1), 33683ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1), 33783ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1), 33883ac08c0SLiam Girdwood SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), 33983ac08c0SLiam Girdwood SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1), 34083ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1), 34183ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1), 34283ac08c0SLiam Girdwood SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1), 34383ac08c0SLiam Girdwood }; 34483ac08c0SLiam Girdwood 34583ac08c0SLiam Girdwood /* mono mic mux */ 34683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls = 34783ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[2]); 34883ac08c0SLiam Girdwood 34983ac08c0SLiam Girdwood /* mono output mux */ 35083ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_mono_mux_controls = 35183ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[7]); 35283ac08c0SLiam Girdwood 35383ac08c0SLiam Girdwood /* speaker left output mux */ 35483ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls = 35583ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[8]); 35683ac08c0SLiam Girdwood 35783ac08c0SLiam Girdwood /* speaker right output mux */ 35883ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls = 35983ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[9]); 36083ac08c0SLiam Girdwood 36183ac08c0SLiam Girdwood /* headphone left output mux */ 36283ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls = 36383ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[10]); 36483ac08c0SLiam Girdwood 36583ac08c0SLiam Girdwood /* headphone right output mux */ 36683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls = 36783ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[11]); 36883ac08c0SLiam Girdwood 36983ac08c0SLiam Girdwood /* Out3 mux */ 37083ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_out3_mux_controls = 37183ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[12]); 37283ac08c0SLiam Girdwood 37383ac08c0SLiam Girdwood /* Out4 mux */ 37483ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_out4_mux_controls = 37583ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[13]); 37683ac08c0SLiam Girdwood 37783ac08c0SLiam Girdwood /* DAC inv mux 1 */ 37883ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls = 37983ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[14]); 38083ac08c0SLiam Girdwood 38183ac08c0SLiam Girdwood /* DAC inv mux 2 */ 38283ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls = 38383ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[15]); 38483ac08c0SLiam Girdwood 38583ac08c0SLiam Girdwood /* Capture source left */ 38683ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls = 38783ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[3]); 38883ac08c0SLiam Girdwood 38983ac08c0SLiam Girdwood /* Capture source right */ 39083ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls = 39183ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[4]); 39283ac08c0SLiam Girdwood 39383ac08c0SLiam Girdwood /* mic source */ 39483ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls = 39583ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[18]); 39683ac08c0SLiam Girdwood 39783ac08c0SLiam Girdwood /* mic source B virtual control */ 39883ac08c0SLiam Girdwood static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls = 39983ac08c0SLiam Girdwood SOC_DAPM_ENUM("Route", wm9713_enum[19]); 40083ac08c0SLiam Girdwood 40183ac08c0SLiam Girdwood static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = { 40283ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0, 40383ac08c0SLiam Girdwood &wm9713_hp_rec_mux_controls), 40483ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0, 40583ac08c0SLiam Girdwood &wm9713_hp_mic_mux_controls), 40683ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0, 40783ac08c0SLiam Girdwood &wm9713_mono_mic_mux_controls), 40883ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0, 40983ac08c0SLiam Girdwood &wm9713_mono_mux_controls), 41083ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0, 41183ac08c0SLiam Girdwood &wm9713_hp_spkl_mux_controls), 41283ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0, 41383ac08c0SLiam Girdwood &wm9713_hp_spkr_mux_controls), 41483ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0, 41583ac08c0SLiam Girdwood &wm9713_hpl_out_mux_controls), 41683ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0, 41783ac08c0SLiam Girdwood &wm9713_hpr_out_mux_controls), 41883ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0, 41983ac08c0SLiam Girdwood &wm9713_out3_mux_controls), 42083ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0, 42183ac08c0SLiam Girdwood &wm9713_out4_mux_controls), 42283ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0, 42383ac08c0SLiam Girdwood &wm9713_dac_inv1_mux_controls), 42483ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0, 42583ac08c0SLiam Girdwood &wm9713_dac_inv2_mux_controls), 42683ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, 42783ac08c0SLiam Girdwood &wm9713_rec_srcl_mux_controls), 42883ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, 42983ac08c0SLiam Girdwood &wm9713_rec_srcr_mux_controls), 43083ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0, 43183ac08c0SLiam Girdwood &wm9713_mic_sel_mux_controls), 43283ac08c0SLiam Girdwood SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0, 43383ac08c0SLiam Girdwood &wm9713_micb_sel_mux_controls), 434cf1f2ebeSLars-Peter Clausen SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, 435cf1f2ebeSLars-Peter Clausen &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls)), 436cf1f2ebeSLars-Peter Clausen SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, 437cf1f2ebeSLars-Peter Clausen &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls)), 43883ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, 43983ac08c0SLiam Girdwood &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)), 44083ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, 44183ac08c0SLiam Girdwood &wm9713_speaker_mixer_controls[0], 44283ac08c0SLiam Girdwood ARRAY_SIZE(wm9713_speaker_mixer_controls)), 44383ac08c0SLiam Girdwood SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1), 44483ac08c0SLiam Girdwood SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1), 44583ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 44683ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 44783ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 44883ac08c0SLiam Girdwood SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), 4496bbcb459SMark Brown SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1, 4506bbcb459SMark Brown wm9713_voice_shutdown, SND_SOC_DAPM_PRE_PMD), 45183ac08c0SLiam Girdwood SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1), 452ccbc301eSMark Brown SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0), 453ccbc301eSMark Brown SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0), 454ccbc301eSMark Brown SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), 455ccbc301eSMark Brown SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), 456ccbc301eSMark Brown SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM, 0, 0), 457ccbc301eSMark Brown SND_SOC_DAPM_ADC("Right Voice ADC", "Right Voice Capture", SND_SOC_NOPM, 0, 0), 45883ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0), 45983ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0), 46083ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0), 46183ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0), 46283ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0), 46383ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0), 46483ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0), 46583ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0), 46683ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0), 46783ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0), 46883ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0), 46983ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0), 47083ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0), 47183ac08c0SLiam Girdwood SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0), 47283ac08c0SLiam Girdwood SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1), 47383ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("MONO"), 47483ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("HPL"), 47583ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("HPR"), 47683ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("SPKL"), 47783ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("SPKR"), 47883ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("OUT3"), 47983ac08c0SLiam Girdwood SND_SOC_DAPM_OUTPUT("OUT4"), 48083ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("LINEL"), 48183ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("LINER"), 48283ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("MONOIN"), 48383ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("PCBEEP"), 48483ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("MIC1"), 48583ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("MIC2A"), 48683ac08c0SLiam Girdwood SND_SOC_DAPM_INPUT("MIC2B"), 48783ac08c0SLiam Girdwood SND_SOC_DAPM_VMID("VMID"), 48883ac08c0SLiam Girdwood }; 48983ac08c0SLiam Girdwood 4907ad7dd12SLu Guanqun static const struct snd_soc_dapm_route wm9713_audio_map[] = { 49183ac08c0SLiam Girdwood /* left HP mixer */ 492d355c82aSJaroslav Kysela {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"}, 49383ac08c0SLiam Girdwood {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, 49483ac08c0SLiam Girdwood {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, 49583ac08c0SLiam Girdwood {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, 49683ac08c0SLiam Girdwood {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, 49783ac08c0SLiam Girdwood {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"}, 49883ac08c0SLiam Girdwood {"Left HP Mixer", NULL, "Capture Headphone Mux"}, 49983ac08c0SLiam Girdwood 50083ac08c0SLiam Girdwood /* right HP mixer */ 501d355c82aSJaroslav Kysela {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"}, 50283ac08c0SLiam Girdwood {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, 50383ac08c0SLiam Girdwood {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, 50483ac08c0SLiam Girdwood {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, 50583ac08c0SLiam Girdwood {"Right HP Mixer", "PCM Playback Switch", "Right DAC"}, 50683ac08c0SLiam Girdwood {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"}, 50783ac08c0SLiam Girdwood {"Right HP Mixer", NULL, "Capture Headphone Mux"}, 50883ac08c0SLiam Girdwood 50983ac08c0SLiam Girdwood /* virtual mixer - mixes left & right channels for spk and mono */ 51083ac08c0SLiam Girdwood {"AC97 Mixer", NULL, "Left DAC"}, 51183ac08c0SLiam Girdwood {"AC97 Mixer", NULL, "Right DAC"}, 51283ac08c0SLiam Girdwood {"Line Mixer", NULL, "Right Line In"}, 51383ac08c0SLiam Girdwood {"Line Mixer", NULL, "Left Line In"}, 51483ac08c0SLiam Girdwood {"HP Mixer", NULL, "Left HP Mixer"}, 51583ac08c0SLiam Girdwood {"HP Mixer", NULL, "Right HP Mixer"}, 51683ac08c0SLiam Girdwood {"Capture Mixer", NULL, "Left Capture Source"}, 51783ac08c0SLiam Girdwood {"Capture Mixer", NULL, "Right Capture Source"}, 51883ac08c0SLiam Girdwood 51983ac08c0SLiam Girdwood /* speaker mixer */ 520d355c82aSJaroslav Kysela {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"}, 52183ac08c0SLiam Girdwood {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, 52283ac08c0SLiam Girdwood {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, 52383ac08c0SLiam Girdwood {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, 52483ac08c0SLiam Girdwood {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"}, 52583ac08c0SLiam Girdwood {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, 52683ac08c0SLiam Girdwood 52783ac08c0SLiam Girdwood /* mono mixer */ 528d355c82aSJaroslav Kysela {"Mono Mixer", "Beep Playback Switch", "PCBEEP"}, 52983ac08c0SLiam Girdwood {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, 53083ac08c0SLiam Girdwood {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, 53183ac08c0SLiam Girdwood {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, 53283ac08c0SLiam Girdwood {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"}, 533c0bbf48dSRobert Jarzmik {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"}, 534c0bbf48dSRobert Jarzmik {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"}, 53583ac08c0SLiam Girdwood {"Mono Mixer", NULL, "Capture Mono Mux"}, 53683ac08c0SLiam Girdwood 53783ac08c0SLiam Girdwood /* DAC inv mux 1 */ 53883ac08c0SLiam Girdwood {"DAC Inv Mux 1", "Mono", "Mono Mixer"}, 53983ac08c0SLiam Girdwood {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"}, 54083ac08c0SLiam Girdwood {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"}, 54183ac08c0SLiam Girdwood {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"}, 54283ac08c0SLiam Girdwood {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"}, 54383ac08c0SLiam Girdwood 54483ac08c0SLiam Girdwood /* DAC inv mux 2 */ 54583ac08c0SLiam Girdwood {"DAC Inv Mux 2", "Mono", "Mono Mixer"}, 54683ac08c0SLiam Girdwood {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"}, 54783ac08c0SLiam Girdwood {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"}, 54883ac08c0SLiam Girdwood {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"}, 54983ac08c0SLiam Girdwood {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"}, 55083ac08c0SLiam Girdwood 55183ac08c0SLiam Girdwood /* headphone left mux */ 55283ac08c0SLiam Girdwood {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"}, 55383ac08c0SLiam Girdwood 55483ac08c0SLiam Girdwood /* headphone right mux */ 55583ac08c0SLiam Girdwood {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"}, 55683ac08c0SLiam Girdwood 55783ac08c0SLiam Girdwood /* speaker left mux */ 55883ac08c0SLiam Girdwood {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"}, 55983ac08c0SLiam Girdwood {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"}, 56083ac08c0SLiam Girdwood {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"}, 56183ac08c0SLiam Girdwood 56283ac08c0SLiam Girdwood /* speaker right mux */ 56383ac08c0SLiam Girdwood {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"}, 56483ac08c0SLiam Girdwood {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"}, 56583ac08c0SLiam Girdwood {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"}, 56683ac08c0SLiam Girdwood 56783ac08c0SLiam Girdwood /* mono mux */ 56883ac08c0SLiam Girdwood {"Mono Out Mux", "Mono", "Mono Mixer"}, 56983ac08c0SLiam Girdwood {"Mono Out Mux", "Inv", "DAC Inv Mux 1"}, 57083ac08c0SLiam Girdwood 57183ac08c0SLiam Girdwood /* out 3 mux */ 57283ac08c0SLiam Girdwood {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"}, 57383ac08c0SLiam Girdwood 57483ac08c0SLiam Girdwood /* out 4 mux */ 57583ac08c0SLiam Girdwood {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"}, 57683ac08c0SLiam Girdwood 57783ac08c0SLiam Girdwood /* output pga */ 57883ac08c0SLiam Girdwood {"HPL", NULL, "Left Headphone"}, 57983ac08c0SLiam Girdwood {"Left Headphone", NULL, "Left Headphone Out Mux"}, 58083ac08c0SLiam Girdwood {"HPR", NULL, "Right Headphone"}, 58183ac08c0SLiam Girdwood {"Right Headphone", NULL, "Right Headphone Out Mux"}, 58283ac08c0SLiam Girdwood {"OUT3", NULL, "Out 3"}, 58383ac08c0SLiam Girdwood {"Out 3", NULL, "Out 3 Mux"}, 58483ac08c0SLiam Girdwood {"OUT4", NULL, "Out 4"}, 58583ac08c0SLiam Girdwood {"Out 4", NULL, "Out 4 Mux"}, 58683ac08c0SLiam Girdwood {"SPKL", NULL, "Left Speaker"}, 58783ac08c0SLiam Girdwood {"Left Speaker", NULL, "Left Speaker Out Mux"}, 58883ac08c0SLiam Girdwood {"SPKR", NULL, "Right Speaker"}, 58983ac08c0SLiam Girdwood {"Right Speaker", NULL, "Right Speaker Out Mux"}, 59083ac08c0SLiam Girdwood {"MONO", NULL, "Mono Out"}, 59183ac08c0SLiam Girdwood {"Mono Out", NULL, "Mono Out Mux"}, 59283ac08c0SLiam Girdwood 59383ac08c0SLiam Girdwood /* input pga */ 59483ac08c0SLiam Girdwood {"Left Line In", NULL, "LINEL"}, 59583ac08c0SLiam Girdwood {"Right Line In", NULL, "LINER"}, 59683ac08c0SLiam Girdwood {"Mono In", NULL, "MONOIN"}, 59783ac08c0SLiam Girdwood {"Mic A PGA", NULL, "Mic A Pre Amp"}, 59883ac08c0SLiam Girdwood {"Mic B PGA", NULL, "Mic B Pre Amp"}, 59983ac08c0SLiam Girdwood 60083ac08c0SLiam Girdwood /* left capture select */ 60183ac08c0SLiam Girdwood {"Left Capture Source", "Mic 1", "Mic A Pre Amp"}, 60283ac08c0SLiam Girdwood {"Left Capture Source", "Mic 2", "Mic B Pre Amp"}, 60383ac08c0SLiam Girdwood {"Left Capture Source", "Line", "LINEL"}, 60483ac08c0SLiam Girdwood {"Left Capture Source", "Mono In", "MONOIN"}, 60583ac08c0SLiam Girdwood {"Left Capture Source", "Headphone", "Left HP Mixer"}, 60683ac08c0SLiam Girdwood {"Left Capture Source", "Speaker", "Speaker Mixer"}, 60783ac08c0SLiam Girdwood {"Left Capture Source", "Mono Out", "Mono Mixer"}, 60883ac08c0SLiam Girdwood 60983ac08c0SLiam Girdwood /* right capture select */ 61083ac08c0SLiam Girdwood {"Right Capture Source", "Mic 1", "Mic A Pre Amp"}, 61183ac08c0SLiam Girdwood {"Right Capture Source", "Mic 2", "Mic B Pre Amp"}, 61283ac08c0SLiam Girdwood {"Right Capture Source", "Line", "LINER"}, 61383ac08c0SLiam Girdwood {"Right Capture Source", "Mono In", "MONOIN"}, 61483ac08c0SLiam Girdwood {"Right Capture Source", "Headphone", "Right HP Mixer"}, 61583ac08c0SLiam Girdwood {"Right Capture Source", "Speaker", "Speaker Mixer"}, 61683ac08c0SLiam Girdwood {"Right Capture Source", "Mono Out", "Mono Mixer"}, 61783ac08c0SLiam Girdwood 61883ac08c0SLiam Girdwood /* left ADC */ 61983ac08c0SLiam Girdwood {"Left ADC", NULL, "Left Capture Source"}, 620ccbc301eSMark Brown {"Left Voice ADC", NULL, "Left ADC"}, 621ccbc301eSMark Brown {"Left HiFi ADC", NULL, "Left ADC"}, 62283ac08c0SLiam Girdwood 62383ac08c0SLiam Girdwood /* right ADC */ 62483ac08c0SLiam Girdwood {"Right ADC", NULL, "Right Capture Source"}, 625ccbc301eSMark Brown {"Right Voice ADC", NULL, "Right ADC"}, 626ccbc301eSMark Brown {"Right HiFi ADC", NULL, "Right ADC"}, 62783ac08c0SLiam Girdwood 62883ac08c0SLiam Girdwood /* mic */ 62983ac08c0SLiam Girdwood {"Mic A Pre Amp", NULL, "Mic A Source"}, 63083ac08c0SLiam Girdwood {"Mic A Source", "Mic 1", "MIC1"}, 63183ac08c0SLiam Girdwood {"Mic A Source", "Mic 2 A", "MIC2A"}, 63283ac08c0SLiam Girdwood {"Mic A Source", "Mic 2 B", "Mic B Source"}, 63383ac08c0SLiam Girdwood {"Mic B Pre Amp", "MPB", "Mic B Source"}, 63483ac08c0SLiam Girdwood {"Mic B Source", NULL, "MIC2B"}, 63583ac08c0SLiam Girdwood 63683ac08c0SLiam Girdwood /* headphone capture */ 63783ac08c0SLiam Girdwood {"Capture Headphone Mux", "Stereo", "Capture Mixer"}, 63883ac08c0SLiam Girdwood {"Capture Headphone Mux", "Left", "Left Capture Source"}, 63983ac08c0SLiam Girdwood {"Capture Headphone Mux", "Right", "Right Capture Source"}, 64083ac08c0SLiam Girdwood 64183ac08c0SLiam Girdwood /* mono capture */ 64283ac08c0SLiam Girdwood {"Capture Mono Mux", "Stereo", "Capture Mixer"}, 64383ac08c0SLiam Girdwood {"Capture Mono Mux", "Left", "Left Capture Source"}, 64483ac08c0SLiam Girdwood {"Capture Mono Mux", "Right", "Right Capture Source"}, 64583ac08c0SLiam Girdwood }; 64683ac08c0SLiam Girdwood 647700dadfeSRobert Jarzmik static bool wm9713_readable_reg(struct device *dev, unsigned int reg) 64883ac08c0SLiam Girdwood { 649700dadfeSRobert Jarzmik switch (reg) { 650700dadfeSRobert Jarzmik case AC97_RESET ... AC97_PCM_SURR_DAC_RATE: 651700dadfeSRobert Jarzmik case AC97_PCM_LR_ADC_RATE: 652700dadfeSRobert Jarzmik case AC97_CENTER_LFE_MASTER: 653700dadfeSRobert Jarzmik case AC97_SPDIF ... AC97_LINE1_LEVEL: 654700dadfeSRobert Jarzmik case AC97_GPIO_CFG ... 0x5c: 655700dadfeSRobert Jarzmik case AC97_CODEC_CLASS_REV ... AC97_PCI_SID: 656700dadfeSRobert Jarzmik case 0x74 ... AC97_VENDOR_ID2: 657700dadfeSRobert Jarzmik return true; 658700dadfeSRobert Jarzmik default: 659700dadfeSRobert Jarzmik return false; 66083ac08c0SLiam Girdwood } 66183ac08c0SLiam Girdwood } 66283ac08c0SLiam Girdwood 663700dadfeSRobert Jarzmik static bool wm9713_writeable_reg(struct device *dev, unsigned int reg) 66483ac08c0SLiam Girdwood { 665700dadfeSRobert Jarzmik switch (reg) { 666700dadfeSRobert Jarzmik case AC97_VENDOR_ID1: 667700dadfeSRobert Jarzmik case AC97_VENDOR_ID2: 668700dadfeSRobert Jarzmik return false; 669700dadfeSRobert Jarzmik default: 670700dadfeSRobert Jarzmik return wm9713_readable_reg(dev, reg); 67183ac08c0SLiam Girdwood } 672700dadfeSRobert Jarzmik } 673700dadfeSRobert Jarzmik 674700dadfeSRobert Jarzmik static const struct reg_default wm9713_reg_defaults[] = { 675700dadfeSRobert Jarzmik { 0x02, 0x8080 }, /* Speaker Output Volume */ 676700dadfeSRobert Jarzmik { 0x04, 0x8080 }, /* Headphone Output Volume */ 677700dadfeSRobert Jarzmik { 0x06, 0x8080 }, /* Out3/OUT4 Volume */ 678700dadfeSRobert Jarzmik { 0x08, 0xc880 }, /* Mono Volume */ 679700dadfeSRobert Jarzmik { 0x0a, 0xe808 }, /* LINEIN Volume */ 680700dadfeSRobert Jarzmik { 0x0c, 0xe808 }, /* DAC PGA Volume */ 681700dadfeSRobert Jarzmik { 0x0e, 0x0808 }, /* MIC PGA Volume */ 682700dadfeSRobert Jarzmik { 0x10, 0x00da }, /* MIC Routing Control */ 683700dadfeSRobert Jarzmik { 0x12, 0x8000 }, /* Record PGA Volume */ 684700dadfeSRobert Jarzmik { 0x14, 0xd600 }, /* Record Routing */ 685700dadfeSRobert Jarzmik { 0x16, 0xaaa0 }, /* PCBEEP Volume */ 686700dadfeSRobert Jarzmik { 0x18, 0xaaa0 }, /* VxDAC Volume */ 687700dadfeSRobert Jarzmik { 0x1a, 0xaaa0 }, /* AUXDAC Volume */ 688700dadfeSRobert Jarzmik { 0x1c, 0x0000 }, /* Output PGA Mux */ 689700dadfeSRobert Jarzmik { 0x1e, 0x0000 }, /* DAC 3D control */ 690700dadfeSRobert Jarzmik { 0x20, 0x0f0f }, /* DAC Tone Control*/ 691700dadfeSRobert Jarzmik { 0x22, 0x0040 }, /* MIC Input Select & Bias */ 692700dadfeSRobert Jarzmik { 0x24, 0x0000 }, /* Output Volume Mapping & Jack */ 693700dadfeSRobert Jarzmik { 0x26, 0x7f00 }, /* Powerdown Ctrl/Stat*/ 694700dadfeSRobert Jarzmik { 0x28, 0x0405 }, /* Extended Audio ID */ 695700dadfeSRobert Jarzmik { 0x2a, 0x0410 }, /* Extended Audio Start/Ctrl */ 696700dadfeSRobert Jarzmik { 0x2c, 0xbb80 }, /* Audio DACs Sample Rate */ 697700dadfeSRobert Jarzmik { 0x2e, 0xbb80 }, /* AUXDAC Sample Rate */ 698700dadfeSRobert Jarzmik { 0x32, 0xbb80 }, /* Audio ADCs Sample Rate */ 699700dadfeSRobert Jarzmik { 0x36, 0x4523 }, /* PCM codec control */ 700700dadfeSRobert Jarzmik { 0x3a, 0x2000 }, /* SPDIF control */ 701700dadfeSRobert Jarzmik { 0x3c, 0xfdff }, /* Powerdown 1 */ 702700dadfeSRobert Jarzmik { 0x3e, 0xffff }, /* Powerdown 2 */ 703700dadfeSRobert Jarzmik { 0x40, 0x0000 }, /* General Purpose */ 704700dadfeSRobert Jarzmik { 0x42, 0x0000 }, /* Fast Power-Up Control */ 705700dadfeSRobert Jarzmik { 0x44, 0x0080 }, /* MCLK/PLL Control */ 706700dadfeSRobert Jarzmik { 0x46, 0x0000 }, /* MCLK/PLL Control */ 707700dadfeSRobert Jarzmik { 0x4c, 0xfffe }, /* GPIO Pin Configuration */ 708700dadfeSRobert Jarzmik { 0x4e, 0xffff }, /* GPIO Pin Polarity / Type */ 709700dadfeSRobert Jarzmik { 0x50, 0x0000 }, /* GPIO Pin Sticky */ 710700dadfeSRobert Jarzmik { 0x52, 0x0000 }, /* GPIO Pin Wake-Up */ 711700dadfeSRobert Jarzmik /* GPIO Pin Status */ 712700dadfeSRobert Jarzmik { 0x56, 0xfffe }, /* GPIO Pin Sharing */ 713700dadfeSRobert Jarzmik { 0x58, 0x4000 }, /* GPIO PullUp/PullDown */ 714700dadfeSRobert Jarzmik { 0x5a, 0x0000 }, /* Additional Functions 1 */ 715700dadfeSRobert Jarzmik { 0x5c, 0x0000 }, /* Additional Functions 2 */ 716700dadfeSRobert Jarzmik { 0x60, 0xb032 }, /* ALC Control */ 717700dadfeSRobert Jarzmik { 0x62, 0x3e00 }, /* ALC / Noise Gate Control */ 718700dadfeSRobert Jarzmik { 0x64, 0x0000 }, /* AUXDAC input control */ 719700dadfeSRobert Jarzmik { 0x74, 0x0000 }, /* Digitiser Reg 1 */ 720700dadfeSRobert Jarzmik { 0x76, 0x0006 }, /* Digitiser Reg 2 */ 721700dadfeSRobert Jarzmik { 0x78, 0x0001 }, /* Digitiser Reg 3 */ 722700dadfeSRobert Jarzmik { 0x7a, 0x0000 }, /* Digitiser Read Back */ 723700dadfeSRobert Jarzmik }; 724700dadfeSRobert Jarzmik 725700dadfeSRobert Jarzmik static const struct regmap_config wm9713_regmap_config = { 726700dadfeSRobert Jarzmik .reg_bits = 16, 727700dadfeSRobert Jarzmik .reg_stride = 2, 728700dadfeSRobert Jarzmik .val_bits = 16, 729700dadfeSRobert Jarzmik .max_register = 0x7e, 730700dadfeSRobert Jarzmik .cache_type = REGCACHE_RBTREE, 731700dadfeSRobert Jarzmik 732700dadfeSRobert Jarzmik .reg_defaults = wm9713_reg_defaults, 733700dadfeSRobert Jarzmik .num_reg_defaults = ARRAY_SIZE(wm9713_reg_defaults), 734700dadfeSRobert Jarzmik .volatile_reg = regmap_ac97_default_volatile, 735700dadfeSRobert Jarzmik .readable_reg = wm9713_readable_reg, 736700dadfeSRobert Jarzmik .writeable_reg = wm9713_writeable_reg, 737700dadfeSRobert Jarzmik }; 73883ac08c0SLiam Girdwood 73983ac08c0SLiam Girdwood /* PLL divisors */ 74083ac08c0SLiam Girdwood struct _pll_div { 74183ac08c0SLiam Girdwood u32 divsel:1; 74283ac08c0SLiam Girdwood u32 divctl:1; 74383ac08c0SLiam Girdwood u32 lf:1; 74483ac08c0SLiam Girdwood u32 n:4; 74583ac08c0SLiam Girdwood u32 k:24; 74683ac08c0SLiam Girdwood }; 74783ac08c0SLiam Girdwood 74883ac08c0SLiam Girdwood /* The size in bits of the PLL divide multiplied by 10 74983ac08c0SLiam Girdwood * to allow rounding later */ 75083ac08c0SLiam Girdwood #define FIXED_PLL_SIZE ((1 << 22) * 10) 75183ac08c0SLiam Girdwood 7528ea99bc6SKuninori Morimoto static void pll_factors(struct snd_soc_component *component, 753a6c2b07fSLars-Peter Clausen struct _pll_div *pll_div, unsigned int source) 75483ac08c0SLiam Girdwood { 75583ac08c0SLiam Girdwood u64 Kpart; 75683ac08c0SLiam Girdwood unsigned int K, Ndiv, Nmod, target; 75783ac08c0SLiam Girdwood 75885131d94SRandy Dunlap /* The PLL output is always 98.304MHz. */ 75983ac08c0SLiam Girdwood target = 98304000; 76083ac08c0SLiam Girdwood 76183ac08c0SLiam Girdwood /* If the input frequency is over 14.4MHz then scale it down. */ 76283ac08c0SLiam Girdwood if (source > 14400000) { 76383ac08c0SLiam Girdwood source >>= 1; 76483ac08c0SLiam Girdwood pll_div->divsel = 1; 76583ac08c0SLiam Girdwood 76683ac08c0SLiam Girdwood if (source > 14400000) { 76783ac08c0SLiam Girdwood source >>= 1; 76883ac08c0SLiam Girdwood pll_div->divctl = 1; 76983ac08c0SLiam Girdwood } else 77083ac08c0SLiam Girdwood pll_div->divctl = 0; 77183ac08c0SLiam Girdwood 77283ac08c0SLiam Girdwood } else { 77383ac08c0SLiam Girdwood pll_div->divsel = 0; 77483ac08c0SLiam Girdwood pll_div->divctl = 0; 77583ac08c0SLiam Girdwood } 77683ac08c0SLiam Girdwood 77783ac08c0SLiam Girdwood /* Low frequency sources require an additional divide in the 77883ac08c0SLiam Girdwood * loop. 77983ac08c0SLiam Girdwood */ 78083ac08c0SLiam Girdwood if (source < 8192000) { 78183ac08c0SLiam Girdwood pll_div->lf = 1; 78283ac08c0SLiam Girdwood target >>= 2; 78383ac08c0SLiam Girdwood } else 78483ac08c0SLiam Girdwood pll_div->lf = 0; 78583ac08c0SLiam Girdwood 78683ac08c0SLiam Girdwood Ndiv = target / source; 78783ac08c0SLiam Girdwood if ((Ndiv < 5) || (Ndiv > 12)) 7888ea99bc6SKuninori Morimoto dev_warn(component->dev, 789449bd54dSRoel Kluin "WM9713 PLL N value %u out of recommended range!\n", 79083ac08c0SLiam Girdwood Ndiv); 79183ac08c0SLiam Girdwood 79283ac08c0SLiam Girdwood pll_div->n = Ndiv; 79383ac08c0SLiam Girdwood Nmod = target % source; 79483ac08c0SLiam Girdwood Kpart = FIXED_PLL_SIZE * (long long)Nmod; 79583ac08c0SLiam Girdwood 79683ac08c0SLiam Girdwood do_div(Kpart, source); 79783ac08c0SLiam Girdwood 79883ac08c0SLiam Girdwood K = Kpart & 0xFFFFFFFF; 79983ac08c0SLiam Girdwood 80083ac08c0SLiam Girdwood /* Check if we need to round */ 80183ac08c0SLiam Girdwood if ((K % 10) >= 5) 80283ac08c0SLiam Girdwood K += 5; 80383ac08c0SLiam Girdwood 80483ac08c0SLiam Girdwood /* Move down to proper range now rounding is done */ 80583ac08c0SLiam Girdwood K /= 10; 80683ac08c0SLiam Girdwood 80783ac08c0SLiam Girdwood pll_div->k = K; 80883ac08c0SLiam Girdwood } 80983ac08c0SLiam Girdwood 810442950a3SPierre-Louis Bossart /* 81183ac08c0SLiam Girdwood * Please note that changing the PLL input frequency may require 81283ac08c0SLiam Girdwood * resynchronisation with the AC97 controller. 81383ac08c0SLiam Girdwood */ 8148ea99bc6SKuninori Morimoto static int wm9713_set_pll(struct snd_soc_component *component, 81583ac08c0SLiam Girdwood int pll_id, unsigned int freq_in, unsigned int freq_out) 81683ac08c0SLiam Girdwood { 8178ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 81883ac08c0SLiam Girdwood u16 reg, reg2; 81983ac08c0SLiam Girdwood struct _pll_div pll_div; 82083ac08c0SLiam Girdwood 82183ac08c0SLiam Girdwood /* turn PLL off ? */ 822c42f69bbSMark Brown if (freq_in == 0) { 82383ac08c0SLiam Girdwood /* disable PLL power and select ext source */ 8248ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0080, 0x0080); 8258ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0x0200, 0x0200); 826c42f69bbSMark Brown wm9713->pll_in = 0; 82783ac08c0SLiam Girdwood return 0; 82883ac08c0SLiam Girdwood } 82983ac08c0SLiam Girdwood 8308ea99bc6SKuninori Morimoto pll_factors(component, &pll_div, freq_in); 83183ac08c0SLiam Girdwood 83283ac08c0SLiam Girdwood if (pll_div.k == 0) { 83383ac08c0SLiam Girdwood reg = (pll_div.n << 12) | (pll_div.lf << 11) | 83483ac08c0SLiam Girdwood (pll_div.divsel << 9) | (pll_div.divctl << 8); 8358ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 83683ac08c0SLiam Girdwood } else { 83783ac08c0SLiam Girdwood /* write the fractional k to the reg 0x46 pages */ 83883ac08c0SLiam Girdwood reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) | 83983ac08c0SLiam Girdwood (pll_div.divsel << 9) | (pll_div.divctl << 8); 84083ac08c0SLiam Girdwood 84183ac08c0SLiam Girdwood /* K [21:20] */ 84283ac08c0SLiam Girdwood reg = reg2 | (0x5 << 4) | (pll_div.k >> 20); 8438ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 84483ac08c0SLiam Girdwood 84583ac08c0SLiam Girdwood /* K [19:16] */ 84683ac08c0SLiam Girdwood reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf); 8478ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 84883ac08c0SLiam Girdwood 84983ac08c0SLiam Girdwood /* K [15:12] */ 85083ac08c0SLiam Girdwood reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf); 8518ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 85283ac08c0SLiam Girdwood 85383ac08c0SLiam Girdwood /* K [11:8] */ 85483ac08c0SLiam Girdwood reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf); 8558ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 85683ac08c0SLiam Girdwood 85783ac08c0SLiam Girdwood /* K [7:4] */ 85883ac08c0SLiam Girdwood reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf); 8598ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 86083ac08c0SLiam Girdwood 86183ac08c0SLiam Girdwood reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */ 8628ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_LINE1_LEVEL, reg); 86383ac08c0SLiam Girdwood } 86483ac08c0SLiam Girdwood 86583ac08c0SLiam Girdwood /* turn PLL on and select as source */ 8668ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0x0200, 0x0000); 8678ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0080, 0x0000); 86883ac08c0SLiam Girdwood wm9713->pll_in = freq_in; 86983ac08c0SLiam Girdwood 87083ac08c0SLiam Girdwood /* wait 10ms AC97 link frames for the link to stabilise */ 87183ac08c0SLiam Girdwood schedule_timeout_interruptible(msecs_to_jiffies(10)); 87283ac08c0SLiam Girdwood return 0; 87383ac08c0SLiam Girdwood } 87483ac08c0SLiam Girdwood 87585488037SMark Brown static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, 87685488037SMark Brown int source, unsigned int freq_in, unsigned int freq_out) 87783ac08c0SLiam Girdwood { 8788ea99bc6SKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 8798ea99bc6SKuninori Morimoto return wm9713_set_pll(component, pll_id, freq_in, freq_out); 88083ac08c0SLiam Girdwood } 88183ac08c0SLiam Girdwood 88283ac08c0SLiam Girdwood /* 88383ac08c0SLiam Girdwood * Tristate the PCM DAI lines, tristate can be disabled by calling 88483ac08c0SLiam Girdwood * wm9713_set_dai_fmt() 88583ac08c0SLiam Girdwood */ 886e550e17fSLiam Girdwood static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai, 88783ac08c0SLiam Girdwood int tristate) 88883ac08c0SLiam Girdwood { 8898ea99bc6SKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 89083ac08c0SLiam Girdwood 89183ac08c0SLiam Girdwood if (tristate) 8928ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CENTER_LFE_MASTER, 893fa1a51f3SRobert Jarzmik 0x6000, 0x0000); 89483ac08c0SLiam Girdwood 89583ac08c0SLiam Girdwood return 0; 89683ac08c0SLiam Girdwood } 89783ac08c0SLiam Girdwood 89883ac08c0SLiam Girdwood /* 89983ac08c0SLiam Girdwood * Configure WM9713 clock dividers. 90083ac08c0SLiam Girdwood * Voice DAC needs 256 FS 90183ac08c0SLiam Girdwood */ 902e550e17fSLiam Girdwood static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai, 90383ac08c0SLiam Girdwood int div_id, int div) 90483ac08c0SLiam Girdwood { 9058ea99bc6SKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 90683ac08c0SLiam Girdwood 90783ac08c0SLiam Girdwood switch (div_id) { 90883ac08c0SLiam Girdwood case WM9713_PCMCLK_DIV: 9098ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0f00, div); 91083ac08c0SLiam Girdwood break; 91183ac08c0SLiam Girdwood case WM9713_CLKA_MULT: 9128ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0002, div); 91383ac08c0SLiam Girdwood break; 91483ac08c0SLiam Girdwood case WM9713_CLKB_MULT: 9158ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x0004, div); 91683ac08c0SLiam Girdwood break; 91783ac08c0SLiam Girdwood case WM9713_HIFI_DIV: 9188ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_HANDSET_RATE, 0x7000, div); 91983ac08c0SLiam Girdwood break; 92083ac08c0SLiam Girdwood case WM9713_PCMBCLK_DIV: 9218ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CENTER_LFE_MASTER, 0x0e00, div); 92283ac08c0SLiam Girdwood break; 92383ac08c0SLiam Girdwood case WM9713_PCMCLK_PLL_DIV: 9248ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_LINE1_LEVEL, 925fa1a51f3SRobert Jarzmik 0x007f, div | 0x60); 92683ac08c0SLiam Girdwood break; 92783ac08c0SLiam Girdwood case WM9713_HIFI_PLL_DIV: 9288ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_LINE1_LEVEL, 929fa1a51f3SRobert Jarzmik 0x007f, div | 0x70); 93083ac08c0SLiam Girdwood break; 93183ac08c0SLiam Girdwood default: 93283ac08c0SLiam Girdwood return -EINVAL; 93383ac08c0SLiam Girdwood } 93483ac08c0SLiam Girdwood 93583ac08c0SLiam Girdwood return 0; 93683ac08c0SLiam Girdwood } 93783ac08c0SLiam Girdwood 938e550e17fSLiam Girdwood static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai, 93983ac08c0SLiam Girdwood unsigned int fmt) 94083ac08c0SLiam Girdwood { 9418ea99bc6SKuninori Morimoto struct snd_soc_component *component = codec_dai->component; 9426d75dfc3SKuninori Morimoto u16 gpio = snd_soc_component_read(component, AC97_GPIO_CFG) & 0xffc5; 94383ac08c0SLiam Girdwood u16 reg = 0x8000; 94483ac08c0SLiam Girdwood 94583ac08c0SLiam Girdwood /* clock masters */ 94683ac08c0SLiam Girdwood switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { 94783ac08c0SLiam Girdwood case SND_SOC_DAIFMT_CBM_CFM: 94883ac08c0SLiam Girdwood reg |= 0x4000; 94983ac08c0SLiam Girdwood gpio |= 0x0010; 95083ac08c0SLiam Girdwood break; 95183ac08c0SLiam Girdwood case SND_SOC_DAIFMT_CBM_CFS: 95283ac08c0SLiam Girdwood reg |= 0x6000; 95383ac08c0SLiam Girdwood gpio |= 0x0018; 95483ac08c0SLiam Girdwood break; 95583ac08c0SLiam Girdwood case SND_SOC_DAIFMT_CBS_CFS: 956d133b0ceSMark Brown reg |= 0x2000; 95783ac08c0SLiam Girdwood gpio |= 0x001a; 95883ac08c0SLiam Girdwood break; 95983ac08c0SLiam Girdwood case SND_SOC_DAIFMT_CBS_CFM: 96083ac08c0SLiam Girdwood gpio |= 0x0012; 96183ac08c0SLiam Girdwood break; 96283ac08c0SLiam Girdwood } 96383ac08c0SLiam Girdwood 96483ac08c0SLiam Girdwood /* clock inversion */ 96583ac08c0SLiam Girdwood switch (fmt & SND_SOC_DAIFMT_INV_MASK) { 96683ac08c0SLiam Girdwood case SND_SOC_DAIFMT_IB_IF: 96783ac08c0SLiam Girdwood reg |= 0x00c0; 96883ac08c0SLiam Girdwood break; 96983ac08c0SLiam Girdwood case SND_SOC_DAIFMT_IB_NF: 97083ac08c0SLiam Girdwood reg |= 0x0080; 97183ac08c0SLiam Girdwood break; 97283ac08c0SLiam Girdwood case SND_SOC_DAIFMT_NB_IF: 97383ac08c0SLiam Girdwood reg |= 0x0040; 97483ac08c0SLiam Girdwood break; 97583ac08c0SLiam Girdwood } 97683ac08c0SLiam Girdwood 97783ac08c0SLiam Girdwood /* DAI format */ 97883ac08c0SLiam Girdwood switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { 97983ac08c0SLiam Girdwood case SND_SOC_DAIFMT_I2S: 98083ac08c0SLiam Girdwood reg |= 0x0002; 98183ac08c0SLiam Girdwood break; 98283ac08c0SLiam Girdwood case SND_SOC_DAIFMT_RIGHT_J: 98383ac08c0SLiam Girdwood break; 98483ac08c0SLiam Girdwood case SND_SOC_DAIFMT_LEFT_J: 98583ac08c0SLiam Girdwood reg |= 0x0001; 98683ac08c0SLiam Girdwood break; 98783ac08c0SLiam Girdwood case SND_SOC_DAIFMT_DSP_A: 98883ac08c0SLiam Girdwood reg |= 0x0003; 98983ac08c0SLiam Girdwood break; 99083ac08c0SLiam Girdwood case SND_SOC_DAIFMT_DSP_B: 99183ac08c0SLiam Girdwood reg |= 0x0043; 99283ac08c0SLiam Girdwood break; 99383ac08c0SLiam Girdwood } 99483ac08c0SLiam Girdwood 9958ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_GPIO_CFG, gpio); 9968ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_CENTER_LFE_MASTER, reg); 99783ac08c0SLiam Girdwood return 0; 99883ac08c0SLiam Girdwood } 99983ac08c0SLiam Girdwood 100083ac08c0SLiam Girdwood static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, 1001dee89c4dSMark Brown struct snd_pcm_hw_params *params, 1002dee89c4dSMark Brown struct snd_soc_dai *dai) 100383ac08c0SLiam Girdwood { 10048ea99bc6SKuninori Morimoto struct snd_soc_component *component = dai->component; 100583ac08c0SLiam Girdwood 1006fa1a51f3SRobert Jarzmik /* enable PCM interface in master mode */ 1007563fe71fSMark Brown switch (params_width(params)) { 1008563fe71fSMark Brown case 16: 100983ac08c0SLiam Girdwood break; 1010563fe71fSMark Brown case 20: 10118ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CENTER_LFE_MASTER, 1012fa1a51f3SRobert Jarzmik 0x000c, 0x0004); 101383ac08c0SLiam Girdwood break; 1014563fe71fSMark Brown case 24: 10158ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CENTER_LFE_MASTER, 1016fa1a51f3SRobert Jarzmik 0x000c, 0x0008); 101783ac08c0SLiam Girdwood break; 1018563fe71fSMark Brown case 32: 10198ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CENTER_LFE_MASTER, 1020fa1a51f3SRobert Jarzmik 0x000c, 0x000c); 102183ac08c0SLiam Girdwood break; 102283ac08c0SLiam Girdwood } 102383ac08c0SLiam Girdwood return 0; 102483ac08c0SLiam Girdwood } 102583ac08c0SLiam Girdwood 1026dee89c4dSMark Brown static int ac97_hifi_prepare(struct snd_pcm_substream *substream, 1027dee89c4dSMark Brown struct snd_soc_dai *dai) 102883ac08c0SLiam Girdwood { 10298ea99bc6SKuninori Morimoto struct snd_soc_component *component = dai->component; 103083ac08c0SLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 103183ac08c0SLiam Girdwood int reg; 103283ac08c0SLiam Girdwood 10338ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x0001, 0x0001); 103483ac08c0SLiam Girdwood 103583ac08c0SLiam Girdwood if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 103683ac08c0SLiam Girdwood reg = AC97_PCM_FRONT_DAC_RATE; 103783ac08c0SLiam Girdwood else 103883ac08c0SLiam Girdwood reg = AC97_PCM_LR_ADC_RATE; 103983ac08c0SLiam Girdwood 10408ea99bc6SKuninori Morimoto return snd_soc_component_write(component, reg, runtime->rate); 104183ac08c0SLiam Girdwood } 104283ac08c0SLiam Girdwood 1043dee89c4dSMark Brown static int ac97_aux_prepare(struct snd_pcm_substream *substream, 1044dee89c4dSMark Brown struct snd_soc_dai *dai) 104583ac08c0SLiam Girdwood { 10468ea99bc6SKuninori Morimoto struct snd_soc_component *component = dai->component; 104783ac08c0SLiam Girdwood struct snd_pcm_runtime *runtime = substream->runtime; 104883ac08c0SLiam Girdwood 10498ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_STATUS, 0x0001, 0x0001); 10508ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_PCI_SID, 0x8000, 0x8000); 105183ac08c0SLiam Girdwood 105283ac08c0SLiam Girdwood if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) 105383ac08c0SLiam Girdwood return -ENODEV; 105483ac08c0SLiam Girdwood 10558ea99bc6SKuninori Morimoto return snd_soc_component_write(component, AC97_PCM_SURR_DAC_RATE, runtime->rate); 105683ac08c0SLiam Girdwood } 105783ac08c0SLiam Girdwood 10585415552dSMark Brown #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \ 10595415552dSMark Brown SNDRV_PCM_RATE_11025 | \ 10605415552dSMark Brown SNDRV_PCM_RATE_22050 | \ 10615415552dSMark Brown SNDRV_PCM_RATE_44100 | \ 10625415552dSMark Brown SNDRV_PCM_RATE_48000) 10635415552dSMark Brown 10645415552dSMark Brown #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \ 10655415552dSMark Brown SNDRV_PCM_RATE_11025 | \ 10665415552dSMark Brown SNDRV_PCM_RATE_16000 | \ 10675415552dSMark Brown SNDRV_PCM_RATE_22050 | \ 10685415552dSMark Brown SNDRV_PCM_RATE_44100 | \ 106983ac08c0SLiam Girdwood SNDRV_PCM_RATE_48000) 107083ac08c0SLiam Girdwood 107183ac08c0SLiam Girdwood #define WM9713_PCM_FORMATS \ 1072e712bfcaSMaciej S. Szmigiero (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ 1073e712bfcaSMaciej S. Szmigiero SNDRV_PCM_FMTBIT_S24_LE) 107483ac08c0SLiam Girdwood 107585e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = { 10766335d055SEric Miao .prepare = ac97_hifi_prepare, 10776335d055SEric Miao .set_clkdiv = wm9713_set_dai_clkdiv, 10786335d055SEric Miao .set_pll = wm9713_set_dai_pll, 10796335d055SEric Miao }; 10806335d055SEric Miao 108185e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9713_dai_ops_aux = { 10826335d055SEric Miao .prepare = ac97_aux_prepare, 10836335d055SEric Miao .set_clkdiv = wm9713_set_dai_clkdiv, 10846335d055SEric Miao .set_pll = wm9713_set_dai_pll, 10856335d055SEric Miao }; 10866335d055SEric Miao 108785e7652dSLars-Peter Clausen static const struct snd_soc_dai_ops wm9713_dai_ops_voice = { 10886335d055SEric Miao .hw_params = wm9713_pcm_hw_params, 10896335d055SEric Miao .set_clkdiv = wm9713_set_dai_clkdiv, 10906335d055SEric Miao .set_pll = wm9713_set_dai_pll, 10916335d055SEric Miao .set_fmt = wm9713_set_dai_fmt, 10926335d055SEric Miao .set_tristate = wm9713_set_dai_tristate, 10936335d055SEric Miao }; 10946335d055SEric Miao 1095f0fba2adSLiam Girdwood static struct snd_soc_dai_driver wm9713_dai[] = { 109683ac08c0SLiam Girdwood { 1097f0fba2adSLiam Girdwood .name = "wm9713-hifi", 109883ac08c0SLiam Girdwood .playback = { 109983ac08c0SLiam Girdwood .stream_name = "HiFi Playback", 110083ac08c0SLiam Girdwood .channels_min = 1, 110183ac08c0SLiam Girdwood .channels_max = 2, 110283ac08c0SLiam Girdwood .rates = WM9713_RATES, 110333f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS,}, 110483ac08c0SLiam Girdwood .capture = { 110583ac08c0SLiam Girdwood .stream_name = "HiFi Capture", 110683ac08c0SLiam Girdwood .channels_min = 1, 110783ac08c0SLiam Girdwood .channels_max = 2, 110883ac08c0SLiam Girdwood .rates = WM9713_RATES, 110933f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS,}, 11106335d055SEric Miao .ops = &wm9713_dai_ops_hifi, 111183ac08c0SLiam Girdwood }, 111283ac08c0SLiam Girdwood { 1113f0fba2adSLiam Girdwood .name = "wm9713-aux", 111483ac08c0SLiam Girdwood .playback = { 111583ac08c0SLiam Girdwood .stream_name = "Aux Playback", 111683ac08c0SLiam Girdwood .channels_min = 1, 111783ac08c0SLiam Girdwood .channels_max = 1, 111883ac08c0SLiam Girdwood .rates = WM9713_RATES, 111933f503c9SMark Brown .formats = SND_SOC_STD_AC97_FMTS,}, 11206335d055SEric Miao .ops = &wm9713_dai_ops_aux, 112183ac08c0SLiam Girdwood }, 112283ac08c0SLiam Girdwood { 1123f0fba2adSLiam Girdwood .name = "wm9713-voice", 112483ac08c0SLiam Girdwood .playback = { 112583ac08c0SLiam Girdwood .stream_name = "Voice Playback", 112683ac08c0SLiam Girdwood .channels_min = 1, 112783ac08c0SLiam Girdwood .channels_max = 1, 11285415552dSMark Brown .rates = WM9713_PCM_RATES, 112983ac08c0SLiam Girdwood .formats = WM9713_PCM_FORMATS,}, 113083ac08c0SLiam Girdwood .capture = { 113183ac08c0SLiam Girdwood .stream_name = "Voice Capture", 113283ac08c0SLiam Girdwood .channels_min = 1, 113383ac08c0SLiam Girdwood .channels_max = 2, 11345415552dSMark Brown .rates = WM9713_PCM_RATES, 113583ac08c0SLiam Girdwood .formats = WM9713_PCM_FORMATS,}, 11366335d055SEric Miao .ops = &wm9713_dai_ops_voice, 1137*07695752SKuninori Morimoto .symmetric_rate = 1, 113883ac08c0SLiam Girdwood }, 113983ac08c0SLiam Girdwood }; 114083ac08c0SLiam Girdwood 11418ea99bc6SKuninori Morimoto static int wm9713_set_bias_level(struct snd_soc_component *component, 11420be9898aSMark Brown enum snd_soc_bias_level level) 114383ac08c0SLiam Girdwood { 11440be9898aSMark Brown switch (level) { 11450be9898aSMark Brown case SND_SOC_BIAS_ON: 114683ac08c0SLiam Girdwood /* enable thermal shutdown */ 11478ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0xe400, 0x0000); 114883ac08c0SLiam Girdwood break; 11490be9898aSMark Brown case SND_SOC_BIAS_PREPARE: 115083ac08c0SLiam Girdwood break; 11510be9898aSMark Brown case SND_SOC_BIAS_STANDBY: 115283ac08c0SLiam Girdwood /* enable master bias and vmid */ 11538ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0xc400, 0x0000); 11548ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_POWERDOWN, 0x0000); 115583ac08c0SLiam Girdwood break; 11560be9898aSMark Brown case SND_SOC_BIAS_OFF: 115783ac08c0SLiam Girdwood /* disable everything including AC link */ 11588ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_EXTENDED_MID, 0xffff); 11598ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_EXTENDED_MSTATUS, 0xffff); 11608ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_POWERDOWN, 0xffff); 116183ac08c0SLiam Girdwood break; 116283ac08c0SLiam Girdwood } 116383ac08c0SLiam Girdwood return 0; 116483ac08c0SLiam Girdwood } 116583ac08c0SLiam Girdwood 11668ea99bc6SKuninori Morimoto static int wm9713_soc_suspend(struct snd_soc_component *component) 116783ac08c0SLiam Girdwood { 116887b57fe2SMark Brown /* Disable everything except touchpanel - that will be handled 116987b57fe2SMark Brown * by the touch driver and left disabled if touch is not in 117087b57fe2SMark Brown * use. */ 11718ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_EXTENDED_MID, 0x7fff, 1172fa1a51f3SRobert Jarzmik 0x7fff); 11738ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_EXTENDED_MSTATUS, 0xffff); 11748ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_POWERDOWN, 0x6f00); 11758ea99bc6SKuninori Morimoto snd_soc_component_write(component, AC97_POWERDOWN, 0xffff); 117687b57fe2SMark Brown 117783ac08c0SLiam Girdwood return 0; 117883ac08c0SLiam Girdwood } 117983ac08c0SLiam Girdwood 11808ea99bc6SKuninori Morimoto static int wm9713_soc_resume(struct snd_soc_component *component) 118183ac08c0SLiam Girdwood { 11828ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 1183700dadfeSRobert Jarzmik int ret; 118483ac08c0SLiam Girdwood 1185310398f5SLars-Peter Clausen ret = snd_ac97_reset(wm9713->ac97, true, WM9713_VENDOR_ID, 1186310398f5SLars-Peter Clausen WM9713_VENDOR_ID_MASK); 1187a6c2b07fSLars-Peter Clausen if (ret < 0) 118883ac08c0SLiam Girdwood return ret; 118983ac08c0SLiam Girdwood 11908ea99bc6SKuninori Morimoto snd_soc_component_force_bias_level(component, SND_SOC_BIAS_STANDBY); 119183ac08c0SLiam Girdwood 119283ac08c0SLiam Girdwood /* do we need to re-start the PLL ? */ 1193c42f69bbSMark Brown if (wm9713->pll_in) 11948ea99bc6SKuninori Morimoto wm9713_set_pll(component, 0, wm9713->pll_in, 0); 119583ac08c0SLiam Girdwood 119683ac08c0SLiam Girdwood /* only synchronise the codec if warm reset failed */ 119783ac08c0SLiam Girdwood if (ret == 0) { 11988ea99bc6SKuninori Morimoto regcache_mark_dirty(component->regmap); 11998ea99bc6SKuninori Morimoto snd_soc_component_cache_sync(component); 120083ac08c0SLiam Girdwood } 120183ac08c0SLiam Girdwood 120283ac08c0SLiam Girdwood return ret; 120383ac08c0SLiam Girdwood } 120483ac08c0SLiam Girdwood 12058ea99bc6SKuninori Morimoto static int wm9713_soc_probe(struct snd_soc_component *component) 120683ac08c0SLiam Girdwood { 12078ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 12089bd400caSRobert Jarzmik struct regmap *regmap = NULL; 120983ac08c0SLiam Girdwood 12109bd400caSRobert Jarzmik if (wm9713->mfd_pdata) { 12119bd400caSRobert Jarzmik wm9713->ac97 = wm9713->mfd_pdata->ac97; 12129bd400caSRobert Jarzmik regmap = wm9713->mfd_pdata->regmap; 1213576ce407SArnd Bergmann } else if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS)) { 12148ea99bc6SKuninori Morimoto wm9713->ac97 = snd_soc_new_ac97_component(component, WM9713_VENDOR_ID, 1215310398f5SLars-Peter Clausen WM9713_VENDOR_ID_MASK); 1216358a8bb5SLars-Peter Clausen if (IS_ERR(wm9713->ac97)) 1217358a8bb5SLars-Peter Clausen return PTR_ERR(wm9713->ac97); 1218da9b9303SRobert Jarzmik regmap = regmap_init_ac97(wm9713->ac97, &wm9713_regmap_config); 1219700dadfeSRobert Jarzmik if (IS_ERR(regmap)) { 12208ea99bc6SKuninori Morimoto snd_soc_free_ac97_component(wm9713->ac97); 1221700dadfeSRobert Jarzmik return PTR_ERR(regmap); 1222700dadfeSRobert Jarzmik } 1223576ce407SArnd Bergmann } else { 1224576ce407SArnd Bergmann return -ENXIO; 12259bd400caSRobert Jarzmik } 1226700dadfeSRobert Jarzmik 12278ea99bc6SKuninori Morimoto snd_soc_component_init_regmap(component, regmap); 1228700dadfeSRobert Jarzmik 122983ac08c0SLiam Girdwood /* unmute the adc - move to kcontrol */ 12308ea99bc6SKuninori Morimoto snd_soc_component_update_bits(component, AC97_CD, 0x7fff, 0x0000); 123183ac08c0SLiam Girdwood 123283ac08c0SLiam Girdwood return 0; 123383ac08c0SLiam Girdwood } 123483ac08c0SLiam Girdwood 12358ea99bc6SKuninori Morimoto static void wm9713_soc_remove(struct snd_soc_component *component) 123683ac08c0SLiam Girdwood { 12378ea99bc6SKuninori Morimoto struct wm9713_priv *wm9713 = snd_soc_component_get_drvdata(component); 1238358a8bb5SLars-Peter Clausen 1239576ce407SArnd Bergmann if (IS_ENABLED(CONFIG_SND_SOC_AC97_BUS) && !wm9713->mfd_pdata) { 12408ea99bc6SKuninori Morimoto snd_soc_component_exit_regmap(component); 12418ea99bc6SKuninori Morimoto snd_soc_free_ac97_component(wm9713->ac97); 12429bd400caSRobert Jarzmik } 124383ac08c0SLiam Girdwood } 124483ac08c0SLiam Girdwood 12458ea99bc6SKuninori Morimoto static const struct snd_soc_component_driver soc_component_dev_wm9713 = { 124683ac08c0SLiam Girdwood .probe = wm9713_soc_probe, 124783ac08c0SLiam Girdwood .remove = wm9713_soc_remove, 124883ac08c0SLiam Girdwood .suspend = wm9713_soc_suspend, 124983ac08c0SLiam Girdwood .resume = wm9713_soc_resume, 1250f0fba2adSLiam Girdwood .set_bias_level = wm9713_set_bias_level, 1251c1359ca3SLars-Peter Clausen .controls = wm9713_snd_ac97_controls, 1252c1359ca3SLars-Peter Clausen .num_controls = ARRAY_SIZE(wm9713_snd_ac97_controls), 12537ad7dd12SLu Guanqun .dapm_widgets = wm9713_dapm_widgets, 12547ad7dd12SLu Guanqun .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets), 12557ad7dd12SLu Guanqun .dapm_routes = wm9713_audio_map, 12567ad7dd12SLu Guanqun .num_dapm_routes = ARRAY_SIZE(wm9713_audio_map), 12578ea99bc6SKuninori Morimoto .idle_bias_on = 1, 12588ea99bc6SKuninori Morimoto .use_pmdown_time = 1, 12598ea99bc6SKuninori Morimoto .endianness = 1, 12608ea99bc6SKuninori Morimoto .non_legacy_dai_naming = 1, 126183ac08c0SLiam Girdwood }; 1262f0fba2adSLiam Girdwood 12637a79e94eSBill Pemberton static int wm9713_probe(struct platform_device *pdev) 1264f0fba2adSLiam Girdwood { 12655efe89d9SLars-Peter Clausen struct wm9713_priv *wm9713; 12665efe89d9SLars-Peter Clausen 12675efe89d9SLars-Peter Clausen wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL); 12685efe89d9SLars-Peter Clausen if (wm9713 == NULL) 12695efe89d9SLars-Peter Clausen return -ENOMEM; 12705efe89d9SLars-Peter Clausen 1271cf1f2ebeSLars-Peter Clausen mutex_init(&wm9713->lock); 1272cf1f2ebeSLars-Peter Clausen 12739bd400caSRobert Jarzmik wm9713->mfd_pdata = dev_get_platdata(&pdev->dev); 12745efe89d9SLars-Peter Clausen platform_set_drvdata(pdev, wm9713); 12755efe89d9SLars-Peter Clausen 12768ea99bc6SKuninori Morimoto return devm_snd_soc_register_component(&pdev->dev, 12778ea99bc6SKuninori Morimoto &soc_component_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai)); 1278f0fba2adSLiam Girdwood } 1279f0fba2adSLiam Girdwood 1280f0fba2adSLiam Girdwood static struct platform_driver wm9713_codec_driver = { 1281f0fba2adSLiam Girdwood .driver = { 1282f0fba2adSLiam Girdwood .name = "wm9713-codec", 1283f0fba2adSLiam Girdwood }, 1284f0fba2adSLiam Girdwood 1285f0fba2adSLiam Girdwood .probe = wm9713_probe, 1286f0fba2adSLiam Girdwood }; 1287f0fba2adSLiam Girdwood 12885bbcc3c0SMark Brown module_platform_driver(wm9713_codec_driver); 128983ac08c0SLiam Girdwood 129083ac08c0SLiam Girdwood MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver"); 129183ac08c0SLiam Girdwood MODULE_AUTHOR("Liam Girdwood"); 129283ac08c0SLiam Girdwood MODULE_LICENSE("GPL"); 1293