dcu_sii9022a.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2014 Freescale Semiconductor, Inc.
  4. */
  5. #include <asm/io.h>
  6. #include <common.h>
  7. #include <fsl_dcu_fb.h>
  8. #include <i2c.h>
  9. #include <linux/fb.h>
  10. #define PIXEL_CLK_LSB_REG 0x00
  11. #define PIXEL_CLK_MSB_REG 0x01
  12. #define VERT_FREQ_LSB_REG 0x02
  13. #define VERT_FREQ_MSB_REG 0x03
  14. #define TOTAL_PIXELS_LSB_REG 0x04
  15. #define TOTAL_PIXELS_MSB_REG 0x05
  16. #define TOTAL_LINES_LSB_REG 0x06
  17. #define TOTAL_LINES_MSB_REG 0x07
  18. #define TPI_INBUS_FMT_REG 0x08
  19. #define TPI_INPUT_FMT_REG 0x09
  20. #define TPI_OUTPUT_FMT_REG 0x0A
  21. #define TPI_SYS_CTRL_REG 0x1A
  22. #define TPI_PWR_STAT_REG 0x1E
  23. #define TPI_AUDIO_HANDING_REG 0x25
  24. #define TPI_AUDIO_INTF_REG 0x26
  25. #define TPI_AUDIO_FREQ_REG 0x27
  26. #define TPI_SET_PAGE_REG 0xBC
  27. #define TPI_SET_OFFSET_REG 0xBD
  28. #define TPI_RW_ACCESS_REG 0xBE
  29. #define TPI_TRANS_MODE_REG 0xC7
  30. #define TPI_INBUS_CLOCK_RATIO_1 (1 << 6)
  31. #define TPI_INBUS_FULL_PIXEL_WIDE (1 << 5)
  32. #define TPI_INBUS_RISING_EDGE (1 << 4)
  33. #define TPI_INPUT_CLR_DEPTH_8BIT (0 << 6)
  34. #define TPI_INPUT_VRANGE_EXPAN_AUTO (0 << 2)
  35. #define TPI_INPUT_CLR_RGB (0 << 0)
  36. #define TPI_OUTPUT_CLR_DEPTH_8BIT (0 << 6)
  37. #define TPI_OUTPUT_VRANGE_COMPRE_AUTO (0 << 2)
  38. #define TPI_OUTPUT_CLR_HDMI_RGB (0 << 0)
  39. #define TPI_SYS_TMDS_OUTPUT (0 << 4)
  40. #define TPI_SYS_AV_NORAML (0 << 3)
  41. #define TPI_SYS_AV_MUTE (1 << 3)
  42. #define TPI_SYS_DVI_MODE (0 << 0)
  43. #define TPI_SYS_HDMI_MODE (1 << 0)
  44. #define TPI_PWR_STAT_MASK (3 << 0)
  45. #define TPI_PWR_STAT_D0 (0 << 0)
  46. #define TPI_AUDIO_PASS_BASIC (0 << 0)
  47. #define TPI_AUDIO_INTF_I2S (2 << 6)
  48. #define TPI_AUDIO_INTF_NORMAL (0 << 4)
  49. #define TPI_AUDIO_TYPE_PCM (1 << 0)
  50. #define TPI_AUDIO_SAMP_SIZE_16BIT (1 << 6)
  51. #define TPI_AUDIO_SAMP_FREQ_44K (2 << 3)
  52. #define TPI_SET_PAGE_SII9022A 0x01
  53. #define TPI_SET_OFFSET_SII9022A 0x82
  54. #define TPI_RW_EN_SRC_TERMIN (1 << 0)
  55. #define TPI_TRANS_MODE_ENABLE (0 << 7)
  56. /* Programming of Silicon SIi9022a HDMI Transmitter */
  57. int dcu_set_dvi_encoder(struct fb_videomode *videomode)
  58. {
  59. u8 temp;
  60. u16 temp1, temp2;
  61. u32 temp3;
  62. i2c_set_bus_num(CONFIG_SYS_I2C_DVI_BUS_NUM);
  63. /* Enable TPI transmitter mode */
  64. temp = TPI_TRANS_MODE_ENABLE;
  65. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_TRANS_MODE_REG, 1, &temp, 1);
  66. /* Enter into D0 state, full operation */
  67. i2c_read(CONFIG_SYS_I2C_DVI_ADDR, TPI_PWR_STAT_REG, 1, &temp, 1);
  68. temp &= ~TPI_PWR_STAT_MASK;
  69. temp |= TPI_PWR_STAT_D0;
  70. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_PWR_STAT_REG, 1, &temp, 1);
  71. /* Enable source termination */
  72. temp = TPI_SET_PAGE_SII9022A;
  73. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_SET_PAGE_REG, 1, &temp, 1);
  74. temp = TPI_SET_OFFSET_SII9022A;
  75. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_SET_OFFSET_REG, 1, &temp, 1);
  76. i2c_read(CONFIG_SYS_I2C_DVI_ADDR, TPI_RW_ACCESS_REG, 1, &temp, 1);
  77. temp |= TPI_RW_EN_SRC_TERMIN;
  78. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_RW_ACCESS_REG, 1, &temp, 1);
  79. /* Set TPI system control */
  80. temp = TPI_SYS_TMDS_OUTPUT | TPI_SYS_AV_NORAML | TPI_SYS_DVI_MODE;
  81. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_SYS_CTRL_REG, 1, &temp, 1);
  82. /* Set pixel clock */
  83. temp1 = PICOS2KHZ(videomode->pixclock) / 10;
  84. temp = (u8)(temp1 & 0xFF);
  85. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, PIXEL_CLK_LSB_REG, 1, &temp, 1);
  86. temp = (u8)(temp1 >> 8);
  87. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, PIXEL_CLK_MSB_REG, 1, &temp, 1);
  88. /* Set total pixels per line */
  89. temp1 = videomode->hsync_len + videomode->left_margin +
  90. videomode->xres + videomode->right_margin;
  91. temp = (u8)(temp1 & 0xFF);
  92. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TOTAL_PIXELS_LSB_REG, 1, &temp, 1);
  93. temp = (u8)(temp1 >> 8);
  94. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TOTAL_PIXELS_MSB_REG, 1, &temp, 1);
  95. /* Set total lines */
  96. temp2 = videomode->vsync_len + videomode->upper_margin +
  97. videomode->yres + videomode->lower_margin;
  98. temp = (u8)(temp2 & 0xFF);
  99. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TOTAL_LINES_LSB_REG, 1, &temp, 1);
  100. temp = (u8)(temp2 >> 8);
  101. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TOTAL_LINES_MSB_REG, 1, &temp, 1);
  102. /* Set vertical frequency in Hz */
  103. temp3 = temp1 * temp2;
  104. temp3 = (PICOS2KHZ(videomode->pixclock) * 1000) / temp3;
  105. temp1 = (u16)temp3 * 100;
  106. temp = (u8)(temp1 & 0xFF);
  107. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, VERT_FREQ_LSB_REG, 1, &temp, 1);
  108. temp = (u8)(temp1 >> 8);
  109. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, VERT_FREQ_MSB_REG, 1, &temp, 1);
  110. /* Set TPI input bus and pixel repetition data */
  111. temp = TPI_INBUS_CLOCK_RATIO_1 | TPI_INBUS_FULL_PIXEL_WIDE |
  112. TPI_INBUS_RISING_EDGE;
  113. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_INBUS_FMT_REG, 1, &temp, 1);
  114. /* Set TPI AVI Input format data */
  115. temp = TPI_INPUT_CLR_DEPTH_8BIT | TPI_INPUT_VRANGE_EXPAN_AUTO |
  116. TPI_INPUT_CLR_RGB;
  117. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_INPUT_FMT_REG, 1, &temp, 1);
  118. /* Set TPI AVI Output format data */
  119. temp = TPI_OUTPUT_CLR_DEPTH_8BIT | TPI_OUTPUT_VRANGE_COMPRE_AUTO |
  120. TPI_OUTPUT_CLR_HDMI_RGB;
  121. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_OUTPUT_FMT_REG, 1, &temp, 1);
  122. /* Set TPI audio configuration write data */
  123. temp = TPI_AUDIO_PASS_BASIC;
  124. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_AUDIO_HANDING_REG, 1, &temp, 1);
  125. temp = TPI_AUDIO_INTF_I2S | TPI_AUDIO_INTF_NORMAL |
  126. TPI_AUDIO_TYPE_PCM;
  127. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_AUDIO_INTF_REG, 1, &temp, 1);
  128. temp = TPI_AUDIO_SAMP_SIZE_16BIT | TPI_AUDIO_SAMP_FREQ_44K;
  129. i2c_write(CONFIG_SYS_I2C_DVI_ADDR, TPI_AUDIO_FREQ_REG, 1, &temp, 1);
  130. return 0;
  131. }