blob: 32bf157f48150fd57993bce1dd6a6a7c7d02d516 [file] [log] [blame]
Woogyom Kim2165c8a2012-01-04 08:27:43 +04001/*
Kim, Milof7bae492012-01-26 22:59:08 -08002 * Driver for LP8727 Micro/Mini USB IC with integrated charger
Woogyom Kim2165c8a2012-01-04 08:27:43 +04003 *
Kim, Miloe39b8282012-01-29 17:28:18 -08004 * Copyright (C) 2011 Texas Instruments
Woogyom Kim2165c8a2012-01-04 08:27:43 +04005 * Copyright (C) 2011 National Semiconductor
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12
13#include <linux/module.h>
14#include <linux/slab.h>
15#include <linux/interrupt.h>
16#include <linux/i2c.h>
17#include <linux/power_supply.h>
Kim, Milo1aebb092012-07-03 01:19:03 +000018#include <linux/platform_data/lp8727.h>
Woogyom Kim2165c8a2012-01-04 08:27:43 +040019
Kim, Milo638555d2012-08-31 09:24:09 +000020#define LP8788_NUM_INTREGS 2
Kim, Milo60fd57e2012-08-31 09:23:25 +000021#define DEFAULT_DEBOUNCE_MSEC 270
Woogyom Kim2165c8a2012-01-04 08:27:43 +040022
23/* Registers */
24#define CTRL1 0x1
25#define CTRL2 0x2
26#define SWCTRL 0x3
27#define INT1 0x4
28#define INT2 0x5
29#define STATUS1 0x6
Kim, Milo73368802012-01-26 22:58:51 -080030#define STATUS2 0x7
Woogyom Kim2165c8a2012-01-04 08:27:43 +040031#define CHGCTRL2 0x9
32
33/* CTRL1 register */
34#define CP_EN (1 << 0)
35#define ADC_EN (1 << 1)
36#define ID200_EN (1 << 4)
37
38/* CTRL2 register */
39#define CHGDET_EN (1 << 1)
40#define INT_EN (1 << 6)
41
42/* SWCTRL register */
43#define SW_DM1_DM (0x0 << 0)
44#define SW_DM1_U1 (0x1 << 0)
45#define SW_DM1_HiZ (0x7 << 0)
46#define SW_DP2_DP (0x0 << 3)
47#define SW_DP2_U2 (0x1 << 3)
48#define SW_DP2_HiZ (0x7 << 3)
49
50/* INT1 register */
51#define IDNO (0xF << 0)
52#define VBUS (1 << 4)
53
54/* STATUS1 register */
55#define CHGSTAT (3 << 4)
56#define CHPORT (1 << 6)
57#define DCPORT (1 << 7)
Kim, Milofaaae9b2012-08-31 09:24:37 +000058#define LP8727_STAT_EOC 0x30
Woogyom Kim2165c8a2012-01-04 08:27:43 +040059
60/* STATUS2 register */
61#define TEMP_STAT (3 << 5)
Kim, Milob1ad0792012-08-31 09:24:28 +000062#define TEMP_SHIFT 5
Woogyom Kim2165c8a2012-01-04 08:27:43 +040063
64enum lp8727_dev_id {
65 ID_NONE,
66 ID_TA,
67 ID_DEDICATED_CHG,
68 ID_USB_CHG,
69 ID_USB_DS,
70 ID_MAX,
71};
72
Kim, Milob1ad0792012-08-31 09:24:28 +000073enum lp8727_die_temp {
74 LP8788_TEMP_75C,
75 LP8788_TEMP_95C,
76 LP8788_TEMP_115C,
77 LP8788_TEMP_135C,
78};
79
Woogyom Kim2165c8a2012-01-04 08:27:43 +040080struct lp8727_psy {
81 struct power_supply ac;
82 struct power_supply usb;
83 struct power_supply batt;
84};
85
86struct lp8727_chg {
87 struct device *dev;
88 struct i2c_client *client;
89 struct mutex xfer_lock;
90 struct delayed_work work;
Woogyom Kim2165c8a2012-01-04 08:27:43 +040091 struct lp8727_platform_data *pdata;
92 struct lp8727_psy *psy;
93 struct lp8727_chg_param *chg_parm;
94 enum lp8727_dev_id devid;
Kim, Milo60fd57e2012-08-31 09:23:25 +000095 unsigned long debounce_jiffies;
Kim, Milod71fda02012-08-31 09:23:57 +000096 int irq;
Woogyom Kim2165c8a2012-01-04 08:27:43 +040097};
98
Kim, Milo27aefa32012-01-26 22:58:39 -080099static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400100{
101 s32 ret;
102
103 mutex_lock(&pchg->xfer_lock);
104 ret = i2c_smbus_read_i2c_block_data(pchg->client, reg, len, data);
105 mutex_unlock(&pchg->xfer_lock);
106
107 return (ret != len) ? -EIO : 0;
108}
109
Kim, Milo27aefa32012-01-26 22:58:39 -0800110static inline int lp8727_read_byte(struct lp8727_chg *pchg, u8 reg, u8 *data)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400111{
Kim, Milo27aefa32012-01-26 22:58:39 -0800112 return lp8727_read_bytes(pchg, reg, data, 1);
113}
114
115static int lp8727_write_byte(struct lp8727_chg *pchg, u8 reg, u8 data)
116{
117 int ret;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400118
119 mutex_lock(&pchg->xfer_lock);
Kim, Milo27aefa32012-01-26 22:58:39 -0800120 ret = i2c_smbus_write_byte_data(pchg->client, reg, data);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400121 mutex_unlock(&pchg->xfer_lock);
122
123 return ret;
124}
125
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400126static int lp8727_is_charger_attached(const char *name, int id)
127{
128 if (name) {
129 if (!strcmp(name, "ac"))
130 return (id == ID_TA || id == ID_DEDICATED_CHG) ? 1 : 0;
131 else if (!strcmp(name, "usb"))
132 return (id == ID_USB_CHG) ? 1 : 0;
133 }
134
135 return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0;
136}
137
Kim, Milo7da63342012-01-26 22:58:30 -0800138static int lp8727_init_device(struct lp8727_chg *pchg)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400139{
140 u8 val;
Kim, Milo7da63342012-01-26 22:58:30 -0800141 int ret;
Kim, Milo638555d2012-08-31 09:24:09 +0000142 u8 intstat[LP8788_NUM_INTREGS];
143
144 /* clear interrupts */
145 ret = lp8727_read_bytes(pchg, INT1, intstat, LP8788_NUM_INTREGS);
146 if (ret)
147 return ret;
148
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400149
150 val = ID200_EN | ADC_EN | CP_EN;
Kim, Milo27aefa32012-01-26 22:58:39 -0800151 ret = lp8727_write_byte(pchg, CTRL1, val);
Kim, Milo7da63342012-01-26 22:58:30 -0800152 if (ret)
153 return ret;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400154
155 val = INT_EN | CHGDET_EN;
Kim, Milo27aefa32012-01-26 22:58:39 -0800156 ret = lp8727_write_byte(pchg, CTRL2, val);
Kim, Milo7da63342012-01-26 22:58:30 -0800157 if (ret)
158 return ret;
159
160 return 0;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400161}
162
163static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg)
164{
165 u8 val;
Kim, Milo27aefa32012-01-26 22:58:39 -0800166 lp8727_read_byte(pchg, STATUS1, &val);
Kim, Milo73368802012-01-26 22:58:51 -0800167 return val & DCPORT;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400168}
169
170static int lp8727_is_usb_charger(struct lp8727_chg *pchg)
171{
172 u8 val;
Kim, Milo27aefa32012-01-26 22:58:39 -0800173 lp8727_read_byte(pchg, STATUS1, &val);
Kim, Milo73368802012-01-26 22:58:51 -0800174 return val & CHPORT;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400175}
176
177static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw)
178{
Kim, Milo27aefa32012-01-26 22:58:39 -0800179 lp8727_write_byte(pchg, SWCTRL, sw);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400180}
181
182static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin)
183{
Kim, Milo318cb382012-08-31 09:23:12 +0000184 struct lp8727_platform_data *pdata = pchg->pdata;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400185 u8 devid = ID_NONE;
186 u8 swctrl = SW_DM1_HiZ | SW_DP2_HiZ;
187
188 switch (id) {
189 case 0x5:
190 devid = ID_TA;
Kim, Milo318cb382012-08-31 09:23:12 +0000191 pchg->chg_parm = pdata ? pdata->ac : NULL;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400192 break;
193 case 0xB:
194 if (lp8727_is_dedicated_charger(pchg)) {
Kim, Milo318cb382012-08-31 09:23:12 +0000195 pchg->chg_parm = pdata ? pdata->ac : NULL;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400196 devid = ID_DEDICATED_CHG;
197 } else if (lp8727_is_usb_charger(pchg)) {
Kim, Milo318cb382012-08-31 09:23:12 +0000198 pchg->chg_parm = pdata ? pdata->usb : NULL;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400199 devid = ID_USB_CHG;
200 swctrl = SW_DM1_DM | SW_DP2_DP;
201 } else if (vbusin) {
202 devid = ID_USB_DS;
203 swctrl = SW_DM1_DM | SW_DP2_DP;
204 }
205 break;
206 default:
207 devid = ID_NONE;
208 pchg->chg_parm = NULL;
209 break;
210 }
211
212 pchg->devid = devid;
213 lp8727_ctrl_switch(pchg, swctrl);
214}
215
216static void lp8727_enable_chgdet(struct lp8727_chg *pchg)
217{
218 u8 val;
219
Kim, Milo27aefa32012-01-26 22:58:39 -0800220 lp8727_read_byte(pchg, CTRL2, &val);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400221 val |= CHGDET_EN;
Kim, Milo27aefa32012-01-26 22:58:39 -0800222 lp8727_write_byte(pchg, CTRL2, val);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400223}
224
225static void lp8727_delayed_func(struct work_struct *_work)
226{
227 u8 intstat[2], idno, vbus;
228 struct lp8727_chg *pchg =
229 container_of(_work, struct lp8727_chg, work.work);
230
Kim, Milo27aefa32012-01-26 22:58:39 -0800231 if (lp8727_read_bytes(pchg, INT1, intstat, 2)) {
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400232 dev_err(pchg->dev, "can not read INT registers\n");
233 return;
234 }
235
236 idno = intstat[0] & IDNO;
237 vbus = intstat[0] & VBUS;
238
239 lp8727_id_detection(pchg, idno, vbus);
240 lp8727_enable_chgdet(pchg);
241
242 power_supply_changed(&pchg->psy->ac);
243 power_supply_changed(&pchg->psy->usb);
244 power_supply_changed(&pchg->psy->batt);
245}
246
247static irqreturn_t lp8727_isr_func(int irq, void *ptr)
248{
249 struct lp8727_chg *pchg = ptr;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400250
Kim, Milo2a092582012-08-31 09:23:41 +0000251 schedule_delayed_work(&pchg->work, pchg->debounce_jiffies);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400252 return IRQ_HANDLED;
253}
254
Kim, Milod71fda02012-08-31 09:23:57 +0000255static int lp8727_setup_irq(struct lp8727_chg *pchg)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400256{
Kim, Milod71fda02012-08-31 09:23:57 +0000257 int ret;
258 int irq = pchg->client->irq;
Kim, Milo60fd57e2012-08-31 09:23:25 +0000259 unsigned delay_msec = pchg->pdata ? pchg->pdata->debounce_msec :
260 DEFAULT_DEBOUNCE_MSEC;
261
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400262 INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func);
263
Kim, Milod71fda02012-08-31 09:23:57 +0000264 if (irq <= 0) {
265 dev_warn(pchg->dev, "invalid irq number: %d\n", irq);
266 return 0;
267 }
268
269 ret = request_threaded_irq(irq, NULL, lp8727_isr_func,
270 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
271 "lp8727_irq", pchg);
272
273 if (ret)
274 return ret;
275
276 pchg->irq = irq;
Kim, Milo60fd57e2012-08-31 09:23:25 +0000277 pchg->debounce_jiffies = msecs_to_jiffies(delay_msec);
278
Kim, Milod71fda02012-08-31 09:23:57 +0000279 return 0;
280}
281
282static void lp8727_release_irq(struct lp8727_chg *pchg)
283{
284 cancel_delayed_work_sync(&pchg->work);
285
286 if (pchg->irq)
287 free_irq(pchg->irq, pchg);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400288}
289
290static enum power_supply_property lp8727_charger_prop[] = {
291 POWER_SUPPLY_PROP_ONLINE,
292};
293
294static enum power_supply_property lp8727_battery_prop[] = {
295 POWER_SUPPLY_PROP_STATUS,
296 POWER_SUPPLY_PROP_HEALTH,
297 POWER_SUPPLY_PROP_PRESENT,
298 POWER_SUPPLY_PROP_VOLTAGE_NOW,
299 POWER_SUPPLY_PROP_CAPACITY,
300 POWER_SUPPLY_PROP_TEMP,
301};
302
303static char *battery_supplied_to[] = {
304 "main_batt",
305};
306
307static int lp8727_charger_get_property(struct power_supply *psy,
308 enum power_supply_property psp,
309 union power_supply_propval *val)
310{
311 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent);
312
Kim, Miloce09aff2012-01-04 09:03:18 +0400313 if (psp == POWER_SUPPLY_PROP_ONLINE)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400314 val->intval = lp8727_is_charger_attached(psy->name,
315 pchg->devid);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400316
317 return 0;
318}
319
Kim, Milob1ad0792012-08-31 09:24:28 +0000320static bool lp8727_is_high_temperature(enum lp8727_die_temp temp)
321{
322 switch (temp) {
323 case LP8788_TEMP_95C:
324 case LP8788_TEMP_115C:
325 case LP8788_TEMP_135C:
326 return true;
327 default:
328 return false;
329 }
330}
331
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400332static int lp8727_battery_get_property(struct power_supply *psy,
333 enum power_supply_property psp,
334 union power_supply_propval *val)
335{
336 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent);
Kim, Milo318cb382012-08-31 09:23:12 +0000337 struct lp8727_platform_data *pdata = pchg->pdata;
Kim, Milob1ad0792012-08-31 09:24:28 +0000338 enum lp8727_die_temp temp;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400339 u8 read;
340
341 switch (psp) {
342 case POWER_SUPPLY_PROP_STATUS:
343 if (lp8727_is_charger_attached(psy->name, pchg->devid)) {
Kim, Milo27aefa32012-01-26 22:58:39 -0800344 lp8727_read_byte(pchg, STATUS1, &read);
Kim, Milofaaae9b2012-08-31 09:24:37 +0000345
346 val->intval = (read & CHGSTAT) == LP8727_STAT_EOC ?
347 POWER_SUPPLY_STATUS_FULL :
348 POWER_SUPPLY_STATUS_CHARGING;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400349 } else {
350 val->intval = POWER_SUPPLY_STATUS_DISCHARGING;
351 }
352 break;
353 case POWER_SUPPLY_PROP_HEALTH:
Kim, Milo27aefa32012-01-26 22:58:39 -0800354 lp8727_read_byte(pchg, STATUS2, &read);
Kim, Milob1ad0792012-08-31 09:24:28 +0000355 temp = (read & TEMP_STAT) >> TEMP_SHIFT;
356
357 val->intval = lp8727_is_high_temperature(temp) ?
358 POWER_SUPPLY_HEALTH_OVERHEAT :
359 POWER_SUPPLY_HEALTH_GOOD;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400360 break;
361 case POWER_SUPPLY_PROP_PRESENT:
Kim, Milo318cb382012-08-31 09:23:12 +0000362 if (!pdata)
363 return -EINVAL;
364
365 if (pdata->get_batt_present)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400366 val->intval = pchg->pdata->get_batt_present();
367 break;
368 case POWER_SUPPLY_PROP_VOLTAGE_NOW:
Kim, Milo318cb382012-08-31 09:23:12 +0000369 if (!pdata)
370 return -EINVAL;
371
372 if (pdata->get_batt_level)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400373 val->intval = pchg->pdata->get_batt_level();
374 break;
375 case POWER_SUPPLY_PROP_CAPACITY:
Kim, Milo318cb382012-08-31 09:23:12 +0000376 if (!pdata)
377 return -EINVAL;
378
379 if (pdata->get_batt_capacity)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400380 val->intval = pchg->pdata->get_batt_capacity();
381 break;
382 case POWER_SUPPLY_PROP_TEMP:
Kim, Milo318cb382012-08-31 09:23:12 +0000383 if (!pdata)
384 return -EINVAL;
385
386 if (pdata->get_batt_temp)
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400387 val->intval = pchg->pdata->get_batt_temp();
388 break;
389 default:
390 break;
391 }
392
393 return 0;
394}
395
396static void lp8727_charger_changed(struct power_supply *psy)
397{
398 struct lp8727_chg *pchg = dev_get_drvdata(psy->dev->parent);
399 u8 val;
400 u8 eoc_level, ichg;
401
402 if (lp8727_is_charger_attached(psy->name, pchg->devid)) {
403 if (pchg->chg_parm) {
404 eoc_level = pchg->chg_parm->eoc_level;
405 ichg = pchg->chg_parm->ichg;
406 val = (ichg << 4) | eoc_level;
Kim, Milo27aefa32012-01-26 22:58:39 -0800407 lp8727_write_byte(pchg, CHGCTRL2, val);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400408 }
409 }
410}
411
412static int lp8727_register_psy(struct lp8727_chg *pchg)
413{
414 struct lp8727_psy *psy;
415
Kim, Milo74727c52012-08-31 09:22:46 +0000416 psy = devm_kzalloc(pchg->dev, sizeof(*psy), GFP_KERNEL);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400417 if (!psy)
Devendra Naga6297b5e2012-07-29 23:31:55 +0545418 return -ENOMEM;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400419
420 pchg->psy = psy;
421
422 psy->ac.name = "ac";
423 psy->ac.type = POWER_SUPPLY_TYPE_MAINS;
424 psy->ac.properties = lp8727_charger_prop;
425 psy->ac.num_properties = ARRAY_SIZE(lp8727_charger_prop);
426 psy->ac.get_property = lp8727_charger_get_property;
427 psy->ac.supplied_to = battery_supplied_to;
428 psy->ac.num_supplicants = ARRAY_SIZE(battery_supplied_to);
429
430 if (power_supply_register(pchg->dev, &psy->ac))
Devendra Naga6297b5e2012-07-29 23:31:55 +0545431 goto err_psy_ac;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400432
433 psy->usb.name = "usb";
434 psy->usb.type = POWER_SUPPLY_TYPE_USB;
435 psy->usb.properties = lp8727_charger_prop;
436 psy->usb.num_properties = ARRAY_SIZE(lp8727_charger_prop);
437 psy->usb.get_property = lp8727_charger_get_property;
438 psy->usb.supplied_to = battery_supplied_to;
439 psy->usb.num_supplicants = ARRAY_SIZE(battery_supplied_to);
440
441 if (power_supply_register(pchg->dev, &psy->usb))
Devendra Naga6297b5e2012-07-29 23:31:55 +0545442 goto err_psy_usb;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400443
444 psy->batt.name = "main_batt";
445 psy->batt.type = POWER_SUPPLY_TYPE_BATTERY;
446 psy->batt.properties = lp8727_battery_prop;
447 psy->batt.num_properties = ARRAY_SIZE(lp8727_battery_prop);
448 psy->batt.get_property = lp8727_battery_get_property;
449 psy->batt.external_power_changed = lp8727_charger_changed;
450
451 if (power_supply_register(pchg->dev, &psy->batt))
Devendra Naga6297b5e2012-07-29 23:31:55 +0545452 goto err_psy_batt;
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400453
454 return 0;
455
Devendra Naga6297b5e2012-07-29 23:31:55 +0545456err_psy_batt:
457 power_supply_unregister(&psy->usb);
458err_psy_usb:
459 power_supply_unregister(&psy->ac);
460err_psy_ac:
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400461 return -EPERM;
462}
463
464static void lp8727_unregister_psy(struct lp8727_chg *pchg)
465{
466 struct lp8727_psy *psy = pchg->psy;
467
Kim, Miloce09aff2012-01-04 09:03:18 +0400468 if (!psy)
469 return;
470
471 power_supply_unregister(&psy->ac);
472 power_supply_unregister(&psy->usb);
473 power_supply_unregister(&psy->batt);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400474}
475
476static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id)
477{
478 struct lp8727_chg *pchg;
479 int ret;
480
Kim, Milo998a8e72011-11-17 21:43:06 -0800481 if (!i2c_check_functionality(cl->adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
482 return -EIO;
483
Kim, Milo74727c52012-08-31 09:22:46 +0000484 pchg = devm_kzalloc(&cl->dev, sizeof(*pchg), GFP_KERNEL);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400485 if (!pchg)
486 return -ENOMEM;
487
488 pchg->client = cl;
489 pchg->dev = &cl->dev;
490 pchg->pdata = cl->dev.platform_data;
491 i2c_set_clientdata(cl, pchg);
492
493 mutex_init(&pchg->xfer_lock);
494
Kim, Milo7da63342012-01-26 22:58:30 -0800495 ret = lp8727_init_device(pchg);
496 if (ret) {
497 dev_err(pchg->dev, "i2c communication err: %d", ret);
Kim, Milofb9adc52012-08-31 09:23:03 +0000498 return ret;
Kim, Milo7da63342012-01-26 22:58:30 -0800499 }
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400500
501 ret = lp8727_register_psy(pchg);
Kim, Milo7da63342012-01-26 22:58:30 -0800502 if (ret) {
503 dev_err(pchg->dev, "power supplies register err: %d", ret);
Kim, Milofb9adc52012-08-31 09:23:03 +0000504 return ret;
505 }
506
Kim, Milod71fda02012-08-31 09:23:57 +0000507 ret = lp8727_setup_irq(pchg);
Kim, Milofb9adc52012-08-31 09:23:03 +0000508 if (ret) {
509 dev_err(pchg->dev, "irq handler err: %d", ret);
510 lp8727_unregister_psy(pchg);
511 return ret;
Kim, Milo7da63342012-01-26 22:58:30 -0800512 }
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400513
514 return 0;
515}
516
517static int __devexit lp8727_remove(struct i2c_client *cl)
518{
519 struct lp8727_chg *pchg = i2c_get_clientdata(cl);
520
Kim, Milod71fda02012-08-31 09:23:57 +0000521 lp8727_release_irq(pchg);
Kim, Milofb9adc52012-08-31 09:23:03 +0000522 lp8727_unregister_psy(pchg);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400523 return 0;
524}
525
526static const struct i2c_device_id lp8727_ids[] = {
527 {"lp8727", 0},
Axel Lin455a0e22012-01-16 13:48:20 +0800528 { }
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400529};
Axel Line2c5f7d2012-01-12 20:45:02 +0800530MODULE_DEVICE_TABLE(i2c, lp8727_ids);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400531
532static struct i2c_driver lp8727_driver = {
533 .driver = {
534 .name = "lp8727",
535 },
536 .probe = lp8727_probe,
537 .remove = __devexit_p(lp8727_remove),
538 .id_table = lp8727_ids,
539};
Axel Lin5ff92e72012-01-21 14:42:54 +0800540module_i2c_driver(lp8727_driver);
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400541
Kim, Miloe39b8282012-01-29 17:28:18 -0800542MODULE_DESCRIPTION("TI/National Semiconductor LP8727 charger driver");
Kim, Milo73368802012-01-26 22:58:51 -0800543MODULE_AUTHOR("Woogyom Kim <milo.kim@ti.com>, "
544 "Daniel Jeong <daniel.jeong@ti.com>");
Woogyom Kim2165c8a2012-01-04 08:27:43 +0400545MODULE_LICENSE("GPL");