summaryrefslogtreecommitdiff
path: root/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
diff options
context:
space:
mode:
authorMichael Sevakis <jethead71@rockbox.org>2008-12-21 18:10:36 +0000
committerMichael Sevakis <jethead71@rockbox.org>2008-12-21 18:10:36 +0000
commit5667682dd204a07c52f057506fd2eef05bf63f2e (patch)
treea5f4f3cb22751362a9ed7774698ca55d27819d16 /firmware/target/arm/imx31/gigabeat-s/power-imx31.c
parentc3c15cce88481a2504eb492ba06b6a691d8e998d (diff)
downloadrockbox-5667682dd204a07c52f057506fd2eef05bf63f2e.tar.gz
rockbox-5667682dd204a07c52f057506fd2eef05bf63f2e.zip
Gigabeat S: Implement charging and power control to charge from AC or USB. Hold MENU while plugging USB cable to charge from USB without connecting. Under Windows, plugging USB for charging only but not connecting still needs to be properly handled (driver popup issue) but it will charge when connected normally-- no issue under Linux. Some accomodating changes made to powermgmt.c will soon be made nicer.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19547 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/imx31/gigabeat-s/power-imx31.c')
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-imx31.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
index 17008cec4b..39724c7b75 100644
--- a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
+++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c
@@ -20,6 +20,8 @@
20 ****************************************************************************/ 20 ****************************************************************************/
21#include "config.h" 21#include "config.h"
22#include "system.h" 22#include "system.h"
23#include "usb.h"
24#include "usb_core.h"
23#include "power.h" 25#include "power.h"
24#include "power-imx31.h" 26#include "power-imx31.h"
25#include "backlight.h" 27#include "backlight.h"
@@ -29,35 +31,47 @@
29#include "i2c-imx31.h" 31#include "i2c-imx31.h"
30 32
31extern struct i2c_node si4700_i2c_node; 33extern struct i2c_node si4700_i2c_node;
34static unsigned int power_status = POWER_INPUT_NONE;
32 35
33static bool charger_detect = false; 36/* Detect which power sources are present. */
34
35/* This is called from the mc13783 interrupt thread */
36void charger_detect_event(void)
37{
38 charger_detect =
39 mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_CHGDETS;
40}
41
42unsigned int power_input_status(void) 37unsigned int power_input_status(void)
43{ 38{
44 unsigned int status = POWER_INPUT_NONE; 39 unsigned int status = power_status;
45 40
46 if ((GPIO3_DR & (1 << 20)) != 0) 41 if (GPIO3_DR & (1 << 20))
47 status |= POWER_INPUT_BATTERY; 42 status |= POWER_INPUT_BATTERY;
48 43
49 if (charger_detect) 44 if (usb_allowed_current() < 500)
50 status |= POWER_INPUT_MAIN_CHARGER; 45 {
46 /* ACK that USB is connected but NOT chargeable */
47 status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER);
48 }
51 49
52 return status; 50 return status;
53} 51}
54 52
55/* Returns true if the unit is charging the batteries. */ 53/* Detect changes in presence of the AC adaptor. */
56bool charging_state(void) 54void charger_main_detect_event(void)
57{ 55{
58 return false; 56 if (mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_SE1S)
57 power_status |= POWER_INPUT_MAIN_CHARGER;
58 else
59 power_status &= ~POWER_INPUT_MAIN_CHARGER;
59} 60}
60 61
62/* Detect changes in USB bus power. Called from usb connect event handler. */
63void charger_usb_detect_event(int status)
64{
65 /* USB plugged does not imply charging is possible or even
66 * powering the device to maintain the battery. */
67 if (status == USB_INSERTED)
68 power_status |= POWER_INPUT_USB_CHARGER;
69 else
70 power_status &= ~POWER_INPUT_USB_CHARGER;
71}
72
73/* charging_state is implemented in powermgmt-imx31.c */
74
61void ide_power_enable(bool on) 75void ide_power_enable(bool on)
62{ 76{
63 if (!on) 77 if (!on)
@@ -129,9 +143,8 @@ void power_off(void)
129void power_init(void) 143void power_init(void)
130{ 144{
131 /* Poll initial state */ 145 /* Poll initial state */
132 charger_detect_event(); 146 charger_main_detect_event();
133 147
134 /* Enable detect event */ 148 /* Enable detect event */
135 mc13783_enable_event(MC13783_CHGDET_EVENT); 149 mc13783_enable_event(MC13783_SE1_EVENT);
136} 150}
137