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 { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 33 | struct snd_ac97 *ac97; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 34 | u32 pll_in; /* PLL input frequency */ |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 35 | unsigned int hp_mixer[2]; |
| 36 | struct mutex lock; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 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, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 67 | #define HPL_MIXER 0 |
| 68 | #define HPR_MIXER 1 |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 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 */ |
Lars-Peter Clausen | 5bc39b5 | 2014-10-30 21:01:10 +0100 | [diff] [blame] | 113 | SOC_ENUM_SINGLE_VIRT(2, wm9713_micb_select), /* mic selection 19 */ |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 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 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 237 | static const unsigned int wm9713_mixer_mute_regs[] = { |
| 238 | AC97_PC_BEEP, |
| 239 | AC97_MASTER_TONE, |
| 240 | AC97_PHONE, |
| 241 | AC97_REC_SEL, |
| 242 | AC97_PCM, |
| 243 | AC97_AUX, |
| 244 | }; |
Mark Brown | 6bbcb45 | 2009-04-13 11:29:10 +0100 | [diff] [blame] | 245 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 246 | /* We have to create a fake left and right HP mixers because |
| 247 | * the codec only has a single control that is shared by both channels. |
| 248 | * This makes it impossible to determine the audio path using the current |
| 249 | * register map, thus we add a new (virtual) register to help determine the |
| 250 | * audio route within the device. |
| 251 | */ |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 252 | static int wm9713_hp_mixer_put(struct snd_kcontrol *kcontrol, |
| 253 | struct snd_ctl_elem_value *ucontrol) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 254 | { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 255 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 256 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 257 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
| 258 | unsigned int val = ucontrol->value.enumerated.item[0]; |
| 259 | struct soc_mixer_control *mc = |
| 260 | (struct soc_mixer_control *)kcontrol->private_value; |
| 261 | unsigned int mixer, mask, shift, old; |
| 262 | struct snd_soc_dapm_update update; |
| 263 | bool change; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 264 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 265 | mixer = mc->shift >> 8; |
| 266 | shift = mc->shift & 0xff; |
| 267 | mask = (1 << shift); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 268 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 269 | mutex_lock(&wm9713->lock); |
| 270 | old = wm9713->hp_mixer[mixer]; |
| 271 | if (ucontrol->value.enumerated.item[0]) |
| 272 | wm9713->hp_mixer[mixer] |= mask; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 273 | else |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 274 | wm9713->hp_mixer[mixer] &= ~mask; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 275 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 276 | change = old != wm9713->hp_mixer[mixer]; |
| 277 | if (change) { |
| 278 | update.kcontrol = kcontrol; |
| 279 | update.reg = wm9713_mixer_mute_regs[shift]; |
| 280 | update.mask = 0x8000; |
| 281 | if ((wm9713->hp_mixer[0] & mask) || |
| 282 | (wm9713->hp_mixer[1] & mask)) |
| 283 | update.val = 0x0; |
| 284 | else |
| 285 | update.val = 0x8000; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 286 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 287 | snd_soc_dapm_mixer_update_power(dapm, kcontrol, val, |
| 288 | &update); |
| 289 | } |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 290 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 291 | mutex_unlock(&wm9713->lock); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 292 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 293 | return change; |
| 294 | } |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 295 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 296 | static int wm9713_hp_mixer_get(struct snd_kcontrol *kcontrol, |
| 297 | struct snd_ctl_elem_value *ucontrol) |
| 298 | { |
| 299 | struct snd_soc_dapm_context *dapm = snd_soc_dapm_kcontrol_dapm(kcontrol); |
| 300 | struct snd_soc_codec *codec = snd_soc_dapm_to_codec(dapm); |
| 301 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
| 302 | struct soc_mixer_control *mc = |
| 303 | (struct soc_mixer_control *)kcontrol->private_value; |
| 304 | unsigned int mixer, shift; |
| 305 | |
| 306 | mixer = mc->shift >> 8; |
| 307 | shift = mc->shift & 0xff; |
| 308 | |
| 309 | ucontrol->value.enumerated.item[0] = |
| 310 | (wm9713->hp_mixer[mixer] >> shift) & 1; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 315 | #define WM9713_HP_MIXER_CTRL(xname, xmixer, xshift) { \ |
| 316 | .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ |
| 317 | .info = snd_soc_info_volsw, \ |
| 318 | .get = wm9713_hp_mixer_get, .put = wm9713_hp_mixer_put, \ |
| 319 | .private_value = SOC_DOUBLE_VALUE(SND_SOC_NOPM, \ |
| 320 | xshift, xmixer, 1, 0, 0) \ |
| 321 | } |
| 322 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 323 | /* Left Headphone Mixers */ |
| 324 | static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 325 | WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPL_MIXER, 5), |
| 326 | WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPL_MIXER, 4), |
| 327 | WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPL_MIXER, 3), |
| 328 | WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPL_MIXER, 2), |
| 329 | WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPL_MIXER, 1), |
| 330 | WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPL_MIXER, 0), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 331 | }; |
| 332 | |
| 333 | /* Right Headphone Mixers */ |
| 334 | static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = { |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 335 | WM9713_HP_MIXER_CTRL("Beep Playback Switch", HPR_MIXER, 5), |
| 336 | WM9713_HP_MIXER_CTRL("Voice Playback Switch", HPR_MIXER, 4), |
| 337 | WM9713_HP_MIXER_CTRL("Aux Playback Switch", HPR_MIXER, 3), |
| 338 | WM9713_HP_MIXER_CTRL("PCM Playback Switch", HPR_MIXER, 2), |
| 339 | WM9713_HP_MIXER_CTRL("MonoIn Playback Switch", HPR_MIXER, 1), |
| 340 | WM9713_HP_MIXER_CTRL("Bypass Playback Switch", HPR_MIXER, 0), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 341 | }; |
| 342 | |
| 343 | /* headphone capture mux */ |
| 344 | static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls = |
| 345 | SOC_DAPM_ENUM("Route", wm9713_enum[1]); |
| 346 | |
| 347 | /* headphone mic mux */ |
| 348 | static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls = |
| 349 | SOC_DAPM_ENUM("Route", wm9713_enum[0]); |
| 350 | |
| 351 | /* Speaker Mixer */ |
| 352 | static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = { |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 353 | SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 11, 1, 1), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 354 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1), |
| 355 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1), |
| 356 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1), |
| 357 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1), |
| 358 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1), |
| 359 | }; |
| 360 | |
| 361 | /* Mono Mixer */ |
| 362 | static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = { |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 363 | SOC_DAPM_SINGLE("Beep Playback Switch", AC97_AUX, 7, 1, 1), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 364 | SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1), |
| 365 | SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1), |
| 366 | SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1), |
| 367 | SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1), |
| 368 | SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1), |
| 369 | SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1), |
| 370 | SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1), |
| 371 | }; |
| 372 | |
| 373 | /* mono mic mux */ |
| 374 | static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls = |
| 375 | SOC_DAPM_ENUM("Route", wm9713_enum[2]); |
| 376 | |
| 377 | /* mono output mux */ |
| 378 | static const struct snd_kcontrol_new wm9713_mono_mux_controls = |
| 379 | SOC_DAPM_ENUM("Route", wm9713_enum[7]); |
| 380 | |
| 381 | /* speaker left output mux */ |
| 382 | static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls = |
| 383 | SOC_DAPM_ENUM("Route", wm9713_enum[8]); |
| 384 | |
| 385 | /* speaker right output mux */ |
| 386 | static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls = |
| 387 | SOC_DAPM_ENUM("Route", wm9713_enum[9]); |
| 388 | |
| 389 | /* headphone left output mux */ |
| 390 | static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls = |
| 391 | SOC_DAPM_ENUM("Route", wm9713_enum[10]); |
| 392 | |
| 393 | /* headphone right output mux */ |
| 394 | static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls = |
| 395 | SOC_DAPM_ENUM("Route", wm9713_enum[11]); |
| 396 | |
| 397 | /* Out3 mux */ |
| 398 | static const struct snd_kcontrol_new wm9713_out3_mux_controls = |
| 399 | SOC_DAPM_ENUM("Route", wm9713_enum[12]); |
| 400 | |
| 401 | /* Out4 mux */ |
| 402 | static const struct snd_kcontrol_new wm9713_out4_mux_controls = |
| 403 | SOC_DAPM_ENUM("Route", wm9713_enum[13]); |
| 404 | |
| 405 | /* DAC inv mux 1 */ |
| 406 | static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls = |
| 407 | SOC_DAPM_ENUM("Route", wm9713_enum[14]); |
| 408 | |
| 409 | /* DAC inv mux 2 */ |
| 410 | static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls = |
| 411 | SOC_DAPM_ENUM("Route", wm9713_enum[15]); |
| 412 | |
| 413 | /* Capture source left */ |
| 414 | static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls = |
| 415 | SOC_DAPM_ENUM("Route", wm9713_enum[3]); |
| 416 | |
| 417 | /* Capture source right */ |
| 418 | static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls = |
| 419 | SOC_DAPM_ENUM("Route", wm9713_enum[4]); |
| 420 | |
| 421 | /* mic source */ |
| 422 | static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls = |
| 423 | SOC_DAPM_ENUM("Route", wm9713_enum[18]); |
| 424 | |
| 425 | /* mic source B virtual control */ |
| 426 | static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls = |
| 427 | SOC_DAPM_ENUM("Route", wm9713_enum[19]); |
| 428 | |
| 429 | static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = { |
| 430 | SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0, |
| 431 | &wm9713_hp_rec_mux_controls), |
| 432 | SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0, |
| 433 | &wm9713_hp_mic_mux_controls), |
| 434 | SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0, |
| 435 | &wm9713_mono_mic_mux_controls), |
| 436 | SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0, |
| 437 | &wm9713_mono_mux_controls), |
| 438 | SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0, |
| 439 | &wm9713_hp_spkl_mux_controls), |
| 440 | SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0, |
| 441 | &wm9713_hp_spkr_mux_controls), |
| 442 | SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0, |
| 443 | &wm9713_hpl_out_mux_controls), |
| 444 | SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0, |
| 445 | &wm9713_hpr_out_mux_controls), |
| 446 | SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0, |
| 447 | &wm9713_out3_mux_controls), |
| 448 | SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0, |
| 449 | &wm9713_out4_mux_controls), |
| 450 | SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0, |
| 451 | &wm9713_dac_inv1_mux_controls), |
| 452 | SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0, |
| 453 | &wm9713_dac_inv2_mux_controls), |
| 454 | SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0, |
| 455 | &wm9713_rec_srcl_mux_controls), |
| 456 | SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0, |
| 457 | &wm9713_rec_srcr_mux_controls), |
| 458 | SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0, |
| 459 | &wm9713_mic_sel_mux_controls), |
| 460 | SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0, |
| 461 | &wm9713_micb_sel_mux_controls), |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 462 | SND_SOC_DAPM_MIXER("Left HP Mixer", AC97_EXTENDED_MID, 3, 1, |
| 463 | &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls)), |
| 464 | SND_SOC_DAPM_MIXER("Right HP Mixer", AC97_EXTENDED_MID, 2, 1, |
| 465 | &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls)), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 466 | SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1, |
| 467 | &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)), |
| 468 | SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1, |
| 469 | &wm9713_speaker_mixer_controls[0], |
| 470 | ARRAY_SIZE(wm9713_speaker_mixer_controls)), |
| 471 | SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1), |
| 472 | SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1), |
| 473 | SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 474 | SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 475 | SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0), |
| 476 | 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] | 477 | SND_SOC_DAPM_DAC_E("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1, |
| 478 | wm9713_voice_shutdown, SND_SOC_DAPM_PRE_PMD), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 479 | 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] | 480 | SND_SOC_DAPM_PGA("Left ADC", AC97_EXTENDED_MID, 5, 1, NULL, 0), |
| 481 | SND_SOC_DAPM_PGA("Right ADC", AC97_EXTENDED_MID, 4, 1, NULL, 0), |
| 482 | SND_SOC_DAPM_ADC("Left HiFi ADC", "Left HiFi Capture", SND_SOC_NOPM, 0, 0), |
| 483 | SND_SOC_DAPM_ADC("Right HiFi ADC", "Right HiFi Capture", SND_SOC_NOPM, 0, 0), |
| 484 | SND_SOC_DAPM_ADC("Left Voice ADC", "Left Voice Capture", SND_SOC_NOPM, 0, 0), |
| 485 | 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] | 486 | SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0), |
| 487 | SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0), |
| 488 | SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0), |
| 489 | SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0), |
| 490 | SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0), |
| 491 | SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0), |
| 492 | SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0), |
| 493 | SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0), |
| 494 | SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0), |
| 495 | SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0), |
| 496 | SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0), |
| 497 | SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0), |
| 498 | SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0), |
| 499 | SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0), |
| 500 | SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1), |
| 501 | SND_SOC_DAPM_OUTPUT("MONO"), |
| 502 | SND_SOC_DAPM_OUTPUT("HPL"), |
| 503 | SND_SOC_DAPM_OUTPUT("HPR"), |
| 504 | SND_SOC_DAPM_OUTPUT("SPKL"), |
| 505 | SND_SOC_DAPM_OUTPUT("SPKR"), |
| 506 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 507 | SND_SOC_DAPM_OUTPUT("OUT4"), |
| 508 | SND_SOC_DAPM_INPUT("LINEL"), |
| 509 | SND_SOC_DAPM_INPUT("LINER"), |
| 510 | SND_SOC_DAPM_INPUT("MONOIN"), |
| 511 | SND_SOC_DAPM_INPUT("PCBEEP"), |
| 512 | SND_SOC_DAPM_INPUT("MIC1"), |
| 513 | SND_SOC_DAPM_INPUT("MIC2A"), |
| 514 | SND_SOC_DAPM_INPUT("MIC2B"), |
| 515 | SND_SOC_DAPM_VMID("VMID"), |
| 516 | }; |
| 517 | |
Lu Guanqun | 7ad7dd1 | 2011-03-30 21:53:11 +0800 | [diff] [blame] | 518 | static const struct snd_soc_dapm_route wm9713_audio_map[] = { |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 519 | /* left HP mixer */ |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 520 | {"Left HP Mixer", "Beep Playback Switch", "PCBEEP"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 521 | {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 522 | {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 523 | {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"}, |
| 524 | {"Left HP Mixer", "PCM Playback Switch", "Left DAC"}, |
| 525 | {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 526 | {"Left HP Mixer", NULL, "Capture Headphone Mux"}, |
| 527 | |
| 528 | /* right HP mixer */ |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 529 | {"Right HP Mixer", "Beep Playback Switch", "PCBEEP"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 530 | {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 531 | {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 532 | {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"}, |
| 533 | {"Right HP Mixer", "PCM Playback Switch", "Right DAC"}, |
| 534 | {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 535 | {"Right HP Mixer", NULL, "Capture Headphone Mux"}, |
| 536 | |
| 537 | /* virtual mixer - mixes left & right channels for spk and mono */ |
| 538 | {"AC97 Mixer", NULL, "Left DAC"}, |
| 539 | {"AC97 Mixer", NULL, "Right DAC"}, |
| 540 | {"Line Mixer", NULL, "Right Line In"}, |
| 541 | {"Line Mixer", NULL, "Left Line In"}, |
| 542 | {"HP Mixer", NULL, "Left HP Mixer"}, |
| 543 | {"HP Mixer", NULL, "Right HP Mixer"}, |
| 544 | {"Capture Mixer", NULL, "Left Capture Source"}, |
| 545 | {"Capture Mixer", NULL, "Right Capture Source"}, |
| 546 | |
| 547 | /* speaker mixer */ |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 548 | {"Speaker Mixer", "Beep Playback Switch", "PCBEEP"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 549 | {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 550 | {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 551 | {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"}, |
| 552 | {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
| 553 | {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"}, |
| 554 | |
| 555 | /* mono mixer */ |
Jaroslav Kysela | d355c82a | 2009-11-03 15:47:25 +0100 | [diff] [blame] | 556 | {"Mono Mixer", "Beep Playback Switch", "PCBEEP"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 557 | {"Mono Mixer", "Voice Playback Switch", "Voice DAC"}, |
| 558 | {"Mono Mixer", "Aux Playback Switch", "Aux DAC"}, |
| 559 | {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"}, |
| 560 | {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"}, |
Robert Jarzmik | c0bbf48 | 2008-03-18 12:08:35 +0100 | [diff] [blame] | 561 | {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"}, |
| 562 | {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 563 | {"Mono Mixer", NULL, "Capture Mono Mux"}, |
| 564 | |
| 565 | /* DAC inv mux 1 */ |
| 566 | {"DAC Inv Mux 1", "Mono", "Mono Mixer"}, |
| 567 | {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"}, |
| 568 | {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"}, |
| 569 | {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"}, |
| 570 | {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"}, |
| 571 | |
| 572 | /* DAC inv mux 2 */ |
| 573 | {"DAC Inv Mux 2", "Mono", "Mono Mixer"}, |
| 574 | {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"}, |
| 575 | {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"}, |
| 576 | {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"}, |
| 577 | {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"}, |
| 578 | |
| 579 | /* headphone left mux */ |
| 580 | {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"}, |
| 581 | |
| 582 | /* headphone right mux */ |
| 583 | {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"}, |
| 584 | |
| 585 | /* speaker left mux */ |
| 586 | {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"}, |
| 587 | {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"}, |
| 588 | {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"}, |
| 589 | |
| 590 | /* speaker right mux */ |
| 591 | {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"}, |
| 592 | {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"}, |
| 593 | {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"}, |
| 594 | |
| 595 | /* mono mux */ |
| 596 | {"Mono Out Mux", "Mono", "Mono Mixer"}, |
| 597 | {"Mono Out Mux", "Inv", "DAC Inv Mux 1"}, |
| 598 | |
| 599 | /* out 3 mux */ |
| 600 | {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"}, |
| 601 | |
| 602 | /* out 4 mux */ |
| 603 | {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"}, |
| 604 | |
| 605 | /* output pga */ |
| 606 | {"HPL", NULL, "Left Headphone"}, |
| 607 | {"Left Headphone", NULL, "Left Headphone Out Mux"}, |
| 608 | {"HPR", NULL, "Right Headphone"}, |
| 609 | {"Right Headphone", NULL, "Right Headphone Out Mux"}, |
| 610 | {"OUT3", NULL, "Out 3"}, |
| 611 | {"Out 3", NULL, "Out 3 Mux"}, |
| 612 | {"OUT4", NULL, "Out 4"}, |
| 613 | {"Out 4", NULL, "Out 4 Mux"}, |
| 614 | {"SPKL", NULL, "Left Speaker"}, |
| 615 | {"Left Speaker", NULL, "Left Speaker Out Mux"}, |
| 616 | {"SPKR", NULL, "Right Speaker"}, |
| 617 | {"Right Speaker", NULL, "Right Speaker Out Mux"}, |
| 618 | {"MONO", NULL, "Mono Out"}, |
| 619 | {"Mono Out", NULL, "Mono Out Mux"}, |
| 620 | |
| 621 | /* input pga */ |
| 622 | {"Left Line In", NULL, "LINEL"}, |
| 623 | {"Right Line In", NULL, "LINER"}, |
| 624 | {"Mono In", NULL, "MONOIN"}, |
| 625 | {"Mic A PGA", NULL, "Mic A Pre Amp"}, |
| 626 | {"Mic B PGA", NULL, "Mic B Pre Amp"}, |
| 627 | |
| 628 | /* left capture select */ |
| 629 | {"Left Capture Source", "Mic 1", "Mic A Pre Amp"}, |
| 630 | {"Left Capture Source", "Mic 2", "Mic B Pre Amp"}, |
| 631 | {"Left Capture Source", "Line", "LINEL"}, |
| 632 | {"Left Capture Source", "Mono In", "MONOIN"}, |
| 633 | {"Left Capture Source", "Headphone", "Left HP Mixer"}, |
| 634 | {"Left Capture Source", "Speaker", "Speaker Mixer"}, |
| 635 | {"Left Capture Source", "Mono Out", "Mono Mixer"}, |
| 636 | |
| 637 | /* right capture select */ |
| 638 | {"Right Capture Source", "Mic 1", "Mic A Pre Amp"}, |
| 639 | {"Right Capture Source", "Mic 2", "Mic B Pre Amp"}, |
| 640 | {"Right Capture Source", "Line", "LINER"}, |
| 641 | {"Right Capture Source", "Mono In", "MONOIN"}, |
| 642 | {"Right Capture Source", "Headphone", "Right HP Mixer"}, |
| 643 | {"Right Capture Source", "Speaker", "Speaker Mixer"}, |
| 644 | {"Right Capture Source", "Mono Out", "Mono Mixer"}, |
| 645 | |
| 646 | /* left ADC */ |
| 647 | {"Left ADC", NULL, "Left Capture Source"}, |
Mark Brown | ccbc301 | 2008-09-15 15:51:13 +0100 | [diff] [blame] | 648 | {"Left Voice ADC", NULL, "Left ADC"}, |
| 649 | {"Left HiFi ADC", NULL, "Left ADC"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 650 | |
| 651 | /* right ADC */ |
| 652 | {"Right ADC", NULL, "Right Capture Source"}, |
Mark Brown | ccbc301 | 2008-09-15 15:51:13 +0100 | [diff] [blame] | 653 | {"Right Voice ADC", NULL, "Right ADC"}, |
| 654 | {"Right HiFi ADC", NULL, "Right ADC"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 655 | |
| 656 | /* mic */ |
| 657 | {"Mic A Pre Amp", NULL, "Mic A Source"}, |
| 658 | {"Mic A Source", "Mic 1", "MIC1"}, |
| 659 | {"Mic A Source", "Mic 2 A", "MIC2A"}, |
| 660 | {"Mic A Source", "Mic 2 B", "Mic B Source"}, |
| 661 | {"Mic B Pre Amp", "MPB", "Mic B Source"}, |
| 662 | {"Mic B Source", NULL, "MIC2B"}, |
| 663 | |
| 664 | /* headphone capture */ |
| 665 | {"Capture Headphone Mux", "Stereo", "Capture Mixer"}, |
| 666 | {"Capture Headphone Mux", "Left", "Left Capture Source"}, |
| 667 | {"Capture Headphone Mux", "Right", "Right Capture Source"}, |
| 668 | |
| 669 | /* mono capture */ |
| 670 | {"Capture Mono Mux", "Stereo", "Capture Mixer"}, |
| 671 | {"Capture Mono Mux", "Left", "Left Capture Source"}, |
| 672 | {"Capture Mono Mux", "Right", "Right Capture Source"}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 673 | }; |
| 674 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 675 | static unsigned int ac97_read(struct snd_soc_codec *codec, |
| 676 | unsigned int reg) |
| 677 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 678 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 679 | u16 *cache = codec->reg_cache; |
| 680 | |
| 681 | if (reg == AC97_RESET || reg == AC97_GPIO_STATUS || |
| 682 | reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 || |
| 683 | reg == AC97_CD) |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 684 | return soc_ac97_ops->read(wm9713->ac97, reg); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 685 | else { |
| 686 | reg = reg >> 1; |
| 687 | |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 688 | if (reg >= (ARRAY_SIZE(wm9713_reg))) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 689 | return -EIO; |
| 690 | |
| 691 | return cache[reg]; |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | static int ac97_write(struct snd_soc_codec *codec, unsigned int reg, |
| 696 | unsigned int val) |
| 697 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 698 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
| 699 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 700 | u16 *cache = codec->reg_cache; |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 701 | soc_ac97_ops->write(wm9713->ac97, reg, val); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 702 | reg = reg >> 1; |
Ian Molton | 91432e9 | 2009-01-17 17:44:23 +0000 | [diff] [blame] | 703 | if (reg < (ARRAY_SIZE(wm9713_reg))) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 704 | cache[reg] = val; |
| 705 | |
| 706 | return 0; |
| 707 | } |
| 708 | |
| 709 | /* PLL divisors */ |
| 710 | struct _pll_div { |
| 711 | u32 divsel:1; |
| 712 | u32 divctl:1; |
| 713 | u32 lf:1; |
| 714 | u32 n:4; |
| 715 | u32 k:24; |
| 716 | }; |
| 717 | |
| 718 | /* The size in bits of the PLL divide multiplied by 10 |
| 719 | * to allow rounding later */ |
| 720 | #define FIXED_PLL_SIZE ((1 << 22) * 10) |
| 721 | |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 722 | static void pll_factors(struct snd_soc_codec *codec, |
| 723 | struct _pll_div *pll_div, unsigned int source) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 724 | { |
| 725 | u64 Kpart; |
| 726 | unsigned int K, Ndiv, Nmod, target; |
| 727 | |
| 728 | /* The the PLL output is always 98.304MHz. */ |
| 729 | target = 98304000; |
| 730 | |
| 731 | /* If the input frequency is over 14.4MHz then scale it down. */ |
| 732 | if (source > 14400000) { |
| 733 | source >>= 1; |
| 734 | pll_div->divsel = 1; |
| 735 | |
| 736 | if (source > 14400000) { |
| 737 | source >>= 1; |
| 738 | pll_div->divctl = 1; |
| 739 | } else |
| 740 | pll_div->divctl = 0; |
| 741 | |
| 742 | } else { |
| 743 | pll_div->divsel = 0; |
| 744 | pll_div->divctl = 0; |
| 745 | } |
| 746 | |
| 747 | /* Low frequency sources require an additional divide in the |
| 748 | * loop. |
| 749 | */ |
| 750 | if (source < 8192000) { |
| 751 | pll_div->lf = 1; |
| 752 | target >>= 2; |
| 753 | } else |
| 754 | pll_div->lf = 0; |
| 755 | |
| 756 | Ndiv = target / source; |
| 757 | if ((Ndiv < 5) || (Ndiv > 12)) |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 758 | dev_warn(codec->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 759 | "WM9713 PLL N value %u out of recommended range!\n", |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 760 | Ndiv); |
| 761 | |
| 762 | pll_div->n = Ndiv; |
| 763 | Nmod = target % source; |
| 764 | Kpart = FIXED_PLL_SIZE * (long long)Nmod; |
| 765 | |
| 766 | do_div(Kpart, source); |
| 767 | |
| 768 | K = Kpart & 0xFFFFFFFF; |
| 769 | |
| 770 | /* Check if we need to round */ |
| 771 | if ((K % 10) >= 5) |
| 772 | K += 5; |
| 773 | |
| 774 | /* Move down to proper range now rounding is done */ |
| 775 | K /= 10; |
| 776 | |
| 777 | pll_div->k = K; |
| 778 | } |
| 779 | |
| 780 | /** |
| 781 | * Please note that changing the PLL input frequency may require |
| 782 | * resynchronisation with the AC97 controller. |
| 783 | */ |
| 784 | static int wm9713_set_pll(struct snd_soc_codec *codec, |
| 785 | int pll_id, unsigned int freq_in, unsigned int freq_out) |
| 786 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 787 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 788 | u16 reg, reg2; |
| 789 | struct _pll_div pll_div; |
| 790 | |
| 791 | /* turn PLL off ? */ |
Mark Brown | c42f69b | 2009-01-16 16:31:03 +0000 | [diff] [blame] | 792 | if (freq_in == 0) { |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 793 | /* disable PLL power and select ext source */ |
| 794 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
| 795 | ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080); |
| 796 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 797 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200); |
Mark Brown | c42f69b | 2009-01-16 16:31:03 +0000 | [diff] [blame] | 798 | wm9713->pll_in = 0; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 799 | return 0; |
| 800 | } |
| 801 | |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 802 | pll_factors(codec, &pll_div, freq_in); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 803 | |
| 804 | if (pll_div.k == 0) { |
| 805 | reg = (pll_div.n << 12) | (pll_div.lf << 11) | |
| 806 | (pll_div.divsel << 9) | (pll_div.divctl << 8); |
| 807 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 808 | } else { |
| 809 | /* write the fractional k to the reg 0x46 pages */ |
| 810 | reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) | |
| 811 | (pll_div.divsel << 9) | (pll_div.divctl << 8); |
| 812 | |
| 813 | /* K [21:20] */ |
| 814 | reg = reg2 | (0x5 << 4) | (pll_div.k >> 20); |
| 815 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 816 | |
| 817 | /* K [19:16] */ |
| 818 | reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf); |
| 819 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 820 | |
| 821 | /* K [15:12] */ |
| 822 | reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf); |
| 823 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 824 | |
| 825 | /* K [11:8] */ |
| 826 | reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf); |
| 827 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 828 | |
| 829 | /* K [7:4] */ |
| 830 | reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf); |
| 831 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 832 | |
| 833 | reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */ |
| 834 | ac97_write(codec, AC97_LINE1_LEVEL, reg); |
| 835 | } |
| 836 | |
| 837 | /* turn PLL on and select as source */ |
| 838 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 839 | ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff); |
| 840 | reg = ac97_read(codec, AC97_HANDSET_RATE); |
| 841 | ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 842 | wm9713->pll_in = freq_in; |
| 843 | |
| 844 | /* wait 10ms AC97 link frames for the link to stabilise */ |
| 845 | schedule_timeout_interruptible(msecs_to_jiffies(10)); |
| 846 | return 0; |
| 847 | } |
| 848 | |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 849 | static int wm9713_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
| 850 | int source, unsigned int freq_in, unsigned int freq_out) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 851 | { |
| 852 | struct snd_soc_codec *codec = codec_dai->codec; |
| 853 | return wm9713_set_pll(codec, pll_id, freq_in, freq_out); |
| 854 | } |
| 855 | |
| 856 | /* |
| 857 | * Tristate the PCM DAI lines, tristate can be disabled by calling |
| 858 | * wm9713_set_dai_fmt() |
| 859 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 860 | static int wm9713_set_dai_tristate(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 861 | int tristate) |
| 862 | { |
| 863 | struct snd_soc_codec *codec = codec_dai->codec; |
| 864 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff; |
| 865 | |
| 866 | if (tristate) |
| 867 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 868 | |
| 869 | return 0; |
| 870 | } |
| 871 | |
| 872 | /* |
| 873 | * Configure WM9713 clock dividers. |
| 874 | * Voice DAC needs 256 FS |
| 875 | */ |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 876 | static int wm9713_set_dai_clkdiv(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 877 | int div_id, int div) |
| 878 | { |
| 879 | struct snd_soc_codec *codec = codec_dai->codec; |
| 880 | u16 reg; |
| 881 | |
| 882 | switch (div_id) { |
| 883 | case WM9713_PCMCLK_DIV: |
| 884 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff; |
| 885 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 886 | break; |
| 887 | case WM9713_CLKA_MULT: |
| 888 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd; |
| 889 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 890 | break; |
| 891 | case WM9713_CLKB_MULT: |
| 892 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb; |
| 893 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 894 | break; |
| 895 | case WM9713_HIFI_DIV: |
| 896 | reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff; |
| 897 | ac97_write(codec, AC97_HANDSET_RATE, reg | div); |
| 898 | break; |
| 899 | case WM9713_PCMBCLK_DIV: |
| 900 | reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff; |
| 901 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div); |
| 902 | break; |
| 903 | case WM9713_PCMCLK_PLL_DIV: |
| 904 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; |
| 905 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div); |
| 906 | break; |
| 907 | case WM9713_HIFI_PLL_DIV: |
| 908 | reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80; |
| 909 | ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div); |
| 910 | break; |
| 911 | default: |
| 912 | return -EINVAL; |
| 913 | } |
| 914 | |
| 915 | return 0; |
| 916 | } |
| 917 | |
Liam Girdwood | e550e17 | 2008-07-07 16:07:52 +0100 | [diff] [blame] | 918 | static int wm9713_set_dai_fmt(struct snd_soc_dai *codec_dai, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 919 | unsigned int fmt) |
| 920 | { |
| 921 | struct snd_soc_codec *codec = codec_dai->codec; |
| 922 | u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5; |
| 923 | u16 reg = 0x8000; |
| 924 | |
| 925 | /* clock masters */ |
| 926 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 927 | case SND_SOC_DAIFMT_CBM_CFM: |
| 928 | reg |= 0x4000; |
| 929 | gpio |= 0x0010; |
| 930 | break; |
| 931 | case SND_SOC_DAIFMT_CBM_CFS: |
| 932 | reg |= 0x6000; |
| 933 | gpio |= 0x0018; |
| 934 | break; |
| 935 | case SND_SOC_DAIFMT_CBS_CFS: |
Mark Brown | d133b0c | 2008-06-11 13:47:11 +0100 | [diff] [blame] | 936 | reg |= 0x2000; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 937 | gpio |= 0x001a; |
| 938 | break; |
| 939 | case SND_SOC_DAIFMT_CBS_CFM: |
| 940 | gpio |= 0x0012; |
| 941 | break; |
| 942 | } |
| 943 | |
| 944 | /* clock inversion */ |
| 945 | switch (fmt & SND_SOC_DAIFMT_INV_MASK) { |
| 946 | case SND_SOC_DAIFMT_IB_IF: |
| 947 | reg |= 0x00c0; |
| 948 | break; |
| 949 | case SND_SOC_DAIFMT_IB_NF: |
| 950 | reg |= 0x0080; |
| 951 | break; |
| 952 | case SND_SOC_DAIFMT_NB_IF: |
| 953 | reg |= 0x0040; |
| 954 | break; |
| 955 | } |
| 956 | |
| 957 | /* DAI format */ |
| 958 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 959 | case SND_SOC_DAIFMT_I2S: |
| 960 | reg |= 0x0002; |
| 961 | break; |
| 962 | case SND_SOC_DAIFMT_RIGHT_J: |
| 963 | break; |
| 964 | case SND_SOC_DAIFMT_LEFT_J: |
| 965 | reg |= 0x0001; |
| 966 | break; |
| 967 | case SND_SOC_DAIFMT_DSP_A: |
| 968 | reg |= 0x0003; |
| 969 | break; |
| 970 | case SND_SOC_DAIFMT_DSP_B: |
| 971 | reg |= 0x0043; |
| 972 | break; |
| 973 | } |
| 974 | |
| 975 | ac97_write(codec, AC97_GPIO_CFG, gpio); |
| 976 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 977 | return 0; |
| 978 | } |
| 979 | |
| 980 | static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream, |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 981 | struct snd_pcm_hw_params *params, |
| 982 | struct snd_soc_dai *dai) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 983 | { |
Mark Brown | 55b8bac | 2008-11-24 14:05:29 +0000 | [diff] [blame] | 984 | struct snd_soc_codec *codec = dai->codec; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 985 | u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3; |
| 986 | |
Mark Brown | 563fe71 | 2014-07-31 12:55:23 +0100 | [diff] [blame] | 987 | switch (params_width(params)) { |
| 988 | case 16: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 989 | break; |
Mark Brown | 563fe71 | 2014-07-31 12:55:23 +0100 | [diff] [blame] | 990 | case 20: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 991 | reg |= 0x0004; |
| 992 | break; |
Mark Brown | 563fe71 | 2014-07-31 12:55:23 +0100 | [diff] [blame] | 993 | case 24: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 994 | reg |= 0x0008; |
| 995 | break; |
Mark Brown | 563fe71 | 2014-07-31 12:55:23 +0100 | [diff] [blame] | 996 | case 32: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 997 | reg |= 0x000c; |
| 998 | break; |
| 999 | } |
| 1000 | |
| 1001 | /* enable PCM interface in master mode */ |
| 1002 | ac97_write(codec, AC97_CENTER_LFE_MASTER, reg); |
| 1003 | return 0; |
| 1004 | } |
| 1005 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 1006 | static int ac97_hifi_prepare(struct snd_pcm_substream *substream, |
| 1007 | struct snd_soc_dai *dai) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1008 | { |
Mark Brown | 55b8bac | 2008-11-24 14:05:29 +0000 | [diff] [blame] | 1009 | struct snd_soc_codec *codec = dai->codec; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1010 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1011 | int reg; |
| 1012 | u16 vra; |
| 1013 | |
| 1014 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 1015 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 1016 | |
| 1017 | if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) |
| 1018 | reg = AC97_PCM_FRONT_DAC_RATE; |
| 1019 | else |
| 1020 | reg = AC97_PCM_LR_ADC_RATE; |
| 1021 | |
| 1022 | return ac97_write(codec, reg, runtime->rate); |
| 1023 | } |
| 1024 | |
Mark Brown | dee89c4 | 2008-11-18 22:11:38 +0000 | [diff] [blame] | 1025 | static int ac97_aux_prepare(struct snd_pcm_substream *substream, |
| 1026 | struct snd_soc_dai *dai) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1027 | { |
Mark Brown | 55b8bac | 2008-11-24 14:05:29 +0000 | [diff] [blame] | 1028 | struct snd_soc_codec *codec = dai->codec; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1029 | struct snd_pcm_runtime *runtime = substream->runtime; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1030 | u16 vra, xsle; |
| 1031 | |
| 1032 | vra = ac97_read(codec, AC97_EXTENDED_STATUS); |
| 1033 | ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1); |
| 1034 | xsle = ac97_read(codec, AC97_PCI_SID); |
| 1035 | ac97_write(codec, AC97_PCI_SID, xsle | 0x8000); |
| 1036 | |
| 1037 | if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK) |
| 1038 | return -ENODEV; |
| 1039 | |
| 1040 | return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate); |
| 1041 | } |
| 1042 | |
Mark Brown | 5415552 | 2008-07-02 11:51:19 +0100 | [diff] [blame] | 1043 | #define WM9713_RATES (SNDRV_PCM_RATE_8000 | \ |
| 1044 | SNDRV_PCM_RATE_11025 | \ |
| 1045 | SNDRV_PCM_RATE_22050 | \ |
| 1046 | SNDRV_PCM_RATE_44100 | \ |
| 1047 | SNDRV_PCM_RATE_48000) |
| 1048 | |
| 1049 | #define WM9713_PCM_RATES (SNDRV_PCM_RATE_8000 | \ |
| 1050 | SNDRV_PCM_RATE_11025 | \ |
| 1051 | SNDRV_PCM_RATE_16000 | \ |
| 1052 | SNDRV_PCM_RATE_22050 | \ |
| 1053 | SNDRV_PCM_RATE_44100 | \ |
| 1054 | SNDRV_PCM_RATE_48000) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1055 | |
| 1056 | #define WM9713_PCM_FORMATS \ |
| 1057 | (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \ |
| 1058 | SNDRV_PCM_FORMAT_S24_LE) |
| 1059 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1060 | static const struct snd_soc_dai_ops wm9713_dai_ops_hifi = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1061 | .prepare = ac97_hifi_prepare, |
| 1062 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1063 | .set_pll = wm9713_set_dai_pll, |
| 1064 | }; |
| 1065 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1066 | static const struct snd_soc_dai_ops wm9713_dai_ops_aux = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1067 | .prepare = ac97_aux_prepare, |
| 1068 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1069 | .set_pll = wm9713_set_dai_pll, |
| 1070 | }; |
| 1071 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1072 | static const struct snd_soc_dai_ops wm9713_dai_ops_voice = { |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1073 | .hw_params = wm9713_pcm_hw_params, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1074 | .set_clkdiv = wm9713_set_dai_clkdiv, |
| 1075 | .set_pll = wm9713_set_dai_pll, |
| 1076 | .set_fmt = wm9713_set_dai_fmt, |
| 1077 | .set_tristate = wm9713_set_dai_tristate, |
| 1078 | }; |
| 1079 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1080 | static struct snd_soc_dai_driver wm9713_dai[] = { |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1081 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1082 | .name = "wm9713-hifi", |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1083 | .playback = { |
| 1084 | .stream_name = "HiFi Playback", |
| 1085 | .channels_min = 1, |
| 1086 | .channels_max = 2, |
| 1087 | .rates = WM9713_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 1088 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1089 | .capture = { |
| 1090 | .stream_name = "HiFi Capture", |
| 1091 | .channels_min = 1, |
| 1092 | .channels_max = 2, |
| 1093 | .rates = WM9713_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 1094 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1095 | .ops = &wm9713_dai_ops_hifi, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1096 | }, |
| 1097 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1098 | .name = "wm9713-aux", |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1099 | .playback = { |
| 1100 | .stream_name = "Aux Playback", |
| 1101 | .channels_min = 1, |
| 1102 | .channels_max = 1, |
| 1103 | .rates = WM9713_RATES, |
Mark Brown | 33f503c | 2009-05-02 12:24:55 +0100 | [diff] [blame] | 1104 | .formats = SND_SOC_STD_AC97_FMTS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1105 | .ops = &wm9713_dai_ops_aux, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1106 | }, |
| 1107 | { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1108 | .name = "wm9713-voice", |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1109 | .playback = { |
| 1110 | .stream_name = "Voice Playback", |
| 1111 | .channels_min = 1, |
| 1112 | .channels_max = 1, |
Mark Brown | 5415552 | 2008-07-02 11:51:19 +0100 | [diff] [blame] | 1113 | .rates = WM9713_PCM_RATES, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1114 | .formats = WM9713_PCM_FORMATS,}, |
| 1115 | .capture = { |
| 1116 | .stream_name = "Voice Capture", |
| 1117 | .channels_min = 1, |
| 1118 | .channels_max = 2, |
Mark Brown | 5415552 | 2008-07-02 11:51:19 +0100 | [diff] [blame] | 1119 | .rates = WM9713_PCM_RATES, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1120 | .formats = WM9713_PCM_FORMATS,}, |
Eric Miao | 6335d05 | 2009-03-03 09:41:00 +0800 | [diff] [blame] | 1121 | .ops = &wm9713_dai_ops_voice, |
Mark Brown | f497611 | 2009-04-13 10:53:02 +0100 | [diff] [blame] | 1122 | .symmetric_rates = 1, |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1123 | }, |
| 1124 | }; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1125 | |
| 1126 | int wm9713_reset(struct snd_soc_codec *codec, int try_warm) |
| 1127 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1128 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
| 1129 | |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 1130 | if (try_warm && soc_ac97_ops->warm_reset) { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1131 | soc_ac97_ops->warm_reset(wm9713->ac97); |
Mark Brown | abb68c2 | 2008-06-13 16:24:04 +0100 | [diff] [blame] | 1132 | if (ac97_read(codec, 0) == wm9713_reg[0]) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1133 | return 1; |
| 1134 | } |
| 1135 | |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1136 | soc_ac97_ops->reset(wm9713->ac97); |
Mark Brown | b047e1c | 2013-06-26 12:45:59 +0100 | [diff] [blame] | 1137 | if (soc_ac97_ops->warm_reset) |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1138 | soc_ac97_ops->warm_reset(wm9713->ac97); |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 1139 | if (ac97_read(codec, 0) != wm9713_reg[0]) { |
| 1140 | dev_err(codec->dev, "Failed to reset: AC97 link error\n"); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1141 | return -EIO; |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 1142 | } |
| 1143 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1144 | return 0; |
| 1145 | } |
| 1146 | EXPORT_SYMBOL_GPL(wm9713_reset); |
| 1147 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1148 | static int wm9713_set_bias_level(struct snd_soc_codec *codec, |
| 1149 | enum snd_soc_bias_level level) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1150 | { |
| 1151 | u16 reg; |
| 1152 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1153 | switch (level) { |
| 1154 | case SND_SOC_BIAS_ON: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1155 | /* enable thermal shutdown */ |
| 1156 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff; |
| 1157 | ac97_write(codec, AC97_EXTENDED_MID, reg); |
| 1158 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1159 | case SND_SOC_BIAS_PREPARE: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1160 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1161 | case SND_SOC_BIAS_STANDBY: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1162 | /* enable master bias and vmid */ |
| 1163 | reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff; |
| 1164 | ac97_write(codec, AC97_EXTENDED_MID, reg); |
| 1165 | ac97_write(codec, AC97_POWERDOWN, 0x0000); |
| 1166 | break; |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1167 | case SND_SOC_BIAS_OFF: |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1168 | /* disable everything including AC link */ |
| 1169 | ac97_write(codec, AC97_EXTENDED_MID, 0xffff); |
| 1170 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); |
| 1171 | ac97_write(codec, AC97_POWERDOWN, 0xffff); |
| 1172 | break; |
| 1173 | } |
Liam Girdwood | ce6120c | 2010-11-05 15:53:46 +0200 | [diff] [blame] | 1174 | codec->dapm.bias_level = level; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1175 | return 0; |
| 1176 | } |
| 1177 | |
Lars-Peter Clausen | 84b315e | 2011-12-02 10:18:28 +0100 | [diff] [blame] | 1178 | static int wm9713_soc_suspend(struct snd_soc_codec *codec) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1179 | { |
Mark Brown | 87b57fe | 2008-04-14 15:27:30 +0200 | [diff] [blame] | 1180 | u16 reg; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1181 | |
Mark Brown | 87b57fe | 2008-04-14 15:27:30 +0200 | [diff] [blame] | 1182 | /* Disable everything except touchpanel - that will be handled |
| 1183 | * by the touch driver and left disabled if touch is not in |
| 1184 | * use. */ |
| 1185 | reg = ac97_read(codec, AC97_EXTENDED_MID); |
| 1186 | ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff); |
| 1187 | ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); |
| 1188 | ac97_write(codec, AC97_POWERDOWN, 0x6f00); |
| 1189 | ac97_write(codec, AC97_POWERDOWN, 0xffff); |
| 1190 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1191 | return 0; |
| 1192 | } |
| 1193 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1194 | static int wm9713_soc_resume(struct snd_soc_codec *codec) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1195 | { |
Mark Brown | b2c812e | 2010-04-14 15:35:19 +0900 | [diff] [blame] | 1196 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1197 | int i, ret; |
| 1198 | u16 *cache = codec->reg_cache; |
| 1199 | |
| 1200 | ret = wm9713_reset(codec, 1); |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 1201 | if (ret < 0) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1202 | return ret; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1203 | |
Mark Brown | 0be9898 | 2008-05-19 12:31:28 +0200 | [diff] [blame] | 1204 | wm9713_set_bias_level(codec, SND_SOC_BIAS_STANDBY); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1205 | |
| 1206 | /* do we need to re-start the PLL ? */ |
Mark Brown | c42f69b | 2009-01-16 16:31:03 +0000 | [diff] [blame] | 1207 | if (wm9713->pll_in) |
| 1208 | wm9713_set_pll(codec, 0, wm9713->pll_in, 0); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1209 | |
| 1210 | /* only synchronise the codec if warm reset failed */ |
| 1211 | if (ret == 0) { |
| 1212 | for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) { |
| 1213 | if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID || |
| 1214 | i == AC97_EXTENDED_MSTATUS || i > 0x66) |
| 1215 | continue; |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1216 | soc_ac97_ops->write(wm9713->ac97, i, cache[i>>1]); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1217 | } |
| 1218 | } |
| 1219 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1220 | return ret; |
| 1221 | } |
| 1222 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1223 | static int wm9713_soc_probe(struct snd_soc_codec *codec) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1224 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1225 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1226 | int ret = 0, reg; |
| 1227 | |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 1228 | wm9713->ac97 = snd_soc_alloc_ac97_codec(codec); |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1229 | if (IS_ERR(wm9713->ac97)) |
| 1230 | return PTR_ERR(wm9713->ac97); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1231 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1232 | /* do a cold reset for the controller and then try |
| 1233 | * a warm reset followed by an optional cold reset for codec */ |
| 1234 | wm9713_reset(codec, 0); |
| 1235 | ret = wm9713_reset(codec, 1); |
Lars-Peter Clausen | a6c2b07 | 2014-10-30 21:01:07 +0100 | [diff] [blame] | 1236 | if (ret < 0) |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 1237 | goto err_put_device; |
| 1238 | |
| 1239 | ret = device_add(&wm9713->ac97->dev); |
| 1240 | if (ret) |
| 1241 | goto err_put_device; |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1242 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1243 | /* unmute the adc - move to kcontrol */ |
| 1244 | reg = ac97_read(codec, AC97_CD) & 0x7fff; |
| 1245 | ac97_write(codec, AC97_CD, reg); |
| 1246 | |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1247 | return 0; |
| 1248 | |
Lars-Peter Clausen | f8d71be | 2015-01-23 16:21:37 +0100 | [diff] [blame] | 1249 | err_put_device: |
| 1250 | put_device(&wm9713->ac97->dev); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1251 | return ret; |
| 1252 | } |
| 1253 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1254 | static int wm9713_soc_remove(struct snd_soc_codec *codec) |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1255 | { |
Lars-Peter Clausen | 358a8bb | 2014-11-10 22:41:53 +0100 | [diff] [blame] | 1256 | struct wm9713_priv *wm9713 = snd_soc_codec_get_drvdata(codec); |
| 1257 | |
| 1258 | snd_soc_free_ac97_codec(wm9713->ac97); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1259 | return 0; |
| 1260 | } |
| 1261 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1262 | static struct snd_soc_codec_driver soc_codec_dev_wm9713 = { |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1263 | .probe = wm9713_soc_probe, |
| 1264 | .remove = wm9713_soc_remove, |
| 1265 | .suspend = wm9713_soc_suspend, |
| 1266 | .resume = wm9713_soc_resume, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1267 | .read = ac97_read, |
| 1268 | .write = ac97_write, |
| 1269 | .set_bias_level = wm9713_set_bias_level, |
Dimitris Papastamos | e5eec34 | 2010-09-10 18:14:56 +0100 | [diff] [blame] | 1270 | .reg_cache_size = ARRAY_SIZE(wm9713_reg), |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1271 | .reg_word_size = sizeof(u16), |
| 1272 | .reg_cache_step = 2, |
| 1273 | .reg_cache_default = wm9713_reg, |
Lars-Peter Clausen | c1359ca | 2014-10-30 21:01:08 +0100 | [diff] [blame] | 1274 | |
| 1275 | .controls = wm9713_snd_ac97_controls, |
| 1276 | .num_controls = ARRAY_SIZE(wm9713_snd_ac97_controls), |
Lu Guanqun | 7ad7dd1 | 2011-03-30 21:53:11 +0800 | [diff] [blame] | 1277 | .dapm_widgets = wm9713_dapm_widgets, |
| 1278 | .num_dapm_widgets = ARRAY_SIZE(wm9713_dapm_widgets), |
| 1279 | .dapm_routes = wm9713_audio_map, |
| 1280 | .num_dapm_routes = ARRAY_SIZE(wm9713_audio_map), |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1281 | }; |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1282 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1283 | static int wm9713_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1284 | { |
Lars-Peter Clausen | 5efe89d | 2014-10-30 21:01:09 +0100 | [diff] [blame] | 1285 | struct wm9713_priv *wm9713; |
| 1286 | |
| 1287 | wm9713 = devm_kzalloc(&pdev->dev, sizeof(*wm9713), GFP_KERNEL); |
| 1288 | if (wm9713 == NULL) |
| 1289 | return -ENOMEM; |
| 1290 | |
Lars-Peter Clausen | cf1f2eb | 2014-11-03 19:33:03 +0100 | [diff] [blame] | 1291 | mutex_init(&wm9713->lock); |
| 1292 | |
Lars-Peter Clausen | 5efe89d | 2014-10-30 21:01:09 +0100 | [diff] [blame] | 1293 | platform_set_drvdata(pdev, wm9713); |
| 1294 | |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1295 | return snd_soc_register_codec(&pdev->dev, |
| 1296 | &soc_codec_dev_wm9713, wm9713_dai, ARRAY_SIZE(wm9713_dai)); |
| 1297 | } |
| 1298 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1299 | static int wm9713_remove(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1300 | { |
| 1301 | snd_soc_unregister_codec(&pdev->dev); |
| 1302 | return 0; |
| 1303 | } |
| 1304 | |
| 1305 | static struct platform_driver wm9713_codec_driver = { |
| 1306 | .driver = { |
| 1307 | .name = "wm9713-codec", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1308 | }, |
| 1309 | |
| 1310 | .probe = wm9713_probe, |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1311 | .remove = wm9713_remove, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1312 | }; |
| 1313 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 1314 | module_platform_driver(wm9713_codec_driver); |
Liam Girdwood | 83ac08c | 2008-02-15 16:43:11 +0100 | [diff] [blame] | 1315 | |
| 1316 | MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver"); |
| 1317 | MODULE_AUTHOR("Liam Girdwood"); |
| 1318 | MODULE_LICENSE("GPL"); |