diff options
Diffstat (limited to 'drivers/usb/host/uhci-hcd.h')
-rw-r--r-- | drivers/usb/host/uhci-hcd.h | 248 |
1 files changed, 221 insertions, 27 deletions
diff --git a/drivers/usb/host/uhci-hcd.h b/drivers/usb/host/uhci-hcd.h index 49bf2790f9c2..7af2b7052047 100644 --- a/drivers/usb/host/uhci-hcd.h +++ b/drivers/usb/host/uhci-hcd.h | |||
@@ -78,11 +78,11 @@ | |||
78 | #define USBPORT1EN 0x01 | 78 | #define USBPORT1EN 0x01 |
79 | #define USBPORT2EN 0x02 | 79 | #define USBPORT2EN 0x02 |
80 | 80 | ||
81 | #define UHCI_PTR_BITS cpu_to_le32(0x000F) | 81 | #define UHCI_PTR_BITS(uhci) cpu_to_hc32((uhci), 0x000F) |
82 | #define UHCI_PTR_TERM cpu_to_le32(0x0001) | 82 | #define UHCI_PTR_TERM(uhci) cpu_to_hc32((uhci), 0x0001) |
83 | #define UHCI_PTR_QH cpu_to_le32(0x0002) | 83 | #define UHCI_PTR_QH(uhci) cpu_to_hc32((uhci), 0x0002) |
84 | #define UHCI_PTR_DEPTH cpu_to_le32(0x0004) | 84 | #define UHCI_PTR_DEPTH(uhci) cpu_to_hc32((uhci), 0x0004) |
85 | #define UHCI_PTR_BREADTH cpu_to_le32(0x0000) | 85 | #define UHCI_PTR_BREADTH(uhci) cpu_to_hc32((uhci), 0x0000) |
86 | 86 | ||
87 | #define UHCI_NUMFRAMES 1024 /* in the frame list [array] */ | 87 | #define UHCI_NUMFRAMES 1024 /* in the frame list [array] */ |
88 | #define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ | 88 | #define UHCI_MAX_SOF_NUMBER 2047 /* in an SOF packet */ |
@@ -99,6 +99,22 @@ | |||
99 | 99 | ||
100 | 100 | ||
101 | /* | 101 | /* |
102 | * __hc32 and __hc16 are "Host Controller" types, they may be equivalent to | ||
103 | * __leXX (normally) or __beXX (given UHCI_BIG_ENDIAN_DESC), depending on | ||
104 | * the host controller implementation. | ||
105 | * | ||
106 | * To facilitate the strongest possible byte-order checking from "sparse" | ||
107 | * and so on, we use __leXX unless that's not practical. | ||
108 | */ | ||
109 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_DESC | ||
110 | typedef __u32 __bitwise __hc32; | ||
111 | typedef __u16 __bitwise __hc16; | ||
112 | #else | ||
113 | #define __hc32 __le32 | ||
114 | #define __hc16 __le16 | ||
115 | #endif | ||
116 | |||
117 | /* | ||
102 | * Queue Headers | 118 | * Queue Headers |
103 | */ | 119 | */ |
104 | 120 | ||
@@ -130,8 +146,8 @@ | |||
130 | 146 | ||
131 | struct uhci_qh { | 147 | struct uhci_qh { |
132 | /* Hardware fields */ | 148 | /* Hardware fields */ |
133 | __le32 link; /* Next QH in the schedule */ | 149 | __hc32 link; /* Next QH in the schedule */ |
134 | __le32 element; /* Queue element (TD) pointer */ | 150 | __hc32 element; /* Queue element (TD) pointer */ |
135 | 151 | ||
136 | /* Software fields */ | 152 | /* Software fields */ |
137 | dma_addr_t dma_handle; | 153 | dma_addr_t dma_handle; |
@@ -168,14 +184,10 @@ struct uhci_qh { | |||
168 | * We need a special accessor for the element pointer because it is | 184 | * We need a special accessor for the element pointer because it is |
169 | * subject to asynchronous updates by the controller. | 185 | * subject to asynchronous updates by the controller. |
170 | */ | 186 | */ |
171 | static inline __le32 qh_element(struct uhci_qh *qh) { | 187 | #define qh_element(qh) ACCESS_ONCE((qh)->element) |
172 | __le32 element = qh->element; | ||
173 | 188 | ||
174 | barrier(); | 189 | #define LINK_TO_QH(uhci, qh) (UHCI_PTR_QH((uhci)) | \ |
175 | return element; | 190 | cpu_to_hc32((uhci), (qh)->dma_handle)) |
176 | } | ||
177 | |||
178 | #define LINK_TO_QH(qh) (UHCI_PTR_QH | cpu_to_le32((qh)->dma_handle)) | ||
179 | 191 | ||
180 | 192 | ||
181 | /* | 193 | /* |
@@ -212,7 +224,7 @@ static inline __le32 qh_element(struct uhci_qh *qh) { | |||
212 | /* | 224 | /* |
213 | * for TD <info>: (a.k.a. Token) | 225 | * for TD <info>: (a.k.a. Token) |
214 | */ | 226 | */ |
215 | #define td_token(td) le32_to_cpu((td)->token) | 227 | #define td_token(uhci, td) hc32_to_cpu((uhci), (td)->token) |
216 | #define TD_TOKEN_DEVADDR_SHIFT 8 | 228 | #define TD_TOKEN_DEVADDR_SHIFT 8 |
217 | #define TD_TOKEN_TOGGLE_SHIFT 19 | 229 | #define TD_TOKEN_TOGGLE_SHIFT 19 |
218 | #define TD_TOKEN_TOGGLE (1 << 19) | 230 | #define TD_TOKEN_TOGGLE (1 << 19) |
@@ -245,10 +257,10 @@ static inline __le32 qh_element(struct uhci_qh *qh) { | |||
245 | */ | 257 | */ |
246 | struct uhci_td { | 258 | struct uhci_td { |
247 | /* Hardware fields */ | 259 | /* Hardware fields */ |
248 | __le32 link; | 260 | __hc32 link; |
249 | __le32 status; | 261 | __hc32 status; |
250 | __le32 token; | 262 | __hc32 token; |
251 | __le32 buffer; | 263 | __hc32 buffer; |
252 | 264 | ||
253 | /* Software fields */ | 265 | /* Software fields */ |
254 | dma_addr_t dma_handle; | 266 | dma_addr_t dma_handle; |
@@ -263,14 +275,10 @@ struct uhci_td { | |||
263 | * We need a special accessor for the control/status word because it is | 275 | * We need a special accessor for the control/status word because it is |
264 | * subject to asynchronous updates by the controller. | 276 | * subject to asynchronous updates by the controller. |
265 | */ | 277 | */ |
266 | static inline u32 td_status(struct uhci_td *td) { | 278 | #define td_status(uhci, td) hc32_to_cpu((uhci), \ |
267 | __le32 status = td->status; | 279 | ACCESS_ONCE((td)->status)) |
268 | 280 | ||
269 | barrier(); | 281 | #define LINK_TO_TD(uhci, td) (cpu_to_hc32((uhci), (td)->dma_handle)) |
270 | return le32_to_cpu(status); | ||
271 | } | ||
272 | |||
273 | #define LINK_TO_TD(td) (cpu_to_le32((td)->dma_handle)) | ||
274 | 282 | ||
275 | 283 | ||
276 | /* | 284 | /* |
@@ -380,6 +388,9 @@ struct uhci_hcd { | |||
380 | /* Grabbed from PCI */ | 388 | /* Grabbed from PCI */ |
381 | unsigned long io_addr; | 389 | unsigned long io_addr; |
382 | 390 | ||
391 | /* Used when registers are memory mapped */ | ||
392 | void __iomem *regs; | ||
393 | |||
383 | struct dma_pool *qh_pool; | 394 | struct dma_pool *qh_pool; |
384 | struct dma_pool *td_pool; | 395 | struct dma_pool *td_pool; |
385 | 396 | ||
@@ -390,7 +401,7 @@ struct uhci_hcd { | |||
390 | spinlock_t lock; | 401 | spinlock_t lock; |
391 | 402 | ||
392 | dma_addr_t frame_dma_handle; /* Hardware frame list */ | 403 | dma_addr_t frame_dma_handle; /* Hardware frame list */ |
393 | __le32 *frame; | 404 | __hc32 *frame; |
394 | void **frame_cpu; /* CPU's frame list */ | 405 | void **frame_cpu; /* CPU's frame list */ |
395 | 406 | ||
396 | enum uhci_rh_state rh_state; | 407 | enum uhci_rh_state rh_state; |
@@ -415,6 +426,12 @@ struct uhci_hcd { | |||
415 | 426 | ||
416 | struct timer_list fsbr_timer; /* For turning off FBSR */ | 427 | struct timer_list fsbr_timer; /* For turning off FBSR */ |
417 | 428 | ||
429 | /* Silicon quirks */ | ||
430 | unsigned int oc_low:1; /* OverCurrent bit active low */ | ||
431 | unsigned int wait_for_hp:1; /* Wait for HP port reset */ | ||
432 | unsigned int big_endian_mmio:1; /* Big endian registers */ | ||
433 | unsigned int big_endian_desc:1; /* Big endian descriptors */ | ||
434 | |||
418 | /* Support for port suspend/resume/reset */ | 435 | /* Support for port suspend/resume/reset */ |
419 | unsigned long port_c_suspend; /* Bit-arrays of ports */ | 436 | unsigned long port_c_suspend; /* Bit-arrays of ports */ |
420 | unsigned long resuming_ports; | 437 | unsigned long resuming_ports; |
@@ -429,6 +446,16 @@ struct uhci_hcd { | |||
429 | 446 | ||
430 | int total_load; /* Sum of array values */ | 447 | int total_load; /* Sum of array values */ |
431 | short load[MAX_PHASE]; /* Periodic allocations */ | 448 | short load[MAX_PHASE]; /* Periodic allocations */ |
449 | |||
450 | /* Reset host controller */ | ||
451 | void (*reset_hc) (struct uhci_hcd *uhci); | ||
452 | int (*check_and_reset_hc) (struct uhci_hcd *uhci); | ||
453 | /* configure_hc should perform arch specific settings, if needed */ | ||
454 | void (*configure_hc) (struct uhci_hcd *uhci); | ||
455 | /* Check for broken resume detect interrupts */ | ||
456 | int (*resume_detect_interrupts_are_broken) (struct uhci_hcd *uhci); | ||
457 | /* Check for broken global suspend */ | ||
458 | int (*global_suspend_mode_is_broken) (struct uhci_hcd *uhci); | ||
432 | }; | 459 | }; |
433 | 460 | ||
434 | /* Convert between a usb_hcd pointer and the corresponding uhci_hcd */ | 461 | /* Convert between a usb_hcd pointer and the corresponding uhci_hcd */ |
@@ -467,4 +494,171 @@ struct urb_priv { | |||
467 | #define PCI_VENDOR_ID_GENESYS 0x17a0 | 494 | #define PCI_VENDOR_ID_GENESYS 0x17a0 |
468 | #define PCI_DEVICE_ID_GL880S_UHCI 0x8083 | 495 | #define PCI_DEVICE_ID_GL880S_UHCI 0x8083 |
469 | 496 | ||
497 | /* | ||
498 | * Functions used to access controller registers. The UCHI spec says that host | ||
499 | * controller I/O registers are mapped into PCI I/O space. For non-PCI hosts | ||
500 | * we use memory mapped registers. | ||
501 | */ | ||
502 | |||
503 | #ifndef CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC | ||
504 | /* Support PCI only */ | ||
505 | static inline u32 uhci_readl(const struct uhci_hcd *uhci, int reg) | ||
506 | { | ||
507 | return inl(uhci->io_addr + reg); | ||
508 | } | ||
509 | |||
510 | static inline void uhci_writel(const struct uhci_hcd *uhci, u32 val, int reg) | ||
511 | { | ||
512 | outl(val, uhci->io_addr + reg); | ||
513 | } | ||
514 | |||
515 | static inline u16 uhci_readw(const struct uhci_hcd *uhci, int reg) | ||
516 | { | ||
517 | return inw(uhci->io_addr + reg); | ||
518 | } | ||
519 | |||
520 | static inline void uhci_writew(const struct uhci_hcd *uhci, u16 val, int reg) | ||
521 | { | ||
522 | outw(val, uhci->io_addr + reg); | ||
523 | } | ||
524 | |||
525 | static inline u8 uhci_readb(const struct uhci_hcd *uhci, int reg) | ||
526 | { | ||
527 | return inb(uhci->io_addr + reg); | ||
528 | } | ||
529 | |||
530 | static inline void uhci_writeb(const struct uhci_hcd *uhci, u8 val, int reg) | ||
531 | { | ||
532 | outb(val, uhci->io_addr + reg); | ||
533 | } | ||
534 | |||
535 | #else | ||
536 | /* Support non-PCI host controllers */ | ||
537 | #ifdef CONFIG_PCI | ||
538 | /* Support PCI and non-PCI host controllers */ | ||
539 | #define uhci_has_pci_registers(u) ((u)->io_addr != 0) | ||
540 | #else | ||
541 | /* Support non-PCI host controllers only */ | ||
542 | #define uhci_has_pci_registers(u) 0 | ||
543 | #endif | ||
544 | |||
545 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
546 | /* Support (non-PCI) big endian host controllers */ | ||
547 | #define uhci_big_endian_mmio(u) ((u)->big_endian_mmio) | ||
548 | #else | ||
549 | #define uhci_big_endian_mmio(u) 0 | ||
550 | #endif | ||
551 | |||
552 | static inline u32 uhci_readl(const struct uhci_hcd *uhci, int reg) | ||
553 | { | ||
554 | if (uhci_has_pci_registers(uhci)) | ||
555 | return inl(uhci->io_addr + reg); | ||
556 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
557 | else if (uhci_big_endian_mmio(uhci)) | ||
558 | return readl_be(uhci->regs + reg); | ||
559 | #endif | ||
560 | else | ||
561 | return readl(uhci->regs + reg); | ||
562 | } | ||
563 | |||
564 | static inline void uhci_writel(const struct uhci_hcd *uhci, u32 val, int reg) | ||
565 | { | ||
566 | if (uhci_has_pci_registers(uhci)) | ||
567 | outl(val, uhci->io_addr + reg); | ||
568 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
569 | else if (uhci_big_endian_mmio(uhci)) | ||
570 | writel_be(val, uhci->regs + reg); | ||
571 | #endif | ||
572 | else | ||
573 | writel(val, uhci->regs + reg); | ||
574 | } | ||
575 | |||
576 | static inline u16 uhci_readw(const struct uhci_hcd *uhci, int reg) | ||
577 | { | ||
578 | if (uhci_has_pci_registers(uhci)) | ||
579 | return inw(uhci->io_addr + reg); | ||
580 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
581 | else if (uhci_big_endian_mmio(uhci)) | ||
582 | return readw_be(uhci->regs + reg); | ||
583 | #endif | ||
584 | else | ||
585 | return readw(uhci->regs + reg); | ||
586 | } | ||
587 | |||
588 | static inline void uhci_writew(const struct uhci_hcd *uhci, u16 val, int reg) | ||
589 | { | ||
590 | if (uhci_has_pci_registers(uhci)) | ||
591 | outw(val, uhci->io_addr + reg); | ||
592 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
593 | else if (uhci_big_endian_mmio(uhci)) | ||
594 | writew_be(val, uhci->regs + reg); | ||
595 | #endif | ||
596 | else | ||
597 | writew(val, uhci->regs + reg); | ||
598 | } | ||
599 | |||
600 | static inline u8 uhci_readb(const struct uhci_hcd *uhci, int reg) | ||
601 | { | ||
602 | if (uhci_has_pci_registers(uhci)) | ||
603 | return inb(uhci->io_addr + reg); | ||
604 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
605 | else if (uhci_big_endian_mmio(uhci)) | ||
606 | return readb_be(uhci->regs + reg); | ||
607 | #endif | ||
608 | else | ||
609 | return readb(uhci->regs + reg); | ||
610 | } | ||
611 | |||
612 | static inline void uhci_writeb(const struct uhci_hcd *uhci, u8 val, int reg) | ||
613 | { | ||
614 | if (uhci_has_pci_registers(uhci)) | ||
615 | outb(val, uhci->io_addr + reg); | ||
616 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_MMIO | ||
617 | else if (uhci_big_endian_mmio(uhci)) | ||
618 | writeb_be(val, uhci->regs + reg); | ||
619 | #endif | ||
620 | else | ||
621 | writeb(val, uhci->regs + reg); | ||
622 | } | ||
623 | #endif /* CONFIG_USB_UHCI_SUPPORT_NON_PCI_HC */ | ||
624 | |||
625 | /* | ||
626 | * The GRLIB GRUSBHC controller can use big endian format for its descriptors. | ||
627 | * | ||
628 | * UHCI controllers accessed through PCI work normally (little-endian | ||
629 | * everywhere), so we don't bother supporting a BE-only mode. | ||
630 | */ | ||
631 | #ifdef CONFIG_USB_UHCI_BIG_ENDIAN_DESC | ||
632 | #define uhci_big_endian_desc(u) ((u)->big_endian_desc) | ||
633 | |||
634 | /* cpu to uhci */ | ||
635 | static inline __hc32 cpu_to_hc32(const struct uhci_hcd *uhci, const u32 x) | ||
636 | { | ||
637 | return uhci_big_endian_desc(uhci) | ||
638 | ? (__force __hc32)cpu_to_be32(x) | ||
639 | : (__force __hc32)cpu_to_le32(x); | ||
640 | } | ||
641 | |||
642 | /* uhci to cpu */ | ||
643 | static inline u32 hc32_to_cpu(const struct uhci_hcd *uhci, const __hc32 x) | ||
644 | { | ||
645 | return uhci_big_endian_desc(uhci) | ||
646 | ? be32_to_cpu((__force __be32)x) | ||
647 | : le32_to_cpu((__force __le32)x); | ||
648 | } | ||
649 | |||
650 | #else | ||
651 | /* cpu to uhci */ | ||
652 | static inline __hc32 cpu_to_hc32(const struct uhci_hcd *uhci, const u32 x) | ||
653 | { | ||
654 | return cpu_to_le32(x); | ||
655 | } | ||
656 | |||
657 | /* uhci to cpu */ | ||
658 | static inline u32 hc32_to_cpu(const struct uhci_hcd *uhci, const __hc32 x) | ||
659 | { | ||
660 | return le32_to_cpu(x); | ||
661 | } | ||
662 | #endif | ||
663 | |||
470 | #endif | 664 | #endif |