95 lines
2.5 KiB
C
95 lines
2.5 KiB
C
/*
|
|
Copyright (C) 2012, Aaron Lindsay <aaron@aclindsay.com>
|
|
|
|
This file is part of Aedrix.
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
(at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
*/
|
|
|
|
#include <types.h>
|
|
#include <framebuffer.h>
|
|
#include <kmalloc.h>
|
|
#include <print.h>
|
|
#include <drivers/bcm2835_mailbox.h>
|
|
|
|
struct bcm2835_config {
|
|
uint32 width;
|
|
uint32 height;
|
|
uint32 vwidth;
|
|
uint32 vheight;
|
|
uint32 pitch;
|
|
uint32 color_depth;
|
|
uint32 xoffset;
|
|
uint32 yoffset;
|
|
uint32 fb_base_addr;
|
|
uint32 size;
|
|
};
|
|
|
|
#define MAILBOX_BUFFER_SIZE (32*4*2)
|
|
#define FB_WIDTH 1024
|
|
#define FB_HEIGHT 768
|
|
|
|
struct fbdev bcm2835_fb_device;
|
|
|
|
int bcm2835_videocore_init(struct fb *f, unsigned int color_depth) {
|
|
struct bcm2835_config *cfg;
|
|
uint32 result;
|
|
void *mailbox_buffer_orig, *mailbox_buffer;
|
|
|
|
if (!(mailbox_buffer_orig = kmalloc(MAILBOX_BUFFER_SIZE))) {
|
|
return -1;
|
|
}
|
|
|
|
/* Round mailbox buffer to multiple of 0x10 because the low 4 bits of
|
|
the mailbox are used to send the channel, and therefore can't hold the low 4
|
|
bits of the address */
|
|
if ((uint32)mailbox_buffer_orig & 0xf)
|
|
mailbox_buffer = (void *)((uint32)mailbox_buffer_orig & ~0xf) + 0x10;
|
|
else
|
|
mailbox_buffer = mailbox_buffer_orig;
|
|
|
|
cfg = (struct bcm2835_config *)mailbox_buffer;
|
|
cfg->width = FB_WIDTH;
|
|
cfg->height = FB_HEIGHT;
|
|
cfg->vwidth = FB_WIDTH;
|
|
cfg->vheight = FB_HEIGHT;
|
|
cfg->pitch = 0;
|
|
cfg->color_depth = color_depth;
|
|
cfg->xoffset = 0;
|
|
cfg->yoffset = 0;
|
|
cfg->fb_base_addr = 0;
|
|
cfg->size = 0;
|
|
|
|
mailbox_write(MBOX_FB, (uint32)cfg);
|
|
result = mailbox_read(MBOX_FB);
|
|
|
|
if (result || !cfg->fb_base_addr) {
|
|
print("Error: did not request a proper framebuffer\n");
|
|
return -1;
|
|
}
|
|
|
|
f->device = &bcm2835_fb_device;
|
|
f->device->fbaddr = (void*)cfg->fb_base_addr;
|
|
f->width = cfg->width;
|
|
f->device->pixelwidth = cfg->width;
|
|
f->height = cfg->height;
|
|
f->device->pixelheight = cfg->height;
|
|
|
|
f->color_depth = color_depth;
|
|
f->device->color_depth = color_depth;
|
|
|
|
return 0;
|
|
}
|