Lines Matching +full:rockchip +full:- +full:lvds
1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
5 * Mark Yao <mark.yao@rock-chips.com>
6 * Sandy Huang <hjc@rock-chips.com>
38 * struct rockchip_lvds_soc_data - rockchip lvds Soc private data
39 * @probe: LVDS platform probe function
40 * @helper_funcs: LVDS connector helper functions
43 int (*probe)(struct platform_device *pdev, struct rockchip_lvds *lvds);
54 int output; /* rgb lvds or dual lvds output */
76 static inline void rk3288_writel(struct rockchip_lvds *lvds, u32 offset, in rk3288_writel() argument
79 writel_relaxed(val, lvds->regs + offset); in rk3288_writel()
80 if (lvds->output == DISPLAY_OUTPUT_LVDS) in rk3288_writel()
82 writel_relaxed(val, lvds->regs + offset + RK3288_LVDS_CH1_OFFSET); in rk3288_writel()
87 if (strncmp(s, "jeida-18", 8) == 0) in rockchip_lvds_name_to_format()
89 else if (strncmp(s, "jeida-24", 8) == 0) in rockchip_lvds_name_to_format()
91 else if (strncmp(s, "vesa-24", 7) == 0) in rockchip_lvds_name_to_format()
94 return -EINVAL; in rockchip_lvds_name_to_format()
101 else if (strncmp(s, "lvds", 4) == 0) in rockchip_lvds_name_to_output()
106 return -EINVAL; in rockchip_lvds_name_to_output()
119 struct rockchip_lvds *lvds = connector_to_lvds(connector); in rockchip_lvds_connector_get_modes() local
120 struct drm_panel *panel = lvds->panel; in rockchip_lvds_connector_get_modes()
137 s->output_mode = ROCKCHIP_OUT_MODE_P888; in rockchip_lvds_encoder_atomic_check()
138 s->output_type = DRM_MODE_CONNECTOR_LVDS; in rockchip_lvds_encoder_atomic_check()
143 static int rk3288_lvds_poweron(struct rockchip_lvds *lvds) in rk3288_lvds_poweron() argument
148 ret = clk_enable(lvds->pclk); in rk3288_lvds_poweron()
150 DRM_DEV_ERROR(lvds->dev, "failed to enable lvds pclk %d\n", ret); in rk3288_lvds_poweron()
153 ret = pm_runtime_resume_and_get(lvds->dev); in rk3288_lvds_poweron()
155 DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret); in rk3288_lvds_poweron()
156 clk_disable(lvds->pclk); in rk3288_lvds_poweron()
162 if (lvds->output == DISPLAY_OUTPUT_RGB) { in rk3288_lvds_poweron()
165 rk3288_writel(lvds, RK3288_LVDS_CH0_REG0, val); in rk3288_lvds_poweron()
166 rk3288_writel(lvds, RK3288_LVDS_CH0_REG2, in rk3288_lvds_poweron()
168 rk3288_writel(lvds, RK3288_LVDS_CH0_REG4, in rk3288_lvds_poweron()
175 rk3288_writel(lvds, RK3288_LVDS_CH0_REG5, in rk3288_lvds_poweron()
185 rk3288_writel(lvds, RK3288_LVDS_CH0_REG0, val); in rk3288_lvds_poweron()
186 rk3288_writel(lvds, RK3288_LVDS_CH0_REG1, in rk3288_lvds_poweron()
193 rk3288_writel(lvds, RK3288_LVDS_CH0_REG2, in rk3288_lvds_poweron()
202 rk3288_writel(lvds, RK3288_LVDS_CH0_REG4, 0x00); in rk3288_lvds_poweron()
203 rk3288_writel(lvds, RK3288_LVDS_CH0_REG5, 0x00); in rk3288_lvds_poweron()
205 rk3288_writel(lvds, RK3288_LVDS_CH0_REG3, in rk3288_lvds_poweron()
207 rk3288_writel(lvds, RK3288_LVDS_CH0_REGD, in rk3288_lvds_poweron()
209 rk3288_writel(lvds, RK3288_LVDS_CH0_REG20, in rk3288_lvds_poweron()
212 rk3288_writel(lvds, RK3288_LVDS_CFG_REGC, in rk3288_lvds_poweron()
214 rk3288_writel(lvds, RK3288_LVDS_CFG_REG21, in rk3288_lvds_poweron()
220 static void rk3288_lvds_poweroff(struct rockchip_lvds *lvds) in rk3288_lvds_poweroff() argument
225 rk3288_writel(lvds, RK3288_LVDS_CFG_REG21, in rk3288_lvds_poweroff()
227 rk3288_writel(lvds, RK3288_LVDS_CFG_REGC, in rk3288_lvds_poweroff()
231 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON7, val); in rk3288_lvds_poweroff()
233 DRM_DEV_ERROR(lvds->dev, "Could not write to GRF: %d\n", ret); in rk3288_lvds_poweroff()
235 pm_runtime_put(lvds->dev); in rk3288_lvds_poweroff()
236 clk_disable(lvds->pclk); in rk3288_lvds_poweroff()
242 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in rk3288_lvds_grf_config() local
243 u8 pin_hsync = (mode->flags & DRM_MODE_FLAG_PHSYNC) ? 1 : 0; in rk3288_lvds_grf_config()
244 u8 pin_dclk = (mode->flags & DRM_MODE_FLAG_PCSYNC) ? 1 : 0; in rk3288_lvds_grf_config()
249 if (lvds->output == DISPLAY_OUTPUT_RGB) in rk3288_lvds_grf_config()
250 if (lvds->pins && !IS_ERR(lvds->pins->default_state)) in rk3288_lvds_grf_config()
251 pinctrl_select_state(lvds->pins->p, in rk3288_lvds_grf_config()
252 lvds->pins->default_state); in rk3288_lvds_grf_config()
253 val = lvds->format | LVDS_CH0_EN; in rk3288_lvds_grf_config()
254 if (lvds->output == DISPLAY_OUTPUT_RGB) in rk3288_lvds_grf_config()
256 else if (lvds->output == DISPLAY_OUTPUT_DUAL_LVDS) in rk3288_lvds_grf_config()
259 if ((mode->htotal - mode->hsync_start) & 0x01) in rk3288_lvds_grf_config()
264 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON7, val); in rk3288_lvds_grf_config()
266 DRM_DEV_ERROR(lvds->dev, "Could not write to GRF: %d\n", ret); in rk3288_lvds_grf_config()
271 static int rk3288_lvds_set_vop_source(struct rockchip_lvds *lvds, in rk3288_lvds_set_vop_source() argument
277 ret = drm_of_encoder_active_endpoint_id(lvds->dev->of_node, encoder); in rk3288_lvds_set_vop_source()
285 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON6, val); in rk3288_lvds_set_vop_source()
294 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in rk3288_lvds_encoder_enable() local
295 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in rk3288_lvds_encoder_enable()
298 drm_panel_prepare(lvds->panel); in rk3288_lvds_encoder_enable()
300 ret = rk3288_lvds_poweron(lvds); in rk3288_lvds_encoder_enable()
302 DRM_DEV_ERROR(lvds->dev, "failed to power on LVDS: %d\n", ret); in rk3288_lvds_encoder_enable()
303 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
309 DRM_DEV_ERROR(lvds->dev, "failed to configure LVDS: %d\n", ret); in rk3288_lvds_encoder_enable()
310 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
314 ret = rk3288_lvds_set_vop_source(lvds, encoder); in rk3288_lvds_encoder_enable()
316 DRM_DEV_ERROR(lvds->dev, "failed to set VOP source: %d\n", ret); in rk3288_lvds_encoder_enable()
317 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
321 drm_panel_enable(lvds->panel); in rk3288_lvds_encoder_enable()
326 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in rk3288_lvds_encoder_disable() local
328 drm_panel_disable(lvds->panel); in rk3288_lvds_encoder_disable()
329 rk3288_lvds_poweroff(lvds); in rk3288_lvds_encoder_disable()
330 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_disable()
333 static int px30_lvds_poweron(struct rockchip_lvds *lvds) in px30_lvds_poweron() argument
337 ret = pm_runtime_resume_and_get(lvds->dev); in px30_lvds_poweron()
339 DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret); in px30_lvds_poweron()
343 /* Enable LVDS mode */ in px30_lvds_poweron()
344 ret = regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_poweron()
348 pm_runtime_put(lvds->dev); in px30_lvds_poweron()
353 static void px30_lvds_poweroff(struct rockchip_lvds *lvds) in px30_lvds_poweroff() argument
355 regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_poweroff()
359 pm_runtime_put(lvds->dev); in px30_lvds_poweroff()
365 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in px30_lvds_grf_config() local
367 if (lvds->output != DISPLAY_OUTPUT_LVDS) { in px30_lvds_grf_config()
368 DRM_DEV_ERROR(lvds->dev, "Unsupported display output %d\n", in px30_lvds_grf_config()
369 lvds->output); in px30_lvds_grf_config()
370 return -EINVAL; in px30_lvds_grf_config()
374 return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_grf_config()
375 PX30_LVDS_FORMAT(lvds->format), in px30_lvds_grf_config()
376 PX30_LVDS_FORMAT(lvds->format)); in px30_lvds_grf_config()
379 static int px30_lvds_set_vop_source(struct rockchip_lvds *lvds, in px30_lvds_set_vop_source() argument
384 vop = drm_of_encoder_active_endpoint_id(lvds->dev->of_node, encoder); in px30_lvds_set_vop_source()
388 return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_set_vop_source()
395 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in px30_lvds_encoder_enable() local
396 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in px30_lvds_encoder_enable()
399 drm_panel_prepare(lvds->panel); in px30_lvds_encoder_enable()
401 ret = px30_lvds_poweron(lvds); in px30_lvds_encoder_enable()
403 DRM_DEV_ERROR(lvds->dev, "failed to power on LVDS: %d\n", ret); in px30_lvds_encoder_enable()
404 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
410 DRM_DEV_ERROR(lvds->dev, "failed to configure LVDS: %d\n", ret); in px30_lvds_encoder_enable()
411 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
415 ret = px30_lvds_set_vop_source(lvds, encoder); in px30_lvds_encoder_enable()
417 DRM_DEV_ERROR(lvds->dev, "failed to set VOP source: %d\n", ret); in px30_lvds_encoder_enable()
418 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
422 drm_panel_enable(lvds->panel); in px30_lvds_encoder_enable()
427 struct rockchip_lvds *lvds = encoder_to_lvds(encoder); in px30_lvds_encoder_disable() local
429 drm_panel_disable(lvds->panel); in px30_lvds_encoder_disable()
430 px30_lvds_poweroff(lvds); in px30_lvds_encoder_disable()
431 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_disable()
449 struct rockchip_lvds *lvds) in rk3288_lvds_probe() argument
453 lvds->regs = devm_platform_ioremap_resource(pdev, 0); in rk3288_lvds_probe()
454 if (IS_ERR(lvds->regs)) in rk3288_lvds_probe()
455 return PTR_ERR(lvds->regs); in rk3288_lvds_probe()
457 lvds->pclk = devm_clk_get(lvds->dev, "pclk_lvds"); in rk3288_lvds_probe()
458 if (IS_ERR(lvds->pclk)) { in rk3288_lvds_probe()
459 DRM_DEV_ERROR(lvds->dev, "could not get pclk_lvds\n"); in rk3288_lvds_probe()
460 return PTR_ERR(lvds->pclk); in rk3288_lvds_probe()
463 lvds->pins = devm_kzalloc(lvds->dev, sizeof(*lvds->pins), in rk3288_lvds_probe()
465 if (!lvds->pins) in rk3288_lvds_probe()
466 return -ENOMEM; in rk3288_lvds_probe()
468 lvds->pins->p = devm_pinctrl_get(lvds->dev); in rk3288_lvds_probe()
469 if (IS_ERR(lvds->pins->p)) { in rk3288_lvds_probe()
470 DRM_DEV_ERROR(lvds->dev, "no pinctrl handle\n"); in rk3288_lvds_probe()
471 devm_kfree(lvds->dev, lvds->pins); in rk3288_lvds_probe()
472 lvds->pins = NULL; in rk3288_lvds_probe()
474 lvds->pins->default_state = in rk3288_lvds_probe()
475 pinctrl_lookup_state(lvds->pins->p, "lcdc"); in rk3288_lvds_probe()
476 if (IS_ERR(lvds->pins->default_state)) { in rk3288_lvds_probe()
477 DRM_DEV_ERROR(lvds->dev, "no default pinctrl state\n"); in rk3288_lvds_probe()
478 devm_kfree(lvds->dev, lvds->pins); in rk3288_lvds_probe()
479 lvds->pins = NULL; in rk3288_lvds_probe()
483 ret = clk_prepare(lvds->pclk); in rk3288_lvds_probe()
485 DRM_DEV_ERROR(lvds->dev, "failed to prepare pclk_lvds\n"); in rk3288_lvds_probe()
493 struct rockchip_lvds *lvds) in px30_lvds_probe() argument
498 ret = regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_probe()
505 lvds->dphy = devm_phy_get(&pdev->dev, "dphy"); in px30_lvds_probe()
506 if (IS_ERR(lvds->dphy)) in px30_lvds_probe()
507 return PTR_ERR(lvds->dphy); in px30_lvds_probe()
509 ret = phy_init(lvds->dphy); in px30_lvds_probe()
513 ret = phy_set_mode(lvds->dphy, PHY_MODE_LVDS); in px30_lvds_probe()
517 return phy_power_on(lvds->dphy); in px30_lvds_probe()
532 .compatible = "rockchip,rk3288-lvds",
536 .compatible = "rockchip,px30-lvds",
546 struct rockchip_lvds *lvds = dev_get_drvdata(dev); in rockchip_lvds_bind() local
556 lvds->drm_dev = drm_dev; in rockchip_lvds_bind()
557 port = of_graph_get_port_by_id(dev->of_node, 1); in rockchip_lvds_bind()
560 "can't found port point, please init lvds panel port!\n"); in rockchip_lvds_bind()
561 return -EINVAL; in rockchip_lvds_bind()
566 ret = drm_of_find_panel_or_bridge(dev->of_node, 1, endpoint_id, in rockchip_lvds_bind()
567 &lvds->panel, &lvds->bridge); in rockchip_lvds_bind()
574 DRM_DEV_ERROR(dev, "lvds port does not have any children\n"); in rockchip_lvds_bind()
575 ret = -EINVAL; in rockchip_lvds_bind()
581 if (lvds->panel) in rockchip_lvds_bind()
582 remote = lvds->panel->dev->of_node; in rockchip_lvds_bind()
584 remote = lvds->bridge->of_node; in rockchip_lvds_bind()
585 if (of_property_read_string(dev->of_node, "rockchip,output", &name)) in rockchip_lvds_bind()
587 lvds->output = DISPLAY_OUTPUT_RGB; in rockchip_lvds_bind()
589 lvds->output = rockchip_lvds_name_to_output(name); in rockchip_lvds_bind()
591 if (lvds->output < 0) { in rockchip_lvds_bind()
593 ret = lvds->output; in rockchip_lvds_bind()
597 if (of_property_read_string(remote, "data-mapping", &name)) in rockchip_lvds_bind()
599 lvds->format = LVDS_VESA_18; in rockchip_lvds_bind()
601 lvds->format = rockchip_lvds_name_to_format(name); in rockchip_lvds_bind()
603 if (lvds->format < 0) { in rockchip_lvds_bind()
604 DRM_DEV_ERROR(dev, "invalid data-mapping format [%s]\n", name); in rockchip_lvds_bind()
605 ret = lvds->format; in rockchip_lvds_bind()
609 encoder = &lvds->encoder.encoder; in rockchip_lvds_bind()
610 encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, in rockchip_lvds_bind()
611 dev->of_node); in rockchip_lvds_bind()
615 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
620 drm_encoder_helper_add(encoder, lvds->soc_data->helper_funcs); in rockchip_lvds_bind()
621 connector = &lvds->connector; in rockchip_lvds_bind()
623 if (lvds->panel) { in rockchip_lvds_bind()
624 connector->dpms = DRM_MODE_DPMS_OFF; in rockchip_lvds_bind()
629 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
637 ret = drm_bridge_attach(encoder, lvds->bridge, NULL, in rockchip_lvds_bind()
642 connector = drm_bridge_connector_init(lvds->drm_dev, encoder); in rockchip_lvds_bind()
644 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
654 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
680 struct rockchip_lvds *lvds = dev_get_drvdata(dev); in rockchip_lvds_unbind() local
683 encoder_funcs = lvds->soc_data->helper_funcs; in rockchip_lvds_unbind()
684 encoder_funcs->disable(&lvds->encoder.encoder); in rockchip_lvds_unbind()
686 drm_connector_cleanup(&lvds->connector); in rockchip_lvds_unbind()
687 drm_encoder_cleanup(&lvds->encoder.encoder); in rockchip_lvds_unbind()
697 struct device *dev = &pdev->dev; in rockchip_lvds_probe()
698 struct rockchip_lvds *lvds; in rockchip_lvds_probe() local
702 if (!dev->of_node) in rockchip_lvds_probe()
703 return -ENODEV; in rockchip_lvds_probe()
705 lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); in rockchip_lvds_probe()
706 if (!lvds) in rockchip_lvds_probe()
707 return -ENOMEM; in rockchip_lvds_probe()
709 lvds->dev = dev; in rockchip_lvds_probe()
710 match = of_match_node(rockchip_lvds_dt_ids, dev->of_node); in rockchip_lvds_probe()
712 return -ENODEV; in rockchip_lvds_probe()
713 lvds->soc_data = match->data; in rockchip_lvds_probe()
715 lvds->grf = syscon_regmap_lookup_by_phandle(dev->of_node, in rockchip_lvds_probe()
716 "rockchip,grf"); in rockchip_lvds_probe()
717 if (IS_ERR(lvds->grf)) { in rockchip_lvds_probe()
718 DRM_DEV_ERROR(dev, "missing rockchip,grf property\n"); in rockchip_lvds_probe()
719 return PTR_ERR(lvds->grf); in rockchip_lvds_probe()
722 ret = lvds->soc_data->probe(pdev, lvds); in rockchip_lvds_probe()
728 dev_set_drvdata(dev, lvds); in rockchip_lvds_probe()
730 ret = component_add(&pdev->dev, &rockchip_lvds_component_ops); in rockchip_lvds_probe()
733 clk_unprepare(lvds->pclk); in rockchip_lvds_probe()
741 struct rockchip_lvds *lvds = platform_get_drvdata(pdev); in rockchip_lvds_remove() local
743 component_del(&pdev->dev, &rockchip_lvds_component_ops); in rockchip_lvds_remove()
744 clk_unprepare(lvds->pclk); in rockchip_lvds_remove()
751 .name = "rockchip-lvds",