sun8i_dw_hdmi.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright (C) 2018 Jernej Skrabec <jernej.skrabec@siol.net>
  4. */
  5. #ifndef _SUN8I_DW_HDMI_H_
  6. #define _SUN8I_DW_HDMI_H_
  7. #include <drm/bridge/dw_hdmi.h>
  8. #include <drm/drm_encoder.h>
  9. #include <linux/clk.h>
  10. #include <linux/regmap.h>
  11. #include <linux/reset.h>
  12. #define SUN8I_HDMI_PHY_DBG_CTRL_REG 0x0000
  13. #define SUN8I_HDMI_PHY_DBG_CTRL_PX_LOCK BIT(0)
  14. #define SUN8I_HDMI_PHY_DBG_CTRL_POL_MASK GENMASK(15, 8)
  15. #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NHSYNC BIT(8)
  16. #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NVSYNC BIT(9)
  17. #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR_MASK GENMASK(23, 16)
  18. #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR(addr) (addr << 16)
  19. #define SUN8I_HDMI_PHY_REXT_CTRL_REG 0x0004
  20. #define SUN8I_HDMI_PHY_REXT_CTRL_REXT_EN BIT(31)
  21. #define SUN8I_HDMI_PHY_READ_EN_REG 0x0010
  22. #define SUN8I_HDMI_PHY_READ_EN_MAGIC 0x54524545
  23. #define SUN8I_HDMI_PHY_UNSCRAMBLE_REG 0x0014
  24. #define SUN8I_HDMI_PHY_UNSCRAMBLE_MAGIC 0x42494E47
  25. #define SUN8I_HDMI_PHY_ANA_CFG1_REG 0x0020
  26. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SWI BIT(31)
  27. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWEND BIT(30)
  28. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWENC BIT(29)
  29. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_CALSW BIT(28)
  30. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVRCAL(x) ((x) << 26)
  31. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVBH(x) ((x) << 24)
  32. #define SUN8I_HDMI_PHY_ANA_CFG1_AMP_OPT BIT(23)
  33. #define SUN8I_HDMI_PHY_ANA_CFG1_EMP_OPT BIT(22)
  34. #define SUN8I_HDMI_PHY_ANA_CFG1_AMPCK_OPT BIT(21)
  35. #define SUN8I_HDMI_PHY_ANA_CFG1_EMPCK_OPT BIT(20)
  36. #define SUN8I_HDMI_PHY_ANA_CFG1_ENRCAL BIT(19)
  37. #define SUN8I_HDMI_PHY_ANA_CFG1_ENCALOG BIT(18)
  38. #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SCKTMDS BIT(17)
  39. #define SUN8I_HDMI_PHY_ANA_CFG1_TMDSCLK_EN BIT(16)
  40. #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_MASK GENMASK(15, 12)
  41. #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_ALL (0xf << 12)
  42. #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDSCLK BIT(11)
  43. #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS2 BIT(10)
  44. #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS1 BIT(9)
  45. #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS0 BIT(8)
  46. #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDSCLK BIT(7)
  47. #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS2 BIT(6)
  48. #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS1 BIT(5)
  49. #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS0 BIT(4)
  50. #define SUN8I_HDMI_PHY_ANA_CFG1_CKEN BIT(3)
  51. #define SUN8I_HDMI_PHY_ANA_CFG1_LDOEN BIT(2)
  52. #define SUN8I_HDMI_PHY_ANA_CFG1_ENVBS BIT(1)
  53. #define SUN8I_HDMI_PHY_ANA_CFG1_ENBI BIT(0)
  54. #define SUN8I_HDMI_PHY_ANA_CFG2_REG 0x0024
  55. #define SUN8I_HDMI_PHY_ANA_CFG2_M_EN BIT(31)
  56. #define SUN8I_HDMI_PHY_ANA_CFG2_PLLDBEN BIT(30)
  57. #define SUN8I_HDMI_PHY_ANA_CFG2_SEN BIT(29)
  58. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDPD BIT(28)
  59. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDEN BIT(27)
  60. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLRCK BIT(26)
  61. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLR(x) ((x) << 23)
  62. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DENCK BIT(22)
  63. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DEN BIT(21)
  64. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CD(x) ((x) << 19)
  65. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CKSS(x) ((x) << 17)
  66. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSWCK BIT(16)
  67. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSW BIT(15)
  68. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CSMPS(x) ((x) << 13)
  69. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_SLV(x) ((x) << 10)
  70. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOSTCK(x) ((x) << 8)
  71. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOST(x) ((x) << 6)
  72. #define SUN8I_HDMI_PHY_ANA_CFG2_REG_RESDI(x) ((x) << 0)
  73. #define SUN8I_HDMI_PHY_ANA_CFG3_REG 0x0028
  74. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOWCK(x) ((x) << 30)
  75. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOW(x) ((x) << 28)
  76. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_WIRE(x) ((x) << 18)
  77. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMPCK(x) ((x) << 14)
  78. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMPCK(x) ((x) << 11)
  79. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMP(x) ((x) << 7)
  80. #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMP(x) ((x) << 4)
  81. #define SUN8I_HDMI_PHY_ANA_CFG3_SDAPD BIT(3)
  82. #define SUN8I_HDMI_PHY_ANA_CFG3_SDAEN BIT(2)
  83. #define SUN8I_HDMI_PHY_ANA_CFG3_SCLPD BIT(1)
  84. #define SUN8I_HDMI_PHY_ANA_CFG3_SCLEN BIT(0)
  85. #define SUN8I_HDMI_PHY_PLL_CFG1_REG 0x002c
  86. #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD1 BIT(31)
  87. #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD BIT(30)
  88. #define SUN8I_HDMI_PHY_PLL_CFG1_LDO2_EN BIT(29)
  89. #define SUN8I_HDMI_PHY_PLL_CFG1_LDO1_EN BIT(28)
  90. #define SUN8I_HDMI_PHY_PLL_CFG1_HV_IS_33 BIT(27)
  91. #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_MSK BIT(26)
  92. #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_SHIFT 26
  93. #define SUN8I_HDMI_PHY_PLL_CFG1_PLLEN BIT(25)
  94. #define SUN8I_HDMI_PHY_PLL_CFG1_LDO_VSET(x) ((x) << 22)
  95. #define SUN8I_HDMI_PHY_PLL_CFG1_UNKNOWN(x) ((x) << 20)
  96. #define SUN8I_HDMI_PHY_PLL_CFG1_PLLDBEN BIT(19)
  97. #define SUN8I_HDMI_PHY_PLL_CFG1_CS BIT(18)
  98. #define SUN8I_HDMI_PHY_PLL_CFG1_CP_S(x) ((x) << 13)
  99. #define SUN8I_HDMI_PHY_PLL_CFG1_CNT_INT(x) ((x) << 7)
  100. #define SUN8I_HDMI_PHY_PLL_CFG1_BWS BIT(6)
  101. #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_MSK GENMASK(5, 0)
  102. #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_SHIFT 0
  103. #define SUN8I_HDMI_PHY_PLL_CFG2_REG 0x0030
  104. #define SUN8I_HDMI_PHY_PLL_CFG2_SV_H BIT(31)
  105. #define SUN8I_HDMI_PHY_PLL_CFG2_PDCLKSEL(x) ((x) << 29)
  106. #define SUN8I_HDMI_PHY_PLL_CFG2_CLKSTEP(x) ((x) << 27)
  107. #define SUN8I_HDMI_PHY_PLL_CFG2_PSET(x) ((x) << 24)
  108. #define SUN8I_HDMI_PHY_PLL_CFG2_PCLK_SEL BIT(23)
  109. #define SUN8I_HDMI_PHY_PLL_CFG2_AUTOSYNC_DIS BIT(22)
  110. #define SUN8I_HDMI_PHY_PLL_CFG2_VREG2_OUT_EN BIT(21)
  111. #define SUN8I_HDMI_PHY_PLL_CFG2_VREG1_OUT_EN BIT(20)
  112. #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN_EN BIT(19)
  113. #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN(x) ((x) << 16)
  114. #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_S(x) ((x) << 12)
  115. #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_RST_IN BIT(11)
  116. #define SUN8I_HDMI_PHY_PLL_CFG2_SINT_FRAC BIT(10)
  117. #define SUN8I_HDMI_PHY_PLL_CFG2_SDIV2 BIT(9)
  118. #define SUN8I_HDMI_PHY_PLL_CFG2_S(x) ((x) << 6)
  119. #define SUN8I_HDMI_PHY_PLL_CFG2_S6P25_7P5 BIT(5)
  120. #define SUN8I_HDMI_PHY_PLL_CFG2_S5_7 BIT(4)
  121. #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_MSK GENMASK(3, 0)
  122. #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_SHIFT 0
  123. #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV(x) (((x) - 1) << 0)
  124. #define SUN8I_HDMI_PHY_PLL_CFG3_REG 0x0034
  125. #define SUN8I_HDMI_PHY_PLL_CFG3_SOUT_DIV2 BIT(0)
  126. #define SUN8I_HDMI_PHY_ANA_STS_REG 0x0038
  127. #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_SHIFT 11
  128. #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_MSK GENMASK(16, 11)
  129. #define SUN8I_HDMI_PHY_ANA_STS_RCALEND2D BIT(7)
  130. #define SUN8I_HDMI_PHY_ANA_STS_RCAL_MASK GENMASK(5, 0)
  131. #define SUN8I_HDMI_PHY_CEC_REG 0x003c
  132. struct sun8i_hdmi_phy;
  133. struct sun8i_hdmi_phy_variant {
  134. bool has_phy_clk;
  135. bool has_second_pll;
  136. void (*phy_init)(struct sun8i_hdmi_phy *phy);
  137. void (*phy_disable)(struct dw_hdmi *hdmi,
  138. struct sun8i_hdmi_phy *phy);
  139. int (*phy_config)(struct dw_hdmi *hdmi,
  140. struct sun8i_hdmi_phy *phy,
  141. unsigned int clk_rate);
  142. };
  143. struct sun8i_hdmi_phy {
  144. struct clk *clk_bus;
  145. struct clk *clk_mod;
  146. struct clk *clk_phy;
  147. struct clk *clk_pll0;
  148. struct clk *clk_pll1;
  149. unsigned int rcal;
  150. struct regmap *regs;
  151. struct reset_control *rst_phy;
  152. struct sun8i_hdmi_phy_variant *variant;
  153. };
  154. struct sun8i_dw_hdmi {
  155. struct clk *clk_tmds;
  156. struct device *dev;
  157. struct dw_hdmi *hdmi;
  158. struct drm_encoder encoder;
  159. struct sun8i_hdmi_phy *phy;
  160. struct dw_hdmi_plat_data plat_data;
  161. struct reset_control *rst_ctrl;
  162. };
  163. static inline struct sun8i_dw_hdmi *
  164. encoder_to_sun8i_dw_hdmi(struct drm_encoder *encoder)
  165. {
  166. return container_of(encoder, struct sun8i_dw_hdmi, encoder);
  167. }
  168. int sun8i_hdmi_phy_probe(struct sun8i_dw_hdmi *hdmi, struct device_node *node);
  169. void sun8i_hdmi_phy_remove(struct sun8i_dw_hdmi *hdmi);
  170. void sun8i_hdmi_phy_init(struct sun8i_hdmi_phy *phy);
  171. const struct dw_hdmi_phy_ops *sun8i_hdmi_phy_get_ops(void);
  172. int sun8i_phy_clk_create(struct sun8i_hdmi_phy *phy, struct device *dev,
  173. bool second_parent);
  174. #endif /* _SUN8I_DW_HDMI_H_ */