Skip to content

Commit a0c543b

Browse files
gkhnclkmxmbroonie
authored andcommitted
regulator: max77503: Add ADI MAX77503 support
Add ADI MAX77503 buck converter driver support. Signed-off-by: Gokhan Celik <[email protected]> Link: https://lore.kernel.org/r/10bb3894fea31a098d768e346c8721e730d7cb21.1698000185.git.gokhan.celik@analog.com Signed-off-by: Mark Brown <[email protected]>
1 parent 8f7e17d commit a0c543b

File tree

3 files changed

+148
-0
lines changed

3 files changed

+148
-0
lines changed

drivers/regulator/Kconfig

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,16 @@ config REGULATOR_MAX5970
564564
The MAX5970/5978 is a smart switch with no output regulation, but
565565
fault protection and voltage and current monitoring capabilities.
566566

567+
config REGULATOR_MAX77503
568+
tristate "Analog Devices MAX77503 Regulator"
569+
depends on I2C
570+
select REGMAP_I2C
571+
help
572+
This driver controls a Analog Devices MAX77503 14V input, 1.5A
573+
high-efficiency buck converter via I2C bus.
574+
Say M here if you want to include support for the regulator as a
575+
module.
576+
567577
config REGULATOR_MAX77541
568578
tristate "Analog Devices MAX77541/77540 Regulator"
569579
depends on MFD_MAX77541

