From patchwork Thu Jan 10 11:40:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 155132 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1792634jaa; Thu, 10 Jan 2019 03:40:56 -0800 (PST) X-Google-Smtp-Source: ALg8bN4LOskgmmJ0iV9UbcEue4jjBB6mM6+lSQeTwvPUJN3cGDhoUNhnIl0nhmWUS474dIOXJjDw X-Received: by 2002:a62:a99:: with SMTP id 25mr9740220pfk.121.1547120456922; Thu, 10 Jan 2019 03:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547120456; cv=none; d=google.com; s=arc-20160816; b=M9YCie5G/x+EwOaEbwc+x7CBVay3+qy05ix4ML594vBkJoDigsJ3SB+ldbzcbPhrH1 rGIOcYQMWnvXwknOH98Su0KizcjVjcis2PeDxKsYSvFYsTpE6sPI0UkPPSEVQLU49pUL un3bW+B6VvrH3knvmoPOTSvm+A8ZD16U43g5eDmOa7sA7igVA9TCZdVX8viv5zL5cnCC s/QXNTaJlmPeGu8PeUguQG9obt98RDfU23hceSJKogAuHRWjq3ydyVSx2X/2QWnuX+s6 RKGcdNGU/PiD69cyuAtX9yVsMg5jAW8rf8DWfjOtrNYmBpnvx6SNcgBc/E+X5AoJyptz TUZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=IlDK8bGb/kRNe1UzuHHE+g8wvOU0YDJW7WMbCLP2uh0=; b=Ctu3BNr9OfNhPOQFn0R4etdlYX7jYMLKg65YbLoUFfQqxpOQiRXW6zbm14j6LSiSi8 6uxeuT5PPBAdmRRgOQwDjKPTTegpx4pTOF08Q2wTjRhabjBdZr/dSv/JgkohG9kd91A5 6iAU+CyL4YVPQS0Po7UOvS1S8NaB/OCOAKuZYuY6m76UUUEHsQnRs/nKkbfE1aA2aDeW qbDrotjen7s39j/smqD/nXsF1oK9LBeHqDRamfRRp86b3r0JZ/BT1VJcY6HpLKCT+93n IKAYuOdOyof+zRpv+8yDrlNMdoT5MShAMKwTnxUVm5v/1G5i/tJ5QCL+/s44Y8RXzYxt DyKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+FGocRv; spf=pass (google.com: best guess record for domain of linux-fbdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-fbdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x135si72849358pgx.579.2019.01.10.03.40.56; Thu, 10 Jan 2019 03:40:56 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-fbdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=d+FGocRv; spf=pass (google.com: best guess record for domain of linux-fbdev-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-fbdev-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728456AbfAJLk4 (ORCPT + 1 other); Thu, 10 Jan 2019 06:40:56 -0500 Received: from mail-lf1-f65.google.com ([209.85.167.65]:33012 "EHLO mail-lf1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727938AbfAJLk4 (ORCPT ); Thu, 10 Jan 2019 06:40:56 -0500 Received: by mail-lf1-f65.google.com with SMTP id i26so8090226lfc.0 for ; Thu, 10 Jan 2019 03:40:54 -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=IlDK8bGb/kRNe1UzuHHE+g8wvOU0YDJW7WMbCLP2uh0=; b=d+FGocRvhsD+gmzQW8HEJEv1gnpLdpOeJZQW4JLualBkev6vkye2YieO0ftmo4S1LZ 3NaeHEdVLiJ1F64qJQck7pL3MLX+mGPONC/cenzjYeQ4CMWPFL3ttvi0AwA2zPNpKhqn mgkPMjQvNAOD/rbvU4fNNritrslBMOTMzyWEM= 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=IlDK8bGb/kRNe1UzuHHE+g8wvOU0YDJW7WMbCLP2uh0=; b=O/sEzQdkYMp3uT+p7COXunds0uErYXtS50pXgI0vGwTHxgLyXQd6/ycb8CqVc3wnKT dDzjLaWdIVaFW/iWMT/NTNRMb1VfXBgvoYdbqRMCOjRAWSy4/FP39ZbGNGmmQgOiL+KY TEnFSnrG2+USX/TChOJ9hmd8e0znkvPUhg2s6YQFmRDoARLJ25eTbfI6bkt6/DkihwwR hfGzmuanvR9ObKC4aLc7D2w4LWQ05Nrxac5BZ8pnbCxhTWWxBBLEZZgVwBSYB9hcBzx8 7cSfULYpr8GNSUlm9v376F2/xUJNpzz61bptG0STsESWChjeEWB7XjER8+qfGXjYoGgS DhZg== X-Gm-Message-State: AJcUukfwk9YTjM1fCRUDTzIGXuMdjjaXejsxuUNBQtAcEmspHMviod+6 iK+PmEn/v9r1w6jFtK4JVgBHmQ== X-Received: by 2002:a19:5a05:: with SMTP id o5mr5974222lfb.140.1547120453263; Thu, 10 Jan 2019 03:40:53 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id k20sm7573177lfe.3.2019.01.10.03.40.51 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 10 Jan 2019 03:40:52 -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?q?Ville_Syrj=C3=A4l?= =?utf-8?b?w6Q=?= Subject: [PATCH v4] drm/fb-helper: Scale back depth to supported maximum Date: Thu, 10 Jan 2019 12:40:49 +0100 Message-Id: <20190110114049.10618-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 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 v3->v4: - Assign best_depth also when we have a perfect fit, duh. 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 | 55 ++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) -- 2.19.2 diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index d3af098b0922..f7f31ad5d3ee 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,55 @@ 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) { + best_depth = fmt->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;