Multiple fixes for BCM2835 framebuffer
- Get resolution settings from FDT blob - Properly handle 24 and 16 bits per pixel - Add colors support for text console
This commit is contained in:
parent
d8e808617d
commit
0f275f4278
@ -68,8 +68,35 @@ __FBSDID("$FreeBSD$");
|
||||
|
||||
#define BCMFB_FONT_HEIGHT 16
|
||||
|
||||
struct argb {
|
||||
uint8_t a;
|
||||
uint8_t r;
|
||||
uint8_t g;
|
||||
uint8_t b;
|
||||
};
|
||||
|
||||
static struct argb bcmfb_palette[16] = {
|
||||
{0x00, 0x00, 0x00, 0x00},
|
||||
{0x00, 0x00, 0x00, 0xaa},
|
||||
{0x00, 0x00, 0xaa, 0x00},
|
||||
{0x00, 0x00, 0xaa, 0xaa},
|
||||
{0x00, 0xaa, 0x00, 0x00},
|
||||
{0x00, 0xaa, 0x00, 0xaa},
|
||||
{0x00, 0xaa, 0x55, 0x00},
|
||||
{0x00, 0xaa, 0xaa, 0xaa},
|
||||
{0x00, 0x55, 0x55, 0x55},
|
||||
{0x00, 0x55, 0x55, 0xff},
|
||||
{0x00, 0x55, 0xff, 0x55},
|
||||
{0x00, 0x55, 0xff, 0xff},
|
||||
{0x00, 0xff, 0x55, 0x55},
|
||||
{0x00, 0xff, 0x55, 0xff},
|
||||
{0x00, 0xff, 0xff, 0x55},
|
||||
{0x00, 0xff, 0xff, 0xff}
|
||||
};
|
||||
|
||||
#define FB_WIDTH 640
|
||||
#define FB_HEIGHT 480
|
||||
#define FB_DEPTH 24
|
||||
|
||||
struct bcm_fb_config {
|
||||
uint32_t xres;
|
||||
@ -107,6 +134,7 @@ struct video_adapter_softc {
|
||||
|
||||
unsigned int height;
|
||||
unsigned int width;
|
||||
unsigned int depth;
|
||||
unsigned int stride;
|
||||
|
||||
unsigned int xmargin;
|
||||
@ -126,6 +154,8 @@ static struct video_adapter_softc va_softc;
|
||||
static int bcm_fb_probe(device_t);
|
||||
static int bcm_fb_attach(device_t);
|
||||
static void bcm_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err);
|
||||
static void bcmfb_update_margins(video_adapter_t *adp);
|
||||
static int bcmfb_configure(int);
|
||||
|
||||
static void
|
||||
bcm_fb_init(void *arg)
|
||||
@ -134,15 +164,34 @@ bcm_fb_init(void *arg)
|
||||
struct video_adapter_softc *va_sc = &va_softc;
|
||||
int err;
|
||||
volatile struct bcm_fb_config* fb_config = sc->fb_config;
|
||||
phandle_t node;
|
||||
pcell_t cell;
|
||||
|
||||
node = ofw_bus_get_node(sc->dev);
|
||||
|
||||
fb_config->xres = 0;
|
||||
fb_config->yres = 0;
|
||||
fb_config->bpp = 0;
|
||||
|
||||
if ((OF_getprop(node, "broadcom,width", &cell, sizeof(cell))) > 0)
|
||||
fb_config->xres = (int)fdt32_to_cpu(cell);
|
||||
if (fb_config->xres == 0)
|
||||
fb_config->xres = FB_WIDTH;
|
||||
|
||||
if ((OF_getprop(node, "broadcom,height", &cell, sizeof(cell))) > 0)
|
||||
fb_config->yres = (uint32_t)fdt32_to_cpu(cell);
|
||||
if (fb_config->yres == 0)
|
||||
fb_config->yres = FB_HEIGHT;
|
||||
|
||||
if ((OF_getprop(node, "broadcom,depth", &cell, sizeof(cell))) > 0)
|
||||
fb_config->bpp = (uint32_t)fdt32_to_cpu(cell);
|
||||
if (fb_config->bpp == 0)
|
||||
fb_config->bpp = FB_DEPTH;
|
||||
|
||||
/* TODO: replace it with FDT stuff */
|
||||
fb_config->xres = FB_WIDTH;
|
||||
fb_config->yres = FB_HEIGHT;
|
||||
fb_config->vxres = 0;
|
||||
fb_config->vyres = 0;
|
||||
fb_config->xoffset = 0;
|
||||
fb_config->yoffset = 0;
|
||||
fb_config->bpp = 24;
|
||||
fb_config->base = 0;
|
||||
fb_config->pitch = 0;
|
||||
fb_config->screen_size = 0;
|
||||
@ -154,7 +203,7 @@ bcm_fb_init(void *arg)
|
||||
bus_dmamap_sync(sc->dma_tag, sc->dma_map,
|
||||
BUS_DMASYNC_POSTREAD);
|
||||
|
||||
if (err == 0) {
|
||||
if (fb_config->base != 0) {
|
||||
device_printf(sc->dev, "%dx%d(%dx%d@%d,%d) %dbpp\n",
|
||||
fb_config->xres, fb_config->yres,
|
||||
fb_config->vxres, fb_config->vyres,
|
||||
@ -166,14 +215,19 @@ bcm_fb_init(void *arg)
|
||||
fb_config->pitch, fb_config->base,
|
||||
fb_config->screen_size);
|
||||
|
||||
if (fb_config->base) {
|
||||
va_sc->fb_addr = (intptr_t)pmap_mapdev(fb_config->base, fb_config->screen_size);
|
||||
va_sc->fb_size = fb_config->screen_size;
|
||||
va_sc->stride = fb_config->pitch;
|
||||
}
|
||||
va_sc->fb_addr = (intptr_t)pmap_mapdev(fb_config->base, fb_config->screen_size);
|
||||
va_sc->fb_size = fb_config->screen_size;
|
||||
va_sc->depth = fb_config->bpp;
|
||||
va_sc->stride = fb_config->pitch;
|
||||
|
||||
va_sc->width = fb_config->xres;
|
||||
va_sc->height = fb_config->yres;
|
||||
bcmfb_update_margins(&va_sc->va);
|
||||
}
|
||||
else
|
||||
else {
|
||||
device_printf(sc->dev, "Failed to set framebuffer info\n");
|
||||
return;
|
||||
}
|
||||
|
||||
config_intrhook_disestablish(&sc->init_hook);
|
||||
}
|
||||
@ -181,7 +235,7 @@ bcm_fb_init(void *arg)
|
||||
static int
|
||||
bcm_fb_probe(device_t dev)
|
||||
{
|
||||
int error;
|
||||
int error = 0;
|
||||
|
||||
if (!ofw_bus_is_compatible(dev, "broadcom,bcm2835-fb"))
|
||||
return (ENXIO);
|
||||
@ -190,10 +244,10 @@ bcm_fb_probe(device_t dev)
|
||||
|
||||
error = sc_probe_unit(device_get_unit(dev),
|
||||
device_get_flags(dev) | SC_AUTODETECT_KBD);
|
||||
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
}
|
||||
|
||||
@ -293,12 +347,11 @@ static driver_t bcm_fb_driver = {
|
||||
sizeof(struct bcmsc_softc),
|
||||
};
|
||||
|
||||
DRIVER_MODULE(bcm2835fb, simplebus, bcm_fb_driver, bcm_fb_devclass, 0, 0);
|
||||
DRIVER_MODULE(bcm2835fb, fdtbus, bcm_fb_driver, bcm_fb_devclass, 0, 0);
|
||||
|
||||
/*
|
||||
* Video driver routines and glue.
|
||||
*/
|
||||
static int bcmfb_configure(int);
|
||||
static vi_probe_t bcmfb_probe;
|
||||
static vi_init_t bcmfb_init;
|
||||
static vi_get_info_t bcmfb_get_info;
|
||||
@ -374,22 +427,62 @@ RENDERER_MODULE(bcmfb, gfb_set);
|
||||
static uint16_t bcmfb_static_window[ROW*COL];
|
||||
extern u_char dflt_font_16[];
|
||||
|
||||
/*
|
||||
* Update videoadapter settings after changing resolution
|
||||
*/
|
||||
static void
|
||||
bcmfb_update_margins(video_adapter_t *adp)
|
||||
{
|
||||
struct video_adapter_softc *sc;
|
||||
video_info_t *vi;
|
||||
|
||||
sc = (struct video_adapter_softc *)adp;
|
||||
vi = &adp->va_info;
|
||||
|
||||
sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
|
||||
sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
|
||||
}
|
||||
|
||||
static int
|
||||
bcmfb_configure(int flags)
|
||||
{
|
||||
struct video_adapter_softc *sc;
|
||||
struct video_adapter_softc *va_sc;
|
||||
|
||||
sc = &va_softc;
|
||||
va_sc = &va_softc;
|
||||
phandle_t display, root;
|
||||
pcell_t cell;
|
||||
|
||||
if (sc->initialized)
|
||||
return 0;
|
||||
if (va_sc->initialized)
|
||||
return (0);
|
||||
|
||||
sc->height = FB_HEIGHT;
|
||||
sc->width = FB_WIDTH;
|
||||
va_sc->width = 0;
|
||||
va_sc->height = 0;
|
||||
|
||||
bcmfb_init(0, &sc->va, 0);
|
||||
/*
|
||||
* It seems there is no way to let syscons framework know
|
||||
* that framebuffer resolution has changed. So just try
|
||||
* to fetch data from FDT and go with defaults if failed
|
||||
*/
|
||||
root = OF_finddevice("/");
|
||||
if ((root != 0) &&
|
||||
(display = fdt_find_compatible(root, "broadcom,bcm2835-fb", 1))) {
|
||||
if ((OF_getprop(display, "broadcom,width",
|
||||
&cell, sizeof(cell))) > 0)
|
||||
va_sc->width = (int)fdt32_to_cpu(cell);
|
||||
|
||||
sc->initialized = 1;
|
||||
if ((OF_getprop(display, "broadcom,height",
|
||||
&cell, sizeof(cell))) > 0)
|
||||
va_sc->height = (int)fdt32_to_cpu(cell);
|
||||
}
|
||||
|
||||
if (va_sc->width == 0)
|
||||
va_sc->width = FB_WIDTH;
|
||||
if (va_sc->height == 0)
|
||||
va_sc->height = FB_HEIGHT;
|
||||
|
||||
bcmfb_init(0, &va_sc->va, 0);
|
||||
|
||||
va_sc->initialized = 1;
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -415,6 +508,7 @@ bcmfb_init(int unit, video_adapter_t *adp, int flags)
|
||||
sc->font = dflt_font_16;
|
||||
vi->vi_cheight = BCMFB_FONT_HEIGHT;
|
||||
vi->vi_cwidth = 8;
|
||||
|
||||
vi->vi_width = sc->width/8;
|
||||
vi->vi_height = sc->height/vi->vi_cheight;
|
||||
|
||||
@ -429,6 +523,7 @@ bcmfb_init(int unit, video_adapter_t *adp, int flags)
|
||||
sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
|
||||
sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
|
||||
|
||||
|
||||
adp->va_window = (vm_offset_t) bcmfb_static_window;
|
||||
adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
|
||||
|
||||
@ -541,6 +636,12 @@ static int
|
||||
bcmfb_blank_display(video_adapter_t *adp, int mode)
|
||||
{
|
||||
|
||||
struct video_adapter_softc *sc;
|
||||
|
||||
sc = (struct video_adapter_softc *)adp;
|
||||
if (sc && sc->fb_addr)
|
||||
memset((void*)sc->fb_addr, 0, sc->fb_size);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -638,6 +739,7 @@ bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
|
||||
uint8_t *addr;
|
||||
u_char *p;
|
||||
uint8_t fg, bg, color;
|
||||
uint16_t rgb;
|
||||
|
||||
sc = (struct video_adapter_softc *)adp;
|
||||
|
||||
@ -651,11 +753,8 @@ bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
|
||||
+ (row + sc->ymargin)*(sc->stride)
|
||||
+ 3 * (col + sc->xmargin);
|
||||
|
||||
/*
|
||||
* FIXME: hardcoded
|
||||
*/
|
||||
bg = 0x00;
|
||||
fg = 0x80;
|
||||
fg = a & 0xf ;
|
||||
bg = (a >> 8) & 0xf;
|
||||
|
||||
for (i = 0; i < BCMFB_FONT_HEIGHT; i++) {
|
||||
for (j = 0, k = 7; j < 8; j++, k--) {
|
||||
@ -664,9 +763,28 @@ bcmfb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
|
||||
else
|
||||
color = fg;
|
||||
|
||||
addr[3*j] = color;
|
||||
addr[3*j+1] = color;
|
||||
addr[3*j+2] = color;
|
||||
switch (sc->depth) {
|
||||
case 32:
|
||||
addr[4*j+0] = bcmfb_palette[color].r;
|
||||
addr[4*j+1] = bcmfb_palette[color].g;
|
||||
addr[4*j+2] = bcmfb_palette[color].b;
|
||||
addr[4*j+3] = bcmfb_palette[color].a;
|
||||
break;
|
||||
case 24:
|
||||
addr[3*j] = bcmfb_palette[color].r;
|
||||
addr[3*j+1] = bcmfb_palette[color].g;
|
||||
addr[3*j+2] = bcmfb_palette[color].b;
|
||||
break;
|
||||
case 16:
|
||||
rgb = (bcmfb_palette[color].r >> 3) << 10;
|
||||
rgb |= (bcmfb_palette[color].g >> 3) << 5;
|
||||
rgb |= (bcmfb_palette[color].b >> 3);
|
||||
addr[2*j] = (rgb >> 8) & 0xff;
|
||||
addr[2*j + 1] = rgb & 0xff;
|
||||
default:
|
||||
/* Not supported yet */
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
addr += (sc->stride);
|
||||
|
Loading…
Reference in New Issue
Block a user