diu.c 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2010-2011 Freescale Semiconductor, Inc.
  4. * Authors: Timur Tabi <timur@freescale.com>
  5. *
  6. * FSL DIU Framebuffer driver
  7. */
  8. #include <common.h>
  9. #include <command.h>
  10. #include <linux/ctype.h>
  11. #include <asm/io.h>
  12. #include <stdio_dev.h>
  13. #include <video_fb.h>
  14. #include <fsl_diu_fb.h>
  15. #define PMUXCR_ELBCDIU_MASK 0xc0000000
  16. #define PMUXCR_ELBCDIU_NOR16 0x80000000
  17. #define PMUXCR_ELBCDIU_DIU 0x40000000
  18. /*
  19. * DIU Area Descriptor
  20. *
  21. * Note that we need to byte-swap the value before it's written to the AD
  22. * register. So even though the registers don't look like they're in the same
  23. * bit positions as they are on the MPC8610, the same value is written to the
  24. * AD register on the MPC8610 and on the P1022.
  25. */
  26. #define AD_BYTE_F 0x10000000
  27. #define AD_ALPHA_C_SHIFT 25
  28. #define AD_BLUE_C_SHIFT 23
  29. #define AD_GREEN_C_SHIFT 21
  30. #define AD_RED_C_SHIFT 19
  31. #define AD_PIXEL_S_SHIFT 16
  32. #define AD_COMP_3_SHIFT 12
  33. #define AD_COMP_2_SHIFT 8
  34. #define AD_COMP_1_SHIFT 4
  35. #define AD_COMP_0_SHIFT 0
  36. /*
  37. * Variables used by the DIU/LBC switching code. It's safe to makes these
  38. * global, because the DIU requires DDR, so we'll only run this code after
  39. * relocation.
  40. */
  41. static u32 pmuxcr;
  42. void diu_set_pixel_clock(unsigned int pixclock)
  43. {
  44. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  45. unsigned long speed_ccb, temp;
  46. u32 pixval;
  47. speed_ccb = get_bus_freq(0);
  48. temp = 1000000000 / pixclock;
  49. temp *= 1000;
  50. pixval = speed_ccb / temp;
  51. debug("DIU pixval = %u\n", pixval);
  52. /* Modify PXCLK in GUTS CLKDVDR */
  53. temp = in_be32(&gur->clkdvdr) & 0x2000FFFF;
  54. out_be32(&gur->clkdvdr, temp); /* turn off clock */
  55. out_be32(&gur->clkdvdr, temp | 0x80000000 | ((pixval & 0x1F) << 16));
  56. }
  57. int platform_diu_init(unsigned int xres, unsigned int yres, const char *port)
  58. {
  59. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  60. u32 pixel_format;
  61. pixel_format = cpu_to_le32(AD_BYTE_F | (3 << AD_ALPHA_C_SHIFT) |
  62. (0 << AD_BLUE_C_SHIFT) | (1 << AD_GREEN_C_SHIFT) |
  63. (2 << AD_RED_C_SHIFT) | (8 << AD_COMP_3_SHIFT) |
  64. (8 << AD_COMP_2_SHIFT) | (8 << AD_COMP_1_SHIFT) |
  65. (8 << AD_COMP_0_SHIFT) | (3 << AD_PIXEL_S_SHIFT));
  66. printf("DIU: Switching to %ux%u\n", xres, yres);
  67. /* Set PMUXCR to switch the muxed pins from the LBC to the DIU */
  68. clrsetbits_be32(&gur->pmuxcr, PMUXCR_ELBCDIU_MASK, PMUXCR_ELBCDIU_DIU);
  69. pmuxcr = in_be32(&gur->pmuxcr);
  70. return fsl_diu_init(xres, yres, pixel_format, 0);
  71. }