1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/lcd.c Sun Jun 07 02:20:54 2015 +0200
1.3 @@ -0,0 +1,88 @@
1.4 +/*
1.5 + * Ben NanoNote LCD initialisation, based on uboot-xburst and xburst-tools.
1.6 + *
1.7 + * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.8 + * Copyright (C) 2001-2002 Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
1.9 + *
1.10 + * This program is free software; you can redistribute it and/or modify it under
1.11 + * the terms of the GNU General Public License as published by the Free Software
1.12 + * Foundation; either version 3 of the License, or (at your option) any later
1.13 + * version.
1.14 + *
1.15 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.16 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.17 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.18 + * details.
1.19 + *
1.20 + * You should have received a copy of the GNU General Public License along with
1.21 + * this program. If not, see <http://www.gnu.org/licenses/>.
1.22 + */
1.23 +
1.24 +#include "xburst_types.h"
1.25 +#include "nanonote_gpm940b0.h"
1.26 +#include "board-nanonote.h"
1.27 +
1.28 +#define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1)
1.29 +#define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
1.30 +
1.31 +unsigned long lcd_setmem(unsigned long addr)
1.32 +{
1.33 + unsigned long size;
1.34 +
1.35 + size = lcd_get_size();
1.36 +
1.37 + /* Round up to nearest full page, or MMU section if defined */
1.38 + size = ALIGN(size, PAGE_SIZE);
1.39 + addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE);
1.40 +
1.41 + /* Allocate pages for the frame buffer. */
1.42 + addr -= size;
1.43 +
1.44 + return addr;
1.45 +}
1.46 +
1.47 +#define N_BLK_VERT 2
1.48 +#define N_BLK_HOR 3
1.49 +
1.50 +static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
1.51 + 0x00ff0000, 0x0000ff00, 0x00ffff00,
1.52 + 0x000000ff, 0x00ff00ff, 0x0000ffff,
1.53 +};
1.54 +
1.55 +static void test_pattern(void *lcd_base)
1.56 +{
1.57 + unsigned short v_max = panel_info.vl_row;
1.58 + unsigned short h_max = panel_info.vl_col;
1.59 + unsigned short v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
1.60 + unsigned short h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
1.61 + unsigned short v, h;
1.62 + unsigned char *pix = (unsigned char *)lcd_base;
1.63 +
1.64 + /* WARNING: Code silently assumes 8bit/pixel */
1.65 + for (v = 0; v < v_max; ++v) {
1.66 + unsigned char iy = v / v_step;
1.67 + for (h = 0; h < h_max; ++h) {
1.68 + unsigned char ix = N_BLK_HOR * iy + h / h_step;
1.69 + *pix++ = test_colors[ix];
1.70 + }
1.71 + }
1.72 +}
1.73 +
1.74 +void lcd_clear(void *lcd_base)
1.75 +{
1.76 + test_pattern(lcd_base);
1.77 +}
1.78 +
1.79 +/* LCD initialisation. */
1.80 +
1.81 +static void *lcd_base;
1.82 +
1.83 +void lcd_init(void)
1.84 +{
1.85 + /* Start from the top of memory and obtain a framebuffer region. */
1.86 +
1.87 + lcd_base = (void *) lcd_setmem(get_memory_size());
1.88 + lcd_ctrl_init(lcd_base);
1.89 + lcd_clear(lcd_base);
1.90 + lcd_enable();
1.91 +}