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

regulator: tps65090: Allow setting the overcurrent wait time

The tps65090 regulator allows you to specify how long you want it to
wait before detecting an overcurrent condition. Allow specifying that
through the device tree (or through platform data).

Signed-off-by: Doug Anderson <dianders@chromium.org>
Signed-off-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Michael Spang <spang@chromium.org>
Signed-off-by: Sean Paul <seanpaul@chromium.org>
Signed-off-by: Mark Brown <broonie@linaro.org>

authored by

Doug Anderson and committed by
Mark Brown
29041449 c9eaa447

+65
+4
Documentation/devicetree/bindings/regulator/tps65090.txt
··· 21 21 number should be provided. If it is externally controlled and no GPIO 22 22 entry then driver will just configure this rails as external control 23 23 and will not provide any enable/disable APIs. 24 + - ti,overcurrent-wait: This is applicable to FET registers, which have a 25 + poorly defined "overcurrent wait" field. If this property is present it 26 + should be between 0 - 3. If this property isn't present we won't touch the 27 + "overcurrent wait" field and we'll leave it to the BIOS/EC to deal with. 24 28 25 29 Each regulator is defined using the standard binding for regulators. 26 30
+56
drivers/regulator/tps65090-regulator.c
··· 28 28 #include <linux/regulator/of_regulator.h> 29 29 #include <linux/mfd/tps65090.h> 30 30 31 + #define CTRL_WT_BIT 2 /* Regulator wait time 0 bit */ 32 + 33 + #define MAX_OVERCURRENT_WAIT 3 /* Overcurrent wait must be <= this */ 34 + 35 + /** 36 + * struct tps65090_regulator - Per-regulator data for a tps65090 regulator 37 + * 38 + * @dev: Pointer to our device. 39 + * @desc: The struct regulator_desc for the regulator. 40 + * @rdev: The struct regulator_dev for the regulator. 41 + * @overcurrent_wait_valid: True if overcurrent_wait is valid. 42 + * @overcurrent_wait: For FETs, the value to put in the WTFET bitfield. 43 + */ 44 + 31 45 struct tps65090_regulator { 32 46 struct device *dev; 33 47 struct regulator_desc *desc; 34 48 struct regulator_dev *rdev; 49 + bool overcurrent_wait_valid; 50 + int overcurrent_wait; 35 51 }; 36 52 37 53 static struct regulator_ops tps65090_ext_control_ops = { 38 54 }; 55 + 56 + /** 57 + * tps65090_reg_set_overcurrent_wait - Setup overcurrent wait 58 + * 59 + * This will set the overcurrent wait time based on what's in the regulator 60 + * info. 61 + * 62 + * @ri: Overall regulator data 63 + * @rdev: Regulator device 64 + * 65 + * Return: 0 if no error, non-zero if there was an error writing the register. 66 + */ 67 + static int tps65090_reg_set_overcurrent_wait(struct tps65090_regulator *ri, 68 + struct regulator_dev *rdev) 69 + { 70 + int ret; 71 + 72 + ret = regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, 73 + MAX_OVERCURRENT_WAIT << CTRL_WT_BIT, 74 + ri->overcurrent_wait << CTRL_WT_BIT); 75 + if (ret) { 76 + dev_err(&rdev->dev, "Error updating overcurrent wait %#x\n", 77 + rdev->desc->enable_reg); 78 + } 79 + 80 + return ret; 81 + } 39 82 40 83 static struct regulator_ops tps65090_reg_contol_ops = { 41 84 .enable = regulator_enable_regmap, ··· 252 209 rpdata->gpio = of_get_named_gpio(np, 253 210 "dcdc-ext-control-gpios", 0); 254 211 212 + if (of_property_read_u32(tps65090_matches[idx].of_node, 213 + "ti,overcurrent-wait", 214 + &rpdata->overcurrent_wait) == 0) 215 + rpdata->overcurrent_wait_valid = true; 216 + 255 217 tps65090_pdata->reg_pdata[idx] = rpdata; 256 218 } 257 219 return tps65090_pdata; ··· 306 258 ri = &pmic[num]; 307 259 ri->dev = &pdev->dev; 308 260 ri->desc = &tps65090_regulator_desc[num]; 261 + ri->overcurrent_wait_valid = tps_pdata->overcurrent_wait_valid; 262 + ri->overcurrent_wait = tps_pdata->overcurrent_wait; 309 263 310 264 /* 311 265 * TPS5090 DCDC support the control from external digital input. ··· 348 298 return PTR_ERR(rdev); 349 299 } 350 300 ri->rdev = rdev; 301 + 302 + if (ri->overcurrent_wait_valid) { 303 + ret = tps65090_reg_set_overcurrent_wait(ri, rdev); 304 + if (ret < 0) 305 + return ret; 306 + } 351 307 352 308 /* Enable external control if it is require */ 353 309 if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data &&
+5
include/linux/mfd/tps65090.h
··· 78 78 * DCDC1, DCDC2 and DCDC3. 79 79 * @gpio: Gpio number if external control is enabled and controlled through 80 80 * gpio. 81 + * @overcurrent_wait_valid: True if the overcurrent_wait should be applied. 82 + * @overcurrent_wait: Value to set as the overcurrent wait time. This is the 83 + * actual bitfield value, not a time in ms (valid value are 0 - 3). 81 84 */ 82 85 struct tps65090_regulator_plat_data { 83 86 struct regulator_init_data *reg_init_data; 84 87 bool enable_ext_control; 85 88 int gpio; 89 + bool overcurrent_wait_valid; 90 + int overcurrent_wait; 86 91 }; 87 92 88 93 struct tps65090_platform_data {