2006-10-05 10:58:51 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2002 by Linus Nielsen Feltzing
|
|
|
|
*
|
|
|
|
* iPod driver based on code from the ipodlinux project - http://ipodlinux.org
|
|
|
|
* Adapted for Rockbox in January 2006
|
|
|
|
* Original file: podzilla/usb.c
|
|
|
|
* Copyright (C) 2005 Adam Johnston
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "system.h"
|
|
|
|
#include "usb.h"
|
2007-08-27 16:26:56 +00:00
|
|
|
#include "button.h"
|
|
|
|
#include "ata.h"
|
2007-08-27 16:30:23 +00:00
|
|
|
#include "string.h"
|
2007-11-22 20:51:00 +00:00
|
|
|
#include "usb_core.h"
|
2007-11-23 00:02:52 +00:00
|
|
|
#include "usb_drv.h"
|
2008-05-03 07:10:21 +00:00
|
|
|
#include "usb-target.h"
|
2007-08-27 16:04:32 +00:00
|
|
|
|
2006-10-05 10:58:51 +00:00
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2007-11-22 20:51:00 +00:00
|
|
|
/* enable usb module */
|
2007-08-27 18:21:05 +00:00
|
|
|
outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
|
2008-02-20 22:54:26 +00:00
|
|
|
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_EN |= DEV_USB0;
|
|
|
|
DEV_EN |= DEV_USB1;
|
2007-09-05 15:52:49 +00:00
|
|
|
|
2008-02-10 05:39:20 +00:00
|
|
|
/* reset both USBs */
|
|
|
|
DEV_RS |= DEV_USB0;
|
|
|
|
DEV_RS &=~DEV_USB0;
|
|
|
|
DEV_RS |= DEV_USB1;
|
|
|
|
DEV_RS &=~DEV_USB1;
|
2007-09-05 15:52:49 +00:00
|
|
|
|
2007-10-16 10:48:16 +00:00
|
|
|
DEV_INIT2 |= INIT_USB;
|
2008-02-20 22:54:26 +00:00
|
|
|
|
2007-09-05 15:52:49 +00:00
|
|
|
while ((inl(0x70000028) & 0x80) == 0);
|
|
|
|
outl(inl(0x70000028) | 0x2, 0x70000028);
|
2008-03-01 21:40:33 +00:00
|
|
|
udelay(100000);
|
2008-02-10 05:39:20 +00:00
|
|
|
|
|
|
|
/* disable USB-devices until USB is detected via GPIO */
|
2008-03-26 10:37:17 +00:00
|
|
|
#ifndef BOOTLOADER
|
2008-04-07 13:00:28 +00:00
|
|
|
/* Disabling USB0 in the bootloader makes the OF not load,
|
|
|
|
Also something here breaks usb pin detect in bootloader.
|
|
|
|
leave it all enabled untill rockbox main loads */
|
2008-02-10 05:39:20 +00:00
|
|
|
DEV_EN &= ~DEV_USB0;
|
|
|
|
DEV_EN &= ~DEV_USB1;
|
|
|
|
DEV_INIT2 &= ~INIT_USB;
|
2008-04-07 13:00:28 +00:00
|
|
|
#endif
|
2007-09-05 15:52:49 +00:00
|
|
|
|
2007-08-01 22:44:02 +00:00
|
|
|
#if defined(IPOD_COLOR) || defined(IPOD_4G) \
|
|
|
|
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
|
|
/* GPIO C bit 1 is firewire detect */
|
|
|
|
GPIOC_ENABLE |= 0x02;
|
|
|
|
GPIOC_OUTPUT_EN &= ~0x02;
|
|
|
|
#endif
|
2008-04-20 03:30:57 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_USBSTACK
|
|
|
|
/* Do one-time inits */
|
|
|
|
usb_drv_startup();
|
|
|
|
#endif
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_enable(bool on)
|
|
|
|
{
|
2007-11-23 15:02:26 +00:00
|
|
|
if (on) {
|
2008-02-27 19:08:30 +00:00
|
|
|
/* if USB is detected, re-enable the USB-devices, otherwise make sure it's disabled */
|
|
|
|
DEV_EN |= DEV_USB0;
|
|
|
|
DEV_EN |= DEV_USB1;
|
|
|
|
DEV_INIT2 |= INIT_USB;
|
|
|
|
usb_core_init();
|
2007-11-23 15:02:26 +00:00
|
|
|
}
|
2008-02-27 19:08:30 +00:00
|
|
|
else {
|
2007-11-22 20:51:00 +00:00
|
|
|
usb_core_exit();
|
2008-02-27 19:08:30 +00:00
|
|
|
/* Disable USB devices */
|
|
|
|
DEV_EN &=~ DEV_USB0;
|
|
|
|
DEV_EN &=~ DEV_USB1;
|
|
|
|
DEV_INIT2 &=~ INIT_USB;
|
|
|
|
}
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
|
|
|
|
2007-11-23 18:00:24 +00:00
|
|
|
static bool usb_pin_detect(void)
|
2006-10-05 10:58:51 +00:00
|
|
|
{
|
2008-02-10 05:39:20 +00:00
|
|
|
bool retval = false;
|
|
|
|
|
2007-11-23 17:59:43 +00:00
|
|
|
#if defined(IPOD_4G) || defined(IPOD_COLOR) \
|
|
|
|
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
|
|
/* GPIO D bit 3 is usb detect */
|
|
|
|
if (GPIOD_INPUT_VAL & 0x08)
|
2008-02-10 05:39:20 +00:00
|
|
|
retval = true;
|
2007-11-23 17:59:43 +00:00
|
|
|
|
|
|
|
#elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
|
2007-11-23 15:02:26 +00:00
|
|
|
/* GPIO L bit 4 is usb detect */
|
|
|
|
if (GPIOL_INPUT_VAL & 0x10)
|
2008-02-10 05:39:20 +00:00
|
|
|
retval = true;
|
2007-11-23 15:02:26 +00:00
|
|
|
|
2007-11-23 00:02:52 +00:00
|
|
|
#elif defined(SANSA_C200)
|
2007-11-22 20:51:00 +00:00
|
|
|
/* GPIO H bit 1 is usb detect */
|
|
|
|
if (GPIOH_INPUT_VAL & 0x02)
|
2008-02-10 05:39:20 +00:00
|
|
|
retval = true;
|
2007-11-23 15:02:26 +00:00
|
|
|
|
2007-11-22 20:51:00 +00:00
|
|
|
#elif defined(SANSA_E200)
|
|
|
|
/* GPIO B bit 4 is usb detect */
|
|
|
|
if (GPIOB_INPUT_VAL & 0x10)
|
2008-02-10 05:39:20 +00:00
|
|
|
retval = true;
|
2007-11-23 15:02:26 +00:00
|
|
|
|
2008-03-02 13:07:11 +00:00
|
|
|
#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB) || defined(MROBE_100)
|
2007-11-22 20:51:00 +00:00
|
|
|
/* GPIO L bit 2 is usb detect */
|
|
|
|
if (GPIOL_INPUT_VAL & 0x4)
|
2008-02-10 05:39:20 +00:00
|
|
|
retval = true;
|
2008-05-21 03:55:17 +00:00
|
|
|
|
|
|
|
#elif defined(PHILIPS_SA9200)
|
|
|
|
/* GPIO F bit 7 is usb detect */
|
|
|
|
if (!(GPIOF_INPUT_VAL & 0x80))
|
|
|
|
retval = true;
|
2007-09-04 23:29:42 +00:00
|
|
|
#endif
|
2008-02-10 05:39:20 +00:00
|
|
|
|
|
|
|
return retval;
|
2007-11-23 15:02:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* detect host or charger (INSERTED or POWERED) */
|
|
|
|
int usb_detect(void)
|
|
|
|
{
|
2008-02-27 19:08:30 +00:00
|
|
|
if(usb_pin_detect()) {
|
2008-03-21 00:04:17 +00:00
|
|
|
return USB_INSERTED;
|
2008-02-27 19:08:30 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
return USB_EXTRACTED;
|
|
|
|
}
|
|
|
|
}
|
2007-11-23 15:02:26 +00:00
|
|
|
|
|
|
|
#if defined(IPOD_COLOR) || defined(IPOD_4G) \
|
|
|
|
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
2008-02-27 19:08:30 +00:00
|
|
|
bool firewire_detect(void)
|
|
|
|
{
|
2007-11-23 15:02:26 +00:00
|
|
|
/* GPIO C bit 1 is firewire detect */
|
|
|
|
if (!(GPIOC_INPUT_VAL & 0x02))
|
|
|
|
/* no charger detection needed for firewire */
|
2008-02-27 19:08:30 +00:00
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
2006-10-05 10:58:51 +00:00
|
|
|
}
|
2008-02-27 19:08:30 +00:00
|
|
|
#endif
|