From patchwork Mon Feb 5 19:38:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10201639 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 03017602CA for ; Mon, 5 Feb 2018 19:39:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E6DCB205FC for ; Mon, 5 Feb 2018 19:39:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DB319287CF; Mon, 5 Feb 2018 19:39:58 +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=-4.1 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, 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 831A0205FC for ; Mon, 5 Feb 2018 19:39:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B9AAC6E32E; Mon, 5 Feb 2018 19:39:18 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x244.google.com (mail-qt0-x244.google.com [IPv6:2607:f8b0:400d:c0d::244]) by gabe.freedesktop.org (Postfix) with ESMTPS id 140C06E32E for ; Mon, 5 Feb 2018 19:39:17 +0000 (UTC) Received: by mail-qt0-x244.google.com with SMTP id t25so7544162qtg.3 for ; Mon, 05 Feb 2018 11:39:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=gkXBRc68u6Ofy1ChRB4220onhBnx1KrNqKBfEhRGDgM=; b=h9Jl8UmBJNzdB+jqZsecWHWouCo052gAFwrnsOGsPCZTK3I1QRRbfiYNgFR6JAYggQ KDWUoNQxyQMrGDMr4OG7YuZRdxAXV+/7wNrr7g+WSw7YwFoCXNbnI2iuRwRU3OKDN2z1 sn3P7QDsfn9XzsNi/0yophp/8MOVH59NrT2rtjx8kOnmP/w1uURjq5zRXvgpVwpOzKrJ 7+3fqg4ZKSHNdYLGGsP3Uf94smp7ue38UJNeCO4X6w2a5KAb8xykb1yApjxSYehjdV2W xUopbBcCmqC+8uLQcBGcJuYvxiyKyIIxSGb0mGLFeHRhYVUpMa3cMJ1J6R7D8eEZ47OB cKew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=gkXBRc68u6Ofy1ChRB4220onhBnx1KrNqKBfEhRGDgM=; b=HMnGmCYWpX9ThMwoklA2umr6Q60zxhy4O7wnfvkG6DChOmFlsZ7wGN/YZ/BozvHQEg /QrlU5sSraC1kGgYCMqNCH6jNKrhcum3ANRdQVanCohXFHMQQvAY4fYZnd0ZViNPwcF7 A58/0jR/ugY7g5g+h9V4xA1zx30j/w9EI38EynNQX+mfpvJ4+/pwKeDejCjg/frIZM2s l6dzqvM7winssljLp0NYvG5bdn0M9jm+QEbPN5yUGmzyfecatWKK0pEtQZl1AfndjB49 X/kByXsKiAEX+razk4fLlSxSFx7SYnUfHDcvrBCoD1V7tEFPSptfd3KPuZcjLelmANF1 AClg== X-Gm-Message-State: APf1xPD9M1o7FBouSlkzYk2qhHbU/Ay3Da0gkEnpo3GbzS7bZBnlXqCk wHo1wcDb0Fx2rh2kAMtwkAAu1w== X-Google-Smtp-Source: AH8x225eDpePnZZmElePf+US+LCwVUY5DmvhkNuU2LE5XZzSpg75Hbl1s9CRiEgtEGQ/MvORYAKCxg== X-Received: by 10.237.36.99 with SMTP id s32mr4979992qtc.148.1517859555214; Mon, 05 Feb 2018 11:39:15 -0800 (PST) Received: from localhost (p200300E41F41B00009B231EAB1BE76D4.dip0.t-ipconnect.de. [2003:e4:1f41:b000:9b2:31ea:b1be:76d4]) by smtp.gmail.com with ESMTPSA id n20sm6130041qka.47.2018.02.05.11.39.14 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 05 Feb 2018 11:39:14 -0800 (PST) From: Thierry Reding To: dri-devel@lists.freedesktop.org Subject: [PATCH 17/17] drm/dp: Add drm_dp_link_choose() helper Date: Mon, 5 Feb 2018 20:38:27 +0100 Message-Id: <20180205193827.20374-18-thierry.reding@gmail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20180205193827.20374-1-thierry.reding@gmail.com> References: <20180205193827.20374-1-thierry.reding@gmail.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 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 From: Thierry Reding This helper chooses an appropriate configuration, according to the bitrate requirements of the video mode and the capabilities of the DisplayPort sink. Signed-off-by: Thierry Reding --- drivers/gpu/drm/drm_dp_helper.c | 55 +++++++++++++++++++++++++++++++++++++++++ include/drm/drm_dp_helper.h | 5 ++++ 2 files changed, 60 insertions(+) diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c index c8b18c0161d7..fb6ee3ebc37d 100644 --- a/drivers/gpu/drm/drm_dp_helper.c +++ b/drivers/gpu/drm/drm_dp_helper.c @@ -557,6 +557,61 @@ int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link) } EXPORT_SYMBOL(drm_dp_link_configure); +/** + * drm_dp_link_choose() - choose the lowest possible configuration for a mode + * @link: DRM DP link object + * @mode: DRM display mode + * @info: DRM display information + * + * According to the eDP specification, a source should select a configuration + * with the lowest number of lanes and the lowest possible link rate that can + * match the bitrate requirements of a video mode. However it must ensure not + * to exceed the capabilities of the sink. + * + * Returns: 0 on success or a negative error code on failure. + */ +int drm_dp_link_choose(struct drm_dp_link *link, + const struct drm_display_mode *mode, + const struct drm_display_info *info) +{ + /* available link symbol clock rates */ + static const unsigned int rates[3] = { 162000, 270000, 540000 }; + /* available number of lanes */ + static const unsigned int lanes[3] = { 1, 2, 4 }; + unsigned long requirement, capacity; + unsigned int rate = link->max_rate; + unsigned int i, j; + + /* bandwidth requirement */ + requirement = mode->clock * info->bpc * 3; + + for (i = 0; i < ARRAY_SIZE(lanes) && lanes[i] <= link->max_lanes; i++) { + for (j = 0; j < ARRAY_SIZE(rates) && rates[j] <= rate; j++) { + /* + * Capacity for this combination of lanes and rate, + * factoring in the ANSI 8B/10B encoding. + * + * Link rates in the DRM DP helpers are really link + * symbol frequencies, so a tenth of the actual rate + * of the link. + */ + capacity = lanes[i] * (rates[j] * 10) * 8 / 10; + + if (capacity >= requirement) { + DRM_DEBUG_KMS("using %u lanes at %u kHz (%lu/%lu kbps)\n", + lanes[i], rates[j], requirement, + capacity); + link->lanes = lanes[i]; + link->rate = rates[j]; + return 0; + } + } + } + + return -ERANGE; +} +EXPORT_SYMBOL(drm_dp_link_choose); + /** * drm_dp_downstream_max_clock() - extract branch device max * pixel rate for legacy VGA diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index 4c7badcde945..39d134f9a954 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -27,6 +27,8 @@ #include #include +#include + /* * Unless otherwise noted, all values are from the DP 1.1a spec. Note that * DP and DPCD versions are independent. Differences from 1.0 are not noted, @@ -1194,6 +1196,9 @@ int drm_dp_link_probe(struct drm_dp_aux *aux, struct drm_dp_link *link); int drm_dp_link_power_up(struct drm_dp_aux *aux, struct drm_dp_link *link); int drm_dp_link_power_down(struct drm_dp_aux *aux, struct drm_dp_link *link); int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link); +int drm_dp_link_choose(struct drm_dp_link *link, + const struct drm_display_mode *mode, + const struct drm_display_info *info); int drm_dp_downstream_max_clock(const u8 dpcd[DP_RECEIVER_CAP_SIZE], const u8 port_cap[4]); int drm_dp_downstream_max_bpc(const u8 dpcd[DP_RECEIVER_CAP_SIZE],