summaryrefslogtreecommitdiff
path: root/firmware/target/arm/as3525
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/as3525')
-rw-r--r--firmware/target/arm/as3525/usb-as3525.c79
1 files changed, 55 insertions, 24 deletions
diff --git a/firmware/target/arm/as3525/usb-as3525.c b/firmware/target/arm/as3525/usb-as3525.c
index 5664eb2096..a6d5d3a245 100644
--- a/firmware/target/arm/as3525/usb-as3525.c
+++ b/firmware/target/arm/as3525/usb-as3525.c
@@ -18,9 +18,8 @@
18 * KIND, either express or implied. 18 * KIND, either express or implied.
19 * 19 *
20 ****************************************************************************/ 20 ****************************************************************************/
21
22#include <stdbool.h>
23#include "config.h" 21#include "config.h"
22#include "system.h"
24#include "usb.h" 23#include "usb.h"
25#ifdef HAVE_USBSTACK 24#ifdef HAVE_USBSTACK
26#include "usb_core.h" 25#include "usb_core.h"
@@ -29,8 +28,40 @@
29#include "power.h" 28#include "power.h"
30#include "as3525.h" 29#include "as3525.h"
31 30
32static bool bus_activity = 0; 31static int usb_status = USB_EXTRACTED;
33static bool connected = 0; 32
33#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
34/* Rebooting on USB plug can crash these players in a state where
35 * hardware power off (pressing the power button) doesn't work anymore
36 * TODO: Implement USB in rockbox for these players */
37#define USB_INSERT_INT_STATUS USB_EXTRACTED
38#undef USB_DETECT_BY_DRV
39#undef USB_DETECT_BY_CORE
40#undef USB_STATUS_BY_EVENT
41
42#else /* !AS3525v2 */
43
44#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
45
46#ifdef USB_STATUS_BY_EVENT
47#define USB_INSERT_INT_STATUS USB_INSERTED
48#define USB_INSERT_INT_EVENT USB_POWERED
49#define USB_REMOVE_INT_EVENT USB_UNPOWERED
50#else
51#define USB_INSERT_INT_STATUS USB_POWERED
52#endif /* USB_STATUS_BY_EVENT */
53
54#else /* !USB_DETECT_BY_* */
55
56#define USB_INSERT_INT_STATUS USB_INSERTED
57#ifdef USB_STATUS_BY_EVENT
58#define USB_INSERT_INT_EVENT USB_INSERTED
59#define USB_REMOVE_INT_EVENT USB_EXTRACTED
60#endif /* USB_STATUS_BY_EVENT */
61
62#endif /* USB_DETECT_BY_* */
63
64#endif /* AS3525v2 */
34 65
35void usb_enable(bool on) 66void usb_enable(bool on)
36{ 67{
@@ -46,36 +77,36 @@ void usb_enable(bool on)
46 77
47void usb_insert_int(void) 78void usb_insert_int(void)
48{ 79{
49 connected = 1; 80 usb_status = USB_INSERT_INT_STATUS;
81#ifdef USB_STATUS_BY_EVENT
82 usb_status_event(USB_INSERT_INT_EVENT);
83#endif
50} 84}
51 85
52void usb_remove_int(void) 86void usb_remove_int(void)
53{ 87{
54 connected = 0; 88 usb_status = USB_EXTRACTED;
55 bus_activity = 0; 89#ifdef USB_STATUS_BY_EVENT
90 usb_status_event(USB_REMOVE_INT_EVENT);
91#endif
56} 92}
57 93
58void usb_drv_usb_detect_event(void) 94void usb_drv_usb_detect_event(void)
59{ 95{
60 /* Bus activity seen */ 96#if defined(USB_DETECT_BY_DRV) || defined(USB_DETECT_BY_CORE)
61 bus_activity = 1; 97 int oldstatus = disable_irq_save(); /* May come via USB thread */
98 if (usb_status == USB_INSERT_INT_STATUS)
99 {
100 usb_status = USB_INSERTED;
101#ifdef USB_STATUS_BY_EVENT
102 usb_status_event(USB_INSERTED);
103#endif
104 }
105 restore_irq(oldstatus);
106#endif /* USB_DETECT_BY_* */
62} 107}
63 108
64int usb_detect(void) 109int usb_detect(void)
65{ 110{
66#if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB) 111 return usb_status;
67 /* Rebooting on USB plug can crash these players in a state where
68 * hardware power off (pressing the power button) doesn't work anymore
69 * TODO: Implement USB in rockbox for these players */
70 return USB_EXTRACTED;
71#elif defined(USB_DETECT_BY_DRV)
72 if(bus_activity && connected)
73 return USB_INSERTED;
74 else if(connected)
75 return USB_POWERED;
76 else
77 return USB_UNPOWERED;
78#else
79 return connected?USB_INSERTED:USB_EXTRACTED;
80#endif
81} 112}