Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // Copyright (C) 2018 ROHM Semiconductors |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 3 | // bd71837-regulator.c ROHM BD71837MWV/BD71847MWV regulator driver |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 4 | |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 5 | #include <linux/delay.h> |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 6 | #include <linux/err.h> |
| 7 | #include <linux/interrupt.h> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Matti Vaittinen | 410e8b4 | 2018-07-30 14:50:08 +0300 | [diff] [blame] | 9 | #include <linux/mfd/rohm-bd718x7.h> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 10 | #include <linux/module.h> |
Matti Vaittinen | 9cce724 | 2018-10-29 14:16:30 +0200 | [diff] [blame] | 11 | #include <linux/of.h> |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 12 | #include <linux/platform_device.h> |
| 13 | #include <linux/regulator/driver.h> |
| 14 | #include <linux/regulator/machine.h> |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 15 | #include <linux/regulator/of_regulator.h> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 16 | #include <linux/slab.h> |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 17 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 18 | /* |
| 19 | * BUCK1/2/3/4 |
| 20 | * BUCK1RAMPRATE[1:0] BUCK1 DVS ramp rate setting |
| 21 | * 00: 10.00mV/usec 10mV 1uS |
| 22 | * 01: 5.00mV/usec 10mV 2uS |
| 23 | * 10: 2.50mV/usec 10mV 4uS |
| 24 | * 11: 1.25mV/usec 10mV 8uS |
| 25 | */ |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 26 | static int bd718xx_buck1234_set_ramp_delay(struct regulator_dev *rdev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 27 | int ramp_delay) |
| 28 | { |
Axel Lin | 0a245f0 | 2019-04-07 17:03:02 +0800 | [diff] [blame] | 29 | int id = rdev_get_id(rdev); |
| 30 | unsigned int ramp_value; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 31 | |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 32 | dev_dbg(&rdev->dev, "Buck[%d] Set Ramp = %d\n", id + 1, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 33 | ramp_delay); |
| 34 | switch (ramp_delay) { |
| 35 | case 1 ... 1250: |
| 36 | ramp_value = BUCK_RAMPRATE_1P25MV; |
| 37 | break; |
| 38 | case 1251 ... 2500: |
| 39 | ramp_value = BUCK_RAMPRATE_2P50MV; |
| 40 | break; |
| 41 | case 2501 ... 5000: |
| 42 | ramp_value = BUCK_RAMPRATE_5P00MV; |
| 43 | break; |
| 44 | case 5001 ... 10000: |
| 45 | ramp_value = BUCK_RAMPRATE_10P00MV; |
| 46 | break; |
| 47 | default: |
| 48 | ramp_value = BUCK_RAMPRATE_10P00MV; |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 49 | dev_err(&rdev->dev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 50 | "%s: ramp_delay: %d not supported, setting 10000mV//us\n", |
| 51 | rdev->desc->name, ramp_delay); |
| 52 | } |
| 53 | |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 54 | return regmap_update_bits(rdev->regmap, BD718XX_REG_BUCK1_CTRL + id, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 55 | BUCK_RAMPRATE_MASK, ramp_value << 6); |
| 56 | } |
| 57 | |
| 58 | /* Bucks 1 to 4 support DVS. PWM mode is used when voltage is changed. |
| 59 | * Bucks 5 to 8 and LDOs can use PFM and must be disabled when voltage |
| 60 | * is changed. Hence we return -EBUSY for these if voltage is changed |
| 61 | * when BUCK/LDO is enabled. |
| 62 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 63 | static int bd718xx_set_voltage_sel_restricted(struct regulator_dev *rdev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 64 | unsigned int sel) |
| 65 | { |
Axel Lin | ffdc498 | 2018-06-27 20:40:14 +0800 | [diff] [blame] | 66 | if (regulator_is_enabled_regmap(rdev)) |
| 67 | return -EBUSY; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 68 | |
Axel Lin | ffdc498 | 2018-06-27 20:40:14 +0800 | [diff] [blame] | 69 | return regulator_set_voltage_sel_regmap(rdev, sel); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 70 | } |
| 71 | |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 72 | static int bd718xx_set_voltage_sel_pickable_restricted( |
| 73 | struct regulator_dev *rdev, unsigned int sel) |
| 74 | { |
| 75 | if (regulator_is_enabled_regmap(rdev)) |
| 76 | return -EBUSY; |
| 77 | |
| 78 | return regulator_set_voltage_sel_pickable_regmap(rdev, sel); |
| 79 | } |
| 80 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 81 | static const struct regulator_ops bd718xx_pickable_range_ldo_ops = { |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 82 | .enable = regulator_enable_regmap, |
| 83 | .disable = regulator_disable_regmap, |
| 84 | .is_enabled = regulator_is_enabled_regmap, |
| 85 | .list_voltage = regulator_list_voltage_pickable_linear_range, |
| 86 | .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, |
| 87 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, |
| 88 | }; |
| 89 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 90 | static const struct regulator_ops bd718xx_pickable_range_buck_ops = { |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 91 | .enable = regulator_enable_regmap, |
| 92 | .disable = regulator_disable_regmap, |
| 93 | .is_enabled = regulator_is_enabled_regmap, |
| 94 | .list_voltage = regulator_list_voltage_pickable_linear_range, |
| 95 | .set_voltage_sel = bd718xx_set_voltage_sel_pickable_restricted, |
| 96 | .get_voltage_sel = regulator_get_voltage_sel_pickable_regmap, |
| 97 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 98 | }; |
| 99 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 100 | static const struct regulator_ops bd718xx_ldo_regulator_ops = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 101 | .enable = regulator_enable_regmap, |
| 102 | .disable = regulator_disable_regmap, |
| 103 | .is_enabled = regulator_is_enabled_regmap, |
| 104 | .list_voltage = regulator_list_voltage_linear_range, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 105 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 106 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 107 | }; |
| 108 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 109 | static const struct regulator_ops bd718xx_ldo_regulator_nolinear_ops = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 110 | .enable = regulator_enable_regmap, |
| 111 | .disable = regulator_disable_regmap, |
| 112 | .is_enabled = regulator_is_enabled_regmap, |
| 113 | .list_voltage = regulator_list_voltage_table, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 114 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 115 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 116 | }; |
| 117 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 118 | static const struct regulator_ops bd718xx_buck_regulator_ops = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 119 | .enable = regulator_enable_regmap, |
| 120 | .disable = regulator_disable_regmap, |
| 121 | .is_enabled = regulator_is_enabled_regmap, |
| 122 | .list_voltage = regulator_list_voltage_linear_range, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 123 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 124 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 125 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 126 | }; |
| 127 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 128 | static const struct regulator_ops bd718xx_buck_regulator_nolinear_ops = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 129 | .enable = regulator_enable_regmap, |
| 130 | .disable = regulator_disable_regmap, |
| 131 | .is_enabled = regulator_is_enabled_regmap, |
| 132 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | 2e61286 | 2018-11-10 11:50:03 +0800 | [diff] [blame] | 133 | .map_voltage = regulator_map_voltage_ascend, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 134 | .set_voltage_sel = bd718xx_set_voltage_sel_restricted, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 135 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 136 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
| 137 | }; |
| 138 | |
Axel Lin | 704c5c0 | 2019-01-24 18:02:08 +0800 | [diff] [blame] | 139 | static const struct regulator_ops bd718xx_dvs_buck_regulator_ops = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 140 | .enable = regulator_enable_regmap, |
| 141 | .disable = regulator_disable_regmap, |
| 142 | .is_enabled = regulator_is_enabled_regmap, |
| 143 | .list_voltage = regulator_list_voltage_linear_range, |
| 144 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
| 145 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 146 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 147 | .set_ramp_delay = bd718xx_buck1234_set_ramp_delay, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | /* |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 151 | * BD71837 BUCK1/2/3/4 |
| 152 | * BD71847 BUCK1/2 |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 153 | * 0.70 to 1.30V (10mV step) |
| 154 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 155 | static const struct regulator_linear_range bd718xx_dvs_buck_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 156 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x3C, 10000), |
| 157 | REGULATOR_LINEAR_RANGE(1300000, 0x3D, 0x3F, 0), |
| 158 | }; |
| 159 | |
| 160 | /* |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 161 | * BD71837 BUCK5 |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 162 | * 0.7V to 1.35V (range 0) |
| 163 | * and |
| 164 | * 0.675 to 1.325 (range 1) |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 165 | */ |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 166 | static const struct regulator_linear_range bd71837_buck5_volts[] = { |
| 167 | /* Ranges when VOLT_SEL bit is 0 */ |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 168 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), |
| 169 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), |
| 170 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 171 | /* Ranges when VOLT_SEL bit is 1 */ |
| 172 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), |
| 173 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), |
| 174 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 175 | }; |
| 176 | |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 177 | /* |
| 178 | * Range selector for first 3 linear ranges is 0x0 |
| 179 | * and 0x1 for last 3 ranges. |
| 180 | */ |
| 181 | static const unsigned int bd71837_buck5_volt_range_sel[] = { |
| 182 | 0x0, 0x0, 0x0, 0x80, 0x80, 0x80 |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 183 | }; |
| 184 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 185 | /* |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 186 | * BD71847 BUCK3 |
| 187 | */ |
| 188 | static const struct regulator_linear_range bd71847_buck3_volts[] = { |
| 189 | /* Ranges when VOLT_SEL bits are 00 */ |
| 190 | REGULATOR_LINEAR_RANGE(700000, 0x00, 0x03, 100000), |
| 191 | REGULATOR_LINEAR_RANGE(1050000, 0x04, 0x05, 50000), |
| 192 | REGULATOR_LINEAR_RANGE(1200000, 0x06, 0x07, 150000), |
| 193 | /* Ranges when VOLT_SEL bits are 01 */ |
| 194 | REGULATOR_LINEAR_RANGE(550000, 0x0, 0x7, 50000), |
| 195 | /* Ranges when VOLT_SEL bits are 11 */ |
| 196 | REGULATOR_LINEAR_RANGE(675000, 0x0, 0x3, 100000), |
| 197 | REGULATOR_LINEAR_RANGE(1025000, 0x4, 0x5, 50000), |
| 198 | REGULATOR_LINEAR_RANGE(1175000, 0x6, 0x7, 150000), |
| 199 | }; |
| 200 | |
| 201 | static const unsigned int bd71847_buck3_volt_range_sel[] = { |
| 202 | 0x0, 0x0, 0x0, 0x40, 0x80, 0x80, 0x80 |
| 203 | }; |
| 204 | |
| 205 | static const struct regulator_linear_range bd71847_buck4_volts[] = { |
| 206 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
| 207 | REGULATOR_LINEAR_RANGE(2600000, 0x00, 0x03, 100000), |
| 208 | }; |
| 209 | |
| 210 | static const unsigned int bd71847_buck4_volt_range_sel[] = { 0x0, 0x40 }; |
| 211 | |
| 212 | /* |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 213 | * BUCK6 |
| 214 | * 3.0V to 3.3V (step 100mV) |
| 215 | */ |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 216 | static const struct regulator_linear_range bd71837_buck6_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 217 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
| 218 | }; |
| 219 | |
| 220 | /* |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 221 | * BD71837 BUCK7 |
| 222 | * BD71847 BUCK5 |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 223 | * 000 = 1.605V |
| 224 | * 001 = 1.695V |
| 225 | * 010 = 1.755V |
| 226 | * 011 = 1.8V (Initial) |
| 227 | * 100 = 1.845V |
| 228 | * 101 = 1.905V |
| 229 | * 110 = 1.95V |
| 230 | * 111 = 1.995V |
| 231 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 232 | static const unsigned int bd718xx_3rd_nodvs_buck_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 233 | 1605000, 1695000, 1755000, 1800000, 1845000, 1905000, 1950000, 1995000 |
| 234 | }; |
| 235 | |
| 236 | /* |
| 237 | * BUCK8 |
| 238 | * 0.8V to 1.40V (step 10mV) |
| 239 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 240 | static const struct regulator_linear_range bd718xx_4th_nodvs_buck_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 241 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x3C, 10000), |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | /* |
| 245 | * LDO1 |
| 246 | * 3.0 to 3.3V (100mV step) |
| 247 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 248 | static const struct regulator_linear_range bd718xx_ldo1_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 249 | REGULATOR_LINEAR_RANGE(3000000, 0x00, 0x03, 100000), |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 250 | REGULATOR_LINEAR_RANGE(1600000, 0x00, 0x03, 100000), |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 251 | }; |
| 252 | |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 253 | static const unsigned int bd718xx_ldo1_volt_range_sel[] = { 0x0, 0x20 }; |
| 254 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 255 | /* |
| 256 | * LDO2 |
| 257 | * 0.8 or 0.9V |
| 258 | */ |
Axel Lin | adb78a8 | 2018-06-27 20:40:13 +0800 | [diff] [blame] | 259 | static const unsigned int ldo_2_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 260 | 900000, 800000 |
| 261 | }; |
| 262 | |
| 263 | /* |
| 264 | * LDO3 |
| 265 | * 1.8 to 3.3V (100mV step) |
| 266 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 267 | static const struct regulator_linear_range bd718xx_ldo3_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 268 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
| 269 | }; |
| 270 | |
| 271 | /* |
| 272 | * LDO4 |
| 273 | * 0.9 to 1.8V (100mV step) |
| 274 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 275 | static const struct regulator_linear_range bd718xx_ldo4_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 276 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 277 | }; |
| 278 | |
| 279 | /* |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 280 | * LDO5 for BD71837 |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 281 | * 1.8 to 3.3V (100mV step) |
| 282 | */ |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 283 | static const struct regulator_linear_range bd71837_ldo5_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 284 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
| 285 | }; |
| 286 | |
| 287 | /* |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 288 | * LDO5 for BD71837 |
| 289 | * 1.8 to 3.3V (100mV step) |
| 290 | */ |
| 291 | static const struct regulator_linear_range bd71847_ldo5_volts[] = { |
| 292 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
| 293 | REGULATOR_LINEAR_RANGE(800000, 0x00, 0x0F, 100000), |
| 294 | }; |
| 295 | |
| 296 | static const unsigned int bd71847_ldo5_volt_range_sel[] = { 0x0, 0x20 }; |
| 297 | |
| 298 | /* |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 299 | * LDO6 |
| 300 | * 0.9 to 1.8V (100mV step) |
| 301 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 302 | static const struct regulator_linear_range bd718xx_ldo6_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 303 | REGULATOR_LINEAR_RANGE(900000, 0x00, 0x09, 100000), |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | /* |
| 307 | * LDO7 |
| 308 | * 1.8 to 3.3V (100mV step) |
| 309 | */ |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 310 | static const struct regulator_linear_range bd71837_ldo7_volts[] = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 311 | REGULATOR_LINEAR_RANGE(1800000, 0x00, 0x0F, 100000), |
| 312 | }; |
| 313 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 314 | struct reg_init { |
| 315 | unsigned int reg; |
| 316 | unsigned int mask; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 317 | unsigned int val; |
| 318 | }; |
| 319 | struct bd718xx_regulator_data { |
| 320 | struct regulator_desc desc; |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 321 | const struct rohm_dvs_config dvs; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 322 | const struct reg_init init; |
| 323 | const struct reg_init *additional_inits; |
| 324 | int additional_init_amnt; |
| 325 | }; |
| 326 | |
| 327 | /* |
| 328 | * There is a HW quirk in BD71837. The shutdown sequence timings for |
| 329 | * bucks/LDOs which are controlled via register interface are changed. |
| 330 | * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the |
| 331 | * beginning of shut-down sequence. As bucks 6 and 7 are parent |
| 332 | * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage |
| 333 | * monitoring to errorneously detect under voltage and force PMIC to |
| 334 | * emergency state instead of poweroff. In order to avoid this we |
| 335 | * disable voltage monitoring for LDO5 and LDO6 |
| 336 | */ |
| 337 | static const struct reg_init bd71837_ldo5_inits[] = { |
| 338 | { |
| 339 | .reg = BD718XX_REG_MVRFLTMASK2, |
| 340 | .mask = BD718XX_LDO5_VRMON80, |
| 341 | .val = BD718XX_LDO5_VRMON80, |
| 342 | }, |
| 343 | }; |
| 344 | |
| 345 | static const struct reg_init bd71837_ldo6_inits[] = { |
| 346 | { |
| 347 | .reg = BD718XX_REG_MVRFLTMASK2, |
| 348 | .mask = BD718XX_LDO6_VRMON80, |
| 349 | .val = BD718XX_LDO6_VRMON80, |
| 350 | }, |
| 351 | }; |
| 352 | |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 353 | static int buck_set_hw_dvs_levels(struct device_node *np, |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 354 | const struct regulator_desc *desc, |
| 355 | struct regulator_config *cfg) |
| 356 | { |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 357 | struct bd718xx_regulator_data *data; |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 358 | |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 359 | data = container_of(desc, struct bd718xx_regulator_data, desc); |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 360 | |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 361 | return rohm_regulator_set_dvs_levels(&data->dvs, np, desc, cfg->regmap); |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 362 | } |
| 363 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 364 | static const struct bd718xx_regulator_data bd71847_regulators[] = { |
| 365 | { |
| 366 | .desc = { |
| 367 | .name = "buck1", |
| 368 | .of_match = of_match_ptr("BUCK1"), |
| 369 | .regulators_node = of_match_ptr("regulators"), |
| 370 | .id = BD718XX_BUCK1, |
| 371 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 372 | .type = REGULATOR_VOLTAGE, |
| 373 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 374 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 375 | .n_linear_ranges = |
| 376 | ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 377 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 378 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 379 | .enable_reg = BD718XX_REG_BUCK1_CTRL, |
| 380 | .enable_mask = BD718XX_BUCK_EN, |
| 381 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 382 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 383 | }, |
| 384 | .dvs = { |
| 385 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | |
| 386 | ROHM_DVS_LEVEL_SUSPEND, |
| 387 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 388 | .run_mask = DVS_BUCK_RUN_MASK, |
| 389 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, |
| 390 | .idle_mask = DVS_BUCK_RUN_MASK, |
| 391 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, |
| 392 | .suspend_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 393 | }, |
| 394 | .init = { |
| 395 | .reg = BD718XX_REG_BUCK1_CTRL, |
| 396 | .mask = BD718XX_BUCK_SEL, |
| 397 | .val = BD718XX_BUCK_SEL, |
| 398 | }, |
| 399 | }, |
| 400 | { |
| 401 | .desc = { |
| 402 | .name = "buck2", |
| 403 | .of_match = of_match_ptr("BUCK2"), |
| 404 | .regulators_node = of_match_ptr("regulators"), |
| 405 | .id = BD718XX_BUCK2, |
| 406 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 407 | .type = REGULATOR_VOLTAGE, |
| 408 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 409 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 410 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 411 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 412 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 413 | .enable_reg = BD718XX_REG_BUCK2_CTRL, |
| 414 | .enable_mask = BD718XX_BUCK_EN, |
| 415 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 416 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 417 | }, |
| 418 | .dvs = { |
| 419 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, |
| 420 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 421 | .run_mask = DVS_BUCK_RUN_MASK, |
| 422 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, |
| 423 | .idle_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 424 | }, |
| 425 | .init = { |
| 426 | .reg = BD718XX_REG_BUCK2_CTRL, |
| 427 | .mask = BD718XX_BUCK_SEL, |
| 428 | .val = BD718XX_BUCK_SEL, |
| 429 | }, |
| 430 | }, |
| 431 | { |
| 432 | .desc = { |
| 433 | .name = "buck3", |
| 434 | .of_match = of_match_ptr("BUCK3"), |
| 435 | .regulators_node = of_match_ptr("regulators"), |
| 436 | .id = BD718XX_BUCK3, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 437 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 438 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 439 | .n_voltages = BD71847_BUCK3_VOLTAGE_NUM, |
| 440 | .linear_ranges = bd71847_buck3_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 441 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 442 | ARRAY_SIZE(bd71847_buck3_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 443 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 444 | .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 445 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 446 | .vsel_range_mask = BD71847_BUCK3_RANGE_MASK, |
| 447 | .linear_range_selectors = bd71847_buck3_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 448 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 449 | .enable_mask = BD718XX_BUCK_EN, |
| 450 | .owner = THIS_MODULE, |
| 451 | }, |
| 452 | .init = { |
| 453 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 454 | .mask = BD718XX_BUCK_SEL, |
| 455 | .val = BD718XX_BUCK_SEL, |
| 456 | }, |
| 457 | }, |
| 458 | { |
| 459 | .desc = { |
| 460 | .name = "buck4", |
| 461 | .of_match = of_match_ptr("BUCK4"), |
| 462 | .regulators_node = of_match_ptr("regulators"), |
| 463 | .id = BD718XX_BUCK4, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 464 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 465 | .type = REGULATOR_VOLTAGE, |
| 466 | .n_voltages = BD71847_BUCK4_VOLTAGE_NUM, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 467 | .linear_ranges = bd71847_buck4_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 468 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 469 | ARRAY_SIZE(bd71847_buck4_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 470 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 471 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 472 | .vsel_mask = BD71847_BUCK4_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 473 | .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 474 | .vsel_range_mask = BD71847_BUCK4_RANGE_MASK, |
| 475 | .linear_range_selectors = bd71847_buck4_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 476 | .enable_mask = BD718XX_BUCK_EN, |
| 477 | .owner = THIS_MODULE, |
| 478 | }, |
| 479 | .init = { |
| 480 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 481 | .mask = BD718XX_BUCK_SEL, |
| 482 | .val = BD718XX_BUCK_SEL, |
| 483 | }, |
| 484 | }, |
| 485 | { |
| 486 | .desc = { |
| 487 | .name = "buck5", |
| 488 | .of_match = of_match_ptr("BUCK5"), |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 489 | .regulators_node = of_match_ptr("regulators"), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 490 | .id = BD718XX_BUCK5, |
| 491 | .ops = &bd718xx_buck_regulator_nolinear_ops, |
| 492 | .type = REGULATOR_VOLTAGE, |
| 493 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], |
| 494 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), |
| 495 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, |
| 496 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, |
| 497 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 498 | .enable_mask = BD718XX_BUCK_EN, |
| 499 | .owner = THIS_MODULE, |
| 500 | }, |
| 501 | .init = { |
| 502 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 503 | .mask = BD718XX_BUCK_SEL, |
| 504 | .val = BD718XX_BUCK_SEL, |
| 505 | }, |
| 506 | }, |
| 507 | { |
| 508 | .desc = { |
| 509 | .name = "buck6", |
| 510 | .of_match = of_match_ptr("BUCK6"), |
| 511 | .regulators_node = of_match_ptr("regulators"), |
| 512 | .id = BD718XX_BUCK6, |
| 513 | .ops = &bd718xx_buck_regulator_ops, |
| 514 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 515 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 516 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
| 517 | .n_linear_ranges = |
| 518 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), |
| 519 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, |
| 520 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, |
| 521 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 522 | .enable_mask = BD718XX_BUCK_EN, |
| 523 | .owner = THIS_MODULE, |
| 524 | }, |
| 525 | .init = { |
| 526 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 527 | .mask = BD718XX_BUCK_SEL, |
| 528 | .val = BD718XX_BUCK_SEL, |
| 529 | }, |
| 530 | }, |
| 531 | { |
| 532 | .desc = { |
| 533 | .name = "ldo1", |
| 534 | .of_match = of_match_ptr("LDO1"), |
| 535 | .regulators_node = of_match_ptr("regulators"), |
| 536 | .id = BD718XX_LDO1, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 537 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 538 | .type = REGULATOR_VOLTAGE, |
| 539 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, |
| 540 | .linear_ranges = bd718xx_ldo1_volts, |
| 541 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), |
| 542 | .vsel_reg = BD718XX_REG_LDO1_VOLT, |
| 543 | .vsel_mask = BD718XX_LDO1_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 544 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
| 545 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, |
| 546 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 547 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
| 548 | .enable_mask = BD718XX_LDO_EN, |
| 549 | .owner = THIS_MODULE, |
| 550 | }, |
| 551 | .init = { |
| 552 | .reg = BD718XX_REG_LDO1_VOLT, |
| 553 | .mask = BD718XX_LDO_SEL, |
| 554 | .val = BD718XX_LDO_SEL, |
| 555 | }, |
| 556 | }, |
| 557 | { |
| 558 | .desc = { |
| 559 | .name = "ldo2", |
| 560 | .of_match = of_match_ptr("LDO2"), |
| 561 | .regulators_node = of_match_ptr("regulators"), |
| 562 | .id = BD718XX_LDO2, |
| 563 | .ops = &bd718xx_ldo_regulator_nolinear_ops, |
| 564 | .type = REGULATOR_VOLTAGE, |
| 565 | .volt_table = &ldo_2_volts[0], |
| 566 | .vsel_reg = BD718XX_REG_LDO2_VOLT, |
| 567 | .vsel_mask = BD718XX_LDO2_MASK, |
| 568 | .n_voltages = ARRAY_SIZE(ldo_2_volts), |
| 569 | .enable_reg = BD718XX_REG_LDO2_VOLT, |
| 570 | .enable_mask = BD718XX_LDO_EN, |
| 571 | .owner = THIS_MODULE, |
| 572 | }, |
| 573 | .init = { |
| 574 | .reg = BD718XX_REG_LDO2_VOLT, |
| 575 | .mask = BD718XX_LDO_SEL, |
| 576 | .val = BD718XX_LDO_SEL, |
| 577 | }, |
| 578 | }, |
| 579 | { |
| 580 | .desc = { |
| 581 | .name = "ldo3", |
| 582 | .of_match = of_match_ptr("LDO3"), |
| 583 | .regulators_node = of_match_ptr("regulators"), |
| 584 | .id = BD718XX_LDO3, |
| 585 | .ops = &bd718xx_ldo_regulator_ops, |
| 586 | .type = REGULATOR_VOLTAGE, |
| 587 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, |
| 588 | .linear_ranges = bd718xx_ldo3_volts, |
| 589 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), |
| 590 | .vsel_reg = BD718XX_REG_LDO3_VOLT, |
| 591 | .vsel_mask = BD718XX_LDO3_MASK, |
| 592 | .enable_reg = BD718XX_REG_LDO3_VOLT, |
| 593 | .enable_mask = BD718XX_LDO_EN, |
| 594 | .owner = THIS_MODULE, |
| 595 | }, |
| 596 | .init = { |
| 597 | .reg = BD718XX_REG_LDO3_VOLT, |
| 598 | .mask = BD718XX_LDO_SEL, |
| 599 | .val = BD718XX_LDO_SEL, |
| 600 | }, |
| 601 | }, |
| 602 | { |
| 603 | .desc = { |
| 604 | .name = "ldo4", |
| 605 | .of_match = of_match_ptr("LDO4"), |
| 606 | .regulators_node = of_match_ptr("regulators"), |
| 607 | .id = BD718XX_LDO4, |
| 608 | .ops = &bd718xx_ldo_regulator_ops, |
| 609 | .type = REGULATOR_VOLTAGE, |
| 610 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, |
| 611 | .linear_ranges = bd718xx_ldo4_volts, |
| 612 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), |
| 613 | .vsel_reg = BD718XX_REG_LDO4_VOLT, |
| 614 | .vsel_mask = BD718XX_LDO4_MASK, |
| 615 | .enable_reg = BD718XX_REG_LDO4_VOLT, |
| 616 | .enable_mask = BD718XX_LDO_EN, |
| 617 | .owner = THIS_MODULE, |
| 618 | }, |
| 619 | .init = { |
| 620 | .reg = BD718XX_REG_LDO4_VOLT, |
| 621 | .mask = BD718XX_LDO_SEL, |
| 622 | .val = BD718XX_LDO_SEL, |
| 623 | }, |
| 624 | }, |
| 625 | { |
| 626 | .desc = { |
| 627 | .name = "ldo5", |
| 628 | .of_match = of_match_ptr("LDO5"), |
| 629 | .regulators_node = of_match_ptr("regulators"), |
| 630 | .id = BD718XX_LDO5, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 631 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 632 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 633 | .n_voltages = BD71847_LDO5_VOLTAGE_NUM, |
| 634 | .linear_ranges = bd71847_ldo5_volts, |
| 635 | .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 636 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
| 637 | .vsel_mask = BD71847_LDO5_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 638 | .vsel_range_reg = BD718XX_REG_LDO5_VOLT, |
| 639 | .vsel_range_mask = BD71847_LDO5_RANGE_MASK, |
| 640 | .linear_range_selectors = bd71847_ldo5_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 641 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
| 642 | .enable_mask = BD718XX_LDO_EN, |
| 643 | .owner = THIS_MODULE, |
| 644 | }, |
| 645 | .init = { |
| 646 | .reg = BD718XX_REG_LDO5_VOLT, |
| 647 | .mask = BD718XX_LDO_SEL, |
| 648 | .val = BD718XX_LDO_SEL, |
| 649 | }, |
| 650 | }, |
| 651 | { |
| 652 | .desc = { |
| 653 | .name = "ldo6", |
| 654 | .of_match = of_match_ptr("LDO6"), |
| 655 | .regulators_node = of_match_ptr("regulators"), |
| 656 | .id = BD718XX_LDO6, |
| 657 | .ops = &bd718xx_ldo_regulator_ops, |
| 658 | .type = REGULATOR_VOLTAGE, |
| 659 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, |
| 660 | .linear_ranges = bd718xx_ldo6_volts, |
| 661 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), |
| 662 | /* LDO6 is supplied by buck5 */ |
| 663 | .supply_name = "buck5", |
| 664 | .vsel_reg = BD718XX_REG_LDO6_VOLT, |
| 665 | .vsel_mask = BD718XX_LDO6_MASK, |
| 666 | .enable_reg = BD718XX_REG_LDO6_VOLT, |
| 667 | .enable_mask = BD718XX_LDO_EN, |
| 668 | .owner = THIS_MODULE, |
| 669 | }, |
| 670 | .init = { |
| 671 | .reg = BD718XX_REG_LDO6_VOLT, |
| 672 | .mask = BD718XX_LDO_SEL, |
| 673 | .val = BD718XX_LDO_SEL, |
| 674 | }, |
| 675 | }, |
| 676 | }; |
| 677 | |
| 678 | static const struct bd718xx_regulator_data bd71837_regulators[] = { |
| 679 | { |
| 680 | .desc = { |
| 681 | .name = "buck1", |
| 682 | .of_match = of_match_ptr("BUCK1"), |
| 683 | .regulators_node = of_match_ptr("regulators"), |
| 684 | .id = BD718XX_BUCK1, |
| 685 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 686 | .type = REGULATOR_VOLTAGE, |
| 687 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 688 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 689 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 690 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 691 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 692 | .enable_reg = BD718XX_REG_BUCK1_CTRL, |
| 693 | .enable_mask = BD718XX_BUCK_EN, |
| 694 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 695 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 696 | }, |
| 697 | .dvs = { |
| 698 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE | |
| 699 | ROHM_DVS_LEVEL_SUSPEND, |
| 700 | .run_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 701 | .run_mask = DVS_BUCK_RUN_MASK, |
| 702 | .idle_reg = BD718XX_REG_BUCK1_VOLT_IDLE, |
| 703 | .idle_mask = DVS_BUCK_RUN_MASK, |
| 704 | .suspend_reg = BD718XX_REG_BUCK1_VOLT_SUSP, |
| 705 | .suspend_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 706 | }, |
| 707 | .init = { |
| 708 | .reg = BD718XX_REG_BUCK1_CTRL, |
| 709 | .mask = BD718XX_BUCK_SEL, |
| 710 | .val = BD718XX_BUCK_SEL, |
| 711 | }, |
| 712 | }, |
| 713 | { |
| 714 | .desc = { |
| 715 | .name = "buck2", |
| 716 | .of_match = of_match_ptr("BUCK2"), |
| 717 | .regulators_node = of_match_ptr("regulators"), |
| 718 | .id = BD718XX_BUCK2, |
| 719 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 720 | .type = REGULATOR_VOLTAGE, |
| 721 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 722 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 723 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 724 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 725 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 726 | .enable_reg = BD718XX_REG_BUCK2_CTRL, |
| 727 | .enable_mask = BD718XX_BUCK_EN, |
| 728 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 729 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 730 | }, |
| 731 | .dvs = { |
| 732 | .level_map = ROHM_DVS_LEVEL_RUN | ROHM_DVS_LEVEL_IDLE, |
| 733 | .run_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 734 | .run_mask = DVS_BUCK_RUN_MASK, |
| 735 | .idle_reg = BD718XX_REG_BUCK2_VOLT_IDLE, |
| 736 | .idle_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 737 | }, |
| 738 | .init = { |
| 739 | .reg = BD718XX_REG_BUCK2_CTRL, |
| 740 | .mask = BD718XX_BUCK_SEL, |
| 741 | .val = BD718XX_BUCK_SEL, |
| 742 | }, |
| 743 | }, |
| 744 | { |
| 745 | .desc = { |
| 746 | .name = "buck3", |
| 747 | .of_match = of_match_ptr("BUCK3"), |
| 748 | .regulators_node = of_match_ptr("regulators"), |
| 749 | .id = BD718XX_BUCK3, |
| 750 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 751 | .type = REGULATOR_VOLTAGE, |
| 752 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 753 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 754 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 755 | .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN, |
| 756 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 757 | .enable_reg = BD71837_REG_BUCK3_CTRL, |
| 758 | .enable_mask = BD718XX_BUCK_EN, |
| 759 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 760 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 761 | }, |
| 762 | .dvs = { |
| 763 | .level_map = ROHM_DVS_LEVEL_RUN, |
| 764 | .run_reg = BD71837_REG_BUCK3_VOLT_RUN, |
| 765 | .run_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 766 | }, |
| 767 | .init = { |
| 768 | .reg = BD71837_REG_BUCK3_CTRL, |
| 769 | .mask = BD718XX_BUCK_SEL, |
| 770 | .val = BD718XX_BUCK_SEL, |
| 771 | }, |
| 772 | }, |
| 773 | { |
| 774 | .desc = { |
| 775 | .name = "buck4", |
| 776 | .of_match = of_match_ptr("BUCK4"), |
| 777 | .regulators_node = of_match_ptr("regulators"), |
| 778 | .id = BD718XX_BUCK4, |
| 779 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 780 | .type = REGULATOR_VOLTAGE, |
| 781 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 782 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 783 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 784 | .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN, |
| 785 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 786 | .enable_reg = BD71837_REG_BUCK4_CTRL, |
| 787 | .enable_mask = BD718XX_BUCK_EN, |
| 788 | .owner = THIS_MODULE, |
Matti Vaittinen | 21b7215 | 2020-01-20 15:44:45 +0200 | [diff] [blame] | 789 | .of_parse_cb = buck_set_hw_dvs_levels, |
| 790 | }, |
| 791 | .dvs = { |
| 792 | .level_map = ROHM_DVS_LEVEL_RUN, |
| 793 | .run_reg = BD71837_REG_BUCK4_VOLT_RUN, |
| 794 | .run_mask = DVS_BUCK_RUN_MASK, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 795 | }, |
| 796 | .init = { |
| 797 | .reg = BD71837_REG_BUCK4_CTRL, |
| 798 | .mask = BD718XX_BUCK_SEL, |
| 799 | .val = BD718XX_BUCK_SEL, |
| 800 | }, |
| 801 | }, |
| 802 | { |
| 803 | .desc = { |
| 804 | .name = "buck5", |
| 805 | .of_match = of_match_ptr("BUCK5"), |
| 806 | .regulators_node = of_match_ptr("regulators"), |
| 807 | .id = BD718XX_BUCK5, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 808 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 809 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 810 | .n_voltages = BD71837_BUCK5_VOLTAGE_NUM, |
| 811 | .linear_ranges = bd71837_buck5_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 812 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 813 | ARRAY_SIZE(bd71837_buck5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 814 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 815 | .vsel_mask = BD71837_BUCK5_MASK, |
| 816 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 817 | .vsel_range_mask = BD71837_BUCK5_RANGE_MASK, |
| 818 | .linear_range_selectors = bd71837_buck5_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 819 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 820 | .enable_mask = BD718XX_BUCK_EN, |
| 821 | .owner = THIS_MODULE, |
| 822 | }, |
| 823 | .init = { |
| 824 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 825 | .mask = BD718XX_BUCK_SEL, |
| 826 | .val = BD718XX_BUCK_SEL, |
| 827 | }, |
| 828 | }, |
| 829 | { |
| 830 | .desc = { |
| 831 | .name = "buck6", |
| 832 | .of_match = of_match_ptr("BUCK6"), |
| 833 | .regulators_node = of_match_ptr("regulators"), |
| 834 | .id = BD718XX_BUCK6, |
| 835 | .ops = &bd718xx_buck_regulator_ops, |
| 836 | .type = REGULATOR_VOLTAGE, |
| 837 | .n_voltages = BD71837_BUCK6_VOLTAGE_NUM, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 838 | .linear_ranges = bd71837_buck6_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 839 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 840 | ARRAY_SIZE(bd71837_buck6_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 841 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 842 | .vsel_mask = BD71837_BUCK6_MASK, |
| 843 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 844 | .enable_mask = BD718XX_BUCK_EN, |
| 845 | .owner = THIS_MODULE, |
| 846 | }, |
| 847 | .init = { |
| 848 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 849 | .mask = BD718XX_BUCK_SEL, |
| 850 | .val = BD718XX_BUCK_SEL, |
| 851 | }, |
| 852 | }, |
| 853 | { |
| 854 | .desc = { |
| 855 | .name = "buck7", |
| 856 | .of_match = of_match_ptr("BUCK7"), |
| 857 | .regulators_node = of_match_ptr("regulators"), |
| 858 | .id = BD718XX_BUCK7, |
| 859 | .ops = &bd718xx_buck_regulator_nolinear_ops, |
| 860 | .type = REGULATOR_VOLTAGE, |
| 861 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], |
| 862 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), |
| 863 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, |
| 864 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, |
| 865 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 866 | .enable_mask = BD718XX_BUCK_EN, |
| 867 | .owner = THIS_MODULE, |
| 868 | }, |
| 869 | .init = { |
| 870 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 871 | .mask = BD718XX_BUCK_SEL, |
| 872 | .val = BD718XX_BUCK_SEL, |
| 873 | }, |
| 874 | }, |
| 875 | { |
| 876 | .desc = { |
| 877 | .name = "buck8", |
| 878 | .of_match = of_match_ptr("BUCK8"), |
| 879 | .regulators_node = of_match_ptr("regulators"), |
| 880 | .id = BD718XX_BUCK8, |
| 881 | .ops = &bd718xx_buck_regulator_ops, |
| 882 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 883 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 884 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
| 885 | .n_linear_ranges = |
| 886 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), |
| 887 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, |
| 888 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, |
| 889 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 890 | .enable_mask = BD718XX_BUCK_EN, |
| 891 | .owner = THIS_MODULE, |
| 892 | }, |
| 893 | .init = { |
| 894 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 895 | .mask = BD718XX_BUCK_SEL, |
| 896 | .val = BD718XX_BUCK_SEL, |
| 897 | }, |
| 898 | }, |
| 899 | { |
| 900 | .desc = { |
| 901 | .name = "ldo1", |
| 902 | .of_match = of_match_ptr("LDO1"), |
| 903 | .regulators_node = of_match_ptr("regulators"), |
| 904 | .id = BD718XX_LDO1, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 905 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 906 | .type = REGULATOR_VOLTAGE, |
| 907 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, |
| 908 | .linear_ranges = bd718xx_ldo1_volts, |
| 909 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), |
| 910 | .vsel_reg = BD718XX_REG_LDO1_VOLT, |
| 911 | .vsel_mask = BD718XX_LDO1_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 912 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
| 913 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, |
| 914 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 915 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
| 916 | .enable_mask = BD718XX_LDO_EN, |
| 917 | .owner = THIS_MODULE, |
| 918 | }, |
| 919 | .init = { |
| 920 | .reg = BD718XX_REG_LDO1_VOLT, |
| 921 | .mask = BD718XX_LDO_SEL, |
| 922 | .val = BD718XX_LDO_SEL, |
| 923 | }, |
| 924 | }, |
| 925 | { |
| 926 | .desc = { |
| 927 | .name = "ldo2", |
| 928 | .of_match = of_match_ptr("LDO2"), |
| 929 | .regulators_node = of_match_ptr("regulators"), |
| 930 | .id = BD718XX_LDO2, |
| 931 | .ops = &bd718xx_ldo_regulator_nolinear_ops, |
| 932 | .type = REGULATOR_VOLTAGE, |
| 933 | .volt_table = &ldo_2_volts[0], |
| 934 | .vsel_reg = BD718XX_REG_LDO2_VOLT, |
| 935 | .vsel_mask = BD718XX_LDO2_MASK, |
| 936 | .n_voltages = ARRAY_SIZE(ldo_2_volts), |
| 937 | .enable_reg = BD718XX_REG_LDO2_VOLT, |
| 938 | .enable_mask = BD718XX_LDO_EN, |
| 939 | .owner = THIS_MODULE, |
| 940 | }, |
| 941 | .init = { |
| 942 | .reg = BD718XX_REG_LDO2_VOLT, |
| 943 | .mask = BD718XX_LDO_SEL, |
| 944 | .val = BD718XX_LDO_SEL, |
| 945 | }, |
| 946 | }, |
| 947 | { |
| 948 | .desc = { |
| 949 | .name = "ldo3", |
| 950 | .of_match = of_match_ptr("LDO3"), |
| 951 | .regulators_node = of_match_ptr("regulators"), |
| 952 | .id = BD718XX_LDO3, |
| 953 | .ops = &bd718xx_ldo_regulator_ops, |
| 954 | .type = REGULATOR_VOLTAGE, |
| 955 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, |
| 956 | .linear_ranges = bd718xx_ldo3_volts, |
| 957 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), |
| 958 | .vsel_reg = BD718XX_REG_LDO3_VOLT, |
| 959 | .vsel_mask = BD718XX_LDO3_MASK, |
| 960 | .enable_reg = BD718XX_REG_LDO3_VOLT, |
| 961 | .enable_mask = BD718XX_LDO_EN, |
| 962 | .owner = THIS_MODULE, |
| 963 | }, |
| 964 | .init = { |
| 965 | .reg = BD718XX_REG_LDO3_VOLT, |
| 966 | .mask = BD718XX_LDO_SEL, |
| 967 | .val = BD718XX_LDO_SEL, |
| 968 | }, |
| 969 | }, |
| 970 | { |
| 971 | .desc = { |
| 972 | .name = "ldo4", |
| 973 | .of_match = of_match_ptr("LDO4"), |
| 974 | .regulators_node = of_match_ptr("regulators"), |
| 975 | .id = BD718XX_LDO4, |
| 976 | .ops = &bd718xx_ldo_regulator_ops, |
| 977 | .type = REGULATOR_VOLTAGE, |
| 978 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, |
| 979 | .linear_ranges = bd718xx_ldo4_volts, |
| 980 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), |
| 981 | .vsel_reg = BD718XX_REG_LDO4_VOLT, |
| 982 | .vsel_mask = BD718XX_LDO4_MASK, |
| 983 | .enable_reg = BD718XX_REG_LDO4_VOLT, |
| 984 | .enable_mask = BD718XX_LDO_EN, |
| 985 | .owner = THIS_MODULE, |
| 986 | }, |
| 987 | .init = { |
| 988 | .reg = BD718XX_REG_LDO4_VOLT, |
| 989 | .mask = BD718XX_LDO_SEL, |
| 990 | .val = BD718XX_LDO_SEL, |
| 991 | }, |
| 992 | }, |
| 993 | { |
| 994 | .desc = { |
| 995 | .name = "ldo5", |
| 996 | .of_match = of_match_ptr("LDO5"), |
| 997 | .regulators_node = of_match_ptr("regulators"), |
| 998 | .id = BD718XX_LDO5, |
| 999 | .ops = &bd718xx_ldo_regulator_ops, |
| 1000 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 1001 | .n_voltages = BD71837_LDO5_VOLTAGE_NUM, |
| 1002 | .linear_ranges = bd71837_ldo5_volts, |
| 1003 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1004 | /* LDO5 is supplied by buck6 */ |
| 1005 | .supply_name = "buck6", |
| 1006 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
| 1007 | .vsel_mask = BD71837_LDO5_MASK, |
| 1008 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
| 1009 | .enable_mask = BD718XX_LDO_EN, |
| 1010 | .owner = THIS_MODULE, |
| 1011 | }, |
| 1012 | .init = { |
| 1013 | .reg = BD718XX_REG_LDO5_VOLT, |
| 1014 | .mask = BD718XX_LDO_SEL, |
| 1015 | .val = BD718XX_LDO_SEL, |
| 1016 | }, |
| 1017 | .additional_inits = bd71837_ldo5_inits, |
| 1018 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits), |
| 1019 | }, |
| 1020 | { |
| 1021 | .desc = { |
| 1022 | .name = "ldo6", |
| 1023 | .of_match = of_match_ptr("LDO6"), |
| 1024 | .regulators_node = of_match_ptr("regulators"), |
| 1025 | .id = BD718XX_LDO6, |
| 1026 | .ops = &bd718xx_ldo_regulator_ops, |
| 1027 | .type = REGULATOR_VOLTAGE, |
| 1028 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, |
| 1029 | .linear_ranges = bd718xx_ldo6_volts, |
| 1030 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), |
| 1031 | /* LDO6 is supplied by buck7 */ |
| 1032 | .supply_name = "buck7", |
| 1033 | .vsel_reg = BD718XX_REG_LDO6_VOLT, |
| 1034 | .vsel_mask = BD718XX_LDO6_MASK, |
| 1035 | .enable_reg = BD718XX_REG_LDO6_VOLT, |
| 1036 | .enable_mask = BD718XX_LDO_EN, |
| 1037 | .owner = THIS_MODULE, |
| 1038 | }, |
| 1039 | .init = { |
| 1040 | .reg = BD718XX_REG_LDO6_VOLT, |
| 1041 | .mask = BD718XX_LDO_SEL, |
| 1042 | .val = BD718XX_LDO_SEL, |
| 1043 | }, |
| 1044 | .additional_inits = bd71837_ldo6_inits, |
| 1045 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits), |
| 1046 | }, |
| 1047 | { |
| 1048 | .desc = { |
| 1049 | .name = "ldo7", |
| 1050 | .of_match = of_match_ptr("LDO7"), |
| 1051 | .regulators_node = of_match_ptr("regulators"), |
| 1052 | .id = BD718XX_LDO7, |
| 1053 | .ops = &bd718xx_ldo_regulator_ops, |
| 1054 | .type = REGULATOR_VOLTAGE, |
| 1055 | .n_voltages = BD71837_LDO7_VOLTAGE_NUM, |
| 1056 | .linear_ranges = bd71837_ldo7_volts, |
| 1057 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts), |
| 1058 | .vsel_reg = BD71837_REG_LDO7_VOLT, |
| 1059 | .vsel_mask = BD71837_LDO7_MASK, |
| 1060 | .enable_reg = BD71837_REG_LDO7_VOLT, |
| 1061 | .enable_mask = BD718XX_LDO_EN, |
| 1062 | .owner = THIS_MODULE, |
| 1063 | }, |
| 1064 | .init = { |
| 1065 | .reg = BD71837_REG_LDO7_VOLT, |
| 1066 | .mask = BD718XX_LDO_SEL, |
| 1067 | .val = BD718XX_LDO_SEL, |
| 1068 | }, |
| 1069 | }, |
| 1070 | }; |
| 1071 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1072 | static int bd718xx_probe(struct platform_device *pdev) |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1073 | { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1074 | struct bd718xx *mfd; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1075 | struct regulator_config config = { 0 }; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1076 | int i, j, err; |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1077 | bool use_snvs; |
Axel Lin | b389cea | 2020-01-08 09:42:55 +0800 | [diff] [blame] | 1078 | const struct bd718xx_regulator_data *reg_data; |
| 1079 | unsigned int num_reg_data; |
Matti Vaittinen | 1b1c26b | 2020-01-20 15:42:38 +0200 | [diff] [blame] | 1080 | enum rohm_chip_type chip = platform_get_device_id(pdev)->driver_data; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1081 | |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1082 | mfd = dev_get_drvdata(pdev->dev.parent); |
| 1083 | if (!mfd) { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1084 | dev_err(&pdev->dev, "No MFD driver data\n"); |
| 1085 | err = -EINVAL; |
| 1086 | goto err; |
| 1087 | } |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1088 | |
Linus Torvalds | af32f3a | 2020-02-03 14:51:57 +0000 | [diff] [blame] | 1089 | switch (chip) { |
Axel Lin | b389cea | 2020-01-08 09:42:55 +0800 | [diff] [blame] | 1090 | case ROHM_CHIP_TYPE_BD71837: |
| 1091 | reg_data = bd71837_regulators; |
| 1092 | num_reg_data = ARRAY_SIZE(bd71837_regulators); |
| 1093 | break; |
| 1094 | case ROHM_CHIP_TYPE_BD71847: |
| 1095 | reg_data = bd71847_regulators; |
| 1096 | num_reg_data = ARRAY_SIZE(bd71847_regulators); |
| 1097 | break; |
| 1098 | default: |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1099 | dev_err(&pdev->dev, "Unsupported chip type\n"); |
| 1100 | err = -EINVAL; |
| 1101 | goto err; |
| 1102 | } |
| 1103 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1104 | /* Register LOCK release */ |
Matti Vaittinen | 2a6a7aa | 2019-06-03 10:24:32 +0300 | [diff] [blame] | 1105 | err = regmap_update_bits(mfd->chip.regmap, BD718XX_REG_REGLOCK, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1106 | (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); |
| 1107 | if (err) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1108 | dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1109 | goto err; |
| 1110 | } else { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1111 | dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1112 | BD718XX_REG_REGLOCK); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1113 | } |
| 1114 | |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1115 | use_snvs = of_property_read_bool(pdev->dev.parent->of_node, |
| 1116 | "rohm,reset-snvs-powered"); |
| 1117 | |
| 1118 | /* |
Matti Vaittinen | e770b18 | 2018-11-07 15:41:26 +0200 | [diff] [blame] | 1119 | * Change the next stage from poweroff to be READY instead of SNVS |
| 1120 | * for all reset types because OTP loading at READY will clear SEL |
| 1121 | * bit allowing HW defaults for power rails to be used |
| 1122 | */ |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1123 | if (!use_snvs) { |
Matti Vaittinen | 2a6a7aa | 2019-06-03 10:24:32 +0300 | [diff] [blame] | 1124 | err = regmap_update_bits(mfd->chip.regmap, |
| 1125 | BD718XX_REG_TRANS_COND1, |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1126 | BD718XX_ON_REQ_POWEROFF_MASK | |
| 1127 | BD718XX_SWRESET_POWEROFF_MASK | |
| 1128 | BD718XX_WDOG_POWEROFF_MASK | |
| 1129 | BD718XX_KEY_L_POWEROFF_MASK, |
| 1130 | BD718XX_POWOFF_TO_RDY); |
| 1131 | if (err) { |
| 1132 | dev_err(&pdev->dev, "Failed to change reset target\n"); |
| 1133 | goto err; |
| 1134 | } else { |
| 1135 | dev_dbg(&pdev->dev, |
| 1136 | "Changed all resets from SVNS to READY\n"); |
| 1137 | } |
Matti Vaittinen | e770b18 | 2018-11-07 15:41:26 +0200 | [diff] [blame] | 1138 | } |
| 1139 | |
Axel Lin | b389cea | 2020-01-08 09:42:55 +0800 | [diff] [blame] | 1140 | for (i = 0; i < num_reg_data; i++) { |
Matti Vaittinen | 823f18f | 2018-08-29 15:36:10 +0300 | [diff] [blame] | 1141 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1142 | const struct regulator_desc *desc; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1143 | struct regulator_dev *rdev; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1144 | const struct bd718xx_regulator_data *r; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1145 | |
Axel Lin | b389cea | 2020-01-08 09:42:55 +0800 | [diff] [blame] | 1146 | r = ®_data[i]; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1147 | desc = &r->desc; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1148 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1149 | config.dev = pdev->dev.parent; |
Matti Vaittinen | 2a6a7aa | 2019-06-03 10:24:32 +0300 | [diff] [blame] | 1150 | config.regmap = mfd->chip.regmap; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1151 | |
| 1152 | rdev = devm_regulator_register(&pdev->dev, desc, &config); |
| 1153 | if (IS_ERR(rdev)) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1154 | dev_err(&pdev->dev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1155 | "failed to register %s regulator\n", |
| 1156 | desc->name); |
| 1157 | err = PTR_ERR(rdev); |
| 1158 | goto err; |
| 1159 | } |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1160 | |
| 1161 | /* |
| 1162 | * Regulator register gets the regulator constraints and |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1163 | * applies them (set_machine_constraints). This should have |
| 1164 | * turned the control register(s) to correct values and we |
| 1165 | * can now switch the control from PMIC state machine to the |
| 1166 | * register interface |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1167 | * |
| 1168 | * At poweroff transition PMIC HW disables EN bit for |
| 1169 | * regulators but leaves SEL bit untouched. So if state |
| 1170 | * transition from POWEROFF is done to SNVS - then all power |
| 1171 | * rails controlled by SW (having SEL bit set) stay disabled |
| 1172 | * as EN is cleared. This will result boot failure if any |
| 1173 | * crucial systems are powered by these rails. We don't |
| 1174 | * enable SW control for crucial regulators if snvs state is |
| 1175 | * used |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1176 | */ |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1177 | if (!use_snvs || !rdev->constraints->always_on || |
| 1178 | !rdev->constraints->boot_on) { |
Matti Vaittinen | 2a6a7aa | 2019-06-03 10:24:32 +0300 | [diff] [blame] | 1179 | err = regmap_update_bits(mfd->chip.regmap, r->init.reg, |
Matti Vaittinen | 049369d | 2019-02-14 11:39:36 +0200 | [diff] [blame] | 1180 | r->init.mask, r->init.val); |
| 1181 | if (err) { |
| 1182 | dev_err(&pdev->dev, |
| 1183 | "Failed to take control for (%s)\n", |
| 1184 | desc->name); |
| 1185 | goto err; |
| 1186 | } |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1187 | } |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1188 | for (j = 0; j < r->additional_init_amnt; j++) { |
Matti Vaittinen | 2a6a7aa | 2019-06-03 10:24:32 +0300 | [diff] [blame] | 1189 | err = regmap_update_bits(mfd->chip.regmap, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1190 | r->additional_inits[j].reg, |
| 1191 | r->additional_inits[j].mask, |
| 1192 | r->additional_inits[j].val); |
| 1193 | if (err) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1194 | dev_err(&pdev->dev, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1195 | "Buck (%s) initialization failed\n", |
| 1196 | desc->name); |
| 1197 | goto err; |
| 1198 | } |
| 1199 | } |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1200 | } |
| 1201 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1202 | err: |
| 1203 | return err; |
| 1204 | } |
| 1205 | |
Matti Vaittinen | 1b1c26b | 2020-01-20 15:42:38 +0200 | [diff] [blame] | 1206 | static const struct platform_device_id bd718x7_pmic_id[] = { |
| 1207 | { "bd71837-pmic", ROHM_CHIP_TYPE_BD71837 }, |
| 1208 | { "bd71847-pmic", ROHM_CHIP_TYPE_BD71847 }, |
| 1209 | { }, |
| 1210 | }; |
| 1211 | MODULE_DEVICE_TABLE(platform, bd718x7_pmic_id); |
| 1212 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1213 | static struct platform_driver bd718xx_regulator = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1214 | .driver = { |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1215 | .name = "bd718xx-pmic", |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1216 | }, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1217 | .probe = bd718xx_probe, |
Matti Vaittinen | 1b1c26b | 2020-01-20 15:42:38 +0200 | [diff] [blame] | 1218 | .id_table = bd718x7_pmic_id, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1219 | }; |
| 1220 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1221 | module_platform_driver(bd718xx_regulator); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1222 | |
| 1223 | MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1224 | MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver"); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1225 | MODULE_LICENSE("GPL"); |
Guido Günther | 95bddd8 | 2019-09-30 22:26:00 +0200 | [diff] [blame] | 1226 | MODULE_ALIAS("platform:bd718xx-pmic"); |