blob: bcea4e1eea1e1aeb43724556241165f19186ad64 [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;
Laxman Dewangan62199292012-01-09 20:27:41 +053068 int vsel0_gpio;
69 int vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +053070 u8 voltage_reg_mask;
71 bool en_internal_pulldn;
Laxman Dewangan62199292012-01-09 20:27:41 +053072 bool en_discharge;
73 bool valid_gpios;
74 int lru_index[4];
75 int curr_vset_vsel[4];
76 int curr_vset_id;
Laxman Dewangana60cfce2012-05-07 18:08:26 +053077 int change_uv_per_us;
Laxman Dewangan62199292012-01-09 20:27:41 +053078};
79
80/*
81 * find_voltage_set_register: Find new voltage configuration register
82 * (VSET) id.
83 * The finding of the new VSET register will be based on the LRU mechanism.
84 * Each VSET register will have different voltage configured . This
85 * Function will look if any of the VSET register have requested voltage set
86 * or not.
87 * - If it is already there then it will make that register as most
88 * recently used and return as found so that caller need not to set
89 * the VSET register but need to set the proper gpios to select this
90 * VSET register.
91 * - If requested voltage is not found then it will use the least
92 * recently mechanism to get new VSET register for new configuration
93 * and will return not_found so that caller need to set new VSET
94 * register and then gpios (both).
95 */
96static bool find_voltage_set_register(struct tps62360_chip *tps,
97 int req_vsel, int *vset_reg_id)
98{
99 int i;
100 bool found = false;
101 int new_vset_reg = tps->lru_index[3];
102 int found_index = 3;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530103
Laxman Dewangan62199292012-01-09 20:27:41 +0530104 for (i = 0; i < 4; ++i) {
105 if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
106 new_vset_reg = tps->lru_index[i];
107 found_index = i;
108 found = true;
109 goto update_lru_index;
110 }
111 }
112
113update_lru_index:
114 for (i = found_index; i > 0; i--)
115 tps->lru_index[i] = tps->lru_index[i - 1];
116
117 tps->lru_index[0] = new_vset_reg;
118 *vset_reg_id = new_vset_reg;
119 return found;
120}
121
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530122static int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev)
Laxman Dewangan62199292012-01-09 20:27:41 +0530123{
124 struct tps62360_chip *tps = rdev_get_drvdata(dev);
125 int vsel;
126 unsigned int data;
127 int ret;
128
129 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
130 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530131 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
132 __func__, REG_VSET0 + tps->curr_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530133 return ret;
134 }
135 vsel = (int)data & tps->voltage_reg_mask;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530136 return vsel;
Laxman Dewangan62199292012-01-09 20:27:41 +0530137}
138
Axel Lin41097af2012-05-14 11:27:25 +0800139static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
140 unsigned selector)
Laxman Dewangan62199292012-01-09 20:27:41 +0530141{
142 struct tps62360_chip *tps = rdev_get_drvdata(dev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530143 int ret;
144 bool found = false;
145 int new_vset_id = tps->curr_vset_id;
146
Laxman Dewangan62199292012-01-09 20:27:41 +0530147 /*
148 * If gpios are available to select the VSET register then least
149 * recently used register for new configuration.
150 */
151 if (tps->valid_gpios)
Axel Lin41097af2012-05-14 11:27:25 +0800152 found = find_voltage_set_register(tps, selector, &new_vset_id);
Laxman Dewangan62199292012-01-09 20:27:41 +0530153
154 if (!found) {
155 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
Axel Lin41097af2012-05-14 11:27:25 +0800156 tps->voltage_reg_mask, selector);
Laxman Dewangan62199292012-01-09 20:27:41 +0530157 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530158 dev_err(tps->dev,
159 "%s(): register %d update failed with err %d\n",
160 __func__, REG_VSET0 + new_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530161 return ret;
162 }
163 tps->curr_vset_id = new_vset_id;
Axel Lin41097af2012-05-14 11:27:25 +0800164 tps->curr_vset_vsel[new_vset_id] = selector;
Laxman Dewangan62199292012-01-09 20:27:41 +0530165 }
166
167 /* Select proper VSET register vio gpios */
168 if (tps->valid_gpios) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530169 gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
Laxman Dewangan62199292012-01-09 20:27:41 +0530170 gpio_set_value_cansleep(tps->vsel1_gpio,
171 (new_vset_id >> 1) & 0x1);
172 }
173 return 0;
174}
175
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530176static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
177 unsigned int old_selector, unsigned int new_selector)
178{
179 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530180
Axel Line08ef732012-06-08 14:35:32 +0800181 return DIV_ROUND_UP(abs(new_selector - old_selector) *
182 rdev->desc->uV_step,
183 tps->change_uv_per_us);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530184}
185
Laxman Dewangan9a006302012-05-14 17:46:51 +0530186static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
187{
188 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
189 int i;
190 int val;
191 int ret;
192
193 /* Enable force PWM mode in FAST mode only. */
194 switch (mode) {
195 case REGULATOR_MODE_FAST:
196 val = FORCE_PWM_ENABLE;
197 break;
198
199 case REGULATOR_MODE_NORMAL:
200 val = 0;
201 break;
202
203 default:
204 return -EINVAL;
205 }
206
207 if (!tps->valid_gpios) {
208 ret = regmap_update_bits(tps->regmap,
209 REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val);
210 if (ret < 0)
211 dev_err(tps->dev,
212 "%s(): register %d update failed with err %d\n",
213 __func__, REG_VSET0 + tps->curr_vset_id, ret);
214 return ret;
215 }
216
217 /* If gpios are valid then all register set need to be control */
218 for (i = 0; i < 4; ++i) {
219 ret = regmap_update_bits(tps->regmap,
220 REG_VSET0 + i, FORCE_PWM_ENABLE, val);
221 if (ret < 0) {
222 dev_err(tps->dev,
223 "%s(): register %d update failed with err %d\n",
224 __func__, REG_VSET0 + i, ret);
225 return ret;
226 }
227 }
228 return ret;
229}
230
231static unsigned int tps62360_get_mode(struct regulator_dev *rdev)
232{
233 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
234 unsigned int data;
235 int ret;
236
237 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
238 if (ret < 0) {
239 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
240 __func__, REG_VSET0 + tps->curr_vset_id, ret);
241 return ret;
242 }
243 return (data & FORCE_PWM_ENABLE) ?
244 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
245}
246
Laxman Dewangan62199292012-01-09 20:27:41 +0530247static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530248 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
Axel Lin41097af2012-05-14 11:27:25 +0800249 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
Axel Lin7f225ba2012-05-14 11:25:42 +0800250 .list_voltage = regulator_list_voltage_linear,
Axel Lin41097af2012-05-14 11:27:25 +0800251 .map_voltage = regulator_map_voltage_linear,
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530252 .set_voltage_time_sel = tps62360_set_voltage_time_sel,
Laxman Dewangan9a006302012-05-14 17:46:51 +0530253 .set_mode = tps62360_set_mode,
254 .get_mode = tps62360_get_mode,
Laxman Dewangan62199292012-01-09 20:27:41 +0530255};
256
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530257static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530258 struct tps62360_regulator_platform_data *pdata)
259{
260 int ret;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530261 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530262
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530263 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530264 if (tps->en_internal_pulldn)
265 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
266 else
267 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
268 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530269 dev_err(tps->dev,
270 "%s(): register %d write failed with err %d\n",
271 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530272 return ret;
273 }
274
Laxman Dewangan62199292012-01-09 20:27:41 +0530275 /* Reset output discharge path to reduce power consumption */
276 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530277 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530278 dev_err(tps->dev,
279 "%s(): register %d update failed with err %d\n",
280 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530281 return ret;
282 }
283
284 /* Get ramp value from ramp control register */
285 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
286 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530287 dev_err(tps->dev,
288 "%s(): register %d read failed with err %d\n",
289 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530290 return ret;
291 }
292 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
293
294 /* ramp mV/us = 32/(2^ramp_ctrl) */
295 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530296 return ret;
297}
298
299static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530300 .reg_bits = 8,
301 .val_bits = 8,
302 .max_register = REG_CHIPID,
303 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530304};
305
Laxman Dewangan684ae392012-05-11 12:08:43 +0530306static struct tps62360_regulator_platform_data *
307 of_get_tps62360_platform_data(struct device *dev)
308{
309 struct tps62360_regulator_platform_data *pdata;
310 struct device_node *np = dev->of_node;
311
312 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
313 if (!pdata) {
314 dev_err(dev, "Memory alloc failed for platform data\n");
315 return NULL;
316 }
317
318 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
319 if (!pdata->reg_init_data) {
320 dev_err(dev, "Not able to get OF regulator init data\n");
321 return NULL;
322 }
323
324 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
325 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
326
327 if (of_find_property(np, "ti,vsel0-state-high", NULL))
328 pdata->vsel0_def_state = 1;
329
330 if (of_find_property(np, "ti,vsel1-state-high", NULL))
331 pdata->vsel1_def_state = 1;
332
333 if (of_find_property(np, "ti,enable-pull-down", NULL))
334 pdata->en_internal_pulldn = true;
335
Laxman Dewangan684ae392012-05-11 12:08:43 +0530336 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
337 pdata->en_discharge = true;
338
339 return pdata;
340}
341
342#if defined(CONFIG_OF)
343static const struct of_device_id tps62360_of_match[] = {
344 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
345 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
346 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
347 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
348 {},
Axel Linbe154112012-05-14 23:58:08 +0800349};
Laxman Dewangan684ae392012-05-11 12:08:43 +0530350MODULE_DEVICE_TABLE(of, tps62360_of_match);
351#endif
352
Laxman Dewangan62199292012-01-09 20:27:41 +0530353static int __devinit tps62360_probe(struct i2c_client *client,
354 const struct i2c_device_id *id)
355{
Mark Brownc1727082012-04-04 00:50:22 +0100356 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530357 struct tps62360_regulator_platform_data *pdata;
358 struct regulator_dev *rdev;
359 struct tps62360_chip *tps;
360 int ret;
361 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530362 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530363
364 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530365 chip_id = id->driver_data;
366
367 if (client->dev.of_node) {
368 const struct of_device_id *match;
369 match = of_match_device(of_match_ptr(tps62360_of_match),
370 &client->dev);
371 if (!match) {
372 dev_err(&client->dev, "Error: No device match found\n");
373 return -ENODEV;
374 }
375 chip_id = (int)match->data;
376 if (!pdata)
377 pdata = of_get_tps62360_platform_data(&client->dev);
378 }
379
Laxman Dewangan62199292012-01-09 20:27:41 +0530380 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530381 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530382 __func__);
383 return -EIO;
384 }
385
386 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
387 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530388 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530389 __func__);
390 return -ENOMEM;
391 }
392
Laxman Dewangan62199292012-01-09 20:27:41 +0530393 tps->en_discharge = pdata->en_discharge;
394 tps->en_internal_pulldn = pdata->en_internal_pulldn;
395 tps->vsel0_gpio = pdata->vsel0_gpio;
396 tps->vsel1_gpio = pdata->vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +0530397 tps->dev = &client->dev;
Axel Lind1cf4f62012-04-02 18:19:28 +0800398
Laxman Dewangan684ae392012-05-11 12:08:43 +0530399 switch (chip_id) {
Axel Lind1cf4f62012-04-02 18:19:28 +0800400 case TPS62360:
401 case TPS62362:
Axel Linb5152412012-06-14 09:38:26 +0800402 tps->desc.min_uV = TPS62360_BASE_VOLTAGE;
Axel Lind1cf4f62012-04-02 18:19:28 +0800403 tps->voltage_reg_mask = 0x3F;
404 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
405 break;
406 case TPS62361:
407 case TPS62363:
Axel Linb5152412012-06-14 09:38:26 +0800408 tps->desc.min_uV = TPS62361_BASE_VOLTAGE;
Axel Lind1cf4f62012-04-02 18:19:28 +0800409 tps->voltage_reg_mask = 0x7F;
410 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
411 break;
412 default:
413 return -ENODEV;
414 }
Laxman Dewangan62199292012-01-09 20:27:41 +0530415
416 tps->desc.name = id->name;
417 tps->desc.id = 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530418 tps->desc.ops = &tps62360_dcdc_ops;
419 tps->desc.type = REGULATOR_VOLTAGE;
420 tps->desc.owner = THIS_MODULE;
Axel Lin7f225ba2012-05-14 11:25:42 +0800421 tps->desc.uV_step = 10000;
422
Axel Lin9a4bdd82012-04-07 23:29:56 +0800423 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530424 if (IS_ERR(tps->regmap)) {
425 ret = PTR_ERR(tps->regmap);
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530426 dev_err(&client->dev,
427 "%s(): regmap allocation failed with err %d\n",
428 __func__, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530429 return ret;
430 }
431 i2c_set_clientdata(client, tps);
432
433 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
434 (pdata->vsel0_def_state & 1);
435 tps->lru_index[0] = tps->curr_vset_id;
436 tps->valid_gpios = false;
437
438 if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530439 int gpio_flags;
440 gpio_flags = (pdata->vsel0_def_state) ?
441 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
442 ret = gpio_request_one(tps->vsel0_gpio,
443 gpio_flags, "tps62360-vsel0");
Laxman Dewangan62199292012-01-09 20:27:41 +0530444 if (ret) {
445 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530446 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
447 __func__, tps->vsel0_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530448 goto err_gpio0;
449 }
450
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530451 gpio_flags = (pdata->vsel1_def_state) ?
452 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
453 ret = gpio_request_one(tps->vsel1_gpio,
454 gpio_flags, "tps62360-vsel1");
Laxman Dewangan62199292012-01-09 20:27:41 +0530455 if (ret) {
456 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530457 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
458 __func__, tps->vsel1_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530459 goto err_gpio1;
460 }
461 tps->valid_gpios = true;
462
463 /*
464 * Initialize the lru index with vset_reg id
465 * The index 0 will be most recently used and
466 * set with the tps->curr_vset_id */
467 for (i = 0; i < 4; ++i)
468 tps->lru_index[i] = i;
469 tps->lru_index[0] = tps->curr_vset_id;
470 tps->lru_index[tps->curr_vset_id] = 0;
471 }
472
473 ret = tps62360_init_dcdc(tps, pdata);
474 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530475 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530476 __func__, ret);
477 goto err_init;
478 }
479
Mark Brownc1727082012-04-04 00:50:22 +0100480 config.dev = &client->dev;
Laxman Dewangan8bdca0092012-05-11 12:08:42 +0530481 config.init_data = pdata->reg_init_data;
Mark Brownc1727082012-04-04 00:50:22 +0100482 config.driver_data = tps;
Laxman Dewangan9fc38152012-05-20 21:48:47 +0530483 config.of_node = client->dev.of_node;
Mark Brownc1727082012-04-04 00:50:22 +0100484
Laxman Dewangan62199292012-01-09 20:27:41 +0530485 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100486 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530487 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530488 dev_err(tps->dev,
489 "%s(): regulator register failed with err %s\n",
490 __func__, id->name);
Laxman Dewangan62199292012-01-09 20:27:41 +0530491 ret = PTR_ERR(rdev);
492 goto err_init;
493 }
494
495 tps->rdev = rdev;
496 return 0;
497
498err_init:
499 if (gpio_is_valid(tps->vsel1_gpio))
500 gpio_free(tps->vsel1_gpio);
501err_gpio1:
502 if (gpio_is_valid(tps->vsel0_gpio))
503 gpio_free(tps->vsel0_gpio);
504err_gpio0:
Laxman Dewangan62199292012-01-09 20:27:41 +0530505 return ret;
506}
507
508/**
509 * tps62360_remove - tps62360 driver i2c remove handler
510 * @client: i2c driver client device structure
511 *
512 * Unregister TPS driver as an i2c client device driver
513 */
514static int __devexit tps62360_remove(struct i2c_client *client)
515{
516 struct tps62360_chip *tps = i2c_get_clientdata(client);
517
518 if (gpio_is_valid(tps->vsel1_gpio))
519 gpio_free(tps->vsel1_gpio);
520
521 if (gpio_is_valid(tps->vsel0_gpio))
522 gpio_free(tps->vsel0_gpio);
523
524 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530525 return 0;
526}
527
528static void tps62360_shutdown(struct i2c_client *client)
529{
530 struct tps62360_chip *tps = i2c_get_clientdata(client);
531 int st;
532
533 if (!tps->en_discharge)
534 return;
535
536 /* Configure the output discharge path */
537 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
538 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530539 dev_err(tps->dev,
540 "%s(): register %d update failed with err %d\n",
541 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530542}
543
544static const struct i2c_device_id tps62360_id[] = {
545 {.name = "tps62360", .driver_data = TPS62360},
546 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800547 {.name = "tps62362", .driver_data = TPS62362},
548 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530549 {},
550};
551
552MODULE_DEVICE_TABLE(i2c, tps62360_id);
553
554static struct i2c_driver tps62360_i2c_driver = {
555 .driver = {
556 .name = "tps62360",
557 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530558 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530559 },
560 .probe = tps62360_probe,
561 .remove = __devexit_p(tps62360_remove),
562 .shutdown = tps62360_shutdown,
563 .id_table = tps62360_id,
564};
565
566static int __init tps62360_init(void)
567{
568 return i2c_add_driver(&tps62360_i2c_driver);
569}
570subsys_initcall(tps62360_init);
571
572static void __exit tps62360_cleanup(void)
573{
574 i2c_del_driver(&tps62360_i2c_driver);
575}
576module_exit(tps62360_cleanup);
577
578MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800579MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530580MODULE_LICENSE("GPL v2");