diff options
author | Kim, Milo <Milo.Kim@ti.com> | 2012-08-31 05:24:51 -0400 |
---|---|---|
committer | Anton Vorontsov <anton.vorontsov@linaro.org> | 2012-09-20 21:01:33 -0400 |
commit | 6029719f08d2d21624504e326f50c68f89731353 (patch) | |
tree | 73c2903844b75c4fadce0ec1520c39df740c55db /drivers/power | |
parent | faaae9bbb1f91f8bcd03bd9976620ac08d8b4454 (diff) |
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 <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 | 130 |
1 files changed, 64 insertions, 66 deletions
diff --git a/drivers/power/lp8727_charger.c b/drivers/power/lp8727_charger.c index 32bf157f4815..65c9840a37e1 100644 --- a/drivers/power/lp8727_charger.c +++ b/drivers/power/lp8727_charger.c | |||
@@ -21,53 +21,51 @@ | |||
21 | #define DEFAULT_DEBOUNCE_MSEC 270 | 21 | #define DEFAULT_DEBOUNCE_MSEC 270 |
22 | 22 | ||
23 | /* Registers */ | 23 | /* Registers */ |
24 | #define CTRL1 0x1 | 24 | #define LP8727_CTRL1 0x1 |
25 | #define CTRL2 0x2 | 25 | #define LP8727_CTRL2 0x2 |
26 | #define SWCTRL 0x3 | 26 | #define LP8727_SWCTRL 0x3 |
27 | #define INT1 0x4 | 27 | #define LP8727_INT1 0x4 |
28 | #define INT2 0x5 | 28 | #define LP8727_INT2 0x5 |
29 | #define STATUS1 0x6 | 29 | #define LP8727_STATUS1 0x6 |
30 | #define STATUS2 0x7 | 30 | #define LP8727_STATUS2 0x7 |
31 | #define CHGCTRL2 0x9 | 31 | #define LP8727_CHGCTRL2 0x9 |
32 | 32 | ||
33 | /* CTRL1 register */ | 33 | /* CTRL1 register */ |
34 | #define CP_EN (1 << 0) | 34 | #define LP8727_CP_EN BIT(0) |
35 | #define ADC_EN (1 << 1) | 35 | #define LP8727_ADC_EN BIT(1) |
36 | #define ID200_EN (1 << 4) | 36 | #define LP8727_ID200_EN BIT(4) |
37 | 37 | ||
38 | /* CTRL2 register */ | 38 | /* CTRL2 register */ |
39 | #define CHGDET_EN (1 << 1) | 39 | #define LP8727_CHGDET_EN BIT(1) |
40 | #define INT_EN (1 << 6) | 40 | #define LP8727_INT_EN BIT(6) |
41 | 41 | ||
42 | /* SWCTRL register */ | 42 | /* SWCTRL register */ |
43 | #define SW_DM1_DM (0x0 << 0) | 43 | #define LP8727_SW_DM1_DM (0x0 << 0) |
44 | #define SW_DM1_U1 (0x1 << 0) | 44 | #define LP8727_SW_DM1_HiZ (0x7 << 0) |
45 | #define SW_DM1_HiZ (0x7 << 0) | 45 | #define LP8727_SW_DP2_DP (0x0 << 3) |
46 | #define SW_DP2_DP (0x0 << 3) | 46 | #define LP8727_SW_DP2_HiZ (0x7 << 3) |
47 | #define SW_DP2_U2 (0x1 << 3) | ||
48 | #define SW_DP2_HiZ (0x7 << 3) | ||
49 | 47 | ||
50 | /* INT1 register */ | 48 | /* INT1 register */ |
51 | #define IDNO (0xF << 0) | 49 | #define LP8727_IDNO (0xF << 0) |
52 | #define VBUS (1 << 4) | 50 | #define LP8727_VBUS BIT(4) |
53 | 51 | ||
54 | /* STATUS1 register */ | 52 | /* STATUS1 register */ |
55 | #define CHGSTAT (3 << 4) | 53 | #define LP8727_CHGSTAT (3 << 4) |
56 | #define CHPORT (1 << 6) | 54 | #define LP8727_CHPORT BIT(6) |
57 | #define DCPORT (1 << 7) | 55 | #define LP8727_DCPORT BIT(7) |
58 | #define LP8727_STAT_EOC 0x30 | 56 | #define LP8727_STAT_EOC 0x30 |
59 | 57 | ||
60 | /* STATUS2 register */ | 58 | /* STATUS2 register */ |
61 | #define TEMP_STAT (3 << 5) | 59 | #define LP8727_TEMP_STAT (3 << 5) |
62 | #define TEMP_SHIFT 5 | 60 | #define LP8727_TEMP_SHIFT 5 |
63 | 61 | ||
64 | enum lp8727_dev_id { | 62 | enum lp8727_dev_id { |
65 | ID_NONE, | 63 | LP8727_ID_NONE, |
66 | ID_TA, | 64 | LP8727_ID_TA, |
67 | ID_DEDICATED_CHG, | 65 | LP8727_ID_DEDICATED_CHG, |
68 | ID_USB_CHG, | 66 | LP8727_ID_USB_CHG, |
69 | ID_USB_DS, | 67 | LP8727_ID_USB_DS, |
70 | ID_MAX, | 68 | LP8727_ID_MAX, |
71 | }; | 69 | }; |
72 | 70 | ||
73 | enum lp8727_die_temp { | 71 | enum lp8727_die_temp { |
@@ -127,12 +125,12 @@ static int lp8727_is_charger_attached(const char *name, int id) | |||
127 | { | 125 | { |
128 | if (name) { | 126 | if (name) { |
129 | if (!strcmp(name, "ac")) | 127 | if (!strcmp(name, "ac")) |
130 | return (id == ID_TA || id == ID_DEDICATED_CHG) ? 1 : 0; | 128 | return (id == LP8727_ID_TA || id == LP8727_ID_DEDICATED_CHG) ? 1 : 0; |
131 | else if (!strcmp(name, "usb")) | 129 | else if (!strcmp(name, "usb")) |
132 | return (id == ID_USB_CHG) ? 1 : 0; | 130 | return (id == LP8727_ID_USB_CHG) ? 1 : 0; |
133 | } | 131 | } |
134 | 132 | ||
135 | return (id >= ID_TA && id <= ID_USB_CHG) ? 1 : 0; | 133 | return (id >= LP8727_ID_TA && id <= LP8727_ID_USB_CHG) ? 1 : 0; |
136 | } | 134 | } |
137 | 135 | ||
138 | static int lp8727_init_device(struct lp8727_chg *pchg) | 136 | static int lp8727_init_device(struct lp8727_chg *pchg) |
@@ -142,18 +140,18 @@ static int lp8727_init_device(struct lp8727_chg *pchg) | |||
142 | u8 intstat[LP8788_NUM_INTREGS]; | 140 | u8 intstat[LP8788_NUM_INTREGS]; |
143 | 141 | ||
144 | /* clear interrupts */ | 142 | /* clear interrupts */ |
145 | ret = lp8727_read_bytes(pchg, INT1, intstat, LP8788_NUM_INTREGS); | 143 | ret = lp8727_read_bytes(pchg, LP8727_INT1, intstat, LP8788_NUM_INTREGS); |
146 | if (ret) | 144 | if (ret) |
147 | return ret; | 145 | return ret; |
148 | 146 | ||
149 | 147 | ||
150 | val = ID200_EN | ADC_EN | CP_EN; | 148 | val = LP8727_ID200_EN | LP8727_ADC_EN | LP8727_CP_EN; |
151 | ret = lp8727_write_byte(pchg, CTRL1, val); | 149 | ret = lp8727_write_byte(pchg, LP8727_CTRL1, val); |
152 | if (ret) | 150 | if (ret) |
153 | return ret; | 151 | return ret; |
154 | 152 | ||
155 | val = INT_EN | CHGDET_EN; | 153 | val = LP8727_INT_EN | LP8727_CHGDET_EN; |
156 | ret = lp8727_write_byte(pchg, CTRL2, val); | 154 | ret = lp8727_write_byte(pchg, LP8727_CTRL2, val); |
157 | if (ret) | 155 | if (ret) |
158 | return ret; | 156 | return ret; |
159 | 157 | ||
@@ -163,48 +161,48 @@ static int lp8727_init_device(struct lp8727_chg *pchg) | |||
163 | static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) | 161 | static int lp8727_is_dedicated_charger(struct lp8727_chg *pchg) |
164 | { | 162 | { |
165 | u8 val; | 163 | u8 val; |
166 | lp8727_read_byte(pchg, STATUS1, &val); | 164 | lp8727_read_byte(pchg, LP8727_STATUS1, &val); |
167 | return val & DCPORT; | 165 | return val & LP8727_DCPORT; |
168 | } | 166 | } |
169 | 167 | ||
170 | static int lp8727_is_usb_charger(struct lp8727_chg *pchg) | 168 | static int lp8727_is_usb_charger(struct lp8727_chg *pchg) |
171 | { | 169 | { |
172 | u8 val; | 170 | u8 val; |
173 | lp8727_read_byte(pchg, STATUS1, &val); | 171 | lp8727_read_byte(pchg, LP8727_STATUS1, &val); |
174 | return val & CHPORT; | 172 | return val & LP8727_CHPORT; |
175 | } | 173 | } |
176 | 174 | ||
177 | static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) | 175 | static void lp8727_ctrl_switch(struct lp8727_chg *pchg, u8 sw) |
178 | { | 176 | { |
179 | lp8727_write_byte(pchg, SWCTRL, sw); | 177 | lp8727_write_byte(pchg, LP8727_SWCTRL, sw); |
180 | } | 178 | } |
181 | 179 | ||
182 | static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin) | 180 | static void lp8727_id_detection(struct lp8727_chg *pchg, u8 id, int vbusin) |
183 | { | 181 | { |
184 | struct lp8727_platform_data *pdata = pchg->pdata; | 182 | struct lp8727_platform_data *pdata = pchg->pdata; |
185 | u8 devid = ID_NONE; | 183 | u8 devid = LP8727_ID_NONE; |
186 | u8 swctrl = SW_DM1_HiZ | SW_DP2_HiZ; | 184 | u8 swctrl = LP8727_SW_DM1_HiZ | LP8727_SW_DP2_HiZ; |
187 | 185 | ||
188 | switch (id) { | 186 | switch (id) { |
189 | case 0x5: | 187 | case 0x5: |
190 | devid = ID_TA; | 188 | devid = LP8727_ID_TA; |
191 | pchg->chg_parm = pdata ? pdata->ac : NULL; | 189 | pchg->chg_parm = pdata ? pdata->ac : NULL; |
192 | break; | 190 | break; |
193 | case 0xB: | 191 | case 0xB: |
194 | if (lp8727_is_dedicated_charger(pchg)) { | 192 | if (lp8727_is_dedicated_charger(pchg)) { |
195 | pchg->chg_parm = pdata ? pdata->ac : NULL; | 193 | pchg->chg_parm = pdata ? pdata->ac : NULL; |
196 | devid = ID_DEDICATED_CHG; | 194 | devid = LP8727_ID_DEDICATED_CHG; |
197 | } else if (lp8727_is_usb_charger(pchg)) { | 195 | } else if (lp8727_is_usb_charger(pchg)) { |
198 | pchg->chg_parm = pdata ? pdata->usb : NULL; | 196 | pchg->chg_parm = pdata ? pdata->usb : NULL; |
199 | devid = ID_USB_CHG; | 197 | devid = LP8727_ID_USB_CHG; |
200 | swctrl = SW_DM1_DM | SW_DP2_DP; | 198 | swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; |
201 | } else if (vbusin) { | 199 | } else if (vbusin) { |
202 | devid = ID_USB_DS; | 200 | devid = LP8727_ID_USB_DS; |
203 | swctrl = SW_DM1_DM | SW_DP2_DP; | 201 | swctrl = LP8727_SW_DM1_DM | LP8727_SW_DP2_DP; |
204 | } | 202 | } |
205 | break; | 203 | break; |
206 | default: | 204 | default: |
207 | devid = ID_NONE; | 205 | devid = LP8727_ID_NONE; |
208 | pchg->chg_parm = NULL; | 206 | pchg->chg_parm = NULL; |
209 | break; | 207 | break; |
210 | } | 208 | } |
@@ -217,9 +215,9 @@ static void lp8727_enable_chgdet(struct lp8727_chg *pchg) | |||
217 | { | 215 | { |
218 | u8 val; | 216 | u8 val; |
219 | 217 | ||
220 | lp8727_read_byte(pchg, CTRL2, &val); | 218 | lp8727_read_byte(pchg, LP8727_CTRL2, &val); |
221 | val |= CHGDET_EN; | 219 | val |= LP8727_CHGDET_EN; |
222 | lp8727_write_byte(pchg, CTRL2, val); | 220 | lp8727_write_byte(pchg, LP8727_CTRL2, val); |
223 | } | 221 | } |
224 | 222 | ||
225 | static void lp8727_delayed_func(struct work_struct *_work) | 223 | static void lp8727_delayed_func(struct work_struct *_work) |
@@ -228,13 +226,13 @@ static void lp8727_delayed_func(struct work_struct *_work) | |||
228 | struct lp8727_chg *pchg = | 226 | struct lp8727_chg *pchg = |
229 | container_of(_work, struct lp8727_chg, work.work); | 227 | container_of(_work, struct lp8727_chg, work.work); |
230 | 228 | ||
231 | if (lp8727_read_bytes(pchg, INT1, intstat, 2)) { | 229 | if (lp8727_read_bytes(pchg, LP8727_INT1, intstat, 2)) { |
232 | dev_err(pchg->dev, "can not read INT registers\n"); | 230 | dev_err(pchg->dev, "can not read INT registers\n"); |
233 | return; | 231 | return; |
234 | } | 232 | } |
235 | 233 | ||
236 | idno = intstat[0] & IDNO; | 234 | idno = intstat[0] & LP8727_IDNO; |
237 | vbus = intstat[0] & VBUS; | 235 | vbus = intstat[0] & LP8727_VBUS; |
238 | 236 | ||
239 | lp8727_id_detection(pchg, idno, vbus); | 237 | lp8727_id_detection(pchg, idno, vbus); |
240 | lp8727_enable_chgdet(pchg); | 238 | lp8727_enable_chgdet(pchg); |
@@ -341,9 +339,9 @@ static int lp8727_battery_get_property(struct power_supply *psy, | |||
341 | switch (psp) { | 339 | switch (psp) { |
342 | case POWER_SUPPLY_PROP_STATUS: | 340 | case POWER_SUPPLY_PROP_STATUS: |
343 | if (lp8727_is_charger_attached(psy->name, pchg->devid)) { | 341 | if (lp8727_is_charger_attached(psy->name, pchg->devid)) { |
344 | lp8727_read_byte(pchg, STATUS1, &read); | 342 | lp8727_read_byte(pchg, LP8727_STATUS1, &read); |
345 | 343 | ||
346 | val->intval = (read & CHGSTAT) == LP8727_STAT_EOC ? | 344 | val->intval = (read & LP8727_CHGSTAT) == LP8727_STAT_EOC ? |
347 | POWER_SUPPLY_STATUS_FULL : | 345 | POWER_SUPPLY_STATUS_FULL : |
348 | POWER_SUPPLY_STATUS_CHARGING; | 346 | POWER_SUPPLY_STATUS_CHARGING; |
349 | } else { | 347 | } else { |
@@ -351,8 +349,8 @@ static int lp8727_battery_get_property(struct power_supply *psy, | |||
351 | } | 349 | } |
352 | break; | 350 | break; |
353 | case POWER_SUPPLY_PROP_HEALTH: | 351 | case POWER_SUPPLY_PROP_HEALTH: |
354 | lp8727_read_byte(pchg, STATUS2, &read); | 352 | lp8727_read_byte(pchg, LP8727_STATUS2, &read); |
355 | temp = (read & TEMP_STAT) >> TEMP_SHIFT; | 353 | temp = (read & LP8727_TEMP_STAT) >> LP8727_TEMP_SHIFT; |
356 | 354 | ||
357 | val->intval = lp8727_is_high_temperature(temp) ? | 355 | val->intval = lp8727_is_high_temperature(temp) ? |
358 | POWER_SUPPLY_HEALTH_OVERHEAT : | 356 | POWER_SUPPLY_HEALTH_OVERHEAT : |
@@ -404,7 +402,7 @@ static void lp8727_charger_changed(struct power_supply *psy) | |||
404 | eoc_level = pchg->chg_parm->eoc_level; | 402 | eoc_level = pchg->chg_parm->eoc_level; |
405 | ichg = pchg->chg_parm->ichg; | 403 | ichg = pchg->chg_parm->ichg; |
406 | val = (ichg << 4) | eoc_level; | 404 | val = (ichg << 4) | eoc_level; |
407 | lp8727_write_byte(pchg, CHGCTRL2, val); | 405 | lp8727_write_byte(pchg, LP8727_CHGCTRL2, val); |
408 | } | 406 | } |
409 | } | 407 | } |
410 | } | 408 | } |