Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 by Linus Nielsen Feltzing |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 12 | * This program is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU General Public License |
| 14 | * as published by the Free Software Foundation; either version 2 |
| 15 | * of the License, or (at your option) any later version. |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | #include "config.h" |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 22 | #include "cpu.h" |
| 23 | #include "system.h" |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 24 | #include "kernel.h" |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 25 | #include "ata.h" |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 26 | #include "usb.h" |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 27 | |
| 28 | #define USB_RST_ASSERT GPBDAT &= ~(1 << 4) |
| 29 | #define USB_RST_DEASSERT GPBDAT |= (1 << 4) |
| 30 | |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 31 | #define USB_VBUS_PWR_ASSERT GPBDAT |= (1 << 6) |
| 32 | #define USB_VBUS_PWR_DEASSERT GPBDAT &= ~(1 << 6) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 33 | |
Karl Kurbjun | b081052 | 2007-02-12 07:05:15 +0000 | [diff] [blame] | 34 | #define USB_UNIT_IS_PRESENT !(GPFDAT & 0x01) |
Marcoen Hirschberg | df43715 | 2007-06-23 18:25:41 +0000 | [diff] [blame] | 35 | #define USB_CRADLE_IS_PRESENT ((GPFDAT &0x02)&&((GPGDAT&(3<<13))==(1<<13))) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 36 | |
Karl Kurbjun | b081052 | 2007-02-12 07:05:15 +0000 | [diff] [blame] | 37 | #define USB_CRADLE_BUS_ENABLE GPHDAT |= (1 << 8) |
| 38 | #define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 39 | |
| 40 | /* The usb detect is one pin to the cpu active low */ |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 41 | int usb_detect(void) |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 42 | { |
Dave Chapman | 1672350 | 2007-09-04 08:03:07 +0000 | [diff] [blame] | 43 | if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT) |
| 44 | return USB_INSERTED; |
| 45 | else |
| 46 | return USB_EXTRACTED; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 47 | } |
| 48 | |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 49 | void usb_init_device(void) |
| 50 | { |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 51 | /* Setup USB Cradle Power control (output, disabled, no pullup) */ |
| 52 | GPHCON=( GPHCON&~(1<<17) ) | (1<<16); |
| 53 | GPHUP|=1<<8; |
| 54 | USB_CRADLE_BUS_DISABLE; |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 55 | |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 56 | /* Setup VBUS PWR (output, asserted, no pullup) */ |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 57 | GPBCON=( GPBCON&~(1<<13) ) | (1 << 12); |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 58 | GPBUP|=1<<6; |
| 59 | USB_VBUS_PWR_ASSERT; |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 60 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 61 | sleep(HZ/20); |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 62 | |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 63 | /* Setup USB reset (output, asserted, no pullup) */ |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 64 | GPBCON = (GPBCON & ~0x200) | 0x100; /* Make sure reset line is an output */ |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 65 | GPBUP|=1<<4; |
Karl Kurbjun | 173b611 | 2007-05-07 19:34:34 +0000 | [diff] [blame] | 66 | USB_RST_ASSERT; |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 67 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 68 | sleep(HZ/25); |
| 69 | USB_RST_DEASSERT; |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 70 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 71 | /* needed to complete the reset */ |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 72 | ata_enable(false); |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 73 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 74 | sleep(HZ/15); /* 66ms */ |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 75 | |
Karl Kurbjun | 60fed9a | 2007-04-11 05:30:15 +0000 | [diff] [blame] | 76 | ata_enable(true); |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 77 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 78 | sleep(HZ/25); |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 79 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 80 | /* leave chip in low power mode */ |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 81 | USB_VBUS_PWR_DEASSERT; |
Karl Kurbjun | dcf6bd2 | 2007-04-12 07:21:51 +0000 | [diff] [blame] | 82 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 83 | sleep(HZ/25); |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 84 | } |
| 85 | |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 86 | void usb_enable(bool on) |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 87 | { |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 88 | if (on) |
| 89 | { |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 90 | USB_VBUS_PWR_ASSERT; |
Karl Kurbjun | b081052 | 2007-02-12 07:05:15 +0000 | [diff] [blame] | 91 | if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_ENABLE; |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 92 | } |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 93 | else |
| 94 | { |
Karl Kurbjun | b081052 | 2007-02-12 07:05:15 +0000 | [diff] [blame] | 95 | if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_DISABLE; |
Karl Kurbjun | 68afa9d | 2008-04-22 04:13:07 +0000 | [diff] [blame] | 96 | USB_VBUS_PWR_DEASSERT; |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 97 | } |
Karl Kurbjun | b081052 | 2007-02-12 07:05:15 +0000 | [diff] [blame] | 98 | |
Marcoen Hirschberg | 2953676 | 2006-12-29 02:49:12 +0000 | [diff] [blame] | 99 | sleep(HZ/20); // > 50ms for detecting the enable state change |
Marcoen Hirschberg | dd75488 | 2006-08-12 08:01:54 +0000 | [diff] [blame] | 100 | } |