6e7fac7c34
fix button-detection so screenshots and charge-only mode work without enabling UMS firewire detection is now handled separately from usb detection increase the usb thread priority while an UMS connection is active git-svn-id: svn://svn.rockbox.org/rockbox/trunk@16435 a1c6a512-1295-4272-9138-f99709370657
150 lines
3.8 KiB
C
150 lines
3.8 KiB
C
/***************************************************************************
|
|
* __________ __ ___.
|
|
* 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"
|
|
#include "button.h"
|
|
#include "ata.h"
|
|
#include "string.h"
|
|
#include "usb_core.h"
|
|
#include "usb_drv.h"
|
|
|
|
void usb_init_device(void)
|
|
{
|
|
/* enable usb module */
|
|
outl(inl(0x7000002C) | 0x3000000, 0x7000002C);
|
|
|
|
DEV_EN |= DEV_USB0;
|
|
DEV_EN |= DEV_USB1;
|
|
|
|
/* reset both USBs */
|
|
DEV_RS |= DEV_USB0;
|
|
DEV_RS &=~DEV_USB0;
|
|
DEV_RS |= DEV_USB1;
|
|
DEV_RS &=~DEV_USB1;
|
|
|
|
#if CONFIG_CPU == PP5020
|
|
DEV_INIT2 |= INIT_USB;
|
|
#endif
|
|
|
|
while ((inl(0x70000028) & 0x80) == 0);
|
|
outl(inl(0x70000028) | 0x2, 0x70000028);
|
|
udelay(0x186A0);
|
|
|
|
/* disable USB-devices until USB is detected via GPIO */
|
|
DEV_EN &= ~DEV_USB0;
|
|
DEV_EN &= ~DEV_USB1;
|
|
#if CONFIG_CPU == PP5020
|
|
DEV_INIT2 &= ~INIT_USB;
|
|
#endif
|
|
|
|
#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
|
|
}
|
|
|
|
void usb_enable(bool on)
|
|
{
|
|
if (on) {
|
|
/* if USB is detected, re-enable the USB-devices, otherwise make sure it's disabled */
|
|
DEV_EN |= DEV_USB0;
|
|
DEV_RS &=~DEV_USB0;
|
|
DEV_EN |= DEV_USB1;
|
|
DEV_RS &=~DEV_USB1;
|
|
#if CONFIG_CPU == PP5020
|
|
DEV_INIT2 |= INIT_USB;
|
|
#endif
|
|
usb_core_init();
|
|
}
|
|
else {
|
|
usb_core_exit();
|
|
/* Disable USB devices */
|
|
DEV_EN &=~ DEV_USB0;
|
|
DEV_EN &=~ DEV_USB1;
|
|
#if CONFIG_CPU == PP5020
|
|
DEV_INIT2 &=~ INIT_USB;
|
|
#endif
|
|
}
|
|
}
|
|
|
|
static bool usb_pin_detect(void)
|
|
{
|
|
bool retval = false;
|
|
|
|
#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)
|
|
retval = true;
|
|
|
|
#elif defined(IPOD_NANO) || defined(IPOD_VIDEO)
|
|
/* GPIO L bit 4 is usb detect */
|
|
if (GPIOL_INPUT_VAL & 0x10)
|
|
retval = true;
|
|
|
|
#elif defined(SANSA_C200)
|
|
/* GPIO H bit 1 is usb detect */
|
|
if (GPIOH_INPUT_VAL & 0x02)
|
|
retval = true;
|
|
|
|
#elif defined(SANSA_E200)
|
|
/* GPIO B bit 4 is usb detect */
|
|
if (GPIOB_INPUT_VAL & 0x10)
|
|
retval = true;
|
|
|
|
#elif defined(IRIVER_H10) || defined(IRIVER_H10_5GB)
|
|
/* GPIO L bit 2 is usb detect */
|
|
if (GPIOL_INPUT_VAL & 0x4)
|
|
retval = true;
|
|
#endif
|
|
|
|
return retval;
|
|
}
|
|
|
|
/* detect host or charger (INSERTED or POWERED) */
|
|
int usb_detect(void)
|
|
{
|
|
if(usb_pin_detect()) {
|
|
return USB_INSERTED;
|
|
}
|
|
else {
|
|
return USB_EXTRACTED;
|
|
}
|
|
}
|
|
|
|
#if defined(IPOD_COLOR) || defined(IPOD_4G) \
|
|
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
|
|
bool firewire_detect(void)
|
|
{
|
|
/* GPIO C bit 1 is firewire detect */
|
|
if (!(GPIOC_INPUT_VAL & 0x02))
|
|
/* no charger detection needed for firewire */
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
#endif
|