Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp4258645rwb; Sat, 21 Jan 2023 08:25:34 -0800 (PST) X-Google-Smtp-Source: AMrXdXvFFfuSeieL60Bot/ZDsoEZLKV6H//ywizwPN/gzIZyZlh9HWCrAtQ9rtb5Q6gFxp3yK3A6 X-Received: by 2002:a17:906:814e:b0:86d:f6fe:3c3b with SMTP id z14-20020a170906814e00b0086df6fe3c3bmr19732811ejw.23.1674318334458; Sat, 21 Jan 2023 08:25:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674318334; cv=none; d=google.com; s=arc-20160816; b=p2SgMV9HoiHcxV5vEH6GwMIJStguUiWF3uU5pv9+4nVLUjhULcQCZMv9MsGJ5YmccI 7togGD5IZFI8pZSLjSIUI8Rawyk1CT7fMuzuVrs8ejMMGQ5nAXWg9ZgUp+bTt5JhGGbl rBEMmWNZAdmQ9gQmYRL2BCMxVmsJvkh+ajqBXOS93f9LRR8daiOWLAds/rAc9Oz+t5Zs MCRIGwMHIpf/UW2tAyCTBFViF1QrOBOpiX+f/v3hM1uGTJ+AV1pzoU1W82OWriglVHkv RrRd+r8qC0Pw8DM/YyOKAGvSItAsppRaPx8FmSQf+wREG5TugQoEgL0w6DbrEgWTCpaO l6OA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A4c8WkU35Mq5MDZit6NsQwryhg7/hXEwGbhE/MTvXvA=; b=vcZ1BNpX3OugLXsC23c9zhdAOHjbFCgHBI8RBK7xU1v4hd6tKbSma8qbKwviTxWd6N 6X9I2TjAJYx5zlxL/p2Sg7HtLOQqsmBiBND0D3qgHoWFJ3Fk0dl6I8RMNV1PotJW/ojJ X4r2sBOBisBRbbVtoxFePhcJhnKZNN7WPa27/j+4DCnMRr9pXr5XBbmMY4AR9wx03JVO u/k4b27SfsaSptCrNQ6Qgv/0mls++q8B6yQjc0tv4Hvkw45SmmRWZ7toLCRFkNggg8Q4 8Sh/IEhLnQXlWB1TvSnayJmf784hdFPxT6pu2axzb2nWEaJf+caMRwj5MvzFFxGsf0jV /I9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ansari.sh header.s=key1 header.b=EvhIzhnm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ansari.sh Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id cr16-20020a170906d55000b00870b95fb7c4si24234993ejc.998.2023.01.21.08.25.22; Sat, 21 Jan 2023 08:25:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ansari.sh header.s=key1 header.b=EvhIzhnm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=ansari.sh Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbjAUPg2 (ORCPT + 50 others); Sat, 21 Jan 2023 10:36:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229540AbjAUPgZ (ORCPT ); Sat, 21 Jan 2023 10:36:25 -0500 Received: from out2.migadu.com (out2.migadu.com [188.165.223.204]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF4C728D1C; Sat, 21 Jan 2023 07:36:24 -0800 (PST) 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=1674315383; 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=A4c8WkU35Mq5MDZit6NsQwryhg7/hXEwGbhE/MTvXvA=; b=EvhIzhnmrTwhMfdhF5oPG9UJeknkJw+xNAd4IY2QbS2p6vOSWTo3Vd/O8w2WbFbFBsWluL 1QeQXbrSZBOvaoXPV5eekY9OktKC0xJhhPNkva+47XL9au1Xw07raV6gnfCKtVlzQtfjT/ yAyoQ+DKnhhzoIun8OK5dz6sLBQl/x0= From: Rayyan Ansari To: dri-devel@lists.freedesktop.org Cc: ~postmarketos/upstreaming@lists.sr.ht, asahi@lists.linux.dev, janne@jannau.net, Rayyan Ansari , Daniel Vetter , David Airlie , devicetree@vger.kernel.org, Hans de Goede , Javier Martinez Canillas , Krzysztof Kozlowski , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org, Rob Herring , Thomas Zimmermann Subject: [PATCH v2 1/2] drm/simpledrm: Allow physical width and height configuration via DT Date: Sat, 21 Jan 2023 15:35:43 +0000 Message-Id: <20230121153544.467126-2-rayyan@ansari.sh> In-Reply-To: <20230121153544.467126-1-rayyan@ansari.sh> References: <20230121153544.467126-1-rayyan@ansari.sh> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; -- 2.39.0