1 /* 2 * Ben NanoNote LCD initialisation, based on uboot-xburst and xburst-tools. 3 * 4 * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 5 * Copyright (C) 2001-2002 Wolfgang Denk, DENX Software Engineering, <wd@denx.de> 6 * 7 * This program is free software; you can redistribute it and/or modify it under 8 * the terms of the GNU General Public License as published by the Free Software 9 * Foundation; either version 3 of the License, or (at your option) any later 10 * version. 11 * 12 * This program is distributed in the hope that it will be useful, but WITHOUT 13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 15 * details. 16 * 17 * You should have received a copy of the GNU General Public License along with 18 * this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #include "xburst_types.h" 22 #include "nanonote_gpm940b0.h" 23 #include "board-nanonote.h" 24 25 #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) 26 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 27 28 unsigned long lcd_setmem(unsigned long addr) 29 { 30 unsigned long size; 31 32 size = lcd_get_size(); 33 34 /* Round up to nearest full page, or MMU section if defined */ 35 size = ALIGN(size, PAGE_SIZE); 36 addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE); 37 38 /* Allocate pages for the frame buffer. */ 39 addr -= size; 40 41 return addr; 42 } 43 44 #define N_BLK_VERT 2 45 #define N_BLK_HOR 3 46 47 static int test_colors[N_BLK_HOR * N_BLK_VERT] = { 48 0x00ff0000, 0x0000ff00, 0x00ffff00, 49 0x000000ff, 0x00ff00ff, 0x0000ffff, 50 }; 51 52 static void test_pattern(void *lcd_base) 53 { 54 unsigned short v_max = panel_info.vl_row; 55 unsigned short h_max = panel_info.vl_col; 56 unsigned short v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; 57 unsigned short h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; 58 unsigned short v, h; 59 unsigned char *pix = (unsigned char *)lcd_base; 60 61 /* WARNING: Code silently assumes 8bit/pixel */ 62 for (v = 0; v < v_max; ++v) { 63 unsigned char iy = v / v_step; 64 for (h = 0; h < h_max; ++h) { 65 unsigned char ix = N_BLK_HOR * iy + h / h_step; 66 *pix++ = test_colors[ix]; 67 } 68 } 69 } 70 71 void lcd_clear(void *lcd_base) 72 { 73 test_pattern(lcd_base); 74 } 75 76 /* LCD initialisation. */ 77 78 static void *lcd_base; 79 80 void lcd_init(void) 81 { 82 /* Start from the top of memory and obtain a framebuffer region. */ 83 84 lcd_base = (void *) lcd_setmem(get_memory_size()); 85 lcd_ctrl_init(lcd_base); 86 lcd_clear(lcd_base); 87 lcd_enable(); 88 }