Skip to contentSkip to conversation

Add Qualcomm Technologies, Inc. PM8008 regulator driver

PATCH Superseded Satya Priya 4 participants 17 messages Sep 17, 2021 – Sep 28, 2021

Subsystems (6)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add Qualcomm Technologies, Inc. PM8008 regulator driver

Satya Priya (2):
dt-bindings: mfd: pm8008: Add pm8008-regulator binding
regulator: dt-bindings: Add pm8008 regulator bindings

satya priya (2):
regulator: Add a regulator driver for the PM8008 PMIC
arm64: dts: qcom: sc7280: Add pm8008 regulators support for sc7280-idp

 .../devicetree/bindings/mfd/qcom,pm8008.yaml       |  24 ++
 .../bindings/regulator/qcom,pm8008-regulator.yaml  |  76 ++++
 arch/arm64/boot/dts/qcom/sc7280-idp.dtsi           | 103 +++++
 drivers/regulator/Kconfig                          |   9 +
 drivers/regulator/Makefile                         |   1 +
 drivers/regulator/qcom-pm8008-regulator.c          | 441 +++++++++++++++++++++
 6 files changed, 654 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml
 create mode 100644 drivers/regulator/qcom-pm8008-regulator.c
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
#1 lore raw

PATCH 1/4 dt-bindings: mfd: pm8008: Add pm8008 regulator node

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +24 -0
index ec3138c..de182f8 100644
@@ -45,6 +45,10 @@ properties:
     const: 0
 
 patternProperties:
+  "^pm8008[a-z]?-regulator$":
+    type: object
+    $ref: "../regulator/qcom,pm8008-regulator.yaml#"
+
   "^gpio@[0-9a-f]+$":
     type: object
 
@@ -122,6 +126,26 @@ examples:
           interrupt-controller;
           #interrupt-cells = <2>;
         };
+
+        pm8008-regulator {
+          compatible = "qcom,pm8008-regulator";
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          vdd_l1_l2-supply = <&vreg_s8b_1p2>;
+          vdd_l3_l4-supply = <&vreg_s1b_1p8>;
+          vdd_l5-supply = <&vreg_bob>;
+          vdd_l6-supply = <&vreg_bob>;
+          vdd_l7-supply = <&vreg_bob>;
+
+          pm8008_l1: regulator@4000 {
+            reg = <0x4000>;
+            regulator-name = "pm8008_l1";
+            regulator-min-microvolt = <950000>;
+            regulator-max-microvolt = <1300000>;
+            qcom,min-dropout-voltage = <96000>;
+          };
+        };
       };
     };
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#2 lore raw

Re: [PATCH 1/4] dt-bindings: mfd: pm8008: Add pm8008 regulator node

Quoted 7 lines · Satya Priya

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Unknown file referenced: [Errno 2] No such file or directory: '/usr/local/lib/python3.8/dist-packages/dtschema/schemas/regulator/qcom,pm8008-regulator.yaml'
xargs: dt-doc-validate: exited with status 255; aborting
make[1]: *** Deleting file 'Documentation/devicetree/bindings/mfd/qcom,pm8008.example.dt.yaml'
Unknown file referenced: [Errno 2] No such file or directory: '/usr/local/lib/python3.8/dist-packages/dtschema/schemas/regulator/qcom,pm8008-regulator.yaml' make[1]: *** [scripts/Makefile.lib:385: Documentation/devicetree/bindings/mfd/qcom,pm8008.example.dt.yaml] Error 255
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1441: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1529335

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

maintainer
#3 lore raw

Re: [PATCH 1/4] dt-bindings: mfd: pm8008: Add pm8008 regulator node

In reply to Satya Priya
Quoted 12 lines · Satya Priya

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +0 -0
index ec3138c..de182f8 100644

Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml properties: · line 48

Quoted 4 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +1 -0
@@ -45,6 +45,10 @@ properties:
     const: 0
 
 patternProperties:
+  "^pm8008[a-z]?-regulator$":

Is more than 1 node possible for a given PMIC? If not use 'regulators' for the node name.

Quoted 38 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +23 -0
+    type: object
+    $ref: "../regulator/qcom,pm8008-regulator.yaml#"
+
   "^gpio@[0-9a-f]+$":
     type: object
 
@@ -122,6 +126,26 @@ examples:
           interrupt-controller;
           #interrupt-cells = <2>;
         };
