summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700/usb-s5l8701.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700/usb-s5l8701.c')
-rw-r--r--firmware/target/arm/s5l8700/usb-s5l8701.c138
1 files changed, 138 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/usb-s5l8701.c b/firmware/target/arm/s5l8700/usb-s5l8701.c
new file mode 100644
index 0000000000..860f54b2d8
--- /dev/null
+++ b/firmware/target/arm/s5l8700/usb-s5l8701.c
@@ -0,0 +1,138 @@
1/***************************************************************************
2* __________ __ ___.
3* Open \______ \ ____ ____ | | _\_ |__ _______ ___
4* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7* \/ \/ \/ \/ \/
8* $Id$
9*
10* Copyright (C) 2014 Michael Sparmann
11*
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.
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 <inttypes.h>
22
23#include "config.h"
24#include "usb.h"
25#include "usb_drv.h"
26#ifdef HAVE_USBSTACK
27#include "usb_core.h"
28#include "power.h"
29#endif
30
31#include "s5l8700.h"
32#include "usb-designware.h"
33
34
35const struct usb_dw_config usb_dw_config =
36{
37 /* PHY must run at 60MHz, otherwise there are spurious -EPROTO
38 errors, probably related with GHWCFG4_MIN_AHB_FREQ. */
39 .phytype = DWC_PHYTYPE_UTMI_8,
40
41 /*
42 * Total available FIFO memory: 0x500 words.
43 */
44 .rx_fifosz = 0x220,
45 /* nptx_fifosz seems limited to 0x200 due to some internal counter
46 misbehaviour (TBC). */
47 .nptx_fifosz = 0x200,
48 /* ptx_fifosz is not writeable (fixed to 0x300), anyway it seems
49 internally limited to a small number, aroung 0x10..0x20 (TBC),
50 we use_ptxfifo_as_plain_buffer to deal with this issue. */
51 .ptx_fifosz = 0x80,
52 .use_ptxfifo_as_plain_buffer = true,
53
54#ifdef USB_DW_ARCH_SLAVE
55 .disable_double_buffering = false,
56#else
57 .ahb_burst_len = HBSTLEN_INCR4,
58#endif
59};
60
61void usb_dw_target_enable_clocks()
62{
63 PWRCON &= ~0x4000;
64 PWRCONEXT &= ~0x800;
65
66 OPHYPWR = 0; /* PHY: Power up */
67 udelay(10);
68 OPHYUNK1 = 1;
69 OPHYUNK2 = 0xe3f;
70 ORSTCON = 1; /* PHY: Assert Software Reset */
71 udelay(10);
72 ORSTCON = 0; /* PHY: Deassert Software Reset */
73 udelay(10);
74 OPHYUNK3 = 0x600;
75 OPHYCLK = USB_DW_CLOCK;
76 udelay(400);
77}
78
79void usb_dw_target_disable_clocks()
80{
81 OPHYPWR = 0xf; /* PHY: Power down */
82 udelay(10);
83 ORSTCON = 7; /* PHY: Assert Software Reset */
84 udelay(10);
85
86 PWRCON |= 0x4000;
87 PWRCONEXT |= 0x800;
88}
89
90void usb_dw_target_enable_irq()
91{
92 INTMSK |= INTMSK_USB_OTG;
93}
94
95void usb_dw_target_disable_irq()
96{
97 INTMSK &= ~INTMSK_USB_OTG;
98}
99
100void usb_dw_target_clear_irq()
101{
102 SRCPND |= INTMSK_USB_OTG;
103}
104
105/* RB API fuctions */
106void usb_enable(bool on)
107{
108#ifdef HAVE_USBSTACK
109 if (on){
110 cpu_boost(1);
111 usb_core_init();
112 } else {
113 usb_core_exit();
114 cpu_boost(0);
115 }
116#else
117 (void)on;
118#endif
119}
120
121int usb_detect(void)
122{
123#ifdef HAVE_USBSTACK
124 if (power_input_status() & POWER_INPUT_USB)
125 return USB_INSERTED;
126#endif
127 return USB_EXTRACTED;
128}
129
130void usb_init_device(void)
131{
132 /* Power up the core clocks to allow writing
133 to some registers needed to power it down */
134 usb_dw_target_disable_irq();
135 usb_dw_target_enable_clocks();
136
137 usb_drv_exit();
138}