diu.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #define PX_BRDCFG0_ELBC_DIU 0x02
  20. #define PX_BRDCFG1_DVIEN 0x80
  21. #define PX_BRDCFG1_DFPEN 0x40
  22. #define PX_BRDCFG1_BACKLIGHT 0x20
  23. /*
  24. * DIU Area Descriptor
  25. *
  26. * Note that we need to byte-swap the value before it's written to the AD
  27. * register. So even though the registers don't look like they're in the same
  28. * bit positions as they are on the MPC8610, the same value is written to the
  29. * AD register on the MPC8610 and on the P1022.
  30. */
  31. #define AD_BYTE_F 0x10000000
  32. #define AD_ALPHA_C_SHIFT 25
  33. #define AD_BLUE_C_SHIFT 23
  34. #define AD_GREEN_C_SHIFT 21
  35. #define AD_RED_C_SHIFT 19
  36. #define AD_PIXEL_S_SHIFT 16
  37. #define AD_COMP_3_SHIFT 12
  38. #define AD_COMP_2_SHIFT 8
  39. #define AD_COMP_1_SHIFT 4
  40. #define AD_COMP_0_SHIFT 0
  41. void diu_set_pixel_clock(unsigned int pixclock)
  42. {
  43. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  44. unsigned long speed_ccb, temp;
  45. u32 pixval;
  46. speed_ccb = get_bus_freq(0);
  47. temp = 1000000000 / pixclock;
  48. temp *= 1000;
  49. pixval = speed_ccb / temp;
  50. debug("DIU pixval = %lu\n", pixval);
  51. /* Modify PXCLK in GUTS CLKDVDR */
  52. temp = in_be32(&gur->clkdvdr) & 0x2000FFFF;
  53. out_be32(&gur->clkdvdr, temp); /* turn off clock */
  54. out_be32(&gur->clkdvdr, temp | 0x80000000 | ((pixval & 0x1F) << 16));
  55. }
  56. int platform_diu_init(unsigned int *xres, unsigned int *yres)
  57. {
  58. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  59. char *monitor_port;
  60. u32 pixel_format;
  61. u8 temp;
  62. pixel_format = cpu_to_le32(AD_BYTE_F | (3 << AD_ALPHA_C_SHIFT) |
  63. (0 << AD_BLUE_C_SHIFT) | (1 << AD_GREEN_C_SHIFT) |
  64. (2 << AD_RED_C_SHIFT) | (8 << AD_COMP_3_SHIFT) |
  65. (8 << AD_COMP_2_SHIFT) | (8 << AD_COMP_1_SHIFT) |
  66. (8 << AD_COMP_0_SHIFT) | (3 << AD_PIXEL_S_SHIFT));
  67. temp = in_8(&pixis->brdcfg1);
  68. monitor_port = getenv("monitor");
  69. if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */
  70. *xres = 1024;
  71. *yres = 768;
  72. /* Enable the DFP port, disable the DVI and the backlight */
  73. temp &= ~(PX_BRDCFG1_DVIEN | PX_BRDCFG1_BACKLIGHT);
  74. temp |= PX_BRDCFG1_DFPEN;
  75. } else { /* DVI */
  76. *xres = 1280;
  77. *yres = 1024;
  78. /* Enable the DVI port, disable the DFP and the backlight */
  79. temp &= ~(PX_BRDCFG1_DFPEN | PX_BRDCFG1_BACKLIGHT);
  80. temp |= PX_BRDCFG1_DVIEN;
  81. }
  82. out_8(&pixis->brdcfg1, temp);
  83. /*
  84. * Route the LAD pins to the DIU. This will disable access to the eLBC,
  85. * which means we won't be able to read/write any NOR flash addresses!
  86. */
  87. out_8(&pixis->brdcfg0, in_8(&pixis->brdcfg0) | PX_BRDCFG0_ELBC_DIU);
  88. /* we must do the dummy read from eLBC to sync the write as above */
  89. in_8(&pixis->brdcfg0);
  90. /* Setting PMUXCR to switch to DVI from ELBC */
  91. /* Set pmuxcr to allow both i2c1 and i2c2 */
  92. clrsetbits_be32(&gur->pmuxcr, 0xc0000000, 0x40000000);
  93. in_be32(&gur->pmuxcr);
  94. return fsl_diu_init(*xres, pixel_format, 0);
  95. }