From nobody Thu Dec 25 09:15:16 2025 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 1C21434180; Sun, 21 Jan 2024 01:44:14 +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=1705801457; cv=none; b=QTFXMCBdMzvdEFpNuT23E10Q6azli9KjTIXPOOheCiZBCDLqozCxea6ejfDM6I5xg2j5Vdd2k19MsD4Zj2yfM2mRIj94CyEQo/X+A3n69WOagru4/iSKhv3OJ2S/WMMloWMMgA7K6gwBbtlJ/EnvFqjPQvcCXKZ5bpitN4QXvIA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801457; c=relaxed/simple; bh=DPa+Nkb0JVfgtnAuyOILFcJ3GBwfuVrctlhfHFq+TEg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=j18usTzS6BeG5Y1XOldf8EhOt2SsPhotizUIIRm6Mw5pmVqweKN16nLOmFhb+Gt1ZEzAbMW6DyNtthisa5ss3uFbDGcWpQ2eS73uXBWYgB9DQo2psoGh7iPObT9qBdN6V0UOXFIknxgTdrbmOa4GSKe/7ocnpGhEG1XWD4xxpdY= 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=lMtAffAy; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="lMtAffAy" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id A6DAC4620D; Sun, 21 Jan 2024 01:44:13 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?UTF-8?q?Ond=C5=99ej=20Jirman?= , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH 1/3] power: supply: axp20x_usb_power: add input current limit Date: Sat, 20 Jan 2024 20:40:00 -0500 Message-ID: <20240121014057.1042466-3-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705801454; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=mTTqhJZ+TXCTAU2v1OkBw9B/XAxQraalT4JO8XnSZII=; b=lMtAffAyNqtnakbBvalpNJNZCjKVCYzo1SnhFulzJ6j5l0GvqTznjjHx0OjR+7ZlrQXSED S6UNgd+Wl5jGT1DiZW3RIfJM0F9G0A2cZNIRq9oJ3gfLhSIeQbQ3gjkVkWtVxtdINQCs2i Cax7oMSGnjbdQEAUTSRkPbODXFBKvhA= Content-Type: text/plain; charset="utf-8" Add properties for setting the maximum current that will be drawn from the usb connection. These changes don't apply to all axp20x chips, so we need to add new power_desc and power supply property objects for axp813 specifically. These are copied from the axp22x variants that were used before, with extra fields added. Also add a dev field to the axp20x_usb_power struct, so we can use dev_dbg and dev_err in more places. Signed-off-by: Aren Moynihan Reviewed-By: Ondrej Jirman --- drivers/power/supply/axp20x_usb_power.c | 127 +++++++++++++++++++++++- 1 file changed, 125 insertions(+), 2 deletions(-) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply= /axp20x_usb_power.c index e23308ad4cc7..8c0c2c25565f 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -50,7 +50,10 @@ struct axp_data { const char * const *irq_names; unsigned int num_irq_names; const int *curr_lim_table; + int input_curr_lim_table_size; + const int *input_curr_lim_table; struct reg_field curr_lim_fld; + struct reg_field input_curr_lim_fld; struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; @@ -59,7 +62,9 @@ struct axp_data { }; =20 struct axp20x_usb_power { + struct device *dev; struct regmap *regmap; + struct regmap_field *input_curr_lim_fld; struct regmap_field *curr_lim_fld; struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; @@ -115,6 +120,15 @@ static void axp20x_usb_power_poll_vbus(struct work_str= uct *work) if (val !=3D power->old_status) power_supply_changed(power->supply); =20 + if (power->usb_bc_en_bit && (val & AXP20X_PWR_STATUS_VBUS_PRESENT) !=3D + (power->old_status & AXP20X_PWR_STATUS_VBUS_PRESENT)) { + dev_dbg(power->dev, "Cable status changed, re-enabling USB BC"); + ret =3D regmap_field_write(power->usb_bc_en_bit, 1); + if (ret) + dev_err(power->dev, "failed to enable USB BC: errno %d", + ret); + } + power->old_status =3D val; power->online =3D val & AXP20X_PWR_STATUS_VBUS_USED; =20 @@ -123,6 +137,66 @@ static void axp20x_usb_power_poll_vbus(struct work_str= uct *work) mod_delayed_work(system_power_efficient_wq, &power->vbus_detect, DEBOUNC= E_TIME); } =20 +static int +axp20x_usb_power_set_input_current_limit(struct axp20x_usb_power *power, + int limit) +{ + int ret; + unsigned int reg; + + if (!power->axp_data->input_curr_lim_table) + return -EINVAL; + + if (limit < power->axp_data->input_curr_lim_table[0]) + return -EINVAL; + + /* + * BC1.2 detection can cause a race condition if we try to set a current + * limit while it's in progress. When it finishes it will overwrite the + * current limit we just set. + */ + if (power->usb_bc_en_bit) { + dev_dbg(power->dev, + "disabling BC1.2 detection because current limit was set"); + ret =3D regmap_field_write(power->usb_bc_en_bit, 0); + if (ret) + return ret; + } + + for (reg =3D power->axp_data->input_curr_lim_table_size - 1; reg > 0; reg= --) { + if (limit >=3D power->axp_data->input_curr_lim_table[reg]) + break; + } + + dev_dbg(power->dev, "setting input current limit reg to %d (%d uA), reque= sted %d uA", + reg, power->axp_data->input_curr_lim_table[reg], limit); + + return regmap_field_write(power->input_curr_lim_fld, reg); +} + +static int +axp20x_usb_power_get_input_current_limit(struct axp20x_usb_power *power, + int *intval) +{ + int ret; + unsigned int v; + + if (!power->axp_data->input_curr_lim_table) + return -EINVAL; + + ret =3D regmap_field_read(power->input_curr_lim_fld, &v); + if (ret) + return ret; + + if (v < power->axp_data->input_curr_lim_table_size) + *intval =3D power->axp_data->input_curr_lim_table[v]; + else + *intval =3D power->axp_data->input_curr_lim_table[ + power->axp_data->input_curr_lim_table_size - 1]; + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -189,6 +263,9 @@ static int axp20x_usb_power_get_property(struct power_s= upply *psy, =20 val->intval =3D ret * 375; /* 1 step =3D 0.375 mA */ return 0; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return axp20x_usb_power_get_input_current_limit(power, + &val->intval); default: break; } @@ -290,6 +367,10 @@ static int axp20x_usb_power_set_property(struct power_= supply *psy, case POWER_SUPPLY_PROP_CURRENT_MAX: return axp20x_usb_power_set_current_max(power, val->intval); =20 + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: + return axp20x_usb_power_set_input_current_limit(power, + val->intval); + default: return -EINVAL; } @@ -313,7 +394,8 @@ static int axp20x_usb_power_prop_writeable(struct power= _supply *psy, return power->vbus_disable_bit !=3D NULL; =20 return psp =3D=3D POWER_SUPPLY_PROP_VOLTAGE_MIN || - psp =3D=3D POWER_SUPPLY_PROP_CURRENT_MAX; + psp =3D=3D POWER_SUPPLY_PROP_CURRENT_MAX || + psp =3D=3D POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT; } =20 static enum power_supply_property axp20x_usb_power_properties[] =3D { @@ -334,6 +416,15 @@ static enum power_supply_property axp22x_usb_power_pro= perties[] =3D { POWER_SUPPLY_PROP_CURRENT_MAX, }; =20 +static enum power_supply_property axp813_usb_power_properties[] =3D { + POWER_SUPPLY_PROP_HEALTH, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_ONLINE, + POWER_SUPPLY_PROP_VOLTAGE_MIN, + POWER_SUPPLY_PROP_CURRENT_MAX, + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, +}; + static const struct power_supply_desc axp20x_usb_power_desc =3D { .name =3D "axp20x-usb", .type =3D POWER_SUPPLY_TYPE_USB, @@ -354,6 +445,16 @@ static const struct power_supply_desc axp22x_usb_power= _desc =3D { .set_property =3D axp20x_usb_power_set_property, }; =20 +static const struct power_supply_desc axp813_usb_power_desc =3D { + .name =3D "axp20x-usb", + .type =3D POWER_SUPPLY_TYPE_USB, + .properties =3D axp813_usb_power_properties, + .num_properties =3D ARRAY_SIZE(axp813_usb_power_properties), + .property_is_writeable =3D axp20x_usb_power_prop_writeable, + .get_property =3D axp20x_usb_power_get_property, + .set_property =3D axp20x_usb_power_set_property, +}; + static const char * const axp20x_irq_names[] =3D { "VBUS_PLUGIN", "VBUS_REMOVAL", @@ -394,6 +495,18 @@ static int axp813_usb_curr_lim_table[] =3D { 2500000, }; =20 +static int axp_813_usb_input_curr_lim_table[] =3D { + 100000, + 500000, + 900000, + 1500000, + 2000000, + 2500000, + 3000000, + 3500000, + 4000000, +}; + static const struct axp_data axp192_data =3D { .power_desc =3D &axp20x_usb_power_desc, .irq_names =3D axp20x_irq_names, @@ -433,11 +546,14 @@ static const struct axp_data axp223_data =3D { }; =20 static const struct axp_data axp813_data =3D { - .power_desc =3D &axp22x_usb_power_desc, + .power_desc =3D &axp813_usb_power_desc, .irq_names =3D axp22x_irq_names, .num_irq_names =3D ARRAY_SIZE(axp22x_irq_names), .curr_lim_table =3D axp813_usb_curr_lim_table, .curr_lim_fld =3D REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 0, 1), + .input_curr_lim_table_size =3D ARRAY_SIZE(axp_813_usb_input_curr_lim_tabl= e), + .input_curr_lim_table =3D axp_813_usb_input_curr_lim_table, + .input_curr_lim_fld =3D REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), .usb_bc_en_bit =3D REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .vbus_disable_bit =3D REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_needs_polling =3D true, @@ -558,6 +674,7 @@ static int axp20x_usb_power_probe(struct platform_devic= e *pdev) =20 platform_set_drvdata(pdev, power); =20 + power->dev =3D &pdev->dev; power->axp_data =3D axp_data; power->regmap =3D axp20x->regmap; power->num_irqs =3D axp_data->num_irq_names; @@ -567,6 +684,12 @@ static int axp20x_usb_power_probe(struct platform_devi= ce *pdev) if (IS_ERR(power->curr_lim_fld)) return PTR_ERR(power->curr_lim_fld); =20 + ret =3D axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->input_curr_lim_fld, + &power->input_curr_lim_fld); + if (ret) + return ret; + ret =3D axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_valid_bit, &power->vbus_valid_bit); --=20 2.43.0 From nobody Thu Dec 25 09:15:16 2025 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 B279134180; Sun, 21 Jan 2024 01:44:53 +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=1705801495; cv=none; b=t28BSom9w3FvXnGJYNhwVAmCMUoQSaQzwNqfGDgdj9koJUNkR4Qs2YSXjZhq0QVorH3fT4Fto2HqcpFSJBeAVAuxIaI0ts5dBRa0tRVu5Y0w0O1K4A+0/7/qQgRcNQ4bABwl9gTsu36t7dEd8grebmmJaJdE/lAD/l7+VrsBfTM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705801495; c=relaxed/simple; bh=uXkUwCYq0H2JtLAC7JcuuDcFZ0QN3QO/RdNy0mw0xvo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EJ5HZC1zRhMtJ6gXMcB3uV70j3kusff6CKT7bE95jxzG8Nr+vROGXcbAyV/elcypHcJVr0POzT4HKZIJsT1RJKjXZ4hGpkA6/uTjaVS1gj3gU2cL92UvHfL94MFthtneg2oenfnCqaf6t6JxNQF+h/d6J9ynHH2lT+KAstlZZig= 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=bY6eYvsB; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="bY6eYvsB" Received: from authenticated-user (PRIMARY_HOSTNAME [PUBLIC_IP]) by a.peacevolution.org (Postfix) with ESMTPA id 8560743C8C; Sun, 21 Jan 2024 01:44:52 +0000 (UTC) From: Aren Moynihan To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?UTF-8?q?Ond=C5=99ej=20Jirman?= , Aren Moynihan , Chen-Yu Tsai , Sebastian Reichel Subject: [PATCH 2/3] power: supply: axp20x_usb_power: enable usb_type reporting Date: Sat, 20 Jan 2024 20:40:02 -0500 Message-ID: <20240121014057.1042466-5-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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Authentication-Results: auth=pass smtp.auth=aren@peacevolution.org smtp.mailfrom=aren@peacevolution.org X-Spam-Level: *** X-Spamd-Bar: +++ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=peacevolution.org; s=dkim; t=1705801493; h=from:subject:date:message-id:to:cc:mime-version:content-transfer-encoding:in-reply-to:references; bh=1Ryn10C70a9eu2vzgWK/233iIVPb5X5KUoLMJ9eT+QI=; b=bY6eYvsBWw7PD/Q1sl8IgYA0nY9CiwfYHPli59OymCdke/XL10mFB3Nt3C5EPOg0fMfS8B TUfHmMXrWbbP0RvNqZLcvMul3Nysk4SYW9TgT+Z0JtqjCU0vEkDMvmF0BAwKrVCSGTRpDm +oiKXDRhR3D4hqOs0rh4yqn2DFxfkA8= Content-Type: text/plain; charset="utf-8" Axp803 and axp813 can report the detected usb bc mode. SDP, CDP, and DCP are supported. Signed-off-by: Aren Moynihan --- drivers/power/supply/axp20x_usb_power.c | 52 +++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/drivers/power/supply/axp20x_usb_power.c b/drivers/power/supply= /axp20x_usb_power.c index 8c0c2c25565f..5656f6e57d54 100644 --- a/drivers/power/supply/axp20x_usb_power.c +++ b/drivers/power/supply/axp20x_usb_power.c @@ -57,6 +57,7 @@ struct axp_data { struct reg_field vbus_valid_bit; struct reg_field vbus_mon_bit; struct reg_field usb_bc_en_bit; + struct reg_field usb_bc_det_fld; struct reg_field vbus_disable_bit; bool vbus_needs_polling: 1; }; @@ -69,6 +70,7 @@ struct axp20x_usb_power { struct regmap_field *vbus_valid_bit; struct regmap_field *vbus_mon_bit; struct regmap_field *usb_bc_en_bit; + struct regmap_field *usb_bc_det_fld; struct regmap_field *vbus_disable_bit; struct power_supply *supply; const struct axp_data *axp_data; @@ -197,6 +199,37 @@ axp20x_usb_power_get_input_current_limit(struct axp20x= _usb_power *power, return 0; } =20 +static int axp20x_get_usb_type(struct axp20x_usb_power *power, + union power_supply_propval *val) +{ + unsigned int reg; + int ret; + + if (!power->usb_bc_det_fld) + return -EINVAL; + + ret =3D regmap_field_read(power->usb_bc_det_fld, ®); + if (ret) + return ret; + + switch (reg) { + case 1: + val->intval =3D POWER_SUPPLY_USB_TYPE_SDP; + break; + case 2: + val->intval =3D POWER_SUPPLY_USB_TYPE_CDP; + break; + case 3: + val->intval =3D POWER_SUPPLY_USB_TYPE_DCP; + break; + default: + val->intval =3D POWER_SUPPLY_USB_TYPE_UNKNOWN; + break; + } + + return 0; +} + static int axp20x_usb_power_get_property(struct power_supply *psy, enum power_supply_property psp, union power_supply_propval *val) { @@ -266,6 +299,8 @@ static int axp20x_usb_power_get_property(struct power_s= upply *psy, case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: return axp20x_usb_power_get_input_current_limit(power, &val->intval); + case POWER_SUPPLY_PROP_USB_TYPE: + return axp20x_get_usb_type(power, val); default: break; } @@ -423,6 +458,14 @@ static enum power_supply_property axp813_usb_power_pro= perties[] =3D { POWER_SUPPLY_PROP_VOLTAGE_MIN, POWER_SUPPLY_PROP_CURRENT_MAX, POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, + POWER_SUPPLY_PROP_USB_TYPE, +}; + +static enum power_supply_usb_type axp813_usb_types[] =3D { + POWER_SUPPLY_USB_TYPE_SDP, + POWER_SUPPLY_USB_TYPE_DCP, + POWER_SUPPLY_USB_TYPE_CDP, + POWER_SUPPLY_USB_TYPE_UNKNOWN, }; =20 static const struct power_supply_desc axp20x_usb_power_desc =3D { @@ -453,6 +496,8 @@ static const struct power_supply_desc axp813_usb_power_= desc =3D { .property_is_writeable =3D axp20x_usb_power_prop_writeable, .get_property =3D axp20x_usb_power_get_property, .set_property =3D axp20x_usb_power_set_property, + .usb_types =3D axp813_usb_types, + .num_usb_types =3D ARRAY_SIZE(axp813_usb_types), }; =20 static const char * const axp20x_irq_names[] =3D { @@ -555,6 +600,7 @@ static const struct axp_data axp813_data =3D { .input_curr_lim_table =3D axp_813_usb_input_curr_lim_table, .input_curr_lim_fld =3D REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), .usb_bc_en_bit =3D REG_FIELD(AXP288_BC_GLOBAL, 0, 0), + .usb_bc_det_fld =3D REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit =3D REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), .vbus_needs_polling =3D true, }; @@ -708,6 +754,12 @@ static int axp20x_usb_power_probe(struct platform_devi= ce *pdev) if (ret) return ret; =20 + ret =3D axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, + axp_data->usb_bc_det_fld, + &power->usb_bc_det_fld); + if (ret) + return ret; + ret =3D axp20x_regmap_field_alloc_optional(&pdev->dev, power->regmap, axp_data->vbus_disable_bit, &power->vbus_disable_bit); --=20 2.43.0 From nobody Thu Dec 25 09:15:16 2025 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=peacevolution.org header.i=@peacevolution.org header.b="go2unihH" 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 To: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Aidan MacDonald , =?UTF-8?q?Ond=C5=99ej=20Jirman?= , Aren Moynihan , Chen-Yu Tsai , Quentin Schulz , Sebastian Reichel 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: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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= Content-Type: text/plain; charset="utf-8" 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 AXP8= 13") Signed-off-by: Aren Moynihan --- 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 =3D { .input_curr_lim_table_size =3D ARRAY_SIZE(axp_813_usb_input_curr_lim_tabl= e), .input_curr_lim_table =3D axp_813_usb_input_curr_lim_table, .input_curr_lim_fld =3D REG_FIELD(AXP22X_CHRG_CTRL3, 4, 7), + .force_input_curr_lim =3D 500000, .usb_bc_en_bit =3D REG_FIELD(AXP288_BC_GLOBAL, 0, 0), .usb_bc_det_fld =3D REG_FIELD(AXP288_BC_DET_STAT, 5, 7), .vbus_disable_bit =3D REG_FIELD(AXP20X_VBUS_IPSOUT_MGMT, 7, 7), @@ -786,6 +788,17 @@ static int axp20x_usb_power_probe(struct platform_devi= ce *pdev) return ret; } =20 + 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 =3D 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 =3D regmap_field_write(power->usb_bc_en_bit, 1); --=20 2.43.0