From 616c98b38f6ddac0ac3dde8ec0fa248f835717e2 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 19 Jan 2009 13:41:25 +0000 Subject: USB detection changes. c200/e200: Consider USB to be powered when charger is plugged but detect USB connection by bus reset. When received, disconnect and restart the driver fully enabled. imx31: Fix hack used to make initial connect succeeded-- set PHY type before initial reset. General: Move some target code out of usb-drv-arc.c and implement it in respective usb sources and CPU headers so things stay clean. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@19797 a1c6a512-1295-4272-9138-f99709370657 --- firmware/target/arm/usb-drv-arc.c | 186 +++++++++++++++++++------------------- 1 file changed, 92 insertions(+), 94 deletions(-) (limited to 'firmware/target/arm/usb-drv-arc.c') diff --git a/firmware/target/arm/usb-drv-arc.c b/firmware/target/arm/usb-drv-arc.c index 1cdc0f9e90..99845c2a49 100644 --- a/firmware/target/arm/usb-drv-arc.c +++ b/firmware/target/arm/usb-drv-arc.c @@ -9,7 +9,7 @@ * * Driver for ARC USBOTG Device Controller * - * Copyright (C) 2007 by Björn Stenberg + * Copyright (C) 2007 by Björn Stenberg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,11 +33,6 @@ //#define LOGF_ENABLE #include "logf.h" -#if CONFIG_CPU == IMX31L -#include "avic-imx31.h" -static void __attribute__((interrupt("IRQ"))) USB_OTG_HANDLER(void); -#endif - /* USB device mode registers (Little Endian) */ #define REG_ID (*(volatile unsigned int *)(USB_BASE+0x000)) @@ -326,8 +321,8 @@ struct transfer_descriptor { unsigned int reserved; } __attribute__ ((packed)); -static struct transfer_descriptor td_array[NUM_ENDPOINTS*2] - USBDEVBSS_ATTR __attribute__((aligned(32))); +static struct transfer_descriptor td_array[USB_NUM_ENDPOINTS*2] + USB_DEVBSS_ATTR __attribute__((aligned(32))); /* manual: 32.13.1 Endpoint Queue Head (dQH) */ struct queue_head { @@ -342,17 +337,10 @@ struct queue_head { unsigned int wait; /* for softwate use, indicates if the transfer is blocking */ } __attribute__((packed)); -#if CONFIG_CPU == IMX31L -static struct queue_head qh_array[NUM_ENDPOINTS*2] - QHARRAY_ATTR __attribute__((aligned (2048))); -#else -/* This still needs to be 2048 byte aligned, but QHARRAY_ATTR should take - care of that */ -static struct queue_head qh_array[NUM_ENDPOINTS*2] - QHARRAY_ATTR __attribute__((aligned (4))); -#endif +static struct queue_head qh_array[USB_NUM_ENDPOINTS*2] + USB_QHARRAY_ATTR; -static struct wakeup transfer_completion_signal[NUM_ENDPOINTS*2] +static struct wakeup transfer_completion_signal[USB_NUM_ENDPOINTS*2] SHAREDBSS_ATTR; static const unsigned int pipe2mask[] = { @@ -363,7 +351,7 @@ static const unsigned int pipe2mask[] = { 0x10, 0x100000, }; -static char ep_allocation[NUM_ENDPOINTS]; +static char ep_allocation[USB_NUM_ENDPOINTS]; /*-------------------------------------------------------------------------*/ static void transfer_completed(void); @@ -378,52 +366,46 @@ static void init_control_queue_heads(void); static void init_bulk_queue_heads(void); static void init_endpoints(void); /*-------------------------------------------------------------------------*/ - -bool usb_drv_powered(void) +static void usb_drv_stop(void) { - return (REG_OTGSC & OTGSC_B_SESSION_VALID) ? true : false; + /* disable interrupts */ + REG_USBINTR = 0; + /* stop usb controller (disconnect) */ + REG_USBCMD &= ~USBCMD_RUN; } -/* One-time driver startup init */ -void usb_drv_startup(void) +void usb_drv_reset(void) { -#if CONFIG_CPU == IMX31L && defined(BOOTLOADER) - /* This is the bootloader - activate the OTG controller or cold - * connect later could/will fail */ + int oldlevel = disable_irq_save(); REG_USBCMD &= ~USBCMD_RUN; + restore_irq(oldlevel); +#ifdef USB_PORTSCX_PHY_TYPE + /* If a PHY type is specified, set it now */ + REG_PORTSC1 = (REG_PORTSC1 & ~PORTSCX_PHY_TYPE_SEL) | USB_PORTSCX_PHY_TYPE; +#endif sleep(HZ/20); REG_USBCMD |= USBCMD_CTRL_RESET; while (REG_USBCMD & USBCMD_CTRL_RESET); +} - /* Set to ULPI */ - REG_PORTSC1 = (REG_PORTSC1 & ~PORTSCX_PHY_TYPE_SEL) | PORTSCX_PTS_ULPI; - sleep(HZ/10); -#endif - +/* One-time driver startup init */ +void usb_drv_startup(void) +{ /* Initialize all the signal objects once */ int i; - for(i=0;i