| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | | - * Regulator driver for Rockchip RK808/RK818 |
|---|
| 3 | + * Regulator driver for Rockchip RK805/RK808/RK818 |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (c) 2014, Fuzhou Rockchip Electronics Co., Ltd |
|---|
| 5 | 6 | * |
|---|
| .. | .. |
|---|
| 9 | 10 | * Copyright (C) 2016 PHYTEC Messtechnik GmbH |
|---|
| 10 | 11 | * |
|---|
| 11 | 12 | * Author: Wadim Egorov <w.egorov@phytec.de> |
|---|
| 12 | | - * |
|---|
| 13 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 14 | | - * under the terms and conditions of the GNU General Public License, |
|---|
| 15 | | - * version 2, as published by the Free Software Foundation. |
|---|
| 16 | | - * |
|---|
| 17 | | - * This program is distributed in the hope it will be useful, but WITHOUT |
|---|
| 18 | | - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|---|
| 19 | | - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
|---|
| 20 | | - * more details. |
|---|
| 21 | 13 | */ |
|---|
| 22 | 14 | |
|---|
| 23 | 15 | #include <linux/delay.h> |
|---|
| .. | .. |
|---|
| 36 | 28 | #define RK808_BUCK4_VSEL_MASK 0xf |
|---|
| 37 | 29 | #define RK808_LDO_VSEL_MASK 0x1f |
|---|
| 38 | 30 | |
|---|
| 39 | | -#define RK809_BUCK5_VSEL_MASK 0x7 |
|---|
| 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 |
|---|
| 40 | 36 | |
|---|
| 41 | 37 | #define RK816_DCDC_SLP_EN_REG_OFFSET 2 |
|---|
| 42 | 38 | #define RK816_SWITCH_SLP_EN_REG_OFFSET 1 |
|---|
| 43 | 39 | #define RK816_LDO1_4_SLP_EN_REG_OFFSET 1 |
|---|
| 44 | 40 | #define RK816_LDO5_6_SLP_EN_REG_OFFSET 2 |
|---|
| 45 | | - |
|---|
| 46 | | -#define RK817_LDO_VSEL_MASK 0x7f |
|---|
| 47 | | -#define RK817_BOOST_VSEL_MASK 0x7 |
|---|
| 48 | | -#define RK817_BUCK_VSEL_MASK 0x7f |
|---|
| 49 | 41 | |
|---|
| 50 | 42 | #define RK818_BUCK_VSEL_MASK 0x3f |
|---|
| 51 | 43 | #define RK818_BUCK4_VSEL_MASK 0x1f |
|---|
| .. | .. |
|---|
| 183 | 175 | RK808_BUCK4_CONFIG_REG, |
|---|
| 184 | 176 | }; |
|---|
| 185 | 177 | |
|---|
| 186 | | -static const struct regulator_linear_range rk805_buck_1_2_voltage_ranges[] = { |
|---|
| 178 | +static const struct linear_range rk805_buck_1_2_voltage_ranges[] = { |
|---|
| 187 | 179 | REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500), /* 0.7125v - 1.45v */ |
|---|
| 188 | 180 | REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),/* 1.8v - 2.2v */ |
|---|
| 189 | 181 | REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0), /* 2.3v - 2.3v */ |
|---|
| 190 | 182 | }; |
|---|
| 191 | 183 | |
|---|
| 192 | | -static const struct regulator_linear_range rk805_buck4_voltage_ranges[] = { |
|---|
| 184 | +static const struct linear_range rk805_buck4_voltage_ranges[] = { |
|---|
| 193 | 185 | REGULATOR_LINEAR_RANGE(800000, 0, 26, 100000), /* 0.8v - 3.4v */ |
|---|
| 194 | 186 | REGULATOR_LINEAR_RANGE(3500000, 27, 31, 0), /* 3.5v */ |
|---|
| 195 | 187 | }; |
|---|
| 196 | 188 | |
|---|
| 197 | | -static const struct regulator_linear_range rk808_ldo3_voltage_ranges[] = { |
|---|
| 189 | +static const struct linear_range rk808_ldo3_voltage_ranges[] = { |
|---|
| 198 | 190 | REGULATOR_LINEAR_RANGE(800000, 0, 13, 100000), |
|---|
| 199 | 191 | REGULATOR_LINEAR_RANGE(2500000, 15, 15, 0), |
|---|
| 200 | 192 | }; |
|---|
| 201 | 193 | |
|---|
| 202 | | -static const struct regulator_linear_range rk816_buck_voltage_ranges[] = { |
|---|
| 194 | +static const struct linear_range rk816_buck_voltage_ranges[] = { |
|---|
| 203 | 195 | REGULATOR_LINEAR_RANGE(712500, 0, 59, 12500), /* 0.7125v - 1.45v */ |
|---|
| 204 | 196 | REGULATOR_LINEAR_RANGE(1800000, 60, 62, 200000),/* 1.8v - 2.2v */ |
|---|
| 205 | 197 | REGULATOR_LINEAR_RANGE(2300000, 63, 63, 0), /* 2.3v - 2.3v */ |
|---|
| 206 | 198 | }; |
|---|
| 207 | 199 | |
|---|
| 208 | | -static const struct regulator_linear_range rk816_buck4_voltage_ranges[] = { |
|---|
| 200 | +static const struct linear_range rk816_buck4_voltage_ranges[] = { |
|---|
| 209 | 201 | REGULATOR_LINEAR_RANGE(800000, 0, 26, 100000), /* 0.8v - 3.4 */ |
|---|
| 210 | 202 | REGULATOR_LINEAR_RANGE(3500000, 27, 31, 0), /* 3.5v */ |
|---|
| 211 | 203 | }; |
|---|
| 212 | 204 | |
|---|
| 213 | 205 | #define RK809_BUCK5_SEL_CNT (8) |
|---|
| 214 | 206 | |
|---|
| 215 | | -static const struct regulator_linear_range rk809_buck5_voltage_ranges[] = { |
|---|
| 207 | +static const struct linear_range rk809_buck5_voltage_ranges[] = { |
|---|
| 216 | 208 | REGULATOR_LINEAR_RANGE(1500000, 0, 0, 0), |
|---|
| 217 | 209 | REGULATOR_LINEAR_RANGE(1800000, 1, 3, 200000), |
|---|
| 218 | 210 | REGULATOR_LINEAR_RANGE(2800000, 4, 5, 200000), |
|---|
| .. | .. |
|---|
| 241 | 233 | #define RK817_BUCK1_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK1_SEL1 + 1) |
|---|
| 242 | 234 | #define RK817_BUCK3_SEL_CNT (RK817_BUCK1_SEL0 + RK817_BUCK3_SEL1 + 1) |
|---|
| 243 | 235 | |
|---|
| 244 | | -static const struct regulator_linear_range rk817_buck1_voltage_ranges[] = { |
|---|
| 236 | +static const struct linear_range rk817_buck1_voltage_ranges[] = { |
|---|
| 245 | 237 | REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0, |
|---|
| 246 | 238 | RK817_BUCK1_SEL0, RK817_BUCK1_STP0), |
|---|
| 247 | 239 | REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1, |
|---|
| 248 | 240 | RK817_BUCK1_SEL_CNT, RK817_BUCK1_STP1), |
|---|
| 249 | 241 | }; |
|---|
| 250 | 242 | |
|---|
| 251 | | -static const struct regulator_linear_range rk817_buck3_voltage_ranges[] = { |
|---|
| 243 | +static const struct linear_range rk817_buck3_voltage_ranges[] = { |
|---|
| 252 | 244 | REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN0, 0, |
|---|
| 253 | 245 | RK817_BUCK1_SEL0, RK817_BUCK1_STP0), |
|---|
| 254 | 246 | REGULATOR_LINEAR_RANGE(RK817_BUCK1_MIN1, RK817_BUCK1_SEL0 + 1, |
|---|
| .. | .. |
|---|
| 327 | 319 | return ret; |
|---|
| 328 | 320 | } |
|---|
| 329 | 321 | |
|---|
| 330 | | -#ifdef CONFIG_CPU_RK312X |
|---|
| 322 | +#ifdef CONFIG_CLK_RK312X |
|---|
| 331 | 323 | extern void rkclk_cpuclk_div_setting(int div); |
|---|
| 332 | 324 | #else |
|---|
| 333 | 325 | static inline void rkclk_cpuclk_div_setting(int div) {} |
|---|
| .. | .. |
|---|
| 517 | 509 | break; |
|---|
| 518 | 510 | default: |
|---|
| 519 | 511 | dev_warn(&rdev->dev, |
|---|
| 520 | | - "%s ramp_delay: %d not supported, setting 10000\n", |
|---|
| 512 | + "%s ramp_delay: %d not supported, setting 25000\n", |
|---|
| 521 | 513 | rdev->desc->name, ramp_delay); |
|---|
| 522 | 514 | } |
|---|
| 523 | 515 | |
|---|
| .. | .. |
|---|
| 530 | 522 | unsigned int reg; |
|---|
| 531 | 523 | int sel = regulator_map_voltage_linear(rdev, uv, uv); |
|---|
| 532 | 524 | |
|---|
| 533 | | - if (sel < 0) |
|---|
| 534 | | - return -EINVAL; |
|---|
| 535 | | - |
|---|
| 536 | | - reg = rdev->desc->vsel_reg + RK808_SLP_REG_OFFSET; |
|---|
| 537 | | - |
|---|
| 538 | | - return regmap_update_bits(rdev->regmap, reg, |
|---|
| 539 | | - rdev->desc->vsel_mask, |
|---|
| 540 | | - sel); |
|---|
| 541 | | -} |
|---|
| 542 | | - |
|---|
| 543 | | -static int rk817_set_suspend_voltage(struct regulator_dev *rdev, int uv) |
|---|
| 544 | | -{ |
|---|
| 545 | | - unsigned int reg; |
|---|
| 546 | | - int sel = regulator_map_voltage_linear(rdev, uv, uv); |
|---|
| 547 | | - /* only ldo1~ldo9 */ |
|---|
| 548 | 525 | if (sel < 0) |
|---|
| 549 | 526 | return -EINVAL; |
|---|
| 550 | 527 | |
|---|
| .. | .. |
|---|
| 811 | 788 | case 2: |
|---|
| 812 | 789 | return REGULATOR_MODE_NORMAL; |
|---|
| 813 | 790 | default: |
|---|
| 814 | | - return -EINVAL; |
|---|
| 791 | + return REGULATOR_MODE_INVALID; |
|---|
| 815 | 792 | } |
|---|
| 816 | 793 | } |
|---|
| 817 | 794 | |
|---|
| .. | .. |
|---|
| 891 | 868 | .set_suspend_disable = rk808_set_suspend_disable, |
|---|
| 892 | 869 | }; |
|---|
| 893 | 870 | |
|---|
| 894 | | -static struct regulator_ops rk809_buck5_ops_range = { |
|---|
| 871 | +static const struct regulator_ops rk809_buck5_ops_range = { |
|---|
| 895 | 872 | .list_voltage = regulator_list_voltage_linear_range, |
|---|
| 896 | 873 | .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 897 | 874 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| .. | .. |
|---|
| 905 | 882 | .set_suspend_disable = rk817_set_suspend_disable, |
|---|
| 906 | 883 | }; |
|---|
| 907 | 884 | |
|---|
| 908 | | -static struct regulator_ops rk817_reg_ops = { |
|---|
| 885 | +static const struct regulator_ops rk817_reg_ops = { |
|---|
| 909 | 886 | .list_voltage = regulator_list_voltage_linear, |
|---|
| 910 | 887 | .map_voltage = regulator_map_voltage_linear, |
|---|
| 911 | 888 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| .. | .. |
|---|
| 913 | 890 | .enable = rk8xx_enabled_wmsk_regmap, |
|---|
| 914 | 891 | .disable = rk8xx_disabled_wmsk_regmap, |
|---|
| 915 | 892 | .is_enabled = rk8xx_is_enabled_wmsk_regmap, |
|---|
| 916 | | - .set_suspend_voltage = rk817_set_suspend_voltage, |
|---|
| 893 | + .set_suspend_voltage = rk808_set_suspend_voltage, |
|---|
| 917 | 894 | .set_suspend_enable = rk817_set_suspend_enable, |
|---|
| 918 | 895 | .set_suspend_disable = rk817_set_suspend_disable, |
|---|
| 919 | 896 | }; |
|---|
| 920 | 897 | |
|---|
| 921 | | -static struct regulator_ops rk817_boost_ops = { |
|---|
| 898 | +static const struct regulator_ops rk817_boost_ops = { |
|---|
| 922 | 899 | .list_voltage = regulator_list_voltage_linear, |
|---|
| 923 | 900 | .map_voltage = regulator_map_voltage_linear, |
|---|
| 924 | 901 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| .. | .. |
|---|
| 930 | 907 | .set_suspend_disable = rk817_set_suspend_disable, |
|---|
| 931 | 908 | }; |
|---|
| 932 | 909 | |
|---|
| 933 | | -static struct regulator_ops rk817_buck_ops_range = { |
|---|
| 910 | +static const struct regulator_ops rk817_buck_ops_range = { |
|---|
| 934 | 911 | .list_voltage = regulator_list_voltage_linear_range, |
|---|
| 935 | 912 | .map_voltage = regulator_map_voltage_linear_range, |
|---|
| 936 | 913 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
|---|
| .. | .. |
|---|
| 948 | 925 | .set_suspend_disable = rk817_set_suspend_disable, |
|---|
| 949 | 926 | }; |
|---|
| 950 | 927 | |
|---|
| 951 | | -static struct regulator_ops rk817_switch_ops = { |
|---|
| 928 | +static const struct regulator_ops rk817_switch_ops = { |
|---|
| 952 | 929 | .enable = rk8xx_enabled_wmsk_regmap, |
|---|
| 953 | 930 | .disable = rk8xx_disabled_wmsk_regmap, |
|---|
| 954 | 931 | .is_enabled = rk8xx_is_enabled_wmsk_regmap, |
|---|
| .. | .. |
|---|
| 1135 | 1112 | RK8XX_DESC_SWITCH(RK808_ID_SWITCH2, "SWITCH_REG2", "vcc12", |
|---|
| 1136 | 1113 | RK808_DCDC_EN_REG, BIT(6)), |
|---|
| 1137 | 1114 | }; |
|---|
| 1138 | | - |
|---|
| 1139 | 1115 | |
|---|
| 1140 | 1116 | static const struct regulator_desc rk816_reg[] = { |
|---|
| 1141 | 1117 | { |
|---|
| .. | .. |
|---|
| 1730 | 1706 | module_platform_driver(rk808_regulator_driver); |
|---|
| 1731 | 1707 | #endif |
|---|
| 1732 | 1708 | |
|---|
| 1733 | | -MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK809/RK817/RK818 series PMICs"); |
|---|
| 1709 | +MODULE_DESCRIPTION("regulator driver for the RK805/RK808/RK816/RK818 series PMICs"); |
|---|
| 1734 | 1710 | MODULE_AUTHOR("Tony xie <tony.xie@rock-chips.com>"); |
|---|
| 1735 | 1711 | MODULE_AUTHOR("Chris Zhong <zyw@rock-chips.com>"); |
|---|
| 1736 | 1712 | MODULE_AUTHOR("Zhang Qing <zhangqing@rock-chips.com>"); |
|---|