Skip to content
This repository was archived by the owner on Nov 8, 2023. It is now read-only.

Commit 0b9a078

Browse files
committed
regulator: Add Maxim MAX20411 support
Merge series from Bjorn Andersson <quic_bjorande@quicinc.com>: Introduce binding and driver for the Maxim MAX20411, and wire these up on the Qualcomm SA8295P ADP.
2 parents 8966a72 + 047ebaf commit 0b9a078

File tree

4 files changed

+230
-0
lines changed

4 files changed

+230
-0
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
2+
%YAML 1.2
3+
---
4+
$id: http://devicetree.org/schemas/regulator/maxim,max20411.yaml#
5+
$schema: http://devicetree.org/meta-schemas/core.yaml#
6+
7+
title: Maxim Integrated MAX20411 Step-Down DC-DC Converter
8+
9+
maintainers:
10+
- Bjorn Andersson <andersson@kernel.org>
11+
12+
description:
13+
The MAX20411 is a high-efficiency, DC-DC step-down converter. It provides
14+
configurable output voltage in the range of 0.5V to 1.275V, configurable over
15+
I2C.
16+
17+
allOf:
18+
- $ref: regulator.yaml#
19+
20+
properties:
21+
compatible:
22+
const: maxim,max20411
23+
24+
reg:
25+
maxItems: 1
26+
27+
enable-gpios:
28+
description: GPIO connected to the EN pin, active high
29+
30+
vdd-supply:
31+
description: Input supply for the device (VDD pin, 3.0V to 5.5V)
32+
33+
required:
34+
- compatible
35+
- reg
36+
- enable-gpios
37+
38+
unevaluatedProperties: false
39+
40+
examples:
41+
- |
42+
#include <dt-bindings/gpio/gpio.h>
43+
44+
i2c {
45+
#address-cells = <1>;
46+
#size-cells = <0>;
47+
48+
regulator@39 {
49+
compatible = "maxim,max20411";
50+
reg = <0x39>;
51+
52+
enable-gpios = <&gpio 2 GPIO_ACTIVE_HIGH>;
53+
54+
regulator-min-microvolt = <800000>;
55+
regulator-max-microvolt = <1000000>;
56+
};
57+
};
58+
...

drivers/regulator/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,14 @@ config REGULATOR_MAX20086
655655
protectorvia I2C bus. The regulator has 2 or 4 outputs depending on
656656
the device model. This driver is only capable to turn on/off them.
657657

658+
config REGULATOR_MAX20411
659+
tristate "Maxim MAX20411 High-Efficiency Single Step-Down Converter"
660+
depends on I2C
661+
select REGMAP_I2C
662+
help
663+
This driver controls the Maxim MAX20411 family of high-efficiency,
664+
syncrhonous step-down converters.
665+
658666
config REGULATOR_MAX77686
659667
tristate "Maxim 77686 regulator"
660668
depends on MFD_MAX77686 || COMPILE_TEST

