From patchwork Tue Jan 23 13:22:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10180327 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 AA023601D5 for ; Tue, 23 Jan 2018 13:34:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 963F628066 for ; Tue, 23 Jan 2018 13:34:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A446286BE; Tue, 23 Jan 2018 13:34:34 +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_SIGNED, 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 E3D4A28066 for ; Tue, 23 Jan 2018 13:34:33 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3098C6E418; Tue, 23 Jan 2018 13:33:17 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf0-x243.google.com (mail-lf0-x243.google.com [IPv6:2a00:1450:4010:c07::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id B3E2C6E2C2 for ; Tue, 23 Jan 2018 13:22:28 +0000 (UTC) Received: by mail-lf0-x243.google.com with SMTP id a204so596995lfa.2 for ; Tue, 23 Jan 2018 05:22:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=OwPjEi+so4Uo10OgyuTfYoXMlfUByYTogfTbER7CxT8=; b=KSl0/GxLY+GDs8iZOjvP04JVFAcpTKJfxv7IWK60LDgwLFonkMtr4G3R0gHSv1AYUE o0eH4Mrbh2y05j3fE2MwTEzmqV+MOAGgJLLHGfX0RxffqHX16tQPjTxaIfHT8UV2ZStT gbmLg/AEA2ST/5yCPEHSLbsrLMHKMZnBQyCo4= 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=OwPjEi+so4Uo10OgyuTfYoXMlfUByYTogfTbER7CxT8=; b=KIxJEtYqMP1ewpr7Gfmy53ZOq6BtdyCxLBtrhq+4zmTUJgLgNojcVg4zsLFrAkv+dU Dh4HfVS9LdfQrdWfdiaOaAkJK8BloXzJnlfgIpbUHclTYmF3tlzdgLqZ0Dtsr6K9XMzq oaV08V5Uu2vwWff079xDoe+VnfHuR4O+vwk90JEWm2TycyAXgXcliFrTMlh2FoUjcj0P JvmGgdqprZ6qS7P/SGOgxZzNAD14UeY17dp5BZyNcbhQYVzaPlwNYpG12IMd+kLRnrS0 NiHaaC46uomxvtXuYGp5PLIqWca9ngW7sVXEXpubf0WHPWIjQJ3IWFz2lIGx5Fyudcqy JJcQ== X-Gm-Message-State: AKwxytewpg4c64bZMHzPONW30Qtosal1eu+9IINYZNKORGlgM4w3OA4c sIk1RNbODwGWk8ZEs7kfNfm96/sWLFM= X-Google-Smtp-Source: AH8x227pHEXdFheOJUD/9YYRmrW1NTXQwDGL2oYdwMeAPnhUxXajJzmgjr6f1CUcwdMBsDVcn/MLHA== X-Received: by 10.25.74.87 with SMTP id x84mr1255955lfa.109.1516713746516; Tue, 23 Jan 2018 05:22:26 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id y198sm51761lfd.62.2018.01.23.05.22.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 05:22:25 -0800 (PST) From: Linus Walleij To: dri-devel@lists.freedesktop.org, Eric Anholt , Daniel Vetter , Jani Nikula , Sean Paul Subject: [PATCH] drm/pl111: Use max memory bandwidth for resolution Date: Tue, 23 Jan 2018 14:22:20 +0100 Message-Id: <20180123132220.29886-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 Cc: linux-arm-kernel@lists.infradead.org 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 were previously selecting 1024x768 and 32BPP as the default set-up for the PL111 consumers. This does not work on elder systems: the device tree bindings support a property "max-memory-bandwidth" in bytes/second that states that if you exceed this the memory bus will saturate. The result is flickering and unstable images. Parse the "max-memory-bandwidth" and respect it when intializing the driver. On the RealView PB11MP we get a nice 1024x768 console with RGB565 as default with this code. If the device tree does not specify the maximum memory bandwidth we keep the old assumption that we can support 1024x768, 32BPP. Signed-off-by: Linus Walleij --- drivers/gpu/drm/pl111/pl111_drm.h | 1 + drivers/gpu/drm/pl111/pl111_drv.c | 99 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 97 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/pl111/pl111_drm.h b/drivers/gpu/drm/pl111/pl111_drm.h index 440f53ebee8c..770ef5ce3645 100644 --- a/drivers/gpu/drm/pl111/pl111_drm.h +++ b/drivers/gpu/drm/pl111/pl111_drm.h @@ -56,6 +56,7 @@ struct pl111_drm_dev_private { struct drm_fbdev_cma *fbdev; void *regs; + u32 memory_bw; u32 ienb; u32 ctrl; /* The pixel clock (a reference to our clock divider off of CLCDCLK). */ diff --git a/drivers/gpu/drm/pl111/pl111_drv.c b/drivers/gpu/drm/pl111/pl111_drv.c index 101a9c7db6ff..1b47ee67097d 100644 --- a/drivers/gpu/drm/pl111/pl111_drv.c +++ b/drivers/gpu/drm/pl111/pl111_drv.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include @@ -80,21 +81,107 @@ static const struct drm_mode_config_funcs mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; +/** + * pl111_choose_max_resolution() - choose max resolution + * @dev: DRM device + * @memory_bw: the graphics maximum memory bandwidth in bytes/s + * @max_width: returns the maximum width + * @max_height: returns the maximum height + * @bpp: returns the maximum bips per pixed (32 or 16) + * + * This function attempts to cut down the maximum supported resolution + * to something the system memory bus can handle. The PL111 and pixel + * clocks may be able to support higher resolutions and color depths + * but as we go up the memory bus get saturated and becomes the + * bottleneck for the resolution. On several systems using e.g. + * 1024x768 with 32 BPP results in instable flickering images. + */ +static void pl111_choose_max_resolution(struct drm_device *dev, + u32 memory_bw, + int *max_width, + int *max_height, + unsigned int *bpp) +{ + /* No limitations, this is the most aggressive */ + if (!memory_bw) { + *max_width = 1024; + *max_height = 768; + *bpp = 32; + return; + } + + /* + * 1024x768 with RGBX8888 requires a memory bandwidth of + * 65Mhz * 4 bytes = 260000000 bytes per second. + */ + if (memory_bw >= 260000000) { + *max_width = 1024; + *max_height = 768; + *bpp = 32; + return; + } + + /* + * 800x600 with RGB8888 requires a memory bandwidth of + * 36Mhz * 4 bytes = 144000000 bytes per second. But we + * assume the user prefer higher resolution over more + * color depth, so we do not add this mode here. + */ + + /* + * 1024x768 with RGB565 requires a memory bandwidth of + * 65Mhz * 2 bytes = 130000000 bytes per second. + */ + if (memory_bw >= 130000000) { + *max_width = 1024; + *max_height = 768; + *bpp = 16; + return; + } + + /* + * 800x600 with RGB565 requires a memory bandwidth of + * 36Mhz * 2 bytes = 72000000 bytes per second. + */ + if (memory_bw >= 72000000) { + *max_width = 800; + *max_height = 600; + *bpp = 16; + return; + } + + /* + * 640x480 with RGB565 requires a memory bandwidth of + * 25.175Mhz * 2 bytes = 50350000 bytes per second. + */ + if (memory_bw < 50350000) + dev_err(dev->dev, "can't even do 640x480 VGA RGB565, proceed anyway\n"); + + *max_width = 640; + *max_height = 480; + *bpp = 16; +} + static int pl111_modeset_init(struct drm_device *dev) { struct drm_mode_config *mode_config; struct pl111_drm_dev_private *priv = dev->dev_private; struct drm_panel *panel; struct drm_bridge *bridge; + unsigned int bpp; /* bits per pixel */ int ret = 0; drm_mode_config_init(dev); mode_config = &dev->mode_config; mode_config->funcs = &mode_config_funcs; mode_config->min_width = 1; - mode_config->max_width = 1024; mode_config->min_height = 1; - mode_config->max_height = 768; + + pl111_choose_max_resolution(dev, priv->memory_bw, + &mode_config->max_width, + &mode_config->max_height, &bpp); + dev_info(dev->dev, "cap resolution at %u x %u, %u BPP\n", + mode_config->max_width, mode_config->max_height, bpp); ret = drm_of_find_panel_or_bridge(dev->dev->of_node, 0, 0, &panel, &bridge); @@ -139,7 +226,7 @@ static int pl111_modeset_init(struct drm_device *dev) drm_mode_config_reset(dev); - priv->fbdev = drm_fbdev_cma_init(dev, 32, + priv->fbdev = drm_fbdev_cma_init(dev, bpp, dev->mode_config.num_connector); drm_kms_helper_poll_init(dev); @@ -216,6 +303,12 @@ static int pl111_amba_probe(struct amba_device *amba_dev, drm->dev_private = priv; priv->variant = variant; + if (of_property_read_u32(dev->of_node, "max-memory-bandwidth", + &priv->memory_bw)) { + dev_info(dev, "no max memory bandwidth specified, assume unlimited\n"); + priv->memory_bw = 0; + } + /* * The PL110 and PL111 variants have two registers * swapped: interrupt enable and control. For this reason