blob: a490d5b749b2c75efffe33c4249fdf06a83c4e33 [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;
77};
78
79/*
80 * find_voltage_set_register: Find new voltage configuration register
81 * (VSET) id.
82 * The finding of the new VSET register will be based on the LRU mechanism.
83 * Each VSET register will have different voltage configured . This
84 * Function will look if any of the VSET register have requested voltage set
85 * or not.
86 * - If it is already there then it will make that register as most
87 * recently used and return as found so that caller need not to set
88 * the VSET register but need to set the proper gpios to select this
89 * VSET register.
90 * - If requested voltage is not found then it will use the least
91 * recently mechanism to get new VSET register for new configuration
92 * and will return not_found so that caller need to set new VSET
93 * register and then gpios (both).
94 */
95static bool find_voltage_set_register(struct tps62360_chip *tps,
96 int req_vsel, int *vset_reg_id)
97{
98 int i;
99 bool found = false;
100 int new_vset_reg = tps->lru_index[3];
101 int found_index = 3;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530102
Laxman Dewangan62199292012-01-09 20:27:41 +0530103 for (i = 0; i < 4; ++i) {
104 if (tps->curr_vset_vsel[tps->lru_index[i]] == req_vsel) {
105 new_vset_reg = tps->lru_index[i];
106 found_index = i;
107 found = true;
108 goto update_lru_index;
109 }
110 }
111
112update_lru_index:
113 for (i = found_index; i > 0; i--)
114 tps->lru_index[i] = tps->lru_index[i - 1];
115
116 tps->lru_index[0] = new_vset_reg;
117 *vset_reg_id = new_vset_reg;
118 return found;
119}
120
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530121static int tps62360_dcdc_get_voltage_sel(struct regulator_dev *dev)
Laxman Dewangan62199292012-01-09 20:27:41 +0530122{
123 struct tps62360_chip *tps = rdev_get_drvdata(dev);
124 int vsel;
125 unsigned int data;
126 int ret;
127
128 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
129 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530130 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
131 __func__, REG_VSET0 + tps->curr_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530132 return ret;
133 }
134 vsel = (int)data & tps->voltage_reg_mask;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530135 return vsel;
Laxman Dewangan62199292012-01-09 20:27:41 +0530136}
137
Axel Lin41097af2012-05-14 11:27:25 +0800138static int tps62360_dcdc_set_voltage_sel(struct regulator_dev *dev,
139 unsigned selector)
Laxman Dewangan62199292012-01-09 20:27:41 +0530140{
141 struct tps62360_chip *tps = rdev_get_drvdata(dev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530142 int ret;
143 bool found = false;
144 int new_vset_id = tps->curr_vset_id;
145
Laxman Dewangan62199292012-01-09 20:27:41 +0530146 /*
147 * If gpios are available to select the VSET register then least
148 * recently used register for new configuration.
149 */
150 if (tps->valid_gpios)
Axel Lin41097af2012-05-14 11:27:25 +0800151 found = find_voltage_set_register(tps, selector, &new_vset_id);
Laxman Dewangan62199292012-01-09 20:27:41 +0530152
153 if (!found) {
154 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
Axel Lin41097af2012-05-14 11:27:25 +0800155 tps->voltage_reg_mask, selector);
Laxman Dewangan62199292012-01-09 20:27:41 +0530156 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530157 dev_err(tps->dev,
158 "%s(): register %d update failed with err %d\n",
159 __func__, REG_VSET0 + new_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530160 return ret;
161 }
162 tps->curr_vset_id = new_vset_id;
Axel Lin41097af2012-05-14 11:27:25 +0800163 tps->curr_vset_vsel[new_vset_id] = selector;
Laxman Dewangan62199292012-01-09 20:27:41 +0530164 }
165
166 /* Select proper VSET register vio gpios */
167 if (tps->valid_gpios) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530168 gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
Laxman Dewangan62199292012-01-09 20:27:41 +0530169 gpio_set_value_cansleep(tps->vsel1_gpio,
170 (new_vset_id >> 1) & 0x1);
171 }
172 return 0;
173}
174
Laxman Dewangan9a006302012-05-14 17:46:51 +0530175static int tps62360_set_mode(struct regulator_dev *rdev, unsigned int mode)
176{
177 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
178 int i;
179 int val;
180 int ret;
181
182 /* Enable force PWM mode in FAST mode only. */
183 switch (mode) {
184 case REGULATOR_MODE_FAST:
185 val = FORCE_PWM_ENABLE;
186 break;
187
188 case REGULATOR_MODE_NORMAL:
189 val = 0;
190 break;
191
192 default:
193 return -EINVAL;
194 }
195
196 if (!tps->valid_gpios) {
197 ret = regmap_update_bits(tps->regmap,
198 REG_VSET0 + tps->curr_vset_id, FORCE_PWM_ENABLE, val);
199 if (ret < 0)
200 dev_err(tps->dev,
201 "%s(): register %d update failed with err %d\n",
202 __func__, REG_VSET0 + tps->curr_vset_id, ret);
203 return ret;
204 }
205
206 /* If gpios are valid then all register set need to be control */
207 for (i = 0; i < 4; ++i) {
208 ret = regmap_update_bits(tps->regmap,
209 REG_VSET0 + i, 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 + i, ret);
214 return ret;
215 }
216 }
217 return ret;
218}
219
220static unsigned int tps62360_get_mode(struct regulator_dev *rdev)
221{
222 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
223 unsigned int data;
224 int ret;
225
226 ret = regmap_read(tps->regmap, REG_VSET0 + tps->curr_vset_id, &data);
227 if (ret < 0) {
228 dev_err(tps->dev, "%s(): register %d read failed with err %d\n",
229 __func__, REG_VSET0 + tps->curr_vset_id, ret);
230 return ret;
231 }
232 return (data & FORCE_PWM_ENABLE) ?
233 REGULATOR_MODE_FAST : REGULATOR_MODE_NORMAL;
234}
235
Laxman Dewangan62199292012-01-09 20:27:41 +0530236static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530237 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
Axel Lin41097af2012-05-14 11:27:25 +0800238 .set_voltage_sel = tps62360_dcdc_set_voltage_sel,
Axel Lin7f225ba2012-05-14 11:25:42 +0800239 .list_voltage = regulator_list_voltage_linear,
Axel Lin41097af2012-05-14 11:27:25 +0800240 .map_voltage = regulator_map_voltage_linear,
Axel Lin0072f0a2012-06-20 22:55:50 +0800241 .set_voltage_time_sel = regulator_set_voltage_time_sel,
Laxman Dewangan9a006302012-05-14 17:46:51 +0530242 .set_mode = tps62360_set_mode,
243 .get_mode = tps62360_get_mode,
Laxman Dewangan62199292012-01-09 20:27:41 +0530244};
245
Bill Pembertona5023572012-11-19 13:22:22 -0500246static int tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530247 struct tps62360_regulator_platform_data *pdata)
248{
249 int ret;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530250 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530251
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530252 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530253 if (tps->en_internal_pulldn)
254 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
255 else
256 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
257 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530258 dev_err(tps->dev,
259 "%s(): register %d write failed with err %d\n",
260 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530261 return ret;
262 }
263
Laxman Dewangan62199292012-01-09 20:27:41 +0530264 /* Reset output discharge path to reduce power consumption */
265 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530266 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530267 dev_err(tps->dev,
268 "%s(): register %d update failed with err %d\n",
269 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530270 return ret;
271 }
272
273 /* Get ramp value from ramp control register */
274 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
275 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530276 dev_err(tps->dev,
277 "%s(): register %d read failed with err %d\n",
278 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530279 return ret;
280 }
Axel Lin1864b672013-04-23 12:35:53 +0800281 ramp_ctrl = (ramp_ctrl >> 5) & 0x7;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530282
283 /* ramp mV/us = 32/(2^ramp_ctrl) */
Axel Lin0072f0a2012-06-20 22:55:50 +0800284 tps->desc.ramp_delay = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530285 return ret;
286}
287
288static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530289 .reg_bits = 8,
290 .val_bits = 8,
291 .max_register = REG_CHIPID,
292 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530293};
294
Laxman Dewangan684ae392012-05-11 12:08:43 +0530295static struct tps62360_regulator_platform_data *
296 of_get_tps62360_platform_data(struct device *dev)
297{
298 struct tps62360_regulator_platform_data *pdata;
299 struct device_node *np = dev->of_node;
300
301 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
302 if (!pdata) {
303 dev_err(dev, "Memory alloc failed for platform data\n");
304 return NULL;
305 }
306
307 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
308 if (!pdata->reg_init_data) {
309 dev_err(dev, "Not able to get OF regulator init data\n");
310 return NULL;
311 }
312
313 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
314 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
315
316 if (of_find_property(np, "ti,vsel0-state-high", NULL))
317 pdata->vsel0_def_state = 1;
318
319 if (of_find_property(np, "ti,vsel1-state-high", NULL))
320 pdata->vsel1_def_state = 1;
321
322 if (of_find_property(np, "ti,enable-pull-down", NULL))
323 pdata->en_internal_pulldn = true;
324
Laxman Dewangan684ae392012-05-11 12:08:43 +0530325 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
326 pdata->en_discharge = true;
327
328 return pdata;
329}
330
331#if defined(CONFIG_OF)
332static const struct of_device_id tps62360_of_match[] = {
333 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
334 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
335 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
336 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
337 {},
Axel Linbe154112012-05-14 23:58:08 +0800338};
Laxman Dewangan684ae392012-05-11 12:08:43 +0530339MODULE_DEVICE_TABLE(of, tps62360_of_match);
340#endif
341
Bill Pembertona5023572012-11-19 13:22:22 -0500342static int tps62360_probe(struct i2c_client *client,
Laxman Dewangan62199292012-01-09 20:27:41 +0530343 const struct i2c_device_id *id)
344{
Mark Brownc1727082012-04-04 00:50:22 +0100345 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530346 struct tps62360_regulator_platform_data *pdata;
347 struct regulator_dev *rdev;
348 struct tps62360_chip *tps;
349 int ret;
350 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530351 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530352
353 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530354
355 if (client->dev.of_node) {
356 const struct of_device_id *match;
357 match = of_match_device(of_match_ptr(tps62360_of_match),
358 &client->dev);
359 if (!match) {
360 dev_err(&client->dev, "Error: No device match found\n");
361 return -ENODEV;
362 }
363 chip_id = (int)match->data;
364 if (!pdata)
365 pdata = of_get_tps62360_platform_data(&client->dev);
Tuomas Tynkkynen0a62d032013-06-18 13:14:41 +0300366 } else if (id) {
367 chip_id = id->driver_data;
368 } else {
369 dev_err(&client->dev, "No device tree match or id table match found\n");
370 return -ENODEV;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530371 }
372
Laxman Dewangan62199292012-01-09 20:27:41 +0530373 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530374 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530375 __func__);
376 return -EIO;
377 }
378
379 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
380 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530381 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530382 __func__);
383 return -ENOMEM;
384 }
385
Laxman Dewangan62199292012-01-09 20:27:41 +0530386 tps->en_discharge = pdata->en_discharge;
387 tps->en_internal_pulldn = pdata->en_internal_pulldn;
388 tps->vsel0_gpio = pdata->vsel0_gpio;
389 tps->vsel1_gpio = pdata->vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +0530390 tps->dev = &client->dev;
Axel Lind1cf4f62012-04-02 18:19:28 +0800391
Laxman Dewangan684ae392012-05-11 12:08:43 +0530392 switch (chip_id) {
Axel Lind1cf4f62012-04-02 18:19:28 +0800393 case TPS62360:
394 case TPS62362:
Axel Linb5152412012-06-14 09:38:26 +0800395 tps->desc.min_uV = TPS62360_BASE_VOLTAGE;
Axel Lind1cf4f62012-04-02 18:19:28 +0800396 tps->voltage_reg_mask = 0x3F;
397 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
398 break;
399 case TPS62361:
400 case TPS62363:
Axel Linb5152412012-06-14 09:38:26 +0800401 tps->desc.min_uV = TPS62361_BASE_VOLTAGE;
Axel Lind1cf4f62012-04-02 18:19:28 +0800402 tps->voltage_reg_mask = 0x7F;
403 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
404 break;
405 default:
406 return -ENODEV;
407 }
Laxman Dewangan62199292012-01-09 20:27:41 +0530408
Tuomas Tynkkynen0a62d032013-06-18 13:14:41 +0300409 tps->desc.name = client->name;
Laxman Dewangan62199292012-01-09 20:27:41 +0530410 tps->desc.id = 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530411 tps->desc.ops = &tps62360_dcdc_ops;
412 tps->desc.type = REGULATOR_VOLTAGE;
413 tps->desc.owner = THIS_MODULE;
Axel Lin7f225ba2012-05-14 11:25:42 +0800414 tps->desc.uV_step = 10000;
415
Axel Lin9a4bdd82012-04-07 23:29:56 +0800416 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530417 if (IS_ERR(tps->regmap)) {
418 ret = PTR_ERR(tps->regmap);
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530419 dev_err(&client->dev,
420 "%s(): regmap allocation failed with err %d\n",
421 __func__, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530422 return ret;
423 }
424 i2c_set_clientdata(client, tps);
425
426 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
427 (pdata->vsel0_def_state & 1);
428 tps->lru_index[0] = tps->curr_vset_id;
429 tps->valid_gpios = false;
430
431 if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530432 int gpio_flags;
433 gpio_flags = (pdata->vsel0_def_state) ?
434 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530435 ret = devm_gpio_request_one(&client->dev, tps->vsel0_gpio,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530436 gpio_flags, "tps62360-vsel0");
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 vsel0 GPIO %d: %d\n",
440 __func__, tps->vsel0_gpio, ret);
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530441 return ret;
Laxman Dewangan62199292012-01-09 20:27:41 +0530442 }
443
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530444 gpio_flags = (pdata->vsel1_def_state) ?
445 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530446 ret = devm_gpio_request_one(&client->dev, tps->vsel1_gpio,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530447 gpio_flags, "tps62360-vsel1");
Laxman Dewangan62199292012-01-09 20:27:41 +0530448 if (ret) {
449 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530450 "%s(): Could not obtain vsel1 GPIO %d: %d\n",
451 __func__, tps->vsel1_gpio, ret);
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530452 return ret;
Laxman Dewangan62199292012-01-09 20:27:41 +0530453 }
454 tps->valid_gpios = true;
455
456 /*
457 * Initialize the lru index with vset_reg id
458 * The index 0 will be most recently used and
459 * set with the tps->curr_vset_id */
460 for (i = 0; i < 4; ++i)
461 tps->lru_index[i] = i;
462 tps->lru_index[0] = tps->curr_vset_id;
463 tps->lru_index[tps->curr_vset_id] = 0;
464 }
465
466 ret = tps62360_init_dcdc(tps, pdata);
467 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530468 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530469 __func__, ret);
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530470 return ret;
Laxman Dewangan62199292012-01-09 20:27:41 +0530471 }
472
Mark Brownc1727082012-04-04 00:50:22 +0100473 config.dev = &client->dev;
Laxman Dewangan8bdca0092012-05-11 12:08:42 +0530474 config.init_data = pdata->reg_init_data;
Mark Brownc1727082012-04-04 00:50:22 +0100475 config.driver_data = tps;
Laxman Dewangan9fc38152012-05-20 21:48:47 +0530476 config.of_node = client->dev.of_node;
Mark Brownc1727082012-04-04 00:50:22 +0100477
Laxman Dewangan62199292012-01-09 20:27:41 +0530478 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100479 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530480 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530481 dev_err(tps->dev,
482 "%s(): regulator register failed with err %s\n",
483 __func__, id->name);
Laxman Dewangan8a8e3d52012-07-02 15:35:48 +0530484 return PTR_ERR(rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530485 }
486
487 tps->rdev = rdev;
488 return 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530489}
490
491/**
492 * tps62360_remove - tps62360 driver i2c remove handler
493 * @client: i2c driver client device structure
494 *
495 * Unregister TPS driver as an i2c client device driver
496 */
Bill Pemberton8dc995f2012-11-19 13:26:10 -0500497static int tps62360_remove(struct i2c_client *client)
Laxman Dewangan62199292012-01-09 20:27:41 +0530498{
499 struct tps62360_chip *tps = i2c_get_clientdata(client);
500
Laxman Dewangan62199292012-01-09 20:27:41 +0530501 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530502 return 0;
503}
504
505static void tps62360_shutdown(struct i2c_client *client)
506{
507 struct tps62360_chip *tps = i2c_get_clientdata(client);
508 int st;
509
510 if (!tps->en_discharge)
511 return;
512
513 /* Configure the output discharge path */
514 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
515 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530516 dev_err(tps->dev,
517 "%s(): register %d update failed with err %d\n",
518 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530519}
520
521static const struct i2c_device_id tps62360_id[] = {
522 {.name = "tps62360", .driver_data = TPS62360},
523 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800524 {.name = "tps62362", .driver_data = TPS62362},
525 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530526 {},
527};
528
529MODULE_DEVICE_TABLE(i2c, tps62360_id);
530
531static struct i2c_driver tps62360_i2c_driver = {
532 .driver = {
533 .name = "tps62360",
534 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530535 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530536 },
537 .probe = tps62360_probe,
Bill Pemberton5eb9f2b2012-11-19 13:20:42 -0500538 .remove = tps62360_remove,
Laxman Dewangan62199292012-01-09 20:27:41 +0530539 .shutdown = tps62360_shutdown,
540 .id_table = tps62360_id,
541};
542
543static int __init tps62360_init(void)
544{
545 return i2c_add_driver(&tps62360_i2c_driver);
546}
547subsys_initcall(tps62360_init);
548
549static void __exit tps62360_cleanup(void)
550{
551 i2c_del_driver(&tps62360_i2c_driver);
552}
553module_exit(tps62360_cleanup);
554
555MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800556MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530557MODULE_LICENSE("GPL v2");