Thomas Gleixner | 2874c5f | 2019-05-27 08:55:01 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 2 | /* |
| 3 | * wm8400.c -- WM8400 ALSA Soc Audio driver |
| 4 | * |
Mark Brown | 656baae | 2012-05-23 12:39:07 +0100 | [diff] [blame] | 5 | * Copyright 2008-11 Wolfson Microelectronics PLC. |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <linux/module.h> |
| 10 | #include <linux/moduleparam.h> |
| 11 | #include <linux/kernel.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 13 | #include <linux/init.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/pm.h> |
| 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/regulator/consumer.h> |
| 18 | #include <linux/mfd/wm8400-audio.h> |
| 19 | #include <linux/mfd/wm8400-private.h> |
Andres Salomon | dab1547 | 2011-02-17 19:07:27 -0800 | [diff] [blame] | 20 | #include <linux/mfd/core.h> |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 21 | #include <sound/core.h> |
| 22 | #include <sound/pcm.h> |
| 23 | #include <sound/pcm_params.h> |
| 24 | #include <sound/soc.h> |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 25 | #include <sound/initval.h> |
| 26 | #include <sound/tlv.h> |
| 27 | |
| 28 | #include "wm8400.h" |
| 29 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 30 | static struct regulator_bulk_data power[] = { |
| 31 | { |
| 32 | .supply = "I2S1VDD", |
| 33 | }, |
| 34 | { |
| 35 | .supply = "I2S2VDD", |
| 36 | }, |
| 37 | { |
| 38 | .supply = "DCVDD", |
| 39 | }, |
| 40 | { |
Mark Brown | 24a5102 | 2009-03-18 15:19:48 +0000 | [diff] [blame] | 41 | .supply = "AVDD", |
| 42 | }, |
| 43 | { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 44 | .supply = "FLLVDD", |
| 45 | }, |
| 46 | { |
| 47 | .supply = "HPVDD", |
| 48 | }, |
| 49 | { |
| 50 | .supply = "SPKVDD", |
| 51 | }, |
| 52 | }; |
| 53 | |
| 54 | /* codec private data */ |
| 55 | struct wm8400_priv { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 56 | struct wm8400 *wm8400; |
| 57 | u16 fake_register; |
| 58 | unsigned int sysclk; |
| 59 | unsigned int pcmclk; |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 60 | int fll_in, fll_out; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 61 | }; |
| 62 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 63 | static void wm8400_component_reset(struct snd_soc_component *component) |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 64 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 65 | struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 66 | |
| 67 | wm8400_reset_codec_reg_cache(wm8400->wm8400); |
| 68 | } |
| 69 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 70 | static const DECLARE_TLV_DB_SCALE(in_pga_tlv, -1650, 3000, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 71 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 72 | static const DECLARE_TLV_DB_SCALE(out_mix_tlv, -2100, 0, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 73 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 74 | static const DECLARE_TLV_DB_SCALE(out_pga_tlv, -7300, 600, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 75 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 76 | static const DECLARE_TLV_DB_SCALE(out_dac_tlv, -7163, 0, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 77 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 78 | static const DECLARE_TLV_DB_SCALE(in_adc_tlv, -7163, 1763, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 79 | |
Mark Brown | 3351e9f | 2010-05-25 10:48:31 -0700 | [diff] [blame] | 80 | static const DECLARE_TLV_DB_SCALE(out_sidetone_tlv, -3600, 0, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 81 | |
| 82 | static int wm8400_outpga_put_volsw_vu(struct snd_kcontrol *kcontrol, |
| 83 | struct snd_ctl_elem_value *ucontrol) |
| 84 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 85 | struct snd_soc_component *component = snd_soc_kcontrol_component(kcontrol); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 86 | struct soc_mixer_control *mc = |
| 87 | (struct soc_mixer_control *)kcontrol->private_value; |
| 88 | int reg = mc->reg; |
| 89 | int ret; |
| 90 | u16 val; |
| 91 | |
| 92 | ret = snd_soc_put_volsw(kcontrol, ucontrol); |
| 93 | if (ret < 0) |
| 94 | return ret; |
| 95 | |
| 96 | /* now hit the volume update bits (always bit 8) */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 97 | val = snd_soc_component_read(component, reg); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 98 | return snd_soc_component_write(component, reg, val | 0x0100); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | #define WM8400_OUTPGA_SINGLE_R_TLV(xname, reg, shift, max, invert, tlv_array) \ |
Lars-Peter Clausen | a44b517 | 2013-06-19 19:33:54 +0200 | [diff] [blame] | 102 | SOC_SINGLE_EXT_TLV(xname, reg, shift, max, invert, \ |
| 103 | snd_soc_get_volsw, wm8400_outpga_put_volsw_vu, tlv_array) |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 104 | |
| 105 | |
| 106 | static const char *wm8400_digital_sidetone[] = |
| 107 | {"None", "Left ADC", "Right ADC", "Reserved"}; |
| 108 | |
Takashi Iwai | 898b48e | 2014-02-18 09:34:44 +0100 | [diff] [blame] | 109 | static SOC_ENUM_SINGLE_DECL(wm8400_left_digital_sidetone_enum, |
| 110 | WM8400_DIGITAL_SIDE_TONE, |
| 111 | WM8400_ADC_TO_DACL_SHIFT, |
| 112 | wm8400_digital_sidetone); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 113 | |
Takashi Iwai | 898b48e | 2014-02-18 09:34:44 +0100 | [diff] [blame] | 114 | static SOC_ENUM_SINGLE_DECL(wm8400_right_digital_sidetone_enum, |
| 115 | WM8400_DIGITAL_SIDE_TONE, |
| 116 | WM8400_ADC_TO_DACR_SHIFT, |
| 117 | wm8400_digital_sidetone); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 118 | |
| 119 | static const char *wm8400_adcmode[] = |
| 120 | {"Hi-fi mode", "Voice mode 1", "Voice mode 2", "Voice mode 3"}; |
| 121 | |
Takashi Iwai | 898b48e | 2014-02-18 09:34:44 +0100 | [diff] [blame] | 122 | static SOC_ENUM_SINGLE_DECL(wm8400_right_adcmode_enum, |
| 123 | WM8400_ADC_CTRL, |
| 124 | WM8400_ADC_HPF_CUT_SHIFT, |
| 125 | wm8400_adcmode); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 126 | |
| 127 | static const struct snd_kcontrol_new wm8400_snd_controls[] = { |
| 128 | /* INMIXL */ |
| 129 | SOC_SINGLE("LIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L12MNBST_SHIFT, |
| 130 | 1, 0), |
| 131 | SOC_SINGLE("LIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_L34MNBST_SHIFT, |
| 132 | 1, 0), |
| 133 | /* INMIXR */ |
| 134 | SOC_SINGLE("RIN12 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R12MNBST_SHIFT, |
| 135 | 1, 0), |
| 136 | SOC_SINGLE("RIN34 PGA Boost", WM8400_INPUT_MIXER3, WM8400_R34MNBST_SHIFT, |
| 137 | 1, 0), |
| 138 | |
| 139 | /* LOMIX */ |
| 140 | SOC_SINGLE_TLV("LOMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER3, |
| 141 | WM8400_LLI3LOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 142 | SOC_SINGLE_TLV("LOMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3, |
| 143 | WM8400_LR12LOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 144 | SOC_SINGLE_TLV("LOMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER3, |
| 145 | WM8400_LL12LOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 146 | SOC_SINGLE_TLV("LOMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER5, |
| 147 | WM8400_LRI3LOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 148 | SOC_SINGLE_TLV("LOMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER5, |
| 149 | WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 150 | SOC_SINGLE_TLV("LOMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER5, |
| 151 | WM8400_LRBLOVOL_SHIFT, 7, 0, out_mix_tlv), |
| 152 | |
| 153 | /* ROMIX */ |
| 154 | SOC_SINGLE_TLV("ROMIX RIN3 Bypass Volume", WM8400_OUTPUT_MIXER4, |
| 155 | WM8400_RRI3ROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 156 | SOC_SINGLE_TLV("ROMIX LIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4, |
| 157 | WM8400_RL12ROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 158 | SOC_SINGLE_TLV("ROMIX RIN12 PGA Bypass Volume", WM8400_OUTPUT_MIXER4, |
| 159 | WM8400_RR12ROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 160 | SOC_SINGLE_TLV("ROMIX LIN3 Bypass Volume", WM8400_OUTPUT_MIXER6, |
| 161 | WM8400_RLI3ROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 162 | SOC_SINGLE_TLV("ROMIX AINLMUX Bypass Volume", WM8400_OUTPUT_MIXER6, |
| 163 | WM8400_RLBROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 164 | SOC_SINGLE_TLV("ROMIX AINRMUX Bypass Volume", WM8400_OUTPUT_MIXER6, |
| 165 | WM8400_RRBROVOL_SHIFT, 7, 0, out_mix_tlv), |
| 166 | |
| 167 | /* LOUT */ |
| 168 | WM8400_OUTPGA_SINGLE_R_TLV("LOUT Volume", WM8400_LEFT_OUTPUT_VOLUME, |
| 169 | WM8400_LOUTVOL_SHIFT, WM8400_LOUTVOL_MASK, 0, out_pga_tlv), |
| 170 | SOC_SINGLE("LOUT ZC", WM8400_LEFT_OUTPUT_VOLUME, WM8400_LOZC_SHIFT, 1, 0), |
| 171 | |
| 172 | /* ROUT */ |
| 173 | WM8400_OUTPGA_SINGLE_R_TLV("ROUT Volume", WM8400_RIGHT_OUTPUT_VOLUME, |
| 174 | WM8400_ROUTVOL_SHIFT, WM8400_ROUTVOL_MASK, 0, out_pga_tlv), |
| 175 | SOC_SINGLE("ROUT ZC", WM8400_RIGHT_OUTPUT_VOLUME, WM8400_ROZC_SHIFT, 1, 0), |
| 176 | |
| 177 | /* LOPGA */ |
| 178 | WM8400_OUTPGA_SINGLE_R_TLV("LOPGA Volume", WM8400_LEFT_OPGA_VOLUME, |
| 179 | WM8400_LOPGAVOL_SHIFT, WM8400_LOPGAVOL_MASK, 0, out_pga_tlv), |
| 180 | SOC_SINGLE("LOPGA ZC Switch", WM8400_LEFT_OPGA_VOLUME, |
| 181 | WM8400_LOPGAZC_SHIFT, 1, 0), |
| 182 | |
| 183 | /* ROPGA */ |
| 184 | WM8400_OUTPGA_SINGLE_R_TLV("ROPGA Volume", WM8400_RIGHT_OPGA_VOLUME, |
| 185 | WM8400_ROPGAVOL_SHIFT, WM8400_ROPGAVOL_MASK, 0, out_pga_tlv), |
| 186 | SOC_SINGLE("ROPGA ZC Switch", WM8400_RIGHT_OPGA_VOLUME, |
| 187 | WM8400_ROPGAZC_SHIFT, 1, 0), |
| 188 | |
| 189 | SOC_SINGLE("LON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 190 | WM8400_LONMUTE_SHIFT, 1, 0), |
| 191 | SOC_SINGLE("LOP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 192 | WM8400_LOPMUTE_SHIFT, 1, 0), |
| 193 | SOC_SINGLE("LOP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 194 | WM8400_LOATTN_SHIFT, 1, 0), |
| 195 | SOC_SINGLE("RON Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 196 | WM8400_RONMUTE_SHIFT, 1, 0), |
| 197 | SOC_SINGLE("ROP Mute Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 198 | WM8400_ROPMUTE_SHIFT, 1, 0), |
| 199 | SOC_SINGLE("ROP Attenuation Switch", WM8400_LINE_OUTPUTS_VOLUME, |
| 200 | WM8400_ROATTN_SHIFT, 1, 0), |
| 201 | |
| 202 | SOC_SINGLE("OUT3 Mute Switch", WM8400_OUT3_4_VOLUME, |
| 203 | WM8400_OUT3MUTE_SHIFT, 1, 0), |
| 204 | SOC_SINGLE("OUT3 Attenuation Switch", WM8400_OUT3_4_VOLUME, |
| 205 | WM8400_OUT3ATTN_SHIFT, 1, 0), |
| 206 | |
| 207 | SOC_SINGLE("OUT4 Mute Switch", WM8400_OUT3_4_VOLUME, |
| 208 | WM8400_OUT4MUTE_SHIFT, 1, 0), |
| 209 | SOC_SINGLE("OUT4 Attenuation Switch", WM8400_OUT3_4_VOLUME, |
| 210 | WM8400_OUT4ATTN_SHIFT, 1, 0), |
| 211 | |
| 212 | SOC_SINGLE("Speaker Mode Switch", WM8400_CLASSD1, |
| 213 | WM8400_CDMODE_SHIFT, 1, 0), |
| 214 | |
| 215 | SOC_SINGLE("Speaker Output Attenuation Volume", WM8400_SPEAKER_VOLUME, |
| 216 | WM8400_SPKATTN_SHIFT, WM8400_SPKATTN_MASK, 0), |
| 217 | SOC_SINGLE("Speaker DC Boost Volume", WM8400_CLASSD3, |
| 218 | WM8400_DCGAIN_SHIFT, 6, 0), |
| 219 | SOC_SINGLE("Speaker AC Boost Volume", WM8400_CLASSD3, |
| 220 | WM8400_ACGAIN_SHIFT, 6, 0), |
| 221 | |
| 222 | WM8400_OUTPGA_SINGLE_R_TLV("Left DAC Digital Volume", |
| 223 | WM8400_LEFT_DAC_DIGITAL_VOLUME, WM8400_DACL_VOL_SHIFT, |
| 224 | 127, 0, out_dac_tlv), |
| 225 | |
| 226 | WM8400_OUTPGA_SINGLE_R_TLV("Right DAC Digital Volume", |
| 227 | WM8400_RIGHT_DAC_DIGITAL_VOLUME, WM8400_DACR_VOL_SHIFT, |
| 228 | 127, 0, out_dac_tlv), |
| 229 | |
| 230 | SOC_ENUM("Left Digital Sidetone", wm8400_left_digital_sidetone_enum), |
| 231 | SOC_ENUM("Right Digital Sidetone", wm8400_right_digital_sidetone_enum), |
| 232 | |
| 233 | SOC_SINGLE_TLV("Left Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE, |
| 234 | WM8400_ADCL_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv), |
| 235 | SOC_SINGLE_TLV("Right Digital Sidetone Volume", WM8400_DIGITAL_SIDE_TONE, |
| 236 | WM8400_ADCR_DAC_SVOL_SHIFT, 15, 0, out_sidetone_tlv), |
| 237 | |
| 238 | SOC_SINGLE("ADC Digital High Pass Filter Switch", WM8400_ADC_CTRL, |
| 239 | WM8400_ADC_HPF_ENA_SHIFT, 1, 0), |
| 240 | |
| 241 | SOC_ENUM("ADC HPF Mode", wm8400_right_adcmode_enum), |
| 242 | |
| 243 | WM8400_OUTPGA_SINGLE_R_TLV("Left ADC Digital Volume", |
| 244 | WM8400_LEFT_ADC_DIGITAL_VOLUME, |
| 245 | WM8400_ADCL_VOL_SHIFT, |
| 246 | WM8400_ADCL_VOL_MASK, |
| 247 | 0, |
| 248 | in_adc_tlv), |
| 249 | |
| 250 | WM8400_OUTPGA_SINGLE_R_TLV("Right ADC Digital Volume", |
| 251 | WM8400_RIGHT_ADC_DIGITAL_VOLUME, |
| 252 | WM8400_ADCR_VOL_SHIFT, |
| 253 | WM8400_ADCR_VOL_MASK, |
| 254 | 0, |
| 255 | in_adc_tlv), |
| 256 | |
| 257 | WM8400_OUTPGA_SINGLE_R_TLV("LIN12 Volume", |
| 258 | WM8400_LEFT_LINE_INPUT_1_2_VOLUME, |
| 259 | WM8400_LIN12VOL_SHIFT, |
| 260 | WM8400_LIN12VOL_MASK, |
| 261 | 0, |
| 262 | in_pga_tlv), |
| 263 | |
| 264 | SOC_SINGLE("LIN12 ZC Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME, |
| 265 | WM8400_LI12ZC_SHIFT, 1, 0), |
| 266 | |
| 267 | SOC_SINGLE("LIN12 Mute Switch", WM8400_LEFT_LINE_INPUT_1_2_VOLUME, |
| 268 | WM8400_LI12MUTE_SHIFT, 1, 0), |
| 269 | |
| 270 | WM8400_OUTPGA_SINGLE_R_TLV("LIN34 Volume", |
| 271 | WM8400_LEFT_LINE_INPUT_3_4_VOLUME, |
| 272 | WM8400_LIN34VOL_SHIFT, |
| 273 | WM8400_LIN34VOL_MASK, |
| 274 | 0, |
| 275 | in_pga_tlv), |
| 276 | |
| 277 | SOC_SINGLE("LIN34 ZC Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME, |
| 278 | WM8400_LI34ZC_SHIFT, 1, 0), |
| 279 | |
| 280 | SOC_SINGLE("LIN34 Mute Switch", WM8400_LEFT_LINE_INPUT_3_4_VOLUME, |
| 281 | WM8400_LI34MUTE_SHIFT, 1, 0), |
| 282 | |
| 283 | WM8400_OUTPGA_SINGLE_R_TLV("RIN12 Volume", |
| 284 | WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, |
| 285 | WM8400_RIN12VOL_SHIFT, |
| 286 | WM8400_RIN12VOL_MASK, |
| 287 | 0, |
| 288 | in_pga_tlv), |
| 289 | |
| 290 | SOC_SINGLE("RIN12 ZC Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, |
| 291 | WM8400_RI12ZC_SHIFT, 1, 0), |
| 292 | |
| 293 | SOC_SINGLE("RIN12 Mute Switch", WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, |
| 294 | WM8400_RI12MUTE_SHIFT, 1, 0), |
| 295 | |
| 296 | WM8400_OUTPGA_SINGLE_R_TLV("RIN34 Volume", |
| 297 | WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, |
| 298 | WM8400_RIN34VOL_SHIFT, |
| 299 | WM8400_RIN34VOL_MASK, |
| 300 | 0, |
| 301 | in_pga_tlv), |
| 302 | |
| 303 | SOC_SINGLE("RIN34 ZC Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, |
| 304 | WM8400_RI34ZC_SHIFT, 1, 0), |
| 305 | |
| 306 | SOC_SINGLE("RIN34 Mute Switch", WM8400_RIGHT_LINE_INPUT_3_4_VOLUME, |
| 307 | WM8400_RI34MUTE_SHIFT, 1, 0), |
| 308 | |
| 309 | }; |
| 310 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 311 | /* |
| 312 | * _DAPM_ Controls |
| 313 | */ |
| 314 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 315 | static int outmixer_event (struct snd_soc_dapm_widget *w, |
| 316 | struct snd_kcontrol * kcontrol, int event) |
| 317 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 318 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 319 | struct soc_mixer_control *mc = |
| 320 | (struct soc_mixer_control *)kcontrol->private_value; |
| 321 | u32 reg_shift = mc->shift; |
| 322 | int ret = 0; |
| 323 | u16 reg; |
| 324 | |
| 325 | switch (reg_shift) { |
| 326 | case WM8400_SPEAKER_MIXER | (WM8400_LDSPK << 8) : |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 327 | reg = snd_soc_component_read(component, WM8400_OUTPUT_MIXER1); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 328 | if (reg & WM8400_LDLO) { |
| 329 | printk(KERN_WARNING |
| 330 | "Cannot set as Output Mixer 1 LDLO Set\n"); |
| 331 | ret = -1; |
| 332 | } |
| 333 | break; |
| 334 | case WM8400_SPEAKER_MIXER | (WM8400_RDSPK << 8): |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 335 | reg = snd_soc_component_read(component, WM8400_OUTPUT_MIXER2); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 336 | if (reg & WM8400_RDRO) { |
| 337 | printk(KERN_WARNING |
| 338 | "Cannot set as Output Mixer 2 RDRO Set\n"); |
| 339 | ret = -1; |
| 340 | } |
| 341 | break; |
| 342 | case WM8400_OUTPUT_MIXER1 | (WM8400_LDLO << 8): |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 343 | reg = snd_soc_component_read(component, WM8400_SPEAKER_MIXER); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 344 | if (reg & WM8400_LDSPK) { |
| 345 | printk(KERN_WARNING |
| 346 | "Cannot set as Speaker Mixer LDSPK Set\n"); |
| 347 | ret = -1; |
| 348 | } |
| 349 | break; |
| 350 | case WM8400_OUTPUT_MIXER2 | (WM8400_RDRO << 8): |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 351 | reg = snd_soc_component_read(component, WM8400_SPEAKER_MIXER); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 352 | if (reg & WM8400_RDSPK) { |
| 353 | printk(KERN_WARNING |
| 354 | "Cannot set as Speaker Mixer RDSPK Set\n"); |
| 355 | ret = -1; |
| 356 | } |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | return ret; |
| 361 | } |
| 362 | |
| 363 | /* INMIX dB values */ |
Lars-Peter Clausen | 0b65e6c | 2015-08-02 17:19:59 +0200 | [diff] [blame] | 364 | static const DECLARE_TLV_DB_SCALE(in_mix_tlv, -1200, 600, 0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 365 | |
| 366 | /* Left In PGA Connections */ |
| 367 | static const struct snd_kcontrol_new wm8400_dapm_lin12_pga_controls[] = { |
| 368 | SOC_DAPM_SINGLE("LIN1 Switch", WM8400_INPUT_MIXER2, WM8400_LMN1_SHIFT, 1, 0), |
| 369 | SOC_DAPM_SINGLE("LIN2 Switch", WM8400_INPUT_MIXER2, WM8400_LMP2_SHIFT, 1, 0), |
| 370 | }; |
| 371 | |
| 372 | static const struct snd_kcontrol_new wm8400_dapm_lin34_pga_controls[] = { |
| 373 | SOC_DAPM_SINGLE("LIN3 Switch", WM8400_INPUT_MIXER2, WM8400_LMN3_SHIFT, 1, 0), |
| 374 | SOC_DAPM_SINGLE("LIN4 Switch", WM8400_INPUT_MIXER2, WM8400_LMP4_SHIFT, 1, 0), |
| 375 | }; |
| 376 | |
| 377 | /* Right In PGA Connections */ |
| 378 | static const struct snd_kcontrol_new wm8400_dapm_rin12_pga_controls[] = { |
| 379 | SOC_DAPM_SINGLE("RIN1 Switch", WM8400_INPUT_MIXER2, WM8400_RMN1_SHIFT, 1, 0), |
| 380 | SOC_DAPM_SINGLE("RIN2 Switch", WM8400_INPUT_MIXER2, WM8400_RMP2_SHIFT, 1, 0), |
| 381 | }; |
| 382 | |
| 383 | static const struct snd_kcontrol_new wm8400_dapm_rin34_pga_controls[] = { |
| 384 | SOC_DAPM_SINGLE("RIN3 Switch", WM8400_INPUT_MIXER2, WM8400_RMN3_SHIFT, 1, 0), |
| 385 | SOC_DAPM_SINGLE("RIN4 Switch", WM8400_INPUT_MIXER2, WM8400_RMP4_SHIFT, 1, 0), |
| 386 | }; |
| 387 | |
| 388 | /* INMIXL */ |
| 389 | static const struct snd_kcontrol_new wm8400_dapm_inmixl_controls[] = { |
| 390 | SOC_DAPM_SINGLE_TLV("Record Left Volume", WM8400_INPUT_MIXER3, |
| 391 | WM8400_LDBVOL_SHIFT, WM8400_LDBVOL_MASK, 0, in_mix_tlv), |
| 392 | SOC_DAPM_SINGLE_TLV("LIN2 Volume", WM8400_INPUT_MIXER5, WM8400_LI2BVOL_SHIFT, |
| 393 | 7, 0, in_mix_tlv), |
| 394 | SOC_DAPM_SINGLE("LINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT, |
| 395 | 1, 0), |
| 396 | SOC_DAPM_SINGLE("LINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT, |
| 397 | 1, 0), |
| 398 | }; |
| 399 | |
| 400 | /* INMIXR */ |
| 401 | static const struct snd_kcontrol_new wm8400_dapm_inmixr_controls[] = { |
| 402 | SOC_DAPM_SINGLE_TLV("Record Right Volume", WM8400_INPUT_MIXER4, |
| 403 | WM8400_RDBVOL_SHIFT, WM8400_RDBVOL_MASK, 0, in_mix_tlv), |
| 404 | SOC_DAPM_SINGLE_TLV("RIN2 Volume", WM8400_INPUT_MIXER6, WM8400_RI2BVOL_SHIFT, |
| 405 | 7, 0, in_mix_tlv), |
| 406 | SOC_DAPM_SINGLE("RINPGA12 Switch", WM8400_INPUT_MIXER3, WM8400_L12MNB_SHIFT, |
| 407 | 1, 0), |
| 408 | SOC_DAPM_SINGLE("RINPGA34 Switch", WM8400_INPUT_MIXER3, WM8400_L34MNB_SHIFT, |
| 409 | 1, 0), |
| 410 | }; |
| 411 | |
| 412 | /* AINLMUX */ |
| 413 | static const char *wm8400_ainlmux[] = |
| 414 | {"INMIXL Mix", "RXVOICE Mix", "DIFFINL Mix"}; |
| 415 | |
Takashi Iwai | 898b48e | 2014-02-18 09:34:44 +0100 | [diff] [blame] | 416 | static SOC_ENUM_SINGLE_DECL(wm8400_ainlmux_enum, |
| 417 | WM8400_INPUT_MIXER1, |
| 418 | WM8400_AINLMODE_SHIFT, |
| 419 | wm8400_ainlmux); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 420 | |
| 421 | static const struct snd_kcontrol_new wm8400_dapm_ainlmux_controls = |
| 422 | SOC_DAPM_ENUM("Route", wm8400_ainlmux_enum); |
| 423 | |
| 424 | /* DIFFINL */ |
| 425 | |
| 426 | /* AINRMUX */ |
| 427 | static const char *wm8400_ainrmux[] = |
| 428 | {"INMIXR Mix", "RXVOICE Mix", "DIFFINR Mix"}; |
| 429 | |
Takashi Iwai | 898b48e | 2014-02-18 09:34:44 +0100 | [diff] [blame] | 430 | static SOC_ENUM_SINGLE_DECL(wm8400_ainrmux_enum, |
| 431 | WM8400_INPUT_MIXER1, |
| 432 | WM8400_AINRMODE_SHIFT, |
| 433 | wm8400_ainrmux); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 434 | |
| 435 | static const struct snd_kcontrol_new wm8400_dapm_ainrmux_controls = |
| 436 | SOC_DAPM_ENUM("Route", wm8400_ainrmux_enum); |
| 437 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 438 | /* LOMIX */ |
| 439 | static const struct snd_kcontrol_new wm8400_dapm_lomix_controls[] = { |
| 440 | SOC_DAPM_SINGLE("LOMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 441 | WM8400_LRBLO_SHIFT, 1, 0), |
| 442 | SOC_DAPM_SINGLE("LOMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 443 | WM8400_LLBLO_SHIFT, 1, 0), |
| 444 | SOC_DAPM_SINGLE("LOMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 445 | WM8400_LRI3LO_SHIFT, 1, 0), |
| 446 | SOC_DAPM_SINGLE("LOMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 447 | WM8400_LLI3LO_SHIFT, 1, 0), |
| 448 | SOC_DAPM_SINGLE("LOMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 449 | WM8400_LR12LO_SHIFT, 1, 0), |
| 450 | SOC_DAPM_SINGLE("LOMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER1, |
| 451 | WM8400_LL12LO_SHIFT, 1, 0), |
| 452 | SOC_DAPM_SINGLE("LOMIX Left DAC Switch", WM8400_OUTPUT_MIXER1, |
| 453 | WM8400_LDLO_SHIFT, 1, 0), |
| 454 | }; |
| 455 | |
| 456 | /* ROMIX */ |
| 457 | static const struct snd_kcontrol_new wm8400_dapm_romix_controls[] = { |
| 458 | SOC_DAPM_SINGLE("ROMIX Left ADC Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 459 | WM8400_RLBRO_SHIFT, 1, 0), |
| 460 | SOC_DAPM_SINGLE("ROMIX Right ADC Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 461 | WM8400_RRBRO_SHIFT, 1, 0), |
| 462 | SOC_DAPM_SINGLE("ROMIX LIN3 Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 463 | WM8400_RLI3RO_SHIFT, 1, 0), |
| 464 | SOC_DAPM_SINGLE("ROMIX RIN3 Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 465 | WM8400_RRI3RO_SHIFT, 1, 0), |
| 466 | SOC_DAPM_SINGLE("ROMIX LIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 467 | WM8400_RL12RO_SHIFT, 1, 0), |
| 468 | SOC_DAPM_SINGLE("ROMIX RIN12 PGA Bypass Switch", WM8400_OUTPUT_MIXER2, |
| 469 | WM8400_RR12RO_SHIFT, 1, 0), |
| 470 | SOC_DAPM_SINGLE("ROMIX Right DAC Switch", WM8400_OUTPUT_MIXER2, |
| 471 | WM8400_RDRO_SHIFT, 1, 0), |
| 472 | }; |
| 473 | |
| 474 | /* LONMIX */ |
| 475 | static const struct snd_kcontrol_new wm8400_dapm_lonmix_controls[] = { |
| 476 | SOC_DAPM_SINGLE("LONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1, |
| 477 | WM8400_LLOPGALON_SHIFT, 1, 0), |
| 478 | SOC_DAPM_SINGLE("LONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER1, |
| 479 | WM8400_LROPGALON_SHIFT, 1, 0), |
| 480 | SOC_DAPM_SINGLE("LONMIX Inverted LOP Switch", WM8400_LINE_MIXER1, |
| 481 | WM8400_LOPLON_SHIFT, 1, 0), |
| 482 | }; |
| 483 | |
| 484 | /* LOPMIX */ |
| 485 | static const struct snd_kcontrol_new wm8400_dapm_lopmix_controls[] = { |
| 486 | SOC_DAPM_SINGLE("LOPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER1, |
| 487 | WM8400_LR12LOP_SHIFT, 1, 0), |
| 488 | SOC_DAPM_SINGLE("LOPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER1, |
| 489 | WM8400_LL12LOP_SHIFT, 1, 0), |
| 490 | SOC_DAPM_SINGLE("LOPMIX Left Mixer PGA Switch", WM8400_LINE_MIXER1, |
| 491 | WM8400_LLOPGALOP_SHIFT, 1, 0), |
| 492 | }; |
| 493 | |
| 494 | /* RONMIX */ |
| 495 | static const struct snd_kcontrol_new wm8400_dapm_ronmix_controls[] = { |
| 496 | SOC_DAPM_SINGLE("RONMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2, |
| 497 | WM8400_RROPGARON_SHIFT, 1, 0), |
| 498 | SOC_DAPM_SINGLE("RONMIX Left Mixer PGA Switch", WM8400_LINE_MIXER2, |
| 499 | WM8400_RLOPGARON_SHIFT, 1, 0), |
| 500 | SOC_DAPM_SINGLE("RONMIX Inverted ROP Switch", WM8400_LINE_MIXER2, |
| 501 | WM8400_ROPRON_SHIFT, 1, 0), |
| 502 | }; |
| 503 | |
| 504 | /* ROPMIX */ |
| 505 | static const struct snd_kcontrol_new wm8400_dapm_ropmix_controls[] = { |
| 506 | SOC_DAPM_SINGLE("ROPMIX Left Mic Bypass Switch", WM8400_LINE_MIXER2, |
| 507 | WM8400_RL12ROP_SHIFT, 1, 0), |
| 508 | SOC_DAPM_SINGLE("ROPMIX Right Mic Bypass Switch", WM8400_LINE_MIXER2, |
| 509 | WM8400_RR12ROP_SHIFT, 1, 0), |
| 510 | SOC_DAPM_SINGLE("ROPMIX Right Mixer PGA Switch", WM8400_LINE_MIXER2, |
| 511 | WM8400_RROPGAROP_SHIFT, 1, 0), |
| 512 | }; |
| 513 | |
| 514 | /* OUT3MIX */ |
| 515 | static const struct snd_kcontrol_new wm8400_dapm_out3mix_controls[] = { |
| 516 | SOC_DAPM_SINGLE("OUT3MIX LIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER, |
| 517 | WM8400_LI4O3_SHIFT, 1, 0), |
| 518 | SOC_DAPM_SINGLE("OUT3MIX Left Out PGA Switch", WM8400_OUT3_4_MIXER, |
| 519 | WM8400_LPGAO3_SHIFT, 1, 0), |
| 520 | }; |
| 521 | |
| 522 | /* OUT4MIX */ |
| 523 | static const struct snd_kcontrol_new wm8400_dapm_out4mix_controls[] = { |
| 524 | SOC_DAPM_SINGLE("OUT4MIX Right Out PGA Switch", WM8400_OUT3_4_MIXER, |
| 525 | WM8400_RPGAO4_SHIFT, 1, 0), |
| 526 | SOC_DAPM_SINGLE("OUT4MIX RIN4/RXP Bypass Switch", WM8400_OUT3_4_MIXER, |
| 527 | WM8400_RI4O4_SHIFT, 1, 0), |
| 528 | }; |
| 529 | |
| 530 | /* SPKMIX */ |
| 531 | static const struct snd_kcontrol_new wm8400_dapm_spkmix_controls[] = { |
| 532 | SOC_DAPM_SINGLE("SPKMIX LIN2 Bypass Switch", WM8400_SPEAKER_MIXER, |
| 533 | WM8400_LI2SPK_SHIFT, 1, 0), |
| 534 | SOC_DAPM_SINGLE("SPKMIX LADC Bypass Switch", WM8400_SPEAKER_MIXER, |
| 535 | WM8400_LB2SPK_SHIFT, 1, 0), |
| 536 | SOC_DAPM_SINGLE("SPKMIX Left Mixer PGA Switch", WM8400_SPEAKER_MIXER, |
| 537 | WM8400_LOPGASPK_SHIFT, 1, 0), |
| 538 | SOC_DAPM_SINGLE("SPKMIX Left DAC Switch", WM8400_SPEAKER_MIXER, |
| 539 | WM8400_LDSPK_SHIFT, 1, 0), |
| 540 | SOC_DAPM_SINGLE("SPKMIX Right DAC Switch", WM8400_SPEAKER_MIXER, |
| 541 | WM8400_RDSPK_SHIFT, 1, 0), |
| 542 | SOC_DAPM_SINGLE("SPKMIX Right Mixer PGA Switch", WM8400_SPEAKER_MIXER, |
| 543 | WM8400_ROPGASPK_SHIFT, 1, 0), |
| 544 | SOC_DAPM_SINGLE("SPKMIX RADC Bypass Switch", WM8400_SPEAKER_MIXER, |
| 545 | WM8400_RL12ROP_SHIFT, 1, 0), |
| 546 | SOC_DAPM_SINGLE("SPKMIX RIN2 Bypass Switch", WM8400_SPEAKER_MIXER, |
| 547 | WM8400_RI2SPK_SHIFT, 1, 0), |
| 548 | }; |
| 549 | |
| 550 | static const struct snd_soc_dapm_widget wm8400_dapm_widgets[] = { |
| 551 | /* Input Side */ |
| 552 | /* Input Lines */ |
| 553 | SND_SOC_DAPM_INPUT("LIN1"), |
| 554 | SND_SOC_DAPM_INPUT("LIN2"), |
| 555 | SND_SOC_DAPM_INPUT("LIN3"), |
| 556 | SND_SOC_DAPM_INPUT("LIN4/RXN"), |
| 557 | SND_SOC_DAPM_INPUT("RIN3"), |
| 558 | SND_SOC_DAPM_INPUT("RIN4/RXP"), |
| 559 | SND_SOC_DAPM_INPUT("RIN1"), |
| 560 | SND_SOC_DAPM_INPUT("RIN2"), |
| 561 | SND_SOC_DAPM_INPUT("Internal ADC Source"), |
| 562 | |
| 563 | /* DACs */ |
| 564 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", WM8400_POWER_MANAGEMENT_2, |
| 565 | WM8400_ADCL_ENA_SHIFT, 0), |
| 566 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", WM8400_POWER_MANAGEMENT_2, |
| 567 | WM8400_ADCR_ENA_SHIFT, 0), |
| 568 | |
| 569 | /* Input PGAs */ |
| 570 | SND_SOC_DAPM_MIXER("LIN12 PGA", WM8400_POWER_MANAGEMENT_2, |
| 571 | WM8400_LIN12_ENA_SHIFT, |
| 572 | 0, &wm8400_dapm_lin12_pga_controls[0], |
| 573 | ARRAY_SIZE(wm8400_dapm_lin12_pga_controls)), |
| 574 | SND_SOC_DAPM_MIXER("LIN34 PGA", WM8400_POWER_MANAGEMENT_2, |
| 575 | WM8400_LIN34_ENA_SHIFT, |
| 576 | 0, &wm8400_dapm_lin34_pga_controls[0], |
| 577 | ARRAY_SIZE(wm8400_dapm_lin34_pga_controls)), |
| 578 | SND_SOC_DAPM_MIXER("RIN12 PGA", WM8400_POWER_MANAGEMENT_2, |
| 579 | WM8400_RIN12_ENA_SHIFT, |
| 580 | 0, &wm8400_dapm_rin12_pga_controls[0], |
| 581 | ARRAY_SIZE(wm8400_dapm_rin12_pga_controls)), |
| 582 | SND_SOC_DAPM_MIXER("RIN34 PGA", WM8400_POWER_MANAGEMENT_2, |
| 583 | WM8400_RIN34_ENA_SHIFT, |
| 584 | 0, &wm8400_dapm_rin34_pga_controls[0], |
| 585 | ARRAY_SIZE(wm8400_dapm_rin34_pga_controls)), |
| 586 | |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 587 | SND_SOC_DAPM_SUPPLY("INL", WM8400_POWER_MANAGEMENT_2, WM8400_AINL_ENA_SHIFT, |
| 588 | 0, NULL, 0), |
| 589 | SND_SOC_DAPM_SUPPLY("INR", WM8400_POWER_MANAGEMENT_2, WM8400_AINR_ENA_SHIFT, |
| 590 | 0, NULL, 0), |
| 591 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 592 | /* INMIXL */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 593 | SND_SOC_DAPM_MIXER("INMIXL", SND_SOC_NOPM, 0, 0, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 594 | &wm8400_dapm_inmixl_controls[0], |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 595 | ARRAY_SIZE(wm8400_dapm_inmixl_controls)), |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 596 | |
| 597 | /* AINLMUX */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 598 | SND_SOC_DAPM_MUX("AILNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainlmux_controls), |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 599 | |
| 600 | /* INMIXR */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 601 | SND_SOC_DAPM_MIXER("INMIXR", SND_SOC_NOPM, 0, 0, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 602 | &wm8400_dapm_inmixr_controls[0], |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 603 | ARRAY_SIZE(wm8400_dapm_inmixr_controls)), |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 604 | |
| 605 | /* AINRMUX */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 606 | SND_SOC_DAPM_MUX("AIRNMUX", SND_SOC_NOPM, 0, 0, &wm8400_dapm_ainrmux_controls), |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 607 | |
| 608 | /* Output Side */ |
| 609 | /* DACs */ |
| 610 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", WM8400_POWER_MANAGEMENT_3, |
| 611 | WM8400_DACL_ENA_SHIFT, 0), |
| 612 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", WM8400_POWER_MANAGEMENT_3, |
| 613 | WM8400_DACR_ENA_SHIFT, 0), |
| 614 | |
| 615 | /* LOMIX */ |
| 616 | SND_SOC_DAPM_MIXER_E("LOMIX", WM8400_POWER_MANAGEMENT_3, |
| 617 | WM8400_LOMIX_ENA_SHIFT, |
| 618 | 0, &wm8400_dapm_lomix_controls[0], |
| 619 | ARRAY_SIZE(wm8400_dapm_lomix_controls), |
| 620 | outmixer_event, SND_SOC_DAPM_PRE_REG), |
| 621 | |
| 622 | /* LONMIX */ |
| 623 | SND_SOC_DAPM_MIXER("LONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LON_ENA_SHIFT, |
| 624 | 0, &wm8400_dapm_lonmix_controls[0], |
| 625 | ARRAY_SIZE(wm8400_dapm_lonmix_controls)), |
| 626 | |
| 627 | /* LOPMIX */ |
| 628 | SND_SOC_DAPM_MIXER("LOPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_LOP_ENA_SHIFT, |
| 629 | 0, &wm8400_dapm_lopmix_controls[0], |
| 630 | ARRAY_SIZE(wm8400_dapm_lopmix_controls)), |
| 631 | |
| 632 | /* OUT3MIX */ |
| 633 | SND_SOC_DAPM_MIXER("OUT3MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT3_ENA_SHIFT, |
| 634 | 0, &wm8400_dapm_out3mix_controls[0], |
| 635 | ARRAY_SIZE(wm8400_dapm_out3mix_controls)), |
| 636 | |
| 637 | /* SPKMIX */ |
| 638 | SND_SOC_DAPM_MIXER_E("SPKMIX", WM8400_POWER_MANAGEMENT_1, WM8400_SPK_ENA_SHIFT, |
| 639 | 0, &wm8400_dapm_spkmix_controls[0], |
| 640 | ARRAY_SIZE(wm8400_dapm_spkmix_controls), outmixer_event, |
| 641 | SND_SOC_DAPM_PRE_REG), |
| 642 | |
| 643 | /* OUT4MIX */ |
| 644 | SND_SOC_DAPM_MIXER("OUT4MIX", WM8400_POWER_MANAGEMENT_1, WM8400_OUT4_ENA_SHIFT, |
| 645 | 0, &wm8400_dapm_out4mix_controls[0], |
| 646 | ARRAY_SIZE(wm8400_dapm_out4mix_controls)), |
| 647 | |
| 648 | /* ROPMIX */ |
| 649 | SND_SOC_DAPM_MIXER("ROPMIX", WM8400_POWER_MANAGEMENT_3, WM8400_ROP_ENA_SHIFT, |
| 650 | 0, &wm8400_dapm_ropmix_controls[0], |
| 651 | ARRAY_SIZE(wm8400_dapm_ropmix_controls)), |
| 652 | |
| 653 | /* RONMIX */ |
| 654 | SND_SOC_DAPM_MIXER("RONMIX", WM8400_POWER_MANAGEMENT_3, WM8400_RON_ENA_SHIFT, |
| 655 | 0, &wm8400_dapm_ronmix_controls[0], |
| 656 | ARRAY_SIZE(wm8400_dapm_ronmix_controls)), |
| 657 | |
| 658 | /* ROMIX */ |
| 659 | SND_SOC_DAPM_MIXER_E("ROMIX", WM8400_POWER_MANAGEMENT_3, |
| 660 | WM8400_ROMIX_ENA_SHIFT, |
| 661 | 0, &wm8400_dapm_romix_controls[0], |
| 662 | ARRAY_SIZE(wm8400_dapm_romix_controls), |
| 663 | outmixer_event, SND_SOC_DAPM_PRE_REG), |
| 664 | |
| 665 | /* LOUT PGA */ |
| 666 | SND_SOC_DAPM_PGA("LOUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_LOUT_ENA_SHIFT, |
| 667 | 0, NULL, 0), |
| 668 | |
| 669 | /* ROUT PGA */ |
| 670 | SND_SOC_DAPM_PGA("ROUT PGA", WM8400_POWER_MANAGEMENT_1, WM8400_ROUT_ENA_SHIFT, |
| 671 | 0, NULL, 0), |
| 672 | |
| 673 | /* LOPGA */ |
| 674 | SND_SOC_DAPM_PGA("LOPGA", WM8400_POWER_MANAGEMENT_3, WM8400_LOPGA_ENA_SHIFT, 0, |
| 675 | NULL, 0), |
| 676 | |
| 677 | /* ROPGA */ |
| 678 | SND_SOC_DAPM_PGA("ROPGA", WM8400_POWER_MANAGEMENT_3, WM8400_ROPGA_ENA_SHIFT, 0, |
| 679 | NULL, 0), |
| 680 | |
| 681 | /* MICBIAS */ |
Mark Brown | 3ff51c8 | 2011-10-27 09:44:59 +0200 | [diff] [blame] | 682 | SND_SOC_DAPM_SUPPLY("MICBIAS", WM8400_POWER_MANAGEMENT_1, |
| 683 | WM8400_MIC1BIAS_ENA_SHIFT, 0, NULL, 0), |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 684 | |
| 685 | SND_SOC_DAPM_OUTPUT("LON"), |
| 686 | SND_SOC_DAPM_OUTPUT("LOP"), |
| 687 | SND_SOC_DAPM_OUTPUT("OUT3"), |
| 688 | SND_SOC_DAPM_OUTPUT("LOUT"), |
| 689 | SND_SOC_DAPM_OUTPUT("SPKN"), |
| 690 | SND_SOC_DAPM_OUTPUT("SPKP"), |
| 691 | SND_SOC_DAPM_OUTPUT("ROUT"), |
| 692 | SND_SOC_DAPM_OUTPUT("OUT4"), |
| 693 | SND_SOC_DAPM_OUTPUT("ROP"), |
| 694 | SND_SOC_DAPM_OUTPUT("RON"), |
| 695 | |
| 696 | SND_SOC_DAPM_OUTPUT("Internal DAC Sink"), |
| 697 | }; |
| 698 | |
Mark Brown | b4505ab | 2011-12-03 11:34:34 +0000 | [diff] [blame] | 699 | static const struct snd_soc_dapm_route wm8400_dapm_routes[] = { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 700 | /* Make DACs turn on when playing even if not mixed into any outputs */ |
| 701 | {"Internal DAC Sink", NULL, "Left DAC"}, |
| 702 | {"Internal DAC Sink", NULL, "Right DAC"}, |
| 703 | |
| 704 | /* Make ADCs turn on when recording |
| 705 | * even if not mixed from any inputs */ |
| 706 | {"Left ADC", NULL, "Internal ADC Source"}, |
| 707 | {"Right ADC", NULL, "Internal ADC Source"}, |
| 708 | |
| 709 | /* Input Side */ |
| 710 | /* LIN12 PGA */ |
| 711 | {"LIN12 PGA", "LIN1 Switch", "LIN1"}, |
| 712 | {"LIN12 PGA", "LIN2 Switch", "LIN2"}, |
| 713 | /* LIN34 PGA */ |
| 714 | {"LIN34 PGA", "LIN3 Switch", "LIN3"}, |
| 715 | {"LIN34 PGA", "LIN4 Switch", "LIN4/RXN"}, |
| 716 | /* INMIXL */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 717 | {"INMIXL", NULL, "INL"}, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 718 | {"INMIXL", "Record Left Volume", "LOMIX"}, |
| 719 | {"INMIXL", "LIN2 Volume", "LIN2"}, |
| 720 | {"INMIXL", "LINPGA12 Switch", "LIN12 PGA"}, |
| 721 | {"INMIXL", "LINPGA34 Switch", "LIN34 PGA"}, |
| 722 | /* AILNMUX */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 723 | {"AILNMUX", NULL, "INL"}, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 724 | {"AILNMUX", "INMIXL Mix", "INMIXL"}, |
| 725 | {"AILNMUX", "DIFFINL Mix", "LIN12 PGA"}, |
| 726 | {"AILNMUX", "DIFFINL Mix", "LIN34 PGA"}, |
| 727 | {"AILNMUX", "RXVOICE Mix", "LIN4/RXN"}, |
| 728 | {"AILNMUX", "RXVOICE Mix", "RIN4/RXP"}, |
| 729 | /* ADC */ |
| 730 | {"Left ADC", NULL, "AILNMUX"}, |
| 731 | |
| 732 | /* RIN12 PGA */ |
| 733 | {"RIN12 PGA", "RIN1 Switch", "RIN1"}, |
| 734 | {"RIN12 PGA", "RIN2 Switch", "RIN2"}, |
| 735 | /* RIN34 PGA */ |
| 736 | {"RIN34 PGA", "RIN3 Switch", "RIN3"}, |
| 737 | {"RIN34 PGA", "RIN4 Switch", "RIN4/RXP"}, |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 738 | /* INMIXR */ |
| 739 | {"INMIXR", NULL, "INR"}, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 740 | {"INMIXR", "Record Right Volume", "ROMIX"}, |
| 741 | {"INMIXR", "RIN2 Volume", "RIN2"}, |
| 742 | {"INMIXR", "RINPGA12 Switch", "RIN12 PGA"}, |
| 743 | {"INMIXR", "RINPGA34 Switch", "RIN34 PGA"}, |
| 744 | /* AIRNMUX */ |
Mark Brown | 37c83ed | 2013-08-31 13:17:08 +0100 | [diff] [blame] | 745 | {"AIRNMUX", NULL, "INR"}, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 746 | {"AIRNMUX", "INMIXR Mix", "INMIXR"}, |
| 747 | {"AIRNMUX", "DIFFINR Mix", "RIN12 PGA"}, |
| 748 | {"AIRNMUX", "DIFFINR Mix", "RIN34 PGA"}, |
| 749 | {"AIRNMUX", "RXVOICE Mix", "LIN4/RXN"}, |
| 750 | {"AIRNMUX", "RXVOICE Mix", "RIN4/RXP"}, |
| 751 | /* ADC */ |
| 752 | {"Right ADC", NULL, "AIRNMUX"}, |
| 753 | |
| 754 | /* LOMIX */ |
| 755 | {"LOMIX", "LOMIX RIN3 Bypass Switch", "RIN3"}, |
| 756 | {"LOMIX", "LOMIX LIN3 Bypass Switch", "LIN3"}, |
| 757 | {"LOMIX", "LOMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, |
| 758 | {"LOMIX", "LOMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, |
| 759 | {"LOMIX", "LOMIX Right ADC Bypass Switch", "AIRNMUX"}, |
| 760 | {"LOMIX", "LOMIX Left ADC Bypass Switch", "AILNMUX"}, |
| 761 | {"LOMIX", "LOMIX Left DAC Switch", "Left DAC"}, |
| 762 | |
| 763 | /* ROMIX */ |
| 764 | {"ROMIX", "ROMIX RIN3 Bypass Switch", "RIN3"}, |
| 765 | {"ROMIX", "ROMIX LIN3 Bypass Switch", "LIN3"}, |
| 766 | {"ROMIX", "ROMIX LIN12 PGA Bypass Switch", "LIN12 PGA"}, |
| 767 | {"ROMIX", "ROMIX RIN12 PGA Bypass Switch", "RIN12 PGA"}, |
| 768 | {"ROMIX", "ROMIX Right ADC Bypass Switch", "AIRNMUX"}, |
| 769 | {"ROMIX", "ROMIX Left ADC Bypass Switch", "AILNMUX"}, |
| 770 | {"ROMIX", "ROMIX Right DAC Switch", "Right DAC"}, |
| 771 | |
| 772 | /* SPKMIX */ |
| 773 | {"SPKMIX", "SPKMIX LIN2 Bypass Switch", "LIN2"}, |
| 774 | {"SPKMIX", "SPKMIX RIN2 Bypass Switch", "RIN2"}, |
| 775 | {"SPKMIX", "SPKMIX LADC Bypass Switch", "AILNMUX"}, |
| 776 | {"SPKMIX", "SPKMIX RADC Bypass Switch", "AIRNMUX"}, |
| 777 | {"SPKMIX", "SPKMIX Left Mixer PGA Switch", "LOPGA"}, |
| 778 | {"SPKMIX", "SPKMIX Right Mixer PGA Switch", "ROPGA"}, |
| 779 | {"SPKMIX", "SPKMIX Right DAC Switch", "Right DAC"}, |
| 780 | {"SPKMIX", "SPKMIX Left DAC Switch", "Right DAC"}, |
| 781 | |
| 782 | /* LONMIX */ |
| 783 | {"LONMIX", "LONMIX Left Mixer PGA Switch", "LOPGA"}, |
| 784 | {"LONMIX", "LONMIX Right Mixer PGA Switch", "ROPGA"}, |
| 785 | {"LONMIX", "LONMIX Inverted LOP Switch", "LOPMIX"}, |
| 786 | |
| 787 | /* LOPMIX */ |
| 788 | {"LOPMIX", "LOPMIX Right Mic Bypass Switch", "RIN12 PGA"}, |
| 789 | {"LOPMIX", "LOPMIX Left Mic Bypass Switch", "LIN12 PGA"}, |
| 790 | {"LOPMIX", "LOPMIX Left Mixer PGA Switch", "LOPGA"}, |
| 791 | |
| 792 | /* OUT3MIX */ |
| 793 | {"OUT3MIX", "OUT3MIX LIN4/RXP Bypass Switch", "LIN4/RXN"}, |
| 794 | {"OUT3MIX", "OUT3MIX Left Out PGA Switch", "LOPGA"}, |
| 795 | |
| 796 | /* OUT4MIX */ |
| 797 | {"OUT4MIX", "OUT4MIX Right Out PGA Switch", "ROPGA"}, |
| 798 | {"OUT4MIX", "OUT4MIX RIN4/RXP Bypass Switch", "RIN4/RXP"}, |
| 799 | |
| 800 | /* RONMIX */ |
| 801 | {"RONMIX", "RONMIX Right Mixer PGA Switch", "ROPGA"}, |
| 802 | {"RONMIX", "RONMIX Left Mixer PGA Switch", "LOPGA"}, |
| 803 | {"RONMIX", "RONMIX Inverted ROP Switch", "ROPMIX"}, |
| 804 | |
| 805 | /* ROPMIX */ |
| 806 | {"ROPMIX", "ROPMIX Left Mic Bypass Switch", "LIN12 PGA"}, |
| 807 | {"ROPMIX", "ROPMIX Right Mic Bypass Switch", "RIN12 PGA"}, |
| 808 | {"ROPMIX", "ROPMIX Right Mixer PGA Switch", "ROPGA"}, |
| 809 | |
| 810 | /* Out Mixer PGAs */ |
| 811 | {"LOPGA", NULL, "LOMIX"}, |
| 812 | {"ROPGA", NULL, "ROMIX"}, |
| 813 | |
| 814 | {"LOUT PGA", NULL, "LOMIX"}, |
| 815 | {"ROUT PGA", NULL, "ROMIX"}, |
| 816 | |
| 817 | /* Output Pins */ |
| 818 | {"LON", NULL, "LONMIX"}, |
| 819 | {"LOP", NULL, "LOPMIX"}, |
| 820 | {"OUT3", NULL, "OUT3MIX"}, |
| 821 | {"LOUT", NULL, "LOUT PGA"}, |
| 822 | {"SPKN", NULL, "SPKMIX"}, |
| 823 | {"ROUT", NULL, "ROUT PGA"}, |
| 824 | {"OUT4", NULL, "OUT4MIX"}, |
| 825 | {"ROP", NULL, "ROPMIX"}, |
| 826 | {"RON", NULL, "RONMIX"}, |
| 827 | }; |
| 828 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 829 | /* |
| 830 | * Clock after FLL and dividers |
| 831 | */ |
| 832 | static int wm8400_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 833 | int clk_id, unsigned int freq, int dir) |
| 834 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 835 | struct snd_soc_component *component = codec_dai->component; |
| 836 | struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 837 | |
| 838 | wm8400->sysclk = freq; |
| 839 | return 0; |
| 840 | } |
| 841 | |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 842 | struct fll_factors { |
| 843 | u16 n; |
| 844 | u16 k; |
| 845 | u16 outdiv; |
| 846 | u16 fratio; |
| 847 | u16 freq_ref; |
| 848 | }; |
| 849 | |
| 850 | #define FIXED_FLL_SIZE ((1 << 16) * 10) |
| 851 | |
| 852 | static int fll_factors(struct wm8400_priv *wm8400, struct fll_factors *factors, |
| 853 | unsigned int Fref, unsigned int Fout) |
| 854 | { |
| 855 | u64 Kpart; |
| 856 | unsigned int K, Nmod, target; |
| 857 | |
| 858 | factors->outdiv = 2; |
| 859 | while (Fout * factors->outdiv < 90000000 || |
| 860 | Fout * factors->outdiv > 100000000) { |
| 861 | factors->outdiv *= 2; |
| 862 | if (factors->outdiv > 32) { |
| 863 | dev_err(wm8400->wm8400->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 864 | "Unsupported FLL output frequency %uHz\n", |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 865 | Fout); |
| 866 | return -EINVAL; |
| 867 | } |
| 868 | } |
| 869 | target = Fout * factors->outdiv; |
| 870 | factors->outdiv = factors->outdiv >> 2; |
| 871 | |
| 872 | if (Fref < 48000) |
| 873 | factors->freq_ref = 1; |
| 874 | else |
| 875 | factors->freq_ref = 0; |
| 876 | |
| 877 | if (Fref < 1000000) |
| 878 | factors->fratio = 9; |
| 879 | else |
| 880 | factors->fratio = 0; |
| 881 | |
| 882 | /* Ensure we have a fractional part */ |
| 883 | do { |
| 884 | if (Fref < 1000000) |
| 885 | factors->fratio--; |
| 886 | else |
| 887 | factors->fratio++; |
| 888 | |
| 889 | if (factors->fratio < 1 || factors->fratio > 8) { |
| 890 | dev_err(wm8400->wm8400->dev, |
| 891 | "Unable to calculate FRATIO\n"); |
| 892 | return -EINVAL; |
| 893 | } |
| 894 | |
| 895 | factors->n = target / (Fref * factors->fratio); |
| 896 | Nmod = target % (Fref * factors->fratio); |
| 897 | } while (Nmod == 0); |
| 898 | |
| 899 | /* Calculate fractional part - scale up so we can round. */ |
| 900 | Kpart = FIXED_FLL_SIZE * (long long)Nmod; |
| 901 | |
| 902 | do_div(Kpart, (Fref * factors->fratio)); |
| 903 | |
| 904 | K = Kpart & 0xFFFFFFFF; |
| 905 | |
| 906 | if ((K % 10) >= 5) |
| 907 | K += 5; |
| 908 | |
| 909 | /* Move down to proper range now rounding is done */ |
| 910 | factors->k = K / 10; |
| 911 | |
| 912 | dev_dbg(wm8400->wm8400->dev, |
Roel Kluin | 449bd54 | 2009-05-27 17:08:39 -0700 | [diff] [blame] | 913 | "FLL: Fref=%u Fout=%u N=%x K=%x, FRATIO=%x OUTDIV=%x\n", |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 914 | Fref, Fout, |
| 915 | factors->n, factors->k, factors->fratio, factors->outdiv); |
| 916 | |
| 917 | return 0; |
| 918 | } |
| 919 | |
| 920 | static int wm8400_set_dai_pll(struct snd_soc_dai *codec_dai, int pll_id, |
Mark Brown | 8548803 | 2009-09-05 18:52:16 +0100 | [diff] [blame] | 921 | int source, unsigned int freq_in, |
| 922 | unsigned int freq_out) |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 923 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 924 | struct snd_soc_component *component = codec_dai->component; |
| 925 | struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 926 | struct fll_factors factors; |
| 927 | int ret; |
| 928 | u16 reg; |
| 929 | |
| 930 | if (freq_in == wm8400->fll_in && freq_out == wm8400->fll_out) |
| 931 | return 0; |
| 932 | |
Mark Brown | 8aa2df5 | 2009-07-17 21:53:49 +0100 | [diff] [blame] | 933 | if (freq_out) { |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 934 | ret = fll_factors(wm8400, &factors, freq_in, freq_out); |
| 935 | if (ret != 0) |
| 936 | return ret; |
Mark Brown | 8aa2df5 | 2009-07-17 21:53:49 +0100 | [diff] [blame] | 937 | } else { |
| 938 | /* Bodge GCC 4.4.0 uninitialised variable warning - it |
| 939 | * doesn't seem capable of working out that we exit if |
| 940 | * freq_out is 0 before any of the uses. */ |
| 941 | memset(&factors, 0, sizeof(factors)); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 942 | } |
| 943 | |
| 944 | wm8400->fll_out = freq_out; |
| 945 | wm8400->fll_in = freq_in; |
| 946 | |
| 947 | /* We *must* disable the FLL before any changes */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 948 | reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_2); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 949 | reg &= ~WM8400_FLL_ENA; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 950 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_2, reg); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 951 | |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 952 | reg = snd_soc_component_read(component, WM8400_FLL_CONTROL_1); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 953 | reg &= ~WM8400_FLL_OSC_ENA; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 954 | snd_soc_component_write(component, WM8400_FLL_CONTROL_1, reg); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 955 | |
Mark Brown | 8aa2df5 | 2009-07-17 21:53:49 +0100 | [diff] [blame] | 956 | if (!freq_out) |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 957 | return 0; |
| 958 | |
| 959 | reg &= ~(WM8400_FLL_REF_FREQ | WM8400_FLL_FRATIO_MASK); |
| 960 | reg |= WM8400_FLL_FRAC | factors.fratio; |
| 961 | reg |= factors.freq_ref << WM8400_FLL_REF_FREQ_SHIFT; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 962 | snd_soc_component_write(component, WM8400_FLL_CONTROL_1, reg); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 963 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 964 | snd_soc_component_write(component, WM8400_FLL_CONTROL_2, factors.k); |
| 965 | snd_soc_component_write(component, WM8400_FLL_CONTROL_3, factors.n); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 966 | |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 967 | reg = snd_soc_component_read(component, WM8400_FLL_CONTROL_4); |
Axel Lin | 1d533de | 2011-10-22 22:48:27 +0800 | [diff] [blame] | 968 | reg &= ~WM8400_FLL_OUTDIV_MASK; |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 969 | reg |= factors.outdiv; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 970 | snd_soc_component_write(component, WM8400_FLL_CONTROL_4, reg); |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 971 | |
| 972 | return 0; |
| 973 | } |
| 974 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 975 | /* |
| 976 | * Sets ADC and Voice DAC format. |
| 977 | */ |
| 978 | static int wm8400_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 979 | unsigned int fmt) |
| 980 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 981 | struct snd_soc_component *component = codec_dai->component; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 982 | u16 audio1, audio3; |
| 983 | |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 984 | audio1 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_1); |
| 985 | audio3 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_3); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 986 | |
| 987 | /* set master/slave audio interface */ |
| 988 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 989 | case SND_SOC_DAIFMT_CBS_CFS: |
| 990 | audio3 &= ~WM8400_AIF_MSTR1; |
| 991 | break; |
| 992 | case SND_SOC_DAIFMT_CBM_CFM: |
| 993 | audio3 |= WM8400_AIF_MSTR1; |
| 994 | break; |
| 995 | default: |
| 996 | return -EINVAL; |
| 997 | } |
| 998 | |
| 999 | audio1 &= ~WM8400_AIF_FMT_MASK; |
| 1000 | |
| 1001 | /* interface format */ |
| 1002 | switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { |
| 1003 | case SND_SOC_DAIFMT_I2S: |
| 1004 | audio1 |= WM8400_AIF_FMT_I2S; |
| 1005 | audio1 &= ~WM8400_AIF_LRCLK_INV; |
| 1006 | break; |
| 1007 | case SND_SOC_DAIFMT_RIGHT_J: |
| 1008 | audio1 |= WM8400_AIF_FMT_RIGHTJ; |
| 1009 | audio1 &= ~WM8400_AIF_LRCLK_INV; |
| 1010 | break; |
| 1011 | case SND_SOC_DAIFMT_LEFT_J: |
| 1012 | audio1 |= WM8400_AIF_FMT_LEFTJ; |
| 1013 | audio1 &= ~WM8400_AIF_LRCLK_INV; |
| 1014 | break; |
| 1015 | case SND_SOC_DAIFMT_DSP_A: |
| 1016 | audio1 |= WM8400_AIF_FMT_DSP; |
| 1017 | audio1 &= ~WM8400_AIF_LRCLK_INV; |
| 1018 | break; |
| 1019 | case SND_SOC_DAIFMT_DSP_B: |
| 1020 | audio1 |= WM8400_AIF_FMT_DSP | WM8400_AIF_LRCLK_INV; |
| 1021 | break; |
| 1022 | default: |
| 1023 | return -EINVAL; |
| 1024 | } |
| 1025 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1026 | snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_1, audio1); |
| 1027 | snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_3, audio3); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1028 | return 0; |
| 1029 | } |
| 1030 | |
| 1031 | static int wm8400_set_dai_clkdiv(struct snd_soc_dai *codec_dai, |
| 1032 | int div_id, int div) |
| 1033 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1034 | struct snd_soc_component *component = codec_dai->component; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1035 | u16 reg; |
| 1036 | |
| 1037 | switch (div_id) { |
| 1038 | case WM8400_MCLK_DIV: |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1039 | reg = snd_soc_component_read(component, WM8400_CLOCKING_2) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1040 | ~WM8400_MCLK_DIV_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1041 | snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1042 | break; |
| 1043 | case WM8400_DACCLK_DIV: |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1044 | reg = snd_soc_component_read(component, WM8400_CLOCKING_2) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1045 | ~WM8400_DAC_CLKDIV_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1046 | snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1047 | break; |
| 1048 | case WM8400_ADCCLK_DIV: |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1049 | reg = snd_soc_component_read(component, WM8400_CLOCKING_2) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1050 | ~WM8400_ADC_CLKDIV_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1051 | snd_soc_component_write(component, WM8400_CLOCKING_2, reg | div); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1052 | break; |
| 1053 | case WM8400_BCLK_DIV: |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1054 | reg = snd_soc_component_read(component, WM8400_CLOCKING_1) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1055 | ~WM8400_BCLK_DIV_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1056 | snd_soc_component_write(component, WM8400_CLOCKING_1, reg | div); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1057 | break; |
| 1058 | default: |
| 1059 | return -EINVAL; |
| 1060 | } |
| 1061 | |
| 1062 | return 0; |
| 1063 | } |
| 1064 | |
| 1065 | /* |
| 1066 | * Set PCM DAI bit size and sample rate. |
| 1067 | */ |
| 1068 | static int wm8400_hw_params(struct snd_pcm_substream *substream, |
| 1069 | struct snd_pcm_hw_params *params, |
| 1070 | struct snd_soc_dai *dai) |
| 1071 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1072 | struct snd_soc_component *component = dai->component; |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1073 | u16 audio1 = snd_soc_component_read(component, WM8400_AUDIO_INTERFACE_1); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1074 | |
| 1075 | audio1 &= ~WM8400_AIF_WL_MASK; |
| 1076 | /* bit size */ |
Mark Brown | 6fe12c2 | 2014-07-31 12:49:53 +0100 | [diff] [blame] | 1077 | switch (params_width(params)) { |
| 1078 | case 16: |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1079 | break; |
Mark Brown | 6fe12c2 | 2014-07-31 12:49:53 +0100 | [diff] [blame] | 1080 | case 20: |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1081 | audio1 |= WM8400_AIF_WL_20BITS; |
| 1082 | break; |
Mark Brown | 6fe12c2 | 2014-07-31 12:49:53 +0100 | [diff] [blame] | 1083 | case 24: |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1084 | audio1 |= WM8400_AIF_WL_24BITS; |
| 1085 | break; |
Mark Brown | 6fe12c2 | 2014-07-31 12:49:53 +0100 | [diff] [blame] | 1086 | case 32: |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1087 | audio1 |= WM8400_AIF_WL_32BITS; |
| 1088 | break; |
| 1089 | } |
| 1090 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1091 | snd_soc_component_write(component, WM8400_AUDIO_INTERFACE_1, audio1); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1092 | return 0; |
| 1093 | } |
| 1094 | |
Kuninori Morimoto | 26d3c16 | 2020-07-09 10:56:53 +0900 | [diff] [blame] | 1095 | static int wm8400_mute(struct snd_soc_dai *dai, int mute, int direction) |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1096 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1097 | struct snd_soc_component *component = dai->component; |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1098 | u16 val = snd_soc_component_read(component, WM8400_DAC_CTRL) & ~WM8400_DAC_MUTE; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1099 | |
| 1100 | if (mute) |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1101 | snd_soc_component_write(component, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1102 | else |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1103 | snd_soc_component_write(component, WM8400_DAC_CTRL, val); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1104 | |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
| 1108 | /* TODO: set bias for best performance at standby */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1109 | static int wm8400_set_bias_level(struct snd_soc_component *component, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1110 | enum snd_soc_bias_level level) |
| 1111 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1112 | struct wm8400_priv *wm8400 = snd_soc_component_get_drvdata(component); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1113 | u16 val; |
| 1114 | int ret; |
| 1115 | |
| 1116 | switch (level) { |
| 1117 | case SND_SOC_BIAS_ON: |
| 1118 | break; |
| 1119 | |
| 1120 | case SND_SOC_BIAS_PREPARE: |
| 1121 | /* VMID=2*50k */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1122 | val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1123 | ~WM8400_VMID_MODE_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1124 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val | 0x2); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1125 | break; |
| 1126 | |
| 1127 | case SND_SOC_BIAS_STANDBY: |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1128 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_OFF) { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1129 | ret = regulator_bulk_enable(ARRAY_SIZE(power), |
| 1130 | &power[0]); |
| 1131 | if (ret != 0) { |
| 1132 | dev_err(wm8400->wm8400->dev, |
| 1133 | "Failed to enable regulators: %d\n", |
| 1134 | ret); |
| 1135 | return ret; |
| 1136 | } |
| 1137 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1138 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1139 | WM8400_CODEC_ENA | WM8400_SYSCLK_ENA); |
| 1140 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1141 | /* Enable POBCTRL, SOFT_ST, VMIDTOG and BUFDCOPEN */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1142 | snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1143 | WM8400_BUFDCOPEN | WM8400_POBCTRL); |
| 1144 | |
Mark Brown | e3598f6 | 2009-03-18 15:19:10 +0000 | [diff] [blame] | 1145 | msleep(50); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1146 | |
| 1147 | /* Enable VREF & VMID at 2x50k */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1148 | val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1149 | val |= 0x2 | WM8400_VREF_ENA; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1150 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1151 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1152 | /* Enable BUFIOEN */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1153 | snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1154 | WM8400_BUFDCOPEN | WM8400_POBCTRL | |
| 1155 | WM8400_BUFIOEN); |
| 1156 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1157 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1158 | snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_BUFIOEN); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1159 | } |
| 1160 | |
| 1161 | /* VMID=2*300k */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1162 | val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1) & |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1163 | ~WM8400_VMID_MODE_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1164 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val | 0x4); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1165 | break; |
| 1166 | |
| 1167 | case SND_SOC_BIAS_OFF: |
| 1168 | /* Enable POBCTRL and SOFT_ST */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1169 | snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1170 | WM8400_POBCTRL | WM8400_BUFIOEN); |
| 1171 | |
| 1172 | /* Enable POBCTRL, SOFT_ST and BUFDCOPEN */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1173 | snd_soc_component_write(component, WM8400_ANTIPOP2, WM8400_SOFTST | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1174 | WM8400_BUFDCOPEN | WM8400_POBCTRL | |
| 1175 | WM8400_BUFIOEN); |
| 1176 | |
| 1177 | /* mute DAC */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1178 | val = snd_soc_component_read(component, WM8400_DAC_CTRL); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1179 | snd_soc_component_write(component, WM8400_DAC_CTRL, val | WM8400_DAC_MUTE); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1180 | |
| 1181 | /* Enable any disabled outputs */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1182 | val = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1183 | val |= WM8400_SPK_ENA | WM8400_OUT3_ENA | |
| 1184 | WM8400_OUT4_ENA | WM8400_LOUT_ENA | |
| 1185 | WM8400_ROUT_ENA; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1186 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1187 | |
| 1188 | /* Disable VMID */ |
| 1189 | val &= ~WM8400_VMID_MODE_MASK; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1190 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1191 | |
| 1192 | msleep(300); |
| 1193 | |
| 1194 | /* Enable all output discharge bits */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1195 | snd_soc_component_write(component, WM8400_ANTIPOP1, WM8400_DIS_LLINE | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1196 | WM8400_DIS_RLINE | WM8400_DIS_OUT3 | |
| 1197 | WM8400_DIS_OUT4 | WM8400_DIS_LOUT | |
| 1198 | WM8400_DIS_ROUT); |
| 1199 | |
| 1200 | /* Disable VREF */ |
| 1201 | val &= ~WM8400_VREF_ENA; |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1202 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, val); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1203 | |
| 1204 | /* disable POBCTRL, SOFT_ST and BUFDCOPEN */ |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1205 | snd_soc_component_write(component, WM8400_ANTIPOP2, 0x0); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1206 | |
| 1207 | ret = regulator_bulk_disable(ARRAY_SIZE(power), |
| 1208 | &power[0]); |
| 1209 | if (ret != 0) |
| 1210 | return ret; |
| 1211 | |
| 1212 | break; |
| 1213 | } |
| 1214 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1215 | return 0; |
| 1216 | } |
| 1217 | |
| 1218 | #define WM8400_RATES SNDRV_PCM_RATE_8000_96000 |
| 1219 | |
| 1220 | #define WM8400_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ |
| 1221 | SNDRV_PCM_FMTBIT_S24_LE) |
| 1222 | |
Lars-Peter Clausen | 85e7652 | 2011-11-23 11:40:40 +0100 | [diff] [blame] | 1223 | static const struct snd_soc_dai_ops wm8400_dai_ops = { |
Mark Brown | 65ec1cd | 2009-03-11 16:51:31 +0000 | [diff] [blame] | 1224 | .hw_params = wm8400_hw_params, |
Kuninori Morimoto | 26d3c16 | 2020-07-09 10:56:53 +0900 | [diff] [blame] | 1225 | .mute_stream = wm8400_mute, |
Mark Brown | 65ec1cd | 2009-03-11 16:51:31 +0000 | [diff] [blame] | 1226 | .set_fmt = wm8400_set_dai_fmt, |
| 1227 | .set_clkdiv = wm8400_set_dai_clkdiv, |
| 1228 | .set_sysclk = wm8400_set_dai_sysclk, |
Mark Brown | e8523b6 | 2009-03-18 18:28:01 +0000 | [diff] [blame] | 1229 | .set_pll = wm8400_set_dai_pll, |
Kuninori Morimoto | 26d3c16 | 2020-07-09 10:56:53 +0900 | [diff] [blame] | 1230 | .no_capture_mute = 1, |
Mark Brown | 65ec1cd | 2009-03-11 16:51:31 +0000 | [diff] [blame] | 1231 | }; |
| 1232 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1233 | /* |
| 1234 | * The WM8400 supports 2 different and mutually exclusive DAI |
| 1235 | * configurations. |
| 1236 | * |
| 1237 | * 1. ADC/DAC on Primary Interface |
| 1238 | * 2. ADC on Primary Interface/DAC on secondary |
| 1239 | */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1240 | static struct snd_soc_dai_driver wm8400_dai = { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1241 | /* ADC/DAC on primary */ |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1242 | .name = "wm8400-hifi", |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1243 | .playback = { |
| 1244 | .stream_name = "Playback", |
| 1245 | .channels_min = 1, |
| 1246 | .channels_max = 2, |
| 1247 | .rates = WM8400_RATES, |
| 1248 | .formats = WM8400_FORMATS, |
| 1249 | }, |
| 1250 | .capture = { |
| 1251 | .stream_name = "Capture", |
| 1252 | .channels_min = 1, |
| 1253 | .channels_max = 2, |
| 1254 | .rates = WM8400_RATES, |
| 1255 | .formats = WM8400_FORMATS, |
| 1256 | }, |
Mark Brown | 65ec1cd | 2009-03-11 16:51:31 +0000 | [diff] [blame] | 1257 | .ops = &wm8400_dai_ops, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1258 | }; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1259 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1260 | static int wm8400_component_probe(struct snd_soc_component *component) |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1261 | { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1262 | struct wm8400 *wm8400 = dev_get_platdata(component->dev); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1263 | struct wm8400_priv *priv; |
| 1264 | int ret; |
| 1265 | u16 reg; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1266 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1267 | priv = devm_kzalloc(component->dev, sizeof(struct wm8400_priv), |
Mark Brown | b903c0e | 2011-12-03 11:41:27 +0000 | [diff] [blame] | 1268 | GFP_KERNEL); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1269 | if (priv == NULL) |
| 1270 | return -ENOMEM; |
| 1271 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1272 | snd_soc_component_init_regmap(component, wm8400->regmap); |
| 1273 | snd_soc_component_set_drvdata(component, priv); |
Mark Brown | b8cc415 | 2013-08-31 13:21:12 +0100 | [diff] [blame] | 1274 | priv->wm8400 = wm8400; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1275 | |
Sachin Kamat | 95a5b24 | 2012-11-26 17:19:36 +0530 | [diff] [blame] | 1276 | ret = devm_regulator_bulk_get(wm8400->dev, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1277 | ARRAY_SIZE(power), &power[0]); |
| 1278 | if (ret != 0) { |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1279 | dev_err(component->dev, "Failed to get regulators: %d\n", ret); |
Mark Brown | b903c0e | 2011-12-03 11:41:27 +0000 | [diff] [blame] | 1280 | return ret; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1281 | } |
| 1282 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1283 | wm8400_component_reset(component); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1284 | |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1285 | reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1286 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, reg | WM8400_CODEC_ENA); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1287 | |
| 1288 | /* Latch volume update bits */ |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1289 | reg = snd_soc_component_read(component, WM8400_LEFT_LINE_INPUT_1_2_VOLUME); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1290 | snd_soc_component_write(component, WM8400_LEFT_LINE_INPUT_1_2_VOLUME, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1291 | reg & WM8400_IPVU); |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1292 | reg = snd_soc_component_read(component, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1293 | snd_soc_component_write(component, WM8400_RIGHT_LINE_INPUT_1_2_VOLUME, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1294 | reg & WM8400_IPVU); |
| 1295 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1296 | snd_soc_component_write(component, WM8400_LEFT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
| 1297 | snd_soc_component_write(component, WM8400_RIGHT_OUTPUT_VOLUME, 0x50 | (1<<8)); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1298 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1299 | return 0; |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1300 | } |
| 1301 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1302 | static void wm8400_component_remove(struct snd_soc_component *component) |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1303 | { |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1304 | u16 reg; |
| 1305 | |
Kuninori Morimoto | 6d75dfc | 2020-06-16 14:21:29 +0900 | [diff] [blame] | 1306 | reg = snd_soc_component_read(component, WM8400_POWER_MANAGEMENT_1); |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1307 | snd_soc_component_write(component, WM8400_POWER_MANAGEMENT_1, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1308 | reg & (~WM8400_CODEC_ENA)); |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1309 | } |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1310 | |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1311 | static const struct snd_soc_component_driver soc_component_dev_wm8400 = { |
| 1312 | .probe = wm8400_component_probe, |
| 1313 | .remove = wm8400_component_remove, |
| 1314 | .set_bias_level = wm8400_set_bias_level, |
| 1315 | .controls = wm8400_snd_controls, |
| 1316 | .num_controls = ARRAY_SIZE(wm8400_snd_controls), |
| 1317 | .dapm_widgets = wm8400_dapm_widgets, |
| 1318 | .num_dapm_widgets = ARRAY_SIZE(wm8400_dapm_widgets), |
| 1319 | .dapm_routes = wm8400_dapm_routes, |
| 1320 | .num_dapm_routes = ARRAY_SIZE(wm8400_dapm_routes), |
| 1321 | .suspend_bias_off = 1, |
| 1322 | .idle_bias_on = 1, |
| 1323 | .use_pmdown_time = 1, |
| 1324 | .endianness = 1, |
| 1325 | .non_legacy_dai_naming = 1, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1326 | }; |
| 1327 | |
Bill Pemberton | 7a79e94 | 2012-12-07 09:26:37 -0500 | [diff] [blame] | 1328 | static int wm8400_probe(struct platform_device *pdev) |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1329 | { |
weiyongjun (A) | 822e70a | 2018-03-16 07:32:07 +0000 | [diff] [blame] | 1330 | return devm_snd_soc_register_component(&pdev->dev, |
Kuninori Morimoto | 10dc44c | 2018-01-29 03:00:04 +0000 | [diff] [blame] | 1331 | &soc_component_dev_wm8400, |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1332 | &wm8400_dai, 1); |
| 1333 | } |
| 1334 | |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1335 | static struct platform_driver wm8400_codec_driver = { |
| 1336 | .driver = { |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1337 | .name = "wm8400-codec", |
Liam Girdwood | f0fba2a | 2010-03-17 20:15:21 +0000 | [diff] [blame] | 1338 | }, |
| 1339 | .probe = wm8400_probe, |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1340 | }; |
| 1341 | |
Mark Brown | 5bbcc3c | 2011-11-23 22:52:08 +0000 | [diff] [blame] | 1342 | module_platform_driver(wm8400_codec_driver); |
Mark Brown | aaf1e17 | 2009-03-10 10:55:15 +0000 | [diff] [blame] | 1343 | |
| 1344 | MODULE_DESCRIPTION("ASoC WM8400 driver"); |
| 1345 | MODULE_AUTHOR("Mark Brown"); |
| 1346 | MODULE_LICENSE("GPL"); |
| 1347 | MODULE_ALIAS("platform:wm8400-codec"); |