blob: dae08a8c6c793643e30d9f082622672f2d1535ea [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
140static int tps62360_dcdc_set_voltage(struct regulator_dev *dev,
141 int min_uV, int max_uV, unsigned *selector)
142{
143 struct tps62360_chip *tps = rdev_get_drvdata(dev);
144 int vsel;
145 int ret;
146 bool found = false;
147 int new_vset_id = tps->curr_vset_id;
148
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530149 if ((max_uV < min_uV) || (max_uV < tps->voltage_base))
Laxman Dewangan62199292012-01-09 20:27:41 +0530150 return -EINVAL;
151
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530152 if (min_uV > (tps->voltage_base + (tps->desc.n_voltages - 1) * 10000))
Laxman Dewangan62199292012-01-09 20:27:41 +0530153 return -EINVAL;
154
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530155 vsel = DIV_ROUND_UP(min_uV - tps->voltage_base, 10000);
Laxman Dewangan62199292012-01-09 20:27:41 +0530156 if (selector)
157 *selector = (vsel & tps->voltage_reg_mask);
158
159 /*
160 * If gpios are available to select the VSET register then least
161 * recently used register for new configuration.
162 */
163 if (tps->valid_gpios)
164 found = find_voltage_set_register(tps, vsel, &new_vset_id);
165
166 if (!found) {
167 ret = regmap_update_bits(tps->regmap, REG_VSET0 + new_vset_id,
168 tps->voltage_reg_mask, vsel);
169 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530170 dev_err(tps->dev,
171 "%s(): register %d update failed with err %d\n",
172 __func__, REG_VSET0 + new_vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530173 return ret;
174 }
175 tps->curr_vset_id = new_vset_id;
176 tps->curr_vset_vsel[new_vset_id] = vsel;
177 }
178
179 /* Select proper VSET register vio gpios */
180 if (tps->valid_gpios) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530181 gpio_set_value_cansleep(tps->vsel0_gpio, new_vset_id & 0x1);
Laxman Dewangan62199292012-01-09 20:27:41 +0530182 gpio_set_value_cansleep(tps->vsel1_gpio,
183 (new_vset_id >> 1) & 0x1);
184 }
185 return 0;
186}
187
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530188static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
189 unsigned int old_selector, unsigned int new_selector)
190{
191 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
192 int old_uV, new_uV;
193
Axel Lin7f225ba2012-05-14 11:25:42 +0800194 old_uV = regulator_list_voltage_linear(rdev, old_selector);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530195 if (old_uV < 0)
196 return old_uV;
197
Axel Lin7f225ba2012-05-14 11:25:42 +0800198 new_uV = regulator_list_voltage_linear(rdev, new_selector);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530199 if (new_uV < 0)
200 return new_uV;
201
202 return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us);
203}
204
Laxman Dewangan62199292012-01-09 20:27:41 +0530205static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530206 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
207 .set_voltage = tps62360_dcdc_set_voltage,
Axel Lin7f225ba2012-05-14 11:25:42 +0800208 .list_voltage = regulator_list_voltage_linear,
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530209 .set_voltage_time_sel = tps62360_set_voltage_time_sel,
Laxman Dewangan62199292012-01-09 20:27:41 +0530210};
211
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530212static int __devinit tps62360_init_force_pwm(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530213 struct tps62360_regulator_platform_data *pdata,
214 int vset_id)
215{
Laxman Dewangan62199292012-01-09 20:27:41 +0530216 int ret;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530217 int bit = 0;
218
Laxman Dewangan62199292012-01-09 20:27:41 +0530219 if (pdata->en_force_pwm)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530220 bit = BIT(7);
221
222 ret = regmap_update_bits(tps->regmap, REG_VSET0 + vset_id, BIT(7), bit);
Laxman Dewangan62199292012-01-09 20:27:41 +0530223 if (ret < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530224 dev_err(tps->dev,
225 "%s(): register %d update failed with err %d\n",
226 __func__, REG_VSET0 + vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530227 return ret;
228}
229
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530230static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530231 struct tps62360_regulator_platform_data *pdata)
232{
233 int ret;
234 int i;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530235 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530236
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530237 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530238 if (tps->en_internal_pulldn)
239 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
240 else
241 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
242 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530243 dev_err(tps->dev,
244 "%s(): register %d write failed with err %d\n",
245 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530246 return ret;
247 }
248
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530249 /* Initialize force PWM mode */
Laxman Dewangan62199292012-01-09 20:27:41 +0530250 if (tps->valid_gpios) {
251 for (i = 0; i < 4; ++i) {
252 ret = tps62360_init_force_pwm(tps, pdata, i);
253 if (ret < 0)
254 return ret;
255 }
256 } else {
257 ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id);
258 if (ret < 0)
259 return ret;
260 }
261
262 /* Reset output discharge path to reduce power consumption */
263 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530264 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530265 dev_err(tps->dev,
266 "%s(): register %d update failed with err %d\n",
267 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530268 return ret;
269 }
270
271 /* Get ramp value from ramp control register */
272 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
273 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530274 dev_err(tps->dev,
275 "%s(): register %d read failed with err %d\n",
276 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530277 return ret;
278 }
279 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
280
281 /* ramp mV/us = 32/(2^ramp_ctrl) */
282 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530283 return ret;
284}
285
286static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530287 .reg_bits = 8,
288 .val_bits = 8,
289 .max_register = REG_CHIPID,
290 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530291};
292
Laxman Dewangan684ae392012-05-11 12:08:43 +0530293static struct tps62360_regulator_platform_data *
294 of_get_tps62360_platform_data(struct device *dev)
295{
296 struct tps62360_regulator_platform_data *pdata;
297 struct device_node *np = dev->of_node;
298
299 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
300 if (!pdata) {
301 dev_err(dev, "Memory alloc failed for platform data\n");
302 return NULL;
303 }
304
305 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
306 if (!pdata->reg_init_data) {
307 dev_err(dev, "Not able to get OF regulator init data\n");
308 return NULL;
309 }
310
311 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
312 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
313
314 if (of_find_property(np, "ti,vsel0-state-high", NULL))
315 pdata->vsel0_def_state = 1;
316
317 if (of_find_property(np, "ti,vsel1-state-high", NULL))
318 pdata->vsel1_def_state = 1;
319
320 if (of_find_property(np, "ti,enable-pull-down", NULL))
321 pdata->en_internal_pulldn = true;
322
323 if (of_find_property(np, "ti,enable-force-pwm", NULL))
324 pdata->en_force_pwm = true;
325
326 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
327 pdata->en_discharge = true;
328
329 return pdata;
330}
331
332#if defined(CONFIG_OF)
333static const struct of_device_id tps62360_of_match[] = {
334 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
335 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
336 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
337 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
338 {},
339}
340MODULE_DEVICE_TABLE(of, tps62360_of_match);
341#endif
342
Laxman Dewangan62199292012-01-09 20:27:41 +0530343static int __devinit tps62360_probe(struct i2c_client *client,
344 const struct i2c_device_id *id)
345{
Mark Brownc1727082012-04-04 00:50:22 +0100346 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530347 struct tps62360_regulator_platform_data *pdata;
348 struct regulator_dev *rdev;
349 struct tps62360_chip *tps;
350 int ret;
351 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530352 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530353
354 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530355 chip_id = id->driver_data;
356
357 if (client->dev.of_node) {
358 const struct of_device_id *match;
359 match = of_match_device(of_match_ptr(tps62360_of_match),
360 &client->dev);
361 if (!match) {
362 dev_err(&client->dev, "Error: No device match found\n");
363 return -ENODEV;
364 }
365 chip_id = (int)match->data;
366 if (!pdata)
367 pdata = of_get_tps62360_platform_data(&client->dev);
368 }
369
Laxman Dewangan62199292012-01-09 20:27:41 +0530370 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530371 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530372 __func__);
373 return -EIO;
374 }
375
376 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
377 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530378 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530379 __func__);
380 return -ENOMEM;
381 }
382
383 tps->en_force_pwm = pdata->en_force_pwm;
384 tps->en_discharge = pdata->en_discharge;
385 tps->en_internal_pulldn = pdata->en_internal_pulldn;
386 tps->vsel0_gpio = pdata->vsel0_gpio;
387 tps->vsel1_gpio = pdata->vsel1_gpio;
Laxman Dewangan62199292012-01-09 20:27:41 +0530388 tps->dev = &client->dev;
Axel Lind1cf4f62012-04-02 18:19:28 +0800389
Laxman Dewangan684ae392012-05-11 12:08:43 +0530390 switch (chip_id) {
Axel Lind1cf4f62012-04-02 18:19:28 +0800391 case TPS62360:
392 case TPS62362:
393 tps->voltage_base = TPS62360_BASE_VOLTAGE;
394 tps->voltage_reg_mask = 0x3F;
395 tps->desc.n_voltages = TPS62360_N_VOLTAGES;
396 break;
397 case TPS62361:
398 case TPS62363:
399 tps->voltage_base = TPS62361_BASE_VOLTAGE;
400 tps->voltage_reg_mask = 0x7F;
401 tps->desc.n_voltages = TPS62361_N_VOLTAGES;
402 break;
403 default:
404 return -ENODEV;
405 }
Laxman Dewangan62199292012-01-09 20:27:41 +0530406
407 tps->desc.name = id->name;
408 tps->desc.id = 0;
Laxman Dewangan62199292012-01-09 20:27:41 +0530409 tps->desc.ops = &tps62360_dcdc_ops;
410 tps->desc.type = REGULATOR_VOLTAGE;
411 tps->desc.owner = THIS_MODULE;
Axel Lin7f225ba2012-05-14 11:25:42 +0800412 tps->desc.min_uV = tps->voltage_base;
413 tps->desc.uV_step = 10000;
414
Axel Lin9a4bdd82012-04-07 23:29:56 +0800415 tps->regmap = devm_regmap_init_i2c(client, &tps62360_regmap_config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530416 if (IS_ERR(tps->regmap)) {
417 ret = PTR_ERR(tps->regmap);
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530418 dev_err(&client->dev,
419 "%s(): regmap allocation failed with err %d\n",
420 __func__, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530421 return ret;
422 }
423 i2c_set_clientdata(client, tps);
424
425 tps->curr_vset_id = (pdata->vsel1_def_state & 1) * 2 +
426 (pdata->vsel0_def_state & 1);
427 tps->lru_index[0] = tps->curr_vset_id;
428 tps->valid_gpios = false;
429
430 if (gpio_is_valid(tps->vsel0_gpio) && gpio_is_valid(tps->vsel1_gpio)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530431 int gpio_flags;
432 gpio_flags = (pdata->vsel0_def_state) ?
433 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
434 ret = gpio_request_one(tps->vsel0_gpio,
435 gpio_flags, "tps62360-vsel0");
Laxman Dewangan62199292012-01-09 20:27:41 +0530436 if (ret) {
437 dev_err(&client->dev,
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530438 "%s(): Could not obtain vsel0 GPIO %d: %d\n",
439 __func__, tps->vsel0_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530440 goto err_gpio0;
441 }
442
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530443 gpio_flags = (pdata->vsel1_def_state) ?
444 GPIOF_OUT_INIT_HIGH : GPIOF_OUT_INIT_LOW;
445 ret = gpio_request_one(tps->vsel1_gpio,
446 gpio_flags, "tps62360-vsel1");
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 vsel1 GPIO %d: %d\n",
450 __func__, tps->vsel1_gpio, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530451 goto err_gpio1;
452 }
453 tps->valid_gpios = true;
454
455 /*
456 * Initialize the lru index with vset_reg id
457 * The index 0 will be most recently used and
458 * set with the tps->curr_vset_id */
459 for (i = 0; i < 4; ++i)
460 tps->lru_index[i] = i;
461 tps->lru_index[0] = tps->curr_vset_id;
462 tps->lru_index[tps->curr_vset_id] = 0;
463 }
464
465 ret = tps62360_init_dcdc(tps, pdata);
466 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530467 dev_err(tps->dev, "%s(): Init failed with err = %d\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530468 __func__, ret);
469 goto err_init;
470 }
471
Mark Brownc1727082012-04-04 00:50:22 +0100472 config.dev = &client->dev;
Laxman Dewangan8bdca0092012-05-11 12:08:42 +0530473 config.init_data = pdata->reg_init_data;
Mark Brownc1727082012-04-04 00:50:22 +0100474 config.driver_data = tps;
475
Laxman Dewangan62199292012-01-09 20:27:41 +0530476 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100477 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530478 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530479 dev_err(tps->dev,
480 "%s(): regulator register failed with err %s\n",
481 __func__, id->name);
Laxman Dewangan62199292012-01-09 20:27:41 +0530482 ret = PTR_ERR(rdev);
483 goto err_init;
484 }
485
486 tps->rdev = rdev;
487 return 0;
488
489err_init:
490 if (gpio_is_valid(tps->vsel1_gpio))
491 gpio_free(tps->vsel1_gpio);
492err_gpio1:
493 if (gpio_is_valid(tps->vsel0_gpio))
494 gpio_free(tps->vsel0_gpio);
495err_gpio0:
Laxman Dewangan62199292012-01-09 20:27:41 +0530496 return ret;
497}
498
499/**
500 * tps62360_remove - tps62360 driver i2c remove handler
501 * @client: i2c driver client device structure
502 *
503 * Unregister TPS driver as an i2c client device driver
504 */
505static int __devexit tps62360_remove(struct i2c_client *client)
506{
507 struct tps62360_chip *tps = i2c_get_clientdata(client);
508
509 if (gpio_is_valid(tps->vsel1_gpio))
510 gpio_free(tps->vsel1_gpio);
511
512 if (gpio_is_valid(tps->vsel0_gpio))
513 gpio_free(tps->vsel0_gpio);
514
515 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530516 return 0;
517}
518
519static void tps62360_shutdown(struct i2c_client *client)
520{
521 struct tps62360_chip *tps = i2c_get_clientdata(client);
522 int st;
523
524 if (!tps->en_discharge)
525 return;
526
527 /* Configure the output discharge path */
528 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
529 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530530 dev_err(tps->dev,
531 "%s(): register %d update failed with err %d\n",
532 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530533}
534
535static const struct i2c_device_id tps62360_id[] = {
536 {.name = "tps62360", .driver_data = TPS62360},
537 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800538 {.name = "tps62362", .driver_data = TPS62362},
539 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530540 {},
541};
542
543MODULE_DEVICE_TABLE(i2c, tps62360_id);
544
545static struct i2c_driver tps62360_i2c_driver = {
546 .driver = {
547 .name = "tps62360",
548 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530549 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530550 },
551 .probe = tps62360_probe,
552 .remove = __devexit_p(tps62360_remove),
553 .shutdown = tps62360_shutdown,
554 .id_table = tps62360_id,
555};
556
557static int __init tps62360_init(void)
558{
559 return i2c_add_driver(&tps62360_i2c_driver);
560}
561subsys_initcall(tps62360_init);
562
563static void __exit tps62360_cleanup(void)
564{
565 i2c_del_driver(&tps62360_i2c_driver);
566}
567module_exit(tps62360_cleanup);
568
569MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800570MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530571MODULE_LICENSE("GPL v2");