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