dcu_sii9022a.c 5.2 KB

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