slhci_zbus.c revision 1.1 1 /* $NetBSD: slhci_zbus.c,v 1.1 2013/04/27 22:27:33 rkujawa Exp $ */
2
3 /*-
4 * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Radoslaw Kujawa.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: slhci_zbus.c,v 1.1 2013/04/27 22:27:33 rkujawa Exp $");
34
35 /*
36 * Thylacine driver.
37 * Inspired by slhci_intio.c.
38 */
39
40 #include <sys/param.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43 #include <sys/systm.h>
44 #include <sys/bus.h>
45
46 #include <amiga/amiga/device.h>
47 #include <amiga/amiga/isr.h>
48
49 #include <amiga/dev/zbusvar.h>
50
51 #include <dev/usb/usb.h>
52 #include <dev/usb/usbdi.h>
53 #include <dev/usb/usbdivar.h>
54
55 #include <dev/ic/sl811hsreg.h>
56 #include <dev/ic/sl811hsvar.h>
57
58 #define THYLACINE_SLHCI_PWR_OFFSET 0x100
59 #define THYLACINE_SLHCI_ADDR_OFFSET 0x1
60 #define THYLACINE_SLHCI_DATA_STRIDE 0x4000
61 #define THYLACINE_SIZE 0x8000
62
63 static int slhci_zbus_match(device_t, cfdata_t , void *);
64 static void slhci_zbus_attach(device_t, device_t, void *);
65 static void slhci_zbus_enable_power(void *, enum power_change);
66
67 struct slhci_zbus_softc {
68 struct slhci_softc sc_sc;
69
70 struct bus_space_tag sc_bst;
71 struct isr sc_isr;
72 };
73
74 CFATTACH_DECL_NEW(slhci_zbus, sizeof(struct slhci_zbus_softc),
75 slhci_zbus_match, slhci_zbus_attach, NULL, NULL);
76
77 static int
78 slhci_zbus_match(device_t parent, cfdata_t cf, void *aux)
79 {
80 struct zbus_args *zap = aux;
81
82 /* Thylacine */
83 if (zap->manid == 0x1392 && zap->prodid == 0x1) {
84 return 1;
85 }
86
87 return 0;
88 }
89
90 static void
91 slhci_zbus_attach(device_t parent, device_t self, void *aux)
92 {
93 struct slhci_zbus_softc *zsc;
94 struct slhci_softc *sc;
95 struct zbus_args *zap;
96 bus_space_tag_t iot;
97 bus_space_handle_t ioh;
98
99 zap = aux;
100 zsc = device_private(self);
101 sc = &zsc->sc_sc;
102 sc->sc_dev = self;
103 sc->sc_bus.hci_private = sc;
104
105 zsc->sc_bst.base = (bus_addr_t)zap->va;
106 zsc->sc_bst.absm = &amiga_bus_stride_1;
107 iot = &zsc->sc_bst;
108
109 aprint_normal(": Thylacine USB Host Controller\n");
110
111 if (bus_space_map(iot, THYLACINE_SLHCI_ADDR_OFFSET, THYLACINE_SIZE, 0,
112 &ioh)) {
113 aprint_error_dev(sc->sc_dev, "can't map the bus\n");
114 }
115
116 slhci_preinit(sc, slhci_zbus_enable_power, iot, ioh, 500,
117 THYLACINE_SLHCI_DATA_STRIDE);
118
119 /* Attach interrupt routine. */
120 zsc->sc_isr.isr_intr = slhci_intr;
121 zsc->sc_isr.isr_arg = sc;
122 zsc->sc_isr.isr_ipl = 6;
123 add_isr(&zsc->sc_isr);
124
125 slhci_attach(sc);
126
127 }
128
129 static void
130 slhci_zbus_enable_power(void *arg, enum power_change mode)
131 {
132 struct slhci_zbus_softc *zsc = arg;
133
134 /*
135 * The hardware is dumb. Changing power mode depends only on A8 being
136 * low or high.
137 */
138 if (mode == POWER_ON)
139 bus_space_read_1(zsc->sc_sc.sc_iot, zsc->sc_sc.sc_ioh,
140 THYLACINE_SLHCI_DATA_STRIDE);
141 else
142 bus_space_read_1(zsc->sc_sc.sc_iot, zsc->sc_sc.sc_ioh,
143 THYLACINE_SLHCI_PWR_OFFSET);
144 }
145
146