Skip to contentSkip to conversation

Qualcomm labibb regulator driver

PATCH Superseded Sumit Semwal 4 participants 22 messages Jun 2, 2020 – Jun 18, 2020

Subsystems (4)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 cover Qualcomm labibb regulator driver

This series adds a driver for LAB/IBB regulators found on some Qualcomm SoCs. These regulators provide positive and/or negative boost power supplies for LCD/LED display panels connected to the SoC.

This series adds the support for pmi8998 PMIC found in SDM845 family of SoCs.

Changes from v3:
- Handled review comments from v3
- In core, swapped the meaning of enable_time and poll_enabled_time; so we wait for total enable_time delay, and poll in-between at poll_enabled_time interval now.
- fixed dt_bindings_check issues in dt-bindings patch.
- Cleanup of register_labibb_regulator(), and adapted to updated meaning of poll_enabled_time.

Changes from v2:
- Review comments from v2
- Moved the poll-to-check-enabled functionality to regulator core.
- Used more core features to simplify enable/disable functions.
- Moved the devicetree binding to yaml.
- Updated interrupt-names and simplified handling.

Changes from v1:
- Incorporated review comments from v1
- Changed from virtual-regulator based handling to individual regulator based handling.
- Reworked the core to merge most of enable/disable functions, combine the regulator_ops into one and allow for future variations.
- is_enabled() is now _really_ is_enabled()
- Simplified the SC interrupt handling - use regmap_read_poll_timeout, REGULATOR_EVENT_OVER_CURRENT handling and notification to clients.

Nisha Kumari (4):
dt-bindings: regulator: Add labibb regulator
arm64: dts: qcom: pmi8998: Add nodes for LAB and IBB regulators
regulator: qcom: Add labibb driver
regulator: qcom: labibb: Add SC interrupt handling

Sumit Semwal (1):
regulator: Allow regulators to verify enabled during enable()

 .../regulator/qcom-labibb-regulator.yaml      |  79 +++++
 arch/arm64/boot/dts/qcom/pmi8998.dtsi         |  14 +
 drivers/regulator/Kconfig                     |  10 +
 drivers/regulator/Makefile                    |   1 +
 drivers/regulator/core.c                      |  58 +++-
 drivers/regulator/qcom-labibb-regulator.c     | 289 ++++++++++++++++++
 include/linux/regulator/driver.h              |   5 +
 7 files changed, 455 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml
 create mode 100644 drivers/regulator/qcom-labibb-regulator.c
Signature · 1 line
2.26.2
#1 lore raw

PATCH v4 1/5 regulator: Allow regulators to verify enabled during enable()

Some regulators might need to verify that they have indeed been enabled after the enable() call is made and enable_time delay has passed.

This is implemented by repeatedly checking is_enabled() upto poll_enabled_time, waiting for the already calculated enable delay in each iteration.

--
v2: Address review comments, including swapping enable_time and poll_enabled_time.

---
 drivers/regulator/core.c         | 58 +++++++++++++++++++++++++++++++-
 include/linux/regulator/driver.h |  5 +++
 2 files changed, 62 insertions(+), 1 deletion(-)
drivers/regulator/core.c +57 -1
index 7486f6e4e613..d9ab888da95f 100644
@@ -2347,6 +2347,32 @@ static void _regulator_enable_delay(unsigned int delay)
 		udelay(us);
 }
 
