From patchwork Wed Jun 17 23:18:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 11611533 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54E2A14B7 for ; Thu, 18 Jun 2020 07:18:14 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 341CD21532 for ; Thu, 18 Jun 2020 07:18:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DhL6Q+i9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 341CD21532 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A55446EAC5; Thu, 18 Jun 2020 07:17:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-lf1-x143.google.com (mail-lf1-x143.google.com [IPv6:2a00:1450:4864:20::143]) by gabe.freedesktop.org (Postfix) with ESMTPS id 93E5A6E21A for ; Wed, 17 Jun 2020 23:20:16 +0000 (UTC) Received: by mail-lf1-x143.google.com with SMTP id t74so2363034lff.2 for ; Wed, 17 Jun 2020 16:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9RXXDREzEvi9GJkz9Ew+kxIBw0+JCmn+dwyV4+Iogjo=; b=DhL6Q+i9H1kTLhsx/jJL8lSuJaElavKhd6ST9db/CbXsuk6jwmsjgZ8MTjd/YRdQHS SKta33F1AQVLw5b9TN66Y9hcba3AGfeV5ZPKOXhDqYXwex8bqtnbbZAxdzpaAXhILZed /Kn9oJ+sFyuvJ7UvBz3MVt0FUOMGPIrziDbxhLup6Iy+p+04IZesaJaUqbeg/wDVdh2G a8xPi+4E/rnOwFs85KQz2nlZzNckhUdRF0nnb4pT9rd8pQGWce1WsmD4fOcoBq+DAb7q YmtirL6GsWZu5GJ9fTuAhTIKqBX9atSzwRZmGZe5QRKEI7Tdy9quNl7rTkBvhNx/72Oa jXeA== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=9RXXDREzEvi9GJkz9Ew+kxIBw0+JCmn+dwyV4+Iogjo=; b=UwiHApbfLWSMrVrzx4GdwmUw9Reo6g5FtZ6InehyQSoZrvlcZ+AIfESBa/EXnvP8Gn j0V2rN/VZaH9JTpcOx96SUcbosRmQK2JS2x1B9sf20jalGu/Q3rZxMgRU+8CA+FyIbPO RtzHa+lsSNPGgthDpf8oAbBgrucDf0Ho45cpcqwCZT3ppvXSctP9v6ljLXZ+KekD60DI 09TBF06XJAMiON2EY3D1ppdgV7zmtg1t7GQfD8XA658uC0g1h7dnyZRIpEK5o1v8EvGo hMIOpi6y+t0LP52aQMaR88L0NZ0uYIg9/98bmxmshrQzmUdJf2Vu2pd02lcxUjtlUdSw mM1Q== X-Gm-Message-State: AOAM533a8olvWS7n6EU0Rrk89JW4S4CykqMub3Zu11h5fxvA2oOZrQf1 U1uubYV7i4BpsT186s9e/a/8xydW X-Google-Smtp-Source: ABdhPJwZXIhog4dfoVtf01rQeNtS3EPm83m3tQ88S1ioAOIyLA+qbTylfDrp24rpcDGN50czElcYXQ== X-Received: by 2002:a19:c797:: with SMTP id x145mr680536lff.143.1592436014944; Wed, 17 Jun 2020 16:20:14 -0700 (PDT) Received: from localhost.localdomain (79-139-237-54.dynamic.spd-mgts.ru. [79.139.237.54]) by smtp.gmail.com with ESMTPSA id x3sm235100ljc.82.2020.06.17.16.20.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Jun 2020 16:20:14 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Thomas Zimmermann , Derek Basehore , Sam Ravnborg , Laurent Pinchart , Sean Paul , Daniel Vetter , =?utf-8?b?VmlsbGUgU3lyasOkbMOk?= , Emil Velikov , Daniel Stone Subject: [PATCH v11 1/4] drm/panel: Add helper for reading DT rotation Date: Thu, 18 Jun 2020 02:18:39 +0300 Message-Id: <20200617231842.30671-2-digetx@gmail.com> X-Mailer: git-send-email 2.26.0 In-Reply-To: <20200617231842.30671-1-digetx@gmail.com> References: <20200617231842.30671-1-digetx@gmail.com> MIME-Version: 1.0 X-Mailman-Approved-At: Thu, 18 Jun 2020 07:17:31 +0000 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: linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Derek Basehore This adds a helper function for reading the rotation (panel orientation) from the device tree. Signed-off-by: Derek Basehore Reviewed-by: Sam Ravnborg Tested-by: Dmitry Osipenko --- drivers/gpu/drm/drm_panel.c | 43 +++++++++++++++++++++++++++++++++++++ include/drm/drm_panel.h | 9 ++++++++ 2 files changed, 52 insertions(+) diff --git a/drivers/gpu/drm/drm_panel.c b/drivers/gpu/drm/drm_panel.c index 8c7bac85a793..5557c75301f1 100644 --- a/drivers/gpu/drm/drm_panel.c +++ b/drivers/gpu/drm/drm_panel.c @@ -300,6 +300,49 @@ struct drm_panel *of_drm_find_panel(const struct device_node *np) return ERR_PTR(-EPROBE_DEFER); } EXPORT_SYMBOL(of_drm_find_panel); + +/** + * of_drm_get_panel_orientation - look up the orientation of the panel through + * the "rotation" binding from a device tree node + * @np: device tree node of the panel + * @orientation: orientation enum to be filled in + * + * Looks up the rotation of a panel in the device tree. The orientation of the + * panel is expressed as a property name "rotation" in the device tree. The + * rotation in the device tree is counter clockwise. + * + * Return: 0 when a valid rotation value (0, 90, 180, or 270) is read or the + * rotation property doesn't exist. -EERROR otherwise. + */ +int of_drm_get_panel_orientation(const struct device_node *np, + enum drm_panel_orientation *orientation) +{ + int rotation, ret; + + ret = of_property_read_u32(np, "rotation", &rotation); + if (ret == -EINVAL) { + /* Don't return an error if there's no rotation property. */ + *orientation = DRM_MODE_PANEL_ORIENTATION_UNKNOWN; + return 0; + } + + if (ret < 0) + return ret; + + if (rotation == 0) + *orientation = DRM_MODE_PANEL_ORIENTATION_NORMAL; + else if (rotation == 90) + *orientation = DRM_MODE_PANEL_ORIENTATION_RIGHT_UP; + else if (rotation == 180) + *orientation = DRM_MODE_PANEL_ORIENTATION_BOTTOM_UP; + else if (rotation == 270) + *orientation = DRM_MODE_PANEL_ORIENTATION_LEFT_UP; + else + return -EINVAL; + + return 0; +} +EXPORT_SYMBOL(of_drm_get_panel_orientation); #endif #if IS_REACHABLE(CONFIG_BACKLIGHT_CLASS_DEVICE) diff --git a/include/drm/drm_panel.h b/include/drm/drm_panel.h index 6193cb555acc..781c735f0f9b 100644 --- a/include/drm/drm_panel.h +++ b/include/drm/drm_panel.h @@ -35,6 +35,8 @@ struct drm_device; struct drm_panel; struct display_timing; +enum drm_panel_orientation; + /** * struct drm_panel_funcs - perform operations on a given panel * @@ -191,11 +193,18 @@ int drm_panel_get_modes(struct drm_panel *panel, struct drm_connector *connector #if defined(CONFIG_OF) && defined(CONFIG_DRM_PANEL) struct drm_panel *of_drm_find_panel(const struct device_node *np); +int of_drm_get_panel_orientation(const struct device_node *np, + enum drm_panel_orientation *orientation); #else static inline struct drm_panel *of_drm_find_panel(const struct device_node *np) { return ERR_PTR(-ENODEV); } +static inline int of_drm_get_panel_orientation(const struct device_node *np, + enum drm_panel_orientation *orientation) +{ + return -ENODEV; +} #endif #if IS_ENABLED(CONFIG_DRM_PANEL) && (IS_BUILTIN(CONFIG_BACKLIGHT_CLASS_DEVICE) || \