Skip to contentSkip to conversation

max77693: USB event listener for charger

PATCH In review Wolfgang Wiedmeyer 3 participants 14 messages Sep 26, 2016 – Sep 28, 2016

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover max77693: USB event listener for charger

This patch series adds an USB event listener to the charger driver that enables charging if an USB cable is connected. Before the charger can be enabled, the maximum input current and the fast charge current need to be set. In order to make this possible, the regulator function that sets the current needs to be extended.

Wolfgang Wiedmeyer (3):
mfd: max77693: Add defines for charger current control
regulator: max77693: Also manipulate the fast charge current
power_supply: max77693: Listen for cable events and enable charging

 drivers/power/Kconfig                  |   2 +-
 drivers/power/max77693_charger.c       | 171 +++++++++++++++++++++++++++++++++
 drivers/regulator/max77693-regulator.c |  45 ++++++++-
 include/linux/mfd/max77693-private.h   |   7 ++
 4 files changed, 221 insertions(+), 4 deletions(-)
Signature · 1 line
2.8.0.rc3
#1 lore raw

PATCH 1/3 mfd: max77693: Add defines for charger current control

This prepares for an updated regulator and charger driver. The defines are needed to set the maximum input current and the fast charge current.

---
 include/linux/mfd/max77693-private.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/mfd/max77693-private.h +7 -0
