From patchwork Thu Jan 10 09:24:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10755417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3A156C2 for ; Thu, 10 Jan 2019 09:24:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B51E82923C for ; Thu, 10 Jan 2019 09:24:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A938229254; Thu, 10 Jan 2019 09:24:19 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0CA2C29250 for ; Thu, 10 Jan 2019 09:24:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727865AbfAJJYS (ORCPT ); Thu, 10 Jan 2019 04:24:18 -0500 Received: from mail-lj1-f193.google.com ([209.85.208.193]:42650 "EHLO mail-lj1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726255AbfAJJYS (ORCPT ); Thu, 10 Jan 2019 04:24:18 -0500 Received: by mail-lj1-f193.google.com with SMTP id l15-v6so9024478lja.9 for ; Thu, 10 Jan 2019 01:24:15 -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=JR/GkMfuzX7df3pIgljwTmHVCF8u0ta8aYFvG3AlIeU=; b=DD21+p7H8rbl+MEPYKD5KxW/YNAFY98EG3IEp9GrlfytvsIaO099tDMsv6KFt5RzjJ 2wxk4TM4vCiHfs4UUzkinl2rr14Qg1ZvrDM+sC9Ej6pA4ZgBCbjS7MUOCUmflhdiZprz oYeevTmYn9ZKqfNXJsmHqLSYzZ8naNVET5KeA= 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=JR/GkMfuzX7df3pIgljwTmHVCF8u0ta8aYFvG3AlIeU=; b=WP0rfUC0QyBJzJ931pWdmeZ2qGf5mwpxUGKxDV2SV117LqXr6dLjHD9SPxRgy4ovrC I1TSlYpLGvSmrlP3uaCpxGLMv/GJfMZO57ZyFUOAe97yG7Vi5JIDvf3NdMeR+VRHLF+p er/by8iJ6yxtANQMnq/tu4RizD98xEpcWunxzCLaRRVa7U4M9NhwrCqrDFYmYzTJZD6w mxuyMkEmPAY+eHbF447bNziooCMQvAREw4mIt++BGGIgt8vTv07Q1QC6zUuf6iZ+78PQ qOJTdKeyrQALFbg77ZQ2cppMcXR3zm6+gK2yPSfMyKvjhH8XkT5UQWjp3m8y0z+/+aMp Lz0w== X-Gm-Message-State: AJcUukdi9tTD+wRDMoLuvHnITF4Saf44MjYCAPYlcDtreHa2allf4ZPT ul3zcUWs1zlZtUwB3x2Bc5SHKg== X-Google-Smtp-Source: ALg8bN7Umo/WCw5U+rXhWqJcdAOFL6eIW9vg9g+iiW8jHW7v4n0eJqTjTlp5X/tCJujPmkrauRmtkA== X-Received: by 2002:a2e:12d0:: with SMTP id 77-v6mr5244674ljs.132.1547112255016; Thu, 10 Jan 2019 01:24:15 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id q6sm13881335lfh.52.2019.01.10.01.24.13 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 01:24:13 -0800 (PST) From: Linus Walleij To: Bartlomiej Zolnierkiewicz , Eric Anholt , =?utf-8?q?Noralf_Tr=C3=B8nnes?= , Dave Airlie , David Lechner Cc: dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, linux-fbdev@vger.kernel.org, Linus Walleij , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= Subject: [PATCH v3] drm/fb-helper: Scale back depth to supported maximum Date: Thu, 10 Jan 2019 10:24:03 +0100 Message-Id: <20190110092403.28324-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.2 MIME-Version: 1.0 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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ä Reviewed-by: Daniel Vetter Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased and tested with v5.0-rc1 - Skip any formats with fmt->depth == 0 - Collected Daniels review tag. 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 | 53 ++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index d3af098b0922..e29432e486f4 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,53 @@ 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 or other complicated formats + * for framebuffers. This means only legacy formats + * are supported (fmt->depth is a legacy field) but + * the framebuffer emulation can only deal with such + * formats, specifically RGB/BGA formats. + */ + if (fmt->depth == 0) + 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;