asoc: codecs: Add bat cfg check

Add check to validate bat cfg,
bat cfg register read compared to dts read

Change-Id: Ib62ae3b3535a75dbc7c71b2b2ac3752fb2e61156
Signed-off-by: Shazmaan Ali <quic_shazmaan@quicinc.com>
This commit is contained in:
Shazmaan Ali
2022-02-07 07:30:16 -08:00
committed by Gerrit - the friendly Code Review server
parent ba5d48660f
commit 16a78f8cb3
2 changed files with 26 additions and 9 deletions

View File

@@ -366,7 +366,7 @@ struct wsa884x_priv {
int variant; int variant;
int version; int version;
u8 pa_gain; u8 pa_gain;
u8 bat_cfg; u32 bat_cfg;
u32 rload; u32 rload;
u8 system_gain; u8 system_gain;
u32 sys_gains[MAX_DEV_MODE * 2]; u32 sys_gains[MAX_DEV_MODE * 2];

View File

@@ -1103,14 +1103,19 @@ static int wsa884x_get_compander(struct snd_kcontrol *kcontrol,
* wsa884x_validate_dt_configuration_params - returns 1 or 0 * wsa884x_validate_dt_configuration_params - returns 1 or 0
* Return: 0 Valid configuration, 1 Invalid configuration * Return: 0 Valid configuration, 1 Invalid configuration
*/ */
static bool wsa884x_validate_dt_configuration_params(u8 irload, u8 ibat_cfg, static bool wsa884x_validate_dt_configuration_params(struct snd_soc_component *component,
u8 isystem_gain) u8 irload, u8 ibat_cfg_dts, u8 isystem_gain)
{ {
u8 bat_cfg_reg;
bool is_invalid_flag = true; bool is_invalid_flag = true;
bat_cfg_reg = snd_soc_component_read(component, WSA884X_VPHX_SYS_EN_STATUS);
if ((ibat_cfg_dts == EXT_1S) || (ibat_cfg_dts == EXT_2S) || (ibat_cfg_dts == EXT_3S))
ibat_cfg_dts = EXT_ABOVE_3S;
if ((WSA_4_OHMS <= irload && irload < WSA_MAX_OHMS) && if ((WSA_4_OHMS <= irload && irload < WSA_MAX_OHMS) &&
(G_21_DB <= isystem_gain && isystem_gain < G_MAX_DB) && (G_21_DB <= isystem_gain && isystem_gain < G_MAX_DB) &&
(EXT_ABOVE_3S <= ibat_cfg && ibat_cfg < CONFIG_MAX)) (EXT_ABOVE_3S <= ibat_cfg_dts && ibat_cfg_dts < CONFIG_MAX) &&
(ibat_cfg_dts == bat_cfg_reg))
is_invalid_flag = false; is_invalid_flag = false;
return is_invalid_flag; return is_invalid_flag;
@@ -2164,6 +2169,18 @@ static int wsa884x_swr_probe(struct swr_device *pdev)
goto err_mem; goto err_mem;
} }
ret = of_property_read_u32_index(
wsa884x->macro_dev->dev.of_node,
"qcom,wsa-bat-cfgs",
dev_index - 1,
&wsa884x->bat_cfg);
if (ret) {
dev_err(&pdev->dev,
"%s: Failed to read wsa bat cfgs\n",
__func__);
goto err_mem;
}
ret = of_property_read_u32(wsa884x->macro_dev->dev.of_node, ret = of_property_read_u32(wsa884x->macro_dev->dev.of_node,
"qcom,noise-gate-mode", &noise_gate_mode); "qcom,noise-gate-mode", &noise_gate_mode);
if (ret) { if (ret) {
@@ -2210,15 +2227,15 @@ static int wsa884x_swr_probe(struct swr_device *pdev)
goto err_mem; goto err_mem;
} }
wsa884x->bat_cfg = snd_soc_component_read(component,
WSA884X_VPHX_SYS_EN_STATUS);
dev_dbg(component->dev, dev_dbg(component->dev,
"%s: Bat_cfg: 0x%x, Rload: 0x%x, Sys_gain: 0x%x\n", __func__, "%s: Bat_cfg: 0x%x rload: 0x%x, sys_gain: 0x%x\n", __func__,
wsa884x->bat_cfg, wsa884x->rload, wsa884x->system_gain); wsa884x->bat_cfg, wsa884x->rload, wsa884x->system_gain);
ret = wsa884x_validate_dt_configuration_params(wsa884x->rload, ret = wsa884x_validate_dt_configuration_params(component, wsa884x->rload,
wsa884x->bat_cfg, wsa884x->system_gain); wsa884x->bat_cfg, wsa884x->system_gain);
if (ret) { if (ret) {
dev_err(&pdev->dev, "%s: invalid dt parameter\n", __func__); dev_err(&pdev->dev,
"%s: invalid dt parameter: Bat_cfg: 0x%x rload: 0x%x, sys_gain: 0x%x\n",
__func__, wsa884x->bat_cfg, wsa884x->rload, wsa884x->system_gain);
ret = -EINVAL; ret = -EINVAL;
goto err_mem; goto err_mem;
} }