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