+
+        pm8008-regulator {
+          compatible = "qcom,pm8008-regulator";
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          vdd_l1_l2-supply = <&vreg_s8b_1p2>;
+          vdd_l3_l4-supply = <&vreg_s1b_1p8>;
+          vdd_l5-supply = <&vreg_bob>;
+          vdd_l6-supply = <&vreg_bob>;
+          vdd_l7-supply = <&vreg_bob>;
+
+          pm8008_l1: regulator@4000 {
+            reg = <0x4000>;
+            regulator-name = "pm8008_l1";
+            regulator-min-microvolt = <950000>;
+            regulator-max-microvolt = <1300000>;
+            qcom,min-dropout-voltage = <96000>;
+          };
+        };
       };
     };
 
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
#4 lore raw

Re: [PATCH 1/4] dt-bindings: mfd: pm8008: Add pm8008 regulator node

Quoted 16 lines · Rob Herring
Quoted 15 lines · Satya Priya

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 
++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +0 -0
index ec3138c..de182f8 100644
@@ -45,6 +45,10 @@ properties:
     const: 0
 
Quoted 6 lines

Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml properties: · line 48

Quoted 2 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +1 -0
 patternProperties:
+  "^pm8008[a-z]?-regulator$":

Is more than 1 node possible for a given PMIC? If not use 'regulators' for the node name.

Not possible, will change the node name.

Quoted 38 lines
Quoted 38 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +23 -1
+    type: object
+    $ref: "../regulator/qcom,pm8008-regulator.yaml#"
+
   "^gpio@[0-9a-f]+$":
     type: object
 
@@ -122,6 +126,26 @@ examples:
           interrupt-controller;
           #interrupt-cells = <2>;
         };
+
+        pm8008-regulator {
+          compatible = "qcom,pm8008-regulator";
+          #address-cells = <1>;
+          #size-cells = <0>;
+
+          vdd_l1_l2-supply = <&vreg_s8b_1p2>;
+          vdd_l3_l4-supply = <&vreg_s1b_1p8>;
+          vdd_l5-supply = <&vreg_bob>;
+          vdd_l6-supply = <&vreg_bob>;
+          vdd_l7-supply = <&vreg_bob>;
+
+          pm8008_l1: regulator@4000 {
+            reg = <0x4000>;
+            regulator-name = "pm8008_l1";
+            regulator-min-microvolt = <950000>;
+            regulator-max-microvolt = <1300000>;
+            qcom,min-dropout-voltage = <96000>;
+          };
+        };
       };
     };
 
--

QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, hosted by The Linux Foundation

#5 lore raw

Re: [PATCH 1/4] dt-bindings: mfd: pm8008: Add pm8008 regulator node

In reply to Satya Priya

Quoting Satya Priya (2021-09-17 03:45:35)

Quoted 12 lines

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +0 -0
index ec3138c..de182f8 100644

Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml properties: · line 48

Quoted 4 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +1 -0
@@ -45,6 +45,10 @@ properties:
     const: 0
 
 patternProperties:
+  "^pm8008[a-z]?-regulator$":

Shouldn't it be ^pm8008-regulator$ without the a-z optional letter?

Quoted 6 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +3 -0
+    type: object
+    $ref: "../regulator/qcom,pm8008-regulator.yaml#"
+
   "^gpio@[0-9a-f]+$":
     type: object
 
#6 lore raw

Re: [PATCH 1/4] dt-bindings: mfd: pm8008: Add pm8008 regulator node

Quoted 16 lines · Stephen Boyd

Quoting Satya Priya (2021-09-17 03:45:35)

Quoted 15 lines

Add pm8008-regulator node and example.

---
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       | 24 
++++++++++++++++++++++
 1 file changed, 24 insertions(+)
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +0 -0
index ec3138c..de182f8 100644
@@ -45,6 +45,10 @@ properties:
     const: 0
 
Quoted 5 lines

Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml properties: · line 48

Quoted 2 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +1 -0
 patternProperties:
+  "^pm8008[a-z]?-regulator$":

Shouldn't it be ^pm8008-regulator$ without the a-z optional letter?

Some platforms use 2 PM8008 PMICS, in that case we need suffixing like pm8008i pm8008j etc. So, I mentioned this way.

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/mfd/qcom,pm8008.yaml +3 -0
+    type: object
+    $ref: "../regulator/qcom,pm8008-regulator.yaml#"
+
   "^gpio@[0-9a-f]+$":
     type: object
 
#7 lore raw

PATCH 2/4 regulator: dt-bindings: Add pm8008 regulator bindings

In reply to Satya Priya

Add bindings for pm8008 pmic regulators.

---
 .../bindings/regulator/qcom,pm8008-regulator.yaml  | 76 ++++++++++++++++++++++
 1 file changed, 76 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml new file +76 -0
