linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling
@ 2020-12-30 20:51 Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
                   ` (9 more replies)
  0 siblings, 10 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:51 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

This allows the MAX8997 charger to set the current limit depending on
the detected extcon charger type.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: No change.
v4: No change.
v3: No change.
v2: Remove empty line.

 drivers/extcon/extcon-max8997.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 337b0eea4e62..e1408075ef7d 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -44,6 +44,8 @@ static struct max8997_muic_irq muic_irqs[] = {
 	{ MAX8997_MUICIRQ_ChgDetRun,	"muic-CHGDETRUN" },
 	{ MAX8997_MUICIRQ_ChgTyp,	"muic-CHGTYP" },
 	{ MAX8997_MUICIRQ_OVP,		"muic-OVP" },
+	{ MAX8997_PMICIRQ_CHGINS,	"pmic-CHGINS" },
+	{ MAX8997_PMICIRQ_CHGRM,	"pmic-CHGRM" },
 };
 
 /* Define supported cable type */
@@ -538,6 +540,8 @@ static void max8997_muic_irq_work(struct work_struct *work)
 	case MAX8997_MUICIRQ_DCDTmr:
 	case MAX8997_MUICIRQ_ChgDetRun:
 	case MAX8997_MUICIRQ_ChgTyp:
+	case MAX8997_PMICIRQ_CHGINS:
+	case MAX8997_PMICIRQ_CHGRM:
 		/* Handle charger cable */
 		ret = max8997_muic_chg_handler(info);
 		break;
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
@ 2020-12-30 20:52 ` Timon Baetz
  2021-01-04 13:51   ` Mark Brown
  2021-01-11 21:50   ` Rob Herring
  2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
                   ` (8 subsequent siblings)
  9 siblings, 2 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

Add maxim,max8997-battery and maxim,max8997-muic optional nodes.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
Acked-by: Krzysztof Kozlowski <krzk@kernel.org>
---
v6: No change.
v5: No change.
v4: Make extcon and charger-supply optional.
v3: Reorder patch, no change.
v2: Add patch.

 .../bindings/regulator/max8997-regulator.txt         | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
index 6fe825b8ac1b..faaf2bbf0272 100644
--- a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
+++ b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
@@ -53,6 +53,18 @@ Additional properties required if either of the optional properties are used:
 - max8997,pmic-buck125-dvs-gpios: GPIO specifiers for three host gpio's used
   for dvs. The format of the gpio specifier depends in the gpio controller.
 
+Optional nodes:
+- charger: Node for configuring the charger driver.
+  Required properties:
+  - compatible: "maxim,max8997-battery"
+  Optional properties:
+  - extcon: extcon specifier for charging events
+  - charger-supply: regulator node for charging current
+
+- muic: Node used only by extcon consumers.
+  Required properties:
+  - compatible: "maxim,max8997-muic"
+
 Regulators: The regulators of max8997 that have to be instantiated should be
 included in a sub-node named 'regulators'. Regulator nodes included in this
 sub-node should be of the format as listed below.
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
@ 2020-12-30 20:52 ` Timon Baetz
  2020-12-30 23:22   ` kernel test robot
                     ` (2 more replies)
  2020-12-30 20:52 ` [PATCH v6 4/8] ARM: dts: exynos: Add muic and charger nodes for I9100 Timon Baetz
                   ` (7 subsequent siblings)
  9 siblings, 3 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

Register for extcon notification and set charging current depending on
the detected cable type. Current values are taken from vendor kernel,
where most charger types end up setting 650mA [0].

Also enable and disable the CHARGER regulator based on extcon events.

[0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/misc/max8997-muic.c#L1675-L1678

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: dev_info() instead of dev_err().
v5: Use devm_regulator_get_optional(), dev_err() on failure.
    dev_err() on extcon_get_edev_by_phandle() failure.
v4: Make extcon and charger-supply optional.
v3: Split MFD change.
    return on regulator_set_current_limit() failure.
v2: Split DTS changes.
    Add missing include.
    Rename charger_data members.
    Disable regulator on regulator_set_current_limit() failure.
    Fix ret declaration.
    Remove unneeded variables.
    Don't dev_err() on deferral.
    Get regulator and extcon from DTS.
    Use devm_regulator_get(). 
    Fix indentation.

 drivers/power/supply/max8997_charger.c | 96 ++++++++++++++++++++++++++
 1 file changed, 96 insertions(+)

diff --git a/drivers/power/supply/max8997_charger.c b/drivers/power/supply/max8997_charger.c
index 1947af25879a..23df91ed2c72 100644
--- a/drivers/power/supply/max8997_charger.c
+++ b/drivers/power/supply/max8997_charger.c
@@ -6,12 +6,14 @@
 //  MyungJoo Ham <myungjoo.ham@samsung.com>
 
 #include <linux/err.h>
+#include <linux/extcon.h>
 #include <linux/module.h>
 #include <linux/slab.h>
 #include <linux/platform_device.h>
 #include <linux/power_supply.h>
 #include <linux/mfd/max8997.h>
 #include <linux/mfd/max8997-private.h>
+#include <linux/regulator/consumer.h>
 
 /* MAX8997_REG_STATUS4 */
 #define DCINOK_SHIFT		1
@@ -31,6 +33,10 @@ struct charger_data {
 	struct device *dev;
 	struct max8997_dev *iodev;
 	struct power_supply *battery;
+	struct regulator *reg;
+	struct extcon_dev *edev;
+	struct notifier_block extcon_nb;
+	struct work_struct extcon_work;
 };
 
 static enum power_supply_property max8997_battery_props[] = {
@@ -88,6 +94,67 @@ static int max8997_battery_get_property(struct power_supply *psy,
 	return 0;
 }
 
+static void max8997_battery_extcon_evt_stop_work(void *data)
+{
+	struct charger_data *charger = data;
+
+	cancel_work_sync(&charger->extcon_work);
+}
+
+static void max8997_battery_extcon_evt_worker(struct work_struct *work)
+{
+	struct charger_data *charger =
+	    container_of(work, struct charger_data, extcon_work);
+	struct extcon_dev *edev = charger->edev;
+	int current_limit;
+
+	if (extcon_get_state(edev, EXTCON_CHG_USB_SDP) > 0) {
+		dev_dbg(charger->dev, "USB SDP charger is connected\n");
+		current_limit = 450000;
+	} else if (extcon_get_state(edev, EXTCON_CHG_USB_DCP) > 0) {
+		dev_dbg(charger->dev, "USB DCP charger is connected\n");
+		current_limit = 650000;
+	} else if (extcon_get_state(edev, EXTCON_CHG_USB_FAST) > 0) {
+		dev_dbg(charger->dev, "USB FAST charger is connected\n");
+		current_limit = 650000;
+	} else if (extcon_get_state(edev, EXTCON_CHG_USB_SLOW) > 0) {
+		dev_dbg(charger->dev, "USB SLOW charger is connected\n");
+		current_limit = 650000;
+	} else if (extcon_get_state(edev, EXTCON_CHG_USB_CDP) > 0) {
+		dev_dbg(charger->dev, "USB CDP charger is connected\n");
+		current_limit = 650000;
+	} else {
+		dev_dbg(charger->dev, "USB charger is diconnected\n");
+		current_limit = -1;
+	}
+
+	if (current_limit > 0) {
+		int ret = regulator_set_current_limit(charger->reg, current_limit, current_limit);
+
+		if (ret) {
+			dev_err(charger->dev, "failed to set current limit: %d\n", ret);
+			return;
+		}
+		ret = regulator_enable(charger->reg);
+		if (ret)
+			dev_err(charger->dev, "failed to enable regulator: %d\n", ret);
+	} else {
+		int ret  = regulator_disable(charger->reg);
+
+		if (ret)
+			dev_err(charger->dev, "failed to disable regulator: %d\n", ret);
+	}
+}
+
+static int max8997_battery_extcon_evt(struct notifier_block *nb,
+				unsigned long event, void *param)
+{
+	struct charger_data *charger =
+		container_of(nb, struct charger_data, extcon_nb);
+	schedule_work(&charger->extcon_work);
+	return NOTIFY_OK;
+}
+
 static const struct power_supply_desc max8997_battery_desc = {
 	.name		= "max8997_pmic",
 	.type		= POWER_SUPPLY_TYPE_BATTERY,
@@ -170,6 +237,35 @@ static int max8997_battery_probe(struct platform_device *pdev)
 		return PTR_ERR(charger->battery);
 	}
 
+	charger->reg = devm_regulator_get_optional(&pdev->dev, "charger");
+	if (IS_ERR(charger->reg)) {
+		if (PTR_ERR(charger->reg) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_info(&pdev->dev, "couldn't get charger regulator\n");
+	}
+	charger->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
+	if (IS_ERR(charger->edev)) {
+		if (PTR_ERR(charger->edev) == -EPROBE_DEFER)
+			return -EPROBE_DEFER;
+		dev_info(charger->dev, "couldn't get extcon device\n");
+	}
+
+	if (!IS_ERR(charger->reg) && !IS_ERR(charger->edev)) {
+		INIT_WORK(&charger->extcon_work, max8997_battery_extcon_evt_worker);
+		ret = devm_add_action(&pdev->dev, max8997_battery_extcon_evt_stop_work, charger);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to add extcon evt stop action: %d\n", ret);
+			return ret;
+		}
+		charger->extcon_nb.notifier_call = max8997_battery_extcon_evt;
+		ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
+							&charger->extcon_nb);
+		if (ret) {
+			dev_err(&pdev->dev, "failed to register extcon notifier\n");
+			return ret;
+		};
+	}
+
 	return 0;
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 4/8] ARM: dts: exynos: Add muic and charger nodes for I9100
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
@ 2020-12-30 20:52 ` Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 5/8] ARM: dts: exynos: Add muic and charger nodes for Origen Timon Baetz
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

muic node is only used for extcon consumers.
charger node is used to point to muic and regulator.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: No change.
v4: No change.
v3: Reorder patch, no change.
v2: Add patch.

 arch/arm/boot/dts/exynos4210-i9100.dts | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-i9100.dts b/arch/arm/boot/dts/exynos4210-i9100.dts
index 5370ee477186..8fa704babd5e 100644
--- a/arch/arm/boot/dts/exynos4210-i9100.dts
+++ b/arch/arm/boot/dts/exynos4210-i9100.dts
@@ -584,6 +584,16 @@ EN32KHZ_CP {
 				regulator-always-on;
 			};
 		};
+
+		muic: max8997-muic {
+			compatible = "maxim,max8997-muic";
+		};
+
+		charger {
+			compatible = "maxim,max8997-battery";
+			charger-supply = <&charger_reg>;
+			extcon = <&muic>;
+		};
 	};
 };
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 5/8] ARM: dts: exynos: Add muic and charger nodes for Origen
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (2 preceding siblings ...)
  2020-12-30 20:52 ` [PATCH v6 4/8] ARM: dts: exynos: Add muic and charger nodes for I9100 Timon Baetz
