1 1.1 christos /* $NetBSD: slhci_tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $ */ 2 1.1 christos 3 1.1 christos /*- 4 1.1 christos * Copyright (c) 2016, Felix Deichmann 5 1.1 christos * All rights reserved. 6 1.1 christos * 7 1.1 christos * Redistribution and use in source and binary forms, with or without 8 1.1 christos * modification, are permitted provided that the following conditions 9 1.1 christos * are met: 10 1.1 christos * 1. Redistributions of source code must retain the above copyright 11 1.1 christos * notice, this list of conditions and the following disclaimer. 12 1.1 christos * 2. Redistributions in binary form must reproduce the above copyright 13 1.1 christos * notice, this list of conditions and the following disclaimer in the 14 1.1 christos * documentation and/or other materials provided with the distribution. 15 1.1 christos * 16 1.1 christos * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 1.1 christos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 1.1 christos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 1.1 christos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 1.1 christos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 1.1 christos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 1.1 christos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 1.1 christos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 1.1 christos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 1.1 christos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 1.1 christos * POSSIBILITY OF SUCH DAMAGE. 27 1.1 christos */ 28 1.1 christos 29 1.1 christos /* 30 1.1 christos * flxd TC-USB - TURBOchannel USB host option 31 1.1 christos */ 32 1.1 christos 33 1.1 christos #include <sys/cdefs.h> 34 1.1 christos __KERNEL_RCSID(0, "$NetBSD: slhci_tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $"); 35 1.1 christos 36 1.1 christos #include <sys/param.h> 37 1.1 christos #include <sys/systm.h> 38 1.1 christos #include <sys/device.h> 39 1.1 christos 40 1.1 christos #include <sys/bus.h> 41 1.1 christos 42 1.1 christos #include <dev/usb/usb.h> 43 1.1 christos #include <dev/usb/usbdi.h> 44 1.1 christos #include <dev/usb/usbdivar.h> 45 1.1 christos 46 1.1 christos #include <dev/ic/sl811hsreg.h> 47 1.1 christos #include <dev/ic/sl811hsvar.h> 48 1.1 christos 49 1.1 christos #include <dev/tc/tcvar.h> 50 1.1 christos 51 1.1 christos struct slhci_tcu_softc { 52 1.1 christos struct slhci_softc sc; 53 1.1 christos }; 54 1.1 christos 55 1.1 christos static int slhci_tcu_match(device_t, cfdata_t, void *); 56 1.1 christos static void slhci_tcu_attach(device_t, device_t, void *); 57 1.1 christos 58 1.1 christos CFATTACH_DECL_NEW(slhci_tcu, sizeof(struct slhci_tcu_softc), 59 1.1 christos slhci_tcu_match, slhci_tcu_attach, NULL, slhci_activate); 60 1.1 christos 61 1.1 christos static int 62 1.1 christos slhci_tcu_match(device_t parent, cfdata_t cf, void *aux) 63 1.1 christos { 64 1.1 christos 65 1.1 christos /* Always match. */ 66 1.1 christos return 1; 67 1.1 christos } 68 1.1 christos 69 1.1 christos #define SLHCI_TCU_STRIDE 4 70 1.1 christos #define SLHCI_TCU_IMAX 500 /* mA */ 71 1.1 christos 72 1.1 christos static void 73 1.1 christos slhci_tcu_attach(device_t parent, device_t self, void *aux) 74 1.1 christos { 75 1.1 christos struct slhci_tcu_softc *tsc = device_private(self); 76 1.1 christos struct slhci_softc *sc = &tsc->sc; 77 1.1 christos struct tc_attach_args *ta = aux; 78 1.1 christos bus_space_tag_t iot = ta->ta_memt; 79 1.1 christos bus_space_handle_t ioh; 80 1.1 christos int error; 81 1.1 christos 82 1.1 christos sc->sc_dev = self; 83 1.1 christos sc->sc_bus.ub_hcpriv = sc; 84 1.1 christos 85 1.1 christos aprint_normal("\n"); 86 1.1 christos 87 1.1 christos error = bus_space_map(iot, ta->ta_addr, 88 1.1 christos SLHCI_TCU_STRIDE * SL11_PORTSIZE, 0, &ioh); 89 1.1 christos if (error) { 90 1.1 christos aprint_error_dev(self, "bus_space_map() failed (%d)\n", error); 91 1.1 christos return; 92 1.1 christos } 93 1.1 christos 94 1.1 christos slhci_preinit(sc, NULL, iot, ioh, SLHCI_TCU_IMAX, SLHCI_TCU_STRIDE); 95 1.1 christos 96 1.1 christos tc_intr_establish(device_parent(parent), ta->ta_cookie, IPL_USB, 97 1.1 christos slhci_intr, sc); 98 1.1 christos 99 1.1 christos if (slhci_attach(sc)) 100 1.1 christos aprint_error_dev(self, "slhci_attach() failed\n"); 101 1.1 christos } 102