linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs
@ 2022-08-01  4:47 Samuel Holland
  2022-08-01  4:47 ` [PATCH 2/2] regulator: sun20i: Add support for " Samuel Holland
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Samuel Holland @ 2022-08-01  4:47 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Chen-Yu Tsai, Jernej Skrabec,
	Krzysztof Kozlowski, Rob Herring
  Cc: Samuel Holland, devicetree, linux-arm-kernel, linux-kernel, linux-sunxi

The Allwinner D1 SoC contains two pairs of in-package LDOs. One pair is
for general purpose use. LDOA generally powers the board's 1.8 V rail.
LDOB generally powers the in-package DRAM, where applicable.

The other pair of LDOs powers the analog power domains inside the SoC,
including the audio codec, thermal sensor, and ADCs. These LDOs require
a 0.9 V bandgap voltage reference. The calibration value for the voltage
reference is stored in an eFuse, accessed via an NVMEM cell.

Neither LDO control register is in its own MMIO range; instead, each
regulator device relies on a syscon exported by some "host" device node.
Getting the register via a syscon avoids a dependency on the subsystem/
driver for that host device (e.g. a functioning thermal sensor should
not depend on having the audio codec driver loaded).

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 .../allwinner,sun20i-d1-analog-ldos.yaml      | 77 +++++++++++++++++++
 .../allwinner,sun20i-d1-system-ldos.yaml      | 55 +++++++++++++
 2 files changed, 132 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
 create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml

diff --git a/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
new file mode 100644
index 000000000000..df648c56123d
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
@@ -0,0 +1,77 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/allwinner,sun20i-d1-analog-ldos.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Allwinner D1 Analog LDOs
+
+description:
+  Allwinner D1 contains a set of LDOs which are designed to supply analog power
+  inside and outside the SoC. They are controlled by a register within the audio
+  codec MMIO space, but which is not part of the audio codec clock/reset domain,
+  and so is exposed as a syscon.
+
+maintainers:
+  - Samuel Holland <samuel@sholland.org>
+
+properties:
+  compatible:
+    enum:
+      - allwinner,sun20i-d1-analog-ldos
+
+  nvmem-cells:
+    items:
+      - description: NVMEM cell for the calibrated bandgap reference trim value
+
+  nvmem-cell-names:
+    items:
+      - const: bg_trim
+
+  syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of the device containing the power register
+
+patternProperties:
+  "^(aldo|hpldo)$":
+    type: object
+    $ref: regulator.yaml#
+
+required:
+  - compatible
+  - nvmem-cells
+  - nvmem-cell-names
+  - syscon
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    sid: efuse {
+        #address-cells = <1>;
+        #size-cells = <1>;
+
+        bg_trim: bg-trim@28 {
+            reg = <0x28 0x4>;
+            bits = <16, 8>;
+        };
+    };
+
+    ldos-analog {
+        compatible = "allwinner,sun20i-d1-analog-ldos";
+        nvmem-cells = <&bg_trim>;
+        nvmem-cell-names = "bg_trim";
+        syscon = <&codec>;
+
+        reg_aldo: aldo {
+            regulator-min-microvolt = <1800000>;
+            regulator-max-microvolt = <1800000>;
+        };
+
+        reg_hpldo: hpldo {
+            regulator-min-microvolt = <1800000>;
+            regulator-max-microvolt = <1800000>;
+        };
+    };
+
+...
diff --git a/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
new file mode 100644
index 000000000000..13b2e8c84f1d
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
@@ -0,0 +1,55 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/allwinner,sun20i-d1-system-ldos.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Allwinner D1 System LDOs
+
+description:
+  Allwinner D1 contains a pair of general-purpose LDOs which are designed to
+  supply power inside and outside the SoC. They are controlled by a register
+  within the system controller MMIO space.
+
+maintainers:
+  - Samuel Holland <samuel@sholland.org>
+
+properties:
+  compatible:
+    enum:
+      - allwinner,sun20i-d1-system-ldos
+
+  syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of the device containing the LDO control register
+
+patternProperties:
+  "^(ldoa|ldob)$":
+    type: object
+    $ref: regulator.yaml#
+
+required:
+  - compatible
+  - syscon
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ldos-system {
+        compatible = "allwinner,sun20i-d1-system-ldos";
+        syscon = <&syscon>;
+
+        reg_ldoa: ldoa {
+            regulator-min-microvolt = <1800000>;
+            regulator-max-microvolt = <1800000>;
+        };
+
+        reg_ldob: ldob {
+            regulator-name = "vcc-dram";
+            regulator-min-microvolt = <1500000>;
+            regulator-max-microvolt = <1500000>;
+        };
+    };
+
+...
-- 
2.35.1


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

* [PATCH 2/2] regulator: sun20i: Add support for Allwinner D1 LDOs
  2022-08-01  4:47 [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs Samuel Holland
@ 2022-08-01  4:47 ` Samuel Holland
  2022-08-01 16:03   ` Mark Brown
  2022-08-01 13:43 ` [PATCH 1/2] regulator: dt-bindings: Add " Rob Herring
  2022-08-01 17:27 ` Rob Herring
  2 siblings, 1 reply; 5+ messages in thread
From: Samuel Holland @ 2022-08-01  4:47 UTC (permalink / raw)
  To: Liam Girdwood, Mark Brown, Chen-Yu Tsai, Jernej Skrabec,
	Krzysztof Kozlowski, Rob Herring
  Cc: Samuel Holland, devicetree, linux-arm-kernel, linux-kernel, linux-sunxi

D1 contains two pairs of LDOs. Since they have similar bindings, and
they always exist together, put them in a single driver.

The analog LDOs are relatively boring, with a single linear range. The
one quirk is that their bandgap reference must be calibrated for them to
produce the correct voltage.

The system LDOs have the complication that their voltage step is not an
integer, so a custom .list_voltage is needed to get the rounding right.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

 drivers/regulator/Kconfig            |   8 +
 drivers/regulator/Makefile           |   1 +
 drivers/regulator/sun20i-regulator.c | 244 +++++++++++++++++++++++++++
 3 files changed, 253 insertions(+)
 create mode 100644 drivers/regulator/sun20i-regulator.c

diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index cbe0f96ca342..20a22f900bb2 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -1234,6 +1234,14 @@ config REGULATOR_STW481X_VMMC
 	  This driver supports the internal VMMC regulator in the STw481x
 	  PMIC chips.
 
+config REGULATOR_SUN20I
+	tristate "Allwinner D1 internal LDOs"
+	depends on ARCH_SUNXI || COMPILE_TEST
+	depends on MFD_SYSCON && NVMEM
+	default ARCH_SUNXI
+	help
+	  This driver supports the internal LDOs in the Allwinner D1 SoC.
+
 config REGULATOR_SY7636A
 	tristate "Silergy SY7636A voltage regulator"
 	help
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 8d3ee8b6d41d..cb3ac9290fc3 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -145,6 +145,7 @@ obj-$(CONFIG_REGULATOR_STM32_VREFBUF) += stm32-vrefbuf.o
 obj-$(CONFIG_REGULATOR_STM32_PWR) += stm32-pwr.o
 obj-$(CONFIG_REGULATOR_STPMIC1) += stpmic1_regulator.o
 obj-$(CONFIG_REGULATOR_STW481X_VMMC) += stw481x-vmmc.o
+obj-$(CONFIG_REGULATOR_SUN20I) += sun20i-regulator.o
 obj-$(CONFIG_REGULATOR_SY7636A) += sy7636a-regulator.o
 obj-$(CONFIG_REGULATOR_SY8106A) += sy8106a-regulator.o
 obj-$(CONFIG_REGULATOR_SY8824X) += sy8824x.o
diff --git a/drivers/regulator/sun20i-regulator.c b/drivers/regulator/sun20i-regulator.c
new file mode 100644
index 000000000000..c4d075440249
--- /dev/null
+++ b/drivers/regulator/sun20i-regulator.c
@@ -0,0 +1,244 @@
+// SPDX-License-Identifier: GPL-2.0-only
+//
+// Copyright (c) 2021-2022 Samuel Holland <samuel@sholland.org>
+//
+
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/nvmem-consumer.h>
+#include <linux/of_device.h>
+#include <linux/platform_device.h>
+#include <linux/regmap.h>
+#include <linux/regulator/driver.h>
+
+#define SUN20I_POWER_REG		0x348
+
+#define SUN20I_SYS_LDO_CTRL_REG		0x150
+
+struct sun20i_regulator_data {
+	int				(*init)(struct device *dev,
+						struct regmap *regmap);
+	const struct regulator_desc	*descs;
+	unsigned int			ndescs;
+};
+
+static int sun20i_d1_analog_ldos_init(struct device *dev, struct regmap *regmap)
+{
+	u8 bg_trim;
+	int ret;
+
+	ret = nvmem_cell_read_u8(dev, "bg_trim", &bg_trim);
+	if (ret)
+		return dev_err_probe(dev, ret, "Failed to get bg_trim value\n");
+
+	/* The default value corresponds to 900 mV. */
+	if (!bg_trim)
+		bg_trim = 0x19;
+
+	return regmap_update_bits(regmap, SUN20I_POWER_REG,
+				  GENMASK(7, 0), bg_trim);
+}
+
+static const struct regulator_ops sun20i_d1_analog_ldo_ops = {
+	.list_voltage		= regulator_list_voltage_linear,
+	.map_voltage		= regulator_map_voltage_linear,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+	.enable			= regulator_enable_regmap,
+	.disable		= regulator_disable_regmap,
+	.is_enabled		= regulator_is_enabled_regmap,
+};
+
+static const struct regulator_desc sun20i_d1_analog_ldo_descs[] = {
+	{
+		.name		= "aldo",
+		.supply_name	= "vdd33",
+		.of_match	= "aldo",
+		.ops		= &sun20i_d1_analog_ldo_ops,
+		.type		= REGULATOR_VOLTAGE,
+		.owner		= THIS_MODULE,
+		.n_voltages	= BIT(3),
+		.min_uV		= 1650000,
+		.uV_step	= 50000,
+		.vsel_reg	= SUN20I_POWER_REG,
+		.vsel_mask	= GENMASK(14, 12),
+		.enable_reg	= SUN20I_POWER_REG,
+		.enable_mask	= BIT(31),
+	},
+	{
+		.name		= "hpldo",
+		.supply_name	= "hpldoin",
+		.of_match	= "hpldo",
+		.ops		= &sun20i_d1_analog_ldo_ops,
+		.type		= REGULATOR_VOLTAGE,
+		.owner		= THIS_MODULE,
+		.n_voltages	= BIT(3),
+		.min_uV		= 1650000,
+		.uV_step	= 50000,
+		.vsel_reg	= SUN20I_POWER_REG,
+		.vsel_mask	= GENMASK(10, 8),
+		.enable_reg	= SUN20I_POWER_REG,
+		.enable_mask	= BIT(30),
+	},
+};
+
+static const struct sun20i_regulator_data sun20i_d1_analog_ldos = {
+	.init	= sun20i_d1_analog_ldos_init,
+	.descs	= sun20i_d1_analog_ldo_descs,
+	.ndescs	= ARRAY_SIZE(sun20i_d1_analog_ldo_descs),
+};
+
+/* regulator_list_voltage_linear() modified for the non-integral uV_step. */
+static int sun20i_d1_system_ldo_list_voltage(struct regulator_dev *rdev,
+					     unsigned int selector)
+{
+	const struct regulator_desc *desc = rdev->desc;
+	unsigned int uV;
+
+	if (selector >= desc->n_voltages)
+		return -EINVAL;
+
+	uV = desc->min_uV + (desc->uV_step * selector);
+
+	/* Produce correctly-rounded absolute voltages. */
+	return uV + ((selector + 1 + (desc->min_uV % 4)) / 3);
+}
+
+static const struct regulator_ops sun20i_d1_system_ldo_ops = {
+	.list_voltage		= sun20i_d1_system_ldo_list_voltage,
+	.map_voltage		= regulator_map_voltage_ascend,
+	.set_voltage_sel	= regulator_set_voltage_sel_regmap,
+	.get_voltage_sel	= regulator_get_voltage_sel_regmap,
+};
+
+static const struct regulator_desc sun20i_d1_system_ldo_descs[] = {
+	{
+		.name		= "ldoa",
+		.supply_name	= "ldo-in",
+		.of_match	= "ldoa",
+		.ops		= &sun20i_d1_system_ldo_ops,
+		.type		= REGULATOR_VOLTAGE,
+		.owner		= THIS_MODULE,
+		.n_voltages	= BIT(5),
+		.min_uV		= 1600000,
+		.uV_step	= 13333, /* repeating */
+		.vsel_reg	= SUN20I_SYS_LDO_CTRL_REG,
+		.vsel_mask	= GENMASK(7, 0),
+	},
+	{
+		.name		= "ldob",
+		.supply_name	= "ldo-in",
+		.of_match	= "ldob",
+		.ops		= &sun20i_d1_system_ldo_ops,
+		.type		= REGULATOR_VOLTAGE,
+		.owner		= THIS_MODULE,
+		.n_voltages	= BIT(6),
+		.min_uV		= 1166666,
+		.uV_step	= 13333, /* repeating */
+		.vsel_reg	= SUN20I_SYS_LDO_CTRL_REG,
+		.vsel_mask	= GENMASK(15, 8),
+	},
+};
+
+static const struct sun20i_regulator_data sun20i_d1_system_ldos = {
+	.descs	= sun20i_d1_system_ldo_descs,
+	.ndescs	= ARRAY_SIZE(sun20i_d1_system_ldo_descs),
+};
+
+static const struct of_device_id sun20i_regulator_of_match[] = {
+	{
+		.compatible = "allwinner,sun20i-d1-analog-ldos",
+		.data = &sun20i_d1_analog_ldos,
+	},
+	{
+		.compatible = "allwinner,sun20i-d1-system-ldos",
+		.data = &sun20i_d1_system_ldos,
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, sun20i_regulator_of_match);
+
+static struct regmap *sun20i_regulator_get_regmap(struct device *dev)
+{
+	struct platform_device *syscon_pdev;
+	struct device_node *syscon_node;
+	struct regmap *regmap;
+
+	/*
+	 * First try the syscon interface. The system control device is not
+	 * compatible with "syscon", so fall back to getting the regmap from
+	 * its platform device. This is ugly, but required for devicetree
+	 * backward compatibility.
+	 */
+	regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
+	if (!IS_ERR(regmap))
+		return regmap;
+
+	syscon_node = of_parse_phandle(dev->of_node, "syscon", 0);
+	if (!syscon_node)
+		return ERR_PTR(-ENODEV);
+
+	syscon_pdev = of_find_device_by_node(syscon_node);
+	of_node_put(syscon_node);
+	if (!syscon_pdev)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	regmap = dev_get_regmap(&syscon_pdev->dev, NULL);
+	platform_device_put(syscon_pdev);
+	if (!regmap)
+		return ERR_PTR(-EPROBE_DEFER);
+
+	return regmap;
+}
+
+static int sun20i_regulator_probe(struct platform_device *pdev)
+{
+	const struct sun20i_regulator_data *data;
+	struct device *dev = &pdev->dev;
+	struct regulator_config config;
+	struct regmap *regmap;
+	int ret;
+
+	data = of_device_get_match_data(dev);
+	if (!data)
+		return -EINVAL;
+
+	regmap = sun20i_regulator_get_regmap(dev);
+	if (IS_ERR(regmap))
+		return dev_err_probe(dev, PTR_ERR(regmap), "Failed to get regmap\n");
+
+	if (data->init) {
+		ret = data->init(dev, regmap);
+		if (ret)
+			return ret;
+	}
+
+	config = (struct regulator_config) {
+		.dev	= dev,
+		.regmap	= regmap,
+	};
+
+	for (unsigned int i = 0; i < data->ndescs; ++i) {
+		const struct regulator_desc *desc = &data->descs[i];
+		struct regulator_dev *rdev;
+
+		rdev = devm_regulator_register(dev, desc, &config);
+		if (IS_ERR(rdev))
+			return PTR_ERR(rdev);
+	}
+
+	return 0;
+}
+
+static struct platform_driver sun20i_regulator_driver = {
+	.probe	= sun20i_regulator_probe,
+	.driver	= {
+		.name		= "sun20i-regulator",
+		.of_match_table	= sun20i_regulator_of_match,
+	},
+};
+module_platform_driver(sun20i_regulator_driver);
+
+MODULE_AUTHOR("Samuel Holland <samuel@sholland.org>");
+MODULE_DESCRIPTION("Allwinner D1 internal LDO driver");
+MODULE_LICENSE("GPL");
-- 
2.35.1


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

* Re: [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs
  2022-08-01  4:47 [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs Samuel Holland
  2022-08-01  4:47 ` [PATCH 2/2] regulator: sun20i: Add support for " Samuel Holland
