Thomas Gleixner | abd4627 | 2022-06-07 16:11:31 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 2 | /* |
| 3 | * tps65218-regulator.c |
| 4 | * |
| 5 | * Regulator driver for TPS65218 PMIC |
| 6 | * |
Alexander A. Klimov | 2ca76b3 | 2020-07-19 22:06:23 +0200 | [diff] [blame] | 7 | * Copyright (C) 2014 Texas Instruments Incorporated - https://www.ti.com/ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/module.h> |
| 12 | #include <linux/device.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/err.h> |
| 15 | #include <linux/platform_device.h> |
| 16 | #include <linux/of_device.h> |
Keerthy | 0aced35 | 2016-09-19 13:09:02 +0530 | [diff] [blame] | 17 | #include <linux/regmap.h> |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 18 | #include <linux/regulator/of_regulator.h> |
| 19 | #include <linux/regulator/driver.h> |
| 20 | #include <linux/regulator/machine.h> |
| 21 | #include <linux/mfd/tps65218.h> |
| 22 | |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 23 | #define TPS65218_REGULATOR(_name, _of, _id, _type, _ops, _n, _vr, _vm, _er, \ |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 24 | _em, _cr, _cm, _lr, _nlr, _delay, _fuv, _sr, _sm, \ |
| 25 | _ct, _ncl) \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 26 | { \ |
| 27 | .name = _name, \ |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 28 | .of_match = _of, \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 29 | .id = _id, \ |
| 30 | .ops = &_ops, \ |
| 31 | .n_voltages = _n, \ |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 32 | .type = _type, \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 33 | .owner = THIS_MODULE, \ |
| 34 | .vsel_reg = _vr, \ |
| 35 | .vsel_mask = _vm, \ |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 36 | .csel_reg = _cr, \ |
| 37 | .csel_mask = _cm, \ |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 38 | .curr_table = _ct, \ |
| 39 | .n_current_limits = _ncl, \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 40 | .enable_reg = _er, \ |
| 41 | .enable_mask = _em, \ |
Felipe Balbi | dd648ef | 2014-07-08 14:09:13 -0500 | [diff] [blame] | 42 | .volt_table = NULL, \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 43 | .linear_ranges = _lr, \ |
| 44 | .n_linear_ranges = _nlr, \ |
Axel Lin | 5ab9be4 | 2014-05-22 09:26:47 +0800 | [diff] [blame] | 45 | .ramp_delay = _delay, \ |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 46 | .fixed_uV = _fuv, \ |
| 47 | .bypass_reg = _sr, \ |
| 48 | .bypass_mask = _sm, \ |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 49 | } \ |
| 50 | |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 51 | static const struct linear_range dcdc1_dcdc2_ranges[] = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 52 | REGULATOR_LINEAR_RANGE(850000, 0x0, 0x32, 10000), |
| 53 | REGULATOR_LINEAR_RANGE(1375000, 0x33, 0x3f, 25000), |
| 54 | }; |
| 55 | |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 56 | static const struct linear_range ldo1_dcdc3_ranges[] = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 57 | REGULATOR_LINEAR_RANGE(900000, 0x0, 0x1a, 25000), |
| 58 | REGULATOR_LINEAR_RANGE(1600000, 0x1b, 0x3f, 50000), |
| 59 | }; |
| 60 | |
Matti Vaittinen | 60ab7f4 | 2020-05-08 18:43:36 +0300 | [diff] [blame] | 61 | static const struct linear_range dcdc4_ranges[] = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 62 | REGULATOR_LINEAR_RANGE(1175000, 0x0, 0xf, 25000), |
Felipe Balbi | 42ab0f3 | 2014-07-08 14:09:12 -0500 | [diff] [blame] | 63 | REGULATOR_LINEAR_RANGE(1600000, 0x10, 0x34, 50000), |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 64 | }; |
| 65 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 66 | static int tps65218_pmic_set_voltage_sel(struct regulator_dev *dev, |
| 67 | unsigned selector) |
| 68 | { |
| 69 | int ret; |
| 70 | struct tps65218 *tps = rdev_get_drvdata(dev); |
| 71 | unsigned int rid = rdev_get_id(dev); |
| 72 | |
| 73 | /* Set the voltage based on vsel value and write protect level is 2 */ |
| 74 | ret = tps65218_set_bits(tps, dev->desc->vsel_reg, dev->desc->vsel_mask, |
| 75 | selector, TPS65218_PROTECT_L1); |
| 76 | |
| 77 | /* Set GO bit for DCDC1/2 to initiate voltage transistion */ |
| 78 | switch (rid) { |
| 79 | case TPS65218_DCDC_1: |
| 80 | case TPS65218_DCDC_2: |
| 81 | ret = tps65218_set_bits(tps, TPS65218_REG_CONTRL_SLEW_RATE, |
| 82 | TPS65218_SLEW_RATE_GO, |
| 83 | TPS65218_SLEW_RATE_GO, |
| 84 | TPS65218_PROTECT_L1); |
| 85 | break; |
| 86 | } |
| 87 | |
| 88 | return ret; |
| 89 | } |
| 90 | |
| 91 | static int tps65218_pmic_enable(struct regulator_dev *dev) |
| 92 | { |
| 93 | struct tps65218 *tps = rdev_get_drvdata(dev); |
Sachin Kamat | 5f986f7 | 2014-06-24 13:59:16 +0530 | [diff] [blame] | 94 | int rid = rdev_get_id(dev); |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 95 | |
| 96 | if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1) |
| 97 | return -EINVAL; |
| 98 | |
| 99 | /* Enable the regulator and password protection is level 1 */ |
| 100 | return tps65218_set_bits(tps, dev->desc->enable_reg, |
| 101 | dev->desc->enable_mask, dev->desc->enable_mask, |
| 102 | TPS65218_PROTECT_L1); |
| 103 | } |
| 104 | |
| 105 | static int tps65218_pmic_disable(struct regulator_dev *dev) |
| 106 | { |
| 107 | struct tps65218 *tps = rdev_get_drvdata(dev); |
Sachin Kamat | 5f986f7 | 2014-06-24 13:59:16 +0530 | [diff] [blame] | 108 | int rid = rdev_get_id(dev); |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 109 | |
| 110 | if (rid < TPS65218_DCDC_1 || rid > TPS65218_LDO_1) |
| 111 | return -EINVAL; |
| 112 | |
| 113 | /* Disable the regulator and password protection is level 1 */ |
| 114 | return tps65218_clear_bits(tps, dev->desc->enable_reg, |
| 115 | dev->desc->enable_mask, TPS65218_PROTECT_L1); |
| 116 | } |
| 117 | |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 118 | static int tps65218_pmic_set_suspend_enable(struct regulator_dev *dev) |
| 119 | { |
| 120 | struct tps65218 *tps = rdev_get_drvdata(dev); |
| 121 | unsigned int rid = rdev_get_id(dev); |
| 122 | |
Lee Jones | 02d8886 | 2020-06-26 07:57:36 +0100 | [diff] [blame] | 123 | if (rid > TPS65218_LDO_1) |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 124 | return -EINVAL; |
| 125 | |
| 126 | return tps65218_clear_bits(tps, dev->desc->bypass_reg, |
| 127 | dev->desc->bypass_mask, |
| 128 | TPS65218_PROTECT_L1); |
| 129 | } |
| 130 | |
| 131 | static int tps65218_pmic_set_suspend_disable(struct regulator_dev *dev) |
| 132 | { |
| 133 | struct tps65218 *tps = rdev_get_drvdata(dev); |
| 134 | unsigned int rid = rdev_get_id(dev); |
| 135 | |
Lee Jones | 02d8886 | 2020-06-26 07:57:36 +0100 | [diff] [blame] | 136 | if (rid > TPS65218_LDO_1) |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 137 | return -EINVAL; |
| 138 | |
Tero Kristo | 23a34f9 | 2016-08-10 17:53:55 +0530 | [diff] [blame] | 139 | /* |
| 140 | * Certain revisions of TPS65218 will need to have DCDC3 regulator |
| 141 | * enabled always, otherwise an immediate system reboot will occur |
| 142 | * during poweroff. |
| 143 | */ |
| 144 | if (rid == TPS65218_DCDC_3 && tps->rev == TPS65218_REV_2_1) |
| 145 | return 0; |
| 146 | |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 147 | if (!tps->strobes[rid]) { |
Tero Kristo | 3fb2ef1 | 2016-06-24 13:58:09 +0530 | [diff] [blame] | 148 | if (rid == TPS65218_DCDC_3) |
Keerthy | efeb88c | 2017-11-10 17:22:43 +0530 | [diff] [blame] | 149 | tps->strobes[rid] = 3; |
Tero Kristo | 3fb2ef1 | 2016-06-24 13:58:09 +0530 | [diff] [blame] | 150 | else |
| 151 | return -EINVAL; |
| 152 | } |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 153 | |
| 154 | return tps65218_set_bits(tps, dev->desc->bypass_reg, |
| 155 | dev->desc->bypass_mask, |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 156 | tps->strobes[rid], TPS65218_PROTECT_L1); |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 157 | } |
| 158 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 159 | /* Operations permitted on DCDC1, DCDC2 */ |
Axel Lin | d1030b4 | 2019-03-24 10:05:42 +0800 | [diff] [blame] | 160 | static const struct regulator_ops tps65218_dcdc12_ops = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 161 | .is_enabled = regulator_is_enabled_regmap, |
| 162 | .enable = tps65218_pmic_enable, |
| 163 | .disable = tps65218_pmic_disable, |
| 164 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 165 | .set_voltage_sel = tps65218_pmic_set_voltage_sel, |
| 166 | .list_voltage = regulator_list_voltage_linear_range, |
| 167 | .map_voltage = regulator_map_voltage_linear_range, |
Axel Lin | 5ab9be4 | 2014-05-22 09:26:47 +0800 | [diff] [blame] | 168 | .set_voltage_time_sel = regulator_set_voltage_time_sel, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 169 | .set_suspend_enable = tps65218_pmic_set_suspend_enable, |
| 170 | .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 171 | }; |
| 172 | |
| 173 | /* Operations permitted on DCDC3, DCDC4 and LDO1 */ |
Axel Lin | d1030b4 | 2019-03-24 10:05:42 +0800 | [diff] [blame] | 174 | static const struct regulator_ops tps65218_ldo1_dcdc34_ops = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 175 | .is_enabled = regulator_is_enabled_regmap, |
| 176 | .enable = tps65218_pmic_enable, |
| 177 | .disable = tps65218_pmic_disable, |
| 178 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 179 | .set_voltage_sel = tps65218_pmic_set_voltage_sel, |
| 180 | .list_voltage = regulator_list_voltage_linear_range, |
| 181 | .map_voltage = regulator_map_voltage_linear_range, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 182 | .set_suspend_enable = tps65218_pmic_set_suspend_enable, |
| 183 | .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 184 | }; |
| 185 | |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 186 | static const unsigned int ls3_currents[] = { 100000, 200000, 500000, 1000000 }; |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 187 | |
| 188 | static int tps65218_pmic_set_input_current_lim(struct regulator_dev *dev, |
| 189 | int lim_uA) |
| 190 | { |
| 191 | unsigned int index = 0; |
| 192 | unsigned int num_currents = ARRAY_SIZE(ls3_currents); |
| 193 | struct tps65218 *tps = rdev_get_drvdata(dev); |
| 194 | |
| 195 | while (index < num_currents && ls3_currents[index] != lim_uA) |
| 196 | index++; |
| 197 | |
| 198 | if (index == num_currents) |
| 199 | return -EINVAL; |
| 200 | |
| 201 | return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, |
Christian Hohnstaedt | e5c8ba0 | 2019-02-22 09:38:54 +0100 | [diff] [blame] | 202 | index << __builtin_ctz(dev->desc->csel_mask), |
| 203 | TPS65218_PROTECT_L1); |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int tps65218_pmic_set_current_limit(struct regulator_dev *dev, |
| 207 | int min_uA, int max_uA) |
| 208 | { |
| 209 | int index = 0; |
| 210 | unsigned int num_currents = ARRAY_SIZE(ls3_currents); |
| 211 | struct tps65218 *tps = rdev_get_drvdata(dev); |
| 212 | |
Christian Hohnstaedt | 71a64ba | 2019-02-20 09:15:50 +0100 | [diff] [blame] | 213 | while (index < num_currents && ls3_currents[index] <= max_uA) |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 214 | index++; |
| 215 | |
| 216 | index--; |
| 217 | |
| 218 | if (index < 0 || ls3_currents[index] < min_uA) |
| 219 | return -EINVAL; |
| 220 | |
| 221 | return tps65218_set_bits(tps, dev->desc->csel_reg, dev->desc->csel_mask, |
Christian Hohnstaedt | e5c8ba0 | 2019-02-22 09:38:54 +0100 | [diff] [blame] | 222 | index << __builtin_ctz(dev->desc->csel_mask), |
| 223 | TPS65218_PROTECT_L1); |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 224 | } |
| 225 | |
Axel Lin | d1030b4 | 2019-03-24 10:05:42 +0800 | [diff] [blame] | 226 | static const struct regulator_ops tps65218_ls23_ops = { |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 227 | .is_enabled = regulator_is_enabled_regmap, |
| 228 | .enable = tps65218_pmic_enable, |
| 229 | .disable = tps65218_pmic_disable, |
| 230 | .set_input_current_limit = tps65218_pmic_set_input_current_lim, |
| 231 | .set_current_limit = tps65218_pmic_set_current_limit, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 232 | .get_current_limit = regulator_get_current_limit_regmap, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 233 | }; |
| 234 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 235 | /* Operations permitted on DCDC5, DCDC6 */ |
Axel Lin | d1030b4 | 2019-03-24 10:05:42 +0800 | [diff] [blame] | 236 | static const struct regulator_ops tps65218_dcdc56_pmic_ops = { |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 237 | .is_enabled = regulator_is_enabled_regmap, |
| 238 | .enable = tps65218_pmic_enable, |
| 239 | .disable = tps65218_pmic_disable, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 240 | .set_suspend_enable = tps65218_pmic_set_suspend_enable, |
| 241 | .set_suspend_disable = tps65218_pmic_set_suspend_disable, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 242 | }; |
| 243 | |
| 244 | static const struct regulator_desc regulators[] = { |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 245 | TPS65218_REGULATOR("DCDC1", "regulator-dcdc1", TPS65218_DCDC_1, |
| 246 | REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64, |
| 247 | TPS65218_REG_CONTROL_DCDC1, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 248 | TPS65218_CONTROL_DCDC1_MASK, TPS65218_REG_ENABLE1, |
| 249 | TPS65218_ENABLE1_DC1_EN, 0, 0, dcdc1_dcdc2_ranges, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 250 | 2, 4000, 0, TPS65218_REG_SEQ3, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 251 | TPS65218_SEQ3_DC1_SEQ_MASK, NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 252 | TPS65218_REGULATOR("DCDC2", "regulator-dcdc2", TPS65218_DCDC_2, |
| 253 | REGULATOR_VOLTAGE, tps65218_dcdc12_ops, 64, |
| 254 | TPS65218_REG_CONTROL_DCDC2, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 255 | TPS65218_CONTROL_DCDC2_MASK, TPS65218_REG_ENABLE1, |
| 256 | TPS65218_ENABLE1_DC2_EN, 0, 0, dcdc1_dcdc2_ranges, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 257 | 2, 4000, 0, TPS65218_REG_SEQ3, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 258 | TPS65218_SEQ3_DC2_SEQ_MASK, NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 259 | TPS65218_REGULATOR("DCDC3", "regulator-dcdc3", TPS65218_DCDC_3, |
| 260 | REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 261 | TPS65218_REG_CONTROL_DCDC3, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 262 | TPS65218_CONTROL_DCDC3_MASK, TPS65218_REG_ENABLE1, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 263 | TPS65218_ENABLE1_DC3_EN, 0, 0, ldo1_dcdc3_ranges, 2, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 264 | 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC3_SEQ_MASK, |
| 265 | NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 266 | TPS65218_REGULATOR("DCDC4", "regulator-dcdc4", TPS65218_DCDC_4, |
| 267 | REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 53, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 268 | TPS65218_REG_CONTROL_DCDC4, |
| 269 | TPS65218_CONTROL_DCDC4_MASK, TPS65218_REG_ENABLE1, |
| 270 | TPS65218_ENABLE1_DC4_EN, 0, 0, dcdc4_ranges, 2, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 271 | 0, 0, TPS65218_REG_SEQ4, TPS65218_SEQ4_DC4_SEQ_MASK, |
| 272 | NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 273 | TPS65218_REGULATOR("DCDC5", "regulator-dcdc5", TPS65218_DCDC_5, |
| 274 | REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1, |
| 275 | -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC5_EN, 0, |
| 276 | 0, NULL, 0, 0, 1000000, TPS65218_REG_SEQ5, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 277 | TPS65218_SEQ5_DC5_SEQ_MASK, NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 278 | TPS65218_REGULATOR("DCDC6", "regulator-dcdc6", TPS65218_DCDC_6, |
| 279 | REGULATOR_VOLTAGE, tps65218_dcdc56_pmic_ops, 1, -1, |
| 280 | -1, TPS65218_REG_ENABLE1, TPS65218_ENABLE1_DC6_EN, 0, |
| 281 | 0, NULL, 0, 0, 1800000, TPS65218_REG_SEQ5, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 282 | TPS65218_SEQ5_DC6_SEQ_MASK, NULL, 0), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 283 | TPS65218_REGULATOR("LDO1", "regulator-ldo1", TPS65218_LDO_1, |
| 284 | REGULATOR_VOLTAGE, tps65218_ldo1_dcdc34_ops, 64, |
Keerthy | 0eada6a | 2014-06-18 10:17:48 -0500 | [diff] [blame] | 285 | TPS65218_REG_CONTROL_LDO1, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 286 | TPS65218_CONTROL_LDO1_MASK, TPS65218_REG_ENABLE2, |
Nikita Kiryanov | c0ea88b | 2015-11-25 13:59:04 +0200 | [diff] [blame] | 287 | TPS65218_ENABLE2_LDO1_EN, 0, 0, ldo1_dcdc3_ranges, |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 288 | 2, 0, 0, TPS65218_REG_SEQ6, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 289 | TPS65218_SEQ6_LDO1_SEQ_MASK, NULL, 0), |
Christian Hohnstaedt | e5c8ba0 | 2019-02-22 09:38:54 +0100 | [diff] [blame] | 290 | TPS65218_REGULATOR("LS2", "regulator-ls2", TPS65218_LS_2, |
| 291 | REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0, |
| 292 | TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS2_EN, |
| 293 | TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS2ILIM_MASK, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 294 | NULL, 0, 0, 0, 0, 0, ls3_currents, |
| 295 | ARRAY_SIZE(ls3_currents)), |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 296 | TPS65218_REGULATOR("LS3", "regulator-ls3", TPS65218_LS_3, |
Christian Hohnstaedt | e5c8ba0 | 2019-02-22 09:38:54 +0100 | [diff] [blame] | 297 | REGULATOR_CURRENT, tps65218_ls23_ops, 0, 0, 0, |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 298 | TPS65218_REG_ENABLE2, TPS65218_ENABLE2_LS3_EN, |
| 299 | TPS65218_REG_CONFIG2, TPS65218_CONFIG2_LS3ILIM_MASK, |
Axel Lin | 7cfcecf | 2019-04-13 10:29:07 +0800 | [diff] [blame] | 300 | NULL, 0, 0, 0, 0, 0, ls3_currents, |
| 301 | ARRAY_SIZE(ls3_currents)), |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 302 | }; |
| 303 | |
| 304 | static int tps65218_regulator_probe(struct platform_device *pdev) |
| 305 | { |
| 306 | struct tps65218 *tps = dev_get_drvdata(pdev->dev.parent); |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 307 | struct regulator_dev *rdev; |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 308 | struct regulator_config config = { }; |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 309 | int i, ret; |
Tero Kristo | b9a0d35 | 2016-06-24 13:58:08 +0530 | [diff] [blame] | 310 | unsigned int val; |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 311 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 312 | config.dev = &pdev->dev; |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 313 | config.dev->of_node = tps->dev->of_node; |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 314 | config.driver_data = tps; |
| 315 | config.regmap = tps->regmap; |
| 316 | |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 317 | /* Allocate memory for strobes */ |
Kees Cook | a86854d | 2018-06-12 14:07:58 -0700 | [diff] [blame] | 318 | tps->strobes = devm_kcalloc(&pdev->dev, |
| 319 | TPS65218_NUM_REGULATOR, sizeof(u8), |
| 320 | GFP_KERNEL); |
Axel Lin | 5597bfb | 2017-11-13 20:52:32 +0800 | [diff] [blame] | 321 | if (!tps->strobes) |
| 322 | return -ENOMEM; |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 323 | |
| 324 | for (i = 0; i < ARRAY_SIZE(regulators); i++) { |
| 325 | rdev = devm_regulator_register(&pdev->dev, ®ulators[i], |
| 326 | &config); |
| 327 | if (IS_ERR(rdev)) { |
| 328 | dev_err(tps->dev, "failed to register %s regulator\n", |
| 329 | pdev->name); |
| 330 | return PTR_ERR(rdev); |
| 331 | } |
| 332 | |
| 333 | ret = regmap_read(tps->regmap, regulators[i].bypass_reg, &val); |
| 334 | if (ret) |
| 335 | return ret; |
| 336 | |
| 337 | tps->strobes[i] = val & regulators[i].bypass_mask; |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 338 | } |
| 339 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 340 | return 0; |
| 341 | } |
| 342 | |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 343 | static const struct platform_device_id tps65218_regulator_id_table[] = { |
| 344 | { "tps65218-regulator", }, |
| 345 | { /* sentinel */ } |
| 346 | }; |
| 347 | MODULE_DEVICE_TABLE(platform, tps65218_regulator_id_table); |
| 348 | |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 349 | static struct platform_driver tps65218_regulator_driver = { |
| 350 | .driver = { |
| 351 | .name = "tps65218-pmic", |
Douglas Anderson | 259b93b | 2023-03-16 12:54:38 -0700 | [diff] [blame] | 352 | .probe_type = PROBE_PREFER_ASYNCHRONOUS, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 353 | }, |
| 354 | .probe = tps65218_regulator_probe, |
Keerthy | 2dc4940 | 2016-09-19 13:09:06 +0530 | [diff] [blame] | 355 | .id_table = tps65218_regulator_id_table, |
Keerthy | 90e7d52 | 2014-02-06 11:20:13 +0530 | [diff] [blame] | 356 | }; |
| 357 | |
| 358 | module_platform_driver(tps65218_regulator_driver); |
| 359 | |
| 360 | MODULE_AUTHOR("J Keerthy <j-keerthy@ti.com>"); |
| 361 | MODULE_DESCRIPTION("TPS65218 voltage regulator driver"); |
| 362 | MODULE_ALIAS("platform:tps65218-pmic"); |
| 363 | MODULE_LICENSE("GPL v2"); |