Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp615029pxb; Tue, 1 Feb 2022 07:03:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJwxd6J/JfrX8N8rU13NU7Xj2yNsYYbhW8uXyO3un4JWLmfGsoGW8umoLITT+xqTgF72fVGz X-Received: by 2002:a17:902:c40b:: with SMTP id k11mr25710138plk.94.1643727834298; Tue, 01 Feb 2022 07:03:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643727834; cv=none; d=google.com; s=arc-20160816; b=QVIbkQfRLGVmJ6KFFvrwNQhXMK8WVQONUw4Dj4016FOa4YR4Br/3oDsRicxoyxPYMA +BkinBf0aNiOyBcxS2uKWiOff7jT8QuTG6SVQjF/hK42fhb0bdKhjIWl4eBN7DELD/Fm kqftcKRdZRq7GnWkSk0PjufnvkQKZS287JXt78ZA5pUVVqPJ02f3NfWkv8A20d1D+nNz M3NZg9h4/8ZFD0jLGVCKHqic45DFgTLtarljC9fcuS8MAaYOOzijBk+37T4+2CUAgjr1 3Rjj38H3g9lt0M4GO1VoiKnb+bb5fkmWZf+1giRv/10ubshiZYQxZZ8Vtyn/UxDay0O5 S+JA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/NpFdB1bVbDNAo3VG1s0TVH/ohpEAXL05zlAcvCO9sw=; b=YVigN4u7FVMoGoTDOXJM3mDc26o8LSuT3n/DDNF76xn1vKUtFWZC/qOhGEAX9/Nemr m1lnI3ipyRIp+Foc+/YKhSYosg3egz2sJzmUh8CCp3Bg7yDJZGCP1QkVCO2cpOxAETNU ayxUHCLzNlAwRaXCx8qfPfLJGvJd6E/7eGfDjMYBUglobhpf2D3BiAaDe0uEegcVj9nh NL46Pos/KkPxiqFUKvQIa0iRAKROxZi5hW0xBWxVoYTEDhrNm6WNkjneJmk6o+9ZDLon INgSEM2bWxm2zxjRb/bk1blEQeVxYy85VELhiVWdKRoxozCQ+wlXd7K7AcCz9wlMRb3J U8uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d4h+6EyB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k7si2421440pjm.137.2022.02.01.07.03.42; Tue, 01 Feb 2022 07:03:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=d4h+6EyB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356205AbiA3Uq3 (ORCPT + 99 others); Sun, 30 Jan 2022 15:46:29 -0500 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:40921 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356188AbiA3UqX (ORCPT ); Sun, 30 Jan 2022 15:46:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643575583; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/NpFdB1bVbDNAo3VG1s0TVH/ohpEAXL05zlAcvCO9sw=; b=d4h+6EyBDwssFVIGaj0uZa3KW4YC6vqeyBqrvLknvbuv6vjASieMZMX7bE9iPhLVLzD9f0 +kw0C0gvhII7LyIeZ7CBQb/CA6wDQ7/M8Im9h5ZL24aTutRevGsgD3a68HlklEnpohVKwT vDniMX3SLLJcq9OxYfJqf7BzVxp6L2w= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-614-jvKquqjfMtKnSpE55yRK7w-1; Sun, 30 Jan 2022 15:46:17 -0500 X-MC-Unique: jvKquqjfMtKnSpE55yRK7w-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B1E248030D2; Sun, 30 Jan 2022 20:46:14 +0000 (UTC) Received: from shalem.redhat.com (unknown [10.39.192.60]) by smtp.corp.redhat.com (Postfix) with ESMTP id 4D23E61093; Sun, 30 Jan 2022 20:46:11 +0000 (UTC) From: Hans de Goede To: "Rafael J . Wysocki" , Mika Westerberg , Mark Gross , Andy Shevchenko , Wolfram Sang , Lee Jones , Sebastian Reichel , MyungJoo Ham , Chanwoo Choi , Ard Biesheuvel Cc: Hans de Goede , Len Brown , linux-acpi@vger.kernel.org, Yauhen Kharuzhy , Tsuchiya Yuto , Fabio Aiuto , platform-driver-x86@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-efi@vger.kernel.org Subject: [PATCH v4 03/20] power: supply: bq25890: Reduce reported CONSTANT_CHARGE_CURRENT_MAX for low temperatures Date: Sun, 30 Jan 2022 21:45:40 +0100 Message-Id: <20220130204557.15662-4-hdegoede@redhat.com> In-Reply-To: <20220130204557.15662-1-hdegoede@redhat.com> References: <20220130204557.15662-1-hdegoede@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Yauhen Kharuzhy Take into account possible current reduction due to low-temperature when reading POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX. As described in the datasheet in cool (0-20° Celcius) conditions the current limit is decreased to 20% or 50% of ICHG field value depended on JEITA_ISET field. Also add NTC_FAULT field value to the debug message in bq25890_get_chip_state(). Changed by Hans de Goede: - Fix reading F_CHG_FAULT instead of F_NTC_FIELD for state->ntc_fault - Only read JEITA_ISET field if necessary - Tweak commit message a bit Signed-off-by: Yauhen Kharuzhy Co-developed-by: Hans de Goede Signed-off-by: Hans de Goede --- Changes in v3: - Drop chunk adding a F_JEITA_VSET read to bq25890_power_supply_get_property() which accidentally got added to this patch --- drivers/power/supply/bq25890_charger.c | 29 +++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c index fb987579d05a..7a3269c06b38 100644 --- a/drivers/power/supply/bq25890_charger.c +++ b/drivers/power/supply/bq25890_charger.c @@ -94,6 +94,7 @@ struct bq25890_state { u8 vsys_status; u8 boost_fault; u8 bat_fault; + u8 ntc_fault; }; struct bq25890_device { @@ -407,6 +408,14 @@ enum bq25890_chrg_fault { CHRG_FAULT_TIMER_EXPIRED, }; +enum bq25890_ntc_fault { + NTC_FAULT_NORMAL = 0, + NTC_FAULT_WARM = 2, + NTC_FAULT_COOL = 3, + NTC_FAULT_COLD = 5, + NTC_FAULT_HOT = 6, +}; + static bool bq25890_is_adc_property(enum power_supply_property psp) { switch (psp) { @@ -499,6 +508,18 @@ static int bq25890_power_supply_get_property(struct power_supply *psy, case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); + + /* When temperature is too low, charge current is decreased */ + if (bq->state.ntc_fault == NTC_FAULT_COOL) { + ret = bq25890_field_read(bq, F_JEITA_ISET); + if (ret < 0) + return ret; + + if (ret) + val->intval /= 5; + else + val->intval /= 2; + } break; case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: @@ -583,7 +604,8 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, {F_VSYS_STAT, &state->vsys_status}, {F_BOOST_FAULT, &state->boost_fault}, {F_BAT_FAULT, &state->bat_fault}, - {F_CHG_FAULT, &state->chrg_fault} + {F_CHG_FAULT, &state->chrg_fault}, + {F_NTC_FAULT, &state->ntc_fault} }; for (i = 0; i < ARRAY_SIZE(state_fields); i++) { @@ -594,9 +616,10 @@ static int bq25890_get_chip_state(struct bq25890_device *bq, *state_fields[i].data = ret; } - dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT=%d/%d/%d\n", + dev_dbg(bq->dev, "S:CHG/PG/VSYS=%d/%d/%d, F:CHG/BOOST/BAT/NTC=%d/%d/%d/%d\n", state->chrg_status, state->online, state->vsys_status, - state->chrg_fault, state->boost_fault, state->bat_fault); + state->chrg_fault, state->boost_fault, state->bat_fault, + state->ntc_fault); return 0; } -- 2.33.1