@ 2022-08-01 13:43 ` Rob Herring
  2022-08-01 17:27 ` Rob Herring
  2 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2022-08-01 13:43 UTC (permalink / raw)
  To: Samuel Holland
  Cc: devicetree, Mark Brown, linux-kernel, linux-arm-kernel,
	Chen-Yu Tsai, Rob Herring, Liam Girdwood, linux-sunxi,
	Krzysztof Kozlowski, Jernej Skrabec

On Sun, 31 Jul 2022 23:47:57 -0500, Samuel Holland wrote:
> The Allwinner D1 SoC contains two pairs of in-package LDOs. One pair is
> for general purpose use. LDOA generally powers the board's 1.8 V rail.
> LDOB generally powers the in-package DRAM, where applicable.
> 
> The other pair of LDOs powers the analog power domains inside the SoC,
> including the audio codec, thermal sensor, and ADCs. These LDOs require
> a 0.9 V bandgap voltage reference. The calibration value for the voltage
> reference is stored in an eFuse, accessed via an NVMEM cell.
> 
> Neither LDO control register is in its own MMIO range; instead, each
> regulator device relies on a syscon exported by some "host" device node.
> Getting the register via a syscon avoids a dependency on the subsystem/
> driver for that host device (e.g. a functioning thermal sensor should
> not depend on having the audio codec driver loaded).
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  .../allwinner,sun20i-d1-analog-ldos.yaml      | 77 +++++++++++++++++++
>  .../allwinner,sun20i-d1-system-ldos.yaml      | 55 +++++++++++++
>  2 files changed, 132 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
>  create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
> 

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:
Error: Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.example.dts:24.27-28 syntax error
FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:383: Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.example.dtb] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1404: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

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

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.


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

