dcu.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014 Freescale Semiconductor, Inc.
  4. *
  5. * FSL DCU Framebuffer driver
  6. */
  7. #include <asm/io.h>
  8. #include <common.h>
  9. #include <fsl_dcu_fb.h>
  10. #include <i2c.h>
  11. #include "div64.h"
  12. #include "../common/diu_ch7301.h"
  13. #include "ls1021aqds_qixis.h"
  14. DECLARE_GLOBAL_DATA_PTR;
  15. static int select_i2c_ch_pca9547(u8 ch)
  16. {
  17. int ret;
  18. ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
  19. if (ret) {
  20. puts("PCA: failed to select proper channel\n");
  21. return ret;
  22. }
  23. return 0;
  24. }
  25. unsigned int dcu_set_pixel_clock(unsigned int pixclock)
  26. {
  27. unsigned long long div;
  28. div = (unsigned long long)(gd->bus_clk / 1000);
  29. div *= (unsigned long long)pixclock;
  30. do_div(div, 1000000000);
  31. return div;
  32. }
  33. int platform_dcu_init(struct fb_info *fbinfo,
  34. unsigned int xres,
  35. unsigned int yres,
  36. const char *port,
  37. struct fb_videomode *dcu_fb_videomode)
  38. {
  39. const char *name;
  40. unsigned int pixel_format;
  41. int ret;
  42. u8 ch;
  43. /* Mux I2C3+I2C4 as HSYNC+VSYNC */
  44. ret = i2c_read(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5,
  45. 1, &ch, 1);
  46. if (ret) {
  47. printf("Error: failed to read I2C @%02x\n",
  48. CONFIG_SYS_I2C_QIXIS_ADDR);
  49. return ret;
  50. }
  51. ch &= 0x1F;
  52. ch |= 0xA0;
  53. ret = i2c_write(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5,
  54. 1, &ch, 1);
  55. if (ret) {
  56. printf("Error: failed to write I2C @%02x\n",
  57. CONFIG_SYS_I2C_QIXIS_ADDR);
  58. return ret;
  59. }
  60. if (strncmp(port, "hdmi", 4) == 0) {
  61. unsigned long pixval;
  62. name = "HDMI";
  63. pixval = 1000000000 / dcu_fb_videomode->pixclock;
  64. pixval *= 1000;
  65. i2c_set_bus_num(CONFIG_SYS_I2C_DVI_BUS_NUM);
  66. select_i2c_ch_pca9547(I2C_MUX_CH_CH7301);
  67. diu_set_dvi_encoder(pixval);
  68. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  69. } else {
  70. return 0;
  71. }
  72. printf("DCU: Switching to %s monitor @ %ux%u\n", name, xres, yres);
  73. pixel_format = 32;
  74. fsl_dcu_init(fbinfo, xres, yres, pixel_format);
  75. return 0;
  76. }