1 // Code for handling OHCI USB controllers.
3 // Copyright (C) 2009 Kevin O'Connor <kevin@koconnor.net>
5 // This file may be distributed under the terms of the GNU LGPLv3 license.
7 #include "util.h" // dprintf
8 #include "pci.h" // pci_bdf_to_bus
9 #include "config.h" // CONFIG_*
10 #include "ioport.h" // outw
11 #include "usb-ohci.h" // USBLEGSUP
12 #include "pci_regs.h" // PCI_BASE_ADDRESS_4
13 #include "usb.h" // struct usb_s
14 #include "farptr.h" // GET_FLATPTR
15 #include "biosvar.h" // GET_GLOBAL
18 reset_ohci(struct usb_s *cntl)
23 configure_ohci(struct usb_s *cntl)
25 // XXX - check for SMM control?
27 writel(&cntl->ohci.regs->intrdisable, OHCI_INTR_MIE);
29 struct ohci_hcca *hcca = memalign_low(256, sizeof(*hcca));
31 dprintf(1, "No ram for ohci init\n");
39 start_ohci(struct usb_s *cntl)
43 // Find any devices connected to the root hub.
45 check_ohci_ports(struct usb_s *cntl)
51 ohci_init(struct usb_s *cntl)
53 if (! CONFIG_USB_OHCI)
56 cntl->type = USB_TYPE_OHCI;
57 u32 baseaddr = pci_config_readl(cntl->bdf, PCI_BASE_ADDRESS_0);
58 cntl->ohci.regs = (void*)(baseaddr & PCI_BASE_ADDRESS_MEM_MASK);
60 dprintf(3, "OHCI init on dev %02x:%02x.%x (regs=%p)\n"
61 , pci_bdf_to_bus(cntl->bdf), pci_bdf_to_dev(cntl->bdf)
62 , pci_bdf_to_fn(cntl->bdf), cntl->ohci.regs);
64 // Enable bus mastering and memory access.
65 pci_config_maskw(cntl->bdf, PCI_COMMAND
66 , 0, PCI_COMMAND_MASTER|PCI_COMMAND_MEMORY);
72 int count = check_ohci_ports(cntl);
74 // XXX - no devices; free data structures.
82 ohci_control(u32 endp, int dir, const void *cmd, int cmdsize
83 , void *data, int datasize)
85 if (! CONFIG_USB_OHCI)
88 dprintf(5, "ohci_control %x\n", endp);
93 ohci_alloc_intr_pipe(u32 endp, int period)
95 if (! CONFIG_USB_OHCI)
98 dprintf(7, "ohci_alloc_intr_pipe %x %d\n", endp, period);
103 ohci_poll_intr(void *pipe, void *data)
106 if (! CONFIG_USB_OHCI)