xref: /freebsd/sys/arm/broadcom/bcm2835/bcm2835_fb.c (revision 526e1dc1c0d052b9d2a6cd6da7a16eb09c971c54)
1 /*-
2  * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24  * SUCH DAMAGE.
25  *
26  */
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29 
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bio.h>
33 #include <sys/bus.h>
34 #include <sys/conf.h>
35 #include <sys/endian.h>
36 #include <sys/kernel.h>
37 #include <sys/kthread.h>
38 #include <sys/lock.h>
39 #include <sys/malloc.h>
40 #include <sys/module.h>
41 #include <sys/mutex.h>
42 #include <sys/queue.h>
43 #include <sys/resource.h>
44 #include <sys/rman.h>
45 #include <sys/time.h>
46 #include <sys/timetc.h>
47 #include <sys/fbio.h>
48 #include <sys/consio.h>
49 
50 #include <sys/kdb.h>
51 
52 #include <machine/bus.h>
53 #include <machine/cpu.h>
54 #include <machine/cpufunc.h>
55 #include <machine/resource.h>
56 #include <machine/frame.h>
57 #include <machine/intr.h>
58 
59 #include <dev/fdt/fdt_common.h>
60 #include <dev/ofw/ofw_bus.h>
61 #include <dev/ofw/ofw_bus_subr.h>
62 
63 #include <dev/fb/fbreg.h>
64 #include <dev/syscons/syscons.h>
65 
66 #include <arm/broadcom/bcm2835/bcm2835_mbox.h>
67 #include <arm/broadcom/bcm2835/bcm2835_vcbus.h>
68 
69 #define	BCMFB_FONT_HEIGHT	16
70 
71 struct argb {
72 	uint8_t		a;
73 	uint8_t		r;
74 	uint8_t		g;
75 	uint8_t		b;
76 };
77 
78 static struct argb bcmfb_palette[16] = {
79 	{0x00, 0x00, 0x00, 0x00},
80 	{0x00, 0x00, 0x00, 0xaa},
81 	{0x00, 0x00, 0xaa, 0x00},
82 	{0x00, 0x00, 0xaa, 0xaa},
83 	{0x00, 0xaa, 0x00, 0x00},
84 	{0x00, 0xaa, 0x00, 0xaa},
85 	{0x00, 0xaa, 0x55, 0x00},
86 	{0x00, 0xaa, 0xaa, 0xaa},
87 	{0x00, 0x55, 0x55, 0x55},
88 	{0x00, 0x55, 0x55, 0xff},
89 	{0x00, 0x55, 0xff, 0x55},
90 	{0x00, 0x55, 0xff, 0xff},
91 	{0x00, 0xff, 0x55, 0x55},
92 	{0x00, 0xff, 0x55, 0xff},
93 	{0x00, 0xff, 0xff, 0x55},
94 	{0x00, 0xff, 0xff, 0xff}
95 };
96 
97 #define FB_WIDTH		640
98 #define FB_HEIGHT		480
99 #define FB_DEPTH		24
100 
101 struct bcm_fb_config {
102 	uint32_t	xres;
103 	uint32_t	yres;
104 	uint32_t	vxres;
105 	uint32_t	vyres;
106 	uint32_t	pitch;
107 	uint32_t	bpp;
108 	uint32_t	xoffset;
109 	uint32_t	yoffset;
110 	/* Filled by videocore */
111 	uint32_t	base;
112 	uint32_t	screen_size;
113 };
114 
115 struct bcmsc_softc {
116 	device_t		dev;
117 	struct cdev *		cdev;
118 	struct mtx		mtx;
119 	bus_dma_tag_t		dma_tag;
120 	bus_dmamap_t		dma_map;
121 	struct bcm_fb_config*	fb_config;
122 	bus_addr_t		fb_config_phys;
123 	struct intr_config_hook	init_hook;
124 
125 };
126 
127 struct video_adapter_softc {
128 	/* Videoadpater part */
129 	video_adapter_t	va;
130 	int		console;
131 
132 	intptr_t	fb_addr;
133 	unsigned int	fb_size;
134 
135 	unsigned int	height;
136 	unsigned int	width;
137 	unsigned int	depth;
138 	unsigned int	stride;
139 
140 	unsigned int	xmargin;
141 	unsigned int	ymargin;
142 
143 	unsigned char	*font;
144 	int		initialized;
145 };
146 
147 static struct bcmsc_softc *bcmsc_softc;
148 static struct video_adapter_softc va_softc;
149 
150 #define	bcm_fb_lock(_sc)	mtx_lock(&(_sc)->mtx)
151 #define	bcm_fb_unlock(_sc)	mtx_unlock(&(_sc)->mtx)
152 #define	bcm_fb_lock_assert(sc)	mtx_assert(&(_sc)->mtx, MA_OWNED)
153 
154 static int bcm_fb_probe(device_t);
155 static int bcm_fb_attach(device_t);
156 static void bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err);
157 static void bcmfb_update_margins(video_adapter_t *adp);
158 static int bcmfb_configure(int);
159 
160 static void
161 bcm_fb_init(void *arg)
162 {
163 	struct bcmsc_softc *sc = arg;
164 	struct video_adapter_softc *va_sc = &va_softc;
165 	int err;
166 	volatile struct bcm_fb_config*	fb_config = sc->fb_config;
167 	phandle_t node;
168 	pcell_t cell;
169 
170 	node = ofw_bus_get_node(sc->dev);
171 
172 	fb_config->xres = 0;
173 	fb_config->yres = 0;
174 	fb_config->bpp = 0;
175 
176 	if ((OF_getprop(node, "broadcom,width", &cell, sizeof(cell))) > 0)
177 		fb_config->xres = (int)fdt32_to_cpu(cell);
178 	if (fb_config->xres == 0)
179 		fb_config->xres = FB_WIDTH;
180 
181 	if ((OF_getprop(node, "broadcom,height", &cell, sizeof(cell))) > 0)
182 		fb_config->yres = (uint32_t)fdt32_to_cpu(cell);
183 	if (fb_config->yres == 0)
184 		fb_config->yres = FB_HEIGHT;
185 
186 	if ((OF_getprop(node, "broadcom,depth", &cell, sizeof(cell))) > 0)
187 		fb_config->bpp = (uint32_t)fdt32_to_cpu(cell);
188 	if (fb_config->bpp == 0)
189 		fb_config->bpp = FB_DEPTH;
190 
191 	fb_config->vxres = 0;
192 	fb_config->vyres = 0;
193 	fb_config->xoffset = 0;
194 	fb_config->yoffset = 0;
195 	fb_config->base = 0;
196 	fb_config->pitch = 0;
197 	fb_config->screen_size = 0;
198 
199 	bus_dmamap_sync(sc->dma_tag, sc->dma_map,
200 		BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
201 	bcm_mbox_write(BCM2835_MBOX_CHAN_FB, sc->fb_config_phys);
202 	bcm_mbox_read(BCM2835_MBOX_CHAN_FB, &err);
203 	bus_dmamap_sync(sc->dma_tag, sc->dma_map,
204 		BUS_DMASYNC_POSTREAD);
205 
206 	if (fb_config->base != 0) {
207 		device_printf(sc->dev, "%dx%d(%dx%d@%d,%d) %dbpp\n",
208 			fb_config->xres, fb_config->yres,
209 			fb_config->vxres, fb_config->vyres,
210 			fb_config->xoffset, fb_config->yoffset,
211 			fb_config->bpp);
212 
213 
214 		device_printf(sc->dev, "pitch %d, base 0x%08x, screen_size %d\n",
215 			fb_config->pitch, fb_config->base,
216 			fb_config->screen_size);
217 
218 		va_sc->fb_addr = (intptr_t)pmap_mapdev(fb_config->base, fb_config->screen_size);
219 		va_sc->fb_size = fb_config->screen_size;
220 		va_sc->depth = fb_config->bpp;
221 		va_sc->stride = fb_config->pitch;
222 
223 		va_sc->width = fb_config->xres;
224 		va_sc->height = fb_config->yres;
225 		bcmfb_update_margins(&va_sc->va);
226 	}
227 	else {
228 		device_printf(sc->dev, "Failed to set framebuffer info\n");
229 		return;
230 	}
231 
232 	config_intrhook_disestablish(&sc->init_hook);
233 }
234 
235 static int
236 bcm_fb_probe(device_t dev)
237 {
238 	int error = 0;
239 
240 	if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb"))
241 		return (ENXIO);
242 
243 	device_set_desc(dev, "BCM2835 framebuffer device");
244 
245 	error = sc_probe_unit(device_get_unit(dev),
246 	    device_get_flags(dev) | SC_AUTODETECT_KBD);
247 	if (error != 0)
248 		return (error);
249 
250 
251 	return (BUS_PROBE_DEFAULT);
252 }
253 
254 static int
255 bcm_fb_attach(device_t dev)
256 {
257 	struct bcmsc_softc *sc = device_get_softc(dev);
258 	int dma_size = sizeof(struct bcm_fb_config);
259 	int err;
260 
261 	if (bcmsc_softc)
262 		return (ENXIO);
263 
264 	bcmsc_softc = sc;
265 
266 	sc->dev = dev;
267 	mtx_init(&sc->mtx, "bcm2835fb", "fb", MTX_DEF);
268 
269 	err = bus_dma_tag_create(
270 	    bus_get_dma_tag(sc->dev),
271 	    PAGE_SIZE, 0,		/* alignment, boundary */
272 	    BUS_SPACE_MAXADDR_32BIT,	/* lowaddr */
273 	    BUS_SPACE_MAXADDR,		/* highaddr */
274 	    NULL, NULL,			/* filter, filterarg */
275 	    dma_size, 1,		/* maxsize, nsegments */
276 	    dma_size, 0,		/* maxsegsize, flags */
277 	    NULL, NULL,			/* lockfunc, lockarg */
278 	    &sc->dma_tag);
279 
280 	err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_config,
281 	    0, &sc->dma_map);
282 	if (err) {
283 		device_printf(dev, "cannot allocate framebuffer\n");
284 		goto fail;
285 	}
286 
287 	err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_config,
288 	    dma_size, bcm_fb_dmamap_cb, &sc->fb_config_phys, BUS_DMA_NOWAIT);
289 
290 	if (err) {
291 		device_printf(dev, "cannot load DMA map\n");
292 		goto fail;
293 	}
294 
295 	err = (sc_attach_unit(device_get_unit(dev),
296 	    device_get_flags(dev) | SC_AUTODETECT_KBD));
297 
298 	if (err) {
299 		device_printf(dev, "failed to attach syscons\n");
300 		goto fail;
301 	}
302 
303 	/*
304 	 * We have to wait until interrupts are enabled.
305 	 * Mailbox relies on it to get data from VideoCore
306 	 */
307         sc->init_hook.ich_func = bcm_fb_init;
308         sc->init_hook.ich_arg = sc;
309 
310         if (config_intrhook_establish(&sc->init_hook) != 0) {
311 		device_printf(dev, "failed to establish intrhook\n");
312                 return (ENOMEM);
313 	}
314 
315 	return (0);
316 
317 fail:
318 	return (ENXIO);
319 }
320 
321 
322 static void
323 bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err)
324 {
325 	bus_addr_t *addr;
326 
327 	if (err)
328 		return;
329 
330 	addr = (bus_addr_t*)arg;
331 	*addr = PHYS_TO_VCBUS(segs[0].ds_addr);
332 }
333 
334 static device_method_t bcm_fb_methods[] = {
335 	/* Device interface */
336 	DEVMETHOD(device_probe,		bcm_fb_probe),
337 	DEVMETHOD(device_attach,	bcm_fb_attach),
338 
339 	{ 0, 0 }
340 };
341 
342 static devclass_t bcm_fb_devclass;
343 
344 static driver_t bcm_fb_driver = {
345 	"fb",
346 	bcm_fb_methods,
347 	sizeof(struct bcmsc_softc),
348 };
349 
350 DRIVER_MODULE(bcm2835fb, fdtbus, bcm_fb_driver, bcm_fb_devclass, 0, 0);
351 
352 /*
353  * Video driver routines and glue.
354  */
355 static vi_probe_t		bcmfb_probe;
356 static vi_init_t		bcmfb_init;
357 static vi_get_info_t		bcmfb_get_info;
358 static vi_query_mode_t		bcmfb_query_mode;
359 static vi_set_mode_t		bcmfb_set_mode;
360 static vi_save_font_t		bcmfb_save_font;
361 static vi_load_font_t		bcmfb_load_font;
362 static vi_show_font_t		bcmfb_show_font;
363 static vi_save_palette_t	bcmfb_save_palette;
364 static vi_load_palette_t	bcmfb_load_palette;
365 static vi_set_border_t		bcmfb_set_border;
366 static vi_save_state_t		bcmfb_save_state;
367 static vi_load_state_t		bcmfb_load_state;
368 static vi_set_win_org_t		bcmfb_set_win_org;
369 static vi_read_hw_cursor_t	bcmfb_read_hw_cursor;
370 static vi_set_hw_cursor_t	bcmfb_set_hw_cursor;
371 static vi_set_hw_cursor_shape_t	bcmfb_set_hw_cursor_shape;
372 static vi_blank_display_t	bcmfb_blank_display;
373 static vi_mmap_t		bcmfb_mmap;
374 static vi_ioctl_t		bcmfb_ioctl;
375 static vi_clear_t		bcmfb_clear;
376 static vi_fill_rect_t		bcmfb_fill_rect;
377 static vi_bitblt_t		bcmfb_bitblt;
378 static vi_diag_t		bcmfb_diag;
379 static vi_save_cursor_palette_t	bcmfb_save_cursor_palette;
380 static vi_load_cursor_palette_t	bcmfb_load_cursor_palette;
381 static vi_copy_t		bcmfb_copy;
382 static vi_putp_t		bcmfb_putp;
383 static vi_putc_t		bcmfb_putc;
384 static vi_puts_t		bcmfb_puts;
385 static vi_putm_t		bcmfb_putm;
386 
387 static video_switch_t bcmfbvidsw = {
388 	.probe			= bcmfb_probe,
389 	.init			= bcmfb_init,
390 	.get_info		= bcmfb_get_info,
391 	.query_mode		= bcmfb_query_mode,
392 	.set_mode		= bcmfb_set_mode,
393 	.save_font		= bcmfb_save_font,
394 	.load_font		= bcmfb_load_font,
395 	.show_font		= bcmfb_show_font,
396 	.save_palette		= bcmfb_save_palette,
397 	.load_palette		= bcmfb_load_palette,
398 	.set_border		= bcmfb_set_border,
399 	.save_state		= bcmfb_save_state,
400 	.load_state		= bcmfb_load_state,
401 	.set_win_org		= bcmfb_set_win_org,
402 	.read_hw_cursor		= bcmfb_read_hw_cursor,
403 	.set_hw_cursor		= bcmfb_set_hw_cursor,
404 	.set_hw_cursor_shape	= bcmfb_set_hw_cursor_shape,
405 	.blank_display		= bcmfb_blank_display,
406 	.mmap			= bcmfb_mmap,
407 	.ioctl			= bcmfb_ioctl,
408 	.clear			= bcmfb_clear,
409 	.fill_rect		= bcmfb_fill_rect,
410 	.bitblt			= bcmfb_bitblt,
411 	.diag			= bcmfb_diag,
412 	.save_cursor_palette	= bcmfb_save_cursor_palette,
413 	.load_cursor_palette	= bcmfb_load_cursor_palette,
414 	.copy			= bcmfb_copy,
415 	.putp			= bcmfb_putp,
416 	.putc			= bcmfb_putc,
417 	.puts			= bcmfb_puts,
418 	.putm			= bcmfb_putm,
419 };
420 
421 VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure);
422 
423 extern sc_rndr_sw_t txtrndrsw;
424 RENDERER(bcmfb, 0, txtrndrsw, gfb_set);
425 RENDERER_MODULE(bcmfb, gfb_set);
426 
427 static uint16_t bcmfb_static_window[ROW*COL];
428 extern u_char dflt_font_16[];
429 
430 /*
431  * Update videoadapter settings after changing resolution
432  */
433 static void
434 bcmfb_update_margins(video_adapter_t *adp)
435 {
436 	struct video_adapter_softc *sc;
437 	video_info_t *vi;
438 
439 	sc = (struct video_adapter_softc *)adp;
440 	vi = &adp->va_info;
441 
442 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
443 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
444 }
445 
446 static int
447 bcmfb_configure(int flags)
448 {
449 	struct video_adapter_softc *va_sc;
450 
451 	va_sc = &va_softc;
452 	phandle_t display, root;
453 	pcell_t cell;
454 
455 	if (va_sc->initialized)
456 		return (0);
457 
458 	va_sc->width = 0;
459 	va_sc->height = 0;
460 
461 	/*
462 	 * It seems there is no way to let syscons framework know
463 	 * that framebuffer resolution has changed. So just try
464 	 * to fetch data from FDT and go with defaults if failed
465 	 */
466 	root = OF_finddevice("/");
467 	if ((root != 0) &&
468 	    (display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) {
469 		if ((OF_getprop(display, "broadcom,width",
470 		    &cell, sizeof(cell))) > 0)
471 			va_sc->width = (int)fdt32_to_cpu(cell);
472 
473 		if ((OF_getprop(display, "broadcom,height",
474 		    &cell, sizeof(cell))) > 0)
475 			va_sc->height = (int)fdt32_to_cpu(cell);
476 	}
477 
478 	if (va_sc->width == 0)
479 		va_sc->width = FB_WIDTH;
480 	if (va_sc->height == 0)
481 		va_sc->height = FB_HEIGHT;
482 
483 	bcmfb_init(0, &va_sc->va, 0);
484 
485 	va_sc->initialized = 1;
486 
487 	return (0);
488 }
489 
490 static int
491 bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
492 {
493 
494 	return (0);
495 }
496 
497 static int
498 bcmfb_init(int unit, video_adapter_t *adp, int flags)
499 {
500 	struct video_adapter_softc *sc;
501 	video_info_t *vi;
502 
503 	sc = (struct video_adapter_softc *)adp;
504 	vi = &adp->va_info;
505 
506 	vid_init_struct(adp, "bcmfb", -1, unit);
507 
508 	sc->font = dflt_font_16;
509 	vi->vi_cheight = BCMFB_FONT_HEIGHT;
510 	vi->vi_cwidth = 8;
511 
512 	vi->vi_width = sc->width/8;
513 	vi->vi_height = sc->height/vi->vi_cheight;
514 
515 	/*
516 	 * Clamp width/height to syscons maximums
517 	 */
518 	if (vi->vi_width > COL)
519 		vi->vi_width = COL;
520 	if (vi->vi_height > ROW)
521 		vi->vi_height = ROW;
522 
523 	sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
524 	sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
525 
526 
527 	adp->va_window = (vm_offset_t) bcmfb_static_window;
528 	adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
529 
530 	vid_register(&sc->va);
531 
532 	return (0);
533 }
534 
535 static int
536 bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
537 {
538 	bcopy(&adp->va_info, info, sizeof(*info));
539 	return (0);
540 }
541 
542 static int
543 bcmfb_query_mode(video_adapter_t *adp, video_info_t *info)
544 {
545 	return (0);
546 }
547 
548 static int
549 bcmfb_set_mode(video_adapter_t *adp, int mode)
550 {
551 	return (0);
552 }
553 
554 static int
555 bcmfb_save_font(video_adapter_t *adp, int page, int size, int width,
556     u_char *data, int c, int count)
557 {
558 	return (0);
559 }
560 
561 static int
562 bcmfb_load_font(video_adapter_t *adp, int page, int size, int width,
563     u_char *data, int c, int count)
564 {
565 	struct video_adapter_softc *sc = (struct video_adapter_softc *)adp;
566 
567 	sc->font = data;
568 
569 	return (0);
570 }
571 
572 static int
573 bcmfb_show_font(video_adapter_t *adp, int page)
574 {
575 	return (0);
576 }
577 
578 static int
579 bcmfb_save_palette(video_adapter_t *adp, u_char *palette)
580 {
581 	return (0);
582 }
583 
584 static int
585 bcmfb_load_palette(video_adapter_t *adp, u_char *palette)
586 {
587 	return (0);
588 }
589 
590 static int
591 bcmfb_set_border(video_adapter_t *adp, int border)
592 {
593 	return (bcmfb_blank_display(adp, border));
594 }
595 
596 static int
597 bcmfb_save_state(video_adapter_t *adp, void *p, size_t size)
598 {
599 	return (0);
600 }
601 
602 static int
603 bcmfb_load_state(video_adapter_t *adp, void *p)
604 {
605 	return (0);
606 }
607 
608 static int
609 bcmfb_set_win_org(video_adapter_t *adp, off_t offset)
610 {
611 	return (0);
612 }
613 
614 static int
615 bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
616 {
617 	*col = *row = 0;
618 
619 	return (0);
620 }
621 
622 static int
623 bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
624 {
625 	return (0);
626 }
627 
628 static int
629 bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
630     int celsize, int blink)
631 {
632 	return (0);
633 }
634 
635 static int
636 bcmfb_blank_display(video_adapter_t *adp, int mode)
637 {
638 
639 	struct video_adapter_softc *sc;
640 
641 	sc = (struct video_adapter_softc *)adp;
642 	if (sc && sc->fb_addr)
643 		memset((void*)sc->fb_addr, 0, sc->fb_size);
644 
645 	return (0);
646 }
647 
648 static int
649 bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
650     int prot, vm_memattr_t *memattr)
651 {
652 	struct video_adapter_softc *sc;
653 
654 	sc = (struct video_adapter_softc *)adp;
655 
656 	/*
657 	 * This might be a legacy VGA mem request: if so, just point it at the
658 	 * framebuffer, since it shouldn't be touched
659 	 */
660 	if (offset < sc->stride*sc->height) {
661 		*paddr = sc->fb_addr + offset;
662 		return (0);
663 	}
664 
665 	return (EINVAL);
666 }
667 
668 static int
669 bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
670 {
671 
672 	return (0);
673 }
674 
675 static int
676 bcmfb_clear(video_adapter_t *adp)
677 {
678 
679 	return (bcmfb_blank_display(adp, 0));
680 }
681 
682 static int
683 bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
684 {
685 
686 	return (0);
687 }
688 
689 static int
690 bcmfb_bitblt(video_adapter_t *adp, ...)
691 {
692 
693 	return (0);
694 }
695 
696 static int
697 bcmfb_diag(video_adapter_t *adp, int level)
698 {
699 
700 	return (0);
701 }
702 
703 static int
704 bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
705 {
706 
707 	return (0);
708 }
709 
710 static int
711 bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
712 {
713 
714 	return (0);
715 }
716 
717 static int
718 bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
719 {
720 
721 	return (0);
722 }
723 
724 static int
725 bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
726     int size, int bpp, int bit_ltor, int byte_ltor)
727 {
728 
729 	return (0);
730 }
731 
732 static int
733 bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
734 {
735 	struct video_adapter_softc *sc;
736 	int row;
737 	int col;
738 	int i, j, k;
739 	uint8_t *addr;
740 	u_char *p;
741 	uint8_t fg, bg, color;
742 	uint16_t rgb;
743 
744 	sc = (struct video_adapter_softc *)adp;
745 
746 	if (sc->fb_addr == 0)
747 		return (0);
748 
749 	row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
750 	col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
751 	p = sc->font + c*BCMFB_FONT_HEIGHT;
752 	addr = (uint8_t *)sc->fb_addr
753 	    + (row + sc->ymargin)*(sc->stride)
754 	    + (sc->depth/8) * (col + sc->xmargin);
755 
756 	fg = a & 0xf ;
757 	bg = (a >> 8) & 0xf;
758 
759 	for (i = 0; i < BCMFB_FONT_HEIGHT; i++) {
760 		for (j = 0, k = 7; j < 8; j++, k--) {
761 			if ((p[i] & (1 << k)) == 0)
762 				color = bg;
763 			else
764 				color = fg;
765 
766 			switch (sc->depth) {
767 			case 32:
768 				addr[4*j+0] = bcmfb_palette[color].r;
769 				addr[4*j+1] = bcmfb_palette[color].g;
770 				addr[4*j+2] = bcmfb_palette[color].b;
771 				addr[4*j+3] = bcmfb_palette[color].a;
772 				break;
773 			case 24:
774 				addr[3*j] = bcmfb_palette[color].r;
775 				addr[3*j+1] = bcmfb_palette[color].g;
776 				addr[3*j+2] = bcmfb_palette[color].b;
777 				break;
778 			case 16:
779 				rgb = (bcmfb_palette[color].r >> 3) << 11;
780 				rgb |= (bcmfb_palette[color].g >> 2) << 5;
781 				rgb |= (bcmfb_palette[color].b >> 3);
782 				addr[2*j] = rgb & 0xff;
783 				addr[2*j + 1] = (rgb >> 8) & 0xff;
784 			default:
785 				/* Not supported yet */
786 				break;
787 			}
788 		}
789 
790 		addr += (sc->stride);
791 	}
792 
793         return (0);
794 }
795 
796 static int
797 bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
798 {
799 	int i;
800 
801 	for (i = 0; i < len; i++)
802 		bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
803 
804 	return (0);
805 }
806 
807 static int
808 bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
809     uint32_t pixel_mask, int size, int width)
810 {
811 
812 	return (0);
813 }
814 
815 /*
816  * Define a stub keyboard driver in case one hasn't been
817  * compiled into the kernel
818  */
819 #include <sys/kbio.h>
820 #include <dev/kbd/kbdreg.h>
821 
822 static int dummy_kbd_configure(int flags);
823 
824 keyboard_switch_t bcmdummysw;
825 
826 static int
827 dummy_kbd_configure(int flags)
828 {
829 
830 	return (0);
831 }
832 KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure);
833