summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorSteve Bavin <pondlife@pondlife.me>2007-02-01 10:47:22 +0000
committerSteve Bavin <pondlife@pondlife.me>2007-02-01 10:47:22 +0000
commit338d94f4661643dcd4c6440aa1c12af6933da4a5 (patch)
tree966f0bf5dcc7f4ccb71c266317adedd5705c5d2f /firmware
parent73ee2379c5361126d6fb9754845fc9e249614e40 (diff)
downloadrockbox-338d94f4661643dcd4c6440aa1c12af6933da4a5.tar.gz
rockbox-338d94f4661643dcd4c6440aa1c12af6933da4a5.tar.bz2
rockbox-338d94f4661643dcd4c6440aa1c12af6933da4a5.zip
FS#4770 - Add USB charging for the H300 series
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12169 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/pcf50606.h5
-rw-r--r--firmware/export/usb.h4
-rw-r--r--firmware/powermgmt.c5
-rw-r--r--firmware/target/coldfire/iriver/h300/pcf50606-h300.c26
-rw-r--r--firmware/usb.c38
5 files changed, 77 insertions, 1 deletions
diff --git a/firmware/export/pcf50606.h b/firmware/export/pcf50606.h
index 1f4b6ba3ad..f01df520cf 100644
--- a/firmware/export/pcf50606.h
+++ b/firmware/export/pcf50606.h
@@ -24,6 +24,8 @@ int pcf50606_write_multiple(int address, const unsigned char* buf, int count);
int pcf50606_write(int address, unsigned char val);
int pcf50606_read_multiple(int address, unsigned char* buf, int count);
int pcf50606_read(int address);
+void pcf50606_set_usb_charging(bool on);
+bool pcf50606_usb_charging_enabled(void);
/* internal low level calls used by the eeprom driver for h300 */
void pcf50606_i2c_init(void);
@@ -32,8 +34,11 @@ void pcf50606_i2c_start(void);
void pcf50606_i2c_stop(void);
void pcf50606_i2c_ack(bool ack);
bool pcf50606_i2c_getack(void);
+#if defined(IRIVER_H300_SERIES)
+/* USB charging support */
void pcf50606_i2c_outb(unsigned char byte);
unsigned char pcf50606_i2c_inb(bool ack);
+#endif
#if defined(IAUDIO_X5) && !defined(SIMULATOR)
void pcf50606_reset_timeout(void);
diff --git a/firmware/export/usb.h b/firmware/export/usb.h
index b16c11a9b8..622db35543 100644
--- a/firmware/export/usb.h
+++ b/firmware/export/usb.h
@@ -31,6 +31,10 @@ bool usb_inserted(void); /* return the official value, what's been reported to t
bool usb_detect(void); /* return the raw hardware value */
#ifdef HAVE_USB_POWER
bool usb_powered(void);
+#ifdef CONFIG_CHARGING
+bool usb_charging_enable(bool on);
+bool usb_charging_enabled(void);
+#endif
#endif
#endif
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 5c7607413c..1b160af232 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -759,8 +759,11 @@ static void power_thread_sleep(int ticks)
* transition to the appropriate steady state charger on/off state.
*/
if(charger_inserted()
-#ifdef HAVE_USB_POWER
+#ifdef HAVE_USB_POWER /* USB powered or USB inserted both provide power */
|| usb_powered()
+#ifdef CONFIG_CHARGING
+ || (usb_inserted() && usb_charging_enabled())
+#endif
#endif
) {
switch(charger_input_state) {
diff --git a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
index 3a67d541d3..7d101f7347 100644
--- a/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
+++ b/firmware/target/coldfire/iriver/h300/pcf50606-h300.c
@@ -21,6 +21,9 @@
#include "kernel.h"
#include "pcf50606.h"
#include "button-target.h"
+#include "logf.h"
+
+static bool usb_ch_enabled = false;
/* These voltages were determined by measuring the output of the PCF50606
on a running H300, and verified by disassembling the original firmware */
@@ -70,6 +73,27 @@ static inline void enable_pmu_interrupts(void)
or_l(0x03000000, &INTPRI5); /* INT38 - Priority 3 */
}
+/* enables/disables USB charging
+ * ATTENTION: make sure to set the irq level
+ * to highest before calling this function! */
+void pcf50606_set_usb_charging(bool on)
+{
+ if (on)
+ pcf50606_write(0x39, 0x00); /* Set GPOOD2 to High-Z for USB Charge Enable */
+ else
+ pcf50606_write(0x39, 0x07); /* Set GPOOD2 to pulled down to disable USB charging */
+
+ usb_ch_enabled = on;
+
+ logf("pcf50606_set_usb_charging(%s)\n", on ? "on" : "off" );
+}
+
+bool pcf50606_usb_charging_enabled(void)
+{
+ /* TODO: read the state of the GPOOD2 register... */
+ return usb_ch_enabled;
+}
+
void pcf50606_init(void)
{
pcf50606_i2c_init();
@@ -82,6 +106,8 @@ void pcf50606_init(void)
pcf50606_write(0x09, 0x05); /* USB and ON key debounce: 14ms */
pcf50606_write(0x29, 0x1C); /* Disable the unused MBC module */
+ pcf50606_set_usb_charging(false); /* Disable USB charging atm. */
+
pcf50606_write(0x35, 0x13); /* Backlight PWM = 512Hz 50/50 */
pcf50606_write(0x3a, 0x3b); /* PWM output on GPOOD1 */
diff --git a/firmware/usb.c b/firmware/usb.c
index 651c17a4b3..0a329ad624 100644
--- a/firmware/usb.c
+++ b/firmware/usb.c
@@ -44,6 +44,10 @@
#ifdef TARGET_TREE
#include "usb-target.h"
#endif
+#ifdef IRIVER_H300_SERIES
+#include "pcf50606.h" /* for pcf50606_usb_charging_... */
+#endif
+#include "logf.h"
extern void dbg_ports(void); /* NASTY! defined in apps/ */
@@ -487,6 +491,40 @@ bool usb_powered(void)
{
return usb_state == USB_POWERED;
}
+
+#ifdef 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 = set_irq_level(HIGHEST_IRQ_LEVEL);
+ pcf50606_set_usb_charging(on);
+ rc = on;
+ (void)set_irq_level(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_enabled: %s\n", rc ? "true" : "false" );
+ return rc;
+}
+#endif
#endif
#else