Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 1 | /* |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 2 | * Regulator driver for Rockchip RK808/RK818 |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 3 | * |
| 4 | * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd |
| 5 | * |
| 6 | * Author: Chris Zhong <zyw@rock-chips.com> |
| 7 | * Author: Zhang Qing <zhangqing@rock-chips.com> |
| 8 | * |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 9 | * Copyright (C) 2016 PHYTEC Messtechnik GmbH |
| 10 | * |
| 11 | * Author: Wadim Egorov <w.egorov@phytec.de> |
| 12 | * |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify it |
| 14 | * under the terms and conditions of the GNU General Public License, |
| 15 | * version 2, as published by the Free Software Foundation. |
| 16 | * |
| 17 | * This program is distributed in the hope it will be useful, but WITHOUT |
| 18 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 19 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 20 | * more details. |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 21 | */ |
| 22 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 23 | #include <linux/delay.h> |
| 24 | #include <linux/gpio.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 25 | #include <linux/i2c.h> |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 26 | #include <linux/module.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 27 | #include <linux/of_device.h> |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 28 | #include <linux/of_gpio.h> |
| 29 | #include <linux/mfd/rk808.h> |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 30 | #include <linux/regulator/driver.h> |
| 31 | #include <linux/regulator/of_regulator.h> |
Uwe Kleine-König | 604d499 | 2015-07-21 16:46:24 +0200 | [diff] [blame] | 32 | #include <linux/gpio/consumer.h> |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 33 | |
| 34 | /* Field Definitions */ |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 35 | #define RK808_BUCK_VSEL_MASK 0x3f |
| 36 | #define RK808_BUCK4_VSEL_MASK 0xf |
| 37 | #define RK808_LDO_VSEL_MASK 0x1f |
| 38 | |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 39 | #define RK818_BUCK_VSEL_MASK 0x3f |
| 40 | #define RK818_BUCK4_VSEL_MASK 0x1f |
| 41 | #define RK818_LDO_VSEL_MASK 0x1f |
| 42 | #define RK818_LDO3_ON_VSEL_MASK 0xf |
| 43 | #define RK818_BOOST_ON_VSEL_MASK 0xe0 |
| 44 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 45 | /* Ramp rate definitions for buck1 / buck2 only */ |
| 46 | #define RK808_RAMP_RATE_OFFSET 3 |
| 47 | #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET) |
| 48 | #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET) |
| 49 | #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET) |
| 50 | #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) |
| 51 | #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) |
| 52 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 53 | #define RK808_DVS2_POL BIT(2) |
| 54 | #define RK808_DVS1_POL BIT(1) |
| 55 | |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 56 | /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */ |
| 57 | #define RK808_SLP_REG_OFFSET 1 |
| 58 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 59 | /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */ |
| 60 | #define RK808_DVS_REG_OFFSET 2 |
| 61 | |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 62 | /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */ |
| 63 | #define RK808_SLP_SET_OFF_REG_OFFSET 2 |
| 64 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 65 | /* max steps for increase voltage of Buck1/2, equal 100mv*/ |
| 66 | #define MAX_STEPS_ONE_TIME 8 |
| 67 | |
Elaine Zhang | c4e0d34 | 2017-08-21 03:28:36 +0200 | [diff] [blame] | 68 | #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ |
| 69 | _vmask, _ereg, _emask, _etime) \ |
| 70 | [_id] = { \ |
| 71 | .name = (_match), \ |
| 72 | .supply_name = (_supply), \ |
| 73 | .of_match = of_match_ptr(_match), \ |
| 74 | .regulators_node = of_match_ptr("regulators"), \ |
| 75 | .type = REGULATOR_VOLTAGE, \ |
| 76 | .id = (_id), \ |
| 77 | .n_voltages = (((_max) - (_min)) / (_step) + 1), \ |
| 78 | .owner = THIS_MODULE, \ |
| 79 | .min_uV = (_min) * 1000, \ |
| 80 | .uV_step = (_step) * 1000, \ |
| 81 | .vsel_reg = (_vreg), \ |
| 82 | .vsel_mask = (_vmask), \ |
| 83 | .enable_reg = (_ereg), \ |
| 84 | .enable_mask = (_emask), \ |
| 85 | .enable_time = (_etime), \ |
| 86 | .ops = &rk805_reg_ops, \ |
| 87 | } |
| 88 | |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 89 | #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ |
| 90 | _vmask, _ereg, _emask, _etime) \ |
| 91 | [_id] = { \ |
| 92 | .name = (_match), \ |
| 93 | .supply_name = (_supply), \ |
| 94 | .of_match = of_match_ptr(_match), \ |
| 95 | .regulators_node = of_match_ptr("regulators"), \ |
| 96 | .type = REGULATOR_VOLTAGE, \ |
| 97 | .id = (_id), \ |
| 98 | .n_voltages = (((_max) - (_min)) / (_step) + 1), \ |
| 99 | .owner = THIS_MODULE, \ |
| 100 | .min_uV = (_min) * 1000, \ |
| 101 | .uV_step = (_step) * 1000, \ |
| 102 | .vsel_reg = (_vreg), \ |
| 103 | .vsel_mask = (_vmask), \ |
| 104 | .enable_reg = (_ereg), \ |
| 105 | .enable_mask = (_emask), \ |
| 106 | .enable_time = (_etime), \ |
| 107 | .ops = &rk808_reg_ops, \ |
| 108 | } |
| 109 | |
| 110 | #define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask) \ |
| 111 | [_id] = { \ |
| 112 | .name = (_match), \ |
| 113 | .supply_name = (_supply), \ |
| 114 | .of_match = of_match_ptr(_match), \ |
| 115 | .regulators_node = of_match_ptr("regulators"), \ |
| 116 | .type = REGULATOR_VOLTAGE, \ |
| 117 | .id = (_id), \ |
| 118 | .enable_reg = (_ereg), \ |
| 119 | .enable_mask = (_emask), \ |
| 120 | .owner = THIS_MODULE, \ |
| 121 | .ops = &rk808_switch_ops \ |
| 122 | } |
| 123 | |
| 124 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 125 | struct rk808_regulator_data { |
| 126 | struct gpio_desc *dvs_gpio[2]; |
| 127 | }; |
| 128 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 129 | static const int rk808_buck_config_regs[] = { |
| 130 | RK808_BUCK1_CONFIG_REG, |
| 131 | RK808_BUCK2_CONFIG_REG, |
| 132 | RK808_BUCK3_CONFIG_REG, |
| 133 | RK808_BUCK4_CONFIG_REG, |
| 134 | }; |
| 135 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 136 | static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = { |
| 137 | REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), |
| 138 | REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), |
| 139 | }; |
| 140 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 141 | static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev) |
| 142 | { |
| 143 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); |
Axel Lin | bf8e276 | 2016-10-21 10:30:16 +0800 | [diff] [blame] | 144 | int id = rdev_get_id(rdev); |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 145 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; |
| 146 | unsigned int val; |
| 147 | int ret; |
| 148 | |
Uwe Kleine-König | a13eaf0 | 2015-07-21 16:46:25 +0200 | [diff] [blame] | 149 | if (!gpio || gpiod_get_value(gpio) == 0) |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 150 | return regulator_get_voltage_sel_regmap(rdev); |
| 151 | |
| 152 | ret = regmap_read(rdev->regmap, |
| 153 | rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET, |
| 154 | &val); |
| 155 | if (ret != 0) |
| 156 | return ret; |
| 157 | |
| 158 | val &= rdev->desc->vsel_mask; |
| 159 | val >>= ffs(rdev->desc->vsel_mask) - 1; |
| 160 | |
| 161 | return val; |
| 162 | } |
| 163 | |
| 164 | static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev, |
| 165 | unsigned sel) |
| 166 | { |
| 167 | int ret, delta_sel; |
| 168 | unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask; |
| 169 | |
| 170 | ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); |
| 171 | if (ret != 0) |
| 172 | return ret; |
| 173 | |
| 174 | tmp = val & ~mask; |
| 175 | old_sel = val & mask; |
| 176 | old_sel >>= ffs(mask) - 1; |
| 177 | delta_sel = sel - old_sel; |
| 178 | |
| 179 | /* |
| 180 | * If directly modify the register to change the voltage, we will face |
| 181 | * the risk of overshoot. Put it into a multi-step, can effectively |
| 182 | * avoid this problem, a step is 100mv here. |
| 183 | */ |
| 184 | while (delta_sel > MAX_STEPS_ONE_TIME) { |
| 185 | old_sel += MAX_STEPS_ONE_TIME; |
| 186 | val = old_sel << (ffs(mask) - 1); |
| 187 | val |= tmp; |
| 188 | |
| 189 | /* |
| 190 | * i2c is 400kHz (2.5us per bit) and we must transmit _at least_ |
| 191 | * 3 bytes (24 bits) plus start and stop so 26 bits. So we've |
| 192 | * got more than 65 us between each voltage change and thus |
| 193 | * won't ramp faster than ~1500 uV / us. |
| 194 | */ |
| 195 | ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); |
| 196 | delta_sel = sel - old_sel; |
| 197 | } |
| 198 | |
| 199 | sel <<= ffs(mask) - 1; |
| 200 | val = tmp | sel; |
| 201 | ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); |
| 202 | |
| 203 | /* |
| 204 | * When we change the voltage register directly, the ramp rate is about |
| 205 | * 100000uv/us, wait 1us to make sure the target voltage to be stable, |
| 206 | * so we needn't wait extra time after that. |
| 207 | */ |
| 208 | udelay(1); |
| 209 | |
| 210 | return ret; |
| 211 | } |
| 212 | |
| 213 | static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev, |
| 214 | unsigned sel) |
| 215 | { |
| 216 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); |
Axel Lin | bf8e276 | 2016-10-21 10:30:16 +0800 | [diff] [blame] | 217 | int id = rdev_get_id(rdev); |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 218 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; |
| 219 | unsigned int reg = rdev->desc->vsel_reg; |
| 220 | unsigned old_sel; |
| 221 | int ret, gpio_level; |
| 222 | |
Uwe Kleine-König | a13eaf0 | 2015-07-21 16:46:25 +0200 | [diff] [blame] | 223 | if (!gpio) |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 224 | return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel); |
| 225 | |
| 226 | gpio_level = gpiod_get_value(gpio); |
| 227 | if (gpio_level == 0) { |
| 228 | reg += RK808_DVS_REG_OFFSET; |
| 229 | ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel); |
| 230 | } else { |
| 231 | ret = regmap_read(rdev->regmap, |
| 232 | reg + RK808_DVS_REG_OFFSET, |
| 233 | &old_sel); |
| 234 | } |
| 235 | |
| 236 | if (ret != 0) |
| 237 | return ret; |
| 238 | |
| 239 | sel <<= ffs(rdev->desc->vsel_mask) - 1; |
| 240 | sel |= old_sel & ~rdev->desc->vsel_mask; |
| 241 | |
| 242 | ret = regmap_write(rdev->regmap, reg, sel); |
| 243 | if (ret) |
| 244 | return ret; |
| 245 | |
| 246 | gpiod_set_value(gpio, !gpio_level); |
| 247 | |
| 248 | return ret; |
| 249 | } |
| 250 | |
| 251 | static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev, |
| 252 | unsigned int old_selector, |
| 253 | unsigned int new_selector) |
| 254 | { |
| 255 | struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); |
Axel Lin | bf8e276 | 2016-10-21 10:30:16 +0800 | [diff] [blame] | 256 | int id = rdev_get_id(rdev); |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 257 | struct gpio_desc *gpio = pdata->dvs_gpio[id]; |
| 258 | |
| 259 | /* if there is no dvs1/2 pin, we don't need wait extra time here. */ |
Uwe Kleine-König | a13eaf0 | 2015-07-21 16:46:25 +0200 | [diff] [blame] | 260 | if (!gpio) |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 261 | return 0; |
| 262 | |
| 263 | return regulator_set_voltage_time_sel(rdev, old_selector, new_selector); |
| 264 | } |
| 265 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 266 | static int rk808_set_ramp_delay(struct regulator_dev *rdev, int ramp_delay) |
| 267 | { |
| 268 | unsigned int ramp_value = RK808_RAMP_RATE_10MV_PER_US; |
Axel Lin | bf8e276 | 2016-10-21 10:30:16 +0800 | [diff] [blame] | 269 | unsigned int reg = rk808_buck_config_regs[rdev_get_id(rdev)]; |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 270 | |
| 271 | switch (ramp_delay) { |
| 272 | case 1 ... 2000: |
| 273 | ramp_value = RK808_RAMP_RATE_2MV_PER_US; |
| 274 | break; |
| 275 | case 2001 ... 4000: |
| 276 | ramp_value = RK808_RAMP_RATE_4MV_PER_US; |
| 277 | break; |
| 278 | case 4001 ... 6000: |
| 279 | ramp_value = RK808_RAMP_RATE_6MV_PER_US; |
| 280 | break; |
| 281 | case 6001 ... 10000: |
| 282 | break; |
| 283 | default: |
| 284 | pr_warn("%s ramp_delay: %d not supported, setting 10000\n", |
| 285 | rdev->desc->name, ramp_delay); |
| 286 | } |
| 287 | |
| 288 | return regmap_update_bits(rdev->regmap, reg, |
| 289 | RK808_RAMP_RATE_MASK, ramp_value); |
| 290 | } |
| 291 | |
Wei Yongjun | 5cb2f03 | 2014-12-09 21:19:51 +0800 | [diff] [blame] | 292 | static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv) |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 293 | { |
| 294 | unsigned int reg; |
Wadim Egorov | afcd666 | 2016-04-25 15:20:43 +0200 | [diff] [blame] | 295 | int sel = regulator_map_voltage_linear(rdev, uv, uv); |
| 296 | |
| 297 | if (sel < 0) |
| 298 | return -EINVAL; |
| 299 | |
| 300 | reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; |
| 301 | |
| 302 | return regmap_update_bits(rdev->regmap, reg, |
| 303 | rdev->desc->vsel_mask, |
| 304 | sel); |
| 305 | } |
| 306 | |
Wadim Egorov | 129d7cf | 2016-04-26 16:54:04 +0200 | [diff] [blame] | 307 | static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv) |
| 308 | { |
| 309 | unsigned int reg; |
| 310 | int sel = regulator_map_voltage_linear_range(rdev, uv, uv); |
| 311 | |
| 312 | if (sel < 0) |
| 313 | return -EINVAL; |
| 314 | |
| 315 | reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; |
| 316 | |
| 317 | return regmap_update_bits(rdev->regmap, reg, |
| 318 | rdev->desc->vsel_mask, |
| 319 | sel); |
| 320 | } |
| 321 | |
Elaine Zhang | c4e0d34 | 2017-08-21 03:28:36 +0200 | [diff] [blame] | 322 | static int rk805_set_suspend_enable(struct regulator_dev *rdev) |
| 323 | { |
| 324 | unsigned int reg; |
| 325 | |
| 326 | reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; |
| 327 | |
| 328 | return regmap_update_bits(rdev->regmap, reg, |
| 329 | rdev->desc->enable_mask, |
| 330 | rdev->desc->enable_mask); |
| 331 | } |
| 332 | |
| 333 | static int rk805_set_suspend_disable(struct regulator_dev *rdev) |
| 334 | { |
| 335 | unsigned int reg; |
| 336 | |
| 337 | reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; |
| 338 | |
| 339 | return regmap_update_bits(rdev->regmap, reg, |
| 340 | rdev->desc->enable_mask, |
| 341 | 0); |
| 342 | } |
| 343 | |
Wei Yongjun | 5cb2f03 | 2014-12-09 21:19:51 +0800 | [diff] [blame] | 344 | static int rk808_set_suspend_enable(struct regulator_dev *rdev) |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 345 | { |
| 346 | unsigned int reg; |
| 347 | |
| 348 | reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; |
| 349 | |
| 350 | return regmap_update_bits(rdev->regmap, reg, |
| 351 | rdev->desc->enable_mask, |
| 352 | 0); |
| 353 | } |
| 354 | |
Wei Yongjun | 5cb2f03 | 2014-12-09 21:19:51 +0800 | [diff] [blame] | 355 | static int rk808_set_suspend_disable(struct regulator_dev *rdev) |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 356 | { |
| 357 | unsigned int reg; |
| 358 | |
| 359 | reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; |
| 360 | |
| 361 | return regmap_update_bits(rdev->regmap, reg, |
| 362 | rdev->desc->enable_mask, |
| 363 | rdev->desc->enable_mask); |
| 364 | } |
| 365 | |
Elaine Zhang | c4e0d34 | 2017-08-21 03:28:36 +0200 | [diff] [blame] | 366 | static struct regulator_ops rk805_reg_ops = { |
| 367 | .list_voltage = regulator_list_voltage_linear, |
| 368 | .map_voltage = regulator_map_voltage_linear, |
| 369 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 370 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 371 | .enable = regulator_enable_regmap, |
| 372 | .disable = regulator_disable_regmap, |
| 373 | .is_enabled = regulator_is_enabled_regmap, |
| 374 | .set_suspend_voltage = rk808_set_suspend_voltage, |
| 375 | .set_suspend_enable = rk805_set_suspend_enable, |
| 376 | .set_suspend_disable = rk805_set_suspend_disable, |
| 377 | }; |
| 378 | |
| 379 | static struct regulator_ops rk805_switch_ops = { |
| 380 | .enable = regulator_enable_regmap, |
| 381 | .disable = regulator_disable_regmap, |
| 382 | .is_enabled = regulator_is_enabled_regmap, |
| 383 | .set_suspend_enable = rk805_set_suspend_enable, |
| 384 | .set_suspend_disable = rk805_set_suspend_disable, |
| 385 | }; |
| 386 | |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 387 | static struct regulator_ops rk808_buck1_2_ops = { |
Wadim Egorov | afcd666 | 2016-04-25 15:20:43 +0200 | [diff] [blame] | 388 | .list_voltage = regulator_list_voltage_linear, |
| 389 | .map_voltage = regulator_map_voltage_linear, |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 390 | .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap, |
| 391 | .set_voltage_sel = rk808_buck1_2_set_voltage_sel, |
| 392 | .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 393 | .enable = regulator_enable_regmap, |
| 394 | .disable = regulator_disable_regmap, |
| 395 | .is_enabled = regulator_is_enabled_regmap, |
| 396 | .set_ramp_delay = rk808_set_ramp_delay, |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 397 | .set_suspend_voltage = rk808_set_suspend_voltage, |
| 398 | .set_suspend_enable = rk808_set_suspend_enable, |
| 399 | .set_suspend_disable = rk808_set_suspend_disable, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 400 | }; |
| 401 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 402 | static struct regulator_ops rk808_reg_ops = { |
Wadim Egorov | afcd666 | 2016-04-25 15:20:43 +0200 | [diff] [blame] | 403 | .list_voltage = regulator_list_voltage_linear, |
| 404 | .map_voltage = regulator_map_voltage_linear, |
| 405 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 406 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 407 | .enable = regulator_enable_regmap, |
| 408 | .disable = regulator_disable_regmap, |
| 409 | .is_enabled = regulator_is_enabled_regmap, |
| 410 | .set_suspend_voltage = rk808_set_suspend_voltage, |
| 411 | .set_suspend_enable = rk808_set_suspend_enable, |
| 412 | .set_suspend_disable = rk808_set_suspend_disable, |
| 413 | }; |
| 414 | |
Wadim Egorov | 129d7cf | 2016-04-26 16:54:04 +0200 | [diff] [blame] | 415 | static struct regulator_ops rk808_reg_ops_ranges = { |
| 416 | .list_voltage = regulator_list_voltage_linear_range, |
| 417 | .map_voltage = regulator_map_voltage_linear_range, |
| 418 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 419 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 420 | .enable = regulator_enable_regmap, |
| 421 | .disable = regulator_disable_regmap, |
| 422 | .is_enabled = regulator_is_enabled_regmap, |
| 423 | .set_suspend_voltage = rk808_set_suspend_voltage_range, |
| 424 | .set_suspend_enable = rk808_set_suspend_enable, |
| 425 | .set_suspend_disable = rk808_set_suspend_disable, |
| 426 | }; |
| 427 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 428 | static struct regulator_ops rk808_switch_ops = { |
Chris Zhong | 251ce318 | 2014-10-10 15:35:06 -0700 | [diff] [blame] | 429 | .enable = regulator_enable_regmap, |
| 430 | .disable = regulator_disable_regmap, |
| 431 | .is_enabled = regulator_is_enabled_regmap, |
| 432 | .set_suspend_enable = rk808_set_suspend_enable, |
| 433 | .set_suspend_disable = rk808_set_suspend_disable, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 434 | }; |
| 435 | |
Elaine Zhang | c4e0d34 | 2017-08-21 03:28:36 +0200 | [diff] [blame] | 436 | static const struct regulator_desc rk805_reg[] = { |
| 437 | { |
| 438 | .name = "DCDC_REG1", |
| 439 | .supply_name = "vcc1", |
| 440 | .of_match = of_match_ptr("DCDC_REG1"), |
| 441 | .regulators_node = of_match_ptr("regulators"), |
| 442 | .id = RK805_ID_DCDC1, |
| 443 | .ops = &rk805_reg_ops, |
| 444 | .type = REGULATOR_VOLTAGE, |
| 445 | .min_uV = 712500, |
| 446 | .uV_step = 12500, |
| 447 | .n_voltages = 64, |
| 448 | .vsel_reg = RK805_BUCK1_ON_VSEL_REG, |
| 449 | .vsel_mask = RK818_BUCK_VSEL_MASK, |
| 450 | .enable_reg = RK805_DCDC_EN_REG, |
| 451 | .enable_mask = BIT(0), |
| 452 | .owner = THIS_MODULE, |
| 453 | }, { |
| 454 | .name = "DCDC_REG2", |
| 455 | .supply_name = "vcc2", |
| 456 | .of_match = of_match_ptr("DCDC_REG2"), |
| 457 | .regulators_node = of_match_ptr("regulators"), |
| 458 | .id = RK805_ID_DCDC2, |
| 459 | .ops = &rk805_reg_ops, |
| 460 | .type = REGULATOR_VOLTAGE, |
| 461 | .min_uV = 712500, |
| 462 | .uV_step = 12500, |
| 463 | .n_voltages = 64, |
| 464 | .vsel_reg = RK805_BUCK2_ON_VSEL_REG, |
| 465 | .vsel_mask = RK818_BUCK_VSEL_MASK, |
| 466 | .enable_reg = RK805_DCDC_EN_REG, |
| 467 | .enable_mask = BIT(1), |
| 468 | .owner = THIS_MODULE, |
| 469 | }, { |
| 470 | .name = "DCDC_REG3", |
| 471 | .supply_name = "vcc3", |
| 472 | .of_match = of_match_ptr("DCDC_REG3"), |
| 473 | .regulators_node = of_match_ptr("regulators"), |
| 474 | .id = RK805_ID_DCDC3, |
| 475 | .ops = &rk805_switch_ops, |
| 476 | .type = REGULATOR_VOLTAGE, |
| 477 | .n_voltages = 1, |
| 478 | .enable_reg = RK805_DCDC_EN_REG, |
| 479 | .enable_mask = BIT(2), |
| 480 | .owner = THIS_MODULE, |
| 481 | }, |
| 482 | |
| 483 | RK805_DESC(RK805_ID_DCDC4, "DCDC_REG4", "vcc4", 800, 3400, 100, |
| 484 | RK805_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK, |
| 485 | RK805_DCDC_EN_REG, BIT(3), 0), |
| 486 | |
| 487 | RK805_DESC(RK805_ID_LDO1, "LDO_REG1", "vcc5", 800, 3400, 100, |
| 488 | RK805_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, |
| 489 | BIT(0), 400), |
| 490 | RK805_DESC(RK805_ID_LDO2, "LDO_REG2", "vcc5", 800, 3400, 100, |
| 491 | RK805_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, |
| 492 | BIT(1), 400), |
| 493 | RK805_DESC(RK805_ID_LDO3, "LDO_REG3", "vcc6", 800, 3400, 100, |
| 494 | RK805_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, |
| 495 | BIT(2), 400), |
| 496 | }; |
| 497 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 498 | static const struct regulator_desc rk808_reg[] = { |
| 499 | { |
| 500 | .name = "DCDC_REG1", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 501 | .supply_name = "vcc1", |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 502 | .of_match = of_match_ptr("DCDC_REG1"), |
| 503 | .regulators_node = of_match_ptr("regulators"), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 504 | .id = RK808_ID_DCDC1, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 505 | .ops = &rk808_buck1_2_ops, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 506 | .type = REGULATOR_VOLTAGE, |
Wadim Egorov | afcd666 | 2016-04-25 15:20:43 +0200 | [diff] [blame] | 507 | .min_uV = 712500, |
| 508 | .uV_step = 12500, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 509 | .n_voltages = 64, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 510 | .vsel_reg = RK808_BUCK1_ON_VSEL_REG, |
| 511 | .vsel_mask = RK808_BUCK_VSEL_MASK, |
| 512 | .enable_reg = RK808_DCDC_EN_REG, |
| 513 | .enable_mask = BIT(0), |
| 514 | .owner = THIS_MODULE, |
| 515 | }, { |
| 516 | .name = "DCDC_REG2", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 517 | .supply_name = "vcc2", |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 518 | .of_match = of_match_ptr("DCDC_REG2"), |
| 519 | .regulators_node = of_match_ptr("regulators"), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 520 | .id = RK808_ID_DCDC2, |
Doug Anderson | 8af2522 | 2014-09-16 10:22:54 -0700 | [diff] [blame] | 521 | .ops = &rk808_buck1_2_ops, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 522 | .type = REGULATOR_VOLTAGE, |
Wadim Egorov | afcd666 | 2016-04-25 15:20:43 +0200 | [diff] [blame] | 523 | .min_uV = 712500, |
| 524 | .uV_step = 12500, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 525 | .n_voltages = 64, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 526 | .vsel_reg = RK808_BUCK2_ON_VSEL_REG, |
| 527 | .vsel_mask = RK808_BUCK_VSEL_MASK, |
| 528 | .enable_reg = RK808_DCDC_EN_REG, |
| 529 | .enable_mask = BIT(1), |
| 530 | .owner = THIS_MODULE, |
| 531 | }, { |
| 532 | .name = "DCDC_REG3", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 533 | .supply_name = "vcc3", |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 534 | .of_match = of_match_ptr("DCDC_REG3"), |
| 535 | .regulators_node = of_match_ptr("regulators"), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 536 | .id = RK808_ID_DCDC3, |
| 537 | .ops = &rk808_switch_ops, |
| 538 | .type = REGULATOR_VOLTAGE, |
| 539 | .n_voltages = 1, |
| 540 | .enable_reg = RK808_DCDC_EN_REG, |
| 541 | .enable_mask = BIT(2), |
| 542 | .owner = THIS_MODULE, |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 543 | }, |
| 544 | RK8XX_DESC(RK808_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3300, 100, |
| 545 | RK808_BUCK4_ON_VSEL_REG, RK808_BUCK4_VSEL_MASK, |
| 546 | RK808_DCDC_EN_REG, BIT(3), 0), |
| 547 | RK8XX_DESC(RK808_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100, |
| 548 | RK808_LDO1_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 549 | BIT(0), 400), |
| 550 | RK8XX_DESC(RK808_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100, |
| 551 | RK808_LDO2_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 552 | BIT(1), 400), |
| 553 | { |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 554 | .name = "LDO_REG3", |
Doug Anderson | b8074eb | 2014-09-02 09:14:28 -0700 | [diff] [blame] | 555 | .supply_name = "vcc7", |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 556 | .of_match = of_match_ptr("LDO_REG3"), |
| 557 | .regulators_node = of_match_ptr("regulators"), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 558 | .id = RK808_ID_LDO3, |
Wadim Egorov | 129d7cf | 2016-04-26 16:54:04 +0200 | [diff] [blame] | 559 | .ops = &rk808_reg_ops_ranges, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 560 | .type = REGULATOR_VOLTAGE, |
| 561 | .n_voltages = 16, |
| 562 | .linear_ranges = rk808_ldo3_voltage_ranges, |
| 563 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), |
| 564 | .vsel_reg = RK808_LDO3_ON_VSEL_REG, |
| 565 | .vsel_mask = RK808_BUCK4_VSEL_MASK, |
| 566 | .enable_reg = RK808_LDO_EN_REG, |
| 567 | .enable_mask = BIT(2), |
Doug Anderson | 28249b0 | 2015-02-20 16:53:38 -0800 | [diff] [blame] | 568 | .enable_time = 400, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 569 | .owner = THIS_MODULE, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 570 | }, |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 571 | RK8XX_DESC(RK808_ID_LDO4, "LDO_REG4", "vcc9", 1800, 3400, 100, |
| 572 | RK808_LDO4_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 573 | BIT(3), 400), |
| 574 | RK8XX_DESC(RK808_ID_LDO5, "LDO_REG5", "vcc9", 1800, 3400, 100, |
| 575 | RK808_LDO5_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 576 | BIT(4), 400), |
| 577 | RK8XX_DESC(RK808_ID_LDO6, "LDO_REG6", "vcc10", 800, 2500, 100, |
| 578 | RK808_LDO6_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 579 | BIT(5), 400), |
| 580 | RK8XX_DESC(RK808_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100, |
| 581 | RK808_LDO7_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 582 | BIT(6), 400), |
| 583 | RK8XX_DESC(RK808_ID_LDO8, "LDO_REG8", "vcc11", 1800, 3400, 100, |
| 584 | RK808_LDO8_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, |
| 585 | BIT(7), 400), |
| 586 | RK8XX_DESC_SWITCH(RK808_ID_SWITCH1, "SWITCH_REG1", "vcc8", |
| 587 | RK808_DCDC_EN_REG, BIT(5)), |
| 588 | RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12", |
| 589 | RK808_DCDC_EN_REG, BIT(6)), |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 590 | }; |
| 591 | |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 592 | static const struct regulator_desc rk818_reg[] = { |
| 593 | { |
| 594 | .name = "DCDC_REG1", |
| 595 | .supply_name = "vcc1", |
| 596 | .of_match = of_match_ptr("DCDC_REG1"), |
| 597 | .regulators_node = of_match_ptr("regulators"), |
| 598 | .id = RK818_ID_DCDC1, |
| 599 | .ops = &rk808_reg_ops, |
| 600 | .type = REGULATOR_VOLTAGE, |
| 601 | .min_uV = 712500, |
| 602 | .uV_step = 12500, |
| 603 | .n_voltages = 64, |
| 604 | .vsel_reg = RK818_BUCK1_ON_VSEL_REG, |
| 605 | .vsel_mask = RK818_BUCK_VSEL_MASK, |
| 606 | .enable_reg = RK818_DCDC_EN_REG, |
| 607 | .enable_mask = BIT(0), |
| 608 | .owner = THIS_MODULE, |
| 609 | }, { |
| 610 | .name = "DCDC_REG2", |
| 611 | .supply_name = "vcc2", |
| 612 | .of_match = of_match_ptr("DCDC_REG2"), |
| 613 | .regulators_node = of_match_ptr("regulators"), |
| 614 | .id = RK818_ID_DCDC2, |
| 615 | .ops = &rk808_reg_ops, |
| 616 | .type = REGULATOR_VOLTAGE, |
| 617 | .min_uV = 712500, |
| 618 | .uV_step = 12500, |
| 619 | .n_voltages = 64, |
| 620 | .vsel_reg = RK818_BUCK2_ON_VSEL_REG, |
| 621 | .vsel_mask = RK818_BUCK_VSEL_MASK, |
| 622 | .enable_reg = RK818_DCDC_EN_REG, |
| 623 | .enable_mask = BIT(1), |
| 624 | .owner = THIS_MODULE, |
| 625 | }, { |
| 626 | .name = "DCDC_REG3", |
| 627 | .supply_name = "vcc3", |
| 628 | .of_match = of_match_ptr("DCDC_REG3"), |
| 629 | .regulators_node = of_match_ptr("regulators"), |
| 630 | .id = RK818_ID_DCDC3, |
| 631 | .ops = &rk808_switch_ops, |
| 632 | .type = REGULATOR_VOLTAGE, |
| 633 | .n_voltages = 1, |
| 634 | .enable_reg = RK818_DCDC_EN_REG, |
| 635 | .enable_mask = BIT(2), |
| 636 | .owner = THIS_MODULE, |
| 637 | }, |
| 638 | RK8XX_DESC(RK818_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3600, 100, |
| 639 | RK818_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK, |
| 640 | RK818_DCDC_EN_REG, BIT(3), 0), |
| 641 | RK8XX_DESC(RK818_ID_BOOST, "DCDC_BOOST", "boost", 4700, 5400, 100, |
| 642 | RK818_BOOST_LDO9_ON_VSEL_REG, RK818_BOOST_ON_VSEL_MASK, |
| 643 | RK818_DCDC_EN_REG, BIT(4), 0), |
| 644 | RK8XX_DESC(RK818_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100, |
| 645 | RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 646 | BIT(0), 400), |
| 647 | RK8XX_DESC(RK818_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100, |
Wadim Egorov | 75f8811 | 2017-03-22 16:50:50 +0100 | [diff] [blame] | 648 | RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 649 | BIT(1), 400), |
| 650 | { |
| 651 | .name = "LDO_REG3", |
| 652 | .supply_name = "vcc7", |
| 653 | .of_match = of_match_ptr("LDO_REG3"), |
| 654 | .regulators_node = of_match_ptr("regulators"), |
| 655 | .id = RK818_ID_LDO3, |
| 656 | .ops = &rk808_reg_ops_ranges, |
| 657 | .type = REGULATOR_VOLTAGE, |
| 658 | .n_voltages = 16, |
| 659 | .linear_ranges = rk808_ldo3_voltage_ranges, |
| 660 | .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), |
| 661 | .vsel_reg = RK818_LDO3_ON_VSEL_REG, |
| 662 | .vsel_mask = RK818_LDO3_ON_VSEL_MASK, |
| 663 | .enable_reg = RK818_LDO_EN_REG, |
| 664 | .enable_mask = BIT(2), |
| 665 | .enable_time = 400, |
| 666 | .owner = THIS_MODULE, |
| 667 | }, |
| 668 | RK8XX_DESC(RK818_ID_LDO4, "LDO_REG4", "vcc8", 1800, 3400, 100, |
| 669 | RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 670 | BIT(3), 400), |
| 671 | RK8XX_DESC(RK818_ID_LDO5, "LDO_REG5", "vcc7", 1800, 3400, 100, |
| 672 | RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 673 | BIT(4), 400), |
| 674 | RK8XX_DESC(RK818_ID_LDO6, "LDO_REG6", "vcc8", 800, 2500, 100, |
| 675 | RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 676 | BIT(5), 400), |
| 677 | RK8XX_DESC(RK818_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100, |
| 678 | RK818_LDO7_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 679 | BIT(6), 400), |
| 680 | RK8XX_DESC(RK818_ID_LDO8, "LDO_REG8", "vcc8", 1800, 3400, 100, |
| 681 | RK818_LDO8_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, |
| 682 | BIT(7), 400), |
| 683 | RK8XX_DESC(RK818_ID_LDO9, "LDO_REG9", "vcc9", 1800, 3400, 100, |
| 684 | RK818_BOOST_LDO9_ON_VSEL_REG, RK818_LDO_VSEL_MASK, |
| 685 | RK818_DCDC_EN_REG, BIT(5), 400), |
| 686 | RK8XX_DESC_SWITCH(RK818_ID_SWITCH, "SWITCH_REG", "vcc9", |
| 687 | RK818_DCDC_EN_REG, BIT(6)), |
| 688 | RK8XX_DESC_SWITCH(RK818_ID_HDMI_SWITCH, "HDMI_SWITCH", "h_5v", |
| 689 | RK818_H5V_EN_REG, BIT(0)), |
| 690 | RK8XX_DESC_SWITCH(RK818_ID_OTG_SWITCH, "OTG_SWITCH", "usb", |
| 691 | RK818_DCDC_EN_REG, BIT(7)), |
| 692 | }; |
| 693 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 694 | static int rk808_regulator_dt_parse_pdata(struct device *dev, |
| 695 | struct device *client_dev, |
| 696 | struct regmap *map, |
| 697 | struct rk808_regulator_data *pdata) |
| 698 | { |
| 699 | struct device_node *np; |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 700 | int tmp, ret = 0, i; |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 701 | |
| 702 | np = of_get_child_by_name(client_dev->of_node, "regulators"); |
| 703 | if (!np) |
| 704 | return -ENXIO; |
| 705 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 706 | for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { |
Uwe Kleine-König | a13eaf0 | 2015-07-21 16:46:25 +0200 | [diff] [blame] | 707 | pdata->dvs_gpio[i] = |
| 708 | devm_gpiod_get_index_optional(client_dev, "dvs", i, |
| 709 | GPIOD_OUT_LOW); |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 710 | if (IS_ERR(pdata->dvs_gpio[i])) { |
Uwe Kleine-König | a13eaf0 | 2015-07-21 16:46:25 +0200 | [diff] [blame] | 711 | ret = PTR_ERR(pdata->dvs_gpio[i]); |
| 712 | dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret); |
| 713 | goto dt_parse_end; |
| 714 | } |
| 715 | |
| 716 | if (!pdata->dvs_gpio[i]) { |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 717 | dev_warn(dev, "there is no dvs%d gpio\n", i); |
| 718 | continue; |
| 719 | } |
| 720 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 721 | tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL; |
| 722 | ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp, |
| 723 | gpiod_is_active_low(pdata->dvs_gpio[i]) ? |
| 724 | 0 : tmp); |
| 725 | } |
| 726 | |
| 727 | dt_parse_end: |
| 728 | of_node_put(np); |
| 729 | return ret; |
| 730 | } |
| 731 | |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 732 | static int rk808_regulator_probe(struct platform_device *pdev) |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 733 | { |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 734 | struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); |
| 735 | struct i2c_client *client = rk808->i2c; |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 736 | struct regulator_config config = {}; |
| 737 | struct regulator_dev *rk808_rdev; |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 738 | struct rk808_regulator_data *pdata; |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 739 | const struct regulator_desc *regulators; |
| 740 | int ret, i, nregulators; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 741 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 742 | pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); |
| 743 | if (!pdata) |
| 744 | return -ENOMEM; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 745 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 746 | ret = rk808_regulator_dt_parse_pdata(&pdev->dev, &client->dev, |
| 747 | rk808->regmap, pdata); |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 748 | if (ret < 0) |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 749 | return ret; |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 750 | |
Chris Zhong | bad47ad | 2015-07-20 17:23:53 +0800 | [diff] [blame] | 751 | platform_set_drvdata(pdev, pdata); |
| 752 | |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 753 | switch (rk808->variant) { |
Elaine Zhang | c4e0d34 | 2017-08-21 03:28:36 +0200 | [diff] [blame] | 754 | case RK805_ID: |
| 755 | regulators = rk805_reg; |
| 756 | nregulators = RK805_NUM_REGULATORS; |
| 757 | break; |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 758 | case RK808_ID: |
| 759 | regulators = rk808_reg; |
| 760 | nregulators = RK808_NUM_REGULATORS; |
| 761 | break; |
| 762 | case RK818_ID: |
| 763 | regulators = rk818_reg; |
| 764 | nregulators = RK818_NUM_REGULATORS; |
| 765 | break; |
| 766 | default: |
| 767 | dev_err(&client->dev, "unsupported RK8XX ID %lu\n", |
| 768 | rk808->variant); |
| 769 | return -EINVAL; |
| 770 | } |
| 771 | |
Wadim Egorov | 9e9daa0 | 2016-05-10 15:18:55 +0200 | [diff] [blame] | 772 | config.dev = &client->dev; |
| 773 | config.driver_data = pdata; |
| 774 | config.regmap = rk808->regmap; |
| 775 | |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 776 | /* Instantiate the regulators */ |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 777 | for (i = 0; i < nregulators; i++) { |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 778 | rk808_rdev = devm_regulator_register(&pdev->dev, |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 779 | ®ulators[i], &config); |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 780 | if (IS_ERR(rk808_rdev)) { |
Chris Zhong | d76c333 | 2014-08-25 21:37:06 +0800 | [diff] [blame] | 781 | dev_err(&client->dev, |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 782 | "failed to register %d regulator\n", i); |
| 783 | return PTR_ERR(rk808_rdev); |
| 784 | } |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 785 | } |
Chris Zhong | 571a401 | 2014-09-10 09:18:06 +0800 | [diff] [blame] | 786 | |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 787 | return 0; |
| 788 | } |
| 789 | |
| 790 | static struct platform_driver rk808_regulator_driver = { |
| 791 | .probe = rk808_regulator_probe, |
| 792 | .driver = { |
Markus Elfring | 556ae22 | 2016-08-15 10:30:31 +0200 | [diff] [blame] | 793 | .name = "rk808-regulator" |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 794 | }, |
| 795 | }; |
| 796 | |
| 797 | module_platform_driver(rk808_regulator_driver); |
| 798 | |
Wadim Egorov | 1137529 | 2016-08-29 13:07:59 +0200 | [diff] [blame] | 799 | MODULE_DESCRIPTION("regulator driver for the RK808/RK818 series PMICs"); |
| 800 | MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); |
| 801 | MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>"); |
| 802 | MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>"); |
Chris Zhong | 2cd64ae | 2014-08-20 11:36:42 +0800 | [diff] [blame] | 803 | MODULE_LICENSE("GPL"); |
| 804 | MODULE_ALIAS("platform:rk808-regulator"); |