diff options
Diffstat (limited to 'drivers/usb/early/ehci-dbgp.c')
-rw-r--r-- | drivers/usb/early/ehci-dbgp.c | 68 |
1 files changed, 28 insertions, 40 deletions
diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c index 2958a1271b20..6e98a3697844 100644 --- a/drivers/usb/early/ehci-dbgp.c +++ b/drivers/usb/early/ehci-dbgp.c | |||
@@ -66,8 +66,6 @@ static struct ehci_dev ehci_dev; | |||
66 | 66 | ||
67 | #define USB_DEBUG_DEVNUM 127 | 67 | #define USB_DEBUG_DEVNUM 127 |
68 | 68 | ||
69 | #define DBGP_DATA_TOGGLE 0x8800 | ||
70 | |||
71 | #ifdef DBGP_DEBUG | 69 | #ifdef DBGP_DEBUG |
72 | #define dbgp_printk printk | 70 | #define dbgp_printk printk |
73 | static void dbgp_ehci_status(char *str) | 71 | static void dbgp_ehci_status(char *str) |
@@ -88,11 +86,6 @@ static inline void dbgp_ehci_status(char *str) { } | |||
88 | static inline void dbgp_printk(const char *fmt, ...) { } | 86 | static inline void dbgp_printk(const char *fmt, ...) { } |
89 | #endif | 87 | #endif |
90 | 88 | ||
91 | static inline u32 dbgp_pid_update(u32 x, u32 tok) | ||
92 | { | ||
93 | return ((x ^ DBGP_DATA_TOGGLE) & 0xffff00) | (tok & 0xff); | ||
94 | } | ||
95 | |||
96 | static inline u32 dbgp_len_update(u32 x, u32 len) | 89 | static inline u32 dbgp_len_update(u32 x, u32 len) |
97 | { | 90 | { |
98 | return (x & ~0x0f) | (len & 0x0f); | 91 | return (x & ~0x0f) | (len & 0x0f); |
@@ -136,6 +129,19 @@ static inline u32 dbgp_len_update(u32 x, u32 len) | |||
136 | 129 | ||
137 | #define DBGP_MAX_PACKET 8 | 130 | #define DBGP_MAX_PACKET 8 |
138 | #define DBGP_TIMEOUT (250 * 1000) | 131 | #define DBGP_TIMEOUT (250 * 1000) |
132 | #define DBGP_LOOPS 1000 | ||
133 | |||
134 | static inline u32 dbgp_pid_write_update(u32 x, u32 tok) | ||
135 | { | ||
136 | static int data0 = USB_PID_DATA1; | ||
137 | data0 ^= USB_PID_DATA_TOGGLE; | ||
138 | return (x & 0xffff0000) | (data0 << 8) | (tok & 0xff); | ||
139 | } | ||
140 | |||
141 | static inline u32 dbgp_pid_read_update(u32 x, u32 tok) | ||
142 | { | ||
143 | return (x & 0xffff0000) | (USB_PID_DATA0 << 8) | (tok & 0xff); | ||
144 | } | ||
139 | 145 | ||
140 | static int dbgp_wait_until_complete(void) | 146 | static int dbgp_wait_until_complete(void) |
141 | { | 147 | { |
@@ -180,7 +186,7 @@ static int dbgp_wait_until_done(unsigned ctrl) | |||
180 | { | 186 | { |
181 | u32 pids, lpid; | 187 | u32 pids, lpid; |
182 | int ret; | 188 | int ret; |
183 | int loop = 3; | 189 | int loop = DBGP_LOOPS; |
184 | 190 | ||
185 | retry: | 191 | retry: |
186 | writel(ctrl | DBGP_GO, &ehci_debug->control); | 192 | writel(ctrl | DBGP_GO, &ehci_debug->control); |
@@ -197,6 +203,8 @@ retry: | |||
197 | */ | 203 | */ |
198 | if (ret == -DBGP_TIMEOUT && !dbgp_not_safe) | 204 | if (ret == -DBGP_TIMEOUT && !dbgp_not_safe) |
199 | dbgp_not_safe = 1; | 205 | dbgp_not_safe = 1; |
206 | if (ret == -DBGP_ERR_BAD && --loop > 0) | ||
207 | goto retry; | ||
200 | return ret; | 208 | return ret; |
201 | } | 209 | } |
202 | 210 | ||
@@ -245,12 +253,20 @@ static inline void dbgp_get_data(void *buf, int size) | |||
245 | bytes[i] = (hi >> (8*(i - 4))) & 0xff; | 253 | bytes[i] = (hi >> (8*(i - 4))) & 0xff; |
246 | } | 254 | } |
247 | 255 | ||
248 | static int dbgp_out(u32 addr, const char *bytes, int size) | 256 | static int dbgp_bulk_write(unsigned devnum, unsigned endpoint, |
257 | const char *bytes, int size) | ||
249 | { | 258 | { |
259 | int ret; | ||
260 | u32 addr; | ||
250 | u32 pids, ctrl; | 261 | u32 pids, ctrl; |
251 | 262 | ||
263 | if (size > DBGP_MAX_PACKET) | ||
264 | return -1; | ||
265 | |||
266 | addr = DBGP_EPADDR(devnum, endpoint); | ||
267 | |||
252 | pids = readl(&ehci_debug->pids); | 268 | pids = readl(&ehci_debug->pids); |
253 | pids = dbgp_pid_update(pids, USB_PID_OUT); | 269 | pids = dbgp_pid_write_update(pids, USB_PID_OUT); |
254 | 270 | ||
255 | ctrl = readl(&ehci_debug->control); | 271 | ctrl = readl(&ehci_debug->control); |
256 | ctrl = dbgp_len_update(ctrl, size); | 272 | ctrl = dbgp_len_update(ctrl, size); |
@@ -260,34 +276,7 @@ static int dbgp_out(u32 addr, const char *bytes, int size) | |||
260 | dbgp_set_data(bytes, size); | 276 | dbgp_set_data(bytes, size); |
261 | writel(addr, &ehci_debug->address); | 277 | writel(addr, &ehci_debug->address); |
262 | writel(pids, &ehci_debug->pids); | 278 | writel(pids, &ehci_debug->pids); |
263 | return dbgp_wait_until_done(ctrl); | 279 | ret = dbgp_wait_until_done(ctrl); |
264 | } | ||
265 | |||
266 | static int dbgp_bulk_write(unsigned devnum, unsigned endpoint, | ||
267 | const char *bytes, int size) | ||
268 | { | ||
269 | int ret; | ||
270 | int loops = 5; | ||
271 | u32 addr; | ||
272 | if (size > DBGP_MAX_PACKET) | ||
273 | return -1; | ||
274 | |||
275 | addr = DBGP_EPADDR(devnum, endpoint); | ||
276 | try_again: | ||
277 | if (loops--) { | ||
278 | ret = dbgp_out(addr, bytes, size); | ||
279 | if (ret == -DBGP_ERR_BAD) { | ||
280 | int try_loops = 3; | ||
281 | do { | ||
282 | /* Emit a dummy packet to re-sync communication | ||
283 | * with the debug device */ | ||
284 | if (dbgp_out(addr, "12345678", 8) >= 0) { | ||
285 | udelay(2); | ||
286 | goto try_again; | ||
287 | } | ||
288 | } while (try_loops--); | ||
289 | } | ||
290 | } | ||
291 | 280 | ||
292 | return ret; | 281 | return ret; |
293 | } | 282 | } |
@@ -304,7 +293,7 @@ static int dbgp_bulk_read(unsigned devnum, unsigned endpoint, void *data, | |||
304 | addr = DBGP_EPADDR(devnum, endpoint); | 293 | addr = DBGP_EPADDR(devnum, endpoint); |
305 | 294 | ||
306 | pids = readl(&ehci_debug->pids); | 295 | pids = readl(&ehci_debug->pids); |
307 | pids = dbgp_pid_update(pids, USB_PID_IN); | 296 | pids = dbgp_pid_read_update(pids, USB_PID_IN); |
308 | 297 | ||
309 | ctrl = readl(&ehci_debug->control); | 298 | ctrl = readl(&ehci_debug->control); |
310 | ctrl = dbgp_len_update(ctrl, size); | 299 | ctrl = dbgp_len_update(ctrl, size); |
@@ -362,7 +351,6 @@ static int dbgp_control_msg(unsigned devnum, int requesttype, | |||
362 | return dbgp_bulk_read(devnum, 0, data, size); | 351 | return dbgp_bulk_read(devnum, 0, data, size); |
363 | } | 352 | } |
364 | 353 | ||
365 | |||
366 | /* Find a PCI capability */ | 354 | /* Find a PCI capability */ |
367 | static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap) | 355 | static u32 __init find_cap(u32 num, u32 slot, u32 func, int cap) |
368 | { | 356 | { |