sti_sgc.c revision 1.1 1 1.1 tsutsui /* $NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $ */
2 1.1 tsutsui /* $OpenBSD: sti_sgc.c,v 1.14 2007/05/26 00:36:03 krw Exp $ */
3 1.1 tsutsui
4 1.1 tsutsui /*
5 1.1 tsutsui * Copyright (c) 2005, Miodrag Vallat
6 1.1 tsutsui *
7 1.1 tsutsui * Redistribution and use in source and binary forms, with or without
8 1.1 tsutsui * modification, are permitted provided that the following conditions
9 1.1 tsutsui * are met:
10 1.1 tsutsui * 1. Redistributions of source code must retain the above copyright
11 1.1 tsutsui * notice, this list of conditions and the following disclaimer.
12 1.1 tsutsui * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 tsutsui * notice, this list of conditions and the following disclaimer in the
14 1.1 tsutsui * documentation and/or other materials provided with the distribution.
15 1.1 tsutsui *
16 1.1 tsutsui * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 tsutsui * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 1.1 tsutsui * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 1.1 tsutsui * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
20 1.1 tsutsui * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 1.1 tsutsui * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 1.1 tsutsui * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 1.1 tsutsui * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 1.1 tsutsui * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
25 1.1 tsutsui * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 1.1 tsutsui * POSSIBILITY OF SUCH DAMAGE.
27 1.1 tsutsui *
28 1.1 tsutsui */
29 1.1 tsutsui #include <sys/cdefs.h>
30 1.1 tsutsui __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.1 2013/01/11 12:03:03 tsutsui Exp $");
31 1.1 tsutsui
32 1.1 tsutsui #include <sys/param.h>
33 1.1 tsutsui #include <sys/device.h>
34 1.1 tsutsui #include <sys/bus.h>
35 1.1 tsutsui
36 1.1 tsutsui #include <uvm/uvm_extern.h>
37 1.1 tsutsui
38 1.1 tsutsui #include <dev/wscons/wsdisplayvar.h>
39 1.1 tsutsui
40 1.1 tsutsui #include <dev/ic/stireg.h>
41 1.1 tsutsui #include <dev/ic/stivar.h>
42 1.1 tsutsui
43 1.1 tsutsui #include <hp300/dev/sgcvar.h>
44 1.1 tsutsui
45 1.1 tsutsui static int sticonslot;
46 1.1 tsutsui
47 1.1 tsutsui static int sti_sgc_match(device_t, struct cfdata *, void *);
48 1.1 tsutsui static void sti_sgc_attach(device_t, device_t, void *);
49 1.1 tsutsui
50 1.1 tsutsui static int sti_sgc_probe(bus_space_tag_t, int);
51 1.1 tsutsui static void sti_sgc_end_attach(device_t);
52 1.1 tsutsui
53 1.1 tsutsui CFATTACH_DECL_NEW(sti_sgc, sizeof(struct sti_softc),
54 1.1 tsutsui sti_sgc_match, sti_sgc_attach, NULL, NULL);
55 1.1 tsutsui
56 1.1 tsutsui static int
57 1.1 tsutsui sti_sgc_match(device_t parent, struct cfdata *cf, void *aux)
58 1.1 tsutsui {
59 1.1 tsutsui struct sgc_attach_args *saa = aux;
60 1.1 tsutsui
61 1.1 tsutsui /*
62 1.1 tsutsui * If we already probed it successfully as a console device, go ahead,
63 1.1 tsutsui * since we will not be able to bus_space_map() again.
64 1.1 tsutsui */
65 1.1 tsutsui if (saa->saa_slot == sticonslot)
66 1.1 tsutsui return 1;
67 1.1 tsutsui
68 1.1 tsutsui return sti_sgc_probe(saa->saa_iot, saa->saa_slot);
69 1.1 tsutsui }
70 1.1 tsutsui
71 1.1 tsutsui static void
72 1.1 tsutsui sti_sgc_attach(device_t parent, device_t self, void *aux)
73 1.1 tsutsui {
74 1.1 tsutsui struct sti_softc *sc = device_private(self);
75 1.1 tsutsui struct sgc_attach_args *saa = aux;
76 1.1 tsutsui bus_space_tag_t iot = saa->saa_iot;
77 1.1 tsutsui bus_space_handle_t ioh, romh;
78 1.1 tsutsui bus_addr_t pa = (bus_addr_t)sgc_slottopa(saa->saa_slot);
79 1.1 tsutsui u_int romend;
80 1.1 tsutsui int i;
81 1.1 tsutsui
82 1.1 tsutsui /* XXX: temporalily map before obtain romend. */
83 1.1 tsutsui #define STI_ROMSIZE_SAFE (sizeof(struct sti_dd) * 4)
84 1.1 tsutsui if (bus_space_map(iot, pa, STI_ROMSIZE_SAFE, 0, &ioh)) {
85 1.1 tsutsui aprint_error(": can't map ROM");
86 1.1 tsutsui return;
87 1.1 tsutsui }
88 1.1 tsutsui romend = sti_rom_size(iot, ioh);
89 1.1 tsutsui bus_space_unmap(iot, ioh, STI_ROMSIZE_SAFE);
90 1.1 tsutsui
91 1.1 tsutsui sc->sc_dev = self;
92 1.1 tsutsui sc->sc_enable_rom = NULL;
93 1.1 tsutsui sc->sc_disable_rom = NULL;
94 1.1 tsutsui
95 1.1 tsutsui if (bus_space_map(iot, pa, romend, 0, &romh)) {
96 1.1 tsutsui aprint_error(": can't map ROM(2)");
97 1.1 tsutsui return;
98 1.1 tsutsui }
99 1.1 tsutsui sc->bases[0] = romh;
100 1.1 tsutsui for (i = 0; i < STI_REGION_MAX; i++)
101 1.1 tsutsui sc->bases[i] = pa;
102 1.1 tsutsui if (saa->saa_slot == sticonslot)
103 1.1 tsutsui sc->sc_flags |= STI_CONSOLE;
104 1.1 tsutsui if (sti_attach_common(sc, iot, iot, romh, STI_CODEBASE_ALT) == 0)
105 1.1 tsutsui config_interrupts(self, sti_sgc_end_attach);
106 1.1 tsutsui }
107 1.1 tsutsui
108 1.1 tsutsui static int
109 1.1 tsutsui sti_sgc_probe(bus_space_tag_t iot, int slot)
110 1.1 tsutsui {
111 1.1 tsutsui bus_space_handle_t ioh;
112 1.1 tsutsui bus_addr_t pa = (bus_addr_t)sgc_slottopa(slot);
113 1.1 tsutsui int devtype;
114 1.1 tsutsui
115 1.1 tsutsui if (bus_space_map(iot, pa, PAGE_SIZE, 0, &ioh))
116 1.1 tsutsui return 0;
117 1.1 tsutsui devtype = bus_space_read_1(iot, ioh, 3);
118 1.1 tsutsui bus_space_unmap(iot, ioh, PAGE_SIZE);
119 1.1 tsutsui
120 1.1 tsutsui /*
121 1.1 tsutsui * This might not be reliable enough. On the other hand, non-STI
122 1.1 tsutsui * SGC cards will apparently not initialize in an hp300, to the
123 1.1 tsutsui * point of not even answering bus probes (checked with an
124 1.1 tsutsui * Harmony/FDDI SGC card).
125 1.1 tsutsui */
126 1.1 tsutsui if (devtype != STI_DEVTYPE1 &&
127 1.1 tsutsui devtype != STI_DEVTYPE4)
128 1.1 tsutsui return 0;
129 1.1 tsutsui return 1;
130 1.1 tsutsui }
131 1.1 tsutsui
132 1.1 tsutsui static void
133 1.1 tsutsui sti_sgc_end_attach(device_t self)
134 1.1 tsutsui {
135 1.1 tsutsui struct sti_softc *sc = device_private(self);
136 1.1 tsutsui
137 1.1 tsutsui sti_end_attach(sc);
138 1.1 tsutsui }
139