blob: 926c0e89a55a22f95f44ce096dc1e5790e1184eb [file] [log] [blame]
Laxman Dewangan62199292012-01-09 20:27:41 +05301/*
2 * tps62360.c -- TI tps62360
3 *
Axel Lind1cf4f62012-04-02 18:19:28 +08004 * Driver for processor core supply tps62360, tps62361B, tps62362 and tps62363.
Laxman Dewangan62199292012-01-09 20:27:41 +05305 *
6 * Copyright (c) 2012, NVIDIA Corporation.
7 *
8 * Author: Laxman Dewangan <ldewangan@nvidia.com>
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation version 2.
13 *
14 * This program is distributed "as is" WITHOUT ANY WARRANTY of any kind,
15 * whether express or implied; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 * 02111-1307, USA
23 */
24
25#include <linux/kernel.h>
26#include <linux/module.h>
27#include <linux/init.h>
28#include <linux/err.h>
Laxman Dewangan684ae392012-05-11 12:08:43 +053029#include <linux/of.h>
30#include <linux/of_device.h>
31#include <linux/of_gpio.h>
32#include <linux/regulator/of_regulator.h>
Laxman Dewangan62199292012-01-09 20:27:41 +053033#include <linux/platform_device.h>
34#include <linux/regulator/driver.h>
35#include <linux/regulator/machine.h>
36#include <linux/regulator/tps62360.h>
37#include <linux/gpio.h>
38#include <linux/i2c.h>
Laxman Dewangan62199292012-01-09 20:27:41 +053039#include <linux/slab.h>
40#include <linux/regmap.h>
41
42/* Register definitions */
43#define REG_VSET0 0
44#define REG_VSET1 1
45#define REG_VSET2 2
46#define REG_VSET3 3
47#define REG_CONTROL 4
48#define REG_TEMP 5
49#define REG_RAMPCTRL 6
50#define REG_CHIPID 8
51
Axel Lind1cf4f62012-04-02 18:19:28 +080052enum chips {TPS62360, TPS62361, TPS62362, TPS62363};
Laxman Dewangan62199292012-01-09 20:27:41 +053053
Laxman Dewangan2935fb12012-05-08 17:05:58 +053054#define TPS62360_BASE_VOLTAGE 770000
Laxman Dewangan62199292012-01-09 20:27:41 +053055#define TPS62360_N_VOLTAGES 64
56
Laxman Dewangan2935fb12012-05-08 17:05:58 +053057#define TPS62361_BASE_VOLTAGE 500000
Laxman Dewangan62199292012-01-09 20:27:41 +053058#define TPS62361_N_VOLTAGES 128
59
60/* tps 62360 chip information */
61struct tps62360_chip {
Laxman Dewangan62199292012-01-09 20:27:41 +053062 struct device *dev;
63 struct regulator_desc desc;
Laxman Dewangan62199292012-01-09 20:27:41 +053064 struct regulator_dev *rdev;
65 struct regmap *regmap;
66 int chip_id;
67 int vsel0_gpio;
68 int vsel1_gpio;
69 int voltage_base;
70 u8 voltage_reg_mask;
71 bool en_internal_pulldn;
72 bool en_force_pwm;
73 bool en_discharge;
74 bool valid_gpios;
75 int lru_index[4];
76 int curr_vset_vsel[4];
77 int curr_vset_id;
Laxman Dewangana60cfce2012-05-07 18:08:26 +053078 int change_uv_per_us;
Laxman Dewangan62199292012-01-09 20:27:41 +053079};
80
81/*
82 * find_voltage_set_register: Find new voltage configuration register
83 * (VSET) id.
84 * The finding of the new VSET register will be based on the LRU mechanism.
85 * Each VSET register will have different voltage configured . This
86 * Function will look if any of the VSET register have requested voltage set
87 * or not.
88 * - If it is already there then it will make that register as most
89 * recently used and return as found so that caller need not to set
90 * the VSET register but need to set the proper gpios to select this
91 * VSET register.
92 * - If requested voltage is not found then it will use the least
93 * recently mechanism to get new VSET register for new configuration
94 * and will return not_found so that caller need to set new VSET
95 * register and then gpios (both).
96 */
97static bool find_voltage_set_register(struct tps62360_chip *tps,
98 int req_vsel, int *vset_reg_id)
99{
100 int i;
101 bool found = false;
102 int new_vset_reg = tps->lru_index[3];
103 int found_index = 3;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530104
Laxman Dewangan62199292012-01-09 20:27:41 +0530105 for (i = 0; i < 4; ++i) {
106 if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
107 new_vset_reg = tps->lru_index[i];
108 found_index = i;
109 found = true;
110 goto update_lru_index;
111 }
112 }
113
114update_lru_index:
115 for (i = found_index; i > 0; i--)
116 tps->lru_index[i] = tps->lru_index[i - 1];
117
118 tps->lru_index[0] = new_vset_reg;
119 *vset_reg_id = new_vset_reg;
120 return found;
121}
122
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530123static int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev)
Laxman Dewangan62199292012-01-09 20:27:41 +0530124{
125 struct tps62360_chip *tps = rdev_get_drvdata(dev);
126 int vsel;
127 unsigned int data;
128 int ret;
129
130 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
131 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530132 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
133 __func__, REG_VSET0 + tps->curr_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530134 return ret;
135 }
136 vsel = (int)data & tps->voltage_reg_mask;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530137 return vsel;
Laxman Dewangan62199292012-01-09 20:27:41 +0530138}
139
Axel Lin41097af2012-05-14 11:27:25 +0800140static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
141 unsigned selector)
Laxman Dewangan62199292012-01-09 20:27:41 +0530142{
143 struct tps62360_chip *tps = rdev_get_drvdata(dev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530144 int ret;
145 bool found = false;
146 int new_vset_id = tps->curr_vset_id;
147
Laxman Dewangan62199292012-01-09 20:27:41 +0530148 /*
149 * If gpios are available to select the VSET register then least
150 * recently used register for new configuration.
151 */
152 if (tps->valid_gpios)
Axel Lin41097af2012-05-14 11:27:25 +0800153 found = find_voltage_set_register(tps, selector, &new_vset_id);
Laxman Dewangan62199292012-01-09 20:27:41 +0530154
155 if (!found) {
156 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
Axel Lin41097af2012-05-14 11:27:25 +0800157 tps->voltage_reg_mask, selector);
Laxman Dewangan62199292012-01-09 20:27:41 +0530158 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530159 dev_err(tps->dev,
160 "%s(): register %d update failed with err %d\n",
161 __func__, REG_VSET0 + new_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530162 return ret;
163 }
164 tps->curr_vset_id = new_vset_id;
Axel Lin41097af2012-05-14 11:27:25 +0800165 tps->curr_vset_vsel[new_vset_id] = selector;
Laxman Dewangan62199292012-01-09 20:27:41 +0530166 }
167
168 /* Select proper VSET register vio gpios */
169 if (tps->valid_gpios) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530170 gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
Laxman Dewangan62199292012-01-09 20:27:41 +0530171 gpio_set_value_cansleep(tps->vsel1_gpio,
172 (new_vset_id >> 1) & 0x1);
173 }
174 return 0;
175}
176
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530177static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
178 unsigned int old_selector, unsigned int new_selector)
179{
180 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
181 int old_uV, new_uV;
182
Axel Lin7f225ba2012-05-14 11:25:42 +0800183 old_uV = regulator_list_voltage_linear(rdev, old_selector);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530184 if (old_uV < 0)
185 return old_uV;
186
Axel Lin7f225ba2012-05-14 11:25:42 +0800187 new_uV = regulator_list_voltage_linear(rdev, new_selector);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530188 if (new_uV < 0)
189 return new_uV;
190
191 return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us);
192}
193
Laxman Dewangan62199292012-01-09 20:27:41 +0530194static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530195 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
Axel Lin41097af2012-05-14 11:27:25 +0800196 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
Axel Lin7f225ba2012-05-14 11:25:42 +0800197 .list_voltage = regulator_list_voltage_linear,
Axel Lin41097af2012-05-14 11:27:25 +0800198 .map_voltage = regulator_map_voltage_linear,
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530199 .set_voltage_time_sel = tps62360_set_voltage_time_sel,
Laxman Dewangan62199292012-01-09 20:27:41 +0530200};
201
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530202static int __devinit tps62360_init_force_pwm(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530203 struct tps62360_regulator_platform_data *pdata,
204 int vset_id)
205{
Laxman Dewangan62199292012-01-09 20:27:41 +0530206 int ret;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530207 int bit = 0;
208
Laxman Dewangan62199292012-01-09 20:27:41 +0530209 if (pdata->en_force_pwm)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530210 bit = BIT(7);
211
212 ret = regmap_update_bits(tps->regmap, REG_VSET0 + vset_id, BIT(7), bit);
Laxman Dewangan62199292012-01-09 20:27:41 +0530213 if (ret < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530214 dev_err(tps->dev,
215 "%s(): register %d update failed with err %d\n",
216 __func__, REG_VSET0 + vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530217 return ret;
218}
219
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530220static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530221 struct tps62360_regulator_platform_data *pdata)
222{
223 int ret;
224 int i;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530225 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530226
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530227 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530228 if (tps->en_internal_pulldn)
229 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
230 else
231 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
232 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530233 dev_err(tps->dev,
234 "%s(): register %d write failed with err %d\n",
235 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530236 return ret;
237 }
238
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530239 /* Initialize force PWM mode */
Laxman Dewangan62199292012-01-09 20:27:41 +0530240 if (tps->valid_gpios) {
241 for (i = 0; i < 4; ++i) {
242 ret = tps62360_init_force_pwm(tps, pdata, i);
243 if (ret < 0)
244 return ret;
245 }
246 } else {
247 ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id);
248 if (ret < 0)
249 return ret;
250 }
251
252 /* Reset output discharge path to reduce power consumption */
253 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530254 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530255 dev_err(tps->dev,
256 "%s(): register %d update failed with err %d\n",
257 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530258 return ret;
259 }
260
261 /* Get ramp value from ramp control register */
262 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
263 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530264 dev_err(tps->dev,
265 "%s(): register %d read failed with err %d\n",
266 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530267 return ret;
268 }
269 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
270
271 /* ramp mV/us = 32/(2^ramp_ctrl) */
272 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530273 return ret;
274}
275
276static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530277 .reg_bits = 8,
278 .val_bits = 8,
279 .max_register = REG_CHIPID,
280 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530281};
282
Laxman Dewangan684ae392012-05-11 12:08:43 +0530283static struct tps62360_regulator_platform_data *
284 of_get_tps62360_platform_data(struct device *dev)
285{
286 struct tps62360_regulator_platform_data *pdata;
287 struct device_node *np = dev->of_node;
288
289 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
290 if (!pdata) {
291 dev_err(dev, "Memory alloc failed for platform data\n");
292 return NULL;
293 }
294
295 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
296 if (!pdata->reg_init_data) {
297 dev_err(dev, "Not able to get OF regulator init data\n");
298 return NULL;
299 }
300
301 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
302 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
303
304 if (of_find_property(np, "ti,vsel0-state-high", NULL))
305 pdata->vsel0_def_state = 1;
306
307 if (of_find_property(np, "ti,vsel1-state-high", NULL))
308 pdata->vsel1_def_state = 1;
309
310 if (of_find_property(np, "ti,enable-pull-down", NULL))
311 pdata->en_internal_pulldn = true;
312
313 if (of_find_property(np, "ti,enable-force-pwm", NULL))
314 pdata->en_force_pwm = true;
315
316 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
317 pdata->en_discharge = true;
318
319 return pdata;
320}
321
322#if defined(CONFIG_OF)
323static const struct of_device_id tps62360_of_match[] = {
324 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
325 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
326 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
327 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
328 {},
329}
330MODULE_DEVICE_TABLE(of, tps62360_of_match);
331#endif
332
Laxman Dewangan62199292012-01-09 20:27:41 +0530333static int __devinit tps62360_probe(struct i2c_client *client,
334 const struct i2c_device_id *id)
335{
Mark Brownc1727082012-04-04 00:50:22 +0100336 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530337 struct tps62360_regulator_platform_data *pdata;
338 struct regulator_dev *rdev;
339 struct tps62360_chip *tps;
340 int ret;
341 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530342 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530343
344 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530345 chip_id = id->driver_data;
346
347 if (client->dev.of_node) {
348 const struct of_device_id *match;
349 match = of_match_device(of_match_ptr(tps62360_of_match),
350 &client->dev);
351 if (!match) {
352 dev_err(&client->dev, "Error: No device match found\n");
353 return -ENODEV;
354 }
355 chip_id = (int)match->data;
356 if (!pdata)
357 pdata = of_get_tps62360_platform_data(&client->dev);
358 }
359
Laxman Dewangan62199292012-01-09 20:27:41 +0530360 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530361 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530362 __func__);
363 return -EIO;
364 }
365
366 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
367 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530368 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530369 __func__);
370 return -ENOMEM;
371 }
372
373 tps->en_force_pwm = pdata->en_force_pwm;
374 tps->en_discharge = pdata->en_discharge;
375 tps->en_internal_pulldn = pdata->en_internal_pulldn;
376 tps->vsel0_gpio = pdata->vsel0_gpio;
377 tps->vsel1_gpio = pdata->vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +0530378 tps->dev = &client->dev;
Axel Lind1cf4f62012-04-02 18:19:28 +0800379
Laxman Dewangan684ae392012-05-11 12:08:43 +0530380 switch (chip_id) {
Axel Lind1cf4f62012-04-02 18:19:28 +0800381 case TPS62360:
382 case TPS62362:
383 tps->voltage_base = TPS62360_BASE_VOLTAGE;
384 tps->voltage_reg_mask = 0x3F;
385 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
386 break;
387 case TPS62361:
388 case TPS62363:
389 tps->voltage_base = TPS62361_BASE_VOLTAGE;
390 tps->voltage_reg_mask = 0x7F;
391 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
392 break;
393 default:
394 return -ENODEV;
395 }
Laxman Dewangan62199292012-01-09 20:27:41 +0530396
397 tps->desc.name = id->name;
398 tps->desc.id = 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530399 tps->desc.ops = &tps62360_dcdc_ops;
400 tps->desc.type = REGULATOR_VOLTAGE;
401 tps->desc.owner = THIS_MODULE;
Axel Lin7f225ba2012-05-14 11:25:42 +0800402 tps->desc.min_uV = tps->voltage_base;
403 tps->desc.uV_step = 10000;
404
Axel Lin9a4bdd82012-04-07 23:29:56 +0800405 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530406 if (IS_ERR(tps->regmap)) {
407 ret = PTR_ERR(tps->regmap);
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530408 dev_err(&client->dev,
409 "%s(): regmap allocation failed with err %d\n",
410 __func__, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530411 return ret;
412 }
413 i2c_set_clientdata(client, tps);
414
415 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
416 (pdata->vsel0_def_state & 1);
417 tps->lru_index[0] = tps->curr_vset_id;
418 tps->valid_gpios = false;
419
420 if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530421 int gpio_flags;
422 gpio_flags = (pdata->vsel0_def_state) ?
423 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
424 ret = gpio_request_one(tps->vsel0_gpio,
425 gpio_flags, "tps62360-vsel0");
Laxman Dewangan62199292012-01-09 20:27:41 +0530426 if (ret) {
427 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530428 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
429 __func__, tps->vsel0_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530430 goto err_gpio0;
431 }
432
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530433 gpio_flags = (pdata->vsel1_def_state) ?
434 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
435 ret = gpio_request_one(tps->vsel1_gpio,
436 gpio_flags, "tps62360-vsel1");
Laxman Dewangan62199292012-01-09 20:27:41 +0530437 if (ret) {
438 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530439 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
440 __func__, tps->vsel1_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530441 goto err_gpio1;
442 }
443 tps->valid_gpios = true;
444
445 /*
446 * Initialize the lru index with vset_reg id
447 * The index 0 will be most recently used and
448 * set with the tps->curr_vset_id */
449 for (i = 0; i < 4; ++i)
450 tps->lru_index[i] = i;
451 tps->lru_index[0] = tps->curr_vset_id;
452 tps->lru_index[tps->curr_vset_id] = 0;
453 }
454
455 ret = tps62360_init_dcdc(tps, pdata);
456 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530457 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530458 __func__, ret);
459 goto err_init;
460 }
461
Mark Brownc1727082012-04-04 00:50:22 +0100462 config.dev = &client->dev;
Laxman Dewangan8bdca0092012-05-11 12:08:42 +0530463 config.init_data = pdata->reg_init_data;
Mark Brownc1727082012-04-04 00:50:22 +0100464 config.driver_data = tps;
465
Laxman Dewangan62199292012-01-09 20:27:41 +0530466 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100467 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530468 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530469 dev_err(tps->dev,
470 "%s(): regulator register failed with err %s\n",
471 __func__, id->name);
Laxman Dewangan62199292012-01-09 20:27:41 +0530472 ret = PTR_ERR(rdev);
473 goto err_init;
474 }
475
476 tps->rdev = rdev;
477 return 0;
478
479err_init:
480 if (gpio_is_valid(tps->vsel1_gpio))
481 gpio_free(tps->vsel1_gpio);
482err_gpio1:
483 if (gpio_is_valid(tps->vsel0_gpio))
484 gpio_free(tps->vsel0_gpio);
485err_gpio0:
Laxman Dewangan62199292012-01-09 20:27:41 +0530486 return ret;
487}
488
489/**
490 * tps62360_remove - tps62360 driver i2c remove handler
491 * @client: i2c driver client device structure
492 *
493 * Unregister TPS driver as an i2c client device driver
494 */
495static int __devexit tps62360_remove(struct i2c_client *client)
496{
497 struct tps62360_chip *tps = i2c_get_clientdata(client);
498
499 if (gpio_is_valid(tps->vsel1_gpio))
500 gpio_free(tps->vsel1_gpio);
501
502 if (gpio_is_valid(tps->vsel0_gpio))
503 gpio_free(tps->vsel0_gpio);
504
505 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530506 return 0;
507}
508
509static void tps62360_shutdown(struct i2c_client *client)
510{
511 struct tps62360_chip *tps = i2c_get_clientdata(client);
512 int st;
513
514 if (!tps->en_discharge)
515 return;
516
517 /* Configure the output discharge path */
518 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
519 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530520 dev_err(tps->dev,
521 "%s(): register %d update failed with err %d\n",
522 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530523}
524
525static const struct i2c_device_id tps62360_id[] = {
526 {.name = "tps62360", .driver_data = TPS62360},
527 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800528 {.name = "tps62362", .driver_data = TPS62362},
529 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530530 {},
531};
532
533MODULE_DEVICE_TABLE(i2c, tps62360_id);
534
535static struct i2c_driver tps62360_i2c_driver = {
536 .driver = {
537 .name = "tps62360",
538 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530539 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530540 },
541 .probe = tps62360_probe,
542 .remove = __devexit_p(tps62360_remove),
543 .shutdown = tps62360_shutdown,
544 .id_table = tps62360_id,
545};
546
547static int __init tps62360_init(void)
548{
549 return i2c_add_driver(&tps62360_i2c_driver);
550}
551subsys_initcall(tps62360_init);
552
553static void __exit tps62360_cleanup(void)
554{
555 i2c_del_driver(&tps62360_i2c_driver);
556}
557module_exit(tps62360_cleanup);
558
559MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800560MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530561MODULE_LICENSE("GPL v2");