Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 1 | /* |
| 2 | * tps65023-regulator.c |
| 3 | * |
| 4 | * Supports TPS65023 Regulator |
| 5 | * |
| 6 | * Copyright (C) 2009 Texas Instrument 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 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 | /* LDO_CTRL bitfields */ |
| 73 | #define TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_id) ((ldo_id)*4) |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 74 | #define TPS65023_LDO_CTRL_LDOx_MASK(ldo_id) (0x0F << ((ldo_id)*4)) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 75 | |
| 76 | /* Number of step-down converters available */ |
| 77 | #define TPS65023_NUM_DCDC 3 |
| 78 | /* Number of LDO voltage regulators available */ |
| 79 | #define TPS65023_NUM_LDO 2 |
| 80 | /* Number of total regulators available */ |
| 81 | #define TPS65023_NUM_REGULATOR (TPS65023_NUM_DCDC + TPS65023_NUM_LDO) |
| 82 | |
| 83 | /* DCDCs */ |
| 84 | #define TPS65023_DCDC_1 0 |
| 85 | #define TPS65023_DCDC_2 1 |
| 86 | #define TPS65023_DCDC_3 2 |
| 87 | /* LDOs */ |
| 88 | #define TPS65023_LDO_1 3 |
| 89 | #define TPS65023_LDO_2 4 |
| 90 | |
| 91 | #define TPS65023_MAX_REG_ID TPS65023_LDO_2 |
| 92 | |
| 93 | /* Supported voltage values for regulators */ |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 94 | static const u16 VCORE_VSEL_table[] = { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 95 | 800, 825, 850, 875, |
| 96 | 900, 925, 950, 975, |
| 97 | 1000, 1025, 1050, 1075, |
| 98 | 1100, 1125, 1150, 1175, |
| 99 | 1200, 1225, 1250, 1275, |
| 100 | 1300, 1325, 1350, 1375, |
| 101 | 1400, 1425, 1450, 1475, |
| 102 | 1500, 1525, 1550, 1600, |
| 103 | }; |
| 104 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 105 | /* Supported voltage values for LDO regulators for tps65020 */ |
| 106 | static const u16 TPS65020_LDO1_VSEL_table[] = { |
| 107 | 1000, 1050, 1100, 1300, |
| 108 | 1800, 2500, 3000, 3300, |
| 109 | }; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 110 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 111 | static const u16 TPS65020_LDO2_VSEL_table[] = { |
| 112 | 1000, 1050, 1100, 1300, |
| 113 | 1800, 2500, 3000, 3300, |
| 114 | }; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 115 | |
| 116 | /* Supported voltage values for LDO regulators |
| 117 | * for tps65021 and tps65023 */ |
| 118 | static const u16 TPS65023_LDO1_VSEL_table[] = { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 119 | 1000, 1100, 1300, 1800, |
| 120 | 2200, 2600, 2800, 3150, |
| 121 | }; |
| 122 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 123 | static const u16 TPS65023_LDO2_VSEL_table[] = { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 124 | 1050, 1200, 1300, 1800, |
| 125 | 2500, 2800, 3000, 3300, |
| 126 | }; |
| 127 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 128 | /* Regulator specific details */ |
| 129 | struct tps_info { |
| 130 | const char *name; |
| 131 | unsigned min_uV; |
| 132 | unsigned max_uV; |
| 133 | bool fixed; |
| 134 | u8 table_len; |
| 135 | const u16 *table; |
| 136 | }; |
| 137 | |
| 138 | /* PMIC details */ |
| 139 | struct tps_pmic { |
| 140 | struct regulator_desc desc[TPS65023_NUM_REGULATOR]; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 141 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; |
| 142 | const struct tps_info *info[TPS65023_NUM_REGULATOR]; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 143 | struct regmap *regmap; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 144 | u8 core_regulator; |
| 145 | }; |
| 146 | |
| 147 | /* Struct passed as driver data */ |
| 148 | struct tps_driver_data { |
| 149 | const struct tps_info *info; |
| 150 | u8 core_regulator; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 151 | }; |
| 152 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 153 | static int tps65023_dcdc_get_voltage(struct regulator_dev *dev) |
| 154 | { |
| 155 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 156 | int ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 157 | int data, dcdc = rdev_get_id(dev); |
| 158 | |
| 159 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) |
| 160 | return -EINVAL; |
| 161 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 162 | if (dcdc == tps->core_regulator) { |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 163 | ret = regmap_read(tps->regmap, TPS65023_REG_DEF_CORE, &data); |
| 164 | if (ret != 0) |
| 165 | return ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 166 | data &= (tps->info[dcdc]->table_len - 1); |
| 167 | return tps->info[dcdc]->table[data] * 1000; |
| 168 | } else |
| 169 | return tps->info[dcdc]->min_uV; |
| 170 | } |
| 171 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 172 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, |
| 173 | unsigned selector) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 174 | { |
| 175 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 176 | int dcdc = rdev_get_id(dev); |
Marcus Folkesson | cc17ef3 | 2011-08-08 20:29:33 +0200 | [diff] [blame] | 177 | int ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 178 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 179 | if (dcdc != tps->core_regulator) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 180 | return -EINVAL; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 181 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 182 | ret = regmap_write(tps->regmap, TPS65023_REG_DEF_CORE, selector); |
| 183 | if (ret) |
| 184 | goto out; |
Marcus Folkesson | cc17ef3 | 2011-08-08 20:29:33 +0200 | [diff] [blame] | 185 | |
| 186 | /* Tell the chip that we have changed the value in DEFCORE |
| 187 | * and its time to update the core voltage |
| 188 | */ |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 189 | ret = regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, |
| 190 | TPS65023_REG_CTRL2_GO, TPS65023_REG_CTRL2_GO); |
Marcus Folkesson | cc17ef3 | 2011-08-08 20:29:33 +0200 | [diff] [blame] | 191 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 192 | out: |
Marcus Folkesson | cc17ef3 | 2011-08-08 20:29:33 +0200 | [diff] [blame] | 193 | return ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int tps65023_ldo_get_voltage(struct regulator_dev *dev) |
| 197 | { |
| 198 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 199 | int data, ldo = rdev_get_id(dev); |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 200 | int ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 201 | |
| 202 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) |
| 203 | return -EINVAL; |
| 204 | |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 205 | ret = regmap_read(tps->regmap, TPS65023_REG_LDO_CTRL, &data); |
| 206 | if (ret != 0) |
| 207 | return ret; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 208 | |
| 209 | data >>= (TPS65023_LDO_CTRL_LDOx_SHIFT(ldo - TPS65023_LDO_1)); |
| 210 | data &= (tps->info[ldo]->table_len - 1); |
| 211 | return tps->info[ldo]->table[data] * 1000; |
| 212 | } |
| 213 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 214 | static int tps65023_ldo_set_voltage_sel(struct regulator_dev *dev, |
| 215 | unsigned selector) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 216 | { |
| 217 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 218 | int ldo_index = rdev_get_id(dev) - TPS65023_LDO_1; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 219 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 220 | return regmap_update_bits(tps->regmap, TPS65023_REG_LDO_CTRL, |
| 221 | TPS65023_LDO_CTRL_LDOx_MASK(ldo_index), |
| 222 | selector << TPS65023_LDO_CTRL_LDOx_SHIFT(ldo_index)); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | static int tps65023_dcdc_list_voltage(struct regulator_dev *dev, |
| 226 | unsigned selector) |
| 227 | { |
| 228 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 229 | int dcdc = rdev_get_id(dev); |
| 230 | |
| 231 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) |
| 232 | return -EINVAL; |
| 233 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 234 | if (dcdc == tps->core_regulator) { |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 235 | if (selector >= tps->info[dcdc]->table_len) |
| 236 | return -EINVAL; |
| 237 | else |
| 238 | return tps->info[dcdc]->table[selector] * 1000; |
| 239 | } else |
| 240 | return tps->info[dcdc]->min_uV; |
| 241 | } |
| 242 | |
| 243 | static int tps65023_ldo_list_voltage(struct regulator_dev *dev, |
| 244 | unsigned selector) |
| 245 | { |
| 246 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 247 | int ldo = rdev_get_id(dev); |
| 248 | |
| 249 | if (ldo < TPS65023_LDO_1 || ldo > TPS65023_LDO_2) |
| 250 | return -EINVAL; |
| 251 | |
| 252 | if (selector >= tps->info[ldo]->table_len) |
| 253 | return -EINVAL; |
| 254 | else |
| 255 | return tps->info[ldo]->table[selector] * 1000; |
| 256 | } |
| 257 | |
| 258 | /* Operations permitted on VDCDCx */ |
| 259 | static struct regulator_ops tps65023_dcdc_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 260 | .is_enabled = regulator_is_enabled_regmap, |
| 261 | .enable = regulator_enable_regmap, |
| 262 | .disable = regulator_disable_regmap, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 263 | .get_voltage = tps65023_dcdc_get_voltage, |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 264 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 265 | .list_voltage = tps65023_dcdc_list_voltage, |
| 266 | }; |
| 267 | |
| 268 | /* Operations permitted on LDOx */ |
| 269 | static struct regulator_ops tps65023_ldo_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 270 | .is_enabled = regulator_is_enabled_regmap, |
| 271 | .enable = regulator_enable_regmap, |
| 272 | .disable = regulator_disable_regmap, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 273 | .get_voltage = tps65023_ldo_get_voltage, |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 274 | .set_voltage_sel = tps65023_ldo_set_voltage_sel, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 275 | .list_voltage = tps65023_ldo_list_voltage, |
| 276 | }; |
| 277 | |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 278 | static struct regmap_config tps65023_regmap_config = { |
| 279 | .reg_bits = 8, |
| 280 | .val_bits = 8, |
| 281 | }; |
| 282 | |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 283 | static int __devinit tps_65023_probe(struct i2c_client *client, |
| 284 | const struct i2c_device_id *id) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 285 | { |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 286 | const struct tps_driver_data *drv_data = (void *)id->driver_data; |
| 287 | const struct tps_info *info = drv_data->info; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 288 | struct regulator_config config = { }; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 289 | struct regulator_init_data *init_data; |
| 290 | struct regulator_dev *rdev; |
| 291 | struct tps_pmic *tps; |
| 292 | int i; |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 293 | int error; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 294 | |
| 295 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 296 | return -EIO; |
| 297 | |
| 298 | /** |
| 299 | * init_data points to array of regulator_init structures |
| 300 | * coming from the board-evm file. |
| 301 | */ |
| 302 | init_data = client->dev.platform_data; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 303 | if (!init_data) |
| 304 | return -EIO; |
| 305 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 306 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 307 | if (!tps) |
| 308 | return -ENOMEM; |
| 309 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 310 | tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 311 | if (IS_ERR(tps->regmap)) { |
| 312 | error = PTR_ERR(tps->regmap); |
| 313 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
| 314 | error); |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 315 | return error; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 316 | } |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 317 | |
| 318 | /* common for all regulators */ |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 319 | tps->core_regulator = drv_data->core_regulator; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 320 | |
| 321 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { |
| 322 | /* Store regulator specific information */ |
| 323 | tps->info[i] = info; |
| 324 | |
| 325 | tps->desc[i].name = info->name; |
Axel Lin | 77fa44d | 2011-05-12 13:47:50 +0800 | [diff] [blame] | 326 | tps->desc[i].id = i; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 327 | tps->desc[i].n_voltages = info->table_len; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 328 | tps->desc[i].ops = (i > TPS65023_DCDC_3 ? |
| 329 | &tps65023_ldo_ops : &tps65023_dcdc_ops); |
| 330 | tps->desc[i].type = REGULATOR_VOLTAGE; |
| 331 | tps->desc[i].owner = THIS_MODULE; |
| 332 | |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 333 | tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; |
| 334 | if (i == TPS65023_LDO_1) |
| 335 | tps->desc[i].enable_mask = 1 << 1; |
| 336 | else if (i == TPS65023_LDO_2) |
| 337 | tps->desc[i].enable_mask = 1 << 2; |
| 338 | else /* DCDCx */ |
| 339 | tps->desc[i].enable_mask = |
| 340 | 1 << (TPS65023_NUM_REGULATOR - i); |
| 341 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 342 | config.dev = &client->dev; |
| 343 | config.init_data = init_data; |
| 344 | config.driver_data = tps; |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 345 | config.regmap = tps->regmap; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 346 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 347 | /* Register the regulators */ |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 348 | rdev = regulator_register(&tps->desc[i], &config); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 349 | if (IS_ERR(rdev)) { |
| 350 | dev_err(&client->dev, "failed to register %s\n", |
| 351 | id->name); |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 352 | error = PTR_ERR(rdev); |
| 353 | goto fail; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* Save regulator for cleanup */ |
| 357 | tps->rdev[i] = rdev; |
| 358 | } |
| 359 | |
| 360 | i2c_set_clientdata(client, tps); |
| 361 | |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 362 | /* Enable setting output voltage by I2C */ |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 363 | regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, |
| 364 | TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 365 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 366 | return 0; |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 367 | |
| 368 | fail: |
| 369 | while (--i >= 0) |
| 370 | regulator_unregister(tps->rdev[i]); |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 371 | return error; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 372 | } |
| 373 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 374 | static int __devexit tps_65023_remove(struct i2c_client *client) |
| 375 | { |
| 376 | struct tps_pmic *tps = i2c_get_clientdata(client); |
| 377 | int i; |
| 378 | |
| 379 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) |
| 380 | regulator_unregister(tps->rdev[i]); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 381 | return 0; |
| 382 | } |
| 383 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 384 | static const struct tps_info tps65020_regs[] = { |
| 385 | { |
| 386 | .name = "VDCDC1", |
| 387 | .min_uV = 3300000, |
| 388 | .max_uV = 3300000, |
| 389 | .fixed = 1, |
| 390 | }, |
| 391 | { |
| 392 | .name = "VDCDC2", |
| 393 | .min_uV = 1800000, |
| 394 | .max_uV = 1800000, |
| 395 | .fixed = 1, |
| 396 | }, |
| 397 | { |
| 398 | .name = "VDCDC3", |
| 399 | .min_uV = 800000, |
| 400 | .max_uV = 1600000, |
| 401 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 402 | .table = VCORE_VSEL_table, |
| 403 | }, |
| 404 | |
| 405 | { |
| 406 | .name = "LDO1", |
| 407 | .min_uV = 1000000, |
| 408 | .max_uV = 3150000, |
| 409 | .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), |
| 410 | .table = TPS65020_LDO1_VSEL_table, |
| 411 | }, |
| 412 | { |
| 413 | .name = "LDO2", |
| 414 | .min_uV = 1050000, |
| 415 | .max_uV = 3300000, |
| 416 | .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), |
| 417 | .table = TPS65020_LDO2_VSEL_table, |
| 418 | }, |
| 419 | }; |
| 420 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 421 | static const struct tps_info tps65021_regs[] = { |
| 422 | { |
| 423 | .name = "VDCDC1", |
| 424 | .min_uV = 3300000, |
| 425 | .max_uV = 3300000, |
| 426 | .fixed = 1, |
| 427 | }, |
| 428 | { |
| 429 | .name = "VDCDC2", |
| 430 | .min_uV = 1800000, |
| 431 | .max_uV = 1800000, |
| 432 | .fixed = 1, |
| 433 | }, |
| 434 | { |
| 435 | .name = "VDCDC3", |
| 436 | .min_uV = 800000, |
| 437 | .max_uV = 1600000, |
| 438 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 439 | .table = VCORE_VSEL_table, |
| 440 | }, |
| 441 | { |
| 442 | .name = "LDO1", |
| 443 | .min_uV = 1000000, |
| 444 | .max_uV = 3150000, |
| 445 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
| 446 | .table = TPS65023_LDO1_VSEL_table, |
| 447 | }, |
| 448 | { |
| 449 | .name = "LDO2", |
| 450 | .min_uV = 1050000, |
| 451 | .max_uV = 3300000, |
| 452 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
| 453 | .table = TPS65023_LDO2_VSEL_table, |
| 454 | }, |
| 455 | }; |
| 456 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 457 | static const struct tps_info tps65023_regs[] = { |
| 458 | { |
| 459 | .name = "VDCDC1", |
| 460 | .min_uV = 800000, |
| 461 | .max_uV = 1600000, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 462 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 463 | .table = VCORE_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 464 | }, |
| 465 | { |
| 466 | .name = "VDCDC2", |
| 467 | .min_uV = 3300000, |
| 468 | .max_uV = 3300000, |
| 469 | .fixed = 1, |
| 470 | }, |
| 471 | { |
| 472 | .name = "VDCDC3", |
| 473 | .min_uV = 1800000, |
| 474 | .max_uV = 1800000, |
| 475 | .fixed = 1, |
| 476 | }, |
| 477 | { |
| 478 | .name = "LDO1", |
| 479 | .min_uV = 1000000, |
| 480 | .max_uV = 3150000, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 481 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
| 482 | .table = TPS65023_LDO1_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 483 | }, |
| 484 | { |
| 485 | .name = "LDO2", |
| 486 | .min_uV = 1050000, |
| 487 | .max_uV = 3300000, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 488 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
| 489 | .table = TPS65023_LDO2_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 490 | }, |
| 491 | }; |
| 492 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 493 | static struct tps_driver_data tps65020_drv_data = { |
| 494 | .info = tps65020_regs, |
| 495 | .core_regulator = TPS65023_DCDC_3, |
| 496 | }; |
| 497 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 498 | static struct tps_driver_data tps65021_drv_data = { |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 499 | .info = tps65021_regs, |
| 500 | .core_regulator = TPS65023_DCDC_3, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 501 | }; |
| 502 | |
| 503 | static struct tps_driver_data tps65023_drv_data = { |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 504 | .info = tps65023_regs, |
| 505 | .core_regulator = TPS65023_DCDC_1, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 506 | }; |
| 507 | |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 508 | static const struct i2c_device_id tps_65023_id[] = { |
| 509 | {.name = "tps65023", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 510 | .driver_data = (unsigned long) &tps65023_drv_data}, |
Marek Vasut | 1880a2f | 2010-06-24 15:49:49 +0200 | [diff] [blame] | 511 | {.name = "tps65021", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 512 | .driver_data = (unsigned long) &tps65021_drv_data,}, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 513 | {.name = "tps65020", |
| 514 | .driver_data = (unsigned long) &tps65020_drv_data}, |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 515 | { }, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 516 | }; |
| 517 | |
| 518 | MODULE_DEVICE_TABLE(i2c, tps_65023_id); |
| 519 | |
| 520 | static struct i2c_driver tps_65023_i2c_driver = { |
| 521 | .driver = { |
| 522 | .name = "tps65023", |
| 523 | .owner = THIS_MODULE, |
| 524 | }, |
| 525 | .probe = tps_65023_probe, |
| 526 | .remove = __devexit_p(tps_65023_remove), |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 527 | .id_table = tps_65023_id, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 528 | }; |
| 529 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 530 | static int __init tps_65023_init(void) |
| 531 | { |
| 532 | return i2c_add_driver(&tps_65023_i2c_driver); |
| 533 | } |
| 534 | subsys_initcall(tps_65023_init); |
| 535 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 536 | static void __exit tps_65023_cleanup(void) |
| 537 | { |
| 538 | i2c_del_driver(&tps_65023_i2c_driver); |
| 539 | } |
| 540 | module_exit(tps_65023_cleanup); |
| 541 | |
| 542 | MODULE_AUTHOR("Texas Instruments"); |
| 543 | MODULE_DESCRIPTION("TPS65023 voltage regulator driver"); |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 544 | MODULE_LICENSE("GPL v2"); |