kup4k.c 11 KB

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