0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #include <linux/module.h>
0032 #include <linux/moduleparam.h>
0033 #include <linux/init.h>
0034 #include <linux/delay.h>
0035 #include <linux/pm.h>
0036 #include <linux/i2c.h>
0037 #include <linux/gpio.h>
0038 #include <linux/regulator/consumer.h>
0039 #include <linux/of.h>
0040 #include <linux/of_gpio.h>
0041 #include <linux/slab.h>
0042 #include <sound/core.h>
0043 #include <sound/pcm.h>
0044 #include <sound/pcm_params.h>
0045 #include <sound/soc.h>
0046 #include <sound/initval.h>
0047 #include <sound/tlv.h>
0048 #include <sound/tlv320aic3x.h>
0049
0050 #include "tlv320aic3x.h"
0051
0052 #define AIC3X_NUM_SUPPLIES 4
0053 static const char *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = {
0054 "IOVDD",
0055 "DVDD",
0056 "AVDD",
0057 "DRVDD",
0058 };
0059
0060 static LIST_HEAD(reset_list);
0061
0062 struct aic3x_priv;
0063
0064 struct aic3x_disable_nb {
0065 struct notifier_block nb;
0066 struct aic3x_priv *aic3x;
0067 };
0068
0069
0070 struct aic3x_priv {
0071 struct snd_soc_component *component;
0072 struct regmap *regmap;
0073 struct regulator_bulk_data supplies[AIC3X_NUM_SUPPLIES];
0074 struct aic3x_disable_nb disable_nb[AIC3X_NUM_SUPPLIES];
0075 struct aic3x_setup_data *setup;
0076 unsigned int sysclk;
0077 unsigned int dai_fmt;
0078 unsigned int tdm_delay;
0079 unsigned int slot_width;
0080 struct list_head list;
0081 int master;
0082 int gpio_reset;
0083 int power;
0084 u16 model;
0085
0086
0087 enum aic3x_micbias_voltage micbias_vg;
0088
0089 u8 ocmv;
0090 };
0091
0092 static const struct reg_default aic3x_reg[] = {
0093 { 0, 0x00 }, { 1, 0x00 }, { 2, 0x00 }, { 3, 0x10 },
0094 { 4, 0x04 }, { 5, 0x00 }, { 6, 0x00 }, { 7, 0x00 },
0095 { 8, 0x00 }, { 9, 0x00 }, { 10, 0x00 }, { 11, 0x01 },
0096 { 12, 0x00 }, { 13, 0x00 }, { 14, 0x00 }, { 15, 0x80 },
0097 { 16, 0x80 }, { 17, 0xff }, { 18, 0xff }, { 19, 0x78 },
0098 { 20, 0x78 }, { 21, 0x78 }, { 22, 0x78 }, { 23, 0x78 },
0099 { 24, 0x78 }, { 25, 0x00 }, { 26, 0x00 }, { 27, 0xfe },
0100 { 28, 0x00 }, { 29, 0x00 }, { 30, 0xfe }, { 31, 0x00 },
0101 { 32, 0x18 }, { 33, 0x18 }, { 34, 0x00 }, { 35, 0x00 },
0102 { 36, 0x00 }, { 37, 0x00 }, { 38, 0x00 }, { 39, 0x00 },
0103 { 40, 0x00 }, { 41, 0x00 }, { 42, 0x00 }, { 43, 0x80 },
0104 { 44, 0x80 }, { 45, 0x00 }, { 46, 0x00 }, { 47, 0x00 },
0105 { 48, 0x00 }, { 49, 0x00 }, { 50, 0x00 }, { 51, 0x04 },
0106 { 52, 0x00 }, { 53, 0x00 }, { 54, 0x00 }, { 55, 0x00 },
0107 { 56, 0x00 }, { 57, 0x00 }, { 58, 0x04 }, { 59, 0x00 },
0108 { 60, 0x00 }, { 61, 0x00 }, { 62, 0x00 }, { 63, 0x00 },
0109 { 64, 0x00 }, { 65, 0x04 }, { 66, 0x00 }, { 67, 0x00 },
0110 { 68, 0x00 }, { 69, 0x00 }, { 70, 0x00 }, { 71, 0x00 },
0111 { 72, 0x04 }, { 73, 0x00 }, { 74, 0x00 }, { 75, 0x00 },
0112 { 76, 0x00 }, { 77, 0x00 }, { 78, 0x00 }, { 79, 0x00 },
0113 { 80, 0x00 }, { 81, 0x00 }, { 82, 0x00 }, { 83, 0x00 },
0114 { 84, 0x00 }, { 85, 0x00 }, { 86, 0x00 }, { 87, 0x00 },
0115 { 88, 0x00 }, { 89, 0x00 }, { 90, 0x00 }, { 91, 0x00 },
0116 { 92, 0x00 }, { 93, 0x00 }, { 94, 0x00 }, { 95, 0x00 },
0117 { 96, 0x00 }, { 97, 0x00 }, { 98, 0x00 }, { 99, 0x00 },
0118 { 100, 0x00 }, { 101, 0x00 }, { 102, 0x02 }, { 103, 0x00 },
0119 { 104, 0x00 }, { 105, 0x00 }, { 106, 0x00 }, { 107, 0x00 },
0120 { 108, 0x00 }, { 109, 0x00 },
0121 };
0122
0123 static bool aic3x_volatile_reg(struct device *dev, unsigned int reg)
0124 {
0125 switch (reg) {
0126 case AIC3X_RESET:
0127 return true;
0128 default:
0129 return false;
0130 }
0131 }
0132
0133 const struct regmap_config aic3x_regmap = {
0134 .max_register = DAC_ICC_ADJ,
0135 .reg_defaults = aic3x_reg,
0136 .num_reg_defaults = ARRAY_SIZE(aic3x_reg),
0137
0138 .volatile_reg = aic3x_volatile_reg,
0139
0140 .cache_type = REGCACHE_RBTREE,
0141 };
0142 EXPORT_SYMBOL_GPL(aic3x_regmap);
0143
0144 #define SOC_DAPM_SINGLE_AIC3X(xname, reg, shift, mask, invert) \
0145 SOC_SINGLE_EXT(xname, reg, shift, mask, invert, \
0146 snd_soc_dapm_get_volsw, snd_soc_dapm_put_volsw_aic3x)
0147
0148
0149
0150
0151
0152 static int snd_soc_dapm_put_volsw_aic3x(struct snd_kcontrol *kcontrol,
0153 struct snd_ctl_elem_value *ucontrol)
0154 {
0155 struct snd_soc_component *component = snd_soc_dapm_kcontrol_component(kcontrol);
0156 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
0157 struct soc_mixer_control *mc =
0158 (struct soc_mixer_control *)kcontrol->private_value;
0159 unsigned int reg = mc->reg;
0160 unsigned int shift = mc->shift;
0161 int max = mc->max;
0162 unsigned int mask = (1 << fls(max)) - 1;
0163 unsigned int invert = mc->invert;
0164 unsigned short val;
0165 struct snd_soc_dapm_update update = {};
0166 int connect, change;
0167
0168 val = (ucontrol->value.integer.value[0] & mask);
0169
0170 mask = 0xf;
0171 if (val)
0172 val = mask;
0173
0174 connect = !!val;
0175
0176 if (invert)
0177 val = mask - val;
0178
0179 mask <<= shift;
0180 val <<= shift;
0181
0182 change = snd_soc_component_test_bits(component, reg, mask, val);
0183 if (change) {
0184 update.kcontrol = kcontrol;
0185 update.reg = reg;
0186 update.mask = mask;
0187 update.val = val;
0188
0189 snd_soc_dapm_mixer_update_power(dapm, kcontrol, connect,
0190 &update);
0191 }
0192
0193 return change;
0194 }
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 static int mic_bias_event(struct snd_soc_dapm_widget *w,
0206 struct snd_kcontrol *kcontrol, int event)
0207 {
0208 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm);
0209 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
0210
0211 switch (event) {
0212 case SND_SOC_DAPM_POST_PMU:
0213
0214 snd_soc_component_update_bits(component, MICBIAS_CTRL,
0215 MICBIAS_LEVEL_MASK,
0216 aic3x->micbias_vg << MICBIAS_LEVEL_SHIFT);
0217 break;
0218
0219 case SND_SOC_DAPM_PRE_PMD:
0220 snd_soc_component_update_bits(component, MICBIAS_CTRL,
0221 MICBIAS_LEVEL_MASK, 0);
0222 break;
0223 }
0224 return 0;
0225 }
0226
0227 static const char * const aic3x_left_dac_mux[] = {
0228 "DAC_L1", "DAC_L3", "DAC_L2" };
0229 static SOC_ENUM_SINGLE_DECL(aic3x_left_dac_enum, DAC_LINE_MUX, 6,
0230 aic3x_left_dac_mux);
0231
0232 static const char * const aic3x_right_dac_mux[] = {
0233 "DAC_R1", "DAC_R3", "DAC_R2" };
0234 static SOC_ENUM_SINGLE_DECL(aic3x_right_dac_enum, DAC_LINE_MUX, 4,
0235 aic3x_right_dac_mux);
0236
0237 static const char * const aic3x_left_hpcom_mux[] = {
0238 "differential of HPLOUT", "constant VCM", "single-ended" };
0239 static SOC_ENUM_SINGLE_DECL(aic3x_left_hpcom_enum, HPLCOM_CFG, 4,
0240 aic3x_left_hpcom_mux);
0241
0242 static const char * const aic3x_right_hpcom_mux[] = {
0243 "differential of HPROUT", "constant VCM", "single-ended",
0244 "differential of HPLCOM", "external feedback" };
0245 static SOC_ENUM_SINGLE_DECL(aic3x_right_hpcom_enum, HPRCOM_CFG, 3,
0246 aic3x_right_hpcom_mux);
0247
0248 static const char * const aic3x_linein_mode_mux[] = {
0249 "single-ended", "differential" };
0250 static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_l_enum, LINE1L_2_LADC_CTRL, 7,
0251 aic3x_linein_mode_mux);
0252 static SOC_ENUM_SINGLE_DECL(aic3x_line1l_2_r_enum, LINE1L_2_RADC_CTRL, 7,
0253 aic3x_linein_mode_mux);
0254 static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_l_enum, LINE1R_2_LADC_CTRL, 7,
0255 aic3x_linein_mode_mux);
0256 static SOC_ENUM_SINGLE_DECL(aic3x_line1r_2_r_enum, LINE1R_2_RADC_CTRL, 7,
0257 aic3x_linein_mode_mux);
0258 static SOC_ENUM_SINGLE_DECL(aic3x_line2l_2_ldac_enum, LINE2L_2_LADC_CTRL, 7,
0259 aic3x_linein_mode_mux);
0260 static SOC_ENUM_SINGLE_DECL(aic3x_line2r_2_rdac_enum, LINE2R_2_RADC_CTRL, 7,
0261 aic3x_linein_mode_mux);
0262
0263 static const char * const aic3x_adc_hpf[] = {
0264 "Disabled", "0.0045xFs", "0.0125xFs", "0.025xFs" };
0265 static SOC_ENUM_DOUBLE_DECL(aic3x_adc_hpf_enum, AIC3X_CODEC_DFILT_CTRL, 6, 4,
0266 aic3x_adc_hpf);
0267
0268 static const char * const aic3x_agc_level[] = {
0269 "-5.5dB", "-8dB", "-10dB", "-12dB",
0270 "-14dB", "-17dB", "-20dB", "-24dB" };
0271 static SOC_ENUM_SINGLE_DECL(aic3x_lagc_level_enum, LAGC_CTRL_A, 4,
0272 aic3x_agc_level);
0273 static SOC_ENUM_SINGLE_DECL(aic3x_ragc_level_enum, RAGC_CTRL_A, 4,
0274 aic3x_agc_level);
0275
0276 static const char * const aic3x_agc_attack[] = {
0277 "8ms", "11ms", "16ms", "20ms" };
0278 static SOC_ENUM_SINGLE_DECL(aic3x_lagc_attack_enum, LAGC_CTRL_A, 2,
0279 aic3x_agc_attack);
0280 static SOC_ENUM_SINGLE_DECL(aic3x_ragc_attack_enum, RAGC_CTRL_A, 2,
0281 aic3x_agc_attack);
0282
0283 static const char * const aic3x_agc_decay[] = {
0284 "100ms", "200ms", "400ms", "500ms" };
0285 static SOC_ENUM_SINGLE_DECL(aic3x_lagc_decay_enum, LAGC_CTRL_A, 0,
0286 aic3x_agc_decay);
0287 static SOC_ENUM_SINGLE_DECL(aic3x_ragc_decay_enum, RAGC_CTRL_A, 0,
0288 aic3x_agc_decay);
0289
0290 static const char * const aic3x_poweron_time[] = {
0291 "0us", "10us", "100us", "1ms", "10ms", "50ms",
0292 "100ms", "200ms", "400ms", "800ms", "2s", "4s" };
0293 static SOC_ENUM_SINGLE_DECL(aic3x_poweron_time_enum, HPOUT_POP_REDUCTION, 4,
0294 aic3x_poweron_time);
0295
0296 static const char * const aic3x_rampup_step[] = { "0ms", "1ms", "2ms", "4ms" };
0297 static SOC_ENUM_SINGLE_DECL(aic3x_rampup_step_enum, HPOUT_POP_REDUCTION, 2,
0298 aic3x_rampup_step);
0299
0300
0301
0302
0303 static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0);
0304
0305 static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0);
0306
0307
0308
0309
0310
0311
0312
0313
0314
0315 static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
0316
0317
0318 static const DECLARE_TLV_DB_SCALE(out_tlv, 0, 100, 0);
0319
0320 static const struct snd_kcontrol_new aic3x_snd_controls[] = {
0321
0322 SOC_DOUBLE_R_TLV("PCM Playback Volume",
0323 LDAC_VOL, RDAC_VOL, 0, 0x7f, 1, dac_tlv),
0324
0325
0326
0327
0328
0329
0330 SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume",
0331 PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
0332 SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume",
0333 DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
0334
0335 SOC_SINGLE_TLV("Right Line Mixer PGAL Bypass Volume",
0336 PGAL_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
0337 SOC_SINGLE_TLV("Right Line Mixer DACL1 Playback Volume",
0338 DACL1_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
0339
0340 SOC_SINGLE_TLV("Left HP Mixer PGAR Bypass Volume",
0341 PGAR_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
0342 SOC_SINGLE_TLV("Left HP Mixer DACR1 Playback Volume",
0343 DACR1_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
0344
0345 SOC_SINGLE_TLV("Right HP Mixer PGAL Bypass Volume",
0346 PGAL_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
0347 SOC_SINGLE_TLV("Right HP Mixer DACL1 Playback Volume",
0348 DACL1_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
0349
0350 SOC_SINGLE_TLV("Left HPCOM Mixer PGAR Bypass Volume",
0351 PGAR_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
0352 SOC_SINGLE_TLV("Left HPCOM Mixer DACR1 Playback Volume",
0353 DACR1_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
0354
0355 SOC_SINGLE_TLV("Right HPCOM Mixer PGAL Bypass Volume",
0356 PGAL_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
0357 SOC_SINGLE_TLV("Right HPCOM Mixer DACL1 Playback Volume",
0358 DACL1_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
0359
0360
0361 SOC_DOUBLE_R_TLV("Line PGA Bypass Volume",
0362 PGAL_2_LLOPM_VOL, PGAR_2_RLOPM_VOL,
0363 0, 118, 1, output_stage_tlv),
0364 SOC_DOUBLE_R_TLV("Line DAC Playback Volume",
0365 DACL1_2_LLOPM_VOL, DACR1_2_RLOPM_VOL,
0366 0, 118, 1, output_stage_tlv),
0367
0368 SOC_DOUBLE_R_TLV("HP PGA Bypass Volume",
0369 PGAL_2_HPLOUT_VOL, PGAR_2_HPROUT_VOL,
0370 0, 118, 1, output_stage_tlv),
0371 SOC_DOUBLE_R_TLV("HP DAC Playback Volume",
0372 DACL1_2_HPLOUT_VOL, DACR1_2_HPROUT_VOL,
0373 0, 118, 1, output_stage_tlv),
0374
0375 SOC_DOUBLE_R_TLV("HPCOM PGA Bypass Volume",
0376 PGAL_2_HPLCOM_VOL, PGAR_2_HPRCOM_VOL,
0377 0, 118, 1, output_stage_tlv),
0378 SOC_DOUBLE_R_TLV("HPCOM DAC Playback Volume",
0379 DACL1_2_HPLCOM_VOL, DACR1_2_HPRCOM_VOL,
0380 0, 118, 1, output_stage_tlv),
0381
0382
0383 SOC_DOUBLE_R_TLV("Line Playback Volume", LLOPM_CTRL, RLOPM_CTRL, 4,
0384 9, 0, out_tlv),
0385 SOC_DOUBLE_R("Line Playback Switch", LLOPM_CTRL, RLOPM_CTRL, 3,
0386 0x01, 0),
0387 SOC_DOUBLE_R_TLV("HP Playback Volume", HPLOUT_CTRL, HPROUT_CTRL, 4,
0388 9, 0, out_tlv),
0389 SOC_DOUBLE_R("HP Playback Switch", HPLOUT_CTRL, HPROUT_CTRL, 3,
0390 0x01, 0),
0391 SOC_DOUBLE_R_TLV("HPCOM Playback Volume", HPLCOM_CTRL, HPRCOM_CTRL,
0392 4, 9, 0, out_tlv),
0393 SOC_DOUBLE_R("HPCOM Playback Switch", HPLCOM_CTRL, HPRCOM_CTRL, 3,
0394 0x01, 0),
0395
0396
0397
0398
0399
0400 SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
0401 SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum),
0402 SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum),
0403 SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum),
0404 SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum),
0405 SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum),
0406 SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum),
0407
0408
0409 SOC_DOUBLE("De-emphasis Switch", AIC3X_CODEC_DFILT_CTRL, 2, 0, 0x01, 0),
0410
0411
0412 SOC_DOUBLE_R_TLV("PGA Capture Volume", LADC_VOL, RADC_VOL,
0413 0, 119, 0, adc_tlv),
0414 SOC_DOUBLE_R("PGA Capture Switch", LADC_VOL, RADC_VOL, 7, 0x01, 1),
0415
0416 SOC_ENUM("ADC HPF Cut-off", aic3x_adc_hpf_enum),
0417
0418
0419 SOC_ENUM("Output Driver Power-On time", aic3x_poweron_time_enum),
0420 SOC_ENUM("Output Driver Ramp-up step", aic3x_rampup_step_enum),
0421 };
0422
0423
0424 static const struct snd_kcontrol_new aic3x_extra_snd_controls[] = {
0425
0426
0427
0428
0429
0430 SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
0431 LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
0432
0433 SOC_SINGLE_TLV("Right Line Mixer Line2L Bypass Volume",
0434 LINE2L_2_RLOPM_VOL, 0, 118, 1, output_stage_tlv),
0435
0436 SOC_SINGLE_TLV("Left HP Mixer Line2R Bypass Volume",
0437 LINE2R_2_HPLOUT_VOL, 0, 118, 1, output_stage_tlv),
0438
0439 SOC_SINGLE_TLV("Right HP Mixer Line2L Bypass Volume",
0440 LINE2L_2_HPROUT_VOL, 0, 118, 1, output_stage_tlv),
0441
0442 SOC_SINGLE_TLV("Left HPCOM Mixer Line2R Bypass Volume",
0443 LINE2R_2_HPLCOM_VOL, 0, 118, 1, output_stage_tlv),
0444
0445 SOC_SINGLE_TLV("Right HPCOM Mixer Line2L Bypass Volume",
0446 LINE2L_2_HPRCOM_VOL, 0, 118, 1, output_stage_tlv),
0447
0448
0449 SOC_DOUBLE_R_TLV("Line Line2 Bypass Volume",
0450 LINE2L_2_LLOPM_VOL, LINE2R_2_RLOPM_VOL,
0451 0, 118, 1, output_stage_tlv),
0452
0453 SOC_DOUBLE_R_TLV("HP Line2 Bypass Volume",
0454 LINE2L_2_HPLOUT_VOL, LINE2R_2_HPROUT_VOL,
0455 0, 118, 1, output_stage_tlv),
0456
0457 SOC_DOUBLE_R_TLV("HPCOM Line2 Bypass Volume",
0458 LINE2L_2_HPLCOM_VOL, LINE2R_2_HPRCOM_VOL,
0459 0, 118, 1, output_stage_tlv),
0460 };
0461
0462 static const struct snd_kcontrol_new aic3x_mono_controls[] = {
0463 SOC_DOUBLE_R_TLV("Mono Line2 Bypass Volume",
0464 LINE2L_2_MONOLOPM_VOL, LINE2R_2_MONOLOPM_VOL,
0465 0, 118, 1, output_stage_tlv),
0466 SOC_DOUBLE_R_TLV("Mono PGA Bypass Volume",
0467 PGAL_2_MONOLOPM_VOL, PGAR_2_MONOLOPM_VOL,
0468 0, 118, 1, output_stage_tlv),
0469 SOC_DOUBLE_R_TLV("Mono DAC Playback Volume",
0470 DACL1_2_MONOLOPM_VOL, DACR1_2_MONOLOPM_VOL,
0471 0, 118, 1, output_stage_tlv),
0472
0473 SOC_SINGLE("Mono Playback Switch", MONOLOPM_CTRL, 3, 0x01, 0),
0474 SOC_SINGLE_TLV("Mono Playback Volume", MONOLOPM_CTRL, 4, 9, 0,
0475 out_tlv),
0476
0477 };
0478
0479
0480
0481
0482 static DECLARE_TLV_DB_SCALE(classd_amp_tlv, 0, 600, 0);
0483
0484 static const struct snd_kcontrol_new aic3x_classd_amp_gain_ctrl =
0485 SOC_DOUBLE_TLV("Class-D Playback Volume", CLASSD_CTRL, 6, 4, 3, 0, classd_amp_tlv);
0486
0487
0488 static const struct snd_kcontrol_new aic3x_left_dac_mux_controls =
0489 SOC_DAPM_ENUM("Route", aic3x_left_dac_enum);
0490
0491
0492 static const struct snd_kcontrol_new aic3x_right_dac_mux_controls =
0493 SOC_DAPM_ENUM("Route", aic3x_right_dac_enum);
0494
0495
0496 static const struct snd_kcontrol_new aic3x_left_hpcom_mux_controls =
0497 SOC_DAPM_ENUM("Route", aic3x_left_hpcom_enum);
0498
0499
0500 static const struct snd_kcontrol_new aic3x_right_hpcom_mux_controls =
0501 SOC_DAPM_ENUM("Route", aic3x_right_hpcom_enum);
0502
0503
0504 static const struct snd_kcontrol_new aic3x_left_line_mixer_controls[] = {
0505 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_LLOPM_VOL, 7, 1, 0),
0506 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_LLOPM_VOL, 7, 1, 0),
0507 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_LLOPM_VOL, 7, 1, 0),
0508 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_LLOPM_VOL, 7, 1, 0),
0509
0510 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_LLOPM_VOL, 7, 1, 0),
0511 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_LLOPM_VOL, 7, 1, 0),
0512 };
0513
0514
0515 static const struct snd_kcontrol_new aic3x_right_line_mixer_controls[] = {
0516 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_RLOPM_VOL, 7, 1, 0),
0517 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_RLOPM_VOL, 7, 1, 0),
0518 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_RLOPM_VOL, 7, 1, 0),
0519 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_RLOPM_VOL, 7, 1, 0),
0520
0521 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_RLOPM_VOL, 7, 1, 0),
0522 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_RLOPM_VOL, 7, 1, 0),
0523 };
0524
0525
0526 static const struct snd_kcontrol_new aic3x_mono_mixer_controls[] = {
0527 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_MONOLOPM_VOL, 7, 1, 0),
0528 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_MONOLOPM_VOL, 7, 1, 0),
0529 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_MONOLOPM_VOL, 7, 1, 0),
0530 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_MONOLOPM_VOL, 7, 1, 0),
0531 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_MONOLOPM_VOL, 7, 1, 0),
0532 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_MONOLOPM_VOL, 7, 1, 0),
0533 };
0534
0535
0536 static const struct snd_kcontrol_new aic3x_left_hp_mixer_controls[] = {
0537 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLOUT_VOL, 7, 1, 0),
0538 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLOUT_VOL, 7, 1, 0),
0539 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLOUT_VOL, 7, 1, 0),
0540 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLOUT_VOL, 7, 1, 0),
0541
0542 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLOUT_VOL, 7, 1, 0),
0543 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLOUT_VOL, 7, 1, 0),
0544 };
0545
0546
0547 static const struct snd_kcontrol_new aic3x_right_hp_mixer_controls[] = {
0548 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPROUT_VOL, 7, 1, 0),
0549 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPROUT_VOL, 7, 1, 0),
0550 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPROUT_VOL, 7, 1, 0),
0551 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPROUT_VOL, 7, 1, 0),
0552
0553 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPROUT_VOL, 7, 1, 0),
0554 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPROUT_VOL, 7, 1, 0),
0555 };
0556
0557
0558 static const struct snd_kcontrol_new aic3x_left_hpcom_mixer_controls[] = {
0559 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPLCOM_VOL, 7, 1, 0),
0560 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPLCOM_VOL, 7, 1, 0),
0561 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPLCOM_VOL, 7, 1, 0),
0562 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPLCOM_VOL, 7, 1, 0),
0563
0564 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPLCOM_VOL, 7, 1, 0),
0565 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPLCOM_VOL, 7, 1, 0),
0566 };
0567
0568
0569 static const struct snd_kcontrol_new aic3x_right_hpcom_mixer_controls[] = {
0570 SOC_DAPM_SINGLE("PGAL Bypass Switch", PGAL_2_HPRCOM_VOL, 7, 1, 0),
0571 SOC_DAPM_SINGLE("DACL1 Switch", DACL1_2_HPRCOM_VOL, 7, 1, 0),
0572 SOC_DAPM_SINGLE("PGAR Bypass Switch", PGAR_2_HPRCOM_VOL, 7, 1, 0),
0573 SOC_DAPM_SINGLE("DACR1 Switch", DACR1_2_HPRCOM_VOL, 7, 1, 0),
0574
0575 SOC_DAPM_SINGLE("Line2L Bypass Switch", LINE2L_2_HPRCOM_VOL, 7, 1, 0),
0576 SOC_DAPM_SINGLE("Line2R Bypass Switch", LINE2R_2_HPRCOM_VOL, 7, 1, 0),
0577 };
0578
0579
0580 static const struct snd_kcontrol_new aic3x_left_pga_mixer_controls[] = {
0581 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
0582 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
0583 SOC_DAPM_SINGLE_AIC3X("Line2L Switch", LINE2L_2_LADC_CTRL, 3, 1, 1),
0584 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
0585 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
0586 };
0587
0588
0589 static const struct snd_kcontrol_new aic3x_right_pga_mixer_controls[] = {
0590 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
0591 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
0592 SOC_DAPM_SINGLE_AIC3X("Line2R Switch", LINE2R_2_RADC_CTRL, 3, 1, 1),
0593 SOC_DAPM_SINGLE_AIC3X("Mic3L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
0594 SOC_DAPM_SINGLE_AIC3X("Mic3R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
0595 };
0596
0597
0598 static const struct snd_kcontrol_new aic3104_left_pga_mixer_controls[] = {
0599 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_LADC_CTRL, 3, 1, 1),
0600 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_LADC_CTRL, 3, 1, 1),
0601 SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_LADC_CTRL, 4, 1, 1),
0602 SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_LADC_CTRL, 0, 1, 1),
0603 };
0604
0605
0606 static const struct snd_kcontrol_new aic3104_right_pga_mixer_controls[] = {
0607 SOC_DAPM_SINGLE_AIC3X("Line1R Switch", LINE1R_2_RADC_CTRL, 3, 1, 1),
0608 SOC_DAPM_SINGLE_AIC3X("Line1L Switch", LINE1L_2_RADC_CTRL, 3, 1, 1),
0609 SOC_DAPM_SINGLE_AIC3X("Mic2L Switch", MIC3LR_2_RADC_CTRL, 4, 1, 1),
0610 SOC_DAPM_SINGLE_AIC3X("Mic2R Switch", MIC3LR_2_RADC_CTRL, 0, 1, 1),
0611 };
0612
0613
0614 static const struct snd_kcontrol_new aic3x_left_line1l_mux_controls =
0615 SOC_DAPM_ENUM("Route", aic3x_line1l_2_l_enum);
0616 static const struct snd_kcontrol_new aic3x_right_line1l_mux_controls =
0617 SOC_DAPM_ENUM("Route", aic3x_line1l_2_r_enum);
0618
0619
0620 static const struct snd_kcontrol_new aic3x_right_line1r_mux_controls =
0621 SOC_DAPM_ENUM("Route", aic3x_line1r_2_r_enum);
0622 static const struct snd_kcontrol_new aic3x_left_line1r_mux_controls =
0623 SOC_DAPM_ENUM("Route", aic3x_line1r_2_l_enum);
0624
0625
0626 static const struct snd_kcontrol_new aic3x_left_line2_mux_controls =
0627 SOC_DAPM_ENUM("Route", aic3x_line2l_2_ldac_enum);
0628
0629
0630 static const struct snd_kcontrol_new aic3x_right_line2_mux_controls =
0631 SOC_DAPM_ENUM("Route", aic3x_line2r_2_rdac_enum);
0632
0633 static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
0634
0635 SND_SOC_DAPM_DAC("Left DAC", "Left Playback", DAC_PWR, 7, 0),
0636 SND_SOC_DAPM_MUX("Left DAC Mux", SND_SOC_NOPM, 0, 0,
0637 &aic3x_left_dac_mux_controls),
0638 SND_SOC_DAPM_MUX("Left HPCOM Mux", SND_SOC_NOPM, 0, 0,
0639 &aic3x_left_hpcom_mux_controls),
0640 SND_SOC_DAPM_PGA("Left Line Out", LLOPM_CTRL, 0, 0, NULL, 0),
0641 SND_SOC_DAPM_PGA("Left HP Out", HPLOUT_CTRL, 0, 0, NULL, 0),
0642 SND_SOC_DAPM_PGA("Left HP Com", HPLCOM_CTRL, 0, 0, NULL, 0),
0643
0644
0645 SND_SOC_DAPM_DAC("Right DAC", "Right Playback", DAC_PWR, 6, 0),
0646 SND_SOC_DAPM_MUX("Right DAC Mux", SND_SOC_NOPM, 0, 0,
0647 &aic3x_right_dac_mux_controls),
0648 SND_SOC_DAPM_MUX("Right HPCOM Mux", SND_SOC_NOPM, 0, 0,
0649 &aic3x_right_hpcom_mux_controls),
0650 SND_SOC_DAPM_PGA("Right Line Out", RLOPM_CTRL, 0, 0, NULL, 0),
0651 SND_SOC_DAPM_PGA("Right HP Out", HPROUT_CTRL, 0, 0, NULL, 0),
0652 SND_SOC_DAPM_PGA("Right HP Com", HPRCOM_CTRL, 0, 0, NULL, 0),
0653
0654
0655 SND_SOC_DAPM_ADC("Left ADC", "Left Capture", LINE1L_2_LADC_CTRL, 2, 0),
0656 SND_SOC_DAPM_MUX("Left Line1L Mux", SND_SOC_NOPM, 0, 0,
0657 &aic3x_left_line1l_mux_controls),
0658 SND_SOC_DAPM_MUX("Left Line1R Mux", SND_SOC_NOPM, 0, 0,
0659 &aic3x_left_line1r_mux_controls),
0660
0661
0662 SND_SOC_DAPM_ADC("Right ADC", "Right Capture",
0663 LINE1R_2_RADC_CTRL, 2, 0),
0664 SND_SOC_DAPM_MUX("Right Line1L Mux", SND_SOC_NOPM, 0, 0,
0665 &aic3x_right_line1l_mux_controls),
0666 SND_SOC_DAPM_MUX("Right Line1R Mux", SND_SOC_NOPM, 0, 0,
0667 &aic3x_right_line1r_mux_controls),
0668
0669
0670 SND_SOC_DAPM_SUPPLY("Mic Bias", MICBIAS_CTRL, 6, 0,
0671 mic_bias_event,
0672 SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD),
0673
0674 SND_SOC_DAPM_OUTPUT("LLOUT"),
0675 SND_SOC_DAPM_OUTPUT("RLOUT"),
0676 SND_SOC_DAPM_OUTPUT("HPLOUT"),
0677 SND_SOC_DAPM_OUTPUT("HPROUT"),
0678 SND_SOC_DAPM_OUTPUT("HPLCOM"),
0679 SND_SOC_DAPM_OUTPUT("HPRCOM"),
0680
0681 SND_SOC_DAPM_INPUT("LINE1L"),
0682 SND_SOC_DAPM_INPUT("LINE1R"),
0683
0684
0685
0686
0687
0688
0689
0690 SND_SOC_DAPM_OUTPUT("Detection"),
0691 };
0692
0693
0694 static const struct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = {
0695
0696 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
0697 &aic3x_left_pga_mixer_controls[0],
0698 ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
0699 SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
0700 &aic3x_left_line2_mux_controls),
0701
0702
0703 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
0704 &aic3x_right_pga_mixer_controls[0],
0705 ARRAY_SIZE(aic3x_right_pga_mixer_controls)),
0706 SND_SOC_DAPM_MUX("Right Line2R Mux", SND_SOC_NOPM, 0, 0,
0707 &aic3x_right_line2_mux_controls),
0708
0709
0710
0711
0712
0713
0714 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
0715 AIC3X_GPIO1_REG, 4, 0xf,
0716 AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
0717 AIC3X_GPIO1_FUNC_DISABLED),
0718
0719
0720
0721
0722
0723 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
0724 AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
0725 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
0726 AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
0727 SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
0728 AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
0729
0730
0731 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
0732 &aic3x_left_line_mixer_controls[0],
0733 ARRAY_SIZE(aic3x_left_line_mixer_controls)),
0734 SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
0735 &aic3x_right_line_mixer_controls[0],
0736 ARRAY_SIZE(aic3x_right_line_mixer_controls)),
0737 SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
0738 &aic3x_left_hp_mixer_controls[0],
0739 ARRAY_SIZE(aic3x_left_hp_mixer_controls)),
0740 SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
0741 &aic3x_right_hp_mixer_controls[0],
0742 ARRAY_SIZE(aic3x_right_hp_mixer_controls)),
0743 SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
0744 &aic3x_left_hpcom_mixer_controls[0],
0745 ARRAY_SIZE(aic3x_left_hpcom_mixer_controls)),
0746 SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
0747 &aic3x_right_hpcom_mixer_controls[0],
0748 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls)),
0749
0750 SND_SOC_DAPM_INPUT("MIC3L"),
0751 SND_SOC_DAPM_INPUT("MIC3R"),
0752 SND_SOC_DAPM_INPUT("LINE2L"),
0753 SND_SOC_DAPM_INPUT("LINE2R"),
0754 };
0755
0756
0757 static const struct snd_soc_dapm_widget aic3104_extra_dapm_widgets[] = {
0758
0759 SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
0760 &aic3104_left_pga_mixer_controls[0],
0761 ARRAY_SIZE(aic3104_left_pga_mixer_controls)),
0762
0763
0764 SND_SOC_DAPM_MIXER("Right PGA Mixer", SND_SOC_NOPM, 0, 0,
0765 &aic3104_right_pga_mixer_controls[0],
0766 ARRAY_SIZE(aic3104_right_pga_mixer_controls)),
0767
0768
0769 SND_SOC_DAPM_MIXER("Left Line Mixer", SND_SOC_NOPM, 0, 0,
0770 &aic3x_left_line_mixer_controls[0],
0771 ARRAY_SIZE(aic3x_left_line_mixer_controls) - 2),
0772 SND_SOC_DAPM_MIXER("Right Line Mixer", SND_SOC_NOPM, 0, 0,
0773 &aic3x_right_line_mixer_controls[0],
0774 ARRAY_SIZE(aic3x_right_line_mixer_controls) - 2),
0775 SND_SOC_DAPM_MIXER("Left HP Mixer", SND_SOC_NOPM, 0, 0,
0776 &aic3x_left_hp_mixer_controls[0],
0777 ARRAY_SIZE(aic3x_left_hp_mixer_controls) - 2),
0778 SND_SOC_DAPM_MIXER("Right HP Mixer", SND_SOC_NOPM, 0, 0,
0779 &aic3x_right_hp_mixer_controls[0],
0780 ARRAY_SIZE(aic3x_right_hp_mixer_controls) - 2),
0781 SND_SOC_DAPM_MIXER("Left HPCOM Mixer", SND_SOC_NOPM, 0, 0,
0782 &aic3x_left_hpcom_mixer_controls[0],
0783 ARRAY_SIZE(aic3x_left_hpcom_mixer_controls) - 2),
0784 SND_SOC_DAPM_MIXER("Right HPCOM Mixer", SND_SOC_NOPM, 0, 0,
0785 &aic3x_right_hpcom_mixer_controls[0],
0786 ARRAY_SIZE(aic3x_right_hpcom_mixer_controls) - 2),
0787
0788 SND_SOC_DAPM_INPUT("MIC2L"),
0789 SND_SOC_DAPM_INPUT("MIC2R"),
0790 };
0791
0792 static const struct snd_soc_dapm_widget aic3x_dapm_mono_widgets[] = {
0793
0794 SND_SOC_DAPM_PGA("Mono Out", MONOLOPM_CTRL, 0, 0, NULL, 0),
0795
0796 SND_SOC_DAPM_MIXER("Mono Mixer", SND_SOC_NOPM, 0, 0,
0797 &aic3x_mono_mixer_controls[0],
0798 ARRAY_SIZE(aic3x_mono_mixer_controls)),
0799
0800 SND_SOC_DAPM_OUTPUT("MONO_LOUT"),
0801 };
0802
0803 static const struct snd_soc_dapm_widget aic3007_dapm_widgets[] = {
0804
0805 SND_SOC_DAPM_PGA("Left Class-D Out", CLASSD_CTRL, 3, 0, NULL, 0),
0806 SND_SOC_DAPM_PGA("Right Class-D Out", CLASSD_CTRL, 2, 0, NULL, 0),
0807
0808 SND_SOC_DAPM_OUTPUT("SPOP"),
0809 SND_SOC_DAPM_OUTPUT("SPOM"),
0810 };
0811
0812 static const struct snd_soc_dapm_route intercon[] = {
0813
0814 {"Left Line1L Mux", "single-ended", "LINE1L"},
0815 {"Left Line1L Mux", "differential", "LINE1L"},
0816 {"Left Line1R Mux", "single-ended", "LINE1R"},
0817 {"Left Line1R Mux", "differential", "LINE1R"},
0818
0819 {"Left PGA Mixer", "Line1L Switch", "Left Line1L Mux"},
0820 {"Left PGA Mixer", "Line1R Switch", "Left Line1R Mux"},
0821
0822 {"Left ADC", NULL, "Left PGA Mixer"},
0823
0824
0825 {"Right Line1R Mux", "single-ended", "LINE1R"},
0826 {"Right Line1R Mux", "differential", "LINE1R"},
0827 {"Right Line1L Mux", "single-ended", "LINE1L"},
0828 {"Right Line1L Mux", "differential", "LINE1L"},
0829
0830 {"Right PGA Mixer", "Line1L Switch", "Right Line1L Mux"},
0831 {"Right PGA Mixer", "Line1R Switch", "Right Line1R Mux"},
0832
0833 {"Right ADC", NULL, "Right PGA Mixer"},
0834
0835
0836 {"Left DAC Mux", "DAC_L1", "Left DAC"},
0837 {"Left DAC Mux", "DAC_L2", "Left DAC"},
0838 {"Left DAC Mux", "DAC_L3", "Left DAC"},
0839
0840
0841 {"Right DAC Mux", "DAC_R1", "Right DAC"},
0842 {"Right DAC Mux", "DAC_R2", "Right DAC"},
0843 {"Right DAC Mux", "DAC_R3", "Right DAC"},
0844
0845
0846 {"Left Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0847 {"Left Line Mixer", "DACL1 Switch", "Left DAC Mux"},
0848 {"Left Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0849 {"Left Line Mixer", "DACR1 Switch", "Right DAC Mux"},
0850
0851 {"Left Line Out", NULL, "Left Line Mixer"},
0852 {"Left Line Out", NULL, "Left DAC Mux"},
0853 {"LLOUT", NULL, "Left Line Out"},
0854
0855
0856 {"Right Line Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0857 {"Right Line Mixer", "DACL1 Switch", "Left DAC Mux"},
0858 {"Right Line Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0859 {"Right Line Mixer", "DACR1 Switch", "Right DAC Mux"},
0860
0861 {"Right Line Out", NULL, "Right Line Mixer"},
0862 {"Right Line Out", NULL, "Right DAC Mux"},
0863 {"RLOUT", NULL, "Right Line Out"},
0864
0865
0866 {"Left HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0867 {"Left HP Mixer", "DACL1 Switch", "Left DAC Mux"},
0868 {"Left HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0869 {"Left HP Mixer", "DACR1 Switch", "Right DAC Mux"},
0870
0871 {"Left HP Out", NULL, "Left HP Mixer"},
0872 {"Left HP Out", NULL, "Left DAC Mux"},
0873 {"HPLOUT", NULL, "Left HP Out"},
0874
0875
0876 {"Right HP Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0877 {"Right HP Mixer", "DACL1 Switch", "Left DAC Mux"},
0878 {"Right HP Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0879 {"Right HP Mixer", "DACR1 Switch", "Right DAC Mux"},
0880
0881 {"Right HP Out", NULL, "Right HP Mixer"},
0882 {"Right HP Out", NULL, "Right DAC Mux"},
0883 {"HPROUT", NULL, "Right HP Out"},
0884
0885
0886 {"Left HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0887 {"Left HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
0888 {"Left HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0889 {"Left HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
0890
0891 {"Left HPCOM Mux", "differential of HPLOUT", "Left HP Mixer"},
0892 {"Left HPCOM Mux", "constant VCM", "Left HPCOM Mixer"},
0893 {"Left HPCOM Mux", "single-ended", "Left HPCOM Mixer"},
0894 {"Left HP Com", NULL, "Left HPCOM Mux"},
0895 {"HPLCOM", NULL, "Left HP Com"},
0896
0897
0898 {"Right HPCOM Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0899 {"Right HPCOM Mixer", "DACL1 Switch", "Left DAC Mux"},
0900 {"Right HPCOM Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0901 {"Right HPCOM Mixer", "DACR1 Switch", "Right DAC Mux"},
0902
0903 {"Right HPCOM Mux", "differential of HPROUT", "Right HP Mixer"},
0904 {"Right HPCOM Mux", "constant VCM", "Right HPCOM Mixer"},
0905 {"Right HPCOM Mux", "single-ended", "Right HPCOM Mixer"},
0906 {"Right HPCOM Mux", "differential of HPLCOM", "Left HPCOM Mixer"},
0907 {"Right HPCOM Mux", "external feedback", "Right HPCOM Mixer"},
0908 {"Right HP Com", NULL, "Right HPCOM Mux"},
0909 {"HPRCOM", NULL, "Right HP Com"},
0910 };
0911
0912
0913 static const struct snd_soc_dapm_route intercon_extra[] = {
0914
0915 {"Left Line2L Mux", "single-ended", "LINE2L"},
0916 {"Left Line2L Mux", "differential", "LINE2L"},
0917
0918 {"Left PGA Mixer", "Line2L Switch", "Left Line2L Mux"},
0919 {"Left PGA Mixer", "Mic3L Switch", "MIC3L"},
0920 {"Left PGA Mixer", "Mic3R Switch", "MIC3R"},
0921
0922 {"Left ADC", NULL, "GPIO1 dmic modclk"},
0923
0924
0925 {"Right Line2R Mux", "single-ended", "LINE2R"},
0926 {"Right Line2R Mux", "differential", "LINE2R"},
0927
0928 {"Right PGA Mixer", "Line2R Switch", "Right Line2R Mux"},
0929 {"Right PGA Mixer", "Mic3L Switch", "MIC3L"},
0930 {"Right PGA Mixer", "Mic3R Switch", "MIC3R"},
0931
0932 {"Right ADC", NULL, "GPIO1 dmic modclk"},
0933
0934
0935
0936
0937
0938 {"GPIO1 dmic modclk", NULL, "DMic Rate 128"},
0939 {"GPIO1 dmic modclk", NULL, "DMic Rate 64"},
0940 {"GPIO1 dmic modclk", NULL, "DMic Rate 32"},
0941
0942
0943 {"Left Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0944 {"Left Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0945
0946
0947 {"Right Line Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0948 {"Right Line Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0949
0950
0951 {"Left HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0952 {"Left HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0953
0954
0955 {"Right HP Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0956 {"Right HP Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0957
0958
0959 {"Left HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0960 {"Left HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0961
0962
0963 {"Right HPCOM Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0964 {"Right HPCOM Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0965 };
0966
0967
0968 static const struct snd_soc_dapm_route intercon_extra_3104[] = {
0969
0970 {"Left PGA Mixer", "Mic2L Switch", "MIC2L"},
0971 {"Left PGA Mixer", "Mic2R Switch", "MIC2R"},
0972
0973
0974 {"Right PGA Mixer", "Mic2L Switch", "MIC2L"},
0975 {"Right PGA Mixer", "Mic2R Switch", "MIC2R"},
0976 };
0977
0978 static const struct snd_soc_dapm_route intercon_mono[] = {
0979
0980 {"Mono Mixer", "Line2L Bypass Switch", "Left Line2L Mux"},
0981 {"Mono Mixer", "PGAL Bypass Switch", "Left PGA Mixer"},
0982 {"Mono Mixer", "DACL1 Switch", "Left DAC Mux"},
0983 {"Mono Mixer", "Line2R Bypass Switch", "Right Line2R Mux"},
0984 {"Mono Mixer", "PGAR Bypass Switch", "Right PGA Mixer"},
0985 {"Mono Mixer", "DACR1 Switch", "Right DAC Mux"},
0986 {"Mono Out", NULL, "Mono Mixer"},
0987 {"MONO_LOUT", NULL, "Mono Out"},
0988 };
0989
0990 static const struct snd_soc_dapm_route intercon_3007[] = {
0991
0992 {"Left Class-D Out", NULL, "Left Line Out"},
0993 {"Right Class-D Out", NULL, "Left Line Out"},
0994 {"SPOP", NULL, "Left Class-D Out"},
0995 {"SPOM", NULL, "Right Class-D Out"},
0996 };
0997
0998 static int aic3x_add_widgets(struct snd_soc_component *component)
0999 {
1000 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1001 struct snd_soc_dapm_context *dapm = snd_soc_component_get_dapm(component);
1002
1003 switch (aic3x->model) {
1004 case AIC3X_MODEL_3X:
1005 case AIC3X_MODEL_33:
1006 case AIC3X_MODEL_3106:
1007 snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
1008 ARRAY_SIZE(aic3x_extra_dapm_widgets));
1009 snd_soc_dapm_add_routes(dapm, intercon_extra,
1010 ARRAY_SIZE(intercon_extra));
1011 snd_soc_dapm_new_controls(dapm, aic3x_dapm_mono_widgets,
1012 ARRAY_SIZE(aic3x_dapm_mono_widgets));
1013 snd_soc_dapm_add_routes(dapm, intercon_mono,
1014 ARRAY_SIZE(intercon_mono));
1015 break;
1016 case AIC3X_MODEL_3007:
1017 snd_soc_dapm_new_controls(dapm, aic3x_extra_dapm_widgets,
1018 ARRAY_SIZE(aic3x_extra_dapm_widgets));
1019 snd_soc_dapm_add_routes(dapm, intercon_extra,
1020 ARRAY_SIZE(intercon_extra));
1021 snd_soc_dapm_new_controls(dapm, aic3007_dapm_widgets,
1022 ARRAY_SIZE(aic3007_dapm_widgets));
1023 snd_soc_dapm_add_routes(dapm, intercon_3007,
1024 ARRAY_SIZE(intercon_3007));
1025 break;
1026 case AIC3X_MODEL_3104:
1027 snd_soc_dapm_new_controls(dapm, aic3104_extra_dapm_widgets,
1028 ARRAY_SIZE(aic3104_extra_dapm_widgets));
1029 snd_soc_dapm_add_routes(dapm, intercon_extra_3104,
1030 ARRAY_SIZE(intercon_extra_3104));
1031 break;
1032 }
1033
1034 return 0;
1035 }
1036
1037 static int aic3x_hw_params(struct snd_pcm_substream *substream,
1038 struct snd_pcm_hw_params *params,
1039 struct snd_soc_dai *dai)
1040 {
1041 struct snd_soc_component *component = dai->component;
1042 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1043 int codec_clk = 0, bypass_pll = 0, fsref, last_clk = 0;
1044 u8 data, j, r, p, pll_q, pll_p = 1, pll_r = 1, pll_j = 1;
1045 u16 d, pll_d = 1;
1046 int clk;
1047 int width = aic3x->slot_width;
1048
1049 if (!width)
1050 width = params_width(params);
1051
1052
1053 data = snd_soc_component_read(component, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4));
1054 switch (width) {
1055 case 16:
1056 break;
1057 case 20:
1058 data |= (0x01 << 4);
1059 break;
1060 case 24:
1061 data |= (0x02 << 4);
1062 break;
1063 case 32:
1064 data |= (0x03 << 4);
1065 break;
1066 }
1067 snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLB, data);
1068
1069
1070 fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
1071
1072
1073
1074 for (pll_q = 2; pll_q < 18; pll_q++)
1075 if (aic3x->sysclk / (128 * pll_q) == fsref) {
1076 bypass_pll = 1;
1077 break;
1078 }
1079
1080 if (bypass_pll) {
1081 pll_q &= 0xf;
1082 snd_soc_component_write(component, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
1083 snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV);
1084
1085 snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0);
1086
1087 } else {
1088 snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV);
1089
1090 snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG,
1091 PLL_ENABLE, PLL_ENABLE);
1092 }
1093
1094
1095
1096 data = (LDAC2LCH | RDAC2RCH);
1097 data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000;
1098 if (params_rate(params) >= 64000)
1099 data |= DUAL_RATE_MODE;
1100 snd_soc_component_write(component, AIC3X_CODEC_DATAPATH_REG, data);
1101
1102
1103 data = (fsref * 20) / params_rate(params);
1104 if (params_rate(params) < 64000)
1105 data /= 2;
1106 data /= 5;
1107 data -= 2;
1108 data |= (data << 4);
1109 snd_soc_component_write(component, AIC3X_SAMPLE_RATE_SEL_REG, data);
1110
1111 if (bypass_pll)
1112 return 0;
1113
1114
1115
1116
1117
1118
1119
1120 codec_clk = (2048 * fsref) / (aic3x->sysclk / 1000);
1121
1122 for (r = 1; r <= 16; r++)
1123 for (p = 1; p <= 8; p++) {
1124 for (j = 4; j <= 55; j++) {
1125
1126
1127
1128
1129 int tmp_clk = (1000 * j * r) / p;
1130
1131
1132
1133
1134 if (abs(codec_clk - tmp_clk) <
1135 abs(codec_clk - last_clk)) {
1136 pll_j = j; pll_d = 0;
1137 pll_r = r; pll_p = p;
1138 last_clk = tmp_clk;
1139 }
1140
1141
1142 if (tmp_clk == codec_clk)
1143 goto found;
1144 }
1145 }
1146
1147
1148 for (p = 1; p <= 8; p++) {
1149 j = codec_clk * p / 1000;
1150
1151 if (j < 4 || j > 11)
1152 continue;
1153
1154
1155 d = ((2048 * p * fsref) - j * aic3x->sysclk)
1156 * 100 / (aic3x->sysclk/100);
1157
1158 clk = (10000 * j + d) / (10 * p);
1159
1160
1161
1162 if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
1163 pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
1164 last_clk = clk;
1165 }
1166
1167
1168 if (clk == codec_clk)
1169 goto found;
1170 }
1171
1172 if (last_clk == 0) {
1173 printk(KERN_ERR "%s(): unable to setup PLL\n", __func__);
1174 return -EINVAL;
1175 }
1176
1177 found:
1178 snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, PLLP_MASK, pll_p);
1179 snd_soc_component_write(component, AIC3X_OVRF_STATUS_AND_PLLR_REG,
1180 pll_r << PLLR_SHIFT);
1181 snd_soc_component_write(component, AIC3X_PLL_PROGB_REG, pll_j << PLLJ_SHIFT);
1182 snd_soc_component_write(component, AIC3X_PLL_PROGC_REG,
1183 (pll_d >> 6) << PLLD_MSB_SHIFT);
1184 snd_soc_component_write(component, AIC3X_PLL_PROGD_REG,
1185 (pll_d & 0x3F) << PLLD_LSB_SHIFT);
1186
1187 return 0;
1188 }
1189
1190 static int aic3x_prepare(struct snd_pcm_substream *substream,
1191 struct snd_soc_dai *dai)
1192 {
1193 struct snd_soc_component *component = dai->component;
1194 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1195 int delay = 0;
1196 int width = aic3x->slot_width;
1197
1198 if (!width)
1199 width = substream->runtime->sample_bits;
1200
1201
1202 if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_A)
1203 delay += (aic3x->tdm_delay*width + 1);
1204 else if (aic3x->dai_fmt == SND_SOC_DAIFMT_DSP_B)
1205 delay += aic3x->tdm_delay*width;
1206
1207
1208 snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLC, delay);
1209
1210 return 0;
1211 }
1212
1213 static int aic3x_mute(struct snd_soc_dai *dai, int mute, int direction)
1214 {
1215 struct snd_soc_component *component = dai->component;
1216 u8 ldac_reg = snd_soc_component_read(component, LDAC_VOL) & ~MUTE_ON;
1217 u8 rdac_reg = snd_soc_component_read(component, RDAC_VOL) & ~MUTE_ON;
1218
1219 if (mute) {
1220 snd_soc_component_write(component, LDAC_VOL, ldac_reg | MUTE_ON);
1221 snd_soc_component_write(component, RDAC_VOL, rdac_reg | MUTE_ON);
1222 } else {
1223 snd_soc_component_write(component, LDAC_VOL, ldac_reg);
1224 snd_soc_component_write(component, RDAC_VOL, rdac_reg);
1225 }
1226
1227 return 0;
1228 }
1229
1230 static int aic3x_set_dai_sysclk(struct snd_soc_dai *codec_dai,
1231 int clk_id, unsigned int freq, int dir)
1232 {
1233 struct snd_soc_component *component = codec_dai->component;
1234 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1235
1236
1237 snd_soc_component_update_bits(component, AIC3X_CLKGEN_CTRL_REG, PLLCLK_IN_MASK,
1238 clk_id << PLLCLK_IN_SHIFT);
1239 snd_soc_component_update_bits(component, AIC3X_CLKGEN_CTRL_REG, CLKDIV_IN_MASK,
1240 clk_id << CLKDIV_IN_SHIFT);
1241
1242 aic3x->sysclk = freq;
1243 return 0;
1244 }
1245
1246 static int aic3x_set_dai_fmt(struct snd_soc_dai *codec_dai,
1247 unsigned int fmt)
1248 {
1249 struct snd_soc_component *component = codec_dai->component;
1250 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1251 u8 iface_areg, iface_breg;
1252
1253 iface_areg = snd_soc_component_read(component, AIC3X_ASD_INTF_CTRLA) & 0x3f;
1254 iface_breg = snd_soc_component_read(component, AIC3X_ASD_INTF_CTRLB) & 0x3f;
1255
1256 switch (fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) {
1257 case SND_SOC_DAIFMT_CBP_CFP:
1258 aic3x->master = 1;
1259 iface_areg |= BIT_CLK_MASTER | WORD_CLK_MASTER;
1260 break;
1261 case SND_SOC_DAIFMT_CBC_CFC:
1262 aic3x->master = 0;
1263 iface_areg &= ~(BIT_CLK_MASTER | WORD_CLK_MASTER);
1264 break;
1265 case SND_SOC_DAIFMT_CBP_CFC:
1266 aic3x->master = 1;
1267 iface_areg |= BIT_CLK_MASTER;
1268 iface_areg &= ~WORD_CLK_MASTER;
1269 break;
1270 case SND_SOC_DAIFMT_CBC_CFP:
1271 aic3x->master = 1;
1272 iface_areg |= WORD_CLK_MASTER;
1273 iface_areg &= ~BIT_CLK_MASTER;
1274 break;
1275 default:
1276 return -EINVAL;
1277 }
1278
1279
1280
1281
1282
1283 switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
1284 SND_SOC_DAIFMT_INV_MASK)) {
1285 case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF):
1286 break;
1287 case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF):
1288 case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
1289 iface_breg |= (0x01 << 6);
1290 break;
1291 case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
1292 iface_breg |= (0x02 << 6);
1293 break;
1294 case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
1295 iface_breg |= (0x03 << 6);
1296 break;
1297 default:
1298 return -EINVAL;
1299 }
1300
1301 aic3x->dai_fmt = fmt & SND_SOC_DAIFMT_FORMAT_MASK;
1302
1303
1304 snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLA, iface_areg);
1305 snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLB, iface_breg);
1306
1307 return 0;
1308 }
1309
1310 static int aic3x_set_dai_tdm_slot(struct snd_soc_dai *codec_dai,
1311 unsigned int tx_mask, unsigned int rx_mask,
1312 int slots, int slot_width)
1313 {
1314 struct snd_soc_component *component = codec_dai->component;
1315 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1316 unsigned int lsb;
1317
1318 if (tx_mask != rx_mask) {
1319 dev_err(component->dev, "tx and rx masks must be symmetric\n");
1320 return -EINVAL;
1321 }
1322
1323 if (unlikely(!tx_mask)) {
1324 dev_err(component->dev, "tx and rx masks need to be non 0\n");
1325 return -EINVAL;
1326 }
1327
1328
1329 lsb = __ffs(tx_mask);
1330 if ((lsb + 1) != __fls(tx_mask)) {
1331 dev_err(component->dev, "Invalid mask, slots must be adjacent\n");
1332 return -EINVAL;
1333 }
1334
1335 switch (slot_width) {
1336 case 16:
1337 case 20:
1338 case 24:
1339 case 32:
1340 break;
1341 default:
1342 dev_err(component->dev, "Unsupported slot width %d\n", slot_width);
1343 return -EINVAL;
1344 }
1345
1346
1347 aic3x->tdm_delay = lsb;
1348 aic3x->slot_width = slot_width;
1349
1350
1351 snd_soc_component_update_bits(component, AIC3X_ASD_INTF_CTRLA,
1352 DOUT_TRISTATE, DOUT_TRISTATE);
1353
1354 return 0;
1355 }
1356
1357 static int aic3x_regulator_event(struct notifier_block *nb,
1358 unsigned long event, void *data)
1359 {
1360 struct aic3x_disable_nb *disable_nb =
1361 container_of(nb, struct aic3x_disable_nb, nb);
1362 struct aic3x_priv *aic3x = disable_nb->aic3x;
1363
1364 if (event & REGULATOR_EVENT_DISABLE) {
1365
1366
1367
1368
1369 if (gpio_is_valid(aic3x->gpio_reset))
1370 gpio_set_value(aic3x->gpio_reset, 0);
1371 regcache_mark_dirty(aic3x->regmap);
1372 }
1373
1374 return 0;
1375 }
1376
1377 static int aic3x_set_power(struct snd_soc_component *component, int power)
1378 {
1379 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1380 unsigned int pll_c, pll_d;
1381 int ret;
1382
1383 if (power) {
1384 ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
1385 aic3x->supplies);
1386 if (ret)
1387 goto out;
1388 aic3x->power = 1;
1389
1390 if (gpio_is_valid(aic3x->gpio_reset)) {
1391 udelay(1);
1392 gpio_set_value(aic3x->gpio_reset, 1);
1393 }
1394
1395
1396 regcache_cache_only(aic3x->regmap, false);
1397 regcache_sync(aic3x->regmap);
1398
1399
1400
1401
1402
1403 pll_c = snd_soc_component_read(component, AIC3X_PLL_PROGC_REG);
1404 pll_d = snd_soc_component_read(component, AIC3X_PLL_PROGD_REG);
1405 if (pll_c == aic3x_reg[AIC3X_PLL_PROGC_REG].def ||
1406 pll_d == aic3x_reg[AIC3X_PLL_PROGD_REG].def) {
1407 snd_soc_component_write(component, AIC3X_PLL_PROGC_REG, pll_c);
1408 snd_soc_component_write(component, AIC3X_PLL_PROGD_REG, pll_d);
1409 }
1410
1411
1412
1413
1414
1415 mdelay(50);
1416 } else {
1417
1418
1419
1420
1421
1422 snd_soc_component_write(component, AIC3X_RESET, SOFT_RESET);
1423 regcache_mark_dirty(aic3x->regmap);
1424 aic3x->power = 0;
1425
1426 regcache_cache_only(aic3x->regmap, true);
1427 ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies),
1428 aic3x->supplies);
1429 }
1430 out:
1431 return ret;
1432 }
1433
1434 static int aic3x_set_bias_level(struct snd_soc_component *component,
1435 enum snd_soc_bias_level level)
1436 {
1437 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1438
1439 switch (level) {
1440 case SND_SOC_BIAS_ON:
1441 break;
1442 case SND_SOC_BIAS_PREPARE:
1443 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_STANDBY &&
1444 aic3x->master) {
1445
1446 snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG,
1447 PLL_ENABLE, PLL_ENABLE);
1448 }
1449 break;
1450 case SND_SOC_BIAS_STANDBY:
1451 if (!aic3x->power)
1452 aic3x_set_power(component, 1);
1453 if (snd_soc_component_get_bias_level(component) == SND_SOC_BIAS_PREPARE &&
1454 aic3x->master) {
1455
1456 snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG,
1457 PLL_ENABLE, 0);
1458 }
1459 break;
1460 case SND_SOC_BIAS_OFF:
1461 if (aic3x->power)
1462 aic3x_set_power(component, 0);
1463 break;
1464 }
1465
1466 return 0;
1467 }
1468
1469 #define AIC3X_RATES SNDRV_PCM_RATE_8000_96000
1470 #define AIC3X_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
1471 SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_S24_LE | \
1472 SNDRV_PCM_FMTBIT_S32_LE)
1473
1474 static const struct snd_soc_dai_ops aic3x_dai_ops = {
1475 .hw_params = aic3x_hw_params,
1476 .prepare = aic3x_prepare,
1477 .mute_stream = aic3x_mute,
1478 .set_sysclk = aic3x_set_dai_sysclk,
1479 .set_fmt = aic3x_set_dai_fmt,
1480 .set_tdm_slot = aic3x_set_dai_tdm_slot,
1481 .no_capture_mute = 1,
1482 };
1483
1484 static struct snd_soc_dai_driver aic3x_dai = {
1485 .name = "tlv320aic3x-hifi",
1486 .playback = {
1487 .stream_name = "Playback",
1488 .channels_min = 2,
1489 .channels_max = 2,
1490 .rates = AIC3X_RATES,
1491 .formats = AIC3X_FORMATS,},
1492 .capture = {
1493 .stream_name = "Capture",
1494 .channels_min = 2,
1495 .channels_max = 2,
1496 .rates = AIC3X_RATES,
1497 .formats = AIC3X_FORMATS,},
1498 .ops = &aic3x_dai_ops,
1499 .symmetric_rate = 1,
1500 };
1501
1502 static void aic3x_mono_init(struct snd_soc_component *component)
1503 {
1504
1505 snd_soc_component_write(component, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1506 snd_soc_component_write(component, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1507
1508
1509 snd_soc_component_update_bits(component, MONOLOPM_CTRL, UNMUTE, UNMUTE);
1510
1511
1512 snd_soc_component_write(component, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
1513 snd_soc_component_write(component, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
1514
1515
1516 snd_soc_component_write(component, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
1517 snd_soc_component_write(component, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
1518 }
1519
1520
1521
1522
1523
1524 static int aic3x_init(struct snd_soc_component *component)
1525 {
1526 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1527
1528 snd_soc_component_write(component, AIC3X_PAGE_SELECT, PAGE0_SELECT);
1529 snd_soc_component_write(component, AIC3X_RESET, SOFT_RESET);
1530
1531
1532 snd_soc_component_write(component, LDAC_VOL, DEFAULT_VOL | MUTE_ON);
1533 snd_soc_component_write(component, RDAC_VOL, DEFAULT_VOL | MUTE_ON);
1534
1535
1536 snd_soc_component_write(component, DACL1_2_HPLOUT_VOL, DEFAULT_VOL | ROUTE_ON);
1537 snd_soc_component_write(component, DACR1_2_HPROUT_VOL, DEFAULT_VOL | ROUTE_ON);
1538 snd_soc_component_write(component, DACL1_2_HPLCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1539 snd_soc_component_write(component, DACR1_2_HPRCOM_VOL, DEFAULT_VOL | ROUTE_ON);
1540
1541 snd_soc_component_write(component, DACL1_2_LLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1542 snd_soc_component_write(component, DACR1_2_RLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
1543
1544
1545 snd_soc_component_update_bits(component, LLOPM_CTRL, UNMUTE, UNMUTE);
1546 snd_soc_component_update_bits(component, RLOPM_CTRL, UNMUTE, UNMUTE);
1547 snd_soc_component_update_bits(component, HPLOUT_CTRL, UNMUTE, UNMUTE);
1548 snd_soc_component_update_bits(component, HPROUT_CTRL, UNMUTE, UNMUTE);
1549 snd_soc_component_update_bits(component, HPLCOM_CTRL, UNMUTE, UNMUTE);
1550 snd_soc_component_update_bits(component, HPRCOM_CTRL, UNMUTE, UNMUTE);
1551
1552
1553 snd_soc_component_write(component, LADC_VOL, DEFAULT_GAIN);
1554 snd_soc_component_write(component, RADC_VOL, DEFAULT_GAIN);
1555
1556 snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x0);
1557 snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x0);
1558
1559
1560 snd_soc_component_write(component, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
1561 snd_soc_component_write(component, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
1562 snd_soc_component_write(component, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
1563 snd_soc_component_write(component, PGAR_2_HPRCOM_VOL, DEFAULT_VOL);
1564
1565 snd_soc_component_write(component, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
1566 snd_soc_component_write(component, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
1567
1568
1569 if (aic3x->model != AIC3X_MODEL_3104) {
1570
1571 snd_soc_component_write(component, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
1572 snd_soc_component_write(component, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
1573 snd_soc_component_write(component, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
1574 snd_soc_component_write(component, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL);
1575
1576 snd_soc_component_write(component, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
1577 snd_soc_component_write(component, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
1578 }
1579
1580 switch (aic3x->model) {
1581 case AIC3X_MODEL_3X:
1582 case AIC3X_MODEL_33:
1583 case AIC3X_MODEL_3106:
1584 aic3x_mono_init(component);
1585 break;
1586 case AIC3X_MODEL_3007:
1587 snd_soc_component_write(component, CLASSD_CTRL, 0);
1588 break;
1589 }
1590
1591
1592 snd_soc_component_update_bits(component, HPOUT_SC, HPOUT_SC_OCMV_MASK,
1593 aic3x->ocmv << HPOUT_SC_OCMV_SHIFT);
1594
1595 return 0;
1596 }
1597
1598 static bool aic3x_is_shared_reset(struct aic3x_priv *aic3x)
1599 {
1600 struct aic3x_priv *a;
1601
1602 list_for_each_entry(a, &reset_list, list) {
1603 if (gpio_is_valid(aic3x->gpio_reset) &&
1604 aic3x->gpio_reset == a->gpio_reset)
1605 return true;
1606 }
1607
1608 return false;
1609 }
1610
1611 static int aic3x_component_probe(struct snd_soc_component *component)
1612 {
1613 struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
1614 int ret, i;
1615
1616 aic3x->component = component;
1617
1618 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++) {
1619 aic3x->disable_nb[i].nb.notifier_call = aic3x_regulator_event;
1620 aic3x->disable_nb[i].aic3x = aic3x;
1621 ret = devm_regulator_register_notifier(
1622 aic3x->supplies[i].consumer,
1623 &aic3x->disable_nb[i].nb);
1624 if (ret) {
1625 dev_err(component->dev,
1626 "Failed to request regulator notifier: %d\n",
1627 ret);
1628 return ret;
1629 }
1630 }
1631
1632 regcache_mark_dirty(aic3x->regmap);
1633 aic3x_init(component);
1634
1635 if (aic3x->setup) {
1636 if (aic3x->model != AIC3X_MODEL_3104) {
1637
1638 snd_soc_component_write(component, AIC3X_GPIO1_REG,
1639 (aic3x->setup->gpio_func[0] & 0xf) << 4);
1640 snd_soc_component_write(component, AIC3X_GPIO2_REG,
1641 (aic3x->setup->gpio_func[1] & 0xf) << 4);
1642 } else {
1643 dev_warn(component->dev, "GPIO functionality is not supported on tlv320aic3104\n");
1644 }
1645 }
1646
1647 switch (aic3x->model) {
1648 case AIC3X_MODEL_3X:
1649 case AIC3X_MODEL_33:
1650 case AIC3X_MODEL_3106:
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, aic3x_mono_controls,
1654 ARRAY_SIZE(aic3x_mono_controls));
1655 break;
1656 case AIC3X_MODEL_3007:
1657 snd_soc_add_component_controls(component, aic3x_extra_snd_controls,
1658 ARRAY_SIZE(aic3x_extra_snd_controls));
1659 snd_soc_add_component_controls(component,
1660 &aic3x_classd_amp_gain_ctrl, 1);
1661 break;
1662 case AIC3X_MODEL_3104:
1663 break;
1664 }
1665
1666
1667 switch (aic3x->micbias_vg) {
1668 case AIC3X_MICBIAS_2_0V:
1669 case AIC3X_MICBIAS_2_5V:
1670 case AIC3X_MICBIAS_AVDDV:
1671 snd_soc_component_update_bits(component, MICBIAS_CTRL,
1672 MICBIAS_LEVEL_MASK,
1673 (aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT);
1674 break;
1675 case AIC3X_MICBIAS_OFF:
1676
1677
1678
1679
1680
1681 break;
1682 }
1683
1684 aic3x_add_widgets(component);
1685
1686 return 0;
1687 }
1688
1689 static const struct snd_soc_component_driver soc_component_dev_aic3x = {
1690 .set_bias_level = aic3x_set_bias_level,
1691 .probe = aic3x_component_probe,
1692 .controls = aic3x_snd_controls,
1693 .num_controls = ARRAY_SIZE(aic3x_snd_controls),
1694 .dapm_widgets = aic3x_dapm_widgets,
1695 .num_dapm_widgets = ARRAY_SIZE(aic3x_dapm_widgets),
1696 .dapm_routes = intercon,
1697 .num_dapm_routes = ARRAY_SIZE(intercon),
1698 .use_pmdown_time = 1,
1699 .endianness = 1,
1700 };
1701
1702 static void aic3x_configure_ocmv(struct device *dev, struct aic3x_priv *aic3x)
1703 {
1704 struct device_node *np = dev->of_node;
1705 u32 value;
1706 int dvdd, avdd;
1707
1708 if (np && !of_property_read_u32(np, "ai3x-ocmv", &value)) {
1709
1710 if (value <= 3) {
1711 aic3x->ocmv = value;
1712 return;
1713 }
1714 }
1715
1716 dvdd = regulator_get_voltage(aic3x->supplies[1].consumer);
1717 avdd = regulator_get_voltage(aic3x->supplies[2].consumer);
1718
1719 if (avdd > 3600000 || dvdd > 1950000) {
1720 dev_warn(dev,
1721 "Too high supply voltage(s) AVDD: %d, DVDD: %d\n",
1722 avdd, dvdd);
1723 } else if (avdd == 3600000 && dvdd == 1950000) {
1724 aic3x->ocmv = HPOUT_SC_OCMV_1_8V;
1725 } else if (avdd > 3300000 && dvdd > 1800000) {
1726 aic3x->ocmv = HPOUT_SC_OCMV_1_65V;
1727 } else if (avdd > 3000000 && dvdd > 1650000) {
1728 aic3x->ocmv = HPOUT_SC_OCMV_1_5V;
1729 } else if (avdd >= 2700000 && dvdd >= 1525000) {
1730 aic3x->ocmv = HPOUT_SC_OCMV_1_35V;
1731 } else {
1732 dev_warn(dev,
1733 "Invalid supply voltage(s) AVDD: %d, DVDD: %d\n",
1734 avdd, dvdd);
1735 }
1736 }
1737
1738
1739 static const struct reg_sequence aic3007_class_d[] = {
1740
1741 { AIC3X_PAGE_SELECT, 0x0D },
1742 { 0xD, 0x0D },
1743 { 0x8, 0x5C },
1744 { 0x8, 0x5D },
1745 { 0x8, 0x5C },
1746 { AIC3X_PAGE_SELECT, 0x00 },
1747 };
1748
1749 int aic3x_probe(struct device *dev, struct regmap *regmap, kernel_ulong_t driver_data)
1750 {
1751 struct aic3x_pdata *pdata = dev->platform_data;
1752 struct aic3x_priv *aic3x;
1753 struct aic3x_setup_data *ai3x_setup;
1754 struct device_node *np = dev->of_node;
1755 int ret, i;
1756 u32 value;
1757
1758 aic3x = devm_kzalloc(dev, sizeof(struct aic3x_priv), GFP_KERNEL);
1759 if (!aic3x)
1760 return -ENOMEM;
1761
1762 aic3x->regmap = regmap;
1763 if (IS_ERR(aic3x->regmap)) {
1764 ret = PTR_ERR(aic3x->regmap);
1765 return ret;
1766 }
1767
1768 regcache_cache_only(aic3x->regmap, true);
1769
1770 dev_set_drvdata(dev, aic3x);
1771 if (pdata) {
1772 aic3x->gpio_reset = pdata->gpio_reset;
1773 aic3x->setup = pdata->setup;
1774 aic3x->micbias_vg = pdata->micbias_vg;
1775 } else if (np) {
1776 ai3x_setup = devm_kzalloc(dev, sizeof(*ai3x_setup), GFP_KERNEL);
1777 if (!ai3x_setup)
1778 return -ENOMEM;
1779
1780 ret = of_get_named_gpio(np, "reset-gpios", 0);
1781 if (ret >= 0) {
1782 aic3x->gpio_reset = ret;
1783 } else {
1784 ret = of_get_named_gpio(np, "gpio-reset", 0);
1785 if (ret > 0) {
1786 dev_warn(dev, "Using deprecated property \"gpio-reset\", please update your DT");
1787 aic3x->gpio_reset = ret;
1788 } else {
1789 aic3x->gpio_reset = -1;
1790 }
1791 }
1792
1793 if (of_property_read_u32_array(np, "ai3x-gpio-func",
1794 ai3x_setup->gpio_func, 2) >= 0) {
1795 aic3x->setup = ai3x_setup;
1796 }
1797
1798 if (!of_property_read_u32(np, "ai3x-micbias-vg", &value)) {
1799 switch (value) {
1800 case 1 :
1801 aic3x->micbias_vg = AIC3X_MICBIAS_2_0V;
1802 break;
1803 case 2 :
1804 aic3x->micbias_vg = AIC3X_MICBIAS_2_5V;
1805 break;
1806 case 3 :
1807 aic3x->micbias_vg = AIC3X_MICBIAS_AVDDV;
1808 break;
1809 default :
1810 aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
1811 dev_err(dev, "Unsuitable MicBias voltage "
1812 "found in DT\n");
1813 }
1814 } else {
1815 aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
1816 }
1817
1818 } else {
1819 aic3x->gpio_reset = -1;
1820 }
1821
1822 aic3x->model = driver_data;
1823
1824 if (gpio_is_valid(aic3x->gpio_reset) &&
1825 !aic3x_is_shared_reset(aic3x)) {
1826 ret = gpio_request(aic3x->gpio_reset, "tlv320aic3x reset");
1827 if (ret != 0)
1828 goto err;
1829 gpio_direction_output(aic3x->gpio_reset, 0);
1830 }
1831
1832 for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
1833 aic3x->supplies[i].supply = aic3x_supply_names[i];
1834
1835 ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(aic3x->supplies),
1836 aic3x->supplies);
1837 if (ret != 0) {
1838 dev_err(dev, "Failed to request supplies: %d\n", ret);
1839 goto err_gpio;
1840 }
1841
1842 aic3x_configure_ocmv(dev, aic3x);
1843
1844 if (aic3x->model == AIC3X_MODEL_3007) {
1845 ret = regmap_register_patch(aic3x->regmap, aic3007_class_d,
1846 ARRAY_SIZE(aic3007_class_d));
1847 if (ret != 0)
1848 dev_err(dev, "Failed to init class D: %d\n",
1849 ret);
1850 }
1851
1852 ret = devm_snd_soc_register_component(dev, &soc_component_dev_aic3x, &aic3x_dai, 1);
1853
1854 if (ret != 0)
1855 goto err_gpio;
1856
1857 INIT_LIST_HEAD(&aic3x->list);
1858 list_add(&aic3x->list, &reset_list);
1859
1860 return 0;
1861
1862 err_gpio:
1863 if (gpio_is_valid(aic3x->gpio_reset) &&
1864 !aic3x_is_shared_reset(aic3x))
1865 gpio_free(aic3x->gpio_reset);
1866 err:
1867 return ret;
1868 }
1869 EXPORT_SYMBOL(aic3x_probe);
1870
1871 void aic3x_remove(struct device *dev)
1872 {
1873 struct aic3x_priv *aic3x = dev_get_drvdata(dev);
1874
1875 list_del(&aic3x->list);
1876
1877 if (gpio_is_valid(aic3x->gpio_reset) &&
1878 !aic3x_is_shared_reset(aic3x)) {
1879 gpio_set_value(aic3x->gpio_reset, 0);
1880 gpio_free(aic3x->gpio_reset);
1881 }
1882 }
1883 EXPORT_SYMBOL(aic3x_remove);
1884
1885 MODULE_DESCRIPTION("ASoC TLV320AIC3X codec driver");
1886 MODULE_AUTHOR("Vladimir Barinov");
1887 MODULE_LICENSE("GPL");