From 207131c53b15e7b5956177e90932b7445ff5b4ce Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Wed, 14 Sep 2011 14:05:07 +0000 Subject: Convert ARC USB driver code to always use setup packet detection and remove the bus-reset-based detection method for it. This prevents false USB detection from chargers or other accesories that aren't actually a host but can trigger the bus reset condition. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30546 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/usb-drv-arc.c | 93 +++++++++++++-------------------------- 1 file changed, 31 insertions(+), 62 deletions(-) (limited to 'firmware/target') diff --git a/firmware/target/arm/usb-drv-arc.c b/firmware/target/arm/usb-drv-arc.c index f252f11f3e..855f67e4c3 100644 --- a/firmware/target/arm/usb-drv-arc.c +++ b/firmware/target/arm/usb-drv-arc.c @@ -428,9 +428,31 @@ void usb_drv_startup(void) } } +#ifdef LOGF_ENABLE +#define XFER_DIR_STR(dir) ((dir) ? "IN" : "OUT") +#define XFER_TYPE_STR(type) \ + ((type) == USB_ENDPOINT_XFER_CONTROL ? "CTRL" : \ + ((type) == USB_ENDPOINT_XFER_ISOC ? "ISOC" : \ + ((type) == USB_ENDPOINT_XFER_BULK ? "BULK" : \ + ((type) == USB_ENDPOINT_XFER_INT ? "INTR" : "INVL")))) + +static void log_ep(int ep_num, int ep_dir, char* prefix) +{ + usb_endpoint_t* endpoint = &endpoints[ep_num]; + + logf("%s: ep%d %s %s %d", prefix, ep_num, XFER_DIR_STR(ep_dir), + XFER_TYPE_STR(endpoint->type[ep_dir]), + endpoint->max_pkt_size[ep_dir]); +} +#else +#undef log_ep +#define log_ep(...) +#endif + /* manual: 32.14.1 Device Controller Initialization */ -static void _usb_drv_init(bool attach) +void usb_drv_init(void) { + /* USB core decides */ usb_drv_reset(); REG_USBMODE = USBMODE_CTRL_MODE_DEVICE; @@ -447,19 +469,12 @@ static void _usb_drv_init(bool attach) REG_ENDPOINTLISTADDR = (unsigned int)qh_array; REG_DEVICEADDR = 0; - if (!attach) { - /* enable RESET interrupt */ - REG_USBINTR = USBINTR_RESET_EN; - } - else - { - /* enable USB interrupts */ - REG_USBINTR = - USBINTR_INT_EN | - USBINTR_ERR_INT_EN | - USBINTR_PTC_DETECT_EN | - USBINTR_RESET_EN; - } + /* enable USB interrupts */ + REG_USBINTR = + USBINTR_INT_EN | + USBINTR_ERR_INT_EN | + USBINTR_PTC_DETECT_EN | + USBINTR_RESET_EN; usb_drv_int_enable(true); @@ -472,49 +487,12 @@ static void _usb_drv_init(bool attach) logf("usb dccparams %x", REG_DCCPARAMS); /* now a bus reset will occur. see bus_reset() */ - (void)attach; -} - -#ifdef LOGF_ENABLE -#define XFER_DIR_STR(dir) ((dir) ? "IN" : "OUT") -#define XFER_TYPE_STR(type) \ - ((type) == USB_ENDPOINT_XFER_CONTROL ? "CTRL" : \ - ((type) == USB_ENDPOINT_XFER_ISOC ? "ISOC" : \ - ((type) == USB_ENDPOINT_XFER_BULK ? "BULK" : \ - ((type) == USB_ENDPOINT_XFER_INT ? "INTR" : "INVL")))) - -static void log_ep(int ep_num, int ep_dir, char* prefix) -{ - usb_endpoint_t* endpoint = &endpoints[ep_num]; - - logf("%s: ep%d %s %s %d", prefix, ep_num, XFER_DIR_STR(ep_dir), - XFER_TYPE_STR(endpoint->type[ep_dir]), - endpoint->max_pkt_size[ep_dir]); -} -#else -#undef log_ep -#define log_ep(...) -#endif - -void usb_drv_init(void) -{ -#ifdef USB_DETECT_BY_CORE - /* USB core decides */ - _usb_drv_init(true); -#else - /* Use bus reset condition */ - _usb_drv_init(false); -#endif } /* fully enable driver */ void usb_drv_attach(void) { logf("usb_drv_attach"); -#ifndef USB_DETECT_BY_CORE - sleep(HZ/10); - _usb_drv_init(true); -#endif } void usb_drv_exit(void) @@ -563,17 +541,8 @@ void usb_drv_int(void) /* reset interrupt */ if (status & USBSTS_RESET) { REG_USBSTS = USBSTS_RESET; - - if (UNLIKELY(usbintr == USBINTR_RESET_EN)) { - /* USB detected - detach and inform */ - usb_drv_stop(); - usb_drv_usb_detect_event(); - } - else - { - bus_reset(); - usb_core_bus_reset(); /* tell mom */ - } + bus_reset(); + usb_core_bus_reset(); /* tell mom */ } /* port change */ -- cgit v1.2.3