1 /* 2 * Ben NanoNote LCD initialisation, based on uboot-xburst and xburst-tools. 3 * 4 * Copyright (C) 2001-2002 Wolfgang Denk, DENX Software Engineering, <wd@denx.de> 5 * Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> 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 "jzlcd.h" 24 #include "sdram.h" 25 #include "board.h" 26 27 #define ALIGN(x,a) __ALIGN_MASK((x),(typeof(x))(a)-1) 28 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask)) 29 30 unsigned long lcd_setmem(unsigned long addr) 31 { 32 unsigned long size; 33 34 size = lcd_get_size(); 35 36 /* Round up to nearest full page, or MMU section if defined */ 37 size = ALIGN(size, PAGE_SIZE); 38 addr = ALIGN(addr - PAGE_SIZE + 1, PAGE_SIZE); 39 40 /* Allocate pages for the frame buffer. */ 41 addr -= size; 42 43 return addr; 44 } 45 46 static void test_pattern(void *lcd_base) 47 { 48 unsigned short v_max = panel_info.vl_row; 49 unsigned short h_max = panel_info.vl_col; 50 unsigned short v, h; 51 u32 *pix = (u32 *)lcd_base; 52 53 /* WARNING: Code silently assumes 32 bit/pixel */ 54 for (v = 0; v < v_max; v += 1) { 55 for (h = 0; h < h_max; h += 1) { 56 *pix++ = ( 57 (((255 * (h_max - h)) / (h_max - 1)) << 16) + 58 ((((255 * h) / (h_max - 1) + (255 * (v_max - v)) / (v_max - 1)) / 2) << 8) + 59 ((255 * v) / (v_max - 1)) 60 ); 61 } 62 } 63 } 64 65 void lcd_clear(void *lcd_base) 66 { 67 test_pattern(lcd_base); 68 } 69 70 /* LCD initialisation. */ 71 72 static void *lcd_base; 73 74 void lcd_init(void) 75 { 76 __lcd_display_pin_init(); 77 __lcd_display_on(); 78 79 /* Start from the top of memory and obtain a framebuffer region. */ 80 81 lcd_base = (void *) lcd_setmem(get_memory_size()); 82 lcd_ctrl_init(lcd_base); 83 lcd_clear(lcd_base); 84 lcd_enable(); 85 }