xref: /openbmc/linux/drivers/gpu/drm/sun4i/sun8i_dw_hdmi.h (revision 4f2c0a4acffbec01079c28f839422e64ddeff004)
1b7c7436aSJernej Skrabec /* SPDX-License-Identifier: GPL-2.0+ */
2b7c7436aSJernej Skrabec /*
3b7c7436aSJernej Skrabec  * Copyright (C) 2018 Jernej Skrabec <jernej.skrabec@siol.net>
4b7c7436aSJernej Skrabec  */
5b7c7436aSJernej Skrabec 
6b7c7436aSJernej Skrabec #ifndef _SUN8I_DW_HDMI_H_
7b7c7436aSJernej Skrabec #define _SUN8I_DW_HDMI_H_
8b7c7436aSJernej Skrabec 
9b7c7436aSJernej Skrabec #include <drm/bridge/dw_hdmi.h>
10b7c7436aSJernej Skrabec #include <drm/drm_encoder.h>
11b7c7436aSJernej Skrabec #include <linux/clk.h>
12b7c7436aSJernej Skrabec #include <linux/regmap.h>
13633ba1e0SJernej Skrabec #include <linux/regulator/consumer.h>
14b7c7436aSJernej Skrabec #include <linux/reset.h>
15b7c7436aSJernej Skrabec 
166876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_REG	0x0000
176876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_PX_LOCK		BIT(0)
186876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_POL_MASK	GENMASK(15, 8)
196876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NHSYNC	BIT(8)
206876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_POL_NVSYNC	BIT(9)
216876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR_MASK	GENMASK(23, 16)
226876b160SJernej Skrabec #define SUN8I_HDMI_PHY_DBG_CTRL_ADDR(addr)	(addr << 16)
236876b160SJernej Skrabec 
246876b160SJernej Skrabec #define SUN8I_HDMI_PHY_REXT_CTRL_REG	0x0004
256876b160SJernej Skrabec #define SUN8I_HDMI_PHY_REXT_CTRL_REXT_EN	BIT(31)
266876b160SJernej Skrabec 
276876b160SJernej Skrabec #define SUN8I_HDMI_PHY_READ_EN_REG	0x0010
286876b160SJernej Skrabec #define SUN8I_HDMI_PHY_READ_EN_MAGIC		0x54524545
296876b160SJernej Skrabec 
306876b160SJernej Skrabec #define SUN8I_HDMI_PHY_UNSCRAMBLE_REG	0x0014
316876b160SJernej Skrabec #define SUN8I_HDMI_PHY_UNSCRAMBLE_MAGIC		0x42494E47
326876b160SJernej Skrabec 
336876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG	0x0020
346876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SWI		BIT(31)
356876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWEND	BIT(30)
366876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_PWENC	BIT(29)
376876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_CALSW	BIT(28)
386876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVRCAL(x)	((x) << 26)
396876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SVBH(x)	((x) << 24)
406876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_AMP_OPT		BIT(23)
416876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_EMP_OPT		BIT(22)
426876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_AMPCK_OPT	BIT(21)
436876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_EMPCK_OPT	BIT(20)
446876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENRCAL		BIT(19)
456876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENCALOG		BIT(18)
466876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_REG_SCKTMDS	BIT(17)
476876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_TMDSCLK_EN	BIT(16)
486876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_MASK	GENMASK(15, 12)
496876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_TXEN_ALL	(0xf << 12)
506876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDSCLK	BIT(11)
516876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS2	BIT(10)
526876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS1	BIT(9)
536876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_BIASEN_TMDS0	BIT(8)
546876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDSCLK	BIT(7)
556876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS2	BIT(6)
566876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS1	BIT(5)
576876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENP2S_TMDS0	BIT(4)
586876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_CKEN		BIT(3)
596876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_LDOEN		BIT(2)
606876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENVBS		BIT(1)
616876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG1_ENBI		BIT(0)
626876b160SJernej Skrabec 
636876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG	0x0024
646876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_M_EN		BIT(31)
656876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_PLLDBEN		BIT(30)
666876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_SEN		BIT(29)
676876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDPD	BIT(28)
686876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_HPDEN	BIT(27)
696876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLRCK	BIT(26)
706876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_PLR(x)	((x) << 23)
716876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DENCK	BIT(22)
726876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_DEN		BIT(21)
736876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CD(x)	((x) << 19)
746876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CKSS(x)	((x) << 17)
756876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSWCK	BIT(16)
766876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BIGSW	BIT(15)
776876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_CSMPS(x)	((x) << 13)
786876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_SLV(x)	((x) << 10)
796876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOSTCK(x)	((x) << 8)
806876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_BOOST(x)	((x) << 6)
816876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG2_REG_RESDI(x)	((x) << 0)
826876b160SJernej Skrabec 
836876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG	0x0028
846876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOWCK(x)	((x) << 30)
856876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_SLOW(x)	((x) << 28)
866876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_WIRE(x)	((x) << 18)
876876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMPCK(x)	((x) << 14)
886876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMPCK(x)	((x) << 11)
896876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_AMP(x)	((x) << 7)
906876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_REG_EMP(x)	((x) << 4)
916876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_SDAPD		BIT(3)
926876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_SDAEN		BIT(2)
936876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_SCLPD		BIT(1)
946876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_CFG3_SCLEN		BIT(0)
956876b160SJernej Skrabec 
966876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_REG	0x002c
976876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD1		BIT(31)
986876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_REG_OD		BIT(30)
996876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_LDO2_EN		BIT(29)
1006876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_LDO1_EN		BIT(28)
1016876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_HV_IS_33	BIT(27)
10209f380e3SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_MSK	BIT(26)
103c891a65aSJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_CKIN_SEL_SHIFT	26
1046876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_PLLEN		BIT(25)
1056876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_LDO_VSET(x)	((x) << 22)
1066876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_UNKNOWN(x)	((x) << 20)
1076876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_PLLDBEN		BIT(19)
1086876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_CS		BIT(18)
1096876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_CP_S(x)		((x) << 13)
1106876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_CNT_INT(x)	((x) << 7)
1116876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_BWS		BIT(6)
1126876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_MSK	GENMASK(5, 0)
1136876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG1_B_IN_SHIFT	0
1146876b160SJernej Skrabec 
1156876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_REG	0x0030
1166876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_SV_H		BIT(31)
1176876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PDCLKSEL(x)	((x) << 29)
1186876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_CLKSTEP(x)	((x) << 27)
1196876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PSET(x)		((x) << 24)
1206876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PCLK_SEL	BIT(23)
1216876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_AUTOSYNC_DIS	BIT(22)
1226876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VREG2_OUT_EN	BIT(21)
1236876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VREG1_OUT_EN	BIT(20)
1246876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN_EN	BIT(19)
1256876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VCOGAIN(x)	((x) << 16)
1266876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_S(x)	((x) << 12)
1276876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_VCO_RST_IN	BIT(11)
1286876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_SINT_FRAC	BIT(10)
1296876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_SDIV2		BIT(9)
1306876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_S(x)		((x) << 6)
1316876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_S6P25_7P5	BIT(5)
1326876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_S5_7		BIT(4)
1336876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_MSK	GENMASK(3, 0)
1346876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV_SHIFT	0
1356876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG2_PREDIV(x)	(((x) - 1) << 0)
1366876b160SJernej Skrabec 
1376876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG3_REG	0x0034
1386876b160SJernej Skrabec #define SUN8I_HDMI_PHY_PLL_CFG3_SOUT_DIV2	BIT(0)
1396876b160SJernej Skrabec 
1406876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_STS_REG	0x0038
1416876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_SHIFT	11
1426876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_STS_B_OUT_MSK	GENMASK(16, 11)
1436876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_STS_RCALEND2D	BIT(7)
1446876b160SJernej Skrabec #define SUN8I_HDMI_PHY_ANA_STS_RCAL_MASK	GENMASK(5, 0)
1456876b160SJernej Skrabec 
1466876b160SJernej Skrabec #define SUN8I_HDMI_PHY_CEC_REG		0x003c
1476876b160SJernej Skrabec 
1486fd90310SJernej Skrabec struct sun8i_hdmi_phy;
1496fd90310SJernej Skrabec 
1506fd90310SJernej Skrabec struct sun8i_hdmi_phy_variant {
1514f86e817SJernej Skrabec 	bool has_phy_clk;
152aef13fd8SJernej Skrabec 	bool has_second_pll;
153c71c9b2fSJernej Skrabec 	const struct dw_hdmi_curr_ctrl *cur_ctr;
154c71c9b2fSJernej Skrabec 	const struct dw_hdmi_mpll_config *mpll_cfg;
155c71c9b2fSJernej Skrabec 	const struct dw_hdmi_phy_config *phy_cfg;
156*cdf3e5e1SSamuel Holland 	const struct dw_hdmi_phy_ops *phy_ops;
1576fd90310SJernej Skrabec 	void (*phy_init)(struct sun8i_hdmi_phy *phy);
1586fd90310SJernej Skrabec };
1596fd90310SJernej Skrabec 
160b7c7436aSJernej Skrabec struct sun8i_hdmi_phy {
161b7c7436aSJernej Skrabec 	struct clk			*clk_bus;
162b7c7436aSJernej Skrabec 	struct clk			*clk_mod;
1634f86e817SJernej Skrabec 	struct clk			*clk_phy;
1644f86e817SJernej Skrabec 	struct clk			*clk_pll0;
165aef13fd8SJernej Skrabec 	struct clk			*clk_pll1;
166c64c8e04SJernej Skrabec 	struct device			*dev;
1674f86e817SJernej Skrabec 	unsigned int			rcal;
168b7c7436aSJernej Skrabec 	struct regmap			*regs;
169b7c7436aSJernej Skrabec 	struct reset_control		*rst_phy;
1701a395a56SSamuel Holland 	const struct sun8i_hdmi_phy_variant *variant;
171b7c7436aSJernej Skrabec };
172b7c7436aSJernej Skrabec 
17379971521SJernej Skrabec struct sun8i_dw_hdmi_quirks {
17496591a4bSLaurent Pinchart 	enum drm_mode_status (*mode_valid)(struct dw_hdmi *hdmi, void *data,
175af05bba0SLaurent Pinchart 					   const struct drm_display_info *info,
17679971521SJernej Skrabec 					   const struct drm_display_mode *mode);
177c8ff6405SJonas Karlman 	unsigned int use_drm_infoframe : 1;
17879971521SJernej Skrabec };
17979971521SJernej Skrabec 
180b7c7436aSJernej Skrabec struct sun8i_dw_hdmi {
181b7c7436aSJernej Skrabec 	struct clk			*clk_tmds;
182b7c7436aSJernej Skrabec 	struct device			*dev;
183b7c7436aSJernej Skrabec 	struct dw_hdmi			*hdmi;
184b7c7436aSJernej Skrabec 	struct drm_encoder		encoder;
185b7c7436aSJernej Skrabec 	struct sun8i_hdmi_phy		*phy;
186b7c7436aSJernej Skrabec 	struct dw_hdmi_plat_data	plat_data;
187633ba1e0SJernej Skrabec 	struct regulator		*regulator;
18879971521SJernej Skrabec 	const struct sun8i_dw_hdmi_quirks *quirks;
189b7c7436aSJernej Skrabec 	struct reset_control		*rst_ctrl;
190b7c7436aSJernej Skrabec };
191b7c7436aSJernej Skrabec 
1929bf37977SSaravana Kannan extern struct platform_driver sun8i_hdmi_phy_driver;
1939bf37977SSaravana Kannan 
194b7c7436aSJernej Skrabec static inline struct sun8i_dw_hdmi *
encoder_to_sun8i_dw_hdmi(struct drm_encoder * encoder)195b7c7436aSJernej Skrabec encoder_to_sun8i_dw_hdmi(struct drm_encoder *encoder)
196b7c7436aSJernej Skrabec {
197b7c7436aSJernej Skrabec 	return container_of(encoder, struct sun8i_dw_hdmi, encoder);
198b7c7436aSJernej Skrabec }
199b7c7436aSJernej Skrabec 
2009bf37977SSaravana Kannan int sun8i_hdmi_phy_get(struct sun8i_dw_hdmi *hdmi, struct device_node *node);
201b7c7436aSJernej Skrabec 
202c64c8e04SJernej Skrabec int sun8i_hdmi_phy_init(struct sun8i_hdmi_phy *phy);
203c64c8e04SJernej Skrabec void sun8i_hdmi_phy_deinit(struct sun8i_hdmi_phy *phy);
204c71c9b2fSJernej Skrabec void sun8i_hdmi_phy_set_ops(struct sun8i_hdmi_phy *phy,
205c71c9b2fSJernej Skrabec 			    struct dw_hdmi_plat_data *plat_data);
206b7c7436aSJernej Skrabec 
207c891a65aSJernej Skrabec int sun8i_phy_clk_create(struct sun8i_hdmi_phy *phy, struct device *dev,
208c891a65aSJernej Skrabec 			 bool second_parent);
2094f86e817SJernej Skrabec 
210b7c7436aSJernej Skrabec #endif /* _SUN8I_DW_HDMI_H_ */
211