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