From c1717e45fa5ffeba2644f60e0ee8b66c26f4eef3 Mon Sep 17 00:00:00 2001 From: xuwt2 Date: Mon, 25 Nov 2019 19:18:47 +0800 Subject: [PATCH] smb5: Only allow Moto pd policy to set pdo voltage max Base on Kernel built-in Moto PD controlling policy, pdo select depends on PD voltage max, so the product should decide which USB PD voltage is allowed, including the USB PD input power(Hardcode 18W in current code). Different product design may require different USB PD voltage allowance and USB PD input power max allowance. Current Moto PD controlling policy only applies to FIXED pdo but not programmable pdo(PPS), which requires periodic PD output power acknowledgement(at least 10s interval). So it has to redesign current Moto PD controlling policy to support PPS pdo selection. In order to avoid any PD controlling policy conflict with third party disable the PD controlling policy modification interfaces for user space (may be used by hvdcp_opti daemon in Qcom platform). Change-Id: I7565e187e2619252bc6d611b7f4aabc90b72c687 Signed-off-by: xuwt2 Reviewed-on: https://gerrit.mot.com/1461008 SLTApproved: Slta Waiver SME-Granted: SME Approvals Granted Tested-by: Jira Key Reviewed-by: Haijian Ma Reviewed-by: Yonghua Yan Reviewed-by: Jianqi Yang Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1771065 Reviewed-by: Huosheng Liao --- drivers/power/supply/qcom/smb5-iio.c | 4 ++++ drivers/power/supply/qcom/smb5-lib.c | 17 +++++++++++++++++ drivers/power/supply/qcom/smb5-lib.h | 1 + 3 files changed, 22 insertions(+) diff --git a/drivers/power/supply/qcom/smb5-iio.c b/drivers/power/supply/qcom/smb5-iio.c index 62eeafd92b66..c3cdd4416588 100644 --- a/drivers/power/supply/qcom/smb5-iio.c +++ b/drivers/power/supply/qcom/smb5-iio.c @@ -314,10 +314,14 @@ int smb5_iio_set_prop(struct smb_charger *chg, int channel, int val) rc = smblib_set_prop_pr_swap_in_progress(chg, val); break; case PSY_IIO_PD_VOLTAGE_MAX: +#ifdef QCOM_BASE rc = smblib_set_prop_pd_voltage_max(chg, val); +#endif break; case PSY_IIO_PD_VOLTAGE_MIN: +#ifdef QCOM_BASE rc = smblib_set_prop_pd_voltage_min(chg, val); +#endif break; case PSY_IIO_CONNECTOR_HEALTH: chg->connector_health = val; diff --git a/drivers/power/supply/qcom/smb5-lib.c b/drivers/power/supply/qcom/smb5-lib.c index eab526c66c0a..1446086625c4 100644 --- a/drivers/power/supply/qcom/smb5-lib.c +++ b/drivers/power/supply/qcom/smb5-lib.c @@ -7401,6 +7401,23 @@ static void smblib_pd_contract_work(struct work_struct *work) if (!chg->pd || !chg->pd_active) return; + if (!chg->pd_voltage_max_uv) { + rc = of_property_read_u32(chg->dev->of_node, + "qcom,pd-voltage-max-uv", + &chg->pd_voltage_max_uv); + if (rc < 0) { + chg->pd_voltage_max_uv = MICRO_5V; + smblib_err(chg, "Failed to get pd_voltage_max_uv" + "from device tree, rc = %d\n", rc); + } + + if (chg->pd_voltage_max_uv < MICRO_5V) + chg->pd_voltage_max_uv = MICRO_5V; + else if (chg->pd_voltage_max_uv > MICRO_12V) + chg->pd_voltage_max_uv = MICRO_12V; + } + chg->voltage_max_uv = chg->pd_voltage_max_uv; + chg->pd_contract_uv = usbpd_select_pdo_match(chg->pd); if (chg->pd_contract_uv == -ENOTSUPP) diff --git a/drivers/power/supply/qcom/smb5-lib.h b/drivers/power/supply/qcom/smb5-lib.h index 1ab71148c767..48df4a16c97c 100644 --- a/drivers/power/supply/qcom/smb5-lib.h +++ b/drivers/power/supply/qcom/smb5-lib.h @@ -613,6 +613,7 @@ struct smb_charger { /* USB PD interactions */ struct usbpd *pd; int pd_contract_uv; + int pd_voltage_max_uv; struct delayed_work pd_contract_work; /* battery profile */