[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20240530-max77693-charger-extcon-v1-9-dc2a9e5bdf30@gmail.com>
Date: Thu, 30 May 2024 10:55:59 +0200
From: Artur Weber <aweber.kernel@...il.com>
To: Krzysztof Kozlowski <krzk@...nel.org>,
Chanwoo Choi <cw00.choi@...sung.com>
Cc: Sebastian Reichel <sre@...nel.org>, Rob Herring <robh@...nel.org>,
Conor Dooley <conor+dt@...nel.org>, Lee Jones <lee@...nel.org>,
Krzysztof Kozlowski <krzk+dt@...nel.org>,
Alim Akhtar <alim.akhtar@...sung.com>, linux-pm@...r.kernel.org,
devicetree@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org, linux-samsung-soc@...r.kernel.org,
~postmarketos/upstreaming@...ts.sr.ht, Henrik Grimler <henrik@...mler.se>,
Wolfgang Wiedmeyer <wolfgit@...dmeyer.de>,
Denis 'GNUtoo' Carikli <GNUtoo@...erdimension.org>,
Artur Weber <aweber.kernel@...il.com>
Subject: [PATCH RFC 09/11] power: supply: max77693: Set up charge/input
current according to cable type
This behavior was observed on a downstream kernel - for chargers, the
current would be set to a fast charge current value, and it would be
bumped down for all other cable types.
If we leave only the fast charge current value applied, peripheral mode
stops working. If we stick to 500mA, charging becomes too slow. So, set
the charge input current limit accordingly to the cable type.
Signed-off-by: Artur Weber <aweber.kernel@...il.com>
---
drivers/power/supply/max77693_charger.c | 35 ++++++++++++++++++++++++++-------
1 file changed, 28 insertions(+), 7 deletions(-)
diff --git a/drivers/power/supply/max77693_charger.c b/drivers/power/supply/max77693_charger.c
index e548fd420e78..76e08775f796 100644
--- a/drivers/power/supply/max77693_charger.c
+++ b/drivers/power/supply/max77693_charger.c
@@ -711,6 +711,10 @@ static int max77693_reg_init(struct max77693_charger *chg)
if (ret)
return ret;
+ /*
+ * Set it to a lower value by default; the DT fast charge current
+ * property is applied later, in the charger detection mechanism.
+ */
ret = max77693_set_input_current_limit(chg,
DEFAULT_FAST_CHARGE_CURRENT);
if (ret)
@@ -772,6 +776,7 @@ static void max77693_charger_extcon_work(struct work_struct *work)
cable.work);
struct extcon_dev *edev = chg->cable.edev;
bool set_charging, set_otg;
+ unsigned int input_current;
int connector, state;
int ret;
@@ -784,19 +789,28 @@ static void max77693_charger_extcon_work(struct work_struct *work)
switch (connector) {
case EXTCON_CHG_USB_SDP:
- case EXTCON_CHG_USB_DCP:
case EXTCON_CHG_USB_CDP:
+ case EXTCON_CHG_USB_SLOW:
+ input_current = 500000; /* 500 mA */
+ set_charging = true;
+ set_otg = false;
+
+ dev_info(chg->dev, "slow charging. connector type: %d\n",
+ connector);
+ break;
+ case EXTCON_CHG_USB_DCP:
case EXTCON_CHG_USB_ACA:
case EXTCON_CHG_USB_FAST:
- case EXTCON_CHG_USB_SLOW:
case EXTCON_CHG_USB_PD:
+ input_current = chg->fast_charge_current;
set_charging = true;
set_otg = false;
- dev_info(chg->dev, "charging. connector type: %d\n",
+ dev_info(chg->dev, "fast charging. connector type: %d\n",
connector);
break;
case EXTCON_USB_HOST:
+ input_current = 500000; /* 500 mA */
set_charging = false;
set_otg = true;
@@ -804,6 +818,7 @@ static void max77693_charger_extcon_work(struct work_struct *work)
connector);
break;
default:
+ input_current = 500000; /* 500 mA */
set_charging = false;
set_otg = false;
@@ -812,10 +827,12 @@ static void max77693_charger_extcon_work(struct work_struct *work)
break;
}
- /*
- * The functions below already check if the change is necessary,
- * so we don't need to do so here.
- */
+ ret = max77693_set_input_current_limit(chg, input_current);
+ if (ret) {
+ dev_err(chg->dev, "failed to set input current (%d)\n", ret);
+ goto out;
+ }
+
ret = max77693_set_charging(chg, set_charging);
if (ret) {
dev_err(chg->dev, "failed to set charging (%d)\n", ret);
@@ -887,6 +904,10 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
&chg->batttery_overcurrent))
chg->batttery_overcurrent = DEFAULT_BATTERY_OVERCURRENT;
+ if (of_property_read_u32(np, "maxim,fast-charge-current-microamp",
+ &chg->fast_charge_current))
+ chg->fast_charge_current = DEFAULT_FAST_CHARGE_CURRENT;
+
if (of_property_read_u32(np, "maxim,charge-input-threshold-microvolt",
&chg->charge_input_threshold_volt))
chg->charge_input_threshold_volt =
--
2.45.1
Powered by blists - more mailing lists