From patchwork Thu Oct 24 16:45:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 11210279 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5641F1747 for ; Thu, 24 Oct 2019 16:46:20 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3E87821906 for ; Thu, 24 Oct 2019 16:46:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3E87821906 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6CA496E4BB; Thu, 24 Oct 2019 16:46:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9651A6E4BA for ; Thu, 24 Oct 2019 16:46:09 +0000 (UTC) Received: by mail-wr1-x444.google.com with SMTP id t16so21734004wrr.1 for ; Thu, 24 Oct 2019 09:46:09 -0700 (PDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=F4lRUdhvbauplkpd4/zSVY6YswIkikfBSoscbfTPm6A=; b=glW70t6vlQTiX+sVTBdT5txLN+OdEv1OyKcHRrR3SUj+k8O9DWcieN2FlNJYoKZn/d AszmGRt9eJt/pBElBNo0dIr5DtGOXTueQLzrFPjLTiNNPNZszUuL6vy15Mc2uW/cnTHG /swo+O4pN7H+VtMXuSevho/694Gx6ItzfmY0xzGQ7FlJPNSytsccQPCcilQ5UsZi5rRx Kd+tKy9DbXtL99cNxl0ARRxKsh/530kNAEdJ+Bt+nf+S/9oxeZEvjCaoUpJZQe68ij7j AyZLdZcr65K1f5k70e4/Yx53VXKPYbRUcoVODqlqxdgpfs1FddEgiDcdeooe/OV5KADs DBqQ== X-Gm-Message-State: APjAAAXsaYtSoaXAP+tIxHsh6l3qB+3UeEq/dzacLKQ2KF8uRGidD003 KAVm8fMDZZ3NhpgnhtntFaIqznQB X-Google-Smtp-Source: APXvYqxghvX8VIL9TX0Ql3qna64+KUMLlY0Ct0J2y1K44HN6eoCXOu8q79Te3MUH6bA+ZQZdaU3Wew== X-Received: by 2002:adf:fe10:: with SMTP id n16mr4995376wrr.288.1571935568004; Thu, 24 Oct 2019 09:46:08 -0700 (PDT) Received: from localhost (p2E5BE2CE.dip0.t-ipconnect.de. [46.91.226.206]) by smtp.gmail.com with ESMTPSA id u1sm2526372wmc.38.2019.10.24.09.46.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 24 Oct 2019 09:46:06 -0700 (PDT) From: Thierry Reding To: Thierry Reding Subject: [PATCH 14/32] drm/tegra: dp: Add drm_dp_link_choose() helper Date: Thu, 24 Oct 2019 18:45:16 +0200 Message-Id: <20191024164534.132764-15-thierry.reding@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191024164534.132764-1-thierry.reding@gmail.com> References: <20191024164534.132764-1-thierry.reding@gmail.com> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=F4lRUdhvbauplkpd4/zSVY6YswIkikfBSoscbfTPm6A=; b=us02LvLyl9MstWWZI+3sQezky6sgukEOfdq9wVIaT3dAjByyV2942Jrzhjtl21DI7w SUnGEzvgbXAhyKIb/D5MaqmUPy4Og9oRmYO9v6WWnbuTEJOUEFH71bzHDoQ/9UTNI+A+ qMUyxyavj3ZnVJzZWilqZbbplLyfy4ltlt2Z40czShEH3HivFXv89kF+VfpeZJMUHC9M 8RrTl77Y304hFn2I5S/5jIr/llCQjd/WU88VBoBDxcWxa2ORcOWgG4BzBtz05nSXDcCD OhFDWpvxExMYgMPxOK6vQwuUzWRLWnjm3Gt8ALkXguSSe1z+ETJajoI+Vm67QEgIa6Uq H9xQ== 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: , Cc: linux-tegra@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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/tegra/dp.c | 55 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/tegra/dp.h | 5 ++++ 2 files changed, 60 insertions(+) diff --git a/drivers/gpu/drm/tegra/dp.c b/drivers/gpu/drm/tegra/dp.c index 638081b568f4..e9a5db77a2dc 100644 --- a/drivers/gpu/drm/tegra/dp.c +++ b/drivers/gpu/drm/tegra/dp.c @@ -4,6 +4,7 @@ * Copyright (C) 2015 Rob Clark */ +#include #include #include @@ -234,3 +235,57 @@ int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link) return 0; } + +/** + * 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; +} diff --git a/drivers/gpu/drm/tegra/dp.h b/drivers/gpu/drm/tegra/dp.h index 1fe2d4f45ba3..e07b9a1e43d8 100644 --- a/drivers/gpu/drm/tegra/dp.h +++ b/drivers/gpu/drm/tegra/dp.h @@ -9,6 +9,8 @@ #include +struct drm_display_info; +struct drm_display_mode; struct drm_dp_aux; /** @@ -91,5 +93,8 @@ 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); #endif