From afae98dffef32927995ce3e5abac8c622ddea389 Mon Sep 17 00:00:00 2001 From: xuwt2 Date: Thu, 16 Jul 2020 19:30:05 +0800 Subject: [PATCH] smb5: Add syfs node to offer usb_dcp_icl_ua setting To provide a sysfs node to reset the usb_dcp_icl_ua threshold, For handle different DCP icl setting for different SKU regions, Add a sysfs node in smb5 for that. Force rerun APSD after rewriting usb_dcp_icl_ua Change-Id: If7fcd97de95457dea5bcabcb41612bd1c9abdecb Signed-off-by: xuwt2 Reviewed-on: https://gerrit.mot.com/1686899 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Yonghua Yan Reviewed-by: Jianqi Yang Submit-Approved: Jira Key Reviewed-on: https://gerrit.mot.com/1771138 Reviewed-by: Huosheng Liao --- drivers/power/supply/qcom/qpnp-smb5.c | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/power/supply/qcom/qpnp-smb5.c b/drivers/power/supply/qcom/qpnp-smb5.c index 1acff1ad6633..3208bb25c552 100644 --- a/drivers/power/supply/qcom/qpnp-smb5.c +++ b/drivers/power/supply/qcom/qpnp-smb5.c @@ -281,9 +281,38 @@ static ssize_t weak_chg_icl_ua_store(struct device *dev, struct device_attribute } static DEVICE_ATTR_RW(weak_chg_icl_ua); +static ssize_t usb_dcp_icl_ua_show(struct device *dev, struct device_attribute + *attr, char *buf) +{ + struct smb5 *chip = dev_get_drvdata(dev); + struct smb_charger *chg = &chip->chg; + + return snprintf(buf, PAGE_SIZE, "%d\n", chg->usb_dcp_curr_max); +} + +static ssize_t usb_dcp_icl_ua_store(struct device *dev, struct device_attribute + *attr, const char *buf, size_t count) +{ + int val; + struct smb5 *chip = dev_get_drvdata(dev); + struct smb_charger *chg = &chip->chg; + + if (kstrtos32(buf, 0, &val)) + return -EINVAL; + + chg->usb_dcp_curr_max = val; + pr_info("USB dcp icl was rewritten as %dua\n", chg->usb_dcp_curr_max); + if (chg->real_charger_type == POWER_SUPPLY_TYPE_USB_DCP) + smblib_rerun_apsd_if_required(chg); + + return count; +} +static DEVICE_ATTR_RW(usb_dcp_icl_ua); + static struct attribute *smb5_attrs[] = { &dev_attr_pd_disabled.attr, &dev_attr_weak_chg_icl_ua.attr, + &dev_attr_usb_dcp_icl_ua.attr, NULL, }; ATTRIBUTE_GROUPS(smb5);