Re: [PATCH v2 3/3] power: supply: bq24190_charger: Export current regulator

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Le 24/08/2023 à 15:13, Emmanuel Gil Peyrot a écrit :
From: Alexandre Courbot <acourbot@xxxxxxxxxx>

This prevents the charger from ever going over the current limit.

Signed-off-by: Alexandre Courbot <acourbot@xxxxxxxxxx>
Signed-off-by: Emmanuel Gil Peyrot <linkmauve@xxxxxxxxxxxx>
---
  drivers/power/supply/bq24190_charger.c | 82 ++++++++++++++++++++++++++
  1 file changed, 82 insertions(+)

diff --git a/drivers/power/supply/bq24190_charger.c b/drivers/power/supply/bq24190_charger.c
index a56122b39687..cc1bd87f4982 100644
--- a/drivers/power/supply/bq24190_charger.c
+++ b/drivers/power/supply/bq24190_charger.c
@@ -530,6 +530,79 @@ static int bq24190_set_otg_vbus(struct bq24190_dev_info *bdi, bool enable)
  }
#ifdef CONFIG_REGULATOR
+static int bq24190_set_charging_current(struct regulator_dev *dev,
+			int min_uA, int max_uA)
+{
+	struct bq24190_dev_info *bdi = rdev_get_drvdata(dev);
+	u8 ss_reg;
+	int in_current_limit;
+	int ret = 0;

Nit: Un-needed init.

+
+	ret = bq24190_read(bdi, BQ24190_REG_SS, &ss_reg);
+	if (ret < 0)
+		goto error;
+
+	if (max_uA == 0 && ss_reg != 0)
+		return ret;

ret is known to be 0 here. If it is the intension, return 0 would be more explicit. Otherwise a ret = -<error_code> is missing.

Just my 2c,

CJ

+
+	if (!(ss_reg & BQ24190_REG_SS_VBUS_STAT_MASK))
+		in_current_limit = 500;
+	else
+		in_current_limit = max_uA / 1000;
+
+	return bq24190_set_field_val(bdi, BQ24190_REG_ISC,
+			BQ24190_REG_ISC_IINLIM_MASK,
+			BQ24190_REG_ISC_IINLIM_SHIFT,
+			bq24190_isc_iinlim_values,
+			ARRAY_SIZE(bq24190_isc_iinlim_values),
+			in_current_limit);
+error:
+	dev_err(bdi->dev, "Charger enable failed, err = %d\n", ret);
+	return ret;
+}

...




[Index of Archives]     [Device Tree Compilter]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux PCI Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Yosemite Backpacking]


  Powered by Linux