crmfb.c revision 1.5.4.3 1 1.5.4.3 ad /* $NetBSD: crmfb.c,v 1.5.4.3 2007/08/20 18:38:42 ad Exp $ */
2 1.5.4.2 ad
3 1.5.4.2 ad /*-
4 1.5.4.2 ad * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
5 1.5.4.2 ad * All rights reserved.
6 1.5.4.2 ad *
7 1.5.4.2 ad * Redistribution and use in source and binary forms, with or without
8 1.5.4.2 ad * modification, are permitted provided that the following conditions
9 1.5.4.2 ad * are met:
10 1.5.4.2 ad * 1. Redistributions of source code must retain the above copyright
11 1.5.4.2 ad * notice, this list of conditions and the following disclaimer.
12 1.5.4.2 ad * 2. Redistributions in binary form must reproduce the above copyright
13 1.5.4.2 ad * notice, this list of conditions and the following disclaimer in the
14 1.5.4.2 ad * documentation and/or other materials provided with the distribution.
15 1.5.4.2 ad * 3. All advertising materials mentioning features or use of this software
16 1.5.4.2 ad * must display the following acknowledgement:
17 1.5.4.2 ad * This product includes software developed by Jared D. McNeill.
18 1.5.4.2 ad * 4. Neither the name of The NetBSD Foundation nor the names of its
19 1.5.4.2 ad * contributors may be used to endorse or promote products derived
20 1.5.4.2 ad * from this software without specific prior written permission.
21 1.5.4.2 ad *
22 1.5.4.2 ad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.5.4.2 ad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.5.4.2 ad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.5.4.2 ad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.5.4.2 ad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.5.4.2 ad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.5.4.2 ad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.5.4.2 ad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.5.4.2 ad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.5.4.2 ad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.5.4.2 ad * POSSIBILITY OF SUCH DAMAGE.
33 1.5.4.2 ad */
34 1.5.4.2 ad
35 1.5.4.2 ad /*
36 1.5.4.2 ad * SGI-CRM (O2) Framebuffer driver
37 1.5.4.2 ad */
38 1.5.4.2 ad
39 1.5.4.2 ad #include <sys/cdefs.h>
40 1.5.4.3 ad __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.5.4.3 2007/08/20 18:38:42 ad Exp $");
41 1.5.4.2 ad
42 1.5.4.2 ad #include <sys/param.h>
43 1.5.4.2 ad #include <sys/systm.h>
44 1.5.4.2 ad #include <sys/device.h>
45 1.5.4.2 ad #include <sys/malloc.h>
46 1.5.4.2 ad
47 1.5.4.2 ad #define _SGIMIPS_BUS_DMA_PRIVATE
48 1.5.4.2 ad #include <machine/autoconf.h>
49 1.5.4.2 ad #include <machine/bus.h>
50 1.5.4.2 ad #include <machine/machtype.h>
51 1.5.4.2 ad #include <machine/vmparam.h>
52 1.5.4.2 ad
53 1.5.4.2 ad #include <dev/arcbios/arcbios.h>
54 1.5.4.2 ad #include <dev/arcbios/arcbiosvar.h>
55 1.5.4.2 ad
56 1.5.4.2 ad #include <dev/wscons/wsdisplayvar.h>
57 1.5.4.2 ad #include <dev/wscons/wsconsio.h>
58 1.5.4.2 ad #include <dev/wsfont/wsfont.h>
59 1.5.4.2 ad #include <dev/rasops/rasops.h>
60 1.5.4.2 ad #include <dev/wscons/wsdisplay_vconsvar.h>
61 1.5.4.2 ad
62 1.5.4.3 ad #include <arch/sgimips/dev/crmfbreg.h>
63 1.5.4.3 ad
64 1.5.4.2 ad #define CRMFB_SHADOWFB
65 1.5.4.2 ad
66 1.5.4.2 ad struct wsscreen_descr crmfb_defaultscreen = {
67 1.5.4.2 ad "default",
68 1.5.4.2 ad 0, 0,
69 1.5.4.2 ad NULL,
70 1.5.4.2 ad 8, 16,
71 1.5.4.2 ad WSSCREEN_WSCOLORS,
72 1.5.4.2 ad NULL,
73 1.5.4.2 ad };
74 1.5.4.2 ad
75 1.5.4.2 ad const struct wsscreen_descr *_crmfb_scrlist[] = {
76 1.5.4.2 ad &crmfb_defaultscreen,
77 1.5.4.2 ad };
78 1.5.4.2 ad
79 1.5.4.2 ad struct wsscreen_list crmfb_screenlist = {
80 1.5.4.2 ad sizeof(_crmfb_scrlist) / sizeof(struct wsscreen_descr *),
81 1.5.4.2 ad _crmfb_scrlist
82 1.5.4.2 ad };
83 1.5.4.2 ad
84 1.5.4.2 ad static struct vcons_screen crmfb_console_screen;
85 1.5.4.2 ad
86 1.5.4.2 ad static int crmfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
87 1.5.4.2 ad static paddr_t crmfb_mmap(void *, void *, off_t, int);
88 1.5.4.2 ad static void crmfb_init_screen(void *, struct vcons_screen *, int, long *);
89 1.5.4.2 ad
90 1.5.4.2 ad struct wsdisplay_accessops crmfb_accessops = {
91 1.5.4.2 ad crmfb_ioctl,
92 1.5.4.2 ad crmfb_mmap,
93 1.5.4.2 ad NULL, /* alloc_screen */
94 1.5.4.2 ad NULL, /* free_screen */
95 1.5.4.2 ad NULL, /* show_screen */
96 1.5.4.2 ad NULL, /* load_font */
97 1.5.4.2 ad NULL, /* pollc */
98 1.5.4.2 ad NULL, /* scroll */
99 1.5.4.2 ad };
100 1.5.4.2 ad
101 1.5.4.2 ad /* Memory to allocate to SGI-CRM -- remember, this is stolen from
102 1.5.4.2 ad * host memory!
103 1.5.4.2 ad */
104 1.5.4.2 ad #define CRMFB_TILESIZE (512*128)
105 1.5.4.2 ad
106 1.5.4.2 ad static int crmfb_match(struct device *, struct cfdata *, void *);
107 1.5.4.2 ad static void crmfb_attach(struct device *, struct device *, void *);
108 1.5.4.2 ad int crmfb_probe(void);
109 1.5.4.2 ad
110 1.5.4.2 ad #define KERNADDR(p) ((void *)((p).addr))
111 1.5.4.2 ad #define DMAADDR(p) ((p).map->dm_segs[0].ds_addr)
112 1.5.4.2 ad
113 1.5.4.2 ad struct crmfb_dma {
114 1.5.4.2 ad bus_dmamap_t map;
115 1.5.4.2 ad void *addr;
116 1.5.4.2 ad bus_dma_segment_t segs[1];
117 1.5.4.2 ad int nsegs;
118 1.5.4.2 ad size_t size;
119 1.5.4.2 ad };
120 1.5.4.2 ad
121 1.5.4.2 ad struct crmfb_softc {
122 1.5.4.2 ad struct device sc_dev;
123 1.5.4.2 ad struct vcons_data sc_vd;
124 1.5.4.2 ad
125 1.5.4.2 ad bus_space_tag_t sc_iot;
126 1.5.4.2 ad bus_space_handle_t sc_ioh;
127 1.5.4.3 ad
128 1.5.4.2 ad bus_dma_tag_t sc_dmat;
129 1.5.4.2 ad
130 1.5.4.2 ad struct crmfb_dma sc_dma;
131 1.5.4.2 ad struct crmfb_dma sc_dmai;
132 1.5.4.2 ad
133 1.5.4.2 ad int sc_width;
134 1.5.4.2 ad int sc_height;
135 1.5.4.2 ad int sc_depth;
136 1.5.4.2 ad uint32_t sc_fbsize;
137 1.5.4.2 ad uint8_t *sc_shadowfb;
138 1.5.4.2 ad
139 1.5.4.2 ad int sc_wsmode;
140 1.5.4.3 ad
141 1.5.4.3 ad /* cursor stuff */
142 1.5.4.3 ad int sc_cur_x;
143 1.5.4.3 ad int sc_cur_y;
144 1.5.4.3 ad int sc_hot_x;
145 1.5.4.3 ad int sc_hot_y;
146 1.5.4.3 ad
147 1.5.4.2 ad u_char sc_cmap_red[256];
148 1.5.4.2 ad u_char sc_cmap_green[256];
149 1.5.4.2 ad u_char sc_cmap_blue[256];
150 1.5.4.2 ad };
151 1.5.4.2 ad
152 1.5.4.2 ad static int crmfb_putcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
153 1.5.4.2 ad static int crmfb_getcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
154 1.5.4.2 ad static void crmfb_set_palette(struct crmfb_softc *,
155 1.5.4.2 ad int, uint8_t, uint8_t, uint8_t);
156 1.5.4.3 ad static int crmfb_set_curpos(struct crmfb_softc *, int, int);
157 1.5.4.3 ad static int crmfb_gcursor(struct crmfb_softc *, struct wsdisplay_cursor *);
158 1.5.4.3 ad static int crmfb_scursor(struct crmfb_softc *, struct wsdisplay_cursor *);
159 1.5.4.3 ad static inline void crmfb_write_reg(struct crmfb_softc *, int, uint32_t);
160 1.5.4.3 ad
161 1.5.4.3 ad /* setup video hw in given colour depth */
162 1.5.4.3 ad static int crmfb_setup_video(struct crmfb_softc *, int);
163 1.5.4.3 ad static void crmfb_setup_palette(struct crmfb_softc *);
164 1.5.4.2 ad
165 1.5.4.2 ad CFATTACH_DECL(crmfb, sizeof(struct crmfb_softc),
166 1.5.4.2 ad crmfb_match, crmfb_attach, NULL, NULL);
167 1.5.4.2 ad
168 1.5.4.2 ad static int
169 1.5.4.2 ad crmfb_match(struct device *parent, struct cfdata *cf, void *opaque)
170 1.5.4.2 ad {
171 1.5.4.2 ad return crmfb_probe();
172 1.5.4.2 ad }
173 1.5.4.2 ad
174 1.5.4.2 ad static void
175 1.5.4.2 ad crmfb_attach(struct device *parent, struct device *self, void *opaque)
176 1.5.4.2 ad {
177 1.5.4.2 ad struct mainbus_attach_args *ma;
178 1.5.4.2 ad struct crmfb_softc *sc;
179 1.5.4.2 ad struct rasops_info *ri;
180 1.5.4.2 ad struct wsemuldisplaydev_attach_args aa;
181 1.5.4.2 ad uint32_t d, h;
182 1.5.4.2 ad uint16_t *p;
183 1.5.4.2 ad unsigned long v;
184 1.5.4.2 ad long defattr;
185 1.5.4.2 ad const char *consdev;
186 1.5.4.3 ad int rv, i, tiles_x, tiles_y;
187 1.5.4.2 ad
188 1.5.4.2 ad sc = (struct crmfb_softc *)self;
189 1.5.4.2 ad ma = (struct mainbus_attach_args *)opaque;
190 1.5.4.2 ad
191 1.5.4.2 ad sc->sc_iot = SGIMIPS_BUS_SPACE_CRIME;
192 1.5.4.2 ad sc->sc_dmat = &sgimips_default_bus_dma_tag;
193 1.5.4.2 ad sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
194 1.5.4.2 ad
195 1.5.4.2 ad aprint_normal(": SGI CRIME Graphics Display Engine\n");
196 1.5.4.2 ad rv = bus_space_map(sc->sc_iot, ma->ma_addr, 0 /* XXX */,
197 1.5.4.2 ad BUS_SPACE_MAP_LINEAR, &sc->sc_ioh);
198 1.5.4.2 ad if (rv)
199 1.5.4.2 ad panic("crmfb_attach: can't map I/O space");
200 1.5.4.2 ad
201 1.5.4.2 ad /* determine mode configured by firmware */
202 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_VCMAP);
203 1.5.4.2 ad sc->sc_width = (d >> CRMFB_VT_VCMAP_ON_SHIFT) & 0xfff;
204 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP);
205 1.5.4.2 ad sc->sc_height = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff;
206 1.5.4.2 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
207 1.5.4.2 ad h = (d >> CRMFB_FRM_TILESIZE_DEPTH_SHIFT) & 0x3;
208 1.5.4.2 ad if (h == 0)
209 1.5.4.2 ad sc->sc_depth = 8;
210 1.5.4.2 ad else if (h == 1)
211 1.5.4.2 ad sc->sc_depth = 16;
212 1.5.4.2 ad else
213 1.5.4.2 ad sc->sc_depth = 32;
214 1.5.4.2 ad
215 1.5.4.2 ad if (sc->sc_width == 0 || sc->sc_height == 0) {
216 1.5.4.2 ad printf("%s: device unusable if not setup by firmware\n",
217 1.5.4.2 ad sc->sc_dev.dv_xname);
218 1.5.4.2 ad bus_space_unmap(sc->sc_iot, sc->sc_ioh, 0 /* XXX */);
219 1.5.4.2 ad return;
220 1.5.4.2 ad }
221 1.5.4.2 ad
222 1.5.4.3 ad printf("%s: initial resolution %dx%d\n",
223 1.5.4.3 ad sc->sc_dev.dv_xname, sc->sc_width, sc->sc_height);
224 1.5.4.2 ad
225 1.5.4.3 ad /*
226 1.5.4.3 ad * first determine how many tiles we need
227 1.5.4.3 ad * in 32bit each tile is 128x128 pixels
228 1.5.4.3 ad */
229 1.5.4.3 ad tiles_x = (sc->sc_width + 127) >> 7;
230 1.5.4.3 ad tiles_y = (sc->sc_height + 127) >> 7;
231 1.5.4.3 ad sc->sc_fbsize = 0x10000 * tiles_x * tiles_y;
232 1.5.4.3 ad printf("so we need %d x %d tiles -> %08x\n", tiles_x, tiles_y,
233 1.5.4.3 ad sc->sc_fbsize);
234 1.5.4.2 ad
235 1.5.4.3 ad sc->sc_dmai.size = 256 * sizeof(uint16_t);
236 1.5.4.2 ad rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmai.size, 65536, 0,
237 1.5.4.2 ad sc->sc_dmai.segs,
238 1.5.4.2 ad sizeof(sc->sc_dmai.segs) / sizeof(sc->sc_dmai.segs[0]),
239 1.5.4.2 ad &sc->sc_dmai.nsegs, BUS_DMA_NOWAIT);
240 1.5.4.2 ad if (rv)
241 1.5.4.2 ad panic("crmfb_attach: can't allocate DMA memory");
242 1.5.4.2 ad rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dmai.segs, sc->sc_dmai.nsegs,
243 1.5.4.2 ad sc->sc_dmai.size, &sc->sc_dmai.addr,
244 1.5.4.2 ad BUS_DMA_NOWAIT);
245 1.5.4.2 ad if (rv)
246 1.5.4.2 ad panic("crmfb_attach: can't map DMA memory");
247 1.5.4.2 ad rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dmai.size, 1,
248 1.5.4.2 ad sc->sc_dmai.size, 0, BUS_DMA_NOWAIT, &sc->sc_dmai.map);
249 1.5.4.2 ad if (rv)
250 1.5.4.2 ad panic("crmfb_attach: can't create DMA map");
251 1.5.4.2 ad rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dmai.map, sc->sc_dmai.addr,
252 1.5.4.2 ad sc->sc_dmai.size, NULL, BUS_DMA_NOWAIT);
253 1.5.4.2 ad if (rv)
254 1.5.4.2 ad panic("crmfb_attach: can't load DMA map");
255 1.5.4.2 ad
256 1.5.4.2 ad sc->sc_dma.size = sc->sc_fbsize;
257 1.5.4.2 ad rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dma.size, 65536, 0,
258 1.5.4.2 ad sc->sc_dma.segs,
259 1.5.4.2 ad sizeof(sc->sc_dma.segs) / sizeof(sc->sc_dma.segs[0]),
260 1.5.4.2 ad &sc->sc_dma.nsegs, BUS_DMA_NOWAIT);
261 1.5.4.2 ad if (rv)
262 1.5.4.2 ad panic("crmfb_attach: can't allocate DMA memory");
263 1.5.4.2 ad rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dma.segs, sc->sc_dma.nsegs,
264 1.5.4.2 ad sc->sc_dma.size, &sc->sc_dma.addr,
265 1.5.4.2 ad BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
266 1.5.4.2 ad if (rv)
267 1.5.4.2 ad panic("crmfb_attach: can't map DMA memory");
268 1.5.4.2 ad rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dma.size, 1,
269 1.5.4.2 ad sc->sc_dma.size, 0, BUS_DMA_NOWAIT, &sc->sc_dma.map);
270 1.5.4.2 ad if (rv)
271 1.5.4.2 ad panic("crmfb_attach: can't create DMA map");
272 1.5.4.2 ad rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dma.map, sc->sc_dma.addr,
273 1.5.4.2 ad sc->sc_dma.size, NULL, BUS_DMA_NOWAIT);
274 1.5.4.2 ad if (rv)
275 1.5.4.2 ad panic("crmfb_attach: can't load DMA map");
276 1.5.4.2 ad
277 1.5.4.2 ad p = KERNADDR(sc->sc_dmai);
278 1.5.4.2 ad v = (unsigned long)DMAADDR(sc->sc_dma);
279 1.5.4.2 ad for (i = 0; i < (sc->sc_fbsize >> 16); i++) {
280 1.5.4.2 ad p[i] = ((uint32_t)v >> 16) + i;
281 1.5.4.2 ad }
282 1.5.4.2 ad
283 1.5.4.2 ad memset(KERNADDR(sc->sc_dma), 0x00, sc->sc_fbsize);
284 1.5.4.2 ad
285 1.5.4.2 ad printf("%s: allocated %d byte fb @ %p (%p)\n", sc->sc_dev.dv_xname,
286 1.5.4.2 ad sc->sc_fbsize, KERNADDR(sc->sc_dmai), KERNADDR(sc->sc_dma));
287 1.5.4.2 ad
288 1.5.4.2 ad #ifdef CRMFB_SHADOWFB
289 1.5.4.2 ad /* setup shadow framebuffer */
290 1.5.4.2 ad sc->sc_shadowfb = malloc(sc->sc_fbsize, M_DEVBUF, M_NOWAIT | M_ZERO);
291 1.5.4.2 ad if (sc->sc_shadowfb == NULL)
292 1.5.4.2 ad aprint_error("%s: WARNING: couldn't allocate shadow fb\n",
293 1.5.4.2 ad sc->sc_dev.dv_xname);
294 1.5.4.2 ad #endif
295 1.5.4.2 ad
296 1.5.4.2 ad ri = &crmfb_console_screen.scr_ri;
297 1.5.4.2 ad memset(ri, 0, sizeof(struct rasops_info));
298 1.5.4.2 ad
299 1.5.4.2 ad vcons_init(&sc->sc_vd, sc, &crmfb_defaultscreen, &crmfb_accessops);
300 1.5.4.2 ad sc->sc_vd.init_screen = crmfb_init_screen;
301 1.5.4.2 ad crmfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
302 1.5.4.2 ad vcons_init_screen(&sc->sc_vd, &crmfb_console_screen, 1, &defattr);
303 1.5.4.2 ad
304 1.5.4.2 ad crmfb_defaultscreen.ncols = ri->ri_cols;
305 1.5.4.2 ad crmfb_defaultscreen.nrows = ri->ri_rows;
306 1.5.4.2 ad crmfb_defaultscreen.textops = &ri->ri_ops;
307 1.5.4.2 ad crmfb_defaultscreen.capabilities = ri->ri_caps;
308 1.5.4.2 ad crmfb_defaultscreen.modecookie = NULL;
309 1.5.4.2 ad
310 1.5.4.3 ad crmfb_setup_video(sc, 8);
311 1.5.4.3 ad crmfb_setup_palette(sc);
312 1.5.4.2 ad
313 1.5.4.2 ad consdev = ARCBIOS->GetEnvironmentVariable("ConsoleOut");
314 1.5.4.2 ad if (consdev != NULL && strcmp(consdev, "video()") == 0) {
315 1.5.4.2 ad wsdisplay_cnattach(&crmfb_defaultscreen, ri, 0, 0, defattr);
316 1.5.4.2 ad aa.console = 1;
317 1.5.4.2 ad } else
318 1.5.4.2 ad aa.console = 0;
319 1.5.4.2 ad aa.scrdata = &crmfb_screenlist;
320 1.5.4.2 ad aa.accessops = &crmfb_accessops;
321 1.5.4.2 ad aa.accesscookie = &sc->sc_vd;
322 1.5.4.2 ad
323 1.5.4.2 ad config_found(self, &aa, wsemuldisplaydevprint);
324 1.5.4.2 ad
325 1.5.4.3 ad sc->sc_cur_x = 0;
326 1.5.4.3 ad sc->sc_cur_y = 0;
327 1.5.4.3 ad sc->sc_hot_x = 0;
328 1.5.4.3 ad sc->sc_hot_y = 0;
329 1.5.4.3 ad
330 1.5.4.2 ad return;
331 1.5.4.2 ad }
332 1.5.4.2 ad
333 1.5.4.2 ad int
334 1.5.4.2 ad crmfb_probe(void)
335 1.5.4.2 ad {
336 1.5.4.2 ad
337 1.5.4.2 ad if (mach_type != MACH_SGI_IP32)
338 1.5.4.2 ad return 0;
339 1.5.4.2 ad
340 1.5.4.2 ad return 1;
341 1.5.4.2 ad }
342 1.5.4.2 ad
343 1.5.4.2 ad static int
344 1.5.4.2 ad crmfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
345 1.5.4.2 ad {
346 1.5.4.2 ad struct vcons_data *vd;
347 1.5.4.2 ad struct crmfb_softc *sc;
348 1.5.4.2 ad struct vcons_screen *ms;
349 1.5.4.2 ad struct wsdisplay_fbinfo *wdf;
350 1.5.4.2 ad int nmode;
351 1.5.4.2 ad
352 1.5.4.2 ad vd = (struct vcons_data *)v;
353 1.5.4.2 ad sc = (struct crmfb_softc *)vd->cookie;
354 1.5.4.2 ad ms = (struct vcons_screen *)vd->active;
355 1.5.4.2 ad
356 1.5.4.2 ad switch (cmd) {
357 1.5.4.2 ad case WSDISPLAYIO_GTYPE:
358 1.5.4.2 ad /* not really, but who cares? */
359 1.5.4.3 ad /* wsfb does */
360 1.5.4.3 ad *(u_int *)data = WSDISPLAY_TYPE_CRIME;
361 1.5.4.2 ad return 0;
362 1.5.4.2 ad case WSDISPLAYIO_GINFO:
363 1.5.4.2 ad if (vd->active != NULL) {
364 1.5.4.2 ad wdf = (void *)data;
365 1.5.4.2 ad wdf->height = sc->sc_height;
366 1.5.4.2 ad wdf->width = sc->sc_width;
367 1.5.4.3 ad wdf->depth = 32;
368 1.5.4.2 ad wdf->cmsize = 256;
369 1.5.4.2 ad return 0;
370 1.5.4.2 ad } else
371 1.5.4.2 ad return ENODEV;
372 1.5.4.2 ad case WSDISPLAYIO_GETCMAP:
373 1.5.4.2 ad if (sc->sc_depth == 8)
374 1.5.4.2 ad return crmfb_getcmap(sc, (struct wsdisplay_cmap *)data);
375 1.5.4.2 ad else
376 1.5.4.2 ad return EINVAL;
377 1.5.4.2 ad case WSDISPLAYIO_PUTCMAP:
378 1.5.4.2 ad if (sc->sc_depth == 8)
379 1.5.4.2 ad return crmfb_putcmap(sc, (struct wsdisplay_cmap *)data);
380 1.5.4.2 ad else
381 1.5.4.2 ad return EINVAL;
382 1.5.4.2 ad case WSDISPLAYIO_LINEBYTES:
383 1.5.4.2 ad *(u_int *)data = sc->sc_width * sc->sc_depth / 8;
384 1.5.4.2 ad return 0;
385 1.5.4.2 ad case WSDISPLAYIO_SMODE:
386 1.5.4.2 ad nmode = *(int *)data;
387 1.5.4.2 ad if (nmode != sc->sc_wsmode) {
388 1.5.4.2 ad sc->sc_wsmode = nmode;
389 1.5.4.3 ad if (nmode == WSDISPLAYIO_MODE_EMUL) {
390 1.5.4.3 ad crmfb_setup_video(sc, 8);
391 1.5.4.3 ad crmfb_setup_palette(sc);
392 1.5.4.2 ad vcons_redraw_screen(vd->active);
393 1.5.4.3 ad } else {
394 1.5.4.3 ad crmfb_setup_video(sc, 32);
395 1.5.4.3 ad }
396 1.5.4.2 ad }
397 1.5.4.2 ad return 0;
398 1.5.4.2 ad case WSDISPLAYIO_SVIDEO:
399 1.5.4.2 ad case WSDISPLAYIO_GVIDEO:
400 1.5.4.2 ad return ENODEV; /* not supported yet */
401 1.5.4.2 ad
402 1.5.4.3 ad case WSDISPLAYIO_GCURPOS:
403 1.5.4.3 ad {
404 1.5.4.3 ad struct wsdisplay_curpos *pos;
405 1.5.4.3 ad
406 1.5.4.3 ad pos = (struct wsdisplay_curpos *)data;
407 1.5.4.3 ad pos->x = sc->sc_cur_x;
408 1.5.4.3 ad pos->y = sc->sc_cur_y;
409 1.5.4.3 ad }
410 1.5.4.3 ad return 0;
411 1.5.4.3 ad case WSDISPLAYIO_SCURPOS:
412 1.5.4.3 ad {
413 1.5.4.3 ad struct wsdisplay_curpos *pos;
414 1.5.4.3 ad
415 1.5.4.3 ad pos = (struct wsdisplay_curpos *)data;
416 1.5.4.3 ad crmfb_set_curpos(sc, pos->x, pos->y);
417 1.5.4.3 ad }
418 1.5.4.3 ad return 0;
419 1.5.4.3 ad case WSDISPLAYIO_GCURMAX:
420 1.5.4.3 ad {
421 1.5.4.3 ad struct wsdisplay_curpos *pos;
422 1.5.4.3 ad
423 1.5.4.3 ad pos = (struct wsdisplay_curpos *)data;
424 1.5.4.3 ad pos->x = 32;
425 1.5.4.3 ad pos->y = 32;
426 1.5.4.3 ad }
427 1.5.4.3 ad return 0;
428 1.5.4.3 ad case WSDISPLAYIO_GCURSOR:
429 1.5.4.3 ad {
430 1.5.4.3 ad struct wsdisplay_cursor *cu;
431 1.5.4.3 ad
432 1.5.4.3 ad cu = (struct wsdisplay_cursor *)data;
433 1.5.4.3 ad return crmfb_gcursor(sc, cu);
434 1.5.4.3 ad }
435 1.5.4.3 ad case WSDISPLAYIO_SCURSOR:
436 1.5.4.3 ad {
437 1.5.4.3 ad struct wsdisplay_cursor *cu;
438 1.5.4.3 ad
439 1.5.4.3 ad cu = (struct wsdisplay_cursor *)data;
440 1.5.4.3 ad return crmfb_scursor(sc, cu);
441 1.5.4.3 ad }
442 1.5.4.3 ad }
443 1.5.4.2 ad return EPASSTHROUGH;
444 1.5.4.2 ad }
445 1.5.4.2 ad
446 1.5.4.2 ad static paddr_t
447 1.5.4.2 ad crmfb_mmap(void *v, void *vs, off_t offset, int prot)
448 1.5.4.2 ad {
449 1.5.4.2 ad struct vcons_data *vd;
450 1.5.4.2 ad struct crmfb_softc *sc;
451 1.5.4.2 ad paddr_t pa;
452 1.5.4.2 ad
453 1.5.4.2 ad vd = (struct vcons_data *)v;
454 1.5.4.2 ad sc = (struct crmfb_softc *)vd->cookie;
455 1.5.4.2 ad
456 1.5.4.3 ad #if 1
457 1.5.4.2 ad if (offset >= 0 && offset < sc->sc_fbsize) {
458 1.5.4.2 ad pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
459 1.5.4.2 ad sc->sc_dma.nsegs, offset, prot,
460 1.5.4.2 ad BUS_DMA_WAITOK | BUS_DMA_COHERENT);
461 1.5.4.2 ad return pa;
462 1.5.4.2 ad }
463 1.5.4.3 ad #else
464 1.5.4.3 ad if (offset >= 0 && offset < sc->sc_fbsize) {
465 1.5.4.3 ad pa = bus_space_mmap(SGIMIPS_BUS_SPACE_NORMAL, sc->sc_fbh,
466 1.5.4.3 ad offset, prot, SGIMIPS_BUS_SPACE_NORMAL);
467 1.5.4.3 ad printf("%s: %08llx -> %llx\n", __func__, offset, pa);
468 1.5.4.3 ad return pa;
469 1.5.4.3 ad }
470 1.5.4.3 ad #endif
471 1.5.4.2 ad return -1;
472 1.5.4.2 ad }
473 1.5.4.2 ad
474 1.5.4.2 ad static void
475 1.5.4.2 ad crmfb_init_screen(void *c, struct vcons_screen *scr, int existing,
476 1.5.4.2 ad long *defattr)
477 1.5.4.2 ad {
478 1.5.4.2 ad struct crmfb_softc *sc;
479 1.5.4.2 ad struct rasops_info *ri;
480 1.5.4.2 ad
481 1.5.4.2 ad sc = (struct crmfb_softc *)c;
482 1.5.4.2 ad ri = &scr->scr_ri;
483 1.5.4.2 ad
484 1.5.4.2 ad ri->ri_flg = RI_CENTER;
485 1.5.4.2 ad ri->ri_depth = sc->sc_depth;
486 1.5.4.2 ad ri->ri_width = sc->sc_width;
487 1.5.4.2 ad ri->ri_height = sc->sc_height;
488 1.5.4.2 ad ri->ri_stride = ri->ri_width * (ri->ri_depth / 8);
489 1.5.4.2 ad
490 1.5.4.2 ad switch (ri->ri_depth) {
491 1.5.4.2 ad case 16:
492 1.5.4.2 ad ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
493 1.5.4.2 ad ri->ri_rpos = 10;
494 1.5.4.2 ad ri->ri_gpos = 5;
495 1.5.4.2 ad ri->ri_bpos = 0;
496 1.5.4.2 ad break;
497 1.5.4.2 ad case 32:
498 1.5.4.2 ad ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
499 1.5.4.2 ad ri->ri_rpos = 8;
500 1.5.4.2 ad ri->ri_gpos = 16;
501 1.5.4.2 ad ri->ri_bpos = 24;
502 1.5.4.2 ad break;
503 1.5.4.2 ad }
504 1.5.4.2 ad
505 1.5.4.2 ad if (sc->sc_shadowfb == NULL)
506 1.5.4.2 ad ri->ri_bits = KERNADDR(sc->sc_dma);
507 1.5.4.2 ad else {
508 1.5.4.2 ad ri->ri_bits = sc->sc_shadowfb;
509 1.5.4.2 ad ri->ri_hwbits = KERNADDR(sc->sc_dma);
510 1.5.4.2 ad }
511 1.5.4.2 ad
512 1.5.4.2 ad if (existing)
513 1.5.4.2 ad ri->ri_flg |= RI_CLEAR;
514 1.5.4.2 ad
515 1.5.4.2 ad rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
516 1.5.4.2 ad ri->ri_caps = WSSCREEN_WSCOLORS;
517 1.5.4.2 ad rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
518 1.5.4.2 ad ri->ri_width / ri->ri_font->fontwidth);
519 1.5.4.2 ad ri->ri_hw = scr;
520 1.5.4.2 ad
521 1.5.4.2 ad return;
522 1.5.4.2 ad }
523 1.5.4.2 ad
524 1.5.4.2 ad static int
525 1.5.4.2 ad crmfb_putcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
526 1.5.4.2 ad {
527 1.5.4.2 ad u_int idx, cnt;
528 1.5.4.2 ad u_char r[256], g[256], b[256];
529 1.5.4.2 ad u_char *rp, *gp, *bp;
530 1.5.4.2 ad int rv, i;
531 1.5.4.2 ad
532 1.5.4.2 ad idx = cm->index;
533 1.5.4.2 ad cnt = cm->count;
534 1.5.4.2 ad
535 1.5.4.2 ad if (idx >= 255 || cnt > 256 || idx + cnt > 256)
536 1.5.4.2 ad return EINVAL;
537 1.5.4.2 ad
538 1.5.4.2 ad rv = copyin(cm->red, &r[idx], cnt);
539 1.5.4.2 ad if (rv)
540 1.5.4.2 ad return rv;
541 1.5.4.2 ad rv = copyin(cm->green, &g[idx], cnt);
542 1.5.4.2 ad if (rv)
543 1.5.4.2 ad return rv;
544 1.5.4.2 ad rv = copyin(cm->blue, &b[idx], cnt);
545 1.5.4.2 ad if (rv)
546 1.5.4.2 ad return rv;
547 1.5.4.2 ad
548 1.5.4.2 ad memcpy(&sc->sc_cmap_red[idx], &r[idx], cnt);
549 1.5.4.2 ad memcpy(&sc->sc_cmap_green[idx], &g[idx], cnt);
550 1.5.4.2 ad memcpy(&sc->sc_cmap_blue[idx], &b[idx], cnt);
551 1.5.4.2 ad
552 1.5.4.2 ad rp = &sc->sc_cmap_red[idx];
553 1.5.4.2 ad gp = &sc->sc_cmap_green[idx];
554 1.5.4.2 ad bp = &sc->sc_cmap_blue[idx];
555 1.5.4.2 ad
556 1.5.4.2 ad for (i = 0; i < cnt; i++) {
557 1.5.4.2 ad crmfb_set_palette(sc, idx, *rp, *gp, *bp);
558 1.5.4.2 ad idx++;
559 1.5.4.2 ad rp++, gp++, bp++;
560 1.5.4.2 ad }
561 1.5.4.2 ad
562 1.5.4.2 ad return 0;
563 1.5.4.2 ad }
564 1.5.4.2 ad
565 1.5.4.2 ad static int
566 1.5.4.2 ad crmfb_getcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
567 1.5.4.2 ad {
568 1.5.4.2 ad u_int idx, cnt;
569 1.5.4.2 ad int rv;
570 1.5.4.2 ad
571 1.5.4.2 ad idx = cm->index;
572 1.5.4.2 ad cnt = cm->count;
573 1.5.4.2 ad
574 1.5.4.2 ad if (idx >= 255 || cnt > 256 || idx + cnt > 256)
575 1.5.4.2 ad return EINVAL;
576 1.5.4.2 ad
577 1.5.4.2 ad rv = copyout(&sc->sc_cmap_red[idx], cm->red, cnt);
578 1.5.4.2 ad if (rv)
579 1.5.4.2 ad return rv;
580 1.5.4.2 ad rv = copyout(&sc->sc_cmap_green[idx], cm->green, cnt);
581 1.5.4.2 ad if (rv)
582 1.5.4.2 ad return rv;
583 1.5.4.2 ad rv = copyout(&sc->sc_cmap_blue[idx], cm->blue, cnt);
584 1.5.4.2 ad if (rv)
585 1.5.4.2 ad return rv;
586 1.5.4.2 ad
587 1.5.4.2 ad return 0;
588 1.5.4.2 ad }
589 1.5.4.2 ad
590 1.5.4.2 ad static void
591 1.5.4.2 ad crmfb_set_palette(struct crmfb_softc *sc, int reg, uint8_t r, uint8_t g,
592 1.5.4.2 ad uint8_t b)
593 1.5.4.2 ad {
594 1.5.4.2 ad uint32_t val;
595 1.5.4.2 ad
596 1.5.4.2 ad if (reg > 255 || sc->sc_depth != 8)
597 1.5.4.2 ad return;
598 1.5.4.2 ad
599 1.5.4.2 ad while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP_FIFO) >= 63)
600 1.5.4.2 ad DELAY(10);
601 1.5.4.2 ad
602 1.5.4.2 ad val = (r << 24) | (g << 16) | (b << 8);
603 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CMAP + (reg * 4), val);
604 1.5.4.2 ad
605 1.5.4.2 ad return;
606 1.5.4.2 ad }
607 1.5.4.3 ad
608 1.5.4.3 ad static int
609 1.5.4.3 ad crmfb_set_curpos(struct crmfb_softc *sc, int x, int y)
610 1.5.4.3 ad {
611 1.5.4.3 ad uint32_t val;
612 1.5.4.3 ad
613 1.5.4.3 ad sc->sc_cur_x = x;
614 1.5.4.3 ad sc->sc_cur_y = y;
615 1.5.4.3 ad
616 1.5.4.3 ad val = ((x - sc->sc_hot_x) & 0xffff) | ((y - sc->sc_hot_y) << 16);
617 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CURSOR_POS, val);
618 1.5.4.3 ad
619 1.5.4.3 ad return 0;
620 1.5.4.3 ad }
621 1.5.4.3 ad
622 1.5.4.3 ad static int
623 1.5.4.3 ad crmfb_gcursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
624 1.5.4.3 ad {
625 1.5.4.3 ad /* do nothing for now */
626 1.5.4.3 ad return 0;
627 1.5.4.3 ad }
628 1.5.4.3 ad
629 1.5.4.3 ad static int
630 1.5.4.3 ad crmfb_scursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
631 1.5.4.3 ad {
632 1.5.4.3 ad if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
633 1.5.4.3 ad
634 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, cur->enable ? 1 : 0);
635 1.5.4.3 ad }
636 1.5.4.3 ad if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
637 1.5.4.3 ad
638 1.5.4.3 ad sc->sc_hot_x = cur->hot.x;
639 1.5.4.3 ad sc->sc_hot_y = cur->hot.y;
640 1.5.4.3 ad }
641 1.5.4.3 ad if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
642 1.5.4.3 ad
643 1.5.4.3 ad crmfb_set_curpos(sc, cur->pos.x, cur->pos.y);
644 1.5.4.3 ad }
645 1.5.4.3 ad if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
646 1.5.4.3 ad int i;
647 1.5.4.3 ad uint32_t val;
648 1.5.4.3 ad
649 1.5.4.3 ad for (i = 0; i < cur->cmap.count; i++) {
650 1.5.4.3 ad val = (cur->cmap.red[i] << 24) |
651 1.5.4.3 ad (cur->cmap.green[i] << 16) |
652 1.5.4.3 ad (cur->cmap.blue[i] << 8);
653 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CURSOR_CMAP0 +
654 1.5.4.3 ad ((i + cur->cmap.index) << 2), val);
655 1.5.4.3 ad }
656 1.5.4.3 ad }
657 1.5.4.3 ad if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
658 1.5.4.3 ad
659 1.5.4.3 ad int i, j, cnt = 0;
660 1.5.4.3 ad uint32_t latch = 0, omask;
661 1.5.4.3 ad uint8_t imask;
662 1.5.4.3 ad for (i = 0; i < 64; i++) {
663 1.5.4.3 ad omask = 0x80000000;
664 1.5.4.3 ad imask = 0x01;
665 1.5.4.3 ad cur->image[cnt] &= cur->mask[cnt];
666 1.5.4.3 ad for (j = 0; j < 8; j++) {
667 1.5.4.3 ad if (cur->image[cnt] & imask)
668 1.5.4.3 ad latch |= omask;
669 1.5.4.3 ad omask >>= 1;
670 1.5.4.3 ad if (cur->mask[cnt] & imask)
671 1.5.4.3 ad latch |= omask;
672 1.5.4.3 ad omask >>= 1;
673 1.5.4.3 ad imask <<= 1;
674 1.5.4.3 ad }
675 1.5.4.3 ad cnt++;
676 1.5.4.3 ad imask = 0x01;
677 1.5.4.3 ad cur->image[cnt] &= cur->mask[cnt];
678 1.5.4.3 ad for (j = 0; j < 8; j++) {
679 1.5.4.3 ad if (cur->image[cnt] & imask)
680 1.5.4.3 ad latch |= omask;
681 1.5.4.3 ad omask >>= 1;
682 1.5.4.3 ad if (cur->mask[cnt] & imask)
683 1.5.4.3 ad latch |= omask;
684 1.5.4.3 ad omask >>= 1;
685 1.5.4.3 ad imask <<= 1;
686 1.5.4.3 ad }
687 1.5.4.3 ad cnt++;
688 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CURSOR_BITMAP + (i << 2),
689 1.5.4.3 ad latch);
690 1.5.4.3 ad latch = 0;
691 1.5.4.3 ad }
692 1.5.4.3 ad }
693 1.5.4.3 ad return 0;
694 1.5.4.3 ad }
695 1.5.4.3 ad
696 1.5.4.3 ad static inline void
697 1.5.4.3 ad crmfb_write_reg(struct crmfb_softc *sc, int offset, uint32_t val)
698 1.5.4.3 ad {
699 1.5.4.3 ad
700 1.5.4.3 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, val);
701 1.5.4.3 ad wbflush();
702 1.5.4.3 ad }
703 1.5.4.3 ad
704 1.5.4.3 ad static int
705 1.5.4.3 ad crmfb_setup_video(struct crmfb_softc *sc, int depth)
706 1.5.4.3 ad {
707 1.5.4.3 ad uint32_t d, h;
708 1.5.4.3 ad int i;
709 1.5.4.3 ad
710 1.5.4.3 ad /* disable DMA */
711 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL);
712 1.5.4.3 ad d &= ~(1 << CRMFB_OVR_CONTROL_DMAEN_SHIFT);
713 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_OVR_CONTROL, d);
714 1.5.4.3 ad DELAY(50000);
715 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
716 1.5.4.3 ad d &= ~(1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
717 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
718 1.5.4.3 ad DELAY(50000);
719 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_DID_CONTROL, 0);
720 1.5.4.3 ad DELAY(50000);
721 1.5.4.3 ad
722 1.5.4.3 ad /* ensure that CRM starts drawing at the top left of the screen
723 1.5.4.3 ad * when we re-enable DMA later
724 1.5.4.3 ad */
725 1.5.4.3 ad d = (1 << CRMFB_VT_XY_FREEZE_SHIFT);
726 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_VT_XY, d);
727 1.5.4.3 ad delay(1000);
728 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
729 1.5.4.3 ad d &= ~(1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
730 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
731 1.5.4.3 ad delay(1000);
732 1.5.4.3 ad
733 1.5.4.3 ad /* reset FIFO */
734 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
735 1.5.4.3 ad d |= (1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
736 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
737 1.5.4.3 ad d &= ~(1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
738 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
739 1.5.4.3 ad
740 1.5.4.3 ad /* setup colour mode */
741 1.5.4.3 ad switch (depth) {
742 1.5.4.3 ad case 8:
743 1.5.4.3 ad h = CRMFB_MODE_TYP_I8;
744 1.5.4.3 ad break;
745 1.5.4.3 ad case 16:
746 1.5.4.3 ad h = CRMFB_MODE_TYP_ARGB5;
747 1.5.4.3 ad break;
748 1.5.4.3 ad case 32:
749 1.5.4.3 ad h = CRMFB_MODE_TYP_RGB8;
750 1.5.4.3 ad break;
751 1.5.4.3 ad default:
752 1.5.4.3 ad panic("Unsupported depth");
753 1.5.4.3 ad }
754 1.5.4.3 ad d = h << CRMFB_MODE_TYP_SHIFT;
755 1.5.4.3 ad d |= CRMFB_MODE_BUF_BOTH << CRMFB_MODE_BUF_SHIFT;
756 1.5.4.3 ad for (i = 0; i < (32 * 4); i += 4)
757 1.5.4.3 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_MODE + i, d);
758 1.5.4.3 ad wbflush();
759 1.5.4.3 ad
760 1.5.4.3 ad /* setup tile pointer, but don't turn on DMA yet! */
761 1.5.4.3 ad h = DMAADDR(sc->sc_dmai);
762 1.5.4.3 ad d = (h >> 9) << CRMFB_FRM_CONTROL_TILEPTR_SHIFT;
763 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
764 1.5.4.3 ad
765 1.5.4.3 ad /* init framebuffer width and pixel size */
766 1.5.4.3 ad d = (1 << CRMFB_FRM_TILESIZE_WIDTH_SHIFT);
767 1.5.4.3 ad switch (depth) {
768 1.5.4.3 ad case 8:
769 1.5.4.3 ad h = CRMFB_FRM_TILESIZE_DEPTH_8;
770 1.5.4.3 ad break;
771 1.5.4.3 ad case 16:
772 1.5.4.3 ad h = CRMFB_FRM_TILESIZE_DEPTH_16;
773 1.5.4.3 ad break;
774 1.5.4.3 ad case 32:
775 1.5.4.3 ad h = CRMFB_FRM_TILESIZE_DEPTH_32;
776 1.5.4.3 ad break;
777 1.5.4.3 ad default:
778 1.5.4.3 ad panic("Unsupported depth");
779 1.5.4.3 ad }
780 1.5.4.3 ad d |= (h << CRMFB_FRM_TILESIZE_DEPTH_SHIFT);
781 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
782 1.5.4.3 ad
783 1.5.4.3 ad /* init framebuffer height, we use the trick that the Linux
784 1.5.4.3 ad * driver uses to fool the CRM out of tiled mode and into
785 1.5.4.3 ad * linear mode
786 1.5.4.3 ad */
787 1.5.4.3 ad h = sc->sc_width * sc->sc_height / (512 / (depth >> 3));
788 1.5.4.3 ad d = h << CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT;
789 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_PIXSIZE, d);
790 1.5.4.3 ad
791 1.5.4.3 ad /* turn off firmware overlay and hardware cursor */
792 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_OVR_WIDTH_TILE, 0);
793 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, 0);
794 1.5.4.3 ad
795 1.5.4.3 ad /* enable drawing again */
796 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
797 1.5.4.3 ad d |= (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
798 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
799 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_VT_XY, 0);
800 1.5.4.3 ad
801 1.5.4.3 ad /* turn on DMA for the framebuffer */
802 1.5.4.3 ad d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
803 1.5.4.3 ad d |= (1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
804 1.5.4.3 ad crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
805 1.5.4.3 ad
806 1.5.4.3 ad sc->sc_depth = depth;
807 1.5.4.3 ad return 0;
808 1.5.4.3 ad }
809 1.5.4.3 ad
810 1.5.4.3 ad static void
811 1.5.4.3 ad crmfb_setup_palette(struct crmfb_softc *sc)
812 1.5.4.3 ad {
813 1.5.4.3 ad int i;
814 1.5.4.3 ad
815 1.5.4.3 ad for (i = 0; i < 256; i++) {
816 1.5.4.3 ad crmfb_set_palette(sc, i, rasops_cmap[(i * 3) + 2],
817 1.5.4.3 ad rasops_cmap[(i * 3) + 1], rasops_cmap[(i * 3) + 0]);
818 1.5.4.3 ad sc->sc_cmap_red[i] = rasops_cmap[(i * 3) + 2];
819 1.5.4.3 ad sc->sc_cmap_green[i] = rasops_cmap[(i * 3) + 1];
820 1.5.4.3 ad sc->sc_cmap_blue[i] = rasops_cmap[(i * 3) + 0];
821 1.5.4.3 ad }
822 1.5.4.3 ad }
823