Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 1 | /* |
| 2 | * da9052-regulator.c: Regulator driver for DA9052 |
| 3 | * |
| 4 | * Copyright(c) 2011 Dialog Semiconductor Ltd. |
| 5 | * |
| 6 | * Author: David Dajun Chen <dchen@diasemi.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 as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/moduleparam.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/err.h> |
| 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 22 | #ifdef CONFIG_OF |
Mark Brown | cd22a96 | 2012-04-16 09:54:24 +0100 | [diff] [blame] | 23 | #include <linux/of.h> |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 24 | #include <linux/regulator/of_regulator.h> |
| 25 | #endif |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 26 | |
| 27 | #include <linux/mfd/da9052/da9052.h> |
| 28 | #include <linux/mfd/da9052/reg.h> |
| 29 | #include <linux/mfd/da9052/pdata.h> |
| 30 | |
| 31 | /* Buck step size */ |
| 32 | #define DA9052_BUCK_PERI_3uV_STEP 100000 |
| 33 | #define DA9052_BUCK_PERI_REG_MAP_UPTO_3uV 24 |
| 34 | #define DA9052_CONST_3uV 3000000 |
| 35 | |
| 36 | #define DA9052_MIN_UA 0 |
| 37 | #define DA9052_MAX_UA 3 |
| 38 | #define DA9052_CURRENT_RANGE 4 |
| 39 | |
| 40 | /* Bit masks */ |
| 41 | #define DA9052_BUCK_ILIM_MASK_EVEN 0x0c |
| 42 | #define DA9052_BUCK_ILIM_MASK_ODD 0xc0 |
| 43 | |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 44 | /* DA9052 REGULATOR IDs */ |
| 45 | #define DA9052_ID_BUCK1 0 |
| 46 | #define DA9052_ID_BUCK2 1 |
| 47 | #define DA9052_ID_BUCK3 2 |
| 48 | #define DA9052_ID_BUCK4 3 |
| 49 | #define DA9052_ID_LDO1 4 |
| 50 | #define DA9052_ID_LDO2 5 |
| 51 | #define DA9052_ID_LDO3 6 |
| 52 | #define DA9052_ID_LDO4 7 |
| 53 | #define DA9052_ID_LDO5 8 |
| 54 | #define DA9052_ID_LDO6 9 |
| 55 | #define DA9052_ID_LDO7 10 |
| 56 | #define DA9052_ID_LDO8 11 |
| 57 | #define DA9052_ID_LDO9 12 |
| 58 | #define DA9052_ID_LDO10 13 |
| 59 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 60 | static const u32 da9052_current_limits[3][4] = { |
| 61 | {700000, 800000, 1000000, 1200000}, /* DA9052-BC BUCKs */ |
| 62 | {1600000, 2000000, 2400000, 3000000}, /* DA9053-AA/Bx BUCK-CORE */ |
| 63 | {800000, 1000000, 1200000, 1500000}, /* DA9053-AA/Bx BUCK-PRO, |
| 64 | * BUCK-MEM and BUCK-PERI |
| 65 | */ |
| 66 | }; |
| 67 | |
| 68 | struct da9052_regulator_info { |
| 69 | struct regulator_desc reg_desc; |
| 70 | int step_uV; |
| 71 | int min_uV; |
| 72 | int max_uV; |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 73 | unsigned char activate_bit; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | struct da9052_regulator { |
| 77 | struct da9052 *da9052; |
| 78 | struct da9052_regulator_info *info; |
| 79 | struct regulator_dev *rdev; |
| 80 | }; |
| 81 | |
| 82 | static int verify_range(struct da9052_regulator_info *info, |
| 83 | int min_uV, int max_uV) |
| 84 | { |
| 85 | if (min_uV > info->max_uV || max_uV < info->min_uV) |
| 86 | return -EINVAL; |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 91 | static int da9052_dcdc_get_current_limit(struct regulator_dev *rdev) |
| 92 | { |
| 93 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 94 | int offset = rdev_get_id(rdev); |
| 95 | int ret, row = 2; |
| 96 | |
| 97 | ret = da9052_reg_read(regulator->da9052, DA9052_BUCKA_REG + offset/2); |
| 98 | if (ret < 0) |
| 99 | return ret; |
| 100 | |
| 101 | /* Determine the even or odd position of the buck current limit |
| 102 | * register field |
| 103 | */ |
| 104 | if (offset % 2 == 0) |
| 105 | ret = (ret & DA9052_BUCK_ILIM_MASK_EVEN) >> 2; |
| 106 | else |
| 107 | ret = (ret & DA9052_BUCK_ILIM_MASK_ODD) >> 6; |
| 108 | |
| 109 | /* Select the appropriate current limit range */ |
| 110 | if (regulator->da9052->chip_id == DA9052) |
| 111 | row = 0; |
| 112 | else if (offset == 0) |
| 113 | row = 1; |
| 114 | |
| 115 | return da9052_current_limits[row][ret]; |
| 116 | } |
| 117 | |
| 118 | static int da9052_dcdc_set_current_limit(struct regulator_dev *rdev, int min_uA, |
| 119 | int max_uA) |
| 120 | { |
| 121 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 122 | int offset = rdev_get_id(rdev); |
| 123 | int reg_val = 0; |
| 124 | int i, row = 2; |
| 125 | |
| 126 | /* Select the appropriate current limit range */ |
| 127 | if (regulator->da9052->chip_id == DA9052) |
| 128 | row = 0; |
| 129 | else if (offset == 0) |
| 130 | row = 1; |
| 131 | |
Axel Lin | 19d23c2 | 2012-08-08 20:23:54 +0800 | [diff] [blame] | 132 | for (i = DA9052_CURRENT_RANGE - 1; i >= 0; i--) { |
Axel Lin | 1e369bc | 2012-11-26 15:23:38 +0800 | [diff] [blame] | 133 | if ((min_uA <= da9052_current_limits[row][i]) && |
| 134 | (da9052_current_limits[row][i] <= max_uA)) { |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 135 | reg_val = i; |
| 136 | break; |
| 137 | } |
| 138 | } |
| 139 | |
Axel Lin | 1e369bc | 2012-11-26 15:23:38 +0800 | [diff] [blame] | 140 | if (i < 0) |
| 141 | return -EINVAL; |
| 142 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 143 | /* Determine the even or odd position of the buck current limit |
| 144 | * register field |
| 145 | */ |
| 146 | if (offset % 2 == 0) |
| 147 | return da9052_reg_update(regulator->da9052, |
| 148 | DA9052_BUCKA_REG + offset/2, |
| 149 | DA9052_BUCK_ILIM_MASK_EVEN, |
| 150 | reg_val << 2); |
| 151 | else |
| 152 | return da9052_reg_update(regulator->da9052, |
| 153 | DA9052_BUCKA_REG + offset/2, |
| 154 | DA9052_BUCK_ILIM_MASK_ODD, |
| 155 | reg_val << 6); |
| 156 | } |
| 157 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 158 | static int da9052_list_voltage(struct regulator_dev *rdev, |
| 159 | unsigned int selector) |
| 160 | { |
| 161 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 162 | struct da9052_regulator_info *info = regulator->info; |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 163 | int id = rdev_get_id(rdev); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 164 | int volt_uV; |
| 165 | |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 166 | if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052) |
| 167 | && (selector >= DA9052_BUCK_PERI_REG_MAP_UPTO_3uV)) { |
| 168 | volt_uV = ((DA9052_BUCK_PERI_REG_MAP_UPTO_3uV * info->step_uV) |
| 169 | + info->min_uV); |
| 170 | volt_uV += (selector - DA9052_BUCK_PERI_REG_MAP_UPTO_3uV) |
| 171 | * (DA9052_BUCK_PERI_3uV_STEP); |
| 172 | } else { |
| 173 | volt_uV = (selector * info->step_uV) + info->min_uV; |
| 174 | } |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 175 | |
| 176 | if (volt_uV > info->max_uV) |
| 177 | return -EINVAL; |
| 178 | |
| 179 | return volt_uV; |
| 180 | } |
| 181 | |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 182 | static int da9052_map_voltage(struct regulator_dev *rdev, |
| 183 | int min_uV, int max_uV) |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 184 | { |
| 185 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 186 | struct da9052_regulator_info *info = regulator->info; |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 187 | int id = rdev_get_id(rdev); |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 188 | int ret, sel; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 189 | |
| 190 | ret = verify_range(info, min_uV, max_uV); |
| 191 | if (ret < 0) |
| 192 | return ret; |
| 193 | |
| 194 | if (min_uV < info->min_uV) |
| 195 | min_uV = info->min_uV; |
| 196 | |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 197 | if ((id == DA9052_ID_BUCK4) && (regulator->da9052->chip_id == DA9052) |
| 198 | && (min_uV >= DA9052_CONST_3uV)) { |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 199 | sel = DA9052_BUCK_PERI_REG_MAP_UPTO_3uV + |
| 200 | DIV_ROUND_UP(min_uV - DA9052_CONST_3uV, |
| 201 | DA9052_BUCK_PERI_3uV_STEP); |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 202 | } else { |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 203 | sel = DIV_ROUND_UP(min_uV - info->min_uV, info->step_uV); |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 204 | } |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 205 | |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 206 | ret = da9052_list_voltage(rdev, sel); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 207 | if (ret < 0) |
| 208 | return ret; |
| 209 | |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 210 | return sel; |
| 211 | } |
| 212 | |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 213 | static int da9052_regulator_set_voltage_sel(struct regulator_dev *rdev, |
| 214 | unsigned int selector) |
| 215 | { |
| 216 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 217 | struct da9052_regulator_info *info = regulator->info; |
| 218 | int id = rdev_get_id(rdev); |
| 219 | int ret; |
| 220 | |
| 221 | ret = da9052_reg_update(regulator->da9052, rdev->desc->vsel_reg, |
| 222 | rdev->desc->vsel_mask, selector); |
| 223 | if (ret < 0) |
| 224 | return ret; |
| 225 | |
| 226 | /* Some LDOs and DCDCs are DVC controlled which requires enabling of |
| 227 | * the activate bit to implment the changes on the output. |
| 228 | */ |
| 229 | switch (id) { |
| 230 | case DA9052_ID_BUCK1: |
| 231 | case DA9052_ID_BUCK2: |
| 232 | case DA9052_ID_BUCK3: |
| 233 | case DA9052_ID_LDO2: |
| 234 | case DA9052_ID_LDO3: |
| 235 | ret = da9052_reg_update(regulator->da9052, DA9052_SUPPLY_REG, |
| 236 | info->activate_bit, info->activate_bit); |
| 237 | break; |
| 238 | } |
| 239 | |
| 240 | return ret; |
| 241 | } |
| 242 | |
Philipp Zabel | 5c99a7b | 2014-02-06 15:35:21 +0100 | [diff] [blame] | 243 | static int da9052_regulator_set_voltage_time_sel(struct regulator_dev *rdev, |
| 244 | unsigned int old_sel, |
| 245 | unsigned int new_sel) |
| 246 | { |
| 247 | struct da9052_regulator *regulator = rdev_get_drvdata(rdev); |
| 248 | struct da9052_regulator_info *info = regulator->info; |
| 249 | int id = rdev_get_id(rdev); |
| 250 | int ret = 0; |
| 251 | |
| 252 | /* The DVC controlled LDOs and DCDCs ramp with 6.25mV/µs after enabling |
| 253 | * the activate bit. |
| 254 | */ |
| 255 | switch (id) { |
| 256 | case DA9052_ID_BUCK1: |
| 257 | case DA9052_ID_BUCK2: |
| 258 | case DA9052_ID_BUCK3: |
| 259 | case DA9052_ID_LDO2: |
| 260 | case DA9052_ID_LDO3: |
| 261 | ret = (new_sel - old_sel) * info->step_uV / 6250; |
| 262 | break; |
| 263 | } |
| 264 | |
| 265 | return ret; |
| 266 | } |
| 267 | |
Julia Lawall | 71242b4 | 2015-12-19 16:07:09 +0100 | [diff] [blame] | 268 | static const struct regulator_ops da9052_dcdc_ops = { |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 269 | .get_current_limit = da9052_dcdc_get_current_limit, |
| 270 | .set_current_limit = da9052_dcdc_set_current_limit, |
| 271 | |
| 272 | .list_voltage = da9052_list_voltage, |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 273 | .map_voltage = da9052_map_voltage, |
Axel Lin | 09812bc | 2012-04-24 09:54:38 +0800 | [diff] [blame] | 274 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 275 | .set_voltage_sel = da9052_regulator_set_voltage_sel, |
Philipp Zabel | 5c99a7b | 2014-02-06 15:35:21 +0100 | [diff] [blame] | 276 | .set_voltage_time_sel = da9052_regulator_set_voltage_time_sel, |
Axel Lin | 0d481f7 | 2012-04-17 11:34:32 +0800 | [diff] [blame] | 277 | .is_enabled = regulator_is_enabled_regmap, |
| 278 | .enable = regulator_enable_regmap, |
| 279 | .disable = regulator_disable_regmap, |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 280 | }; |
| 281 | |
Julia Lawall | 71242b4 | 2015-12-19 16:07:09 +0100 | [diff] [blame] | 282 | static const struct regulator_ops da9052_ldo_ops = { |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 283 | .list_voltage = da9052_list_voltage, |
Axel Lin | 4923b48b | 2012-05-16 13:12:35 +0800 | [diff] [blame] | 284 | .map_voltage = da9052_map_voltage, |
Axel Lin | 09812bc | 2012-04-24 09:54:38 +0800 | [diff] [blame] | 285 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 286 | .set_voltage_sel = da9052_regulator_set_voltage_sel, |
Philipp Zabel | 5c99a7b | 2014-02-06 15:35:21 +0100 | [diff] [blame] | 287 | .set_voltage_time_sel = da9052_regulator_set_voltage_time_sel, |
Axel Lin | 0d481f7 | 2012-04-17 11:34:32 +0800 | [diff] [blame] | 288 | .is_enabled = regulator_is_enabled_regmap, |
| 289 | .enable = regulator_enable_regmap, |
| 290 | .disable = regulator_disable_regmap, |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 291 | }; |
| 292 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 293 | #define DA9052_LDO(_id, step, min, max, sbits, ebits, abits) \ |
| 294 | {\ |
| 295 | .reg_desc = {\ |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 296 | .name = #_id,\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 297 | .ops = &da9052_ldo_ops,\ |
| 298 | .type = REGULATOR_VOLTAGE,\ |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 299 | .id = DA9052_ID_##_id,\ |
Axel Lin | 7b95765 | 2012-03-05 20:04:32 +0800 | [diff] [blame] | 300 | .n_voltages = (max - min) / step + 1, \ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 301 | .owner = THIS_MODULE,\ |
Axel Lin | 09812bc | 2012-04-24 09:54:38 +0800 | [diff] [blame] | 302 | .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ |
| 303 | .vsel_mask = (1 << (sbits)) - 1,\ |
Axel Lin | 0d481f7 | 2012-04-17 11:34:32 +0800 | [diff] [blame] | 304 | .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ |
| 305 | .enable_mask = 1 << (ebits),\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 306 | },\ |
| 307 | .min_uV = (min) * 1000,\ |
| 308 | .max_uV = (max) * 1000,\ |
| 309 | .step_uV = (step) * 1000,\ |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 310 | .activate_bit = (abits),\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | #define DA9052_DCDC(_id, step, min, max, sbits, ebits, abits) \ |
| 314 | {\ |
| 315 | .reg_desc = {\ |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 316 | .name = #_id,\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 317 | .ops = &da9052_dcdc_ops,\ |
| 318 | .type = REGULATOR_VOLTAGE,\ |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 319 | .id = DA9052_ID_##_id,\ |
Axel Lin | 7b95765 | 2012-03-05 20:04:32 +0800 | [diff] [blame] | 320 | .n_voltages = (max - min) / step + 1, \ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 321 | .owner = THIS_MODULE,\ |
Axel Lin | 09812bc | 2012-04-24 09:54:38 +0800 | [diff] [blame] | 322 | .vsel_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ |
| 323 | .vsel_mask = (1 << (sbits)) - 1,\ |
Axel Lin | 0d481f7 | 2012-04-17 11:34:32 +0800 | [diff] [blame] | 324 | .enable_reg = DA9052_BUCKCORE_REG + DA9052_ID_##_id, \ |
| 325 | .enable_mask = 1 << (ebits),\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 326 | },\ |
| 327 | .min_uV = (min) * 1000,\ |
| 328 | .max_uV = (max) * 1000,\ |
| 329 | .step_uV = (step) * 1000,\ |
Axel Lin | d706b1e | 2013-10-16 17:33:59 +0800 | [diff] [blame] | 330 | .activate_bit = (abits),\ |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 331 | } |
| 332 | |
Axel Lin | 6242eae | 2011-12-20 17:12:00 +0800 | [diff] [blame] | 333 | static struct da9052_regulator_info da9052_regulator_info[] = { |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 334 | DA9052_DCDC(BUCK1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), |
| 335 | DA9052_DCDC(BUCK2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), |
Steve Twiss | 707319b | 2016-07-20 15:53:58 +0100 | [diff] [blame] | 336 | DA9052_DCDC(BUCK3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO), |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 337 | DA9052_DCDC(BUCK4, 50, 1800, 3600, 5, 6, 0), |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 338 | DA9052_LDO(LDO1, 50, 600, 1800, 5, 6, 0), |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 339 | DA9052_LDO(LDO2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), |
| 340 | DA9052_LDO(LDO3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 341 | DA9052_LDO(LDO4, 25, 1725, 3300, 6, 6, 0), |
| 342 | DA9052_LDO(LDO5, 50, 1200, 3600, 6, 6, 0), |
| 343 | DA9052_LDO(LDO6, 50, 1200, 3600, 6, 6, 0), |
| 344 | DA9052_LDO(LDO7, 50, 1200, 3600, 6, 6, 0), |
| 345 | DA9052_LDO(LDO8, 50, 1200, 3600, 6, 6, 0), |
| 346 | DA9052_LDO(LDO9, 50, 1250, 3650, 6, 6, 0), |
| 347 | DA9052_LDO(LDO10, 50, 1200, 3600, 6, 6, 0), |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 348 | }; |
| 349 | |
Axel Lin | 6242eae | 2011-12-20 17:12:00 +0800 | [diff] [blame] | 350 | static struct da9052_regulator_info da9053_regulator_info[] = { |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 351 | DA9052_DCDC(BUCK1, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBCOREGO), |
| 352 | DA9052_DCDC(BUCK2, 25, 500, 2075, 6, 6, DA9052_SUPPLY_VBPROGO), |
Steve Twiss | 707319b | 2016-07-20 15:53:58 +0100 | [diff] [blame] | 353 | DA9052_DCDC(BUCK3, 25, 950, 2525, 6, 6, DA9052_SUPPLY_VBMEMGO), |
| 354 | DA9052_DCDC(BUCK4, 25, 950, 2525, 6, 6, 0), |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 355 | DA9052_LDO(LDO1, 50, 600, 1800, 5, 6, 0), |
Axel Lin | 0ec446e | 2012-03-15 20:00:07 +0800 | [diff] [blame] | 356 | DA9052_LDO(LDO2, 25, 600, 1800, 6, 6, DA9052_SUPPLY_VLDO2GO), |
| 357 | DA9052_LDO(LDO3, 25, 1725, 3300, 6, 6, DA9052_SUPPLY_VLDO3GO), |
Axel Lin | 9210f05 | 2012-03-15 19:58:39 +0800 | [diff] [blame] | 358 | DA9052_LDO(LDO4, 25, 1725, 3300, 6, 6, 0), |
| 359 | DA9052_LDO(LDO5, 50, 1200, 3600, 6, 6, 0), |
| 360 | DA9052_LDO(LDO6, 50, 1200, 3600, 6, 6, 0), |
| 361 | DA9052_LDO(LDO7, 50, 1200, 3600, 6, 6, 0), |
| 362 | DA9052_LDO(LDO8, 50, 1200, 3600, 6, 6, 0), |
| 363 | DA9052_LDO(LDO9, 50, 1250, 3650, 6, 6, 0), |
| 364 | DA9052_LDO(LDO10, 50, 1200, 3600, 6, 6, 0), |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 365 | }; |
| 366 | |
| 367 | static inline struct da9052_regulator_info *find_regulator_info(u8 chip_id, |
| 368 | int id) |
| 369 | { |
| 370 | struct da9052_regulator_info *info; |
| 371 | int i; |
| 372 | |
Ashish Jangam | 984b5a6 | 2011-12-15 18:59:53 +0530 | [diff] [blame] | 373 | switch (chip_id) { |
| 374 | case DA9052: |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 375 | for (i = 0; i < ARRAY_SIZE(da9052_regulator_info); i++) { |
| 376 | info = &da9052_regulator_info[i]; |
| 377 | if (info->reg_desc.id == id) |
| 378 | return info; |
| 379 | } |
Ashish Jangam | 984b5a6 | 2011-12-15 18:59:53 +0530 | [diff] [blame] | 380 | break; |
| 381 | case DA9053_AA: |
| 382 | case DA9053_BA: |
| 383 | case DA9053_BB: |
Steve Twiss | 8b70814 | 2015-10-16 09:55:54 +0100 | [diff] [blame] | 384 | case DA9053_BC: |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 385 | for (i = 0; i < ARRAY_SIZE(da9053_regulator_info); i++) { |
| 386 | info = &da9053_regulator_info[i]; |
| 387 | if (info->reg_desc.id == id) |
| 388 | return info; |
| 389 | } |
Ashish Jangam | 984b5a6 | 2011-12-15 18:59:53 +0530 | [diff] [blame] | 390 | break; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 391 | } |
| 392 | |
| 393 | return NULL; |
| 394 | } |
| 395 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 396 | static int da9052_regulator_probe(struct platform_device *pdev) |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 397 | { |
Johan Hovold | e0c2153 | 2015-05-15 16:27:40 +0200 | [diff] [blame] | 398 | const struct mfd_cell *cell = mfd_get_cell(pdev); |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 399 | struct regulator_config config = { }; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 400 | struct da9052_regulator *regulator; |
| 401 | struct da9052 *da9052; |
| 402 | struct da9052_pdata *pdata; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 403 | |
Ashish Jangam | 984b5a6 | 2011-12-15 18:59:53 +0530 | [diff] [blame] | 404 | regulator = devm_kzalloc(&pdev->dev, sizeof(struct da9052_regulator), |
| 405 | GFP_KERNEL); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 406 | if (!regulator) |
| 407 | return -ENOMEM; |
| 408 | |
| 409 | da9052 = dev_get_drvdata(pdev->dev.parent); |
Jingoo Han | dff91d0 | 2013-07-30 17:20:47 +0900 | [diff] [blame] | 410 | pdata = dev_get_platdata(da9052->dev); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 411 | regulator->da9052 = da9052; |
| 412 | |
| 413 | regulator->info = find_regulator_info(regulator->da9052->chip_id, |
Johan Hovold | e0c2153 | 2015-05-15 16:27:40 +0200 | [diff] [blame] | 414 | cell->id); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 415 | if (regulator->info == NULL) { |
| 416 | dev_err(&pdev->dev, "invalid regulator ID specified\n"); |
Axel Lin | 7eb6444 | 2012-04-05 12:08:58 +0800 | [diff] [blame] | 417 | return -EINVAL; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 418 | } |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 419 | |
| 420 | config.dev = &pdev->dev; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 421 | config.driver_data = regulator; |
Axel Lin | 0d481f7 | 2012-04-17 11:34:32 +0800 | [diff] [blame] | 422 | config.regmap = da9052->regmap; |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 423 | if (pdata && pdata->regulators) { |
Johan Hovold | e0c2153 | 2015-05-15 16:27:40 +0200 | [diff] [blame] | 424 | config.init_data = pdata->regulators[cell->id]; |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 425 | } else { |
| 426 | #ifdef CONFIG_OF |
Guodong Xu | b8b27a4 | 2014-09-10 11:50:39 +0800 | [diff] [blame] | 427 | struct device_node *nproot = da9052->dev->of_node; |
| 428 | struct device_node *np; |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 429 | |
| 430 | if (!nproot) |
| 431 | return -ENODEV; |
| 432 | |
Sachin Kamat | b327bcc | 2014-02-14 17:19:56 +0530 | [diff] [blame] | 433 | nproot = of_get_child_by_name(nproot, "regulators"); |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 434 | if (!nproot) |
| 435 | return -ENODEV; |
| 436 | |
Axel Lin | b86bbdd | 2012-07-07 09:46:45 +0800 | [diff] [blame] | 437 | for_each_child_of_node(nproot, np) { |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 438 | if (!of_node_cmp(np->name, |
| 439 | regulator->info->reg_desc.name)) { |
| 440 | config.init_data = of_get_regulator_init_data( |
Javier Martinez Canillas | 072e78b | 2014-11-10 14:43:53 +0100 | [diff] [blame] | 441 | &pdev->dev, np, |
| 442 | ®ulator->info->reg_desc); |
Axel Lin | e76b9cc | 2012-07-12 22:23:25 +0800 | [diff] [blame] | 443 | config.of_node = np; |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 444 | break; |
| 445 | } |
| 446 | } |
Axel Lin | c92f5dd | 2013-01-27 21:16:56 +0800 | [diff] [blame] | 447 | of_node_put(nproot); |
Ying-Chun Liu (PaulLiu) | 88c84c1 | 2012-04-13 21:37:41 +0800 | [diff] [blame] | 448 | #endif |
| 449 | } |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 450 | |
Axel Lin | ea49a5e | 2013-09-03 14:24:46 +0800 | [diff] [blame] | 451 | regulator->rdev = devm_regulator_register(&pdev->dev, |
| 452 | ®ulator->info->reg_desc, |
| 453 | &config); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 454 | if (IS_ERR(regulator->rdev)) { |
| 455 | dev_err(&pdev->dev, "failed to register regulator %s\n", |
| 456 | regulator->info->reg_desc.name); |
Axel Lin | 7eb6444 | 2012-04-05 12:08:58 +0800 | [diff] [blame] | 457 | return PTR_ERR(regulator->rdev); |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 458 | } |
| 459 | |
| 460 | platform_set_drvdata(pdev, regulator); |
| 461 | |
| 462 | return 0; |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 463 | } |
| 464 | |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 465 | static struct platform_driver da9052_regulator_driver = { |
| 466 | .probe = da9052_regulator_probe, |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 467 | .driver = { |
| 468 | .name = "da9052-regulator", |
Ashish Jangam | 08bf1c0 | 2011-12-09 19:48:20 +0530 | [diff] [blame] | 469 | }, |
| 470 | }; |
| 471 | |
| 472 | static int __init da9052_regulator_init(void) |
| 473 | { |
| 474 | return platform_driver_register(&da9052_regulator_driver); |
| 475 | } |
| 476 | subsys_initcall(da9052_regulator_init); |
| 477 | |
| 478 | static void __exit da9052_regulator_exit(void) |
| 479 | { |
| 480 | platform_driver_unregister(&da9052_regulator_driver); |
| 481 | } |
| 482 | module_exit(da9052_regulator_exit); |
| 483 | |
| 484 | MODULE_AUTHOR("David Dajun Chen <dchen@diasemi.com>"); |
| 485 | MODULE_DESCRIPTION("Power Regulator driver for Dialog DA9052 PMIC"); |
| 486 | MODULE_LICENSE("GPL"); |
| 487 | MODULE_ALIAS("platform:da9052-regulator"); |