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