Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ */
0002 /*
0003  * Copyright (C) 2018 Jernej Skrabec <jernej.skrabec@siol.net>
0004  */
0005 
0006 #ifndef _SUN8I_DW_HDMI_H_
0007 #define _SUN8I_DW_HDMI_H_
0008 
0009 #include <drm/bridge/dw_hdmi.h>
0010 #include <drm/drm_encoder.h>
0011 #include <linux/clk.h>
0012 #include <linux/regmap.h>
0013 #include <linux/regulator/consumer.h>
0014 #include <linux/reset.h>
0015 
0016 #define SUN8I_HDMI_PHY_DBG_CTRL_REG 0x0000
0017 #define SUN8I_HDMI_PHY_DBG_CTRL_PX_LOCK     BIT(0)
0018 #define SUN8I_HDMI_PHY_DBG_CTRL_POL_MASK    GENMASK(15, 8)
0019 #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NHSYNC  BIT(8)
0020 #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NVSYNC  BIT(9)
0021 #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR_MASK   GENMASK(23, 16)
0022 #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR(addr)  (addr << 16)
0023 
0024 #define SUN8I_HDMI_PHY_REXT_CTRL_REG    0x0004
0025 #define SUN8I_HDMI_PHY_REXT_CTRL_REXT_EN    BIT(31)
0026 
0027 #define SUN8I_HDMI_PHY_READ_EN_REG  0x0010
0028 #define SUN8I_HDMI_PHY_READ_EN_MAGIC        0x54524545
0029 
0030 #define SUN8I_HDMI_PHY_UNSCRAMBLE_REG   0x0014
0031 #define SUN8I_HDMI_PHY_UNSCRAMBLE_MAGIC     0x42494E47
0032 
0033 #define SUN8I_HDMI_PHY_ANA_CFG1_REG 0x0020
0034 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SWI     BIT(31)
0035 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWEND   BIT(30)
0036 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWENC   BIT(29)
0037 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_CALSW   BIT(28)
0038 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVRCAL(x)   ((x) << 26)
0039 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVBH(x) ((x) << 24)
0040 #define SUN8I_HDMI_PHY_ANA_CFG1_AMP_OPT     BIT(23)
0041 #define SUN8I_HDMI_PHY_ANA_CFG1_EMP_OPT     BIT(22)
0042 #define SUN8I_HDMI_PHY_ANA_CFG1_AMPCK_OPT   BIT(21)
0043 #define SUN8I_HDMI_PHY_ANA_CFG1_EMPCK_OPT   BIT(20)
0044 #define SUN8I_HDMI_PHY_ANA_CFG1_ENRCAL      BIT(19)
0045 #define SUN8I_HDMI_PHY_ANA_CFG1_ENCALOG     BIT(18)
0046 #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SCKTMDS BIT(17)
0047 #define SUN8I_HDMI_PHY_ANA_CFG1_TMDSCLK_EN  BIT(16)
0048 #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_MASK   GENMASK(15, 12)
0049 #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_ALL    (0xf << 12)
0050 #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDSCLK  BIT(11)
0051 #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS2    BIT(10)
0052 #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS1    BIT(9)
0053 #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS0    BIT(8)
0054 #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDSCLK   BIT(7)
0055 #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS2 BIT(6)
0056 #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS1 BIT(5)
0057 #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS0 BIT(4)
0058 #define SUN8I_HDMI_PHY_ANA_CFG1_CKEN        BIT(3)
0059 #define SUN8I_HDMI_PHY_ANA_CFG1_LDOEN       BIT(2)
0060 #define SUN8I_HDMI_PHY_ANA_CFG1_ENVBS       BIT(1)
0061 #define SUN8I_HDMI_PHY_ANA_CFG1_ENBI        BIT(0)
0062 
0063 #define SUN8I_HDMI_PHY_ANA_CFG2_REG 0x0024
0064 #define SUN8I_HDMI_PHY_ANA_CFG2_M_EN        BIT(31)
0065 #define SUN8I_HDMI_PHY_ANA_CFG2_PLLDBEN     BIT(30)
0066 #define SUN8I_HDMI_PHY_ANA_CFG2_SEN     BIT(29)
0067 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDPD   BIT(28)
0068 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDEN   BIT(27)
0069 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLRCK   BIT(26)
0070 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLR(x)  ((x) << 23)
0071 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DENCK   BIT(22)
0072 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DEN     BIT(21)
0073 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CD(x)   ((x) << 19)
0074 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CKSS(x) ((x) << 17)
0075 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSWCK BIT(16)
0076 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSW   BIT(15)
0077 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CSMPS(x)    ((x) << 13)
0078 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_SLV(x)  ((x) << 10)
0079 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOSTCK(x)  ((x) << 8)
0080 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOST(x)    ((x) << 6)
0081 #define SUN8I_HDMI_PHY_ANA_CFG2_REG_RESDI(x)    ((x) << 0)
0082 
0083 #define SUN8I_HDMI_PHY_ANA_CFG3_REG 0x0028
0084 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOWCK(x)   ((x) << 30)
0085 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOW(x) ((x) << 28)
0086 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_WIRE(x) ((x) << 18)
0087 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMPCK(x)    ((x) << 14)
0088 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMPCK(x)    ((x) << 11)
0089 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMP(x)  ((x) << 7)
0090 #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMP(x)  ((x) << 4)
0091 #define SUN8I_HDMI_PHY_ANA_CFG3_SDAPD       BIT(3)
0092 #define SUN8I_HDMI_PHY_ANA_CFG3_SDAEN       BIT(2)
0093 #define SUN8I_HDMI_PHY_ANA_CFG3_SCLPD       BIT(1)
0094 #define SUN8I_HDMI_PHY_ANA_CFG3_SCLEN       BIT(0)
0095 
0096 #define SUN8I_HDMI_PHY_PLL_CFG1_REG 0x002c
0097 #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD1     BIT(31)
0098 #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD      BIT(30)
0099 #define SUN8I_HDMI_PHY_PLL_CFG1_LDO2_EN     BIT(29)
0100 #define SUN8I_HDMI_PHY_PLL_CFG1_LDO1_EN     BIT(28)
0101 #define SUN8I_HDMI_PHY_PLL_CFG1_HV_IS_33    BIT(27)
0102 #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_MSK    BIT(26)
0103 #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_SHIFT  26
0104 #define SUN8I_HDMI_PHY_PLL_CFG1_PLLEN       BIT(25)
0105 #define SUN8I_HDMI_PHY_PLL_CFG1_LDO_VSET(x) ((x) << 22)
0106 #define SUN8I_HDMI_PHY_PLL_CFG1_UNKNOWN(x)  ((x) << 20)
0107 #define SUN8I_HDMI_PHY_PLL_CFG1_PLLDBEN     BIT(19)
0108 #define SUN8I_HDMI_PHY_PLL_CFG1_CS      BIT(18)
0109 #define SUN8I_HDMI_PHY_PLL_CFG1_CP_S(x)     ((x) << 13)
0110 #define SUN8I_HDMI_PHY_PLL_CFG1_CNT_INT(x)  ((x) << 7)
0111 #define SUN8I_HDMI_PHY_PLL_CFG1_BWS     BIT(6)
0112 #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_MSK    GENMASK(5, 0)
0113 #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_SHIFT  0
0114 
0115 #define SUN8I_HDMI_PHY_PLL_CFG2_REG 0x0030
0116 #define SUN8I_HDMI_PHY_PLL_CFG2_SV_H        BIT(31)
0117 #define SUN8I_HDMI_PHY_PLL_CFG2_PDCLKSEL(x) ((x) << 29)
0118 #define SUN8I_HDMI_PHY_PLL_CFG2_CLKSTEP(x)  ((x) << 27)
0119 #define SUN8I_HDMI_PHY_PLL_CFG2_PSET(x)     ((x) << 24)
0120 #define SUN8I_HDMI_PHY_PLL_CFG2_PCLK_SEL    BIT(23)
0121 #define SUN8I_HDMI_PHY_PLL_CFG2_AUTOSYNC_DIS    BIT(22)
0122 #define SUN8I_HDMI_PHY_PLL_CFG2_VREG2_OUT_EN    BIT(21)
0123 #define SUN8I_HDMI_PHY_PLL_CFG2_VREG1_OUT_EN    BIT(20)
0124 #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN_EN  BIT(19)
0125 #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN(x)  ((x) << 16)
0126 #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_S(x)    ((x) << 12)
0127 #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_RST_IN  BIT(11)
0128 #define SUN8I_HDMI_PHY_PLL_CFG2_SINT_FRAC   BIT(10)
0129 #define SUN8I_HDMI_PHY_PLL_CFG2_SDIV2       BIT(9)
0130 #define SUN8I_HDMI_PHY_PLL_CFG2_S(x)        ((x) << 6)
0131 #define SUN8I_HDMI_PHY_PLL_CFG2_S6P25_7P5   BIT(5)
0132 #define SUN8I_HDMI_PHY_PLL_CFG2_S5_7        BIT(4)
0133 #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_MSK  GENMASK(3, 0)
0134 #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_SHIFT    0
0135 #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV(x)   (((x) - 1) << 0)
0136 
0137 #define SUN8I_HDMI_PHY_PLL_CFG3_REG 0x0034
0138 #define SUN8I_HDMI_PHY_PLL_CFG3_SOUT_DIV2   BIT(0)
0139 
0140 #define SUN8I_HDMI_PHY_ANA_STS_REG  0x0038
0141 #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_SHIFT  11
0142 #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_MSK    GENMASK(16, 11)
0143 #define SUN8I_HDMI_PHY_ANA_STS_RCALEND2D    BIT(7)
0144 #define SUN8I_HDMI_PHY_ANA_STS_RCAL_MASK    GENMASK(5, 0)
0145 
0146 #define SUN8I_HDMI_PHY_CEC_REG      0x003c
0147 
0148 struct sun8i_hdmi_phy;
0149 
0150 struct sun8i_hdmi_phy_variant {
0151     bool has_phy_clk;
0152     bool has_second_pll;
0153     const struct dw_hdmi_curr_ctrl *cur_ctr;
0154     const struct dw_hdmi_mpll_config *mpll_cfg;
0155     const struct dw_hdmi_phy_config *phy_cfg;
0156     const struct dw_hdmi_phy_ops *phy_ops;
0157     void (*phy_init)(struct sun8i_hdmi_phy *phy);
0158 };
0159 
0160 struct sun8i_hdmi_phy {
0161     struct clk          *clk_bus;
0162     struct clk          *clk_mod;
0163     struct clk          *clk_phy;
0164     struct clk          *clk_pll0;
0165     struct clk          *clk_pll1;
0166     struct device           *dev;
0167     unsigned int            rcal;
0168     struct regmap           *regs;
0169     struct reset_control        *rst_phy;
0170     const struct sun8i_hdmi_phy_variant *variant;
0171 };
0172 
0173 struct sun8i_dw_hdmi_quirks {
0174     enum drm_mode_status (*mode_valid)(struct dw_hdmi *hdmi, void *data,
0175                        const struct drm_display_info *info,
0176                        const struct drm_display_mode *mode);
0177     unsigned int use_drm_infoframe : 1;
0178 };
0179 
0180 struct sun8i_dw_hdmi {
0181     struct clk          *clk_tmds;
0182     struct device           *dev;
0183     struct dw_hdmi          *hdmi;
0184     struct drm_encoder      encoder;
0185     struct sun8i_hdmi_phy       *phy;
0186     struct dw_hdmi_plat_data    plat_data;
0187     struct regulator        *regulator;
0188     const struct sun8i_dw_hdmi_quirks *quirks;
0189     struct reset_control        *rst_ctrl;
0190 };
0191 
0192 extern struct platform_driver sun8i_hdmi_phy_driver;
0193 
0194 static inline struct sun8i_dw_hdmi *
0195 encoder_to_sun8i_dw_hdmi(struct drm_encoder *encoder)
0196 {
0197     return container_of(encoder, struct sun8i_dw_hdmi, encoder);
0198 }
0199 
0200 int sun8i_hdmi_phy_get(struct sun8i_dw_hdmi *hdmi, struct device_node *node);
0201 
0202 int sun8i_hdmi_phy_init(struct sun8i_hdmi_phy *phy);
0203 void sun8i_hdmi_phy_deinit(struct sun8i_hdmi_phy *phy);
0204 void sun8i_hdmi_phy_set_ops(struct sun8i_hdmi_phy *phy,
0205                 struct dw_hdmi_plat_data *plat_data);
0206 
0207 int sun8i_phy_clk_create(struct sun8i_hdmi_phy *phy, struct device *dev,
0208              bool second_parent);
0209 
0210 #endif /* _SUN8I_DW_HDMI_H_ */