summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
index 11276a6c3a..5b255a0e27 100644
--- a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
+++ b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c
@@ -33,7 +33,7 @@
33#include "fmradio_i2c.h" 33#include "fmradio_i2c.h"
34#endif 34#endif
35 35
36static unsigned int power_status = POWER_INPUT_NONE; 36static unsigned long power_status = POWER_INPUT_NONE;
37 37
38/* Detect which power sources are present. */ 38/* Detect which power sources are present. */
39unsigned int power_input_status(void) 39unsigned int power_input_status(void)
@@ -58,24 +58,28 @@ void usb_charging_maxcurrent_change(int maxcurrent)
58 /* Nothing to do */ 58 /* Nothing to do */
59} 59}
60 60
61/* Detect changes in presence of the AC adaptor. */ 61/* Helper to update the charger status */
62static void update_main_charger(bool present)
63{
64 bitmod32(&power_status, present ? POWER_INPUT_MAIN_CHARGER : 0,
65 POWER_INPUT_MAIN_CHARGER);
66}
67
68/* Detect changes in presence of the AC adaptor. Called from PMIC ISR. */
62void charger_main_detect_event(void) 69void charger_main_detect_event(void)
63{ 70{
64 if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S) 71 update_main_charger(mc13783_event_sense(MC13783_INT_ID_SE1)
65 power_status |= POWER_INPUT_MAIN_CHARGER; 72 & MC13783_SE1S);
66 else
67 power_status &= ~POWER_INPUT_MAIN_CHARGER;
68} 73}
69 74
70/* Detect changes in USB bus power. Called from usb connect event handler. */ 75/* Detect changes in USB bus power. Called from usb connect event ISR. */
71void charger_usb_detect_event(int status) 76void charger_usb_detect_event(int status)
72{ 77{
73 /* USB plugged does not imply charging is possible or even 78 /* USB plugged does not imply charging is possible or even
74 * powering the device to maintain the battery. */ 79 * powering the device to maintain the battery. */
75 if (status == USB_INSERTED) 80 bitmod32(&power_status,
76 power_status |= POWER_INPUT_USB_CHARGER; 81 status == USB_INSERTED ? POWER_INPUT_USB_CHARGER : 0,
77 else 82 POWER_INPUT_USB_CHARGER);
78 power_status &= ~POWER_INPUT_USB_CHARGER;
79} 83}
80 84
81/* charging_state is implemented in powermgmt-imx31.c */ 85/* charging_state is implemented in powermgmt-imx31.c */
@@ -152,8 +156,9 @@ void power_init(void)
152#endif 156#endif
153 157
154 /* Poll initial state */ 158 /* Poll initial state */
155 charger_main_detect_event(); 159 update_main_charger(mc13783_read(MC13783_INTERRUPT_SENSE0)
160 & MC13783_SE1S);
156 161
157 /* Enable detect event */ 162 /* Enable detect event */
158 mc13783_enable_event(MC13783_SE1_EVENT); 163 mc13783_enable_event(MC13783_SE1_EVENT, true);
159} 164}