Lines Matching +full:adc +full:- +full:freq

1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l52.c -- CS42L52 ALSA SoC audio driver
29 #include <sound/soc-dapm.h>
43 /* MICA mode selection Differential or Single-ended */
46 /* MICB mode selection Differential or Single-ended */
49 /* Charge Pump Freq. Check datasheet Pg73 */
80 { CS42L52_ADC_HPF_FREQ, 0x00 }, /* r0B ADC HPF Corner Freq */
81 { CS42L52_ADC_MISC_CTL, 0x00 }, /* r0C Misc. ADC Ctl */
97 { CS42L52_BEEP_FREQ, 0x00 }, /* r1C Beep Freq on Time */
147 static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0);
149 static DECLARE_TLV_DB_SCALE(hpd_tlv, -9600, 50, 1);
151 static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0);
155 static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0);
157 static DECLARE_TLV_DB_SCALE(pass_tlv, -6000, 50, 0);
159 static DECLARE_TLV_DB_SCALE(mix_tlv, -5150, 50, 0);
161 static DECLARE_TLV_DB_SCALE(beep_tlv, -56, 200, 0);
164 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
165 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0)
181 SOC_DAPM_ENUM("Left ADC Input Capture Mux", adca_enum);
184 SOC_DAPM_ENUM("Right ADC Input Capture Mux", adcb_enum);
202 static const char * const digital_output_mux_text[] = {"ADC", "DSP"};
273 "-34dB", "-37dB", "-40dB", "-43dB",
274 "-46dB", "-52dB", "-58dB", "-64dB"
382 SOC_DOUBLE_R_SX_TLV("ADC Volume", CS42L52_ADCA_VOL,
384 SOC_DOUBLE_R_SX_TLV("ADC Mixer Volume",
388 SOC_DOUBLE("ADC Switch", CS42L52_ADC_MISC_CTL, 0, 1, 1, 0),
390 SOC_DOUBLE_R("ADC Mixer Switch", CS42L52_ADCA_MIXER_VOL,
409 SOC_ENUM("Beep Treble Corner Freq", beep_treble_enum),
410 SOC_ENUM("Beep Bass Corner Freq", beep_bass_enum),
494 struct cs42l52_platform_data *pdata = &cs42l52->pdata; in cs42l52_add_mic_controls()
496 if (!pdata->mica_diff_cfg) in cs42l52_add_mic_controls()
500 if (!pdata->micb_diff_cfg) in cs42l52_add_mic_controls()
526 SND_SOC_DAPM_ADC("ADC Left", NULL, CS42L52_PWRCTL1, 1, 1),
527 SND_SOC_DAPM_ADC("ADC Right", NULL, CS42L52_PWRCTL1, 2, 1),
531 SND_SOC_DAPM_MUX("ADC Left Mux", SND_SOC_NOPM, 0, 0, &adca_mux),
532 SND_SOC_DAPM_MUX("ADC Right Mux", SND_SOC_NOPM, 0, 0, &adcb_mux),
534 SND_SOC_DAPM_MUX("ADC Left Swap", SND_SOC_NOPM,
536 SND_SOC_DAPM_MUX("ADC Right Swap", SND_SOC_NOPM,
587 {"Output Mux", "ADC", "ADC Left"},
588 {"Output Mux", "ADC", "ADC Right"},
590 {"ADC Left", NULL, "Charge Pump"},
591 {"ADC Right", NULL, "Charge Pump"},
593 {"Charge Pump", NULL, "ADC Left Mux"},
594 {"Charge Pump", NULL, "ADC Right Mux"},
596 {"ADC Left Mux", "Input1A", "AIN1L"},
597 {"ADC Right Mux", "Input1B", "AIN1R"},
598 {"ADC Left Mux", "Input2A", "AIN2L"},
599 {"ADC Right Mux", "Input2B", "AIN2R"},
600 {"ADC Left Mux", "Input3A", "AIN3L"},
601 {"ADC Right Mux", "Input3B", "AIN3R"},
602 {"ADC Left Mux", "Input4A", "AIN4L"},
603 {"ADC Right Mux", "Input4B", "AIN4R"},
604 {"ADC Left Mux", "PGA Input Left", "PGA Left"},
605 {"ADC Right Mux", "PGA Input Right" , "PGA Right"},
716 int i, ret = -EINVAL; in cs42l52_get_clk()
722 if (abs(mclk - mclk1) < abs(mclk - mclk2)) { in cs42l52_get_clk()
732 int clk_id, unsigned int freq, int dir) in cs42l52_set_sysclk() argument
734 struct snd_soc_component *component = codec_dai->component; in cs42l52_set_sysclk()
737 if ((freq >= CS42L52_MIN_CLK) && (freq <= CS42L52_MAX_CLK)) { in cs42l52_set_sysclk()
738 cs42l52->sysclk = freq; in cs42l52_set_sysclk()
740 dev_err(component->dev, "Invalid freq parameter\n"); in cs42l52_set_sysclk()
741 return -EINVAL; in cs42l52_set_sysclk()
748 struct snd_soc_component *component = codec_dai->component; in cs42l52_set_fmt()
760 return -EINVAL; in cs42l52_set_fmt()
782 return -EINVAL; in cs42l52_set_fmt()
798 return -EINVAL; in cs42l52_set_fmt()
800 cs42l52->config.format = iface; in cs42l52_set_fmt()
801 snd_soc_component_write(component, CS42L52_IFACE_CTL1, cs42l52->config.format); in cs42l52_set_fmt()
808 struct snd_soc_component *component = dai->component; in cs42l52_mute()
826 struct snd_soc_component *component = dai->component; in cs42l52_pcm_hw_params()
831 index = cs42l52_get_clk(cs42l52->sysclk, params_rate(params)); in cs42l52_pcm_hw_params()
833 cs42l52->sysclk = clk_map_table[index].mclk; in cs42l52_pcm_hw_params()
843 dev_err(component->dev, "can't get correct mclk\n"); in cs42l52_pcm_hw_params()
844 return -EINVAL; in cs42l52_pcm_hw_params()
864 regcache_cache_only(cs42l52->regmap, false); in cs42l52_set_bias_level()
865 regcache_sync(cs42l52->regmap); in cs42l52_set_bias_level()
871 regcache_cache_only(cs42l52->regmap, true); in cs42l52_set_bias_level()
921 struct snd_soc_component *component = cs42l52->component; in cs42l52_beep_work()
927 if (cs42l52->beep_rate) { in cs42l52_beep_work()
929 if (abs(cs42l52->beep_rate - beep_rates[i]) < in cs42l52_beep_work()
930 abs(cs42l52->beep_rate - beep_rates[best])) in cs42l52_beep_work()
934 dev_dbg(component->dev, "Set beep rate %dHz for requested %dHz\n", in cs42l52_beep_work()
935 beep_rates[best], cs42l52->beep_rate); in cs42l52_beep_work()
941 dev_dbg(component->dev, "Disabling beep\n"); in cs42l52_beep_work()
951 /* For usability define a way of injecting beep events for the device -
960 dev_dbg(component->dev, "Beep event %x %x\n", code, hz); in cs42l52_beep_event()
970 return -1; in cs42l52_beep_event()
974 cs42l52->beep_rate = hz; in cs42l52_beep_event()
975 schedule_work(&cs42l52->beep_work); in cs42l52_beep_event()
990 input_event(cs42l52->beep, EV_SND, SND_TONE, time); in beep_store()
1002 cs42l52->beep = devm_input_allocate_device(component->dev); in cs42l52_init_beep()
1003 if (!cs42l52->beep) { in cs42l52_init_beep()
1004 dev_err(component->dev, "Failed to allocate beep device\n"); in cs42l52_init_beep()
1008 INIT_WORK(&cs42l52->beep_work, cs42l52_beep_work); in cs42l52_init_beep()
1009 cs42l52->beep_rate = 0; in cs42l52_init_beep()
1011 cs42l52->beep->name = "CS42L52 Beep Generator"; in cs42l52_init_beep()
1012 cs42l52->beep->phys = dev_name(component->dev); in cs42l52_init_beep()
1013 cs42l52->beep->id.bustype = BUS_I2C; in cs42l52_init_beep()
1015 cs42l52->beep->evbit[0] = BIT_MASK(EV_SND); in cs42l52_init_beep()
1016 cs42l52->beep->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in cs42l52_init_beep()
1017 cs42l52->beep->event = cs42l52_beep_event; in cs42l52_init_beep()
1018 cs42l52->beep->dev.parent = component->dev; in cs42l52_init_beep()
1019 input_set_drvdata(cs42l52->beep, component); in cs42l52_init_beep()
1021 ret = input_register_device(cs42l52->beep); in cs42l52_init_beep()
1023 cs42l52->beep = NULL; in cs42l52_init_beep()
1024 dev_err(component->dev, "Failed to register beep device\n"); in cs42l52_init_beep()
1027 ret = device_create_file(component->dev, &dev_attr_beep); in cs42l52_init_beep()
1029 dev_err(component->dev, "Failed to create keyclick file: %d\n", in cs42l52_init_beep()
1038 device_remove_file(component->dev, &dev_attr_beep); in cs42l52_free_beep()
1039 cancel_work_sync(&cs42l52->beep_work); in cs42l52_free_beep()
1040 cs42l52->beep = NULL; in cs42l52_free_beep()
1050 regcache_cache_only(cs42l52->regmap, true); in cs42l52_probe()
1056 cs42l52->sysclk = CS42L52_DEFAULT_CLK; in cs42l52_probe()
1057 cs42l52->config.format = CS42L52_DEFAULT_FORMAT; in cs42l52_probe()
1116 cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l52), GFP_KERNEL); in cs42l52_i2c_probe()
1118 return -ENOMEM; in cs42l52_i2c_probe()
1119 cs42l52->dev = &i2c_client->dev; in cs42l52_i2c_probe()
1121 cs42l52->regmap = devm_regmap_init_i2c(i2c_client, &cs42l52_regmap); in cs42l52_i2c_probe()
1122 if (IS_ERR(cs42l52->regmap)) { in cs42l52_i2c_probe()
1123 ret = PTR_ERR(cs42l52->regmap); in cs42l52_i2c_probe()
1124 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs42l52_i2c_probe()
1128 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), GFP_KERNEL); in cs42l52_i2c_probe()
1130 return -ENOMEM; in cs42l52_i2c_probe()
1132 if (i2c_client->dev.of_node) { in cs42l52_i2c_probe()
1133 if (of_property_read_bool(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1134 "cirrus,mica-differential-cfg")) in cs42l52_i2c_probe()
1135 pdata->mica_diff_cfg = true; in cs42l52_i2c_probe()
1137 if (of_property_read_bool(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1138 "cirrus,micb-differential-cfg")) in cs42l52_i2c_probe()
1139 pdata->micb_diff_cfg = true; in cs42l52_i2c_probe()
1141 if (of_property_read_u32(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1142 "cirrus,micbias-lvl", &val32) >= 0) in cs42l52_i2c_probe()
1143 pdata->micbias_lvl = val32; in cs42l52_i2c_probe()
1145 if (of_property_read_u32(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1146 "cirrus,chgfreq-divisor", &val32) >= 0) in cs42l52_i2c_probe()
1147 pdata->chgfreq = val32; in cs42l52_i2c_probe()
1149 pdata->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs42l52_i2c_probe()
1153 if (IS_ERR(pdata->reset_gpio)) in cs42l52_i2c_probe()
1154 return PTR_ERR(pdata->reset_gpio); in cs42l52_i2c_probe()
1156 gpiod_set_consumer_name(pdata->reset_gpio, "CS42L52 /RST"); in cs42l52_i2c_probe()
1159 cs42l52->pdata = *pdata; in cs42l52_i2c_probe()
1161 if (cs42l52->pdata.reset_gpio) { in cs42l52_i2c_probe()
1162 gpiod_set_value_cansleep(cs42l52->pdata.reset_gpio, 1); in cs42l52_i2c_probe()
1163 gpiod_set_value_cansleep(cs42l52->pdata.reset_gpio, 0); in cs42l52_i2c_probe()
1168 ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch, in cs42l52_i2c_probe()
1171 dev_warn(cs42l52->dev, "Failed to apply regmap patch: %d\n", in cs42l52_i2c_probe()
1174 ret = regmap_read(cs42l52->regmap, CS42L52_CHIP, &reg); in cs42l52_i2c_probe()
1176 dev_err(&i2c_client->dev, "Failed to read chip ID: %d\n", ret); in cs42l52_i2c_probe()
1182 ret = -ENODEV; in cs42l52_i2c_probe()
1183 dev_err(&i2c_client->dev, in cs42l52_i2c_probe()
1189 dev_info(&i2c_client->dev, "Cirrus Logic CS42L52, Revision: %02X\n", in cs42l52_i2c_probe()
1193 if (cs42l52->pdata.mica_diff_cfg) in cs42l52_i2c_probe()
1194 regmap_update_bits(cs42l52->regmap, CS42L52_MICA_CTL, in cs42l52_i2c_probe()
1196 cs42l52->pdata.mica_diff_cfg << in cs42l52_i2c_probe()
1199 if (cs42l52->pdata.micb_diff_cfg) in cs42l52_i2c_probe()
1200 regmap_update_bits(cs42l52->regmap, CS42L52_MICB_CTL, in cs42l52_i2c_probe()
1202 cs42l52->pdata.micb_diff_cfg << in cs42l52_i2c_probe()
1205 if (cs42l52->pdata.chgfreq) in cs42l52_i2c_probe()
1206 regmap_update_bits(cs42l52->regmap, CS42L52_CHARGE_PUMP, in cs42l52_i2c_probe()
1208 cs42l52->pdata.chgfreq << in cs42l52_i2c_probe()
1211 if (cs42l52->pdata.micbias_lvl) in cs42l52_i2c_probe()
1212 regmap_update_bits(cs42l52->regmap, CS42L52_IFACE_CTL2, in cs42l52_i2c_probe()
1214 cs42l52->pdata.micbias_lvl); in cs42l52_i2c_probe()
1216 return devm_snd_soc_register_component(&i2c_client->dev, in cs42l52_i2c_probe()