@ 2020-12-30 20:52 ` Timon Baetz
  2020-12-30 20:52 ` [PATCH v6 6/8] ARM: dts: exynos: Add muic and charger nodes for Trats Timon Baetz
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

Both nodes are disabled as there is no battery and pins are not
connected.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: Add patch.

 arch/arm/boot/dts/exynos4210-origen.dts | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-origen.dts b/arch/arm/boot/dts/exynos4210-origen.dts
index 7d2cfbafefb2..9792531ac3da 100644
--- a/arch/arm/boot/dts/exynos4210-origen.dts
+++ b/arch/arm/boot/dts/exynos4210-origen.dts
@@ -312,6 +312,16 @@ EN32KHZ_AP {
 				regulator-always-on;
 			};
 		};
+
+		muic {
+			compatible = "maxim,max8997-muic";
+			status = "disabled";
+		};
+
+		charger {
+			compatible = "maxim,max8997-battery";
+			status = "disabled";
+		};
 	};
 };
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 6/8] ARM: dts: exynos: Add muic and charger nodes for Trats
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (3 preceding siblings ...)
  2020-12-30 20:52 ` [PATCH v6 5/8] ARM: dts: exynos: Add muic and charger nodes for Origen Timon Baetz
@ 2020-12-30 20:52 ` Timon Baetz
  2020-12-30 20:53 ` [PATCH v6 7/8] ARM: dts: exynos: Fix charging regulator voltage and current for I9100 Timon Baetz
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:52 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

muic node is only used for extcon consumers.
charger node is used to point to muic.

Note: charging control is not working as we don't have a charger-supply.

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: Add patch.

 arch/arm/boot/dts/exynos4210-trats.dts | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/arm/boot/dts/exynos4210-trats.dts b/arch/arm/boot/dts/exynos4210-trats.dts
index a226bec56a45..686465f0044b 100644
--- a/arch/arm/boot/dts/exynos4210-trats.dts
+++ b/arch/arm/boot/dts/exynos4210-trats.dts
@@ -459,6 +459,15 @@ EN32KHZ_CP {
 				regulator-always-on;
 			};
 		};
+
+		muic: max8997-muic {
+			compatible = "maxim,max8997-muic";
+		};
+
+		charger {
+			compatible = "maxim,max8997-battery";
+			extcon = <&muic>;
+		};
 	};
 };
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 7/8] ARM: dts: exynos: Fix charging regulator voltage and current for I9100
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (4 preceding siblings ...)
  2020-12-30 20:52 ` [PATCH v6 6/8] ARM: dts: exynos: Add muic and charger nodes for Trats Timon Baetz
@ 2020-12-30 20:53 ` Timon Baetz
  2020-12-30 20:53 ` [PATCH v6 8/8] ARM: dts: exynos: Add top-off charging regulator node " Timon Baetz
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:53 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

Set CHARGER current and CHARGER_CV voltage according to Galaxy S2 Epic
4G Touch SPH-D710 Android vendor sources [0,1].

Remove regulator-always-on. The regulator can be enabled and disabled
based on extcon events.

