2006-08-12 08:01:54 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Linus Nielsen Feltzing
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2006-08-12 08:01:54 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#include "config.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "system.h"
|
2006-12-29 02:49:12 +00:00
|
|
|
#include "kernel.h"
|
2007-04-11 05:30:15 +00:00
|
|
|
#include "ata.h"
|
2007-09-04 08:03:07 +00:00
|
|
|
#include "usb.h"
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
#define USB_RST_ASSERT GPBDAT &= ~(1 << 4)
|
|
|
|
#define USB_RST_DEASSERT GPBDAT |= (1 << 4)
|
|
|
|
|
2008-04-22 04:13:07 +00:00
|
|
|
#define USB_VBUS_PWR_ASSERT GPBDAT |= (1 << 6)
|
|
|
|
#define USB_VBUS_PWR_DEASSERT GPBDAT &= ~(1 << 6)
|
2006-08-12 08:01:54 +00:00
|
|
|
|
2007-02-12 07:05:15 +00:00
|
|
|
#define USB_UNIT_IS_PRESENT !(GPFDAT & 0x01)
|
2007-06-23 18:25:41 +00:00
|
|
|
#define USB_CRADLE_IS_PRESENT ((GPFDAT &0x02)&&((GPGDAT&(3<<13))==(1<<13)))
|
2006-12-29 02:49:12 +00:00
|
|
|
|
2007-02-12 07:05:15 +00:00
|
|
|
#define USB_CRADLE_BUS_ENABLE GPHDAT |= (1 << 8)
|
|
|
|
#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8)
|
2006-12-29 02:49:12 +00:00
|
|
|
|
|
|
|
/* The usb detect is one pin to the cpu active low */
|
2007-09-04 08:03:07 +00:00
|
|
|
int usb_detect(void)
|
2006-08-12 08:01:54 +00:00
|
|
|
{
|
2007-09-04 08:03:07 +00:00
|
|
|
if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT)
|
|
|
|
return USB_INSERTED;
|
|
|
|
else
|
|
|
|
return USB_EXTRACTED;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2008-04-22 04:13:07 +00:00
|
|
|
/* Setup USB Cradle Power control (output, disabled, no pullup) */
|
|
|
|
GPHCON=( GPHCON&~(1<<17) ) | (1<<16);
|
|
|
|
GPHUP|=1<<8;
|
|
|
|
USB_CRADLE_BUS_DISABLE;
|
2007-04-11 05:30:15 +00:00
|
|
|
|
2008-04-22 04:13:07 +00:00
|
|
|
/* Setup VBUS PWR (output, asserted, no pullup) */
|
2007-04-11 05:30:15 +00:00
|
|
|
GPBCON=( GPBCON&~(1<<13) ) | (1 << 12);
|
2008-04-22 04:13:07 +00:00
|
|
|
GPBUP|=1<<6;
|
|
|
|
USB_VBUS_PWR_ASSERT;
|
2007-04-11 05:30:15 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/20);
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2008-04-22 04:13:07 +00:00
|
|
|
/* Setup USB reset (output, asserted, no pullup) */
|
2007-04-11 05:30:15 +00:00
|
|
|
GPBCON = (GPBCON & ~0x200) | 0x100; /* Make sure reset line is an output */
|
2008-04-22 04:13:07 +00:00
|
|
|
GPBUP|=1<<4;
|
2007-05-07 19:34:34 +00:00
|
|
|
USB_RST_ASSERT;
|
2007-04-11 05:30:15 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/25);
|
|
|
|
USB_RST_DEASSERT;
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
/* needed to complete the reset */
|
2007-04-11 05:30:15 +00:00
|
|
|
ata_enable(false);
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/15); /* 66ms */
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2007-04-11 05:30:15 +00:00
|
|
|
ata_enable(true);
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/25);
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
/* leave chip in low power mode */
|
2008-04-22 04:13:07 +00:00
|
|
|
USB_VBUS_PWR_DEASSERT;
|
2007-04-12 07:21:51 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/25);
|
|
|
|
}
|
|
|
|
|
|
|
|
void usb_enable(bool on)
|
2008-04-22 04:13:07 +00:00
|
|
|
{
|
2006-12-29 02:49:12 +00:00
|
|
|
if (on)
|
|
|
|
{
|
2008-04-22 04:13:07 +00:00
|
|
|
USB_VBUS_PWR_ASSERT;
|
2007-02-12 07:05:15 +00:00
|
|
|
if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_ENABLE;
|
2006-12-29 02:49:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-02-12 07:05:15 +00:00
|
|
|
if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_DISABLE;
|
2008-04-22 04:13:07 +00:00
|
|
|
USB_VBUS_PWR_DEASSERT;
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|
2007-02-12 07:05:15 +00:00
|
|
|
|
2006-12-29 02:49:12 +00:00
|
|
|
sleep(HZ/20); // > 50ms for detecting the enable state change
|
2006-08-12 08:01:54 +00:00
|
|
|
}
|