1 /* 2 * (C) Copyright 2008-2017 Fuzhou Rockchip Electronics Co., Ltd 3 * 4 * SPDX-License-Identifier: GPL-2.0+ 5 */ 6 7 #include <config.h> 8 #include <common.h> 9 #include <errno.h> 10 #include <malloc.h> 11 #include <fdtdec.h> 12 #include <fdt_support.h> 13 #include <asm/unaligned.h> 14 #include <linux/list.h> 15 #include <asm/io.h> 16 #include <dm/device.h> 17 #include <syscon.h> 18 #include <asm/arch-rockchip/clock.h> 19 #include <asm/gpio.h> 20 21 #include "rockchip_display.h" 22 #include "rockchip_crtc.h" 23 #include "rockchip_connector.h" 24 #include "rockchip_lvds.h" 25 26 enum rockchip_lvds_sub_devtype { 27 RK3288_LVDS, 28 RK3366_LVDS, 29 RK3368_LVDS, 30 RK3126_LVDS, 31 }; 32 33 struct rockchip_lvds_chip_data { 34 u32 chip_type; 35 bool has_vop_sel; 36 u32 grf_soc_con5; 37 u32 grf_soc_con6; 38 u32 grf_soc_con7; 39 u32 grf_soc_con15; 40 u32 grf_gpio1d_iomux; 41 }; 42 43 struct rockchip_lvds_device { 44 void *regbase; 45 void *grf; 46 void *ctrl_reg; 47 u32 channel; 48 u32 output; 49 u32 format; 50 struct drm_display_mode *mode; 51 const struct rockchip_lvds_chip_data *pdata; 52 }; 53 54 static inline int lvds_name_to_format(const char *s) 55 { 56 if (!s) 57 return -EINVAL; 58 59 if (strncmp(s, "jeida", 6) == 0) 60 return LVDS_FORMAT_JEIDA; 61 else if (strncmp(s, "vesa", 5) == 0) 62 return LVDS_FORMAT_VESA; 63 64 return -EINVAL; 65 } 66 67 static inline int lvds_name_to_output(const char *s) 68 { 69 if (!s) 70 return -EINVAL; 71 72 if (strncmp(s, "rgb", 3) == 0) 73 return DISPLAY_OUTPUT_RGB; 74 else if (strncmp(s, "lvds", 4) == 0) 75 return DISPLAY_OUTPUT_LVDS; 76 else if (strncmp(s, "duallvds", 8) == 0) 77 return DISPLAY_OUTPUT_DUAL_LVDS; 78 79 return -EINVAL; 80 } 81 82 static inline void lvds_writel(struct rockchip_lvds_device *lvds, 83 u32 offset, u32 val) 84 { 85 writel(val, lvds->regbase + offset); 86 87 if ((lvds->pdata->chip_type == RK3288_LVDS) && 88 (lvds->output == DISPLAY_OUTPUT_DUAL_LVDS)) 89 writel(val, lvds->regbase + offset + 0x100); 90 } 91 92 static inline void lvds_msk_reg(struct rockchip_lvds_device *lvds, u32 offset, 93 u32 msk, u32 val) 94 { 95 u32 temp; 96 97 temp = readl(lvds->regbase + offset) & (0xFF - (msk)); 98 writel(temp | ((val) & (msk)), lvds->regbase + offset); 99 } 100 101 static inline u32 lvds_readl(struct rockchip_lvds_device *lvds, u32 offset) 102 { 103 return readl(lvds->regbase + offset); 104 } 105 106 static inline void lvds_ctrl_writel(struct rockchip_lvds_device *lvds, 107 u32 offset, u32 val) 108 { 109 writel(val, lvds->ctrl_reg + offset); 110 } 111 112 static inline u32 lvds_pmugrf_readl(u32 offset) 113 { 114 return readl((void *)LVDS_PMUGRF_BASE + offset); 115 } 116 117 static inline void lvds_pmugrf_writel(u32 offset, u32 val) 118 { 119 writel(val, (void *)LVDS_PMUGRF_BASE + offset); 120 } 121 122 static inline u32 lvds_phy_lock(struct rockchip_lvds_device *lvds) 123 { 124 u32 val = 0; 125 val = readl(lvds->ctrl_reg + MIPIC_PHY_STATUS); 126 return (val & m_PHY_LOCK_STATUS) ? 1 : 0; 127 } 128 129 static int rockchip_lvds_clk_enable(struct rockchip_lvds_device *lvds) 130 { 131 return 0; 132 } 133 134 const struct rockchip_lvds_chip_data rk3126_lvds_drv_data = { 135 .chip_type = RK3126_LVDS, 136 .grf_soc_con7 = RK3126_GRF_LVDS_CON0, 137 .grf_soc_con15 = RK3126_GRF_CON1, 138 .has_vop_sel = true, 139 }; 140 141 const struct rockchip_lvds_chip_data rk3366_lvds_drv_data = { 142 .chip_type = RK3366_LVDS, 143 .grf_soc_con7 = RK3366_GRF_SOC_CON5, 144 .grf_soc_con15 = RK3366_GRF_SOC_CON6, 145 .has_vop_sel = true, 146 }; 147 148 const struct rockchip_lvds_chip_data rk3368_lvds_drv_data = { 149 .chip_type = RK3368_LVDS, 150 .grf_soc_con7 = RK3368_GRF_SOC_CON7, 151 .grf_soc_con15 = RK3368_GRF_SOC_CON15, 152 .has_vop_sel = false, 153 }; 154 155 const struct rockchip_lvds_chip_data rk3288_lvds_drv_data = { 156 .chip_type = RK3288_LVDS, 157 .has_vop_sel = true, 158 .grf_soc_con6 = 0x025c, 159 .grf_soc_con7 = 0x0260, 160 .grf_gpio1d_iomux = 0x000c, 161 }; 162 163 static int rk336x_lvds_pwr_off(struct display_state *state) 164 { 165 struct connector_state *conn_state = &state->conn_state; 166 struct rockchip_lvds_device *lvds = conn_state->private; 167 168 /* disable lvds lane and power off pll */ 169 lvds_writel(lvds, MIPIPHY_REGEB, 170 v_LANE0_EN(0) | v_LANE1_EN(0) | v_LANE2_EN(0) | 171 v_LANE3_EN(0) | v_LANECLK_EN(0) | v_PLL_PWR_OFF(1)); 172 173 /* power down lvds pll and bandgap */ 174 lvds_msk_reg(lvds, MIPIPHY_REG1, 175 m_SYNC_RST | m_LDO_PWR_DOWN | m_PLL_PWR_DOWN, 176 v_SYNC_RST(1) | v_LDO_PWR_DOWN(1) | v_PLL_PWR_DOWN(1)); 177 178 /* disable lvds */ 179 lvds_msk_reg(lvds, MIPIPHY_REGE3, m_LVDS_EN | m_TTL_EN, 180 v_LVDS_EN(0) | v_TTL_EN(0)); 181 182 return 0; 183 } 184 185 static int rk3288_lvds_pwr_off(struct display_state *state) 186 { 187 struct connector_state *conn_state = &state->conn_state; 188 struct rockchip_lvds_device *lvds = conn_state->private; 189 190 lvds_writel(lvds, RK3288_LVDS_CFG_REG21, RK3288_LVDS_CFG_REG21_TX_DISABLE); 191 lvds_writel(lvds, RK3288_LVDS_CFG_REGC, RK3288_LVDS_CFG_REGC_PLL_DISABLE); 192 193 writel(0xffff8000, lvds->grf + lvds->pdata->grf_soc_con7); 194 195 return 0; 196 } 197 198 static int rk336x_lvds_pwr_on(struct display_state *state) 199 { 200 struct connector_state *conn_state = &state->conn_state; 201 struct rockchip_lvds_device *lvds = conn_state->private; 202 u32 delay_times = 20; 203 204 if (lvds->output == DISPLAY_OUTPUT_LVDS) { 205 /* set VOCM 900 mv and V-DIFF 350 mv */ 206 lvds_msk_reg(lvds, MIPIPHY_REGE4, m_VOCM | m_DIFF_V, 207 v_VOCM(0) | v_DIFF_V(2)); 208 /* power up lvds pll and ldo */ 209 lvds_msk_reg(lvds, MIPIPHY_REG1, 210 m_SYNC_RST | m_LDO_PWR_DOWN | m_PLL_PWR_DOWN, 211 v_SYNC_RST(0) | v_LDO_PWR_DOWN(0) | 212 v_PLL_PWR_DOWN(0)); 213 /* enable lvds lane and power on pll */ 214 lvds_writel(lvds, MIPIPHY_REGEB, 215 v_LANE0_EN(1) | v_LANE1_EN(1) | v_LANE2_EN(1) | 216 v_LANE3_EN(1) | v_LANECLK_EN(1) | v_PLL_PWR_OFF(0)); 217 218 /* enable lvds */ 219 lvds_msk_reg(lvds, MIPIPHY_REGE3, 220 m_MIPI_EN | m_LVDS_EN | m_TTL_EN, 221 v_MIPI_EN(0) | v_LVDS_EN(1) | v_TTL_EN(0)); 222 } else { 223 lvds_msk_reg(lvds, MIPIPHY_REGE3, 224 m_MIPI_EN | m_LVDS_EN | m_TTL_EN, 225 v_MIPI_EN(0) | v_LVDS_EN(0) | v_TTL_EN(1)); 226 } 227 /* delay for waitting pll lock on */ 228 while (delay_times--) { 229 if (lvds_phy_lock(lvds)) 230 break; 231 udelay(100); 232 } 233 234 if (delay_times <= 0) 235 printf("wait lvds phy lock failed, please check the hardware!\n"); 236 237 return 0; 238 } 239 240 static void rk3126_output_ttl(struct display_state *state) 241 { 242 struct connector_state *conn_state = &state->conn_state; 243 struct rockchip_lvds_device *lvds = conn_state->private; 244 u32 val = 0; 245 246 /* iomux to lcdc */ 247 writel(0xffff5555, lvds->grf + RK3126_GRF_GPIO2B_IOMUX); 248 writel(0xffff5555, lvds->grf + RK3126_GRF_GPIO2C_IOMUX); 249 writel(0x00ff0055, lvds->grf + RK3126_GRF_GPIO2C_IOMUX2); 250 writel(0x700c1004, lvds->grf + RK3126_GRF_GPIO2D_IOMUX); 251 252 /* enable lvds mode */ 253 val = v_RK3126_LVDSMODE_EN(0) | 254 v_RK3126_MIPIPHY_TTL_EN(1) | 255 v_RK3126_MIPIPHY_LANE0_EN(1) | 256 v_RK3126_MIPIDPI_FORCEX_EN(1); 257 writel(val, lvds->grf + lvds->pdata->grf_soc_con7); 258 val = v_RK3126_MIPITTL_CLK_EN(1) | 259 v_RK3126_MIPITTL_LANE0_EN(1) | 260 v_RK3126_MIPITTL_LANE1_EN(1) | 261 v_RK3126_MIPITTL_LANE2_EN(1) | 262 v_RK3126_MIPITTL_LANE3_EN(1); 263 writel(val, lvds->grf + lvds->pdata->grf_soc_con15); 264 /* enable lane */ 265 lvds_writel(lvds, MIPIPHY_REG0, 0x7f); 266 val = v_LANE0_EN(1) | v_LANE1_EN(1) | v_LANE2_EN(1) | v_LANE3_EN(1) | 267 v_LANECLK_EN(1) | v_PLL_PWR_OFF(1); 268 lvds_writel(lvds, MIPIPHY_REGEB, val); 269 /* set ttl mode and reset phy config */ 270 val = v_LVDS_MODE_EN(0) | v_TTL_MODE_EN(1) | v_MIPI_MODE_EN(0) | 271 v_MSB_SEL(1) | v_DIG_INTER_RST(1); 272 lvds_writel(lvds, MIPIPHY_REGE0, val); 273 rk336x_lvds_pwr_on(state); 274 } 275 276 static void rk336x_output_ttl(struct display_state *state) 277 { 278 struct connector_state *conn_state = &state->conn_state; 279 struct rockchip_lvds_device *lvds = conn_state->private; 280 u32 val = 0; 281 282 /* iomux to lcdc */ 283 if (lvds->pdata->chip_type == RK3368_LVDS) { 284 /* lcdc data 11 10 */ 285 lvds_pmugrf_writel(0x04, 0xf0005000); 286 /* lcdc data 12 13 14 15 16 17 18 19 */ 287 lvds_pmugrf_writel(0x08, 0xFFFF5555); 288 /* lcdc data 20 21 22 23 HSYNC VSYNC DEN DCLK */ 289 lvds_pmugrf_writel(0x0c, 0xFFFF5555); 290 /* set clock lane enable */ 291 lvds_ctrl_writel(lvds, 0x0, 0x4); 292 } else { 293 /* lcdc data 15 ... 10, vsync, hsync */ 294 lvds_pmugrf_writel(0x0c, 0xffff555a); 295 /* lcdc data 23 ... 16 */ 296 lvds_pmugrf_writel(0x30, 0xffff5555); 297 /* lcdc dclk, den */ 298 lvds_pmugrf_writel(0x34, 0x000f0005); 299 } 300 301 /* enable lvds mode */ 302 val = v_RK336X_LVDSMODE_EN(0) | v_RK336X_MIPIPHY_TTL_EN(1) | 303 v_RK336X_MIPIPHY_LANE0_EN(1) | 304 v_RK336X_MIPIDPI_FORCEX_EN(1); 305 writel(val, lvds->grf + lvds->pdata->grf_soc_con7); 306 val = v_RK336X_FORCE_JETAG(0); 307 writel(val, lvds->grf + lvds->pdata->grf_soc_con15); 308 309 /* enable lane */ 310 lvds_writel(lvds, MIPIPHY_REG0, 0x7f); 311 val = v_LANE0_EN(1) | v_LANE1_EN(1) | v_LANE2_EN(1) | v_LANE3_EN(1) | 312 v_LANECLK_EN(1) | v_PLL_PWR_OFF(1); 313 lvds_writel(lvds, MIPIPHY_REGEB, val); 314 315 /* set ttl mode and reset phy config */ 316 val = v_LVDS_MODE_EN(0) | v_TTL_MODE_EN(1) | v_MIPI_MODE_EN(0) | 317 v_MSB_SEL(1) | v_DIG_INTER_RST(1); 318 lvds_writel(lvds, MIPIPHY_REGE0, val); 319 320 rk336x_lvds_pwr_on(state); 321 } 322 323 static void rk3126_output_lvds(struct display_state *state) 324 { 325 struct connector_state *conn_state = &state->conn_state; 326 struct rockchip_lvds_device *lvds = conn_state->private; 327 u32 val = 0; 328 329 /* enable lvds mode */ 330 val = v_RK3126_LVDSMODE_EN(1) | 331 v_RK3126_MIPIPHY_TTL_EN(0); 332 /* config lvds_format */ 333 val |= v_RK3126_LVDS_OUTPUT_FORMAT(lvds->format); 334 /* LSB receive mode */ 335 val |= v_RK3126_LVDS_MSBSEL(LVDS_MSB_D7); 336 val |= v_RK3126_MIPIPHY_LANE0_EN(1) | 337 v_RK3126_MIPIDPI_FORCEX_EN(1); 338 writel(val, lvds->grf + lvds->pdata->grf_soc_con7); 339 340 /* digital internal disable */ 341 lvds_msk_reg(lvds, MIPIPHY_REGE1, m_DIG_INTER_EN, v_DIG_INTER_EN(0)); 342 343 /* set pll prediv and fbdiv */ 344 lvds_writel(lvds, MIPIPHY_REG3, v_PREDIV(2) | v_FBDIV_MSB(0)); 345 lvds_writel(lvds, MIPIPHY_REG4, v_FBDIV_LSB(28)); 346 347 lvds_writel(lvds, MIPIPHY_REGE8, 0xfc); 348 349 /* set lvds mode and reset phy config */ 350 lvds_msk_reg(lvds, MIPIPHY_REGE0, 351 m_MSB_SEL | m_DIG_INTER_RST, 352 v_MSB_SEL(1) | v_DIG_INTER_RST(1)); 353 354 rk336x_lvds_pwr_on(state); 355 lvds_msk_reg(lvds, MIPIPHY_REGE1, m_DIG_INTER_EN, v_DIG_INTER_EN(1)); 356 } 357 358 static void rk336x_output_lvds(struct display_state *state) 359 { 360 struct connector_state *conn_state = &state->conn_state; 361 struct rockchip_lvds_device *lvds = conn_state->private; 362 u32 val = 0; 363 364 /* enable lvds mode */ 365 val |= v_RK336X_LVDSMODE_EN(1) | v_RK336X_MIPIPHY_TTL_EN(0); 366 /* config lvds_format */ 367 val |= v_RK336X_LVDS_OUTPUT_FORMAT(lvds->format); 368 /* LSB receive mode */ 369 val |= v_RK336X_LVDS_MSBSEL(LVDS_MSB_D7); 370 val |= v_RK336X_MIPIPHY_LANE0_EN(1) | 371 v_RK336X_MIPIDPI_FORCEX_EN(1); 372 writel(val, lvds->grf + lvds->pdata->grf_soc_con7); 373 /* digital internal disable */ 374 lvds_msk_reg(lvds, MIPIPHY_REGE1, m_DIG_INTER_EN, v_DIG_INTER_EN(0)); 375 376 /* set pll prediv and fbdiv */ 377 lvds_writel(lvds, MIPIPHY_REG3, v_PREDIV(2) | v_FBDIV_MSB(0)); 378 lvds_writel(lvds, MIPIPHY_REG4, v_FBDIV_LSB(28)); 379 380 lvds_writel(lvds, MIPIPHY_REGE8, 0xfc); 381 382 /* set lvds mode and reset phy config */ 383 lvds_msk_reg(lvds, MIPIPHY_REGE0, 384 m_MSB_SEL | m_DIG_INTER_RST, 385 v_MSB_SEL(1) | v_DIG_INTER_RST(1)); 386 387 rk336x_lvds_pwr_on(state); 388 lvds_msk_reg(lvds, MIPIPHY_REGE1, m_DIG_INTER_EN, v_DIG_INTER_EN(1)); 389 } 390 391 static int rk3288_lvds_pwr_on(struct display_state *state) 392 { 393 struct connector_state *conn_state = &state->conn_state; 394 struct rockchip_lvds_device *lvds = conn_state->private; 395 struct drm_display_mode *mode = &conn_state->mode; 396 u32 val; 397 u32 h_bp = mode->htotal - mode->hsync_start; 398 u8 pin_hsync = (mode->flags & DRM_MODE_FLAG_PHSYNC) ? 1 : 0; 399 u8 pin_dclk = (mode->flags & DRM_MODE_FLAG_PCSYNC) ? 1 : 0; 400 401 val = lvds->format; 402 if (lvds->output == DISPLAY_OUTPUT_DUAL_LVDS) 403 val |= LVDS_DUAL | LVDS_CH0_EN | LVDS_CH1_EN; 404 else if (lvds->output == DISPLAY_OUTPUT_LVDS) 405 val |= LVDS_CH0_EN; 406 else if (lvds->output == DISPLAY_OUTPUT_RGB) 407 val |= LVDS_TTL_EN | LVDS_CH0_EN | LVDS_CH1_EN; 408 409 if (h_bp & 0x01) 410 val |= LVDS_START_PHASE_RST_1; 411 412 val |= (pin_dclk << 8) | (pin_hsync << 9); 413 val |= (0xffff << 16); 414 writel(val, lvds->grf + lvds->pdata->grf_soc_con7); 415 416 return 0; 417 } 418 419 static void rk3288_output_ttl(struct display_state *state) 420 { 421 struct connector_state *conn_state = &state->conn_state; 422 struct rockchip_lvds_device *lvds = conn_state->private; 423 424 rk3288_lvds_pwr_on(state); 425 /* iomux: dclk den hsync vsync */ 426 writel(0x00550055, lvds->grf + lvds->pdata->grf_gpio1d_iomux); 427 lvds_writel(lvds, RK3288_LVDS_CH0_REG0, 428 RK3288_LVDS_CH0_REG0_TTL_EN | 429 RK3288_LVDS_CH0_REG0_LANECK_EN | 430 RK3288_LVDS_CH0_REG0_LANE4_EN | 431 RK3288_LVDS_CH0_REG0_LANE3_EN | 432 RK3288_LVDS_CH0_REG0_LANE2_EN | 433 RK3288_LVDS_CH0_REG0_LANE1_EN | 434 RK3288_LVDS_CH0_REG0_LANE0_EN); 435 lvds_writel(lvds, RK3288_LVDS_CH0_REG2, 436 RK3288_LVDS_PLL_FBDIV_REG2(0x46)); 437 438 lvds_writel(lvds, RK3288_LVDS_CH0_REG3, 439 RK3288_LVDS_PLL_FBDIV_REG3(0x46)); 440 lvds_writel(lvds, RK3288_LVDS_CH0_REG4, 441 RK3288_LVDS_CH0_REG4_LANECK_TTL_MODE | 442 RK3288_LVDS_CH0_REG4_LANE4_TTL_MODE | 443 RK3288_LVDS_CH0_REG4_LANE3_TTL_MODE | 444 RK3288_LVDS_CH0_REG4_LANE2_TTL_MODE | 445 RK3288_LVDS_CH0_REG4_LANE1_TTL_MODE | 446 RK3288_LVDS_CH0_REG4_LANE0_TTL_MODE); 447 lvds_writel(lvds, RK3288_LVDS_CH0_REG5, 448 RK3288_LVDS_CH0_REG5_LANECK_TTL_DATA | 449 RK3288_LVDS_CH0_REG5_LANE4_TTL_DATA | 450 RK3288_LVDS_CH0_REG5_LANE3_TTL_DATA | 451 RK3288_LVDS_CH0_REG5_LANE2_TTL_DATA | 452 RK3288_LVDS_CH0_REG5_LANE1_TTL_DATA | 453 RK3288_LVDS_CH0_REG5_LANE0_TTL_DATA); 454 lvds_writel(lvds, RK3288_LVDS_CH0_REGD, 455 RK3288_LVDS_PLL_PREDIV_REGD(0x0a)); 456 lvds_writel(lvds, RK3288_LVDS_CH0_REG20, 457 RK3288_LVDS_CH0_REG20_LSB); 458 459 lvds_writel(lvds, RK3288_LVDS_CFG_REGC, RK3288_LVDS_CFG_REGC_PLL_ENABLE); 460 lvds_writel(lvds, RK3288_LVDS_CFG_REG21, RK3288_LVDS_CFG_REG21_TX_ENABLE); 461 } 462 463 static void rk3288_output_lvds(struct display_state *state) 464 { 465 struct connector_state *conn_state = &state->conn_state; 466 struct rockchip_lvds_device *lvds = conn_state->private; 467 468 rk3288_lvds_pwr_on(state); 469 470 lvds_writel(lvds, RK3288_LVDS_CH0_REG0, 471 RK3288_LVDS_CH0_REG0_LVDS_EN | 472 RK3288_LVDS_CH0_REG0_LANECK_EN | 473 RK3288_LVDS_CH0_REG0_LANE4_EN | 474 RK3288_LVDS_CH0_REG0_LANE3_EN | 475 RK3288_LVDS_CH0_REG0_LANE2_EN | 476 RK3288_LVDS_CH0_REG0_LANE1_EN | 477 RK3288_LVDS_CH0_REG0_LANE0_EN); 478 lvds_writel(lvds, RK3288_LVDS_CH0_REG1, 479 RK3288_LVDS_CH0_REG1_LANECK_BIAS | 480 RK3288_LVDS_CH0_REG1_LANE4_BIAS | 481 RK3288_LVDS_CH0_REG1_LANE3_BIAS | 482 RK3288_LVDS_CH0_REG1_LANE2_BIAS | 483 RK3288_LVDS_CH0_REG1_LANE1_BIAS | 484 RK3288_LVDS_CH0_REG1_LANE0_BIAS); 485 lvds_writel(lvds, RK3288_LVDS_CH0_REG2, 486 RK3288_LVDS_CH0_REG2_RESERVE_ON | 487 RK3288_LVDS_CH0_REG2_LANECK_LVDS_MODE | 488 RK3288_LVDS_CH0_REG2_LANE4_LVDS_MODE | 489 RK3288_LVDS_CH0_REG2_LANE3_LVDS_MODE | 490 RK3288_LVDS_CH0_REG2_LANE2_LVDS_MODE | 491 RK3288_LVDS_CH0_REG2_LANE1_LVDS_MODE | 492 RK3288_LVDS_CH0_REG2_LANE0_LVDS_MODE | 493 RK3288_LVDS_PLL_FBDIV_REG2(0x46)); 494 lvds_writel(lvds, RK3288_LVDS_CH0_REG3, 495 RK3288_LVDS_PLL_FBDIV_REG3(0x46)); 496 lvds_writel(lvds, RK3288_LVDS_CH0_REG4, 0x00); 497 lvds_writel(lvds, RK3288_LVDS_CH0_REG5, 0x00); 498 lvds_writel(lvds, RK3288_LVDS_CH0_REGD, 499 RK3288_LVDS_PLL_PREDIV_REGD(0x0a)); 500 lvds_writel(lvds, RK3288_LVDS_CH0_REG20, 501 RK3288_LVDS_CH0_REG20_LSB); 502 503 lvds_writel(lvds, RK3288_LVDS_CFG_REGC, RK3288_LVDS_CFG_REGC_PLL_ENABLE); 504 lvds_writel(lvds, RK3288_LVDS_CFG_REG21, RK3288_LVDS_CFG_REG21_TX_ENABLE); 505 } 506 507 static int rockchip_lvds_init(struct display_state *state) 508 { 509 struct connector_state *conn_state = &state->conn_state; 510 const struct rockchip_connector *connector = conn_state->connector; 511 const struct rockchip_lvds_chip_data *pdata = connector->data; 512 int lvds_node = conn_state->node; 513 struct rockchip_lvds_device *lvds; 514 const char *name; 515 int i, width; 516 struct fdt_resource lvds_phy, lvds_ctrl; 517 struct panel_state *panel_state = &state->panel_state; 518 int panel_node = panel_state->node; 519 520 lvds = malloc(sizeof(*lvds)); 521 if (!lvds) 522 return -ENOMEM; 523 lvds->pdata = pdata; 524 525 if (pdata->chip_type == RK3288_LVDS) { 526 lvds->regbase = (void *)fdtdec_get_addr_size_auto_noparent(state->blob, 527 lvds_node, "reg", 0, NULL, false); 528 } else { 529 i = fdt_get_named_resource(state->blob, lvds_node, "reg", "reg-names", 530 "mipi_lvds_phy", &lvds_phy); 531 if (i) { 532 printf("can't get regs lvds_phy addresses!\n"); 533 free(lvds); 534 return -ENOMEM; 535 } 536 537 i = fdt_get_named_resource(state->blob, lvds_node, "reg", "reg-names", 538 "mipi_lvds_ctl", &lvds_ctrl); 539 if (i) { 540 printf("can't get regs lvds_ctrl addresses!\n"); 541 free(lvds); 542 return -ENOMEM; 543 } 544 545 lvds->regbase = (void *)lvds_phy.start; 546 lvds->ctrl_reg = (void *)lvds_ctrl.start; 547 } 548 549 lvds->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); 550 if (lvds->grf <= 0) { 551 printf("%s: Get syscon grf failed (ret=%p)\n", 552 __func__, lvds->grf); 553 return -ENXIO; 554 } 555 556 name = fdt_stringlist_get(state->blob, panel_node, "rockchip,output", 0, NULL); 557 if (!name) 558 /* default set it as output rgb */ 559 lvds->output = DISPLAY_OUTPUT_RGB; 560 else 561 lvds->output = lvds_name_to_output(name); 562 if (lvds->output < 0) { 563 printf("invalid output type [%s]\n", name); 564 free(lvds); 565 return lvds->output; 566 } 567 name = fdt_stringlist_get(state->blob, panel_node, "rockchip,data-mapping", 0, NULL); 568 if (!name) 569 /* default set it as format jeida */ 570 lvds->format = LVDS_FORMAT_JEIDA; 571 else 572 lvds->format = lvds_name_to_format(name); 573 574 if (lvds->format < 0) { 575 printf("invalid data-mapping format [%s]\n", name); 576 free(lvds); 577 return lvds->format; 578 } 579 width = fdtdec_get_int(state->blob, panel_node, "rockchip,data-width", 24); 580 if (width == 24) { 581 lvds->format |= LVDS_24BIT; 582 } else if (width == 18) { 583 lvds->format |= LVDS_18BIT; 584 } else { 585 printf("rockchip-lvds unsupport data-width[%d]\n", width); 586 free(lvds); 587 return -EINVAL; 588 } 589 590 printf("LVDS: data mapping: %s, data-width:%d, format:%d,\n", 591 name, width, lvds->format); 592 conn_state->private = lvds; 593 conn_state->type = DRM_MODE_CONNECTOR_LVDS; 594 595 if ((lvds->output == DISPLAY_OUTPUT_RGB) && (width == 18)) 596 conn_state->output_mode = ROCKCHIP_OUT_MODE_P666; 597 else 598 conn_state->output_mode = ROCKCHIP_OUT_MODE_P888; 599 600 return 0; 601 } 602 603 static void rockchip_lvds_deinit(struct display_state *state) 604 { 605 struct connector_state *conn_state = &state->conn_state; 606 struct rockchip_lvds_device *lvds = conn_state->private; 607 608 free(lvds); 609 } 610 611 static int rockchip_lvds_prepare(struct display_state *state) 612 { 613 struct connector_state *conn_state = &state->conn_state; 614 struct rockchip_lvds_device *lvds = conn_state->private; 615 lvds->mode = &conn_state->mode; 616 617 rockchip_lvds_clk_enable(lvds); 618 619 return 0; 620 } 621 622 static void rockchip_lvds_vop_routing(struct rockchip_lvds_device *lvds, int pipe) 623 { 624 u32 val; 625 626 if (lvds->pdata->chip_type == RK3288_LVDS) { 627 if (pipe) 628 val = RK3288_LVDS_SOC_CON6_SEL_VOP_LIT | 629 (RK3288_LVDS_SOC_CON6_SEL_VOP_LIT << 16); 630 else 631 val = RK3288_LVDS_SOC_CON6_SEL_VOP_LIT << 16; 632 writel(val, lvds->grf + lvds->pdata->grf_soc_con6); 633 } else { 634 if (pipe) 635 val = RK3366_LVDS_VOP_SEL_LIT; 636 else 637 val = RK3366_LVDS_VOP_SEL_BIG; 638 639 writel(val, lvds->grf + RK3366_GRF_SOC_CON0); 640 } 641 } 642 643 static int rockchip_lvds_enable(struct display_state *state) 644 { 645 struct connector_state *conn_state = &state->conn_state; 646 struct rockchip_lvds_device *lvds = conn_state->private; 647 struct crtc_state *crtc_state = &state->crtc_state; 648 649 if (lvds->pdata->has_vop_sel) 650 rockchip_lvds_vop_routing(lvds, crtc_state->crtc_id); 651 652 if (lvds->output == DISPLAY_OUTPUT_LVDS) { 653 if (lvds->pdata->chip_type == RK3288_LVDS) 654 rk3288_output_lvds(state); 655 else if (lvds->pdata->chip_type == RK3126_LVDS) 656 rk3126_output_lvds(state); 657 else 658 rk336x_output_lvds(state); 659 } else { 660 if (lvds->pdata->chip_type == RK3288_LVDS) 661 rk3288_output_ttl(state); 662 else if (lvds->pdata->chip_type == RK3126_LVDS) 663 rk3126_output_ttl(state); 664 else 665 rk336x_output_ttl(state); 666 } 667 668 return 0; 669 } 670 671 static int rockchip_lvds_disable(struct display_state *state) 672 { 673 struct connector_state *conn_state = &state->conn_state; 674 struct rockchip_lvds_device *lvds = conn_state->private; 675 676 if (lvds->pdata->chip_type == RK3288_LVDS) 677 rk3288_lvds_pwr_off(state); 678 else 679 rk336x_lvds_pwr_off(state); 680 681 return 0; 682 } 683 684 const struct rockchip_connector_funcs rockchip_lvds_funcs = { 685 .init = rockchip_lvds_init, 686 .deinit = rockchip_lvds_deinit, 687 .prepare = rockchip_lvds_prepare, 688 .enable = rockchip_lvds_enable, 689 .disable = rockchip_lvds_disable, 690 }; 691 692 static const struct rockchip_connector rk3366_lvds_data = { 693 .funcs = &rockchip_lvds_funcs, 694 .data = &rk3366_lvds_drv_data, 695 }; 696 697 static const struct rockchip_connector rk3368_lvds_data = { 698 .funcs = &rockchip_lvds_funcs, 699 .data = &rk3368_lvds_drv_data, 700 }; 701 702 static const struct rockchip_connector rk3288_lvds_data = { 703 .funcs = &rockchip_lvds_funcs, 704 .data = &rk3288_lvds_drv_data, 705 }; 706 707 static const struct rockchip_connector rk3126_lvds_data = { 708 .funcs = &rockchip_lvds_funcs, 709 .data = &rk3126_lvds_drv_data, 710 }; 711 712 static const struct udevice_id rockchip_lvds_ids[] = { 713 { 714 .compatible = "rockchip,rk3366-lvds", 715 .data = (ulong)&rk3366_lvds_data, 716 }, { 717 .compatible = "rockchip,rk3368-lvds", 718 .data = (ulong)&rk3368_lvds_data, 719 }, { 720 .compatible = "rockchip,rk3288-lvds", 721 .data = (ulong)&rk3288_lvds_data, 722 }, { 723 .compatible = "rockchip,rk3126-lvds", 724 .data = (ulong)&rk3126_lvds_data, 725 }, {} 726 }; 727 728 U_BOOT_DRIVER(rockchip_lvds) = { 729 .name = "rockchip_lvds", 730 .id = UCLASS_DISPLAY, 731 .of_match = rockchip_lvds_ids, 732 }; 733