1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (c) 2021-2022 Rockchip Electronics Co., Ltd. 4 * Copyright (c) 2024 Collabora Ltd. 5 * 6 * Author: Algea Cao <algea.cao@rock-chips.com> 7 * Author: Cristian Ciocaltea <cristian.ciocaltea@collabora.com> 8 */ 9 #include <linux/bitfield.h> 10 #include <linux/clk.h> 11 #include <linux/clk-provider.h> 12 #include <linux/delay.h> 13 #include <linux/mfd/syscon.h> 14 #include <linux/module.h> 15 #include <linux/of.h> 16 #include <linux/of_platform.h> 17 #include <linux/phy/phy.h> 18 #include <linux/platform_device.h> 19 #include <linux/pm_runtime.h> 20 #include <linux/rational.h> 21 #include <linux/regmap.h> 22 #include <linux/reset.h> 23 24 #define GRF_HDPTX_CON0 0x00 25 #define HDPTX_I_PLL_EN BIT(7) 26 #define HDPTX_I_BIAS_EN BIT(6) 27 #define HDPTX_I_BGR_EN BIT(5) 28 #define HDPTX_MODE_SEL BIT(0) 29 #define GRF_HDPTX_STATUS 0x80 30 #define HDPTX_O_PLL_LOCK_DONE BIT(3) 31 #define HDPTX_O_PHY_CLK_RDY BIT(2) 32 #define HDPTX_O_PHY_RDY BIT(1) 33 #define HDPTX_O_SB_RDY BIT(0) 34 35 #define HDTPX_REG(_n, _min, _max) \ 36 ( \ 37 BUILD_BUG_ON_ZERO((0x##_n) < (0x##_min)) + \ 38 BUILD_BUG_ON_ZERO((0x##_n) > (0x##_max)) + \ 39 ((0x##_n) * 4) \ 40 ) 41 42 #define CMN_REG(n) HDTPX_REG(n, 0000, 00a7) 43 #define SB_REG(n) HDTPX_REG(n, 0100, 0129) 44 #define LNTOP_REG(n) HDTPX_REG(n, 0200, 0229) 45 #define LANE_REG(n) HDTPX_REG(n, 0300, 062d) 46 47 /* CMN_REG(0008) */ 48 #define OVRD_LCPLL_EN_MASK BIT(7) 49 #define LCPLL_EN_MASK BIT(6) 50 #define LCPLL_LCVCO_MODE_EN_MASK BIT(4) 51 /* CMN_REG(001e) */ 52 #define LCPLL_PI_EN_MASK BIT(5) 53 #define LCPLL_100M_CLK_EN_MASK BIT(0) 54 /* CMN_REG(0025) */ 55 #define LCPLL_PMS_IQDIV_RSTN_MASK BIT(4) 56 /* CMN_REG(0028) */ 57 #define LCPLL_SDC_FRAC_EN_MASK BIT(2) 58 #define LCPLL_SDC_FRAC_RSTN_MASK BIT(0) 59 /* CMN_REG(002d) */ 60 #define LCPLL_SDC_N_MASK GENMASK(3, 1) 61 /* CMN_REG(002e) */ 62 #define LCPLL_SDC_NUMBERATOR_MASK GENMASK(5, 0) 63 /* CMN_REG(002f) */ 64 #define LCPLL_SDC_DENOMINATOR_MASK GENMASK(7, 2) 65 #define LCPLL_SDC_NDIV_RSTN_MASK BIT(0) 66 /* CMN_REG(003c) */ 67 #define ANA_LCPLL_RESERVED7_MASK BIT(7) 68 /* CMN_REG(003d) */ 69 #define OVRD_ROPLL_EN_MASK BIT(7) 70 #define ROPLL_EN_MASK BIT(6) 71 #define ROPLL_LCVCO_EN_MASK BIT(4) 72 /* CMN_REG(0046) */ 73 #define ROPLL_ANA_CPP_CTRL_COARSE_MASK GENMASK(7, 4) 74 #define ROPLL_ANA_CPP_CTRL_FINE_MASK GENMASK(3, 0) 75 /* CMN_REG(0047) */ 76 #define ROPLL_ANA_LPF_C_SEL_COARSE_MASK GENMASK(5, 3) 77 #define ROPLL_ANA_LPF_C_SEL_FINE_MASK GENMASK(2, 0) 78 /* CMN_REG(004e) */ 79 #define ROPLL_PI_EN_MASK BIT(5) 80 /* CMN_REG(0051) */ 81 #define ROPLL_PMS_MDIV_MASK GENMASK(7, 0) 82 /* CMN_REG(0055) */ 83 #define ROPLL_PMS_MDIV_AFC_MASK GENMASK(7, 0) 84 /* CMN_REG(0059) */ 85 #define ANA_ROPLL_PMS_PDIV_MASK GENMASK(7, 4) 86 #define ANA_ROPLL_PMS_REFDIV_MASK GENMASK(3, 0) 87 /* CMN_REG(005a) */ 88 #define ROPLL_PMS_SDIV_RBR_MASK GENMASK(7, 4) 89 #define ROPLL_PMS_SDIV_HBR_MASK GENMASK(3, 0) 90 /* CMN_REG(005b) */ 91 #define ROPLL_PMS_SDIV_HBR2_MASK GENMASK(7, 4) 92 /* CMN_REG(005c) */ 93 #define ROPLL_PMS_IQDIV_RSTN_MASK BIT(5) 94 /* CMN_REG(005e) */ 95 #define ROPLL_SDM_EN_MASK BIT(6) 96 #define OVRD_ROPLL_SDM_RSTN_MASK BIT(5) 97 #define ROPLL_SDM_RSTN_MASK BIT(4) 98 #define ROPLL_SDC_FRAC_EN_RBR_MASK BIT(3) 99 #define ROPLL_SDC_FRAC_EN_HBR_MASK BIT(2) 100 #define ROPLL_SDC_FRAC_EN_HBR2_MASK BIT(1) 101 #define ROPLL_SDM_FRAC_EN_HBR3_MASK BIT(0) 102 /* CMN_REG(005f) */ 103 #define OVRD_ROPLL_SDC_RSTN_MASK BIT(5) 104 #define ROPLL_SDC_RSTN_MASK BIT(4) 105 /* CMN_REG(0060) */ 106 #define ROPLL_SDM_DENOMINATOR_MASK GENMASK(7, 0) 107 /* CMN_REG(0064) */ 108 #define ROPLL_SDM_NUM_SIGN_RBR_MASK BIT(3) 109 #define ROPLL_SDM_NUM_SIGN_HBR_MASK BIT(2) 110 #define ROPLL_SDM_NUM_SIGN_HBR2_MASK BIT(1) 111 /* CMN_REG(0065) */ 112 #define ROPLL_SDM_NUM_MASK GENMASK(7, 0) 113 /* CMN_REG(0069) */ 114 #define ROPLL_SDC_N_RBR_MASK GENMASK(2, 0) 115 /* CMN_REG(006a) */ 116 #define ROPLL_SDC_N_HBR_MASK GENMASK(5, 3) 117 #define ROPLL_SDC_N_HBR2_MASK GENMASK(2, 0) 118 /* CMN_REG(006b) */ 119 #define ROPLL_SDC_N_HBR3_MASK GENMASK(3, 1) 120 /* CMN_REG(006c) */ 121 #define ROPLL_SDC_NUM_MASK GENMASK(5, 0) 122 /* cmn_reg0070 */ 123 #define ROPLL_SDC_DENO_MASK GENMASK(5, 0) 124 /* CMN_REG(0074) */ 125 #define OVRD_ROPLL_SDC_NDIV_RSTN_MASK BIT(3) 126 #define ROPLL_SDC_NDIV_RSTN_MASK BIT(2) 127 #define OVRD_ROPLL_SSC_EN_MASK BIT(1) 128 #define ROPLL_SSC_EN_MASK BIT(0) 129 /* CMN_REG(0075) */ 130 #define ANA_ROPLL_SSC_FM_DEVIATION_MASK GENMASK(5, 0) 131 /* CMN_REG(0076) */ 132 #define ANA_ROPLL_SSC_FM_FREQ_MASK GENMASK(6, 2) 133 /* CMN_REG(0077) */ 134 #define ANA_ROPLL_SSC_CLK_DIV_SEL_MASK GENMASK(6, 3) 135 /* CMN_REG(0081) */ 136 #define OVRD_PLL_CD_CLK_EN_MASK BIT(8) 137 #define ANA_PLL_CD_TX_SER_RATE_SEL_MASK BIT(3) 138 #define ANA_PLL_CD_HSCLK_WEST_EN_MASK BIT(1) 139 #define ANA_PLL_CD_HSCLK_EAST_EN_MASK BIT(0) 140 /* CMN_REG(0082) */ 141 #define ANA_PLL_CD_VREG_GAIN_CTRL_MASK GENMASK(3, 0) 142 /* CMN_REG(0083) */ 143 #define ANA_PLL_CD_VREG_ICTRL_MASK GENMASK(6, 5) 144 /* CMN_REG(0084) */ 145 #define PLL_LCRO_CLK_SEL_MASK BIT(5) 146 /* CMN_REG(0085) */ 147 #define ANA_PLL_SYNC_LOSS_DET_MODE_MASK GENMASK(1, 0) 148 /* CMN_REG(0086) */ 149 #define PLL_PCG_POSTDIV_SEL_MASK GENMASK(7, 4) 150 #define PLL_PCG_CLK_SEL_MASK GENMASK(3, 1) 151 #define PLL_PCG_CLK_EN_MASK BIT(0) 152 /* CMN_REG(0087) */ 153 #define ANA_PLL_FRL_MODE_EN_MASK BIT(3) 154 #define ANA_PLL_TX_HS_CLK_EN_MASK BIT(2) 155 /* CMN_REG(0089) */ 156 #define LCPLL_ALONE_MODE_MASK BIT(1) 157 /* CMN_REG(0095) */ 158 #define DP_TX_LINK_BW_MASK GENMASK(1, 0) 159 /* CMN_REG(0097) */ 160 #define DIG_CLK_SEL_MASK BIT(1) 161 #define LCPLL_REF BIT(1) 162 #define ROPLL_REF 0 163 /* CMN_REG(0099) */ 164 #define SSC_EN_MASK GENMASK(7, 6) 165 #define CMN_ROPLL_ALONE_MODE_MASK BIT(2) 166 #define ROPLL_ALONE_MODE BIT(2) 167 /* CMN_REG(009a) */ 168 #define HS_SPEED_SEL_MASK BIT(0) 169 #define DIV_10_CLOCK BIT(0) 170 /* CMN_REG(009b) */ 171 #define LS_SPEED_SEL_MASK BIT(4) 172 #define LINK_SYMBOL_CLOCK BIT(4) 173 #define LINK_SYMBOL_CLOCK1_2 0 174 175 /* SB_REG(0102) */ 176 #define OVRD_SB_RXTERM_EN_MASK BIT(5) 177 #define SB_RXTERM_EN_MASK BIT(4) 178 #define ANA_SB_RXTERM_OFFSP_MASK GENMASK(3, 0) 179 /* SB_REG(0103) */ 180 #define ANA_SB_RXTERM_OFFSN_MASK GENMASK(6, 3) 181 #define OVRD_SB_RX_RESCAL_DONE_MASK BIT(1) 182 #define SB_RX_RESCAL_DONE_MASK BIT(0) 183 /* SB_REG(0104) */ 184 #define OVRD_SB_EN_MASK BIT(5) 185 #define SB_EN_MASK BIT(4) 186 #define OVRD_SB_AUX_EN_MASK BIT(1) 187 #define SB_AUX_EN_MASK BIT(0) 188 /* SB_REG(0105) */ 189 #define OVRD_SB_EARC_CMDC_EN_MASK BIT(6) 190 #define SB_EARC_CMDC_EN_MASK BIT(5) 191 #define ANA_SB_TX_HLVL_PROG_MASK GENMASK(2, 0) 192 /* SB_REG(0106) */ 193 #define ANA_SB_TX_LLVL_PROG_MASK GENMASK(6, 4) 194 /* SB_REG(0109) */ 195 #define ANA_SB_DMRX_AFC_DIV_RATIO_MASK GENMASK(2, 0) 196 /* SB_REG(010d) */ 197 #define ANA_SB_DMRX_LPBK_DATA_MASK BIT(4) 198 /* SB_REG(010f) */ 199 #define OVRD_SB_VREG_EN_MASK BIT(7) 200 #define SB_VREG_EN_MASK BIT(6) 201 #define OVRD_SB_VREG_LPF_BYPASS_MASK BIT(5) 202 #define SB_VREG_LPF_BYPASS_MASK BIT(4) 203 #define ANA_SB_VREG_GAIN_CTRL_MASK GENMASK(3, 0) 204 /* SB_REG(0110) */ 205 #define ANA_SB_VREG_OUT_SEL_MASK BIT(1) 206 #define ANA_SB_VREG_REF_SEL_MASK BIT(0) 207 /* SB_REG(0113) */ 208 #define SB_RX_RCAL_OPT_CODE_MASK GENMASK(5, 4) 209 #define SB_RX_RTERM_CTRL_MASK GENMASK(3, 0) 210 /* SB_REG(0114) */ 211 #define SB_TG_SB_EN_DELAY_TIME_MASK GENMASK(5, 3) 212 #define SB_TG_RXTERM_EN_DELAY_TIME_MASK GENMASK(2, 0) 213 /* SB_REG(0115) */ 214 #define SB_READY_DELAY_TIME_MASK GENMASK(5, 3) 215 #define SB_TG_OSC_EN_DELAY_TIME_MASK GENMASK(2, 0) 216 /* SB_REG(0116) */ 217 #define AFC_RSTN_DELAY_TIME_MASK GENMASK(6, 4) 218 /* SB_REG(0117) */ 219 #define FAST_PULSE_TIME_MASK GENMASK(3, 0) 220 /* SB_REG(0118) */ 221 #define SB_TG_EARC_DMRX_RECVRD_CLK_CNT_MASK GENMASK(7, 0) 222 /* SB_REG(011a) */ 223 #define SB_TG_CNT_RUN_NO_7_0_MASK GENMASK(7, 0) 224 /* SB_REG(011b) */ 225 #define SB_EARC_SIG_DET_BYPASS_MASK BIT(4) 226 #define SB_AFC_TOL_MASK GENMASK(3, 0) 227 /* SB_REG(011c) */ 228 #define SB_AFC_STB_NUM_MASK GENMASK(3, 0) 229 /* SB_REG(011d) */ 230 #define SB_TG_OSC_CNT_MIN_MASK GENMASK(7, 0) 231 /* SB_REG(011e) */ 232 #define SB_TG_OSC_CNT_MAX_MASK GENMASK(7, 0) 233 /* SB_REG(011f) */ 234 #define SB_PWM_AFC_CTRL_MASK GENMASK(7, 2) 235 #define SB_RCAL_RSTN_MASK BIT(1) 236 /* SB_REG(0120) */ 237 #define SB_AUX_EN_IN_MASK BIT(7) 238 #define SB_EARC_EN_MASK BIT(1) 239 #define SB_EARC_AFC_EN_MASK BIT(2) 240 /* SB_REG(0123) */ 241 #define OVRD_SB_READY_MASK BIT(5) 242 #define SB_READY_MASK BIT(4) 243 244 /* LNTOP_REG(0200) */ 245 #define PROTOCOL_SEL_MASK BIT(2) 246 #define HDMI_MODE BIT(2) 247 #define HDMI_TMDS_FRL_SEL BIT(1) 248 /* LNTOP_REG(0206) */ 249 #define DATA_BUS_WIDTH_MASK GENMASK(2, 1) 250 #define DATA_BUS_WIDTH_SEL_MASK BIT(0) 251 #define DATA_BUS_36_40 BIT(0) 252 /* LNTOP_REG(0207) */ 253 #define LANE_EN_MASK 0xf 254 #define ALL_LANE_EN 0xf 255 256 /* LANE_REG(0301) */ 257 #define OVRD_LN_TX_DRV_EI_EN_MASK BIT(7) 258 #define LN_TX_DRV_EI_EN_MASK BIT(6) 259 /* LANE_REG(0303) */ 260 #define OVRD_LN_TX_DRV_LVL_CTRL_MASK BIT(5) 261 #define LN_TX_DRV_LVL_CTRL_MASK GENMASK(4, 0) 262 /* LANE_REG(0304) */ 263 #define OVRD_LN_TX_DRV_POST_LVL_CTRL_MASK BIT(4) 264 #define LN_TX_DRV_POST_LVL_CTRL_MASK GENMASK(3, 0) 265 /* LANE_REG(0305) */ 266 #define OVRD_LN_TX_DRV_PRE_LVL_CTRL_MASK BIT(6) 267 #define LN_TX_DRV_PRE_LVL_CTRL_MASK GENMASK(5, 2) 268 /* LANE_REG(0306) */ 269 #define LN_ANA_TX_DRV_IDRV_IDN_CTRL_MASK GENMASK(7, 5) 270 #define LN_ANA_TX_DRV_IDRV_IUP_CTRL_MASK GENMASK(4, 2) 271 #define LN_ANA_TX_DRV_ACCDRV_EN_MASK BIT(0) 272 /* LANE_REG(0307) */ 273 #define LN_ANA_TX_DRV_ACCDRV_POL_SEL_MASK BIT(6) 274 #define LN_ANA_TX_DRV_ACCDRV_CTRL_MASK GENMASK(5, 3) 275 /* LANE_REG(030a) */ 276 #define LN_ANA_TX_JEQ_EN_MASK BIT(4) 277 #define LN_TX_JEQ_EVEN_CTRL_RBR_MASK GENMASK(3, 0) 278 /* LANE_REG(030b) */ 279 #define LN_TX_JEQ_EVEN_CTRL_HBR_MASK GENMASK(7, 4) 280 #define LN_TX_JEQ_EVEN_CTRL_HBR2_MASK GENMASK(3, 0) 281 /* LANE_REG(030c) */ 282 #define LN_TX_JEQ_ODD_CTRL_RBR_MASK GENMASK(3, 0) 283 /* LANE_REG(030d) */ 284 #define LN_TX_JEQ_ODD_CTRL_HBR_MASK GENMASK(7, 4) 285 #define LN_TX_JEQ_ODD_CTRL_HBR2_MASK GENMASK(3, 0) 286 /* LANE_REG(0310) */ 287 #define LN_ANA_TX_SYNC_LOSS_DET_MODE_MASK GENMASK(1, 0) 288 /* LANE_REG(0311) */ 289 #define LN_TX_SER_40BIT_EN_RBR_MASK BIT(3) 290 #define LN_TX_SER_40BIT_EN_HBR_MASK BIT(2) 291 #define LN_TX_SER_40BIT_EN_HBR2_MASK BIT(1) 292 /* LANE_REG(0312) */ 293 #define LN0_TX_SER_RATE_SEL_RBR_MASK BIT(5) 294 #define LN0_TX_SER_RATE_SEL_HBR_MASK BIT(4) 295 #define LN0_TX_SER_RATE_SEL_HBR2_MASK BIT(3) 296 #define LN0_TX_SER_RATE_SEL_HBR3_MASK BIT(2) 297 /* LANE_REG(0316) */ 298 #define LN_ANA_TX_SER_VREG_GAIN_CTRL_MASK GENMASK(3, 0) 299 /* LANE_REG(031B) */ 300 #define LN_ANA_TX_RESERVED_MASK GENMASK(7, 0) 301 /* LANE_REG(031e) */ 302 #define LN_POLARITY_INV_MASK BIT(2) 303 #define LN_LANE_MODE_MASK BIT(1) 304 305 /* LANE_REG(0412) */ 306 #define LN1_TX_SER_RATE_SEL_RBR_MASK BIT(5) 307 #define LN1_TX_SER_RATE_SEL_HBR_MASK BIT(4) 308 #define LN1_TX_SER_RATE_SEL_HBR2_MASK BIT(3) 309 #define LN1_TX_SER_RATE_SEL_HBR3_MASK BIT(2) 310 311 /* LANE_REG(0512) */ 312 #define LN2_TX_SER_RATE_SEL_RBR_MASK BIT(5) 313 #define LN2_TX_SER_RATE_SEL_HBR_MASK BIT(4) 314 #define LN2_TX_SER_RATE_SEL_HBR2_MASK BIT(3) 315 #define LN2_TX_SER_RATE_SEL_HBR3_MASK BIT(2) 316 317 /* LANE_REG(0612) */ 318 #define LN3_TX_SER_RATE_SEL_RBR_MASK BIT(5) 319 #define LN3_TX_SER_RATE_SEL_HBR_MASK BIT(4) 320 #define LN3_TX_SER_RATE_SEL_HBR2_MASK BIT(3) 321 #define LN3_TX_SER_RATE_SEL_HBR3_MASK BIT(2) 322 323 #define HDMI14_MAX_RATE 340000000 324 #define HDMI20_MAX_RATE 600000000 325 326 enum dp_link_rate { 327 DP_BW_RBR, 328 DP_BW_HBR, 329 DP_BW_HBR2, 330 }; 331 332 struct ropll_config { 333 unsigned long long rate; 334 u8 pms_mdiv; 335 u8 pms_mdiv_afc; 336 u8 pms_pdiv; 337 u8 pms_refdiv; 338 u8 pms_sdiv; 339 u8 pms_iqdiv_rstn; 340 u8 ref_clk_sel; 341 u8 sdm_en; 342 u8 sdm_rstn; 343 u8 sdc_frac_en; 344 u8 sdc_rstn; 345 u8 sdm_clk_div; 346 u8 sdm_deno; 347 u8 sdm_num_sign; 348 u8 sdm_num; 349 u8 sdc_n; 350 u8 sdc_num; 351 u8 sdc_deno; 352 u8 sdc_ndiv_rstn; 353 u8 ssc_en; 354 u8 ssc_fm_dev; 355 u8 ssc_fm_freq; 356 u8 ssc_clk_div_sel; 357 u8 ana_cpp_ctrl; 358 u8 ana_lpf_c_sel; 359 u8 cd_tx_ser_rate_sel; 360 }; 361 362 struct tx_drv_ctrl { 363 u8 tx_drv_lvl_ctrl; 364 u8 tx_drv_post_lvl_ctrl; 365 u8 ana_tx_drv_idrv_idn_ctrl; 366 u8 ana_tx_drv_idrv_iup_ctrl; 367 u8 ana_tx_drv_accdrv_en; 368 u8 ana_tx_drv_accdrv_ctrl; 369 u8 tx_drv_pre_lvl_ctrl; 370 u8 ana_tx_jeq_en; 371 u8 tx_jeq_even_ctrl; 372 u8 tx_jeq_odd_ctrl; 373 }; 374 375 enum rk_hdptx_reset { 376 RST_APB = 0, 377 RST_INIT, 378 RST_CMN, 379 RST_LANE, 380 RST_MAX 381 }; 382 383 #define MAX_HDPTX_PHY_NUM 2 384 385 struct rk_hdptx_phy_cfg { 386 unsigned int num_phys; 387 unsigned int phy_ids[MAX_HDPTX_PHY_NUM]; 388 }; 389 390 struct rk_hdptx_phy { 391 struct device *dev; 392 struct regmap *regmap; 393 struct regmap *grf; 394 395 int phy_id; 396 struct phy *phy; 397 struct phy_configure_opts_hdmi hdmi_cfg; 398 struct clk_bulk_data *clks; 399 int nr_clks; 400 struct reset_control_bulk_data rsts[RST_MAX]; 401 402 /* clk provider */ 403 struct clk_hw hw; 404 unsigned long hw_rate; 405 bool restrict_rate_change; 406 407 atomic_t usage_count; 408 409 /* used for dp mode */ 410 unsigned int link_rate; 411 unsigned int lanes; 412 }; 413 414 static const struct ropll_config ropll_tmds_cfg[] = { 415 { 594000000ULL, 124, 124, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 416 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 417 { 371250000ULL, 155, 155, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 418 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 419 { 297000000ULL, 124, 124, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 420 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 421 { 162000000ULL, 135, 135, 1, 1, 3, 1, 1, 0, 1, 1, 1, 1, 4, 0, 3, 5, 5, 0x10, 422 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 423 { 185625000ULL, 155, 155, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 424 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 425 { 154000000ULL, 193, 193, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 193, 1, 32, 2, 1, 426 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 427 { 148500000ULL, 0x7b, 0x7b, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 4, 0, 3, 5, 5, 428 0x10, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 429 { 146250000ULL, 122, 122, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 244, 1, 16, 2, 1, 1, 430 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 431 { 119000000ULL, 149, 149, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 149, 1, 16, 2, 1, 1, 432 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 433 { 106500000ULL, 89, 89, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 89, 1, 16, 1, 0, 1, 434 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 435 { 108000000ULL, 135, 135, 1, 1, 5, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 436 0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 437 { 85500000ULL, 214, 214, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 214, 1, 16, 2, 1, 438 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 439 { 83500000ULL, 105, 105, 1, 1, 5, 1, 1, 1, 1, 1, 1, 1, 42, 1, 16, 1, 0, 440 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 441 { 92812500ULL, 155, 155, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 442 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 443 { 74250000ULL, 124, 124, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 62, 1, 16, 5, 0, 444 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 445 { 65000000ULL, 162, 162, 1, 1, 11, 1, 1, 1, 1, 1, 1, 1, 54, 0, 16, 4, 1, 446 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 447 { 50250000ULL, 84, 84, 1, 1, 7, 1, 1, 1, 1, 1, 1, 1, 11, 1, 4, 5, 448 4, 11, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 449 { 33750000ULL, 0x70, 0x70, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 0x2, 0, 0x01, 5, 450 1, 1, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 451 { 40000000ULL, 100, 100, 1, 1, 11, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 452 0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 453 { 27000000ULL, 0x5a, 0x5a, 1, 1, 0xf, 1, 1, 0, 1, 0, 1, 1, 0x9, 0, 0x05, 0, 454 0x14, 0x18, 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 455 { 25175000ULL, 84, 84, 1, 1, 0xf, 1, 1, 1, 1, 1, 1, 1, 168, 1, 16, 4, 1, 1, 456 1, 0, 0x20, 0x0c, 1, 0x0e, 0, 0, }, 457 }; 458 459 static const struct reg_sequence rk_hdtpx_common_cmn_init_seq[] = { 460 REG_SEQ0(CMN_REG(0009), 0x0c), 461 REG_SEQ0(CMN_REG(000a), 0x83), 462 REG_SEQ0(CMN_REG(000b), 0x06), 463 REG_SEQ0(CMN_REG(000c), 0x20), 464 REG_SEQ0(CMN_REG(000d), 0xb8), 465 REG_SEQ0(CMN_REG(000e), 0x0f), 466 REG_SEQ0(CMN_REG(000f), 0x0f), 467 REG_SEQ0(CMN_REG(0010), 0x04), 468 REG_SEQ0(CMN_REG(0011), 0x00), 469 REG_SEQ0(CMN_REG(0012), 0x26), 470 REG_SEQ0(CMN_REG(0013), 0x22), 471 REG_SEQ0(CMN_REG(0014), 0x24), 472 REG_SEQ0(CMN_REG(0015), 0x77), 473 REG_SEQ0(CMN_REG(0016), 0x08), 474 REG_SEQ0(CMN_REG(0017), 0x00), 475 REG_SEQ0(CMN_REG(0018), 0x04), 476 REG_SEQ0(CMN_REG(0019), 0x48), 477 REG_SEQ0(CMN_REG(001a), 0x01), 478 REG_SEQ0(CMN_REG(001b), 0x00), 479 REG_SEQ0(CMN_REG(001c), 0x01), 480 REG_SEQ0(CMN_REG(001d), 0x64), 481 REG_SEQ0(CMN_REG(001f), 0x00), 482 REG_SEQ0(CMN_REG(0026), 0x53), 483 REG_SEQ0(CMN_REG(0029), 0x01), 484 REG_SEQ0(CMN_REG(0030), 0x00), 485 REG_SEQ0(CMN_REG(0031), 0x20), 486 REG_SEQ0(CMN_REG(0032), 0x30), 487 REG_SEQ0(CMN_REG(0033), 0x0b), 488 REG_SEQ0(CMN_REG(0034), 0x23), 489 REG_SEQ0(CMN_REG(0035), 0x00), 490 REG_SEQ0(CMN_REG(0038), 0x00), 491 REG_SEQ0(CMN_REG(0039), 0x00), 492 REG_SEQ0(CMN_REG(003a), 0x00), 493 REG_SEQ0(CMN_REG(003b), 0x00), 494 REG_SEQ0(CMN_REG(003c), 0x80), 495 REG_SEQ0(CMN_REG(003e), 0x0c), 496 REG_SEQ0(CMN_REG(003f), 0x83), 497 REG_SEQ0(CMN_REG(0040), 0x06), 498 REG_SEQ0(CMN_REG(0041), 0x20), 499 REG_SEQ0(CMN_REG(0042), 0xb8), 500 REG_SEQ0(CMN_REG(0043), 0x00), 501 REG_SEQ0(CMN_REG(0044), 0x46), 502 REG_SEQ0(CMN_REG(0045), 0x24), 503 REG_SEQ0(CMN_REG(0046), 0xff), 504 REG_SEQ0(CMN_REG(0047), 0x00), 505 REG_SEQ0(CMN_REG(0048), 0x44), 506 REG_SEQ0(CMN_REG(0049), 0xfa), 507 REG_SEQ0(CMN_REG(004a), 0x08), 508 REG_SEQ0(CMN_REG(004b), 0x00), 509 REG_SEQ0(CMN_REG(004c), 0x01), 510 REG_SEQ0(CMN_REG(004d), 0x64), 511 REG_SEQ0(CMN_REG(004e), 0x14), 512 REG_SEQ0(CMN_REG(004f), 0x00), 513 REG_SEQ0(CMN_REG(0050), 0x00), 514 REG_SEQ0(CMN_REG(005d), 0x0c), 515 REG_SEQ0(CMN_REG(005f), 0x01), 516 REG_SEQ0(CMN_REG(006b), 0x04), 517 REG_SEQ0(CMN_REG(0073), 0x30), 518 REG_SEQ0(CMN_REG(0074), 0x00), 519 REG_SEQ0(CMN_REG(0075), 0x20), 520 REG_SEQ0(CMN_REG(0076), 0x30), 521 REG_SEQ0(CMN_REG(0077), 0x08), 522 REG_SEQ0(CMN_REG(0078), 0x0c), 523 REG_SEQ0(CMN_REG(0079), 0x00), 524 REG_SEQ0(CMN_REG(007b), 0x00), 525 REG_SEQ0(CMN_REG(007c), 0x00), 526 REG_SEQ0(CMN_REG(007d), 0x00), 527 REG_SEQ0(CMN_REG(007e), 0x00), 528 REG_SEQ0(CMN_REG(007f), 0x00), 529 REG_SEQ0(CMN_REG(0080), 0x00), 530 REG_SEQ0(CMN_REG(0081), 0x09), 531 REG_SEQ0(CMN_REG(0082), 0x04), 532 REG_SEQ0(CMN_REG(0083), 0x24), 533 REG_SEQ0(CMN_REG(0084), 0x20), 534 REG_SEQ0(CMN_REG(0085), 0x03), 535 REG_SEQ0(CMN_REG(0086), 0x01), 536 REG_SEQ0(CMN_REG(0087), 0x0c), 537 REG_SEQ0(CMN_REG(008a), 0x55), 538 REG_SEQ0(CMN_REG(008b), 0x25), 539 REG_SEQ0(CMN_REG(008c), 0x2c), 540 REG_SEQ0(CMN_REG(008d), 0x22), 541 REG_SEQ0(CMN_REG(008e), 0x14), 542 REG_SEQ0(CMN_REG(008f), 0x20), 543 REG_SEQ0(CMN_REG(0090), 0x00), 544 REG_SEQ0(CMN_REG(0091), 0x00), 545 REG_SEQ0(CMN_REG(0092), 0x00), 546 REG_SEQ0(CMN_REG(0093), 0x00), 547 REG_SEQ0(CMN_REG(009a), 0x11), 548 REG_SEQ0(CMN_REG(009b), 0x10), 549 }; 550 551 static const struct reg_sequence rk_hdtpx_tmds_cmn_init_seq[] = { 552 REG_SEQ0(CMN_REG(0008), 0x00), 553 REG_SEQ0(CMN_REG(0011), 0x01), 554 REG_SEQ0(CMN_REG(0017), 0x20), 555 REG_SEQ0(CMN_REG(001e), 0x14), 556 REG_SEQ0(CMN_REG(0020), 0x00), 557 REG_SEQ0(CMN_REG(0021), 0x00), 558 REG_SEQ0(CMN_REG(0022), 0x11), 559 REG_SEQ0(CMN_REG(0023), 0x00), 560 REG_SEQ0(CMN_REG(0024), 0x00), 561 REG_SEQ0(CMN_REG(0025), 0x53), 562 REG_SEQ0(CMN_REG(0026), 0x00), 563 REG_SEQ0(CMN_REG(0027), 0x00), 564 REG_SEQ0(CMN_REG(0028), 0x01), 565 REG_SEQ0(CMN_REG(002a), 0x00), 566 REG_SEQ0(CMN_REG(002b), 0x00), 567 REG_SEQ0(CMN_REG(002c), 0x00), 568 REG_SEQ0(CMN_REG(002d), 0x00), 569 REG_SEQ0(CMN_REG(002e), 0x04), 570 REG_SEQ0(CMN_REG(002f), 0x00), 571 REG_SEQ0(CMN_REG(0030), 0x20), 572 REG_SEQ0(CMN_REG(0031), 0x30), 573 REG_SEQ0(CMN_REG(0032), 0x0b), 574 REG_SEQ0(CMN_REG(0033), 0x23), 575 REG_SEQ0(CMN_REG(0034), 0x00), 576 REG_SEQ0(CMN_REG(003d), 0x40), 577 REG_SEQ0(CMN_REG(0042), 0x78), 578 REG_SEQ0(CMN_REG(004e), 0x34), 579 REG_SEQ0(CMN_REG(005c), 0x25), 580 REG_SEQ0(CMN_REG(005e), 0x4f), 581 REG_SEQ0(CMN_REG(0074), 0x04), 582 REG_SEQ0(CMN_REG(0081), 0x01), 583 REG_SEQ0(CMN_REG(0087), 0x04), 584 REG_SEQ0(CMN_REG(0089), 0x00), 585 REG_SEQ0(CMN_REG(0095), 0x00), 586 REG_SEQ0(CMN_REG(0097), 0x02), 587 REG_SEQ0(CMN_REG(0099), 0x04), 588 REG_SEQ0(CMN_REG(009b), 0x00), 589 }; 590 591 static const struct reg_sequence rk_hdtpx_common_sb_init_seq[] = { 592 REG_SEQ0(SB_REG(0114), 0x00), 593 REG_SEQ0(SB_REG(0115), 0x00), 594 REG_SEQ0(SB_REG(0116), 0x00), 595 REG_SEQ0(SB_REG(0117), 0x00), 596 }; 597 598 static const struct reg_sequence rk_hdtpx_tmds_lntop_highbr_seq[] = { 599 REG_SEQ0(LNTOP_REG(0201), 0x00), 600 REG_SEQ0(LNTOP_REG(0202), 0x00), 601 REG_SEQ0(LNTOP_REG(0203), 0x0f), 602 REG_SEQ0(LNTOP_REG(0204), 0xff), 603 REG_SEQ0(LNTOP_REG(0205), 0xff), 604 }; 605 606 static const struct reg_sequence rk_hdtpx_tmds_lntop_lowbr_seq[] = { 607 REG_SEQ0(LNTOP_REG(0201), 0x07), 608 REG_SEQ0(LNTOP_REG(0202), 0xc1), 609 REG_SEQ0(LNTOP_REG(0203), 0xf0), 610 REG_SEQ0(LNTOP_REG(0204), 0x7c), 611 REG_SEQ0(LNTOP_REG(0205), 0x1f), 612 }; 613 614 static const struct reg_sequence rk_hdtpx_common_lane_init_seq[] = { 615 REG_SEQ0(LANE_REG(0303), 0x0c), 616 REG_SEQ0(LANE_REG(0307), 0x20), 617 REG_SEQ0(LANE_REG(030a), 0x17), 618 REG_SEQ0(LANE_REG(030b), 0x77), 619 REG_SEQ0(LANE_REG(030c), 0x77), 620 REG_SEQ0(LANE_REG(030d), 0x77), 621 REG_SEQ0(LANE_REG(030e), 0x38), 622 REG_SEQ0(LANE_REG(0310), 0x03), 623 REG_SEQ0(LANE_REG(0311), 0x0f), 624 REG_SEQ0(LANE_REG(0316), 0x02), 625 REG_SEQ0(LANE_REG(031b), 0x01), 626 REG_SEQ0(LANE_REG(031f), 0x15), 627 REG_SEQ0(LANE_REG(0320), 0xa0), 628 REG_SEQ0(LANE_REG(0403), 0x0c), 629 REG_SEQ0(LANE_REG(0407), 0x20), 630 REG_SEQ0(LANE_REG(040a), 0x17), 631 REG_SEQ0(LANE_REG(040b), 0x77), 632 REG_SEQ0(LANE_REG(040c), 0x77), 633 REG_SEQ0(LANE_REG(040d), 0x77), 634 REG_SEQ0(LANE_REG(040e), 0x38), 635 REG_SEQ0(LANE_REG(0410), 0x03), 636 REG_SEQ0(LANE_REG(0411), 0x0f), 637 REG_SEQ0(LANE_REG(0416), 0x02), 638 REG_SEQ0(LANE_REG(041b), 0x01), 639 REG_SEQ0(LANE_REG(041f), 0x15), 640 REG_SEQ0(LANE_REG(0420), 0xa0), 641 REG_SEQ0(LANE_REG(0503), 0x0c), 642 REG_SEQ0(LANE_REG(0507), 0x20), 643 REG_SEQ0(LANE_REG(050a), 0x17), 644 REG_SEQ0(LANE_REG(050b), 0x77), 645 REG_SEQ0(LANE_REG(050c), 0x77), 646 REG_SEQ0(LANE_REG(050d), 0x77), 647 REG_SEQ0(LANE_REG(050e), 0x38), 648 REG_SEQ0(LANE_REG(0510), 0x03), 649 REG_SEQ0(LANE_REG(0511), 0x0f), 650 REG_SEQ0(LANE_REG(0516), 0x02), 651 REG_SEQ0(LANE_REG(051b), 0x01), 652 REG_SEQ0(LANE_REG(051f), 0x15), 653 REG_SEQ0(LANE_REG(0520), 0xa0), 654 REG_SEQ0(LANE_REG(0603), 0x0c), 655 REG_SEQ0(LANE_REG(0607), 0x20), 656 REG_SEQ0(LANE_REG(060a), 0x17), 657 REG_SEQ0(LANE_REG(060b), 0x77), 658 REG_SEQ0(LANE_REG(060c), 0x77), 659 REG_SEQ0(LANE_REG(060d), 0x77), 660 REG_SEQ0(LANE_REG(060e), 0x38), 661 REG_SEQ0(LANE_REG(0610), 0x03), 662 REG_SEQ0(LANE_REG(0611), 0x0f), 663 REG_SEQ0(LANE_REG(0616), 0x02), 664 REG_SEQ0(LANE_REG(061b), 0x01), 665 REG_SEQ0(LANE_REG(061f), 0x15), 666 REG_SEQ0(LANE_REG(0620), 0xa0), 667 }; 668 669 static const struct reg_sequence rk_hdtpx_tmds_lane_init_seq[] = { 670 REG_SEQ0(LANE_REG(0312), 0x00), 671 REG_SEQ0(LANE_REG(031e), 0x00), 672 REG_SEQ0(LANE_REG(0412), 0x00), 673 REG_SEQ0(LANE_REG(041e), 0x00), 674 REG_SEQ0(LANE_REG(0512), 0x00), 675 REG_SEQ0(LANE_REG(051e), 0x00), 676 REG_SEQ0(LANE_REG(0612), 0x00), 677 REG_SEQ0(LANE_REG(061e), 0x08), 678 REG_SEQ0(LANE_REG(0303), 0x2f), 679 REG_SEQ0(LANE_REG(0403), 0x2f), 680 REG_SEQ0(LANE_REG(0503), 0x2f), 681 REG_SEQ0(LANE_REG(0603), 0x2f), 682 REG_SEQ0(LANE_REG(0305), 0x03), 683 REG_SEQ0(LANE_REG(0405), 0x03), 684 REG_SEQ0(LANE_REG(0505), 0x03), 685 REG_SEQ0(LANE_REG(0605), 0x03), 686 REG_SEQ0(LANE_REG(0306), 0x1c), 687 REG_SEQ0(LANE_REG(0406), 0x1c), 688 REG_SEQ0(LANE_REG(0506), 0x1c), 689 REG_SEQ0(LANE_REG(0606), 0x1c), 690 }; 691 692 static struct tx_drv_ctrl tx_drv_ctrl_rbr[4][4] = { 693 /* voltage swing 0, pre-emphasis 0->3 */ 694 { 695 { 0x2, 0x0, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 696 { 0x4, 0x3, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 697 { 0x7, 0x6, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 698 { 0xd, 0xc, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 699 }, 700 701 /* voltage swing 1, pre-emphasis 0->2 */ 702 { 703 { 0x4, 0x0, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 704 { 0x9, 0x5, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 705 { 0xc, 0x8, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 706 }, 707 708 /* voltage swing 2, pre-emphasis 0->1 */ 709 { 710 { 0x8, 0x0, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 711 { 0xc, 0x5, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 712 }, 713 714 /* voltage swing 3, pre-emphasis 0 */ 715 { 716 { 0xb, 0x0, 0x7, 0x7, 0x1, 0x4, 0x1, 0x1, 0x7, 0x7 }, 717 } 718 }; 719 720 static struct tx_drv_ctrl tx_drv_ctrl_hbr[4][4] = { 721 /* voltage swing 0, pre-emphasis 0->3 */ 722 { 723 { 0x2, 0x0, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 724 { 0x5, 0x4, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 725 { 0x9, 0x8, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 726 { 0xd, 0xc, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 727 }, 728 729 /* voltage swing 1, pre-emphasis 0->2 */ 730 { 731 { 0x6, 0x1, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 732 { 0xa, 0x6, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 733 { 0xc, 0x8, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 734 }, 735 736 /* voltage swing 2, pre-emphasis 0->1 */ 737 { 738 { 0x9, 0x1, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 739 { 0xd, 0x6, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 740 }, 741 742 /* voltage swing 3, pre-emphasis 0 */ 743 { 744 { 0xc, 0x1, 0x7, 0x7, 0x1, 0x4, 0x1, 0x1, 0x7, 0x7 }, 745 } 746 }; 747 748 static struct tx_drv_ctrl tx_drv_ctrl_hbr2[4][4] = { 749 /* voltage swing 0, pre-emphasis 0->3 */ 750 { 751 { 0x2, 0x1, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 752 { 0x5, 0x4, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 753 { 0x9, 0x8, 0x4, 0x6, 0x1, 0x4, 0x0, 0x1, 0x7, 0x7 }, 754 { 0xd, 0xc, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 755 }, 756 757 /* voltage swing 1, pre-emphasis 0->2 */ 758 { 759 { 0x6, 0x1, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 760 { 0xb, 0x7, 0x4, 0x6, 0x0, 0x4, 0x0, 0x1, 0x7, 0x7 }, 761 { 0xd, 0x9, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 762 }, 763 764 /* voltage swing 2, pre-emphasis 0->1 */ 765 { 766 { 0x8, 0x1, 0x4, 0x6, 0x0, 0x4, 0x1, 0x1, 0x7, 0x7 }, 767 { 0xc, 0x6, 0x7, 0x7, 0x1, 0x7, 0x0, 0x1, 0x7, 0x7 }, 768 }, 769 770 /* voltage swing 3, pre-emphasis 0 */ 771 { 772 { 0xb, 0x0, 0x7, 0x7, 0x1, 0x4, 0x1, 0x1, 0x7, 0x7 }, 773 } 774 }; 775 776 static bool rk_hdptx_phy_is_rw_reg(struct device *dev, unsigned int reg) 777 { 778 switch (reg) { 779 case 0x0000 ... 0x029c: /* CMN Register */ 780 case 0x0400 ... 0x04a4: /* Sideband Register */ 781 case 0x0800 ... 0x08a4: /* Lane Top Register */ 782 case 0x0c00 ... 0x0cb4: /* Lane 0 Register */ 783 case 0x1000 ... 0x10b4: /* Lane 1 Register */ 784 case 0x1400 ... 0x14b4: /* Lane 2 Register */ 785 case 0x1800 ... 0x18b4: /* Lane 3 Register */ 786 return true; 787 } 788 789 return false; 790 } 791 792 static const struct regmap_config rk_hdptx_phy_regmap_config = { 793 .reg_bits = 32, 794 .reg_stride = 4, 795 .val_bits = 32, 796 .writeable_reg = rk_hdptx_phy_is_rw_reg, 797 .readable_reg = rk_hdptx_phy_is_rw_reg, 798 .fast_io = true, 799 .max_register = 0x18b4, 800 }; 801 802 #define rk_hdptx_multi_reg_write(hdptx, seq) \ 803 regmap_multi_reg_write((hdptx)->regmap, seq, ARRAY_SIZE(seq)) 804 805 static void rk_hdptx_pre_power_up(struct rk_hdptx_phy *hdptx) 806 { 807 u32 val; 808 809 reset_control_assert(hdptx->rsts[RST_APB].rstc); 810 usleep_range(20, 25); 811 reset_control_deassert(hdptx->rsts[RST_APB].rstc); 812 813 reset_control_assert(hdptx->rsts[RST_LANE].rstc); 814 reset_control_assert(hdptx->rsts[RST_CMN].rstc); 815 reset_control_assert(hdptx->rsts[RST_INIT].rstc); 816 817 val = (HDPTX_I_PLL_EN | HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16; 818 regmap_write(hdptx->grf, GRF_HDPTX_CON0, val); 819 } 820 821 static int rk_hdptx_post_enable_lane(struct rk_hdptx_phy *hdptx) 822 { 823 u32 val; 824 int ret; 825 826 reset_control_deassert(hdptx->rsts[RST_LANE].rstc); 827 828 val = (HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16 | 829 HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN; 830 regmap_write(hdptx->grf, GRF_HDPTX_CON0, val); 831 832 ret = regmap_read_poll_timeout(hdptx->grf, GRF_HDPTX_STATUS, val, 833 (val & HDPTX_O_PHY_RDY) && 834 (val & HDPTX_O_PLL_LOCK_DONE), 835 100, 5000); 836 if (ret) { 837 dev_err(hdptx->dev, "Failed to get PHY lane lock: %d\n", ret); 838 return ret; 839 } 840 841 dev_dbg(hdptx->dev, "PHY lane locked\n"); 842 843 return 0; 844 } 845 846 static int rk_hdptx_post_enable_pll(struct rk_hdptx_phy *hdptx) 847 { 848 u32 val; 849 int ret; 850 851 val = (HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16 | 852 HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN; 853 regmap_write(hdptx->grf, GRF_HDPTX_CON0, val); 854 855 usleep_range(10, 15); 856 reset_control_deassert(hdptx->rsts[RST_INIT].rstc); 857 858 usleep_range(10, 15); 859 val = HDPTX_I_PLL_EN << 16 | HDPTX_I_PLL_EN; 860 regmap_write(hdptx->grf, GRF_HDPTX_CON0, val); 861 862 usleep_range(10, 15); 863 reset_control_deassert(hdptx->rsts[RST_CMN].rstc); 864 865 ret = regmap_read_poll_timeout(hdptx->grf, GRF_HDPTX_STATUS, val, 866 val & HDPTX_O_PHY_CLK_RDY, 20, 400); 867 if (ret) { 868 dev_err(hdptx->dev, "Failed to get PHY clk ready: %d\n", ret); 869 return ret; 870 } 871 872 dev_dbg(hdptx->dev, "PHY clk ready\n"); 873 874 return 0; 875 } 876 877 static void rk_hdptx_phy_disable(struct rk_hdptx_phy *hdptx) 878 { 879 u32 val; 880 881 reset_control_assert(hdptx->rsts[RST_APB].rstc); 882 usleep_range(20, 30); 883 reset_control_deassert(hdptx->rsts[RST_APB].rstc); 884 885 regmap_write(hdptx->regmap, LANE_REG(0300), 0x82); 886 regmap_write(hdptx->regmap, SB_REG(010f), 0xc1); 887 regmap_write(hdptx->regmap, SB_REG(0110), 0x1); 888 regmap_write(hdptx->regmap, LANE_REG(0301), 0x80); 889 regmap_write(hdptx->regmap, LANE_REG(0401), 0x80); 890 regmap_write(hdptx->regmap, LANE_REG(0501), 0x80); 891 regmap_write(hdptx->regmap, LANE_REG(0601), 0x80); 892 893 reset_control_assert(hdptx->rsts[RST_LANE].rstc); 894 reset_control_assert(hdptx->rsts[RST_CMN].rstc); 895 reset_control_assert(hdptx->rsts[RST_INIT].rstc); 896 897 val = (HDPTX_I_PLL_EN | HDPTX_I_BIAS_EN | HDPTX_I_BGR_EN) << 16; 898 regmap_write(hdptx->grf, GRF_HDPTX_CON0, val); 899 } 900 901 static bool rk_hdptx_phy_clk_pll_calc(unsigned long long rate, 902 struct ropll_config *cfg) 903 { 904 const unsigned int fout = div_u64(rate, 200), fref = 24000; 905 unsigned long k = 0, lc, k_sub, lc_sub; 906 unsigned int fvco, sdc; 907 u32 mdiv, sdiv, n = 8; 908 909 if (fout > 0xfffffff) 910 return false; 911 912 for (sdiv = 16; sdiv >= 1; sdiv--) { 913 if (sdiv % 2 && sdiv != 1) 914 continue; 915 916 fvco = fout * sdiv; 917 918 if (fvco < 2000000 || fvco > 4000000) 919 continue; 920 921 mdiv = DIV_ROUND_UP(fvco, fref); 922 if (mdiv < 20 || mdiv > 255) 923 continue; 924 925 if (fref * mdiv - fvco) { 926 for (sdc = 264000; sdc <= 750000; sdc += fref) 927 if (sdc * n > fref * mdiv) 928 break; 929 930 if (sdc > 750000) 931 continue; 932 933 rational_best_approximation(fref * mdiv - fvco, 934 sdc / 16, 935 GENMASK(6, 0), 936 GENMASK(7, 0), 937 &k, &lc); 938 939 rational_best_approximation(sdc * n - fref * mdiv, 940 sdc, 941 GENMASK(6, 0), 942 GENMASK(7, 0), 943 &k_sub, &lc_sub); 944 } 945 946 break; 947 } 948 949 if (sdiv < 1) 950 return false; 951 952 if (cfg) { 953 cfg->pms_mdiv = mdiv; 954 cfg->pms_mdiv_afc = mdiv; 955 cfg->pms_pdiv = 1; 956 cfg->pms_refdiv = 1; 957 cfg->pms_sdiv = sdiv - 1; 958 959 cfg->sdm_en = k > 0 ? 1 : 0; 960 if (cfg->sdm_en) { 961 cfg->sdm_deno = lc; 962 cfg->sdm_num_sign = 1; 963 cfg->sdm_num = k; 964 cfg->sdc_n = n - 3; 965 cfg->sdc_num = k_sub; 966 cfg->sdc_deno = lc_sub; 967 } 968 } 969 970 return true; 971 } 972 973 static int rk_hdptx_ropll_tmds_cmn_config(struct rk_hdptx_phy *hdptx) 974 { 975 const struct ropll_config *cfg = NULL; 976 struct ropll_config rc = {0}; 977 int ret, i; 978 979 if (!hdptx->hdmi_cfg.tmds_char_rate) 980 return 0; 981 982 for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++) 983 if (hdptx->hdmi_cfg.tmds_char_rate == ropll_tmds_cfg[i].rate) { 984 cfg = &ropll_tmds_cfg[i]; 985 break; 986 } 987 988 if (!cfg) { 989 if (!rk_hdptx_phy_clk_pll_calc(hdptx->hdmi_cfg.tmds_char_rate, &rc)) { 990 dev_err(hdptx->dev, "%s cannot find pll cfg for rate=%llu\n", 991 __func__, hdptx->hdmi_cfg.tmds_char_rate); 992 return -EINVAL; 993 } 994 995 cfg = &rc; 996 } 997 998 dev_dbg(hdptx->dev, "%s rate=%llu mdiv=%u sdiv=%u sdm_en=%u k_sign=%u k=%u lc=%u\n", 999 __func__, hdptx->hdmi_cfg.tmds_char_rate, cfg->pms_mdiv, cfg->pms_sdiv + 1, 1000 cfg->sdm_en, cfg->sdm_num_sign, cfg->sdm_num, cfg->sdm_deno); 1001 1002 rk_hdptx_pre_power_up(hdptx); 1003 1004 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_common_cmn_init_seq); 1005 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_tmds_cmn_init_seq); 1006 1007 regmap_write(hdptx->regmap, CMN_REG(0051), cfg->pms_mdiv); 1008 regmap_write(hdptx->regmap, CMN_REG(0055), cfg->pms_mdiv_afc); 1009 regmap_write(hdptx->regmap, CMN_REG(0059), 1010 (cfg->pms_pdiv << 4) | cfg->pms_refdiv); 1011 regmap_write(hdptx->regmap, CMN_REG(005a), cfg->pms_sdiv << 4); 1012 1013 regmap_update_bits(hdptx->regmap, CMN_REG(005e), ROPLL_SDM_EN_MASK, 1014 FIELD_PREP(ROPLL_SDM_EN_MASK, cfg->sdm_en)); 1015 if (!cfg->sdm_en) 1016 regmap_update_bits(hdptx->regmap, CMN_REG(005e), 0xf, 0); 1017 1018 regmap_update_bits(hdptx->regmap, CMN_REG(0064), ROPLL_SDM_NUM_SIGN_RBR_MASK, 1019 FIELD_PREP(ROPLL_SDM_NUM_SIGN_RBR_MASK, cfg->sdm_num_sign)); 1020 1021 regmap_write(hdptx->regmap, CMN_REG(0060), cfg->sdm_deno); 1022 regmap_write(hdptx->regmap, CMN_REG(0065), cfg->sdm_num); 1023 1024 regmap_update_bits(hdptx->regmap, CMN_REG(0069), ROPLL_SDC_N_RBR_MASK, 1025 FIELD_PREP(ROPLL_SDC_N_RBR_MASK, cfg->sdc_n)); 1026 1027 regmap_write(hdptx->regmap, CMN_REG(006c), cfg->sdc_num); 1028 regmap_write(hdptx->regmap, CMN_REG(0070), cfg->sdc_deno); 1029 1030 regmap_update_bits(hdptx->regmap, CMN_REG(0086), PLL_PCG_POSTDIV_SEL_MASK, 1031 FIELD_PREP(PLL_PCG_POSTDIV_SEL_MASK, cfg->pms_sdiv)); 1032 1033 regmap_update_bits(hdptx->regmap, CMN_REG(0086), PLL_PCG_CLK_SEL_MASK, 1034 FIELD_PREP(PLL_PCG_CLK_SEL_MASK, (hdptx->hdmi_cfg.bpc - 8) >> 1)); 1035 1036 regmap_update_bits(hdptx->regmap, CMN_REG(0086), PLL_PCG_CLK_EN_MASK, 1037 FIELD_PREP(PLL_PCG_CLK_EN_MASK, 0x1)); 1038 1039 ret = rk_hdptx_post_enable_pll(hdptx); 1040 if (!ret) 1041 hdptx->hw_rate = hdptx->hdmi_cfg.tmds_char_rate; 1042 1043 return ret; 1044 } 1045 1046 static int rk_hdptx_ropll_tmds_mode_config(struct rk_hdptx_phy *hdptx) 1047 { 1048 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_common_sb_init_seq); 1049 1050 regmap_write(hdptx->regmap, LNTOP_REG(0200), 0x06); 1051 1052 if (hdptx->hdmi_cfg.tmds_char_rate > HDMI14_MAX_RATE) { 1053 /* For 1/40 bitrate clk */ 1054 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_tmds_lntop_highbr_seq); 1055 } else { 1056 /* For 1/10 bitrate clk */ 1057 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_tmds_lntop_lowbr_seq); 1058 } 1059 1060 regmap_write(hdptx->regmap, LNTOP_REG(0206), 0x07); 1061 regmap_write(hdptx->regmap, LNTOP_REG(0207), 0x0f); 1062 1063 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_common_lane_init_seq); 1064 rk_hdptx_multi_reg_write(hdptx, rk_hdtpx_tmds_lane_init_seq); 1065 1066 return rk_hdptx_post_enable_lane(hdptx); 1067 } 1068 1069 static void rk_hdptx_dp_reset(struct rk_hdptx_phy *hdptx) 1070 { 1071 reset_control_assert(hdptx->rsts[RST_LANE].rstc); 1072 reset_control_assert(hdptx->rsts[RST_CMN].rstc); 1073 reset_control_assert(hdptx->rsts[RST_INIT].rstc); 1074 1075 reset_control_assert(hdptx->rsts[RST_APB].rstc); 1076 udelay(10); 1077 reset_control_deassert(hdptx->rsts[RST_APB].rstc); 1078 1079 regmap_update_bits(hdptx->regmap, LANE_REG(0301), 1080 OVRD_LN_TX_DRV_EI_EN_MASK | LN_TX_DRV_EI_EN_MASK, 1081 FIELD_PREP(OVRD_LN_TX_DRV_EI_EN_MASK, 1) | 1082 FIELD_PREP(LN_TX_DRV_EI_EN_MASK, 0)); 1083 regmap_update_bits(hdptx->regmap, LANE_REG(0401), 1084 OVRD_LN_TX_DRV_EI_EN_MASK | LN_TX_DRV_EI_EN_MASK, 1085 FIELD_PREP(OVRD_LN_TX_DRV_EI_EN_MASK, 1) | 1086 FIELD_PREP(LN_TX_DRV_EI_EN_MASK, 0)); 1087 regmap_update_bits(hdptx->regmap, LANE_REG(0501), 1088 OVRD_LN_TX_DRV_EI_EN_MASK | LN_TX_DRV_EI_EN_MASK, 1089 FIELD_PREP(OVRD_LN_TX_DRV_EI_EN_MASK, 1) | 1090 FIELD_PREP(LN_TX_DRV_EI_EN_MASK, 0)); 1091 regmap_update_bits(hdptx->regmap, LANE_REG(0601), 1092 OVRD_LN_TX_DRV_EI_EN_MASK | LN_TX_DRV_EI_EN_MASK, 1093 FIELD_PREP(OVRD_LN_TX_DRV_EI_EN_MASK, 1) | 1094 FIELD_PREP(LN_TX_DRV_EI_EN_MASK, 0)); 1095 1096 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1097 HDPTX_I_PLL_EN << 16 | FIELD_PREP(HDPTX_I_PLL_EN, 0x0)); 1098 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1099 HDPTX_I_BIAS_EN << 16 | FIELD_PREP(HDPTX_I_BIAS_EN, 0x0)); 1100 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1101 HDPTX_I_BGR_EN << 16 | FIELD_PREP(HDPTX_I_BGR_EN, 0x0)); 1102 } 1103 1104 static int rk_hdptx_phy_consumer_get(struct rk_hdptx_phy *hdptx) 1105 { 1106 enum phy_mode mode = phy_get_mode(hdptx->phy); 1107 u32 status; 1108 int ret; 1109 1110 if (atomic_inc_return(&hdptx->usage_count) > 1) 1111 return 0; 1112 1113 ret = regmap_read(hdptx->grf, GRF_HDPTX_STATUS, &status); 1114 if (ret) 1115 goto dec_usage; 1116 1117 if (status & HDPTX_O_PLL_LOCK_DONE) 1118 dev_warn(hdptx->dev, "PLL locked by unknown consumer!\n"); 1119 1120 if (mode == PHY_MODE_DP) { 1121 rk_hdptx_dp_reset(hdptx); 1122 } else { 1123 ret = rk_hdptx_ropll_tmds_cmn_config(hdptx); 1124 if (ret) 1125 goto dec_usage; 1126 } 1127 1128 return 0; 1129 1130 dec_usage: 1131 atomic_dec(&hdptx->usage_count); 1132 return ret; 1133 } 1134 1135 static int rk_hdptx_phy_consumer_put(struct rk_hdptx_phy *hdptx, bool force) 1136 { 1137 enum phy_mode mode = phy_get_mode(hdptx->phy); 1138 u32 status; 1139 int ret; 1140 1141 ret = atomic_dec_return(&hdptx->usage_count); 1142 if (ret > 0) 1143 return 0; 1144 1145 if (ret < 0) { 1146 dev_warn(hdptx->dev, "Usage count underflow!\n"); 1147 ret = -EINVAL; 1148 } else { 1149 ret = regmap_read(hdptx->grf, GRF_HDPTX_STATUS, &status); 1150 if (!ret) { 1151 if (status & HDPTX_O_PLL_LOCK_DONE) { 1152 if (mode == PHY_MODE_DP) 1153 rk_hdptx_dp_reset(hdptx); 1154 else 1155 rk_hdptx_phy_disable(hdptx); 1156 } 1157 return 0; 1158 } else if (force) { 1159 return 0; 1160 } 1161 } 1162 1163 atomic_inc(&hdptx->usage_count); 1164 return ret; 1165 } 1166 1167 static void rk_hdptx_dp_pll_init(struct rk_hdptx_phy *hdptx) 1168 { 1169 regmap_update_bits(hdptx->regmap, CMN_REG(003c), ANA_LCPLL_RESERVED7_MASK, 1170 FIELD_PREP(ANA_LCPLL_RESERVED7_MASK, 0x1)); 1171 1172 regmap_update_bits(hdptx->regmap, CMN_REG(0046), 1173 ROPLL_ANA_CPP_CTRL_COARSE_MASK | ROPLL_ANA_CPP_CTRL_FINE_MASK, 1174 FIELD_PREP(ROPLL_ANA_CPP_CTRL_COARSE_MASK, 0xe) | 1175 FIELD_PREP(ROPLL_ANA_CPP_CTRL_FINE_MASK, 0xe)); 1176 regmap_update_bits(hdptx->regmap, CMN_REG(0047), 1177 ROPLL_ANA_LPF_C_SEL_COARSE_MASK | 1178 ROPLL_ANA_LPF_C_SEL_FINE_MASK, 1179 FIELD_PREP(ROPLL_ANA_LPF_C_SEL_COARSE_MASK, 0x4) | 1180 FIELD_PREP(ROPLL_ANA_LPF_C_SEL_FINE_MASK, 0x4)); 1181 1182 regmap_write(hdptx->regmap, CMN_REG(0051), FIELD_PREP(ROPLL_PMS_MDIV_MASK, 0x87)); 1183 regmap_write(hdptx->regmap, CMN_REG(0052), FIELD_PREP(ROPLL_PMS_MDIV_MASK, 0x71)); 1184 regmap_write(hdptx->regmap, CMN_REG(0053), FIELD_PREP(ROPLL_PMS_MDIV_MASK, 0x71)); 1185 1186 regmap_write(hdptx->regmap, CMN_REG(0055), 1187 FIELD_PREP(ROPLL_PMS_MDIV_AFC_MASK, 0x87)); 1188 regmap_write(hdptx->regmap, CMN_REG(0056), 1189 FIELD_PREP(ROPLL_PMS_MDIV_AFC_MASK, 0x71)); 1190 regmap_write(hdptx->regmap, CMN_REG(0057), 1191 FIELD_PREP(ROPLL_PMS_MDIV_AFC_MASK, 0x71)); 1192 1193 regmap_write(hdptx->regmap, CMN_REG(0059), 1194 FIELD_PREP(ANA_ROPLL_PMS_PDIV_MASK, 0x1) | 1195 FIELD_PREP(ANA_ROPLL_PMS_REFDIV_MASK, 0x1)); 1196 regmap_write(hdptx->regmap, CMN_REG(005a), 1197 FIELD_PREP(ROPLL_PMS_SDIV_RBR_MASK, 0x3) | 1198 FIELD_PREP(ROPLL_PMS_SDIV_HBR_MASK, 0x1)); 1199 regmap_update_bits(hdptx->regmap, CMN_REG(005b), ROPLL_PMS_SDIV_HBR2_MASK, 1200 FIELD_PREP(ROPLL_PMS_SDIV_HBR2_MASK, 0x0)); 1201 1202 regmap_update_bits(hdptx->regmap, CMN_REG(005e), ROPLL_SDM_EN_MASK, 1203 FIELD_PREP(ROPLL_SDM_EN_MASK, 0x1)); 1204 regmap_update_bits(hdptx->regmap, CMN_REG(005e), 1205 OVRD_ROPLL_SDM_RSTN_MASK | ROPLL_SDM_RSTN_MASK, 1206 FIELD_PREP(OVRD_ROPLL_SDM_RSTN_MASK, 0x1) | 1207 FIELD_PREP(ROPLL_SDM_RSTN_MASK, 0x1)); 1208 regmap_update_bits(hdptx->regmap, CMN_REG(005e), ROPLL_SDC_FRAC_EN_RBR_MASK, 1209 FIELD_PREP(ROPLL_SDC_FRAC_EN_RBR_MASK, 0x1)); 1210 regmap_update_bits(hdptx->regmap, CMN_REG(005e), ROPLL_SDC_FRAC_EN_HBR_MASK, 1211 FIELD_PREP(ROPLL_SDC_FRAC_EN_HBR_MASK, 0x1)); 1212 regmap_update_bits(hdptx->regmap, CMN_REG(005e), ROPLL_SDC_FRAC_EN_HBR2_MASK, 1213 FIELD_PREP(ROPLL_SDC_FRAC_EN_HBR2_MASK, 0x1)); 1214 1215 regmap_update_bits(hdptx->regmap, CMN_REG(005f), 1216 OVRD_ROPLL_SDC_RSTN_MASK | ROPLL_SDC_RSTN_MASK, 1217 FIELD_PREP(OVRD_ROPLL_SDC_RSTN_MASK, 0x1) | 1218 FIELD_PREP(ROPLL_SDC_RSTN_MASK, 0x1)); 1219 regmap_write(hdptx->regmap, CMN_REG(0060), 1220 FIELD_PREP(ROPLL_SDM_DENOMINATOR_MASK, 0x21)); 1221 regmap_write(hdptx->regmap, CMN_REG(0061), 1222 FIELD_PREP(ROPLL_SDM_DENOMINATOR_MASK, 0x27)); 1223 regmap_write(hdptx->regmap, CMN_REG(0062), 1224 FIELD_PREP(ROPLL_SDM_DENOMINATOR_MASK, 0x27)); 1225 1226 regmap_update_bits(hdptx->regmap, CMN_REG(0064), 1227 ROPLL_SDM_NUM_SIGN_RBR_MASK | 1228 ROPLL_SDM_NUM_SIGN_HBR_MASK | 1229 ROPLL_SDM_NUM_SIGN_HBR2_MASK, 1230 FIELD_PREP(ROPLL_SDM_NUM_SIGN_RBR_MASK, 0x0) | 1231 FIELD_PREP(ROPLL_SDM_NUM_SIGN_HBR_MASK, 0x1) | 1232 FIELD_PREP(ROPLL_SDM_NUM_SIGN_HBR2_MASK, 0x1)); 1233 regmap_write(hdptx->regmap, CMN_REG(0065), 1234 FIELD_PREP(ROPLL_SDM_NUM_MASK, 0x0)); 1235 regmap_write(hdptx->regmap, CMN_REG(0066), 1236 FIELD_PREP(ROPLL_SDM_NUM_MASK, 0xd)); 1237 regmap_write(hdptx->regmap, CMN_REG(0067), 1238 FIELD_PREP(ROPLL_SDM_NUM_MASK, 0xd)); 1239 1240 regmap_update_bits(hdptx->regmap, CMN_REG(0069), ROPLL_SDC_N_RBR_MASK, 1241 FIELD_PREP(ROPLL_SDC_N_RBR_MASK, 0x2)); 1242 1243 regmap_update_bits(hdptx->regmap, CMN_REG(006a), 1244 ROPLL_SDC_N_HBR_MASK | ROPLL_SDC_N_HBR2_MASK, 1245 FIELD_PREP(ROPLL_SDC_N_HBR_MASK, 0x1) | 1246 FIELD_PREP(ROPLL_SDC_N_HBR2_MASK, 0x1)); 1247 1248 regmap_write(hdptx->regmap, CMN_REG(006c), 1249 FIELD_PREP(ROPLL_SDC_NUM_MASK, 0x3)); 1250 regmap_write(hdptx->regmap, CMN_REG(006d), 1251 FIELD_PREP(ROPLL_SDC_NUM_MASK, 0x7)); 1252 regmap_write(hdptx->regmap, CMN_REG(006e), 1253 FIELD_PREP(ROPLL_SDC_NUM_MASK, 0x7)); 1254 1255 regmap_write(hdptx->regmap, CMN_REG(0070), 1256 FIELD_PREP(ROPLL_SDC_DENO_MASK, 0x8)); 1257 regmap_write(hdptx->regmap, CMN_REG(0071), 1258 FIELD_PREP(ROPLL_SDC_DENO_MASK, 0x18)); 1259 regmap_write(hdptx->regmap, CMN_REG(0072), 1260 FIELD_PREP(ROPLL_SDC_DENO_MASK, 0x18)); 1261 1262 regmap_update_bits(hdptx->regmap, CMN_REG(0074), 1263 OVRD_ROPLL_SDC_NDIV_RSTN_MASK | ROPLL_SDC_NDIV_RSTN_MASK, 1264 FIELD_PREP(OVRD_ROPLL_SDC_NDIV_RSTN_MASK, 0x1) | 1265 FIELD_PREP(ROPLL_SDC_NDIV_RSTN_MASK, 0x1)); 1266 1267 regmap_update_bits(hdptx->regmap, CMN_REG(0077), ANA_ROPLL_SSC_CLK_DIV_SEL_MASK, 1268 FIELD_PREP(ANA_ROPLL_SSC_CLK_DIV_SEL_MASK, 0x1)); 1269 1270 regmap_update_bits(hdptx->regmap, CMN_REG(0081), ANA_PLL_CD_TX_SER_RATE_SEL_MASK, 1271 FIELD_PREP(ANA_PLL_CD_TX_SER_RATE_SEL_MASK, 0x0)); 1272 regmap_update_bits(hdptx->regmap, CMN_REG(0081), 1273 ANA_PLL_CD_HSCLK_EAST_EN_MASK | ANA_PLL_CD_HSCLK_WEST_EN_MASK, 1274 FIELD_PREP(ANA_PLL_CD_HSCLK_EAST_EN_MASK, 0x1) | 1275 FIELD_PREP(ANA_PLL_CD_HSCLK_WEST_EN_MASK, 0x0)); 1276 1277 regmap_update_bits(hdptx->regmap, CMN_REG(0082), ANA_PLL_CD_VREG_GAIN_CTRL_MASK, 1278 FIELD_PREP(ANA_PLL_CD_VREG_GAIN_CTRL_MASK, 0x4)); 1279 regmap_update_bits(hdptx->regmap, CMN_REG(0083), ANA_PLL_CD_VREG_ICTRL_MASK, 1280 FIELD_PREP(ANA_PLL_CD_VREG_ICTRL_MASK, 0x1)); 1281 regmap_update_bits(hdptx->regmap, CMN_REG(0084), PLL_LCRO_CLK_SEL_MASK, 1282 FIELD_PREP(PLL_LCRO_CLK_SEL_MASK, 0x1)); 1283 regmap_update_bits(hdptx->regmap, CMN_REG(0085), ANA_PLL_SYNC_LOSS_DET_MODE_MASK, 1284 FIELD_PREP(ANA_PLL_SYNC_LOSS_DET_MODE_MASK, 0x3)); 1285 1286 regmap_update_bits(hdptx->regmap, CMN_REG(0087), ANA_PLL_TX_HS_CLK_EN_MASK, 1287 FIELD_PREP(ANA_PLL_TX_HS_CLK_EN_MASK, 0x1)); 1288 1289 regmap_update_bits(hdptx->regmap, CMN_REG(0097), DIG_CLK_SEL_MASK, 1290 FIELD_PREP(DIG_CLK_SEL_MASK, 0x1)); 1291 1292 regmap_update_bits(hdptx->regmap, CMN_REG(0099), CMN_ROPLL_ALONE_MODE_MASK, 1293 FIELD_PREP(CMN_ROPLL_ALONE_MODE_MASK, 0x1)); 1294 regmap_update_bits(hdptx->regmap, CMN_REG(009a), HS_SPEED_SEL_MASK, 1295 FIELD_PREP(HS_SPEED_SEL_MASK, 0x1)); 1296 regmap_update_bits(hdptx->regmap, CMN_REG(009b), LS_SPEED_SEL_MASK, 1297 FIELD_PREP(LS_SPEED_SEL_MASK, 0x1)); 1298 } 1299 1300 static int rk_hdptx_dp_aux_init(struct rk_hdptx_phy *hdptx) 1301 { 1302 u32 status; 1303 int ret; 1304 1305 regmap_update_bits(hdptx->regmap, SB_REG(0102), ANA_SB_RXTERM_OFFSP_MASK, 1306 FIELD_PREP(ANA_SB_RXTERM_OFFSP_MASK, 0x3)); 1307 regmap_update_bits(hdptx->regmap, SB_REG(0103), ANA_SB_RXTERM_OFFSN_MASK, 1308 FIELD_PREP(ANA_SB_RXTERM_OFFSN_MASK, 0x3)); 1309 regmap_update_bits(hdptx->regmap, SB_REG(0104), SB_AUX_EN_MASK, 1310 FIELD_PREP(SB_AUX_EN_MASK, 0x1)); 1311 regmap_update_bits(hdptx->regmap, SB_REG(0105), ANA_SB_TX_HLVL_PROG_MASK, 1312 FIELD_PREP(ANA_SB_TX_HLVL_PROG_MASK, 0x7)); 1313 regmap_update_bits(hdptx->regmap, SB_REG(0106), ANA_SB_TX_LLVL_PROG_MASK, 1314 FIELD_PREP(ANA_SB_TX_LLVL_PROG_MASK, 0x7)); 1315 1316 regmap_update_bits(hdptx->regmap, SB_REG(010d), ANA_SB_DMRX_LPBK_DATA_MASK, 1317 FIELD_PREP(ANA_SB_DMRX_LPBK_DATA_MASK, 0x1)); 1318 1319 regmap_update_bits(hdptx->regmap, SB_REG(010f), ANA_SB_VREG_GAIN_CTRL_MASK, 1320 FIELD_PREP(ANA_SB_VREG_GAIN_CTRL_MASK, 0x0)); 1321 regmap_update_bits(hdptx->regmap, SB_REG(0110), 1322 ANA_SB_VREG_OUT_SEL_MASK | ANA_SB_VREG_REF_SEL_MASK, 1323 FIELD_PREP(ANA_SB_VREG_OUT_SEL_MASK, 0x1) | 1324 FIELD_PREP(ANA_SB_VREG_REF_SEL_MASK, 0x1)); 1325 1326 regmap_update_bits(hdptx->regmap, SB_REG(0113), 1327 SB_RX_RCAL_OPT_CODE_MASK | SB_RX_RTERM_CTRL_MASK, 1328 FIELD_PREP(SB_RX_RCAL_OPT_CODE_MASK, 0x1) | 1329 FIELD_PREP(SB_RX_RTERM_CTRL_MASK, 0x3)); 1330 regmap_update_bits(hdptx->regmap, SB_REG(0114), 1331 SB_TG_SB_EN_DELAY_TIME_MASK | SB_TG_RXTERM_EN_DELAY_TIME_MASK, 1332 FIELD_PREP(SB_TG_SB_EN_DELAY_TIME_MASK, 0x2) | 1333 FIELD_PREP(SB_TG_RXTERM_EN_DELAY_TIME_MASK, 0x2)); 1334 regmap_update_bits(hdptx->regmap, SB_REG(0115), 1335 SB_READY_DELAY_TIME_MASK | SB_TG_OSC_EN_DELAY_TIME_MASK, 1336 FIELD_PREP(SB_READY_DELAY_TIME_MASK, 0x2) | 1337 FIELD_PREP(SB_TG_OSC_EN_DELAY_TIME_MASK, 0x2)); 1338 regmap_update_bits(hdptx->regmap, SB_REG(0116), 1339 AFC_RSTN_DELAY_TIME_MASK, 1340 FIELD_PREP(AFC_RSTN_DELAY_TIME_MASK, 0x2)); 1341 regmap_update_bits(hdptx->regmap, SB_REG(0117), 1342 FAST_PULSE_TIME_MASK, 1343 FIELD_PREP(FAST_PULSE_TIME_MASK, 0x4)); 1344 regmap_update_bits(hdptx->regmap, SB_REG(0118), 1345 SB_TG_EARC_DMRX_RECVRD_CLK_CNT_MASK, 1346 FIELD_PREP(SB_TG_EARC_DMRX_RECVRD_CLK_CNT_MASK, 0xa)); 1347 1348 regmap_update_bits(hdptx->regmap, SB_REG(011a), SB_TG_CNT_RUN_NO_7_0_MASK, 1349 FIELD_PREP(SB_TG_CNT_RUN_NO_7_0_MASK, 0x3)); 1350 regmap_update_bits(hdptx->regmap, SB_REG(011b), 1351 SB_EARC_SIG_DET_BYPASS_MASK | SB_AFC_TOL_MASK, 1352 FIELD_PREP(SB_EARC_SIG_DET_BYPASS_MASK, 0x1) | 1353 FIELD_PREP(SB_AFC_TOL_MASK, 0x3)); 1354 regmap_update_bits(hdptx->regmap, SB_REG(011c), SB_AFC_STB_NUM_MASK, 1355 FIELD_PREP(SB_AFC_STB_NUM_MASK, 0x4)); 1356 regmap_update_bits(hdptx->regmap, SB_REG(011d), SB_TG_OSC_CNT_MIN_MASK, 1357 FIELD_PREP(SB_TG_OSC_CNT_MIN_MASK, 0x67)); 1358 regmap_update_bits(hdptx->regmap, SB_REG(011e), SB_TG_OSC_CNT_MAX_MASK, 1359 FIELD_PREP(SB_TG_OSC_CNT_MAX_MASK, 0x6a)); 1360 regmap_update_bits(hdptx->regmap, SB_REG(011f), SB_PWM_AFC_CTRL_MASK, 1361 FIELD_PREP(SB_PWM_AFC_CTRL_MASK, 0x5)); 1362 regmap_update_bits(hdptx->regmap, SB_REG(011f), SB_RCAL_RSTN_MASK, 1363 FIELD_PREP(SB_RCAL_RSTN_MASK, 0x1)); 1364 regmap_update_bits(hdptx->regmap, SB_REG(0120), SB_AUX_EN_IN_MASK, 1365 FIELD_PREP(SB_AUX_EN_IN_MASK, 0x1)); 1366 1367 regmap_update_bits(hdptx->regmap, SB_REG(0102), OVRD_SB_RXTERM_EN_MASK, 1368 FIELD_PREP(OVRD_SB_RXTERM_EN_MASK, 0x1)); 1369 regmap_update_bits(hdptx->regmap, SB_REG(0103), OVRD_SB_RX_RESCAL_DONE_MASK, 1370 FIELD_PREP(OVRD_SB_RX_RESCAL_DONE_MASK, 0x1)); 1371 regmap_update_bits(hdptx->regmap, SB_REG(0104), OVRD_SB_EN_MASK, 1372 FIELD_PREP(OVRD_SB_EN_MASK, 0x1)); 1373 regmap_update_bits(hdptx->regmap, SB_REG(0104), OVRD_SB_AUX_EN_MASK, 1374 FIELD_PREP(OVRD_SB_AUX_EN_MASK, 0x1)); 1375 1376 regmap_update_bits(hdptx->regmap, SB_REG(010f), OVRD_SB_VREG_EN_MASK, 1377 FIELD_PREP(OVRD_SB_VREG_EN_MASK, 0x1)); 1378 1379 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1380 HDPTX_I_BGR_EN << 16 | FIELD_PREP(HDPTX_I_BGR_EN, 0x1)); 1381 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1382 HDPTX_I_BIAS_EN << 16 | FIELD_PREP(HDPTX_I_BIAS_EN, 0x1)); 1383 usleep_range(20, 25); 1384 1385 reset_control_deassert(hdptx->rsts[RST_INIT].rstc); 1386 usleep_range(20, 25); 1387 reset_control_deassert(hdptx->rsts[RST_CMN].rstc); 1388 usleep_range(20, 25); 1389 1390 regmap_update_bits(hdptx->regmap, SB_REG(0103), OVRD_SB_RX_RESCAL_DONE_MASK, 1391 FIELD_PREP(OVRD_SB_RX_RESCAL_DONE_MASK, 0x1)); 1392 usleep_range(100, 110); 1393 regmap_update_bits(hdptx->regmap, SB_REG(0104), SB_EN_MASK, 1394 FIELD_PREP(SB_EN_MASK, 0x1)); 1395 usleep_range(100, 110); 1396 regmap_update_bits(hdptx->regmap, SB_REG(0102), SB_RXTERM_EN_MASK, 1397 FIELD_PREP(SB_RXTERM_EN_MASK, 0x1)); 1398 usleep_range(20, 25); 1399 regmap_update_bits(hdptx->regmap, SB_REG(010f), SB_VREG_EN_MASK, 1400 FIELD_PREP(SB_VREG_EN_MASK, 0x1)); 1401 usleep_range(20, 25); 1402 regmap_update_bits(hdptx->regmap, SB_REG(0104), SB_AUX_EN_MASK, 1403 FIELD_PREP(SB_AUX_EN_MASK, 0x1)); 1404 usleep_range(100, 110); 1405 1406 ret = regmap_read_poll_timeout(hdptx->grf, GRF_HDPTX_STATUS, 1407 status, FIELD_GET(HDPTX_O_SB_RDY, status), 1408 50, 1000); 1409 if (ret) { 1410 dev_err(hdptx->dev, "Failed to get phy sb ready: %d\n", ret); 1411 return ret; 1412 } 1413 1414 return 0; 1415 } 1416 1417 static int rk_hdptx_phy_power_on(struct phy *phy) 1418 { 1419 struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy); 1420 enum phy_mode mode = phy_get_mode(phy); 1421 int ret, lane; 1422 1423 if (mode != PHY_MODE_DP) { 1424 if (!hdptx->hdmi_cfg.tmds_char_rate) { 1425 /* 1426 * FIXME: Temporary workaround to setup TMDS char rate 1427 * from the RK DW HDMI QP bridge driver. 1428 * Will be removed as soon the switch to the HDMI PHY 1429 * configuration API has been completed on both ends. 1430 */ 1431 hdptx->hdmi_cfg.tmds_char_rate = phy_get_bus_width(hdptx->phy) & 0xfffffff; 1432 hdptx->hdmi_cfg.tmds_char_rate *= 100; 1433 } 1434 1435 dev_dbg(hdptx->dev, "%s rate=%llu bpc=%u\n", __func__, 1436 hdptx->hdmi_cfg.tmds_char_rate, hdptx->hdmi_cfg.bpc); 1437 } 1438 1439 ret = rk_hdptx_phy_consumer_get(hdptx); 1440 if (ret) 1441 return ret; 1442 1443 if (mode == PHY_MODE_DP) { 1444 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1445 HDPTX_MODE_SEL << 16 | FIELD_PREP(HDPTX_MODE_SEL, 0x1)); 1446 1447 for (lane = 0; lane < 4; lane++) { 1448 regmap_update_bits(hdptx->regmap, LANE_REG(031e) + 0x400 * lane, 1449 LN_POLARITY_INV_MASK | LN_LANE_MODE_MASK, 1450 FIELD_PREP(LN_POLARITY_INV_MASK, 0) | 1451 FIELD_PREP(LN_LANE_MODE_MASK, 1)); 1452 } 1453 1454 regmap_update_bits(hdptx->regmap, LNTOP_REG(0200), PROTOCOL_SEL_MASK, 1455 FIELD_PREP(PROTOCOL_SEL_MASK, 0x0)); 1456 regmap_update_bits(hdptx->regmap, LNTOP_REG(0206), DATA_BUS_WIDTH_MASK, 1457 FIELD_PREP(DATA_BUS_WIDTH_MASK, 0x1)); 1458 regmap_update_bits(hdptx->regmap, LNTOP_REG(0206), DATA_BUS_WIDTH_SEL_MASK, 1459 FIELD_PREP(DATA_BUS_WIDTH_SEL_MASK, 0x0)); 1460 1461 rk_hdptx_dp_pll_init(hdptx); 1462 1463 ret = rk_hdptx_dp_aux_init(hdptx); 1464 if (ret) 1465 rk_hdptx_phy_consumer_put(hdptx, true); 1466 } else { 1467 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1468 HDPTX_MODE_SEL << 16 | FIELD_PREP(HDPTX_MODE_SEL, 0x0)); 1469 1470 ret = rk_hdptx_ropll_tmds_mode_config(hdptx); 1471 if (ret) 1472 rk_hdptx_phy_consumer_put(hdptx, true); 1473 } 1474 1475 return ret; 1476 } 1477 1478 static int rk_hdptx_phy_power_off(struct phy *phy) 1479 { 1480 struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy); 1481 1482 return rk_hdptx_phy_consumer_put(hdptx, false); 1483 } 1484 1485 static int rk_hdptx_phy_verify_hdmi_config(struct rk_hdptx_phy *hdptx, 1486 struct phy_configure_opts_hdmi *hdmi) 1487 { 1488 int i; 1489 1490 if (!hdmi->tmds_char_rate || hdmi->tmds_char_rate > HDMI20_MAX_RATE) 1491 return -EINVAL; 1492 1493 for (i = 0; i < ARRAY_SIZE(ropll_tmds_cfg); i++) 1494 if (hdmi->tmds_char_rate == ropll_tmds_cfg[i].rate) 1495 break; 1496 1497 if (i == ARRAY_SIZE(ropll_tmds_cfg) && 1498 !rk_hdptx_phy_clk_pll_calc(hdmi->tmds_char_rate, NULL)) 1499 return -EINVAL; 1500 1501 if (!hdmi->bpc) 1502 hdmi->bpc = 8; 1503 1504 switch (hdmi->bpc) { 1505 case 8: 1506 case 10: 1507 case 12: 1508 case 16: 1509 break; 1510 default: 1511 return -EINVAL; 1512 } 1513 1514 return 0; 1515 } 1516 1517 static int rk_hdptx_phy_verify_dp_config(struct rk_hdptx_phy *hdptx, 1518 struct phy_configure_opts_dp *dp) 1519 { 1520 int i; 1521 1522 if (dp->set_rate) { 1523 switch (dp->link_rate) { 1524 case 1620: 1525 case 2700: 1526 case 5400: 1527 break; 1528 default: 1529 return -EINVAL; 1530 } 1531 } 1532 1533 if (dp->set_lanes) { 1534 switch (dp->lanes) { 1535 case 1: 1536 case 2: 1537 case 4: 1538 break; 1539 default: 1540 return -EINVAL; 1541 } 1542 } 1543 1544 if (dp->set_voltages) { 1545 for (i = 0; i < hdptx->lanes; i++) { 1546 if (dp->voltage[i] > 3 || dp->pre[i] > 3) 1547 return -EINVAL; 1548 1549 if (dp->voltage[i] + dp->pre[i] > 3) 1550 return -EINVAL; 1551 } 1552 } 1553 1554 return 0; 1555 } 1556 1557 static int rk_hdptx_phy_set_rate(struct rk_hdptx_phy *hdptx, 1558 struct phy_configure_opts_dp *dp) 1559 { 1560 u32 bw, status; 1561 int ret; 1562 1563 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1564 HDPTX_I_PLL_EN << 16 | FIELD_PREP(HDPTX_I_PLL_EN, 0x0)); 1565 1566 switch (dp->link_rate) { 1567 case 1620: 1568 bw = DP_BW_RBR; 1569 break; 1570 case 2700: 1571 bw = DP_BW_HBR; 1572 break; 1573 case 5400: 1574 bw = DP_BW_HBR2; 1575 break; 1576 default: 1577 return -EINVAL; 1578 } 1579 hdptx->link_rate = dp->link_rate; 1580 1581 regmap_update_bits(hdptx->regmap, CMN_REG(0008), OVRD_LCPLL_EN_MASK | LCPLL_EN_MASK, 1582 FIELD_PREP(OVRD_LCPLL_EN_MASK, 0x1) | 1583 FIELD_PREP(LCPLL_EN_MASK, 0x0)); 1584 1585 regmap_update_bits(hdptx->regmap, CMN_REG(003d), OVRD_ROPLL_EN_MASK | ROPLL_EN_MASK, 1586 FIELD_PREP(OVRD_ROPLL_EN_MASK, 0x1) | 1587 FIELD_PREP(ROPLL_EN_MASK, 0x1)); 1588 1589 if (dp->ssc) { 1590 regmap_update_bits(hdptx->regmap, CMN_REG(0074), 1591 OVRD_ROPLL_SSC_EN_MASK | ROPLL_SSC_EN_MASK, 1592 FIELD_PREP(OVRD_ROPLL_SSC_EN_MASK, 0x1) | 1593 FIELD_PREP(ROPLL_SSC_EN_MASK, 0x1)); 1594 regmap_write(hdptx->regmap, CMN_REG(0075), 1595 FIELD_PREP(ANA_ROPLL_SSC_FM_DEVIATION_MASK, 0xc)); 1596 regmap_update_bits(hdptx->regmap, CMN_REG(0076), 1597 ANA_ROPLL_SSC_FM_FREQ_MASK, 1598 FIELD_PREP(ANA_ROPLL_SSC_FM_FREQ_MASK, 0x1f)); 1599 1600 regmap_update_bits(hdptx->regmap, CMN_REG(0099), SSC_EN_MASK, 1601 FIELD_PREP(SSC_EN_MASK, 0x2)); 1602 } else { 1603 regmap_update_bits(hdptx->regmap, CMN_REG(0074), 1604 OVRD_ROPLL_SSC_EN_MASK | ROPLL_SSC_EN_MASK, 1605 FIELD_PREP(OVRD_ROPLL_SSC_EN_MASK, 0x1) | 1606 FIELD_PREP(ROPLL_SSC_EN_MASK, 0x0)); 1607 regmap_write(hdptx->regmap, CMN_REG(0075), 1608 FIELD_PREP(ANA_ROPLL_SSC_FM_DEVIATION_MASK, 0x20)); 1609 regmap_update_bits(hdptx->regmap, CMN_REG(0076), 1610 ANA_ROPLL_SSC_FM_FREQ_MASK, 1611 FIELD_PREP(ANA_ROPLL_SSC_FM_FREQ_MASK, 0xc)); 1612 1613 regmap_update_bits(hdptx->regmap, CMN_REG(0099), SSC_EN_MASK, 1614 FIELD_PREP(SSC_EN_MASK, 0x0)); 1615 } 1616 1617 regmap_update_bits(hdptx->regmap, CMN_REG(0095), DP_TX_LINK_BW_MASK, 1618 FIELD_PREP(DP_TX_LINK_BW_MASK, bw)); 1619 1620 regmap_write(hdptx->grf, GRF_HDPTX_CON0, 1621 HDPTX_I_PLL_EN << 16 | FIELD_PREP(HDPTX_I_PLL_EN, 0x1)); 1622 1623 ret = regmap_read_poll_timeout(hdptx->grf, GRF_HDPTX_STATUS, 1624 status, FIELD_GET(HDPTX_O_PLL_LOCK_DONE, status), 1625 50, 1000); 1626 if (ret) { 1627 dev_err(hdptx->dev, "Failed to get phy pll lock: %d\n", ret); 1628 return ret; 1629 } 1630 1631 return 0; 1632 } 1633 1634 static int rk_hdptx_phy_set_lanes(struct rk_hdptx_phy *hdptx, 1635 struct phy_configure_opts_dp *dp) 1636 { 1637 hdptx->lanes = dp->lanes; 1638 1639 regmap_update_bits(hdptx->regmap, LNTOP_REG(0207), LANE_EN_MASK, 1640 FIELD_PREP(LANE_EN_MASK, GENMASK(hdptx->lanes - 1, 0))); 1641 1642 return 0; 1643 } 1644 1645 static void rk_hdptx_phy_set_voltage(struct rk_hdptx_phy *hdptx, 1646 struct phy_configure_opts_dp *dp, 1647 u8 lane) 1648 { 1649 const struct tx_drv_ctrl *ctrl; 1650 u32 offset = lane * 0x400; 1651 1652 switch (hdptx->link_rate) { 1653 case 1620: 1654 ctrl = &tx_drv_ctrl_rbr[dp->voltage[lane]][dp->pre[lane]]; 1655 regmap_update_bits(hdptx->regmap, LANE_REG(030a) + offset, 1656 LN_TX_JEQ_EVEN_CTRL_RBR_MASK, 1657 FIELD_PREP(LN_TX_JEQ_EVEN_CTRL_RBR_MASK, 1658 ctrl->tx_jeq_even_ctrl)); 1659 regmap_update_bits(hdptx->regmap, LANE_REG(030c) + offset, 1660 LN_TX_JEQ_ODD_CTRL_RBR_MASK, 1661 FIELD_PREP(LN_TX_JEQ_ODD_CTRL_RBR_MASK, 1662 ctrl->tx_jeq_odd_ctrl)); 1663 regmap_update_bits(hdptx->regmap, LANE_REG(0311) + offset, 1664 LN_TX_SER_40BIT_EN_RBR_MASK, 1665 FIELD_PREP(LN_TX_SER_40BIT_EN_RBR_MASK, 0x1)); 1666 break; 1667 case 2700: 1668 ctrl = &tx_drv_ctrl_hbr[dp->voltage[lane]][dp->pre[lane]]; 1669 regmap_update_bits(hdptx->regmap, LANE_REG(030b) + offset, 1670 LN_TX_JEQ_EVEN_CTRL_HBR_MASK, 1671 FIELD_PREP(LN_TX_JEQ_EVEN_CTRL_HBR_MASK, 1672 ctrl->tx_jeq_even_ctrl)); 1673 regmap_update_bits(hdptx->regmap, LANE_REG(030d) + offset, 1674 LN_TX_JEQ_ODD_CTRL_HBR_MASK, 1675 FIELD_PREP(LN_TX_JEQ_ODD_CTRL_HBR_MASK, 1676 ctrl->tx_jeq_odd_ctrl)); 1677 regmap_update_bits(hdptx->regmap, LANE_REG(0311) + offset, 1678 LN_TX_SER_40BIT_EN_HBR_MASK, 1679 FIELD_PREP(LN_TX_SER_40BIT_EN_HBR_MASK, 0x1)); 1680 break; 1681 case 5400: 1682 default: 1683 ctrl = &tx_drv_ctrl_hbr2[dp->voltage[lane]][dp->pre[lane]]; 1684 regmap_update_bits(hdptx->regmap, LANE_REG(030b) + offset, 1685 LN_TX_JEQ_EVEN_CTRL_HBR2_MASK, 1686 FIELD_PREP(LN_TX_JEQ_EVEN_CTRL_HBR2_MASK, 1687 ctrl->tx_jeq_even_ctrl)); 1688 regmap_update_bits(hdptx->regmap, LANE_REG(030d) + offset, 1689 LN_TX_JEQ_ODD_CTRL_HBR2_MASK, 1690 FIELD_PREP(LN_TX_JEQ_ODD_CTRL_HBR2_MASK, 1691 ctrl->tx_jeq_odd_ctrl)); 1692 regmap_update_bits(hdptx->regmap, LANE_REG(0311) + offset, 1693 LN_TX_SER_40BIT_EN_HBR2_MASK, 1694 FIELD_PREP(LN_TX_SER_40BIT_EN_HBR2_MASK, 0x1)); 1695 break; 1696 } 1697 1698 regmap_update_bits(hdptx->regmap, LANE_REG(0303) + offset, 1699 OVRD_LN_TX_DRV_LVL_CTRL_MASK | LN_TX_DRV_LVL_CTRL_MASK, 1700 FIELD_PREP(OVRD_LN_TX_DRV_LVL_CTRL_MASK, 0x1) | 1701 FIELD_PREP(LN_TX_DRV_LVL_CTRL_MASK, 1702 ctrl->tx_drv_lvl_ctrl)); 1703 regmap_update_bits(hdptx->regmap, LANE_REG(0304) + offset, 1704 OVRD_LN_TX_DRV_POST_LVL_CTRL_MASK | 1705 LN_TX_DRV_POST_LVL_CTRL_MASK, 1706 FIELD_PREP(OVRD_LN_TX_DRV_POST_LVL_CTRL_MASK, 0x1) | 1707 FIELD_PREP(LN_TX_DRV_POST_LVL_CTRL_MASK, 1708 ctrl->tx_drv_post_lvl_ctrl)); 1709 regmap_update_bits(hdptx->regmap, LANE_REG(0305) + offset, 1710 OVRD_LN_TX_DRV_PRE_LVL_CTRL_MASK | 1711 LN_TX_DRV_PRE_LVL_CTRL_MASK, 1712 FIELD_PREP(OVRD_LN_TX_DRV_PRE_LVL_CTRL_MASK, 0x1) | 1713 FIELD_PREP(LN_TX_DRV_PRE_LVL_CTRL_MASK, 1714 ctrl->tx_drv_pre_lvl_ctrl)); 1715 regmap_update_bits(hdptx->regmap, LANE_REG(0306) + offset, 1716 LN_ANA_TX_DRV_IDRV_IDN_CTRL_MASK | 1717 LN_ANA_TX_DRV_IDRV_IUP_CTRL_MASK | 1718 LN_ANA_TX_DRV_ACCDRV_EN_MASK, 1719 FIELD_PREP(LN_ANA_TX_DRV_IDRV_IDN_CTRL_MASK, 1720 ctrl->ana_tx_drv_idrv_idn_ctrl) | 1721 FIELD_PREP(LN_ANA_TX_DRV_IDRV_IUP_CTRL_MASK, 1722 ctrl->ana_tx_drv_idrv_iup_ctrl) | 1723 FIELD_PREP(LN_ANA_TX_DRV_ACCDRV_EN_MASK, 1724 ctrl->ana_tx_drv_accdrv_en)); 1725 regmap_update_bits(hdptx->regmap, LANE_REG(0307) + offset, 1726 LN_ANA_TX_DRV_ACCDRV_POL_SEL_MASK | 1727 LN_ANA_TX_DRV_ACCDRV_CTRL_MASK, 1728 FIELD_PREP(LN_ANA_TX_DRV_ACCDRV_POL_SEL_MASK, 0x1) | 1729 FIELD_PREP(LN_ANA_TX_DRV_ACCDRV_CTRL_MASK, 1730 ctrl->ana_tx_drv_accdrv_ctrl)); 1731 1732 regmap_update_bits(hdptx->regmap, LANE_REG(030a) + offset, 1733 LN_ANA_TX_JEQ_EN_MASK, 1734 FIELD_PREP(LN_ANA_TX_JEQ_EN_MASK, ctrl->ana_tx_jeq_en)); 1735 1736 regmap_update_bits(hdptx->regmap, LANE_REG(0310) + offset, 1737 LN_ANA_TX_SYNC_LOSS_DET_MODE_MASK, 1738 FIELD_PREP(LN_ANA_TX_SYNC_LOSS_DET_MODE_MASK, 0x3)); 1739 1740 regmap_update_bits(hdptx->regmap, LANE_REG(0316) + offset, 1741 LN_ANA_TX_SER_VREG_GAIN_CTRL_MASK, 1742 FIELD_PREP(LN_ANA_TX_SER_VREG_GAIN_CTRL_MASK, 0x2)); 1743 1744 regmap_update_bits(hdptx->regmap, LANE_REG(031b) + offset, 1745 LN_ANA_TX_RESERVED_MASK, 1746 FIELD_PREP(LN_ANA_TX_RESERVED_MASK, 0x1)); 1747 } 1748 1749 static int rk_hdptx_phy_set_voltages(struct rk_hdptx_phy *hdptx, 1750 struct phy_configure_opts_dp *dp) 1751 { 1752 u8 lane; 1753 u32 status; 1754 int ret; 1755 1756 for (lane = 0; lane < hdptx->lanes; lane++) 1757 rk_hdptx_phy_set_voltage(hdptx, dp, lane); 1758 1759 reset_control_deassert(hdptx->rsts[RST_LANE].rstc); 1760 1761 ret = regmap_read_poll_timeout(hdptx->grf, GRF_HDPTX_STATUS, 1762 status, FIELD_GET(HDPTX_O_PHY_RDY, status), 1763 50, 5000); 1764 if (ret) { 1765 dev_err(hdptx->dev, "Failed to get phy ready: %d\n", ret); 1766 return ret; 1767 } 1768 1769 return 0; 1770 } 1771 1772 static int rk_hdptx_phy_configure(struct phy *phy, union phy_configure_opts *opts) 1773 { 1774 struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy); 1775 enum phy_mode mode = phy_get_mode(phy); 1776 int ret; 1777 1778 if (mode != PHY_MODE_DP) { 1779 ret = rk_hdptx_phy_verify_hdmi_config(hdptx, &opts->hdmi); 1780 if (ret) { 1781 dev_err(hdptx->dev, "invalid hdmi params for phy configure\n"); 1782 } else { 1783 hdptx->hdmi_cfg = opts->hdmi; 1784 hdptx->restrict_rate_change = true; 1785 } 1786 1787 dev_dbg(hdptx->dev, "%s rate=%llu bpc=%u\n", __func__, 1788 hdptx->hdmi_cfg.tmds_char_rate, hdptx->hdmi_cfg.bpc); 1789 return ret; 1790 } 1791 1792 ret = rk_hdptx_phy_verify_dp_config(hdptx, &opts->dp); 1793 if (ret) { 1794 dev_err(hdptx->dev, "invalid dp params for phy configure\n"); 1795 return ret; 1796 } 1797 1798 if (opts->dp.set_rate) { 1799 ret = rk_hdptx_phy_set_rate(hdptx, &opts->dp); 1800 if (ret) { 1801 dev_err(hdptx->dev, "failed to set rate: %d\n", ret); 1802 return ret; 1803 } 1804 } 1805 1806 if (opts->dp.set_lanes) { 1807 ret = rk_hdptx_phy_set_lanes(hdptx, &opts->dp); 1808 if (ret) { 1809 dev_err(hdptx->dev, "failed to set lanes: %d\n", ret); 1810 return ret; 1811 } 1812 } 1813 1814 if (opts->dp.set_voltages) { 1815 ret = rk_hdptx_phy_set_voltages(hdptx, &opts->dp); 1816 if (ret) { 1817 dev_err(hdptx->dev, "failed to set voltages: %d\n", 1818 ret); 1819 return ret; 1820 } 1821 } 1822 1823 return 0; 1824 } 1825 1826 static int rk_hdptx_phy_validate(struct phy *phy, enum phy_mode mode, 1827 int submode, union phy_configure_opts *opts) 1828 { 1829 struct rk_hdptx_phy *hdptx = phy_get_drvdata(phy); 1830 1831 if (mode != PHY_MODE_DP) 1832 return rk_hdptx_phy_verify_hdmi_config(hdptx, &opts->hdmi); 1833 1834 return rk_hdptx_phy_verify_dp_config(hdptx, &opts->dp); 1835 } 1836 1837 static const struct phy_ops rk_hdptx_phy_ops = { 1838 .power_on = rk_hdptx_phy_power_on, 1839 .power_off = rk_hdptx_phy_power_off, 1840 .configure = rk_hdptx_phy_configure, 1841 .validate = rk_hdptx_phy_validate, 1842 .owner = THIS_MODULE, 1843 }; 1844 1845 static struct rk_hdptx_phy *to_rk_hdptx_phy(struct clk_hw *hw) 1846 { 1847 return container_of(hw, struct rk_hdptx_phy, hw); 1848 } 1849 1850 static int rk_hdptx_phy_clk_prepare(struct clk_hw *hw) 1851 { 1852 struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw); 1853 1854 return rk_hdptx_phy_consumer_get(hdptx); 1855 } 1856 1857 static void rk_hdptx_phy_clk_unprepare(struct clk_hw *hw) 1858 { 1859 struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw); 1860 1861 rk_hdptx_phy_consumer_put(hdptx, true); 1862 } 1863 1864 static unsigned long rk_hdptx_phy_clk_recalc_rate(struct clk_hw *hw, 1865 unsigned long parent_rate) 1866 { 1867 struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw); 1868 1869 return hdptx->hw_rate; 1870 } 1871 1872 static long rk_hdptx_phy_clk_round_rate(struct clk_hw *hw, unsigned long rate, 1873 unsigned long *parent_rate) 1874 { 1875 struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw); 1876 1877 /* 1878 * FIXME: Temporarily allow altering TMDS char rate via CCF. 1879 * To be dropped as soon as the RK DW HDMI QP bridge driver 1880 * switches to make use of phy_configure(). 1881 */ 1882 if (!hdptx->restrict_rate_change && rate != hdptx->hdmi_cfg.tmds_char_rate) { 1883 struct phy_configure_opts_hdmi hdmi = { 1884 .tmds_char_rate = rate, 1885 }; 1886 int ret = rk_hdptx_phy_verify_hdmi_config(hdptx, &hdmi); 1887 1888 if (ret) 1889 return ret; 1890 1891 hdptx->hdmi_cfg = hdmi; 1892 } 1893 1894 /* 1895 * The TMDS char rate shall be adjusted via phy_configure() only, 1896 * hence ensure rk_hdptx_phy_clk_set_rate() won't be invoked with 1897 * a different rate argument. 1898 */ 1899 return hdptx->hdmi_cfg.tmds_char_rate; 1900 } 1901 1902 static int rk_hdptx_phy_clk_set_rate(struct clk_hw *hw, unsigned long rate, 1903 unsigned long parent_rate) 1904 { 1905 struct rk_hdptx_phy *hdptx = to_rk_hdptx_phy(hw); 1906 1907 /* Revert any unlikely TMDS char rate change since round_rate() */ 1908 if (hdptx->hdmi_cfg.tmds_char_rate != rate) { 1909 dev_warn(hdptx->dev, "Reverting unexpected rate change from %lu to %llu\n", 1910 rate, hdptx->hdmi_cfg.tmds_char_rate); 1911 hdptx->hdmi_cfg.tmds_char_rate = rate; 1912 } 1913 1914 /* 1915 * The TMDS char rate would be normally programmed in HW during 1916 * phy_ops.power_on() or clk_ops.prepare() callbacks, but it might 1917 * happen that the former gets fired too late, i.e. after this call, 1918 * while the latter being executed only once, i.e. when clock remains 1919 * in the prepared state during rate changes. 1920 */ 1921 return rk_hdptx_ropll_tmds_cmn_config(hdptx); 1922 } 1923 1924 static const struct clk_ops hdptx_phy_clk_ops = { 1925 .prepare = rk_hdptx_phy_clk_prepare, 1926 .unprepare = rk_hdptx_phy_clk_unprepare, 1927 .recalc_rate = rk_hdptx_phy_clk_recalc_rate, 1928 .round_rate = rk_hdptx_phy_clk_round_rate, 1929 .set_rate = rk_hdptx_phy_clk_set_rate, 1930 }; 1931 1932 static int rk_hdptx_phy_clk_register(struct rk_hdptx_phy *hdptx) 1933 { 1934 struct device *dev = hdptx->dev; 1935 const char *name, *pname; 1936 struct clk *refclk; 1937 int ret; 1938 1939 refclk = devm_clk_get(dev, "ref"); 1940 if (IS_ERR(refclk)) 1941 return dev_err_probe(dev, PTR_ERR(refclk), 1942 "Failed to get ref clock\n"); 1943 1944 name = hdptx->phy_id > 0 ? "clk_hdmiphy_pixel1" : "clk_hdmiphy_pixel0"; 1945 pname = __clk_get_name(refclk); 1946 1947 hdptx->hw.init = CLK_HW_INIT(name, pname, &hdptx_phy_clk_ops, 1948 CLK_GET_RATE_NOCACHE); 1949 1950 ret = devm_clk_hw_register(dev, &hdptx->hw); 1951 if (ret) 1952 return dev_err_probe(dev, ret, "Failed to register clock\n"); 1953 1954 ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get, &hdptx->hw); 1955 if (ret) 1956 return dev_err_probe(dev, ret, 1957 "Failed to register clk provider\n"); 1958 return 0; 1959 } 1960 1961 static int rk_hdptx_phy_runtime_suspend(struct device *dev) 1962 { 1963 struct rk_hdptx_phy *hdptx = dev_get_drvdata(dev); 1964 1965 clk_bulk_disable_unprepare(hdptx->nr_clks, hdptx->clks); 1966 1967 return 0; 1968 } 1969 1970 static int rk_hdptx_phy_runtime_resume(struct device *dev) 1971 { 1972 struct rk_hdptx_phy *hdptx = dev_get_drvdata(dev); 1973 int ret; 1974 1975 ret = clk_bulk_prepare_enable(hdptx->nr_clks, hdptx->clks); 1976 if (ret) 1977 dev_err(hdptx->dev, "Failed to enable clocks: %d\n", ret); 1978 1979 return ret; 1980 } 1981 1982 static int rk_hdptx_phy_probe(struct platform_device *pdev) 1983 { 1984 const struct rk_hdptx_phy_cfg *cfgs; 1985 struct phy_provider *phy_provider; 1986 struct device *dev = &pdev->dev; 1987 struct rk_hdptx_phy *hdptx; 1988 struct resource *res; 1989 void __iomem *regs; 1990 int ret, id; 1991 1992 hdptx = devm_kzalloc(dev, sizeof(*hdptx), GFP_KERNEL); 1993 if (!hdptx) 1994 return -ENOMEM; 1995 1996 hdptx->dev = dev; 1997 hdptx->hdmi_cfg.bpc = 8; 1998 1999 regs = devm_platform_get_and_ioremap_resource(pdev, 0, &res); 2000 if (IS_ERR(regs)) 2001 return dev_err_probe(dev, PTR_ERR(regs), 2002 "Failed to ioremap resource\n"); 2003 2004 cfgs = device_get_match_data(dev); 2005 if (!cfgs) 2006 return dev_err_probe(dev, -EINVAL, "missing match data\n"); 2007 2008 /* find the phy-id from the io address */ 2009 hdptx->phy_id = -ENODEV; 2010 for (id = 0; id < cfgs->num_phys; id++) { 2011 if (res->start == cfgs->phy_ids[id]) { 2012 hdptx->phy_id = id; 2013 break; 2014 } 2015 } 2016 2017 if (hdptx->phy_id < 0) 2018 return dev_err_probe(dev, -ENODEV, "no matching device found\n"); 2019 2020 ret = devm_clk_bulk_get_all(dev, &hdptx->clks); 2021 if (ret < 0) 2022 return dev_err_probe(dev, ret, "Failed to get clocks\n"); 2023 if (ret == 0) 2024 return dev_err_probe(dev, -EINVAL, "Missing clocks\n"); 2025 2026 hdptx->nr_clks = ret; 2027 2028 hdptx->regmap = devm_regmap_init_mmio(dev, regs, 2029 &rk_hdptx_phy_regmap_config); 2030 if (IS_ERR(hdptx->regmap)) 2031 return dev_err_probe(dev, PTR_ERR(hdptx->regmap), 2032 "Failed to init regmap\n"); 2033 2034 hdptx->rsts[RST_APB].id = "apb"; 2035 hdptx->rsts[RST_INIT].id = "init"; 2036 hdptx->rsts[RST_CMN].id = "cmn"; 2037 hdptx->rsts[RST_LANE].id = "lane"; 2038 2039 ret = devm_reset_control_bulk_get_exclusive(dev, RST_MAX, hdptx->rsts); 2040 if (ret) 2041 return dev_err_probe(dev, ret, "Failed to get resets\n"); 2042 2043 hdptx->grf = syscon_regmap_lookup_by_phandle(dev->of_node, 2044 "rockchip,grf"); 2045 if (IS_ERR(hdptx->grf)) 2046 return dev_err_probe(dev, PTR_ERR(hdptx->grf), 2047 "Could not get GRF syscon\n"); 2048 2049 platform_set_drvdata(pdev, hdptx); 2050 2051 ret = devm_pm_runtime_enable(dev); 2052 if (ret) 2053 return dev_err_probe(dev, ret, "Failed to enable runtime PM\n"); 2054 2055 hdptx->phy = devm_phy_create(dev, NULL, &rk_hdptx_phy_ops); 2056 if (IS_ERR(hdptx->phy)) 2057 return dev_err_probe(dev, PTR_ERR(hdptx->phy), 2058 "Failed to create HDMI PHY\n"); 2059 2060 phy_set_drvdata(hdptx->phy, hdptx); 2061 phy_set_bus_width(hdptx->phy, 8); 2062 2063 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); 2064 if (IS_ERR(phy_provider)) 2065 return dev_err_probe(dev, PTR_ERR(phy_provider), 2066 "Failed to register PHY provider\n"); 2067 2068 reset_control_deassert(hdptx->rsts[RST_APB].rstc); 2069 reset_control_deassert(hdptx->rsts[RST_CMN].rstc); 2070 reset_control_deassert(hdptx->rsts[RST_INIT].rstc); 2071 2072 return rk_hdptx_phy_clk_register(hdptx); 2073 } 2074 2075 static const struct dev_pm_ops rk_hdptx_phy_pm_ops = { 2076 RUNTIME_PM_OPS(rk_hdptx_phy_runtime_suspend, 2077 rk_hdptx_phy_runtime_resume, NULL) 2078 }; 2079 2080 static const struct rk_hdptx_phy_cfg rk3576_hdptx_phy_cfgs = { 2081 .num_phys = 1, 2082 .phy_ids = { 2083 0x2b000000, 2084 }, 2085 }; 2086 2087 static const struct rk_hdptx_phy_cfg rk3588_hdptx_phy_cfgs = { 2088 .num_phys = 2, 2089 .phy_ids = { 2090 0xfed60000, 2091 0xfed70000, 2092 }, 2093 }; 2094 2095 static const struct of_device_id rk_hdptx_phy_of_match[] = { 2096 { 2097 .compatible = "rockchip,rk3576-hdptx-phy", 2098 .data = &rk3576_hdptx_phy_cfgs 2099 }, 2100 { 2101 .compatible = "rockchip,rk3588-hdptx-phy", 2102 .data = &rk3588_hdptx_phy_cfgs 2103 }, 2104 {} 2105 }; 2106 MODULE_DEVICE_TABLE(of, rk_hdptx_phy_of_match); 2107 2108 static struct platform_driver rk_hdptx_phy_driver = { 2109 .probe = rk_hdptx_phy_probe, 2110 .driver = { 2111 .name = "rockchip-hdptx-phy", 2112 .pm = &rk_hdptx_phy_pm_ops, 2113 .of_match_table = rk_hdptx_phy_of_match, 2114 }, 2115 }; 2116 module_platform_driver(rk_hdptx_phy_driver); 2117 2118 MODULE_AUTHOR("Algea Cao <algea.cao@rock-chips.com>"); 2119 MODULE_AUTHOR("Cristian Ciocaltea <cristian.ciocaltea@collabora.com>"); 2120 MODULE_AUTHOR("Damon Ding <damon.ding@rock-chips.com>"); 2121 MODULE_DESCRIPTION("Samsung HDMI/eDP Transmitter Combo PHY Driver"); 2122 MODULE_LICENSE("GPL"); 2123