1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/module.h>
5 #include <linux/regulator/driver.h>
6 #include <linux/regmap.h>
8 static const struct regulator_ops pg86x_ops
= {
9 .set_voltage_sel
= regulator_set_voltage_sel_regmap
,
10 .get_voltage_sel
= regulator_get_voltage_sel_regmap
,
11 .list_voltage
= regulator_list_voltage_linear_range
,
14 static const struct linear_range pg86x_buck1_ranges
[] = {
15 REGULATOR_LINEAR_RANGE( 0, 0, 10, 0),
16 REGULATOR_LINEAR_RANGE(1000000, 11, 34, 25000),
17 REGULATOR_LINEAR_RANGE(1600000, 35, 47, 50000),
20 static const struct linear_range pg86x_buck2_ranges
[] = {
21 REGULATOR_LINEAR_RANGE( 0, 0, 15, 0),
22 REGULATOR_LINEAR_RANGE(1000000, 16, 39, 25000),
23 REGULATOR_LINEAR_RANGE(1600000, 40, 52, 50000),
26 static const struct regulator_desc pg86x_regulators
[] = {
29 .type
= REGULATOR_VOLTAGE
,
31 .of_match
= of_match_ptr("buck1"),
32 .n_voltages
= 11 + 24 + 13,
33 .linear_ranges
= pg86x_buck1_ranges
,
42 .type
= REGULATOR_VOLTAGE
,
44 .of_match
= of_match_ptr("buck2"),
45 .n_voltages
= 16 + 24 + 13,
46 .linear_ranges
= pg86x_buck2_ranges
,
55 static const struct regmap_config pg86x_regmap
= {
60 static int pg86x_i2c_probe(struct i2c_client
*i2c
)
63 struct regulator_config config
= {.dev
= &i2c
->dev
};
64 struct regmap
*regmap
= devm_regmap_init_i2c(i2c
, &pg86x_regmap
);
67 ret
= PTR_ERR(regmap
);
68 dev_err(&i2c
->dev
, "regmap init failed: %d\n", ret
);
72 for (id
= 0; id
< ARRAY_SIZE(pg86x_regulators
); id
++) {
73 struct regulator_dev
*rdev
;
74 rdev
= devm_regulator_register(&i2c
->dev
,
75 &pg86x_regulators
[id
],
79 dev_err(&i2c
->dev
, "failed to register %s: %d\n",
80 pg86x_regulators
[id
].name
, ret
);
87 static const struct of_device_id __maybe_unused pg86x_dt_ids
[] = {
88 { .compatible
= "marvell,88pg867" },
89 { .compatible
= "marvell,88pg868" },
92 MODULE_DEVICE_TABLE(of
, pg86x_dt_ids
);
94 static const struct i2c_device_id pg86x_i2c_id
[] = {
99 MODULE_DEVICE_TABLE(i2c
, pg86x_i2c_id
);
101 static struct i2c_driver pg86x_regulator_driver
= {
104 .of_match_table
= of_match_ptr(pg86x_dt_ids
),
106 .probe_new
= pg86x_i2c_probe
,
107 .id_table
= pg86x_i2c_id
,
110 module_i2c_driver(pg86x_regulator_driver
);
112 MODULE_DESCRIPTION("Marvell 88PG86X voltage regulator");
113 MODULE_AUTHOR("Alexander Monakov <amonakov@gmail.com>");
114 MODULE_LICENSE("GPL");