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