summaryrefslogtreecommitdiffstats
path: root/firmware/target/arm/s3c2440/gigabeat-fx/usb-meg-fx.c
blob: 217a7d3cefa380e6f8498aa32ceac13cf14a2c1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2006 by Linus Nielsen Feltzing
 *
 * 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 "cpu.h"
#include "system.h"
#include "kernel.h"
#include "ata.h"
#include "usb.h"

#define USB_RST_ASSERT   GPBDAT &= ~(1 << 4)
#define USB_RST_DEASSERT GPBDAT |=  (1 << 4)

#define USB_VPLUS_PWR_ASSERT    GPBDAT |=  (1 << 6)
#define USB_VPLUS_PWR_DEASSERT  GPBDAT &= ~(1 << 6)

#define USB_UNIT_IS_PRESENT  !(GPFDAT & 0x01)
#define USB_CRADLE_IS_PRESENT  ((GPFDAT &0x02)&&((GPGDAT&(3<<13))==(1<<13)))

#define USB_CRADLE_BUS_ENABLE GPHDAT |=  (1 << 8)
#define USB_CRADLE_BUS_DISABLE GPHDAT &= ~(1 << 8)

/* The usb detect is one pin to the cpu active low */
int usb_detect(void)
{
   if (USB_UNIT_IS_PRESENT | USB_CRADLE_IS_PRESENT)
       return USB_INSERTED;
   else
       return USB_EXTRACTED;
}

void usb_init_device(void)
{
    /* Input is the default configuration, only pullups need to be disabled */
/*    GPFUP|=0x02;  */

    GPBCON=( GPBCON&~(1<<13) ) | (1 << 12);
    USB_VPLUS_PWR_ASSERT;

    sleep(HZ/20);

    /* Reset the usb port */
    GPBCON = (GPBCON & ~0x200) | 0x100; /* Make sure reset line is an output */
    USB_RST_ASSERT;

    sleep(HZ/25);
    USB_RST_DEASSERT;

    /* needed to complete the reset */
    ata_enable(false);

    sleep(HZ/15);       /* 66ms */

    ata_enable(true);

    sleep(HZ/25);

    /* leave chip in low power mode */
    USB_VPLUS_PWR_DEASSERT;

    sleep(HZ/25);
}

void usb_enable(bool on)
{
    GPHCON=( GPHCON&~(1<<17) ) | (1<<16); /* Make the pin an output */
    GPHUP|=1<<8;  /* Disable pullup in SOC as we are now driving */
    
    if (on)
    {
        USB_VPLUS_PWR_ASSERT;
        if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_ENABLE;
    }
    else
    {
        if(USB_CRADLE_IS_PRESENT) USB_CRADLE_BUS_DISABLE;
        USB_VPLUS_PWR_DEASSERT;
    }

    sleep(HZ/20); // > 50ms for detecting the enable state change
}