Lines Matching full:ohci
3 * URB OHCI HCD (Host Controller Driver) for USB on the AT91RM9200 and PCI bus.
46 #include "ohci.h"
69 {0x10b9, 0x5237}, /* ULI1575 PCI OHCI module ids */
70 {0x1033, 0x0035}, /* NEC PCI OHCI module ids */
71 {0x1131, 0x1561}, /* Philips 1561 PCI OHCI module ids */
72 /* Please add supported PCI OHCI controller ids here */
141 /* mapping of the OHCI CC status to error codes */
196 static inline u32 roothub_a(struct ohci *hc) in roothub_a()
198 static inline u32 roothub_b(struct ohci *hc) in roothub_b()
200 static inline u32 roothub_status(struct ohci *hc) in roothub_status()
202 static inline u32 roothub_portstatus(struct ohci *hc, int i) in roothub_portstatus()
206 static int hc_interrupt(ohci_t *ohci);
207 static void td_submit_job(ohci_t *ohci, struct usb_device *dev,
211 static int ep_link(ohci_t * ohci, ed_t * ed);
212 static int ep_unlink(ohci_t * ohci, ed_t * ed);
271 static int sohci_get_current_frame_number(ohci_t *ohci);
276 static void pkt_print(ohci_t *ohci, urb_priv_t *purb, struct usb_device *dev, in pkt_print() argument
282 sohci_get_current_frame_number(ohci), in pkt_print()
317 void ep_print_int_eds(ohci_t *ohci, char *str) in ep_print_int_eds() argument
323 ed_p = &(ohci->hcca->int_table [i]); in ep_print_int_eds()
490 dbg("OHCI controller usb-%s state", controller->slot_name); in ohci_dump()
508 int sohci_submit_job(ohci_t *ohci, ohci_dev_t *ohci_dev, urb_priv_t *urb, in sohci_submit_job() argument
522 if (ohci->disabled) { in sohci_submit_job()
585 ep_link(ohci, ed); in sohci_submit_job()
588 td_submit_job(ohci, dev, pipe, buffer, transfer_len, in sohci_submit_job()
598 static int sohci_get_current_frame_number(ohci_t *ohci) in sohci_get_current_frame_number() argument
600 invalidate_dcache_hcca(ohci->hcca); in sohci_get_current_frame_number()
601 return m16_swap(ohci->hcca->frame_no); in sohci_get_current_frame_number()
614 static int ep_int_ballance(ohci_t *ohci, int interval, int load) in ep_int_ballance() argument
622 if (ohci->ohci_int_load [branch] > ohci->ohci_int_load [i]) in ep_int_ballance()
627 ohci->ohci_int_load [i] += load; in ep_int_ballance()
663 static int ep_link(ohci_t *ohci, ed_t *edi) in ep_link() argument
680 if (ohci->ed_controltail == NULL) in ep_link()
681 ohci_writel((uintptr_t)ed, &ohci->regs->ed_controlhead); in ep_link()
683 ohci->ed_controltail->hwNextED = in ep_link()
686 ed->ed_prev = ohci->ed_controltail; in ep_link()
687 if (!ohci->ed_controltail && !ohci->ed_rm_list[0] && in ep_link()
688 !ohci->ed_rm_list[1] && !ohci->sleeping) { in ep_link()
689 ohci->hc_control |= OHCI_CTRL_CLE; in ep_link()
690 ohci_writel(ohci->hc_control, &ohci->regs->control); in ep_link()
692 ohci->ed_controltail = edi; in ep_link()
698 if (ohci->ed_bulktail == NULL) in ep_link()
699 ohci_writel((uintptr_t)ed, &ohci->regs->ed_bulkhead); in ep_link()
701 ohci->ed_bulktail->hwNextED = in ep_link()
704 ed->ed_prev = ohci->ed_bulktail; in ep_link()
705 if (!ohci->ed_bulktail && !ohci->ed_rm_list[0] && in ep_link()
706 !ohci->ed_rm_list[1] && !ohci->sleeping) { in ep_link()
707 ohci->hc_control |= OHCI_CTRL_BLE; in ep_link()
708 ohci_writel(ohci->hc_control, &ohci->regs->control); in ep_link()
710 ohci->ed_bulktail = edi; in ep_link()
717 int_branch = ep_int_ballance(ohci, interval, load); in ep_link()
722 for (ed_p = &(ohci->hcca->int_table[\ in ep_link()
732 flush_dcache_hcca(ohci->hcca); in ep_link()
742 static void periodic_unlink(struct ohci *ohci, volatile struct ed *ed, in periodic_unlink() argument
748 __u32 *ed_p = &ohci->hcca->int_table [index]; in periodic_unlink()
772 static int ep_unlink(ohci_t *ohci, ed_t *edi) in ep_unlink() argument
784 ohci->hc_control &= ~OHCI_CTRL_CLE; in ep_unlink()
785 ohci_writel(ohci->hc_control, in ep_unlink()
786 &ohci->regs->control); in ep_unlink()
789 &ohci->regs->ed_controlhead); in ep_unlink()
794 if (ohci->ed_controltail == ed) { in ep_unlink()
795 ohci->ed_controltail = ed->ed_prev; in ep_unlink()
805 ohci->hc_control &= ~OHCI_CTRL_BLE; in ep_unlink()
806 ohci_writel(ohci->hc_control, in ep_unlink()
807 &ohci->regs->control); in ep_unlink()
810 &ohci->regs->ed_bulkhead); in ep_unlink()
815 if (ohci->ed_bulktail == ed) { in ep_unlink()
816 ohci->ed_bulktail = ed->ed_prev; in ep_unlink()
824 periodic_unlink(ohci, ed, 0, 1); in ep_unlink()
826 ohci->ohci_int_load[i] -= ed->int_load; in ep_unlink()
891 /* enqueue next TD for this URB (OHCI spec 5.2.8.2) */
893 static void td_fill(ohci_t *ohci, unsigned int info, in td_fill() argument
949 static void td_submit_job(ohci_t *ohci, struct usb_device *dev, in td_submit_job() argument
962 /* OHCI handles the DATA-toggles itself, we just use the USB-toggle in td_submit_job()
982 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), in td_submit_job()
988 td_fill(ohci, info | (cnt? TD_T_TOGGLE:toggle), data, in td_submit_job()
992 if (!ohci->sleeping) { in td_submit_job()
994 ohci_writel(OHCI_BLF, &ohci->regs->cmdstatus); in td_submit_job()
1002 td_fill(ohci, info, setup, 8, dev, cnt++, urb); in td_submit_job()
1010 td_fill(ohci, info, data, data_len, dev, cnt++, urb); in td_submit_job()
1017 td_fill(ohci, info, data, 0, dev, cnt++, urb); in td_submit_job()
1019 if (!ohci->sleeping) { in td_submit_job()
1021 ohci_writel(OHCI_CLF, &ohci->regs->cmdstatus); in td_submit_job()
1029 td_fill(ohci, info, data, data_len, dev, cnt++, urb); in td_submit_job()
1093 static td_t *dl_reverse_done_list(ohci_t *ohci) in dl_reverse_done_list() argument
1099 invalidate_dcache_hcca(ohci->hcca); in dl_reverse_done_list()
1100 td_list_hc = m32_swap(ohci->hcca->done_head) & 0xfffffff0; in dl_reverse_done_list()
1101 ohci->hcca->done_head = 0; in dl_reverse_done_list()
1102 flush_dcache_hcca(ohci->hcca); in dl_reverse_done_list()
1118 static void finish_urb(ohci_t *ohci, urb_priv_t *urb, int status) in finish_urb() argument
1132 static int takeback_td(ohci_t *ohci, td_t *td_list) in takeback_td() argument
1161 finish_urb(ohci, lurb_priv, ed->state); in takeback_td()
1173 ep_unlink(ohci, ed); in takeback_td()
1178 static int dl_done_list(ohci_t *ohci) in dl_done_list() argument
1181 td_t *td_list = dl_reverse_done_list(ohci); in dl_done_list()
1185 stat = takeback_td(ohci, td_list); in dl_done_list()
1204 &ohci->regs->roothub.status); }
1206 (x)); ohci_writel((x), &ohci->regs->roothub.portstatus[wIndex-1]); }
1208 #define WR_RH_STAT(x) ohci_writel((x), &ohci->regs->roothub.status)
1210 &ohci->regs->roothub.portstatus[wIndex-1])
1212 #define RD_RH_STAT roothub_status(ohci)
1213 #define RD_RH_PORTSTAT roothub_portstatus(ohci, wIndex-1)
1241 static int ohci_submit_rh_msg(ohci_t *ohci, struct usb_device *dev, in ohci_submit_rh_msg() argument
1256 pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, in ohci_submit_rh_msg()
1349 ohci->rh.devnum = wValue; in ohci_submit_rh_msg()
1394 __u32 temp = roothub_a(ohci); in ohci_submit_rh_msg()
1413 temp = roothub_b(ohci); in ohci_submit_rh_msg()
1442 ohci_dump_roothub(ohci, 1); in ohci_submit_rh_msg()
1454 pkt_print(ohci, NULL, dev, pipe, buffer, in ohci_submit_rh_msg()
1465 static ohci_dev_t *ohci_get_ohci_dev(ohci_t *ohci, int devnum, int intr) in ohci_get_ohci_dev() argument
1470 return &ohci->ohci_dev; in ohci_get_ohci_dev()
1474 if (ohci->int_dev[i].devnum == devnum) in ohci_get_ohci_dev()
1475 return &ohci->int_dev[i]; in ohci_get_ohci_dev()
1480 if (ohci->int_dev[i].devnum == -1) { in ohci_get_ohci_dev()
1481 ohci->int_dev[i].devnum = devnum; in ohci_get_ohci_dev()
1482 return &ohci->int_dev[i]; in ohci_get_ohci_dev()
1486 printf("ohci: Error out of ohci_devs for interrupt endpoints\n"); in ohci_get_ohci_dev()
1499 printf("ohci: Error out of memory allocating urb\n"); in ohci_alloc_urb()
1512 static int submit_common_msg(ohci_t *ohci, struct usb_device *dev, in submit_common_msg() argument
1528 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, in submit_common_msg()
1539 ohci_dev = ohci_get_ohci_dev(ohci, dev->devnum, usb_pipeint(pipe)); in submit_common_msg()
1543 if (sohci_submit_job(ohci, ohci_dev, urb, setup) < 0) { in submit_common_msg()
1550 /* ohci_dump_status(ohci); */ in submit_common_msg()
1558 stat = hc_interrupt(ohci); in submit_common_msg()
1600 pkt_print(ohci, urb, dev, pipe, buffer, transfer_len, in submit_common_msg()
1617 static struct int_queue *_ohci_create_int_queue(ohci_t *ohci, in _ohci_create_int_queue() argument
1628 ohci_dev = ohci_get_ohci_dev(ohci, udev->devnum, 1); in _ohci_create_int_queue()
1634 printf("ohci: Error out of memory allocating int queue\n"); in _ohci_create_int_queue()
1645 if (sohci_submit_job(ohci, ohci_dev, queue->urb[i], NULL)) { in _ohci_create_int_queue()
1646 printf("ohci: Error submitting int queue job\n"); in _ohci_create_int_queue()
1663 static void *_ohci_poll_int_queue(ohci_t *ohci, struct usb_device *udev, in _ohci_poll_int_queue() argument
1669 if (hc_interrupt(ohci) < 0) in _ohci_poll_int_queue()
1681 static int _ohci_destroy_int_queue(ohci_t *ohci, struct usb_device *dev, in _ohci_destroy_int_queue() argument
1731 static int _ohci_submit_control_msg(ohci_t *ohci, struct usb_device *dev, in _ohci_submit_control_msg() argument
1739 pkt_print(ohci, NULL, dev, pipe, buffer, transfer_len, in _ohci_submit_control_msg()
1749 if (((pipe >> 8) & 0x7f) == ohci->rh.devnum) { in _ohci_submit_control_msg()
1750 ohci->rh.dev = dev; in _ohci_submit_control_msg()
1752 return ohci_submit_rh_msg(ohci, dev, pipe, buffer, in _ohci_submit_control_msg()
1756 return submit_common_msg(ohci, dev, pipe, buffer, transfer_len, in _ohci_submit_control_msg()
1766 static int hc_reset(ohci_t *ohci) in hc_reset() argument
1800 if (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) { in hc_reset()
1802 ohci_writel(OHCI_OCR, &ohci->regs->cmdstatus); in hc_reset()
1804 while (ohci_readl(&ohci->regs->control) & OHCI_CTRL_IR) { in hc_reset()
1814 ohci_writel(OHCI_INTR_MIE, &ohci->regs->intrdisable); in hc_reset()
1817 ohci->slot_name, in hc_reset()
1818 ohci_readl(&ohci->regs->control)); in hc_reset()
1821 ohci->hc_control = 0; in hc_reset()
1822 ohci_writel(ohci->hc_control, &ohci->regs->control); in hc_reset()
1825 ohci_writel(OHCI_HCR, &ohci->regs->cmdstatus); in hc_reset()
1826 while ((ohci_readl(&ohci->regs->cmdstatus) & OHCI_HCR) != 0) { in hc_reset()
1838 /* Start an OHCI controller, set the BUS operational
1842 static int hc_start(ohci_t *ohci) in hc_start() argument
1848 ohci->disabled = 1; in hc_start()
1850 ohci->int_dev[i].devnum = -1; in hc_start()
1855 ohci_writel(0, &ohci->regs->ed_controlhead); in hc_start()
1856 ohci_writel(0, &ohci->regs->ed_bulkhead); in hc_start()
1858 ohci_writel((uintptr_t)ohci->hcca, in hc_start()
1859 &ohci->regs->hcca); /* reset clears this */ in hc_start()
1862 ohci_writel((fminterval * 9) / 10, &ohci->regs->periodicstart); in hc_start()
1864 ohci_writel(fminterval, &ohci->regs->fminterval); in hc_start()
1865 ohci_writel(0x628, &ohci->regs->lsthresh); in hc_start()
1868 ohci->hc_control = OHCI_CONTROL_INIT | OHCI_USB_OPER; in hc_start()
1869 ohci->disabled = 0; in hc_start()
1870 ohci_writel(ohci->hc_control, &ohci->regs->control); in hc_start()
1876 ohci_writel(mask, &ohci->regs->intrdisable); in hc_start()
1879 ohci_writel(mask, &ohci->regs->intrstatus); in hc_start()
1882 ohci_writel(mask, &ohci->regs->intrenable); in hc_start()
1886 ohci_writel((roothub_a(ohci) | RH_A_NPS) & ~RH_A_PSM, in hc_start()
1887 &ohci->regs->roothub.a); in hc_start()
1888 ohci_writel(RH_HS_LPSC, &ohci->regs->roothub.status); in hc_start()
1892 ohci->rh.devnum = 0; in hc_start()
1901 static int hc_interrupt(ohci_t *ohci) in hc_interrupt() argument
1903 struct ohci_regs *regs = ohci->regs; in hc_interrupt()
1907 invalidate_dcache_hcca(ohci->hcca); in hc_interrupt()
1909 if ((ohci->hcca->done_head != 0) && in hc_interrupt()
1910 !(m32_swap(ohci->hcca->done_head) & 0x01)) { in hc_interrupt()
1915 ohci->disabled++; in hc_interrupt()
1916 err("%s device removed!", ohci->slot_name); in hc_interrupt()
1928 le16_to_cpu(ohci->hcca->frame_no)); */ in hc_interrupt()
1934 ohci->disabled++; in hc_interrupt()
1935 err("OHCI Unrecoverable Error, controller usb-%s disabled", in hc_interrupt()
1936 ohci->slot_name); in hc_interrupt()
1940 ohci_dump(ohci, 1); in hc_interrupt()
1948 hc_reset(ohci); in hc_interrupt()
1956 stat = dl_done_list(ohci); in hc_interrupt()
1969 unsigned int frame = m16_swap(ohci->hcca->frame_no) & 1; in hc_interrupt()
1972 if (ohci->ed_rm_list[frame] != NULL) in hc_interrupt()
1989 static void hc_release_ohci(ohci_t *ohci) in hc_release_ohci() argument
1991 dbg("USB HC release ohci usb-%s", ohci->slot_name); in hc_release_ohci()
1993 if (!ohci->disabled) in hc_release_ohci()
1994 hc_reset(ohci); in hc_release_ohci()
2043 printf("OHCI pci controller (%04x, %04x) found @(%d:%d:%d)\n", in usb_lowlevel_init()
2047 printf("OHCI regs address 0x%08x\n", base); in usb_lowlevel_init()
2138 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_submit_control_msg() local
2140 return _ohci_submit_control_msg(ohci, udev, pipe, buffer, in ohci_submit_control_msg()
2147 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_submit_bulk_msg() local
2149 return submit_common_msg(ohci, udev, pipe, buffer, length, NULL, 0); in ohci_submit_bulk_msg()
2156 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_submit_int_msg() local
2158 return submit_common_msg(ohci, udev, pipe, buffer, length, in ohci_submit_int_msg()
2166 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_create_int_queue() local
2168 return _ohci_create_int_queue(ohci, udev, pipe, queuesize, elementsize, in ohci_create_int_queue()
2175 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_poll_int_queue() local
2177 return _ohci_poll_int_queue(ohci, udev, queue); in ohci_poll_int_queue()
2183 ohci_t *ohci = dev_get_priv(usb_get_bus(dev)); in ohci_destroy_int_queue() local
2185 return _ohci_destroy_int_queue(ohci, udev, queue); in ohci_destroy_int_queue()
2191 ohci_t *ohci = dev_get_priv(dev); in ohci_register() local
2196 ohci->regs = regs; in ohci_register()
2197 ohci->hcca = memalign(256, sizeof(struct ohci_hcca)); in ohci_register()
2198 if (!ohci->hcca) in ohci_register()
2200 memset(ohci->hcca, 0, sizeof(struct ohci_hcca)); in ohci_register()
2201 flush_dcache_hcca(ohci->hcca); in ohci_register()
2203 if (hc_reset(ohci) < 0) in ohci_register()
2206 if (hc_start(ohci) < 0) in ohci_register()
2210 printf("USB OHCI %x.%x\n", (reg >> 4) & 0xf, reg & 0xf); in ohci_register()
2217 ohci_t *ohci = dev_get_priv(dev); in ohci_deregister() local
2219 if (hc_reset(ohci) < 0) in ohci_deregister()
2222 free(ohci->hcca); in ohci_deregister()