Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | bb01f60 | 2009-07-21 21:20:45 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
| 3 | * |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006 Eric Biederman (ebiederm@xmission.com) |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007 AMD |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 6 | * |
Stefan Reinauer | bb01f60 | 2009-07-21 21:20:45 +0000 | [diff] [blame] | 7 | * 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 Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 10 | * |
Stefan Reinauer | bb01f60 | 2009-07-21 21:20:45 +0000 | [diff] [blame] | 11 | * 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. |
Stefan Reinauer | bb01f60 | 2009-07-21 21:20:45 +0000 | [diff] [blame] | 15 | */ |
Uwe Hermann | 06694a8 | 2010-09-23 18:16:46 +0000 | [diff] [blame] | 16 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 17 | #include <stddef.h> |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 18 | #include <console/console.h> |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 19 | #include <console/usb.h> |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 20 | #include <arch/io.h> |
Stefan Reinauer | fd4f413 | 2013-06-19 12:25:44 -0700 | [diff] [blame] | 21 | #include <arch/early_variables.h> |
Kyösti Mälkki | e23c22d | 2013-07-28 23:16:47 +0300 | [diff] [blame] | 22 | #include <string.h> |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 23 | #include <cbmem.h> |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 24 | |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 25 | #include "ehci_debug.h" |
Kyösti Mälkki | e2227a2 | 2014-02-05 13:02:55 +0200 | [diff] [blame] | 26 | #include "usb_ch9.h" |
| 27 | #include "ehci.h" |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 28 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 29 | struct ehci_debug_info { |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 30 | void *ehci_base; |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 31 | void *ehci_debug; |
| 32 | |
| 33 | struct dbgp_pipe ep_pipe[DBGP_MAX_ENDPOINTS]; |
| 34 | }; |
| 35 | |
Kyösti Mälkki | 3be80cc | 2013-06-06 10:46:37 +0300 | [diff] [blame] | 36 | #if CONFIG_DEBUG_USBDEBUG |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 37 | static void dbgp_print_data(struct ehci_dbg_port *ehci_debug); |
Kyösti Mälkki | d799140 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 38 | static int dbgp_enabled(void); |
| 39 | # define dprintk(LEVEL, args...) \ |
| 40 | do { if (!dbgp_enabled()) printk(LEVEL, ##args); } while (0) |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 41 | #else |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 42 | # define dbgp_print_data(x) do {} while(0) |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 43 | # define dprintk(LEVEL, args...) do {} while(0) |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 44 | #endif |
| 45 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 46 | #define DBGP_LEN_UPDATE(x, len) (((x) & ~0x0f) | ((len) & 0x0f)) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 47 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 48 | #define DBGP_CLAIM (DBGP_OWNER | DBGP_ENABLED | DBGP_INUSE) |
| 49 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 50 | #define HUB_ROOT_RESET_TIME 50 /* times are in msec */ |
| 51 | #define HUB_SHORT_RESET_TIME 10 |
| 52 | #define HUB_LONG_RESET_TIME 200 |
| 53 | #define HUB_RESET_TIMEOUT 500 |
| 54 | |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 55 | #define DBGP_MICROFRAME_TIMEOUT_LOOPS 1000 |
| 56 | #define DBGP_MICROFRAME_RETRIES 10 |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 57 | #define DBGP_MAX_PACKET 8 |
| 58 | |
Kyösti Mälkki | 8ee04d7 | 2013-07-06 11:41:09 +0300 | [diff] [blame] | 59 | static struct ehci_debug_info glob_dbg_info CAR_GLOBAL; |
Kyösti Mälkki | 618d179 | 2014-10-27 08:01:55 +0200 | [diff] [blame] | 60 | static struct ehci_debug_info * glob_dbg_info_p CAR_GLOBAL; |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 61 | |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 62 | static inline struct ehci_debug_info *dbgp_ehci_info(void) |
| 63 | { |
Kyösti Mälkki | 618d179 | 2014-10-27 08:01:55 +0200 | [diff] [blame] | 64 | if (car_get_var(glob_dbg_info_p) == NULL) |
| 65 | car_set_var(glob_dbg_info_p, &glob_dbg_info); |
| 66 | |
| 67 | return car_get_var(glob_dbg_info_p); |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 68 | } |
| 69 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 70 | static int dbgp_wait_until_complete(struct ehci_dbg_port *ehci_debug) |
| 71 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 72 | u32 ctrl; |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 73 | int loop = 0; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 74 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 75 | do { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 76 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 77 | /* Stop when the transaction is finished */ |
| 78 | if (ctrl & DBGP_DONE) |
| 79 | break; |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 80 | } while (++loop < DBGP_MICROFRAME_TIMEOUT_LOOPS); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 81 | |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 82 | if (! (ctrl & DBGP_DONE)) { |
| 83 | dprintk(BIOS_ERR, "dbgp_wait_until_complete: retry timeout.\n"); |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 84 | return -DBGP_ERR_SIGNAL; |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 85 | } |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 86 | |
| 87 | /* Now that we have observed the completed transaction, |
| 88 | * clear the done bit. |
| 89 | */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 90 | write32(&ehci_debug->control, ctrl | DBGP_DONE); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 91 | return (ctrl & DBGP_ERROR) ? -DBGP_ERRCODE(ctrl) : DBGP_LEN(ctrl); |
| 92 | } |
| 93 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 94 | static void dbgp_breath(void) |
| 95 | { |
| 96 | /* Sleep to give the debug port a chance to breathe */ |
| 97 | } |
| 98 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 99 | static int dbgp_wait_until_done(struct ehci_dbg_port *ehci_debug, struct dbgp_pipe *pipe, |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 100 | unsigned ctrl, const int timeout) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 101 | { |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 102 | u32 rd_ctrl, rd_pids; |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 103 | u32 ctrl_prev = 0, pids_prev = 0; |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 104 | u8 lpid; |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 105 | int ret, host_retries; |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 106 | int loop; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 107 | |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 108 | loop = 0; |
| 109 | device_retry: |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 110 | host_retries = 0; |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 111 | if (loop++ >= timeout) |
| 112 | return -DBGP_ERR_BAD; |
| 113 | |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 114 | host_retry: |
| 115 | if (host_retries++ >= DBGP_MICROFRAME_RETRIES) |
| 116 | return -DBGP_ERR_BAD; |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 117 | if (loop == 1 || host_retries > 1) |
| 118 | dprintk(BIOS_SPEW, "dbgp: start (@ %3d,%d) ctrl=%08x\n", |
| 119 | loop, host_retries, ctrl | DBGP_GO); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 120 | write32(&ehci_debug->control, ctrl | DBGP_GO); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 121 | ret = dbgp_wait_until_complete(ehci_debug); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 122 | rd_ctrl = read32(&ehci_debug->control); |
| 123 | rd_pids = read32(&ehci_debug->pids); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 124 | |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 125 | if (rd_ctrl != ctrl_prev || rd_pids != pids_prev || (ret<0)) { |
| 126 | ctrl_prev = rd_ctrl; |
| 127 | pids_prev = rd_pids; |
| 128 | dprintk(BIOS_SPEW, "dbgp: status (@ %3d,%d) ctrl=%08x pids=%08x ret=%d\n", |
| 129 | loop, host_retries, rd_ctrl, rd_pids, ret); |
| 130 | } |
| 131 | |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 132 | /* Controller hardware failure. */ |
| 133 | if (ret == -DBGP_ERR_SIGNAL) { |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 134 | return ret; |
Kyösti Mälkki | 2de841b3 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 135 | |
| 136 | /* Bus failure (corrupted microframe). */ |
| 137 | } else if (ret == -DBGP_ERR_BAD) { |
| 138 | goto host_retry; |
Sven Schnelle | 1068087 | 2012-07-25 14:19:45 +0200 | [diff] [blame] | 139 | } |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 140 | |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 141 | lpid = DBGP_PID_GET(rd_pids); |
| 142 | |
| 143 | /* If I get an ACK or in-sync DATA PID, we are done. */ |
| 144 | if ((lpid == USB_PID_ACK) || (lpid == pipe->pid)) { |
Kyösti Mälkki | 48e899d | 2014-01-21 10:44:08 +0200 | [diff] [blame] | 145 | pipe->pid ^= USB_PID_DATA_TOGGLE; |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 146 | } |
| 147 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 148 | /* If the port is getting full or it has dropped data |
| 149 | * start pacing ourselves, not necessary but it's friendly. |
| 150 | */ |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 151 | else if (lpid == USB_PID_NYET) { |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 152 | dbgp_breath(); |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 153 | goto device_retry; |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | /* If I get a NACK or out-of-sync DATA PID, reissue the transmission. */ |
| 157 | else if ((lpid == USB_PID_NAK) || (lpid == (pipe->pid ^ USB_PID_DATA_TOGGLE))) { |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 158 | goto device_retry; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 159 | } |
| 160 | |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 161 | /* Abort on STALL handshake for endpoint 0.*/ |
| 162 | else if ((lpid == USB_PID_STALL) && (pipe->endpoint == 0x0)) { |
| 163 | ret = -DBGP_ERR_BAD; |
| 164 | } |
| 165 | |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 166 | dbgp_print_data(ehci_debug); |
| 167 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 168 | return ret; |
| 169 | } |
| 170 | |
| 171 | static void dbgp_set_data(struct ehci_dbg_port *ehci_debug, const void *buf, int size) |
| 172 | { |
| 173 | const unsigned char *bytes = buf; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 174 | u32 lo, hi; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 175 | int i; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 176 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 177 | lo = hi = 0; |
| 178 | for (i = 0; i < 4 && i < size; i++) |
| 179 | lo |= bytes[i] << (8*i); |
| 180 | for (; i < 8 && i < size; i++) |
| 181 | hi |= bytes[i] << (8*(i - 4)); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 182 | write32(&ehci_debug->data03, lo); |
| 183 | write32(&ehci_debug->data47, hi); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | static void dbgp_get_data(struct ehci_dbg_port *ehci_debug, void *buf, int size) |
| 187 | { |
| 188 | unsigned char *bytes = buf; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 189 | u32 lo, hi; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 190 | int i; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 191 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 192 | lo = read32(&ehci_debug->data03); |
| 193 | hi = read32(&ehci_debug->data47); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 194 | for (i = 0; i < 4 && i < size; i++) |
| 195 | bytes[i] = (lo >> (8*i)) & 0xff; |
| 196 | for (; i < 8 && i < size; i++) |
| 197 | bytes[i] = (hi >> (8*(i - 4))) & 0xff; |
| 198 | } |
| 199 | |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 200 | #if CONFIG_DEBUG_USBDEBUG |
| 201 | static void dbgp_print_data(struct ehci_dbg_port *ehci_debug) |
| 202 | { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 203 | u32 ctrl = read32(&ehci_debug->control); |
| 204 | u32 lo = read32(&ehci_debug->data03); |
| 205 | u32 hi = read32(&ehci_debug->data47); |
Kyösti Mälkki | e53cece | 2013-08-10 10:50:43 +0300 | [diff] [blame] | 206 | int len = DBGP_LEN(ctrl); |
| 207 | if (len) { |
| 208 | int i; |
| 209 | dprintk(BIOS_SPEW, "dbgp: buf:"); |
| 210 | for (i = 0; i < 4 && i < len; i++) |
| 211 | dprintk(BIOS_SPEW, " %02x", (lo >> (8*i)) & 0xff); |
| 212 | for (; i < 8 && i < len; i++) |
| 213 | dprintk(BIOS_SPEW, " %02x", (hi >> (8*(i - 4))) & 0xff); |
| 214 | dprintk(BIOS_SPEW, "\n"); |
| 215 | } |
| 216 | } |
| 217 | #endif |
| 218 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 219 | static int dbgp_bulk_write(struct ehci_dbg_port *ehci_debug, struct dbgp_pipe *pipe, |
| 220 | const char *bytes, int size) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 221 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 222 | u32 pids, addr, ctrl; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 223 | int ret; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 224 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 225 | if (size > DBGP_MAX_PACKET) |
| 226 | return -1; |
| 227 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 228 | addr = DBGP_EPADDR(pipe->devnum, pipe->endpoint); |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 229 | pids = DBGP_PID_SET(pipe->pid, USB_PID_OUT); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 230 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 231 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 232 | ctrl = DBGP_LEN_UPDATE(ctrl, size); |
| 233 | ctrl |= DBGP_OUT; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 234 | |
| 235 | dbgp_set_data(ehci_debug, bytes, size); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 236 | write32(&ehci_debug->address, addr); |
| 237 | write32(&ehci_debug->pids, pids); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 238 | |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 239 | ret = dbgp_wait_until_done(ehci_debug, pipe, ctrl, pipe->timeout); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 240 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 241 | return ret; |
| 242 | } |
| 243 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 244 | int dbgp_bulk_write_x(struct dbgp_pipe *pipe, const char *bytes, int size) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 245 | { |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 246 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 247 | return dbgp_bulk_write(dbg_info->ehci_debug, pipe, bytes, size); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 250 | static int dbgp_bulk_read(struct ehci_dbg_port *ehci_debug, struct dbgp_pipe *pipe, |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 251 | void *data, int size) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 252 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 253 | u32 pids, addr, ctrl; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 254 | int ret; |
| 255 | |
| 256 | if (size > DBGP_MAX_PACKET) |
| 257 | return -1; |
| 258 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 259 | addr = DBGP_EPADDR(pipe->devnum, pipe->endpoint); |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 260 | pids = DBGP_PID_SET(pipe->pid, USB_PID_IN); |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 261 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 262 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 263 | ctrl = DBGP_LEN_UPDATE(ctrl, size); |
| 264 | ctrl &= ~DBGP_OUT; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 265 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 266 | write32(&ehci_debug->address, addr); |
| 267 | write32(&ehci_debug->pids, pids); |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 268 | ret = dbgp_wait_until_done(ehci_debug, pipe, ctrl, pipe->timeout); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 269 | if (ret < 0) |
| 270 | return ret; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 271 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 272 | if (size > ret) |
| 273 | size = ret; |
| 274 | dbgp_get_data(ehci_debug, data, size); |
| 275 | return ret; |
| 276 | } |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 277 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 278 | int dbgp_bulk_read_x(struct dbgp_pipe *pipe, void *data, int size) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 279 | { |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 280 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 281 | return dbgp_bulk_read(dbg_info->ehci_debug, pipe, data, size); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 282 | } |
| 283 | |
Kyösti Mälkki | 83fe6d7 | 2014-02-25 20:11:52 +0200 | [diff] [blame] | 284 | void dbgp_mdelay(int ms) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 285 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 286 | int i; |
| 287 | |
| 288 | while (ms--) { |
| 289 | for (i = 0; i < 1000; i++) |
| 290 | inb(0x80); |
| 291 | } |
| 292 | } |
| 293 | |
Kyösti Mälkki | 83fe6d7 | 2014-02-25 20:11:52 +0200 | [diff] [blame] | 294 | int dbgp_control_msg(struct ehci_dbg_port *ehci_debug, unsigned devnum, int requesttype, |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 295 | int request, int value, int index, void *data, int size) |
| 296 | { |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 297 | struct ehci_debug_info *info = dbgp_ehci_info(); |
| 298 | struct dbgp_pipe *pipe = &info->ep_pipe[DBGP_SETUP_EP0]; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 299 | u32 pids, addr, ctrl; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 300 | struct usb_ctrlrequest req; |
| 301 | int read; |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 302 | int ret, ret2; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 303 | |
| 304 | read = (requesttype & USB_DIR_IN) != 0; |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 305 | if (size > DBGP_MAX_PACKET) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 306 | return -1; |
Stefan Reinauer | 14e2277 | 2010-04-27 06:56:47 +0000 | [diff] [blame] | 307 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 308 | /* Compute the control message */ |
| 309 | req.bRequestType = requesttype; |
| 310 | req.bRequest = request; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 311 | req.wValue = cpu_to_le16(value); |
| 312 | req.wIndex = cpu_to_le16(index); |
| 313 | req.wLength = cpu_to_le16(size); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 314 | |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 315 | pipe->devnum = devnum; |
| 316 | pipe->endpoint = 0; |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 317 | pipe->pid = USB_PID_DATA0; |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 318 | pipe->timeout = 1000; |
Kyösti Mälkki | 75d0062 | 2013-08-10 10:34:01 +0300 | [diff] [blame] | 319 | addr = DBGP_EPADDR(pipe->devnum, pipe->endpoint); |
Kyösti Mälkki | e29584c | 2013-08-10 10:50:38 +0300 | [diff] [blame] | 320 | pids = DBGP_PID_SET(pipe->pid, USB_PID_SETUP); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 321 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 322 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 323 | ctrl = DBGP_LEN_UPDATE(ctrl, sizeof(req)); |
| 324 | ctrl |= DBGP_OUT; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 325 | |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 326 | /* Setup stage */ |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 327 | dbgp_set_data(ehci_debug, &req, sizeof(req)); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 328 | write32(&ehci_debug->address, addr); |
| 329 | write32(&ehci_debug->pids, pids); |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 330 | ret = dbgp_wait_until_done(ehci_debug, pipe, ctrl, 1); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 331 | if (ret < 0) |
| 332 | return ret; |
| 333 | |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 334 | /* Data stage (optional) */ |
| 335 | if (read && size) |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 336 | ret = dbgp_bulk_read(ehci_debug, pipe, data, size); |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 337 | else if (!read && size) |
| 338 | ret = dbgp_bulk_write(ehci_debug, pipe, data, size); |
| 339 | |
| 340 | /* Status stage in opposite direction */ |
| 341 | pipe->pid = USB_PID_DATA1; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 342 | ctrl = read32(&ehci_debug->control); |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 343 | ctrl = DBGP_LEN_UPDATE(ctrl, 0); |
| 344 | if (read) { |
| 345 | pids = DBGP_PID_SET(pipe->pid, USB_PID_OUT); |
| 346 | ctrl |= DBGP_OUT; |
| 347 | } else { |
| 348 | pids = DBGP_PID_SET(pipe->pid, USB_PID_IN); |
| 349 | ctrl &= ~DBGP_OUT; |
| 350 | } |
| 351 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 352 | write32(&ehci_debug->pids, pids); |
Kyösti Mälkki | 5c87d2f1 | 2013-08-19 12:45:16 +0300 | [diff] [blame] | 353 | ret2 = dbgp_wait_until_done(ehci_debug, pipe, ctrl, pipe->timeout); |
Kyösti Mälkki | dcccbd1 | 2013-08-10 10:08:38 +0300 | [diff] [blame] | 354 | if (ret2 < 0) |
| 355 | return ret2; |
| 356 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 357 | return ret; |
| 358 | } |
| 359 | |
| 360 | static int ehci_reset_port(struct ehci_regs *ehci_regs, int port) |
| 361 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 362 | u32 portsc; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 363 | int loop; |
| 364 | |
| 365 | /* Reset the usb debug port */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 366 | portsc = read32(&ehci_regs->port_status[port - 1]); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 367 | portsc &= ~PORT_PE; |
| 368 | portsc |= PORT_RESET; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 369 | write32(&ehci_regs->port_status[port - 1], portsc); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 370 | |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 371 | dbgp_mdelay(HUB_ROOT_RESET_TIME); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 372 | |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 373 | portsc = read32(&ehci_regs->port_status[port - 1]); |
| 374 | write32(&ehci_regs->port_status[port - 1], |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 375 | portsc & ~(PORT_RWC_BITS | PORT_RESET)); |
| 376 | |
| 377 | loop = 100; |
| 378 | do { |
| 379 | dbgp_mdelay(1); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 380 | portsc = read32(&ehci_regs->port_status[port - 1]); |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 381 | } while ((portsc & PORT_RESET) && (--loop > 0)); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 382 | |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 383 | /* Device went away? */ |
| 384 | if (!(portsc & PORT_CONNECT)) |
| 385 | return -1; //-ENOTCONN; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 386 | |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 387 | /* bomb out completely if something weird happened */ |
| 388 | if ((portsc & PORT_CSC)) |
| 389 | return -2; //-EINVAL; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 390 | |
Kyösti Mälkki | b8ef4c9 | 2013-08-12 21:35:20 +0300 | [diff] [blame] | 391 | /* If we've finished resetting, then break out of the loop */ |
| 392 | if (!(portsc & PORT_RESET) && (portsc & PORT_PE)) |
| 393 | return 0; |
| 394 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 395 | return -3; //-EBUSY; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 396 | } |
| 397 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 398 | static int ehci_wait_for_port(struct ehci_regs *ehci_regs, int port) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 399 | { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 400 | u32 status; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 401 | int ret, reps; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 402 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 403 | for (reps = 0; reps < 3; reps++) { |
| 404 | dbgp_mdelay(100); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 405 | status = read32(&ehci_regs->status); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 406 | if (status & STS_PCD) { |
| 407 | ret = ehci_reset_port(ehci_regs, port); |
| 408 | if (ret == 0) |
| 409 | return 0; |
| 410 | } |
| 411 | } |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 412 | return -1; //-ENOTCONN; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 413 | } |
| 414 | |
Kyösti Mälkki | d2dac0a | 2013-08-23 23:33:16 +0300 | [diff] [blame] | 415 | |
Kyösti Mälkki | 8101aa6 | 2013-08-15 16:27:06 +0300 | [diff] [blame] | 416 | |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 417 | static int usbdebug_init_(unsigned ehci_bar, unsigned offset, struct ehci_debug_info *info) |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 418 | { |
| 419 | struct ehci_caps *ehci_caps; |
| 420 | struct ehci_regs *ehci_regs; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 421 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 422 | u32 cmd, ctrl, status, portsc, hcs_params; |
| 423 | u32 debug_port, new_debug_port = 0, n_ports; |
Kyösti Mälkki | 46249be2 | 2014-10-27 14:07:28 +0200 | [diff] [blame] | 424 | int ret, i; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 425 | int loop; |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 426 | int port_map_tried; |
| 427 | int playtimes = 3; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 428 | |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 429 | /* Keep all endpoints disabled before any printk() call. */ |
| 430 | memset(info, 0, sizeof (*info)); |
| 431 | info->ehci_base = (void *)ehci_bar; |
| 432 | info->ehci_debug = (void *)(ehci_bar + offset); |
| 433 | |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 434 | dprintk(BIOS_INFO, "ehci_bar: 0x%x debug_offset 0x%x\n", ehci_bar, offset); |
| 435 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 436 | ehci_caps = (struct ehci_caps *)ehci_bar; |
Stefan Reinauer | 5ff7c13 | 2011-10-31 12:56:45 -0700 | [diff] [blame] | 437 | ehci_regs = (struct ehci_regs *)(ehci_bar + |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 438 | HC_LENGTH(read32(&ehci_caps->hc_capbase))); |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 439 | |
| 440 | struct ehci_dbg_port *ehci_debug = info->ehci_debug; |
Kyösti Mälkki | 2410010 | 2013-08-12 20:40:37 +0300 | [diff] [blame] | 441 | |
| 442 | if (CONFIG_USBDEBUG_DEFAULT_PORT > 0) |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 443 | ehci_debug_select_port(CONFIG_USBDEBUG_DEFAULT_PORT); |
Kyösti Mälkki | 2410010 | 2013-08-12 20:40:37 +0300 | [diff] [blame] | 444 | else |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 445 | ehci_debug_select_port(1); |
Kyösti Mälkki | 2410010 | 2013-08-12 20:40:37 +0300 | [diff] [blame] | 446 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 447 | try_next_time: |
| 448 | port_map_tried = 0; |
| 449 | |
| 450 | try_next_port: |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 451 | hcs_params = read32(&ehci_caps->hcs_params); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 452 | debug_port = HCS_DEBUG_PORT(hcs_params); |
| 453 | n_ports = HCS_N_PORTS(hcs_params); |
| 454 | |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 455 | dprintk(BIOS_INFO, "debug_port: %d\n", debug_port); |
| 456 | dprintk(BIOS_INFO, "n_ports: %d\n", n_ports); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 457 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 458 | for (i = 1; i <= n_ports; i++) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 459 | portsc = read32(&ehci_regs->port_status[i-1]); |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 460 | dprintk(BIOS_INFO, "PORTSC #%d: %08x\n", i, portsc); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 461 | } |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 462 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 463 | if(port_map_tried && (new_debug_port != debug_port)) { |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 464 | if(--playtimes) { |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 465 | ehci_debug_select_port(debug_port); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 466 | goto try_next_time; |
| 467 | } |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 468 | return -1; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 469 | } |
| 470 | |
Kyösti Mälkki | 16c0145 | 2013-08-12 15:32:25 +0300 | [diff] [blame] | 471 | /* Wait until the controller is halted */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 472 | status = read32(&ehci_regs->status); |
Kyösti Mälkki | 16c0145 | 2013-08-12 15:32:25 +0300 | [diff] [blame] | 473 | if (!(status & STS_HALT)) { |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 474 | cmd = read32(&ehci_regs->command); |
Kyösti Mälkki | 16c0145 | 2013-08-12 15:32:25 +0300 | [diff] [blame] | 475 | cmd &= ~CMD_RUN; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 476 | write32(&ehci_regs->command, cmd); |
Kyösti Mälkki | 16c0145 | 2013-08-12 15:32:25 +0300 | [diff] [blame] | 477 | loop = 100; |
| 478 | do { |
| 479 | dbgp_mdelay(10); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 480 | status = read32(&ehci_regs->status); |
Kyösti Mälkki | 16c0145 | 2013-08-12 15:32:25 +0300 | [diff] [blame] | 481 | } while (!(status & STS_HALT) && (--loop > 0)); |
| 482 | if (status & STS_HALT) |
| 483 | dprintk(BIOS_INFO, "EHCI controller halted successfully.\n"); |
| 484 | else |
| 485 | dprintk(BIOS_INFO, "EHCI controller is not halted. Reset may fail.\n"); |
| 486 | } |
| 487 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 488 | loop = 100; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 489 | /* Reset the EHCI controller */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 490 | cmd = read32(&ehci_regs->command); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 491 | cmd |= CMD_RESET; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 492 | write32(&ehci_regs->command, cmd); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 493 | do { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 494 | dbgp_mdelay(10); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 495 | cmd = read32(&ehci_regs->command); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 496 | } while ((cmd & CMD_RESET) && (--loop > 0)); |
| 497 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 498 | if(!loop) { |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 499 | dprintk(BIOS_INFO, "Could not reset EHCI controller.\n"); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 500 | // on some systems it works without succeeding here. |
| 501 | // return -2; |
| 502 | } else { |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 503 | dprintk(BIOS_INFO, "EHCI controller reset successfully.\n"); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 504 | } |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 505 | |
| 506 | /* Claim ownership, but do not enable yet */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 507 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 508 | ctrl |= DBGP_OWNER; |
| 509 | ctrl &= ~(DBGP_ENABLED | DBGP_INUSE); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 510 | write32(&ehci_debug->control, ctrl); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 511 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 512 | /* Start EHCI controller */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 513 | cmd = read32(&ehci_regs->command); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 514 | cmd &= ~(CMD_LRESET | CMD_IAAD | CMD_PSE | CMD_ASE | CMD_RESET); |
| 515 | cmd |= CMD_RUN; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 516 | write32(&ehci_regs->command, cmd); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 517 | |
| 518 | /* Ensure everything is routed to the EHCI */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 519 | write32(&ehci_regs->configured_flag, FLAG_CF); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 520 | |
| 521 | /* Wait until the controller is no longer halted */ |
| 522 | loop = 10; |
| 523 | do { |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 524 | dbgp_mdelay(10); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 525 | status = read32(&ehci_regs->status); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 526 | } while ((status & STS_HALT) && (--loop > 0)); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 527 | |
| 528 | if(!loop) { |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 529 | dprintk(BIOS_INFO, "EHCI could not be started.\n"); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 530 | return -3; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 531 | } |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 532 | dprintk(BIOS_INFO, "EHCI started.\n"); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 533 | |
| 534 | /* Wait for a device to show up in the debug port */ |
| 535 | ret = ehci_wait_for_port(ehci_regs, debug_port); |
| 536 | if (ret < 0) { |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 537 | dprintk(BIOS_INFO, "No device found in debug port %d\n", debug_port); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 538 | goto next_debug_port; |
| 539 | } |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 540 | dprintk(BIOS_INFO, "EHCI done waiting for port.\n"); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 541 | |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 542 | |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 543 | /* Enable the debug port */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 544 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 545 | ctrl |= DBGP_CLAIM; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 546 | write32(&ehci_debug->control, ctrl); |
| 547 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 548 | if ((ctrl & DBGP_CLAIM) != DBGP_CLAIM) { |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 549 | dprintk(BIOS_INFO, "No device in EHCI debug port.\n"); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 550 | write32(&ehci_debug->control, ctrl & ~DBGP_CLAIM); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 551 | ret = -4; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 552 | goto err; |
| 553 | } |
Kyösti Mälkki | 8ff3d68 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 554 | dprintk(BIOS_INFO, "EHCI debug port enabled.\n"); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 555 | |
Kyösti Mälkki | 9e999d6 | 2013-06-06 10:33:39 +0300 | [diff] [blame] | 556 | #if 0 |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 557 | /* Completely transfer the debug device to the debug controller */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 558 | portsc = read32(&ehci_regs->port_status[debug_port - 1]); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 559 | portsc &= ~PORT_PE; |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 560 | write32(&ehci_regs->port_status[debug_port - 1], portsc); |
Kyösti Mälkki | 9e999d6 | 2013-06-06 10:33:39 +0300 | [diff] [blame] | 561 | #endif |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 562 | |
| 563 | dbgp_mdelay(100); |
| 564 | |
Kyösti Mälkki | 83fe6d7 | 2014-02-25 20:11:52 +0200 | [diff] [blame] | 565 | ret = dbgp_probe_gadget(info->ehci_debug, &info->ep_pipe[0]); |
Kyösti Mälkki | d2dac0a | 2013-08-23 23:33:16 +0300 | [diff] [blame] | 566 | if (ret < 0) { |
Kyösti Mälkki | 83fe6d7 | 2014-02-25 20:11:52 +0200 | [diff] [blame] | 567 | dprintk(BIOS_INFO, "Could not probe gadget on debug port.\n"); |
Kyösti Mälkki | d2dac0a | 2013-08-23 23:33:16 +0300 | [diff] [blame] | 568 | ret = -6; |
| 569 | goto err; |
| 570 | } |
Kyösti Mälkki | d2dac0a | 2013-08-23 23:33:16 +0300 | [diff] [blame] | 571 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 572 | return 0; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 573 | err: |
| 574 | /* Things didn't work so remove my claim */ |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 575 | ctrl = read32(&ehci_debug->control); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 576 | ctrl &= ~(DBGP_CLAIM | DBGP_OUT); |
Kevin Paul Herbert | bde6d30 | 2014-12-24 18:43:20 -0800 | [diff] [blame] | 577 | write32(&ehci_debug->control, ctrl); |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 578 | //return ret; |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 579 | |
| 580 | next_debug_port: |
Kyösti Mälkki | 2410010 | 2013-08-12 20:40:37 +0300 | [diff] [blame] | 581 | #if CONFIG_USBDEBUG_DEFAULT_PORT==0 |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 582 | port_map_tried |= (1 << (debug_port - 1)); |
| 583 | new_debug_port = ((debug_port-1 + 1) % n_ports) + 1; |
| 584 | if (port_map_tried != ((1 << n_ports) - 1)) { |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 585 | ehci_debug_select_port(new_debug_port); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 586 | goto try_next_port; |
| 587 | } |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 588 | if (--playtimes) { |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 589 | ehci_debug_select_port(new_debug_port); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 590 | goto try_next_time; |
| 591 | } |
Kyösti Mälkki | 2410010 | 2013-08-12 20:40:37 +0300 | [diff] [blame] | 592 | #else |
| 593 | if (0) |
| 594 | goto try_next_port; |
| 595 | if (--playtimes) |
| 596 | goto try_next_time; |
| 597 | #endif |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 598 | |
Stefan Reinauer | 16ce01b | 2011-01-28 08:05:54 +0000 | [diff] [blame] | 599 | return -10; |
| 600 | } |
| 601 | |
Kyösti Mälkki | d799140 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 602 | #if CONFIG_DEBUG_USBDEBUG |
| 603 | static int dbgp_enabled(void) |
| 604 | { |
| 605 | struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; |
| 606 | return (globals->status & DBGP_EP_ENABLED); |
| 607 | } |
| 608 | #endif |
| 609 | |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 610 | int dbgp_try_get(struct dbgp_pipe *pipe) |
Kyösti Mälkki | d799140 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 611 | { |
| 612 | struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; |
| 613 | if (!dbgp_ep_is_active(pipe) || (globals->status & DBGP_EP_BUSY)) |
| 614 | return 0; |
| 615 | globals->status |= DBGP_EP_BUSY; |
| 616 | pipe->status |= DBGP_EP_BUSY; |
| 617 | return 1; |
| 618 | } |
| 619 | |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 620 | void dbgp_put(struct dbgp_pipe *pipe) |
Kyösti Mälkki | d799140 | 2013-08-12 16:11:34 +0300 | [diff] [blame] | 621 | { |
| 622 | struct dbgp_pipe *globals = &dbgp_ehci_info()->ep_pipe[DBGP_SETUP_EP0]; |
| 623 | globals->status &= ~DBGP_EP_BUSY; |
| 624 | pipe->status &= ~DBGP_EP_BUSY; |
| 625 | } |
| 626 | |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 627 | #if !defined(__PRE_RAM__) && !defined(__SMM__) |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 628 | void usbdebug_re_enable(unsigned ehci_base) |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 629 | { |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 630 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 631 | unsigned diff; |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 632 | int i; |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 633 | |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 634 | diff = (unsigned)dbg_info->ehci_base - ehci_base; |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 635 | dbg_info->ehci_debug -= diff; |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 636 | dbg_info->ehci_base = (void*)ehci_base; |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 637 | |
| 638 | for (i=0; i<DBGP_MAX_ENDPOINTS; i++) |
Kyösti Mälkki | 7bb4f86 | 2014-10-27 15:07:20 +0200 | [diff] [blame] | 639 | if (dbg_info->ep_pipe[i].status & DBGP_EP_VALID) |
| 640 | dbg_info->ep_pipe[i].status |= DBGP_EP_ENABLED; |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 641 | } |
| 642 | |
Kyösti Mälkki | cb141bc | 2014-02-07 19:24:23 +0200 | [diff] [blame] | 643 | void usbdebug_disable(void) |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 644 | { |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 645 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 646 | int i; |
| 647 | for (i=0; i<DBGP_MAX_ENDPOINTS; i++) |
| 648 | dbg_info->ep_pipe[i].status &= ~DBGP_EP_ENABLED; |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 649 | } |
| 650 | |
Kyösti Mälkki | 41c10cd | 2013-07-09 04:19:22 +0300 | [diff] [blame] | 651 | #endif |
| 652 | |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 653 | #if !defined(__PRE_RAM__) && !defined(__SMM__) |
| 654 | static int get_usbdebug_from_cbmem(struct ehci_debug_info *info) |
| 655 | { |
| 656 | struct ehci_debug_info *dbg_info_cbmem; |
| 657 | |
| 658 | dbg_info_cbmem = cbmem_find(CBMEM_ID_EHCI_DEBUG); |
| 659 | if (dbg_info_cbmem == NULL) |
| 660 | return -1; |
| 661 | |
| 662 | memcpy(info, dbg_info_cbmem, sizeof (*info)); |
| 663 | printk(BIOS_DEBUG, "EHCI debug port found in CBMEM.\n"); |
| 664 | |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | #elif defined(__PRE_RAM__) |
Aaron Durbin | 41607a4 | 2015-06-09 13:54:10 -0500 | [diff] [blame] | 669 | static void migrate_ehci_debug(int is_recovery) |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 670 | { |
| 671 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
| 672 | struct ehci_debug_info *dbg_info_cbmem; |
| 673 | |
| 674 | dbg_info_cbmem = cbmem_add(CBMEM_ID_EHCI_DEBUG, sizeof(*dbg_info)); |
| 675 | if (dbg_info_cbmem == NULL) |
| 676 | return; |
| 677 | |
| 678 | memcpy(dbg_info_cbmem, dbg_info, sizeof(*dbg_info)); |
Kyösti Mälkki | 618d179 | 2014-10-27 08:01:55 +0200 | [diff] [blame] | 679 | car_set_var(glob_dbg_info_p, dbg_info_cbmem); |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 680 | } |
Kyösti Mälkki | 4fbac46 | 2015-01-07 04:48:43 +0200 | [diff] [blame] | 681 | ROMSTAGE_CBMEM_INIT_HOOK(migrate_ehci_debug); |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 682 | #endif |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 683 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 684 | int dbgp_ep_is_active(struct dbgp_pipe *pipe) |
Kyösti Mälkki | 4d409b5 | 2013-07-05 21:38:54 +0300 | [diff] [blame] | 685 | { |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 686 | return (pipe->status & DBGP_EP_STATMASK) == (DBGP_EP_VALID | DBGP_EP_ENABLED); |
Yinghai Lu | d57241f | 2007-02-28 11:17:02 +0000 | [diff] [blame] | 687 | } |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 688 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 689 | struct dbgp_pipe *dbgp_console_output(void) |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 690 | { |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 691 | return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPOUT]; |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 692 | } |
| 693 | |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 694 | struct dbgp_pipe *dbgp_console_input(void) |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 695 | { |
Kyösti Mälkki | 026ff3e | 2013-07-08 18:11:44 +0300 | [diff] [blame] | 696 | return &dbgp_ehci_info()->ep_pipe[DBGP_CONSOLE_EPIN]; |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | int usbdebug_init(void) |
| 700 | { |
Kyösti Mälkki | cbe2ede | 2013-07-11 07:49:46 +0300 | [diff] [blame] | 701 | struct ehci_debug_info *dbg_info = dbgp_ehci_info(); |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 702 | unsigned int ehci_base, dbg_offset; |
Kyösti Mälkki | 8ee04d7 | 2013-07-06 11:41:09 +0300 | [diff] [blame] | 703 | |
Kyösti Mälkki | cbf5bdf | 2013-09-10 00:07:21 +0300 | [diff] [blame] | 704 | #if !defined(__PRE_RAM__) && !defined(__SMM__) |
Kyösti Mälkki | 690bf2f | 2013-07-06 11:41:21 +0300 | [diff] [blame] | 705 | if (!get_usbdebug_from_cbmem(dbg_info)) |
| 706 | return 0; |
| 707 | #endif |
Kyösti Mälkki | 6f6a249 | 2014-02-09 19:21:30 +0200 | [diff] [blame] | 708 | if (ehci_debug_hw_enable(&ehci_base, &dbg_offset)) |
| 709 | return -1; |
| 710 | return usbdebug_init_(ehci_base, dbg_offset, dbg_info); |
Kyösti Mälkki | 9e7806a | 2013-07-06 11:56:49 +0300 | [diff] [blame] | 711 | } |