dcu.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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(unsigned int xres, unsigned int yres,
  34. const char *port,
  35. struct fb_videomode *dcu_fb_videomode)
  36. {
  37. const char *name;
  38. unsigned int pixel_format;
  39. int ret;
  40. u8 ch;
  41. /* Mux I2C3+I2C4 as HSYNC+VSYNC */
  42. ret = i2c_read(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5,
  43. 1, &ch, 1);
  44. if (ret) {
  45. printf("Error: failed to read I2C @%02x\n",
  46. CONFIG_SYS_I2C_QIXIS_ADDR);
  47. return ret;
  48. }
  49. ch &= 0x1F;
  50. ch |= 0xA0;
  51. ret = i2c_write(CONFIG_SYS_I2C_QIXIS_ADDR, QIXIS_DCU_BRDCFG5,
  52. 1, &ch, 1);
  53. if (ret) {
  54. printf("Error: failed to write I2C @%02x\n",
  55. CONFIG_SYS_I2C_QIXIS_ADDR);
  56. return ret;
  57. }
  58. if (strncmp(port, "hdmi", 4) == 0) {
  59. unsigned long pixval;
  60. name = "HDMI";
  61. pixval = 1000000000 / dcu_fb_videomode->pixclock;
  62. pixval *= 1000;
  63. i2c_set_bus_num(CONFIG_SYS_I2C_DVI_BUS_NUM);
  64. select_i2c_ch_pca9547(I2C_MUX_CH_CH7301);
  65. diu_set_dvi_encoder(pixval);
  66. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  67. } else {
  68. return 0;
  69. }
  70. printf("DCU: Switching to %s monitor @ %ux%u\n", name, xres, yres);
  71. pixel_format = 32;
  72. fsl_dcu_init(xres, yres, pixel_format);
  73. return 0;
  74. }