From patchwork Thu Nov 3 19:46:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Kristian_H=C3=B8gsberg?= X-Patchwork-Id: 9411399 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1FAB460722 for ; Thu, 3 Nov 2016 19:46:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0857D2AE16 for ; Thu, 3 Nov 2016 19:46:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F093E2AE9B; Thu, 3 Nov 2016 19:46:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.6 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 584702AE36 for ; Thu, 3 Nov 2016 19:46:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C1FB6E7FE; Thu, 3 Nov 2016 19:46:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) by gabe.freedesktop.org (Postfix) with ESMTPS id 83E146E7FE for ; Thu, 3 Nov 2016 19:46:52 +0000 (UTC) Received: by mail-pf0-x242.google.com with SMTP id a136so5689184pfa.0 for ; Thu, 03 Nov 2016 12:46:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=unhDOHqjODDaXNsjx6rZp+Nm0/y0f9/cPB60mC82Pog=; b=H7p3IKrSE/NafV9HFQ0Ng2RXbT4CcW+RRTX6PlKHW8YQ/H5HvRBQchgPm6zGo/EkIh xvy2nkjw9J1eQbHfysvr19E1sYgdWb5sAGMUNZ+fUQm4PaC//HXU47xz1W01e/m350K7 1i4FgqCwM6RdLrdEdrlaEXvKrlICnaN6S4VBvfEbnAIJCXcyPsvxOAZkhvl433LSd7z6 nN9xv+VUx3xl2HVlQxRns2/iPFgjl09p0Zgg57STYKRpdjapxY9OCHsvCtWsQWhG7hfm k4L6p6Wtj8hufJ0cGJiJTD1bvXIQeRghtN3VKGAnBQTmAEAfR8MbWQiW/ICwjZtQ5veU 3YNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=unhDOHqjODDaXNsjx6rZp+Nm0/y0f9/cPB60mC82Pog=; b=Db1e7bZCm3fPLc/KlgMU6FY41dCw/HsI7wWBm2NYVA9oHXaMIsaEiMNOwAKxEqyJth fZLM2t7eI758C0Ze8HXEJ2pOVBy3uCI7sjxDERh9wuxCYzqAdxp2HXf+C70ipmZSlDaQ KN9u3Eyoefg3ehB5VlTbyZSZ7PtK5TPjC0A5r8d+jT47dYrMn2Vgn23WgVyGHc/7kMJX b4BI8F+yjmDT9mz5af28TcuMZWGuoSvGeJwy4PxscO5+LgrXSZCiJTMEaZdbdGJMFkPS UdOpVJ+rauoxqMsxPlxoleYwnDQMyUOM03nCOAa7IObyTIvEVzm+iIU6ubizgPNNNdjt EO2Q== X-Gm-Message-State: ABUngvcZttpi9byzbA48F2O+0RNGQ+bx0DthvqQLgSeBmLP5seGbHa6qZtLomWFPqD4/mQ== X-Received: by 10.99.178.89 with SMTP id t25mr16313665pgo.131.1478202412020; Thu, 03 Nov 2016 12:46:52 -0700 (PDT) Received: from hawkmoon.pdx.corp.google.com ([100.118.88.18]) by smtp.gmail.com with ESMTPSA id l7sm14621752pfg.35.2016.11.03.12.46.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 03 Nov 2016 12:46:51 -0700 (PDT) From: "Kristian H. Kristensen" X-Google-Original-From: "Kristian H. Kristensen" To: dri-devel@lists.freedesktop.org Subject: [PATCH v2] drm/rockchip: Use an enum to identify Rockchip VOPs Date: Thu, 3 Nov 2016 12:46:48 -0700 Message-Id: <1478202408-11635-1-git-send-email-hoegsberg@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Cc: "Kristian H. Kristensen" X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We used to call drm_of_encoder_active_endpoint_id() from rockchip_dp_drm_encoder_atomic_check() to determine the endpoint for the active encoder. However, the encoder isn't necessarily active at this point or it may be connected to different crtc than what we're switching to. Instead, look at the crtc from the drm_crtc_state. This fixes wrong colors when driving the eDP with the big VOP. Further, we can identify the type of VOP we're dealing with by just putting a VOP id enum in the vop_data. On way to test this is to use the modetest tool from libdrm: $ modetest -M rockchip -s 32@28:2400x1600 which displays dark or black colors because we fail to look up the endpoint and use default 0 (which is ROCKCHIP_OUT_MODE_P888) for big VOP instead of RGB10 as required. For reference, $ modetest -M rockchip -s 32@25:2400x1600 drives the eDP from little VOP and displays correctly. Signed-off-by: Kristian H. Kristensen --- v2: Stripped chromeos annotations, fix compile errors for drivers I didn't compile when I first wrote the patch. drivers/gpu/drm/rockchip/analogix_dp-rockchip.c | 45 ++++++++++--------------- drivers/gpu/drm/rockchip/cdn-dp-core.c | 19 +++++------ drivers/gpu/drm/rockchip/dw-mipi-dsi.c | 12 ++++--- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 7 ++++ drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 10 ++++++ drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 4 +++ 6 files changed, 56 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c index 558a3bc..9ae4a9c 100644 --- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c +++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c @@ -196,14 +196,16 @@ static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder) int ret; u32 val; - ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); - if (ret < 0) - return; - - if (ret) + switch (vop_get_crtc_vop_id(encoder->crtc)) { + case RK3399_VOP_LIT: val = dp->data->lcdsel_lit; - else + break; + case RK3399_VOP_BIG: val = dp->data->lcdsel_big; + break; + default: + return; + } dev_dbg(dp->dev, "vop %s output to dp\n", (ret) ? "LIT" : "BIG"); @@ -231,34 +233,23 @@ rockchip_dp_drm_encoder_atomic_check(struct drm_encoder *encoder, struct drm_connector_state *conn_state) { struct rockchip_crtc_state *s = to_rockchip_crtc_state(crtc_state); - struct rockchip_dp_device *dp = to_dp(encoder); - int ret; - /* - * The hardware IC designed that VOP must output the RGB10 video - * format to eDP contoller, and if eDP panel only support RGB8, - * then eDP contoller should cut down the video data, not via VOP - * contoller, that's why we need to hardcode the VOP output mode - * to RGA10 here. - */ - - ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); - if (ret < 0) - return 0; - - switch (dp->data->chip_type) { - case RK3399_EDP: + switch (vop_get_crtc_vop_id(crtc_state->crtc)) { + case RK3399_VOP_LIT: /* * For RK3399, VOP Lit must code the out mode to RGB888, * VOP Big must code the out mode to RGB10. */ - if (ret) - s->output_mode = ROCKCHIP_OUT_MODE_P888; - else - s->output_mode = ROCKCHIP_OUT_MODE_AAAA; + s->output_mode = ROCKCHIP_OUT_MODE_P888; break; - default: + /* + * The hardware IC designed that VOP must output the RGB10 video + * format to eDP contoller, and if eDP panel only support RGB8, + * then eDP contoller should cut down the video data, not via VOP + * contoller, that's why we need to hardcode the VOP output mode + * to RGA10 here. + */ s->output_mode = ROCKCHIP_OUT_MODE_AAAA; break; } diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c index f020e2e..b9e6184 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c @@ -570,21 +570,20 @@ static void cdn_dp_encoder_mode_set(struct drm_encoder *encoder, video->v_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NVSYNC); video->h_sync_polarity = !!(mode->flags & DRM_MODE_FLAG_NHSYNC); - ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); - if (ret < 0) { - DRM_DEV_ERROR(dp->dev, "Could not get vop id, %d", ret); - return; - } - - DRM_DEV_DEBUG_KMS(dp->dev, "vop %s output to cdn-dp\n", - (ret) ? "LIT" : "BIG"); state = to_rockchip_crtc_state(encoder->crtc->state); - if (ret) { + switch (vop_get_crtc_vop_id(encoder->crtc)) { + case RK3399_VOP_LIT: + DRM_DEV_DEBUG_KMS(dp->dev, "vop LIT output to cdn-dp\n"); val = DP_SEL_VOP_LIT | (DP_SEL_VOP_LIT << 16); state->output_mode = ROCKCHIP_OUT_MODE_P888; - } else { + break; + case RK3399_VOP_BIG: + DRM_DEV_DEBUG_KMS(dp->dev, "vop BIG output to cdn-dp\n"); val = DP_SEL_VOP_LIT << 16; state->output_mode = ROCKCHIP_OUT_MODE_AAAA; + break; + default: + break; } ret = cdn_dp_grf_write(dp, GRF_SOC_CON9, val); diff --git a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c index dedc65b..b01a82a 100644 --- a/drivers/gpu/drm/rockchip/dw-mipi-dsi.c +++ b/drivers/gpu/drm/rockchip/dw-mipi-dsi.c @@ -878,7 +878,6 @@ static void dw_mipi_dsi_encoder_disable(struct drm_encoder *encoder) static void dw_mipi_dsi_encoder_commit(struct drm_encoder *encoder) { struct dw_mipi_dsi *dsi = encoder_to_dsi(encoder); - int mux = drm_of_encoder_active_endpoint_id(dsi->dev->of_node, encoder); u32 val; if (clk_prepare_enable(dsi->pclk)) { @@ -894,13 +893,18 @@ static void dw_mipi_dsi_encoder_commit(struct drm_encoder *encoder) clk_disable_unprepare(dsi->pclk); - if (mux) + switch (vop_get_crtc_vop_id(encoder->crtc)) { + case RK3399_VOP_LIT: + dev_dbg(dsi->dev, "vop LIT output to dsi0\n"); val = DSI0_SEL_VOP_LIT | (DSI0_SEL_VOP_LIT << 16); - else + break; + default: + dev_dbg(dsi->dev, "vop BIG output to dsi0\n"); val = DSI0_SEL_VOP_LIT << 16; + break; + } regmap_write(dsi->grf_regmap, GRF_SOC_CON6, val); - dev_dbg(dsi->dev, "vop %s output to dsi0\n", (mux) ? "LIT" : "BIG"); } static int diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index d5ea4ab..e849f26 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -141,6 +141,13 @@ struct vop { struct vop_win win[]; }; +enum vop_id vop_get_crtc_vop_id(struct drm_crtc *crtc) +{ + struct vop *vop = to_vop(crtc); + + return vop->data->id; +} + static inline void vop_writel(struct vop *vop, uint32_t offset, uint32_t v) { writel(v, vop->regs + offset); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h index 5a4faa85..2c54bcc 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h @@ -135,8 +135,16 @@ struct vop_win_data { enum drm_plane_type type; }; +enum vop_id { + RK3036_VOP, + RK3288_VOP, + RK3399_VOP_BIG, + RK3399_VOP_LIT, +}; + struct vop_data { const struct vop_reg_data *init_table; + uint32_t id; unsigned int table_size; const struct vop_ctrl *ctrl; const struct vop_intr *intr; @@ -321,5 +329,7 @@ static inline int scl_vop_cal_lb_mode(int width, bool is_yuv) return lb_mode; } +enum vop_id vop_get_crtc_vop_id(struct drm_crtc *crtc); + extern const struct component_ops vop_component_ops; #endif /* _ROCKCHIP_DRM_VOP_H */ diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c index aaede6b..a46e2c8 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c @@ -131,6 +131,7 @@ static const struct vop_reg_data rk3036_vop_init_reg_table[] = { }; static const struct vop_data rk3036_vop = { + .id = RK3036_VOP, .init_table = rk3036_vop_init_reg_table, .table_size = ARRAY_SIZE(rk3036_vop_init_reg_table), .ctrl = &rk3036_ctrl_data, @@ -272,6 +273,7 @@ static const struct vop_intr rk3288_vop_intr = { }; static const struct vop_data rk3288_vop = { + .id = RK3288_VOP, .init_table = rk3288_init_reg_table, .table_size = ARRAY_SIZE(rk3288_init_reg_table), .intr = &rk3288_vop_intr, @@ -340,6 +342,7 @@ static const struct vop_reg_data rk3399_init_reg_table[] = { }; static const struct vop_data rk3399_vop_big = { + .id = RK3399_VOP_BIG, .init_table = rk3399_init_reg_table, .table_size = ARRAY_SIZE(rk3399_init_reg_table), .intr = &rk3399_vop_intr, @@ -359,6 +362,7 @@ static const struct vop_win_data rk3399_vop_lit_win_data[] = { }; static const struct vop_data rk3399_vop_lit = { + .id = RK3399_VOP_LIT, .init_table = rk3399_init_reg_table, .table_size = ARRAY_SIZE(rk3399_init_reg_table), .intr = &rk3399_vop_intr,