sun4i_tcon.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /*
  2. * Copyright (C) 2015 Free Electrons
  3. * Copyright (C) 2015 NextThing Co
  4. *
  5. * Boris Brezillon <boris.brezillon@free-electrons.com>
  6. * Maxime Ripard <maxime.ripard@free-electrons.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. */
  13. #ifndef __SUN4I_TCON_H__
  14. #define __SUN4I_TCON_H__
  15. #include <drm/drm_crtc.h>
  16. #include <linux/kernel.h>
  17. #include <linux/reset.h>
  18. #define SUN4I_TCON_GCTL_REG 0x0
  19. #define SUN4I_TCON_GCTL_TCON_ENABLE BIT(31)
  20. #define SUN4I_TCON_GCTL_IOMAP_MASK BIT(0)
  21. #define SUN4I_TCON_GCTL_IOMAP_TCON1 (1 << 0)
  22. #define SUN4I_TCON_GCTL_IOMAP_TCON0 (0 << 0)
  23. #define SUN4I_TCON_GINT0_REG 0x4
  24. #define SUN4I_TCON_GINT0_VBLANK_ENABLE(pipe) BIT(31 - (pipe))
  25. #define SUN4I_TCON_GINT0_VBLANK_INT(pipe) BIT(15 - (pipe))
  26. #define SUN4I_TCON_GINT1_REG 0x8
  27. #define SUN4I_TCON_FRM_CTL_REG 0x10
  28. #define SUN4I_TCON0_CTL_REG 0x40
  29. #define SUN4I_TCON0_CTL_TCON_ENABLE BIT(31)
  30. #define SUN4I_TCON0_CTL_CLK_DELAY_MASK GENMASK(8, 4)
  31. #define SUN4I_TCON0_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON0_CTL_CLK_DELAY_MASK)
  32. #define SUN4I_TCON0_DCLK_REG 0x44
  33. #define SUN4I_TCON0_DCLK_GATE_BIT (31)
  34. #define SUN4I_TCON0_DCLK_DIV_SHIFT (0)
  35. #define SUN4I_TCON0_DCLK_DIV_WIDTH (7)
  36. #define SUN4I_TCON0_BASIC0_REG 0x48
  37. #define SUN4I_TCON0_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16)
  38. #define SUN4I_TCON0_BASIC0_Y(height) (((height) - 1) & 0xfff)
  39. #define SUN4I_TCON0_BASIC1_REG 0x4c
  40. #define SUN4I_TCON0_BASIC1_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16)
  41. #define SUN4I_TCON0_BASIC1_H_BACKPORCH(bp) (((bp) - 1) & 0xfff)
  42. #define SUN4I_TCON0_BASIC2_REG 0x50
  43. #define SUN4I_TCON0_BASIC2_V_TOTAL(total) ((((total) * 2) & 0x1fff) << 16)
  44. #define SUN4I_TCON0_BASIC2_V_BACKPORCH(bp) (((bp) - 1) & 0xfff)
  45. #define SUN4I_TCON0_BASIC3_REG 0x54
  46. #define SUN4I_TCON0_BASIC3_H_SYNC(width) ((((width) - 1) & 0x7ff) << 16)
  47. #define SUN4I_TCON0_BASIC3_V_SYNC(height) (((height) - 1) & 0x7ff)
  48. #define SUN4I_TCON0_HV_IF_REG 0x58
  49. #define SUN4I_TCON0_CPU_IF_REG 0x60
  50. #define SUN4I_TCON0_CPU_WR_REG 0x64
  51. #define SUN4I_TCON0_CPU_RD0_REG 0x68
  52. #define SUN4I_TCON0_CPU_RDA_REG 0x6c
  53. #define SUN4I_TCON0_TTL0_REG 0x70
  54. #define SUN4I_TCON0_TTL1_REG 0x74
  55. #define SUN4I_TCON0_TTL2_REG 0x78
  56. #define SUN4I_TCON0_TTL3_REG 0x7c
  57. #define SUN4I_TCON0_TTL4_REG 0x80
  58. #define SUN4I_TCON0_LVDS_IF_REG 0x84
  59. #define SUN4I_TCON0_IO_POL_REG 0x88
  60. #define SUN4I_TCON0_IO_POL_DCLK_PHASE(phase) ((phase & 3) << 28)
  61. #define SUN4I_TCON0_IO_POL_HSYNC_POSITIVE BIT(25)
  62. #define SUN4I_TCON0_IO_POL_VSYNC_POSITIVE BIT(24)
  63. #define SUN4I_TCON0_IO_TRI_REG 0x8c
  64. #define SUN4I_TCON0_IO_TRI_HSYNC_DISABLE BIT(25)
  65. #define SUN4I_TCON0_IO_TRI_VSYNC_DISABLE BIT(24)
  66. #define SUN4I_TCON0_IO_TRI_DATA_PINS_DISABLE(pins) GENMASK(pins, 0)
  67. #define SUN4I_TCON1_CTL_REG 0x90
  68. #define SUN4I_TCON1_CTL_TCON_ENABLE BIT(31)
  69. #define SUN4I_TCON1_CTL_INTERLACE_ENABLE BIT(20)
  70. #define SUN4I_TCON1_CTL_CLK_DELAY_MASK GENMASK(8, 4)
  71. #define SUN4I_TCON1_CTL_CLK_DELAY(delay) ((delay << 4) & SUN4I_TCON1_CTL_CLK_DELAY_MASK)
  72. #define SUN4I_TCON1_BASIC0_REG 0x94
  73. #define SUN4I_TCON1_BASIC0_X(width) ((((width) - 1) & 0xfff) << 16)
  74. #define SUN4I_TCON1_BASIC0_Y(height) (((height) - 1) & 0xfff)
  75. #define SUN4I_TCON1_BASIC1_REG 0x98
  76. #define SUN4I_TCON1_BASIC1_X(width) ((((width) - 1) & 0xfff) << 16)
  77. #define SUN4I_TCON1_BASIC1_Y(height) (((height) - 1) & 0xfff)
  78. #define SUN4I_TCON1_BASIC2_REG 0x9c
  79. #define SUN4I_TCON1_BASIC2_X(width) ((((width) - 1) & 0xfff) << 16)
  80. #define SUN4I_TCON1_BASIC2_Y(height) (((height) - 1) & 0xfff)
  81. #define SUN4I_TCON1_BASIC3_REG 0xa0
  82. #define SUN4I_TCON1_BASIC3_H_TOTAL(total) ((((total) - 1) & 0x1fff) << 16)
  83. #define SUN4I_TCON1_BASIC3_H_BACKPORCH(bp) (((bp) - 1) & 0xfff)
  84. #define SUN4I_TCON1_BASIC4_REG 0xa4
  85. #define SUN4I_TCON1_BASIC4_V_TOTAL(total) (((total) & 0x1fff) << 16)
  86. #define SUN4I_TCON1_BASIC4_V_BACKPORCH(bp) (((bp) - 1) & 0xfff)
  87. #define SUN4I_TCON1_BASIC5_REG 0xa8
  88. #define SUN4I_TCON1_BASIC5_H_SYNC(width) ((((width) - 1) & 0x3ff) << 16)
  89. #define SUN4I_TCON1_BASIC5_V_SYNC(height) (((height) - 1) & 0x3ff)
  90. #define SUN4I_TCON1_IO_POL_REG 0xf0
  91. #define SUN4I_TCON1_IO_TRI_REG 0xf4
  92. #define SUN4I_TCON_CEU_CTL_REG 0x100
  93. #define SUN4I_TCON_CEU_MUL_RR_REG 0x110
  94. #define SUN4I_TCON_CEU_MUL_RG_REG 0x114
  95. #define SUN4I_TCON_CEU_MUL_RB_REG 0x118
  96. #define SUN4I_TCON_CEU_ADD_RC_REG 0x11c
  97. #define SUN4I_TCON_CEU_MUL_GR_REG 0x120
  98. #define SUN4I_TCON_CEU_MUL_GG_REG 0x124
  99. #define SUN4I_TCON_CEU_MUL_GB_REG 0x128
  100. #define SUN4I_TCON_CEU_ADD_GC_REG 0x12c
  101. #define SUN4I_TCON_CEU_MUL_BR_REG 0x130
  102. #define SUN4I_TCON_CEU_MUL_BG_REG 0x134
  103. #define SUN4I_TCON_CEU_MUL_BB_REG 0x138
  104. #define SUN4I_TCON_CEU_ADD_BC_REG 0x13c
  105. #define SUN4I_TCON_CEU_RANGE_R_REG 0x140
  106. #define SUN4I_TCON_CEU_RANGE_G_REG 0x144
  107. #define SUN4I_TCON_CEU_RANGE_B_REG 0x148
  108. #define SUN4I_TCON_MUX_CTRL_REG 0x200
  109. #define SUN4I_TCON1_FILL_CTL_REG 0x300
  110. #define SUN4I_TCON1_FILL_BEG0_REG 0x304
  111. #define SUN4I_TCON1_FILL_END0_REG 0x308
  112. #define SUN4I_TCON1_FILL_DATA0_REG 0x30c
  113. #define SUN4I_TCON1_FILL_BEG1_REG 0x310
  114. #define SUN4I_TCON1_FILL_END1_REG 0x314
  115. #define SUN4I_TCON1_FILL_DATA1_REG 0x318
  116. #define SUN4I_TCON1_FILL_BEG2_REG 0x31c
  117. #define SUN4I_TCON1_FILL_END2_REG 0x320
  118. #define SUN4I_TCON1_FILL_DATA2_REG 0x324
  119. #define SUN4I_TCON1_GAMMA_TABLE_REG 0x400
  120. #define SUN4I_TCON_MAX_CHANNELS 2
  121. struct sun4i_tcon_quirks {
  122. bool has_unknown_mux; /* sun5i has undocumented mux */
  123. bool has_channel_1; /* a33 does not have channel 1 */
  124. };
  125. struct sun4i_tcon {
  126. struct device *dev;
  127. struct drm_device *drm;
  128. struct regmap *regs;
  129. /* Main bus clock */
  130. struct clk *clk;
  131. /* Clocks for the TCON channels */
  132. struct clk *sclk0;
  133. struct clk *sclk1;
  134. /* Pixel clock */
  135. struct clk *dclk;
  136. /* Reset control */
  137. struct reset_control *lcd_rst;
  138. struct drm_panel *panel;
  139. /* Platform adjustments */
  140. const struct sun4i_tcon_quirks *quirks;
  141. };
  142. struct drm_bridge *sun4i_tcon_find_bridge(struct device_node *node);
  143. struct drm_panel *sun4i_tcon_find_panel(struct device_node *node);
  144. /* Global Control */
  145. void sun4i_tcon_disable(struct sun4i_tcon *tcon);
  146. void sun4i_tcon_enable(struct sun4i_tcon *tcon);
  147. /* Channel Control */
  148. void sun4i_tcon_channel_disable(struct sun4i_tcon *tcon, int channel);
  149. void sun4i_tcon_channel_enable(struct sun4i_tcon *tcon, int channel);
  150. void sun4i_tcon_enable_vblank(struct sun4i_tcon *tcon, bool enable);
  151. /* Mode Related Controls */
  152. void sun4i_tcon_switch_interlace(struct sun4i_tcon *tcon,
  153. bool enable);
  154. void sun4i_tcon0_mode_set(struct sun4i_tcon *tcon,
  155. struct drm_display_mode *mode);
  156. void sun4i_tcon1_mode_set(struct sun4i_tcon *tcon,
  157. struct drm_display_mode *mode);
  158. #endif /* __SUN4I_TCON_H__ */