Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1 | /* |
| 2 | * wm9713.c -- ALSA Soc WM9713 codec support |
| 3 | * |
| 4 | * Copyright 2006 Wolfson Microelectronics PLC. |
| 5 | * Author: Liam Girdwood |
| 6 | * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 13 | * Features:- |
| 14 | * |
| 15 | * o Support for AC97 Codec, Voice DAC and Aux DAC |
| 16 | * o Support for DAPM |
| 17 | */ |
| 18 | |
| 19 | #include <linux/init.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/device.h> |
| 22 | #include <sound/core.h> |
| 23 | #include <sound/pcm.h> |
| 24 | #include <sound/ac97_codec.h> |
| 25 | #include <sound/initval.h> |
| 26 | #include <sound/pcm_params.h> |
| 27 | #include <sound/soc.h> |
| 28 | #include <sound/soc-dapm.h> |
| 29 | |
| 30 | #include "wm9713.h" |
| 31 | |
| 32 | #define WM9713_VERSION "0.15" |
| 33 | |
| 34 | struct wm9713_priv { |
| 35 | u32 pll_in; /* PLL input frequency */ |
| 36 | u32 pll_out; /* PLL output frequency */ |
| 37 | }; |
| 38 | |
| 39 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
| 40 | unsigned int reg); |
| 41 | static int ac97_write(struct snd_soc_codec *codec, |
| 42 | unsigned int reg, unsigned int val); |
| 43 | |
| 44 | /* |
| 45 | * WM9713 register cache |
| 46 | * Reg 0x3c bit 15 is used by touch driver. |
| 47 | */ |
| 48 | static const u16 wm9713_reg[] = { |
| 49 | 0x6174, 0x8080, 0x8080, 0x8080, |
| 50 | 0xc880, 0xe808, 0xe808, 0x0808, |
| 51 | 0x00da, 0x8000, 0xd600, 0xaaa0, |
| 52 | 0xaaa0, 0xaaa0, 0x0000, 0x0000, |
| 53 | 0x0f0f, 0x0040, 0x0000, 0x7f00, |
| 54 | 0x0405, 0x0410, 0xbb80, 0xbb80, |
| 55 | 0x0000, 0xbb80, 0x0000, 0x4523, |
| 56 | 0x0000, 0x2000, 0x7eff, 0xffff, |
| 57 | 0x0000, 0x0000, 0x0080, 0x0000, |
| 58 | 0x0000, 0x0000, 0xfffe, 0xffff, |
| 59 | 0x0000, 0x0000, 0x0000, 0xfffe, |
| 60 | 0x4000, 0x0000, 0x0000, 0x0000, |
| 61 | 0xb032, 0x3e00, 0x0000, 0x0000, |
| 62 | 0x0000, 0x0000, 0x0000, 0x0000, |
| 63 | 0x0000, 0x0000, 0x0000, 0x0006, |
| 64 | 0x0001, 0x0000, 0x574d, 0x4c13, |
| 65 | 0x0000, 0x0000, 0x0000 |
| 66 | }; |
| 67 | |
| 68 | /* virtual HP mixers regs */ |
| 69 | #define HPL_MIXER 0x80 |
| 70 | #define HPR_MIXER 0x82 |
| 71 | #define MICB_MUX 0x82 |
| 72 | |
| 73 | static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"}; |
| 74 | static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"}; |
| 75 | static const char *wm9713_rec_src[] = |
| 76 | {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker", |
| 77 | "Mono Out", "Zh"}; |
| 78 | static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"}; |
| 79 | static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"}; |
| 80 | static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv", |
| 81 | "Mono Vmid", "Inv Vmid"}; |
| 82 | static const char *wm9713_spk_pga[] = |
| 83 | {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid", |
| 84 | "Speaker Vmid", "Inv Vmid"}; |
| 85 | static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone", |
| 86 | "Headphone Vmid"}; |
| 87 | static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"}; |
| 88 | static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"}; |
| 89 | static const char *wm9713_dac_inv[] = |
| 90 | {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone", |
| 91 | "Headphone Mono", "NC", "Vmid"}; |
| 92 | static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"}; |
| 93 | static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"}; |
| 94 | static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"}; |
| 95 | static const char *wm9713_micb_select[] = {"MPB", "MPA"}; |
| 96 | |
| 97 | static const struct soc_enum wm9713_enum[] = { |
| 98 | SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */ |
| 99 | SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */ |
| 100 | SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */ |
| 101 | SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */ |
| 102 | SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/ |
| 103 | SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */ |
| 104 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/ |
| 105 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */ |
| 106 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */ |
| 107 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */ |
| 108 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */ |
| 109 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */ |
| 110 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */ |
| 111 | SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */ |
| 112 | SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */ |
| 113 | SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */ |
| 114 | SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */ |
| 115 | SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */ |
| 116 | SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */ |
| 117 | SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */ |
| 118 | }; |
| 119 | |
| 120 | static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = { |
| 121 | SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1), |
| 122 | SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1), |
| 123 | SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1), |
| 124 | SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1), |
| 125 | SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1), |
| 126 | SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1), |
| 127 | SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1), |
| 128 | SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1), |
| 129 | |
| 130 | SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0), |
| 131 | SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1), |
| 132 | |
| 133 | SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1), |
| 134 | SOC_ENUM("Capture Volume Steps", wm9713_enum[5]), |
| 135 | SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0), |
| 136 | SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0), |
| 137 | |
| 138 | SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1), |
| 139 | SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0), |
| 140 | SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0), |
| 141 | |
| 142 | SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0), |
| 143 | SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0), |
| 144 | SOC_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0), |
| 145 | SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0), |
| 146 | SOC_ENUM("ALC Function", wm9713_enum[6]), |
| 147 | SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0), |
| 148 | SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0), |
| 149 | SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0), |
| 150 | SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0), |
| 151 | SOC_ENUM("ALC NG Type", wm9713_enum[17]), |
| 152 | SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0), |
| 153 | |
| 154 | SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0), |
| 155 | SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0), |
| 156 | |
| 157 | SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1), |
| 158 | SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0), |
| 159 | SOC_SINGLE("Out4 Playback Volume", AC97_MASTER_MONO, 8, 63, 1), |
| 160 | |
| 161 | SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1), |
| 162 | SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0), |
| 163 | SOC_SINGLE("Out3 Playback Volume", AC97_MASTER_MONO, 0, 63, 1), |
| 164 | |
| 165 | SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1), |
| 166 | SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1), |
| 167 | SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0), |
| 168 | SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1), |
| 169 | |
| 170 | SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1), |
| 171 | SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1), |
| 172 | SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1), |
| 173 | |
| 174 | SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1), |
| 175 | SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1), |
| 176 | SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1), |
| 177 | |
| 178 | SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1), |
| 179 | SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1), |
| 180 | SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1), |
| 181 | |
| 182 | SOC_ENUM("Bass Control", wm9713_enum[16]), |
| 183 | SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1), |
| 184 | SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1), |
| 185 | SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0), |
| 186 | SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1), |
| 187 | SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1), |
| 188 | |
| 189 | SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0), |
| 190 | SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0), |
| 191 | SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1), |
| 192 | }; |
| 193 | |
| 194 | /* add non dapm controls */ |
| 195 | static int wm9713_add_controls(struct snd_soc_codec *codec) |
| 196 | { |
| 197 | int err, i; |
| 198 | |
| 199 | for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) { |
| 200 | err = snd_ctl_add(codec->card, |
| 201 | snd_soc_cnew(&wm9713_snd_ac97_controls[i], |
| 202 | codec, NULL)); |
| 203 | if (err < 0) |
| 204 | return err; |
| 205 | } |
| 206 | return 0; |
| 207 | } |
| 208 | |
| 209 | /* We have to create a fake left and right HP mixers because |
| 210 | * the codec only has a single control that is shared by both channels. |
| 211 | * This makes it impossible to determine the audio path using the current |
| 212 | * register map, thus we add a new (virtual) register to help determine the |
| 213 | * audio route within the device. |
| 214 | */ |
| 215 | static int mixer_event(struct snd_soc_dapm_widget *w, |
| 216 | struct snd_kcontrol *kcontrol, int event) |
| 217 | { |
| 218 | u16 l, r, beep, tone, phone, rec, pcm, aux; |
| 219 | |
| 220 | l = ac97_read(w->codec, HPL_MIXER); |
| 221 | r = ac97_read(w->codec, HPR_MIXER); |
| 222 | beep = ac97_read(w->codec, AC97_PC_BEEP); |
| 223 | tone = ac97_read(w->codec, AC97_MASTER_TONE); |
| 224 | phone = ac97_read(w->codec, AC97_PHONE); |
| 225 | rec = ac97_read(w->codec, AC97_REC_SEL); |
| 226 | pcm = ac97_read(w->codec, AC97_PCM); |
| 227 | aux = ac97_read(w->codec, AC97_AUX); |
| 228 | |
| 229 | if (event & SND_SOC_DAPM_PRE_REG) |
| 230 | return 0; |
| 231 | if ((l & 0x1) || (r & 0x1)) |
| 232 | ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff); |
| 233 | else |
| 234 | ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000); |
| 235 | |
| 236 | if ((l & 0x2) || (r & 0x2)) |
| 237 | ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff); |
| 238 | else |
| 239 | ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000); |
| 240 | |
| 241 | if ((l & 0x4) || (r & 0x4)) |
| 242 | ac97_write(w->codec, AC97_PHONE, phone & 0x7fff); |
| 243 | else |
| 244 | ac97_write(w->codec, AC97_PHONE, phone | 0x8000); |
| 245 | |
| 246 | if ((l & 0x8) || (r & 0x8)) |
| 247 | ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff); |
| 248 | else |
| 249 | ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000); |
| 250 | |
| 251 | if ((l & 0x10) || (r & 0x10)) |
| 252 | ac97_write(w->codec, AC97_PCM, pcm & 0x7fff); |
| 253 | else |
| 254 | ac97_write(w->codec, AC97_PCM, pcm | 0x8000); |
| 255 | |
| 256 | if ((l & 0x20) || (r & 0x20)) |
| 257 | ac97_write(w->codec, AC97_AUX, aux & 0x7fff); |
| 258 | else |
| 259 | ac97_write(w->codec, AC97_AUX, aux | 0x8000); |
| 260 | |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | /* Left Headphone Mixers */ |
| 265 | static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { |
| 266 | SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0), |
| 267 | SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0), |
| 268 | SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0), |
| 269 | SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0), |
| 270 | SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0), |
| 271 | SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0), |
| 272 | }; |
| 273 | |
| 274 | /* Right Headphone Mixers */ |
| 275 | static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { |
| 276 | SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0), |
| 277 | SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0), |
| 278 | SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0), |
| 279 | SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0), |
| 280 | SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0), |
| 281 | SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0), |
| 282 | }; |
| 283 | |
| 284 | /* headphone capture mux */ |
| 285 | static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls = |
| 286 | SOC_DAPM_ENUM("Route", wm9713_enum[1]); |
| 287 | |
| 288 | /* headphone mic mux */ |
| 289 | static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls = |
| 290 | SOC_DAPM_ENUM("Route", wm9713_enum[0]); |
| 291 | |
| 292 | /* Speaker Mixer */ |
| 293 | static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { |
| 294 | SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1), |
| 295 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1), |
| 296 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1), |
| 297 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), |
| 298 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1), |
| 299 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1), |
| 300 | }; |
| 301 | |
| 302 | /* Mono Mixer */ |
| 303 | static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { |
| 304 | SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1), |
| 305 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1), |
| 306 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1), |
| 307 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), |
| 308 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1), |
| 309 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1), |
| 310 | SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1), |
| 311 | SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1), |
| 312 | }; |
| 313 | |
| 314 | /* mono mic mux */ |
| 315 | static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls = |
| 316 | SOC_DAPM_ENUM("Route", wm9713_enum[2]); |
| 317 | |
| 318 | /* mono output mux */ |
| 319 | static const struct snd_kcontrol_new wm9713_mono_mux_controls = |
| 320 | SOC_DAPM_ENUM("Route", wm9713_enum[7]); |
| 321 | |
| 322 | /* speaker left output mux */ |
| 323 | static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls = |
| 324 | SOC_DAPM_ENUM("Route", wm9713_enum[8]); |
| 325 | |
| 326 | /* speaker right output mux */ |
| 327 | static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls = |
| 328 | SOC_DAPM_ENUM("Route", wm9713_enum[9]); |
| 329 | |
| 330 | /* headphone left output mux */ |
| 331 | static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls = |
| 332 | SOC_DAPM_ENUM("Route", wm9713_enum[10]); |
| 333 | |
| 334 | /* headphone right output mux */ |
| 335 | static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls = |
| 336 | SOC_DAPM_ENUM("Route", wm9713_enum[11]); |
| 337 | |
| 338 | /* Out3 mux */ |
| 339 | static const struct snd_kcontrol_new wm9713_out3_mux_controls = |
| 340 | SOC_DAPM_ENUM("Route", wm9713_enum[12]); |
| 341 | |
| 342 | /* Out4 mux */ |
| 343 | static const struct snd_kcontrol_new wm9713_out4_mux_controls = |
| 344 | SOC_DAPM_ENUM("Route", wm9713_enum[13]); |
| 345 | |
| 346 | /* DAC inv mux 1 */ |
| 347 | static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls = |
| 348 | SOC_DAPM_ENUM("Route", wm9713_enum[14]); |
| 349 | |
| 350 | /* DAC inv mux 2 */ |
| 351 | static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls = |
| 352 | SOC_DAPM_ENUM("Route", wm9713_enum[15]); |
| 353 | |
| 354 | /* Capture source left */ |
| 355 | static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls = |
| 356 | SOC_DAPM_ENUM("Route", wm9713_enum[3]); |
| 357 | |
| 358 | /* Capture source right */ |
| 359 | static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls = |
| 360 | SOC_DAPM_ENUM("Route", wm9713_enum[4]); |
| 361 | |
| 362 | /* mic source */ |
| 363 | static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls = |
| 364 | SOC_DAPM_ENUM("Route", wm9713_enum[18]); |
| 365 | |
| 366 | /* mic source B virtual control */ |
| 367 | static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls = |
| 368 | SOC_DAPM_ENUM("Route", wm9713_enum[19]); |
| 369 | |
| 370 | static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = { |
| 371 | SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 372 | &wm9713_hp_rec_mux_controls), |
| 373 | SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0, |
| 374 | &wm9713_hp_mic_mux_controls), |
| 375 | SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0, |
| 376 | &wm9713_mono_mic_mux_controls), |
| 377 | SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0, |
| 378 | &wm9713_mono_mux_controls), |
| 379 | SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0, |
| 380 | &wm9713_hp_spkl_mux_controls), |
| 381 | SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0, |
| 382 | &wm9713_hp_spkr_mux_controls), |
| 383 | SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0, |
| 384 | &wm9713_hpl_out_mux_controls), |
| 385 | SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0, |
| 386 | &wm9713_hpr_out_mux_controls), |
| 387 | SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0, |
| 388 | &wm9713_out3_mux_controls), |
| 389 | SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0, |
| 390 | &wm9713_out4_mux_controls), |
| 391 | SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0, |
| 392 | &wm9713_dac_inv1_mux_controls), |
| 393 | SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0, |
| 394 | &wm9713_dac_inv2_mux_controls), |
| 395 | SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, |
| 396 | &wm9713_rec_srcl_mux_controls), |
| 397 | SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, |
| 398 | &wm9713_rec_srcr_mux_controls), |
| 399 | SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0, |
| 400 | &wm9713_mic_sel_mux_controls), |
| 401 | SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0, |
| 402 | &wm9713_micb_sel_mux_controls), |
| 403 | SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, |
| 404 | &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls), |
| 405 | mixer_event, SND_SOC_DAPM_POST_REG), |
| 406 | SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, |
| 407 | &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls), |
| 408 | mixer_event, SND_SOC_DAPM_POST_REG), |
| 409 | SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, |
| 410 | &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)), |
| 411 | SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, |
| 412 | &wm9713_speaker_mixer_controls[0], |
| 413 | ARRAY_SIZE(wm9713_speaker_mixer_controls)), |
| 414 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1), |
| 415 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1), |
| 416 | SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 417 | SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 418 | SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 419 | SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 420 | SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1), |
| 421 | SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1), |
| 422 | SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_EXTENDED_MID, 5, 1), |
| 423 | SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_EXTENDED_MID, 4, 1), |
| 424 | SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0), |
| 425 | SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0), |
| 426 | SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0), |
| 427 | SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0), |
| 428 | SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0), |
| 429 | SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0), |
| 430 | SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0), |
| 431 | SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0), |
| 432 | SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0), |
| 433 | SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0), |
| 434 | SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0), |
| 435 | SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0), |
| 436 | SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0), |
| 437 | SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0), |
| 438 | SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1), |
| 439 | SND_SOC_DAPM_OUTPUT("MONO"), |
| 440 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 441 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 442 | SND_SOC_DAPM_OUTPUT("SPKL"), |
| 443 | SND_SOC_DAPM_OUTPUT("SPKR"), |
| 444 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 445 | SND_SOC_DAPM_OUTPUT("OUT4"), |
| 446 | SND_SOC_DAPM_INPUT("LINEL"), |
| 447 | SND_SOC_DAPM_INPUT("LINER"), |
| 448 | SND_SOC_DAPM_INPUT("MONOIN"), |
| 449 | SND_SOC_DAPM_INPUT("PCBEEP"), |
| 450 | SND_SOC_DAPM_INPUT("MIC1"), |
| 451 | SND_SOC_DAPM_INPUT("MIC2A"), |
| 452 | SND_SOC_DAPM_INPUT("MIC2B"), |
| 453 | SND_SOC_DAPM_VMID("VMID"), |
| 454 | }; |
| 455 | |
Mark Brown | a65f056 | 2008-05-13 14:54:43 +0200 | [diff] [blame^] | 456 | static const struct snd_soc_dapm_route audio_map[] = { |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 457 | /* left HP mixer */ |
| 458 | {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, |
| 459 | {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 460 | {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 461 | {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, |
| 462 | {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, |
| 463 | {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 464 | {"Left HP Mixer", NULL, "Capture Headphone Mux"}, |
| 465 | |
| 466 | /* right HP mixer */ |
| 467 | {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"}, |
| 468 | {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 469 | {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 470 | {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, |
| 471 | {"Right HP Mixer", "PCM Playback Switch", "Right DAC"}, |
| 472 | {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 473 | {"Right HP Mixer", NULL, "Capture Headphone Mux"}, |
| 474 | |
| 475 | /* virtual mixer - mixes left & right channels for spk and mono */ |
| 476 | {"AC97 Mixer", NULL, "Left DAC"}, |
| 477 | {"AC97 Mixer", NULL, "Right DAC"}, |
| 478 | {"Line Mixer", NULL, "Right Line In"}, |
| 479 | {"Line Mixer", NULL, "Left Line In"}, |
| 480 | {"HP Mixer", NULL, "Left HP Mixer"}, |
| 481 | {"HP Mixer", NULL, "Right HP Mixer"}, |
| 482 | {"Capture Mixer", NULL, "Left Capture Source"}, |
| 483 | {"Capture Mixer", NULL, "Right Capture Source"}, |
| 484 | |
| 485 | /* speaker mixer */ |
| 486 | {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"}, |
| 487 | {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 488 | {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 489 | {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, |
| 490 | {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
| 491 | {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 492 | |
| 493 | /* mono mixer */ |
| 494 | {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"}, |
| 495 | {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 496 | {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 497 | {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, |
| 498 | {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
Robert Jarzmik | c0bbf48 | 2008-03-18 12:08:35 +0100 | [diff] [blame] | 499 | {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"}, |
| 500 | {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 501 | {"Mono Mixer", NULL, "Capture Mono Mux"}, |
| 502 | |
| 503 | /* DAC inv mux 1 */ |
| 504 | {"DAC Inv Mux 1", "Mono", "Mono Mixer"}, |
| 505 | {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"}, |
| 506 | {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"}, |
| 507 | {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"}, |
| 508 | {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"}, |
| 509 | |
| 510 | /* DAC inv mux 2 */ |
| 511 | {"DAC Inv Mux 2", "Mono", "Mono Mixer"}, |
| 512 | {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"}, |
| 513 | {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"}, |
| 514 | {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"}, |
| 515 | {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"}, |
| 516 | |
| 517 | /* headphone left mux */ |
| 518 | {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"}, |
| 519 | |
| 520 | /* headphone right mux */ |
| 521 | {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"}, |
| 522 | |
| 523 | /* speaker left mux */ |
| 524 | {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"}, |
| 525 | {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"}, |
| 526 | {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"}, |
| 527 | |
| 528 | /* speaker right mux */ |
| 529 | {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"}, |
| 530 | {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"}, |
| 531 | {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"}, |
| 532 | |
| 533 | /* mono mux */ |
| 534 | {"Mono Out Mux", "Mono", "Mono Mixer"}, |
| 535 | {"Mono Out Mux", "Inv", "DAC Inv Mux 1"}, |
| 536 | |
| 537 | /* out 3 mux */ |
| 538 | {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"}, |
| 539 | |
| 540 | /* out 4 mux */ |
| 541 | {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"}, |
| 542 | |
| 543 | /* output pga */ |
| 544 | {"HPL", NULL, "Left Headphone"}, |
| 545 | {"Left Headphone", NULL, "Left Headphone Out Mux"}, |
| 546 | {"HPR", NULL, "Right Headphone"}, |
| 547 | {"Right Headphone", NULL, "Right Headphone Out Mux"}, |
| 548 | {"OUT3", NULL, "Out 3"}, |
| 549 | {"Out 3", NULL, "Out 3 Mux"}, |
| 550 | {"OUT4", NULL, "Out 4"}, |
| 551 | {"Out 4", NULL, "Out 4 Mux"}, |
| 552 | {"SPKL", NULL, "Left Speaker"}, |
| 553 | {"Left Speaker", NULL, "Left Speaker Out Mux"}, |
| 554 | {"SPKR", NULL, "Right Speaker"}, |
| 555 | {"Right Speaker", NULL, "Right Speaker Out Mux"}, |
| 556 | {"MONO", NULL, "Mono Out"}, |
| 557 | {"Mono Out", NULL, "Mono Out Mux"}, |
| 558 | |
| 559 | /* input pga */ |
| 560 | {"Left Line In", NULL, "LINEL"}, |
| 561 | {"Right Line In", NULL, "LINER"}, |
| 562 | {"Mono In", NULL, "MONOIN"}, |
| 563 | {"Mic A PGA", NULL, "Mic A Pre Amp"}, |
| 564 | {"Mic B PGA", NULL, "Mic B Pre Amp"}, |
| 565 | |
| 566 | /* left capture select */ |
| 567 | {"Left Capture Source", "Mic 1", "Mic A Pre Amp"}, |
| 568 | {"Left Capture Source", "Mic 2", "Mic B Pre Amp"}, |
| 569 | {"Left Capture Source", "Line", "LINEL"}, |
| 570 | {"Left Capture Source", "Mono In", "MONOIN"}, |
| 571 | {"Left Capture Source", "Headphone", "Left HP Mixer"}, |
| 572 | {"Left Capture Source", "Speaker", "Speaker Mixer"}, |
| 573 | {"Left Capture Source", "Mono Out", "Mono Mixer"}, |
| 574 | |
| 575 | /* right capture select */ |
| 576 | {"Right Capture Source", "Mic 1", "Mic A Pre Amp"}, |
| 577 | {"Right Capture Source", "Mic 2", "Mic B Pre Amp"}, |
| 578 | {"Right Capture Source", "Line", "LINER"}, |
| 579 | {"Right Capture Source", "Mono In", "MONOIN"}, |
| 580 | {"Right Capture Source", "Headphone", "Right HP Mixer"}, |
| 581 | {"Right Capture Source", "Speaker", "Speaker Mixer"}, |
| 582 | {"Right Capture Source", "Mono Out", "Mono Mixer"}, |
| 583 | |
| 584 | /* left ADC */ |
| 585 | {"Left ADC", NULL, "Left Capture Source"}, |
| 586 | |
| 587 | /* right ADC */ |
| 588 | {"Right ADC", NULL, "Right Capture Source"}, |
| 589 | |
| 590 | /* mic */ |
| 591 | {"Mic A Pre Amp", NULL, "Mic A Source"}, |
| 592 | {"Mic A Source", "Mic 1", "MIC1"}, |
| 593 | {"Mic A Source", "Mic 2 A", "MIC2A"}, |
| 594 | {"Mic A Source", "Mic 2 B", "Mic B Source"}, |
| 595 | {"Mic B Pre Amp", "MPB", "Mic B Source"}, |
| 596 | {"Mic B Source", NULL, "MIC2B"}, |
| 597 | |
| 598 | /* headphone capture */ |
| 599 | {"Capture Headphone Mux", "Stereo", "Capture Mixer"}, |
| 600 | {"Capture Headphone Mux", "Left", "Left Capture Source"}, |
| 601 | {"Capture Headphone Mux", "Right", "Right Capture Source"}, |
| 602 | |
| 603 | /* mono capture */ |
| 604 | {"Capture Mono Mux", "Stereo", "Capture Mixer"}, |
| 605 | {"Capture Mono Mux", "Left", "Left Capture Source"}, |
| 606 | {"Capture Mono Mux", "Right", "Right Capture Source"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 607 | }; |
| 608 | |
| 609 | static int wm9713_add_widgets(struct snd_soc_codec *codec) |
| 610 | { |
Mark Brown | a65f056 | 2008-05-13 14:54:43 +0200 | [diff] [blame^] | 611 | snd_soc_dapm_new_controls(codec, wm9713_dapm_widgets, |
| 612 | ARRAY_SIZE(wm9713_dapm_widgets)); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 613 | |
Mark Brown | a65f056 | 2008-05-13 14:54:43 +0200 | [diff] [blame^] | 614 | snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map)); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 615 | |
| 616 | snd_soc_dapm_new_widgets(codec); |
| 617 | return 0; |
| 618 | } |
| 619 | |
| 620 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
| 621 | unsigned int reg) |
| 622 | { |
| 623 | u16 *cache = codec->reg_cache; |
| 624 | |
| 625 | if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || |
| 626 | reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || |
| 627 | reg == AC97_CD) |
| 628 | return soc_ac97_ops.read(codec->ac97, reg); |
| 629 | else { |
| 630 | reg = reg >> 1; |
| 631 | |
| 632 | if (reg > (ARRAY_SIZE(wm9713_reg))) |
| 633 | return -EIO; |
| 634 | |
| 635 | return cache[reg]; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, |
| 640 | unsigned int val) |
| 641 | { |
| 642 | u16 *cache = codec->reg_cache; |
| 643 | if (reg < 0x7c) |
| 644 | soc_ac97_ops.write(codec->ac97, reg, val); |
| 645 | reg = reg >> 1; |
| 646 | if (reg <= (ARRAY_SIZE(wm9713_reg))) |
| 647 | cache[reg] = val; |
| 648 | |
| 649 | return 0; |
| 650 | } |
| 651 | |
| 652 | /* PLL divisors */ |
| 653 | struct _pll_div { |
| 654 | u32 divsel:1; |
| 655 | u32 divctl:1; |
| 656 | u32 lf:1; |
| 657 | u32 n:4; |
| 658 | u32 k:24; |
| 659 | }; |
| 660 | |
| 661 | /* The size in bits of the PLL divide multiplied by 10 |
| 662 | * to allow rounding later */ |
| 663 | #define FIXED_PLL_SIZE ((1 << 22) * 10) |
| 664 | |
| 665 | static void pll_factors(struct _pll_div *pll_div, unsigned int source) |
| 666 | { |
| 667 | u64 Kpart; |
| 668 | unsigned int K, Ndiv, Nmod, target; |
| 669 | |
| 670 | /* The the PLL output is always 98.304MHz. */ |
| 671 | target = 98304000; |
| 672 | |
| 673 | /* If the input frequency is over 14.4MHz then scale it down. */ |
| 674 | if (source > 14400000) { |
| 675 | source >>= 1; |
| 676 | pll_div->divsel = 1; |
| 677 | |
| 678 | if (source > 14400000) { |
| 679 | source >>= 1; |
| 680 | pll_div->divctl = 1; |
| 681 | } else |
| 682 | pll_div->divctl = 0; |
| 683 | |
| 684 | } else { |
| 685 | pll_div->divsel = 0; |
| 686 | pll_div->divctl = 0; |
| 687 | } |
| 688 | |
| 689 | /* Low frequency sources require an additional divide in the |
| 690 | * loop. |
| 691 | */ |
| 692 | if (source < 8192000) { |
| 693 | pll_div->lf = 1; |
| 694 | target >>= 2; |
| 695 | } else |
| 696 | pll_div->lf = 0; |
| 697 | |
| 698 | Ndiv = target / source; |
| 699 | if ((Ndiv < 5) || (Ndiv > 12)) |
| 700 | printk(KERN_WARNING |
| 701 | "WM9713 PLL N value %d out of recommended range!\n", |
| 702 | Ndiv); |
| 703 | |
| 704 | pll_div->n = Ndiv; |
| 705 | Nmod = target % source; |
| 706 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; |
| 707 | |
| 708 | do_div(Kpart, source); |
| 709 | |
| 710 | K = Kpart & 0xFFFFFFFF; |
| 711 | |
| 712 | /* Check if we need to round */ |
| 713 | if ((K % 10) >= 5) |
| 714 | K += 5; |
| 715 | |
| 716 | /* Move down to proper range now rounding is done */ |
| 717 | K /= 10; |
| 718 | |
| 719 | pll_div->k = K; |
| 720 | } |
| 721 | |
| 722 | /** |
| 723 | * Please note that changing the PLL input frequency may require |
| 724 | * resynchronisation with the AC97 controller. |
| 725 | */ |
| 726 | static int wm9713_set_pll(struct snd_soc_codec *codec, |
| 727 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
| 728 | { |
| 729 | struct wm9713_priv *wm9713 = codec->private_data; |
| 730 | u16 reg, reg2; |
| 731 | struct _pll_div pll_div; |
| 732 | |
| 733 | /* turn PLL off ? */ |
| 734 | if (freq_in == 0 || freq_out == 0) { |
| 735 | /* disable PLL power and select ext source */ |
| 736 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
| 737 | ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); |
| 738 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 739 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); |
| 740 | wm9713->pll_out = 0; |
| 741 | return 0; |
| 742 | } |
| 743 | |
| 744 | pll_factors(&pll_div, freq_in); |
| 745 | |
| 746 | if (pll_div.k == 0) { |
| 747 | reg = (pll_div.n << 12) | (pll_div.lf << 11) | |
| 748 | (pll_div.divsel << 9) | (pll_div.divctl << 8); |
| 749 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 750 | } else { |
| 751 | /* write the fractional k to the reg 0x46 pages */ |
| 752 | reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) | |
| 753 | (pll_div.divsel << 9) | (pll_div.divctl << 8); |
| 754 | |
| 755 | /* K [21:20] */ |
| 756 | reg = reg2 | (0x5 << 4) | (pll_div.k >> 20); |
| 757 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 758 | |
| 759 | /* K [19:16] */ |
| 760 | reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf); |
| 761 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 762 | |
| 763 | /* K [15:12] */ |
| 764 | reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf); |
| 765 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 766 | |
| 767 | /* K [11:8] */ |
| 768 | reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf); |
| 769 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 770 | |
| 771 | /* K [7:4] */ |
| 772 | reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf); |
| 773 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 774 | |
| 775 | reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */ |
| 776 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 777 | } |
| 778 | |
| 779 | /* turn PLL on and select as source */ |
| 780 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 781 | ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); |
| 782 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
| 783 | ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); |
| 784 | wm9713->pll_out = freq_out; |
| 785 | wm9713->pll_in = freq_in; |
| 786 | |
| 787 | /* wait 10ms AC97 link frames for the link to stabilise */ |
| 788 | schedule_timeout_interruptible(msecs_to_jiffies(10)); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai, |
| 793 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
| 794 | { |
| 795 | struct snd_soc_codec *codec = codec_dai->codec; |
| 796 | return wm9713_set_pll(codec, pll_id, freq_in, freq_out); |
| 797 | } |
| 798 | |
| 799 | /* |
| 800 | * Tristate the PCM DAI lines, tristate can be disabled by calling |
| 801 | * wm9713_set_dai_fmt() |
| 802 | */ |
| 803 | static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai, |
| 804 | int tristate) |
| 805 | { |
| 806 | struct snd_soc_codec *codec = codec_dai->codec; |
| 807 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff; |
| 808 | |
| 809 | if (tristate) |
| 810 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 811 | |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | /* |
| 816 | * Configure WM9713 clock dividers. |
| 817 | * Voice DAC needs 256 FS |
| 818 | */ |
| 819 | static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai, |
| 820 | int div_id, int div) |
| 821 | { |
| 822 | struct snd_soc_codec *codec = codec_dai->codec; |
| 823 | u16 reg; |
| 824 | |
| 825 | switch (div_id) { |
| 826 | case WM9713_PCMCLK_DIV: |
| 827 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff; |
| 828 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 829 | break; |
| 830 | case WM9713_CLKA_MULT: |
| 831 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd; |
| 832 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 833 | break; |
| 834 | case WM9713_CLKB_MULT: |
| 835 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb; |
| 836 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 837 | break; |
| 838 | case WM9713_HIFI_DIV: |
| 839 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff; |
| 840 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 841 | break; |
| 842 | case WM9713_PCMBCLK_DIV: |
| 843 | reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff; |
| 844 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div); |
| 845 | break; |
| 846 | case WM9713_PCMCLK_PLL_DIV: |
| 847 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; |
| 848 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div); |
| 849 | break; |
| 850 | case WM9713_HIFI_PLL_DIV: |
| 851 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; |
| 852 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div); |
| 853 | break; |
| 854 | default: |
| 855 | return -EINVAL; |
| 856 | } |
| 857 | |
| 858 | return 0; |
| 859 | } |
| 860 | |
| 861 | static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai, |
| 862 | unsigned int fmt) |
| 863 | { |
| 864 | struct snd_soc_codec *codec = codec_dai->codec; |
| 865 | u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5; |
| 866 | u16 reg = 0x8000; |
| 867 | |
| 868 | /* clock masters */ |
| 869 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 870 | case SND_SOC_DAIFMT_CBM_CFM: |
| 871 | reg |= 0x4000; |
| 872 | gpio |= 0x0010; |
| 873 | break; |
| 874 | case SND_SOC_DAIFMT_CBM_CFS: |
| 875 | reg |= 0x6000; |
| 876 | gpio |= 0x0018; |
| 877 | break; |
| 878 | case SND_SOC_DAIFMT_CBS_CFS: |
| 879 | reg |= 0x0200; |
| 880 | gpio |= 0x001a; |
| 881 | break; |
| 882 | case SND_SOC_DAIFMT_CBS_CFM: |
| 883 | gpio |= 0x0012; |
| 884 | break; |
| 885 | } |
| 886 | |
| 887 | /* clock inversion */ |
| 888 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 889 | case SND_SOC_DAIFMT_IB_IF: |
| 890 | reg |= 0x00c0; |
| 891 | break; |
| 892 | case SND_SOC_DAIFMT_IB_NF: |
| 893 | reg |= 0x0080; |
| 894 | break; |
| 895 | case SND_SOC_DAIFMT_NB_IF: |
| 896 | reg |= 0x0040; |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | /* DAI format */ |
| 901 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 902 | case SND_SOC_DAIFMT_I2S: |
| 903 | reg |= 0x0002; |
| 904 | break; |
| 905 | case SND_SOC_DAIFMT_RIGHT_J: |
| 906 | break; |
| 907 | case SND_SOC_DAIFMT_LEFT_J: |
| 908 | reg |= 0x0001; |
| 909 | break; |
| 910 | case SND_SOC_DAIFMT_DSP_A: |
| 911 | reg |= 0x0003; |
| 912 | break; |
| 913 | case SND_SOC_DAIFMT_DSP_B: |
| 914 | reg |= 0x0043; |
| 915 | break; |
| 916 | } |
| 917 | |
| 918 | ac97_write(codec, AC97_GPIO_CFG, gpio); |
| 919 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 920 | return 0; |
| 921 | } |
| 922 | |
| 923 | static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, |
| 924 | struct snd_pcm_hw_params *params) |
| 925 | { |
| 926 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 927 | struct snd_soc_device *socdev = rtd->socdev; |
| 928 | struct snd_soc_codec *codec = socdev->codec; |
| 929 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3; |
| 930 | |
| 931 | switch (params_format(params)) { |
| 932 | case SNDRV_PCM_FORMAT_S16_LE: |
| 933 | break; |
| 934 | case SNDRV_PCM_FORMAT_S20_3LE: |
| 935 | reg |= 0x0004; |
| 936 | break; |
| 937 | case SNDRV_PCM_FORMAT_S24_LE: |
| 938 | reg |= 0x0008; |
| 939 | break; |
| 940 | case SNDRV_PCM_FORMAT_S32_LE: |
| 941 | reg |= 0x000c; |
| 942 | break; |
| 943 | } |
| 944 | |
| 945 | /* enable PCM interface in master mode */ |
| 946 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | static void wm9713_voiceshutdown(struct snd_pcm_substream *substream) |
| 951 | { |
| 952 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 953 | struct snd_soc_device *socdev = rtd->socdev; |
| 954 | struct snd_soc_codec *codec = socdev->codec; |
| 955 | u16 status; |
| 956 | |
| 957 | /* Gracefully shut down the voice interface. */ |
| 958 | status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000; |
| 959 | ac97_write(codec, AC97_HANDSET_RATE, 0x0280); |
| 960 | schedule_timeout_interruptible(msecs_to_jiffies(1)); |
| 961 | ac97_write(codec, AC97_HANDSET_RATE, 0x0F80); |
| 962 | ac97_write(codec, AC97_EXTENDED_MID, status); |
| 963 | } |
| 964 | |
| 965 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream) |
| 966 | { |
| 967 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 968 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 969 | struct snd_soc_device *socdev = rtd->socdev; |
| 970 | struct snd_soc_codec *codec = socdev->codec; |
| 971 | int reg; |
| 972 | u16 vra; |
| 973 | |
| 974 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 975 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 976 | |
| 977 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 978 | reg = AC97_PCM_FRONT_DAC_RATE; |
| 979 | else |
| 980 | reg = AC97_PCM_LR_ADC_RATE; |
| 981 | |
| 982 | return ac97_write(codec, reg, runtime->rate); |
| 983 | } |
| 984 | |
| 985 | static int ac97_aux_prepare(struct snd_pcm_substream *substream) |
| 986 | { |
| 987 | struct snd_pcm_runtime *runtime = substream->runtime; |
| 988 | struct snd_soc_pcm_runtime *rtd = substream->private_data; |
| 989 | struct snd_soc_device *socdev = rtd->socdev; |
| 990 | struct snd_soc_codec *codec = socdev->codec; |
| 991 | u16 vra, xsle; |
| 992 | |
| 993 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 994 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 995 | xsle = ac97_read(codec, AC97_PCI_SID); |
| 996 | ac97_write(codec, AC97_PCI_SID, xsle | 0x8000); |
| 997 | |
| 998 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 999 | return -ENODEV; |
| 1000 | |
| 1001 | return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate); |
| 1002 | } |
| 1003 | |
| 1004 | #define WM9713_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ |
| 1005 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\ |
| 1006 | SNDRV_PCM_RATE_48000) |
| 1007 | |
| 1008 | #define WM9713_PCM_FORMATS \ |
| 1009 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ |
| 1010 | SNDRV_PCM_FORMAT_S24_LE) |
| 1011 | |
| 1012 | struct snd_soc_codec_dai wm9713_dai[] = { |
| 1013 | { |
| 1014 | .name = "AC97 HiFi", |
| 1015 | .type = SND_SOC_DAI_AC97_BUS, |
| 1016 | .playback = { |
| 1017 | .stream_name = "HiFi Playback", |
| 1018 | .channels_min = 1, |
| 1019 | .channels_max = 2, |
| 1020 | .rates = WM9713_RATES, |
| 1021 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 1022 | .capture = { |
| 1023 | .stream_name = "HiFi Capture", |
| 1024 | .channels_min = 1, |
| 1025 | .channels_max = 2, |
| 1026 | .rates = WM9713_RATES, |
| 1027 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 1028 | .ops = { |
| 1029 | .prepare = ac97_hifi_prepare,}, |
| 1030 | .dai_ops = { |
| 1031 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1032 | .set_pll = wm9713_set_dai_pll,}, |
| 1033 | }, |
| 1034 | { |
| 1035 | .name = "AC97 Aux", |
| 1036 | .playback = { |
| 1037 | .stream_name = "Aux Playback", |
| 1038 | .channels_min = 1, |
| 1039 | .channels_max = 1, |
| 1040 | .rates = WM9713_RATES, |
| 1041 | .formats = SNDRV_PCM_FMTBIT_S16_LE,}, |
| 1042 | .ops = { |
| 1043 | .prepare = ac97_aux_prepare,}, |
| 1044 | .dai_ops = { |
| 1045 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1046 | .set_pll = wm9713_set_dai_pll,}, |
| 1047 | }, |
| 1048 | { |
| 1049 | .name = "WM9713 Voice", |
| 1050 | .playback = { |
| 1051 | .stream_name = "Voice Playback", |
| 1052 | .channels_min = 1, |
| 1053 | .channels_max = 1, |
| 1054 | .rates = WM9713_RATES, |
| 1055 | .formats = WM9713_PCM_FORMATS,}, |
| 1056 | .capture = { |
| 1057 | .stream_name = "Voice Capture", |
| 1058 | .channels_min = 1, |
| 1059 | .channels_max = 2, |
| 1060 | .rates = WM9713_RATES, |
| 1061 | .formats = WM9713_PCM_FORMATS,}, |
| 1062 | .ops = { |
| 1063 | .hw_params = wm9713_pcm_hw_params, |
| 1064 | .shutdown = wm9713_voiceshutdown,}, |
| 1065 | .dai_ops = { |
| 1066 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1067 | .set_pll = wm9713_set_dai_pll, |
| 1068 | .set_fmt = wm9713_set_dai_fmt, |
| 1069 | .set_tristate = wm9713_set_dai_tristate, |
| 1070 | }, |
| 1071 | }, |
| 1072 | }; |
| 1073 | EXPORT_SYMBOL_GPL(wm9713_dai); |
| 1074 | |
| 1075 | int wm9713_reset(struct snd_soc_codec *codec, int try_warm) |
| 1076 | { |
| 1077 | if (try_warm && soc_ac97_ops.warm_reset) { |
| 1078 | soc_ac97_ops.warm_reset(codec->ac97); |
| 1079 | if (!(ac97_read(codec, 0) & 0x8000)) |
| 1080 | return 1; |
| 1081 | } |
| 1082 | |
| 1083 | soc_ac97_ops.reset(codec->ac97); |
| 1084 | if (ac97_read(codec, 0) & 0x8000) |
| 1085 | return -EIO; |
| 1086 | return 0; |
| 1087 | } |
| 1088 | EXPORT_SYMBOL_GPL(wm9713_reset); |
| 1089 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1090 | static int wm9713_set_bias_level(struct snd_soc_codec *codec, |
| 1091 | enum snd_soc_bias_level level) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1092 | { |
| 1093 | u16 reg; |
| 1094 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1095 | switch (level) { |
| 1096 | case SND_SOC_BIAS_ON: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1097 | /* enable thermal shutdown */ |
| 1098 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff; |
| 1099 | ac97_write(codec, AC97_EXTENDED_MID, reg); |
| 1100 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1101 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1102 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1103 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1104 | /* enable master bias and vmid */ |
| 1105 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff; |
| 1106 | ac97_write(codec, AC97_EXTENDED_MID, reg); |
| 1107 | ac97_write(codec, AC97_POWERDOWN, 0x0000); |
| 1108 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1109 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1110 | /* disable everything including AC link */ |
| 1111 | ac97_write(codec, AC97_EXTENDED_MID, 0xffff); |
| 1112 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); |
| 1113 | ac97_write(codec, AC97_POWERDOWN, 0xffff); |
| 1114 | break; |
| 1115 | } |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1116 | codec->bias_level = level; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1117 | return 0; |
| 1118 | } |
| 1119 | |
| 1120 | static int wm9713_soc_suspend(struct platform_device *pdev, |
| 1121 | pm_message_t state) |
| 1122 | { |
| 1123 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1124 | struct snd_soc_codec *codec = socdev->codec; |
Mark Brown | 87b57fe | 2008-04-14 15:27:30 +0200 | [diff] [blame] | 1125 | u16 reg; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1126 | |
Mark Brown | 87b57fe | 2008-04-14 15:27:30 +0200 | [diff] [blame] | 1127 | /* Disable everything except touchpanel - that will be handled |
| 1128 | * by the touch driver and left disabled if touch is not in |
| 1129 | * use. */ |
| 1130 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 1131 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff); |
| 1132 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); |
| 1133 | ac97_write(codec, AC97_POWERDOWN, 0x6f00); |
| 1134 | ac97_write(codec, AC97_POWERDOWN, 0xffff); |
| 1135 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1136 | return 0; |
| 1137 | } |
| 1138 | |
| 1139 | static int wm9713_soc_resume(struct platform_device *pdev) |
| 1140 | { |
| 1141 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1142 | struct snd_soc_codec *codec = socdev->codec; |
| 1143 | struct wm9713_priv *wm9713 = codec->private_data; |
| 1144 | int i, ret; |
| 1145 | u16 *cache = codec->reg_cache; |
| 1146 | |
| 1147 | ret = wm9713_reset(codec, 1); |
| 1148 | if (ret < 0) { |
| 1149 | printk(KERN_ERR "could not reset AC97 codec\n"); |
| 1150 | return ret; |
| 1151 | } |
| 1152 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1153 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1154 | |
| 1155 | /* do we need to re-start the PLL ? */ |
| 1156 | if (wm9713->pll_out) |
| 1157 | wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out); |
| 1158 | |
| 1159 | /* only synchronise the codec if warm reset failed */ |
| 1160 | if (ret == 0) { |
| 1161 | for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) { |
| 1162 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID || |
| 1163 | i == AC97_EXTENDED_MSTATUS || i > 0x66) |
| 1164 | continue; |
| 1165 | soc_ac97_ops.write(codec->ac97, i, cache[i>>1]); |
| 1166 | } |
| 1167 | } |
| 1168 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1169 | if (codec->suspend_bias_level == SND_SOC_BIAS_ON) |
| 1170 | wm9713_set_bias_level(codec, SND_SOC_BIAS_ON); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1171 | |
| 1172 | return ret; |
| 1173 | } |
| 1174 | |
| 1175 | static int wm9713_soc_probe(struct platform_device *pdev) |
| 1176 | { |
| 1177 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1178 | struct snd_soc_codec *codec; |
| 1179 | int ret = 0, reg; |
| 1180 | |
| 1181 | printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION); |
| 1182 | |
| 1183 | socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); |
| 1184 | if (socdev->codec == NULL) |
| 1185 | return -ENOMEM; |
| 1186 | codec = socdev->codec; |
| 1187 | mutex_init(&codec->mutex); |
| 1188 | |
| 1189 | codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL); |
| 1190 | if (codec->reg_cache == NULL) { |
| 1191 | ret = -ENOMEM; |
| 1192 | goto cache_err; |
| 1193 | } |
| 1194 | codec->reg_cache_size = sizeof(wm9713_reg); |
| 1195 | codec->reg_cache_step = 2; |
| 1196 | |
| 1197 | codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL); |
| 1198 | if (codec->private_data == NULL) { |
| 1199 | ret = -ENOMEM; |
| 1200 | goto priv_err; |
| 1201 | } |
| 1202 | |
| 1203 | codec->name = "WM9713"; |
| 1204 | codec->owner = THIS_MODULE; |
| 1205 | codec->dai = wm9713_dai; |
| 1206 | codec->num_dai = ARRAY_SIZE(wm9713_dai); |
| 1207 | codec->write = ac97_write; |
| 1208 | codec->read = ac97_read; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1209 | codec->set_bias_level = wm9713_set_bias_level; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1210 | INIT_LIST_HEAD(&codec->dapm_widgets); |
| 1211 | INIT_LIST_HEAD(&codec->dapm_paths); |
| 1212 | |
| 1213 | ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0); |
| 1214 | if (ret < 0) |
| 1215 | goto codec_err; |
| 1216 | |
| 1217 | /* register pcms */ |
| 1218 | ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); |
| 1219 | if (ret < 0) |
| 1220 | goto pcm_err; |
| 1221 | |
| 1222 | /* do a cold reset for the controller and then try |
| 1223 | * a warm reset followed by an optional cold reset for codec */ |
| 1224 | wm9713_reset(codec, 0); |
| 1225 | ret = wm9713_reset(codec, 1); |
| 1226 | if (ret < 0) { |
| 1227 | printk(KERN_ERR "AC97 link error\n"); |
| 1228 | goto reset_err; |
| 1229 | } |
| 1230 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1231 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1232 | |
| 1233 | /* unmute the adc - move to kcontrol */ |
| 1234 | reg = ac97_read(codec, AC97_CD) & 0x7fff; |
| 1235 | ac97_write(codec, AC97_CD, reg); |
| 1236 | |
| 1237 | wm9713_add_controls(codec); |
| 1238 | wm9713_add_widgets(codec); |
| 1239 | ret = snd_soc_register_card(socdev); |
| 1240 | if (ret < 0) |
| 1241 | goto reset_err; |
| 1242 | return 0; |
| 1243 | |
| 1244 | reset_err: |
| 1245 | snd_soc_free_pcms(socdev); |
| 1246 | |
| 1247 | pcm_err: |
| 1248 | snd_soc_free_ac97_codec(codec); |
| 1249 | |
| 1250 | codec_err: |
| 1251 | kfree(codec->private_data); |
| 1252 | |
| 1253 | priv_err: |
| 1254 | kfree(codec->reg_cache); |
| 1255 | |
| 1256 | cache_err: |
| 1257 | kfree(socdev->codec); |
| 1258 | socdev->codec = NULL; |
| 1259 | return ret; |
| 1260 | } |
| 1261 | |
| 1262 | static int wm9713_soc_remove(struct platform_device *pdev) |
| 1263 | { |
| 1264 | struct snd_soc_device *socdev = platform_get_drvdata(pdev); |
| 1265 | struct snd_soc_codec *codec = socdev->codec; |
| 1266 | |
| 1267 | if (codec == NULL) |
| 1268 | return 0; |
| 1269 | |
| 1270 | snd_soc_dapm_free(socdev); |
| 1271 | snd_soc_free_pcms(socdev); |
| 1272 | snd_soc_free_ac97_codec(codec); |
| 1273 | kfree(codec->private_data); |
| 1274 | kfree(codec->reg_cache); |
| 1275 | kfree(codec->dai); |
| 1276 | kfree(codec); |
| 1277 | return 0; |
| 1278 | } |
| 1279 | |
| 1280 | struct snd_soc_codec_device soc_codec_dev_wm9713 = { |
| 1281 | .probe = wm9713_soc_probe, |
| 1282 | .remove = wm9713_soc_remove, |
| 1283 | .suspend = wm9713_soc_suspend, |
| 1284 | .resume = wm9713_soc_resume, |
| 1285 | }; |
| 1286 | EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713); |
| 1287 | |
| 1288 | MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver"); |
| 1289 | MODULE_AUTHOR("Liam Girdwood"); |
| 1290 | MODULE_LICENSE("GPL"); |