blob: d044a58640e7ddb8280514cafd998fcfa6ea4153 [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
Laxman Dewangan9a006302012-05-14 17:46:51 +053052#define FORCE_PWM_ENABLE BIT(7)
53
Axel Lind1cf4f62012-04-02 18:19:28 +080054enum chips {TPS62360, TPS62361, TPS62362, TPS62363};
Laxman Dewangan62199292012-01-09 20:27:41 +053055
Laxman Dewangan2935fb12012-05-08 17:05:58 +053056#define TPS62360_BASE_VOLTAGE 770000
Laxman Dewangan62199292012-01-09 20:27:41 +053057#define TPS62360_N_VOLTAGES 64
58
Laxman Dewangan2935fb12012-05-08 17:05:58 +053059#define TPS62361_BASE_VOLTAGE 500000
Laxman Dewangan62199292012-01-09 20:27:41 +053060#define TPS62361_N_VOLTAGES 128
61
62/* tps 62360 chip information */
63struct tps62360_chip {
Laxman Dewangan62199292012-01-09 20:27:41 +053064 struct device *dev;
65 struct regulator_desc desc;
Laxman Dewangan62199292012-01-09 20:27:41 +053066 struct regulator_dev *rdev;
67 struct regmap *regmap;
68 int chip_id;
69 int vsel0_gpio;
70 int vsel1_gpio;
71 int voltage_base;
72 u8 voltage_reg_mask;
73 bool en_internal_pulldn;
Laxman Dewangan62199292012-01-09 20:27:41 +053074 bool en_discharge;
75 bool valid_gpios;
76 int lru_index[4];
77 int curr_vset_vsel[4];
78 int curr_vset_id;
Laxman Dewangana60cfce2012-05-07 18:08:26 +053079 int change_uv_per_us;
Laxman Dewangan62199292012-01-09 20:27:41 +053080};
81
82/*
83 * find_voltage_set_register: Find new voltage configuration register
84 * (VSET) id.
85 * The finding of the new VSET register will be based on the LRU mechanism.
86 * Each VSET register will have different voltage configured . This
87 * Function will look if any of the VSET register have requested voltage set
88 * or not.
89 * - If it is already there then it will make that register as most
90 * recently used and return as found so that caller need not to set
91 * the VSET register but need to set the proper gpios to select this
92 * VSET register.
93 * - If requested voltage is not found then it will use the least
94 * recently mechanism to get new VSET register for new configuration
95 * and will return not_found so that caller need to set new VSET
96 * register and then gpios (both).
97 */
98static bool find_voltage_set_register(struct tps62360_chip *tps,
99 int req_vsel, int *vset_reg_id)
100{
101 int i;
102 bool found = false;
103 int new_vset_reg = tps->lru_index[3];
104 int found_index = 3;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530105
Laxman Dewangan62199292012-01-09 20:27:41 +0530106 for (i = 0; i < 4; ++i) {
107 if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
108 new_vset_reg = tps->lru_index[i];
109 found_index = i;
110 found = true;
111 goto update_lru_index;
112 }
113 }
114
115update_lru_index:
116 for (i = found_index; i > 0; i--)
117 tps->lru_index[i] = tps->lru_index[i - 1];
118
119 tps->lru_index[0] = new_vset_reg;
120 *vset_reg_id = new_vset_reg;
121 return found;
122}
123
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530124static int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev)
Laxman Dewangan62199292012-01-09 20:27:41 +0530125{
126 struct tps62360_chip *tps = rdev_get_drvdata(dev);
127 int vsel;
128 unsigned int data;
129 int ret;
130
131 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
132 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530133 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
134 __func__, REG_VSET0 + tps->curr_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530135 return ret;
136 }
137 vsel = (int)data & tps->voltage_reg_mask;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530138 return vsel;
Laxman Dewangan62199292012-01-09 20:27:41 +0530139}
140
Axel Lin41097af2012-05-14 11:27:25 +0800141static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
142 unsigned selector)
Laxman Dewangan62199292012-01-09 20:27:41 +0530143{
144 struct tps62360_chip *tps = rdev_get_drvdata(dev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530145 int ret;
146 bool found = false;
147 int new_vset_id = tps->curr_vset_id;
148
Laxman Dewangan62199292012-01-09 20:27:41 +0530149 /*
150 * If gpios are available to select the VSET register then least
151 * recently used register for new configuration.
152 */
153 if (tps->valid_gpios)
Axel Lin41097af2012-05-14 11:27:25 +0800154 found = find_voltage_set_register(tps, selector, &new_vset_id);
Laxman Dewangan62199292012-01-09 20:27:41 +0530155
156 if (!found) {
157 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
Axel Lin41097af2012-05-14 11:27:25 +0800158 tps->voltage_reg_mask, selector);
Laxman Dewangan62199292012-01-09 20:27:41 +0530159 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530160 dev_err(tps->dev,
161 "%s(): register %d update failed with err %d\n",
162 __func__, REG_VSET0 + new_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530163 return ret;
164 }
165 tps->curr_vset_id = new_vset_id;
Axel Lin41097af2012-05-14 11:27:25 +0800166 tps->curr_vset_vsel[new_vset_id] = selector;
Laxman Dewangan62199292012-01-09 20:27:41 +0530167 }
168
169 /* Select proper VSET register vio gpios */
170 if (tps->valid_gpios) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530171 gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
Laxman Dewangan62199292012-01-09 20:27:41 +0530172 gpio_set_value_cansleep(tps->vsel1_gpio,
173 (new_vset_id >> 1) & 0x1);
174 }
175 return 0;
176}
177
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530178static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
179 unsigned int old_selector, unsigned int new_selector)
180{
181 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530182
Axel Line08ef732012-06-08 14:35:32 +0800183 return DIV_ROUND_UP(abs(new_selector - old_selector) *
184 rdev->desc->uV_step,
185 tps->change_uv_per_us);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530186}
187
Laxman Dewangan9a006302012-05-14 17:46:51 +0530188static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
189{
190 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
191 int i;
192 int val;
193 int ret;
194
195 /* Enable force PWM mode in FAST mode only. */
196 switch (mode) {
197 case REGULATOR_MODE_FAST:
198 val = FORCE_PWM_ENABLE;
199 break;
200
201 case REGULATOR_MODE_NORMAL:
202 val = 0;
203 break;
204
205 default:
206 return -EINVAL;
207 }
208
209 if (!tps->valid_gpios) {
210 ret = regmap_update_bits(tps->regmap,
211 REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val);
212 if (ret < 0)
213 dev_err(tps->dev,
214 "%s(): register %d update failed with err %d\n",
215 __func__, REG_VSET0 + tps->curr_vset_id, ret);
216 return ret;
217 }
218
219 /* If gpios are valid then all register set need to be control */
220 for (i = 0; i < 4; ++i) {
221 ret = regmap_update_bits(tps->regmap,
222 REG_VSET0 + i, FORCE_PWM_ENABLE, val);
223 if (ret < 0) {
224 dev_err(tps->dev,
225 "%s(): register %d update failed with err %d\n",
226 __func__, REG_VSET0 + i, ret);
227 return ret;
228 }
229 }
230 return ret;
231}
232
233static unsigned int tps62360_get_mode(struct regulator_dev *rdev)
234{
235 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
236 unsigned int data;
237 int ret;
238
239 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
240 if (ret < 0) {
241 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
242 __func__, REG_VSET0 + tps->curr_vset_id, ret);
243 return ret;
244 }
245 return (data & FORCE_PWM_ENABLE) ?
246 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
247}
248
Laxman Dewangan62199292012-01-09 20:27:41 +0530249static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530250 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
Axel Lin41097af2012-05-14 11:27:25 +0800251 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
Axel Lin7f225ba2012-05-14 11:25:42 +0800252 .list_voltage = regulator_list_voltage_linear,
Axel Lin41097af2012-05-14 11:27:25 +0800253 .map_voltage = regulator_map_voltage_linear,
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530254 .set_voltage_time_sel = tps62360_set_voltage_time_sel,
Laxman Dewangan9a006302012-05-14 17:46:51 +0530255 .set_mode = tps62360_set_mode,
256 .get_mode = tps62360_get_mode,
Laxman Dewangan62199292012-01-09 20:27:41 +0530257};
258
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530259static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530260 struct tps62360_regulator_platform_data *pdata)
261{
262 int ret;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530263 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530264
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530265 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530266 if (tps->en_internal_pulldn)
267 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
268 else
269 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
270 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530271 dev_err(tps->dev,
272 "%s(): register %d write failed with err %d\n",
273 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530274 return ret;
275 }
276
Laxman Dewangan62199292012-01-09 20:27:41 +0530277 /* Reset output discharge path to reduce power consumption */
278 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530279 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530280 dev_err(tps->dev,
281 "%s(): register %d update failed with err %d\n",
282 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530283 return ret;
284 }
285
286 /* Get ramp value from ramp control register */
287 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
288 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530289 dev_err(tps->dev,
290 "%s(): register %d read failed with err %d\n",
291 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530292 return ret;
293 }
294 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
295
296 /* ramp mV/us = 32/(2^ramp_ctrl) */
297 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530298 return ret;
299}
300
301static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530302 .reg_bits = 8,
303 .val_bits = 8,
304 .max_register = REG_CHIPID,
305 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530306};
307
Laxman Dewangan684ae392012-05-11 12:08:43 +0530308static struct tps62360_regulator_platform_data *
309 of_get_tps62360_platform_data(struct device *dev)
310{
311 struct tps62360_regulator_platform_data *pdata;
312 struct device_node *np = dev->of_node;
313
314 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
315 if (!pdata) {
316 dev_err(dev, "Memory alloc failed for platform data\n");
317 return NULL;
318 }
319
320 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
321 if (!pdata->reg_init_data) {
322 dev_err(dev, "Not able to get OF regulator init data\n");
323 return NULL;
324 }
325
326 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
327 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
328
329 if (of_find_property(np, "ti,vsel0-state-high", NULL))
330 pdata->vsel0_def_state = 1;
331
332 if (of_find_property(np, "ti,vsel1-state-high", NULL))
333 pdata->vsel1_def_state = 1;
334
335 if (of_find_property(np, "ti,enable-pull-down", NULL))
336 pdata->en_internal_pulldn = true;
337
Laxman Dewangan684ae392012-05-11 12:08:43 +0530338 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
339 pdata->en_discharge = true;
340
341 return pdata;
342}
343
344#if defined(CONFIG_OF)
345static const struct of_device_id tps62360_of_match[] = {
346 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
347 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
348 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
349 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
350 {},
Axel Linbe154112012-05-14 23:58:08 +0800351};
Laxman Dewangan684ae392012-05-11 12:08:43 +0530352MODULE_DEVICE_TABLE(of, tps62360_of_match);
353#endif
354
Laxman Dewangan62199292012-01-09 20:27:41 +0530355static int __devinit tps62360_probe(struct i2c_client *client,
356 const struct i2c_device_id *id)
357{
Mark Brownc1727082012-04-04 00:50:22 +0100358 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530359 struct tps62360_regulator_platform_data *pdata;
360 struct regulator_dev *rdev;
361 struct tps62360_chip *tps;
362 int ret;
363 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530364 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530365
366 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530367 chip_id = id->driver_data;
368
369 if (client->dev.of_node) {
370 const struct of_device_id *match;
371 match = of_match_device(of_match_ptr(tps62360_of_match),
372 &client->dev);
373 if (!match) {
374 dev_err(&client->dev, "Error: No device match found\n");
375 return -ENODEV;
376 }
377 chip_id = (int)match->data;
378 if (!pdata)
379 pdata = of_get_tps62360_platform_data(&client->dev);
380 }
381
Laxman Dewangan62199292012-01-09 20:27:41 +0530382 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530383 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530384 __func__);
385 return -EIO;
386 }
387
388 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
389 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530390 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530391 __func__);
392 return -ENOMEM;
393 }
394
Laxman Dewangan62199292012-01-09 20:27:41 +0530395 tps->en_discharge = pdata->en_discharge;
396 tps->en_internal_pulldn = pdata->en_internal_pulldn;
397 tps->vsel0_gpio = pdata->vsel0_gpio;
398 tps->vsel1_gpio = pdata->vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +0530399 tps->dev = &client->dev;
Axel Lind1cf4f62012-04-02 18:19:28 +0800400
Laxman Dewangan684ae392012-05-11 12:08:43 +0530401 switch (chip_id) {
Axel Lind1cf4f62012-04-02 18:19:28 +0800402 case TPS62360:
403 case TPS62362:
404 tps->voltage_base = TPS62360_BASE_VOLTAGE;
405 tps->voltage_reg_mask = 0x3F;
406 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
407 break;
408 case TPS62361:
409 case TPS62363:
410 tps->voltage_base = TPS62361_BASE_VOLTAGE;
411 tps->voltage_reg_mask = 0x7F;
412 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
413 break;
414 default:
415 return -ENODEV;
416 }
Laxman Dewangan62199292012-01-09 20:27:41 +0530417
418 tps->desc.name = id->name;
419 tps->desc.id = 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530420 tps->desc.ops = &tps62360_dcdc_ops;
421 tps->desc.type = REGULATOR_VOLTAGE;
422 tps->desc.owner = THIS_MODULE;
Axel Lin7f225ba2012-05-14 11:25:42 +0800423 tps->desc.min_uV = tps->voltage_base;
424 tps->desc.uV_step = 10000;
425
Axel Lin9a4bdd82012-04-07 23:29:56 +0800426 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530427 if (IS_ERR(tps->regmap)) {
428 ret = PTR_ERR(tps->regmap);
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530429 dev_err(&client->dev,
430 "%s(): regmap allocation failed with err %d\n",
431 __func__, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530432 return ret;
433 }
434 i2c_set_clientdata(client, tps);
435
436 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
437 (pdata->vsel0_def_state & 1);
438 tps->lru_index[0] = tps->curr_vset_id;
439 tps->valid_gpios = false;
440
441 if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530442 int gpio_flags;
443 gpio_flags = (pdata->vsel0_def_state) ?
444 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
445 ret = gpio_request_one(tps->vsel0_gpio,
446 gpio_flags, "tps62360-vsel0");
Laxman Dewangan62199292012-01-09 20:27:41 +0530447 if (ret) {
448 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530449 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
450 __func__, tps->vsel0_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530451 goto err_gpio0;
452 }
453
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530454 gpio_flags = (pdata->vsel1_def_state) ?
455 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
456 ret = gpio_request_one(tps->vsel1_gpio,
457 gpio_flags, "tps62360-vsel1");
Laxman Dewangan62199292012-01-09 20:27:41 +0530458 if (ret) {
459 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530460 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
461 __func__, tps->vsel1_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530462 goto err_gpio1;
463 }
464 tps->valid_gpios = true;
465
466 /*
467 * Initialize the lru index with vset_reg id
468 * The index 0 will be most recently used and
469 * set with the tps->curr_vset_id */
470 for (i = 0; i < 4; ++i)
471 tps->lru_index[i] = i;
472 tps->lru_index[0] = tps->curr_vset_id;
473 tps->lru_index[tps->curr_vset_id] = 0;
474 }
475
476 ret = tps62360_init_dcdc(tps, pdata);
477 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530478 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530479 __func__, ret);
480 goto err_init;
481 }
482
Mark Brownc1727082012-04-04 00:50:22 +0100483 config.dev = &client->dev;
Laxman Dewangan8bdca0092012-05-11 12:08:42 +0530484 config.init_data = pdata->reg_init_data;
Mark Brownc1727082012-04-04 00:50:22 +0100485 config.driver_data = tps;
Laxman Dewangan9fc38152012-05-20 21:48:47 +0530486 config.of_node = client->dev.of_node;
Mark Brownc1727082012-04-04 00:50:22 +0100487
Laxman Dewangan62199292012-01-09 20:27:41 +0530488 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100489 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530490 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530491 dev_err(tps->dev,
492 "%s(): regulator register failed with err %s\n",
493 __func__, id->name);
Laxman Dewangan62199292012-01-09 20:27:41 +0530494 ret = PTR_ERR(rdev);
495 goto err_init;
496 }
497
498 tps->rdev = rdev;
499 return 0;
500
501err_init:
502 if (gpio_is_valid(tps->vsel1_gpio))
503 gpio_free(tps->vsel1_gpio);
504err_gpio1:
505 if (gpio_is_valid(tps->vsel0_gpio))
506 gpio_free(tps->vsel0_gpio);
507err_gpio0:
Laxman Dewangan62199292012-01-09 20:27:41 +0530508 return ret;
509}
510
511/**
512 * tps62360_remove - tps62360 driver i2c remove handler
513 * @client: i2c driver client device structure
514 *
515 * Unregister TPS driver as an i2c client device driver
516 */
517static int __devexit tps62360_remove(struct i2c_client *client)
518{
519 struct tps62360_chip *tps = i2c_get_clientdata(client);
520
521 if (gpio_is_valid(tps->vsel1_gpio))
522 gpio_free(tps->vsel1_gpio);
523
524 if (gpio_is_valid(tps->vsel0_gpio))
525 gpio_free(tps->vsel0_gpio);
526
527 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530528 return 0;
529}
530
531static void tps62360_shutdown(struct i2c_client *client)
532{
533 struct tps62360_chip *tps = i2c_get_clientdata(client);
534 int st;
535
536 if (!tps->en_discharge)
537 return;
538
539 /* Configure the output discharge path */
540 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
541 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530542 dev_err(tps->dev,
543 "%s(): register %d update failed with err %d\n",
544 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530545}
546
547static const struct i2c_device_id tps62360_id[] = {
548 {.name = "tps62360", .driver_data = TPS62360},
549 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800550 {.name = "tps62362", .driver_data = TPS62362},
551 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530552 {},
553};
554
555MODULE_DEVICE_TABLE(i2c, tps62360_id);
556
557static struct i2c_driver tps62360_i2c_driver = {
558 .driver = {
559 .name = "tps62360",
560 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530561 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530562 },
563 .probe = tps62360_probe,
564 .remove = __devexit_p(tps62360_remove),
565 .shutdown = tps62360_shutdown,
566 .id_table = tps62360_id,
567};
568
569static int __init tps62360_init(void)
570{
571 return i2c_add_driver(&tps62360_i2c_driver);
572}
573subsys_initcall(tps62360_init);
574
575static void __exit tps62360_cleanup(void)
576{
577 i2c_del_driver(&tps62360_i2c_driver);
578}
579module_exit(tps62360_cleanup);
580
581MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800582MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530583MODULE_LICENSE("GPL v2");