2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * Copyright (c) 2012, 2013 The FreeBSD Foundation
6 * Portions of this software were developed by Oleksandr Rybalko
7 * under sponsorship from the FreeBSD Foundation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
35 #include <sys/systm.h>
39 #include <sys/kernel.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
46 #include <dev/fdt/fdt_common.h>
47 #include <dev/ofw/ofw_bus.h>
48 #include <dev/ofw/ofw_bus_subr.h>
50 #include <dev/fb/fbreg.h>
51 #include <dev/vt/vt.h>
52 #include <dev/vt/colors/vt_termcolors.h>
54 #include <arm/broadcom/bcm2835/bcm2835_mbox_prop.h>
65 static int bcm_fb_probe(device_t);
66 static int bcm_fb_attach(device_t);
69 bcm_fb_probe(device_t dev)
71 if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb"))
74 device_set_desc(dev, "BCM2835 VT framebuffer driver");
76 return (BUS_PROBE_DEFAULT);
80 bcm_fb_attach(device_t dev)
82 char bootargs[2048], *n, *p, *v;
86 struct bcm2835_fb_config fb;
87 struct bcmsc_softc *sc;
90 sc = device_get_softc(dev);
91 memset(&fb, 0, sizeof(fb));
92 if (bcm2835_mbox_fb_get_w_h(dev, &fb) != 0)
95 if (bcm2835_mbox_fb_init(dev, &fb) != 0)
98 info = malloc(sizeof(struct fb_info), M_DEVBUF, M_WAITOK | M_ZERO);
99 info->fb_name = device_get_nameunit(dev);
100 info->fb_vbase = (intptr_t)pmap_mapdev(fb.base, fb.size);
101 info->fb_pbase = fb.base;
102 info->fb_size = fb.size;
103 info->fb_bpp = info->fb_depth = fb.bpp;
104 info->fb_stride = fb.pitch;
105 info->fb_width = fb.xres;
106 info->fb_height = fb.yres;
109 /* Newer firmware versions needs an inverted color palette. */
111 chosen = OF_finddevice("/chosen");
113 OF_getprop(chosen, "bootargs", &bootargs, sizeof(bootargs)) > 0) {
115 while ((v = strsep(&p, " ")) != NULL) {
119 if (strcmp(n, "bcm2708_fb.fbswap") == 0 && v != NULL)
125 switch (info->fb_bpp) {
127 vt_generate_cons_palette(info->fb_cmap,
128 COLOR_FORMAT_RGB, 0xff, 0, 0xff, 8, 0xff, 16);
129 info->fb_cmsize = 16;
132 vt_generate_cons_palette(info->fb_cmap,
133 COLOR_FORMAT_RGB, 0xff, 16, 0xff, 8, 0xff, 0);
134 info->fb_cmsize = 16;
139 fbd = device_add_child(dev, "fbd", device_get_unit(dev));
141 device_printf(dev, "Failed to add fbd child\n");
142 free(info, M_DEVBUF);
144 } else if (device_probe_and_attach(fbd) != 0) {
145 device_printf(dev, "Failed to attach fbd device\n");
146 device_delete_child(dev, fbd);
147 free(info, M_DEVBUF);
151 device_printf(dev, "%dx%d(%dx%d@%d,%d) %dbpp\n", fb.xres, fb.yres,
152 fb.vxres, fb.vyres, fb.xoffset, fb.yoffset, fb.bpp);
154 "fbswap: %d, pitch %d, base 0x%08x, screen_size %d\n",
155 fbswap, fb.pitch, fb.base, fb.size);
160 static struct fb_info *
161 bcm_fb_helper_getinfo(device_t dev)
163 struct bcmsc_softc *sc;
165 sc = device_get_softc(dev);
170 static device_method_t bcm_fb_methods[] = {
171 /* Device interface */
172 DEVMETHOD(device_probe, bcm_fb_probe),
173 DEVMETHOD(device_attach, bcm_fb_attach),
175 /* Framebuffer service methods */
176 DEVMETHOD(fb_getinfo, bcm_fb_helper_getinfo),
181 static devclass_t bcm_fb_devclass;
183 static driver_t bcm_fb_driver = {
186 sizeof(struct bcmsc_softc),
189 DRIVER_MODULE(bcm2835fb, ofwbus, bcm_fb_driver, bcm_fb_devclass, 0, 0);