Lines Matching +full:vcp +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l56.c -- CS42L56 ALSA SoC audio driver
29 #include <sound/soc-dapm.h>
38 "VCP",
63 { 3, 0x7f }, /* r03 - Power Ctl 1 */
64 { 4, 0xff }, /* r04 - Power Ctl 2 */
65 { 5, 0x00 }, /* ro5 - Clocking Ctl 1 */
66 { 6, 0x0b }, /* r06 - Clocking Ctl 2 */
67 { 7, 0x00 }, /* r07 - Serial Format */
68 { 8, 0x05 }, /* r08 - Class H Ctl */
69 { 9, 0x0c }, /* r09 - Misc Ctl */
70 { 10, 0x80 }, /* r0a - INT Status */
71 { 11, 0x00 }, /* r0b - Playback Ctl */
72 { 12, 0x0c }, /* r0c - DSP Mute Ctl */
73 { 13, 0x00 }, /* r0d - ADCA Mixer Volume */
74 { 14, 0x00 }, /* r0e - ADCB Mixer Volume */
75 { 15, 0x00 }, /* r0f - PCMA Mixer Volume */
76 { 16, 0x00 }, /* r10 - PCMB Mixer Volume */
77 { 17, 0x00 }, /* r11 - Analog Input Advisory Volume */
78 { 18, 0x00 }, /* r12 - Digital Input Advisory Volume */
79 { 19, 0x00 }, /* r13 - Master A Volume */
80 { 20, 0x00 }, /* r14 - Master B Volume */
81 { 21, 0x00 }, /* r15 - Beep Freq / On Time */
82 { 22, 0x00 }, /* r16 - Beep Volume / Off Time */
83 { 23, 0x00 }, /* r17 - Beep Tone Ctl */
84 { 24, 0x88 }, /* r18 - Tone Ctl */
85 { 25, 0x00 }, /* r19 - Channel Mixer & Swap */
86 { 26, 0x00 }, /* r1a - AIN Ref Config / ADC Mux */
87 { 27, 0xa0 }, /* r1b - High-Pass Filter Ctl */
88 { 28, 0x00 }, /* r1c - Misc ADC Ctl */
89 { 29, 0x00 }, /* r1d - Gain & Bias Ctl */
90 { 30, 0x00 }, /* r1e - PGAA Mux & Volume */
91 { 31, 0x00 }, /* r1f - PGAB Mux & Volume */
92 { 32, 0x00 }, /* r20 - ADCA Attenuator */
93 { 33, 0x00 }, /* r21 - ADCB Attenuator */
94 { 34, 0x00 }, /* r22 - ALC Enable & Attack Rate */
95 { 35, 0xbf }, /* r23 - ALC Release Rate */
96 { 36, 0x00 }, /* r24 - ALC Threshold */
97 { 37, 0x00 }, /* r25 - Noise Gate Ctl */
98 { 38, 0x00 }, /* r26 - ALC, Limiter, SFT, ZeroCross */
99 { 39, 0x00 }, /* r27 - Analog Mute, LO & HP Mux */
100 { 40, 0x00 }, /* r28 - HP A Volume */
101 { 41, 0x00 }, /* r29 - HP B Volume */
102 { 42, 0x00 }, /* r2a - LINEOUT A Volume */
103 { 43, 0x00 }, /* r2b - LINEOUT B Volume */
104 { 44, 0x00 }, /* r2c - Limit Threshold Ctl */
105 { 45, 0x7f }, /* r2d - Limiter Ctl & Release Rate */
106 { 46, 0x00 }, /* r2e - Limiter Attack Rate */
129 static DECLARE_TLV_DB_SCALE(beep_tlv, -5000, 200, 0);
130 static DECLARE_TLV_DB_SCALE(hl_tlv, -6000, 50, 0);
131 static DECLARE_TLV_DB_SCALE(adv_tlv, -10200, 50, 0);
132 static DECLARE_TLV_DB_SCALE(adc_tlv, -9600, 100, 0);
133 static DECLARE_TLV_DB_SCALE(tone_tlv, -1050, 150, 0);
135 static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0);
138 0, 1, TLV_DB_SCALE_ITEM(-8200, 600, 0),
139 2, 5, TLV_DB_SCALE_ITEM(-7600, 300, 0)
142 0, 2, TLV_DB_SCALE_ITEM(-6400, 600, 0),
143 3, 7, TLV_DB_SCALE_ITEM(-4600, 300, 0)
146 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
147 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0)
711 return -EINVAL; in cs42l56_get_mclk_ratio()
717 struct snd_soc_component *component = codec_dai->component; in cs42l56_set_sysclk()
724 cs42l56->mclk_div2 = 0; in cs42l56_set_sysclk()
725 cs42l56->mclk_prediv = 0; in cs42l56_set_sysclk()
730 cs42l56->mclk_div2 = CS42L56_MCLK_DIV2; in cs42l56_set_sysclk()
731 cs42l56->mclk_prediv = 0; in cs42l56_set_sysclk()
736 cs42l56->mclk_div2 = CS42L56_MCLK_DIV2; in cs42l56_set_sysclk()
737 cs42l56->mclk_prediv = CS42L56_MCLK_PREDIV; in cs42l56_set_sysclk()
740 return -EINVAL; in cs42l56_set_sysclk()
742 cs42l56->mclk = freq; in cs42l56_set_sysclk()
746 cs42l56->mclk_prediv); in cs42l56_set_sysclk()
749 cs42l56->mclk_div2); in cs42l56_set_sysclk()
756 struct snd_soc_component *component = codec_dai->component; in cs42l56_set_dai_fmt()
761 cs42l56->iface = CS42L56_MASTER_MODE; in cs42l56_set_dai_fmt()
764 cs42l56->iface = CS42L56_SLAVE_MODE; in cs42l56_set_dai_fmt()
767 return -EINVAL; in cs42l56_set_dai_fmt()
773 cs42l56->iface_fmt = CS42L56_DIG_FMT_I2S; in cs42l56_set_dai_fmt()
776 cs42l56->iface_fmt = CS42L56_DIG_FMT_LEFT_J; in cs42l56_set_dai_fmt()
779 return -EINVAL; in cs42l56_set_dai_fmt()
785 cs42l56->iface_inv = 0; in cs42l56_set_dai_fmt()
788 cs42l56->iface_inv = CS42L56_SCLK_INV; in cs42l56_set_dai_fmt()
791 return -EINVAL; in cs42l56_set_dai_fmt()
795 CS42L56_MS_MODE_MASK, cs42l56->iface); in cs42l56_set_dai_fmt()
797 CS42L56_DIG_FMT_MASK, cs42l56->iface_fmt); in cs42l56_set_dai_fmt()
799 CS42L56_SCLK_INV_MASK, cs42l56->iface_inv); in cs42l56_set_dai_fmt()
805 struct snd_soc_component *component = dai->component; in cs42l56_mute()
862 struct snd_soc_component *component = dai->component; in cs42l56_pcm_hw_params()
866 ratio = cs42l56_get_mclk_ratio(cs42l56->mclk, params_rate(params)); in cs42l56_pcm_hw_params()
871 dev_err(component->dev, "unsupported mclk/sclk/lrclk ratio\n"); in cs42l56_pcm_hw_params()
872 return -EINVAL; in cs42l56_pcm_hw_params()
895 regcache_cache_only(cs42l56->regmap, false); in cs42l56_set_bias_level()
896 regcache_sync(cs42l56->regmap); in cs42l56_set_bias_level()
897 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l56->supplies), in cs42l56_set_bias_level()
898 cs42l56->supplies); in cs42l56_set_bias_level()
900 dev_err(cs42l56->dev, in cs42l56_set_bias_level()
914 regcache_cache_only(cs42l56->regmap, true); in cs42l56_set_bias_level()
915 regulator_bulk_disable(ARRAY_SIZE(cs42l56->supplies), in cs42l56_set_bias_level()
916 cs42l56->supplies); in cs42l56_set_bias_level()
966 struct snd_soc_component *component = cs42l56->component; in cs42l56_beep_work()
972 if (cs42l56->beep_rate) { in cs42l56_beep_work()
974 if (abs(cs42l56->beep_rate - beep_freq[i]) < in cs42l56_beep_work()
975 abs(cs42l56->beep_rate - beep_freq[best])) in cs42l56_beep_work()
979 dev_dbg(component->dev, "Set beep rate %dHz for requested %dHz\n", in cs42l56_beep_work()
980 beep_freq[best], cs42l56->beep_rate); in cs42l56_beep_work()
986 dev_dbg(component->dev, "Disabling beep\n"); in cs42l56_beep_work()
996 /* For usability define a way of injecting beep events for the device -
1005 dev_dbg(component->dev, "Beep event %x %x\n", code, hz); in cs42l56_beep_event()
1015 return -1; in cs42l56_beep_event()
1019 cs42l56->beep_rate = hz; in cs42l56_beep_event()
1020 schedule_work(&cs42l56->beep_work); in cs42l56_beep_event()
1035 input_event(cs42l56->beep, EV_SND, SND_TONE, time); in beep_store()
1047 cs42l56->beep = devm_input_allocate_device(component->dev); in cs42l56_init_beep()
1048 if (!cs42l56->beep) { in cs42l56_init_beep()
1049 dev_err(component->dev, "Failed to allocate beep device\n"); in cs42l56_init_beep()
1053 INIT_WORK(&cs42l56->beep_work, cs42l56_beep_work); in cs42l56_init_beep()
1054 cs42l56->beep_rate = 0; in cs42l56_init_beep()
1056 cs42l56->beep->name = "CS42L56 Beep Generator"; in cs42l56_init_beep()
1057 cs42l56->beep->phys = dev_name(component->dev); in cs42l56_init_beep()
1058 cs42l56->beep->id.bustype = BUS_I2C; in cs42l56_init_beep()
1060 cs42l56->beep->evbit[0] = BIT_MASK(EV_SND); in cs42l56_init_beep()
1061 cs42l56->beep->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in cs42l56_init_beep()
1062 cs42l56->beep->event = cs42l56_beep_event; in cs42l56_init_beep()
1063 cs42l56->beep->dev.parent = component->dev; in cs42l56_init_beep()
1064 input_set_drvdata(cs42l56->beep, component); in cs42l56_init_beep()
1066 ret = input_register_device(cs42l56->beep); in cs42l56_init_beep()
1068 cs42l56->beep = NULL; in cs42l56_init_beep()
1069 dev_err(component->dev, "Failed to register beep device\n"); in cs42l56_init_beep()
1072 ret = device_create_file(component->dev, &dev_attr_beep); in cs42l56_init_beep()
1074 dev_err(component->dev, "Failed to create keyclick file: %d\n", in cs42l56_init_beep()
1083 device_remove_file(component->dev, &dev_attr_beep); in cs42l56_free_beep()
1084 cancel_work_sync(&cs42l56->beep_work); in cs42l56_free_beep()
1085 cs42l56->beep = NULL; in cs42l56_free_beep()
1134 struct device_node *np = i2c_client->dev.of_node; in cs42l56_handle_of_data()
1137 if (of_property_read_bool(np, "cirrus,ain1a-reference-cfg")) in cs42l56_handle_of_data()
1138 pdata->ain1a_ref_cfg = true; in cs42l56_handle_of_data()
1140 if (of_property_read_bool(np, "cirrus,ain2a-reference-cfg")) in cs42l56_handle_of_data()
1141 pdata->ain2a_ref_cfg = true; in cs42l56_handle_of_data()
1143 if (of_property_read_bool(np, "cirrus,ain1b-reference-cfg")) in cs42l56_handle_of_data()
1144 pdata->ain1b_ref_cfg = true; in cs42l56_handle_of_data()
1146 if (of_property_read_bool(np, "cirrus,ain2b-reference-cfg")) in cs42l56_handle_of_data()
1147 pdata->ain2b_ref_cfg = true; in cs42l56_handle_of_data()
1149 if (of_property_read_u32(np, "cirrus,micbias-lvl", &val32) >= 0) in cs42l56_handle_of_data()
1150 pdata->micbias_lvl = val32; in cs42l56_handle_of_data()
1152 if (of_property_read_u32(np, "cirrus,chgfreq-divisor", &val32) >= 0) in cs42l56_handle_of_data()
1153 pdata->chgfreq = val32; in cs42l56_handle_of_data()
1155 if (of_property_read_u32(np, "cirrus,adaptive-pwr-cfg", &val32) >= 0) in cs42l56_handle_of_data()
1156 pdata->adaptive_pwr = val32; in cs42l56_handle_of_data()
1158 if (of_property_read_u32(np, "cirrus,hpf-left-freq", &val32) >= 0) in cs42l56_handle_of_data()
1159 pdata->hpfa_freq = val32; in cs42l56_handle_of_data()
1161 if (of_property_read_u32(np, "cirrus,hpf-left-freq", &val32) >= 0) in cs42l56_handle_of_data()
1162 pdata->hpfb_freq = val32; in cs42l56_handle_of_data()
1164 pdata->gpio_nreset = of_get_named_gpio(np, "cirrus,gpio-nreset", 0); in cs42l56_handle_of_data()
1173 dev_get_platdata(&i2c_client->dev); in cs42l56_i2c_probe()
1179 cs42l56 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l56), GFP_KERNEL); in cs42l56_i2c_probe()
1181 return -ENOMEM; in cs42l56_i2c_probe()
1182 cs42l56->dev = &i2c_client->dev; in cs42l56_i2c_probe()
1184 cs42l56->regmap = devm_regmap_init_i2c(i2c_client, &cs42l56_regmap); in cs42l56_i2c_probe()
1185 if (IS_ERR(cs42l56->regmap)) { in cs42l56_i2c_probe()
1186 ret = PTR_ERR(cs42l56->regmap); in cs42l56_i2c_probe()
1187 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs42l56_i2c_probe()
1192 cs42l56->pdata = *pdata; in cs42l56_i2c_probe()
1194 if (i2c_client->dev.of_node) { in cs42l56_i2c_probe()
1196 &cs42l56->pdata); in cs42l56_i2c_probe()
1202 if (cs42l56->pdata.gpio_nreset) { in cs42l56_i2c_probe()
1203 ret = gpio_request_one(cs42l56->pdata.gpio_nreset, in cs42l56_i2c_probe()
1206 dev_err(&i2c_client->dev, in cs42l56_i2c_probe()
1208 cs42l56->pdata.gpio_nreset, ret); in cs42l56_i2c_probe()
1211 gpio_set_value_cansleep(cs42l56->pdata.gpio_nreset, 0); in cs42l56_i2c_probe()
1212 gpio_set_value_cansleep(cs42l56->pdata.gpio_nreset, 1); in cs42l56_i2c_probe()
1218 for (i = 0; i < ARRAY_SIZE(cs42l56->supplies); i++) in cs42l56_i2c_probe()
1219 cs42l56->supplies[i].supply = cs42l56_supply_names[i]; in cs42l56_i2c_probe()
1221 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs42l56_i2c_probe()
1222 ARRAY_SIZE(cs42l56->supplies), in cs42l56_i2c_probe()
1223 cs42l56->supplies); in cs42l56_i2c_probe()
1225 dev_err(&i2c_client->dev, in cs42l56_i2c_probe()
1230 ret = regulator_bulk_enable(ARRAY_SIZE(cs42l56->supplies), in cs42l56_i2c_probe()
1231 cs42l56->supplies); in cs42l56_i2c_probe()
1233 dev_err(&i2c_client->dev, in cs42l56_i2c_probe()
1238 ret = regmap_read(cs42l56->regmap, CS42L56_CHIP_ID_1, ®); in cs42l56_i2c_probe()
1240 dev_err(&i2c_client->dev, "Failed to read chip ID: %d\n", ret); in cs42l56_i2c_probe()
1246 dev_err(&i2c_client->dev, in cs42l56_i2c_probe()
1249 ret = -EINVAL; in cs42l56_i2c_probe()
1255 dev_info(&i2c_client->dev, "Cirrus Logic CS42L56 "); in cs42l56_i2c_probe()
1256 dev_info(&i2c_client->dev, "Alpha Rev %X Metal Rev %X\n", in cs42l56_i2c_probe()
1259 if (cs42l56->pdata.ain1a_ref_cfg) in cs42l56_i2c_probe()
1260 regmap_update_bits(cs42l56->regmap, CS42L56_AIN_REFCFG_ADC_MUX, in cs42l56_i2c_probe()
1264 if (cs42l56->pdata.ain1b_ref_cfg) in cs42l56_i2c_probe()
1265 regmap_update_bits(cs42l56->regmap, CS42L56_AIN_REFCFG_ADC_MUX, in cs42l56_i2c_probe()
1269 if (cs42l56->pdata.ain2a_ref_cfg) in cs42l56_i2c_probe()
1270 regmap_update_bits(cs42l56->regmap, CS42L56_AIN_REFCFG_ADC_MUX, in cs42l56_i2c_probe()
1274 if (cs42l56->pdata.ain2b_ref_cfg) in cs42l56_i2c_probe()
1275 regmap_update_bits(cs42l56->regmap, CS42L56_AIN_REFCFG_ADC_MUX, in cs42l56_i2c_probe()
1279 if (cs42l56->pdata.micbias_lvl) in cs42l56_i2c_probe()
1280 regmap_update_bits(cs42l56->regmap, CS42L56_GAIN_BIAS_CTL, in cs42l56_i2c_probe()
1282 cs42l56->pdata.micbias_lvl); in cs42l56_i2c_probe()
1284 if (cs42l56->pdata.chgfreq) in cs42l56_i2c_probe()
1285 regmap_update_bits(cs42l56->regmap, CS42L56_CLASSH_CTL, in cs42l56_i2c_probe()
1287 cs42l56->pdata.chgfreq); in cs42l56_i2c_probe()
1289 if (cs42l56->pdata.hpfb_freq) in cs42l56_i2c_probe()
1290 regmap_update_bits(cs42l56->regmap, CS42L56_HPF_CTL, in cs42l56_i2c_probe()
1292 cs42l56->pdata.hpfb_freq); in cs42l56_i2c_probe()
1294 if (cs42l56->pdata.hpfa_freq) in cs42l56_i2c_probe()
1295 regmap_update_bits(cs42l56->regmap, CS42L56_HPF_CTL, in cs42l56_i2c_probe()
1297 cs42l56->pdata.hpfa_freq); in cs42l56_i2c_probe()
1299 if (cs42l56->pdata.adaptive_pwr) in cs42l56_i2c_probe()
1300 regmap_update_bits(cs42l56->regmap, CS42L56_CLASSH_CTL, in cs42l56_i2c_probe()
1302 cs42l56->pdata.adaptive_pwr); in cs42l56_i2c_probe()
1304 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs42l56_i2c_probe()
1312 regulator_bulk_disable(ARRAY_SIZE(cs42l56->supplies), in cs42l56_i2c_probe()
1313 cs42l56->supplies); in cs42l56_i2c_probe()
1321 regulator_bulk_disable(ARRAY_SIZE(cs42l56->supplies), in cs42l56_i2c_remove()
1322 cs42l56->supplies); in cs42l56_i2c_remove()