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 | /* 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 | |
| 89 | /* Supported voltage values for regulators */ |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 90 | static const unsigned int VCORE_VSEL_table[] = { |
| 91 | 800000, 825000, 850000, 875000, |
| 92 | 900000, 925000, 950000, 975000, |
| 93 | 1000000, 1025000, 1050000, 1075000, |
| 94 | 1100000, 1125000, 1150000, 1175000, |
| 95 | 1200000, 1225000, 1250000, 1275000, |
| 96 | 1300000, 1325000, 1350000, 1375000, |
| 97 | 1400000, 1425000, 1450000, 1475000, |
| 98 | 1500000, 1525000, 1550000, 1600000, |
| 99 | }; |
| 100 | |
| 101 | static const unsigned int DCDC_FIXED_3300000_VSEL_table[] = { |
| 102 | 3300000, |
| 103 | }; |
| 104 | |
| 105 | static const unsigned int DCDC_FIXED_1800000_VSEL_table[] = { |
| 106 | 1800000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 107 | }; |
| 108 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 109 | /* Supported voltage values for LDO regulators for tps65020 */ |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 110 | static const unsigned int TPS65020_LDO1_VSEL_table[] = { |
| 111 | 1000000, 1050000, 1100000, 1300000, |
| 112 | 1800000, 2500000, 3000000, 3300000, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 113 | }; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 114 | |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 115 | static const unsigned int TPS65020_LDO2_VSEL_table[] = { |
| 116 | 1000000, 1050000, 1100000, 1300000, |
| 117 | 1800000, 2500000, 3000000, 3300000, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 118 | }; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 119 | |
| 120 | /* Supported voltage values for LDO regulators |
| 121 | * for tps65021 and tps65023 */ |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 122 | static const unsigned int TPS65023_LDO1_VSEL_table[] = { |
| 123 | 1000000, 1100000, 1300000, 1800000, |
| 124 | 2200000, 2600000, 2800000, 3150000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 125 | }; |
| 126 | |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 127 | static const unsigned int TPS65023_LDO2_VSEL_table[] = { |
| 128 | 1050000, 1200000, 1300000, 1800000, |
| 129 | 2500000, 2800000, 3000000, 3300000, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 130 | }; |
| 131 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 132 | /* Regulator specific details */ |
| 133 | struct tps_info { |
| 134 | const char *name; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 135 | u8 table_len; |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 136 | const unsigned int *table; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 137 | }; |
| 138 | |
| 139 | /* PMIC details */ |
| 140 | struct tps_pmic { |
| 141 | struct regulator_desc desc[TPS65023_NUM_REGULATOR]; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 142 | struct regulator_dev *rdev[TPS65023_NUM_REGULATOR]; |
| 143 | const struct tps_info *info[TPS65023_NUM_REGULATOR]; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 144 | struct regmap *regmap; |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 145 | u8 core_regulator; |
| 146 | }; |
| 147 | |
| 148 | /* Struct passed as driver data */ |
| 149 | struct tps_driver_data { |
| 150 | const struct tps_info *info; |
| 151 | u8 core_regulator; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 152 | }; |
| 153 | |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 154 | static int tps65023_dcdc_get_voltage_sel(struct regulator_dev *dev) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 155 | { |
| 156 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame^] | 157 | int dcdc = rdev_get_id(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 158 | |
| 159 | if (dcdc < TPS65023_DCDC_1 || dcdc > TPS65023_DCDC_3) |
| 160 | return -EINVAL; |
| 161 | |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame^] | 162 | if (dcdc != tps->core_regulator) |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 163 | return 0; |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame^] | 164 | |
| 165 | return regulator_get_voltage_sel_regmap(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 166 | } |
| 167 | |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 168 | static int tps65023_dcdc_set_voltage_sel(struct regulator_dev *dev, |
| 169 | unsigned selector) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 170 | { |
| 171 | struct tps_pmic *tps = rdev_get_drvdata(dev); |
| 172 | int dcdc = rdev_get_id(dev); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 173 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 174 | if (dcdc != tps->core_regulator) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 175 | return -EINVAL; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 176 | |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame^] | 177 | return regulator_set_voltage_sel_regmap(dev, selector); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 178 | } |
| 179 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 180 | /* Operations permitted on VDCDCx */ |
| 181 | static struct regulator_ops tps65023_dcdc_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 182 | .is_enabled = regulator_is_enabled_regmap, |
| 183 | .enable = regulator_enable_regmap, |
| 184 | .disable = regulator_disable_regmap, |
Axel Lin | a133829 | 2012-06-19 17:13:13 +0800 | [diff] [blame] | 185 | .get_voltage_sel = tps65023_dcdc_get_voltage_sel, |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 186 | .set_voltage_sel = tps65023_dcdc_set_voltage_sel, |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 187 | .list_voltage = regulator_list_voltage_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | /* Operations permitted on LDOx */ |
| 191 | static struct regulator_ops tps65023_ldo_ops = { |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 192 | .is_enabled = regulator_is_enabled_regmap, |
| 193 | .enable = regulator_enable_regmap, |
| 194 | .disable = regulator_disable_regmap, |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 195 | .get_voltage_sel = regulator_get_voltage_sel_regmap, |
| 196 | .set_voltage_sel = regulator_set_voltage_sel_regmap, |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 197 | .list_voltage = regulator_list_voltage_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 198 | }; |
| 199 | |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 200 | static struct regmap_config tps65023_regmap_config = { |
| 201 | .reg_bits = 8, |
| 202 | .val_bits = 8, |
| 203 | }; |
| 204 | |
Bill Pemberton | a502357 | 2012-11-19 13:22:22 -0500 | [diff] [blame] | 205 | static int tps_65023_probe(struct i2c_client *client, |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 206 | const struct i2c_device_id *id) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 207 | { |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 208 | const struct tps_driver_data *drv_data = (void *)id->driver_data; |
| 209 | const struct tps_info *info = drv_data->info; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 210 | struct regulator_config config = { }; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 211 | struct regulator_init_data *init_data; |
| 212 | struct regulator_dev *rdev; |
| 213 | struct tps_pmic *tps; |
| 214 | int i; |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 215 | int error; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 216 | |
| 217 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 218 | return -EIO; |
| 219 | |
| 220 | /** |
| 221 | * init_data points to array of regulator_init structures |
| 222 | * coming from the board-evm file. |
| 223 | */ |
| 224 | init_data = client->dev.platform_data; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 225 | if (!init_data) |
| 226 | return -EIO; |
| 227 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 228 | tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 229 | if (!tps) |
| 230 | return -ENOMEM; |
| 231 | |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 232 | tps->regmap = devm_regmap_init_i2c(client, &tps65023_regmap_config); |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 233 | if (IS_ERR(tps->regmap)) { |
| 234 | error = PTR_ERR(tps->regmap); |
| 235 | dev_err(&client->dev, "Failed to allocate register map: %d\n", |
| 236 | error); |
Axel Lin | 19a8da2 | 2012-04-07 23:31:44 +0800 | [diff] [blame] | 237 | return error; |
Mark Brown | 9092335 | 2011-06-18 01:18:51 +0100 | [diff] [blame] | 238 | } |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 239 | |
| 240 | /* common for all regulators */ |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 241 | tps->core_regulator = drv_data->core_regulator; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 242 | |
| 243 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++, info++, init_data++) { |
| 244 | /* Store regulator specific information */ |
| 245 | tps->info[i] = info; |
| 246 | |
| 247 | tps->desc[i].name = info->name; |
Axel Lin | 77fa44d | 2011-05-12 13:47:50 +0800 | [diff] [blame] | 248 | tps->desc[i].id = i; |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 249 | tps->desc[i].n_voltages = info->table_len; |
| 250 | tps->desc[i].volt_table = info->table; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 251 | tps->desc[i].ops = (i > TPS65023_DCDC_3 ? |
| 252 | &tps65023_ldo_ops : &tps65023_dcdc_ops); |
| 253 | tps->desc[i].type = REGULATOR_VOLTAGE; |
| 254 | tps->desc[i].owner = THIS_MODULE; |
| 255 | |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 256 | tps->desc[i].enable_reg = TPS65023_REG_REG_CTRL; |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 257 | switch (i) { |
| 258 | case TPS65023_LDO_1: |
| 259 | tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; |
| 260 | tps->desc[i].vsel_mask = 0x07; |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 261 | tps->desc[i].enable_mask = 1 << 1; |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 262 | break; |
| 263 | case TPS65023_LDO_2: |
| 264 | tps->desc[i].vsel_reg = TPS65023_REG_LDO_CTRL; |
| 265 | tps->desc[i].vsel_mask = 0x70; |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 266 | tps->desc[i].enable_mask = 1 << 2; |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 267 | break; |
| 268 | default: /* DCDCx */ |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 269 | tps->desc[i].enable_mask = |
| 270 | 1 << (TPS65023_NUM_REGULATOR - i); |
Axel Lin | 46bcb00 | 2013-04-23 11:54:48 +0800 | [diff] [blame^] | 271 | tps->desc[i].vsel_reg = TPS65023_REG_DEF_CORE; |
| 272 | tps->desc[i].vsel_mask = info->table_len - 1; |
| 273 | tps->desc[i].apply_reg = TPS65023_REG_CON_CTRL2; |
| 274 | tps->desc[i].apply_bit = TPS65023_REG_CTRL2_GO; |
Axel Lin | e90a844 | 2012-06-19 17:14:31 +0800 | [diff] [blame] | 275 | } |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 276 | |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 277 | config.dev = &client->dev; |
| 278 | config.init_data = init_data; |
| 279 | config.driver_data = tps; |
Axel Lin | ee7b191 | 2012-04-16 19:03:09 +0800 | [diff] [blame] | 280 | config.regmap = tps->regmap; |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 281 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 282 | /* Register the regulators */ |
Mark Brown | c172708 | 2012-04-04 00:50:22 +0100 | [diff] [blame] | 283 | rdev = regulator_register(&tps->desc[i], &config); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 284 | if (IS_ERR(rdev)) { |
| 285 | dev_err(&client->dev, "failed to register %s\n", |
| 286 | id->name); |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 287 | error = PTR_ERR(rdev); |
| 288 | goto fail; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | /* Save regulator for cleanup */ |
| 292 | tps->rdev[i] = rdev; |
| 293 | } |
| 294 | |
| 295 | i2c_set_clientdata(client, tps); |
| 296 | |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 297 | /* Enable setting output voltage by I2C */ |
Jonghwan Choi | 43530b6 | 2011-11-07 08:16:04 +0900 | [diff] [blame] | 298 | regmap_update_bits(tps->regmap, TPS65023_REG_CON_CTRL2, |
| 299 | TPS65023_REG_CTRL2_CORE_ADJ, TPS65023_REG_CTRL2_CORE_ADJ); |
Marcus Folkesson | fc999b8 | 2011-08-04 13:33:49 +0200 | [diff] [blame] | 300 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 301 | return 0; |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 302 | |
| 303 | fail: |
| 304 | while (--i >= 0) |
| 305 | regulator_unregister(tps->rdev[i]); |
Dmitry Torokhov | 54d13ab | 2010-02-23 23:38:06 -0800 | [diff] [blame] | 306 | return error; |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 307 | } |
| 308 | |
Bill Pemberton | 8dc995f | 2012-11-19 13:26:10 -0500 | [diff] [blame] | 309 | static int tps_65023_remove(struct i2c_client *client) |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 310 | { |
| 311 | struct tps_pmic *tps = i2c_get_clientdata(client); |
| 312 | int i; |
| 313 | |
| 314 | for (i = 0; i < TPS65023_NUM_REGULATOR; i++) |
| 315 | regulator_unregister(tps->rdev[i]); |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 316 | return 0; |
| 317 | } |
| 318 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 319 | static const struct tps_info tps65020_regs[] = { |
| 320 | { |
| 321 | .name = "VDCDC1", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 322 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
| 323 | .table = DCDC_FIXED_3300000_VSEL_table, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 324 | }, |
| 325 | { |
| 326 | .name = "VDCDC2", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 327 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
| 328 | .table = DCDC_FIXED_1800000_VSEL_table, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 329 | }, |
| 330 | { |
| 331 | .name = "VDCDC3", |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 332 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 333 | .table = VCORE_VSEL_table, |
| 334 | }, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 335 | { |
| 336 | .name = "LDO1", |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 337 | .table_len = ARRAY_SIZE(TPS65020_LDO1_VSEL_table), |
| 338 | .table = TPS65020_LDO1_VSEL_table, |
| 339 | }, |
| 340 | { |
| 341 | .name = "LDO2", |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 342 | .table_len = ARRAY_SIZE(TPS65020_LDO2_VSEL_table), |
| 343 | .table = TPS65020_LDO2_VSEL_table, |
| 344 | }, |
| 345 | }; |
| 346 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 347 | static const struct tps_info tps65021_regs[] = { |
| 348 | { |
| 349 | .name = "VDCDC1", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 350 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
| 351 | .table = DCDC_FIXED_3300000_VSEL_table, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 352 | }, |
| 353 | { |
| 354 | .name = "VDCDC2", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 355 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
| 356 | .table = DCDC_FIXED_1800000_VSEL_table, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 357 | }, |
| 358 | { |
| 359 | .name = "VDCDC3", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 360 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 361 | .table = VCORE_VSEL_table, |
| 362 | }, |
| 363 | { |
| 364 | .name = "LDO1", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 365 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
| 366 | .table = TPS65023_LDO1_VSEL_table, |
| 367 | }, |
| 368 | { |
| 369 | .name = "LDO2", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 370 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
| 371 | .table = TPS65023_LDO2_VSEL_table, |
| 372 | }, |
| 373 | }; |
| 374 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 375 | static const struct tps_info tps65023_regs[] = { |
| 376 | { |
| 377 | .name = "VDCDC1", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 378 | .table_len = ARRAY_SIZE(VCORE_VSEL_table), |
| 379 | .table = VCORE_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 380 | }, |
| 381 | { |
| 382 | .name = "VDCDC2", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 383 | .table_len = ARRAY_SIZE(DCDC_FIXED_3300000_VSEL_table), |
| 384 | .table = DCDC_FIXED_3300000_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 385 | }, |
| 386 | { |
| 387 | .name = "VDCDC3", |
Axel Lin | ba3bd8a | 2012-06-19 17:12:18 +0800 | [diff] [blame] | 388 | .table_len = ARRAY_SIZE(DCDC_FIXED_1800000_VSEL_table), |
| 389 | .table = DCDC_FIXED_1800000_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 390 | }, |
| 391 | { |
| 392 | .name = "LDO1", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 393 | .table_len = ARRAY_SIZE(TPS65023_LDO1_VSEL_table), |
| 394 | .table = TPS65023_LDO1_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 395 | }, |
| 396 | { |
| 397 | .name = "LDO2", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 398 | .table_len = ARRAY_SIZE(TPS65023_LDO2_VSEL_table), |
| 399 | .table = TPS65023_LDO2_VSEL_table, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 400 | }, |
| 401 | }; |
| 402 | |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 403 | static struct tps_driver_data tps65020_drv_data = { |
| 404 | .info = tps65020_regs, |
| 405 | .core_regulator = TPS65023_DCDC_3, |
| 406 | }; |
| 407 | |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 408 | static struct tps_driver_data tps65021_drv_data = { |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 409 | .info = tps65021_regs, |
| 410 | .core_regulator = TPS65023_DCDC_3, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 411 | }; |
| 412 | |
| 413 | static struct tps_driver_data tps65023_drv_data = { |
Axel Lin | 7061873 | 2012-03-26 13:46:44 +0800 | [diff] [blame] | 414 | .info = tps65023_regs, |
| 415 | .core_regulator = TPS65023_DCDC_1, |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 416 | }; |
| 417 | |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 418 | static const struct i2c_device_id tps_65023_id[] = { |
| 419 | {.name = "tps65023", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 420 | .driver_data = (unsigned long) &tps65023_drv_data}, |
Marek Vasut | 1880a2fc | 2010-06-24 15:49:49 +0200 | [diff] [blame] | 421 | {.name = "tps65021", |
Marcus Folkesson | 1c3ede0 | 2011-08-08 20:29:34 +0200 | [diff] [blame] | 422 | .driver_data = (unsigned long) &tps65021_drv_data,}, |
Marcus Folkesson | 437afd2 | 2011-08-08 20:29:35 +0200 | [diff] [blame] | 423 | {.name = "tps65020", |
| 424 | .driver_data = (unsigned long) &tps65020_drv_data}, |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 425 | { }, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 426 | }; |
| 427 | |
| 428 | MODULE_DEVICE_TABLE(i2c, tps_65023_id); |
| 429 | |
| 430 | static struct i2c_driver tps_65023_i2c_driver = { |
| 431 | .driver = { |
| 432 | .name = "tps65023", |
| 433 | .owner = THIS_MODULE, |
| 434 | }, |
| 435 | .probe = tps_65023_probe, |
Bill Pemberton | 5eb9f2b | 2012-11-19 13:20:42 -0500 | [diff] [blame] | 436 | .remove = tps_65023_remove, |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 437 | .id_table = tps_65023_id, |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 438 | }; |
| 439 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 440 | static int __init tps_65023_init(void) |
| 441 | { |
| 442 | return i2c_add_driver(&tps_65023_i2c_driver); |
| 443 | } |
| 444 | subsys_initcall(tps_65023_init); |
| 445 | |
Anuj Aggarwal | 30e6599 | 2009-08-21 00:39:31 +0530 | [diff] [blame] | 446 | static void __exit tps_65023_cleanup(void) |
| 447 | { |
| 448 | i2c_del_driver(&tps_65023_i2c_driver); |
| 449 | } |
| 450 | module_exit(tps_65023_cleanup); |
| 451 | |
| 452 | MODULE_AUTHOR("Texas Instruments"); |
| 453 | MODULE_DESCRIPTION("TPS65023 voltage regulator driver"); |
Liam Girdwood | 9e108d3 | 2009-08-24 10:31:34 +0100 | [diff] [blame] | 454 | MODULE_LICENSE("GPL v2"); |