new file mode 100644
index 0000000..59518c4
@@ -0,0 +1,76 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/qcom,pm8008-regulator.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Technologies, Inc. PM8008 Regulator bindings
+
+maintainers:
+  - Satya Priya <[email protected]>
+
+description:
+  Qualcomm Technologies, Inc. PM8008 is an I2C controlled PMIC
+  containing 7 LDO regulators.
+
+properties:
+  compatible:
+    const: qcom,pm8008-regulator
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  vdd_l1_l2-supply:
+    description: Input supply phandle of ldo1 and ldo2 regulators.
+
+  vdd_l3_l4-supply:
+    description: Input supply phandle of ldo3 and ldo4 regulators.
+
+  vdd_l5-supply:
+    description: Input supply phandle of ldo5 regulator.
+
+  vdd_l6-supply:
+    description: Input supply phandle of ldo6 regulator.
+
+  vdd_l7-supply:
+    description: Input supply phandle of ldo7 regulator.
+
+patternProperties:
+  "^regulator@[0-9a-f]+$":
+    type: object
+
+    $ref: "regulator.yaml#"
+
+    description: PM8008 regulator peripherals of PM8008 regulator device
+
+    properties:
+      reg:
+        maxItems: 1
+      regulator-name: true
+      regulator-min-microvolt: true
+      regulator-max-microvolt: true
+      qcom,min-dropout-voltage:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Specifies the minimum voltage in microvolts that the parent
+          supply regulator must output, above the output of this
+          regulator.
+
+    required:
+      - reg
+      - regulator-name
+      - regulator-min-microvolt
+      - regulator-max-microvolt
+
+    additionalProperties: false
+
+required:
+  - compatible
+  - "#address-cells"
+  - "#size-cells"
+
+additionalProperties: false
+...
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#8 lore raw

Re: [PATCH 2/4] regulator: dt-bindings: Add pm8008 regulator bindings

Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml line 54

Quoted 6 lines · Satya Priya
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml new file +6 -0
+    properties:
+      reg:
+        maxItems: 1
+      regulator-name: true
+      regulator-min-microvolt: true
+      regulator-max-microvolt: true

You shouldn't be forcing these properties, it should be perfectly OK for boards to have fixed voltages especially for example during bringup or for debugging.

Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml line 60

Quoted 6 lines
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml new file +6 -0
+      qcom,min-dropout-voltage:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Specifies the minimum voltage in microvolts that the parent
+          supply regulator must output, above the output of this
+          regulator.

If this is needed in DT it should be a generic property since most regulators have some requirement here however usually it's a fixed property of the silicon and should therefore just gets set in the regulator_desc as min_dropout_uV - I'd strongly recommend having a default there even if there's some requirement for it to be set per board.

#9 lore raw

Re: [PATCH 2/4] regulator: dt-bindings: Add pm8008 regulator bindings

Quoted 9 lines · Mark Brown

Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml line 54

Quoted 6 lines · Satya Priya
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml new file +6 -0
+    properties:
+      reg:
+        maxItems: 1
+      regulator-name: true
+      regulator-min-microvolt: true
+      regulator-max-microvolt: true
Quoted 4 lines

You shouldn't be forcing these properties, it should be perfectly OK for boards to have fixed voltages especially for example during bringup or for debugging.

Okay. I will remove these.

Quoted 7 lines

Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml line 60

Quoted 6 lines
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml new file +6 -0
+      qcom,min-dropout-voltage:
+        $ref: /schemas/types.yaml#/definitions/uint32
+        description:
+          Specifies the minimum voltage in microvolts that the parent
+          supply regulator must output, above the output of this
+          regulator.
Quoted 6 lines

If this is needed in DT it should be a generic property since most regulators have some requirement here however usually it's a fixed property of the silicon and should therefore just gets set in the regulator_desc as min_dropout_uV - I'd strongly recommend having a default there even if there's some requirement for it to be set per board.

Yeah, we are setting the default values for this(headroom_uv) from driver. Please see below

struct regulator_data {
     char        *name;
     char        *supply_name;
     int     min_uv;
     int     max_uv;
     int     min_dropout_uv;
};
static const struct regulator_data reg_data[PM8008_MAX_LDO] = {
     /* name  parent      min_uv  max_uv  headroom_uv */
    {"l1", "vdd_l1_l2",  528000, 1504000, 225000},
    {"l2", "vdd_l1_l2",  528000, 1504000, 225000},
    {"l3", "vdd_l3_l4", 1504000, 3400000, 200000},
    {"l4", "vdd_l3_l4", 1504000, 3400000, 200000},
    {"l5", "vdd_l5",    1504000, 3400000, 300000},
    {"l6", "vdd_l6",    1504000, 3400000, 300000},
    {"l7", "vdd_l7",    1504000, 3400000, 300000},
};

Inside Register LDO API:

