From 8b30a0a81851e2c4ce72a3c38bca4d7f46a44ed3 Mon Sep 17 00:00:00 2001 From: "[A" Date: Mon, 29 Aug 2022 10:20:00 +0800 Subject: [PATCH] sc89890h charger ic factory mode close ico Modify: factory mode close ico Change-Id: I3e8b3de62820074534f4829306f91a9cd7ac8c34 Signed-off-by: Reviewed-on: https://gerrit.mot.com/2372989 SME-Granted: SME Approvals Granted SLTApproved: Slta Waiver Tested-by: Jira Key Reviewed-by: Wei Xu Reviewed-by: Xiangpo Zhao Submit-Approved: Jira Key --- .../power/bq2589x_chg_mmi/bq2589x_charger.c | 41 ++++++++++++++++--- 1 file changed, 36 insertions(+), 5 deletions(-) diff --git a/drivers/power/bq2589x_chg_mmi/bq2589x_charger.c b/drivers/power/bq2589x_chg_mmi/bq2589x_charger.c index fdea3ed9c2fa..1dc4fd55b1c8 100644 --- a/drivers/power/bq2589x_chg_mmi/bq2589x_charger.c +++ b/drivers/power/bq2589x_chg_mmi/bq2589x_charger.c @@ -96,7 +96,7 @@ struct bq2589x_config { bool enable_ico; bool use_absolute_vindpm; bool disable_ilim; - + int charge_voltage; int charge_current; int term_current; @@ -185,7 +185,8 @@ struct bq2589x { struct bq2589x_iio iio; #ifdef CONFIG_MMI_QC3P_WT6670_DETECTED struct iio_channel **ext_iio_chans; -#endif +#endif + bool factory_mode; }; struct pe_ctrl { @@ -2693,7 +2694,35 @@ static int bq2589x_get_real_charger_type(struct charger_device *chg_dev, int *ch return 0; } - + +static bool bq2589x_is_factory_mode(void) +{ + struct device_node *np = of_find_node_by_path("/chosen"); + bool factory_mode = false; + const char *bootargs = NULL; + char *bootmode = NULL; + char *end = NULL; + + if (!np) + return factory_mode; + + if (!of_property_read_string(np, "bootargs", &bootargs)) { + bootmode = strstr(bootargs, "androidboot.mode="); + if (bootmode) { + end = strpbrk(bootmode, " "); + bootmode = strpbrk(bootmode, "="); + } + if (bootmode && + end > bootmode && + strnstr(bootmode, "mot-factory", end - bootmode)) { + factory_mode = true; + } + } + of_node_put(np); + + return factory_mode; +} + static int bq2589x_set_icl(struct charger_device *chg_dev, u32 uA) { struct bq2589x *bq = dev_get_drvdata(&chg_dev->dev); @@ -2708,7 +2737,7 @@ static int bq2589x_set_icl(struct charger_device *chg_dev, u32 uA) dev_info(bq->dev, "hvdcp detecting now\n"); return 0; } - if (bq->part_no == SC89890H) { + if (bq->part_no == SC89890H && bq->factory_mode) { if (mA < BQ2589X_ENABLE_ICO_THRESHOLD) { bq2589x_enable_ico(bq, false); } else { @@ -3038,7 +3067,9 @@ static int bq2589x_charger_probe(struct i2c_client *client, pe.enable = false; bq2589x_rerun_apsd_if_required(bq); - + + if (bq2589x_is_factory_mode()) + bq->factory_mode = true; return 0; err_irq: