1 /* $OpenBSD: octehci.c,v 1.3 2017/07/25 11:01:28 jmatthew Exp $ */ 2 3 /* 4 * Copyright (c) 2015 Jonathan Matthew <jmatthew@openbsd.org> 5 * 6 * Permission to use, copy, modify, and/or distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #include <sys/param.h> 20 #include <sys/systm.h> 21 #include <sys/device.h> 22 23 #include <machine/intr.h> 24 #include <machine/bus.h> 25 #include <machine/octeonreg.h> 26 #include <machine/octeonvar.h> 27 28 #include <octeon/dev/octuctlreg.h> 29 #include <octeon/dev/octuctlvar.h> 30 31 #include <dev/usb/usb.h> 32 #include <dev/usb/usbdi.h> 33 #include <dev/usb/usbdivar.h> 34 35 #include <sys/rwlock.h> 36 #include <dev/usb/ehcireg.h> 37 #include <dev/usb/ehcivar.h> 38 39 struct octehci_softc { 40 struct ehci_softc sc_ehci; 41 42 void *sc_ih; 43 }; 44 45 int octehci_match(struct device *, void *, void *); 46 void octehci_attach(struct device *, struct device *, void *); 47 48 const struct cfattach octehci_ca = { 49 sizeof(struct octehci_softc), octehci_match, octehci_attach, 50 }; 51 52 struct cfdriver octehci_cd = { 53 NULL, "ehci", DV_DULL 54 }; 55 56 int 57 octehci_match(struct device *parent, void *match, void *aux) 58 { 59 struct octuctl_attach_args *aa = aux; 60 return (OF_is_compatible(aa->aa_node, "cavium,octeon-6335-ehci")); 61 } 62 63 void 64 octehci_attach(struct device *parent, struct device *self, void *aux) 65 { 66 struct octehci_softc *sc = (struct octehci_softc *)self; 67 struct octuctl_attach_args *aa = aux; 68 uint64_t port_ctl; 69 int rc; 70 int s; 71 72 sc->sc_ehci.iot = aa->aa_bust; 73 sc->sc_ehci.sc_bus.pipe_size = sizeof(struct usbd_pipe); 74 sc->sc_ehci.sc_bus.dmatag = aa->aa_dmat; 75 76 rc = bus_space_map(sc->sc_ehci.iot, aa->aa_reg.addr, aa->aa_reg.size, 77 0, &sc->sc_ehci.ioh); 78 KASSERT(rc == 0); 79 80 port_ctl = bus_space_read_8(aa->aa_octuctl_bust, aa->aa_ioh, 81 UCTL_EHCI_CTL); 82 port_ctl &= ~UCTL_EHCI_CTL_L2C_ADDR_MSB_MASK; 83 port_ctl |= (1 << UCTL_EHCI_CTL_L2C_DESC_EMOD_SHIFT); 84 port_ctl |= (1 << UCTL_EHCI_CTL_L2C_BUFF_EMOD_SHIFT); 85 port_ctl |= UCTL_EHCI_CTL_EHCI_64B_ADDR_EN; 86 bus_space_write_8(aa->aa_octuctl_bust, aa->aa_ioh, UCTL_EHCI_CTL, 87 port_ctl); 88 89 s = splhardusb(); 90 sc->sc_ehci.sc_offs = EREAD1(&sc->sc_ehci, EHCI_CAPLENGTH); 91 EOWRITE2(&sc->sc_ehci, EHCI_USBINTR, 0); 92 93 sc->sc_ehci.sc_id_vendor = 0; 94 strlcpy(sc->sc_ehci.sc_vendor, "Octeon", sizeof(sc->sc_ehci.sc_vendor)); 95 96 sc->sc_ih = octeon_intr_establish(CIU_INT_USB, IPL_USB | IPL_MPSAFE, 97 ehci_intr, (void *)&sc->sc_ehci, sc->sc_ehci.sc_bus.bdev.dv_xname); 98 KASSERT(sc->sc_ih != NULL); 99 100 rc = ehci_init(&sc->sc_ehci); 101 if (rc != USBD_NORMAL_COMPLETION) { 102 printf(": init failed, error=%d\n", rc); 103 octeon_intr_disestablish(sc->sc_ih); 104 bus_space_unmap(sc->sc_ehci.iot, sc->sc_ehci.ioh, 105 aa->aa_reg.size); 106 splx(s); 107 return; 108 } 109 110 printf("\n"); 111 if (rc == 0) 112 config_found(self, &sc->sc_ehci.sc_bus, usbctlprint); 113 splx(s); 114 } 115