diff options
28 files changed, 1622 insertions, 184 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 262f62eec837..834b48441829 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
| @@ -27,6 +27,17 @@ config REGULATOR_DEBUG | |||
| 27 | help | 27 | help |
| 28 | Say yes here to enable debugging support. | 28 | Say yes here to enable debugging support. |
| 29 | 29 | ||
| 30 | config REGULATOR_DUMMY | ||
| 31 | bool "Provide a dummy regulator if regulator lookups fail" | ||
| 32 | help | ||
| 33 | If this option is enabled then when a regulator lookup fails | ||
| 34 | and the board has not specified that it has provided full | ||
| 35 | constraints then the regulator core will provide an always | ||
| 36 | enabled dummy regulator will be provided, allowing consumer | ||
| 37 | drivers to continue. | ||
| 38 | |||
| 39 | A warning will be generated when this substitution is done. | ||
| 40 | |||
| 30 | config REGULATOR_FIXED_VOLTAGE | 41 | config REGULATOR_FIXED_VOLTAGE |
| 31 | tristate "Fixed voltage regulator support" | 42 | tristate "Fixed voltage regulator support" |
| 32 | help | 43 | help |
| @@ -69,6 +80,13 @@ config REGULATOR_MAX1586 | |||
| 69 | regulator via I2C bus. The provided regulator is suitable | 80 | regulator via I2C bus. The provided regulator is suitable |
| 70 | for PXA27x chips to control VCC_CORE and VCC_USIM voltages. | 81 | for PXA27x chips to control VCC_CORE and VCC_USIM voltages. |
| 71 | 82 | ||
| 83 | config REGULATOR_MAX8649 | ||
| 84 | tristate "Maxim 8649 voltage regulator" | ||
| 85 | depends on I2C | ||
| 86 | help | ||
| 87 | This driver controls a Maxim 8649 voltage output regulator via | ||
| 88 | I2C bus. | ||
| 89 | |||
| 72 | config REGULATOR_MAX8660 | 90 | config REGULATOR_MAX8660 |
| 73 | tristate "Maxim 8660/8661 voltage regulator" | 91 | tristate "Maxim 8660/8661 voltage regulator" |
| 74 | depends on I2C | 92 | depends on I2C |
| @@ -91,19 +109,26 @@ config REGULATOR_WM831X | |||
| 91 | of PMIC devices. | 109 | of PMIC devices. |
| 92 | 110 | ||
| 93 | config REGULATOR_WM8350 | 111 | config REGULATOR_WM8350 |
| 94 | tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC" | 112 | tristate "Wolfson Microelectronics WM8350 AudioPlus PMIC" |
| 95 | depends on MFD_WM8350 | 113 | depends on MFD_WM8350 |
| 96 | help | 114 | help |
| 97 | This driver provides support for the voltage and current regulators | 115 | This driver provides support for the voltage and current regulators |
| 98 | of the WM8350 AudioPlus PMIC. | 116 | of the WM8350 AudioPlus PMIC. |
| 99 | 117 | ||
| 100 | config REGULATOR_WM8400 | 118 | config REGULATOR_WM8400 |
| 101 | tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC" | 119 | tristate "Wolfson Microelectronics WM8400 AudioPlus PMIC" |
| 102 | depends on MFD_WM8400 | 120 | depends on MFD_WM8400 |
| 103 | help | 121 | help |
| 104 | This driver provides support for the voltage regulators of the | 122 | This driver provides support for the voltage regulators of the |
| 105 | WM8400 AudioPlus PMIC. | 123 | WM8400 AudioPlus PMIC. |
| 106 | 124 | ||
| 125 | config REGULATOR_WM8994 | ||
| 126 | tristate "Wolfson Microelectronics WM8994 CODEC" | ||
| 127 | depends on MFD_WM8994 | ||
| 128 | help | ||
| 129 | This driver provides support for the voltage regulators on the | ||
| 130 | WM8994 CODEC. | ||
| 131 | |||
| 107 | config REGULATOR_DA903X | 132 | config REGULATOR_DA903X |
| 108 | tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" | 133 | tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC" |
| 109 | depends on PMIC_DA903X | 134 | depends on PMIC_DA903X |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index b3c806c79415..e845b66ad59c 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
| @@ -9,15 +9,18 @@ obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o | |||
| 9 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o | 9 | obj-$(CONFIG_REGULATOR_USERSPACE_CONSUMER) += userspace-consumer.o |
| 10 | 10 | ||
| 11 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o | 11 | obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o |
| 12 | obj-$(CONFIG_REGULATOR_DUMMY) += dummy.o | ||
| 12 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o | 13 | obj-$(CONFIG_REGULATOR_LP3971) += lp3971.o |
| 13 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o | 14 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o |
| 14 | obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o | 15 | obj-$(CONFIG_REGULATOR_TWL4030) += twl-regulator.o |
| 16 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o | ||
| 15 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o | 17 | obj-$(CONFIG_REGULATOR_MAX8660) += max8660.o |
| 16 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o | 18 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-dcdc.o |
| 17 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o | 19 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-isink.o |
| 18 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o | 20 | obj-$(CONFIG_REGULATOR_WM831X) += wm831x-ldo.o |
| 19 | obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o | 21 | obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o |
| 20 | obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o | 22 | obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o |
| 23 | obj-$(CONFIG_REGULATOR_WM8994) += wm8994-regulator.o | ||
| 21 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o | 24 | obj-$(CONFIG_REGULATOR_DA903X) += da903x.o |
| 22 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o | 25 | obj-$(CONFIG_REGULATOR_PCF50633) += pcf50633-regulator.o |
| 23 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o | 26 | obj-$(CONFIG_REGULATOR_PCAP) += pcap-regulator.o |
diff --git a/drivers/regulator/ab3100.c b/drivers/regulator/ab3100.c index b349db4504b7..7de950959ed2 100644 --- a/drivers/regulator/ab3100.c +++ b/drivers/regulator/ab3100.c | |||
| @@ -561,7 +561,7 @@ ab3100_regulator_desc[AB3100_NUM_REGULATORS] = { | |||
| 561 | * for all the different regulators. | 561 | * for all the different regulators. |
| 562 | */ | 562 | */ |
| 563 | 563 | ||
| 564 | static int __init ab3100_regulators_probe(struct platform_device *pdev) | 564 | static int __devinit ab3100_regulators_probe(struct platform_device *pdev) |
| 565 | { | 565 | { |
| 566 | struct ab3100_platform_data *plfdata = pdev->dev.platform_data; | 566 | struct ab3100_platform_data *plfdata = pdev->dev.platform_data; |
| 567 | struct ab3100 *ab3100 = platform_get_drvdata(pdev); | 567 | struct ab3100 *ab3100 = platform_get_drvdata(pdev); |
| @@ -641,7 +641,7 @@ static int __init ab3100_regulators_probe(struct platform_device *pdev) | |||
| 641 | return 0; | 641 | return 0; |
| 642 | } | 642 | } |
| 643 | 643 | ||
| 644 | static int __exit ab3100_regulators_remove(struct platform_device *pdev) | 644 | static int __devexit ab3100_regulators_remove(struct platform_device *pdev) |
| 645 | { | 645 | { |
| 646 | int i; | 646 | int i; |
| 647 | 647 | ||
| @@ -659,7 +659,7 @@ static struct platform_driver ab3100_regulators_driver = { | |||
| 659 | .owner = THIS_MODULE, | 659 | .owner = THIS_MODULE, |
| 660 | }, | 660 | }, |
| 661 | .probe = ab3100_regulators_probe, | 661 | .probe = ab3100_regulators_probe, |
| 662 | .remove = __exit_p(ab3100_regulators_remove), | 662 | .remove = __devexit_p(ab3100_regulators_remove), |
| 663 | }; | 663 | }; |
| 664 | 664 | ||
| 665 | static __init int ab3100_regulators_init(void) | 665 | static __init int ab3100_regulators_init(void) |
diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c index b60a4c9f8f16..c7bbe30010f7 100644 --- a/drivers/regulator/core.c +++ b/drivers/regulator/core.c | |||
| @@ -19,10 +19,13 @@ | |||
| 19 | #include <linux/err.h> | 19 | #include <linux/err.h> |
| 20 | #include <linux/mutex.h> | 20 | #include <linux/mutex.h> |
| 21 | #include <linux/suspend.h> | 21 | #include <linux/suspend.h> |
| 22 | #include <linux/delay.h> | ||
| 22 | #include <linux/regulator/consumer.h> | 23 | #include <linux/regulator/consumer.h> |
| 23 | #include <linux/regulator/driver.h> | 24 | #include <linux/regulator/driver.h> |
| 24 | #include <linux/regulator/machine.h> | 25 | #include <linux/regulator/machine.h> |
| 25 | 26 | ||
| 27 | #include "dummy.h" | ||
| 28 | |||
| 26 | #define REGULATOR_VERSION "0.5" | 29 | #define REGULATOR_VERSION "0.5" |
| 27 | 30 | ||
| 28 | static DEFINE_MUTEX(regulator_list_mutex); | 31 | static DEFINE_MUTEX(regulator_list_mutex); |
| @@ -1084,6 +1087,13 @@ overflow_err: | |||
| 1084 | return NULL; | 1087 | return NULL; |
| 1085 | } | 1088 | } |
| 1086 | 1089 | ||
| 1090 | static int _regulator_get_enable_time(struct regulator_dev *rdev) | ||
| 1091 | { | ||
| 1092 | if (!rdev->desc->ops->enable_time) | ||
| 1093 | return 0; | ||
| 1094 | return rdev->desc->ops->enable_time(rdev); | ||
| 1095 | } | ||
| 1096 | |||
| 1087 | /* Internal regulator request function */ | 1097 | /* Internal regulator request function */ |
| 1088 | static struct regulator *_regulator_get(struct device *dev, const char *id, | 1098 | static struct regulator *_regulator_get(struct device *dev, const char *id, |
| 1089 | int exclusive) | 1099 | int exclusive) |
| @@ -1115,6 +1125,22 @@ static struct regulator *_regulator_get(struct device *dev, const char *id, | |||
| 1115 | goto found; | 1125 | goto found; |
| 1116 | } | 1126 | } |
| 1117 | } | 1127 | } |
| 1128 | |||
| 1129 | #ifdef CONFIG_REGULATOR_DUMMY | ||
| 1130 | if (!devname) | ||
| 1131 | devname = "deviceless"; | ||
| 1132 | |||
| 1133 | /* If the board didn't flag that it was fully constrained then | ||
| 1134 | * substitute in a dummy regulator so consumers can continue. | ||
| 1135 | */ | ||
| 1136 | if (!has_full_constraints) { | ||
| 1137 | pr_warning("%s supply %s not found, using dummy regulator\n", | ||
| 1138 | devname, id); | ||
| 1139 | rdev = dummy_regulator_rdev; | ||
| 1140 | goto found; | ||
| 1141 | } | ||
| 1142 | #endif | ||
| 1143 | |||
| 1118 | mutex_unlock(®ulator_list_mutex); | 1144 | mutex_unlock(®ulator_list_mutex); |
| 1119 | return regulator; | 1145 | return regulator; |
| 1120 | 1146 | ||
| @@ -1251,7 +1277,7 @@ static int _regulator_can_change_status(struct regulator_dev *rdev) | |||
| 1251 | /* locks held by regulator_enable() */ | 1277 | /* locks held by regulator_enable() */ |
| 1252 | static int _regulator_enable(struct regulator_dev *rdev) | 1278 | static int _regulator_enable(struct regulator_dev *rdev) |
| 1253 | { | 1279 | { |
| 1254 | int ret; | 1280 | int ret, delay; |
| 1255 | 1281 | ||
| 1256 | /* do we need to enable the supply regulator first */ | 1282 | /* do we need to enable the supply regulator first */ |
| 1257 | if (rdev->supply) { | 1283 | if (rdev->supply) { |
| @@ -1275,13 +1301,34 @@ static int _regulator_enable(struct regulator_dev *rdev) | |||
| 1275 | if (!_regulator_can_change_status(rdev)) | 1301 | if (!_regulator_can_change_status(rdev)) |
| 1276 | return -EPERM; | 1302 | return -EPERM; |
| 1277 | 1303 | ||
| 1278 | if (rdev->desc->ops->enable) { | 1304 | if (!rdev->desc->ops->enable) |
| 1279 | ret = rdev->desc->ops->enable(rdev); | ||
| 1280 | if (ret < 0) | ||
| 1281 | return ret; | ||
| 1282 | } else { | ||
| 1283 | return -EINVAL; | 1305 | return -EINVAL; |
| 1306 | |||
| 1307 | /* Query before enabling in case configuration | ||
| 1308 | * dependant. */ | ||
| 1309 | ret = _regulator_get_enable_time(rdev); | ||
| 1310 | if (ret >= 0) { | ||
| 1311 | delay = ret; | ||
| 1312 | } else { | ||
| 1313 | printk(KERN_WARNING | ||
| 1314 | "%s: enable_time() failed for %s: %d\n", | ||
| 1315 | __func__, rdev_get_name(rdev), | ||
| 1316 | ret); | ||
| 1317 | delay = 0; | ||
| 1284 | } | 1318 | } |
| 1319 | |||
| 1320 | /* Allow the regulator to ramp; it would be useful | ||
| 1321 | * to extend this for bulk operations so that the | ||
| 1322 | * regulators can ramp together. */ | ||
| 1323 | ret = rdev->desc->ops->enable(rdev); | ||
| 1324 | if (ret < 0) | ||
| 1325 | return ret; | ||
| 1326 | |||
| 1327 | if (delay >= 1000) | ||
| 1328 | mdelay(delay / 1000); | ||
| 1329 | else if (delay) | ||
| 1330 | udelay(delay); | ||
| 1331 | |||
| 1285 | } else if (ret < 0) { | 1332 | } else if (ret < 0) { |
| 1286 | printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", | 1333 | printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", |
| 1287 | __func__, rdev_get_name(rdev), ret); | 1334 | __func__, rdev_get_name(rdev), ret); |
| @@ -1341,6 +1388,9 @@ static int _regulator_disable(struct regulator_dev *rdev) | |||
| 1341 | __func__, rdev_get_name(rdev)); | 1388 | __func__, rdev_get_name(rdev)); |
| 1342 | return ret; | 1389 | return ret; |
| 1343 | } | 1390 | } |
| 1391 | |||
| 1392 | _notifier_call_chain(rdev, REGULATOR_EVENT_DISABLE, | ||
| 1393 | NULL); | ||
| 1344 | } | 1394 | } |
| 1345 | 1395 | ||
| 1346 | /* decrease our supplies ref count and disable if required */ | 1396 | /* decrease our supplies ref count and disable if required */ |
| @@ -1399,8 +1449,8 @@ static int _regulator_force_disable(struct regulator_dev *rdev) | |||
| 1399 | return ret; | 1449 | return ret; |
| 1400 | } | 1450 | } |
| 1401 | /* notify other consumers that power has been forced off */ | 1451 | /* notify other consumers that power has been forced off */ |
| 1402 | _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE, | 1452 | _notifier_call_chain(rdev, REGULATOR_EVENT_FORCE_DISABLE | |
| 1403 | NULL); | 1453 | REGULATOR_EVENT_DISABLE, NULL); |
| 1404 | } | 1454 | } |
| 1405 | 1455 | ||
| 1406 | /* decrease our supplies ref count and disable if required */ | 1456 | /* decrease our supplies ref count and disable if required */ |
| @@ -1434,9 +1484,9 @@ EXPORT_SYMBOL_GPL(regulator_force_disable); | |||
| 1434 | 1484 | ||
| 1435 | static int _regulator_is_enabled(struct regulator_dev *rdev) | 1485 | static int _regulator_is_enabled(struct regulator_dev *rdev) |
| 1436 | { | 1486 | { |
| 1437 | /* sanity check */ | 1487 | /* If we don't know then assume that the regulator is always on */ |
| 1438 | if (!rdev->desc->ops->is_enabled) | 1488 | if (!rdev->desc->ops->is_enabled) |
| 1439 | return -EINVAL; | 1489 | return 1; |
| 1440 | 1490 | ||
| 1441 | return rdev->desc->ops->is_enabled(rdev); | 1491 | return rdev->desc->ops->is_enabled(rdev); |
| 1442 | } | 1492 | } |
| @@ -2451,8 +2501,15 @@ EXPORT_SYMBOL_GPL(regulator_get_init_drvdata); | |||
| 2451 | 2501 | ||
| 2452 | static int __init regulator_init(void) | 2502 | static int __init regulator_init(void) |
| 2453 | { | 2503 | { |
| 2504 | int ret; | ||
| 2505 | |||
| 2454 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); | 2506 | printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION); |
| 2455 | return class_register(®ulator_class); | 2507 | |
| 2508 | ret = class_register(®ulator_class); | ||
| 2509 | |||
| 2510 | regulator_dummy_init(); | ||
| 2511 | |||
| 2512 | return ret; | ||
| 2456 | } | 2513 | } |
| 2457 | 2514 | ||
| 2458 | /* init early to allow our consumers to complete system booting */ | 2515 | /* init early to allow our consumers to complete system booting */ |
diff --git a/drivers/regulator/dummy.c b/drivers/regulator/dummy.c new file mode 100644 index 000000000000..c7410bde7b5d --- /dev/null +++ b/drivers/regulator/dummy.c | |||
| @@ -0,0 +1,66 @@ | |||
| 1 | /* | ||
| 2 | * dummy.c | ||
| 3 | * | ||
| 4 | * Copyright 2010 Wolfson Microelectronics PLC. | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation; either version 2 of the | ||
| 11 | * License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This is useful for systems with mixed controllable and | ||
| 14 | * non-controllable regulators, as well as for allowing testing on | ||
| 15 | * systems with no controllable regulators. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <linux/err.h> | ||
| 19 | #include <linux/platform_device.h> | ||
| 20 | #include <linux/regulator/driver.h> | ||
| 21 | #include <linux/regulator/machine.h> | ||
| 22 | |||
| 23 | #include "dummy.h" | ||
| 24 | |||
| 25 | struct regulator_dev *dummy_regulator_rdev; | ||
| 26 | |||
| 27 | static struct regulator_init_data dummy_initdata; | ||
| 28 | |||
| 29 | static struct regulator_ops dummy_ops; | ||
| 30 | |||
| 31 | static struct regulator_desc dummy_desc = { | ||
| 32 | .name = "dummy", | ||
| 33 | .id = -1, | ||
| 34 | .type = REGULATOR_VOLTAGE, | ||
| 35 | .owner = THIS_MODULE, | ||
| 36 | .ops = &dummy_ops, | ||
| 37 | }; | ||
| 38 | |||
| 39 | static struct platform_device *dummy_pdev; | ||
| 40 | |||
| 41 | void __init regulator_dummy_init(void) | ||
| 42 | { | ||
| 43 | int ret; | ||
| 44 | |||
| 45 | dummy_pdev = platform_device_alloc("reg-dummy", -1); | ||
| 46 | if (!dummy_pdev) { | ||
| 47 | pr_err("Failed to allocate dummy regulator device\n"); | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | |||
| 51 | ret = platform_device_add(dummy_pdev); | ||
| 52 | if (ret != 0) { | ||
| 53 | pr_err("Failed to register dummy regulator device: %d\n", ret); | ||
| 54 | platform_device_put(dummy_pdev); | ||
| 55 | return; | ||
| 56 | } | ||
| 57 | |||
| 58 | dummy_regulator_rdev = regulator_register(&dummy_desc, NULL, | ||
| 59 | &dummy_initdata, NULL); | ||
| 60 | if (IS_ERR(dummy_regulator_rdev)) { | ||
| 61 | ret = PTR_ERR(dummy_regulator_rdev); | ||
| 62 | pr_err("Failed to register regulator: %d\n", ret); | ||
| 63 | platform_device_unregister(dummy_pdev); | ||
| 64 | return; | ||
| 65 | } | ||
| 66 | } | ||
diff --git a/drivers/regulator/dummy.h b/drivers/regulator/dummy.h new file mode 100644 index 000000000000..3921c0e24249 --- /dev/null +++ b/drivers/regulator/dummy.h | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | /* | ||
| 2 | * dummy.h | ||
| 3 | * | ||
| 4 | * Copyright 2010 Wolfson Microelectronics PLC. | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or | ||
| 9 | * modify it under the terms of the GNU General Public License as | ||
| 10 | * published by the Free Software Foundation; either version 2 of the | ||
| 11 | * License, or (at your option) any later version. | ||
| 12 | * | ||
| 13 | * This is useful for systems with mixed controllable and | ||
| 14 | * non-controllable regulators, as well as for allowing testing on | ||
| 15 | * systems with no controllable regulators. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #ifndef _DUMMY_H | ||
| 19 | #define _DUMMY_H | ||
| 20 | |||
| 21 | struct regulator_dev; | ||
| 22 | |||
| 23 | extern struct regulator_dev *dummy_regulator_rdev; | ||
| 24 | |||
| 25 | #ifdef CONFIG_REGULATOR_DUMMY | ||
| 26 | void __init regulator_dummy_init(void); | ||
| 27 | #else | ||
| 28 | static inline void regulator_dummy_init(void) { } | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #endif | ||
diff --git a/drivers/regulator/fixed.c b/drivers/regulator/fixed.c index f9f516a3028a..d11f7622430b 100644 --- a/drivers/regulator/fixed.c +++ b/drivers/regulator/fixed.c | |||
| @@ -24,14 +24,16 @@ | |||
| 24 | #include <linux/regulator/driver.h> | 24 | #include <linux/regulator/driver.h> |
| 25 | #include <linux/regulator/fixed.h> | 25 | #include <linux/regulator/fixed.h> |
| 26 | #include <linux/gpio.h> | 26 | #include <linux/gpio.h> |
| 27 | #include <linux/delay.h> | ||
| 27 | 28 | ||
| 28 | struct fixed_voltage_data { | 29 | struct fixed_voltage_data { |
| 29 | struct regulator_desc desc; | 30 | struct regulator_desc desc; |
| 30 | struct regulator_dev *dev; | 31 | struct regulator_dev *dev; |
| 31 | int microvolts; | 32 | int microvolts; |
| 32 | int gpio; | 33 | int gpio; |
| 33 | unsigned enable_high:1; | 34 | unsigned startup_delay; |
| 34 | unsigned is_enabled:1; | 35 | bool enable_high; |
| 36 | bool is_enabled; | ||
| 35 | }; | 37 | }; |
| 36 | 38 | ||
| 37 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) | 39 | static int fixed_voltage_is_enabled(struct regulator_dev *dev) |
| @@ -47,7 +49,7 @@ static int fixed_voltage_enable(struct regulator_dev *dev) | |||
| 47 | 49 | ||
| 48 | if (gpio_is_valid(data->gpio)) { | 50 | if (gpio_is_valid(data->gpio)) { |
| 49 | gpio_set_value_cansleep(data->gpio, data->enable_high); | 51 | gpio_set_value_cansleep(data->gpio, data->enable_high); |
| 50 | data->is_enabled = 1; | 52 | data->is_enabled = true; |
| 51 | } | 53 | } |
| 52 | 54 | ||
| 53 | return 0; | 55 | return 0; |
| @@ -59,12 +61,19 @@ static int fixed_voltage_disable(struct regulator_dev *dev) | |||
| 59 | 61 | ||
| 60 | if (gpio_is_valid(data->gpio)) { | 62 | if (gpio_is_valid(data->gpio)) { |
| 61 | gpio_set_value_cansleep(data->gpio, !data->enable_high); | 63 | gpio_set_value_cansleep(data->gpio, !data->enable_high); |
| 62 | data->is_enabled = 0; | 64 | data->is_enabled = false; |
| 63 | } | 65 | } |
| 64 | 66 | ||
| 65 | return 0; | 67 | return 0; |
| 66 | } | 68 | } |
| 67 | 69 | ||
| 70 | static int fixed_voltage_enable_time(struct regulator_dev *dev) | ||
| 71 | { | ||
| 72 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | ||
| 73 | |||
| 74 | return data->startup_delay; | ||
| 75 | } | ||
| 76 | |||
| 68 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) | 77 | static int fixed_voltage_get_voltage(struct regulator_dev *dev) |
| 69 | { | 78 | { |
| 70 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); | 79 | struct fixed_voltage_data *data = rdev_get_drvdata(dev); |
| @@ -87,11 +96,12 @@ static struct regulator_ops fixed_voltage_ops = { | |||
| 87 | .is_enabled = fixed_voltage_is_enabled, | 96 | .is_enabled = fixed_voltage_is_enabled, |
| 88 | .enable = fixed_voltage_enable, | 97 | .enable = fixed_voltage_enable, |
| 89 | .disable = fixed_voltage_disable, | 98 | .disable = fixed_voltage_disable, |
| 99 | .enable_time = fixed_voltage_enable_time, | ||
| 90 | .get_voltage = fixed_voltage_get_voltage, | 100 | .get_voltage = fixed_voltage_get_voltage, |
| 91 | .list_voltage = fixed_voltage_list_voltage, | 101 | .list_voltage = fixed_voltage_list_voltage, |
| 92 | }; | 102 | }; |
| 93 | 103 | ||
| 94 | static int regulator_fixed_voltage_probe(struct platform_device *pdev) | 104 | static int __devinit reg_fixed_voltage_probe(struct platform_device *pdev) |
| 95 | { | 105 | { |
| 96 | struct fixed_voltage_config *config = pdev->dev.platform_data; | 106 | struct fixed_voltage_config *config = pdev->dev.platform_data; |
| 97 | struct fixed_voltage_data *drvdata; | 107 | struct fixed_voltage_data *drvdata; |
| @@ -117,6 +127,7 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev) | |||
| 117 | 127 | ||
| 118 | drvdata->microvolts = config->microvolts; | 128 | drvdata->microvolts = config->microvolts; |
| 119 | drvdata->gpio = config->gpio; | 129 | drvdata->gpio = config->gpio; |
| 130 | drvdata->startup_delay = config->startup_delay; | ||
| 120 | 131 | ||
| 121 | if (gpio_is_valid(config->gpio)) { | 132 | if (gpio_is_valid(config->gpio)) { |
| 122 | drvdata->enable_high = config->enable_high; | 133 | drvdata->enable_high = config->enable_high; |
| @@ -163,7 +174,7 @@ static int regulator_fixed_voltage_probe(struct platform_device *pdev) | |||
| 163 | /* Regulator without GPIO control is considered | 174 | /* Regulator without GPIO control is considered |
| 164 | * always enabled | 175 | * always enabled |
| 165 | */ | 176 | */ |
| 166 | drvdata->is_enabled = 1; | 177 | drvdata->is_enabled = true; |
| 167 | } | 178 | } |
| 168 | 179 | ||
| 169 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, | 180 | drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, |
| @@ -191,7 +202,7 @@ err: | |||
| 191 | return ret; | 202 | return ret; |
| 192 | } | 203 | } |
| 193 | 204 | ||
| 194 | static int regulator_fixed_voltage_remove(struct platform_device *pdev) | 205 | static int __devexit reg_fixed_voltage_remove(struct platform_device *pdev) |
| 195 | { | 206 | { |
| 196 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); | 207 | struct fixed_voltage_data *drvdata = platform_get_drvdata(pdev); |
| 197 | 208 | ||
| @@ -205,10 +216,11 @@ static int regulator_fixed_voltage_remove(struct platform_device *pdev) | |||
| 205 | } | 216 | } |
| 206 | 217 | ||
| 207 | static struct platform_driver regulator_fixed_voltage_driver = { | 218 | static struct platform_driver regulator_fixed_voltage_driver = { |
| 208 | .probe = regulator_fixed_voltage_probe, | 219 | .probe = reg_fixed_voltage_probe, |
| 209 | .remove = regulator_fixed_voltage_remove, | 220 | .remove = __devexit_p(reg_fixed_voltage_remove), |
| 210 | .driver = { | 221 | .driver = { |
| 211 | .name = "reg-fixed-voltage", | 222 | .name = "reg-fixed-voltage", |
| 223 | .owner = THIS_MODULE, | ||
| 212 | }, | 224 | }, |
| 213 | }; | 225 | }; |
| 214 | 226 | ||
diff --git a/drivers/regulator/lp3971.c b/drivers/regulator/lp3971.c index 4f33a0f4a179..f5532ed79272 100644 --- a/drivers/regulator/lp3971.c +++ b/drivers/regulator/lp3971.c | |||
| @@ -54,7 +54,7 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val); | |||
| 54 | #define LP3971_BUCK2_BASE 0x29 | 54 | #define LP3971_BUCK2_BASE 0x29 |
| 55 | #define LP3971_BUCK3_BASE 0x32 | 55 | #define LP3971_BUCK3_BASE 0x32 |
| 56 | 56 | ||
| 57 | const static int buck_base_addr[] = { | 57 | static const int buck_base_addr[] = { |
| 58 | LP3971_BUCK1_BASE, | 58 | LP3971_BUCK1_BASE, |
| 59 | LP3971_BUCK2_BASE, | 59 | LP3971_BUCK2_BASE, |
| 60 | LP3971_BUCK3_BASE, | 60 | LP3971_BUCK3_BASE, |
| @@ -63,7 +63,7 @@ const static int buck_base_addr[] = { | |||
| 63 | #define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) | 63 | #define LP3971_BUCK_TARGET_VOL1_REG(x) (buck_base_addr[x]) |
| 64 | #define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) | 64 | #define LP3971_BUCK_TARGET_VOL2_REG(x) (buck_base_addr[x]+1) |
| 65 | 65 | ||
| 66 | const static int buck_voltage_map[] = { | 66 | static const int buck_voltage_map[] = { |
| 67 | 0, 800, 850, 900, 950, 1000, 1050, 1100, | 67 | 0, 800, 850, 900, 950, 1000, 1050, 1100, |
| 68 | 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, | 68 | 1150, 1200, 1250, 1300, 1350, 1400, 1450, 1500, |
| 69 | 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, | 69 | 1550, 1600, 1650, 1700, 1800, 1900, 2500, 2800, |
| @@ -96,17 +96,17 @@ const static int buck_voltage_map[] = { | |||
| 96 | #define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) | 96 | #define LDO_VOL_CONTR_SHIFT(x) ((x & 1) << 2) |
| 97 | #define LDO_VOL_CONTR_MASK 0x0f | 97 | #define LDO_VOL_CONTR_MASK 0x0f |
| 98 | 98 | ||
| 99 | const static int ldo45_voltage_map[] = { | 99 | static const int ldo45_voltage_map[] = { |
| 100 | 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, | 100 | 1000, 1050, 1100, 1150, 1200, 1250, 1300, 1350, |
| 101 | 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, | 101 | 1400, 1500, 1800, 1900, 2500, 2800, 3000, 3300, |
| 102 | }; | 102 | }; |
| 103 | 103 | ||
| 104 | const static int ldo123_voltage_map[] = { | 104 | static const int ldo123_voltage_map[] = { |
| 105 | 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, | 105 | 1800, 1900, 2000, 2100, 2200, 2300, 2400, 2500, |
| 106 | 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, | 106 | 2600, 2700, 2800, 2900, 3000, 3100, 3200, 3300, |
| 107 | }; | 107 | }; |
| 108 | 108 | ||
| 109 | const static int *ldo_voltage_map[] = { | 109 | static const int *ldo_voltage_map[] = { |
| 110 | ldo123_voltage_map, /* LDO1 */ | 110 | ldo123_voltage_map, /* LDO1 */ |
| 111 | ldo123_voltage_map, /* LDO2 */ | 111 | ldo123_voltage_map, /* LDO2 */ |
| 112 | ldo123_voltage_map, /* LDO3 */ | 112 | ldo123_voltage_map, /* LDO3 */ |
| @@ -431,20 +431,20 @@ static int lp3971_set_bits(struct lp3971 *lp3971, u8 reg, u16 mask, u16 val) | |||
| 431 | return ret; | 431 | return ret; |
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | static int setup_regulators(struct lp3971 *lp3971, | 434 | static int __devinit setup_regulators(struct lp3971 *lp3971, |
| 435 | struct lp3971_platform_data *pdata) | 435 | struct lp3971_platform_data *pdata) |
| 436 | { | 436 | { |
| 437 | int i, err; | 437 | int i, err; |
| 438 | int num_regulators = pdata->num_regulators; | 438 | |
| 439 | lp3971->num_regulators = num_regulators; | 439 | lp3971->num_regulators = pdata->num_regulators; |
| 440 | lp3971->rdev = kzalloc(sizeof(struct regulator_dev *) * num_regulators, | 440 | lp3971->rdev = kcalloc(pdata->num_regulators, |
| 441 | GFP_KERNEL); | 441 | sizeof(struct regulator_dev *), GFP_KERNEL); |
| 442 | 442 | ||
| 443 | /* Instantiate the regulators */ | 443 | /* Instantiate the regulators */ |
| 444 | for (i = 0; i < num_regulators; i++) { | 444 | for (i = 0; i < pdata->num_regulators; i++) { |
| 445 | int id = pdata->regulators[i].id; | 445 | struct lp3971_regulator_subdev *reg = &pdata->regulators[i]; |
| 446 | lp3971->rdev[i] = regulator_register(®ulators[id], | 446 | lp3971->rdev[i] = regulator_register(®ulators[reg->id], |
| 447 | lp3971->dev, pdata->regulators[i].initdata, lp3971); | 447 | lp3971->dev, reg->initdata, lp3971); |
| 448 | 448 | ||
| 449 | if (IS_ERR(lp3971->rdev[i])) { | 449 | if (IS_ERR(lp3971->rdev[i])) { |
| 450 | err = PTR_ERR(lp3971->rdev[i]); | 450 | err = PTR_ERR(lp3971->rdev[i]); |
| @@ -455,10 +455,10 @@ static int setup_regulators(struct lp3971 *lp3971, | |||
| 455 | } | 455 | } |
| 456 | 456 | ||
| 457 | return 0; | 457 | return 0; |
| 458 | |||
| 458 | error: | 459 | error: |
| 459 | for (i = 0; i < num_regulators; i++) | 460 | while (--i >= 0) |
| 460 | if (lp3971->rdev[i]) | 461 | regulator_unregister(lp3971->rdev[i]); |
| 461 | regulator_unregister(lp3971->rdev[i]); | ||
| 462 | kfree(lp3971->rdev); | 462 | kfree(lp3971->rdev); |
| 463 | lp3971->rdev = NULL; | 463 | lp3971->rdev = NULL; |
| 464 | return err; | 464 | return err; |
| @@ -472,15 +472,17 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c, | |||
| 472 | int ret; | 472 | int ret; |
| 473 | u16 val; | 473 | u16 val; |
| 474 | 474 | ||
| 475 | lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL); | 475 | if (!pdata) { |
| 476 | if (lp3971 == NULL) { | 476 | dev_dbg(&i2c->dev, "No platform init data supplied\n"); |
| 477 | ret = -ENOMEM; | 477 | return -ENODEV; |
| 478 | goto err; | ||
| 479 | } | 478 | } |
| 480 | 479 | ||
| 480 | lp3971 = kzalloc(sizeof(struct lp3971), GFP_KERNEL); | ||
| 481 | if (lp3971 == NULL) | ||
| 482 | return -ENOMEM; | ||
| 483 | |||
| 481 | lp3971->i2c = i2c; | 484 | lp3971->i2c = i2c; |
| 482 | lp3971->dev = &i2c->dev; | 485 | lp3971->dev = &i2c->dev; |
| 483 | i2c_set_clientdata(i2c, lp3971); | ||
| 484 | 486 | ||
| 485 | mutex_init(&lp3971->io_lock); | 487 | mutex_init(&lp3971->io_lock); |
| 486 | 488 | ||
| @@ -493,19 +495,15 @@ static int __devinit lp3971_i2c_probe(struct i2c_client *i2c, | |||
| 493 | goto err_detect; | 495 | goto err_detect; |
| 494 | } | 496 | } |
| 495 | 497 | ||
| 496 | if (pdata) { | 498 | ret = setup_regulators(lp3971, pdata); |
| 497 | ret = setup_regulators(lp3971, pdata); | 499 | if (ret < 0) |
| 498 | if (ret < 0) | 500 | goto err_detect; |
| 499 | goto err_detect; | ||
| 500 | } else | ||
| 501 | dev_warn(lp3971->dev, "No platform init data supplied\n"); | ||
| 502 | 501 | ||
| 502 | i2c_set_clientdata(i2c, lp3971); | ||
| 503 | return 0; | 503 | return 0; |
| 504 | 504 | ||
| 505 | err_detect: | 505 | err_detect: |
| 506 | i2c_set_clientdata(i2c, NULL); | ||
| 507 | kfree(lp3971); | 506 | kfree(lp3971); |
| 508 | err: | ||
| 509 | return ret; | 507 | return ret; |
| 510 | } | 508 | } |
| 511 | 509 | ||
| @@ -513,11 +511,13 @@ static int __devexit lp3971_i2c_remove(struct i2c_client *i2c) | |||
| 513 | { | 511 | { |
| 514 | struct lp3971 *lp3971 = i2c_get_clientdata(i2c); | 512 | struct lp3971 *lp3971 = i2c_get_clientdata(i2c); |
| 515 | int i; | 513 | int i; |
| 514 | |||
| 515 | i2c_set_clientdata(i2c, NULL); | ||
| 516 | |||
| 516 | for (i = 0; i < lp3971->num_regulators; i++) | 517 | for (i = 0; i < lp3971->num_regulators; i++) |
| 517 | if (lp3971->rdev[i]) | 518 | regulator_unregister(lp3971->rdev[i]); |
| 518 | regulator_unregister(lp3971->rdev[i]); | 519 | |
| 519 | kfree(lp3971->rdev); | 520 | kfree(lp3971->rdev); |
| 520 | i2c_set_clientdata(i2c, NULL); | ||
| 521 | kfree(lp3971); | 521 | kfree(lp3971); |
| 522 | 522 | ||
| 523 | return 0; | 523 | return 0; |
diff --git a/drivers/regulator/max1586.c b/drivers/regulator/max1586.c index 2c082d3ef484..a49fc952c9a9 100644 --- a/drivers/regulator/max1586.c +++ b/drivers/regulator/max1586.c | |||
| @@ -179,8 +179,8 @@ static struct regulator_desc max1586_reg[] = { | |||
| 179 | }, | 179 | }, |
| 180 | }; | 180 | }; |
| 181 | 181 | ||
| 182 | static int max1586_pmic_probe(struct i2c_client *client, | 182 | static int __devinit max1586_pmic_probe(struct i2c_client *client, |
| 183 | const struct i2c_device_id *i2c_id) | 183 | const struct i2c_device_id *i2c_id) |
| 184 | { | 184 | { |
| 185 | struct regulator_dev **rdev; | 185 | struct regulator_dev **rdev; |
| 186 | struct max1586_platform_data *pdata = client->dev.platform_data; | 186 | struct max1586_platform_data *pdata = client->dev.platform_data; |
| @@ -235,7 +235,7 @@ out: | |||
| 235 | return ret; | 235 | return ret; |
| 236 | } | 236 | } |
| 237 | 237 | ||
| 238 | static int max1586_pmic_remove(struct i2c_client *client) | 238 | static int __devexit max1586_pmic_remove(struct i2c_client *client) |
| 239 | { | 239 | { |
| 240 | struct regulator_dev **rdev = i2c_get_clientdata(client); | 240 | struct regulator_dev **rdev = i2c_get_clientdata(client); |
| 241 | int i; | 241 | int i; |
| @@ -257,9 +257,10 @@ MODULE_DEVICE_TABLE(i2c, max1586_id); | |||
| 257 | 257 | ||
| 258 | static struct i2c_driver max1586_pmic_driver = { | 258 | static struct i2c_driver max1586_pmic_driver = { |
| 259 | .probe = max1586_pmic_probe, | 259 | .probe = max1586_pmic_probe, |
| 260 | .remove = max1586_pmic_remove, | 260 | .remove = __devexit_p(max1586_pmic_remove), |
| 261 | .driver = { | 261 | .driver = { |
| 262 | .name = "max1586", | 262 | .name = "max1586", |
| 263 | .owner = THIS_MODULE, | ||
| 263 | }, | 264 | }, |
| 264 | .id_table = max1586_id, | 265 | .id_table = max1586_id, |
| 265 | }; | 266 | }; |
diff --git a/drivers/regulator/max8649.c b/drivers/regulator/max8649.c new file mode 100644 index 000000000000..3ebdf698c648 --- /dev/null +++ b/drivers/regulator/max8649.c | |||
| @@ -0,0 +1,408 @@ | |||
| 1 | /* | ||
| 2 | * Regulators driver for Maxim max8649 | ||
| 3 | * | ||
| 4 | * Copyright (C) 2009-2010 Marvell International Ltd. | ||
| 5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | #include <linux/kernel.h> | ||
| 12 | #include <linux/module.h> | ||
| 13 | #include <linux/err.h> | ||
| 14 | #include <linux/i2c.h> | ||
| 15 | #include <linux/platform_device.h> | ||
| 16 | #include <linux/regulator/driver.h> | ||
| 17 | #include <linux/regulator/max8649.h> | ||
| 18 | |||
| 19 | #define MAX8649_DCDC_VMIN 750000 /* uV */ | ||
| 20 | #define MAX8649_DCDC_VMAX 1380000 /* uV */ | ||
| 21 | #define MAX8649_DCDC_STEP 10000 /* uV */ | ||
| 22 | #define MAX8649_VOL_MASK 0x3f | ||
| 23 | |||
| 24 | /* Registers */ | ||
| 25 | #define MAX8649_MODE0 0x00 | ||
| 26 | #define MAX8649_MODE1 0x01 | ||
| 27 | #define MAX8649_MODE2 0x02 | ||
| 28 | #define MAX8649_MODE3 0x03 | ||
| 29 | #define MAX8649_CONTROL 0x04 | ||
| 30 | #define MAX8649_SYNC 0x05 | ||
| 31 | #define MAX8649_RAMP 0x06 | ||
| 32 | #define MAX8649_CHIP_ID1 0x08 | ||
| 33 | #define MAX8649_CHIP_ID2 0x09 | ||
| 34 | |||
| 35 | /* Bits */ | ||
| 36 | #define MAX8649_EN_PD (1 << 7) | ||
| 37 | #define MAX8649_VID0_PD (1 << 6) | ||
| 38 | #define MAX8649_VID1_PD (1 << 5) | ||
| 39 | #define MAX8649_VID_MASK (3 << 5) | ||
| 40 | |||
| 41 | #define MAX8649_FORCE_PWM (1 << 7) | ||
| 42 | #define MAX8649_SYNC_EXTCLK (1 << 6) | ||
| 43 | |||
| 44 | #define MAX8649_EXT_MASK (3 << 6) | ||
| 45 | |||
| 46 | #define MAX8649_RAMP_MASK (7 << 5) | ||
| 47 | #define MAX8649_RAMP_DOWN (1 << 1) | ||
| 48 | |||
| 49 | struct max8649_regulator_info { | ||
| 50 | struct regulator_dev *regulator; | ||
| 51 | struct i2c_client *i2c; | ||
| 52 | struct device *dev; | ||
| 53 | struct mutex io_lock; | ||
| 54 | |||
| 55 | int vol_reg; | ||
| 56 | unsigned mode:2; /* bit[1:0] = VID1, VID0 */ | ||
| 57 | unsigned extclk_freq:2; | ||
| 58 | unsigned extclk:1; | ||
| 59 | unsigned ramp_timing:3; | ||
| 60 | unsigned ramp_down:1; | ||
| 61 | }; | ||
| 62 | |||
| 63 | /* I2C operations */ | ||
| 64 | |||
| 65 | static inline int max8649_read_device(struct i2c_client *i2c, | ||
| 66 | int reg, int bytes, void *dest) | ||
| 67 | { | ||
| 68 | unsigned char data; | ||
| 69 | int ret; | ||
| 70 | |||
| 71 | data = (unsigned char)reg; | ||
| 72 | ret = i2c_master_send(i2c, &data, 1); | ||
| 73 | if (ret < 0) | ||
| 74 | return ret; | ||
| 75 | ret = i2c_master_recv(i2c, dest, bytes); | ||
| 76 | if (ret < 0) | ||
| 77 | return ret; | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | static inline int max8649_write_device(struct i2c_client *i2c, | ||
| 82 | int reg, int bytes, void *src) | ||
| 83 | { | ||
| 84 | unsigned char buf[bytes + 1]; | ||
| 85 | int ret; | ||
| 86 | |||
| 87 | buf[0] = (unsigned char)reg; | ||
| 88 | memcpy(&buf[1], src, bytes); | ||
| 89 | |||
| 90 | ret = i2c_master_send(i2c, buf, bytes + 1); | ||
| 91 | if (ret < 0) | ||
| 92 | return ret; | ||
| 93 | return 0; | ||
| 94 | } | ||
| 95 | |||
| 96 | static int max8649_reg_read(struct i2c_client *i2c, int reg) | ||
| 97 | { | ||
| 98 | struct max8649_regulator_info *info = i2c_get_clientdata(i2c); | ||
| 99 | unsigned char data; | ||
| 100 | int ret; | ||
| 101 | |||
| 102 | mutex_lock(&info->io_lock); | ||
| 103 | ret = max8649_read_device(i2c, reg, 1, &data); | ||
| 104 | mutex_unlock(&info->io_lock); | ||
| 105 | |||
| 106 | if (ret < 0) | ||
| 107 | return ret; | ||
| 108 | return (int)data; | ||
| 109 | } | ||
| 110 | |||
| 111 | static int max8649_set_bits(struct i2c_client *i2c, int reg, | ||
| 112 | unsigned char mask, unsigned char data) | ||
| 113 | { | ||
| 114 | struct max8649_regulator_info *info = i2c_get_clientdata(i2c); | ||
| 115 | unsigned char value; | ||
| 116 | int ret; | ||
| 117 | |||
| 118 | mutex_lock(&info->io_lock); | ||
| 119 | ret = max8649_read_device(i2c, reg, 1, &value); | ||
| 120 | if (ret < 0) | ||
| 121 | goto out; | ||
| 122 | value &= ~mask; | ||
| 123 | value |= data; | ||
| 124 | ret = max8649_write_device(i2c, reg, 1, &value); | ||
| 125 | out: | ||
| 126 | mutex_unlock(&info->io_lock); | ||
| 127 | return ret; | ||
| 128 | } | ||
| 129 | |||
| 130 | static inline int check_range(int min_uV, int max_uV) | ||
| 131 | { | ||
| 132 | if ((min_uV < MAX8649_DCDC_VMIN) || (max_uV > MAX8649_DCDC_VMAX) | ||
| 133 | || (min_uV > max_uV)) | ||
| 134 | return -EINVAL; | ||
| 135 | return 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | static int max8649_list_voltage(struct regulator_dev *rdev, unsigned index) | ||
| 139 | { | ||
| 140 | return (MAX8649_DCDC_VMIN + index * MAX8649_DCDC_STEP); | ||
| 141 | } | ||
| 142 | |||
| 143 | static int max8649_get_voltage(struct regulator_dev *rdev) | ||
| 144 | { | ||
| 145 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 146 | unsigned char data; | ||
| 147 | int ret; | ||
| 148 | |||
| 149 | ret = max8649_reg_read(info->i2c, info->vol_reg); | ||
| 150 | if (ret < 0) | ||
| 151 | return ret; | ||
| 152 | data = (unsigned char)ret & MAX8649_VOL_MASK; | ||
| 153 | return max8649_list_voltage(rdev, data); | ||
| 154 | } | ||
| 155 | |||
| 156 | static int max8649_set_voltage(struct regulator_dev *rdev, | ||
| 157 | int min_uV, int max_uV) | ||
| 158 | { | ||
| 159 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 160 | unsigned char data, mask; | ||
| 161 | |||
| 162 | if (check_range(min_uV, max_uV)) { | ||
| 163 | dev_err(info->dev, "invalid voltage range (%d, %d) uV\n", | ||
| 164 | min_uV, max_uV); | ||
| 165 | return -EINVAL; | ||
| 166 | } | ||
| 167 | data = (min_uV - MAX8649_DCDC_VMIN + MAX8649_DCDC_STEP - 1) | ||
| 168 | / MAX8649_DCDC_STEP; | ||
| 169 | mask = MAX8649_VOL_MASK; | ||
| 170 | |||
| 171 | return max8649_set_bits(info->i2c, info->vol_reg, mask, data); | ||
| 172 | } | ||
| 173 | |||
| 174 | /* EN_PD means pulldown on EN input */ | ||
| 175 | static int max8649_enable(struct regulator_dev *rdev) | ||
| 176 | { | ||
| 177 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 178 | return max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD, 0); | ||
| 179 | } | ||
| 180 | |||
| 181 | /* | ||
| 182 | * Applied internal pulldown resistor on EN input pin. | ||
| 183 | * If pulldown EN pin outside, it would be better. | ||
| 184 | */ | ||
| 185 | static int max8649_disable(struct regulator_dev *rdev) | ||
| 186 | { | ||
| 187 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 188 | return max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_EN_PD, | ||
| 189 | MAX8649_EN_PD); | ||
| 190 | } | ||
| 191 | |||
| 192 | static int max8649_is_enabled(struct regulator_dev *rdev) | ||
| 193 | { | ||
| 194 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 195 | int ret; | ||
| 196 | |||
| 197 | ret = max8649_reg_read(info->i2c, MAX8649_CONTROL); | ||
| 198 | if (ret < 0) | ||
| 199 | return ret; | ||
| 200 | return !((unsigned char)ret & MAX8649_EN_PD); | ||
| 201 | } | ||
| 202 | |||
| 203 | static int max8649_enable_time(struct regulator_dev *rdev) | ||
| 204 | { | ||
| 205 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 206 | int voltage, rate, ret; | ||
| 207 | |||
| 208 | /* get voltage */ | ||
| 209 | ret = max8649_reg_read(info->i2c, info->vol_reg); | ||
| 210 | if (ret < 0) | ||
| 211 | return ret; | ||
| 212 | ret &= MAX8649_VOL_MASK; | ||
| 213 | voltage = max8649_list_voltage(rdev, (unsigned char)ret); /* uV */ | ||
| 214 | |||
| 215 | /* get rate */ | ||
| 216 | ret = max8649_reg_read(info->i2c, MAX8649_RAMP); | ||
| 217 | if (ret < 0) | ||
| 218 | return ret; | ||
| 219 | ret = (ret & MAX8649_RAMP_MASK) >> 5; | ||
| 220 | rate = (32 * 1000) >> ret; /* uV/uS */ | ||
| 221 | |||
| 222 | return (voltage / rate); | ||
| 223 | } | ||
| 224 | |||
| 225 | static int max8649_set_mode(struct regulator_dev *rdev, unsigned int mode) | ||
| 226 | { | ||
| 227 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 228 | |||
| 229 | switch (mode) { | ||
| 230 | case REGULATOR_MODE_FAST: | ||
| 231 | max8649_set_bits(info->i2c, info->vol_reg, MAX8649_FORCE_PWM, | ||
| 232 | MAX8649_FORCE_PWM); | ||
| 233 | break; | ||
| 234 | case REGULATOR_MODE_NORMAL: | ||
| 235 | max8649_set_bits(info->i2c, info->vol_reg, | ||
| 236 | MAX8649_FORCE_PWM, 0); | ||
| 237 | break; | ||
| 238 | default: | ||
| 239 | return -EINVAL; | ||
| 240 | } | ||
| 241 | return 0; | ||
| 242 | } | ||
| 243 | |||
| 244 | static unsigned int max8649_get_mode(struct regulator_dev *rdev) | ||
| 245 | { | ||
| 246 | struct max8649_regulator_info *info = rdev_get_drvdata(rdev); | ||
| 247 | int ret; | ||
| 248 | |||
| 249 | ret = max8649_reg_read(info->i2c, info->vol_reg); | ||
| 250 | if (ret & MAX8649_FORCE_PWM) | ||
| 251 | return REGULATOR_MODE_FAST; | ||
| 252 | return REGULATOR_MODE_NORMAL; | ||
| 253 | } | ||
| 254 | |||
| 255 | static struct regulator_ops max8649_dcdc_ops = { | ||
| 256 | .set_voltage = max8649_set_voltage, | ||
| 257 | .get_voltage = max8649_get_voltage, | ||
| 258 | .list_voltage = max8649_list_voltage, | ||
| 259 | .enable = max8649_enable, | ||
| 260 | .disable = max8649_disable, | ||
| 261 | .is_enabled = max8649_is_enabled, | ||
| 262 | .enable_time = max8649_enable_time, | ||
| 263 | .set_mode = max8649_set_mode, | ||
| 264 | .get_mode = max8649_get_mode, | ||
| 265 | |||
| 266 | }; | ||
| 267 | |||
| 268 | static struct regulator_desc dcdc_desc = { | ||
| 269 | .name = "max8649", | ||
| 270 | .ops = &max8649_dcdc_ops, | ||
| 271 | .type = REGULATOR_VOLTAGE, | ||
| 272 | .n_voltages = 1 << 6, | ||
| 273 | .owner = THIS_MODULE, | ||
| 274 | }; | ||
| 275 | |||
| 276 | static int __devinit max8649_regulator_probe(struct i2c_client *client, | ||
| 277 | const struct i2c_device_id *id) | ||
| 278 | { | ||
| 279 | struct max8649_platform_data *pdata = client->dev.platform_data; | ||
| 280 | struct max8649_regulator_info *info = NULL; | ||
| 281 | unsigned char data; | ||
| 282 | int ret; | ||
| 283 | |||
| 284 | info = kzalloc(sizeof(struct max8649_regulator_info), GFP_KERNEL); | ||
| 285 | if (!info) { | ||
| 286 | dev_err(&client->dev, "No enough memory\n"); | ||
| 287 | return -ENOMEM; | ||
| 288 | } | ||
| 289 | |||
| 290 | info->i2c = client; | ||
| 291 | info->dev = &client->dev; | ||
| 292 | mutex_init(&info->io_lock); | ||
| 293 | i2c_set_clientdata(client, info); | ||
| 294 | |||
| 295 | info->mode = pdata->mode; | ||
| 296 | switch (info->mode) { | ||
| 297 | case 0: | ||
| 298 | info->vol_reg = MAX8649_MODE0; | ||
| 299 | break; | ||
| 300 | case 1: | ||
| 301 | info->vol_reg = MAX8649_MODE1; | ||
| 302 | break; | ||
| 303 | case 2: | ||
| 304 | info->vol_reg = MAX8649_MODE2; | ||
| 305 | break; | ||
| 306 | case 3: | ||
| 307 | info->vol_reg = MAX8649_MODE3; | ||
| 308 | break; | ||
| 309 | default: | ||
| 310 | break; | ||
| 311 | } | ||
| 312 | |||
| 313 | ret = max8649_reg_read(info->i2c, MAX8649_CHIP_ID1); | ||
| 314 | if (ret < 0) { | ||
| 315 | dev_err(info->dev, "Failed to detect ID of MAX8649:%d\n", | ||
| 316 | ret); | ||
| 317 | goto out; | ||
| 318 | } | ||
| 319 | dev_info(info->dev, "Detected MAX8649 (ID:%x)\n", ret); | ||
| 320 | |||
| 321 | /* enable VID0 & VID1 */ | ||
| 322 | max8649_set_bits(info->i2c, MAX8649_CONTROL, MAX8649_VID_MASK, 0); | ||
| 323 | |||
| 324 | /* enable/disable external clock synchronization */ | ||
| 325 | info->extclk = pdata->extclk; | ||
| 326 | data = (info->extclk) ? MAX8649_SYNC_EXTCLK : 0; | ||
| 327 | max8649_set_bits(info->i2c, info->vol_reg, MAX8649_SYNC_EXTCLK, data); | ||
| 328 | if (info->extclk) { | ||
| 329 | /* set external clock frequency */ | ||
| 330 | info->extclk_freq = pdata->extclk_freq; | ||
| 331 | max8649_set_bits(info->i2c, MAX8649_SYNC, MAX8649_EXT_MASK, | ||
| 332 | info->extclk_freq); | ||
| 333 | } | ||
| 334 | |||
| 335 | if (pdata->ramp_timing) { | ||
| 336 | info->ramp_timing = pdata->ramp_timing; | ||
| 337 | max8649_set_bits(info->i2c, MAX8649_RAMP, MAX8649_RAMP_MASK, | ||
| 338 | info->ramp_timing << 5); | ||
| 339 | } | ||
| 340 | |||
| 341 | info->ramp_down = pdata->ramp_down; | ||
| 342 | if (info->ramp_down) { | ||
| 343 | max8649_set_bits(info->i2c, MAX8649_RAMP, MAX8649_RAMP_DOWN, | ||
| 344 | MAX8649_RAMP_DOWN); | ||
| 345 | } | ||
| 346 | |||
| 347 | info->regulator = regulator_register(&dcdc_desc, &client->dev, | ||
| 348 | pdata->regulator, info); | ||
| 349 | if (IS_ERR(info->regulator)) { | ||
| 350 | dev_err(info->dev, "failed to register regulator %s\n", | ||
| 351 | dcdc_desc.name); | ||
| 352 | ret = PTR_ERR(info->regulator); | ||
| 353 | goto out; | ||
| 354 | } | ||
| 355 | |||
| 356 | dev_info(info->dev, "Max8649 regulator device is detected.\n"); | ||
| 357 | return 0; | ||
| 358 | out: | ||
| 359 | kfree(info); | ||
| 360 | return ret; | ||
| 361 | } | ||
| 362 | |||
| 363 | static int __devexit max8649_regulator_remove(struct i2c_client *client) | ||
| 364 | { | ||
| 365 | struct max8649_regulator_info *info = i2c_get_clientdata(client); | ||
| 366 | |||
| 367 | if (info) { | ||
| 368 | if (info->regulator) | ||
| 369 | regulator_unregister(info->regulator); | ||
| 370 | kfree(info); | ||
| 371 | } | ||
| 372 | i2c_set_clientdata(client, NULL); | ||
| 373 | |||
| 374 | return 0; | ||
| 375 | } | ||
| 376 | |||
| 377 | static const struct i2c_device_id max8649_id[] = { | ||
| 378 | { "max8649", 0 }, | ||
| 379 | { } | ||
| 380 | }; | ||
| 381 | MODULE_DEVICE_TABLE(i2c, max8649_id); | ||
| 382 | |||
| 383 | static struct i2c_driver max8649_driver = { | ||
| 384 | .probe = max8649_regulator_probe, | ||
| 385 | .remove = __devexit_p(max8649_regulator_remove), | ||
| 386 | .driver = { | ||
| 387 | .name = "max8649", | ||
| 388 | }, | ||
| 389 | .id_table = max8649_id, | ||
| 390 | }; | ||
| 391 | |||
| 392 | static int __init max8649_init(void) | ||
| 393 | { | ||
| 394 | return i2c_add_driver(&max8649_driver); | ||
| 395 | } | ||
| 396 | subsys_initcall(max8649_init); | ||
| 397 | |||
| 398 | static void __exit max8649_exit(void) | ||
| 399 | { | ||
| 400 | i2c_del_driver(&max8649_driver); | ||
| 401 | } | ||
| 402 | module_exit(max8649_exit); | ||
| 403 | |||
| 404 | /* Module information */ | ||
| 405 | MODULE_DESCRIPTION("MAXIM 8649 voltage regulator driver"); | ||
| 406 | MODULE_AUTHOR("Haojian Zhuang <haojian.zhuang@marvell.com>"); | ||
| 407 | MODULE_LICENSE("GPL"); | ||
| 408 | |||
diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c index acc2fb7b6087..f12f1bb62138 100644 --- a/drivers/regulator/max8660.c +++ b/drivers/regulator/max8660.c | |||
| @@ -345,8 +345,8 @@ static struct regulator_desc max8660_reg[] = { | |||
| 345 | }, | 345 | }, |
| 346 | }; | 346 | }; |
| 347 | 347 | ||
| 348 | static int max8660_probe(struct i2c_client *client, | 348 | static int __devinit max8660_probe(struct i2c_client *client, |
| 349 | const struct i2c_device_id *i2c_id) | 349 | const struct i2c_device_id *i2c_id) |
| 350 | { | 350 | { |
| 351 | struct regulator_dev **rdev; | 351 | struct regulator_dev **rdev; |
| 352 | struct max8660_platform_data *pdata = client->dev.platform_data; | 352 | struct max8660_platform_data *pdata = client->dev.platform_data; |
| @@ -354,7 +354,7 @@ static int max8660_probe(struct i2c_client *client, | |||
| 354 | int boot_on, i, id, ret = -EINVAL; | 354 | int boot_on, i, id, ret = -EINVAL; |
| 355 | 355 | ||
| 356 | if (pdata->num_subdevs > MAX8660_V_END) { | 356 | if (pdata->num_subdevs > MAX8660_V_END) { |
| 357 | dev_err(&client->dev, "Too much regulators found!\n"); | 357 | dev_err(&client->dev, "Too many regulators found!\n"); |
| 358 | goto out; | 358 | goto out; |
| 359 | } | 359 | } |
| 360 | 360 | ||
| @@ -462,7 +462,7 @@ out: | |||
| 462 | return ret; | 462 | return ret; |
| 463 | } | 463 | } |
| 464 | 464 | ||
| 465 | static int max8660_remove(struct i2c_client *client) | 465 | static int __devexit max8660_remove(struct i2c_client *client) |
| 466 | { | 466 | { |
| 467 | struct regulator_dev **rdev = i2c_get_clientdata(client); | 467 | struct regulator_dev **rdev = i2c_get_clientdata(client); |
| 468 | int i; | 468 | int i; |
| @@ -485,9 +485,10 @@ MODULE_DEVICE_TABLE(i2c, max8660_id); | |||
| 485 | 485 | ||
| 486 | static struct i2c_driver max8660_driver = { | 486 | static struct i2c_driver max8660_driver = { |
| 487 | .probe = max8660_probe, | 487 | .probe = max8660_probe, |
| 488 | .remove = max8660_remove, | 488 | .remove = __devexit_p(max8660_remove), |
| 489 | .driver = { | 489 | .driver = { |
| 490 | .name = "max8660", | 490 | .name = "max8660", |
| 491 | .owner = THIS_MODULE, | ||
| 491 | }, | 492 | }, |
| 492 | .id_table = max8660_id, | 493 | .id_table = max8660_id, |
| 493 | }; | 494 | }; |
diff --git a/drivers/regulator/mc13783-regulator.c b/drivers/regulator/mc13783-regulator.c index 39c495300045..f7b81845a196 100644 --- a/drivers/regulator/mc13783-regulator.c +++ b/drivers/regulator/mc13783-regulator.c | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | * Regulator Driver for Freescale MC13783 PMIC | 2 | * Regulator Driver for Freescale MC13783 PMIC |
| 3 | * | 3 | * |
| 4 | * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> | 4 | * Copyright (C) 2008 Sascha Hauer, Pengutronix <s.hauer@pengutronix.de> |
| 5 | * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com> | ||
| 5 | * | 6 | * |
| 6 | * This program is free software; you can redistribute it and/or modify | 7 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as | 8 | * it under the terms of the GNU General Public License version 2 as |
| @@ -16,11 +17,44 @@ | |||
| 16 | #include <linux/init.h> | 17 | #include <linux/init.h> |
| 17 | #include <linux/err.h> | 18 | #include <linux/err.h> |
| 18 | 19 | ||
| 19 | #define MC13783_REG_SWITCHERS4 28 | ||
| 20 | #define MC13783_REG_SWITCHERS4_PLLEN (1 << 18) | ||
| 21 | |||
| 22 | #define MC13783_REG_SWITCHERS5 29 | 20 | #define MC13783_REG_SWITCHERS5 29 |
| 23 | #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) | 21 | #define MC13783_REG_SWITCHERS5_SW3EN (1 << 20) |
| 22 | #define MC13783_REG_SWITCHERS5_SW3VSEL 18 | ||
| 23 | #define MC13783_REG_SWITCHERS5_SW3VSEL_M (3 << 18) | ||
| 24 | |||
| 25 | #define MC13783_REG_REGULATORSETTING0 30 | ||
| 26 | #define MC13783_REG_REGULATORSETTING0_VIOLOVSEL 2 | ||
| 27 | #define MC13783_REG_REGULATORSETTING0_VDIGVSEL 4 | ||
| 28 | #define MC13783_REG_REGULATORSETTING0_VGENVSEL 6 | ||
| 29 | #define MC13783_REG_REGULATORSETTING0_VRFDIGVSEL 9 | ||
| 30 | #define MC13783_REG_REGULATORSETTING0_VRFREFVSEL 11 | ||
| 31 | #define MC13783_REG_REGULATORSETTING0_VRFCPVSEL 13 | ||
| 32 | #define MC13783_REG_REGULATORSETTING0_VSIMVSEL 14 | ||
| 33 | #define MC13783_REG_REGULATORSETTING0_VESIMVSEL 15 | ||
| 34 | #define MC13783_REG_REGULATORSETTING0_VCAMVSEL 16 | ||
| 35 | |||
| 36 | #define MC13783_REG_REGULATORSETTING0_VIOLOVSEL_M (3 << 2) | ||
| 37 | #define MC13783_REG_REGULATORSETTING0_VDIGVSEL_M (3 << 4) | ||
| 38 | #define MC13783_REG_REGULATORSETTING0_VGENVSEL_M (7 << 6) | ||
| 39 | #define MC13783_REG_REGULATORSETTING0_VRFDIGVSEL_M (3 << 9) | ||
| 40 | #define MC13783_REG_REGULATORSETTING0_VRFREFVSEL_M (3 << 11) | ||
| 41 | #define MC13783_REG_REGULATORSETTING0_VRFCPVSEL_M (1 << 13) | ||
| 42 | #define MC13783_REG_REGULATORSETTING0_VSIMVSEL_M (1 << 14) | ||
| 43 | #define MC13783_REG_REGULATORSETTING0_VESIMVSEL_M (1 << 15) | ||
| 44 | #define MC13783_REG_REGULATORSETTING0_VCAMVSEL_M (7 << 16) | ||
| 45 | |||
| 46 | #define MC13783_REG_REGULATORSETTING1 31 | ||
| 47 | #define MC13783_REG_REGULATORSETTING1_VVIBVSEL 0 | ||
| 48 | #define MC13783_REG_REGULATORSETTING1_VRF1VSEL 2 | ||
| 49 | #define MC13783_REG_REGULATORSETTING1_VRF2VSEL 4 | ||
| 50 | #define MC13783_REG_REGULATORSETTING1_VMMC1VSEL 6 | ||
| 51 | #define MC13783_REG_REGULATORSETTING1_VMMC2VSEL 9 | ||
| 52 | |||
| 53 | #define MC13783_REG_REGULATORSETTING1_VVIBVSEL_M (3 << 0) | ||
| 54 | #define MC13783_REG_REGULATORSETTING1_VRF1VSEL_M (3 << 2) | ||
| 55 | #define MC13783_REG_REGULATORSETTING1_VRF2VSEL_M (3 << 4) | ||
| 56 | #define MC13783_REG_REGULATORSETTING1_VMMC1VSEL_M (7 << 6) | ||
| 57 | #define MC13783_REG_REGULATORSETTING1_VMMC2VSEL_M (7 << 9) | ||
| 24 | 58 | ||
| 25 | #define MC13783_REG_REGULATORMODE0 32 | 59 | #define MC13783_REG_REGULATORMODE0 32 |
| 26 | #define MC13783_REG_REGULATORMODE0_VAUDIOEN (1 << 0) | 60 | #define MC13783_REG_REGULATORMODE0_VAUDIOEN (1 << 0) |
| @@ -48,19 +82,107 @@ | |||
| 48 | #define MC13783_REG_POWERMISC_GPO2EN (1 << 8) | 82 | #define MC13783_REG_POWERMISC_GPO2EN (1 << 8) |
| 49 | #define MC13783_REG_POWERMISC_GPO3EN (1 << 10) | 83 | #define MC13783_REG_POWERMISC_GPO3EN (1 << 10) |
| 50 | #define MC13783_REG_POWERMISC_GPO4EN (1 << 12) | 84 | #define MC13783_REG_POWERMISC_GPO4EN (1 << 12) |
| 85 | #define MC13783_REG_POWERMISC_PWGT1SPIEN (1 << 15) | ||
| 86 | #define MC13783_REG_POWERMISC_PWGT2SPIEN (1 << 16) | ||
| 87 | |||
| 88 | #define MC13783_REG_POWERMISC_PWGTSPI_M (3 << 15) | ||
| 89 | |||
| 51 | 90 | ||
| 52 | struct mc13783_regulator { | 91 | struct mc13783_regulator { |
| 53 | struct regulator_desc desc; | 92 | struct regulator_desc desc; |
| 54 | int reg; | 93 | int reg; |
| 55 | int enable_bit; | 94 | int enable_bit; |
| 95 | int vsel_reg; | ||
| 96 | int vsel_shift; | ||
| 97 | int vsel_mask; | ||
| 98 | int const *voltages; | ||
| 99 | }; | ||
| 100 | |||
| 101 | /* Voltage Values */ | ||
| 102 | static const int const mc13783_sw3_val[] = { | ||
| 103 | 5000000, 5000000, 5000000, 5500000, | ||
| 104 | }; | ||
| 105 | |||
| 106 | static const int const mc13783_vaudio_val[] = { | ||
| 107 | 2775000, | ||
| 108 | }; | ||
| 109 | |||
| 110 | static const int const mc13783_viohi_val[] = { | ||
| 111 | 2775000, | ||
| 112 | }; | ||
| 113 | |||
| 114 | static const int const mc13783_violo_val[] = { | ||
| 115 | 1200000, 1300000, 1500000, 1800000, | ||
| 116 | }; | ||
| 117 | |||
| 118 | static const int const mc13783_vdig_val[] = { | ||
| 119 | 1200000, 1300000, 1500000, 1800000, | ||
| 120 | }; | ||
| 121 | |||
| 122 | static const int const mc13783_vgen_val[] = { | ||
| 123 | 1200000, 1300000, 1500000, 1800000, | ||
| 124 | 1100000, 2000000, 2775000, 2400000, | ||
| 125 | }; | ||
| 126 | |||
| 127 | static const int const mc13783_vrfdig_val[] = { | ||
| 128 | 1200000, 1500000, 1800000, 1875000, | ||
| 129 | }; | ||
| 130 | |||
| 131 | static const int const mc13783_vrfref_val[] = { | ||
| 132 | 2475000, 2600000, 2700000, 2775000, | ||
| 133 | }; | ||
| 134 | |||
| 135 | static const int const mc13783_vrfcp_val[] = { | ||
| 136 | 2700000, 2775000, | ||
| 137 | }; | ||
| 138 | |||
| 139 | static const int const mc13783_vsim_val[] = { | ||
| 140 | 1800000, 2900000, 3000000, | ||
| 141 | }; | ||
| 142 | |||
| 143 | static const int const mc13783_vesim_val[] = { | ||
| 144 | 1800000, 2900000, | ||
| 145 | }; | ||
| 146 | |||
| 147 | static const int const mc13783_vcam_val[] = { | ||
| 148 | 1500000, 1800000, 2500000, 2550000, | ||
| 149 | 2600000, 2750000, 2800000, 3000000, | ||
| 150 | }; | ||
| 151 | |||
| 152 | static const int const mc13783_vrfbg_val[] = { | ||
| 153 | 1250000, | ||
| 154 | }; | ||
| 155 | |||
| 156 | static const int const mc13783_vvib_val[] = { | ||
| 157 | 1300000, 1800000, 2000000, 3000000, | ||
| 158 | }; | ||
| 159 | |||
| 160 | static const int const mc13783_vmmc_val[] = { | ||
| 161 | 1600000, 1800000, 2000000, 2600000, | ||
| 162 | 2700000, 2800000, 2900000, 3000000, | ||
| 163 | }; | ||
| 164 | |||
| 165 | static const int const mc13783_vrf_val[] = { | ||
| 166 | 1500000, 1875000, 2700000, 2775000, | ||
| 167 | }; | ||
| 168 | |||
| 169 | static const int const mc13783_gpo_val[] = { | ||
| 170 | 3100000, | ||
| 171 | }; | ||
| 172 | |||
| 173 | static const int const mc13783_pwgtdrv_val[] = { | ||
| 174 | 5500000, | ||
| 56 | }; | 175 | }; |
| 57 | 176 | ||
| 58 | static struct regulator_ops mc13783_regulator_ops; | 177 | static struct regulator_ops mc13783_regulator_ops; |
| 178 | static struct regulator_ops mc13783_fixed_regulator_ops; | ||
| 179 | static struct regulator_ops mc13783_gpo_regulator_ops; | ||
| 59 | 180 | ||
| 60 | #define MC13783_DEFINE(prefix, _name, _reg) \ | 181 | #define MC13783_DEFINE(prefix, _name, _reg, _vsel_reg, _voltages) \ |
| 61 | [MC13783_ ## prefix ## _ ## _name] = { \ | 182 | [MC13783_ ## prefix ## _ ## _name] = { \ |
| 62 | .desc = { \ | 183 | .desc = { \ |
| 63 | .name = #prefix "_" #_name, \ | 184 | .name = #prefix "_" #_name, \ |
| 185 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
| 64 | .ops = &mc13783_regulator_ops, \ | 186 | .ops = &mc13783_regulator_ops, \ |
| 65 | .type = REGULATOR_VOLTAGE, \ | 187 | .type = REGULATOR_VOLTAGE, \ |
| 66 | .id = MC13783_ ## prefix ## _ ## _name, \ | 188 | .id = MC13783_ ## prefix ## _ ## _name, \ |
| @@ -68,40 +190,92 @@ static struct regulator_ops mc13783_regulator_ops; | |||
| 68 | }, \ | 190 | }, \ |
| 69 | .reg = MC13783_REG_ ## _reg, \ | 191 | .reg = MC13783_REG_ ## _reg, \ |
| 70 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | 192 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ |
| 193 | .vsel_reg = MC13783_REG_ ## _vsel_reg, \ | ||
| 194 | .vsel_shift = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL,\ | ||
| 195 | .vsel_mask = MC13783_REG_ ## _vsel_reg ## _ ## _name ## VSEL_M,\ | ||
| 196 | .voltages = _voltages, \ | ||
| 197 | } | ||
| 198 | |||
| 199 | #define MC13783_FIXED_DEFINE(prefix, _name, _reg, _voltages) \ | ||
| 200 | [MC13783_ ## prefix ## _ ## _name] = { \ | ||
| 201 | .desc = { \ | ||
| 202 | .name = #prefix "_" #_name, \ | ||
| 203 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
| 204 | .ops = &mc13783_fixed_regulator_ops, \ | ||
| 205 | .type = REGULATOR_VOLTAGE, \ | ||
| 206 | .id = MC13783_ ## prefix ## _ ## _name, \ | ||
| 207 | .owner = THIS_MODULE, \ | ||
| 208 | }, \ | ||
| 209 | .reg = MC13783_REG_ ## _reg, \ | ||
| 210 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | ||
| 211 | .voltages = _voltages, \ | ||
| 71 | } | 212 | } |
| 72 | 213 | ||
| 73 | #define MC13783_DEFINE_SW(_name, _reg) MC13783_DEFINE(SW, _name, _reg) | 214 | #define MC13783_GPO_DEFINE(prefix, _name, _reg, _voltages) \ |
| 74 | #define MC13783_DEFINE_REGU(_name, _reg) MC13783_DEFINE(REGU, _name, _reg) | 215 | [MC13783_ ## prefix ## _ ## _name] = { \ |
| 216 | .desc = { \ | ||
| 217 | .name = #prefix "_" #_name, \ | ||
| 218 | .n_voltages = ARRAY_SIZE(_voltages), \ | ||
| 219 | .ops = &mc13783_gpo_regulator_ops, \ | ||
| 220 | .type = REGULATOR_VOLTAGE, \ | ||
| 221 | .id = MC13783_ ## prefix ## _ ## _name, \ | ||
| 222 | .owner = THIS_MODULE, \ | ||
| 223 | }, \ | ||
| 224 | .reg = MC13783_REG_ ## _reg, \ | ||
| 225 | .enable_bit = MC13783_REG_ ## _reg ## _ ## _name ## EN, \ | ||
| 226 | .voltages = _voltages, \ | ||
| 227 | } | ||
| 228 | |||
| 229 | #define MC13783_DEFINE_SW(_name, _reg, _vsel_reg, _voltages) \ | ||
| 230 | MC13783_DEFINE(SW, _name, _reg, _vsel_reg, _voltages) | ||
| 231 | #define MC13783_DEFINE_REGU(_name, _reg, _vsel_reg, _voltages) \ | ||
| 232 | MC13783_DEFINE(REGU, _name, _reg, _vsel_reg, _voltages) | ||
| 75 | 233 | ||
| 76 | static struct mc13783_regulator mc13783_regulators[] = { | 234 | static struct mc13783_regulator mc13783_regulators[] = { |
| 77 | MC13783_DEFINE_SW(SW3, SWITCHERS5), | 235 | MC13783_DEFINE_SW(SW3, SWITCHERS5, SWITCHERS5, mc13783_sw3_val), |
| 78 | MC13783_DEFINE_SW(PLL, SWITCHERS4), | 236 | |
| 79 | 237 | MC13783_FIXED_DEFINE(REGU, VAUDIO, REGULATORMODE0, mc13783_vaudio_val), | |
| 80 | MC13783_DEFINE_REGU(VAUDIO, REGULATORMODE0), | 238 | MC13783_FIXED_DEFINE(REGU, VIOHI, REGULATORMODE0, mc13783_viohi_val), |
| 81 | MC13783_DEFINE_REGU(VIOHI, REGULATORMODE0), | 239 | MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0, REGULATORSETTING0, \ |
| 82 | MC13783_DEFINE_REGU(VIOLO, REGULATORMODE0), | 240 | mc13783_violo_val), |
| 83 | MC13783_DEFINE_REGU(VDIG, REGULATORMODE0), | 241 | MC13783_DEFINE_REGU(VDIG, REGULATORMODE0, REGULATORSETTING0, \ |
| 84 | MC13783_DEFINE_REGU(VGEN, REGULATORMODE0), | 242 | mc13783_vdig_val), |
| 85 | MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0), | 243 | MC13783_DEFINE_REGU(VGEN, REGULATORMODE0, REGULATORSETTING0, \ |
| 86 | MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0), | 244 | mc13783_vgen_val), |
| 87 | MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0), | 245 | MC13783_DEFINE_REGU(VRFDIG, REGULATORMODE0, REGULATORSETTING0, \ |
| 88 | MC13783_DEFINE_REGU(VSIM, REGULATORMODE1), | 246 | mc13783_vrfdig_val), |
| 89 | MC13783_DEFINE_REGU(VESIM, REGULATORMODE1), | 247 | MC13783_DEFINE_REGU(VRFREF, REGULATORMODE0, REGULATORSETTING0, \ |
| 90 | MC13783_DEFINE_REGU(VCAM, REGULATORMODE1), | 248 | mc13783_vrfref_val), |
| 91 | MC13783_DEFINE_REGU(VRFBG, REGULATORMODE1), | 249 | MC13783_DEFINE_REGU(VRFCP, REGULATORMODE0, REGULATORSETTING0, \ |
| 92 | MC13783_DEFINE_REGU(VVIB, REGULATORMODE1), | 250 | mc13783_vrfcp_val), |
| 93 | MC13783_DEFINE_REGU(VRF1, REGULATORMODE1), | 251 | MC13783_DEFINE_REGU(VSIM, REGULATORMODE1, REGULATORSETTING0, \ |
| 94 | MC13783_DEFINE_REGU(VRF2, REGULATORMODE1), | 252 | mc13783_vsim_val), |
| 95 | MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1), | 253 | MC13783_DEFINE_REGU(VESIM, REGULATORMODE1, REGULATORSETTING0, \ |
| 96 | MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1), | 254 | mc13783_vesim_val), |
| 97 | MC13783_DEFINE_REGU(GPO1, POWERMISC), | 255 | MC13783_DEFINE_REGU(VCAM, REGULATORMODE1, REGULATORSETTING0, \ |
| 98 | MC13783_DEFINE_REGU(GPO2, POWERMISC), | 256 | mc13783_vcam_val), |
| 99 | MC13783_DEFINE_REGU(GPO3, POWERMISC), | 257 | MC13783_FIXED_DEFINE(REGU, VRFBG, REGULATORMODE1, mc13783_vrfbg_val), |
| 100 | MC13783_DEFINE_REGU(GPO4, POWERMISC), | 258 | MC13783_DEFINE_REGU(VVIB, REGULATORMODE1, REGULATORSETTING1, \ |
| 259 | mc13783_vvib_val), | ||
| 260 | MC13783_DEFINE_REGU(VRF1, REGULATORMODE1, REGULATORSETTING1, \ | ||
| 261 | mc13783_vrf_val), | ||
| 262 | MC13783_DEFINE_REGU(VRF2, REGULATORMODE1, REGULATORSETTING1, \ | ||
| 263 | mc13783_vrf_val), | ||
| 264 | MC13783_DEFINE_REGU(VMMC1, REGULATORMODE1, REGULATORSETTING1, \ | ||
| 265 | mc13783_vmmc_val), | ||
| 266 | MC13783_DEFINE_REGU(VMMC2, REGULATORMODE1, REGULATORSETTING1, \ | ||
| 267 | mc13783_vmmc_val), | ||
| 268 | MC13783_GPO_DEFINE(REGU, GPO1, POWERMISC, mc13783_gpo_val), | ||
| 269 | MC13783_GPO_DEFINE(REGU, GPO2, POWERMISC, mc13783_gpo_val), | ||
| 270 | MC13783_GPO_DEFINE(REGU, GPO3, POWERMISC, mc13783_gpo_val), | ||
| 271 | MC13783_GPO_DEFINE(REGU, GPO4, POWERMISC, mc13783_gpo_val), | ||
| 272 | MC13783_GPO_DEFINE(REGU, PWGT1SPI, POWERMISC, mc13783_pwgtdrv_val), | ||
| 273 | MC13783_GPO_DEFINE(REGU, PWGT2SPI, POWERMISC, mc13783_pwgtdrv_val), | ||
| 101 | }; | 274 | }; |
| 102 | 275 | ||
| 103 | struct mc13783_regulator_priv { | 276 | struct mc13783_regulator_priv { |
| 104 | struct mc13783 *mc13783; | 277 | struct mc13783 *mc13783; |
| 278 | u32 powermisc_pwgt_state; | ||
| 105 | struct regulator_dev *regulators[]; | 279 | struct regulator_dev *regulators[]; |
| 106 | }; | 280 | }; |
| 107 | 281 | ||
| @@ -154,10 +328,241 @@ static int mc13783_regulator_is_enabled(struct regulator_dev *rdev) | |||
| 154 | return (val & mc13783_regulators[id].enable_bit) != 0; | 328 | return (val & mc13783_regulators[id].enable_bit) != 0; |
| 155 | } | 329 | } |
| 156 | 330 | ||
| 331 | static int mc13783_regulator_list_voltage(struct regulator_dev *rdev, | ||
| 332 | unsigned selector) | ||
| 333 | { | ||
| 334 | int id = rdev_get_id(rdev); | ||
| 335 | |||
| 336 | if (selector >= mc13783_regulators[id].desc.n_voltages) | ||
| 337 | return -EINVAL; | ||
| 338 | |||
| 339 | return mc13783_regulators[id].voltages[selector]; | ||
| 340 | } | ||
| 341 | |||
| 342 | static int mc13783_get_best_voltage_index(struct regulator_dev *rdev, | ||
| 343 | int min_uV, int max_uV) | ||
| 344 | { | ||
| 345 | int reg_id = rdev_get_id(rdev); | ||
| 346 | int i; | ||
| 347 | int bestmatch; | ||
| 348 | int bestindex; | ||
| 349 | |||
| 350 | /* | ||
| 351 | * Locate the minimum voltage fitting the criteria on | ||
| 352 | * this regulator. The switchable voltages are not | ||
| 353 | * in strict falling order so we need to check them | ||
| 354 | * all for the best match. | ||
| 355 | */ | ||
| 356 | bestmatch = INT_MAX; | ||
| 357 | bestindex = -1; | ||
| 358 | for (i = 0; i < mc13783_regulators[reg_id].desc.n_voltages; i++) { | ||
| 359 | if (mc13783_regulators[reg_id].voltages[i] >= min_uV && | ||
| 360 | mc13783_regulators[reg_id].voltages[i] < bestmatch) { | ||
| 361 | bestmatch = mc13783_regulators[reg_id].voltages[i]; | ||
| 362 | bestindex = i; | ||
| 363 | } | ||
| 364 | } | ||
| 365 | |||
| 366 | if (bestindex < 0 || bestmatch > max_uV) { | ||
| 367 | dev_warn(&rdev->dev, "no possible value for %d<=x<=%d uV\n", | ||
| 368 | min_uV, max_uV); | ||
| 369 | return -EINVAL; | ||
| 370 | } | ||
| 371 | return bestindex; | ||
| 372 | } | ||
| 373 | |||
| 374 | static int mc13783_regulator_set_voltage(struct regulator_dev *rdev, | ||
| 375 | int min_uV, int max_uV) | ||
| 376 | { | ||
| 377 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
| 378 | int value, id = rdev_get_id(rdev); | ||
| 379 | int ret; | ||
| 380 | |||
| 381 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | ||
| 382 | __func__, id, min_uV, max_uV); | ||
| 383 | |||
| 384 | /* Find the best index */ | ||
| 385 | value = mc13783_get_best_voltage_index(rdev, min_uV, max_uV); | ||
| 386 | dev_dbg(rdev_get_dev(rdev), "%s best value: %d \n", __func__, value); | ||
| 387 | if (value < 0) | ||
| 388 | return value; | ||
| 389 | |||
| 390 | mc13783_lock(priv->mc13783); | ||
| 391 | ret = mc13783_reg_rmw(priv->mc13783, mc13783_regulators[id].vsel_reg, | ||
| 392 | mc13783_regulators[id].vsel_mask, | ||
| 393 | value << mc13783_regulators[id].vsel_shift); | ||
| 394 | mc13783_unlock(priv->mc13783); | ||
| 395 | |||
| 396 | return ret; | ||
| 397 | } | ||
| 398 | |||
| 399 | static int mc13783_regulator_get_voltage(struct regulator_dev *rdev) | ||
| 400 | { | ||
| 401 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
| 402 | int ret, id = rdev_get_id(rdev); | ||
| 403 | unsigned int val; | ||
| 404 | |||
| 405 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
| 406 | |||
| 407 | mc13783_lock(priv->mc13783); | ||
| 408 | ret = mc13783_reg_read(priv->mc13783, | ||
| 409 | mc13783_regulators[id].vsel_reg, &val); | ||
| 410 | mc13783_unlock(priv->mc13783); | ||
| 411 | |||
| 412 | if (ret) | ||
| 413 | return ret; | ||
| 414 | |||
| 415 | val = (val & mc13783_regulators[id].vsel_mask) | ||
| 416 | >> mc13783_regulators[id].vsel_shift; | ||
| 417 | |||
| 418 | dev_dbg(rdev_get_dev(rdev), "%s id: %d val: %d\n", __func__, id, val); | ||
| 419 | |||
| 420 | BUG_ON(val < 0 || val > mc13783_regulators[id].desc.n_voltages); | ||
| 421 | |||
| 422 | return mc13783_regulators[id].voltages[val]; | ||
| 423 | } | ||
| 424 | |||
| 157 | static struct regulator_ops mc13783_regulator_ops = { | 425 | static struct regulator_ops mc13783_regulator_ops = { |
| 158 | .enable = mc13783_regulator_enable, | 426 | .enable = mc13783_regulator_enable, |
| 159 | .disable = mc13783_regulator_disable, | 427 | .disable = mc13783_regulator_disable, |
| 160 | .is_enabled = mc13783_regulator_is_enabled, | 428 | .is_enabled = mc13783_regulator_is_enabled, |
| 429 | .list_voltage = mc13783_regulator_list_voltage, | ||
| 430 | .set_voltage = mc13783_regulator_set_voltage, | ||
| 431 | .get_voltage = mc13783_regulator_get_voltage, | ||
| 432 | }; | ||
| 433 | |||
| 434 | static int mc13783_fixed_regulator_set_voltage(struct regulator_dev *rdev, | ||
| 435 | int min_uV, int max_uV) | ||
| 436 | { | ||
| 437 | int id = rdev_get_id(rdev); | ||
| 438 | |||
| 439 | dev_dbg(rdev_get_dev(rdev), "%s id: %d min_uV: %d max_uV: %d\n", | ||
| 440 | __func__, id, min_uV, max_uV); | ||
| 441 | |||
| 442 | if (min_uV > mc13783_regulators[id].voltages[0] && | ||
| 443 | max_uV < mc13783_regulators[id].voltages[0]) | ||
| 444 | return 0; | ||
| 445 | else | ||
| 446 | return -EINVAL; | ||
| 447 | } | ||
| 448 | |||
| 449 | static int mc13783_fixed_regulator_get_voltage(struct regulator_dev *rdev) | ||
| 450 | { | ||
| 451 | int id = rdev_get_id(rdev); | ||
| 452 | |||
| 453 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
| 454 | |||
| 455 | return mc13783_regulators[id].voltages[0]; | ||
| 456 | } | ||
| 457 | |||
| 458 | static struct regulator_ops mc13783_fixed_regulator_ops = { | ||
| 459 | .enable = mc13783_regulator_enable, | ||
| 460 | .disable = mc13783_regulator_disable, | ||
| 461 | .is_enabled = mc13783_regulator_is_enabled, | ||
| 462 | .list_voltage = mc13783_regulator_list_voltage, | ||
| 463 | .set_voltage = mc13783_fixed_regulator_set_voltage, | ||
| 464 | .get_voltage = mc13783_fixed_regulator_get_voltage, | ||
| 465 | }; | ||
| 466 | |||
| 467 | int mc13783_powermisc_rmw(struct mc13783_regulator_priv *priv, u32 mask, | ||
| 468 | u32 val) | ||
| 469 | { | ||
| 470 | struct mc13783 *mc13783 = priv->mc13783; | ||
| 471 | int ret; | ||
| 472 | u32 valread; | ||
| 473 | |||
| 474 | BUG_ON(val & ~mask); | ||
| 475 | |||
| 476 | ret = mc13783_reg_read(mc13783, MC13783_REG_POWERMISC, &valread); | ||
| 477 | if (ret) | ||
| 478 | return ret; | ||
| 479 | |||
| 480 | /* Update the stored state for Power Gates. */ | ||
| 481 | priv->powermisc_pwgt_state = | ||
| 482 | (priv->powermisc_pwgt_state & ~mask) | val; | ||
| 483 | priv->powermisc_pwgt_state &= MC13783_REG_POWERMISC_PWGTSPI_M; | ||
| 484 | |||
| 485 | /* Construct the new register value */ | ||
| 486 | valread = (valread & ~mask) | val; | ||
| 487 | /* Overwrite the PWGTxEN with the stored version */ | ||
| 488 | valread = (valread & ~MC13783_REG_POWERMISC_PWGTSPI_M) | | ||
| 489 | priv->powermisc_pwgt_state; | ||
| 490 | |||
| 491 | return mc13783_reg_write(mc13783, MC13783_REG_POWERMISC, valread); | ||
| 492 | } | ||
| 493 | |||
| 494 | static int mc13783_gpo_regulator_enable(struct regulator_dev *rdev) | ||
| 495 | { | ||
| 496 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
| 497 | int id = rdev_get_id(rdev); | ||
| 498 | int ret; | ||
| 499 | u32 en_val = mc13783_regulators[id].enable_bit; | ||
| 500 | |||
| 501 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
| 502 | |||
| 503 | /* Power Gate enable value is 0 */ | ||
| 504 | if (id == MC13783_REGU_PWGT1SPI || | ||
| 505 | id == MC13783_REGU_PWGT2SPI) | ||
| 506 | en_val = 0; | ||
| 507 | |||
| 508 | mc13783_lock(priv->mc13783); | ||
| 509 | ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, | ||
| 510 | en_val); | ||
| 511 | mc13783_unlock(priv->mc13783); | ||
| 512 | |||
| 513 | return ret; | ||
| 514 | } | ||
| 515 | |||
| 516 | static int mc13783_gpo_regulator_disable(struct regulator_dev *rdev) | ||
| 517 | { | ||
| 518 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
| 519 | int id = rdev_get_id(rdev); | ||
| 520 | int ret; | ||
| 521 | u32 dis_val = 0; | ||
| 522 | |||
| 523 | dev_dbg(rdev_get_dev(rdev), "%s id: %d\n", __func__, id); | ||
| 524 | |||
| 525 | /* Power Gate disable value is 1 */ | ||
| 526 | if (id == MC13783_REGU_PWGT1SPI || | ||
| 527 | id == MC13783_REGU_PWGT2SPI) | ||
| 528 | dis_val = mc13783_regulators[id].enable_bit; | ||
| 529 | |||
| 530 | mc13783_lock(priv->mc13783); | ||
| 531 | ret = mc13783_powermisc_rmw(priv, mc13783_regulators[id].enable_bit, | ||
| 532 | dis_val); | ||
| 533 | mc13783_unlock(priv->mc13783); | ||
| 534 | |||
| 535 | return ret; | ||
| 536 | } | ||
| 537 | |||
| 538 | static int mc13783_gpo_regulator_is_enabled(struct regulator_dev *rdev) | ||
| 539 | { | ||
| 540 | struct mc13783_regulator_priv *priv = rdev_get_drvdata(rdev); | ||
| 541 | int ret, id = rdev_get_id(rdev); | ||
| 542 | unsigned int val; | ||
| 543 | |||
| 544 | mc13783_lock(priv->mc13783); | ||
| 545 | ret = mc13783_reg_read(priv->mc13783, mc13783_regulators[id].reg, &val); | ||
| 546 | mc13783_unlock(priv->mc13783); | ||
| 547 | |||
| 548 | if (ret) | ||
| 549 | return ret; | ||
| 550 | |||
| 551 | /* Power Gates state is stored in powermisc_pwgt_state | ||
| 552 | * where the meaning of bits is negated */ | ||
| 553 | val = (val & ~MC13783_REG_POWERMISC_PWGTSPI_M) | | ||
| 554 | (priv->powermisc_pwgt_state ^ MC13783_REG_POWERMISC_PWGTSPI_M); | ||
| 555 | |||
| 556 | return (val & mc13783_regulators[id].enable_bit) != 0; | ||
| 557 | } | ||
| 558 | |||
| 559 | static struct regulator_ops mc13783_gpo_regulator_ops = { | ||
| 560 | .enable = mc13783_gpo_regulator_enable, | ||
| 561 | .disable = mc13783_gpo_regulator_disable, | ||
| 562 | .is_enabled = mc13783_gpo_regulator_is_enabled, | ||
| 563 | .list_voltage = mc13783_regulator_list_voltage, | ||
| 564 | .set_voltage = mc13783_fixed_regulator_set_voltage, | ||
| 565 | .get_voltage = mc13783_fixed_regulator_get_voltage, | ||
| 161 | }; | 566 | }; |
| 162 | 567 | ||
| 163 | static int __devinit mc13783_regulator_probe(struct platform_device *pdev) | 568 | static int __devinit mc13783_regulator_probe(struct platform_device *pdev) |
diff --git a/drivers/regulator/pcap-regulator.c b/drivers/regulator/pcap-regulator.c index 33d7d899e030..29d0566379ae 100644 --- a/drivers/regulator/pcap-regulator.c +++ b/drivers/regulator/pcap-regulator.c | |||
| @@ -288,16 +288,18 @@ static int __devexit pcap_regulator_remove(struct platform_device *pdev) | |||
| 288 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | 288 | struct regulator_dev *rdev = platform_get_drvdata(pdev); |
| 289 | 289 | ||
| 290 | regulator_unregister(rdev); | 290 | regulator_unregister(rdev); |
| 291 | platform_set_drvdata(pdev, NULL); | ||
| 291 | 292 | ||
| 292 | return 0; | 293 | return 0; |
| 293 | } | 294 | } |
| 294 | 295 | ||
| 295 | static struct platform_driver pcap_regulator_driver = { | 296 | static struct platform_driver pcap_regulator_driver = { |
| 296 | .driver = { | 297 | .driver = { |
| 297 | .name = "pcap-regulator", | 298 | .name = "pcap-regulator", |
| 299 | .owner = THIS_MODULE, | ||
| 298 | }, | 300 | }, |
| 299 | .probe = pcap_regulator_probe, | 301 | .probe = pcap_regulator_probe, |
| 300 | .remove = __devexit_p(pcap_regulator_remove), | 302 | .remove = __devexit_p(pcap_regulator_remove), |
| 301 | }; | 303 | }; |
| 302 | 304 | ||
| 303 | static int __init pcap_regulator_init(void) | 305 | static int __init pcap_regulator_init(void) |
diff --git a/drivers/regulator/tps65023-regulator.c b/drivers/regulator/tps65023-regulator.c index 07fda0a75adf..1f183543bdbd 100644 --- a/drivers/regulator/tps65023-regulator.c +++ b/drivers/regulator/tps65023-regulator.c | |||
| @@ -457,8 +457,8 @@ static struct regulator_ops tps65023_ldo_ops = { | |||
| 457 | .list_voltage = tps65023_ldo_list_voltage, | 457 | .list_voltage = tps65023_ldo_list_voltage, |
| 458 | }; | 458 | }; |
| 459 | 459 | ||
| 460 | static | 460 | static int __devinit tps_65023_probe(struct i2c_client *client, |
| 461 | int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) | 461 | const struct i2c_device_id *id) |
| 462 | { | 462 | { |
| 463 | static int desc_id; | 463 | static int desc_id; |
| 464 | const struct tps_info *info = (void *)id->driver_data; | 464 | const struct tps_info *info = (void *)id->driver_data; |
| @@ -466,6 +466,7 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 466 | struct regulator_dev *rdev; | 466 | struct regulator_dev *rdev; |
| 467 | struct tps_pmic *tps; | 467 | struct tps_pmic *tps; |
| 468 | int i; | 468 | int i; |
| 469 | int error; | ||
| 469 | 470 | ||
| 470 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | 471 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 471 | return -EIO; | 472 | return -EIO; |
| @@ -475,7 +476,6 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 475 | * coming from the board-evm file. | 476 | * coming from the board-evm file. |
| 476 | */ | 477 | */ |
| 477 | init_data = client->dev.platform_data; | 478 | init_data = client->dev.platform_data; |
| 478 | |||
| 479 | if (!init_data) | 479 | if (!init_data) |
| 480 | return -EIO; | 480 | return -EIO; |
| 481 | 481 | ||
| @@ -502,21 +502,12 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 502 | 502 | ||
| 503 | /* Register the regulators */ | 503 | /* Register the regulators */ |
| 504 | rdev = regulator_register(&tps->desc[i], &client->dev, | 504 | rdev = regulator_register(&tps->desc[i], &client->dev, |
| 505 | init_data, tps); | 505 | init_data, tps); |
| 506 | if (IS_ERR(rdev)) { | 506 | if (IS_ERR(rdev)) { |
| 507 | dev_err(&client->dev, "failed to register %s\n", | 507 | dev_err(&client->dev, "failed to register %s\n", |
| 508 | id->name); | 508 | id->name); |
| 509 | 509 | error = PTR_ERR(rdev); | |
| 510 | /* Unregister */ | 510 | goto fail; |
| 511 | while (i) | ||
| 512 | regulator_unregister(tps->rdev[--i]); | ||
| 513 | |||
| 514 | tps->client = NULL; | ||
| 515 | |||
| 516 | /* clear the client data in i2c */ | ||
| 517 | i2c_set_clientdata(client, NULL); | ||
| 518 | kfree(tps); | ||
| 519 | return PTR_ERR(rdev); | ||
| 520 | } | 511 | } |
| 521 | 512 | ||
| 522 | /* Save regulator for cleanup */ | 513 | /* Save regulator for cleanup */ |
| @@ -526,6 +517,13 @@ int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 526 | i2c_set_clientdata(client, tps); | 517 | i2c_set_clientdata(client, tps); |
| 527 | 518 | ||
| 528 | return 0; | 519 | return 0; |
| 520 | |||
| 521 | fail: | ||
| 522 | while (--i >= 0) | ||
| 523 | regulator_unregister(tps->rdev[i]); | ||
| 524 | |||
| 525 | kfree(tps); | ||
| 526 | return error; | ||
| 529 | } | 527 | } |
| 530 | 528 | ||
| 531 | /** | 529 | /** |
| @@ -539,13 +537,12 @@ static int __devexit tps_65023_remove(struct i2c_client *client) | |||
| 539 | struct tps_pmic *tps = i2c_get_clientdata(client); | 537 | struct tps_pmic *tps = i2c_get_clientdata(client); |
| 540 | int i; | 538 | int i; |
| 541 | 539 | ||
| 540 | /* clear the client data in i2c */ | ||
| 541 | i2c_set_clientdata(client, NULL); | ||
| 542 | |||
| 542 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) | 543 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) |
| 543 | regulator_unregister(tps->rdev[i]); | 544 | regulator_unregister(tps->rdev[i]); |
| 544 | 545 | ||
| 545 | tps->client = NULL; | ||
| 546 | |||
| 547 | /* clear the client data in i2c */ | ||
| 548 | i2c_set_clientdata(client, NULL); | ||
| 549 | kfree(tps); | 546 | kfree(tps); |
| 550 | 547 | ||
| 551 | return 0; | 548 | return 0; |
diff --git a/drivers/regulator/tps6507x-regulator.c b/drivers/regulator/tps6507x-regulator.c index f8a6dfbef751..c2a9539acd72 100644 --- a/drivers/regulator/tps6507x-regulator.c +++ b/drivers/regulator/tps6507x-regulator.c | |||
| @@ -538,8 +538,8 @@ static struct regulator_ops tps6507x_ldo_ops = { | |||
| 538 | .list_voltage = tps6507x_ldo_list_voltage, | 538 | .list_voltage = tps6507x_ldo_list_voltage, |
| 539 | }; | 539 | }; |
| 540 | 540 | ||
| 541 | static | 541 | static int __devinit tps_6507x_probe(struct i2c_client *client, |
| 542 | int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) | 542 | const struct i2c_device_id *id) |
| 543 | { | 543 | { |
| 544 | static int desc_id; | 544 | static int desc_id; |
| 545 | const struct tps_info *info = (void *)id->driver_data; | 545 | const struct tps_info *info = (void *)id->driver_data; |
| @@ -547,6 +547,7 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 547 | struct regulator_dev *rdev; | 547 | struct regulator_dev *rdev; |
| 548 | struct tps_pmic *tps; | 548 | struct tps_pmic *tps; |
| 549 | int i; | 549 | int i; |
| 550 | int error; | ||
| 550 | 551 | ||
| 551 | if (!i2c_check_functionality(client->adapter, | 552 | if (!i2c_check_functionality(client->adapter, |
| 552 | I2C_FUNC_SMBUS_BYTE_DATA)) | 553 | I2C_FUNC_SMBUS_BYTE_DATA)) |
| @@ -557,7 +558,6 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 557 | * coming from the board-evm file. | 558 | * coming from the board-evm file. |
| 558 | */ | 559 | */ |
| 559 | init_data = client->dev.platform_data; | 560 | init_data = client->dev.platform_data; |
| 560 | |||
| 561 | if (!init_data) | 561 | if (!init_data) |
| 562 | return -EIO; | 562 | return -EIO; |
| 563 | 563 | ||
| @@ -586,18 +586,8 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 586 | if (IS_ERR(rdev)) { | 586 | if (IS_ERR(rdev)) { |
| 587 | dev_err(&client->dev, "failed to register %s\n", | 587 | dev_err(&client->dev, "failed to register %s\n", |
| 588 | id->name); | 588 | id->name); |
| 589 | 589 | error = PTR_ERR(rdev); | |
| 590 | /* Unregister */ | 590 | goto fail; |
| 591 | while (i) | ||
| 592 | regulator_unregister(tps->rdev[--i]); | ||
| 593 | |||
| 594 | tps->client = NULL; | ||
| 595 | |||
| 596 | /* clear the client data in i2c */ | ||
| 597 | i2c_set_clientdata(client, NULL); | ||
| 598 | |||
| 599 | kfree(tps); | ||
| 600 | return PTR_ERR(rdev); | ||
| 601 | } | 591 | } |
| 602 | 592 | ||
| 603 | /* Save regulator for cleanup */ | 593 | /* Save regulator for cleanup */ |
| @@ -607,6 +597,13 @@ int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) | |||
| 607 | i2c_set_clientdata(client, tps); | 597 | i2c_set_clientdata(client, tps); |
| 608 | 598 | ||
| 609 | return 0; | 599 | return 0; |
| 600 | |||
| 601 | fail: | ||
| 602 | while (--i >= 0) | ||
| 603 | regulator_unregister(tps->rdev[i]); | ||
| 604 | |||
| 605 | kfree(tps); | ||
| 606 | return error; | ||
| 610 | } | 607 | } |
| 611 | 608 | ||
| 612 | /** | 609 | /** |
| @@ -620,13 +617,12 @@ static int __devexit tps_6507x_remove(struct i2c_client *client) | |||
| 620 | struct tps_pmic *tps = i2c_get_clientdata(client); | 617 | struct tps_pmic *tps = i2c_get_clientdata(client); |
| 621 | int i; | 618 | int i; |
| 622 | 619 | ||
| 620 | /* clear the client data in i2c */ | ||
| 621 | i2c_set_clientdata(client, NULL); | ||
| 622 | |||
| 623 | for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) | 623 | for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) |
| 624 | regulator_unregister(tps->rdev[i]); | 624 | regulator_unregister(tps->rdev[i]); |
| 625 | 625 | ||
| 626 | tps->client = NULL; | ||
| 627 | |||
| 628 | /* clear the client data in i2c */ | ||
| 629 | i2c_set_clientdata(client, NULL); | ||
| 630 | kfree(tps); | 626 | kfree(tps); |
| 631 | 627 | ||
| 632 | return 0; | 628 | return 0; |
diff --git a/drivers/regulator/twl-regulator.c b/drivers/regulator/twl-regulator.c index 7e674859bd59..9729d760fb4d 100644 --- a/drivers/regulator/twl-regulator.c +++ b/drivers/regulator/twl-regulator.c | |||
| @@ -519,19 +519,19 @@ static struct twlreg_info twl_regs[] = { | |||
| 519 | /* 6030 REG with base as PMC Slave Misc : 0x0030 */ | 519 | /* 6030 REG with base as PMC Slave Misc : 0x0030 */ |
| 520 | /* Turnon-delay and remap configuration values for 6030 are not | 520 | /* Turnon-delay and remap configuration values for 6030 are not |
| 521 | verified since the specification is not public */ | 521 | verified since the specification is not public */ |
| 522 | TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1, 0, 0x08), | 522 | TWL6030_ADJUSTABLE_LDO(VAUX1_6030, 0x54, 1, 0, 0x21), |
| 523 | TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2, 0, 0x08), | 523 | TWL6030_ADJUSTABLE_LDO(VAUX2_6030, 0x58, 2, 0, 0x21), |
| 524 | TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3, 0, 0x08), | 524 | TWL6030_ADJUSTABLE_LDO(VAUX3_6030, 0x5c, 3, 0, 0x21), |
| 525 | TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4, 0, 0x08), | 525 | TWL6030_ADJUSTABLE_LDO(VMMC, 0x68, 4, 0, 0x21), |
| 526 | TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5, 0, 0x08), | 526 | TWL6030_ADJUSTABLE_LDO(VPP, 0x6c, 5, 0, 0x21), |
| 527 | TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7, 0, 0x08), | 527 | TWL6030_ADJUSTABLE_LDO(VUSIM, 0x74, 7, 0, 0x21), |
| 528 | TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x08), | 528 | TWL6030_FIXED_LDO(VANA, 0x50, 2100, 15, 0, 0x21), |
| 529 | TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x08), | 529 | TWL6030_FIXED_LDO(VCXIO, 0x60, 1800, 16, 0, 0x21), |
| 530 | TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x08), | 530 | TWL6030_FIXED_LDO(VDAC, 0x64, 1800, 17, 0, 0x21), |
| 531 | TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x08) | 531 | TWL6030_FIXED_LDO(VUSB, 0x70, 3300, 18, 0, 0x21) |
| 532 | }; | 532 | }; |
| 533 | 533 | ||
| 534 | static int twlreg_probe(struct platform_device *pdev) | 534 | static int __devinit twlreg_probe(struct platform_device *pdev) |
| 535 | { | 535 | { |
| 536 | int i; | 536 | int i; |
| 537 | struct twlreg_info *info; | 537 | struct twlreg_info *info; |
diff --git a/drivers/regulator/virtual.c b/drivers/regulator/virtual.c index addc032c84bf..d96cecaac73d 100644 --- a/drivers/regulator/virtual.c +++ b/drivers/regulator/virtual.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | struct virtual_consumer_data { | 19 | struct virtual_consumer_data { |
| 20 | struct mutex lock; | 20 | struct mutex lock; |
| 21 | struct regulator *regulator; | 21 | struct regulator *regulator; |
| 22 | int enabled; | 22 | bool enabled; |
| 23 | int min_uV; | 23 | int min_uV; |
| 24 | int max_uV; | 24 | int max_uV; |
| 25 | int min_uA; | 25 | int min_uA; |
| @@ -49,7 +49,7 @@ static void update_voltage_constraints(struct device *dev, | |||
| 49 | dev_dbg(dev, "Enabling regulator\n"); | 49 | dev_dbg(dev, "Enabling regulator\n"); |
| 50 | ret = regulator_enable(data->regulator); | 50 | ret = regulator_enable(data->regulator); |
| 51 | if (ret == 0) | 51 | if (ret == 0) |
| 52 | data->enabled = 1; | 52 | data->enabled = true; |
| 53 | else | 53 | else |
| 54 | dev_err(dev, "regulator_enable() failed: %d\n", | 54 | dev_err(dev, "regulator_enable() failed: %d\n", |
| 55 | ret); | 55 | ret); |
| @@ -59,7 +59,7 @@ static void update_voltage_constraints(struct device *dev, | |||
| 59 | dev_dbg(dev, "Disabling regulator\n"); | 59 | dev_dbg(dev, "Disabling regulator\n"); |
| 60 | ret = regulator_disable(data->regulator); | 60 | ret = regulator_disable(data->regulator); |
| 61 | if (ret == 0) | 61 | if (ret == 0) |
| 62 | data->enabled = 0; | 62 | data->enabled = false; |
| 63 | else | 63 | else |
| 64 | dev_err(dev, "regulator_disable() failed: %d\n", | 64 | dev_err(dev, "regulator_disable() failed: %d\n", |
| 65 | ret); | 65 | ret); |
| @@ -89,7 +89,7 @@ static void update_current_limit_constraints(struct device *dev, | |||
| 89 | dev_dbg(dev, "Enabling regulator\n"); | 89 | dev_dbg(dev, "Enabling regulator\n"); |
| 90 | ret = regulator_enable(data->regulator); | 90 | ret = regulator_enable(data->regulator); |
| 91 | if (ret == 0) | 91 | if (ret == 0) |
| 92 | data->enabled = 1; | 92 | data->enabled = true; |
| 93 | else | 93 | else |
| 94 | dev_err(dev, "regulator_enable() failed: %d\n", | 94 | dev_err(dev, "regulator_enable() failed: %d\n", |
| 95 | ret); | 95 | ret); |
| @@ -99,7 +99,7 @@ static void update_current_limit_constraints(struct device *dev, | |||
| 99 | dev_dbg(dev, "Disabling regulator\n"); | 99 | dev_dbg(dev, "Disabling regulator\n"); |
| 100 | ret = regulator_disable(data->regulator); | 100 | ret = regulator_disable(data->regulator); |
| 101 | if (ret == 0) | 101 | if (ret == 0) |
| 102 | data->enabled = 0; | 102 | data->enabled = false; |
| 103 | else | 103 | else |
| 104 | dev_err(dev, "regulator_disable() failed: %d\n", | 104 | dev_err(dev, "regulator_disable() failed: %d\n", |
| 105 | ret); | 105 | ret); |
| @@ -270,24 +270,28 @@ static DEVICE_ATTR(min_microamps, 0666, show_min_uA, set_min_uA); | |||
| 270 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); | 270 | static DEVICE_ATTR(max_microamps, 0666, show_max_uA, set_max_uA); |
| 271 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); | 271 | static DEVICE_ATTR(mode, 0666, show_mode, set_mode); |
| 272 | 272 | ||
| 273 | static struct device_attribute *attributes[] = { | 273 | static struct attribute *regulator_virtual_attributes[] = { |
| 274 | &dev_attr_min_microvolts, | 274 | &dev_attr_min_microvolts.attr, |
| 275 | &dev_attr_max_microvolts, | 275 | &dev_attr_max_microvolts.attr, |
| 276 | &dev_attr_min_microamps, | 276 | &dev_attr_min_microamps.attr, |
| 277 | &dev_attr_max_microamps, | 277 | &dev_attr_max_microamps.attr, |
| 278 | &dev_attr_mode, | 278 | &dev_attr_mode.attr, |
| 279 | NULL | ||
| 279 | }; | 280 | }; |
| 280 | 281 | ||
| 281 | static int regulator_virtual_consumer_probe(struct platform_device *pdev) | 282 | static const struct attribute_group regulator_virtual_attr_group = { |
| 283 | .attrs = regulator_virtual_attributes, | ||
| 284 | }; | ||
| 285 | |||
| 286 | static int __devinit regulator_virtual_probe(struct platform_device *pdev) | ||
| 282 | { | 287 | { |
| 283 | char *reg_id = pdev->dev.platform_data; | 288 | char *reg_id = pdev->dev.platform_data; |
| 284 | struct virtual_consumer_data *drvdata; | 289 | struct virtual_consumer_data *drvdata; |
| 285 | int ret, i; | 290 | int ret; |
| 286 | 291 | ||
| 287 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); | 292 | drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); |
| 288 | if (drvdata == NULL) { | 293 | if (drvdata == NULL) |
| 289 | return -ENOMEM; | 294 | return -ENOMEM; |
| 290 | } | ||
| 291 | 295 | ||
| 292 | mutex_init(&drvdata->lock); | 296 | mutex_init(&drvdata->lock); |
| 293 | 297 | ||
| @@ -299,13 +303,12 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev) | |||
| 299 | goto err; | 303 | goto err; |
| 300 | } | 304 | } |
| 301 | 305 | ||
| 302 | for (i = 0; i < ARRAY_SIZE(attributes); i++) { | 306 | ret = sysfs_create_group(&pdev->dev.kobj, |
| 303 | ret = device_create_file(&pdev->dev, attributes[i]); | 307 | ®ulator_virtual_attr_group); |
| 304 | if (ret != 0) { | 308 | if (ret != 0) { |
| 305 | dev_err(&pdev->dev, "Failed to create attr %d: %d\n", | 309 | dev_err(&pdev->dev, |
| 306 | i, ret); | 310 | "Failed to create attribute group: %d\n", ret); |
| 307 | goto err_regulator; | 311 | goto err_regulator; |
| 308 | } | ||
| 309 | } | 312 | } |
| 310 | 313 | ||
| 311 | drvdata->mode = regulator_get_mode(drvdata->regulator); | 314 | drvdata->mode = regulator_get_mode(drvdata->regulator); |
| @@ -317,37 +320,36 @@ static int regulator_virtual_consumer_probe(struct platform_device *pdev) | |||
| 317 | err_regulator: | 320 | err_regulator: |
| 318 | regulator_put(drvdata->regulator); | 321 | regulator_put(drvdata->regulator); |
| 319 | err: | 322 | err: |
| 320 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | ||
| 321 | device_remove_file(&pdev->dev, attributes[i]); | ||
| 322 | kfree(drvdata); | 323 | kfree(drvdata); |
| 323 | return ret; | 324 | return ret; |
| 324 | } | 325 | } |
| 325 | 326 | ||
| 326 | static int regulator_virtual_consumer_remove(struct platform_device *pdev) | 327 | static int __devexit regulator_virtual_remove(struct platform_device *pdev) |
| 327 | { | 328 | { |
| 328 | struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); | 329 | struct virtual_consumer_data *drvdata = platform_get_drvdata(pdev); |
| 329 | int i; | ||
| 330 | 330 | ||
| 331 | for (i = 0; i < ARRAY_SIZE(attributes); i++) | 331 | sysfs_remove_group(&pdev->dev.kobj, ®ulator_virtual_attr_group); |
| 332 | device_remove_file(&pdev->dev, attributes[i]); | 332 | |
| 333 | if (drvdata->enabled) | 333 | if (drvdata->enabled) |
| 334 | regulator_disable(drvdata->regulator); | 334 | regulator_disable(drvdata->regulator); |
| 335 | regulator_put(drvdata->regulator); | 335 | regulator_put(drvdata->regulator); |
| 336 | 336 | ||
| 337 | kfree(drvdata); | 337 | kfree(drvdata); |
| 338 | 338 | ||
| 339 | platform_set_drvdata(pdev, NULL); | ||
| 340 | |||
| 339 | return 0; | 341 | return 0; |
| 340 | } | 342 | } |
| 341 | 343 | ||
| 342 | static struct platform_driver regulator_virtual_consumer_driver = { | 344 | static struct platform_driver regulator_virtual_consumer_driver = { |
| 343 | .probe = regulator_virtual_consumer_probe, | 345 | .probe = regulator_virtual_probe, |
| 344 | .remove = regulator_virtual_consumer_remove, | 346 | .remove = __devexit_p(regulator_virtual_remove), |
| 345 | .driver = { | 347 | .driver = { |
| 346 | .name = "reg-virt-consumer", | 348 | .name = "reg-virt-consumer", |
| 349 | .owner = THIS_MODULE, | ||
| 347 | }, | 350 | }, |
| 348 | }; | 351 | }; |
| 349 | 352 | ||
| 350 | |||
| 351 | static int __init regulator_virtual_consumer_init(void) | 353 | static int __init regulator_virtual_consumer_init(void) |
| 352 | { | 354 | { |
| 353 | return platform_driver_register(®ulator_virtual_consumer_driver); | 355 | return platform_driver_register(®ulator_virtual_consumer_driver); |
diff --git a/drivers/regulator/wm831x-dcdc.c b/drivers/regulator/wm831x-dcdc.c index 0a6577577e8d..6e18e56d850b 100644 --- a/drivers/regulator/wm831x-dcdc.c +++ b/drivers/regulator/wm831x-dcdc.c | |||
| @@ -600,6 +600,8 @@ static __devexit int wm831x_buckv_remove(struct platform_device *pdev) | |||
| 600 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); | 600 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); |
| 601 | struct wm831x *wm831x = dcdc->wm831x; | 601 | struct wm831x *wm831x = dcdc->wm831x; |
| 602 | 602 | ||
| 603 | platform_set_drvdata(pdev, NULL); | ||
| 604 | |||
| 603 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "HC"), dcdc); | 605 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "HC"), dcdc); |
| 604 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); | 606 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); |
| 605 | regulator_unregister(dcdc->regulator); | 607 | regulator_unregister(dcdc->regulator); |
| @@ -615,6 +617,7 @@ static struct platform_driver wm831x_buckv_driver = { | |||
| 615 | .remove = __devexit_p(wm831x_buckv_remove), | 617 | .remove = __devexit_p(wm831x_buckv_remove), |
| 616 | .driver = { | 618 | .driver = { |
| 617 | .name = "wm831x-buckv", | 619 | .name = "wm831x-buckv", |
| 620 | .owner = THIS_MODULE, | ||
| 618 | }, | 621 | }, |
| 619 | }; | 622 | }; |
| 620 | 623 | ||
| @@ -769,6 +772,8 @@ static __devexit int wm831x_buckp_remove(struct platform_device *pdev) | |||
| 769 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); | 772 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); |
| 770 | struct wm831x *wm831x = dcdc->wm831x; | 773 | struct wm831x *wm831x = dcdc->wm831x; |
| 771 | 774 | ||
| 775 | platform_set_drvdata(pdev, NULL); | ||
| 776 | |||
| 772 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); | 777 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); |
| 773 | regulator_unregister(dcdc->regulator); | 778 | regulator_unregister(dcdc->regulator); |
| 774 | kfree(dcdc); | 779 | kfree(dcdc); |
| @@ -781,6 +786,7 @@ static struct platform_driver wm831x_buckp_driver = { | |||
| 781 | .remove = __devexit_p(wm831x_buckp_remove), | 786 | .remove = __devexit_p(wm831x_buckp_remove), |
| 782 | .driver = { | 787 | .driver = { |
| 783 | .name = "wm831x-buckp", | 788 | .name = "wm831x-buckp", |
| 789 | .owner = THIS_MODULE, | ||
| 784 | }, | 790 | }, |
| 785 | }; | 791 | }; |
| 786 | 792 | ||
| @@ -895,6 +901,8 @@ static __devexit int wm831x_boostp_remove(struct platform_device *pdev) | |||
| 895 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); | 901 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); |
| 896 | struct wm831x *wm831x = dcdc->wm831x; | 902 | struct wm831x *wm831x = dcdc->wm831x; |
| 897 | 903 | ||
| 904 | platform_set_drvdata(pdev, NULL); | ||
| 905 | |||
| 898 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); | 906 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), dcdc); |
| 899 | regulator_unregister(dcdc->regulator); | 907 | regulator_unregister(dcdc->regulator); |
| 900 | kfree(dcdc); | 908 | kfree(dcdc); |
| @@ -907,6 +915,7 @@ static struct platform_driver wm831x_boostp_driver = { | |||
| 907 | .remove = __devexit_p(wm831x_boostp_remove), | 915 | .remove = __devexit_p(wm831x_boostp_remove), |
| 908 | .driver = { | 916 | .driver = { |
| 909 | .name = "wm831x-boostp", | 917 | .name = "wm831x-boostp", |
| 918 | .owner = THIS_MODULE, | ||
| 910 | }, | 919 | }, |
| 911 | }; | 920 | }; |
| 912 | 921 | ||
| @@ -979,6 +988,8 @@ static __devexit int wm831x_epe_remove(struct platform_device *pdev) | |||
| 979 | { | 988 | { |
| 980 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); | 989 | struct wm831x_dcdc *dcdc = platform_get_drvdata(pdev); |
| 981 | 990 | ||
| 991 | platform_set_drvdata(pdev, NULL); | ||
| 992 | |||
| 982 | regulator_unregister(dcdc->regulator); | 993 | regulator_unregister(dcdc->regulator); |
| 983 | kfree(dcdc); | 994 | kfree(dcdc); |
| 984 | 995 | ||
| @@ -990,6 +1001,7 @@ static struct platform_driver wm831x_epe_driver = { | |||
| 990 | .remove = __devexit_p(wm831x_epe_remove), | 1001 | .remove = __devexit_p(wm831x_epe_remove), |
| 991 | .driver = { | 1002 | .driver = { |
| 992 | .name = "wm831x-epe", | 1003 | .name = "wm831x-epe", |
| 1004 | .owner = THIS_MODULE, | ||
| 993 | }, | 1005 | }, |
| 994 | }; | 1006 | }; |
| 995 | 1007 | ||
diff --git a/drivers/regulator/wm831x-isink.c b/drivers/regulator/wm831x-isink.c index 48857008758c..ca0f6b6c384b 100644 --- a/drivers/regulator/wm831x-isink.c +++ b/drivers/regulator/wm831x-isink.c | |||
| @@ -222,6 +222,8 @@ static __devexit int wm831x_isink_remove(struct platform_device *pdev) | |||
| 222 | struct wm831x_isink *isink = platform_get_drvdata(pdev); | 222 | struct wm831x_isink *isink = platform_get_drvdata(pdev); |
| 223 | struct wm831x *wm831x = isink->wm831x; | 223 | struct wm831x *wm831x = isink->wm831x; |
| 224 | 224 | ||
| 225 | platform_set_drvdata(pdev, NULL); | ||
| 226 | |||
| 225 | wm831x_free_irq(wm831x, platform_get_irq(pdev, 0), isink); | 227 | wm831x_free_irq(wm831x, platform_get_irq(pdev, 0), isink); |
| 226 | 228 | ||
| 227 | regulator_unregister(isink->regulator); | 229 | regulator_unregister(isink->regulator); |
| @@ -235,6 +237,7 @@ static struct platform_driver wm831x_isink_driver = { | |||
| 235 | .remove = __devexit_p(wm831x_isink_remove), | 237 | .remove = __devexit_p(wm831x_isink_remove), |
| 236 | .driver = { | 238 | .driver = { |
| 237 | .name = "wm831x-isink", | 239 | .name = "wm831x-isink", |
| 240 | .owner = THIS_MODULE, | ||
| 238 | }, | 241 | }, |
| 239 | }; | 242 | }; |
| 240 | 243 | ||
diff --git a/drivers/regulator/wm831x-ldo.c b/drivers/regulator/wm831x-ldo.c index 61e02ac2fda3..d2406c1519a1 100644 --- a/drivers/regulator/wm831x-ldo.c +++ b/drivers/regulator/wm831x-ldo.c | |||
| @@ -371,6 +371,8 @@ static __devexit int wm831x_gp_ldo_remove(struct platform_device *pdev) | |||
| 371 | struct wm831x_ldo *ldo = platform_get_drvdata(pdev); | 371 | struct wm831x_ldo *ldo = platform_get_drvdata(pdev); |
| 372 | struct wm831x *wm831x = ldo->wm831x; | 372 | struct wm831x *wm831x = ldo->wm831x; |
| 373 | 373 | ||
| 374 | platform_set_drvdata(pdev, NULL); | ||
| 375 | |||
| 374 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), ldo); | 376 | wm831x_free_irq(wm831x, platform_get_irq_byname(pdev, "UV"), ldo); |
| 375 | regulator_unregister(ldo->regulator); | 377 | regulator_unregister(ldo->regulator); |
| 376 | kfree(ldo); | 378 | kfree(ldo); |
| @@ -383,6 +385,7 @@ static struct platform_driver wm831x_gp_ldo_driver = { | |||
| 383 | .remove = __devexit_p(wm831x_gp_ldo_remove), | 385 | .remove = __devexit_p(wm831x_gp_ldo_remove), |
| 384 | .driver = { | 386 | .driver = { |
| 385 | .name = "wm831x-ldo", | 387 | .name = "wm831x-ldo", |
| 388 | .owner = THIS_MODULE, | ||
| 386 | }, | 389 | }, |
| 387 | }; | 390 | }; |
| 388 | 391 | ||
| @@ -640,6 +643,7 @@ static struct platform_driver wm831x_aldo_driver = { | |||
| 640 | .remove = __devexit_p(wm831x_aldo_remove), | 643 | .remove = __devexit_p(wm831x_aldo_remove), |
| 641 | .driver = { | 644 | .driver = { |
| 642 | .name = "wm831x-aldo", | 645 | .name = "wm831x-aldo", |
| 646 | .owner = THIS_MODULE, | ||
| 643 | }, | 647 | }, |
| 644 | }; | 648 | }; |
| 645 | 649 | ||
| @@ -811,6 +815,7 @@ static struct platform_driver wm831x_alive_ldo_driver = { | |||
| 811 | .remove = __devexit_p(wm831x_alive_ldo_remove), | 815 | .remove = __devexit_p(wm831x_alive_ldo_remove), |
| 812 | .driver = { | 816 | .driver = { |
| 813 | .name = "wm831x-alive-ldo", | 817 | .name = "wm831x-alive-ldo", |
| 818 | .owner = THIS_MODULE, | ||
| 814 | }, | 819 | }, |
| 815 | }; | 820 | }; |
| 816 | 821 | ||
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c index e7b89e704af6..94227dd6ba7b 100644 --- a/drivers/regulator/wm8350-regulator.c +++ b/drivers/regulator/wm8350-regulator.c | |||
| @@ -290,6 +290,51 @@ static int wm8350_isink_is_enabled(struct regulator_dev *rdev) | |||
| 290 | return -EINVAL; | 290 | return -EINVAL; |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | static int wm8350_isink_enable_time(struct regulator_dev *rdev) | ||
| 294 | { | ||
| 295 | struct wm8350 *wm8350 = rdev_get_drvdata(rdev); | ||
| 296 | int isink = rdev_get_id(rdev); | ||
| 297 | int reg; | ||
| 298 | |||
| 299 | switch (isink) { | ||
| 300 | case WM8350_ISINK_A: | ||
| 301 | reg = wm8350_reg_read(wm8350, WM8350_CSA_FLASH_CONTROL); | ||
| 302 | break; | ||
| 303 | case WM8350_ISINK_B: | ||
| 304 | reg = wm8350_reg_read(wm8350, WM8350_CSB_FLASH_CONTROL); | ||
| 305 | break; | ||
| 306 | default: | ||
| 307 | return -EINVAL; | ||
| 308 | } | ||
| 309 | |||
| 310 | if (reg & WM8350_CS1_FLASH_MODE) { | ||
| 311 | switch (reg & WM8350_CS1_ON_RAMP_MASK) { | ||
| 312 | case 0: | ||
| 313 | return 0; | ||
| 314 | case 1: | ||
| 315 | return 1950; | ||
| 316 | case 2: | ||
| 317 | return 3910; | ||
| 318 | case 3: | ||
| 319 | return 7800; | ||
| 320 | } | ||
| 321 | } else { | ||
| 322 | switch (reg & WM8350_CS1_ON_RAMP_MASK) { | ||
| 323 | case 0: | ||
| 324 | return 0; | ||
| 325 | case 1: | ||
| 326 | return 250000; | ||
| 327 | case 2: | ||
| 328 | return 500000; | ||
| 329 | case 3: | ||
| 330 | return 1000000; | ||
| 331 | } | ||
| 332 | } | ||
| 333 | |||
| 334 | return -EINVAL; | ||
| 335 | } | ||
| 336 | |||
| 337 | |||
| 293 | int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, | 338 | int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode, |
| 294 | u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp, | 339 | u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp, |
| 295 | u16 drive) | 340 | u16 drive) |
| @@ -1221,6 +1266,7 @@ static struct regulator_ops wm8350_isink_ops = { | |||
| 1221 | .enable = wm8350_isink_enable, | 1266 | .enable = wm8350_isink_enable, |
| 1222 | .disable = wm8350_isink_disable, | 1267 | .disable = wm8350_isink_disable, |
| 1223 | .is_enabled = wm8350_isink_is_enabled, | 1268 | .is_enabled = wm8350_isink_is_enabled, |
| 1269 | .enable_time = wm8350_isink_enable_time, | ||
| 1224 | }; | 1270 | }; |
| 1225 | 1271 | ||
| 1226 | static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { | 1272 | static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = { |
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c index d9a2c988c6e7..924c7eb29ee9 100644 --- a/drivers/regulator/wm8400-regulator.c +++ b/drivers/regulator/wm8400-regulator.c | |||
| @@ -317,14 +317,17 @@ static struct regulator_desc regulators[] = { | |||
| 317 | 317 | ||
| 318 | static int __devinit wm8400_regulator_probe(struct platform_device *pdev) | 318 | static int __devinit wm8400_regulator_probe(struct platform_device *pdev) |
| 319 | { | 319 | { |
| 320 | struct wm8400 *wm8400 = container_of(pdev, struct wm8400, regulators[pdev->id]); | ||
| 320 | struct regulator_dev *rdev; | 321 | struct regulator_dev *rdev; |
| 321 | 322 | ||
| 322 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, | 323 | rdev = regulator_register(®ulators[pdev->id], &pdev->dev, |
| 323 | pdev->dev.platform_data, dev_get_drvdata(&pdev->dev)); | 324 | pdev->dev.platform_data, wm8400); |
| 324 | 325 | ||
| 325 | if (IS_ERR(rdev)) | 326 | if (IS_ERR(rdev)) |
| 326 | return PTR_ERR(rdev); | 327 | return PTR_ERR(rdev); |
| 327 | 328 | ||
| 329 | platform_set_drvdata(pdev, rdev); | ||
| 330 | |||
| 328 | return 0; | 331 | return 0; |
| 329 | } | 332 | } |
| 330 | 333 | ||
| @@ -332,6 +335,7 @@ static int __devexit wm8400_regulator_remove(struct platform_device *pdev) | |||
| 332 | { | 335 | { |
| 333 | struct regulator_dev *rdev = platform_get_drvdata(pdev); | 336 | struct regulator_dev *rdev = platform_get_drvdata(pdev); |
| 334 | 337 | ||
| 338 | platform_set_drvdata(pdev, NULL); | ||
| 335 | regulator_unregister(rdev); | 339 | regulator_unregister(rdev); |
| 336 | 340 | ||
| 337 | return 0; | 341 | return 0; |
| @@ -370,7 +374,6 @@ int wm8400_register_regulator(struct device *dev, int reg, | |||
| 370 | wm8400->regulators[reg].id = reg; | 374 | wm8400->regulators[reg].id = reg; |
| 371 | wm8400->regulators[reg].dev.parent = dev; | 375 | wm8400->regulators[reg].dev.parent = dev; |
| 372 | wm8400->regulators[reg].dev.platform_data = initdata; | 376 | wm8400->regulators[reg].dev.platform_data = initdata; |
| 373 | dev_set_drvdata(&wm8400->regulators[reg].dev, wm8400); | ||
| 374 | 377 | ||
| 375 | return platform_device_register(&wm8400->regulators[reg]); | 378 | return platform_device_register(&wm8400->regulators[reg]); |
| 376 | } | 379 | } |
diff --git a/drivers/regulator/wm8994-regulator.c b/drivers/regulator/wm8994-regulator.c new file mode 100644 index 000000000000..95454a4637b7 --- /dev/null +++ b/drivers/regulator/wm8994-regulator.c | |||
| @@ -0,0 +1,307 @@ | |||
| 1 | /* | ||
| 2 | * wm8994-regulator.c -- Regulator driver for the WM8994 | ||
| 3 | * | ||
| 4 | * Copyright 2009 Wolfson Microelectronics PLC. | ||
| 5 | * | ||
| 6 | * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> | ||
| 7 | * | ||
| 8 | * This program is free software; you can redistribute it and/or modify it | ||
| 9 | * under the terms of the GNU General Public License as published by the | ||
| 10 | * Free Software Foundation; either version 2 of the License, or (at your | ||
| 11 | * option) any later version. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/moduleparam.h> | ||
| 16 | #include <linux/init.h> | ||
| 17 | #include <linux/bitops.h> | ||
| 18 | #include <linux/err.h> | ||
| 19 | #include <linux/platform_device.h> | ||
| 20 | #include <linux/regulator/driver.h> | ||
| 21 | #include <linux/gpio.h> | ||
| 22 | |||
| 23 | #include <linux/mfd/wm8994/core.h> | ||
| 24 | #include <linux/mfd/wm8994/registers.h> | ||
| 25 | #include <linux/mfd/wm8994/pdata.h> | ||
| 26 | |||
| 27 | struct wm8994_ldo { | ||
| 28 | int enable; | ||
| 29 | bool is_enabled; | ||
| 30 | struct regulator_dev *regulator; | ||
| 31 | struct wm8994 *wm8994; | ||
| 32 | }; | ||
| 33 | |||
| 34 | #define WM8994_LDO1_MAX_SELECTOR 0x7 | ||
| 35 | #define WM8994_LDO2_MAX_SELECTOR 0x3 | ||
| 36 | |||
| 37 | static int wm8994_ldo_enable(struct regulator_dev *rdev) | ||
| 38 | { | ||
| 39 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 40 | |||
| 41 | /* If we have no soft control assume that the LDO is always enabled. */ | ||
| 42 | if (!ldo->enable) | ||
| 43 | return 0; | ||
| 44 | |||
| 45 | gpio_set_value(ldo->enable, 1); | ||
| 46 | ldo->is_enabled = true; | ||
| 47 | |||
| 48 | return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | static int wm8994_ldo_disable(struct regulator_dev *rdev) | ||
| 52 | { | ||
| 53 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 54 | |||
| 55 | /* If we have no soft control assume that the LDO is always enabled. */ | ||
| 56 | if (!ldo->enable) | ||
| 57 | return -EINVAL; | ||
| 58 | |||
| 59 | gpio_set_value(ldo->enable, 0); | ||
| 60 | ldo->is_enabled = false; | ||
| 61 | |||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | static int wm8994_ldo_is_enabled(struct regulator_dev *rdev) | ||
| 66 | { | ||
| 67 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 68 | |||
| 69 | return ldo->is_enabled; | ||
| 70 | } | ||
| 71 | |||
| 72 | static int wm8994_ldo_enable_time(struct regulator_dev *rdev) | ||
| 73 | { | ||
| 74 | /* 3ms is fairly conservative but this shouldn't be too performance | ||
| 75 | * critical; can be tweaked per-system if required. */ | ||
| 76 | return 3000; | ||
| 77 | } | ||
| 78 | |||
| 79 | static int wm8994_ldo1_list_voltage(struct regulator_dev *rdev, | ||
| 80 | unsigned int selector) | ||
| 81 | { | ||
| 82 | if (selector > WM8994_LDO1_MAX_SELECTOR) | ||
| 83 | return -EINVAL; | ||
| 84 | |||
| 85 | return (selector * 100000) + 2400000; | ||
| 86 | } | ||
| 87 | |||
| 88 | static int wm8994_ldo1_get_voltage(struct regulator_dev *rdev) | ||
| 89 | { | ||
| 90 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 91 | int val; | ||
| 92 | |||
| 93 | val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_1); | ||
| 94 | if (val < 0) | ||
| 95 | return val; | ||
| 96 | |||
| 97 | val = (val & WM8994_LDO1_VSEL_MASK) >> WM8994_LDO1_VSEL_SHIFT; | ||
| 98 | |||
| 99 | return wm8994_ldo1_list_voltage(rdev, val); | ||
| 100 | } | ||
| 101 | |||
| 102 | static int wm8994_ldo1_set_voltage(struct regulator_dev *rdev, | ||
| 103 | int min_uV, int max_uV) | ||
| 104 | { | ||
| 105 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 106 | int selector, v; | ||
| 107 | |||
| 108 | selector = (min_uV - 2400000) / 100000; | ||
| 109 | v = wm8994_ldo1_list_voltage(rdev, selector); | ||
| 110 | if (v < 0 || v > max_uV) | ||
| 111 | return -EINVAL; | ||
| 112 | |||
| 113 | selector <<= WM8994_LDO1_VSEL_SHIFT; | ||
| 114 | |||
| 115 | return wm8994_set_bits(ldo->wm8994, WM8994_LDO_1, | ||
| 116 | WM8994_LDO1_VSEL_MASK, selector); | ||
| 117 | } | ||
| 118 | |||
| 119 | static struct regulator_ops wm8994_ldo1_ops = { | ||
| 120 | .enable = wm8994_ldo_enable, | ||
| 121 | .disable = wm8994_ldo_disable, | ||
| 122 | .is_enabled = wm8994_ldo_is_enabled, | ||
| 123 | .enable_time = wm8994_ldo_enable_time, | ||
| 124 | |||
| 125 | .list_voltage = wm8994_ldo1_list_voltage, | ||
| 126 | .get_voltage = wm8994_ldo1_get_voltage, | ||
| 127 | .set_voltage = wm8994_ldo1_set_voltage, | ||
| 128 | }; | ||
| 129 | |||
| 130 | static int wm8994_ldo2_list_voltage(struct regulator_dev *rdev, | ||
| 131 | unsigned int selector) | ||
| 132 | { | ||
| 133 | if (selector > WM8994_LDO2_MAX_SELECTOR) | ||
| 134 | return -EINVAL; | ||
| 135 | |||
| 136 | return (selector * 100000) + 900000; | ||
| 137 | } | ||
| 138 | |||
| 139 | static int wm8994_ldo2_get_voltage(struct regulator_dev *rdev) | ||
| 140 | { | ||
| 141 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 142 | int val; | ||
| 143 | |||
| 144 | val = wm8994_reg_read(ldo->wm8994, WM8994_LDO_2); | ||
| 145 | if (val < 0) | ||
| 146 | return val; | ||
| 147 | |||
| 148 | val = (val & WM8994_LDO2_VSEL_MASK) >> WM8994_LDO2_VSEL_SHIFT; | ||
| 149 | |||
| 150 | return wm8994_ldo2_list_voltage(rdev, val); | ||
| 151 | } | ||
| 152 | |||
| 153 | static int wm8994_ldo2_set_voltage(struct regulator_dev *rdev, | ||
| 154 | int min_uV, int max_uV) | ||
| 155 | { | ||
| 156 | struct wm8994_ldo *ldo = rdev_get_drvdata(rdev); | ||
| 157 | int selector, v; | ||
| 158 | |||
| 159 | selector = (min_uV - 900000) / 100000; | ||
| 160 | v = wm8994_ldo2_list_voltage(rdev, selector); | ||
| 161 | if (v < 0 || v > max_uV) | ||
| 162 | return -EINVAL; | ||
| 163 | |||
| 164 | selector <<= WM8994_LDO2_VSEL_SHIFT; | ||
| 165 | |||
| 166 | return wm8994_set_bits(ldo->wm8994, WM8994_LDO_2, | ||
| 167 | WM8994_LDO2_VSEL_MASK, selector); | ||
| 168 | } | ||
| 169 | |||
| 170 | static struct regulator_ops wm8994_ldo2_ops = { | ||
| 171 | .enable = wm8994_ldo_enable, | ||
| 172 | .disable = wm8994_ldo_disable, | ||
| 173 | .is_enabled = wm8994_ldo_is_enabled, | ||
| 174 | .enable_time = wm8994_ldo_enable_time, | ||
| 175 | |||
| 176 | .list_voltage = wm8994_ldo2_list_voltage, | ||
| 177 | .get_voltage = wm8994_ldo2_get_voltage, | ||
| 178 | .set_voltage = wm8994_ldo2_set_voltage, | ||
| 179 | }; | ||
| 180 | |||
| 181 | static struct regulator_desc wm8994_ldo_desc[] = { | ||
| 182 | { | ||
| 183 | .name = "LDO1", | ||
| 184 | .id = 1, | ||
| 185 | .type = REGULATOR_VOLTAGE, | ||
| 186 | .n_voltages = WM8994_LDO1_MAX_SELECTOR + 1, | ||
| 187 | .ops = &wm8994_ldo1_ops, | ||
| 188 | .owner = THIS_MODULE, | ||
| 189 | }, | ||
| 190 | { | ||
| 191 | .name = "LDO2", | ||
| 192 | .id = 2, | ||
| 193 | .type = REGULATOR_VOLTAGE, | ||
| 194 | .n_voltages = WM8994_LDO2_MAX_SELECTOR + 1, | ||
| 195 | .ops = &wm8994_ldo2_ops, | ||
| 196 | .owner = THIS_MODULE, | ||
| 197 | }, | ||
| 198 | }; | ||
| 199 | |||
| 200 | static __devinit int wm8994_ldo_probe(struct platform_device *pdev) | ||
| 201 | { | ||
| 202 | struct wm8994 *wm8994 = dev_get_drvdata(pdev->dev.parent); | ||
| 203 | struct wm8994_pdata *pdata = wm8994->dev->platform_data; | ||
| 204 | int id = pdev->id % ARRAY_SIZE(pdata->ldo); | ||
| 205 | struct wm8994_ldo *ldo; | ||
| 206 | int ret; | ||
| 207 | |||
| 208 | dev_dbg(&pdev->dev, "Probing LDO%d\n", id + 1); | ||
| 209 | |||
| 210 | if (!pdata) | ||
| 211 | return -ENODEV; | ||
| 212 | |||
| 213 | ldo = kzalloc(sizeof(struct wm8994_ldo), GFP_KERNEL); | ||
| 214 | if (ldo == NULL) { | ||
| 215 | dev_err(&pdev->dev, "Unable to allocate private data\n"); | ||
| 216 | return -ENOMEM; | ||
| 217 | } | ||
| 218 | |||
| 219 | ldo->wm8994 = wm8994; | ||
| 220 | |||
| 221 | ldo->is_enabled = true; | ||
| 222 | |||
| 223 | if (pdata->ldo[id].enable && gpio_is_valid(pdata->ldo[id].enable)) { | ||
| 224 | ldo->enable = pdata->ldo[id].enable; | ||
| 225 | |||
| 226 | ret = gpio_request(ldo->enable, "WM8994 LDO enable"); | ||
| 227 | if (ret < 0) { | ||
| 228 | dev_err(&pdev->dev, "Failed to get enable GPIO: %d\n", | ||
| 229 | ret); | ||
| 230 | goto err; | ||
| 231 | } | ||
| 232 | |||
| 233 | ret = gpio_direction_output(ldo->enable, ldo->is_enabled); | ||
| 234 | if (ret < 0) { | ||
| 235 | dev_err(&pdev->dev, "Failed to set GPIO up: %d\n", | ||
| 236 | ret); | ||
| 237 | goto err_gpio; | ||
| 238 | } | ||
| 239 | } | ||
| 240 | |||
| 241 | ldo->regulator = regulator_register(&wm8994_ldo_desc[id], &pdev->dev, | ||
| 242 | pdata->ldo[id].init_data, ldo); | ||
| 243 | if (IS_ERR(ldo->regulator)) { | ||
| 244 | ret = PTR_ERR(ldo->regulator); | ||
| 245 | dev_err(wm8994->dev, "Failed to register LDO%d: %d\n", | ||
| 246 | id + 1, ret); | ||
| 247 | goto err_gpio; | ||
| 248 | } | ||
| 249 | |||
| 250 | platform_set_drvdata(pdev, ldo); | ||
| 251 | |||
| 252 | return 0; | ||
| 253 | |||
| 254 | err_gpio: | ||
| 255 | if (gpio_is_valid(ldo->enable)) | ||
| 256 | gpio_free(ldo->enable); | ||
| 257 | err: | ||
| 258 | kfree(ldo); | ||
| 259 | return ret; | ||
| 260 | } | ||
| 261 | |||
| 262 | static __devexit int wm8994_ldo_remove(struct platform_device *pdev) | ||
| 263 | { | ||
| 264 | struct wm8994_ldo *ldo = platform_get_drvdata(pdev); | ||
| 265 | |||
| 266 | platform_set_drvdata(pdev, NULL); | ||
| 267 | |||
| 268 | regulator_unregister(ldo->regulator); | ||
| 269 | if (gpio_is_valid(ldo->enable)) | ||
| 270 | gpio_free(ldo->enable); | ||
| 271 | kfree(ldo); | ||
| 272 | |||
| 273 | return 0; | ||
| 274 | } | ||
| 275 | |||
| 276 | static struct platform_driver wm8994_ldo_driver = { | ||
| 277 | .probe = wm8994_ldo_probe, | ||
| 278 | .remove = __devexit_p(wm8994_ldo_remove), | ||
| 279 | .driver = { | ||
| 280 | .name = "wm8994-ldo", | ||
| 281 | .owner = THIS_MODULE, | ||
| 282 | }, | ||
| 283 | }; | ||
| 284 | |||
| 285 | static int __init wm8994_ldo_init(void) | ||
| 286 | { | ||
| 287 | int ret; | ||
| 288 | |||
| 289 | ret = platform_driver_register(&wm8994_ldo_driver); | ||
| 290 | if (ret != 0) | ||
| 291 | pr_err("Failed to register Wm8994 GP LDO driver: %d\n", ret); | ||
| 292 | |||
| 293 | return ret; | ||
| 294 | } | ||
| 295 | subsys_initcall(wm8994_ldo_init); | ||
| 296 | |||
| 297 | static void __exit wm8994_ldo_exit(void) | ||
| 298 | { | ||
| 299 | platform_driver_unregister(&wm8994_ldo_driver); | ||
| 300 | } | ||
| 301 | module_exit(wm8994_ldo_exit); | ||
| 302 | |||
| 303 | /* Module information */ | ||
| 304 | MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>"); | ||
| 305 | MODULE_DESCRIPTION("WM8994 LDO driver"); | ||
| 306 | MODULE_LICENSE("GPL"); | ||
| 307 | MODULE_ALIAS("platform:wm8994-ldo"); | ||
diff --git a/include/linux/mfd/mc13783.h b/include/linux/mfd/mc13783.h index 35680409b8cf..94cb51a64037 100644 --- a/include/linux/mfd/mc13783.h +++ b/include/linux/mfd/mc13783.h | |||
| @@ -108,6 +108,8 @@ int mc13783_adc_do_conversion(struct mc13783 *mc13783, unsigned int mode, | |||
| 108 | #define MC13783_REGU_V2 28 | 108 | #define MC13783_REGU_V2 28 |
| 109 | #define MC13783_REGU_V3 29 | 109 | #define MC13783_REGU_V3 29 |
| 110 | #define MC13783_REGU_V4 30 | 110 | #define MC13783_REGU_V4 30 |
| 111 | #define MC13783_REGU_PWGT1SPI 31 | ||
| 112 | #define MC13783_REGU_PWGT2SPI 32 | ||
| 111 | 113 | ||
| 112 | #define MC13783_IRQ_ADCDONE 0 | 114 | #define MC13783_IRQ_ADCDONE 0 |
| 113 | #define MC13783_IRQ_ADCBISDONE 1 | 115 | #define MC13783_IRQ_ADCBISDONE 1 |
diff --git a/include/linux/regulator/consumer.h b/include/linux/regulator/consumer.h index 030d92255c7a..28c9fd020d39 100644 --- a/include/linux/regulator/consumer.h +++ b/include/linux/regulator/consumer.h | |||
| @@ -89,8 +89,9 @@ | |||
| 89 | * REGULATION_OUT Regulator output is out of regulation. | 89 | * REGULATION_OUT Regulator output is out of regulation. |
| 90 | * FAIL Regulator output has failed. | 90 | * FAIL Regulator output has failed. |
| 91 | * OVER_TEMP Regulator over temp. | 91 | * OVER_TEMP Regulator over temp. |
| 92 | * FORCE_DISABLE Regulator shut down by software. | 92 | * FORCE_DISABLE Regulator forcibly shut down by software. |
| 93 | * VOLTAGE_CHANGE Regulator voltage changed. | 93 | * VOLTAGE_CHANGE Regulator voltage changed. |
| 94 | * DISABLE Regulator was disabled. | ||
| 94 | * | 95 | * |
| 95 | * NOTE: These events can be OR'ed together when passed into handler. | 96 | * NOTE: These events can be OR'ed together when passed into handler. |
| 96 | */ | 97 | */ |
| @@ -102,6 +103,7 @@ | |||
| 102 | #define REGULATOR_EVENT_OVER_TEMP 0x10 | 103 | #define REGULATOR_EVENT_OVER_TEMP 0x10 |
| 103 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 | 104 | #define REGULATOR_EVENT_FORCE_DISABLE 0x20 |
| 104 | #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 | 105 | #define REGULATOR_EVENT_VOLTAGE_CHANGE 0x40 |
| 106 | #define REGULATOR_EVENT_DISABLE 0x80 | ||
| 105 | 107 | ||
| 106 | struct regulator; | 108 | struct regulator; |
| 107 | 109 | ||
diff --git a/include/linux/regulator/driver.h b/include/linux/regulator/driver.h index 31f2055eae28..592cd7c642c2 100644 --- a/include/linux/regulator/driver.h +++ b/include/linux/regulator/driver.h | |||
| @@ -58,6 +58,9 @@ enum regulator_status { | |||
| 58 | * @get_optimum_mode: Get the most efficient operating mode for the regulator | 58 | * @get_optimum_mode: Get the most efficient operating mode for the regulator |
| 59 | * when running with the specified parameters. | 59 | * when running with the specified parameters. |
| 60 | * | 60 | * |
| 61 | * @enable_time: Time taken for the regulator voltage output voltage to | ||
| 62 | * stabalise after being enabled, in microseconds. | ||
| 63 | * | ||
| 61 | * @set_suspend_voltage: Set the voltage for the regulator when the system | 64 | * @set_suspend_voltage: Set the voltage for the regulator when the system |
| 62 | * is suspended. | 65 | * is suspended. |
| 63 | * @set_suspend_enable: Mark the regulator as enabled when the system is | 66 | * @set_suspend_enable: Mark the regulator as enabled when the system is |
| @@ -93,6 +96,9 @@ struct regulator_ops { | |||
| 93 | int (*set_mode) (struct regulator_dev *, unsigned int mode); | 96 | int (*set_mode) (struct regulator_dev *, unsigned int mode); |
| 94 | unsigned int (*get_mode) (struct regulator_dev *); | 97 | unsigned int (*get_mode) (struct regulator_dev *); |
| 95 | 98 | ||
| 99 | /* Time taken to enable the regulator */ | ||
| 100 | int (*enable_time) (struct regulator_dev *); | ||
| 101 | |||
| 96 | /* report regulator status ... most other accessors report | 102 | /* report regulator status ... most other accessors report |
| 97 | * control inputs, this reports results of combining inputs | 103 | * control inputs, this reports results of combining inputs |
| 98 | * from Linux (and other sources) with the actual load. | 104 | * from Linux (and other sources) with the actual load. |
diff --git a/include/linux/regulator/fixed.h b/include/linux/regulator/fixed.h index e94a4a1c7c8a..ffd7d508e726 100644 --- a/include/linux/regulator/fixed.h +++ b/include/linux/regulator/fixed.h | |||
| @@ -25,6 +25,7 @@ struct regulator_init_data; | |||
| 25 | * @microvolts: Output voltage of regulator | 25 | * @microvolts: Output voltage of regulator |
| 26 | * @gpio: GPIO to use for enable control | 26 | * @gpio: GPIO to use for enable control |
| 27 | * set to -EINVAL if not used | 27 | * set to -EINVAL if not used |
| 28 | * @startup_delay: Start-up time in microseconds | ||
| 28 | * @enable_high: Polarity of enable GPIO | 29 | * @enable_high: Polarity of enable GPIO |
| 29 | * 1 = Active high, 0 = Active low | 30 | * 1 = Active high, 0 = Active low |
| 30 | * @enabled_at_boot: Whether regulator has been enabled at | 31 | * @enabled_at_boot: Whether regulator has been enabled at |
| @@ -41,6 +42,7 @@ struct fixed_voltage_config { | |||
| 41 | const char *supply_name; | 42 | const char *supply_name; |
| 42 | int microvolts; | 43 | int microvolts; |
| 43 | int gpio; | 44 | int gpio; |
| 45 | unsigned startup_delay; | ||
| 44 | unsigned enable_high:1; | 46 | unsigned enable_high:1; |
| 45 | unsigned enabled_at_boot:1; | 47 | unsigned enabled_at_boot:1; |
| 46 | struct regulator_init_data *init_data; | 48 | struct regulator_init_data *init_data; |
diff --git a/include/linux/regulator/max8649.h b/include/linux/regulator/max8649.h new file mode 100644 index 000000000000..417d14ecd5cb --- /dev/null +++ b/include/linux/regulator/max8649.h | |||
| @@ -0,0 +1,44 @@ | |||
| 1 | /* | ||
| 2 | * Interface of Maxim max8649 | ||
| 3 | * | ||
| 4 | * Copyright (C) 2009-2010 Marvell International Ltd. | ||
| 5 | * Haojian Zhuang <haojian.zhuang@marvell.com> | ||
| 6 | * | ||
| 7 | * This program is free software; you can redistribute it and/or modify | ||
| 8 | * it under the terms of the GNU General Public License version 2 as | ||
| 9 | * published by the Free Software Foundation. | ||
| 10 | */ | ||
| 11 | |||
| 12 | #ifndef __LINUX_REGULATOR_MAX8649_H | ||
| 13 | #define __LINUX_REGULATOR_MAX8649_H | ||
| 14 | |||
| 15 | #include <linux/regulator/machine.h> | ||
| 16 | |||
| 17 | enum { | ||
| 18 | MAX8649_EXTCLK_26MHZ = 0, | ||
| 19 | MAX8649_EXTCLK_13MHZ, | ||
| 20 | MAX8649_EXTCLK_19MHZ, /* 19.2MHz */ | ||
| 21 | }; | ||
| 22 | |||
| 23 | enum { | ||
| 24 | MAX8649_RAMP_32MV = 0, | ||
| 25 | MAX8649_RAMP_16MV, | ||
| 26 | MAX8649_RAMP_8MV, | ||
| 27 | MAX8649_RAMP_4MV, | ||
| 28 | MAX8649_RAMP_2MV, | ||
| 29 | MAX8649_RAMP_1MV, | ||
| 30 | MAX8649_RAMP_0_5MV, | ||
| 31 | MAX8649_RAMP_0_25MV, | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct max8649_platform_data { | ||
| 35 | struct regulator_init_data *regulator; | ||
| 36 | |||
| 37 | unsigned mode:2; /* bit[1:0] = VID1,VID0 */ | ||
| 38 | unsigned extclk_freq:2; | ||
| 39 | unsigned extclk:1; | ||
| 40 | unsigned ramp_timing:3; | ||
| 41 | unsigned ramp_down:1; | ||
| 42 | }; | ||
| 43 | |||
| 44 | #endif /* __LINUX_REGULATOR_MAX8649_H */ | ||
