summaryrefslogtreecommitdiff
path: root/firmware/target/arm/tms320dm320/mrobe-500/usb-mr500.c
blob: 5a60a248436030a9e75a3f1ba91e7b7605481fa1 (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
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2007, 2009 by Karl Kurbjun
 *
 * 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.
 *
 ****************************************************************************/
/*#define LOGF_ENABLE*/

#include "config.h"
#include "logf.h"
#include "cpu.h"
#include "system.h"

#include "m66591.h"

void usb_init_device(void) {
    logf("mxx: SOC Init");

    /* The following EMIF timing values are from the OF:
     *      IO_EMIF_CS4CTRL1 = 0x66AB;
     *      IO_EMIF_CS4CTRL2 = 0x4220;
     *
     * More agressive numbers may be possible, but it depends on the clocking
     *  setup. 
     *
     * When USB_TRANS_BLOCK is not defined the USB driver does not work unless
     *  the values from the OF are used.
     */
    
    IO_EMIF_CS4CTRL1 = 0x66AB;
    IO_EMIF_CS4CTRL2 = 0x4220; 

    /* Setup the m66591 reset signal */
    /*  2: output, non-inverted, no-irq, falling edge, no-chat, normal */
    dm320_set_io(2, false, false, false, false, false, 0x00);

    /* Setup the m66591 interrupt signal */
    /*  3: input , non-inverted,    irq, falling edge, no-chat, normal */
    dm320_set_io(3, true, false, true, false, false, 0x00);
    
    udelay(100);
    
    /* Drive the reset pin low */
    IO_GIO_BITCLR0  = 1<<2;

    /* Wait a bit */
    udelay(100);

    /* Release the reset (drive it high) */
    IO_GIO_BITSET0  = 1<<2;
    
    udelay(500);

    /* Enable the MXX interrupt */
    IO_INTC_EINT1 |= (1<<8); /* IRQ_GIO3 */
}

/* This is the initial interupt handler routine for the USB controller */
void GIO3 (void)  __attribute__ ((section(".icode")));
void GIO3 (void) {
    /* Clear the interrupt, this is critical to do before running the full
     *  handler otherwise you might miss an interrupt and everything will stop
     *  working.
     *
     * The M66591 interrupt line is attached to GPIO3.
     */
    IO_INTC_IRQ1 = (1<<8); 
    
    /* Start the full handler which is located in the driver */
    USB_DEVICE();
}