summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c')
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c94
1 files changed, 94 insertions, 0 deletions
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
new file mode 100644
index 0000000000..3aed8c3256
--- /dev/null
+++ b/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
@@ -0,0 +1,94 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Linus Nielsen Feltzing
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "config.h"
20#include <stdbool.h>
21#include "cpu.h"
22#include "system.h"
23#include "kernel.h"
24#include "ata.h"
25
26#define USB_RST_ASSERT GPBDAT &= ~(1 << 4)
27#define USB_RST_DEASSERT GPBDAT |= (1 << 4)
28
29#define USB_VPLUS_PWR_ASSERT GPBDAT |= (1 << 6)
30#define USB_VPLUS_PWR_DEASSERT GPBDAT &= ~(1 << 6)
31
32#define USB_UNIT_IS_PRESENT !(GPFDAT & 0x01)
33#define USB_CRADLE_IS_PRESENT ((GPFDAT &0x02)&&!(GPGDAT&1<<14))
34
35#define USB_CRADLE_BUS_ENABLE GPHDAT |= (1 << 8)
36#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8)
37
38/* The usb detect is one pin to the cpu active low */
39inline bool usb_detect(void)
40{
41 return USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT;
42}
43
44void usb_init_device(void)
45{
46 /* Input is the default configuration, only pullups need to be disabled */
47 GPFUP|=0x02;
48
49 USB_VPLUS_PWR_ASSERT;
50 GPBCON=( GPBCON&~(1<<13) ) | (1 << 12);
51
52 sleep(HZ/20);
53
54 /* Reset the usb port */
55 USB_RST_ASSERT;
56 GPBCON = (GPBCON & ~0x200) | 0x100; /* Make sure reset line is an output */
57
58 sleep(HZ/25);
59 USB_RST_DEASSERT;
60
61 /* needed to complete the reset */
62 ata_enable(false);
63
64 sleep(HZ/15); /* 66ms */
65
66 ata_enable(true);
67
68 sleep(HZ/25);
69
70 /* leave chip in low power mode */
71 USB_VPLUS_PWR_DEASSERT;
72
73 sleep(HZ/25);
74}
75
76void usb_enable(bool on)
77{
78 if (on)
79 {
80 USB_VPLUS_PWR_ASSERT;
81 if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_ENABLE;
82 }
83 else
84 {
85 if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_DISABLE;
86 USB_VPLUS_PWR_DEASSERT;
87 }
88
89 /* Make sure USB_CRADLE_BUS pin is an output */
90 GPHCON=( GPHCON&~(1<<17) ) | (1<<16); /* Make the pin an output */
91 GPHUP|=1<<8; /* Disable pullup in SOC as we are now driving */
92
93 sleep(HZ/20); // > 50ms for detecting the enable state change
94}