diu.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * Copyright 2010 Freescale Semiconductor, Inc.
  3. * Authors: Timur Tabi <timur@freescale.com>
  4. *
  5. * FSL DIU Framebuffer driver
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the Free
  9. * Software Foundation; either version 2 of the License, or (at your option)
  10. * any later version.
  11. */
  12. #include <common.h>
  13. #include <command.h>
  14. #include <asm/io.h>
  15. #include <stdio_dev.h>
  16. #include <video_fb.h>
  17. #include "../common/ngpixis.h"
  18. #include <fsl_diu_fb.h>
  19. /* The CTL register is called 'csr' in the ngpixis_t structure */
  20. #define PX_CTL_ALTACC 0x80
  21. #define PX_BRDCFG0_ELBC_SPI_MASK 0xc0
  22. #define PX_BRDCFG0_ELBC_SPI_ELBC 0x00
  23. #define PX_BRDCFG0_ELBC_SPI_NULL 0xc0
  24. #define PX_BRDCFG0_ELBC_DIU 0x02
  25. #define PX_BRDCFG1_DVIEN 0x80
  26. #define PX_BRDCFG1_DFPEN 0x40
  27. #define PX_BRDCFG1_BACKLIGHT 0x20
  28. #define PMUXCR_ELBCDIU_MASK 0xc0000000
  29. #define PMUXCR_ELBCDIU_NOR16 0x80000000
  30. #define PMUXCR_ELBCDIU_DIU 0x40000000
  31. /*
  32. * DIU Area Descriptor
  33. *
  34. * Note that we need to byte-swap the value before it's written to the AD
  35. * register. So even though the registers don't look like they're in the same
  36. * bit positions as they are on the MPC8610, the same value is written to the
  37. * AD register on the MPC8610 and on the P1022.
  38. */
  39. #define AD_BYTE_F 0x10000000
  40. #define AD_ALPHA_C_SHIFT 25
  41. #define AD_BLUE_C_SHIFT 23
  42. #define AD_GREEN_C_SHIFT 21
  43. #define AD_RED_C_SHIFT 19
  44. #define AD_PIXEL_S_SHIFT 16
  45. #define AD_COMP_3_SHIFT 12
  46. #define AD_COMP_2_SHIFT 8
  47. #define AD_COMP_1_SHIFT 4
  48. #define AD_COMP_0_SHIFT 0
  49. /*
  50. * Variables used by the DIU/LBC switching code. It's safe to makes these
  51. * global, because the DIU requires DDR, so we'll only run this code after
  52. * relocation.
  53. */
  54. static u8 px_brdcfg0;
  55. static u32 pmuxcr;
  56. static void *lbc_lcs0_ba;
  57. static void *lbc_lcs1_ba;
  58. void diu_set_pixel_clock(unsigned int pixclock)
  59. {
  60. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  61. unsigned long speed_ccb, temp;
  62. u32 pixval;
  63. speed_ccb = get_bus_freq(0);
  64. temp = 1000000000 / pixclock;
  65. temp *= 1000;
  66. pixval = speed_ccb / temp;
  67. debug("DIU pixval = %lu\n", pixval);
  68. /* Modify PXCLK in GUTS CLKDVDR */
  69. temp = in_be32(&gur->clkdvdr) & 0x2000FFFF;
  70. out_be32(&gur->clkdvdr, temp); /* turn off clock */
  71. out_be32(&gur->clkdvdr, temp | 0x80000000 | ((pixval & 0x1F) << 16));
  72. }
  73. int platform_diu_init(unsigned int *xres, unsigned int *yres)
  74. {
  75. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  76. char *monitor_port;
  77. u32 pixel_format;
  78. u8 temp;
  79. /* Save the LBC LCS0 and LCS1 addresses for the DIU mux functions */
  80. lbc_lcs0_ba = (void *)(get_lbc_br(0) & get_lbc_or(0) & 0xFFFF8000);
  81. lbc_lcs1_ba = (void *)(get_lbc_br(1) & get_lbc_or(1) & 0xFFFF8000);
  82. pixel_format = cpu_to_le32(AD_BYTE_F | (3 << AD_ALPHA_C_SHIFT) |
  83. (0 << AD_BLUE_C_SHIFT) | (1 << AD_GREEN_C_SHIFT) |
  84. (2 << AD_RED_C_SHIFT) | (8 << AD_COMP_3_SHIFT) |
  85. (8 << AD_COMP_2_SHIFT) | (8 << AD_COMP_1_SHIFT) |
  86. (8 << AD_COMP_0_SHIFT) | (3 << AD_PIXEL_S_SHIFT));
  87. temp = in_8(&pixis->brdcfg1);
  88. monitor_port = getenv("monitor");
  89. if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */
  90. *xres = 1024;
  91. *yres = 768;
  92. /* Enable the DFP port, disable the DVI and the backlight */
  93. temp &= ~(PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT);
  94. temp |= PX_BRDCFG1_DFPEN;
  95. } else { /* DVI */
  96. *xres = 1280;
  97. *yres = 1024;
  98. /* Enable the DVI port, disable the DFP and the backlight */
  99. temp &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
  100. temp |= PX_BRDCFG1_DVIEN;
  101. }
  102. out_8(&pixis->brdcfg1, temp);
  103. /*
  104. * Enable PIXIS indirect access mode. This is a hack that allows us to
  105. * access PIXIS registers even when the LBC pins have been muxed to the
  106. * DIU.
  107. */
  108. setbits_8(&pixis->csr, PX_CTL_ALTACC);
  109. /*
  110. * Route the LAD pins to the DIU. This will disable access to the eLBC,
  111. * which means we won't be able to read/write any NOR flash addresses!
  112. */
  113. out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
  114. px_brdcfg0 = in_8(lbc_lcs1_ba);
  115. out_8(lbc_lcs1_ba, px_brdcfg0 | PX_BRDCFG0_ELBC_DIU);
  116. /* Set PMUXCR to switch the muxed pins from the LBC to the DIU */
  117. clrsetbits_be32(&gur->pmuxcr, PMUXCR_ELBCDIU_MASK, PMUXCR_ELBCDIU_DIU);
  118. pmuxcr = in_be32(&gur->pmuxcr);
  119. return fsl_diu_init(*xres, pixel_format, 0);
  120. }
  121. #ifdef CONFIG_CFI_FLASH_USE_WEAK_ACCESSORS
  122. /*
  123. * set_mux_to_lbc - disable the DIU so that we can read/write to elbc
  124. *
  125. * On the Freescale P1022, the DIU video signal and the LBC address/data lines
  126. * share the same pins, which means that when the DIU is active (e.g. the
  127. * console is on the DVI display), NOR flash cannot be accessed. So we use the
  128. * weak accessor feature of the CFI flash code to temporarily switch the pin
  129. * mux from DIU to LBC whenever we want to read or write flash. This has a
  130. * significant performance penalty, but it's the only way to make it work.
  131. *
  132. * There are two muxes: one on the chip, and one on the board. The chip mux
  133. * controls whether the pins are used for the DIU or the LBC, and it is
  134. * set via PMUXCR. The board mux controls whether those signals go to
  135. * the video connector or the NOR flash chips, and it is set via the ngPIXIS.
  136. */
  137. static int set_mux_to_lbc(void)
  138. {
  139. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  140. /* Switch the muxes only if they're currently set to DIU mode */
  141. if ((in_be32(&gur->pmuxcr) & PMUXCR_ELBCDIU_MASK) !=
  142. PMUXCR_ELBCDIU_NOR16) {
  143. /*
  144. * In DIU mode, the PIXIS can only be accessed indirectly
  145. * since we can't read/write the LBC directly.
  146. */
  147. /* Set the board mux to LBC. This will disable the display. */
  148. out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
  149. px_brdcfg0 = in_8(lbc_lcs1_ba);
  150. out_8(lbc_lcs1_ba, (px_brdcfg0 & ~(PX_BRDCFG0_ELBC_SPI_MASK
  151. | PX_BRDCFG0_ELBC_DIU)) | PX_BRDCFG0_ELBC_SPI_ELBC);
  152. /* Disable indirect PIXIS mode */
  153. out_8(lbc_lcs0_ba, offsetof(ngpixis_t, csr));
  154. clrbits_8(lbc_lcs1_ba, PX_CTL_ALTACC);
  155. /* Set the chip mux to LBC mode, so that writes go to flash. */
  156. out_be32(&gur->pmuxcr, (pmuxcr & ~PMUXCR_ELBCDIU_MASK) |
  157. PMUXCR_ELBCDIU_NOR16);
  158. in_be32(&gur->pmuxcr);
  159. return 1;
  160. }
  161. return 0;
  162. }
  163. /*
  164. * set_mux_to_diu - re-enable the DIU muxing
  165. *
  166. * This function restores the chip and board muxing to point to the DIU.
  167. */
  168. static void set_mux_to_diu(void)
  169. {
  170. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  171. /* Enable indirect PIXIS mode */
  172. setbits_8(&pixis->csr, PX_CTL_ALTACC);
  173. /* Set the board mux to DIU. This will enable the display. */
  174. out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
  175. out_8(lbc_lcs1_ba, px_brdcfg0);
  176. in_8(lbc_lcs1_ba);
  177. /* Set the chip mux to DIU mode. */
  178. out_be32(&gur->pmuxcr, pmuxcr);
  179. in_be32(&gur->pmuxcr);
  180. }
  181. void flash_write8(u8 value, void *addr)
  182. {
  183. int sw = set_mux_to_lbc();
  184. __raw_writeb(value, addr);
  185. if (sw) {
  186. /*
  187. * To ensure the post-write is completed to eLBC, software must
  188. * perform a dummy read from one valid address from eLBC space
  189. * before changing the eLBC_DIU from NOR mode to DIU mode.
  190. * set_mux_to_diu() includes a sync that will ensure the
  191. * __raw_readb() completes before it switches the mux.
  192. */
  193. __raw_readb(addr);
  194. set_mux_to_diu();
  195. }
  196. }
  197. void flash_write16(u16 value, void *addr)
  198. {
  199. int sw = set_mux_to_lbc();
  200. __raw_writew(value, addr);
  201. if (sw) {
  202. /*
  203. * To ensure the post-write is completed to eLBC, software must
  204. * perform a dummy read from one valid address from eLBC space
  205. * before changing the eLBC_DIU from NOR mode to DIU mode.
  206. * set_mux_to_diu() includes a sync that will ensure the
  207. * __raw_readb() completes before it switches the mux.
  208. */
  209. __raw_readb(addr);
  210. set_mux_to_diu();
  211. }
  212. }
  213. void flash_write32(u32 value, void *addr)
  214. {
  215. int sw = set_mux_to_lbc();
  216. __raw_writel(value, addr);
  217. if (sw) {
  218. /*
  219. * To ensure the post-write is completed to eLBC, software must
  220. * perform a dummy read from one valid address from eLBC space
  221. * before changing the eLBC_DIU from NOR mode to DIU mode.
  222. * set_mux_to_diu() includes a sync that will ensure the
  223. * __raw_readb() completes before it switches the mux.
  224. */
  225. __raw_readb(addr);
  226. set_mux_to_diu();
  227. }
  228. }
  229. void flash_write64(u64 value, void *addr)
  230. {
  231. int sw = set_mux_to_lbc();
  232. uint32_t *p = addr;
  233. /*
  234. * There is no __raw_writeq(), so do the write manually. We don't trust
  235. * the compiler, so we use inline assembly.
  236. */
  237. __asm__ __volatile__(
  238. "stw%U0%X0 %2,%0;\n"
  239. "stw%U1%X1 %3,%1;\n"
  240. : "=m" (*p), "=m" (*(p + 1))
  241. : "r" ((uint32_t) (value >> 32)), "r" ((uint32_t) (value)));
  242. if (sw) {
  243. /*
  244. * To ensure the post-write is completed to eLBC, software must
  245. * perform a dummy read from one valid address from eLBC space
  246. * before changing the eLBC_DIU from NOR mode to DIU mode. We
  247. * read addr+4 because we just wrote to addr+4, so that's how we
  248. * maintain execution order. set_mux_to_diu() includes a sync
  249. * that will ensure the __raw_readb() completes before it
  250. * switches the mux.
  251. */
  252. __raw_readb(addr + 4);
  253. set_mux_to_diu();
  254. }
  255. }
  256. u8 flash_read8(void *addr)
  257. {
  258. u8 ret;
  259. int sw = set_mux_to_lbc();
  260. ret = __raw_readb(addr);
  261. if (sw)
  262. set_mux_to_diu();
  263. return ret;
  264. }
  265. u16 flash_read16(void *addr)
  266. {
  267. u16 ret;
  268. int sw = set_mux_to_lbc();
  269. ret = __raw_readw(addr);
  270. if (sw)
  271. set_mux_to_diu();
  272. return ret;
  273. }
  274. u32 flash_read32(void *addr)
  275. {
  276. u32 ret;
  277. int sw = set_mux_to_lbc();
  278. ret = __raw_readl(addr);
  279. if (sw)
  280. set_mux_to_diu();
  281. return ret;
  282. }
  283. u64 flash_read64(void *addr)
  284. {
  285. u64 ret;
  286. int sw = set_mux_to_lbc();
  287. /* There is no __raw_readq(), so do the read manually */
  288. ret = *(volatile u64 *)addr;
  289. if (sw)
  290. set_mux_to_diu();
  291. return ret;
  292. }
  293. #endif