dcu.c 1.8 KB

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