drivers/regulator/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ obj-$(CONFIG_REGULATOR_LTC3676) += ltc3676.o
6969
obj-$(CONFIG_REGULATOR_MAX14577) += max14577-regulator.o
7070
obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o
7171
obj-$(CONFIG_REGULATOR_MAX5970) += max5970-regulator.o
72+
obj-$(CONFIG_REGULATOR_MAX77503) += max77503-regulator.o
7273
obj-$(CONFIG_REGULATOR_MAX77541) += max77541-regulator.o
7374
obj-$(CONFIG_REGULATOR_MAX77620) += max77620-regulator.o
7475
obj-$(CONFIG_REGULATOR_MAX77650) += max77650-regulator.o
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*
3+
* Copyright (c) 2023 Analog Devices, Inc.
4+
* ADI regulator driver for MAX77503.
5+
*/
6+
7+
#include <linux/i2c.h>
8+
#include <linux/module.h>
9+
#include <linux/regmap.h>
10+
#include <linux/regulator/driver.h>
11+
#include <linux/regulator/machine.h>
12+
#include <linux/regulator/of_regulator.h>
13+
#include <linux/util_macros.h>
14+
15+
#define MAX77503_REG_CFG 0x00
16+
#define MAX77503_REG_VOUT 0x01
17+
18+
#define MAX77503_BIT_EN BIT(0)
19+
#define MAX77503_BIT_CURR_LIM BIT(3)
20+
#define MAX77503_BIT_ADEN BIT(6)
21+
22+
#define MAX77503_BITS_SOFT_START GENMASK(5, 4)
23+
#define MAX77503_BITS_MX_VOUT GENMASK(7, 0)
24+
25+
#define MAX77503_AD_ENABLED 0x1
26+
#define MAX77503_AD_DISABLED 0x0
27+
28+
struct max77503_dev {
29+
struct device *dev;
30+
struct device_node *of_node;
31+
struct regulator_desc desc;
32+
struct regulator_dev *rdev;
33+
struct regmap *regmap;
34+
};
35+
36+
static const struct regmap_config max77503_regmap_config = {
37+
.reg_bits = 8,
38+
.val_bits = 8,
39+
.max_register = 0x2,
40+
};
41+
42+
static const struct regulator_ops max77503_buck_ops = {
43+
.list_voltage = regulator_list_voltage_linear_range,
44+
.map_voltage = regulator_map_voltage_ascend,
45+
.is_enabled = regulator_is_enabled_regmap,
46+
.enable = regulator_enable_regmap,
47+
.disable = regulator_disable_regmap,
48+
.get_voltage_sel = regulator_get_voltage_sel_regmap,
49+
.set_voltage_sel = regulator_set_voltage_sel_regmap,
50+
.get_current_limit = regulator_get_current_limit_regmap,
51+
.set_current_limit = regulator_set_current_limit_regmap,
52+
.set_active_discharge = regulator_set_active_discharge_regmap,
53+
.set_soft_start = regulator_set_soft_start_regmap,
54+
};
55+
56+
static const struct linear_range max77503_buck_ranges[] = {
57+
REGULATOR_LINEAR_RANGE(800000, 0x00, 0x54, 50000)
58+
};
59+
60+
static const unsigned int max77503_current_limit_table[] = {
61+
500000, 2000000
62+
};
63+
64+
static const struct regulator_desc max77503_regulators_desc = {
65+
.name = "max77503",
66+
.enable_reg = MAX77503_REG_CFG,
67+
.enable_mask = MAX77503_BIT_EN,
68+
.ops = &max77503_buck_ops,
69+
.type = REGULATOR_VOLTAGE,
70+
.linear_ranges = max77503_buck_ranges,
71+
.n_linear_ranges = ARRAY_SIZE(max77503_buck_ranges),
72+
.vsel_reg = MAX77503_REG_VOUT,
73+
.vsel_mask = MAX77503_BITS_MX_VOUT,
74+
.soft_start_reg = MAX77503_REG_CFG,
75+
.soft_start_mask = MAX77503_BITS_SOFT_START,
76+
.active_discharge_reg = MAX77503_REG_CFG,
77+
.active_discharge_mask = MAX77503_BIT_ADEN,
78+
.active_discharge_off = MAX77503_AD_DISABLED,
79+
.active_discharge_on = MAX77503_AD_ENABLED,
80+
.csel_reg = MAX77503_REG_CFG,
81+
.csel_mask = MAX77503_BIT_CURR_LIM,
82+
.curr_table = max77503_current_limit_table,
83+
.n_current_limits = ARRAY_SIZE(max77503_current_limit_table),
84+
.owner = THIS_MODULE,
85+
};
86+
87+
static int max77503_regulator_probe(struct i2c_client *client)
88+
{
89+
struct device *dev = &client->dev;
90+
struct regulator_config config = {};
91+
struct regulator_dev *rdev;
92+
93+
config.dev = dev;
94+
config.of_node = dev->of_node;
95+
config.regmap = devm_regmap_init_i2c(client, &max77503_regmap_config);
96+
if (IS_ERR(config.regmap)) {
97+
dev_err(dev, "Failed to init regmap");
98+
return PTR_ERR(config.regmap);
99+
}
100+
101+
rdev = devm_regulator_register(dev, &max77503_regulators_desc, &config);
102+
if (IS_ERR(rdev)) {
103+
dev_err(dev, "Failed to register regulator MAX77503");
104+
return PTR_ERR(rdev);
105+
}
106+
107+
return 0;
108+
}
109+
110+
static const struct of_device_id of_max77503_match_tbl[] = {
111+
{ .compatible = "adi,max77503", },
112+
{ }
113+
};
114+
115+
MODULE_DEVICE_TABLE(of, of_max77503_match_tbl);
116+
117+
static const struct i2c_device_id max77503_regulator_id[] = {
118+
{"max77503"},
119+
{ }
120+
};
121+
122+
MODULE_DEVICE_TABLE(i2c, max77503_regulator_id);
123+
124+
static struct i2c_driver max77503_regulator_driver = {
125+
.driver = {
126+
.name = "max77503",
127+
.of_match_table = of_max77503_match_tbl
128+
},
129+
.probe = max77503_regulator_probe,
130+
.id_table = max77503_regulator_id,
131+
};
132+
133+
module_i2c_driver(max77503_regulator_driver);
134+
135+
MODULE_AUTHOR("Gokhan Celik <[email protected]>");
136+
MODULE_DESCRIPTION("MAX77503 regulator driver");
137+
MODULE_LICENSE("GPL");

0 commit comments

Comments
 (0)