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