kup4k.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446
  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,
  49. 0xEEAEFC04,
  50. 0x11ADFC04,
  51. 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,
  62. 0xEFEABC34,
  63. 0x1FB57C35, /* last */
  64. /*
  65. * Burst Read. (Offset 8 in UPMA RAM)
  66. */
  67. 0x1F07FC04,
  68. 0xEEAEFC04,
  69. 0x10ADFC04,
  70. 0xF0AFFC00,
  71. 0xF0AFFC00,
  72. 0xF1AFFC00,
  73. 0xEFBBBC00,
  74. 0x1FF77C47, /* last */
  75. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  76. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  77. /*
  78. * Single Write. (Offset 18 in UPMA RAM)
  79. */
  80. 0x1F27FC04,
  81. 0xEEAEBC00,
  82. 0x01B93C04,
  83. 0x1FF77C47, /* last */
  84. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  85. /*
  86. * Burst Write. (Offset 20 in UPMA RAM)
  87. */
  88. 0x1F07FC04,
  89. 0xEEAEBC00,
  90. 0x10AD7C00,
  91. 0xF0AFFC00,
  92. 0xF0AFFC00,
  93. 0xE1BBBC04,
  94. 0x1FF77C47, /* last */
  95. _NOT_USED_,
  96. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  97. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  98. /*
  99. * Refresh (Offset 30 in UPMA RAM)
  100. */
  101. 0x1FF5FC84,
  102. 0xFFFFFC04,
  103. 0xFFFFFC04,
  104. 0xFFFFFC04,
  105. 0xFFFFFC84,
  106. 0xFFFFFC07, /* last */
  107. _NOT_USED_, _NOT_USED_,
  108. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  109. /*
  110. * Exception. (Offset 3c in UPMA RAM)
  111. */
  112. 0x7FFFFC07, /* last */
  113. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  114. };
  115. /* ------------------------------------------------------------------------- */
  116. /*
  117. * Check Board Identity:
  118. */
  119. int checkboard (void)
  120. {
  121. printf ("### No HW ID - assuming KUP4K-Color\n");
  122. return (0);
  123. }
  124. /* ------------------------------------------------------------------------- */
  125. long int initdram (int board_type)
  126. {
  127. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  128. volatile memctl8xx_t *memctl = &immap->im_memctl;
  129. long int size_b0 = 0;
  130. long int size_b1 = 0;
  131. long int size_b2 = 0;
  132. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  133. /*
  134. * Preliminary prescaler for refresh (depends on number of
  135. * banks): This value is selected for four cycles every 62.4 us
  136. * with two SDRAM banks or four cycles every 31.2 us with one
  137. * bank. It will be adjusted after memory sizing.
  138. */
  139. memctl->memc_mptpr = CFG_MPTPR;
  140. memctl->memc_mar = 0x00000088;
  141. /*
  142. * Map controller banks 1 and 2 to the SDRAM banks 2 and 3 at
  143. * preliminary addresses - these have to be modified after the
  144. * SDRAM size has been determined.
  145. */
  146. /* memctl->memc_or1 = CFG_OR1_PRELIM; */
  147. /* memctl->memc_br1 = CFG_BR1_PRELIM; */
  148. /* memctl->memc_or2 = CFG_OR2_PRELIM; */
  149. /* memctl->memc_br2 = CFG_BR2_PRELIM; */
  150. memctl->memc_mamr = CFG_MAMR & (~(MAMR_PTAE)); /* no refresh yet */
  151. udelay(200);
  152. /* perform SDRAM initializsation sequence */
  153. memctl->memc_mcr = 0x80002105; /* SDRAM bank 0 */
  154. udelay(1);
  155. memctl->memc_mcr = 0x80002830; /* SDRAM bank 0 - execute twice */
  156. udelay(1);
  157. memctl->memc_mcr = 0x80002106; /* SDRAM bank 0 - RUN MRS Pattern from loc 6 */
  158. udelay(1);
  159. memctl->memc_mcr = 0x80004105; /* SDRAM bank 1 */
  160. udelay(1);
  161. memctl->memc_mcr = 0x80004830; /* SDRAM bank 1 - execute twice */
  162. udelay(1);
  163. memctl->memc_mcr = 0x80004106; /* SDRAM bank 1 - RUN MRS Pattern from loc 6 */
  164. udelay(1);
  165. memctl->memc_mcr = 0x80006105; /* SDRAM bank 2 */
  166. udelay(1);
  167. memctl->memc_mcr = 0x80006830; /* SDRAM bank 2 - execute twice */
  168. udelay(1);
  169. memctl->memc_mcr = 0x80006106; /* SDRAM bank 2 - RUN MRS Pattern from loc 6 */
  170. udelay(1);
  171. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  172. udelay (1000);
  173. size_b0 = 0x00800000;
  174. size_b1 = 0x00800000;
  175. size_b2 = 0x00800000;
  176. memctl->memc_mptpr = CFG_MPTPR;
  177. udelay(1000);
  178. memctl->memc_or1 = 0xFF800A00;
  179. memctl->memc_br1 = 0x00000081;
  180. memctl->memc_or2 = 0xFF000A00;
  181. memctl->memc_br2 = 0x00800081;
  182. memctl->memc_or3 = 0xFE000A00;
  183. memctl->memc_br3 = 0x01000081;
  184. udelay(10000);
  185. return (size_b0 + size_b1 + size_b2);
  186. }
  187. /* ------------------------------------------------------------------------- */
  188. /*
  189. * Check memory range for valid RAM. A simple memory test determines
  190. * the actually available RAM size between addresses `base' and
  191. * `base + maxsize'. Some (not all) hardware errors are detected:
  192. * - short between address lines
  193. * - short between data lines
  194. */
  195. #if 0
  196. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  197. {
  198. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  199. volatile memctl8xx_t *memctl = &immap->im_memctl;
  200. volatile long int *addr;
  201. ulong cnt, val;
  202. ulong save[32]; /* to make test non-destructive */
  203. unsigned char i = 0;
  204. memctl->memc_mamr = mamr_value;
  205. for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
  206. addr = base + cnt; /* pointer arith! */
  207. save[i++] = *addr;
  208. *addr = ~cnt;
  209. }
  210. /* write 0 to base address */
  211. addr = base;
  212. save[i] = *addr;
  213. *addr = 0;
  214. /* check at base address */
  215. if ((val = *addr) != 0) {
  216. *addr = save[i];
  217. return (0);
  218. }
  219. for (cnt = 1; cnt <= maxsize/sizeof(long); cnt <<= 1) {
  220. addr = base + cnt; /* pointer arith! */
  221. val = *addr;
  222. *addr = save[--i];
  223. if (val != (~cnt)) {
  224. return (cnt * sizeof(long));
  225. }
  226. }
  227. return (maxsize);
  228. }
  229. #endif
  230. int misc_init_r (void)
  231. {
  232. DECLARE_GLOBAL_DATA_PTR;
  233. #ifdef CONFIG_STATUS_LED
  234. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  235. #endif
  236. #ifdef CONFIG_KUP4K_LOGO
  237. bd_t *bd = gd->bd;
  238. lcd_logo(bd);
  239. #endif /* CONFIG_KUP4K_LOGO */
  240. #ifdef CONFIG_IDE_LED
  241. /* Configure PA8 as output port */
  242. immap->im_ioport.iop_padir |= 0x80;
  243. immap->im_ioport.iop_paodr |= 0x80;
  244. immap->im_ioport.iop_papar &= ~0x80;
  245. immap->im_ioport.iop_padat |= 0x80; /* turn it off */
  246. #endif
  247. return(0);
  248. }
  249. #ifdef CONFIG_KUP4K_LOGO
  250. void lcd_logo(bd_t *bd){
  251. FB_INFO_S1D13xxx fb_info;
  252. S1D_INDEX s1dReg;
  253. S1D_VALUE s1dValue;
  254. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  255. volatile memctl8xx_t *memctl;
  256. ushort i;
  257. uchar *fb;
  258. int rs, gs, bs;
  259. int r = 8, g = 8, b = 4;
  260. int r1,g1,b1;
  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) || (((S1D_VALUE*)fb_info.RegAddr)[1] != 0x14))
  274. {
  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. {
  281. s1dReg = aS1DRegs[i].Index;
  282. s1dValue = aS1DRegs[i].Value;
  283. /* printf("sid1 Index: %02x Register: %02x Wert: %02x\n",i, aS1DRegs[i].Index, aS1DRegs[i].Value); */
  284. ((S1D_VALUE*)fb_info.RegAddr)[s1dReg/sizeof(S1D_VALUE)] = 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",bd->bi_busfreq);
  309. case 64000000:
  310. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x32;
  311. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x69;
  312. break;
  313. }
  314. ((S1D_VALUE*)fb_info.RegAddr)[0x10] = 0x00;
  315. #else
  316. switch(bd->bi_busfreq){
  317. #if 0
  318. case 24000000:
  319. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x22;
  320. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x34;
  321. break;
  322. case 32000000:
  323. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x32;
  324. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x34;
  325. break;
  326. #endif
  327. case 40000000:
  328. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x32;
  329. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x41;
  330. break;
  331. case 48000000:
  332. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x22;
  333. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x34;
  334. break;
  335. default:
  336. printf("KUP4K S1D1: unknown busfrequency: %ld assuming 64 MHz\n",bd->bi_busfreq);
  337. case 64000000:
  338. ((S1D_VALUE*)fb_info.RegAddr)[0x05] = 0x32;
  339. ((S1D_VALUE*)fb_info.RegAddr)[0x12] = 0x66;
  340. break;
  341. }
  342. #endif
  343. /* create and set colormap */
  344. rs = 256 / (r - 1);
  345. gs = 256 / (g - 1);
  346. bs = 256 / (b - 1);
  347. for(i=0;i<256;i++){
  348. r1=(rs * ((i / (g * b)) % r)) * 255;
  349. g1=(gs * ((i / b) % g)) * 255;
  350. b1=(bs * ((i) % b)) * 255;
  351. /* printf("%d %04x %04x %04x\n",i,r1>>4,g1>>4,b1>>4); */
  352. S1D_WRITE_PALETTE(fb_info.RegAddr,i,(r1>>4),(g1>>4),(b1>>4));
  353. }
  354. /* copy bitmap */
  355. fb = (char *) (fb_info.VmemAddr);
  356. memcpy (fb, (uchar *)CONFIG_KUP4K_LOGO, 320 * 240);
  357. }
  358. #endif /* CONFIG_KUP4K_LOGO */
  359. #ifdef CONFIG_IDE_LED
  360. void ide_led (uchar led, uchar status)
  361. {
  362. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  363. /* We have one led for both pcmcia slots */
  364. if (status) { /* led on */
  365. immap->im_ioport.iop_padat &= ~0x80;
  366. } else {
  367. immap->im_ioport.iop_padat |= 0x80;
  368. }
  369. }
  370. #endif