From e39b828f5355e41a8fd24f413fb9dfb81d808397 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Sun, 29 Jan 2012 17:28:18 -0800 Subject: lp8727_charger: Add company name and description Add 'Texas Instruments' because TI acquired National semiconductor at 2011. And the driver information is added in the header file. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index c53dd1292f8..d23a3bcc74d 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -1,6 +1,7 @@ /* * Driver for LP8727 Micro/Mini USB IC with intergrated charger * + * Copyright (C) 2011 Texas Instruments * Copyright (C) 2011 National Semiconductor * * This program is free software; you can redistribute it and/or modify @@ -489,7 +490,7 @@ static void __exit lp8727_exit(void) module_init(lp8727_init); module_exit(lp8727_exit); -MODULE_DESCRIPTION("National Semiconductor LP8727 charger driver"); +MODULE_DESCRIPTION("TI/National Semiconductor LP8727 charger driver"); MODULE_AUTHOR ("Woogyom Kim , Daniel Jeong "); MODULE_LICENSE("GPL"); -- cgit v1.2.3-70-g09d2 From 7da6334e73fe3c0579d8c6a56001336a430a5d99 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 26 Jan 2012 22:58:30 -0800 Subject: 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 Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 57 +++++++++++++++++++++++++++++------------- 1 file changed, 39 insertions(+), 18 deletions(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index d23a3bcc74d..6239bd7bcc2 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) return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0; } -static void lp8727_init_device(struct lp8727_chg *pchg) +static int lp8727_init_device(struct lp8727_chg *pchg) { u8 val; + int ret; val = ID200_EN | ADC_EN | CP_EN; - if (lp8727_i2c_write_byte(pchg, CTRL1, &val)) - dev_err(pchg->dev, "i2c write err : addr=0x%.2x\n", CTRL1); + ret = lp8727_i2c_write_byte(pchg, CTRL1, &val); + if (ret) + return ret; val = INT_EN | CHGDET_EN; - if (lp8727_i2c_write_byte(pchg, CTRL2, &val)) - dev_err(pchg->dev, "i2c write err : addr=0x%.2x\n", CTRL2); + ret = lp8727_i2c_write_byte(pchg, CTRL2, &val); + if (ret) + return ret; + + return 0; } static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) @@ -245,20 +250,22 @@ static irqreturn_t lp8727_isr_func(int irq, void *ptr) return IRQ_HANDLED; } -static void lp8727_intr_config(struct lp8727_chg *pchg) +static int lp8727_intr_config(struct lp8727_chg *pchg) { INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); pchg->irqthread = create_singlethread_workqueue("lp8727-irqthd"); - if (!pchg->irqthread) + if (!pchg->irqthread) { dev_err(pchg->dev, "can not create thread for lp8727\n"); - - if (request_threaded_irq(pchg->client->irq, - NULL, - lp8727_isr_func, - IRQF_TRIGGER_FALLING, "lp8727_irq", pchg)) { - dev_err(pchg->dev, "lp8727 irq can not be registered\n"); + return -ENOMEM; } + + return request_threaded_irq(pchg->client->irq, + NULL, + lp8727_isr_func, + IRQF_TRIGGER_FALLING, + "lp8727_irq", + pchg); } 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) mutex_init(&pchg->xfer_lock); - lp8727_init_device(pchg); - lp8727_intr_config(pchg); + ret = lp8727_init_device(pchg); + if (ret) { + dev_err(pchg->dev, "i2c communication err: %d", ret); + goto error; + } + + ret = lp8727_intr_config(pchg); + if (ret) { + dev_err(pchg->dev, "irq handler err: %d", ret); + goto error; + } ret = lp8727_register_psy(pchg); - if (ret) - dev_err(pchg->dev, - "can not register power supplies. err=%d", ret); + if (ret) { + dev_err(pchg->dev, "power supplies register err: %d", ret); + goto error; + } return 0; + +error: + kfree(pchg); + return ret; } static int __devexit lp8727_remove(struct i2c_client *cl) -- cgit v1.2.3-70-g09d2 From 27aefa3b7d8b1c37e0bc21cbd0ce3c93bdf163ca Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 26 Jan 2012 22:58:39 -0800 Subject: lp8727_charger: Change i2c functions On writing single byte via i2c, use i2c_smbus_write_byte_data() rather than i2c_smbus_write_i2c_block_data(). Name changes : lp8727_i2c_read() -> lp8727_read_bytes() lp8727_i2c_write() -> removed lp8727_i2c_read_byte() -> lp8727_read_byte() lp8727_i2c_write_byte() -> lp8727_write_byte() Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 48 ++++++++++++++++++------------------------ 1 file changed, 20 insertions(+), 28 deletions(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 6239bd7bcc2..1e8a98b29d8 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -92,7 +92,7 @@ struct lp8727_chg { enum lp8727_dev_id devid; }; -static int lp8727_i2c_read(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) +static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) { s32 ret; @@ -103,29 +103,22 @@ static int lp8727_i2c_read(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) return (ret != len) ? -EIO : 0; } -static int lp8727_i2c_write(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) +static inline int lp8727_read_byte(struct lp8727_chg *pchg, u8 reg, u8 *data) { - s32 ret; + return lp8727_read_bytes(pchg, reg, data, 1); +} + +static int lp8727_write_byte(struct lp8727_chg *pchg, u8 reg, u8 data) +{ + int ret; mutex_lock(&pchg->xfer_lock); - ret = i2c_smbus_write_i2c_block_data(pchg->client, reg, len, data); + ret = i2c_smbus_write_byte_data(pchg->client, reg, data); mutex_unlock(&pchg->xfer_lock); return ret; } -static inline int lp8727_i2c_read_byte(struct lp8727_chg *pchg, u8 reg, - u8 *data) -{ - return lp8727_i2c_read(pchg, reg, data, 1); -} - -static inline int lp8727_i2c_write_byte(struct lp8727_chg *pchg, u8 reg, - u8 *data) -{ - return lp8727_i2c_write(pchg, reg, data, 1); -} - static int lp8727_is_charger_attached(const char *name, int id) { if (name) { @@ -144,12 +137,12 @@ static int lp8727_init_device(struct lp8727_chg *pchg) int ret; val = ID200_EN | ADC_EN | CP_EN; - ret = lp8727_i2c_write_byte(pchg, CTRL1, &val); + ret = lp8727_write_byte(pchg, CTRL1, val); if (ret) return ret; val = INT_EN | CHGDET_EN; - ret = lp8727_i2c_write_byte(pchg, CTRL2, &val); + ret = lp8727_write_byte(pchg, CTRL2, val); if (ret) return ret; @@ -159,21 +152,20 @@ static int lp8727_init_device(struct lp8727_chg *pchg) static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) { u8 val; - lp8727_i2c_read_byte(pchg, STATUS1, &val); + lp8727_read_byte(pchg, STATUS1, &val); return (val & DCPORT); } static int lp8727_is_usb_charger(struct lp8727_chg *pchg) { u8 val; - lp8727_i2c_read_byte(pchg, STATUS1, &val); + lp8727_read_byte(pchg, STATUS1, &val); return (val & CHPORT); } static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) { - u8 val = sw; - lp8727_i2c_write_byte(pchg, SWCTRL, &val); + lp8727_write_byte(pchg, SWCTRL, sw); } static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin) @@ -213,9 +205,9 @@ static void lp8727_enable_chgdet(struct lp8727_chg *pchg) { u8 val; - lp8727_i2c_read_byte(pchg, CTRL2, &val); + lp8727_read_byte(pchg, CTRL2, &val); val |= CHGDET_EN; - lp8727_i2c_write_byte(pchg, CTRL2, &val); + lp8727_write_byte(pchg, CTRL2, val); } static void lp8727_delayed_func(struct work_struct *_work) @@ -224,7 +216,7 @@ static void lp8727_delayed_func(struct work_struct *_work) struct lp8727_chg *pchg = container_of(_work, struct lp8727_chg, work.work); - if (lp8727_i2c_read(pchg, INT1, intstat, 2)) { + if (lp8727_read_bytes(pchg, INT1, intstat, 2)) { dev_err(pchg->dev, "can not read INT registers\n"); return; } @@ -308,7 +300,7 @@ static int lp8727_battery_get_property(struct power_supply *psy, switch (psp) { case POWER_SUPPLY_PROP_STATUS: if (lp8727_is_charger_attached(psy->name, pchg->devid)) { - lp8727_i2c_read_byte(pchg, STATUS1, &read); + lp8727_read_byte(pchg, STATUS1, &read); if (((read & CHGSTAT) >> 4) == EOC) val->intval = POWER_SUPPLY_STATUS_FULL; else @@ -318,7 +310,7 @@ static int lp8727_battery_get_property(struct power_supply *psy, } break; case POWER_SUPPLY_PROP_HEALTH: - lp8727_i2c_read_byte(pchg, STATUS2, &read); + lp8727_read_byte(pchg, STATUS2, &read); read = (read & TEMP_STAT) >> 5; if (read >= 0x1 && read <= 0x3) val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; @@ -359,7 +351,7 @@ static void lp8727_charger_changed(struct power_supply *psy) eoc_level = pchg->chg_parm->eoc_level; ichg = pchg->chg_parm->ichg; val = (ichg << 4) | eoc_level; - lp8727_i2c_write_byte(pchg, CHGCTRL2, &val); + lp8727_write_byte(pchg, CHGCTRL2, val); } } } -- cgit v1.2.3-70-g09d2 From 7336880e3d73ee38b0c2bb99674e7e79d87dd43e Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 26 Jan 2012 22:58:51 -0800 Subject: lp8727_charger: Fix wrong code style Definition of STATUS2 : remove space before tabs. Return code of lp8727_is_dedicated_charger(), lp8727_is_usb_charger() : remove parentheses when return is not a function. MODULE_AUTHOR section : remove space at the start of a line. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 1e8a98b29d8..d5aab54eda1 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -26,7 +26,7 @@ #define INT1 0x4 #define INT2 0x5 #define STATUS1 0x6 -#define STATUS2 0x7 +#define STATUS2 0x7 #define CHGCTRL2 0x9 /* CTRL1 register */ @@ -153,14 +153,14 @@ static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) { u8 val; lp8727_read_byte(pchg, STATUS1, &val); - return (val & DCPORT); + return val & DCPORT; } static int lp8727_is_usb_charger(struct lp8727_chg *pchg) { u8 val; lp8727_read_byte(pchg, STATUS1, &val); - return (val & CHPORT); + return val & CHPORT; } static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) @@ -504,6 +504,6 @@ module_init(lp8727_init); module_exit(lp8727_exit); MODULE_DESCRIPTION("TI/National Semiconductor LP8727 charger driver"); -MODULE_AUTHOR - ("Woogyom Kim , Daniel Jeong "); +MODULE_AUTHOR("Woogyom Kim , " + "Daniel Jeong "); MODULE_LICENSE("GPL"); -- cgit v1.2.3-70-g09d2 From f7bae49aa1247a195a3fe4235edf6811c175bb7b Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Thu, 26 Jan 2012 22:59:08 -0800 Subject: lp8727_charger: Correct typos on the comment intergrated charger -> integrated charger ^ Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 2 +- include/linux/lp8727.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index d5aab54eda1..815dba37e3e 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -1,5 +1,5 @@ /* - * Driver for LP8727 Micro/Mini USB IC with intergrated charger + * Driver for LP8727 Micro/Mini USB IC with integrated charger * * Copyright (C) 2011 Texas Instruments * Copyright (C) 2011 National Semiconductor diff --git a/include/linux/lp8727.h b/include/linux/lp8727.h index a508b4555e6..ea98c6133d3 100644 --- a/include/linux/lp8727.h +++ b/include/linux/lp8727.h @@ -1,5 +1,5 @@ /* - * LP8727 Micro/Mini USB IC with intergrated charger + * LP8727 Micro/Mini USB IC with integrated charger * * Copyright (C) 2011 Texas Instruments * Copyright (C) 2011 National Semiconductor -- cgit v1.2.3-70-g09d2 From e2c5f7db789a5be8ba131e9fe3e87b66bc606e3b Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Thu, 12 Jan 2012 20:45:02 +0800 Subject: lp8727_charger: Add MODULE_DEVICE_TABLE Add MODULE_DEVICE_TABLE to setup modalias for lp8727. Allows auto modprobing. Signed-off-by: Axel Lin Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 815dba37e3e..ab0f431876e 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -480,6 +480,7 @@ static const struct i2c_device_id lp8727_ids[] = { {"lp8727", 0}, { } }; +MODULE_DEVICE_TABLE(i2c, lp8727_ids); static struct i2c_driver lp8727_driver = { .driver = { -- cgit v1.2.3-70-g09d2 From 5ff92e7ab3591299089cfba440acb4d2ba8ab92f Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sat, 21 Jan 2012 14:42:54 +0800 Subject: power_supply: Convert i2c drivers to module_i2c_driver Factor out some boilerplate code for i2c driver registration into module_i2c_driver. Signed-off-by: Axel Lin Cc: Woogyom Kim Cc: Daniel Jeong Cc: Minkyu Kang Cc: Peter Edwards Acked-by: Milo(Woogyom) Kim Acked-by: Rhyland Klein Acked-by: Ryan Mallon Signed-off-by: Anton Vorontsov --- drivers/power/ds2782_battery.c | 13 +------------ drivers/power/lp8727_charger.c | 14 +------------- drivers/power/max17040_battery.c | 13 +------------ drivers/power/max17042_battery.c | 13 +------------ drivers/power/sbs-battery.c | 13 +------------ drivers/power/z2_battery.c | 14 +------------- 6 files changed, 6 insertions(+), 74 deletions(-) (limited to 'drivers/power/lp8727_charger.c') diff --git a/drivers/power/ds2782_battery.c b/drivers/power/ds2782_battery.c index bfbce5de49d..6bb6e2f5ea8 100644 --- a/drivers/power/ds2782_battery.c +++ b/drivers/power/ds2782_battery.c @@ -403,18 +403,7 @@ static struct i2c_driver ds278x_battery_driver = { .remove = ds278x_battery_remove, .id_table = ds278x_id, }; - -static int __init ds278x_init(void) -{ - return i2c_add_driver(&ds278x_battery_driver); -} -module_init(ds278x_init); - -static void __exit ds278x_exit(void) -{ - i2c_del_driver(&ds278x_battery_driver); -} -module_exit(ds278x_exit); +module_i2c_driver(ds278x_battery_driver); MODULE_AUTHOR("Ryan Mallon"); MODULE_DESCRIPTION("Maxim/Dallas DS2782 Stand-Alone Fuel Gauage IC driver"); diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index ab0f431876e..d8b75780bfe 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -490,19 +490,7 @@ static struct i2c_driver lp8727_driver = { .remove = __devexit_p(lp8727_remove), .id_table = lp8727_ids, }; - -static int __init lp8727_init(void) -{ - return i2c_add_driver(&lp8727_driver); -} - -static void __exit lp8727_exit(void) -{ - i2c_del_driver(&lp8727_driver); -} - -module_init(lp8727_init); -module_exit(lp8727_exit); +module_i2c_driver(lp8727_driver); MODULE_DESCRIPTION("TI/National Semiconductor LP8727 charger driver"); MODULE_AUTHOR("Woogyom Kim , " diff --git a/drivers/power/max17040_battery.c b/drivers/power/max17040_battery.c index 2f2f9a6f54f..c284143cfcd 100644 --- a/drivers/power/max17040_battery.c +++ b/drivers/power/max17040_battery.c @@ -290,18 +290,7 @@ static struct i2c_driver max17040_i2c_driver = { .resume = max17040_resume, .id_table = max17040_id, }; - -static int __init max17040_init(void) -{ - return i2c_add_driver(&max17040_i2c_driver); -} -module_init(max17040_init); - -static void __exit max17040_exit(void) -{ - i2c_del_driver(&max17040_i2c_driver); -} -module_exit(max17040_exit); +module_i2c_driver(max17040_i2c_driver); MODULE_AUTHOR("Minkyu Kang "); MODULE_DESCRIPTION("MAX17040 Fuel Gauge"); diff --git a/drivers/power/max17042_battery.c b/drivers/power/max17042_battery.c index e36763a4f0f..5474e76d36f 100644 --- a/drivers/power/max17042_battery.c +++ b/drivers/power/max17042_battery.c @@ -751,18 +751,7 @@ static struct i2c_driver max17042_i2c_driver = { .remove = __devexit_p(max17042_remove), .id_table = max17042_id, }; - -static int __init max17042_init(void) -{ - return i2c_add_driver(&max17042_i2c_driver); -} -module_init(max17042_init); - -static void __exit max17042_exit(void) -{ - i2c_del_driver(&max17042_i2c_driver); -} -module_exit(max17042_exit); +module_i2c_driver(max17042_i2c_driver); MODULE_AUTHOR("MyungJoo Ham "); MODULE_DESCRIPTION("MAX17042 Fuel Gauge"); diff --git a/drivers/power/sbs-battery.c b/drivers/power/sbs-battery.c index 9ff8af069da..06b659d9179 100644 --- a/drivers/power/sbs-battery.c +++ b/drivers/power/sbs-battery.c @@ -852,18 +852,7 @@ static struct i2c_driver sbs_battery_driver = { .of_match_table = sbs_dt_ids, }, }; - -static int __init sbs_battery_init(void) -{ - return i2c_add_driver(&sbs_battery_driver); -} -module_init(sbs_battery_init); - -static void __exit sbs_battery_exit(void) -{ - i2c_del_driver(&sbs_battery_driver); -} -module_exit(sbs_battery_exit); +module_i2c_driver(sbs_battery_driver); MODULE_DESCRIPTION("SBS battery monitor driver"); MODULE_LICENSE("GPL"); diff --git a/drivers/power/z2_battery.c b/drivers/power/z2_battery.c index 636ebb2a0e8..8c9a607ea77 100644 --- a/drivers/power/z2_battery.c +++ b/drivers/power/z2_battery.c @@ -316,19 +316,7 @@ static struct i2c_driver z2_batt_driver = { .remove = __devexit_p(z2_batt_remove), .id_table = z2_batt_id, }; - -static int __init z2_batt_init(void) -{ - return i2c_add_driver(&z2_batt_driver); -} - -static void __exit z2_batt_exit(void) -{ - i2c_del_driver(&z2_batt_driver); -} - -module_init(z2_batt_init); -module_exit(z2_batt_exit); +module_i2c_driver(z2_batt_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Peter Edwards "); -- cgit v1.2.3-70-g09d2