1 // SPDX-License-Identifier: GPL-2.0+
2 #include <linux/module.h>
4 #include <linux/regmap.h>
5 #include <linux/regulator/driver.h>
7 enum fan53880_regulator_ids
{
16 enum fan53880_registers
{
17 FAN53880_PRODUCT_ID
= 0x00,
27 FAN53880_ENABLE_BOOST
,
30 #define FAN53880_ID 0x01
32 static const struct regulator_ops fan53880_ops
= {
33 .list_voltage
= regulator_list_voltage_linear_range
,
34 .map_voltage
= regulator_map_voltage_linear_range
,
35 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
36 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
37 .enable
= regulator_enable_regmap
,
38 .disable
= regulator_disable_regmap
,
39 .is_enabled
= regulator_is_enabled_regmap
,
42 #define FAN53880_LDO(_num, _supply, _default) \
43 [FAN53880_LDO ## _num] = { \
45 .of_match = "LDO"#_num, \
46 .regulators_node = "regulators", \
47 .type = REGULATOR_VOLTAGE, \
48 .owner = THIS_MODULE, \
49 .linear_ranges = (struct linear_range[]) { \
50 REGULATOR_LINEAR_RANGE(_default, 0x0, 0x0, 0), \
51 REGULATOR_LINEAR_RANGE(800000, 0xf, 0x73, 25000), \
53 .n_linear_ranges = 2, \
55 .vsel_reg = FAN53880_LDO ## _num ## VOUT, \
57 .enable_reg = FAN53880_ENABLE, \
58 .enable_mask = BIT(_num - 1), \
60 .supply_name = _supply, \
61 .ops = &fan53880_ops, \
64 static const struct regulator_desc fan53880_regulators
[] = {
65 FAN53880_LDO(1, "VIN12", 2800000),
66 FAN53880_LDO(2, "VIN12", 2800000),
67 FAN53880_LDO(3, "VIN3", 1800000),
68 FAN53880_LDO(4, "VIN4", 1800000),
72 .regulators_node
= "regulators",
73 .type
= REGULATOR_VOLTAGE
,
75 .linear_ranges
= (struct linear_range
[]) {
76 REGULATOR_LINEAR_RANGE(1100000, 0x0, 0x0, 0),
77 REGULATOR_LINEAR_RANGE(600000, 0x1f, 0xf7, 12500),
81 .vsel_reg
= FAN53880_BUCKVOUT
,
83 .enable_reg
= FAN53880_ENABLE
,
86 .supply_name
= "PVIN",
92 .regulators_node
= "regulators",
93 .type
= REGULATOR_VOLTAGE
,
95 .linear_ranges
= (struct linear_range
[]) {
96 REGULATOR_LINEAR_RANGE(5000000, 0x0, 0x0, 0),
97 REGULATOR_LINEAR_RANGE(3000000, 0x4, 0x70, 25000),
101 .vsel_reg
= FAN53880_BOOSTVOUT
,
103 .enable_reg
= FAN53880_ENABLE_BOOST
,
106 .supply_name
= "PVIN",
107 .ops
= &fan53880_ops
,
111 static const struct regmap_config fan53880_regmap
= {
114 .max_register
= FAN53880_ENABLE_BOOST
,
117 static int fan53880_i2c_probe(struct i2c_client
*i2c
)
119 struct regulator_config config
= { };
120 struct regulator_dev
*rdev
;
121 struct regmap
*regmap
;
125 regmap
= devm_regmap_init_i2c(i2c
, &fan53880_regmap
);
126 if (IS_ERR(regmap
)) {
127 ret
= PTR_ERR(regmap
);
128 dev_err(&i2c
->dev
, "Failed to create regmap: %d\n", ret
);
132 ret
= regmap_read(regmap
, FAN53880_PRODUCT_ID
, &data
);
134 dev_err(&i2c
->dev
, "Failed to read PRODUCT_ID: %d\n", ret
);
137 if (data
!= FAN53880_ID
) {
138 dev_err(&i2c
->dev
, "Unsupported device id: 0x%x.\n", data
);
142 config
.dev
= &i2c
->dev
;
143 config
.init_data
= NULL
;
145 for (i
= 0; i
< ARRAY_SIZE(fan53880_regulators
); i
++) {
146 rdev
= devm_regulator_register(&i2c
->dev
,
147 &fan53880_regulators
[i
],
151 dev_err(&i2c
->dev
, "Failed to register %s: %d\n",
152 fan53880_regulators
[i
].name
, ret
);
160 static const struct of_device_id fan53880_dt_ids
[] = {
161 { .compatible
= "onnn,fan53880", },
164 MODULE_DEVICE_TABLE(of
, fan53880_dt_ids
);
166 static const struct i2c_device_id fan53880_i2c_id
[] = {
170 MODULE_DEVICE_TABLE(i2c
, fan53880_i2c_id
);
172 static struct i2c_driver fan53880_regulator_driver
= {
175 .probe_type
= PROBE_PREFER_ASYNCHRONOUS
,
176 .of_match_table
= fan53880_dt_ids
,
178 .probe
= fan53880_i2c_probe
,
179 .id_table
= fan53880_i2c_id
,
181 module_i2c_driver(fan53880_regulator_driver
);
183 MODULE_DESCRIPTION("FAN53880 PMIC voltage regulator driver");
184 MODULE_AUTHOR("Christoph Fritz <chf.fritz@googlemail.com>");
185 MODULE_LICENSE("GPL");