diff options
| author | Michael Sevakis <jethead71@rockbox.org> | 2008-12-03 19:54:25 +0000 |
|---|---|---|
| committer | Michael Sevakis <jethead71@rockbox.org> | 2008-12-03 19:54:25 +0000 |
| commit | 58eb784a5d1f0ac800e656d5dfa3a1bff8fb2657 (patch) | |
| tree | 084c7b7c5d374fbfef2f8cddb3673a3b2a26a7df /firmware | |
| parent | 0d0cc039f88ced4f6db5c4468b19913f52cd08c8 (diff) | |
| download | rockbox-58eb784a5d1f0ac800e656d5dfa3a1bff8fb2657.zip rockbox-58eb784a5d1f0ac800e656d5dfa3a1bff8fb2657.tar.gz rockbox-58eb784a5d1f0ac800e656d5dfa3a1bff8fb2657.tar.bz2 rockbox-58eb784a5d1f0ac800e656d5dfa3a1bff8fb2657.tar.xz | |
Straighten out some powermanagement stuff. Give target complete control over how power inputs are sensed. Clean SIMULATOR stuff out of target files. Get rid of USB charging option on targets that don't support it or don't implement it yet. Menu string remains to avoid language incompatibility but should be removed on next cleanup for targets not using it (notice in english.lang). global_settings becomes incompatible for some builds and so plugin API version is incremented.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19315 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
33 files changed, 260 insertions, 376 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c index 1208973..07cc953 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c @@ -488,11 +488,7 @@ static void backlight_update_state(void) else #endif #if CONFIG_CHARGING - if (charger_inserted() -#ifdef HAVE_USB_POWER - || usb_powered() -#endif - ) + if (power_input_present()) backlight_timeout = backlight_timeout_plugged; else #endif @@ -532,11 +528,7 @@ static void remote_backlight_update_state(void) else #endif #if CONFIG_CHARGING - if (charger_inserted() -#ifdef HAVE_USB_POWER - || usb_powered() -#endif - ) + if (power_input_present()) remote_backlight_timeout = remote_backlight_timeout_plugged; else #endif diff --git a/firmware/export/config-gigabeat-s.h b/firmware/export/config-gigabeat-s.h index 8ddca5c..f0e9e92 100644 --- a/firmware/export/config-gigabeat-s.h +++ b/firmware/export/config-gigabeat-s.h @@ -134,6 +134,11 @@ /* define this if the unit can be powered or charged via USB */ //#define HAVE_USB_POWER /* Disable for now */ +//#define HAVE_USB_CHARGING_ENABLE + +/* define this if the unit has a battery switch or battery can be removed + * when running */ +#define HAVE_BATTERY_SWITCH /* USB On-the-go */ #define CONFIG_USBOTG USBOTG_ARC diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h index 0c54624..313bdad 100644 --- a/firmware/export/config-gigabeat.h +++ b/firmware/export/config-gigabeat.h @@ -114,6 +114,10 @@ /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER +/* define this if the unit has a battery switch or battery can be removed + * when running */ +#define HAVE_BATTERY_SWITCH + #ifndef SIMULATOR /* The LCD on a Gigabeat is 240x320 - it is portrait */ diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 680ca91..fa0046a 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h @@ -112,6 +112,10 @@ /* define this if the unit can be powered or charged via USB */ #define HAVE_USB_POWER +/* define this if the unit can have USB charging disabled by user - + * if USB/MAIN power is discernable and hardware doesn't compel charging */ +#define HAVE_USB_CHARGING_ENABLE + #ifndef SIMULATOR /* define this if the backlight thread is used for fade, not for sim, needs diff --git a/firmware/export/power.h b/firmware/export/power.h index f74e6fe..7478879 100644 --- a/firmware/export/power.h +++ b/firmware/export/power.h @@ -27,8 +27,57 @@ void charger_enable(bool on); #endif #if CONFIG_CHARGING -bool charger_inserted(void); +enum power_input_flags { + /* No external power source? Default. */ + POWER_INPUT_NONE = 0x00, + + /* Main power source is available (AC?), the default other than + * battery if for instance USB and others cannot be distinguished or + * USB is the only possibility. */ + POWER_INPUT_MAIN = 0x01, + + /* USB power source is available (and is discernable from MAIN). */ + POWER_INPUT_USB = 0x02, + + /* Something is plugged. */ + POWER_INPUT = 0x0f, + + /* POWER_INPUT_*_CHARGER of course implies presence of the respective + * power source. */ + + /* Battery not included in CHARGER (it can't charge itself) */ + + /* Charging is possible on main. */ + POWER_INPUT_MAIN_CHARGER = 0x10 | POWER_INPUT_MAIN, + + /* Charging is possible on USB. */ + POWER_INPUT_USB_CHARGER = 0x20 | POWER_INPUT_USB, + + /* Charging is possible from something. */ + POWER_INPUT_CHARGER = 0xf0, + +#ifdef HAVE_BATTERY_SWITCH + /* Battery is powering device or is available to power device. It + * could also be used if the battery is hot-swappable to indicate if + * it is present ("switch" as verb vs. noun). */ + POWER_INPUT_BATTERY = 0x100, #endif +}; + +/* Returns detailed power input status information from device. */ +unsigned int power_input_status(void); + +/* Shortcuts */ +/* Returns true if any power source that is connected is capable of + * charging the batteries. + * > (power_input_status() & POWER_INPUT_CHARGER) != 0 */ +bool charger_inserted(void); + +/* Returns true if any power input is connected - charging-capable + * or not. + * > (power_input_status() & POWER_INPUT) != 0 */ +bool power_input_present(void); +#endif /* CONFIG_CHARGING */ void power_off(void); void ide_power_enable(bool on); diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 6f0c37b..899e103 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c @@ -935,6 +935,23 @@ static inline void charging_algorithm_close(void) } #endif /* CONFIG_CHARGING == CHARGING_CONTROL */ +#if CONFIG_CHARGING +/* Shortcut function calls - compatibility, simplicity. */ + +/* Returns true if any power input is capable of charging. */ +bool charger_inserted(void) +{ + return power_input_status() & POWER_INPUT_CHARGER; +} + +/* Returns true if any power input is connected - charging-capable + * or not. */ +bool power_input_present(void) +{ + return power_input_status() & POWER_INPUT; +} +#endif /* CONFIG_CHARGING */ + /* * This function is called to do the relativly long sleep waits from within the * main power_thread loop while at the same time servicing any other periodic @@ -957,12 +974,7 @@ static void power_thread_sleep(int ticks) * loop (including the subroutines), and end up back here where we * transition to the appropriate steady state charger on/off state. */ - if(charger_inserted() -#ifdef HAVE_USB_POWER /* USB powered or USB inserted both provide power */ - || usb_powered() - || (usb_inserted() && usb_charging_enabled()) -#endif - ) { + if(power_input_status() & POWER_INPUT_CHARGER) { switch(charger_input_state) { case NO_CHARGER: case CHARGER_UNPLUGGED: diff --git a/firmware/target/arm/archos/av300/power-av300.c b/firmware/target/arm/archos/av300/power-av300.c index 5aa757d..013fd04 100644 --- a/firmware/target/arm/archos/av300/power-av300.c +++ b/firmware/target/arm/archos/av300/power-av300.c @@ -32,16 +32,14 @@ #include "system.h" #include "power.h" -#ifndef SIMULATOR - void power_init(void) { /* Charger detect */ } -bool charger_inserted(void) -{ - return false; +unsigned int power_input_status(void) +{ + return POWER_INPUT_NONE; } void ide_power_enable(bool on) @@ -61,29 +59,6 @@ void power_off(void) { } -#else - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ - bool tuner_power(bool status) { (void)status; diff --git a/firmware/target/arm/as3525/power-as3525.c b/firmware/target/arm/as3525/power-as3525.c index a61cb59..0786754 100644 --- a/firmware/target/arm/as3525/power-as3525.c +++ b/firmware/target/arm/as3525/power-as3525.c @@ -18,7 +18,6 @@ * KIND, either express or implied. * ****************************************************************************/ - #include <stdbool.h> #include "config.h" #include "ascodec-target.h" @@ -40,14 +39,14 @@ void power_init(void) } #if CONFIG_CHARGING -bool charger_inserted(void) +unsigned int power_input_status(void) { - if(ascodec_read(AS3514_IRQ_ENRD0) & (1<<5)) - return true; - else - return false; + return (ascodec_read(AS3514_IRQ_ENRD0) & (1<<5)) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; + + /* TODO: Handle USB and other sources properly */ } -#endif +#endif /* CONFIG_CHARGING */ void ide_power_enable(bool on) { diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c index 9d9cc6b..62f9982 100644 --- a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c @@ -27,8 +27,6 @@ #include "avic-imx31.h" #include "mc13783.h" -#ifndef SIMULATOR - static bool charger_detect = false; /* This is called from the mc13783 interrupt thread */ @@ -38,9 +36,17 @@ void charger_detect_event(void) mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_CHGDETS; } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return charger_detect; + unsigned int status = POWER_INPUT_NONE; + + if ((GPIO3_DR & (1 << 20)) != 0) + status |= POWER_INPUT_BATTERY; + + if (charger_detect) + status |= POWER_INPUT_MAIN_CHARGER; + + return status; } /* Returns true if the unit is charging the batteries. */ @@ -90,26 +96,3 @@ void power_init(void) mc13783_enable_event(MC13783_CHGDET_EVENT); } -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ - diff --git a/firmware/target/arm/ipod/power-ipod.c b/firmware/target/arm/ipod/power-ipod.c index af1ac9f..cb93fe3 100644 --- a/firmware/target/arm/ipod/power-ipod.c +++ b/firmware/target/arm/ipod/power-ipod.c @@ -43,18 +43,28 @@ void power_init(void) } #if CONFIG_CHARGING -bool charger_inserted(void) +unsigned int power_input_status(void) { -#if defined(IPOD_VIDEO) - return (GPIOL_INPUT_VAL & 0x08)?false:true; + unsigned int status = POWER_INPUT_NONE; + +#if defined(IPOD_NANO) || defined(IPOD_VIDEO) + if ((GPIOL_INPUT_VAL & 0x08) == 0) + status = POWER_INPUT_MAIN_CHARGER; + + if ((GPIOL_INPUT_VAL & 0x10) != 0) + status |= POWER_INPUT_USB_CHARGER; + /* */ #elif defined(IPOD_4G) || defined(IPOD_COLOR) \ || defined(IPOD_MINI) || defined(IPOD_MINI2G) /* C2 is firewire power */ - return (GPIOC_INPUT_VAL & 0x04)?false:true; + if ((GPIOC_INPUT_VAL & 0x04) == 0) + status = POWER_INPUT_MAIN_CHARGER; + /* */ #else /* This needs filling in for other ipods. */ - return false; #endif + + return status; } /* Returns true if the unit is charging the batteries. */ diff --git a/firmware/target/arm/iriver/h10/power-h10.c b/firmware/target/arm/iriver/h10/power-h10.c index dd09387..deca325 100644 --- a/firmware/target/arm/iriver/h10/power-h10.c +++ b/firmware/target/arm/iriver/h10/power-h10.c @@ -52,9 +52,11 @@ void power_init(void) { } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return (GPIOF_INPUT_VAL & 0x08)?true:false; + /* No separate source for USB and charges from USB on its own */ + return (GPIOF_INPUT_VAL & 0x08) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/olympus/mrobe-100/power-mr100.c b/firmware/target/arm/olympus/mrobe-100/power-mr100.c index 1ff15c5..c3eb96b 100644 --- a/firmware/target/arm/olympus/mrobe-100/power-mr100.c +++ b/firmware/target/arm/olympus/mrobe-100/power-mr100.c @@ -41,9 +41,10 @@ void power_init(void) GPIOB_OUTPUT_EN |= 0x80; } -bool charger_inserted(void) -{ - return (GPIOL_INPUT_VAL & 0x24) ? true : false ; +unsigned int power_input_status(void) +{ + return (GPIOL_INPUT_VAL & 0x24) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/philips/hdd1630/power-hdd1630.c b/firmware/target/arm/philips/hdd1630/power-hdd1630.c index 91193ba..ade2536 100755 --- a/firmware/target/arm/philips/hdd1630/power-hdd1630.c +++ b/firmware/target/arm/philips/hdd1630/power-hdd1630.c @@ -37,9 +37,9 @@ void power_init(void) { } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return false ; + return POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/philips/sa9200/power-sa9200.c b/firmware/target/arm/philips/sa9200/power-sa9200.c index 44df437..654beee 100644 --- a/firmware/target/arm/philips/sa9200/power-sa9200.c +++ b/firmware/target/arm/philips/sa9200/power-sa9200.c @@ -54,15 +54,9 @@ void power_off(void) } } -bool charger_inserted(void) +unsigned int power_input_status(void) { -#ifdef SANSA_E200 - if(GPIOB_INPUT_VAL & 0x10) -#else /* SANSA_C200 */ - if(GPIOH_INPUT_VAL & 0x2) -#endif - return true; - return false; + return POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c index c1c0595..ad9098d 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c @@ -27,8 +27,7 @@ #include "pcf50606.h" #include "backlight.h" #include "backlight-target.h" - -#ifndef SIMULATOR +#include "usb.h" void power_init(void) { @@ -39,13 +38,28 @@ void power_init(void) /* Charger detect */ } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return (GPFDAT & (1 << 4)) ? false : true; + unsigned int status = POWER_INPUT_NONE; + + /* Is the battery switch ON? */ + if ((GPGDAT & (1 << 9)) == 0) + status |= POWER_INPUT_BATTERY; + + /* Main or cradle power available? */ + if ((GPFDAT & (1 << 4)) == 0) + status |= POWER_INPUT_MAIN_CHARGER; + + /* Is the USB cable inserted? */ + if (usb_detect() == USB_INSERTED) + status |= POWER_INPUT_USB_CHARGER; + + return status; } /* Returns true if the unit is charging the batteries. */ -bool charging_state(void) { +bool charging_state(void) +{ return (GPGDAT & (1 << 8)) ? false : true; } @@ -87,27 +101,3 @@ void power_off(void) reboot_point(); } - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ - diff --git a/firmware/target/arm/sandisk/power-c200_e200.c b/firmware/target/arm/sandisk/power-c200_e200.c index d6319f4..cc9d16f 100644 --- a/firmware/target/arm/sandisk/power-c200_e200.c +++ b/firmware/target/arm/sandisk/power-c200_e200.c @@ -26,6 +26,7 @@ #include "tuner.h" #include "as3514.h" #include "power.h" +#include "usb.h" void power_init(void) { @@ -53,15 +54,24 @@ void power_off(void) } } -bool charger_inserted(void) +unsigned int power_input_status(void) { -#ifdef SANSA_E200 - if(GPIOB_INPUT_VAL & 0x10) -#else /* SANSA_C200 */ - if(GPIOH_INPUT_VAL & 0x2) + unsigned int status = POWER_INPUT_NONE; + +#if defined(SANSA_E200) + #define _charger_present() (GPIOB_INPUT_VAL & 0x10) +#elif defined(SANSA_C200) + #define _charger_present() (GPIOH_INPUT_VAL & 0x2) +#else + #define _charger_present() 0 #endif - return true; - return false; + + if (_charger_present()) + status = POWER_INPUT_MAIN_CHARGER; + + /* No separate source for USB */ + + return status; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/tatung/tpj1022/power-tpj1022.c b/firmware/target/arm/tatung/tpj1022/power-tpj1022.c index f16d3c9..abf5790 100644 --- a/firmware/target/arm/tatung/tpj1022/power-tpj1022.c +++ b/firmware/target/arm/tatung/tpj1022/power-tpj1022.c @@ -41,9 +41,9 @@ void power_init(void) { } -bool charger_inserted(void) -{ - return false; +unsigned int power_input_status(void) +{ + return POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/arm/tcc77x/c100/power-c100.c b/firmware/target/arm/tcc77x/c100/power-c100.c index 77574cc..e84ff1c 100644 --- a/firmware/target/arm/tcc77x/c100/power-c100.c +++ b/firmware/target/arm/tcc77x/c100/power-c100.c @@ -25,8 +25,6 @@ #include "system.h" #include "power.h" -#ifndef SIMULATOR - void power_init(void) { } @@ -43,22 +41,3 @@ bool ide_powered(void) void power_off(void) { } - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c index ce7175e..0501ba2 100644 --- a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c +++ b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c @@ -141,7 +141,8 @@ bool tuner_power(bool status) #endif /* CONFIG_TUNER */ -bool charger_inserted(void) +unsigned int power_input_status(void) { - return (GPIOA & 0x1) ? true : false; + return (GPIOA & 0x1) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } diff --git a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c index 82eb8dc..e84ff1c 100644 --- a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c +++ b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c @@ -25,8 +25,6 @@ #include "system.h" #include "power.h" -#ifndef SIMULATOR - void power_init(void) { } @@ -43,26 +41,3 @@ bool ide_powered(void) void power_off(void) { } - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tcc77x/m200/power-m200.c b/firmware/target/arm/tcc77x/m200/power-m200.c index 82eb8dc..e84ff1c 100644 --- a/firmware/target/arm/tcc77x/m200/power-m200.c +++ b/firmware/target/arm/tcc77x/m200/power-m200.c @@ -25,8 +25,6 @@ #include "system.h" #include "power.h" -#ifndef SIMULATOR - void power_init(void) { } @@ -43,26 +41,3 @@ bool ide_powered(void) void power_off(void) { } - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c index 9eb0871..d3f6a1c 100644 --- a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c @@ -26,8 +26,6 @@ #include "button-target.h" #include "tuner.h" -#ifndef SIMULATOR - void power_init(void) { unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ @@ -93,9 +91,10 @@ void EXT3(void) #endif #if CONFIG_CHARGING -bool charger_inserted(void) +unsigned int power_input_status(void) { - return (GPIOC & (1<<26)) ? false:true; + return ((GPIOC & (1<<26)) == 0) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } #endif @@ -147,26 +146,3 @@ bool tuner_power(bool status) } #endif /* CONFIG_TUNER */ - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c index a76e827..9c0f9c3 100644 --- a/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c +++ b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c @@ -28,8 +28,6 @@ #include "backlight.h" #include "backlight-target.h" -#ifndef SIMULATOR - void power_init(void) { /* Initialize IDE power pin */ @@ -37,34 +35,17 @@ void power_init(void) /* Charger detect */ } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return false; + return POWER_INPUT_NONE; } /* Returns true if the unit is charging the batteries. */ -bool charging_state(void) { - return false; -} - -void power_off(void) -{ -} - -#else /* SIMULATOR */ - -bool charger_inserted(void) +bool charging_state(void) { return false; } -void charger_enable(bool on) -{ - (void)on; -} - void power_off(void) { } - -#endif /* SIMULATOR */ diff --git a/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c index 7f4a3b3..8e8531e 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c @@ -29,8 +29,6 @@ #include "backlight.h" #include "backlight-target.h" -#ifndef SIMULATOR - void power_init(void) { /* Initialize IDE power pin */ @@ -40,9 +38,9 @@ void power_init(void) /* Charger detect */ } -bool charger_inserted(void) +unsigned int power_input_status(void) { - return false; + return POWER_INPUT_NONE; } /* Returns true if the unit is charging the batteries. */ @@ -71,27 +69,3 @@ void power_off(void) /* Hard shutdown */ IO_GIO_BITSET1|=1<<10; } - -#else /* SIMULATOR */ - -bool charger_inserted(void) -{ - return false; -} - -void charger_enable(bool on) -{ - (void)on; -} - -void power_off(void) -{ -} - -void ide_power_enable(bool on) -{ - (void)on; -} - -#endif /* SIMULATOR */ - diff --git a/firmware/target/coldfire/iaudio/m3/power-m3.c b/firmware/target/coldfire/iaudio/m3/power-m3.c index 5dbeadf..4c446e5 100644 --- a/firmware/target/coldfire/iaudio/m3/power-m3.c +++ b/firmware/target/coldfire/iaudio/m3/power-m3.c @@ -27,8 +27,6 @@ #include "power.h" #include "system.h" -#ifndef SIMULATOR - void power_init(void) { /* Set KEEPACT */ @@ -47,9 +45,10 @@ void power_init(void) #endif } -bool charger_inserted(void) -{ - return (GPIO1_READ & 0x00000020) == 0; +unsigned int power_input_status(void) +{ + return ((GPIO1_READ & 0x00000020) == 0) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) @@ -77,8 +76,6 @@ void power_off(void) asm("halt"); } -#endif /* SIMULATOR */ - bool tuner_power(bool status) { (void)status; diff --git a/firmware/target/coldfire/iaudio/m5/power-m5.c b/firmware/target/coldfire/iaudio/m5/power-m5.c index 987ce0f..8bb36c6 100644 --- a/firmware/target/coldfire/iaudio/m5/power-m5.c +++ b/firmware/target/coldfire/iaudio/m5/power-m5.c @@ -27,8 +27,6 @@ #include "pcf50606.h" #include "lcd-remote-target.h" -#ifndef SIMULATOR - void power_init(void) { /* Charger detect */ @@ -38,9 +36,10 @@ void power_init(void) pcf50606_init(); } -bool charger_inserted(void) -{ - return (GPIO1_READ & 0x01000000) != 0; +unsigned int power_input_status(void) +{ + return (GPIO1_READ & 0x01000000) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) @@ -66,5 +65,3 @@ void power_off(void) and_l(~0x00000008, &GPIO_OUT); /* Set KEEPACT low */ asm("halt"); } - -#endif /* SIMULATOR */ diff --git a/firmware/target/coldfire/iaudio/x5/power-x5.c b/firmware/target/coldfire/iaudio/x5/power-x5.c index 22f5696..4feb9c1 100644 --- a/firmware/target/coldfire/iaudio/x5/power-x5.c +++ b/firmware/target/coldfire/iaudio/x5/power-x5.c @@ -27,8 +27,6 @@ #include "pcf50606.h" #include "lcd-remote-target.h" -#ifndef SIMULATOR - void power_init(void) { /* Charger detect */ @@ -38,9 +36,10 @@ void power_init(void) pcf50606_init(); } -bool charger_inserted(void) -{ - return (GPIO1_READ & 0x01000000) != 0; +unsigned int power_input_status(void) +{ + return (GPIO1_READ & 0x01000000) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) @@ -67,8 +66,6 @@ void power_off(void) asm("halt"); } -#endif /* SIMULATOR */ - bool tuner_power(bool status) { (void)status; diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c index 6eb4037..2717e42 100644 --- a/firmware/target/coldfire/iriver/h100/power-h100.c +++ b/firmware/target/coldfire/iriver/h100/power-h100.c @@ -26,19 +26,14 @@ #include "power.h" #include "spdif.h" - #if CONFIG_TUNER - bool tuner_power(bool status) { (void)status; return true; } - #endif /* #if CONFIG_TUNER */ -#ifndef SIMULATOR - void power_init(void) { or_l(0x00080000, &GPIO1_OUT); @@ -56,14 +51,16 @@ void power_init(void) #endif } - -bool charger_inserted(void) -{ - return (GPIO1_READ & 0x00400000)?true:false; +unsigned int power_input_status(void) +{ + return (GPIO1_READ & 0x00400000) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } + /* Returns true if the unit is charging the batteries. */ -bool charging_state(void) { - return charger_inserted(); +bool charging_state(void) +{ + return (power_input_status() & POWER_INPUT_CHARGER) != 0; } #ifdef HAVE_SPDIF_POWER @@ -119,5 +116,3 @@ void power_off(void) asm("halt"); while(1); } - -#endif /* SIMULATOR */ diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c index ea66625..400dc02 100644 --- a/firmware/target/coldfire/iriver/h300/power-h300.c +++ b/firmware/target/coldfire/iriver/h300/power-h300.c @@ -25,20 +25,18 @@ #include "system.h" #include "power.h" #include "pcf50606.h" +#include "usb.h" +#include "logf.h" #if CONFIG_TUNER - bool tuner_power(bool status) { (void)status; return true; } - #endif /* #if CONFIG_TUNER */ -#ifndef SIMULATOR - void power_init(void) { or_l(0x00080000, &GPIO1_OUT); @@ -56,17 +54,54 @@ void power_init(void) #if CONFIG_CHARGING -bool charger_inserted(void) -{ - return (GPIO1_READ & 0x00400000)?true:false; +unsigned int power_input_status(void) +{ + unsigned int status = POWER_INPUT_NONE; + + if (GPIO1_READ & 0x00400000) + status |= POWER_INPUT_MAIN_CHARGER; + +#ifdef HAVE_USB_POWER + if (usb_detect() == USB_INSERTED && pcf50606_usb_charging_enabled()) + status |= POWER_INPUT_USB_CHARGER; + /* CHECK: Can the device be powered from USB w/o charging it? */ +#endif + + return status; } + +#ifdef HAVE_USB_POWER +bool usb_charging_enable(bool on) +{ + bool rc = false; + int irqlevel; + logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); + irqlevel = disable_irq_save(); + pcf50606_set_usb_charging(on); + rc = on; + restore_irq(irqlevel); + return rc; +} +#endif /* HAVE_USB_POWER */ + #endif /* CONFIG_CHARGING */ /* Returns true if the unit is charging the batteries. */ -bool charging_state(void) { +bool charging_state(void) +{ return (GPIO_READ & 0x00800000)?true:false; } +bool usb_charging_enabled(void) +{ + bool rc = false; + /* TODO: read the state of the GPOOD2 register... + * (this also means to set the irq level here) */ + rc = pcf50606_usb_charging_enabled(); + + logf("usb charging %s", rc ? "enabled" : "disabled" ); + return rc; +} void ide_power_enable(bool on) { @@ -90,5 +125,3 @@ void power_off(void) asm("halt"); while(1); } - -#endif /* SIMULATOR */ diff --git a/firmware/target/sh/archos/fm_v2/power-fm_v2.c b/firmware/target/sh/archos/fm_v2/power-fm_v2.c index 32b5c95..24bccf6 100644 --- a/firmware/target/sh/archos/fm_v2/power-fm_v2.c +++ b/firmware/target/sh/archos/fm_v2/power-fm_v2.c @@ -28,7 +28,6 @@ #include "usb.h" #if CONFIG_TUNER - bool tuner_power(bool status) { (void)status; @@ -44,10 +43,20 @@ void power_init(void) or_b(0x20, &PBDRL); /* hold power */ } -bool charger_inserted(void) +unsigned int power_input_status(void) { + unsigned int status = POWER_INPUT_NONE; + /* FM or V2 can also charge from the USB port */ - return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF); + if (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) + status = POWER_INPUT_MAIN_CHARGER; + +#ifdef HAVE_USB_POWER + if (usb_detect() == USB_INSERTED) + status |= POWER_INPUT_USB_CHARGER; +#endif + + return status; } /* Returns true if the unit is charging the batteries. */ diff --git a/firmware/target/sh/archos/player/power-player.c b/firmware/target/sh/archos/player/power-player.c index 59b87f6..857ba25 100644 --- a/firmware/target/sh/archos/player/power-player.c +++ b/firmware/target/sh/archos/player/power-player.c @@ -31,10 +31,11 @@ void power_init(void) { } -bool charger_inserted(void) +unsigned int power_input_status(void) { /* Player */ - return (PADR & 1) == 0; + return ((PADR & 1) == 0) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void ide_power_enable(bool on) diff --git a/firmware/target/sh/archos/recorder/power-recorder.c b/firmware/target/sh/archos/recorder/power-recorder.c index b0a7ad1..d90c029 100644 --- a/firmware/target/sh/archos/recorder/power-recorder.c +++ b/firmware/target/sh/archos/recorder/power-recorder.c @@ -36,10 +36,11 @@ void power_init(void) charger_enable(false); /* Default to charger OFF */ } -bool charger_inserted(void) +unsigned int power_input_status(void) { /* Recorder */ - return adc_read(ADC_EXT_POWER) > 0x100; + return (adc_read(ADC_EXT_POWER) > 0x100) ? + POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; } void charger_enable(bool on) diff --git a/firmware/usb.c b/firmware/usb.c index 00e0bb3..9d4bb00 100644 --- a/firmware/usb.c +++ b/firmware/usb.c @@ -42,9 +42,6 @@ #ifdef HAVE_USBSTACK #include "usb_core.h" #endif -#ifdef IRIVER_H300_SERIES -#include "pcf50606.h" /* for pcf50606_usb_charging_... */ -#endif #include "logf.h" /* Conditions under which we want the entire driver */ @@ -588,40 +585,6 @@ bool usb_powered(void) { return usb_state == USB_POWERED; } - -#if CONFIG_CHARGING -bool usb_charging_enable(bool on) -{ - bool rc = false; -#ifdef IRIVER_H300_SERIES - int irqlevel; - logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); - irqlevel = disable_irq_save(); - pcf50606_set_usb_charging(on); - rc = on; - restore_irq(irqlevel); -#else - /* TODO: implement it for other targets... */ - (void)on; -#endif - return rc; -} - -bool usb_charging_enabled(void) -{ - bool rc = false; -#ifdef IRIVER_H300_SERIES - /* TODO: read the state of the GPOOD2 register... - * (this also means to set the irq level here) */ - rc = pcf50606_usb_charging_enabled(); -#else - /* TODO: implement it for other targets... */ -#endif - - logf("usb charging %s", rc ? "enabled" : "disabled" ); - return rc; -} -#endif #endif #else |