* Re: [PATCH 2/2] regulator: sun20i: Add support for Allwinner D1 LDOs
  2022-08-01  4:47 ` [PATCH 2/2] regulator: sun20i: Add support for " Samuel Holland
@ 2022-08-01 16:03   ` Mark Brown
  0 siblings, 0 replies; 5+ messages in thread
From: Mark Brown @ 2022-08-01 16:03 UTC (permalink / raw)
  To: Samuel Holland
  Cc: Liam Girdwood, Chen-Yu Tsai, Jernej Skrabec, Krzysztof Kozlowski,
	Rob Herring, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

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

On Sun, Jul 31, 2022 at 11:47:58PM -0500, Samuel Holland wrote:

> +static const struct regulator_desc sun20i_d1_analog_ldo_descs[] = {
> +	{
> +		.name		= "aldo",
> +		.supply_name	= "vdd33",
> +		.of_match	= "aldo",
> +		.ops		= &sun20i_d1_analog_ldo_ops,
> +		.type		= REGULATOR_VOLTAGE,
> +		.owner		= THIS_MODULE,
> +		.n_voltages	= BIT(3),

I'm really unconvinced that using BIT() is clearer than just writing the
number of voltages directly as a number.

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

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

* Re: [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs
  2022-08-01  4:47 [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs Samuel Holland
  2022-08-01  4:47 ` [PATCH 2/2] regulator: sun20i: Add support for " Samuel Holland
  2022-08-01 13:43 ` [PATCH 1/2] regulator: dt-bindings: Add " Rob Herring
@ 2022-08-01 17:27 ` Rob Herring
  2 siblings, 0 replies; 5+ messages in thread
From: Rob Herring @ 2022-08-01 17:27 UTC (permalink / raw)
  To: Samuel Holland
  Cc: Liam Girdwood, Mark Brown, Chen-Yu Tsai, Jernej Skrabec,
	Krzysztof Kozlowski, devicetree, linux-arm-kernel, linux-kernel,
	linux-sunxi

On Sun, Jul 31, 2022 at 11:47:57PM -0500, Samuel Holland wrote:
> The Allwinner D1 SoC contains two pairs of in-package LDOs. One pair is
> for general purpose use. LDOA generally powers the board's 1.8 V rail.
> LDOB generally powers the in-package DRAM, where applicable.
> 
> The other pair of LDOs powers the analog power domains inside the SoC,
> including the audio codec, thermal sensor, and ADCs. These LDOs require
> a 0.9 V bandgap voltage reference. The calibration value for the voltage
> reference is stored in an eFuse, accessed via an NVMEM cell.
> 
> Neither LDO control register is in its own MMIO range; instead, each
> regulator device relies on a syscon exported by some "host" device node.
> Getting the register via a syscon avoids a dependency on the subsystem/
> driver for that host device (e.g. a functioning thermal sensor should
> not depend on having the audio codec driver loaded).
> 
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
> 
>  .../allwinner,sun20i-d1-analog-ldos.yaml      | 77 +++++++++++++++++++
>  .../allwinner,sun20i-d1-system-ldos.yaml      | 55 +++++++++++++
>  2 files changed, 132 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
>  create mode 100644 Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
> 
> diff --git a/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
> new file mode 100644
> index 000000000000..df648c56123d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-analog-ldos.yaml
> @@ -0,0 +1,77 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/regulator/allwinner,sun20i-d1-analog-ldos.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Allwinner D1 Analog LDOs
> +
> +description:
> +  Allwinner D1 contains a set of LDOs which are designed to supply analog power
> +  inside and outside the SoC. They are controlled by a register within the audio
> +  codec MMIO space, but which is not part of the audio codec clock/reset domain,
> +  and so is exposed as a syscon.
> +
> +maintainers:
> +  - Samuel Holland <samuel@sholland.org>
> +
> +properties:
> +  compatible:
> +    enum:
> +      - allwinner,sun20i-d1-analog-ldos
> +
> +  nvmem-cells:
> +    items:
> +      - description: NVMEM cell for the calibrated bandgap reference trim value
> +
> +  nvmem-cell-names:
> +    items:
> +      - const: bg_trim
> +
> +  syscon:

'syscon' is not a generic property. Name it based on the block you are 
linking to or what the control is. 

Or better yet, if this is the only control interface, make this a child 
node of the referenced node instead.

> +    $ref: /schemas/types.yaml#/definitions/phandle
> +    description: phandle of the device containing the power register
> +
> +patternProperties:
> +  "^(aldo|hpldo)$":
> +    type: object
> +    $ref: regulator.yaml#

       unevaluatedProperties: false

> +
> +required:
> +  - compatible
> +  - nvmem-cells
> +  - nvmem-cell-names
> +  - syscon
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    sid: efuse {
> +        #address-cells = <1>;
> +        #size-cells = <1>;
> +
> +        bg_trim: bg-trim@28 {
> +            reg = <0x28 0x4>;
> +            bits = <16, 8>;
> +        };
> +    };
> +
> +    ldos-analog {
> +        compatible = "allwinner,sun20i-d1-analog-ldos";
> +        nvmem-cells = <&bg_trim>;
> +        nvmem-cell-names = "bg_trim";
> +        syscon = <&codec>;
> +
> +        reg_aldo: aldo {
> +            regulator-min-microvolt = <1800000>;
> +            regulator-max-microvolt = <1800000>;
> +        };
> +
> +        reg_hpldo: hpldo {
> +            regulator-min-microvolt = <1800000>;
> +            regulator-max-microvolt = <1800000>;
> +        };
> +    };
> +
> +...
> diff --git a/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
> new file mode 100644
> index 000000000000..13b2e8c84f1d
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/regulator/allwinner,sun20i-d1-system-ldos.yaml
> @@ -0,0 +1,55 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/regulator/allwinner,sun20i-d1-system-ldos.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: Allwinner D1 System LDOs
> +
> +description:
> +  Allwinner D1 contains a pair of general-purpose LDOs which are designed to
> +  supply power inside and outside the SoC. They are controlled by a register
> +  within the system controller MMIO space.
> +
> +maintainers:
> +  - Samuel Holland <samuel@sholland.org>
> +
> +properties:
> +  compatible:
> +    enum:
> +      - allwinner,sun20i-d1-system-ldos
> +
> +  syscon:
> +    $ref: /schemas/types.yaml#/definitions/phandle
> +    description: phandle of the device containing the LDO control register
> +
> +patternProperties:
> +  "^(ldoa|ldob)$":
> +    type: object
> +    $ref: regulator.yaml#
> +
> +required:
> +  - compatible
> +  - syscon
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    ldos-system {
> +        compatible = "allwinner,sun20i-d1-system-ldos";
> +        syscon = <&syscon>;
> +
> +        reg_ldoa: ldoa {
> +            regulator-min-microvolt = <1800000>;
> +            regulator-max-microvolt = <1800000>;
> +        };
> +
> +        reg_ldob: ldob {
> +            regulator-name = "vcc-dram";
> +            regulator-min-microvolt = <1500000>;
> +            regulator-max-microvolt = <1500000>;
> +        };
> +    };
> +
> +...
> -- 
> 2.35.1
> 
> 

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

end of thread, other threads:[~2022-08-01 17:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-01  4:47 [PATCH 1/2] regulator: dt-bindings: Add Allwinner D1 LDOs Samuel Holland
2022-08-01  4:47 ` [PATCH 2/2] regulator: sun20i: Add support for " Samuel Holland
2022-08-01 16:03   ` Mark Brown
2022-08-01 13:43 ` [PATCH 1/2] regulator: dt-bindings: Add " Rob Herring
2022-08-01 17:27 ` Rob Herring

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).