Make usb_detect() return USB_UNPOWERED instead of USB_EXTRACTED. Without that, not...
[kugel-rb.git] / firmware / target / arm / as3525 / usb-as3525.c
blob5664eb20960b7e726c94b9aa241d84e64ef403d1
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright © 2008 Rafaël Carré
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdbool.h>
23 #include "config.h"
24 #include "usb.h"
25 #ifdef HAVE_USBSTACK
26 #include "usb_core.h"
27 #endif
28 #include "usb-target.h"
29 #include "power.h"
30 #include "as3525.h"
32 static bool bus_activity = 0;
33 static bool connected = 0;
35 void usb_enable(bool on)
37 #if defined(HAVE_USBSTACK) && defined(USE_ROCKBOX_USB)
38 if (on)
39 usb_core_init();
40 else
41 usb_core_exit();
42 #else
43 (void)on;
44 #endif
47 void usb_insert_int(void)
49 connected = 1;
52 void usb_remove_int(void)
54 connected = 0;
55 bus_activity = 0;
58 void usb_drv_usb_detect_event(void)
60 /* Bus activity seen */
61 bus_activity = 1;
64 int usb_detect(void)
66 #if CONFIG_CPU == AS3525v2 && !defined(USE_ROCKBOX_USB)
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