diff options
Diffstat (limited to 'drivers/regulator')
-rw-r--r-- | drivers/regulator/Kconfig | 27 | ||||
-rw-r--r-- | drivers/regulator/Makefile | 3 | ||||
-rw-r--r-- | drivers/regulator/core.c | 38 | ||||
-rw-r--r-- | drivers/regulator/gpio-regulator.c | 100 | ||||
-rw-r--r-- | drivers/regulator/tps51632-regulator.c | 332 | ||||
-rw-r--r-- | drivers/regulator/tps65090-regulator.c | 247 | ||||
-rw-r--r-- | drivers/regulator/tps80031-regulator.c | 793 | ||||
-rw-r--r-- | drivers/regulator/vexpress.c | 147 |
8 files changed, 1611 insertions, 76 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 67d47b59a66d..0ae658f048e2 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
@@ -335,6 +335,17 @@ config REGULATOR_PALMAS | |||
335 | on the muxing. This is handled automatically in the driver by | 335 | on the muxing. This is handled automatically in the driver by |
336 | reading the mux info from OTP. | 336 | reading the mux info from OTP. |
337 | 337 | ||
338 | config REGULATOR_TPS51632 | ||
339 | tristate "TI TPS51632 Power Regulator" | ||
340 | depends on I2C | ||
341 | select REGMAP_I2C | ||
342 | help | ||
343 | This driver supports TPS51632 voltage regulator chip. | ||
344 | The TPS51632 is 3-2-1 Phase D-Cap+ Step Down Driverless Controller | ||
345 | with Serial VID control and DVFS. | ||
346 | The voltage output can be configure through I2C interface or PWM | ||
347 | interface. | ||
348 | |||
338 | config REGULATOR_TPS6105X | 349 | config REGULATOR_TPS6105X |
339 | tristate "TI TPS6105X Power regulators" | 350 | tristate "TI TPS6105X Power regulators" |
340 | depends on TPS6105X | 351 | depends on TPS6105X |
@@ -415,6 +426,15 @@ config REGULATOR_TPS65912 | |||
415 | help | 426 | help |
416 | This driver supports TPS65912 voltage regulator chip. | 427 | This driver supports TPS65912 voltage regulator chip. |
417 | 428 | ||
429 | config REGULATOR_TPS80031 | ||
430 | tristate "TI TPS80031/TPS80032 power regualtor driver" | ||
431 | depends on MFD_TPS80031 | ||
432 | help | ||
433 | TPS80031/ TPS80032 Fully Integrated Power Management with Power | ||
434 | Path and Battery Charger. It has 5 configurable step-down | ||
435 | converters, 11 general purpose LDOs, VBUS generator and digital | ||
436 | output to control regulators. | ||
437 | |||
418 | config REGULATOR_TWL4030 | 438 | config REGULATOR_TWL4030 |
419 | bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" | 439 | bool "TI TWL4030/TWL5030/TWL6030/TPS659x0 PMIC" |
420 | depends on TWL4030_CORE | 440 | depends on TWL4030_CORE |
@@ -422,6 +442,13 @@ config REGULATOR_TWL4030 | |||
422 | This driver supports the voltage regulators provided by | 442 | This driver supports the voltage regulators provided by |
423 | this family of companion chips. | 443 | this family of companion chips. |
424 | 444 | ||
445 | config REGULATOR_VEXPRESS | ||
446 | tristate "Versatile Express regulators" | ||
447 | depends on VEXPRESS_CONFIG | ||
448 | help | ||
449 | This driver provides support for voltage regulators available | ||
450 | on the ARM Ltd's Versatile Express platform. | ||
451 | |||
425 | config REGULATOR_WM831X | 452 | config REGULATOR_WM831X |
426 | tristate "Wolfson Microelectronics WM831x PMIC regulators" | 453 | tristate "Wolfson Microelectronics WM831x PMIC regulators" |
427 | depends on MFD_WM831X | 454 | depends on MFD_WM831X |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index e431eed8a878..6166d122d125 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
@@ -41,6 +41,7 @@ obj-$(CONFIG_REGULATOR_MC13783) += mc13783-regulator.o | |||
41 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o | 41 | obj-$(CONFIG_REGULATOR_MC13892) += mc13892-regulator.o |
42 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o | 42 | obj-$(CONFIG_REGULATOR_MC13XXX_CORE) += mc13xxx-regulator-core.o |
43 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o | 43 | obj-$(CONFIG_REGULATOR_PALMAS) += palmas-regulator.o |
44 | obj-$(CONFIG_REGULATOR_TPS51632) += tps51632-regulator.o | ||
44 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o | 45 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o |
45 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o | 46 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o |
46 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o | 47 | obj-$(CONFIG_REGULATOR_RC5T583) += rc5t583-regulator.o |
@@ -56,7 +57,9 @@ obj-$(CONFIG_REGULATOR_TPS6524X) += tps6524x-regulator.o | |||
56 | obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o | 57 | obj-$(CONFIG_REGULATOR_TPS6586X) += tps6586x-regulator.o |
57 | obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o | 58 | obj-$(CONFIG_REGULATOR_TPS65910) += tps65910-regulator.o |
58 | obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o | 59 | obj-$(CONFIG_REGULATOR_TPS65912) += tps65912-regulator.o |
60 | obj-$(CONFIG_REGULATOR_TPS80031) += tps80031-regulator.o | ||
59 | obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o | 61 | obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o |
62 | obj-$(CONFIG_REGULATOR_VEXPRESS) += vexpress.o | ||
60 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o | 63 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o |
61 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o | 64 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o |
62 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o | 65 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index 5c4829cba6a6..3db1e011d229 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
@@ -1381,22 +1381,14 @@ struct regulator *regulator_get_exclusive(struct device *dev, const char *id) | |||
1381 | } | 1381 | } |
1382 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); | 1382 | EXPORT_SYMBOL_GPL(regulator_get_exclusive); |
1383 | 1383 | ||
1384 | /** | 1384 | /* Locks held by regulator_put() */ |
1385 | * regulator_put - "free" the regulator source | 1385 | static void _regulator_put(struct regulator *regulator) |
1386 | * @regulator: regulator source | ||
1387 | * | ||
1388 | * Note: drivers must ensure that all regulator_enable calls made on this | ||
1389 | * regulator source are balanced by regulator_disable calls prior to calling | ||
1390 | * this function. | ||
1391 | */ | ||
1392 | void regulator_put(struct regulator *regulator) | ||
1393 | { | 1386 | { |
1394 | struct regulator_dev *rdev; | 1387 | struct regulator_dev *rdev; |
1395 | 1388 | ||
1396 | if (regulator == NULL || IS_ERR(regulator)) | 1389 | if (regulator == NULL || IS_ERR(regulator)) |
1397 | return; | 1390 | return; |
1398 | 1391 | ||
1399 | mutex_lock(®ulator_list_mutex); | ||
1400 | rdev = regulator->rdev; | 1392 | rdev = regulator->rdev; |
1401 | 1393 | ||
1402 | debugfs_remove_recursive(regulator->debugfs); | 1394 | debugfs_remove_recursive(regulator->debugfs); |
@@ -1412,6 +1404,20 @@ void regulator_put(struct regulator *regulator) | |||
1412 | rdev->exclusive = 0; | 1404 | rdev->exclusive = 0; |
1413 | 1405 | ||
1414 | module_put(rdev->owner); | 1406 | module_put(rdev->owner); |
1407 | } | ||
1408 | |||
1409 | /** | ||
1410 | * regulator_put - "free" the regulator source | ||
1411 | * @regulator: regulator source | ||
1412 | * | ||
1413 | * Note: drivers must ensure that all regulator_enable calls made on this | ||
1414 | * regulator source are balanced by regulator_disable calls prior to calling | ||
1415 | * this function. | ||
1416 | */ | ||
1417 | void regulator_put(struct regulator *regulator) | ||
1418 | { | ||
1419 | mutex_lock(®ulator_list_mutex); | ||
1420 | _regulator_put(regulator); | ||
1415 | mutex_unlock(®ulator_list_mutex); | 1421 | mutex_unlock(®ulator_list_mutex); |
1416 | } | 1422 | } |
1417 | EXPORT_SYMBOL_GPL(regulator_put); | 1423 | EXPORT_SYMBOL_GPL(regulator_put); |
@@ -1974,11 +1980,16 @@ int regulator_is_supported_voltage(struct regulator *regulator, | |||
1974 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { | 1980 | if (!(rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_VOLTAGE)) { |
1975 | ret = regulator_get_voltage(regulator); | 1981 | ret = regulator_get_voltage(regulator); |
1976 | if (ret >= 0) | 1982 | if (ret >= 0) |
1977 | return (min_uV >= ret && ret <= max_uV); | 1983 | return (min_uV <= ret && ret <= max_uV); |
1978 | else | 1984 | else |
1979 | return ret; | 1985 | return ret; |
1980 | } | 1986 | } |
1981 | 1987 | ||
1988 | /* Any voltage within constrains range is fine? */ | ||
1989 | if (rdev->desc->continuous_voltage_range) | ||
1990 | return min_uV >= rdev->constraints->min_uV && | ||
1991 | max_uV <= rdev->constraints->max_uV; | ||
1992 | |||
1982 | ret = regulator_count_voltages(regulator); | 1993 | ret = regulator_count_voltages(regulator); |
1983 | if (ret < 0) | 1994 | if (ret < 0) |
1984 | return ret; | 1995 | return ret; |
@@ -3365,7 +3376,7 @@ regulator_register(const struct regulator_desc *regulator_desc, | |||
3365 | if (ret != 0) { | 3376 | if (ret != 0) { |
3366 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", | 3377 | rdev_err(rdev, "Failed to request enable GPIO%d: %d\n", |
3367 | config->ena_gpio, ret); | 3378 | config->ena_gpio, ret); |
3368 | goto clean; | 3379 | goto wash; |
3369 | } | 3380 | } |
3370 | 3381 | ||
3371 | rdev->ena_gpio = config->ena_gpio; | 3382 | rdev->ena_gpio = config->ena_gpio; |
@@ -3445,10 +3456,11 @@ unset_supplies: | |||
3445 | 3456 | ||
3446 | scrub: | 3457 | scrub: |
3447 | if (rdev->supply) | 3458 | if (rdev->supply) |
3448 | regulator_put(rdev->supply); | 3459 | _regulator_put(rdev->supply); |
3449 | if (rdev->ena_gpio) | 3460 | if (rdev->ena_gpio) |
3450 | gpio_free(rdev->ena_gpio); | 3461 | gpio_free(rdev->ena_gpio); |
3451 | kfree(rdev->constraints); | 3462 | kfree(rdev->constraints); |
3463 | wash: | ||
3452 | device_unregister(&rdev->dev); | 3464 | device_unregister(&rdev->dev); |
3453 | /* device core frees rdev */ | 3465 | /* device core frees rdev */ |
3454 | rdev = ERR_PTR(ret); | 3466 | rdev = ERR_PTR(ret); |
diff --git a/drivers/regulator/gpio-regulator.c b/drivers/regulator/gpio-regulator.c index 8b5944f2d7d1..dc9260545b80 100644 --- a/drivers/regulator/gpio-regulator.c +++ b/drivers/regulator/gpio-regulator.c | |||
@@ -28,9 +28,12 @@ | |||
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/regulator/driver.h> | 29 | #include <linux/regulator/driver.h> |
30 | #include <linux/regulator/machine.h> | 30 | #include <linux/regulator/machine.h> |
31 | #include <linux/regulator/of_regulator.h> | ||
31 | #include <linux/regulator/gpio-regulator.h> | 32 | #include <linux/regulator/gpio-regulator.h> |
32 | #include <linux/gpio.h> | 33 | #include <linux/gpio.h> |
33 | #include <linux/slab.h> | 34 | #include <linux/slab.h> |
35 | #include <linux/of.h> | ||
36 | #include <linux/of_gpio.h> | ||
34 | 37 | ||
35 | struct gpio_regulator_data { | 38 | struct gpio_regulator_data { |
36 | struct regulator_desc desc; | 39 | struct regulator_desc desc; |
@@ -129,6 +132,89 @@ static struct regulator_ops gpio_regulator_voltage_ops = { | |||
129 | .list_voltage = gpio_regulator_list_voltage, | 132 | .list_voltage = gpio_regulator_list_voltage, |
130 | }; | 133 | }; |
131 | 134 | ||
135 | struct gpio_regulator_config * | ||
136 | of_get_gpio_regulator_config(struct device *dev, struct device_node *np) | ||
137 | { | ||
138 | struct gpio_regulator_config *config; | ||
139 | struct property *prop; | ||
140 | const char *regtype; | ||
141 | int proplen, gpio, i; | ||
142 | |||
143 | config = devm_kzalloc(dev, | ||
144 | sizeof(struct gpio_regulator_config), | ||
145 | GFP_KERNEL); | ||
146 | if (!config) | ||
147 | return ERR_PTR(-ENOMEM); | ||
148 | |||
149 | config->init_data = of_get_regulator_init_data(dev, np); | ||
150 | if (!config->init_data) | ||
151 | return ERR_PTR(-EINVAL); | ||
152 | |||
153 | config->supply_name = config->init_data->constraints.name; | ||
154 | |||
155 | if (of_property_read_bool(np, "enable-active-high")) | ||
156 | config->enable_high = true; | ||
157 | |||
158 | if (of_property_read_bool(np, "enable-at-boot")) | ||
159 | config->enabled_at_boot = true; | ||
160 | |||
161 | of_property_read_u32(np, "startup-delay-us", &config->startup_delay); | ||
162 | |||
163 | config->enable_gpio = of_get_named_gpio(np, "enable-gpio", 0); | ||
164 | |||
165 | /* Fetch GPIOs. */ | ||
166 | for (i = 0; ; i++) | ||
167 | if (of_get_named_gpio(np, "gpios", i) < 0) | ||
168 | break; | ||
169 | config->nr_gpios = i; | ||
170 | |||
171 | config->gpios = devm_kzalloc(dev, | ||
172 | sizeof(struct gpio) * config->nr_gpios, | ||
173 | GFP_KERNEL); | ||
174 | if (!config->gpios) | ||
175 | return ERR_PTR(-ENOMEM); | ||
176 | |||
177 | for (i = 0; config->nr_gpios; i++) { | ||
178 | gpio = of_get_named_gpio(np, "gpios", i); | ||
179 | if (gpio < 0) | ||
180 | break; | ||
181 | config->gpios[i].gpio = gpio; | ||
182 | } | ||
183 | |||
184 | /* Fetch states. */ | ||
185 | prop = of_find_property(np, "states", NULL); | ||
186 | if (!prop) { | ||
187 | dev_err(dev, "No 'states' property found\n"); | ||
188 | return ERR_PTR(-EINVAL); | ||
189 | } | ||
190 | |||
191 | proplen = prop->length / sizeof(int); | ||
192 | |||
193 | config->states = devm_kzalloc(dev, | ||
194 | sizeof(struct gpio_regulator_state) | ||
195 | * (proplen / 2), | ||
196 | GFP_KERNEL); | ||
197 | if (!config->states) | ||
198 | return ERR_PTR(-ENOMEM); | ||
199 | |||
200 | for (i = 0; i < proplen / 2; i++) { | ||
201 | config->states[i].value = | ||
202 | be32_to_cpup((int *)prop->value + (i * 2)); | ||
203 | config->states[i].gpios = | ||
204 | be32_to_cpup((int *)prop->value + (i * 2 + 1)); | ||
205 | } | ||
206 | config->nr_states = i; | ||
207 | |||
208 | of_property_read_string(np, "regulator-type", ®type); | ||
209 | |||
210 | if (!strncmp("voltage", regtype, 7)) | ||
211 | config->type = REGULATOR_VOLTAGE; | ||
212 | else if (!strncmp("current", regtype, 7)) | ||
213 | config->type = REGULATOR_CURRENT; | ||
214 | |||
215 | return config; | ||
216 | } | ||
217 | |||
132 | static struct regulator_ops gpio_regulator_current_ops = { | 218 | static struct regulator_ops gpio_regulator_current_ops = { |
133 | .get_current_limit = gpio_regulator_get_value, | 219 | .get_current_limit = gpio_regulator_get_value, |
134 | .set_current_limit = gpio_regulator_set_current_limit, | 220 | .set_current_limit = gpio_regulator_set_current_limit, |
@@ -137,10 +223,17 @@ static struct regulator_ops gpio_regulator_current_ops = { | |||
137 | static int __devinit gpio_regulator_probe(struct platform_device *pdev) | 223 | static int __devinit gpio_regulator_probe(struct platform_device *pdev) |
138 | { | 224 | { |
139 | struct gpio_regulator_config *config = pdev->dev.platform_data; | 225 | struct gpio_regulator_config *config = pdev->dev.platform_data; |
226 | struct device_node *np = pdev->dev.of_node; | ||
140 | struct gpio_regulator_data *drvdata; | 227 | struct gpio_regulator_data *drvdata; |
141 | struct regulator_config cfg = { }; | 228 | struct regulator_config cfg = { }; |
142 | int ptr, ret, state; | 229 | int ptr, ret, state; |
143 | 230 | ||
231 | if (np) { | ||
232 | config = of_get_gpio_regulator_config(&pdev->dev, np); | ||
233 | if (IS_ERR(config)) | ||
234 | return PTR_ERR(config); | ||
235 | } | ||
236 | |||
144 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), | 237 | drvdata = devm_kzalloc(&pdev->dev, sizeof(struct gpio_regulator_data), |
145 | GFP_KERNEL); | 238 | GFP_KERNEL); |
146 | if (drvdata == NULL) { | 239 | if (drvdata == NULL) { |
@@ -215,6 +308,7 @@ static int __devinit gpio_regulator_probe(struct platform_device *pdev) | |||
215 | cfg.dev = &pdev->dev; | 308 | cfg.dev = &pdev->dev; |
216 | cfg.init_data = config->init_data; | 309 | cfg.init_data = config->init_data; |
217 | cfg.driver_data = drvdata; | 310 | cfg.driver_data = drvdata; |
311 | cfg.of_node = np; | ||
218 | 312 | ||
219 | if (config->enable_gpio >= 0) | 313 | if (config->enable_gpio >= 0) |
220 | cfg.ena_gpio = config->enable_gpio; | 314 | cfg.ena_gpio = config->enable_gpio; |
@@ -270,12 +364,18 @@ static int __devexit gpio_regulator_remove(struct platform_device *pdev) | |||
270 | return 0; | 364 | return 0; |
271 | } | 365 | } |
272 | 366 | ||
367 | static const struct of_device_id regulator_gpio_of_match[] __devinitconst = { | ||
368 | { .compatible = "regulator-gpio", }, | ||
369 | {}, | ||
370 | }; | ||
371 | |||
273 | static struct platform_driver gpio_regulator_driver = { | 372 | static struct platform_driver gpio_regulator_driver = { |
274 | .probe = gpio_regulator_probe, | 373 | .probe = gpio_regulator_probe, |
275 | .remove = __devexit_p(gpio_regulator_remove), | 374 | .remove = __devexit_p(gpio_regulator_remove), |
276 | .driver = { | 375 | .driver = { |
277 | .name = "gpio-regulator", | 376 | .name = "gpio-regulator", |
278 | .owner = THIS_MODULE, | 377 | .owner = THIS_MODULE, |
378 | .of_match_table = regulator_gpio_of_match, | ||
279 | }, | 379 | }, |
280 | }; | 380 | }; |
281 | 381 | ||
diff --git a/drivers/regulator/tps51632-regulator.c b/drivers/regulator/tps51632-regulator.c new file mode 100644 index 000000000000..34603640d6d9 --- /dev/null +++ b/drivers/regulator/tps51632-regulator.c | |||
@@ -0,0 +1,332 @@ | |||
1 | /* | ||
2 | * tps51632-regulator.c -- TI TPS51632 | ||
3 | * | ||
4 | * Regulator driver for TPS51632 3-2-1 Phase D-Cap Step Down Driverless | ||
5 | * Controller with serial VID control and DVFS. | ||
6 | * | ||
7 | * Copyright (c) 2012, NVIDIA Corporation. | ||
8 | * | ||
9 | * Author: Laxman Dewangan <ldewangan@nvidia.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License as | ||
13 | * published by the Free Software Foundation version 2. | ||
14 | * | ||
15 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | ||
16 | * whether express or implied; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
23 | * 02111-1307, USA | ||
24 | */ | ||
25 | |||
26 | #include <linux/err.h> | ||
27 | #include <linux/i2c.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/module.h> | ||
31 | #include <linux/platform_device.h> | ||
32 | #include <linux/regmap.h> | ||
33 | #include <linux/regulator/driver.h> | ||
34 | #include <linux/regulator/machine.h> | ||
35 | #include <linux/regulator/tps51632-regulator.h> | ||
36 | #include <linux/slab.h> | ||
37 | |||
38 | /* Register definitions */ | ||
39 | #define TPS51632_VOLTAGE_SELECT_REG 0x0 | ||
40 | #define TPS51632_VOLTAGE_BASE_REG 0x1 | ||
41 | #define TPS51632_OFFSET_REG 0x2 | ||
42 | #define TPS51632_IMON_REG 0x3 | ||
43 | #define TPS51632_VMAX_REG 0x4 | ||
44 | #define TPS51632_DVFS_CONTROL_REG 0x5 | ||
45 | #define TPS51632_POWER_STATE_REG 0x6 | ||
46 | #define TPS51632_SLEW_REGS 0x7 | ||
47 | #define TPS51632_FAULT_REG 0x14 | ||
48 | |||
49 | #define TPS51632_MAX_REG 0x15 | ||
50 | |||
51 | #define TPS51632_VOUT_MASK 0x7F | ||
52 | #define TPS51632_VOUT_OFFSET_MASK 0x1F | ||
53 | #define TPS51632_VMAX_MASK 0x7F | ||
54 | #define TPS51632_VMAX_LOCK 0x80 | ||
55 | |||
56 | /* TPS51632_DVFS_CONTROL_REG */ | ||
57 | #define TPS51632_DVFS_PWMEN 0x1 | ||
58 | #define TPS51632_DVFS_STEP_20 0x2 | ||
59 | #define TPS51632_DVFS_VMAX_PG 0x4 | ||
60 | #define TPS51632_DVFS_PWMRST 0x8 | ||
61 | #define TPS51632_DVFS_OCA_EN 0x10 | ||
62 | #define TPS51632_DVFS_FCCM 0x20 | ||
63 | |||
64 | /* TPS51632_POWER_STATE_REG */ | ||
65 | #define TPS51632_POWER_STATE_MASK 0x03 | ||
66 | #define TPS51632_POWER_STATE_MULTI_PHASE_CCM 0x0 | ||
67 | #define TPS51632_POWER_STATE_SINGLE_PHASE_CCM 0x1 | ||
68 | #define TPS51632_POWER_STATE_SINGLE_PHASE_DCM 0x2 | ||
69 | |||
70 | #define TPS51632_MIN_VOLATGE 500000 | ||
71 | #define TPS51632_MAX_VOLATGE 1520000 | ||
72 | #define TPS51632_VOLATGE_STEP_10mV 10000 | ||
73 | #define TPS51632_VOLATGE_STEP_20mV 20000 | ||
74 | #define TPS51632_MAX_VSEL 0x7F | ||
75 | #define TPS51632_MIN_VSEL 0x19 | ||
76 | #define TPS51632_DEFAULT_RAMP_DELAY 6000 | ||
77 | #define TPS51632_VOLT_VSEL(uV) \ | ||
78 | (DIV_ROUND_UP(uV - TPS51632_MIN_VOLATGE, \ | ||
79 | TPS51632_VOLATGE_STEP_10mV) + \ | ||
80 | TPS51632_MIN_VSEL) | ||
81 | |||
82 | /* TPS51632 chip information */ | ||
83 | struct tps51632_chip { | ||
84 | struct device *dev; | ||
85 | struct regulator_desc desc; | ||
86 | struct regulator_dev *rdev; | ||
87 | struct regmap *regmap; | ||
88 | bool enable_pwm_dvfs; | ||
89 | }; | ||
90 | |||
91 | static int tps51632_dcdc_get_voltage_sel(struct regulator_dev *rdev) | ||
92 | { | ||
93 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
94 | unsigned int data; | ||
95 | int ret; | ||
96 | unsigned int reg = TPS51632_VOLTAGE_SELECT_REG; | ||
97 | int vsel; | ||
98 | |||
99 | if (tps->enable_pwm_dvfs) | ||
100 | reg = TPS51632_VOLTAGE_BASE_REG; | ||
101 | |||
102 | ret = regmap_read(tps->regmap, reg, &data); | ||
103 | if (ret < 0) { | ||
104 | dev_err(tps->dev, "reg read failed, err %d\n", ret); | ||
105 | return ret; | ||
106 | } | ||
107 | |||
108 | vsel = data & TPS51632_VOUT_MASK; | ||
109 | |||
110 | if (vsel < TPS51632_MIN_VSEL) | ||
111 | return 0; | ||
112 | else | ||
113 | return vsel - TPS51632_MIN_VSEL; | ||
114 | } | ||
115 | |||
116 | static int tps51632_dcdc_set_voltage_sel(struct regulator_dev *rdev, | ||
117 | unsigned selector) | ||
118 | { | ||
119 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
120 | int vsel; | ||
121 | int ret; | ||
122 | unsigned int reg = TPS51632_VOLTAGE_SELECT_REG; | ||
123 | |||
124 | if (tps->enable_pwm_dvfs) | ||
125 | reg = TPS51632_VOLTAGE_BASE_REG; | ||
126 | |||
127 | vsel = selector + TPS51632_MIN_VSEL; | ||
128 | if (vsel > TPS51632_MAX_VSEL) | ||
129 | return -EINVAL; | ||
130 | |||
131 | ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_SELECT_REG, vsel); | ||
132 | if (ret < 0) | ||
133 | dev_err(tps->dev, "reg write failed, err %d\n", ret); | ||
134 | return ret; | ||
135 | } | ||
136 | |||
137 | static int tps51632_dcdc_set_ramp_delay(struct regulator_dev *rdev, | ||
138 | int ramp_delay) | ||
139 | { | ||
140 | struct tps51632_chip *tps = rdev_get_drvdata(rdev); | ||
141 | int bit = ramp_delay/6000; | ||
142 | int ret; | ||
143 | |||
144 | if (bit) | ||
145 | bit--; | ||
146 | ret = regmap_write(tps->regmap, TPS51632_SLEW_REGS, BIT(bit)); | ||
147 | if (ret < 0) | ||
148 | dev_err(tps->dev, "SLEW reg write failed, err %d\n", ret); | ||
149 | return ret; | ||
150 | } | ||
151 | |||
152 | static struct regulator_ops tps51632_dcdc_ops = { | ||
153 | .get_voltage_sel = tps51632_dcdc_get_voltage_sel, | ||
154 | .set_voltage_sel = tps51632_dcdc_set_voltage_sel, | ||
155 | .list_voltage = regulator_list_voltage_linear, | ||
156 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
157 | .set_ramp_delay = tps51632_dcdc_set_ramp_delay, | ||
158 | }; | ||
159 | |||
160 | static int __devinit tps51632_init_dcdc(struct tps51632_chip *tps, | ||
161 | struct tps51632_regulator_platform_data *pdata) | ||
162 | { | ||
163 | int ret; | ||
164 | uint8_t control = 0; | ||
165 | int vsel; | ||
166 | |||
167 | if (!pdata->enable_pwm_dvfs) | ||
168 | goto skip_pwm_config; | ||
169 | |||
170 | control |= TPS51632_DVFS_PWMEN; | ||
171 | tps->enable_pwm_dvfs = pdata->enable_pwm_dvfs; | ||
172 | vsel = TPS51632_VOLT_VSEL(pdata->base_voltage_uV); | ||
173 | ret = regmap_write(tps->regmap, TPS51632_VOLTAGE_BASE_REG, vsel); | ||
174 | if (ret < 0) { | ||
175 | dev_err(tps->dev, "BASE reg write failed, err %d\n", ret); | ||
176 | return ret; | ||
177 | } | ||
178 | |||
179 | if (pdata->dvfs_step_20mV) | ||
180 | control |= TPS51632_DVFS_STEP_20; | ||
181 | |||
182 | if (pdata->max_voltage_uV) { | ||
183 | unsigned int vmax; | ||
184 | /** | ||
185 | * TPS51632 hw behavior: VMAX register can be write only | ||
186 | * once as it get locked after first write. The lock get | ||
187 | * reset only when device is power-reset. | ||
188 | * Write register only when lock bit is not enabled. | ||
189 | */ | ||
190 | ret = regmap_read(tps->regmap, TPS51632_VMAX_REG, &vmax); | ||
191 | if (ret < 0) { | ||
192 | dev_err(tps->dev, "VMAX read failed, err %d\n", ret); | ||
193 | return ret; | ||
194 | } | ||
195 | if (!(vmax & TPS51632_VMAX_LOCK)) { | ||
196 | vsel = TPS51632_VOLT_VSEL(pdata->max_voltage_uV); | ||
197 | ret = regmap_write(tps->regmap, TPS51632_VMAX_REG, | ||
198 | vsel); | ||
199 | if (ret < 0) { | ||
200 | dev_err(tps->dev, | ||
201 | "VMAX write failed, err %d\n", ret); | ||
202 | return ret; | ||
203 | } | ||
204 | } | ||
205 | } | ||
206 | |||
207 | skip_pwm_config: | ||
208 | ret = regmap_write(tps->regmap, TPS51632_DVFS_CONTROL_REG, control); | ||
209 | if (ret < 0) | ||
210 | dev_err(tps->dev, "DVFS reg write failed, err %d\n", ret); | ||
211 | return ret; | ||
212 | } | ||
213 | |||
214 | static bool rd_wr_reg(struct device *dev, unsigned int reg) | ||
215 | { | ||
216 | if ((reg >= 0x8) && (reg <= 0x10)) | ||
217 | return false; | ||
218 | return true; | ||
219 | } | ||
220 | |||
221 | static const struct regmap_config tps51632_regmap_config = { | ||
222 | .reg_bits = 8, | ||
223 | .val_bits = 8, | ||
224 | .writeable_reg = rd_wr_reg, | ||
225 | .readable_reg = rd_wr_reg, | ||
226 | .max_register = TPS51632_MAX_REG - 1, | ||
227 | .cache_type = REGCACHE_RBTREE, | ||
228 | }; | ||
229 | |||
230 | static int __devinit tps51632_probe(struct i2c_client *client, | ||
231 | const struct i2c_device_id *id) | ||
232 | { | ||
233 | struct tps51632_regulator_platform_data *pdata; | ||
234 | struct regulator_dev *rdev; | ||
235 | struct tps51632_chip *tps; | ||
236 | int ret; | ||
237 | struct regulator_config config = { }; | ||
238 | |||
239 | pdata = client->dev.platform_data; | ||
240 | if (!pdata) { | ||
241 | dev_err(&client->dev, "No Platform data\n"); | ||
242 | return -EINVAL; | ||
243 | } | ||
244 | |||
245 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); | ||
246 | if (!tps) { | ||
247 | dev_err(&client->dev, "Memory allocation failed\n"); | ||
248 | return -ENOMEM; | ||
249 | } | ||
250 | |||
251 | tps->dev = &client->dev; | ||
252 | tps->desc.name = id->name; | ||
253 | tps->desc.id = 0; | ||
254 | tps->desc.ramp_delay = TPS51632_DEFAULT_RAMP_DELAY; | ||
255 | tps->desc.min_uV = TPS51632_MIN_VOLATGE; | ||
256 | tps->desc.uV_step = TPS51632_VOLATGE_STEP_10mV; | ||
257 | tps->desc.n_voltages = (TPS51632_MAX_VSEL - TPS51632_MIN_VSEL) + 1; | ||
258 | tps->desc.ops = &tps51632_dcdc_ops; | ||
259 | tps->desc.type = REGULATOR_VOLTAGE; | ||
260 | tps->desc.owner = THIS_MODULE; | ||
261 | |||
262 | tps->regmap = devm_regmap_init_i2c(client, &tps51632_regmap_config); | ||
263 | if (IS_ERR(tps->regmap)) { | ||
264 | ret = PTR_ERR(tps->regmap); | ||
265 | dev_err(&client->dev, "regmap init failed, err %d\n", ret); | ||
266 | return ret; | ||
267 | } | ||
268 | i2c_set_clientdata(client, tps); | ||
269 | |||
270 | ret = tps51632_init_dcdc(tps, pdata); | ||
271 | if (ret < 0) { | ||
272 | dev_err(tps->dev, "Init failed, err = %d\n", ret); | ||
273 | return ret; | ||
274 | } | ||
275 | |||
276 | /* Register the regulators */ | ||
277 | config.dev = &client->dev; | ||
278 | config.init_data = pdata->reg_init_data; | ||
279 | config.driver_data = tps; | ||
280 | config.regmap = tps->regmap; | ||
281 | config.of_node = client->dev.of_node; | ||
282 | |||
283 | rdev = regulator_register(&tps->desc, &config); | ||
284 | if (IS_ERR(rdev)) { | ||
285 | dev_err(tps->dev, "regulator register failed\n"); | ||
286 | return PTR_ERR(rdev); | ||
287 | } | ||
288 | |||
289 | tps->rdev = rdev; | ||
290 | return 0; | ||
291 | } | ||
292 | |||
293 | static int __devexit tps51632_remove(struct i2c_client *client) | ||
294 | { | ||
295 | struct tps51632_chip *tps = i2c_get_clientdata(client); | ||
296 | |||
297 | regulator_unregister(tps->rdev); | ||
298 | return 0; | ||
299 | } | ||
300 | |||
301 | static const struct i2c_device_id tps51632_id[] = { | ||
302 | {.name = "tps51632",}, | ||
303 | {}, | ||
304 | }; | ||
305 | |||
306 | MODULE_DEVICE_TABLE(i2c, tps51632_id); | ||
307 | |||
308 | static struct i2c_driver tps51632_i2c_driver = { | ||
309 | .driver = { | ||
310 | .name = "tps51632", | ||
311 | .owner = THIS_MODULE, | ||
312 | }, | ||
313 | .probe = tps51632_probe, | ||
314 | .remove = __devexit_p(tps51632_remove), | ||
315 | .id_table = tps51632_id, | ||
316 | }; | ||
317 | |||
318 | static int __init tps51632_init(void) | ||
319 | { | ||
320 | return i2c_add_driver(&tps51632_i2c_driver); | ||
321 | } | ||
322 | subsys_initcall(tps51632_init); | ||
323 | |||
324 | static void __exit tps51632_cleanup(void) | ||
325 | { | ||
326 | i2c_del_driver(&tps51632_i2c_driver); | ||
327 | } | ||
328 | module_exit(tps51632_cleanup); | ||
329 | |||
330 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
331 | MODULE_DESCRIPTION("TPS51632 voltage regulator driver"); | ||
332 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/tps65090-regulator.c b/drivers/regulator/tps65090-regulator.c index 001ad554ac62..412413838e12 100644 --- a/drivers/regulator/tps65090-regulator.c +++ b/drivers/regulator/tps65090-regulator.c | |||
@@ -18,67 +18,124 @@ | |||
18 | 18 | ||
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
21 | #include <linux/gpio.h> | ||
21 | #include <linux/slab.h> | 22 | #include <linux/slab.h> |
22 | #include <linux/err.h> | 23 | #include <linux/err.h> |
23 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
24 | #include <linux/regulator/driver.h> | 25 | #include <linux/regulator/driver.h> |
25 | #include <linux/regulator/machine.h> | 26 | #include <linux/regulator/machine.h> |
26 | #include <linux/mfd/tps65090.h> | 27 | #include <linux/mfd/tps65090.h> |
27 | #include <linux/regulator/tps65090-regulator.h> | ||
28 | 28 | ||
29 | struct tps65090_regulator { | 29 | struct tps65090_regulator { |
30 | int id; | ||
31 | /* used by regulator core */ | ||
32 | struct regulator_desc desc; | ||
33 | |||
34 | /* Device */ | ||
35 | struct device *dev; | 30 | struct device *dev; |
31 | struct regulator_desc *desc; | ||
32 | struct regulator_dev *rdev; | ||
33 | }; | ||
34 | |||
35 | static struct regulator_ops tps65090_ext_control_ops = { | ||
36 | }; | ||
37 | |||
38 | static struct regulator_ops tps65090_reg_contol_ops = { | ||
39 | .enable = regulator_enable_regmap, | ||
40 | .disable = regulator_disable_regmap, | ||
41 | .is_enabled = regulator_is_enabled_regmap, | ||
36 | }; | 42 | }; |
37 | 43 | ||
38 | static struct regulator_ops tps65090_ops = { | 44 | static struct regulator_ops tps65090_ldo_ops = { |
39 | .enable = regulator_enable_regmap, | ||
40 | .disable = regulator_disable_regmap, | ||
41 | .is_enabled = regulator_is_enabled_regmap, | ||
42 | }; | 45 | }; |
43 | 46 | ||
44 | #define tps65090_REG(_id) \ | 47 | #define tps65090_REG_DESC(_id, _sname, _en_reg, _ops) \ |
45 | { \ | 48 | { \ |
46 | .id = TPS65090_ID_##_id, \ | 49 | .name = "TPS65090_RAILS"#_id, \ |
47 | .desc = { \ | 50 | .supply_name = _sname, \ |
48 | .name = tps65090_rails(_id), \ | 51 | .id = TPS65090_REGULATOR_##_id, \ |
49 | .id = TPS65090_ID_##_id, \ | 52 | .ops = &_ops, \ |
50 | .ops = &tps65090_ops, \ | 53 | .enable_reg = _en_reg, \ |
51 | .type = REGULATOR_VOLTAGE, \ | 54 | .enable_mask = BIT(0), \ |
52 | .owner = THIS_MODULE, \ | 55 | .type = REGULATOR_VOLTAGE, \ |
53 | .enable_reg = (TPS65090_ID_##_id) + 12, \ | 56 | .owner = THIS_MODULE, \ |
54 | .enable_mask = BIT(0), \ | ||
55 | }, \ | ||
56 | } | 57 | } |
57 | 58 | ||
58 | static struct tps65090_regulator TPS65090_regulator[] = { | 59 | static struct regulator_desc tps65090_regulator_desc[] = { |
59 | tps65090_REG(DCDC1), | 60 | tps65090_REG_DESC(DCDC1, "vsys1", 0x0C, tps65090_reg_contol_ops), |
60 | tps65090_REG(DCDC2), | 61 | tps65090_REG_DESC(DCDC2, "vsys2", 0x0D, tps65090_reg_contol_ops), |
61 | tps65090_REG(DCDC3), | 62 | tps65090_REG_DESC(DCDC3, "vsys3", 0x0E, tps65090_reg_contol_ops), |
62 | tps65090_REG(FET1), | 63 | tps65090_REG_DESC(FET1, "infet1", 0x0F, tps65090_reg_contol_ops), |
63 | tps65090_REG(FET2), | 64 | tps65090_REG_DESC(FET2, "infet2", 0x10, tps65090_reg_contol_ops), |
64 | tps65090_REG(FET3), | 65 | tps65090_REG_DESC(FET3, "infet3", 0x11, tps65090_reg_contol_ops), |
65 | tps65090_REG(FET4), | 66 | tps65090_REG_DESC(FET4, "infet4", 0x12, tps65090_reg_contol_ops), |
66 | tps65090_REG(FET5), | 67 | tps65090_REG_DESC(FET5, "infet5", 0x13, tps65090_reg_contol_ops), |
67 | tps65090_REG(FET6), | 68 | tps65090_REG_DESC(FET6, "infet6", 0x14, tps65090_reg_contol_ops), |
68 | tps65090_REG(FET7), | 69 | tps65090_REG_DESC(FET7, "infet7", 0x15, tps65090_reg_contol_ops), |
70 | tps65090_REG_DESC(LDO1, "vsys_l1", 0, tps65090_ldo_ops), | ||
71 | tps65090_REG_DESC(LDO2, "vsys_l2", 0, tps65090_ldo_ops), | ||
69 | }; | 72 | }; |
70 | 73 | ||
71 | static inline struct tps65090_regulator *find_regulator_info(int id) | 74 | static inline bool is_dcdc(int id) |
72 | { | 75 | { |
73 | struct tps65090_regulator *ri; | 76 | switch (id) { |
74 | int i; | 77 | case TPS65090_REGULATOR_DCDC1: |
78 | case TPS65090_REGULATOR_DCDC2: | ||
79 | case TPS65090_REGULATOR_DCDC3: | ||
80 | return true; | ||
81 | default: | ||
82 | return false; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | static int __devinit tps65090_config_ext_control( | ||
87 | struct tps65090_regulator *ri, bool enable) | ||
88 | { | ||
89 | int ret; | ||
90 | struct device *parent = ri->dev->parent; | ||
91 | unsigned int reg_en_reg = ri->desc->enable_reg; | ||
92 | |||
93 | if (enable) | ||
94 | ret = tps65090_set_bits(parent, reg_en_reg, 1); | ||
95 | else | ||
96 | ret = tps65090_clr_bits(parent, reg_en_reg, 1); | ||
97 | if (ret < 0) | ||
98 | dev_err(ri->dev, "Error in updating reg 0x%x\n", reg_en_reg); | ||
99 | return ret; | ||
100 | } | ||
101 | |||
102 | static int __devinit tps65090_regulator_disable_ext_control( | ||
103 | struct tps65090_regulator *ri, | ||
104 | struct tps65090_regulator_plat_data *tps_pdata) | ||
105 | { | ||
106 | int ret = 0; | ||
107 | struct device *parent = ri->dev->parent; | ||
108 | unsigned int reg_en_reg = ri->desc->enable_reg; | ||
109 | |||
110 | /* | ||
111 | * First enable output for internal control if require. | ||
112 | * And then disable external control. | ||
113 | */ | ||
114 | if (tps_pdata->reg_init_data->constraints.always_on || | ||
115 | tps_pdata->reg_init_data->constraints.boot_on) { | ||
116 | ret = tps65090_set_bits(parent, reg_en_reg, 0); | ||
117 | if (ret < 0) { | ||
118 | dev_err(ri->dev, "Error in set reg 0x%x\n", reg_en_reg); | ||
119 | return ret; | ||
120 | } | ||
121 | } | ||
122 | return tps65090_config_ext_control(ri, false); | ||
123 | } | ||
124 | |||
125 | static void __devinit tps65090_configure_regulator_config( | ||
126 | struct tps65090_regulator_plat_data *tps_pdata, | ||
127 | struct regulator_config *config) | ||
128 | { | ||
129 | if (gpio_is_valid(tps_pdata->gpio)) { | ||
130 | int gpio_flag = GPIOF_OUT_INIT_LOW; | ||
131 | |||
132 | if (tps_pdata->reg_init_data->constraints.always_on || | ||
133 | tps_pdata->reg_init_data->constraints.boot_on) | ||
134 | gpio_flag = GPIOF_OUT_INIT_HIGH; | ||
75 | 135 | ||
76 | for (i = 0; i < ARRAY_SIZE(TPS65090_regulator); i++) { | 136 | config->ena_gpio = tps_pdata->gpio; |
77 | ri = &TPS65090_regulator[i]; | 137 | config->ena_gpio_flags = gpio_flag; |
78 | if (ri->desc.id == id) | ||
79 | return ri; | ||
80 | } | 138 | } |
81 | return NULL; | ||
82 | } | 139 | } |
83 | 140 | ||
84 | static int __devinit tps65090_regulator_probe(struct platform_device *pdev) | 141 | static int __devinit tps65090_regulator_probe(struct platform_device *pdev) |
@@ -87,46 +144,110 @@ static int __devinit tps65090_regulator_probe(struct platform_device *pdev) | |||
87 | struct tps65090_regulator *ri = NULL; | 144 | struct tps65090_regulator *ri = NULL; |
88 | struct regulator_config config = { }; | 145 | struct regulator_config config = { }; |
89 | struct regulator_dev *rdev; | 146 | struct regulator_dev *rdev; |
90 | struct tps65090_regulator_platform_data *tps_pdata; | 147 | struct tps65090_regulator_plat_data *tps_pdata; |
91 | int id = pdev->id; | 148 | struct tps65090_regulator *pmic; |
149 | struct tps65090_platform_data *tps65090_pdata; | ||
150 | int num; | ||
151 | int ret; | ||
92 | 152 | ||
93 | dev_dbg(&pdev->dev, "Probing regulator %d\n", id); | 153 | dev_dbg(&pdev->dev, "Probing regulator\n"); |
94 | 154 | ||
95 | ri = find_regulator_info(id); | 155 | tps65090_pdata = dev_get_platdata(pdev->dev.parent); |
96 | if (ri == NULL) { | 156 | if (!tps65090_pdata) { |
97 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); | 157 | dev_err(&pdev->dev, "Platform data missing\n"); |
98 | return -EINVAL; | 158 | return -EINVAL; |
99 | } | 159 | } |
100 | tps_pdata = pdev->dev.platform_data; | 160 | |
101 | ri->dev = &pdev->dev; | 161 | pmic = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX * sizeof(*pmic), |
102 | 162 | GFP_KERNEL); | |
103 | config.dev = &pdev->dev; | 163 | if (!pmic) { |
104 | config.init_data = &tps_pdata->regulator; | 164 | dev_err(&pdev->dev, "mem alloc for pmic failed\n"); |
105 | config.driver_data = ri; | 165 | return -ENOMEM; |
106 | config.regmap = tps65090_mfd->rmap; | 166 | } |
107 | 167 | ||
108 | rdev = regulator_register(&ri->desc, &config); | 168 | for (num = 0; num < TPS65090_REGULATOR_MAX; num++) { |
109 | if (IS_ERR(rdev)) { | 169 | tps_pdata = tps65090_pdata->reg_pdata[num]; |
110 | dev_err(&pdev->dev, "failed to register regulator %s\n", | 170 | |
111 | ri->desc.name); | 171 | ri = &pmic[num]; |
112 | return PTR_ERR(rdev); | 172 | ri->dev = &pdev->dev; |
173 | ri->desc = &tps65090_regulator_desc[num]; | ||
174 | |||
175 | /* | ||
176 | * TPS5090 DCDC support the control from external digital input. | ||
177 | * Configure it as per platform data. | ||
178 | */ | ||
179 | if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data) { | ||
180 | if (tps_pdata->enable_ext_control) { | ||
181 | tps65090_configure_regulator_config( | ||
182 | tps_pdata, &config); | ||
183 | ri->desc->ops = &tps65090_ext_control_ops; | ||
184 | } else { | ||
185 | ret = tps65090_regulator_disable_ext_control( | ||
186 | ri, tps_pdata); | ||
187 | if (ret < 0) { | ||
188 | dev_err(&pdev->dev, | ||
189 | "failed disable ext control\n"); | ||
190 | goto scrub; | ||
191 | } | ||
192 | } | ||
193 | } | ||
194 | |||
195 | config.dev = &pdev->dev; | ||
196 | config.driver_data = ri; | ||
197 | config.regmap = tps65090_mfd->rmap; | ||
198 | if (tps_pdata) | ||
199 | config.init_data = tps_pdata->reg_init_data; | ||
200 | else | ||
201 | config.init_data = NULL; | ||
202 | |||
203 | rdev = regulator_register(ri->desc, &config); | ||
204 | if (IS_ERR(rdev)) { | ||
205 | dev_err(&pdev->dev, "failed to register regulator %s\n", | ||
206 | ri->desc->name); | ||
207 | ret = PTR_ERR(rdev); | ||
208 | goto scrub; | ||
209 | } | ||
210 | ri->rdev = rdev; | ||
211 | |||
212 | /* Enable external control if it is require */ | ||
213 | if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data && | ||
214 | tps_pdata->enable_ext_control) { | ||
215 | ret = tps65090_config_ext_control(ri, true); | ||
216 | if (ret < 0) { | ||
217 | /* Increment num to get unregister rdev */ | ||
218 | num++; | ||
219 | goto scrub; | ||
220 | } | ||
221 | } | ||
113 | } | 222 | } |
114 | 223 | ||
115 | platform_set_drvdata(pdev, rdev); | 224 | platform_set_drvdata(pdev, pmic); |
116 | return 0; | 225 | return 0; |
226 | |||
227 | scrub: | ||
228 | while (--num >= 0) { | ||
229 | ri = &pmic[num]; | ||
230 | regulator_unregister(ri->rdev); | ||
231 | } | ||
232 | return ret; | ||
117 | } | 233 | } |
118 | 234 | ||
119 | static int __devexit tps65090_regulator_remove(struct platform_device *pdev) | 235 | static int __devexit tps65090_regulator_remove(struct platform_device *pdev) |
120 | { | 236 | { |
121 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | 237 | struct tps65090_regulator *pmic = platform_get_drvdata(pdev); |
238 | struct tps65090_regulator *ri; | ||
239 | int num; | ||
122 | 240 | ||
123 | regulator_unregister(rdev); | 241 | for (num = 0; num < TPS65090_REGULATOR_MAX; ++num) { |
242 | ri = &pmic[num]; | ||
243 | regulator_unregister(ri->rdev); | ||
244 | } | ||
124 | return 0; | 245 | return 0; |
125 | } | 246 | } |
126 | 247 | ||
127 | static struct platform_driver tps65090_regulator_driver = { | 248 | static struct platform_driver tps65090_regulator_driver = { |
128 | .driver = { | 249 | .driver = { |
129 | .name = "tps65090-regulator", | 250 | .name = "tps65090-pmic", |
130 | .owner = THIS_MODULE, | 251 | .owner = THIS_MODULE, |
131 | }, | 252 | }, |
132 | .probe = tps65090_regulator_probe, | 253 | .probe = tps65090_regulator_probe, |
diff --git a/drivers/regulator/tps80031-regulator.c b/drivers/regulator/tps80031-regulator.c new file mode 100644 index 000000000000..a37ede80abbf --- /dev/null +++ b/drivers/regulator/tps80031-regulator.c | |||
@@ -0,0 +1,793 @@ | |||
1 | /* | ||
2 | * tps80031-regulator.c -- TI TPS80031 regulator driver. | ||
3 | * | ||
4 | * Regulator driver for TITPS80031/TPS80032 Fully Integrated Power | ||
5 | * Management with Power Path and Battery Charger. | ||
6 | * | ||
7 | * Copyright (c) 2012, NVIDIA Corporation. | ||
8 | * | ||
9 | * Author: Laxman Dewangan <ldewangan@nvidia.com> | ||
10 | * | ||
11 | * This program is free software; you can redistribute it and/or | ||
12 | * modify it under the terms of the GNU General Public License as | ||
13 | * published by the Free Software Foundation version 2. | ||
14 | * | ||
15 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, | ||
16 | * whether express or implied; without even the implied warranty of | ||
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
18 | * General Public License for more details. | ||
19 | * | ||
20 | * You should have received a copy of the GNU General Public License | ||
21 | * along with this program; if not, write to the Free Software | ||
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA | ||
23 | * 02111-1307, USA | ||
24 | */ | ||
25 | |||
26 | #include <linux/delay.h> | ||
27 | #include <linux/err.h> | ||
28 | #include <linux/init.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/mfd/tps80031.h> | ||
31 | #include <linux/module.h> | ||
32 | #include <linux/platform_device.h> | ||
33 | #include <linux/regulator/driver.h> | ||
34 | #include <linux/regulator/machine.h> | ||
35 | #include <linux/slab.h> | ||
36 | |||
37 | /* Flags for DCDC Voltage reading */ | ||
38 | #define DCDC_OFFSET_EN BIT(0) | ||
39 | #define DCDC_EXTENDED_EN BIT(1) | ||
40 | #define TRACK_MODE_ENABLE BIT(2) | ||
41 | |||
42 | #define SMPS_MULTOFFSET_VIO BIT(1) | ||
43 | #define SMPS_MULTOFFSET_SMPS1 BIT(3) | ||
44 | #define SMPS_MULTOFFSET_SMPS2 BIT(4) | ||
45 | #define SMPS_MULTOFFSET_SMPS3 BIT(6) | ||
46 | #define SMPS_MULTOFFSET_SMPS4 BIT(0) | ||
47 | |||
48 | #define SMPS_CMD_MASK 0xC0 | ||
49 | #define SMPS_VSEL_MASK 0x3F | ||
50 | #define LDO_VSEL_MASK 0x1F | ||
51 | #define LDO_TRACK_VSEL_MASK 0x3F | ||
52 | |||
53 | #define MISC2_LDOUSB_IN_VSYS BIT(4) | ||
54 | #define MISC2_LDOUSB_IN_PMID BIT(3) | ||
55 | #define MISC2_LDOUSB_IN_MASK 0x18 | ||
56 | |||
57 | #define MISC2_LDO3_SEL_VIB_VAL BIT(0) | ||
58 | #define MISC2_LDO3_SEL_VIB_MASK 0x1 | ||
59 | |||
60 | #define BOOST_HW_PWR_EN BIT(5) | ||
61 | #define BOOST_HW_PWR_EN_MASK BIT(5) | ||
62 | |||
63 | #define OPA_MODE_EN BIT(6) | ||
64 | #define OPA_MODE_EN_MASK BIT(6) | ||
65 | |||
66 | #define USB_VBUS_CTRL_SET 0x04 | ||
67 | #define USB_VBUS_CTRL_CLR 0x05 | ||
68 | #define VBUS_DISCHRG 0x20 | ||
69 | |||
70 | struct tps80031_regulator_info { | ||
71 | /* Regulator register address.*/ | ||
72 | u8 trans_reg; | ||
73 | u8 state_reg; | ||
74 | u8 force_reg; | ||
75 | u8 volt_reg; | ||
76 | u8 volt_id; | ||
77 | |||
78 | /*Power request bits */ | ||
79 | int preq_bit; | ||
80 | |||
81 | /* used by regulator core */ | ||
82 | struct regulator_desc desc; | ||
83 | |||
84 | }; | ||
85 | |||
86 | struct tps80031_regulator { | ||
87 | struct device *dev; | ||
88 | struct regulator_dev *rdev; | ||
89 | struct tps80031_regulator_info *rinfo; | ||
90 | |||
91 | u8 device_flags; | ||
92 | unsigned int config_flags; | ||
93 | unsigned int ext_ctrl_flag; | ||
94 | }; | ||
95 | |||
96 | static inline struct device *to_tps80031_dev(struct regulator_dev *rdev) | ||
97 | { | ||
98 | return rdev_get_dev(rdev)->parent->parent; | ||
99 | } | ||
100 | |||
101 | static int tps80031_reg_is_enabled(struct regulator_dev *rdev) | ||
102 | { | ||
103 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
104 | struct device *parent = to_tps80031_dev(rdev); | ||
105 | u8 reg_val; | ||
106 | int ret; | ||
107 | |||
108 | if (ri->ext_ctrl_flag & TPS80031_EXT_PWR_REQ) | ||
109 | return true; | ||
110 | |||
111 | ret = tps80031_read(parent, TPS80031_SLAVE_ID1, ri->rinfo->state_reg, | ||
112 | ®_val); | ||
113 | if (ret < 0) { | ||
114 | dev_err(&rdev->dev, "Reg 0x%02x read failed, err = %d\n", | ||
115 | ri->rinfo->state_reg, ret); | ||
116 | return ret; | ||
117 | } | ||
118 | return ((reg_val & TPS80031_STATE_MASK) == TPS80031_STATE_ON); | ||
119 | } | ||
120 | |||
121 | static int tps80031_reg_enable(struct regulator_dev *rdev) | ||
122 | { | ||
123 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
124 | struct device *parent = to_tps80031_dev(rdev); | ||
125 | int ret; | ||
126 | |||
127 | if (ri->ext_ctrl_flag & TPS80031_EXT_PWR_REQ) | ||
128 | return 0; | ||
129 | |||
130 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, ri->rinfo->state_reg, | ||
131 | TPS80031_STATE_ON, TPS80031_STATE_MASK); | ||
132 | if (ret < 0) { | ||
133 | dev_err(&rdev->dev, "Reg 0x%02x update failed, err = %d\n", | ||
134 | ri->rinfo->state_reg, ret); | ||
135 | return ret; | ||
136 | } | ||
137 | return ret; | ||
138 | } | ||
139 | |||
140 | static int tps80031_reg_disable(struct regulator_dev *rdev) | ||
141 | { | ||
142 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
143 | struct device *parent = to_tps80031_dev(rdev); | ||
144 | int ret; | ||
145 | |||
146 | if (ri->ext_ctrl_flag & TPS80031_EXT_PWR_REQ) | ||
147 | return 0; | ||
148 | |||
149 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, ri->rinfo->state_reg, | ||
150 | TPS80031_STATE_OFF, TPS80031_STATE_MASK); | ||
151 | if (ret < 0) | ||
152 | dev_err(&rdev->dev, "Reg 0x%02x update failed, err = %d\n", | ||
153 | ri->rinfo->state_reg, ret); | ||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | /* DCDC voltages for the selector of 58 to 63 */ | ||
158 | static int tps80031_dcdc_voltages[4][5] = { | ||
159 | { 1350, 1500, 1800, 1900, 2100}, | ||
160 | { 1350, 1500, 1800, 1900, 2100}, | ||
161 | { 2084, 2315, 2778, 2932, 3241}, | ||
162 | { 4167, 2315, 2778, 2932, 3241}, | ||
163 | }; | ||
164 | |||
165 | static int tps80031_dcdc_list_voltage(struct regulator_dev *rdev, unsigned sel) | ||
166 | { | ||
167 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
168 | int volt_index = ri->device_flags & 0x3; | ||
169 | |||
170 | if (sel == 0) | ||
171 | return 0; | ||
172 | else if (sel < 58) | ||
173 | return regulator_list_voltage_linear(rdev, sel - 1); | ||
174 | else | ||
175 | return tps80031_dcdc_voltages[volt_index][sel - 58] * 1000; | ||
176 | } | ||
177 | |||
178 | static int tps80031_dcdc_set_voltage_sel(struct regulator_dev *rdev, | ||
179 | unsigned vsel) | ||
180 | { | ||
181 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
182 | struct device *parent = to_tps80031_dev(rdev); | ||
183 | int ret; | ||
184 | u8 reg_val; | ||
185 | |||
186 | if (ri->rinfo->force_reg) { | ||
187 | ret = tps80031_read(parent, ri->rinfo->volt_id, | ||
188 | ri->rinfo->force_reg, ®_val); | ||
189 | if (ret < 0) { | ||
190 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
191 | ri->rinfo->force_reg, ret); | ||
192 | return ret; | ||
193 | } | ||
194 | if (!(reg_val & SMPS_CMD_MASK)) { | ||
195 | ret = tps80031_update(parent, ri->rinfo->volt_id, | ||
196 | ri->rinfo->force_reg, vsel, SMPS_VSEL_MASK); | ||
197 | if (ret < 0) | ||
198 | dev_err(ri->dev, | ||
199 | "reg 0x%02x update failed, e = %d\n", | ||
200 | ri->rinfo->force_reg, ret); | ||
201 | return ret; | ||
202 | } | ||
203 | } | ||
204 | ret = tps80031_update(parent, ri->rinfo->volt_id, | ||
205 | ri->rinfo->volt_reg, vsel, SMPS_VSEL_MASK); | ||
206 | if (ret < 0) | ||
207 | dev_err(ri->dev, "reg 0x%02x update failed, e = %d\n", | ||
208 | ri->rinfo->volt_reg, ret); | ||
209 | return ret; | ||
210 | } | ||
211 | |||
212 | static int tps80031_dcdc_get_voltage_sel(struct regulator_dev *rdev) | ||
213 | { | ||
214 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
215 | struct device *parent = to_tps80031_dev(rdev); | ||
216 | uint8_t vsel = 0; | ||
217 | int ret; | ||
218 | |||
219 | if (ri->rinfo->force_reg) { | ||
220 | ret = tps80031_read(parent, ri->rinfo->volt_id, | ||
221 | ri->rinfo->force_reg, &vsel); | ||
222 | if (ret < 0) { | ||
223 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
224 | ri->rinfo->force_reg, ret); | ||
225 | return ret; | ||
226 | } | ||
227 | |||
228 | if (!(vsel & SMPS_CMD_MASK)) | ||
229 | return vsel & SMPS_VSEL_MASK; | ||
230 | } | ||
231 | ret = tps80031_read(parent, ri->rinfo->volt_id, | ||
232 | ri->rinfo->volt_reg, &vsel); | ||
233 | if (ret < 0) { | ||
234 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
235 | ri->rinfo->volt_reg, ret); | ||
236 | return ret; | ||
237 | } | ||
238 | return vsel & SMPS_VSEL_MASK; | ||
239 | } | ||
240 | |||
241 | static int tps80031_ldo_set_voltage_sel(struct regulator_dev *rdev, | ||
242 | unsigned sel) | ||
243 | { | ||
244 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
245 | struct device *parent = to_tps80031_dev(rdev); | ||
246 | int ret; | ||
247 | |||
248 | /* Check for valid setting for TPS80031 or TPS80032-ES1.0 */ | ||
249 | if ((ri->rinfo->desc.id == TPS80031_REGULATOR_LDO2) && | ||
250 | (ri->device_flags & TRACK_MODE_ENABLE)) { | ||
251 | unsigned nvsel = (sel) & 0x1F; | ||
252 | if (((tps80031_get_chip_info(parent) == TPS80031) || | ||
253 | ((tps80031_get_chip_info(parent) == TPS80032) && | ||
254 | (tps80031_get_pmu_version(parent) == 0x0))) && | ||
255 | ((nvsel == 0x0) || (nvsel >= 0x19 && nvsel <= 0x1F))) { | ||
256 | dev_err(ri->dev, | ||
257 | "Invalid sel %d in track mode LDO2\n", | ||
258 | nvsel); | ||
259 | return -EINVAL; | ||
260 | } | ||
261 | } | ||
262 | |||
263 | ret = tps80031_write(parent, ri->rinfo->volt_id, | ||
264 | ri->rinfo->volt_reg, sel); | ||
265 | if (ret < 0) | ||
266 | dev_err(ri->dev, "Error in writing reg 0x%02x, e = %d\n", | ||
267 | ri->rinfo->volt_reg, ret); | ||
268 | return ret; | ||
269 | } | ||
270 | |||
271 | static int tps80031_ldo_get_voltage_sel(struct regulator_dev *rdev) | ||
272 | { | ||
273 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
274 | struct device *parent = to_tps80031_dev(rdev); | ||
275 | uint8_t vsel; | ||
276 | int ret; | ||
277 | |||
278 | ret = tps80031_read(parent, ri->rinfo->volt_id, | ||
279 | ri->rinfo->volt_reg, &vsel); | ||
280 | if (ret < 0) { | ||
281 | dev_err(ri->dev, "Error in writing the Voltage register\n"); | ||
282 | return ret; | ||
283 | } | ||
284 | return vsel & rdev->desc->vsel_mask; | ||
285 | } | ||
286 | |||
287 | static int tps80031_ldo_list_voltage(struct regulator_dev *rdev, unsigned sel) | ||
288 | { | ||
289 | if (sel == 0) | ||
290 | return 0; | ||
291 | else | ||
292 | return regulator_list_voltage_linear(rdev, sel - 1); | ||
293 | } | ||
294 | |||
295 | static int tps80031_vbus_is_enabled(struct regulator_dev *rdev) | ||
296 | { | ||
297 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
298 | struct device *parent = to_tps80031_dev(rdev); | ||
299 | int ret = -EIO; | ||
300 | uint8_t ctrl1 = 0; | ||
301 | uint8_t ctrl3 = 0; | ||
302 | |||
303 | ret = tps80031_read(parent, TPS80031_SLAVE_ID2, | ||
304 | TPS80031_CHARGERUSB_CTRL1, &ctrl1); | ||
305 | if (ret < 0) { | ||
306 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
307 | TPS80031_CHARGERUSB_CTRL1, ret); | ||
308 | return ret; | ||
309 | } | ||
310 | ret = tps80031_read(parent, TPS80031_SLAVE_ID2, | ||
311 | TPS80031_CHARGERUSB_CTRL3, &ctrl3); | ||
312 | if (ret < 0) { | ||
313 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
314 | TPS80031_CHARGERUSB_CTRL1, ret); | ||
315 | return ret; | ||
316 | } | ||
317 | if ((ctrl1 & OPA_MODE_EN) && (ctrl3 & BOOST_HW_PWR_EN)) | ||
318 | return 1; | ||
319 | return ret; | ||
320 | } | ||
321 | |||
322 | static int tps80031_vbus_enable(struct regulator_dev *rdev) | ||
323 | { | ||
324 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
325 | struct device *parent = to_tps80031_dev(rdev); | ||
326 | int ret; | ||
327 | |||
328 | ret = tps80031_set_bits(parent, TPS80031_SLAVE_ID2, | ||
329 | TPS80031_CHARGERUSB_CTRL1, OPA_MODE_EN); | ||
330 | if (ret < 0) { | ||
331 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
332 | TPS80031_CHARGERUSB_CTRL1, ret); | ||
333 | return ret; | ||
334 | } | ||
335 | |||
336 | ret = tps80031_set_bits(parent, TPS80031_SLAVE_ID2, | ||
337 | TPS80031_CHARGERUSB_CTRL3, BOOST_HW_PWR_EN); | ||
338 | if (ret < 0) { | ||
339 | dev_err(ri->dev, "reg 0x%02x read failed, e = %d\n", | ||
340 | TPS80031_CHARGERUSB_CTRL3, ret); | ||
341 | return ret; | ||
342 | } | ||
343 | return ret; | ||
344 | } | ||
345 | |||
346 | static int tps80031_vbus_disable(struct regulator_dev *rdev) | ||
347 | { | ||
348 | struct tps80031_regulator *ri = rdev_get_drvdata(rdev); | ||
349 | struct device *parent = to_tps80031_dev(rdev); | ||
350 | int ret = 0; | ||
351 | |||
352 | if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) { | ||
353 | ret = tps80031_write(parent, TPS80031_SLAVE_ID2, | ||
354 | USB_VBUS_CTRL_SET, VBUS_DISCHRG); | ||
355 | if (ret < 0) { | ||
356 | dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n", | ||
357 | USB_VBUS_CTRL_SET, ret); | ||
358 | return ret; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2, | ||
363 | TPS80031_CHARGERUSB_CTRL1, OPA_MODE_EN); | ||
364 | if (ret < 0) { | ||
365 | dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n", | ||
366 | TPS80031_CHARGERUSB_CTRL1, ret); | ||
367 | return ret; | ||
368 | } | ||
369 | |||
370 | ret = tps80031_clr_bits(parent, TPS80031_SLAVE_ID2, | ||
371 | TPS80031_CHARGERUSB_CTRL3, BOOST_HW_PWR_EN); | ||
372 | if (ret < 0) { | ||
373 | dev_err(ri->dev, "reg 0x%02x clearbit failed, e = %d\n", | ||
374 | TPS80031_CHARGERUSB_CTRL3, ret); | ||
375 | return ret; | ||
376 | } | ||
377 | |||
378 | mdelay(DIV_ROUND_UP(ri->rinfo->desc.enable_time, 1000)); | ||
379 | if (ri->config_flags & TPS80031_VBUS_DISCHRG_EN_PDN) { | ||
380 | ret = tps80031_write(parent, TPS80031_SLAVE_ID2, | ||
381 | USB_VBUS_CTRL_CLR, VBUS_DISCHRG); | ||
382 | if (ret < 0) { | ||
383 | dev_err(ri->dev, "reg 0x%02x write failed, e = %d\n", | ||
384 | USB_VBUS_CTRL_CLR, ret); | ||
385 | return ret; | ||
386 | } | ||
387 | } | ||
388 | return ret; | ||
389 | } | ||
390 | |||
391 | static struct regulator_ops tps80031_dcdc_ops = { | ||
392 | .list_voltage = tps80031_dcdc_list_voltage, | ||
393 | .set_voltage_sel = tps80031_dcdc_set_voltage_sel, | ||
394 | .get_voltage_sel = tps80031_dcdc_get_voltage_sel, | ||
395 | .enable = tps80031_reg_enable, | ||
396 | .disable = tps80031_reg_disable, | ||
397 | .is_enabled = tps80031_reg_is_enabled, | ||
398 | }; | ||
399 | |||
400 | static struct regulator_ops tps80031_ldo_ops = { | ||
401 | .list_voltage = tps80031_ldo_list_voltage, | ||
402 | .set_voltage_sel = tps80031_ldo_set_voltage_sel, | ||
403 | .get_voltage_sel = tps80031_ldo_get_voltage_sel, | ||
404 | .enable = tps80031_reg_enable, | ||
405 | .disable = tps80031_reg_disable, | ||
406 | .is_enabled = tps80031_reg_is_enabled, | ||
407 | }; | ||
408 | |||
409 | static struct regulator_ops tps80031_vbus_sw_ops = { | ||
410 | .enable = tps80031_vbus_enable, | ||
411 | .disable = tps80031_vbus_disable, | ||
412 | .is_enabled = tps80031_vbus_is_enabled, | ||
413 | }; | ||
414 | |||
415 | static struct regulator_ops tps80031_vbus_hw_ops = { | ||
416 | }; | ||
417 | |||
418 | static struct regulator_ops tps80031_ext_reg_ops = { | ||
419 | .enable = tps80031_reg_enable, | ||
420 | .disable = tps80031_reg_disable, | ||
421 | .is_enabled = tps80031_reg_is_enabled, | ||
422 | }; | ||
423 | |||
424 | /* Non-exiting default definition for some register */ | ||
425 | #define TPS80031_SMPS3_CFG_FORCE 0 | ||
426 | #define TPS80031_SMPS4_CFG_FORCE 0 | ||
427 | |||
428 | #define TPS80031_VBUS_CFG_TRANS 0 | ||
429 | #define TPS80031_VBUS_CFG_STATE 0 | ||
430 | |||
431 | #define TPS80031_REG_SMPS(_id, _volt_id, _pbit) \ | ||
432 | { \ | ||
433 | .trans_reg = TPS80031_##_id##_CFG_TRANS, \ | ||
434 | .state_reg = TPS80031_##_id##_CFG_STATE, \ | ||
435 | .force_reg = TPS80031_##_id##_CFG_FORCE, \ | ||
436 | .volt_reg = TPS80031_##_id##_CFG_VOLTAGE, \ | ||
437 | .volt_id = TPS80031_SLAVE_##_volt_id, \ | ||
438 | .preq_bit = _pbit, \ | ||
439 | .desc = { \ | ||
440 | .name = "tps80031_"#_id, \ | ||
441 | .id = TPS80031_REGULATOR_##_id, \ | ||
442 | .n_voltages = 63, \ | ||
443 | .ops = &tps80031_dcdc_ops, \ | ||
444 | .type = REGULATOR_VOLTAGE, \ | ||
445 | .owner = THIS_MODULE, \ | ||
446 | .enable_time = 500, \ | ||
447 | }, \ | ||
448 | } | ||
449 | |||
450 | #define TPS80031_REG_LDO(_id, _preq_bit) \ | ||
451 | { \ | ||
452 | .trans_reg = TPS80031_##_id##_CFG_TRANS, \ | ||
453 | .state_reg = TPS80031_##_id##_CFG_STATE, \ | ||
454 | .volt_reg = TPS80031_##_id##_CFG_VOLTAGE, \ | ||
455 | .volt_id = TPS80031_SLAVE_ID1, \ | ||
456 | .preq_bit = _preq_bit, \ | ||
457 | .desc = { \ | ||
458 | .owner = THIS_MODULE, \ | ||
459 | .name = "tps80031_"#_id, \ | ||
460 | .id = TPS80031_REGULATOR_##_id, \ | ||
461 | .ops = &tps80031_ldo_ops, \ | ||
462 | .type = REGULATOR_VOLTAGE, \ | ||
463 | .min_uV = 1000000, \ | ||
464 | .uV_step = 100000, \ | ||
465 | .n_voltages = 25, \ | ||
466 | .vsel_mask = LDO_VSEL_MASK, \ | ||
467 | .enable_time = 500, \ | ||
468 | }, \ | ||
469 | } | ||
470 | |||
471 | #define TPS80031_REG_FIXED(_id, max_mV, _ops, _delay, _pbit) \ | ||
472 | { \ | ||
473 | .trans_reg = TPS80031_##_id##_CFG_TRANS, \ | ||
474 | .state_reg = TPS80031_##_id##_CFG_STATE, \ | ||
475 | .volt_id = TPS80031_SLAVE_ID1, \ | ||
476 | .preq_bit = _pbit, \ | ||
477 | .desc = { \ | ||
478 | .name = "tps80031_"#_id, \ | ||
479 | .id = TPS80031_REGULATOR_##_id, \ | ||
480 | .n_voltages = 2, \ | ||
481 | .ops = &_ops, \ | ||
482 | .type = REGULATOR_VOLTAGE, \ | ||
483 | .owner = THIS_MODULE, \ | ||
484 | .enable_time = _delay, \ | ||
485 | }, \ | ||
486 | } | ||
487 | |||
488 | static struct tps80031_regulator_info tps80031_rinfo[TPS80031_REGULATOR_MAX] = { | ||
489 | TPS80031_REG_SMPS(VIO, ID0, 4), | ||
490 | TPS80031_REG_SMPS(SMPS1, ID0, 0), | ||
491 | TPS80031_REG_SMPS(SMPS2, ID0, 1), | ||
492 | TPS80031_REG_SMPS(SMPS3, ID1, 2), | ||
493 | TPS80031_REG_SMPS(SMPS4, ID1, 3), | ||
494 | TPS80031_REG_LDO(VANA, -1), | ||
495 | TPS80031_REG_LDO(LDO1, 8), | ||
496 | TPS80031_REG_LDO(LDO2, 9), | ||
497 | TPS80031_REG_LDO(LDO3, 10), | ||
498 | TPS80031_REG_LDO(LDO4, 11), | ||
499 | TPS80031_REG_LDO(LDO5, 12), | ||
500 | TPS80031_REG_LDO(LDO6, 13), | ||
501 | TPS80031_REG_LDO(LDO7, 14), | ||
502 | TPS80031_REG_LDO(LDOLN, 15), | ||
503 | TPS80031_REG_LDO(LDOUSB, 5), | ||
504 | TPS80031_REG_FIXED(VBUS, 5000, tps80031_vbus_hw_ops, 100000, -1), | ||
505 | TPS80031_REG_FIXED(REGEN1, 3300, tps80031_ext_reg_ops, 0, 16), | ||
506 | TPS80031_REG_FIXED(REGEN2, 3300, tps80031_ext_reg_ops, 0, 17), | ||
507 | TPS80031_REG_FIXED(SYSEN, 3300, tps80031_ext_reg_ops, 0, 18), | ||
508 | }; | ||
509 | |||
510 | static int tps80031_power_req_config(struct device *parent, | ||
511 | struct tps80031_regulator *ri, | ||
512 | struct tps80031_regulator_platform_data *tps80031_pdata) | ||
513 | { | ||
514 | int ret = 0; | ||
515 | |||
516 | if (ri->rinfo->preq_bit < 0) | ||
517 | goto skip_pwr_req_config; | ||
518 | |||
519 | ret = tps80031_ext_power_req_config(parent, ri->ext_ctrl_flag, | ||
520 | ri->rinfo->preq_bit, ri->rinfo->state_reg, | ||
521 | ri->rinfo->trans_reg); | ||
522 | if (ret < 0) { | ||
523 | dev_err(ri->dev, "ext powerreq config failed, err = %d\n", ret); | ||
524 | return ret; | ||
525 | } | ||
526 | |||
527 | skip_pwr_req_config: | ||
528 | if (tps80031_pdata->ext_ctrl_flag & TPS80031_PWR_ON_ON_SLEEP) { | ||
529 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, | ||
530 | ri->rinfo->trans_reg, TPS80031_TRANS_SLEEP_ON, | ||
531 | TPS80031_TRANS_SLEEP_MASK); | ||
532 | if (ret < 0) { | ||
533 | dev_err(ri->dev, "Reg 0x%02x update failed, e %d\n", | ||
534 | ri->rinfo->trans_reg, ret); | ||
535 | return ret; | ||
536 | } | ||
537 | } | ||
538 | return ret; | ||
539 | } | ||
540 | |||
541 | static int tps80031_regulator_config(struct device *parent, | ||
542 | struct tps80031_regulator *ri, | ||
543 | struct tps80031_regulator_platform_data *tps80031_pdata) | ||
544 | { | ||
545 | int ret = 0; | ||
546 | |||
547 | switch (ri->rinfo->desc.id) { | ||
548 | case TPS80031_REGULATOR_LDOUSB: | ||
549 | if (ri->config_flags & (TPS80031_USBLDO_INPUT_VSYS | | ||
550 | TPS80031_USBLDO_INPUT_PMID)) { | ||
551 | unsigned val = 0; | ||
552 | if (ri->config_flags & TPS80031_USBLDO_INPUT_VSYS) | ||
553 | val = MISC2_LDOUSB_IN_VSYS; | ||
554 | else | ||
555 | val = MISC2_LDOUSB_IN_PMID; | ||
556 | |||
557 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, | ||
558 | TPS80031_MISC2, val, | ||
559 | MISC2_LDOUSB_IN_MASK); | ||
560 | if (ret < 0) { | ||
561 | dev_err(ri->dev, | ||
562 | "LDOUSB config failed, e= %d\n", ret); | ||
563 | return ret; | ||
564 | } | ||
565 | } | ||
566 | break; | ||
567 | |||
568 | case TPS80031_REGULATOR_LDO3: | ||
569 | if (ri->config_flags & TPS80031_LDO3_OUTPUT_VIB) { | ||
570 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, | ||
571 | TPS80031_MISC2, MISC2_LDO3_SEL_VIB_VAL, | ||
572 | MISC2_LDO3_SEL_VIB_MASK); | ||
573 | if (ret < 0) { | ||
574 | dev_err(ri->dev, | ||
575 | "LDO3 config failed, e = %d\n", ret); | ||
576 | return ret; | ||
577 | } | ||
578 | } | ||
579 | break; | ||
580 | |||
581 | case TPS80031_REGULATOR_VBUS: | ||
582 | /* Provide SW control Ops if VBUS is SW control */ | ||
583 | if (!(ri->config_flags & TPS80031_VBUS_SW_ONLY)) | ||
584 | ri->rinfo->desc.ops = &tps80031_vbus_sw_ops; | ||
585 | break; | ||
586 | default: | ||
587 | break; | ||
588 | } | ||
589 | |||
590 | /* Configure Active state to ON, SLEEP to OFF and OFF_state to OFF */ | ||
591 | ret = tps80031_update(parent, TPS80031_SLAVE_ID1, ri->rinfo->trans_reg, | ||
592 | TPS80031_TRANS_ACTIVE_ON | TPS80031_TRANS_SLEEP_OFF | | ||
593 | TPS80031_TRANS_OFF_OFF, TPS80031_TRANS_ACTIVE_MASK | | ||
594 | TPS80031_TRANS_SLEEP_MASK | TPS80031_TRANS_OFF_MASK); | ||
595 | if (ret < 0) { | ||
596 | dev_err(ri->dev, "trans reg update failed, e %d\n", ret); | ||
597 | return ret; | ||
598 | } | ||
599 | |||
600 | return ret; | ||
601 | } | ||
602 | |||
603 | static int check_smps_mode_mult(struct device *parent, | ||
604 | struct tps80031_regulator *ri) | ||
605 | { | ||
606 | int mult_offset; | ||
607 | int ret; | ||
608 | u8 smps_offset; | ||
609 | u8 smps_mult; | ||
610 | |||
611 | ret = tps80031_read(parent, TPS80031_SLAVE_ID1, | ||
612 | TPS80031_SMPS_OFFSET, &smps_offset); | ||
613 | if (ret < 0) { | ||
614 | dev_err(parent, "Error in reading smps offset register\n"); | ||
615 | return ret; | ||
616 | } | ||
617 | |||
618 | ret = tps80031_read(parent, TPS80031_SLAVE_ID1, | ||
619 | TPS80031_SMPS_MULT, &smps_mult); | ||
620 | if (ret < 0) { | ||
621 | dev_err(parent, "Error in reading smps mult register\n"); | ||
622 | return ret; | ||
623 | } | ||
624 | |||
625 | switch (ri->rinfo->desc.id) { | ||
626 | case TPS80031_REGULATOR_VIO: | ||
627 | mult_offset = SMPS_MULTOFFSET_VIO; | ||
628 | break; | ||
629 | case TPS80031_REGULATOR_SMPS1: | ||
630 | mult_offset = SMPS_MULTOFFSET_SMPS1; | ||
631 | break; | ||
632 | case TPS80031_REGULATOR_SMPS2: | ||
633 | mult_offset = SMPS_MULTOFFSET_SMPS2; | ||
634 | break; | ||
635 | case TPS80031_REGULATOR_SMPS3: | ||
636 | mult_offset = SMPS_MULTOFFSET_SMPS3; | ||
637 | break; | ||
638 | case TPS80031_REGULATOR_SMPS4: | ||
639 | mult_offset = SMPS_MULTOFFSET_SMPS4; | ||
640 | break; | ||
641 | case TPS80031_REGULATOR_LDO2: | ||
642 | ri->device_flags = smps_mult & BIT(5) ? TRACK_MODE_ENABLE : 0; | ||
643 | /* TRACK mode the ldo2 varies from 600mV to 1300mV */ | ||
644 | if (ri->device_flags & TRACK_MODE_ENABLE) { | ||
645 | ri->rinfo->desc.min_uV = 600000; | ||
646 | ri->rinfo->desc.uV_step = 12500; | ||
647 | ri->rinfo->desc.n_voltages = 57; | ||
648 | ri->rinfo->desc.vsel_mask = LDO_TRACK_VSEL_MASK; | ||
649 | } | ||
650 | return 0; | ||
651 | default: | ||
652 | return 0; | ||
653 | } | ||
654 | |||
655 | ri->device_flags = (smps_offset & mult_offset) ? DCDC_OFFSET_EN : 0; | ||
656 | ri->device_flags |= (smps_mult & mult_offset) ? DCDC_EXTENDED_EN : 0; | ||
657 | switch (ri->device_flags) { | ||
658 | case 0: | ||
659 | ri->rinfo->desc.min_uV = 607700; | ||
660 | ri->rinfo->desc.uV_step = 12660; | ||
661 | break; | ||
662 | case DCDC_OFFSET_EN: | ||
663 | ri->rinfo->desc.min_uV = 700000; | ||
664 | ri->rinfo->desc.uV_step = 12500; | ||
665 | break; | ||
666 | case DCDC_EXTENDED_EN: | ||
667 | ri->rinfo->desc.min_uV = 1852000; | ||
668 | ri->rinfo->desc.uV_step = 38600; | ||
669 | break; | ||
670 | case DCDC_OFFSET_EN | DCDC_EXTENDED_EN: | ||
671 | ri->rinfo->desc.min_uV = 2161000; | ||
672 | ri->rinfo->desc.uV_step = 38600; | ||
673 | break; | ||
674 | } | ||
675 | return 0; | ||
676 | } | ||
677 | |||
678 | static int __devinit tps80031_regulator_probe(struct platform_device *pdev) | ||
679 | { | ||
680 | struct tps80031_platform_data *pdata; | ||
681 | struct tps80031_regulator_platform_data *tps_pdata; | ||
682 | struct tps80031_regulator_info *rinfo; | ||
683 | struct tps80031_regulator *ri; | ||
684 | struct tps80031_regulator *pmic; | ||
685 | struct regulator_dev *rdev; | ||
686 | struct regulator_config config = { }; | ||
687 | int ret; | ||
688 | int num; | ||
689 | |||
690 | pdata = dev_get_platdata(pdev->dev.parent); | ||
691 | |||
692 | if (!pdata) { | ||
693 | dev_err(&pdev->dev, "No platform data\n"); | ||
694 | return -EINVAL; | ||
695 | } | ||
696 | |||
697 | pmic = devm_kzalloc(&pdev->dev, | ||
698 | TPS80031_REGULATOR_MAX * sizeof(*pmic), GFP_KERNEL); | ||
699 | if (!pmic) { | ||
700 | dev_err(&pdev->dev, "mem alloc for pmic failed\n"); | ||
701 | return -ENOMEM; | ||
702 | } | ||
703 | |||
704 | for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) { | ||
705 | tps_pdata = pdata->regulator_pdata[num]; | ||
706 | rinfo = &tps80031_rinfo[num]; | ||
707 | ri = &pmic[num]; | ||
708 | ri->rinfo = rinfo; | ||
709 | ri->dev = &pdev->dev; | ||
710 | |||
711 | check_smps_mode_mult(pdev->dev.parent, ri); | ||
712 | config.dev = &pdev->dev; | ||
713 | config.init_data = NULL; | ||
714 | config.driver_data = ri; | ||
715 | if (tps_pdata) { | ||
716 | config.init_data = tps_pdata->reg_init_data; | ||
717 | ri->config_flags = tps_pdata->config_flags; | ||
718 | ri->ext_ctrl_flag = tps_pdata->ext_ctrl_flag; | ||
719 | ret = tps80031_regulator_config(pdev->dev.parent, | ||
720 | ri, tps_pdata); | ||
721 | if (ret < 0) { | ||
722 | dev_err(&pdev->dev, | ||
723 | "regulator config failed, e %d\n", ret); | ||
724 | goto fail; | ||
725 | } | ||
726 | |||
727 | ret = tps80031_power_req_config(pdev->dev.parent, | ||
728 | ri, tps_pdata); | ||
729 | if (ret < 0) { | ||
730 | dev_err(&pdev->dev, | ||
731 | "pwr_req config failed, err %d\n", ret); | ||
732 | goto fail; | ||
733 | } | ||
734 | } | ||
735 | rdev = regulator_register(&ri->rinfo->desc, &config); | ||
736 | if (IS_ERR_OR_NULL(rdev)) { | ||
737 | dev_err(&pdev->dev, | ||
738 | "register regulator failed %s\n", | ||
739 | ri->rinfo->desc.name); | ||
740 | ret = PTR_ERR(rdev); | ||
741 | goto fail; | ||
742 | } | ||
743 | ri->rdev = rdev; | ||
744 | } | ||
745 | |||
746 | platform_set_drvdata(pdev, pmic); | ||
747 | return 0; | ||
748 | fail: | ||
749 | while (--num >= 0) { | ||
750 | ri = &pmic[num]; | ||
751 | regulator_unregister(ri->rdev); | ||
752 | } | ||
753 | return ret; | ||
754 | } | ||
755 | |||
756 | static int __devexit tps80031_regulator_remove(struct platform_device *pdev) | ||
757 | { | ||
758 | struct tps80031_regulator *pmic = platform_get_drvdata(pdev); | ||
759 | struct tps80031_regulator *ri = NULL; | ||
760 | int num; | ||
761 | |||
762 | for (num = 0; num < TPS80031_REGULATOR_MAX; ++num) { | ||
763 | ri = &pmic[num]; | ||
764 | regulator_unregister(ri->rdev); | ||
765 | } | ||
766 | return 0; | ||
767 | } | ||
768 | |||
769 | static struct platform_driver tps80031_regulator_driver = { | ||
770 | .driver = { | ||
771 | .name = "tps80031-pmic", | ||
772 | .owner = THIS_MODULE, | ||
773 | }, | ||
774 | .probe = tps80031_regulator_probe, | ||
775 | .remove = __devexit_p(tps80031_regulator_remove), | ||
776 | }; | ||
777 | |||
778 | static int __init tps80031_regulator_init(void) | ||
779 | { | ||
780 | return platform_driver_register(&tps80031_regulator_driver); | ||
781 | } | ||
782 | subsys_initcall(tps80031_regulator_init); | ||
783 | |||
784 | static void __exit tps80031_regulator_exit(void) | ||
785 | { | ||
786 | platform_driver_unregister(&tps80031_regulator_driver); | ||
787 | } | ||
788 | module_exit(tps80031_regulator_exit); | ||
789 | |||
790 | MODULE_ALIAS("platform:tps80031-regulator"); | ||
791 | MODULE_DESCRIPTION("Regulator Driver for TI TPS80031 PMIC"); | ||
792 | MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>"); | ||
793 | MODULE_LICENSE("GPL v2"); | ||
diff --git a/drivers/regulator/vexpress.c b/drivers/regulator/vexpress.c new file mode 100644 index 000000000000..1d558111d60f --- /dev/null +++ b/drivers/regulator/vexpress.c | |||
@@ -0,0 +1,147 @@ | |||
1 | /* | ||
2 | * This program is free software; you can redistribute it and/or modify | ||
3 | * it under the terms of the GNU General Public License version 2 as | ||
4 | * published by the Free Software Foundation. | ||
5 | * | ||
6 | * This program is distributed in the hope that it will be useful, | ||
7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
9 | * GNU General Public License for more details. | ||
10 | * | ||
11 | * Copyright (C) 2012 ARM Limited | ||
12 | */ | ||
13 | |||
14 | #define DRVNAME "vexpress-regulator" | ||
15 | #define pr_fmt(fmt) DRVNAME ": " fmt | ||
16 | |||
17 | #include <linux/device.h> | ||
18 | #include <linux/err.h> | ||
19 | #include <linux/module.h> | ||
20 | #include <linux/of_device.h> | ||
21 | #include <linux/regulator/driver.h> | ||
22 | #include <linux/regulator/machine.h> | ||
23 | #include <linux/regulator/of_regulator.h> | ||
24 | #include <linux/vexpress.h> | ||
25 | |||
26 | struct vexpress_regulator { | ||
27 | struct regulator_desc desc; | ||
28 | struct regulator_dev *regdev; | ||
29 | struct vexpress_config_func *func; | ||
30 | }; | ||
31 | |||
32 | static int vexpress_regulator_get_voltage(struct regulator_dev *regdev) | ||
33 | { | ||
34 | struct vexpress_regulator *reg = rdev_get_drvdata(regdev); | ||
35 | u32 uV; | ||
36 | int err = vexpress_config_read(reg->func, 0, &uV); | ||
37 | |||
38 | return err ? err : uV; | ||
39 | } | ||
40 | |||
41 | static int vexpress_regulator_set_voltage(struct regulator_dev *regdev, | ||
42 | int min_uV, int max_uV, unsigned *selector) | ||
43 | { | ||
44 | struct vexpress_regulator *reg = rdev_get_drvdata(regdev); | ||
45 | |||
46 | return vexpress_config_write(reg->func, 0, min_uV); | ||
47 | } | ||
48 | |||
49 | static struct regulator_ops vexpress_regulator_ops_ro = { | ||
50 | .get_voltage = vexpress_regulator_get_voltage, | ||
51 | }; | ||
52 | |||
53 | static struct regulator_ops vexpress_regulator_ops = { | ||
54 | .get_voltage = vexpress_regulator_get_voltage, | ||
55 | .set_voltage = vexpress_regulator_set_voltage, | ||
56 | }; | ||
57 | |||
58 | static int vexpress_regulator_probe(struct platform_device *pdev) | ||
59 | { | ||
60 | int err; | ||
61 | struct vexpress_regulator *reg; | ||
62 | struct regulator_init_data *init_data; | ||
63 | struct regulator_config config = { }; | ||
64 | |||
65 | reg = devm_kzalloc(&pdev->dev, sizeof(*reg), GFP_KERNEL); | ||
66 | if (!reg) { | ||
67 | err = -ENOMEM; | ||
68 | goto error_kzalloc; | ||
69 | } | ||
70 | |||
71 | reg->func = vexpress_config_func_get_by_dev(&pdev->dev); | ||
72 | if (!reg->func) { | ||
73 | err = -ENXIO; | ||
74 | goto error_get_func; | ||
75 | } | ||
76 | |||
77 | reg->desc.name = dev_name(&pdev->dev); | ||
78 | reg->desc.type = REGULATOR_VOLTAGE; | ||
79 | reg->desc.owner = THIS_MODULE; | ||
80 | reg->desc.continuous_voltage_range = true; | ||
81 | |||
82 | init_data = of_get_regulator_init_data(&pdev->dev, pdev->dev.of_node); | ||
83 | if (!init_data) { | ||
84 | err = -EINVAL; | ||
85 | goto error_get_regulator_init_data; | ||
86 | } | ||
87 | |||
88 | init_data->constraints.apply_uV = 0; | ||
89 | if (init_data->constraints.min_uV && init_data->constraints.max_uV) | ||
90 | reg->desc.ops = &vexpress_regulator_ops; | ||
91 | else | ||
92 | reg->desc.ops = &vexpress_regulator_ops_ro; | ||
93 | |||
94 | config.dev = &pdev->dev; | ||
95 | config.init_data = init_data; | ||
96 | config.driver_data = reg; | ||
97 | config.of_node = pdev->dev.of_node; | ||
98 | |||
99 | reg->regdev = regulator_register(®->desc, &config); | ||
100 | if (IS_ERR(reg->regdev)) { | ||
101 | err = PTR_ERR(reg->regdev); | ||
102 | goto error_regulator_register; | ||
103 | } | ||
104 | |||
105 | platform_set_drvdata(pdev, reg); | ||
106 | |||
107 | return 0; | ||
108 | |||
109 | error_regulator_register: | ||
110 | error_get_regulator_init_data: | ||
111 | vexpress_config_func_put(reg->func); | ||
112 | error_get_func: | ||
113 | error_kzalloc: | ||
114 | return err; | ||
115 | } | ||
116 | |||
117 | static int __devexit vexpress_regulator_remove(struct platform_device *pdev) | ||
118 | { | ||
119 | struct vexpress_regulator *reg = platform_get_drvdata(pdev); | ||
120 | |||
121 | vexpress_config_func_put(reg->func); | ||
122 | regulator_unregister(reg->regdev); | ||
123 | |||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | static struct of_device_id vexpress_regulator_of_match[] = { | ||
128 | { .compatible = "arm,vexpress-volt", }, | ||
129 | { } | ||
130 | }; | ||
131 | |||
132 | static struct platform_driver vexpress_regulator_driver = { | ||
133 | .probe = vexpress_regulator_probe, | ||
134 | .remove = __devexit_p(vexpress_regulator_remove), | ||
135 | .driver = { | ||
136 | .name = DRVNAME, | ||
137 | .owner = THIS_MODULE, | ||
138 | .of_match_table = vexpress_regulator_of_match, | ||
139 | }, | ||
140 | }; | ||
141 | |||
142 | module_platform_driver(vexpress_regulator_driver); | ||
143 | |||
144 | MODULE_AUTHOR("Pawel Moll <pawel.moll@arm.com>"); | ||
145 | MODULE_DESCRIPTION("Versatile Express regulator"); | ||
146 | MODULE_LICENSE("GPL"); | ||
147 | MODULE_ALIAS("platform:vexpress-regulator"); | ||