index 3c7a63b..ca18344 100644
@@ -222,6 +222,9 @@ enum max77693_charger_battery_state {
 #define CHG_CNFG_00_CHG_MASK		0x1
 #define CHG_CNFG_00_BUCK_MASK		0x4
 
+/* MAX77693 CHG_CNFG_02 register */
+#define CHG_CNFG_02_CC_MASK		0x3F
+
 /* MAX77693_CHG_REG_CHG_CNFG_01 register */
 #define CHG_CNFG_01_FCHGTIME_SHIFT	0
 #define CHG_CNFG_01_CHGRSTRT_SHIFT	4
@@ -258,6 +261,10 @@ enum max77693_charger_battery_state {
 
 /* MAX77693 CHG_CNFG_09 Register */
 #define CHG_CNFG_09_CHGIN_ILIM_MASK	0x7F
+#define CHG_CNFG_09_CHGIN_ILIM_500_MAX	500000
+#define CHG_CNFG_09_CHGIN_ILIM_500_MIN	470000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MAX	60000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MIN	0
 
 /* MAX77693 CHG_CTRL Register */
 #define SAFEOUT_CTRL_SAFEOUT1_MASK	0x3
Signature · 1 line
2.8.0.rc3
#2 lore raw

Re: [PATCH 1/3] mfd: max77693: Add defines for charger current control

Quoted 5 lines · Wolfgang Wiedmeyer

This prepares for an updated regulator and charger driver. The defines are needed to set the maximum input current and the fast charge current.

This shouldn't be separate patch, because:
1. You are touching later power and regulator so this patch should be applied to one and then pulled by other... a lot of unneeded work.
2. It is difficult to find which new code is needed for which driver.

Simpler approach might work - when changing the regulator or psy driver, just change the header as needed. Unless there are conflicts and both of them need the same?

Best regards,
Krzysztof

Quoted 32 lines
---
 include/linux/mfd/max77693-private.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/mfd/max77693-private.h +7 -0
index 3c7a63b..ca18344 100644
@@ -222,6 +222,9 @@ enum max77693_charger_battery_state {
 #define CHG_CNFG_00_CHG_MASK		0x1
 #define CHG_CNFG_00_BUCK_MASK		0x4
 
+/* MAX77693 CHG_CNFG_02 register */
+#define CHG_CNFG_02_CC_MASK		0x3F
+
 /* MAX77693_CHG_REG_CHG_CNFG_01 register */
 #define CHG_CNFG_01_FCHGTIME_SHIFT	0
 #define CHG_CNFG_01_CHGRSTRT_SHIFT	4
@@ -258,6 +261,10 @@ enum max77693_charger_battery_state {
 
 /* MAX77693 CHG_CNFG_09 Register */
 #define CHG_CNFG_09_CHGIN_ILIM_MASK	0x7F
+#define CHG_CNFG_09_CHGIN_ILIM_500_MAX	500000
+#define CHG_CNFG_09_CHGIN_ILIM_500_MIN	470000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MAX	60000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MIN	0
 
 /* MAX77693 CHG_CTRL Register */
 #define SAFEOUT_CTRL_SAFEOUT1_MASK	0x3
Signature · 1 line
2.8.0.rc3
#3 lore raw

Re: [PATCH 1/3] mfd: max77693: Add defines for charger current control

Quoted 7 lines · Krzysztof Kozlowski
Quoted 5 lines · Wolfgang Wiedmeyer

This prepares for an updated regulator and charger driver. The defines are needed to set the maximum input current and the fast charge current.

Quoted 8 lines

This shouldn't be separate patch, because:
1. You are touching later power and regulator so this patch should be applied to one and then pulled by other... a lot of unneeded work.
2. It is difficult to find which new code is needed for which driver.

Simpler approach might work - when changing the regulator or psy driver, just change the header as needed. Unless there are conflicts and both of them need the same?

No, no conflicts. I will change the header as needed and won't do a separate patch.

Thanks,
Wolfgang

Quoted 35 lines

Best regards,
Krzysztof

Quoted 32 lines
---
 include/linux/mfd/max77693-private.h | 7 +++++++
 1 file changed, 7 insertions(+)
include/linux/mfd/max77693-private.h +7 -0
index 3c7a63b..ca18344 100644
@@ -222,6 +222,9 @@ enum max77693_charger_battery_state {
 #define CHG_CNFG_00_CHG_MASK		0x1
 #define CHG_CNFG_00_BUCK_MASK		0x4
 
+/* MAX77693 CHG_CNFG_02 register */
+#define CHG_CNFG_02_CC_MASK		0x3F
+
 /* MAX77693_CHG_REG_CHG_CNFG_01 register */
 #define CHG_CNFG_01_FCHGTIME_SHIFT	0
 #define CHG_CNFG_01_CHGRSTRT_SHIFT	4
@@ -258,6 +261,10 @@ enum max77693_charger_battery_state {
 
 /* MAX77693 CHG_CNFG_09 Register */
 #define CHG_CNFG_09_CHGIN_ILIM_MASK	0x7F
+#define CHG_CNFG_09_CHGIN_ILIM_500_MAX	500000
+#define CHG_CNFG_09_CHGIN_ILIM_500_MIN	470000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MAX	60000
+#define CHG_CNFG_09_CHGIN_ILIM_0_MIN	0
 
 /* MAX77693 CHG_CTRL Register */
 #define SAFEOUT_CTRL_SAFEOUT1_MASK	0x3
Signature · 1 line
2.8.0.rc3
Signature · 3 lines
Website: https://fossencdi.org
OpenPGP: 0F30 D1A0 2F73 F70A 6FEE  048E 5816 A24C 1075 7FC4
Key download: https://wiedmeyer.de/keys/ww.asc
#4 lore raw

PATCH 2/3 regulator: max77693: Also manipulate the fast charge current

In reply to Wolfgang Wiedmeyer

For MAX77693, the fast charge current also needs to be manipulated for proper charging. The fast charge current is only set in the case of the MAX77693 type, as the MAX77843 properly manipulates the fast charge current.
The fast charge current is set to the next possible value below the maximum input current.

---
 drivers/regulator/max77693-regulator.c | 45 +++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
drivers/regulator/max77693-regulator.c +42 -3
index cfbb951..e2f7584 100644
@@ -54,14 +54,19 @@ struct chg_reg_data {
 	unsigned int linear_mask;
 	unsigned int uA_step;
 	unsigned int min_sel;
+
+	bool set_fast;
+	unsigned int fast_reg;
+	unsigned int fast_mask;
 };
 
 /*
  * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
  * 0x00, 0x01, 0x2, 0x03	= 60 mA
  * 0x04 ~ 0x7E			= (60 + (X - 3) * 20) mA
- * Actually for MAX77693 the driver manipulates the maximum input current,
- * not the fast charge current (output). This should be fixed.
+ * Actually for MAX77693 the driver manipulates the maximum input current
+ * and the fast charge current (output) because the fast charge current
+ * is not set.
  *
  * On MAX77843 the calculation formula is the same (except values).
  * Fortunately it properly manipulates the fast charge current.
@@ -100,6 +105,8 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
 	unsigned int chg_min_uA = rdev->constraints->min_uA;
 	int sel = 0;
+	unsigned int data;
+	int ret;
 
 	while (chg_min_uA + reg_data->uA_step * sel < min_uA)
 		sel++;
@@ -110,7 +117,35 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	/* the first four codes for charger current are all 60mA */
 	sel += reg_data->min_sel;
 
-	return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	ret = regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	if (ret < 0)
+		return ret;
+
+	if (reg_data->set_fast) {
+		/* disable fast charge if minimum value */
+		if (sel == reg_data->min_sel)
+			data = 0;
+		else {
+			/*
+			 * set the fast charge current to the closest value
+			 * below the input current
+			 */
+			ret = regmap_read(rdev->regmap, reg_data->fast_reg,
+					  &data);
+			if (ret < 0)
+				return ret;
+
+			sel *= reg_data->uA_step / 1000; /* convert to mA */
+			data &= ~reg_data->fast_mask;
+			data |= sel * 10 / 333; /* 0.1A/3 steps */
+		}
+
+		ret = regmap_write(rdev->regmap, reg_data->fast_reg, data);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
 }
 /* end of CHARGER regulator ops */
 
@@ -197,6 +232,9 @@ static const struct chg_reg_data max77693_chg_reg_data = {
 	.linear_mask	= CHG_CNFG_09_CHGIN_ILIM_MASK,
 	.uA_step	= 20000,
 	.min_sel	= 3,
+	.set_fast	= true,
+	.fast_reg	= MAX77693_CHG_REG_CHG_CNFG_02,
+	.fast_mask	= CHG_CNFG_02_CC_MASK,
 };
 
 #define	max77843_regulator_desc_esafeout(num)	{			\
@@ -237,6 +275,7 @@ static const struct chg_reg_data max77843_chg_reg_data = {
 	.linear_mask	= MAX77843_CHG_FAST_CHG_CURRENT_MASK,
 	.uA_step	= MAX77843_CHG_FAST_CHG_CURRENT_STEP,
 	.min_sel	= 2,
+	.set_fast	= false,
 };
 
 static int max77693_pmic_probe(struct platform_device *pdev)
Signature · 1 line
2.8.0.rc3
#5 lore raw

Re: [PATCH 2/3] regulator: max77693: Also manipulate the fast charge current

Quoted 4 lines · Wolfgang Wiedmeyer

For MAX77693, the fast charge current also needs to be manipulated for proper charging. The fast charge current is only set in the case of the MAX77693 type, as the MAX77843 properly manipulates the fast charge current.

Are you sure it has to be manipulated? Some time I didn't dig into this. Now I looked at the datasheet and it says that usually there is no need for changing the charge current during the operation. Maxim recommends to setting it to a maximum safe value for the battery. The device will manage charge current on its own.

However I agree that the charge current should be set... maybe once, to a maximum value appropriate for battery. Probably this should be done by max77693_charger in max77693_dt_init().

Best regards,
Krzysztof

Quoted 103 lines

The fast charge current is set to the next possible value below the maximum input current.

---
 drivers/regulator/max77693-regulator.c | 45 +++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
drivers/regulator/max77693-regulator.c +42 -3
index cfbb951..e2f7584 100644
@@ -54,14 +54,19 @@ struct chg_reg_data {
 	unsigned int linear_mask;
 	unsigned int uA_step;
 	unsigned int min_sel;
+
+	bool set_fast;
+	unsigned int fast_reg;
+	unsigned int fast_mask;
 };
 
 /*
  * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
  * 0x00, 0x01, 0x2, 0x03	= 60 mA
  * 0x04 ~ 0x7E			= (60 + (X - 3) * 20) mA
- * Actually for MAX77693 the driver manipulates the maximum input current,
- * not the fast charge current (output). This should be fixed.
+ * Actually for MAX77693 the driver manipulates the maximum input current
+ * and the fast charge current (output) because the fast charge current
+ * is not set.
  *
  * On MAX77843 the calculation formula is the same (except values).
  * Fortunately it properly manipulates the fast charge current.
@@ -100,6 +105,8 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
 	unsigned int chg_min_uA = rdev->constraints->min_uA;
 	int sel = 0;
+	unsigned int data;
+	int ret;
 
 	while (chg_min_uA + reg_data->uA_step * sel < min_uA)
 		sel++;
@@ -110,7 +117,35 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	/* the first four codes for charger current are all 60mA */
 	sel += reg_data->min_sel;
 
-	return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	ret = regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	if (ret < 0)
+		return ret;
+
+	if (reg_data->set_fast) {
+		/* disable fast charge if minimum value */
+		if (sel == reg_data->min_sel)
+			data = 0;
+		else {
+			/*
+			 * set the fast charge current to the closest value
+			 * below the input current
+			 */
+			ret = regmap_read(rdev->regmap, reg_data->fast_reg,
+					  &data);
+			if (ret < 0)
+				return ret;
+
+			sel *= reg_data->uA_step / 1000; /* convert to mA */
+			data &= ~reg_data->fast_mask;
+			data |= sel * 10 / 333; /* 0.1A/3 steps */
+		}
+
+		ret = regmap_write(rdev->regmap, reg_data->fast_reg, data);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
 }
 /* end of CHARGER regulator ops */
 
@@ -197,6 +232,9 @@ static const struct chg_reg_data max77693_chg_reg_data = {
 	.linear_mask	= CHG_CNFG_09_CHGIN_ILIM_MASK,
 	.uA_step	= 20000,
 	.min_sel	= 3,
+	.set_fast	= true,
+	.fast_reg	= MAX77693_CHG_REG_CHG_CNFG_02,
+	.fast_mask	= CHG_CNFG_02_CC_MASK,
 };
 
 #define	max77843_regulator_desc_esafeout(num)	{			\
@@ -237,6 +275,7 @@ static const struct chg_reg_data max77843_chg_reg_data = {
 	.linear_mask	= MAX77843_CHG_FAST_CHG_CURRENT_MASK,
 	.uA_step	= MAX77843_CHG_FAST_CHG_CURRENT_STEP,
 	.min_sel	= 2,
+	.set_fast	= false,
 };
 
 static int max77693_pmic_probe(struct platform_device *pdev)
Signature · 1 line
2.8.0.rc3
#6 lore raw

Re: [PATCH 2/3] regulator: max77693: Also manipulate the fast charge current

Quoted 12 lines · Krzysztof Kozlowski
Quoted 4 lines · Wolfgang Wiedmeyer

For MAX77693, the fast charge current also needs to be manipulated for proper charging. The fast charge current is only set in the case of the MAX77693 type, as the MAX77843 properly manipulates the fast charge current.

Are you sure it has to be manipulated? Some time I didn't dig into this. Now I looked at the datasheet and it says that usually there is no need for changing the charge current during the operation. Maxim recommends to setting it to a maximum safe value for the battery. The device will manage charge current on its own.

Quoted 3 lines

However I agree that the charge current should be set... maybe once, to a maximum value appropriate for battery. Probably this should be done by max77693_charger in max77693_dt_init().

When charging is disabled (e.g. by removing the USB cable) the charge current is not reset to zero. So if I expose the current by the CURRENT_NOW property, it incorrectly reports the current that was set when charging was enabled, although there is no charging going on anymore. So I felt the need to update the charge current every time the charger gets enabled or disabled.
Initially, the charge current is set to zero, so I think it needs to be set at least at the beginning to enable charging.

Thanks,
Wolfgang

Quoted 107 lines

Best regards,
Krzysztof

Quoted 103 lines

The fast charge current is set to the next possible value below the maximum input current.

---
 drivers/regulator/max77693-regulator.c | 45 +++++++++++++++++++++++++++++++---
 1 file changed, 42 insertions(+), 3 deletions(-)
drivers/regulator/max77693-regulator.c +42 -3
index cfbb951..e2f7584 100644
@@ -54,14 +54,19 @@ struct chg_reg_data {
 	unsigned int linear_mask;
 	unsigned int uA_step;
 	unsigned int min_sel;
+
+	bool set_fast;
+	unsigned int fast_reg;
+	unsigned int fast_mask;
 };
 
 /*
  * MAX77693 CHARGER regulator - Min : 20mA, Max : 2580mA, step : 20mA
  * 0x00, 0x01, 0x2, 0x03	= 60 mA
  * 0x04 ~ 0x7E			= (60 + (X - 3) * 20) mA
- * Actually for MAX77693 the driver manipulates the maximum input current,
- * not the fast charge current (output). This should be fixed.
+ * Actually for MAX77693 the driver manipulates the maximum input current
+ * and the fast charge current (output) because the fast charge current
+ * is not set.
  *
  * On MAX77843 the calculation formula is the same (except values).
  * Fortunately it properly manipulates the fast charge current.
@@ -100,6 +105,8 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	const struct chg_reg_data *reg_data = rdev_get_drvdata(rdev);
 	unsigned int chg_min_uA = rdev->constraints->min_uA;
 	int sel = 0;
+	unsigned int data;
+	int ret;
 
 	while (chg_min_uA + reg_data->uA_step * sel < min_uA)
 		sel++;
@@ -110,7 +117,35 @@ static int max77693_chg_set_current_limit(struct regulator_dev *rdev,
 	/* the first four codes for charger current are all 60mA */
 	sel += reg_data->min_sel;
 
-	return regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	ret = regmap_write(rdev->regmap, reg_data->linear_reg, sel);
+	if (ret < 0)
+		return ret;
+
+	if (reg_data->set_fast) {
+		/* disable fast charge if minimum value */
+		if (sel == reg_data->min_sel)
+			data = 0;
+		else {
+			/*
+			 * set the fast charge current to the closest value
+			 * below the input current
+			 */
+			ret = regmap_read(rdev->regmap, reg_data->fast_reg,
+					  &data);
+			if (ret < 0)
+				return ret;
+
+			sel *= reg_data->uA_step / 1000; /* convert to mA */
+			data &= ~reg_data->fast_mask;
+			data |= sel * 10 / 333; /* 0.1A/3 steps */
+		}
+
+		ret = regmap_write(rdev->regmap, reg_data->fast_reg, data);
+		if (ret < 0)
+			return ret;
+	}
+
+	return 0;
 }
 /* end of CHARGER regulator ops */
 
@@ -197,6 +232,9 @@ static const struct chg_reg_data max77693_chg_reg_data = {
 	.linear_mask	= CHG_CNFG_09_CHGIN_ILIM_MASK,
 	.uA_step	= 20000,
 	.min_sel	= 3,
+	.set_fast	= true,
+	.fast_reg	= MAX77693_CHG_REG_CHG_CNFG_02,
+	.fast_mask	= CHG_CNFG_02_CC_MASK,
 };
 
 #define	max77843_regulator_desc_esafeout(num)	{			\
@@ -237,6 +275,7 @@ static const struct chg_reg_data max77843_chg_reg_data = {
 	.linear_mask	= MAX77843_CHG_FAST_CHG_CURRENT_MASK,
 	.uA_step	= MAX77843_CHG_FAST_CHG_CURRENT_STEP,
 	.min_sel	= 2,
+	.set_fast	= false,
 };
 
 static int max77693_pmic_probe(struct platform_device *pdev)
Signature · 1 line
2.8.0.rc3
Signature · 3 lines
Website: https://fossencdi.org
OpenPGP: 0F30 D1A0 2F73 F70A 6FEE  048E 5816 A24C 1075 7FC4
Key download: https://wiedmeyer.de/keys/ww.asc
maintainer
#7 lore raw

Re: [PATCH 2/3] regulator: max77693: Also manipulate the fast charge current

Quoted 8 lines · Wolfgang Wiedmeyer

When charging is disabled (e.g. by removing the USB cable) the charge current is not reset to zero. So if I expose the current by the CURRENT_NOW property, it incorrectly reports the current that was set when charging was enabled, although there is no charging going on anymore. So I felt the need to update the charge current every time the charger gets enabled or disabled.
Initially, the charge current is set to zero, so I think it needs to be set at least at the beginning to enable charging.

Are you sure that the register value you're looking at is the actual charge current right now and not just the maximum that the charger will try to use depending on the conditions (supply available, battery state...)? It seems like you're acting as though it's the latter but that's not what the chip is doing.

#8 lore raw

Re: [PATCH 2/3] regulator: max77693: Also manipulate the fast charge current

Quoted 11 lines · Mark Brown
Quoted 8 lines · Wolfgang Wiedmeyer

When charging is disabled (e.g. by removing the USB cable) the charge current is not reset to zero. So if I expose the current by the CURRENT_NOW property, it incorrectly reports the current that was set when charging was enabled, although there is no charging going on anymore. So I felt the need to update the charge current every time the charger gets enabled or disabled.
Initially, the charge current is set to zero, so I think it needs to be set at least at the beginning to enable charging.

Quoted 5 lines

Are you sure that the register value you're looking at is the actual charge current right now and not just the maximum that the charger will try to use depending on the conditions (supply available, battery state...)? It seems like you're acting as though it's the latter but that's not what the chip is doing.

I was looking at the vendor code that was released for the Galaxy S3 and there the same register gets accessed for getting the current for the CURRENT_NOW property [1] and for setting the current [2]. So is this probably the wrong use of the CURRENT_NOW property because not the actual charge current is read but the maximum value that was set? Unfortunately, I don't have access to the datasheet and I didn't find it online so I don't know where the actual current can be accessed.

Thanks,
Wolfgang

[1] https://code.fossencdi.org/kernel_samsung_smdk4412.git/tree/drivers/battery/max77693_charger.c#n531

[2] https://code.fossencdi.org/kernel_samsung_smdk4412.git/tree/drivers/battery/max77693_charger.c#n552

Signature · 3 lines
Website: https://fossencdi.org
OpenPGP: 0F30 D1A0 2F73 F70A 6FEE  048E 5816 A24C 1075 7FC4
Key download: https://wiedmeyer.de/keys/ww.asc
#9 lore raw

Re: [PATCH 2/3] regulator: max77693: Also manipulate the fast charge current

Quoted 20 lines · Wolfgang Wiedmeyer
Quoted 11 lines · Mark Brown
Quoted 8 lines · Wolfgang Wiedmeyer

When charging is disabled (e.g. by removing the USB cable) the charge current is not reset to zero. So if I expose the current by the CURRENT_NOW property, it incorrectly reports the current that was set when charging was enabled, although there is no charging going on anymore. So I felt the need to update the charge current every time the charger gets enabled or disabled.
Initially, the charge current is set to zero, so I think it needs to be set at least at the beginning to enable charging.

Quoted 5 lines

Are you sure that the register value you're looking at is the actual charge current right now and not just the maximum that the charger will try to use depending on the conditions (supply available, battery state...)? It seems like you're acting as though it's the latter but that's not what the chip is doing.

Quoted 6 lines

I was looking at the vendor code that was released for the Galaxy S3 and there the same register gets accessed for getting the current for the CURRENT_NOW property [1] and for setting the current [2]. So is this probably the wrong use of the CURRENT_NOW property because not the actual charge current is read but the maximum value that was set?

Yes, reading from this register will give only information about currently set charge current. Not the real current.

Best regards,
Krzysztof

#10 lore raw

PATCH 3/3 power_supply: max77693: Listen for cable events and enable charging

In reply to Wolfgang Wiedmeyer

This patch adds a listener for extcon cable events and enables charging if an USB cable is connected. It recognizes SDP and DCP cable types and treats them the same (same input current and fast charge current). The maximum input current is set before the charger is enabled and before the charger gets disabled, the maximum input current is set to zero. The listener is inspired by the listener implementation that was used for the AXP288 Charger driver.

The patch also adds support for the CURRENT_NOW property. It reads the fast charge current that gets set before the charger is enabled or disabled.

---
 drivers/power/Kconfig            |   2 +-
 drivers/power/max77693_charger.c | 171 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 172 insertions(+), 1 deletion(-)
drivers/power/Kconfig +1 -1
index acd4a15..28254d3 100644
@@ -372,7 +372,7 @@ config CHARGER_MAX14577
 
 config CHARGER_MAX77693
 	tristate "Maxim MAX77693 battery charger driver"
-	depends on MFD_MAX77693
+	depends on MFD_MAX77693 && REGULATOR_MAX77693
 	help
 	  Say Y to enable support for the Maxim MAX77693 battery charger.
 
drivers/power/max77693_charger.c +171 -0

239 lines not on this page · raw message

Signature · 1 line
2.8.0.rc3
#11 lore raw

Re: [PATCH 3/3] power_supply: max77693: Listen for cable events and enable charging

Quoted 8 lines · Wolfgang Wiedmeyer

This patch adds a listener for extcon cable events and enables charging if an USB cable is connected. It recognizes SDP and DCP cable types and treats them the same (same input current and fast charge current). The maximum input current is set before the charger is enabled and before the charger gets disabled, the maximum input current is set to zero. The listener is inspired by the listener implementation that was used for the AXP288 Charger driver.

Quoted 5 lines

The patch also adds support for the CURRENT_NOW property. It reads the fast charge current that gets set before the charger is enabled or disabled.

No. This power supply driver should not manage regulators. It is not a regulator consumer. For that specific need, there is a charger-manager driver.

I agree that you might configure here the charger. You might even expose some writeable properties through power supply class. However the purpose of this driver is to expose the battery charger to user-space, not to replace the user-space with its work.

So... NACK.

If you would like to play with charger-manager, here is my old DTS for Trats2 (might need updates):

index 595ad4ba6977..b4361b4a9de7 100644

arch/arm/boot/dts/exynos4412-trats2.dts +38 -0
@@ -856,6 +856,44 @@
                };
        };
 
+       charger-manager@0 {
+               compatible = "charger-manager";
+               status = "okay";
+               chg-reg-supply = <&charger_reg>;
+
+               cm-name = "battery";
+               /* Polling only for external power source */
+               cm-poll-mode = <2>;
+               cm-poll-interval = <30000>;
+
+               cm-fullbatt-vchkdrop-ms = <30000>;
+               cm-fullbatt-vchkdrop-volt = <150000>;
+               cm-fullbatt-soc = <100>;
+
+               cm-battery-stat = <0>;
+               cm-fuel-gauge = "max170xx_battery";
+
+               /* Allow charging for 5hr */
+               cm-charging-max = <18000000>;
+               /* Allow discharging for 2hr */
+               cm-discharging-max = <7200000>;
+
+               cm-num-chargers = <1>;
+               cm-chargers = "max77693-charger";
+
+               charger@0 {
+                       cm-regulator-name = "chg-reg";
+                       cable@0 {
+                               cm-cable-name = "USB";
+                               cm-cable-extcon = "max77693-muic";
+                       };
+                       cable@1 {
+                               cm-cable-name = "TA";
+                               cm-cable-extcon = "max77693-muic";
+                       };
+               };
+       };
+
        exynos-usbphy@125B0000 {
                status = "okay";
        };

Best regards,
Krzysztof

#12 lore raw

Re: [PATCH 3/3] power_supply: max77693: Listen for cable events and enable charging

Quoted 9 lines · Krzysztof Kozlowski
Quoted 8 lines · Wolfgang Wiedmeyer

This patch adds a listener for extcon cable events and enables charging if an USB cable is connected. It recognizes SDP and DCP cable types and treats them the same (same input current and fast charge current). The maximum input current is set before the charger is enabled and before the charger gets disabled, the maximum input current is set to zero. The listener is inspired by the listener implementation that was used for the AXP288 Charger driver.

Quoted 8 lines
Quoted 5 lines

The patch also adds support for the CURRENT_NOW property. It reads the fast charge current that gets set before the charger is enabled or disabled.

No. This power supply driver should not manage regulators. It is not a regulator consumer. For that specific need, there is a charger-manager driver.

When I was in the middle of implementing this, I noticed that the charger manager does everything that is needed. But it took me quite some time to configure the DTS correctly until I realized that the charger manager used a deprecated function (extcon_register_interest()) and thus couldn't work. And as I didn't see the charger-manager in any other device's DTS, I thought that this might not be right way.
But Chanwoo Choi has a fix: https://patchwork.kernel.org/patch/8898541/
So I will try to get it working with this patch.

Quoted 6 lines

I agree that you might configure here the charger. You might even expose some writeable properties through power supply class. However the purpose of this driver is to expose the battery charger to user-space, not to replace the user-space with its work.

So... NACK.

Ok, then I will try to reduce the patch to the CURRENT_NOW property support.

Quoted 2 lines

If you would like to play with charger-manager, here is my old DTS for Trats2 (might need updates):

Is there a reason that this patch is not in the kernel? It would have been very helpful for me :)

Thanks,
Wolfgang

Quoted 53 lines

index 595ad4ba6977..b4361b4a9de7 100644

arch/arm/boot/dts/exynos4412-trats2.dts +38 -0
@@ -856,6 +856,44 @@
                };
        };
 
