Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2015 Google, Inc |
| 4 | * Written by Simon Glass <sjg@chromium.org> |
| 5 | * |
| 6 | * Based on Rockchip's drivers/power/pmic/pmic_rk808.c: |
| 7 | * Copyright (C) 2012 rockchips |
| 8 | * zyw <zyw@rock-chips.com> |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 9 | */ |
| 10 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 11 | #include <dm.h> |
| 12 | #include <errno.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Jonas Karlman | 31c3c80 | 2023-07-02 12:41:15 +0000 | [diff] [blame] | 14 | #include <linux/delay.h> |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 15 | #include <power/rk8xx_pmic.h> |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 16 | #include <power/pmic.h> |
| 17 | #include <power/regulator.h> |
| 18 | |
| 19 | #ifndef CONFIG_SPL_BUILD |
| 20 | #define ENABLE_DRIVER |
| 21 | #endif |
| 22 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 23 | /* Not used or exisit register and configure */ |
| 24 | #define NA 0xff |
| 25 | |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 26 | /* Field Definitions */ |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 27 | #define RK806_BUCK_CONFIG(n) (0x10 + (n) - 1) |
| 28 | #define RK806_BUCK_ON_VSEL(n) (0x1a + (n) - 1) |
| 29 | #define RK806_BUCK_SLP_VSEL(n) (0x24 + (n) - 1) |
| 30 | #define RK806_BUCK_VSEL_MASK 0xff |
| 31 | |
| 32 | #define RK806_NLDO_ON_VSEL(n) (0x43 + (n) - 1) |
| 33 | #define RK806_NLDO_SLP_VSEL(n) (0x48 + (n) - 1) |
| 34 | #define RK806_NLDO_VSEL_MASK 0xff |
| 35 | |
| 36 | #define RK806_PLDO_ON_VSEL(n) (0x4e + (n) - 1) |
| 37 | #define RK806_PLDO_SLP_VSEL(n) (0x54 + (n) - 1) |
| 38 | #define RK806_PLDO_VSEL_MASK 0xff |
| 39 | |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 40 | #define RK808_BUCK_VSEL_MASK 0x3f |
| 41 | #define RK808_BUCK4_VSEL_MASK 0xf |
| 42 | #define RK808_LDO_VSEL_MASK 0x1f |
| 43 | |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 44 | /* RK809 BUCK5 */ |
| 45 | #define RK809_BUCK5_CONFIG(n) (0xde + (n) * 1) |
| 46 | #define RK809_BUCK5_VSEL_MASK 0x07 |
| 47 | |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 48 | /* RK817 BUCK */ |
| 49 | #define RK817_BUCK_ON_VSEL(n) (0xbb + 3 * ((n) - 1)) |
| 50 | #define RK817_BUCK_SLP_VSEL(n) (0xbc + 3 * ((n) - 1)) |
| 51 | #define RK817_BUCK_VSEL_MASK 0x7f |
| 52 | #define RK817_BUCK_CONFIG(i) (0xba + (i) * 3) |
| 53 | |
| 54 | /* RK817 LDO */ |
| 55 | #define RK817_LDO_ON_VSEL(n) (0xcc + 2 * ((n) - 1)) |
| 56 | #define RK817_LDO_SLP_VSEL(n) (0xcd + 2 * ((n) - 1)) |
| 57 | #define RK817_LDO_VSEL_MASK 0x7f |
| 58 | |
| 59 | /* RK817 ENABLE */ |
| 60 | #define RK817_POWER_EN(n) (0xb1 + (n)) |
| 61 | #define RK817_POWER_SLP_EN(n) (0xb5 + (n)) |
| 62 | |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 63 | #define RK818_BUCK_VSEL_MASK 0x3f |
| 64 | #define RK818_BUCK4_VSEL_MASK 0x1f |
| 65 | #define RK818_LDO_VSEL_MASK 0x1f |
| 66 | #define RK818_LDO3_ON_VSEL_MASK 0xf |
| 67 | #define RK818_BOOST_ON_VSEL_MASK 0xe0 |
Wadim Egorov | c258105 | 2017-06-19 12:36:39 +0200 | [diff] [blame] | 68 | #define RK818_USB_ILIM_SEL_MASK 0x0f |
| 69 | #define RK818_USB_CHG_SD_VSEL_MASK 0x70 |
| 70 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 71 | /* |
| 72 | * Ramp delay |
| 73 | */ |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 74 | #define RK805_RAMP_RATE_OFFSET 3 |
| 75 | #define RK805_RAMP_RATE_MASK (3 << RK805_RAMP_RATE_OFFSET) |
| 76 | #define RK805_RAMP_RATE_3MV_PER_US (0 << RK805_RAMP_RATE_OFFSET) |
| 77 | #define RK805_RAMP_RATE_6MV_PER_US (1 << RK805_RAMP_RATE_OFFSET) |
| 78 | #define RK805_RAMP_RATE_12_5MV_PER_US (2 << RK805_RAMP_RATE_OFFSET) |
| 79 | #define RK805_RAMP_RATE_25MV_PER_US (3 << RK805_RAMP_RATE_OFFSET) |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 80 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 81 | #define RK808_RAMP_RATE_OFFSET 3 |
| 82 | #define RK808_RAMP_RATE_MASK (3 << RK808_RAMP_RATE_OFFSET) |
| 83 | #define RK808_RAMP_RATE_2MV_PER_US (0 << RK808_RAMP_RATE_OFFSET) |
| 84 | #define RK808_RAMP_RATE_4MV_PER_US (1 << RK808_RAMP_RATE_OFFSET) |
| 85 | #define RK808_RAMP_RATE_6MV_PER_US (2 << RK808_RAMP_RATE_OFFSET) |
| 86 | #define RK808_RAMP_RATE_10MV_PER_US (3 << RK808_RAMP_RATE_OFFSET) |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 87 | |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 88 | #define RK817_RAMP_RATE_OFFSET 6 |
| 89 | #define RK817_RAMP_RATE_MASK (0x3 << RK817_RAMP_RATE_OFFSET) |
| 90 | #define RK817_RAMP_RATE_3MV_PER_US (0x0 << RK817_RAMP_RATE_OFFSET) |
| 91 | #define RK817_RAMP_RATE_6_3MV_PER_US (0x1 << RK817_RAMP_RATE_OFFSET) |
| 92 | #define RK817_RAMP_RATE_12_5MV_PER_US (0x2 << RK817_RAMP_RATE_OFFSET) |
| 93 | #define RK817_RAMP_RATE_25MV_PER_US (0x3 << RK817_RAMP_RATE_OFFSET) |
| 94 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 95 | struct rk8xx_reg_info { |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 96 | uint min_uv; |
| 97 | uint step_uv; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 98 | u8 vsel_reg; |
| 99 | u8 vsel_sleep_reg; |
| 100 | u8 config_reg; |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 101 | u8 vsel_mask; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 102 | u8 min_sel; |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 103 | u8 max_sel; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 104 | }; |
| 105 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 106 | static const struct rk8xx_reg_info rk806_buck[] = { |
| 107 | /* buck 1 */ |
| 108 | { 500000, 6250, RK806_BUCK_ON_VSEL(1), RK806_BUCK_SLP_VSEL(1), RK806_BUCK_CONFIG(1), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 109 | { 1500000, 25000, RK806_BUCK_ON_VSEL(1), RK806_BUCK_SLP_VSEL(1), RK806_BUCK_CONFIG(1), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 110 | { 3400000, 0, RK806_BUCK_ON_VSEL(1), RK806_BUCK_SLP_VSEL(1), RK806_BUCK_CONFIG(1), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 111 | /* buck 2 */ |
| 112 | { 500000, 6250, RK806_BUCK_ON_VSEL(2), RK806_BUCK_SLP_VSEL(2), RK806_BUCK_CONFIG(2), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 113 | { 1500000, 25000, RK806_BUCK_ON_VSEL(2), RK806_BUCK_SLP_VSEL(2), RK806_BUCK_CONFIG(2), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 114 | { 3400000, 0, RK806_BUCK_ON_VSEL(2), RK806_BUCK_SLP_VSEL(2), RK806_BUCK_CONFIG(2), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 115 | /* buck 3 */ |
| 116 | { 500000, 6250, RK806_BUCK_ON_VSEL(3), RK806_BUCK_SLP_VSEL(3), RK806_BUCK_CONFIG(3), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 117 | { 1500000, 25000, RK806_BUCK_ON_VSEL(3), RK806_BUCK_SLP_VSEL(3), RK806_BUCK_CONFIG(3), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 118 | { 3400000, 0, RK806_BUCK_ON_VSEL(3), RK806_BUCK_SLP_VSEL(3), RK806_BUCK_CONFIG(3), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 119 | /* buck 4 */ |
| 120 | { 500000, 6250, RK806_BUCK_ON_VSEL(4), RK806_BUCK_SLP_VSEL(4), RK806_BUCK_CONFIG(4), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 121 | { 1500000, 25000, RK806_BUCK_ON_VSEL(4), RK806_BUCK_SLP_VSEL(4), RK806_BUCK_CONFIG(4), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 122 | { 3400000, 0, RK806_BUCK_ON_VSEL(4), RK806_BUCK_SLP_VSEL(4), RK806_BUCK_CONFIG(4), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 123 | /* buck 5 */ |
| 124 | { 500000, 6250, RK806_BUCK_ON_VSEL(5), RK806_BUCK_SLP_VSEL(5), RK806_BUCK_CONFIG(5), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 125 | { 1500000, 25000, RK806_BUCK_ON_VSEL(5), RK806_BUCK_SLP_VSEL(5), RK806_BUCK_CONFIG(5), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 126 | { 3400000, 0, RK806_BUCK_ON_VSEL(5), RK806_BUCK_SLP_VSEL(5), RK806_BUCK_CONFIG(5), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 127 | /* buck 6 */ |
| 128 | { 500000, 6250, RK806_BUCK_ON_VSEL(6), RK806_BUCK_SLP_VSEL(6), RK806_BUCK_CONFIG(6), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 129 | { 1500000, 25000, RK806_BUCK_ON_VSEL(6), RK806_BUCK_SLP_VSEL(6), RK806_BUCK_CONFIG(6), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 130 | { 3400000, 0, RK806_BUCK_ON_VSEL(6), RK806_BUCK_SLP_VSEL(6), RK806_BUCK_CONFIG(6), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 131 | /* buck 7 */ |
| 132 | { 500000, 6250, RK806_BUCK_ON_VSEL(7), RK806_BUCK_SLP_VSEL(7), RK806_BUCK_CONFIG(7), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 133 | { 1500000, 25000, RK806_BUCK_ON_VSEL(7), RK806_BUCK_SLP_VSEL(7), RK806_BUCK_CONFIG(7), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 134 | { 3400000, 0, RK806_BUCK_ON_VSEL(7), RK806_BUCK_SLP_VSEL(7), RK806_BUCK_CONFIG(7), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 135 | /* buck 8 */ |
| 136 | { 500000, 6250, RK806_BUCK_ON_VSEL(8), RK806_BUCK_SLP_VSEL(8), RK806_BUCK_CONFIG(8), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 137 | { 1500000, 25000, RK806_BUCK_ON_VSEL(8), RK806_BUCK_SLP_VSEL(8), RK806_BUCK_CONFIG(8), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 138 | { 3400000, 0, RK806_BUCK_ON_VSEL(8), RK806_BUCK_SLP_VSEL(8), RK806_BUCK_CONFIG(8), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 139 | /* buck 9 */ |
| 140 | { 500000, 6250, RK806_BUCK_ON_VSEL(9), RK806_BUCK_SLP_VSEL(9), RK806_BUCK_CONFIG(9), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 141 | { 1500000, 25000, RK806_BUCK_ON_VSEL(9), RK806_BUCK_SLP_VSEL(9), RK806_BUCK_CONFIG(9), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 142 | { 3400000, 0, RK806_BUCK_ON_VSEL(9), RK806_BUCK_SLP_VSEL(9), RK806_BUCK_CONFIG(9), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 143 | /* buck 10 */ |
| 144 | { 500000, 6250, RK806_BUCK_ON_VSEL(10), RK806_BUCK_SLP_VSEL(10), RK806_BUCK_CONFIG(10), RK806_BUCK_VSEL_MASK, 0x00, 0x9f }, |
| 145 | { 1500000, 25000, RK806_BUCK_ON_VSEL(10), RK806_BUCK_SLP_VSEL(10), RK806_BUCK_CONFIG(10), RK806_BUCK_VSEL_MASK, 0xa0, 0xeb }, |
| 146 | { 3400000, 0, RK806_BUCK_ON_VSEL(10), RK806_BUCK_SLP_VSEL(10), RK806_BUCK_CONFIG(10), RK806_BUCK_VSEL_MASK, 0xec, 0xff }, |
| 147 | }; |
| 148 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 149 | static const struct rk8xx_reg_info rk808_buck[] = { |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 150 | { 712500, 12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK808_BUCK_VSEL_MASK, 0x00, 0x3f }, |
| 151 | { 712500, 12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK808_BUCK_VSEL_MASK, 0x00, 0x3f }, |
| 152 | { NA, NA, NA, NA, REG_BUCK3_CONFIG, NA, NA, NA }, |
| 153 | { 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK808_BUCK4_VSEL_MASK, 0x00, 0x0f }, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 154 | }; |
| 155 | |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 156 | static const struct rk8xx_reg_info rk816_buck[] = { |
| 157 | /* buck 1 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 158 | { 712500, 12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, 0x3b }, |
| 159 | { 1800000, 200000, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, 0x3e }, |
| 160 | { 2300000, 0, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, 0x3f }, |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 161 | /* buck 2 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 162 | { 712500, 12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, 0x3b }, |
| 163 | { 1800000, 200000, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3c, 0x3e }, |
| 164 | { 2300000, 0, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x3f, 0x3f }, |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 165 | /* buck 3 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 166 | { NA, NA, NA, NA, REG_BUCK3_CONFIG, NA, NA, NA }, |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 167 | /* buck 4 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 168 | { 800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f }, |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 169 | }; |
| 170 | |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 171 | static const struct rk8xx_reg_info rk809_buck5[] = { |
| 172 | /* buck 5 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 173 | { 1500000, 0, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x00, 0x00 }, |
| 174 | { 1800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x01, 0x03 }, |
| 175 | { 2800000, 200000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x04, 0x05 }, |
| 176 | { 3300000, 300000, RK809_BUCK5_CONFIG(0), RK809_BUCK5_CONFIG(1), NA, RK809_BUCK5_VSEL_MASK, 0x06, 0x07 }, |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 177 | }; |
| 178 | |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 179 | static const struct rk8xx_reg_info rk817_buck[] = { |
| 180 | /* buck 1 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 181 | { 500000, 12500, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x00, 0x4f }, |
| 182 | { 1500000, 100000, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x50, 0x58 }, |
| 183 | { 2400000, 0, RK817_BUCK_ON_VSEL(1), RK817_BUCK_SLP_VSEL(1), RK817_BUCK_CONFIG(1), RK817_BUCK_VSEL_MASK, 0x59, 0x7f }, |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 184 | /* buck 2 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 185 | { 500000, 12500, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x00, 0x4f }, |
| 186 | { 1500000, 100000, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x50, 0x58 }, |
| 187 | { 2400000, 0, RK817_BUCK_ON_VSEL(2), RK817_BUCK_SLP_VSEL(2), RK817_BUCK_CONFIG(2), RK817_BUCK_VSEL_MASK, 0x59, 0x7f }, |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 188 | /* buck 3 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 189 | { 500000, 12500, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x00, 0x4f }, |
| 190 | { 1500000, 100000, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x50, 0x58 }, |
| 191 | { 2400000, 0, RK817_BUCK_ON_VSEL(3), RK817_BUCK_SLP_VSEL(3), RK817_BUCK_CONFIG(3), RK817_BUCK_VSEL_MASK, 0x59, 0x7f }, |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 192 | /* buck 4 */ |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 193 | { 500000, 12500, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x00, 0x4f }, |
| 194 | { 1500000, 100000, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x50, 0x62 }, |
| 195 | { 3400000, 0, RK817_BUCK_ON_VSEL(4), RK817_BUCK_SLP_VSEL(4), RK817_BUCK_CONFIG(4), RK817_BUCK_VSEL_MASK, 0x63, 0x7f }, |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 196 | }; |
| 197 | |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 198 | static const struct rk8xx_reg_info rk818_buck[] = { |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 199 | { 712500, 12500, REG_BUCK1_ON_VSEL, REG_BUCK1_SLP_VSEL, REG_BUCK1_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, 0x3f }, |
| 200 | { 712500, 12500, REG_BUCK2_ON_VSEL, REG_BUCK2_SLP_VSEL, REG_BUCK2_CONFIG, RK818_BUCK_VSEL_MASK, 0x00, 0x3f }, |
| 201 | { NA, NA, NA, NA, REG_BUCK3_CONFIG, NA, NA, NA }, |
| 202 | { 1800000, 100000, REG_BUCK4_ON_VSEL, REG_BUCK4_SLP_VSEL, REG_BUCK4_CONFIG, RK818_BUCK4_VSEL_MASK, 0x00, 0x1f }, |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 203 | }; |
| 204 | |
| 205 | #ifdef ENABLE_DRIVER |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 206 | static const struct rk8xx_reg_info rk806_nldo[] = { |
| 207 | /* nldo 1 */ |
| 208 | { 500000, 12500, RK806_NLDO_ON_VSEL(1), RK806_NLDO_SLP_VSEL(1), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, |
| 209 | { 3400000, 0, RK806_NLDO_ON_VSEL(1), RK806_NLDO_SLP_VSEL(1), NA, RK806_NLDO_VSEL_MASK, 0xe8, 0xff}, |
| 210 | /* nldo 2 */ |
| 211 | { 500000, 12500, RK806_NLDO_ON_VSEL(2), RK806_NLDO_SLP_VSEL(2), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, |
| 212 | { 3400000, 0, RK806_NLDO_ON_VSEL(2), RK806_NLDO_SLP_VSEL(2), NA, RK806_NLDO_VSEL_MASK, 0xe8, 0xff}, |
| 213 | /* nldo 3 */ |
| 214 | { 500000, 12500, RK806_NLDO_ON_VSEL(3), RK806_NLDO_SLP_VSEL(3), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, |
| 215 | { 3400000, 0, RK806_NLDO_ON_VSEL(3), RK806_NLDO_SLP_VSEL(3), NA, RK806_NLDO_VSEL_MASK, 0xe8, 0xff}, |
| 216 | /* nldo 4 */ |
| 217 | { 500000, 12500, RK806_NLDO_ON_VSEL(4), RK806_NLDO_SLP_VSEL(4), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, |
| 218 | { 3400000, 0, RK806_NLDO_ON_VSEL(4), RK806_NLDO_SLP_VSEL(4), NA, RK806_NLDO_VSEL_MASK, 0xe8, 0xff}, |
| 219 | /* nldo 5 */ |
| 220 | { 500000, 12500, RK806_NLDO_ON_VSEL(5), RK806_NLDO_SLP_VSEL(5), NA, RK806_NLDO_VSEL_MASK, 0x00, 0xe7}, |
| 221 | { 3400000, 0, RK806_NLDO_ON_VSEL(5), RK806_NLDO_SLP_VSEL(5), NA, RK806_NLDO_VSEL_MASK, 0xe8, 0xff}, |
| 222 | }; |
| 223 | |
| 224 | static const struct rk8xx_reg_info rk806_pldo[] = { |
| 225 | /* pldo 1 */ |
| 226 | { 500000, 12500, RK806_PLDO_ON_VSEL(1), RK806_PLDO_SLP_VSEL(1), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 227 | { 3400000, 0, RK806_PLDO_ON_VSEL(1), RK806_PLDO_SLP_VSEL(1), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 228 | /* pldo 2 */ |
| 229 | { 500000, 12500, RK806_PLDO_ON_VSEL(2), RK806_PLDO_SLP_VSEL(2), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 230 | { 3400000, 0, RK806_PLDO_ON_VSEL(2), RK806_PLDO_SLP_VSEL(2), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 231 | /* pldo 3 */ |
| 232 | { 500000, 12500, RK806_PLDO_ON_VSEL(3), RK806_PLDO_SLP_VSEL(3), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 233 | { 3400000, 0, RK806_PLDO_ON_VSEL(3), RK806_PLDO_SLP_VSEL(3), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 234 | /* pldo 4 */ |
| 235 | { 500000, 12500, RK806_PLDO_ON_VSEL(4), RK806_PLDO_SLP_VSEL(4), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 236 | { 3400000, 0, RK806_PLDO_ON_VSEL(4), RK806_PLDO_SLP_VSEL(4), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 237 | /* pldo 5 */ |
| 238 | { 500000, 12500, RK806_PLDO_ON_VSEL(5), RK806_PLDO_SLP_VSEL(5), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 239 | { 3400000, 0, RK806_PLDO_ON_VSEL(5), RK806_PLDO_SLP_VSEL(5), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 240 | /* pldo 6 */ |
| 241 | { 500000, 12500, RK806_PLDO_ON_VSEL(6), RK806_PLDO_SLP_VSEL(6), NA, RK806_PLDO_VSEL_MASK, 0x00, 0xe7}, |
| 242 | { 3400000, 0, RK806_PLDO_ON_VSEL(6), RK806_PLDO_SLP_VSEL(6), NA, RK806_PLDO_VSEL_MASK, 0xe8, 0xff}, |
| 243 | }; |
| 244 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 245 | static const struct rk8xx_reg_info rk808_ldo[] = { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 246 | { 1800000, 100000, REG_LDO1_ON_VSEL, REG_LDO1_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 247 | { 1800000, 100000, REG_LDO2_ON_VSEL, REG_LDO2_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 248 | { 800000, 100000, REG_LDO3_ON_VSEL, REG_LDO3_SLP_VSEL, NA, RK808_BUCK4_VSEL_MASK, }, |
| 249 | { 1800000, 100000, REG_LDO4_ON_VSEL, REG_LDO4_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 250 | { 1800000, 100000, REG_LDO5_ON_VSEL, REG_LDO5_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 251 | { 800000, 100000, REG_LDO6_ON_VSEL, REG_LDO6_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 252 | { 800000, 100000, REG_LDO7_ON_VSEL, REG_LDO7_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
| 253 | { 1800000, 100000, REG_LDO8_ON_VSEL, REG_LDO8_SLP_VSEL, NA, RK808_LDO_VSEL_MASK, }, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 254 | }; |
| 255 | |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 256 | static const struct rk8xx_reg_info rk816_ldo[] = { |
| 257 | { 800000, 100000, REG_LDO1_ON_VSEL, REG_LDO1_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 258 | { 800000, 100000, REG_LDO2_ON_VSEL, REG_LDO2_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 259 | { 800000, 100000, REG_LDO3_ON_VSEL, REG_LDO3_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 260 | { 800000, 100000, REG_LDO4_ON_VSEL, REG_LDO4_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 261 | { 800000, 100000, REG_LDO5_ON_VSEL, REG_LDO5_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 262 | { 800000, 100000, REG_LDO6_ON_VSEL, REG_LDO6_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 263 | }; |
| 264 | |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 265 | static const struct rk8xx_reg_info rk817_ldo[] = { |
| 266 | /* ldo1 */ |
| 267 | { 600000, 25000, RK817_LDO_ON_VSEL(1), RK817_LDO_SLP_VSEL(1), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 268 | { 3400000, 0, RK817_LDO_ON_VSEL(1), RK817_LDO_SLP_VSEL(1), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 269 | /* ldo2 */ |
| 270 | { 600000, 25000, RK817_LDO_ON_VSEL(2), RK817_LDO_SLP_VSEL(2), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 271 | { 3400000, 0, RK817_LDO_ON_VSEL(2), RK817_LDO_SLP_VSEL(2), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 272 | /* ldo3 */ |
| 273 | { 600000, 25000, RK817_LDO_ON_VSEL(3), RK817_LDO_SLP_VSEL(3), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 274 | { 3400000, 0, RK817_LDO_ON_VSEL(3), RK817_LDO_SLP_VSEL(3), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 275 | /* ldo4 */ |
| 276 | { 600000, 25000, RK817_LDO_ON_VSEL(4), RK817_LDO_SLP_VSEL(4), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 277 | { 3400000, 0, RK817_LDO_ON_VSEL(4), RK817_LDO_SLP_VSEL(4), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 278 | /* ldo5 */ |
| 279 | { 600000, 25000, RK817_LDO_ON_VSEL(5), RK817_LDO_SLP_VSEL(5), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 280 | { 3400000, 0, RK817_LDO_ON_VSEL(5), RK817_LDO_SLP_VSEL(5), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 281 | /* ldo6 */ |
| 282 | { 600000, 25000, RK817_LDO_ON_VSEL(6), RK817_LDO_SLP_VSEL(6), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 283 | { 3400000, 0, RK817_LDO_ON_VSEL(6), RK817_LDO_SLP_VSEL(6), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 284 | /* ldo7 */ |
| 285 | { 600000, 25000, RK817_LDO_ON_VSEL(7), RK817_LDO_SLP_VSEL(7), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 286 | { 3400000, 0, RK817_LDO_ON_VSEL(7), RK817_LDO_SLP_VSEL(7), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 287 | /* ldo8 */ |
| 288 | { 600000, 25000, RK817_LDO_ON_VSEL(8), RK817_LDO_SLP_VSEL(8), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 289 | { 3400000, 0, RK817_LDO_ON_VSEL(8), RK817_LDO_SLP_VSEL(8), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 290 | /* ldo9 */ |
| 291 | { 600000, 25000, RK817_LDO_ON_VSEL(9), RK817_LDO_SLP_VSEL(9), NA, RK817_LDO_VSEL_MASK, 0x00, }, |
| 292 | { 3400000, 0, RK817_LDO_ON_VSEL(9), RK817_LDO_SLP_VSEL(9), NA, RK817_LDO_VSEL_MASK, 0x70, }, |
| 293 | }; |
| 294 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 295 | static const struct rk8xx_reg_info rk818_ldo[] = { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 296 | { 1800000, 100000, REG_LDO1_ON_VSEL, REG_LDO1_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 297 | { 1800000, 100000, REG_LDO2_ON_VSEL, REG_LDO2_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 298 | { 800000, 100000, REG_LDO3_ON_VSEL, REG_LDO3_SLP_VSEL, NA, RK818_LDO3_ON_VSEL_MASK, }, |
| 299 | { 1800000, 100000, REG_LDO4_ON_VSEL, REG_LDO4_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 300 | { 1800000, 100000, REG_LDO5_ON_VSEL, REG_LDO5_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 301 | { 800000, 100000, REG_LDO6_ON_VSEL, REG_LDO6_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 302 | { 800000, 100000, REG_LDO7_ON_VSEL, REG_LDO7_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
| 303 | { 1800000, 100000, REG_LDO8_ON_VSEL, REG_LDO8_SLP_VSEL, NA, RK818_LDO_VSEL_MASK, }, |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 304 | }; |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 305 | #endif |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 306 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 307 | static const struct rk8xx_reg_info *get_buck_reg(struct udevice *pmic, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 308 | int num, int uvolt) |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 309 | { |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 310 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 311 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 312 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 313 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 314 | case RK816_ID: |
| 315 | switch (num) { |
| 316 | case 0: |
| 317 | case 1: |
| 318 | if (uvolt <= 1450000) |
| 319 | return &rk816_buck[num * 3 + 0]; |
| 320 | else if (uvolt <= 2200000) |
| 321 | return &rk816_buck[num * 3 + 1]; |
| 322 | else |
| 323 | return &rk816_buck[num * 3 + 2]; |
| 324 | default: |
| 325 | return &rk816_buck[num + 4]; |
| 326 | } |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 327 | case RK806_ID: |
| 328 | if (uvolt < 1500000) |
| 329 | return &rk806_buck[num * 3 + 0]; |
| 330 | else if (uvolt < 3400000) |
| 331 | return &rk806_buck[num * 3 + 1]; |
| 332 | return &rk806_buck[num * 3 + 2]; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 333 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 334 | case RK817_ID: |
| 335 | switch (num) { |
| 336 | case 0 ... 2: |
| 337 | if (uvolt < 1500000) |
| 338 | return &rk817_buck[num * 3 + 0]; |
| 339 | else if (uvolt < 2400000) |
| 340 | return &rk817_buck[num * 3 + 1]; |
| 341 | else |
| 342 | return &rk817_buck[num * 3 + 2]; |
| 343 | case 3: |
| 344 | if (uvolt < 1500000) |
| 345 | return &rk817_buck[num * 3 + 0]; |
| 346 | else if (uvolt < 3400000) |
| 347 | return &rk817_buck[num * 3 + 1]; |
| 348 | else |
| 349 | return &rk817_buck[num * 3 + 2]; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 350 | /* BUCK5 for RK809 */ |
| 351 | default: |
| 352 | if (uvolt < 1800000) |
| 353 | return &rk809_buck5[0]; |
| 354 | else if (uvolt < 2800000) |
| 355 | return &rk809_buck5[1]; |
| 356 | else if (uvolt < 3300000) |
| 357 | return &rk809_buck5[2]; |
| 358 | else |
| 359 | return &rk809_buck5[3]; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 360 | } |
Jacob Chen | 36163e3 | 2017-05-02 14:54:51 +0800 | [diff] [blame] | 361 | case RK818_ID: |
| 362 | return &rk818_buck[num]; |
| 363 | default: |
| 364 | return &rk808_buck[num]; |
| 365 | } |
| 366 | } |
| 367 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 368 | static int _buck_set_value(struct udevice *pmic, int buck, int uvolt) |
| 369 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 370 | const struct rk8xx_reg_info *info = get_buck_reg(pmic, buck, uvolt); |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 371 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 372 | int mask = info->vsel_mask; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 373 | int val; |
| 374 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 375 | if (info->vsel_reg == NA) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 376 | return -ENOSYS; |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 377 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 378 | if (info->step_uv == 0) /* Fixed voltage */ |
| 379 | val = info->min_sel; |
| 380 | else |
| 381 | val = ((uvolt - info->min_uv) / info->step_uv) + info->min_sel; |
| 382 | |
| 383 | debug("%s: volt=%d, buck=%d, reg=0x%x, mask=0x%x, val=0x%x\n", |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 384 | __func__, uvolt, buck, info->vsel_reg, mask, val); |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 385 | |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 386 | if (priv->variant == RK816_ID) { |
| 387 | pmic_clrsetbits(pmic, info->vsel_reg, mask, val); |
| 388 | return pmic_clrsetbits(pmic, RK816_REG_DCDC_EN2, |
| 389 | 1 << 7, 1 << 7); |
| 390 | } else { |
| 391 | return pmic_clrsetbits(pmic, info->vsel_reg, mask, val); |
| 392 | } |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | static int _buck_set_enable(struct udevice *pmic, int buck, bool enable) |
| 396 | { |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 397 | uint mask, value, en_reg; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 398 | int ret = 0; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 399 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 400 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 401 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 402 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 403 | case RK816_ID: |
| 404 | if (buck >= 4) { |
| 405 | buck -= 4; |
| 406 | en_reg = RK816_REG_DCDC_EN2; |
| 407 | } else { |
| 408 | en_reg = RK816_REG_DCDC_EN1; |
| 409 | } |
| 410 | if (enable) |
| 411 | value = ((1 << buck) | (1 << (buck + 4))); |
| 412 | else |
| 413 | value = ((0 << buck) | (1 << (buck + 4))); |
| 414 | ret = pmic_reg_write(pmic, en_reg, value); |
| 415 | break; |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 416 | case RK806_ID: |
| 417 | value = RK806_POWER_EN_CLRSETBITS(buck % 4, enable); |
Jonas Karlman | 2942516 | 2024-09-17 20:59:17 +0000 | [diff] [blame] | 418 | en_reg = RK806_POWER_EN(buck / 4); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 419 | ret = pmic_reg_write(pmic, en_reg, value); |
| 420 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 421 | case RK808_ID: |
| 422 | case RK818_ID: |
| 423 | mask = 1 << buck; |
| 424 | if (enable) { |
| 425 | ret = pmic_clrsetbits(pmic, REG_DCDC_ILMAX, |
| 426 | 0, 3 << (buck * 2)); |
| 427 | if (ret) |
| 428 | return ret; |
| 429 | } |
| 430 | ret = pmic_clrsetbits(pmic, REG_DCDC_EN, mask, |
| 431 | enable ? mask : 0); |
| 432 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 433 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 434 | case RK817_ID: |
| 435 | if (buck < 4) { |
| 436 | if (enable) |
| 437 | value = ((1 << buck) | (1 << (buck + 4))); |
| 438 | else |
| 439 | value = ((0 << buck) | (1 << (buck + 4))); |
| 440 | ret = pmic_reg_write(pmic, RK817_POWER_EN(0), value); |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 441 | /* BUCK5 for RK809 */ |
| 442 | } else { |
| 443 | if (enable) |
| 444 | value = ((1 << 1) | (1 << 5)); |
| 445 | else |
| 446 | value = ((0 << 1) | (1 << 5)); |
| 447 | ret = pmic_reg_write(pmic, RK817_POWER_EN(3), value); |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 448 | } |
| 449 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 450 | default: |
| 451 | ret = -EINVAL; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 452 | } |
| 453 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 454 | return ret; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | #ifdef ENABLE_DRIVER |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 458 | static int _buck_set_suspend_value(struct udevice *pmic, int buck, int uvolt) |
| 459 | { |
| 460 | const struct rk8xx_reg_info *info = get_buck_reg(pmic, buck, uvolt); |
| 461 | int mask = info->vsel_mask; |
| 462 | int val; |
| 463 | |
| 464 | if (info->vsel_sleep_reg == NA) |
| 465 | return -ENOSYS; |
| 466 | |
| 467 | if (info->step_uv == 0) |
| 468 | val = info->min_sel; |
| 469 | else |
| 470 | val = ((uvolt - info->min_uv) / info->step_uv) + info->min_sel; |
| 471 | |
| 472 | debug("%s: volt=%d, buck=%d, reg=0x%x, mask=0x%x, val=0x%x\n", |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 473 | __func__, uvolt, buck, info->vsel_sleep_reg, mask, val); |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 474 | |
| 475 | return pmic_clrsetbits(pmic, info->vsel_sleep_reg, mask, val); |
| 476 | } |
| 477 | |
| 478 | static int _buck_get_enable(struct udevice *pmic, int buck) |
| 479 | { |
| 480 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 481 | uint mask = 0; |
| 482 | int ret = 0; |
| 483 | |
| 484 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 485 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 486 | case RK816_ID: |
| 487 | if (buck >= 4) { |
| 488 | mask = 1 << (buck - 4); |
| 489 | ret = pmic_reg_read(pmic, RK816_REG_DCDC_EN2); |
| 490 | } else { |
| 491 | mask = 1 << buck; |
| 492 | ret = pmic_reg_read(pmic, RK816_REG_DCDC_EN1); |
| 493 | } |
| 494 | break; |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 495 | case RK806_ID: |
| 496 | mask = BIT(buck % 4); |
Jonas Karlman | 2942516 | 2024-09-17 20:59:17 +0000 | [diff] [blame] | 497 | ret = pmic_reg_read(pmic, RK806_POWER_EN(buck / 4)); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 498 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 499 | case RK808_ID: |
| 500 | case RK818_ID: |
| 501 | mask = 1 << buck; |
| 502 | ret = pmic_reg_read(pmic, REG_DCDC_EN); |
| 503 | if (ret < 0) |
| 504 | return ret; |
| 505 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 506 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 507 | case RK817_ID: |
| 508 | if (buck < 4) { |
| 509 | mask = 1 << buck; |
| 510 | ret = pmic_reg_read(pmic, RK817_POWER_EN(0)); |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 511 | /* BUCK5 for RK809 */ |
| 512 | } else { |
| 513 | mask = 1 << 1; |
| 514 | ret = pmic_reg_read(pmic, RK817_POWER_EN(3)); |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 515 | } |
| 516 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 517 | } |
| 518 | |
| 519 | if (ret < 0) |
| 520 | return ret; |
| 521 | |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 522 | return (ret & mask) ? true : false; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | static int _buck_set_suspend_enable(struct udevice *pmic, int buck, bool enable) |
| 526 | { |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 527 | uint mask = 0; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 528 | int ret; |
| 529 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 530 | |
| 531 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 532 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 533 | case RK816_ID: |
| 534 | mask = 1 << buck; |
| 535 | ret = pmic_clrsetbits(pmic, RK816_REG_DCDC_SLP_EN, mask, |
| 536 | enable ? mask : 0); |
| 537 | break; |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 538 | case RK806_ID: |
| 539 | { |
| 540 | u8 reg; |
| 541 | |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 542 | if (buck >= 8) { |
| 543 | /* BUCK9 and BUCK10 */ |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 544 | reg = RK806_POWER_SLP_EN1; |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 545 | mask = BIT(buck - 2); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 546 | } else { |
| 547 | reg = RK806_POWER_SLP_EN0; |
Jonas Karlman | 2942516 | 2024-09-17 20:59:17 +0000 | [diff] [blame] | 548 | mask = BIT(buck); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 549 | } |
| 550 | ret = pmic_clrsetbits(pmic, reg, mask, enable ? mask : 0); |
| 551 | } |
| 552 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 553 | case RK808_ID: |
| 554 | case RK818_ID: |
| 555 | mask = 1 << buck; |
| 556 | ret = pmic_clrsetbits(pmic, REG_SLEEP_SET_OFF1, mask, |
| 557 | enable ? 0 : mask); |
| 558 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 559 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 560 | case RK817_ID: |
| 561 | if (buck < 4) |
| 562 | mask = 1 << buck; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 563 | else |
| 564 | mask = 1 << 5; /* BUCK5 for RK809 */ |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 565 | ret = pmic_clrsetbits(pmic, RK817_POWER_SLP_EN(0), mask, |
| 566 | enable ? mask : 0); |
| 567 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 568 | default: |
| 569 | ret = -EINVAL; |
| 570 | } |
| 571 | |
| 572 | return ret; |
| 573 | } |
| 574 | |
| 575 | static int _buck_get_suspend_enable(struct udevice *pmic, int buck) |
| 576 | { |
| 577 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 578 | int ret, val; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 579 | uint mask = 0; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 580 | |
| 581 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 582 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 583 | case RK816_ID: |
| 584 | mask = 1 << buck; |
| 585 | val = pmic_reg_read(pmic, RK816_REG_DCDC_SLP_EN); |
| 586 | if (val < 0) |
| 587 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 588 | ret = (val & mask) ? 1 : 0; |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 589 | break; |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 590 | case RK806_ID: |
| 591 | { |
| 592 | u8 reg; |
| 593 | |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 594 | if (buck >= 8) { |
| 595 | /* BUCK9 and BUCK10 */ |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 596 | reg = RK806_POWER_SLP_EN1; |
Jonas Karlman | 431810c | 2024-09-17 20:59:18 +0000 | [diff] [blame] | 597 | mask = BIT(buck - 2); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 598 | } else { |
| 599 | reg = RK806_POWER_SLP_EN0; |
Jonas Karlman | 2942516 | 2024-09-17 20:59:17 +0000 | [diff] [blame] | 600 | mask = BIT(buck); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 601 | } |
| 602 | val = pmic_reg_read(pmic, reg); |
| 603 | } |
| 604 | ret = (val & mask) ? 1 : 0; |
| 605 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 606 | case RK808_ID: |
| 607 | case RK818_ID: |
| 608 | mask = 1 << buck; |
| 609 | val = pmic_reg_read(pmic, REG_SLEEP_SET_OFF1); |
| 610 | if (val < 0) |
| 611 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 612 | ret = (val & mask) ? 0 : 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 613 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 614 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 615 | case RK817_ID: |
| 616 | if (buck < 4) |
| 617 | mask = 1 << buck; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 618 | else |
| 619 | mask = 1 << 5; /* BUCK5 for RK809 */ |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 620 | |
| 621 | val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(0)); |
| 622 | if (val < 0) |
| 623 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 624 | ret = (val & mask) ? 1 : 0; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 625 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 626 | default: |
| 627 | ret = -EINVAL; |
| 628 | } |
| 629 | |
| 630 | return ret; |
| 631 | } |
| 632 | |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 633 | static const struct rk8xx_reg_info *get_ldo_reg(struct udevice *pmic, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 634 | int num, int uvolt) |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 635 | { |
| 636 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 637 | |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 638 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 639 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 640 | case RK816_ID: |
| 641 | return &rk816_ldo[num]; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 642 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 643 | case RK817_ID: |
| 644 | if (uvolt < 3400000) |
| 645 | return &rk817_ldo[num * 2 + 0]; |
| 646 | else |
| 647 | return &rk817_ldo[num * 2 + 1]; |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 648 | case RK818_ID: |
| 649 | return &rk818_ldo[num]; |
| 650 | default: |
| 651 | return &rk808_ldo[num]; |
| 652 | } |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 653 | } |
| 654 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 655 | static const struct rk8xx_reg_info *get_nldo_reg(struct udevice *pmic, |
| 656 | int num, int uvolt) |
| 657 | { |
| 658 | const struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 659 | |
| 660 | switch (priv->variant) { |
| 661 | case RK806_ID: |
| 662 | default: |
| 663 | if (uvolt < 3400000) |
| 664 | return &rk806_nldo[num * 2 + 0]; |
| 665 | return &rk806_nldo[num * 2 + 1]; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | static const struct rk8xx_reg_info *get_pldo_reg(struct udevice *pmic, |
| 670 | int num, int uvolt) |
| 671 | { |
| 672 | const struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 673 | |
| 674 | switch (priv->variant) { |
| 675 | case RK806_ID: |
| 676 | default: |
| 677 | if (uvolt < 3400000) |
| 678 | return &rk806_pldo[num * 2 + 0]; |
| 679 | return &rk806_pldo[num * 2 + 1]; |
| 680 | } |
| 681 | } |
| 682 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 683 | static int _ldo_get_enable(struct udevice *pmic, int ldo) |
| 684 | { |
| 685 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 686 | uint mask = 0; |
| 687 | int ret = 0; |
| 688 | |
| 689 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 690 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 691 | case RK816_ID: |
| 692 | if (ldo >= 4) { |
| 693 | mask = 1 << (ldo - 4); |
| 694 | ret = pmic_reg_read(pmic, RK816_REG_LDO_EN2); |
| 695 | } else { |
| 696 | mask = 1 << ldo; |
| 697 | ret = pmic_reg_read(pmic, RK816_REG_LDO_EN1); |
| 698 | } |
| 699 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 700 | case RK808_ID: |
| 701 | case RK818_ID: |
| 702 | mask = 1 << ldo; |
| 703 | ret = pmic_reg_read(pmic, REG_LDO_EN); |
| 704 | if (ret < 0) |
| 705 | return ret; |
| 706 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 707 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 708 | case RK817_ID: |
| 709 | if (ldo < 4) { |
| 710 | mask = 1 << ldo; |
| 711 | ret = pmic_reg_read(pmic, RK817_POWER_EN(1)); |
| 712 | } else if (ldo < 8) { |
| 713 | mask = 1 << (ldo - 4); |
| 714 | ret = pmic_reg_read(pmic, RK817_POWER_EN(2)); |
| 715 | } else if (ldo == 8) { |
| 716 | mask = 1 << 0; |
| 717 | ret = pmic_reg_read(pmic, RK817_POWER_EN(3)); |
| 718 | } else { |
| 719 | return false; |
| 720 | } |
| 721 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 722 | } |
| 723 | |
| 724 | if (ret < 0) |
| 725 | return ret; |
| 726 | |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 727 | return (ret & mask) ? true : false; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 728 | } |
| 729 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 730 | static int _nldo_get_enable(struct udevice *pmic, int nldo) |
| 731 | { |
| 732 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 733 | uint mask = 0; |
| 734 | int ret = 0; |
| 735 | u8 en_reg = 0; |
| 736 | |
| 737 | switch (priv->variant) { |
| 738 | case RK806_ID: |
| 739 | default: |
| 740 | if (nldo + 1 >= 5) { |
| 741 | mask = BIT(2); |
| 742 | en_reg = RK806_POWER_EN(5); |
| 743 | } else { |
| 744 | mask = BIT(nldo); |
| 745 | en_reg = RK806_POWER_EN(3); |
| 746 | } |
| 747 | ret = pmic_reg_read(pmic, en_reg); |
| 748 | break; |
| 749 | } |
| 750 | |
| 751 | if (ret < 0) |
| 752 | return ret; |
| 753 | |
| 754 | return (ret & mask) ? 1 : 0; |
| 755 | } |
| 756 | |
| 757 | static int _pldo_get_enable(struct udevice *pmic, int pldo) |
| 758 | { |
| 759 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 760 | uint mask = 0; |
| 761 | int ret = 0; |
| 762 | u8 en_reg = 0; |
| 763 | |
| 764 | switch (priv->variant) { |
| 765 | case RK806_ID: |
| 766 | default: |
| 767 | if (pldo + 1 <= 3) { |
| 768 | mask = BIT(pldo + 1); |
| 769 | en_reg = RK806_POWER_EN(4); |
| 770 | } else if (pldo + 1 == 6) { |
| 771 | mask = BIT(0); |
| 772 | en_reg = RK806_POWER_EN(4); |
| 773 | } else { |
| 774 | mask = BIT((pldo + 1) % 4); |
| 775 | en_reg = RK806_POWER_EN(5); |
| 776 | } |
| 777 | ret = pmic_reg_read(pmic, en_reg); |
| 778 | break; |
| 779 | } |
| 780 | |
| 781 | if (ret < 0) |
| 782 | return ret; |
| 783 | |
| 784 | return (ret & mask) ? 1 : 0; |
| 785 | } |
| 786 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 787 | static int _ldo_set_enable(struct udevice *pmic, int ldo, bool enable) |
| 788 | { |
| 789 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 790 | uint mask, value, en_reg; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 791 | int ret = 0; |
| 792 | |
| 793 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 794 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 795 | case RK816_ID: |
| 796 | if (ldo >= 4) { |
| 797 | ldo -= 4; |
| 798 | en_reg = RK816_REG_LDO_EN2; |
| 799 | } else { |
| 800 | en_reg = RK816_REG_LDO_EN1; |
| 801 | } |
| 802 | if (enable) |
| 803 | value = ((1 << ldo) | (1 << (ldo + 4))); |
| 804 | else |
| 805 | value = ((0 << ldo) | (1 << (ldo + 4))); |
| 806 | |
| 807 | ret = pmic_reg_write(pmic, en_reg, value); |
| 808 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 809 | case RK808_ID: |
| 810 | case RK818_ID: |
| 811 | mask = 1 << ldo; |
| 812 | ret = pmic_clrsetbits(pmic, REG_LDO_EN, mask, |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 813 | enable ? mask : 0); |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 814 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 815 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 816 | case RK817_ID: |
| 817 | if (ldo < 4) { |
| 818 | en_reg = RK817_POWER_EN(1); |
| 819 | } else if (ldo < 8) { |
| 820 | ldo -= 4; |
| 821 | en_reg = RK817_POWER_EN(2); |
| 822 | } else if (ldo == 8) { |
| 823 | ldo = 0; /* BIT 0 */ |
| 824 | en_reg = RK817_POWER_EN(3); |
| 825 | } else { |
| 826 | return -EINVAL; |
| 827 | } |
| 828 | if (enable) |
| 829 | value = ((1 << ldo) | (1 << (ldo + 4))); |
| 830 | else |
| 831 | value = ((0 << ldo) | (1 << (ldo + 4))); |
| 832 | ret = pmic_reg_write(pmic, en_reg, value); |
| 833 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 834 | } |
| 835 | |
Jonas Karlman | 31c3c80 | 2023-07-02 12:41:15 +0000 | [diff] [blame] | 836 | if (enable) |
| 837 | udelay(500); |
| 838 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 839 | return ret; |
Wadim Egorov | 4c4905f | 2017-06-19 12:36:38 +0200 | [diff] [blame] | 840 | } |
| 841 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 842 | static int _nldo_set_enable(struct udevice *pmic, int nldo, bool enable) |
| 843 | { |
| 844 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 845 | uint value, en_reg; |
| 846 | int ret = 0; |
| 847 | |
| 848 | switch (priv->variant) { |
| 849 | case RK806_ID: |
| 850 | default: |
| 851 | if (nldo + 1 >= 5) { |
| 852 | value = RK806_POWER_EN_CLRSETBITS(2, enable); |
| 853 | en_reg = RK806_POWER_EN(5); |
| 854 | } else { |
| 855 | value = RK806_POWER_EN_CLRSETBITS(nldo, enable); |
| 856 | en_reg = RK806_POWER_EN(3); |
| 857 | } |
| 858 | ret = pmic_reg_write(pmic, en_reg, value); |
| 859 | break; |
| 860 | } |
| 861 | |
| 862 | if (enable) |
| 863 | udelay(500); |
| 864 | |
| 865 | return ret; |
| 866 | } |
| 867 | |
| 868 | static int _pldo_set_enable(struct udevice *pmic, int pldo, bool enable) |
| 869 | { |
| 870 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 871 | uint value, en_reg; |
| 872 | int ret = 0; |
| 873 | |
| 874 | switch (priv->variant) { |
| 875 | case RK806_ID: |
| 876 | default: |
| 877 | /* PLDO */ |
| 878 | if (pldo + 1 <= 3) { |
| 879 | value = RK806_POWER_EN_CLRSETBITS(pldo + 1, enable); |
| 880 | en_reg = RK806_POWER_EN(4); |
| 881 | } else if (pldo + 1 == 6) { |
| 882 | value = RK806_POWER_EN_CLRSETBITS(0, enable); |
| 883 | en_reg = RK806_POWER_EN(4); |
| 884 | } else { |
| 885 | value = RK806_POWER_EN_CLRSETBITS((pldo + 1) % 4, enable); |
| 886 | en_reg = RK806_POWER_EN(5); |
| 887 | } |
| 888 | ret = pmic_reg_write(pmic, en_reg, value); |
| 889 | break; |
| 890 | } |
| 891 | |
| 892 | if (enable) |
| 893 | udelay(500); |
| 894 | |
| 895 | return ret; |
| 896 | } |
| 897 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 898 | static int _ldo_set_suspend_enable(struct udevice *pmic, int ldo, bool enable) |
| 899 | { |
| 900 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 901 | uint mask; |
| 902 | int ret = 0; |
| 903 | |
| 904 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 905 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 906 | case RK816_ID: |
| 907 | mask = 1 << ldo; |
| 908 | ret = pmic_clrsetbits(pmic, RK816_REG_LDO_SLP_EN, mask, |
| 909 | enable ? mask : 0); |
| 910 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 911 | case RK808_ID: |
| 912 | case RK818_ID: |
| 913 | mask = 1 << ldo; |
| 914 | ret = pmic_clrsetbits(pmic, REG_SLEEP_SET_OFF2, mask, |
| 915 | enable ? 0 : mask); |
| 916 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 917 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 918 | case RK817_ID: |
| 919 | if (ldo == 8) { |
| 920 | mask = 1 << 4; /* LDO9 */ |
| 921 | ret = pmic_clrsetbits(pmic, RK817_POWER_SLP_EN(0), mask, |
| 922 | enable ? mask : 0); |
| 923 | } else { |
| 924 | mask = 1 << ldo; |
| 925 | ret = pmic_clrsetbits(pmic, RK817_POWER_SLP_EN(1), mask, |
| 926 | enable ? mask : 0); |
| 927 | } |
| 928 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | return ret; |
| 932 | } |
| 933 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 934 | static int _nldo_set_suspend_enable(struct udevice *pmic, int nldo, bool enable) |
| 935 | { |
| 936 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 937 | uint mask; |
| 938 | int ret = 0; |
| 939 | |
| 940 | switch (priv->variant) { |
| 941 | case RK806_ID: |
| 942 | default: |
| 943 | mask = BIT(nldo); |
| 944 | ret = pmic_clrsetbits(pmic, RK806_POWER_SLP_EN1, mask, enable ? mask : 0); |
| 945 | break; |
| 946 | } |
| 947 | |
| 948 | return ret; |
| 949 | } |
| 950 | |
| 951 | static int _pldo_set_suspend_enable(struct udevice *pmic, int pldo, bool enable) |
| 952 | { |
| 953 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 954 | uint mask; |
| 955 | int ret = 0; |
| 956 | |
| 957 | switch (priv->variant) { |
| 958 | case RK806_ID: |
| 959 | default: |
| 960 | if (pldo + 1 >= 6) |
| 961 | mask = BIT(0); |
| 962 | else |
| 963 | mask = BIT(pldo + 1); |
| 964 | ret = pmic_clrsetbits(pmic, RK806_POWER_SLP_EN2, mask, enable ? mask : 0); |
| 965 | break; |
| 966 | } |
| 967 | |
| 968 | return ret; |
| 969 | } |
| 970 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 971 | static int _ldo_get_suspend_enable(struct udevice *pmic, int ldo) |
| 972 | { |
| 973 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 974 | int val, ret = 0; |
| 975 | uint mask; |
| 976 | |
| 977 | switch (priv->variant) { |
Elaine Zhang | 1d9077e | 2019-09-26 15:43:55 +0800 | [diff] [blame] | 978 | case RK805_ID: |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 979 | case RK816_ID: |
| 980 | mask = 1 << ldo; |
| 981 | val = pmic_reg_read(pmic, RK816_REG_LDO_SLP_EN); |
| 982 | if (val < 0) |
| 983 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 984 | ret = (val & mask) ? 1 : 0; |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 985 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 986 | case RK808_ID: |
| 987 | case RK818_ID: |
| 988 | mask = 1 << ldo; |
| 989 | val = pmic_reg_read(pmic, REG_SLEEP_SET_OFF2); |
| 990 | if (val < 0) |
| 991 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 992 | ret = (val & mask) ? 0 : 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 993 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 994 | case RK809_ID: |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 995 | case RK817_ID: |
| 996 | if (ldo == 8) { |
| 997 | mask = 1 << 4; /* LDO9 */ |
| 998 | val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(0)); |
| 999 | if (val < 0) |
| 1000 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1001 | ret = (val & mask) ? 1 : 0; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 1002 | } else { |
| 1003 | mask = 1 << ldo; |
| 1004 | val = pmic_reg_read(pmic, RK817_POWER_SLP_EN(1)); |
| 1005 | if (val < 0) |
| 1006 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1007 | ret = (val & mask) ? 1 : 0; |
Joseph Chen | 4a1ae18 | 2019-09-26 15:44:55 +0800 | [diff] [blame] | 1008 | } |
| 1009 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | return ret; |
| 1013 | } |
| 1014 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1015 | static int _nldo_get_suspend_enable(struct udevice *pmic, int nldo) |
| 1016 | { |
| 1017 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 1018 | int val, ret = 0; |
| 1019 | uint mask; |
| 1020 | |
| 1021 | switch (priv->variant) { |
| 1022 | case RK806_ID: |
| 1023 | default: |
| 1024 | mask = BIT(nldo); |
| 1025 | val = pmic_reg_read(pmic, RK806_POWER_SLP_EN1); |
| 1026 | ret = (val & mask) ? 1 : 0; |
| 1027 | break; |
| 1028 | } |
| 1029 | |
| 1030 | return ret; |
| 1031 | } |
| 1032 | |
| 1033 | static int _pldo_get_suspend_enable(struct udevice *pmic, int pldo) |
| 1034 | { |
| 1035 | struct rk8xx_priv *priv = dev_get_priv(pmic); |
| 1036 | int val, ret = 0; |
| 1037 | uint mask; |
| 1038 | |
| 1039 | switch (priv->variant) { |
| 1040 | case RK806_ID: |
| 1041 | default: |
| 1042 | if (pldo + 1 >= 6) |
| 1043 | mask = BIT(0); |
| 1044 | else |
| 1045 | mask = BIT(pldo + 1); |
| 1046 | val = pmic_reg_read(pmic, RK806_POWER_SLP_EN2); |
| 1047 | ret = (val & mask) ? 1 : 0; |
| 1048 | break; |
| 1049 | } |
| 1050 | |
| 1051 | return ret; |
| 1052 | } |
| 1053 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1054 | static int buck_get_value(struct udevice *dev) |
| 1055 | { |
| 1056 | int buck = dev->driver_data - 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1057 | const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0); |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 1058 | int mask = info->vsel_mask; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1059 | int ret, val; |
| 1060 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1061 | if (info->vsel_reg == NA) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1062 | return -ENOSYS; |
Elaine Zhang | 04e5a43 | 2019-09-26 15:43:54 +0800 | [diff] [blame] | 1063 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1064 | ret = pmic_reg_read(dev->parent, info->vsel_reg); |
| 1065 | if (ret < 0) |
| 1066 | return ret; |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 1067 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1068 | val = ret & mask; |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 1069 | while (val > info->max_sel) |
| 1070 | info++; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1071 | |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 1072 | return info->min_uv + (val - info->min_sel) * info->step_uv; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1073 | } |
| 1074 | |
| 1075 | static int buck_set_value(struct udevice *dev, int uvolt) |
| 1076 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1077 | int buck = dev->driver_data - 1; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1078 | |
| 1079 | return _buck_set_value(dev->parent, buck, uvolt); |
| 1080 | } |
| 1081 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1082 | static int buck_get_suspend_value(struct udevice *dev) |
| 1083 | { |
| 1084 | int buck = dev->driver_data - 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1085 | const struct rk8xx_reg_info *info = get_buck_reg(dev->parent, buck, 0); |
| 1086 | int mask = info->vsel_mask; |
| 1087 | int ret, val; |
| 1088 | |
| 1089 | if (info->vsel_sleep_reg == NA) |
| 1090 | return -ENOSYS; |
| 1091 | |
| 1092 | ret = pmic_reg_read(dev->parent, info->vsel_sleep_reg); |
| 1093 | if (ret < 0) |
| 1094 | return ret; |
| 1095 | |
| 1096 | val = ret & mask; |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 1097 | while (val > info->max_sel) |
| 1098 | info++; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1099 | |
Joseph Chen | fb18ddd | 2023-08-21 22:30:25 +0000 | [diff] [blame] | 1100 | return info->min_uv + (val - info->min_sel) * info->step_uv; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | static int buck_set_suspend_value(struct udevice *dev, int uvolt) |
| 1104 | { |
| 1105 | int buck = dev->driver_data - 1; |
| 1106 | |
| 1107 | return _buck_set_suspend_value(dev->parent, buck, uvolt); |
| 1108 | } |
| 1109 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1110 | static int buck_set_enable(struct udevice *dev, bool enable) |
| 1111 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1112 | int buck = dev->driver_data - 1; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1113 | |
| 1114 | return _buck_set_enable(dev->parent, buck, enable); |
| 1115 | } |
| 1116 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1117 | static int buck_set_suspend_enable(struct udevice *dev, bool enable) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1118 | { |
| 1119 | int buck = dev->driver_data - 1; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1120 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1121 | return _buck_set_suspend_enable(dev->parent, buck, enable); |
| 1122 | } |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1123 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1124 | static int buck_get_suspend_enable(struct udevice *dev) |
| 1125 | { |
| 1126 | int buck = dev->driver_data - 1; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1127 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1128 | return _buck_get_suspend_enable(dev->parent, buck); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1129 | } |
| 1130 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1131 | static int buck_get_enable(struct udevice *dev) |
| 1132 | { |
| 1133 | int buck = dev->driver_data - 1; |
| 1134 | |
| 1135 | return _buck_get_enable(dev->parent, buck); |
| 1136 | } |
| 1137 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1138 | static int _ldo_get_value(struct udevice *pmic, const struct rk8xx_reg_info *info) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1139 | { |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 1140 | int mask = info->vsel_mask; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1141 | int ret, val; |
| 1142 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1143 | if (info->vsel_reg == NA) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1144 | return -ENOSYS; |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1145 | ret = pmic_reg_read(pmic, info->vsel_reg); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1146 | if (ret < 0) |
| 1147 | return ret; |
| 1148 | val = ret & mask; |
| 1149 | |
| 1150 | return info->min_uv + val * info->step_uv; |
| 1151 | } |
| 1152 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1153 | static int ldo_get_value(struct udevice *dev) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1154 | { |
| 1155 | int ldo = dev->driver_data - 1; |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1156 | const struct rk8xx_reg_info *info = get_ldo_reg(dev->parent, ldo, 0); |
| 1157 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1158 | return _ldo_get_value(dev->parent, info); |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1159 | } |
| 1160 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1161 | static int nldo_get_value(struct udevice *dev) |
| 1162 | { |
| 1163 | int nldo = dev->driver_data - 1; |
| 1164 | const struct rk8xx_reg_info *info = get_nldo_reg(dev->parent, nldo, 0); |
| 1165 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1166 | return _ldo_get_value(dev->parent, info); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1167 | } |
| 1168 | |
| 1169 | static int pldo_get_value(struct udevice *dev) |
| 1170 | { |
| 1171 | int pldo = dev->driver_data - 1; |
| 1172 | const struct rk8xx_reg_info *info = get_pldo_reg(dev->parent, pldo, 0); |
| 1173 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1174 | return _ldo_get_value(dev->parent, info); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1177 | static int _ldo_set_value(struct udevice *pmic, const struct rk8xx_reg_info *info, int uvolt) |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1178 | { |
Jacob Chen | 21a6a25 | 2017-05-02 14:54:50 +0800 | [diff] [blame] | 1179 | int mask = info->vsel_mask; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1180 | int val; |
| 1181 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1182 | if (info->vsel_reg == NA) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1183 | return -ENOSYS; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1184 | |
| 1185 | if (info->step_uv == 0) |
| 1186 | val = info->min_sel; |
| 1187 | else |
| 1188 | val = ((uvolt - info->min_uv) / info->step_uv) + info->min_sel; |
| 1189 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1190 | debug("%s: volt=%d, reg=0x%x, mask=0x%x, val=0x%x\n", |
| 1191 | __func__, uvolt, info->vsel_reg, mask, val); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1192 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1193 | return pmic_clrsetbits(pmic, info->vsel_reg, mask, val); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1194 | } |
| 1195 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1196 | static int ldo_set_value(struct udevice *dev, int uvolt) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1197 | { |
| 1198 | int ldo = dev->driver_data - 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1199 | const struct rk8xx_reg_info *info = get_ldo_reg(dev->parent, ldo, uvolt); |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1200 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1201 | return _ldo_set_value(dev->parent, info, uvolt); |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1202 | } |
| 1203 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1204 | static int nldo_set_value(struct udevice *dev, int uvolt) |
| 1205 | { |
| 1206 | int nldo = dev->driver_data - 1; |
| 1207 | const struct rk8xx_reg_info *info = get_nldo_reg(dev->parent, nldo, uvolt); |
| 1208 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1209 | return _ldo_set_value(dev->parent, info, uvolt); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static int pldo_set_value(struct udevice *dev, int uvolt) |
| 1213 | { |
| 1214 | int pldo = dev->driver_data - 1; |
| 1215 | const struct rk8xx_reg_info *info = get_pldo_reg(dev->parent, pldo, uvolt); |
| 1216 | |
Quentin Schulz | 23b16d4 | 2024-06-05 11:33:22 +0200 | [diff] [blame] | 1217 | return _ldo_set_value(dev->parent, info, uvolt); |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1218 | } |
| 1219 | |
Quentin Schulz | e4b47f5 | 2024-06-05 11:33:21 +0200 | [diff] [blame] | 1220 | static int _ldo_set_suspend_value(struct udevice *pmic, const struct rk8xx_reg_info *info, int uvolt) |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1221 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1222 | int mask = info->vsel_mask; |
| 1223 | int val; |
| 1224 | |
| 1225 | if (info->vsel_sleep_reg == NA) |
| 1226 | return -ENOSYS; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1227 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1228 | if (info->step_uv == 0) |
| 1229 | val = info->min_sel; |
| 1230 | else |
| 1231 | val = ((uvolt - info->min_uv) / info->step_uv) + info->min_sel; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1232 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1233 | debug("%s: volt=%d, reg=0x%x, mask=0x%x, val=0x%x\n", |
| 1234 | __func__, uvolt, info->vsel_sleep_reg, mask, val); |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1235 | |
Quentin Schulz | e4b47f5 | 2024-06-05 11:33:21 +0200 | [diff] [blame] | 1236 | return pmic_clrsetbits(pmic, info->vsel_sleep_reg, mask, val); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1237 | } |
| 1238 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1239 | static int ldo_set_suspend_value(struct udevice *dev, int uvolt) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1240 | { |
| 1241 | int ldo = dev->driver_data - 1; |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1242 | const struct rk8xx_reg_info *info = get_ldo_reg(dev->parent, ldo, uvolt); |
| 1243 | |
| 1244 | return _ldo_set_suspend_value(dev->parent, info, uvolt); |
| 1245 | } |
| 1246 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1247 | static int nldo_set_suspend_value(struct udevice *dev, int uvolt) |
| 1248 | { |
| 1249 | int nldo = dev->driver_data - 1; |
| 1250 | const struct rk8xx_reg_info *info = get_nldo_reg(dev->parent, nldo, uvolt); |
| 1251 | |
| 1252 | return _ldo_set_suspend_value(dev->parent, info, uvolt); |
| 1253 | } |
| 1254 | |
| 1255 | static int pldo_set_suspend_value(struct udevice *dev, int uvolt) |
| 1256 | { |
| 1257 | int pldo = dev->driver_data - 1; |
| 1258 | const struct rk8xx_reg_info *info = get_pldo_reg(dev->parent, pldo, uvolt); |
| 1259 | |
| 1260 | return _ldo_set_suspend_value(dev->parent, info, uvolt); |
| 1261 | } |
| 1262 | |
Quentin Schulz | e4b47f5 | 2024-06-05 11:33:21 +0200 | [diff] [blame] | 1263 | static int _ldo_get_suspend_value(struct udevice *pmic, const struct rk8xx_reg_info *info) |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1264 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1265 | int mask = info->vsel_mask; |
| 1266 | int val, ret; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1267 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1268 | if (info->vsel_sleep_reg == NA) |
| 1269 | return -ENOSYS; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1270 | |
Quentin Schulz | e4b47f5 | 2024-06-05 11:33:21 +0200 | [diff] [blame] | 1271 | ret = pmic_reg_read(pmic, info->vsel_sleep_reg); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1272 | if (ret < 0) |
| 1273 | return ret; |
| 1274 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1275 | val = ret & mask; |
| 1276 | |
| 1277 | return info->min_uv + val * info->step_uv; |
| 1278 | } |
| 1279 | |
Quentin Schulz | ec7dd64 | 2024-03-14 10:36:17 +0100 | [diff] [blame] | 1280 | static int ldo_get_suspend_value(struct udevice *dev) |
| 1281 | { |
| 1282 | int ldo = dev->driver_data - 1; |
| 1283 | const struct rk8xx_reg_info *info = get_ldo_reg(dev->parent, ldo, 0); |
| 1284 | |
| 1285 | return _ldo_get_suspend_value(dev->parent, info); |
| 1286 | } |
| 1287 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1288 | static int nldo_get_suspend_value(struct udevice *dev) |
| 1289 | { |
| 1290 | int nldo = dev->driver_data - 1; |
| 1291 | const struct rk8xx_reg_info *info = get_nldo_reg(dev->parent, nldo, 0); |
| 1292 | |
| 1293 | return _ldo_get_suspend_value(dev->parent, info); |
| 1294 | } |
| 1295 | |
| 1296 | static int pldo_get_suspend_value(struct udevice *dev) |
| 1297 | { |
| 1298 | int pldo = dev->driver_data - 1; |
| 1299 | const struct rk8xx_reg_info *info = get_pldo_reg(dev->parent, pldo, 0); |
| 1300 | |
| 1301 | return _ldo_get_suspend_value(dev->parent, info); |
| 1302 | } |
| 1303 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1304 | static int ldo_set_enable(struct udevice *dev, bool enable) |
| 1305 | { |
| 1306 | int ldo = dev->driver_data - 1; |
| 1307 | |
| 1308 | return _ldo_set_enable(dev->parent, ldo, enable); |
| 1309 | } |
| 1310 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1311 | static int nldo_set_enable(struct udevice *dev, bool enable) |
| 1312 | { |
| 1313 | int nldo = dev->driver_data - 1; |
| 1314 | |
| 1315 | return _nldo_set_enable(dev->parent, nldo, enable); |
| 1316 | } |
| 1317 | |
| 1318 | static int pldo_set_enable(struct udevice *dev, bool enable) |
| 1319 | { |
| 1320 | int pldo = dev->driver_data - 1; |
| 1321 | |
| 1322 | return _pldo_set_enable(dev->parent, pldo, enable); |
| 1323 | } |
| 1324 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1325 | static int ldo_set_suspend_enable(struct udevice *dev, bool enable) |
| 1326 | { |
| 1327 | int ldo = dev->driver_data - 1; |
| 1328 | |
| 1329 | return _ldo_set_suspend_enable(dev->parent, ldo, enable); |
| 1330 | } |
| 1331 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1332 | static int nldo_set_suspend_enable(struct udevice *dev, bool enable) |
| 1333 | { |
| 1334 | int nldo = dev->driver_data - 1; |
| 1335 | |
| 1336 | return _nldo_set_suspend_enable(dev->parent, nldo, enable); |
| 1337 | } |
| 1338 | |
| 1339 | static int pldo_set_suspend_enable(struct udevice *dev, bool enable) |
| 1340 | { |
| 1341 | int pldo = dev->driver_data - 1; |
| 1342 | |
| 1343 | return _pldo_set_suspend_enable(dev->parent, pldo, enable); |
| 1344 | } |
| 1345 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1346 | static int ldo_get_suspend_enable(struct udevice *dev) |
| 1347 | { |
| 1348 | int ldo = dev->driver_data - 1; |
| 1349 | |
| 1350 | return _ldo_get_suspend_enable(dev->parent, ldo); |
| 1351 | } |
| 1352 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1353 | static int nldo_get_suspend_enable(struct udevice *dev) |
| 1354 | { |
| 1355 | int nldo = dev->driver_data - 1; |
| 1356 | |
| 1357 | return _nldo_get_suspend_enable(dev->parent, nldo); |
| 1358 | } |
| 1359 | |
| 1360 | static int pldo_get_suspend_enable(struct udevice *dev) |
| 1361 | { |
| 1362 | int pldo = dev->driver_data - 1; |
| 1363 | |
| 1364 | return _pldo_get_suspend_enable(dev->parent, pldo); |
| 1365 | } |
| 1366 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1367 | static int ldo_get_enable(struct udevice *dev) |
| 1368 | { |
| 1369 | int ldo = dev->driver_data - 1; |
| 1370 | |
| 1371 | return _ldo_get_enable(dev->parent, ldo); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1372 | } |
| 1373 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1374 | static int nldo_get_enable(struct udevice *dev) |
| 1375 | { |
| 1376 | int nldo = dev->driver_data - 1; |
| 1377 | |
| 1378 | return _nldo_get_enable(dev->parent, nldo); |
| 1379 | } |
| 1380 | |
| 1381 | static int pldo_get_enable(struct udevice *dev) |
| 1382 | { |
| 1383 | int pldo = dev->driver_data - 1; |
| 1384 | |
| 1385 | return _pldo_get_enable(dev->parent, pldo); |
| 1386 | } |
| 1387 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1388 | static int switch_set_enable(struct udevice *dev, bool enable) |
| 1389 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1390 | struct rk8xx_priv *priv = dev_get_priv(dev->parent); |
| 1391 | int ret = 0, sw = dev->driver_data - 1; |
| 1392 | uint mask = 0; |
| 1393 | |
| 1394 | switch (priv->variant) { |
| 1395 | case RK808_ID: |
| 1396 | mask = 1 << (sw + 5); |
| 1397 | ret = pmic_clrsetbits(dev->parent, REG_DCDC_EN, mask, |
| 1398 | enable ? mask : 0); |
| 1399 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1400 | case RK809_ID: |
| 1401 | mask = (1 << (sw + 2)) | (1 << (sw + 6)); |
| 1402 | ret = pmic_clrsetbits(dev->parent, RK817_POWER_EN(3), mask, |
William Wu | b863e49 | 2024-03-14 10:36:16 +0100 | [diff] [blame] | 1403 | enable ? mask : (1 << (sw + 6))); |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1404 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1405 | case RK818_ID: |
| 1406 | mask = 1 << 6; |
| 1407 | ret = pmic_clrsetbits(dev->parent, REG_DCDC_EN, mask, |
| 1408 | enable ? mask : 0); |
| 1409 | break; |
| 1410 | } |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1411 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1412 | debug("%s: switch%d, enable=%d, mask=0x%x\n", |
| 1413 | __func__, sw + 1, enable, mask); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1414 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1415 | return ret; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
Keerthy | c8f82fb | 2017-06-13 09:53:52 +0530 | [diff] [blame] | 1418 | static int switch_get_enable(struct udevice *dev) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1419 | { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1420 | struct rk8xx_priv *priv = dev_get_priv(dev->parent); |
| 1421 | int ret = 0, sw = dev->driver_data - 1; |
| 1422 | uint mask = 0; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1423 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1424 | switch (priv->variant) { |
| 1425 | case RK808_ID: |
| 1426 | mask = 1 << (sw + 5); |
| 1427 | ret = pmic_reg_read(dev->parent, REG_DCDC_EN); |
| 1428 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1429 | case RK809_ID: |
| 1430 | mask = 1 << (sw + 2); |
| 1431 | ret = pmic_reg_read(dev->parent, RK817_POWER_EN(3)); |
| 1432 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1433 | case RK818_ID: |
| 1434 | mask = 1 << 6; |
| 1435 | ret = pmic_reg_read(dev->parent, REG_DCDC_EN); |
| 1436 | break; |
| 1437 | } |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1438 | |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1439 | if (ret < 0) |
| 1440 | return ret; |
| 1441 | |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1442 | return (ret & mask) ? true : false; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1443 | } |
| 1444 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1445 | static int switch_set_suspend_value(struct udevice *dev, int uvolt) |
| 1446 | { |
| 1447 | return 0; |
| 1448 | } |
| 1449 | |
| 1450 | static int switch_get_suspend_value(struct udevice *dev) |
| 1451 | { |
| 1452 | return 0; |
| 1453 | } |
| 1454 | |
| 1455 | static int switch_set_suspend_enable(struct udevice *dev, bool enable) |
| 1456 | { |
| 1457 | struct rk8xx_priv *priv = dev_get_priv(dev->parent); |
| 1458 | int ret = 0, sw = dev->driver_data - 1; |
| 1459 | uint mask = 0; |
| 1460 | |
| 1461 | switch (priv->variant) { |
| 1462 | case RK808_ID: |
| 1463 | mask = 1 << (sw + 5); |
| 1464 | ret = pmic_clrsetbits(dev->parent, REG_SLEEP_SET_OFF1, mask, |
| 1465 | enable ? 0 : mask); |
| 1466 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1467 | case RK809_ID: |
| 1468 | mask = 1 << (sw + 6); |
| 1469 | ret = pmic_clrsetbits(dev->parent, RK817_POWER_SLP_EN(0), mask, |
| 1470 | enable ? mask : 0); |
| 1471 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1472 | case RK818_ID: |
| 1473 | mask = 1 << 6; |
| 1474 | ret = pmic_clrsetbits(dev->parent, REG_SLEEP_SET_OFF1, mask, |
| 1475 | enable ? 0 : mask); |
| 1476 | break; |
| 1477 | } |
| 1478 | |
| 1479 | debug("%s: switch%d, enable=%d, mask=0x%x\n", |
| 1480 | __func__, sw + 1, enable, mask); |
| 1481 | |
| 1482 | return ret; |
| 1483 | } |
| 1484 | |
| 1485 | static int switch_get_suspend_enable(struct udevice *dev) |
| 1486 | { |
| 1487 | struct rk8xx_priv *priv = dev_get_priv(dev->parent); |
| 1488 | int val, ret = 0, sw = dev->driver_data - 1; |
| 1489 | uint mask = 0; |
| 1490 | |
| 1491 | switch (priv->variant) { |
| 1492 | case RK808_ID: |
| 1493 | mask = 1 << (sw + 5); |
| 1494 | val = pmic_reg_read(dev->parent, REG_SLEEP_SET_OFF1); |
| 1495 | if (val < 0) |
| 1496 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1497 | ret = (val & mask) ? 0 : 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1498 | break; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1499 | case RK809_ID: |
| 1500 | mask = 1 << (sw + 6); |
| 1501 | val = pmic_reg_read(dev->parent, RK817_POWER_SLP_EN(0)); |
| 1502 | if (val < 0) |
| 1503 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1504 | ret = (val & mask) ? 1 : 0; |
Joseph Chen | d6b3e83 | 2019-09-26 15:45:07 +0800 | [diff] [blame] | 1505 | break; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1506 | case RK818_ID: |
| 1507 | mask = 1 << 6; |
| 1508 | val = pmic_reg_read(dev->parent, REG_SLEEP_SET_OFF1); |
| 1509 | if (val < 0) |
| 1510 | return val; |
Quentin Schulz | 53dfd48 | 2024-06-05 11:33:23 +0200 | [diff] [blame] | 1511 | ret = (val & mask) ? 0 : 1; |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1512 | break; |
| 1513 | } |
| 1514 | |
| 1515 | return ret; |
| 1516 | } |
| 1517 | |
| 1518 | /* |
| 1519 | * RK8xx switch does not need to set the voltage, |
| 1520 | * but if dts set regulator-min-microvolt/regulator-max-microvolt, |
| 1521 | * will cause regulator set value fail and not to enable this switch. |
| 1522 | * So add an empty function to return success. |
| 1523 | */ |
| 1524 | static int switch_get_value(struct udevice *dev) |
| 1525 | { |
shengfei Xu | 7851d4e | 2023-08-21 22:30:26 +0000 | [diff] [blame] | 1526 | static const char * const supply_name_rk809[] = { |
| 1527 | "vcc9-supply", |
| 1528 | "vcc8-supply", |
| 1529 | }; |
| 1530 | struct rk8xx_priv *priv = dev_get_priv(dev->parent); |
| 1531 | struct udevice *supply; |
| 1532 | int id = dev->driver_data - 1; |
| 1533 | |
| 1534 | if (!switch_get_enable(dev)) |
| 1535 | return 0; |
| 1536 | |
| 1537 | if (priv->variant == RK809_ID) { |
| 1538 | if (!uclass_get_device_by_phandle(UCLASS_REGULATOR, |
| 1539 | dev->parent, |
| 1540 | supply_name_rk809[id], |
| 1541 | &supply)) |
| 1542 | return regulator_get_value(supply); |
| 1543 | } |
| 1544 | |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1545 | return 0; |
| 1546 | } |
| 1547 | |
| 1548 | static int switch_set_value(struct udevice *dev, int uvolt) |
| 1549 | { |
| 1550 | return 0; |
| 1551 | } |
| 1552 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1553 | static int rk8xx_buck_probe(struct udevice *dev) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1554 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1555 | struct dm_regulator_uclass_plat *uc_pdata; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1556 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1557 | uc_pdata = dev_get_uclass_plat(dev); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1558 | |
| 1559 | uc_pdata->type = REGULATOR_TYPE_BUCK; |
| 1560 | uc_pdata->mode_count = 0; |
| 1561 | |
| 1562 | return 0; |
| 1563 | } |
| 1564 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1565 | static int rk8xx_ldo_probe(struct udevice *dev) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1566 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1567 | struct dm_regulator_uclass_plat *uc_pdata; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1568 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1569 | uc_pdata = dev_get_uclass_plat(dev); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1570 | |
| 1571 | uc_pdata->type = REGULATOR_TYPE_LDO; |
| 1572 | uc_pdata->mode_count = 0; |
| 1573 | |
| 1574 | return 0; |
| 1575 | } |
| 1576 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1577 | static int rk8xx_switch_probe(struct udevice *dev) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1578 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1579 | struct dm_regulator_uclass_plat *uc_pdata; |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1580 | |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 1581 | uc_pdata = dev_get_uclass_plat(dev); |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1582 | |
| 1583 | uc_pdata->type = REGULATOR_TYPE_FIXED; |
| 1584 | uc_pdata->mode_count = 0; |
| 1585 | |
| 1586 | return 0; |
| 1587 | } |
| 1588 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1589 | static const struct dm_regulator_ops rk8xx_buck_ops = { |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1590 | .get_value = buck_get_value, |
| 1591 | .set_value = buck_set_value, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1592 | .set_suspend_value = buck_set_suspend_value, |
| 1593 | .get_suspend_value = buck_get_suspend_value, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1594 | .get_enable = buck_get_enable, |
| 1595 | .set_enable = buck_set_enable, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1596 | .set_suspend_enable = buck_set_suspend_enable, |
| 1597 | .get_suspend_enable = buck_get_suspend_enable, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1598 | }; |
| 1599 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1600 | static const struct dm_regulator_ops rk8xx_ldo_ops = { |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1601 | .get_value = ldo_get_value, |
| 1602 | .set_value = ldo_set_value, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1603 | .set_suspend_value = ldo_set_suspend_value, |
| 1604 | .get_suspend_value = ldo_get_suspend_value, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1605 | .get_enable = ldo_get_enable, |
| 1606 | .set_enable = ldo_set_enable, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1607 | .set_suspend_enable = ldo_set_suspend_enable, |
| 1608 | .get_suspend_enable = ldo_get_suspend_enable, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1609 | }; |
| 1610 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1611 | static const struct dm_regulator_ops rk8xx_nldo_ops = { |
| 1612 | .get_value = nldo_get_value, |
| 1613 | .set_value = nldo_set_value, |
| 1614 | .set_suspend_value = nldo_set_suspend_value, |
| 1615 | .get_suspend_value = nldo_get_suspend_value, |
| 1616 | .get_enable = nldo_get_enable, |
| 1617 | .set_enable = nldo_set_enable, |
| 1618 | .set_suspend_enable = nldo_set_suspend_enable, |
| 1619 | .get_suspend_enable = nldo_get_suspend_enable, |
| 1620 | }; |
| 1621 | |
| 1622 | static const struct dm_regulator_ops rk8xx_pldo_ops = { |
| 1623 | .get_value = pldo_get_value, |
| 1624 | .set_value = pldo_set_value, |
| 1625 | .set_suspend_value = pldo_set_suspend_value, |
| 1626 | .get_suspend_value = pldo_get_suspend_value, |
| 1627 | .get_enable = pldo_get_enable, |
| 1628 | .set_enable = pldo_set_enable, |
| 1629 | .set_suspend_enable = pldo_set_suspend_enable, |
| 1630 | .get_suspend_enable = pldo_get_suspend_enable, |
| 1631 | }; |
| 1632 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1633 | static const struct dm_regulator_ops rk8xx_switch_ops = { |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1634 | .get_value = switch_get_value, |
| 1635 | .set_value = switch_set_value, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1636 | .get_enable = switch_get_enable, |
| 1637 | .set_enable = switch_set_enable, |
Elaine Zhang | fa9cccc | 2019-09-26 15:43:53 +0800 | [diff] [blame] | 1638 | .set_suspend_enable = switch_set_suspend_enable, |
| 1639 | .get_suspend_enable = switch_get_suspend_enable, |
| 1640 | .set_suspend_value = switch_set_suspend_value, |
| 1641 | .get_suspend_value = switch_get_suspend_value, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1642 | }; |
| 1643 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1644 | U_BOOT_DRIVER(rk8xx_buck) = { |
| 1645 | .name = "rk8xx_buck", |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1646 | .id = UCLASS_REGULATOR, |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1647 | .ops = &rk8xx_buck_ops, |
| 1648 | .probe = rk8xx_buck_probe, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1649 | }; |
| 1650 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1651 | U_BOOT_DRIVER(rk8xx_ldo) = { |
| 1652 | .name = "rk8xx_ldo", |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1653 | .id = UCLASS_REGULATOR, |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1654 | .ops = &rk8xx_ldo_ops, |
| 1655 | .probe = rk8xx_ldo_probe, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1656 | }; |
| 1657 | |
Quentin Schulz | f7c6da1 | 2024-03-14 10:36:18 +0100 | [diff] [blame] | 1658 | U_BOOT_DRIVER(rk8xx_nldo) = { |
| 1659 | .name = "rk8xx_nldo", |
| 1660 | .id = UCLASS_REGULATOR, |
| 1661 | .ops = &rk8xx_nldo_ops, |
| 1662 | .probe = rk8xx_ldo_probe, |
| 1663 | }; |
| 1664 | |
| 1665 | U_BOOT_DRIVER(rk8xx_pldo) = { |
| 1666 | .name = "rk8xx_pldo", |
| 1667 | .id = UCLASS_REGULATOR, |
| 1668 | .ops = &rk8xx_pldo_ops, |
| 1669 | .probe = rk8xx_ldo_probe, |
| 1670 | }; |
| 1671 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1672 | U_BOOT_DRIVER(rk8xx_switch) = { |
| 1673 | .name = "rk8xx_switch", |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1674 | .id = UCLASS_REGULATOR, |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1675 | .ops = &rk8xx_switch_ops, |
| 1676 | .probe = rk8xx_switch_probe, |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1677 | }; |
| 1678 | #endif |
| 1679 | |
Jacob Chen | 614704b | 2017-05-02 14:54:52 +0800 | [diff] [blame] | 1680 | int rk8xx_spl_configure_buck(struct udevice *pmic, int buck, int uvolt) |
Simon Glass | adecfef | 2016-01-21 19:43:30 -0700 | [diff] [blame] | 1681 | { |
| 1682 | int ret; |
| 1683 | |
| 1684 | ret = _buck_set_value(pmic, buck, uvolt); |
| 1685 | if (ret) |
| 1686 | return ret; |
| 1687 | |
| 1688 | return _buck_set_enable(pmic, buck, true); |
| 1689 | } |