2 * TI LM363X Regulator Driver
4 * Copyright 2015 Texas Instruments
6 * Author: Milo Kim <milo.kim@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/err.h>
14 #include <linux/kernel.h>
15 #include <linux/mfd/ti-lmu.h>
16 #include <linux/mfd/ti-lmu-register.h>
17 #include <linux/module.h>
19 #include <linux/gpio/consumer.h>
20 #include <linux/platform_device.h>
21 #include <linux/regulator/driver.h>
22 #include <linux/regulator/of_regulator.h>
23 #include <linux/slab.h>
26 #define LM3631_BOOST_VSEL_MAX 0x25
27 #define LM3631_LDO_VSEL_MAX 0x28
28 #define LM3631_CONT_VSEL_MAX 0x03
29 #define LM3631_VBOOST_MIN 4500000
30 #define LM3631_VCONT_MIN 1800000
31 #define LM3631_VLDO_MIN 4000000
32 #define ENABLE_TIME_USEC 1000
35 #define LM3632_BOOST_VSEL_MAX 0x26
36 #define LM3632_LDO_VSEL_MAX 0x29
37 #define LM3632_VBOOST_MIN 4500000
38 #define LM3632_VLDO_MIN 4000000
41 #define LM363X_STEP_50mV 50000
42 #define LM363X_STEP_500mV 500000
44 static const int ldo_cont_enable_time[] = {
45 0, 2000, 5000, 10000, 20000, 50000, 100000, 200000,
48 static int lm363x_regulator_enable_time(struct regulator_dev *rdev)
50 enum lm363x_regulator_id id = rdev_get_id(rdev);
55 addr = LM3631_REG_ENTIME_VCONT;
56 mask = LM3631_ENTIME_CONT_MASK;
59 addr = LM3631_REG_ENTIME_VOREF;
60 mask = LM3631_ENTIME_MASK;
63 addr = LM3631_REG_ENTIME_VPOS;
64 mask = LM3631_ENTIME_MASK;
67 addr = LM3631_REG_ENTIME_VNEG;
68 mask = LM3631_ENTIME_MASK;
74 if (regmap_read(rdev->regmap, addr, (unsigned int *)&val))
77 val = (val & mask) >> LM3631_ENTIME_SHIFT;
79 if (id == LM3631_LDO_CONT)
80 return ldo_cont_enable_time[val];
82 return ENABLE_TIME_USEC * val;
85 static struct regulator_ops lm363x_boost_voltage_table_ops = {
86 .list_voltage = regulator_list_voltage_linear,
87 .set_voltage_sel = regulator_set_voltage_sel_regmap,
88 .get_voltage_sel = regulator_get_voltage_sel_regmap,
91 static struct regulator_ops lm363x_regulator_voltage_table_ops = {
92 .list_voltage = regulator_list_voltage_linear,
93 .set_voltage_sel = regulator_set_voltage_sel_regmap,
94 .get_voltage_sel = regulator_get_voltage_sel_regmap,
95 .enable = regulator_enable_regmap,
96 .disable = regulator_disable_regmap,
97 .is_enabled = regulator_is_enabled_regmap,
98 .enable_time = lm363x_regulator_enable_time,
101 static const struct regulator_desc lm363x_regulator_desc[] = {
105 .of_match = "vboost",
107 .ops = &lm363x_boost_voltage_table_ops,
108 .n_voltages = LM3631_BOOST_VSEL_MAX + 1,
109 .min_uV = LM3631_VBOOST_MIN,
110 .uV_step = LM363X_STEP_50mV,
111 .type = REGULATOR_VOLTAGE,
112 .owner = THIS_MODULE,
113 .vsel_reg = LM3631_REG_VOUT_BOOST,
114 .vsel_mask = LM3631_VOUT_MASK,
119 .id = LM3631_LDO_CONT,
120 .ops = &lm363x_regulator_voltage_table_ops,
121 .n_voltages = LM3631_CONT_VSEL_MAX + 1,
122 .min_uV = LM3631_VCONT_MIN,
123 .uV_step = LM363X_STEP_500mV,
124 .type = REGULATOR_VOLTAGE,
125 .owner = THIS_MODULE,
126 .vsel_reg = LM3631_REG_VOUT_CONT,
127 .vsel_mask = LM3631_VOUT_CONT_MASK,
128 .enable_reg = LM3631_REG_LDO_CTRL2,
129 .enable_mask = LM3631_EN_CONT_MASK,
134 .id = LM3631_LDO_OREF,
135 .ops = &lm363x_regulator_voltage_table_ops,
136 .n_voltages = LM3631_LDO_VSEL_MAX + 1,
137 .min_uV = LM3631_VLDO_MIN,
138 .uV_step = LM363X_STEP_50mV,
139 .type = REGULATOR_VOLTAGE,
140 .owner = THIS_MODULE,
141 .vsel_reg = LM3631_REG_VOUT_OREF,
142 .vsel_mask = LM3631_VOUT_MASK,
143 .enable_reg = LM3631_REG_LDO_CTRL1,
144 .enable_mask = LM3631_EN_OREF_MASK,
149 .id = LM3631_LDO_POS,
150 .ops = &lm363x_regulator_voltage_table_ops,
151 .n_voltages = LM3631_LDO_VSEL_MAX + 1,
152 .min_uV = LM3631_VLDO_MIN,
153 .uV_step = LM363X_STEP_50mV,
154 .type = REGULATOR_VOLTAGE,
155 .owner = THIS_MODULE,
156 .vsel_reg = LM3631_REG_VOUT_POS,
157 .vsel_mask = LM3631_VOUT_MASK,
158 .enable_reg = LM3631_REG_LDO_CTRL1,
159 .enable_mask = LM3631_EN_VPOS_MASK,
164 .id = LM3631_LDO_NEG,
165 .ops = &lm363x_regulator_voltage_table_ops,
166 .n_voltages = LM3631_LDO_VSEL_MAX + 1,
167 .min_uV = LM3631_VLDO_MIN,
168 .uV_step = LM363X_STEP_50mV,
169 .type = REGULATOR_VOLTAGE,
170 .owner = THIS_MODULE,
171 .vsel_reg = LM3631_REG_VOUT_NEG,
172 .vsel_mask = LM3631_VOUT_MASK,
173 .enable_reg = LM3631_REG_LDO_CTRL1,
174 .enable_mask = LM3631_EN_VNEG_MASK,
179 .of_match = "vboost",
181 .ops = &lm363x_boost_voltage_table_ops,
182 .n_voltages = LM3632_BOOST_VSEL_MAX + 1,
183 .min_uV = LM3632_VBOOST_MIN,
184 .uV_step = LM363X_STEP_50mV,
185 .type = REGULATOR_VOLTAGE,
186 .owner = THIS_MODULE,
187 .vsel_reg = LM3632_REG_VOUT_BOOST,
188 .vsel_mask = LM3632_VOUT_MASK,
193 .id = LM3632_LDO_POS,
194 .ops = &lm363x_regulator_voltage_table_ops,
195 .n_voltages = LM3632_LDO_VSEL_MAX + 1,
196 .min_uV = LM3632_VLDO_MIN,
197 .uV_step = LM363X_STEP_50mV,
198 .type = REGULATOR_VOLTAGE,
199 .owner = THIS_MODULE,
200 .vsel_reg = LM3632_REG_VOUT_POS,
201 .vsel_mask = LM3632_VOUT_MASK,
202 .enable_reg = LM3632_REG_BIAS_CONFIG,
203 .enable_mask = LM3632_EN_VPOS_MASK,
208 .id = LM3632_LDO_NEG,
209 .ops = &lm363x_regulator_voltage_table_ops,
210 .n_voltages = LM3632_LDO_VSEL_MAX + 1,
211 .min_uV = LM3632_VLDO_MIN,
212 .uV_step = LM363X_STEP_50mV,
213 .type = REGULATOR_VOLTAGE,
214 .owner = THIS_MODULE,
215 .vsel_reg = LM3632_REG_VOUT_NEG,
216 .vsel_mask = LM3632_VOUT_MASK,
217 .enable_reg = LM3632_REG_BIAS_CONFIG,
218 .enable_mask = LM3632_EN_VNEG_MASK,
222 static struct gpio_desc *lm363x_regulator_of_get_enable_gpio(struct device *dev, int id)
225 * Check LCM_EN1/2_GPIO is configured.
226 * Those pins are used for enabling VPOS/VNEG LDOs.
230 return devm_gpiod_get_index_optional(dev, "enable", 0, GPIOD_OUT_LOW);
232 return devm_gpiod_get_index_optional(dev, "enable", 1, GPIOD_OUT_LOW);
238 static int lm363x_regulator_probe(struct platform_device *pdev)
240 struct ti_lmu *lmu = dev_get_drvdata(pdev->dev.parent);
241 struct regmap *regmap = lmu->regmap;
242 struct regulator_config cfg = { };
243 struct regulator_dev *rdev;
244 struct device *dev = &pdev->dev;
246 struct gpio_desc *gpiod;
253 * LM3632 LDOs can be controlled by external pin.
254 * Register update is required if the pin is used.
256 gpiod = lm363x_regulator_of_get_enable_gpio(dev, id);
258 cfg.ena_gpiod = gpiod;
260 ret = regmap_update_bits(regmap, LM3632_REG_BIAS_CONFIG,
264 dev_err(dev, "External pin err: %d\n", ret);
269 rdev = devm_regulator_register(dev, &lm363x_regulator_desc[id], &cfg);
272 dev_err(dev, "[%d] regulator register err: %d\n", id, ret);
279 static struct platform_driver lm363x_regulator_driver = {
280 .probe = lm363x_regulator_probe,
282 .name = "lm363x-regulator",
286 module_platform_driver(lm363x_regulator_driver);
288 MODULE_DESCRIPTION("TI LM363X Regulator Driver");
289 MODULE_AUTHOR("Milo Kim");
290 MODULE_LICENSE("GPL v2");
291 MODULE_ALIAS("platform:lm363x-regulator");