+/* _regulator_check_status_enabled
+ *
+ * returns:
+ *          1 if status shows regulator is in enabled state
+ *          0 if not enabled state
+ *          else, error value as received from ops->get_status()
+ */
+static inline int _regulator_check_status_enabled(struct regulator_dev *rdev)
+{
+	int ret = rdev->desc->ops->get_status(rdev);
+
+	if (ret < 0) {
+		rdev_info(rdev, "get_status returned error: %d\n", ret);
+		return ret;
+	}
+
+	switch (ret) {
+	case REGULATOR_STATUS_OFF:
+	case REGULATOR_STATUS_ERROR:
+	case REGULATOR_STATUS_UNDEFINED:
+		return 0;
+	default:
+		return 1;
+	}
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
@@ -2407,7 +2433,37 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
 	 * together.  */
 	trace_regulator_enable_delay(rdev_get_name(rdev));
 
-	_regulator_enable_delay(delay);
+	/* If poll_enabled_time is set, poll upto the delay calculated
+	 * above, delaying poll_enabled_time uS to check if the regulator
+	 * actually got enabled.
+	 * If the regulator isn't enabled after enable_delay has
+	 * expired, return -ETIMEDOUT.
+	 */
+	if (rdev->desc->poll_enabled_time) {
+		unsigned int time_remaining = delay;
+
+		while (time_remaining > 0) {
+			_regulator_enable_delay(rdev->desc->poll_enabled_time);
+
+			if (rdev->desc->ops->get_status) {
+				ret = _regulator_check_status_enabled(rdev);
+				if (ret < 0)
+					return ret;
+				else if (ret)
+					break;
+			} else if (rdev->desc->ops->is_enabled(rdev))
+				break;
+
+			time_remaining -= rdev->desc->poll_enabled_time;
+		}
+
+		if (time_remaining <= 0) {
+			rdev_err(rdev, "Enabled check failed.\n");
+			return -ETIMEDOUT;
+		}
+	} else {
+		_regulator_enable_delay(delay);
+	}
 
 	trace_regulator_enable_complete(rdev_get_name(rdev));
 
include/linux/regulator/driver.h +5 -0
index 29d920516e0b..bb50e943010f 100644
@@ -322,6 +322,9 @@ enum regulator_type {
  * @enable_time: Time taken for initial enable of regulator (in uS).
  * @off_on_delay: guard time (in uS), before re-enabling a regulator
  *
+ * @poll_enabled_time: Maximum time (in uS) to poll if the regulator is
+ *                          actually enabled, after enable() call
+ *
  * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
  */
 struct regulator_desc {
@@ -389,6 +392,8 @@ struct regulator_desc {
 
 	unsigned int off_on_delay;
 
+	unsigned int poll_enabled_time;
+
 	unsigned int (*of_map_mode)(unsigned int mode);
 };
 
Signature · 1 line
2.26.2
maintainer
#2 lore raw

Re: [PATCH v4 1/5] regulator: Allow regulators to verify enabled during enable()

drivers/regulator/core.c static int _regulator_do_enable(struct regulator_dev *rdev) · line 2462

Quoted 4 lines · Sumit Semwal
drivers/regulator/core.c +4 -0
+
+		if (time_remaining <= 0) {
+			rdev_err(rdev, "Enabled check failed.\n");
+			return -ETIMEDOUT;

s/failed/timed out/

Quoted 3 lines

+ * @poll_enabled_time: Maximum time (in uS) to poll if the regulator is
+ * actually enabled, after enable() call
+ *

This comment needs updating to reflect the new implementation.

#3 lore raw

Re: [PATCH v4 1/5] regulator: Allow regulators to verify enabled during enable()

Hi Mark,

Thanks for the review!

Quoted 9 lines · Mark Brown

drivers/regulator/core.c static int _regulator_do_enable(struct regulator_dev *rdev) · line 2462

Quoted 4 lines · Sumit Semwal
drivers/regulator/core.c +4 -0
+
+             if (time_remaining <= 0) {
+                     rdev_err(rdev, "Enabled check failed.\n");
+                     return -ETIMEDOUT;

s/failed/timed out/

Ack

Quoted 6 lines
Quoted 4 lines

+ * @poll_enabled_time: Maximum time (in uS) to poll if the regulator is
+ * actually enabled, after enable() call
+ *

This comment needs updating to reflect the new implementation.

Yes, I will update.

Best,
Sumit.

#4 lore raw

Re: [PATCH v4 1/5] regulator: Allow regulators to verify enabled during enable()

In reply to Sumit Semwal
Quoted 20 lines · Sumit Semwal

Some regulators might need to verify that they have indeed been enabled after the enable() call is made and enable_time delay has passed.

This is implemented by repeatedly checking is_enabled() upto poll_enabled_time, waiting for the already calculated enable delay in each iteration.

--
v2: Address review comments, including swapping enable_time and poll_enabled_time.

---
 drivers/regulator/core.c         | 58 +++++++++++++++++++++++++++++++-
 include/linux/regulator/driver.h |  5 +++
 2 files changed, 62 insertions(+), 1 deletion(-)
drivers/regulator/core.c +0 -0
index 7486f6e4e613..d9ab888da95f 100644

drivers/regulator/core.c static void _regulator_enable_delay(unsigned int delay) · line 2350

Quoted 4 lines
drivers/regulator/core.c +1 -0
@@ -2347,6 +2347,32 @@ static void _regulator_enable_delay(unsigned int delay)
 		udelay(us);
 }
 
+/* _regulator_check_status_enabled

Please make all your kerneldoc follow:
https://www.kernel.org/doc/html/latest/doc-guide/kernel-doc.html#function-documentation

Quoted 72 lines
drivers/regulator/core.c +56 -1
+ *
+ * returns:
+ *          1 if status shows regulator is in enabled state
+ *          0 if not enabled state
+ *          else, error value as received from ops->get_status()
+ */
+static inline int _regulator_check_status_enabled(struct regulator_dev *rdev)
+{
+	int ret = rdev->desc->ops->get_status(rdev);
+
+	if (ret < 0) {
+		rdev_info(rdev, "get_status returned error: %d\n", ret);
+		return ret;
+	}
+
+	switch (ret) {
+	case REGULATOR_STATUS_OFF:
+	case REGULATOR_STATUS_ERROR:
+	case REGULATOR_STATUS_UNDEFINED:
+		return 0;
+	default:
+		return 1;
+	}
+}
+
 static int _regulator_do_enable(struct regulator_dev *rdev)
 {
 	int ret, delay;
@@ -2407,7 +2433,37 @@ static int _regulator_do_enable(struct regulator_dev *rdev)
 	 * together.  */
 	trace_regulator_enable_delay(rdev_get_name(rdev));
 
-	_regulator_enable_delay(delay);
+	/* If poll_enabled_time is set, poll upto the delay calculated
+	 * above, delaying poll_enabled_time uS to check if the regulator
+	 * actually got enabled.
+	 * If the regulator isn't enabled after enable_delay has
+	 * expired, return -ETIMEDOUT.
+	 */
+	if (rdev->desc->poll_enabled_time) {
+		unsigned int time_remaining = delay;
+
+		while (time_remaining > 0) {
+			_regulator_enable_delay(rdev->desc->poll_enabled_time);
+
+			if (rdev->desc->ops->get_status) {
+				ret = _regulator_check_status_enabled(rdev);
+				if (ret < 0)
+					return ret;
+				else if (ret)
+					break;
+			} else if (rdev->desc->ops->is_enabled(rdev))
+				break;
+
+			time_remaining -= rdev->desc->poll_enabled_time;
+		}
+
+		if (time_remaining <= 0) {
+			rdev_err(rdev, "Enabled check failed.\n");
+			return -ETIMEDOUT;
+		}
+	} else {
+		_regulator_enable_delay(delay);
+	}
 
 	trace_regulator_enable_complete(rdev_get_name(rdev));
 
include/linux/regulator/driver.h +0 -0
index 29d920516e0b..bb50e943010f 100644

include/linux/regulator/driver.h enum regulator_type { · line 326

Quoted 5 lines
include/linux/regulator/driver.h +2 -0
@@ -322,6 +322,9 @@ enum regulator_type {
  * @enable_time: Time taken for initial enable of regulator (in uS).
  * @off_on_delay: guard time (in uS), before re-enabling a regulator
  *
+ * @poll_enabled_time: Maximum time (in uS) to poll if the regulator is
+ *                          actually enabled, after enable() call

I read this as "how long should we stay in the poll loop". I think it would be better describes as something like "The polling interval to use while checking that the regulator was actually enabled".

Regards,
Bjorn

Quoted 16 lines
include/linux/regulator/driver.h +3 -0
+ *
  * @of_map_mode: Maps a hardware mode defined in a DeviceTree to a standard mode
  */
 struct regulator_desc {
@@ -389,6 +392,8 @@ struct regulator_desc {
 
 	unsigned int off_on_delay;
 
+	unsigned int poll_enabled_time;
+
 	unsigned int (*of_map_mode)(unsigned int mode);
 };
 
Signature · 1 line
2.26.2
#5 lore raw

PATCH v4 2/5 dt-bindings: regulator: Add labibb regulator

In reply to Sumit Semwal

From: Nisha Kumari <[email protected]>

Adding the devicetree binding for labibb regulator.

[sumits: cleanup as per review comments and update to yaml]

--
v2: updated for better compatible string and names.
v3: moved to yaml
v4: fixed dt_binding_check issues

---
 .../regulator/qcom-labibb-regulator.yaml      | 79 +++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +79 -0
new file mode 100644
index 000000000000..178820ec04c7
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0-only
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/qcom-labibb-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm's LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) Regulator
+
+maintainers:
+  - Sumit Semwal <[email protected]>
+
+description:
+  LAB can be used as a positive boost power supply and IBB can be used as a
+  negative boost power supply for display panels. Currently implemented for
+  pmi8998.
+
+allOf:
+  - $ref: "regulator.yaml#"
+
+properties:
+  compatible:
+    const: qcom,pmi8998-lab-ibb
+
+  lab:
+    type: object
+
+    properties:
+
+      interrupts:
+        maxItems: 1
+        description:
+          Short-circuit interrupt for lab.
+
+      interrupt-names:
+        const: sc-err
+
+    required:
+    - interrupts
+    - interrupt-names
+
+  ibb:
+    type: object
+
+    properties:
+
+      interrupts:
+        maxItems: 1
+        description:
+          Short-circuit interrupt for lab.
+
+      interrupt-names:
+        const: sc-err
+
+    required:
+    - interrupts
+    - interrupt-names
+
+required:
+  - compatible
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    labibb {
+      compatible = "qcom,pmi8998-lab-ibb";
+
+      lab {
+        interrupts = <0x3 0x0 IRQ_TYPE_EDGE_RISING>;
+        interrupt-names = "sc-err";
+      };
+
+      ibb {
+        interrupts = <0x3 0x2 IRQ_TYPE_EDGE_RISING>;
+        interrupt-names = "sc-err";
+      };
+    };
+
+...
Signature · 1 line
2.26.2
maintainer
#6 lore raw

Re: [PATCH v4 2/5] dt-bindings: regulator: Add labibb regulator

Quoted 22 lines · Sumit Semwal

From: Nisha Kumari <[email protected]>

Adding the devicetree binding for labibb regulator.

[sumits: cleanup as per review comments and update to yaml]

--
v2: updated for better compatible string and names.
v3: moved to yaml
v4: fixed dt_binding_check issues

---
 .../regulator/qcom-labibb-regulator.yaml      | 79 +++++++++++++++++++
 1 file changed, 79 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +0 -0
new file mode 100644
index 000000000000..178820ec04c7

Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml line 1

Quoted 1 line
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +1 -0
@@ -0,0 +1,79 @@
+# SPDX-License-Identifier: GPL-2.0-only

Dual license new bindings:

(GPL-2.0-only OR BSD-2-Clause)

Quoted 7 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +7 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/qcom-labibb-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm's LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) Regulator
+

Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml line 18

Quoted 10 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +10 -0
+maintainers:
+  - Sumit Semwal <[email protected]>
+
+description:
+  LAB can be used as a positive boost power supply and IBB can be used as a
+  negative boost power supply for display panels. Currently implemented for
+  pmi8998.
+
+allOf:
+  - $ref: "regulator.yaml#"

I think you want this under each child as this schema applies to each regulator. But you aren't using any of the regulator properties, so not even needed? Or the example is not complete?

Quoted 7 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +7 -0
+
+properties:
+  compatible:
+    const: qcom,pmi8998-lab-ibb
+
+  lab:
+    type: object

Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml line 35

Quoted 10 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +10 -0
+
+    properties:
+
+      interrupts:
+        maxItems: 1
+        description:
+          Short-circuit interrupt for lab.
+
+      interrupt-names:
+        const: sc-err

You don't really need a name if there's only 1.

Quoted 14 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +14 -0
+
+    required:
+    - interrupts
+    - interrupt-names
+
+  ibb:
+    type: object
+
+    properties:
+
+      interrupts:
+        maxItems: 1
+        description:
+          Short-circuit interrupt for lab.

Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml line 59

Quoted 10 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +10 -0
+
+      interrupt-names:
+        const: sc-err
+
+    required:
+    - interrupts
+    - interrupt-names
+
+required:
+  - compatible

unevaluatedProperties: false

Quoted 23 lines
Documentation/devicetree/bindings/regulator/qcom-labibb-regulator.yaml new file +20 -0
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/irq.h>
+
+    labibb {
+      compatible = "qcom,pmi8998-lab-ibb";
+
+      lab {
+        interrupts = <0x3 0x0 IRQ_TYPE_EDGE_RISING>;
+        interrupt-names = "sc-err";
+      };
+
+      ibb {
+        interrupts = <0x3 0x2 IRQ_TYPE_EDGE_RISING>;
+        interrupt-names = "sc-err";
+      };
+    };
+
+...
Signature · 1 line
2.26.2
#7 lore raw

PATCH v4 3/5 arm64: dts: qcom: pmi8998: Add nodes for LAB and IBB regulators

In reply to Sumit Semwal

From: Nisha Kumari <[email protected]>

This patch adds devicetree nodes for LAB and IBB regulators.

[sumits: Updated for better compatible strings and names]

--
v2: sumits: updated for better compatible string and names
v3: sumits: updated interrupt-names as per review comments
v4: sumits: removed labibb label

---
 arch/arm64/boot/dts/qcom/pmi8998.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/arm64/boot/dts/qcom/pmi8998.dtsi +14 -0
index 23f9146a161e..3230b78b8048 100644
@@ -25,5 +25,19 @@ pmi8998_lsid1: pmic@3 {
 		reg = <0x3 SPMI_USID>;
 		#address-cells = <1>;
 		#size-cells = <0>;
+
+		labibb {
+			compatible = "qcom,pmi8998-lab-ibb";
+
+			ibb: ibb {
+				interrupts = <0x3 0xdc 0x2 IRQ_TYPE_EDGE_RISING>;
+				interrupt-names = "sc-err";
+			};
+
+			lab: lab {
+				interrupts = <0x3 0xde 0x0 IRQ_TYPE_EDGE_RISING>;
+				interrupt-names = "sc-err";
+			};
+		};
 	};
 };
Signature · 1 line
2.26.2
#8 lore raw

PATCH v4 4/5 regulator: qcom: Add labibb driver

In reply to Sumit Semwal

From: Nisha Kumari <[email protected]>

Qualcomm platforms have LAB(LCD AMOLED Boost)/IBB(Inverting Buck Boost) regulators, labibb for short, which are used as power supply for LCD Mode displays.

This patch adds labibb regulator driver for pmi8998 PMIC, found on SDM845 platforms.

[sumits: reworked to driver for more common code, using core regulator
features, and using newly-added poll_enabled_time functionality from core]
--
v2: sumits: reworked the driver for more common code, and addressed
review comments from v1
v3: sumits: addressed review comments from v2; moved to use core
regulator features like enable_time, off_on_delay, and the newly added poll_enabled_time. Moved the check_enabled functionality to core framework via poll_enabled_time.
v4: sumits: address review comments from v3, including cleaning up
register_labibb_regulator(), and adapted to updated meaning of poll_enabled_time.

---
 drivers/regulator/Kconfig                 |  10 ++
 drivers/regulator/Makefile                |   1 +
 drivers/regulator/qcom-labibb-regulator.c | 193 ++++++++++++++++++++++
 3 files changed, 204 insertions(+)
 create mode 100644 drivers/regulator/qcom-labibb-regulator.c
drivers/regulator/Kconfig +10 -0
index f4b72cb098ef..58704a9fd05d 100644
@@ -1167,5 +1167,15 @@ config REGULATOR_WM8994
 	  This driver provides support for the voltage regulators on the
 	  WM8994 CODEC.
 
+config REGULATOR_QCOM_LABIBB
+	tristate "QCOM LAB/IBB regulator support"
+	depends on SPMI || COMPILE_TEST
+	help
+	  This driver supports Qualcomm's LAB/IBB regulators present on the
+	  Qualcomm's PMIC chip pmi8998. QCOM LAB and IBB are SPMI
+	  based PMIC implementations. LAB can be used as positive
+	  boost regulator and IBB can be used as a negative boost regulator
+	  for LCD display panel.
+
 endif
 
drivers/regulator/Makefile +1 -0
index 6610ee001d9a..5b313786c0e8 100644
@@ -87,6 +87,7 @@ obj-$(CONFIG_REGULATOR_MT6323)	+= mt6323-regulator.o
 obj-$(CONFIG_REGULATOR_MT6358)	+= mt6358-regulator.o
 obj-$(CONFIG_REGULATOR_MT6380)	+= mt6380-regulator.o
 obj-$(CONFIG_REGULATOR_MT6397)	+= mt6397-regulator.o
+obj-$(CONFIG_REGULATOR_QCOM_LABIBB) += qcom-labibb-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_RPM) += qcom_rpm-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_RPMH) += qcom-rpmh-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_SMD_RPM) += qcom_smd-regulator.o
drivers/regulator/qcom-labibb-regulator.c new file +194 -0

194 lines not on this page · raw message

Signature · 1 line
2.26.2
maintainer
#9 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

drivers/regulator/qcom-labibb-regulator.c line 59

Quoted 13 lines · Sumit Semwal
drivers/regulator/qcom-labibb-regulator.c new file +13 -0
+static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
+{
+	int ret;
+	unsigned int val;
+	struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+	ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, &val);
+	if (ret < 0) {
+		dev_err(reg->dev, "Read register failed ret = %d\n", ret);
+		return ret;
+	}
+	return !!(val & LABIBB_STATUS1_VREG_OK_BIT);
+}

This should be a get_status() callback...

drivers/regulator/qcom-labibb-regulator.c line 69

Quoted 9 lines
drivers/regulator/qcom-labibb-regulator.c new file +9 -0
+static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
+{
+	return regulator_enable_regmap(rdev);
+}
+
+static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
+{
+	return regulator_disable_regmap(rdev);
+}

...is_enabled() should just be regulator_is_enabled_regmap() and these functions should just be removed entirely, you can use the regmap operations directly as the ops without the wrapper.

drivers/regulator/qcom-labibb-regulator.c line 144

Quoted 9 lines
drivers/regulator/qcom-labibb-regulator.c new file +9 -0
+	match = of_match_device(qcom_labibb_match, &pdev->dev);
+	if (!match)
+		return -ENODEV;
+
+	for (reg_data = match->data; reg_data->name; reg_data++) {
+		child = of_get_child_by_name(pdev->dev.of_node, reg_data->name);
+
+		if (WARN_ON(child == NULL))
+			return -EINVAL;

This feels like the DT bindings are confused - why do we need to search like this?

drivers/regulator/qcom-labibb-regulator.c line 170

Quoted 1 line
drivers/regulator/qcom-labibb-regulator.c new file +1 -0
+		dev_info(dev, "Registering %s regulator\n", child->full_name);

This is noise, remove it. The regulator framework will announce new regulators anyway.

#10 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Hi Mark,

Thank you very much for reviewing.

Quoted 19 lines · Mark Brown

drivers/regulator/qcom-labibb-regulator.c line 59

Quoted 13 lines · Sumit Semwal
drivers/regulator/qcom-labibb-regulator.c new file +13 -0
+static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
+{
+     int ret;
+     unsigned int val;
+     struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+     ret = regmap_read(reg->regmap, reg->base + REG_LABIBB_STATUS1, &val);
+     if (ret < 0) {
+             dev_err(reg->dev, "Read register failed ret = %d\n", ret);
+             return ret;
+     }
+     return !!(val & LABIBB_STATUS1_VREG_OK_BIT);
+}

This should be a get_status() callback...

From my (limited) understanding of downstream code, it seemed like for this set of regulators, the 'enabled' check is done via the 'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg / enable_mask ones. That's why I used it as is_enabled() callback. I will try and check with the QC folks to clarify this point about their hardware.

Quoted 5 lines
Quoted 5 lines
drivers/regulator/qcom-labibb-regulator.c new file +5 -0
+static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
+{
+     return regulator_enable_regmap(rdev);
+}
+
Quoted 8 lines

drivers/regulator/qcom-labibb-regulator.c line 69

Quoted 4 lines
drivers/regulator/qcom-labibb-regulator.c new file +4 -0
+static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
+{
+     return regulator_disable_regmap(rdev);
+}

...is_enabled() should just be regulator_is_enabled_regmap() and these functions should just be removed entirely, you can use the regmap operations directly as the ops without the wrapper.

The 2 wrappers are a precursor to the next patch, where we keep track of regulator's enable status to check during SC handling.

Quoted 13 lines

drivers/regulator/qcom-labibb-regulator.c line 144

Quoted 10 lines
drivers/regulator/qcom-labibb-regulator.c new file +9 -0
+     match = of_match_device(qcom_labibb_match, &pdev->dev);
+     if (!match)
+             return -ENODEV;
+
+     for (reg_data = match->data; reg_data->name; reg_data++) {
+             child = of_get_child_by_name(pdev->dev.of_node, reg_data->name);
+
+             if (WARN_ON(child == NULL))
+                     return -EINVAL;

This feels like the DT bindings are confused - why do we need to search like this?

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

Quoted 5 lines
Quoted 2 lines

+ dev_info(dev, "Registering %s regulator\n", child->full_name);

This is noise, remove it. The regulator framework will announce new regulators anyway.

Agreed. will remove in the next iteration.

Best,
Sumit.

maintainer
#11 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 11 lines · Sumit Semwal
Quoted 3 lines · Mark Brown

On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:

This should be a get_status() callback...

From my (limited) understanding of downstream code, it seemed like for this set of regulators, the 'enabled' check is done via the 'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg / enable_mask ones. That's why I used it as is_enabled() callback. I will try and check with the QC folks to clarify this point about their hardware.

The way this is functioning at the minute the downstream code is just buggy.

Quoted 6 lines
Quoted 3 lines

...is_enabled() should just be regulator_is_enabled_regmap() and these functions should just be removed entirely, you can use the regmap operations directly as the ops without the wrapper.

The 2 wrappers are a precursor to the next patch, where we keep track of regulator's enable status to check during SC handling.

Add the functions when they're useful, not before. TBH if the register is write only you're probably better off adding a register cache.

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
drivers/regulator/qcom-labibb-regulator.c new file +4 -0
+     match = of_match_device(qcom_labibb_match, &pdev->dev);
+     if (!match)
+             return -ENODEV;
+
Quoted 8 lines

drivers/regulator/qcom-labibb-regulator.c line 144

Quoted 5 lines
drivers/regulator/qcom-labibb-regulator.c new file +5 -0
+     for (reg_data = match->data; reg_data->name; reg_data++) {
+             child = of_get_child_by_name(pdev->dev.of_node, reg_data->name);
+
+             if (WARN_ON(child == NULL))
+                     return -EINVAL;

This feels like the DT bindings are confused - why do we need to search like this?

Quoted 2 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?

#12 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Hello Mark,

Quoted 14 lines · Mark Brown
Quoted 11 lines · Sumit Semwal
Quoted 3 lines · Mark Brown

On Tue, Jun 02, 2020 at 03:39:23PM +0530, Sumit Semwal wrote:

This should be a get_status() callback...

From my (limited) understanding of downstream code, it seemed like for this set of regulators, the 'enabled' check is done via the 'REG_LABIBB_STATUS1 reg; for some reason, not via the same enable_reg / enable_mask ones. That's why I used it as is_enabled() callback. I will try and check with the QC folks to clarify this point about their hardware.

Quoted 2 lines

The way this is functioning at the minute the downstream code is just buggy.

Apologies for the delay in responding - I pinged the QC folks, and was waiting for their reply but haven't got any response so far.

I tried your suggestion to use the ENABLE_CTL register for checking if the regulator is actually enabled. In my limited testing on the Poco, it seems like the STATUS1 register updates faster than the ENABLE_CTL register, so on the device, I see noticeable lag when I use ENABLE_CTL for is_enabled() check. [This is especially true for the IBB, which takes longer to become usable than the LAB regulator.]

I understand from a pure regulators' correctness point of view, ENABLE_CTL should be the one checked there, so I can change the patch as you suggested, but there seems to be some performance penalty there.

Quoted 10 lines
Quoted 7 lines
Quoted 4 lines

...is_enabled() should just be regulator_is_enabled_regmap() and these functions should just be removed entirely, you can use the regmap operations directly as the ops without the wrapper.

The 2 wrappers are a precursor to the next patch, where we keep track of regulator's enable status to check during SC handling.

Add the functions when they're useful, not before. TBH if the register is write only you're probably better off adding a register cache.

Agreed, I will remove the wrappers from here, using the regmap functions, and add the wrappers with the SC handling patch.

Quoted 14 lines
Quoted 13 lines
Quoted 13 lines

drivers/regulator/qcom-labibb-regulator.c line 144

Quoted 10 lines
drivers/regulator/qcom-labibb-regulator.c new file +9 -0
+     match = of_match_device(qcom_labibb_match, &pdev->dev);
+     if (!match)
+             return -ENODEV;
+
+     for (reg_data = match->data; reg_data->name; reg_data++) {
+             child = of_get_child_by_name(pdev->dev.of_node, reg_data->name);
+
+             if (WARN_ON(child == NULL))
+                     return -EINVAL;

This feels like the DT bindings are confused - why do we need to search like this?

Quoted 4 lines
Quoted 2 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?

This loop mechanism is what I saw in the other qcom regulators upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get and validate both nodes?

Best,
Sumit.

maintainer
#13 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 4 lines · Sumit Semwal

I understand from a pure regulators' correctness point of view, ENABLE_CTL should be the one checked there, so I can change the patch as you suggested, but there seems to be some performance penalty there.

I thought the goal was to have the performance penalty to ensure that the regulator had actually started?

Quoted 9 lines
Quoted 4 lines
Quoted 2 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?

This loop mechanism is what I saw in the other qcom regulators upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get and validate both nodes?

I don't understand what you mean by "two children nodes" here?

#14 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 10 lines · Mark Brown
Quoted 4 lines · Sumit Semwal

I understand from a pure regulators' correctness point of view, ENABLE_CTL should be the one checked there, so I can change the patch as you suggested, but there seems to be some performance penalty there.

I thought the goal was to have the performance penalty to ensure that the regulator had actually started?

IMHO, with the poll_enabled_time mechanism added, we would not need to wait for the full enabled_time time for the regulator to get enabled, but we could poll (and potentially know earlier) if the regulator is enabled.
The performance penalty I was talking, is about how should we check if the regulator is really enabled or not - via reading the STATUS1 register, which seems to tell the status a bit faster, or via reading the ENABLE_CTL register which we also use to enable/disable the regulator, but which seems to be slower in updating the status.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

No, this whole loop - why this whole match and get child stuff?

This loop mechanism is what I saw in the other qcom regulators upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get and validate both nodes?

I don't understand what you mean by "two children nodes" here?

The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.

Best,
Sumit.

maintainer
#15 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 11 lines · Sumit Semwal
Quoted 9 lines · Mark Brown
Quoted 4 lines · Sumit Semwal

I understand from a pure regulators' correctness point of view, ENABLE_CTL should be the one checked there, so I can change the patch as you suggested, but there seems to be some performance penalty there.

I thought the goal was to have the performance penalty to ensure that the regulator had actually started?

Quoted 9 lines

IMHO, with the poll_enabled_time mechanism added, we would not need to wait for the full enabled_time time for the regulator to get enabled, but we could poll (and potentially know earlier) if the regulator is enabled.
The performance penalty I was talking, is about how should we check if the regulator is really enabled or not - via reading the STATUS1 register, which seems to tell the status a bit faster, or via reading the ENABLE_CTL register which we also use to enable/disable the regulator, but which seems to be slower in updating the status.

That seems... interesting. Are you sure the regulator has fully ramped when STATUS1 starts flagging?

Quoted 5 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

This loop mechanism is what I saw in the other qcom regulators upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get and validate both nodes?

I don't understand what you mean by "two children nodes" here?

The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.

Use of_match and regulators_node like other regulator drivers.

#16 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 23 lines · Mark Brown
Quoted 11 lines · Sumit Semwal
Quoted 9 lines · Mark Brown
Quoted 4 lines · Sumit Semwal

I understand from a pure regulators' correctness point of view, ENABLE_CTL should be the one checked there, so I can change the patch as you suggested, but there seems to be some performance penalty there.

I thought the goal was to have the performance penalty to ensure that the regulator had actually started?

Quoted 9 lines

IMHO, with the poll_enabled_time mechanism added, we would not need to wait for the full enabled_time time for the regulator to get enabled, but we could poll (and potentially know earlier) if the regulator is enabled.
The performance penalty I was talking, is about how should we check if the regulator is really enabled or not - via reading the STATUS1 register, which seems to tell the status a bit faster, or via reading the ENABLE_CTL register which we also use to enable/disable the regulator, but which seems to be slower in updating the status.

Quoted 2 lines

That seems... interesting. Are you sure the regulator has fully ramped when STATUS1 starts flagging?

On a consumer device, I am not sure I have any way of checking that, but if there's some way you'd like me to validate it, I'll be happy to.

Quoted 11 lines
Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
Quoted 5 lines
Quoted 3 lines

The WARN_ON? This was suggested by Bjorn to catch the case where the DT binding for a PMIC instantiates only one of the regulators.

No, this whole loop - why this whole match and get child stuff?

This loop mechanism is what I saw in the other qcom regulators upstream, so thought it was an acceptable way.
For the two children nodes, do you recommend another mechanism to get and validate both nodes?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I don't understand what you mean by "two children nodes" here?

The two 'lab' and 'ibb' regulator nodes that are part of the labibb node.

Use of_match and regulators_node like other regulator drivers.

Ok, let me see what I can do with those; we still need to flag if some platform only instantiates one of the two lab/ibb regulators - I was given the impression they're 'both or none' case.

Best,
Sumit.

maintainer
#17 lore raw

Re: [PATCH v4 4/5] regulator: qcom: Add labibb driver

Quoted 8 lines · Sumit Semwal
Quoted 2 lines · Mark Brown

That seems... interesting. Are you sure the regulator has fully ramped when STATUS1 starts flagging?

On a consumer device, I am not sure I have any way of checking that, but if there's some way you'd like me to validate it, I'll be happy to.

Without any way of validating what's going on or information on the hardware I'd be inclined to go with whatever reports more slowly for safety.

#18 lore raw

PATCH v4 5/5 regulator: qcom: labibb: Add SC interrupt handling

In reply to Sumit Semwal

From: Nisha Kumari <[email protected]>

Add Short circuit interrupt handling and recovery for the lab and ibb regulators on qcom platforms.

The client panel drivers need to register for REGULATOR_EVENT_OVER_CURRENT notification which will be triggered on short circuit. They should try to enable the regulator once, and if it doesn't get enabled, handle shutting down the panel accordingly.

[sumits: updated to rework to use regmap_read_poll_timeout, handle it per
regulator, add REGULATOR_EVENT_OVER_CURRENT handling and notification to clients and other cleanup]
--
v2: sumits: reworked handling to user regmap_read_poll_timeout, and handle it
per-regulator instead of clearing both lab and ibb errors on either irq triggering. Also added REGULATOR_EVENT_OVER_CURRENT handling and notification to clients.
v3: sumits: updated as per review comments of v2: removed spurious check for
irq in handler and some unused variables; inlined some of the code, omitted IRQF_TRIGGER_RISING as it's coming from DT.
v4: sumits: updated 'int vreg_enabled' to 'boot enabled', made sc_irq a local var
and other review comments from v3.

---
 drivers/regulator/qcom-labibb-regulator.c | 102 +++++++++++++++++++++-
 1 file changed, 99 insertions(+), 3 deletions(-)
drivers/regulator/qcom-labibb-regulator.c +99 -3
index 33b764ac69d1..bca0308b26dd 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-only
 // Copyright (c) 2020, The Linux Foundation. All rights reserved.
 
+#include <linux/interrupt.h>
 #include <linux/module.h>
 #include <linux/of_irq.h>
 #include <linux/of.h>
@@ -18,6 +19,7 @@
 #define REG_LABIBB_ENABLE_CTL		0x46
 #define LABIBB_STATUS1_VREG_OK_BIT	BIT(7)
 #define LABIBB_CONTROL_ENABLE		BIT(7)
+#define LABIBB_STATUS1_SC_DETECT_BIT	BIT(6)
 
 #define LAB_ENABLE_CTL_MASK		BIT(7)
 #define IBB_ENABLE_CTL_MASK		(BIT(7) | BIT(6))
@@ -27,12 +29,16 @@
 #define IBB_ENABLE_TIME			(LABIBB_OFF_ON_DELAY * 10)
 #define LABIBB_POLL_ENABLED_TIME	1000
 
+#define POLLING_SCP_DONE_INTERVAL_US	5000
+#define POLLING_SCP_TIMEOUT		16000
+
 struct labibb_regulator {
 	struct regulator_desc		desc;
 	struct device			*dev;
 	struct regmap			*regmap;
 	struct regulator_dev		*rdev;
 	u16				base;
+	bool				enabled;
 	u8				type;
 };
 
@@ -59,12 +65,26 @@ static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev)
 
 static int qcom_labibb_regulator_enable(struct regulator_dev *rdev)
 {
-	return regulator_enable_regmap(rdev);
+	int ret;
+	struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+	ret = regulator_enable_regmap(rdev);
+	if (ret >= 0)
+		reg->enabled = true;
+
+	return ret;
 }
 
 static int qcom_labibb_regulator_disable(struct regulator_dev *rdev)
 {
-	return regulator_disable_regmap(rdev);
+	int ret = 0;
+	struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+	ret = regulator_disable_regmap(rdev);
+	if (ret >= 0)
+		reg->enabled = false;
+
+	return ret;
 }
 
 static struct regulator_ops qcom_labibb_ops = {
@@ -73,12 +93,70 @@ static struct regulator_ops qcom_labibb_ops = {
 	.is_enabled		= qcom_labibb_regulator_is_enabled,
 };
 
+static irqreturn_t labibb_sc_err_handler(int irq, void *_reg)
+{
+	int ret;
+	u16 reg;
+	unsigned int val;
+	struct labibb_regulator *labibb_reg = _reg;
+	bool in_sc_err, scp_done = false;
+
+	ret = regmap_read(labibb_reg->regmap,
+			  labibb_reg->base + REG_LABIBB_STATUS1, &val);
+	if (ret < 0) {
+		dev_err(labibb_reg->dev, "sc_err_irq: Read failed, ret=%d\n",
+			ret);
+		return IRQ_HANDLED;
+	}
+
+	dev_dbg(labibb_reg->dev, "%s SC error triggered! STATUS1 = %d\n",
+		labibb_reg->desc.name, val);
+
+	in_sc_err = !!(val & LABIBB_STATUS1_SC_DETECT_BIT);
+
+	/*
+	 * The SC(short circuit) fault would trigger PBS(Portable Batch
+	 * System) to disable regulators for protection. This would
+	 * cause the SC_DETECT status being cleared so that it's not
+	 * able to get the SC fault status.
+	 * Check if the regulator is enabled in the driver but
+	 * disabled in hardware, this means a SC fault had happened
+	 * and SCP handling is completed by PBS.
+	 */
+	if (!in_sc_err) {
+
+		reg = labibb_reg->base + REG_LABIBB_ENABLE_CTL;
+
+		ret = regmap_read_poll_timeout(labibb_reg->regmap,
+					reg, val,
+					!(val & LABIBB_CONTROL_ENABLE),
+					POLLING_SCP_DONE_INTERVAL_US,
+					POLLING_SCP_TIMEOUT);
+
+		if (!ret && labibb_reg->enabled) {
+			dev_dbg(labibb_reg->dev,
+				"%s has been disabled by SCP\n",
+				labibb_reg->desc.name);
+			scp_done = true;
+		}
+	}
+
+	if (in_sc_err || scp_done) {
+		regulator_lock(labibb_reg->rdev);
+		regulator_notifier_call_chain(labibb_reg->rdev,
+						REGULATOR_EVENT_OVER_CURRENT,
+						NULL);
+		regulator_unlock(labibb_reg->rdev);
+	}
+	return IRQ_HANDLED;
+}
+
 static struct regulator_dev *register_labibb_regulator(struct labibb_regulator *reg,
 				const struct labibb_regulator_data *reg_data,
 				struct device_node *of_node)
 {
 	struct regulator_config cfg = {};
-	int ret;
+	int ret, sc_irq;
 
 	reg->base = reg_data->base;
 	reg->type = reg_data->type;
@@ -95,6 +173,24 @@ static struct regulator_dev *register_labibb_regulator(struct labibb_regulator *
 	reg->desc.poll_enabled_time = LABIBB_POLL_ENABLED_TIME;
 	reg->desc.off_on_delay = LABIBB_OFF_ON_DELAY;
 
+	sc_irq = of_irq_get_byname(of_node, "sc-err");
+	if (sc_irq < 0) {
+		dev_err(reg->dev, "Unable to get sc-err, ret = %d\n",
+			sc_irq);
+		return ERR_PTR(sc_irq);
+	} else {
+		ret = devm_request_threaded_irq(reg->dev,
+						sc_irq,
+						NULL, labibb_sc_err_handler,
+						IRQF_ONESHOT,
+						"sc-err", reg);
+		if (ret) {
+			dev_err(reg->dev, "Failed to register sc-err irq ret=%d\n",
+				ret);
+			return ERR_PTR(ret);
+		}
+	}
+
 	cfg.dev = reg->dev;
 	cfg.driver_data = reg;
 	cfg.regmap = reg->regmap;
Signature · 1 line
2.26.2
maintainer
#19 lore raw

Re: [PATCH v4 5/5] regulator: qcom: labibb: Add SC interrupt handling

drivers/regulator/qcom-labibb-regulator.c static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev) · line 73

Quoted 9 lines · Sumit Semwal

static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) {

drivers/regulator/qcom-labibb-regulator.c +6 -1
-	return regulator_enable_regmap(rdev);
+	int ret;
+	struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+	ret = regulator_enable_regmap(rdev);
+	if (ret >= 0)
+		reg->enabled = true;

Can we not read the register we just wrote to here?

Quoted 8 lines
drivers/regulator/qcom-labibb-regulator.c +8 -0
+	/*
+	 * The SC(short circuit) fault would trigger PBS(Portable Batch
+	 * System) to disable regulators for protection. This would
+	 * cause the SC_DETECT status being cleared so that it's not
+	 * able to get the SC fault status.
+	 * Check if the regulator is enabled in the driver but
+	 * disabled in hardware, this means a SC fault had happened
+	 * and SCP handling is completed by PBS.

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 134

Quoted 10 lines
drivers/regulator/qcom-labibb-regulator.c +10 -0
+	 */
+	if (!in_sc_err) {
+
+		reg = labibb_reg->base + REG_LABIBB_ENABLE_CTL;
+
+		ret = regmap_read_poll_timeout(labibb_reg->regmap,
+					reg, val,
+					!(val & LABIBB_CONTROL_ENABLE),
+					POLLING_SCP_DONE_INTERVAL_US,
+					POLLING_SCP_TIMEOUT);

Why do we need a timeout here?

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 151

Quoted 4 lines
drivers/regulator/qcom-labibb-regulator.c +4 -0
+						NULL);
+		regulator_unlock(labibb_reg->rdev);
+	}
+	return IRQ_HANDLED;

This returns IRQ_HANDLED even if we didn't detect an interrupt source... Especially given the need to check to see if the regulator was turned off by the hardware it seems like there must be some false positives.

drivers/regulator/qcom-labibb-regulator.c static struct regulator_dev *register_labibb_regulator(struct labibb_regulator * · line 186

Quoted 6 lines
drivers/regulator/qcom-labibb-regulator.c +6 -0
+	} else {
+		ret = devm_request_threaded_irq(reg->dev,
+						sc_irq,
+						NULL, labibb_sc_err_handler,
+						IRQF_ONESHOT,
+						"sc-err", reg);

This looks like we're requesting the interrupt before we register the regulator which means the interrupt might fire without the regulator being there. The order of registration should be reversed.

#20 lore raw

Re: [PATCH v4 5/5] regulator: qcom: labibb: Add SC interrupt handling

Hi Mark,

Quoted 13 lines · Mark Brown

drivers/regulator/qcom-labibb-regulator.c static int qcom_labibb_regulator_is_enabled(struct regulator_dev *rdev) · line 73

Quoted 9 lines · Sumit Semwal

static int qcom_labibb_regulator_enable(struct regulator_dev *rdev) {

drivers/regulator/qcom-labibb-regulator.c +6 -1
-     return regulator_enable_regmap(rdev);
+     int ret;
+     struct labibb_regulator *reg = rdev_get_drvdata(rdev);
+
+     ret = regulator_enable_regmap(rdev);
+     if (ret >= 0)
+             reg->enabled = true;
Quoted 1 line

Can we not read the register we just wrote to here?

As I mentioned in the other patch, it seems there is a (noticeable) delay in getting the value to reflect in this register for IBB.

Also, from the notes from the downstream driver (also copied below), it seems like during short circuit there is another protection system that can cause the registers to be cleared, hence the need to track the current state in software.

Quoted 13 lines
Quoted 13 lines
drivers/regulator/qcom-labibb-regulator.c +12 -0
+     /*
+      * The SC(short circuit) fault would trigger PBS(Portable Batch
+      * System) to disable regulators for protection. This would
+      * cause the SC_DETECT status being cleared so that it's not
+      * able to get the SC fault status.
+      * Check if the regulator is enabled in the driver but
+      * disabled in hardware, this means a SC fault had happened
+      * and SCP handling is completed by PBS.
+      */
+     if (!in_sc_err) {
+
+             reg = labibb_reg->base + REG_LABIBB_ENABLE_CTL;
Quoted 8 lines

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 134

Quoted 6 lines
drivers/regulator/qcom-labibb-regulator.c +6 -0
+
+             ret = regmap_read_poll_timeout(labibb_reg->regmap,
+                                     reg, val,
+                                     !(val & LABIBB_CONTROL_ENABLE),
+                                     POLLING_SCP_DONE_INTERVAL_US,
+                                     POLLING_SCP_TIMEOUT);

Why do we need a timeout here?

IMHO, This seems to be the time required by the PBS to actually disable the regulator? If the PBS is not able to disable the regulator, then it points to a more serious problem?
I'm sorry, that's just my understanding based on the downstream driver :/ - not much input is available from the QC teams about it.

Quoted 9 lines

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 151

Quoted 5 lines
drivers/regulator/qcom-labibb-regulator.c +4 -0
+                                             NULL);
+             regulator_unlock(labibb_reg->rdev);
+     }
+     return IRQ_HANDLED;

This returns IRQ_HANDLED even if we didn't detect an interrupt source... Especially given the need to check to see if the regulator was turned off by the hardware it seems like there must be some false positives.

Right - I'm not sure what else can I do here.

Quoted 11 lines

drivers/regulator/qcom-labibb-regulator.c static struct regulator_dev *register_labibb_regulator(struct labibb_regulator * · line 186

Quoted 7 lines
drivers/regulator/qcom-labibb-regulator.c +6 -0
+     } else {
+             ret = devm_request_threaded_irq(reg->dev,
+                                             sc_irq,
+                                             NULL, labibb_sc_err_handler,
+                                             IRQF_ONESHOT,
+                                             "sc-err", reg);

This looks like we're requesting the interrupt before we register the regulator which means the interrupt might fire without the regulator being there. The order of registration should be reversed.

Agreed, and will update in the next version.

Best,
Sumit.

maintainer
#21 lore raw

Re: [PATCH v4 5/5] regulator: qcom: labibb: Add SC interrupt handling

Quoted 8 lines · Sumit Semwal
Quoted 6 lines · Mark Brown
Quoted 4 lines · Sumit Semwal
drivers/regulator/qcom-labibb-regulator.c +4 -0
+
+     ret = regulator_enable_regmap(rdev);
+     if (ret >= 0)
+             reg->enabled = true;
Quoted 4 lines
Quoted 1 line

Can we not read the register we just wrote to here?

As I mentioned in the other patch, it seems there is a (noticeable) delay in getting the value to reflect in this register for IBB.

This sounds like it may not actually have finished enabling fully?

Quoted 4 lines

Also, from the notes from the downstream driver (also copied below), it seems like during short circuit there is another protection system that can cause the registers to be cleared, hence the need to track the current state in software.

If the regulator has been disabled underneath us in a way that means it won't come back the driver should be reflecting that in the status it reports.

Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
drivers/regulator/qcom-labibb-regulator.c +7 -0
+      * Check if the regulator is enabled in the driver but
+      * disabled in hardware, this means a SC fault had happened
+      * and SCP handling is completed by PBS.
+      */
+     if (!in_sc_err) {
+
+             reg = labibb_reg->base + REG_LABIBB_ENABLE_CTL;
Quoted 8 lines

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 134

Quoted 6 lines
drivers/regulator/qcom-labibb-regulator.c +6 -0
+
+             ret = regmap_read_poll_timeout(labibb_reg->regmap,
+                                     reg, val,
+                                     !(val & LABIBB_CONTROL_ENABLE),
+                                     POLLING_SCP_DONE_INTERVAL_US,
+                                     POLLING_SCP_TIMEOUT);

Why do we need a timeout here?

Quoted 5 lines

IMHO, This seems to be the time required by the PBS to actually disable the regulator? If the PBS is not able to disable the regulator, then it points to a more serious problem?
I'm sorry, that's just my understanding based on the downstream driver :/ - not much input is available from the QC teams about it.

So it might generate an interrupt but then take a long time to take the actions associated with the interrupt that allow us to tell what the interrupt was about? That doesn't seem great. Do you know if this code has ever been exercised, the error handling code appears unusually involved here? Normally errors don't routinely occur in production.

Quoted 10 lines
Quoted 8 lines

drivers/regulator/qcom-labibb-regulator.c static struct regulator_ops qcom_labibb_ops = { · line 151

Quoted 4 lines
drivers/regulator/qcom-labibb-regulator.c +4 -0
+                                             NULL);
+             regulator_unlock(labibb_reg->rdev);
+     }
+     return IRQ_HANDLED;

This returns IRQ_HANDLED even if we didn't detect an interrupt source... Especially given the need to check to see if the regulator was turned off by the hardware it seems like there must be some false positives.

Right - I'm not sure what else can I do here.

Only return IRQ_HANDLED if we actually managed to figure out an error to report?