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