diff options
-rw-r--r-- | drivers/power/Kconfig | 7 | ||||
-rw-r--r-- | drivers/power/Makefile | 1 | ||||
-rw-r--r-- | drivers/power/wm8350_power.c | 515 | ||||
-rw-r--r-- | include/linux/mfd/wm8350/core.h | 26 | ||||
-rw-r--r-- | include/linux/mfd/wm8350/supply.h | 23 |
5 files changed, 571 insertions, 1 deletions
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig index 8e0c2b47803c..52f86767f72e 100644 --- a/drivers/power/Kconfig +++ b/drivers/power/Kconfig | |||
@@ -29,6 +29,13 @@ config APM_POWER | |||
29 | Say Y here to enable support APM status emulation using | 29 | Say Y here to enable support APM status emulation using |
30 | battery class devices. | 30 | battery class devices. |
31 | 31 | ||
32 | config WM8350_POWER | ||
33 | tristate "WM8350 PMU support" | ||
34 | depends on MFD_WM8350 | ||
35 | help | ||
36 | Say Y here to enable support for the power management unit | ||
37 | provided by the Wolfson Microelectronics WM8350 PMIC. | ||
38 | |||
32 | config BATTERY_DS2760 | 39 | config BATTERY_DS2760 |
33 | tristate "DS2760 battery driver (HP iPAQ & others)" | 40 | tristate "DS2760 battery driver (HP iPAQ & others)" |
34 | select W1 | 41 | select W1 |
diff --git a/drivers/power/Makefile b/drivers/power/Makefile index e8f1ecec5d8f..e6f68655d9e8 100644 --- a/drivers/power/Makefile +++ b/drivers/power/Makefile | |||
@@ -16,6 +16,7 @@ obj-$(CONFIG_POWER_SUPPLY) += power_supply.o | |||
16 | 16 | ||
17 | obj-$(CONFIG_PDA_POWER) += pda_power.o | 17 | obj-$(CONFIG_PDA_POWER) += pda_power.o |
18 | obj-$(CONFIG_APM_POWER) += apm_power.o | 18 | obj-$(CONFIG_APM_POWER) += apm_power.o |
19 | obj-$(CONFIG_WM8350_POWER) += wm8350_power.o | ||
19 | 20 | ||
20 | obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o | 21 | obj-$(CONFIG_BATTERY_DS2760) += ds2760_battery.o |
21 | obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o | 22 | obj-$(CONFIG_BATTERY_PMU) += pmu_battery.o |
diff --git a/drivers/power/wm8350_power.c b/drivers/power/wm8350_power.c new file mode 100644 index 000000000000..9c0a847a1139 --- /dev/null +++ b/drivers/power/wm8350_power.c | |||
@@ -0,0 +1,515 @@ | |||
1 | /* | ||
2 | * Battery driver for wm8350 PMIC | ||
3 | * | ||
4 | * Copyright 2007, 2008 Wolfson Microelectronics PLC. | ||
5 | * | ||
6 | * Based on OLPC Battery Driver | ||
7 | * | ||
8 | * Copyright 2006 David Woodhouse <dwmw2@infradead.org> | ||
9 | * | ||
10 | * This program is free software; you can redistribute it and/or modify | ||
11 | * it under the terms of the GNU General Public License version 2 as | ||
12 | * published by the Free Software Foundation. | ||
13 | */ | ||
14 | |||
15 | #include <linux/module.h> | ||
16 | #include <linux/err.h> | ||
17 | #include <linux/platform_device.h> | ||
18 | #include <linux/power_supply.h> | ||
19 | #include <linux/mfd/wm8350/supply.h> | ||
20 | #include <linux/mfd/wm8350/core.h> | ||
21 | #include <linux/mfd/wm8350/comparator.h> | ||
22 | |||
23 | static int wm8350_read_battery_uvolts(struct wm8350 *wm8350) | ||
24 | { | ||
25 | return wm8350_read_auxadc(wm8350, WM8350_AUXADC_BATT, 0, 0) | ||
26 | * WM8350_AUX_COEFF; | ||
27 | } | ||
28 | |||
29 | static int wm8350_read_line_uvolts(struct wm8350 *wm8350) | ||
30 | { | ||
31 | return wm8350_read_auxadc(wm8350, WM8350_AUXADC_LINE, 0, 0) | ||
32 | * WM8350_AUX_COEFF; | ||
33 | } | ||
34 | |||
35 | static int wm8350_read_usb_uvolts(struct wm8350 *wm8350) | ||
36 | { | ||
37 | return wm8350_read_auxadc(wm8350, WM8350_AUXADC_USB, 0, 0) | ||
38 | * WM8350_AUX_COEFF; | ||
39 | } | ||
40 | |||
41 | #define WM8350_BATT_SUPPLY 1 | ||
42 | #define WM8350_USB_SUPPLY 2 | ||
43 | #define WM8350_LINE_SUPPLY 4 | ||
44 | |||
45 | static inline int wm8350_charge_time_min(struct wm8350 *wm8350, int min) | ||
46 | { | ||
47 | if (wm8350->rev < WM8350_REV_G) | ||
48 | return (((min - 30) / 15) & 0xf) << 8; | ||
49 | else | ||
50 | return (((min - 30) / 30) & 0xf) << 8; | ||
51 | } | ||
52 | |||
53 | static int wm8350_get_supplies(struct wm8350 *wm8350) | ||
54 | { | ||
55 | u16 sm, ov, co, chrg; | ||
56 | int supplies = 0; | ||
57 | |||
58 | sm = wm8350_reg_read(wm8350, WM8350_STATE_MACHINE_STATUS); | ||
59 | ov = wm8350_reg_read(wm8350, WM8350_MISC_OVERRIDES); | ||
60 | co = wm8350_reg_read(wm8350, WM8350_COMPARATOR_OVERRIDES); | ||
61 | chrg = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2); | ||
62 | |||
63 | /* USB_SM */ | ||
64 | sm = (sm & WM8350_USB_SM_MASK) >> WM8350_USB_SM_SHIFT; | ||
65 | |||
66 | /* CHG_ISEL */ | ||
67 | chrg &= WM8350_CHG_ISEL_MASK; | ||
68 | |||
69 | /* If the USB state machine is active then we're using that with or | ||
70 | * without battery, otherwise check for wall supply */ | ||
71 | if (((sm == WM8350_USB_SM_100_SLV) || | ||
72 | (sm == WM8350_USB_SM_500_SLV) || | ||
73 | (sm == WM8350_USB_SM_STDBY_SLV)) | ||
74 | && !(ov & WM8350_USB_LIMIT_OVRDE)) | ||
75 | supplies = WM8350_USB_SUPPLY; | ||
76 | else if (((sm == WM8350_USB_SM_100_SLV) || | ||
77 | (sm == WM8350_USB_SM_500_SLV) || | ||
78 | (sm == WM8350_USB_SM_STDBY_SLV)) | ||
79 | && (ov & WM8350_USB_LIMIT_OVRDE) && (chrg == 0)) | ||
80 | supplies = WM8350_USB_SUPPLY | WM8350_BATT_SUPPLY; | ||
81 | else if (co & WM8350_WALL_FB_OVRDE) | ||
82 | supplies = WM8350_LINE_SUPPLY; | ||
83 | else | ||
84 | supplies = WM8350_BATT_SUPPLY; | ||
85 | |||
86 | return supplies; | ||
87 | } | ||
88 | |||
89 | static int wm8350_charger_config(struct wm8350 *wm8350, | ||
90 | struct wm8350_charger_policy *policy) | ||
91 | { | ||
92 | u16 reg, eoc_mA, fast_limit_mA; | ||
93 | |||
94 | if (!policy) { | ||
95 | dev_warn(wm8350->dev, | ||
96 | "No charger policy, charger not configured.\n"); | ||
97 | return -EINVAL; | ||
98 | } | ||
99 | |||
100 | /* make sure USB fast charge current is not > 500mA */ | ||
101 | if (policy->fast_limit_USB_mA > 500) { | ||
102 | dev_err(wm8350->dev, "USB fast charge > 500mA\n"); | ||
103 | return -EINVAL; | ||
104 | } | ||
105 | |||
106 | eoc_mA = WM8350_CHG_EOC_mA(policy->eoc_mA); | ||
107 | |||
108 | wm8350_reg_unlock(wm8350); | ||
109 | |||
110 | reg = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1) | ||
111 | & WM8350_CHG_ENA_R168; | ||
112 | wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1, | ||
113 | reg | eoc_mA | policy->trickle_start_mV | | ||
114 | WM8350_CHG_TRICKLE_TEMP_CHOKE | | ||
115 | WM8350_CHG_TRICKLE_USB_CHOKE | | ||
116 | WM8350_CHG_FAST_USB_THROTTLE); | ||
117 | |||
118 | if (wm8350_get_supplies(wm8350) & WM8350_USB_SUPPLY) { | ||
119 | fast_limit_mA = | ||
120 | WM8350_CHG_FAST_LIMIT_mA(policy->fast_limit_USB_mA); | ||
121 | wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2, | ||
122 | policy->charge_mV | policy->trickle_charge_USB_mA | | ||
123 | fast_limit_mA | wm8350_charge_time_min(wm8350, | ||
124 | policy->charge_timeout)); | ||
125 | |||
126 | } else { | ||
127 | fast_limit_mA = | ||
128 | WM8350_CHG_FAST_LIMIT_mA(policy->fast_limit_mA); | ||
129 | wm8350_reg_write(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2, | ||
130 | policy->charge_mV | policy->trickle_charge_mA | | ||
131 | fast_limit_mA | wm8350_charge_time_min(wm8350, | ||
132 | policy->charge_timeout)); | ||
133 | } | ||
134 | |||
135 | wm8350_reg_lock(wm8350); | ||
136 | return 0; | ||
137 | } | ||
138 | |||
139 | static int wm8350_batt_status(struct wm8350 *wm8350) | ||
140 | { | ||
141 | u16 state; | ||
142 | |||
143 | state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2); | ||
144 | state &= WM8350_CHG_STS_MASK; | ||
145 | |||
146 | switch (state) { | ||
147 | case WM8350_CHG_STS_OFF: | ||
148 | return POWER_SUPPLY_STATUS_DISCHARGING; | ||
149 | |||
150 | case WM8350_CHG_STS_TRICKLE: | ||
151 | case WM8350_CHG_STS_FAST: | ||
152 | return POWER_SUPPLY_STATUS_CHARGING; | ||
153 | |||
154 | default: | ||
155 | return POWER_SUPPLY_STATUS_UNKNOWN; | ||
156 | } | ||
157 | } | ||
158 | |||
159 | static ssize_t charger_state_show(struct device *dev, | ||
160 | struct device_attribute *attr, char *buf) | ||
161 | { | ||
162 | struct wm8350 *wm8350 = dev_get_drvdata(dev); | ||
163 | char *charge; | ||
164 | int state; | ||
165 | |||
166 | state = wm8350_reg_read(wm8350, WM8350_BATTERY_CHARGER_CONTROL_2) & | ||
167 | WM8350_CHG_STS_MASK; | ||
168 | switch (state) { | ||
169 | case WM8350_CHG_STS_OFF: | ||
170 | charge = "Charger Off"; | ||
171 | break; | ||
172 | case WM8350_CHG_STS_TRICKLE: | ||
173 | charge = "Trickle Charging"; | ||
174 | break; | ||
175 | case WM8350_CHG_STS_FAST: | ||
176 | charge = "Fast Charging"; | ||
177 | break; | ||
178 | default: | ||
179 | return 0; | ||
180 | } | ||
181 | |||
182 | return sprintf(buf, "%s\n", charge); | ||
183 | } | ||
184 | |||
185 | static DEVICE_ATTR(charger_state, 0444, charger_state_show, NULL); | ||
186 | |||
187 | static void wm8350_charger_handler(struct wm8350 *wm8350, int irq, void *data) | ||
188 | { | ||
189 | struct wm8350_power *power = &wm8350->power; | ||
190 | struct wm8350_charger_policy *policy = power->policy; | ||
191 | |||
192 | switch (irq) { | ||
193 | case WM8350_IRQ_CHG_BAT_HOT: | ||
194 | dev_err(wm8350->dev, "battery too hot\n"); | ||
195 | break; | ||
196 | case WM8350_IRQ_CHG_BAT_COLD: | ||
197 | dev_err(wm8350->dev, "battery too cold\n"); | ||
198 | break; | ||
199 | case WM8350_IRQ_CHG_BAT_FAIL: | ||
200 | dev_err(wm8350->dev, "battery failed\n"); | ||
201 | break; | ||
202 | case WM8350_IRQ_CHG_TO: | ||
203 | dev_err(wm8350->dev, "charger timeout\n"); | ||
204 | break; | ||
205 | case WM8350_IRQ_CHG_END: | ||
206 | power_supply_changed(&power->battery); | ||
207 | break; | ||
208 | case WM8350_IRQ_CHG_START: | ||
209 | power_supply_changed(&power->battery); | ||
210 | break; | ||
211 | |||
212 | case WM8350_IRQ_CHG_FAST_RDY: | ||
213 | dev_dbg(wm8350->dev, "fast charger ready\n"); | ||
214 | wm8350_charger_config(wm8350, policy); | ||
215 | wm8350_reg_unlock(wm8350); | ||
216 | wm8350_set_bits(wm8350, WM8350_BATTERY_CHARGER_CONTROL_1, | ||
217 | WM8350_CHG_FAST); | ||
218 | wm8350_reg_lock(wm8350); | ||
219 | break; | ||
220 | |||
221 | case WM8350_IRQ_CHG_VBATT_LT_3P9: | ||
222 | dev_warn(wm8350->dev, "battery < 3.9V\n"); | ||
223 | break; | ||
224 | case WM8350_IRQ_CHG_VBATT_LT_3P1: | ||
225 | dev_warn(wm8350->dev, "battery < 3.1V\n"); | ||
226 | break; | ||
227 | case WM8350_IRQ_CHG_VBATT_LT_2P85: | ||
228 | dev_warn(wm8350->dev, "battery < 2.85V\n"); | ||
229 | break; | ||
230 | |||
231 | /* Supply change. We will overnotify but it should do | ||
232 | * no harm. */ | ||
233 | case WM8350_IRQ_EXT_USB_FB: | ||
234 | case WM8350_IRQ_EXT_WALL_FB: | ||
235 | wm8350_charger_config(wm8350, policy); | ||
236 | case WM8350_IRQ_EXT_BAT_FB: /* Fall through */ | ||
237 | power_supply_changed(&power->battery); | ||
238 | power_supply_changed(&power->usb); | ||
239 | power_supply_changed(&power->ac); | ||
240 | break; | ||
241 | |||
242 | default: | ||
243 | dev_err(wm8350->dev, "Unknown interrupt %d\n", irq); | ||
244 | } | ||
245 | } | ||
246 | |||
247 | /********************************************************************* | ||
248 | * AC Power | ||
249 | *********************************************************************/ | ||
250 | static int wm8350_ac_get_prop(struct power_supply *psy, | ||
251 | enum power_supply_property psp, | ||
252 | union power_supply_propval *val) | ||
253 | { | ||
254 | struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); | ||
255 | int ret = 0; | ||
256 | |||
257 | switch (psp) { | ||
258 | case POWER_SUPPLY_PROP_ONLINE: | ||
259 | val->intval = !!(wm8350_get_supplies(wm8350) & | ||
260 | WM8350_LINE_SUPPLY); | ||
261 | break; | ||
262 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
263 | val->intval = wm8350_read_line_uvolts(wm8350); | ||
264 | break; | ||
265 | default: | ||
266 | ret = -EINVAL; | ||
267 | break; | ||
268 | } | ||
269 | return ret; | ||
270 | } | ||
271 | |||
272 | static enum power_supply_property wm8350_ac_props[] = { | ||
273 | POWER_SUPPLY_PROP_ONLINE, | ||
274 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
275 | }; | ||
276 | |||
277 | /********************************************************************* | ||
278 | * USB Power | ||
279 | *********************************************************************/ | ||
280 | static int wm8350_usb_get_prop(struct power_supply *psy, | ||
281 | enum power_supply_property psp, | ||
282 | union power_supply_propval *val) | ||
283 | { | ||
284 | struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); | ||
285 | int ret = 0; | ||
286 | |||
287 | switch (psp) { | ||
288 | case POWER_SUPPLY_PROP_ONLINE: | ||
289 | val->intval = !!(wm8350_get_supplies(wm8350) & | ||
290 | WM8350_USB_SUPPLY); | ||
291 | break; | ||
292 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
293 | val->intval = wm8350_read_usb_uvolts(wm8350); | ||
294 | break; | ||
295 | default: | ||
296 | ret = -EINVAL; | ||
297 | break; | ||
298 | } | ||
299 | return ret; | ||
300 | } | ||
301 | |||
302 | static enum power_supply_property wm8350_usb_props[] = { | ||
303 | POWER_SUPPLY_PROP_ONLINE, | ||
304 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
305 | }; | ||
306 | |||
307 | /********************************************************************* | ||
308 | * Battery properties | ||
309 | *********************************************************************/ | ||
310 | |||
311 | static int wm8350_bat_get_property(struct power_supply *psy, | ||
312 | enum power_supply_property psp, | ||
313 | union power_supply_propval *val) | ||
314 | { | ||
315 | struct wm8350 *wm8350 = dev_get_drvdata(psy->dev->parent); | ||
316 | int ret = 0; | ||
317 | |||
318 | switch (psp) { | ||
319 | case POWER_SUPPLY_PROP_STATUS: | ||
320 | val->intval = wm8350_batt_status(wm8350); | ||
321 | break; | ||
322 | case POWER_SUPPLY_PROP_ONLINE: | ||
323 | val->intval = !!(wm8350_get_supplies(wm8350) & | ||
324 | WM8350_BATT_SUPPLY); | ||
325 | break; | ||
326 | case POWER_SUPPLY_PROP_VOLTAGE_NOW: | ||
327 | val->intval = wm8350_read_battery_uvolts(wm8350); | ||
328 | break; | ||
329 | default: | ||
330 | ret = -EINVAL; | ||
331 | break; | ||
332 | } | ||
333 | |||
334 | return ret; | ||
335 | } | ||
336 | |||
337 | static enum power_supply_property wm8350_bat_props[] = { | ||
338 | POWER_SUPPLY_PROP_STATUS, | ||
339 | POWER_SUPPLY_PROP_ONLINE, | ||
340 | POWER_SUPPLY_PROP_VOLTAGE_NOW, | ||
341 | }; | ||
342 | |||
343 | /********************************************************************* | ||
344 | * Initialisation | ||
345 | *********************************************************************/ | ||
346 | |||
347 | static void wm8350_init_charger(struct wm8350 *wm8350) | ||
348 | { | ||
349 | /* register our interest in charger events */ | ||
350 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT, | ||
351 | wm8350_charger_handler, NULL); | ||
352 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT); | ||
353 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD, | ||
354 | wm8350_charger_handler, NULL); | ||
355 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD); | ||
356 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL, | ||
357 | wm8350_charger_handler, NULL); | ||
358 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL); | ||
359 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_TO, | ||
360 | wm8350_charger_handler, NULL); | ||
361 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_TO); | ||
362 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_END, | ||
363 | wm8350_charger_handler, NULL); | ||
364 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_END); | ||
365 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_START, | ||
366 | wm8350_charger_handler, NULL); | ||
367 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_START); | ||
368 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY, | ||
369 | wm8350_charger_handler, NULL); | ||
370 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_FAST_RDY); | ||
371 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9, | ||
372 | wm8350_charger_handler, NULL); | ||
373 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9); | ||
374 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1, | ||
375 | wm8350_charger_handler, NULL); | ||
376 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1); | ||
377 | wm8350_register_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85, | ||
378 | wm8350_charger_handler, NULL); | ||
379 | wm8350_unmask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85); | ||
380 | |||
381 | /* and supply change events */ | ||
382 | wm8350_register_irq(wm8350, WM8350_IRQ_EXT_USB_FB, | ||
383 | wm8350_charger_handler, NULL); | ||
384 | wm8350_unmask_irq(wm8350, WM8350_IRQ_EXT_USB_FB); | ||
385 | wm8350_register_irq(wm8350, WM8350_IRQ_EXT_WALL_FB, | ||
386 | wm8350_charger_handler, NULL); | ||
387 | wm8350_unmask_irq(wm8350, WM8350_IRQ_EXT_WALL_FB); | ||
388 | wm8350_register_irq(wm8350, WM8350_IRQ_EXT_BAT_FB, | ||
389 | wm8350_charger_handler, NULL); | ||
390 | wm8350_unmask_irq(wm8350, WM8350_IRQ_EXT_BAT_FB); | ||
391 | } | ||
392 | |||
393 | static void free_charger_irq(struct wm8350 *wm8350) | ||
394 | { | ||
395 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT); | ||
396 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_HOT); | ||
397 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD); | ||
398 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_COLD); | ||
399 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL); | ||
400 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_BAT_FAIL); | ||
401 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_TO); | ||
402 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_TO); | ||
403 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_END); | ||
404 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_END); | ||
405 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_START); | ||
406 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_START); | ||
407 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9); | ||
408 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P9); | ||
409 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1); | ||
410 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_3P1); | ||
411 | wm8350_mask_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85); | ||
412 | wm8350_free_irq(wm8350, WM8350_IRQ_CHG_VBATT_LT_2P85); | ||
413 | wm8350_mask_irq(wm8350, WM8350_IRQ_EXT_USB_FB); | ||
414 | wm8350_free_irq(wm8350, WM8350_IRQ_EXT_USB_FB); | ||
415 | wm8350_mask_irq(wm8350, WM8350_IRQ_EXT_WALL_FB); | ||
416 | wm8350_free_irq(wm8350, WM8350_IRQ_EXT_WALL_FB); | ||
417 | wm8350_mask_irq(wm8350, WM8350_IRQ_EXT_BAT_FB); | ||
418 | wm8350_free_irq(wm8350, WM8350_IRQ_EXT_BAT_FB); | ||
419 | } | ||
420 | |||
421 | static __devinit int wm8350_power_probe(struct platform_device *pdev) | ||
422 | { | ||
423 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
424 | struct wm8350_power *power = &wm8350->power; | ||
425 | struct wm8350_charger_policy *policy = power->policy; | ||
426 | struct power_supply *usb = &power->usb; | ||
427 | struct power_supply *battery = &power->battery; | ||
428 | struct power_supply *ac = &power->ac; | ||
429 | int ret; | ||
430 | |||
431 | ac->name = "wm8350-ac"; | ||
432 | ac->type = POWER_SUPPLY_TYPE_MAINS; | ||
433 | ac->properties = wm8350_ac_props; | ||
434 | ac->num_properties = ARRAY_SIZE(wm8350_ac_props); | ||
435 | ac->get_property = wm8350_ac_get_prop; | ||
436 | ret = power_supply_register(&pdev->dev, ac); | ||
437 | if (ret) | ||
438 | return ret; | ||
439 | |||
440 | battery->name = "wm8350-battery"; | ||
441 | battery->properties = wm8350_bat_props; | ||
442 | battery->num_properties = ARRAY_SIZE(wm8350_bat_props); | ||
443 | battery->get_property = wm8350_bat_get_property; | ||
444 | battery->use_for_apm = 1; | ||
445 | ret = power_supply_register(&pdev->dev, battery); | ||
446 | if (ret) | ||
447 | goto battery_failed; | ||
448 | |||
449 | usb->name = "wm8350-usb", | ||
450 | usb->type = POWER_SUPPLY_TYPE_USB; | ||
451 | usb->properties = wm8350_usb_props; | ||
452 | usb->num_properties = ARRAY_SIZE(wm8350_usb_props); | ||
453 | usb->get_property = wm8350_usb_get_prop; | ||
454 | ret = power_supply_register(&pdev->dev, usb); | ||
455 | if (ret) | ||
456 | goto usb_failed; | ||
457 | |||
458 | ret = device_create_file(&pdev->dev, &dev_attr_charger_state); | ||
459 | if (ret < 0) | ||
460 | dev_warn(wm8350->dev, "failed to add charge sysfs: %d\n", ret); | ||
461 | ret = 0; | ||
462 | |||
463 | wm8350_init_charger(wm8350); | ||
464 | if (wm8350_charger_config(wm8350, policy) == 0) { | ||
465 | wm8350_reg_unlock(wm8350); | ||
466 | wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CHG_ENA); | ||
467 | wm8350_reg_lock(wm8350); | ||
468 | } | ||
469 | |||
470 | return ret; | ||
471 | |||
472 | usb_failed: | ||
473 | power_supply_unregister(battery); | ||
474 | battery_failed: | ||
475 | power_supply_unregister(ac); | ||
476 | |||
477 | return ret; | ||
478 | } | ||
479 | |||
480 | static __devexit int wm8350_power_remove(struct platform_device *pdev) | ||
481 | { | ||
482 | struct wm8350 *wm8350 = platform_get_drvdata(pdev); | ||
483 | struct wm8350_power *power = &wm8350->power; | ||
484 | |||
485 | free_charger_irq(wm8350); | ||
486 | device_remove_file(&pdev->dev, &dev_attr_charger_state); | ||
487 | power_supply_unregister(&power->battery); | ||
488 | power_supply_unregister(&power->ac); | ||
489 | power_supply_unregister(&power->usb); | ||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | static struct platform_driver wm8350_power_driver = { | ||
494 | .probe = wm8350_power_probe, | ||
495 | .remove = __devexit_p(wm8350_power_remove), | ||
496 | .driver = { | ||
497 | .name = "wm8350-power", | ||
498 | }, | ||
499 | }; | ||
500 | |||
501 | static int __init wm8350_power_init(void) | ||
502 | { | ||
503 | return platform_driver_register(&wm8350_power_driver); | ||
504 | } | ||
505 | module_init(wm8350_power_init); | ||
506 | |||
507 | static void __exit wm8350_power_exit(void) | ||
508 | { | ||
509 | platform_driver_unregister(&wm8350_power_driver); | ||
510 | } | ||
511 | module_exit(wm8350_power_exit); | ||
512 | |||
513 | MODULE_LICENSE("GPL"); | ||
514 | MODULE_DESCRIPTION("Power supply driver for WM8350"); | ||
515 | MODULE_ALIAS("platform:wm8350-power"); | ||
diff --git a/include/linux/mfd/wm8350/core.h b/include/linux/mfd/wm8350/core.h index cc190055b9c4..d2614dfc9397 100644 --- a/include/linux/mfd/wm8350/core.h +++ b/include/linux/mfd/wm8350/core.h | |||
@@ -57,6 +57,9 @@ | |||
57 | #define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25 | 57 | #define WM8350_OVER_CURRENT_INT_STATUS_MASK 0x25 |
58 | #define WM8350_GPIO_INT_STATUS_MASK 0x26 | 58 | #define WM8350_GPIO_INT_STATUS_MASK 0x26 |
59 | #define WM8350_COMPARATOR_INT_STATUS_MASK 0x27 | 59 | #define WM8350_COMPARATOR_INT_STATUS_MASK 0x27 |
60 | #define WM8350_MISC_OVERRIDES 0xE3 | ||
61 | #define WM8350_COMPARATOR_OVERRIDES 0xE7 | ||
62 | #define WM8350_STATE_MACHINE_STATUS 0xE9 | ||
60 | 63 | ||
61 | #define WM8350_MAX_REGISTER 0xFF | 64 | #define WM8350_MAX_REGISTER 0xFF |
62 | 65 | ||
@@ -523,6 +526,29 @@ | |||
523 | #define WM8350_DC2_STS 0x0002 | 526 | #define WM8350_DC2_STS 0x0002 |
524 | #define WM8350_DC1_STS 0x0001 | 527 | #define WM8350_DC1_STS 0x0001 |
525 | 528 | ||
529 | /* | ||
530 | * R227 (0xE3) - Misc Overrides | ||
531 | */ | ||
532 | #define WM8350_USB_LIMIT_OVRDE 0x0400 | ||
533 | |||
534 | /* | ||
535 | * R227 (0xE7) - Comparator Overrides | ||
536 | */ | ||
537 | #define WM8350_USB_FB_OVRDE 0x8000 | ||
538 | #define WM8350_WALL_FB_OVRDE 0x4000 | ||
539 | #define WM8350_BATT_FB_OVRDE 0x2000 | ||
540 | |||
541 | |||
542 | /* | ||
543 | * R233 (0xE9) - State Machinine Status | ||
544 | */ | ||
545 | #define WM8350_USB_SM_MASK 0x0700 | ||
546 | #define WM8350_USB_SM_SHIFT 8 | ||
547 | |||
548 | #define WM8350_USB_SM_100_SLV 1 | ||
549 | #define WM8350_USB_SM_500_SLV 5 | ||
550 | #define WM8350_USB_SM_STDBY_SLV 7 | ||
551 | |||
526 | /* WM8350 wake up conditions */ | 552 | /* WM8350 wake up conditions */ |
527 | #define WM8350_IRQ_WKUP_OFF_STATE 43 | 553 | #define WM8350_IRQ_WKUP_OFF_STATE 43 |
528 | #define WM8350_IRQ_WKUP_HIB_STATE 44 | 554 | #define WM8350_IRQ_WKUP_HIB_STATE 44 |
diff --git a/include/linux/mfd/wm8350/supply.h b/include/linux/mfd/wm8350/supply.h index 1c8f3cde79b0..79721513fa9f 100644 --- a/include/linux/mfd/wm8350/supply.h +++ b/include/linux/mfd/wm8350/supply.h | |||
@@ -13,7 +13,8 @@ | |||
13 | #ifndef __LINUX_MFD_WM8350_SUPPLY_H_ | 13 | #ifndef __LINUX_MFD_WM8350_SUPPLY_H_ |
14 | #define __LINUX_MFD_WM8350_SUPPLY_H_ | 14 | #define __LINUX_MFD_WM8350_SUPPLY_H_ |
15 | 15 | ||
16 | #include <linux/platform_device.h> | 16 | #include <linux/mutex.h> |
17 | #include <linux/power_supply.h> | ||
17 | 18 | ||
18 | /* | 19 | /* |
19 | * Charger registers | 20 | * Charger registers |
@@ -104,8 +105,28 @@ | |||
104 | #define WM8350_IRQ_EXT_WALL_FB 37 | 105 | #define WM8350_IRQ_EXT_WALL_FB 37 |
105 | #define WM8350_IRQ_EXT_BAT_FB 38 | 106 | #define WM8350_IRQ_EXT_BAT_FB 38 |
106 | 107 | ||
108 | /* | ||
109 | * Policy to control charger state machine. | ||
110 | */ | ||
111 | struct wm8350_charger_policy { | ||
112 | |||
113 | /* charger state machine policy - set in machine driver */ | ||
114 | int eoc_mA; /* end of charge current (mA) */ | ||
115 | int charge_mV; /* charge voltage */ | ||
116 | int fast_limit_mA; /* fast charge current limit */ | ||
117 | int fast_limit_USB_mA; /* USB fast charge current limit */ | ||
118 | int charge_timeout; /* charge timeout (mins) */ | ||
119 | int trickle_start_mV; /* trickle charge starts at mV */ | ||
120 | int trickle_charge_mA; /* trickle charge current */ | ||
121 | int trickle_charge_USB_mA; /* USB trickle charge current */ | ||
122 | }; | ||
123 | |||
107 | struct wm8350_power { | 124 | struct wm8350_power { |
108 | struct platform_device *pdev; | 125 | struct platform_device *pdev; |
126 | struct power_supply battery; | ||
127 | struct power_supply usb; | ||
128 | struct power_supply ac; | ||
129 | struct wm8350_charger_policy *policy; | ||
109 | }; | 130 | }; |
110 | 131 | ||
111 | #endif | 132 | #endif |