Lines Matching +full:vp +full:- +full:supply
1 // SPDX-License-Identifier: GPL-2.0-only
3 * cs35l34.c -- CS35l34 ALSA SoC audio driver
28 #include <sound/soc-dapm.h>
48 struct gpio_desc *reset_gpio; /* Active-low reset GPIO */
235 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l34_sdin_event()
241 if (priv->tdm_mode) in cs35l34_sdin_event()
242 regmap_update_bits(priv->regmap, CS35L34_PWRCTL3, in cs35l34_sdin_event()
245 ret = regmap_update_bits(priv->regmap, CS35L34_PWRCTL1, in cs35l34_sdin_event()
248 dev_err(component->dev, "Cannot set Power bits %d\n", ret); in cs35l34_sdin_event()
254 if (priv->tdm_mode) { in cs35l34_sdin_event()
255 regmap_update_bits(priv->regmap, CS35L34_PWRCTL3, in cs35l34_sdin_event()
258 ret = regmap_update_bits(priv->regmap, CS35L34_PWRCTL1, in cs35l34_sdin_event()
270 struct snd_soc_component *component = dai->component; in cs35l34_set_tdm_slot()
276 return -EINVAL; in cs35l34_set_tdm_slot()
278 priv->tdm_mode = true; in cs35l34_set_tdm_slot()
280 slot = ffs(rx_mask) - 1; in cs35l34_set_tdm_slot()
288 slot = ffs(tx_mask) - 1; in cs35l34_set_tdm_slot()
299 /* disconnect {vp,vbst}_mon routes: eanble later if set in tx_mask*/ in cs35l34_set_tdm_slot()
324 reg = CS35L34_TDM_TX_SLOT_EN_4 - (slot/8); in cs35l34_set_tdm_slot()
325 bit_pos = slot - ((slot / 8) * (8)); in cs35l34_set_tdm_slot()
330 slot = ffs(tx_mask) - 1; in cs35l34_set_tdm_slot()
340 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l34_main_amp_event()
345 regmap_update_bits(priv->regmap, CS35L34_BST_CVTR_V_CTL, in cs35l34_main_amp_event()
346 CS35L34_BST_CVTL_MASK, priv->pdata.boost_vtge); in cs35l34_main_amp_event()
348 regmap_update_bits(priv->regmap, CS35L34_PROTECT_CTL, in cs35l34_main_amp_event()
352 regmap_update_bits(priv->regmap, CS35L34_BST_CVTR_V_CTL, in cs35l34_main_amp_event()
354 regmap_update_bits(priv->regmap, CS35L34_PROTECT_CTL, in cs35l34_main_amp_event()
364 static DECLARE_TLV_DB_SCALE(dig_vol_tlv, -10200, 50, 0);
380 struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); in cs35l34_mclk_event()
387 ret = regmap_read(priv->regmap, CS35L34_AMP_DIG_VOL_CTL, in cs35l34_mclk_event()
399 ret = regmap_read(priv->regmap, CS35L34_INT_STATUS_2, in cs35l34_mclk_event()
434 SND_SOC_DAPM_INPUT("VP"),
517 return -EINVAL; in cs35l34_get_mclk_coeff()
522 struct snd_soc_component *component = codec_dai->component; in cs35l34_set_dai_fmt()
527 regmap_update_bits(priv->regmap, CS35L34_ADSP_CLK_CTL, in cs35l34_set_dai_fmt()
531 regmap_update_bits(priv->regmap, CS35L34_ADSP_CLK_CTL, in cs35l34_set_dai_fmt()
535 return -EINVAL; in cs35l34_set_dai_fmt()
544 struct snd_soc_component *component = dai->component; in cs35l34_pcm_hw_params()
549 int coeff = cs35l34_get_mclk_coeff(priv->mclk_int, srate); in cs35l34_pcm_hw_params()
552 dev_err(component->dev, "ERROR: Invalid mclk %d and/or srate %d\n", in cs35l34_pcm_hw_params()
553 priv->mclk_int, srate); in cs35l34_pcm_hw_params()
557 ret = regmap_update_bits(priv->regmap, CS35L34_ADSP_CLK_CTL, in cs35l34_pcm_hw_params()
560 dev_err(component->dev, "Failed to set clock state %d\n", ret); in cs35l34_pcm_hw_params()
579 snd_pcm_hw_constraint_list(substream->runtime, 0, in cs35l34_pcm_startup()
588 struct snd_soc_component *component = dai->component; in cs35l34_set_tristate()
602 struct snd_soc_component *component = dai->component; in cs35l34_dai_set_sysclk()
609 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
613 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
617 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
621 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
625 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
629 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
632 dev_err(component->dev, "ERROR: Invalid Frequency %d\n", freq); in cs35l34_dai_set_sysclk()
633 cs35l34->mclk_int = 0; in cs35l34_dai_set_sysclk()
634 return -EINVAL; in cs35l34_dai_set_sysclk()
636 regmap_update_bits(cs35l34->regmap, CS35L34_MCLK_CTL, in cs35l34_dai_set_sysclk()
674 struct snd_soc_component *component = cs35l34->component; in cs35l34_boost_inductor()
678 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x24); in cs35l34_boost_inductor()
679 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x24); in cs35l34_boost_inductor()
680 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
682 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 0); in cs35l34_boost_inductor()
685 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x20); in cs35l34_boost_inductor()
686 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x20); in cs35l34_boost_inductor()
687 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
689 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 1); in cs35l34_boost_inductor()
692 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x20); in cs35l34_boost_inductor()
693 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x20); in cs35l34_boost_inductor()
694 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
696 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 2); in cs35l34_boost_inductor()
699 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x19); in cs35l34_boost_inductor()
700 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x25); in cs35l34_boost_inductor()
701 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
703 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 3); in cs35l34_boost_inductor()
706 dev_err(component->dev, "%s Invalid Inductor Value %d uH\n", in cs35l34_boost_inductor()
708 return -EINVAL; in cs35l34_boost_inductor()
718 pm_runtime_get_sync(component->dev); in cs35l34_probe()
721 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
727 regmap_write(cs35l34->regmap, CS35L34_PWRCTL2, 0xFD); in cs35l34_probe()
728 regmap_write(cs35l34->regmap, CS35L34_PWRCTL3, 0x1F); in cs35l34_probe()
731 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
735 if (cs35l34->pdata.boost_peak) in cs35l34_probe()
736 regmap_update_bits(cs35l34->regmap, CS35L34_BST_PEAK_I, in cs35l34_probe()
738 cs35l34->pdata.boost_peak); in cs35l34_probe()
740 if (cs35l34->pdata.gain_zc_disable) in cs35l34_probe()
741 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
744 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
747 if (cs35l34->pdata.aif_half_drv) in cs35l34_probe()
748 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_CLK_CTL, in cs35l34_probe()
751 if (cs35l34->pdata.digsft_disable) in cs35l34_probe()
752 regmap_update_bits(cs35l34->regmap, CS35L34_AMP_DIG_VOL_CTL, in cs35l34_probe()
755 if (cs35l34->pdata.amp_inv) in cs35l34_probe()
756 regmap_update_bits(cs35l34->regmap, CS35L34_AMP_DIG_VOL_CTL, in cs35l34_probe()
759 if (cs35l34->pdata.boost_ind) in cs35l34_probe()
760 ret = cs35l34_boost_inductor(cs35l34, cs35l34->pdata.boost_ind); in cs35l34_probe()
762 if (cs35l34->pdata.i2s_sdinloc) in cs35l34_probe()
763 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_I2S_CTL, in cs35l34_probe()
765 cs35l34->pdata.i2s_sdinloc << CS35L34_I2S_LOC_SHIFT); in cs35l34_probe()
767 if (cs35l34->pdata.tdm_rising_edge) in cs35l34_probe()
768 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_TDM_CTL, in cs35l34_probe()
771 pm_runtime_put_sync(component->dev); in cs35l34_probe()
809 struct device_node *np = i2c_client->dev.of_node; in cs35l34_handle_of_data()
812 if (of_property_read_u32(np, "cirrus,boost-vtge-millivolt", in cs35l34_handle_of_data()
816 dev_err(&i2c_client->dev, in cs35l34_handle_of_data()
818 return -EINVAL; in cs35l34_handle_of_data()
821 pdata->boost_vtge = 0; /* Use VP */ in cs35l34_handle_of_data()
823 pdata->boost_vtge = ((val - 3300)/100) + 1; in cs35l34_handle_of_data()
825 dev_warn(&i2c_client->dev, in cs35l34_handle_of_data()
826 "Boost Voltage not specified. Using VP\n"); in cs35l34_handle_of_data()
829 if (of_property_read_u32(np, "cirrus,boost-ind-nanohenry", &val) >= 0) { in cs35l34_handle_of_data()
830 pdata->boost_ind = val; in cs35l34_handle_of_data()
832 dev_err(&i2c_client->dev, "Inductor not specified.\n"); in cs35l34_handle_of_data()
833 return -EINVAL; in cs35l34_handle_of_data()
836 if (of_property_read_u32(np, "cirrus,boost-peak-milliamp", &val) >= 0) { in cs35l34_handle_of_data()
838 dev_err(&i2c_client->dev, in cs35l34_handle_of_data()
840 return -EINVAL; in cs35l34_handle_of_data()
842 pdata->boost_peak = ((val - 1200)/80) + 1; in cs35l34_handle_of_data()
845 pdata->aif_half_drv = of_property_read_bool(np, in cs35l34_handle_of_data()
846 "cirrus,aif-half-drv"); in cs35l34_handle_of_data()
847 pdata->digsft_disable = of_property_read_bool(np, in cs35l34_handle_of_data()
848 "cirrus,digsft-disable"); in cs35l34_handle_of_data()
850 pdata->gain_zc_disable = of_property_read_bool(np, in cs35l34_handle_of_data()
851 "cirrus,gain-zc-disable"); in cs35l34_handle_of_data()
852 pdata->amp_inv = of_property_read_bool(np, "cirrus,amp-inv"); in cs35l34_handle_of_data()
854 if (of_property_read_u32(np, "cirrus,i2s-sdinloc", &val) >= 0) in cs35l34_handle_of_data()
855 pdata->i2s_sdinloc = val; in cs35l34_handle_of_data()
856 if (of_property_read_u32(np, "cirrus,tdm-rising-edge", &val) >= 0) in cs35l34_handle_of_data()
857 pdata->tdm_rising_edge = val; in cs35l34_handle_of_data()
865 struct snd_soc_component *component = cs35l34->component; in cs35l34_irq_thread()
871 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_4, &sticky4); in cs35l34_irq_thread()
872 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_3, &sticky3); in cs35l34_irq_thread()
873 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_2, &sticky2); in cs35l34_irq_thread()
874 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_1, &sticky1); in cs35l34_irq_thread()
876 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_4, &mask4); in cs35l34_irq_thread()
877 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_3, &mask3); in cs35l34_irq_thread()
878 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_2, &mask2); in cs35l34_irq_thread()
879 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_1, &mask1); in cs35l34_irq_thread()
885 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_1, ¤t1); in cs35l34_irq_thread()
888 dev_err(component->dev, "Cal error\n"); in cs35l34_irq_thread()
892 dev_dbg(component->dev, "Cal error release\n"); in cs35l34_irq_thread()
893 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
896 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
900 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
903 /* note: amp will re-calibrate on next resume */ in cs35l34_irq_thread()
908 dev_err(component->dev, "Alive error\n"); in cs35l34_irq_thread()
911 dev_crit(component->dev, "Amp short error\n"); in cs35l34_irq_thread()
915 dev_dbg(component->dev, in cs35l34_irq_thread()
917 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
920 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
924 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
931 dev_crit(component->dev, "Over temperature warning\n"); in cs35l34_irq_thread()
935 dev_dbg(component->dev, in cs35l34_irq_thread()
937 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
940 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
944 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
951 dev_crit(component->dev, "Over temperature error\n"); in cs35l34_irq_thread()
955 dev_dbg(component->dev, in cs35l34_irq_thread()
957 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
960 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
964 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
971 dev_crit(component->dev, "VBST too high error; powering off!\n"); in cs35l34_irq_thread()
972 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL2, in cs35l34_irq_thread()
974 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL1, in cs35l34_irq_thread()
979 dev_crit(component->dev, "LBST short error; powering off!\n"); in cs35l34_irq_thread()
980 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL2, in cs35l34_irq_thread()
982 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL1, in cs35l34_irq_thread()
991 "VP",
998 dev_get_platdata(&i2c_client->dev); in cs35l34_i2c_probe()
1003 cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l34), GFP_KERNEL); in cs35l34_i2c_probe()
1005 return -ENOMEM; in cs35l34_i2c_probe()
1008 cs35l34->regmap = devm_regmap_init_i2c(i2c_client, &cs35l34_regmap); in cs35l34_i2c_probe()
1009 if (IS_ERR(cs35l34->regmap)) { in cs35l34_i2c_probe()
1010 ret = PTR_ERR(cs35l34->regmap); in cs35l34_i2c_probe()
1011 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs35l34_i2c_probe()
1015 cs35l34->num_core_supplies = ARRAY_SIZE(cs35l34_core_supplies); in cs35l34_i2c_probe()
1017 cs35l34->core_supplies[i].supply = cs35l34_core_supplies[i]; in cs35l34_i2c_probe()
1019 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs35l34_i2c_probe()
1020 cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1021 cs35l34->core_supplies); in cs35l34_i2c_probe()
1023 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1028 ret = regulator_bulk_enable(cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1029 cs35l34->core_supplies); in cs35l34_i2c_probe()
1031 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1037 cs35l34->pdata = *pdata; in cs35l34_i2c_probe()
1039 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), in cs35l34_i2c_probe()
1042 ret = -ENOMEM; in cs35l34_i2c_probe()
1046 if (i2c_client->dev.of_node) { in cs35l34_i2c_probe()
1052 cs35l34->pdata = *pdata; in cs35l34_i2c_probe()
1055 ret = devm_request_threaded_irq(&i2c_client->dev, i2c_client->irq, NULL, in cs35l34_i2c_probe()
1059 dev_err(&i2c_client->dev, "Failed to request IRQ: %d\n", ret); in cs35l34_i2c_probe()
1061 cs35l34->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs35l34_i2c_probe()
1063 if (IS_ERR(cs35l34->reset_gpio)) { in cs35l34_i2c_probe()
1064 ret = PTR_ERR(cs35l34->reset_gpio); in cs35l34_i2c_probe()
1068 gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); in cs35l34_i2c_probe()
1072 devid = cirrus_read_device_id(cs35l34->regmap, CS35L34_DEVID_AB); in cs35l34_i2c_probe()
1075 dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret); in cs35l34_i2c_probe()
1080 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1083 ret = -ENODEV; in cs35l34_i2c_probe()
1087 ret = regmap_read(cs35l34->regmap, CS35L34_REV_ID, ®); in cs35l34_i2c_probe()
1089 dev_err(&i2c_client->dev, "Get Revision ID failed\n"); in cs35l34_i2c_probe()
1093 dev_info(&i2c_client->dev, in cs35l34_i2c_probe()
1098 regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_1, in cs35l34_i2c_probe()
1102 regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_3, in cs35l34_i2c_probe()
1105 pm_runtime_set_autosuspend_delay(&i2c_client->dev, 100); in cs35l34_i2c_probe()
1106 pm_runtime_use_autosuspend(&i2c_client->dev); in cs35l34_i2c_probe()
1107 pm_runtime_set_active(&i2c_client->dev); in cs35l34_i2c_probe()
1108 pm_runtime_enable(&i2c_client->dev); in cs35l34_i2c_probe()
1110 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs35l34_i2c_probe()
1113 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1121 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_i2c_probe()
1123 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1124 cs35l34->core_supplies); in cs35l34_i2c_probe()
1133 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_i2c_remove()
1135 pm_runtime_disable(&client->dev); in cs35l34_i2c_remove()
1136 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_i2c_remove()
1137 cs35l34->core_supplies); in cs35l34_i2c_remove()
1145 ret = regulator_bulk_enable(cs35l34->num_core_supplies, in cs35l34_runtime_resume()
1146 cs35l34->core_supplies); in cs35l34_runtime_resume()
1154 regcache_cache_only(cs35l34->regmap, false); in cs35l34_runtime_resume()
1156 gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); in cs35l34_runtime_resume()
1159 ret = regcache_sync(cs35l34->regmap); in cs35l34_runtime_resume()
1166 regcache_cache_only(cs35l34->regmap, true); in cs35l34_runtime_resume()
1167 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_runtime_resume()
1168 cs35l34->core_supplies); in cs35l34_runtime_resume()
1177 regcache_cache_only(cs35l34->regmap, true); in cs35l34_runtime_suspend()
1178 regcache_mark_dirty(cs35l34->regmap); in cs35l34_runtime_suspend()
1180 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_runtime_suspend()
1182 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_runtime_suspend()
1183 cs35l34->core_supplies); in cs35l34_runtime_suspend()