light.c revision 1.4.4.2 1 1.4.4.2 ad /* $Id: light.c,v 1.4.4.2 2007/01/12 01:00:57 ad Exp $ */
2 1.4.4.2 ad
3 1.4.4.2 ad /*
4 1.4.4.2 ad * Copyright (c) 2006 Stephen M. Rumble
5 1.4.4.2 ad * Copyright (c) 2003 Ilpo Ruotsalainen
6 1.4.4.2 ad * All rights reserved.
7 1.4.4.2 ad *
8 1.4.4.2 ad * Redistribution and use in source and binary forms, with or without
9 1.4.4.2 ad * modification, are permitted provided that the following conditions
10 1.4.4.2 ad * are met:
11 1.4.4.2 ad * 1. Redistributions of source code must retain the above copyright
12 1.4.4.2 ad * notice, this list of conditions and the following disclaimer.
13 1.4.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
14 1.4.4.2 ad * notice, this list of conditions and the following disclaimer in the
15 1.4.4.2 ad * documentation and/or other materials provided with the distribution.
16 1.4.4.2 ad * 3. The name of the author may not be used to endorse or promote products
17 1.4.4.2 ad * derived from this software without specific prior written permission.
18 1.4.4.2 ad *
19 1.4.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 1.4.4.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 1.4.4.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 1.4.4.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.4.4.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 1.4.4.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 1.4.4.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 1.4.4.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 1.4.4.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 1.4.4.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 1.4.4.2 ad *
30 1.4.4.2 ad * <<Id: LICENSE_GC,v 1.1 2001/10/01 23:24:05 cgd Exp>>
31 1.4.4.2 ad */
32 1.4.4.2 ad
33 1.4.4.2 ad /*
34 1.4.4.2 ad * SGI "Light" graphics, a.k.a. "Entry", "Starter", "LG1", and "LG2".
35 1.4.4.2 ad *
36 1.4.4.2 ad * 1024x768 8bpp at 60Hz.
37 1.4.4.2 ad *
38 1.4.4.2 ad * This driver supports the boards found in Indigo R3k and R4k machines.
39 1.4.4.2 ad * There is a Crimson variant, but the register offsets differ significantly.
40 1.4.4.2 ad *
41 1.4.4.2 ad * Light's REX chip is the precursor of the REX3 found in "newport", hence
42 1.4.4.2 ad * much similarity exists.
43 1.4.4.2 ad */
44 1.4.4.2 ad
45 1.4.4.2 ad #include <sys/cdefs.h>
46 1.4.4.2 ad __KERNEL_RCSID(0, "$NetBSD: light.c,v 1.4.4.2 2007/01/12 01:00:57 ad Exp $");
47 1.4.4.2 ad
48 1.4.4.2 ad #include <sys/param.h>
49 1.4.4.2 ad #include <sys/systm.h>
50 1.4.4.2 ad #include <sys/device.h>
51 1.4.4.2 ad #include <sys/malloc.h>
52 1.4.4.2 ad
53 1.4.4.2 ad #include <machine/sysconf.h>
54 1.4.4.2 ad
55 1.4.4.2 ad #include <dev/wscons/wsconsio.h>
56 1.4.4.2 ad #include <dev/wscons/wsdisplayvar.h>
57 1.4.4.2 ad #include <dev/wsfont/wsfont.h>
58 1.4.4.2 ad
59 1.4.4.2 ad #include <sgimips/gio/giovar.h>
60 1.4.4.2 ad #include <sgimips/gio/lightvar.h>
61 1.4.4.2 ad #include <sgimips/gio/lightreg.h>
62 1.4.4.2 ad
63 1.4.4.2 ad struct light_softc {
64 1.4.4.2 ad struct device sc_dev;
65 1.4.4.2 ad
66 1.4.4.2 ad struct light_devconfig *sc_dc;
67 1.4.4.2 ad };
68 1.4.4.2 ad
69 1.4.4.2 ad struct light_devconfig {
70 1.4.4.2 ad uint32_t dc_addr;
71 1.4.4.2 ad
72 1.4.4.2 ad bus_space_tag_t dc_st;
73 1.4.4.2 ad bus_space_handle_t dc_sh;
74 1.4.4.2 ad
75 1.4.4.2 ad int dc_boardrev;
76 1.4.4.2 ad int dc_font;
77 1.4.4.2 ad struct wsdisplay_font *dc_fontdata;
78 1.4.4.2 ad };
79 1.4.4.2 ad
80 1.4.4.2 ad /* always 1024x768x8 */
81 1.4.4.2 ad #define LIGHT_XRES 1024
82 1.4.4.2 ad #define LIGHT_YRES 768
83 1.4.4.2 ad #define LIGHT_DEPTH 8
84 1.4.4.2 ad
85 1.4.4.2 ad static int light_match(struct device *, struct cfdata *, void *);
86 1.4.4.2 ad static void light_attach(struct device *, struct device *, void *);
87 1.4.4.2 ad
88 1.4.4.2 ad CFATTACH_DECL(light, sizeof(struct light_softc), light_match, light_attach,
89 1.4.4.2 ad NULL, NULL);
90 1.4.4.2 ad
91 1.4.4.2 ad /* wsdisplay_emulops */
92 1.4.4.2 ad static void light_cursor(void *, int, int, int);
93 1.4.4.2 ad static int light_mapchar(void *, int, unsigned int *);
94 1.4.4.2 ad static void light_putchar(void *, int, int, u_int, long);
95 1.4.4.2 ad static void light_copycols(void *, int, int, int, int);
96 1.4.4.2 ad static void light_erasecols(void *, int, int, int, long);
97 1.4.4.2 ad static void light_copyrows(void *, int, int, int);
98 1.4.4.2 ad static void light_eraserows(void *, int, int, long);
99 1.4.4.2 ad static int light_allocattr(void *, int, int, int, long *);
100 1.4.4.2 ad
101 1.4.4.2 ad /* wsdisplay_accessops */
102 1.4.4.2 ad static int light_ioctl(void *, void *, u_long, caddr_t, int, struct lwp *);
103 1.4.4.2 ad static paddr_t light_mmap(void *, void *, off_t, int);
104 1.4.4.2 ad static int light_alloc_screen(void *, const struct wsscreen_descr *,
105 1.4.4.2 ad void **, int *, int *, long *);
106 1.4.4.2 ad static void light_free_screen(void *, void *);
107 1.4.4.2 ad static int light_show_screen(void *, void *, int,
108 1.4.4.2 ad void (*)(void *, int, int), void *);
109 1.4.4.2 ad
110 1.4.4.2 ad static const struct wsdisplay_accessops light_accessops = {
111 1.4.4.2 ad .ioctl = light_ioctl,
112 1.4.4.2 ad .mmap = light_mmap,
113 1.4.4.2 ad .alloc_screen = light_alloc_screen,
114 1.4.4.2 ad .free_screen = light_free_screen,
115 1.4.4.2 ad .show_screen = light_show_screen,
116 1.4.4.2 ad .load_font = NULL,
117 1.4.4.2 ad .pollc = NULL,
118 1.4.4.2 ad .scroll = NULL
119 1.4.4.2 ad };
120 1.4.4.2 ad
121 1.4.4.2 ad static const struct wsdisplay_emulops light_emulops = {
122 1.4.4.2 ad .cursor = light_cursor,
123 1.4.4.2 ad .mapchar = light_mapchar,
124 1.4.4.2 ad .putchar = light_putchar,
125 1.4.4.2 ad .copycols = light_copycols,
126 1.4.4.2 ad .erasecols = light_erasecols,
127 1.4.4.2 ad .copyrows = light_copyrows,
128 1.4.4.2 ad .eraserows = light_eraserows,
129 1.4.4.2 ad .allocattr = light_allocattr,
130 1.4.4.2 ad .replaceattr = NULL
131 1.4.4.2 ad };
132 1.4.4.2 ad
133 1.4.4.2 ad static const struct wsscreen_descr light_screen = {
134 1.4.4.2 ad .name = "1024x768",
135 1.4.4.2 ad .ncols = 128,
136 1.4.4.2 ad .nrows = 48,
137 1.4.4.2 ad .textops = &light_emulops,
138 1.4.4.2 ad .fontwidth = 8,
139 1.4.4.2 ad .fontheight = 16,
140 1.4.4.2 ad .capabilities = WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_REVERSE
141 1.4.4.2 ad };
142 1.4.4.2 ad
143 1.4.4.2 ad const struct wsscreen_descr *_light_screenlist[] = {
144 1.4.4.2 ad &light_screen
145 1.4.4.2 ad };
146 1.4.4.2 ad
147 1.4.4.2 ad static const struct wsscreen_list light_screenlist = {
148 1.4.4.2 ad sizeof(_light_screenlist) / sizeof(_light_screenlist[0]),
149 1.4.4.2 ad _light_screenlist
150 1.4.4.2 ad };
151 1.4.4.2 ad
152 1.4.4.2 ad static struct light_devconfig light_console_dc;
153 1.4.4.2 ad static int light_is_console = 0;
154 1.4.4.2 ad
155 1.4.4.2 ad #define LIGHT_ATTR_ENCODE(fg, bg) (((fg << 8) & 0xff00) | (bg * 0x00ff))
156 1.4.4.2 ad #define LIGHT_ATTR_FG(attr) ((attr >> 8) & 0x00ff)
157 1.4.4.2 ad #define LIGHT_ATTR_BG(attr) (attr & 0x00ff)
158 1.4.4.2 ad
159 1.4.4.2 ad #define LIGHT_IS_LG1(_rev) ((_rev) < 2) /* else LG2 */
160 1.4.4.2 ad
161 1.4.4.2 ad /*******************************************************************************
162 1.4.4.2 ad * REX routines and helper functions
163 1.4.4.2 ad ******************************************************************************/
164 1.4.4.2 ad
165 1.4.4.2 ad static uint32_t
166 1.4.4.2 ad rex_read(struct light_devconfig *dc, uint32_t rset, uint32_t r)
167 1.4.4.2 ad {
168 1.4.4.2 ad
169 1.4.4.2 ad return (bus_space_read_4(dc->dc_st, dc->dc_sh, rset + r));
170 1.4.4.2 ad }
171 1.4.4.2 ad
172 1.4.4.2 ad static void
173 1.4.4.2 ad rex_write(struct light_devconfig *dc, uint32_t rset, uint32_t r, uint32_t v)
174 1.4.4.2 ad {
175 1.4.4.2 ad
176 1.4.4.2 ad bus_space_write_4(dc->dc_st, dc->dc_sh, rset + r, v);
177 1.4.4.2 ad }
178 1.4.4.2 ad
179 1.4.4.2 ad static uint8_t
180 1.4.4.2 ad rex_vc1_read(struct light_devconfig *dc)
181 1.4.4.2 ad {
182 1.4.4.2 ad
183 1.4.4.2 ad rex_write(dc, REX_PAGE1_GO, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_SYSCTL);
184 1.4.4.2 ad rex_read(dc, REX_PAGE1_GO, REX_P1REG_VC1_ADDRDATA);
185 1.4.4.2 ad return (rex_read(dc, REX_PAGE1_SET, REX_P1REG_VC1_ADDRDATA));
186 1.4.4.2 ad }
187 1.4.4.2 ad
188 1.4.4.2 ad static void
189 1.4.4.2 ad rex_vc1_write(struct light_devconfig *dc, uint8_t val)
190 1.4.4.2 ad {
191 1.4.4.2 ad
192 1.4.4.2 ad rex_write(dc, REX_PAGE1_GO, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_SYSCTL);
193 1.4.4.2 ad rex_write(dc, REX_PAGE1_SET, REX_P1REG_VC1_ADDRDATA, val);
194 1.4.4.2 ad rex_write(dc, REX_PAGE1_GO, REX_P1REG_VC1_ADDRDATA, val);
195 1.4.4.2 ad }
196 1.4.4.2 ad
197 1.4.4.2 ad static void
198 1.4.4.2 ad rex_wait(struct light_devconfig *dc)
199 1.4.4.2 ad {
200 1.4.4.2 ad
201 1.4.4.2 ad while (rex_read(dc, REX_PAGE1_SET,REX_P1REG_CFGMODE) & REX_CFGMODE_BUSY)
202 1.4.4.2 ad ;
203 1.4.4.2 ad }
204 1.4.4.2 ad
205 1.4.4.2 ad static int
206 1.4.4.2 ad rex_revision(struct light_devconfig *dc)
207 1.4.4.2 ad {
208 1.4.4.2 ad
209 1.4.4.2 ad rex_write(dc, REX_PAGE1_SET, REX_P1REG_CFGSEL, REX_CFGSEL_VC1_LADDR);
210 1.4.4.2 ad rex_read(dc, REX_PAGE1_GO, REX_P1REG_WCLOCKREV);
211 1.4.4.2 ad return (rex_read(dc, REX_PAGE1_SET, REX_P1REG_WCLOCKREV) & 0x7);
212 1.4.4.2 ad }
213 1.4.4.2 ad
214 1.4.4.2 ad static void
215 1.4.4.2 ad rex_copy_rect(struct light_devconfig *dc, int from_x, int from_y, int to_x,
216 1.4.4.2 ad int to_y, int width, int height)
217 1.4.4.2 ad {
218 1.4.4.2 ad int dx, dy, ystarti, yendi;
219 1.4.4.2 ad
220 1.4.4.2 ad dx = from_x - to_x;
221 1.4.4.2 ad dy = from_y - to_y;
222 1.4.4.2 ad
223 1.4.4.2 ad /* adjust for y. NB: STOPONX, STOPONY are inclusive */
224 1.4.4.2 ad if (to_y > from_y) {
225 1.4.4.2 ad ystarti = to_y + height - 1;
226 1.4.4.2 ad yendi = to_y;
227 1.4.4.2 ad } else {
228 1.4.4.2 ad ystarti = to_y;
229 1.4.4.2 ad yendi = to_y + height - 1;
230 1.4.4.2 ad }
231 1.4.4.2 ad
232 1.4.4.2 ad rex_wait(dc);
233 1.4.4.2 ad
234 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, to_x);
235 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, to_x + width);
236 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, ystarti);
237 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, yendi);
238 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
239 1.4.4.2 ad REX_LOGICOP_SRC | REX_OP_FLG_LOGICSRC | REX_OP_FLG_QUADMODE |
240 1.4.4.2 ad REX_OP_FLG_BLOCK | REX_OP_FLG_STOPONX | REX_OP_FLG_STOPONY);
241 1.4.4.2 ad rex_write(dc, REX_PAGE0_GO, REX_P0REG_XYMOVE,
242 1.4.4.2 ad ((dx << 16) & 0xffff0000) | (dy & 0x0000ffff));
243 1.4.4.2 ad }
244 1.4.4.2 ad
245 1.4.4.2 ad static void
246 1.4.4.2 ad rex_fill_rect(struct light_devconfig *dc, int from_x, int from_y, int to_x,
247 1.4.4.2 ad int to_y, long attr)
248 1.4.4.2 ad {
249 1.4.4.2 ad
250 1.4.4.2 ad rex_wait(dc);
251 1.4.4.2 ad
252 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, from_y);
253 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, to_y);
254 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, from_x);
255 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, to_x);
256 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORREDI, LIGHT_ATTR_BG(attr));
257 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
258 1.4.4.2 ad REX_LOGICOP_SRC | REX_OP_FLG_QUADMODE | REX_OP_FLG_BLOCK |
259 1.4.4.2 ad REX_OP_FLG_STOPONX | REX_OP_FLG_STOPONY);
260 1.4.4.2 ad rex_read(dc, REX_PAGE0_GO, REX_P0REG_COMMAND);
261 1.4.4.2 ad }
262 1.4.4.2 ad
263 1.4.4.2 ad /*******************************************************************************
264 1.4.4.2 ad * match/attach functions
265 1.4.4.2 ad ******************************************************************************/
266 1.4.4.2 ad
267 1.4.4.2 ad static int
268 1.4.4.2 ad light_match(struct device *parent, struct cfdata *self, void *aux)
269 1.4.4.2 ad {
270 1.4.4.2 ad struct gio_attach_args *ga = aux;
271 1.4.4.2 ad
272 1.4.4.2 ad if (ga->ga_addr != LIGHT_ADDR_0 && ga->ga_addr != LIGHT_ADDR_1)
273 1.4.4.2 ad return (0);
274 1.4.4.2 ad
275 1.4.4.2 ad if (platform.badaddr(
276 1.4.4.2 ad (void *)(ga->ga_ioh + REX_PAGE1_SET + REX_P1REG_XYOFFSET),
277 1.4.4.2 ad sizeof(uint32_t)))
278 1.4.4.2 ad return (0);
279 1.4.4.2 ad
280 1.4.4.2 ad if (bus_space_read_4(ga->ga_iot, ga->ga_ioh,
281 1.4.4.2 ad REX_PAGE1_SET + REX_P1REG_XYOFFSET) != 0x08000800)
282 1.4.4.2 ad return (0);
283 1.4.4.2 ad
284 1.4.4.2 ad return (1);
285 1.4.4.2 ad }
286 1.4.4.2 ad
287 1.4.4.2 ad static void
288 1.4.4.2 ad light_attach_common(struct light_devconfig *dc, struct gio_attach_args *ga)
289 1.4.4.2 ad {
290 1.4.4.2 ad
291 1.4.4.2 ad dc->dc_addr = ga->ga_addr;
292 1.4.4.2 ad dc->dc_st = ga->ga_iot;
293 1.4.4.2 ad dc->dc_sh = ga->ga_ioh;
294 1.4.4.2 ad
295 1.4.4.2 ad dc->dc_boardrev = rex_revision(dc);
296 1.4.4.2 ad
297 1.4.4.2 ad wsfont_init();
298 1.4.4.2 ad
299 1.4.4.2 ad dc->dc_font = wsfont_find(NULL, 8, 16, 0, WSDISPLAY_FONTORDER_L2R,
300 1.4.4.2 ad WSDISPLAY_FONTORDER_L2R);
301 1.4.4.2 ad
302 1.4.4.2 ad if (dc->dc_font < 0)
303 1.4.4.2 ad panic("light_attach_common: no suitable fonts");
304 1.4.4.2 ad
305 1.4.4.2 ad if (wsfont_lock(dc->dc_font, &dc->dc_fontdata))
306 1.4.4.2 ad panic("light_attach_common: unable to lock font data");
307 1.4.4.2 ad
308 1.4.4.2 ad rex_vc1_write(dc, rex_vc1_read(dc) & ~(VC1_SYSCTL_CURSOR |
309 1.4.4.2 ad VC1_SYSCTL_CURSOR_ON));
310 1.4.4.2 ad rex_fill_rect(dc, 0, 0, LIGHT_XRES - 1, LIGHT_YRES - 1, 0);
311 1.4.4.2 ad }
312 1.4.4.2 ad
313 1.4.4.2 ad static void
314 1.4.4.2 ad light_attach(struct device *parent, struct device *self, void *aux)
315 1.4.4.2 ad {
316 1.4.4.2 ad struct gio_attach_args *ga = aux;
317 1.4.4.2 ad struct light_softc *sc = (void *)self;
318 1.4.4.2 ad struct wsemuldisplaydev_attach_args wa;
319 1.4.4.2 ad
320 1.4.4.2 ad if (light_is_console && ga->ga_addr == light_console_dc.dc_addr) {
321 1.4.4.2 ad wa.console = 1;
322 1.4.4.2 ad sc->sc_dc = &light_console_dc;
323 1.4.4.2 ad } else {
324 1.4.4.2 ad wa.console = 0;
325 1.4.4.2 ad sc->sc_dc = malloc(sizeof(struct light_devconfig), M_DEVBUF,
326 1.4.4.2 ad M_WAITOK | M_ZERO);
327 1.4.4.2 ad if (sc->sc_dc == NULL)
328 1.4.4.2 ad panic("light_attach: out of memory");
329 1.4.4.2 ad
330 1.4.4.2 ad light_attach_common(sc->sc_dc, ga);
331 1.4.4.2 ad }
332 1.4.4.2 ad
333 1.4.4.2 ad aprint_naive(": Display adapter\n");
334 1.4.4.2 ad
335 1.4.4.2 ad aprint_normal(": SGI LG%d (board revision %d)\n",
336 1.4.4.2 ad LIGHT_IS_LG1(sc->sc_dc->dc_boardrev) ? 1 : 2,
337 1.4.4.2 ad sc->sc_dc->dc_boardrev);
338 1.4.4.2 ad
339 1.4.4.2 ad wa.scrdata = &light_screenlist;
340 1.4.4.2 ad wa.accessops = &light_accessops;
341 1.4.4.2 ad wa.accesscookie = sc->sc_dc;
342 1.4.4.2 ad
343 1.4.4.2 ad config_found(&sc->sc_dev, &wa, wsemuldisplaydevprint);
344 1.4.4.2 ad }
345 1.4.4.2 ad
346 1.4.4.2 ad int
347 1.4.4.2 ad light_cnattach(struct gio_attach_args *ga)
348 1.4.4.2 ad {
349 1.4.4.2 ad
350 1.4.4.2 ad if (!light_match(NULL, NULL, ga))
351 1.4.4.2 ad return (ENXIO);
352 1.4.4.2 ad
353 1.4.4.2 ad light_attach_common(&light_console_dc, ga);
354 1.4.4.2 ad
355 1.4.4.2 ad wsdisplay_cnattach(&light_screen, &light_console_dc, 0, 0,
356 1.4.4.2 ad LIGHT_ATTR_ENCODE(WSCOL_WHITE, WSCOL_BLACK));
357 1.4.4.2 ad
358 1.4.4.2 ad light_is_console = 1;
359 1.4.4.2 ad
360 1.4.4.2 ad return (0);
361 1.4.4.2 ad }
362 1.4.4.2 ad
363 1.4.4.2 ad /*******************************************************************************
364 1.4.4.2 ad * wsdisplay_emulops
365 1.4.4.2 ad ******************************************************************************/
366 1.4.4.2 ad
367 1.4.4.2 ad static void
368 1.4.4.2 ad light_cursor(void *c, int on, int row, int col)
369 1.4.4.2 ad {
370 1.4.4.2 ad /* XXX */
371 1.4.4.2 ad }
372 1.4.4.2 ad
373 1.4.4.2 ad static int
374 1.4.4.2 ad light_mapchar(void *c, int ch, unsigned int *cp)
375 1.4.4.2 ad {
376 1.4.4.2 ad struct light_devconfig *dc = (void *)c;
377 1.4.4.2 ad
378 1.4.4.2 ad if (dc->dc_fontdata->encoding != WSDISPLAY_FONTENC_ISO) {
379 1.4.4.2 ad ch = wsfont_map_unichar(dc->dc_fontdata, ch);
380 1.4.4.2 ad
381 1.4.4.2 ad if (ch < 0)
382 1.4.4.2 ad goto fail;
383 1.4.4.2 ad }
384 1.4.4.2 ad
385 1.4.4.2 ad if (ch < dc->dc_fontdata->firstchar ||
386 1.4.4.2 ad ch >= dc->dc_fontdata->firstchar + dc->dc_fontdata->numchars)
387 1.4.4.2 ad goto fail;
388 1.4.4.2 ad
389 1.4.4.2 ad *cp = ch;
390 1.4.4.2 ad return 5;
391 1.4.4.2 ad
392 1.4.4.2 ad fail:
393 1.4.4.2 ad *cp = ' ';
394 1.4.4.2 ad return 0;
395 1.4.4.2 ad }
396 1.4.4.2 ad
397 1.4.4.2 ad static void
398 1.4.4.2 ad light_putchar(void *c, int row, int col, u_int ch, long attr)
399 1.4.4.2 ad {
400 1.4.4.2 ad struct light_devconfig *dc = c;
401 1.4.4.2 ad struct wsdisplay_font *font = dc->dc_fontdata;
402 1.4.4.2 ad uint8_t *bitmap;
403 1.4.4.2 ad uint32_t pattern;
404 1.4.4.2 ad int i, x, y;
405 1.4.4.2 ad
406 1.4.4.2 ad bitmap = (u_int8_t *)font->data +
407 1.4.4.2 ad ((ch - font->firstchar) * font->fontheight * font->stride);
408 1.4.4.2 ad x = col * font->fontwidth;
409 1.4.4.2 ad y = row * font->fontheight;
410 1.4.4.2 ad
411 1.4.4.2 ad rex_wait(dc);
412 1.4.4.2 ad
413 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YSTARTI, y);
414 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_YENDI, y + font->fontheight - 1);
415 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XSTARTI, x);
416 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_XENDI, x + font->fontwidth - 1);
417 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORREDI, LIGHT_ATTR_FG(attr));
418 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COLORBACK, LIGHT_ATTR_BG(attr));
419 1.4.4.2 ad rex_write(dc, REX_PAGE0_GO, REX_P0REG_COMMAND, REX_OP_NOP);
420 1.4.4.2 ad
421 1.4.4.2 ad rex_wait(dc);
422 1.4.4.2 ad
423 1.4.4.2 ad rex_write(dc, REX_PAGE0_SET, REX_P0REG_COMMAND, REX_OP_DRAW |
424 1.4.4.2 ad REX_LOGICOP_SRC | REX_OP_FLG_ENZPATTERN | REX_OP_FLG_QUADMODE |
425 1.4.4.2 ad REX_OP_FLG_XYCONTINUE | REX_OP_FLG_STOPONX | REX_OP_FLG_BLOCK |
426 1.4.4.2 ad REX_OP_FLG_LENGTH32 | REX_OP_FLG_ZOPAQUE);
427 1.4.4.2 ad
428 1.4.4.2 ad for (i = 0; i < font->fontheight; i++) {
429 1.4.4.2 ad /* XXX assumes font->fontwidth == 8 */
430 1.4.4.2 ad pattern = *bitmap << 24;
431 1.4.4.2 ad rex_write(dc, REX_PAGE0_GO, REX_P0REG_ZPATTERN, pattern);
432 1.4.4.2 ad bitmap += font->stride;
433 1.4.4.2 ad }
434 1.4.4.2 ad }
435 1.4.4.2 ad
436 1.4.4.2 ad /* copy set of columns within the same line */
437 1.4.4.2 ad static void
438 1.4.4.2 ad light_copycols(void *c, int row, int srccol, int dstcol, int ncols)
439 1.4.4.2 ad {
440 1.4.4.2 ad struct light_devconfig *dc = c;
441 1.4.4.2 ad struct wsdisplay_font *font = dc->dc_fontdata;
442 1.4.4.2 ad int from_x, from_y, to_x, to_y, width, height;
443 1.4.4.2 ad
444 1.4.4.2 ad from_x = srccol * font->fontwidth;
445 1.4.4.2 ad from_y = row * font->fontheight;
446 1.4.4.2 ad to_x = dstcol * font->fontwidth;
447 1.4.4.2 ad to_y = from_y;
448 1.4.4.2 ad width = ncols * font->fontwidth;
449 1.4.4.2 ad height = font->fontheight;
450 1.4.4.2 ad
451 1.4.4.2 ad rex_copy_rect(c, from_x, from_y, to_x, to_y, width, height);
452 1.4.4.2 ad }
453 1.4.4.2 ad
454 1.4.4.2 ad /* erase a set of columns in the same line */
455 1.4.4.2 ad static void
456 1.4.4.2 ad light_erasecols(void *c, int row, int startcol, int ncols, long attr)
457 1.4.4.2 ad {
458 1.4.4.2 ad struct light_devconfig *dc = c;
459 1.4.4.2 ad struct wsdisplay_font *font = dc->dc_fontdata;
460 1.4.4.2 ad int from_x, from_y, to_x, to_y;
461 1.4.4.2 ad
462 1.4.4.2 ad from_x = startcol * font->fontwidth;
463 1.4.4.2 ad from_y = row * font->fontheight;
464 1.4.4.2 ad to_x = from_x + (ncols * font->fontwidth) - 1;
465 1.4.4.2 ad to_y = from_y + font->fontheight - 1;
466 1.4.4.2 ad
467 1.4.4.2 ad rex_fill_rect(c, from_x, from_y, to_x, to_y, attr);
468 1.4.4.2 ad }
469 1.4.4.2 ad
470 1.4.4.2 ad /* copy a set of complete rows */
471 1.4.4.2 ad static void
472 1.4.4.2 ad light_copyrows(void *c, int srcrow, int dstrow, int nrows)
473 1.4.4.2 ad {
474 1.4.4.2 ad struct light_devconfig *dc = c;
475 1.4.4.2 ad struct wsdisplay_font *font = dc->dc_fontdata;
476 1.4.4.2 ad int from_x, from_y, to_x, to_y, width, height;
477 1.4.4.2 ad
478 1.4.4.2 ad from_x = 0;
479 1.4.4.2 ad from_y = srcrow * font->fontheight;
480 1.4.4.2 ad to_x = 0;
481 1.4.4.2 ad to_y = dstrow * font->fontheight;
482 1.4.4.2 ad width = LIGHT_XRES;
483 1.4.4.2 ad height = nrows * font->fontheight;
484 1.4.4.2 ad
485 1.4.4.2 ad rex_copy_rect(c, from_x, from_y, to_x, to_y, width, height);
486 1.4.4.2 ad }
487 1.4.4.2 ad
488 1.4.4.2 ad /* erase a set of complete rows */
489 1.4.4.2 ad static void
490 1.4.4.2 ad light_eraserows(void *c, int row, int nrows, long attr)
491 1.4.4.2 ad {
492 1.4.4.2 ad struct light_devconfig *dc = c;
493 1.4.4.2 ad struct wsdisplay_font *font = dc->dc_fontdata;
494 1.4.4.2 ad int from_x, from_y, to_x, to_y;
495 1.4.4.2 ad
496 1.4.4.2 ad from_x = 0;
497 1.4.4.2 ad from_y = row * font->fontheight;
498 1.4.4.2 ad to_x = LIGHT_XRES - 1;
499 1.4.4.2 ad to_y = from_y + (nrows * font->fontheight) - 1;
500 1.4.4.2 ad
501 1.4.4.2 ad rex_fill_rect(c, from_x, from_y, to_x, to_y, attr);
502 1.4.4.2 ad }
503 1.4.4.2 ad
504 1.4.4.2 ad static int
505 1.4.4.2 ad light_allocattr(void *c, int fg, int bg, int flags, long *attr)
506 1.4.4.2 ad {
507 1.4.4.2 ad
508 1.4.4.2 ad if (flags & ~(WSATTR_WSCOLORS | WSATTR_HILIT | WSATTR_REVERSE))
509 1.4.4.2 ad return (EINVAL);
510 1.4.4.2 ad
511 1.4.4.2 ad if ((flags & WSATTR_WSCOLORS) == 0) {
512 1.4.4.2 ad fg = WSCOL_WHITE;
513 1.4.4.2 ad bg = WSCOL_BLACK;
514 1.4.4.2 ad }
515 1.4.4.2 ad
516 1.4.4.2 ad if (flags & WSATTR_HILIT)
517 1.4.4.2 ad fg += 8;
518 1.4.4.2 ad
519 1.4.4.2 ad if (flags & WSATTR_REVERSE) {
520 1.4.4.2 ad int tmp = fg;
521 1.4.4.2 ad fg = bg;
522 1.4.4.2 ad bg = tmp;
523 1.4.4.2 ad }
524 1.4.4.2 ad
525 1.4.4.2 ad *attr = LIGHT_ATTR_ENCODE(fg, bg);
526 1.4.4.2 ad return (0);
527 1.4.4.2 ad }
528 1.4.4.2 ad
529 1.4.4.2 ad /*******************************************************************************
530 1.4.4.2 ad * wsdisplay_accessops
531 1.4.4.2 ad ******************************************************************************/
532 1.4.4.2 ad
533 1.4.4.2 ad static int
534 1.4.4.2 ad light_ioctl(void *c, void *vs, u_long cmd, caddr_t data, int flag,
535 1.4.4.2 ad struct lwp *l)
536 1.4.4.2 ad {
537 1.4.4.2 ad struct wsdisplay_fbinfo *fbinfo = (struct wsdisplay_fbinfo *)data;
538 1.4.4.2 ad
539 1.4.4.2 ad switch (cmd) {
540 1.4.4.2 ad case WSDISPLAYIO_GINFO:
541 1.4.4.2 ad fbinfo->width = LIGHT_XRES;
542 1.4.4.2 ad fbinfo->height = LIGHT_YRES;
543 1.4.4.2 ad fbinfo->depth = LIGHT_DEPTH;
544 1.4.4.2 ad fbinfo->cmsize = 1 << LIGHT_DEPTH;
545 1.4.4.2 ad return (0);
546 1.4.4.2 ad
547 1.4.4.2 ad case WSDISPLAYIO_GMODE:
548 1.4.4.2 ad *(u_int *)data = WSDISPLAYIO_MODE_EMUL;
549 1.4.4.2 ad break;
550 1.4.4.2 ad
551 1.4.4.2 ad case WSDISPLAYIO_GTYPE:
552 1.4.4.2 ad *(u_int *)data = WSDISPLAY_TYPE_LIGHT;
553 1.4.4.2 ad return (0);
554 1.4.4.2 ad
555 1.4.4.2 ad case WSDISPLAYIO_SVIDEO:
556 1.4.4.2 ad /*
557 1.4.4.2 ad * Turning off VC1 will stop refreshing the video ram (or so I
558 1.4.4.2 ad * suspect). We'll blank the screen after bringing it back up,
559 1.4.4.2 ad * since that's nicer than displaying garbage.
560 1.4.4.2 ad */
561 1.4.4.2 ad if (*(u_int *)data == WSDISPLAYIO_VIDEO_OFF)
562 1.4.4.2 ad rex_vc1_write(c,rex_vc1_read(c) & ~VC1_SYSCTL_VIDEO_ON);
563 1.4.4.2 ad else {
564 1.4.4.2 ad rex_vc1_write(c, rex_vc1_read(c) | VC1_SYSCTL_VIDEO_ON);
565 1.4.4.2 ad rex_fill_rect(c, 0, 0, LIGHT_XRES-1, LIGHT_YRES-1, 0);
566 1.4.4.2 ad }
567 1.4.4.2 ad return (0);
568 1.4.4.2 ad }
569 1.4.4.2 ad
570 1.4.4.2 ad return (EPASSTHROUGH);
571 1.4.4.2 ad }
572 1.4.4.2 ad
573 1.4.4.2 ad static paddr_t
574 1.4.4.2 ad light_mmap(void *c, void *vs, off_t off, int prot)
575 1.4.4.2 ad {
576 1.4.4.2 ad struct light_devconfig *dc = c;
577 1.4.4.2 ad
578 1.4.4.2 ad if (off >= 0x7fff)
579 1.4.4.2 ad return (-1);
580 1.4.4.2 ad
581 1.4.4.2 ad return (mips_btop(dc->dc_addr + off));
582 1.4.4.2 ad }
583 1.4.4.2 ad
584 1.4.4.2 ad static int
585 1.4.4.2 ad light_alloc_screen(void *c, const struct wsscreen_descr *type, void **cookiep,
586 1.4.4.2 ad int *curxp, int *curyp, long *attr)
587 1.4.4.2 ad {
588 1.4.4.2 ad
589 1.4.4.2 ad return (ENOMEM);
590 1.4.4.2 ad }
591 1.4.4.2 ad
592 1.4.4.2 ad static void
593 1.4.4.2 ad light_free_screen(void *c, void *cookie)
594 1.4.4.2 ad {
595 1.4.4.2 ad
596 1.4.4.2 ad panic("light_free_screen");
597 1.4.4.2 ad }
598 1.4.4.2 ad
599 1.4.4.2 ad static int
600 1.4.4.2 ad light_show_screen(void *c, void *cookie, int waitok,
601 1.4.4.2 ad void (*cb)(void *, int, int), void *cbarg)
602 1.4.4.2 ad {
603 1.4.4.2 ad
604 1.4.4.2 ad return (0);
605 1.4.4.2 ad }
606