From patchwork Fri Dec 28 15:40:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 154607 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp8147047ljp; Fri, 28 Dec 2018 07:40:58 -0800 (PST) X-Google-Smtp-Source: AFSGD/VDq7bQYQMuMMpFYMmQE1EeTgy3uLp8Hoe1sMCuRCz7fK3QfEjflE3bXCs8D2GO1NDmVTRp X-Received: by 2002:aa7:8608:: with SMTP id p8mr28998486pfn.125.1546011658539; Fri, 28 Dec 2018 07:40:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546011658; cv=none; d=google.com; s=arc-20160816; b=nN/EkMFM91s/xYrDCHwzBYtKeUUXhu8gTH0AbwgjIpghZ5mB7EJlv1uKR7DJ9vKpUS tR0p9vbGHm1t+ADWOlquMgBRh8l8/SJsi34L1M/KQVUF1fp96tHKLkqbjcPgfF3sQMus c0K+obXEtcnHoc76xIMOxypPiC1QQvWWqB+Whun8Gl7+t13veczff+c1eCYoHMa6g4VM PDTPF93ap6bsPuDHpp4Ef0DRK+WFKe4Mrv2ANag1mcc/OuhAakKilK1SJ+Hd2eSxBVk0 ISZTwCUAQmm7cgOUGDEutQsjnv3iBytLJlN+zwTwniJ30MX4Xx+wxgwSl2P6dT/YLNp7 Kieg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:message-id:date:subject:to:from :delivered-to; bh=32fipst0yafZxvIVE2Jq583aPNHJOAMRRaBlTKO2aGE=; b=yHYaCWw4uKE13JlgGDc0MoAYuYXkpAlNdFwDidzctVtdQZqiaOPoiUBP8aKg5hCrxy sdB0VmtbQgmZBKpJu1CWAsubiRPRNSBG4BvVWsyWwBNc+BpVdWWCc+Y4JkIj8iaotnHE ltWRD8PoaR9Bl7OTK3A6K24F7ZD6iI/wsK3g7y9IDYo5B+AJzYXtUHhwztwRAP7OGNo3 mivBoWVwapIAu/Rtb9TBJIlyjvTLBvMU7HlaSffZc7pbi6QSW246wTFKatX/W6oXr9ZA kh4KVEWzm0sU8lVoQJ1uGx4FNWqHtugw+18r0QXJx0jGNRAHvyuIVWWlj2h3xG3d2I5p vyrg== ARC-Authentication-Results: i=1; mx.google.com; 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 a24si38054320pgd.248.2018.12.28.07.40.58 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Dec 2018 07:40:58 -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; 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 69B336E98F; Fri, 28 Dec 2018 15:40:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x144.google.com (mail-lf1-x144.google.com [IPv6:2a00:1450:4864:20::144]) by gabe.freedesktop.org (Postfix) with ESMTPS id 49E586E98F for ; Fri, 28 Dec 2018 15:40:55 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id p6so14830381lfc.1 for ; Fri, 28 Dec 2018 07:40:55 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=21bsbvry1odVTcqRpYrqvwkCOSdtbscuZy8+UeBKt40=; b=kH0/vWwcL0nwSWx+aqvKt0sycQJk46C4Rpu/mdDlVGagaglq8KcCOegRGbowoaNGJo nf0cM9abZgK5wOA6h0ggkm0S1cZrVEniDKx1j54jbSlQmZwPnRtcXsyb1peIWazlZ13x bNoM/g2YprRkEWjiQFlXB0nlmRl/6rofi7LR7GUoU+uVkdQNFSUMAGe/ICJJP/gBq/zi THSlgXPNxPnVA02kwivlLcT9FxHTiSFXbosiBvRkiE6ukDvXMFneD/BVNzECbFOxRrrx 2qNNa6QA8GB6Ixqwe0BBWn6KnKSnvlUu6AdLGEUMzX8hO6HIrhagUrRvQoqWWvxpggDo jJVg== X-Gm-Message-State: AA+aEWaXhOuM4khQEj8G3tUmvC2fe1FKgsYEnYrXQfvmiyhxzj0krpSH WltQZz4xKUSdts44ge+poM8+4P5D4uSbSg== X-Received: by 2002:a19:5d42:: with SMTP id p2mr15075250lfj.83.1546011653326; Fri, 28 Dec 2018 07:40:53 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id d24-v6sm8599125ljg.2.2018.12.28.07.40.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Dec 2018 07:40:52 -0800 (PST) From: Linus Walleij To: dri-devel@lists.freedesktop.org, Eric Anholt , Daniel Vetter , Jani Nikula , Sean Paul Subject: [PATCH v2] drm/fb-helper: Scale back depth to supported maximum Date: Fri, 28 Dec 2018 16:40:44 +0100 Message-Id: <20181228154044.10945-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 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-arm-kernel@lists.infradead.org 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 not for this hardware that only support odd formats. 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 on each CRTC managed by the FB helper and cap the depth to the maximum supported on any primary plane. 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. Cc: Noralf Trønnes Cc: Ville Syrjälä Signed-off-by: Linus Walleij Reviewed-by: Daniel Vetter --- ChangeLog v1->v2: - Loop over the CRTCs managed by the helper and check the crtc->primary on each CRTC for the applicable formats and thus depths. - Skip over YUV formats. The framebuffer emulation cannot handle these formats. The v1 was sent some while back in february and I only recently got back to fixing this up to support the last CLCD displays. It was agreed that it is probably best to augment the framebuffer initializer to pass a desired pixel format instead of just BPP as today, but that is a bit daunting, and Daniel said that we would probably anyways need a fallback like this. --- drivers/gpu/drm/drm_fb_helper.c | 47 ++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index d3af098b0922..57be06d932e4 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -1797,6 +1797,7 @@ 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; + int best_depth = 0; memset(&sizes, 0, sizeof(struct drm_fb_helper_surface_size)); sizes.surface_depth = 24; @@ -1804,7 +1805,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; @@ -1839,6 +1843,47 @@ 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. + */ + for (i = 0; i < fb_helper->crtc_count; i++) { + struct drm_mode_set *mode_set = &fb_helper->crtc_info[i].mode_set; + struct drm_crtc *crtc = mode_set->crtc; + struct drm_plane *plane = crtc->primary; + int j; + + DRM_DEBUG("test CRTC %d primary plane\n", i); + + for (j = 0; j < plane->format_count; j++) { + const struct drm_format_info *fmt; + + fmt = drm_format_info(plane->format_types[j]); + + /* Do not consider YUV formats for framebuffers */ + if (fmt->is_yuv) + continue; + + /* 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_INFO("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;