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