Commit 6029719f authored by Kim, Milo's avatar Kim, Milo Committed by Anton Vorontsov

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: default avatarMilo(Woogyom) Kim <milo.kim@ti.com>
Signed-off-by: default avatarAnton Vorontsov <anton.vorontsov@linaro.org>
parent faaae9bb
...@@ -21,53 +21,51 @@ ...@@ -21,53 +21,51 @@
#define DEFAULT_DEBOUNCE_MSEC 270 #define DEFAULT_DEBOUNCE_MSEC 270
/* Registers */ /* Registers */
#define CTRL1 0x1 #define LP8727_CTRL1 0x1
#define CTRL2 0x2 #define LP8727_CTRL2 0x2
#define SWCTRL 0x3 #define LP8727_SWCTRL 0x3
#define INT1 0x4 #define LP8727_INT1 0x4
#define INT2 0x5 #define LP8727_INT2 0x5
#define STATUS1 0x6 #define LP8727_STATUS1 0x6
#define STATUS2 0x7 #define LP8727_STATUS2 0x7
#define CHGCTRL2 0x9 #define LP8727_CHGCTRL2 0x9
/* CTRL1 register */ /* CTRL1 register */
#define CP_EN (1 << 0) #define LP8727_CP_EN BIT(0)
#define ADC_EN (1 << 1) #define LP8727_ADC_EN BIT(1)
#define ID200_EN (1 << 4) #define LP8727_ID200_EN BIT(4)
/* CTRL2 register */ /* CTRL2 register */
#define CHGDET_EN (1 << 1) #define LP8727_CHGDET_EN BIT(1)
#define INT_EN (1 << 6) #define LP8727_INT_EN BIT(6)
/* SWCTRL register */ /* SWCTRL register */
#define SW_DM1_DM (0x0 << 0) #define LP8727_SW_DM1_DM (0x0 << 0)
#define SW_DM1_U1 (0x1 << 0) #define LP8727_SW_DM1_HiZ (0x7 << 0)
#define SW_DM1_HiZ (0x7 << 0) #define LP8727_SW_DP2_DP (0x0 << 3)
#define SW_DP2_DP (0x0 << 3) #define LP8727_SW_DP2_HiZ (0x7 << 3)
#define SW_DP2_U2 (0x1 << 3)
#define SW_DP2_HiZ (0x7 << 3)
/* INT1 register */ /* INT1 register */
#define IDNO (0xF << 0) #define LP8727_IDNO (0xF << 0)
#define VBUS (1 << 4) #define LP8727_VBUS BIT(4)
/* STATUS1 register */ /* STATUS1 register */
#define CHGSTAT (3 << 4) #define LP8727_CHGSTAT (3 << 4)
#define CHPORT (1 << 6) #define LP8727_CHPORT BIT(6)
#define DCPORT (1 << 7) #define LP8727_DCPORT BIT(7)
#define LP8727_STAT_EOC 0x30 #define LP8727_STAT_EOC 0x30
/* STATUS2 register */ /* STATUS2 register */
#define TEMP_STAT (3 << 5) #define LP8727_TEMP_STAT (3 << 5)
#define TEMP_SHIFT 5 #define LP8727_TEMP_SHIFT 5
enum lp8727_dev_id { enum lp8727_dev_id {
ID_NONE, LP8727_ID_NONE,
ID_TA, LP8727_ID_TA,
ID_DEDICATED_CHG, LP8727_ID_DEDICATED_CHG,
ID_USB_CHG, LP8727_ID_USB_CHG,
ID_USB_DS, LP8727_ID_USB_DS,
ID_MAX, LP8727_ID_MAX,
}; };
enum lp8727_die_temp { enum lp8727_die_temp {
...@@ -127,12 +125,12 @@ static int lp8727_is_charger_attached(const char *name, int id) ...@@ -127,12 +125,12 @@ static int lp8727_is_charger_attached(const char *name, int id)
{ {
if (name) { if (name) {
if (!strcmp(name, "ac")) 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")) 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) static int lp8727_init_device(struct lp8727_chg *pchg)
...@@ -142,18 +140,18 @@ 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]; u8 intstat[LP8788_NUM_INTREGS];
/* clear interrupts */ /* 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) if (ret)
return ret; return ret;
val = ID200_EN | ADC_EN | CP_EN; val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN;
ret = lp8727_write_byte(pchg, CTRL1, val); ret = lp8727_write_byte(pchg, LP8727_CTRL1, val);
if (ret) if (ret)
return ret; return ret;
val = INT_EN | CHGDET_EN; val = LP8727_INT_EN | LP8727_CHGDET_EN;
ret = lp8727_write_byte(pchg, CTRL2, val); ret = lp8727_write_byte(pchg, LP8727_CTRL2, val);
if (ret) if (ret)
return ret; return ret;
...@@ -163,48 +161,48 @@ static int lp8727_init_device(struct lp8727_chg *pchg) ...@@ -163,48 +161,48 @@ static int lp8727_init_device(struct lp8727_chg *pchg)
static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg)
{ {
u8 val; u8 val;
lp8727_read_byte(pchg, STATUS1, &val); lp8727_read_byte(pchg, LP8727_STATUS1, &val);
return val & DCPORT; return val & LP8727_DCPORT;
} }
static int lp8727_is_usb_charger(struct lp8727_chg *pchg) static int lp8727_is_usb_charger(struct lp8727_chg *pchg)
{ {
u8 val; u8 val;
lp8727_read_byte(pchg, STATUS1, &val); lp8727_read_byte(pchg, LP8727_STATUS1, &val);
return val & CHPORT; return val & LP8727_CHPORT;
} }
static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) 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) static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin)
{ {
struct lp8727_platform_data *pdata = pchg->pdata; struct lp8727_platform_data *pdata = pchg->pdata;
u8 devid = ID_NONE; u8 devid = LP8727_ID_NONE;
u8 swctrl = SW_DM1_HiZ | SW_DP2_HiZ; u8 swctrl = LP8727_SW_DM1_HiZ | LP8727_SW_DP2_HiZ;
switch (id) { switch (id) {
case 0x5: case 0x5:
devid = ID_TA; devid = LP8727_ID_TA;
pchg->chg_parm = pdata ? pdata->ac : NULL; pchg->chg_parm = pdata ? pdata->ac : NULL;
break; break;
case 0xB: case 0xB:
if (lp8727_is_dedicated_charger(pchg)) { if (lp8727_is_dedicated_charger(pchg)) {
pchg->chg_parm = pdata ? pdata->ac : NULL; pchg->chg_parm = pdata ? pdata->ac : NULL;
devid = ID_DEDICATED_CHG; devid = LP8727_ID_DEDICATED_CHG;
} else if (lp8727_is_usb_charger(pchg)) { } else if (lp8727_is_usb_charger(pchg)) {
pchg->chg_parm = pdata ? pdata->usb : NULL; pchg->chg_parm = pdata ? pdata->usb : NULL;
devid = ID_USB_CHG; devid = LP8727_ID_USB_CHG;
swctrl = SW_DM1_DM | SW_DP2_DP; swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP;
} else if (vbusin) { } else if (vbusin) {
devid = ID_USB_DS; devid = LP8727_ID_USB_DS;
swctrl = SW_DM1_DM | SW_DP2_DP; swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP;
} }
break; break;
default: default:
devid = ID_NONE; devid = LP8727_ID_NONE;
pchg->chg_parm = NULL; pchg->chg_parm = NULL;
break; break;
} }
...@@ -217,9 +215,9 @@ static void lp8727_enable_chgdet(struct lp8727_chg *pchg) ...@@ -217,9 +215,9 @@ static void lp8727_enable_chgdet(struct lp8727_chg *pchg)
{ {
u8 val; u8 val;
lp8727_read_byte(pchg, CTRL2, &val); lp8727_read_byte(pchg, LP8727_CTRL2, &val);
val |= CHGDET_EN; val |= LP8727_CHGDET_EN;
lp8727_write_byte(pchg, CTRL2, val); lp8727_write_byte(pchg, LP8727_CTRL2, val);
} }
static void lp8727_delayed_func(struct work_struct *_work) static void lp8727_delayed_func(struct work_struct *_work)
...@@ -228,13 +226,13 @@ 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 = struct lp8727_chg *pchg =
container_of(_work, struct lp8727_chg, work.work); 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"); dev_err(pchg->dev, "can not read INT registers\n");
return; return;
} }
idno = intstat[0] & IDNO; idno = intstat[0] & LP8727_IDNO;
vbus = intstat[0] & VBUS; vbus = intstat[0] & LP8727_VBUS;
lp8727_id_detection(pchg, idno, vbus); lp8727_id_detection(pchg, idno, vbus);
lp8727_enable_chgdet(pchg); lp8727_enable_chgdet(pchg);
...@@ -341,9 +339,9 @@ static int lp8727_battery_get_property(struct power_supply *psy, ...@@ -341,9 +339,9 @@ static int lp8727_battery_get_property(struct power_supply *psy,
switch (psp) { switch (psp) {
case POWER_SUPPLY_PROP_STATUS: case POWER_SUPPLY_PROP_STATUS:
if (lp8727_is_charger_attached(psy->name, pchg->devid)) { 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_FULL :
POWER_SUPPLY_STATUS_CHARGING; POWER_SUPPLY_STATUS_CHARGING;
} else { } else {
...@@ -351,8 +349,8 @@ static int lp8727_battery_get_property(struct power_supply *psy, ...@@ -351,8 +349,8 @@ static int lp8727_battery_get_property(struct power_supply *psy,
} }
break; break;
case POWER_SUPPLY_PROP_HEALTH: case POWER_SUPPLY_PROP_HEALTH:
lp8727_read_byte(pchg, STATUS2, &read); lp8727_read_byte(pchg, LP8727_STATUS2, &read);
temp = (read & TEMP_STAT) >> TEMP_SHIFT; temp = (read & LP8727_TEMP_STAT) >> LP8727_TEMP_SHIFT;
val->intval = lp8727_is_high_temperature(temp) ? val->intval = lp8727_is_high_temperature(temp) ?
POWER_SUPPLY_HEALTH_OVERHEAT : POWER_SUPPLY_HEALTH_OVERHEAT :
...@@ -404,7 +402,7 @@ static void lp8727_charger_changed(struct power_supply *psy) ...@@ -404,7 +402,7 @@ static void lp8727_charger_changed(struct power_supply *psy)
eoc_level = pchg->chg_parm->eoc_level; eoc_level = pchg->chg_parm->eoc_level;
ichg = pchg->chg_parm->ichg; ichg = pchg->chg_parm->ichg;
val = (ichg << 4) | eoc_level; val = (ichg << 4) | eoc_level;
lp8727_write_byte(pchg, CHGCTRL2, val); lp8727_write_byte(pchg, LP8727_CHGCTRL2, val);
} }
} }
} }
......
...@@ -13,26 +13,26 @@ ...@@ -13,26 +13,26 @@
#define _LP8727_H #define _LP8727_H
enum lp8727_eoc_level { enum lp8727_eoc_level {
EOC_5P, LP8727_EOC_5P,
EOC_10P, LP8727_EOC_10P,
EOC_16P, LP8727_EOC_16P,
EOC_20P, LP8727_EOC_20P,
EOC_25P, LP8727_EOC_25P,
EOC_33P, LP8727_EOC_33P,
EOC_50P, LP8727_EOC_50P,
}; };
enum lp8727_ichg { enum lp8727_ichg {
ICHG_90mA, LP8727_ICHG_90mA,
ICHG_100mA, LP8727_ICHG_100mA,
ICHG_400mA, LP8727_ICHG_400mA,
ICHG_450mA, LP8727_ICHG_450mA,
ICHG_500mA, LP8727_ICHG_500mA,
ICHG_600mA, LP8727_ICHG_600mA,
ICHG_700mA, LP8727_ICHG_700mA,
ICHG_800mA, LP8727_ICHG_800mA,
ICHG_900mA, LP8727_ICHG_900mA,
ICHG_1000mA, LP8727_ICHG_1000mA,
}; };
/** /**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment