2011-11-16 14:08:01 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: $
|
|
|
|
*
|
2021-06-05 07:22:27 +00:00
|
|
|
* Copyright (C) 2011-2021 by Tomasz Moń
|
2011-11-16 14:08:01 +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.
|
|
|
|
*
|
|
|
|
* 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 "kernel.h"
|
|
|
|
#include "usb_core.h"
|
2011-12-16 11:20:38 +00:00
|
|
|
|
|
|
|
static int usb_detect_callback(struct timeout *tmo)
|
|
|
|
{
|
|
|
|
(void)tmo;
|
2021-06-05 07:22:27 +00:00
|
|
|
usb_status_event(usb_detect());
|
2011-12-16 11:20:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GIO9(void) __attribute__ ((section(".icode")));
|
|
|
|
void GIO9(void)
|
|
|
|
{
|
|
|
|
static struct timeout usb_oneshot;
|
|
|
|
|
|
|
|
/* Clear interrupt */
|
|
|
|
IO_INTC_IRQ1 = (1 << 14);
|
|
|
|
|
|
|
|
timeout_register(&usb_oneshot, usb_detect_callback, HZ, 0);
|
|
|
|
}
|
|
|
|
|
2011-11-16 14:08:01 +00:00
|
|
|
int usb_detect(void)
|
|
|
|
{
|
2021-06-05 07:22:27 +00:00
|
|
|
if (IO_GIO_BITSET0 & (1 << 9))
|
2011-12-16 11:20:38 +00:00
|
|
|
{
|
2021-06-05 07:22:27 +00:00
|
|
|
return USB_EXTRACTED;
|
2011-12-16 11:20:38 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-06-05 07:22:27 +00:00
|
|
|
return USB_INSERTED;
|
2011-12-16 11:20:38 +00:00
|
|
|
}
|
2011-11-16 14:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_init_device(void)
|
|
|
|
{
|
2011-12-03 15:03:44 +00:00
|
|
|
/* set VLYNQ port functions */
|
|
|
|
IO_GIO_FSEL1 = 0xAAAA;
|
|
|
|
IO_GIO_FSEL2 = (IO_GIO_FSEL2 & 0xFFF0) | 0xA;
|
|
|
|
|
2011-12-16 11:20:38 +00:00
|
|
|
/* set GIO7 as output (TNETV reset) */
|
|
|
|
/* set GIO9 as input (USB inserted indicator) */
|
|
|
|
IO_GIO_INV0 &= ~((1 << 7) | (1 << 9));
|
|
|
|
IO_GIO_DIR0 = (IO_GIO_DIR0 & ~(1 << 7)) | (1 << 9);
|
|
|
|
|
|
|
|
/* Enable interrupt on GIO9 change (any edge) */
|
|
|
|
IO_GIO_IRQPORT |= (1 << 9);
|
|
|
|
IO_GIO_IRQEDGE |= (1 << 9);
|
|
|
|
|
|
|
|
/* set GIO33 as output (TNETV clock) */
|
|
|
|
IO_GIO_DIR2 &= ~(1 << 1);
|
|
|
|
IO_GIO_INV2 &= ~(1 << 1);
|
|
|
|
/* use M48XI clock on GIO33 */
|
|
|
|
IO_CLK_OSEL = (IO_CLK_OSEL & 0xF0F) | 0x50;
|
|
|
|
|
|
|
|
/* Powerdown internal USB */
|
|
|
|
IO_CLK_LPCTL1 = 0x11;
|
|
|
|
/* Disable internal USB clock */
|
|
|
|
IO_CLK_MOD2 &= ~(1 << 6);
|
|
|
|
|
|
|
|
/* Enable USB insert detection interrupt */
|
|
|
|
IO_INTC_EINT1 |= (1 << 14);
|
2011-11-16 14:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_enable(bool on)
|
|
|
|
{
|
2021-06-05 07:22:27 +00:00
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
usb_core_init();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
usb_core_exit();
|
|
|
|
}
|
2011-11-16 14:08:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void usb_attach(void)
|
|
|
|
{
|
|
|
|
}
|