| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * TI LM363X Regulator Driver |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright 2015 Texas Instruments |
|---|
| 5 | 6 | * |
|---|
| 6 | 7 | * Author: Milo Kim <milo.kim@ti.com> |
|---|
| 7 | | - * |
|---|
| 8 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 9 | | - * it under the terms of the GNU General Public License version 2 as |
|---|
| 10 | | - * published by the Free Software Foundation. |
|---|
| 11 | 8 | */ |
|---|
| 12 | 9 | |
|---|
| 13 | 10 | #include <linux/err.h> |
|---|
| .. | .. |
|---|
| 37 | 34 | #define LM3632_VBOOST_MIN 4500000 |
|---|
| 38 | 35 | #define LM3632_VLDO_MIN 4000000 |
|---|
| 39 | 36 | |
|---|
| 37 | +/* LM36274 */ |
|---|
| 38 | +#define LM36274_BOOST_VSEL_MAX 0x3f |
|---|
| 39 | +#define LM36274_LDO_VSEL_MAX 0x32 |
|---|
| 40 | +#define LM36274_VOLTAGE_MIN 4000000 |
|---|
| 41 | + |
|---|
| 40 | 42 | /* Common */ |
|---|
| 41 | 43 | #define LM363X_STEP_50mV 50000 |
|---|
| 42 | 44 | #define LM363X_STEP_500mV 500000 |
|---|
| .. | .. |
|---|
| 48 | 50 | static int lm363x_regulator_enable_time(struct regulator_dev *rdev) |
|---|
| 49 | 51 | { |
|---|
| 50 | 52 | enum lm363x_regulator_id id = rdev_get_id(rdev); |
|---|
| 51 | | - u8 val, addr, mask; |
|---|
| 53 | + unsigned int val, addr, mask; |
|---|
| 52 | 54 | |
|---|
| 53 | 55 | switch (id) { |
|---|
| 54 | 56 | case LM3631_LDO_CONT: |
|---|
| .. | .. |
|---|
| 71 | 73 | return 0; |
|---|
| 72 | 74 | } |
|---|
| 73 | 75 | |
|---|
| 74 | | - if (regmap_read(rdev->regmap, addr, (unsigned int *)&val)) |
|---|
| 76 | + if (regmap_read(rdev->regmap, addr, &val)) |
|---|
| 75 | 77 | return -EINVAL; |
|---|
| 76 | 78 | |
|---|
| 77 | 79 | val = (val & mask) >> LM3631_ENTIME_SHIFT; |
|---|
| .. | .. |
|---|
| 82 | 84 | return ENABLE_TIME_USEC * val; |
|---|
| 83 | 85 | } |
|---|
| 84 | 86 | |
|---|
| 85 | | -static struct regulator_ops lm363x_boost_voltage_table_ops = { |
|---|
| 87 | +static const struct regulator_ops lm363x_boost_voltage_table_ops = { |
|---|
| 86 | 88 | .list_voltage = regulator_list_voltage_linear, |
|---|
| 87 | 89 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
|---|
| 88 | 90 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| 89 | 91 | }; |
|---|
| 90 | 92 | |
|---|
| 91 | | -static struct regulator_ops lm363x_regulator_voltage_table_ops = { |
|---|
| 93 | +static const struct regulator_ops lm363x_regulator_voltage_table_ops = { |
|---|
| 92 | 94 | .list_voltage = regulator_list_voltage_linear, |
|---|
| 93 | 95 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
|---|
| 94 | 96 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| .. | .. |
|---|
| 217 | 219 | .enable_reg = LM3632_REG_BIAS_CONFIG, |
|---|
| 218 | 220 | .enable_mask = LM3632_EN_VNEG_MASK, |
|---|
| 219 | 221 | }, |
|---|
| 222 | + |
|---|
| 223 | + /* LM36274 */ |
|---|
| 224 | + { |
|---|
| 225 | + .name = "vboost", |
|---|
| 226 | + .of_match = "vboost", |
|---|
| 227 | + .id = LM36274_BOOST, |
|---|
| 228 | + .ops = &lm363x_boost_voltage_table_ops, |
|---|
| 229 | + .n_voltages = LM36274_BOOST_VSEL_MAX + 1, |
|---|
| 230 | + .min_uV = LM36274_VOLTAGE_MIN, |
|---|
| 231 | + .uV_step = LM363X_STEP_50mV, |
|---|
| 232 | + .type = REGULATOR_VOLTAGE, |
|---|
| 233 | + .owner = THIS_MODULE, |
|---|
| 234 | + .vsel_reg = LM36274_REG_VOUT_BOOST, |
|---|
| 235 | + .vsel_mask = LM36274_VOUT_MASK, |
|---|
| 236 | + }, |
|---|
| 237 | + { |
|---|
| 238 | + .name = "ldo_vpos", |
|---|
| 239 | + .of_match = "vpos", |
|---|
| 240 | + .id = LM36274_LDO_POS, |
|---|
| 241 | + .ops = &lm363x_regulator_voltage_table_ops, |
|---|
| 242 | + .n_voltages = LM36274_LDO_VSEL_MAX + 1, |
|---|
| 243 | + .min_uV = LM36274_VOLTAGE_MIN, |
|---|
| 244 | + .uV_step = LM363X_STEP_50mV, |
|---|
| 245 | + .type = REGULATOR_VOLTAGE, |
|---|
| 246 | + .owner = THIS_MODULE, |
|---|
| 247 | + .vsel_reg = LM36274_REG_VOUT_POS, |
|---|
| 248 | + .vsel_mask = LM36274_VOUT_MASK, |
|---|
| 249 | + .enable_reg = LM36274_REG_BIAS_CONFIG_1, |
|---|
| 250 | + .enable_mask = LM36274_EN_VPOS_MASK, |
|---|
| 251 | + }, |
|---|
| 252 | + { |
|---|
| 253 | + .name = "ldo_vneg", |
|---|
| 254 | + .of_match = "vneg", |
|---|
| 255 | + .id = LM36274_LDO_NEG, |
|---|
| 256 | + .ops = &lm363x_regulator_voltage_table_ops, |
|---|
| 257 | + .n_voltages = LM36274_LDO_VSEL_MAX + 1, |
|---|
| 258 | + .min_uV = LM36274_VOLTAGE_MIN, |
|---|
| 259 | + .uV_step = LM363X_STEP_50mV, |
|---|
| 260 | + .type = REGULATOR_VOLTAGE, |
|---|
| 261 | + .owner = THIS_MODULE, |
|---|
| 262 | + .vsel_reg = LM36274_REG_VOUT_NEG, |
|---|
| 263 | + .vsel_mask = LM36274_VOUT_MASK, |
|---|
| 264 | + .enable_reg = LM36274_REG_BIAS_CONFIG_1, |
|---|
| 265 | + .enable_mask = LM36274_EN_VNEG_MASK, |
|---|
| 266 | + }, |
|---|
| 220 | 267 | }; |
|---|
| 221 | 268 | |
|---|
| 222 | 269 | static struct gpio_desc *lm363x_regulator_of_get_enable_gpio(struct device *dev, int id) |
|---|
| .. | .. |
|---|
| 224 | 271 | /* |
|---|
| 225 | 272 | * Check LCM_EN1/2_GPIO is configured. |
|---|
| 226 | 273 | * Those pins are used for enabling VPOS/VNEG LDOs. |
|---|
| 274 | + * Do not use devm* here: the regulator core takes over the |
|---|
| 275 | + * lifecycle management of the GPIO descriptor. |
|---|
| 227 | 276 | */ |
|---|
| 228 | 277 | switch (id) { |
|---|
| 229 | 278 | case LM3632_LDO_POS: |
|---|
| 230 | | - return devm_gpiod_get_index_optional(dev, "enable", 0, GPIOD_OUT_LOW); |
|---|
| 279 | + case LM36274_LDO_POS: |
|---|
| 280 | + return gpiod_get_index_optional(dev, "enable", 0, |
|---|
| 281 | + GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE); |
|---|
| 231 | 282 | case LM3632_LDO_NEG: |
|---|
| 232 | | - return devm_gpiod_get_index_optional(dev, "enable", 1, GPIOD_OUT_LOW); |
|---|
| 283 | + case LM36274_LDO_NEG: |
|---|
| 284 | + return gpiod_get_index_optional(dev, "enable", 1, |
|---|
| 285 | + GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE); |
|---|
| 233 | 286 | default: |
|---|
| 234 | 287 | return NULL; |
|---|
| 235 | 288 | } |
|---|
| 289 | +} |
|---|
| 290 | + |
|---|
| 291 | +static int lm363x_regulator_set_ext_en(struct regmap *regmap, int id) |
|---|
| 292 | +{ |
|---|
| 293 | + int ext_en_mask = 0; |
|---|
| 294 | + |
|---|
| 295 | + switch (id) { |
|---|
| 296 | + case LM3632_LDO_POS: |
|---|
| 297 | + case LM3632_LDO_NEG: |
|---|
| 298 | + ext_en_mask = LM3632_EXT_EN_MASK; |
|---|
| 299 | + break; |
|---|
| 300 | + case LM36274_LDO_POS: |
|---|
| 301 | + case LM36274_LDO_NEG: |
|---|
| 302 | + ext_en_mask = LM36274_EXT_EN_MASK; |
|---|
| 303 | + break; |
|---|
| 304 | + default: |
|---|
| 305 | + return -ENODEV; |
|---|
| 306 | + } |
|---|
| 307 | + |
|---|
| 308 | + return regmap_update_bits(regmap, lm363x_regulator_desc[id].enable_reg, |
|---|
| 309 | + ext_en_mask, ext_en_mask); |
|---|
| 236 | 310 | } |
|---|
| 237 | 311 | |
|---|
| 238 | 312 | static int lm363x_regulator_probe(struct platform_device *pdev) |
|---|
| .. | .. |
|---|
| 254 | 328 | * Register update is required if the pin is used. |
|---|
| 255 | 329 | */ |
|---|
| 256 | 330 | gpiod = lm363x_regulator_of_get_enable_gpio(dev, id); |
|---|
| 331 | + if (IS_ERR(gpiod)) |
|---|
| 332 | + return PTR_ERR(gpiod); |
|---|
| 333 | + |
|---|
| 257 | 334 | if (gpiod) { |
|---|
| 258 | 335 | cfg.ena_gpiod = gpiod; |
|---|
| 259 | | - |
|---|
| 260 | | - ret = regmap_update_bits(regmap, LM3632_REG_BIAS_CONFIG, |
|---|
| 261 | | - LM3632_EXT_EN_MASK, |
|---|
| 262 | | - LM3632_EXT_EN_MASK); |
|---|
| 336 | + ret = lm363x_regulator_set_ext_en(regmap, id); |
|---|
| 263 | 337 | if (ret) { |
|---|
| 338 | + gpiod_put(gpiod); |
|---|
| 264 | 339 | dev_err(dev, "External pin err: %d\n", ret); |
|---|
| 265 | 340 | return ret; |
|---|
| 266 | 341 | } |
|---|