mhpc.c 13 KB

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