diu.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  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. /*
  31. * DIU Area Descriptor
  32. *
  33. * Note that we need to byte-swap the value before it's written to the AD
  34. * register. So even though the registers don't look like they're in the same
  35. * bit positions as they are on the MPC8610, the same value is written to the
  36. * AD register on the MPC8610 and on the P1022.
  37. */
  38. #define AD_BYTE_F 0x10000000
  39. #define AD_ALPHA_C_SHIFT 25
  40. #define AD_BLUE_C_SHIFT 23
  41. #define AD_GREEN_C_SHIFT 21
  42. #define AD_RED_C_SHIFT 19
  43. #define AD_PIXEL_S_SHIFT 16
  44. #define AD_COMP_3_SHIFT 12
  45. #define AD_COMP_2_SHIFT 8
  46. #define AD_COMP_1_SHIFT 4
  47. #define AD_COMP_0_SHIFT 0
  48. /*
  49. * Variables used by the DIU/LBC switching code. It's safe to makes these
  50. * global, because the DIU requires DDR, so we'll only run this code after
  51. * relocation.
  52. */
  53. static u8 px_brdcfg0;
  54. static u32 pmuxcr;
  55. static void *lbc_lcs0_ba;
  56. static void *lbc_lcs1_ba;
  57. void diu_set_pixel_clock(unsigned int pixclock)
  58. {
  59. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  60. unsigned long speed_ccb, temp;
  61. u32 pixval;
  62. speed_ccb = get_bus_freq(0);
  63. temp = 1000000000 / pixclock;
  64. temp *= 1000;
  65. pixval = speed_ccb / temp;
  66. debug("DIU pixval = %lu\n", pixval);
  67. /* Modify PXCLK in GUTS CLKDVDR */
  68. temp = in_be32(&gur->clkdvdr) & 0x2000FFFF;
  69. out_be32(&gur->clkdvdr, temp); /* turn off clock */
  70. out_be32(&gur->clkdvdr, temp | 0x80000000 | ((pixval & 0x1F) << 16));
  71. }
  72. int platform_diu_init(unsigned int *xres, unsigned int *yres)
  73. {
  74. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  75. char *monitor_port;
  76. u32 pixel_format;
  77. u8 temp;
  78. /* Save the LBC LCS0 and LCS1 addresses for the DIU mux functions */
  79. lbc_lcs0_ba = (void *)(get_lbc_br(0) & get_lbc_or(0) & 0xFFFF8000);
  80. lbc_lcs1_ba = (void *)(get_lbc_br(1) & get_lbc_or(1) & 0xFFFF8000);
  81. pixel_format = cpu_to_le32(AD_BYTE_F | (3 << AD_ALPHA_C_SHIFT) |
  82. (0 << AD_BLUE_C_SHIFT) | (1 << AD_GREEN_C_SHIFT) |
  83. (2 << AD_RED_C_SHIFT) | (8 << AD_COMP_3_SHIFT) |
  84. (8 << AD_COMP_2_SHIFT) | (8 << AD_COMP_1_SHIFT) |
  85. (8 << AD_COMP_0_SHIFT) | (3 << AD_PIXEL_S_SHIFT));
  86. temp = in_8(&pixis->brdcfg1);
  87. monitor_port = getenv("monitor");
  88. if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */
  89. *xres = 1024;
  90. *yres = 768;
  91. /* Enable the DFP port, disable the DVI and the backlight */
  92. temp &= ~(PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT);
  93. temp |= PX_BRDCFG1_DFPEN;
  94. } else { /* DVI */
  95. *xres = 1280;
  96. *yres = 1024;
  97. /* Enable the DVI port, disable the DFP and the backlight */
  98. temp &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
  99. temp |= PX_BRDCFG1_DVIEN;
  100. }
  101. out_8(&pixis->brdcfg1, temp);
  102. /*
  103. * Enable PIXIS indirect access mode. This is a hack that allows us to
  104. * access PIXIS registers even when the LBC pins have been muxed to the
  105. * DIU.
  106. */
  107. setbits_8(&pixis->csr, PX_CTL_ALTACC);
  108. /*
  109. * Route the LAD pins to the DIU. This will disable access to the eLBC,
  110. * which means we won't be able to read/write any NOR flash addresses!
  111. */
  112. out_8(lbc_lcs0_ba, offsetof(ngpixis_t, brdcfg0));
  113. px_brdcfg0 = in_8(lbc_lcs1_ba);
  114. out_8(lbc_lcs1_ba, px_brdcfg0 | PX_BRDCFG0_ELBC_DIU);
  115. /* Setting PMUXCR to switch to DVI from ELBC */
  116. clrsetbits_be32(&gur->pmuxcr,
  117. PMUXCR_ELBCDIU_MASK, PMUXCR_ELBCDIU_NOR16);
  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. set_mux_to_diu();
  187. }
  188. void flash_write16(u16 value, void *addr)
  189. {
  190. int sw = set_mux_to_lbc();
  191. __raw_writew(value, addr);
  192. if (sw)
  193. set_mux_to_diu();
  194. }
  195. void flash_write32(u32 value, void *addr)
  196. {
  197. int sw = set_mux_to_lbc();
  198. __raw_writel(value, addr);
  199. if (sw)
  200. set_mux_to_diu();
  201. }
  202. void flash_write64(u64 value, void *addr)
  203. {
  204. int sw = set_mux_to_lbc();
  205. /* There is no __raw_writeq(), so do the write manually */
  206. *(volatile u64 *)addr = value;
  207. if (sw)
  208. set_mux_to_diu();
  209. }
  210. u8 flash_read8(void *addr)
  211. {
  212. u8 ret;
  213. int sw = set_mux_to_lbc();
  214. ret = __raw_readb(addr);
  215. if (sw)
  216. set_mux_to_diu();
  217. return ret;
  218. }
  219. u16 flash_read16(void *addr)
  220. {
  221. u16 ret;
  222. int sw = set_mux_to_lbc();
  223. ret = __raw_readw(addr);
  224. if (sw)
  225. set_mux_to_diu();
  226. return ret;
  227. }
  228. u32 flash_read32(void *addr)
  229. {
  230. u32 ret;
  231. int sw = set_mux_to_lbc();
  232. ret = __raw_readl(addr);
  233. if (sw)
  234. set_mux_to_diu();
  235. return ret;
  236. }
  237. u64 flash_read64(void *addr)
  238. {
  239. u64 ret;
  240. int sw = set_mux_to_lbc();
  241. /* There is no __raw_readq(), so do the read manually */
  242. ret = *(volatile u64 *)addr;
  243. if (sw)
  244. set_mux_to_diu();
  245. return ret;
  246. }
  247. #endif