From patchwork Thu Feb 1 13:04:46 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 126534 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp1689500ljc; Thu, 1 Feb 2018 05:04:55 -0800 (PST) X-Google-Smtp-Source: AH8x227ZcYm1vg2xTOvBKHYxiYl9TtmNLgxq6euJxktsmAD/m/jzUxCYAEmIgr2TncglFdsUGfsA X-Received: by 2002:a17:902:147:: with SMTP id 65-v6mr29881491plb.128.1517490295759; Thu, 01 Feb 2018 05:04:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517490295; cv=none; d=google.com; s=arc-20160816; b=m1/mLe0BSn0F0oBJP8UFZ5VEA5OnobQ9EkLHS+wyRISwBQ2+q2hVWhi3MPsvpmw13X S7EaF3KGu11EktcuViG76pkCTmlLAGbCnO/Igu5tf8t9f+yvtkEgL4WBjLinp/nJ6ls8 rRrltCRuE471DPiKWNTNZN80jsKFv+7nPyAB+AVyM9X7mFRYxUa8TbAYg+RBW7wSpJ3t M4ljEndv7QeIEuOB+QP2EpSicS6gqSKuSKYBnfBDuYzHPbAcjOp45AoSXAEJy0CX6KCQ qRW/1rMCdGNW4DekV7k05pwU+Sti4IyZ0v6C4dOkq3TTlxrsKpb6pI4MC+T9jogfwQFu lhvg== 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:cc :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:message-id:date:subject:to:from:dkim-signature :delivered-to:arc-authentication-results; bh=RhjJztE4jTxZFzwm9OHsCO1FhelQeUxycW7imje3T/0=; b=vt0J1kpIFiyc48qh0TuMNUTLsQB4SLAPohNbTifrOfT8PT6sJ/buGGjW01aIVmpTn9 /hv5Qzij81AHS+dM8qmUll679wkd9fo9yBZjUeNaeWpxv/Q7OTasjZO6IWZB9DM47UpN FaE0pckW0qoe0fGn6nc7siBhGI95QdGcIKttojVaSfWNnx/KsxK2qT8DTxBHIdu5iP+T A5hNQNAnARRWiK5UJwxl79x7nbLirg8QFCcNLeJTaP9f5GyE9r8vfKsB4/xaqhvWGMZa /hTo7vo/3C5aIZFKDMv1wJdgCU9u+iMpWiqj9VmCi/MetKQdtuuRUTVABOUDvuUrSYYW lFZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=H/jICvLb; 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 s86si1949390pfd.398.2018.02.01.05.04.55 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Feb 2018 05:04:55 -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=H/jICvLb; 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 BA1E86E0A3; Thu, 1 Feb 2018 13:04:53 +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 87C346E0A3 for ; Thu, 1 Feb 2018 13:04:52 +0000 (UTC) Received: by mail-lf0-x243.google.com with SMTP id a204so26103700lfa.2 for ; Thu, 01 Feb 2018 05:04:52 -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=SyU2DJ8k0aXvMOkPUQk8UMuQzTG3ImM42sd/hSwdfFU=; b=H/jICvLb5N4+yaxIG1xeTADHAget7+P12+uAApsiNLBsASv4cw5QqYMSgWpxXujwnC WsTwd/cITLUwA0vRR6X0xZGnRXZ4O2OSj3aSmTw6/oPQErQP5iPGNMNwzp+E030Bb6Nh UpM8xgtk0uX/WoVsUTQWpwmo1MgdmQk3dQfwQ= 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=SyU2DJ8k0aXvMOkPUQk8UMuQzTG3ImM42sd/hSwdfFU=; b=bUPPaq6+9Q9TjO3HFiSVfTrVpC2qnqIqlVfXTi6P2vfOogCQl8c7MG4RDjvahUE0EX RHFhiKhYj/UBtEW4OduEuGc9zH1mf3Q13t9KGtk8jfORTX2/H5I8Sl+584hm8OkOxlW6 j+Lxb0uGKaRuaNLI+eK0e1AheThKulGQWd5KoLUDuQW7wArGy6On3vAJBl/ocWd0r6UG zVpQ0e1CUEePu1aNjCBPEfYUnHQYK7t9Lc+bOta7BMD0MtKw3va4Rs5xSInh8RlmczlO bUsHCBDzhSyq2HH2GAOpZYPqKfZYmsZnUu0iFqNiF2tbHFVhWeorPWAqaF3j0oHkbNQ5 O9yg== X-Gm-Message-State: AKwxytfFrf29OTv2txGsiBVxLDOjdjCog3ft2jrnrF9iVOU+Z0dskboJ pquJtSvl6FU5tGbS97jXZMSwZQ== X-Received: by 10.46.48.1 with SMTP id w1mr7476731ljw.69.1517490290947; Thu, 01 Feb 2018 05:04:50 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id f126sm2645337lff.49.2018.02.01.05.04.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Feb 2018 05:04:50 -0800 (PST) From: Linus Walleij To: Bartlomiej Zolnierkiewicz , Eric Anholt , =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Dave Airlie , David Lechner Subject: [PATCH] drm/fb-helper: Scale back depth to supported maximum Date: Thu, 1 Feb 2018 14:04:46 +0100 Message-Id: <20180201130446.6165-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.14.3 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-fbdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org, dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The following happened when migrating an old fbdev driver to DRM: The Integrator/CP PL111 supports 16BPP but only ARGB1555/ABGR1555 or XRGB1555/XBGR1555 i.e. the maximum depth is 15. This makes the initialization of the framebuffer fail since the code in drm_fb_helper_single_fb_probe() assigns the same value to sizes.surface_bpp and sizes.surface_depth. I.e. it simply assumes a 1-to-1 mapping between BPP and depth, which is true in most cases but typically not for this hardware. To support the odd case of a driver supporting 16BPP with only 15 bits of depth, this patch will make the code loop over the formats supported on the primary plane and cap the depth to the maximum supported. On the PL110 Integrator, this makes drm_mode_legacy_fb_format() select DRM_FORMAT_XRGB1555 which is acceptable for this driver, and thus we get framebuffer, penguin and console on the Integrator/CP. Signed-off-by: Linus Walleij --- drivers/gpu/drm/drm_fb_helper.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index e56166334455..5076f9103740 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1720,6 +1720,8 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, int i; struct drm_fb_helper_surface_size sizes; int gamma_size = 0; + struct drm_plane *plane; + int best_depth = 0; memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); sizes.surface_depth = 24; @@ -1727,7 +1729,10 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, sizes.fb_width = (u32)-1; sizes.fb_height = (u32)-1; - /* if driver picks 8 or 16 by default use that for both depth/bpp */ + /* + * If driver picks 8 or 16 by default use that for both depth/bpp + * to begin with + */ if (preferred_bpp != sizes.surface_bpp) sizes.surface_depth = sizes.surface_bpp = preferred_bpp; @@ -1762,6 +1767,39 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, } } + /* + * If we run into a situation where, for example, the primary plane + * supports RGBA5551 (16 bpp, depth 15) but not RGB565 (16 bpp, depth + * 16) we need to scale down the depth of the sizes we request. + */ + drm_for_each_plane(plane, fb_helper->dev) { + /* Only check the primary plane */ + if (plane->type != DRM_PLANE_TYPE_PRIMARY) + continue; + + for (i = 0; i < plane->format_count; i++) { + const struct drm_format_info *fmt; + + fmt = drm_format_info(plane->format_types[i]); + /* We found a perfect fit, great */ + if (fmt->depth == sizes.surface_depth) + break; + + /* Skip depths above what we're looking for */ + if (fmt->depth > sizes.surface_depth) + continue; + + /* Best depth found so far */ + if (fmt->depth > best_depth) + best_depth = fmt->depth; + } + } + if (sizes.surface_depth != best_depth) { + DRM_DEBUG("requested bpp %d, scaled depth down to %d", + sizes.surface_bpp, best_depth); + sizes.surface_depth = best_depth; + } + crtc_count = 0; for (i = 0; i < fb_helper->crtc_count; i++) { struct drm_display_mode *desired_mode;