kup4k.c 11 KB

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