18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (C) 2015 Broadcom
48c2ecf20Sopenharmony_ci * Copyright (c) 2014 The Linux Foundation. All rights reserved.
58c2ecf20Sopenharmony_ci * Copyright (C) 2013 Red Hat
68c2ecf20Sopenharmony_ci * Author: Rob Clark <robdclark@gmail.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include "vc4_hdmi.h"
108c2ecf20Sopenharmony_ci#include "vc4_regs.h"
118c2ecf20Sopenharmony_ci#include "vc4_hdmi_regs.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_PLL_RESETB	BIT(5)
148c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_PLLDIV_RESETB	BIT(4)
158c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_TX_CK_RESET	BIT(3)
168c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_TX_2_RESET	BIT(2)
178c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_TX_1_RESET	BIT(1)
188c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_RESET_CTL_TX_0_RESET	BIT(0)
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_POWERDOWN_CTL_RNDGEN_PWRDN	BIT(4)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_PREEMP_SHIFT	29
238c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_PREEMP_MASK	VC4_MASK(31, 29)
248c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_MAINDRV_SHIFT	24
258c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_MAINDRV_MASK	VC4_MASK(28, 24)
268c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_PREEMP_SHIFT	21
278c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_PREEMP_MASK	VC4_MASK(23, 21)
288c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_MAINDRV_SHIFT	16
298c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_MAINDRV_MASK	VC4_MASK(20, 16)
308c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_PREEMP_SHIFT	13
318c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_PREEMP_MASK	VC4_MASK(15, 13)
328c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_MAINDRV_SHIFT	8
338c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_MAINDRV_MASK	VC4_MASK(12, 8)
348c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_PREEMP_SHIFT	5
358c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_PREEMP_MASK	VC4_MASK(7, 5)
368c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_MAINDRV_SHIFT	0
378c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_MAINDRV_MASK	VC4_MASK(4, 0)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA2_SHIFT	15
408c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA2_MASK	VC4_MASK(19, 15)
418c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA1_SHIFT	10
428c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA1_MASK	VC4_MASK(14, 10)
438c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA0_SHIFT	5
448c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA0_MASK	VC4_MASK(9, 5)
458c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_CK_SHIFT		0
468c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_1_RES_SEL_CK_MASK		VC4_MASK(4, 0)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_VCO_GAIN_SHIFT		16
498c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_VCO_GAIN_MASK		VC4_MASK(19, 16)
508c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA2_SHIFT	12
518c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA2_MASK	VC4_MASK(15, 12)
528c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA1_SHIFT	8
538c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA1_MASK	VC4_MASK(11, 8)
548c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA0_SHIFT	4
558c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA0_MASK	VC4_MASK(7, 4)
568c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELCK_SHIFT	0
578c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELCK_MASK	VC4_MASK(3, 0)
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_RP_SHIFT			17
608c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_RP_MASK			VC4_MASK(19, 17)
618c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_RZ_SHIFT			12
628c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_RZ_MASK			VC4_MASK(16, 12)
638c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CP1_SHIFT			10
648c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CP1_MASK			VC4_MASK(11, 10)
658c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CP_SHIFT			8
668c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CP_MASK			VC4_MASK(9, 8)
678c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CZ_SHIFT			6
688c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_CZ_MASK			VC4_MASK(7, 6)
698c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_ICP_SHIFT			0
708c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CTL_3_ICP_MASK			VC4_MASK(5, 0)
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_MASH11_MODE		BIT(13)
738c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VC_RANGE_EN		BIT(12)
748c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_EMULATE_VC_LOW	BIT(11)
758c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_EMULATE_VC_HIGH	BIT(10)
768c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_SEL_SHIFT		9
778c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_SEL_MASK		VC4_MASK(9, 9)
788c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_FB_DIV2		BIT(8)
798c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_POST_DIV2		BIT(7)
808c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_CONT_EN		BIT(6)
818c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_0_ENA_VCO_CLK		BIT(5)
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_CPP_SHIFT			16
848c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_CPP_MASK			VC4_MASK(27, 16)
858c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_FREQ_DOUBLER_DELAY_SHIFT	14
868c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_FREQ_DOUBLER_DELAY_MASK	VC4_MASK(15, 14)
878c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_FREQ_DOUBLER_ENABLE		BIT(13)
888c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_POST_RST_SEL_SHIFT		11
898c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CTL_1_POST_RST_SEL_MASK		VC4_MASK(12, 11)
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CLK_DIV_VCO_SHIFT		8
928c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CLK_DIV_VCO_MASK		VC4_MASK(15, 8)
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CFG_PDIV_SHIFT		0
958c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CFG_PDIV_MASK		VC4_MASK(3, 0)
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TXCK_OUT_SEL_MASK	VC4_MASK(13, 12)
988c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TXCK_OUT_SEL_SHIFT	12
998c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX2_OUT_SEL_MASK	VC4_MASK(9, 8)
1008c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX2_OUT_SEL_SHIFT	8
1018c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX1_OUT_SEL_MASK	VC4_MASK(5, 4)
1028c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX1_OUT_SEL_SHIFT	4
1038c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX0_OUT_SEL_MASK	VC4_MASK(1, 0)
1048c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX0_OUT_SEL_SHIFT	0
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1_MIN_LIMIT_MASK		VC4_MASK(27, 0)
1078c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1_MIN_LIMIT_SHIFT	0
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2_MAX_LIMIT_MASK		VC4_MASK(27, 0)
1108c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2_MAX_LIMIT_SHIFT	0
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_STABLE_THRESHOLD_MASK	VC4_MASK(31, 16)
1138c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_STABLE_THRESHOLD_SHIFT	16
1148c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_HOLD_THRESHOLD_MASK	VC4_MASK(15, 0)
1158c2ecf20Sopenharmony_ci#define VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_HOLD_THRESHOLD_SHIFT	0
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_CONTROL_EN_FREEZE_COUNTERS		BIT(19)
1188c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_CONTROL_EN_LOAD_INTEGRATOR		BIT(17)
1198c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_CONTROL_FREE_RUN			BIT(4)
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_OFFSET_ONLY				BIT(31)
1228c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_OFFSET_OFFSET_SHIFT			0
1238c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_OFFSET_OFFSET_MASK			VC4_MASK(30, 0)
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_FORMAT_SHIFT_SHIFT			24
1268c2ecf20Sopenharmony_ci#define VC4_HDMI_RM_FORMAT_SHIFT_MASK			VC4_MASK(25, 24)
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define OSCILLATOR_FREQUENCY	54000000
1298c2ecf20Sopenharmony_ci
1308c2ecf20Sopenharmony_civoid vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, struct drm_display_mode *mode)
1318c2ecf20Sopenharmony_ci{
1328c2ecf20Sopenharmony_ci	/* PHY should be in reset, like
1338c2ecf20Sopenharmony_ci	 * vc4_hdmi_encoder_disable() does.
1348c2ecf20Sopenharmony_ci	 */
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL, 0xf << 16);
1378c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL, 0);
1388c2ecf20Sopenharmony_ci}
1398c2ecf20Sopenharmony_ci
1408c2ecf20Sopenharmony_civoid vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi)
1418c2ecf20Sopenharmony_ci{
1428c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL, 0xf << 16);
1438c2ecf20Sopenharmony_ci}
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_civoid vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi)
1468c2ecf20Sopenharmony_ci{
1478c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_0,
1488c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_CTL_0) &
1498c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_RNG_PWRDN);
1508c2ecf20Sopenharmony_ci}
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_civoid vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi)
1538c2ecf20Sopenharmony_ci{
1548c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_0,
1558c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_CTL_0) |
1568c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_RNG_PWRDN);
1578c2ecf20Sopenharmony_ci}
1588c2ecf20Sopenharmony_ci
1598c2ecf20Sopenharmony_cistatic unsigned long long
1608c2ecf20Sopenharmony_ciphy_get_vco_freq(unsigned long long clock, u8 *vco_sel, u8 *vco_div)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	unsigned long long vco_freq = clock;
1638c2ecf20Sopenharmony_ci	unsigned int _vco_div = 0;
1648c2ecf20Sopenharmony_ci	unsigned int _vco_sel = 0;
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci	while (vco_freq < 3000000000ULL) {
1678c2ecf20Sopenharmony_ci		_vco_div++;
1688c2ecf20Sopenharmony_ci		vco_freq = clock * _vco_div * 10;
1698c2ecf20Sopenharmony_ci	}
1708c2ecf20Sopenharmony_ci
1718c2ecf20Sopenharmony_ci	if (vco_freq > 4500000000ULL)
1728c2ecf20Sopenharmony_ci		_vco_sel = 1;
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_ci	*vco_sel = _vco_sel;
1758c2ecf20Sopenharmony_ci	*vco_div = _vco_div;
1768c2ecf20Sopenharmony_ci
1778c2ecf20Sopenharmony_ci	return vco_freq;
1788c2ecf20Sopenharmony_ci}
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic u8 phy_get_cp_current(unsigned long vco_freq)
1818c2ecf20Sopenharmony_ci{
1828c2ecf20Sopenharmony_ci	if (vco_freq < 3700000000ULL)
1838c2ecf20Sopenharmony_ci		return 0x1c;
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci	return 0x18;
1868c2ecf20Sopenharmony_ci}
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_cistatic u32 phy_get_rm_offset(unsigned long long vco_freq)
1898c2ecf20Sopenharmony_ci{
1908c2ecf20Sopenharmony_ci	unsigned long long fref = OSCILLATOR_FREQUENCY;
1918c2ecf20Sopenharmony_ci	u64 offset = 0;
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci	/* RM offset is stored as 9.22 format */
1948c2ecf20Sopenharmony_ci	offset = vco_freq * 2;
1958c2ecf20Sopenharmony_ci	offset = offset << 22;
1968c2ecf20Sopenharmony_ci	do_div(offset, fref);
1978c2ecf20Sopenharmony_ci	offset >>= 2;
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci	return offset;
2008c2ecf20Sopenharmony_ci}
2018c2ecf20Sopenharmony_ci
2028c2ecf20Sopenharmony_cistatic u8 phy_get_vco_gain(unsigned long long vco_freq)
2038c2ecf20Sopenharmony_ci{
2048c2ecf20Sopenharmony_ci	if (vco_freq < 3350000000ULL)
2058c2ecf20Sopenharmony_ci		return 0xf;
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci	if (vco_freq < 3700000000ULL)
2088c2ecf20Sopenharmony_ci		return 0xc;
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci	if (vco_freq < 4050000000ULL)
2118c2ecf20Sopenharmony_ci		return 0x6;
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_ci	if (vco_freq < 4800000000ULL)
2148c2ecf20Sopenharmony_ci		return 0x5;
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci	if (vco_freq < 5200000000ULL)
2178c2ecf20Sopenharmony_ci		return 0x7;
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci	return 0x2;
2208c2ecf20Sopenharmony_ci}
2218c2ecf20Sopenharmony_ci
2228c2ecf20Sopenharmony_cistruct phy_lane_settings {
2238c2ecf20Sopenharmony_ci	struct {
2248c2ecf20Sopenharmony_ci		u8 preemphasis;
2258c2ecf20Sopenharmony_ci		u8 main_driver;
2268c2ecf20Sopenharmony_ci	} amplitude;
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci	u8 res_sel_data;
2298c2ecf20Sopenharmony_ci	u8 term_res_sel_data;
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistruct phy_settings {
2338c2ecf20Sopenharmony_ci	unsigned long long min_rate;
2348c2ecf20Sopenharmony_ci	unsigned long long max_rate;
2358c2ecf20Sopenharmony_ci	struct phy_lane_settings channel[3];
2368c2ecf20Sopenharmony_ci	struct phy_lane_settings clock;
2378c2ecf20Sopenharmony_ci};
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistatic const struct phy_settings vc5_hdmi_phy_settings[] = {
2408c2ecf20Sopenharmony_ci	{
2418c2ecf20Sopenharmony_ci		0, 50000000,
2428c2ecf20Sopenharmony_ci		{
2438c2ecf20Sopenharmony_ci			{{0x0, 0x0A}, 0x12, 0x0},
2448c2ecf20Sopenharmony_ci			{{0x0, 0x0A}, 0x12, 0x0},
2458c2ecf20Sopenharmony_ci			{{0x0, 0x0A}, 0x12, 0x0}
2468c2ecf20Sopenharmony_ci		},
2478c2ecf20Sopenharmony_ci		{{0x0, 0x0A}, 0x18, 0x0},
2488c2ecf20Sopenharmony_ci	},
2498c2ecf20Sopenharmony_ci	{
2508c2ecf20Sopenharmony_ci		50000001, 75000000,
2518c2ecf20Sopenharmony_ci		{
2528c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0},
2538c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0},
2548c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0}
2558c2ecf20Sopenharmony_ci		},
2568c2ecf20Sopenharmony_ci		{{0x0, 0x0C}, 0x18, 0x3},
2578c2ecf20Sopenharmony_ci	},
2588c2ecf20Sopenharmony_ci	{
2598c2ecf20Sopenharmony_ci		75000001,   165000000,
2608c2ecf20Sopenharmony_ci		{
2618c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0},
2628c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0},
2638c2ecf20Sopenharmony_ci			{{0x0, 0x09}, 0x12, 0x0}
2648c2ecf20Sopenharmony_ci		},
2658c2ecf20Sopenharmony_ci		{{0x0, 0x0C}, 0x18, 0x3},
2668c2ecf20Sopenharmony_ci	},
2678c2ecf20Sopenharmony_ci	{
2688c2ecf20Sopenharmony_ci		165000001,  250000000,
2698c2ecf20Sopenharmony_ci		{
2708c2ecf20Sopenharmony_ci			{{0x0, 0x0F}, 0x12, 0x1},
2718c2ecf20Sopenharmony_ci			{{0x0, 0x0F}, 0x12, 0x1},
2728c2ecf20Sopenharmony_ci			{{0x0, 0x0F}, 0x12, 0x1}
2738c2ecf20Sopenharmony_ci		},
2748c2ecf20Sopenharmony_ci		{{0x0, 0x0C}, 0x18, 0x3},
2758c2ecf20Sopenharmony_ci	},
2768c2ecf20Sopenharmony_ci	{
2778c2ecf20Sopenharmony_ci		250000001,  340000000,
2788c2ecf20Sopenharmony_ci		{
2798c2ecf20Sopenharmony_ci			{{0x2, 0x0D}, 0x12, 0x1},
2808c2ecf20Sopenharmony_ci			{{0x2, 0x0D}, 0x12, 0x1},
2818c2ecf20Sopenharmony_ci			{{0x2, 0x0D}, 0x12, 0x1}
2828c2ecf20Sopenharmony_ci		},
2838c2ecf20Sopenharmony_ci		{{0x0, 0x0C}, 0x18, 0xF},
2848c2ecf20Sopenharmony_ci	},
2858c2ecf20Sopenharmony_ci	{
2868c2ecf20Sopenharmony_ci		340000001,  450000000,
2878c2ecf20Sopenharmony_ci		{
2888c2ecf20Sopenharmony_ci			{{0x0, 0x1B}, 0x12, 0xF},
2898c2ecf20Sopenharmony_ci			{{0x0, 0x1B}, 0x12, 0xF},
2908c2ecf20Sopenharmony_ci			{{0x0, 0x1B}, 0x12, 0xF}
2918c2ecf20Sopenharmony_ci		},
2928c2ecf20Sopenharmony_ci		{{0x0, 0x0A}, 0x12, 0xF},
2938c2ecf20Sopenharmony_ci	},
2948c2ecf20Sopenharmony_ci	{
2958c2ecf20Sopenharmony_ci		450000001,  600000000,
2968c2ecf20Sopenharmony_ci		{
2978c2ecf20Sopenharmony_ci			{{0x0, 0x1C}, 0x12, 0xF},
2988c2ecf20Sopenharmony_ci			{{0x0, 0x1C}, 0x12, 0xF},
2998c2ecf20Sopenharmony_ci			{{0x0, 0x1C}, 0x12, 0xF}
3008c2ecf20Sopenharmony_ci		},
3018c2ecf20Sopenharmony_ci		{{0x0, 0x0B}, 0x13, 0xF},
3028c2ecf20Sopenharmony_ci	},
3038c2ecf20Sopenharmony_ci};
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_cistatic const struct phy_settings *phy_get_settings(unsigned long long tmds_rate)
3068c2ecf20Sopenharmony_ci{
3078c2ecf20Sopenharmony_ci	unsigned int count = ARRAY_SIZE(vc5_hdmi_phy_settings);
3088c2ecf20Sopenharmony_ci	unsigned int i;
3098c2ecf20Sopenharmony_ci
3108c2ecf20Sopenharmony_ci	for (i = 0; i < count; i++) {
3118c2ecf20Sopenharmony_ci		const struct phy_settings *s = &vc5_hdmi_phy_settings[i];
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_ci		if (tmds_rate >= s->min_rate && tmds_rate <= s->max_rate)
3148c2ecf20Sopenharmony_ci			return s;
3158c2ecf20Sopenharmony_ci	}
3168c2ecf20Sopenharmony_ci
3178c2ecf20Sopenharmony_ci	/*
3188c2ecf20Sopenharmony_ci	 * If the pixel clock exceeds our max setting, try the max
3198c2ecf20Sopenharmony_ci	 * setting anyway.
3208c2ecf20Sopenharmony_ci	 */
3218c2ecf20Sopenharmony_ci	return &vc5_hdmi_phy_settings[count - 1];
3228c2ecf20Sopenharmony_ci}
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic const struct phy_lane_settings *
3258c2ecf20Sopenharmony_ciphy_get_channel_settings(enum vc4_hdmi_phy_channel chan,
3268c2ecf20Sopenharmony_ci			 unsigned long long tmds_rate)
3278c2ecf20Sopenharmony_ci{
3288c2ecf20Sopenharmony_ci	const struct phy_settings *settings = phy_get_settings(tmds_rate);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_ci	if (chan == PHY_LANE_CK)
3318c2ecf20Sopenharmony_ci		return &settings->clock;
3328c2ecf20Sopenharmony_ci
3338c2ecf20Sopenharmony_ci	return &settings->channel[chan];
3348c2ecf20Sopenharmony_ci}
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_cistatic void vc5_hdmi_reset_phy(struct vc4_hdmi *vc4_hdmi)
3378c2ecf20Sopenharmony_ci{
3388c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL, 0x0f);
3398c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_POWERDOWN_CTL, BIT(10));
3408c2ecf20Sopenharmony_ci}
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_civoid vc5_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi, struct drm_display_mode *mode)
3438c2ecf20Sopenharmony_ci{
3448c2ecf20Sopenharmony_ci	const struct phy_lane_settings *chan0_settings, *chan1_settings, *chan2_settings, *clock_settings;
3458c2ecf20Sopenharmony_ci	const struct vc4_hdmi_variant *variant = vc4_hdmi->variant;
3468c2ecf20Sopenharmony_ci	unsigned long long pixel_freq = mode->clock * 1000;
3478c2ecf20Sopenharmony_ci	unsigned long long vco_freq;
3488c2ecf20Sopenharmony_ci	unsigned char word_sel;
3498c2ecf20Sopenharmony_ci	u8 vco_sel, vco_div;
3508c2ecf20Sopenharmony_ci
3518c2ecf20Sopenharmony_ci	vco_freq = phy_get_vco_freq(pixel_freq, &vco_sel, &vco_div);
3528c2ecf20Sopenharmony_ci
3538c2ecf20Sopenharmony_ci	vc5_hdmi_reset_phy(vc4_hdmi);
3548c2ecf20Sopenharmony_ci
3558c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_POWERDOWN_CTL,
3568c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_POWERDOWN_CTL_RNDGEN_PWRDN);
3578c2ecf20Sopenharmony_ci
3588c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL,
3598c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_RESET_CTL) &
3608c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_RESET_CTL_TX_0_RESET &
3618c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_RESET_CTL_TX_1_RESET &
3628c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_RESET_CTL_TX_2_RESET &
3638c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_RESET_CTL_TX_CK_RESET);
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_RM_CONTROL,
3668c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_RM_CONTROL) |
3678c2ecf20Sopenharmony_ci		   VC4_HDMI_RM_CONTROL_EN_FREEZE_COUNTERS |
3688c2ecf20Sopenharmony_ci		   VC4_HDMI_RM_CONTROL_EN_LOAD_INTEGRATOR |
3698c2ecf20Sopenharmony_ci		   VC4_HDMI_RM_CONTROL_FREE_RUN);
3708c2ecf20Sopenharmony_ci
3718c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1,
3728c2ecf20Sopenharmony_ci		   (HDMI_READ(HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1) &
3738c2ecf20Sopenharmony_ci		    ~VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1_MIN_LIMIT_MASK) |
3748c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(0, VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_1_MIN_LIMIT));
3758c2ecf20Sopenharmony_ci
3768c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2,
3778c2ecf20Sopenharmony_ci		   (HDMI_READ(HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2) &
3788c2ecf20Sopenharmony_ci		    ~VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2_MAX_LIMIT_MASK) |
3798c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(0, VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_2_MAX_LIMIT));
3808c2ecf20Sopenharmony_ci
3818c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_RM_OFFSET,
3828c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(phy_get_rm_offset(vco_freq),
3838c2ecf20Sopenharmony_ci				 VC4_HDMI_RM_OFFSET_OFFSET) |
3848c2ecf20Sopenharmony_ci		   VC4_HDMI_RM_OFFSET_ONLY);
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CLK_DIV,
3878c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(vco_div, VC4_HDMI_TX_PHY_CLK_DIV_VCO));
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4,
3908c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(0xe147, VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_HOLD_THRESHOLD) |
3918c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(0xe14, VC4_HDMI_TX_PHY_PLL_CALIBRATION_CONFIG_4_STABLE_THRESHOLD));
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CTL_0,
3948c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_PLL_CTL_0_ENA_VCO_CLK |
3958c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_CONT_EN |
3968c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_PLL_CTL_0_MASH11_MODE |
3978c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(vco_sel, VC4_HDMI_TX_PHY_PLL_CTL_0_VCO_SEL));
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CTL_1,
4008c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_PLL_CTL_1) |
4018c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_PLL_CTL_1_FREQ_DOUBLER_ENABLE |
4028c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(3, VC4_HDMI_TX_PHY_PLL_CTL_1_POST_RST_SEL) |
4038c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(1, VC4_HDMI_TX_PHY_PLL_CTL_1_FREQ_DOUBLER_DELAY) |
4048c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(0x8a, VC4_HDMI_TX_PHY_PLL_CTL_1_CPP));
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_RM_FORMAT,
4078c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_RM_FORMAT) |
4088c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(2, VC4_HDMI_RM_FORMAT_SHIFT));
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_PLL_CFG,
4118c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_PLL_CFG) |
4128c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(1, VC4_HDMI_TX_PHY_PLL_CFG_PDIV));
4138c2ecf20Sopenharmony_ci
4148c2ecf20Sopenharmony_ci	if (pixel_freq >= 340000000)
4158c2ecf20Sopenharmony_ci		word_sel = 3;
4168c2ecf20Sopenharmony_ci	else
4178c2ecf20Sopenharmony_ci		word_sel = 0;
4188c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_TMDS_CLK_WORD_SEL, word_sel);
4198c2ecf20Sopenharmony_ci
4208c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_3,
4218c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(phy_get_cp_current(vco_freq),
4228c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_3_ICP) |
4238c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(1, VC4_HDMI_TX_PHY_CTL_3_CP) |
4248c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(1, VC4_HDMI_TX_PHY_CTL_3_CP1) |
4258c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(3, VC4_HDMI_TX_PHY_CTL_3_CZ) |
4268c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(4, VC4_HDMI_TX_PHY_CTL_3_RP) |
4278c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(6, VC4_HDMI_TX_PHY_CTL_3_RZ));
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ci	chan0_settings =
4308c2ecf20Sopenharmony_ci		phy_get_channel_settings(variant->phy_lane_mapping[PHY_LANE_0],
4318c2ecf20Sopenharmony_ci					 pixel_freq);
4328c2ecf20Sopenharmony_ci	chan1_settings =
4338c2ecf20Sopenharmony_ci		phy_get_channel_settings(variant->phy_lane_mapping[PHY_LANE_1],
4348c2ecf20Sopenharmony_ci					 pixel_freq);
4358c2ecf20Sopenharmony_ci	chan2_settings =
4368c2ecf20Sopenharmony_ci		phy_get_channel_settings(variant->phy_lane_mapping[PHY_LANE_2],
4378c2ecf20Sopenharmony_ci					 pixel_freq);
4388c2ecf20Sopenharmony_ci	clock_settings =
4398c2ecf20Sopenharmony_ci		phy_get_channel_settings(variant->phy_lane_mapping[PHY_LANE_CK],
4408c2ecf20Sopenharmony_ci					 pixel_freq);
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_0,
4438c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan0_settings->amplitude.preemphasis,
4448c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_PREEMP) |
4458c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan0_settings->amplitude.main_driver,
4468c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_0_MAINDRV) |
4478c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan1_settings->amplitude.preemphasis,
4488c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_PREEMP) |
4498c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan1_settings->amplitude.main_driver,
4508c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_1_MAINDRV) |
4518c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan2_settings->amplitude.preemphasis,
4528c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_PREEMP) |
4538c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan2_settings->amplitude.main_driver,
4548c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_2_MAINDRV) |
4558c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(clock_settings->amplitude.preemphasis,
4568c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_PREEMP) |
4578c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(clock_settings->amplitude.main_driver,
4588c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_0_PREEMP_CK_MAINDRV));
4598c2ecf20Sopenharmony_ci
4608c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_1,
4618c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_CTL_1) |
4628c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan0_settings->res_sel_data,
4638c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA0) |
4648c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan1_settings->res_sel_data,
4658c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA1) |
4668c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan2_settings->res_sel_data,
4678c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_1_RES_SEL_DATA2) |
4688c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(clock_settings->res_sel_data,
4698c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_1_RES_SEL_CK));
4708c2ecf20Sopenharmony_ci
4718c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CTL_2,
4728c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan0_settings->term_res_sel_data,
4738c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA0) |
4748c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan1_settings->term_res_sel_data,
4758c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA1) |
4768c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(chan2_settings->term_res_sel_data,
4778c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELDATA2) |
4788c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(clock_settings->term_res_sel_data,
4798c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_2_TERM_RES_SELCK) |
4808c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(phy_get_vco_gain(vco_freq),
4818c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CTL_2_VCO_GAIN));
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_CHANNEL_SWAP,
4848c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(variant->phy_lane_mapping[PHY_LANE_0],
4858c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX0_OUT_SEL) |
4868c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(variant->phy_lane_mapping[PHY_LANE_1],
4878c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX1_OUT_SEL) |
4888c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(variant->phy_lane_mapping[PHY_LANE_2],
4898c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CHANNEL_SWAP_TX2_OUT_SEL) |
4908c2ecf20Sopenharmony_ci		   VC4_SET_FIELD(variant->phy_lane_mapping[PHY_LANE_CK],
4918c2ecf20Sopenharmony_ci				 VC4_HDMI_TX_PHY_CHANNEL_SWAP_TXCK_OUT_SEL));
4928c2ecf20Sopenharmony_ci
4938c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL,
4948c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_RESET_CTL) &
4958c2ecf20Sopenharmony_ci		   ~(VC4_HDMI_TX_PHY_RESET_CTL_PLL_RESETB |
4968c2ecf20Sopenharmony_ci		     VC4_HDMI_TX_PHY_RESET_CTL_PLLDIV_RESETB));
4978c2ecf20Sopenharmony_ci
4988c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_RESET_CTL,
4998c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_RESET_CTL) |
5008c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_RESET_CTL_PLL_RESETB |
5018c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_RESET_CTL_PLLDIV_RESETB);
5028c2ecf20Sopenharmony_ci}
5038c2ecf20Sopenharmony_ci
5048c2ecf20Sopenharmony_civoid vc5_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi)
5058c2ecf20Sopenharmony_ci{
5068c2ecf20Sopenharmony_ci	vc5_hdmi_reset_phy(vc4_hdmi);
5078c2ecf20Sopenharmony_ci}
5088c2ecf20Sopenharmony_ci
5098c2ecf20Sopenharmony_civoid vc5_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi)
5108c2ecf20Sopenharmony_ci{
5118c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_POWERDOWN_CTL,
5128c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_POWERDOWN_CTL) &
5138c2ecf20Sopenharmony_ci		   ~VC4_HDMI_TX_PHY_POWERDOWN_CTL_RNDGEN_PWRDN);
5148c2ecf20Sopenharmony_ci}
5158c2ecf20Sopenharmony_ci
5168c2ecf20Sopenharmony_civoid vc5_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi)
5178c2ecf20Sopenharmony_ci{
5188c2ecf20Sopenharmony_ci	HDMI_WRITE(HDMI_TX_PHY_POWERDOWN_CTL,
5198c2ecf20Sopenharmony_ci		   HDMI_READ(HDMI_TX_PHY_POWERDOWN_CTL) |
5208c2ecf20Sopenharmony_ci		   VC4_HDMI_TX_PHY_POWERDOWN_CTL_RNDGEN_PWRDN);
5218c2ecf20Sopenharmony_ci}
522