Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 #include <linux/module.h>
0003 #include <linux/i2c.h>
0004 #include <linux/of.h>
0005 #include <linux/regmap.h>
0006 #include <linux/regulator/driver.h>
0007 
0008 static const struct regulator_ops max8893_ops = {
0009     .is_enabled     = regulator_is_enabled_regmap,
0010     .enable         = regulator_enable_regmap,
0011     .disable        = regulator_disable_regmap,
0012     .get_voltage_sel    = regulator_get_voltage_sel_regmap,
0013     .set_voltage_sel    = regulator_set_voltage_sel_regmap,
0014     .list_voltage       = regulator_list_voltage_linear,
0015     .map_voltage        = regulator_map_voltage_linear,
0016 };
0017 
0018 static const struct regulator_desc max8893_regulators[] = {
0019     {
0020         .name = "BUCK",
0021         .supply_name = "in-buck",
0022         .of_match = of_match_ptr("buck"),
0023         .regulators_node = of_match_ptr("regulators"),
0024         .n_voltages = 0x11,
0025         .id = 6,
0026         .ops = &max8893_ops,
0027         .type = REGULATOR_VOLTAGE,
0028         .owner = THIS_MODULE,
0029         .min_uV = 800000,
0030         .uV_step = 100000,
0031         .vsel_reg = 0x4,
0032         .vsel_mask = 0x1f,
0033         .enable_reg = 0x0,
0034         .enable_mask = BIT(7),
0035     },
0036     {
0037         .name = "LDO1",
0038         .supply_name = "in-ldo1",
0039         .of_match = of_match_ptr("ldo1"),
0040         .regulators_node = of_match_ptr("regulators"),
0041         .n_voltages = 0x12,
0042         .id = 1,
0043         .ops = &max8893_ops,
0044         .type = REGULATOR_VOLTAGE,
0045         .owner = THIS_MODULE,
0046         .min_uV = 1600000,
0047         .uV_step = 100000,
0048         .vsel_reg = 0x5,
0049         .vsel_mask = 0x1f,
0050         .enable_reg = 0x0,
0051         .enable_mask = BIT(5),
0052     },
0053     {
0054         .name = "LDO2",
0055         .supply_name = "in-ldo2",
0056         .of_match = of_match_ptr("ldo2"),
0057         .regulators_node = of_match_ptr("regulators"),
0058         .n_voltages = 0x16,
0059         .id = 2,
0060         .ops = &max8893_ops,
0061         .type = REGULATOR_VOLTAGE,
0062         .owner = THIS_MODULE,
0063         .min_uV = 1200000,
0064         .uV_step = 100000,
0065         .vsel_reg = 0x6,
0066         .vsel_mask = 0x1f,
0067         .enable_reg = 0x0,
0068         .enable_mask = BIT(4),
0069     },
0070     {
0071         .name = "LDO3",
0072         .supply_name = "in-ldo3",
0073         .of_match = of_match_ptr("ldo3"),
0074         .regulators_node = of_match_ptr("regulators"),
0075         .n_voltages = 0x12,
0076         .id = 3,
0077         .ops = &max8893_ops,
0078         .type = REGULATOR_VOLTAGE,
0079         .owner = THIS_MODULE,
0080         .min_uV = 1600000,
0081         .uV_step = 100000,
0082         .vsel_reg = 0x7,
0083         .vsel_mask = 0x1f,
0084         .enable_reg = 0x0,
0085         .enable_mask = BIT(3),
0086     },
0087     {
0088         .name = "LDO4",
0089         .supply_name = "in-ldo4",
0090         .of_match = of_match_ptr("ldo4"),
0091         .regulators_node = of_match_ptr("regulators"),
0092         .n_voltages = 0x1a,
0093         .id = 4,
0094         .ops = &max8893_ops,
0095         .type = REGULATOR_VOLTAGE,
0096         .owner = THIS_MODULE,
0097         .min_uV = 800000,
0098         .uV_step = 100000,
0099         .vsel_reg = 0x8,
0100         .vsel_mask = 0x1f,
0101         .enable_reg = 0x0,
0102         .enable_mask = BIT(2),
0103     },
0104     {
0105         .name = "LDO5",
0106         .supply_name = "in-ldo5",
0107         .of_match = of_match_ptr("ldo5"),
0108         .regulators_node = of_match_ptr("regulators"),
0109         .n_voltages = 0x1a,
0110         .id = 5,
0111         .ops = &max8893_ops,
0112         .type = REGULATOR_VOLTAGE,
0113         .owner = THIS_MODULE,
0114         .min_uV = 800000,
0115         .uV_step = 100000,
0116         .vsel_reg = 0x9,
0117         .vsel_mask = 0x1f,
0118         .enable_reg = 0x0,
0119         .enable_mask = BIT(1),
0120     }
0121 };
0122 
0123 static const struct regmap_config max8893_regmap = {
0124     .reg_bits = 8,
0125     .val_bits = 8,
0126 };
0127 
0128 static int max8893_probe_new(struct i2c_client *i2c)
0129 {
0130     int id, ret;
0131     struct regulator_config config = {.dev = &i2c->dev};
0132     struct regmap *regmap = devm_regmap_init_i2c(i2c, &max8893_regmap);
0133 
0134     if (IS_ERR(regmap)) {
0135         ret = PTR_ERR(regmap);
0136         dev_err(&i2c->dev, "regmap init failed: %d\n", ret);
0137         return ret;
0138     }
0139 
0140     for (id = 0; id < ARRAY_SIZE(max8893_regulators); id++) {
0141         struct regulator_dev *rdev;
0142         rdev = devm_regulator_register(&i2c->dev,
0143                            &max8893_regulators[id],
0144                            &config);
0145         if (IS_ERR(rdev)) {
0146             ret = PTR_ERR(rdev);
0147             dev_err(&i2c->dev, "failed to register %s: %d\n",
0148                 max8893_regulators[id].name, ret);
0149             return ret;
0150         }
0151     }
0152 
0153     return 0;
0154 }
0155 
0156 #ifdef CONFIG_OF
0157 static const struct of_device_id max8893_dt_match[] = {
0158     { .compatible = "maxim,max8893" },
0159     { /* sentinel */ },
0160 };
0161 MODULE_DEVICE_TABLE(of, max8893_dt_match);
0162 #endif
0163 
0164 static const struct i2c_device_id max8893_ids[] = {
0165     { "max8893", 0 },
0166     { },
0167 };
0168 MODULE_DEVICE_TABLE(i2c, max8893_ids);
0169 
0170 static struct i2c_driver max8893_driver = {
0171     .probe_new  = max8893_probe_new,
0172     .driver     = {
0173         .name   = "max8893",
0174         .of_match_table = of_match_ptr(max8893_dt_match),
0175     },
0176     .id_table   = max8893_ids,
0177 };
0178 
0179 module_i2c_driver(max8893_driver);
0180 
0181 MODULE_DESCRIPTION("Maxim MAX8893 PMIC driver");
0182 MODULE_AUTHOR("Sergey Larin <cerg2010cerg2010@mail.ru>");
0183 MODULE_LICENSE("GPL");