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