pm8008_reg->rdesc.min_dropout_uV = reg_data[i].min_dropout_uv; of_property_read_u32(reg_node, "qcom,min-dropout-voltage",

                  &pm8008_reg->rdesc.min_dropout_uV);
#10 lore raw

PATCH 3/4 regulator: Add a regulator driver for the PM8008 PMIC

In reply to Satya Priya

From: satya priya <[email protected]>

Qualcomm Technologies, Inc. PM8008 is an I2C controlled PMIC containing 7 LDO regulators. Add a PM8008 regulator driver to support PMIC regulator management via the regulator framework.

---
 drivers/regulator/Kconfig                 |   9 +
 drivers/regulator/Makefile                |   1 +
 drivers/regulator/qcom-pm8008-regulator.c | 441 ++++++++++++++++++++++++++++++
 3 files changed, 451 insertions(+)
 create mode 100644 drivers/regulator/qcom-pm8008-regulator.c
drivers/regulator/Kconfig +9 -0
index e35cca5..888ce30 100644
@@ -916,6 +916,15 @@ config REGULATOR_PWM
 	  This driver supports PWM controlled voltage regulators. PWM
 	  duty cycle can increase or decrease the voltage.
 
+config REGULATOR_QCOM_PM8008
+	tristate "Qualcomm Technologies, Inc. PM8008 PMIC regulators"
+	depends on MFD_QCOM_PM8008
+	help
+	  Select this option to get support for the voltage regulators
+	  of Qualcomm Technologies, Inc. PM8008 PMIC chip. PM8008 has 7 LDO
+	  regulators. This driver provides support for basic operations like
+	  set/get voltage and enable/disable.
+
 config REGULATOR_QCOM_RPM
 	tristate "Qualcomm RPM regulator driver"
 	depends on MFD_QCOM_RPM
drivers/regulator/Makefile +1 -0
index 9e382b5..5e935ff 100644
@@ -100,6 +100,7 @@ obj-$(CONFIG_REGULATOR_MT6380)	+= mt6380-regulator.o
 obj-$(CONFIG_REGULATOR_MT6397)	+= mt6397-regulator.o
 obj-$(CONFIG_REGULATOR_MTK_DVFSRC) += mtk-dvfsrc-regulator.o
 obj-$(CONFIG_REGULATOR_QCOM_LABIBB) += qcom-labibb-regulator.o
+obj-$(CONFIG_REGULATOR_QCOM_PM8008) += qcom-pm8008-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-pm8008-regulator.c new file +441 -0

441 lines not on this page · raw message

Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
maintainer
#11 lore raw

Re: [PATCH 3/4] regulator: Add a regulator driver for the PM8008 PMIC

Quoted 5 lines · Satya Priya
drivers/regulator/qcom-pm8008-regulator.c new file +5 -0
+static int pm8008_regulator_is_enabled(struct regulator_dev *rdev)
+{
+	struct pm8008_regulator *pm8008_reg = rdev_get_drvdata(rdev);
+	int rc;
+	u8 reg;

drivers/regulator/qcom-pm8008-regulator.c line 134

Quoted 10 lines
drivers/regulator/qcom-pm8008-regulator.c new file +10 -0
+
+	rc = pm8008_read(pm8008_reg->regmap,
+			LDO_ENABLE_REG(pm8008_reg->base), &reg, 1);
+	if (rc < 0) {
+		pr_err("failed to read enable reg rc=%d\n", rc);
+		return rc;
+	}
+
+	return !!(reg & ENABLE_BIT);
+}

This could just be regulator_is_enabled_regmap(). There's also a lot of instances in the driver where it's using pr_err() not dev_err() (and similarly for the debug prints).

drivers/regulator/qcom-pm8008-regulator.c line 140

