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 u8 *get_pixel8(unsigned short h, unsigned short v) 53 { 54 return (u8 *) (lcd_base + v * get_line_length()) + h; 55 } 56 57 static unsigned long pixel(unsigned short h, unsigned short v, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift) 58 { 59 unsigned short v_max = panel_info.vl_row; 60 unsigned short h_max = panel_info.vl_col; 61 62 return (((rmax * (h_max - h - 1)) / h_max) << rshift) | 63 ((((gmax * h) / (h_max - 1) + (gmax * (v_max - v - 1)) / v_max) / 2) << gshift) | 64 (((bmax * v) / (v_max - 1)) << bshift); 65 } 66 67 static void test_pixel32(unsigned short h, unsigned short v) 68 { 69 u32 *pix = get_pixel32(h, v); 70 *pix = (u32) pixel(h, v, 255, 255, 255, 16, 8, 0); 71 } 72 73 static void test_pixel16_565(unsigned short h, unsigned short v) 74 { 75 u16 *pix = get_pixel16(h, v); 76 *pix = (u16) pixel(h, v, 31, 63, 31, 11, 5, 0); 77 } 78 79 static void test_pixel8(unsigned short h, unsigned short v) 80 { 81 u8 *pix = get_pixel8(h, v); 82 *pix = (u8) pixel(h, v, 7, 7, 3, 5, 2, 0); 83 } 84 85 void test_pixel(unsigned short h, unsigned short v) 86 { 87 switch (panel_info.vl_bpix) 88 { 89 case LCD_COLOR32: 90 test_pixel32(h, v); 91 break; 92 93 case LCD_COLOR8: 94 test_pixel8(h, v); 95 break; 96 97 case LCD_COLOR16: 98 default: 99 test_pixel16_565(h, v); 100 break; 101 } 102 } 103 104 void clear_pixel32(unsigned short h, unsigned short v) 105 { 106 u32 *pix = get_pixel32(h, v); 107 *pix = 0; 108 } 109 110 void clear_pixel16(unsigned short h, unsigned short v) 111 { 112 u16 *pix = get_pixel16(h, v); 113 *pix = 0; 114 } 115 116 void clear_pixel8(unsigned short h, unsigned short v) 117 { 118 u8 *pix = get_pixel8(h, v); 119 *pix = 0; 120 } 121 122 void clear_pixel(unsigned short h, unsigned short v) 123 { 124 switch (panel_info.vl_bpix) 125 { 126 case LCD_COLOR32: 127 clear_pixel32(h, v); 128 break; 129 130 case LCD_COLOR8: 131 clear_pixel8(h, v); 132 break; 133 134 case LCD_COLOR16: 135 default: 136 clear_pixel16(h, v); 137 break; 138 } 139 } 140 141 void test_pattern() 142 { 143 unsigned short v_max = panel_info.vl_row; 144 unsigned short h_max = panel_info.vl_col; 145 unsigned short v, h; 146 147 for (v = 0; v < v_max; v += 1) { 148 for (h = 0; h < h_max; h += 1) { 149 test_pixel(h, v); 150 } 151 } 152 } 153 154 void lcd_clear(unsigned long lcd_base) 155 { 156 unsigned short v_max = panel_info.vl_row; 157 unsigned short h_max = panel_info.vl_col; 158 unsigned short v, h; 159 unsigned long *pix = (unsigned long *)lcd_base; 160 161 for (v = 0; v < v_max; v += 1) { 162 for (h = 0; h < h_max; h += 1) { 163 *pix++ = 0; 164 } 165 } 166 } 167 168 /* LCD initialisation. */ 169 170 void lcd_init(void) 171 { 172 __lcd_display_pin_init(); 173 __lcd_display_on(); 174 175 lcd_base = lcd_ctrl_init(); 176 lcd_clear(lcd_base); 177 lcd_enable(); 178 }