From patchwork Thu Jan 27 01:12:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 014EEC433EF for ; Thu, 27 Jan 2022 01:14:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232051AbiA0BOv (ORCPT ); Wed, 26 Jan 2022 20:14:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232038AbiA0BOu (ORCPT ); Wed, 26 Jan 2022 20:14:50 -0500 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64A21C06161C for ; Wed, 26 Jan 2022 17:14:50 -0800 (PST) Received: by mail-lj1-x230.google.com with SMTP id c7so1476448ljr.13 for ; Wed, 26 Jan 2022 17:14:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZW2D4BiFOvi2PTtwabIJYLTJ12ZSsrTtv8Cw6S3q1pY=; b=WD5/bUiq2VN7kP84h7GJ7o4yVIOkt3KHtYXkJSw5jWQFBd8od77BpNm7DMYYEEh5Iq YIB0j/9HX3voh4VvGiaFKuKl4YskzJRRH+LKm3JkGJgfvrpeBCL/G5blGvTm4KQgyljS p8iQ66GXBxWbimXKhlZL33AwTXcnTMDq2esl4rV1cqBQjzL9Gz5YjIGi4r2EkhilI5BV PQhqicujjhnyQ2O4RFNYGaVDpSNQyHHB+bUIkRecm0axYfbdnJwokr8XhFJYHu6m3iQe wGl14BJiEhDZvRfJ1WaQgDIIz05/KYH0TCcnVSr3Mg/kmtqzjLisOti09RuSe7phyzNN 76lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZW2D4BiFOvi2PTtwabIJYLTJ12ZSsrTtv8Cw6S3q1pY=; b=c9c/88FErfLTQ+BCFl00ekrA29yEMvfhfYbxGwWO5CCYtAw9HfvzbF4msIoxe/8w0R zqU7RZMi94qwJmSQ01AoTyu0ZoDLtdjvDW3X25mTekT6rUCe45M6kncMjOOtkzMe6Afg cjHfgBIja3tQ3IuDLT4HH4mQLFbkvsXuG8DydJbF2A+R2sEnFWRggkS0IgbwRU2CzXI5 Km46VE+RPqkdm46Tgv70uvJEinWl99mwSzjzOvtDArPfoxFkCKOZdt5GyJ0DqeYBPL1F PwDBB5gE7XOUGKt2BcW+LihZIvu7Vd9gwSjL6k/Z82YWaISDRytmTmqglJq3KbJxrfMg s6zw== X-Gm-Message-State: AOAM5333l7gDtL4jEFEdzCdkfY8vOAn02vImZizGui7qscRre216CqUm H13mymywjtkBr4VMnwTSMX0YAQ== X-Google-Smtp-Source: ABdhPJw1jsU0j21uIZONyXZ60mJ6riVHauYpv7htTz15C1n0PoMO8E/2T49wOawFJhL/PlRQskjm6A== X-Received: by 2002:a2e:9084:: with SMTP id l4mr1241187ljg.123.1643246088664; Wed, 26 Jan 2022 17:14:48 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:48 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 01/11] power: supply: ab8500: Drop BATCTRL thermal mode Date: Thu, 27 Jan 2022 02:12:26 +0100 Message-Id: <20220127011236.332687-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The BATCTRL mode reads the temperature of the battery by enabling a certain probing current (7-20 mA) and then measure the voltage of the NTC mounted inside the battery. None of the AB8500 product or the reference designs use this mode. What we use is the so-called BATTEMP mode which enables an internal 230 kOhm pull-up to 1.8 V to the external NTC on pin BatTemp (N16) and then measures the voltage over the NTC using the ADC: 1.8V (VTVOUT) | [ ] 230 kOhm | BatTemp +---------------- ADC Pin N16 | _ |/ [/] NTC _/| | GND Cut out the BATCTRL code to clear the forest and stop maintaining code we can never test. The current inducing method is still used to probe for the battery type using the internal BTI (battery type indicator) on the BatCtrl (C3) pin in a separate code path. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500-bm.h | 16 -- drivers/power/supply/ab8500_bmdata.c | 2 - drivers/power/supply/ab8500_btemp.c | 263 +++------------------------ 3 files changed, 24 insertions(+), 257 deletions(-) diff --git a/drivers/power/supply/ab8500-bm.h b/drivers/power/supply/ab8500-bm.h index 56a5aaf9a27a..3bc6fd9337d2 100644 --- a/drivers/power/supply/ab8500-bm.h +++ b/drivers/power/supply/ab8500-bm.h @@ -260,18 +260,6 @@ enum bup_vch_sel { #define BUS_PP_PRECHG_CURRENT_MASK 0x0E #define BUS_POWER_PATH_PRECHG_ENA 0x01 -/* - * ADC for the battery thermistor. - * When using the AB8500_ADC_THERM_BATCTRL the battery ID resistor is combined - * with a NTC resistor to both identify the battery and to measure its - * temperature. Different phone manufactures uses different techniques to both - * identify the battery and to read its temperature. - */ -enum ab8500_adc_therm { - AB8500_ADC_THERM_BATCTRL, - AB8500_ADC_THERM_BATTEMP, -}; - /** * struct ab8500_res_to_temp - defines one point in a temp to res curve. To * be used in battery packs that combines the identification resistor with a @@ -423,7 +411,6 @@ struct ab8500_bm_charger_parameters { * @bkup_bat_i current which we charge the backup battery with * @no_maintenance indicates that maintenance charging is disabled * @capacity_scaling indicates whether capacity scaling is to be used - * @ab8500_adc_therm placement of thermistor, batctrl or battemp adc * @chg_unknown_bat flag to enable charging of unknown batteries * @enable_overshoot flag to enable VBAT overshoot control * @auto_trig flag to enable auto adc trigger @@ -431,7 +418,6 @@ struct ab8500_bm_charger_parameters { * @interval_charging charge alg cycle period time when charging (sec) * @interval_not_charging charge alg cycle period time when not charging (sec) * @temp_hysteresis temperature hysteresis - * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm) * @maxi maximization parameters * @cap_levels capacity in percent for the different capacity levels * @bat_type table of supported battery types @@ -452,12 +438,10 @@ struct ab8500_bm_data { bool chg_unknown_bat; bool enable_overshoot; bool auto_trig; - enum ab8500_adc_therm adc_therm; int fg_res; int interval_charging; int interval_not_charging; int temp_hysteresis; - int gnd_lift_resistance; const struct ab8500_maxim_parameters *maxi; const struct ab8500_bm_capacity_levels *cap_levels; struct ab8500_battery_type *bat_type; diff --git a/drivers/power/supply/ab8500_bmdata.c b/drivers/power/supply/ab8500_bmdata.c index 7ae95f537580..7133cce6a25a 100644 --- a/drivers/power/supply/ab8500_bmdata.c +++ b/drivers/power/supply/ab8500_bmdata.c @@ -150,7 +150,6 @@ struct ab8500_bm_data ab8500_bm_data = { .bkup_bat_i = BUP_ICH_SEL_150UA, .no_maintenance = false, .capacity_scaling = false, - .adc_therm = AB8500_ADC_THERM_BATCTRL, .chg_unknown_bat = false, .enable_overshoot = false, .fg_res = 100, @@ -158,7 +157,6 @@ struct ab8500_bm_data ab8500_bm_data = { .bat_type = &bat_type_thermistor_unknown, .interval_charging = 5, .interval_not_charging = 120, - .gnd_lift_resistance = 34, .maxi = &ab8500_maxi_params, .chg_params = &chg, .fg_params = &fg, diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c index cc33c5187fbb..a5ca09124c93 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -135,8 +135,6 @@ static LIST_HEAD(ab8500_btemp_list); static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di, int v_batctrl, int inst_curr) { - int rbs; - if (is_ab8500_1p1_or_earlier(di->parent)) { /* * For ABB cut1.0 and 1.1 BAT_CTRL is internally @@ -145,23 +143,11 @@ static int ab8500_btemp_batctrl_volt_to_res(struct ab8500_btemp *di, return (450000 * (v_batctrl)) / (1800 - v_batctrl); } - if (di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) { - /* - * If the battery has internal NTC, we use the current - * source to calculate the resistance. - */ - rbs = (v_batctrl * 1000 - - di->bm->gnd_lift_resistance * inst_curr) - / di->curr_source; - } else { - /* - * BAT_CTRL is internally - * connected to 1.8V through a 80k resistor - */ - rbs = (80000 * (v_batctrl)) / (1800 - v_batctrl); - } - - return rbs; + /* + * BAT_CTRL is internally + * connected to 1.8V through a 80k resistor + */ + return (80000 * (v_batctrl)) / (1800 - v_batctrl); } /** @@ -186,155 +172,6 @@ static int ab8500_btemp_read_batctrl_voltage(struct ab8500_btemp *di) return vbtemp; } -/** - * ab8500_btemp_curr_source_enable() - enable/disable batctrl current source - * @di: pointer to the ab8500_btemp structure - * @enable: enable or disable the current source - * - * Enable or disable the current sources for the BatCtrl AD channel - */ -static int ab8500_btemp_curr_source_enable(struct ab8500_btemp *di, - bool enable) -{ - int curr; - int ret = 0; - - /* - * BATCTRL current sources are included on AB8500 cut2.0 - * and future versions - */ - if (is_ab8500_1p1_or_earlier(di->parent)) - return 0; - - /* Only do this for batteries with internal NTC */ - if (di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL && enable) { - - if (di->curr_source == BTEMP_BATCTRL_CURR_SRC_7UA) - curr = BAT_CTRL_7U_ENA; - else - curr = BAT_CTRL_20U_ENA; - - dev_dbg(di->dev, "Set BATCTRL %duA\n", di->curr_source); - - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - FORCE_BAT_CTRL_CMP_HIGH, FORCE_BAT_CTRL_CMP_HIGH); - if (ret) { - dev_err(di->dev, "%s failed setting cmp_force\n", - __func__); - return ret; - } - - /* - * We have to wait one 32kHz cycle before enabling - * the current source, since ForceBatCtrlCmpHigh needs - * to be written in a separate cycle - */ - udelay(32); - - ret = abx500_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - FORCE_BAT_CTRL_CMP_HIGH | curr); - if (ret) { - dev_err(di->dev, "%s failed enabling current source\n", - __func__); - goto disable_curr_source; - } - } else if (di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL && !enable) { - dev_dbg(di->dev, "Disable BATCTRL curr source\n"); - - /* Write 0 to the curr bits */ - ret = abx500_mask_and_set_register_interruptible( - di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA, - ~(BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA)); - - if (ret) { - dev_err(di->dev, "%s failed disabling current source\n", - __func__); - goto disable_curr_source; - } - - /* Enable Pull-Up and comparator */ - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA, - BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA); - if (ret) { - dev_err(di->dev, "%s failed enabling PU and comp\n", - __func__); - goto enable_pu_comp; - } - - /* - * We have to wait one 32kHz cycle before disabling - * ForceBatCtrlCmpHigh since this needs to be written - * in a separate cycle - */ - udelay(32); - - /* Disable 'force comparator' */ - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - FORCE_BAT_CTRL_CMP_HIGH, ~FORCE_BAT_CTRL_CMP_HIGH); - if (ret) { - dev_err(di->dev, "%s failed disabling force comp\n", - __func__); - goto disable_force_comp; - } - } - return ret; - - /* - * We have to try unsetting FORCE_BAT_CTRL_CMP_HIGH one more time - * if we got an error above - */ -disable_curr_source: - /* Write 0 to the curr bits */ - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA, - ~(BAT_CTRL_7U_ENA | BAT_CTRL_20U_ENA)); - - if (ret) { - dev_err(di->dev, "%s failed disabling current source\n", - __func__); - return ret; - } -enable_pu_comp: - /* Enable Pull-Up and comparator */ - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA, - BAT_CTRL_PULL_UP_ENA | BAT_CTRL_CMP_ENA); - if (ret) { - dev_err(di->dev, "%s failed enabling PU and comp\n", - __func__); - return ret; - } - -disable_force_comp: - /* - * We have to wait one 32kHz cycle before disabling - * ForceBatCtrlCmpHigh since this needs to be written - * in a separate cycle - */ - udelay(32); - - /* Disable 'force comparator' */ - ret = abx500_mask_and_set_register_interruptible(di->dev, - AB8500_CHARGER, AB8500_BAT_CTRL_CURRENT_SOURCE, - FORCE_BAT_CTRL_CMP_HIGH, ~FORCE_BAT_CTRL_CMP_HIGH); - if (ret) { - dev_err(di->dev, "%s failed disabling force comp\n", - __func__); - return ret; - } - - return ret; -} - /** * ab8500_btemp_get_batctrl_res() - get battery resistance * @di: pointer to the ab8500_btemp structure @@ -350,16 +187,6 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di) int inst_curr; int i; - /* - * BATCTRL current sources are included on AB8500 cut2.0 - * and future versions - */ - ret = ab8500_btemp_curr_source_enable(di, true); - if (ret) { - dev_err(di->dev, "%s curr source enabled failed\n", __func__); - return ret; - } - if (!di->fg) di->fg = ab8500_fg_get(); if (!di->fg) { @@ -395,12 +222,6 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di) res = ab8500_btemp_batctrl_volt_to_res(di, batctrl, inst_curr); - ret = ab8500_btemp_curr_source_enable(di, false); - if (ret) { - dev_err(di->dev, "%s curr source disable failed\n", __func__); - return ret; - } - dev_dbg(di->dev, "%s batctrl: %d res: %d inst_curr: %d samples: %d\n", __func__, batctrl, res, inst_curr, i); @@ -451,47 +272,28 @@ static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di, */ static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) { - struct power_supply_battery_info *bi = di->bm->bi; int temp, ret; static int prev; - int rbat, rntc, vntc; - - if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && - (bi && (bi->technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) { - - rbat = ab8500_btemp_get_batctrl_res(di); - if (rbat < 0) { - dev_err(di->dev, "%s get batctrl res failed\n", - __func__); - /* - * Return out-of-range temperature so that - * charging is stopped - */ - return BTEMP_THERMAL_LOW_LIMIT; - } - - temp = ab8500_btemp_res_to_temp(di, - di->bm->bat_type->r_to_t_tbl, - di->bm->bat_type->n_temp_tbl_elements, rbat); - } else { - ret = iio_read_channel_processed(di->btemp_ball, &vntc); - if (ret < 0) { - dev_err(di->dev, - "%s ADC conversion failed," - " using previous value\n", __func__); - return prev; - } - /* - * The PCB NTC is sourced from VTVOUT via a 230kOhm - * resistor. - */ - rntc = 230000 * vntc / (VTVOUT_V - vntc); + int rntc, vntc; - temp = ab8500_btemp_res_to_temp(di, - di->bm->bat_type->r_to_t_tbl, - di->bm->bat_type->n_temp_tbl_elements, rntc); - prev = temp; + ret = iio_read_channel_processed(di->btemp_ball, &vntc); + if (ret < 0) { + dev_err(di->dev, + "%s ADC conversion failed," + " using previous value\n", __func__); + return prev; } + /* + * The PCB NTC is sourced from VTVOUT via a 230kOhm + * resistor. + */ + rntc = 230000 * vntc / (VTVOUT_V - vntc); + + temp = ab8500_btemp_res_to_temp(di, + di->bm->bat_type->r_to_t_tbl, + di->bm->bat_type->n_temp_tbl_elements, rntc); + prev = temp; + dev_dbg(di->dev, "Battery temperature is %d\n", temp); return temp; } @@ -519,11 +321,9 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) if ((res <= di->bm->bat_type->resis_high) && (res >= di->bm->bat_type->resis_low)) { - dev_info(di->dev, "Battery detected on %s" + dev_info(di->dev, "Battery detected on BATTEMP" " low %d < res %d < high: %d" " index: %d\n", - di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL ? - "BATCTRL" : "BATTEMP", di->bm->bat_type->resis_low, res, di->bm->bat_type->resis_high, i); } else { @@ -532,21 +332,6 @@ static int ab8500_btemp_id(struct ab8500_btemp *di) return -ENXIO; } - /* - * We only have to change current source if the - * detected type is Type 1 (LIPO) resis_high = 53407, resis_low = 12500 - * if someone hacks this in. - * - * FIXME: make sure this is done automatically for the batteries - * that need it. - */ - if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && - (di->bm->bi && (di->bm->bi->technology == POWER_SUPPLY_TECHNOLOGY_LIPO)) && - (res <= 53407) && (res >= 12500)) { - dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n"); - di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA; - } - return 0; } From patchwork Thu Jan 27 01:12:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537457 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C2E1C433FE for ; Thu, 27 Jan 2022 01:14:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232038AbiA0BOw (ORCPT ); Wed, 26 Jan 2022 20:14:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39186 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiA0BOw (ORCPT ); Wed, 26 Jan 2022 20:14:52 -0500 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37C6AC06161C for ; Wed, 26 Jan 2022 17:14:52 -0800 (PST) Received: by mail-lf1-x134.google.com with SMTP id x23so2360189lfc.0 for ; Wed, 26 Jan 2022 17:14:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=R/gXlHlEYU9y3S7brw2btRZQi4ddRdh7nKPMfXzIQjU=; b=cXvbtyEUybHqB2oFR0m4Dv5+3WDnF9mij5M2EooxS8iWuuGWl8W4pocn1mlYryGkyu nOnRVmE7gdwPpUlWEkyK6Me7KzfoLrW2K4o2leHV1d/U3gE72k404UH4PBcwzyLAaS3W uronUgffDsTBW7II2IcpsVMnJvIamPrIbw/wFhXzHyJSz8AldofkTncmRpKVY4bZEtuj L9UGhcfHcy+cvbwZw60j6Os+eNDlCAJFQWuzjAWwXe/7b5t6Ta4GWbOdU8vYaDXT8G2E Z0FkaX65J6mnwpPj9TO68t/aEP8CNvHVd9N1HVF67ysXh1g7U98GvB0bT4nOcPEVWopK SzGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=R/gXlHlEYU9y3S7brw2btRZQi4ddRdh7nKPMfXzIQjU=; b=DaFzF4h03uWsoa5hLix5aqOwjYoBi4j6unXSf5KH/SN9SmTIGh8uSP82icxIPm39P9 HA7ocQ2Fnc5kItHYEoPGzaO8EEuf5PAWw+I898o8msBlIiyz2N4SZBuj9cd0a7dkAdVU gh97/W4+nqWphBXFSdITtwmalCSc08Cw2WFQD+UjR9GP2a+VVw+oqKpFT6kRqQ4BnQFG WsyR8cnhipjrqalhc+o1DF/u3kGCqZY+M6sXLe22kEDy9SwtkUvs1Z0LhbUff33mZwVK QEPBrpJ1Z8+7d10bdvKP6rFbXDHJMJSfge0NmFG/3hIxOwde0s7hOH88BgTuTRmL3RQH 2mWw== X-Gm-Message-State: AOAM532L5AjtSq+ofGsYi5gdNT5hBzHGoVYTDNgGR901BU4l6ZmJrvoz vueCOCPGuLSqIaDk45q0ZjwTvg== X-Google-Smtp-Source: ABdhPJx3p5GmN6XiWsa1fYU3jENqHyjUy33TCf03WJGELT2vPMSI7415iBvJK0ZQsEXMjstR3L5aXg== X-Received: by 2002:ac2:55bc:: with SMTP id y28mr1277279lfg.548.1643246090562; Wed, 26 Jan 2022 17:14:50 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:50 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 02/11] power: supply: ab8500: Swap max and overvoltage Date: Thu, 27 Jan 2022 02:12:27 +0100 Message-Id: <20220127011236.332687-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org We should terminate charging when we reach the voltage_max_design_uv not overvoltage_limit_uv, this is an abuse of that struct member. The overvoltage limit is actually not configurable on the AB8500, it is fixed to 4.75 V so drop a comment about that in the code. Fixes: 2a5f41830aad ("power: supply: ab8500: Standardize voltages") Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_bmdata.c | 8 +++----- drivers/power/supply/ab8500_chargalg.c | 2 +- drivers/power/supply/ab8500_fg.c | 8 +++++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/drivers/power/supply/ab8500_bmdata.c b/drivers/power/supply/ab8500_bmdata.c index 7133cce6a25a..62b63f0437dd 100644 --- a/drivers/power/supply/ab8500_bmdata.c +++ b/drivers/power/supply/ab8500_bmdata.c @@ -186,13 +186,11 @@ int ab8500_bm_of_probe(struct power_supply *psy, * fall back to safe defaults. */ if ((bi->voltage_min_design_uv < 0) || - (bi->voltage_max_design_uv < 0) || - (bi->overvoltage_limit_uv < 0)) { + (bi->voltage_max_design_uv < 0)) { /* Nominal voltage is 3.7V for unknown batteries */ bi->voltage_min_design_uv = 3700000; - bi->voltage_max_design_uv = 3700000; - /* Termination voltage (overcharge limit) 4.05V */ - bi->overvoltage_limit_uv = 4050000; + /* Termination voltage 4.05V */ + bi->voltage_max_design_uv = 4050000; } if (bi->constant_charge_current_max_ua < 0) diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c index c4a2fe07126c..bcf85ae6828e 100644 --- a/drivers/power/supply/ab8500_chargalg.c +++ b/drivers/power/supply/ab8500_chargalg.c @@ -802,7 +802,7 @@ static void ab8500_chargalg_end_of_charge(struct ab8500_chargalg *di) if (di->charge_status == POWER_SUPPLY_STATUS_CHARGING && di->charge_state == STATE_NORMAL && !di->maintenance_chg && (di->batt_data.volt_uv >= - di->bm->bi->overvoltage_limit_uv || + di->bm->bi->voltage_max_design_uv || di->events.usb_cv_active || di->events.ac_cv_active) && di->batt_data.avg_curr_ua < di->bm->bi->charge_term_current_ua && diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index b0919a6a6587..236fd9f9d6f1 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -2263,7 +2263,13 @@ static int ab8500_fg_init_hw_registers(struct ab8500_fg *di) { int ret; - /* Set VBAT OVV threshold */ + /* + * Set VBAT OVV (overvoltage) threshold to 4.75V (typ) this is what + * the hardware supports, nothing else can be configured in hardware. + * See this as an "outer limit" where the charger will certainly + * shut down. Other (lower) overvoltage levels need to be implemented + * in software. + */ ret = abx500_mask_and_set_register_interruptible(di->dev, AB8500_CHARGER, AB8500_BATT_OVV, From patchwork Thu Jan 27 01:12:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537848 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 57E33C433F5 for ; Thu, 27 Jan 2022 01:14:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbiA0BOy (ORCPT ); Wed, 26 Jan 2022 20:14:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiA0BOy (ORCPT ); Wed, 26 Jan 2022 20:14:54 -0500 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B736BC06161C for ; Wed, 26 Jan 2022 17:14:53 -0800 (PST) Received: by mail-lj1-x229.google.com with SMTP id j14so2020408lja.3 for ; Wed, 26 Jan 2022 17:14:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FHqs4T2rMtDB+Y+pEEDFoSETpDqVbGr13PTAvmfS35Q=; b=XxXOsbWao60A2+uc6rC667EvAF/Px3ZiXRQSVnGpaex6R7M1tTGO+Zw35lyviLv81c SOP1O0w53SIQLCwC5Idu+HKPBGG7B+SA4xrVxDga6a/BssYSCYpzgD2sL5DKvf/p2JAB 0BeKb1ABaPD1qgK4SLPaDGGxwbPkDrBEJINHDjqsoxmzxys2Xmzqf5EobtKCHQtRlVsf 6mimjVp20phIXyeInLXDHGkauVJz2FIX4yCdSwwdXtRqwZUwRuA6z+S/EmtU4TzRHYL8 qK0o7zK2DFS79xK29UyV+dyBKoF+fV3vgOIr1TG8EK4YaqB+AZaKlPA5SYbprjRS2jj+ 94ng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FHqs4T2rMtDB+Y+pEEDFoSETpDqVbGr13PTAvmfS35Q=; b=pmYXfU+MzPPFRk5lPRdfgol+B94Z9FOLvkkgByCtAuhjJ2LqOVGtssBlA+GHVHyEeK om5X0+pMs0mDI0oQWUknSn/v+t0j6985p88DRYsy9vphhXoO7eb4NEaMAVgmAd0kX9ji rvrdDl7s+/BoiWDgeqh9hC/c3jiwsgkXmSwOvEF6wjWRXWYqBSjMpmbbe48QM00OCQDc Su5Xn6aQA6WaHoDhIRhDTpNCzAGJx1b/HLLneHYRBfqdoU8JlrhIMxL+DtKi0Rl9GoYX TFxwtaj0G7eyJEznvJc6Z+n5DN3DCvRvsF0q4T2xanGjFgl4cAIIp/UIoo/mF0qgg9xN Ukfw== X-Gm-Message-State: AOAM530L2JyVXltkaTJ4PSNS/5FkJJW+Stb/H80JbRGrTJK9m1ZaJKoq RHCFWoD4bRptzq9DIJRcQ3pAdw== X-Google-Smtp-Source: ABdhPJxa8O6ThfFwp7xhgfrFgYJJBCpRiR2i0VVkpBOTxnd6eVBMMSgQmElQAeHIe2W6WALu4ijP0Q== X-Received: by 2002:a2e:b0cc:: with SMTP id g12mr1273945ljl.21.1643246092016; Wed, 26 Jan 2022 17:14:52 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:51 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 03/11] power: supply: ab8500: Integrate thermal zone Date: Thu, 27 Jan 2022 02:12:28 +0100 Message-Id: <20220127011236.332687-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Instead of providing our own homebrewn thermal measurement code for an NTC and passing tables, we put the NTC thermistor into the device tree, create a passive thermal zone, and poll this thermal zone for the temperature. Signed-off-by: Linus Walleij --- drivers/power/supply/Kconfig | 2 + drivers/power/supply/ab8500-bm.h | 33 --------- drivers/power/supply/ab8500_bmdata.c | 24 ------- drivers/power/supply/ab8500_btemp.c | 103 ++++++--------------------- 4 files changed, 24 insertions(+), 138 deletions(-) diff --git a/drivers/power/supply/Kconfig b/drivers/power/supply/Kconfig index b366e2fd8e97..6815e5a4c0bd 100644 --- a/drivers/power/supply/Kconfig +++ b/drivers/power/supply/Kconfig @@ -728,6 +728,8 @@ config BATTERY_GAUGE_LTC2941 config AB8500_BM bool "AB8500 Battery Management Driver" depends on AB8500_CORE && AB8500_GPADC && (IIO = y) && OF + select THERMAL + select THERMAL_OF help Say Y to include support for AB8500 battery management. diff --git a/drivers/power/supply/ab8500-bm.h b/drivers/power/supply/ab8500-bm.h index 3bc6fd9337d2..6efd5174dbce 100644 --- a/drivers/power/supply/ab8500-bm.h +++ b/drivers/power/supply/ab8500-bm.h @@ -260,18 +260,6 @@ enum bup_vch_sel { #define BUS_PP_PRECHG_CURRENT_MASK 0x0E #define BUS_POWER_PATH_PRECHG_ENA 0x01 -/** - * struct ab8500_res_to_temp - defines one point in a temp to res curve. To - * be used in battery packs that combines the identification resistor with a - * NTC resistor. - * @temp: battery pack temperature in Celsius - * @resist: NTC resistor net total resistance - */ -struct ab8500_res_to_temp { - int temp; - int resist; -}; - /* Forward declaration */ struct ab8500_fg; @@ -351,8 +339,6 @@ struct ab8500_maxim_parameters { * @maint_b_chg_timer_h: charge time in maintenance B state * @low_high_cur_lvl: charger current in temp low/high state in mA * @low_high_vol_lvl: charger voltage in temp low/high state in mV' - * @n_r_t_tbl_elements: number of elements in r_to_t_tbl - * @r_to_t_tbl: table containing resistance to temp points */ struct ab8500_battery_type { int resis_high; @@ -365,8 +351,6 @@ struct ab8500_battery_type { int maint_b_chg_timer_h; int low_high_cur_lvl; int low_high_vol_lvl; - int n_temp_tbl_elements; - const struct ab8500_res_to_temp *r_to_t_tbl; }; /** @@ -449,23 +433,6 @@ struct ab8500_bm_data { const struct ab8500_fg_parameters *fg_params; }; -enum { - NTC_EXTERNAL = 0, - NTC_INTERNAL, -}; - -/** - * struct res_to_temp - defines one point in a temp to res curve. To - * be used in battery packs that combines the identification resistor with a - * NTC resistor. - * @temp: battery pack temperature in Celsius - * @resist: NTC resistor net total resistance - */ -struct res_to_temp { - int temp; - int resist; -}; - /* Forward declaration */ struct ab8500_fg; diff --git a/drivers/power/supply/ab8500_bmdata.c b/drivers/power/supply/ab8500_bmdata.c index 62b63f0437dd..d8fc72be0f0e 100644 --- a/drivers/power/supply/ab8500_bmdata.c +++ b/drivers/power/supply/ab8500_bmdata.c @@ -43,28 +43,6 @@ static struct power_supply_battery_ocv_table ocv_cap_tbl[] = { { .ocv = 3094000, .capacity = 0}, }; -/* - * Note that the res_to_temp table must be strictly sorted by falling - * resistance values to work. - */ -static const struct ab8500_res_to_temp temp_tbl[] = { - {-5, 214834}, - { 0, 162943}, - { 5, 124820}, - {10, 96520}, - {15, 75306}, - {20, 59254}, - {25, 47000}, - {30, 37566}, - {35, 30245}, - {40, 24520}, - {45, 20010}, - {50, 16432}, - {55, 13576}, - {60, 11280}, - {65, 9425}, -}; - /* * Note that the batres_vs_temp table must be strictly sorted by falling * temperature values to work. Factory resistance is 300 mOhm and the @@ -92,8 +70,6 @@ static struct ab8500_battery_type bat_type_thermistor_unknown = { .maint_b_chg_timer_h = 200, .low_high_cur_lvl = 300, .low_high_vol_lvl = 4000, - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), - .r_to_t_tbl = temp_tbl, }; static const struct ab8500_bm_capacity_levels cap_levels = { diff --git a/drivers/power/supply/ab8500_btemp.c b/drivers/power/supply/ab8500_btemp.c index a5ca09124c93..2a6fc151210c 100644 --- a/drivers/power/supply/ab8500_btemp.c +++ b/drivers/power/supply/ab8500_btemp.c @@ -26,13 +26,12 @@ #include #include #include +#include #include #include #include "ab8500-bm.h" -#define VTVOUT_V 1800 - #define BTEMP_THERMAL_LOW_LIMIT -10 #define BTEMP_THERMAL_MED_LIMIT 0 #define BTEMP_THERMAL_HIGH_LIMIT_52 52 @@ -82,7 +81,7 @@ struct ab8500_btemp_ranges { * @bat_temp: Dispatched battery temperature in degree Celsius * @prev_bat_temp Last measured battery temperature in degree Celsius * @parent: Pointer to the struct ab8500 - * @adc_btemp_ball: ADC channel for the battery ball temperature + * @tz: Thermal zone for the battery * @adc_bat_ctrl: ADC channel for the battery control * @fg: Pointer to the struct fg * @bm: Platform specific battery management information @@ -100,7 +99,7 @@ struct ab8500_btemp { int bat_temp; int prev_bat_temp; struct ab8500 *parent; - struct iio_channel *btemp_ball; + struct thermal_zone_device *tz; struct iio_channel *bat_ctrl; struct ab8500_fg *fg; struct ab8500_bm_data *bm; @@ -228,76 +227,6 @@ static int ab8500_btemp_get_batctrl_res(struct ab8500_btemp *di) return res; } -/** - * ab8500_btemp_res_to_temp() - resistance to temperature - * @di: pointer to the ab8500_btemp structure - * @tbl: pointer to the resiatance to temperature table - * @tbl_size: size of the resistance to temperature table - * @res: resistance to calculate the temperature from - * - * This function returns the battery temperature in degrees Celsius - * based on the NTC resistance. - */ -static int ab8500_btemp_res_to_temp(struct ab8500_btemp *di, - const struct ab8500_res_to_temp *tbl, int tbl_size, int res) -{ - int i; - /* - * Calculate the formula for the straight line - * Simple interpolation if we are within - * the resistance table limits, extrapolate - * if resistance is outside the limits. - */ - if (res > tbl[0].resist) - i = 0; - else if (res <= tbl[tbl_size - 1].resist) - i = tbl_size - 2; - else { - i = 0; - while (!(res <= tbl[i].resist && - res > tbl[i + 1].resist)) - i++; - } - - return fixp_linear_interpolate(tbl[i].resist, tbl[i].temp, - tbl[i + 1].resist, tbl[i + 1].temp, - res); -} - -/** - * ab8500_btemp_measure_temp() - measure battery temperature - * @di: pointer to the ab8500_btemp structure - * - * Returns battery temperature (on success) else the previous temperature - */ -static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) -{ - int temp, ret; - static int prev; - int rntc, vntc; - - ret = iio_read_channel_processed(di->btemp_ball, &vntc); - if (ret < 0) { - dev_err(di->dev, - "%s ADC conversion failed," - " using previous value\n", __func__); - return prev; - } - /* - * The PCB NTC is sourced from VTVOUT via a 230kOhm - * resistor. - */ - rntc = 230000 * vntc / (VTVOUT_V - vntc); - - temp = ab8500_btemp_res_to_temp(di, - di->bm->bat_type->r_to_t_tbl, - di->bm->bat_type->n_temp_tbl_elements, rntc); - prev = temp; - - dev_dbg(di->dev, "Battery temperature is %d\n", temp); - return temp; -} - /** * ab8500_btemp_id() - Identify the connected battery * @di: pointer to the ab8500_btemp structure @@ -347,6 +276,9 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) int bat_temp; struct ab8500_btemp *di = container_of(work, struct ab8500_btemp, btemp_periodic_work.work); + /* Assume 25 degrees celsius as start temperature */ + static int prev = 25; + int ret; if (!di->initialized) { /* Identify the battery */ @@ -354,7 +286,17 @@ static void ab8500_btemp_periodic_work(struct work_struct *work) dev_warn(di->dev, "failed to identify the battery\n"); } - bat_temp = ab8500_btemp_measure_temp(di); + /* Failover if a reading is erroneous, use last meausurement */ + ret = thermal_zone_get_temp(di->tz, &bat_temp); + if (ret) { + dev_err(di->dev, "error reading temperature\n"); + bat_temp = prev; + } else { + /* Convert from millicentigrades to centigrades */ + bat_temp /= 1000; + prev = bat_temp; + } + /* * Filter battery temperature. * Allow direct updates on temperature only if two samples result in @@ -783,12 +725,11 @@ static int ab8500_btemp_probe(struct platform_device *pdev) di->dev = dev; di->parent = dev_get_drvdata(pdev->dev.parent); - /* Get ADC channels */ - di->btemp_ball = devm_iio_channel_get(dev, "btemp_ball"); - if (IS_ERR(di->btemp_ball)) { - ret = dev_err_probe(dev, PTR_ERR(di->btemp_ball), - "failed to get BTEMP BALL ADC channel\n"); - return ret; + /* Get thermal zone and ADC */ + di->tz = thermal_zone_get_zone_by_name("battery-thermal"); + if (IS_ERR(di->tz)) { + return dev_err_probe(dev, PTR_ERR(di->tz), + "failed to get battery thermal zone\n"); } di->bat_ctrl = devm_iio_channel_get(dev, "bat_ctrl"); if (IS_ERR(di->bat_ctrl)) { From patchwork Thu Jan 27 01:12:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537456 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B6044C433EF for ; Thu, 27 Jan 2022 01:14:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232109AbiA0BO4 (ORCPT ); Wed, 26 Jan 2022 20:14:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiA0BOz (ORCPT ); Wed, 26 Jan 2022 20:14:55 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DEB8C06161C for ; Wed, 26 Jan 2022 17:14:55 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id u6so2203886lfm.10 for ; Wed, 26 Jan 2022 17:14:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bmo1KPyQuJu1qr8r4resFl86vrFfdMW4m6+4mc83kkc=; b=mLMLwFsg1tlE2IOMyaIdgdjx2wtEypTmr8XhH8KBbXY3bvZB3sCM3BTqiD9fTE+CV4 zfjUJyThw57Xt0TGFV24LXmbhs4HFV7H6ku+BC/OsWNxxIb4Qke4Xr8vnu9TuookmIbl IbCzFvZmtnfDNGd6oYUQ8gGSuxy05G8grEGeHQL80/gKFkwXpPpl3sr+Ewn1kTfykgOl j0CNwowxUdcPlk6lk4rZCweOzDDdV+y0IOc2SOX/BSfaaXrjWPVqhGr0EZJmZEPa32UK fDMKvZ6D65kogd8agTc7JSZ3ogL630USBph/QzUlH7jQQOWLBa3f4TLpSKNyWELRMC29 qhYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bmo1KPyQuJu1qr8r4resFl86vrFfdMW4m6+4mc83kkc=; b=2XugEn8grDyBB2XPKjh415rFlnZ/gYBxgxghP2VO7eAez0bbp18KhUeifV3ThEVZ5U q0GaLpDy26qrX+hzkHFqPfPvkLiHB8jxIfxaVYgxdBkspL8ETFCrJifYfac0M/LQVh5f 8+7+cm+9y2SRzgYmu8sNrklxkspNBXQbPsCCOQILGkqIrtgRKk8LB7jI9+PlLyf3oIE3 8IuXNGohB/F/i9+exg1hWibRimx9s7VcV33S7U0Gbnpkbyn3UmRNFrmouH06/7EbAzSP hgoBRnYj00SuyOoxZDUpdS9HCrajhB+f7ewX5/jxS8lH/FSabk8RyJhOx8XY45U9tgVH Ze+w== X-Gm-Message-State: AOAM531zMouq++95PHhME5CTqIEmV5WqRSawEOHZQzaqO64/uHBXcgZj ODbt9dcco/4MXu9etYCjaiWgrAL+5Ie9KCne X-Google-Smtp-Source: ABdhPJyCyOPha657c/qDAwnxINoitSl7JRxjpUilpIACMRrCTxatsxfbYIB3vOJ8tKK4erCAqtNjMw== X-Received: by 2002:a05:6512:1398:: with SMTP id p24mr1176929lfa.581.1643246093655; Wed, 26 Jan 2022 17:14:53 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:53 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 04/11] power: supply: ab8500_fg: Break loop for measurement Date: Thu, 27 Jan 2022 02:12:29 +0100 Message-Id: <20220127011236.332687-5-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In the Samsung code tree we find that it can happen that this measurement loop goes on for a long time, and it seems like a good idea to break it after 70 iterations if it goes on for too long. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_fg.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 236fd9f9d6f1..29896f09fd17 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -45,6 +45,7 @@ #define SEC_TO_SAMPLE(S) (S * 4) #define NBR_AVG_SAMPLES 20 +#define WAIT_FOR_INST_CURRENT_MAX 70 #define LOW_BAT_CHECK_INTERVAL (HZ / 16) /* 62.5 ms */ @@ -926,10 +927,18 @@ static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) vbat_uv += ab8500_fg_bat_voltage(di); i++; usleep_range(5000, 6000); - } while (!ab8500_fg_inst_curr_done(di)); + } while (!ab8500_fg_inst_curr_done(di) && + i <= WAIT_FOR_INST_CURRENT_MAX); + + if (i > WAIT_FOR_INST_CURRENT_MAX) { + dev_err(di->dev, + "TIMEOUT: return capacity based on uncompensated measurement of VBAT\n"); + goto calc_cap; + } ab8500_fg_inst_curr_finalize(di, &di->inst_curr_ua); +calc_cap: di->vbat_uv = vbat_uv / i; res = ab8500_fg_battery_resistance(di); From patchwork Thu Jan 27 01:12:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A746EC433F5 for ; Thu, 27 Jan 2022 01:14:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232105AbiA0BO5 (ORCPT ); Wed, 26 Jan 2022 20:14:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiA0BO5 (ORCPT ); Wed, 26 Jan 2022 20:14:57 -0500 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B452FC06161C for ; Wed, 26 Jan 2022 17:14:56 -0800 (PST) Received: by mail-lf1-x129.google.com with SMTP id a28so2230955lfl.7 for ; Wed, 26 Jan 2022 17:14:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ctCYoyyJFkpZolUjzwLxdyw/U34O4ojHAy2N2y/LCUo=; b=toBAE5YmuPv7wEVymjPSWeF9nV5wt8CXCkvWXhAF9XuL60mbV9MSxCPwkIUB5hNnNO M2zTUm/TAZ4nWUFm7i5w9nz8QS/qFF4QMkG/i5hbn2Z3rAZF7GgWKuZgQGZ2xaUzpZOH lPd9HNriiaEpgHb2Lm3XCiumGp1PITI0ja8DQ5GBeX/ZN2JGwG2IIXk5xUNu2hqcMThB WRHJOmYEjSmfkxOcH2lUa7QwKYZbRU4zDKbc4DMS2uyi1O73ACkyimpZz0W+QD5ljaMc 8xZ/7/JK2dS+CfiKXTQvcE2iDC4QDhVF0EKLu6IDxXrRV2gZjSXSzLKC2LbnDUr2kwq8 yHoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ctCYoyyJFkpZolUjzwLxdyw/U34O4ojHAy2N2y/LCUo=; b=MThcbOyBTusjIBMotqZ7j6j2EkBgBfs5THiD+ZVAZbIjzJhXdLBz62yqCyHxEgN/ve LzMqxUSEsTROEHPNaB729JN70MSk6DUdMveCJpUeLLPfXrr21wXZITnSVTdPcbL3ZP5T w2olenkvSkA+QCXJ4QDO6nvNvIGLvjCJjk+M09+v+6Z8eWNc2UzXpd3LQI+dNBXM6tHS xVmdubd3muhAZgjF7GxdGS3v9sEx5tXJYEzbMXr1vj2mqp/LJxJkUdHrnZMD2HB2jxkU gpIXg1jPFoWDmrPY7AAPHqqn6JbWcPQfHHxX9JgssOmqBqw+wavzOFHSQXO6bwssZ7Bg Tkdw== X-Gm-Message-State: AOAM530sdgdtsaXaVOvp6wW70sx1MpsEkZ82yg7jgLCgqyLmB5xinQHC 6KuCy7hi+ykF2udzvDO6Z5N1AQ== X-Google-Smtp-Source: ABdhPJxvPCip2bV9AcH3UyX8oiMizy1OfXpY4oeL3VbxjaiLk39nRUpQIvb5FW+jRqWF1iFg7zglSg== X-Received: by 2002:a05:6512:2815:: with SMTP id cf21mr1136175lfb.619.1643246095055; Wed, 26 Jan 2022 17:14:55 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:54 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 05/11] power: supply: ab8500_fg: Break out load compensated voltage Date: Thu, 27 Jan 2022 02:12:30 +0100 Message-Id: <20220127011236.332687-6-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Break out the part of the function providing the load compensated capacity that provides the load compensated voltage and use that to get the load compensated capacity. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_fg.c | 50 ++++++++++++++++++++------------ 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 29896f09fd17..8c907900a56d 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -909,18 +909,20 @@ static int ab8500_fg_battery_resistance(struct ab8500_fg *di) } /** - * ab8500_fg_load_comp_volt_to_capacity() - Load compensated voltage based capacity + * ab8500_load_comp_fg_bat_voltage() - get load compensated battery voltage * @di: pointer to the ab8500_fg structure * - * Returns battery capacity based on battery voltage that is load compensated - * for the voltage drop + * Returns compensated battery voltage (on success) else error code. + * If always is specified, we always return a voltage but it may be + * uncompensated. */ -static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) +static int ab8500_load_comp_fg_bat_voltage(struct ab8500_fg *di) { - int vbat_comp_uv, res; int i = 0; int vbat_uv = 0; + int rcomp; + /* Average the instant current to get a stable current measurement */ ab8500_fg_inst_curr_start(di); do { @@ -932,25 +934,37 @@ static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) if (i > WAIT_FOR_INST_CURRENT_MAX) { dev_err(di->dev, - "TIMEOUT: return capacity based on uncompensated measurement of VBAT\n"); - goto calc_cap; + "TIMEOUT: return uncompensated measurement of VBAT\n"); + di->vbat_uv = vbat_uv / i; + return di->vbat_uv; } ab8500_fg_inst_curr_finalize(di, &di->inst_curr_ua); -calc_cap: - di->vbat_uv = vbat_uv / i; - res = ab8500_fg_battery_resistance(di); + vbat_uv = vbat_uv / i; - /* - * Use Ohms law to get the load compensated voltage. - * Divide by 1000 to get from milliohms to ohms. - */ - vbat_comp_uv = di->vbat_uv - (di->inst_curr_ua * res) / 1000; + /* Next we apply voltage compensation from internal resistance */ + rcomp = ab8500_fg_battery_resistance(di, vbat_uv); + vbat_uv = vbat_uv - (di->inst_curr_ua * rcomp) / 1000; + + /* Always keep this state at latest measurement */ + di->vbat_uv = vbat_uv; + + return vbat_uv; +} + +/** + * ab8500_fg_load_comp_volt_to_capacity() - Load compensated voltage based capacity + * @di: pointer to the ab8500_fg structure + * + * Returns battery capacity based on battery voltage that is load compensated + * for the voltage drop + */ +static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) +{ + int vbat_comp_uv; - dev_dbg(di->dev, "%s Measured Vbat: %d uV,Compensated Vbat %d uV, " - "R: %d mOhm, Current: %d uA Vbat Samples: %d\n", - __func__, di->vbat_uv, vbat_comp_uv, res, di->inst_curr_ua, i); + vbat_comp_uv = ab8500_load_comp_fg_bat_voltage(di); return ab8500_fg_volt_to_capacity(di, vbat_comp_uv); } From patchwork Thu Jan 27 01:12:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537455 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9131EC433EF for ; Thu, 27 Jan 2022 01:14:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232110AbiA0BO7 (ORCPT ); Wed, 26 Jan 2022 20:14:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232031AbiA0BO6 (ORCPT ); Wed, 26 Jan 2022 20:14:58 -0500 Received: from mail-lj1-x22f.google.com (mail-lj1-x22f.google.com [IPv6:2a00:1450:4864:20::22f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5CE5EC06161C for ; Wed, 26 Jan 2022 17:14:58 -0800 (PST) Received: by mail-lj1-x22f.google.com with SMTP id e17so2009590ljk.5 for ; Wed, 26 Jan 2022 17:14:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IrjM1MQ0G3FDaMRIIRJA5dUwbfXPuiWXnRfRN9yfCGg=; b=VTyiQGofjVVGxfgX8nhW+RrcsQ4MDxnqT8D2u3YwESeYdlT5/Js6ANjWs2lAlBWjy7 2ZTCUk+7TW8ND2zSO6U6cIK4bcolPI32lbyJI18LDIxAFnyjPZZsGXRHkd+Oe2NAPJZ0 xqRCYOwr10vtVKmr9m+dqeTihUz2XD4Cof8rSQZfcwMwRzW0BuLyy1fRqRdNV5LWk/9R cRiJURqzD6yooPVA8XuvIAOgqR0pfFSkhBYol43KwmHk2sXRPIwVgH4Md5qivnhOjwpV u7gGlIGVcl91DsMtIGGvH93pWQ7ysr7Js7fOdH06w/U7sY/HUSK9KjeuiyX3Pxvi9qOk 7VuQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IrjM1MQ0G3FDaMRIIRJA5dUwbfXPuiWXnRfRN9yfCGg=; b=Dbp+VndXXuEhCKPQfH84wbOpfZ1DlEfWVxhFIdjS72n/5FAB74u5sWm9ieUA3itKp6 NbIHqaARaDiLipTM1pa3PjqU3E09dslrkVzfaXobnxUiBV7tOxH2yQr2CLI6FJFdB69V ApE3CEwrlQ+VzNUlkYNTT8RaFG32kCTRIQsaf/vByaDLRKdE81PCFtQB9FtPUexcwy+h iys+9w3Ggn/PKNpFcnuF8rzR0iDuPm2H+51xSm0E0ZUDbb3CBvbz8gvYLkZmDg9k3DEl aug7kW2MMK1Ks/oYpD9H4nIalz5UVtzO120GkW6Mp2AP2hyiFWiAgc1YLmkjkbLIJZ7F 1x+Q== X-Gm-Message-State: AOAM532KmAiEqVQBwEOaruckoMmOVdCFCwBSe2ENa6E7KCdt4EcyVof3 jAxNelHZ/Fx8eHfd8hubGncJEg== X-Google-Smtp-Source: ABdhPJwHxTO5JSUWk/GCdV1dOFx1HsvVxIbAOvCwWDFsDzhoQe9W67wp8jHZP/Q4nUHN47Kf3S1/rA== X-Received: by 2002:a2e:a378:: with SMTP id i24mr1299003ljn.240.1643246096749; Wed, 26 Jan 2022 17:14:56 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:56 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 06/11] power: supply: ab8500_fg: Safeguard compensated voltage Date: Thu, 27 Jan 2022 02:12:31 +0100 Message-Id: <20220127011236.332687-7-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org In some cases when the platform is dissapating more than 500mA the voltage measurements and compensation will become instable. Add a parameter to bail out of the voltage measurement if this happens. This code was found in a Samsung vendor tree. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_fg.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 8c907900a56d..323f6bacefd8 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -46,6 +46,8 @@ #define NBR_AVG_SAMPLES 20 #define WAIT_FOR_INST_CURRENT_MAX 70 +/* Currents higher than -500mA (dissipating) will make compensation unstable */ +#define IGNORE_VBAT_HIGHCUR -500000 #define LOW_BAT_CHECK_INTERVAL (HZ / 16) /* 62.5 ms */ @@ -911,12 +913,13 @@ static int ab8500_fg_battery_resistance(struct ab8500_fg *di) /** * ab8500_load_comp_fg_bat_voltage() - get load compensated battery voltage * @di: pointer to the ab8500_fg structure + * @always: always return a voltage, also uncompensated * * Returns compensated battery voltage (on success) else error code. * If always is specified, we always return a voltage but it may be * uncompensated. */ -static int ab8500_load_comp_fg_bat_voltage(struct ab8500_fg *di) +static int ab8500_load_comp_fg_bat_voltage(struct ab8500_fg *di, bool always) { int i = 0; int vbat_uv = 0; @@ -941,6 +944,14 @@ static int ab8500_load_comp_fg_bat_voltage(struct ab8500_fg *di) ab8500_fg_inst_curr_finalize(di, &di->inst_curr_ua); + /* + * If there is too high current dissipation, the compensation cannot be + * trusted so return an error unless we must return something here, as + * enforced by the "always" parameter. + */ + if (!always && di->inst_curr_ua < IGNORE_VBAT_HIGHCUR) + return -EINVAL; + vbat_uv = vbat_uv / i; /* Next we apply voltage compensation from internal resistance */ @@ -964,7 +975,7 @@ static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) { int vbat_comp_uv; - vbat_comp_uv = ab8500_load_comp_fg_bat_voltage(di); + vbat_comp_uv = ab8500_load_comp_fg_bat_voltage(di, true); return ab8500_fg_volt_to_capacity(di, vbat_comp_uv); } From patchwork Thu Jan 27 01:12:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0B012C433EF for ; Thu, 27 Jan 2022 01:15:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232031AbiA0BPA (ORCPT ); Wed, 26 Jan 2022 20:15:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232128AbiA0BPA (ORCPT ); Wed, 26 Jan 2022 20:15:00 -0500 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E05FC06161C for ; Wed, 26 Jan 2022 17:15:00 -0800 (PST) Received: by mail-lf1-x12a.google.com with SMTP id z19so2173932lfq.13 for ; Wed, 26 Jan 2022 17:14:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=r9/KleBGoO0PO95Mx9jAXT4YN2e2L9g/3cjOpS4m2Og=; b=Uur9cwQYEtlq9UTRd353wREk9TgzYS1t4rt9DwbMXKOIa14TvjvJ5X7bZgeqp7Gwb1 73/gNDuCYh0qhknuJ4WAKrbSAuPVBSYRfu746lbfQmiO9rnvcDnKlbLOq/HAuQLaaRzz 1e5iJv/7yR7w3UF8BD54WnDoLP8YvWqgN9rMjRYjnyAmKF6bGXDai5lPHlIxqB5XmEYS HtfwDGowjxelE3mgM6pWQ+lj5eSRgF2Gn/yGgyPpEAyFhsN4C6ZGH+5iye6EpI4zhU02 SHayC/SCSbM+LotrE412pRNG47BOeXtEgmmO7zRLvXm3JQER3R1wsLTbo3tpqqsYN+h3 razQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=r9/KleBGoO0PO95Mx9jAXT4YN2e2L9g/3cjOpS4m2Og=; b=kx13k53PwGg8J72dflfCBQIq0TDpZUBQ1zhjT3nHQsoilrLMiSNb+DeNiRksUMbr22 QO7N2RmiCf4bq5fTNg146AeRmv5ebsaYvupHQlvAzVntGfLWFh7zt6xsFEopU/XG5zzv 3hL7kJInR00Me/VH2Rpder7ezHw+3b6r0GJaI9gwi9evakzpXOwN8oJAaQ6FkEVfp6x+ GwKtc/DqRcOlLB0vTMXYT/w0EcAVtW6lWwYmgcpYqTgo47wJiBHrU5u+ixPsU4PbaMFK 81T/HpsaH1+Qd+MMUr3WYm0utHdeUQMFipAutTS2orBJL3J/90fnot1FVQ5P6+0L08x6 TSNA== X-Gm-Message-State: AOAM532/o9tH8bW6zBuU2z/hYnaEx3xJ/CSHy/K+emuNH1E6LotSOPR6 z+xxPEPVTTWHZpegXh/E4yrkbA== X-Google-Smtp-Source: ABdhPJyJgNa0PwxJwof/RQfYwTUyhbhFZZEMeWJah93XGYuW+cA4hvT2Yjv+TWzWZpuXgIdN8OnpZA== X-Received: by 2002:a05:6512:2347:: with SMTP id p7mr1227546lfu.123.1643246098405; Wed, 26 Jan 2022 17:14:58 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:58 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 07/11] power: supply: ab8500_fg: Drop useless parameter Date: Thu, 27 Jan 2022 02:12:32 +0100 Message-Id: <20220127011236.332687-8-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org All calls to ab8500_fg_calc_cap_discharge_voltage() require compensation and pass true as the second argument so just drop this argument. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_fg.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/drivers/power/supply/ab8500_fg.c b/drivers/power/supply/ab8500_fg.c index 323f6bacefd8..fa61ecebbce3 100644 --- a/drivers/power/supply/ab8500_fg.c +++ b/drivers/power/supply/ab8500_fg.c @@ -1073,20 +1073,16 @@ static int ab8500_fg_calc_cap_charging(struct ab8500_fg *di) /** * ab8500_fg_calc_cap_discharge_voltage() - Capacity in discharge with voltage * @di: pointer to the ab8500_fg structure - * @comp: if voltage should be load compensated before capacity calc * - * Return the capacity in mAh based on the battery voltage. The voltage can - * either be load compensated or not. This value is added to the filter and a - * new mean value is calculated and returned. + * Return the capacity in mAh based on the load compensated battery voltage. + * This value is added to the filter and a new mean value is calculated and + * returned. */ -static int ab8500_fg_calc_cap_discharge_voltage(struct ab8500_fg *di, bool comp) +static int ab8500_fg_calc_cap_discharge_voltage(struct ab8500_fg *di) { int permille, mah; - if (comp) - permille = ab8500_fg_load_comp_volt_to_capacity(di); - else - permille = ab8500_fg_uncomp_volt_to_capacity(di); + permille = ab8500_fg_load_comp_volt_to_capacity(di); mah = ab8500_fg_convert_permille_to_mah(di, permille); @@ -1563,7 +1559,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) /* Discard the first [x] seconds */ if (di->init_cnt > di->bm->fg_params->init_discard_time) { - ab8500_fg_calc_cap_discharge_voltage(di, true); + ab8500_fg_calc_cap_discharge_voltage(di); ab8500_fg_check_capacity_limits(di, true); } @@ -1646,7 +1642,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) break; } - ab8500_fg_calc_cap_discharge_voltage(di, true); + ab8500_fg_calc_cap_discharge_voltage(di); } else { mutex_lock(&di->cc_lock); if (!di->flags.conv_done) { @@ -1680,7 +1676,7 @@ static void ab8500_fg_algorithm_discharging(struct ab8500_fg *di) break; case AB8500_FG_DISCHARGE_WAKEUP: - ab8500_fg_calc_cap_discharge_voltage(di, true); + ab8500_fg_calc_cap_discharge_voltage(di); di->fg_samples = SEC_TO_SAMPLE( di->bm->fg_params->accu_high_curr); @@ -1799,7 +1795,7 @@ static void ab8500_fg_periodic_work(struct work_struct *work) if (di->init_capacity) { /* Get an initial capacity calculation */ - ab8500_fg_calc_cap_discharge_voltage(di, true); + ab8500_fg_calc_cap_discharge_voltage(di); ab8500_fg_check_capacity_limits(di, true); di->init_capacity = false; @@ -2422,7 +2418,7 @@ static void ab8500_fg_reinit_work(struct work_struct *work) if (!di->flags.calibrate) { dev_dbg(di->dev, "Resetting FG state machine to init.\n"); ab8500_fg_clear_cap_samples(di); - ab8500_fg_calc_cap_discharge_voltage(di, true); + ab8500_fg_calc_cap_discharge_voltage(di); ab8500_fg_charge_state_to(di, AB8500_FG_CHARGE_INIT); ab8500_fg_discharge_state_to(di, AB8500_FG_DISCHARGE_INIT); queue_delayed_work(di->fg_wq, &di->fg_periodic_work, 0); From patchwork Thu Jan 27 01:12:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537454 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3100C433F5 for ; Thu, 27 Jan 2022 01:15:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232128AbiA0BPC (ORCPT ); Wed, 26 Jan 2022 20:15:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232720AbiA0BPC (ORCPT ); Wed, 26 Jan 2022 20:15:02 -0500 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB7C6C06173B for ; Wed, 26 Jan 2022 17:15:01 -0800 (PST) Received: by mail-lf1-x133.google.com with SMTP id z4so2268037lft.3 for ; Wed, 26 Jan 2022 17:15:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xI1RSZYqgsQ81M8OcAMrVpP/Yu138GU0W7y71VAKSdU=; b=SJlLf/q/PguG7p2Ts0u+C2vBez6/Hr1hNeyjaJoR31YSM5JMH+H04u9VG/k4ZUoaqm 3s4gu7illZ0ZhVE8IaFYMV6u0MNjQfKCDuhNqm5JOBOEOENVk/PD1wzNr65YUX2wJfpw 4V4GarToXYGSqsvAcnr+8GsVl8b0oVRGHGkeUPIwXRDn9WPgsmQUupH/cV77JUBxF5UZ aXkhQcryblYsxhqFm2jHkq63fH6lBSgmrs/a1tqmLYi5puLAtfmRXKQpwz03QBApRbL0 cDjR7rLT/qGQbTWW+3GfTmFPfseNqq9Te7Ksgyt+rVTEt6P9NG/xS19LTgC/ZI+qADkg IcNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xI1RSZYqgsQ81M8OcAMrVpP/Yu138GU0W7y71VAKSdU=; b=f0ZjAyTICvBfsa7Q0KcLhhjAypwPKVAFrMcOEorvbHquJ/pWOW2TvqZA08fqOaxaiT vYl6H4oVz3FOoPyElzpcHf2VQfg83qaaW9uIa/sRh7AAJBs8UvCewAKDV+2cB8BJBFDC jul/2T5oKasI8jVtIO7tjS4KsDRWYuKq2/zjooOb/h0WvnM0pClHodaw0/y4PcFUxZhf iqjHBXi7PXuag/xim2wsIu6QfQMgpogZ5q8hsjeqJIWoAGpNzbxGWZtL1rC2HG18nbn4 dQ4NfJuKtiYzsF10LO0XmlJqJjHUiAlBlD1LvOTnZmoOXjP0TvDLK9QPvysroTvCsoYe /O3w== X-Gm-Message-State: AOAM531wgpC1DiWrNxuIFw36XFtqVad5408mtwDuT8MsUMbx9N3ZYTAc rq18umpAlAw1ziOUgFNSgaM5eg== X-Google-Smtp-Source: ABdhPJwHa9t452xK7pptztdTSYNzr9G5P31oRlKbz88Fx1uVmdUf/18QY4VIRdp6MP/s33ksUkfHAw== X-Received: by 2002:ac2:43ae:: with SMTP id t14mr1140436lfl.599.1643246100136; Wed, 26 Jan 2022 17:15:00 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.14.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:14:59 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 08/11] power: supply: ab8500_chargalg: Drop charging step Date: Thu, 27 Jan 2022 02:12:33 +0100 Message-Id: <20220127011236.332687-9-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There is a sysfs ABI to change the "charging step" of the charger i.e. limit how much we charge from userspace. Since we don't have any userspace for this code, this sits unused and it is not used on production products either. Drop this code. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_chargalg.c | 105 ++----------------------- 1 file changed, 6 insertions(+), 99 deletions(-) diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c index bcf85ae6828e..9f9a84ad2da2 100644 --- a/drivers/power/supply/ab8500_chargalg.c +++ b/drivers/power/supply/ab8500_chargalg.c @@ -46,9 +46,6 @@ /* Five minutes expressed in seconds */ #define FIVE_MINUTES_IN_SECONDS 300 -#define CHARGALG_CURR_STEP_LOW_UA 0 -#define CHARGALG_CURR_STEP_HIGH_UA 100000 - /* * This is the battery capacity limit that will trigger a new * full charging cycle in the case where maintenance charging @@ -86,11 +83,6 @@ struct ab8500_chargalg_suspension_status { bool usb_suspended; }; -struct ab8500_chargalg_current_step_status { - bool curr_step_change; - int curr_step_ua; -}; - struct ab8500_chargalg_battery_data { int temp; int volt_uv; @@ -186,8 +178,6 @@ struct ab8500_chargalg_events { * struct ab8500_charge_curr_maximization - Charger maximization parameters * @original_iset_ua: the non optimized/maximised charger current * @current_iset_ua: the charging current used at this moment - * @test_delta_i_ua: the delta between the current we want to charge and the - current that is really going into the battery * @condition_cnt: number of iterations needed before a new charger current is set * @max_current_ua: maximum charger current @@ -200,7 +190,6 @@ struct ab8500_chargalg_events { struct ab8500_charge_curr_maximization { int original_iset_ua; int current_iset_ua; - int test_delta_i_ua; int condition_cnt; int max_current_ua; int wait_cnt; @@ -229,7 +218,6 @@ enum maxim_ret { * @batt_data: data of the battery * @susp_status: current charger suspension status * @bm: Platform specific battery management information - * @curr_status: Current step status for over-current protection * @parent: pointer to the struct ab8500 * @chargalg_psy: structure that holds the battery properties exposed by * the charging algorithm @@ -255,7 +243,6 @@ struct ab8500_chargalg { struct ab8500_chargalg_battery_data batt_data; struct ab8500_chargalg_suspension_status susp_status; struct ab8500 *parent; - struct ab8500_chargalg_current_step_status curr_status; struct ab8500_bm_data *bm; struct power_supply *chargalg_psy; struct ux500_charger *ac_chg; @@ -420,22 +407,6 @@ static int ab8500_chargalg_check_charger_connection(struct ab8500_chargalg *di) return di->chg_info.conn_chg; } -/** - * ab8500_chargalg_check_current_step_status() - Check charging current - * step status. - * @di: pointer to the ab8500_chargalg structure - * - * This function will check if there is a change in the charging current step - * and change charge state accordingly. - */ -static void ab8500_chargalg_check_current_step_status - (struct ab8500_chargalg *di) -{ - if (di->curr_status.curr_step_change) - ab8500_chargalg_state_to(di, STATE_NORMAL_INIT); - di->curr_status.curr_step_change = false; -} - /** * ab8500_chargalg_start_safety_timer() - Start charging safety timer * @di: pointer to the ab8500_chargalg structure @@ -831,7 +802,6 @@ static void init_maxim_chg_curr(struct ab8500_chargalg *di) di->ccm.original_iset_ua = bi->constant_charge_current_max_ua; di->ccm.current_iset_ua = bi->constant_charge_current_max_ua; - di->ccm.test_delta_i_ua = di->bm->maxi->charger_curr_step_ua; di->ccm.max_current_ua = di->bm->maxi->chg_curr_ua; di->ccm.condition_cnt = di->bm->maxi->wait_cycles; di->ccm.level = 0; @@ -862,8 +832,7 @@ static enum maxim_ret ab8500_chargalg_chg_curr_maxim(struct ab8500_chargalg *di) dev_dbg(di->dev, "lowering current\n"); di->ccm.wait_cnt++; di->ccm.condition_cnt = di->bm->maxi->wait_cycles; - di->ccm.max_current_ua = - di->ccm.current_iset_ua - di->ccm.test_delta_i_ua; + di->ccm.max_current_ua = di->ccm.current_iset_ua; di->ccm.current_iset_ua = di->ccm.max_current_ua; di->ccm.level--; return MAXIM_RET_CHANGE; @@ -893,29 +862,8 @@ static enum maxim_ret ab8500_chargalg_chg_curr_maxim(struct ab8500_chargalg *di) return MAXIM_RET_IBAT_TOO_HIGH; } - if (delta_i_ua > di->ccm.test_delta_i_ua && - (di->ccm.current_iset_ua + di->ccm.test_delta_i_ua) < - di->ccm.max_current_ua) { - if (di->ccm.condition_cnt-- == 0) { - /* Increse the iset with cco.test_delta_i */ - di->ccm.condition_cnt = di->bm->maxi->wait_cycles; - di->ccm.current_iset_ua += di->ccm.test_delta_i_ua; - di->ccm.level++; - dev_dbg(di->dev, " Maximization needed, increase" - " with %d uA to %duA (Optimal ibat: %d uA)" - " Level %d\n", - di->ccm.test_delta_i_ua, - di->ccm.current_iset_ua, - di->ccm.original_iset_ua, - di->ccm.level); - return MAXIM_RET_CHANGE; - } else { - return MAXIM_RET_NOACTION; - } - } else { - di->ccm.condition_cnt = di->bm->maxi->wait_cycles; - return MAXIM_RET_NOACTION; - } + di->ccm.condition_cnt = di->bm->maxi->wait_cycles; + return MAXIM_RET_NOACTION; } static void handle_maxim_chg_curr(struct ab8500_chargalg *di) @@ -1302,7 +1250,6 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) struct power_supply_battery_info *bi = di->bm->bi; int charger_status; int ret; - int curr_step_lvl_ua; /* Collect data from all power_supply class devices */ class_for_each_device(power_supply_class, NULL, @@ -1313,7 +1260,6 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) ab8500_chargalg_check_charger_voltage(di); charger_status = ab8500_chargalg_check_charger_connection(di); - ab8500_chargalg_check_current_step_status(di); if (is_ab8500(di->parent)) { ret = ab8500_chargalg_check_charger_enable(di); @@ -1511,15 +1457,13 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) break; case STATE_NORMAL_INIT: - if (di->curr_status.curr_step_ua == CHARGALG_CURR_STEP_LOW_UA) + if (bi->constant_charge_current_max_ua == 0) + /* "charging" with 0 uA */ ab8500_chargalg_stop_charging(di); else { - curr_step_lvl_ua = bi->constant_charge_current_max_ua - * di->curr_status.curr_step_ua - / CHARGALG_CURR_STEP_HIGH_UA; ab8500_chargalg_start_charging(di, bi->constant_charge_voltage_max_uv, - curr_step_lvl_ua); + bi->constant_charge_current_max_ua); } ab8500_chargalg_state_to(di, STATE_NORMAL); @@ -1742,37 +1686,6 @@ static int ab8500_chargalg_get_property(struct power_supply *psy, /* Exposure to the sysfs interface */ -static ssize_t ab8500_chargalg_curr_step_show(struct ab8500_chargalg *di, - char *buf) -{ - return sprintf(buf, "%d\n", di->curr_status.curr_step_ua); -} - -static ssize_t ab8500_chargalg_curr_step_store(struct ab8500_chargalg *di, - const char *buf, size_t length) -{ - long param; - int ret; - - ret = kstrtol(buf, 10, ¶m); - if (ret < 0) - return ret; - - di->curr_status.curr_step_ua = param; - if (di->curr_status.curr_step_ua >= CHARGALG_CURR_STEP_LOW_UA && - di->curr_status.curr_step_ua <= CHARGALG_CURR_STEP_HIGH_UA) { - di->curr_status.curr_step_change = true; - queue_work(di->chargalg_wq, &di->chargalg_work); - } else - dev_info(di->dev, "Wrong current step\n" - "Enter 0. Disable AC/USB Charging\n" - "1--100. Set AC/USB charging current step\n" - "100. Enable AC/USB Charging\n"); - - return strlen(buf); -} - - static ssize_t ab8500_chargalg_en_show(struct ab8500_chargalg *di, char *buf) { @@ -1832,10 +1745,6 @@ static struct ab8500_chargalg_sysfs_entry ab8500_chargalg_en_charger = __ATTR(chargalg, 0644, ab8500_chargalg_en_show, ab8500_chargalg_en_store); -static struct ab8500_chargalg_sysfs_entry ab8500_chargalg_curr_step = - __ATTR(chargalg_curr_step, 0644, ab8500_chargalg_curr_step_show, - ab8500_chargalg_curr_step_store); - static ssize_t ab8500_chargalg_sysfs_show(struct kobject *kobj, struct attribute *attr, char *buf) { @@ -1868,7 +1777,6 @@ static ssize_t ab8500_chargalg_sysfs_charger(struct kobject *kobj, static struct attribute *ab8500_chargalg_chg[] = { &ab8500_chargalg_en_charger.attr, - &ab8500_chargalg_curr_step.attr, NULL, }; @@ -2057,7 +1965,6 @@ static int ab8500_chargalg_probe(struct platform_device *pdev) dev_err(di->dev, "failed to create sysfs entry\n"); return ret; } - di->curr_status.curr_step_ua = CHARGALG_CURR_STEP_HIGH_UA; dev_info(di->dev, "probe success\n"); return component_add(dev, &ab8500_chargalg_component_ops); From patchwork Thu Jan 27 01:12:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537453 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0C757C433EF for ; Thu, 27 Jan 2022 01:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232155AbiA0BPF (ORCPT ); Wed, 26 Jan 2022 20:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39246 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232134AbiA0BPE (ORCPT ); Wed, 26 Jan 2022 20:15:04 -0500 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7399EC06161C for ; Wed, 26 Jan 2022 17:15:03 -0800 (PST) Received: by mail-lf1-x12f.google.com with SMTP id u14so2195512lfo.11 for ; Wed, 26 Jan 2022 17:15:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+oO7HwNMY4aHvue+tWipCamLbhgFX5YMJnEMGCppnFg=; b=pw8u3NzKOd+yWDw8PpZVeP5lANf8Z8FQF5f8SIOLna5VUzszsAwh8UFArpGku7sN1D RwTOAdyrwdjd1TQu/yeHuYSG2UPuVElD6yBYwCGoF2kBGGiWzXiC28s1t6XaNniZQCck Ug6/GNEK6z/eLUwSQzRY3IJCgzRkSEMrWz09OYjzdENIQ/Z7ZkrigF+PPQxaYJQKvMdK ixZlufnYayjn+B/SyfSdn6eBlOn4PeOUhKqx77hxu3FrgHYLO9Kg5kfPrAaycWvr9Z2m TxvHBbq288dr575F/aT6vjfVI+PYrXJhFNBlHK+e5mIa5oF8qzysfrMcdmNL7V4/e/7z x3og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+oO7HwNMY4aHvue+tWipCamLbhgFX5YMJnEMGCppnFg=; b=W2Al1/KcpIT/2tA1/V8ZGF55CboL0HKBtn9MNFNZous9Gcn+mhmb6n++w9mObVn/yZ v4RQ3EtlulGrlQB4+Y8yaCaDghPVGdaezZd0y5yfxbqIprRz1T43wCurThRk6RanCgi3 f1Hsn1w4AiyPig3KT3fwfBlghJCVbC0FmTiBXsGR9plB5U7AwQVdkcBTrC9MGjWabn0R q4sUtwTLxOMFR3M7uZPZriVGa1dRHvdwHTZl8+1UNAg6q22p7zGINv5rh/jw5DNmpcoy gQD2pFuvu+XWXcY2G+edD2aSBZ1N7QAWkiw6kn8fkYT9jV+fXqM2AoLSteuGSpKQyRoL iiyQ== X-Gm-Message-State: AOAM531LATu5VW7+iquoWldUjKEV+HB5SJfViOA+hAaTCH7Tm1o4QhEH JT8u29tb1WLTEJujMeiOWIuqYRyABgbJXQ== X-Google-Smtp-Source: ABdhPJxNtH8OjF36YpOzBl6JPSfAbE8xdgGNnLh5OE7gWKDPBC/2OV+u4cI+rs9cVCnWqxyex9DeWA== X-Received: by 2002:a05:6512:114d:: with SMTP id m13mr1182951lfg.650.1643246101808; Wed, 26 Jan 2022 17:15:01 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.15.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:15:01 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 09/11] power: supply: ab8500_chargalg: Drop enable/disable sysfs Date: Thu, 27 Jan 2022 02:12:34 +0100 Message-Id: <20220127011236.332687-10-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org There is a sysfs ABI to enable/disable charging of different types (AC/USB). Since we don't have any userspace for this code, this sits unused and it is not used on production products either. Drop this code. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_chargalg.c | 211 +------------------------ 1 file changed, 6 insertions(+), 205 deletions(-) diff --git a/drivers/power/supply/ab8500_chargalg.c b/drivers/power/supply/ab8500_chargalg.c index 9f9a84ad2da2..b5a3096e78a1 100644 --- a/drivers/power/supply/ab8500_chargalg.c +++ b/drivers/power/supply/ab8500_chargalg.c @@ -77,12 +77,6 @@ struct ab8500_chargalg_charger_info { int ac_iset_ua; }; -struct ab8500_chargalg_suspension_status { - bool suspended_change; - bool ac_suspended; - bool usb_suspended; -}; - struct ab8500_chargalg_battery_data { int temp; int volt_uv; @@ -110,8 +104,6 @@ enum ab8500_chargalg_states { STATE_TEMP_UNDEROVER, STATE_TEMP_LOWHIGH_INIT, STATE_TEMP_LOWHIGH, - STATE_SUSPENDED_INIT, - STATE_SUSPENDED, STATE_OVV_PROTECT_INIT, STATE_OVV_PROTECT, STATE_SAFETY_TIMER_EXPIRED_INIT, @@ -141,8 +133,6 @@ static const char * const states[] = { "TEMP_UNDEROVER", "TEMP_LOWHIGH_INIT", "TEMP_LOWHIGH", - "SUSPENDED_INIT", - "SUSPENDED", "OVV_PROTECT_INIT", "OVV_PROTECT", "SAFETY_TIMER_EXPIRED_INIT", @@ -216,7 +206,6 @@ enum maxim_ret { * @ccm charging current maximization parameters * @chg_info: information about connected charger types * @batt_data: data of the battery - * @susp_status: current charger suspension status * @bm: Platform specific battery management information * @parent: pointer to the struct ab8500 * @chargalg_psy: structure that holds the battery properties exposed by @@ -241,7 +230,6 @@ struct ab8500_chargalg { struct ab8500_charge_curr_maximization ccm; struct ab8500_chargalg_charger_info chg_info; struct ab8500_chargalg_battery_data batt_data; - struct ab8500_chargalg_suspension_status susp_status; struct ab8500 *parent; struct ab8500_bm_data *bm; struct power_supply *chargalg_psy; @@ -372,37 +360,24 @@ static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di) */ static int ab8500_chargalg_check_charger_connection(struct ab8500_chargalg *di) { - if (di->chg_info.conn_chg != di->chg_info.prev_conn_chg || - di->susp_status.suspended_change) { - /* - * Charger state changed or suspension - * has changed since last update - */ - if ((di->chg_info.conn_chg & AC_CHG) && - !di->susp_status.ac_suspended) { - dev_dbg(di->dev, "Charging source is AC\n"); + if (di->chg_info.conn_chg != di->chg_info.prev_conn_chg) { + /* Charger state changed since last update */ + if (di->chg_info.conn_chg & AC_CHG) { + dev_info(di->dev, "Charging source is AC\n"); if (di->chg_info.charger_type != AC_CHG) { di->chg_info.charger_type = AC_CHG; ab8500_chargalg_state_to(di, STATE_NORMAL_INIT); } - } else if ((di->chg_info.conn_chg & USB_CHG) && - !di->susp_status.usb_suspended) { - dev_dbg(di->dev, "Charging source is USB\n"); + } else if (di->chg_info.conn_chg & USB_CHG) { + dev_info(di->dev, "Charging source is USB\n"); di->chg_info.charger_type = USB_CHG; ab8500_chargalg_state_to(di, STATE_NORMAL_INIT); - } else if (di->chg_info.conn_chg && - (di->susp_status.ac_suspended || - di->susp_status.usb_suspended)) { - dev_dbg(di->dev, "Charging is suspended\n"); - di->chg_info.charger_type = NO_CHG; - ab8500_chargalg_state_to(di, STATE_SUSPENDED_INIT); } else { dev_dbg(di->dev, "Charging source is OFF\n"); di->chg_info.charger_type = NO_CHG; ab8500_chargalg_state_to(di, STATE_HANDHELD_INIT); } di->chg_info.prev_conn_chg = di->chg_info.conn_chg; - di->susp_status.suspended_change = false; } return di->chg_info.conn_chg; } @@ -1281,12 +1256,6 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) } } - /* If suspended, we should not continue checking the flags */ - else if (di->charge_state == STATE_SUSPENDED_INIT || - di->charge_state == STATE_SUSPENDED) { - /* We don't do anything here, just don,t continue */ - } - /* Safety timer expiration */ else if (di->events.safety_timer_expired) { if (di->charge_state != STATE_SAFETY_TIMER_EXPIRED) @@ -1384,23 +1353,6 @@ static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) case STATE_HANDHELD: break; - case STATE_SUSPENDED_INIT: - if (di->susp_status.ac_suspended) - ab8500_chargalg_ac_en(di, false, 0, 0); - if (di->susp_status.usb_suspended) - ab8500_chargalg_usb_en(di, false, 0, 0); - ab8500_chargalg_stop_safety_timer(di); - ab8500_chargalg_stop_maintenance_timer(di); - di->charge_status = POWER_SUPPLY_STATUS_NOT_CHARGING; - di->maintenance_chg = false; - ab8500_chargalg_state_to(di, STATE_SUSPENDED); - power_supply_changed(di->chargalg_psy); - fallthrough; - - case STATE_SUSPENDED: - /* CHARGING is suspended */ - break; - case STATE_BATT_REMOVED_INIT: ab8500_chargalg_stop_charging(di); ab8500_chargalg_state_to(di, STATE_BATT_REMOVED); @@ -1684,144 +1636,6 @@ static int ab8500_chargalg_get_property(struct power_supply *psy, return 0; } -/* Exposure to the sysfs interface */ - -static ssize_t ab8500_chargalg_en_show(struct ab8500_chargalg *di, - char *buf) -{ - return sprintf(buf, "%d\n", - di->susp_status.ac_suspended && - di->susp_status.usb_suspended); -} - -static ssize_t ab8500_chargalg_en_store(struct ab8500_chargalg *di, - const char *buf, size_t length) -{ - long param; - int ac_usb; - int ret; - - ret = kstrtol(buf, 10, ¶m); - if (ret < 0) - return ret; - - ac_usb = param; - switch (ac_usb) { - case 0: - /* Disable charging */ - di->susp_status.ac_suspended = true; - di->susp_status.usb_suspended = true; - di->susp_status.suspended_change = true; - /* Trigger a state change */ - queue_work(di->chargalg_wq, - &di->chargalg_work); - break; - case 1: - /* Enable AC Charging */ - di->susp_status.ac_suspended = false; - di->susp_status.suspended_change = true; - /* Trigger a state change */ - queue_work(di->chargalg_wq, - &di->chargalg_work); - break; - case 2: - /* Enable USB charging */ - di->susp_status.usb_suspended = false; - di->susp_status.suspended_change = true; - /* Trigger a state change */ - queue_work(di->chargalg_wq, - &di->chargalg_work); - break; - default: - dev_info(di->dev, "Wrong input\n" - "Enter 0. Disable AC/USB Charging\n" - "1. Enable AC charging\n" - "2. Enable USB Charging\n"); - } - return strlen(buf); -} - -static struct ab8500_chargalg_sysfs_entry ab8500_chargalg_en_charger = - __ATTR(chargalg, 0644, ab8500_chargalg_en_show, - ab8500_chargalg_en_store); - -static ssize_t ab8500_chargalg_sysfs_show(struct kobject *kobj, - struct attribute *attr, char *buf) -{ - struct ab8500_chargalg_sysfs_entry *entry = container_of(attr, - struct ab8500_chargalg_sysfs_entry, attr); - - struct ab8500_chargalg *di = container_of(kobj, - struct ab8500_chargalg, chargalg_kobject); - - if (!entry->show) - return -EIO; - - return entry->show(di, buf); -} - -static ssize_t ab8500_chargalg_sysfs_charger(struct kobject *kobj, - struct attribute *attr, const char *buf, size_t length) -{ - struct ab8500_chargalg_sysfs_entry *entry = container_of(attr, - struct ab8500_chargalg_sysfs_entry, attr); - - struct ab8500_chargalg *di = container_of(kobj, - struct ab8500_chargalg, chargalg_kobject); - - if (!entry->store) - return -EIO; - - return entry->store(di, buf, length); -} - -static struct attribute *ab8500_chargalg_chg[] = { - &ab8500_chargalg_en_charger.attr, - NULL, -}; - -static const struct sysfs_ops ab8500_chargalg_sysfs_ops = { - .show = ab8500_chargalg_sysfs_show, - .store = ab8500_chargalg_sysfs_charger, -}; - -static struct kobj_type ab8500_chargalg_ktype = { - .sysfs_ops = &ab8500_chargalg_sysfs_ops, - .default_attrs = ab8500_chargalg_chg, -}; - -/** - * ab8500_chargalg_sysfs_exit() - de-init of sysfs entry - * @di: pointer to the struct ab8500_chargalg - * - * This function removes the entry in sysfs. - */ -static void ab8500_chargalg_sysfs_exit(struct ab8500_chargalg *di) -{ - kobject_del(&di->chargalg_kobject); -} - -/** - * ab8500_chargalg_sysfs_init() - init of sysfs entry - * @di: pointer to the struct ab8500_chargalg - * - * This function adds an entry in sysfs. - * Returns error code in case of failure else 0(on success) - */ -static int ab8500_chargalg_sysfs_init(struct ab8500_chargalg *di) -{ - int ret = 0; - - ret = kobject_init_and_add(&di->chargalg_kobject, - &ab8500_chargalg_ktype, - NULL, "ab8500_chargalg"); - if (ret < 0) - dev_err(di->dev, "failed to create sysfs entry\n"); - - return ret; -} -/* Exposure to the sysfs interface <> */ - static int __maybe_unused ab8500_chargalg_resume(struct device *dev) { struct ab8500_chargalg *di = dev_get_drvdata(dev); @@ -1911,7 +1725,6 @@ static int ab8500_chargalg_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct power_supply_config psy_cfg = {}; struct ab8500_chargalg *di; - int ret = 0; di = devm_kzalloc(dev, sizeof(*di), GFP_KERNEL); if (!di) @@ -1959,26 +1772,14 @@ static int ab8500_chargalg_probe(struct platform_device *pdev) platform_set_drvdata(pdev, di); - /* sysfs interface to enable/disable charging from user space */ - ret = ab8500_chargalg_sysfs_init(di); - if (ret) { - dev_err(di->dev, "failed to create sysfs entry\n"); - return ret; - } - dev_info(di->dev, "probe success\n"); return component_add(dev, &ab8500_chargalg_component_ops); } static int ab8500_chargalg_remove(struct platform_device *pdev) { - struct ab8500_chargalg *di = platform_get_drvdata(pdev); - component_del(&pdev->dev, &ab8500_chargalg_component_ops); - /* sysfs interface to enable/disable charging from user space */ - ab8500_chargalg_sysfs_exit(di); - return 0; } From patchwork Thu Jan 27 01:12:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5C5E3C433F5 for ; Thu, 27 Jan 2022 01:15:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232134AbiA0BPF (ORCPT ); Wed, 26 Jan 2022 20:15:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39248 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232206AbiA0BPF (ORCPT ); Wed, 26 Jan 2022 20:15:05 -0500 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BD242C06173B for ; Wed, 26 Jan 2022 17:15:04 -0800 (PST) Received: by mail-lf1-x12d.google.com with SMTP id o12so2179282lfg.12 for ; Wed, 26 Jan 2022 17:15:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=haRFNa2MOuGGx+qiHY4rYq2fcJJPvI8NSUcWdSM3M9o=; b=ZxBLmP94C2g/0rl+XNyh6ZIQ1WIHp1DCoDrqMU+zlkNlMNH5KTmib/Dy3XCE+LbLXr 3ni0qldNPP/pTNNdEij1n9z4g5KX6DW/tlwtrfemRse/h5EXaS28sf0jCIpl9iNO/njj CU/AOSwwiFHa2mru41YsTKZ4pqVfN/P5R5rDxg1Fy71lIY4q/wiY/XEDhmAxJvJhe2L/ ZpDwFyGqYqBIdqJHbD5MKRd93VieDLxcs9L1VyvNU4osUV85kK/FWRu4PsMDR5GBUnBf Q2MFmPdUhg3G90sf23HV2k5S9B5+X3EDf2nHndA90fvkb5PmJur6NEfE6U0/7dRURLzM Kn8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=haRFNa2MOuGGx+qiHY4rYq2fcJJPvI8NSUcWdSM3M9o=; b=xj41JoMKpL3hgh9zPxIe+pnywAoxAKMbKGpRXB7HUFuUSZg2Cytbxkwuz2gae4CLH+ 8scjDXH9wUgoNsxY1EAE1fOjGz+5lPE2Aoo/5q/3PzswyA6lL8Vvr3DPK9uc+0k2ZasH X0JvUBmuTxM83BehJcmtTUPu1BqUbCsqgQbABcr4jmYb842lLjqeg8YAfhaC9mBuPHGn okOTCGH+PwvRLSjngkjUjmL+xhVs4B0qYPAzvbJxQR63eITiTHsrBI0OthdiztQhealE pkT0oErNKkjGftbhroxK6BTWXK9rS/lXdjSO/w0oM5IYlWCdwVEg/tLu638SnHqL/EDe PbKg== X-Gm-Message-State: AOAM5315eVAAkxTuKZH9gJfuGtN+ExkgrJzw9d4gwYg28ugiMi2rmXO5 mKzQ7+XwQteg/jrtMYHH54jsgg== X-Google-Smtp-Source: ABdhPJztp4pcWK0oUBNBH0iA2LHgVCrevSIUo1onUQt/yOGNW8a++8eWI5+ARJ9Esgh/SAFdljmtjg== X-Received: by 2002:ac2:4e89:: with SMTP id o9mr1276366lfr.246.1643246103170; Wed, 26 Jan 2022 17:15:03 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.15.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:15:02 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 10/11] power: supply: ab8500_charger: Restrict ADC retrieveal Date: Thu, 27 Jan 2022 02:12:35 +0100 Message-Id: <20220127011236.332687-11-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The AB8505 only has two ADC channels: the voltage and current provided from VBUS (USB). It does not support AC charging at all. Make sure we don't try to retrieve the non-existing channels. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_charger.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index ce074c018dcb..681b53bb0df0 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -3443,17 +3443,19 @@ static int ab8500_charger_probe(struct platform_device *pdev) di->parent = dev_get_drvdata(pdev->dev.parent); /* Get ADC channels */ - di->adc_main_charger_v = devm_iio_channel_get(dev, "main_charger_v"); - if (IS_ERR(di->adc_main_charger_v)) { - ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_v), - "failed to get ADC main charger voltage\n"); - return ret; - } - di->adc_main_charger_c = devm_iio_channel_get(dev, "main_charger_c"); - if (IS_ERR(di->adc_main_charger_c)) { - ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_c), - "failed to get ADC main charger current\n"); - return ret; + if (!is_ab8505(di->parent)) { + di->adc_main_charger_v = devm_iio_channel_get(dev, "main_charger_v"); + if (IS_ERR(di->adc_main_charger_v)) { + ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_v), + "failed to get ADC main charger voltage\n"); + return ret; + } + di->adc_main_charger_c = devm_iio_channel_get(dev, "main_charger_c"); + if (IS_ERR(di->adc_main_charger_c)) { + ret = dev_err_probe(dev, PTR_ERR(di->adc_main_charger_c), + "failed to get ADC main charger current\n"); + return ret; + } } di->adc_vbus_v = devm_iio_channel_get(dev, "vbus_v"); if (IS_ERR(di->adc_vbus_v)) { From patchwork Thu Jan 27 01:12:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 537844 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C518C433F5 for ; Thu, 27 Jan 2022 01:15:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232206AbiA0BPI (ORCPT ); Wed, 26 Jan 2022 20:15:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231386AbiA0BPG (ORCPT ); Wed, 26 Jan 2022 20:15:06 -0500 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 733C8C06161C for ; Wed, 26 Jan 2022 17:15:06 -0800 (PST) Received: by mail-lf1-x135.google.com with SMTP id n8so2265319lfq.4 for ; Wed, 26 Jan 2022 17:15:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ykjGaL0hTNu/sFC5BS2s3FG5tHHOkoccsGYthrfBM5s=; b=paQumlxaFdnS3Y1aaB/QbnjiND43BhcQvxtYiFNyUrrIYwnLwNOysR0C5WOcJ981pP F2dhTvsembDYjy/PURZ6lD0Qj9Huoy8aAQhCZpA3sG910jLMl7oKA7yUSOrU5pd/z89C 95xPNTxwiLWx1BEVlGV/2kxA2HsC5WFF+npKoMsK4dknG/KjPliVXbXRXEbS0MFJpOtm bMSyNapgQI+vH1E/ec/jYN6bIPw2zQJpFXg0QOPptfhIEUh8boEqEPnR/8bOUBHW8X74 D8PQaci8uBBCnXsHwti7LivwIj6d/wg3C8Y6M4c4PM1xqivOI1XAOP0zxPXPBPFgrESZ S+Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ykjGaL0hTNu/sFC5BS2s3FG5tHHOkoccsGYthrfBM5s=; b=2BG8ceIZyCLXzQfh0V4ORwcLXNJDv5T/9DaAJ0oyJOuk+55ZJKPsga2kniT9eWC0Ai wAph09XN4tq59P0kBaJxKUW4kqhXoLoawDH2V+MLfNanaXxpJSazCgxAtKGCjLSGbgHD GMpzOCbhHBnbYGZC1wHe6FXra3j/y83NBCw7VX/SXl2fd5u+zSJe3PbqN7iCzkci5Pc3 c+oEuo4WOiHTRhpdfrDZ5lGYdZLRRGPZCmvZrJll7f8btJTs4sDbPp0WEUVyiUCD7TGk CpSCEyga7dmlfW/+HY5yVx+XkUTnxbFruOOSaOCfqz2QYSOpc5mQ4sWxJRcZgNgd5hw1 vp8g== X-Gm-Message-State: AOAM5302dWz5tv9rPwv6tQPBUJ/x2QmEAPe3FhWJ2tPjAavg1OgU2i7H XzcjL949DCRp9lzC2e2XAyhjyQ== X-Google-Smtp-Source: ABdhPJyhI4nFtxKHbYxKGY8ZI794y18fImfolRZynLn1n5NgQGhzXZrBhWkrXkDXNulh/Ymynysssw== X-Received: by 2002:a05:6512:2314:: with SMTP id o20mr1249321lfu.590.1643246104781; Wed, 26 Jan 2022 17:15:04 -0800 (PST) Received: from localhost.localdomain (c-fdcc225c.014-348-6c756e10.bbcust.telenor.se. [92.34.204.253]) by smtp.gmail.com with ESMTPSA id u14sm1028337lji.40.2022.01.26.17.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Jan 2022 17:15:04 -0800 (PST) From: Linus Walleij To: Sebastian Reichel , Marcus Cooper Cc: linux-pm@vger.kernel.org, Linus Walleij Subject: [PATCH 11/11] power: supply: ab8500_charger: Fix VBAT interval check Date: Thu, 27 Jan 2022 02:12:36 +0100 Message-Id: <20220127011236.332687-12-linus.walleij@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220127011236.332687-1-linus.walleij@linaro.org> References: <20220127011236.332687-1-linus.walleij@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org When using USB charging, the AB8500 charger is periodically checking VBAT for a threshold at 3.8V. This crashes badly, as the class_for_each_device() was passed the wrong argument. I think this has maybe worked by chance in the past because of how the structs were arranged but it is leading to crashes now. Fix this up and also switch to using microvolts for the voltages like the rest of the code. Signed-off-by: Linus Walleij --- drivers/power/supply/ab8500_charger.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/power/supply/ab8500_charger.c b/drivers/power/supply/ab8500_charger.c index 681b53bb0df0..88099cdba8a7 100644 --- a/drivers/power/supply/ab8500_charger.c +++ b/drivers/power/supply/ab8500_charger.c @@ -163,7 +163,7 @@ enum ab8500_usb_state { #define USB_CH_IP_CUR_LVL_1P4 1400000 #define USB_CH_IP_CUR_LVL_1P5 1500000 -#define VBAT_TRESH_IP_CUR_RED 3800 +#define VBAT_TRESH_IP_CUR_RED 3800000 #define to_ab8500_charger_usb_device_info(x) container_of((x), \ struct ab8500_charger, usb_chg) @@ -1920,7 +1920,11 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data) di = to_ab8500_charger_usb_device_info(usb_chg); - /* For all psy where the driver name appears in any supplied_to */ + /* + * For all psy where the driver name appears in any supplied_to + * in practice what we will find will always be "ab8500_fg" as + * the fuel gauge is responsible of keeping track of VBAT. + */ j = match_string(supplicants, ext->num_supplicants, psy->desc->name); if (j < 0) return 0; @@ -1937,7 +1941,10 @@ static int ab8500_charger_get_ext_psy_data(struct device *dev, void *data) case POWER_SUPPLY_PROP_VOLTAGE_NOW: switch (ext->desc->type) { case POWER_SUPPLY_TYPE_BATTERY: - di->vbat = ret.intval / 1000; + /* This will always be "ab8500_fg" */ + dev_dbg(di->dev, "get VBAT from %s\n", + dev_name(&ext->dev)); + di->vbat = ret.intval; break; default: break; @@ -1966,7 +1973,7 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work) struct ab8500_charger, check_vbat_work.work); class_for_each_device(power_supply_class, NULL, - di->usb_chg.psy, ab8500_charger_get_ext_psy_data); + &di->usb_chg, ab8500_charger_get_ext_psy_data); /* First run old_vbat is 0. */ if (di->old_vbat == 0) @@ -1991,8 +1998,8 @@ static void ab8500_charger_check_vbat_work(struct work_struct *work) * No need to check the battery voltage every second when not close to * the threshold. */ - if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100) && - (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100))) + if (di->vbat < (VBAT_TRESH_IP_CUR_RED + 100000) && + (di->vbat > (VBAT_TRESH_IP_CUR_RED - 100000))) t = 1; queue_delayed_work(di->charger_wq, &di->check_vbat_work, t * HZ);