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/bus.h>
33 #include <sys/consio.h>
34 #include <sys/fbio.h>
35 #include <sys/kdb.h>
36 #include <sys/kernel.h>
37 #include <sys/malloc.h>
38 #include <sys/module.h>
39
40 #include <vm/vm.h>
41 #include <vm/pmap.h>
42
43 #include <dev/fb/fbreg.h>
44 #include <dev/fdt/fdt_common.h>
45 #include <dev/ofw/ofw_bus.h>
46 #include <dev/ofw/ofw_bus_subr.h>
47 #include <dev/syscons/syscons.h>
48
49 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
50
51 #include "mbox_if.h"
52
53 struct argb {
54 uint8_t a;
55 uint8_t r;
56 uint8_t g;
57 uint8_t b;
58 };
59
60 static struct argb bcmfb_palette[16] = {
61 {0x00, 0x00, 0x00, 0x00},
62 {0x00, 0x00, 0x00, 0xaa},
63 {0x00, 0x00, 0xaa, 0x00},
64 {0x00, 0x00, 0xaa, 0xaa},
65 {0x00, 0xaa, 0x00, 0x00},
66 {0x00, 0xaa, 0x00, 0xaa},
67 {0x00, 0xaa, 0x55, 0x00},
68 {0x00, 0xaa, 0xaa, 0xaa},
69 {0x00, 0x55, 0x55, 0x55},
70 {0x00, 0x55, 0x55, 0xff},
71 {0x00, 0x55, 0xff, 0x55},
72 {0x00, 0x55, 0xff, 0xff},
73 {0x00, 0xff, 0x55, 0x55},
74 {0x00, 0xff, 0x55, 0xff},
75 {0x00, 0xff, 0xff, 0x55},
76 {0x00, 0xff, 0xff, 0xff}
77 };
78
79 /* mouse pointer from dev/syscons/scgfbrndr.c */
80 static u_char mouse_pointer[16] = {
81 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
82 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
83 };
84
85 #define BCMFB_FONT_HEIGHT 16
86 #define BCMFB_FONT_WIDTH 8
87 #define FB_WIDTH 640
88 #define FB_HEIGHT 480
89 #define FB_DEPTH 24
90
91 struct bcmsc_softc {
92 /* Videoadpater part */
93 video_adapter_t va;
94
95 intptr_t fb_addr;
96 intptr_t fb_paddr;
97 unsigned int fb_size;
98
99 unsigned int height;
100 unsigned int width;
101 unsigned int depth;
102 unsigned int stride;
103
104 unsigned int xmargin;
105 unsigned int ymargin;
106
107 unsigned char *font;
108 int fbswap;
109 int initialized;
110 };
111
112 static struct bcmsc_softc bcmsc;
113
114 static int bcm_fb_probe(device_t);
115 static int bcm_fb_attach(device_t);
116 static void bcmfb_update_margins(video_adapter_t *adp);
117 static int bcmfb_configure(int);
118
119 static int
bcm_fb_probe(device_t dev)120 bcm_fb_probe(device_t dev)
121 {
122 int error;
123
124 if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb"))
125 return (ENXIO);
126 device_set_desc(dev, "BCM2835 framebuffer device");
127 error = sc_probe_unit(device_get_unit(dev),
128 device_get_flags(dev) | SC_AUTODETECT_KBD);
129 if (error != 0)
130 return (error);
131
132 return (BUS_PROBE_DEFAULT);
133 }
134
135 static int
bcm_fb_attach(device_t dev)136 bcm_fb_attach(device_t dev)
137 {
138 struct bcm2835_fb_config fb;
139 struct bcmsc_softc *sc;
140
141 sc = (struct bcmsc_softc *)vid_get_adapter(vid_find_adapter(
142 "bcmfb", 0));
143 if (sc != NULL)
144 device_set_softc(dev, sc);
145 else
146 sc = device_get_softc(dev);
147
148 memset(&fb, 0, sizeof(fb));
149 if (bcm2835_mbox_fb_get_w_h(dev, &fb) != 0)
150 return (ENXIO);
151 fb.bpp = FB_DEPTH;
152 if (bcm2835_mbox_fb_init(dev, &fb) != 0)
153 return (ENXIO);
154
155 sc->fb_addr = (intptr_t)pmap_mapdev(fb.base, fb.size);
156 sc->fb_paddr = fb.base;
157 sc->fb_size = fb.size;
158 sc->depth = fb.bpp;
159 sc->stride = fb.pitch;
160 sc->width = fb.xres;
161 sc->height = fb.yres;
162 bcmfb_update_margins(&sc->va);
163
164 if (sc_attach_unit(device_get_unit(dev),
165 device_get_flags(dev) | SC_AUTODETECT_KBD) != 0) {
166 device_printf(dev, "failed to attach syscons\n");
167 return (ENXIO);
168 }
169
170 device_printf(dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres,
171 fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp);
172 device_printf(dev,
173 "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n",
174 sc->fbswap, fb.pitch, fb.base, fb.size);
175
176 return (0);
177 }
178
179 static device_method_t bcm_fb_methods[] = {
180 /* Device interface */
181 DEVMETHOD(device_probe, bcm_fb_probe),
182 DEVMETHOD(device_attach, bcm_fb_attach),
183
184 { 0, 0 }
185 };
186
187 static devclass_t bcm_fb_devclass;
188
189 static driver_t bcm_fb_driver = {
190 "fb",
191 bcm_fb_methods,
192 sizeof(struct bcmsc_softc),
193 };
194
195 DRIVER_MODULE(bcm2835fb, ofwbus, bcm_fb_driver, bcm_fb_devclass, 0, 0);
196
197 /*
198 * Video driver routines and glue.
199 */
200 static vi_probe_t bcmfb_probe;
201 static vi_init_t bcmfb_init;
202 static vi_get_info_t bcmfb_get_info;
203 static vi_query_mode_t bcmfb_query_mode;
204 static vi_set_mode_t bcmfb_set_mode;
205 static vi_save_font_t bcmfb_save_font;
206 static vi_load_font_t bcmfb_load_font;
207 static vi_show_font_t bcmfb_show_font;
208 static vi_save_palette_t bcmfb_save_palette;
209 static vi_load_palette_t bcmfb_load_palette;
210 static vi_set_border_t bcmfb_set_border;
211 static vi_save_state_t bcmfb_save_state;
212 static vi_load_state_t bcmfb_load_state;
213 static vi_set_win_org_t bcmfb_set_win_org;
214 static vi_read_hw_cursor_t bcmfb_read_hw_cursor;
215 static vi_set_hw_cursor_t bcmfb_set_hw_cursor;
216 static vi_set_hw_cursor_shape_t bcmfb_set_hw_cursor_shape;
217 static vi_blank_display_t bcmfb_blank_display;
218 static vi_mmap_t bcmfb_mmap;
219 static vi_ioctl_t bcmfb_ioctl;
220 static vi_clear_t bcmfb_clear;
221 static vi_fill_rect_t bcmfb_fill_rect;
222 static vi_bitblt_t bcmfb_bitblt;
223 static vi_diag_t bcmfb_diag;
224 static vi_save_cursor_palette_t bcmfb_save_cursor_palette;
225 static vi_load_cursor_palette_t bcmfb_load_cursor_palette;
226 static vi_copy_t bcmfb_copy;
227 static vi_putp_t bcmfb_putp;
228 static vi_putc_t bcmfb_putc;
229 static vi_puts_t bcmfb_puts;
230 static vi_putm_t bcmfb_putm;
231
232 static video_switch_t bcmfbvidsw = {
233 .probe = bcmfb_probe,
234 .init = bcmfb_init,
235 .get_info = bcmfb_get_info,
236 .query_mode = bcmfb_query_mode,
237 .set_mode = bcmfb_set_mode,
238 .save_font = bcmfb_save_font,
239 .load_font = bcmfb_load_font,
240 .show_font = bcmfb_show_font,
241 .save_palette = bcmfb_save_palette,
242 .load_palette = bcmfb_load_palette,
243 .set_border = bcmfb_set_border,
244 .save_state = bcmfb_save_state,
245 .load_state = bcmfb_load_state,
246 .set_win_org = bcmfb_set_win_org,
247 .read_hw_cursor = bcmfb_read_hw_cursor,
248 .set_hw_cursor = bcmfb_set_hw_cursor,
249 .set_hw_cursor_shape = bcmfb_set_hw_cursor_shape,
250 .blank_display = bcmfb_blank_display,
251 .mmap = bcmfb_mmap,
252 .ioctl = bcmfb_ioctl,
253 .clear = bcmfb_clear,
254 .fill_rect = bcmfb_fill_rect,
255 .bitblt = bcmfb_bitblt,
256 .diag = bcmfb_diag,
257 .save_cursor_palette = bcmfb_save_cursor_palette,
258 .load_cursor_palette = bcmfb_load_cursor_palette,
259 .copy = bcmfb_copy,
260 .putp = bcmfb_putp,
261 .putc = bcmfb_putc,
262 .puts = bcmfb_puts,
263 .putm = bcmfb_putm,
264 };
265
266 VIDEO_DRIVER(bcmfb, bcmfbvidsw, bcmfb_configure);
267
268 static vr_init_t bcmrend_init;
269 static vr_clear_t bcmrend_clear;
270 static vr_draw_border_t bcmrend_draw_border;
271 static vr_draw_t bcmrend_draw;
272 static vr_set_cursor_t bcmrend_set_cursor;
273 static vr_draw_cursor_t bcmrend_draw_cursor;
274 static vr_blink_cursor_t bcmrend_blink_cursor;
275 static vr_set_mouse_t bcmrend_set_mouse;
276 static vr_draw_mouse_t bcmrend_draw_mouse;
277
278 /*
279 * We use our own renderer; this is because we must emulate a hardware
280 * cursor.
281 */
282 static sc_rndr_sw_t bcmrend = {
283 bcmrend_init,
284 bcmrend_clear,
285 bcmrend_draw_border,
286 bcmrend_draw,
287 bcmrend_set_cursor,
288 bcmrend_draw_cursor,
289 bcmrend_blink_cursor,
290 bcmrend_set_mouse,
291 bcmrend_draw_mouse
292 };
293
294 RENDERER(bcmfb, 0, bcmrend, gfb_set);
295 RENDERER_MODULE(bcmfb, gfb_set);
296
297 static void
bcmrend_init(scr_stat * scp)298 bcmrend_init(scr_stat* scp)
299 {
300 }
301
302 static void
bcmrend_clear(scr_stat * scp,int c,int attr)303 bcmrend_clear(scr_stat* scp, int c, int attr)
304 {
305 }
306
307 static void
bcmrend_draw_border(scr_stat * scp,int color)308 bcmrend_draw_border(scr_stat* scp, int color)
309 {
310 }
311
312 static void
bcmrend_draw(scr_stat * scp,int from,int count,int flip)313 bcmrend_draw(scr_stat* scp, int from, int count, int flip)
314 {
315 video_adapter_t* adp = scp->sc->adp;
316 int i, c, a;
317
318 if (!flip) {
319 /* Normal printing */
320 vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
321 } else {
322 /* This is for selections and such: invert the color attribute */
323 for (i = count; i-- > 0; ++from) {
324 c = sc_vtb_getc(&scp->vtb, from);
325 a = sc_vtb_geta(&scp->vtb, from) >> 8;
326 vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
327 }
328 }
329 }
330
331 static void
bcmrend_set_cursor(scr_stat * scp,int base,int height,int blink)332 bcmrend_set_cursor(scr_stat* scp, int base, int height, int blink)
333 {
334 }
335
336 static void
bcmrend_draw_cursor(scr_stat * scp,int off,int blink,int on,int flip)337 bcmrend_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
338 {
339 int bytes, col, i, j, row;
340 struct bcmsc_softc *sc;
341 uint8_t *addr;
342 video_adapter_t *adp;
343
344 adp = scp->sc->adp;
345 sc = (struct bcmsc_softc *)adp;
346
347 if (scp->curs_attr.height <= 0)
348 return;
349
350 if (sc->fb_addr == 0)
351 return;
352
353 if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
354 return;
355
356 /* calculate the coordinates in the video buffer */
357 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
358 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
359
360 addr = (uint8_t *)sc->fb_addr
361 + (row + sc->ymargin)*(sc->stride)
362 + (sc->depth/8) * (col + sc->xmargin);
363
364 bytes = sc->depth / 8;
365 /* our cursor consists of simply inverting the char under it */
366 for (i = 0; i < adp->va_info.vi_cheight; i++) {
367 for (j = 0; j < adp->va_info.vi_cwidth; j++) {
368 switch (sc->depth) {
369 case 32:
370 case 24:
371 addr[bytes*j + 2] ^= 0xff;
372 /* FALLTHROUGH */
373 case 16:
374 addr[bytes*j + 1] ^= 0xff;
375 addr[bytes*j] ^= 0xff;
376 break;
377 default:
378 break;
379 }
380 }
381
382 addr += sc->stride;
383 }
384 }
385
386 static void
bcmrend_blink_cursor(scr_stat * scp,int at,int flip)387 bcmrend_blink_cursor(scr_stat* scp, int at, int flip)
388 {
389 }
390
391 static void
bcmrend_set_mouse(scr_stat * scp)392 bcmrend_set_mouse(scr_stat* scp)
393 {
394 }
395
396 static void
bcmrend_draw_mouse(scr_stat * scp,int x,int y,int on)397 bcmrend_draw_mouse(scr_stat* scp, int x, int y, int on)
398 {
399 vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
400 }
401
402 static uint16_t bcmfb_static_window[ROW*COL];
403 extern u_char dflt_font_16[];
404
405 /*
406 * Update videoadapter settings after changing resolution
407 */
408 static void
bcmfb_update_margins(video_adapter_t * adp)409 bcmfb_update_margins(video_adapter_t *adp)
410 {
411 struct bcmsc_softc *sc;
412 video_info_t *vi;
413
414 sc = (struct bcmsc_softc *)adp;
415 vi = &adp->va_info;
416
417 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
418 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2;
419 }
420
421 static int
bcmfb_configure(int flags)422 bcmfb_configure(int flags)
423 {
424 char bootargs[2048], *n, *p, *v;
425 pcell_t cell;
426 phandle_t chosen, display, root;
427 struct bcmsc_softc *sc;
428
429 sc = &bcmsc;
430 if (sc->initialized)
431 return (0);
432
433 sc->width = 0;
434 sc->height = 0;
435
436 /*
437 * It seems there is no way to let syscons framework know
438 * that framebuffer resolution has changed. So just try
439 * to fetch data from FDT bootargs, FDT display data and
440 * finally go with defaults if everything else has failed.
441 */
442 chosen = OF_finddevice("/chosen");
443 if (chosen != 0 &&
444 OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) {
445 p = bootargs;
446 while ((v = strsep(&p, " ")) != NULL) {
447 if (*v == '\0')
448 continue;
449 n = strsep(&v, "=");
450 if (strcmp(n, "bcm2708_fb.fbwidth") == 0 && v != NULL)
451 sc->width = (unsigned int)strtol(v, NULL, 0);
452 else if (strcmp(n, "bcm2708_fb.fbheight") == 0 &&
453 v != NULL)
454 sc->height = (unsigned int)strtol(v, NULL, 0);
455 else if (strcmp(n, "bcm2708_fb.fbswap") == 0 &&
456 v != NULL)
457 if (*v == '1')
458 sc->fbswap = 1;
459 }
460 }
461
462 root = OF_finddevice("/");
463 if ((root != 0) &&
464 (display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) {
465 if (sc->width == 0) {
466 if ((OF_getprop(display, "broadcom,width",
467 &cell, sizeof(cell))) > 0)
468 sc->width = (int)fdt32_to_cpu(cell);
469 }
470
471 if (sc->height == 0) {
472 if ((OF_getprop(display, "broadcom,height",
473 &cell, sizeof(cell))) > 0)
474 sc->height = (int)fdt32_to_cpu(cell);
475 }
476 }
477
478 if (sc->width == 0)
479 sc->width = FB_WIDTH;
480 if (sc->height == 0)
481 sc->height = FB_HEIGHT;
482
483 bcmfb_init(0, &sc->va, 0);
484 sc->initialized = 1;
485
486 return (0);
487 }
488
489 static int
bcmfb_probe(int unit,video_adapter_t ** adp,void * arg,int flags)490 bcmfb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
491 {
492
493 return (0);
494 }
495
496 static int
bcmfb_init(int unit,video_adapter_t * adp,int flags)497 bcmfb_init(int unit, video_adapter_t *adp, int flags)
498 {
499 struct bcmsc_softc *sc;
500 video_info_t *vi;
501
502 sc = (struct bcmsc_softc *)adp;
503 vi = &adp->va_info;
504
505 vid_init_struct(adp, "bcmfb", -1, unit);
506
507 sc->font = dflt_font_16;
508 vi->vi_cheight = BCMFB_FONT_HEIGHT;
509 vi->vi_cwidth = BCMFB_FONT_WIDTH;
510 vi->vi_width = sc->width / vi->vi_cwidth;
511 vi->vi_height = sc->height / vi->vi_cheight;
512
513 /*
514 * Clamp width/height to syscons maximums
515 */
516 if (vi->vi_width > COL)
517 vi->vi_width = COL;
518 if (vi->vi_height > ROW)
519 vi->vi_height = ROW;
520
521 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
522 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight)) / 2;
523
524 adp->va_window = (vm_offset_t) bcmfb_static_window;
525 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
526
527 vid_register(&sc->va);
528
529 return (0);
530 }
531
532 static int
bcmfb_get_info(video_adapter_t * adp,int mode,video_info_t * info)533 bcmfb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
534 {
535 bcopy(&adp->va_info, info, sizeof(*info));
536 return (0);
537 }
538
539 static int
bcmfb_query_mode(video_adapter_t * adp,video_info_t * info)540 bcmfb_query_mode(video_adapter_t *adp, video_info_t *info)
541 {
542 return (0);
543 }
544
545 static int
bcmfb_set_mode(video_adapter_t * adp,int mode)546 bcmfb_set_mode(video_adapter_t *adp, int mode)
547 {
548 return (0);
549 }
550
551 static int
bcmfb_save_font(video_adapter_t * adp,int page,int size,int width,u_char * data,int c,int count)552 bcmfb_save_font(video_adapter_t *adp, int page, int size, int width,
553 u_char *data, int c, int count)
554 {
555 return (0);
556 }
557
558 static int
bcmfb_load_font(video_adapter_t * adp,int page,int size,int width,u_char * data,int c,int count)559 bcmfb_load_font(video_adapter_t *adp, int page, int size, int width,
560 u_char *data, int c, int count)
561 {
562 struct bcmsc_softc *sc;
563
564 sc = (struct bcmsc_softc *)adp;
565 sc->font = data;
566
567 return (0);
568 }
569
570 static int
bcmfb_show_font(video_adapter_t * adp,int page)571 bcmfb_show_font(video_adapter_t *adp, int page)
572 {
573 return (0);
574 }
575
576 static int
bcmfb_save_palette(video_adapter_t * adp,u_char * palette)577 bcmfb_save_palette(video_adapter_t *adp, u_char *palette)
578 {
579 return (0);
580 }
581
582 static int
bcmfb_load_palette(video_adapter_t * adp,u_char * palette)583 bcmfb_load_palette(video_adapter_t *adp, u_char *palette)
584 {
585 return (0);
586 }
587
588 static int
bcmfb_set_border(video_adapter_t * adp,int border)589 bcmfb_set_border(video_adapter_t *adp, int border)
590 {
591 return (bcmfb_blank_display(adp, border));
592 }
593
594 static int
bcmfb_save_state(video_adapter_t * adp,void * p,size_t size)595 bcmfb_save_state(video_adapter_t *adp, void *p, size_t size)
596 {
597 return (0);
598 }
599
600 static int
bcmfb_load_state(video_adapter_t * adp,void * p)601 bcmfb_load_state(video_adapter_t *adp, void *p)
602 {
603 return (0);
604 }
605
606 static int
bcmfb_set_win_org(video_adapter_t * adp,off_t offset)607 bcmfb_set_win_org(video_adapter_t *adp, off_t offset)
608 {
609 return (0);
610 }
611
612 static int
bcmfb_read_hw_cursor(video_adapter_t * adp,int * col,int * row)613 bcmfb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
614 {
615 *col = *row = 0;
616
617 return (0);
618 }
619
620 static int
bcmfb_set_hw_cursor(video_adapter_t * adp,int col,int row)621 bcmfb_set_hw_cursor(video_adapter_t *adp, int col, int row)
622 {
623 return (0);
624 }
625
626 static int
bcmfb_set_hw_cursor_shape(video_adapter_t * adp,int base,int height,int celsize,int blink)627 bcmfb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
628 int celsize, int blink)
629 {
630 return (0);
631 }
632
633 static int
bcmfb_blank_display(video_adapter_t * adp,int mode)634 bcmfb_blank_display(video_adapter_t *adp, int mode)
635 {
636
637 struct bcmsc_softc *sc;
638
639 sc = (struct bcmsc_softc *)adp;
640 if (sc && sc->fb_addr)
641 memset((void*)sc->fb_addr, 0, sc->fb_size);
642
643 return (0);
644 }
645
646 static int
bcmfb_mmap(video_adapter_t * adp,vm_ooffset_t offset,vm_paddr_t * paddr,int prot,vm_memattr_t * memattr)647 bcmfb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
648 int prot, vm_memattr_t *memattr)
649 {
650 struct bcmsc_softc *sc;
651
652 sc = (struct bcmsc_softc *)adp;
653
654 /*
655 * This might be a legacy VGA mem request: if so, just point it at the
656 * framebuffer, since it shouldn't be touched
657 */
658 if (offset < sc->stride*sc->height) {
659 *paddr = sc->fb_paddr + offset;
660 return (0);
661 }
662
663 return (EINVAL);
664 }
665
666 static int
bcmfb_ioctl(video_adapter_t * adp,u_long cmd,caddr_t data)667 bcmfb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
668 {
669 struct bcmsc_softc *sc;
670 struct fbtype *fb;
671
672 sc = (struct bcmsc_softc *)adp;
673
674 switch (cmd) {
675 case FBIOGTYPE:
676 fb = (struct fbtype *)data;
677 fb->fb_type = FBTYPE_PCIMISC;
678 fb->fb_height = sc->height;
679 fb->fb_width = sc->width;
680 fb->fb_depth = sc->depth;
681 if (sc->depth <= 1 || sc->depth > 8)
682 fb->fb_cmsize = 0;
683 else
684 fb->fb_cmsize = 1 << sc->depth;
685 fb->fb_size = sc->fb_size;
686 break;
687 default:
688 return (fb_commonioctl(adp, cmd, data));
689 }
690
691 return (0);
692 }
693
694 static int
bcmfb_clear(video_adapter_t * adp)695 bcmfb_clear(video_adapter_t *adp)
696 {
697
698 return (bcmfb_blank_display(adp, 0));
699 }
700
701 static int
bcmfb_fill_rect(video_adapter_t * adp,int val,int x,int y,int cx,int cy)702 bcmfb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
703 {
704
705 return (0);
706 }
707
708 static int
bcmfb_bitblt(video_adapter_t * adp,...)709 bcmfb_bitblt(video_adapter_t *adp, ...)
710 {
711
712 return (0);
713 }
714
715 static int
bcmfb_diag(video_adapter_t * adp,int level)716 bcmfb_diag(video_adapter_t *adp, int level)
717 {
718
719 return (0);
720 }
721
722 static int
bcmfb_save_cursor_palette(video_adapter_t * adp,u_char * palette)723 bcmfb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
724 {
725
726 return (0);
727 }
728
729 static int
bcmfb_load_cursor_palette(video_adapter_t * adp,u_char * palette)730 bcmfb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
731 {
732
733 return (0);
734 }
735
736 static int
bcmfb_copy(video_adapter_t * adp,vm_offset_t src,vm_offset_t dst,int n)737 bcmfb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
738 {
739
740 return (0);
741 }
742
743 static int
bcmfb_putp(video_adapter_t * adp,vm_offset_t off,uint32_t p,uint32_t a,int size,int bpp,int bit_ltor,int byte_ltor)744 bcmfb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
745 int size, int bpp, int bit_ltor, int byte_ltor)
746 {
747
748 return (0);
749 }
750
751 static int
bcmfb_putc(video_adapter_t * adp,vm_offset_t off,uint8_t c,uint8_t a)752 bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
753 {
754 int bytes, col, i, j, k, row;
755 struct bcmsc_softc *sc;
756 u_char *p;
757 uint8_t *addr, fg, bg, color;
758 uint16_t rgb;
759
760 sc = (struct bcmsc_softc *)adp;
761
762 if (sc->fb_addr == 0)
763 return (0);
764
765 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
766 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
767 p = sc->font + c*BCMFB_FONT_HEIGHT;
768 addr = (uint8_t *)sc->fb_addr
769 + (row + sc->ymargin)*(sc->stride)
770 + (sc->depth/8) * (col + sc->xmargin);
771
772 fg = a & 0xf ;
773 bg = (a >> 4) & 0xf;
774
775 bytes = sc->depth / 8;
776 for (i = 0; i < BCMFB_FONT_HEIGHT; i++) {
777 for (j = 0, k = 7; j < 8; j++, k--) {
778 if ((p[i] & (1 << k)) == 0)
779 color = bg;
780 else
781 color = fg;
782
783 switch (sc->depth) {
784 case 32:
785 case 24:
786 if (sc->fbswap) {
787 addr[bytes * j + 0] =
788 bcmfb_palette[color].b;
789 addr[bytes * j + 1] =
790 bcmfb_palette[color].g;
791 addr[bytes * j + 2] =
792 bcmfb_palette[color].r;
793 } else {
794 addr[bytes * j + 0] =
795 bcmfb_palette[color].r;
796 addr[bytes * j + 1] =
797 bcmfb_palette[color].g;
798 addr[bytes * j + 2] =
799 bcmfb_palette[color].b;
800 }
801 if (sc->depth == 32)
802 addr[bytes * j + 3] =
803 bcmfb_palette[color].a;
804 break;
805 case 16:
806 rgb = (bcmfb_palette[color].r >> 3) << 11;
807 rgb |= (bcmfb_palette[color].g >> 2) << 5;
808 rgb |= (bcmfb_palette[color].b >> 3);
809 addr[bytes * j] = rgb & 0xff;
810 addr[bytes * j + 1] = (rgb >> 8) & 0xff;
811 default:
812 /* Not supported yet */
813 break;
814 }
815 }
816
817 addr += (sc->stride);
818 }
819
820 return (0);
821 }
822
823 static int
bcmfb_puts(video_adapter_t * adp,vm_offset_t off,u_int16_t * s,int len)824 bcmfb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
825 {
826 int i;
827
828 for (i = 0; i < len; i++)
829 bcmfb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
830
831 return (0);
832 }
833
834 static int
bcmfb_putm(video_adapter_t * adp,int x,int y,uint8_t * pixel_image,uint32_t pixel_mask,int size,int width)835 bcmfb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
836 uint32_t pixel_mask, int size, int width)
837 {
838
839 return (0);
840 }
841
842 /*
843 * Define a stub keyboard driver in case one hasn't been
844 * compiled into the kernel
845 */
846 #include <sys/kbio.h>
847 #include <dev/kbd/kbdreg.h>
848
849 static int dummy_kbd_configure(int flags);
850
851 keyboard_switch_t bcmdummysw;
852
853 static int
dummy_kbd_configure(int flags)854 dummy_kbd_configure(int flags)
855 {
856
857 return (0);
858 }
859 KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure);
860