Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Regulator driver for tps65090 power management chip. |
| 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 | #include <linux/module.h> |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 20 | #include <linux/init.h> |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 21 | #include <linux/gpio.h> |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 22 | #include <linux/of_gpio.h> |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 23 | #include <linux/slab.h> |
| 24 | #include <linux/err.h> |
| 25 | #include <linux/platform_device.h> |
| 26 | #include <linux/regulator/driver.h> |
| 27 | #include <linux/regulator/machine.h> |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 28 | #include <linux/regulator/of_regulator.h> |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 29 | #include <linux/mfd/tps65090.h> |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 30 | |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 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 | |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 45 | struct tps65090_regulator { |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 46 | struct device *dev; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 47 | struct regulator_desc *desc; |
| 48 | struct regulator_dev *rdev; |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 49 | bool overcurrent_wait_valid; |
| 50 | int overcurrent_wait; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 51 | }; |
| 52 | |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 53 | static struct regulator_ops tps65090_ext_control_ops = { |
| 54 | }; |
| 55 | |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 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 | } |
| 82 | |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 83 | static struct regulator_ops tps65090_reg_contol_ops = { |
| 84 | .enable = regulator_enable_regmap, |
| 85 | .disable = regulator_disable_regmap, |
| 86 | .is_enabled = regulator_is_enabled_regmap, |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 87 | }; |
| 88 | |
Laxman Dewangan | 3a81ef8 | 2012-10-09 15:19:01 +0530 | [diff] [blame] | 89 | static struct regulator_ops tps65090_ldo_ops = { |
| 90 | }; |
| 91 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 92 | #define tps65090_REG_DESC(_id, _sname, _en_reg, _ops) \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 93 | { \ |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 94 | .name = "TPS65090_RAILS"#_id, \ |
| 95 | .supply_name = _sname, \ |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 96 | .id = TPS65090_REGULATOR_##_id, \ |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 97 | .ops = &_ops, \ |
| 98 | .enable_reg = _en_reg, \ |
| 99 | .enable_mask = BIT(0), \ |
| 100 | .type = REGULATOR_VOLTAGE, \ |
| 101 | .owner = THIS_MODULE, \ |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 102 | } |
| 103 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 104 | static struct regulator_desc tps65090_regulator_desc[] = { |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 105 | tps65090_REG_DESC(DCDC1, "vsys1", 0x0C, tps65090_reg_contol_ops), |
| 106 | tps65090_REG_DESC(DCDC2, "vsys2", 0x0D, tps65090_reg_contol_ops), |
| 107 | tps65090_REG_DESC(DCDC3, "vsys3", 0x0E, tps65090_reg_contol_ops), |
| 108 | tps65090_REG_DESC(FET1, "infet1", 0x0F, tps65090_reg_contol_ops), |
| 109 | tps65090_REG_DESC(FET2, "infet2", 0x10, tps65090_reg_contol_ops), |
| 110 | tps65090_REG_DESC(FET3, "infet3", 0x11, tps65090_reg_contol_ops), |
| 111 | tps65090_REG_DESC(FET4, "infet4", 0x12, tps65090_reg_contol_ops), |
| 112 | tps65090_REG_DESC(FET5, "infet5", 0x13, tps65090_reg_contol_ops), |
| 113 | tps65090_REG_DESC(FET6, "infet6", 0x14, tps65090_reg_contol_ops), |
| 114 | tps65090_REG_DESC(FET7, "infet7", 0x15, tps65090_reg_contol_ops), |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 115 | tps65090_REG_DESC(LDO1, "vsys-l1", 0, tps65090_ldo_ops), |
| 116 | tps65090_REG_DESC(LDO2, "vsys-l2", 0, tps65090_ldo_ops), |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 117 | }; |
| 118 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 119 | static inline bool is_dcdc(int id) |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 120 | { |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 121 | switch (id) { |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 122 | case TPS65090_REGULATOR_DCDC1: |
| 123 | case TPS65090_REGULATOR_DCDC2: |
| 124 | case TPS65090_REGULATOR_DCDC3: |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 125 | return true; |
| 126 | default: |
| 127 | return false; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 128 | } |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 129 | } |
| 130 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 131 | static int tps65090_config_ext_control( |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 132 | struct tps65090_regulator *ri, bool enable) |
| 133 | { |
| 134 | int ret; |
| 135 | struct device *parent = ri->dev->parent; |
| 136 | unsigned int reg_en_reg = ri->desc->enable_reg; |
| 137 | |
| 138 | if (enable) |
| 139 | ret = tps65090_set_bits(parent, reg_en_reg, 1); |
| 140 | else |
| 141 | ret = tps65090_clr_bits(parent, reg_en_reg, 1); |
| 142 | if (ret < 0) |
| 143 | dev_err(ri->dev, "Error in updating reg 0x%x\n", reg_en_reg); |
| 144 | return ret; |
| 145 | } |
| 146 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 147 | static int tps65090_regulator_disable_ext_control( |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 148 | struct tps65090_regulator *ri, |
| 149 | struct tps65090_regulator_plat_data *tps_pdata) |
| 150 | { |
| 151 | int ret = 0; |
| 152 | struct device *parent = ri->dev->parent; |
| 153 | unsigned int reg_en_reg = ri->desc->enable_reg; |
| 154 | |
| 155 | /* |
| 156 | * First enable output for internal control if require. |
| 157 | * And then disable external control. |
| 158 | */ |
| 159 | if (tps_pdata->reg_init_data->constraints.always_on || |
| 160 | tps_pdata->reg_init_data->constraints.boot_on) { |
| 161 | ret = tps65090_set_bits(parent, reg_en_reg, 0); |
| 162 | if (ret < 0) { |
| 163 | dev_err(ri->dev, "Error in set reg 0x%x\n", reg_en_reg); |
| 164 | return ret; |
| 165 | } |
| 166 | } |
| 167 | return tps65090_config_ext_control(ri, false); |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 168 | } |
| 169 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 170 | static void tps65090_configure_regulator_config( |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 171 | struct tps65090_regulator_plat_data *tps_pdata, |
| 172 | struct regulator_config *config) |
| 173 | { |
| 174 | if (gpio_is_valid(tps_pdata->gpio)) { |
| 175 | int gpio_flag = GPIOF_OUT_INIT_LOW; |
| 176 | |
| 177 | if (tps_pdata->reg_init_data->constraints.always_on || |
| 178 | tps_pdata->reg_init_data->constraints.boot_on) |
| 179 | gpio_flag = GPIOF_OUT_INIT_HIGH; |
| 180 | |
| 181 | config->ena_gpio = tps_pdata->gpio; |
| 182 | config->ena_gpio_flags = gpio_flag; |
| 183 | } |
| 184 | } |
| 185 | |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 186 | #ifdef CONFIG_OF |
| 187 | static struct of_regulator_match tps65090_matches[] = { |
| 188 | { .name = "dcdc1", }, |
| 189 | { .name = "dcdc2", }, |
| 190 | { .name = "dcdc3", }, |
| 191 | { .name = "fet1", }, |
| 192 | { .name = "fet2", }, |
| 193 | { .name = "fet3", }, |
| 194 | { .name = "fet4", }, |
| 195 | { .name = "fet5", }, |
| 196 | { .name = "fet6", }, |
| 197 | { .name = "fet7", }, |
| 198 | { .name = "ldo1", }, |
| 199 | { .name = "ldo2", }, |
| 200 | }; |
| 201 | |
| 202 | static struct tps65090_platform_data *tps65090_parse_dt_reg_data( |
| 203 | struct platform_device *pdev, |
| 204 | struct of_regulator_match **tps65090_reg_matches) |
| 205 | { |
| 206 | struct tps65090_platform_data *tps65090_pdata; |
| 207 | struct device_node *np = pdev->dev.parent->of_node; |
| 208 | struct device_node *regulators; |
| 209 | int idx = 0, ret; |
| 210 | struct tps65090_regulator_plat_data *reg_pdata; |
| 211 | |
| 212 | tps65090_pdata = devm_kzalloc(&pdev->dev, sizeof(*tps65090_pdata), |
| 213 | GFP_KERNEL); |
Sachin Kamat | 0ad91c6 | 2014-02-20 14:23:15 +0530 | [diff] [blame] | 214 | if (!tps65090_pdata) |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 215 | return ERR_PTR(-ENOMEM); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 216 | |
| 217 | reg_pdata = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX * |
| 218 | sizeof(*reg_pdata), GFP_KERNEL); |
Sachin Kamat | 0ad91c6 | 2014-02-20 14:23:15 +0530 | [diff] [blame] | 219 | if (!reg_pdata) |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 220 | return ERR_PTR(-ENOMEM); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 221 | |
Laxman Dewangan | 4c850ea | 2013-10-08 19:31:02 +0530 | [diff] [blame] | 222 | regulators = of_get_child_by_name(np, "regulators"); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 223 | if (!regulators) { |
| 224 | dev_err(&pdev->dev, "regulator node not found\n"); |
| 225 | return ERR_PTR(-ENODEV); |
| 226 | } |
| 227 | |
Axel Lin | 09a228e | 2013-01-30 20:28:20 +0800 | [diff] [blame] | 228 | ret = of_regulator_match(&pdev->dev, regulators, tps65090_matches, |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 229 | ARRAY_SIZE(tps65090_matches)); |
Sachin Kamat | 026cdfe | 2014-02-17 14:33:37 +0530 | [diff] [blame] | 230 | of_node_put(regulators); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 231 | if (ret < 0) { |
| 232 | dev_err(&pdev->dev, |
| 233 | "Error parsing regulator init data: %d\n", ret); |
| 234 | return ERR_PTR(ret); |
| 235 | } |
| 236 | |
| 237 | *tps65090_reg_matches = tps65090_matches; |
| 238 | for (idx = 0; idx < ARRAY_SIZE(tps65090_matches); idx++) { |
| 239 | struct regulator_init_data *ri_data; |
| 240 | struct tps65090_regulator_plat_data *rpdata; |
| 241 | |
| 242 | rpdata = ®_pdata[idx]; |
| 243 | ri_data = tps65090_matches[idx].init_data; |
| 244 | if (!ri_data || !tps65090_matches[idx].of_node) |
| 245 | continue; |
| 246 | |
| 247 | rpdata->reg_init_data = ri_data; |
| 248 | rpdata->enable_ext_control = of_property_read_bool( |
| 249 | tps65090_matches[idx].of_node, |
| 250 | "ti,enable-ext-control"); |
| 251 | if (rpdata->enable_ext_control) |
| 252 | rpdata->gpio = of_get_named_gpio(np, |
| 253 | "dcdc-ext-control-gpios", 0); |
| 254 | |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 255 | if (of_property_read_u32(tps65090_matches[idx].of_node, |
| 256 | "ti,overcurrent-wait", |
| 257 | &rpdata->overcurrent_wait) == 0) |
| 258 | rpdata->overcurrent_wait_valid = true; |
| 259 | |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 260 | tps65090_pdata->reg_pdata[idx] = rpdata; |
| 261 | } |
| 262 | return tps65090_pdata; |
| 263 | } |
| 264 | #else |
| 265 | static inline struct tps65090_platform_data *tps65090_parse_dt_reg_data( |
| 266 | struct platform_device *pdev, |
| 267 | struct of_regulator_match **tps65090_reg_matches) |
| 268 | { |
| 269 | *tps65090_reg_matches = NULL; |
| 270 | return NULL; |
| 271 | } |
| 272 | #endif |
| 273 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 274 | static int tps65090_regulator_probe(struct platform_device *pdev) |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 275 | { |
Axel Lin | 06c4998 | 2012-04-17 17:08:56 +0800 | [diff] [blame] | 276 | struct tps65090 *tps65090_mfd = dev_get_drvdata(pdev->dev.parent); |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 277 | struct tps65090_regulator *ri = NULL; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 278 | struct regulator_config config = { }; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 279 | struct regulator_dev *rdev; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 280 | struct tps65090_regulator_plat_data *tps_pdata; |
| 281 | struct tps65090_regulator *pmic; |
| 282 | struct tps65090_platform_data *tps65090_pdata; |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 283 | struct of_regulator_match *tps65090_reg_matches = NULL; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 284 | int num; |
| 285 | int ret; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 286 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 287 | dev_dbg(&pdev->dev, "Probing regulator\n"); |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 288 | |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 289 | tps65090_pdata = dev_get_platdata(pdev->dev.parent); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 290 | if (!tps65090_pdata && tps65090_mfd->dev->of_node) |
| 291 | tps65090_pdata = tps65090_parse_dt_reg_data(pdev, |
| 292 | &tps65090_reg_matches); |
| 293 | if (IS_ERR_OR_NULL(tps65090_pdata)) { |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 294 | dev_err(&pdev->dev, "Platform data missing\n"); |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 295 | return tps65090_pdata ? PTR_ERR(tps65090_pdata) : -EINVAL; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 296 | } |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 297 | |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 298 | pmic = devm_kzalloc(&pdev->dev, TPS65090_REGULATOR_MAX * sizeof(*pmic), |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 299 | GFP_KERNEL); |
Sachin Kamat | 0ad91c6 | 2014-02-20 14:23:15 +0530 | [diff] [blame] | 300 | if (!pmic) |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 301 | return -ENOMEM; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 302 | |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 303 | for (num = 0; num < TPS65090_REGULATOR_MAX; num++) { |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 304 | tps_pdata = tps65090_pdata->reg_pdata[num]; |
| 305 | |
| 306 | ri = &pmic[num]; |
| 307 | ri->dev = &pdev->dev; |
| 308 | ri->desc = &tps65090_regulator_desc[num]; |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 309 | ri->overcurrent_wait_valid = tps_pdata->overcurrent_wait_valid; |
| 310 | ri->overcurrent_wait = tps_pdata->overcurrent_wait; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 311 | |
| 312 | /* |
| 313 | * TPS5090 DCDC support the control from external digital input. |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 314 | * Configure it as per platform data. |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 315 | */ |
| 316 | if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data) { |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 317 | if (tps_pdata->enable_ext_control) { |
| 318 | tps65090_configure_regulator_config( |
| 319 | tps_pdata, &config); |
| 320 | ri->desc->ops = &tps65090_ext_control_ops; |
| 321 | } else { |
| 322 | ret = tps65090_regulator_disable_ext_control( |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 323 | ri, tps_pdata); |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 324 | if (ret < 0) { |
| 325 | dev_err(&pdev->dev, |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 326 | "failed disable ext control\n"); |
Sachin Kamat | 9738efa | 2013-09-04 17:17:48 +0530 | [diff] [blame] | 327 | return ret; |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 328 | } |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 329 | } |
| 330 | } |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 331 | |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 332 | config.dev = pdev->dev.parent; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 333 | config.driver_data = ri; |
| 334 | config.regmap = tps65090_mfd->rmap; |
| 335 | if (tps_pdata) |
| 336 | config.init_data = tps_pdata->reg_init_data; |
| 337 | else |
| 338 | config.init_data = NULL; |
Laxman Dewangan | 6c7a7a0 | 2013-01-29 14:35:16 +0530 | [diff] [blame] | 339 | if (tps65090_reg_matches) |
| 340 | config.of_node = tps65090_reg_matches[num].of_node; |
| 341 | else |
| 342 | config.of_node = NULL; |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 343 | |
Sachin Kamat | 9738efa | 2013-09-04 17:17:48 +0530 | [diff] [blame] | 344 | rdev = devm_regulator_register(&pdev->dev, ri->desc, &config); |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 345 | if (IS_ERR(rdev)) { |
| 346 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 347 | ri->desc->name); |
Sachin Kamat | 9738efa | 2013-09-04 17:17:48 +0530 | [diff] [blame] | 348 | return PTR_ERR(rdev); |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 349 | } |
| 350 | ri->rdev = rdev; |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 351 | |
Doug Anderson | 2904144 | 2014-04-16 16:12:28 -0700 | [diff] [blame^] | 352 | if (ri->overcurrent_wait_valid) { |
| 353 | ret = tps65090_reg_set_overcurrent_wait(ri, rdev); |
| 354 | if (ret < 0) |
| 355 | return ret; |
| 356 | } |
| 357 | |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 358 | /* Enable external control if it is require */ |
| 359 | if (tps_pdata && is_dcdc(num) && tps_pdata->reg_init_data && |
| 360 | tps_pdata->enable_ext_control) { |
| 361 | ret = tps65090_config_ext_control(ri, true); |
Sachin Kamat | 9738efa | 2013-09-04 17:17:48 +0530 | [diff] [blame] | 362 | if (ret < 0) |
| 363 | return ret; |
Laxman Dewangan | f329b17 | 2012-10-09 15:19:02 +0530 | [diff] [blame] | 364 | } |
Laxman Dewangan | 24282a1 | 2012-10-09 15:18:59 +0530 | [diff] [blame] | 365 | } |
| 366 | |
| 367 | platform_set_drvdata(pdev, pmic); |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 368 | return 0; |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | static struct platform_driver tps65090_regulator_driver = { |
| 372 | .driver = { |
Laxman Dewangan | 8620ca9 | 2012-10-09 15:19:00 +0530 | [diff] [blame] | 373 | .name = "tps65090-pmic", |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 374 | .owner = THIS_MODULE, |
| 375 | }, |
| 376 | .probe = tps65090_regulator_probe, |
Venu Byravarasu | 452534e | 2012-03-22 18:34:09 +0530 | [diff] [blame] | 377 | }; |
| 378 | |
| 379 | static int __init tps65090_regulator_init(void) |
| 380 | { |
| 381 | return platform_driver_register(&tps65090_regulator_driver); |
| 382 | } |
| 383 | subsys_initcall(tps65090_regulator_init); |
| 384 | |
| 385 | static void __exit tps65090_regulator_exit(void) |
| 386 | { |
| 387 | platform_driver_unregister(&tps65090_regulator_driver); |
| 388 | } |
| 389 | module_exit(tps65090_regulator_exit); |
| 390 | |
| 391 | MODULE_DESCRIPTION("tps65090 regulator driver"); |
| 392 | MODULE_AUTHOR("Venu Byravarasu <vbyravarasu@nvidia.com>"); |
| 393 | MODULE_LICENSE("GPL v2"); |
Axel Lin | d95420b | 2012-11-23 23:47:16 +0800 | [diff] [blame] | 394 | MODULE_ALIAS("platform:tps65090-pmic"); |