kup4k.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. * Klaus Heydeck, Kieback & Peter GmbH & Co KG, heydeck@kieback-peter.de
  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. #include <common.h>
  25. #include <mpc8xx.h>
  26. #include "../common/kup.h"
  27. #ifdef CONFIG_KUP4K_LOGO
  28. #include "s1d13706.h"
  29. #endif
  30. #undef DEBUG
  31. #ifdef DEBUG
  32. # define debugk(fmt,args...) printf(fmt ,##args)
  33. #else
  34. # define debugk(fmt,args...)
  35. #endif
  36. typedef struct {
  37. volatile unsigned char *VmemAddr;
  38. volatile unsigned char *RegAddr;
  39. } FB_INFO_S1D13xxx;
  40. /* ------------------------------------------------------------------------- */
  41. #if 0
  42. static long int dram_size (long int, long int *, long int);
  43. #endif
  44. #ifdef CONFIG_KUP4K_LOGO
  45. void lcd_logo(bd_t *bd);
  46. #endif
  47. /* ------------------------------------------------------------------------- */
  48. #define _NOT_USED_ 0xFFFFFFFF
  49. const uint sdram_table[] = {
  50. /*
  51. * Single Read. (Offset 0 in UPMA RAM)
  52. */
  53. 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
  54. 0x1FF77C47, /* last */
  55. /*
  56. * SDRAM Initialization (offset 5 in UPMA RAM)
  57. *
  58. * This is no UPM entry point. The following definition uses
  59. * the remaining space to establish an initialization
  60. * sequence, which is executed by a RUN command.
  61. *
  62. */
  63. 0x1FF77C35, 0xEFEABC34, 0x1FB57C35, /* last */
  64. /*
  65. * Burst Read. (Offset 8 in UPMA RAM)
  66. */
  67. 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
  68. 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
  69. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  70. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  71. /*
  72. * Single Write. (Offset 18 in UPMA RAM)
  73. */
  74. 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
  75. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  76. /*
  77. * Burst Write. (Offset 20 in UPMA RAM)
  78. */
  79. 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
  80. 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
  81. _NOT_USED_,
  82. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  83. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  84. /*
  85. * Refresh (Offset 30 in UPMA RAM)
  86. */
  87. 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  88. 0xFFFFFC84, 0xFFFFFC07, /* last */
  89. _NOT_USED_, _NOT_USED_,
  90. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  91. /*
  92. * Exception. (Offset 3c in UPMA RAM)
  93. */
  94. 0x7FFFFC07, /* last */
  95. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  96. };
  97. /* ------------------------------------------------------------------------- */
  98. /*
  99. * Check Board Identity:
  100. */
  101. int checkboard (void)
  102. {
  103. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  104. uchar *latch,rev,mod;
  105. /*
  106. * Init ChipSelect #4 (CAN + HW-Latch)
  107. */
  108. immap->im_memctl.memc_or4 = 0xFFFF8926;
  109. immap->im_memctl.memc_br4 = 0x90000401;
  110. __asm__ ("eieio");
  111. latch=(uchar *)0x90000200;
  112. rev = (*latch & 0xF8) >> 3;
  113. mod=(*latch & 0x03);
  114. printf ("Board: KUP4K Rev %d.%d\n",rev,mod);
  115. return (0);
  116. }
  117. /* ------------------------------------------------------------------------- */
  118. long int initdram (int board_type)
  119. {
  120. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  121. volatile memctl8xx_t *memctl = &immap->im_memctl;
  122. long int size_b0 = 0;
  123. long int size_b1 = 0;
  124. long int size_b2 = 0;
  125. upmconfig (UPMA, (uint *) sdram_table,
  126. sizeof (sdram_table) / sizeof (uint));
  127. /*
  128. * Preliminary prescaler for refresh (depends on number of
  129. * banks): This value is selected for four cycles every 62.4 us
  130. * with two SDRAM banks or four cycles every 31.2 us with one
  131. * bank. It will be adjusted after memory sizing.
  132. */
  133. memctl->memc_mptpr = CFG_MPTPR;
  134. memctl->memc_mar = 0x00000088;
  135. /*
  136. * Map controller banks 1 and 2 to the SDRAM banks 2 and 3 at
  137. * preliminary addresses - these have to be modified after the
  138. * SDRAM size has been determined.
  139. */
  140. /* memctl->memc_or1 = CFG_OR1_PRELIM; */
  141. /* memctl->memc_br1 = CFG_BR1_PRELIM; */
  142. /* memctl->memc_or2 = CFG_OR2_PRELIM; */
  143. /* memctl->memc_br2 = CFG_BR2_PRELIM; */
  144. memctl->memc_mamr = CFG_MAMR & (~(MAMR_PTAE)); /* no refresh yet */
  145. udelay (200);
  146. /* perform SDRAM initializsation sequence */
  147. memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
  148. udelay (1);
  149. memctl->memc_mcr = 0x80002830; /* SDRAM bank 0 - execute twice */
  150. udelay (1);
  151. memctl->memc_mcr = 0x80002106; /* SDRAM bank 0 - RUN MRS Pattern from loc 6 */
  152. udelay (1);
  153. memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
  154. udelay (1);
  155. memctl->memc_mcr = 0x80004830; /* SDRAM bank 1 - execute twice */
  156. udelay (1);
  157. memctl->memc_mcr = 0x80004106; /* SDRAM bank 1 - RUN MRS Pattern from loc 6 */
  158. udelay (1);
  159. memctl->memc_mcr = 0x80006105; /* SDRAM bank 2 */
  160. udelay (1);
  161. memctl->memc_mcr = 0x80006830; /* SDRAM bank 2 - execute twice */
  162. udelay (1);
  163. memctl->memc_mcr = 0x80006106; /* SDRAM bank 2 - RUN MRS Pattern from loc 6 */
  164. udelay (1);
  165. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  166. udelay (1000);
  167. #if 0 /* 3 x 8MB */
  168. size_b0 = 0x00800000;
  169. size_b1 = 0x00800000;
  170. size_b2 = 0x00800000;
  171. memctl->memc_mptpr = CFG_MPTPR;
  172. udelay (1000);
  173. memctl->memc_or1 = 0xFF800A00;
  174. memctl->memc_br1 = 0x00000081;
  175. memctl->memc_or2 = 0xFF000A00;
  176. memctl->memc_br2 = 0x00800081;
  177. memctl->memc_or3 = 0xFE000A00;
  178. memctl->memc_br3 = 0x01000081;
  179. #else /* 3 x 16 MB */
  180. size_b0 = 0x01000000;
  181. size_b1 = 0x01000000;
  182. size_b2 = 0x01000000;
  183. memctl->memc_mptpr = CFG_MPTPR;
  184. udelay (1000);
  185. memctl->memc_or1 = 0xFF000A00;
  186. memctl->memc_br1 = 0x00000081;
  187. memctl->memc_or2 = 0xFE000A00;
  188. memctl->memc_br2 = 0x01000081;
  189. memctl->memc_or3 = 0xFC000A00;
  190. memctl->memc_br3 = 0x02000081;
  191. #endif
  192. udelay (10000);
  193. return (size_b0 + size_b1 + size_b2);
  194. }
  195. /* ------------------------------------------------------------------------- */
  196. /*
  197. * Check memory range for valid RAM. A simple memory test determines
  198. * the actually available RAM size between addresses `base' and
  199. * `base + maxsize'. Some (not all) hardware errors are detected:
  200. * - short between address lines
  201. * - short between data lines
  202. */
  203. #if 0
  204. static long int dram_size (long int mamr_value, long int *base,
  205. long int maxsize)
  206. {
  207. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  208. volatile memctl8xx_t *memctl = &immap->im_memctl;
  209. volatile long int *addr;
  210. ulong cnt, val;
  211. ulong save[32]; /* to make test non-destructive */
  212. unsigned char i = 0;
  213. memctl->memc_mamr = mamr_value;
  214. for (cnt = maxsize / sizeof (long); cnt > 0; cnt >>= 1) {
  215. addr = base + cnt; /* pointer arith! */
  216. save[i++] = *addr;
  217. *addr = ~cnt;
  218. }
  219. /* write 0 to base address */
  220. addr = base;
  221. save[i] = *addr;
  222. *addr = 0;
  223. /* check at base address */
  224. if ((val = *addr) != 0) {
  225. *addr = save[i];
  226. return (0);
  227. }
  228. for (cnt = 1; cnt <= maxsize / sizeof (long); cnt <<= 1) {
  229. addr = base + cnt; /* pointer arith! */
  230. val = *addr;
  231. *addr = save[--i];
  232. if (val != (~cnt)) {
  233. return (cnt * sizeof (long));
  234. }
  235. }
  236. return (maxsize);
  237. }
  238. #endif
  239. int misc_init_r (void)
  240. {
  241. DECLARE_GLOBAL_DATA_PTR;
  242. #ifdef CONFIG_STATUS_LED
  243. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  244. #endif
  245. #ifdef CONFIG_KUP4K_LOGO
  246. bd_t *bd = gd->bd;
  247. lcd_logo (bd);
  248. #endif /* CONFIG_KUP4K_LOGO */
  249. #ifdef CONFIG_IDE_LED
  250. /* Configure PA8 as output port */
  251. immap->im_ioport.iop_padir |= 0x80;
  252. immap->im_ioport.iop_paodr |= 0x80;
  253. immap->im_ioport.iop_papar &= ~0x80;
  254. immap->im_ioport.iop_padat |= 0x80; /* turn it off */
  255. #endif
  256. setenv("hw","4k");
  257. poweron_key();
  258. return (0);
  259. }
  260. #ifdef CONFIG_KUP4K_LOGO
  261. void lcd_logo (bd_t * bd)
  262. {
  263. FB_INFO_S1D13xxx fb_info;
  264. S1D_INDEX s1dReg;
  265. S1D_VALUE s1dValue;
  266. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  267. volatile memctl8xx_t *memctl;
  268. ushort i;
  269. uchar *fb;
  270. int rs, gs, bs;
  271. int r = 8, g = 8, b = 4;
  272. int r1, g1, b1;
  273. int n;
  274. uchar tmp[64]; /* long enough for environment variables */
  275. int tft = 0;
  276. immr->im_cpm.cp_pbpar &= ~(PB_LCD_PWM);
  277. immr->im_cpm.cp_pbodr &= ~(PB_LCD_PWM);
  278. immr->im_cpm.cp_pbdat &= ~(PB_LCD_PWM); /* set to 0 = enabled */
  279. immr->im_cpm.cp_pbdir |= (PB_LCD_PWM);
  280. /*----------------------------------------------------------------------------- */
  281. /* Initialize the chip and the frame buffer driver. */
  282. /*----------------------------------------------------------------------------- */
  283. memctl = &immr->im_memctl;
  284. /*
  285. * Init ChipSelect #5 (S1D13768)
  286. */
  287. memctl->memc_or5 = 0xFFC007F0; /* 4 MB 17 WS or externel TA */
  288. memctl->memc_br5 = 0x80080801; /* Start at 0x80080000 */
  289. __asm__ ("eieio");
  290. fb_info.VmemAddr = (unsigned char *) (S1D_PHYSICAL_VMEM_ADDR);
  291. fb_info.RegAddr = (unsigned char *) (S1D_PHYSICAL_REG_ADDR);
  292. if ((((S1D_VALUE *) fb_info.RegAddr)[0] != 0x28)
  293. || (((S1D_VALUE *) fb_info.RegAddr)[1] != 0x14)) {
  294. printf ("Warning:LCD Controller S1D13706 not found\n");
  295. setenv ("lcd", "none");
  296. return;
  297. }
  298. for (i = 0; i < sizeof(aS1DRegs_prelimn) / sizeof(aS1DRegs_prelimn[0]); i++) {
  299. s1dReg = aS1DRegs_prelimn[i].Index;
  300. s1dValue = aS1DRegs_prelimn[i].Value;
  301. debugk ("s13768 reg: %02x value: %02x\n",
  302. aS1DRegs_prelimn[i].Index, aS1DRegs_prelimn[i].Value);
  303. ((S1D_VALUE *) fb_info.RegAddr)[s1dReg / sizeof (S1D_VALUE)] =
  304. s1dValue;
  305. }
  306. n = getenv_r ("lcd", tmp, sizeof (tmp));
  307. if (n > 0) {
  308. if (!strcmp ("tft", tmp))
  309. tft = 1;
  310. else
  311. tft = 0;
  312. }
  313. #if 0
  314. if (((S1D_VALUE *) fb_info.RegAddr)[0xAC] & 0x04)
  315. tft = 0;
  316. else
  317. tft = 1;
  318. #endif
  319. debugk ("Port=0x%02x -> TFT=%d\n", tft,
  320. ((S1D_VALUE *) fb_info.RegAddr)[0xAC]);
  321. /* init controller */
  322. if (!tft) {
  323. for (i = 0; i < sizeof(aS1DRegs_stn) / sizeof(aS1DRegs_stn[0]); i++) {
  324. s1dReg = aS1DRegs_stn[i].Index;
  325. s1dValue = aS1DRegs_stn[i].Value;
  326. debugk ("s13768 reg: %02x value: %02x\n",
  327. aS1DRegs_stn[i].Index,
  328. aS1DRegs_stn[i].Value);
  329. ((S1D_VALUE *) fb_info.RegAddr)[s1dReg / sizeof(S1D_VALUE)] =
  330. s1dValue;
  331. }
  332. n = getenv_r ("contrast", tmp, sizeof (tmp));
  333. ((S1D_VALUE *) fb_info.RegAddr)[0xB3] =
  334. (n > 0) ? (uchar) simple_strtoul (tmp, NULL, 10) * 255 / 100 : 0xA0;
  335. switch (bd->bi_busfreq) {
  336. case 40000000:
  337. ((S1D_VALUE *) fb_info.RegAddr)[0x05] = 0x32;
  338. ((S1D_VALUE *) fb_info.RegAddr)[0x12] = 0x41;
  339. break;
  340. case 48000000:
  341. ((S1D_VALUE *) fb_info.RegAddr)[0x05] = 0x22;
  342. ((S1D_VALUE *) fb_info.RegAddr)[0x12] = 0x34;
  343. break;
  344. default:
  345. printf ("KUP4K S1D1: unknown busfrequency: %ld assuming 64 MHz\n", bd->bi_busfreq);
  346. case 64000000:
  347. ((S1D_VALUE *) fb_info.RegAddr)[0x05] = 0x32;
  348. ((S1D_VALUE *) fb_info.RegAddr)[0x12] = 0x66;
  349. break;
  350. }
  351. /* setenv("lcd","stn"); */
  352. } else {
  353. for (i = 0; i < sizeof(aS1DRegs_tft) / sizeof(aS1DRegs_tft[0]); i++) {
  354. s1dReg = aS1DRegs_tft[i].Index;
  355. s1dValue = aS1DRegs_tft[i].Value;
  356. debugk ("s13768 reg: %02x value: %02x\n",
  357. aS1DRegs_tft[i].Index,
  358. aS1DRegs_tft[i].Value);
  359. ((S1D_VALUE *) fb_info.RegAddr)[s1dReg / sizeof (S1D_VALUE)] =
  360. s1dValue;
  361. }
  362. switch (bd->bi_busfreq) {
  363. default:
  364. printf ("KUP4K S1D1: unknown busfrequency: %ld assuming 64 MHz\n", bd->bi_busfreq);
  365. case 40000000:
  366. ((S1D_VALUE *) fb_info.RegAddr)[0x05] = 0x42;
  367. ((S1D_VALUE *) fb_info.RegAddr)[0x12] = 0x30;
  368. break;
  369. }
  370. /* setenv("lcd","tft"); */
  371. }
  372. /* create and set colormap */
  373. rs = 256 / (r - 1);
  374. gs = 256 / (g - 1);
  375. bs = 256 / (b - 1);
  376. for (i = 0; i < 256; i++) {
  377. r1 = (rs * ((i / (g * b)) % r)) * 255;
  378. g1 = (gs * ((i / b) % g)) * 255;
  379. b1 = (bs * ((i) % b)) * 255;
  380. debugk ("%d %04x %04x %04x\n", i, r1 >> 4, g1 >> 4, b1 >> 4);
  381. S1D_WRITE_PALETTE (fb_info.RegAddr, i, (r1 >> 4), (g1 >> 4),
  382. (b1 >> 4));
  383. }
  384. /* copy bitmap */
  385. fb = (char *) (fb_info.VmemAddr);
  386. memcpy (fb, (uchar *) CONFIG_KUP4K_LOGO, 320 * 240);
  387. }
  388. #endif /* CONFIG_KUP4K_LOGO */