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 ADMHCD_REG_CONTROL 0x00
34 #define ADMHCD_REG_INTSTATUS 0x04
35 #define ADMHCD_REG_INTENABLE 0x08
36 #define ADMHCD_REG_HOSTCONTROL 0x10
37 #define ADMHCD_REG_FMINTERVAL 0x18
38 #define ADMHCD_REG_FMNUMBER 0x1c
39 #define ADMHCD_REG_LSTHRESH 0x70
40 #define ADMHCD_REG_RHDESCR 0x74
41 #define ADMHCD_REG_PORTSTATUS0 0x78
42 #define ADMHCD_REG_PORTSTATUS1 0x7c
43 #define ADMHCD_REG_HOSTHEAD 0x80
46 #define ADMHCD_NUMPORTS 2
48 #define ADMHCD_HOST_EN 0x00000001 /* Host enable */
49 #define ADMHCD_SW_INTREQ 0x00000002 /* request software int */
50 #define ADMHCD_SW_RESET 0x00000008 /* Reset */
52 #define ADMHCD_INT_TD 0x00100000 /* TD completed */
53 #define ADMHCD_INT_SW 0x20000000 /* software interrupt */
54 #define ADMHCD_INT_FATAL 0x40000000 /* Fatal interrupt */
55 #define ADMHCD_INT_ACT 0x80000000 /* Interrupt active */
57 #define ADMHCD_STATE_RST 0x00000000 /* bus state reset */
58 #define ADMHCD_STATE_RES 0x00000001 /* bus state resume */
59 #define ADMHCD_STATE_OP 0x00000002 /* bus state operational */
60 #define ADMHCD_STATE_SUS 0x00000003 /* bus state suspended */
61 #define ADMHCD_DMA_EN 0x00000004 /* enable dma engine */
63 #define ADMHCD_NPS 0x00000020 /* No Power Switch */
64 #define ADMHCD_LPSC 0x04000000 /* Local power switch change */
66 #define ADMHCD_CCS 0x00000001 /* current connect status */
67 #define ADMHCD_PES 0x00000002 /* port enable status */
68 #define ADMHCD_PSS 0x00000004 /* port suspend status */
69 #define ADMHCD_POCI 0x00000008 /* port overcurrent indicator */
70 #define ADMHCD_PRS 0x00000010 /* port reset status */
71 #define ADMHCD_PPS 0x00000100 /* port power status */
72 #define ADMHCD_LSDA 0x00000200 /* low speed device attached */
73 #define ADMHCD_CSC 0x00010000 /* connect status change */
74 #define ADMHCD_PESC 0x00020000 /* enable status change */
75 #define ADMHCD_PSSC 0x00040000 /* suspend status change */
76 #define ADMHCD_OCIC 0x00080000 /* overcurrent change*/
77 #define ADMHCD_PRSC 0x00100000 /* reset status change */
81 /* Don't change first four, they used for DMA */
83 struct admhcd_td
*tail
;
84 struct admhcd_td
*head
;
85 struct admhcd_ed
*next
;
86 /* the rest is for the driver only: */
87 struct admhcd_td
*cur
;
88 struct usb_host_endpoint
*ep
;
90 struct admhcd_ed
*real
;
91 } __attribute__ ((packed
));
93 #define ADMHCD_ED_EPSHIFT 7 /* Shift for endpoint number */
94 #define ADMHCD_ED_INT 0x00000800 /* Is this an int endpoint */
95 #define ADMHCD_ED_SPEED 0x00002000 /* Is it a high speed dev? */
96 #define ADMHCD_ED_SKIP 0x00004000 /* Skip this ED */
97 #define ADMHCD_ED_FORMAT 0x00008000 /* Is this an isoc endpoint */
98 #define ADMHCD_ED_MAXSHIFT 16 /* Shift for max packet size */
101 /* Don't change first four, they are used for DMA */
105 struct admhcd_td
*next
;
106 /* the rest is for the driver only: */
108 struct admhcd_td
*real
;
109 } __attribute__ ((packed
));
111 #define ADMHCD_TD_OWN 0x80000000
112 #define ADMHCD_TD_TOGGLE 0x00000000
113 #define ADMHCD_TD_DATA0 0x01000000
114 #define ADMHCD_TD_DATA1 0x01800000
115 #define ADMHCD_TD_OUT 0x00200000
116 #define ADMHCD_TD_IN 0x00400000
117 #define ADMHCD_TD_SETUP 0x00000000
118 #define ADMHCD_TD_ISO 0x00010000
119 #define ADMHCD_TD_R 0x00040000
120 #define ADMHCD_TD_INTEN 0x00010000
122 static int admhcd_td_err
[16] = {
124 -EREMOTEIO
, /* CRC */
125 -EREMOTEIO
, /* bit stuff */
126 -EREMOTEIO
, /* data toggle */
128 -ETIMEDOUT
, /* timeout */
129 -EPROTO
, /* pid err */
130 -EPROTO
, /* unexpected pid */
131 -EREMOTEIO
, /* data overrun */
132 -EREMOTEIO
, /* data underrun */
133 -ETIMEDOUT
, /* 1010 */
134 -ETIMEDOUT
, /* 1011 */
135 -EREMOTEIO
, /* buffer overrun */
136 -EREMOTEIO
, /* buffer underrun */
137 -ETIMEDOUT
, /* 1110 */
138 -ETIMEDOUT
, /* 1111 */
141 #define ADMHCD_TD_ERRMASK 0x38000000
142 #define ADMHCD_TD_ERRSHIFT 27
144 #define TD(td) ((struct admhcd_td *)(((u32)(td)) & ~0xf))
145 #define ED(ed) ((struct admhcd_ed *)(((u32)(ed)) & ~0xf))
150 void __iomem
*addr_reg
;
151 void __iomem
*data_reg
;
152 /* Root hub registers */
158 /* async schedule: control, bulk */
159 struct list_head async
;
166 static inline struct admhcd
*hcd_to_admhcd(struct usb_hcd
*hcd
)
168 return (struct admhcd
*)(hcd
->hcd_priv
);
171 static inline struct usb_hcd
*admhcd_to_hcd(struct admhcd
*admhcd
)
173 return container_of((void *)admhcd
, struct usb_hcd
, hcd_priv
);
176 static char hcd_name
[] = "adm5120-hcd";
178 static u32
admhcd_reg_get(struct admhcd
*ahcd
, int reg
)
180 return *(volatile u32
*)KSEG1ADDR(ahcd
->base
+reg
);
183 static void admhcd_reg_set(struct admhcd
*ahcd
, int reg
, u32 val
)
185 *(volatile u32
*)KSEG1ADDR(ahcd
->base
+reg
) = val
;
188 static void admhcd_lock(struct admhcd
*ahcd
)
190 spin_lock_irqsave(&ahcd
->lock
, ahcd
->flags
);
191 ahcd
->dma_en
= admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTCONTROL
) &
193 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
, ADMHCD_STATE_OP
);
196 static void admhcd_unlock(struct admhcd
*ahcd
)
198 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
,
199 ADMHCD_STATE_OP
| ahcd
->dma_en
);
200 spin_unlock_irqrestore(&ahcd
->lock
, ahcd
->flags
);
203 static struct admhcd_td
*admhcd_td_alloc(struct admhcd_ed
*ed
, struct urb
*urb
)
205 struct admhcd_td
*tdn
, *td
;
207 tdn
= kmalloc(sizeof(struct admhcd_td
), GFP_ATOMIC
);
211 tdn
= (struct admhcd_td
*)KSEG1ADDR(tdn
);
212 memset(tdn
, 0, sizeof(struct admhcd_td
));
213 if (ed
->cur
== NULL
) {
219 /* Supply back the old tail and link in new td as tail */
221 TD(ed
->tail
)->next
= tdn
;
229 static void admhcd_td_free(struct admhcd_ed
*ed
, struct urb
*urb
)
231 struct admhcd_td
*td
, **tdp
;
234 ed
->control
|= ADMHCD_ED_SKIP
;
243 while (td
&& td
->urb
== urb
) {
250 /* Find an endpoint's descriptor, if needed allocate a new one and link it
253 static struct admhcd_ed
*admhcd_get_ed(struct admhcd
*ahcd
,
254 struct usb_host_endpoint
*ep
, struct urb
*urb
)
256 struct admhcd_ed
*hosthead
;
257 struct admhcd_ed
*found
= NULL
, *ed
= NULL
;
258 unsigned int pipe
= urb
->pipe
;
261 hosthead
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
263 for (ed
= hosthead
;; ed
= ED(ed
->next
)) {
268 if (ED(ed
->next
) == hosthead
)
273 found
= kmalloc(sizeof(struct admhcd_ed
), GFP_ATOMIC
);
276 memset(found
, 0, sizeof(struct admhcd_ed
));
279 found
= (struct admhcd_ed
*)KSEG1ADDR(found
);
280 found
->control
= usb_pipedevice(pipe
) |
281 (usb_pipeendpoint(pipe
) << ADMHCD_ED_EPSHIFT
) |
282 (usb_pipeint(pipe
) ? ADMHCD_ED_INT
: 0) |
283 (urb
->dev
->speed
== USB_SPEED_FULL
? ADMHCD_ED_SPEED
: 0) |
284 (usb_pipeisoc(pipe
) ? ADMHCD_ED_FORMAT
: 0) |
285 (usb_maxpacket(urb
->dev
, pipe
, usb_pipeout(pipe
)) << ADMHCD_ED_MAXSHIFT
);
286 /* Alloc first dummy td */
287 admhcd_td_alloc(found
, NULL
);
289 found
->next
= hosthead
;
293 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, (u32
)found
);
301 static struct admhcd_td
*admhcd_td_fill(u32 control
, struct admhcd_td
*td
,
302 dma_addr_t data
, int len
)
306 td
->control
= control
;
310 static void admhcd_ed_start(struct admhcd
*ahcd
, struct admhcd_ed
*ed
)
312 struct admhcd_td
*td
= ed
->cur
;
319 td
->control
|= ADMHCD_TD_OWN
;
320 if (TD(td
->next
)->urb
!= td
->urb
) {
321 td
->buflen
|= ADMHCD_TD_INTEN
;
327 ed
->head
= TD(ed
->head
);
328 ahcd
->dma_en
|= ADMHCD_DMA_EN
;
331 static irqreturn_t
adm5120hcd_irq(int irq
, void *ptr
, struct pt_regs
*regs
)
333 struct usb_hcd
*hcd
= (struct usb_hcd
*)ptr
;
334 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
337 intstatus
= admhcd_reg_get(ahcd
, ADMHCD_REG_INTSTATUS
);
338 if (intstatus
& ADMHCD_INT_FATAL
) {
339 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_FATAL
);
342 if (intstatus
& ADMHCD_INT_SW
) {
343 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_SW
);
346 if (intstatus
& ADMHCD_INT_TD
) {
347 struct admhcd_ed
*ed
, *head
;
349 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
, ADMHCD_INT_TD
);
351 head
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
354 /* Is it a finished TD? */
355 if (ed
->urb
&& !(ed
->cur
->control
& ADMHCD_TD_OWN
)) {
356 struct admhcd_td
*td
;
360 error
= (td
->control
& ADMHCD_TD_ERRMASK
) >>
362 ed
->urb
->status
= admhcd_td_err
[error
];
363 admhcd_td_free(ed
, ed
->urb
);
364 // Calculate real length!!!
365 ed
->urb
->actual_length
= ed
->urb
->transfer_buffer_length
;
366 ed
->urb
->hcpriv
= NULL
;
367 usb_hcd_giveback_urb(hcd
, ed
->urb
);
370 admhcd_ed_start(ahcd
, ed
);
372 } while (ed
!= head
);
378 static int admhcd_urb_enqueue(struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
,
379 struct urb
*urb
, gfp_t mem_flags
)
381 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
382 struct admhcd_ed
*ed
;
383 struct admhcd_td
*td
;
384 int size
= 0, i
, zero
= 0, ret
= 0;
385 unsigned int pipe
= urb
->pipe
, toggle
= 0;
386 dma_addr_t data
= (dma_addr_t
)urb
->transfer_buffer
;
387 int data_len
= urb
->transfer_buffer_length
;
389 ed
= admhcd_get_ed(ahcd
, ep
, urb
);
393 switch(usb_pipetype(pipe
)) {
399 size
+= urb
->transfer_buffer_length
/ 4096;
400 if (urb
->transfer_buffer_length
% 4096)
404 else if (urb
->transfer_flags
& URB_ZERO_PACKET
&&
405 !(urb
->transfer_buffer_length
%
406 usb_maxpacket(urb
->dev
, pipe
, usb_pipeout(pipe
)))) {
411 case PIPE_ISOCHRONOUS
:
412 size
= urb
->number_of_packets
;
417 /* Remember the first td */
418 td
= admhcd_td_alloc(ed
, urb
);
423 /* Allocate additionall tds first */
424 for (i
= 1; i
< size
; i
++) {
425 if (admhcd_td_alloc(ed
, urb
) == NULL
) {
426 admhcd_td_free(ed
, urb
);
432 if (usb_gettoggle(urb
->dev
, usb_pipeendpoint(pipe
), usb_pipeout(pipe
)))
433 toggle
= ADMHCD_TD_TOGGLE
;
435 toggle
= ADMHCD_TD_DATA0
;
436 usb_settoggle(urb
->dev
, usb_pipeendpoint(pipe
),
437 usb_pipeout(pipe
), 1);
440 switch(usb_pipetype(pipe
)) {
442 td
= admhcd_td_fill(ADMHCD_TD_SETUP
| ADMHCD_TD_DATA0
,
443 td
, (dma_addr_t
)urb
->setup_packet
, 8);
444 while (data_len
> 0) {
445 td
= admhcd_td_fill(ADMHCD_TD_DATA1
448 ADMHCD_TD_OUT
: ADMHCD_TD_IN
), td
,
449 data
, data_len
% 4097);
452 admhcd_td_fill(ADMHCD_TD_DATA1
| (usb_pipeout(pipe
) ?
453 ADMHCD_TD_IN
: ADMHCD_TD_OUT
), td
,
458 //info ok for interrupt?
460 while(data_len
> 4096) {
461 td
= admhcd_td_fill((usb_pipeout(pipe
) ?
463 ADMHCD_TD_IN
| ADMHCD_TD_R
) |
464 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
,
470 td
= admhcd_td_fill((usb_pipeout(pipe
) ?
471 ADMHCD_TD_OUT
: ADMHCD_TD_IN
) |
472 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
, data
, data_len
);
475 admhcd_td_fill((usb_pipeout(pipe
) ?
476 ADMHCD_TD_OUT
: ADMHCD_TD_IN
) |
477 (i
? ADMHCD_TD_TOGGLE
: toggle
), td
, 0, 0);
479 case PIPE_ISOCHRONOUS
:
480 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
481 td
= admhcd_td_fill(ADMHCD_TD_ISO
|
482 ((urb
->start_frame
+ i
) & 0xffff), td
,
483 data
+ urb
->iso_frame_desc
[i
].offset
,
484 urb
->iso_frame_desc
[i
].length
);
489 admhcd_ed_start(ahcd
, ed
);
495 static int admhcd_urb_dequeue(struct usb_hcd
*hcd
, struct urb
*urb
)
497 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
498 struct admhcd_ed
*ed
;
503 if (ed
&& ed
->urb
!= urb
)
504 admhcd_td_free(ed
, urb
);
510 static void admhcd_endpoint_disable(struct usb_hcd
*hcd
, struct usb_host_endpoint
*ep
)
512 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
513 struct admhcd_ed
*ed
, *edt
, *head
;
517 head
= (struct admhcd_ed
*)admhcd_reg_get(ahcd
, ADMHCD_REG_HOSTHEAD
);
520 for (ed
= head
; ED(ed
->next
) != head
; ed
= ED(ed
->next
))
526 admhcd_td_free(ed
, ed
->cur
->urb
);
528 if (ED(ed
->next
) == ed
) {
529 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, 0);
534 for (edt
= head
; ED(edt
->next
) != head
; edt
= ED(edt
->next
));
535 edt
->next
= ED(ed
->next
);
536 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, (u32
)ed
->next
);
539 for (edt
= head
; edt
->next
!= ed
; edt
= edt
->next
);
540 edt
->next
= ed
->next
;
547 static int admhcd_get_frame_number(struct usb_hcd
*hcd
)
549 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
551 return admhcd_reg_get(ahcd
, ADMHCD_REG_FMNUMBER
) & 0x0000ffff;
554 static int admhcd_hub_status_data(struct usb_hcd
*hcd
, char *buf
)
556 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
560 for (port
= 0; port
< ADMHCD_NUMPORTS
; port
++) {
561 if (admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4) &
562 (ADMHCD_CSC
| ADMHCD_PESC
| ADMHCD_PSSC
| ADMHCD_OCIC
|
564 *buf
|= (1 << (port
+ 1));
569 static __u8 root_hub_hub_des
[] = {
570 0x09, /* __u8 bLength; */
571 0x29, /* __u8 bDescriptorType; Hub-descriptor */
572 0x02, /* __u8 bNbrPorts; */
573 0x0a, 0x00, /* __u16 wHubCharacteristics; */
574 0x01, /* __u8 bPwrOn2pwrGood; 2ms */
575 0x00, /* __u8 bHubContrCurrent; 0mA */
576 0x00, /* __u8 DeviceRemovable; */
577 0xff, /* __u8 PortPwrCtrlMask; */
580 static int admhcd_hub_control(struct usb_hcd
*hcd
, u16 typeReq
, u16 wValue
,
581 u16 wIndex
, char *buf
, u16 wLength
)
583 struct admhcd
*ahcd
= hcd_to_admhcd(hcd
);
585 unsigned int port
= wIndex
-1;
590 *(__le32
*)buf
= cpu_to_le32(0);
593 if (port
>= ADMHCD_NUMPORTS
)
595 *(__le32
*)buf
= cpu_to_le32(
596 admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4));
598 case SetHubFeature
: /* We don't implement these */
599 case ClearHubFeature
:
601 case C_HUB_OVER_CURRENT
:
602 case C_HUB_LOCAL_POWER
:
608 if (port
>= ADMHCD_NUMPORTS
)
612 case USB_PORT_FEAT_SUSPEND
:
613 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
616 case USB_PORT_FEAT_RESET
:
617 if (admhcd_reg_get(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4)
620 ADMHCD_REG_PORTSTATUS0
+ port
*4,
621 ADMHCD_PRS
| ADMHCD_CSC
);
624 ADMHCD_REG_PORTSTATUS0
+ port
*4,
625 ADMHCD_PES
| ADMHCD_CSC
);
628 case USB_PORT_FEAT_POWER
:
629 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
636 case ClearPortFeature
:
637 if (port
>= ADMHCD_NUMPORTS
)
641 case USB_PORT_FEAT_ENABLE
:
642 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
645 case USB_PORT_FEAT_C_ENABLE
:
646 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
649 case USB_PORT_FEAT_SUSPEND
:
650 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
653 case USB_PORT_FEAT_C_SUSPEND
:
654 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
656 case USB_PORT_FEAT_POWER
:
657 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
660 case USB_PORT_FEAT_C_CONNECTION
:
661 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
664 case USB_PORT_FEAT_C_OVER_CURRENT
:
665 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
668 case USB_PORT_FEAT_C_RESET
:
669 admhcd_reg_set(ahcd
, ADMHCD_REG_PORTSTATUS0
+ port
*4,
676 case GetHubDescriptor
:
677 len
= min_t(unsigned int, sizeof(root_hub_hub_des
), wLength
);
678 memcpy(buf
, root_hub_hub_des
, len
);
688 static struct hc_driver adm5120_hc_driver
= {
689 .description
= hcd_name
,
690 .product_desc
= "ADM5120 HCD",
691 .hcd_priv_size
= sizeof(struct admhcd
),
693 .urb_enqueue
= admhcd_urb_enqueue
,
694 .urb_dequeue
= admhcd_urb_dequeue
,
695 .endpoint_disable
= admhcd_endpoint_disable
,
696 .get_frame_number
= admhcd_get_frame_number
,
697 .hub_status_data
= admhcd_hub_status_data
,
698 .hub_control
= admhcd_hub_control
,
701 #define resource_len(r) (((r)->end - (r)->start) + 1)
703 static int __init
adm5120hcd_probe(struct platform_device
*pdev
)
707 struct resource
*addr
, *data
;
708 void __iomem
*addr_reg
;
709 void __iomem
*data_reg
;
712 if (pdev
->num_resources
< 3) {
717 data
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
718 addr
= platform_get_resource(pdev
, IORESOURCE_MEM
, 1);
720 if (request_irq(data
->start
, adm5120hcd_irq
, 0, hcd_name
, hcd
)) {
721 printk(KERN_WARNING
"Could not request IRQ\n");
726 if (!addr
|| !data
|| irq
< 0) {
731 if (pdev
->dev
.dma_mask
) {
732 printk(KERN_DEBUG
"DMA not supported\n");
737 if (!request_mem_region(addr
->start
, 2, hcd_name
)) {
741 addr_reg
= ioremap(addr
->start
, resource_len(addr
));
742 if (addr_reg
== NULL
) {
746 if (!request_mem_region(data
->start
, 2, hcd_name
)) {
750 data_reg
= ioremap(data
->start
, resource_len(data
));
751 if (data_reg
== NULL
) {
757 hcd
= usb_create_hcd(&adm5120_hc_driver
, &pdev
->dev
, pdev
->dev
.bus_id
);
761 ahcd
= hcd_to_admhcd(hcd
);
762 ahcd
->data_reg
= data_reg
;
763 ahcd
->addr_reg
= addr_reg
;
764 spin_lock_init(&ahcd
->lock
);
765 INIT_LIST_HEAD(&ahcd
->async
);
767 /* Initialise the HCD registers */
768 admhcd_reg_set(ahcd
, ADMHCD_REG_INTENABLE
, 0);
770 admhcd_reg_set(ahcd
, ADMHCD_REG_CONTROL
, ADMHCD_SW_RESET
);
771 while (admhcd_reg_get(ahcd
, ADMHCD_REG_CONTROL
) & ADMHCD_SW_RESET
)
774 admhcd_reg_set(ahcd
, ADMHCD_REG_CONTROL
, ADMHCD_HOST_EN
);
775 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTHEAD
, 0x00000000);
776 admhcd_reg_set(ahcd
, ADMHCD_REG_FMINTERVAL
, 0x20002edf);
777 admhcd_reg_set(ahcd
, ADMHCD_REG_LSTHRESH
, 0x628);
778 admhcd_reg_set(ahcd
, ADMHCD_REG_INTENABLE
,
779 ADMHCD_INT_ACT
| ADMHCD_INT_FATAL
| ADMHCD_INT_SW
| ADMHCD_INT_TD
);
780 admhcd_reg_set(ahcd
, ADMHCD_REG_INTSTATUS
,
781 ADMHCD_INT_ACT
| ADMHCD_INT_FATAL
| ADMHCD_INT_SW
| ADMHCD_INT_TD
);
782 admhcd_reg_set(ahcd
, ADMHCD_REG_RHDESCR
, ADMHCD_NPS
| ADMHCD_LPSC
);
783 admhcd_reg_set(ahcd
, ADMHCD_REG_HOSTCONTROL
, ADMHCD_STATE_OP
);
785 err
= usb_add_hcd(hcd
, irq
, IRQF_DISABLED
);
796 release_mem_region(addr
->start
, 2);
801 static int __init_or_module
adm5120hcd_remove(struct platform_device
*pdev
)
803 struct usb_hcd
*hcd
= platform_get_drvdata(pdev
);
808 ahcd
= hcd_to_admhcd(hcd
);
815 static struct platform_driver adm5120hcd_driver
= {
816 .probe
= adm5120hcd_probe
,
817 .remove
= adm5120hcd_remove
,
819 .name
= "adm5120-hcd",
820 .owner
= THIS_MODULE
,
824 static int __init
adm5120hcd_init(void)
828 if (!adm5120_board
.has_usb
)
831 return platform_driver_register(&adm5120hcd_driver
);
834 static void __exit
adm5120hcd_exit(void)
836 platform_driver_unregister(&adm5120hcd_driver
);
839 module_init(adm5120hcd_init
);
840 module_exit(adm5120hcd_exit
);