1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * Regulator driver for Rockchip RK805/RK808/RK818 4 * 5 * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd 6 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 7 * 8 * Author: Chris Zhong <zyw@rock-chips.com> 9 * Author: Zhang Qing <zhangqing@rock-chips.com> 10 * Author: Xu Shengfei <xsf@rock-chips.com> 11 * 12 * Copyright (C) 2016 PHYTEC Messtechnik GmbH 13 * 14 * Author: Wadim Egorov <w.egorov@phytec.de> 15 */ 16 17 #include <linux/delay.h> 18 #include <linux/module.h> 19 #include <linux/of.h> 20 #include <linux/mfd/rk808.h> 21 #include <linux/platform_device.h> 22 #include <linux/regulator/driver.h> 23 #include <linux/regulator/of_regulator.h> 24 #include <linux/gpio/consumer.h> 25 26 /* Field Definitions */ 27 #define RK808_BUCK_VSEL_MASK 0x3f 28 #define RK808_BUCK4_VSEL_MASK 0xf 29 #define RK808_LDO_VSEL_MASK 0x1f 30 31 #define RK809_BUCK5_VSEL_MASK 0x7 32 33 #define RK817_LDO_VSEL_MASK 0x7f 34 #define RK817_BOOST_VSEL_MASK 0x7 35 #define RK817_BUCK_VSEL_MASK 0x7f 36 37 #define RK818_BUCK_VSEL_MASK 0x3f 38 #define RK818_BUCK4_VSEL_MASK 0x1f 39 #define RK818_LDO_VSEL_MASK 0x1f 40 #define RK818_LDO3_ON_VSEL_MASK 0xf 41 #define RK818_BOOST_ON_VSEL_MASK 0xe0 42 43 #define RK806_DCDC_SLP_REG_OFFSET 0x0A 44 #define RK806_NLDO_SLP_REG_OFFSET 0x05 45 #define RK806_PLDO_SLP_REG_OFFSET 0x06 46 47 #define RK806_BUCK_SEL_CNT 0xff 48 #define RK806_LDO_SEL_CNT 0xff 49 50 /* Ramp rate definitions for buck1 / buck2 only */ 51 #define RK808_RAMP_RATE_OFFSET 3 52 #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET) 53 #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET) 54 #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET) 55 #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) 56 #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) 57 58 #define RK808_DVS2_POL BIT(2) 59 #define RK808_DVS1_POL BIT(1) 60 61 /* Offset from XXX_ON_VSEL to XXX_SLP_VSEL */ 62 #define RK808_SLP_REG_OFFSET 1 63 64 /* Offset from XXX_ON_VSEL to XXX_DVS_VSEL */ 65 #define RK808_DVS_REG_OFFSET 2 66 67 /* Offset from XXX_EN_REG to SLEEP_SET_OFF_XXX */ 68 #define RK808_SLP_SET_OFF_REG_OFFSET 2 69 70 /* max steps for increase voltage of Buck1/2, equal 100mv*/ 71 #define MAX_STEPS_ONE_TIME 8 72 73 #define ENABLE_MASK(id) (BIT(id) | BIT(4 + (id))) 74 #define DISABLE_VAL(id) (BIT(4 + (id))) 75 76 #define RK817_BOOST_DESC(_id, _match, _supply, _min, _max, _step, _vreg,\ 77 _vmask, _ereg, _emask, _enval, _disval, _etime, m_drop) \ 78 { \ 79 .name = (_match), \ 80 .supply_name = (_supply), \ 81 .of_match = of_match_ptr(_match), \ 82 .regulators_node = of_match_ptr("regulators"), \ 83 .type = REGULATOR_VOLTAGE, \ 84 .id = (_id), \ 85 .n_voltages = (((_max) - (_min)) / (_step) + 1), \ 86 .owner = THIS_MODULE, \ 87 .min_uV = (_min) * 1000, \ 88 .uV_step = (_step) * 1000, \ 89 .vsel_reg = (_vreg), \ 90 .vsel_mask = (_vmask), \ 91 .enable_reg = (_ereg), \ 92 .enable_mask = (_emask), \ 93 .enable_val = (_enval), \ 94 .disable_val = (_disval), \ 95 .enable_time = (_etime), \ 96 .min_dropout_uV = (m_drop) * 1000, \ 97 .ops = &rk817_boost_ops, \ 98 } 99 100 #define RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \ 101 _vmask, _ereg, _emask, _enval, _disval, _etime, _ops) \ 102 { \ 103 .name = (_match), \ 104 .supply_name = (_supply), \ 105 .of_match = of_match_ptr(_match), \ 106 .regulators_node = of_match_ptr("regulators"), \ 107 .type = REGULATOR_VOLTAGE, \ 108 .id = (_id), \ 109 .n_voltages = (((_max) - (_min)) / (_step) + 1), \ 110 .owner = THIS_MODULE, \ 111 .min_uV = (_min) * 1000, \ 112 .uV_step = (_step) * 1000, \ 113 .vsel_reg = (_vreg), \ 114 .vsel_mask = (_vmask), \ 115 .enable_reg = (_ereg), \ 116 .enable_mask = (_emask), \ 117 .enable_val = (_enval), \ 118 .disable_val = (_disval), \ 119 .enable_time = (_etime), \ 120 .ops = _ops, \ 121 } 122 123 #define RK805_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ 124 _vmask, _ereg, _emask, _etime) \ 125 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \ 126 _vmask, _ereg, _emask, 0, 0, _etime, &rk805_reg_ops) 127 128 #define RK806_REGULATOR(_name, _supply_name, _id, _ops,\ 129 _n_voltages, _vr, _er, _lr, ctrl_bit,\ 130 _rr, _rm, _rt)\ 131 [_id] = {\ 132 .name = _name,\ 133 .supply_name = _supply_name,\ 134 .of_match = of_match_ptr(_name),\ 135 .regulators_node = of_match_ptr("regulators"),\ 136 .id = _id,\ 137 .ops = &_ops,\ 138 .type = REGULATOR_VOLTAGE,\ 139 .n_voltages = _n_voltages,\ 140 .linear_ranges = _lr,\ 141 .n_linear_ranges = ARRAY_SIZE(_lr),\ 142 .vsel_reg = _vr,\ 143 .vsel_mask = 0xff,\ 144 .enable_reg = _er,\ 145 .enable_mask = ENABLE_MASK(ctrl_bit),\ 146 .enable_val = ENABLE_MASK(ctrl_bit),\ 147 .disable_val = DISABLE_VAL(ctrl_bit),\ 148 .of_map_mode = rk8xx_regulator_of_map_mode,\ 149 .ramp_reg = _rr,\ 150 .ramp_mask = _rm,\ 151 .ramp_delay_table = _rt, \ 152 .n_ramp_values = ARRAY_SIZE(_rt), \ 153 .owner = THIS_MODULE,\ 154 } 155 156 #define RK8XX_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ 157 _vmask, _ereg, _emask, _etime) \ 158 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \ 159 _vmask, _ereg, _emask, 0, 0, _etime, &rk808_reg_ops) 160 161 #define RK816_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ 162 _vmask, _ereg, _emask, _disval, _etime) \ 163 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \ 164 _vmask, _ereg, _emask, _emask, _disval, _etime, &rk816_reg_ops) 165 166 #define RK817_DESC(_id, _match, _supply, _min, _max, _step, _vreg, \ 167 _vmask, _ereg, _emask, _disval, _etime) \ 168 RK8XX_DESC_COM(_id, _match, _supply, _min, _max, _step, _vreg, \ 169 _vmask, _ereg, _emask, _emask, _disval, _etime, &rk817_reg_ops) 170 171 #define RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \ 172 _enval, _disval, _ops) \ 173 { \ 174 .name = (_match), \ 175 .supply_name = (_supply), \ 176 .of_match = of_match_ptr(_match), \ 177 .regulators_node = of_match_ptr("regulators"), \ 178 .type = REGULATOR_VOLTAGE, \ 179 .id = (_id), \ 180 .enable_reg = (_ereg), \ 181 .enable_mask = (_emask), \ 182 .enable_val = (_enval), \ 183 .disable_val = (_disval), \ 184 .owner = THIS_MODULE, \ 185 .ops = _ops \ 186 } 187 188 #define RK817_DESC_SWITCH(_id, _match, _supply, _ereg, _emask, \ 189 _disval) \ 190 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \ 191 _emask, _disval, &rk817_switch_ops) 192 193 #define RK8XX_DESC_SWITCH(_id, _match, _supply, _ereg, _emask) \ 194 RKXX_DESC_SWITCH_COM(_id, _match, _supply, _ereg, _emask, \ 195 0, 0, &rk808_switch_ops) 196 197 struct rk8xx_register_bit { 198 u8 reg; 199 u8 bit; 200 }; 201 202 #define RK8XX_REG_BIT(_reg, _bit) \ 203 { \ 204 .reg = _reg, \ 205 .bit = BIT(_bit), \ 206 } 207 208 struct rk808_regulator_data { 209 struct gpio_desc *dvs_gpio[2]; 210 }; 211 212 static const struct linear_range rk808_ldo3_voltage_ranges[] = { 213 REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), 214 REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), 215 }; 216 217 #define RK809_BUCK5_SEL_CNT (8) 218 219 static const struct linear_range rk809_buck5_voltage_ranges[] = { 220 REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0), 221 REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000), 222 REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000), 223 REGULATOR_LINEAR_RANGE(3300000, 6, 7, 300000), 224 }; 225 226 #define RK817_BUCK1_MIN0 500000 227 #define RK817_BUCK1_MAX0 1500000 228 229 #define RK817_BUCK1_MIN1 1600000 230 #define RK817_BUCK1_MAX1 2400000 231 232 #define RK817_BUCK3_MAX1 3400000 233 234 #define RK817_BUCK1_STP0 12500 235 #define RK817_BUCK1_STP1 100000 236 237 #define RK817_BUCK1_SEL0 ((RK817_BUCK1_MAX0 - RK817_BUCK1_MIN0) /\ 238 RK817_BUCK1_STP0) 239 #define RK817_BUCK1_SEL1 ((RK817_BUCK1_MAX1 - RK817_BUCK1_MIN1) /\ 240 RK817_BUCK1_STP1) 241 242 #define RK817_BUCK3_SEL1 ((RK817_BUCK3_MAX1 - RK817_BUCK1_MIN1) /\ 243 RK817_BUCK1_STP1) 244 245 #define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1) 246 #define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1) 247 248 static const struct linear_range rk817_buck1_voltage_ranges[] = { 249 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0, 250 RK817_BUCK1_SEL0, RK817_BUCK1_STP0), 251 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1, 252 RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1), 253 }; 254 255 static const struct linear_range rk817_buck3_voltage_ranges[] = { 256 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0, 257 RK817_BUCK1_SEL0, RK817_BUCK1_STP0), 258 REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1, 259 RK817_BUCK3_SEL_CNT, RK817_BUCK1_STP1), 260 }; 261 262 static const unsigned int rk808_buck1_2_ramp_table[] = { 263 2000, 4000, 6000, 10000 264 }; 265 266 /* RK817/RK809/RK816 (buck 1/2 only) */ 267 static const unsigned int rk817_buck1_4_ramp_table[] = { 268 3000, 6300, 12500, 25000 269 }; 270 271 static int rk806_set_mode_dcdc(struct regulator_dev *rdev, unsigned int mode) 272 { 273 int rid = rdev_get_id(rdev); 274 int ctr_bit, reg; 275 276 reg = RK806_POWER_FPWM_EN0 + rid / 8; 277 ctr_bit = rid % 8; 278 279 switch (mode) { 280 case REGULATOR_MODE_FAST: 281 return regmap_update_bits(rdev->regmap, reg, 282 PWM_MODE_MSK << ctr_bit, 283 FPWM_MODE << ctr_bit); 284 case REGULATOR_MODE_NORMAL: 285 return regmap_update_bits(rdev->regmap, reg, 286 PWM_MODE_MSK << ctr_bit, 287 AUTO_PWM_MODE << ctr_bit); 288 default: 289 dev_err(rdev_get_dev(rdev), "mode unsupported: %u\n", mode); 290 return -EINVAL; 291 } 292 293 return 0; 294 } 295 296 static unsigned int rk806_get_mode_dcdc(struct regulator_dev *rdev) 297 { 298 int rid = rdev_get_id(rdev); 299 int ctr_bit, reg; 300 unsigned int val; 301 int err; 302 303 reg = RK806_POWER_FPWM_EN0 + rid / 8; 304 ctr_bit = rid % 8; 305 306 err = regmap_read(rdev->regmap, reg, &val); 307 if (err) 308 return err; 309 310 if ((val >> ctr_bit) & FPWM_MODE) 311 return REGULATOR_MODE_FAST; 312 else 313 return REGULATOR_MODE_NORMAL; 314 } 315 316 static const struct rk8xx_register_bit rk806_dcdc_rate2[] = { 317 RK8XX_REG_BIT(0xEB, 0), 318 RK8XX_REG_BIT(0xEB, 1), 319 RK8XX_REG_BIT(0xEB, 2), 320 RK8XX_REG_BIT(0xEB, 3), 321 RK8XX_REG_BIT(0xEB, 4), 322 RK8XX_REG_BIT(0xEB, 5), 323 RK8XX_REG_BIT(0xEB, 6), 324 RK8XX_REG_BIT(0xEB, 7), 325 RK8XX_REG_BIT(0xEA, 0), 326 RK8XX_REG_BIT(0xEA, 1), 327 }; 328 329 static const unsigned int rk806_ramp_delay_table_dcdc[] = { 330 50000, 25000, 12500, 6250, 3125, 1560, 961, 390 331 }; 332 333 static int rk806_set_ramp_delay_dcdc(struct regulator_dev *rdev, int ramp_delay) 334 { 335 int rid = rdev_get_id(rdev); 336 int regval, ramp_value, ret; 337 338 ret = regulator_find_closest_bigger(ramp_delay, rdev->desc->ramp_delay_table, 339 rdev->desc->n_ramp_values, &ramp_value); 340 if (ret) { 341 dev_warn(rdev_get_dev(rdev), 342 "Can't set ramp-delay %u, setting %u\n", ramp_delay, 343 rdev->desc->ramp_delay_table[ramp_value]); 344 } 345 346 regval = ramp_value << (ffs(rdev->desc->ramp_mask) - 1); 347 348 ret = regmap_update_bits(rdev->regmap, rdev->desc->ramp_reg, 349 rdev->desc->ramp_mask, regval); 350 if (ret) 351 return ret; 352 353 /* 354 * The above is effectively a copy of regulator_set_ramp_delay_regmap(), 355 * but that only stores the lower 2 bits for rk806 DCDC ramp. The MSB must 356 * be stored in a separate register, so this open codes the implementation 357 * to have access to the ramp_value. 358 */ 359 360 regval = (ramp_value >> 2) & 0x1 ? rk806_dcdc_rate2[rid].bit : 0; 361 return regmap_update_bits(rdev->regmap, rk806_dcdc_rate2[rid].reg, 362 rk806_dcdc_rate2[rid].bit, 363 regval); 364 } 365 366 static const unsigned int rk806_ramp_delay_table_ldo[] = { 367 100000, 50000, 25000, 12500, 6280, 3120, 1900, 780 368 }; 369 370 static int rk806_set_suspend_voltage_range(struct regulator_dev *rdev, int reg_offset, int uv) 371 { 372 int sel = regulator_map_voltage_linear_range(rdev, uv, uv); 373 unsigned int reg; 374 375 if (sel < 0) 376 return -EINVAL; 377 378 reg = rdev->desc->vsel_reg + reg_offset; 379 380 return regmap_update_bits(rdev->regmap, reg, rdev->desc->vsel_mask, sel); 381 } 382 383 static int rk806_set_suspend_voltage_range_dcdc(struct regulator_dev *rdev, int uv) 384 { 385 return rk806_set_suspend_voltage_range(rdev, RK806_DCDC_SLP_REG_OFFSET, uv); 386 } 387 388 static int rk806_set_suspend_voltage_range_nldo(struct regulator_dev *rdev, int uv) 389 { 390 return rk806_set_suspend_voltage_range(rdev, RK806_NLDO_SLP_REG_OFFSET, uv); 391 } 392 393 static int rk806_set_suspend_voltage_range_pldo(struct regulator_dev *rdev, int uv) 394 { 395 return rk806_set_suspend_voltage_range(rdev, RK806_PLDO_SLP_REG_OFFSET, uv); 396 } 397 398 static int rk808_buck1_2_get_voltage_sel_regmap(struct regulator_dev *rdev) 399 { 400 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 401 int id = rdev_get_id(rdev); 402 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 403 unsigned int val; 404 int ret; 405 406 if (!gpio || gpiod_get_value(gpio) == 0) 407 return regulator_get_voltage_sel_regmap(rdev); 408 409 ret = regmap_read(rdev->regmap, 410 rdev->desc->vsel_reg + RK808_DVS_REG_OFFSET, 411 &val); 412 if (ret != 0) 413 return ret; 414 415 val &= rdev->desc->vsel_mask; 416 val >>= ffs(rdev->desc->vsel_mask) - 1; 417 418 return val; 419 } 420 421 static int rk808_buck1_2_i2c_set_voltage_sel(struct regulator_dev *rdev, 422 unsigned sel) 423 { 424 int ret, delta_sel; 425 unsigned int old_sel, tmp, val, mask = rdev->desc->vsel_mask; 426 427 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); 428 if (ret != 0) 429 return ret; 430 431 tmp = val & ~mask; 432 old_sel = val & mask; 433 old_sel >>= ffs(mask) - 1; 434 delta_sel = sel - old_sel; 435 436 /* 437 * If directly modify the register to change the voltage, we will face 438 * the risk of overshoot. Put it into a multi-step, can effectively 439 * avoid this problem, a step is 100mv here. 440 */ 441 while (delta_sel > MAX_STEPS_ONE_TIME) { 442 old_sel += MAX_STEPS_ONE_TIME; 443 val = old_sel << (ffs(mask) - 1); 444 val |= tmp; 445 446 /* 447 * i2c is 400kHz (2.5us per bit) and we must transmit _at least_ 448 * 3 bytes (24 bits) plus start and stop so 26 bits. So we've 449 * got more than 65 us between each voltage change and thus 450 * won't ramp faster than ~1500 uV / us. 451 */ 452 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); 453 delta_sel = sel - old_sel; 454 } 455 456 sel <<= ffs(mask) - 1; 457 val = tmp | sel; 458 ret = regmap_write(rdev->regmap, rdev->desc->vsel_reg, val); 459 460 /* 461 * When we change the voltage register directly, the ramp rate is about 462 * 100000uv/us, wait 1us to make sure the target voltage to be stable, 463 * so we needn't wait extra time after that. 464 */ 465 udelay(1); 466 467 return ret; 468 } 469 470 static int rk808_buck1_2_set_voltage_sel(struct regulator_dev *rdev, 471 unsigned sel) 472 { 473 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 474 int id = rdev_get_id(rdev); 475 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 476 unsigned int reg = rdev->desc->vsel_reg; 477 unsigned old_sel; 478 int ret, gpio_level; 479 480 if (!gpio) 481 return rk808_buck1_2_i2c_set_voltage_sel(rdev, sel); 482 483 gpio_level = gpiod_get_value(gpio); 484 if (gpio_level == 0) { 485 reg += RK808_DVS_REG_OFFSET; 486 ret = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &old_sel); 487 } else { 488 ret = regmap_read(rdev->regmap, 489 reg + RK808_DVS_REG_OFFSET, 490 &old_sel); 491 } 492 493 if (ret != 0) 494 return ret; 495 496 sel <<= ffs(rdev->desc->vsel_mask) - 1; 497 sel |= old_sel & ~rdev->desc->vsel_mask; 498 499 ret = regmap_write(rdev->regmap, reg, sel); 500 if (ret) 501 return ret; 502 503 gpiod_set_value(gpio, !gpio_level); 504 505 return ret; 506 } 507 508 static int rk808_buck1_2_set_voltage_time_sel(struct regulator_dev *rdev, 509 unsigned int old_selector, 510 unsigned int new_selector) 511 { 512 struct rk808_regulator_data *pdata = rdev_get_drvdata(rdev); 513 int id = rdev_get_id(rdev); 514 struct gpio_desc *gpio = pdata->dvs_gpio[id]; 515 516 /* if there is no dvs1/2 pin, we don't need wait extra time here. */ 517 if (!gpio) 518 return 0; 519 520 return regulator_set_voltage_time_sel(rdev, old_selector, new_selector); 521 } 522 523 static int rk808_set_suspend_voltage(struct regulator_dev *rdev, int uv) 524 { 525 unsigned int reg; 526 int sel = regulator_map_voltage_linear(rdev, uv, uv); 527 528 if (sel < 0) 529 return -EINVAL; 530 531 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; 532 533 return regmap_update_bits(rdev->regmap, reg, 534 rdev->desc->vsel_mask, 535 sel); 536 } 537 538 static int rk808_set_suspend_voltage_range(struct regulator_dev *rdev, int uv) 539 { 540 unsigned int reg; 541 int sel = regulator_map_voltage_linear_range(rdev, uv, uv); 542 int ret; 543 544 if (sel < 0) 545 return -EINVAL; 546 547 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; 548 549 ret = regmap_update_bits(rdev->regmap, reg, 550 rdev->desc->vsel_mask, 551 sel); 552 if (ret) 553 return ret; 554 555 if (rdev->desc->apply_bit) 556 ret = regmap_update_bits(rdev->regmap, rdev->desc->apply_reg, 557 rdev->desc->apply_bit, 558 rdev->desc->apply_bit); 559 560 return ret; 561 } 562 563 static int rk805_set_suspend_enable(struct regulator_dev *rdev) 564 { 565 unsigned int reg; 566 567 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 568 569 return regmap_update_bits(rdev->regmap, reg, 570 rdev->desc->enable_mask, 571 rdev->desc->enable_mask); 572 } 573 574 static int rk805_set_suspend_disable(struct regulator_dev *rdev) 575 { 576 unsigned int reg; 577 578 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 579 580 return regmap_update_bits(rdev->regmap, reg, 581 rdev->desc->enable_mask, 582 0); 583 } 584 585 static const struct rk8xx_register_bit rk806_suspend_bits[] = { 586 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 0), 587 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 1), 588 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 2), 589 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 3), 590 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 4), 591 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 5), 592 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 6), 593 RK8XX_REG_BIT(RK806_POWER_SLP_EN0, 7), 594 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 6), 595 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 7), 596 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 0), 597 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 1), 598 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 2), 599 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 3), 600 RK8XX_REG_BIT(RK806_POWER_SLP_EN1, 4), 601 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 1), 602 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 2), 603 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 3), 604 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 4), 605 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 5), 606 RK8XX_REG_BIT(RK806_POWER_SLP_EN2, 0), 607 }; 608 609 static int rk806_set_suspend_enable(struct regulator_dev *rdev) 610 { 611 int rid = rdev_get_id(rdev); 612 613 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg, 614 rk806_suspend_bits[rid].bit, 615 rk806_suspend_bits[rid].bit); 616 } 617 618 static int rk806_set_suspend_disable(struct regulator_dev *rdev) 619 { 620 int rid = rdev_get_id(rdev); 621 622 return regmap_update_bits(rdev->regmap, rk806_suspend_bits[rid].reg, 623 rk806_suspend_bits[rid].bit, 0); 624 } 625 626 static int rk808_set_suspend_enable(struct regulator_dev *rdev) 627 { 628 unsigned int reg; 629 630 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 631 632 return regmap_update_bits(rdev->regmap, reg, 633 rdev->desc->enable_mask, 634 0); 635 } 636 637 static int rk808_set_suspend_disable(struct regulator_dev *rdev) 638 { 639 unsigned int reg; 640 641 reg = rdev->desc->enable_reg + RK808_SLP_SET_OFF_REG_OFFSET; 642 643 return regmap_update_bits(rdev->regmap, reg, 644 rdev->desc->enable_mask, 645 rdev->desc->enable_mask); 646 } 647 648 static const struct rk8xx_register_bit rk816_suspend_bits[] = { 649 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 0), 650 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 1), 651 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 2), 652 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 3), 653 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 0), 654 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 1), 655 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 2), 656 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 3), 657 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 4), 658 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG2, 5), 659 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 5), 660 RK8XX_REG_BIT(RK818_SLEEP_SET_OFF_REG1, 6), 661 }; 662 663 static int rk816_set_suspend_enable(struct regulator_dev *rdev) 664 { 665 int rid = rdev_get_id(rdev); 666 667 return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg, 668 rk816_suspend_bits[rid].bit, 669 rk816_suspend_bits[rid].bit); 670 } 671 672 static int rk816_set_suspend_disable(struct regulator_dev *rdev) 673 { 674 int rid = rdev_get_id(rdev); 675 676 return regmap_update_bits(rdev->regmap, rk816_suspend_bits[rid].reg, 677 rk816_suspend_bits[rid].bit, 0); 678 } 679 680 static int rk817_set_suspend_enable_ctrl(struct regulator_dev *rdev, 681 unsigned int en) 682 { 683 unsigned int reg; 684 int id = rdev_get_id(rdev); 685 unsigned int id_slp, msk, val; 686 687 if (id >= RK817_ID_DCDC1 && id <= RK817_ID_DCDC4) 688 id_slp = id; 689 else if (id >= RK817_ID_LDO1 && id <= RK817_ID_LDO8) 690 id_slp = 8 + (id - RK817_ID_LDO1); 691 else if (id >= RK817_ID_LDO9 && id <= RK809_ID_SW2) 692 id_slp = 4 + (id - RK817_ID_LDO9); 693 else 694 return -EINVAL; 695 696 reg = RK817_POWER_SLP_EN_REG(id_slp / 8); 697 698 msk = BIT(id_slp % 8); 699 if (en) 700 val = msk; 701 else 702 val = 0; 703 704 return regmap_update_bits(rdev->regmap, reg, msk, val); 705 } 706 707 static int rk817_set_suspend_enable(struct regulator_dev *rdev) 708 { 709 return rk817_set_suspend_enable_ctrl(rdev, 1); 710 } 711 712 static int rk817_set_suspend_disable(struct regulator_dev *rdev) 713 { 714 return rk817_set_suspend_enable_ctrl(rdev, 0); 715 } 716 717 static int rk8xx_set_suspend_mode(struct regulator_dev *rdev, unsigned int mode) 718 { 719 unsigned int reg; 720 721 reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; 722 723 switch (mode) { 724 case REGULATOR_MODE_FAST: 725 return regmap_update_bits(rdev->regmap, reg, 726 PWM_MODE_MSK, FPWM_MODE); 727 case REGULATOR_MODE_NORMAL: 728 return regmap_update_bits(rdev->regmap, reg, 729 PWM_MODE_MSK, AUTO_PWM_MODE); 730 default: 731 dev_err(&rdev->dev, "do not support this mode\n"); 732 return -EINVAL; 733 } 734 735 return 0; 736 } 737 738 static int rk8xx_set_mode(struct regulator_dev *rdev, unsigned int mode) 739 { 740 switch (mode) { 741 case REGULATOR_MODE_FAST: 742 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg, 743 PWM_MODE_MSK, FPWM_MODE); 744 case REGULATOR_MODE_NORMAL: 745 return regmap_update_bits(rdev->regmap, rdev->desc->vsel_reg, 746 PWM_MODE_MSK, AUTO_PWM_MODE); 747 default: 748 dev_err(&rdev->dev, "do not support this mode\n"); 749 return -EINVAL; 750 } 751 752 return 0; 753 } 754 755 static unsigned int rk8xx_get_mode(struct regulator_dev *rdev) 756 { 757 unsigned int val; 758 int err; 759 760 err = regmap_read(rdev->regmap, rdev->desc->vsel_reg, &val); 761 if (err) 762 return err; 763 764 if (val & FPWM_MODE) 765 return REGULATOR_MODE_FAST; 766 else 767 return REGULATOR_MODE_NORMAL; 768 } 769 770 static int rk8xx_is_enabled_wmsk_regmap(struct regulator_dev *rdev) 771 { 772 unsigned int val; 773 int ret; 774 775 ret = regmap_read(rdev->regmap, rdev->desc->enable_reg, &val); 776 if (ret != 0) 777 return ret; 778 779 /* add write mask bit */ 780 val |= (rdev->desc->enable_mask & 0xf0); 781 val &= rdev->desc->enable_mask; 782 783 if (rdev->desc->enable_is_inverted) { 784 if (rdev->desc->enable_val) 785 return val != rdev->desc->enable_val; 786 return (val == 0); 787 } 788 if (rdev->desc->enable_val) 789 return val == rdev->desc->enable_val; 790 return val != 0; 791 } 792 793 static unsigned int rk8xx_regulator_of_map_mode(unsigned int mode) 794 { 795 switch (mode) { 796 case 1: 797 return REGULATOR_MODE_FAST; 798 case 2: 799 return REGULATOR_MODE_NORMAL; 800 default: 801 return REGULATOR_MODE_INVALID; 802 } 803 } 804 805 static const struct regulator_ops rk805_reg_ops = { 806 .list_voltage = regulator_list_voltage_linear, 807 .map_voltage = regulator_map_voltage_linear, 808 .get_voltage_sel = regulator_get_voltage_sel_regmap, 809 .set_voltage_sel = regulator_set_voltage_sel_regmap, 810 .enable = regulator_enable_regmap, 811 .disable = regulator_disable_regmap, 812 .is_enabled = regulator_is_enabled_regmap, 813 .set_suspend_voltage = rk808_set_suspend_voltage, 814 .set_suspend_enable = rk805_set_suspend_enable, 815 .set_suspend_disable = rk805_set_suspend_disable, 816 }; 817 818 static const struct regulator_ops rk805_switch_ops = { 819 .enable = regulator_enable_regmap, 820 .disable = regulator_disable_regmap, 821 .is_enabled = regulator_is_enabled_regmap, 822 .set_suspend_enable = rk805_set_suspend_enable, 823 .set_suspend_disable = rk805_set_suspend_disable, 824 }; 825 826 static const struct regulator_ops rk806_ops_dcdc = { 827 .list_voltage = regulator_list_voltage_linear_range, 828 .map_voltage = regulator_map_voltage_linear_range, 829 .get_voltage_sel = regulator_get_voltage_sel_regmap, 830 .set_voltage_sel = regulator_set_voltage_sel_regmap, 831 .set_voltage_time_sel = regulator_set_voltage_time_sel, 832 .set_mode = rk806_set_mode_dcdc, 833 .get_mode = rk806_get_mode_dcdc, 834 835 .enable = regulator_enable_regmap, 836 .disable = regulator_disable_regmap, 837 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 838 839 .set_suspend_mode = rk806_set_mode_dcdc, 840 .set_ramp_delay = rk806_set_ramp_delay_dcdc, 841 842 .set_suspend_voltage = rk806_set_suspend_voltage_range_dcdc, 843 .set_suspend_enable = rk806_set_suspend_enable, 844 .set_suspend_disable = rk806_set_suspend_disable, 845 }; 846 847 static const struct regulator_ops rk806_ops_nldo = { 848 .list_voltage = regulator_list_voltage_linear_range, 849 .map_voltage = regulator_map_voltage_linear_range, 850 .get_voltage_sel = regulator_get_voltage_sel_regmap, 851 .set_voltage_sel = regulator_set_voltage_sel_regmap, 852 .set_voltage_time_sel = regulator_set_voltage_time_sel, 853 854 .enable = regulator_enable_regmap, 855 .disable = regulator_disable_regmap, 856 .is_enabled = regulator_is_enabled_regmap, 857 858 .set_ramp_delay = regulator_set_ramp_delay_regmap, 859 860 .set_suspend_voltage = rk806_set_suspend_voltage_range_nldo, 861 .set_suspend_enable = rk806_set_suspend_enable, 862 .set_suspend_disable = rk806_set_suspend_disable, 863 }; 864 865 static const struct regulator_ops rk806_ops_pldo = { 866 .list_voltage = regulator_list_voltage_linear_range, 867 .map_voltage = regulator_map_voltage_linear_range, 868 869 .get_voltage_sel = regulator_get_voltage_sel_regmap, 870 .set_voltage_sel = regulator_set_voltage_sel_regmap, 871 .set_voltage_time_sel = regulator_set_voltage_time_sel, 872 873 .enable = regulator_enable_regmap, 874 .disable = regulator_disable_regmap, 875 .is_enabled = regulator_is_enabled_regmap, 876 877 .set_ramp_delay = regulator_set_ramp_delay_regmap, 878 879 .set_suspend_voltage = rk806_set_suspend_voltage_range_pldo, 880 .set_suspend_enable = rk806_set_suspend_enable, 881 .set_suspend_disable = rk806_set_suspend_disable, 882 }; 883 884 static const struct regulator_ops rk808_buck1_2_ops = { 885 .list_voltage = regulator_list_voltage_linear, 886 .map_voltage = regulator_map_voltage_linear, 887 .get_voltage_sel = rk808_buck1_2_get_voltage_sel_regmap, 888 .set_voltage_sel = rk808_buck1_2_set_voltage_sel, 889 .set_voltage_time_sel = rk808_buck1_2_set_voltage_time_sel, 890 .enable = regulator_enable_regmap, 891 .disable = regulator_disable_regmap, 892 .is_enabled = regulator_is_enabled_regmap, 893 .set_ramp_delay = regulator_set_ramp_delay_regmap, 894 .set_suspend_voltage = rk808_set_suspend_voltage, 895 .set_suspend_enable = rk808_set_suspend_enable, 896 .set_suspend_disable = rk808_set_suspend_disable, 897 }; 898 899 static const struct regulator_ops rk808_reg_ops = { 900 .list_voltage = regulator_list_voltage_linear, 901 .map_voltage = regulator_map_voltage_linear, 902 .get_voltage_sel = regulator_get_voltage_sel_regmap, 903 .set_voltage_sel = regulator_set_voltage_sel_regmap, 904 .enable = regulator_enable_regmap, 905 .disable = regulator_disable_regmap, 906 .is_enabled = regulator_is_enabled_regmap, 907 .set_suspend_voltage = rk808_set_suspend_voltage, 908 .set_suspend_enable = rk808_set_suspend_enable, 909 .set_suspend_disable = rk808_set_suspend_disable, 910 }; 911 912 static const struct regulator_ops rk808_reg_ops_ranges = { 913 .list_voltage = regulator_list_voltage_linear_range, 914 .map_voltage = regulator_map_voltage_linear_range, 915 .get_voltage_sel = regulator_get_voltage_sel_regmap, 916 .set_voltage_sel = regulator_set_voltage_sel_regmap, 917 .enable = regulator_enable_regmap, 918 .disable = regulator_disable_regmap, 919 .is_enabled = regulator_is_enabled_regmap, 920 .set_suspend_voltage = rk808_set_suspend_voltage_range, 921 .set_suspend_enable = rk808_set_suspend_enable, 922 .set_suspend_disable = rk808_set_suspend_disable, 923 }; 924 925 static const struct regulator_ops rk808_switch_ops = { 926 .enable = regulator_enable_regmap, 927 .disable = regulator_disable_regmap, 928 .is_enabled = regulator_is_enabled_regmap, 929 .set_suspend_enable = rk808_set_suspend_enable, 930 .set_suspend_disable = rk808_set_suspend_disable, 931 }; 932 933 static const struct linear_range rk805_buck_1_2_voltage_ranges[] = { 934 REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500), 935 REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000), 936 REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0), 937 }; 938 939 static const struct regulator_ops rk809_buck5_ops_range = { 940 .list_voltage = regulator_list_voltage_linear_range, 941 .map_voltage = regulator_map_voltage_linear_range, 942 .get_voltage_sel = regulator_get_voltage_sel_regmap, 943 .set_voltage_sel = regulator_set_voltage_sel_regmap, 944 .set_voltage_time_sel = regulator_set_voltage_time_sel, 945 .enable = regulator_enable_regmap, 946 .disable = regulator_disable_regmap, 947 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 948 .set_suspend_voltage = rk808_set_suspend_voltage_range, 949 .set_suspend_enable = rk817_set_suspend_enable, 950 .set_suspend_disable = rk817_set_suspend_disable, 951 }; 952 953 static const struct regulator_ops rk816_buck1_2_ops_ranges = { 954 .list_voltage = regulator_list_voltage_linear_range, 955 .map_voltage = regulator_map_voltage_linear_range, 956 .get_voltage_sel = regulator_get_voltage_sel_regmap, 957 .set_voltage_sel = regulator_set_voltage_sel_regmap, 958 .set_voltage_time_sel = regulator_set_voltage_time_sel, 959 .enable = regulator_enable_regmap, 960 .disable = regulator_disable_regmap, 961 .is_enabled = regulator_is_enabled_regmap, 962 .set_mode = rk8xx_set_mode, 963 .get_mode = rk8xx_get_mode, 964 .set_suspend_mode = rk8xx_set_suspend_mode, 965 .set_ramp_delay = regulator_set_ramp_delay_regmap, 966 .set_suspend_voltage = rk808_set_suspend_voltage_range, 967 .set_suspend_enable = rk816_set_suspend_enable, 968 .set_suspend_disable = rk816_set_suspend_disable, 969 }; 970 971 static const struct regulator_ops rk816_buck4_ops_ranges = { 972 .list_voltage = regulator_list_voltage_linear_range, 973 .map_voltage = regulator_map_voltage_linear_range, 974 .get_voltage_sel = regulator_get_voltage_sel_regmap, 975 .set_voltage_sel = regulator_set_voltage_sel_regmap, 976 .set_voltage_time_sel = regulator_set_voltage_time_sel, 977 .enable = regulator_enable_regmap, 978 .disable = regulator_disable_regmap, 979 .is_enabled = regulator_is_enabled_regmap, 980 .set_mode = rk8xx_set_mode, 981 .get_mode = rk8xx_get_mode, 982 .set_suspend_mode = rk8xx_set_suspend_mode, 983 .set_suspend_voltage = rk808_set_suspend_voltage_range, 984 .set_suspend_enable = rk816_set_suspend_enable, 985 .set_suspend_disable = rk816_set_suspend_disable, 986 }; 987 988 static const struct regulator_ops rk816_reg_ops = { 989 .list_voltage = regulator_list_voltage_linear, 990 .map_voltage = regulator_map_voltage_linear, 991 .get_voltage_sel = regulator_get_voltage_sel_regmap, 992 .set_voltage_sel = regulator_set_voltage_sel_regmap, 993 .enable = regulator_enable_regmap, 994 .disable = regulator_disable_regmap, 995 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 996 .set_suspend_voltage = rk808_set_suspend_voltage, 997 .set_suspend_enable = rk816_set_suspend_enable, 998 .set_suspend_disable = rk816_set_suspend_disable, 999 }; 1000 1001 static const struct regulator_ops rk817_reg_ops = { 1002 .list_voltage = regulator_list_voltage_linear, 1003 .map_voltage = regulator_map_voltage_linear, 1004 .get_voltage_sel = regulator_get_voltage_sel_regmap, 1005 .set_voltage_sel = regulator_set_voltage_sel_regmap, 1006 .enable = regulator_enable_regmap, 1007 .disable = regulator_disable_regmap, 1008 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 1009 .set_suspend_voltage = rk808_set_suspend_voltage, 1010 .set_suspend_enable = rk817_set_suspend_enable, 1011 .set_suspend_disable = rk817_set_suspend_disable, 1012 }; 1013 1014 static const struct regulator_ops rk817_boost_ops = { 1015 .list_voltage = regulator_list_voltage_linear, 1016 .map_voltage = regulator_map_voltage_linear, 1017 .get_voltage_sel = regulator_get_voltage_sel_regmap, 1018 .set_voltage_sel = regulator_set_voltage_sel_regmap, 1019 .enable = regulator_enable_regmap, 1020 .disable = regulator_disable_regmap, 1021 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 1022 .set_suspend_enable = rk817_set_suspend_enable, 1023 .set_suspend_disable = rk817_set_suspend_disable, 1024 }; 1025 1026 static const struct regulator_ops rk817_buck_ops_range = { 1027 .list_voltage = regulator_list_voltage_linear_range, 1028 .map_voltage = regulator_map_voltage_linear_range, 1029 .get_voltage_sel = regulator_get_voltage_sel_regmap, 1030 .set_voltage_sel = regulator_set_voltage_sel_regmap, 1031 .set_voltage_time_sel = regulator_set_voltage_time_sel, 1032 .enable = regulator_enable_regmap, 1033 .disable = regulator_disable_regmap, 1034 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 1035 .set_mode = rk8xx_set_mode, 1036 .get_mode = rk8xx_get_mode, 1037 .set_suspend_mode = rk8xx_set_suspend_mode, 1038 .set_ramp_delay = regulator_set_ramp_delay_regmap, 1039 .set_suspend_voltage = rk808_set_suspend_voltage_range, 1040 .set_suspend_enable = rk817_set_suspend_enable, 1041 .set_suspend_disable = rk817_set_suspend_disable, 1042 }; 1043 1044 static const struct regulator_ops rk817_switch_ops = { 1045 .enable = regulator_enable_regmap, 1046 .disable = regulator_disable_regmap, 1047 .is_enabled = rk8xx_is_enabled_wmsk_regmap, 1048 .set_suspend_enable = rk817_set_suspend_enable, 1049 .set_suspend_disable = rk817_set_suspend_disable, 1050 }; 1051 1052 static const struct regulator_desc rk805_reg[] = { 1053 { 1054 .name = "DCDC_REG1", 1055 .supply_name = "vcc1", 1056 .of_match = of_match_ptr("DCDC_REG1"), 1057 .regulators_node = of_match_ptr("regulators"), 1058 .id = RK805_ID_DCDC1, 1059 .ops = &rk808_reg_ops_ranges, 1060 .type = REGULATOR_VOLTAGE, 1061 .n_voltages = 64, 1062 .linear_ranges = rk805_buck_1_2_voltage_ranges, 1063 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges), 1064 .vsel_reg = RK805_BUCK1_ON_VSEL_REG, 1065 .vsel_mask = RK818_BUCK_VSEL_MASK, 1066 .enable_reg = RK805_DCDC_EN_REG, 1067 .enable_mask = BIT(0), 1068 .owner = THIS_MODULE, 1069 }, { 1070 .name = "DCDC_REG2", 1071 .supply_name = "vcc2", 1072 .of_match = of_match_ptr("DCDC_REG2"), 1073 .regulators_node = of_match_ptr("regulators"), 1074 .id = RK805_ID_DCDC2, 1075 .ops = &rk808_reg_ops_ranges, 1076 .type = REGULATOR_VOLTAGE, 1077 .n_voltages = 64, 1078 .linear_ranges = rk805_buck_1_2_voltage_ranges, 1079 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges), 1080 .vsel_reg = RK805_BUCK2_ON_VSEL_REG, 1081 .vsel_mask = RK818_BUCK_VSEL_MASK, 1082 .enable_reg = RK805_DCDC_EN_REG, 1083 .enable_mask = BIT(1), 1084 .owner = THIS_MODULE, 1085 }, { 1086 .name = "DCDC_REG3", 1087 .supply_name = "vcc3", 1088 .of_match = of_match_ptr("DCDC_REG3"), 1089 .regulators_node = of_match_ptr("regulators"), 1090 .id = RK805_ID_DCDC3, 1091 .ops = &rk805_switch_ops, 1092 .type = REGULATOR_VOLTAGE, 1093 .n_voltages = 1, 1094 .enable_reg = RK805_DCDC_EN_REG, 1095 .enable_mask = BIT(2), 1096 .owner = THIS_MODULE, 1097 }, 1098 1099 RK805_DESC(RK805_ID_DCDC4, "DCDC_REG4", "vcc4", 800, 3400, 100, 1100 RK805_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK, 1101 RK805_DCDC_EN_REG, BIT(3), 0), 1102 1103 RK805_DESC(RK805_ID_LDO1, "LDO_REG1", "vcc5", 800, 3400, 100, 1104 RK805_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, 1105 BIT(0), 400), 1106 RK805_DESC(RK805_ID_LDO2, "LDO_REG2", "vcc5", 800, 3400, 100, 1107 RK805_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, 1108 BIT(1), 400), 1109 RK805_DESC(RK805_ID_LDO3, "LDO_REG3", "vcc6", 800, 3400, 100, 1110 RK805_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK805_LDO_EN_REG, 1111 BIT(2), 400), 1112 }; 1113 1114 static const struct linear_range rk806_buck_voltage_ranges[] = { 1115 REGULATOR_LINEAR_RANGE(500000, 0, 159, 6250), /* 500mV ~ 1500mV */ 1116 REGULATOR_LINEAR_RANGE(1500000, 160, 235, 25000), /* 1500mV ~ 3400mV */ 1117 REGULATOR_LINEAR_RANGE(3400000, 236, 255, 0), 1118 }; 1119 1120 static const struct linear_range rk806_ldo_voltage_ranges[] = { 1121 REGULATOR_LINEAR_RANGE(500000, 0, 231, 12500), /* 500mV ~ 3400mV */ 1122 REGULATOR_LINEAR_RANGE(3400000, 232, 255, 0), 1123 }; 1124 1125 static const struct regulator_desc rk806_reg[] = { 1126 RK806_REGULATOR("dcdc-reg1", "vcc1", RK806_ID_DCDC1, rk806_ops_dcdc, 1127 RK806_BUCK_SEL_CNT, RK806_BUCK1_ON_VSEL, 1128 RK806_POWER_EN0, rk806_buck_voltage_ranges, 0, 1129 RK806_BUCK1_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1130 RK806_REGULATOR("dcdc-reg2", "vcc2", RK806_ID_DCDC2, rk806_ops_dcdc, 1131 RK806_BUCK_SEL_CNT, RK806_BUCK2_ON_VSEL, 1132 RK806_POWER_EN0, rk806_buck_voltage_ranges, 1, 1133 RK806_BUCK2_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1134 RK806_REGULATOR("dcdc-reg3", "vcc3", RK806_ID_DCDC3, rk806_ops_dcdc, 1135 RK806_BUCK_SEL_CNT, RK806_BUCK3_ON_VSEL, 1136 RK806_POWER_EN0, rk806_buck_voltage_ranges, 2, 1137 RK806_BUCK3_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1138 RK806_REGULATOR("dcdc-reg4", "vcc4", RK806_ID_DCDC4, rk806_ops_dcdc, 1139 RK806_BUCK_SEL_CNT, RK806_BUCK4_ON_VSEL, 1140 RK806_POWER_EN0, rk806_buck_voltage_ranges, 3, 1141 RK806_BUCK4_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1142 1143 RK806_REGULATOR("dcdc-reg5", "vcc5", RK806_ID_DCDC5, rk806_ops_dcdc, 1144 RK806_BUCK_SEL_CNT, RK806_BUCK5_ON_VSEL, 1145 RK806_POWER_EN1, rk806_buck_voltage_ranges, 0, 1146 RK806_BUCK5_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1147 RK806_REGULATOR("dcdc-reg6", "vcc6", RK806_ID_DCDC6, rk806_ops_dcdc, 1148 RK806_BUCK_SEL_CNT, RK806_BUCK6_ON_VSEL, 1149 RK806_POWER_EN1, rk806_buck_voltage_ranges, 1, 1150 RK806_BUCK6_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1151 RK806_REGULATOR("dcdc-reg7", "vcc7", RK806_ID_DCDC7, rk806_ops_dcdc, 1152 RK806_BUCK_SEL_CNT, RK806_BUCK7_ON_VSEL, 1153 RK806_POWER_EN1, rk806_buck_voltage_ranges, 2, 1154 RK806_BUCK7_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1155 RK806_REGULATOR("dcdc-reg8", "vcc8", RK806_ID_DCDC8, rk806_ops_dcdc, 1156 RK806_BUCK_SEL_CNT, RK806_BUCK8_ON_VSEL, 1157 RK806_POWER_EN1, rk806_buck_voltage_ranges, 3, 1158 RK806_BUCK8_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1159 1160 RK806_REGULATOR("dcdc-reg9", "vcc9", RK806_ID_DCDC9, rk806_ops_dcdc, 1161 RK806_BUCK_SEL_CNT, RK806_BUCK9_ON_VSEL, 1162 RK806_POWER_EN2, rk806_buck_voltage_ranges, 0, 1163 RK806_BUCK9_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1164 RK806_REGULATOR("dcdc-reg10", "vcc10", RK806_ID_DCDC10, rk806_ops_dcdc, 1165 RK806_BUCK_SEL_CNT, RK806_BUCK10_ON_VSEL, 1166 RK806_POWER_EN2, rk806_buck_voltage_ranges, 1, 1167 RK806_BUCK10_CONFIG, 0xc0, rk806_ramp_delay_table_dcdc), 1168 1169 RK806_REGULATOR("nldo-reg1", "vcc13", RK806_ID_NLDO1, rk806_ops_nldo, 1170 RK806_LDO_SEL_CNT, RK806_NLDO1_ON_VSEL, 1171 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 0, 1172 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1173 RK806_REGULATOR("nldo-reg2", "vcc13", RK806_ID_NLDO2, rk806_ops_nldo, 1174 RK806_LDO_SEL_CNT, RK806_NLDO2_ON_VSEL, 1175 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 1, 1176 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1177 RK806_REGULATOR("nldo-reg3", "vcc13", RK806_ID_NLDO3, rk806_ops_nldo, 1178 RK806_LDO_SEL_CNT, RK806_NLDO3_ON_VSEL, 1179 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 2, 1180 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1181 RK806_REGULATOR("nldo-reg4", "vcc14", RK806_ID_NLDO4, rk806_ops_nldo, 1182 RK806_LDO_SEL_CNT, RK806_NLDO4_ON_VSEL, 1183 RK806_POWER_EN3, rk806_ldo_voltage_ranges, 3, 1184 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1185 1186 RK806_REGULATOR("nldo-reg5", "vcc14", RK806_ID_NLDO5, rk806_ops_nldo, 1187 RK806_LDO_SEL_CNT, RK806_NLDO5_ON_VSEL, 1188 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 2, 1189 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1190 1191 RK806_REGULATOR("pldo-reg1", "vcc11", RK806_ID_PLDO1, rk806_ops_pldo, 1192 RK806_LDO_SEL_CNT, RK806_PLDO1_ON_VSEL, 1193 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 1, 1194 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1195 RK806_REGULATOR("pldo-reg2", "vcc11", RK806_ID_PLDO2, rk806_ops_pldo, 1196 RK806_LDO_SEL_CNT, RK806_PLDO2_ON_VSEL, 1197 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 2, 1198 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1199 RK806_REGULATOR("pldo-reg3", "vcc11", RK806_ID_PLDO3, rk806_ops_pldo, 1200 RK806_LDO_SEL_CNT, RK806_PLDO3_ON_VSEL, 1201 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 3, 1202 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1203 1204 RK806_REGULATOR("pldo-reg4", "vcc12", RK806_ID_PLDO4, rk806_ops_pldo, 1205 RK806_LDO_SEL_CNT, RK806_PLDO4_ON_VSEL, 1206 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 0, 1207 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1208 RK806_REGULATOR("pldo-reg5", "vcc12", RK806_ID_PLDO5, rk806_ops_pldo, 1209 RK806_LDO_SEL_CNT, RK806_PLDO5_ON_VSEL, 1210 RK806_POWER_EN5, rk806_ldo_voltage_ranges, 1, 1211 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1212 1213 RK806_REGULATOR("pldo-reg6", "vcca", RK806_ID_PLDO6, rk806_ops_pldo, 1214 RK806_LDO_SEL_CNT, RK806_PLDO6_ON_VSEL, 1215 RK806_POWER_EN4, rk806_ldo_voltage_ranges, 0, 1216 0xEA, 0x38, rk806_ramp_delay_table_ldo), 1217 }; 1218 1219 1220 static const struct regulator_desc rk808_reg[] = { 1221 { 1222 .name = "DCDC_REG1", 1223 .supply_name = "vcc1", 1224 .of_match = of_match_ptr("DCDC_REG1"), 1225 .regulators_node = of_match_ptr("regulators"), 1226 .id = RK808_ID_DCDC1, 1227 .ops = &rk808_buck1_2_ops, 1228 .type = REGULATOR_VOLTAGE, 1229 .min_uV = 712500, 1230 .uV_step = 12500, 1231 .n_voltages = 64, 1232 .vsel_reg = RK808_BUCK1_ON_VSEL_REG, 1233 .vsel_mask = RK808_BUCK_VSEL_MASK, 1234 .enable_reg = RK808_DCDC_EN_REG, 1235 .enable_mask = BIT(0), 1236 .ramp_reg = RK808_BUCK1_CONFIG_REG, 1237 .ramp_mask = RK808_RAMP_RATE_MASK, 1238 .ramp_delay_table = rk808_buck1_2_ramp_table, 1239 .n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table), 1240 .owner = THIS_MODULE, 1241 }, { 1242 .name = "DCDC_REG2", 1243 .supply_name = "vcc2", 1244 .of_match = of_match_ptr("DCDC_REG2"), 1245 .regulators_node = of_match_ptr("regulators"), 1246 .id = RK808_ID_DCDC2, 1247 .ops = &rk808_buck1_2_ops, 1248 .type = REGULATOR_VOLTAGE, 1249 .min_uV = 712500, 1250 .uV_step = 12500, 1251 .n_voltages = 64, 1252 .vsel_reg = RK808_BUCK2_ON_VSEL_REG, 1253 .vsel_mask = RK808_BUCK_VSEL_MASK, 1254 .enable_reg = RK808_DCDC_EN_REG, 1255 .enable_mask = BIT(1), 1256 .ramp_reg = RK808_BUCK2_CONFIG_REG, 1257 .ramp_mask = RK808_RAMP_RATE_MASK, 1258 .ramp_delay_table = rk808_buck1_2_ramp_table, 1259 .n_ramp_values = ARRAY_SIZE(rk808_buck1_2_ramp_table), 1260 .owner = THIS_MODULE, 1261 }, { 1262 .name = "DCDC_REG3", 1263 .supply_name = "vcc3", 1264 .of_match = of_match_ptr("DCDC_REG3"), 1265 .regulators_node = of_match_ptr("regulators"), 1266 .id = RK808_ID_DCDC3, 1267 .ops = &rk808_switch_ops, 1268 .type = REGULATOR_VOLTAGE, 1269 .n_voltages = 1, 1270 .enable_reg = RK808_DCDC_EN_REG, 1271 .enable_mask = BIT(2), 1272 .owner = THIS_MODULE, 1273 }, 1274 RK8XX_DESC(RK808_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3300, 100, 1275 RK808_BUCK4_ON_VSEL_REG, RK808_BUCK4_VSEL_MASK, 1276 RK808_DCDC_EN_REG, BIT(3), 0), 1277 RK8XX_DESC(RK808_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100, 1278 RK808_LDO1_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1279 BIT(0), 400), 1280 RK8XX_DESC(RK808_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100, 1281 RK808_LDO2_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1282 BIT(1), 400), 1283 { 1284 .name = "LDO_REG3", 1285 .supply_name = "vcc7", 1286 .of_match = of_match_ptr("LDO_REG3"), 1287 .regulators_node = of_match_ptr("regulators"), 1288 .id = RK808_ID_LDO3, 1289 .ops = &rk808_reg_ops_ranges, 1290 .type = REGULATOR_VOLTAGE, 1291 .n_voltages = 16, 1292 .linear_ranges = rk808_ldo3_voltage_ranges, 1293 .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), 1294 .vsel_reg = RK808_LDO3_ON_VSEL_REG, 1295 .vsel_mask = RK808_BUCK4_VSEL_MASK, 1296 .enable_reg = RK808_LDO_EN_REG, 1297 .enable_mask = BIT(2), 1298 .enable_time = 400, 1299 .owner = THIS_MODULE, 1300 }, 1301 RK8XX_DESC(RK808_ID_LDO4, "LDO_REG4", "vcc9", 1800, 3400, 100, 1302 RK808_LDO4_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1303 BIT(3), 400), 1304 RK8XX_DESC(RK808_ID_LDO5, "LDO_REG5", "vcc9", 1800, 3400, 100, 1305 RK808_LDO5_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1306 BIT(4), 400), 1307 RK8XX_DESC(RK808_ID_LDO6, "LDO_REG6", "vcc10", 800, 2500, 100, 1308 RK808_LDO6_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1309 BIT(5), 400), 1310 RK8XX_DESC(RK808_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100, 1311 RK808_LDO7_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1312 BIT(6), 400), 1313 RK8XX_DESC(RK808_ID_LDO8, "LDO_REG8", "vcc11", 1800, 3400, 100, 1314 RK808_LDO8_ON_VSEL_REG, RK808_LDO_VSEL_MASK, RK808_LDO_EN_REG, 1315 BIT(7), 400), 1316 RK8XX_DESC_SWITCH(RK808_ID_SWITCH1, "SWITCH_REG1", "vcc8", 1317 RK808_DCDC_EN_REG, BIT(5)), 1318 RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12", 1319 RK808_DCDC_EN_REG, BIT(6)), 1320 }; 1321 1322 static const struct regulator_desc rk809_reg[] = { 1323 { 1324 .name = "DCDC_REG1", 1325 .supply_name = "vcc1", 1326 .of_match = of_match_ptr("DCDC_REG1"), 1327 .regulators_node = of_match_ptr("regulators"), 1328 .id = RK817_ID_DCDC1, 1329 .ops = &rk817_buck_ops_range, 1330 .type = REGULATOR_VOLTAGE, 1331 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1332 .linear_ranges = rk817_buck1_voltage_ranges, 1333 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1334 .vsel_reg = RK817_BUCK1_ON_VSEL_REG, 1335 .vsel_mask = RK817_BUCK_VSEL_MASK, 1336 .enable_reg = RK817_POWER_EN_REG(0), 1337 .enable_mask = ENABLE_MASK(RK817_ID_DCDC1), 1338 .enable_val = ENABLE_MASK(RK817_ID_DCDC1), 1339 .disable_val = DISABLE_VAL(RK817_ID_DCDC1), 1340 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1), 1341 .ramp_mask = RK817_RAMP_RATE_MASK, 1342 .ramp_delay_table = rk817_buck1_4_ramp_table, 1343 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1344 .of_map_mode = rk8xx_regulator_of_map_mode, 1345 .owner = THIS_MODULE, 1346 }, { 1347 .name = "DCDC_REG2", 1348 .supply_name = "vcc2", 1349 .of_match = of_match_ptr("DCDC_REG2"), 1350 .regulators_node = of_match_ptr("regulators"), 1351 .id = RK817_ID_DCDC2, 1352 .ops = &rk817_buck_ops_range, 1353 .type = REGULATOR_VOLTAGE, 1354 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1355 .linear_ranges = rk817_buck1_voltage_ranges, 1356 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1357 .vsel_reg = RK817_BUCK2_ON_VSEL_REG, 1358 .vsel_mask = RK817_BUCK_VSEL_MASK, 1359 .enable_reg = RK817_POWER_EN_REG(0), 1360 .enable_mask = ENABLE_MASK(RK817_ID_DCDC2), 1361 .enable_val = ENABLE_MASK(RK817_ID_DCDC2), 1362 .disable_val = DISABLE_VAL(RK817_ID_DCDC2), 1363 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2), 1364 .ramp_mask = RK817_RAMP_RATE_MASK, 1365 .ramp_delay_table = rk817_buck1_4_ramp_table, 1366 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1367 .of_map_mode = rk8xx_regulator_of_map_mode, 1368 .owner = THIS_MODULE, 1369 }, { 1370 .name = "DCDC_REG3", 1371 .supply_name = "vcc3", 1372 .of_match = of_match_ptr("DCDC_REG3"), 1373 .regulators_node = of_match_ptr("regulators"), 1374 .id = RK817_ID_DCDC3, 1375 .ops = &rk817_buck_ops_range, 1376 .type = REGULATOR_VOLTAGE, 1377 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1378 .linear_ranges = rk817_buck1_voltage_ranges, 1379 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1380 .vsel_reg = RK817_BUCK3_ON_VSEL_REG, 1381 .vsel_mask = RK817_BUCK_VSEL_MASK, 1382 .enable_reg = RK817_POWER_EN_REG(0), 1383 .enable_mask = ENABLE_MASK(RK817_ID_DCDC3), 1384 .enable_val = ENABLE_MASK(RK817_ID_DCDC3), 1385 .disable_val = DISABLE_VAL(RK817_ID_DCDC3), 1386 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3), 1387 .ramp_mask = RK817_RAMP_RATE_MASK, 1388 .ramp_delay_table = rk817_buck1_4_ramp_table, 1389 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1390 .of_map_mode = rk8xx_regulator_of_map_mode, 1391 .owner = THIS_MODULE, 1392 }, { 1393 .name = "DCDC_REG4", 1394 .supply_name = "vcc4", 1395 .of_match = of_match_ptr("DCDC_REG4"), 1396 .regulators_node = of_match_ptr("regulators"), 1397 .id = RK817_ID_DCDC4, 1398 .ops = &rk817_buck_ops_range, 1399 .type = REGULATOR_VOLTAGE, 1400 .n_voltages = RK817_BUCK3_SEL_CNT + 1, 1401 .linear_ranges = rk817_buck3_voltage_ranges, 1402 .n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges), 1403 .vsel_reg = RK817_BUCK4_ON_VSEL_REG, 1404 .vsel_mask = RK817_BUCK_VSEL_MASK, 1405 .enable_reg = RK817_POWER_EN_REG(0), 1406 .enable_mask = ENABLE_MASK(RK817_ID_DCDC4), 1407 .enable_val = ENABLE_MASK(RK817_ID_DCDC4), 1408 .disable_val = DISABLE_VAL(RK817_ID_DCDC4), 1409 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4), 1410 .ramp_mask = RK817_RAMP_RATE_MASK, 1411 .ramp_delay_table = rk817_buck1_4_ramp_table, 1412 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1413 .of_map_mode = rk8xx_regulator_of_map_mode, 1414 .owner = THIS_MODULE, 1415 }, 1416 { 1417 .name = "DCDC_REG5", 1418 .supply_name = "vcc9", 1419 .of_match = of_match_ptr("DCDC_REG5"), 1420 .regulators_node = of_match_ptr("regulators"), 1421 .id = RK809_ID_DCDC5, 1422 .ops = &rk809_buck5_ops_range, 1423 .type = REGULATOR_VOLTAGE, 1424 .n_voltages = RK809_BUCK5_SEL_CNT, 1425 .linear_ranges = rk809_buck5_voltage_ranges, 1426 .n_linear_ranges = ARRAY_SIZE(rk809_buck5_voltage_ranges), 1427 .vsel_reg = RK809_BUCK5_CONFIG(0), 1428 .vsel_mask = RK809_BUCK5_VSEL_MASK, 1429 .enable_reg = RK817_POWER_EN_REG(3), 1430 .enable_mask = ENABLE_MASK(1), 1431 .enable_val = ENABLE_MASK(1), 1432 .disable_val = DISABLE_VAL(1), 1433 .of_map_mode = rk8xx_regulator_of_map_mode, 1434 .owner = THIS_MODULE, 1435 }, 1436 RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25, 1437 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK, 1438 RK817_POWER_EN_REG(1), ENABLE_MASK(0), 1439 DISABLE_VAL(0), 400), 1440 RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25, 1441 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK, 1442 RK817_POWER_EN_REG(1), ENABLE_MASK(1), 1443 DISABLE_VAL(1), 400), 1444 RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25, 1445 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK, 1446 RK817_POWER_EN_REG(1), ENABLE_MASK(2), 1447 DISABLE_VAL(2), 400), 1448 RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25, 1449 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK, 1450 RK817_POWER_EN_REG(1), ENABLE_MASK(3), 1451 DISABLE_VAL(3), 400), 1452 RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25, 1453 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK, 1454 RK817_POWER_EN_REG(2), ENABLE_MASK(0), 1455 DISABLE_VAL(0), 400), 1456 RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25, 1457 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK, 1458 RK817_POWER_EN_REG(2), ENABLE_MASK(1), 1459 DISABLE_VAL(1), 400), 1460 RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25, 1461 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK, 1462 RK817_POWER_EN_REG(2), ENABLE_MASK(2), 1463 DISABLE_VAL(2), 400), 1464 RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25, 1465 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK, 1466 RK817_POWER_EN_REG(2), ENABLE_MASK(3), 1467 DISABLE_VAL(3), 400), 1468 RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25, 1469 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK, 1470 RK817_POWER_EN_REG(3), ENABLE_MASK(0), 1471 DISABLE_VAL(0), 400), 1472 RK817_DESC_SWITCH(RK809_ID_SW1, "SWITCH_REG1", "vcc9", 1473 RK817_POWER_EN_REG(3), ENABLE_MASK(2), 1474 DISABLE_VAL(2)), 1475 RK817_DESC_SWITCH(RK809_ID_SW2, "SWITCH_REG2", "vcc8", 1476 RK817_POWER_EN_REG(3), ENABLE_MASK(3), 1477 DISABLE_VAL(3)), 1478 }; 1479 1480 static const struct linear_range rk816_buck_4_voltage_ranges[] = { 1481 REGULATOR_LINEAR_RANGE(800000, 0, 26, 100000), 1482 REGULATOR_LINEAR_RANGE(3500000, 27, 31, 0), 1483 }; 1484 1485 static const struct regulator_desc rk816_reg[] = { 1486 { 1487 .name = "dcdc1", 1488 .supply_name = "vcc1", 1489 .of_match = of_match_ptr("dcdc1"), 1490 .regulators_node = of_match_ptr("regulators"), 1491 .id = RK816_ID_DCDC1, 1492 .ops = &rk816_buck1_2_ops_ranges, 1493 .type = REGULATOR_VOLTAGE, 1494 .n_voltages = 64, 1495 .linear_ranges = rk805_buck_1_2_voltage_ranges, 1496 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges), 1497 .vsel_reg = RK818_BUCK1_ON_VSEL_REG, 1498 .vsel_mask = RK818_BUCK_VSEL_MASK, 1499 .apply_reg = RK816_DCDC_EN_REG2, 1500 .apply_bit = RK816_BUCK_DVS_CONFIRM, 1501 .enable_reg = RK816_DCDC_EN_REG1, 1502 .enable_mask = BIT(4) | BIT(0), 1503 .enable_val = BIT(4) | BIT(0), 1504 .disable_val = BIT(4), 1505 .ramp_reg = RK818_BUCK1_CONFIG_REG, 1506 .ramp_mask = RK808_RAMP_RATE_MASK, 1507 .ramp_delay_table = rk817_buck1_4_ramp_table, 1508 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1509 .of_map_mode = rk8xx_regulator_of_map_mode, 1510 .owner = THIS_MODULE, 1511 }, { 1512 .name = "dcdc2", 1513 .supply_name = "vcc2", 1514 .of_match = of_match_ptr("dcdc2"), 1515 .regulators_node = of_match_ptr("regulators"), 1516 .id = RK816_ID_DCDC2, 1517 .ops = &rk816_buck1_2_ops_ranges, 1518 .type = REGULATOR_VOLTAGE, 1519 .n_voltages = 64, 1520 .linear_ranges = rk805_buck_1_2_voltage_ranges, 1521 .n_linear_ranges = ARRAY_SIZE(rk805_buck_1_2_voltage_ranges), 1522 .vsel_reg = RK818_BUCK2_ON_VSEL_REG, 1523 .vsel_mask = RK818_BUCK_VSEL_MASK, 1524 .apply_reg = RK816_DCDC_EN_REG2, 1525 .apply_bit = RK816_BUCK_DVS_CONFIRM, 1526 .enable_reg = RK816_DCDC_EN_REG1, 1527 .enable_mask = BIT(5) | BIT(1), 1528 .enable_val = BIT(5) | BIT(1), 1529 .disable_val = BIT(5), 1530 .ramp_reg = RK818_BUCK2_CONFIG_REG, 1531 .ramp_mask = RK808_RAMP_RATE_MASK, 1532 .ramp_delay_table = rk817_buck1_4_ramp_table, 1533 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1534 .of_map_mode = rk8xx_regulator_of_map_mode, 1535 .owner = THIS_MODULE, 1536 }, { 1537 .name = "dcdc3", 1538 .supply_name = "vcc3", 1539 .of_match = of_match_ptr("dcdc3"), 1540 .regulators_node = of_match_ptr("regulators"), 1541 .id = RK816_ID_DCDC3, 1542 .ops = &rk808_switch_ops, 1543 .type = REGULATOR_VOLTAGE, 1544 .n_voltages = 1, 1545 .enable_reg = RK816_DCDC_EN_REG1, 1546 .enable_mask = BIT(6) | BIT(2), 1547 .enable_val = BIT(6) | BIT(2), 1548 .disable_val = BIT(6), 1549 .of_map_mode = rk8xx_regulator_of_map_mode, 1550 .owner = THIS_MODULE, 1551 }, { 1552 .name = "dcdc4", 1553 .supply_name = "vcc4", 1554 .of_match = of_match_ptr("dcdc4"), 1555 .regulators_node = of_match_ptr("regulators"), 1556 .id = RK816_ID_DCDC4, 1557 .ops = &rk816_buck4_ops_ranges, 1558 .type = REGULATOR_VOLTAGE, 1559 .n_voltages = 32, 1560 .linear_ranges = rk816_buck_4_voltage_ranges, 1561 .n_linear_ranges = ARRAY_SIZE(rk816_buck_4_voltage_ranges), 1562 .vsel_reg = RK818_BUCK4_ON_VSEL_REG, 1563 .vsel_mask = RK818_BUCK4_VSEL_MASK, 1564 .enable_reg = RK816_DCDC_EN_REG1, 1565 .enable_mask = BIT(7) | BIT(3), 1566 .enable_val = BIT(7) | BIT(3), 1567 .disable_val = BIT(7), 1568 .of_map_mode = rk8xx_regulator_of_map_mode, 1569 .owner = THIS_MODULE, 1570 }, 1571 RK816_DESC(RK816_ID_LDO1, "ldo1", "vcc5", 800, 3400, 100, 1572 RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1573 RK816_LDO_EN_REG1, ENABLE_MASK(0), DISABLE_VAL(0), 400), 1574 RK816_DESC(RK816_ID_LDO2, "ldo2", "vcc5", 800, 3400, 100, 1575 RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1576 RK816_LDO_EN_REG1, ENABLE_MASK(1), DISABLE_VAL(1), 400), 1577 RK816_DESC(RK816_ID_LDO3, "ldo3", "vcc5", 800, 3400, 100, 1578 RK818_LDO3_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1579 RK816_LDO_EN_REG1, ENABLE_MASK(2), DISABLE_VAL(2), 400), 1580 RK816_DESC(RK816_ID_LDO4, "ldo4", "vcc6", 800, 3400, 100, 1581 RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1582 RK816_LDO_EN_REG1, ENABLE_MASK(3), DISABLE_VAL(3), 400), 1583 RK816_DESC(RK816_ID_LDO5, "ldo5", "vcc6", 800, 3400, 100, 1584 RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1585 RK816_LDO_EN_REG2, ENABLE_MASK(0), DISABLE_VAL(0), 400), 1586 RK816_DESC(RK816_ID_LDO6, "ldo6", "vcc6", 800, 3400, 100, 1587 RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1588 RK816_LDO_EN_REG2, ENABLE_MASK(1), DISABLE_VAL(1), 400), 1589 }; 1590 1591 static const struct regulator_desc rk817_reg[] = { 1592 { 1593 .name = "DCDC_REG1", 1594 .supply_name = "vcc1", 1595 .of_match = of_match_ptr("DCDC_REG1"), 1596 .regulators_node = of_match_ptr("regulators"), 1597 .id = RK817_ID_DCDC1, 1598 .ops = &rk817_buck_ops_range, 1599 .type = REGULATOR_VOLTAGE, 1600 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1601 .linear_ranges = rk817_buck1_voltage_ranges, 1602 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1603 .vsel_reg = RK817_BUCK1_ON_VSEL_REG, 1604 .vsel_mask = RK817_BUCK_VSEL_MASK, 1605 .enable_reg = RK817_POWER_EN_REG(0), 1606 .enable_mask = ENABLE_MASK(RK817_ID_DCDC1), 1607 .enable_val = ENABLE_MASK(RK817_ID_DCDC1), 1608 .disable_val = DISABLE_VAL(RK817_ID_DCDC1), 1609 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC1), 1610 .ramp_mask = RK817_RAMP_RATE_MASK, 1611 .ramp_delay_table = rk817_buck1_4_ramp_table, 1612 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1613 .of_map_mode = rk8xx_regulator_of_map_mode, 1614 .owner = THIS_MODULE, 1615 }, { 1616 .name = "DCDC_REG2", 1617 .supply_name = "vcc2", 1618 .of_match = of_match_ptr("DCDC_REG2"), 1619 .regulators_node = of_match_ptr("regulators"), 1620 .id = RK817_ID_DCDC2, 1621 .ops = &rk817_buck_ops_range, 1622 .type = REGULATOR_VOLTAGE, 1623 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1624 .linear_ranges = rk817_buck1_voltage_ranges, 1625 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1626 .vsel_reg = RK817_BUCK2_ON_VSEL_REG, 1627 .vsel_mask = RK817_BUCK_VSEL_MASK, 1628 .enable_reg = RK817_POWER_EN_REG(0), 1629 .enable_mask = ENABLE_MASK(RK817_ID_DCDC2), 1630 .enable_val = ENABLE_MASK(RK817_ID_DCDC2), 1631 .disable_val = DISABLE_VAL(RK817_ID_DCDC2), 1632 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC2), 1633 .ramp_mask = RK817_RAMP_RATE_MASK, 1634 .ramp_delay_table = rk817_buck1_4_ramp_table, 1635 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1636 .of_map_mode = rk8xx_regulator_of_map_mode, 1637 .owner = THIS_MODULE, 1638 }, { 1639 .name = "DCDC_REG3", 1640 .supply_name = "vcc3", 1641 .of_match = of_match_ptr("DCDC_REG3"), 1642 .regulators_node = of_match_ptr("regulators"), 1643 .id = RK817_ID_DCDC3, 1644 .ops = &rk817_buck_ops_range, 1645 .type = REGULATOR_VOLTAGE, 1646 .n_voltages = RK817_BUCK1_SEL_CNT + 1, 1647 .linear_ranges = rk817_buck1_voltage_ranges, 1648 .n_linear_ranges = ARRAY_SIZE(rk817_buck1_voltage_ranges), 1649 .vsel_reg = RK817_BUCK3_ON_VSEL_REG, 1650 .vsel_mask = RK817_BUCK_VSEL_MASK, 1651 .enable_reg = RK817_POWER_EN_REG(0), 1652 .enable_mask = ENABLE_MASK(RK817_ID_DCDC3), 1653 .enable_val = ENABLE_MASK(RK817_ID_DCDC3), 1654 .disable_val = DISABLE_VAL(RK817_ID_DCDC3), 1655 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC3), 1656 .ramp_mask = RK817_RAMP_RATE_MASK, 1657 .ramp_delay_table = rk817_buck1_4_ramp_table, 1658 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1659 .of_map_mode = rk8xx_regulator_of_map_mode, 1660 .owner = THIS_MODULE, 1661 }, { 1662 .name = "DCDC_REG4", 1663 .supply_name = "vcc4", 1664 .of_match = of_match_ptr("DCDC_REG4"), 1665 .regulators_node = of_match_ptr("regulators"), 1666 .id = RK817_ID_DCDC4, 1667 .ops = &rk817_buck_ops_range, 1668 .type = REGULATOR_VOLTAGE, 1669 .n_voltages = RK817_BUCK3_SEL_CNT + 1, 1670 .linear_ranges = rk817_buck3_voltage_ranges, 1671 .n_linear_ranges = ARRAY_SIZE(rk817_buck3_voltage_ranges), 1672 .vsel_reg = RK817_BUCK4_ON_VSEL_REG, 1673 .vsel_mask = RK817_BUCK_VSEL_MASK, 1674 .enable_reg = RK817_POWER_EN_REG(0), 1675 .enable_mask = ENABLE_MASK(RK817_ID_DCDC4), 1676 .enable_val = ENABLE_MASK(RK817_ID_DCDC4), 1677 .disable_val = DISABLE_VAL(RK817_ID_DCDC4), 1678 .ramp_reg = RK817_BUCK_CONFIG_REG(RK817_ID_DCDC4), 1679 .ramp_mask = RK817_RAMP_RATE_MASK, 1680 .ramp_delay_table = rk817_buck1_4_ramp_table, 1681 .n_ramp_values = ARRAY_SIZE(rk817_buck1_4_ramp_table), 1682 .of_map_mode = rk8xx_regulator_of_map_mode, 1683 .owner = THIS_MODULE, 1684 }, 1685 RK817_DESC(RK817_ID_LDO1, "LDO_REG1", "vcc5", 600, 3400, 25, 1686 RK817_LDO_ON_VSEL_REG(0), RK817_LDO_VSEL_MASK, 1687 RK817_POWER_EN_REG(1), ENABLE_MASK(0), 1688 DISABLE_VAL(0), 400), 1689 RK817_DESC(RK817_ID_LDO2, "LDO_REG2", "vcc5", 600, 3400, 25, 1690 RK817_LDO_ON_VSEL_REG(1), RK817_LDO_VSEL_MASK, 1691 RK817_POWER_EN_REG(1), ENABLE_MASK(1), 1692 DISABLE_VAL(1), 400), 1693 RK817_DESC(RK817_ID_LDO3, "LDO_REG3", "vcc5", 600, 3400, 25, 1694 RK817_LDO_ON_VSEL_REG(2), RK817_LDO_VSEL_MASK, 1695 RK817_POWER_EN_REG(1), ENABLE_MASK(2), 1696 DISABLE_VAL(2), 400), 1697 RK817_DESC(RK817_ID_LDO4, "LDO_REG4", "vcc6", 600, 3400, 25, 1698 RK817_LDO_ON_VSEL_REG(3), RK817_LDO_VSEL_MASK, 1699 RK817_POWER_EN_REG(1), ENABLE_MASK(3), 1700 DISABLE_VAL(3), 400), 1701 RK817_DESC(RK817_ID_LDO5, "LDO_REG5", "vcc6", 600, 3400, 25, 1702 RK817_LDO_ON_VSEL_REG(4), RK817_LDO_VSEL_MASK, 1703 RK817_POWER_EN_REG(2), ENABLE_MASK(0), 1704 DISABLE_VAL(0), 400), 1705 RK817_DESC(RK817_ID_LDO6, "LDO_REG6", "vcc6", 600, 3400, 25, 1706 RK817_LDO_ON_VSEL_REG(5), RK817_LDO_VSEL_MASK, 1707 RK817_POWER_EN_REG(2), ENABLE_MASK(1), 1708 DISABLE_VAL(1), 400), 1709 RK817_DESC(RK817_ID_LDO7, "LDO_REG7", "vcc7", 600, 3400, 25, 1710 RK817_LDO_ON_VSEL_REG(6), RK817_LDO_VSEL_MASK, 1711 RK817_POWER_EN_REG(2), ENABLE_MASK(2), 1712 DISABLE_VAL(2), 400), 1713 RK817_DESC(RK817_ID_LDO8, "LDO_REG8", "vcc7", 600, 3400, 25, 1714 RK817_LDO_ON_VSEL_REG(7), RK817_LDO_VSEL_MASK, 1715 RK817_POWER_EN_REG(2), ENABLE_MASK(3), 1716 DISABLE_VAL(3), 400), 1717 RK817_DESC(RK817_ID_LDO9, "LDO_REG9", "vcc7", 600, 3400, 25, 1718 RK817_LDO_ON_VSEL_REG(8), RK817_LDO_VSEL_MASK, 1719 RK817_POWER_EN_REG(3), ENABLE_MASK(0), 1720 DISABLE_VAL(0), 400), 1721 RK817_BOOST_DESC(RK817_ID_BOOST, "BOOST", "vcc8", 4700, 5400, 100, 1722 RK817_BOOST_OTG_CFG, RK817_BOOST_VSEL_MASK, 1723 RK817_POWER_EN_REG(3), ENABLE_MASK(1), ENABLE_MASK(1), 1724 DISABLE_VAL(1), 400, 3500 - 5400), 1725 RK817_DESC_SWITCH(RK817_ID_BOOST_OTG_SW, "OTG_SWITCH", "vcc9", 1726 RK817_POWER_EN_REG(3), ENABLE_MASK(2), 1727 DISABLE_VAL(2)), 1728 }; 1729 1730 static const struct regulator_desc rk818_reg[] = { 1731 { 1732 .name = "DCDC_REG1", 1733 .supply_name = "vcc1", 1734 .of_match = of_match_ptr("DCDC_REG1"), 1735 .regulators_node = of_match_ptr("regulators"), 1736 .id = RK818_ID_DCDC1, 1737 .ops = &rk808_reg_ops, 1738 .type = REGULATOR_VOLTAGE, 1739 .min_uV = 712500, 1740 .uV_step = 12500, 1741 .n_voltages = 64, 1742 .vsel_reg = RK818_BUCK1_ON_VSEL_REG, 1743 .vsel_mask = RK818_BUCK_VSEL_MASK, 1744 .enable_reg = RK818_DCDC_EN_REG, 1745 .enable_mask = BIT(0), 1746 .owner = THIS_MODULE, 1747 }, { 1748 .name = "DCDC_REG2", 1749 .supply_name = "vcc2", 1750 .of_match = of_match_ptr("DCDC_REG2"), 1751 .regulators_node = of_match_ptr("regulators"), 1752 .id = RK818_ID_DCDC2, 1753 .ops = &rk808_reg_ops, 1754 .type = REGULATOR_VOLTAGE, 1755 .min_uV = 712500, 1756 .uV_step = 12500, 1757 .n_voltages = 64, 1758 .vsel_reg = RK818_BUCK2_ON_VSEL_REG, 1759 .vsel_mask = RK818_BUCK_VSEL_MASK, 1760 .enable_reg = RK818_DCDC_EN_REG, 1761 .enable_mask = BIT(1), 1762 .owner = THIS_MODULE, 1763 }, { 1764 .name = "DCDC_REG3", 1765 .supply_name = "vcc3", 1766 .of_match = of_match_ptr("DCDC_REG3"), 1767 .regulators_node = of_match_ptr("regulators"), 1768 .id = RK818_ID_DCDC3, 1769 .ops = &rk808_switch_ops, 1770 .type = REGULATOR_VOLTAGE, 1771 .n_voltages = 1, 1772 .enable_reg = RK818_DCDC_EN_REG, 1773 .enable_mask = BIT(2), 1774 .owner = THIS_MODULE, 1775 }, 1776 RK8XX_DESC(RK818_ID_DCDC4, "DCDC_REG4", "vcc4", 1800, 3600, 100, 1777 RK818_BUCK4_ON_VSEL_REG, RK818_BUCK4_VSEL_MASK, 1778 RK818_DCDC_EN_REG, BIT(3), 0), 1779 RK8XX_DESC(RK818_ID_BOOST, "DCDC_BOOST", "boost", 4700, 5400, 100, 1780 RK818_BOOST_LDO9_ON_VSEL_REG, RK818_BOOST_ON_VSEL_MASK, 1781 RK818_DCDC_EN_REG, BIT(4), 0), 1782 RK8XX_DESC(RK818_ID_LDO1, "LDO_REG1", "vcc6", 1800, 3400, 100, 1783 RK818_LDO1_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1784 BIT(0), 400), 1785 RK8XX_DESC(RK818_ID_LDO2, "LDO_REG2", "vcc6", 1800, 3400, 100, 1786 RK818_LDO2_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1787 BIT(1), 400), 1788 { 1789 .name = "LDO_REG3", 1790 .supply_name = "vcc7", 1791 .of_match = of_match_ptr("LDO_REG3"), 1792 .regulators_node = of_match_ptr("regulators"), 1793 .id = RK818_ID_LDO3, 1794 .ops = &rk808_reg_ops_ranges, 1795 .type = REGULATOR_VOLTAGE, 1796 .n_voltages = 16, 1797 .linear_ranges = rk808_ldo3_voltage_ranges, 1798 .n_linear_ranges = ARRAY_SIZE(rk808_ldo3_voltage_ranges), 1799 .vsel_reg = RK818_LDO3_ON_VSEL_REG, 1800 .vsel_mask = RK818_LDO3_ON_VSEL_MASK, 1801 .enable_reg = RK818_LDO_EN_REG, 1802 .enable_mask = BIT(2), 1803 .enable_time = 400, 1804 .owner = THIS_MODULE, 1805 }, 1806 RK8XX_DESC(RK818_ID_LDO4, "LDO_REG4", "vcc8", 1800, 3400, 100, 1807 RK818_LDO4_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1808 BIT(3), 400), 1809 RK8XX_DESC(RK818_ID_LDO5, "LDO_REG5", "vcc7", 1800, 3400, 100, 1810 RK818_LDO5_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1811 BIT(4), 400), 1812 RK8XX_DESC(RK818_ID_LDO6, "LDO_REG6", "vcc8", 800, 2500, 100, 1813 RK818_LDO6_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1814 BIT(5), 400), 1815 RK8XX_DESC(RK818_ID_LDO7, "LDO_REG7", "vcc7", 800, 2500, 100, 1816 RK818_LDO7_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1817 BIT(6), 400), 1818 RK8XX_DESC(RK818_ID_LDO8, "LDO_REG8", "vcc8", 1800, 3400, 100, 1819 RK818_LDO8_ON_VSEL_REG, RK818_LDO_VSEL_MASK, RK818_LDO_EN_REG, 1820 BIT(7), 400), 1821 RK8XX_DESC(RK818_ID_LDO9, "LDO_REG9", "vcc9", 1800, 3400, 100, 1822 RK818_BOOST_LDO9_ON_VSEL_REG, RK818_LDO_VSEL_MASK, 1823 RK818_DCDC_EN_REG, BIT(5), 400), 1824 RK8XX_DESC_SWITCH(RK818_ID_SWITCH, "SWITCH_REG", "vcc9", 1825 RK818_DCDC_EN_REG, BIT(6)), 1826 RK8XX_DESC_SWITCH(RK818_ID_HDMI_SWITCH, "HDMI_SWITCH", "h_5v", 1827 RK818_H5V_EN_REG, BIT(0)), 1828 RK8XX_DESC_SWITCH(RK818_ID_OTG_SWITCH, "OTG_SWITCH", "usb", 1829 RK818_DCDC_EN_REG, BIT(7)), 1830 }; 1831 1832 static int rk808_regulator_dt_parse_pdata(struct device *dev, 1833 struct regmap *map, 1834 struct rk808_regulator_data *pdata) 1835 { 1836 struct device_node *np; 1837 int tmp, ret = 0, i; 1838 1839 np = of_get_child_by_name(dev->of_node, "regulators"); 1840 if (!np) 1841 return -ENXIO; 1842 1843 for (i = 0; i < ARRAY_SIZE(pdata->dvs_gpio); i++) { 1844 pdata->dvs_gpio[i] = 1845 devm_gpiod_get_index_optional(dev, "dvs", i, 1846 GPIOD_OUT_LOW); 1847 if (IS_ERR(pdata->dvs_gpio[i])) { 1848 ret = PTR_ERR(pdata->dvs_gpio[i]); 1849 dev_err(dev, "failed to get dvs%d gpio (%d)\n", i, ret); 1850 goto dt_parse_end; 1851 } 1852 1853 if (!pdata->dvs_gpio[i]) { 1854 dev_info(dev, "there is no dvs%d gpio\n", i); 1855 continue; 1856 } 1857 1858 tmp = i ? RK808_DVS2_POL : RK808_DVS1_POL; 1859 ret = regmap_update_bits(map, RK808_IO_POL_REG, tmp, 1860 gpiod_is_active_low(pdata->dvs_gpio[i]) ? 1861 0 : tmp); 1862 } 1863 1864 dt_parse_end: 1865 of_node_put(np); 1866 return ret; 1867 } 1868 1869 static int rk808_regulator_probe(struct platform_device *pdev) 1870 { 1871 struct rk808 *rk808 = dev_get_drvdata(pdev->dev.parent); 1872 struct regulator_config config = {}; 1873 struct regulator_dev *rk808_rdev; 1874 struct rk808_regulator_data *pdata; 1875 const struct regulator_desc *regulators; 1876 struct regmap *regmap; 1877 int ret, i, nregulators; 1878 1879 pdev->dev.of_node = pdev->dev.parent->of_node; 1880 pdev->dev.of_node_reused = true; 1881 1882 regmap = dev_get_regmap(pdev->dev.parent, NULL); 1883 if (!regmap) 1884 return -ENODEV; 1885 1886 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL); 1887 if (!pdata) 1888 return -ENOMEM; 1889 1890 ret = rk808_regulator_dt_parse_pdata(&pdev->dev, regmap, pdata); 1891 if (ret < 0) 1892 return ret; 1893 1894 platform_set_drvdata(pdev, pdata); 1895 1896 switch (rk808->variant) { 1897 case RK805_ID: 1898 regulators = rk805_reg; 1899 nregulators = RK805_NUM_REGULATORS; 1900 break; 1901 case RK806_ID: 1902 regulators = rk806_reg; 1903 nregulators = ARRAY_SIZE(rk806_reg); 1904 break; 1905 case RK808_ID: 1906 regulators = rk808_reg; 1907 nregulators = RK808_NUM_REGULATORS; 1908 break; 1909 case RK809_ID: 1910 regulators = rk809_reg; 1911 nregulators = RK809_NUM_REGULATORS; 1912 break; 1913 case RK816_ID: 1914 regulators = rk816_reg; 1915 nregulators = ARRAY_SIZE(rk816_reg); 1916 break; 1917 case RK817_ID: 1918 regulators = rk817_reg; 1919 nregulators = RK817_NUM_REGULATORS; 1920 break; 1921 case RK818_ID: 1922 regulators = rk818_reg; 1923 nregulators = RK818_NUM_REGULATORS; 1924 break; 1925 default: 1926 dev_err(&pdev->dev, "unsupported RK8XX ID %lu\n", 1927 rk808->variant); 1928 return -EINVAL; 1929 } 1930 1931 config.dev = &pdev->dev; 1932 config.driver_data = pdata; 1933 config.regmap = regmap; 1934 1935 /* Instantiate the regulators */ 1936 for (i = 0; i < nregulators; i++) { 1937 rk808_rdev = devm_regulator_register(&pdev->dev, 1938 ®ulators[i], &config); 1939 if (IS_ERR(rk808_rdev)) 1940 return dev_err_probe(&pdev->dev, PTR_ERR(rk808_rdev), 1941 "failed to register %d regulator\n", i); 1942 } 1943 1944 return 0; 1945 } 1946 1947 static struct platform_driver rk808_regulator_driver = { 1948 .probe = rk808_regulator_probe, 1949 .driver = { 1950 .name = "rk808-regulator", 1951 .probe_type = PROBE_FORCE_SYNCHRONOUS, 1952 }, 1953 }; 1954 1955 module_platform_driver(rk808_regulator_driver); 1956 1957 MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK818 series PMICs"); 1958 MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>"); 1959 MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); 1960 MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>"); 1961 MODULE_AUTHOR("Wadim Egorov <w.egorov@phytec.de>"); 1962 MODULE_AUTHOR("Xu Shengfei <xsf@rock-chips.com>"); 1963 MODULE_LICENSE("GPL"); 1964 MODULE_ALIAS("platform:rk808-regulator"); 1965