diff options
| author | Philipp Zabel <p.zabel@pengutronix.de> | 2014-05-26 04:38:16 -0400 |
|---|---|---|
| committer | Mark Brown <broonie@linaro.org> | 2014-05-26 10:54:57 -0400 |
| commit | 3eb2c7ecb7ea0fad4a53cbedcb87341dcffcea2b (patch) | |
| tree | 84a3f6657c322dd4ba4f811f2e334c218e492dd3 | |
| parent | a3cd1de4ed19831fec98f981e348522e249a4e7a (diff) | |
regulator: Add LTC3589 support
This patch adds support for the Linear Technology LTC3589, LTC3589-1,
and LTC3589-2 8-output I2C voltage regulator ICs.
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Mark Brown <broonie@linaro.org>
| -rw-r--r-- | drivers/regulator/Kconfig | 6 | ||||
| -rw-r--r-- | drivers/regulator/Makefile | 1 | ||||
| -rw-r--r-- | drivers/regulator/ltc3589.c | 565 |
3 files changed, 572 insertions, 0 deletions
diff --git a/drivers/regulator/Kconfig b/drivers/regulator/Kconfig index 903eb37f047a..5599a61bd88c 100644 --- a/drivers/regulator/Kconfig +++ b/drivers/regulator/Kconfig | |||
| @@ -265,6 +265,12 @@ config REGULATOR_LP8788 | |||
| 265 | help | 265 | help |
| 266 | This driver supports LP8788 voltage regulator chip. | 266 | This driver supports LP8788 voltage regulator chip. |
| 267 | 267 | ||
| 268 | config REGULATOR_LTC3589 | ||
| 269 | bool "LTC3589 8-output voltage regulator" | ||
| 270 | help | ||
| 271 | This enables support for the LTC3589, LTC3589-1, and LTC3589-2 | ||
| 272 | 8-output regulators controlled via I2C. | ||
| 273 | |||
| 268 | config REGULATOR_MAX14577 | 274 | config REGULATOR_MAX14577 |
| 269 | tristate "Maxim 14577 regulator" | 275 | tristate "Maxim 14577 regulator" |
| 270 | depends on MFD_MAX14577 | 276 | depends on MFD_MAX14577 |
diff --git a/drivers/regulator/Makefile b/drivers/regulator/Makefile index 12ef277a48b4..16d429ba8ba2 100644 --- a/drivers/regulator/Makefile +++ b/drivers/regulator/Makefile | |||
| @@ -37,6 +37,7 @@ obj-$(CONFIG_REGULATOR_LP872X) += lp872x.o | |||
| 37 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o | 37 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-buck.o |
| 38 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o | 38 | obj-$(CONFIG_REGULATOR_LP8788) += lp8788-ldo.o |
| 39 | obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o | 39 | obj-$(CONFIG_REGULATOR_LP8755) += lp8755.o |
| 40 | obj-$(CONFIG_REGULATOR_LTC3589) += ltc3589.o | ||
| 40 | obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o | 41 | obj-$(CONFIG_REGULATOR_MAX14577) += max14577.o |
| 41 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o | 42 | obj-$(CONFIG_REGULATOR_MAX1586) += max1586.o |
| 42 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o | 43 | obj-$(CONFIG_REGULATOR_MAX8649) += max8649.o |
diff --git a/drivers/regulator/ltc3589.c b/drivers/regulator/ltc3589.c new file mode 100644 index 000000000000..fef64ee31185 --- /dev/null +++ b/drivers/regulator/ltc3589.c | |||
| @@ -0,0 +1,565 @@ | |||
| 1 | /* | ||
| 2 | * Linear Technology LTC3589,LTC3589-1 regulator support | ||
| 3 | * | ||
| 4 | * Copyright (c) 2014 Philipp Zabel <p.zabel@pengutronix.de>, Pengutronix | ||
| 5 | * | ||
| 6 | * See file CREDITS for list of people who contributed to this | ||
| 7 | * project. | ||
| 8 | * | ||
| 9 | * This program is free software; you can redistribute it and/or modify | ||
| 10 | * it under the terms of the GNU General Public License version 2 | ||
| 11 | * as published by the Free Software Foundation. | ||
| 12 | * | ||
| 13 | * This program is distributed in the hope that it will be useful, | ||
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| 16 | * GNU General Public License for more details. | ||
| 17 | * | ||
| 18 | */ | ||
| 19 | #include <linux/i2c.h> | ||
| 20 | #include <linux/init.h> | ||
| 21 | #include <linux/interrupt.h> | ||
| 22 | #include <linux/module.h> | ||
| 23 | #include <linux/kernel.h> | ||
| 24 | #include <linux/of.h> | ||
| 25 | #include <linux/regmap.h> | ||
| 26 | #include <linux/regulator/driver.h> | ||
| 27 | #include <linux/regulator/of_regulator.h> | ||
| 28 | |||
| 29 | #define DRIVER_NAME "ltc3589" | ||
| 30 | |||
| 31 | #define LTC3589_IRQSTAT 0x02 | ||
| 32 | #define LTC3589_SCR1 0x07 | ||
| 33 | #define LTC3589_OVEN 0x10 | ||
| 34 | #define LTC3589_SCR2 0x12 | ||
| 35 | #define LTC3589_PGSTAT 0x13 | ||
| 36 | #define LTC3589_VCCR 0x20 | ||
| 37 | #define LTC3589_CLIRQ 0x21 | ||
| 38 | #define LTC3589_B1DTV1 0x23 | ||
| 39 | #define LTC3589_B1DTV2 0x24 | ||
| 40 | #define LTC3589_VRRCR 0x25 | ||
| 41 | #define LTC3589_B2DTV1 0x26 | ||
| 42 | #define LTC3589_B2DTV2 0x27 | ||
| 43 | #define LTC3589_B3DTV1 0x29 | ||
| 44 | #define LTC3589_B3DTV2 0x2a | ||
| 45 | #define LTC3589_L2DTV1 0x32 | ||
| 46 | #define LTC3589_L2DTV2 0x33 | ||
| 47 | |||
| 48 | #define LTC3589_IRQSTAT_PGOOD_TIMEOUT BIT(3) | ||
| 49 | #define LTC3589_IRQSTAT_UNDERVOLT_WARN BIT(4) | ||
| 50 | #define LTC3589_IRQSTAT_UNDERVOLT_FAULT BIT(5) | ||
| 51 | #define LTC3589_IRQSTAT_THERMAL_WARN BIT(6) | ||
| 52 | #define LTC3589_IRQSTAT_THERMAL_FAULT BIT(7) | ||
| 53 | |||
| 54 | #define LTC3589_OVEN_SW1 BIT(0) | ||
| 55 | #define LTC3589_OVEN_SW2 BIT(1) | ||
| 56 | #define LTC3589_OVEN_SW3 BIT(2) | ||
| 57 | #define LTC3589_OVEN_BB_OUT BIT(3) | ||
| 58 | #define LTC3589_OVEN_LDO2 BIT(4) | ||
| 59 | #define LTC3589_OVEN_LDO3 BIT(5) | ||
| 60 | #define LTC3589_OVEN_LDO4 BIT(6) | ||
| 61 | #define LTC3589_OVEN_SW_CTRL BIT(7) | ||
| 62 | |||
| 63 | #define LTC3589_VCCR_SW1_GO BIT(0) | ||
| 64 | #define LTC3589_VCCR_SW2_GO BIT(2) | ||
| 65 | #define LTC3589_VCCR_SW3_GO BIT(4) | ||
| 66 | #define LTC3589_VCCR_LDO2_GO BIT(6) | ||
| 67 | |||
| 68 | enum ltc3589_variant { | ||
| 69 | LTC3589, | ||
| 70 | LTC3589_1, | ||
| 71 | LTC3589_2, | ||
| 72 | }; | ||
| 73 | |||
| 74 | enum ltc3589_reg { | ||
| 75 | LTC3589_SW1, | ||
| 76 | LTC3589_SW2, | ||
| 77 | LTC3589_SW3, | ||
| 78 | LTC3589_BB_OUT, | ||
| 79 | LTC3589_LDO1, | ||
| 80 | LTC3589_LDO2, | ||
| 81 | LTC3589_LDO3, | ||
| 82 | LTC3589_LDO4, | ||
| 83 | LTC3589_NUM_REGULATORS, | ||
| 84 | }; | ||
| 85 | |||
| 86 | struct ltc3589_regulator { | ||
| 87 | struct regulator_desc desc; | ||
| 88 | |||
| 89 | /* External feedback voltage divider */ | ||
| 90 | unsigned int r1; | ||
| 91 | unsigned int r2; | ||
| 92 | }; | ||
| 93 | |||
| 94 | struct ltc3589 { | ||
| 95 | struct regmap *regmap; | ||
| 96 | struct device *dev; | ||
| 97 | enum ltc3589_variant variant; | ||
| 98 | struct ltc3589_regulator regulator_descs[LTC3589_NUM_REGULATORS]; | ||
| 99 | struct regulator_dev *regulators[LTC3589_NUM_REGULATORS]; | ||
| 100 | }; | ||
| 101 | |||
| 102 | static const int ltc3589_ldo4[] = { | ||
| 103 | 2800000, 2500000, 1800000, 3300000, | ||
| 104 | }; | ||
| 105 | |||
| 106 | static const int ltc3589_12_ldo4[] = { | ||
| 107 | 1200000, 1800000, 2500000, 3200000, | ||
| 108 | }; | ||
| 109 | |||
| 110 | static int ltc3589_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) | ||
| 111 | { | ||
| 112 | struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); | ||
| 113 | int sel, shift; | ||
| 114 | |||
| 115 | if (unlikely(ramp_delay <= 0)) | ||
| 116 | return -EINVAL; | ||
| 117 | |||
| 118 | /* VRRCR slew rate offsets are the same as VCCR go bit offsets */ | ||
| 119 | shift = ffs(rdev->desc->apply_bit) - 1; | ||
| 120 | |||
| 121 | /* The slew rate can be set to 0.88, 1.75, 3.5, or 7 mV/uS */ | ||
| 122 | for (sel = 0; sel < 4; sel++) { | ||
| 123 | if ((880 << sel) >= ramp_delay) { | ||
| 124 | return regmap_update_bits(ltc3589->regmap, | ||
| 125 | LTC3589_VRRCR, | ||
| 126 | 0x3 << shift, sel << shift); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | return -EINVAL; | ||
| 130 | } | ||
| 131 | |||
| 132 | static int ltc3589_set_suspend_voltage(struct regulator_dev *rdev, int uV) | ||
| 133 | { | ||
| 134 | struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); | ||
| 135 | int sel; | ||
| 136 | |||
| 137 | sel = regulator_map_voltage_linear(rdev, uV, uV); | ||
| 138 | if (sel < 0) | ||
| 139 | return sel; | ||
| 140 | |||
| 141 | /* DTV2 register follows right after the corresponding DTV1 register */ | ||
| 142 | return regmap_update_bits(ltc3589->regmap, rdev->desc->vsel_reg + 1, | ||
| 143 | rdev->desc->vsel_mask, sel); | ||
| 144 | } | ||
| 145 | |||
| 146 | static int ltc3589_set_suspend_mode(struct regulator_dev *rdev, | ||
| 147 | unsigned int mode) | ||
| 148 | { | ||
| 149 | struct ltc3589 *ltc3589 = rdev_get_drvdata(rdev); | ||
| 150 | int mask, bit = 0; | ||
| 151 | |||
| 152 | /* VCCR reference selects are right next to the VCCR go bits */ | ||
| 153 | mask = rdev->desc->apply_bit << 1; | ||
| 154 | |||
| 155 | if (mode == REGULATOR_MODE_STANDBY) | ||
| 156 | bit = mask; /* Select DTV2 */ | ||
| 157 | |||
| 158 | mask |= rdev->desc->apply_bit; | ||
| 159 | bit |= rdev->desc->apply_bit; | ||
| 160 | return regmap_update_bits(ltc3589->regmap, LTC3589_VCCR, mask, bit); | ||
| 161 | } | ||
| 162 | |||
| 163 | static int ltc3589_list_voltage_fixed(struct regulator_dev *rdev, | ||
| 164 | unsigned int selector) | ||
| 165 | { | ||
| 166 | if (selector) | ||
| 167 | return -EINVAL; | ||
| 168 | |||
| 169 | return rdev->desc->fixed_uV; | ||
| 170 | } | ||
| 171 | |||
| 172 | /* SW1, SW2, SW3, LDO2 */ | ||
| 173 | static struct regulator_ops ltc3589_linear_regulator_ops = { | ||
| 174 | .enable = regulator_enable_regmap, | ||
| 175 | .disable = regulator_disable_regmap, | ||
| 176 | .is_enabled = regulator_is_enabled_regmap, | ||
| 177 | .list_voltage = regulator_list_voltage_linear, | ||
| 178 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
| 179 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
| 180 | .set_ramp_delay = ltc3589_set_ramp_delay, | ||
| 181 | .set_voltage_time_sel = regulator_set_voltage_time_sel, | ||
| 182 | .set_suspend_voltage = ltc3589_set_suspend_voltage, | ||
| 183 | .set_suspend_mode = ltc3589_set_suspend_mode, | ||
| 184 | }; | ||
| 185 | |||
| 186 | /* BB_OUT, LDO3 */ | ||
| 187 | static struct regulator_ops ltc3589_fixed_regulator_ops = { | ||
| 188 | .enable = regulator_enable_regmap, | ||
| 189 | .disable = regulator_disable_regmap, | ||
| 190 | .is_enabled = regulator_is_enabled_regmap, | ||
| 191 | .list_voltage = ltc3589_list_voltage_fixed, | ||
| 192 | }; | ||
| 193 | |||
| 194 | /* LDO1 */ | ||
| 195 | static struct regulator_ops ltc3589_standby_regulator_ops = { | ||
| 196 | .list_voltage = ltc3589_list_voltage_fixed, | ||
| 197 | }; | ||
| 198 | |||
| 199 | /* LDO4 */ | ||
| 200 | static struct regulator_ops ltc3589_table_regulator_ops = { | ||
| 201 | .enable = regulator_enable_regmap, | ||
| 202 | .disable = regulator_disable_regmap, | ||
| 203 | .is_enabled = regulator_is_enabled_regmap, | ||
| 204 | .list_voltage = regulator_list_voltage_table, | ||
| 205 | .set_voltage_sel = regulator_set_voltage_sel_regmap, | ||
| 206 | .get_voltage_sel = regulator_get_voltage_sel_regmap, | ||
| 207 | }; | ||
| 208 | |||
| 209 | |||
| 210 | #define LTC3589_REG(_name, _ops, en_bit, dtv1_reg, dtv_mask, go_bit) \ | ||
| 211 | [LTC3589_ ## _name] = { \ | ||
| 212 | .desc = { \ | ||
| 213 | .name = #_name, \ | ||
| 214 | .n_voltages = (dtv_mask) + 1, \ | ||
| 215 | .min_uV = (go_bit) ? 362500 : 0, \ | ||
| 216 | .uV_step = (go_bit) ? 12500 : 0, \ | ||
| 217 | .ramp_delay = (go_bit) ? 1750 : 0, \ | ||
| 218 | .fixed_uV = (dtv_mask) ? 0 : 800000, \ | ||
| 219 | .ops = <c3589_ ## _ops ## _regulator_ops, \ | ||
| 220 | .type = REGULATOR_VOLTAGE, \ | ||
| 221 | .id = LTC3589_ ## _name, \ | ||
| 222 | .owner = THIS_MODULE, \ | ||
| 223 | .vsel_reg = (dtv1_reg), \ | ||
| 224 | .vsel_mask = (dtv_mask), \ | ||
| 225 | .apply_reg = (go_bit) ? LTC3589_VCCR : 0, \ | ||
| 226 | .apply_bit = (go_bit), \ | ||
| 227 | .enable_reg = (en_bit) ? LTC3589_OVEN : 0, \ | ||
| 228 | .enable_mask = (en_bit), \ | ||
| 229 | }, \ | ||
| 230 | } | ||
| 231 | |||
| 232 | #define LTC3589_LINEAR_REG(_name, _dtv1) \ | ||
| 233 | LTC3589_REG(_name, linear, LTC3589_OVEN_ ## _name, \ | ||
| 234 | LTC3589_ ## _dtv1, 0x1f, \ | ||
| 235 | LTC3589_VCCR_ ## _name ## _GO) | ||
| 236 | |||
| 237 | #define LTC3589_FIXED_REG(_name) \ | ||
| 238 | LTC3589_REG(_name, fixed, LTC3589_OVEN_ ## _name, 0, 0, 0) | ||
| 239 | |||
| 240 | static struct ltc3589_regulator ltc3589_regulators[LTC3589_NUM_REGULATORS] = { | ||
| 241 | LTC3589_LINEAR_REG(SW1, B1DTV1), | ||
| 242 | LTC3589_LINEAR_REG(SW2, B2DTV1), | ||
| 243 | LTC3589_LINEAR_REG(SW3, B3DTV1), | ||
| 244 | LTC3589_FIXED_REG(BB_OUT), | ||
| 245 | LTC3589_REG(LDO1, standby, 0, 0, 0, 0), | ||
| 246 | LTC3589_LINEAR_REG(LDO2, L2DTV1), | ||
| 247 | LTC3589_FIXED_REG(LDO3), | ||
| 248 | LTC3589_REG(LDO4, table, LTC3589_OVEN_LDO4, LTC3589_L2DTV2, 0x60, 0), | ||
| 249 | }; | ||
| 250 | |||
| 251 | #ifdef CONFIG_OF | ||
| 252 | static struct of_regulator_match ltc3589_matches[LTC3589_NUM_REGULATORS] = { | ||
| 253 | { .name = "sw1", }, | ||
| 254 | { .name = "sw2", }, | ||
| 255 | { .name = "sw3", }, | ||
| 256 | { .name = "bb-out", }, | ||
| 257 | { .name = "ldo1", }, /* standby */ | ||
| 258 | { .name = "ldo2", }, | ||
| 259 | { .name = "ldo3", }, | ||
| 260 | { .name = "ldo4", }, | ||
| 261 | }; | ||
| 262 | |||
| 263 | static int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589) | ||
| 264 | { | ||
| 265 | struct device *dev = ltc3589->dev; | ||
| 266 | struct device_node *node; | ||
| 267 | int i, ret; | ||
| 268 | |||
| 269 | node = of_find_node_by_name(dev->of_node, "regulators"); | ||
| 270 | if (!node) { | ||
| 271 | dev_err(dev, "regulators node not found\n"); | ||
| 272 | return -EINVAL; | ||
| 273 | } | ||
| 274 | |||
| 275 | ret = of_regulator_match(dev, node, ltc3589_matches, | ||
| 276 | ARRAY_SIZE(ltc3589_matches)); | ||
| 277 | of_node_put(node); | ||
| 278 | if (ret < 0) { | ||
| 279 | dev_err(dev, "Error parsing regulator init data: %d\n", ret); | ||
| 280 | return ret; | ||
| 281 | } | ||
| 282 | if (ret != LTC3589_NUM_REGULATORS) { | ||
| 283 | dev_err(dev, "Only %d regulators described in device tree\n", | ||
| 284 | ret); | ||
| 285 | return -EINVAL; | ||
| 286 | } | ||
| 287 | |||
| 288 | /* Parse feedback voltage dividers. LDO3 and LDO4 don't have them */ | ||
| 289 | for (i = 0; i < LTC3589_LDO3; i++) { | ||
| 290 | struct ltc3589_regulator *desc = <c3589->regulator_descs[i]; | ||
| 291 | struct device_node *np = ltc3589_matches[i].of_node; | ||
| 292 | u32 vdiv[2]; | ||
| 293 | |||
| 294 | ret = of_property_read_u32_array(np, "lltc,fb-voltage-divider", | ||
| 295 | vdiv, 2); | ||
| 296 | if (ret) { | ||
| 297 | dev_err(dev, "Failed to parse voltage divider: %d\n", | ||
| 298 | ret); | ||
| 299 | return ret; | ||
| 300 | } | ||
| 301 | |||
| 302 | desc->r1 = vdiv[0]; | ||
| 303 | desc->r2 = vdiv[1]; | ||
| 304 | } | ||
| 305 | |||
| 306 | return 0; | ||
| 307 | } | ||
| 308 | |||
| 309 | static inline struct regulator_init_data *match_init_data(int index) | ||
| 310 | { | ||
| 311 | return ltc3589_matches[index].init_data; | ||
| 312 | } | ||
| 313 | |||
| 314 | static inline struct device_node *match_of_node(int index) | ||
| 315 | { | ||
| 316 | return ltc3589_matches[index].of_node; | ||
| 317 | } | ||
| 318 | #else | ||
| 319 | static inline int ltc3589_parse_regulators_dt(struct ltc3589 *ltc3589) | ||
| 320 | { | ||
| 321 | return 0; | ||
| 322 | } | ||
| 323 | |||
| 324 | static inline struct regulator_init_data *match_init_data(int index) | ||
| 325 | { | ||
| 326 | return NULL; | ||
| 327 | } | ||
| 328 | |||
| 329 | static inline struct device_node *match_of_node(int index) | ||
| 330 | { | ||
| 331 | return NULL; | ||
| 332 | } | ||
| 333 | #endif | ||
| 334 | |||
| 335 | static bool ltc3589_writeable_reg(struct device *dev, unsigned int reg) | ||
| 336 | { | ||
| 337 | switch (reg) { | ||
| 338 | case LTC3589_IRQSTAT: | ||
| 339 | case LTC3589_SCR1: | ||
| 340 | case LTC3589_OVEN: | ||
| 341 | case LTC3589_SCR2: | ||
| 342 | case LTC3589_VCCR: | ||
| 343 | case LTC3589_CLIRQ: | ||
| 344 | case LTC3589_B1DTV1: | ||
| 345 | case LTC3589_B1DTV2: | ||
| 346 | case LTC3589_VRRCR: | ||
| 347 | case LTC3589_B2DTV1: | ||
| 348 | case LTC3589_B2DTV2: | ||
| 349 | case LTC3589_B3DTV1: | ||
| 350 | case LTC3589_B3DTV2: | ||
| 351 | case LTC3589_L2DTV1: | ||
| 352 | case LTC3589_L2DTV2: | ||
| 353 | return true; | ||
| 354 | } | ||
| 355 | return false; | ||
| 356 | } | ||
| 357 | |||
| 358 | static bool ltc3589_readable_reg(struct device *dev, unsigned int reg) | ||
| 359 | { | ||
| 360 | switch (reg) { | ||
| 361 | case LTC3589_IRQSTAT: | ||
| 362 | case LTC3589_SCR1: | ||
| 363 | case LTC3589_OVEN: | ||
| 364 | case LTC3589_SCR2: | ||
| 365 | case LTC3589_PGSTAT: | ||
| 366 | case LTC3589_VCCR: | ||
| 367 | case LTC3589_B1DTV1: | ||
| 368 | case LTC3589_B1DTV2: | ||
| 369 | case LTC3589_VRRCR: | ||
| 370 | case LTC3589_B2DTV1: | ||
| 371 | case LTC3589_B2DTV2: | ||
| 372 | case LTC3589_B3DTV1: | ||
| 373 | case LTC3589_B3DTV2: | ||
| 374 | case LTC3589_L2DTV1: | ||
| 375 | case LTC3589_L2DTV2: | ||
| 376 | return true; | ||
| 377 | } | ||
| 378 | return false; | ||
| 379 | } | ||
| 380 | |||
| 381 | static bool ltc3589_volatile_reg(struct device *dev, unsigned int reg) | ||
| 382 | { | ||
| 383 | switch (reg) { | ||
| 384 | case LTC3589_IRQSTAT: | ||
| 385 | case LTC3589_PGSTAT: | ||
| 386 | return true; | ||
| 387 | } | ||
| 388 | return false; | ||
| 389 | } | ||
| 390 | |||
| 391 | struct reg_default ltc3589_reg_defaults[] = { | ||
| 392 | { LTC3589_SCR1, 0x00 }, | ||
| 393 | { LTC3589_OVEN, 0x00 }, | ||
| 394 | { LTC3589_SCR2, 0x00 }, | ||
| 395 | { LTC3589_VCCR, 0x00 }, | ||
| 396 | { LTC3589_B1DTV1, 0x19 }, | ||
| 397 | { LTC3589_B1DTV2, 0x19 }, | ||
| 398 | { LTC3589_VRRCR, 0xff }, | ||
| 399 | { LTC3589_B2DTV1, 0x19 }, | ||
| 400 | { LTC3589_B2DTV2, 0x19 }, | ||
| 401 | { LTC3589_B3DTV1, 0x19 }, | ||
| 402 | { LTC3589_B3DTV2, 0x19 }, | ||
| 403 | { LTC3589_L2DTV1, 0x19 }, | ||
| 404 | { LTC3589_L2DTV2, 0x19 }, | ||
| 405 | }; | ||
| 406 | |||
| 407 | static const struct regmap_config ltc3589_regmap_config = { | ||
| 408 | .reg_bits = 8, | ||
| 409 | .val_bits = 8, | ||
| 410 | .writeable_reg = ltc3589_writeable_reg, | ||
| 411 | .readable_reg = ltc3589_readable_reg, | ||
| 412 | .volatile_reg = ltc3589_volatile_reg, | ||
| 413 | .max_register = LTC3589_L2DTV2, | ||
| 414 | .reg_defaults = ltc3589_reg_defaults, | ||
| 415 | .num_reg_defaults = ARRAY_SIZE(ltc3589_reg_defaults), | ||
| 416 | .use_single_rw = true, | ||
| 417 | .cache_type = REGCACHE_RBTREE, | ||
| 418 | }; | ||
| 419 | |||
| 420 | |||
| 421 | static irqreturn_t ltc3589_isr(int irq, void *dev_id) | ||
| 422 | { | ||
| 423 | struct ltc3589 *ltc3589 = dev_id; | ||
| 424 | unsigned int i, irqstat, event; | ||
| 425 | |||
| 426 | regmap_read(ltc3589->regmap, LTC3589_IRQSTAT, &irqstat); | ||
| 427 | |||
| 428 | if (irqstat & LTC3589_IRQSTAT_THERMAL_WARN) { | ||
| 429 | event = REGULATOR_EVENT_OVER_TEMP; | ||
| 430 | for (i = 0; i < LTC3589_NUM_REGULATORS; i++) | ||
| 431 | regulator_notifier_call_chain(ltc3589->regulators[i], | ||
| 432 | event, NULL); | ||
| 433 | } | ||
| 434 | |||
| 435 | if (irqstat & LTC3589_IRQSTAT_UNDERVOLT_WARN) { | ||
| 436 | event = REGULATOR_EVENT_UNDER_VOLTAGE; | ||
| 437 | for (i = 0; i < LTC3589_NUM_REGULATORS; i++) | ||
| 438 | regulator_notifier_call_chain(ltc3589->regulators[i], | ||
| 439 | event, NULL); | ||
| 440 | } | ||
| 441 | |||
| 442 | /* Clear warning condition */ | ||
| 443 | regmap_write(ltc3589->regmap, LTC3589_CLIRQ, 0); | ||
| 444 | |||
| 445 | return IRQ_HANDLED; | ||
| 446 | } | ||
| 447 | |||
| 448 | static inline unsigned int ltc3589_scale(unsigned int uV, u32 r1, u32 r2) | ||
| 449 | { | ||
| 450 | uint64_t tmp; | ||
| 451 | if (uV == 0) | ||
| 452 | return 0; | ||
| 453 | tmp = (uint64_t)uV * r1; | ||
| 454 | do_div(tmp, r2); | ||
| 455 | return uV + (unsigned int)tmp; | ||
| 456 | } | ||
| 457 | |||
| 458 | static void ltc3589_apply_fb_voltage_divider(struct ltc3589_regulator *rdesc) | ||
| 459 | { | ||
| 460 | struct regulator_desc *desc = &rdesc->desc; | ||
| 461 | |||
| 462 | if (!rdesc->r1 || !rdesc->r2) | ||
| 463 | return; | ||
| 464 | |||
| 465 | desc->min_uV = ltc3589_scale(desc->min_uV, rdesc->r1, rdesc->r2); | ||
| 466 | desc->uV_step = ltc3589_scale(desc->uV_step, rdesc->r1, rdesc->r2); | ||
| 467 | desc->fixed_uV = ltc3589_scale(desc->fixed_uV, rdesc->r1, rdesc->r2); | ||
| 468 | } | ||
| 469 | |||
| 470 | static int ltc3589_probe(struct i2c_client *client, | ||
| 471 | const struct i2c_device_id *id) | ||
| 472 | { | ||
| 473 | struct device *dev = &client->dev; | ||
| 474 | struct ltc3589_regulator *descs; | ||
| 475 | struct ltc3589 *ltc3589; | ||
| 476 | int i, ret; | ||
| 477 | |||
| 478 | ltc3589 = devm_kzalloc(dev, sizeof(*ltc3589), GFP_KERNEL); | ||
| 479 | if (!ltc3589) | ||
| 480 | return -ENOMEM; | ||
| 481 | |||
| 482 | i2c_set_clientdata(client, ltc3589); | ||
| 483 | ltc3589->variant = id->driver_data; | ||
| 484 | ltc3589->dev = dev; | ||
| 485 | |||
| 486 | descs = ltc3589->regulator_descs; | ||
| 487 | memcpy(descs, ltc3589_regulators, sizeof(ltc3589_regulators)); | ||
| 488 | if (ltc3589->variant == LTC3589) { | ||
| 489 | descs[LTC3589_LDO3].desc.fixed_uV = 1800000; | ||
| 490 | descs[LTC3589_LDO4].desc.volt_table = ltc3589_ldo4; | ||
| 491 | } else { | ||
| 492 | descs[LTC3589_LDO3].desc.fixed_uV = 2800000; | ||
| 493 | descs[LTC3589_LDO4].desc.volt_table = ltc3589_12_ldo4; | ||
| 494 | } | ||
| 495 | |||
| 496 | ltc3589->regmap = devm_regmap_init_i2c(client, <c3589_regmap_config); | ||
| 497 | if (IS_ERR(ltc3589->regmap)) { | ||
| 498 | ret = PTR_ERR(ltc3589->regmap); | ||
| 499 | dev_err(dev, "failed to initialize regmap: %d\n", ret); | ||
| 500 | return ret; | ||
| 501 | } | ||
| 502 | |||
| 503 | ret = ltc3589_parse_regulators_dt(ltc3589); | ||
| 504 | if (ret) | ||
| 505 | return ret; | ||
| 506 | |||
| 507 | for (i = 0; i < LTC3589_NUM_REGULATORS; i++) { | ||
| 508 | struct ltc3589_regulator *rdesc = <c3589->regulator_descs[i]; | ||
| 509 | struct regulator_desc *desc = &rdesc->desc; | ||
| 510 | struct regulator_init_data *init_data; | ||
| 511 | struct regulator_config config = { }; | ||
| 512 | |||
| 513 | init_data = match_init_data(i); | ||
| 514 | |||
| 515 | if (i < LTC3589_LDO3) | ||
| 516 | ltc3589_apply_fb_voltage_divider(rdesc); | ||
| 517 | |||
| 518 | config.dev = dev; | ||
| 519 | config.init_data = init_data; | ||
| 520 | config.driver_data = ltc3589; | ||
| 521 | config.of_node = match_of_node(i); | ||
| 522 | |||
| 523 | ltc3589->regulators[i] = devm_regulator_register(dev, desc, | ||
| 524 | &config); | ||
| 525 | if (IS_ERR(ltc3589->regulators[i])) { | ||
| 526 | ret = PTR_ERR(ltc3589->regulators[i]); | ||
| 527 | dev_err(dev, "failed to register regulator %s: %d\n", | ||
| 528 | desc->name, ret); | ||
| 529 | return ret; | ||
| 530 | } | ||
| 531 | } | ||
| 532 | |||
| 533 | ret = devm_request_threaded_irq(dev, client->irq, NULL, ltc3589_isr, | ||
| 534 | IRQF_TRIGGER_LOW | IRQF_ONESHOT, | ||
| 535 | client->name, ltc3589); | ||
| 536 | if (ret) { | ||
| 537 | dev_err(dev, "Failed to request IRQ: %d\n", ret); | ||
| 538 | return ret; | ||
| 539 | } | ||
| 540 | |||
| 541 | return 0; | ||
| 542 | } | ||
| 543 | |||
| 544 | static struct i2c_device_id ltc3589_i2c_id[] = { | ||
| 545 | { "ltc3589", LTC3589 }, | ||
| 546 | { "ltc3589-1", LTC3589_1 }, | ||
| 547 | { "ltc3589-2", LTC3589_2 }, | ||
| 548 | { } | ||
| 549 | }; | ||
| 550 | MODULE_DEVICE_TABLE(i2c, ltc3589_i2c_id); | ||
| 551 | |||
| 552 | static struct i2c_driver ltc3589_driver = { | ||
| 553 | .driver = { | ||
| 554 | .name = DRIVER_NAME, | ||
| 555 | .owner = THIS_MODULE, | ||
| 556 | }, | ||
| 557 | .probe = ltc3589_probe, | ||
| 558 | .id_table = ltc3589_i2c_id, | ||
| 559 | }; | ||
| 560 | module_i2c_driver(ltc3589_driver); | ||
| 561 | |||
| 562 | MODULE_AUTHOR("Philipp Zabel <p.zabel@pengutronix.de>"); | ||
| 563 | MODULE_DESCRIPTION("Regulator driver for Linear Technology LTC3589(-1,2)"); | ||
| 564 | MODULE_LICENSE("GPL v2"); | ||
| 565 | MODULE_ALIAS("i2c:ltc3589"); | ||
