#define AIC3X_NUM_SUPPLIES 4 staticconstchar *aic3x_supply_names[AIC3X_NUM_SUPPLIES] = { "IOVDD", /* I/O Voltage */ "DVDD", /* Digital Core Voltage */ "AVDD", /* Analog DAC Voltage */ "DRVDD", /* ADC Analog and Output Driver Voltage */
};
/* * mic bias power on/off share the same register bits with * output voltage of mic bias. when power on mic bias, we * need reclaim it to voltage value. * 0x0 = Powered off * 0x1 = MICBIAS output is powered to 2.0V, * 0x2 = MICBIAS output is powered to 2.5V * 0x3 = MICBIAS output is connected to AVDD
*/ staticint mic_bias_event(struct snd_soc_dapm_widget *w, struct snd_kcontrol *kcontrol, int event)
{ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
switch (event) { case SND_SOC_DAPM_POST_PMU: /* change mic bias voltage to user defined */
snd_soc_component_update_bits(component, MICBIAS_CTRL,
MICBIAS_LEVEL_MASK,
aic3x->micbias_vg << MICBIAS_LEVEL_SHIFT); break;
/* * DAC digital volumes. From -63.5 to 0 dB in 0.5 dB steps
*/ static DECLARE_TLV_DB_SCALE(dac_tlv, -6350, 50, 0); /* ADC PGA gain volumes. From 0 to 59.5 dB in 0.5 dB steps */ static DECLARE_TLV_DB_SCALE(adc_tlv, 0, 50, 0); /* * Output stage volumes. From -78.3 to 0 dB. Muted below -78.3 dB. * Step size is approximately 0.5 dB over most of the scale but increasing * near the very low levels. * Define dB scale so that it is mostly correct for range about -55 to 0 dB * but having increasing dB difference below that (and where it doesn't count * so much). This setting shows -50 dB (actual is -50.3 dB) for register * value 100 and -58.5 dB (actual is -78.3 dB) for register value 117.
*/ static DECLARE_TLV_DB_SCALE(output_stage_tlv, -5900, 50, 1);
/* Output volumes. From 0 to 9 dB in 1 dB steps */ staticconst DECLARE_TLV_DB_SCALE(out_tlv, 0, 100, 0);
/* * Output controls that map to output mixer switches. Note these are * only for swapped L-to-R and R-to-L routes. See below stereo controls * for direct L-to-L and R-to-R routes.
*/
SOC_SINGLE_TLV("Left Line Mixer PGAR Bypass Volume",
PGAR_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
SOC_SINGLE_TLV("Left Line Mixer DACR1 Playback Volume",
DACR1_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
/* * Note: enable Automatic input Gain Controller with care. It can * adjust PGA to max value when ADC is on and will never go back.
*/
SOC_DOUBLE_R("AGC Switch", LAGC_CTRL_A, RAGC_CTRL_A, 7, 0x01, 0),
SOC_ENUM("Left AGC Target level", aic3x_lagc_level_enum),
SOC_ENUM("Right AGC Target level", aic3x_ragc_level_enum),
SOC_ENUM("Left AGC Attack time", aic3x_lagc_attack_enum),
SOC_ENUM("Right AGC Attack time", aic3x_ragc_attack_enum),
SOC_ENUM("Left AGC Decay time", aic3x_lagc_decay_enum),
SOC_ENUM("Right AGC Decay time", aic3x_ragc_decay_enum),
/* For other than tlv320aic3104 */ staticconststruct snd_kcontrol_new aic3x_extra_snd_controls[] = { /* * Output controls that map to output mixer switches. Note these are * only for swapped L-to-R and R-to-L routes. See below stereo controls * for direct L-to-L and R-to-R routes.
*/
SOC_SINGLE_TLV("Left Line Mixer Line2R Bypass Volume",
LINE2R_2_LLOPM_VOL, 0, 118, 1, output_stage_tlv),
/* * Virtual output pin to detection block inside codec. This can be * used to keep codec bias on if gpio or detection features are needed. * Force pin on or construct a path with an input jack and mic bias * widgets.
*/
SND_SOC_DAPM_OUTPUT("Detection"),
};
/* For other than tlv320aic3104 */ staticconststruct snd_soc_dapm_widget aic3x_extra_dapm_widgets[] = { /* Inputs to Left ADC */
SND_SOC_DAPM_MIXER("Left PGA Mixer", SND_SOC_NOPM, 0, 0,
&aic3x_left_pga_mixer_controls[0],
ARRAY_SIZE(aic3x_left_pga_mixer_controls)),
SND_SOC_DAPM_MUX("Left Line2L Mux", SND_SOC_NOPM, 0, 0,
&aic3x_left_line2_mux_controls),
/* * Not a real mic bias widget but similar function. This is for dynamic * control of GPIO1 digital mic modulator clock output function when * using digital mic.
*/
SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "GPIO1 dmic modclk",
AIC3X_GPIO1_REG, 4, 0xf,
AIC3X_GPIO1_FUNC_DIGITAL_MIC_MODCLK,
AIC3X_GPIO1_FUNC_DISABLED),
/* * Also similar function like mic bias. Selects digital mic with * configurable oversampling rate instead of ADC converter.
*/
SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 128",
AIC3X_ASD_INTF_CTRLA, 0, 3, 1, 0),
SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 64",
AIC3X_ASD_INTF_CTRLA, 0, 3, 2, 0),
SND_SOC_DAPM_REG(snd_soc_dapm_micbias, "DMic Rate 32",
AIC3X_ASD_INTF_CTRLA, 0, 3, 3, 0),
/* select data word length */
data = snd_soc_component_read(component, AIC3X_ASD_INTF_CTRLB) & (~(0x3 << 4)); switch (width) { case 16: break; case 20:
data |= (0x01 << 4); break; case 24:
data |= (0x02 << 4); break; case 32:
data |= (0x03 << 4); break;
}
snd_soc_component_write(component, AIC3X_ASD_INTF_CTRLB, data);
/* Fsref can be 44100 or 48000 */
fsref = (params_rate(params) % 11025 == 0) ? 44100 : 48000;
/* Try to find a value for Q which allows us to bypass the PLL and
* generate CODEC_CLK directly. */ for (pll_q = 2; pll_q < 18; pll_q++) if (aic3x->sysclk / (128 * pll_q) == fsref) {
bypass_pll = 1; break;
}
if (bypass_pll) {
pll_q &= 0xf;
snd_soc_component_write(component, AIC3X_PLL_PROGA_REG, pll_q << PLLQ_SHIFT);
snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_CLKDIV); /* disable PLL if it is bypassed */
snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG, PLL_ENABLE, 0);
} else {
snd_soc_component_write(component, AIC3X_GPIOB_REG, CODEC_CLKIN_PLLDIV); /* enable PLL when it is used */
snd_soc_component_update_bits(component, AIC3X_PLL_PROGA_REG,
PLL_ENABLE, PLL_ENABLE);
}
/* Route Left DAC to left channel input and
* right DAC to right channel input */
data = (LDAC2LCH | RDAC2RCH);
data |= (fsref == 44100) ? FSREF_44100 : FSREF_48000; if (params_rate(params) >= 64000)
data |= DUAL_RATE_MODE;
snd_soc_component_write(component, AIC3X_CODEC_DATAPATH_REG, data);
/* codec sample rate select */
data = (fsref * 20) / params_rate(params); if (params_rate(params) < 64000)
data /= 2;
data /= 5;
data -= 2;
data |= (data << 4);
snd_soc_component_write(component, AIC3X_SAMPLE_RATE_SEL_REG, data);
if (bypass_pll) return 0;
/* Use PLL, compute appropriate setup for j, d, r and p, the closest * one wins the game. Try with d==0 first, next with d!=0. * Constraints for j are according to the datasheet. * The sysclk is divided by 1000 to prevent integer overflows.
*/
for (r = 1; r <= 16; r++) for (p = 1; p <= 8; p++) { for (j = 4; j <= 55; j++) { /* This is actually 1000*((j+(d/10000))*r)/p * The term had to be converted to get * rid of the division by 10000; d = 0 here
*/ int tmp_clk = (1000 * j * r) / p;
/* Check whether this values get closer than * the best ones we had before
*/ if (abs(codec_clk - tmp_clk) <
abs(codec_clk - last_clk)) {
pll_j = j; pll_d = 0;
pll_r = r; pll_p = p;
last_clk = tmp_clk;
}
/* Early exit for exact matches */ if (tmp_clk == codec_clk) goto found;
}
}
/* try with d != 0 */ for (p = 1; p <= 8; p++) {
j = codec_clk * p / 1000;
if (j < 4 || j > 11) continue;
/* do not use codec_clk here since we'd loose precision */
d = ((2048 * p * fsref) - j * aic3x->sysclk)
* 100 / (aic3x->sysclk/100);
clk = (10000 * j + d) / (10 * p);
/* check whether this values get closer than the best
* ones we had before */ if (abs(codec_clk - clk) < abs(codec_clk - last_clk)) {
pll_j = j; pll_d = d; pll_r = 1; pll_p = p;
last_clk = clk;
}
/* Early exit for exact matches */ if (clk == codec_clk) goto found;
}
if (last_clk == 0) {
printk(KERN_ERR "%s(): unable to setup PLL\n", __func__); return -EINVAL;
}
/* * match both interface format and signal polarities since they * are fixed
*/ switch (fmt & (SND_SOC_DAIFMT_FORMAT_MASK |
SND_SOC_DAIFMT_INV_MASK)) { case (SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF): break; case (SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_IB_NF): case (SND_SOC_DAIFMT_DSP_B | SND_SOC_DAIFMT_IB_NF):
iface_breg |= (0x01 << 6); break; case (SND_SOC_DAIFMT_RIGHT_J | SND_SOC_DAIFMT_NB_NF):
iface_breg |= (0x02 << 6); break; case (SND_SOC_DAIFMT_LEFT_J | SND_SOC_DAIFMT_NB_NF):
iface_breg |= (0x03 << 6); break; default: return -EINVAL;
}
if (tx_mask != rx_mask) {
dev_err(component->dev, "tx and rx masks must be symmetric\n"); return -EINVAL;
}
if (unlikely(!tx_mask)) {
dev_err(component->dev, "tx and rx masks need to be non 0\n"); return -EINVAL;
}
/* TDM based on DSP mode requires slots to be adjacent */
lsb = __ffs(tx_mask); if ((lsb + 1) != __fls(tx_mask)) {
dev_err(component->dev, "Invalid mask, slots must be adjacent\n"); return -EINVAL;
}
switch (slot_width) { case 16: case 20: case 24: case 32: break; default:
dev_err(component->dev, "Unsupported slot width %d\n", slot_width); return -EINVAL;
}
if (event & REGULATOR_EVENT_DISABLE) { /* * Put codec to reset and require cache sync as at least one * of the supplies was disabled
*/ if (aic3x->gpio_reset)
gpiod_set_value(aic3x->gpio_reset, 1);
regcache_mark_dirty(aic3x->regmap);
}
return 0;
}
staticint aic3x_set_power(struct snd_soc_component *component, int power)
{ struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component); unsignedint pll_c, pll_d; int ret;
if (power) {
ret = regulator_bulk_enable(ARRAY_SIZE(aic3x->supplies),
aic3x->supplies); if (ret) goto out;
aic3x->power = 1;
if (aic3x->gpio_reset) {
udelay(1);
gpiod_set_value(aic3x->gpio_reset, 0);
}
if (aic3x->model == AIC3X_MODEL_3007)
regmap_multi_reg_write_bypassed(aic3x->regmap, aic3007_class_d,
ARRAY_SIZE(aic3007_class_d));
/* Sync reg_cache with the hardware */
regcache_cache_only(aic3x->regmap, false);
regcache_sync(aic3x->regmap);
/* Rewrite paired PLL D registers in case cached sync skipped * writing one of them and thus caused other one also not * being written
*/
pll_c = snd_soc_component_read(component, AIC3X_PLL_PROGC_REG);
pll_d = snd_soc_component_read(component, AIC3X_PLL_PROGD_REG); if (pll_c == aic3x_reg[AIC3X_PLL_PROGC_REG].def ||
pll_d == aic3x_reg[AIC3X_PLL_PROGD_REG].def) {
snd_soc_component_write(component, AIC3X_PLL_PROGC_REG, pll_c);
snd_soc_component_write(component, AIC3X_PLL_PROGD_REG, pll_d);
}
/* * Delay is needed to reduce pop-noise after syncing back the * registers
*/
mdelay(50);
} else { /* * Do soft reset to this codec instance in order to clear * possible VDD leakage currents in case the supply regulators * remain on
*/
snd_soc_component_write(component, AIC3X_RESET, SOFT_RESET);
regcache_mark_dirty(aic3x->regmap);
aic3x->power = 0; /* HW writes are needless when bias is off */
regcache_cache_only(aic3x->regmap, true);
ret = regulator_bulk_disable(ARRAY_SIZE(aic3x->supplies),
aic3x->supplies);
}
out: return ret;
}
staticvoid aic3x_mono_init(struct snd_soc_component *component)
{ /* DAC to Mono Line Out default volume and route to Output mixer */
snd_soc_component_write(component, DACL1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
snd_soc_component_write(component, DACR1_2_MONOLOPM_VOL, DEFAULT_VOL | ROUTE_ON);
/* unmute all outputs */
snd_soc_component_update_bits(component, MONOLOPM_CTRL, UNMUTE, UNMUTE);
/* PGA to Mono Line Out default volume, disconnect from Output Mixer */
snd_soc_component_write(component, PGAL_2_MONOLOPM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, PGAR_2_MONOLOPM_VOL, DEFAULT_VOL);
/* Line2 to Mono Out default volume, disconnect from Output Mixer */
snd_soc_component_write(component, LINE2L_2_MONOLOPM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, LINE2R_2_MONOLOPM_VOL, DEFAULT_VOL);
}
/* * initialise the AIC3X driver * register the mixer and dsp interfaces with the kernel
*/ staticint aic3x_init(struct snd_soc_component *component)
{ struct aic3x_priv *aic3x = snd_soc_component_get_drvdata(component);
/* ADC default volume and unmute */
snd_soc_component_write(component, LADC_VOL, DEFAULT_GAIN);
snd_soc_component_write(component, RADC_VOL, DEFAULT_GAIN); /* By default route Line1 to ADC PGA mixer */
snd_soc_component_write(component, LINE1L_2_LADC_CTRL, 0x0);
snd_soc_component_write(component, LINE1R_2_RADC_CTRL, 0x0);
/* PGA to HP Bypass default volume, disconnect from Output Mixer */
snd_soc_component_write(component, PGAL_2_HPLOUT_VOL, DEFAULT_VOL);
snd_soc_component_write(component, PGAR_2_HPROUT_VOL, DEFAULT_VOL);
snd_soc_component_write(component, PGAL_2_HPLCOM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, PGAR_2_HPRCOM_VOL, DEFAULT_VOL); /* PGA to Line Out default volume, disconnect from Output Mixer */
snd_soc_component_write(component, PGAL_2_LLOPM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, PGAR_2_RLOPM_VOL, DEFAULT_VOL);
/* On tlv320aic3104, these registers are reserved and must not be written */ if (aic3x->model != AIC3X_MODEL_3104) { /* Line2 to HP Bypass default volume, disconnect from Output Mixer */
snd_soc_component_write(component, LINE2L_2_HPLOUT_VOL, DEFAULT_VOL);
snd_soc_component_write(component, LINE2R_2_HPROUT_VOL, DEFAULT_VOL);
snd_soc_component_write(component, LINE2L_2_HPLCOM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, LINE2R_2_HPRCOM_VOL, DEFAULT_VOL); /* Line2 Line Out default volume, disconnect from Output Mixer */
snd_soc_component_write(component, LINE2L_2_LLOPM_VOL, DEFAULT_VOL);
snd_soc_component_write(component, LINE2R_2_RLOPM_VOL, DEFAULT_VOL);
}
switch (aic3x->model) { case AIC3X_MODEL_3X: case AIC3X_MODEL_33: case AIC3X_MODEL_3106:
aic3x_mono_init(component); break; case AIC3X_MODEL_3007:
snd_soc_component_write(component, CLASSD_CTRL, 0); break;
}
/* Output common-mode voltage = 1.5 V */
snd_soc_component_update_bits(component, HPOUT_SC, HPOUT_SC_OCMV_MASK,
aic3x->ocmv << HPOUT_SC_OCMV_SHIFT);
if (aic3x->setup) { if (aic3x->model != AIC3X_MODEL_3104) { /* setup GPIO functions */
snd_soc_component_write(component, AIC3X_GPIO1_REG,
(aic3x->setup->gpio_func[0] & 0xf) << 4);
snd_soc_component_write(component, AIC3X_GPIO2_REG,
(aic3x->setup->gpio_func[1] & 0xf) << 4);
} else {
dev_warn(component->dev, "GPIO functionality is not supported on tlv320aic3104\n");
}
}
switch (aic3x->model) { case AIC3X_MODEL_3X: case AIC3X_MODEL_33: case AIC3X_MODEL_3106:
snd_soc_add_component_controls(component, aic3x_extra_snd_controls,
ARRAY_SIZE(aic3x_extra_snd_controls));
snd_soc_add_component_controls(component, aic3x_mono_controls,
ARRAY_SIZE(aic3x_mono_controls)); break; case AIC3X_MODEL_3007:
snd_soc_add_component_controls(component, aic3x_extra_snd_controls,
ARRAY_SIZE(aic3x_extra_snd_controls));
snd_soc_add_component_controls(component,
&aic3x_classd_amp_gain_ctrl, 1); break; case AIC3X_MODEL_3104: break;
}
/* set mic bias voltage */ switch (aic3x->micbias_vg) { case AIC3X_MICBIAS_2_0V: case AIC3X_MICBIAS_2_5V: case AIC3X_MICBIAS_AVDDV:
snd_soc_component_update_bits(component, MICBIAS_CTRL,
MICBIAS_LEVEL_MASK,
(aic3x->micbias_vg) << MICBIAS_LEVEL_SHIFT); break; case AIC3X_MICBIAS_OFF: /* * noting to do. target won't enter here. This is just to avoid * compile time warning "warning: enumeration value * 'AIC3X_MICBIAS_OFF' not handled in switch"
*/ break;
}
if (!of_property_read_u32(np, "ai3x-micbias-vg", &value)) { switch (value) { case 1 :
aic3x->micbias_vg = AIC3X_MICBIAS_2_0V; break; case 2 :
aic3x->micbias_vg = AIC3X_MICBIAS_2_5V; break; case 3 :
aic3x->micbias_vg = AIC3X_MICBIAS_AVDDV; break; default :
aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
dev_err(dev, "Unsuitable MicBias voltage " "found in DT\n");
}
} else {
aic3x->micbias_vg = AIC3X_MICBIAS_OFF;
}
}
aic3x->model = driver_data;
aic3x->gpio_reset = devm_gpiod_get_optional(dev, "reset",
GPIOD_OUT_HIGH);
ret = PTR_ERR_OR_ZERO(aic3x->gpio_reset); if (ret) { if (ret != -EBUSY) return ret;
/* * Apparently there are setups where the codec is sharing * its reset line. Try to get it non-exclusively, although * the utility of this is unclear: how do we make sure that * resetting one chip will not disturb the others that share * the same line?
*/
aic3x->gpio_reset = devm_gpiod_get(dev, "reset",
GPIOD_ASIS | GPIOD_FLAGS_BIT_NONEXCLUSIVE);
ret = PTR_ERR_OR_ZERO(aic3x->gpio_reset); if (ret) return ret;
for (i = 0; i < ARRAY_SIZE(aic3x->supplies); i++)
aic3x->supplies[i].supply = aic3x_supply_names[i];
ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(aic3x->supplies),
aic3x->supplies); if (ret) return dev_err_probe(dev, ret, "Failed to request supplies\n");
aic3x_configure_ocmv(dev, aic3x);
ret = devm_snd_soc_register_component(dev, &soc_component_dev_aic3x, &aic3x_dai, 1); if (ret) return ret;
/* Leave the codec in reset state */ if (aic3x->gpio_reset && !aic3x->shared_reset)
gpiod_set_value(aic3x->gpio_reset, 1);
}
EXPORT_SYMBOL(aic3x_remove);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.