xref: /openbsd/sys/arch/hppa/dev/sti_sgc.c (revision 4cfece93)
1 /*	$OpenBSD: sti_sgc.c,v 1.40 2014/08/30 14:42:05 miod Exp $	*/
2 
3 /*
4  * Copyright (c) 2000-2003 Michael Shalayeff
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 AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR OR HIS RELATIVES BE LIABLE FOR ANY DIRECT,
20  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
25  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26  * THE POSSIBILITY OF SUCH DAMAGE.
27  */
28 /*
29  * These cards has to be known to work so far:
30  *	- HPA1991AGrayscale rev 0.02	(705/35) (byte-wide)
31  *	- HPA1991AC19       rev 0.02	(715/33) (byte-wide)
32  *	- HPA208LC1280      rev 8.04	(712/80) just works
33  */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/device.h>
38 
39 #include <machine/bus.h>
40 #include <machine/cpu.h>
41 #include <machine/iomod.h>
42 #include <machine/autoconf.h>
43 
44 #include <dev/wscons/wsdisplayvar.h>
45 #include <dev/wscons/wsconsio.h>
46 
47 #include <dev/ic/stireg.h>
48 #include <dev/ic/stivar.h>
49 
50 #include <hppa/dev/cpudevs.h>
51 
52 #define	STI_ROMSIZE	(sizeof(struct sti_dd) * 4)
53 #define	STI_ID_FDDI	0x280b31af	/* Medusa FDDI ROM id */
54 
55 /* gecko optional graphics (these share the onboard's prom) */
56 const char sti_sgc_opt[] = { 0x17, 0x20, 0x30, 0x40, 0x70, 0xc0, 0xd0 };
57 
58 extern struct cfdriver sti_cd;
59 
60 int	sti_sgc_probe(struct device *, void *, void *);
61 void	sti_sgc_attach(struct device *, struct device *, void *);
62 paddr_t	sti_sgc_getrom(int, struct confargs *);
63 
64 struct cfattach sti_gedoens_ca = {
65 	sizeof(struct sti_softc), sti_sgc_probe, sti_sgc_attach
66 };
67 
68 /*
69  * Locate STI ROM.
70  * On some machines it may not be part of the HPA space.
71  */
72 paddr_t
73 sti_sgc_getrom(int unit, struct confargs *ca)
74 {
75 	paddr_t rom = PAGE0->pd_resv2[1];
76 	int i;
77 
78 	if (unit) {
79 		i = -1;
80 		if (ca->ca_type.iodc_sv_model == HPPA_FIO_GSGC)
81 			for (i = sizeof(sti_sgc_opt); i-- &&
82 			    sti_sgc_opt[i] != ca->ca_type.iodc_revision; )
83 				;
84 		if (i < 0)
85 			rom = 0;
86 	}
87 
88 	if (rom < HPPA_IOBEGIN) {
89 		if (ca->ca_naddrs > 0)
90 			rom = ca->ca_addrs[0].addr;
91 		else
92 			rom = ca->ca_hpa;
93 	}
94 
95 	return (rom);
96 }
97 
98 int
99 sti_sgc_probe(struct device *parent, void *match, void *aux)
100 {
101 	struct cfdata *cf = match;
102 	struct confargs *ca = aux;
103 	bus_space_handle_t romh;
104 	paddr_t rom;
105 	u_int32_t id;
106 	u_char devtype;
107 	int rv = 0, romunmapped = 0;
108 
109 	/* due to the graphic nature of this program do probe only one */
110 	if (cf->cf_unit > sti_cd.cd_ndevs)
111 		return (0);
112 
113 	if (ca->ca_type.iodc_type != HPPA_TYPE_FIO)
114 		return (0);
115 
116 	/* these need further checking for the graphics id */
117 	if (ca->ca_type.iodc_sv_model != HPPA_FIO_GSGC &&
118 	    ca->ca_type.iodc_sv_model != HPPA_FIO_SGC)
119 		return 0;
120 
121 	rom = sti_sgc_getrom(cf->cf_unit, ca);
122 #ifdef STIDEBUG
123 	printf ("sti: hpa=%lx, rom=%lx\n", ca->ca_hpa, rom);
124 #endif
125 
126 	/* if it does not map, probably part of the lasi space */
127 	if ((rv = bus_space_map(ca->ca_iot, rom, STI_ROMSIZE, 0, &romh))) {
128 #ifdef STIDEBUG
129 		printf ("sti: cannot map rom space (%d)\n", rv);
130 #endif
131 		if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN) {
132 			romh = rom;
133 			romunmapped++;
134 		} else {
135 			/* in this case nobody has no freaking idea */
136 			return 0;
137 		}
138 	}
139 
140 	devtype = bus_space_read_1(ca->ca_iot, romh, 3);
141 
142 #ifdef STIDEBUG
143 	printf("sti: devtype=%d\n", devtype);
144 #endif
145 	rv = 1;
146 	switch (devtype) {
147 	case STI_DEVTYPE4:
148 		id = bus_space_read_4(ca->ca_iot, romh, 0x8);
149 		break;
150 	case STI_DEVTYPE1:
151 		id = (bus_space_read_1(ca->ca_iot, romh, 0x10 +  3) << 24) |
152 		     (bus_space_read_1(ca->ca_iot, romh, 0x10 +  7) << 16) |
153 		     (bus_space_read_1(ca->ca_iot, romh, 0x10 + 11) <<  8) |
154 		     (bus_space_read_1(ca->ca_iot, romh, 0x10 + 15));
155 		break;
156 	default:
157 #ifdef STIDEBUG
158 		printf("sti: unknown type (%x)\n", devtype);
159 #endif
160 		rv = 0;
161 	}
162 
163 	if (rv &&
164 	    ca->ca_type.iodc_sv_model == HPPA_FIO_SGC && id == STI_ID_FDDI) {
165 #ifdef STIDEBUG
166 		printf("sti: not a graphics device\n");
167 #endif
168 		rv = 0;
169 	}
170 
171 	if (ca->ca_naddrs >= sizeof(ca->ca_addrs)/sizeof(ca->ca_addrs[0])) {
172 		printf("sti: address list overflow\n");
173 		return (0);
174 	}
175 
176 	ca->ca_addrs[ca->ca_naddrs].addr = rom;
177 	ca->ca_addrs[ca->ca_naddrs].size = sti_rom_size(ca->ca_iot, romh);
178 	ca->ca_naddrs++;
179 
180 	if (!romunmapped)
181 		bus_space_unmap(ca->ca_iot, romh, STI_ROMSIZE);
182 	return (rv);
183 }
184 
185 void
186 sti_sgc_attach(struct device *parent, struct device *self, void *aux)
187 {
188 	struct sti_softc *sc = (void *)self;
189 	struct confargs *ca = aux;
190 	bus_space_handle_t romh;
191 	paddr_t rom;
192 	u_int32_t romlen;
193 	int rv;
194 	int i;
195 
196 	/* we stashed rom addr/len into the last slot during probe */
197 	rom = ca->ca_addrs[ca->ca_naddrs - 1].addr;
198 	romlen = ca->ca_addrs[ca->ca_naddrs - 1].size;
199 	if ((rv = bus_space_map(ca->ca_iot, rom, romlen, 0, &romh))) {
200 		if ((rom & HPPA_IOBEGIN) == HPPA_IOBEGIN)
201 			romh = rom;
202 		else {
203 			printf (": cannot map rom space (%d)\n", rv);
204 			return;
205 		}
206 	}
207 
208 	sc->bases[0] = romh;
209 	for (i = 1; i < STI_REGION_MAX; i++)
210 		sc->bases[i] = ca->ca_hpa;
211 
212 #ifdef	HP7300LC_CPU
213 	/* PCXL2: enable accel i/o for this space */
214 	if (cpu_type == hpcxl2)
215 		eaio_l2(0x8 >> (((ca->ca_hpa >> 25) & 3) - 2));
216 #endif
217 
218 	if (ca->ca_hpa == (hppa_hpa_t)PAGE0->mem_cons.pz_hpa)
219 		sc->sc_flags |= STI_CONSOLE;
220 	if (sti_attach_common(sc, ca->ca_iot, ca->ca_iot, romh,
221 	    STI_CODEBASE_PA) == 0)
222 		startuphook_establish(sti_end_attach, sc);
223 }
224