wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2001 |
| 3 | * ELTEC Elektronik AG |
| 4 | * Frank Gottschling <fgottschling@eltec.de> |
| 5 | * |
| 6 | * Board specific routines for the miniHiPerCam |
| 7 | * |
| 8 | * - initialisation (eeprom) |
| 9 | * - memory controller |
| 10 | * - serial io initialisation |
| 11 | * - ethernet io initialisation |
| 12 | * |
| 13 | * ----------------------------------------------------------------- |
| 14 | * See file CREDITS for list of people who contributed to this |
| 15 | * project. |
| 16 | * |
| 17 | * This program is free software; you can redistribute it and/or |
| 18 | * modify it under the terms of the GNU General Public License as |
| 19 | * published by the Free Software Foundation; either version 2 of |
| 20 | * the License, or (at your option) any later version. |
| 21 | * |
| 22 | * This program is distributed in the hope that it will be useful, |
| 23 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 24 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 25 | * GNU General Public License for more details. |
| 26 | * |
| 27 | * You should have received a copy of the GNU General Public License |
| 28 | * along with this program; if not, write to the Free Software |
| 29 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 30 | * MA 02111-1307 USA |
| 31 | */ |
| 32 | #include <common.h> |
| 33 | #include <linux/ctype.h> |
| 34 | #include <commproc.h> |
| 35 | #include "mpc8xx.h" |
| 36 | #include <video_fb.h> |
| 37 | |
| 38 | /* imports from common/main.c */ |
| 39 | extern char console_buffer[CFG_CBSIZE]; |
| 40 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 41 | extern void eeprom_init (void); |
| 42 | extern int eeprom_read (unsigned dev_addr, unsigned offset, |
| 43 | unsigned char *buffer, unsigned cnt); |
| 44 | extern int eeprom_write (unsigned dev_addr, unsigned offset, |
| 45 | unsigned char *buffer, unsigned cnt); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 46 | |
| 47 | /* globals */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 48 | void *video_hw_init (void); |
| 49 | void video_set_lut (unsigned int index, /* color number */ |
| 50 | unsigned char r, /* red */ |
| 51 | unsigned char g, /* green */ |
| 52 | unsigned char b /* blue */ |
| 53 | ); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 54 | |
| 55 | GraphicDevice gdev; |
| 56 | |
| 57 | /* locals */ |
| 58 | static void video_circle (char *center, int radius, int color, int pitch); |
| 59 | static void video_test_image (void); |
| 60 | static void video_default_lut (unsigned int clut_type); |
| 61 | |
| 62 | /* revision info foer MHPC EEPROM offset 480 */ |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 63 | typedef struct { |
| 64 | char board[12]; /* 000 - Board Revision information */ |
| 65 | char sensor; /* 012 - Sensor Type information */ |
| 66 | char serial[8]; /* 013 - Board serial number */ |
| 67 | char etheraddr[6]; /* 021 - Ethernet node addresse */ |
| 68 | char revision[2]; /* 027 - Revision code */ |
| 69 | char option[3]; /* 029 - resevered for options */ |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 70 | } revinfo; |
| 71 | |
| 72 | /* ------------------------------------------------------------------------- */ |
| 73 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 74 | static const unsigned int sdram_table[] = { |
| 75 | /* read single beat cycle */ |
| 76 | 0xef0efc04, 0x0e2dac04, 0x01ba5c04, 0x1ff5fc00, |
| 77 | 0xfffffc05, 0xeffafc34, 0x0ff0bc34, 0x1ff57c35, |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 78 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 79 | /* read burst cycle */ |
| 80 | 0xef0efc04, 0x0e3dac04, 0x10ff5c04, 0xf0fffc00, |
| 81 | 0xf0fffc00, 0xf1fffc00, 0xfffffc00, 0xfffffc05, |
| 82 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 83 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 84 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 85 | /* write single beat cycle */ |
| 86 | 0xef0efc04, 0x0e29ac00, 0x01b25c04, 0x1ff5fc05, |
| 87 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 88 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 89 | /* write burst cycle */ |
| 90 | 0xef0ef804, 0x0e39a000, 0x10f75000, 0xf0fff440, |
| 91 | 0xf0fffc40, 0xf1fffc04, 0xfffffc05, 0xfffffc04, |
| 92 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
| 93 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 94 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 95 | /* periodic timer expired */ |
| 96 | 0xeffebc84, 0x1ffd7c04, 0xfffffc04, 0xfffffc84, |
| 97 | 0xeffebc04, 0x1ffd7c04, 0xfffffc04, 0xfffffc05, |
| 98 | 0xfffffc04, 0xfffffc04, 0xfffffc04, 0xfffffc04, |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 99 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 100 | /* exception */ |
| 101 | 0xfffffc04, 0xfffffc05, 0xfffffc04, 0xfffffc04 |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | /* ------------------------------------------------------------------------- */ |
| 105 | |
wdenk | c837dcb | 2004-01-20 23:12:12 +0000 | [diff] [blame] | 106 | int board_early_init_f (void) |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 107 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 108 | volatile immap_t *im = (immap_t *) CFG_IMMR; |
| 109 | volatile cpm8xx_t *cp = &(im->im_cpm); |
| 110 | volatile iop8xx_t *ip = (iop8xx_t *) & (im->im_ioport); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 111 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 112 | /* reset the port A s.a. cpm-routines */ |
| 113 | ip->iop_padat = 0x0000; |
| 114 | ip->iop_papar = 0x0000; |
| 115 | ip->iop_padir = 0x0800; |
| 116 | ip->iop_paodr = 0x0000; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 117 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 118 | /* reset the port B for digital and LCD output */ |
| 119 | cp->cp_pbdat = 0x0300; |
| 120 | cp->cp_pbpar = 0x5001; |
| 121 | cp->cp_pbdir = 0x5301; |
| 122 | cp->cp_pbodr = 0x0000; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 123 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 124 | /* reset the port C configured for SMC1 serial port and aqc. control */ |
| 125 | ip->iop_pcdat = 0x0800; |
| 126 | ip->iop_pcpar = 0x0000; |
| 127 | ip->iop_pcdir = 0x0e30; |
| 128 | ip->iop_pcso = 0x0000; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 129 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 130 | /* Config port D for LCD output */ |
| 131 | ip->iop_pdpar = 0x1fff; |
| 132 | ip->iop_pddir = 0x1fff; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 133 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 134 | return (0); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* ------------------------------------------------------------------------- */ |
| 138 | |
| 139 | /* |
| 140 | * Check Board Identity |
| 141 | */ |
| 142 | int checkboard (void) |
| 143 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 144 | puts ("Board: ELTEC miniHiperCam\n"); |
| 145 | return (0); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | /* ------------------------------------------------------------------------- */ |
| 149 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 150 | int misc_init_r (void) |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 151 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 152 | revinfo mhpcRevInfo; |
| 153 | char nid[32]; |
| 154 | char *mhpcSensorTypes[] = { "OMNIVISON OV7610/7620 color", |
| 155 | "OMNIVISON OV7110 b&w", NULL |
| 156 | }; |
| 157 | char hex[23] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, |
| 158 | 0, 0, 0, 0, 10, 11, 12, 13, 14, 15 |
| 159 | }; |
| 160 | int i; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 161 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 162 | /* check revision data */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 163 | eeprom_read (CFG_I2C_EEPROM_ADDR, 480, (uchar *) &mhpcRevInfo, 32); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 164 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 165 | if (strncmp ((char *) &mhpcRevInfo.board[2], "MHPC", 4) != 0) { |
| 166 | printf ("Enter revision number (0-9): %c ", |
| 167 | mhpcRevInfo.revision[0]); |
| 168 | if (0 != readline (NULL)) { |
| 169 | mhpcRevInfo.revision[0] = |
| 170 | (char) toupper (console_buffer[0]); |
| 171 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 172 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 173 | printf ("Enter revision character (A-Z): %c ", |
| 174 | mhpcRevInfo.revision[1]); |
| 175 | if (1 == readline (NULL)) { |
| 176 | mhpcRevInfo.revision[1] = |
| 177 | (char) toupper (console_buffer[0]); |
| 178 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 179 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 180 | printf ("Enter board name (V-XXXX-XXXX): %s ", |
| 181 | (char *) &mhpcRevInfo.board); |
| 182 | if (11 == readline (NULL)) { |
| 183 | for (i = 0; i < 11; i++) { |
| 184 | mhpcRevInfo.board[i] = |
| 185 | (char) toupper (console_buffer[i]); |
| 186 | mhpcRevInfo.board[11] = '\0'; |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | printf ("Supported sensor types:\n"); |
| 191 | i = 0; |
| 192 | do { |
| 193 | printf ("\n \'%d\' : %s\n", i, mhpcSensorTypes[i]); |
| 194 | } while (mhpcSensorTypes[++i] != NULL); |
| 195 | |
| 196 | do { |
| 197 | printf ("\nEnter sensor number (0-255): %d ", |
| 198 | (int) mhpcRevInfo.sensor); |
| 199 | if (0 != readline (NULL)) { |
| 200 | mhpcRevInfo.sensor = |
| 201 | (unsigned char) |
| 202 | simple_strtoul (console_buffer, NULL, |
| 203 | 10); |
| 204 | } |
| 205 | } while (mhpcRevInfo.sensor >= i); |
| 206 | |
| 207 | printf ("Enter serial number: %s ", |
| 208 | (char *) &mhpcRevInfo.serial); |
| 209 | if (6 == readline (NULL)) { |
| 210 | for (i = 0; i < 6; i++) { |
| 211 | mhpcRevInfo.serial[i] = console_buffer[i]; |
| 212 | } |
| 213 | mhpcRevInfo.serial[6] = '\0'; |
| 214 | } |
| 215 | |
| 216 | printf ("Enter ether node ID with leading zero (HEX): %02x%02x%02x%02x%02x%02x ", mhpcRevInfo.etheraddr[0], mhpcRevInfo.etheraddr[1], mhpcRevInfo.etheraddr[2], mhpcRevInfo.etheraddr[3], mhpcRevInfo.etheraddr[4], mhpcRevInfo.etheraddr[5]); |
| 217 | if (12 == readline (NULL)) { |
| 218 | for (i = 0; i < 12; i += 2) { |
| 219 | mhpcRevInfo.etheraddr[i >> 1] = |
| 220 | (char) (16 * |
| 221 | hex[toupper |
| 222 | (console_buffer[i]) - |
| 223 | '0'] + |
| 224 | hex[toupper |
| 225 | (console_buffer[i + 1]) - |
| 226 | '0']); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* setup new revision data */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 231 | eeprom_write (CFG_I2C_EEPROM_ADDR, 480, (uchar *) &mhpcRevInfo, |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 232 | 32); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 233 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 234 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 235 | /* set environment */ |
| 236 | sprintf (nid, "%02x:%02x:%02x:%02x:%02x:%02x", |
| 237 | mhpcRevInfo.etheraddr[0], mhpcRevInfo.etheraddr[1], |
| 238 | mhpcRevInfo.etheraddr[2], mhpcRevInfo.etheraddr[3], |
| 239 | mhpcRevInfo.etheraddr[4], mhpcRevInfo.etheraddr[5]); |
| 240 | setenv ("ethaddr", nid); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 241 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 242 | /* print actual board identification */ |
| 243 | printf ("Ident: %s %s Ser %s Rev %c%c\n", |
| 244 | mhpcRevInfo.board, |
| 245 | (mhpcRevInfo.sensor == 0 ? "color" : "b&w"), |
| 246 | (char *) &mhpcRevInfo.serial, mhpcRevInfo.revision[0], |
| 247 | mhpcRevInfo.revision[1]); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 248 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 249 | return (0); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /* ------------------------------------------------------------------------- */ |
| 253 | |
Becky Bruce | 9973e3c | 2008-06-09 16:03:40 -0500 | [diff] [blame] | 254 | phys_size_t initdram (int board_type) |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 255 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 256 | volatile immap_t *immap = (immap_t *) CFG_IMMR; |
| 257 | volatile memctl8xx_t *memctl = &immap->im_memctl; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 258 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 259 | upmconfig (UPMA, (uint *) sdram_table, |
| 260 | sizeof (sdram_table) / sizeof (uint)); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 261 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 262 | memctl->memc_mamr = CFG_MAMR & (~(MAMR_PTAE)); /* no refresh yet */ |
| 263 | memctl->memc_mbmr = MBMR_GPL_B4DIS; /* should this be mamr? - NTL */ |
| 264 | memctl->memc_mptpr = MPTPR_PTP_DIV64; |
| 265 | memctl->memc_mar = 0x00008800; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 266 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 267 | /* |
| 268 | * Map controller SDRAM bank 0 |
| 269 | */ |
| 270 | memctl->memc_or1 = CFG_OR1_PRELIM; |
| 271 | memctl->memc_br1 = CFG_BR1_PRELIM; |
| 272 | udelay (200); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 273 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 274 | /* |
| 275 | * Map controller SDRAM bank 1 |
| 276 | */ |
| 277 | memctl->memc_or2 = CFG_OR2; |
| 278 | memctl->memc_br2 = CFG_BR2; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 279 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 280 | /* |
| 281 | * Perform SDRAM initializsation sequence |
| 282 | */ |
| 283 | memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */ |
| 284 | udelay (1); |
| 285 | memctl->memc_mcr = 0x80002730; /* SDRAM bank 0 - execute twice */ |
| 286 | udelay (1); |
| 287 | memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */ |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 288 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 289 | udelay (10000); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 290 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 291 | /* leave place for framebuffers */ |
| 292 | return (SDRAM_MAX_SIZE - SDRAM_RES_SIZE); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | /* ------------------------------------------------------------------------- */ |
| 296 | |
| 297 | static void video_circle (char *center, int radius, int color, int pitch) |
| 298 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 299 | int x, y, d, dE, dSE; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 300 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 301 | x = 0; |
| 302 | y = radius; |
| 303 | d = 1 - radius; |
| 304 | dE = 3; |
| 305 | dSE = -2 * radius + 5; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 306 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 307 | *(center + x + y * pitch) = color; |
| 308 | *(center + y + x * pitch) = color; |
| 309 | *(center + y - x * pitch) = color; |
| 310 | *(center + x - y * pitch) = color; |
| 311 | *(center - x - y * pitch) = color; |
| 312 | *(center - y - x * pitch) = color; |
| 313 | *(center - y + x * pitch) = color; |
| 314 | *(center - x + y * pitch) = color; |
| 315 | while (y > x) { |
| 316 | if (d < 0) { |
| 317 | d += dE; |
| 318 | dE += 2; |
| 319 | dSE += 2; |
| 320 | x++; |
| 321 | } else { |
| 322 | d += dSE; |
| 323 | dE += 2; |
| 324 | dSE += 4; |
| 325 | x++; |
| 326 | y--; |
| 327 | } |
| 328 | *(center + x + y * pitch) = color; |
| 329 | *(center + y + x * pitch) = color; |
| 330 | *(center + y - x * pitch) = color; |
| 331 | *(center + x - y * pitch) = color; |
| 332 | *(center - x - y * pitch) = color; |
| 333 | *(center - y - x * pitch) = color; |
| 334 | *(center - y + x * pitch) = color; |
| 335 | *(center - x + y * pitch) = color; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 336 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* ------------------------------------------------------------------------- */ |
| 340 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 341 | static void video_test_image (void) |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 342 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 343 | char *di; |
| 344 | int i, n; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 345 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 346 | /* draw raster */ |
| 347 | for (i = 0; i < LCD_VIDEO_ROWS; i += 32) { |
| 348 | memset ((char *) (LCD_VIDEO_ADDR + i * LCD_VIDEO_COLS), |
| 349 | LCD_VIDEO_FG, LCD_VIDEO_COLS); |
| 350 | for (n = i + 1; n < i + 32; n++) |
| 351 | memset ((char *) (LCD_VIDEO_ADDR + |
| 352 | n * LCD_VIDEO_COLS), LCD_VIDEO_BG, |
| 353 | LCD_VIDEO_COLS); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 354 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 355 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 356 | for (i = 0; i < LCD_VIDEO_COLS; i += 32) { |
| 357 | for (n = 0; n < LCD_VIDEO_ROWS; n++) |
| 358 | *(char *) (LCD_VIDEO_ADDR + n * LCD_VIDEO_COLS + i) = |
| 359 | LCD_VIDEO_FG; |
| 360 | } |
| 361 | |
| 362 | /* draw gray bar */ |
| 363 | di = (char *) (LCD_VIDEO_ADDR + (LCD_VIDEO_COLS - 256) / 64 * 32 + |
| 364 | 97 * LCD_VIDEO_COLS); |
| 365 | for (n = 0; n < 63; n++) { |
| 366 | for (i = 0; i < 256; i++) { |
| 367 | *di++ = (char) i; |
| 368 | *(di + LCD_VIDEO_COLS * 64) = (i & 1) * 255; |
| 369 | } |
| 370 | di += LCD_VIDEO_COLS - 256; |
| 371 | } |
| 372 | |
| 373 | video_circle ((char *) LCD_VIDEO_ADDR + LCD_VIDEO_COLS / 2 + |
| 374 | LCD_VIDEO_ROWS / 2 * LCD_VIDEO_COLS, LCD_VIDEO_ROWS / 2, |
| 375 | LCD_VIDEO_FG, LCD_VIDEO_COLS); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | /* ------------------------------------------------------------------------- */ |
| 379 | |
| 380 | static void video_default_lut (unsigned int clut_type) |
| 381 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 382 | unsigned int i; |
| 383 | unsigned char RGB[] = { |
| 384 | 0x00, 0x00, 0x00, /* black */ |
| 385 | 0x80, 0x80, 0x80, /* gray */ |
| 386 | 0xff, 0x00, 0x00, /* red */ |
| 387 | 0x00, 0xff, 0x00, /* green */ |
| 388 | 0x00, 0x00, 0xff, /* blue */ |
| 389 | 0x00, 0xff, 0xff, /* cyan */ |
| 390 | 0xff, 0x00, 0xff, /* magenta */ |
| 391 | 0xff, 0xff, 0x00, /* yellow */ |
| 392 | 0x80, 0x00, 0x00, /* dark red */ |
| 393 | 0x00, 0x80, 0x00, /* dark green */ |
| 394 | 0x00, 0x00, 0x80, /* dark blue */ |
| 395 | 0x00, 0x80, 0x80, /* dark cyan */ |
| 396 | 0x80, 0x00, 0x80, /* dark magenta */ |
| 397 | 0x80, 0x80, 0x00, /* dark yellow */ |
| 398 | 0xc0, 0xc0, 0xc0, /* light gray */ |
| 399 | 0xff, 0xff, 0xff, /* white */ |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 400 | }; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 401 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 402 | switch (clut_type) { |
| 403 | case 1: |
| 404 | for (i = 0; i < 240; i++) |
| 405 | video_set_lut (i, i, i, i); |
| 406 | for (i = 0; i < 16; i++) |
| 407 | video_set_lut (i + 240, RGB[i * 3], RGB[i * 3 + 1], |
| 408 | RGB[i * 3 + 2]); |
| 409 | break; |
| 410 | default: |
| 411 | for (i = 0; i < 256; i++) |
| 412 | video_set_lut (i, i, i, i); |
| 413 | } |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | /* ------------------------------------------------------------------------- */ |
| 417 | |
| 418 | void *video_hw_init (void) |
| 419 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 420 | unsigned int clut = 0; |
| 421 | unsigned char *penv; |
| 422 | immap_t *immr = (immap_t *) CFG_IMMR; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 423 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 424 | /* enable video only on CLUT value */ |
Wolfgang Denk | 77ddac9 | 2005-10-13 16:45:02 +0200 | [diff] [blame] | 425 | if ((penv = (uchar *)getenv ("clut")) != NULL) |
| 426 | clut = (u_int) simple_strtoul ((char *)penv, NULL, 10); |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 427 | else |
| 428 | return NULL; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 429 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 430 | /* disable graphic before write LCD regs. */ |
| 431 | immr->im_lcd.lcd_lccr = 0x96000866; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 432 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 433 | /* config LCD regs. */ |
| 434 | immr->im_lcd.lcd_lcfaa = LCD_VIDEO_ADDR; |
| 435 | immr->im_lcd.lcd_lchcr = 0x010a0093; |
| 436 | immr->im_lcd.lcd_lcvcr = 0x900f0024; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 437 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 438 | printf ("Video: 640x480 8Bit Index Lut %s\n", |
| 439 | (clut == 1 ? "240/16 (gray/vga)" : "256(gray)")); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 440 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 441 | video_default_lut (clut); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 442 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 443 | /* clear framebuffer */ |
| 444 | memset ((char *) (LCD_VIDEO_ADDR), LCD_VIDEO_BG, |
| 445 | LCD_VIDEO_ROWS * LCD_VIDEO_COLS); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 446 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 447 | /* enable graphic */ |
| 448 | immr->im_lcd.lcd_lccr = 0x96000867; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 449 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 450 | /* fill in Graphic Device */ |
| 451 | gdev.frameAdrs = LCD_VIDEO_ADDR; |
| 452 | gdev.winSizeX = LCD_VIDEO_COLS; |
| 453 | gdev.winSizeY = LCD_VIDEO_ROWS; |
| 454 | gdev.gdfBytesPP = 1; |
| 455 | gdev.gdfIndex = GDF__8BIT_INDEX; |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 456 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 457 | if (clut > 1) |
| 458 | /* return Graphic Device for console */ |
| 459 | return (void *) &gdev; |
| 460 | else |
| 461 | /* just graphic enabled - draw something beautiful */ |
| 462 | video_test_image (); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 463 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 464 | return NULL; /* this disabels cfb - console */ |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | /* ------------------------------------------------------------------------- */ |
| 468 | |
| 469 | void video_set_lut (unsigned int index, |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 470 | unsigned char r, unsigned char g, unsigned char b) |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 471 | { |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 472 | unsigned int lum; |
| 473 | unsigned short *pLut = (unsigned short *) (CFG_IMMR + 0x0e00); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 474 | |
wdenk | bf9e3b3 | 2004-02-12 00:47:09 +0000 | [diff] [blame] | 475 | /* 16 bit lut values, 12 bit used, xxxx BBGG RRii iiii */ |
| 476 | /* y = 0.299*R + 0.587*G + 0.114*B */ |
| 477 | lum = (2990 * r + 5870 * g + 1140 * b) / 10000; |
| 478 | pLut[index] = |
| 479 | ((b & 0xc0) << 4) | ((g & 0xc0) << 2) | (r & 0xc0) | (lum & |
| 480 | 0x3f); |
wdenk | 7d393ae | 2002-10-25 21:08:05 +0000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | /* ------------------------------------------------------------------------- */ |