1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2022 Analog Devices, Inc.
4 * ADI Regulator driver for the MAX77540 and MAX77541
7 #include <linux/mfd/max77541.h>
8 #include <linux/mod_devicetable.h>
9 #include <linux/platform_device.h>
10 #include <linux/regmap.h>
11 #include <linux/regulator/driver.h>
13 static const struct regulator_ops max77541_buck_ops = {
14 .enable = regulator_enable_regmap,
15 .disable = regulator_disable_regmap,
16 .is_enabled = regulator_is_enabled_regmap,
17 .list_voltage = regulator_list_voltage_pickable_linear_range,
18 .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap,
19 .set_voltage_sel = regulator_set_voltage_sel_pickable_regmap,
22 static const struct linear_range max77540_buck_ranges[] = {
23 /* Ranges when VOLT_SEL bits are 0x00 */
24 REGULATOR_LINEAR_RANGE(500000, 0x00, 0x8B, 5000),
25 REGULATOR_LINEAR_RANGE(1200000, 0x8C, 0xFF, 0),
26 /* Ranges when VOLT_SEL bits are 0x40 */
27 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x8B, 10000),
28 REGULATOR_LINEAR_RANGE(2400000, 0x8C, 0xFF, 0),
29 /* Ranges when VOLT_SEL bits are 0x80 */
30 REGULATOR_LINEAR_RANGE(2000000, 0x00, 0x9F, 20000),
31 REGULATOR_LINEAR_RANGE(5200000, 0xA0, 0xFF, 0),
34 static const struct linear_range max77541_buck_ranges[] = {
35 /* Ranges when VOLT_SEL bits are 0x00 */
36 REGULATOR_LINEAR_RANGE(300000, 0x00, 0xB3, 5000),
37 REGULATOR_LINEAR_RANGE(1200000, 0xB4, 0xFF, 0),
38 /* Ranges when VOLT_SEL bits are 0x40 */
39 REGULATOR_LINEAR_RANGE(1200000, 0x00, 0x8B, 10000),
40 REGULATOR_LINEAR_RANGE(2400000, 0x8C, 0xFF, 0),
41 /* Ranges when VOLT_SEL bits are 0x80 */
42 REGULATOR_LINEAR_RANGE(2000000, 0x00, 0x9F, 20000),
43 REGULATOR_LINEAR_RANGE(5200000, 0xA0, 0xFF, 0),
46 static const unsigned int max77541_buck_volt_range_sel[] = {
47 0x0, 0x0, 0x1, 0x1, 0x2, 0x2,
50 enum max77541_regulators {
55 #define MAX77540_BUCK(_id, _ops) \
56 { .id = MAX77541_BUCK ## _id, \
58 .of_match = "buck"#_id, \
59 .regulators_node = "regulators", \
60 .enable_reg = MAX77541_REG_EN_CTRL, \
61 .enable_mask = MAX77541_BIT_M ## _id ## _EN, \
63 .type = REGULATOR_VOLTAGE, \
64 .linear_ranges = max77540_buck_ranges, \
65 .n_linear_ranges = ARRAY_SIZE(max77540_buck_ranges), \
66 .vsel_reg = MAX77541_REG_M ## _id ## _VOUT, \
67 .vsel_mask = MAX77541_BITS_MX_VOUT, \
68 .vsel_range_reg = MAX77541_REG_M ## _id ## _CFG1, \
69 .vsel_range_mask = MAX77541_BITS_MX_CFG1_RNG, \
70 .linear_range_selectors_bitfield = max77541_buck_volt_range_sel, \
71 .owner = THIS_MODULE, \
74 #define MAX77541_BUCK(_id, _ops) \
75 { .id = MAX77541_BUCK ## _id, \
77 .of_match = "buck"#_id, \
78 .regulators_node = "regulators", \
79 .enable_reg = MAX77541_REG_EN_CTRL, \
80 .enable_mask = MAX77541_BIT_M ## _id ## _EN, \
82 .type = REGULATOR_VOLTAGE, \
83 .linear_ranges = max77541_buck_ranges, \
84 .n_linear_ranges = ARRAY_SIZE(max77541_buck_ranges), \
85 .vsel_reg = MAX77541_REG_M ## _id ## _VOUT, \
86 .vsel_mask = MAX77541_BITS_MX_VOUT, \
87 .vsel_range_reg = MAX77541_REG_M ## _id ## _CFG1, \
88 .vsel_range_mask = MAX77541_BITS_MX_CFG1_RNG, \
89 .linear_range_selectors_bitfield = max77541_buck_volt_range_sel, \
90 .owner = THIS_MODULE, \
93 static const struct regulator_desc max77540_regulators_desc[] = {
94 MAX77540_BUCK(1, max77541_buck_ops),
95 MAX77540_BUCK(2, max77541_buck_ops),
98 static const struct regulator_desc max77541_regulators_desc[] = {
99 MAX77541_BUCK(1, max77541_buck_ops),
100 MAX77541_BUCK(2, max77541_buck_ops),
103 static int max77541_regulator_probe(struct platform_device *pdev)
105 struct regulator_config config = {};
106 const struct regulator_desc *desc;
107 struct device *dev = &pdev->dev;
108 struct regulator_dev *rdev;
109 struct max77541 *max77541 = dev_get_drvdata(dev->parent);
112 config.dev = dev->parent;
114 switch (max77541->id) {
116 desc = max77540_regulators_desc;
119 desc = max77541_regulators_desc;
125 for (i = 0; i < MAX77541_MAX_REGULATORS; i++) {
126 rdev = devm_regulator_register(dev, &desc[i], &config);
128 return dev_err_probe(dev, PTR_ERR(rdev),
129 "Failed to register regulator\n");
135 static const struct platform_device_id max77541_regulator_platform_id[] = {
136 { "max77540-regulator" },
137 { "max77541-regulator" },
140 MODULE_DEVICE_TABLE(platform, max77541_regulator_platform_id);
142 static struct platform_driver max77541_regulator_driver = {
144 .name = "max77541-regulator",
146 .probe = max77541_regulator_probe,
147 .id_table = max77541_regulator_platform_id,
149 module_platform_driver(max77541_regulator_driver);
151 MODULE_AUTHOR("Okan Sahin <Okan.Sahin@analog.com>");
152 MODULE_DESCRIPTION("MAX77540/MAX77541 regulator driver");
153 MODULE_LICENSE("GPL");