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