Quoted 6 lines
drivers/regulator/qcom-pm8008-regulator.c new file +6 -0
+
+static int pm8008_regulator_enable(struct regulator_dev *rdev)
+{
+	struct pm8008_regulator *pm8008_reg = rdev_get_drvdata(rdev);
+	int rc, current_uv, delay_us, delay_ms, retry_count = 10;
+	u8 reg;

This is the regmap helper.

drivers/regulator/qcom-pm8008-regulator.c line 162

Quoted 7 lines
drivers/regulator/qcom-pm8008-regulator.c new file +7 -0
+	/*
+	 * Wait for the VREG_READY status bit to be set using a timeout delay
+	 * calculated from the current commanded voltage.
+	 */
+	delay_us = STARTUP_DELAY_USEC
+			+ DIV_ROUND_UP(current_uv, pm8008_reg->step_rate);
+	delay_ms = DIV_ROUND_UP(delay_us, 1000);

Set poll_enable_time and implement get_status() then this will be handled by the core.

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int pm8008_regulator_disable(struct regulator_dev *rdev)
+{

Use the regmap helper.

drivers/regulator/qcom-pm8008-regulator.c line 257

Quoted 3 lines
drivers/regulator/qcom-pm8008-regulator.c new file +3 -0
+	rc = pm8008_write_voltage(pm8008_reg, min_uv, max_uv);
+	if (rc < 0)
+		return rc;

This is the only place where write_voltage() is called, may as well just inline it.

drivers/regulator/qcom-pm8008-regulator.c line 305

Quoted 2 lines
drivers/regulator/qcom-pm8008-regulator.c new file +2 -0
+	init_voltage = -EINVAL;
+	of_property_read_u32(reg_node, "qcom,init-voltage", &init_voltage);

Why does this property exist and if it's needed why is it specific to this device? It looks like the device allows you to read the voltage on startup from the regmap.

drivers/regulator/qcom-pm8008-regulator.c line 326

Quoted 10 lines
drivers/regulator/qcom-pm8008-regulator.c new file +10 -0
+	init_data = of_get_regulator_init_data(dev, reg_node,
+						&pm8008_reg->rdesc);
+	if (init_data == NULL) {
+		dev_err(dev, "%s: failed to get regulator data\n", name);
+		return -ENODATA;
+	}
+	if (!init_data->constraints.name) {
+		dev_err(dev, "%s: regulator name missing\n", name);
+		return -EINVAL;
+	}

Just let the core find the init data for you, there is no reason to insist on a system provided name - that is an entirely optional property for systems to use, there is no reason for a regulator driver to care.

drivers/regulator/qcom-pm8008-regulator.c line 339

Quoted 3 lines
drivers/regulator/qcom-pm8008-regulator.c new file +3 -0
+	init_data->constraints.input_uV = init_data->constraints.max_uV;
+	init_data->constraints.valid_ops_mask |= REGULATOR_CHANGE_STATUS
+						| REGULATOR_CHANGE_VOLTAGE;

This is absolutely not something that a regulator driver should be doing, the whole point with constraints is that they come from the machine.

drivers/regulator/qcom-pm8008-regulator.c line 383

Quoted 11 lines
drivers/regulator/qcom-pm8008-regulator.c new file +11 -0
+static int pm8008_parse_regulator(struct regmap *regmap, struct device *dev)
+{
+	int rc = 0;
+	const char *name;
+	struct device_node *child;
+	struct pm8008_regulator *pm8008_reg;
+
+	/* parse each subnode and register regulator for regulator child */
+	for_each_available_child_of_node(dev->of_node, child) {
+		pm8008_reg = devm_kzalloc(dev, sizeof(*pm8008_reg), GFP_KERNEL);
+		if (!pm8008_reg)

You shouldn't be doing this, just unconditionally register all the regulators supported by the chip. If they don't appear in the DT that's totally fine - it gives read only access which can be useful for diagnostics.

#12 lore raw

Re: [PATCH 3/4] regulator: Add a regulator driver for the PM8008 PMIC

Hi Mark,

Thanks for reviewing the changes!

Quoted 13 lines · Mark Brown
Quoted 11 lines · Satya Priya
drivers/regulator/qcom-pm8008-regulator.c new file +11 -0
+static int pm8008_regulator_is_enabled(struct regulator_dev *rdev)
+{
+	struct pm8008_regulator *pm8008_reg = rdev_get_drvdata(rdev);
+	int rc;
+	u8 reg;
+
+	rc = pm8008_read(pm8008_reg->regmap,
+			LDO_ENABLE_REG(pm8008_reg->base), &reg, 1);
+	if (rc < 0) {
+		pr_err("failed to read enable reg rc=%d\n", rc);
+		return rc;
Quoted 9 lines

drivers/regulator/qcom-pm8008-regulator.c line 134

Quoted 4 lines
drivers/regulator/qcom-pm8008-regulator.c new file +4 -0
+	}
+
+	return !!(reg & ENABLE_BIT);
+}

This could just be regulator_is_enabled_regmap(). There's also a lot of instances in the driver where it's using pr_err() not dev_err() (and similarly for the debug prints).

Okay, I'll use the helper regulator_is_enabled_regmap() here and remove this completely.

Quoted 9 lines

drivers/regulator/qcom-pm8008-regulator.c line 140

Quoted 6 lines
drivers/regulator/qcom-pm8008-regulator.c new file +6 -0
+
+static int pm8008_regulator_enable(struct regulator_dev *rdev)
+{
+	struct pm8008_regulator *pm8008_reg = rdev_get_drvdata(rdev);
+	int rc, current_uv, delay_us, delay_ms, retry_count = 10;
+	u8 reg;

This is the regmap helper.

Okay, I'll use regulator_enable_regmap().

Quoted 12 lines

drivers/regulator/qcom-pm8008-regulator.c line 162

Quoted 8 lines
(quoted diff) +2 -0
+	/*
+	 * Wait for the VREG_READY status bit to be set using a timeout 

delay

drivers/regulator/qcom-pm8008-regulator.c new file +5 -0
+	 * calculated from the current commanded voltage.
+	 */
+	delay_us = STARTUP_DELAY_USEC
+			+ DIV_ROUND_UP(current_uv, pm8008_reg->step_rate);
+	delay_ms = DIV_ROUND_UP(delay_us, 1000);

Set poll_enable_time and implement get_status() then this will be handled by the core.

Anyway I will be removing this API.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+static int pm8008_regulator_disable(struct regulator_dev *rdev)
+{

Use the regmap helper.

Ok, I'll use regulator_disable_regmap.

Quoted 7 lines

drivers/regulator/qcom-pm8008-regulator.c line 257

Quoted 3 lines
drivers/regulator/qcom-pm8008-regulator.c new file +3 -0
+	rc = pm8008_write_voltage(pm8008_reg, min_uv, max_uv);
+	if (rc < 0)
+		return rc;

This is the only place where write_voltage() is called, may as well just inline it.

Okay.

Quoted 7 lines

drivers/regulator/qcom-pm8008-regulator.c line 305

Quoted 2 lines
drivers/regulator/qcom-pm8008-regulator.c new file +2 -0
+	init_voltage = -EINVAL;
+	of_property_read_u32(reg_node, "qcom,init-voltage", &init_voltage);

Why does this property exist and if it's needed why is it specific to this device? It looks like the device allows you to read the voltage on startup from the regmap.

I think it is not necessary, will remove it.

Quoted 6 lines
Quoted 6 lines
drivers/regulator/qcom-pm8008-regulator.c new file +6 -0
+	init_data = of_get_regulator_init_data(dev, reg_node,
+						&pm8008_reg->rdesc);
+	if (init_data == NULL) {
+		dev_err(dev, "%s: failed to get regulator data\n", name);
+		return -ENODATA;
+	}
Quoted 9 lines

drivers/regulator/qcom-pm8008-regulator.c line 326

Quoted 4 lines
drivers/regulator/qcom-pm8008-regulator.c new file +4 -0
+	if (!init_data->constraints.name) {
+		dev_err(dev, "%s: regulator name missing\n", name);
+		return -EINVAL;
+	}

Just let the core find the init data for you, there is no reason to insist on a system provided name - that is an entirely optional property for systems to use, there is no reason for a regulator driver to care.

OK, I will remove this if check.

Quoted 8 lines

drivers/regulator/qcom-pm8008-regulator.c line 339

Quoted 3 lines
drivers/regulator/qcom-pm8008-regulator.c new file +3 -0
+	init_data->constraints.input_uV = init_data->constraints.max_uV;
+	init_data->constraints.valid_ops_mask |= REGULATOR_CHANGE_STATUS
+						| REGULATOR_CHANGE_VOLTAGE;

This is absolutely not something that a regulator driver should be doing, the whole point with constraints is that they come from the machine.

Okay I will remove this.

Quoted 9 lines
Quoted 9 lines

+static int pm8008_parse_regulator(struct regmap *regmap, struct device *dev)

drivers/regulator/qcom-pm8008-regulator.c new file +7 -0
+{
+	int rc = 0;
+	const char *name;
+	struct device_node *child;
+	struct pm8008_regulator *pm8008_reg;
+
+	/* parse each subnode and register regulator for regulator child */
Quoted 8 lines

drivers/regulator/qcom-pm8008-regulator.c line 383

Quoted 3 lines
drivers/regulator/qcom-pm8008-regulator.c new file +3 -0
+	for_each_available_child_of_node(dev->of_node, child) {
+		pm8008_reg = devm_kzalloc(dev, sizeof(*pm8008_reg), GFP_KERNEL);
+		if (!pm8008_reg)

You shouldn't be doing this, just unconditionally register all the regulators supported by the chip. If they don't appear in the DT that's totally fine - it gives read only access which can be useful for diagnostics.

Okay will remove this check as well.

-Satya Priya.

#13 lore raw

PATCH 4/4 arm64: dts: qcom: sc7280: Add pm8008 regulators support for sc7280-idp

In reply to Satya Priya

From: satya priya <[email protected]>

Add pm8008 regulators support for sc7280 idp.

---
 arch/arm64/boot/dts/qcom/sc7280-idp.dtsi | 103 +++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +103 -0
index 52638e2..3b3af49 100644
@@ -207,6 +207,97 @@
 	};
 };
 
+&i2c1 {
+	#address-cells = <1>;
+	#size-cells = <0>;
+	status = "okay";
+
+	pm8008_chip: pm8008@8 {
+		compatible = "qcom,pm8008";
+		reg = <0x8>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		pinctrl-names = "default";
+		pinctrl-0 = <&pm8008_active>;
+	};
+
+	pm8008_ldo: pm8008@9 {
+		compatible = "qcom,pm8008";
+		reg = <0x9>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		pm8008-regulator {
+			compatible = "qcom,pm8008-regulator";
+			#address-cells = <1>;
+			#size-cells = <0>;
+
+			vdd_l1_l2-supply = <&vreg_s8b_1p2>;
+			vdd_l3_l4-supply = <&vreg_s1b_1p8>;
+			vdd_l5-supply = <&vreg_bob>;
+			vdd_l6-supply = <&vreg_bob>;
+			vdd_l7-supply = <&vreg_bob>;
+
+			pm8008_l1: regulator@4000 {
+				reg = <0x4000>;
+				regulator-name = "pm8008_l1";
+				regulator-min-microvolt = <950000>;
+				regulator-max-microvolt = <1300000>;
+				qcom,min-dropout-voltage = <96000>;
+			};
+
+			pm8008_l2: regulator@4100 {
+				reg = <0x4100>;
+				regulator-name = "pm8008_l2";
+				regulator-min-microvolt = <950000>;
+				regulator-max-microvolt = <1250000>;
+				qcom,min-dropout-voltage = <24000>;
+			};
+
+			pm8008_l3: regulator@4200 {
+				reg = <0x4200>;
+				regulator-name = "pm8008_l3";
+				regulator-min-microvolt = <1650000>;
+				regulator-max-microvolt = <3000000>;
+				qcom,min-dropout-voltage = <224000>;
+			};
+
+			pm8008_l4: regulator@4300 {
+				reg = <0x4300>;
+				regulator-name = "pm8008_l4";
+				regulator-min-microvolt = <1504000>;
+				regulator-max-microvolt = <1600000>;
+				qcom,min-dropout-voltage = <0>;
+			};
+
+			pm8008_l5: regulator@4400 {
+				reg = <0x4400>;
+				regulator-name = "pm8008_l5";
+				regulator-min-microvolt = <2600000>;
+				regulator-max-microvolt = <3000000>;
+				qcom,min-dropout-voltage = <104000>;
+			};
+
+			pm8008_l6: regulator@4500 {
+				reg = <0x4500>;
+				regulator-name = "pm8008_l6";
+				regulator-min-microvolt = <2600000>;
+				regulator-max-microvolt = <3000000>;
+				qcom,min-dropout-voltage = <112000>;
+			};
+
+			pm8008_l7: regulator@4600 {
+				reg = <0x4600>;
+				regulator-name = "pm8008_l7";
+				regulator-min-microvolt = <3000000>;
+				regulator-max-microvolt = <3544000>;
+				qcom,min-dropout-voltage = <96000>;
+			};
+		};
+	};
+};
+
 &qfprom {
 	vcc-supply = <&vreg_l1c_1p8>;
 };
@@ -313,6 +404,18 @@
 
 /* PINCTRL - additions to nodes defined in sc7280.dtsi */
 
+&pm8350c_gpios {
+	pm8008_reset {
+		pm8008_active: pm8008_active {
+			pins = "gpio4";
+			function = "normal";
+			bias-disable;
+			output-high;
+			power-source = <0>;
+		};
+	};
+};
+
 &qspi_cs0 {
 	bias-disable;
 };
Signature · 2 lines
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a member 
of Code Aurora Forum, hosted by The Linux Foundation
#14 lore raw

Re: [PATCH 4/4] arm64: dts: qcom: sc7280: Add pm8008 regulators support for sc7280-idp

Quoting Satya Priya (2021-09-17 03:45:38)

Quoted 24 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +16 -0
index 52638e2..3b3af49 100644
@@ -207,6 +207,97 @@
        };
 };
 
+&i2c1 {
+       #address-cells = <1>;
+       #size-cells = <0>;
+       status = "okay";
+
+       pm8008_chip: pm8008@8 {
+               compatible = "qcom,pm8008";
+               reg = <0x8>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               pinctrl-names = "default";
+               pinctrl-0 = <&pm8008_active>;
+       };
+
+       pm8008_ldo: pm8008@9 {

[...]

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 295

Quoted 7 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +7 -0
+
+                       pm8008_l7: regulator@4600 {
+                               reg = <0x4600>;
+                               regulator-name = "pm8008_l7";
+                               regulator-min-microvolt = <3000000>;
+                               regulator-max-microvolt = <3544000>;
+                               qcom,min-dropout-voltage = <96000>;

Is this headroom? Is it actually configurable or is it merely a property of the hardware? If it's the latter then it should be in the driver and not in the DTS.

Quoted 9 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +5 -0
+                       };
+               };
+       };
+};
+
 &qfprom {
        vcc-supply = <&vreg_l1c_1p8>;
 };

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 408

Quoted 5 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +2 -0
@@ -313,6 +404,18 @@
 
 /* PINCTRL - additions to nodes defined in sc7280.dtsi */
 
+&pm8350c_gpios {
+       pm8008_reset {

Is this a pinctrl node?

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 409

Quoted 1 line
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +1 -0
+               pm8008_active: pm8008_active {

Please use dashes in node names wherever an underscore goes.

Quoted 8 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +8 -0
+                       pins = "gpio4";
+                       function = "normal";
+                       bias-disable;
+                       output-high;
+                       power-source = <0>;
+               };
+       };
+};
#15 lore raw

Re: [PATCH 4/4] arm64: dts: qcom: sc7280: Add pm8008 regulators support for sc7280-idp

Quoted 34 lines · Stephen Boyd

Quoting Satya Priya (2021-09-17 03:45:38)

Quoted 24 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +16 -0
index 52638e2..3b3af49 100644
@@ -207,6 +207,97 @@
        };
 };
 
+&i2c1 {
+       #address-cells = <1>;
+       #size-cells = <0>;
+       status = "okay";
+
+       pm8008_chip: pm8008@8 {
+               compatible = "qcom,pm8008";
+               reg = <0x8>;
+               #address-cells = <1>;
+               #size-cells = <0>;
+
+               pinctrl-names = "default";
+               pinctrl-0 = <&pm8008_active>;
+       };
+
+       pm8008_ldo: pm8008@9 {

[...]

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 295

Quoted 7 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +7 -0
+
+                       pm8008_l7: regulator@4600 {
+                               reg = <0x4600>;
+                               regulator-name = "pm8008_l7";
+                               regulator-min-microvolt = <3000000>;
+                               regulator-max-microvolt = <3544000>;
+                               qcom,min-dropout-voltage = <96000>;
Quoted 4 lines

Is this headroom? Is it actually configurable or is it merely a property of the hardware? If it's the latter then it should be in the driver and not in the DTS.

Yes this is a headroom and its configurable.

Quoted 10 lines
Quoted 10 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +5 -0
+                       };
+               };
+       };
+};
+
 &qfprom {
        vcc-supply = <&vreg_l1c_1p8>;
 };
