blob: 60765ccd25f594646ab451a0d67c0fc6d4bfa09d [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
188static int tps62360_dcdc_list_voltage(struct regulator_dev *dev,
189 unsigned selector)
190{
191 struct tps62360_chip *tps = rdev_get_drvdata(dev);
192
Axel Lin46783a02012-02-07 11:06:20 +0800193 if (selector >= tps->desc.n_voltages)
Laxman Dewangan62199292012-01-09 20:27:41 +0530194 return -EINVAL;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530195
196 return tps->voltage_base + selector * 10000;
Laxman Dewangan62199292012-01-09 20:27:41 +0530197}
198
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530199static int tps62360_set_voltage_time_sel(struct regulator_dev *rdev,
200 unsigned int old_selector, unsigned int new_selector)
201{
202 struct tps62360_chip *tps = rdev_get_drvdata(rdev);
203 int old_uV, new_uV;
204
205 old_uV = tps62360_dcdc_list_voltage(rdev, old_selector);
206 if (old_uV < 0)
207 return old_uV;
208
209 new_uV = tps62360_dcdc_list_voltage(rdev, new_selector);
210 if (new_uV < 0)
211 return new_uV;
212
213 return DIV_ROUND_UP(abs(old_uV - new_uV), tps->change_uv_per_us);
214}
215
Laxman Dewangan62199292012-01-09 20:27:41 +0530216static struct regulator_ops tps62360_dcdc_ops = {
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530217 .get_voltage_sel = tps62360_dcdc_get_voltage_sel,
218 .set_voltage = tps62360_dcdc_set_voltage,
219 .list_voltage = tps62360_dcdc_list_voltage,
220 .set_voltage_time_sel = tps62360_set_voltage_time_sel,
Laxman Dewangan62199292012-01-09 20:27:41 +0530221};
222
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530223static int __devinit tps62360_init_force_pwm(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530224 struct tps62360_regulator_platform_data *pdata,
225 int vset_id)
226{
Laxman Dewangan62199292012-01-09 20:27:41 +0530227 int ret;
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530228 int bit = 0;
229
Laxman Dewangan62199292012-01-09 20:27:41 +0530230 if (pdata->en_force_pwm)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530231 bit = BIT(7);
232
233 ret = regmap_update_bits(tps->regmap, REG_VSET0 + vset_id, BIT(7), bit);
Laxman Dewangan62199292012-01-09 20:27:41 +0530234 if (ret < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530235 dev_err(tps->dev,
236 "%s(): register %d update failed with err %d\n",
237 __func__, REG_VSET0 + vset_id, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530238 return ret;
239}
240
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530241static int __devinit tps62360_init_dcdc(struct tps62360_chip *tps,
Laxman Dewangan62199292012-01-09 20:27:41 +0530242 struct tps62360_regulator_platform_data *pdata)
243{
244 int ret;
245 int i;
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530246 unsigned int ramp_ctrl;
Laxman Dewangan62199292012-01-09 20:27:41 +0530247
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530248 /* Initialize internal pull up/down control */
Laxman Dewangan62199292012-01-09 20:27:41 +0530249 if (tps->en_internal_pulldn)
250 ret = regmap_write(tps->regmap, REG_CONTROL, 0xE0);
251 else
252 ret = regmap_write(tps->regmap, REG_CONTROL, 0x0);
253 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530254 dev_err(tps->dev,
255 "%s(): register %d write failed with err %d\n",
256 __func__, REG_CONTROL, ret);
Laxman Dewangan62199292012-01-09 20:27:41 +0530257 return ret;
258 }
259
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530260 /* Initialize force PWM mode */
Laxman Dewangan62199292012-01-09 20:27:41 +0530261 if (tps->valid_gpios) {
262 for (i = 0; i < 4; ++i) {
263 ret = tps62360_init_force_pwm(tps, pdata, i);
264 if (ret < 0)
265 return ret;
266 }
267 } else {
268 ret = tps62360_init_force_pwm(tps, pdata, tps->curr_vset_id);
269 if (ret < 0)
270 return ret;
271 }
272
273 /* Reset output discharge path to reduce power consumption */
274 ret = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), 0);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530275 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530276 dev_err(tps->dev,
277 "%s(): register %d update failed with err %d\n",
278 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530279 return ret;
280 }
281
282 /* Get ramp value from ramp control register */
283 ret = regmap_read(tps->regmap, REG_RAMPCTRL, &ramp_ctrl);
284 if (ret < 0) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530285 dev_err(tps->dev,
286 "%s(): register %d read failed with err %d\n",
287 __func__, REG_RAMPCTRL, ret);
Laxman Dewangana60cfce2012-05-07 18:08:26 +0530288 return ret;
289 }
290 ramp_ctrl = (ramp_ctrl >> 4) & 0x7;
291
292 /* ramp mV/us = 32/(2^ramp_ctrl) */
293 tps->change_uv_per_us = DIV_ROUND_UP(32000, BIT(ramp_ctrl));
Laxman Dewangan62199292012-01-09 20:27:41 +0530294 return ret;
295}
296
297static const struct regmap_config tps62360_regmap_config = {
Laxman Dewangan16ea0032012-05-07 18:08:25 +0530298 .reg_bits = 8,
299 .val_bits = 8,
300 .max_register = REG_CHIPID,
301 .cache_type = REGCACHE_RBTREE,
Laxman Dewangan62199292012-01-09 20:27:41 +0530302};
303
Laxman Dewangan684ae392012-05-11 12:08:43 +0530304static struct tps62360_regulator_platform_data *
305 of_get_tps62360_platform_data(struct device *dev)
306{
307 struct tps62360_regulator_platform_data *pdata;
308 struct device_node *np = dev->of_node;
309
310 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
311 if (!pdata) {
312 dev_err(dev, "Memory alloc failed for platform data\n");
313 return NULL;
314 }
315
316 pdata->reg_init_data = of_get_regulator_init_data(dev, dev->of_node);
317 if (!pdata->reg_init_data) {
318 dev_err(dev, "Not able to get OF regulator init data\n");
319 return NULL;
320 }
321
322 pdata->vsel0_gpio = of_get_named_gpio(np, "vsel0-gpio", 0);
323 pdata->vsel1_gpio = of_get_named_gpio(np, "vsel1-gpio", 0);
324
325 if (of_find_property(np, "ti,vsel0-state-high", NULL))
326 pdata->vsel0_def_state = 1;
327
328 if (of_find_property(np, "ti,vsel1-state-high", NULL))
329 pdata->vsel1_def_state = 1;
330
331 if (of_find_property(np, "ti,enable-pull-down", NULL))
332 pdata->en_internal_pulldn = true;
333
334 if (of_find_property(np, "ti,enable-force-pwm", NULL))
335 pdata->en_force_pwm = true;
336
337 if (of_find_property(np, "ti,enable-vout-discharge", NULL))
338 pdata->en_discharge = true;
339
340 return pdata;
341}
342
343#if defined(CONFIG_OF)
344static const struct of_device_id tps62360_of_match[] = {
345 { .compatible = "ti,tps62360", .data = (void *)TPS62360},
346 { .compatible = "ti,tps62361", .data = (void *)TPS62361},
347 { .compatible = "ti,tps62362", .data = (void *)TPS62362},
348 { .compatible = "ti,tps62363", .data = (void *)TPS62363},
349 {},
350}
351MODULE_DEVICE_TABLE(of, tps62360_of_match);
352#endif
353
Laxman Dewangan62199292012-01-09 20:27:41 +0530354static int __devinit tps62360_probe(struct i2c_client *client,
355 const struct i2c_device_id *id)
356{
Mark Brownc1727082012-04-04 00:50:22 +0100357 struct regulator_config config = { };
Laxman Dewangan62199292012-01-09 20:27:41 +0530358 struct tps62360_regulator_platform_data *pdata;
359 struct regulator_dev *rdev;
360 struct tps62360_chip *tps;
361 int ret;
362 int i;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530363 int chip_id;
Laxman Dewangan62199292012-01-09 20:27:41 +0530364
365 pdata = client->dev.platform_data;
Laxman Dewangan684ae392012-05-11 12:08:43 +0530366 chip_id = id->driver_data;
367
368 if (client->dev.of_node) {
369 const struct of_device_id *match;
370 match = of_match_device(of_match_ptr(tps62360_of_match),
371 &client->dev);
372 if (!match) {
373 dev_err(&client->dev, "Error: No device match found\n");
374 return -ENODEV;
375 }
376 chip_id = (int)match->data;
377 if (!pdata)
378 pdata = of_get_tps62360_platform_data(&client->dev);
379 }
380
Laxman Dewangan62199292012-01-09 20:27:41 +0530381 if (!pdata) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530382 dev_err(&client->dev, "%s(): Platform data not found\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530383 __func__);
384 return -EIO;
385 }
386
387 tps = devm_kzalloc(&client->dev, sizeof(*tps), GFP_KERNEL);
388 if (!tps) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530389 dev_err(&client->dev, "%s(): Memory allocation failed\n",
Laxman Dewangan62199292012-01-09 20:27:41 +0530390 __func__);
391 return -ENOMEM;
392 }
393
394 tps->en_force_pwm = pdata->en_force_pwm;
395 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 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;
483
Laxman Dewangan62199292012-01-09 20:27:41 +0530484 /* Register the regulators */
Mark Brownc1727082012-04-04 00:50:22 +0100485 rdev = regulator_register(&tps->desc, &config);
Laxman Dewangan62199292012-01-09 20:27:41 +0530486 if (IS_ERR(rdev)) {
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530487 dev_err(tps->dev,
488 "%s(): regulator register failed with err %s\n",
489 __func__, id->name);
Laxman Dewangan62199292012-01-09 20:27:41 +0530490 ret = PTR_ERR(rdev);
491 goto err_init;
492 }
493
494 tps->rdev = rdev;
495 return 0;
496
497err_init:
498 if (gpio_is_valid(tps->vsel1_gpio))
499 gpio_free(tps->vsel1_gpio);
500err_gpio1:
501 if (gpio_is_valid(tps->vsel0_gpio))
502 gpio_free(tps->vsel0_gpio);
503err_gpio0:
Laxman Dewangan62199292012-01-09 20:27:41 +0530504 return ret;
505}
506
507/**
508 * tps62360_remove - tps62360 driver i2c remove handler
509 * @client: i2c driver client device structure
510 *
511 * Unregister TPS driver as an i2c client device driver
512 */
513static int __devexit tps62360_remove(struct i2c_client *client)
514{
515 struct tps62360_chip *tps = i2c_get_clientdata(client);
516
517 if (gpio_is_valid(tps->vsel1_gpio))
518 gpio_free(tps->vsel1_gpio);
519
520 if (gpio_is_valid(tps->vsel0_gpio))
521 gpio_free(tps->vsel0_gpio);
522
523 regulator_unregister(tps->rdev);
Laxman Dewangan62199292012-01-09 20:27:41 +0530524 return 0;
525}
526
527static void tps62360_shutdown(struct i2c_client *client)
528{
529 struct tps62360_chip *tps = i2c_get_clientdata(client);
530 int st;
531
532 if (!tps->en_discharge)
533 return;
534
535 /* Configure the output discharge path */
536 st = regmap_update_bits(tps->regmap, REG_RAMPCTRL, BIT(2), BIT(2));
537 if (st < 0)
Laxman Dewangan2935fb12012-05-08 17:05:58 +0530538 dev_err(tps->dev,
539 "%s(): register %d update failed with err %d\n",
540 __func__, REG_RAMPCTRL, st);
Laxman Dewangan62199292012-01-09 20:27:41 +0530541}
542
543static const struct i2c_device_id tps62360_id[] = {
544 {.name = "tps62360", .driver_data = TPS62360},
545 {.name = "tps62361", .driver_data = TPS62361},
Axel Lind1cf4f62012-04-02 18:19:28 +0800546 {.name = "tps62362", .driver_data = TPS62362},
547 {.name = "tps62363", .driver_data = TPS62363},
Laxman Dewangan62199292012-01-09 20:27:41 +0530548 {},
549};
550
551MODULE_DEVICE_TABLE(i2c, tps62360_id);
552
553static struct i2c_driver tps62360_i2c_driver = {
554 .driver = {
555 .name = "tps62360",
556 .owner = THIS_MODULE,
Laxman Dewangan684ae392012-05-11 12:08:43 +0530557 .of_match_table = of_match_ptr(tps62360_of_match),
Laxman Dewangan62199292012-01-09 20:27:41 +0530558 },
559 .probe = tps62360_probe,
560 .remove = __devexit_p(tps62360_remove),
561 .shutdown = tps62360_shutdown,
562 .id_table = tps62360_id,
563};
564
565static int __init tps62360_init(void)
566{
567 return i2c_add_driver(&tps62360_i2c_driver);
568}
569subsys_initcall(tps62360_init);
570
571static void __exit tps62360_cleanup(void)
572{
573 i2c_del_driver(&tps62360_i2c_driver);
574}
575module_exit(tps62360_cleanup);
576
577MODULE_AUTHOR("Laxman Dewangan <ldewangan@nvidia.com>");
Axel Lind1cf4f62012-04-02 18:19:28 +0800578MODULE_DESCRIPTION("TPS6236x voltage regulator driver");
Laxman Dewangan62199292012-01-09 20:27:41 +0530579MODULE_LICENSE("GPL v2");