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

Merge branches 'topic/tps51632', 'topic/tps80031', 'topic/vexpress', 'topic/max8925', 'topic/gpio' and 'topic/tps65090' of git://git.kernel.org/pub/scm/linux/kernel/git/broonie/regulator into regulator-hotplug

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