drivers/regulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ obj-$(CONFIG_REGULATOR_MAX8973) += max8973-regulator.o
8080
obj-$(CONFIG_REGULATOR_MAX8997) += max8997-regulator.o
8181
obj-$(CONFIG_REGULATOR_MAX8998) += max8998.o
8282
obj-$(CONFIG_REGULATOR_MAX20086) += max20086-regulator.o
83+
obj-$(CONFIG_REGULATOR_MAX20411) += max20411-regulator.o
8384
obj-$(CONFIG_REGULATOR_MAX77686) += max77686-regulator.o
8485
obj-$(CONFIG_REGULATOR_MAX77693) += max77693-regulator.o
8586
obj-$(CONFIG_REGULATOR_MAX77802) += max77802-regulator.o
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (c) 2021, The Linux Foundation. All rights reserved.
4+
* Copyright (c) 2022, Linaro Ltd.
5+
*/
6+
7+
#include <linux/gpio/consumer.h>
8+
#include <linux/i2c.h>
9+
#include <linux/module.h>
10+
#include <linux/of_platform.h>
11+
#include <linux/regmap.h>
12+
#include <linux/regulator/driver.h>
13+
#include <linux/regulator/machine.h>
14+
#include <linux/regulator/of_regulator.h>
15+
16+
#define MAX20411_UV_STEP 6250
17+
#define MAX20411_BASE_UV 243750
18+
#define MAX20411_MIN_SEL 41 /* 0.5V */
19+
#define MAX20411_MAX_SEL 165 /* 1.275V */
20+
#define MAX20411_VID_OFFSET 0x7
21+
#define MAX20411_VID_MASK 0xff
22+
#define MAX20411_SLEW_OFFSET 0x6
23+
#define MAX20411_SLEW_DVS_MASK 0xc
24+
#define MAX20411_SLEW_SR_MASK 0x3
25+
26+
struct max20411 {
27+
struct device *dev;
28+
struct device_node *of_node;
29+
struct regulator_desc desc;
30+
struct regulator_dev *rdev;
31+
struct regmap *regmap;
32+
};
33+
34+
static const unsigned int max20411_slew_rates[] = { 13100, 6600, 3300, 1600 };
35+
36+
static int max20411_enable_time(struct regulator_dev *rdev)
37+
{
38+
int voltage, rate, ret;
39+
unsigned int val;
40+
41+
/* get voltage */
42+
ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val);
43+
if (ret)
44+
return ret;
45+
46+
val &= rdev->desc->vsel_mask;
47+
voltage = regulator_list_voltage_linear(rdev, val);
48+
49+
/* get rate */
50+
ret = regmap_read(rdev->regmap, MAX20411_SLEW_OFFSET, &val);
51+
if (ret)
52+
return ret;
53+
54+
val = FIELD_GET(MAX20411_SLEW_SR_MASK, val);
55+
rate = max20411_slew_rates[val];
56+
57+
return DIV_ROUND_UP(voltage, rate);
58+
}
59+
60+
static const struct regmap_config max20411_regmap_config = {
61+
.reg_bits = 8,
62+
.val_bits = 8,
63+
.max_register = 0xe,
64+
};
65+
66+
static const struct regulator_ops max20411_ops = {
67+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
68+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
69+
.list_voltage = regulator_list_voltage_linear,
70+
.enable_time = max20411_enable_time,
71+
};
72+
73+
static const struct regulator_desc max20411_desc = {
74+
.ops = &max20411_ops,
75+
.owner = THIS_MODULE,
76+
.type = REGULATOR_VOLTAGE,
77+
.supply_name = "vin",
78+
.name = "max20411",
79+
80+
/*
81+
* voltage = 0.24375V + selector * 6.25mV
82+
* with valid selector between 41 to 165 (0.5V to 1.275V)
83+
*/
84+
.min_uV = MAX20411_BASE_UV,
85+
.uV_step = MAX20411_UV_STEP,
86+
.linear_min_sel = MAX20411_MIN_SEL,
87+
.n_voltages = MAX20411_MAX_SEL,
88+
89+
.vsel_reg = MAX20411_VID_OFFSET,
90+
.vsel_mask = MAX20411_VID_MASK,
91+
92+
.ramp_reg = MAX20411_SLEW_OFFSET,
93+
.ramp_mask = MAX20411_SLEW_DVS_MASK,
94+
.ramp_delay_table = max20411_slew_rates,
95+
.n_ramp_values = ARRAY_SIZE(max20411_slew_rates),
96+
};
97+
98+
static int max20411_probe(struct i2c_client *client,
99+
const struct i2c_device_id *id)
100+
{
101+
struct regulator_init_data *init_data;
102+
struct device *dev = &client->dev;
103+
struct regulator_config cfg = {};
104+
struct max20411 *max20411;
105+
106+
max20411 = devm_kzalloc(dev, sizeof(*max20411), GFP_KERNEL);
107+
if (!max20411)
108+
return -ENOMEM;
109+
110+
max20411->regmap = devm_regmap_init_i2c(client, &max20411_regmap_config);
111+
if (IS_ERR(max20411->regmap)) {
112+
dev_err(dev, "Failed to allocate regmap!\n");
113+
return PTR_ERR(max20411->regmap);
114+
}
115+
116+
max20411->dev = dev;
117+
max20411->of_node = dev->of_node;
118+
119+
max20411->desc = max20411_desc;
120+
init_data = of_get_regulator_init_data(max20411->dev, max20411->of_node, &max20411->desc);
121+
if (!init_data)
122+
return -ENODATA;
123+
124+
cfg.dev = max20411->dev;
125+
cfg.init_data = init_data;
126+
cfg.of_node = max20411->of_node;
127+
cfg.driver_data = max20411;
128+
129+
cfg.ena_gpiod = gpiod_get(max20411->dev, "enable", GPIOD_ASIS);
130+
if (IS_ERR(cfg.ena_gpiod))
131+
return dev_err_probe(dev, PTR_ERR(cfg.ena_gpiod),
132+
"unable to acquire enable gpio\n");
133+
134+
max20411->rdev = devm_regulator_register(max20411->dev, &max20411->desc, &cfg);
135+
if (IS_ERR(max20411->rdev))
136+
dev_err(max20411->dev, "Failed to register regulator\n");
137+
138+
return PTR_ERR_OR_ZERO(max20411->rdev);
139+
}
140+
141+
static const struct of_device_id of_max20411_match_tbl[] = {
142+
{ .compatible = "maxim,max20411", },
143+
{ },
144+
};
145+
MODULE_DEVICE_TABLE(of, of_max20411_match_tbl);
146+
147+
static const struct i2c_device_id max20411_id[] = {
148+
{ "max20411", 0 },
149+
{ },
150+
};
151+
MODULE_DEVICE_TABLE(i2c, max20411_id);
152+
153+
static struct i2c_driver max20411_i2c_driver = {
154+
.driver = {
155+
.name = "max20411",
156+
.of_match_table = of_max20411_match_tbl,
157+
},
158+
.probe = max20411_probe,
159+
.id_table = max20411_id,
160+
};
161+
module_i2c_driver(max20411_i2c_driver);
162+
163+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)