From 318cb389d020e3107979d7d794ab992e4bcd6665 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Fri, 31 Aug 2012 09:23:12 +0000 Subject: lp8727_charger: Fix buggy code of NULL pdata LP8727 platform data is optional, so the driver should work even the platform data is NULL. To check the platform data, charging parameter data should be changed to the pointer type. Fix NULL point access problem when getting the battery properties. When the data is NULL, just return as invalid value. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- include/linux/platform_data/lp8727.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'include/linux/platform_data') diff --git a/include/linux/platform_data/lp8727.h b/include/linux/platform_data/lp8727.h index ea98c6133d3..f4bcdd5f20a 100644 --- a/include/linux/platform_data/lp8727.h +++ b/include/linux/platform_data/lp8727.h @@ -51,15 +51,16 @@ struct lp8727_chg_param { * @get_batt_level : get battery voltage (mV) * @get_batt_capacity : get battery capacity (%) * @get_batt_temp : get battery temperature - * @ac, @usb : charging parameters each charger type + * @ac : charging parameters for AC type charger + * @usb : charging parameters for USB type charger */ struct lp8727_platform_data { u8 (*get_batt_present)(void); u16 (*get_batt_level)(void); u8 (*get_batt_capacity)(void); u8 (*get_batt_temp)(void); - struct lp8727_chg_param ac; - struct lp8727_chg_param usb; + struct lp8727_chg_param *ac; + struct lp8727_chg_param *usb; }; #endif -- cgit v1.2.3-70-g09d2 From 60fd57e06ed7ea13bc0bdf4cb5324d47039105ab Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Fri, 31 Aug 2012 09:23:25 +0000 Subject: lp8727_charger: Add configurable debouce timer Debounce time is configurable in the platform side. If it is not defined, the default value is 270ms. Platform data is msec unit, and this time is converted to jiffies internally. The workqueue uses this jiffies time in the interrupt handling. So debounce_jiffies is added in the private data. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 12 +++++++++--- include/linux/platform_data/lp8727.h | 2 ++ 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'include/linux/platform_data') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 7c19c0927f3..1907b1f7953 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -17,7 +17,7 @@ #include #include -#define DEBOUNCE_MSEC 270 +#define DEFAULT_DEBOUNCE_MSEC 270 /* Registers */ #define CTRL1 0x1 @@ -90,6 +90,7 @@ struct lp8727_chg { struct lp8727_psy *psy; struct lp8727_chg_param *chg_parm; enum lp8727_dev_id devid; + unsigned long debounce_jiffies; }; static int lp8727_read_bytes(struct lp8727_chg *pchg, u8 reg, u8 *data, u8 len) @@ -236,15 +237,18 @@ static void lp8727_delayed_func(struct work_struct *_work) static irqreturn_t lp8727_isr_func(int irq, void *ptr) { struct lp8727_chg *pchg = ptr; - unsigned long delay = msecs_to_jiffies(DEBOUNCE_MSEC); - queue_delayed_work(pchg->irqthread, &pchg->work, delay); + queue_delayed_work(pchg->irqthread, &pchg->work, + pchg->debounce_jiffies); return IRQ_HANDLED; } static int lp8727_intr_config(struct lp8727_chg *pchg) { + unsigned delay_msec = pchg->pdata ? pchg->pdata->debounce_msec : + DEFAULT_DEBOUNCE_MSEC; + INIT_DELAYED_WORK(&pchg->work, lp8727_delayed_func); pchg->irqthread = create_singlethread_workqueue("lp8727-irqthd"); @@ -253,6 +257,8 @@ static int lp8727_intr_config(struct lp8727_chg *pchg) return -ENOMEM; } + pchg->debounce_jiffies = msecs_to_jiffies(delay_msec); + return request_threaded_irq(pchg->client->irq, NULL, lp8727_isr_func, diff --git a/include/linux/platform_data/lp8727.h b/include/linux/platform_data/lp8727.h index f4bcdd5f20a..54b77880ed6 100644 --- a/include/linux/platform_data/lp8727.h +++ b/include/linux/platform_data/lp8727.h @@ -53,6 +53,7 @@ struct lp8727_chg_param { * @get_batt_temp : get battery temperature * @ac : charging parameters for AC type charger * @usb : charging parameters for USB type charger + * @debounce_msec : interrupt debounce time */ struct lp8727_platform_data { u8 (*get_batt_present)(void); @@ -61,6 +62,7 @@ struct lp8727_platform_data { u8 (*get_batt_temp)(void); struct lp8727_chg_param *ac; struct lp8727_chg_param *usb; + unsigned int debounce_msec; }; #endif -- cgit v1.2.3-70-g09d2 From 6029719f08d2d21624504e326f50c68f89731353 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Fri, 31 Aug 2012 09:24:51 +0000 Subject: lp8727_charger: Clean up lp8727 definitions All definitions should be unique, since they're in the gloabl namespace. So the prefix LP8727_ are added. Additionally, use BIT() macro for bit masks. Remove unnecessary definitions such as SW_DM1_U1 and SW_DP2_U2. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 130 +++++++++++++++++------------------ include/linux/platform_data/lp8727.h | 34 ++++----- 2 files changed, 81 insertions(+), 83 deletions(-) (limited to 'include/linux/platform_data') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 32bf157f481..65c9840a37e 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -21,53 +21,51 @@ #define DEFAULT_DEBOUNCE_MSEC 270 /* Registers */ -#define CTRL1 0x1 -#define CTRL2 0x2 -#define SWCTRL 0x3 -#define INT1 0x4 -#define INT2 0x5 -#define STATUS1 0x6 -#define STATUS2 0x7 -#define CHGCTRL2 0x9 +#define LP8727_CTRL1 0x1 +#define LP8727_CTRL2 0x2 +#define LP8727_SWCTRL 0x3 +#define LP8727_INT1 0x4 +#define LP8727_INT2 0x5 +#define LP8727_STATUS1 0x6 +#define LP8727_STATUS2 0x7 +#define LP8727_CHGCTRL2 0x9 /* CTRL1 register */ -#define CP_EN (1 << 0) -#define ADC_EN (1 << 1) -#define ID200_EN (1 << 4) +#define LP8727_CP_EN BIT(0) +#define LP8727_ADC_EN BIT(1) +#define LP8727_ID200_EN BIT(4) /* CTRL2 register */ -#define CHGDET_EN (1 << 1) -#define INT_EN (1 << 6) +#define LP8727_CHGDET_EN BIT(1) +#define LP8727_INT_EN BIT(6) /* SWCTRL register */ -#define SW_DM1_DM (0x0 << 0) -#define SW_DM1_U1 (0x1 << 0) -#define SW_DM1_HiZ (0x7 << 0) -#define SW_DP2_DP (0x0 << 3) -#define SW_DP2_U2 (0x1 << 3) -#define SW_DP2_HiZ (0x7 << 3) +#define LP8727_SW_DM1_DM (0x0 << 0) +#define LP8727_SW_DM1_HiZ (0x7 << 0) +#define LP8727_SW_DP2_DP (0x0 << 3) +#define LP8727_SW_DP2_HiZ (0x7 << 3) /* INT1 register */ -#define IDNO (0xF << 0) -#define VBUS (1 << 4) +#define LP8727_IDNO (0xF << 0) +#define LP8727_VBUS BIT(4) /* STATUS1 register */ -#define CHGSTAT (3 << 4) -#define CHPORT (1 << 6) -#define DCPORT (1 << 7) -#define LP8727_STAT_EOC 0x30 +#define LP8727_CHGSTAT (3 << 4) +#define LP8727_CHPORT BIT(6) +#define LP8727_DCPORT BIT(7) +#define LP8727_STAT_EOC 0x30 /* STATUS2 register */ -#define TEMP_STAT (3 << 5) -#define TEMP_SHIFT 5 +#define LP8727_TEMP_STAT (3 << 5) +#define LP8727_TEMP_SHIFT 5 enum lp8727_dev_id { - ID_NONE, - ID_TA, - ID_DEDICATED_CHG, - ID_USB_CHG, - ID_USB_DS, - ID_MAX, + LP8727_ID_NONE, + LP8727_ID_TA, + LP8727_ID_DEDICATED_CHG, + LP8727_ID_USB_CHG, + LP8727_ID_USB_DS, + LP8727_ID_MAX, }; enum lp8727_die_temp { @@ -127,12 +125,12 @@ static int lp8727_is_charger_attached(const char *name, int id) { if (name) { if (!strcmp(name, "ac")) - return (id == ID_TA || id == ID_DEDICATED_CHG) ? 1 : 0; + return (id == LP8727_ID_TA || id == LP8727_ID_DEDICATED_CHG) ? 1 : 0; else if (!strcmp(name, "usb")) - return (id == ID_USB_CHG) ? 1 : 0; + return (id == LP8727_ID_USB_CHG) ? 1 : 0; } - return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0; + return (id >= LP8727_ID_TA && id <= LP8727_ID_USB_CHG) ? 1 : 0; } static int lp8727_init_device(struct lp8727_chg *pchg) @@ -142,18 +140,18 @@ static int lp8727_init_device(struct lp8727_chg *pchg) u8 intstat[LP8788_NUM_INTREGS]; /* clear interrupts */ - ret = lp8727_read_bytes(pchg, INT1, intstat, LP8788_NUM_INTREGS); + ret = lp8727_read_bytes(pchg, LP8727_INT1, intstat, LP8788_NUM_INTREGS); if (ret) return ret; - val = ID200_EN | ADC_EN | CP_EN; - ret = lp8727_write_byte(pchg, CTRL1, val); + val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN; + ret = lp8727_write_byte(pchg, LP8727_CTRL1, val); if (ret) return ret; - val = INT_EN | CHGDET_EN; - ret = lp8727_write_byte(pchg, CTRL2, val); + val = LP8727_INT_EN | LP8727_CHGDET_EN; + ret = lp8727_write_byte(pchg, LP8727_CTRL2, val); if (ret) return ret; @@ -163,48 +161,48 @@ static int lp8727_init_device(struct lp8727_chg *pchg) static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) { u8 val; - lp8727_read_byte(pchg, STATUS1, &val); - return val & DCPORT; + lp8727_read_byte(pchg, LP8727_STATUS1, &val); + return val & LP8727_DCPORT; } static int lp8727_is_usb_charger(struct lp8727_chg *pchg) { u8 val; - lp8727_read_byte(pchg, STATUS1, &val); - return val & CHPORT; + lp8727_read_byte(pchg, LP8727_STATUS1, &val); + return val & LP8727_CHPORT; } static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) { - lp8727_write_byte(pchg, SWCTRL, sw); + lp8727_write_byte(pchg, LP8727_SWCTRL, sw); } static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin) { struct lp8727_platform_data *pdata = pchg->pdata; - u8 devid = ID_NONE; - u8 swctrl = SW_DM1_HiZ | SW_DP2_HiZ; + u8 devid = LP8727_ID_NONE; + u8 swctrl = LP8727_SW_DM1_HiZ | LP8727_SW_DP2_HiZ; switch (id) { case 0x5: - devid = ID_TA; + devid = LP8727_ID_TA; pchg->chg_parm = pdata ? pdata->ac : NULL; break; case 0xB: if (lp8727_is_dedicated_charger(pchg)) { pchg->chg_parm = pdata ? pdata->ac : NULL; - devid = ID_DEDICATED_CHG; + devid = LP8727_ID_DEDICATED_CHG; } else if (lp8727_is_usb_charger(pchg)) { pchg->chg_parm = pdata ? pdata->usb : NULL; - devid = ID_USB_CHG; - swctrl = SW_DM1_DM | SW_DP2_DP; + devid = LP8727_ID_USB_CHG; + swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; } else if (vbusin) { - devid = ID_USB_DS; - swctrl = SW_DM1_DM | SW_DP2_DP; + devid = LP8727_ID_USB_DS; + swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; } break; default: - devid = ID_NONE; + devid = LP8727_ID_NONE; pchg->chg_parm = NULL; break; } @@ -217,9 +215,9 @@ static void lp8727_enable_chgdet(struct lp8727_chg *pchg) { u8 val; - lp8727_read_byte(pchg, CTRL2, &val); - val |= CHGDET_EN; - lp8727_write_byte(pchg, CTRL2, val); + lp8727_read_byte(pchg, LP8727_CTRL2, &val); + val |= LP8727_CHGDET_EN; + lp8727_write_byte(pchg, LP8727_CTRL2, val); } static void lp8727_delayed_func(struct work_struct *_work) @@ -228,13 +226,13 @@ static void lp8727_delayed_func(struct work_struct *_work) struct lp8727_chg *pchg = container_of(_work, struct lp8727_chg, work.work); - if (lp8727_read_bytes(pchg, INT1, intstat, 2)) { + if (lp8727_read_bytes(pchg, LP8727_INT1, intstat, 2)) { dev_err(pchg->dev, "can not read INT registers\n"); return; } - idno = intstat[0] & IDNO; - vbus = intstat[0] & VBUS; + idno = intstat[0] & LP8727_IDNO; + vbus = intstat[0] & LP8727_VBUS; lp8727_id_detection(pchg, idno, vbus); lp8727_enable_chgdet(pchg); @@ -341,9 +339,9 @@ 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_read_byte(pchg, STATUS1, &read); + lp8727_read_byte(pchg, LP8727_STATUS1, &read); - val->intval = (read & CHGSTAT) == LP8727_STAT_EOC ? + val->intval = (read & LP8727_CHGSTAT) == LP8727_STAT_EOC ? POWER_SUPPLY_STATUS_FULL : POWER_SUPPLY_STATUS_CHARGING; } else { @@ -351,8 +349,8 @@ static int lp8727_battery_get_property(struct power_supply *psy, } break; case POWER_SUPPLY_PROP_HEALTH: - lp8727_read_byte(pchg, STATUS2, &read); - temp = (read & TEMP_STAT) >> TEMP_SHIFT; + lp8727_read_byte(pchg, LP8727_STATUS2, &read); + temp = (read & LP8727_TEMP_STAT) >> LP8727_TEMP_SHIFT; val->intval = lp8727_is_high_temperature(temp) ? POWER_SUPPLY_HEALTH_OVERHEAT : @@ -404,7 +402,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_write_byte(pchg, CHGCTRL2, val); + lp8727_write_byte(pchg, LP8727_CHGCTRL2, val); } } } diff --git a/include/linux/platform_data/lp8727.h b/include/linux/platform_data/lp8727.h index 54b77880ed6..a8b8dbc418c 100644 --- a/include/linux/platform_data/lp8727.h +++ b/include/linux/platform_data/lp8727.h @@ -13,26 +13,26 @@ #define _LP8727_H enum lp8727_eoc_level { - EOC_5P, - EOC_10P, - EOC_16P, - EOC_20P, - EOC_25P, - EOC_33P, - EOC_50P, + LP8727_EOC_5P, + LP8727_EOC_10P, + LP8727_EOC_16P, + LP8727_EOC_20P, + LP8727_EOC_25P, + LP8727_EOC_33P, + LP8727_EOC_50P, }; enum lp8727_ichg { - ICHG_90mA, - ICHG_100mA, - ICHG_400mA, - ICHG_450mA, - ICHG_500mA, - ICHG_600mA, - ICHG_700mA, - ICHG_800mA, - ICHG_900mA, - ICHG_1000mA, + LP8727_ICHG_90mA, + LP8727_ICHG_100mA, + LP8727_ICHG_400mA, + LP8727_ICHG_450mA, + LP8727_ICHG_500mA, + LP8727_ICHG_600mA, + LP8727_ICHG_700mA, + LP8727_ICHG_800mA, + LP8727_ICHG_900mA, + LP8727_ICHG_1000mA, }; /** -- cgit v1.2.3-70-g09d2 From b9633ef1a9cdf4317d8c4a8db977485e2a8e1cb8 Mon Sep 17 00:00:00 2001 From: "Kim, Milo" Date: Fri, 31 Aug 2012 09:27:22 +0000 Subject: lp8727_charger: More pure cosmetic improvements This is really minor, but it improves the readability. Signed-off-by: Milo(Woogyom) Kim Signed-off-by: Anton Vorontsov --- drivers/power/lp8727_charger.c | 3 ++- include/linux/platform_data/lp8727.h | 8 ++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'include/linux/platform_data') diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 717a97690dd..c628224b7f5 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c @@ -149,7 +149,6 @@ static int lp8727_init_device(struct lp8727_chg *pchg) if (ret) return ret; - val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN; ret = lp8727_write_byte(pchg, LP8727_CTRL1, val); if (ret) @@ -162,6 +161,7 @@ static int lp8727_init_device(struct lp8727_chg *pchg) static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) { u8 val; + lp8727_read_byte(pchg, LP8727_STATUS1, &val); return val & LP8727_DCPORT; } @@ -169,6 +169,7 @@ static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) static int lp8727_is_usb_charger(struct lp8727_chg *pchg) { u8 val; + lp8727_read_byte(pchg, LP8727_STATUS1, &val); return val & LP8727_CHPORT; } diff --git a/include/linux/platform_data/lp8727.h b/include/linux/platform_data/lp8727.h index a8b8dbc418c..47128a50e04 100644 --- a/include/linux/platform_data/lp8727.h +++ b/include/linux/platform_data/lp8727.h @@ -38,7 +38,7 @@ enum lp8727_ichg { /** * struct lp8727_chg_param * @eoc_level : end of charge level setting - * @ichg : charging current + * @ichg : charging current */ struct lp8727_chg_param { enum lp8727_eoc_level eoc_level; @@ -47,10 +47,10 @@ struct lp8727_chg_param { /** * struct lp8727_platform_data - * @get_batt_present : check battery status - exists or not - * @get_batt_level : get battery voltage (mV) + * @get_batt_present : check battery status - exists or not + * @get_batt_level : get battery voltage (mV) * @get_batt_capacity : get battery capacity (%) - * @get_batt_temp : get battery temperature + * @get_batt_temp : get battery temperature * @ac : charging parameters for AC type charger * @usb : charging parameters for USB type charger * @debounce_msec : interrupt debounce time -- cgit v1.2.3-70-g09d2