Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6

* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6: (41 commits)
regulator: Add some brief design documentation
regulator: fix voltage range in da9034 ldo12
regulator/driver: be more specific in nanodoc for is_enabled
regulator/lp3971: drop unnecessary initialization
regulator: drop 'default n'
regulator: fix typos
regulator: fix calculation of voltage range in da9034_set_ldo12_voltage()
regulator: update a filename in documentation
drivers/regulator/Kconfig: fix typo (s/Usersapce/Userspace/) in REGULATOR_USERSPACE_CONSUMER description
REGULATOR Handle positive returncode from enable
regulator: tps650xx - build fixes for x86_64
Fix some regulator documentation
Regulator: Adding TPS65023 and TPS6507x in Kconfig and Makefile
Regulator: Add TPS6507x regulator driver
Regulator: Add TPS65023 regulator driver
regulator: userspace: use sysfs_create_group
regulator: Add GPIO enable control to fixed voltage regulator driver
Regulator: Implement list_voltage for pcf50633 regulator driver.
regulator: regulator_enable() permission checking
regulator: Push locking for regulator_is_enabled() out
...

+1982 -192
+33
Documentation/power/regulator/design.txt
··· 1 + Regulator API design notes 2 + ========================== 3 + 4 + This document provides a brief, partially structured, overview of some 5 + of the design considerations which impact the regulator API design. 6 + 7 + Safety 8 + ------ 9 + 10 + - Errors in regulator configuration can have very serious consequences 11 + for the system, potentially including lasting hardware damage. 12 + - It is not possible to automatically determine the power confugration 13 + of the system - software-equivalent variants of the same chip may 14 + have different power requirments, and not all components with power 15 + requirements are visible to software. 16 + 17 + => The API should make no changes to the hardware state unless it has 18 + specific knowledge that these changes are safe to do perform on 19 + this particular system. 20 + 21 + Consumer use cases 22 + ------------------ 23 + 24 + - The overwhelming majority of devices in a system will have no 25 + requirement to do any runtime configuration of their power beyond 26 + being able to turn it on or off. 27 + 28 + - Many of the power supplies in the system will be shared between many 29 + different consumers. 30 + 31 + => The consumer API should be structured so that these use cases are 32 + very easy to handle and so that consumers will work with shared 33 + supplies without any additional effort.
+2 -2
Documentation/power/regulator/machine.txt
··· 87 87 }, 88 88 }; 89 89 /* register regulator 1 device */ 90 - platform_device_register(&wm8350_regulator_devices[0]); 90 + platform_device_register(&regulator_devices[0]); 91 91 92 92 /* register regulator 2 device */ 93 - platform_device_register(&wm8350_regulator_devices[1]); 93 + platform_device_register(&regulator_devices[1]);
+2 -2
Documentation/power/regulator/overview.txt
··· 29 29 30 30 31 31 o PMIC - Power Management IC. An IC that contains numerous regulators 32 - and often contains other susbsystems. 32 + and often contains other subsystems. 33 33 34 34 35 35 o Consumer - Electronic device that is supplied power by a regulator. ··· 168 168 userspace via sysfs. This could be used to help monitor device power 169 169 consumption and status. 170 170 171 - See Documentation/ABI/testing/regulator-sysfs.txt 171 + See Documentation/ABI/testing/sysfs-class-regulator
+3 -2
Documentation/power/regulator/regulator.txt
··· 10 10 11 11 Drivers can register a regulator by calling :- 12 12 13 - struct regulator_dev *regulator_register(struct device *dev, 14 - struct regulator_desc *regulator_desc); 13 + struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc, 14 + struct device *dev, struct regulator_init_data *init_data, 15 + void *driver_data); 15 16 16 17 This will register the regulators capabilities and operations to the regulator 17 18 core.
+17 -7
drivers/regulator/Kconfig
··· 1 1 menuconfig REGULATOR 2 2 bool "Voltage and Current Regulator Support" 3 - default n 4 3 help 5 4 Generic Voltage and Current Regulator support. 6 5 ··· 29 30 30 31 config REGULATOR_FIXED_VOLTAGE 31 32 tristate "Fixed voltage regulator support" 32 - default n 33 33 help 34 34 This driver provides support for fixed voltage regulators, 35 35 useful for systems which use a combination of software ··· 36 38 37 39 config REGULATOR_VIRTUAL_CONSUMER 38 40 tristate "Virtual regulator consumer support" 39 - default n 40 41 help 41 42 This driver provides a virtual consumer for the voltage and 42 43 current regulator API which provides sysfs controls for ··· 46 49 47 50 config REGULATOR_USERSPACE_CONSUMER 48 51 tristate "Userspace regulator consumer support" 49 - default n 50 52 help 51 53 There are some classes of devices that are controlled entirely 52 - from user space. Usersapce consumer driver provides ability to 54 + from user space. Userspace consumer driver provides ability to 53 55 control power supplies for such devices. 54 56 55 57 If unsure, say no. 56 58 57 59 config REGULATOR_BQ24022 58 60 tristate "TI bq24022 Dual Input 1-Cell Li-Ion Charger IC" 59 - default n 60 61 help 61 62 This driver controls a TI bq24022 Charger attached via 62 63 GPIOs. The provided current regulator can enable/disable ··· 64 69 config REGULATOR_MAX1586 65 70 tristate "Maxim 1586/1587 voltage regulator" 66 71 depends on I2C 67 - default n 68 72 help 69 73 This driver controls a Maxim 1586 or 1587 voltage output 70 74 regulator via I2C bus. The provided regulator is suitable ··· 140 146 These regulators correspond to functionality in the 141 147 AB3100 analog baseband dealing with power regulators 142 148 for the system. 149 + 150 + config REGULATOR_TPS65023 151 + tristate "TI TPS65023 Power regulators" 152 + depends on I2C 153 + help 154 + This driver supports TPS65023 voltage regulator chips. TPS65023 provides 155 + three step-down converters and two general-purpose LDO voltage regulators. 156 + It supports TI's software based Class-2 SmartReflex implementation. 157 + 158 + config REGULATOR_TPS6507X 159 + tristate "TI TPS6507X Power regulators" 160 + depends on I2C 161 + help 162 + This driver supports TPS6507X voltage regulator chips. TPS6507X provides 163 + three step-down converters and two general-purpose LDO voltage regulators. 164 + It supports TI's software based Class-2 SmartReflex implementation. 143 165 144 166 endif 145 167
+3
drivers/regulator/Makefile
··· 23 23 obj-$(CONFIG_REGULATOR_MC13783) += mc13783.o 24 24 obj-$(CONFIG_REGULATOR_AB3100) += ab3100.o 25 25 26 + obj-$(CONFIG_REGULATOR_TPS65023) += tps65023-regulator.o 27 + obj-$(CONFIG_REGULATOR_TPS6507X) += tps6507x-regulator.o 28 + 26 29 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
+234 -83
drivers/regulator/core.c
··· 37 37 */ 38 38 struct regulator_map { 39 39 struct list_head list; 40 - struct device *dev; 40 + const char *dev_name; /* The dev_name() for the consumer */ 41 41 const char *supply; 42 42 struct regulator_dev *regulator; 43 43 }; ··· 232 232 struct regulator_dev *rdev = dev_get_drvdata(dev); 233 233 const char *name; 234 234 235 - if (rdev->constraints->name) 235 + if (rdev->constraints && rdev->constraints->name) 236 236 name = rdev->constraints->name; 237 237 else if (rdev->desc->name) 238 238 name = rdev->desc->name; ··· 280 280 struct device_attribute *attr, char *buf) 281 281 { 282 282 struct regulator_dev *rdev = dev_get_drvdata(dev); 283 + ssize_t ret; 283 284 284 - return regulator_print_state(buf, _regulator_is_enabled(rdev)); 285 + mutex_lock(&rdev->mutex); 286 + ret = regulator_print_state(buf, _regulator_is_enabled(rdev)); 287 + mutex_unlock(&rdev->mutex); 288 + 289 + return ret; 285 290 } 286 291 static DEVICE_ATTR(state, 0444, regulator_state_show, NULL); 287 292 ··· 862 857 * set_consumer_device_supply: Bind a regulator to a symbolic supply 863 858 * @rdev: regulator source 864 859 * @consumer_dev: device the supply applies to 860 + * @consumer_dev_name: dev_name() string for device supply applies to 865 861 * @supply: symbolic name for supply 866 862 * 867 863 * Allows platform initialisation code to map physical regulator 868 864 * sources to symbolic names for supplies for use by devices. Devices 869 865 * should use these symbolic names to request regulators, avoiding the 870 866 * need to provide board-specific regulator names as platform data. 867 + * 868 + * Only one of consumer_dev and consumer_dev_name may be specified. 871 869 */ 872 870 static int set_consumer_device_supply(struct regulator_dev *rdev, 873 - struct device *consumer_dev, const char *supply) 871 + struct device *consumer_dev, const char *consumer_dev_name, 872 + const char *supply) 874 873 { 875 874 struct regulator_map *node; 875 + int has_dev; 876 + 877 + if (consumer_dev && consumer_dev_name) 878 + return -EINVAL; 879 + 880 + if (!consumer_dev_name && consumer_dev) 881 + consumer_dev_name = dev_name(consumer_dev); 876 882 877 883 if (supply == NULL) 878 884 return -EINVAL; 879 885 886 + if (consumer_dev_name != NULL) 887 + has_dev = 1; 888 + else 889 + has_dev = 0; 890 + 880 891 list_for_each_entry(node, &regulator_map_list, list) { 881 - if (consumer_dev != node->dev) 892 + if (consumer_dev_name != node->dev_name) 882 893 continue; 883 894 if (strcmp(node->supply, supply) != 0) 884 895 continue; ··· 907 886 return -EBUSY; 908 887 } 909 888 910 - node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL); 889 + node = kzalloc(sizeof(struct regulator_map), GFP_KERNEL); 911 890 if (node == NULL) 912 891 return -ENOMEM; 913 892 914 893 node->regulator = rdev; 915 - node->dev = consumer_dev; 916 894 node->supply = supply; 895 + 896 + if (has_dev) { 897 + node->dev_name = kstrdup(consumer_dev_name, GFP_KERNEL); 898 + if (node->dev_name == NULL) { 899 + kfree(node); 900 + return -ENOMEM; 901 + } 902 + } 917 903 918 904 list_add(&node->list, &regulator_map_list); 919 905 return 0; 920 906 } 921 907 922 908 static void unset_consumer_device_supply(struct regulator_dev *rdev, 923 - struct device *consumer_dev) 909 + const char *consumer_dev_name, struct device *consumer_dev) 924 910 { 925 911 struct regulator_map *node, *n; 926 912 913 + if (consumer_dev && !consumer_dev_name) 914 + consumer_dev_name = dev_name(consumer_dev); 915 + 927 916 list_for_each_entry_safe(node, n, &regulator_map_list, list) { 928 - if (rdev == node->regulator && 929 - consumer_dev == node->dev) { 930 - list_del(&node->list); 931 - kfree(node); 932 - return; 933 - } 917 + if (rdev != node->regulator) 918 + continue; 919 + 920 + if (consumer_dev_name && node->dev_name && 921 + strcmp(consumer_dev_name, node->dev_name)) 922 + continue; 923 + 924 + list_del(&node->list); 925 + kfree(node->dev_name); 926 + kfree(node); 927 + return; 934 928 } 935 929 } 936 930 ··· 956 920 list_for_each_entry_safe(node, n, &regulator_map_list, list) { 957 921 if (rdev == node->regulator) { 958 922 list_del(&node->list); 923 + kfree(node->dev_name); 959 924 kfree(node); 960 925 return; 961 926 } ··· 1038 1001 return NULL; 1039 1002 } 1040 1003 1004 + /* Internal regulator request function */ 1005 + static struct regulator *_regulator_get(struct device *dev, const char *id, 1006 + int exclusive) 1007 + { 1008 + struct regulator_dev *rdev; 1009 + struct regulator_map *map; 1010 + struct regulator *regulator = ERR_PTR(-ENODEV); 1011 + const char *devname = NULL; 1012 + int ret; 1013 + 1014 + if (id == NULL) { 1015 + printk(KERN_ERR "regulator: get() with no identifier\n"); 1016 + return regulator; 1017 + } 1018 + 1019 + if (dev) 1020 + devname = dev_name(dev); 1021 + 1022 + mutex_lock(&regulator_list_mutex); 1023 + 1024 + list_for_each_entry(map, &regulator_map_list, list) { 1025 + /* If the mapping has a device set up it must match */ 1026 + if (map->dev_name && 1027 + (!devname || strcmp(map->dev_name, devname))) 1028 + continue; 1029 + 1030 + if (strcmp(map->supply, id) == 0) { 1031 + rdev = map->regulator; 1032 + goto found; 1033 + } 1034 + } 1035 + mutex_unlock(&regulator_list_mutex); 1036 + return regulator; 1037 + 1038 + found: 1039 + if (rdev->exclusive) { 1040 + regulator = ERR_PTR(-EPERM); 1041 + goto out; 1042 + } 1043 + 1044 + if (exclusive && rdev->open_count) { 1045 + regulator = ERR_PTR(-EBUSY); 1046 + goto out; 1047 + } 1048 + 1049 + if (!try_module_get(rdev->owner)) 1050 + goto out; 1051 + 1052 + regulator = create_regulator(rdev, dev, id); 1053 + if (regulator == NULL) { 1054 + regulator = ERR_PTR(-ENOMEM); 1055 + module_put(rdev->owner); 1056 + } 1057 + 1058 + rdev->open_count++; 1059 + if (exclusive) { 1060 + rdev->exclusive = 1; 1061 + 1062 + ret = _regulator_is_enabled(rdev); 1063 + if (ret > 0) 1064 + rdev->use_count = 1; 1065 + else 1066 + rdev->use_count = 0; 1067 + } 1068 + 1069 + out: 1070 + mutex_unlock(&regulator_list_mutex); 1071 + 1072 + return regulator; 1073 + } 1074 + 1041 1075 /** 1042 1076 * regulator_get - lookup and obtain a reference to a regulator. 1043 1077 * @dev: device for regulator "consumer" ··· 1124 1016 */ 1125 1017 struct regulator *regulator_get(struct device *dev, const char *id) 1126 1018 { 1127 - struct regulator_dev *rdev; 1128 - struct regulator_map *map; 1129 - struct regulator *regulator = ERR_PTR(-ENODEV); 1130 - 1131 - if (id == NULL) { 1132 - printk(KERN_ERR "regulator: get() with no identifier\n"); 1133 - return regulator; 1134 - } 1135 - 1136 - mutex_lock(&regulator_list_mutex); 1137 - 1138 - list_for_each_entry(map, &regulator_map_list, list) { 1139 - if (dev == map->dev && 1140 - strcmp(map->supply, id) == 0) { 1141 - rdev = map->regulator; 1142 - goto found; 1143 - } 1144 - } 1145 - mutex_unlock(&regulator_list_mutex); 1146 - return regulator; 1147 - 1148 - found: 1149 - if (!try_module_get(rdev->owner)) 1150 - goto out; 1151 - 1152 - regulator = create_regulator(rdev, dev, id); 1153 - if (regulator == NULL) { 1154 - regulator = ERR_PTR(-ENOMEM); 1155 - module_put(rdev->owner); 1156 - } 1157 - 1158 - out: 1159 - mutex_unlock(&regulator_list_mutex); 1160 - return regulator; 1019 + return _regulator_get(dev, id, 0); 1161 1020 } 1162 1021 EXPORT_SYMBOL_GPL(regulator_get); 1022 + 1023 + /** 1024 + * regulator_get_exclusive - obtain exclusive access to a regulator. 1025 + * @dev: device for regulator "consumer" 1026 + * @id: Supply name or regulator ID. 1027 + * 1028 + * Returns a struct regulator corresponding to the regulator producer, 1029 + * or IS_ERR() condition containing errno. Other consumers will be 1030 + * unable to obtain this reference is held and the use count for the 1031 + * regulator will be initialised to reflect the current state of the 1032 + * regulator. 1033 + * 1034 + * This is intended for use by consumers which cannot tolerate shared 1035 + * use of the regulator such as those which need to force the 1036 + * regulator off for correct operation of the hardware they are 1037 + * controlling. 1038 + * 1039 + * Use of supply names configured via regulator_set_device_supply() is 1040 + * strongly encouraged. It is recommended that the supply name used 1041 + * should match the name used for the supply and/or the relevant 1042 + * device pins in the datasheet. 1043 + */ 1044 + struct regulator *regulator_get_exclusive(struct device *dev, const char *id) 1045 + { 1046 + return _regulator_get(dev, id, 1); 1047 + } 1048 + EXPORT_SYMBOL_GPL(regulator_get_exclusive); 1163 1049 1164 1050 /** 1165 1051 * regulator_put - "free" the regulator source ··· 1183 1081 list_del(&regulator->list); 1184 1082 kfree(regulator); 1185 1083 1084 + rdev->open_count--; 1085 + rdev->exclusive = 0; 1086 + 1186 1087 module_put(rdev->owner); 1187 1088 mutex_unlock(&regulator_list_mutex); 1188 1089 } 1189 1090 EXPORT_SYMBOL_GPL(regulator_put); 1190 1091 1092 + static int _regulator_can_change_status(struct regulator_dev *rdev) 1093 + { 1094 + if (!rdev->constraints) 1095 + return 0; 1096 + 1097 + if (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_STATUS) 1098 + return 1; 1099 + else 1100 + return 0; 1101 + } 1102 + 1191 1103 /* locks held by regulator_enable() */ 1192 1104 static int _regulator_enable(struct regulator_dev *rdev) 1193 1105 { 1194 - int ret = -EINVAL; 1195 - 1196 - if (!rdev->constraints) { 1197 - printk(KERN_ERR "%s: %s has no constraints\n", 1198 - __func__, rdev->desc->name); 1199 - return ret; 1200 - } 1106 + int ret; 1201 1107 1202 1108 /* do we need to enable the supply regulator first */ 1203 1109 if (rdev->supply) { ··· 1218 1108 } 1219 1109 1220 1110 /* check voltage and requested load before enabling */ 1221 - if (rdev->desc->ops->enable) { 1111 + if (rdev->constraints && 1112 + (rdev->constraints->valid_ops_mask & REGULATOR_CHANGE_DRMS)) 1113 + drms_uA_update(rdev); 1222 1114 1223 - if (rdev->constraints && 1224 - (rdev->constraints->valid_ops_mask & 1225 - REGULATOR_CHANGE_DRMS)) 1226 - drms_uA_update(rdev); 1115 + if (rdev->use_count == 0) { 1116 + /* The regulator may on if it's not switchable or left on */ 1117 + ret = _regulator_is_enabled(rdev); 1118 + if (ret == -EINVAL || ret == 0) { 1119 + if (!_regulator_can_change_status(rdev)) 1120 + return -EPERM; 1227 1121 1228 - ret = rdev->desc->ops->enable(rdev); 1229 - if (ret < 0) { 1230 - printk(KERN_ERR "%s: failed to enable %s: %d\n", 1122 + if (rdev->desc->ops->enable) { 1123 + ret = rdev->desc->ops->enable(rdev); 1124 + if (ret < 0) 1125 + return ret; 1126 + } else { 1127 + return -EINVAL; 1128 + } 1129 + } else if (ret < 0) { 1130 + printk(KERN_ERR "%s: is_enabled() failed for %s: %d\n", 1231 1131 __func__, rdev->desc->name, ret); 1232 1132 return ret; 1233 1133 } 1234 - rdev->use_count++; 1235 - return ret; 1134 + /* Fallthrough on positive return values - already enabled */ 1236 1135 } 1237 1136 1238 - return ret; 1137 + rdev->use_count++; 1138 + 1139 + return 0; 1239 1140 } 1240 1141 1241 1142 /** ··· 1286 1165 if (rdev->use_count == 1 && !rdev->constraints->always_on) { 1287 1166 1288 1167 /* we are last user */ 1289 - if (rdev->desc->ops->disable) { 1168 + if (_regulator_can_change_status(rdev) && 1169 + rdev->desc->ops->disable) { 1290 1170 ret = rdev->desc->ops->disable(rdev); 1291 1171 if (ret < 0) { 1292 1172 printk(KERN_ERR "%s: failed to disable %s\n", ··· 1387 1265 1388 1266 static int _regulator_is_enabled(struct regulator_dev *rdev) 1389 1267 { 1390 - int ret; 1391 - 1392 - mutex_lock(&rdev->mutex); 1393 - 1394 1268 /* sanity check */ 1395 - if (!rdev->desc->ops->is_enabled) { 1396 - ret = -EINVAL; 1397 - goto out; 1398 - } 1269 + if (!rdev->desc->ops->is_enabled) 1270 + return -EINVAL; 1399 1271 1400 - ret = rdev->desc->ops->is_enabled(rdev); 1401 - out: 1402 - mutex_unlock(&rdev->mutex); 1403 - return ret; 1272 + return rdev->desc->ops->is_enabled(rdev); 1404 1273 } 1405 1274 1406 1275 /** ··· 1408 1295 */ 1409 1296 int regulator_is_enabled(struct regulator *regulator) 1410 1297 { 1411 - return _regulator_is_enabled(regulator->rdev); 1298 + int ret; 1299 + 1300 + mutex_lock(&regulator->rdev->mutex); 1301 + ret = _regulator_is_enabled(regulator->rdev); 1302 + mutex_unlock(&regulator->rdev->mutex); 1303 + 1304 + return ret; 1412 1305 } 1413 1306 EXPORT_SYMBOL_GPL(regulator_is_enabled); 1414 1307 ··· 1467 1348 return ret; 1468 1349 } 1469 1350 EXPORT_SYMBOL_GPL(regulator_list_voltage); 1351 + 1352 + /** 1353 + * regulator_is_supported_voltage - check if a voltage range can be supported 1354 + * 1355 + * @regulator: Regulator to check. 1356 + * @min_uV: Minimum required voltage in uV. 1357 + * @max_uV: Maximum required voltage in uV. 1358 + * 1359 + * Returns a boolean or a negative error code. 1360 + */ 1361 + int regulator_is_supported_voltage(struct regulator *regulator, 1362 + int min_uV, int max_uV) 1363 + { 1364 + int i, voltages, ret; 1365 + 1366 + ret = regulator_count_voltages(regulator); 1367 + if (ret < 0) 1368 + return ret; 1369 + voltages = ret; 1370 + 1371 + for (i = 0; i < voltages; i++) { 1372 + ret = regulator_list_voltage(regulator, i); 1373 + 1374 + if (ret >= min_uV && ret <= max_uV) 1375 + return 1; 1376 + } 1377 + 1378 + return 0; 1379 + } 1470 1380 1471 1381 /** 1472 1382 * regulator_set_voltage - set regulator output voltage ··· 2239 2091 for (i = 0; i < init_data->num_consumer_supplies; i++) { 2240 2092 ret = set_consumer_device_supply(rdev, 2241 2093 init_data->consumer_supplies[i].dev, 2094 + init_data->consumer_supplies[i].dev_name, 2242 2095 init_data->consumer_supplies[i].supply); 2243 2096 if (ret < 0) { 2244 2097 for (--i; i >= 0; i--) 2245 2098 unset_consumer_device_supply(rdev, 2246 - init_data->consumer_supplies[i].dev); 2099 + init_data->consumer_supplies[i].dev_name, 2100 + init_data->consumer_supplies[i].dev); 2247 2101 goto scrub; 2248 2102 } 2249 2103 } ··· 2280 2130 return; 2281 2131 2282 2132 mutex_lock(&regulator_list_mutex); 2133 + WARN_ON(rdev->open_count); 2283 2134 unset_regulator_supplies(rdev); 2284 2135 list_del(&rdev->list); 2285 2136 if (rdev->supply) ··· 2428 2277 ops = rdev->desc->ops; 2429 2278 c = rdev->constraints; 2430 2279 2431 - if (c->name) 2280 + if (c && c->name) 2432 2281 name = c->name; 2433 2282 else if (rdev->desc->name) 2434 2283 name = rdev->desc->name; 2435 2284 else 2436 2285 name = "regulator"; 2437 2286 2438 - if (!ops->disable || c->always_on) 2287 + if (!ops->disable || (c && c->always_on)) 2439 2288 continue; 2440 2289 2441 2290 mutex_lock(&rdev->mutex);
+67 -10
drivers/regulator/da903x.c
··· 64 64 #define DA9034_MDTV2 (0x33) 65 65 #define DA9034_MVRC (0x34) 66 66 67 + /* DA9035 Registers. DA9034 Registers are comptabile to DA9035. */ 68 + #define DA9035_OVER3 (0x12) 69 + #define DA9035_VCC2 (0x1f) 70 + #define DA9035_3DTV1 (0x2c) 71 + #define DA9035_3DTV2 (0x2d) 72 + #define DA9035_3VRC (0x2e) 73 + #define DA9035_AUTOSKIP (0x2f) 74 + 67 75 struct da903x_regulator_info { 68 76 struct regulator_desc desc; 69 77 ··· 86 78 int enable_reg; 87 79 int enable_bit; 88 80 }; 81 + 82 + static int da9034_ldo12_data[] = { 1700, 1750, 1800, 1850, 1900, 1950, 83 + 2000, 2050, 2700, 2750, 2800, 2850, 84 + 2900, 2950, 3000, 3050 }; 89 85 90 86 static inline struct device *to_da903x_dev(struct regulator_dev *rdev) 91 87 { ··· 172 160 return ret; 173 161 174 162 return !!(reg_val & (1 << info->enable_bit)); 163 + } 164 + 165 + static int da903x_list_voltage(struct regulator_dev *rdev, unsigned selector) 166 + { 167 + struct da903x_regulator_info *info = rdev_get_drvdata(rdev); 168 + int ret; 169 + 170 + ret = info->min_uV + info->step_uV * selector; 171 + if (ret > info->max_uV) 172 + return -EINVAL; 173 + return ret; 175 174 } 176 175 177 176 /* DA9030 specific operations */ ··· 301 278 } 302 279 303 280 val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV; 304 - val = (val > 7 || val < 20) ? 8 : val - 12; 281 + val = (val >= 20) ? val - 12 : ((val > 7) ? 8 : val); 305 282 val <<= info->vol_shift; 306 283 mask = ((1 << info->vol_nbits) - 1) << info->vol_shift; 307 284 ··· 328 305 return info->min_uV + info->step_uV * val; 329 306 } 330 307 308 + static int da9034_list_ldo12_voltage(struct regulator_dev *rdev, 309 + unsigned selector) 310 + { 311 + if (selector > ARRAY_SIZE(da9034_ldo12_data)) 312 + return -EINVAL; 313 + return da9034_ldo12_data[selector] * 1000; 314 + } 315 + 331 316 static struct regulator_ops da903x_regulator_ldo_ops = { 332 317 .set_voltage = da903x_set_ldo_voltage, 333 318 .get_voltage = da903x_get_voltage, 319 + .list_voltage = da903x_list_voltage, 334 320 .enable = da903x_enable, 335 321 .disable = da903x_disable, 336 322 .is_enabled = da903x_is_enabled, ··· 349 317 static struct regulator_ops da9030_regulator_ldo14_ops = { 350 318 .set_voltage = da9030_set_ldo14_voltage, 351 319 .get_voltage = da9030_get_ldo14_voltage, 320 + .list_voltage = da903x_list_voltage, 352 321 .enable = da903x_enable, 353 322 .disable = da903x_disable, 354 323 .is_enabled = da903x_is_enabled, ··· 359 326 static struct regulator_ops da9030_regulator_ldo1_15_ops = { 360 327 .set_voltage = da9030_set_ldo1_15_voltage, 361 328 .get_voltage = da903x_get_voltage, 329 + .list_voltage = da903x_list_voltage, 362 330 .enable = da903x_enable, 363 331 .disable = da903x_disable, 364 332 .is_enabled = da903x_is_enabled, ··· 368 334 static struct regulator_ops da9034_regulator_dvc_ops = { 369 335 .set_voltage = da9034_set_dvc_voltage, 370 336 .get_voltage = da903x_get_voltage, 337 + .list_voltage = da903x_list_voltage, 371 338 .enable = da903x_enable, 372 339 .disable = da903x_disable, 373 340 .is_enabled = da903x_is_enabled, ··· 378 343 static struct regulator_ops da9034_regulator_ldo12_ops = { 379 344 .set_voltage = da9034_set_ldo12_voltage, 380 345 .get_voltage = da9034_get_ldo12_voltage, 346 + .list_voltage = da9034_list_ldo12_voltage, 381 347 .enable = da903x_enable, 382 348 .disable = da903x_disable, 383 349 .is_enabled = da903x_is_enabled, ··· 391 355 .ops = &da903x_regulator_ldo_ops, \ 392 356 .type = REGULATOR_VOLTAGE, \ 393 357 .id = _pmic##_ID_LDO##_id, \ 358 + .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ 394 359 .owner = THIS_MODULE, \ 395 360 }, \ 396 361 .min_uV = (min) * 1000, \ ··· 404 367 .enable_bit = (ebit), \ 405 368 } 406 369 407 - #define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 370 + #define DA903x_DVC(_pmic, _id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 408 371 { \ 409 372 .desc = { \ 410 373 .name = #_id, \ 411 374 .ops = &da9034_regulator_dvc_ops, \ 412 375 .type = REGULATOR_VOLTAGE, \ 413 - .id = DA9034_ID_##_id, \ 376 + .id = _pmic##_ID_##_id, \ 377 + .n_voltages = (step) ? ((max - min) / step + 1) : 1, \ 414 378 .owner = THIS_MODULE, \ 415 379 }, \ 416 380 .min_uV = (min) * 1000, \ 417 381 .max_uV = (max) * 1000, \ 418 382 .step_uV = (step) * 1000, \ 419 - .vol_reg = DA9034_##vreg, \ 383 + .vol_reg = _pmic##_##vreg, \ 420 384 .vol_shift = (0), \ 421 385 .vol_nbits = (nbits), \ 422 - .update_reg = DA9034_##ureg, \ 386 + .update_reg = _pmic##_##ureg, \ 423 387 .update_bit = (ubit), \ 424 - .enable_reg = DA9034_##ereg, \ 388 + .enable_reg = _pmic##_##ereg, \ 425 389 .enable_bit = (ebit), \ 426 390 } 427 391 ··· 432 394 #define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit) \ 433 395 DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit) 434 396 397 + #define DA9030_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 398 + DA903x_DVC(DA9030, _id, min, max, step, vreg, nbits, ureg, ubit, \ 399 + ereg, ebit) 400 + 401 + #define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 402 + DA903x_DVC(DA9034, _id, min, max, step, vreg, nbits, ureg, ubit, \ 403 + ereg, ebit) 404 + 405 + #define DA9035_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \ 406 + DA903x_DVC(DA9035, _id, min, max, step, vreg, nbits, ureg, ubit, \ 407 + ereg, ebit) 408 + 435 409 static struct da903x_regulator_info da903x_regulator_info[] = { 436 410 /* DA9030 */ 411 + DA9030_DVC(BUCK2, 850, 1625, 25, BUCK2DVM1, 5, BUCK2DVM1, 7, RCTL11, 0), 412 + 437 413 DA9030_LDO( 1, 1200, 3200, 100, LDO1, 0, 5, RCTL12, 1), 438 414 DA9030_LDO( 2, 1800, 3200, 100, LDO23, 0, 4, RCTL12, 2), 439 415 DA9030_LDO( 3, 1800, 3200, 100, LDO23, 4, 4, RCTL12, 3), ··· 469 417 DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */ 470 418 471 419 /* DA9034 */ 472 - DA9034_DVC(BUCK1, 725, 1500, 25, ADTV1, 5, VCC1, 0, OVER1, 0), 473 - DA9034_DVC(BUCK2, 725, 1500, 25, CDTV1, 5, VCC1, 2, OVER1, 1), 474 - DA9034_DVC(LDO2, 725, 1500, 25, SDTV1, 5, VCC1, 4, OVER1, 2), 420 + DA9034_DVC(BUCK1, 725, 1500, 25, ADTV2, 5, VCC1, 0, OVER1, 0), 421 + DA9034_DVC(BUCK2, 725, 1500, 25, CDTV2, 5, VCC1, 2, OVER1, 1), 422 + DA9034_DVC(LDO2, 725, 1500, 25, SDTV2, 5, VCC1, 4, OVER1, 2), 475 423 DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4), 476 424 477 425 DA9034_LDO( 3, 1800, 3300, 100, LDO643, 0, 4, OVER3, 5), ··· 487 435 DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0), 488 436 DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1), 489 437 DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */ 438 + 439 + /* DA9035 */ 440 + DA9035_DVC(BUCK3, 1800, 2200, 100, 3DTV1, 3, VCC2, 0, OVER3, 3), 490 441 }; 491 442 492 443 static inline struct da903x_regulator_info *find_regulator_info(int id) ··· 517 462 } 518 463 519 464 /* Workaround for the weird LDO12 voltage setting */ 520 - if (ri->desc.id == DA9034_ID_LDO12) 465 + if (ri->desc.id == DA9034_ID_LDO12) { 521 466 ri->desc.ops = &da9034_regulator_ldo12_ops; 467 + ri->desc.n_voltages = ARRAY_SIZE(da9034_ldo12_data); 468 + } 522 469 523 470 if (ri->desc.id == DA9030_ID_LDO14) 524 471 ri->desc.ops = &da9030_regulator_ldo14_ops;
+89 -2
drivers/regulator/fixed.c
··· 5 5 * 6 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 7 * 8 + * Copyright (c) 2009 Nokia Corporation 9 + * Roger Quadros <ext-roger.quadros@nokia.com> 10 + * 8 11 * This program is free software; you can redistribute it and/or 9 12 * modify it under the terms of the GNU General Public License as 10 13 * published by the Free Software Foundation; either version 2 of the ··· 23 20 #include <linux/platform_device.h> 24 21 #include <linux/regulator/driver.h> 25 22 #include <linux/regulator/fixed.h> 23 + #include <linux/gpio.h> 26 24 27 25 struct fixed_voltage_data { 28 26 struct regulator_desc desc; 29 27 struct regulator_dev *dev; 30 28 int microvolts; 29 + int gpio; 30 + unsigned enable_high:1; 31 + unsigned is_enabled:1; 31 32 }; 32 33 33 34 static int fixed_voltage_is_enabled(struct regulator_dev *dev) 34 35 { 35 - return 1; 36 + struct fixed_voltage_data *data = rdev_get_drvdata(dev); 37 + 38 + return data->is_enabled; 36 39 } 37 40 38 41 static int fixed_voltage_enable(struct regulator_dev *dev) 39 42 { 43 + struct fixed_voltage_data *data = rdev_get_drvdata(dev); 44 + 45 + if (gpio_is_valid(data->gpio)) { 46 + gpio_set_value_cansleep(data->gpio, data->enable_high); 47 + data->is_enabled = 1; 48 + } 49 + 50 + return 0; 51 + } 52 + 53 + static int fixed_voltage_disable(struct regulator_dev *dev) 54 + { 55 + struct fixed_voltage_data *data = rdev_get_drvdata(dev); 56 + 57 + if (gpio_is_valid(data->gpio)) { 58 + gpio_set_value_cansleep(data->gpio, !data->enable_high); 59 + data->is_enabled = 0; 60 + } 61 + 40 62 return 0; 41 63 } 42 64 ··· 86 58 static struct regulator_ops fixed_voltage_ops = { 87 59 .is_enabled = fixed_voltage_is_enabled, 88 60 .enable = fixed_voltage_enable, 61 + .disable = fixed_voltage_disable, 89 62 .get_voltage = fixed_voltage_get_voltage, 90 63 .list_voltage = fixed_voltage_list_voltage, 91 64 }; ··· 99 70 100 71 drvdata = kzalloc(sizeof(struct fixed_voltage_data), GFP_KERNEL); 101 72 if (drvdata == NULL) { 73 + dev_err(&pdev->dev, "Failed to allocate device data\n"); 102 74 ret = -ENOMEM; 103 75 goto err; 104 76 } 105 77 106 78 drvdata->desc.name = kstrdup(config->supply_name, GFP_KERNEL); 107 79 if (drvdata->desc.name == NULL) { 80 + dev_err(&pdev->dev, "Failed to allocate supply name\n"); 108 81 ret = -ENOMEM; 109 82 goto err; 110 83 } ··· 116 85 drvdata->desc.n_voltages = 1; 117 86 118 87 drvdata->microvolts = config->microvolts; 88 + drvdata->gpio = config->gpio; 89 + 90 + if (gpio_is_valid(config->gpio)) { 91 + drvdata->enable_high = config->enable_high; 92 + 93 + /* FIXME: Remove below print warning 94 + * 95 + * config->gpio must be set to -EINVAL by platform code if 96 + * GPIO control is not required. However, early adopters 97 + * not requiring GPIO control may forget to initialize 98 + * config->gpio to -EINVAL. This will cause GPIO 0 to be used 99 + * for GPIO control. 100 + * 101 + * This warning will be removed once there are a couple of users 102 + * for this driver. 103 + */ 104 + if (!config->gpio) 105 + dev_warn(&pdev->dev, 106 + "using GPIO 0 for regulator enable control\n"); 107 + 108 + ret = gpio_request(config->gpio, config->supply_name); 109 + if (ret) { 110 + dev_err(&pdev->dev, 111 + "Could not obtain regulator enable GPIO %d: %d\n", 112 + config->gpio, ret); 113 + goto err_name; 114 + } 115 + 116 + /* set output direction without changing state 117 + * to prevent glitch 118 + */ 119 + drvdata->is_enabled = config->enabled_at_boot; 120 + ret = drvdata->is_enabled ? 121 + config->enable_high : !config->enable_high; 122 + 123 + ret = gpio_direction_output(config->gpio, ret); 124 + if (ret) { 125 + dev_err(&pdev->dev, 126 + "Could not configure regulator enable GPIO %d direction: %d\n", 127 + config->gpio, ret); 128 + goto err_gpio; 129 + } 130 + 131 + } else { 132 + /* Regulator without GPIO control is considered 133 + * always enabled 134 + */ 135 + drvdata->is_enabled = 1; 136 + } 119 137 120 138 drvdata->dev = regulator_register(&drvdata->desc, &pdev->dev, 121 139 config->init_data, drvdata); 122 140 if (IS_ERR(drvdata->dev)) { 123 141 ret = PTR_ERR(drvdata->dev); 124 - goto err_name; 142 + dev_err(&pdev->dev, "Failed to register regulator: %d\n", ret); 143 + goto err_gpio; 125 144 } 126 145 127 146 platform_set_drvdata(pdev, drvdata); ··· 181 100 182 101 return 0; 183 102 103 + err_gpio: 104 + if (gpio_is_valid(config->gpio)) 105 + gpio_free(config->gpio); 184 106 err_name: 185 107 kfree(drvdata->desc.name); 186 108 err: ··· 198 114 regulator_unregister(drvdata->dev); 199 115 kfree(drvdata->desc.name); 200 116 kfree(drvdata); 117 + 118 + if (gpio_is_valid(drvdata->gpio)) 119 + gpio_free(drvdata->gpio); 201 120 202 121 return 0; 203 122 }
+1 -1
drivers/regulator/lp3971.c
··· 541 541 542 542 static int __init lp3971_module_init(void) 543 543 { 544 - int ret = -ENODEV; 544 + int ret; 545 545 546 546 ret = i2c_add_driver(&lp3971_i2c_driver); 547 547 if (ret != 0)
+65 -33
drivers/regulator/pcf50633-regulator.c
··· 24 24 #include <linux/mfd/pcf50633/core.h> 25 25 #include <linux/mfd/pcf50633/pmic.h> 26 26 27 - #define PCF50633_REGULATOR(_name, _id) \ 27 + #define PCF50633_REGULATOR(_name, _id, _n) \ 28 28 { \ 29 29 .name = _name, \ 30 30 .id = _id, \ 31 31 .ops = &pcf50633_regulator_ops, \ 32 + .n_voltages = _n, \ 32 33 .type = REGULATOR_VOLTAGE, \ 33 34 .owner = THIS_MODULE, \ 34 35 } ··· 150 149 return pcf50633_reg_write(pcf, regnr, volt_bits); 151 150 } 152 151 153 - static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev) 152 + static int pcf50633_regulator_voltage_value(enum pcf50633_regulator_id id, 153 + u8 bits) 154 154 { 155 - struct pcf50633 *pcf; 156 - int regulator_id, millivolts, volt_bits; 157 - u8 regnr; 155 + int millivolts; 158 156 159 - pcf = rdev_get_drvdata(rdev);; 160 - 161 - regulator_id = rdev_get_id(rdev); 162 - if (regulator_id >= PCF50633_NUM_REGULATORS) 163 - return -EINVAL; 164 - 165 - regnr = pcf50633_regulator_registers[regulator_id]; 166 - 167 - volt_bits = pcf50633_reg_read(pcf, regnr); 168 - if (volt_bits < 0) 169 - return -1; 170 - 171 - switch (regulator_id) { 157 + switch (id) { 172 158 case PCF50633_REGULATOR_AUTO: 173 - millivolts = auto_voltage_value(volt_bits); 159 + millivolts = auto_voltage_value(bits); 174 160 break; 175 161 case PCF50633_REGULATOR_DOWN1: 176 - millivolts = down_voltage_value(volt_bits); 162 + millivolts = down_voltage_value(bits); 177 163 break; 178 164 case PCF50633_REGULATOR_DOWN2: 179 - millivolts = down_voltage_value(volt_bits); 165 + millivolts = down_voltage_value(bits); 180 166 break; 181 167 case PCF50633_REGULATOR_LDO1: 182 168 case PCF50633_REGULATOR_LDO2: ··· 172 184 case PCF50633_REGULATOR_LDO5: 173 185 case PCF50633_REGULATOR_LDO6: 174 186 case PCF50633_REGULATOR_HCLDO: 175 - millivolts = ldo_voltage_value(volt_bits); 187 + millivolts = ldo_voltage_value(bits); 176 188 break; 177 189 default: 178 190 return -EINVAL; 179 191 } 180 192 181 193 return millivolts * 1000; 194 + } 195 + 196 + static int pcf50633_regulator_get_voltage(struct regulator_dev *rdev) 197 + { 198 + struct pcf50633 *pcf; 199 + int regulator_id; 200 + u8 volt_bits, regnr; 201 + 202 + pcf = rdev_get_drvdata(rdev); 203 + 204 + regulator_id = rdev_get_id(rdev); 205 + if (regulator_id >= PCF50633_NUM_REGULATORS) 206 + return -EINVAL; 207 + 208 + regnr = pcf50633_regulator_registers[regulator_id]; 209 + 210 + volt_bits = pcf50633_reg_read(pcf, regnr); 211 + 212 + return pcf50633_regulator_voltage_value(regulator_id, volt_bits); 213 + } 214 + 215 + static int pcf50633_regulator_list_voltage(struct regulator_dev *rdev, 216 + unsigned int index) 217 + { 218 + struct pcf50633 *pcf; 219 + int regulator_id; 220 + 221 + pcf = rdev_get_drvdata(rdev); 222 + 223 + regulator_id = rdev_get_id(rdev); 224 + 225 + switch (regulator_id) { 226 + case PCF50633_REGULATOR_AUTO: 227 + index += 0x2f; 228 + break; 229 + case PCF50633_REGULATOR_HCLDO: 230 + index += 0x01; 231 + break; 232 + default: 233 + break; 234 + } 235 + 236 + return pcf50633_regulator_voltage_value(regulator_id, index); 182 237 } 183 238 184 239 static int pcf50633_regulator_enable(struct regulator_dev *rdev) ··· 277 246 static struct regulator_ops pcf50633_regulator_ops = { 278 247 .set_voltage = pcf50633_regulator_set_voltage, 279 248 .get_voltage = pcf50633_regulator_get_voltage, 249 + .list_voltage = pcf50633_regulator_list_voltage, 280 250 .enable = pcf50633_regulator_enable, 281 251 .disable = pcf50633_regulator_disable, 282 252 .is_enabled = pcf50633_regulator_is_enabled, ··· 285 253 286 254 static struct regulator_desc regulators[] = { 287 255 [PCF50633_REGULATOR_AUTO] = 288 - PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO), 256 + PCF50633_REGULATOR("auto", PCF50633_REGULATOR_AUTO, 80), 289 257 [PCF50633_REGULATOR_DOWN1] = 290 - PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1), 258 + PCF50633_REGULATOR("down1", PCF50633_REGULATOR_DOWN1, 95), 291 259 [PCF50633_REGULATOR_DOWN2] = 292 - PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2), 260 + PCF50633_REGULATOR("down2", PCF50633_REGULATOR_DOWN2, 95), 293 261 [PCF50633_REGULATOR_LDO1] = 294 - PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1), 262 + PCF50633_REGULATOR("ldo1", PCF50633_REGULATOR_LDO1, 27), 295 263 [PCF50633_REGULATOR_LDO2] = 296 - PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2), 264 + PCF50633_REGULATOR("ldo2", PCF50633_REGULATOR_LDO2, 27), 297 265 [PCF50633_REGULATOR_LDO3] = 298 - PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3), 266 + PCF50633_REGULATOR("ldo3", PCF50633_REGULATOR_LDO3, 27), 299 267 [PCF50633_REGULATOR_LDO4] = 300 - PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4), 268 + PCF50633_REGULATOR("ldo4", PCF50633_REGULATOR_LDO4, 27), 301 269 [PCF50633_REGULATOR_LDO5] = 302 - PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5), 270 + PCF50633_REGULATOR("ldo5", PCF50633_REGULATOR_LDO5, 27), 303 271 [PCF50633_REGULATOR_LDO6] = 304 - PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6), 272 + PCF50633_REGULATOR("ldo6", PCF50633_REGULATOR_LDO6, 27), 305 273 [PCF50633_REGULATOR_HCLDO] = 306 - PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO), 274 + PCF50633_REGULATOR("hcldo", PCF50633_REGULATOR_HCLDO, 26), 307 275 [PCF50633_REGULATOR_MEMLDO] = 308 - PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO), 276 + PCF50633_REGULATOR("memldo", PCF50633_REGULATOR_MEMLDO, 0), 309 277 }; 310 278 311 279 static int __devinit pcf50633_regulator_probe(struct platform_device *pdev)
+632
drivers/regulator/tps65023-regulator.c
··· 1 + /* 2 + * tps65023-regulator.c 3 + * 4 + * Supports TPS65023 Regulator 5 + * 6 + * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.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 version 2. 11 + * 12 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 13 + * whether express or implied; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/init.h> 21 + #include <linux/err.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/regulator/driver.h> 24 + #include <linux/regulator/machine.h> 25 + #include <linux/i2c.h> 26 + #include <linux/delay.h> 27 + 28 + /* Register definitions */ 29 + #define TPS65023_REG_VERSION 0 30 + #define TPS65023_REG_PGOODZ 1 31 + #define TPS65023_REG_MASK 2 32 + #define TPS65023_REG_REG_CTRL 3 33 + #define TPS65023_REG_CON_CTRL 4 34 + #define TPS65023_REG_CON_CTRL2 5 35 + #define TPS65023_REG_DEF_CORE 6 36 + #define TPS65023_REG_DEFSLEW 7 37 + #define TPS65023_REG_LDO_CTRL 8 38 + 39 + /* PGOODZ bitfields */ 40 + #define TPS65023_PGOODZ_PWRFAILZ BIT(7) 41 + #define TPS65023_PGOODZ_LOWBATTZ BIT(6) 42 + #define TPS65023_PGOODZ_VDCDC1 BIT(5) 43 + #define TPS65023_PGOODZ_VDCDC2 BIT(4) 44 + #define TPS65023_PGOODZ_VDCDC3 BIT(3) 45 + #define TPS65023_PGOODZ_LDO2 BIT(2) 46 + #define TPS65023_PGOODZ_LDO1 BIT(1) 47 + 48 + /* MASK bitfields */ 49 + #define TPS65023_MASK_PWRFAILZ BIT(7) 50 + #define TPS65023_MASK_LOWBATTZ BIT(6) 51 + #define TPS65023_MASK_VDCDC1 BIT(5) 52 + #define TPS65023_MASK_VDCDC2 BIT(4) 53 + #define TPS65023_MASK_VDCDC3 BIT(3) 54 + #define TPS65023_MASK_LDO2 BIT(2) 55 + #define TPS65023_MASK_LDO1 BIT(1) 56 + 57 + /* REG_CTRL bitfields */ 58 + #define TPS65023_REG_CTRL_VDCDC1_EN BIT(5) 59 + #define TPS65023_REG_CTRL_VDCDC2_EN BIT(4) 60 + #define TPS65023_REG_CTRL_VDCDC3_EN BIT(3) 61 + #define TPS65023_REG_CTRL_LDO2_EN BIT(2) 62 + #define TPS65023_REG_CTRL_LDO1_EN BIT(1) 63 + 64 + /* LDO_CTRL bitfields */ 65 + #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) 66 + #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0xF0 >> ((ldo_id)*4)) 67 + 68 + /* Number of step-down converters available */ 69 + #define TPS65023_NUM_DCDC 3 70 + /* Number of LDO voltage regulators available */ 71 + #define TPS65023_NUM_LDO 2 72 + /* Number of total regulators available */ 73 + #define TPS65023_NUM_REGULATOR (TPS65023_NUM_DCDC + TPS65023_NUM_LDO) 74 + 75 + /* DCDCs */ 76 + #define TPS65023_DCDC_1 0 77 + #define TPS65023_DCDC_2 1 78 + #define TPS65023_DCDC_3 2 79 + /* LDOs */ 80 + #define TPS65023_LDO_1 3 81 + #define TPS65023_LDO_2 4 82 + 83 + #define TPS65023_MAX_REG_ID TPS65023_LDO_2 84 + 85 + /* Supported voltage values for regulators */ 86 + static const u16 VDCDC1_VSEL_table[] = { 87 + 800, 825, 850, 875, 88 + 900, 925, 950, 975, 89 + 1000, 1025, 1050, 1075, 90 + 1100, 1125, 1150, 1175, 91 + 1200, 1225, 1250, 1275, 92 + 1300, 1325, 1350, 1375, 93 + 1400, 1425, 1450, 1475, 94 + 1500, 1525, 1550, 1600, 95 + }; 96 + 97 + static const u16 LDO1_VSEL_table[] = { 98 + 1000, 1100, 1300, 1800, 99 + 2200, 2600, 2800, 3150, 100 + }; 101 + 102 + static const u16 LDO2_VSEL_table[] = { 103 + 1050, 1200, 1300, 1800, 104 + 2500, 2800, 3000, 3300, 105 + }; 106 + 107 + static unsigned int num_voltages[] = {ARRAY_SIZE(VDCDC1_VSEL_table), 108 + 0, 0, ARRAY_SIZE(LDO1_VSEL_table), 109 + ARRAY_SIZE(LDO2_VSEL_table)}; 110 + 111 + /* Regulator specific details */ 112 + struct tps_info { 113 + const char *name; 114 + unsigned min_uV; 115 + unsigned max_uV; 116 + bool fixed; 117 + u8 table_len; 118 + const u16 *table; 119 + }; 120 + 121 + /* PMIC details */ 122 + struct tps_pmic { 123 + struct regulator_desc desc[TPS65023_NUM_REGULATOR]; 124 + struct i2c_client *client; 125 + struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; 126 + const struct tps_info *info[TPS65023_NUM_REGULATOR]; 127 + struct mutex io_lock; 128 + }; 129 + 130 + static inline int tps_65023_read(struct tps_pmic *tps, u8 reg) 131 + { 132 + return i2c_smbus_read_byte_data(tps->client, reg); 133 + } 134 + 135 + static inline int tps_65023_write(struct tps_pmic *tps, u8 reg, u8 val) 136 + { 137 + return i2c_smbus_write_byte_data(tps->client, reg, val); 138 + } 139 + 140 + static int tps_65023_set_bits(struct tps_pmic *tps, u8 reg, u8 mask) 141 + { 142 + int err, data; 143 + 144 + mutex_lock(&tps->io_lock); 145 + 146 + data = tps_65023_read(tps, reg); 147 + if (data < 0) { 148 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 149 + err = data; 150 + goto out; 151 + } 152 + 153 + data |= mask; 154 + err = tps_65023_write(tps, reg, data); 155 + if (err) 156 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 157 + 158 + out: 159 + mutex_unlock(&tps->io_lock); 160 + return err; 161 + } 162 + 163 + static int tps_65023_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask) 164 + { 165 + int err, data; 166 + 167 + mutex_lock(&tps->io_lock); 168 + 169 + data = tps_65023_read(tps, reg); 170 + if (data < 0) { 171 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 172 + err = data; 173 + goto out; 174 + } 175 + 176 + data &= ~mask; 177 + 178 + err = tps_65023_write(tps, reg, data); 179 + if (err) 180 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 181 + 182 + out: 183 + mutex_unlock(&tps->io_lock); 184 + return err; 185 + 186 + } 187 + 188 + static int tps_65023_reg_read(struct tps_pmic *tps, u8 reg) 189 + { 190 + int data; 191 + 192 + mutex_lock(&tps->io_lock); 193 + 194 + data = tps_65023_read(tps, reg); 195 + if (data < 0) 196 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 197 + 198 + mutex_unlock(&tps->io_lock); 199 + return data; 200 + } 201 + 202 + static int tps_65023_reg_write(struct tps_pmic *tps, u8 reg, u8 val) 203 + { 204 + int err; 205 + 206 + mutex_lock(&tps->io_lock); 207 + 208 + err = tps_65023_write(tps, reg, val); 209 + if (err < 0) 210 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 211 + 212 + mutex_unlock(&tps->io_lock); 213 + return err; 214 + } 215 + 216 + static int tps65023_dcdc_is_enabled(struct regulator_dev *dev) 217 + { 218 + struct tps_pmic *tps = rdev_get_drvdata(dev); 219 + int data, dcdc = rdev_get_id(dev); 220 + u8 shift; 221 + 222 + if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 223 + return -EINVAL; 224 + 225 + shift = TPS65023_NUM_REGULATOR - dcdc; 226 + data = tps_65023_reg_read(tps, TPS65023_REG_REG_CTRL); 227 + 228 + if (data < 0) 229 + return data; 230 + else 231 + return (data & 1<<shift) ? 1 : 0; 232 + } 233 + 234 + static int tps65023_ldo_is_enabled(struct regulator_dev *dev) 235 + { 236 + struct tps_pmic *tps = rdev_get_drvdata(dev); 237 + int data, ldo = rdev_get_id(dev); 238 + u8 shift; 239 + 240 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 241 + return -EINVAL; 242 + 243 + shift = (ldo == TPS65023_LDO_1 ? 1 : 2); 244 + data = tps_65023_reg_read(tps, TPS65023_REG_REG_CTRL); 245 + 246 + if (data < 0) 247 + return data; 248 + else 249 + return (data & 1<<shift) ? 1 : 0; 250 + } 251 + 252 + static int tps65023_dcdc_enable(struct regulator_dev *dev) 253 + { 254 + struct tps_pmic *tps = rdev_get_drvdata(dev); 255 + int dcdc = rdev_get_id(dev); 256 + u8 shift; 257 + 258 + if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 259 + return -EINVAL; 260 + 261 + shift = TPS65023_NUM_REGULATOR - dcdc; 262 + return tps_65023_set_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); 263 + } 264 + 265 + static int tps65023_dcdc_disable(struct regulator_dev *dev) 266 + { 267 + struct tps_pmic *tps = rdev_get_drvdata(dev); 268 + int dcdc = rdev_get_id(dev); 269 + u8 shift; 270 + 271 + if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 272 + return -EINVAL; 273 + 274 + shift = TPS65023_NUM_REGULATOR - dcdc; 275 + return tps_65023_clear_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); 276 + } 277 + 278 + static int tps65023_ldo_enable(struct regulator_dev *dev) 279 + { 280 + struct tps_pmic *tps = rdev_get_drvdata(dev); 281 + int ldo = rdev_get_id(dev); 282 + u8 shift; 283 + 284 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 285 + return -EINVAL; 286 + 287 + shift = (ldo == TPS65023_LDO_1 ? 1 : 2); 288 + return tps_65023_set_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); 289 + } 290 + 291 + static int tps65023_ldo_disable(struct regulator_dev *dev) 292 + { 293 + struct tps_pmic *tps = rdev_get_drvdata(dev); 294 + int ldo = rdev_get_id(dev); 295 + u8 shift; 296 + 297 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 298 + return -EINVAL; 299 + 300 + shift = (ldo == TPS65023_LDO_1 ? 1 : 2); 301 + return tps_65023_clear_bits(tps, TPS65023_REG_REG_CTRL, 1 << shift); 302 + } 303 + 304 + static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) 305 + { 306 + struct tps_pmic *tps = rdev_get_drvdata(dev); 307 + int data, dcdc = rdev_get_id(dev); 308 + 309 + if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 310 + return -EINVAL; 311 + 312 + if (dcdc == TPS65023_DCDC_1) { 313 + data = tps_65023_reg_read(tps, TPS65023_REG_DEF_CORE); 314 + if (data < 0) 315 + return data; 316 + data &= (tps->info[dcdc]->table_len - 1); 317 + return tps->info[dcdc]->table[data] * 1000; 318 + } else 319 + return tps->info[dcdc]->min_uV; 320 + } 321 + 322 + static int tps65023_dcdc_set_voltage(struct regulator_dev *dev, 323 + int min_uV, int max_uV) 324 + { 325 + struct tps_pmic *tps = rdev_get_drvdata(dev); 326 + int dcdc = rdev_get_id(dev); 327 + int vsel; 328 + 329 + if (dcdc != TPS65023_DCDC_1) 330 + return -EINVAL; 331 + 332 + if (min_uV < tps->info[dcdc]->min_uV 333 + || min_uV > tps->info[dcdc]->max_uV) 334 + return -EINVAL; 335 + if (max_uV < tps->info[dcdc]->min_uV 336 + || max_uV > tps->info[dcdc]->max_uV) 337 + return -EINVAL; 338 + 339 + for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { 340 + int mV = tps->info[dcdc]->table[vsel]; 341 + int uV = mV * 1000; 342 + 343 + /* Break at the first in-range value */ 344 + if (min_uV <= uV && uV <= max_uV) 345 + break; 346 + } 347 + 348 + /* write to the register in case we found a match */ 349 + if (vsel == tps->info[dcdc]->table_len) 350 + return -EINVAL; 351 + else 352 + return tps_65023_reg_write(tps, TPS65023_REG_DEF_CORE, vsel); 353 + } 354 + 355 + static int tps65023_ldo_get_voltage(struct regulator_dev *dev) 356 + { 357 + struct tps_pmic *tps = rdev_get_drvdata(dev); 358 + int data, ldo = rdev_get_id(dev); 359 + 360 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 361 + return -EINVAL; 362 + 363 + data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); 364 + if (data < 0) 365 + return data; 366 + 367 + data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)); 368 + data &= (tps->info[ldo]->table_len - 1); 369 + return tps->info[ldo]->table[data] * 1000; 370 + } 371 + 372 + static int tps65023_ldo_set_voltage(struct regulator_dev *dev, 373 + int min_uV, int max_uV) 374 + { 375 + struct tps_pmic *tps = rdev_get_drvdata(dev); 376 + int data, vsel, ldo = rdev_get_id(dev); 377 + 378 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 379 + return -EINVAL; 380 + 381 + if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) 382 + return -EINVAL; 383 + if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) 384 + return -EINVAL; 385 + 386 + for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { 387 + int mV = tps->info[ldo]->table[vsel]; 388 + int uV = mV * 1000; 389 + 390 + /* Break at the first in-range value */ 391 + if (min_uV <= uV && uV <= max_uV) 392 + break; 393 + } 394 + 395 + if (vsel == tps->info[ldo]->table_len) 396 + return -EINVAL; 397 + 398 + data = tps_65023_reg_read(tps, TPS65023_REG_LDO_CTRL); 399 + if (data < 0) 400 + return data; 401 + 402 + data &= TPS65023_LDO_CTRL_LDOx_MASK(ldo - TPS65023_LDO_1); 403 + data |= (vsel << (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1))); 404 + return tps_65023_reg_write(tps, TPS65023_REG_LDO_CTRL, data); 405 + } 406 + 407 + static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, 408 + unsigned selector) 409 + { 410 + struct tps_pmic *tps = rdev_get_drvdata(dev); 411 + int dcdc = rdev_get_id(dev); 412 + 413 + if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) 414 + return -EINVAL; 415 + 416 + if (dcdc == TPS65023_DCDC_1) { 417 + if (selector >= tps->info[dcdc]->table_len) 418 + return -EINVAL; 419 + else 420 + return tps->info[dcdc]->table[selector] * 1000; 421 + } else 422 + return tps->info[dcdc]->min_uV; 423 + } 424 + 425 + static int tps65023_ldo_list_voltage(struct regulator_dev *dev, 426 + unsigned selector) 427 + { 428 + struct tps_pmic *tps = rdev_get_drvdata(dev); 429 + int ldo = rdev_get_id(dev); 430 + 431 + if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) 432 + return -EINVAL; 433 + 434 + if (selector >= tps->info[ldo]->table_len) 435 + return -EINVAL; 436 + else 437 + return tps->info[ldo]->table[selector] * 1000; 438 + } 439 + 440 + /* Operations permitted on VDCDCx */ 441 + static struct regulator_ops tps65023_dcdc_ops = { 442 + .is_enabled = tps65023_dcdc_is_enabled, 443 + .enable = tps65023_dcdc_enable, 444 + .disable = tps65023_dcdc_disable, 445 + .get_voltage = tps65023_dcdc_get_voltage, 446 + .set_voltage = tps65023_dcdc_set_voltage, 447 + .list_voltage = tps65023_dcdc_list_voltage, 448 + }; 449 + 450 + /* Operations permitted on LDOx */ 451 + static struct regulator_ops tps65023_ldo_ops = { 452 + .is_enabled = tps65023_ldo_is_enabled, 453 + .enable = tps65023_ldo_enable, 454 + .disable = tps65023_ldo_disable, 455 + .get_voltage = tps65023_ldo_get_voltage, 456 + .set_voltage = tps65023_ldo_set_voltage, 457 + .list_voltage = tps65023_ldo_list_voltage, 458 + }; 459 + 460 + static 461 + int tps_65023_probe(struct i2c_client *client, const struct i2c_device_id *id) 462 + { 463 + static int desc_id; 464 + const struct tps_info *info = (void *)id->driver_data; 465 + struct regulator_init_data *init_data; 466 + struct regulator_dev *rdev; 467 + struct tps_pmic *tps; 468 + int i; 469 + 470 + if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 471 + return -EIO; 472 + 473 + /** 474 + * init_data points to array of regulator_init structures 475 + * coming from the board-evm file. 476 + */ 477 + init_data = client->dev.platform_data; 478 + 479 + if (!init_data) 480 + return -EIO; 481 + 482 + tps = kzalloc(sizeof(*tps), GFP_KERNEL); 483 + if (!tps) 484 + return -ENOMEM; 485 + 486 + mutex_init(&tps->io_lock); 487 + 488 + /* common for all regulators */ 489 + tps->client = client; 490 + 491 + for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { 492 + /* Store regulator specific information */ 493 + tps->info[i] = info; 494 + 495 + tps->desc[i].name = info->name; 496 + tps->desc[i].id = desc_id++; 497 + tps->desc[i].n_voltages = num_voltages[i]; 498 + tps->desc[i].ops = (i > TPS65023_DCDC_3 ? 499 + &tps65023_ldo_ops : &tps65023_dcdc_ops); 500 + tps->desc[i].type = REGULATOR_VOLTAGE; 501 + tps->desc[i].owner = THIS_MODULE; 502 + 503 + /* Register the regulators */ 504 + rdev = regulator_register(&tps->desc[i], &client->dev, 505 + init_data, tps); 506 + if (IS_ERR(rdev)) { 507 + dev_err(&client->dev, "failed to register %s\n", 508 + id->name); 509 + 510 + /* Unregister */ 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 + } 521 + 522 + /* Save regulator for cleanup */ 523 + tps->rdev[i] = rdev; 524 + } 525 + 526 + i2c_set_clientdata(client, tps); 527 + 528 + return 0; 529 + } 530 + 531 + /** 532 + * tps_65023_remove - TPS65023 driver i2c remove handler 533 + * @client: i2c driver client device structure 534 + * 535 + * Unregister TPS driver as an i2c client device driver 536 + */ 537 + static int __devexit tps_65023_remove(struct i2c_client *client) 538 + { 539 + struct tps_pmic *tps = i2c_get_clientdata(client); 540 + int i; 541 + 542 + for (i = 0; i < TPS65023_NUM_REGULATOR; i++) 543 + regulator_unregister(tps->rdev[i]); 544 + 545 + tps->client = NULL; 546 + 547 + /* clear the client data in i2c */ 548 + i2c_set_clientdata(client, NULL); 549 + kfree(tps); 550 + 551 + return 0; 552 + } 553 + 554 + static const struct tps_info tps65023_regs[] = { 555 + { 556 + .name = "VDCDC1", 557 + .min_uV = 800000, 558 + .max_uV = 1600000, 559 + .table_len = ARRAY_SIZE(VDCDC1_VSEL_table), 560 + .table = VDCDC1_VSEL_table, 561 + }, 562 + { 563 + .name = "VDCDC2", 564 + .min_uV = 3300000, 565 + .max_uV = 3300000, 566 + .fixed = 1, 567 + }, 568 + { 569 + .name = "VDCDC3", 570 + .min_uV = 1800000, 571 + .max_uV = 1800000, 572 + .fixed = 1, 573 + }, 574 + { 575 + .name = "LDO1", 576 + .min_uV = 1000000, 577 + .max_uV = 3150000, 578 + .table_len = ARRAY_SIZE(LDO1_VSEL_table), 579 + .table = LDO1_VSEL_table, 580 + }, 581 + { 582 + .name = "LDO2", 583 + .min_uV = 1050000, 584 + .max_uV = 3300000, 585 + .table_len = ARRAY_SIZE(LDO2_VSEL_table), 586 + .table = LDO2_VSEL_table, 587 + }, 588 + }; 589 + 590 + static const struct i2c_device_id tps_65023_id[] = { 591 + {.name = "tps65023", 592 + .driver_data = (unsigned long) tps65023_regs,}, 593 + { }, 594 + }; 595 + 596 + MODULE_DEVICE_TABLE(i2c, tps_65023_id); 597 + 598 + static struct i2c_driver tps_65023_i2c_driver = { 599 + .driver = { 600 + .name = "tps65023", 601 + .owner = THIS_MODULE, 602 + }, 603 + .probe = tps_65023_probe, 604 + .remove = __devexit_p(tps_65023_remove), 605 + .id_table = tps_65023_id, 606 + }; 607 + 608 + /** 609 + * tps_65023_init 610 + * 611 + * Module init function 612 + */ 613 + static int __init tps_65023_init(void) 614 + { 615 + return i2c_add_driver(&tps_65023_i2c_driver); 616 + } 617 + subsys_initcall(tps_65023_init); 618 + 619 + /** 620 + * tps_65023_cleanup 621 + * 622 + * Module exit function 623 + */ 624 + static void __exit tps_65023_cleanup(void) 625 + { 626 + i2c_del_driver(&tps_65023_i2c_driver); 627 + } 628 + module_exit(tps_65023_cleanup); 629 + 630 + MODULE_AUTHOR("Texas Instruments"); 631 + MODULE_DESCRIPTION("TPS65023 voltage regulator driver"); 632 + MODULE_LICENSE("GPL v2");
+714
drivers/regulator/tps6507x-regulator.c
··· 1 + /* 2 + * tps6507x-regulator.c 3 + * 4 + * Regulator driver for TPS65073 PMIC 5 + * 6 + * Copyright (C) 2009 Texas Instrument Incorporated - http://www.ti.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 version 2. 11 + * 12 + * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, 13 + * whether express or implied; without even the implied warranty of 14 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 + * General Public License for more details. 16 + */ 17 + 18 + #include <linux/kernel.h> 19 + #include <linux/module.h> 20 + #include <linux/init.h> 21 + #include <linux/err.h> 22 + #include <linux/platform_device.h> 23 + #include <linux/regulator/driver.h> 24 + #include <linux/regulator/machine.h> 25 + #include <linux/i2c.h> 26 + #include <linux/delay.h> 27 + 28 + /* Register definitions */ 29 + #define TPS6507X_REG_PPATH1 0X01 30 + #define TPS6507X_REG_INT 0X02 31 + #define TPS6507X_REG_CHGCONFIG0 0X03 32 + #define TPS6507X_REG_CHGCONFIG1 0X04 33 + #define TPS6507X_REG_CHGCONFIG2 0X05 34 + #define TPS6507X_REG_CHGCONFIG3 0X06 35 + #define TPS6507X_REG_REG_ADCONFIG 0X07 36 + #define TPS6507X_REG_TSCMODE 0X08 37 + #define TPS6507X_REG_ADRESULT_1 0X09 38 + #define TPS6507X_REG_ADRESULT_2 0X0A 39 + #define TPS6507X_REG_PGOOD 0X0B 40 + #define TPS6507X_REG_PGOODMASK 0X0C 41 + #define TPS6507X_REG_CON_CTRL1 0X0D 42 + #define TPS6507X_REG_CON_CTRL2 0X0E 43 + #define TPS6507X_REG_CON_CTRL3 0X0F 44 + #define TPS6507X_REG_DEFDCDC1 0X10 45 + #define TPS6507X_REG_DEFDCDC2_LOW 0X11 46 + #define TPS6507X_REG_DEFDCDC2_HIGH 0X12 47 + #define TPS6507X_REG_DEFDCDC3_LOW 0X13 48 + #define TPS6507X_REG_DEFDCDC3_HIGH 0X14 49 + #define TPS6507X_REG_DEFSLEW 0X15 50 + #define TPS6507X_REG_LDO_CTRL1 0X16 51 + #define TPS6507X_REG_DEFLDO2 0X17 52 + #define TPS6507X_REG_WLED_CTRL1 0X18 53 + #define TPS6507X_REG_WLED_CTRL2 0X19 54 + 55 + /* CON_CTRL1 bitfields */ 56 + #define TPS6507X_CON_CTRL1_DCDC1_ENABLE BIT(4) 57 + #define TPS6507X_CON_CTRL1_DCDC2_ENABLE BIT(3) 58 + #define TPS6507X_CON_CTRL1_DCDC3_ENABLE BIT(2) 59 + #define TPS6507X_CON_CTRL1_LDO1_ENABLE BIT(1) 60 + #define TPS6507X_CON_CTRL1_LDO2_ENABLE BIT(0) 61 + 62 + /* DEFDCDC1 bitfields */ 63 + #define TPS6507X_DEFDCDC1_DCDC1_EXT_ADJ_EN BIT(7) 64 + #define TPS6507X_DEFDCDC1_DCDC1_MASK 0X3F 65 + 66 + /* DEFDCDC2_LOW bitfields */ 67 + #define TPS6507X_DEFDCDC2_LOW_DCDC2_MASK 0X3F 68 + 69 + /* DEFDCDC2_HIGH bitfields */ 70 + #define TPS6507X_DEFDCDC2_HIGH_DCDC2_MASK 0X3F 71 + 72 + /* DEFDCDC3_LOW bitfields */ 73 + #define TPS6507X_DEFDCDC3_LOW_DCDC3_MASK 0X3F 74 + 75 + /* DEFDCDC3_HIGH bitfields */ 76 + #define TPS6507X_DEFDCDC3_HIGH_DCDC3_MASK 0X3F 77 + 78 + /* TPS6507X_REG_LDO_CTRL1 bitfields */ 79 + #define TPS6507X_REG_LDO_CTRL1_LDO1_MASK 0X0F 80 + 81 + /* TPS6507X_REG_DEFLDO2 bitfields */ 82 + #define TPS6507X_REG_DEFLDO2_LDO2_MASK 0X3F 83 + 84 + /* VDCDC MASK */ 85 + #define TPS6507X_DEFDCDCX_DCDC_MASK 0X3F 86 + 87 + /* DCDC's */ 88 + #define TPS6507X_DCDC_1 0 89 + #define TPS6507X_DCDC_2 1 90 + #define TPS6507X_DCDC_3 2 91 + /* LDOs */ 92 + #define TPS6507X_LDO_1 3 93 + #define TPS6507X_LDO_2 4 94 + 95 + #define TPS6507X_MAX_REG_ID TPS6507X_LDO_2 96 + 97 + /* Number of step-down converters available */ 98 + #define TPS6507X_NUM_DCDC 3 99 + /* Number of LDO voltage regulators available */ 100 + #define TPS6507X_NUM_LDO 2 101 + /* Number of total regulators available */ 102 + #define TPS6507X_NUM_REGULATOR (TPS6507X_NUM_DCDC + TPS6507X_NUM_LDO) 103 + 104 + /* Supported voltage values for regulators (in milliVolts) */ 105 + static const u16 VDCDCx_VSEL_table[] = { 106 + 725, 750, 775, 800, 107 + 825, 850, 875, 900, 108 + 925, 950, 975, 1000, 109 + 1025, 1050, 1075, 1100, 110 + 1125, 1150, 1175, 1200, 111 + 1225, 1250, 1275, 1300, 112 + 1325, 1350, 1375, 1400, 113 + 1425, 1450, 1475, 1500, 114 + 1550, 1600, 1650, 1700, 115 + 1750, 1800, 1850, 1900, 116 + 1950, 2000, 2050, 2100, 117 + 2150, 2200, 2250, 2300, 118 + 2350, 2400, 2450, 2500, 119 + 2550, 2600, 2650, 2700, 120 + 2750, 2800, 2850, 2900, 121 + 3000, 3100, 3200, 3300, 122 + }; 123 + 124 + static const u16 LDO1_VSEL_table[] = { 125 + 1000, 1100, 1200, 1250, 126 + 1300, 1350, 1400, 1500, 127 + 1600, 1800, 2500, 2750, 128 + 2800, 3000, 3100, 3300, 129 + }; 130 + 131 + static const u16 LDO2_VSEL_table[] = { 132 + 725, 750, 775, 800, 133 + 825, 850, 875, 900, 134 + 925, 950, 975, 1000, 135 + 1025, 1050, 1075, 1100, 136 + 1125, 1150, 1175, 1200, 137 + 1225, 1250, 1275, 1300, 138 + 1325, 1350, 1375, 1400, 139 + 1425, 1450, 1475, 1500, 140 + 1550, 1600, 1650, 1700, 141 + 1750, 1800, 1850, 1900, 142 + 1950, 2000, 2050, 2100, 143 + 2150, 2200, 2250, 2300, 144 + 2350, 2400, 2450, 2500, 145 + 2550, 2600, 2650, 2700, 146 + 2750, 2800, 2850, 2900, 147 + 3000, 3100, 3200, 3300, 148 + }; 149 + 150 + static unsigned int num_voltages[] = {ARRAY_SIZE(VDCDCx_VSEL_table), 151 + ARRAY_SIZE(VDCDCx_VSEL_table), 152 + ARRAY_SIZE(VDCDCx_VSEL_table), 153 + ARRAY_SIZE(LDO1_VSEL_table), 154 + ARRAY_SIZE(LDO2_VSEL_table)}; 155 + 156 + struct tps_info { 157 + const char *name; 158 + unsigned min_uV; 159 + unsigned max_uV; 160 + u8 table_len; 161 + const u16 *table; 162 + }; 163 + 164 + struct tps_pmic { 165 + struct regulator_desc desc[TPS6507X_NUM_REGULATOR]; 166 + struct i2c_client *client; 167 + struct regulator_dev *rdev[TPS6507X_NUM_REGULATOR]; 168 + const struct tps_info *info[TPS6507X_NUM_REGULATOR]; 169 + struct mutex io_lock; 170 + }; 171 + 172 + static inline int tps_6507x_read(struct tps_pmic *tps, u8 reg) 173 + { 174 + return i2c_smbus_read_byte_data(tps->client, reg); 175 + } 176 + 177 + static inline int tps_6507x_write(struct tps_pmic *tps, u8 reg, u8 val) 178 + { 179 + return i2c_smbus_write_byte_data(tps->client, reg, val); 180 + } 181 + 182 + static int tps_6507x_set_bits(struct tps_pmic *tps, u8 reg, u8 mask) 183 + { 184 + int err, data; 185 + 186 + mutex_lock(&tps->io_lock); 187 + 188 + data = tps_6507x_read(tps, reg); 189 + if (data < 0) { 190 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 191 + err = data; 192 + goto out; 193 + } 194 + 195 + data |= mask; 196 + err = tps_6507x_write(tps, reg, data); 197 + if (err) 198 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 199 + 200 + out: 201 + mutex_unlock(&tps->io_lock); 202 + return err; 203 + } 204 + 205 + static int tps_6507x_clear_bits(struct tps_pmic *tps, u8 reg, u8 mask) 206 + { 207 + int err, data; 208 + 209 + mutex_lock(&tps->io_lock); 210 + 211 + data = tps_6507x_read(tps, reg); 212 + if (data < 0) { 213 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 214 + err = data; 215 + goto out; 216 + } 217 + 218 + data &= ~mask; 219 + err = tps_6507x_write(tps, reg, data); 220 + if (err) 221 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 222 + 223 + out: 224 + mutex_unlock(&tps->io_lock); 225 + return err; 226 + } 227 + 228 + static int tps_6507x_reg_read(struct tps_pmic *tps, u8 reg) 229 + { 230 + int data; 231 + 232 + mutex_lock(&tps->io_lock); 233 + 234 + data = tps_6507x_read(tps, reg); 235 + if (data < 0) 236 + dev_err(&tps->client->dev, "Read from reg 0x%x failed\n", reg); 237 + 238 + mutex_unlock(&tps->io_lock); 239 + return data; 240 + } 241 + 242 + static int tps_6507x_reg_write(struct tps_pmic *tps, u8 reg, u8 val) 243 + { 244 + int err; 245 + 246 + mutex_lock(&tps->io_lock); 247 + 248 + err = tps_6507x_write(tps, reg, val); 249 + if (err < 0) 250 + dev_err(&tps->client->dev, "Write for reg 0x%x failed\n", reg); 251 + 252 + mutex_unlock(&tps->io_lock); 253 + return err; 254 + } 255 + 256 + static int tps6507x_dcdc_is_enabled(struct regulator_dev *dev) 257 + { 258 + struct tps_pmic *tps = rdev_get_drvdata(dev); 259 + int data, dcdc = rdev_get_id(dev); 260 + u8 shift; 261 + 262 + if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 263 + return -EINVAL; 264 + 265 + shift = TPS6507X_MAX_REG_ID - dcdc; 266 + data = tps_6507x_reg_read(tps, TPS6507X_REG_CON_CTRL1); 267 + 268 + if (data < 0) 269 + return data; 270 + else 271 + return (data & 1<<shift) ? 1 : 0; 272 + } 273 + 274 + static int tps6507x_ldo_is_enabled(struct regulator_dev *dev) 275 + { 276 + struct tps_pmic *tps = rdev_get_drvdata(dev); 277 + int data, ldo = rdev_get_id(dev); 278 + u8 shift; 279 + 280 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 281 + return -EINVAL; 282 + 283 + shift = TPS6507X_MAX_REG_ID - ldo; 284 + data = tps_6507x_reg_read(tps, TPS6507X_REG_CON_CTRL1); 285 + 286 + if (data < 0) 287 + return data; 288 + else 289 + return (data & 1<<shift) ? 1 : 0; 290 + } 291 + 292 + static int tps6507x_dcdc_enable(struct regulator_dev *dev) 293 + { 294 + struct tps_pmic *tps = rdev_get_drvdata(dev); 295 + int dcdc = rdev_get_id(dev); 296 + u8 shift; 297 + 298 + if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 299 + return -EINVAL; 300 + 301 + shift = TPS6507X_MAX_REG_ID - dcdc; 302 + return tps_6507x_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 303 + } 304 + 305 + static int tps6507x_dcdc_disable(struct regulator_dev *dev) 306 + { 307 + struct tps_pmic *tps = rdev_get_drvdata(dev); 308 + int dcdc = rdev_get_id(dev); 309 + u8 shift; 310 + 311 + if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 312 + return -EINVAL; 313 + 314 + shift = TPS6507X_MAX_REG_ID - dcdc; 315 + return tps_6507x_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 316 + } 317 + 318 + static int tps6507x_ldo_enable(struct regulator_dev *dev) 319 + { 320 + struct tps_pmic *tps = rdev_get_drvdata(dev); 321 + int ldo = rdev_get_id(dev); 322 + u8 shift; 323 + 324 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 325 + return -EINVAL; 326 + 327 + shift = TPS6507X_MAX_REG_ID - ldo; 328 + return tps_6507x_set_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 329 + } 330 + 331 + static int tps6507x_ldo_disable(struct regulator_dev *dev) 332 + { 333 + struct tps_pmic *tps = rdev_get_drvdata(dev); 334 + int ldo = rdev_get_id(dev); 335 + u8 shift; 336 + 337 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 338 + return -EINVAL; 339 + 340 + shift = TPS6507X_MAX_REG_ID - ldo; 341 + return tps_6507x_clear_bits(tps, TPS6507X_REG_CON_CTRL1, 1 << shift); 342 + } 343 + 344 + static int tps6507x_dcdc_get_voltage(struct regulator_dev *dev) 345 + { 346 + struct tps_pmic *tps = rdev_get_drvdata(dev); 347 + int data, dcdc = rdev_get_id(dev); 348 + u8 reg; 349 + 350 + switch (dcdc) { 351 + case TPS6507X_DCDC_1: 352 + reg = TPS6507X_REG_DEFDCDC1; 353 + break; 354 + case TPS6507X_DCDC_2: 355 + reg = TPS6507X_REG_DEFDCDC2_LOW; 356 + break; 357 + case TPS6507X_DCDC_3: 358 + reg = TPS6507X_REG_DEFDCDC3_LOW; 359 + break; 360 + default: 361 + return -EINVAL; 362 + } 363 + 364 + data = tps_6507x_reg_read(tps, reg); 365 + if (data < 0) 366 + return data; 367 + 368 + data &= TPS6507X_DEFDCDCX_DCDC_MASK; 369 + return tps->info[dcdc]->table[data] * 1000; 370 + } 371 + 372 + static int tps6507x_dcdc_set_voltage(struct regulator_dev *dev, 373 + int min_uV, int max_uV) 374 + { 375 + struct tps_pmic *tps = rdev_get_drvdata(dev); 376 + int data, vsel, dcdc = rdev_get_id(dev); 377 + u8 reg; 378 + 379 + switch (dcdc) { 380 + case TPS6507X_DCDC_1: 381 + reg = TPS6507X_REG_DEFDCDC1; 382 + break; 383 + case TPS6507X_DCDC_2: 384 + reg = TPS6507X_REG_DEFDCDC2_LOW; 385 + break; 386 + case TPS6507X_DCDC_3: 387 + reg = TPS6507X_REG_DEFDCDC3_LOW; 388 + break; 389 + default: 390 + return -EINVAL; 391 + } 392 + 393 + if (min_uV < tps->info[dcdc]->min_uV 394 + || min_uV > tps->info[dcdc]->max_uV) 395 + return -EINVAL; 396 + if (max_uV < tps->info[dcdc]->min_uV 397 + || max_uV > tps->info[dcdc]->max_uV) 398 + return -EINVAL; 399 + 400 + for (vsel = 0; vsel < tps->info[dcdc]->table_len; vsel++) { 401 + int mV = tps->info[dcdc]->table[vsel]; 402 + int uV = mV * 1000; 403 + 404 + /* Break at the first in-range value */ 405 + if (min_uV <= uV && uV <= max_uV) 406 + break; 407 + } 408 + 409 + /* write to the register in case we found a match */ 410 + if (vsel == tps->info[dcdc]->table_len) 411 + return -EINVAL; 412 + 413 + data = tps_6507x_reg_read(tps, reg); 414 + if (data < 0) 415 + return data; 416 + 417 + data &= ~TPS6507X_DEFDCDCX_DCDC_MASK; 418 + data |= vsel; 419 + 420 + return tps_6507x_reg_write(tps, reg, data); 421 + } 422 + 423 + static int tps6507x_ldo_get_voltage(struct regulator_dev *dev) 424 + { 425 + struct tps_pmic *tps = rdev_get_drvdata(dev); 426 + int data, ldo = rdev_get_id(dev); 427 + u8 reg, mask; 428 + 429 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 430 + return -EINVAL; 431 + else { 432 + reg = (ldo == TPS6507X_LDO_1 ? 433 + TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); 434 + mask = (ldo == TPS6507X_LDO_1 ? 435 + TPS6507X_REG_LDO_CTRL1_LDO1_MASK : 436 + TPS6507X_REG_DEFLDO2_LDO2_MASK); 437 + } 438 + 439 + data = tps_6507x_reg_read(tps, reg); 440 + if (data < 0) 441 + return data; 442 + 443 + data &= mask; 444 + return tps->info[ldo]->table[data] * 1000; 445 + } 446 + 447 + static int tps6507x_ldo_set_voltage(struct regulator_dev *dev, 448 + int min_uV, int max_uV) 449 + { 450 + struct tps_pmic *tps = rdev_get_drvdata(dev); 451 + int data, vsel, ldo = rdev_get_id(dev); 452 + u8 reg, mask; 453 + 454 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 455 + return -EINVAL; 456 + else { 457 + reg = (ldo == TPS6507X_LDO_1 ? 458 + TPS6507X_REG_LDO_CTRL1 : TPS6507X_REG_DEFLDO2); 459 + mask = (ldo == TPS6507X_LDO_1 ? 460 + TPS6507X_REG_LDO_CTRL1_LDO1_MASK : 461 + TPS6507X_REG_DEFLDO2_LDO2_MASK); 462 + } 463 + 464 + if (min_uV < tps->info[ldo]->min_uV || min_uV > tps->info[ldo]->max_uV) 465 + return -EINVAL; 466 + if (max_uV < tps->info[ldo]->min_uV || max_uV > tps->info[ldo]->max_uV) 467 + return -EINVAL; 468 + 469 + for (vsel = 0; vsel < tps->info[ldo]->table_len; vsel++) { 470 + int mV = tps->info[ldo]->table[vsel]; 471 + int uV = mV * 1000; 472 + 473 + /* Break at the first in-range value */ 474 + if (min_uV <= uV && uV <= max_uV) 475 + break; 476 + } 477 + 478 + if (vsel == tps->info[ldo]->table_len) 479 + return -EINVAL; 480 + 481 + data = tps_6507x_reg_read(tps, reg); 482 + if (data < 0) 483 + return data; 484 + 485 + data &= ~mask; 486 + data |= vsel; 487 + 488 + return tps_6507x_reg_write(tps, reg, data); 489 + } 490 + 491 + static int tps6507x_dcdc_list_voltage(struct regulator_dev *dev, 492 + unsigned selector) 493 + { 494 + struct tps_pmic *tps = rdev_get_drvdata(dev); 495 + int dcdc = rdev_get_id(dev); 496 + 497 + if (dcdc < TPS6507X_DCDC_1 || dcdc > TPS6507X_DCDC_3) 498 + return -EINVAL; 499 + 500 + if (selector >= tps->info[dcdc]->table_len) 501 + return -EINVAL; 502 + else 503 + return tps->info[dcdc]->table[selector] * 1000; 504 + } 505 + 506 + static int tps6507x_ldo_list_voltage(struct regulator_dev *dev, 507 + unsigned selector) 508 + { 509 + struct tps_pmic *tps = rdev_get_drvdata(dev); 510 + int ldo = rdev_get_id(dev); 511 + 512 + if (ldo < TPS6507X_LDO_1 || ldo > TPS6507X_LDO_2) 513 + return -EINVAL; 514 + 515 + if (selector >= tps->info[ldo]->table_len) 516 + return -EINVAL; 517 + else 518 + return tps->info[ldo]->table[selector] * 1000; 519 + } 520 + 521 + /* Operations permitted on VDCDCx */ 522 + static struct regulator_ops tps6507x_dcdc_ops = { 523 + .is_enabled = tps6507x_dcdc_is_enabled, 524 + .enable = tps6507x_dcdc_enable, 525 + .disable = tps6507x_dcdc_disable, 526 + .get_voltage = tps6507x_dcdc_get_voltage, 527 + .set_voltage = tps6507x_dcdc_set_voltage, 528 + .list_voltage = tps6507x_dcdc_list_voltage, 529 + }; 530 + 531 + /* Operations permitted on LDOx */ 532 + static struct regulator_ops tps6507x_ldo_ops = { 533 + .is_enabled = tps6507x_ldo_is_enabled, 534 + .enable = tps6507x_ldo_enable, 535 + .disable = tps6507x_ldo_disable, 536 + .get_voltage = tps6507x_ldo_get_voltage, 537 + .set_voltage = tps6507x_ldo_set_voltage, 538 + .list_voltage = tps6507x_ldo_list_voltage, 539 + }; 540 + 541 + static 542 + int tps_6507x_probe(struct i2c_client *client, const struct i2c_device_id *id) 543 + { 544 + static int desc_id; 545 + const struct tps_info *info = (void *)id->driver_data; 546 + struct regulator_init_data *init_data; 547 + struct regulator_dev *rdev; 548 + struct tps_pmic *tps; 549 + int i; 550 + 551 + if (!i2c_check_functionality(client->adapter, 552 + I2C_FUNC_SMBUS_BYTE_DATA)) 553 + return -EIO; 554 + 555 + /** 556 + * init_data points to array of regulator_init structures 557 + * coming from the board-evm file. 558 + */ 559 + init_data = client->dev.platform_data; 560 + 561 + if (!init_data) 562 + return -EIO; 563 + 564 + tps = kzalloc(sizeof(*tps), GFP_KERNEL); 565 + if (!tps) 566 + return -ENOMEM; 567 + 568 + mutex_init(&tps->io_lock); 569 + 570 + /* common for all regulators */ 571 + tps->client = client; 572 + 573 + for (i = 0; i < TPS6507X_NUM_REGULATOR; i++, info++, init_data++) { 574 + /* Register the regulators */ 575 + tps->info[i] = info; 576 + tps->desc[i].name = info->name; 577 + tps->desc[i].id = desc_id++; 578 + tps->desc[i].n_voltages = num_voltages[i]; 579 + tps->desc[i].ops = (i > TPS6507X_DCDC_3 ? 580 + &tps6507x_ldo_ops : &tps6507x_dcdc_ops); 581 + tps->desc[i].type = REGULATOR_VOLTAGE; 582 + tps->desc[i].owner = THIS_MODULE; 583 + 584 + rdev = regulator_register(&tps->desc[i], 585 + &client->dev, init_data, tps); 586 + if (IS_ERR(rdev)) { 587 + dev_err(&client->dev, "failed to register %s\n", 588 + id->name); 589 + 590 + /* Unregister */ 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 + } 602 + 603 + /* Save regulator for cleanup */ 604 + tps->rdev[i] = rdev; 605 + } 606 + 607 + i2c_set_clientdata(client, tps); 608 + 609 + return 0; 610 + } 611 + 612 + /** 613 + * tps_6507x_remove - TPS6507x driver i2c remove handler 614 + * @client: i2c driver client device structure 615 + * 616 + * Unregister TPS driver as an i2c client device driver 617 + */ 618 + static int __devexit tps_6507x_remove(struct i2c_client *client) 619 + { 620 + struct tps_pmic *tps = i2c_get_clientdata(client); 621 + int i; 622 + 623 + for (i = 0; i < TPS6507X_NUM_REGULATOR; i++) 624 + regulator_unregister(tps->rdev[i]); 625 + 626 + tps->client = NULL; 627 + 628 + /* clear the client data in i2c */ 629 + i2c_set_clientdata(client, NULL); 630 + kfree(tps); 631 + 632 + return 0; 633 + } 634 + 635 + static const struct tps_info tps6507x_regs[] = { 636 + { 637 + .name = "VDCDC1", 638 + .min_uV = 725000, 639 + .max_uV = 3300000, 640 + .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 641 + .table = VDCDCx_VSEL_table, 642 + }, 643 + { 644 + .name = "VDCDC2", 645 + .min_uV = 725000, 646 + .max_uV = 3300000, 647 + .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 648 + .table = VDCDCx_VSEL_table, 649 + }, 650 + { 651 + .name = "VDCDC3", 652 + .min_uV = 725000, 653 + .max_uV = 3300000, 654 + .table_len = ARRAY_SIZE(VDCDCx_VSEL_table), 655 + .table = VDCDCx_VSEL_table, 656 + }, 657 + { 658 + .name = "LDO1", 659 + .min_uV = 1000000, 660 + .max_uV = 3300000, 661 + .table_len = ARRAY_SIZE(LDO1_VSEL_table), 662 + .table = LDO1_VSEL_table, 663 + }, 664 + { 665 + .name = "LDO2", 666 + .min_uV = 725000, 667 + .max_uV = 3300000, 668 + .table_len = ARRAY_SIZE(LDO2_VSEL_table), 669 + .table = LDO2_VSEL_table, 670 + }, 671 + }; 672 + 673 + static const struct i2c_device_id tps_6507x_id[] = { 674 + {.name = "tps6507x", 675 + .driver_data = (unsigned long) tps6507x_regs,}, 676 + { }, 677 + }; 678 + MODULE_DEVICE_TABLE(i2c, tps_6507x_id); 679 + 680 + static struct i2c_driver tps_6507x_i2c_driver = { 681 + .driver = { 682 + .name = "tps6507x", 683 + .owner = THIS_MODULE, 684 + }, 685 + .probe = tps_6507x_probe, 686 + .remove = __devexit_p(tps_6507x_remove), 687 + .id_table = tps_6507x_id, 688 + }; 689 + 690 + /** 691 + * tps_6507x_init 692 + * 693 + * Module init function 694 + */ 695 + static int __init tps_6507x_init(void) 696 + { 697 + return i2c_add_driver(&tps_6507x_i2c_driver); 698 + } 699 + subsys_initcall(tps_6507x_init); 700 + 701 + /** 702 + * tps_6507x_cleanup 703 + * 704 + * Module exit function 705 + */ 706 + static void __exit tps_6507x_cleanup(void) 707 + { 708 + i2c_del_driver(&tps_6507x_i2c_driver); 709 + } 710 + module_exit(tps_6507x_cleanup); 711 + 712 + MODULE_AUTHOR("Texas Instruments"); 713 + MODULE_DESCRIPTION("TPS6507x voltage regulator driver"); 714 + MODULE_LICENSE("GPL v2");
+23 -22
drivers/regulator/userspace-consumer.c
··· 93 93 static DEVICE_ATTR(name, 0444, reg_show_name, NULL); 94 94 static DEVICE_ATTR(state, 0644, reg_show_state, reg_set_state); 95 95 96 - static struct device_attribute *attributes[] = { 97 - &dev_attr_name, 98 - &dev_attr_state, 96 + static struct attribute *attributes[] = { 97 + &dev_attr_name.attr, 98 + &dev_attr_state.attr, 99 + NULL, 100 + }; 101 + 102 + static const struct attribute_group attr_group = { 103 + .attrs = attributes, 99 104 }; 100 105 101 106 static int regulator_userspace_consumer_probe(struct platform_device *pdev) 102 107 { 103 108 struct regulator_userspace_consumer_data *pdata; 104 109 struct userspace_consumer_data *drvdata; 105 - int ret, i; 110 + int ret; 106 111 107 112 pdata = pdev->dev.platform_data; 108 113 if (!pdata) ··· 130 125 goto err_alloc_supplies; 131 126 } 132 127 133 - for (i = 0; i < ARRAY_SIZE(attributes); i++) { 134 - ret = device_create_file(&pdev->dev, attributes[i]); 135 - if (ret != 0) 136 - goto err_create_attrs; 137 - } 128 + ret = sysfs_create_group(&pdev->dev.kobj, &attr_group); 129 + if (ret != 0) 130 + goto err_create_attrs; 138 131 139 - if (pdata->init_on) 132 + if (pdata->init_on) { 140 133 ret = regulator_bulk_enable(drvdata->num_supplies, 141 134 drvdata->supplies); 142 - 143 - drvdata->enabled = pdata->init_on; 144 - 145 - if (ret) { 146 - dev_err(&pdev->dev, "Failed to set initial state: %d\n", ret); 147 - goto err_create_attrs; 135 + if (ret) { 136 + dev_err(&pdev->dev, 137 + "Failed to set initial state: %d\n", ret); 138 + goto err_enable; 139 + } 148 140 } 149 141 142 + drvdata->enabled = pdata->init_on; 150 143 platform_set_drvdata(pdev, drvdata); 151 144 152 145 return 0; 153 146 154 - err_create_attrs: 155 - for (i = 0; i < ARRAY_SIZE(attributes); i++) 156 - device_remove_file(&pdev->dev, attributes[i]); 147 + err_enable: 148 + sysfs_remove_group(&pdev->dev.kobj, &attr_group); 157 149 150 + err_create_attrs: 158 151 regulator_bulk_free(drvdata->num_supplies, drvdata->supplies); 159 152 160 153 err_alloc_supplies: ··· 163 160 static int regulator_userspace_consumer_remove(struct platform_device *pdev) 164 161 { 165 162 struct userspace_consumer_data *data = platform_get_drvdata(pdev); 166 - int i; 167 163 168 - for (i = 0; i < ARRAY_SIZE(attributes); i++) 169 - device_remove_file(&pdev->dev, attributes[i]); 164 + sysfs_remove_group(&pdev->dev.kobj, &attr_group); 170 165 171 166 if (data->enabled) 172 167 regulator_bulk_disable(data->num_supplies, data->supplies);
+36 -20
drivers/regulator/virtual.c
··· 27 27 unsigned int mode; 28 28 }; 29 29 30 - static void update_voltage_constraints(struct virtual_consumer_data *data) 30 + static void update_voltage_constraints(struct device *dev, 31 + struct virtual_consumer_data *data) 31 32 { 32 33 int ret; 33 34 34 35 if (data->min_uV && data->max_uV 35 36 && data->min_uV <= data->max_uV) { 37 + dev_dbg(dev, "Requesting %d-%duV\n", 38 + data->min_uV, data->max_uV); 36 39 ret = regulator_set_voltage(data->regulator, 37 - data->min_uV, data->max_uV); 40 + data->min_uV, data->max_uV); 38 41 if (ret != 0) { 39 - printk(KERN_ERR "regulator_set_voltage() failed: %d\n", 40 - ret); 42 + dev_err(dev, 43 + "regulator_set_voltage() failed: %d\n", ret); 41 44 return; 42 45 } 43 46 } 44 47 45 48 if (data->min_uV && data->max_uV && !data->enabled) { 49 + dev_dbg(dev, "Enabling regulator\n"); 46 50 ret = regulator_enable(data->regulator); 47 51 if (ret == 0) 48 52 data->enabled = 1; 49 53 else 50 - printk(KERN_ERR "regulator_enable() failed: %d\n", 54 + dev_err(dev, "regulator_enable() failed: %d\n", 51 55 ret); 52 56 } 53 57 54 58 if (!(data->min_uV && data->max_uV) && data->enabled) { 59 + dev_dbg(dev, "Disabling regulator\n"); 55 60 ret = regulator_disable(data->regulator); 56 61 if (ret == 0) 57 62 data->enabled = 0; 58 63 else 59 - printk(KERN_ERR "regulator_disable() failed: %d\n", 64 + dev_err(dev, "regulator_disable() failed: %d\n", 60 65 ret); 61 66 } 62 67 } 63 68 64 - static void update_current_limit_constraints(struct virtual_consumer_data 65 - *data) 69 + static void update_current_limit_constraints(struct device *dev, 70 + struct virtual_consumer_data *data) 66 71 { 67 72 int ret; 68 73 69 74 if (data->max_uA 70 75 && data->min_uA <= data->max_uA) { 76 + dev_dbg(dev, "Requesting %d-%duA\n", 77 + data->min_uA, data->max_uA); 71 78 ret = regulator_set_current_limit(data->regulator, 72 79 data->min_uA, data->max_uA); 73 80 if (ret != 0) { 74 - pr_err("regulator_set_current_limit() failed: %d\n", 75 - ret); 81 + dev_err(dev, 82 + "regulator_set_current_limit() failed: %d\n", 83 + ret); 76 84 return; 77 85 } 78 86 } 79 87 80 88 if (data->max_uA && !data->enabled) { 89 + dev_dbg(dev, "Enabling regulator\n"); 81 90 ret = regulator_enable(data->regulator); 82 91 if (ret == 0) 83 92 data->enabled = 1; 84 93 else 85 - printk(KERN_ERR "regulator_enable() failed: %d\n", 94 + dev_err(dev, "regulator_enable() failed: %d\n", 86 95 ret); 87 96 } 88 97 89 98 if (!(data->min_uA && data->max_uA) && data->enabled) { 99 + dev_dbg(dev, "Disabling regulator\n"); 90 100 ret = regulator_disable(data->regulator); 91 101 if (ret == 0) 92 102 data->enabled = 0; 93 103 else 94 - printk(KERN_ERR "regulator_disable() failed: %d\n", 104 + dev_err(dev, "regulator_disable() failed: %d\n", 95 105 ret); 96 106 } 97 107 } ··· 125 115 mutex_lock(&data->lock); 126 116 127 117 data->min_uV = val; 128 - update_voltage_constraints(data); 118 + update_voltage_constraints(dev, data); 129 119 130 120 mutex_unlock(&data->lock); 131 121 ··· 151 141 mutex_lock(&data->lock); 152 142 153 143 data->max_uV = val; 154 - update_voltage_constraints(data); 144 + update_voltage_constraints(dev, data); 155 145 156 146 mutex_unlock(&data->lock); 157 147 ··· 177 167 mutex_lock(&data->lock); 178 168 179 169 data->min_uA = val; 180 - update_current_limit_constraints(data); 170 + update_current_limit_constraints(dev, data); 181 171 182 172 mutex_unlock(&data->lock); 183 173 ··· 203 193 mutex_lock(&data->lock); 204 194 205 195 data->max_uA = val; 206 - update_current_limit_constraints(data); 196 + update_current_limit_constraints(dev, data); 207 197 208 198 mutex_unlock(&data->lock); 209 199 ··· 286 276 287 277 drvdata = kzalloc(sizeof(struct virtual_consumer_data), GFP_KERNEL); 288 278 if (drvdata == NULL) { 289 - ret = -ENOMEM; 290 - goto err; 279 + return -ENOMEM; 291 280 } 292 281 293 282 mutex_init(&drvdata->lock); ··· 294 285 drvdata->regulator = regulator_get(&pdev->dev, reg_id); 295 286 if (IS_ERR(drvdata->regulator)) { 296 287 ret = PTR_ERR(drvdata->regulator); 288 + dev_err(&pdev->dev, "Failed to obtain supply '%s': %d\n", 289 + reg_id, ret); 297 290 goto err; 298 291 } 299 292 300 293 for (i = 0; i < ARRAY_SIZE(attributes); i++) { 301 294 ret = device_create_file(&pdev->dev, attributes[i]); 302 - if (ret != 0) 303 - goto err; 295 + if (ret != 0) { 296 + dev_err(&pdev->dev, "Failed to create attr %d: %d\n", 297 + i, ret); 298 + goto err_regulator; 299 + } 304 300 } 305 301 306 302 drvdata->mode = regulator_get_mode(drvdata->regulator); ··· 314 300 315 301 return 0; 316 302 303 + err_regulator: 304 + regulator_put(drvdata->regulator); 317 305 err: 318 306 for (i = 0; i < ARRAY_SIZE(attributes); i++) 319 307 device_remove_file(&pdev->dev, attributes[i]);
+2
drivers/regulator/wm8350-regulator.c
··· 1419 1419 { 1420 1420 struct platform_device *pdev; 1421 1421 int ret; 1422 + if (reg < 0 || reg >= NUM_WM8350_REGULATORS) 1423 + return -EINVAL; 1422 1424 1423 1425 if (wm8350->pmic.pdev[reg]) 1424 1426 return -EBUSY;
+3 -1
include/linux/mfd/da903x.h
··· 1 1 #ifndef __LINUX_PMIC_DA903X_H 2 2 #define __LINUX_PMIC_DA903X_H 3 3 4 - /* Unified sub device IDs for DA9030/DA9034 */ 4 + /* Unified sub device IDs for DA9030/DA9034/DA9035 */ 5 5 enum { 6 6 DA9030_ID_LED_1, 7 7 DA9030_ID_LED_2, ··· 57 57 DA9034_ID_LDO13, 58 58 DA9034_ID_LDO14, 59 59 DA9034_ID_LDO15, 60 + 61 + DA9035_ID_BUCK3, 60 62 }; 61 63 62 64 /*
+4
include/linux/regulator/consumer.h
··· 125 125 /* regulator get and put */ 126 126 struct regulator *__must_check regulator_get(struct device *dev, 127 127 const char *id); 128 + struct regulator *__must_check regulator_get_exclusive(struct device *dev, 129 + const char *id); 128 130 void regulator_put(struct regulator *regulator); 129 131 130 132 /* regulator output control and status */ ··· 146 144 147 145 int regulator_count_voltages(struct regulator *regulator); 148 146 int regulator_list_voltage(struct regulator *regulator, unsigned selector); 147 + int regulator_is_supported_voltage(struct regulator *regulator, 148 + int min_uV, int max_uV); 149 149 int regulator_set_voltage(struct regulator *regulator, int min_uV, int max_uV); 150 150 int regulator_get_voltage(struct regulator *regulator); 151 151 int regulator_set_current_limit(struct regulator *regulator,
+4 -1
include/linux/regulator/driver.h
··· 37 37 * 38 38 * @enable: Configure the regulator as enabled. 39 39 * @disable: Configure the regulator as disabled. 40 - * @is_enabled: Return 1 if the regulator is enabled, 0 otherwise. 40 + * @is_enabled: Return 1 if the regulator is enabled, 0 if not. 41 + * May also return negative errno. 41 42 * 42 43 * @set_voltage: Set the voltage for the regulator within the range specified. 43 44 * The driver should select the voltage closest to min_uV. ··· 163 162 struct regulator_dev { 164 163 struct regulator_desc *desc; 165 164 int use_count; 165 + int open_count; 166 + int exclusive; 166 167 167 168 /* lists we belong to */ 168 169 struct list_head list; /* list of all regulators */
+24
include/linux/regulator/fixed.h
··· 5 5 * 6 6 * Author: Mark Brown <broonie@opensource.wolfsonmicro.com> 7 7 * 8 + * Copyright (c) 2009 Nokia Corporation 9 + * Roger Quadros <ext-roger.quadros@nokia.com> 10 + * 8 11 * This program is free software; you can redistribute it and/or 9 12 * modify it under the terms of the GNU General Public License as 10 13 * published by the Free Software Foundation; either version 2 of the ··· 19 16 20 17 struct regulator_init_data; 21 18 19 + /** 20 + * struct fixed_voltage_config - fixed_voltage_config structure 21 + * @supply_name: Name of the regulator supply 22 + * @microvolts: Output voltage of regulator 23 + * @gpio: GPIO to use for enable control 24 + * set to -EINVAL if not used 25 + * @enable_high: Polarity of enable GPIO 26 + * 1 = Active high, 0 = Active low 27 + * @enabled_at_boot: Whether regulator has been enabled at 28 + * boot or not. 1 = Yes, 0 = No 29 + * This is used to keep the regulator at 30 + * the default state 31 + * @init_data: regulator_init_data 32 + * 33 + * This structure contains fixed voltage regulator configuration 34 + * information that must be passed by platform code to the fixed 35 + * voltage regulator driver. 36 + */ 22 37 struct fixed_voltage_config { 23 38 const char *supply_name; 24 39 int microvolts; 40 + int gpio; 41 + unsigned enable_high:1; 42 + unsigned enabled_at_boot:1; 25 43 struct regulator_init_data *init_data; 26 44 }; 27 45
+22 -4
include/linux/regulator/machine.h
··· 41 41 #define REGULATOR_CHANGE_DRMS 0x10 42 42 43 43 /** 44 - * struct regulator_state - regulator state during low power syatem states 44 + * struct regulator_state - regulator state during low power system states 45 45 * 46 46 * This describes a regulators state during a system wide low power state. 47 47 * ··· 117 117 /* mode to set on startup */ 118 118 unsigned int initial_mode; 119 119 120 - /* constriant flags */ 120 + /* constraint flags */ 121 121 unsigned always_on:1; /* regulator never off when system is on */ 122 122 unsigned boot_on:1; /* bootloader/firmware enabled regulator */ 123 - unsigned apply_uV:1; /* apply uV constraint iff min == max */ 123 + unsigned apply_uV:1; /* apply uV constraint if min == max */ 124 124 }; 125 125 126 126 /** 127 127 * struct regulator_consumer_supply - supply -> device mapping 128 128 * 129 - * This maps a supply name to a device. 129 + * This maps a supply name to a device. Only one of dev or dev_name 130 + * can be specified. Use of dev_name allows support for buses which 131 + * make struct device available late such as I2C and is the preferred 132 + * form. 130 133 * 131 134 * @dev: Device structure for the consumer. 135 + * @dev_name: Result of dev_name() for the consumer. 132 136 * @supply: Name for the supply. 133 137 */ 134 138 struct regulator_consumer_supply { 135 139 struct device *dev; /* consumer */ 140 + const char *dev_name; /* dev_name() for consumer */ 136 141 const char *supply; /* consumer supply - e.g. "vcc" */ 137 142 }; 143 + 144 + /* Initialize struct regulator_consumer_supply */ 145 + #define REGULATOR_SUPPLY(_name, _dev_name) \ 146 + { \ 147 + .supply = _name, \ 148 + .dev_name = _dev_name, \ 149 + } 138 150 139 151 /** 140 152 * struct regulator_init_data - regulator platform initialisation data. ··· 178 166 179 167 int regulator_suspend_prepare(suspend_state_t state); 180 168 169 + #ifdef CONFIG_REGULATOR 181 170 void regulator_has_full_constraints(void); 171 + #else 172 + static inline void regulator_has_full_constraints(void) 173 + { 174 + } 175 + #endif 182 176 183 177 #endif
+2 -2
include/linux/regulator/max1586.h
··· 36 36 * max1586_subdev_data - regulator data 37 37 * @id: regulator Id (either MAX1586_V3 or MAX1586_V6) 38 38 * @name: regulator cute name (example for V3: "vcc_core") 39 - * @platform_data: regulator init data (contraints, supplies, ...) 39 + * @platform_data: regulator init data (constraints, supplies, ...) 40 40 */ 41 41 struct max1586_subdev_data { 42 42 int id; ··· 46 46 47 47 /** 48 48 * max1586_platform_data - platform data for max1586 49 - * @num_subdevs: number of regultors used (may be 1 or 2) 49 + * @num_subdevs: number of regulators used (may be 1 or 2) 50 50 * @subdevs: regulator used 51 51 * At most, there will be a regulator for V3 and one for V6 voltages. 52 52 * @v3_gain: gain on the V3 voltage output multiplied by 1e6.