| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | /* |
| 2 | * ALSA SoC TLV320AIC3X codec driver |
| 3 | * |
| 4 | * Author: Vladimir Barinov, <vbarinov@embeddedalley.com> |
| 5 | * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com> |
| 6 | * |
| 7 | * Based on sound/soc/codecs/wm8753.c by Liam Girdwood |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License version 2 as |
| 11 | * published by the Free Software Foundation. |
| 12 | * |
| 13 | * Notes: |
| 14 | * The AIC3X is a driver for a low power stereo audio |
| 15 | * codecs aic31, aic32, aic33, aic3007. |
| 16 | * |
| 17 | * It supports full aic33 codec functionality. |
| 18 | * The compatibility with aic32, aic31 and aic3007 is as follows: |
| 19 | * aic32/aic3007 | aic31 |
| 20 | * --------------------------------------- |
| 21 | * MONO_LOUT -> N/A | MONO_LOUT -> N/A |
| 22 | * | IN1L -> LINE1L |
| 23 | * | IN1R -> LINE1R |
| 24 | * | IN2L -> LINE2L |
| 25 | * | IN2R -> LINE2R |
| 26 | * | MIC3L/R -> N/A |
| 27 | * truncated internal functionality in |
| 28 | * accordance with documentation |
| 29 | * --------------------------------------- |
| 30 | * |
| 31 | * Hence the machine layer should disable unsupported inputs/outputs by |
| 32 | * snd_soc_dapm_disable_pin(codec, "MONO_LOUT"), etc. |
| 33 | */ |
| 34 | |
| 35 | #include <linux/module.h> |
| 36 | #include <linux/moduleparam.h> |
| 37 | #include <linux/init.h> |
| 38 | #include <linux/delay.h> |
| 39 | #include <linux/pm.h> |
| 40 | #include <linux/i2c.h> |
| 41 | #include <linux/gpio.h> |
| 42 | #include <linux/regulator/consumer.h> |
| 43 | #include <linux/of.h> |
| 44 | #include <linux/of_gpio.h> |
| 45 | #include <linux/slab.h> |
| 46 | #include <sound/core.h> |
| 47 | #include <sound/pcm.h> |
| 48 | #include <sound/pcm_params.h> |
| 49 | #include <sound/soc.h> |
| 50 | #include <sound/initval.h> |
| 51 | #include <sound/tlv.h> |
| 52 | #include <sound/tlv320aic3x.h> |
| 53 | #include <linux/regmap.h> |
| 54 | |
| 55 | #include "tlv320aic3x.h" |
| 56 | |
| 57 | #define AIC3X_NUM_SUPPLIES 4 |
| 58 | static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = { |
| 59 | "IOVDD", /* I/O Voltage */ |
| 60 | "DVDD", /* Digital Core Voltage */ |
| 61 | "AVDD", /* Analog DAC Voltage */ |
| 62 | "DRVDD", /* ADC Analog and Output Driver Voltage */ |
| 63 | }; |
| 64 | |
| 65 | static LIST_HEAD(reset_list); |
| 66 | |
| 67 | struct aic3x_priv; |
| 68 | |
| 69 | struct aic3x_disable_nb { |
| 70 | struct notifier_block nb; |
| 71 | struct aic3x_priv *aic3x; |
| 72 | }; |
| 73 | |
| 74 | /* codec private data */ |
| 75 | struct aic3x_priv { |
| 76 | struct snd_soc_component *component; |
| 77 | struct regmap *regmap; |
| 78 | struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES]; |
| 79 | struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES]; |
| 80 | struct aic3x_setup_data *setup; |
| 81 | unsigned int sysclk; |
| 82 | unsigned int dai_fmt; |
| 83 | unsigned int tdm_delay; |
| 84 | unsigned int slot_width; |
| 85 | struct list_head list; |
| 86 | int master; |
| 87 | int gpio_reset; |
| 88 | int power; |
| 89 | #define AIC3X_MODEL_3X 0 |
| 90 | #define AIC3X_MODEL_33 1 |
| 91 | #define AIC3X_MODEL_3007 2 |
| 92 | #define AIC3X_MODEL_3104 3 |
| 93 | u16 model; |
| 94 | |
| 95 | /* Selects the micbias voltage */ |
| 96 | enum aic3x_micbias_voltage micbias_vg; |
| 97 | /* Output Common-Mode Voltage */ |
| 98 | u8 ocmv; |
| 99 | }; |
| 100 | |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 101 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 102 | static const struct reg_default aic3x_reg[] = { |
| 103 | { 0, 0x00 }, { 1, 0x00 }, { 2, 0x00 }, { 3, 0x10 }, |
| 104 | { 4, 0x04 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 }, |
| 105 | { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, { 11, 0x01 }, |
| 106 | { 12, 0x00 }, { 13, 0x00 }, { 14, 0x00 }, { 15, 0x80 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 107 | { 16, 0x80 }, { 17, 0xf0 }, { 18, 0xf0 }, { 19, 0xff }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 108 | { 20, 0x78 }, { 21, 0x78 }, { 22, 0x78 }, { 23, 0x78 }, |
| 109 | { 24, 0x78 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0xfe }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 110 | { 28, 0x00 }, { 29, 0x80 }, { 30, 0xec }, { 31, 0x00 }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 111 | { 32, 0x18 }, { 33, 0x18 }, { 34, 0x00 }, { 35, 0x00 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 112 | { 36, 0x0f }, { 37, 0x00 }, { 38, 0x00 }, { 39, 0x00 }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 113 | { 40, 0x00 }, { 41, 0x00 }, { 42, 0x00 }, { 43, 0x80 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 114 | { 44, 0x08 }, { 45, 0x00 }, { 46, 0x00 }, { 47, 0x00 }, |
| 115 | { 48, 0x00 }, { 49, 0x00 }, { 50, 0x00 }, { 51, 0x8c }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 116 | { 52, 0x00 }, { 53, 0x00 }, { 54, 0x00 }, { 55, 0x00 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 117 | { 56, 0x00 }, { 57, 0x8c }, { 58, 0x8c }, { 59, 0x00 }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 118 | { 60, 0x00 }, { 61, 0x00 }, { 62, 0x00 }, { 63, 0x00 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 119 | { 64, 0x00 }, { 65, 0x8c}, { 66, 0x00 }, { 67, 0x00 }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 120 | { 68, 0x00 }, { 69, 0x00 }, { 70, 0x00 }, { 71, 0x00 }, |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 121 | { 72, 0x8c }, { 73, 0x00 }, { 74, 0x00 }, { 75, 0x00 }, |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 122 | { 76, 0x00 }, { 77, 0x00 }, { 78, 0x00 }, { 79, 0x00 }, |
| 123 | { 80, 0x00 }, { 81, 0x00 }, { 82, 0x00 }, { 83, 0x00 }, |
| 124 | { 84, 0x00 }, { 85, 0x00 }, { 86, 0x00 }, { 87, 0x00 }, |
| 125 | { 88, 0x00 }, { 89, 0x00 }, { 90, 0x00 }, { 91, 0x00 }, |
| 126 | { 92, 0x00 }, { 93, 0x00 }, { 94, 0x00 }, { 95, 0x00 }, |
| 127 | { 96, 0x00 }, { 97, 0x00 }, { 98, 0x00 }, { 99, 0x00 }, |
| 128 | { 100, 0x00 }, { 101, 0x00 }, { 102, 0x02 }, { 103, 0x00 }, |
| 129 | { 104, 0x00 }, { 105, 0x00 }, { 106, 0x00 }, { 107, 0x00 }, |
| 130 | { 108, 0x00 }, { 109, 0x00 }, |
| 131 | }; |
| 132 | |
| 133 | static bool aic3x_volatile_reg(struct device *dev, unsigned int reg) |
| 134 | { |
| 135 | switch (reg) { |
| 136 | case AIC3X_RESET: |
| 137 | return true; |
| 138 | default: |
| 139 | return false; |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | static const struct regmap_config aic3x_regmap = { |
| 144 | .reg_bits = 8, |
| 145 | .val_bits = 8, |
| 146 | |
| 147 | .max_register = DAC_ICC_ADJ, |
| 148 | .reg_defaults = aic3x_reg, |
| 149 | .num_reg_defaults = ARRAY_SIZE(aic3x_reg), |
| 150 | |
| 151 | .volatile_reg = aic3x_volatile_reg, |
| 152 | |
| 153 | .cache_type = REGCACHE_RBTREE, |
| 154 | }; |
| 155 | |
| 156 | #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \ |
| 157 | SOC_SINGLE_EXT(xname, reg, shift, mask, invert, \ |
| 158 | snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw_aic3x) |
| 159 | |
| 160 | /* |
| 161 | * All input lines are connected when !0xf and disconnected with 0xf bit field, |
| 162 | * so we have to use specific dapm_put call for input mixer |
| 163 | */ |
| 164 | static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol, |
| 165 | struct snd_ctl_elem_value *ucontrol) |
| 166 | { |
| 167 | struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol); |
| 168 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
| 169 | struct soc_mixer_control *mc = |
| 170 | (struct soc_mixer_control *)kcontrol->private_value; |
| 171 | unsigned int reg = mc->reg; |
| 172 | unsigned int shift = mc->shift; |
| 173 | int max = mc->max; |
| 174 | unsigned int mask = (1 << fls(max)) - 1; |
| 175 | unsigned int invert = mc->invert; |
| 176 | unsigned short val; |
| 177 | struct snd_soc_dapm_update update = {}; |
| 178 | int connect, change; |
| 179 | |
| 180 | val = (ucontrol->value.integer.value[0] & mask); |
| 181 | |
| 182 | mask = 0xf; |
| 183 | if (val) |
| 184 | val = mask; |
| 185 | |
| 186 | connect = !!val; |
| 187 | |
| 188 | if (invert) |
| 189 | val = mask - val; |
| 190 | |
| 191 | mask <<= shift; |
| 192 | val <<= shift; |
| 193 | |
| 194 | change = snd_soc_component_test_bits(component, reg, mask, val); |
| 195 | if (change) { |
| 196 | update.kcontrol = kcontrol; |
| 197 | update.reg = reg; |
| 198 | update.mask = mask; |
| 199 | update.val = val; |
| 200 | |
| 201 | snd_soc_dapm_mixer_update_power(dapm, kcontrol, connect, |
| 202 | &update); |
| 203 | } |
| 204 | |
| 205 | return change; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * mic bias power on/off share the same register bits with |
| 210 | * output voltage of mic bias. when power on mic bias, we |
| 211 | * need reclaim it to voltage value. |
| 212 | * 0x0 = Powered off |
| 213 | * 0x1 = MICBIAS output is powered to 2.0V, |
| 214 | * 0x2 = MICBIAS output is powered to 2.5V |
| 215 | * 0x3 = MICBIAS output is connected to AVDD |
| 216 | */ |
| 217 | static int mic_bias_event(struct snd_soc_dapm_widget *w, |
| 218 | struct snd_kcontrol *kcontrol, int event) |
| 219 | { |
| 220 | struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); |
| 221 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 222 | |
| 223 | switch (event) { |
| 224 | case SND_SOC_DAPM_POST_PMU: |
| 225 | /* change mic bias voltage to user defined */ |
| 226 | snd_soc_component_update_bits(component, MICBIAS_CTRL, |
| 227 | MICBIAS_LEVEL_MASK, |
| 228 | aic3x->micbias_vg << MICBIAS_LEVEL_SHIFT); |
| 229 | break; |
| 230 | |
| 231 | case SND_SOC_DAPM_PRE_PMD: |
| 232 | snd_soc_component_update_bits(component, MICBIAS_CTRL, |
| 233 | MICBIAS_LEVEL_MASK, 0); |
| 234 | break; |
| 235 | } |
| 236 | return 0; |
| 237 | } |
| 238 | |
| 239 | static const char * const aic3x_left_dac_mux[] = { |
| 240 | "DAC_L1", "DAC_L3", "DAC_L2" }; |
| 241 | static SOC_ENUM_SINGLE_DECL(aic3x_left_dac_enum, DAC_LINE_MUX, 6, |
| 242 | aic3x_left_dac_mux); |
| 243 | |
| 244 | static const char * const aic3x_right_dac_mux[] = { |
| 245 | "DAC_R1", "DAC_R3", "DAC_R2" }; |
| 246 | static SOC_ENUM_SINGLE_DECL(aic3x_right_dac_enum, DAC_LINE_MUX, 4, |
| 247 | aic3x_right_dac_mux); |
| 248 | |
| 249 | static const char * const aic3x_left_hpcom_mux[] = { |
| 250 | "differential of HPLOUT", "constant VCM", "single-ended" }; |
| 251 | static SOC_ENUM_SINGLE_DECL(aic3x_left_hpcom_enum, HPLCOM_CFG, 4, |
| 252 | aic3x_left_hpcom_mux); |
| 253 | |
| 254 | static const char * const aic3x_right_hpcom_mux[] = { |
| 255 | "differential of HPROUT", "constant VCM", "single-ended", |
| 256 | "differential of HPLCOM", "external feedback" }; |
| 257 | static SOC_ENUM_SINGLE_DECL(aic3x_right_hpcom_enum, HPRCOM_CFG, 3, |
| 258 | aic3x_right_hpcom_mux); |
| 259 | |
| 260 | static const char * const aic3x_linein_mode_mux[] = { |
| 261 | "single-ended", "differential" }; |
| 262 | static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_l_enum, LINE1L_2_LADC_CTRL, 7, |
| 263 | aic3x_linein_mode_mux); |
| 264 | static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_r_enum, LINE1L_2_RADC_CTRL, 7, |
| 265 | aic3x_linein_mode_mux); |
| 266 | static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_l_enum, LINE1R_2_LADC_CTRL, 7, |
| 267 | aic3x_linein_mode_mux); |
| 268 | static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_r_enum, LINE1R_2_RADC_CTRL, 7, |
| 269 | aic3x_linein_mode_mux); |
| 270 | static SOC_ENUM_SINGLE_DECL(aic3x_line2l_2_ldac_enum, LINE2L_2_LADC_CTRL, 7, |
| 271 | aic3x_linein_mode_mux); |
| 272 | static SOC_ENUM_SINGLE_DECL(aic3x_line2r_2_rdac_enum, LINE2R_2_RADC_CTRL, 7, |
| 273 | aic3x_linein_mode_mux); |
| 274 | |
| 275 | static const char * const aic3x_adc_hpf[] = { |
| 276 | "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" }; |
| 277 | static SOC_ENUM_DOUBLE_DECL(aic3x_adc_hpf_enum, AIC3X_CODEC_DFILT_CTRL, 6, 4, |
| 278 | aic3x_adc_hpf); |
| 279 | |
| 280 | static const char * const aic3x_agc_level[] = { |
| 281 | "-5.5dB", "-8dB", "-10dB", "-12dB", |
| 282 | "-14dB", "-17dB", "-20dB", "-24dB" }; |
| 283 | static SOC_ENUM_SINGLE_DECL(aic3x_lagc_level_enum, LAGC_CTRL_A, 4, |
| 284 | aic3x_agc_level); |
| 285 | static SOC_ENUM_SINGLE_DECL(aic3x_ragc_level_enum, RAGC_CTRL_A, 4, |
| 286 | aic3x_agc_level); |
| 287 | |
| 288 | static const char * const aic3x_agc_attack[] = { |
| 289 | "8ms", "11ms", "16ms", "20ms" }; |
| 290 | static SOC_ENUM_SINGLE_DECL(aic3x_lagc_attack_enum, LAGC_CTRL_A, 2, |
| 291 | aic3x_agc_attack); |
| 292 | static SOC_ENUM_SINGLE_DECL(aic3x_ragc_attack_enum, RAGC_CTRL_A, 2, |
| 293 | aic3x_agc_attack); |
| 294 | |
| 295 | static const char * const aic3x_agc_decay[] = { |
| 296 | "100ms", "200ms", "400ms", "500ms" }; |
| 297 | static SOC_ENUM_SINGLE_DECL(aic3x_lagc_decay_enum, LAGC_CTRL_A, 0, |
| 298 | aic3x_agc_decay); |
| 299 | static SOC_ENUM_SINGLE_DECL(aic3x_ragc_decay_enum, RAGC_CTRL_A, 0, |
| 300 | aic3x_agc_decay); |
| 301 | |
| 302 | static const char * const aic3x_poweron_time[] = { |
| 303 | "0us", "10us", "100us", "1ms", "10ms", "50ms", |
| 304 | "100ms", "200ms", "400ms", "800ms", "2s", "4s" }; |
| 305 | static SOC_ENUM_SINGLE_DECL(aic3x_poweron_time_enum, HPOUT_POP_REDUCTION, 4, |
| 306 | aic3x_poweron_time); |
| 307 | |
| 308 | static const char * const aic3x_rampup_step[] = { "0ms", "1ms", "2ms", "4ms" }; |
| 309 | static SOC_ENUM_SINGLE_DECL(aic3x_rampup_step_enum, HPOUT_POP_REDUCTION, 2, |
| 310 | aic3x_rampup_step); |
| 311 | |
| 312 | /* |
| 313 | * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps |
| 314 | */ |
| 315 | static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0); |
| 316 | /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */ |
| 317 | static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0); |
| 318 | /* |
| 319 | * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB. |
| 320 | * Step size is approximately 0.5 dB over most of the scale but increasing |
| 321 | * near the very low levels. |
| 322 | * Define dB scale so that it is mostly correct for range about -55 to 0 dB |
| 323 | * but having increasing dB difference below that (and where it doesn't count |
| 324 | * so much). This setting shows -50 dB (actual is -50.3 dB) for register |
| 325 | * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117. |
| 326 | */ |
| 327 | static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1); |
| 328 | |
| 329 | static const struct snd_kcontrol_new aic3x_snd_controls[] = { |
| 330 | /* Output */ |
| 331 | SOC_DOUBLE_R_TLV("PCM Playback Volume", |
| 332 | LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv), |
| 333 | |
| 334 | /* |
| 335 | * Output controls that map to output mixer switches. Note these are |
| 336 | * only for swapped L-to-R and R-to-L routes. See below stereo controls |
| 337 | * for direct L-to-L and R-to-R routes. |
| 338 | */ |
| 339 | SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume", |
| 340 | PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 341 | SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume", |
| 342 | DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 343 | |
| 344 | SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume", |
| 345 | PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 346 | SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume", |
| 347 | DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 348 | |
| 349 | SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume", |
| 350 | PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 351 | SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume", |
| 352 | DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 353 | |
| 354 | SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume", |
| 355 | PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 356 | SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume", |
| 357 | DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 358 | |
| 359 | SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume", |
| 360 | PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 361 | SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume", |
| 362 | DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 363 | |
| 364 | SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume", |
| 365 | PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 366 | SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume", |
| 367 | DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 368 | |
| 369 | /* Stereo output controls for direct L-to-L and R-to-R routes */ |
| 370 | SOC_DOUBLE_R_TLV("Line PGA Bypass Volume", |
| 371 | PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL, |
| 372 | 0, 118, 1, output_stage_tlv), |
| 373 | SOC_DOUBLE_R_TLV("Line DAC Playback Volume", |
| 374 | DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL, |
| 375 | 0, 118, 1, output_stage_tlv), |
| 376 | |
| 377 | SOC_DOUBLE_R_TLV("HP PGA Bypass Volume", |
| 378 | PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL, |
| 379 | 0, 118, 1, output_stage_tlv), |
| 380 | SOC_DOUBLE_R_TLV("HP DAC Playback Volume", |
| 381 | DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL, |
| 382 | 0, 118, 1, output_stage_tlv), |
| 383 | |
| 384 | SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume", |
| 385 | PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL, |
| 386 | 0, 118, 1, output_stage_tlv), |
| 387 | SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume", |
| 388 | DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL, |
| 389 | 0, 118, 1, output_stage_tlv), |
| 390 | |
| 391 | /* Output pin mute controls */ |
| 392 | SOC_DOUBLE_R("Line Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3, |
| 393 | 0x01, 0), |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 394 | //C_DOUBLE_R("HP Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3, |
| 395 | // 0x01, 0), |
| 396 | //C_DOUBLE_R("HPCOM Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3, |
| 397 | // 0x01, 0), |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * Note: enable Automatic input Gain Controller with care. It can |
| 401 | * adjust PGA to max value when ADC is on and will never go back. |
| 402 | */ |
| 403 | SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0), |
| 404 | SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum), |
| 405 | SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum), |
| 406 | SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum), |
| 407 | SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum), |
| 408 | SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum), |
| 409 | SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum), |
| 410 | |
| 411 | /* De-emphasis */ |
| 412 | SOC_DOUBLE("De-emphasis Switch", AIC3X_CODEC_DFILT_CTRL, 2, 0, 0x01, 0), |
| 413 | |
| 414 | /* Input */ |
| 415 | SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL, |
| 416 | 0, 119, 0, adc_tlv), |
| 417 | SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1), |
| 418 | |
| 419 | SOC_ENUM("ADC HPF Cut-off", aic3x_adc_hpf_enum), |
| 420 | |
| 421 | /* Pop reduction */ |
| 422 | SOC_ENUM("Output Driver Power-On time", aic3x_poweron_time_enum), |
| 423 | SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum), |
| 424 | }; |
| 425 | |
| 426 | /* For other than tlv320aic3104 */ |
| 427 | static const struct snd_kcontrol_new aic3x_extra_snd_controls[] = { |
| 428 | /* |
| 429 | * Output controls that map to output mixer switches. Note these are |
| 430 | * only for swapped L-to-R and R-to-L routes. See below stereo controls |
| 431 | * for direct L-to-L and R-to-R routes. |
| 432 | */ |
| 433 | SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume", |
| 434 | LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 435 | |
| 436 | SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume", |
| 437 | LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv), |
| 438 | |
| 439 | SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume", |
| 440 | LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv), |
| 441 | |
| 442 | SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume", |
| 443 | LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv), |
| 444 | |
| 445 | SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume", |
| 446 | LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 447 | |
| 448 | SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume", |
| 449 | LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv), |
| 450 | |
| 451 | /* Stereo output controls for direct L-to-L and R-to-R routes */ |
| 452 | SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume", |
| 453 | LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL, |
| 454 | 0, 118, 1, output_stage_tlv), |
| 455 | |
| 456 | SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume", |
| 457 | LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL, |
| 458 | 0, 118, 1, output_stage_tlv), |
| 459 | |
| 460 | SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume", |
| 461 | LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL, |
| 462 | 0, 118, 1, output_stage_tlv), |
| 463 | }; |
| 464 | |
| 465 | static const struct snd_kcontrol_new aic3x_mono_controls[] = { |
| 466 | SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume", |
| 467 | LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL, |
| 468 | 0, 118, 1, output_stage_tlv), |
| 469 | SOC_DOUBLE_R_TLV("Mono PGA Bypass Volume", |
| 470 | PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL, |
| 471 | 0, 118, 1, output_stage_tlv), |
| 472 | SOC_DOUBLE_R_TLV("Mono DAC Playback Volume", |
| 473 | DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL, |
| 474 | 0, 118, 1, output_stage_tlv), |
| 475 | |
| 476 | SOC_SINGLE("Mono Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0), |
| 477 | }; |
| 478 | |
| 479 | /* |
| 480 | * Class-D amplifier gain. From 0 to 18 dB in 6 dB steps |
| 481 | */ |
| 482 | static DECLARE_TLV_DB_SCALE(classd_amp_tlv, 0, 600, 0); |
| 483 | |
| 484 | static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl = |
| 485 | SOC_DOUBLE_TLV("Class-D Playback Volume", CLASSD_CTRL, 6, 4, 3, 0, classd_amp_tlv); |
| 486 | |
| 487 | /* Left DAC Mux */ |
| 488 | static const struct snd_kcontrol_new aic3x_left_dac_mux_controls = |
| 489 | SOC_DAPM_ENUM("Route", aic3x_left_dac_enum); |
| 490 | |
| 491 | /* Right DAC Mux */ |
| 492 | static const struct snd_kcontrol_new aic3x_right_dac_mux_controls = |
| 493 | SOC_DAPM_ENUM("Route", aic3x_right_dac_enum); |
| 494 | |
| 495 | /* Left HPCOM Mux */ |
| 496 | static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls = |
| 497 | SOC_DAPM_ENUM("Route", aic3x_left_hpcom_enum); |
| 498 | |
| 499 | /* Right HPCOM Mux */ |
| 500 | static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls = |
| 501 | SOC_DAPM_ENUM("Route", aic3x_right_hpcom_enum); |
| 502 | |
| 503 | /* Left Line Mixer */ |
| 504 | static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = { |
| 505 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0), |
| 506 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0), |
| 507 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0), |
| 508 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0), |
| 509 | /* Not on tlv320aic3104 */ |
| 510 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0), |
| 511 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0), |
| 512 | }; |
| 513 | |
| 514 | /* Right Line Mixer */ |
| 515 | static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = { |
| 516 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0), |
| 517 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0), |
| 518 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0), |
| 519 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0), |
| 520 | /* Not on tlv320aic3104 */ |
| 521 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0), |
| 522 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0), |
| 523 | }; |
| 524 | |
| 525 | /* Mono Mixer */ |
| 526 | static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = { |
| 527 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0), |
| 528 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0), |
| 529 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0), |
| 530 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0), |
| 531 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0), |
| 532 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0), |
| 533 | }; |
| 534 | |
| 535 | /* Left HP Mixer */ |
| 536 | static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = { |
| 537 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0), |
| 538 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0), |
| 539 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0), |
| 540 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0), |
| 541 | /* Not on tlv320aic3104 */ |
| 542 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0), |
| 543 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0), |
| 544 | }; |
| 545 | |
| 546 | /* Right HP Mixer */ |
| 547 | static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = { |
| 548 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0), |
| 549 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0), |
| 550 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0), |
| 551 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0), |
| 552 | /* Not on tlv320aic3104 */ |
| 553 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0), |
| 554 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0), |
| 555 | }; |
| 556 | |
| 557 | /* Left HPCOM Mixer */ |
| 558 | static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = { |
| 559 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0), |
| 560 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0), |
| 561 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0), |
| 562 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0), |
| 563 | /* Not on tlv320aic3104 */ |
| 564 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0), |
| 565 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0), |
| 566 | }; |
| 567 | |
| 568 | /* Right HPCOM Mixer */ |
| 569 | static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = { |
| 570 | SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0), |
| 571 | SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0), |
| 572 | SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0), |
| 573 | SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0), |
| 574 | /* Not on tlv320aic3104 */ |
| 575 | SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0), |
| 576 | SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0), |
| 577 | }; |
| 578 | |
| 579 | /* Left PGA Mixer */ |
| 580 | static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = { |
| 581 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), |
| 582 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1), |
| 583 | SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1), |
| 584 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), |
| 585 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1), |
| 586 | }; |
| 587 | |
| 588 | /* Right PGA Mixer */ |
| 589 | static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = { |
| 590 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), |
| 591 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1), |
| 592 | SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1), |
| 593 | SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1), |
| 594 | SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), |
| 595 | }; |
| 596 | |
| 597 | /* Left PGA Mixer for tlv320aic3104 */ |
| 598 | static const struct snd_kcontrol_new aic3104_left_pga_mixer_controls[] = { |
| 599 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1), |
| 600 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1), |
| 601 | SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1), |
| 602 | SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1), |
| 603 | }; |
| 604 | |
| 605 | /* Right PGA Mixer for tlv320aic3104 */ |
| 606 | static const struct snd_kcontrol_new aic3104_right_pga_mixer_controls[] = { |
| 607 | SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1), |
| 608 | SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1), |
| 609 | SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1), |
| 610 | SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1), |
| 611 | }; |
| 612 | |
| 613 | /* Left Line1 Mux */ |
| 614 | static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls = |
| 615 | SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum); |
| 616 | static const struct snd_kcontrol_new aic3x_right_line1l_mux_controls = |
| 617 | SOC_DAPM_ENUM("Route", aic3x_line1l_2_r_enum); |
| 618 | |
| 619 | /* Right Line1 Mux */ |
| 620 | static const struct snd_kcontrol_new aic3x_right_line1r_mux_controls = |
| 621 | SOC_DAPM_ENUM("Route", aic3x_line1r_2_r_enum); |
| 622 | static const struct snd_kcontrol_new aic3x_left_line1r_mux_controls = |
| 623 | SOC_DAPM_ENUM("Route", aic3x_line1r_2_l_enum); |
| 624 | |
| 625 | /* Left Line2 Mux */ |
| 626 | static const struct snd_kcontrol_new aic3x_left_line2_mux_controls = |
| 627 | SOC_DAPM_ENUM("Route", aic3x_line2l_2_ldac_enum); |
| 628 | |
| 629 | /* Right Line2 Mux */ |
| 630 | static const struct snd_kcontrol_new aic3x_right_line2_mux_controls = |
| 631 | SOC_DAPM_ENUM("Route", aic3x_line2r_2_rdac_enum); |
| 632 | |
| 633 | static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = { |
| 634 | /* Left DAC to Left Outputs */ |
| 635 | SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0), |
| 636 | SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0, |
| 637 | &aic3x_left_dac_mux_controls), |
| 638 | SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0, |
| 639 | &aic3x_left_hpcom_mux_controls), |
| 640 | SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0), |
| 641 | SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0), |
| 642 | SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0), |
| 643 | |
| 644 | /* Right DAC to Right Outputs */ |
| 645 | SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0), |
| 646 | SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0, |
| 647 | &aic3x_right_dac_mux_controls), |
| 648 | SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0, |
| 649 | &aic3x_right_hpcom_mux_controls), |
| 650 | SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0), |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 651 | //D_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0), |
| 652 | //D_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0), |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 653 | |
| 654 | /* Inputs to Left ADC */ |
| 655 | SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0), |
| 656 | SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0, |
| 657 | &aic3x_left_line1l_mux_controls), |
| 658 | SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0, |
| 659 | &aic3x_left_line1r_mux_controls), |
| 660 | |
| 661 | /* Inputs to Right ADC */ |
| 662 | SND_SOC_DAPM_ADC("Right ADC", "Right Capture", |
| 663 | LINE1R_2_RADC_CTRL, 2, 0), |
| 664 | SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0, |
| 665 | &aic3x_right_line1l_mux_controls), |
| 666 | SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0, |
| 667 | &aic3x_right_line1r_mux_controls), |
| 668 | |
| 669 | /* Mic Bias */ |
| 670 | SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0, |
| 671 | mic_bias_event, |
| 672 | SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD), |
| 673 | |
| 674 | SND_SOC_DAPM_OUTPUT("LLOUT"), |
| 675 | SND_SOC_DAPM_OUTPUT("RLOUT"), |
| 676 | SND_SOC_DAPM_OUTPUT("HPLOUT"), |
| 677 | SND_SOC_DAPM_OUTPUT("HPROUT"), |
| 678 | SND_SOC_DAPM_OUTPUT("HPLCOM"), |
| 679 | SND_SOC_DAPM_OUTPUT("HPRCOM"), |
| 680 | |
| 681 | SND_SOC_DAPM_INPUT("LINE1L"), |
| 682 | SND_SOC_DAPM_INPUT("LINE1R"), |
| 683 | |
| 684 | /* |
| 685 | * Virtual output pin to detection block inside codec. This can be |
| 686 | * used to keep codec bias on if gpio or detection features are needed. |
| 687 | * Force pin on or construct a path with an input jack and mic bias |
| 688 | * widgets. |
| 689 | */ |
| 690 | SND_SOC_DAPM_OUTPUT("Detection"), |
| 691 | }; |
| 692 | |
| 693 | /* For other than tlv320aic3104 */ |
| 694 | static const struct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = { |
| 695 | /* Inputs to Left ADC */ |
| 696 | SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 697 | &aic3x_left_pga_mixer_controls[0], |
| 698 | ARRAY_SIZE(aic3x_left_pga_mixer_controls)), |
| 699 | SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0, |
| 700 | &aic3x_left_line2_mux_controls), |
| 701 | |
| 702 | /* Inputs to Right ADC */ |
| 703 | SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 704 | &aic3x_right_pga_mixer_controls[0], |
| 705 | ARRAY_SIZE(aic3x_right_pga_mixer_controls)), |
| 706 | SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0, |
| 707 | &aic3x_right_line2_mux_controls), |
| 708 | |
| 709 | /* |
| 710 | * Not a real mic bias widget but similar function. This is for dynamic |
| 711 | * control of GPIO1 digital mic modulator clock output function when |
| 712 | * using digital mic. |
| 713 | */ |
| 714 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk", |
| 715 | AIC3X_GPIO1_REG, 4, 0xf, |
| 716 | AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK, |
| 717 | AIC3X_GPIO1_FUNC_DISABLED), |
| 718 | |
| 719 | /* |
| 720 | * Also similar function like mic bias. Selects digital mic with |
| 721 | * configurable oversampling rate instead of ADC converter. |
| 722 | */ |
| 723 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128", |
| 724 | AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0), |
| 725 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64", |
| 726 | AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0), |
| 727 | SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32", |
| 728 | AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0), |
| 729 | |
| 730 | /* Output mixers */ |
| 731 | SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0, |
| 732 | &aic3x_left_line_mixer_controls[0], |
| 733 | ARRAY_SIZE(aic3x_left_line_mixer_controls)), |
| 734 | SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0, |
| 735 | &aic3x_right_line_mixer_controls[0], |
| 736 | ARRAY_SIZE(aic3x_right_line_mixer_controls)), |
| 737 | SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0, |
| 738 | &aic3x_left_hp_mixer_controls[0], |
| 739 | ARRAY_SIZE(aic3x_left_hp_mixer_controls)), |
| 740 | SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0, |
| 741 | &aic3x_right_hp_mixer_controls[0], |
| 742 | ARRAY_SIZE(aic3x_right_hp_mixer_controls)), |
| 743 | SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 744 | &aic3x_left_hpcom_mixer_controls[0], |
| 745 | ARRAY_SIZE(aic3x_left_hpcom_mixer_controls)), |
| 746 | SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 747 | &aic3x_right_hpcom_mixer_controls[0], |
| 748 | ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)), |
| 749 | |
| 750 | SND_SOC_DAPM_INPUT("MIC3L"), |
| 751 | SND_SOC_DAPM_INPUT("MIC3R"), |
| 752 | SND_SOC_DAPM_INPUT("LINE2L"), |
| 753 | SND_SOC_DAPM_INPUT("LINE2R"), |
| 754 | }; |
| 755 | |
| 756 | /* For tlv320aic3104 */ |
| 757 | static const struct snd_soc_dapm_widget aic3104_extra_dapm_widgets[] = { |
| 758 | /* Inputs to Left ADC */ |
| 759 | SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 760 | &aic3104_left_pga_mixer_controls[0], |
| 761 | ARRAY_SIZE(aic3104_left_pga_mixer_controls)), |
| 762 | |
| 763 | /* Inputs to Right ADC */ |
| 764 | SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0, |
| 765 | &aic3104_right_pga_mixer_controls[0], |
| 766 | ARRAY_SIZE(aic3104_right_pga_mixer_controls)), |
| 767 | |
| 768 | /* Output mixers */ |
| 769 | SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0, |
| 770 | &aic3x_left_line_mixer_controls[0], |
| 771 | ARRAY_SIZE(aic3x_left_line_mixer_controls) - 2), |
| 772 | SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0, |
| 773 | &aic3x_right_line_mixer_controls[0], |
| 774 | ARRAY_SIZE(aic3x_right_line_mixer_controls) - 2), |
| 775 | SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0, |
| 776 | &aic3x_left_hp_mixer_controls[0], |
| 777 | ARRAY_SIZE(aic3x_left_hp_mixer_controls) - 2), |
| 778 | SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0, |
| 779 | &aic3x_right_hp_mixer_controls[0], |
| 780 | ARRAY_SIZE(aic3x_right_hp_mixer_controls) - 2), |
| 781 | SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 782 | &aic3x_left_hpcom_mixer_controls[0], |
| 783 | ARRAY_SIZE(aic3x_left_hpcom_mixer_controls) - 2), |
| 784 | SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0, |
| 785 | &aic3x_right_hpcom_mixer_controls[0], |
| 786 | ARRAY_SIZE(aic3x_right_hpcom_mixer_controls) - 2), |
| 787 | |
| 788 | SND_SOC_DAPM_INPUT("MIC2L"), |
| 789 | SND_SOC_DAPM_INPUT("MIC2R"), |
| 790 | }; |
| 791 | |
| 792 | static const struct snd_soc_dapm_widget aic3x_dapm_mono_widgets[] = { |
| 793 | /* Mono Output */ |
| 794 | SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0), |
| 795 | |
| 796 | SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0, |
| 797 | &aic3x_mono_mixer_controls[0], |
| 798 | ARRAY_SIZE(aic3x_mono_mixer_controls)), |
| 799 | |
| 800 | SND_SOC_DAPM_OUTPUT("MONO_LOUT"), |
| 801 | }; |
| 802 | |
| 803 | static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = { |
| 804 | /* Class-D outputs */ |
| 805 | SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0), |
| 806 | SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0), |
| 807 | |
| 808 | SND_SOC_DAPM_OUTPUT("SPOP"), |
| 809 | SND_SOC_DAPM_OUTPUT("SPOM"), |
| 810 | }; |
| 811 | |
| 812 | static const struct snd_soc_dapm_route intercon[] = { |
| 813 | /* Left Input */ |
| 814 | {"Left Line1L Mux", "single-ended", "LINE1L"}, |
| 815 | {"Left Line1L Mux", "differential", "LINE1L"}, |
| 816 | {"Left Line1R Mux", "single-ended", "LINE1R"}, |
| 817 | {"Left Line1R Mux", "differential", "LINE1R"}, |
| 818 | |
| 819 | {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"}, |
| 820 | {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"}, |
| 821 | |
| 822 | {"Left ADC", NULL, "Left PGA Mixer"}, |
| 823 | |
| 824 | //tianyan@2021.09.17 modify for tlv320 record start |
| 825 | {"Left ADC", NULL, "Mic Bias"}, |
| 826 | //tianyan@2021.09.17 modify for tlv320 record end |
| 827 | |
| 828 | /* Right Input */ |
| 829 | {"Right Line1R Mux", "single-ended", "LINE1R"}, |
| 830 | {"Right Line1R Mux", "differential", "LINE1R"}, |
| 831 | {"Right Line1L Mux", "single-ended", "LINE1L"}, |
| 832 | {"Right Line1L Mux", "differential", "LINE1L"}, |
| 833 | |
| 834 | {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"}, |
| 835 | {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"}, |
| 836 | |
| 837 | {"Right ADC", NULL, "Right PGA Mixer"}, |
| 838 | |
| 839 | //tianyan@2021.09.17 modify for tlv320 record start |
| 840 | {"Right ADC", NULL, "Mic Bias"}, |
| 841 | //tianyan@2021.09.17 modify for tlv320 record end |
| 842 | |
| 843 | /* Left DAC Output */ |
| 844 | {"Left DAC Mux", "DAC_L1", "Left DAC"}, |
| 845 | {"Left DAC Mux", "DAC_L2", "Left DAC"}, |
| 846 | {"Left DAC Mux", "DAC_L3", "Left DAC"}, |
| 847 | |
| 848 | /* Right DAC Output */ |
| 849 | {"Right DAC Mux", "DAC_R1", "Right DAC"}, |
| 850 | {"Right DAC Mux", "DAC_R2", "Right DAC"}, |
| 851 | {"Right DAC Mux", "DAC_R3", "Right DAC"}, |
| 852 | |
| 853 | /* Left Line Output */ |
| 854 | {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 855 | {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 856 | {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 857 | {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 858 | |
| 859 | {"Left Line Out", NULL, "Left Line Mixer"}, |
| 860 | {"Left Line Out", NULL, "Left DAC Mux"}, |
| 861 | {"LLOUT", NULL, "Left Line Out"}, |
| 862 | |
| 863 | /* Right Line Output */ |
| 864 | {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 865 | {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 866 | {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 867 | {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 868 | |
| 869 | {"Right Line Out", NULL, "Right Line Mixer"}, |
| 870 | {"Right Line Out", NULL, "Right DAC Mux"}, |
| 871 | {"RLOUT", NULL, "Right Line Out"}, |
| 872 | |
| 873 | /* Left HP Output */ |
| 874 | {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 875 | {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 876 | {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 877 | {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 878 | |
| 879 | {"Left HP Out", NULL, "Left HP Mixer"}, |
| 880 | {"Left HP Out", NULL, "Left DAC Mux"}, |
| 881 | {"HPLOUT", NULL, "Left HP Out"}, |
| 882 | |
| 883 | /* Right HP Output */ |
| 884 | {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 885 | {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 886 | {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 887 | {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 888 | |
| 889 | {"Right HP Out", NULL, "Right HP Mixer"}, |
| 890 | {"Right HP Out", NULL, "Right DAC Mux"}, |
| 891 | {"HPROUT", NULL, "Right HP Out"}, |
| 892 | |
| 893 | /* Left HPCOM Output */ |
| 894 | {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 895 | {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 896 | {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 897 | {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 898 | |
| 899 | {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"}, |
| 900 | {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"}, |
| 901 | {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"}, |
| 902 | {"Left HP Com", NULL, "Left HPCOM Mux"}, |
| 903 | {"HPLCOM", NULL, "Left HP Com"}, |
| 904 | |
| 905 | /* Right HPCOM Output */ |
| 906 | {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 907 | {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 908 | {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 909 | {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 910 | |
| 911 | {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"}, |
| 912 | {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"}, |
| 913 | {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"}, |
| 914 | {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"}, |
| 915 | {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"}, |
| 916 | {"Right HP Com", NULL, "Right HPCOM Mux"}, |
| 917 | {"HPRCOM", NULL, "Right HP Com"}, |
| 918 | }; |
| 919 | |
| 920 | /* For other than tlv320aic3104 */ |
| 921 | static const struct snd_soc_dapm_route intercon_extra[] = { |
| 922 | /* Left Input */ |
| 923 | {"Left Line2L Mux", "single-ended", "LINE2L"}, |
| 924 | {"Left Line2L Mux", "differential", "LINE2L"}, |
| 925 | |
| 926 | {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"}, |
| 927 | {"Left PGA Mixer", "Mic3L Switch", "MIC3L"}, |
| 928 | {"Left PGA Mixer", "Mic3R Switch", "MIC3R"}, |
| 929 | |
| 930 | {"Left ADC", NULL, "GPIO1 dmic modclk"}, |
| 931 | |
| 932 | /* Right Input */ |
| 933 | {"Right Line2R Mux", "single-ended", "LINE2R"}, |
| 934 | {"Right Line2R Mux", "differential", "LINE2R"}, |
| 935 | |
| 936 | {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"}, |
| 937 | {"Right PGA Mixer", "Mic3L Switch", "MIC3L"}, |
| 938 | {"Right PGA Mixer", "Mic3R Switch", "MIC3R"}, |
| 939 | |
| 940 | {"Right ADC", NULL, "GPIO1 dmic modclk"}, |
| 941 | |
| 942 | /* |
| 943 | * Logical path between digital mic enable and GPIO1 modulator clock |
| 944 | * output function |
| 945 | */ |
| 946 | {"GPIO1 dmic modclk", NULL, "DMic Rate 128"}, |
| 947 | {"GPIO1 dmic modclk", NULL, "DMic Rate 64"}, |
| 948 | {"GPIO1 dmic modclk", NULL, "DMic Rate 32"}, |
| 949 | |
| 950 | /* Left Line Output */ |
| 951 | {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 952 | {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 953 | |
| 954 | /* Right Line Output */ |
| 955 | {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 956 | {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 957 | |
| 958 | /* Left HP Output */ |
| 959 | {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 960 | {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 961 | |
| 962 | /* Right HP Output */ |
| 963 | {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 964 | {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 965 | |
| 966 | /* Left HPCOM Output */ |
| 967 | {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 968 | {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 969 | |
| 970 | /* Right HPCOM Output */ |
| 971 | {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 972 | {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 973 | }; |
| 974 | |
| 975 | /* For tlv320aic3104 */ |
| 976 | static const struct snd_soc_dapm_route intercon_extra_3104[] = { |
| 977 | /* Left Input */ |
| 978 | {"Left PGA Mixer", "Mic2L Switch", "MIC2L"}, |
| 979 | {"Left PGA Mixer", "Mic2R Switch", "MIC2R"}, |
| 980 | |
| 981 | /* Right Input */ |
| 982 | {"Right PGA Mixer", "Mic2L Switch", "MIC2L"}, |
| 983 | {"Right PGA Mixer", "Mic2R Switch", "MIC2R"}, |
| 984 | }; |
| 985 | |
| 986 | static const struct snd_soc_dapm_route intercon_mono[] = { |
| 987 | /* Mono Output */ |
| 988 | {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"}, |
| 989 | {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"}, |
| 990 | {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"}, |
| 991 | {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"}, |
| 992 | {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"}, |
| 993 | {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"}, |
| 994 | {"Mono Out", NULL, "Mono Mixer"}, |
| 995 | {"MONO_LOUT", NULL, "Mono Out"}, |
| 996 | }; |
| 997 | |
| 998 | static const struct snd_soc_dapm_route intercon_3007[] = { |
| 999 | /* Class-D outputs */ |
| 1000 | {"Left Class-D Out", NULL, "Left Line Out"}, |
| 1001 | {"Right Class-D Out", NULL, "Left Line Out"}, |
| 1002 | {"SPOP", NULL, "Left Class-D Out"}, |
| 1003 | {"SPOM", NULL, "Right Class-D Out"}, |
| 1004 | }; |
| 1005 | |
| 1006 | static int aic3x_add_widgets(struct snd_soc_component *component) |
| 1007 | { |
| 1008 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1009 | struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component); |
| 1010 | |
| 1011 | switch (aic3x->model) { |
| 1012 | case AIC3X_MODEL_3X: |
| 1013 | case AIC3X_MODEL_33: |
| 1014 | snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets, |
| 1015 | ARRAY_SIZE(aic3x_extra_dapm_widgets)); |
| 1016 | snd_soc_dapm_add_routes(dapm, intercon_extra, |
| 1017 | ARRAY_SIZE(intercon_extra)); |
| 1018 | snd_soc_dapm_new_controls(dapm, aic3x_dapm_mono_widgets, |
| 1019 | ARRAY_SIZE(aic3x_dapm_mono_widgets)); |
| 1020 | snd_soc_dapm_add_routes(dapm, intercon_mono, |
| 1021 | ARRAY_SIZE(intercon_mono)); |
| 1022 | break; |
| 1023 | case AIC3X_MODEL_3007: |
| 1024 | snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets, |
| 1025 | ARRAY_SIZE(aic3x_extra_dapm_widgets)); |
| 1026 | snd_soc_dapm_add_routes(dapm, intercon_extra, |
| 1027 | ARRAY_SIZE(intercon_extra)); |
| 1028 | snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets, |
| 1029 | ARRAY_SIZE(aic3007_dapm_widgets)); |
| 1030 | snd_soc_dapm_add_routes(dapm, intercon_3007, |
| 1031 | ARRAY_SIZE(intercon_3007)); |
| 1032 | break; |
| 1033 | case AIC3X_MODEL_3104: |
| 1034 | snd_soc_dapm_new_controls(dapm, aic3104_extra_dapm_widgets, |
| 1035 | ARRAY_SIZE(aic3104_extra_dapm_widgets)); |
| 1036 | snd_soc_dapm_add_routes(dapm, intercon_extra_3104, |
| 1037 | ARRAY_SIZE(intercon_extra_3104)); |
| 1038 | break; |
| 1039 | } |
| 1040 | |
| 1041 | return 0; |
| 1042 | } |
| 1043 | |
| 1044 | static int aic3x_hw_params(struct snd_pcm_substream *substream, |
| 1045 | struct snd_pcm_hw_params *params, |
| 1046 | struct snd_soc_dai *dai) |
| 1047 | { |
| 1048 | struct snd_soc_component *component = dai->component; |
| 1049 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1050 | int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0; |
| 1051 | u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1; |
| 1052 | u16 d, pll_d = 1; |
| 1053 | int clk; |
| 1054 | int width = aic3x->slot_width; |
| 1055 | |
| 1056 | if (!width) |
| 1057 | width = params_width(params); |
| 1058 | |
| 1059 | /* select data word length */ |
| 1060 | data = snd_soc_component_read32(component, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4)); |
| 1061 | switch (width) { |
| 1062 | case 16: |
| 1063 | break; |
| 1064 | case 20: |
| 1065 | data |= (0x01 << 4); |
| 1066 | break; |
| 1067 | case 24: |
| 1068 | data |= (0x02 << 4); |
| 1069 | break; |
| 1070 | case 32: |
| 1071 | data |= (0x03 << 4); |
| 1072 | break; |
| 1073 | } |
| 1074 | snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLB, data); |
| 1075 | |
| 1076 | /* Fsref can be 44100 or 48000 */ |
| 1077 | fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000; |
| 1078 | |
| 1079 | /* Try to find a value for Q which allows us to bypass the PLL and |
| 1080 | * generate CODEC_CLK directly. */ |
| 1081 | for (pll_q = 2; pll_q < 18; pll_q++) |
| 1082 | if (aic3x->sysclk / (128 * pll_q) == fsref) { |
| 1083 | bypass_pll = 1; |
| 1084 | break; |
| 1085 | } |
| 1086 | |
| 1087 | if (bypass_pll) { |
| 1088 | pll_q &= 0xf; |
| 1089 | snd_soc_component_write(component, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT); |
| 1090 | snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV); |
| 1091 | /* disable PLL if it is bypassed */ |
| 1092 | snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0); |
| 1093 | |
| 1094 | } else { |
| 1095 | snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV); |
| 1096 | /* enable PLL when it is used */ |
| 1097 | snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, |
| 1098 | PLL_ENABLE, PLL_ENABLE); |
| 1099 | } |
| 1100 | |
| 1101 | /* Route Left DAC to left channel input and |
| 1102 | * right DAC to right channel input */ |
| 1103 | data = (LDAC2LCH | RDAC2RCH); |
| 1104 | data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000; |
| 1105 | if (params_rate(params) >= 64000) |
| 1106 | data |= DUAL_RATE_MODE; |
| 1107 | snd_soc_component_write(component, AIC3X_CODEC_DATAPATH_REG, data); |
| 1108 | |
| 1109 | /* codec sample rate select */ |
| 1110 | data = (fsref * 20) / params_rate(params); |
| 1111 | if (params_rate(params) < 64000) |
| 1112 | data /= 2; |
| 1113 | data /= 5; |
| 1114 | data -= 2; |
| 1115 | data |= (data << 4); |
| 1116 | snd_soc_component_write(component, AIC3X_SAMPLE_RATE_SEL_REG, data); |
| 1117 | |
| 1118 | if (bypass_pll) |
| 1119 | return 0; |
| 1120 | |
| 1121 | /* Use PLL, compute appropriate setup for j, d, r and p, the closest |
| 1122 | * one wins the game. Try with d==0 first, next with d!=0. |
| 1123 | * Constraints for j are according to the datasheet. |
| 1124 | * The sysclk is divided by 1000 to prevent integer overflows. |
| 1125 | */ |
| 1126 | |
| 1127 | codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000); |
| 1128 | |
| 1129 | for (r = 1; r <= 16; r++) |
| 1130 | for (p = 1; p <= 8; p++) { |
| 1131 | for (j = 4; j <= 55; j++) { |
| 1132 | /* This is actually 1000*((j+(d/10000))*r)/p |
| 1133 | * The term had to be converted to get |
| 1134 | * rid of the division by 10000; d = 0 here |
| 1135 | */ |
| 1136 | int tmp_clk = (1000 * j * r) / p; |
| 1137 | |
| 1138 | /* Check whether this values get closer than |
| 1139 | * the best ones we had before |
| 1140 | */ |
| 1141 | if (abs(codec_clk - tmp_clk) < |
| 1142 | abs(codec_clk - last_clk)) { |
| 1143 | pll_j = j; pll_d = 0; |
| 1144 | pll_r = r; pll_p = p; |
| 1145 | last_clk = tmp_clk; |
| 1146 | } |
| 1147 | |
| 1148 | /* Early exit for exact matches */ |
| 1149 | if (tmp_clk == codec_clk) |
| 1150 | goto found; |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | /* try with d != 0 */ |
| 1155 | for (p = 1; p <= 8; p++) { |
| 1156 | j = codec_clk * p / 1000; |
| 1157 | |
| 1158 | if (j < 4 || j > 11) |
| 1159 | continue; |
| 1160 | |
| 1161 | /* do not use codec_clk here since we'd loose precision */ |
| 1162 | d = ((2048 * p * fsref) - j * aic3x->sysclk) |
| 1163 | * 100 / (aic3x->sysclk/100); |
| 1164 | |
| 1165 | clk = (10000 * j + d) / (10 * p); |
| 1166 | |
| 1167 | /* check whether this values get closer than the best |
| 1168 | * ones we had before */ |
| 1169 | if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) { |
| 1170 | pll_j = j; pll_d = d; pll_r = 1; pll_p = p; |
| 1171 | last_clk = clk; |
| 1172 | } |
| 1173 | |
| 1174 | /* Early exit for exact matches */ |
| 1175 | if (clk == codec_clk) |
| 1176 | goto found; |
| 1177 | } |
| 1178 | |
| 1179 | if (last_clk == 0) { |
| 1180 | printk(KERN_ERR "%s(): unable to setup PLL\n", __func__); |
| 1181 | return -EINVAL; |
| 1182 | } |
| 1183 | |
| 1184 | found: |
| 1185 | snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, PLLP_MASK, pll_p); |
| 1186 | snd_soc_component_write(component, AIC3X_OVRF_STATUS_AND_PLLR_REG, |
| 1187 | pll_r << PLLR_SHIFT); |
| 1188 | snd_soc_component_write(component, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT); |
| 1189 | snd_soc_component_write(component, AIC3X_PLL_PROGC_REG, |
| 1190 | (pll_d >> 6) << PLLD_MSB_SHIFT); |
| 1191 | snd_soc_component_write(component, AIC3X_PLL_PROGD_REG, |
| 1192 | (pll_d & 0x3F) << PLLD_LSB_SHIFT); |
| 1193 | |
| 1194 | return 0; |
| 1195 | } |
| 1196 | |
| 1197 | static int aic3x_prepare(struct snd_pcm_substream *substream, |
| 1198 | struct snd_soc_dai *dai) |
| 1199 | { |
| 1200 | struct snd_soc_component *component = dai->component; |
| 1201 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1202 | int delay = 0; |
| 1203 | int width = aic3x->slot_width; |
| 1204 | |
| 1205 | if (!width) |
| 1206 | width = substream->runtime->sample_bits; |
| 1207 | |
| 1208 | /* TDM slot selection only valid in DSP_A/_B mode */ |
| 1209 | if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_A) |
| 1210 | delay += (aic3x->tdm_delay*width + 1); |
| 1211 | else if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_B) |
| 1212 | delay += aic3x->tdm_delay*width; |
| 1213 | |
| 1214 | /* Configure data delay */ |
| 1215 | snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLC, delay); |
| 1216 | |
| 1217 | return 0; |
| 1218 | } |
| 1219 | |
| 1220 | static int aic3x_mute(struct snd_soc_dai *dai, int mute) |
| 1221 | { |
| 1222 | struct snd_soc_component *component = dai->component; |
| 1223 | u8 ldac_reg = snd_soc_component_read32(component, LDAC_VOL) & ~MUTE_ON; |
| 1224 | u8 rdac_reg = snd_soc_component_read32(component, RDAC_VOL) & ~MUTE_ON; |
| 1225 | |
| 1226 | if (mute) { |
| 1227 | snd_soc_component_write(component, LDAC_VOL, ldac_reg | MUTE_ON); |
| 1228 | snd_soc_component_write(component, RDAC_VOL, rdac_reg | MUTE_ON); |
| 1229 | } else { |
| 1230 | snd_soc_component_write(component, LDAC_VOL, ldac_reg); |
| 1231 | snd_soc_component_write(component, RDAC_VOL, rdac_reg); |
| 1232 | } |
| 1233 | |
| 1234 | return 0; |
| 1235 | } |
| 1236 | |
| 1237 | static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai, |
| 1238 | int clk_id, unsigned int freq, int dir) |
| 1239 | { |
| 1240 | struct snd_soc_component *component = codec_dai->component; |
| 1241 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1242 | |
| 1243 | /* set clock on MCLK or GPIO2 or BCLK */ |
| 1244 | snd_soc_component_update_bits(component, AIC3X_CLKGEN_CTRL_REG, PLLCLK_IN_MASK, |
| 1245 | clk_id << PLLCLK_IN_SHIFT); |
| 1246 | snd_soc_component_update_bits(component, AIC3X_CLKGEN_CTRL_REG, CLKDIV_IN_MASK, |
| 1247 | clk_id << CLKDIV_IN_SHIFT); |
| 1248 | |
| 1249 | aic3x->sysclk = freq; |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai, |
| 1254 | unsigned int fmt) |
| 1255 | { |
| 1256 | struct snd_soc_component *component = codec_dai->component; |
| 1257 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1258 | u8 iface_areg, iface_breg; |
| 1259 | |
| 1260 | iface_areg = snd_soc_component_read32(component, AIC3X_ASD_INTF_CTRLA) & 0x3f; |
| 1261 | iface_breg = snd_soc_component_read32(component, AIC3X_ASD_INTF_CTRLB) & 0x3f; |
| 1262 | |
| 1263 | /* set master/slave audio interface */ |
| 1264 | switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { |
| 1265 | case SND_SOC_DAIFMT_CBM_CFM: |
| 1266 | aic3x->master = 1; |
| 1267 | iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER; |
| 1268 | break; |
| 1269 | case SND_SOC_DAIFMT_CBS_CFS: |
| 1270 | aic3x->master = 0; |
| 1271 | iface_areg &= ~(BIT_CLK_MASTER | WORD_CLK_MASTER); |
| 1272 | break; |
| 1273 | default: |
| 1274 | return -EINVAL; |
| 1275 | } |
| 1276 | |
| 1277 | /* |
| 1278 | * match both interface format and signal polarities since they |
| 1279 | * are fixed |
| 1280 | */ |
| 1281 | switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK | |
| 1282 | SND_SOC_DAIFMT_INV_MASK)) { |
| 1283 | case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): |
| 1284 | break; |
| 1285 | case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): |
| 1286 | case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF): |
| 1287 | iface_breg |= (0x01 << 6); |
| 1288 | break; |
| 1289 | case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF): |
| 1290 | iface_breg |= (0x02 << 6); |
| 1291 | break; |
| 1292 | case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF): |
| 1293 | iface_breg |= (0x03 << 6); |
| 1294 | break; |
| 1295 | default: |
| 1296 | return -EINVAL; |
| 1297 | } |
| 1298 | |
| 1299 | aic3x->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK; |
| 1300 | |
| 1301 | /* set iface */ |
| 1302 | snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLA, iface_areg); |
| 1303 | snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLB, iface_breg); |
| 1304 | |
| 1305 | return 0; |
| 1306 | } |
| 1307 | |
| 1308 | static int aic3x_set_dai_tdm_slot(struct snd_soc_dai *codec_dai, |
| 1309 | unsigned int tx_mask, unsigned int rx_mask, |
| 1310 | int slots, int slot_width) |
| 1311 | { |
| 1312 | struct snd_soc_component *component = codec_dai->component; |
| 1313 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1314 | unsigned int lsb; |
| 1315 | |
| 1316 | if (tx_mask != rx_mask) { |
| 1317 | dev_err(component->dev, "tx and rx masks must be symmetric\n"); |
| 1318 | return -EINVAL; |
| 1319 | } |
| 1320 | |
| 1321 | if (unlikely(!tx_mask)) { |
| 1322 | dev_err(component->dev, "tx and rx masks need to be non 0\n"); |
| 1323 | return -EINVAL; |
| 1324 | } |
| 1325 | |
| 1326 | /* TDM based on DSP mode requires slots to be adjacent */ |
| 1327 | lsb = __ffs(tx_mask); |
| 1328 | if ((lsb + 1) != __fls(tx_mask)) { |
| 1329 | dev_err(component->dev, "Invalid mask, slots must be adjacent\n"); |
| 1330 | return -EINVAL; |
| 1331 | } |
| 1332 | |
| 1333 | switch (slot_width) { |
| 1334 | case 16: |
| 1335 | case 20: |
| 1336 | case 24: |
| 1337 | case 32: |
| 1338 | break; |
| 1339 | default: |
| 1340 | dev_err(component->dev, "Unsupported slot width %d\n", slot_width); |
| 1341 | return -EINVAL; |
| 1342 | } |
| 1343 | |
| 1344 | |
| 1345 | aic3x->tdm_delay = lsb; |
| 1346 | aic3x->slot_width = slot_width; |
| 1347 | |
| 1348 | /* DOUT in high-impedance on inactive bit clocks */ |
| 1349 | snd_soc_component_update_bits(component, AIC3X_ASD_INTF_CTRLA, |
| 1350 | DOUT_TRISTATE, DOUT_TRISTATE); |
| 1351 | |
| 1352 | return 0; |
| 1353 | } |
| 1354 | |
| 1355 | static int aic3x_regulator_event(struct notifier_block *nb, |
| 1356 | unsigned long event, void *data) |
| 1357 | { |
| 1358 | struct aic3x_disable_nb *disable_nb = |
| 1359 | container_of(nb, struct aic3x_disable_nb, nb); |
| 1360 | struct aic3x_priv *aic3x = disable_nb->aic3x; |
| 1361 | |
| 1362 | if (event & REGULATOR_EVENT_DISABLE) { |
| 1363 | /* |
| 1364 | * Put codec to reset and require cache sync as at least one |
| 1365 | * of the supplies was disabled |
| 1366 | */ |
| 1367 | if (gpio_is_valid(aic3x->gpio_reset)) |
| 1368 | gpio_set_value(aic3x->gpio_reset, 0); |
| 1369 | regcache_mark_dirty(aic3x->regmap); |
| 1370 | } |
| 1371 | |
| 1372 | return 0; |
| 1373 | } |
| 1374 | |
| 1375 | static int aic3x_set_power(struct snd_soc_component *component, int power) |
| 1376 | { |
| 1377 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1378 | unsigned int pll_c, pll_d; |
| 1379 | int ret; |
| 1380 | |
| 1381 | if (power) { |
| 1382 | ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies), |
| 1383 | aic3x->supplies); |
| 1384 | if (ret) |
| 1385 | goto out; |
| 1386 | aic3x->power = 1; |
| 1387 | |
| 1388 | if (gpio_is_valid(aic3x->gpio_reset)) { |
| 1389 | udelay(1); |
| 1390 | gpio_set_value(aic3x->gpio_reset, 1); |
| 1391 | } |
| 1392 | |
| 1393 | /* Sync reg_cache with the hardware */ |
| 1394 | regcache_cache_only(aic3x->regmap, false); |
| 1395 | regcache_sync(aic3x->regmap); |
| 1396 | |
| 1397 | /* Rewrite paired PLL D registers in case cached sync skipped |
| 1398 | * writing one of them and thus caused other one also not |
| 1399 | * being written |
| 1400 | */ |
| 1401 | pll_c = snd_soc_component_read32(component, AIC3X_PLL_PROGC_REG); |
| 1402 | pll_d = snd_soc_component_read32(component, AIC3X_PLL_PROGD_REG); |
| 1403 | if (pll_c == aic3x_reg[AIC3X_PLL_PROGC_REG].def || |
| 1404 | pll_d == aic3x_reg[AIC3X_PLL_PROGD_REG].def) { |
| 1405 | snd_soc_component_write(component, AIC3X_PLL_PROGC_REG, pll_c); |
| 1406 | snd_soc_component_write(component, AIC3X_PLL_PROGD_REG, pll_d); |
| 1407 | } |
| 1408 | |
| 1409 | /* |
| 1410 | * Delay is needed to reduce pop-noise after syncing back the |
| 1411 | * registers |
| 1412 | */ |
| 1413 | mdelay(50); |
| 1414 | } else { |
| 1415 | /* |
| 1416 | * Do soft reset to this codec instance in order to clear |
| 1417 | * possible VDD leakage currents in case the supply regulators |
| 1418 | * remain on |
| 1419 | */ |
| 1420 | snd_soc_component_write(component, AIC3X_RESET, SOFT_RESET); |
| 1421 | regcache_mark_dirty(aic3x->regmap); |
| 1422 | aic3x->power = 0; |
| 1423 | /* HW writes are needless when bias is off */ |
| 1424 | regcache_cache_only(aic3x->regmap, true); |
| 1425 | ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies), |
| 1426 | aic3x->supplies); |
| 1427 | } |
| 1428 | out: |
| 1429 | return ret; |
| 1430 | } |
| 1431 | |
| 1432 | static int aic3x_set_bias_level(struct snd_soc_component *component, |
| 1433 | enum snd_soc_bias_level level) |
| 1434 | { |
| 1435 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1436 | |
| 1437 | switch (level) { |
| 1438 | case SND_SOC_BIAS_ON: |
| 1439 | break; |
| 1440 | case SND_SOC_BIAS_PREPARE: |
| 1441 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY && |
| 1442 | aic3x->master) { |
| 1443 | /* enable pll */ |
| 1444 | snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, |
| 1445 | PLL_ENABLE, PLL_ENABLE); |
| 1446 | } |
| 1447 | break; |
| 1448 | case SND_SOC_BIAS_STANDBY: |
| 1449 | if (!aic3x->power) |
| 1450 | aic3x_set_power(component, 1); |
| 1451 | if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE && |
| 1452 | aic3x->master) { |
| 1453 | /* disable pll */ |
| 1454 | snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, |
| 1455 | PLL_ENABLE, 0); |
| 1456 | } |
| 1457 | break; |
| 1458 | case SND_SOC_BIAS_OFF: |
| 1459 | if (aic3x->power) |
| 1460 | aic3x_set_power(component, 0); |
| 1461 | break; |
| 1462 | } |
| 1463 | |
| 1464 | return 0; |
| 1465 | } |
| 1466 | |
| 1467 | #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000 |
| 1468 | #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \ |
| 1469 | SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE | \ |
| 1470 | SNDRV_PCM_FMTBIT_S32_LE) |
| 1471 | |
| 1472 | static const struct snd_soc_dai_ops aic3x_dai_ops = { |
| 1473 | .hw_params = aic3x_hw_params, |
| 1474 | .prepare = aic3x_prepare, |
| 1475 | .digital_mute = aic3x_mute, |
| 1476 | .set_sysclk = aic3x_set_dai_sysclk, |
| 1477 | .set_fmt = aic3x_set_dai_fmt, |
| 1478 | .set_tdm_slot = aic3x_set_dai_tdm_slot, |
| 1479 | }; |
| 1480 | |
| 1481 | static struct snd_soc_dai_driver aic3x_dai = { |
| 1482 | .name = "tlv320aic3x-hifi", |
| 1483 | .playback = { |
| 1484 | .stream_name = "Playback", |
| 1485 | .channels_min = 2, |
| 1486 | .channels_max = 2, |
| 1487 | .rates = AIC3X_RATES, |
| 1488 | .formats = AIC3X_FORMATS,}, |
| 1489 | .capture = { |
| 1490 | .stream_name = "Capture", |
| 1491 | .channels_min = 2, |
| 1492 | .channels_max = 2, |
| 1493 | .rates = AIC3X_RATES, |
| 1494 | .formats = AIC3X_FORMATS,}, |
| 1495 | .ops = &aic3x_dai_ops, |
| 1496 | .symmetric_rates = 1, |
| 1497 | }; |
| 1498 | |
| 1499 | static void aic3x_mono_init(struct snd_soc_component *component) |
| 1500 | { |
| 1501 | /* DAC to Mono Line Out default volume and route to Output mixer */ |
| 1502 | snd_soc_component_write(component, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1503 | snd_soc_component_write(component, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1504 | |
| 1505 | /* unmute all outputs */ |
| 1506 | snd_soc_component_update_bits(component, MONOLOPM_CTRL, UNMUTE, UNMUTE); |
| 1507 | |
| 1508 | /* PGA to Mono Line Out default volume, disconnect from Output Mixer */ |
| 1509 | snd_soc_component_write(component, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1510 | snd_soc_component_write(component, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1511 | |
| 1512 | /* Line2 to Mono Out default volume, disconnect from Output Mixer */ |
| 1513 | snd_soc_component_write(component, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1514 | snd_soc_component_write(component, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL); |
| 1515 | } |
| 1516 | |
| 1517 | /* |
| 1518 | * initialise the AIC3X driver |
| 1519 | * register the mixer and dsp interfaces with the kernel |
| 1520 | */ |
| 1521 | static int aic3x_init(struct snd_soc_component *component) |
| 1522 | { |
| 1523 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1524 | |
| 1525 | snd_soc_component_write(component, AIC3X_PAGE_SELECT, PAGE0_SELECT); |
| 1526 | snd_soc_component_write(component, AIC3X_RESET, SOFT_RESET); |
| 1527 | |
| 1528 | /* DAC default volume and mute */ |
| 1529 | snd_soc_component_write(component, LDAC_VOL, DEFAULT_VOL | MUTE_ON); |
| 1530 | snd_soc_component_write(component, RDAC_VOL, DEFAULT_VOL | MUTE_ON); |
| 1531 | |
| 1532 | /* DAC to HP default volume and route to Output mixer */ |
| 1533 | snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1534 | snd_soc_component_write(component, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1535 | snd_soc_component_write(component, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1536 | snd_soc_component_write(component, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1537 | /* DAC to Line Out default volume and route to Output mixer */ |
| 1538 | snd_soc_component_write(component, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1539 | snd_soc_component_write(component, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON); |
| 1540 | |
| 1541 | /* unmute all outputs */ |
| 1542 | snd_soc_component_update_bits(component, LLOPM_CTRL, UNMUTE, UNMUTE); |
| 1543 | snd_soc_component_update_bits(component, RLOPM_CTRL, UNMUTE, UNMUTE); |
| 1544 | snd_soc_component_update_bits(component, HPLOUT_CTRL, UNMUTE, UNMUTE); |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 1545 | //d_soc_component_update_bits(component, HPROUT_CTRL, UNMUTE, UNMUTE); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1546 | snd_soc_component_update_bits(component, HPLCOM_CTRL, UNMUTE, UNMUTE); |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 1547 | //d_soc_component_update_bits(component, HPRCOM_CTRL, UNMUTE, UNMUTE); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1548 | |
| 1549 | /* ADC default volume and unmute */ |
| 1550 | snd_soc_component_write(component, LADC_VOL, DEFAULT_GAIN); |
| 1551 | snd_soc_component_write(component, RADC_VOL, DEFAULT_GAIN); |
| 1552 | /* By default route Line1 to ADC PGA mixer */ |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 1553 | snd_soc_component_write(component, LINE2L_2_LADC_CTRL, 0x0); |
| 1554 | snd_soc_component_write(component, LINE2R_2_RADC_CTRL, 0x0); |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1555 | |
| 1556 | /* PGA to HP Bypass default volume, disconnect from Output Mixer */ |
| 1557 | snd_soc_component_write(component, PGAL_2_HPLOUT_VOL, DEFAULT_VOL); |
| 1558 | snd_soc_component_write(component, PGAR_2_HPROUT_VOL, DEFAULT_VOL); |
| 1559 | snd_soc_component_write(component, PGAL_2_HPLCOM_VOL, DEFAULT_VOL); |
| 1560 | snd_soc_component_write(component, PGAR_2_HPRCOM_VOL, DEFAULT_VOL); |
| 1561 | /* PGA to Line Out default volume, disconnect from Output Mixer */ |
| 1562 | snd_soc_component_write(component, PGAL_2_LLOPM_VOL, DEFAULT_VOL); |
| 1563 | snd_soc_component_write(component, PGAR_2_RLOPM_VOL, DEFAULT_VOL); |
| 1564 | |
| 1565 | /* On tlv320aic3104, these registers are reserved and must not be written */ |
| 1566 | if (aic3x->model != AIC3X_MODEL_3104) { |
| 1567 | /* Line2 to HP Bypass default volume, disconnect from Output Mixer */ |
| 1568 | snd_soc_component_write(component, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL); |
| 1569 | snd_soc_component_write(component, LINE2R_2_HPROUT_VOL, DEFAULT_VOL); |
| 1570 | snd_soc_component_write(component, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL); |
| 1571 | snd_soc_component_write(component, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL); |
| 1572 | /* Line2 Line Out default volume, disconnect from Output Mixer */ |
| 1573 | snd_soc_component_write(component, LINE2L_2_LLOPM_VOL, DEFAULT_VOL); |
| 1574 | snd_soc_component_write(component, LINE2R_2_RLOPM_VOL, DEFAULT_VOL); |
| 1575 | } |
| 1576 | |
| 1577 | switch (aic3x->model) { |
| 1578 | case AIC3X_MODEL_3X: |
| 1579 | case AIC3X_MODEL_33: |
| 1580 | aic3x_mono_init(component); |
| 1581 | break; |
| 1582 | case AIC3X_MODEL_3007: |
| 1583 | snd_soc_component_write(component, CLASSD_CTRL, 0); |
| 1584 | break; |
| 1585 | } |
| 1586 | |
| 1587 | /* Output common-mode voltage = 1.5 V */ |
| 1588 | snd_soc_component_update_bits(component, HPOUT_SC, HPOUT_SC_OCMV_MASK, |
| 1589 | aic3x->ocmv << HPOUT_SC_OCMV_SHIFT); |
| 1590 | |
| 1591 | return 0; |
| 1592 | } |
| 1593 | |
| 1594 | static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x) |
| 1595 | { |
| 1596 | struct aic3x_priv *a; |
| 1597 | |
| 1598 | list_for_each_entry(a, &reset_list, list) { |
| 1599 | if (gpio_is_valid(aic3x->gpio_reset) && |
| 1600 | aic3x->gpio_reset == a->gpio_reset) |
| 1601 | return true; |
| 1602 | } |
| 1603 | |
| 1604 | return false; |
| 1605 | } |
| 1606 | |
| 1607 | static int aic3x_probe(struct snd_soc_component *component) |
| 1608 | { |
| 1609 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1610 | int ret, i; |
| 1611 | |
| 1612 | aic3x->component = component; |
| 1613 | |
| 1614 | for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) { |
| 1615 | aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event; |
| 1616 | aic3x->disable_nb[i].aic3x = aic3x; |
| 1617 | ret = regulator_register_notifier(aic3x->supplies[i].consumer, |
| 1618 | &aic3x->disable_nb[i].nb); |
| 1619 | if (ret) { |
| 1620 | dev_err(component->dev, |
| 1621 | "Failed to request regulator notifier: %d\n", |
| 1622 | ret); |
| 1623 | goto err_notif; |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | regcache_mark_dirty(aic3x->regmap); |
| 1628 | aic3x_init(component); |
| 1629 | |
| 1630 | if (aic3x->setup) { |
| 1631 | if (aic3x->model != AIC3X_MODEL_3104) { |
| 1632 | /* setup GPIO functions */ |
| 1633 | snd_soc_component_write(component, AIC3X_GPIO1_REG, |
| 1634 | (aic3x->setup->gpio_func[0] & 0xf) << 4); |
| 1635 | snd_soc_component_write(component, AIC3X_GPIO2_REG, |
| 1636 | (aic3x->setup->gpio_func[1] & 0xf) << 4); |
| 1637 | } else { |
| 1638 | dev_warn(component->dev, "GPIO functionality is not supported on tlv320aic3104\n"); |
| 1639 | } |
| 1640 | } |
| 1641 | |
| 1642 | switch (aic3x->model) { |
| 1643 | case AIC3X_MODEL_3X: |
| 1644 | case AIC3X_MODEL_33: |
| 1645 | snd_soc_add_component_controls(component, aic3x_extra_snd_controls, |
| 1646 | ARRAY_SIZE(aic3x_extra_snd_controls)); |
| 1647 | snd_soc_add_component_controls(component, aic3x_mono_controls, |
| 1648 | ARRAY_SIZE(aic3x_mono_controls)); |
| 1649 | break; |
| 1650 | case AIC3X_MODEL_3007: |
| 1651 | snd_soc_add_component_controls(component, aic3x_extra_snd_controls, |
| 1652 | ARRAY_SIZE(aic3x_extra_snd_controls)); |
| 1653 | snd_soc_add_component_controls(component, |
| 1654 | &aic3x_classd_amp_gain_ctrl, 1); |
| 1655 | break; |
| 1656 | case AIC3X_MODEL_3104: |
| 1657 | break; |
| 1658 | } |
| 1659 | |
| 1660 | /* set mic bias voltage */ |
| 1661 | switch (aic3x->micbias_vg) { |
| 1662 | case AIC3X_MICBIAS_2_0V: |
| 1663 | case AIC3X_MICBIAS_2_5V: |
| 1664 | case AIC3X_MICBIAS_AVDDV: |
| 1665 | snd_soc_component_update_bits(component, MICBIAS_CTRL, |
| 1666 | MICBIAS_LEVEL_MASK, |
| 1667 | (aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT); |
| 1668 | break; |
| 1669 | case AIC3X_MICBIAS_OFF: |
| 1670 | /* |
| 1671 | * noting to do. target won't enter here. This is just to avoid |
| 1672 | * compile time warning "warning: enumeration value |
| 1673 | * 'AIC3X_MICBIAS_OFF' not handled in switch" |
| 1674 | */ |
| 1675 | break; |
| 1676 | } |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 1677 | |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1678 | |
| 1679 | aic3x_add_widgets(component); |
| 1680 | |
| 1681 | return 0; |
| 1682 | |
| 1683 | err_notif: |
| 1684 | while (i--) |
| 1685 | regulator_unregister_notifier(aic3x->supplies[i].consumer, |
| 1686 | &aic3x->disable_nb[i].nb); |
| 1687 | return ret; |
| 1688 | } |
| 1689 | |
| 1690 | static void aic3x_remove(struct snd_soc_component *component) |
| 1691 | { |
| 1692 | struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); |
| 1693 | int i; |
| 1694 | |
| 1695 | for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) |
| 1696 | regulator_unregister_notifier(aic3x->supplies[i].consumer, |
| 1697 | &aic3x->disable_nb[i].nb); |
| 1698 | } |
| 1699 | |
| 1700 | static const struct snd_soc_component_driver soc_component_dev_aic3x = { |
| 1701 | .set_bias_level = aic3x_set_bias_level, |
| 1702 | .probe = aic3x_probe, |
| 1703 | .remove = aic3x_remove, |
| 1704 | .controls = aic3x_snd_controls, |
| 1705 | .num_controls = ARRAY_SIZE(aic3x_snd_controls), |
| 1706 | .dapm_widgets = aic3x_dapm_widgets, |
| 1707 | .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets), |
| 1708 | .dapm_routes = intercon, |
| 1709 | .num_dapm_routes = ARRAY_SIZE(intercon), |
| 1710 | .use_pmdown_time = 1, |
| 1711 | .endianness = 1, |
| 1712 | .non_legacy_dai_naming = 1, |
| 1713 | }; |
| 1714 | |
| 1715 | static void aic3x_configure_ocmv(struct i2c_client *client) |
| 1716 | { |
| 1717 | struct device_node *np = client->dev.of_node; |
| 1718 | struct aic3x_priv *aic3x = i2c_get_clientdata(client); |
| 1719 | u32 value; |
| 1720 | int dvdd, avdd; |
| 1721 | |
| 1722 | if (np && !of_property_read_u32(np, "ai3x-ocmv", &value)) { |
| 1723 | /* OCMV setting is forced by DT */ |
| 1724 | if (value <= 3) { |
| 1725 | aic3x->ocmv = value; |
| 1726 | return; |
| 1727 | } |
| 1728 | } |
| 1729 | |
| 1730 | dvdd = regulator_get_voltage(aic3x->supplies[1].consumer); |
| 1731 | avdd = regulator_get_voltage(aic3x->supplies[2].consumer); |
| 1732 | |
| 1733 | if (avdd > 3600000 || dvdd > 1950000) { |
| 1734 | dev_warn(&client->dev, |
| 1735 | "Too high supply voltage(s) AVDD: %d, DVDD: %d\n", |
| 1736 | avdd, dvdd); |
| 1737 | } else if (avdd == 3600000 && dvdd == 1950000) { |
| 1738 | aic3x->ocmv = HPOUT_SC_OCMV_1_8V; |
| 1739 | } else if (avdd > 3300000 && dvdd > 1800000) { |
| 1740 | aic3x->ocmv = HPOUT_SC_OCMV_1_65V; |
| 1741 | } else if (avdd > 3000000 && dvdd > 1650000) { |
| 1742 | aic3x->ocmv = HPOUT_SC_OCMV_1_5V; |
| 1743 | } else if (avdd >= 2700000 && dvdd >= 1525000) { |
| 1744 | aic3x->ocmv = HPOUT_SC_OCMV_1_35V; |
| 1745 | } else { |
| 1746 | dev_warn(&client->dev, |
| 1747 | "Invalid supply voltage(s) AVDD: %d, DVDD: %d\n", |
| 1748 | avdd, dvdd); |
| 1749 | } |
| 1750 | } |
| 1751 | |
| 1752 | /* |
| 1753 | * AIC3X 2 wire address can be up to 4 devices with device addresses |
| 1754 | * 0x18, 0x19, 0x1A, 0x1B |
| 1755 | */ |
| 1756 | |
| 1757 | static const struct i2c_device_id aic3x_i2c_id[] = { |
| 1758 | { "tlv320aic3x", AIC3X_MODEL_3X }, |
| 1759 | { "tlv320aic33", AIC3X_MODEL_33 }, |
| 1760 | { "tlv320aic3007", AIC3X_MODEL_3007 }, |
| 1761 | { "tlv320aic3106", AIC3X_MODEL_3X }, |
| 1762 | { "tlv320aic3104", AIC3X_MODEL_3104 }, |
| 1763 | { } |
| 1764 | }; |
| 1765 | MODULE_DEVICE_TABLE(i2c, aic3x_i2c_id); |
| 1766 | |
| 1767 | static const struct reg_sequence aic3007_class_d[] = { |
| 1768 | /* Class-D speaker driver init; datasheet p. 46 */ |
| 1769 | { AIC3X_PAGE_SELECT, 0x0D }, |
| 1770 | { 0xD, 0x0D }, |
| 1771 | { 0x8, 0x5C }, |
| 1772 | { 0x8, 0x5D }, |
| 1773 | { 0x8, 0x5C }, |
| 1774 | { AIC3X_PAGE_SELECT, 0x00 }, |
| 1775 | }; |
| 1776 | |
| 1777 | //tianyan@2021.8.2 modify for compatible codec tlv320aic3104 and add loopback test start |
| 1778 | |
| 1779 | static struct regmap *tlv320aic3104_regmap = NULL; |
| 1780 | |
| 1781 | |
| 1782 | static void aic3x_set_aic3x_config(struct regmap *regmap) |
| 1783 | { |
| 1784 | tlv320aic3104_regmap = regmap; |
| 1785 | } |
| 1786 | |
| 1787 | /* |
| 1788 | *Get tlv320aic3104 config status |
| 1789 | *@return,null is not configed |
| 1790 | */ |
| 1791 | struct regmap * aic3x_get_aic3x_config(void) |
| 1792 | { |
| 1793 | return tlv320aic3104_regmap; |
| 1794 | } |
| 1795 | |
| 1796 | void tlv320aic3104_loopback_test(void) |
| 1797 | { |
| 1798 | regmap_write(tlv320aic3104_regmap,LADC_VOL, 0x3c); |
| 1799 | regmap_write(tlv320aic3104_regmap,RADC_VOL, 0x3c); |
| 1800 | regmap_write(tlv320aic3104_regmap,LINE1L_2_LADC_CTRL, 0x4); |
| 1801 | regmap_write(tlv320aic3104_regmap,LINE1R_2_RADC_CTRL, 0x4); |
| 1802 | regmap_write(tlv320aic3104_regmap,DAC_PWR, 0xc0); |
| 1803 | regmap_write(tlv320aic3104_regmap,LDAC_VOL, 0); |
| 1804 | regmap_write(tlv320aic3104_regmap,RDAC_VOL, 0); |
| 1805 | regmap_write(tlv320aic3104_regmap,DACL1_2_HPLOUT_VOL, 0xb0); |
| 1806 | regmap_write(tlv320aic3104_regmap,DACR1_2_HPROUT_VOL, 0xb0); |
| 1807 | regmap_write(tlv320aic3104_regmap,HPLOUT_CTRL, 0xd); |
| 1808 | regmap_write(tlv320aic3104_regmap,HPLCOM_CTRL, 0xd); |
| 1809 | regmap_write(tlv320aic3104_regmap,HPROUT_CTRL, 0xd); |
| 1810 | regmap_write(tlv320aic3104_regmap,HPRCOM_CTRL, 0xd); |
| 1811 | regmap_write(tlv320aic3104_regmap,LLOPM_CTRL, 0x09); |
| 1812 | regmap_write(tlv320aic3104_regmap,RLOPM_CTRL, 0x09); |
| 1813 | regmap_write(tlv320aic3104_regmap,MICBIAS_CTRL, 0x80); |
| 1814 | regmap_write(tlv320aic3104_regmap,PGAL_2_HPLOUT_VOL, 0x80); |
| 1815 | } |
| 1816 | //tianyan@2021.8.2 modify for compatible codec tlv320aic3104 and add loopback test end |
| 1817 | |
| 1818 | |
| 1819 | /* |
| 1820 | * If the i2c layer weren't so broken, we could pass this kind of data |
| 1821 | * around |
| 1822 | */ |
| 1823 | static int aic3x_i2c_probe(struct i2c_client *i2c, |
| 1824 | const struct i2c_device_id *id) |
| 1825 | { |
| 1826 | struct aic3x_pdata *pdata = i2c->dev.platform_data; |
| 1827 | struct aic3x_priv *aic3x; |
| 1828 | struct aic3x_setup_data *ai3x_setup; |
| 1829 | struct device_node *np = i2c->dev.of_node; |
| 1830 | int ret, i; |
| 1831 | u32 value; |
| 1832 | |
| 1833 | aic3x = devm_kzalloc(&i2c->dev, sizeof(struct aic3x_priv), GFP_KERNEL); |
| 1834 | if (!aic3x) |
| 1835 | return -ENOMEM; |
| 1836 | |
| 1837 | aic3x->regmap = devm_regmap_init_i2c(i2c, &aic3x_regmap); |
| 1838 | if (IS_ERR(aic3x->regmap)) { |
| 1839 | ret = PTR_ERR(aic3x->regmap); |
| 1840 | return ret; |
| 1841 | } |
| 1842 | |
| 1843 | regcache_cache_only(aic3x->regmap, true); |
| 1844 | |
| 1845 | i2c_set_clientdata(i2c, aic3x); |
| 1846 | if (pdata) { |
| 1847 | aic3x->gpio_reset = pdata->gpio_reset; |
| 1848 | aic3x->setup = pdata->setup; |
| 1849 | aic3x->micbias_vg = pdata->micbias_vg; |
| 1850 | } else if (np) { |
| 1851 | ai3x_setup = devm_kzalloc(&i2c->dev, sizeof(*ai3x_setup), |
| 1852 | GFP_KERNEL); |
| 1853 | if (!ai3x_setup) |
| 1854 | return -ENOMEM; |
| c.chen | 0f2a79e | 2022-04-07 23:50:42 -0700 | [diff] [blame] | 1855 | /*modify by chencheng 2022/3/22 start*/ |
| 1856 | ret = of_get_named_gpio(np, "gpio-power", 0); |
| 1857 | printk("ret power gpio = %d\n",ret); |
| 1858 | if(ret>0){ |
| 1859 | aic3x->power = ret; |
| 1860 | gpio_direction_output(aic3x->power, 1); |
| 1861 | mdelay(100); |
| 1862 | } |
| 1863 | /*modify by chencheng 2022/3/22 end*/ |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1864 | |
| 1865 | ret = of_get_named_gpio(np, "reset-gpios", 0); |
| 1866 | if (ret >= 0) { |
| 1867 | aic3x->gpio_reset = ret; |
| 1868 | } else { |
| 1869 | ret = of_get_named_gpio(np, "gpio-reset", 0); |
| 1870 | if (ret > 0) { |
| 1871 | dev_warn(&i2c->dev, "Using deprecated property \"gpio-reset\", please update your DT"); |
| 1872 | aic3x->gpio_reset = ret; |
| 1873 | } else { |
| 1874 | aic3x->gpio_reset = -1; |
| 1875 | } |
| 1876 | } |
| 1877 | |
| 1878 | if (of_property_read_u32_array(np, "ai3x-gpio-func", |
| 1879 | ai3x_setup->gpio_func, 2) >= 0) { |
| 1880 | aic3x->setup = ai3x_setup; |
| 1881 | } |
| 1882 | |
| 1883 | if (!of_property_read_u32(np, "ai3x-micbias-vg", &value)) { |
| 1884 | switch (value) { |
| 1885 | case 1 : |
| 1886 | aic3x->micbias_vg = AIC3X_MICBIAS_2_0V; |
| 1887 | break; |
| 1888 | case 2 : |
| 1889 | aic3x->micbias_vg = AIC3X_MICBIAS_2_5V; |
| 1890 | break; |
| 1891 | case 3 : |
| 1892 | aic3x->micbias_vg = AIC3X_MICBIAS_AVDDV; |
| 1893 | break; |
| 1894 | default : |
| 1895 | aic3x->micbias_vg = AIC3X_MICBIAS_OFF; |
| 1896 | dev_err(&i2c->dev, "Unsuitable MicBias voltage " |
| 1897 | "found in DT\n"); |
| 1898 | } |
| 1899 | } else { |
| 1900 | aic3x->micbias_vg = AIC3X_MICBIAS_OFF; |
| 1901 | } |
| 1902 | |
| 1903 | } else { |
| 1904 | aic3x->gpio_reset = -1; |
| 1905 | } |
| 1906 | |
| 1907 | aic3x->model = id->driver_data; |
| 1908 | |
| 1909 | if (gpio_is_valid(aic3x->gpio_reset) && |
| 1910 | !aic3x_is_shared_reset(aic3x)) { |
| 1911 | ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset"); |
| 1912 | if (ret != 0) |
| 1913 | goto err; |
| 1914 | gpio_direction_output(aic3x->gpio_reset, 0); |
| 1915 | } |
| 1916 | |
| 1917 | //tianyan@2021.9.30 modify for optimize the audio start |
| 1918 | gpio_direction_output(aic3x->gpio_reset, 1); |
| 1919 | regcache_cache_only(aic3x->regmap, false); |
| 1920 | if((ret = regmap_write(aic3x->regmap,1,0x0))) |
| 1921 | { |
| 1922 | printk("Not find tlv320aic3104 codec!\n"); |
| xj | 112b967 | 2022-01-25 16:13:48 +0800 | [diff] [blame] | 1923 | goto err_gpio; |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1924 | } |
| 1925 | printk("Find tlv320aic3104 codec!\n"); |
| 1926 | regcache_cache_only(aic3x->regmap, true); |
| 1927 | gpio_direction_output(aic3x->gpio_reset, 0); |
| 1928 | //tianyan@2021.9.30 modify for optimize the audio end |
| 1929 | |
| 1930 | for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) |
| 1931 | aic3x->supplies[i].supply = aic3x_supply_names[i]; |
| 1932 | |
| 1933 | ret = devm_regulator_bulk_get(&i2c->dev, ARRAY_SIZE(aic3x->supplies), |
| 1934 | aic3x->supplies); |
| 1935 | if (ret != 0) { |
| 1936 | dev_err(&i2c->dev, "Failed to request supplies: %d\n", ret); |
| 1937 | goto err_gpio; |
| 1938 | } |
| 1939 | |
| 1940 | aic3x_configure_ocmv(i2c); |
| 1941 | |
| 1942 | if (aic3x->model == AIC3X_MODEL_3007) { |
| 1943 | ret = regmap_register_patch(aic3x->regmap, aic3007_class_d, |
| 1944 | ARRAY_SIZE(aic3007_class_d)); |
| 1945 | if (ret != 0) |
| 1946 | dev_err(&i2c->dev, "Failed to init class D: %d\n", |
| 1947 | ret); |
| 1948 | } |
| 1949 | |
| 1950 | //tianyan@2021.8.2 modify for compatible codec tlv320aic3104 and add loopback test start |
| 1951 | aic3x_set_aic3x_config(aic3x->regmap); |
| 1952 | //tianyan@2021.8.2 modify for compatible codec tlv320aic3104 and add loopback test end |
| 1953 | |
| 1954 | ret = devm_snd_soc_register_component(&i2c->dev, |
| 1955 | &soc_component_dev_aic3x, &aic3x_dai, 1); |
| 1956 | |
| 1957 | if (ret != 0) |
| 1958 | goto err_gpio; |
| 1959 | |
| 1960 | INIT_LIST_HEAD(&aic3x->list); |
| 1961 | list_add(&aic3x->list, &reset_list); |
| 1962 | |
| yu.dong | bff8773 | 2022-08-19 02:29:53 -0700 | [diff] [blame] | 1963 | //dongyu@2022.8.19 add codec boot without initialization start |
| 1964 | gpio_direction_output(aic3x->power, 0); |
| 1965 | gpio_direction_output(aic3x->gpio_reset, 0); |
| 1966 | //dongyu@2022.8.19 add codec boot without initialization end |
| xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1967 | return 0; |
| 1968 | |
| 1969 | err_gpio: |
| 1970 | if (gpio_is_valid(aic3x->gpio_reset) && |
| 1971 | !aic3x_is_shared_reset(aic3x)) |
| 1972 | gpio_free(aic3x->gpio_reset); |
| 1973 | err: |
| 1974 | return ret; |
| 1975 | } |
| 1976 | |
| 1977 | static int aic3x_i2c_remove(struct i2c_client *client) |
| 1978 | { |
| 1979 | struct aic3x_priv *aic3x = i2c_get_clientdata(client); |
| 1980 | |
| 1981 | list_del(&aic3x->list); |
| 1982 | |
| 1983 | if (gpio_is_valid(aic3x->gpio_reset) && |
| 1984 | !aic3x_is_shared_reset(aic3x)) { |
| 1985 | gpio_set_value(aic3x->gpio_reset, 0); |
| 1986 | gpio_free(aic3x->gpio_reset); |
| 1987 | } |
| 1988 | return 0; |
| 1989 | } |
| 1990 | |
| 1991 | #if defined(CONFIG_OF) |
| 1992 | static const struct of_device_id tlv320aic3x_of_match[] = { |
| 1993 | { .compatible = "ti,tlv320aic3x", }, |
| 1994 | { .compatible = "ti,tlv320aic33" }, |
| 1995 | { .compatible = "ti,tlv320aic3007" }, |
| 1996 | { .compatible = "ti,tlv320aic3106" }, |
| 1997 | { .compatible = "ti,tlv320aic3104" }, |
| 1998 | {}, |
| 1999 | }; |
| 2000 | MODULE_DEVICE_TABLE(of, tlv320aic3x_of_match); |
| 2001 | #endif |
| 2002 | |
| 2003 | /* machine i2c codec control layer */ |
| 2004 | static struct i2c_driver aic3x_i2c_driver = { |
| 2005 | .driver = { |
| 2006 | .name = "tlv320aic3x-codec", |
| 2007 | .of_match_table = of_match_ptr(tlv320aic3x_of_match), |
| 2008 | }, |
| 2009 | .probe = aic3x_i2c_probe, |
| 2010 | .remove = aic3x_i2c_remove, |
| 2011 | .id_table = aic3x_i2c_id, |
| 2012 | }; |
| 2013 | |
| 2014 | module_i2c_driver(aic3x_i2c_driver); |
| 2015 | |
| 2016 | MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver"); |
| 2017 | MODULE_AUTHOR("Vladimir Barinov"); |
| 2018 | MODULE_LICENSE("GPL"); |