wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 3 | * Stäubli Faverges - <www.staubli.com> |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 4 | * Pierre AUBERT p.aubert@staubli.com |
| 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 7 | */ |
| 8 | /* Video support for Epson SED13806 chipset */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 12 | #include <video_fb.h> |
| 13 | #include <sed13806.h> |
| 14 | |
| 15 | #define readByte(ptrReg) \ |
| 16 | *(volatile unsigned char *)(sed13806.isaBase + ptrReg) |
| 17 | |
| 18 | #define writeByte(ptrReg,value) \ |
| 19 | *(volatile unsigned char *)(sed13806.isaBase + ptrReg) = value |
| 20 | |
wdenk | da54bc9 | 2004-08-04 21:56:49 +0000 | [diff] [blame] | 21 | #ifdef CONFIG_TOTAL5200 |
| 22 | #define writeWord(ptrReg,value) \ |
| 23 | (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = value) |
| 24 | #else |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 25 | #define writeWord(ptrReg,value) \ |
| 26 | (*(volatile unsigned short *)(sed13806.isaBase + ptrReg) = ((value >> 8 ) & 0xff) | ((value << 8) & 0xff00)) |
wdenk | da54bc9 | 2004-08-04 21:56:49 +0000 | [diff] [blame] | 27 | #endif |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 28 | |
| 29 | GraphicDevice sed13806; |
| 30 | |
| 31 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 32 | * EpsonSetRegs -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 33 | *----------------------------------------------------------------------------- |
| 34 | */ |
| 35 | static void EpsonSetRegs (void) |
| 36 | { |
| 37 | /* the content of the chipset register depends on the board (clocks, ...)*/ |
| 38 | const S1D_REGS *preg = board_get_regs (); |
| 39 | while (preg -> Index) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 40 | writeByte (preg -> Index, preg -> Value); |
| 41 | preg ++; |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 42 | } |
| 43 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 44 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 45 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 46 | * video_hw_init -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 47 | *----------------------------------------------------------------------------- |
| 48 | */ |
| 49 | void *video_hw_init (void) |
| 50 | { |
| 51 | unsigned int *vm, i; |
| 52 | |
| 53 | memset (&sed13806, 0, sizeof (GraphicDevice)); |
| 54 | |
| 55 | /* Initialization of the access to the graphic chipset |
| 56 | Retreive base address of the chipset |
| 57 | (see board/RPXClassic/eccx.c) */ |
| 58 | if ((sed13806.isaBase = board_video_init ()) == 0) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 59 | return (NULL); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | sed13806.frameAdrs = sed13806.isaBase + FRAME_BUFFER_OFFSET; |
| 63 | sed13806.winSizeX = board_get_width (); |
| 64 | sed13806.winSizeY = board_get_height (); |
| 65 | |
| 66 | #if defined(CONFIG_VIDEO_SED13806_8BPP) |
| 67 | sed13806.gdfIndex = GDF__8BIT_INDEX; |
| 68 | sed13806.gdfBytesPP = 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 69 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 70 | #elif defined(CONFIG_VIDEO_SED13806_16BPP) |
| 71 | sed13806.gdfIndex = GDF_16BIT_565RGB; |
| 72 | sed13806.gdfBytesPP = 2; |
| 73 | |
| 74 | #else |
| 75 | #error Unsupported SED13806 BPP |
| 76 | #endif |
| 77 | |
| 78 | sed13806.memSize = sed13806.winSizeX * sed13806.winSizeY * sed13806.gdfBytesPP; |
| 79 | |
| 80 | /* Load SED registers */ |
| 81 | EpsonSetRegs (); |
| 82 | |
| 83 | /* (see board/RPXClassic/RPXClassic.c) */ |
| 84 | board_validate_screen (sed13806.isaBase); |
| 85 | |
| 86 | /* Clear video memory */ |
| 87 | i = sed13806.memSize/4; |
| 88 | vm = (unsigned int *)sed13806.frameAdrs; |
| 89 | while(i--) |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 90 | *vm++ = 0; |
| 91 | |
| 92 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 93 | return (&sed13806); |
| 94 | } |
| 95 | /*----------------------------------------------------------------------------- |
| 96 | * Epson_wait_idle -- Wait for hardware to become idle |
| 97 | *----------------------------------------------------------------------------- |
| 98 | */ |
| 99 | static void Epson_wait_idle (void) |
| 100 | { |
| 101 | while (readByte (BLT_CTRL0) & 0x80); |
| 102 | |
| 103 | /* Read a word in the BitBLT memory area to shutdown the BitBLT engine */ |
| 104 | *(volatile unsigned short *)(sed13806.isaBase + BLT_REG); |
| 105 | } |
| 106 | |
| 107 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 108 | * video_hw_bitblt -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 109 | *----------------------------------------------------------------------------- |
| 110 | */ |
| 111 | void video_hw_bitblt ( |
| 112 | unsigned int bpp, /* bytes per pixel */ |
| 113 | unsigned int src_x, /* source pos x */ |
| 114 | unsigned int src_y, /* source pos y */ |
| 115 | unsigned int dst_x, /* dest pos x */ |
| 116 | unsigned int dst_y, /* dest pos y */ |
| 117 | unsigned int dim_x, /* frame width */ |
| 118 | unsigned int dim_y /* frame height */ |
| 119 | ) |
| 120 | { |
| 121 | register GraphicDevice *pGD = (GraphicDevice *)&sed13806; |
| 122 | unsigned long srcAddr, dstAddr; |
| 123 | unsigned int stride = bpp * pGD -> winSizeX; |
| 124 | |
| 125 | srcAddr = (src_y * stride) + (src_x * bpp); |
| 126 | dstAddr = (dst_y * stride) + (dst_x * bpp); |
| 127 | |
| 128 | Epson_wait_idle (); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 129 | |
| 130 | writeByte(BLT_ROP,0x0C); /* source */ |
| 131 | writeByte(BLT_OP,0x02);/* move blit in positive direction with ROP */ |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 132 | writeWord(BLT_MEM_OFF0, stride / 2); |
| 133 | if (pGD -> gdfIndex == GDF__8BIT_INDEX) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 134 | writeByte(BLT_CTRL1,0x00); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 135 | } |
| 136 | else { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 137 | writeByte(BLT_CTRL1,0x01); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | writeWord(BLT_WIDTH0,(dim_x - 1)); |
| 141 | writeWord(BLT_HEIGHT0,(dim_y - 1)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 142 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 143 | /* set up blit registers */ |
| 144 | writeByte(BLT_SRC_ADDR0,srcAddr); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 145 | writeByte(BLT_SRC_ADDR1,srcAddr>>8); |
| 146 | writeByte(BLT_SRC_ADDR2,srcAddr>>16); |
| 147 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 148 | writeByte(BLT_DST_ADDR0,dstAddr); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 149 | writeByte(BLT_DST_ADDR1,dstAddr>>8); |
| 150 | writeByte(BLT_DST_ADDR2,dstAddr>>16); |
| 151 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 152 | /* Engage the blt engine */ |
| 153 | /* rectangular region for src and dst */ |
| 154 | writeByte(BLT_CTRL0,0x80); |
| 155 | |
| 156 | /* wait untill current blits finished */ |
| 157 | Epson_wait_idle (); |
| 158 | } |
| 159 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 160 | * video_hw_rectfill -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 161 | *----------------------------------------------------------------------------- |
| 162 | */ |
| 163 | void video_hw_rectfill ( |
| 164 | unsigned int bpp, /* bytes per pixel */ |
| 165 | unsigned int dst_x, /* dest pos x */ |
| 166 | unsigned int dst_y, /* dest pos y */ |
| 167 | unsigned int dim_x, /* frame width */ |
| 168 | unsigned int dim_y, /* frame height */ |
| 169 | unsigned int color /* fill color */ |
| 170 | ) |
| 171 | { |
| 172 | register GraphicDevice *pGD = (GraphicDevice *)&sed13806; |
| 173 | unsigned long dstAddr; |
| 174 | unsigned int stride = bpp * pGD -> winSizeX; |
| 175 | |
| 176 | dstAddr = (dst_y * stride) + (dst_x * bpp); |
| 177 | |
| 178 | Epson_wait_idle (); |
| 179 | |
| 180 | /* set up blit registers */ |
| 181 | writeByte(BLT_DST_ADDR0,dstAddr); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 182 | writeByte(BLT_DST_ADDR1,dstAddr>>8); |
| 183 | writeByte(BLT_DST_ADDR2,dstAddr>>16); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 184 | |
| 185 | writeWord(BLT_WIDTH0,(dim_x - 1)); |
| 186 | writeWord(BLT_HEIGHT0,(dim_y - 1)); |
| 187 | writeWord(BLT_FGCOLOR0,color); |
| 188 | |
| 189 | writeByte(BLT_OP,0x0C); /* solid fill */ |
| 190 | writeWord(BLT_MEM_OFF0,stride / 2); |
| 191 | |
| 192 | if (pGD -> gdfIndex == GDF__8BIT_INDEX) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 193 | writeByte(BLT_CTRL1,0x00); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 194 | } |
| 195 | else { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 196 | writeByte(BLT_CTRL1,0x01); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 197 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 198 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 199 | /* Engage the blt engine */ |
| 200 | /* rectangular region for src and dst */ |
| 201 | writeByte(BLT_CTRL0,0x80); |
| 202 | |
| 203 | /* wait untill current blits finished */ |
| 204 | Epson_wait_idle (); |
| 205 | } |
| 206 | |
| 207 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 208 | * video_set_lut -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 209 | *----------------------------------------------------------------------------- |
| 210 | */ |
| 211 | void video_set_lut ( |
| 212 | unsigned int index, /* color number */ |
| 213 | unsigned char r, /* red */ |
| 214 | unsigned char g, /* green */ |
| 215 | unsigned char b /* blue */ |
| 216 | ) |
| 217 | { |
| 218 | writeByte(REG_LUT_ADDR, index ); |
| 219 | writeByte(REG_LUT_DATA, r); |
| 220 | writeByte(REG_LUT_DATA, g); |
| 221 | writeByte(REG_LUT_DATA, b); |
| 222 | } |
| 223 | #ifdef CONFIG_VIDEO_HW_CURSOR |
| 224 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 225 | * video_set_hw_cursor -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 226 | *----------------------------------------------------------------------------- |
| 227 | */ |
| 228 | void video_set_hw_cursor (int x, int y) |
| 229 | { |
| 230 | writeByte (LCD_CURSOR_XL, (x & 0xff)); |
| 231 | writeByte (LCD_CURSOR_XM, (x >> 8)); |
| 232 | writeByte (LCD_CURSOR_YL, (y & 0xff)); |
| 233 | writeByte (LCD_CURSOR_YM, (y >> 8)); |
| 234 | } |
| 235 | |
| 236 | /*----------------------------------------------------------------------------- |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 237 | * video_init_hw_cursor -- |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 238 | *----------------------------------------------------------------------------- |
| 239 | */ |
| 240 | void video_init_hw_cursor (int font_width, int font_height) |
| 241 | { |
| 242 | volatile unsigned char *ptr; |
| 243 | unsigned char pattern; |
| 244 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 245 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 246 | |
| 247 | /* Init cursor content |
| 248 | Cursor size is 64x64 pixels |
| 249 | Start of the cursor memory depends on panel type (dual panel ...) */ |
| 250 | if ((i = readByte (LCD_CURSOR_START)) == 0) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 251 | ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - HWCURSORSIZE); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 252 | } |
| 253 | else { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 254 | ptr = (unsigned char *)(sed13806.frameAdrs + DEFAULT_VIDEO_MEMORY_SIZE - (i * 8192)); |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /* Fill the first line and the first empty line after cursor */ |
| 258 | for (i = 0, pattern = 0; i < 64; i++) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 259 | if (i < font_width) { |
| 260 | /* Invert background */ |
| 261 | pattern |= 0x3; |
| 262 | |
| 263 | } |
| 264 | else { |
| 265 | /* Background */ |
| 266 | pattern |= 0x2; |
| 267 | } |
| 268 | if ((i & 3) == 3) { |
| 269 | *ptr = pattern; |
| 270 | *(ptr + font_height * 16) = 0xaa; |
| 271 | ptr ++; |
| 272 | pattern = 0; |
| 273 | } |
| 274 | pattern <<= 2; |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 275 | } |
| 276 | |
| 277 | /* Duplicate this line */ |
| 278 | for (i = 1; i < font_height; i++) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 279 | memcpy ((void *)ptr, (void *)(ptr - 16), 16); |
| 280 | ptr += 16; |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 281 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 282 | |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 283 | for (; i < 64; i++) { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 284 | memcpy ((void *)(ptr + 16), (void *)ptr, 16); |
| 285 | ptr += 16; |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* Select cursor mode */ |
| 289 | writeByte (LCD_CURSOR_CNTL, 1); |
| 290 | } |
| 291 | #endif |