[0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/power/max8997_charger_u1.c#L169-L170
[1] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/power/max8997_charger_u1.c#L390-L391

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: No change.
v4: No change.
v3: Reorder patch.
    Remove regulator-always-on.
v2: Fix commit message, add references.

 arch/arm/boot/dts/exynos4210-i9100.dts | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/arch/arm/boot/dts/exynos4210-i9100.dts b/arch/arm/boot/dts/exynos4210-i9100.dts
index 8fa704babd5e..586d801af0b5 100644
--- a/arch/arm/boot/dts/exynos4210-i9100.dts
+++ b/arch/arm/boot/dts/exynos4210-i9100.dts
@@ -562,15 +562,14 @@ safe2_sreg: ESAFEOUT2 {
 
 			charger_reg: CHARGER {
 				regulator-name = "CHARGER";
-				regulator-min-microamp = <60000>;
-				regulator-max-microamp = <2580000>;
-				regulator-always-on;
+				regulator-min-microamp = <200000>;
+				regulator-max-microamp = <950000>;
 			};
 
 			chargercv_reg: CHARGER_CV {
 				regulator-name = "CHARGER_CV";
-				regulator-min-microvolt = <3800000>;
-				regulator-max-microvolt = <4100000>;
+				regulator-min-microvolt = <4200000>;
+				regulator-max-microvolt = <4200000>;
 				regulator-always-on;
 			};
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* [PATCH v6 8/8] ARM: dts: exynos: Add top-off charging regulator node for I9100
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (5 preceding siblings ...)
  2020-12-30 20:53 ` [PATCH v6 7/8] ARM: dts: exynos: Fix charging regulator voltage and current for I9100 Timon Baetz
@ 2020-12-30 20:53 ` Timon Baetz
  2021-01-03 16:32 ` (subset) [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Krzysztof Kozlowski
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 30+ messages in thread
From: Timon Baetz @ 2020-12-30 20:53 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming, Timon Baetz

Value taken from Galaxy S2 Epic 4G Touch SPH-D710 Android vendor
kernel [0] which always sets 200mA.

Also rearrange regulators based on definition in max8997.h.

[0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/power/sec_battery_u1.c#L1525

Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
---
v6: No change.
v5: No change.
v4: No change.
v3: Remove label. 
    Fix commit message.
v2: Add patch.

 arch/arm/boot/dts/exynos4210-i9100.dts | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/arch/arm/boot/dts/exynos4210-i9100.dts b/arch/arm/boot/dts/exynos4210-i9100.dts
index 586d801af0b5..e702adb69670 100644
--- a/arch/arm/boot/dts/exynos4210-i9100.dts
+++ b/arch/arm/boot/dts/exynos4210-i9100.dts
@@ -560,6 +560,16 @@ safe2_sreg: ESAFEOUT2 {
 				regulator-boot-on;
 			};
 
+			EN32KHZ_AP {
+				regulator-name = "EN32KHZ_AP";
+				regulator-always-on;
+			};
+
+			EN32KHZ_CP {
+				regulator-name = "EN32KHZ_CP";
+				regulator-always-on;
+			};
+
 			charger_reg: CHARGER {
 				regulator-name = "CHARGER";
 				regulator-min-microamp = <200000>;
@@ -573,13 +583,10 @@ chargercv_reg: CHARGER_CV {
 				regulator-always-on;
 			};
 
-			EN32KHZ_AP {
-				regulator-name = "EN32KHZ_AP";
-				regulator-always-on;
-			};
-
-			EN32KHZ_CP {
-				regulator-name = "EN32KHZ_CP";
+			CHARGER_TOPOFF {
+				regulator-name = "CHARGER_TOPOFF";
+				regulator-min-microamp = <200000>;
+				regulator-max-microamp = <200000>;
 				regulator-always-on;
 			};
 		};
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
@ 2020-12-30 23:22   ` kernel test robot
  2020-12-31  7:19     ` Timon Baetz
  2020-12-31  8:55   ` Krzysztof Kozlowski
  2021-01-03  1:53   ` Sebastian Reichel
  2 siblings, 1 reply; 30+ messages in thread
From: kernel test robot @ 2020-12-30 23:22 UTC (permalink / raw)
  To: Timon Baetz, Krzysztof Kozlowski
  Cc: kbuild-all, clang-built-linux, Marek Szyprowski, Liam Girdwood,
	Mark Brown, Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 6116 bytes --]

Hi Timon,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on regulator/for-next]
[also build test ERROR on pinctrl-samsung/for-next krzk/for-next v5.11-rc1 next-20201223]
[cannot apply to robh/for-next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
config: arm-randconfig-r004-20201230 (attached as .config)
compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 3c0d36f977d9e012b245c796ddc8596ac3af659b)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # https://github.com/0day-ci/linux/commit/3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
        git remote add linux-review https://github.com/0day-ci/linux
        git fetch --no-tags linux-review Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
        git checkout 3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/power/supply/max8997_charger.c:261:9: error: implicit declaration of function 'devm_extcon_register_notifier_all' [-Werror,-Wimplicit-function-declaration]
                   ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
                         ^
   drivers/power/supply/max8997_charger.c:261:9: note: did you mean 'devm_extcon_register_notifier'?
   include/linux/extcon.h:263:19: note: 'devm_extcon_register_notifier' declared here
   static inline int devm_extcon_register_notifier(struct device *dev,
                     ^
   1 error generated.


vim +/devm_extcon_register_notifier_all +261 drivers/power/supply/max8997_charger.c

   165	
   166	static int max8997_battery_probe(struct platform_device *pdev)
   167	{
   168		int ret = 0;
   169		struct charger_data *charger;
   170		struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
   171		struct i2c_client *i2c = iodev->i2c;
   172		struct max8997_platform_data *pdata = iodev->pdata;
   173		struct power_supply_config psy_cfg = {};
   174	
   175		if (!pdata) {
   176			dev_err(&pdev->dev, "No platform data supplied.\n");
   177			return -EINVAL;
   178		}
   179	
   180		if (pdata->eoc_mA) {
   181			int val = (pdata->eoc_mA - 50) / 10;
   182			if (val < 0)
   183				val = 0;
   184			if (val > 0xf)
   185				val = 0xf;
   186	
   187			ret = max8997_update_reg(i2c, MAX8997_REG_MBCCTRL5,
   188					val << ITOPOFF_SHIFT, ITOPOFF_MASK);
   189			if (ret < 0) {
   190				dev_err(&pdev->dev, "Cannot use i2c bus.\n");
   191				return ret;
   192			}
   193		}
   194		switch (pdata->timeout) {
   195		case 5:
   196			ret = max8997_update_reg(i2c, MAX8997_REG_MBCCTRL1,
   197					0x2 << TFCH_SHIFT, TFCH_MASK);
   198			break;
   199		case 6:
   200			ret = max8997_update_reg(i2c, MAX8997_REG_MBCCTRL1,
   201					0x3 << TFCH_SHIFT, TFCH_MASK);
   202			break;
   203		case 7:
   204			ret = max8997_update_reg(i2c, MAX8997_REG_MBCCTRL1,
   205					0x4 << TFCH_SHIFT, TFCH_MASK);
   206			break;
   207		case 0:
   208			ret = max8997_update_reg(i2c, MAX8997_REG_MBCCTRL1,
   209					0x7 << TFCH_SHIFT, TFCH_MASK);
   210			break;
   211		default:
   212			dev_err(&pdev->dev, "incorrect timeout value (%d)\n",
   213					pdata->timeout);
   214			return -EINVAL;
   215		}
   216		if (ret < 0) {
   217			dev_err(&pdev->dev, "Cannot use i2c bus.\n");
   218			return ret;
   219		}
   220	
   221		charger = devm_kzalloc(&pdev->dev, sizeof(*charger), GFP_KERNEL);
   222		if (!charger)
   223			return -ENOMEM;
   224	
   225		platform_set_drvdata(pdev, charger);
   226	
   227		charger->dev = &pdev->dev;
   228		charger->iodev = iodev;
   229	
   230		psy_cfg.drv_data = charger;
   231	
   232		charger->battery = devm_power_supply_register(&pdev->dev,
   233							 &max8997_battery_desc,
   234							 &psy_cfg);
   235		if (IS_ERR(charger->battery)) {
   236			dev_err(&pdev->dev, "failed: power supply register\n");
   237			return PTR_ERR(charger->battery);
   238		}
   239	
   240		charger->reg = devm_regulator_get_optional(&pdev->dev, "charger");
   241		if (IS_ERR(charger->reg)) {
   242			if (PTR_ERR(charger->reg) == -EPROBE_DEFER)
   243				return -EPROBE_DEFER;
   244			dev_info(&pdev->dev, "couldn't get charger regulator\n");
   245		}
   246		charger->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
   247		if (IS_ERR(charger->edev)) {
   248			if (PTR_ERR(charger->edev) == -EPROBE_DEFER)
   249				return -EPROBE_DEFER;
   250			dev_info(charger->dev, "couldn't get extcon device\n");
   251		}
   252	
   253		if (!IS_ERR(charger->reg) && !IS_ERR(charger->edev)) {
   254			INIT_WORK(&charger->extcon_work, max8997_battery_extcon_evt_worker);
   255			ret = devm_add_action(&pdev->dev, max8997_battery_extcon_evt_stop_work, charger);
   256			if (ret) {
   257				dev_err(&pdev->dev, "failed to add extcon evt stop action: %d\n", ret);
   258				return ret;
   259			}
   260			charger->extcon_nb.notifier_call = max8997_battery_extcon_evt;
 > 261			ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
   262								&charger->extcon_nb);
   263			if (ret) {
   264				dev_err(&pdev->dev, "failed to register extcon notifier\n");
   265				return ret;
   266			};
   267		}
   268	
   269		return 0;
   270	}
   271	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org

[-- Attachment #2: .config.gz --]
[-- Type: application/gzip, Size: 20871 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-30 23:22   ` kernel test robot
@ 2020-12-31  7:19     ` Timon Baetz
  2020-12-31  8:23       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 30+ messages in thread
From: Timon Baetz @ 2020-12-31  7:19 UTC (permalink / raw)
  To: kernel test robot
  Cc: Krzysztof Kozlowski, kbuild-all, clang-built-linux,
	Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel

On Thu, 31 Dec 2020 07:22:22 +0800, kernel test robot wrote:
> Hi Timon,
> 
> Thank you for the patch! Yet something to improve:
> 
> [auto build test ERROR on regulator/for-next]
> [also build test ERROR on pinctrl-samsung/for-next krzk/for-next v5.11-rc1 next-20201223]
> [cannot apply to robh/for-next]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use '--base' as documented in
> https://git-scm.com/docs/git-format-patch]
> 
> url:    https://github.com/0day-ci/linux/commits/Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
> config: arm-randconfig-r004-20201230 (attached as .config)
> compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 3c0d36f977d9e012b245c796ddc8596ac3af659b)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install arm cross compiling tool for clang build
>         # apt-get install binutils-arm-linux-gnueabi
>         # https://github.com/0day-ci/linux/commit/3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
>         git remote add linux-review https://github.com/0day-ci/linux
>         git fetch --no-tags linux-review Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
>         git checkout 3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
> 
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
> 
> All errors (new ones prefixed by >>):
> 
> >> drivers/power/supply/max8997_charger.c:261:9: error: implicit declaration of function 'devm_extcon_register_notifier_all' [-Werror,-Wimplicit-function-declaration]  
>                    ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
>                          ^
>    drivers/power/supply/max8997_charger.c:261:9: note: did you mean 'devm_extcon_register_notifier'?
>    include/linux/extcon.h:263:19: note: 'devm_extcon_register_notifier' declared here
>    static inline int devm_extcon_register_notifier(struct device *dev,
>                      ^
>    1 error generated.

This is failing because CONFIG_EXTCON is not set and *_all() don't have
stub implementations in extcon.h. Should I add a fix for it in this
series?


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-31  7:19     ` Timon Baetz
@ 2020-12-31  8:23       ` Krzysztof Kozlowski
  0 siblings, 0 replies; 30+ messages in thread
From: Krzysztof Kozlowski @ 2020-12-31  8:23 UTC (permalink / raw)
  To: Timon Baetz
  Cc: kernel test robot, kbuild-all, clang-built-linux,
	Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel

On Thu, Dec 31, 2020 at 07:19:07AM +0000, Timon Baetz wrote:
> On Thu, 31 Dec 2020 07:22:22 +0800, kernel test robot wrote:
> > Hi Timon,
> > 
> > Thank you for the patch! Yet something to improve:
> > 
> > [auto build test ERROR on regulator/for-next]
> > [also build test ERROR on pinctrl-samsung/for-next krzk/for-next v5.11-rc1 next-20201223]
> > [cannot apply to robh/for-next]
> > [If your patch is applied to the wrong git tree, kindly drop us a note.
> > And when submitting patch, we suggest to use '--base' as documented in
> > https://git-scm.com/docs/git-format-patch]
> > 
> > url:    https://github.com/0day-ci/linux/commits/Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
> > base:   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator.git for-next
> > config: arm-randconfig-r004-20201230 (attached as .config)
> > compiler: clang version 12.0.0 (https://github.com/llvm/llvm-project 3c0d36f977d9e012b245c796ddc8596ac3af659b)
> > reproduce (this is a W=1 build):
> >         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
> >         chmod +x ~/bin/make.cross
> >         # install arm cross compiling tool for clang build
> >         # apt-get install binutils-arm-linux-gnueabi
> >         # https://github.com/0day-ci/linux/commit/3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
> >         git remote add linux-review https://github.com/0day-ci/linux
> >         git fetch --no-tags linux-review Timon-Baetz/extcon-max8997-Add-CHGINS-and-CHGRM-interrupt-handling/20201231-045812
> >         git checkout 3a597219bbfc1f9a0b65b9662b7b95bbb7cf728f
> >         # save the attached .config to linux build tree
> >         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
> > 
> > If you fix the issue, kindly add following tag as appropriate
> > Reported-by: kernel test robot <lkp@intel.com>
> > 
> > All errors (new ones prefixed by >>):
> > 
> > >> drivers/power/supply/max8997_charger.c:261:9: error: implicit declaration of function 'devm_extcon_register_notifier_all' [-Werror,-Wimplicit-function-declaration]  
> >                    ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
> >                          ^
> >    drivers/power/supply/max8997_charger.c:261:9: note: did you mean 'devm_extcon_register_notifier'?
> >    include/linux/extcon.h:263:19: note: 'devm_extcon_register_notifier' declared here
> >    static inline int devm_extcon_register_notifier(struct device *dev,
> >                      ^
> >    1 error generated.
> 
> This is failing because CONFIG_EXTCON is not set and *_all() don't have
> stub implementations in extcon.h. Should I add a fix for it in this
> series?

It is not problem of your patchset, so up to you.  After your changes
the driver still can work fine without CONFIG_EXTCON and CONFIG_REGULATOR.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
  2020-12-30 23:22   ` kernel test robot
@ 2020-12-31  8:55   ` Krzysztof Kozlowski
  2021-01-03  1:53   ` Sebastian Reichel
  2 siblings, 0 replies; 30+ messages in thread
From: Krzysztof Kozlowski @ 2020-12-31  8:55 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Marek Szyprowski, Liam Girdwood, Mark Brown, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

On Wed, Dec 30, 2020 at 08:52:15PM +0000, Timon Baetz wrote:
> Register for extcon notification and set charging current depending on
> the detected cable type. Current values are taken from vendor kernel,
> where most charger types end up setting 650mA [0].
> 
> Also enable and disable the CHARGER regulator based on extcon events.
> 
> [0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/misc/max8997-muic.c#L1675-L1678
> 
> Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
> ---
> v6: dev_info() instead of dev_err().
> v5: Use devm_regulator_get_optional(), dev_err() on failure.
>     dev_err() on extcon_get_edev_by_phandle() failure.
> v4: Make extcon and charger-supply optional.
> v3: Split MFD change.
>     return on regulator_set_current_limit() failure.
> v2: Split DTS changes.
>     Add missing include.
>     Rename charger_data members.
>     Disable regulator on regulator_set_current_limit() failure.
>     Fix ret declaration.
>     Remove unneeded variables.
>     Don't dev_err() on deferral.
>     Get regulator and extcon from DTS.
>     Use devm_regulator_get(). 
>     Fix indentation.



Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org>

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit
  2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
  2020-12-30 23:22   ` kernel test robot
  2020-12-31  8:55   ` Krzysztof Kozlowski
@ 2021-01-03  1:53   ` Sebastian Reichel
  2 siblings, 0 replies; 30+ messages in thread
From: Sebastian Reichel @ 2021-01-03  1:53 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood, Mark Brown,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones, linux-kernel,
	devicetree, linux-arm-kernel, linux-samsung-soc, linux-pm,
	~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 6197 bytes --]

Hi,

On Wed, Dec 30, 2020 at 08:52:15PM +0000, Timon Baetz wrote:
> Register for extcon notification and set charging current depending on
> the detected cable type. Current values are taken from vendor kernel,
> where most charger types end up setting 650mA [0].
> 
> Also enable and disable the CHARGER regulator based on extcon events.
> 
> [0] https://github.com/krzk/linux-vendor-backup/blob/samsung/galaxy-s2-epic-4g-touch-sph-d710-exynos4210-dump/drivers/misc/max8997-muic.c#L1675-L1678
> 
> Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
> ---

Thanks, queued to power-supply's for-next branch.

-- Sebastian

> v6: dev_info() instead of dev_err().
> v5: Use devm_regulator_get_optional(), dev_err() on failure.
>     dev_err() on extcon_get_edev_by_phandle() failure.
> v4: Make extcon and charger-supply optional.
> v3: Split MFD change.
>     return on regulator_set_current_limit() failure.
> v2: Split DTS changes.
>     Add missing include.
>     Rename charger_data members.
>     Disable regulator on regulator_set_current_limit() failure.
>     Fix ret declaration.
>     Remove unneeded variables.
>     Don't dev_err() on deferral.
>     Get regulator and extcon from DTS.
>     Use devm_regulator_get(). 
>     Fix indentation.
> 
>  drivers/power/supply/max8997_charger.c | 96 ++++++++++++++++++++++++++
>  1 file changed, 96 insertions(+)
> 
> diff --git a/drivers/power/supply/max8997_charger.c b/drivers/power/supply/max8997_charger.c
> index 1947af25879a..23df91ed2c72 100644
> --- a/drivers/power/supply/max8997_charger.c
> +++ b/drivers/power/supply/max8997_charger.c
> @@ -6,12 +6,14 @@
>  //  MyungJoo Ham <myungjoo.ham@samsung.com>
>  
>  #include <linux/err.h>
> +#include <linux/extcon.h>
>  #include <linux/module.h>
>  #include <linux/slab.h>
>  #include <linux/platform_device.h>
>  #include <linux/power_supply.h>
>  #include <linux/mfd/max8997.h>
>  #include <linux/mfd/max8997-private.h>
> +#include <linux/regulator/consumer.h>
>  
>  /* MAX8997_REG_STATUS4 */
>  #define DCINOK_SHIFT		1
> @@ -31,6 +33,10 @@ struct charger_data {
>  	struct device *dev;
>  	struct max8997_dev *iodev;
>  	struct power_supply *battery;
> +	struct regulator *reg;
> +	struct extcon_dev *edev;
> +	struct notifier_block extcon_nb;
> +	struct work_struct extcon_work;
>  };
>  
>  static enum power_supply_property max8997_battery_props[] = {
> @@ -88,6 +94,67 @@ static int max8997_battery_get_property(struct power_supply *psy,
>  	return 0;
>  }
>  
> +static void max8997_battery_extcon_evt_stop_work(void *data)
> +{
> +	struct charger_data *charger = data;
> +
> +	cancel_work_sync(&charger->extcon_work);
> +}
> +
> +static void max8997_battery_extcon_evt_worker(struct work_struct *work)
> +{
> +	struct charger_data *charger =
> +	    container_of(work, struct charger_data, extcon_work);
> +	struct extcon_dev *edev = charger->edev;
> +	int current_limit;
> +
> +	if (extcon_get_state(edev, EXTCON_CHG_USB_SDP) > 0) {
> +		dev_dbg(charger->dev, "USB SDP charger is connected\n");
> +		current_limit = 450000;
> +	} else if (extcon_get_state(edev, EXTCON_CHG_USB_DCP) > 0) {
> +		dev_dbg(charger->dev, "USB DCP charger is connected\n");
> +		current_limit = 650000;
> +	} else if (extcon_get_state(edev, EXTCON_CHG_USB_FAST) > 0) {
> +		dev_dbg(charger->dev, "USB FAST charger is connected\n");
> +		current_limit = 650000;
> +	} else if (extcon_get_state(edev, EXTCON_CHG_USB_SLOW) > 0) {
> +		dev_dbg(charger->dev, "USB SLOW charger is connected\n");
> +		current_limit = 650000;
> +	} else if (extcon_get_state(edev, EXTCON_CHG_USB_CDP) > 0) {
> +		dev_dbg(charger->dev, "USB CDP charger is connected\n");
> +		current_limit = 650000;
> +	} else {
> +		dev_dbg(charger->dev, "USB charger is diconnected\n");
> +		current_limit = -1;
> +	}
> +
> +	if (current_limit > 0) {
> +		int ret = regulator_set_current_limit(charger->reg, current_limit, current_limit);
> +
> +		if (ret) {
> +			dev_err(charger->dev, "failed to set current limit: %d\n", ret);
> +			return;
> +		}
> +		ret = regulator_enable(charger->reg);
> +		if (ret)
> +			dev_err(charger->dev, "failed to enable regulator: %d\n", ret);
> +	} else {
> +		int ret  = regulator_disable(charger->reg);
> +
> +		if (ret)
> +			dev_err(charger->dev, "failed to disable regulator: %d\n", ret);
> +	}
> +}
> +
> +static int max8997_battery_extcon_evt(struct notifier_block *nb,
> +				unsigned long event, void *param)
> +{
> +	struct charger_data *charger =
> +		container_of(nb, struct charger_data, extcon_nb);
> +	schedule_work(&charger->extcon_work);
> +	return NOTIFY_OK;
> +}
> +
>  static const struct power_supply_desc max8997_battery_desc = {
>  	.name		= "max8997_pmic",
>  	.type		= POWER_SUPPLY_TYPE_BATTERY,
> @@ -170,6 +237,35 @@ static int max8997_battery_probe(struct platform_device *pdev)
>  		return PTR_ERR(charger->battery);
>  	}
>  
> +	charger->reg = devm_regulator_get_optional(&pdev->dev, "charger");
> +	if (IS_ERR(charger->reg)) {
> +		if (PTR_ERR(charger->reg) == -EPROBE_DEFER)
> +			return -EPROBE_DEFER;
> +		dev_info(&pdev->dev, "couldn't get charger regulator\n");
> +	}
> +	charger->edev = extcon_get_edev_by_phandle(&pdev->dev, 0);
> +	if (IS_ERR(charger->edev)) {
> +		if (PTR_ERR(charger->edev) == -EPROBE_DEFER)
> +			return -EPROBE_DEFER;
> +		dev_info(charger->dev, "couldn't get extcon device\n");
> +	}
> +
> +	if (!IS_ERR(charger->reg) && !IS_ERR(charger->edev)) {
> +		INIT_WORK(&charger->extcon_work, max8997_battery_extcon_evt_worker);
> +		ret = devm_add_action(&pdev->dev, max8997_battery_extcon_evt_stop_work, charger);
> +		if (ret) {
> +			dev_err(&pdev->dev, "failed to add extcon evt stop action: %d\n", ret);
> +			return ret;
> +		}
> +		charger->extcon_nb.notifier_call = max8997_battery_extcon_evt;
> +		ret = devm_extcon_register_notifier_all(&pdev->dev, charger->edev,
> +							&charger->extcon_nb);
> +		if (ret) {
> +			dev_err(&pdev->dev, "failed to register extcon notifier\n");
> +			return ret;
> +		};
> +	}
> +
>  	return 0;
>  }
>  
> -- 
> 2.25.1
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: (subset) [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (6 preceding siblings ...)
  2020-12-30 20:53 ` [PATCH v6 8/8] ARM: dts: exynos: Add top-off charging regulator node " Timon Baetz
@ 2021-01-03 16:32 ` Krzysztof Kozlowski
  2021-01-03 16:34 ` Krzysztof Kozlowski
  2021-01-04 10:26 ` Chanwoo Choi
  9 siblings, 0 replies; 30+ messages in thread
From: Krzysztof Kozlowski @ 2021-01-03 16:32 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, linux-samsung-soc, devicetree, linux-kernel,
	linux-arm-kernel, Chanwoo Choi, Liam Girdwood, Sebastian Reichel,
	Mark Brown, ~postmarketos/upstreaming, linux-pm,
	Marek Szyprowski, Lee Jones, MyungJoo Ham, Rob Herring

On Wed, 30 Dec 2020 20:51:53 +0000, Timon Baetz wrote:
> This allows the MAX8997 charger to set the current limit depending on
> the detected extcon charger type.

Applied, thanks!

[7/8] ARM: dts: exynos: Fix charging regulator voltage and current for I9100
      commit: 4a928b3b7c0f8a2ae382c3db3a78898877567786

Best regards,
-- 
Krzysztof Kozlowski <krzk@kernel.org>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: (subset) [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (7 preceding siblings ...)
  2021-01-03 16:32 ` (subset) [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Krzysztof Kozlowski
@ 2021-01-03 16:34 ` Krzysztof Kozlowski
  2021-01-04 10:26 ` Chanwoo Choi
  9 siblings, 0 replies; 30+ messages in thread
From: Krzysztof Kozlowski @ 2021-01-03 16:34 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Rob Herring, Liam Girdwood, linux-kernel,
	Lee Jones, devicetree, Mark Brown, MyungJoo Ham,
	linux-arm-kernel, linux-pm, Sebastian Reichel,
	~postmarketos/upstreaming, Chanwoo Choi, linux-samsung-soc,
	Marek Szyprowski

On Wed, 30 Dec 2020 20:51:53 +0000, Timon Baetz wrote:
> This allows the MAX8997 charger to set the current limit depending on
> the detected extcon charger type.

Applied, thanks!

[8/8] ARM: dts: exynos: Add top-off charging regulator node for I9100
      commit: 3803f461bd28c1c817281348509399778633e82f

Best regards,
-- 
Krzysztof Kozlowski <krzk@kernel.org>

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling
  2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
                   ` (8 preceding siblings ...)
  2021-01-03 16:34 ` Krzysztof Kozlowski
@ 2021-01-04 10:26 ` Chanwoo Choi
  9 siblings, 0 replies; 30+ messages in thread
From: Chanwoo Choi @ 2021-01-04 10:26 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood, Mark Brown,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, Linux PM list, ~postmarketos/upstreaming

On Thu, Dec 31, 2020 at 5:54 AM Timon Baetz <timon.baetz@protonmail.com> wrote:
>
> This allows the MAX8997 charger to set the current limit depending on
> the detected extcon charger type.
>
> Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
> ---
> v6: No change.
> v5: No change.
> v4: No change.
> v3: No change.
> v2: Remove empty line.
>
>  drivers/extcon/extcon-max8997.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
> index 337b0eea4e62..e1408075ef7d 100644
> --- a/drivers/extcon/extcon-max8997.c
> +++ b/drivers/extcon/extcon-max8997.c
> @@ -44,6 +44,8 @@ static struct max8997_muic_irq muic_irqs[] = {
>         { MAX8997_MUICIRQ_ChgDetRun,    "muic-CHGDETRUN" },
>         { MAX8997_MUICIRQ_ChgTyp,       "muic-CHGTYP" },
>         { MAX8997_MUICIRQ_OVP,          "muic-OVP" },
> +       { MAX8997_PMICIRQ_CHGINS,       "pmic-CHGINS" },
> +       { MAX8997_PMICIRQ_CHGRM,        "pmic-CHGRM" },
>  };
>
>  /* Define supported cable type */
> @@ -538,6 +540,8 @@ static void max8997_muic_irq_work(struct work_struct *work)
>         case MAX8997_MUICIRQ_DCDTmr:
>         case MAX8997_MUICIRQ_ChgDetRun:
>         case MAX8997_MUICIRQ_ChgTyp:
> +       case MAX8997_PMICIRQ_CHGINS:
> +       case MAX8997_PMICIRQ_CHGRM:
>                 /* Handle charger cable */
>                 ret = max8997_muic_chg_handler(info);
>                 break;
> --
> 2.25.1
>
>

Applied it. Thans.


-- 
Best Regards,
Chanwoo Choi

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
@ 2021-01-04 13:51   ` Mark Brown
  2021-01-04 18:18     ` Krzysztof Kozlowski
  2021-01-11 21:50   ` Rob Herring
  1 sibling, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-04 13:51 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 561 bytes --]

On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:

> +- charger: Node for configuring the charger driver.
> +  Required properties:
> +  - compatible: "maxim,max8997-battery"
> +  Optional properties:
> +  - extcon: extcon specifier for charging events
> +  - charger-supply: regulator node for charging current
> +
> +- muic: Node used only by extcon consumers.
> +  Required properties:
> +  - compatible: "maxim,max8997-muic"

Why do these need to appear in the DT binding?  We know these features
are there simply from knowing this is a max8997.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-04 13:51   ` Mark Brown
@ 2021-01-04 18:18     ` Krzysztof Kozlowski
  2021-01-04 18:27       ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Krzysztof Kozlowski @ 2021-01-04 18:18 UTC (permalink / raw)
  To: Mark Brown
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:
> On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:
> 
> > +- charger: Node for configuring the charger driver.
> > +  Required properties:
> > +  - compatible: "maxim,max8997-battery"
> > +  Optional properties:
> > +  - extcon: extcon specifier for charging events
> > +  - charger-supply: regulator node for charging current
> > +
> > +- muic: Node used only by extcon consumers.
> > +  Required properties:
> > +  - compatible: "maxim,max8997-muic"
> 
> Why do these need to appear in the DT binding?  We know these features
> are there simply from knowing this is a max8997.

If you refer to children nodes, then we do not know these entirely
because the features could be disabled (pins not connected).  In such
case these subnodes can be disabled and MFD framework will not
instantiate children devices.

If you mean "the properties" like extcon or charger, then indeed it's a
good question. In theory, wires still could be routed differently, e.g.
different charging regulator used as a charger.
In practice this is highly unlikely, however such DT design allows
easier hooking up of different devices and even potential re-usage of
kernel drivers (also unlikely...).

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-04 18:18     ` Krzysztof Kozlowski
@ 2021-01-04 18:27       ` Mark Brown
  2021-01-04 18:38         ` Krzysztof Kozlowski
  0 siblings, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-04 18:27 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 1182 bytes --]

On Mon, Jan 04, 2021 at 07:18:25PM +0100, Krzysztof Kozlowski wrote:
> On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:

> > > +- charger: Node for configuring the charger driver.
> > > +  Required properties:
> > > +  - compatible: "maxim,max8997-battery"

> > > +  Optional properties:
> > > +  - extcon: extcon specifier for charging events
> > > +  - charger-supply: regulator node for charging current

> > > +- muic: Node used only by extcon consumers.
> > > +  Required properties:
> > > +  - compatible: "maxim,max8997-muic"

> > Why do these need to appear in the DT binding?  We know these features
> > are there simply from knowing this is a max8997.

> If you refer to children nodes, then we do not know these entirely
> because the features could be disabled (pins not connected).  In such
> case these subnodes can be disabled and MFD framework will not
> instantiate children devices.

We can indicate the presence of features without adding new compatible
strings, that's just encoding the way Linux currently divides things up
into the bindings.  For example having an extcon property seems like it
should be enough to figure out if we're using extcon.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-04 18:27       ` Mark Brown
@ 2021-01-04 18:38         ` Krzysztof Kozlowski
  2021-01-04 21:24           ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Krzysztof Kozlowski @ 2021-01-04 18:38 UTC (permalink / raw)
  To: Mark Brown
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:
> On Mon, Jan 04, 2021 at 07:18:25PM +0100, Krzysztof Kozlowski wrote:
> > On Mon, Jan 04, 2021 at 01:51:56PM +0000, Mark Brown wrote:
> 
> > > > +- charger: Node for configuring the charger driver.
> > > > +  Required properties:
> > > > +  - compatible: "maxim,max8997-battery"
> 
> > > > +  Optional properties:
> > > > +  - extcon: extcon specifier for charging events
> > > > +  - charger-supply: regulator node for charging current
> 
> > > > +- muic: Node used only by extcon consumers.
> > > > +  Required properties:
> > > > +  - compatible: "maxim,max8997-muic"
> 
> > > Why do these need to appear in the DT binding?  We know these features
> > > are there simply from knowing this is a max8997.
> 
> > If you refer to children nodes, then we do not know these entirely
> > because the features could be disabled (pins not connected).  In such
> > case these subnodes can be disabled and MFD framework will not
> > instantiate children devices.
> 
> We can indicate the presence of features without adding new compatible
> strings, that's just encoding the way Linux currently divides things up
> into the bindings.  For example having an extcon property seems like it
> should be enough to figure out if we're using extcon.

It won't be enough because MFD will create device for extcon and bind
the driver. The same for the charger. We have a board where max8997 is
used only as PMIC (providing regulators) without battery and USB
connectivity.

Another point, is that this reflects the real hardware. The same as we
model entire SoC as multiple children of soc node (with their own
properties), here we represent smaller chip which also has
sub-components.

Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-04 18:38         ` Krzysztof Kozlowski
@ 2021-01-04 21:24           ` Mark Brown
  2021-01-05 16:55             ` Krzysztof Kozlowski
  0 siblings, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-04 21:24 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 1174 bytes --]

On Mon, Jan 04, 2021 at 07:38:21PM +0100, Krzysztof Kozlowski wrote:
> On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:

> > We can indicate the presence of features without adding new compatible
> > strings, that's just encoding the way Linux currently divides things up
> > into the bindings.  For example having an extcon property seems like it
> > should be enough to figure out if we're using extcon.

> It won't be enough because MFD will create device for extcon and bind
> the driver. The same for the charger. We have a board where max8997 is
> used only as PMIC (providing regulators) without battery and USB
> connectivity.

I'm not sure I follow, sorry?  Either the core driver can parse the
bindings enough to know what children it has or (probably better) it can
instantiate the children unconditionally and then the function drivers
can figure out if they need to do anything.

> Another point, is that this reflects the real hardware. The same as we
> model entire SoC as multiple children of soc node (with their own
> properties), here we represent smaller chip which also has
> sub-components.

Components we're calling things like "extcon"...

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-04 21:24           ` Mark Brown
@ 2021-01-05 16:55             ` Krzysztof Kozlowski
  2021-01-06 14:59               ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Krzysztof Kozlowski @ 2021-01-05 16:55 UTC (permalink / raw)
  To: Mark Brown
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

On Mon, Jan 04, 2021 at 09:24:49PM +0000, Mark Brown wrote:
> On Mon, Jan 04, 2021 at 07:38:21PM +0100, Krzysztof Kozlowski wrote:
> > On Mon, Jan 04, 2021 at 06:27:34PM +0000, Mark Brown wrote:
> 
> > > We can indicate the presence of features without adding new compatible
> > > strings, that's just encoding the way Linux currently divides things up
> > > into the bindings.  For example having an extcon property seems like it
> > > should be enough to figure out if we're using extcon.
> 
> > It won't be enough because MFD will create device for extcon and bind
> > the driver. The same for the charger. We have a board where max8997 is
> > used only as PMIC (providing regulators) without battery and USB
> > connectivity.
> 
> I'm not sure I follow, sorry?  Either the core driver can parse the
> bindings enough to know what children it has or (probably better) it can
> instantiate the children unconditionally and then the function drivers
> can figure out if they need to do anything.

Currently the MFD parent/core driver will instantiate children
unconditionally.  It would have to be adapted. With proposed bindings -
nothing to change.  MFD core already does the thing.

The point is that function drivers should not be even bound, should not
start to probe. Otherwise if they probe and fail, they will pollute the
dmesg/probe log with failure. With the failure coming from looking for
missing of_node or any other condition from parent/core driver.

> > Another point, is that this reflects the real hardware. The same as we
> > model entire SoC as multiple children of soc node (with their own
> > properties), here we represent smaller chip which also has
> > sub-components.
> 
> Components we're calling things like "extcon"...

I am rather thinking about charger, but yes, extcon as well. Either you
have USB socket (and want to use associated logic) or not.

Best regards,
Krzysztof



^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-05 16:55             ` Krzysztof Kozlowski
@ 2021-01-06 14:59               ` Mark Brown
  2021-01-08 15:16                 ` Timon Baetz
  0 siblings, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-06 14:59 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Timon Baetz, Marek Szyprowski, Liam Girdwood, Rob Herring,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 1656 bytes --]

On Tue, Jan 05, 2021 at 05:55:29PM +0100, Krzysztof Kozlowski wrote:
> On Mon, Jan 04, 2021 at 09:24:49PM +0000, Mark Brown wrote:

> > I'm not sure I follow, sorry?  Either the core driver can parse the
> > bindings enough to know what children it has or (probably better) it can
> > instantiate the children unconditionally and then the function drivers
> > can figure out if they need to do anything.

> Currently the MFD parent/core driver will instantiate children
> unconditionally.  It would have to be adapted. With proposed bindings -
> nothing to change.  MFD core already does the thing.

We're not talking massive amounts of code here, but we are talking ABI
for a DT update.

> The point is that function drivers should not be even bound, should not
> start to probe. Otherwise if they probe and fail, they will pollute the
> dmesg/probe log with failure. With the failure coming from looking for
> missing of_node or any other condition from parent/core driver.

There will only be an error message if one is printed, if we can do a
definitive -ENODEV there should be no need to print an error.

> > > Another point, is that this reflects the real hardware. The same as we
> > > model entire SoC as multiple children of soc node (with their own
> > > properties), here we represent smaller chip which also has
> > > sub-components.

> > Components we're calling things like "extcon"...

> I am rather thinking about charger, but yes, extcon as well. Either you
> have USB socket (and want to use associated logic) or not.

Right, I'm just saying we don't need to add new device nodes reflecting
implementation details into the DT to do that.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-06 14:59               ` Mark Brown
@ 2021-01-08 15:16                 ` Timon Baetz
  2021-01-08 16:16                   ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Timon Baetz @ 2021-01-08 15:16 UTC (permalink / raw)
  To: Mark Brown
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

On Wed, 6 Jan 2021 14:59:31 +0000, Mark Brown wrote:
> On Tue, Jan 05, 2021 at 05:55:29PM +0100, Krzysztof Kozlowski wrote:
> > On Mon, Jan 04, 2021 at 09:24:49PM +0000, Mark Brown wrote:  
> 
> > > I'm not sure I follow, sorry?  Either the core driver can parse the
> > > bindings enough to know what children it has or (probably better) it can
> > > instantiate the children unconditionally and then the function drivers
> > > can figure out if they need to do anything.  
> 
> > Currently the MFD parent/core driver will instantiate children
> > unconditionally.  It would have to be adapted. With proposed bindings -
> > nothing to change.  MFD core already does the thing.  
> 
> We're not talking massive amounts of code here, but we are talking ABI
> for a DT update.
> 
> > The point is that function drivers should not be even bound, should not
> > start to probe. Otherwise if they probe and fail, they will pollute the
> > dmesg/probe log with failure. With the failure coming from looking for
> > missing of_node or any other condition from parent/core driver.  
> 
> There will only be an error message if one is printed, if we can do a
> definitive -ENODEV there should be no need to print an error.
> 
> > > > Another point, is that this reflects the real hardware. The same as we
> > > > model entire SoC as multiple children of soc node (with their own
> > > > properties), here we represent smaller chip which also has
> > > > sub-components.  
> 
> > > Components we're calling things like "extcon"...  
> 
> > I am rather thinking about charger, but yes, extcon as well. Either you
> > have USB socket (and want to use associated logic) or not.  
> 
> Right, I'm just saying we don't need to add new device nodes reflecting
> implementation details into the DT to do that.

I'm not sure I can contribute that much to this discussion (this is my
first proper kernel patch, also I don't really understand the argument).
FWIW I looked at other MFD devices while implementing this like max77836, 
max77693, max77650, max77843 (just to name a few). 
Assigning of_node to sub-devices using sub-nodes with compatible strings 
seemed to be a common pattern for MFD devices.
Muic needs a node to be used with extcon_get_edev_by_phandle().
Charger needs a node to reference a regulator.


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-08 15:16                 ` Timon Baetz
@ 2021-01-08 16:16                   ` Mark Brown
  2021-01-15  6:19                     ` Timon Baetz
  0 siblings, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-08 16:16 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 226 bytes --]

On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:

> Muic needs a node to be used with extcon_get_edev_by_phandle().
> Charger needs a node to reference a regulator.

The pattern is to use the parent device's node.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
  2021-01-04 13:51   ` Mark Brown
@ 2021-01-11 21:50   ` Rob Herring
  1 sibling, 0 replies; 30+ messages in thread
From: Rob Herring @ 2021-01-11 21:50 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood, Mark Brown,
	MyungJoo Ham, Chanwoo Choi, Lee Jones, Sebastian Reichel,
	linux-kernel, devicetree, linux-arm-kernel, linux-samsung-soc,
	linux-pm, ~postmarketos/upstreaming

On Wed, Dec 30, 2020 at 08:52:07PM +0000, Timon Baetz wrote:
> Add maxim,max8997-battery and maxim,max8997-muic optional nodes.
> 
> Signed-off-by: Timon Baetz <timon.baetz@protonmail.com>
> Acked-by: Krzysztof Kozlowski <krzk@kernel.org>
> ---
> v6: No change.
> v5: No change.
> v4: Make extcon and charger-supply optional.
> v3: Reorder patch, no change.
> v2: Add patch.
> 
>  .../bindings/regulator/max8997-regulator.txt         | 12 ++++++++++++
>  1 file changed, 12 insertions(+)

This exceeds my threshold of changes for please convert this to schema 
first. However, I agree with what Mark has said already, so maybe some 
of this isn't needed.

> 
> diff --git a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> index 6fe825b8ac1b..faaf2bbf0272 100644
> --- a/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> +++ b/Documentation/devicetree/bindings/regulator/max8997-regulator.txt
> @@ -53,6 +53,18 @@ Additional properties required if either of the optional properties are used:
>  - max8997,pmic-buck125-dvs-gpios: GPIO specifiers for three host gpio's used
>    for dvs. The format of the gpio specifier depends in the gpio controller.
>  
> +Optional nodes:
> +- charger: Node for configuring the charger driver.
> +  Required properties:
> +  - compatible: "maxim,max8997-battery"
> +  Optional properties:
> +  - extcon: extcon specifier for charging events

Don't use 'extcon' for new bindings. Define a connector node. USB I 
suppose?

> +  - charger-supply: regulator node for charging current
> +
> +- muic: Node used only by extcon consumers.
> +  Required properties:
> +  - compatible: "maxim,max8997-muic"
> +
>  Regulators: The regulators of max8997 that have to be instantiated should be
>  included in a sub-node named 'regulators'. Regulator nodes included in this
>  sub-node should be of the format as listed below.
> -- 
> 2.25.1
> 
> 

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-08 16:16                   ` Mark Brown
@ 2021-01-15  6:19                     ` Timon Baetz
  2021-01-15 13:42                       ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Timon Baetz @ 2021-01-15  6:19 UTC (permalink / raw)
  To: Mark Brown
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

On Fri, 8 Jan 2021 16:16:53 +0000, Mark Brown wrote:
> On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:
> 
> > Muic needs a node to be used with extcon_get_edev_by_phandle().
> > Charger needs a node to reference a regulator.  
> 
> The pattern is to use the parent device's node.

So is extcon going to be a self-reference then?

Just for my understanding: I can see sub-nodes for MFD all over the
place. It is still not clear to me why sub-nodes aren't the right
choice in this specific case?

Thanks for the feedback,
Timon


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-15  6:19                     ` Timon Baetz
@ 2021-01-15 13:42                       ` Mark Brown
  2021-01-16  8:03                         ` Timon Baetz
  0 siblings, 1 reply; 30+ messages in thread
From: Mark Brown @ 2021-01-15 13:42 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 900 bytes --]

On Fri, Jan 15, 2021 at 06:19:28AM +0000, Timon Baetz wrote:
> On Fri, 8 Jan 2021 16:16:53 +0000, Mark Brown wrote:
> > On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:

> > > Muic needs a node to be used with extcon_get_edev_by_phandle().
> > > Charger needs a node to reference a regulator.  

> > The pattern is to use the parent device's node.

> So is extcon going to be a self-reference then?

I guess, assuming you even need to look this up via the device tree.

> Just for my understanding: I can see sub-nodes for MFD all over the
> place. It is still not clear to me why sub-nodes aren't the right
> choice in this specific case?

They probably aren't the right choice for a lot of the other usages
either, there's a great tendency to just encode the specific way that
Linux currently handles things into the DT without really thinking about
what it means.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-15 13:42                       ` Mark Brown
@ 2021-01-16  8:03                         ` Timon Baetz
  2021-01-18 12:45                           ` Mark Brown
  0 siblings, 1 reply; 30+ messages in thread
From: Timon Baetz @ 2021-01-16  8:03 UTC (permalink / raw)
  To: Mark Brown
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

On Fri, 15 Jan 2021 13:42:14 +0000, Mark Brown wrote:
> On Fri, Jan 15, 2021 at 06:19:28AM +0000, Timon Baetz wrote:
> > On Fri, 8 Jan 2021 16:16:53 +0000, Mark Brown wrote:  
> > > On Fri, Jan 08, 2021 at 03:16:48PM +0000, Timon Baetz wrote:  
> 
> > > > Muic needs a node to be used with extcon_get_edev_by_phandle().
> > > > Charger needs a node to reference a regulator.    
> 
> > > The pattern is to use the parent device's node.  
> 
> > So is extcon going to be a self-reference then?  
> 
> I guess, assuming you even need to look this up via the device tree.

I could use extcon_get_extcon_dev("max8997-muic") and basically hard
code the extcon device name in the charger driver. Then I only need
charger-supply in DTS which could be added to the parent device's node.

Would that be acceptable for everyone?

Thanks,
Timon


^ permalink raw reply	[flat|nested] 30+ messages in thread

* Re: [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes
  2021-01-16  8:03                         ` Timon Baetz
@ 2021-01-18 12:45                           ` Mark Brown
  0 siblings, 0 replies; 30+ messages in thread
From: Mark Brown @ 2021-01-18 12:45 UTC (permalink / raw)
  To: Timon Baetz
  Cc: Krzysztof Kozlowski, Marek Szyprowski, Liam Girdwood,
	Rob Herring, MyungJoo Ham, Chanwoo Choi, Lee Jones,
	Sebastian Reichel, linux-kernel, devicetree, linux-arm-kernel,
	linux-samsung-soc, linux-pm, ~postmarketos/upstreaming

[-- Attachment #1: Type: text/plain, Size: 345 bytes --]

On Sat, Jan 16, 2021 at 08:03:25AM +0000, Timon Baetz wrote:

> I could use extcon_get_extcon_dev("max8997-muic") and basically hard
> code the extcon device name in the charger driver. Then I only need
> charger-supply in DTS which could be added to the parent device's node.

> Would that be acceptable for everyone?

Sounds reasonable to me.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2021-01-18 12:52 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-30 20:51 [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Timon Baetz
2020-12-30 20:52 ` [PATCH v6 2/8] regulator: dt-bindings: Document max8997-pmic nodes Timon Baetz
2021-01-04 13:51   ` Mark Brown
2021-01-04 18:18     ` Krzysztof Kozlowski
2021-01-04 18:27       ` Mark Brown
2021-01-04 18:38         ` Krzysztof Kozlowski
2021-01-04 21:24           ` Mark Brown
2021-01-05 16:55             ` Krzysztof Kozlowski
2021-01-06 14:59               ` Mark Brown
2021-01-08 15:16                 ` Timon Baetz
2021-01-08 16:16                   ` Mark Brown
2021-01-15  6:19                     ` Timon Baetz
2021-01-15 13:42                       ` Mark Brown
2021-01-16  8:03                         ` Timon Baetz
2021-01-18 12:45                           ` Mark Brown
2021-01-11 21:50   ` Rob Herring
2020-12-30 20:52 ` [PATCH v6 3/8] power: supply: max8997_charger: Set CHARGER current limit Timon Baetz
2020-12-30 23:22   ` kernel test robot
2020-12-31  7:19     ` Timon Baetz
2020-12-31  8:23       ` Krzysztof Kozlowski
2020-12-31  8:55   ` Krzysztof Kozlowski
2021-01-03  1:53   ` Sebastian Reichel
2020-12-30 20:52 ` [PATCH v6 4/8] ARM: dts: exynos: Add muic and charger nodes for I9100 Timon Baetz
2020-12-30 20:52 ` [PATCH v6 5/8] ARM: dts: exynos: Add muic and charger nodes for Origen Timon Baetz
2020-12-30 20:52 ` [PATCH v6 6/8] ARM: dts: exynos: Add muic and charger nodes for Trats Timon Baetz
2020-12-30 20:53 ` [PATCH v6 7/8] ARM: dts: exynos: Fix charging regulator voltage and current for I9100 Timon Baetz
2020-12-30 20:53 ` [PATCH v6 8/8] ARM: dts: exynos: Add top-off charging regulator node " Timon Baetz
2021-01-03 16:32 ` (subset) [PATCH v6 1/8] extcon: max8997: Add CHGINS and CHGRM interrupt handling Krzysztof Kozlowski
2021-01-03 16:34 ` Krzysztof Kozlowski
2021-01-04 10:26 ` Chanwoo Choi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).