diff options
author | Kim, Milo <Milo.Kim@ti.com> | 2012-01-27 01:58:30 -0500 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-03-26 12:40:54 -0400 |
commit | 7da6334e73fe3c0579d8c6a56001336a430a5d99 (patch) | |
tree | 3fd627bfeb4a781d7217f3cb40264678b1f24e97 /drivers/power | |
parent | e39b828f5355e41a8fd24f413fb9dfb81d808397 (diff) |
lp8727_charger: Add error check routine on probe()
Add error checking on initializing registers and interrupt handler.
Initializing registers - lp8727_init_device()
: check i2c error during probing the driver.
Initializing interrupt handler - lp8727_intr_config()
: check an error on creating the irq thread.
If an error occurs on probing lp8727 driver, allocated lp8727 driver memory is freed.
Signed-off-by: Milo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
Diffstat (limited to 'drivers/power')
-rw-r--r-- | drivers/power/lp8727_charger.c | 57 |
1 files changed, 39 insertions, 18 deletions
diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index d23a3bcc74d9..6239bd7bcc25 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c | |||
@@ -138,17 +138,22 @@ static int lp8727_is_charger_attached(const char *name, int id) | |||
138 | return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0; | 138 | return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0; |
139 | } | 139 | } |
140 | 140 | ||
141 | static void lp8727_init_device(struct lp8727_chg *pchg) | 141 | static int lp8727_init_device(struct lp8727_chg *pchg) |
142 | { | 142 | { |
143 | u8 val; | 143 | u8 val; |
144 | int ret; | ||
144 | 145 | ||
145 | val = ID200_EN | ADC_EN | CP_EN; | 146 | val = ID200_EN | ADC_EN | CP_EN; |
146 | if (lp8727_i2c_write_byte(pchg, CTRL1, &val)) | 147 | ret = lp8727_i2c_write_byte(pchg, CTRL1, &val); |
147 | dev_err(pchg->dev, "i2c write err : addr=0x%.2x\n", CTRL1); | 148 | if (ret) |
149 | return ret; | ||
148 | 150 | ||
149 | val = INT_EN | CHGDET_EN; | 151 | val = INT_EN | CHGDET_EN; |
150 | if (lp8727_i2c_write_byte(pchg, CTRL2, &val)) | 152 | ret = lp8727_i2c_write_byte(pchg, CTRL2, &val); |
151 | dev_err(pchg->dev, "i2c write err : addr=0x%.2x\n", CTRL2); | 153 | if (ret) |
154 | return ret; | ||
155 | |||
156 | return 0; | ||
152 | } | 157 | } |
153 | 158 | ||
154 | static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) | 159 | static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) |
@@ -245,20 +250,22 @@ static irqreturn_t lp8727_isr_func(int irq, void *ptr) | |||
245 | return IRQ_HANDLED; | 250 | return IRQ_HANDLED; |
246 | } | 251 | } |
247 | 252 | ||
248 | static void lp8727_intr_config(struct lp8727_chg *pchg) | 253 | static int lp8727_intr_config(struct lp8727_chg *pchg) |
249 | { | 254 | { |
250 | INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); | 255 | INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); |
251 | 256 | ||
252 | pchg->irqthread = create_singlethread_workqueue("lp8727-irqthd"); | 257 | pchg->irqthread = create_singlethread_workqueue("lp8727-irqthd"); |
253 | if (!pchg->irqthread) | 258 | if (!pchg->irqthread) { |
254 | dev_err(pchg->dev, "can not create thread for lp8727\n"); | 259 | dev_err(pchg->dev, "can not create thread for lp8727\n"); |
255 | 260 | return -ENOMEM; | |
256 | if (request_threaded_irq(pchg->client->irq, | ||
257 | NULL, | ||
258 | lp8727_isr_func, | ||
259 | IRQF_TRIGGER_FALLING, "lp8727_irq", pchg)) { | ||
260 | dev_err(pchg->dev, "lp8727 irq can not be registered\n"); | ||
261 | } | 261 | } |
262 | |||
263 | return request_threaded_irq(pchg->client->irq, | ||
264 | NULL, | ||
265 | lp8727_isr_func, | ||
266 | IRQF_TRIGGER_FALLING, | ||
267 | "lp8727_irq", | ||
268 | pchg); | ||
262 | } | 269 | } |
263 | 270 | ||
264 | static enum power_supply_property lp8727_charger_prop[] = { | 271 | static enum power_supply_property lp8727_charger_prop[] = { |
@@ -440,15 +447,29 @@ static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id) | |||
440 | 447 | ||
441 | mutex_init(&pchg->xfer_lock); | 448 | mutex_init(&pchg->xfer_lock); |
442 | 449 | ||
443 | lp8727_init_device(pchg); | 450 | ret = lp8727_init_device(pchg); |
444 | lp8727_intr_config(pchg); | 451 | if (ret) { |
452 | dev_err(pchg->dev, "i2c communication err: %d", ret); | ||
453 | goto error; | ||
454 | } | ||
455 | |||
456 | ret = lp8727_intr_config(pchg); | ||
457 | if (ret) { | ||
458 | dev_err(pchg->dev, "irq handler err: %d", ret); | ||
459 | goto error; | ||
460 | } | ||
445 | 461 | ||
446 | ret = lp8727_register_psy(pchg); | 462 | ret = lp8727_register_psy(pchg); |
447 | if (ret) | 463 | if (ret) { |
448 | dev_err(pchg->dev, | 464 | dev_err(pchg->dev, "power supplies register err: %d", ret); |
449 | "can not register power supplies. err=%d", ret); | 465 | goto error; |
466 | } | ||
450 | 467 | ||
451 | return 0; | 468 | return 0; |
469 | |||
470 | error: | ||
471 | kfree(pchg); | ||
472 | return ret; | ||
452 | } | 473 | } |
453 | 474 | ||
454 | static int __devexit lp8727_remove(struct i2c_client *cl) | 475 | static int __devexit lp8727_remove(struct i2c_client *cl) |