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