From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5D1DEC433E1 for ; Thu, 13 Aug 2020 21:56:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3288620838 for ; Thu, 13 Aug 2020 21:56:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="i2geYsx8" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726653AbgHMV4e (ORCPT ); Thu, 13 Aug 2020 17:56:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726205AbgHMV4c (ORCPT ); Thu, 13 Aug 2020 17:56:32 -0400 Received: from mail-lj1-x242.google.com (mail-lj1-x242.google.com [IPv6:2a00:1450:4864:20::242]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6923EC061757; Thu, 13 Aug 2020 14:56:32 -0700 (PDT) Received: by mail-lj1-x242.google.com with SMTP id g6so7813452ljn.11; Thu, 13 Aug 2020 14:56:32 -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=O7qBXRGOJkpPjsWWIvuCbGocx96q/WvFO969Ya+/TD4=; b=i2geYsx8r78/23QAK4haMQCO4P3mUskznKeR7l8N8Ha3L0hNlNLHQGiI8/E8TK2oaQ ocED2HdkzeCiQf9qFIh62YqLgnWdHkUL0ofHLTOJLF5ysacLvA8nls6FgTBaPq7JGpiy skIQTg4Is6FW8/mfZaG7ollg1ZrPEj0c9HjmaMPMIxTg1bp62J/O4pGnRs3qy6PpWig4 3WNXRnC02za6PrtLWCeiKOUKrqu3u1Bj7U4byOSijjgPZ9LrSB2pNMBwvo5iqEQn6B6p xZ32xFTM8tPsmkPoI16dzCWSWD7Z20Hl4r8yfwaW+tT28b8C25vvuh3TAD+ezEzjxRKv 5EBg== 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=O7qBXRGOJkpPjsWWIvuCbGocx96q/WvFO969Ya+/TD4=; b=bdbf3jgQu42i99Q0UJ39213XFOP08jefxakLTDGxTqs8RmTqUHbAOXS0vycC30cwqw Q8eq4kvD+fjTrXrW7k2hWfHetf59/aNszkcOdzKk6stn8Aj32Rqi+HZzTHXAE9vMbiAe sLr4CIBc1IeLXyFJ5+T+ZcZ/se8/Ip17kcLR43ERxZXkRUEy+E6+pKP2xI2t1hOOtyvl At5tHGuzKGx7uEKc5xBYfe0xqzeK2tOyI59rLuQKamrS53WhfX8gH9K0jXjFmQhO+zGz MOGTOvNTYlyamK69Y/Vmc9u0Etm3ie17TZFCKqIegoN6aeyccZsOkdkp/fBgavaDi4iL eZ5g== X-Gm-Message-State: AOAM530NCvkVcBJRD3HgtqZ+Dv7nZjT8TBqCSCf2wbyy/hX3WWmRh7ko TV16Yb244V8R9LZiTAUwHsA= X-Google-Smtp-Source: ABdhPJzI8Zb+3XIWnEMDQ/hzYFtXQxfOW8jntx5zXPHoaLem5kvIfWYygZGhvVKDuiPr/3qyzxHYDg== X-Received: by 2002:a2e:9810:: with SMTP id a16mr2666614ljj.157.1597355790900; Thu, 13 Aug 2020 14:56:30 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id z20sm1349977ljk.97.2020.08.13.14.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Aug 2020 14:56:30 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Thomas Zimmermann , Derek Basehore , Sam Ravnborg , Laurent Pinchart , Sean Paul , Daniel Vetter , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Emil Velikov , Daniel Stone Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH RESEND v12 1/4] drm/panel: Add helper for reading DT rotation Date: Fri, 14 Aug 2020 00:56:06 +0300 Message-Id: <20200813215609.28643-2-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200813215609.28643-1-digetx@gmail.com> References: <20200813215609.28643-1-digetx@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-tegra-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-tegra@vger.kernel.org From: Derek Basehore This adds a helper function for reading the rotation (panel orientation) from the device tree. Reviewed-by: Sam Ravnborg Tested-by: Dmitry Osipenko Signed-off-by: Derek Basehore Signed-off-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) || \ -- 2.27.0