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, 2016 Paul Boddie <paul@boddie.org.uk> 6 * 7 * This program is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21 #ifdef CONFIG_CPU_JZ4730_MINIPC 22 #include "minipc_claa070vc01.h" 23 #include "minipc.h" 24 #else 25 #include "nanonote_gpm940b0.h" 26 #include "nanonote.h" 27 #endif 28 29 #include "xburst_types.h" 30 #include "jzlcd.h" 31 #include "sdram.h" 32 #include "board.h" 33 34 extern vidinfo_t panel_info; 35 static unsigned long lcd_base; 36 37 static unsigned int get_line_length() 38 { 39 return ALIGN((panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8, sizeof(u32)); 40 } 41 42 static u32 *get_pixel32(unsigned short h, unsigned short v) 43 { 44 return (u32 *) (lcd_base + v * get_line_length()) + h; 45 } 46 47 static u16 *get_pixel16(unsigned short h, unsigned short v) 48 { 49 return (u16 *) (lcd_base + v * get_line_length()) + h; 50 } 51 52 static void test_pixel32(unsigned short h, unsigned short v) 53 { 54 unsigned short v_max = panel_info.vl_row; 55 unsigned short h_max = panel_info.vl_col; 56 u32 *pix = get_pixel32(h, v); 57 58 *pix = ( 59 (((255 * (h_max - h)) / (h_max - 1)) << 16) + 60 ((((255 * h) / (h_max - 1) + (255 * (v_max - v)) / (v_max - 1)) / 2) << 8) + 61 ((255 * v) / (v_max - 1)) 62 ); 63 } 64 65 static void test_pixel16_565(unsigned short h, unsigned short v) 66 { 67 unsigned short v_max = panel_info.vl_row; 68 unsigned short h_max = panel_info.vl_col; 69 u16 *pix = get_pixel16(h, v); 70 71 *pix = ( 72 (((31 * (h_max - h)) / (h_max - 1)) << 11) + 73 ((((63 * h) / (h_max - 1) + (63 * (v_max - v)) / (v_max - 1)) / 2) << 5) + 74 ((31 * v) / (v_max - 1)) 75 ); 76 } 77 78 void test_pixel(unsigned short h, unsigned short v) 79 { 80 switch (panel_info.vl_bpix) 81 { 82 case LCD_COLOR32: 83 test_pixel32(h, v); 84 break; 85 86 default: 87 test_pixel16_565(h, v); 88 break; 89 } 90 } 91 92 void clear_pixel32(unsigned short h, unsigned short v) 93 { 94 u32 *pix = get_pixel32(h, v); 95 *pix = 0; 96 } 97 98 void clear_pixel16(unsigned short h, unsigned short v) 99 { 100 u16 *pix = get_pixel16(h, v); 101 *pix = 0; 102 } 103 104 void clear_pixel(unsigned short h, unsigned short v) 105 { 106 switch (panel_info.vl_bpix) 107 { 108 case LCD_COLOR32: 109 clear_pixel32(h, v); 110 break; 111 112 default: 113 clear_pixel16(h, v); 114 break; 115 } 116 } 117 118 void test_pattern() 119 { 120 unsigned short v_max = panel_info.vl_row; 121 unsigned short h_max = panel_info.vl_col; 122 unsigned short v, h; 123 124 for (v = 0; v < v_max; v += 1) { 125 for (h = 0; h < h_max; h += 1) { 126 test_pixel(h, v); 127 } 128 } 129 } 130 131 void lcd_clear(unsigned long lcd_base) 132 { 133 unsigned short v_max = panel_info.vl_row; 134 unsigned short h_max = panel_info.vl_col; 135 unsigned short v, h; 136 unsigned long *pix = (unsigned long *)lcd_base; 137 138 for (v = 0; v < v_max; v += 1) { 139 for (h = 0; h < h_max; h += 1) { 140 *pix++ = 0; 141 } 142 } 143 } 144 145 /* LCD initialisation. */ 146 147 void lcd_init(void) 148 { 149 __lcd_display_pin_init(); 150 __lcd_display_on(); 151 152 lcd_base = lcd_ctrl_init(); 153 lcd_clear(lcd_base); 154 lcd_enable(); 155 }