0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #include <linux/module.h>
0013 #include <linux/mod_devicetable.h>
0014 #include <linux/platform_device.h>
0015 #include <linux/regulator/driver.h>
0016
0017 #include <linux/mfd/tps65912.h>
0018
0019 enum tps65912_regulators { DCDC1, DCDC2, DCDC3, DCDC4, LDO1, LDO2, LDO3,
0020 LDO4, LDO5, LDO6, LDO7, LDO8, LDO9, LDO10 };
0021
0022 #define TPS65912_REGULATOR(_name, _id, _of_match, _ops, _vr, _er, _lr) \
0023 [_id] = { \
0024 .name = _name, \
0025 .of_match = _of_match, \
0026 .regulators_node = "regulators", \
0027 .id = _id, \
0028 .ops = &_ops, \
0029 .n_voltages = 64, \
0030 .type = REGULATOR_VOLTAGE, \
0031 .owner = THIS_MODULE, \
0032 .vsel_reg = _vr, \
0033 .vsel_mask = 0x3f, \
0034 .enable_reg = _er, \
0035 .enable_mask = BIT(7), \
0036 .volt_table = NULL, \
0037 .linear_ranges = _lr, \
0038 .n_linear_ranges = ARRAY_SIZE(_lr), \
0039 }
0040
0041 static const struct linear_range tps65912_dcdc_ranges[] = {
0042 REGULATOR_LINEAR_RANGE(500000, 0x0, 0x3f, 50000),
0043 };
0044
0045 static const struct linear_range tps65912_ldo_ranges[] = {
0046 REGULATOR_LINEAR_RANGE(800000, 0x0, 0x20, 25000),
0047 REGULATOR_LINEAR_RANGE(1650000, 0x21, 0x3c, 50000),
0048 REGULATOR_LINEAR_RANGE(3100000, 0x3d, 0x3f, 100000),
0049 };
0050
0051
0052 static const struct regulator_ops tps65912_ops_dcdc = {
0053 .is_enabled = regulator_is_enabled_regmap,
0054 .enable = regulator_enable_regmap,
0055 .disable = regulator_disable_regmap,
0056 .get_voltage_sel = regulator_get_voltage_sel_regmap,
0057 .set_voltage_sel = regulator_set_voltage_sel_regmap,
0058 .list_voltage = regulator_list_voltage_linear_range,
0059 };
0060
0061
0062 static const struct regulator_ops tps65912_ops_ldo = {
0063 .is_enabled = regulator_is_enabled_regmap,
0064 .enable = regulator_enable_regmap,
0065 .disable = regulator_disable_regmap,
0066 .get_voltage_sel = regulator_get_voltage_sel_regmap,
0067 .set_voltage_sel = regulator_set_voltage_sel_regmap,
0068 .list_voltage = regulator_list_voltage_linear_range,
0069 .map_voltage = regulator_map_voltage_linear_range,
0070 };
0071
0072 static const struct regulator_desc regulators[] = {
0073 TPS65912_REGULATOR("DCDC1", DCDC1, "dcdc1", tps65912_ops_dcdc,
0074 TPS65912_DCDC1_OP, TPS65912_DCDC1_CTRL,
0075 tps65912_dcdc_ranges),
0076 TPS65912_REGULATOR("DCDC2", DCDC2, "dcdc2", tps65912_ops_dcdc,
0077 TPS65912_DCDC2_OP, TPS65912_DCDC2_CTRL,
0078 tps65912_dcdc_ranges),
0079 TPS65912_REGULATOR("DCDC3", DCDC3, "dcdc3", tps65912_ops_dcdc,
0080 TPS65912_DCDC3_OP, TPS65912_DCDC3_CTRL,
0081 tps65912_dcdc_ranges),
0082 TPS65912_REGULATOR("DCDC4", DCDC4, "dcdc4", tps65912_ops_dcdc,
0083 TPS65912_DCDC4_OP, TPS65912_DCDC4_CTRL,
0084 tps65912_dcdc_ranges),
0085 TPS65912_REGULATOR("LDO1", LDO1, "ldo1", tps65912_ops_ldo,
0086 TPS65912_LDO1_OP, TPS65912_LDO1_AVS,
0087 tps65912_ldo_ranges),
0088 TPS65912_REGULATOR("LDO2", LDO2, "ldo2", tps65912_ops_ldo,
0089 TPS65912_LDO2_OP, TPS65912_LDO2_AVS,
0090 tps65912_ldo_ranges),
0091 TPS65912_REGULATOR("LDO3", LDO3, "ldo3", tps65912_ops_ldo,
0092 TPS65912_LDO3_OP, TPS65912_LDO3_AVS,
0093 tps65912_ldo_ranges),
0094 TPS65912_REGULATOR("LDO4", LDO4, "ldo4", tps65912_ops_ldo,
0095 TPS65912_LDO4_OP, TPS65912_LDO4_AVS,
0096 tps65912_ldo_ranges),
0097 TPS65912_REGULATOR("LDO5", LDO5, "ldo5", tps65912_ops_ldo,
0098 TPS65912_LDO5, TPS65912_LDO5,
0099 tps65912_ldo_ranges),
0100 TPS65912_REGULATOR("LDO6", LDO6, "ldo6", tps65912_ops_ldo,
0101 TPS65912_LDO6, TPS65912_LDO6,
0102 tps65912_ldo_ranges),
0103 TPS65912_REGULATOR("LDO7", LDO7, "ldo7", tps65912_ops_ldo,
0104 TPS65912_LDO7, TPS65912_LDO7,
0105 tps65912_ldo_ranges),
0106 TPS65912_REGULATOR("LDO8", LDO8, "ldo8", tps65912_ops_ldo,
0107 TPS65912_LDO8, TPS65912_LDO8,
0108 tps65912_ldo_ranges),
0109 TPS65912_REGULATOR("LDO9", LDO9, "ldo9", tps65912_ops_ldo,
0110 TPS65912_LDO9, TPS65912_LDO9,
0111 tps65912_ldo_ranges),
0112 TPS65912_REGULATOR("LDO10", LDO10, "ldo10", tps65912_ops_ldo,
0113 TPS65912_LDO10, TPS65912_LDO10,
0114 tps65912_ldo_ranges),
0115 };
0116
0117 static int tps65912_regulator_probe(struct platform_device *pdev)
0118 {
0119 struct tps65912 *tps = dev_get_drvdata(pdev->dev.parent);
0120 struct regulator_config config = { };
0121 struct regulator_dev *rdev;
0122 int i;
0123
0124 platform_set_drvdata(pdev, tps);
0125
0126 config.dev = &pdev->dev;
0127 config.driver_data = tps;
0128 config.dev->of_node = tps->dev->of_node;
0129 config.regmap = tps->regmap;
0130
0131 for (i = 0; i < ARRAY_SIZE(regulators); i++) {
0132 rdev = devm_regulator_register(&pdev->dev, ®ulators[i],
0133 &config);
0134 if (IS_ERR(rdev)) {
0135 dev_err(tps->dev, "failed to register %s regulator\n",
0136 pdev->name);
0137 return PTR_ERR(rdev);
0138 }
0139 }
0140
0141 return 0;
0142 }
0143
0144 static const struct platform_device_id tps65912_regulator_id_table[] = {
0145 { "tps65912-regulator", },
0146 { }
0147 };
0148 MODULE_DEVICE_TABLE(platform, tps65912_regulator_id_table);
0149
0150 static struct platform_driver tps65912_regulator_driver = {
0151 .driver = {
0152 .name = "tps65912-regulator",
0153 },
0154 .probe = tps65912_regulator_probe,
0155 .id_table = tps65912_regulator_id_table,
0156 };
0157 module_platform_driver(tps65912_regulator_driver);
0158
0159 MODULE_AUTHOR("Andrew F. Davis <afd@ti.com>");
0160 MODULE_DESCRIPTION("TPS65912 voltage regulator driver");
0161 MODULE_LICENSE("GPL v2");