Message ID | 20240130203714.3020464-6-aren@peacevolution.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2087:b0:106:209c:c626 with SMTP id gs7csp1484330dyb; Tue, 30 Jan 2024 12:41:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhwOvDD/AbLN+e2OjwonDoa0TCrW8pEHs9lIXxzlCgDa6+sRWKeyImECFYOZthAwOF6gm7 X-Received: by 2002:a05:6a20:9c8b:b0:19c:b19d:547a with SMTP id mj11-20020a056a209c8b00b0019cb19d547amr5702126pzb.33.1706647268892; Tue, 30 Jan 2024 12:41:08 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706647268; cv=pass; d=google.com; s=arc-20160816; b=n3/VQXDFIoBT+xGN/8R0Xlw2KaJwBeVw2vtK4rJ+uzfCL7b7gI1vWV1rUj9HjHK4vp lH6xJSy5ND/GWAHBzAjrppfZQsHE1cLxvV3DTTpNecuSgzyZeOfRIdLXROPML45rE/Y+ bXmvo47z9P8Susnsy6wf3kSXXy9w06T7lpC4nkLnpTEhb08qphOuhlY/GE0XqULiLFth O6S3k5AORaJQAsV0l7aSehPeizsKWbTHocaOFyplx2zKFLiesffSOdz9/KUFyYNx1czp 5X2dBzZOjvwD/MX8KR3ArC/Ed9LIbD0D4PXa0URF3yU/Jjs+n1AwLZvcb3fwqdro10Mm rcXw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=dkim-signature:content-transfer-encoding:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from; bh=eZlM22aJvF3MR5EwxjV3X6ckVSfAYjgJvEHp2kxoO6k=; fh=CS8UjFWQd4C89aVAWtaFYgKrfPFQKsOq4yc2cb5p77k=; b=KQsiGqsvCw6Oh9m7EFm9/3gZX6t98o22HtLpvmfN0hWoJfCasHcybUgTjR3B3OZxpS TkOs5klGkGs+wDwIjZEwwBy3FYS7ropgf3XTlFwM9OT8uJFi3MkXUmm+yFDQMEhRNGKI TKmHiMqy/3Z1P71fQdhC8jmySh39ZB0j+DyUcYLMJfU7AHSrglsFJ4jNXWISJzyE7H7v zgA6917LWeuFteU+gqf2GpbanaYui5ROTqV+c8zLU+pd5J/3Hf53z7ZLrKTUl6MAPCHp N0UwmJwsuLOF5CgZKRva6QU5drFPpn1BCwPRiFay7Vg+v+cTEhR4IrUIMnb4MfvptLfd YjUg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="M/8nUGKs"; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id m17-20020a056a00081100b006d9a6f39e36si8102698pfk.252.2024.01.30.12.41.08 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Jan 2024 12:41:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b="M/8nUGKs"; arc=pass (i=1 spf=pass spfdomain=peacevolution.org dkim=pass dkdomain=peacevolution.org dmarc=pass fromdomain=peacevolution.org); spf=pass (google.com: domain of linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-45280-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id CBB1BB24886 for <ouuuleilei@gmail.com>; Tue, 30 Jan 2024 20:39:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D45BC79941; Tue, 30 Jan 2024 20:38:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="M/8nUGKs" Received: from a.peacevolution.org (a.peacevolution.org [206.189.193.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8F6AB78B7B; Tue, 30 Jan 2024 20:38:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=206.189.193.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647087; cv=none; b=Tvbyb7xDcMU+d9gtm190sWumB/wGJ6JHwTV851UDbs02EHAa/Zg2bHFfoY8FomvydBnL4qeX+/sTQ9bycLKLlp5xk5M366IpDXbG841Q1i7TSUJ7w2eo7COUplMMCqwX+37nmXdrRV+RHoZIsvV5j1dVYbEiflbeyXGnmp+k4+w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706647087; c=relaxed/simple; bh=ItXbRSSuRULGHehgAkFOPt/p0MSJUvWQ3KbcLpvFS5g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=F7pkK2zK2fS251z62x+ZlkNlbQpr/vdbrqmktPSRtedBZs1aFKgdnGVOsHGXt15m3nm0TCYTusrq/d+YEFFP+mmg4J0TrTMutW3IG//EWjvOlyMR+uMDHWwPIhBlOj0JUrfccdJFINIPv4QpzBP9+5LpqUWuDa5DyuBhhtoh4PM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org; spf=pass smtp.mailfrom=peacevolution.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b=M/8nUGKs; arc=none smtp.client-ip=206.189.193.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=peacevolution.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=peacevolution.org Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id D42EA4661E; Tue, 30 Jan 2024 20:38:03 +0000 (UTC) From: Aren Moynihan <aren@peacevolution.org> To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?utf-8?q?Ond=C5=99ej_Jirman?= <megi@xff.cz>, Hans de Goede <j.w.r.degoede@gmail.com>, Aidan MacDonald <aidanmacdonald.0x0@gmail.com>, Aren Moynihan <aren@peacevolution.org>, Chen-Yu Tsai <wens@csie.org>, Quentin Schulz <quentin.schulz@bootlin.com>, Sebastian Reichel <sre@kernel.org> Subject: [PATCH v2 5/5] power: supply: axp20x_usb_power: set input current limit in probe Date: Tue, 30 Jan 2024 15:28:01 -0500 Message-ID: <20240130203714.3020464-6-aren@peacevolution.org> In-Reply-To: <20240130203714.3020464-1-aren@peacevolution.org> References: <20240130203714.3020464-1-aren@peacevolution.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spamd-Bar: - Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1706647084; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=eZlM22aJvF3MR5EwxjV3X6ckVSfAYjgJvEHp2kxoO6k=; b=M/8nUGKsclChSRKnGxLzS4IoO1E9Nt8BRog8y+x/fzhn6ORnN4xP84cIDZ4K93ex/n0XjY sD0Rk0yEGcDFyekb7xdkqxCLD6MFP4pqDTHf/vJ+e919wrUuYmGdFDYTggTOVkjv4d5JsR fizhJ0M8fVYbAy4RwiCrGadYlLng8SQ= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1789549366960032685 X-GMAIL-MSGID: 1789549366960032685 |
Series |
power: supply: axp20x_usb_power: cleanup input current limit handling
|
|
Commit Message
Aren
Jan. 30, 2024, 8:28 p.m. UTC
axp803 sets the current limit to 3A by default if it doesn't detect a
battery. The datasheet says that register 0x2D bit 6 is used to indicate
first power on status. According to it, if that bit is 0 and the battery
is not detected, it will set the input current limit to 3A, however
setting that bit to 1 doesn't to prevent the pmic from setting the
current limit to 3A.
Waiting for USB BC detection doesn't work either, because (as far as I
can tell) USB BC detection isn't performed when there isn't a battery
detected.
Fixes: c279adafe6ab ("power: supply: axp20x_usb_power: add support for AXP813")
Signed-off-by: Aren Moynihan <aren@peacevolution.org>
---
I'm not sure if the pmic simply ignores the first power on field, or if
it needs to be set in a specific way / at a specific time. I tried
setting it in arm-trusted-firmware, and the pmic still set the input
current limit to 3A.
The datasheet for axp813 says it has the same first power on bit, but I
don't have hardware to test if it behaves the same way. This driver uses
the same platform data for axp803 and axp813.
(no changes since v1)
drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
On Tue, Jan 30, 2024 at 03:28:01PM -0500, Aren Moynihan wrote: > axp803 sets the current limit to 3A by default if it doesn't detect a > battery. The datasheet says that register 0x2D bit 6 is used to indicate > first power on status. According to it, if that bit is 0 and the battery > is not detected, it will set the input current limit to 3A, however > setting that bit to 1 doesn't to prevent the pmic from setting the > current limit to 3A. > > Waiting for USB BC detection doesn't work either, because (as far as I > can tell) USB BC detection isn't performed when there isn't a battery > detected. > > Fixes: c279adafe6ab ("power: supply: axp20x_usb_power: add support for AXP813") Breaks: ;) Last time you wrote: > Unfortunately BC 1.2 detection doesn't seem to be performed without a > battery, at least I wasn't able to trigger it. > > This will be worth revising once we have a driver that can provide a > signal that USB-PD is in progress and/or finished, but until then I'd > prefer not take on that complexity. This patch adds complexity and will lead to hard to debug issues for some people. It certainly did cause issues for me, when I had similar patch in my tree a while ago, forcing me to drop it. There are other situations you're not considering. Like battery being very discharged and unable to provide power, while still being detected and BC1.2 running correctly and successfully when the device is powered up by being plugged into DCP port (only option of powerup in such a scenario). Battery is detected at 2.2V and certainly it will not provide any power if OCV of the battery is anywhere below 3V. See "9.4.5 Battery detection" in AXP803 datasheet. So you have about 1V range of possible battery voltage where BC1.2 will work, but you'll force lower the correctly detected current limit and break boot, because 2.5W is too low for the boot time power surge. The phone will just randomly die halfthrough boot for apparently no reason, despite being connected to DCP. And also forget Pinephone, there may also be batteryless SBCs using this PMIC with battery as an option (similar to Quartz64-A - Rockchip SBC, but exactly this setup with battery capable PMIC in the power path on a normal SBC, with battery being optional), where this patch will break boot on them, too. I'm quite confident PMIC relaxing the limit without a battery is meant for such use cases. If you insist on adding this, at least add dev_warn() about forcing lower limit than detected by the PMIC, so that people who'll do cursory debugging via serial console will know why's their device failing to boot on a strong enough power supply, or why their SBC is suddenly failing when used without battery. As for me, this patch should not be applied at all. Kind regards, o. > Signed-off-by: Aren Moynihan <aren@peacevolution.org> > --- > I'm not sure if the pmic simply ignores the first power on field, or if > it needs to be set in a specific way / at a specific time. I tried > setting it in arm-trusted-firmware, and the pmic still set the input > current limit to 3A. > > The datasheet for axp813 says it has the same first power on bit, but I > don't have hardware to test if it behaves the same way. This driver uses > the same platform data for axp803 and axp813. > > (no changes since v1) > > drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++ > 1 file changed, 13 insertions(+) > > diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c > index dae7e5cfc54e..751b9f02d36f 100644 > --- a/drivers/power/supply/axp20x_usb_power.c > +++ b/drivers/power/supply/axp20x_usb_power.c > @@ -51,6 +51,7 @@ struct axp_data { > unsigned int num_irq_names; > const int *curr_lim_table; > int curr_lim_table_size; > + int force_curr_lim; > struct reg_field curr_lim_fld; > struct reg_field vbus_valid_bit; > struct reg_field vbus_mon_bit; > @@ -545,6 +546,7 @@ static const struct axp_data axp813_data = { > .curr_lim_table = axp813_usb_curr_lim_table, > .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), > .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), > + .force_curr_lim = 500000, > .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), > .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), > .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), > @@ -726,6 +728,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) > return ret; > } > > + if (power->axp_data->force_curr_lim) { > + /* > + * Some chips set the input current limit to 3A when there is no > + * battery connected. Normally the default is 500mA. > + */ > + ret = axp20x_usb_power_set_input_current_limit(power, > + power->axp_data->force_curr_lim); > + if (ret) > + return ret; > + } > + > if (power->usb_bc_en_bit) { > /* Enable USB Battery Charging specification detection */ > ret = regmap_field_write(power->usb_bc_en_bit, 1); > -- > 2.43.0 >
On Tue, Jan 30, 2024 at 10:13:06PM +0100, Ondřej Jirman wrote: > On Tue, Jan 30, 2024 at 03:28:01PM -0500, Aren Moynihan wrote: > > axp803 sets the current limit to 3A by default if it doesn't detect a > > battery. The datasheet says that register 0x2D bit 6 is used to indicate > > first power on status. According to it, if that bit is 0 and the battery > > is not detected, it will set the input current limit to 3A, however > > setting that bit to 1 doesn't to prevent the pmic from setting the > > current limit to 3A. > > > > Waiting for USB BC detection doesn't work either, because (as far as I > > can tell) USB BC detection isn't performed when there isn't a battery > > detected. > > > > Fixes: c279adafe6ab ("power: supply: axp20x_usb_power: add support for AXP813") > > Breaks: ;) > > Last time you wrote: > > > Unfortunately BC 1.2 detection doesn't seem to be performed without a > > battery, at least I wasn't able to trigger it. > > > > This will be worth revising once we have a driver that can provide a > > signal that USB-PD is in progress and/or finished, but until then I'd > > prefer not take on that complexity. > > This patch adds complexity and will lead to hard to debug issues for some > people. It certainly did cause issues for me, when I had similar patch in > my tree a while ago, forcing me to drop it. > > There are other situations you're not considering. Like battery being > very discharged and unable to provide power, while still being detected > and BC1.2 running correctly and successfully when the device is powered > up by being plugged into DCP port (only option of powerup in such a > scenario). Oh you're right, I overlooked the case where the battery is very low, in which case bc detection should still be performed (I think, I haven't tested it). This issue this patch is trying to fix doesn't apply in that case, so it should be simple enough to check if the pmic has detected a battery and skip setting the current limit if it has. > Battery is detected at 2.2V and certainly it will not provide any power > if OCV of the battery is anywhere below 3V. See "9.4.5 Battery detection" > in AXP803 datasheet. So you have about 1V range of possible battery voltage > where BC1.2 will work, but you'll force lower the correctly detected current > limit and break boot, because 2.5W is too low for the boot time power surge. > > The phone will just randomly die halfthrough boot for apparently no reason, > despite being connected to DCP. > > And also forget Pinephone, there may also be batteryless SBCs using this PMIC > with battery as an option (similar to Quartz64-A - Rockchip SBC, but exactly > this setup with battery capable PMIC in the power path on a normal SBC, with > battery being optional), where this patch will break boot on them, too. I'm > quite confident PMIC relaxing the limit without a battery is meant for such use > cases. Perhaps it would be better to read the limit from the device tree, that way it could be set higher for a specific board if it needs to draw that much current and be able to boot without a battery? It seems sketchy to default to a current limit significantly higher than what the usb power supply is required to support. > If you insist on adding this, at least add dev_warn() about forcing lower > limit than detected by the PMIC, so that people who'll do cursory debugging > via serial console will know why's their device failing to boot on a strong > enough power supply, or why their SBC is suddenly failing when used without > battery. Adding a dev_warn is a good idea, I'll do that. Thanks for the review - Aren > As for me, this patch should not be applied at all. > > Kind regards, > o. > > > Signed-off-by: Aren Moynihan <aren@peacevolution.org> > > --- > > I'm not sure if the pmic simply ignores the first power on field, or if > > it needs to be set in a specific way / at a specific time. I tried > > setting it in arm-trusted-firmware, and the pmic still set the input > > current limit to 3A. > > > > The datasheet for axp813 says it has the same first power on bit, but I > > don't have hardware to test if it behaves the same way. This driver uses > > the same platform data for axp803 and axp813. > > > > (no changes since v1) > > > > drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++ > > 1 file changed, 13 insertions(+) > > > > diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c > > index dae7e5cfc54e..751b9f02d36f 100644 > > --- a/drivers/power/supply/axp20x_usb_power.c > > +++ b/drivers/power/supply/axp20x_usb_power.c > > @@ -51,6 +51,7 @@ struct axp_data { > > unsigned int num_irq_names; > > const int *curr_lim_table; > > int curr_lim_table_size; > > + int force_curr_lim; > > struct reg_field curr_lim_fld; > > struct reg_field vbus_valid_bit; > > struct reg_field vbus_mon_bit; > > @@ -545,6 +546,7 @@ static const struct axp_data axp813_data = { > > .curr_lim_table = axp813_usb_curr_lim_table, > > .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), > > .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), > > + .force_curr_lim = 500000, > > .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), > > .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), > > .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), > > @@ -726,6 +728,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) > > return ret; > > } > > > > + if (power->axp_data->force_curr_lim) { > > + /* > > + * Some chips set the input current limit to 3A when there is no > > + * battery connected. Normally the default is 500mA. > > + */ > > + ret = axp20x_usb_power_set_input_current_limit(power, > > + power->axp_data->force_curr_lim); > > + if (ret) > > + return ret; > > + } > > + > > if (power->usb_bc_en_bit) { > > /* Enable USB Battery Charging specification detection */ > > ret = regmap_field_write(power->usb_bc_en_bit, 1); > > -- > > 2.43.0 > >
On Tue, Jan 30, 2024 at 11:20:29PM -0500, Aren wrote: > On Tue, Jan 30, 2024 at 10:13:06PM +0100, Ondřej Jirman wrote: > > On Tue, Jan 30, 2024 at 03:28:01PM -0500, Aren Moynihan wrote: > > > Unfortunately BC 1.2 detection doesn't seem to be performed without a > > > battery, at least I wasn't able to trigger it. > > > > > > This will be worth revising once we have a driver that can provide a > > > signal that USB-PD is in progress and/or finished, but until then I'd > > > prefer not take on that complexity. > > > > This patch adds complexity and will lead to hard to debug issues for some > > people. It certainly did cause issues for me, when I had similar patch in > > my tree a while ago, forcing me to drop it. > > > > There are other situations you're not considering. Like battery being > > very discharged and unable to provide power, while still being detected > > and BC1.2 running correctly and successfully when the device is powered > > up by being plugged into DCP port (only option of powerup in such a > > scenario). > > Oh you're right, I overlooked the case where the battery is very low, in > which case bc detection should still be performed (I think, I haven't > tested it). This issue this patch is trying to fix doesn't apply in that > case, so it should be simple enough to check if the pmic has detected a > battery and skip setting the current limit if it has. > > > Battery is detected at 2.2V and certainly it will not provide any power > > if OCV of the battery is anywhere below 3V. See "9.4.5 Battery detection" > > in AXP803 datasheet. So you have about 1V range of possible battery voltage > > where BC1.2 will work, but you'll force lower the correctly detected current > > limit and break boot, because 2.5W is too low for the boot time power surge. > > > > The phone will just randomly die halfthrough boot for apparently no reason, > > despite being connected to DCP. > > > > And also forget Pinephone, there may also be batteryless SBCs using this PMIC > > with battery as an option (similar to Quartz64-A - Rockchip SBC, but exactly > > this setup with battery capable PMIC in the power path on a normal SBC, with > > battery being optional), where this patch will break boot on them, too. I'm > > quite confident PMIC relaxing the limit without a battery is meant for such use > > cases. > > Perhaps it would be better to read the limit from the device tree, that > way it could be set higher for a specific board if it needs to draw that > much current and be able to boot without a battery? It seems sketchy to > default to a current limit significantly higher than what the usb power > supply is required to support. But is there really an issue? The board may not be using USB power supply. It may simply have a barrel jack, like Quartz64-A does. And it will still create an issue if you make the new behavior "opt-out" via DT. You can make it opt-in if you like. Also in Pinephone case, you'll not really have a case where the battery has < 2V not loaded. That's not going to happen. PMIC will shut off at 3V battery voltage when loaded. It will not discharge further, and after shutoff battery voltage will jump to 3.4V or so, and it will not drop below 2V after that, ever. So the battery will pretty much always be detected as long as it's present. What actual problem have you seen that this patch is trying to solve? Thank you and kind regards, o.
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index dae7e5cfc54e..751b9f02d36f 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -51,6 +51,7 @@ struct axp_data { unsigned int num_irq_names; const int *curr_lim_table; int curr_lim_table_size; + int force_curr_lim; struct reg_field curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; @@ -545,6 +546,7 @@ static const struct axp_data axp813_data = { .curr_lim_table = axp813_usb_curr_lim_table, .curr_lim_table_size = ARRAY_SIZE(axp813_usb_curr_lim_table), .curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), + .force_curr_lim = 500000, .usb_bc_en_bit = REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .usb_bc_det_fld = REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit = REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), @@ -726,6 +728,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; } + if (power->axp_data->force_curr_lim) { + /* + * Some chips set the input current limit to 3A when there is no + * battery connected. Normally the default is 500mA. + */ + ret = axp20x_usb_power_set_input_current_limit(power, + power->axp_data->force_curr_lim); + if (ret) + return ret; + } + if (power->usb_bc_en_bit) { /* Enable USB Battery Charging specification detection */ ret = regmap_field_write(power->usb_bc_en_bit, 1);