@@ -313,6 +404,18 @@
 
Quoted 7 lines

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 408

Quoted 4 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +2 -0
 /* PINCTRL - additions to nodes defined in sc7280.dtsi */
 
+&pm8350c_gpios {
+       pm8008_reset {

Is this a pinctrl node?

No.

Quoted 4 lines

arch/arm64/boot/dts/qcom/sc7280-idp.dtsi line 409

Quoted 1 line
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +1 -0
+               pm8008_active: pm8008_active {

Please use dashes in node names wherever an underscore goes.

Okay.

Quoted 8 lines
Quoted 8 lines
arch/arm64/boot/dts/qcom/sc7280-idp.dtsi +8 -0
+                       pins = "gpio4";
+                       function = "normal";
+                       bias-disable;
+                       output-high;
+                       power-source = <0>;
+               };
+       };
+};
#16 lore raw
In reply to Satya Priya
Quoted 8 lines · Satya Priya

Satya Priya (2):
dt-bindings: mfd: pm8008: Add pm8008-regulator binding
regulator: dt-bindings: Add pm8008 regulator bindings

satya priya (2):
regulator: Add a regulator driver for the PM8008 PMIC
arm64: dts: qcom: sc7280: Add pm8008 regulators support for
sc7280-idp

This dt change depends on [1] which adds i2c1 DT node
[1] https://patchwork.kernel.org/project/linux-arm-msm/patch/[email protected]/

Quoted 11 lines
 .../devicetree/bindings/mfd/qcom,pm8008.yaml       |  24 ++
 .../bindings/regulator/qcom,pm8008-regulator.yaml  |  76 ++++
 arch/arm64/boot/dts/qcom/sc7280-idp.dtsi           | 103 +++++
 drivers/regulator/Kconfig                          |   9 +
 drivers/regulator/Makefile                         |   1 +
 drivers/regulator/qcom-pm8008-regulator.c          | 441 
+++++++++++++++++++++
 6 files changed, 654 insertions(+)
 create mode 100644
Documentation/devicetree/bindings/regulator/qcom,pm8008-regulator.yaml
 create mode 100644 drivers/regulator/qcom-pm8008-regulator.c