From patchwork Tue Jan 24 22:41:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayyan Ansari X-Patchwork-Id: 13114853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 90554C54E94 for ; Tue, 24 Jan 2023 22:42:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C0BEA10E26B; Tue, 24 Jan 2023 22:42:18 +0000 (UTC) Received: from out-54.mta0.migadu.com (out-54.mta0.migadu.com [91.218.175.54]) by gabe.freedesktop.org (Postfix) with ESMTPS id D781C10E268 for ; Tue, 24 Jan 2023 22:42:06 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ansari.sh; s=key1; t=1674600124; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KvJHwd3ZtTUQMGaubg6Qm+PNWUp6rIHTegEYq4CZ9Fo=; b=L6NmD0bbN/VtkjhGm01kiMkr5YLrKWJcjNKZXRKkn6BCj+HmG3cGPnzOeAqzgFLcIfIO0N 4ZaOQrrN7NHEtjmV3N14/GcpGS08eELuvgXcFm2T+EUfYKhGIwGWd2cNdKJrXl3ke9UxEN 7sYQz4/aOTCGOkW3c+eMMhwIz+3FB2s= From: Rayyan Ansari To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 1/2] drm/simpledrm: Allow physical width and height configuration via DT Date: Tue, 24 Jan 2023 22:41:41 +0000 Message-Id: <20230124224142.7133-2-rayyan@ansari.sh> In-Reply-To: <20230124224142.7133-1-rayyan@ansari.sh> References: <20230124224142.7133-1-rayyan@ansari.sh> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, janne@jannau.net, Krzysztof Kozlowski , Thomas Zimmermann , Rayyan Ansari , Javier Martinez Canillas , linux-kernel@vger.kernel.org, Hans de Goede , Rob Herring , ~postmarketos/upstreaming@lists.sr.ht, asahi@lists.linux.dev Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add optional width-mm and height-mm devicetree properties and use this to set the DRM Display Mode instead of calculating it based on an average DPI. Signed-off-by: Rayyan Ansari --- drivers/gpu/drm/tiny/simpledrm.c | 60 +++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/tiny/simpledrm.c b/drivers/gpu/drm/tiny/simpledrm.c index 162eb44dcba8..7aab7fa572f0 100644 --- a/drivers/gpu/drm/tiny/simpledrm.c +++ b/drivers/gpu/drm/tiny/simpledrm.c @@ -128,6 +128,23 @@ simplefb_read_u32_of(struct drm_device *dev, struct device_node *of_node, return ret; } +static int +simplefb_read_u32_of_opt(struct drm_device *dev, struct device_node *of_node, + const char *name, u32 *value) +{ + int ret = of_property_read_u32(of_node, name, value); + + if (ret == -EINVAL) { + *value = 0; + ret = 0; + } else if (ret) { + drm_err(dev, "simplefb: cannot parse framebuffer %s: error %d\n", + name, ret); + } + + return ret; +} + static int simplefb_read_string_of(struct drm_device *dev, struct device_node *of_node, const char *name, const char **value) @@ -184,6 +201,19 @@ simplefb_get_format_of(struct drm_device *dev, struct device_node *of_node) return simplefb_get_validated_format(dev, format); } +static int +simplefb_get_mm_of(struct drm_device *dev, struct device_node *of_node, + const char *name) +{ + int mm; + int ret = simplefb_read_u32_of_opt(dev, of_node, name, &mm); + + if (ret) + return ret; + return simplefb_get_validated_int(dev, name, mm); +} + + /* * Simple Framebuffer device */ @@ -599,16 +629,12 @@ static const struct drm_mode_config_funcs simpledrm_mode_config_funcs = { */ static struct drm_display_mode simpledrm_mode(unsigned int width, - unsigned int height) + unsigned int height, + unsigned int width_mm, + unsigned int height_mm) { - /* - * Assume a monitor resolution of 96 dpi to - * get a somewhat reasonable screen size. - */ const struct drm_display_mode mode = { - DRM_MODE_INIT(60, width, height, - DRM_MODE_RES_MM(width, 96ul), - DRM_MODE_RES_MM(height, 96ul)) + DRM_MODE_INIT(60, width, height, width_mm, height_mm) }; return mode; @@ -622,6 +648,7 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, struct simpledrm_device *sdev; struct drm_device *dev; int width, height, stride; + int width_mm = 0, height_mm = 0; const struct drm_format_info *format; struct resource *res, *mem; void __iomem *screen_base; @@ -676,6 +703,12 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, format = simplefb_get_format_of(dev, of_node); if (IS_ERR(format)) return ERR_CAST(format); + width_mm = simplefb_get_mm_of(dev, of_node, "width-mm"); + if (width_mm < 0) + return ERR_PTR(width_mm); + height_mm = simplefb_get_mm_of(dev, of_node, "height-mm"); + if (height_mm < 0) + return ERR_PTR(height_mm); } else { drm_err(dev, "no simplefb configuration found\n"); return ERR_PTR(-ENODEV); @@ -686,7 +719,16 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, return ERR_PTR(-EINVAL); } - sdev->mode = simpledrm_mode(width, height); + /* + * Assume a monitor resolution of 96 dpi if physical dimensions + * are not specified to get a somewhat reasonable screen size. + */ + if (!width_mm) + width_mm = DRM_MODE_RES_MM(width, 96ul); + if (!height_mm) + height_mm = DRM_MODE_RES_MM(height, 96ul); + + sdev->mode = simpledrm_mode(width, height, width_mm, height_mm); sdev->format = format; sdev->pitch = stride; From patchwork Tue Jan 24 22:41:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rayyan Ansari X-Patchwork-Id: 13114852 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E1A6BC61DA0 for ; Tue, 24 Jan 2023 22:42:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B348E10E268; Tue, 24 Jan 2023 22:42:12 +0000 (UTC) Received: from out-48.mta0.migadu.com (out-48.mta0.migadu.com [IPv6:2001:41d0:1004:224b::30]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A63410E268 for ; Tue, 24 Jan 2023 22:42:07 +0000 (UTC) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ansari.sh; s=key1; t=1674600125; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=36Vs8J0xhZS4TyMPNV0MC8jbKBVP8w8N3cOPO33G5Wk=; b=NDz7l4pPA+sUvoQ0mDQNcUtYzr72ERejOPwyYOT4DtmFUwQqUNTU257VyRO0+JF/FswAXH o+DK4x7vQ2KpVpyASwIA8gwOmP/oGcIzYvE/zqTEcqeFrGuPgG7NvzXYM8TEz1lj5rJldo K7Dqn36RngXMNaaFLCEqxRHj8zJe9GU= From: Rayyan Ansari To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 2/2] dt-bindings: display: simple-framebuffer: Document physical width and height properties Date: Tue, 24 Jan 2023 22:41:42 +0000 Message-Id: <20230124224142.7133-3-rayyan@ansari.sh> In-Reply-To: <20230124224142.7133-1-rayyan@ansari.sh> References: <20230124224142.7133-1-rayyan@ansari.sh> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-fbdev@vger.kernel.org, janne@jannau.net, Krzysztof Kozlowski , Thomas Zimmermann , Rayyan Ansari , Javier Martinez Canillas , linux-kernel@vger.kernel.org, Hans de Goede , Rob Herring , ~postmarketos/upstreaming@lists.sr.ht, asahi@lists.linux.dev Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Document the optional width-mm and height-mm simple-framebuffer properties. Signed-off-by: Rayyan Ansari --- .../devicetree/bindings/display/simple-framebuffer.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/display/simple-framebuffer.yaml b/Documentation/devicetree/bindings/display/simple-framebuffer.yaml index dd64f70b5014..4ae33a4d2da9 100644 --- a/Documentation/devicetree/bindings/display/simple-framebuffer.yaml +++ b/Documentation/devicetree/bindings/display/simple-framebuffer.yaml @@ -106,6 +106,12 @@ properties: - x2r10g10b10 - x8r8g8b8 + width-mm: + description: Physical width of the display in millimetres + + height-mm: + description: Physical height of the display in millimetres + display: $ref: /schemas/types.yaml#/definitions/phandle description: Primary display hardware node