aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power
diff options
context:
space:
mode:
authorKim, Milo <Milo.Kim@ti.com>2012-08-31 05:23:57 -0400
committerAnton Vorontsov <anton.vorontsov@linaro.org>2012-09-20 21:00:08 -0400
commitd71fda01610269e3aaedd451f8d3e34cdf550036 (patch)
tree0213d1f047f26b721226cab4daa90b51a4794011 /drivers/power
parent2a0925827be53db6252afadc79c657b14638ff4a (diff)
lp8727_charger: Clean up the interrupt handler
For better understanding, function name is changed. (lp8727_intr_config() is replaced with lp8727_setup_irq().) The private IRQ number is set when the IRQ is allocated successfully. This data is used for releasing the IRQ on unloading the driver. Even the IRQ number is not defined, the driver should be operated. In this case, just return as 0. In additional function lp8727_release_irq(), the workqueue is canceled and the allocated IRQ is released. 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.c37
1 files changed, 28 insertions, 9 deletions
diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c
index c33532bbb9c7..134ed5c7dde5 100644
--- a/drivers/power/lp8727_charger.c
+++ b/drivers/power/lp8727_charger.c
@@ -90,6 +90,7 @@ struct lp8727_chg {
90 struct lp8727_chg_param *chg_parm; 90 struct lp8727_chg_param *chg_parm;
91 enum lp8727_dev_id devid; 91 enum lp8727_dev_id devid;
92 unsigned long debounce_jiffies; 92 unsigned long debounce_jiffies;
93 int irq;
93}; 94};
94 95
95static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) 96static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len)
@@ -241,21 +242,39 @@ static irqreturn_t lp8727_isr_func(int irq, void *ptr)
241 return IRQ_HANDLED; 242 return IRQ_HANDLED;
242} 243}
243 244
244static int lp8727_intr_config(struct lp8727_chg *pchg) 245static int lp8727_setup_irq(struct lp8727_chg *pchg)
245{ 246{
247 int ret;
248 int irq = pchg->client->irq;
246 unsigned delay_msec = pchg->pdata ? pchg->pdata->debounce_msec : 249 unsigned delay_msec = pchg->pdata ? pchg->pdata->debounce_msec :
247 DEFAULT_DEBOUNCE_MSEC; 250 DEFAULT_DEBOUNCE_MSEC;
248 251
249 INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); 252 INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func);
250 253
251 pchg->debounce_jiffies = msecs_to_jiffies(delay_msec); 254 if (irq <= 0) {
255 dev_warn(pchg->dev, "invalid irq number: %d\n", irq);
256 return 0;
257 }
252 258
253 return request_threaded_irq(pchg->client->irq, 259 ret = request_threaded_irq(irq, NULL, lp8727_isr_func,
254 NULL,
255 lp8727_isr_func,
256 IRQF_TRIGGER_FALLING | IRQF_ONESHOT, 260 IRQF_TRIGGER_FALLING | IRQF_ONESHOT,
257 "lp8727_irq", 261 "lp8727_irq", pchg);
258 pchg); 262
263 if (ret)
264 return ret;
265
266 pchg->irq = irq;
267 pchg->debounce_jiffies = msecs_to_jiffies(delay_msec);
268
269 return 0;
270}
271
272static void lp8727_release_irq(struct lp8727_chg *pchg)
273{
274 cancel_delayed_work_sync(&pchg->work);
275
276 if (pchg->irq)
277 free_irq(pchg->irq, pchg);
259} 278}
260 279
261static enum power_supply_property lp8727_charger_prop[] = { 280static enum power_supply_property lp8727_charger_prop[] = {
@@ -462,7 +481,7 @@ static int lp8727_probe(struct i2c_client *cl, const struct i2c_device_id *id)
462 return ret; 481 return ret;
463 } 482 }
464 483
465 ret = lp8727_intr_config(pchg); 484 ret = lp8727_setup_irq(pchg);
466 if (ret) { 485 if (ret) {
467 dev_err(pchg->dev, "irq handler err: %d", ret); 486 dev_err(pchg->dev, "irq handler err: %d", ret);
468 lp8727_unregister_psy(pchg); 487 lp8727_unregister_psy(pchg);
@@ -476,7 +495,7 @@ static int __devexit lp8727_remove(struct i2c_client *cl)
476{ 495{
477 struct lp8727_chg *pchg = i2c_get_clientdata(cl); 496 struct lp8727_chg *pchg = i2c_get_clientdata(cl);
478 497
479 free_irq(pchg->client->irq, pchg); 498 lp8727_release_irq(pchg);
480 lp8727_unregister_psy(pchg); 499 lp8727_unregister_psy(pchg);
481 return 0; 500 return 0;
482} 501}