Krzysztof Kozlowski | 5e9384c | 2018-08-07 18:18:25 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | // |
| 3 | // max77802.c - Regulator driver for the Maxim 77802 |
| 4 | // |
| 5 | // Copyright (C) 2013-2014 Google, Inc |
| 6 | // Simon Glass <sjg@chromium.org> |
| 7 | // |
| 8 | // Copyright (C) 2012 Samsung Electronics |
| 9 | // Chiwoong Byun <woong.byun@samsung.com> |
| 10 | // Jonghwa Lee <jonghwa3.lee@samsung.com> |
| 11 | // |
| 12 | // This driver is based on max8997.c |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 13 | |
| 14 | #include <linux/kernel.h> |
| 15 | #include <linux/bug.h> |
| 16 | #include <linux/err.h> |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 17 | #include <linux/slab.h> |
Paul Gortmaker | ca1c8e9 | 2015-05-01 20:02:31 -0400 | [diff] [blame] | 18 | #include <linux/module.h> |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/regulator/driver.h> |
| 21 | #include <linux/regulator/machine.h> |
| 22 | #include <linux/regulator/of_regulator.h> |
| 23 | #include <linux/mfd/max77686.h> |
| 24 | #include <linux/mfd/max77686-private.h> |
Javier Martinez Canillas | 5356e0d | 2014-10-16 18:48:50 +0200 | [diff] [blame] | 25 | #include <dt-bindings/regulator/maxim,max77802.h> |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 26 | |
| 27 | /* Default ramp delay in case it is not manually set */ |
| 28 | #define MAX77802_RAMP_DELAY 100000 /* uV/us */ |
| 29 | |
| 30 | #define MAX77802_OPMODE_SHIFT_LDO 6 |
| 31 | #define MAX77802_OPMODE_BUCK234_SHIFT 4 |
| 32 | #define MAX77802_OPMODE_MASK 0x3 |
| 33 | |
| 34 | #define MAX77802_VSEL_MASK 0x3F |
| 35 | #define MAX77802_DVS_VSEL_MASK 0xFF |
| 36 | |
| 37 | #define MAX77802_RAMP_RATE_MASK_2BIT 0xC0 |
| 38 | #define MAX77802_RAMP_RATE_SHIFT_2BIT 6 |
| 39 | #define MAX77802_RAMP_RATE_MASK_4BIT 0xF0 |
| 40 | #define MAX77802_RAMP_RATE_SHIFT_4BIT 4 |
| 41 | |
Javier Martinez Canillas | 0505be7 | 2014-10-16 18:48:49 +0200 | [diff] [blame] | 42 | #define MAX77802_STATUS_OFF 0x0 |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 43 | #define MAX77802_OFF_PWRREQ 0x1 |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 44 | #define MAX77802_LP_PWRREQ 0x2 |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 45 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 46 | /* MAX77802 has two register formats: 2-bit and 4-bit */ |
| 47 | static const unsigned int ramp_table_77802_2bit[] = { |
| 48 | 12500, |
| 49 | 25000, |
| 50 | 50000, |
| 51 | 100000, |
| 52 | }; |
| 53 | |
| 54 | static unsigned int ramp_table_77802_4bit[] = { |
| 55 | 1000, 2000, 3030, 4000, |
| 56 | 5000, 5880, 7140, 8330, |
| 57 | 9090, 10000, 11110, 12500, |
| 58 | 16670, 25000, 50000, 100000, |
| 59 | }; |
| 60 | |
| 61 | struct max77802_regulator_prv { |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 62 | /* Array indexed by regulator id */ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 63 | unsigned int opmode[MAX77802_REG_MAX]; |
| 64 | }; |
| 65 | |
Javier Martinez Canillas | 4d7078e6 | 2014-11-03 15:40:47 +0100 | [diff] [blame] | 66 | static inline unsigned int max77802_map_mode(unsigned int mode) |
Javier Martinez Canillas | efbe519 | 2014-10-16 18:48:47 +0200 | [diff] [blame] | 67 | { |
| 68 | return mode == MAX77802_OPMODE_NORMAL ? |
| 69 | REGULATOR_MODE_NORMAL : REGULATOR_MODE_STANDBY; |
| 70 | } |
| 71 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 72 | static int max77802_get_opmode_shift(int id) |
| 73 | { |
| 74 | if (id == MAX77802_BUCK1 || (id >= MAX77802_BUCK5 && |
| 75 | id <= MAX77802_BUCK10)) |
| 76 | return 0; |
| 77 | |
| 78 | if (id >= MAX77802_BUCK2 && id <= MAX77802_BUCK4) |
| 79 | return MAX77802_OPMODE_BUCK234_SHIFT; |
| 80 | |
| 81 | if (id >= MAX77802_LDO1 && id <= MAX77802_LDO35) |
| 82 | return MAX77802_OPMODE_SHIFT_LDO; |
| 83 | |
| 84 | return -EINVAL; |
| 85 | } |
| 86 | |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 87 | /** |
| 88 | * max77802_set_suspend_disable - Disable the regulator during system suspend |
| 89 | * @rdev: regulator to mark as disabled |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 90 | * |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 91 | * All regulators expect LDO 1, 3, 20 and 21 support OFF by PWRREQ. |
| 92 | * Configure the regulator so the PMIC will turn it OFF during system suspend. |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 93 | */ |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 94 | static int max77802_set_suspend_disable(struct regulator_dev *rdev) |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 95 | { |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 96 | unsigned int val = MAX77802_OFF_PWRREQ; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 97 | struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); |
| 98 | int id = rdev_get_id(rdev); |
| 99 | int shift = max77802_get_opmode_shift(id); |
| 100 | |
| 101 | max77802->opmode[id] = val; |
| 102 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 103 | rdev->desc->enable_mask, val << shift); |
| 104 | } |
| 105 | |
| 106 | /* |
Javier Martinez Canillas | efbe519 | 2014-10-16 18:48:47 +0200 | [diff] [blame] | 107 | * Some LDOs support Low Power Mode while the system is running. |
| 108 | * |
| 109 | * LDOs 1, 3, 20, 21. |
| 110 | */ |
| 111 | static int max77802_set_mode(struct regulator_dev *rdev, unsigned int mode) |
| 112 | { |
| 113 | struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); |
| 114 | int id = rdev_get_id(rdev); |
| 115 | unsigned int val; |
| 116 | int shift = max77802_get_opmode_shift(id); |
| 117 | |
| 118 | switch (mode) { |
| 119 | case REGULATOR_MODE_STANDBY: |
| 120 | val = MAX77802_OPMODE_LP; /* ON in Low Power Mode */ |
| 121 | break; |
| 122 | case REGULATOR_MODE_NORMAL: |
| 123 | val = MAX77802_OPMODE_NORMAL; /* ON in Normal Mode */ |
| 124 | break; |
| 125 | default: |
| 126 | dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", |
| 127 | rdev->desc->name, mode); |
| 128 | return -EINVAL; |
| 129 | } |
| 130 | |
| 131 | max77802->opmode[id] = val; |
| 132 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 133 | rdev->desc->enable_mask, val << shift); |
| 134 | } |
| 135 | |
| 136 | static unsigned max77802_get_mode(struct regulator_dev *rdev) |
| 137 | { |
| 138 | struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); |
| 139 | int id = rdev_get_id(rdev); |
| 140 | |
| 141 | return max77802_map_mode(max77802->opmode[id]); |
| 142 | } |
| 143 | |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 144 | /** |
| 145 | * max77802_set_suspend_mode - set regulator opmode when the system is suspended |
| 146 | * @rdev: regulator to change mode |
| 147 | * @mode: operating mode to be set |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 148 | * |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 149 | * Will set the operating mode for the regulators during system suspend. |
| 150 | * This function is valid for the three different enable control logics: |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 151 | * |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 152 | * Enable Control Logic1 by PWRREQ (BUCK 2-4 and LDOs 2, 4-19, 22-35) |
| 153 | * Enable Control Logic2 by PWRREQ (LDOs 1, 20, 21) |
| 154 | * Enable Control Logic3 by PWRREQ (LDO 3) |
| 155 | * |
| 156 | * If setting the regulator mode fails, the function only warns but does |
| 157 | * not return an error code to avoid the regulator core to stop setting |
| 158 | * the operating mode for the remaining regulators. |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 159 | */ |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 160 | static int max77802_set_suspend_mode(struct regulator_dev *rdev, |
| 161 | unsigned int mode) |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 162 | { |
| 163 | struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); |
| 164 | int id = rdev_get_id(rdev); |
| 165 | unsigned int val; |
| 166 | int shift = max77802_get_opmode_shift(id); |
| 167 | |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 168 | /* |
| 169 | * If the regulator has been disabled for suspend |
| 170 | * then is invalid to try setting a suspend mode. |
| 171 | */ |
Dan Carpenter | bf27537 | 2014-10-27 13:45:06 +0300 | [diff] [blame] | 172 | if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) { |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 173 | dev_warn(&rdev->dev, "%s: is disabled, mode: 0x%x not set\n", |
| 174 | rdev->desc->name, mode); |
| 175 | return 0; |
| 176 | } |
| 177 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 178 | switch (mode) { |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 179 | case REGULATOR_MODE_STANDBY: |
| 180 | /* |
| 181 | * If the regulator opmode is normal then enable |
| 182 | * ON in Low Power Mode by PWRREQ. If the mode is |
| 183 | * already Low Power then no action is required. |
| 184 | */ |
| 185 | if (max77802->opmode[id] == MAX77802_OPMODE_NORMAL) |
| 186 | val = MAX77802_LP_PWRREQ; |
| 187 | else |
| 188 | return 0; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 189 | break; |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 190 | case REGULATOR_MODE_NORMAL: |
| 191 | /* |
| 192 | * If the regulator operating mode is Low Power then |
| 193 | * normal is not a valid opmode in suspend. If the |
| 194 | * mode is already normal then no action is required. |
| 195 | */ |
| 196 | if (max77802->opmode[id] == MAX77802_OPMODE_LP) |
| 197 | dev_warn(&rdev->dev, "%s: in Low Power: 0x%x invalid\n", |
| 198 | rdev->desc->name, mode); |
| 199 | return 0; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 200 | default: |
| 201 | dev_warn(&rdev->dev, "%s: regulator mode: 0x%x not supported\n", |
| 202 | rdev->desc->name, mode); |
| 203 | return -EINVAL; |
| 204 | } |
| 205 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 206 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 207 | rdev->desc->enable_mask, val << shift); |
| 208 | } |
| 209 | |
| 210 | static int max77802_enable(struct regulator_dev *rdev) |
| 211 | { |
| 212 | struct max77802_regulator_prv *max77802 = rdev_get_drvdata(rdev); |
| 213 | int id = rdev_get_id(rdev); |
| 214 | int shift = max77802_get_opmode_shift(id); |
| 215 | |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 216 | if (max77802->opmode[id] == MAX77802_OFF_PWRREQ) |
| 217 | max77802->opmode[id] = MAX77802_OPMODE_NORMAL; |
| 218 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 219 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 220 | rdev->desc->enable_mask, |
| 221 | max77802->opmode[id] << shift); |
| 222 | } |
| 223 | |
| 224 | static int max77802_find_ramp_value(struct regulator_dev *rdev, |
| 225 | const unsigned int limits[], int size, |
| 226 | unsigned int ramp_delay) |
| 227 | { |
| 228 | int i; |
| 229 | |
| 230 | for (i = 0; i < size; i++) { |
| 231 | if (ramp_delay <= limits[i]) |
| 232 | return i; |
| 233 | } |
| 234 | |
| 235 | /* Use maximum value for no ramp control */ |
| 236 | dev_warn(&rdev->dev, "%s: ramp_delay: %d not supported, setting 100000\n", |
| 237 | rdev->desc->name, ramp_delay); |
| 238 | return size - 1; |
| 239 | } |
| 240 | |
| 241 | /* Used for BUCKs 2-4 */ |
| 242 | static int max77802_set_ramp_delay_2bit(struct regulator_dev *rdev, |
| 243 | int ramp_delay) |
| 244 | { |
| 245 | int id = rdev_get_id(rdev); |
| 246 | unsigned int ramp_value; |
| 247 | |
| 248 | if (id > MAX77802_BUCK4) { |
Colin Ian King | c79fba8 | 2019-02-12 13:46:16 +0000 | [diff] [blame] | 249 | dev_warn(&rdev->dev, |
| 250 | "%s: regulator: ramp delay not supported\n", |
| 251 | rdev->desc->name); |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 252 | return -EINVAL; |
| 253 | } |
| 254 | ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_2bit, |
| 255 | ARRAY_SIZE(ramp_table_77802_2bit), ramp_delay); |
| 256 | |
| 257 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 258 | MAX77802_RAMP_RATE_MASK_2BIT, |
| 259 | ramp_value << MAX77802_RAMP_RATE_SHIFT_2BIT); |
| 260 | } |
| 261 | |
| 262 | /* For BUCK1, 6 */ |
| 263 | static int max77802_set_ramp_delay_4bit(struct regulator_dev *rdev, |
| 264 | int ramp_delay) |
| 265 | { |
| 266 | unsigned int ramp_value; |
| 267 | |
| 268 | ramp_value = max77802_find_ramp_value(rdev, ramp_table_77802_4bit, |
| 269 | ARRAY_SIZE(ramp_table_77802_4bit), ramp_delay); |
| 270 | |
| 271 | return regmap_update_bits(rdev->regmap, rdev->desc->enable_reg, |
| 272 | MAX77802_RAMP_RATE_MASK_4BIT, |
| 273 | ramp_value << MAX77802_RAMP_RATE_SHIFT_4BIT); |
| 274 | } |
| 275 | |
| 276 | /* |
| 277 | * LDOs 2, 4-19, 22-35 |
| 278 | */ |
Bhumika Goyal | 0301987 | 2017-01-28 19:55:54 +0530 | [diff] [blame] | 279 | static const struct regulator_ops max77802_ldo_ops_logic1 = { |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 280 | .list_voltage = regulator_list_voltage_linear, |
| 281 | .map_voltage = regulator_map_voltage_linear, |
| 282 | .is_enabled = regulator_is_enabled_regmap, |
| 283 | .enable = max77802_enable, |
| 284 | .disable = regulator_disable_regmap, |
| 285 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 286 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 287 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 288 | .set_suspend_disable = max77802_set_suspend_disable, |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 289 | .set_suspend_mode = max77802_set_suspend_mode, |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 290 | }; |
| 291 | |
| 292 | /* |
| 293 | * LDOs 1, 20, 21, 3 |
| 294 | */ |
Bhumika Goyal | 0301987 | 2017-01-28 19:55:54 +0530 | [diff] [blame] | 295 | static const struct regulator_ops max77802_ldo_ops_logic2 = { |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 296 | .list_voltage = regulator_list_voltage_linear, |
| 297 | .map_voltage = regulator_map_voltage_linear, |
| 298 | .is_enabled = regulator_is_enabled_regmap, |
| 299 | .enable = max77802_enable, |
| 300 | .disable = regulator_disable_regmap, |
| 301 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 302 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 303 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Javier Martinez Canillas | efbe519 | 2014-10-16 18:48:47 +0200 | [diff] [blame] | 304 | .set_mode = max77802_set_mode, |
| 305 | .get_mode = max77802_get_mode, |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 306 | .set_suspend_mode = max77802_set_suspend_mode, |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 307 | }; |
| 308 | |
| 309 | /* BUCKS 1, 6 */ |
Bhumika Goyal | 0301987 | 2017-01-28 19:55:54 +0530 | [diff] [blame] | 310 | static const struct regulator_ops max77802_buck_16_dvs_ops = { |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 311 | .list_voltage = regulator_list_voltage_linear, |
| 312 | .map_voltage = regulator_map_voltage_linear, |
| 313 | .is_enabled = regulator_is_enabled_regmap, |
| 314 | .enable = max77802_enable, |
| 315 | .disable = regulator_disable_regmap, |
| 316 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 317 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 318 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 319 | .set_ramp_delay = max77802_set_ramp_delay_4bit, |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 320 | .set_suspend_disable = max77802_set_suspend_disable, |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 321 | }; |
| 322 | |
Javier Martinez Canillas | b0615f1 | 2014-10-15 18:20:33 +0200 | [diff] [blame] | 323 | /* BUCKs 2-4 */ |
Bhumika Goyal | 0301987 | 2017-01-28 19:55:54 +0530 | [diff] [blame] | 324 | static const struct regulator_ops max77802_buck_234_ops = { |
Javier Martinez Canillas | b0615f1 | 2014-10-15 18:20:33 +0200 | [diff] [blame] | 325 | .list_voltage = regulator_list_voltage_linear, |
| 326 | .map_voltage = regulator_map_voltage_linear, |
| 327 | .is_enabled = regulator_is_enabled_regmap, |
| 328 | .enable = max77802_enable, |
| 329 | .disable = regulator_disable_regmap, |
| 330 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 331 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 332 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 333 | .set_ramp_delay = max77802_set_ramp_delay_2bit, |
Javier Martinez Canillas | b0615f1 | 2014-10-15 18:20:33 +0200 | [diff] [blame] | 334 | .set_suspend_disable = max77802_set_suspend_disable, |
Javier Martinez Canillas | 2e0eaa1 | 2014-10-16 18:48:48 +0200 | [diff] [blame] | 335 | .set_suspend_mode = max77802_set_suspend_mode, |
Javier Martinez Canillas | b0615f1 | 2014-10-15 18:20:33 +0200 | [diff] [blame] | 336 | }; |
| 337 | |
| 338 | /* BUCKs 5, 7-10 */ |
Bhumika Goyal | 0301987 | 2017-01-28 19:55:54 +0530 | [diff] [blame] | 339 | static const struct regulator_ops max77802_buck_dvs_ops = { |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 340 | .list_voltage = regulator_list_voltage_linear, |
| 341 | .map_voltage = regulator_map_voltage_linear, |
| 342 | .is_enabled = regulator_is_enabled_regmap, |
| 343 | .enable = max77802_enable, |
| 344 | .disable = regulator_disable_regmap, |
| 345 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 346 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 347 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 348 | .set_ramp_delay = max77802_set_ramp_delay_2bit, |
Javier Martinez Canillas | e6fb2aa | 2014-10-15 18:20:31 +0200 | [diff] [blame] | 349 | .set_suspend_disable = max77802_set_suspend_disable, |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 350 | }; |
| 351 | |
| 352 | /* LDOs 3-7, 9-14, 18-26, 28, 29, 32-34 */ |
| 353 | #define regulator_77802_desc_p_ldo(num, supply, log) { \ |
| 354 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 355 | .of_match = of_match_ptr("LDO"#num), \ |
| 356 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 357 | .id = MAX77802_LDO##num, \ |
| 358 | .supply_name = "inl"#supply, \ |
| 359 | .ops = &max77802_ldo_ops_logic##log, \ |
| 360 | .type = REGULATOR_VOLTAGE, \ |
| 361 | .owner = THIS_MODULE, \ |
| 362 | .min_uV = 800000, \ |
| 363 | .uV_step = 50000, \ |
| 364 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 365 | .n_voltages = 1 << 6, \ |
| 366 | .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ |
| 367 | .vsel_mask = MAX77802_VSEL_MASK, \ |
| 368 | .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ |
| 369 | .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 370 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | /* LDOs 1, 2, 8, 15, 17, 27, 30, 35 */ |
| 374 | #define regulator_77802_desc_n_ldo(num, supply, log) { \ |
| 375 | .name = "LDO"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 376 | .of_match = of_match_ptr("LDO"#num), \ |
| 377 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 378 | .id = MAX77802_LDO##num, \ |
| 379 | .supply_name = "inl"#supply, \ |
| 380 | .ops = &max77802_ldo_ops_logic##log, \ |
| 381 | .type = REGULATOR_VOLTAGE, \ |
| 382 | .owner = THIS_MODULE, \ |
| 383 | .min_uV = 800000, \ |
| 384 | .uV_step = 25000, \ |
| 385 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 386 | .n_voltages = 1 << 6, \ |
| 387 | .vsel_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ |
| 388 | .vsel_mask = MAX77802_VSEL_MASK, \ |
| 389 | .enable_reg = MAX77802_REG_LDO1CTRL1 + num - 1, \ |
| 390 | .enable_mask = MAX77802_OPMODE_MASK << MAX77802_OPMODE_SHIFT_LDO, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 391 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 392 | } |
| 393 | |
| 394 | /* BUCKs 1, 6 */ |
| 395 | #define regulator_77802_desc_16_buck(num) { \ |
| 396 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 397 | .of_match = of_match_ptr("BUCK"#num), \ |
| 398 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 399 | .id = MAX77802_BUCK##num, \ |
| 400 | .supply_name = "inb"#num, \ |
| 401 | .ops = &max77802_buck_16_dvs_ops, \ |
| 402 | .type = REGULATOR_VOLTAGE, \ |
| 403 | .owner = THIS_MODULE, \ |
| 404 | .min_uV = 612500, \ |
| 405 | .uV_step = 6250, \ |
| 406 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 407 | .n_voltages = 1 << 8, \ |
| 408 | .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \ |
| 409 | .vsel_mask = MAX77802_DVS_VSEL_MASK, \ |
| 410 | .enable_reg = MAX77802_REG_BUCK ## num ## CTRL, \ |
| 411 | .enable_mask = MAX77802_OPMODE_MASK, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 412 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | /* BUCKS 2-4 */ |
| 416 | #define regulator_77802_desc_234_buck(num) { \ |
| 417 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 418 | .of_match = of_match_ptr("BUCK"#num), \ |
| 419 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 420 | .id = MAX77802_BUCK##num, \ |
| 421 | .supply_name = "inb"#num, \ |
Javier Martinez Canillas | b0615f1 | 2014-10-15 18:20:33 +0200 | [diff] [blame] | 422 | .ops = &max77802_buck_234_ops, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 423 | .type = REGULATOR_VOLTAGE, \ |
| 424 | .owner = THIS_MODULE, \ |
| 425 | .min_uV = 600000, \ |
| 426 | .uV_step = 6250, \ |
| 427 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 428 | .n_voltages = 0x91, \ |
| 429 | .vsel_reg = MAX77802_REG_BUCK ## num ## DVS1, \ |
| 430 | .vsel_mask = MAX77802_DVS_VSEL_MASK, \ |
| 431 | .enable_reg = MAX77802_REG_BUCK ## num ## CTRL1, \ |
| 432 | .enable_mask = MAX77802_OPMODE_MASK << \ |
| 433 | MAX77802_OPMODE_BUCK234_SHIFT, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 434 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* BUCK 5 */ |
| 438 | #define regulator_77802_desc_buck5(num) { \ |
| 439 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 440 | .of_match = of_match_ptr("BUCK"#num), \ |
| 441 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 442 | .id = MAX77802_BUCK##num, \ |
| 443 | .supply_name = "inb"#num, \ |
| 444 | .ops = &max77802_buck_dvs_ops, \ |
| 445 | .type = REGULATOR_VOLTAGE, \ |
| 446 | .owner = THIS_MODULE, \ |
| 447 | .min_uV = 750000, \ |
| 448 | .uV_step = 50000, \ |
| 449 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 450 | .n_voltages = 1 << 6, \ |
| 451 | .vsel_reg = MAX77802_REG_BUCK5OUT, \ |
| 452 | .vsel_mask = MAX77802_VSEL_MASK, \ |
| 453 | .enable_reg = MAX77802_REG_BUCK5CTRL, \ |
| 454 | .enable_mask = MAX77802_OPMODE_MASK, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 455 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | /* BUCKs 7-10 */ |
| 459 | #define regulator_77802_desc_buck7_10(num) { \ |
| 460 | .name = "BUCK"#num, \ |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 461 | .of_match = of_match_ptr("BUCK"#num), \ |
| 462 | .regulators_node = of_match_ptr("regulators"), \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 463 | .id = MAX77802_BUCK##num, \ |
| 464 | .supply_name = "inb"#num, \ |
| 465 | .ops = &max77802_buck_dvs_ops, \ |
| 466 | .type = REGULATOR_VOLTAGE, \ |
| 467 | .owner = THIS_MODULE, \ |
| 468 | .min_uV = 750000, \ |
| 469 | .uV_step = 50000, \ |
| 470 | .ramp_delay = MAX77802_RAMP_DELAY, \ |
| 471 | .n_voltages = 1 << 6, \ |
| 472 | .vsel_reg = MAX77802_REG_BUCK7OUT + (num - 7) * 3, \ |
| 473 | .vsel_mask = MAX77802_VSEL_MASK, \ |
| 474 | .enable_reg = MAX77802_REG_BUCK7CTRL + (num - 7) * 3, \ |
| 475 | .enable_mask = MAX77802_OPMODE_MASK, \ |
Javier Martinez Canillas | 45fc84c | 2014-11-11 13:04:44 +0100 | [diff] [blame] | 476 | .of_map_mode = max77802_map_mode, \ |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 477 | } |
| 478 | |
Krzysztof Kozlowski | 6c4159a | 2014-10-27 16:44:13 +0100 | [diff] [blame] | 479 | static const struct regulator_desc regulators[] = { |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 480 | regulator_77802_desc_16_buck(1), |
| 481 | regulator_77802_desc_234_buck(2), |
| 482 | regulator_77802_desc_234_buck(3), |
| 483 | regulator_77802_desc_234_buck(4), |
| 484 | regulator_77802_desc_buck5(5), |
| 485 | regulator_77802_desc_16_buck(6), |
| 486 | regulator_77802_desc_buck7_10(7), |
| 487 | regulator_77802_desc_buck7_10(8), |
| 488 | regulator_77802_desc_buck7_10(9), |
| 489 | regulator_77802_desc_buck7_10(10), |
| 490 | regulator_77802_desc_n_ldo(1, 10, 2), |
| 491 | regulator_77802_desc_n_ldo(2, 10, 1), |
| 492 | regulator_77802_desc_p_ldo(3, 3, 2), |
| 493 | regulator_77802_desc_p_ldo(4, 6, 1), |
| 494 | regulator_77802_desc_p_ldo(5, 3, 1), |
| 495 | regulator_77802_desc_p_ldo(6, 3, 1), |
| 496 | regulator_77802_desc_p_ldo(7, 3, 1), |
| 497 | regulator_77802_desc_n_ldo(8, 1, 1), |
| 498 | regulator_77802_desc_p_ldo(9, 5, 1), |
| 499 | regulator_77802_desc_p_ldo(10, 4, 1), |
| 500 | regulator_77802_desc_p_ldo(11, 4, 1), |
| 501 | regulator_77802_desc_p_ldo(12, 9, 1), |
| 502 | regulator_77802_desc_p_ldo(13, 4, 1), |
| 503 | regulator_77802_desc_p_ldo(14, 4, 1), |
| 504 | regulator_77802_desc_n_ldo(15, 1, 1), |
| 505 | regulator_77802_desc_n_ldo(17, 2, 1), |
| 506 | regulator_77802_desc_p_ldo(18, 7, 1), |
| 507 | regulator_77802_desc_p_ldo(19, 5, 1), |
| 508 | regulator_77802_desc_p_ldo(20, 7, 2), |
| 509 | regulator_77802_desc_p_ldo(21, 6, 2), |
| 510 | regulator_77802_desc_p_ldo(23, 9, 1), |
| 511 | regulator_77802_desc_p_ldo(24, 6, 1), |
| 512 | regulator_77802_desc_p_ldo(25, 9, 1), |
| 513 | regulator_77802_desc_p_ldo(26, 9, 1), |
| 514 | regulator_77802_desc_n_ldo(27, 2, 1), |
| 515 | regulator_77802_desc_p_ldo(28, 7, 1), |
| 516 | regulator_77802_desc_p_ldo(29, 7, 1), |
| 517 | regulator_77802_desc_n_ldo(30, 2, 1), |
| 518 | regulator_77802_desc_p_ldo(32, 9, 1), |
| 519 | regulator_77802_desc_p_ldo(33, 6, 1), |
| 520 | regulator_77802_desc_p_ldo(34, 9, 1), |
| 521 | regulator_77802_desc_n_ldo(35, 2, 1), |
| 522 | }; |
| 523 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 524 | static int max77802_pmic_probe(struct platform_device *pdev) |
| 525 | { |
| 526 | struct max77686_dev *iodev = dev_get_drvdata(pdev->dev.parent); |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 527 | struct max77802_regulator_prv *max77802; |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 528 | int i, val; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 529 | struct regulator_config config = { }; |
| 530 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 531 | max77802 = devm_kzalloc(&pdev->dev, |
| 532 | sizeof(struct max77802_regulator_prv), |
| 533 | GFP_KERNEL); |
| 534 | if (!max77802) |
| 535 | return -ENOMEM; |
| 536 | |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 537 | config.dev = iodev->dev; |
| 538 | config.regmap = iodev->regmap; |
| 539 | config.driver_data = max77802; |
| 540 | platform_set_drvdata(pdev, max77802); |
| 541 | |
| 542 | for (i = 0; i < MAX77802_REG_MAX; i++) { |
| 543 | struct regulator_dev *rdev; |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 544 | int id = regulators[i].id; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 545 | int shift = max77802_get_opmode_shift(id); |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 546 | int ret; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 547 | |
| 548 | ret = regmap_read(iodev->regmap, regulators[i].enable_reg, &val); |
Krzysztof Kozlowski | a26ed45 | 2014-11-04 09:49:43 +0100 | [diff] [blame] | 549 | if (ret < 0) { |
| 550 | dev_warn(&pdev->dev, |
| 551 | "cannot read current mode for %d\n", i); |
| 552 | val = MAX77802_OPMODE_NORMAL; |
| 553 | } else { |
| 554 | val = val >> shift & MAX77802_OPMODE_MASK; |
| 555 | } |
Javier Martinez Canillas | aea8dfb | 2014-08-26 13:37:41 +0200 | [diff] [blame] | 556 | |
| 557 | /* |
| 558 | * If the regulator is disabled and the system warm rebooted, |
| 559 | * the hardware reports OFF as the regulator operating mode. |
| 560 | * Default to operating mode NORMAL in that case. |
| 561 | */ |
Javier Martinez Canillas | 0505be7 | 2014-10-16 18:48:49 +0200 | [diff] [blame] | 562 | if (val == MAX77802_STATUS_OFF) |
Javier Martinez Canillas | aea8dfb | 2014-08-26 13:37:41 +0200 | [diff] [blame] | 563 | max77802->opmode[id] = MAX77802_OPMODE_NORMAL; |
| 564 | else |
| 565 | max77802->opmode[id] = val; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 566 | |
| 567 | rdev = devm_regulator_register(&pdev->dev, |
| 568 | ®ulators[i], &config); |
| 569 | if (IS_ERR(rdev)) { |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 570 | ret = PTR_ERR(rdev); |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 571 | dev_err(&pdev->dev, |
Krzysztof Kozlowski | ff633be | 2014-11-05 10:47:49 +0100 | [diff] [blame] | 572 | "regulator init failed for %d: %d\n", i, ret); |
| 573 | return ret; |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | |
| 577 | return 0; |
| 578 | } |
| 579 | |
| 580 | static const struct platform_device_id max77802_pmic_id[] = { |
| 581 | {"max77802-pmic", 0}, |
| 582 | { }, |
| 583 | }; |
| 584 | MODULE_DEVICE_TABLE(platform, max77802_pmic_id); |
| 585 | |
| 586 | static struct platform_driver max77802_pmic_driver = { |
| 587 | .driver = { |
| 588 | .name = "max77802-pmic", |
Javier Martinez Canillas | e6f2f80 | 2014-08-18 10:32:41 +0200 | [diff] [blame] | 589 | }, |
| 590 | .probe = max77802_pmic_probe, |
| 591 | .id_table = max77802_pmic_id, |
| 592 | }; |
| 593 | |
| 594 | module_platform_driver(max77802_pmic_driver); |
| 595 | |
| 596 | MODULE_DESCRIPTION("MAXIM 77802 Regulator Driver"); |
| 597 | MODULE_AUTHOR("Simon Glass <sjg@chromium.org>"); |
| 598 | MODULE_LICENSE("GPL"); |