Lines Matching +full:spk +full:- +full:fmt
1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs42l52.c -- CS42L52 ALSA SoC audio driver
28 #include <sound/soc-dapm.h>
130 static DECLARE_TLV_DB_SCALE(hl_tlv, -10200, 50, 0);
132 static DECLARE_TLV_DB_SCALE(hpd_tlv, -9600, 50, 1);
134 static DECLARE_TLV_DB_SCALE(ipd_tlv, -9600, 100, 0);
138 static DECLARE_TLV_DB_SCALE(pga_tlv, -600, 50, 0);
140 static DECLARE_TLV_DB_SCALE(mix_tlv, -50, 50, 0);
142 static DECLARE_TLV_DB_SCALE(beep_tlv, -56, 200, 0);
145 0, 2, TLV_DB_SCALE_ITEM(-3000, 600, 0),
146 3, 7, TLV_DB_SCALE_ITEM(-1200, 300, 0)
254 "-34dB", "-37dB", "-40dB", "-43dB",
255 "-46dB", "-52dB", "-58dB", "-64dB"
475 struct cs42l52_platform_data *pdata = &cs42l52->pdata; in cs42l52_add_mic_controls()
477 if (!pdata->mica_diff_cfg) in cs42l52_add_mic_controls()
481 if (!pdata->micb_diff_cfg) in cs42l52_add_mic_controls()
550 SND_SOC_DAPM_SWITCH("SPK Left Amp", SND_SOC_NOPM, 0, 0, &spkl_ctl),
551 SND_SOC_DAPM_SWITCH("SPK Right Amp", SND_SOC_NOPM, 0, 0, &spkr_ctl),
612 {"SPKOUTA", NULL, "SPK Left Amp"},
613 {"SPKOUTB", NULL, "SPK Right Amp"},
615 {"SPK Left Amp", NULL, "Beep"},
616 {"SPK Right Amp", NULL, "Beep"},
617 {"SPK Left Amp", "Switch", "Playback"},
618 {"SPK Right Amp", "Switch", "Playback"},
697 int i, ret = -EINVAL; in cs42l52_get_clk()
703 if (abs(mclk - mclk1) < abs(mclk - mclk2)) { in cs42l52_get_clk()
715 struct snd_soc_component *component = codec_dai->component; in cs42l52_set_sysclk()
719 cs42l52->sysclk = freq; in cs42l52_set_sysclk()
721 dev_err(component->dev, "Invalid freq parameter\n"); in cs42l52_set_sysclk()
722 return -EINVAL; in cs42l52_set_sysclk()
727 static int cs42l52_set_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt) in cs42l52_set_fmt() argument
729 struct snd_soc_component *component = codec_dai->component; in cs42l52_set_fmt()
733 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) { in cs42l52_set_fmt()
741 return -EINVAL; in cs42l52_set_fmt()
745 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) { in cs42l52_set_fmt()
763 return -EINVAL; in cs42l52_set_fmt()
767 switch (fmt & SND_SOC_DAIFMT_INV_MASK) { in cs42l52_set_fmt()
779 return -EINVAL; in cs42l52_set_fmt()
781 cs42l52->config.format = iface; in cs42l52_set_fmt()
782 snd_soc_component_write(component, CS42L52_IFACE_CTL1, cs42l52->config.format); in cs42l52_set_fmt()
789 struct snd_soc_component *component = dai->component; in cs42l52_mute()
807 struct snd_soc_component *component = dai->component; in cs42l52_pcm_hw_params()
812 index = cs42l52_get_clk(cs42l52->sysclk, params_rate(params)); in cs42l52_pcm_hw_params()
814 cs42l52->sysclk = clk_map_table[index].mclk; in cs42l52_pcm_hw_params()
824 dev_err(component->dev, "can't get correct mclk\n"); in cs42l52_pcm_hw_params()
825 return -EINVAL; in cs42l52_pcm_hw_params()
845 regcache_cache_only(cs42l52->regmap, false); in cs42l52_set_bias_level()
846 regcache_sync(cs42l52->regmap); in cs42l52_set_bias_level()
852 regcache_cache_only(cs42l52->regmap, true); in cs42l52_set_bias_level()
902 struct snd_soc_component *component = cs42l52->component; in cs42l52_beep_work()
908 if (cs42l52->beep_rate) { in cs42l52_beep_work()
910 if (abs(cs42l52->beep_rate - beep_rates[i]) < in cs42l52_beep_work()
911 abs(cs42l52->beep_rate - beep_rates[best])) in cs42l52_beep_work()
915 dev_dbg(component->dev, "Set beep rate %dHz for requested %dHz\n", in cs42l52_beep_work()
916 beep_rates[best], cs42l52->beep_rate); in cs42l52_beep_work()
922 dev_dbg(component->dev, "Disabling beep\n"); in cs42l52_beep_work()
932 /* For usability define a way of injecting beep events for the device -
941 dev_dbg(component->dev, "Beep event %x %x\n", code, hz); in cs42l52_beep_event()
950 return -1; in cs42l52_beep_event()
954 cs42l52->beep_rate = hz; in cs42l52_beep_event()
955 schedule_work(&cs42l52->beep_work); in cs42l52_beep_event()
971 input_event(cs42l52->beep, EV_SND, SND_TONE, time); in cs42l52_beep_set()
983 cs42l52->beep = devm_input_allocate_device(component->dev); in cs42l52_init_beep()
984 if (!cs42l52->beep) { in cs42l52_init_beep()
985 dev_err(component->dev, "Failed to allocate beep device\n"); in cs42l52_init_beep()
989 INIT_WORK(&cs42l52->beep_work, cs42l52_beep_work); in cs42l52_init_beep()
990 cs42l52->beep_rate = 0; in cs42l52_init_beep()
992 cs42l52->beep->name = "CS42L52 Beep Generator"; in cs42l52_init_beep()
993 cs42l52->beep->phys = dev_name(component->dev); in cs42l52_init_beep()
994 cs42l52->beep->id.bustype = BUS_I2C; in cs42l52_init_beep()
996 cs42l52->beep->evbit[0] = BIT_MASK(EV_SND); in cs42l52_init_beep()
997 cs42l52->beep->sndbit[0] = BIT_MASK(SND_BELL) | BIT_MASK(SND_TONE); in cs42l52_init_beep()
998 cs42l52->beep->event = cs42l52_beep_event; in cs42l52_init_beep()
999 cs42l52->beep->dev.parent = component->dev; in cs42l52_init_beep()
1000 input_set_drvdata(cs42l52->beep, component); in cs42l52_init_beep()
1002 ret = input_register_device(cs42l52->beep); in cs42l52_init_beep()
1004 cs42l52->beep = NULL; in cs42l52_init_beep()
1005 dev_err(component->dev, "Failed to register beep device\n"); in cs42l52_init_beep()
1008 ret = device_create_file(component->dev, &dev_attr_beep); in cs42l52_init_beep()
1010 dev_err(component->dev, "Failed to create keyclick file: %d\n", in cs42l52_init_beep()
1019 device_remove_file(component->dev, &dev_attr_beep); in cs42l52_free_beep()
1020 cancel_work_sync(&cs42l52->beep_work); in cs42l52_free_beep()
1021 cs42l52->beep = NULL; in cs42l52_free_beep()
1031 regcache_cache_only(cs42l52->regmap, true); in cs42l52_probe()
1037 cs42l52->sysclk = CS42L52_DEFAULT_CLK; in cs42l52_probe()
1038 cs42l52->config.format = CS42L52_DEFAULT_FORMAT; in cs42l52_probe()
1093 struct cs42l52_platform_data *pdata = dev_get_platdata(&i2c_client->dev); in cs42l52_i2c_probe()
1099 cs42l52 = devm_kzalloc(&i2c_client->dev, sizeof(*cs42l52), GFP_KERNEL); in cs42l52_i2c_probe()
1101 return -ENOMEM; in cs42l52_i2c_probe()
1102 cs42l52->dev = &i2c_client->dev; in cs42l52_i2c_probe()
1104 cs42l52->regmap = devm_regmap_init_i2c(i2c_client, &cs42l52_regmap); in cs42l52_i2c_probe()
1105 if (IS_ERR(cs42l52->regmap)) { in cs42l52_i2c_probe()
1106 ret = PTR_ERR(cs42l52->regmap); in cs42l52_i2c_probe()
1107 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs42l52_i2c_probe()
1111 cs42l52->pdata = *pdata; in cs42l52_i2c_probe()
1113 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), in cs42l52_i2c_probe()
1116 return -ENOMEM; in cs42l52_i2c_probe()
1118 if (i2c_client->dev.of_node) { in cs42l52_i2c_probe()
1119 if (of_property_read_bool(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1120 "cirrus,mica-differential-cfg")) in cs42l52_i2c_probe()
1121 pdata->mica_diff_cfg = true; in cs42l52_i2c_probe()
1123 if (of_property_read_bool(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1124 "cirrus,micb-differential-cfg")) in cs42l52_i2c_probe()
1125 pdata->micb_diff_cfg = true; in cs42l52_i2c_probe()
1127 if (of_property_read_u32(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1128 "cirrus,micbias-lvl", &val32) >= 0) in cs42l52_i2c_probe()
1129 pdata->micbias_lvl = val32; in cs42l52_i2c_probe()
1131 if (of_property_read_u32(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1132 "cirrus,chgfreq-divisor", &val32) >= 0) in cs42l52_i2c_probe()
1133 pdata->chgfreq = val32; in cs42l52_i2c_probe()
1135 pdata->reset_gpio = in cs42l52_i2c_probe()
1136 of_get_named_gpio(i2c_client->dev.of_node, in cs42l52_i2c_probe()
1137 "cirrus,reset-gpio", 0); in cs42l52_i2c_probe()
1139 cs42l52->pdata = *pdata; in cs42l52_i2c_probe()
1142 if (cs42l52->pdata.reset_gpio) { in cs42l52_i2c_probe()
1143 ret = devm_gpio_request_one(&i2c_client->dev, in cs42l52_i2c_probe()
1144 cs42l52->pdata.reset_gpio, in cs42l52_i2c_probe()
1148 dev_err(&i2c_client->dev, "Failed to request /RST %d: %d\n", in cs42l52_i2c_probe()
1149 cs42l52->pdata.reset_gpio, ret); in cs42l52_i2c_probe()
1152 gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 0); in cs42l52_i2c_probe()
1153 gpio_set_value_cansleep(cs42l52->pdata.reset_gpio, 1); in cs42l52_i2c_probe()
1158 ret = regmap_register_patch(cs42l52->regmap, cs42l52_threshold_patch, in cs42l52_i2c_probe()
1161 dev_warn(cs42l52->dev, "Failed to apply regmap patch: %d\n", in cs42l52_i2c_probe()
1164 ret = regmap_read(cs42l52->regmap, CS42L52_CHIP, ®); in cs42l52_i2c_probe()
1167 ret = -ENODEV; in cs42l52_i2c_probe()
1168 dev_err(&i2c_client->dev, in cs42l52_i2c_probe()
1174 dev_info(&i2c_client->dev, "Cirrus Logic CS42L52, Revision: %02X\n", in cs42l52_i2c_probe()
1178 if (cs42l52->pdata.mica_diff_cfg) in cs42l52_i2c_probe()
1179 regmap_update_bits(cs42l52->regmap, CS42L52_MICA_CTL, in cs42l52_i2c_probe()
1181 cs42l52->pdata.mica_diff_cfg << in cs42l52_i2c_probe()
1184 if (cs42l52->pdata.micb_diff_cfg) in cs42l52_i2c_probe()
1185 regmap_update_bits(cs42l52->regmap, CS42L52_MICB_CTL, in cs42l52_i2c_probe()
1187 cs42l52->pdata.micb_diff_cfg << in cs42l52_i2c_probe()
1190 if (cs42l52->pdata.chgfreq) in cs42l52_i2c_probe()
1191 regmap_update_bits(cs42l52->regmap, CS42L52_CHARGE_PUMP, in cs42l52_i2c_probe()
1193 cs42l52->pdata.chgfreq << in cs42l52_i2c_probe()
1196 if (cs42l52->pdata.micbias_lvl) in cs42l52_i2c_probe()
1197 regmap_update_bits(cs42l52->regmap, CS42L52_IFACE_CTL2, in cs42l52_i2c_probe()
1199 cs42l52->pdata.micbias_lvl); in cs42l52_i2c_probe()
1201 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs42l52_i2c_probe()