Lines Matching +full:boost +full:- +full:low +full:- +full:freq
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()
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()
444 SND_SOC_DAPM_ADC("BOOST", NULL, CS35L34_PWRCTL2, 2, 1),
453 {"BOOST", NULL, "SDIN"},
454 {"CLASS H", NULL, "BOOST"},
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()
568 struct snd_soc_component *component = dai->component; in cs35l34_set_tristate()
580 int clk_id, unsigned int freq, int dir) in cs35l34_dai_set_sysclk() argument
582 struct snd_soc_component *component = dai->component; in cs35l34_dai_set_sysclk()
586 switch (freq) { in cs35l34_dai_set_sysclk()
589 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
593 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
597 cs35l34->mclk_int = freq; in cs35l34_dai_set_sysclk()
601 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
605 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
609 cs35l34->mclk_int = freq / 2; in cs35l34_dai_set_sysclk()
612 dev_err(component->dev, "ERROR: Invalid Frequency %d\n", freq); in cs35l34_dai_set_sysclk()
613 cs35l34->mclk_int = 0; in cs35l34_dai_set_sysclk()
614 return -EINVAL; in cs35l34_dai_set_sysclk()
616 regmap_update_bits(cs35l34->regmap, CS35L34_MCLK_CTL, in cs35l34_dai_set_sysclk()
653 struct snd_soc_component *component = cs35l34->component; in cs35l34_boost_inductor()
657 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x24); in cs35l34_boost_inductor()
658 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x24); in cs35l34_boost_inductor()
659 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
661 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 0); in cs35l34_boost_inductor()
664 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x20); in cs35l34_boost_inductor()
665 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x20); in cs35l34_boost_inductor()
666 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
668 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 1); in cs35l34_boost_inductor()
671 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x20); in cs35l34_boost_inductor()
672 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x20); in cs35l34_boost_inductor()
673 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SLOPE_COMP, in cs35l34_boost_inductor()
675 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_SW_FREQ, 2); in cs35l34_boost_inductor()
678 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_1, 0x19); in cs35l34_boost_inductor()
679 regmap_write(cs35l34->regmap, CS35L34_BST_CONV_COEF_2, 0x25); 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, 3); in cs35l34_boost_inductor()
685 dev_err(component->dev, "%s Invalid Inductor Value %d uH\n", in cs35l34_boost_inductor()
687 return -EINVAL; in cs35l34_boost_inductor()
697 pm_runtime_get_sync(component->dev); in cs35l34_probe()
700 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
706 regmap_write(cs35l34->regmap, CS35L34_PWRCTL2, 0xFD); in cs35l34_probe()
707 regmap_write(cs35l34->regmap, CS35L34_PWRCTL3, 0x1F); in cs35l34_probe()
710 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
714 if (cs35l34->pdata.boost_peak) in cs35l34_probe()
715 regmap_update_bits(cs35l34->regmap, CS35L34_BST_PEAK_I, in cs35l34_probe()
717 cs35l34->pdata.boost_peak); in cs35l34_probe()
719 if (cs35l34->pdata.gain_zc_disable) in cs35l34_probe()
720 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
723 regmap_update_bits(cs35l34->regmap, CS35L34_PROTECT_CTL, in cs35l34_probe()
726 if (cs35l34->pdata.aif_half_drv) in cs35l34_probe()
727 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_CLK_CTL, in cs35l34_probe()
730 if (cs35l34->pdata.digsft_disable) in cs35l34_probe()
731 regmap_update_bits(cs35l34->regmap, CS35L34_AMP_DIG_VOL_CTL, in cs35l34_probe()
734 if (cs35l34->pdata.amp_inv) in cs35l34_probe()
735 regmap_update_bits(cs35l34->regmap, CS35L34_AMP_DIG_VOL_CTL, in cs35l34_probe()
738 if (cs35l34->pdata.boost_ind) in cs35l34_probe()
739 ret = cs35l34_boost_inductor(cs35l34, cs35l34->pdata.boost_ind); in cs35l34_probe()
741 if (cs35l34->pdata.i2s_sdinloc) in cs35l34_probe()
742 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_I2S_CTL, in cs35l34_probe()
744 cs35l34->pdata.i2s_sdinloc << CS35L34_I2S_LOC_SHIFT); in cs35l34_probe()
746 if (cs35l34->pdata.tdm_rising_edge) in cs35l34_probe()
747 regmap_update_bits(cs35l34->regmap, CS35L34_ADSP_TDM_CTL, in cs35l34_probe()
750 pm_runtime_put_sync(component->dev); in cs35l34_probe()
788 struct device_node *np = i2c_client->dev.of_node; in cs35l34_handle_of_data()
791 if (of_property_read_u32(np, "cirrus,boost-vtge-millivolt", in cs35l34_handle_of_data()
793 /* Boost Voltage has a maximum of 8V */ in cs35l34_handle_of_data()
795 dev_err(&i2c_client->dev, in cs35l34_handle_of_data()
796 "Invalid Boost Voltage %d mV\n", val); in cs35l34_handle_of_data()
797 return -EINVAL; in cs35l34_handle_of_data()
800 pdata->boost_vtge = 0; /* Use VP */ in cs35l34_handle_of_data()
802 pdata->boost_vtge = ((val - 3300)/100) + 1; in cs35l34_handle_of_data()
804 dev_warn(&i2c_client->dev, in cs35l34_handle_of_data()
805 "Boost Voltage not specified. Using VP\n"); in cs35l34_handle_of_data()
808 if (of_property_read_u32(np, "cirrus,boost-ind-nanohenry", &val) >= 0) { in cs35l34_handle_of_data()
809 pdata->boost_ind = val; in cs35l34_handle_of_data()
811 dev_err(&i2c_client->dev, "Inductor not specified.\n"); in cs35l34_handle_of_data()
812 return -EINVAL; in cs35l34_handle_of_data()
815 if (of_property_read_u32(np, "cirrus,boost-peak-milliamp", &val) >= 0) { in cs35l34_handle_of_data()
817 dev_err(&i2c_client->dev, in cs35l34_handle_of_data()
818 "Invalid Boost Peak Current %d mA\n", val); in cs35l34_handle_of_data()
819 return -EINVAL; in cs35l34_handle_of_data()
821 pdata->boost_peak = ((val - 1200)/80) + 1; in cs35l34_handle_of_data()
824 pdata->aif_half_drv = of_property_read_bool(np, in cs35l34_handle_of_data()
825 "cirrus,aif-half-drv"); in cs35l34_handle_of_data()
826 pdata->digsft_disable = of_property_read_bool(np, in cs35l34_handle_of_data()
827 "cirrus,digsft-disable"); in cs35l34_handle_of_data()
829 pdata->gain_zc_disable = of_property_read_bool(np, in cs35l34_handle_of_data()
830 "cirrus,gain-zc-disable"); in cs35l34_handle_of_data()
831 pdata->amp_inv = of_property_read_bool(np, "cirrus,amp-inv"); in cs35l34_handle_of_data()
833 if (of_property_read_u32(np, "cirrus,i2s-sdinloc", &val) >= 0) in cs35l34_handle_of_data()
834 pdata->i2s_sdinloc = val; in cs35l34_handle_of_data()
835 if (of_property_read_u32(np, "cirrus,tdm-rising-edge", &val) >= 0) in cs35l34_handle_of_data()
836 pdata->tdm_rising_edge = val; in cs35l34_handle_of_data()
844 struct snd_soc_component *component = cs35l34->component; in cs35l34_irq_thread()
850 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_4, &sticky4); in cs35l34_irq_thread()
851 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_3, &sticky3); in cs35l34_irq_thread()
852 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_2, &sticky2); in cs35l34_irq_thread()
853 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_1, &sticky1); in cs35l34_irq_thread()
855 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_4, &mask4); in cs35l34_irq_thread()
856 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_3, &mask3); in cs35l34_irq_thread()
857 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_2, &mask2); in cs35l34_irq_thread()
858 regmap_read(cs35l34->regmap, CS35L34_INT_MASK_1, &mask1); in cs35l34_irq_thread()
864 regmap_read(cs35l34->regmap, CS35L34_INT_STATUS_1, ¤t1); in cs35l34_irq_thread()
867 dev_err(component->dev, "Cal error\n"); in cs35l34_irq_thread()
871 dev_dbg(component->dev, "Cal error release\n"); in cs35l34_irq_thread()
872 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
875 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
879 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
882 /* note: amp will re-calibrate on next resume */ in cs35l34_irq_thread()
887 dev_err(component->dev, "Alive error\n"); in cs35l34_irq_thread()
890 dev_crit(component->dev, "Amp short error\n"); in cs35l34_irq_thread()
894 dev_dbg(component->dev, in cs35l34_irq_thread()
896 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
899 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
903 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
910 dev_crit(component->dev, "Over temperature warning\n"); in cs35l34_irq_thread()
914 dev_dbg(component->dev, in cs35l34_irq_thread()
916 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
919 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
923 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
930 dev_crit(component->dev, "Over temperature error\n"); in cs35l34_irq_thread()
934 dev_dbg(component->dev, in cs35l34_irq_thread()
936 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
939 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
943 regmap_update_bits(cs35l34->regmap, in cs35l34_irq_thread()
950 dev_crit(component->dev, "VBST too high error; powering off!\n"); in cs35l34_irq_thread()
951 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL2, in cs35l34_irq_thread()
953 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL1, in cs35l34_irq_thread()
958 dev_crit(component->dev, "LBST short error; powering off!\n"); in cs35l34_irq_thread()
959 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL2, in cs35l34_irq_thread()
961 regmap_update_bits(cs35l34->regmap, CS35L34_PWRCTL1, in cs35l34_irq_thread()
977 dev_get_platdata(&i2c_client->dev); in cs35l34_i2c_probe()
982 cs35l34 = devm_kzalloc(&i2c_client->dev, sizeof(*cs35l34), GFP_KERNEL); in cs35l34_i2c_probe()
984 return -ENOMEM; in cs35l34_i2c_probe()
987 cs35l34->regmap = devm_regmap_init_i2c(i2c_client, &cs35l34_regmap); in cs35l34_i2c_probe()
988 if (IS_ERR(cs35l34->regmap)) { in cs35l34_i2c_probe()
989 ret = PTR_ERR(cs35l34->regmap); in cs35l34_i2c_probe()
990 dev_err(&i2c_client->dev, "regmap_init() failed: %d\n", ret); in cs35l34_i2c_probe()
994 cs35l34->num_core_supplies = ARRAY_SIZE(cs35l34_core_supplies); in cs35l34_i2c_probe()
996 cs35l34->core_supplies[i].supply = cs35l34_core_supplies[i]; in cs35l34_i2c_probe()
998 ret = devm_regulator_bulk_get(&i2c_client->dev, in cs35l34_i2c_probe()
999 cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1000 cs35l34->core_supplies); in cs35l34_i2c_probe()
1002 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1007 ret = regulator_bulk_enable(cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1008 cs35l34->core_supplies); in cs35l34_i2c_probe()
1010 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1016 cs35l34->pdata = *pdata; in cs35l34_i2c_probe()
1018 pdata = devm_kzalloc(&i2c_client->dev, sizeof(*pdata), in cs35l34_i2c_probe()
1021 ret = -ENOMEM; in cs35l34_i2c_probe()
1025 if (i2c_client->dev.of_node) { in cs35l34_i2c_probe()
1031 cs35l34->pdata = *pdata; in cs35l34_i2c_probe()
1034 ret = devm_request_threaded_irq(&i2c_client->dev, i2c_client->irq, NULL, in cs35l34_i2c_probe()
1038 dev_err(&i2c_client->dev, "Failed to request IRQ: %d\n", ret); in cs35l34_i2c_probe()
1040 cs35l34->reset_gpio = devm_gpiod_get_optional(&i2c_client->dev, in cs35l34_i2c_probe()
1042 if (IS_ERR(cs35l34->reset_gpio)) { in cs35l34_i2c_probe()
1043 ret = PTR_ERR(cs35l34->reset_gpio); in cs35l34_i2c_probe()
1047 gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); in cs35l34_i2c_probe()
1051 devid = cirrus_read_device_id(cs35l34->regmap, CS35L34_DEVID_AB); in cs35l34_i2c_probe()
1054 dev_err(&i2c_client->dev, "Failed to read device ID: %d\n", ret); in cs35l34_i2c_probe()
1059 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1062 ret = -ENODEV; in cs35l34_i2c_probe()
1066 ret = regmap_read(cs35l34->regmap, CS35L34_REV_ID, ®); in cs35l34_i2c_probe()
1068 dev_err(&i2c_client->dev, "Get Revision ID failed\n"); in cs35l34_i2c_probe()
1072 dev_info(&i2c_client->dev, in cs35l34_i2c_probe()
1077 regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_1, in cs35l34_i2c_probe()
1081 regmap_update_bits(cs35l34->regmap, CS35L34_INT_MASK_3, in cs35l34_i2c_probe()
1084 pm_runtime_set_autosuspend_delay(&i2c_client->dev, 100); in cs35l34_i2c_probe()
1085 pm_runtime_use_autosuspend(&i2c_client->dev); in cs35l34_i2c_probe()
1086 pm_runtime_set_active(&i2c_client->dev); in cs35l34_i2c_probe()
1087 pm_runtime_enable(&i2c_client->dev); in cs35l34_i2c_probe()
1089 ret = devm_snd_soc_register_component(&i2c_client->dev, in cs35l34_i2c_probe()
1092 dev_err(&i2c_client->dev, in cs35l34_i2c_probe()
1100 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_i2c_probe()
1102 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_i2c_probe()
1103 cs35l34->core_supplies); in cs35l34_i2c_probe()
1112 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_i2c_remove()
1114 pm_runtime_disable(&client->dev); in cs35l34_i2c_remove()
1115 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_i2c_remove()
1116 cs35l34->core_supplies); in cs35l34_i2c_remove()
1124 ret = regulator_bulk_enable(cs35l34->num_core_supplies, in cs35l34_runtime_resume()
1125 cs35l34->core_supplies); in cs35l34_runtime_resume()
1133 regcache_cache_only(cs35l34->regmap, false); in cs35l34_runtime_resume()
1135 gpiod_set_value_cansleep(cs35l34->reset_gpio, 1); in cs35l34_runtime_resume()
1138 ret = regcache_sync(cs35l34->regmap); in cs35l34_runtime_resume()
1145 regcache_cache_only(cs35l34->regmap, true); in cs35l34_runtime_resume()
1146 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_runtime_resume()
1147 cs35l34->core_supplies); in cs35l34_runtime_resume()
1156 regcache_cache_only(cs35l34->regmap, true); in cs35l34_runtime_suspend()
1157 regcache_mark_dirty(cs35l34->regmap); in cs35l34_runtime_suspend()
1159 gpiod_set_value_cansleep(cs35l34->reset_gpio, 0); in cs35l34_runtime_suspend()
1161 regulator_bulk_disable(cs35l34->num_core_supplies, in cs35l34_runtime_suspend()
1162 cs35l34->core_supplies); in cs35l34_runtime_suspend()