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> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 7 | #include <linux/gpio.h> |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 8 | #include <linux/interrupt.h> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 9 | #include <linux/kernel.h> |
Matti Vaittinen | 410e8b4 | 2018-07-30 14:50:08 +0300 | [diff] [blame] | 10 | #include <linux/mfd/rohm-bd718x7.h> |
Matti Vaittinen | c9dc4cf | 2018-06-28 14:22:23 +0300 | [diff] [blame] | 11 | #include <linux/module.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 | { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 29 | int id = rdev->desc->id; |
| 30 | unsigned int ramp_value = BUCK_RAMPRATE_10P00MV; |
| 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 | |
| 81 | static struct regulator_ops bd718xx_pickable_range_ldo_ops = { |
| 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 | |
| 90 | static struct regulator_ops bd718xx_pickable_range_buck_ops = { |
| 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 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 100 | static 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 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 109 | static 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 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 118 | static 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 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 128 | static 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 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 139 | static 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; |
| 321 | const struct reg_init init; |
| 322 | const struct reg_init *additional_inits; |
| 323 | int additional_init_amnt; |
| 324 | }; |
| 325 | |
| 326 | /* |
| 327 | * There is a HW quirk in BD71837. The shutdown sequence timings for |
| 328 | * bucks/LDOs which are controlled via register interface are changed. |
| 329 | * At PMIC poweroff the voltage for BUCK6/7 is cut immediately at the |
| 330 | * beginning of shut-down sequence. As bucks 6 and 7 are parent |
| 331 | * supplies for LDO5 and LDO6 - this causes LDO5/6 voltage |
| 332 | * monitoring to errorneously detect under voltage and force PMIC to |
| 333 | * emergency state instead of poweroff. In order to avoid this we |
| 334 | * disable voltage monitoring for LDO5 and LDO6 |
| 335 | */ |
| 336 | static const struct reg_init bd71837_ldo5_inits[] = { |
| 337 | { |
| 338 | .reg = BD718XX_REG_MVRFLTMASK2, |
| 339 | .mask = BD718XX_LDO5_VRMON80, |
| 340 | .val = BD718XX_LDO5_VRMON80, |
| 341 | }, |
| 342 | }; |
| 343 | |
| 344 | static const struct reg_init bd71837_ldo6_inits[] = { |
| 345 | { |
| 346 | .reg = BD718XX_REG_MVRFLTMASK2, |
| 347 | .mask = BD718XX_LDO6_VRMON80, |
| 348 | .val = BD718XX_LDO6_VRMON80, |
| 349 | }, |
| 350 | }; |
| 351 | |
| 352 | static const struct bd718xx_regulator_data bd71847_regulators[] = { |
| 353 | { |
| 354 | .desc = { |
| 355 | .name = "buck1", |
| 356 | .of_match = of_match_ptr("BUCK1"), |
| 357 | .regulators_node = of_match_ptr("regulators"), |
| 358 | .id = BD718XX_BUCK1, |
| 359 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 360 | .type = REGULATOR_VOLTAGE, |
| 361 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 362 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 363 | .n_linear_ranges = |
| 364 | ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 365 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 366 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 367 | .enable_reg = BD718XX_REG_BUCK1_CTRL, |
| 368 | .enable_mask = BD718XX_BUCK_EN, |
| 369 | .owner = THIS_MODULE, |
| 370 | }, |
| 371 | .init = { |
| 372 | .reg = BD718XX_REG_BUCK1_CTRL, |
| 373 | .mask = BD718XX_BUCK_SEL, |
| 374 | .val = BD718XX_BUCK_SEL, |
| 375 | }, |
| 376 | }, |
| 377 | { |
| 378 | .desc = { |
| 379 | .name = "buck2", |
| 380 | .of_match = of_match_ptr("BUCK2"), |
| 381 | .regulators_node = of_match_ptr("regulators"), |
| 382 | .id = BD718XX_BUCK2, |
| 383 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 384 | .type = REGULATOR_VOLTAGE, |
| 385 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 386 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 387 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 388 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 389 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 390 | .enable_reg = BD718XX_REG_BUCK2_CTRL, |
| 391 | .enable_mask = BD718XX_BUCK_EN, |
| 392 | .owner = THIS_MODULE, |
| 393 | }, |
| 394 | .init = { |
| 395 | .reg = BD718XX_REG_BUCK2_CTRL, |
| 396 | .mask = BD718XX_BUCK_SEL, |
| 397 | .val = BD718XX_BUCK_SEL, |
| 398 | }, |
| 399 | }, |
| 400 | { |
| 401 | .desc = { |
| 402 | .name = "buck3", |
| 403 | .of_match = of_match_ptr("BUCK3"), |
| 404 | .regulators_node = of_match_ptr("regulators"), |
| 405 | .id = BD718XX_BUCK3, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 406 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 407 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 408 | .n_voltages = BD71847_BUCK3_VOLTAGE_NUM, |
| 409 | .linear_ranges = bd71847_buck3_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 410 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 411 | ARRAY_SIZE(bd71847_buck3_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 412 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 413 | .vsel_mask = BD718XX_1ST_NODVS_BUCK_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 414 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 415 | .vsel_range_mask = BD71847_BUCK3_RANGE_MASK, |
| 416 | .linear_range_selectors = bd71847_buck3_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 417 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 418 | .enable_mask = BD718XX_BUCK_EN, |
| 419 | .owner = THIS_MODULE, |
| 420 | }, |
| 421 | .init = { |
| 422 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 423 | .mask = BD718XX_BUCK_SEL, |
| 424 | .val = BD718XX_BUCK_SEL, |
| 425 | }, |
| 426 | }, |
| 427 | { |
| 428 | .desc = { |
| 429 | .name = "buck4", |
| 430 | .of_match = of_match_ptr("BUCK4"), |
| 431 | .regulators_node = of_match_ptr("regulators"), |
| 432 | .id = BD718XX_BUCK4, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 433 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 434 | .type = REGULATOR_VOLTAGE, |
| 435 | .n_voltages = BD71847_BUCK4_VOLTAGE_NUM, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 436 | .linear_ranges = bd71847_buck4_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 437 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 438 | ARRAY_SIZE(bd71847_buck4_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 439 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 440 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 441 | .vsel_mask = BD71847_BUCK4_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 442 | .vsel_range_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 443 | .vsel_range_mask = BD71847_BUCK4_RANGE_MASK, |
| 444 | .linear_range_selectors = bd71847_buck4_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 445 | .enable_mask = BD718XX_BUCK_EN, |
| 446 | .owner = THIS_MODULE, |
| 447 | }, |
| 448 | .init = { |
| 449 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 450 | .mask = BD718XX_BUCK_SEL, |
| 451 | .val = BD718XX_BUCK_SEL, |
| 452 | }, |
| 453 | }, |
| 454 | { |
| 455 | .desc = { |
| 456 | .name = "buck5", |
| 457 | .of_match = of_match_ptr("BUCK5"), |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 458 | .regulators_node = of_match_ptr("regulators"), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 459 | .id = BD718XX_BUCK5, |
| 460 | .ops = &bd718xx_buck_regulator_nolinear_ops, |
| 461 | .type = REGULATOR_VOLTAGE, |
| 462 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], |
| 463 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), |
| 464 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, |
| 465 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, |
| 466 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 467 | .enable_mask = BD718XX_BUCK_EN, |
| 468 | .owner = THIS_MODULE, |
| 469 | }, |
| 470 | .init = { |
| 471 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 472 | .mask = BD718XX_BUCK_SEL, |
| 473 | .val = BD718XX_BUCK_SEL, |
| 474 | }, |
| 475 | }, |
| 476 | { |
| 477 | .desc = { |
| 478 | .name = "buck6", |
| 479 | .of_match = of_match_ptr("BUCK6"), |
| 480 | .regulators_node = of_match_ptr("regulators"), |
| 481 | .id = BD718XX_BUCK6, |
| 482 | .ops = &bd718xx_buck_regulator_ops, |
| 483 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 484 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 485 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
| 486 | .n_linear_ranges = |
| 487 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), |
| 488 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, |
| 489 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, |
| 490 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 491 | .enable_mask = BD718XX_BUCK_EN, |
| 492 | .owner = THIS_MODULE, |
| 493 | }, |
| 494 | .init = { |
| 495 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 496 | .mask = BD718XX_BUCK_SEL, |
| 497 | .val = BD718XX_BUCK_SEL, |
| 498 | }, |
| 499 | }, |
| 500 | { |
| 501 | .desc = { |
| 502 | .name = "ldo1", |
| 503 | .of_match = of_match_ptr("LDO1"), |
| 504 | .regulators_node = of_match_ptr("regulators"), |
| 505 | .id = BD718XX_LDO1, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 506 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 507 | .type = REGULATOR_VOLTAGE, |
| 508 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, |
| 509 | .linear_ranges = bd718xx_ldo1_volts, |
| 510 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), |
| 511 | .vsel_reg = BD718XX_REG_LDO1_VOLT, |
| 512 | .vsel_mask = BD718XX_LDO1_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 513 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
| 514 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, |
| 515 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 516 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
| 517 | .enable_mask = BD718XX_LDO_EN, |
| 518 | .owner = THIS_MODULE, |
| 519 | }, |
| 520 | .init = { |
| 521 | .reg = BD718XX_REG_LDO1_VOLT, |
| 522 | .mask = BD718XX_LDO_SEL, |
| 523 | .val = BD718XX_LDO_SEL, |
| 524 | }, |
| 525 | }, |
| 526 | { |
| 527 | .desc = { |
| 528 | .name = "ldo2", |
| 529 | .of_match = of_match_ptr("LDO2"), |
| 530 | .regulators_node = of_match_ptr("regulators"), |
| 531 | .id = BD718XX_LDO2, |
| 532 | .ops = &bd718xx_ldo_regulator_nolinear_ops, |
| 533 | .type = REGULATOR_VOLTAGE, |
| 534 | .volt_table = &ldo_2_volts[0], |
| 535 | .vsel_reg = BD718XX_REG_LDO2_VOLT, |
| 536 | .vsel_mask = BD718XX_LDO2_MASK, |
| 537 | .n_voltages = ARRAY_SIZE(ldo_2_volts), |
| 538 | .enable_reg = BD718XX_REG_LDO2_VOLT, |
| 539 | .enable_mask = BD718XX_LDO_EN, |
| 540 | .owner = THIS_MODULE, |
| 541 | }, |
| 542 | .init = { |
| 543 | .reg = BD718XX_REG_LDO2_VOLT, |
| 544 | .mask = BD718XX_LDO_SEL, |
| 545 | .val = BD718XX_LDO_SEL, |
| 546 | }, |
| 547 | }, |
| 548 | { |
| 549 | .desc = { |
| 550 | .name = "ldo3", |
| 551 | .of_match = of_match_ptr("LDO3"), |
| 552 | .regulators_node = of_match_ptr("regulators"), |
| 553 | .id = BD718XX_LDO3, |
| 554 | .ops = &bd718xx_ldo_regulator_ops, |
| 555 | .type = REGULATOR_VOLTAGE, |
| 556 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, |
| 557 | .linear_ranges = bd718xx_ldo3_volts, |
| 558 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), |
| 559 | .vsel_reg = BD718XX_REG_LDO3_VOLT, |
| 560 | .vsel_mask = BD718XX_LDO3_MASK, |
| 561 | .enable_reg = BD718XX_REG_LDO3_VOLT, |
| 562 | .enable_mask = BD718XX_LDO_EN, |
| 563 | .owner = THIS_MODULE, |
| 564 | }, |
| 565 | .init = { |
| 566 | .reg = BD718XX_REG_LDO3_VOLT, |
| 567 | .mask = BD718XX_LDO_SEL, |
| 568 | .val = BD718XX_LDO_SEL, |
| 569 | }, |
| 570 | }, |
| 571 | { |
| 572 | .desc = { |
| 573 | .name = "ldo4", |
| 574 | .of_match = of_match_ptr("LDO4"), |
| 575 | .regulators_node = of_match_ptr("regulators"), |
| 576 | .id = BD718XX_LDO4, |
| 577 | .ops = &bd718xx_ldo_regulator_ops, |
| 578 | .type = REGULATOR_VOLTAGE, |
| 579 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, |
| 580 | .linear_ranges = bd718xx_ldo4_volts, |
| 581 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), |
| 582 | .vsel_reg = BD718XX_REG_LDO4_VOLT, |
| 583 | .vsel_mask = BD718XX_LDO4_MASK, |
| 584 | .enable_reg = BD718XX_REG_LDO4_VOLT, |
| 585 | .enable_mask = BD718XX_LDO_EN, |
| 586 | .owner = THIS_MODULE, |
| 587 | }, |
| 588 | .init = { |
| 589 | .reg = BD718XX_REG_LDO4_VOLT, |
| 590 | .mask = BD718XX_LDO_SEL, |
| 591 | .val = BD718XX_LDO_SEL, |
| 592 | }, |
| 593 | }, |
| 594 | { |
| 595 | .desc = { |
| 596 | .name = "ldo5", |
| 597 | .of_match = of_match_ptr("LDO5"), |
| 598 | .regulators_node = of_match_ptr("regulators"), |
| 599 | .id = BD718XX_LDO5, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 600 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 601 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 602 | .n_voltages = BD71847_LDO5_VOLTAGE_NUM, |
| 603 | .linear_ranges = bd71847_ldo5_volts, |
| 604 | .n_linear_ranges = ARRAY_SIZE(bd71847_ldo5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 605 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
| 606 | .vsel_mask = BD71847_LDO5_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 607 | .vsel_range_reg = BD718XX_REG_LDO5_VOLT, |
| 608 | .vsel_range_mask = BD71847_LDO5_RANGE_MASK, |
| 609 | .linear_range_selectors = bd71847_ldo5_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 610 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
| 611 | .enable_mask = BD718XX_LDO_EN, |
| 612 | .owner = THIS_MODULE, |
| 613 | }, |
| 614 | .init = { |
| 615 | .reg = BD718XX_REG_LDO5_VOLT, |
| 616 | .mask = BD718XX_LDO_SEL, |
| 617 | .val = BD718XX_LDO_SEL, |
| 618 | }, |
| 619 | }, |
| 620 | { |
| 621 | .desc = { |
| 622 | .name = "ldo6", |
| 623 | .of_match = of_match_ptr("LDO6"), |
| 624 | .regulators_node = of_match_ptr("regulators"), |
| 625 | .id = BD718XX_LDO6, |
| 626 | .ops = &bd718xx_ldo_regulator_ops, |
| 627 | .type = REGULATOR_VOLTAGE, |
| 628 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, |
| 629 | .linear_ranges = bd718xx_ldo6_volts, |
| 630 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), |
| 631 | /* LDO6 is supplied by buck5 */ |
| 632 | .supply_name = "buck5", |
| 633 | .vsel_reg = BD718XX_REG_LDO6_VOLT, |
| 634 | .vsel_mask = BD718XX_LDO6_MASK, |
| 635 | .enable_reg = BD718XX_REG_LDO6_VOLT, |
| 636 | .enable_mask = BD718XX_LDO_EN, |
| 637 | .owner = THIS_MODULE, |
| 638 | }, |
| 639 | .init = { |
| 640 | .reg = BD718XX_REG_LDO6_VOLT, |
| 641 | .mask = BD718XX_LDO_SEL, |
| 642 | .val = BD718XX_LDO_SEL, |
| 643 | }, |
| 644 | }, |
| 645 | }; |
| 646 | |
| 647 | static const struct bd718xx_regulator_data bd71837_regulators[] = { |
| 648 | { |
| 649 | .desc = { |
| 650 | .name = "buck1", |
| 651 | .of_match = of_match_ptr("BUCK1"), |
| 652 | .regulators_node = of_match_ptr("regulators"), |
| 653 | .id = BD718XX_BUCK1, |
| 654 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 655 | .type = REGULATOR_VOLTAGE, |
| 656 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 657 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 658 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 659 | .vsel_reg = BD718XX_REG_BUCK1_VOLT_RUN, |
| 660 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 661 | .enable_reg = BD718XX_REG_BUCK1_CTRL, |
| 662 | .enable_mask = BD718XX_BUCK_EN, |
| 663 | .owner = THIS_MODULE, |
| 664 | }, |
| 665 | .init = { |
| 666 | .reg = BD718XX_REG_BUCK1_CTRL, |
| 667 | .mask = BD718XX_BUCK_SEL, |
| 668 | .val = BD718XX_BUCK_SEL, |
| 669 | }, |
| 670 | }, |
| 671 | { |
| 672 | .desc = { |
| 673 | .name = "buck2", |
| 674 | .of_match = of_match_ptr("BUCK2"), |
| 675 | .regulators_node = of_match_ptr("regulators"), |
| 676 | .id = BD718XX_BUCK2, |
| 677 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 678 | .type = REGULATOR_VOLTAGE, |
| 679 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 680 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 681 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 682 | .vsel_reg = BD718XX_REG_BUCK2_VOLT_RUN, |
| 683 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 684 | .enable_reg = BD718XX_REG_BUCK2_CTRL, |
| 685 | .enable_mask = BD718XX_BUCK_EN, |
| 686 | .owner = THIS_MODULE, |
| 687 | }, |
| 688 | .init = { |
| 689 | .reg = BD718XX_REG_BUCK2_CTRL, |
| 690 | .mask = BD718XX_BUCK_SEL, |
| 691 | .val = BD718XX_BUCK_SEL, |
| 692 | }, |
| 693 | }, |
| 694 | { |
| 695 | .desc = { |
| 696 | .name = "buck3", |
| 697 | .of_match = of_match_ptr("BUCK3"), |
| 698 | .regulators_node = of_match_ptr("regulators"), |
| 699 | .id = BD718XX_BUCK3, |
| 700 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 701 | .type = REGULATOR_VOLTAGE, |
| 702 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 703 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 704 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 705 | .vsel_reg = BD71837_REG_BUCK3_VOLT_RUN, |
| 706 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 707 | .enable_reg = BD71837_REG_BUCK3_CTRL, |
| 708 | .enable_mask = BD718XX_BUCK_EN, |
| 709 | .owner = THIS_MODULE, |
| 710 | }, |
| 711 | .init = { |
| 712 | .reg = BD71837_REG_BUCK3_CTRL, |
| 713 | .mask = BD718XX_BUCK_SEL, |
| 714 | .val = BD718XX_BUCK_SEL, |
| 715 | }, |
| 716 | }, |
| 717 | { |
| 718 | .desc = { |
| 719 | .name = "buck4", |
| 720 | .of_match = of_match_ptr("BUCK4"), |
| 721 | .regulators_node = of_match_ptr("regulators"), |
| 722 | .id = BD718XX_BUCK4, |
| 723 | .ops = &bd718xx_dvs_buck_regulator_ops, |
| 724 | .type = REGULATOR_VOLTAGE, |
| 725 | .n_voltages = BD718XX_DVS_BUCK_VOLTAGE_NUM, |
| 726 | .linear_ranges = bd718xx_dvs_buck_volts, |
| 727 | .n_linear_ranges = ARRAY_SIZE(bd718xx_dvs_buck_volts), |
| 728 | .vsel_reg = BD71837_REG_BUCK4_VOLT_RUN, |
| 729 | .vsel_mask = DVS_BUCK_RUN_MASK, |
| 730 | .enable_reg = BD71837_REG_BUCK4_CTRL, |
| 731 | .enable_mask = BD718XX_BUCK_EN, |
| 732 | .owner = THIS_MODULE, |
| 733 | }, |
| 734 | .init = { |
| 735 | .reg = BD71837_REG_BUCK4_CTRL, |
| 736 | .mask = BD718XX_BUCK_SEL, |
| 737 | .val = BD718XX_BUCK_SEL, |
| 738 | }, |
| 739 | }, |
| 740 | { |
| 741 | .desc = { |
| 742 | .name = "buck5", |
| 743 | .of_match = of_match_ptr("BUCK5"), |
| 744 | .regulators_node = of_match_ptr("regulators"), |
| 745 | .id = BD718XX_BUCK5, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 746 | .ops = &bd718xx_pickable_range_buck_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 747 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 748 | .n_voltages = BD71837_BUCK5_VOLTAGE_NUM, |
| 749 | .linear_ranges = bd71837_buck5_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 750 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 751 | ARRAY_SIZE(bd71837_buck5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 752 | .vsel_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 753 | .vsel_mask = BD71837_BUCK5_MASK, |
| 754 | .vsel_range_reg = BD718XX_REG_1ST_NODVS_BUCK_VOLT, |
| 755 | .vsel_range_mask = BD71837_BUCK5_RANGE_MASK, |
| 756 | .linear_range_selectors = bd71837_buck5_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 757 | .enable_reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 758 | .enable_mask = BD718XX_BUCK_EN, |
| 759 | .owner = THIS_MODULE, |
| 760 | }, |
| 761 | .init = { |
| 762 | .reg = BD718XX_REG_1ST_NODVS_BUCK_CTRL, |
| 763 | .mask = BD718XX_BUCK_SEL, |
| 764 | .val = BD718XX_BUCK_SEL, |
| 765 | }, |
| 766 | }, |
| 767 | { |
| 768 | .desc = { |
| 769 | .name = "buck6", |
| 770 | .of_match = of_match_ptr("BUCK6"), |
| 771 | .regulators_node = of_match_ptr("regulators"), |
| 772 | .id = BD718XX_BUCK6, |
| 773 | .ops = &bd718xx_buck_regulator_ops, |
| 774 | .type = REGULATOR_VOLTAGE, |
| 775 | .n_voltages = BD71837_BUCK6_VOLTAGE_NUM, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 776 | .linear_ranges = bd71837_buck6_volts, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 777 | .n_linear_ranges = |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 778 | ARRAY_SIZE(bd71837_buck6_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 779 | .vsel_reg = BD718XX_REG_2ND_NODVS_BUCK_VOLT, |
| 780 | .vsel_mask = BD71837_BUCK6_MASK, |
| 781 | .enable_reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 782 | .enable_mask = BD718XX_BUCK_EN, |
| 783 | .owner = THIS_MODULE, |
| 784 | }, |
| 785 | .init = { |
| 786 | .reg = BD718XX_REG_2ND_NODVS_BUCK_CTRL, |
| 787 | .mask = BD718XX_BUCK_SEL, |
| 788 | .val = BD718XX_BUCK_SEL, |
| 789 | }, |
| 790 | }, |
| 791 | { |
| 792 | .desc = { |
| 793 | .name = "buck7", |
| 794 | .of_match = of_match_ptr("BUCK7"), |
| 795 | .regulators_node = of_match_ptr("regulators"), |
| 796 | .id = BD718XX_BUCK7, |
| 797 | .ops = &bd718xx_buck_regulator_nolinear_ops, |
| 798 | .type = REGULATOR_VOLTAGE, |
| 799 | .volt_table = &bd718xx_3rd_nodvs_buck_volts[0], |
| 800 | .n_voltages = ARRAY_SIZE(bd718xx_3rd_nodvs_buck_volts), |
| 801 | .vsel_reg = BD718XX_REG_3RD_NODVS_BUCK_VOLT, |
| 802 | .vsel_mask = BD718XX_3RD_NODVS_BUCK_MASK, |
| 803 | .enable_reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 804 | .enable_mask = BD718XX_BUCK_EN, |
| 805 | .owner = THIS_MODULE, |
| 806 | }, |
| 807 | .init = { |
| 808 | .reg = BD718XX_REG_3RD_NODVS_BUCK_CTRL, |
| 809 | .mask = BD718XX_BUCK_SEL, |
| 810 | .val = BD718XX_BUCK_SEL, |
| 811 | }, |
| 812 | }, |
| 813 | { |
| 814 | .desc = { |
| 815 | .name = "buck8", |
| 816 | .of_match = of_match_ptr("BUCK8"), |
| 817 | .regulators_node = of_match_ptr("regulators"), |
| 818 | .id = BD718XX_BUCK8, |
| 819 | .ops = &bd718xx_buck_regulator_ops, |
| 820 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 821 | .n_voltages = BD718XX_4TH_NODVS_BUCK_VOLTAGE_NUM, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 822 | .linear_ranges = bd718xx_4th_nodvs_buck_volts, |
| 823 | .n_linear_ranges = |
| 824 | ARRAY_SIZE(bd718xx_4th_nodvs_buck_volts), |
| 825 | .vsel_reg = BD718XX_REG_4TH_NODVS_BUCK_VOLT, |
| 826 | .vsel_mask = BD718XX_4TH_NODVS_BUCK_MASK, |
| 827 | .enable_reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 828 | .enable_mask = BD718XX_BUCK_EN, |
| 829 | .owner = THIS_MODULE, |
| 830 | }, |
| 831 | .init = { |
| 832 | .reg = BD718XX_REG_4TH_NODVS_BUCK_CTRL, |
| 833 | .mask = BD718XX_BUCK_SEL, |
| 834 | .val = BD718XX_BUCK_SEL, |
| 835 | }, |
| 836 | }, |
| 837 | { |
| 838 | .desc = { |
| 839 | .name = "ldo1", |
| 840 | .of_match = of_match_ptr("LDO1"), |
| 841 | .regulators_node = of_match_ptr("regulators"), |
| 842 | .id = BD718XX_LDO1, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 843 | .ops = &bd718xx_pickable_range_ldo_ops, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 844 | .type = REGULATOR_VOLTAGE, |
| 845 | .n_voltages = BD718XX_LDO1_VOLTAGE_NUM, |
| 846 | .linear_ranges = bd718xx_ldo1_volts, |
| 847 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo1_volts), |
| 848 | .vsel_reg = BD718XX_REG_LDO1_VOLT, |
| 849 | .vsel_mask = BD718XX_LDO1_MASK, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 850 | .vsel_range_reg = BD718XX_REG_LDO1_VOLT, |
| 851 | .vsel_range_mask = BD718XX_LDO1_RANGE_MASK, |
| 852 | .linear_range_selectors = bd718xx_ldo1_volt_range_sel, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 853 | .enable_reg = BD718XX_REG_LDO1_VOLT, |
| 854 | .enable_mask = BD718XX_LDO_EN, |
| 855 | .owner = THIS_MODULE, |
| 856 | }, |
| 857 | .init = { |
| 858 | .reg = BD718XX_REG_LDO1_VOLT, |
| 859 | .mask = BD718XX_LDO_SEL, |
| 860 | .val = BD718XX_LDO_SEL, |
| 861 | }, |
| 862 | }, |
| 863 | { |
| 864 | .desc = { |
| 865 | .name = "ldo2", |
| 866 | .of_match = of_match_ptr("LDO2"), |
| 867 | .regulators_node = of_match_ptr("regulators"), |
| 868 | .id = BD718XX_LDO2, |
| 869 | .ops = &bd718xx_ldo_regulator_nolinear_ops, |
| 870 | .type = REGULATOR_VOLTAGE, |
| 871 | .volt_table = &ldo_2_volts[0], |
| 872 | .vsel_reg = BD718XX_REG_LDO2_VOLT, |
| 873 | .vsel_mask = BD718XX_LDO2_MASK, |
| 874 | .n_voltages = ARRAY_SIZE(ldo_2_volts), |
| 875 | .enable_reg = BD718XX_REG_LDO2_VOLT, |
| 876 | .enable_mask = BD718XX_LDO_EN, |
| 877 | .owner = THIS_MODULE, |
| 878 | }, |
| 879 | .init = { |
| 880 | .reg = BD718XX_REG_LDO2_VOLT, |
| 881 | .mask = BD718XX_LDO_SEL, |
| 882 | .val = BD718XX_LDO_SEL, |
| 883 | }, |
| 884 | }, |
| 885 | { |
| 886 | .desc = { |
| 887 | .name = "ldo3", |
| 888 | .of_match = of_match_ptr("LDO3"), |
| 889 | .regulators_node = of_match_ptr("regulators"), |
| 890 | .id = BD718XX_LDO3, |
| 891 | .ops = &bd718xx_ldo_regulator_ops, |
| 892 | .type = REGULATOR_VOLTAGE, |
| 893 | .n_voltages = BD718XX_LDO3_VOLTAGE_NUM, |
| 894 | .linear_ranges = bd718xx_ldo3_volts, |
| 895 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo3_volts), |
| 896 | .vsel_reg = BD718XX_REG_LDO3_VOLT, |
| 897 | .vsel_mask = BD718XX_LDO3_MASK, |
| 898 | .enable_reg = BD718XX_REG_LDO3_VOLT, |
| 899 | .enable_mask = BD718XX_LDO_EN, |
| 900 | .owner = THIS_MODULE, |
| 901 | }, |
| 902 | .init = { |
| 903 | .reg = BD718XX_REG_LDO3_VOLT, |
| 904 | .mask = BD718XX_LDO_SEL, |
| 905 | .val = BD718XX_LDO_SEL, |
| 906 | }, |
| 907 | }, |
| 908 | { |
| 909 | .desc = { |
| 910 | .name = "ldo4", |
| 911 | .of_match = of_match_ptr("LDO4"), |
| 912 | .regulators_node = of_match_ptr("regulators"), |
| 913 | .id = BD718XX_LDO4, |
| 914 | .ops = &bd718xx_ldo_regulator_ops, |
| 915 | .type = REGULATOR_VOLTAGE, |
| 916 | .n_voltages = BD718XX_LDO4_VOLTAGE_NUM, |
| 917 | .linear_ranges = bd718xx_ldo4_volts, |
| 918 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo4_volts), |
| 919 | .vsel_reg = BD718XX_REG_LDO4_VOLT, |
| 920 | .vsel_mask = BD718XX_LDO4_MASK, |
| 921 | .enable_reg = BD718XX_REG_LDO4_VOLT, |
| 922 | .enable_mask = BD718XX_LDO_EN, |
| 923 | .owner = THIS_MODULE, |
| 924 | }, |
| 925 | .init = { |
| 926 | .reg = BD718XX_REG_LDO4_VOLT, |
| 927 | .mask = BD718XX_LDO_SEL, |
| 928 | .val = BD718XX_LDO_SEL, |
| 929 | }, |
| 930 | }, |
| 931 | { |
| 932 | .desc = { |
| 933 | .name = "ldo5", |
| 934 | .of_match = of_match_ptr("LDO5"), |
| 935 | .regulators_node = of_match_ptr("regulators"), |
| 936 | .id = BD718XX_LDO5, |
| 937 | .ops = &bd718xx_ldo_regulator_ops, |
| 938 | .type = REGULATOR_VOLTAGE, |
Matti Vaittinen | a4bfc2c | 2018-09-14 11:33:11 +0300 | [diff] [blame] | 939 | .n_voltages = BD71837_LDO5_VOLTAGE_NUM, |
| 940 | .linear_ranges = bd71837_ldo5_volts, |
| 941 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo5_volts), |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 942 | /* LDO5 is supplied by buck6 */ |
| 943 | .supply_name = "buck6", |
| 944 | .vsel_reg = BD718XX_REG_LDO5_VOLT, |
| 945 | .vsel_mask = BD71837_LDO5_MASK, |
| 946 | .enable_reg = BD718XX_REG_LDO5_VOLT, |
| 947 | .enable_mask = BD718XX_LDO_EN, |
| 948 | .owner = THIS_MODULE, |
| 949 | }, |
| 950 | .init = { |
| 951 | .reg = BD718XX_REG_LDO5_VOLT, |
| 952 | .mask = BD718XX_LDO_SEL, |
| 953 | .val = BD718XX_LDO_SEL, |
| 954 | }, |
| 955 | .additional_inits = bd71837_ldo5_inits, |
| 956 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo5_inits), |
| 957 | }, |
| 958 | { |
| 959 | .desc = { |
| 960 | .name = "ldo6", |
| 961 | .of_match = of_match_ptr("LDO6"), |
| 962 | .regulators_node = of_match_ptr("regulators"), |
| 963 | .id = BD718XX_LDO6, |
| 964 | .ops = &bd718xx_ldo_regulator_ops, |
| 965 | .type = REGULATOR_VOLTAGE, |
| 966 | .n_voltages = BD718XX_LDO6_VOLTAGE_NUM, |
| 967 | .linear_ranges = bd718xx_ldo6_volts, |
| 968 | .n_linear_ranges = ARRAY_SIZE(bd718xx_ldo6_volts), |
| 969 | /* LDO6 is supplied by buck7 */ |
| 970 | .supply_name = "buck7", |
| 971 | .vsel_reg = BD718XX_REG_LDO6_VOLT, |
| 972 | .vsel_mask = BD718XX_LDO6_MASK, |
| 973 | .enable_reg = BD718XX_REG_LDO6_VOLT, |
| 974 | .enable_mask = BD718XX_LDO_EN, |
| 975 | .owner = THIS_MODULE, |
| 976 | }, |
| 977 | .init = { |
| 978 | .reg = BD718XX_REG_LDO6_VOLT, |
| 979 | .mask = BD718XX_LDO_SEL, |
| 980 | .val = BD718XX_LDO_SEL, |
| 981 | }, |
| 982 | .additional_inits = bd71837_ldo6_inits, |
| 983 | .additional_init_amnt = ARRAY_SIZE(bd71837_ldo6_inits), |
| 984 | }, |
| 985 | { |
| 986 | .desc = { |
| 987 | .name = "ldo7", |
| 988 | .of_match = of_match_ptr("LDO7"), |
| 989 | .regulators_node = of_match_ptr("regulators"), |
| 990 | .id = BD718XX_LDO7, |
| 991 | .ops = &bd718xx_ldo_regulator_ops, |
| 992 | .type = REGULATOR_VOLTAGE, |
| 993 | .n_voltages = BD71837_LDO7_VOLTAGE_NUM, |
| 994 | .linear_ranges = bd71837_ldo7_volts, |
| 995 | .n_linear_ranges = ARRAY_SIZE(bd71837_ldo7_volts), |
| 996 | .vsel_reg = BD71837_REG_LDO7_VOLT, |
| 997 | .vsel_mask = BD71837_LDO7_MASK, |
| 998 | .enable_reg = BD71837_REG_LDO7_VOLT, |
| 999 | .enable_mask = BD718XX_LDO_EN, |
| 1000 | .owner = THIS_MODULE, |
| 1001 | }, |
| 1002 | .init = { |
| 1003 | .reg = BD71837_REG_LDO7_VOLT, |
| 1004 | .mask = BD718XX_LDO_SEL, |
| 1005 | .val = BD718XX_LDO_SEL, |
| 1006 | }, |
| 1007 | }, |
| 1008 | }; |
| 1009 | |
| 1010 | struct bd718xx_pmic_inits { |
Geert Uytterhoeven | de226eb | 2018-10-28 17:09:22 +0100 | [diff] [blame] | 1011 | const struct bd718xx_regulator_data *r_datas; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1012 | unsigned int r_amount; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1013 | }; |
| 1014 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1015 | static int bd718xx_probe(struct platform_device *pdev) |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1016 | { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1017 | struct bd718xx *mfd; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1018 | struct regulator_config config = { 0 }; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1019 | struct bd718xx_pmic_inits pmic_regulators[] = { |
| 1020 | [BD718XX_TYPE_BD71837] = { |
Geert Uytterhoeven | de226eb | 2018-10-28 17:09:22 +0100 | [diff] [blame] | 1021 | .r_datas = bd71837_regulators, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1022 | .r_amount = ARRAY_SIZE(bd71837_regulators), |
| 1023 | }, |
| 1024 | [BD718XX_TYPE_BD71847] = { |
Geert Uytterhoeven | de226eb | 2018-10-28 17:09:22 +0100 | [diff] [blame] | 1025 | .r_datas = bd71847_regulators, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1026 | .r_amount = ARRAY_SIZE(bd71847_regulators), |
| 1027 | }, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1028 | }; |
| 1029 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1030 | int i, j, err; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1031 | |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1032 | mfd = dev_get_drvdata(pdev->dev.parent); |
| 1033 | if (!mfd) { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1034 | dev_err(&pdev->dev, "No MFD driver data\n"); |
| 1035 | err = -EINVAL; |
| 1036 | goto err; |
| 1037 | } |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1038 | |
| 1039 | if (mfd->chip_type >= BD718XX_TYPE_AMOUNT || |
| 1040 | !pmic_regulators[mfd->chip_type].r_datas) { |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1041 | dev_err(&pdev->dev, "Unsupported chip type\n"); |
| 1042 | err = -EINVAL; |
| 1043 | goto err; |
| 1044 | } |
| 1045 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1046 | /* Register LOCK release */ |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1047 | err = regmap_update_bits(mfd->regmap, BD718XX_REG_REGLOCK, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1048 | (REGLOCK_PWRSEQ | REGLOCK_VREG), 0); |
| 1049 | if (err) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1050 | dev_err(&pdev->dev, "Failed to unlock PMIC (%d)\n", err); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1051 | goto err; |
| 1052 | } else { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1053 | dev_dbg(&pdev->dev, "Unlocked lock register 0x%x\n", |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1054 | BD718XX_REG_REGLOCK); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1055 | } |
| 1056 | |
Matti Vaittinen | e770b18 | 2018-11-07 15:41:26 +0200 | [diff] [blame^] | 1057 | /* At poweroff transition PMIC HW disables EN bit for regulators but |
| 1058 | * leaves SEL bit untouched. So if state transition from POWEROFF |
| 1059 | * is done to SNVS - then all power rails controlled by SW (having |
| 1060 | * SEL bit set) stay disabled as EN is cleared. This may result boot |
| 1061 | * failure if any crucial systems are powered by these rails. |
| 1062 | * |
| 1063 | * Change the next stage from poweroff to be READY instead of SNVS |
| 1064 | * for all reset types because OTP loading at READY will clear SEL |
| 1065 | * bit allowing HW defaults for power rails to be used |
| 1066 | */ |
| 1067 | err = regmap_update_bits(mfd->regmap, BD718XX_REG_TRANS_COND1, |
| 1068 | BD718XX_ON_REQ_POWEROFF_MASK | |
| 1069 | BD718XX_SWRESET_POWEROFF_MASK | |
| 1070 | BD718XX_WDOG_POWEROFF_MASK | |
| 1071 | BD718XX_KEY_L_POWEROFF_MASK, |
| 1072 | BD718XX_POWOFF_TO_RDY); |
| 1073 | if (err) { |
| 1074 | dev_err(&pdev->dev, "Failed to change reset target\n"); |
| 1075 | goto err; |
| 1076 | } else { |
| 1077 | dev_dbg(&pdev->dev, "Changed all resets from SVNS to READY\n"); |
| 1078 | } |
| 1079 | |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1080 | for (i = 0; i < pmic_regulators[mfd->chip_type].r_amount; i++) { |
Matti Vaittinen | 823f18f | 2018-08-29 15:36:10 +0300 | [diff] [blame] | 1081 | |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1082 | const struct regulator_desc *desc; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1083 | struct regulator_dev *rdev; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1084 | const struct bd718xx_regulator_data *r; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1085 | |
Geert Uytterhoeven | de226eb | 2018-10-28 17:09:22 +0100 | [diff] [blame] | 1086 | r = &pmic_regulators[mfd->chip_type].r_datas[i]; |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1087 | desc = &r->desc; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1088 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1089 | config.dev = pdev->dev.parent; |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1090 | config.regmap = mfd->regmap; |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1091 | |
| 1092 | rdev = devm_regulator_register(&pdev->dev, desc, &config); |
| 1093 | if (IS_ERR(rdev)) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1094 | dev_err(&pdev->dev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1095 | "failed to register %s regulator\n", |
| 1096 | desc->name); |
| 1097 | err = PTR_ERR(rdev); |
| 1098 | goto err; |
| 1099 | } |
| 1100 | /* Regulator register gets the regulator constraints and |
| 1101 | * applies them (set_machine_constraints). This should have |
| 1102 | * turned the control register(s) to correct values and we |
| 1103 | * can now switch the control from PMIC state machine to the |
| 1104 | * register interface |
| 1105 | */ |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1106 | err = regmap_update_bits(mfd->regmap, r->init.reg, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1107 | r->init.mask, r->init.val); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1108 | if (err) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1109 | dev_err(&pdev->dev, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1110 | "Failed to write BUCK/LDO SEL bit for (%s)\n", |
| 1111 | desc->name); |
| 1112 | goto err; |
| 1113 | } |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1114 | for (j = 0; j < r->additional_init_amnt; j++) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1115 | err = regmap_update_bits(mfd->regmap, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1116 | r->additional_inits[j].reg, |
| 1117 | r->additional_inits[j].mask, |
| 1118 | r->additional_inits[j].val); |
| 1119 | if (err) { |
Axel Lin | bcb047e | 2018-10-04 15:25:58 +0800 | [diff] [blame] | 1120 | dev_err(&pdev->dev, |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1121 | "Buck (%s) initialization failed\n", |
| 1122 | desc->name); |
| 1123 | goto err; |
| 1124 | } |
| 1125 | } |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1126 | } |
| 1127 | |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1128 | err: |
| 1129 | return err; |
| 1130 | } |
| 1131 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1132 | static struct platform_driver bd718xx_regulator = { |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1133 | .driver = { |
Matti Vaittinen | 494edd2 | 2018-09-14 11:27:46 +0300 | [diff] [blame] | 1134 | .name = "bd718xx-pmic", |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1135 | }, |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1136 | .probe = bd718xx_probe, |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1137 | }; |
| 1138 | |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1139 | module_platform_driver(bd718xx_regulator); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1140 | |
| 1141 | MODULE_AUTHOR("Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>"); |
Matti Vaittinen | dd2be63 | 2018-09-14 11:32:26 +0300 | [diff] [blame] | 1142 | MODULE_DESCRIPTION("BD71837/BD71847 voltage regulator driver"); |
Matti Vaittinen | ba08799 | 2018-05-30 11:43:43 +0300 | [diff] [blame] | 1143 | MODULE_LICENSE("GPL"); |