blob: 4cd2987d6f99b0abf10a1f6ca99f8d7172f723c0 [file] [log] [blame]
Yinghai Lud57241f2007-02-28 11:17:02 +00001/*
Stefan Reinauerbb01f602009-07-21 21:20:45 +00002 * This file is part of the coreboot project.
3 *
Yinghai Lud57241f2007-02-28 11:17:02 +00004 * Copyright (C) 2006 Eric Biederman (ebiederm@xmission.com)
Stefan Reinauer16ce01b2011-01-28 08:05:54 +00005 * Copyright (C) 2007 AMD
Yinghai Lud57241f2007-02-28 11:17:02 +00006 *
Stefan Reinauerbb01f602009-07-21 21:20:45 +00007 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
Yinghai Lud57241f2007-02-28 11:17:02 +000010 *
Stefan Reinauerbb01f602009-07-21 21:20:45 +000011 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
19 */
Uwe Hermann06694a82010-09-23 18:16:46 +000020
Stefan Reinauer16ce01b2011-01-28 08:05:54 +000021#include <stddef.h>
Yinghai Lud57241f2007-02-28 11:17:02 +000022#include <console/console.h>
Yinghai Lud57241f2007-02-28 11:17:02 +000023#include <arch/io.h>
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +030024#include <device/pci.h>
Stefan Reinauer16ce01b2011-01-28 08:05:54 +000025#include <arch/byteorder.h>
Kyösti Mälkki8ee04d72013-07-06 11:41:09 +030026#include <cpu/x86/car.h>
Kyösti Mälkkie23c22d2013-07-28 23:16:47 +030027#include <string.h>
Yinghai Lud57241f2007-02-28 11:17:02 +000028
29#include <usb_ch9.h>
30#include <ehci.h>
Stefan Reinauerda323732010-05-25 16:17:45 +000031#include <usbdebug.h>
Yinghai Lud57241f2007-02-28 11:17:02 +000032
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +030033
34#define DBGP_EP_VALID (1<<0)
35#define DBGP_EP_ENABLED (1<<1)
36#define DBGP_EP_STATMASK (DBGP_EP_VALID | DBGP_EP_ENABLED)
37
38struct dbgp_pipe
39{
40 u8 endpoint;
41 u8 status;
42 u8 bufidx;
43 char buf[8];
44};
45
46#define DBGP_MAX_ENDPOINTS 4
47#define DBGP_CONSOLE_EPOUT 0
48#define DBGP_CONSOLE_EPIN 1
49
50struct ehci_debug_info {
51 u8 devnum;
52
53 void *ehci_caps;
54 void *ehci_regs;
55 void *ehci_debug;
56
57 struct dbgp_pipe ep_pipe[DBGP_MAX_ENDPOINTS];
58};
59
Kyösti Mälkki3be80cc2013-06-06 10:46:37 +030060#if CONFIG_DEBUG_USBDEBUG
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +030061# define dprintk(LEVEL, args...) printk(LEVEL, args)
Stefan Reinauer16ce01b2011-01-28 08:05:54 +000062#else
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +030063# define dprintk(LEVEL, args...) do {} while(0)
Stefan Reinauer16ce01b2011-01-28 08:05:54 +000064#endif
65
Yinghai Lud57241f2007-02-28 11:17:02 +000066#define USB_DEBUG_DEVNUM 127
67
68#define DBGP_DATA_TOGGLE 0x8800
69#define DBGP_PID_UPDATE(x, tok) \
70 ((((x) ^ DBGP_DATA_TOGGLE) & 0xffff00) | ((tok) & 0xff))
71
72#define DBGP_LEN_UPDATE(x, len) (((x) & ~0x0f) | ((len) & 0x0f))
73/*
74 * USB Packet IDs (PIDs)
75 */
76
77/* token */
78#define USB_PID_OUT 0xe1
79#define USB_PID_IN 0x69
80#define USB_PID_SOF 0xa5
81#define USB_PID_SETUP 0x2d
82/* handshake */
83#define USB_PID_ACK 0xd2
84#define USB_PID_NAK 0x5a
85#define USB_PID_STALL 0x1e
86#define USB_PID_NYET 0x96
87/* data */
88#define USB_PID_DATA0 0xc3
89#define USB_PID_DATA1 0x4b
90#define USB_PID_DATA2 0x87
91#define USB_PID_MDATA 0x0f
92/* Special */
93#define USB_PID_PREAMBLE 0x3c
94#define USB_PID_ERR 0x3c
95#define USB_PID_SPLIT 0x78
96#define USB_PID_PING 0xb4
97#define USB_PID_UNDEF_0 0xf0
98
99#define USB_PID_DATA_TOGGLE 0x88
100#define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE)
101
102#define PCI_CAP_ID_EHCI_DEBUG 0xa
103
104#define HUB_ROOT_RESET_TIME 50 /* times are in msec */
105#define HUB_SHORT_RESET_TIME 10
106#define HUB_LONG_RESET_TIME 200
107#define HUB_RESET_TIMEOUT 500
108
109#define DBGP_MAX_PACKET 8
Sven Schnelle10680872012-07-25 14:19:45 +0200110#define DBGP_LOOPS 1000
Yinghai Lud57241f2007-02-28 11:17:02 +0000111
Kyösti Mälkki8ee04d72013-07-06 11:41:09 +0300112static struct ehci_debug_info glob_dbg_info CAR_GLOBAL;
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300113#if !defined(__PRE_RAM__) && !defined(__SMM__)
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300114static struct device_operations *ehci_drv_ops;
115static struct device_operations ehci_dbg_ops;
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300116#endif
117
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300118static inline struct ehci_debug_info *dbgp_ehci_info(void)
119{
120 return car_get_var_ptr(&glob_dbg_info);
121}
122
Yinghai Lud57241f2007-02-28 11:17:02 +0000123static int dbgp_wait_until_complete(struct ehci_dbg_port *ehci_debug)
124{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000125 u32 ctrl;
Yinghai Lud57241f2007-02-28 11:17:02 +0000126 int loop = 0x100000;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000127
Yinghai Lud57241f2007-02-28 11:17:02 +0000128 do {
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000129 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000130 /* Stop when the transaction is finished */
131 if (ctrl & DBGP_DONE)
132 break;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000133 } while (--loop > 0);
Yinghai Lud57241f2007-02-28 11:17:02 +0000134
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000135 if (!loop)
136 return -1;
Yinghai Lud57241f2007-02-28 11:17:02 +0000137
138 /* Now that we have observed the completed transaction,
139 * clear the done bit.
140 */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000141 write32((unsigned long)&ehci_debug->control, ctrl | DBGP_DONE);
Yinghai Lud57241f2007-02-28 11:17:02 +0000142 return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl);
143}
144
Yinghai Lud57241f2007-02-28 11:17:02 +0000145static void dbgp_breath(void)
146{
147 /* Sleep to give the debug port a chance to breathe */
148}
149
Sven Schnelle10680872012-07-25 14:19:45 +0200150static int dbgp_wait_until_done(struct ehci_dbg_port *ehci_debug, unsigned ctrl, int loop)
Yinghai Lud57241f2007-02-28 11:17:02 +0000151{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000152 u32 pids, lpid;
Yinghai Lud57241f2007-02-28 11:17:02 +0000153 int ret;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000154
Yinghai Lud57241f2007-02-28 11:17:02 +0000155retry:
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000156 write32((unsigned long)&ehci_debug->control, ctrl | DBGP_GO);
Yinghai Lud57241f2007-02-28 11:17:02 +0000157 ret = dbgp_wait_until_complete(ehci_debug);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000158 pids = read32((unsigned long)&ehci_debug->pids);
Yinghai Lud57241f2007-02-28 11:17:02 +0000159 lpid = DBGP_PID_GET(pids);
160
Sven Schnelle10680872012-07-25 14:19:45 +0200161 if (ret < 0) {
162 if (ret == -DBGP_ERR_BAD && --loop > 0)
163 goto retry;
Yinghai Lud57241f2007-02-28 11:17:02 +0000164 return ret;
Sven Schnelle10680872012-07-25 14:19:45 +0200165 }
Yinghai Lud57241f2007-02-28 11:17:02 +0000166
167 /* If the port is getting full or it has dropped data
168 * start pacing ourselves, not necessary but it's friendly.
169 */
170 if ((lpid == USB_PID_NAK) || (lpid == USB_PID_NYET))
171 dbgp_breath();
Stefan Reinauer14e22772010-04-27 06:56:47 +0000172
Yinghai Lud57241f2007-02-28 11:17:02 +0000173 /* If I get a NACK reissue the transmission */
174 if (lpid == USB_PID_NAK) {
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000175 if (--loop > 0)
176 goto retry;
Yinghai Lud57241f2007-02-28 11:17:02 +0000177 }
178
179 return ret;
180}
181
182static void dbgp_set_data(struct ehci_dbg_port *ehci_debug, const void *buf, int size)
183{
184 const unsigned char *bytes = buf;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000185 u32 lo, hi;
Yinghai Lud57241f2007-02-28 11:17:02 +0000186 int i;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000187
Yinghai Lud57241f2007-02-28 11:17:02 +0000188 lo = hi = 0;
189 for (i = 0; i < 4 && i < size; i++)
190 lo |= bytes[i] << (8*i);
191 for (; i < 8 && i < size; i++)
192 hi |= bytes[i] << (8*(i - 4));
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000193 write32((unsigned long)&ehci_debug->data03, lo);
194 write32((unsigned long)&ehci_debug->data47, hi);
Yinghai Lud57241f2007-02-28 11:17:02 +0000195}
196
197static void dbgp_get_data(struct ehci_dbg_port *ehci_debug, void *buf, int size)
198{
199 unsigned char *bytes = buf;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000200 u32 lo, hi;
Yinghai Lud57241f2007-02-28 11:17:02 +0000201 int i;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000202
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000203 lo = read32((unsigned long)&ehci_debug->data03);
204 hi = read32((unsigned long)&ehci_debug->data47);
Yinghai Lud57241f2007-02-28 11:17:02 +0000205 for (i = 0; i < 4 && i < size; i++)
206 bytes[i] = (lo >> (8*i)) & 0xff;
207 for (; i < 8 && i < size; i++)
208 bytes[i] = (hi >> (8*(i - 4))) & 0xff;
209}
210
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700211static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug,
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000212 unsigned devnum, unsigned endpoint, const char *bytes, int size)
Yinghai Lud57241f2007-02-28 11:17:02 +0000213{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000214 u32 pids, addr, ctrl;
Yinghai Lud57241f2007-02-28 11:17:02 +0000215 int ret;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000216
Yinghai Lud57241f2007-02-28 11:17:02 +0000217 if (size > DBGP_MAX_PACKET)
218 return -1;
219
220 addr = DBGP_EPADDR(devnum, endpoint);
221
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000222 pids = read32((unsigned long)&ehci_debug->pids);
Yinghai Lud57241f2007-02-28 11:17:02 +0000223 pids = DBGP_PID_UPDATE(pids, USB_PID_OUT);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000224
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000225 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000226 ctrl = DBGP_LEN_UPDATE(ctrl, size);
227 ctrl |= DBGP_OUT;
228 ctrl |= DBGP_GO;
229
230 dbgp_set_data(ehci_debug, bytes, size);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000231 write32((unsigned long)&ehci_debug->address, addr);
232 write32((unsigned long)&ehci_debug->pids, pids);
Yinghai Lud57241f2007-02-28 11:17:02 +0000233
Sven Schnelle10680872012-07-25 14:19:45 +0200234 ret = dbgp_wait_until_done(ehci_debug, ctrl, DBGP_LOOPS);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000235
Yinghai Lud57241f2007-02-28 11:17:02 +0000236 return ret;
237}
238
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300239int dbgp_bulk_write_x(struct dbgp_pipe *pipe, const char *bytes, int size)
Yinghai Lud57241f2007-02-28 11:17:02 +0000240{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300241 struct ehci_debug_info *dbg_info = dbgp_ehci_info();
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000242 return dbgp_bulk_write(dbg_info->ehci_debug, dbg_info->devnum,
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300243 pipe->endpoint, bytes, size);
Yinghai Lud57241f2007-02-28 11:17:02 +0000244}
245
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000246static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, unsigned devnum,
Sven Schnelle10680872012-07-25 14:19:45 +0200247 unsigned endpoint, void *data, int size, int loops)
Yinghai Lud57241f2007-02-28 11:17:02 +0000248{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000249 u32 pids, addr, ctrl;
Yinghai Lud57241f2007-02-28 11:17:02 +0000250 int ret;
251
252 if (size > DBGP_MAX_PACKET)
253 return -1;
254
255 addr = DBGP_EPADDR(devnum, endpoint);
256
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000257 pids = read32((unsigned long)&ehci_debug->pids);
Yinghai Lud57241f2007-02-28 11:17:02 +0000258 pids = DBGP_PID_UPDATE(pids, USB_PID_IN);
Stefan Reinauer14e22772010-04-27 06:56:47 +0000259
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000260 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000261 ctrl = DBGP_LEN_UPDATE(ctrl, size);
262 ctrl &= ~DBGP_OUT;
263 ctrl |= DBGP_GO;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000264
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000265 write32((unsigned long)&ehci_debug->address, addr);
266 write32((unsigned long)&ehci_debug->pids, pids);
Sven Schnelle10680872012-07-25 14:19:45 +0200267 ret = dbgp_wait_until_done(ehci_debug, ctrl, loops);
Yinghai Lud57241f2007-02-28 11:17:02 +0000268 if (ret < 0)
269 return ret;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000270
Yinghai Lud57241f2007-02-28 11:17:02 +0000271 if (size > ret)
272 size = ret;
273 dbgp_get_data(ehci_debug, data, size);
274 return ret;
275}
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000276
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300277int dbgp_bulk_read_x(struct dbgp_pipe *pipe, void *data, int size)
Yinghai Lud57241f2007-02-28 11:17:02 +0000278{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300279 struct ehci_debug_info *dbg_info = dbgp_ehci_info();
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700280 return dbgp_bulk_read(dbg_info->ehci_debug, dbg_info->devnum,
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300281 pipe->endpoint, data, size, DBGP_LOOPS);
Yinghai Lud57241f2007-02-28 11:17:02 +0000282}
283
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000284static void dbgp_mdelay(int ms)
Yinghai Lud57241f2007-02-28 11:17:02 +0000285{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000286 int i;
287
288 while (ms--) {
289 for (i = 0; i < 1000; i++)
290 inb(0x80);
291 }
292}
293
294static int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requesttype,
295 int request, int value, int index, void *data, int size)
296{
297 u32 pids, addr, ctrl;
Yinghai Lud57241f2007-02-28 11:17:02 +0000298 struct usb_ctrlrequest req;
299 int read;
300 int ret;
301
302 read = (requesttype & USB_DIR_IN) != 0;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000303 if (size > (read ? DBGP_MAX_PACKET:0))
Yinghai Lud57241f2007-02-28 11:17:02 +0000304 return -1;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000305
Yinghai Lud57241f2007-02-28 11:17:02 +0000306 /* Compute the control message */
307 req.bRequestType = requesttype;
308 req.bRequest = request;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000309 req.wValue = cpu_to_le16(value);
310 req.wIndex = cpu_to_le16(index);
311 req.wLength = cpu_to_le16(size);
Yinghai Lud57241f2007-02-28 11:17:02 +0000312
313 pids = DBGP_PID_SET(USB_PID_DATA0, USB_PID_SETUP);
314 addr = DBGP_EPADDR(devnum, 0);
315
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000316 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000317 ctrl = DBGP_LEN_UPDATE(ctrl, sizeof(req));
318 ctrl |= DBGP_OUT;
319 ctrl |= DBGP_GO;
320
321 /* Send the setup message */
322 dbgp_set_data(ehci_debug, &req, sizeof(req));
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000323 write32((unsigned long)&ehci_debug->address, addr);
324 write32((unsigned long)&ehci_debug->pids, pids);
Sven Schnelle10680872012-07-25 14:19:45 +0200325 ret = dbgp_wait_until_done(ehci_debug, ctrl, DBGP_LOOPS);
Yinghai Lud57241f2007-02-28 11:17:02 +0000326 if (ret < 0)
327 return ret;
328
329
330 /* Read the result */
Sven Schnelle10680872012-07-25 14:19:45 +0200331 ret = dbgp_bulk_read(ehci_debug, devnum, 0, data, size, DBGP_LOOPS);
Yinghai Lud57241f2007-02-28 11:17:02 +0000332 return ret;
333}
334
335static int ehci_reset_port(struct ehci_regs *ehci_regs, int port)
336{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000337 u32 portsc;
338 u32 delay_time, delay_ms;
Yinghai Lud57241f2007-02-28 11:17:02 +0000339 int loop;
340
341 /* Reset the usb debug port */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000342 portsc = read32((unsigned long)&ehci_regs->port_status[port - 1]);
Yinghai Lud57241f2007-02-28 11:17:02 +0000343 portsc &= ~PORT_PE;
344 portsc |= PORT_RESET;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000345 write32((unsigned long)&ehci_regs->port_status[port - 1], portsc);
Yinghai Lud57241f2007-02-28 11:17:02 +0000346
Uwe Hermanna34a0b12010-09-22 23:42:32 +0000347 delay_ms = HUB_ROOT_RESET_TIME;
Yinghai Lud57241f2007-02-28 11:17:02 +0000348 for (delay_time = 0; delay_time < HUB_RESET_TIMEOUT;
Uwe Hermanna34a0b12010-09-22 23:42:32 +0000349 delay_time += delay_ms) {
350 dbgp_mdelay(delay_ms);
Yinghai Lud57241f2007-02-28 11:17:02 +0000351
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000352 portsc = read32((unsigned long)&ehci_regs->port_status[port - 1]);
Yinghai Lud57241f2007-02-28 11:17:02 +0000353 if (portsc & PORT_RESET) {
354 /* force reset to complete */
355 loop = 2;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000356 write32((unsigned long)&ehci_regs->port_status[port - 1],
Stefan Reinauer9fe4d792010-01-16 17:53:38 +0000357 portsc & ~(PORT_RWC_BITS | PORT_RESET));
Stefan Reinauer14e22772010-04-27 06:56:47 +0000358 do {
Uwe Hermanna34a0b12010-09-22 23:42:32 +0000359 dbgp_mdelay(delay_ms);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000360 portsc = read32((unsigned long)&ehci_regs->port_status[port - 1]);
Uwe Hermanna34a0b12010-09-22 23:42:32 +0000361 delay_time += delay_ms;
Yinghai Lud57241f2007-02-28 11:17:02 +0000362 } while ((portsc & PORT_RESET) && (--loop > 0));
363 if (!loop) {
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000364 printk(BIOS_DEBUG, "ehci_reset_port forced done");
Yinghai Lud57241f2007-02-28 11:17:02 +0000365 }
366 }
367
368 /* Device went away? */
369 if (!(portsc & PORT_CONNECT))
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000370 return -1; //-ENOTCONN;
Yinghai Lud57241f2007-02-28 11:17:02 +0000371
Martin Rothcbf2bd72013-07-09 21:51:14 -0600372 /* bomb out completely if something weird happened */
Yinghai Lud57241f2007-02-28 11:17:02 +0000373 if ((portsc & PORT_CSC))
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000374 return -2; //-EINVAL;
Yinghai Lud57241f2007-02-28 11:17:02 +0000375
376 /* If we've finished resetting, then break out of the loop */
377 if (!(portsc & PORT_RESET) && (portsc & PORT_PE))
378 return 0;
379 }
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000380 return -3; //-EBUSY;
Yinghai Lud57241f2007-02-28 11:17:02 +0000381}
382
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000383static int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port)
Yinghai Lud57241f2007-02-28 11:17:02 +0000384{
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000385 u32 status;
Yinghai Lud57241f2007-02-28 11:17:02 +0000386 int ret, reps;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000387
Yinghai Lud57241f2007-02-28 11:17:02 +0000388 for (reps = 0; reps < 3; reps++) {
389 dbgp_mdelay(100);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000390 status = read32((unsigned long)&ehci_regs->status);
Yinghai Lud57241f2007-02-28 11:17:02 +0000391 if (status & STS_PCD) {
392 ret = ehci_reset_port(ehci_regs, port);
393 if (ret == 0)
394 return 0;
395 }
396 }
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000397 return -1; //-ENOTCONN;
Yinghai Lud57241f2007-02-28 11:17:02 +0000398}
399
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300400static int usbdebug_init_(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info)
Yinghai Lud57241f2007-02-28 11:17:02 +0000401{
402 struct ehci_caps *ehci_caps;
403 struct ehci_regs *ehci_regs;
404 struct ehci_dbg_port *ehci_debug;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000405
Yinghai Lud57241f2007-02-28 11:17:02 +0000406 struct usb_debug_descriptor dbgp_desc;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000407 u32 cmd, ctrl, status, portsc, hcs_params;
408 u32 debug_port, new_debug_port = 0, n_ports;
409 u32 devnum;
410 int ret, i;
Yinghai Lud57241f2007-02-28 11:17:02 +0000411 int loop;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000412 int port_map_tried;
413 int playtimes = 3;
Yinghai Lud57241f2007-02-28 11:17:02 +0000414
415 ehci_caps = (struct ehci_caps *)ehci_bar;
Stefan Reinauer5ff7c132011-10-31 12:56:45 -0700416 ehci_regs = (struct ehci_regs *)(ehci_bar +
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000417 HC_LENGTH(read32((unsigned long)&ehci_caps->hc_capbase)));
Yinghai Lud57241f2007-02-28 11:17:02 +0000418 ehci_debug = (struct ehci_dbg_port *)(ehci_bar + offset);
Yinghai Lud57241f2007-02-28 11:17:02 +0000419 info->ehci_debug = (void *)0;
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300420
421 memset(&info->ep_pipe, 0, sizeof (info->ep_pipe));
Yinghai Lud57241f2007-02-28 11:17:02 +0000422try_next_time:
423 port_map_tried = 0;
424
425try_next_port:
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000426 hcs_params = read32((unsigned long)&ehci_caps->hcs_params);
Yinghai Lud57241f2007-02-28 11:17:02 +0000427 debug_port = HCS_DEBUG_PORT(hcs_params);
428 n_ports = HCS_N_PORTS(hcs_params);
429
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300430 dprintk(BIOS_INFO, "ehci_bar: 0x%x\n", ehci_bar);
431 dprintk(BIOS_INFO, "debug_port: %d\n", debug_port);
432 dprintk(BIOS_INFO, "n_ports: %d\n", n_ports);
Yinghai Lud57241f2007-02-28 11:17:02 +0000433
Yinghai Lud57241f2007-02-28 11:17:02 +0000434 for (i = 1; i <= n_ports; i++) {
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000435 portsc = read32((unsigned long)&ehci_regs->port_status[i-1]);
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300436 dprintk(BIOS_INFO, "PORTSC #%d: %08x\n", i, portsc);
Yinghai Lud57241f2007-02-28 11:17:02 +0000437 }
Yinghai Lud57241f2007-02-28 11:17:02 +0000438
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000439 if(port_map_tried && (new_debug_port != debug_port)) {
Yinghai Lud57241f2007-02-28 11:17:02 +0000440 if(--playtimes) {
441 set_debug_port(debug_port);
442 goto try_next_time;
443 }
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000444 return -1;
Yinghai Lud57241f2007-02-28 11:17:02 +0000445 }
446
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000447 loop = 100;
Yinghai Lud57241f2007-02-28 11:17:02 +0000448 /* Reset the EHCI controller */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000449 cmd = read32((unsigned long)&ehci_regs->command);
Yinghai Lud57241f2007-02-28 11:17:02 +0000450 cmd |= CMD_RESET;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000451 write32((unsigned long)&ehci_regs->command, cmd);
Yinghai Lud57241f2007-02-28 11:17:02 +0000452 do {
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000453 dbgp_mdelay(10);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000454 cmd = read32((unsigned long)&ehci_regs->command);
Yinghai Lud57241f2007-02-28 11:17:02 +0000455 } while ((cmd & CMD_RESET) && (--loop > 0));
456
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000457 if(!loop) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300458 dprintk(BIOS_INFO, "Could not reset EHCI controller.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000459 // on some systems it works without succeeding here.
460 // return -2;
461 } else {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300462 dprintk(BIOS_INFO, "EHCI controller reset successfully.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000463 }
Yinghai Lud57241f2007-02-28 11:17:02 +0000464
465 /* Claim ownership, but do not enable yet */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000466 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000467 ctrl |= DBGP_OWNER;
468 ctrl &= ~(DBGP_ENABLED | DBGP_INUSE);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000469 write32((unsigned long)&ehci_debug->control, ctrl);
Yinghai Lud57241f2007-02-28 11:17:02 +0000470
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000471 /* Start EHCI controller */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000472 cmd = read32((unsigned long)&ehci_regs->command);
Yinghai Lud57241f2007-02-28 11:17:02 +0000473 cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET);
474 cmd |= CMD_RUN;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000475 write32((unsigned long)&ehci_regs->command, cmd);
Yinghai Lud57241f2007-02-28 11:17:02 +0000476
477 /* Ensure everything is routed to the EHCI */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000478 write32((unsigned long)&ehci_regs->configured_flag, FLAG_CF);
Yinghai Lud57241f2007-02-28 11:17:02 +0000479
480 /* Wait until the controller is no longer halted */
481 loop = 10;
482 do {
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000483 dbgp_mdelay(10);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000484 status = read32((unsigned long)&ehci_regs->status);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000485 } while ((status & STS_HALT) && (--loop > 0));
Yinghai Lud57241f2007-02-28 11:17:02 +0000486
487 if(!loop) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300488 dprintk(BIOS_INFO, "EHCI could not be started.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000489 return -3;
Yinghai Lud57241f2007-02-28 11:17:02 +0000490 }
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300491 dprintk(BIOS_INFO, "EHCI started.\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000492
493 /* Wait for a device to show up in the debug port */
494 ret = ehci_wait_for_port(ehci_regs, debug_port);
495 if (ret < 0) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300496 dprintk(BIOS_INFO, "No device found in debug port %d\n", debug_port);
Yinghai Lud57241f2007-02-28 11:17:02 +0000497 goto next_debug_port;
498 }
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300499 dprintk(BIOS_INFO, "EHCI done waiting for port.\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000500
501 /* Enable the debug port */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000502 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000503 ctrl |= DBGP_CLAIM;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000504 write32((unsigned long)&ehci_debug->control, ctrl);
505 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000506 if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300507 dprintk(BIOS_INFO, "No device in EHCI debug port.\n");
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000508 write32((unsigned long)&ehci_debug->control, ctrl & ~DBGP_CLAIM);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000509 ret = -4;
Yinghai Lud57241f2007-02-28 11:17:02 +0000510 goto err;
511 }
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300512 dprintk(BIOS_INFO, "EHCI debug port enabled.\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000513
514 /* Completely transfer the debug device to the debug controller */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000515 portsc = read32((unsigned long)&ehci_regs->port_status[debug_port - 1]);
Yinghai Lud57241f2007-02-28 11:17:02 +0000516 portsc &= ~PORT_PE;
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000517 write32((unsigned long)&ehci_regs->port_status[debug_port - 1], portsc);
Yinghai Lud57241f2007-02-28 11:17:02 +0000518
519 dbgp_mdelay(100);
520
521 /* Find the debug device and make it device number 127 */
522 for (devnum = 0; devnum <= 127; devnum++) {
523 ret = dbgp_control_msg(ehci_debug, devnum,
524 USB_DIR_IN | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
525 USB_REQ_GET_DESCRIPTOR, (USB_DT_DEBUG << 8), 0,
526 &dbgp_desc, sizeof(dbgp_desc));
527 if (ret > 0)
528 break;
529 }
530 if (devnum > 127) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300531 dprintk(BIOS_INFO, "Could not find attached debug device.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000532 ret = -5;
Yinghai Lud57241f2007-02-28 11:17:02 +0000533 goto err;
534 }
535 if (ret < 0) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300536 dprintk(BIOS_INFO, "Attached device is not a debug device.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000537 ret = -6;
Yinghai Lud57241f2007-02-28 11:17:02 +0000538 goto err;
539 }
Yinghai Lud57241f2007-02-28 11:17:02 +0000540
541 /* Move the device to 127 if it isn't already there */
542 if (devnum != USB_DEBUG_DEVNUM) {
543 ret = dbgp_control_msg(ehci_debug, devnum,
544 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000545 USB_REQ_SET_ADDRESS, USB_DEBUG_DEVNUM, 0, NULL, 0);
Yinghai Lud57241f2007-02-28 11:17:02 +0000546 if (ret < 0) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300547 dprintk(BIOS_INFO, "Could not move attached device to %d.\n",
Yinghai Lud57241f2007-02-28 11:17:02 +0000548 USB_DEBUG_DEVNUM);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000549 ret = -7;
Yinghai Lud57241f2007-02-28 11:17:02 +0000550 goto err;
551 }
552 devnum = USB_DEBUG_DEVNUM;
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300553 dprintk(BIOS_INFO, "EHCI debug device renamed to 127.\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000554 }
555
556 /* Enable the debug interface */
557 ret = dbgp_control_msg(ehci_debug, USB_DEBUG_DEVNUM,
558 USB_DIR_OUT | USB_TYPE_STANDARD | USB_RECIP_DEVICE,
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000559 USB_REQ_SET_FEATURE, USB_DEVICE_DEBUG_MODE, 0, NULL, 0);
Yinghai Lud57241f2007-02-28 11:17:02 +0000560 if (ret < 0) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300561 dprintk(BIOS_INFO, "Could not enable EHCI debug device.\n");
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000562 ret = -8;
Yinghai Lud57241f2007-02-28 11:17:02 +0000563 goto err;
564 }
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300565 dprintk(BIOS_INFO, "EHCI debug interface enabled.\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000566
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000567 /* Perform a small write to get the even/odd data state in sync */
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300568 ret = dbgp_bulk_write(ehci_debug, USB_DEBUG_DEVNUM, dbgp_desc.bDebugOutEndpoint, "USB\r\n",5);
Yinghai Lud57241f2007-02-28 11:17:02 +0000569 if (ret < 0) {
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300570 dprintk(BIOS_INFO, "dbgp_bulk_write failed: %d\n", ret);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000571 ret = -9;
Yinghai Lud57241f2007-02-28 11:17:02 +0000572 goto err;
573 }
Kyösti Mälkki8ff3d682013-08-12 16:11:34 +0300574 dprintk(BIOS_INFO, "Test write done\n");
Yinghai Lud57241f2007-02-28 11:17:02 +0000575
576 info->ehci_caps = ehci_caps;
577 info->ehci_regs = ehci_regs;
578 info->ehci_debug = ehci_debug;
579 info->devnum = devnum;
Stefan Reinauer14e22772010-04-27 06:56:47 +0000580
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300581 info->ep_pipe[DBGP_CONSOLE_EPOUT].endpoint = dbgp_desc.bDebugOutEndpoint;
582 info->ep_pipe[DBGP_CONSOLE_EPIN].endpoint = dbgp_desc.bDebugInEndpoint;
583 info->ep_pipe[DBGP_CONSOLE_EPOUT].status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
584 info->ep_pipe[DBGP_CONSOLE_EPIN].status |= DBGP_EP_ENABLED | DBGP_EP_VALID;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000585 return 0;
Yinghai Lud57241f2007-02-28 11:17:02 +0000586err:
587 /* Things didn't work so remove my claim */
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000588 ctrl = read32((unsigned long)&ehci_debug->control);
Yinghai Lud57241f2007-02-28 11:17:02 +0000589 ctrl &= ~(DBGP_CLAIM | DBGP_OUT);
Stefan Reinauer75a05dc2010-05-25 16:35:51 +0000590 write32((unsigned long)(unsigned long)&ehci_debug->control, ctrl);
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000591 //return ret;
Yinghai Lud57241f2007-02-28 11:17:02 +0000592
593next_debug_port:
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000594 port_map_tried |= (1 << (debug_port - 1));
595 new_debug_port = ((debug_port-1 + 1) % n_ports) + 1;
596 if (port_map_tried != ((1 << n_ports) - 1)) {
Yinghai Lud57241f2007-02-28 11:17:02 +0000597 set_debug_port(new_debug_port);
598 goto try_next_port;
599 }
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000600 if (--playtimes) {
601 //set_debug_port(new_debug_port);
Yinghai Lud57241f2007-02-28 11:17:02 +0000602 set_debug_port(debug_port);
603 goto try_next_time;
604 }
605
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000606 return -10;
607}
608
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300609void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data)
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000610{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300611 if (dbgp_ep_is_active(pipe)) {
612 pipe->buf[pipe->bufidx++] = data;
613 if (pipe->bufidx >= 8) {
614 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
615 pipe->bufidx = 0;
Sven Schnelle82704c62012-07-26 14:31:40 +0200616 }
617 }
618}
619
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300620void usbdebug_tx_flush(struct dbgp_pipe *pipe)
Sven Schnelle82704c62012-07-26 14:31:40 +0200621{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300622 if (dbgp_ep_is_active(pipe) && pipe->bufidx > 0) {
623 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
624 pipe->bufidx = 0;
Stefan Reinauer16ce01b2011-01-28 08:05:54 +0000625 }
Kyösti Mälkki4d409b52013-07-05 21:38:54 +0300626}
627
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300628#if !defined(__PRE_RAM__) && !defined(__SMM__)
629static void usbdebug_re_enable(unsigned ehci_base)
630{
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300631 struct ehci_debug_info *dbg_info = dbgp_ehci_info();
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300632 unsigned diff;
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300633 int i;
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300634
635 if (!dbg_info->ehci_debug)
636 return;
637
638 diff = (unsigned)dbg_info->ehci_caps - ehci_base;
639 dbg_info->ehci_regs -= diff;
640 dbg_info->ehci_debug -= diff;
641 dbg_info->ehci_caps = (void*)ehci_base;
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300642
643 for (i=0; i<DBGP_MAX_ENDPOINTS; i++)
644 dbg_info->ep_pipe[i].status |= DBGP_EP_ENABLED;
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300645}
646
647static void usbdebug_disable(void)
648{
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300649 struct ehci_debug_info *dbg_info = dbgp_ehci_info();
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300650 int i;
651 for (i=0; i<DBGP_MAX_ENDPOINTS; i++)
652 dbg_info->ep_pipe[i].status &= ~DBGP_EP_ENABLED;
Kyösti Mälkki41c10cd2013-07-09 04:19:22 +0300653}
654
655static void pci_ehci_set_resources(struct device *dev)
656{
657 struct resource *res;
658
659 printk(BIOS_DEBUG, "%s EHCI Debug Port hook triggered\n", dev_path(dev));
660 usbdebug_disable();
661
662 if (ehci_drv_ops->set_resources)
663 ehci_drv_ops->set_resources(dev);
664 res = find_resource(dev, EHCI_BAR_INDEX);
665 if (!res)
666 return;
667
668 usbdebug_re_enable((u32)res->base);
669 report_resource_stored(dev, res, "");
670 printk(BIOS_DEBUG, "%s EHCI Debug Port relocated\n", dev_path(dev));
671}
672
673void pci_ehci_read_resources(struct device *dev)
674{
675 if (!ehci_drv_ops) {
676 memcpy(&ehci_dbg_ops, dev->ops, sizeof(ehci_dbg_ops));
677 ehci_drv_ops = dev->ops;
678 ehci_dbg_ops.set_resources = pci_ehci_set_resources;
679 dev->ops = &ehci_dbg_ops;
680 printk(BIOS_DEBUG, "%s EHCI BAR hook registered\n", dev_path(dev));
681 } else {
682 printk(BIOS_DEBUG, "More than one caller of %s from %s\n", __func__, dev_path(dev));
683 }
684
685 pci_dev_read_resources(dev);
686}
687#endif
688
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300689int dbgp_ep_is_active(struct dbgp_pipe *pipe)
Kyösti Mälkki4d409b52013-07-05 21:38:54 +0300690{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300691 return (pipe->status & DBGP_EP_STATMASK) == (DBGP_EP_VALID | DBGP_EP_ENABLED);
Yinghai Lud57241f2007-02-28 11:17:02 +0000692}
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300693
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300694struct dbgp_pipe *dbgp_console_output(void)
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300695{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300696 return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPOUT];
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300697}
698
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300699struct dbgp_pipe *dbgp_console_input(void)
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300700{
Kyösti Mälkki026ff3e2013-07-08 18:11:44 +0300701 return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPIN];
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300702}
703
704int usbdebug_init(void)
705{
Kyösti Mälkkicbe2ede2013-07-11 07:49:46 +0300706 struct ehci_debug_info *dbg_info = dbgp_ehci_info();
Kyösti Mälkki8ee04d72013-07-06 11:41:09 +0300707
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +0300708#if defined(__PRE_RAM__) || !CONFIG_EARLY_CONSOLE
709 enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT);
710#endif
711 return usbdebug_init_(CONFIG_EHCI_BAR, CONFIG_EHCI_DEBUG_OFFSET, dbg_info);
712}