1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2023 Analog Devices, Inc.
4 * ADI regulator driver for MAX77503.
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>
15 #define MAX77503_REG_CFG 0x00
16 #define MAX77503_REG_VOUT 0x01
18 #define MAX77503_BIT_EN BIT(0)
19 #define MAX77503_BIT_CURR_LIM BIT(3)
20 #define MAX77503_BIT_ADEN BIT(6)
22 #define MAX77503_BITS_SOFT_START GENMASK(5, 4)
23 #define MAX77503_BITS_MX_VOUT GENMASK(7, 0)
25 #define MAX77503_AD_ENABLED 0x1
26 #define MAX77503_AD_DISABLED 0x0
28 static const struct regmap_config max77503_regmap_config
= {
34 static const struct regulator_ops max77503_buck_ops
= {
35 .list_voltage
= regulator_list_voltage_linear_range
,
36 .map_voltage
= regulator_map_voltage_ascend
,
37 .is_enabled
= regulator_is_enabled_regmap
,
38 .enable
= regulator_enable_regmap
,
39 .disable
= regulator_disable_regmap
,
40 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
41 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
42 .get_current_limit
= regulator_get_current_limit_regmap
,
43 .set_current_limit
= regulator_set_current_limit_regmap
,
44 .set_active_discharge
= regulator_set_active_discharge_regmap
,
45 .set_soft_start
= regulator_set_soft_start_regmap
,
48 static const struct linear_range max77503_buck_ranges
[] = {
49 REGULATOR_LINEAR_RANGE(800000, 0x00, 0x54, 50000)
52 static const unsigned int max77503_current_limit_table
[] = {
56 static const struct regulator_desc max77503_regulators_desc
= {
58 .enable_reg
= MAX77503_REG_CFG
,
59 .enable_mask
= MAX77503_BIT_EN
,
60 .ops
= &max77503_buck_ops
,
61 .type
= REGULATOR_VOLTAGE
,
62 .linear_ranges
= max77503_buck_ranges
,
63 .n_linear_ranges
= ARRAY_SIZE(max77503_buck_ranges
),
64 .vsel_reg
= MAX77503_REG_VOUT
,
65 .vsel_mask
= MAX77503_BITS_MX_VOUT
,
66 .soft_start_reg
= MAX77503_REG_CFG
,
67 .soft_start_mask
= MAX77503_BITS_SOFT_START
,
68 .active_discharge_reg
= MAX77503_REG_CFG
,
69 .active_discharge_mask
= MAX77503_BIT_ADEN
,
70 .active_discharge_off
= MAX77503_AD_DISABLED
,
71 .active_discharge_on
= MAX77503_AD_ENABLED
,
72 .csel_reg
= MAX77503_REG_CFG
,
73 .csel_mask
= MAX77503_BIT_CURR_LIM
,
74 .curr_table
= max77503_current_limit_table
,
75 .n_current_limits
= ARRAY_SIZE(max77503_current_limit_table
),
79 static int max77503_regulator_probe(struct i2c_client
*client
)
81 struct device
*dev
= &client
->dev
;
82 struct regulator_config config
= {};
83 struct regulator_dev
*rdev
;
86 config
.of_node
= dev
->of_node
;
87 config
.regmap
= devm_regmap_init_i2c(client
, &max77503_regmap_config
);
88 if (IS_ERR(config
.regmap
)) {
89 dev_err(dev
, "Failed to init regmap");
90 return PTR_ERR(config
.regmap
);
93 rdev
= devm_regulator_register(dev
, &max77503_regulators_desc
, &config
);
95 dev_err(dev
, "Failed to register regulator MAX77503");
102 static const struct of_device_id of_max77503_match_tbl
[] = {
103 { .compatible
= "adi,max77503", },
107 MODULE_DEVICE_TABLE(of
, of_max77503_match_tbl
);
109 static const struct i2c_device_id max77503_regulator_id
[] = {
114 MODULE_DEVICE_TABLE(i2c
, max77503_regulator_id
);
116 static struct i2c_driver max77503_regulator_driver
= {
119 .of_match_table
= of_max77503_match_tbl
121 .probe
= max77503_regulator_probe
,
122 .id_table
= max77503_regulator_id
,
125 module_i2c_driver(max77503_regulator_driver
);
127 MODULE_AUTHOR("Gokhan Celik <Gokhan.Celik@analog.com>");
128 MODULE_DESCRIPTION("MAX77503 regulator driver");
129 MODULE_LICENSE("GPL");