2 * HCD driver for ADM5120 SoC
4 * Copyright (C) 2005 Jeroen Vreeken (pe1rxq@amsat.org)
6 * Based on the ADMtek 2.4 driver
7 * (C) Copyright 2003 Junius Chen <juniusc@admtek.com.tw>
8 * Which again was based on the ohci and uhci drivers.
11 #include <linux/module.h>
12 #include <linux/delay.h>
13 #include <linux/debugfs.h>
14 #include <linux/seq_file.h>
15 #include <linux/errno.h>
16 #include <linux/init.h>
17 #include <linux/list.h>
18 #include <linux/usb.h>
19 #include <linux/platform_device.h>
21 #include <asm/bootinfo.h>
24 #include <asm/system.h>
25 #include <asm/byteorder.h>
26 #include <asm/mach-adm5120/adm5120_info.h>
28 #include "../core/hcd.h"
30 MODULE_DESCRIPTION("ADM5120 USB Host Controller Driver");
31 MODULE_LICENSE("GPL");
32 MODULE_AUTHOR("Jeroen Vreeken (pe1rxq@amsat.org)");
34 #define PFX "adm5120-hcd: "
36 #define ADMHCD_REG_CONTROL 0x00
37 #define ADMHCD_SW_RESET 0x00000008 /* Reset */
38 #define ADMHCD_DMAA 0x00000004 /* DMA arbitration control */
39 #define ADMHCD_SW_INTREQ 0x00000002 /* request software int */
40 #define ADMHCD_HOST_EN 0x00000001 /* Host enable */
41 #define ADMHCD_REG_INTSTATUS 0x04
42 #define ADMHCD_INT_ACT 0x80000000 /* Interrupt active */
43 #define ADMHCD_INT_FATAL 0x40000000 /* Fatal interrupt */
44 #define ADMHCD_INT_SW 0x20000000 /* software interrupt */
45 #define ADMHCD_INT_TD 0x00100000 /* TD completed */
46 #define ADMHCD_FNO 0x00000800 /* Frame number overaflow */
47 #define ADMHCD_SO 0x00000400 /* Scheduling overrun */
48 #define ADMHCD_INSMI 0x00000200 /* Root hub status change */
49 #define ADMHCD_BABI 0x00000100 /* Babble detected, host mode */
50 #define ADMHCD_RESI 0x00000020 /* Resume detected */
51 #define ADMHCD_SOFI 0x00000010 /* SOF transmitted/received, host mode */
52 #define ADMHCD_REG_INTENABLE 0x08
53 #define ADMHCD_INT_EN 0x80000000 /* Interrupt enable */
54 #define ADMHCD_INTMASK 0x00000001 /* Interrupt mask */
55 #define ADMHCD_REG_HOSTCONTROL 0x10
56 #define ADMHCD_DMA_EN 0x00000004 /* USB host DMA enable */
57 #define ADMHCD_STATE_MASK 0x00000003
58 #define ADMHCD_STATE_RST 0x00000000 /* bus state reset */
59 #define ADMHCD_STATE_RES 0x00000001 /* bus state resume */
60 #define ADMHCD_STATE_OP 0x00000002 /* bus state operational */
61 #define ADMHCD_STATE_SUS 0x00000003 /* bus state suspended */
62 #define ADMHCD_REG_FMINTERVAL 0x18
63 #define ADMHCD_REG_FMNUMBER 0x1c
64 #define ADMHCD_REG_LSTHRESH 0x70
65 #define ADMHCD_REG_RHDESCR 0x74
66 #define ADMHCD_CRWE 0x20000000 /* Clear wakeup enable */
67 #define ADMHCD_DRWE 0x10000000 /* Device remote wakeup enable */
68 #define ADMHCD_HW_OCIC 0x08000000 /* Over current indication change */
69 #define ADMHCD_LPSC 0x04000000 /* Local power switch change */
70 #define ADMHCD_OCI 0x02000000 /* Over current indication */
71 #define ADMHCD_LPS 0x01000000 /* Local power switch/global power switch */
72 #define ADMHCD_NOCP 0x00000800 /* No over current protect mode */
73 #define ADMHCD_OPCM 0x00000400 /* Over current protect mode */
74 #define ADMHCD_NPS 0x00000200 /* No Power Switch */
75 #define ADMHCD_PSM 0x00000100 /* Power switch mode */
76 #define ADMHCD_REG_PORTSTATUS0 0x78
77 #define ADMHCD_CCS 0x00000001 /* current connect status */
78 #define ADMHCD_PES 0x00000002 /* port enable status */
79 #define ADMHCD_PSS 0x00000004 /* port suspend status */
80 #define ADMHCD_POCI 0x00000008 /* port overcurrent indicator */
81 #define ADMHCD_PRS 0x00000010 /* port reset status */
82 #define ADMHCD_PPS 0x00000100 /* port power status */
83 #define ADMHCD_LSDA 0x00000200 /* low speed device attached */
84 #define ADMHCD_CSC 0x00010000 /* connect status change */
85 #define ADMHCD_PESC 0x00020000 /* enable status change */
86 #define ADMHCD_PSSC 0x00040000 /* suspend status change */
87 #define ADMHCD_OCIC 0x00080000 /* overcurrent change*/
88 #define ADMHCD_PRSC 0x00100000 /* reset status change */
89 #define ADMHCD_REG_PORTSTATUS1 0x7c
90 #define ADMHCD_REG_HOSTHEAD 0x80
92 #define ADMHCD_NUMPORTS 2
95 /* Don't change first four, they used for DMA */
97 struct admhcd_td *tail;
98 struct admhcd_td *head;
99 struct admhcd_ed *next;
100 /* the rest is for the driver only: */
101 struct admhcd_td *cur;
102 struct usb_host_endpoint *ep;
104 struct admhcd_ed *real;
105 } __attribute__ ((packed));
107 #define ADMHCD_ED_EPSHIFT 7 /* Shift for endpoint number */
108 #define ADMHCD_ED_INT 0x00000800 /* Is this an int endpoint */
109 #define ADMHCD_ED_SPEED 0x00002000 /* Is it a high speed dev? */
110 #define ADMHCD_ED_SKIP 0x00004000 /* Skip this ED */
111 #define ADMHCD_ED_FORMAT 0x00008000 /* Is this an isoc endpoint */
112 #define ADMHCD_ED_MAXSHIFT 16 /* Shift for max packet size */
115 /* Don't change first four, they are used for DMA */
119 struct admhcd_td *next;
120 /* the rest is for the driver only: */
122 struct admhcd_td *real;
123 } __attribute__ ((packed));
125 #define ADMHCD_TD_OWN 0x80000000
126 #define ADMHCD_TD_TOGGLE 0x00000000
127 #define ADMHCD_TD_DATA0 0x01000000
128 #define ADMHCD_TD_DATA1 0x01800000
129 #define ADMHCD_TD_OUT 0x00200000
130 #define ADMHCD_TD_IN 0x00400000
131 #define ADMHCD_TD_SETUP 0x00000000
132 #define ADMHCD_TD_ISO 0x00010000
133 #define ADMHCD_TD_R 0x00040000
134 #define ADMHCD_TD_INTEN 0x00010000
136 static int admhcd_td_err[16] = {
138 -EREMOTEIO, /* CRC */
139 -EREMOTEIO, /* bit stuff */
140 -EREMOTEIO, /* data toggle */
142 -ETIMEDOUT, /* timeout */
143 -EPROTO, /* pid err */
144 -EPROTO, /* unexpected pid */
145 -EREMOTEIO, /* data overrun */
146 -EREMOTEIO, /* data underrun */
147 -ETIMEDOUT, /* 1010 */
148 -ETIMEDOUT, /* 1011 */
149 -EREMOTEIO, /* buffer overrun */
150 -EREMOTEIO, /* buffer underrun */
151 -ETIMEDOUT, /* 1110 */
152 -ETIMEDOUT, /* 1111 */
155 #define ADMHCD_TD_ERRMASK 0x38000000
156 #define ADMHCD_TD_ERRSHIFT 27
158 #define TD(td) ((struct admhcd_td *)(((u32)(td)) & ~0xf))
159 #define ED(ed) ((struct admhcd_ed *)(((u32)(ed)) & ~0xf))
164 void __iomem *data_reg;
165 /* Root hub registers */
171 /* async schedule: control, bulk */
172 struct list_head async;
179 static inline struct admhcd *hcd_to_admhcd(struct usb_hcd *hcd)
181 return (struct admhcd *)(hcd->hcd_priv);
184 static inline struct usb_hcd *admhcd_to_hcd(struct admhcd *admhcd)
186 return container_of((void *)admhcd, struct usb_hcd, hcd_priv);
189 static char hcd_name[] = "adm5120-hcd";
191 static u32 admhcd_reg_get(struct admhcd *ahcd, int reg)
193 return *(volatile u32 *)KSEG1ADDR(ahcd->base+reg);
196 static void admhcd_reg_set(struct admhcd *ahcd, int reg, u32 val)
198 *(volatile u32 *)KSEG1ADDR(ahcd->base+reg) = val;
201 static void admhcd_lock(struct admhcd *ahcd)
203 spin_lock_irqsave(&ahcd->lock, ahcd->flags);
204 ahcd->dma_en = admhcd_reg_get(ahcd, ADMHCD_REG_HOSTCONTROL) &
206 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTCONTROL, ADMHCD_STATE_OP);
209 static void admhcd_unlock(struct admhcd *ahcd)
211 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTCONTROL,
212 ADMHCD_STATE_OP | ahcd->dma_en);
213 spin_unlock_irqrestore(&ahcd->lock, ahcd->flags);
216 static struct admhcd_td *admhcd_td_alloc(struct admhcd_ed *ed, struct urb *urb)
218 struct admhcd_td *tdn, *td;
220 tdn = kzalloc(sizeof(*tdn), GFP_ATOMIC);
225 tdn = (struct admhcd_td *)KSEG1ADDR(tdn);
226 if (ed->cur == NULL) {
232 /* Supply back the old tail and link in new td as tail */
234 TD(ed->tail)->next = tdn;
242 static void admhcd_td_free(struct admhcd_ed *ed, struct urb *urb)
244 struct admhcd_td *td, **tdp;
247 ed->control |= ADMHCD_ED_SKIP;
256 while (td && td->urb == urb) {
263 /* Find an endpoint's descriptor, if needed allocate a new one and link it
266 static struct admhcd_ed *admhcd_get_ed(struct admhcd *ahcd,
267 struct usb_host_endpoint *ep, struct urb *urb)
269 struct admhcd_ed *hosthead;
270 struct admhcd_ed *found = NULL, *ed = NULL;
271 unsigned int pipe = urb->pipe;
274 hosthead = (struct admhcd_ed *)admhcd_reg_get(ahcd, ADMHCD_REG_HOSTHEAD);
276 for (ed = hosthead;; ed = ED(ed->next)) {
281 if (ED(ed->next) == hosthead)
286 found = kzalloc(sizeof(*found), GFP_ATOMIC);
291 found = (struct admhcd_ed *)KSEG1ADDR(found);
292 found->control = usb_pipedevice(pipe) |
293 (usb_pipeendpoint(pipe) << ADMHCD_ED_EPSHIFT) |
294 (usb_pipeint(pipe) ? ADMHCD_ED_INT : 0) |
295 (urb->dev->speed == USB_SPEED_FULL ? ADMHCD_ED_SPEED : 0) |
296 (usb_pipeisoc(pipe) ? ADMHCD_ED_FORMAT : 0) |
297 (usb_maxpacket(urb->dev, pipe, usb_pipeout(pipe)) << ADMHCD_ED_MAXSHIFT);
298 /* Alloc first dummy td */
299 admhcd_td_alloc(found, NULL);
301 found->next = hosthead;
305 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, (u32)found);
313 static struct admhcd_td *admhcd_td_fill(u32 control, struct admhcd_td *td,
314 dma_addr_t data, int len)
318 td->control = control;
322 static void admhcd_ed_start(struct admhcd *ahcd, struct admhcd_ed *ed)
324 struct admhcd_td *td = ed->cur;
331 td->control |= ADMHCD_TD_OWN;
332 if (TD(td->next)->urb != td->urb) {
333 td->buflen |= ADMHCD_TD_INTEN;
339 ed->head = TD(ed->head);
340 ahcd->dma_en |= ADMHCD_DMA_EN;
343 static irqreturn_t admhcd_irq(struct usb_hcd *hcd)
345 struct admhcd *ahcd = hcd_to_admhcd(hcd);
348 intstatus = admhcd_reg_get(ahcd, ADMHCD_REG_INTSTATUS);
349 if (intstatus & ADMHCD_INT_FATAL) {
350 admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, ADMHCD_INT_FATAL);
351 /* FIXME: handle fatal interrupts */
354 if (intstatus & ADMHCD_INT_SW) {
355 admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, ADMHCD_INT_SW);
356 /* FIXME: handle software interrupts */
359 if (intstatus & ADMHCD_INT_TD) {
360 struct admhcd_ed *ed, *head;
362 admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, ADMHCD_INT_TD);
364 head = (struct admhcd_ed *)admhcd_reg_get(ahcd, ADMHCD_REG_HOSTHEAD);
367 /* Is it a finished TD? */
368 if (ed->urb && !(ed->cur->control & ADMHCD_TD_OWN)) {
369 struct admhcd_td *td;
373 error = (td->control & ADMHCD_TD_ERRMASK) >>
375 ed->urb->status = admhcd_td_err[error];
376 admhcd_td_free(ed, ed->urb);
377 // Calculate real length!!!
378 ed->urb->actual_length = ed->urb->transfer_buffer_length;
379 ed->urb->hcpriv = NULL;
380 usb_hcd_giveback_urb(hcd, ed->urb);
383 admhcd_ed_start(ahcd, ed);
385 } while (ed != head);
391 static int admhcd_urb_enqueue(struct usb_hcd *hcd, struct usb_host_endpoint *ep,
392 struct urb *urb, gfp_t mem_flags)
394 struct admhcd *ahcd = hcd_to_admhcd(hcd);
395 struct admhcd_ed *ed;
396 struct admhcd_td *td;
397 int size = 0, i, zero = 0, ret = 0;
398 unsigned int pipe = urb->pipe, toggle = 0;
399 dma_addr_t data = (dma_addr_t)urb->transfer_buffer;
400 int data_len = urb->transfer_buffer_length;
402 ed = admhcd_get_ed(ahcd, ep, urb);
406 switch(usb_pipetype(pipe)) {
412 size += urb->transfer_buffer_length / 4096;
413 if (urb->transfer_buffer_length % 4096)
417 else if (urb->transfer_flags & URB_ZERO_PACKET &&
418 !(urb->transfer_buffer_length %
419 usb_maxpacket(urb->dev, pipe, usb_pipeout(pipe)))) {
424 case PIPE_ISOCHRONOUS:
425 size = urb->number_of_packets;
430 /* Remember the first td */
431 td = admhcd_td_alloc(ed, urb);
436 /* Allocate additionall tds first */
437 for (i = 1; i < size; i++) {
438 if (admhcd_td_alloc(ed, urb) == NULL) {
439 admhcd_td_free(ed, urb);
445 if (usb_gettoggle(urb->dev, usb_pipeendpoint(pipe), usb_pipeout(pipe)))
446 toggle = ADMHCD_TD_TOGGLE;
448 toggle = ADMHCD_TD_DATA0;
449 usb_settoggle(urb->dev, usb_pipeendpoint(pipe),
450 usb_pipeout(pipe), 1);
453 switch(usb_pipetype(pipe)) {
455 td = admhcd_td_fill(ADMHCD_TD_SETUP | ADMHCD_TD_DATA0,
456 td, (dma_addr_t)urb->setup_packet, 8);
457 while (data_len > 0) {
458 td = admhcd_td_fill(ADMHCD_TD_DATA1
461 ADMHCD_TD_OUT : ADMHCD_TD_IN), td,
462 data, data_len % 4097);
465 admhcd_td_fill(ADMHCD_TD_DATA1 | (usb_pipeout(pipe) ?
466 ADMHCD_TD_IN : ADMHCD_TD_OUT), td,
471 //info ok for interrupt?
473 while(data_len > 4096) {
474 td = admhcd_td_fill((usb_pipeout(pipe) ?
476 ADMHCD_TD_IN | ADMHCD_TD_R) |
477 (i ? ADMHCD_TD_TOGGLE : toggle), td,
483 td = admhcd_td_fill((usb_pipeout(pipe) ?
484 ADMHCD_TD_OUT : ADMHCD_TD_IN) |
485 (i ? ADMHCD_TD_TOGGLE : toggle), td, data, data_len);
488 admhcd_td_fill((usb_pipeout(pipe) ?
489 ADMHCD_TD_OUT : ADMHCD_TD_IN) |
490 (i ? ADMHCD_TD_TOGGLE : toggle), td, 0, 0);
492 case PIPE_ISOCHRONOUS:
493 for (i = 0; i < urb->number_of_packets; i++) {
494 td = admhcd_td_fill(ADMHCD_TD_ISO |
495 ((urb->start_frame + i) & 0xffff), td,
496 data + urb->iso_frame_desc[i].offset,
497 urb->iso_frame_desc[i].length);
502 admhcd_ed_start(ahcd, ed);
508 static int admhcd_urb_dequeue(struct usb_hcd *hcd, struct urb *urb)
510 struct admhcd *ahcd = hcd_to_admhcd(hcd);
511 struct admhcd_ed *ed;
516 if (ed && ed->urb != urb)
517 admhcd_td_free(ed, urb);
523 static void admhcd_endpoint_disable(struct usb_hcd *hcd, struct usb_host_endpoint *ep)
525 struct admhcd *ahcd = hcd_to_admhcd(hcd);
526 struct admhcd_ed *ed, *edt, *head;
530 head = (struct admhcd_ed *)admhcd_reg_get(ahcd, ADMHCD_REG_HOSTHEAD);
533 for (ed = head; ED(ed->next) != head; ed = ED(ed->next))
539 admhcd_td_free(ed, ed->cur->urb);
541 if (ED(ed->next) == ed) {
542 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, 0);
547 for (edt = head; ED(edt->next) != head; edt = ED(edt->next));
548 edt->next = ED(ed->next);
549 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, (u32)ed->next);
552 for (edt = head; edt->next != ed; edt = edt->next);
553 edt->next = ed->next;
561 static int admhcd_get_frame_number(struct usb_hcd *hcd)
563 struct admhcd *ahcd = hcd_to_admhcd(hcd);
565 return admhcd_reg_get(ahcd, ADMHCD_REG_FMNUMBER) & 0x0000ffff;
568 static int admhcd_hub_status_data(struct usb_hcd *hcd, char *buf)
570 struct admhcd *ahcd = hcd_to_admhcd(hcd);
574 for (port = 0; port < ADMHCD_NUMPORTS; port++) {
575 if (admhcd_reg_get(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4) &
576 (ADMHCD_CSC | ADMHCD_PESC | ADMHCD_PSSC | ADMHCD_OCIC |
578 *buf |= (1 << (port + 1));
583 static __u8 root_hub_hub_des[] = {
584 0x09, /* __u8 bLength; */
585 0x29, /* __u8 bDescriptorType; Hub-descriptor */
586 0x02, /* __u8 bNbrPorts; */
587 0x0a, 0x00, /* __u16 wHubCharacteristics; */
588 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
589 0x00, /* __u8 bHubContrCurrent; 0mA */
590 0x00, /* __u8 DeviceRemovable; */
591 0xff, /* __u8 PortPwrCtrlMask; */
594 static int admhcd_hub_control(struct usb_hcd *hcd, u16 typeReq, u16 wValue,
595 u16 wIndex, char *buf, u16 wLength)
597 struct admhcd *ahcd = hcd_to_admhcd(hcd);
599 unsigned int port = wIndex -1;
604 *(__le32 *)buf = cpu_to_le32(0);
607 if (port >= ADMHCD_NUMPORTS)
609 *(__le32 *)buf = cpu_to_le32(
610 admhcd_reg_get(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4));
612 case SetHubFeature: /* We don't implement these */
613 case ClearHubFeature:
615 case C_HUB_OVER_CURRENT:
616 case C_HUB_LOCAL_POWER:
622 if (port >= ADMHCD_NUMPORTS)
626 case USB_PORT_FEAT_SUSPEND:
627 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
630 case USB_PORT_FEAT_RESET:
631 if (admhcd_reg_get(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4)
634 ADMHCD_REG_PORTSTATUS0 + port*4,
635 ADMHCD_PRS | ADMHCD_CSC);
638 ADMHCD_REG_PORTSTATUS0 + port*4,
639 ADMHCD_PES | ADMHCD_CSC);
642 case USB_PORT_FEAT_POWER:
643 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
650 case ClearPortFeature:
651 if (port >= ADMHCD_NUMPORTS)
655 case USB_PORT_FEAT_ENABLE:
656 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
659 case USB_PORT_FEAT_C_ENABLE:
660 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
663 case USB_PORT_FEAT_SUSPEND:
664 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
667 case USB_PORT_FEAT_C_SUSPEND:
668 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
670 case USB_PORT_FEAT_POWER:
671 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
674 case USB_PORT_FEAT_C_CONNECTION:
675 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
678 case USB_PORT_FEAT_C_OVER_CURRENT:
679 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
682 case USB_PORT_FEAT_C_RESET:
683 admhcd_reg_set(ahcd, ADMHCD_REG_PORTSTATUS0 + port*4,
690 case GetHubDescriptor:
691 len = min_t(unsigned int, sizeof(root_hub_hub_des), wLength);
692 memcpy(buf, root_hub_hub_des, len);
702 static int admhcd_start(struct usb_hcd *hcd)
704 struct admhcd *ahcd = hcd_to_admhcd(hcd);
707 printk(KERN_DEBUG PFX "calling admhcd_start\n");
709 spin_lock_irqsave(&ahcd->lock, flags);
711 /* Initialise the HCD registers */
712 admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0);
715 admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_SW_RESET);
717 while (admhcd_reg_get(ahcd, ADMHCD_REG_CONTROL) & ADMHCD_SW_RESET) {
718 printk(KERN_WARNING PFX "waiting for reset to complete\n");
722 hcd->uses_new_polling = 1;
724 /* Enable USB host mode */
725 admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_HOST_EN);
727 /* Set host specific settings */
728 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTHEAD, 0x00000000);
729 admhcd_reg_set(ahcd, ADMHCD_REG_FMINTERVAL, 0x20002edf);
730 admhcd_reg_set(ahcd, ADMHCD_REG_LSTHRESH, 0x628);
733 admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, ADMHCD_INT_ACT |
734 ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD);
735 admhcd_reg_set(ahcd, ADMHCD_REG_INTSTATUS, ADMHCD_INT_ACT |
736 ADMHCD_INT_FATAL | ADMHCD_INT_SW | ADMHCD_INT_TD);
738 /* Power on all ports */
739 admhcd_reg_set(ahcd, ADMHCD_REG_RHDESCR, ADMHCD_NPS | ADMHCD_LPSC);
741 /* HCD is now operationnal */
742 admhcd_reg_set(ahcd, ADMHCD_REG_HOSTCONTROL, ADMHCD_STATE_OP);
744 hcd->state = HC_STATE_RUNNING;
746 spin_unlock_irqrestore(&ahcd->lock, flags);
748 printk(KERN_DEBUG PFX "returning 0 from admhcd_start\n");
752 static int admhcd_sw_reset(struct admhcd *ahcd)
758 spin_lock_irqsave(&ahcd->lock, flags);
760 admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0);
763 admhcd_reg_set(ahcd, ADMHCD_REG_CONTROL, ADMHCD_SW_RESET);
767 if (!(admhcd_reg_get(ahcd, ADMHCD_REG_CONTROL) & ADMHCD_SW_RESET))
771 printk(KERN_WARNING "%s: software reset timeout\n", hcd_name);
774 spin_unlock_irqrestore(&ahcd->lock, flags);
778 static int admhcd_reset(struct usb_hcd *hcd)
780 struct admhcd *ahcd = hcd_to_admhcd(hcd);
782 int ret, timeout = 15; /* ms */
785 ret = admhcd_sw_reset(ahcd);
789 t = jiffies + msecs_to_jiffies(timeout);
791 spin_lock_irq(&ahcd->lock);
792 state = admhcd_reg_get(ahcd, ADMHCD_REG_HOSTCONTROL);
793 spin_unlock_irq(&ahcd->lock);
794 state &= ADMHCD_STATE_MASK;
795 if (state == ADMHCD_STATE_RST)
798 } while (time_before_eq(jiffies, t));
800 if (state != ADMHCD_STATE_RST) {
801 printk(KERN_WARNING "%s: device not ready after %dms\n",
809 static void admhcd_stop(struct usb_hcd *hcd)
811 struct admhcd *ahcd = hcd_to_admhcd(hcd);
815 spin_lock_irqsave(&ahcd->lock, flags);
816 admhcd_reg_set(ahcd, ADMHCD_REG_INTENABLE, 0);
818 /* Set global control of power for ports */
819 val = admhcd_reg_get(ahcd, ADMHCD_REG_RHDESCR);
820 val &= (~ADMHCD_PSM | ADMHCD_LPS);
821 admhcd_reg_set(ahcd, ADMHCD_REG_RHDESCR, val);
823 spin_unlock_irqrestore(&ahcd->lock, flags);
825 /* Ask for software reset */
826 admhcd_sw_reset(ahcd);
830 static struct hc_driver adm5120_hc_driver = {
831 .description = hcd_name,
832 .product_desc = "ADM5120 HCD",
833 .hcd_priv_size = sizeof(struct admhcd),
836 .urb_enqueue = admhcd_urb_enqueue,
837 .urb_dequeue = admhcd_urb_dequeue,
838 .endpoint_disable = admhcd_endpoint_disable,
839 .get_frame_number = admhcd_get_frame_number,
840 .hub_status_data = admhcd_hub_status_data,
841 .hub_control = admhcd_hub_control,
842 .start = admhcd_start,
844 .reset = admhcd_reset,
847 #define resource_len(r) (((r)->end - (r)->start) + 1)
849 static int __init adm5120hcd_probe(struct platform_device *pdev)
853 struct resource *data;
854 void __iomem *data_reg;
858 if (pdev->num_resources < 2) {
859 printk(KERN_WARNING PFX "not enough resources\n");
864 irq = platform_get_irq(pdev, 0);
865 data = platform_get_resource(pdev, IORESOURCE_MEM, 0);
867 if (pdev->dev.dma_mask) {
868 printk(KERN_DEBUG PFX "no we won't dma\n");
872 if (!data || irq < 0) {
873 printk(KERN_DEBUG PFX "either IRQ or data resource is invalid\n");
878 if (!request_mem_region(data->start, resource_len(data), hcd_name)) {
879 printk(KERN_DEBUG PFX "cannot request memory regions for the data resource\n");
884 data_reg = ioremap(data->start, resource_len(data));
885 if (data_reg == NULL) {
886 printk(KERN_DEBUG PFX "unable to ioremap\n");
891 hcd = usb_create_hcd(&adm5120_hc_driver, &pdev->dev, pdev->dev.bus_id);
893 printk(KERN_DEBUG PFX "unable to create the hcd\n");
898 hcd->rsrc_start = data->start;
899 hcd->rsrc_len = resource_len(data);
900 hcd->regs = data_reg;
902 ahcd = hcd_to_admhcd(hcd);
903 ahcd->data_reg = data_reg;
904 ahcd->base = (u32)data_reg;
906 spin_lock_init(&ahcd->lock);
907 INIT_LIST_HEAD(&ahcd->async);
909 hcd->product_desc = "ADM5120 HCD";
911 err = usb_add_hcd(hcd, irq, IRQF_DISABLED);
913 printk(KERN_DEBUG PFX "unable to add hcd\n");
924 release_mem_region(pdev->resource[0].start, pdev->resource[0].end - pdev->resource[0].start +1);
930 static int adm5120hcd_suspend(struct platform_device *pdev, pm_message_t state)
932 pdev-dev.power.power_state = state;
937 static int adm5120hcd_resume(struct platform_device *pdev, pm_message_t state)
939 pdev->dev.power.power_state = PMSG_ON;
944 #define adm5120hcd_suspend NULL
945 #define adm5120hcd_resume NULL
948 static int __init_or_module adm5120hcd_remove(struct platform_device *pdev)
950 struct usb_hcd *hcd = platform_get_drvdata(pdev);
955 ahcd = hcd_to_admhcd(hcd);
962 static struct platform_driver adm5120hcd_driver = {
963 .probe = adm5120hcd_probe,
964 .remove = adm5120hcd_remove,
965 .suspend = adm5120hcd_suspend,
966 .remove = adm5120hcd_resume,
968 .name = (char *)hcd_name,
969 .owner = THIS_MODULE,
973 static int __init adm5120hcd_init(void)
977 if (usb_disabled()) {
978 printk(KERN_DEBUG PFX "USB support is disabled\n");
982 if (mips_machgroup != MACH_GROUP_ADM5120) {
983 printk(KERN_DEBUG PFX "unsupported machine group\n");
987 ret = platform_driver_register(&adm5120hcd_driver);
989 printk(KERN_INFO PFX "registered\n");
994 static void __exit adm5120hcd_exit(void)
996 platform_driver_unregister(&adm5120hcd_driver);
997 printk(KERN_INFO PFX "driver unregistered\n");
1000 module_init(adm5120hcd_init);
1001 module_exit(adm5120hcd_exit);