Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | * tps65023-regulator.c |
| 3 | * |
| 4 | * Supports TPS65023 Regulator |
| 5 | * |
Alexander A. Klimov | 2ca76b3 | 2020-07-19 22:06:23 +0200 | [diff] [blame] | 6 | * Copyright (C) 2009 Texas Instrument Incorporated - https://www.ti.com/ |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 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 as |
| 10 | * published by the Free Software Foundation version 2. |
| 11 | * |
| 12 | * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind, |
| 13 | * whether express or implied; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | */ |
| 17 | |
| 18 | #include <linux/kernel.h> |
| 19 | #include <linux/module.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/err.h> |
| 22 | #include <linux/platform_device.h> |
| 23 | #include <linux/regulator/driver.h> |
| 24 | #include <linux/regulator/machine.h> |
| 25 | #include <linux/i2c.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 27 | #include <linux/regmap.h> |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 28 | |
| 29 | /* Register definitions */ |
| 30 | #define TPS65023_REG_VERSION 0 |
| 31 | #define TPS65023_REG_PGOODZ 1 |
| 32 | #define TPS65023_REG_MASK 2 |
| 33 | #define TPS65023_REG_REG_CTRL 3 |
| 34 | #define TPS65023_REG_CON_CTRL 4 |
| 35 | #define TPS65023_REG_CON_CTRL2 5 |
| 36 | #define TPS65023_REG_DEF_CORE 6 |
| 37 | #define TPS65023_REG_DEFSLEW 7 |
| 38 | #define TPS65023_REG_LDO_CTRL 8 |
| 39 | |
| 40 | /* PGOODZ bitfields */ |
| 41 | #define TPS65023_PGOODZ_PWRFAILZ BIT(7) |
| 42 | #define TPS65023_PGOODZ_LOWBATTZ BIT(6) |
| 43 | #define TPS65023_PGOODZ_VDCDC1 BIT(5) |
| 44 | #define TPS65023_PGOODZ_VDCDC2 BIT(4) |
| 45 | #define TPS65023_PGOODZ_VDCDC3 BIT(3) |
| 46 | #define TPS65023_PGOODZ_LDO2 BIT(2) |
| 47 | #define TPS65023_PGOODZ_LDO1 BIT(1) |
| 48 | |
| 49 | /* MASK bitfields */ |
| 50 | #define TPS65023_MASK_PWRFAILZ BIT(7) |
| 51 | #define TPS65023_MASK_LOWBATTZ BIT(6) |
| 52 | #define TPS65023_MASK_VDCDC1 BIT(5) |
| 53 | #define TPS65023_MASK_VDCDC2 BIT(4) |
| 54 | #define TPS65023_MASK_VDCDC3 BIT(3) |
| 55 | #define TPS65023_MASK_LDO2 BIT(2) |
| 56 | #define TPS65023_MASK_LDO1 BIT(1) |
| 57 | |
| 58 | /* REG_CTRL bitfields */ |
| 59 | #define TPS65023_REG_CTRL_VDCDC1_EN BIT(5) |
| 60 | #define TPS65023_REG_CTRL_VDCDC2_EN BIT(4) |
| 61 | #define TPS65023_REG_CTRL_VDCDC3_EN BIT(3) |
| 62 | #define TPS65023_REG_CTRL_LDO2_EN BIT(2) |
| 63 | #define TPS65023_REG_CTRL_LDO1_EN BIT(1) |
| 64 | |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 65 | /* REG_CTRL2 bitfields */ |
| 66 | #define TPS65023_REG_CTRL2_GO BIT(7) |
| 67 | #define TPS65023_REG_CTRL2_CORE_ADJ BIT(6) |
| 68 | #define TPS65023_REG_CTRL2_DCDC2 BIT(2) |
Marcus Folkesson | f068ad8 | 2011-08-08 20:29:32 +0200 | [diff] [blame] | 69 | #define TPS65023_REG_CTRL2_DCDC1 BIT(1) |
| 70 | #define TPS65023_REG_CTRL2_DCDC3 BIT(0) |
| 71 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 72 | /* Number of step-down converters available */ |
| 73 | #define TPS65023_NUM_DCDC 3 |
| 74 | /* Number of LDO voltage regulators available */ |
| 75 | #define TPS65023_NUM_LDO 2 |
| 76 | /* Number of total regulators available */ |
| 77 | #define TPS65023_NUM_REGULATOR (TPS65023_NUM_DCDC + TPS65023_NUM_LDO) |
| 78 | |
| 79 | /* DCDCs */ |
| 80 | #define TPS65023_DCDC_1 0 |
| 81 | #define TPS65023_DCDC_2 1 |
| 82 | #define TPS65023_DCDC_3 2 |
| 83 | /* LDOs */ |
| 84 | #define TPS65023_LDO_1 3 |
| 85 | #define TPS65023_LDO_2 4 |
| 86 | |
| 87 | #define TPS65023_MAX_REG_ID TPS65023_LDO_2 |
| 88 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 89 | #define TPS65023_REGULATOR_DCDC(_num, _t, _em) \ |
| 90 | { \ |
| 91 | .name = "VDCDC"#_num, \ |
| 92 | .of_match = of_match_ptr("VDCDC"#_num), \ |
| 93 | .regulators_node = of_match_ptr("regulators"), \ |
| 94 | .id = TPS65023_DCDC_##_num, \ |
| 95 | .n_voltages = ARRAY_SIZE(_t), \ |
| 96 | .ops = &tps65023_dcdc_ops, \ |
| 97 | .type = REGULATOR_VOLTAGE, \ |
| 98 | .owner = THIS_MODULE, \ |
| 99 | .volt_table = _t, \ |
| 100 | .vsel_reg = TPS65023_REG_DEF_CORE, \ |
| 101 | .vsel_mask = ARRAY_SIZE(_t) - 1, \ |
| 102 | .enable_mask = _em, \ |
| 103 | .enable_reg = TPS65023_REG_REG_CTRL, \ |
| 104 | .apply_reg = TPS65023_REG_CON_CTRL2, \ |
| 105 | .apply_bit = TPS65023_REG_CTRL2_GO, \ |
| 106 | } \ |
| 107 | |
| 108 | #define TPS65023_REGULATOR_LDO(_num, _t, _vm) \ |
| 109 | { \ |
| 110 | .name = "LDO"#_num, \ |
| 111 | .of_match = of_match_ptr("LDO"#_num), \ |
| 112 | .regulators_node = of_match_ptr("regulators"), \ |
| 113 | .id = TPS65023_LDO_##_num, \ |
| 114 | .n_voltages = ARRAY_SIZE(_t), \ |
| 115 | .ops = &tps65023_ldo_ops, \ |
| 116 | .type = REGULATOR_VOLTAGE, \ |
| 117 | .owner = THIS_MODULE, \ |
| 118 | .volt_table = _t, \ |
| 119 | .vsel_reg = TPS65023_REG_LDO_CTRL, \ |
| 120 | .vsel_mask = _vm, \ |
| 121 | .enable_mask = 1 << (_num), \ |
| 122 | .enable_reg = TPS65023_REG_REG_CTRL, \ |
| 123 | } \ |
| 124 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 125 | /* Supported voltage values for regulators */ |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 126 | static const unsigned int VCORE_VSEL_table[] = { |
| 127 | 800000, 825000, 850000, 875000, |
| 128 | 900000, 925000, 950000, 975000, |
| 129 | 1000000, 1025000, 1050000, 1075000, |
| 130 | 1100000, 1125000, 1150000, 1175000, |
| 131 | 1200000, 1225000, 1250000, 1275000, |
| 132 | 1300000, 1325000, 1350000, 1375000, |
| 133 | 1400000, 1425000, 1450000, 1475000, |
| 134 | 1500000, 1525000, 1550000, 1600000, |
| 135 | }; |
| 136 | |
| 137 | static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = { |
| 138 | 3300000, |
| 139 | }; |
| 140 | |
| 141 | static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = { |
| 142 | 1800000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 143 | }; |
| 144 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 145 | /* Supported voltage values for LDO regulators for tps65020 */ |
Axel Lin | 2040541 | 2013-04-25 11:31:42 +0800 | [diff] [blame] | 146 | static const unsigned int TPS65020_LDO_VSEL_table[] = { |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 147 | 1000000, 1050000, 1100000, 1300000, |
| 148 | 1800000, 2500000, 3000000, 3300000, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 149 | }; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 150 | |
| 151 | /* Supported voltage values for LDO regulators |
| 152 | * for tps65021 and tps65023 */ |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 153 | static const unsigned int TPS65023_LDO1_VSEL_table[] = { |
| 154 | 1000000, 1100000, 1300000, 1800000, |
| 155 | 2200000, 2600000, 2800000, 3150000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 156 | }; |
| 157 | |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 158 | static const unsigned int TPS65023_LDO2_VSEL_table[] = { |
| 159 | 1050000, 1200000, 1300000, 1800000, |
| 160 | 2500000, 2800000, 3000000, 3300000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 161 | }; |
| 162 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 163 | /* PMIC details */ |
| 164 | struct tps_pmic { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 165 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 166 | const struct tps_driver_data *driver_data; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 167 | struct regmap *regmap; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 168 | }; |
| 169 | |
| 170 | /* Struct passed as driver data */ |
| 171 | struct tps_driver_data { |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 172 | const struct regulator_desc *desc; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 173 | u8 core_regulator; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 174 | }; |
| 175 | |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 176 | static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 177 | { |
| 178 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame] | 179 | int dcdc = rdev_get_id(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 180 | |
| 181 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) |
| 182 | return -EINVAL; |
| 183 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 184 | if (dcdc != tps->driver_data->core_regulator) |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 185 | return 0; |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame] | 186 | |
| 187 | return regulator_get_voltage_sel_regmap(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 188 | } |
| 189 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 190 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, |
| 191 | unsigned selector) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 192 | { |
| 193 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 194 | int dcdc = rdev_get_id(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 195 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 196 | if (dcdc != tps->driver_data->core_regulator) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 197 | return -EINVAL; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 198 | |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame] | 199 | return regulator_set_voltage_sel_regmap(dev, selector); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 200 | } |
| 201 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 202 | /* Operations permitted on VDCDCx */ |
Krzysztof Kozlowski | 4604a06 | 2015-01-05 10:05:48 +0100 | [diff] [blame] | 203 | static const struct regulator_ops tps65023_dcdc_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 204 | .is_enabled = regulator_is_enabled_regmap, |
| 205 | .enable = regulator_enable_regmap, |
| 206 | .disable = regulator_disable_regmap, |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 207 | .get_voltage_sel = tps65023_dcdc_get_voltage_sel, |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 208 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 209 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | c4bbfbd | 2013-04-25 11:32:40 +0800 | [diff] [blame] | 210 | .map_voltage = regulator_map_voltage_ascend, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 211 | }; |
| 212 | |
| 213 | /* Operations permitted on LDOx */ |
Krzysztof Kozlowski | 4604a06 | 2015-01-05 10:05:48 +0100 | [diff] [blame] | 214 | static const struct regulator_ops tps65023_ldo_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 215 | .is_enabled = regulator_is_enabled_regmap, |
| 216 | .enable = regulator_enable_regmap, |
| 217 | .disable = regulator_disable_regmap, |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 218 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 219 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 220 | .list_voltage = regulator_list_voltage_table, |
Axel Lin | c4bbfbd | 2013-04-25 11:32:40 +0800 | [diff] [blame] | 221 | .map_voltage = regulator_map_voltage_ascend, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 222 | }; |
| 223 | |
Krzysztof Kozlowski | 4604a06 | 2015-01-05 10:05:48 +0100 | [diff] [blame] | 224 | static const struct regmap_config tps65023_regmap_config = { |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 225 | .reg_bits = 8, |
| 226 | .val_bits = 8, |
| 227 | }; |
| 228 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 229 | static const struct regulator_desc tps65020_regulators[] = { |
| 230 | TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), |
| 231 | TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), |
| 232 | TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), |
| 233 | TPS65023_REGULATOR_LDO(1, TPS65020_LDO_VSEL_table, 0x07), |
| 234 | TPS65023_REGULATOR_LDO(2, TPS65020_LDO_VSEL_table, 0x70), |
| 235 | }; |
| 236 | |
| 237 | static const struct regulator_desc tps65021_regulators[] = { |
| 238 | TPS65023_REGULATOR_DCDC(1, DCDC_FIXED_3300000_VSEL_table, 0x20), |
| 239 | TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_1800000_VSEL_table, 0x10), |
| 240 | TPS65023_REGULATOR_DCDC(3, VCORE_VSEL_table, 0x08), |
| 241 | TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), |
| 242 | TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), |
| 243 | }; |
| 244 | |
| 245 | static const struct regulator_desc tps65023_regulators[] = { |
| 246 | TPS65023_REGULATOR_DCDC(1, VCORE_VSEL_table, 0x20), |
| 247 | TPS65023_REGULATOR_DCDC(2, DCDC_FIXED_3300000_VSEL_table, 0x10), |
| 248 | TPS65023_REGULATOR_DCDC(3, DCDC_FIXED_1800000_VSEL_table, 0x08), |
| 249 | TPS65023_REGULATOR_LDO(1, TPS65023_LDO1_VSEL_table, 0x07), |
| 250 | TPS65023_REGULATOR_LDO(2, TPS65023_LDO2_VSEL_table, 0x70), |
| 251 | }; |
| 252 | |
| 253 | static struct tps_driver_data tps65020_drv_data = { |
| 254 | .desc = tps65020_regulators, |
| 255 | .core_regulator = TPS65023_DCDC_3, |
| 256 | }; |
| 257 | |
| 258 | static struct tps_driver_data tps65021_drv_data = { |
| 259 | .desc = tps65021_regulators, |
| 260 | .core_regulator = TPS65023_DCDC_3, |
| 261 | }; |
| 262 | |
| 263 | static struct tps_driver_data tps65023_drv_data = { |
| 264 | .desc = tps65023_regulators, |
| 265 | .core_regulator = TPS65023_DCDC_1, |
| 266 | }; |
| 267 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 268 | static int tps_65023_probe(struct i2c_client *client, |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 269 | const struct i2c_device_id *id) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 270 | { |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 271 | struct regulator_init_data *init_data = dev_get_platdata(&client->dev); |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 272 | struct regulator_config config = { }; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 273 | struct tps_pmic *tps; |
| 274 | int i; |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 275 | int error; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 276 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 277 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 278 | if (!tps) |
| 279 | return -ENOMEM; |
| 280 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 281 | tps->driver_data = (struct tps_driver_data *)id->driver_data; |
| 282 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 283 | tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 284 | if (IS_ERR(tps->regmap)) { |
| 285 | error = PTR_ERR(tps->regmap); |
| 286 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
| 287 | error); |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 288 | return error; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 289 | } |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 290 | |
| 291 | /* common for all regulators */ |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 292 | config.dev = &client->dev; |
| 293 | config.driver_data = tps; |
| 294 | config.regmap = tps->regmap; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 295 | |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 296 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) { |
| 297 | if (init_data) |
| 298 | config.init_data = &init_data[i]; |
Mark Brown | c172708d | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 299 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 300 | /* Register the regulators */ |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 301 | tps->rdev[i] = devm_regulator_register(&client->dev, |
| 302 | &tps->driver_data->desc[i], &config); |
| 303 | if (IS_ERR(tps->rdev[i])) { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 304 | dev_err(&client->dev, "failed to register %s\n", |
| 305 | id->name); |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 306 | return PTR_ERR(tps->rdev[i]); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 307 | } |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | i2c_set_clientdata(client, tps); |
| 311 | |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 312 | /* Enable setting output voltage by I2C */ |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 313 | regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, |
Richard Cochran | c90722b | 2017-04-17 10:23:36 +0200 | [diff] [blame] | 314 | TPS65023_REG_CTRL2_CORE_ADJ, 0); |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 315 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 316 | return 0; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 317 | } |
| 318 | |
Jisheng Zhang | 8536bf8 | 2020-08-21 11:20:09 +0800 | [diff] [blame] | 319 | static const struct of_device_id __maybe_unused tps65023_of_match[] = { |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 320 | { .compatible = "ti,tps65020", .data = &tps65020_drv_data}, |
| 321 | { .compatible = "ti,tps65021", .data = &tps65021_drv_data}, |
| 322 | { .compatible = "ti,tps65023", .data = &tps65023_drv_data}, |
| 323 | {}, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 324 | }; |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 325 | MODULE_DEVICE_TABLE(of, tps65023_of_match); |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 326 | |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 327 | static const struct i2c_device_id tps_65023_id[] = { |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 328 | { |
| 329 | .name = "tps65023", |
| 330 | .driver_data = (kernel_ulong_t)&tps65023_drv_data |
| 331 | }, { |
| 332 | .name = "tps65021", |
| 333 | .driver_data = (kernel_ulong_t)&tps65021_drv_data |
| 334 | }, { |
| 335 | .name = "tps65020", |
| 336 | .driver_data = (kernel_ulong_t)&tps65020_drv_data |
| 337 | }, |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 338 | { }, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 339 | }; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 340 | MODULE_DEVICE_TABLE(i2c, tps_65023_id); |
| 341 | |
| 342 | static struct i2c_driver tps_65023_i2c_driver = { |
| 343 | .driver = { |
| 344 | .name = "tps65023", |
Thomas Elste | 2d3eda6 | 2015-09-21 16:30:47 +0200 | [diff] [blame] | 345 | .of_match_table = of_match_ptr(tps65023_of_match), |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 346 | }, |
| 347 | .probe = tps_65023_probe, |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 348 | .id_table = tps_65023_id, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 349 | }; |
| 350 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 351 | static int __init tps_65023_init(void) |
| 352 | { |
| 353 | return i2c_add_driver(&tps_65023_i2c_driver); |
| 354 | } |
| 355 | subsys_initcall(tps_65023_init); |
| 356 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 357 | static void __exit tps_65023_cleanup(void) |
| 358 | { |
| 359 | i2c_del_driver(&tps_65023_i2c_driver); |
| 360 | } |
| 361 | module_exit(tps_65023_cleanup); |
| 362 | |
| 363 | MODULE_AUTHOR("Texas Instruments"); |
| 364 | MODULE_DESCRIPTION("TPS65023 voltage regulator driver"); |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 365 | MODULE_LICENSE("GPL v2"); |