2012-09-26 23:59:58 -04:00
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2012-09-10 22:44:54 -04:00
|
|
|
#include <framebuffer.h>
|
2012-10-07 23:25:11 -04:00
|
|
|
#include <init.h>
|
2012-10-02 23:12:16 -04:00
|
|
|
#include <math.h>
|
2013-01-01 23:42:45 -05:00
|
|
|
#include <frames.h>
|
2012-10-07 23:25:11 -04:00
|
|
|
#include <types.h>
|
|
|
|
|
|
|
|
#include <drivers/fb.h>
|
2012-09-10 22:44:54 -04:00
|
|
|
|
|
|
|
#define PL111_CR_EN 0x001
|
|
|
|
#define PL111_CR_PWR 0x800
|
|
|
|
#define PL111_IOBASE 0x10020000
|
|
|
|
#define PL111_PALBASE (PL111_IOBASE + 0x200)
|
|
|
|
|
|
|
|
struct pl111_control {
|
|
|
|
uint32 volatile timing0; //0
|
|
|
|
uint32 volatile timing1; //4
|
|
|
|
uint32 volatile timing2; //8
|
|
|
|
uint32 volatile timing3; //c
|
|
|
|
uint32 volatile upbase; //10
|
|
|
|
uint32 volatile lpbase; //14
|
|
|
|
uint32 volatile control; //18
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fbdev pl111_fb_device;
|
|
|
|
|
2012-10-07 23:25:11 -04:00
|
|
|
int pl111_init_dev(struct fb *f, unsigned int color_depth) {
|
2012-10-02 23:12:16 -04:00
|
|
|
unsigned int width, height;
|
|
|
|
unsigned int fb_size, power;
|
2012-09-10 22:44:54 -04:00
|
|
|
struct pl111_control *plio = (struct pl111_control*)PL111_IOBASE;
|
2013-01-01 23:42:45 -05:00
|
|
|
struct frame *fr;
|
2012-09-10 22:44:54 -04:00
|
|
|
|
|
|
|
/* 640x480 pixels */
|
2012-10-02 23:12:16 -04:00
|
|
|
width = 640;
|
|
|
|
height = 480;
|
2012-09-10 22:44:54 -04:00
|
|
|
plio->timing0 = 0x3f1f3f9c;
|
|
|
|
plio->timing1 = 0x080b61df;
|
2012-10-02 23:12:16 -04:00
|
|
|
|
|
|
|
/* Allocate memory for framebuffer */
|
|
|
|
fb_size = width * height * (color_depth / 8);
|
2013-01-01 23:53:18 -05:00
|
|
|
power = log(fb_size) - log(CONFIG_PAGE_SIZE);
|
2012-10-02 23:12:16 -04:00
|
|
|
if ((unsigned int)1<<power < fb_size)
|
|
|
|
power++;
|
2013-01-01 23:42:45 -05:00
|
|
|
fr = get_free_frames(power);
|
|
|
|
if (!fr)
|
2012-10-02 23:12:16 -04:00
|
|
|
return -1;
|
|
|
|
|
2013-01-01 23:42:45 -05:00
|
|
|
plio->upbase = (uint32)fr->address;
|
2012-09-10 22:44:54 -04:00
|
|
|
|
|
|
|
if (color_depth == FB_COLOR_DEPTH_8) {
|
|
|
|
plio->control = 0x1827;
|
|
|
|
} else if (color_depth == FB_COLOR_DEPTH_16) {
|
|
|
|
plio->control = 0x1829;
|
|
|
|
} else if (color_depth == FB_COLOR_DEPTH_24) {
|
|
|
|
plio->control = 0x182B;
|
|
|
|
} else {
|
|
|
|
//assume 16 if nothing else fit
|
|
|
|
color_depth = 16;
|
|
|
|
plio->control = 0x1829;
|
|
|
|
}
|
|
|
|
|
|
|
|
f->device = &pl111_fb_device;
|
2012-10-02 23:12:16 -04:00
|
|
|
f->device->fbaddr = (void*)plio->upbase;
|
|
|
|
f->width = width;
|
|
|
|
f->device->pixelwidth = width;
|
|
|
|
f->height = height;
|
|
|
|
f->device->pixelheight = height;
|
2012-09-10 22:44:54 -04:00
|
|
|
|
|
|
|
f->color_depth = color_depth;
|
|
|
|
f->device->color_depth = color_depth;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2012-10-07 23:25:11 -04:00
|
|
|
|
|
|
|
struct fb_dev pl111_dev = {
|
2012-10-07 23:38:37 -04:00
|
|
|
.name = "pl111",
|
2012-10-07 23:25:11 -04:00
|
|
|
.init = &pl111_init_dev
|
|
|
|
};
|
|
|
|
|
|
|
|
void pl111_init() {
|
|
|
|
fb_register_device(&pl111_dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
device_initcall(pl111_init);
|