summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCástor Muñoz <cmvidal@gmail.com>2016-05-25 23:43:26 +0200
committerCástor Muñoz <cmvidal@gmail.com>2016-05-26 09:06:30 +0200
commitdaee722455d6459d0a7a5a3fcc1555d22144ad41 (patch)
treebf2997d5fc198956c2015511cd762715bd846ff8
parentf6ed4f830666b7281308cca4bf90e0000dcfaef4 (diff)
downloadrockbox-daee722455d6459d0a7a5a3fcc1555d22144ad41.tar.gz
rockbox-daee722455d6459d0a7a5a3fcc1555d22144ad41.zip
iPod Classic: use PMU interrupts to detect USB and FW
Change-Id: I9be733e1a943ddeb99335d362f81f74879eeb94b
-rw-r--r--firmware/target/arm/s5l8700/usb-nano2g-6g.c32
-rw-r--r--firmware/target/arm/s5l8702/debug-s5l8702.c2
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c11
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/pmu-target.h1
-rw-r--r--firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c17
-rw-r--r--firmware/target/arm/s5l8702/system-target.h3
6 files changed, 44 insertions, 22 deletions
diff --git a/firmware/target/arm/s5l8700/usb-nano2g-6g.c b/firmware/target/arm/s5l8700/usb-nano2g-6g.c
index db397f8fd5..7d48a5cabd 100644
--- a/firmware/target/arm/s5l8700/usb-nano2g-6g.c
+++ b/firmware/target/arm/s5l8700/usb-nano2g-6g.c
@@ -27,7 +27,6 @@
27#ifdef HAVE_USBSTACK 27#ifdef HAVE_USBSTACK
28#include "usb_core.h" 28#include "usb_core.h"
29#include "usb_drv.h" 29#include "usb_drv.h"
30#include "power.h"
31 30
32void usb_enable(bool on) 31void usb_enable(bool on)
33{ 32{
@@ -35,6 +34,9 @@ void usb_enable(bool on)
35 else usb_core_exit(); 34 else usb_core_exit();
36} 35}
37 36
37#if CONFIG_CPU==S5L8701
38#include "power.h"
39
38int usb_detect(void) 40int usb_detect(void)
39{ 41{
40 if (power_input_status() & POWER_INPUT_USB) 42 if (power_input_status() & POWER_INPUT_USB)
@@ -42,6 +44,31 @@ int usb_detect(void)
42 return USB_EXTRACTED; 44 return USB_EXTRACTED;
43} 45}
44 46
47#elif CONFIG_CPU==S5L8702
48static int usb_status = USB_EXTRACTED;
49
50int usb_detect(void)
51{
52 return usb_status;
53}
54
55void usb_insert_int(void)
56{
57 usb_status = USB_INSERTED;
58#ifdef USB_STATUS_BY_EVENT
59 usb_status_event(USB_INSERTED);
60#endif
61}
62
63void usb_remove_int(void)
64{
65 usb_status = USB_EXTRACTED;
66#ifdef USB_STATUS_BY_EVENT
67 usb_status_event(USB_EXTRACTED);
68#endif
69}
70#endif /* S5L8702 */
71
45void usb_init_device(void) 72void usb_init_device(void)
46{ 73{
47 /* Power up the core clocks to allow writing 74 /* Power up the core clocks to allow writing
@@ -59,7 +86,8 @@ void usb_init_device(void)
59 86
60 usb_drv_exit(); 87 usb_drv_exit();
61} 88}
62#else 89
90#else /* !HAVE_STACK */
63void usb_enable(bool on) 91void usb_enable(bool on)
64{ 92{
65 (void)on; 93 (void)on;
diff --git a/firmware/target/arm/s5l8702/debug-s5l8702.c b/firmware/target/arm/s5l8702/debug-s5l8702.c
index b274b5fc0a..cead1b7219 100644
--- a/firmware/target/arm/s5l8702/debug-s5l8702.c
+++ b/firmware/target/arm/s5l8702/debug-s5l8702.c
@@ -122,7 +122,7 @@ bool dbg_hw_info(void)
122 _DEBUG_PRINTF("brightness value: %d", pmu_read(0x28)); 122 _DEBUG_PRINTF("brightness value: %d", pmu_read(0x28));
123 line++; 123 line++;
124 _DEBUG_PRINTF("USB present: %s", 124 _DEBUG_PRINTF("USB present: %s",
125 pmu_usb_present() ? "true" : "false"); 125 (power_input_status() & POWER_INPUT_USB) ? "true" : "false");
126#if CONFIG_CHARGING 126#if CONFIG_CHARGING
127 _DEBUG_PRINTF("FW present: %s", 127 _DEBUG_PRINTF("FW present: %s",
128 pmu_firewire_present() ? "true" : "false"); 128 pmu_firewire_present() ? "true" : "false");
diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
index 4200308861..c439a30fc1 100644
--- a/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/pmu-ipod6g.c
@@ -161,18 +161,12 @@ static struct eint_handler pmu_eint = {
161}; 161};
162 162
163static int pmu_input_holdswitch; 163static int pmu_input_holdswitch;
164static int pmu_input_usb;
165 164
166int pmu_holdswitch_locked(void) 165int pmu_holdswitch_locked(void)
167{ 166{
168 return pmu_input_holdswitch; 167 return pmu_input_holdswitch;
169} 168}
170 169
171int pmu_usb_present(void)
172{
173 return pmu_input_usb;
174}
175
176#ifdef IPOD_ACCESSORY_PROTOCOL 170#ifdef IPOD_ACCESSORY_PROTOCOL
177static int pmu_input_accessory; 171static int pmu_input_accessory;
178 172
@@ -206,7 +200,10 @@ static void pmu_read_inputs_gpio(void)
206static void pmu_read_inputs_ooc(void) 200static void pmu_read_inputs_ooc(void)
207{ 201{
208 unsigned char oocstat = pmu_read(PCF5063X_REG_OOCSTAT); 202 unsigned char oocstat = pmu_read(PCF5063X_REG_OOCSTAT);
209 pmu_input_usb = !!(oocstat & PCF5063X_OOCSTAT_EXTON2); 203 if (oocstat & PCF5063X_OOCSTAT_EXTON2)
204 usb_insert_int();
205 else
206 usb_remove_int();
210#ifdef IPOD_ACCESSORY_PROTOCOL 207#ifdef IPOD_ACCESSORY_PROTOCOL
211 pmu_input_accessory = !(oocstat & PCF5063X_OOCSTAT_EXTON3); 208 pmu_input_accessory = !(oocstat & PCF5063X_OOCSTAT_EXTON3);
212#endif 209#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/pmu-target.h b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h
index 2274b4061f..5552e2196a 100644
--- a/firmware/target/arm/s5l8702/ipod6g/pmu-target.h
+++ b/firmware/target/arm/s5l8702/ipod6g/pmu-target.h
@@ -92,7 +92,6 @@ void pmu_write_rtc(unsigned char* buffer);
92void pmu_hdd_power(bool on); 92void pmu_hdd_power(bool on);
93 93
94int pmu_holdswitch_locked(void); 94int pmu_holdswitch_locked(void);
95int pmu_usb_present(void);
96#if CONFIG_CHARGING 95#if CONFIG_CHARGING
97int pmu_firewire_present(void); 96int pmu_firewire_present(void);
98#endif 97#endif
diff --git a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
index d3224d2a66..1a8e1e1a7e 100644
--- a/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
+++ b/firmware/target/arm/s5l8702/ipod6g/power-ipod6g.c
@@ -119,17 +119,12 @@ void usb_charging_maxcurrent_change(int maxcurrent)
119 119
120unsigned int power_input_status(void) 120unsigned int power_input_status(void)
121{ 121{
122 /* This checks if USB Vbus is present. */ 122 unsigned int status = POWER_INPUT_NONE;
123 if (!(PDAT(12) & 0x8)) return POWER_INPUT_USB_CHARGER; 123 if (usb_detect() == USB_INSERTED)
124 124 status |= POWER_INPUT_USB_CHARGER;
125 /* If USB Vbus is not present, check if we have a positive power balance 125 if (pmu_firewire_present())
126 regardless. This would indicate FireWire charging. Note that this will 126 status |= POWER_INPUT_MAIN_CHARGER;
127 drop to POWER_INPUT_NONE if FireWire isn't able to supply enough current 127 return status;
128 for device operation, e.g. during disk spinup. */
129 if (PDAT(11) & 0x20) return POWER_INPUT_NONE;
130
131 /* Looks like we have FireWire power. */
132 return POWER_INPUT_MAIN_CHARGER;
133} 128}
134 129
135bool charging_state(void) 130bool charging_state(void)
diff --git a/firmware/target/arm/s5l8702/system-target.h b/firmware/target/arm/s5l8702/system-target.h
index b40d563e46..d3db7476ee 100644
--- a/firmware/target/arm/s5l8702/system-target.h
+++ b/firmware/target/arm/s5l8702/system-target.h
@@ -47,6 +47,9 @@ static inline void udelay(unsigned usecs)
47 while (TIME_BEFORE(USEC_TIMER, stop)); 47 while (TIME_BEFORE(USEC_TIMER, stop));
48} 48}
49 49
50void usb_insert_int(void);
51void usb_remove_int(void);
52
50#ifdef BOOTLOADER 53#ifdef BOOTLOADER
51void system_preinit(void); 54void system_preinit(void);
52#endif 55#endif