diff options
author | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-06-05 10:05:27 +0000 |
---|---|---|
committer | Torne Wuff <torne@wolfpuppy.org.uk> | 2010-06-05 10:05:27 +0000 |
commit | 991e92fd3dc15f1e365761264c26305559ddb0a4 (patch) | |
tree | ac6d18cf1a803c416c0dbc8f61f521444d265ec9 /firmware | |
parent | e49464b38735585eaa0ce01f5734c0bcfad851dd (diff) | |
download | rockbox-991e92fd3dc15f1e365761264c26305559ddb0a4.tar.gz rockbox-991e92fd3dc15f1e365761264c26305559ddb0a4.zip |
New USB charging system, part 1 - API rework and user-visible setting update
1) "Charge during USB connection" option is now tristate: off/on/force. Currently "force" behaves just like "on", but in future it will allow charging even when it was not possible to positively identify a charger.
2) The H300 code has been adjusted to use the new system but there should be no functional differences, it already had the USB charging option and its USB/charging support is hardware controlled.
3) The Gigabeat S code has been adjusted to use the new system: the player now has the USB charging option, which wasn't previously available. The player will only charge at full speed when allowed to do so by a working USB host, so USB AC adapters won't work very well; however, they didn't work before either, so this is not a change in functionality.
4) The iPod Nano 2G code has been adjusted to use the new system: it already had the USB charging option. Using a USB AC adapter won't charge at full speed any more (it did before) - the old implementation was equivalent to the not-yet-implemented "force" option in the new system.
No other target should be affected. Support for the "force" mode and support for at least some other iPod models will come in a future commit :)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26570 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/export/config/gigabeats.h | 2 | ||||
-rw-r--r-- | firmware/export/usb.h | 13 | ||||
-rw-r--r-- | firmware/export/usb_core.h | 10 | ||||
-rw-r--r-- | firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c | 8 | ||||
-rw-r--r-- | firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c | 9 | ||||
-rw-r--r-- | firmware/target/coldfire/iriver/h300/power-h300.c | 17 | ||||
-rw-r--r-- | firmware/usbstack/usb_core.c | 42 |
7 files changed, 69 insertions, 32 deletions
diff --git a/firmware/export/config/gigabeats.h b/firmware/export/config/gigabeats.h index f096fb07d6..fcfa274314 100644 --- a/firmware/export/config/gigabeats.h +++ b/firmware/export/config/gigabeats.h | |||
@@ -173,6 +173,8 @@ | |||
173 | /* Charging implemented in a target-specific algorithm */ | 173 | /* Charging implemented in a target-specific algorithm */ |
174 | #define CONFIG_CHARGING CHARGING_TARGET | 174 | #define CONFIG_CHARGING CHARGING_TARGET |
175 | 175 | ||
176 | #define HAVE_USB_CHARGING_ENABLE | ||
177 | |||
176 | /* define this if the hardware can be powered off while charging */ | 178 | /* define this if the hardware can be powered off while charging */ |
177 | /* We don't charge while powered down so maybe implement a | 179 | /* We don't charge while powered down so maybe implement a |
178 | finish-charging-and-then-poweroff mode */ | 180 | finish-charging-and-then-poweroff mode */ |
diff --git a/firmware/export/usb.h b/firmware/export/usb.h index 48400b11dc..d544f5cab1 100644 --- a/firmware/export/usb.h +++ b/firmware/export/usb.h | |||
@@ -146,9 +146,16 @@ int usb_detect(void); /* return the raw hardware value - nothing/pc/charger */ | |||
146 | void usb_status_event(int current_status); | 146 | void usb_status_event(int current_status); |
147 | #ifdef HAVE_USB_POWER | 147 | #ifdef HAVE_USB_POWER |
148 | bool usb_powered(void); | 148 | bool usb_powered(void); |
149 | #ifdef CONFIG_CHARGING | 149 | #ifdef HAVE_USB_CHARGING_ENABLE |
150 | bool usb_charging_enable(bool on); | 150 | enum { |
151 | bool usb_charging_enabled(void); | 151 | USB_CHARGING_DISABLE, |
152 | USB_CHARGING_ENABLE, | ||
153 | USB_CHARGING_FORCE | ||
154 | }; | ||
155 | /* called by app, implemented by usb_core on targets with rockbox usb | ||
156 | * or target-specific code on others | ||
157 | */ | ||
158 | void usb_charging_enable(int state); | ||
152 | #endif | 159 | #endif |
153 | #endif | 160 | #endif |
154 | #ifdef HAVE_USBSTACK | 161 | #ifdef HAVE_USBSTACK |
diff --git a/firmware/export/usb_core.h b/firmware/export/usb_core.h index 5286dbcdfe..6405aa492d 100644 --- a/firmware/export/usb_core.h +++ b/firmware/export/usb_core.h | |||
@@ -59,8 +59,14 @@ void usb_core_release_endpoint(int dir); | |||
59 | void usb_core_hotswap_event(int volume,bool inserted); | 59 | void usb_core_hotswap_event(int volume,bool inserted); |
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | #ifdef HAVE_USB_POWER | 62 | #ifdef HAVE_USB_CHARGING_ENABLE |
63 | unsigned short usb_allowed_current(void); | 63 | /* hardware which knows how to control usb current should use one |
64 | * of the following to find out from the usb stack how much is ok | ||
65 | */ | ||
66 | /* implemented by target, called by usb when value changes */ | ||
67 | void usb_charging_maxcurrent_change(int maxcurrent); | ||
68 | /* implemented by usb, called by target to get value */ | ||
69 | int usb_charging_maxcurrent(void); | ||
64 | #endif | 70 | #endif |
65 | 71 | ||
66 | #endif | 72 | #endif |
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 d7fe87f168..4540be671a 100644 --- a/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c +++ b/firmware/target/arm/imx31/gigabeat-s/power-gigabeat-s.c | |||
@@ -43,7 +43,7 @@ unsigned int power_input_status(void) | |||
43 | if (GPIO3_DR & (1 << 20)) | 43 | if (GPIO3_DR & (1 << 20)) |
44 | status |= POWER_INPUT_BATTERY; | 44 | status |= POWER_INPUT_BATTERY; |
45 | 45 | ||
46 | if (usb_allowed_current() < 500) | 46 | if (usb_charging_maxcurrent() < 500) |
47 | { | 47 | { |
48 | /* ACK that USB is connected but NOT chargeable */ | 48 | /* ACK that USB is connected but NOT chargeable */ |
49 | status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER); | 49 | status &= ~(POWER_INPUT_USB_CHARGER & POWER_INPUT_CHARGER); |
@@ -52,6 +52,12 @@ unsigned int power_input_status(void) | |||
52 | return status; | 52 | return status; |
53 | } | 53 | } |
54 | 54 | ||
55 | void usb_charging_maxcurrent_change(int maxcurrent) | ||
56 | { | ||
57 | (void)maxcurrent; | ||
58 | /* Nothing to do */ | ||
59 | } | ||
60 | |||
55 | /* Detect changes in presence of the AC adaptor. */ | 61 | /* Detect changes in presence of the AC adaptor. */ |
56 | void charger_main_detect_event(void) | 62 | void charger_main_detect_event(void) |
57 | { | 63 | { |
diff --git a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c index 5164f0fa1a..a75cb39729 100644 --- a/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c +++ b/firmware/target/arm/s5l8700/ipodnano2g/power-nano2g.c | |||
@@ -54,15 +54,10 @@ void power_init(void) | |||
54 | #if CONFIG_CHARGING | 54 | #if CONFIG_CHARGING |
55 | 55 | ||
56 | #ifdef HAVE_USB_CHARGING_ENABLE | 56 | #ifdef HAVE_USB_CHARGING_ENABLE |
57 | bool usb_charging_enable(bool on) | 57 | void usb_charging_maxcurrent_change(int maxcurrent) |
58 | { | 58 | { |
59 | bool on = (maxcurrent >= 500); | ||
59 | PDAT11 = (PDAT11 & ~1) | (on ? 1 : 0); | 60 | PDAT11 = (PDAT11 & ~1) | (on ? 1 : 0); |
60 | return on; | ||
61 | } | ||
62 | |||
63 | bool usb_charging_enabled(void) | ||
64 | { | ||
65 | return PDAT11 & 1; | ||
66 | } | 61 | } |
67 | #endif | 62 | #endif |
68 | 63 | ||
diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c index 400dc02526..202e1d68ed 100644 --- a/firmware/target/coldfire/iriver/h300/power-h300.c +++ b/firmware/target/coldfire/iriver/h300/power-h300.c | |||
@@ -71,16 +71,14 @@ unsigned int power_input_status(void) | |||
71 | } | 71 | } |
72 | 72 | ||
73 | #ifdef HAVE_USB_POWER | 73 | #ifdef HAVE_USB_POWER |
74 | bool usb_charging_enable(bool on) | 74 | void usb_charging_enable(int state) |
75 | { | 75 | { |
76 | bool rc = false; | 76 | bool on = (state != USB_CHARGING_DISABLE); |
77 | int irqlevel; | 77 | int irqlevel; |
78 | logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); | 78 | logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); |
79 | irqlevel = disable_irq_save(); | 79 | irqlevel = disable_irq_save(); |
80 | pcf50606_set_usb_charging(on); | 80 | pcf50606_set_usb_charging(on); |
81 | rc = on; | ||
82 | restore_irq(irqlevel); | 81 | restore_irq(irqlevel); |
83 | return rc; | ||
84 | } | 82 | } |
85 | #endif /* HAVE_USB_POWER */ | 83 | #endif /* HAVE_USB_POWER */ |
86 | 84 | ||
@@ -92,17 +90,6 @@ bool charging_state(void) | |||
92 | return (GPIO_READ & 0x00800000)?true:false; | 90 | return (GPIO_READ & 0x00800000)?true:false; |
93 | } | 91 | } |
94 | 92 | ||
95 | bool usb_charging_enabled(void) | ||
96 | { | ||
97 | bool rc = false; | ||
98 | /* TODO: read the state of the GPOOD2 register... | ||
99 | * (this also means to set the irq level here) */ | ||
100 | rc = pcf50606_usb_charging_enabled(); | ||
101 | |||
102 | logf("usb charging %s", rc ? "enabled" : "disabled" ); | ||
103 | return rc; | ||
104 | } | ||
105 | |||
106 | void ide_power_enable(bool on) | 93 | void ide_power_enable(bool on) |
107 | { | 94 | { |
108 | if(on) | 95 | if(on) |
diff --git a/firmware/usbstack/usb_core.c b/firmware/usbstack/usb_core.c index a2e2b5f063..dfcce05064 100644 --- a/firmware/usbstack/usb_core.c +++ b/firmware/usbstack/usb_core.c | |||
@@ -166,6 +166,11 @@ static int usb_address = 0; | |||
166 | static bool initialized = false; | 166 | static bool initialized = false; |
167 | static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state; | 167 | static enum { DEFAULT, ADDRESS, CONFIGURED } usb_state; |
168 | 168 | ||
169 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
170 | static int usb_charging_mode = USB_CHARGING_DISABLE; | ||
171 | static int usb_charging_current_requested = 500; | ||
172 | #endif | ||
173 | |||
169 | static int usb_core_num_interfaces; | 174 | static int usb_core_num_interfaces; |
170 | 175 | ||
171 | typedef void (*completion_handler_t)(int ep, int dir, int status, int length); | 176 | typedef void (*completion_handler_t)(int ep, int dir, int status, int length); |
@@ -378,6 +383,9 @@ void usb_core_exit(void) | |||
378 | initialized = false; | 383 | initialized = false; |
379 | } | 384 | } |
380 | usb_state = DEFAULT; | 385 | usb_state = DEFAULT; |
386 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
387 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
388 | #endif | ||
381 | logf("usb_core_exit() finished"); | 389 | logf("usb_core_exit() finished"); |
382 | } | 390 | } |
383 | 391 | ||
@@ -552,6 +560,16 @@ static void request_handler_device_get_descriptor(struct usb_ctrlrequest* req) | |||
552 | config_descriptor.bDescriptorType = | 560 | config_descriptor.bDescriptorType = |
553 | USB_DT_OTHER_SPEED_CONFIG; | 561 | USB_DT_OTHER_SPEED_CONFIG; |
554 | } | 562 | } |
563 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
564 | if (usb_charging_mode == USB_CHARGING_DISABLE) { | ||
565 | config_descriptor.bMaxPower = (100+1)/2; | ||
566 | usb_charging_current_requested = 100; | ||
567 | } | ||
568 | else { | ||
569 | config_descriptor.bMaxPower = (500+1)/2; | ||
570 | usb_charging_current_requested = 500; | ||
571 | } | ||
572 | #endif | ||
555 | size = sizeof(struct usb_config_descriptor); | 573 | size = sizeof(struct usb_config_descriptor); |
556 | 574 | ||
557 | for(i = 0; i < USB_NUM_DRIVERS; i++) | 575 | for(i = 0; i < USB_NUM_DRIVERS; i++) |
@@ -628,8 +646,10 @@ static void request_handler_device(struct usb_ctrlrequest* req) | |||
628 | } | 646 | } |
629 | else | 647 | else |
630 | usb_state = ADDRESS; | 648 | usb_state = ADDRESS; |
631 | |||
632 | usb_drv_send(EP_CONTROL, NULL, 0); | 649 | usb_drv_send(EP_CONTROL, NULL, 0); |
650 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
651 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
652 | #endif | ||
633 | break; | 653 | break; |
634 | } | 654 | } |
635 | case USB_REQ_SET_ADDRESS: { | 655 | case USB_REQ_SET_ADDRESS: { |
@@ -809,6 +829,9 @@ void usb_core_bus_reset(void) | |||
809 | { | 829 | { |
810 | usb_address = 0; | 830 | usb_address = 0; |
811 | usb_state = DEFAULT; | 831 | usb_state = DEFAULT; |
832 | #ifdef HAVE_USB_CHARGING_ENABLE | ||
833 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
834 | #endif | ||
812 | } | 835 | } |
813 | 836 | ||
814 | /* called by usb_drv_transfer_completed() */ | 837 | /* called by usb_drv_transfer_completed() */ |
@@ -850,9 +873,20 @@ void usb_core_control_request(struct usb_ctrlrequest* req) | |||
850 | usb_signal_transfer_completion(completion_event); | 873 | usb_signal_transfer_completion(completion_event); |
851 | } | 874 | } |
852 | 875 | ||
853 | #ifdef HAVE_USB_POWER | 876 | #ifdef HAVE_USB_CHARGING_ENABLE |
854 | unsigned short usb_allowed_current() | 877 | void usb_charging_enable(int state) |
878 | { | ||
879 | usb_charging_mode = state; | ||
880 | usb_charging_maxcurrent_change(usb_charging_maxcurrent()); | ||
881 | } | ||
882 | |||
883 | int usb_charging_maxcurrent() | ||
855 | { | 884 | { |
856 | return (usb_state == CONFIGURED) ? MAX(USB_MAX_CURRENT, 100) : 100; | 885 | if (!initialized |
886 | || usb_charging_mode == USB_CHARGING_DISABLE | ||
887 | || usb_state != CONFIGURED) | ||
888 | return 100; | ||
889 | /* usb_state == CONFIGURED, charging enabled/forced */ | ||
890 | return usb_charging_current_requested; | ||
857 | } | 891 | } |
858 | #endif | 892 | #endif |