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: 125521 Delivered-To: patch@linaro.org Received: by 10.46.66.141 with SMTP id h13csp1760030ljf; Tue, 23 Jan 2018 05:35:03 -0800 (PST) X-Google-Smtp-Source: AH8x225WCVnWyBoh2ZFi/9rMMrE+7PA3l/Bz0HObQz/ZLJ9CGY8L2b610MSTzQmFhCS7FhE16imY X-Received: by 2002:a17:902:e81:: with SMTP id 1-v6mr5508726plx.235.1516714503244; Tue, 23 Jan 2018 05:35:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516714503; cv=none; d=google.com; s=arc-20160816; b=D7EysTMWltFYYBemeSuGC2KBpkrZQGv7u7jLlzA4r4a7KZ90tMgJpwIlyZpAOyS3Oo bJhLJ0CjDeXdw2wESQZ3b+GCm/hIwYi0szsWxo0XAaacYNcVa9fP9hzHgC7i8pQU+nNm s7EJ0ikmOEH6JQVVhJNZ981b05THncFgkO4WECXHMPacq0igDrzaiuHT7Zsd3k3A7Sl8 FqiX6HefpF7wr3beXam5ohUtEobkfyg2KzC7jki2WbZqRPj4sRBrAVLUd7O13EhBNZU5 o+7mKVyMmuhhd3K1I8k8JstIPrLiTuMeSTW7VZ5fyzfgyeahCwEZ6TZwJLE9jD4T7hXV dcIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:message-id:date:subject:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=VhbWBfBqYPoXuUupZjr8gHZunuwkDR0TbSdKcRO8s2w=; b=Ur5qpcVMLeMqPeh/IHEZLGjeWr/XjjsBsAhMLKNjs+e+Yy5bQelcVhxThfFM4FLzgO eeWeUnZCZO+X+sVNHtQR+oLtywHGqYIb9pfuQV+ha7fDKnPBPsvujdehDzG3zNDKpBeU mEMNBtSWfocSZTG6HbpiYtBTGnUr3AO5TV+9sz4w2FUmB0bzzigugufJpBOXKS/808iI ydigfVceV/SFs6ZmZ5KVi92LPPGVjajVI19wPklkoVCULbUJbfA4uHT/49DtdsaoWujk eYgs+t8MNmz4j3PLQjV52J4C1DwYTUEghhglB4U85l50DSoEZ+6XMhvCz0zQh91vnZpM kshw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KSl0/GxL; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id y96-v6si4759716plh.703.2018.01.23.05.35.02 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 23 Jan 2018 05:35:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=KSl0/GxL; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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-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" 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