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 u8 *get_pixel4(unsigned short h, unsigned short v) 58 { 59 return (u8 *) (lcd_base + v * get_line_length()) + h / 2; 60 } 61 62 static inline unsigned short div(unsigned short num, unsigned short denom, unsigned short scale) 63 { 64 return (scale * num) / denom; 65 } 66 67 static unsigned long pixel(unsigned short h, unsigned short v, u8 rmax, u8 gmax, u8 bmax, u8 rshift, u8 gshift, u8 bshift) 68 { 69 unsigned short v_max = panel_info.vl_row; 70 unsigned short h_max = panel_info.vl_col; 71 72 return (((rmax - div(h, h_max, rmax + 1) + rmax - div(v, v_max, rmax + 1)) / 2) << rshift) | 73 ((gmax - div(v, v_max, gmax + 1)) << gshift) | 74 (((div(h, h_max, bmax + 1) + div(v, v_max, bmax + 1)) / 2) << bshift); 75 } 76 77 static void test_pixel32(unsigned short h, unsigned short v) 78 { 79 u32 *pix = get_pixel32(h, v); 80 *pix = (u32) pixel(h, v, 255, 255, 255, 16, 8, 0); 81 } 82 83 static void test_pixel16_565(unsigned short h, unsigned short v) 84 { 85 u16 *pix = get_pixel16(h, v); 86 *pix = (u16) pixel(h, v, 31, 63, 31, 11, 5, 0); 87 } 88 89 static void test_pixel8(unsigned short h, unsigned short v) 90 { 91 u8 *pix = get_pixel8(h, v); 92 *pix = (u8) pixel(h, v, 7, 7, 3, 5, 2, 0); 93 } 94 95 static void test_pixel4(unsigned short h, unsigned short v) 96 { 97 u8 *pix = get_pixel4(h, v); 98 u8 mask = h & 1 ? 0xf0 : 0x0f; 99 *pix = (*pix & mask) | ((u8) pixel(h, v, 1, 2, 1, 3, 1, 0) << (h & 1 ? 0 : 4)); 100 } 101 102 void test_pixel(unsigned short h, unsigned short v) 103 { 104 switch (panel_info.vl_bpix) 105 { 106 case LCD_COLOR32: 107 test_pixel32(h, v); 108 break; 109 110 case LCD_COLOR8: 111 test_pixel8(h, v); 112 break; 113 114 case LCD_COLOR4: 115 test_pixel4(h, v); 116 break; 117 118 case LCD_COLOR16: 119 default: 120 test_pixel16_565(h, v); 121 break; 122 } 123 } 124 125 void clear_pixel32(unsigned short h, unsigned short v) 126 { 127 u32 *pix = get_pixel32(h, v); 128 *pix = 0; 129 } 130 131 void clear_pixel16(unsigned short h, unsigned short v) 132 { 133 u16 *pix = get_pixel16(h, v); 134 *pix = 0; 135 } 136 137 void clear_pixel8(unsigned short h, unsigned short v) 138 { 139 u8 *pix = get_pixel8(h, v); 140 *pix = 0; 141 } 142 143 void clear_pixel4(unsigned short h, unsigned short v) 144 { 145 u8 *pix = get_pixel4(h, v); 146 u8 mask = h & 1 ? 0xf0 : 0x0f; 147 *pix = *pix & mask; 148 } 149 150 void clear_pixel(unsigned short h, unsigned short v) 151 { 152 switch (panel_info.vl_bpix) 153 { 154 case LCD_COLOR32: 155 clear_pixel32(h, v); 156 break; 157 158 case LCD_COLOR8: 159 clear_pixel8(h, v); 160 break; 161 162 case LCD_COLOR4: 163 clear_pixel4(h, v); 164 break; 165 166 case LCD_COLOR16: 167 default: 168 clear_pixel16(h, v); 169 break; 170 } 171 } 172 173 void test_pattern() 174 { 175 unsigned short v_max = panel_info.vl_row; 176 unsigned short h_max = panel_info.vl_col; 177 unsigned short v, h; 178 179 for (v = 0; v < v_max; v += 1) { 180 for (h = 0; h < h_max; h += 1) { 181 test_pixel(h, v); 182 } 183 } 184 } 185 186 void lcd_clear(unsigned long lcd_base) 187 { 188 unsigned short v_max = panel_info.vl_row; 189 unsigned short h_max = panel_info.vl_col; 190 unsigned short v, h; 191 unsigned long *pix = (unsigned long *)lcd_base; 192 193 for (v = 0; v < v_max; v += 1) { 194 for (h = 0; h < h_max; h += 1) { 195 *pix++ = 0; 196 } 197 } 198 } 199 200 /* LCD initialisation. */ 201 202 void lcd_init(void) 203 { 204 __lcd_display_pin_init(); 205 __lcd_display_on(); 206 207 lcd_base = lcd_ctrl_init(); 208 lcd_clear(lcd_base); 209 lcd_enable(); 210 }