+       charger-manager@0 {
+               compatible = "charger-manager";
+               status = "okay";
+               chg-reg-supply = <&charger_reg>;
+
+               cm-name = "battery";
+               /* Polling only for external power source */
+               cm-poll-mode = <2>;
+               cm-poll-interval = <30000>;
+
+               cm-fullbatt-vchkdrop-ms = <30000>;
+               cm-fullbatt-vchkdrop-volt = <150000>;
+               cm-fullbatt-soc = <100>;
+
+               cm-battery-stat = <0>;
+               cm-fuel-gauge = "max170xx_battery";
+
+               /* Allow charging for 5hr */
+               cm-charging-max = <18000000>;
+               /* Allow discharging for 2hr */
+               cm-discharging-max = <7200000>;
+
+               cm-num-chargers = <1>;
+               cm-chargers = "max77693-charger";
+
+               charger@0 {
+                       cm-regulator-name = "chg-reg";
+                       cable@0 {
+                               cm-cable-name = "USB";
+                               cm-cable-extcon = "max77693-muic";
+                       };
+                       cable@1 {
+                               cm-cable-name = "TA";
+                               cm-cable-extcon = "max77693-muic";
+                       };
+               };
+       };
+
        exynos-usbphy@125B0000 {
                status = "okay";
        };

