From patchwork Tue Jul 18 17:59:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 108183 Delivered-To: patches@linaro.org Received: by 10.182.45.195 with SMTP id p3csp6208777obm; Tue, 18 Jul 2017 10:59:46 -0700 (PDT) X-Received: by 10.98.82.87 with SMTP id g84mr2938916pfb.232.1500400786378; Tue, 18 Jul 2017 10:59:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1500400786; cv=none; d=google.com; s=arc-20160816; b=SKZtRF5NavPwJjCQsQ4Mb8czZx9Dt7VMvjTNJlWJlnSZ686JvkLlkPLWNc6rISaBfh dIJymaa9S3f+nztNiuP8JyEKzFV1cUqrrrnQ7xfGTIr828Qd8p7zzVtnKRckVZ3m8i+G FKizBPmBfKoBTfz+7twkB0dyVoUC9Sk5f21V1FjwwXLFGIE0vCWpMiBg9sUPmHnFR5tP IUpH9s/DZX2ah72orOHJdu5322P+kZAEfpckbWQhKAtoCyCTyp8GKF7npDp3lzTzNAcF hlAJM9EHCrTFbe7+f4CbJRV1dXN+XPQTwSdJE4aqGEKSp9G9Y2YlQjcpvWL+RWvjxA15 NnjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=zH1OEu2FawMZhkNJEm7NsPqtXgepjuZ8PW5GQ4xQ8I8=; b=gi92MOncxE62yG32VyN1waEfSiFbX4ogx/jIP4c7sd37iv2vU2Ww5UzyZgVgeMUGls +1SLe8C1p0cQsa9zphCCOf5Rt1M1NvBQ0BDP4NMU2arbUHxbYKJITh4/erTj6bZ985D+ KItVutMxI4eeit1fDVegiPWq/t5YmPLCUpYDiGVgQ6QOEs5Q/Pxtjlqt6AChNz5Er1qF KInjak7MGephwo15m+TVgfKnTlHKJBxdYDxhZd/4n7fdToToj381DIBWAbiM3gw9RR4P bZrvqhpUwfO1g6jLvCYVIdT6pgL379yW//oIDV4FCHsl4NwUhnHnwRr6HpdMqNFJfsPa LI3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.b=X8a4RLJz; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-pf0-x22c.google.com (mail-pf0-x22c.google.com. [2607:f8b0:400e:c00::22c]) by mx.google.com with ESMTPS id 8si2289395pla.536.2017.07.18.10.59.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Jul 2017 10:59:46 -0700 (PDT) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) client-ip=2607:f8b0:400e:c00::22c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.b=X8a4RLJz; spf=pass (google.com: domain of john.stultz@linaro.org designates 2607:f8b0:400e:c00::22c as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by mail-pf0-x22c.google.com with SMTP id s70so5833893pfs.0 for ; Tue, 18 Jul 2017 10:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=zH1OEu2FawMZhkNJEm7NsPqtXgepjuZ8PW5GQ4xQ8I8=; b=X8a4RLJzAa8vZMkQTUAH6yQlcI3EA3rabYAg+7XMZiipPwu5NzhRb0a2ob6wLRuabC IvGwhGqKYLkADMnC1W89wPfy9Z9JCcAgouK3FUCfe0bdZB1/s3tQA2R7sAjSwtGgt6aR r/2mSldmLlkPcZGvq7PKHNF5AGc4+7DjtFEn8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=zH1OEu2FawMZhkNJEm7NsPqtXgepjuZ8PW5GQ4xQ8I8=; b=GNeoVTANTAHf/RLE8nkMOSI7nE393ValGv15QkFprYiRxDTicTegWb7jmMnL9dbR02 OSw+6mJmWifXZC4T7QJSo3pgtxJlvl5YAlehMC2Cn/JVmCiQb9Ho3zdPnwLfYsj7nnHs U2jXR7kjHwd7HXEKu4Ekjj/kTuGjG8D0BV6Aqp0olUN/WBSD4zUgZe7Poo8FXFwrKN9z h08PhWYAGES3JZhtFr65ycw7lfqfHP9y/HrjUib5PQWZbIluXYZIEIH2F3QU6QMN57PU vIpaC8zFZm8O/0/wreHfNahmUQWSIpx3KAlgZ6dlbME7Z8ZVkmTMESM7+AW8MW8+8XrA xHfw== X-Gm-Message-State: AIVw1124P97MvI0vdOGwNo8/pbrXAwV0CLjHV9Ic9g+/Z008IzHkP51L jAHocCyIc5m4SfSKjmw= X-Received: by 10.101.90.197 with SMTP id d5mr2796707pgt.223.1500400785948; Tue, 18 Jul 2017 10:59:45 -0700 (PDT) Return-Path: Received: from localhost.localdomain ([2601:1c2:1002:83f0:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id z69sm5096788pgz.42.2017.07.18.10.59.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 10:59:45 -0700 (PDT) From: John Stultz To: lkml Cc: John Stultz , Daniel Vetter , Jani Nikula , Sean Paul , David Airlie , Rob Clark , Xinliang Liu , Xinliang Liu , Rongrong Zou , Xinwei Kong , Chen Feng , Jose Abreu , Archit Taneja , dri-devel@lists.freedesktop.org Subject: [RFC][PATCH v3] drm: kirin: Add mode_valid logic to avoid mode clocks we can't generate Date: Tue, 18 Jul 2017 10:59:41 -0700 Message-Id: <1500400781-18162-1-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 Currently the hikey dsi logic cannot generate accurate byte clocks values for all pixel clock values. Thus if a mode clock is selected that cannot match the calculated byte clock, the device will boot with a blank screen. This patch uses the new mode_valid callback (many thanks to Jose Abreu for upstreaming it!) to ensure we don't select modes we cannot generate. Also, since the ade crtc code will adjust the mode in mode_set, this patch also adds a mode_fixup callback which we use to make sure we are validating the mode clock that will eventually be used. Many thanks to Jose and Daniel for recent feedback. I think this version is looking much nicer. But I'd still welcome any feedback or suggestions! Cc: Daniel Vetter Cc: Jani Nikula Cc: Sean Paul Cc: David Airlie Cc: Rob Clark Cc: Xinliang Liu Cc: Xinliang Liu Cc: Rongrong Zou Cc: Xinwei Kong Cc: Chen Feng Cc: Jose Abreu Cc: Archit Taneja Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- v2: Reworked to calculate if modeclock matches the phy's byteclock, rather then using a whitelist of known modes. v3: Reworked to check across all possible crtcs (even though for us there is only one), and use mode_fixup instead of a custom function, as suggested by Jose and Daniel. --- drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c | 62 +++++++++++++++++++++++++ drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c | 14 ++++++ 2 files changed, 76 insertions(+) -- 2.7.4 diff --git a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c index f77dcfa..d7b5820 100644 --- a/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c +++ b/drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c @@ -603,6 +603,67 @@ static void dsi_encoder_enable(struct drm_encoder *encoder) dsi->enable = true; } +static enum drm_mode_status dsi_encoder_phy_mode_valid(struct drm_encoder *encoder, + const struct drm_display_mode *mode) +{ + struct dw_dsi *dsi = encoder_to_dsi(encoder); + struct mipi_phy_params phy; + u32 bpp = mipi_dsi_pixel_format_to_bpp(dsi->format); + u32 req_kHz, act_kHz, lane_byte_clk_kHz; + + /* Calculate the lane byte clk using the adjusted mode clk */ + memset(&phy, 0, sizeof(phy)); + req_kHz = mode->clock * bpp / dsi->lanes; + act_kHz = dsi_calc_phy_rate(req_kHz, &phy); + lane_byte_clk_kHz = act_kHz / 8; + + DRM_DEBUG_DRIVER("Checking mode %ix%i-%i@%i clock: %i...", + mode->hdisplay, mode->vdisplay, bpp, + drm_mode_vrefresh(mode), mode->clock); + + /* + * Make sure the adjused mode clock and the lane byte clk + * have a common denominator base frequency + */ + if (mode->clock/dsi->lanes == lane_byte_clk_kHz/3) { + DRM_DEBUG_DRIVER("OK!\n"); + return MODE_OK; + } + + DRM_DEBUG_DRIVER("BAD!\n"); + return MODE_BAD; +} + +static enum drm_mode_status dsi_encoder_mode_valid(struct drm_encoder *encoder, + const struct drm_display_mode *mode) + +{ + const struct drm_crtc_helper_funcs *crtc_funcs = NULL; + struct drm_crtc *crtc = NULL; + struct drm_display_mode adj_mode; + int ret; + + memcpy(&adj_mode, mode, sizeof(adj_mode)); + + /* + * The crtc might adjust the mode, so go through the + * possible crtcs (technically just one) and call + * mode_fixup to figure out the adjusted mode before we + * validate it. + */ + drm_for_each_crtc(crtc, encoder->dev) { + crtc_funcs = crtc->helper_private; + if (crtc_funcs && crtc_funcs->mode_fixup) + ret = crtc_funcs->mode_fixup(crtc, mode, + &adj_mode); + + ret = dsi_encoder_phy_mode_valid(encoder, &adj_mode); + if (ret != MODE_OK) + return ret; + } + return MODE_OK; +} + static void dsi_encoder_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, struct drm_display_mode *adj_mode) @@ -622,6 +683,7 @@ static int dsi_encoder_atomic_check(struct drm_encoder *encoder, static const struct drm_encoder_helper_funcs dw_encoder_helper_funcs = { .atomic_check = dsi_encoder_atomic_check, + .mode_valid = dsi_encoder_mode_valid, .mode_set = dsi_encoder_mode_set, .enable = dsi_encoder_enable, .disable = dsi_encoder_disable diff --git a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c index c96c228..dec7f4e 100644 --- a/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c +++ b/drivers/gpu/drm/hisilicon/kirin/kirin_drm_ade.c @@ -178,6 +178,19 @@ static void ade_init(struct ade_hw_ctx *ctx) FRM_END_START_MASK, REG_EFFECTIVE_IN_ADEEN_FRMEND); } +static bool ade_crtc_mode_fixup(struct drm_crtc *crtc, + const struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +{ + struct ade_crtc *acrtc = to_ade_crtc(crtc); + struct ade_hw_ctx *ctx = acrtc->ctx; + + adjusted_mode->clock = + clk_round_rate(ctx->ade_pix_clk, mode->clock * 1000) / 1000; + return true; +} + + static void ade_set_pix_clk(struct ade_hw_ctx *ctx, struct drm_display_mode *mode, struct drm_display_mode *adj_mode) @@ -555,6 +568,7 @@ static void ade_crtc_atomic_flush(struct drm_crtc *crtc, static const struct drm_crtc_helper_funcs ade_crtc_helper_funcs = { .enable = ade_crtc_enable, .disable = ade_crtc_disable, + .mode_fixup = ade_crtc_mode_fixup, .mode_set_nofb = ade_crtc_mode_set_nofb, .atomic_begin = ade_crtc_atomic_begin, .atomic_flush = ade_crtc_atomic_flush,