Lines Matching +full:rk3288 +full:- +full:vop
1 // SPDX-License-Identifier: GPL-2.0-only
5 * Mark Yao <mark.yao@rock-chips.com>
6 * Sandy Huang <hjc@rock-chips.com>
40 * struct rockchip_lvds_soc_data - rockchip lvds Soc private data
81 writel_relaxed(val, lvds->regs + offset); in rk3288_writel()
82 if (lvds->output == DISPLAY_OUTPUT_LVDS) in rk3288_writel()
84 writel_relaxed(val, lvds->regs + offset + RK3288_LVDS_CH1_OFFSET); in rk3288_writel()
89 if (strncmp(s, "jeida-18", 8) == 0) in rockchip_lvds_name_to_format()
91 else if (strncmp(s, "jeida-24", 8) == 0) in rockchip_lvds_name_to_format()
93 else if (strncmp(s, "vesa-24", 7) == 0) in rockchip_lvds_name_to_format()
96 return -EINVAL; in rockchip_lvds_name_to_format()
108 return -EINVAL; in rockchip_lvds_name_to_output()
122 struct drm_panel *panel = lvds->panel; in rockchip_lvds_connector_get_modes()
139 s->output_mode = ROCKCHIP_OUT_MODE_P888; in rockchip_lvds_encoder_atomic_check()
140 s->output_type = DRM_MODE_CONNECTOR_LVDS; in rockchip_lvds_encoder_atomic_check()
150 ret = clk_enable(lvds->pclk); in rk3288_lvds_poweron()
152 DRM_DEV_ERROR(lvds->dev, "failed to enable lvds pclk %d\n", ret); in rk3288_lvds_poweron()
155 ret = pm_runtime_get_sync(lvds->dev); in rk3288_lvds_poweron()
157 DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret); in rk3288_lvds_poweron()
158 clk_disable(lvds->pclk); in rk3288_lvds_poweron()
164 if (lvds->output == DISPLAY_OUTPUT_RGB) { in rk3288_lvds_poweron()
233 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON7, val); in rk3288_lvds_poweroff()
235 DRM_DEV_ERROR(lvds->dev, "Could not write to GRF: %d\n", ret); in rk3288_lvds_poweroff()
237 pm_runtime_put(lvds->dev); in rk3288_lvds_poweroff()
238 clk_disable(lvds->pclk); in rk3288_lvds_poweroff()
245 u8 pin_hsync = (mode->flags & DRM_MODE_FLAG_PHSYNC) ? 1 : 0; in rk3288_lvds_grf_config()
246 u8 pin_dclk = (mode->flags & DRM_MODE_FLAG_PCSYNC) ? 1 : 0; in rk3288_lvds_grf_config()
251 if (lvds->output == DISPLAY_OUTPUT_RGB) in rk3288_lvds_grf_config()
252 if (lvds->pins && !IS_ERR(lvds->pins->default_state)) in rk3288_lvds_grf_config()
253 pinctrl_select_state(lvds->pins->p, in rk3288_lvds_grf_config()
254 lvds->pins->default_state); in rk3288_lvds_grf_config()
255 val = lvds->format | LVDS_CH0_EN; in rk3288_lvds_grf_config()
256 if (lvds->output == DISPLAY_OUTPUT_RGB) in rk3288_lvds_grf_config()
258 else if (lvds->output == DISPLAY_OUTPUT_DUAL_LVDS) in rk3288_lvds_grf_config()
261 if ((mode->htotal - mode->hsync_start) & 0x01) in rk3288_lvds_grf_config()
266 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON7, val); in rk3288_lvds_grf_config()
268 DRM_DEV_ERROR(lvds->dev, "Could not write to GRF: %d\n", ret); in rk3288_lvds_grf_config()
279 ret = drm_of_encoder_active_endpoint_id(lvds->dev->of_node, encoder); in rk3288_lvds_set_vop_source()
287 ret = regmap_write(lvds->grf, RK3288_LVDS_GRF_SOC_CON6, val); in rk3288_lvds_set_vop_source()
297 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in rk3288_lvds_encoder_enable()
300 drm_panel_prepare(lvds->panel); in rk3288_lvds_encoder_enable()
304 DRM_DEV_ERROR(lvds->dev, "failed to power on LVDS: %d\n", ret); in rk3288_lvds_encoder_enable()
305 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
311 DRM_DEV_ERROR(lvds->dev, "failed to configure LVDS: %d\n", ret); in rk3288_lvds_encoder_enable()
312 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
318 DRM_DEV_ERROR(lvds->dev, "failed to set VOP source: %d\n", ret); in rk3288_lvds_encoder_enable()
319 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_enable()
323 drm_panel_enable(lvds->panel); in rk3288_lvds_encoder_enable()
330 drm_panel_disable(lvds->panel); in rk3288_lvds_encoder_disable()
332 drm_panel_unprepare(lvds->panel); in rk3288_lvds_encoder_disable()
339 ret = pm_runtime_get_sync(lvds->dev); in px30_lvds_poweron()
341 DRM_DEV_ERROR(lvds->dev, "failed to get pm runtime: %d\n", ret); in px30_lvds_poweron()
346 return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_poweron()
353 regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_poweroff()
357 pm_runtime_put(lvds->dev); in px30_lvds_poweroff()
365 if (lvds->output != DISPLAY_OUTPUT_LVDS) { in px30_lvds_grf_config()
366 DRM_DEV_ERROR(lvds->dev, "Unsupported display output %d\n", in px30_lvds_grf_config()
367 lvds->output); in px30_lvds_grf_config()
368 return -EINVAL; in px30_lvds_grf_config()
372 return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_grf_config()
373 PX30_LVDS_FORMAT(lvds->format), in px30_lvds_grf_config()
374 PX30_LVDS_FORMAT(lvds->format)); in px30_lvds_grf_config()
380 int vop; in px30_lvds_set_vop_source() local
382 vop = drm_of_encoder_active_endpoint_id(lvds->dev->of_node, encoder); in px30_lvds_set_vop_source()
383 if (vop < 0) in px30_lvds_set_vop_source()
384 return vop; in px30_lvds_set_vop_source()
386 return regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_set_vop_source()
388 PX30_LVDS_VOP_SEL(vop)); in px30_lvds_set_vop_source()
394 struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode; in px30_lvds_encoder_enable()
397 drm_panel_prepare(lvds->panel); in px30_lvds_encoder_enable()
401 DRM_DEV_ERROR(lvds->dev, "failed to power on LVDS: %d\n", ret); in px30_lvds_encoder_enable()
402 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
408 DRM_DEV_ERROR(lvds->dev, "failed to configure LVDS: %d\n", ret); in px30_lvds_encoder_enable()
409 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
415 DRM_DEV_ERROR(lvds->dev, "failed to set VOP source: %d\n", ret); in px30_lvds_encoder_enable()
416 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_enable()
420 drm_panel_enable(lvds->panel); in px30_lvds_encoder_enable()
427 drm_panel_disable(lvds->panel); in px30_lvds_encoder_disable()
429 drm_panel_unprepare(lvds->panel); in px30_lvds_encoder_disable()
451 lvds->regs = devm_platform_ioremap_resource(pdev, 0); in rk3288_lvds_probe()
452 if (IS_ERR(lvds->regs)) in rk3288_lvds_probe()
453 return PTR_ERR(lvds->regs); in rk3288_lvds_probe()
455 lvds->pclk = devm_clk_get(lvds->dev, "pclk_lvds"); in rk3288_lvds_probe()
456 if (IS_ERR(lvds->pclk)) { in rk3288_lvds_probe()
457 DRM_DEV_ERROR(lvds->dev, "could not get pclk_lvds\n"); in rk3288_lvds_probe()
458 return PTR_ERR(lvds->pclk); in rk3288_lvds_probe()
461 lvds->pins = devm_kzalloc(lvds->dev, sizeof(*lvds->pins), in rk3288_lvds_probe()
463 if (!lvds->pins) in rk3288_lvds_probe()
464 return -ENOMEM; in rk3288_lvds_probe()
466 lvds->pins->p = devm_pinctrl_get(lvds->dev); in rk3288_lvds_probe()
467 if (IS_ERR(lvds->pins->p)) { in rk3288_lvds_probe()
468 DRM_DEV_ERROR(lvds->dev, "no pinctrl handle\n"); in rk3288_lvds_probe()
469 devm_kfree(lvds->dev, lvds->pins); in rk3288_lvds_probe()
470 lvds->pins = NULL; in rk3288_lvds_probe()
472 lvds->pins->default_state = in rk3288_lvds_probe()
473 pinctrl_lookup_state(lvds->pins->p, "lcdc"); in rk3288_lvds_probe()
474 if (IS_ERR(lvds->pins->default_state)) { in rk3288_lvds_probe()
475 DRM_DEV_ERROR(lvds->dev, "no default pinctrl state\n"); in rk3288_lvds_probe()
476 devm_kfree(lvds->dev, lvds->pins); in rk3288_lvds_probe()
477 lvds->pins = NULL; in rk3288_lvds_probe()
481 ret = clk_prepare(lvds->pclk); in rk3288_lvds_probe()
483 DRM_DEV_ERROR(lvds->dev, "failed to prepare pclk_lvds\n"); in rk3288_lvds_probe()
496 ret = regmap_update_bits(lvds->grf, PX30_LVDS_GRF_PD_VO_CON1, in px30_lvds_probe()
503 lvds->dphy = devm_phy_get(&pdev->dev, "dphy"); in px30_lvds_probe()
504 if (IS_ERR(lvds->dphy)) in px30_lvds_probe()
505 return PTR_ERR(lvds->dphy); in px30_lvds_probe()
507 ret = phy_init(lvds->dphy); in px30_lvds_probe()
511 ret = phy_set_mode(lvds->dphy, PHY_MODE_LVDS); in px30_lvds_probe()
515 return phy_power_on(lvds->dphy); in px30_lvds_probe()
530 .compatible = "rockchip,rk3288-lvds",
534 .compatible = "rockchip,px30-lvds",
554 lvds->drm_dev = drm_dev; in rockchip_lvds_bind()
555 port = of_graph_get_port_by_id(dev->of_node, 1); in rockchip_lvds_bind()
559 return -EINVAL; in rockchip_lvds_bind()
564 ret = drm_of_find_panel_or_bridge(dev->of_node, 1, endpoint_id, in rockchip_lvds_bind()
565 &lvds->panel, &lvds->bridge); in rockchip_lvds_bind()
573 ret = -EINVAL; in rockchip_lvds_bind()
577 ret = -EPROBE_DEFER; in rockchip_lvds_bind()
580 if (lvds->panel) in rockchip_lvds_bind()
581 remote = lvds->panel->dev->of_node; in rockchip_lvds_bind()
583 remote = lvds->bridge->of_node; in rockchip_lvds_bind()
584 if (of_property_read_string(dev->of_node, "rockchip,output", &name)) in rockchip_lvds_bind()
586 lvds->output = DISPLAY_OUTPUT_RGB; in rockchip_lvds_bind()
588 lvds->output = rockchip_lvds_name_to_output(name); in rockchip_lvds_bind()
590 if (lvds->output < 0) { in rockchip_lvds_bind()
592 ret = lvds->output; in rockchip_lvds_bind()
596 if (of_property_read_string(remote, "data-mapping", &name)) in rockchip_lvds_bind()
598 lvds->format = LVDS_VESA_18; in rockchip_lvds_bind()
600 lvds->format = rockchip_lvds_name_to_format(name); in rockchip_lvds_bind()
602 if (lvds->format < 0) { in rockchip_lvds_bind()
603 DRM_DEV_ERROR(dev, "invalid data-mapping format [%s]\n", name); in rockchip_lvds_bind()
604 ret = lvds->format; in rockchip_lvds_bind()
608 encoder = &lvds->encoder.encoder; in rockchip_lvds_bind()
609 encoder->possible_crtcs = drm_of_find_possible_crtcs(drm_dev, in rockchip_lvds_bind()
610 dev->of_node); in rockchip_lvds_bind()
614 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
619 drm_encoder_helper_add(encoder, lvds->soc_data->helper_funcs); in rockchip_lvds_bind()
620 connector = &lvds->connector; in rockchip_lvds_bind()
622 if (lvds->panel) { in rockchip_lvds_bind()
623 connector->dpms = DRM_MODE_DPMS_OFF; in rockchip_lvds_bind()
628 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
636 ret = drm_bridge_attach(encoder, lvds->bridge, NULL, in rockchip_lvds_bind()
641 connector = drm_bridge_connector_init(lvds->drm_dev, encoder); in rockchip_lvds_bind()
643 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
653 DRM_DEV_ERROR(drm_dev->dev, in rockchip_lvds_bind()
682 encoder_funcs = lvds->soc_data->helper_funcs; in rockchip_lvds_unbind()
683 encoder_funcs->disable(&lvds->encoder.encoder); in rockchip_lvds_unbind()
685 drm_connector_cleanup(&lvds->connector); in rockchip_lvds_unbind()
686 drm_encoder_cleanup(&lvds->encoder.encoder); in rockchip_lvds_unbind()
696 struct device *dev = &pdev->dev; in rockchip_lvds_probe()
701 if (!dev->of_node) in rockchip_lvds_probe()
702 return -ENODEV; in rockchip_lvds_probe()
704 lvds = devm_kzalloc(&pdev->dev, sizeof(*lvds), GFP_KERNEL); in rockchip_lvds_probe()
706 return -ENOMEM; in rockchip_lvds_probe()
708 lvds->dev = dev; in rockchip_lvds_probe()
709 match = of_match_node(rockchip_lvds_dt_ids, dev->of_node); in rockchip_lvds_probe()
711 return -ENODEV; in rockchip_lvds_probe()
712 lvds->soc_data = match->data; in rockchip_lvds_probe()
714 lvds->grf = syscon_regmap_lookup_by_phandle(dev->of_node, in rockchip_lvds_probe()
716 if (IS_ERR(lvds->grf)) { in rockchip_lvds_probe()
718 return PTR_ERR(lvds->grf); in rockchip_lvds_probe()
721 ret = lvds->soc_data->probe(pdev, lvds); in rockchip_lvds_probe()
729 ret = component_add(&pdev->dev, &rockchip_lvds_component_ops); in rockchip_lvds_probe()
732 clk_unprepare(lvds->pclk); in rockchip_lvds_probe()
742 component_del(&pdev->dev, &rockchip_lvds_component_ops); in rockchip_lvds_remove()
743 clk_unprepare(lvds->pclk); in rockchip_lvds_remove()
752 .name = "rockchip-lvds",