Best regards,
Krzysztof

Signature · 3 lines
Website: https://fossencdi.org
OpenPGP: 0F30 D1A0 2F73 F70A 6FEE  048E 5816 A24C 1075 7FC4
Key download: https://wiedmeyer.de/keys/ww.asc
#13 lore raw

Re: [PATCH 3/3] power_supply: max77693: Listen for cable events and enable charging

Quoted 38 lines · Wolfgang Wiedmeyer
Quoted 9 lines · Krzysztof Kozlowski
Quoted 8 lines · Wolfgang Wiedmeyer

This patch adds a listener for extcon cable events and enables charging if an USB cable is connected. It recognizes SDP and DCP cable types and treats them the same (same input current and fast charge current). The maximum input current is set before the charger is enabled and before the charger gets disabled, the maximum input current is set to zero. The listener is inspired by the listener implementation that was used for the AXP288 Charger driver.

Quoted 8 lines
Quoted 5 lines

The patch also adds support for the CURRENT_NOW property. It reads the fast charge current that gets set before the charger is enabled or disabled.

No. This power supply driver should not manage regulators. It is not a regulator consumer. For that specific need, there is a charger-manager driver.

When I was in the middle of implementing this, I noticed that the charger manager does everything that is needed. But it took me quite some time to configure the DTS correctly until I realized that the charger manager used a deprecated function (extcon_register_interest()) and thus couldn't work. And as I didn't see the charger-manager in any other device's DTS, I thought that this might not be right way.
But Chanwoo Choi has a fix: https://patchwork.kernel.org/patch/8898541/
So I will try to get it working with this patch.

Quoted 6 lines

I agree that you might configure here the charger. You might even expose some writeable properties through power supply class. However the purpose of this driver is to expose the battery charger to user-space, not to replace the user-space with its work.

So... NACK.

Quoted 8 lines

Ok, then I will try to reduce the patch to the CURRENT_NOW property support.

Quoted 2 lines

If you would like to play with charger-manager, here is my old DTS for Trats2 (might need updates):

Is there a reason that this patch is not in the kernel? It would have been very helpful for me :)

In general, DeviceTree should describe the hardware. Charger manager is an abstract device, not a real one. This DT node does not describe real hardware but it is a driver-specific glue needed to get things done.

I am not convinced that we should add to DTS such abstract devices. What about people who want to control charging from user-space? They would have to disable charger-manager from config.

Best regards,
Krzysztof