]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/usb/host/isp116x-hcd.c
46e4cee1d04c9dd3af28bdaa09b121f11e056719
[karo-tx-uboot.git] / drivers / usb / host / isp116x-hcd.c
1 /*
2  * ISP116x HCD (Host Controller Driver) for u-boot.
3  *
4  * Copyright (C) 2006-2007 Rodolfo Giometti <giometti@linux.it>
5  * Copyright (C) 2006-2007 Eurotech S.p.A. <info@eurotech.it>
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  *
9  * Derived in part from the SL811 HCD driver "u-boot/drivers/usb/sl811_usb.c"
10  * (original copyright message follows):
11  *
12  *    (C) Copyright 2004
13  *    Wolfgang Denk, DENX Software Engineering, wd@denx.de.
14  *
15  *    This code is based on linux driver for sl811hs chip, source at
16  *    drivers/usb/host/sl811.c:
17  *
18  *    SL811 Host Controller Interface driver for USB.
19  *
20  *    Copyright (c) 2003/06, Courage Co., Ltd.
21  *
22  *    Based on:
23  *         1.uhci.c by Linus Torvalds, Johannes Erdfelt, Randy Dunlap,
24  *           Georg Acher, Deti Fliegl, Thomas Sailer, Roman Weissgaerber,
25  *           Adam Richter, Gregory P. Smith;
26  *         2.Original SL811 driver (hc_sl811.o) by Pei Liu <pbl@cypress.com>
27  *         3.Rewrited as sl811.o by Yin Aihua <yinah:couragetech.com.cn>
28  *
29  *    [[GNU/GPL disclaimer]]
30  *
31  * and in part from AU1x00 OHCI HCD driver "u-boot/arch/mips/cpu/au1x00_usb_ohci.c"
32  * (original copyright message follows):
33  *
34  *    URB OHCI HCD (Host Controller Driver) for USB on the AU1x00.
35  *
36  *    (C) Copyright 2003
37  *    Gary Jennejohn, DENX Software Engineering <garyj@denx.de>
38  *
39  *    [[GNU/GPL disclaimer]]
40  *
41  *    Note: Part of this code has been derived from linux
42  */
43
44 #include <common.h>
45 #include <asm/io.h>
46 #include <usb.h>
47 #include <malloc.h>
48 #include <linux/list.h>
49
50 /*
51  * ISP116x chips require certain delays between accesses to its
52  * registers. The following timing options exist.
53  *
54  * 1. Configure your memory controller (the best)
55  * 2. Use ndelay (easiest, poorest). For that, enable the following macro.
56  *
57  * Value is in microseconds.
58  */
59 #ifdef ISP116X_HCD_USE_UDELAY
60 #define UDELAY          1
61 #endif
62
63 /*
64  * On some (slowly?) machines an extra delay after data packing into
65  * controller's FIFOs is required, * otherwise you may get the following
66  * error:
67  *
68  *   uboot> usb start
69  *   (Re)start USB...
70  *   USB:   scanning bus for devices... isp116x: isp116x_submit_job: CTL:TIMEOUT
71  *   isp116x: isp116x_submit_job: ****** FIFO not ready! ******
72  *
73  *         USB device not responding, giving up (status=4)
74  *         isp116x: isp116x_submit_job: ****** FIFO not empty! ******
75  *         isp116x: isp116x_submit_job: ****** FIFO not empty! ******
76  *         isp116x: isp116x_submit_job: ****** FIFO not empty! ******
77  *         3 USB Device(s) found
78  *                scanning bus for storage devices... 0 Storage Device(s) found
79  *
80  * Value is in milliseconds.
81  */
82 #ifdef ISP116X_HCD_USE_EXTRA_DELAY
83 #define EXTRA_DELAY     2
84 #endif
85
86 /*
87  * Enable the following defines if you wish enable debugging messages.
88  */
89 #undef DEBUG                    /* enable debugging messages */
90 #undef TRACE                    /* enable tracing code */
91 #undef VERBOSE                  /* verbose debugging messages */
92
93 #include "isp116x.h"
94
95 #define DRIVER_VERSION  "08 Jan 2007"
96 static const char hcd_name[] = "isp116x-hcd";
97
98 struct isp116x isp116x_dev;
99 struct isp116x_platform_data isp116x_board;
100 static int got_rhsc;            /* root hub status change */
101 struct usb_device *devgone;     /* device which was disconnected */
102 static int rh_devnum;           /* address of Root Hub endpoint */
103
104 /* ------------------------------------------------------------------------- */
105
106 #define ALIGN(x,a)      (((x)+(a)-1UL)&~((a)-1UL))
107 #define min_t(type,x,y) \
108         ({ type __x = (x); type __y = (y); __x < __y ? __x : __y; })
109
110 /* ------------------------------------------------------------------------- */
111
112 static int isp116x_reset(struct isp116x *isp116x);
113
114 /* --- Debugging functions ------------------------------------------------- */
115
116 #define isp116x_show_reg(d, r) {                                \
117         if ((r) < 0x20) {                                       \
118                 DBG("%-12s[%02x]: %08x", #r,                    \
119                         r, isp116x_read_reg32(d, r));           \
120         } else {                                                \
121                 DBG("%-12s[%02x]:     %04x", #r,                \
122                         r, isp116x_read_reg16(d, r));           \
123         }                                                       \
124 }
125
126 #define isp116x_show_regs(d) {                                  \
127         isp116x_show_reg(d, HCREVISION);                        \
128         isp116x_show_reg(d, HCCONTROL);                         \
129         isp116x_show_reg(d, HCCMDSTAT);                         \
130         isp116x_show_reg(d, HCINTSTAT);                         \
131         isp116x_show_reg(d, HCINTENB);                          \
132         isp116x_show_reg(d, HCFMINTVL);                         \
133         isp116x_show_reg(d, HCFMREM);                           \
134         isp116x_show_reg(d, HCFMNUM);                           \
135         isp116x_show_reg(d, HCLSTHRESH);                        \
136         isp116x_show_reg(d, HCRHDESCA);                         \
137         isp116x_show_reg(d, HCRHDESCB);                         \
138         isp116x_show_reg(d, HCRHSTATUS);                        \
139         isp116x_show_reg(d, HCRHPORT1);                         \
140         isp116x_show_reg(d, HCRHPORT2);                         \
141         isp116x_show_reg(d, HCHWCFG);                           \
142         isp116x_show_reg(d, HCDMACFG);                          \
143         isp116x_show_reg(d, HCXFERCTR);                         \
144         isp116x_show_reg(d, HCuPINT);                           \
145         isp116x_show_reg(d, HCuPINTENB);                        \
146         isp116x_show_reg(d, HCCHIPID);                          \
147         isp116x_show_reg(d, HCSCRATCH);                         \
148         isp116x_show_reg(d, HCITLBUFLEN);                       \
149         isp116x_show_reg(d, HCATLBUFLEN);                       \
150         isp116x_show_reg(d, HCBUFSTAT);                         \
151         isp116x_show_reg(d, HCRDITL0LEN);                       \
152         isp116x_show_reg(d, HCRDITL1LEN);                       \
153 }
154
155 #if defined(TRACE)
156
157 static int isp116x_get_current_frame_number(struct usb_device *usb_dev)
158 {
159         struct isp116x *isp116x = &isp116x_dev;
160
161         return isp116x_read_reg32(isp116x, HCFMNUM);
162 }
163
164 static void dump_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
165                      int len, char *str)
166 {
167 #if defined(VERBOSE)
168         int i;
169 #endif
170
171         DBG("%s URB:[%4x] dev:%2d,ep:%2d-%c,type:%s,len:%d stat:%#lx",
172             str,
173             isp116x_get_current_frame_number(dev),
174             usb_pipedevice(pipe),
175             usb_pipeendpoint(pipe),
176             usb_pipeout(pipe) ? 'O' : 'I',
177             usb_pipetype(pipe) < 2 ?
178             (usb_pipeint(pipe) ?
179              "INTR" : "ISOC") :
180             (usb_pipecontrol(pipe) ? "CTRL" : "BULK"), len, dev->status);
181 #if defined(VERBOSE)
182         if (len > 0 && buffer) {
183                 printf(__FILE__ ": data(%d):", len);
184                 for (i = 0; i < 16 && i < len; i++)
185                         printf(" %02x", ((__u8 *) buffer)[i]);
186                 printf("%s\n", i < len ? "..." : "");
187         }
188 #endif
189 }
190
191 #define PTD_DIR_STR(ptd)  ({char __c;           \
192         switch(PTD_GET_DIR(ptd)){               \
193         case 0:  __c = 's'; break;              \
194         case 1:  __c = 'o'; break;              \
195         default: __c = 'i'; break;              \
196         }; __c;})
197
198 /*
199   Dump PTD info. The code documents the format
200   perfectly, right :)
201 */
202 static inline void dump_ptd(struct ptd *ptd)
203 {
204 #if defined(VERBOSE)
205         int k;
206 #endif
207
208         DBG("PTD(ext) : cc:%x %d%c%d %d,%d,%d t:%x %x%x%x",
209             PTD_GET_CC(ptd),
210             PTD_GET_FA(ptd), PTD_DIR_STR(ptd), PTD_GET_EP(ptd),
211             PTD_GET_COUNT(ptd), PTD_GET_LEN(ptd), PTD_GET_MPS(ptd),
212             PTD_GET_TOGGLE(ptd),
213             PTD_GET_ACTIVE(ptd), PTD_GET_SPD(ptd), PTD_GET_LAST(ptd));
214 #if defined(VERBOSE)
215         printf("isp116x: %s: PTD(byte): ", __FUNCTION__);
216         for (k = 0; k < sizeof(struct ptd); ++k)
217                 printf("%02x ", ((u8 *) ptd)[k]);
218         printf("\n");
219 #endif
220 }
221
222 static inline void dump_ptd_data(struct ptd *ptd, u8 * buf, int type)
223 {
224 #if defined(VERBOSE)
225         int k;
226
227         if (type == 0 /* 0ut data */ ) {
228                 printf("isp116x: %s: out data: ", __FUNCTION__);
229                 for (k = 0; k < PTD_GET_LEN(ptd); ++k)
230                         printf("%02x ", ((u8 *) buf)[k]);
231                 printf("\n");
232         }
233         if (type == 1 /* 1n data */ ) {
234                 printf("isp116x: %s: in data: ", __FUNCTION__);
235                 for (k = 0; k < PTD_GET_COUNT(ptd); ++k)
236                         printf("%02x ", ((u8 *) buf)[k]);
237                 printf("\n");
238         }
239
240         if (PTD_GET_LAST(ptd))
241                 DBG("--- last PTD ---");
242 #endif
243 }
244
245 #else
246
247 #define dump_msg(dev, pipe, buffer, len, str)                   do { } while (0)
248 #define dump_pkt(dev, pipe, buffer, len, setup, str, small)     do {} while (0)
249
250 #define dump_ptd(ptd)                   do {} while (0)
251 #define dump_ptd_data(ptd, buf, type)   do {} while (0)
252
253 #endif
254
255 /* --- Virtual Root Hub ---------------------------------------------------- */
256
257 #include <usbroothubdes.h>
258
259 /*
260  * Hub class-specific descriptor is constructed dynamically
261  */
262
263 /* --- Virtual root hub management functions ------------------------------- */
264
265 static int rh_check_port_status(struct isp116x *isp116x)
266 {
267         u32 temp, ndp, i;
268         int res;
269
270         res = -1;
271         temp = isp116x_read_reg32(isp116x, HCRHSTATUS);
272         ndp = (temp & RH_A_NDP);
273         for (i = 0; i < ndp; i++) {
274                 temp = isp116x_read_reg32(isp116x, HCRHPORT1 + i);
275                 /* check for a device disconnect */
276                 if (((temp & (RH_PS_PESC | RH_PS_CSC)) ==
277                      (RH_PS_PESC | RH_PS_CSC)) && ((temp & RH_PS_CCS) == 0)) {
278                         res = i;
279                         break;
280                 }
281         }
282         return res;
283 }
284
285 /* --- HC management functions --------------------------------------------- */
286
287 /* Write len bytes to fifo, pad till 32-bit boundary
288  */
289 static void write_ptddata_to_fifo(struct isp116x *isp116x, void *buf, int len)
290 {
291         u8 *dp = (u8 *) buf;
292         u16 *dp2 = (u16 *) buf;
293         u16 w;
294         int quot = len % 4;
295
296         if ((unsigned long)dp2 & 1) {
297                 /* not aligned */
298                 for (; len > 1; len -= 2) {
299                         w = *dp++;
300                         w |= *dp++ << 8;
301                         isp116x_raw_write_data16(isp116x, w);
302                 }
303                 if (len)
304                         isp116x_write_data16(isp116x, (u16) * dp);
305         } else {
306                 /* aligned */
307                 for (; len > 1; len -= 2)
308                         isp116x_raw_write_data16(isp116x, *dp2++);
309                 if (len)
310                         isp116x_write_data16(isp116x, 0xff & *((u8 *) dp2));
311         }
312         if (quot == 1 || quot == 2)
313                 isp116x_raw_write_data16(isp116x, 0);
314 }
315
316 /* Read len bytes from fifo and then read till 32-bit boundary
317  */
318 static void read_ptddata_from_fifo(struct isp116x *isp116x, void *buf, int len)
319 {
320         u8 *dp = (u8 *) buf;
321         u16 *dp2 = (u16 *) buf;
322         u16 w;
323         int quot = len % 4;
324
325         if ((unsigned long)dp2 & 1) {
326                 /* not aligned */
327                 for (; len > 1; len -= 2) {
328                         w = isp116x_raw_read_data16(isp116x);
329                         *dp++ = w & 0xff;
330                         *dp++ = (w >> 8) & 0xff;
331                 }
332                 if (len)
333                         *dp = 0xff & isp116x_read_data16(isp116x);
334         } else {
335                 /* aligned */
336                 for (; len > 1; len -= 2)
337                         *dp2++ = isp116x_raw_read_data16(isp116x);
338                 if (len)
339                         *(u8 *) dp2 = 0xff & isp116x_read_data16(isp116x);
340         }
341         if (quot == 1 || quot == 2)
342                 isp116x_raw_read_data16(isp116x);
343 }
344
345 /* Write PTD's and data for scheduled transfers into the fifo ram.
346  * Fifo must be empty and ready */
347 static void pack_fifo(struct isp116x *isp116x, struct usb_device *dev,
348                       unsigned long pipe, struct ptd *ptd, int n, void *data,
349                       int len)
350 {
351         int buflen = n * sizeof(struct ptd) + len;
352         int i, done;
353
354         DBG("--- pack buffer %p - %d bytes (fifo %d) ---", data, len, buflen);
355
356         isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
357         isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
358         isp116x_write_addr(isp116x, HCATLPORT | ISP116x_WRITE_OFFSET);
359
360         done = 0;
361         for (i = 0; i < n; i++) {
362                 DBG("i=%d - done=%d - len=%d", i, done, PTD_GET_LEN(&ptd[i]));
363
364                 dump_ptd(&ptd[i]);
365                 isp116x_write_data16(isp116x, ptd[i].count);
366                 isp116x_write_data16(isp116x, ptd[i].mps);
367                 isp116x_write_data16(isp116x, ptd[i].len);
368                 isp116x_write_data16(isp116x, ptd[i].faddr);
369
370                 dump_ptd_data(&ptd[i], (__u8 *) data + done, 0);
371                 write_ptddata_to_fifo(isp116x,
372                                       (__u8 *) data + done,
373                                       PTD_GET_LEN(&ptd[i]));
374
375                 done += PTD_GET_LEN(&ptd[i]);
376         }
377 }
378
379 /* Read the processed PTD's and data from fifo ram back to URBs' buffers.
380  * Fifo must be full and done */
381 static int unpack_fifo(struct isp116x *isp116x, struct usb_device *dev,
382                        unsigned long pipe, struct ptd *ptd, int n, void *data,
383                        int len)
384 {
385         int buflen = n * sizeof(struct ptd) + len;
386         int i, done, cc, ret;
387
388         isp116x_write_reg16(isp116x, HCuPINT, HCuPINT_AIIEOT);
389         isp116x_write_reg16(isp116x, HCXFERCTR, buflen);
390         isp116x_write_addr(isp116x, HCATLPORT);
391
392         ret = TD_CC_NOERROR;
393         done = 0;
394         for (i = 0; i < n; i++) {
395                 DBG("i=%d - done=%d - len=%d", i, done, PTD_GET_LEN(&ptd[i]));
396
397                 ptd[i].count = isp116x_read_data16(isp116x);
398                 ptd[i].mps = isp116x_read_data16(isp116x);
399                 ptd[i].len = isp116x_read_data16(isp116x);
400                 ptd[i].faddr = isp116x_read_data16(isp116x);
401                 dump_ptd(&ptd[i]);
402
403                 read_ptddata_from_fifo(isp116x,
404                                        (__u8 *) data + done,
405                                        PTD_GET_LEN(&ptd[i]));
406                 dump_ptd_data(&ptd[i], (__u8 *) data + done, 1);
407
408                 done += PTD_GET_LEN(&ptd[i]);
409
410                 cc = PTD_GET_CC(&ptd[i]);
411
412                 /* Data underrun means basically that we had more buffer space than
413                  * the function had data. It is perfectly normal but upper levels have
414                  * to know how much we actually transferred.
415                  */
416                 if (cc == TD_NOTACCESSED ||
417                                 (cc != TD_CC_NOERROR && (ret == TD_CC_NOERROR || ret == TD_DATAUNDERRUN)))
418                         ret = cc;
419         }
420
421         DBG("--- unpack buffer %p - %d bytes (fifo %d) ---", data, len, buflen);
422
423         return ret;
424 }
425
426 /* Interrupt handling
427  */
428 static int isp116x_interrupt(struct isp116x *isp116x)
429 {
430         u16 irqstat;
431         u32 intstat;
432         int ret = 0;
433
434         isp116x_write_reg16(isp116x, HCuPINTENB, 0);
435         irqstat = isp116x_read_reg16(isp116x, HCuPINT);
436         isp116x_write_reg16(isp116x, HCuPINT, irqstat);
437         DBG(">>>>>> irqstat %x <<<<<<", irqstat);
438
439         if (irqstat & HCuPINT_ATL) {
440                 DBG(">>>>>> HCuPINT_ATL <<<<<<");
441                 udelay(500);
442                 ret = 1;
443         }
444
445         if (irqstat & HCuPINT_OPR) {
446                 intstat = isp116x_read_reg32(isp116x, HCINTSTAT);
447                 isp116x_write_reg32(isp116x, HCINTSTAT, intstat);
448                 DBG(">>>>>> HCuPINT_OPR %x <<<<<<", intstat);
449
450                 if (intstat & HCINT_UE) {
451                         ERR("unrecoverable error, controller disabled");
452
453                         /* FIXME: be optimistic, hope that bug won't repeat
454                          * often. Make some non-interrupt context restart the
455                          * controller. Count and limit the retries though;
456                          * either hardware or software errors can go forever...
457                          */
458                         isp116x_reset(isp116x);
459                         ret = -1;
460                         return -1;
461                 }
462
463                 if (intstat & HCINT_RHSC) {
464                         got_rhsc = 1;
465                         ret = 1;
466                         /* When root hub or any of its ports is going
467                            to come out of suspend, it may take more
468                            than 10ms for status bits to stabilize. */
469                         mdelay(20);
470                 }
471
472                 if (intstat & HCINT_SO) {
473                         ERR("schedule overrun");
474                         ret = -1;
475                 }
476
477                 irqstat &= ~HCuPINT_OPR;
478         }
479
480         return ret;
481 }
482
483 /* With one PTD we can transfer almost 1K in one go;
484  * HC does the splitting into endpoint digestible transactions
485  */
486 struct ptd ptd[1];
487
488 static inline int max_transfer_len(struct usb_device *dev, unsigned long pipe)
489 {
490         unsigned mpck = usb_maxpacket(dev, pipe);
491
492         /* One PTD can transfer 1023 bytes but try to always
493          * transfer multiples of endpoint buffer size
494          */
495         return 1023 / mpck * mpck;
496 }
497
498 /* Do an USB transfer
499  */
500 static int isp116x_submit_job(struct usb_device *dev, unsigned long pipe,
501                               int dir, void *buffer, int len)
502 {
503         struct isp116x *isp116x = &isp116x_dev;
504         int type = usb_pipetype(pipe);
505         int epnum = usb_pipeendpoint(pipe);
506         int max = usb_maxpacket(dev, pipe);
507         int dir_out = usb_pipeout(pipe);
508         int speed_low = (dev->speed == USB_SPEED_LOW);
509         int i, done = 0, stat, timeout, cc;
510
511         /* 500 frames or 0.5s timeout when function is busy and NAKs transactions for a while */
512         int retries = 500;
513
514         DBG("------------------------------------------------");
515         dump_msg(dev, pipe, buffer, len, "SUBMIT");
516         DBG("------------------------------------------------");
517
518         if (len >= 1024) {
519                 ERR("Too big job");
520                 dev->status = USB_ST_CRC_ERR;
521                 return -1;
522         }
523
524         if (isp116x->disabled) {
525                 ERR("EPIPE");
526                 dev->status = USB_ST_CRC_ERR;
527                 return -1;
528         }
529
530         /* device pulled? Shortcut the action. */
531         if (devgone == dev) {
532                 ERR("ENODEV");
533                 dev->status = USB_ST_CRC_ERR;
534                 return USB_ST_CRC_ERR;
535         }
536
537         if (!max) {
538                 ERR("pipesize for pipe %lx is zero", pipe);
539                 dev->status = USB_ST_CRC_ERR;
540                 return -1;
541         }
542
543         if (type == PIPE_ISOCHRONOUS) {
544                 ERR("isochronous transfers not supported");
545                 dev->status = USB_ST_CRC_ERR;
546                 return -1;
547         }
548
549         /* FIFO not empty? */
550         if (isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_FULL) {
551                 ERR("****** FIFO not empty! ******");
552                 dev->status = USB_ST_BUF_ERR;
553                 return -1;
554         }
555
556       retry:
557         isp116x_write_reg32(isp116x, HCINTSTAT, 0xff);
558
559         /* Prepare the PTD data */
560         ptd->count = PTD_CC_MSK | PTD_ACTIVE_MSK |
561                 PTD_TOGGLE(usb_gettoggle(dev, epnum, dir_out));
562         ptd->mps = PTD_MPS(max) | PTD_SPD(speed_low) | PTD_EP(epnum) | PTD_LAST_MSK;
563         ptd->len = PTD_LEN(len) | PTD_DIR(dir);
564         ptd->faddr = PTD_FA(usb_pipedevice(pipe));
565
566 retry_same:
567         /* Pack data into FIFO ram */
568         pack_fifo(isp116x, dev, pipe, ptd, 1, buffer, len);
569 #ifdef EXTRA_DELAY
570         mdelay(EXTRA_DELAY);
571 #endif
572
573         /* Start the data transfer */
574
575         /* Allow more time for a BULK device to react - some are slow */
576         if (usb_pipebulk(pipe))
577                 timeout = 5000;
578         else
579                 timeout = 100;
580
581         /* Wait for it to complete */
582         for (;;) {
583                 /* Check whether the controller is done */
584                 stat = isp116x_interrupt(isp116x);
585
586                 if (stat < 0) {
587                         dev->status = USB_ST_CRC_ERR;
588                         break;
589                 }
590                 if (stat > 0)
591                         break;
592
593                 /* Check the timeout */
594                 if (--timeout)
595                         udelay(1);
596                 else {
597                         ERR("CTL:TIMEOUT ");
598                         stat = USB_ST_CRC_ERR;
599                         break;
600                 }
601         }
602
603         /* We got an Root Hub Status Change interrupt */
604         if (got_rhsc) {
605                 isp116x_show_regs(isp116x);
606
607                 got_rhsc = 0;
608
609                 /* Abuse timeout */
610                 timeout = rh_check_port_status(isp116x);
611                 if (timeout >= 0) {
612                         /*
613                          * FIXME! NOTE! AAAARGH!
614                          * This is potentially dangerous because it assumes
615                          * that only one device is ever plugged in!
616                          */
617                         devgone = dev;
618                 }
619         }
620
621         /* Ok, now we can read transfer status */
622
623         /* FIFO not ready? */
624         if (!(isp116x_read_reg16(isp116x, HCBUFSTAT) & HCBUFSTAT_ATL_DONE)) {
625                 ERR("****** FIFO not ready! ******");
626                 dev->status = USB_ST_BUF_ERR;
627                 return -1;
628         }
629
630         /* Unpack data from FIFO ram */
631         cc = unpack_fifo(isp116x, dev, pipe, ptd, 1, buffer, len);
632
633         i = PTD_GET_COUNT(ptd);
634         done += i;
635         buffer += i;
636         len -= i;
637
638         /* There was some kind of real problem; Prepare the PTD again
639          * and retry from the failed transaction on
640          */
641         if (cc && cc != TD_NOTACCESSED && cc != TD_DATAUNDERRUN) {
642                 if (retries >= 100) {
643                         retries -= 100;
644                         /* The chip will have toggled the toggle bit for the failed
645                          * transaction too. We have to toggle it back.
646                          */
647                         usb_settoggle(dev, epnum, dir_out, !PTD_GET_TOGGLE(ptd));
648                         goto retry;
649                 }
650         }
651         /* "Normal" errors; TD_NOTACCESSED would mean in effect that the function have NAKed
652          * the transactions from the first on for the whole frame. It may be busy and we retry
653          * with the same PTD. PTD_ACTIVE (and not TD_NOTACCESSED) would mean that some of the
654          * PTD didn't make it because the function was busy or the frame ended before the PTD
655          * finished. We prepare the rest of the data and try again.
656          */
657         else if (cc == TD_NOTACCESSED || PTD_GET_ACTIVE(ptd) || (cc != TD_DATAUNDERRUN && PTD_GET_COUNT(ptd) < PTD_GET_LEN(ptd))) {
658                 if (retries) {
659                         --retries;
660                         if (cc == TD_NOTACCESSED && PTD_GET_ACTIVE(ptd) && !PTD_GET_COUNT(ptd)) goto retry_same;
661                         usb_settoggle(dev, epnum, dir_out, PTD_GET_TOGGLE(ptd));
662                         goto retry;
663                 }
664         }
665
666         if (cc != TD_CC_NOERROR && cc != TD_DATAUNDERRUN) {
667                 DBG("****** completition code error %x ******", cc);
668                 switch (cc) {
669                 case TD_CC_BITSTUFFING:
670                         dev->status = USB_ST_BIT_ERR;
671                         break;
672                 case TD_CC_STALL:
673                         dev->status = USB_ST_STALLED;
674                         break;
675                 case TD_BUFFEROVERRUN:
676                 case TD_BUFFERUNDERRUN:
677                         dev->status = USB_ST_BUF_ERR;
678                         break;
679                 default:
680                         dev->status = USB_ST_CRC_ERR;
681                 }
682                 return -cc;
683         }
684         else usb_settoggle(dev, epnum, dir_out, PTD_GET_TOGGLE(ptd));
685
686         dump_msg(dev, pipe, buffer, len, "SUBMIT(ret)");
687
688         dev->status = 0;
689         return done;
690 }
691
692 /* Adapted from au1x00_usb_ohci.c
693  */
694 static int isp116x_submit_rh_msg(struct usb_device *dev, unsigned long pipe,
695                                  void *buffer, int transfer_len,
696                                  struct devrequest *cmd)
697 {
698         struct isp116x *isp116x = &isp116x_dev;
699         u32 tmp = 0;
700
701         int leni = transfer_len;
702         int len = 0;
703         int stat = 0;
704         u32 datab[4];
705         u8 *data_buf = (u8 *) datab;
706         u16 bmRType_bReq;
707         u16 wValue;
708         u16 wIndex;
709         u16 wLength;
710
711         if (usb_pipeint(pipe)) {
712                 INFO("Root-Hub submit IRQ: NOT implemented");
713                 return 0;
714         }
715
716         bmRType_bReq = cmd->requesttype | (cmd->request << 8);
717         wValue = swap_16(cmd->value);
718         wIndex = swap_16(cmd->index);
719         wLength = swap_16(cmd->length);
720
721         DBG("--- HUB ----------------------------------------");
722         DBG("submit rh urb, req=%x val=%#x index=%#x len=%d",
723             bmRType_bReq, wValue, wIndex, wLength);
724         dump_msg(dev, pipe, buffer, transfer_len, "RH");
725         DBG("------------------------------------------------");
726
727         switch (bmRType_bReq) {
728         case RH_GET_STATUS:
729                 DBG("RH_GET_STATUS");
730
731                 *(__u16 *) data_buf = swap_16(1);
732                 len = 2;
733                 break;
734
735         case RH_GET_STATUS | RH_INTERFACE:
736                 DBG("RH_GET_STATUS | RH_INTERFACE");
737
738                 *(__u16 *) data_buf = swap_16(0);
739                 len = 2;
740                 break;
741
742         case RH_GET_STATUS | RH_ENDPOINT:
743                 DBG("RH_GET_STATUS | RH_ENDPOINT");
744
745                 *(__u16 *) data_buf = swap_16(0);
746                 len = 2;
747                 break;
748
749         case RH_GET_STATUS | RH_CLASS:
750                 DBG("RH_GET_STATUS | RH_CLASS");
751
752                 tmp = isp116x_read_reg32(isp116x, HCRHSTATUS);
753
754                 *(__u32 *) data_buf = swap_32(tmp & ~(RH_HS_CRWE | RH_HS_DRWE));
755                 len = 4;
756                 break;
757
758         case RH_GET_STATUS | RH_OTHER | RH_CLASS:
759                 DBG("RH_GET_STATUS | RH_OTHER | RH_CLASS");
760
761                 tmp = isp116x_read_reg32(isp116x, HCRHPORT1 + wIndex - 1);
762                 *(__u32 *) data_buf = swap_32(tmp);
763                 isp116x_show_regs(isp116x);
764                 len = 4;
765                 break;
766
767         case RH_CLEAR_FEATURE | RH_ENDPOINT:
768                 DBG("RH_CLEAR_FEATURE | RH_ENDPOINT");
769
770                 switch (wValue) {
771                 case RH_ENDPOINT_STALL:
772                         DBG("C_HUB_ENDPOINT_STALL");
773                         len = 0;
774                         break;
775                 }
776                 break;
777
778         case RH_CLEAR_FEATURE | RH_CLASS:
779                 DBG("RH_CLEAR_FEATURE | RH_CLASS");
780
781                 switch (wValue) {
782                 case RH_C_HUB_LOCAL_POWER:
783                         DBG("C_HUB_LOCAL_POWER");
784                         len = 0;
785                         break;
786
787                 case RH_C_HUB_OVER_CURRENT:
788                         DBG("C_HUB_OVER_CURRENT");
789                         isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_OCIC);
790                         len = 0;
791                         break;
792                 }
793                 break;
794
795         case RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS:
796                 DBG("RH_CLEAR_FEATURE | RH_OTHER | RH_CLASS");
797
798                 switch (wValue) {
799                 case RH_PORT_ENABLE:
800                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
801                                             RH_PS_CCS);
802                         len = 0;
803                         break;
804
805                 case RH_PORT_SUSPEND:
806                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
807                                             RH_PS_POCI);
808                         len = 0;
809                         break;
810
811                 case RH_PORT_POWER:
812                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
813                                             RH_PS_LSDA);
814                         len = 0;
815                         break;
816
817                 case RH_C_PORT_CONNECTION:
818                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
819                                             RH_PS_CSC);
820                         len = 0;
821                         break;
822
823                 case RH_C_PORT_ENABLE:
824                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
825                                             RH_PS_PESC);
826                         len = 0;
827                         break;
828
829                 case RH_C_PORT_SUSPEND:
830                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
831                                             RH_PS_PSSC);
832                         len = 0;
833                         break;
834
835                 case RH_C_PORT_OVER_CURRENT:
836                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
837                                             RH_PS_POCI);
838                         len = 0;
839                         break;
840
841                 case RH_C_PORT_RESET:
842                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
843                                             RH_PS_PRSC);
844                         len = 0;
845                         break;
846
847                 default:
848                         ERR("invalid wValue");
849                         stat = USB_ST_STALLED;
850                 }
851
852                 isp116x_show_regs(isp116x);
853
854                 break;
855
856         case RH_SET_FEATURE | RH_OTHER | RH_CLASS:
857                 DBG("RH_SET_FEATURE | RH_OTHER | RH_CLASS");
858
859                 switch (wValue) {
860                 case RH_PORT_SUSPEND:
861                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
862                                             RH_PS_PSS);
863                         len = 0;
864                         break;
865
866                 case RH_PORT_RESET:
867                         /* Spin until any current reset finishes */
868                         while (1) {
869                                 tmp =
870                                     isp116x_read_reg32(isp116x,
871                                                        HCRHPORT1 + wIndex - 1);
872                                 if (!(tmp & RH_PS_PRS))
873                                         break;
874                                 mdelay(1);
875                         }
876                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
877                                             RH_PS_PRS);
878                         mdelay(10);
879
880                         len = 0;
881                         break;
882
883                 case RH_PORT_POWER:
884                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
885                                             RH_PS_PPS);
886                         len = 0;
887                         break;
888
889                 case RH_PORT_ENABLE:
890                         isp116x_write_reg32(isp116x, HCRHPORT1 + wIndex - 1,
891                                             RH_PS_PES);
892                         len = 0;
893                         break;
894
895                 default:
896                         ERR("invalid wValue");
897                         stat = USB_ST_STALLED;
898                 }
899
900                 isp116x_show_regs(isp116x);
901
902                 break;
903
904         case RH_SET_ADDRESS:
905                 DBG("RH_SET_ADDRESS");
906
907                 rh_devnum = wValue;
908                 len = 0;
909                 break;
910
911         case RH_GET_DESCRIPTOR:
912                 DBG("RH_GET_DESCRIPTOR: %x, %d", wValue, wLength);
913
914                 switch (wValue) {
915                 case (USB_DT_DEVICE << 8):      /* device descriptor */
916                         len = min_t(unsigned int,
917                                     leni, min_t(unsigned int,
918                                                 sizeof(root_hub_dev_des),
919                                                 wLength));
920                         data_buf = root_hub_dev_des;
921                         break;
922
923                 case (USB_DT_CONFIG << 8):      /* configuration descriptor */
924                         len = min_t(unsigned int,
925                                     leni, min_t(unsigned int,
926                                                 sizeof(root_hub_config_des),
927                                                 wLength));
928                         data_buf = root_hub_config_des;
929                         break;
930
931                 case ((USB_DT_STRING << 8) | 0x00):     /* string 0 descriptors */
932                         len = min_t(unsigned int,
933                                     leni, min_t(unsigned int,
934                                                 sizeof(root_hub_str_index0),
935                                                 wLength));
936                         data_buf = root_hub_str_index0;
937                         break;
938
939                 case ((USB_DT_STRING << 8) | 0x01):     /* string 1 descriptors */
940                         len = min_t(unsigned int,
941                                     leni, min_t(unsigned int,
942                                                 sizeof(root_hub_str_index1),
943                                                 wLength));
944                         data_buf = root_hub_str_index1;
945                         break;
946
947                 default:
948                         ERR("invalid wValue");
949                         stat = USB_ST_STALLED;
950                 }
951
952                 break;
953
954         case RH_GET_DESCRIPTOR | RH_CLASS:
955                 DBG("RH_GET_DESCRIPTOR | RH_CLASS");
956
957                 tmp = isp116x_read_reg32(isp116x, HCRHDESCA);
958
959                 data_buf[0] = 0x09;     /* min length; */
960                 data_buf[1] = 0x29;
961                 data_buf[2] = tmp & RH_A_NDP;
962                 data_buf[3] = 0;
963                 if (tmp & RH_A_PSM)     /* per-port power switching? */
964                         data_buf[3] |= 0x01;
965                 if (tmp & RH_A_NOCP)    /* no overcurrent reporting? */
966                         data_buf[3] |= 0x10;
967                 else if (tmp & RH_A_OCPM)       /* per-port overcurrent rep? */
968                         data_buf[3] |= 0x08;
969
970                 /* Corresponds to data_buf[4-7] */
971                 datab[1] = 0;
972                 data_buf[5] = (tmp & RH_A_POTPGT) >> 24;
973
974                 tmp = isp116x_read_reg32(isp116x, HCRHDESCB);
975
976                 data_buf[7] = tmp & RH_B_DR;
977                 if (data_buf[2] < 7)
978                         data_buf[8] = 0xff;
979                 else {
980                         data_buf[0] += 2;
981                         data_buf[8] = (tmp & RH_B_DR) >> 8;
982                         data_buf[10] = data_buf[9] = 0xff;
983                 }
984
985                 len = min_t(unsigned int, leni,
986                             min_t(unsigned int, data_buf[0], wLength));
987                 break;
988
989         case RH_GET_CONFIGURATION:
990                 DBG("RH_GET_CONFIGURATION");
991
992                 *(__u8 *) data_buf = 0x01;
993                 len = 1;
994                 break;
995
996         case RH_SET_CONFIGURATION:
997                 DBG("RH_SET_CONFIGURATION");
998
999                 isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPSC);
1000                 len = 0;
1001                 break;
1002
1003         default:
1004                 ERR("*** *** *** unsupported root hub command *** *** ***");
1005                 stat = USB_ST_STALLED;
1006         }
1007
1008         len = min_t(int, len, leni);
1009         if (buffer != data_buf)
1010                 memcpy(buffer, data_buf, len);
1011
1012         dev->act_len = len;
1013         dev->status = stat;
1014         DBG("dev act_len %d, status %d", dev->act_len, dev->status);
1015
1016         dump_msg(dev, pipe, buffer, transfer_len, "RH(ret)");
1017
1018         return stat;
1019 }
1020
1021 /* --- Transfer functions -------------------------------------------------- */
1022
1023 int submit_int_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1024                    int len, int interval)
1025 {
1026         DBG("dev=%p pipe=%#lx buf=%p size=%d int=%d",
1027             dev, pipe, buffer, len, interval);
1028
1029         return -1;
1030 }
1031
1032 int submit_control_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1033                        int len, struct devrequest *setup)
1034 {
1035         int devnum = usb_pipedevice(pipe);
1036         int epnum = usb_pipeendpoint(pipe);
1037         int max = max_transfer_len(dev, pipe);
1038         int dir_in = usb_pipein(pipe);
1039         int done, ret;
1040
1041         /* Control message is for the HUB? */
1042         if (devnum == rh_devnum)
1043                 return isp116x_submit_rh_msg(dev, pipe, buffer, len, setup);
1044
1045         /* Ok, no HUB message so send the message to the device */
1046
1047         /* Setup phase */
1048         DBG("--- SETUP PHASE --------------------------------");
1049         usb_settoggle(dev, epnum, 1, 0);
1050         ret = isp116x_submit_job(dev, pipe,
1051                                  PTD_DIR_SETUP,
1052                                  setup, sizeof(struct devrequest));
1053         if (ret < 0) {
1054                 DBG("control setup phase error (ret = %d", ret);
1055                 return -1;
1056         }
1057
1058         /* Data phase */
1059         DBG("--- DATA PHASE ---------------------------------");
1060         done = 0;
1061         usb_settoggle(dev, epnum, !dir_in, 1);
1062         while (done < len) {
1063                 ret = isp116x_submit_job(dev, pipe,
1064                                          dir_in ? PTD_DIR_IN : PTD_DIR_OUT,
1065                                          (__u8 *) buffer + done,
1066                                          max > len - done ? len - done : max);
1067                 if (ret < 0) {
1068                         DBG("control data phase error (ret = %d)", ret);
1069                         return -1;
1070                 }
1071                 done += ret;
1072
1073                 if (dir_in && ret < max)        /* short packet */
1074                         break;
1075         }
1076
1077         /* Status phase */
1078         DBG("--- STATUS PHASE -------------------------------");
1079         usb_settoggle(dev, epnum, !dir_in, 1);
1080         ret = isp116x_submit_job(dev, pipe,
1081                                  !dir_in ? PTD_DIR_IN : PTD_DIR_OUT, NULL, 0);
1082         if (ret < 0) {
1083                 DBG("control status phase error (ret = %d", ret);
1084                 return -1;
1085         }
1086
1087         dev->act_len = done;
1088
1089         dump_msg(dev, pipe, buffer, len, "DEV(ret)");
1090
1091         return done;
1092 }
1093
1094 int submit_bulk_msg(struct usb_device *dev, unsigned long pipe, void *buffer,
1095                     int len)
1096 {
1097         int dir_out = usb_pipeout(pipe);
1098         int max = max_transfer_len(dev, pipe);
1099         int done, ret;
1100
1101         DBG("--- BULK ---------------------------------------");
1102         DBG("dev=%ld pipe=%ld buf=%p size=%d dir_out=%d",
1103             usb_pipedevice(pipe), usb_pipeendpoint(pipe), buffer, len, dir_out);
1104
1105         done = 0;
1106         while (done < len) {
1107                 ret = isp116x_submit_job(dev, pipe,
1108                                          !dir_out ? PTD_DIR_IN : PTD_DIR_OUT,
1109                                          (__u8 *) buffer + done,
1110                                          max > len - done ? len - done : max);
1111                 if (ret < 0) {
1112                         DBG("error on bulk message (ret = %d)", ret);
1113                         return -1;
1114                 }
1115
1116                 done += ret;
1117
1118                 if (!dir_out && ret < max)      /* short packet */
1119                         break;
1120         }
1121
1122         dev->act_len = done;
1123
1124         return 0;
1125 }
1126
1127 /* --- Basic functions ----------------------------------------------------- */
1128
1129 static int isp116x_sw_reset(struct isp116x *isp116x)
1130 {
1131         int retries = 15;
1132         int ret = 0;
1133
1134         DBG("");
1135
1136         isp116x->disabled = 1;
1137
1138         isp116x_write_reg16(isp116x, HCSWRES, HCSWRES_MAGIC);
1139         isp116x_write_reg32(isp116x, HCCMDSTAT, HCCMDSTAT_HCR);
1140         while (--retries) {
1141                 /* It usually resets within 1 ms */
1142                 mdelay(1);
1143                 if (!(isp116x_read_reg32(isp116x, HCCMDSTAT) & HCCMDSTAT_HCR))
1144                         break;
1145         }
1146         if (!retries) {
1147                 ERR("software reset timeout");
1148                 ret = -1;
1149         }
1150         return ret;
1151 }
1152
1153 static int isp116x_reset(struct isp116x *isp116x)
1154 {
1155         unsigned long t;
1156         u16 clkrdy = 0;
1157         int ret, timeout = 15 /* ms */ ;
1158
1159         DBG("");
1160
1161         ret = isp116x_sw_reset(isp116x);
1162         if (ret)
1163                 return ret;
1164
1165         for (t = 0; t < timeout; t++) {
1166                 clkrdy = isp116x_read_reg16(isp116x, HCuPINT) & HCuPINT_CLKRDY;
1167                 if (clkrdy)
1168                         break;
1169                 mdelay(1);
1170         }
1171         if (!clkrdy) {
1172                 ERR("clock not ready after %dms", timeout);
1173                 /* After sw_reset the clock won't report to be ready, if
1174                    H_WAKEUP pin is high. */
1175                 ERR("please make sure that the H_WAKEUP pin is pulled low!");
1176                 ret = -1;
1177         }
1178         return ret;
1179 }
1180
1181 static void isp116x_stop(struct isp116x *isp116x)
1182 {
1183         u32 val;
1184
1185         DBG("");
1186
1187         isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1188
1189         /* Switch off ports' power, some devices don't come up
1190            after next 'start' without this */
1191         val = isp116x_read_reg32(isp116x, HCRHDESCA);
1192         val &= ~(RH_A_NPS | RH_A_PSM);
1193         isp116x_write_reg32(isp116x, HCRHDESCA, val);
1194         isp116x_write_reg32(isp116x, HCRHSTATUS, RH_HS_LPS);
1195
1196         isp116x_sw_reset(isp116x);
1197 }
1198
1199 /*
1200  *  Configure the chip. The chip must be successfully reset by now.
1201  */
1202 static int isp116x_start(struct isp116x *isp116x)
1203 {
1204         struct isp116x_platform_data *board = isp116x->board;
1205         u32 val;
1206
1207         DBG("");
1208
1209         /* Clear interrupt status and disable all interrupt sources */
1210         isp116x_write_reg16(isp116x, HCuPINT, 0xff);
1211         isp116x_write_reg16(isp116x, HCuPINTENB, 0);
1212
1213         isp116x_write_reg16(isp116x, HCITLBUFLEN, ISP116x_ITL_BUFSIZE);
1214         isp116x_write_reg16(isp116x, HCATLBUFLEN, ISP116x_ATL_BUFSIZE);
1215
1216         /* Hardware configuration */
1217         val = HCHWCFG_DBWIDTH(1);
1218         if (board->sel15Kres)
1219                 val |= HCHWCFG_15KRSEL;
1220         /* Remote wakeup won't work without working clock */
1221         if (board->remote_wakeup_enable)
1222                 val |= HCHWCFG_CLKNOTSTOP;
1223         if (board->oc_enable)
1224                 val |= HCHWCFG_ANALOG_OC;
1225         isp116x_write_reg16(isp116x, HCHWCFG, val);
1226
1227         /* --- Root hub configuration */
1228         val = (25 << 24) & RH_A_POTPGT;
1229         /* AN10003_1.pdf recommends RH_A_NPS (no power switching) to
1230            be always set. Yet, instead, we request individual port
1231            power switching. */
1232         val |= RH_A_PSM;
1233         /* Report overcurrent per port */
1234         val |= RH_A_OCPM;
1235         isp116x_write_reg32(isp116x, HCRHDESCA, val);
1236         isp116x->rhdesca = isp116x_read_reg32(isp116x, HCRHDESCA);
1237
1238         val = RH_B_PPCM;
1239         isp116x_write_reg32(isp116x, HCRHDESCB, val);
1240         isp116x->rhdescb = isp116x_read_reg32(isp116x, HCRHDESCB);
1241
1242         val = 0;
1243         if (board->remote_wakeup_enable)
1244                 val |= RH_HS_DRWE;
1245         isp116x_write_reg32(isp116x, HCRHSTATUS, val);
1246         isp116x->rhstatus = isp116x_read_reg32(isp116x, HCRHSTATUS);
1247
1248         isp116x_write_reg32(isp116x, HCFMINTVL, 0x27782edf);
1249
1250         /* Go operational */
1251         val = HCCONTROL_USB_OPER;
1252         if (board->remote_wakeup_enable)
1253                 val |= HCCONTROL_RWE;
1254         isp116x_write_reg32(isp116x, HCCONTROL, val);
1255
1256         /* Disable ports to avoid race in device enumeration */
1257         isp116x_write_reg32(isp116x, HCRHPORT1, RH_PS_CCS);
1258         isp116x_write_reg32(isp116x, HCRHPORT2, RH_PS_CCS);
1259
1260         isp116x_show_regs(isp116x);
1261
1262         isp116x->disabled = 0;
1263
1264         return 0;
1265 }
1266
1267 /* --- Init functions ------------------------------------------------------ */
1268
1269 int isp116x_check_id(struct isp116x *isp116x)
1270 {
1271         int val;
1272
1273         val = isp116x_read_reg16(isp116x, HCCHIPID);
1274         if ((val & HCCHIPID_MASK) != HCCHIPID_MAGIC) {
1275                 ERR("invalid chip ID %04x", val);
1276                 return -1;
1277         }
1278
1279         return 0;
1280 }
1281
1282 int usb_lowlevel_init(int index, enum usb_init_type init, void **controller))
1283 {
1284         struct isp116x *isp116x = &isp116x_dev;
1285
1286         DBG("");
1287
1288         got_rhsc = rh_devnum = 0;
1289
1290         /* Init device registers addr */
1291         isp116x->addr_reg = (u16 *) ISP116X_HCD_ADDR;
1292         isp116x->data_reg = (u16 *) ISP116X_HCD_DATA;
1293
1294         /* Setup specific board settings */
1295 #ifdef ISP116X_HCD_SEL15kRES
1296         isp116x_board.sel15Kres = 1;
1297 #endif
1298 #ifdef ISP116X_HCD_OC_ENABLE
1299         isp116x_board.oc_enable = 1;
1300 #endif
1301 #ifdef ISP116X_HCD_REMOTE_WAKEUP_ENABLE
1302         isp116x_board.remote_wakeup_enable = 1;
1303 #endif
1304         isp116x->board = &isp116x_board;
1305
1306         /* Try to get ISP116x silicon chip ID */
1307         if (isp116x_check_id(isp116x) < 0)
1308                 return -1;
1309
1310         isp116x->disabled = 1;
1311         isp116x->sleeping = 0;
1312
1313         isp116x_reset(isp116x);
1314         isp116x_start(isp116x);
1315
1316         return 0;
1317 }
1318
1319 int usb_lowlevel_stop(int index)
1320 {
1321         struct isp116x *isp116x = &isp116x_dev;
1322
1323         DBG("");
1324
1325         if (!isp116x->disabled)
1326                 isp116x_stop(isp116x);
1327
1328         return 0;
1329 }