1 // SPDX-License-Identifier: GPL-2.0+
2 #include <linux/module.h>
5 #include <linux/regmap.h>
6 #include <linux/regulator/driver.h>
8 static const struct regulator_ops max8893_ops = {
9 .is_enabled = regulator_is_enabled_regmap,
10 .enable = regulator_enable_regmap,
11 .disable = regulator_disable_regmap,
12 .get_voltage_sel = regulator_get_voltage_sel_regmap,
13 .set_voltage_sel = regulator_set_voltage_sel_regmap,
14 .list_voltage = regulator_list_voltage_linear,
15 .map_voltage = regulator_map_voltage_linear,
18 static const struct regulator_desc max8893_regulators[] = {
21 .supply_name = "in-buck",
22 .of_match = of_match_ptr("buck"),
23 .regulators_node = of_match_ptr("regulators"),
27 .type = REGULATOR_VOLTAGE,
34 .enable_mask = BIT(7),
38 .supply_name = "in-ldo1",
39 .of_match = of_match_ptr("ldo1"),
40 .regulators_node = of_match_ptr("regulators"),
44 .type = REGULATOR_VOLTAGE,
51 .enable_mask = BIT(5),
55 .supply_name = "in-ldo2",
56 .of_match = of_match_ptr("ldo2"),
57 .regulators_node = of_match_ptr("regulators"),
61 .type = REGULATOR_VOLTAGE,
68 .enable_mask = BIT(4),
72 .supply_name = "in-ldo3",
73 .of_match = of_match_ptr("ldo3"),
74 .regulators_node = of_match_ptr("regulators"),
78 .type = REGULATOR_VOLTAGE,
85 .enable_mask = BIT(3),
89 .supply_name = "in-ldo4",
90 .of_match = of_match_ptr("ldo4"),
91 .regulators_node = of_match_ptr("regulators"),
95 .type = REGULATOR_VOLTAGE,
102 .enable_mask = BIT(2),
106 .supply_name = "in-ldo5",
107 .of_match = of_match_ptr("ldo5"),
108 .regulators_node = of_match_ptr("regulators"),
112 .type = REGULATOR_VOLTAGE,
113 .owner = THIS_MODULE,
119 .enable_mask = BIT(1),
123 static const struct regmap_config max8893_regmap = {
128 static int max8893_probe_new(struct i2c_client *i2c)
131 struct regulator_config config = {.dev = &i2c->dev};
132 struct regmap *regmap = devm_regmap_init_i2c(i2c, &max8893_regmap);
134 if (IS_ERR(regmap)) {
135 ret = PTR_ERR(regmap);
136 dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
140 for (id = 0; id < ARRAY_SIZE(max8893_regulators); id++) {
141 struct regulator_dev *rdev;
142 rdev = devm_regulator_register(&i2c->dev,
143 &max8893_regulators[id],
147 dev_err(&i2c->dev, "failed to register %s: %d\n",
148 max8893_regulators[id].name, ret);
157 static const struct of_device_id max8893_dt_match[] = {
158 { .compatible = "maxim,max8893" },
161 MODULE_DEVICE_TABLE(of, max8893_dt_match);
164 static const struct i2c_device_id max8893_ids[] = {
168 MODULE_DEVICE_TABLE(i2c, max8893_ids);
170 static struct i2c_driver max8893_driver = {
171 .probe_new = max8893_probe_new,
174 .of_match_table = of_match_ptr(max8893_dt_match),
176 .id_table = max8893_ids,
179 module_i2c_driver(max8893_driver);
181 MODULE_DESCRIPTION("Maxim MAX8893 PMIC driver");
182 MODULE_AUTHOR("Sergey Larin <cerg2010cerg2010@mail.ru>");
183 MODULE_LICENSE("GPL");