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: 1019197 Return-Path: X-Original-To: incoming-imx@patchwork.ozlabs.org Delivered-To: patchwork-incoming-imx@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A1N1U/Ty"; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="Wh3uAEM3"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43R9sm72bsz9rxp for ; Sat, 29 Dec 2018 02:41:16 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=joNrKr7yS7Fmjb6U+5jMtdm/yNcQxAzAZW7OYPXRqSg=; b=A1N1U/TyU303uD H13zkDuSiVJuxzlvRHAd14nrhKKGmjMXjtfNpFxSCFp+OHc9RbYFIeeQ5wt8KQG4hyQdRyAWAVYDP ZrSj4HgazNeX0+cMKthLFPMRD3LpAFUkLSd8rD4W7T1hKuGOFJtPZ0kkYH3/5HEK15bNm3iLxPJ0s C8nP0/4HrwFxqhW1y5TgcsU2UDZzBWUWey4oGR3M07Itpjtehpe7aQxGycfx+GN7cW5kZGL9vqMJb Nyu6q9C6xHJKgvyW0Re3JCFHQJksozCgFozz5YvmeqaECg2LizS72WWQs+S5xR5qX9pSuf7GdWQ7+ /B6IJkz4B6fZkgl/BcVA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcuG5-0000uv-SN; Fri, 28 Dec 2018 15:41:09 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gcuG2-0000uA-5Q for linux-arm-kernel@lists.infradead.org; Fri, 28 Dec 2018 15:41:07 +0000 Received: by mail-lf1-x141.google.com with SMTP id v5so14769850lfe.7 for ; Fri, 28 Dec 2018 07:40:55 -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:mime-version :content-transfer-encoding; bh=21bsbvry1odVTcqRpYrqvwkCOSdtbscuZy8+UeBKt40=; b=Wh3uAEM3h6DLV6/itgP98cVGx5/oDNCoCbjR+/ajc42ghSWqyi1ygeZp+9/9sH/PJ3 Uuq5IC4mFuPtb1JQ1loE3PyCq8Kne0N5HjqNQ/SHRDKl9QOe52kDltk76zA91xzOhsnK 9xHtI1p5yp5v7iFnEvfSWj6rBDFBA4PEQpmdE= 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=TDzSRUOx5Fo+dXPndaYSyV8CsjWnmvqRNoTaGfau40t1CJFMln/eDLmUrAEgM6EeWx J+JBHB30Kfh+ssKygeWpyjmpAS2fO4f1/TY0BRBGK2Y9NZiBh5rNuLaLZDUaG82IUCed Uo6PscCsXoTgifj+iywqQkbDp7JdnzVYj2X2AfMBNam6aX7ba4ck42JrDfOak+jxbG6b o9tAM2OAY0MFRzZRkPPdagbk0iTJERwFBW8IH5f5Yh5zSBRSg3oMCY1G97tGBHj5Bdmw +a6RgWgvoCyhI1Ic3ETKMJSRisXbz7whpXVbClX0Yp+5D50iKgq3U2aDBSn0jMWsHKN9 xowQ== X-Gm-Message-State: AA+aEWYkb4RaKFg10YelQFbkfzIb+/4p0YpdPwz9UDcSHPdW9XbKXKcy AMmyocWObMaOEmPHZvWKa2MkUg== X-Google-Smtp-Source: AFSGD/WKBi04XSTl+h6U02bk/UfDRBm+3Lzw8rB46ZQQ52lsgo+VLRnZ5R/PczXk9OkDpvO9O1uI3w== 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-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181228_074106_207691_7E6C7727 X-CRM114-Status: GOOD ( 19.84 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:141 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Linus Walleij , =?utf-8?q?Noralf_Tr=C3=B8nne?= =?utf-8?q?s?= , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+incoming-imx=patchwork.ozlabs.org@lists.infradead.org List-Id: linux-imx-kernel.lists.patchwork.ozlabs.org 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;