No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hp700 / dev / sti_sgc.c
blobcf6b4093d0a66b74bf5f0917c8306c15af8e779b
1 /* $NetBSD: sti_sgc.c,v 1.17 2009/05/24 06:53:34 skrll Exp $ */
3 /* $OpenBSD: sti_sgc.c,v 1.21 2003/12/22 23:39:06 mickey Exp $ */
5 /*
6 * Copyright (c) 2000-2003 Michael Shalayeff
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
28 * THE POSSIBILITY OF SUCH DAMAGE.
31 * These cards has to be known to work so far:
32 * - HPA1991AGrayscale rev 0.02 (705/35) (byte-wide)
33 * - HPA1991AC19 rev 0.02 (715/33) (byte-wide)
34 * - HPA208LC1280 rev 8.04 (712/80) just works
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: sti_sgc.c,v 1.17 2009/05/24 06:53:34 skrll Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
44 #include <uvm/uvm.h>
46 #include <machine/bus.h>
47 #include <machine/cpu.h>
48 #include <machine/iomod.h>
49 #include <machine/autoconf.h>
51 #include <dev/wscons/wsdisplayvar.h>
52 #include <dev/wscons/wsconsio.h>
54 #include <dev/ic/stireg.h>
55 #include <dev/ic/stivar.h>
57 #include <hp700/dev/cpudevs.h>
58 #include <hp700/hp700/machdep.h>
60 #define STI_ROMSIZE (sizeof(struct sti_dd) * 4)
61 #define STI_ID_FDDI 0x280b31af /* Medusa FDDI ROM id */
63 /* gecko optional graphics */
64 #define STI_GOPT1_REV 0x17
65 #define STI_GOPT2_REV 0x70
66 #define STI_GOPT3_REV 0xd0
67 #define STI_GOPT4_REV 0x00
68 #define STI_GOPT5_REV 0x20
69 #define STI_GOPT6_REV 0x40
70 #define STI_GOPT7_REV 0x30
72 /* internal EG */
73 #define STI_INEG_REV 0x60
74 #define STI_INEG_PROM 0xf0011000
76 int sti_sgc_probe(device_t, cfdata_t, void *);
77 void sti_sgc_attach(device_t, device_t, void *);
79 CFATTACH_DECL_NEW(sti_gedoens, sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach,
80 NULL, NULL);
82 paddr_t sti_sgc_getrom(struct confargs *);
85 * Locate STI ROM.
86 * On some machines it may not be part of the HPA space.
88 paddr_t
89 sti_sgc_getrom(struct confargs *ca)
91 paddr_t rom;
92 int pagezero_cookie;
94 rom = ca->ca_hpa;
96 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC) {
97 return rom;
100 switch (ca->ca_type.iodc_revision) {
101 case STI_GOPT1_REV:
102 case STI_GOPT2_REV:
103 case STI_GOPT3_REV:
104 case STI_GOPT4_REV:
105 case STI_GOPT5_REV:
106 case STI_GOPT6_REV:
107 case STI_GOPT7_REV:
108 /* these share the onboard's prom */
109 pagezero_cookie = hp700_pagezero_map();
110 rom = PAGE0->pd_resv2[1];
111 hp700_pagezero_unmap(pagezero_cookie);
112 break;
114 case STI_INEG_REV:
115 rom = STI_INEG_PROM;
116 break;
118 return rom;
122 sti_sgc_probe(device_t parent, cfdata_t cf, void *aux)
124 struct confargs *ca = aux;
125 bus_space_handle_t romh;
126 paddr_t rom;
127 uint32_t id, romend;
128 u_char devtype;
129 int rv = 0, romunmapped = 0;
131 if (ca->ca_type.iodc_type != HPPA_TYPE_FIO)
132 return (0);
134 /* these need futher checking for the graphics id */
135 if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC &&
136 ca->ca_type.iodc_sv_model != HPPA_FIO_SGC)
137 return 0;
139 rom = sti_sgc_getrom(ca);
140 #ifdef STIDEBUG
141 printf ("sti: hpa=%x, rom=%x\n", (uint)ca->ca_hpa, (uint)rom);
142 #endif
144 /* if it does not map, probably part of the lasi space */
145 if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) {
146 #ifdef STIDEBUG
147 printf ("sti: can't map rom space (%d)\n", rv);
148 #endif
149 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) {
150 romh = rom;
151 romunmapped++;
152 } else {
153 /* in this case nobody has no freaking idea */
154 return 0;
158 devtype = bus_space_read_1(ca->ca_iot, romh, 3);
160 #ifdef STIDEBUG
161 printf("sti: devtype=%d\n", devtype);
162 #endif
163 rv = 1;
164 switch (devtype) {
165 case STI_DEVTYPE4:
166 id = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_GRID);
167 romend = bus_space_read_4(ca->ca_iot, romh, STI_DEV4_DD_ROMEND);
168 break;
169 case STI_DEVTYPE1:
170 id = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
171 + 3) << 24) |
172 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
173 + 7) << 16) |
174 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
175 + 11) << 8) |
176 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_GRID
177 + 15));
178 romend = (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND
179 + 3) << 24) |
180 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND
181 + 7) << 16) |
182 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND
183 + 11) << 8) |
184 (bus_space_read_1(ca->ca_iot, romh, STI_DEV1_DD_ROMEND
185 + 15));
186 break;
187 default:
188 #ifdef STIDEBUG
189 printf("sti: unknown type (%x)\n", devtype);
190 #endif
191 rv = 0;
192 romend = 0;
195 if (rv &&
196 ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) {
197 #ifdef STIDEBUG
198 printf("sti: not a graphics device\n");
199 #endif
200 rv = 0;
203 if (ca->ca_naddrs >= sizeof(ca->ca_addrs) / sizeof(ca->ca_addrs[0])) {
204 printf("sti: address list overflow\n");
205 return (0);
208 ca->ca_addrs[ca->ca_naddrs].addr = rom;
209 ca->ca_addrs[ca->ca_naddrs].size = round_page(romend);
210 ca->ca_naddrs++;
212 if (!romunmapped)
213 bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE);
214 return (rv);
217 void
218 sti_sgc_attach(device_t parent, device_t self, void *aux)
220 struct sti_softc *sc = device_private(self);
221 struct confargs *ca = aux;
222 paddr_t rom;
223 uint32_t romlen;
224 int rv;
225 int pagezero_cookie;
227 pagezero_cookie = hp700_pagezero_map();
228 sc->sc_dev = self;
229 sc->memt = sc->iot = ca->ca_iot;
230 sc->base = ca->ca_hpa;
232 /* we stashed rom addr/len into the last slot during probe */
233 rom = ca->ca_addrs[ca->ca_naddrs - 1].addr;
234 romlen = ca->ca_addrs[ca->ca_naddrs - 1].size;
235 if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &sc->romh))) {
236 if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN)
237 sc->romh = rom;
238 else {
239 aprint_error(": can't map rom space (%d)\n", rv);
240 return;
244 #ifdef HP7300LC_CPU
246 * PCXL2: enable accel I/O for this space, see PCX-L2 ERS "ACCEL_IO".
247 * "pcxl2_ers.{ps,pdf}", (section / chapter . rel. page / abs. page)
248 * 8.7.4 / 8-12 / 92, 11.3.14 / 11-14 / 122 and 14.8 / 14-5 / 203.
250 if (strcmp(hppa_cpu_info->hppa_cpu_info_chip_type, "PCX-L2") == 0
251 && ca->ca_hpa >= PCXL2_ACCEL_IO_START
252 && ca->ca_hpa <= PCXL2_ACCEL_IO_END)
253 eaio_l2(PCXL2_ACCEL_IO_ADDR2MASK(ca->ca_hpa));
254 #endif /* HP7300LC_CPU */
256 sc->sc_devtype = bus_space_read_1(sc->iot, sc->romh, 3);
257 if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
258 sc->sc_flags |= STI_CONSOLE;
259 hp700_pagezero_unmap(pagezero_cookie);
260 sti_attach_common(sc);