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>
23 #include <asm/system.h>
24 #include <asm/byteorder.h>
25 #include <asm/mach-adm5120/adm5120_info.h>
27 #include "../core/hcd.h"
29 MODULE_DESCRIPTION("ADM5120 USB Host Controller Driver");
30 MODULE_LICENSE("GPL");
31 MODULE_AUTHOR("Jeroen Vreeken (pe1rxq@amsat.org)");
33 #define PFX "adm5120-hcd: "
35 #define ADMHCD_REG_CONTROL 0x00
36 #define ADMHCD_REG_INTSTATUS 0x04
37 #define ADMHCD_REG_INTENABLE 0x08
38 #define ADMHCD_REG_HOSTCONTROL 0x10
39 #define ADMHCD_REG_FMINTERVAL 0x18
40 #define ADMHCD_REG_FMNUMBER 0x1c
41 #define ADMHCD_REG_LSTHRESH 0x70
42 #define ADMHCD_REG_RHDESCR 0x74
43 #define ADMHCD_REG_PORTSTATUS0 0x78
44 #define ADMHCD_REG_PORTSTATUS1 0x7c
45 #define ADMHCD_REG_HOSTHEAD 0x80
48 #define ADMHCD_NUMPORTS 2
50 #define ADMHCD_HOST_EN 0x00000001 /* Host enable */
51 #define ADMHCD_SW_INTREQ 0x00000002 /* request software int */
52 #define ADMHCD_SW_RESET 0x00000008 /* Reset */
54 #define ADMHCD_INT_TD 0x00100000 /* TD completed */
55 #define ADMHCD_INT_SW 0x20000000 /* software interrupt */
56 #define ADMHCD_INT_FATAL 0x40000000 /* Fatal interrupt */
57 #define ADMHCD_INT_ACT 0x80000000 /* Interrupt active */
59 #define ADMHCD_STATE_RST 0x00000000 /* bus state reset */
60 #define ADMHCD_STATE_RES 0x00000001 /* bus state resume */
61 #define ADMHCD_STATE_OP 0x00000002 /* bus state operational */
62 #define ADMHCD_STATE_SUS 0x00000003 /* bus state suspended */
63 #define ADMHCD_DMA_EN 0x00000004 /* enable dma engine */
65 #define ADMHCD_NPS 0x00000020 /* No Power Switch */
66 #define ADMHCD_LPSC 0x04000000 /* Local power switch change */
68 #define ADMHCD_CCS 0x00000001 /* current connect status */
69 #define ADMHCD_PES 0x00000002 /* port enable status */
70 #define ADMHCD_PSS 0x00000004 /* port suspend status */
71 #define ADMHCD_POCI 0x00000008 /* port overcurrent indicator */
72 #define ADMHCD_PRS 0x00000010 /* port reset status */
73 #define ADMHCD_PPS 0x00000100 /* port power status */
74 #define ADMHCD_LSDA 0x00000200 /* low speed device attached */
75 #define ADMHCD_CSC 0x00010000 /* connect status change */
76 #define ADMHCD_PESC 0x00020000 /* enable status change */
77 #define ADMHCD_PSSC 0x00040000 /* suspend status change */
78 #define ADMHCD_OCIC 0x00080000 /* overcurrent change*/
79 #define ADMHCD_PRSC 0x00100000 /* reset status change */
83 /* Don't change first four, they used for DMA */
85 struct admhcd_td
*tail
;
86 struct admhcd_td
*head
;
87 struct admhcd_ed
*next
;
88 /* the rest is for the driver only: */
89 struct admhcd_td
*cur
;
90 struct usb_host_endpoint
*ep
;
92 struct admhcd_ed
*real
;
93 } __attribute__ ((packed
));
95 #define ADMHCD_ED_EPSHIFT 7 /* Shift for endpoint number */
96 #define ADMHCD_ED_INT 0x00000800 /* Is this an int endpoint */
97 #define ADMHCD_ED_SPEED 0x00002000 /* Is it a high speed dev? */
98 #define ADMHCD_ED_SKIP 0x00004000 /* Skip this ED */
99 #define ADMHCD_ED_FORMAT 0x00008000 /* Is this an isoc endpoint */
100 #define ADMHCD_ED_MAXSHIFT 16 /* Shift for max packet size */
103 /* Don't change first four, they are used for DMA */
107 struct admhcd_td
*next
;
108 /* the rest is for the driver only: */
110 struct admhcd_td
*real
;
111 } __attribute__ ((packed
));
113 #define ADMHCD_TD_OWN 0x80000000
114 #define ADMHCD_TD_TOGGLE 0x00000000
115 #define ADMHCD_TD_DATA0 0x01000000
116 #define ADMHCD_TD_DATA1 0x01800000
117 #define ADMHCD_TD_OUT 0x00200000
118 #define ADMHCD_TD_IN 0x00400000
119 #define ADMHCD_TD_SETUP 0x00000000
120 #define ADMHCD_TD_ISO 0x00010000
121 #define ADMHCD_TD_R 0x00040000
122 #define ADMHCD_TD_INTEN 0x00010000
124 static int admhcd_td_err
[16] = {
126 -EREMOTEIO
, /* CRC */
127 -EREMOTEIO
, /* bit stuff */
128 -EREMOTEIO
, /* data toggle */
130 -ETIMEDOUT
, /* timeout */
131 -EPROTO
, /* pid err */
132 -EPROTO
, /* unexpected pid */
133 -EREMOTEIO
, /* data overrun */
134 -EREMOTEIO
, /* data underrun */
135 -ETIMEDOUT
, /* 1010 */
136 -ETIMEDOUT
, /* 1011 */
137 -EREMOTEIO
, /* buffer overrun */
138 -EREMOTEIO
, /* buffer underrun */
139 -ETIMEDOUT
, /* 1110 */
140 -ETIMEDOUT
, /* 1111 */
143 #define ADMHCD_TD_ERRMASK 0x38000000
144 #define ADMHCD_TD_ERRSHIFT 27
146 #define TD(td) ((struct admhcd_td *)(((u32)(td)) & ~0xf))
147 #define ED(ed) ((struct admhcd_ed *)(((u32)(ed)) & ~0xf))
152 void __iomem
*addr_reg
;
153 void __iomem
*data_reg
;
154 /* Root hub registers */
160 /* async schedule: control, bulk */
161 struct list_head async
;
168 static inline struct admhcd
*hcd_to_admhcd(struct usb_hcd
*hcd
)
170 return (struct admhcd
*)(hcd
->hcd_priv
);
173 static inline struct usb_hcd
*admhcd_to_hcd(struct admhcd
*admhcd
)
175 return container_of((void *)admhcd
, struct usb_hcd
, hcd_priv
);
178 static char hcd_name
[] = "adm5120-hcd";
180 static u32
admhcd_reg_get(struct admhcd
*ahcd
, int reg
)
182 return *(volatile u32
*)KSEG1ADDR(ahcd
->base
+reg
);
185 static void admhcd_reg_set(struct admhcd
*ahcd
, int reg
, u32 val
)
187 *(volatile u32
*)KSEG1ADDR(ahcd
->base
+reg
) = val
;
190 static void admhcd_lock(struct admhcd
*ahcd
)
192 spin_lock_irqsave(&ahcd
->lock
, ahcd
->flags
);
193 ahcd
->dma_en
= admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTCONTROL
) &
195 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
, ADMHCD_STATE_OP
);
198 static void admhcd_unlock(struct admhcd
*ahcd
)
200 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
,
201 ADMHCD_STATE_OP
| ahcd
->dma_en
);
202 spin_unlock_irqrestore(&ahcd
->lock
, ahcd
->flags
);
205 static struct admhcd_td
*admhcd_td_alloc(struct admhcd_ed
*ed
, struct urb
*urb
)
207 struct admhcd_td
*tdn
, *td
;
209 tdn
= kmalloc(sizeof(struct admhcd_td
), GFP_ATOMIC
);
213 tdn
= (struct admhcd_td
*)KSEG1ADDR(tdn
);
214 memset(tdn
, 0, sizeof(struct admhcd_td
));
215 if (ed
->cur
== NULL
) {
221 /* Supply back the old tail and link in new td as tail */
223 TD(ed
->tail
)->next
= tdn
;
231 static void admhcd_td_free(struct admhcd_ed
*ed
, struct urb
*urb
)
233 struct admhcd_td
*td
, **tdp
;
236 ed
->control
|= ADMHCD_ED_SKIP
;
245 while (td
&& td
->urb
== urb
) {
252 /* Find an endpoint's descriptor, if needed allocate a new one and link it
255 static struct admhcd_ed
*admhcd_get_ed(struct admhcd
*ahcd
,
256 struct usb_host_endpoint
*ep
, struct urb
*urb
)
258 struct admhcd_ed
*hosthead
;
259 struct admhcd_ed
*found
= NULL
, *ed
= NULL
;
260 unsigned int pipe
= urb
->pipe
;
263 hosthead
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
265 for (ed
= hosthead
;; ed
= ED(ed
->next
)) {
270 if (ED(ed
->next
) == hosthead
)
275 found
= kmalloc(sizeof(struct admhcd_ed
), GFP_ATOMIC
);
278 memset(found
, 0, sizeof(struct admhcd_ed
));
281 found
= (struct admhcd_ed
*)KSEG1ADDR(found
);
282 found
->control
= usb_pipedevice(pipe
) |
283 (usb_pipeendpoint(pipe
) << ADMHCD_ED_EPSHIFT
) |
284 (usb_pipeint(pipe
) ? ADMHCD_ED_INT
: 0) |
285 (urb
->dev
->speed
== USB_SPEED_FULL
? ADMHCD_ED_SPEED
: 0) |
286 (usb_pipeisoc(pipe
) ? ADMHCD_ED_FORMAT
: 0) |
287 (usb_maxpacket(urb
->dev
, pipe
, usb_pipeout(pipe
)) << ADMHCD_ED_MAXSHIFT
);
288 /* Alloc first dummy td */
289 admhcd_td_alloc(found
, NULL
);
291 found
->next
= hosthead
;
295 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, (u32
)found
);
303 static struct admhcd_td
*admhcd_td_fill(u32 control
, struct admhcd_td
*td
,
304 dma_addr_t data
, int len
)
308 td
->control
= control
;
312 static void admhcd_ed_start(struct admhcd
*ahcd
, struct admhcd_ed
*ed
)
314 struct admhcd_td
*td
= ed
->cur
;
321 td
->control
|= ADMHCD_TD_OWN
;
322 if (TD(td
->next
)->urb
!= td
->urb
) {
323 td
->buflen
|= ADMHCD_TD_INTEN
;
329 ed
->head
= TD(ed
->head
);
330 ahcd
->dma_en
|= ADMHCD_DMA_EN
;
333 static irqreturn_t
adm5120hcd_irq(struct usb_hcd
*hcd
)
335 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
338 intstatus
= admhcd_reg_get(ahcd
, ADMHCD_REG_INTSTATUS
);
339 if (intstatus
& ADMHCD_INT_FATAL
) {
340 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_FATAL
);
343 if (intstatus
& ADMHCD_INT_SW
) {
344 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_SW
);
347 if (intstatus
& ADMHCD_INT_TD
) {
348 struct admhcd_ed
*ed
, *head
;
350 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_TD
);
352 head
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
355 /* Is it a finished TD? */
356 if (ed
->urb
&& !(ed
->cur
->control
& ADMHCD_TD_OWN
)) {
357 struct admhcd_td
*td
;
361 error
= (td
->control
& ADMHCD_TD_ERRMASK
) >>
363 ed
->urb
->status
= admhcd_td_err
[error
];
364 admhcd_td_free(ed
, ed
->urb
);
365 // Calculate real length!!!
366 ed
->urb
->actual_length
= ed
->urb
->transfer_buffer_length
;
367 ed
->urb
->hcpriv
= NULL
;
368 usb_hcd_giveback_urb(hcd
, ed
->urb
);
371 admhcd_ed_start(ahcd
, ed
);
373 } while (ed
!= head
);
379 static int admhcd_urb_enqueue(struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
,
380 struct urb
*urb
, gfp_t mem_flags
)
382 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
383 struct admhcd_ed
*ed
;
384 struct admhcd_td
*td
;
385 int size
= 0, i
, zero
= 0, ret
= 0;
386 unsigned int pipe
= urb
->pipe
, toggle
= 0;
387 dma_addr_t data
= (dma_addr_t
)urb
->transfer_buffer
;
388 int data_len
= urb
->transfer_buffer_length
;
390 ed
= admhcd_get_ed(ahcd
, ep
, urb
);
394 switch(usb_pipetype(pipe
)) {
400 size
+= urb
->transfer_buffer_length
/ 4096;
401 if (urb
->transfer_buffer_length
% 4096)
405 else if (urb
->transfer_flags
& URB_ZERO_PACKET
&&
406 !(urb
->transfer_buffer_length
%
407 usb_maxpacket(urb
->dev
, pipe
, usb_pipeout(pipe
)))) {
412 case PIPE_ISOCHRONOUS
:
413 size
= urb
->number_of_packets
;
418 /* Remember the first td */
419 td
= admhcd_td_alloc(ed
, urb
);
424 /* Allocate additionall tds first */
425 for (i
= 1; i
< size
; i
++) {
426 if (admhcd_td_alloc(ed
, urb
) == NULL
) {
427 admhcd_td_free(ed
, urb
);
433 if (usb_gettoggle(urb
->dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
)))
434 toggle
= ADMHCD_TD_TOGGLE
;
436 toggle
= ADMHCD_TD_DATA0
;
437 usb_settoggle(urb
->dev
, usb_pipeendpoint(pipe
),
438 usb_pipeout(pipe
), 1);
441 switch(usb_pipetype(pipe
)) {
443 td
= admhcd_td_fill(ADMHCD_TD_SETUP
| ADMHCD_TD_DATA0
,
444 td
, (dma_addr_t
)urb
->setup_packet
, 8);
445 while (data_len
> 0) {
446 td
= admhcd_td_fill(ADMHCD_TD_DATA1
449 ADMHCD_TD_OUT
: ADMHCD_TD_IN
), td
,
450 data
, data_len
% 4097);
453 admhcd_td_fill(ADMHCD_TD_DATA1
| (usb_pipeout(pipe
) ?
454 ADMHCD_TD_IN
: ADMHCD_TD_OUT
), td
,
459 //info ok for interrupt?
461 while(data_len
> 4096) {
462 td
= admhcd_td_fill((usb_pipeout(pipe
) ?
464 ADMHCD_TD_IN
| ADMHCD_TD_R
) |
465 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
,
471 td
= admhcd_td_fill((usb_pipeout(pipe
) ?
472 ADMHCD_TD_OUT
: ADMHCD_TD_IN
) |
473 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
, data
, data_len
);
476 admhcd_td_fill((usb_pipeout(pipe
) ?
477 ADMHCD_TD_OUT
: ADMHCD_TD_IN
) |
478 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
, 0, 0);
480 case PIPE_ISOCHRONOUS
:
481 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
482 td
= admhcd_td_fill(ADMHCD_TD_ISO
|
483 ((urb
->start_frame
+ i
) & 0xffff), td
,
484 data
+ urb
->iso_frame_desc
[i
].offset
,
485 urb
->iso_frame_desc
[i
].length
);
490 admhcd_ed_start(ahcd
, ed
);
496 static int admhcd_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
498 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
499 struct admhcd_ed
*ed
;
504 if (ed
&& ed
->urb
!= urb
)
505 admhcd_td_free(ed
, urb
);
511 static void admhcd_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
)
513 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
514 struct admhcd_ed
*ed
, *edt
, *head
;
518 head
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
521 for (ed
= head
; ED(ed
->next
) != head
; ed
= ED(ed
->next
))
527 admhcd_td_free(ed
, ed
->cur
->urb
);
529 if (ED(ed
->next
) == ed
) {
530 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, 0);
535 for (edt
= head
; ED(edt
->next
) != head
; edt
= ED(edt
->next
));
536 edt
->next
= ED(ed
->next
);
537 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, (u32
)ed
->next
);
540 for (edt
= head
; edt
->next
!= ed
; edt
= edt
->next
);
541 edt
->next
= ed
->next
;
548 static int admhcd_get_frame_number(struct usb_hcd
*hcd
)
550 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
552 return admhcd_reg_get(ahcd
, ADMHCD_REG_FMNUMBER
) & 0x0000ffff;
555 static int admhcd_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
557 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
561 for (port
= 0; port
< ADMHCD_NUMPORTS
; port
++) {
562 if (admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4) &
563 (ADMHCD_CSC
| ADMHCD_PESC
| ADMHCD_PSSC
| ADMHCD_OCIC
|
565 *buf
|= (1 << (port
+ 1));
570 static __u8 root_hub_hub_des
[] = {
571 0x09, /* __u8 bLength; */
572 0x29, /* __u8 bDescriptorType; Hub-descriptor */
573 0x02, /* __u8 bNbrPorts; */
574 0x0a, 0x00, /* __u16 wHubCharacteristics; */
575 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
576 0x00, /* __u8 bHubContrCurrent; 0mA */
577 0x00, /* __u8 DeviceRemovable; */
578 0xff, /* __u8 PortPwrCtrlMask; */
581 static int admhcd_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
582 u16 wIndex
, char *buf
, u16 wLength
)
584 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
586 unsigned int port
= wIndex
-1;
591 *(__le32
*)buf
= cpu_to_le32(0);
594 if (port
>= ADMHCD_NUMPORTS
)
596 *(__le32
*)buf
= cpu_to_le32(
597 admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4));
599 case SetHubFeature
: /* We don't implement these */
600 case ClearHubFeature
:
602 case C_HUB_OVER_CURRENT
:
603 case C_HUB_LOCAL_POWER
:
609 if (port
>= ADMHCD_NUMPORTS
)
613 case USB_PORT_FEAT_SUSPEND
:
614 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
617 case USB_PORT_FEAT_RESET
:
618 if (admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4)
621 ADMHCD_REG_PORTSTATUS0
+ port
*4,
622 ADMHCD_PRS
| ADMHCD_CSC
);
625 ADMHCD_REG_PORTSTATUS0
+ port
*4,
626 ADMHCD_PES
| ADMHCD_CSC
);
629 case USB_PORT_FEAT_POWER
:
630 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
637 case ClearPortFeature
:
638 if (port
>= ADMHCD_NUMPORTS
)
642 case USB_PORT_FEAT_ENABLE
:
643 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
646 case USB_PORT_FEAT_C_ENABLE
:
647 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
650 case USB_PORT_FEAT_SUSPEND
:
651 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
654 case USB_PORT_FEAT_C_SUSPEND
:
655 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
657 case USB_PORT_FEAT_POWER
:
658 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
661 case USB_PORT_FEAT_C_CONNECTION
:
662 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
665 case USB_PORT_FEAT_C_OVER_CURRENT
:
666 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
669 case USB_PORT_FEAT_C_RESET
:
670 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
677 case GetHubDescriptor
:
678 len
= min_t(unsigned int, sizeof(root_hub_hub_des
), wLength
);
679 memcpy(buf
, root_hub_hub_des
, len
);
689 static struct hc_driver adm5120_hc_driver
= {
690 .description
= hcd_name
,
691 .product_desc
= "ADM5120 HCD",
692 .hcd_priv_size
= sizeof(struct admhcd
),
693 .irq
= adm5120hcd_irq
,
695 .urb_enqueue
= admhcd_urb_enqueue
,
696 .urb_dequeue
= admhcd_urb_dequeue
,
697 .endpoint_disable
= admhcd_endpoint_disable
,
698 .get_frame_number
= admhcd_get_frame_number
,
699 .hub_status_data
= admhcd_hub_status_data
,
700 .hub_control
= admhcd_hub_control
,
703 #define resource_len(r) (((r)->end - (r)->start) + 1)
705 static int __init
adm5120hcd_probe(struct platform_device
*pdev
)
709 struct resource
*addr
, *data
;
710 void __iomem
*addr_reg
;
711 void __iomem
*data_reg
;
715 if (pdev
->num_resources
< 3) {
720 if (pdev
->dev
.dma_mask
) {
721 printk(KERN_DEBUG
"no we won't dma\n");
725 irq
= platform_get_irq(pdev
, 0);
726 data
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
727 addr
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
729 if (!addr
|| !data
|| irq
< 0) {
734 if (!request_mem_region(addr
->start
, 2, hcd_name
)) {
739 addr_reg
= ioremap(addr
->start
, resource_len(addr
));
740 if (addr_reg
== NULL
) {
744 if (!request_mem_region(data
->start
, 2, hcd_name
)) {
749 data_reg
= ioremap(data
->start
, resource_len(data
));
750 if (data_reg
== NULL
) {
755 hcd
= usb_create_hcd(&adm5120_hc_driver
, &pdev
->dev
, pdev
->dev
.bus_id
);
759 hcd
->rsrc_start
= addr
->start
;
760 ahcd
= hcd_to_admhcd(hcd
);
762 spin_lock_init(&ahcd
->lock
);
763 INIT_LIST_HEAD(&ahcd
->async
);
765 ahcd
->data_reg
= data_reg
;
766 ahcd
->addr_reg
= addr_reg
;
768 hcd
->product_desc
= "ADM5120 HCD";
770 /* Initialise the HCD registers */
771 admhcd_reg_set(ahcd
, ADMHCD_REG_INTENABLE
, 0);
774 admhcd_reg_set(ahcd
, ADMHCD_REG_CONTROL
, ADMHCD_SW_RESET
);
776 while (admhcd_reg_get(ahcd
, ADMHCD_REG_CONTROL
) & ADMHCD_SW_RESET
)
779 admhcd_reg_set(ahcd
, ADMHCD_REG_CONTROL
, ADMHCD_HOST_EN
);
780 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, 0x00000000);
781 admhcd_reg_set(ahcd
, ADMHCD_REG_FMINTERVAL
, 0x20002edf);
782 admhcd_reg_set(ahcd
, ADMHCD_REG_LSTHRESH
, 0x628);
783 admhcd_reg_set(ahcd
, ADMHCD_REG_INTENABLE
,
784 ADMHCD_INT_ACT
| ADMHCD_INT_FATAL
| ADMHCD_INT_SW
| ADMHCD_INT_TD
);
785 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
,
786 ADMHCD_INT_ACT
| ADMHCD_INT_FATAL
| ADMHCD_INT_SW
| ADMHCD_INT_TD
);
787 admhcd_reg_set(ahcd
, ADMHCD_REG_RHDESCR
, ADMHCD_NPS
| ADMHCD_LPSC
);
788 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
, ADMHCD_STATE_OP
);
790 err
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
);
801 release_mem_region(pdev
->resource
[0].start
, pdev
->resource
[0].end
- pdev
->resource
[0].start
);
806 static int __init_or_module
adm5120hcd_remove(struct platform_device
*pdev
)
808 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
813 ahcd
= hcd_to_admhcd(hcd
);
820 static struct platform_driver adm5120hcd_driver
= {
821 .probe
= adm5120hcd_probe
,
822 .remove
= adm5120hcd_remove
,
824 .name
= "adm5120-hcd",
825 .owner
= THIS_MODULE
,
829 static int __init
adm5120hcd_init(void)
833 if (!adm5120_board
.has_usb
) {
834 printk(KERN_DEBUG PFX
"this board does not have USB\n");
838 printk(KERN_INFO PFX
"registered\n");
839 return platform_driver_register(&adm5120hcd_driver
);
842 static void __exit
adm5120hcd_exit(void)
844 platform_driver_unregister(&adm5120hcd_driver
);
847 module_init(adm5120hcd_init
);
848 module_exit(adm5120hcd_exit
);