* [PATCH 0/2] DA9121 regulator support
@ 2020-10-29 15:15 Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 1/2] dt-bindings: regulator: Add DA9121 Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 2/2] regulator: Add support for DA9121 regulator Vincent Whitchurch
0 siblings, 2 replies; 5+ messages in thread
From: Vincent Whitchurch @ 2020-10-29 15:15 UTC (permalink / raw)
To: lgirdwood, broonie, support.opensource
Cc: kernel, devicetree, linux-kernel, robh+dt, Vincent Whitchurch
This series adds support for the DA9121, a "High-Performance, 10 A, Dual-Phase
DC-DC Converter". The datasheet is currently available here:
https://www.dialog-semiconductor.com/sites/default/files/da9121_datasheet_2v3.pdf
Vincent Whitchurch (2):
dt-bindings: regulator: Add DA9121
regulator: Add support for DA9121 regulator
.../bindings/regulator/dlg,da9121.yaml | 42 +++++++
drivers/regulator/Kconfig | 12 ++
drivers/regulator/Makefile | 1 +
drivers/regulator/da9121-regulator.c | 111 ++++++++++++++++++
4 files changed, 166 insertions(+)
create mode 100644 Documentation/devicetree/bindings/regulator/dlg,da9121.yaml
create mode 100644 drivers/regulator/da9121-regulator.c
--
2.28.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH 1/2] dt-bindings: regulator: Add DA9121
2020-10-29 15:15 [PATCH 0/2] DA9121 regulator support Vincent Whitchurch
@ 2020-10-29 15:15 ` Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 2/2] regulator: Add support for DA9121 regulator Vincent Whitchurch
1 sibling, 0 replies; 5+ messages in thread
From: Vincent Whitchurch @ 2020-10-29 15:15 UTC (permalink / raw)
To: lgirdwood, broonie, support.opensource
Cc: kernel, devicetree, linux-kernel, robh+dt, Vincent Whitchurch
Add bindings for the Dialog Semiconductor DA9121 voltage regulator.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
.../bindings/regulator/dlg,da9121.yaml | 42 +++++++++++++++++++
1 file changed, 42 insertions(+)
create mode 100644 Documentation/devicetree/bindings/regulator/dlg,da9121.yaml
diff --git a/Documentation/devicetree/bindings/regulator/dlg,da9121.yaml b/Documentation/devicetree/bindings/regulator/dlg,da9121.yaml
new file mode 100644
index 000000000000..2e67cc164da9
--- /dev/null
+++ b/Documentation/devicetree/bindings/regulator/dlg,da9121.yaml
@@ -0,0 +1,42 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/regulator/dlg,da9121.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Dialog Semiconductor DA9121 voltage regulator
+
+maintainers:
+ - Vincent Whitchurch <vincent.whitchurch@axis.com>
+
+allOf:
+ - $ref: regulator.yaml#
+
+properties:
+ compatible:
+ const: dlg,da9121
+
+ reg:
+ maxItems: 1
+
+unevaluatedProperties: false
+
+required:
+ - compatible
+ - reg
+
+examples:
+ - |
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+ regulator@68 {
+ compatible = "dlg,da9121";
+ reg = <0x68>;
+
+ regulator-min-microvolt = <675000>;
+ regulator-max-microvolt = <825000>;
+ };
+ };
+
+...
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH 2/2] regulator: Add support for DA9121 regulator
2020-10-29 15:15 [PATCH 0/2] DA9121 regulator support Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 1/2] dt-bindings: regulator: Add DA9121 Vincent Whitchurch
@ 2020-10-29 15:15 ` Vincent Whitchurch
2020-10-29 15:28 ` Mark Brown
1 sibling, 1 reply; 5+ messages in thread
From: Vincent Whitchurch @ 2020-10-29 15:15 UTC (permalink / raw)
To: lgirdwood, broonie, support.opensource
Cc: kernel, devicetree, linux-kernel, robh+dt, Vincent Whitchurch
Add support for the Dialog Semiconductor DA9121, a single-channel
dual-phase buck converter controlled via I2C.
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com>
---
drivers/regulator/Kconfig | 12 +++
drivers/regulator/Makefile | 1 +
drivers/regulator/da9121-regulator.c | 111 +++++++++++++++++++++++++++
3 files changed, 124 insertions(+)
create mode 100644 drivers/regulator/da9121-regulator.c
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig
index 020a00d6696b..005a6036dd38 100644
--- a/drivers/regulator/Kconfig
+++ b/drivers/regulator/Kconfig
@@ -303,6 +303,18 @@ config REGULATOR_DA9063
This driver can also be built as a module. If so, the module
will be called da9063-regulator.
+config REGULATOR_DA9121
+ tristate "Dialog Semiconductor DA9121 regulator"
+ depends on I2C && OF
+ select REGMAP_I2C
+ help
+ Say y here to support for the Dialog Semiconductor DA9121. The
+ DA9210 is a dual-phase buck converter controlled through an I2C
+ interface.
+
+ This driver can also be built as a module. If so, the module
+ will be called da9121-regulator.
+
config REGULATOR_DA9210
tristate "Dialog Semiconductor DA9210 regulator"
depends on I2C
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile
index 6ebae516258e..6096862a1d60 100644
--- a/drivers/regulator/Makefile
+++ b/drivers/regulator/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_REGULATOR_DA9052) += da9052-regulator.o
obj-$(CONFIG_REGULATOR_DA9055) += da9055-regulator.o
obj-$(CONFIG_REGULATOR_DA9062) += da9062-regulator.o
obj-$(CONFIG_REGULATOR_DA9063) += da9063-regulator.o
+obj-$(CONFIG_REGULATOR_DA9121) += da9121-regulator.o
obj-$(CONFIG_REGULATOR_DA9210) += da9210-regulator.o
obj-$(CONFIG_REGULATOR_DA9211) += da9211-regulator.o
obj-$(CONFIG_REGULATOR_DBX500_PRCMU) += dbx500-prcmu.o
diff --git a/drivers/regulator/da9121-regulator.c b/drivers/regulator/da9121-regulator.c
new file mode 100644
index 000000000000..d712e8f07c41
--- /dev/null
+++ b/drivers/regulator/da9121-regulator.c
@@ -0,0 +1,111 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/* Copyright (C) 2020 Axis Communications AB */
+
+#include <linux/of_device.h>
+#include <linux/regulator/of_regulator.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/driver.h>
+#include <linux/module.h>
+#include <linux/regmap.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+
+#define DA9121_BUCK_BUCK1_0 0x20
+#define DA9121_BUCK_BUCK1_0_CH1_EN BIT(0)
+
+#define DA9121_BUCK_BUCK1_5 0x25
+#define DA9121_BUCK_BUCK1_5_CH1_A_VOUT GENMASK(7, 0)
+
+#define DA9121_MIN_MV 300
+#define DA9121_MAX_MV 1900
+#define DA9121_STEP_MV 10
+#define DA9121_MIN_SEL (DA9121_MIN_MV / DA9121_STEP_MV)
+#define DA9121_N_VOLTAGES (((DA9121_MAX_MV - DA9121_MIN_MV) / DA9121_STEP_MV) \
+ + 1 + DA9121_MIN_SEL)
+
+static const struct regmap_config da9121_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+};
+
+static const struct regulator_ops da9121_buck_ops = {
+ .enable = regulator_enable_regmap,
+ .disable = regulator_disable_regmap,
+ .is_enabled = regulator_is_enabled_regmap,
+ .set_voltage_sel = regulator_set_voltage_sel_regmap,
+ .get_voltage_sel = regulator_get_voltage_sel_regmap,
+ .list_voltage = regulator_list_voltage_linear,
+};
+
+static const struct regulator_desc da9121_reg = {
+ .name = "da9121",
+ .owner = THIS_MODULE,
+ .ops = &da9121_buck_ops,
+ .type = REGULATOR_VOLTAGE,
+ .n_voltages = DA9121_N_VOLTAGES,
+ .min_uV = DA9121_MIN_MV * 1000,
+ .uV_step = DA9121_STEP_MV * 1000,
+ .linear_min_sel = DA9121_MIN_SEL,
+ .vsel_reg = DA9121_BUCK_BUCK1_5,
+ .vsel_mask = DA9121_BUCK_BUCK1_5_CH1_A_VOUT,
+ .enable_reg = DA9121_BUCK_BUCK1_0,
+ .enable_mask = DA9121_BUCK_BUCK1_0_CH1_EN,
+ /* Default value of BUCK_BUCK1_0.CH1_SRC_DVC_UP */
+ .ramp_delay = 20000,
+ /* tBUCK_EN */
+ .enable_time = 20,
+};
+
+static const struct of_device_id da9121_dt_ids[] = {
+ { .compatible = "dlg,da9121", },
+ { }
+};
+MODULE_DEVICE_TABLE(of, da9121_dt_ids);
+
+static int da9121_i2c_probe(struct i2c_client *i2c,
+ const struct i2c_device_id *id)
+{
+ struct device *dev = &i2c->dev;
+ struct regulator_config config = {};
+ struct regulator_dev *rdev;
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(i2c, &da9121_regmap_config);
+ if (IS_ERR(regmap))
+ return PTR_ERR(regmap);
+
+ config.dev = &i2c->dev;
+ config.of_node = dev->of_node;
+ config.regmap = regmap;
+
+ config.init_data = of_get_regulator_init_data(dev, dev->of_node, &da9121_reg);
+ if (!config.init_data)
+ return -ENOMEM;
+
+ rdev = devm_regulator_register(&i2c->dev, &da9121_reg, &config);
+ if (IS_ERR(rdev)) {
+ dev_err(&i2c->dev, "Failed to register da9121 regulator\n");
+ return PTR_ERR(rdev);
+ }
+
+ return 0;
+}
+
+static const struct i2c_device_id da9121_i2c_id[] = {
+ { "da9121", 0 },
+ {},
+};
+MODULE_DEVICE_TABLE(i2c, da9121_i2c_id);
+
+static struct i2c_driver da9121_regulator_driver = {
+ .driver = {
+ .name = "da9121",
+ .of_match_table = of_match_ptr(da9121_dt_ids),
+ },
+ .probe = da9121_i2c_probe,
+ .id_table = da9121_i2c_id,
+};
+
+module_i2c_driver(da9121_regulator_driver);
+
+MODULE_LICENSE("GPL v2");
--
2.28.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] regulator: Add support for DA9121 regulator
2020-10-29 15:15 ` [PATCH 2/2] regulator: Add support for DA9121 regulator Vincent Whitchurch
@ 2020-10-29 15:28 ` Mark Brown
2020-11-02 15:48 ` Vincent Whitchurch
0 siblings, 1 reply; 5+ messages in thread
From: Mark Brown @ 2020-10-29 15:28 UTC (permalink / raw)
To: Vincent Whitchurch
Cc: lgirdwood, support.opensource, kernel, devicetree, linux-kernel, robh+dt
[-- Attachment #1: Type: text/plain, Size: 380 bytes --]
On Thu, Oct 29, 2020 at 04:15:38PM +0100, Vincent Whitchurch wrote:
> + config.init_data = of_get_regulator_init_data(dev, dev->of_node, &da9121_reg);
> + if (!config.init_data)
> + return -ENOMEM;
Don't do this, the core can do the DT bit for you and there is no reason
not to register the device if there are no constraints. -ENOMEM would
also be the wrong error code here.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 2/2] regulator: Add support for DA9121 regulator
2020-10-29 15:28 ` Mark Brown
@ 2020-11-02 15:48 ` Vincent Whitchurch
0 siblings, 0 replies; 5+ messages in thread
From: Vincent Whitchurch @ 2020-11-02 15:48 UTC (permalink / raw)
To: Mark Brown
Cc: lgirdwood, support.opensource, kernel, devicetree, linux-kernel, robh+dt
On Thu, Oct 29, 2020 at 03:28:43PM +0000, Mark Brown wrote:
> On Thu, Oct 29, 2020 at 04:15:38PM +0100, Vincent Whitchurch wrote:
>
> > + config.init_data = of_get_regulator_init_data(dev, dev->of_node, &da9121_reg);
> > + if (!config.init_data)
> > + return -ENOMEM;
>
> Don't do this, the core can do the DT bit for you and there is no reason
> not to register the device if there are no constraints. -ENOMEM would
> also be the wrong error code here.
OK, thanks. I see that I can get the core to do it if I set ->of_match
on the regulator_desc. I also see that there is some flexibility about
the placement of the constraints (desc->regulators_node is optional).
This chip has only one output which the datasheet calls Buck1, so I will
remove this call and set the desc.of_match field to get the driver to
support a node which looks like this:
regulator@68 {
compatible = "dlg,da9121";
reg = <0x68>;
buck1 {
regulator-min-microvolt = <675000>;
regulator-max-microvolt = <825000>;
};
};
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2020-11-02 15:48 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-29 15:15 [PATCH 0/2] DA9121 regulator support Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 1/2] dt-bindings: regulator: Add DA9121 Vincent Whitchurch
2020-10-29 15:15 ` [PATCH 2/2] regulator: Add support for DA9121 regulator Vincent Whitchurch
2020-10-29 15:28 ` Mark Brown
2020-11-02 15:48 ` Vincent Whitchurch
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).