Message ID | 20240121014057.1042466-7-aren@peacevolution.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:2bc4:b0:101:a8e8:374 with SMTP id hx4csp1879125dyb; Sat, 20 Jan 2024 17:46:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IHEbkCnuZZxnpyOuinSLNANtFAWgE6+jmhHo3FXyrNUuASwMndLW9y53JFyw4qFW+77ykyX X-Received: by 2002:a05:620a:2725:b0:783:9afd:f8b6 with SMTP id b37-20020a05620a272500b007839afdf8b6mr251260qkp.37.1705801617593; Sat, 20 Jan 2024 17:46:57 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1705801617; cv=pass; d=google.com; s=arc-20160816; b=aeF14hppfJbu3QnIV1xG5vyb4Osg15o5Fa/rNIK3fhru9EMLI5K9O5/bdwv4VYQTU7 GYWMGdxlxVXHa8/Qw7HDEGt76IA4yW/gN4c0SDAhFLH8GlgnQYHD4rvH/7qdpLuE0UIS yU2frzEuYv4uD3MtUdyViPCaA5s63VIyTLhIbN4UypfN0RVMfqwQQT5NDc/ygGHf357l vluiYpVxbFAo9Z966dzmLRr0wT+dSJh6mqX+rFwI59xFjD9lIw464K0wBgSZ0ETjd7kM mDrmYTnPoex2cczSqpe0nrDCMm9Orkrv912l+zxjAq7bU8v/a1n30U4/KhJNAlntK0xR pRVw== 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=vMyg+vwFP4scpXStIE0uQ3xwlw79VXW+sqgg112o19M=; fh=wEdsi57ruOXwzZ0+QCfz/ydvXnF8YJmkhQf9OA42hCQ=; b=gb7GQzIq5sGZ3UOsYJ/qwK6hsvYdbqUFSU8SgFAWjnv8y4zjAejLI6REfOyBn8IDbC D9PBPvtFgZHlikXZRWRVMIZJME09XNKeARGWdha9ebaqhtYod8yVkCR2c2O1jiaQHu4t 42WSIftKVJ1066TA/F5ZuDt0Qb5HmQIqc4UHXK/epnykq5ahaHfxKUNovUQc5Zc5GnjF B8TXGREMuRRz2aS6LndekPkFZHsaP2tr6oFX/6zOX/nh+w7av3soy1HbxbllIUB/G6tG KO7BOBB1eKnRowhZRbuyQ0a5mWYsw7Rb3a/nwNqQAn0DKCooyj9FVBiZKLXyHlUNQy4t nMMg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=go2unihH; 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-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=peacevolution.org Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id k23-20020a05620a0b9700b0078364281171si2630872qkh.178.2024.01.20.17.46.57 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Jan 2024 17:46:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@peacevolution.org header.s=dkim header.b=go2unihH; 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-31949-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-31949-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 64DA51C215EE for <ouuuleilei@gmail.com>; Sun, 21 Jan 2024 01:46:57 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1306F358AD; Sun, 21 Jan 2024 01:46:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="go2unihH" 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 1CE0035292; Sun, 21 Jan 2024 01:46:38 +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=1705801600; cv=none; b=PLhNikp2n+s4i3bxBoh8636mDV7FeL9C023JBLU4g1z/AFbwEWiZ0HiOmUuRknX8sOuuqOP43+DvY2ETeMJP7LVfxUcQmTSCiw0VJ2cUafqeuzZmhsDzlFULSv7GqLZRRuc7u4f/bJ9eDbq+yGOh8zkLwpKdkAO/SOi8Sau6HnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801600; c=relaxed/simple; bh=0Qorkd0LmlFqn728SoPqMwhcM8AsRBxN+sCmP8incD0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=mlfblFpd5wERXzRTnX4IV/0lE610A5IS4Z/p9WqI7UUtfFwL/iNUSNSxjoBypYYjI4jfRonaHuYHrfYMj170qaSvB1hJoHFMEgPzbrsflaqOwL5LxpZPDForlSKv6esxKId1Ko9RsL/N857Tq6OtF4EFWzUJNA0LTZY2PYosqJA= 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=go2unihH; 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 43C8843C8C; Sun, 21 Jan 2024 01:46:37 +0000 (UTC) From: Aren Moynihan <aren@peacevolution.org> To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald <aidanmacdonald.0x0@gmail.com>, =?utf-8?q?Ond=C5=99ej_Ji?= =?utf-8?q?rman?= <megi@xff.cz>, Aren Moynihan <aren@peacevolution.org>, Chen-Yu Tsai <wens@csie.org>, Quentin Schulz <quentin.schulz@bootlin.com>, Sebastian Reichel <sre@kernel.org> Subject: [PATCH 3/3] power: supply: axp20x_usb_power: set input current limit in probe Date: Sat, 20 Jan 2024 20:40:04 -0500 Message-ID: <20240121014057.1042466-7-aren@peacevolution.org> In-Reply-To: <20240121014057.1042466-1-aren@peacevolution.org> References: <20240121014057.1042466-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=1705801597; h=from:subject:date:message-id:to:cc:mime-version:content-type:content-transfer-encoding:in-reply-to:references; bh=vMyg+vwFP4scpXStIE0uQ3xwlw79VXW+sqgg112o19M=; b=go2unihHUCDvGf2rxNqpJZFRHUG8yq9g6DqT05V4XXvHkiOAeC62icrSsw5zD6zKqgEu9p rW1cfQ9sfWZI5h2wyuFI0DSHVYyAExSRlOEJo8fP8bgHxWH+xeTIcWMsB2JqnnXdqAUZbd oX+HI1vYliv8Z4UQisDZfm487TbMvak= X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788662636836747170 X-GMAIL-MSGID: 1788662636836747170 |
Series |
power: supply: axp20x_usb_power: prepare for external power delivery negotiation
|
|
Commit Message
Aren
Jan. 21, 2024, 1:40 a.m. UTC
axp803 sets the current limit to 3A by default if it doesn't detect a
battery. The datasheet says that reg 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.
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.
drivers/power/supply/axp20x_usb_power.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
Comments
Hello Aren, On Sat, Jan 20, 2024 at 08:40:04PM -0500, Aren Moynihan wrote: > axp803 sets the current limit to 3A by default if it doesn't detect a > battery. The datasheet says that reg 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. > > 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. > > 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 5656f6e57d54..95b136ee20f2 100644 > --- a/drivers/power/supply/axp20x_usb_power.c > +++ b/drivers/power/supply/axp20x_usb_power.c > @@ -52,6 +52,7 @@ struct axp_data { > const int *curr_lim_table; > int input_curr_lim_table_size; > const int *input_curr_lim_table; > + int force_input_curr_lim; > struct reg_field curr_lim_fld; > struct reg_field input_curr_lim_fld; > struct reg_field vbus_valid_bit; > @@ -599,6 +600,7 @@ static const struct axp_data axp813_data = { > .input_curr_lim_table_size = ARRAY_SIZE(axp_813_usb_input_curr_lim_table), > .input_curr_lim_table = axp_813_usb_input_curr_lim_table, > .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), > + .force_input_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), > @@ -786,6 +788,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) > return ret; > } > > + if (power->axp_data->force_input_curr_lim) { > + /* > + * Certain 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_input_curr_lim); > + if (ret) > + return ret; > + } This will break the usecase of powering Pinephone from USB without a battery present (or fully discharged). The phone can require more than 500mA before USB power supply detection manages to run and sets the higher limit. Linux should keep the limit set by the bootloader until it figures out something better based on BC 1.2 or USB-PD. You should only change the limit as the result of negotiation. Kind regards, o. > 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 Sun, Jan 21, 2024 at 12:08:37PM +0100, Ondřej Jirman wrote: > Hello Aren, > > On Sat, Jan 20, 2024 at 08:40:04PM -0500, Aren Moynihan wrote: > > axp803 sets the current limit to 3A by default if it doesn't detect a > > battery. The datasheet says that reg 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. > > > > 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. > > > > 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 5656f6e57d54..95b136ee20f2 100644 > > --- a/drivers/power/supply/axp20x_usb_power.c > > +++ b/drivers/power/supply/axp20x_usb_power.c > > @@ -52,6 +52,7 @@ struct axp_data { > > const int *curr_lim_table; > > int input_curr_lim_table_size; > > const int *input_curr_lim_table; > > + int force_input_curr_lim; > > struct reg_field curr_lim_fld; > > struct reg_field input_curr_lim_fld; > > struct reg_field vbus_valid_bit; > > @@ -599,6 +600,7 @@ static const struct axp_data axp813_data = { > > .input_curr_lim_table_size = ARRAY_SIZE(axp_813_usb_input_curr_lim_table), > > .input_curr_lim_table = axp_813_usb_input_curr_lim_table, > > .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), > > + .force_input_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), > > @@ -786,6 +788,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) > > return ret; > > } > > > > + if (power->axp_data->force_input_curr_lim) { > > + /* > > + * Certain 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_input_curr_lim); > > + if (ret) > > + return ret; > > + } > > This will break the usecase of powering Pinephone from USB without a battery > present (or fully discharged). > > The phone can require more than 500mA before USB power supply detection manages > to run and sets the higher limit. Linux should keep the limit set by the > bootloader until it figures out something better based on BC 1.2 or USB-PD. > > You should only change the limit as the result of negotiation. 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. - Aren > Kind regards, > o. > > > 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 > >
diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply/axp20x_usb_power.c index 5656f6e57d54..95b136ee20f2 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -52,6 +52,7 @@ struct axp_data { const int *curr_lim_table; int input_curr_lim_table_size; const int *input_curr_lim_table; + int force_input_curr_lim; struct reg_field curr_lim_fld; struct reg_field input_curr_lim_fld; struct reg_field vbus_valid_bit; @@ -599,6 +600,7 @@ static const struct axp_data axp813_data = { .input_curr_lim_table_size = ARRAY_SIZE(axp_813_usb_input_curr_lim_table), .input_curr_lim_table = axp_813_usb_input_curr_lim_table, .input_curr_lim_fld = REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), + .force_input_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), @@ -786,6 +788,17 @@ static int axp20x_usb_power_probe(struct platform_device *pdev) return ret; } + if (power->axp_data->force_input_curr_lim) { + /* + * Certain 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_input_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);