From 5a8da163c842b08c6dbf1df6921507ec2fd5a534 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 2 Jan 2012 18:32:35 +0000 Subject: i.MX31 - Dethreading operations continue Dispense with "pmic" thread and process PMIC events directly within ISR. Add sense bit reading as part of the handling. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@31528 a1c6a512-1295-4272-9138-f99709370657 --- .../target/arm/imx31/gigabeat-s/power-gigabeat-s.c | 31 +++++++++++++--------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c') 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 @@ #include "fmradio_i2c.h" #endif -static unsigned int power_status = POWER_INPUT_NONE; +static unsigned long power_status = POWER_INPUT_NONE; /* Detect which power sources are present. */ unsigned int power_input_status(void) @@ -58,24 +58,28 @@ void usb_charging_maxcurrent_change(int maxcurrent) /* Nothing to do */ } -/* Detect changes in presence of the AC adaptor. */ +/* Helper to update the charger status */ +static void update_main_charger(bool present) +{ + bitmod32(&power_status, present ? POWER_INPUT_MAIN_CHARGER : 0, + POWER_INPUT_MAIN_CHARGER); +} + +/* Detect changes in presence of the AC adaptor. Called from PMIC ISR. */ void charger_main_detect_event(void) { - if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S) - power_status |= POWER_INPUT_MAIN_CHARGER; - else - power_status &= ~POWER_INPUT_MAIN_CHARGER; + update_main_charger(mc13783_event_sense(MC13783_INT_ID_SE1) + & MC13783_SE1S); } -/* Detect changes in USB bus power. Called from usb connect event handler. */ +/* Detect changes in USB bus power. Called from usb connect event ISR. */ void charger_usb_detect_event(int status) { /* USB plugged does not imply charging is possible or even * powering the device to maintain the battery. */ - if (status == USB_INSERTED) - power_status |= POWER_INPUT_USB_CHARGER; - else - power_status &= ~POWER_INPUT_USB_CHARGER; + bitmod32(&power_status, + status == USB_INSERTED ? POWER_INPUT_USB_CHARGER : 0, + POWER_INPUT_USB_CHARGER); } /* charging_state is implemented in powermgmt-imx31.c */ @@ -152,8 +156,9 @@ void power_init(void) #endif /* Poll initial state */ - charger_main_detect_event(); + update_main_charger(mc13783_read(MC13783_INTERRUPT_SENSE0) + & MC13783_SE1S); /* Enable detect event */ - mc13783_enable_event(MC13783_SE1_EVENT); + mc13783_enable_event(MC13783_SE1_EVENT, true); } -- cgit v1.2.3