1 /* $OpenBSD: octohci.c,v 1.1 2016/03/18 05:38:10 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 <dev/usb/ohcireg.h> 36 #include <dev/usb/ohcivar.h> 37 38 struct octohci_softc { 39 struct ohci_softc sc_ohci; 40 41 void *sc_ih; 42 }; 43 44 int octohci_match(struct device *, void *, void *); 45 void octohci_attach(struct device *, struct device *, void *); 46 void octohci_attach_deferred(struct device *); 47 48 const struct cfattach octohci_ca = { 49 sizeof(struct octohci_softc), octohci_match, octohci_attach, 50 }; 51 52 struct cfdriver octohci_cd = { 53 NULL, "ohci", DV_DULL 54 }; 55 56 int 57 octohci_match(struct device *parent, void *match, void *aux) 58 { 59 struct octuctl_attach_args *aa = aux; 60 61 if (strcmp(aa->aa_name, "ohci") != 0) 62 return (0); 63 64 return (1); 65 } 66 67 void 68 octohci_attach(struct device *parent, struct device *self, void *aux) 69 { 70 struct octohci_softc *sc = (struct octohci_softc *)self; 71 struct octuctl_attach_args *aa = aux; 72 char *devname; 73 uint64_t port_ctl; 74 int rc; 75 int s; 76 77 sc->sc_ohci.iot = aa->aa_bust; 78 sc->sc_ohci.sc_bus.pipe_size = sizeof(struct usbd_pipe); 79 sc->sc_ohci.sc_bus.dmatag = aa->aa_dmat; 80 81 rc = bus_space_map(sc->sc_ohci.iot, UCTL_OHCI_BASE, UCTL_OHCI_SIZE, 82 0, &sc->sc_ohci.ioh); 83 KASSERT(rc == 0); 84 85 port_ctl = bus_space_read_8(aa->aa_octuctl_bust, aa->aa_ioh, 86 UCTL_OHCI_CTL); 87 port_ctl &= ~UCTL_OHCI_CTL_L2C_ADDR_MSB_MASK; 88 port_ctl |= (1 << UCTL_OHCI_CTL_L2C_DESC_EMOD_SHIFT); 89 port_ctl |= (1 << UCTL_OHCI_CTL_L2C_BUFF_EMOD_SHIFT); 90 bus_space_write_8(aa->aa_octuctl_bust, aa->aa_ioh, UCTL_OHCI_CTL, 91 port_ctl); 92 93 s = splusb(); 94 95 sc->sc_ohci.sc_id_vendor = 0; 96 strlcpy(sc->sc_ohci.sc_vendor, "Octeon", sizeof(sc->sc_ohci.sc_vendor)); 97 98 sc->sc_ih = octeon_intr_establish(CIU_INT_USB, IPL_USB, ohci_intr, 99 (void *)&sc->sc_ohci, devname); 100 KASSERT(sc->sc_ih != NULL); 101 102 if ((ohci_checkrev(&sc->sc_ohci) != USBD_NORMAL_COMPLETION) || 103 (ohci_handover(&sc->sc_ohci) != USBD_NORMAL_COMPLETION)) 104 goto failed; 105 106 /* ignore interrupts for now */ 107 sc->sc_ohci.sc_bus.dying = 1; 108 config_defer(self, octohci_attach_deferred); 109 110 splx(s); 111 return; 112 113 failed: 114 octeon_intr_disestablish(sc->sc_ih); 115 bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh, UCTL_OHCI_SIZE); 116 splx(s); 117 return; 118 } 119 120 void 121 octohci_attach_deferred(struct device *self) 122 { 123 struct octohci_softc *sc = (struct octohci_softc *)self; 124 usbd_status r; 125 int s; 126 127 s = splusb(); 128 sc->sc_ohci.sc_bus.dying = 0; 129 130 r = ohci_init(&sc->sc_ohci); 131 splx(s); 132 133 if (r != USBD_NORMAL_COMPLETION) { 134 printf("%s: init failed, error=%d\n", 135 sc->sc_ohci.sc_bus.bdev.dv_xname, r); 136 octeon_intr_disestablish(sc->sc_ih); 137 bus_space_unmap(sc->sc_ohci.iot, sc->sc_ohci.ioh, 138 UCTL_OHCI_SIZE); 139 } else { 140 config_found(self, &sc->sc_ohci.sc_bus, usbctlprint); 141 } 142 } 143