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