From patchwork Tue Nov 22 10:41:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 9440791 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EA051600BA for ; Tue, 22 Nov 2016 10:44:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD5C1284CB for ; Tue, 22 Nov 2016 10:44:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C208E284D8; Tue, 22 Nov 2016 10:44:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 67B9B284CB for ; Tue, 22 Nov 2016 10:44:12 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1c98XE-0001fl-Ks; Tue, 22 Nov 2016 10:42:44 +0000 Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1c98Wp-0001FQ-CU for linux-arm-kernel@lists.infradead.org; Tue, 22 Nov 2016 10:42:20 +0000 Received: by mail-wm0-x236.google.com with SMTP id a197so17874203wmd.0 for ; Tue, 22 Nov 2016 02:41:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wZvjTy5CqD1+avP+y8uphKpTPmSfKih2rcPlbE6NUcA=; b=EPdbS+sCb5JStPZSEMcz/Ben7csw3QIY/+SnXz9lzUzKQWNrhrmbNGZeASRqNJ3EaD PpwLw3tmc7lcRUj2EnC4imuepDhF8bWwtAGvyE7CrOcIl+S9aPCXzpE4euVkZbaxxTP4 pGKFcfCewHRn+zDN/4u69zb2i7umNNcNF3g+9nyyxJXZ2lURMWL0kbHpiWsbP7vm0Iyf lcCFpqU3kbiTxvKl4VJ2ZL/y5JGzrwt/Fv8/0kajGLswcuKu1NiXT5VBpG35nCbzq0Q8 PzjIgrAgqwInuZW6eNdAqa0EsxxkzecL7wEkGv4Xrr/s/vGrqCv2sC+H0dw+RjXjxAeU fIAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wZvjTy5CqD1+avP+y8uphKpTPmSfKih2rcPlbE6NUcA=; b=WsQYXVFL+iV5JV3vzsgBlCvXNt9FK9ikFPSprLtRSTF33uDqO8me+3r0Pjy+73A+Ms +6ZpIwv9QO9nl/DsDf5/h3LIt4wZ6+JmtSH6rUnNEjdfsQxwRYZa/W3rZQiI4QTTh27o i3Wtya6JneO3qTbnO7nkbSleKo5BO29psvCK8EOxsfL3AdWzOj1E8kCjqkXmB2NVou6D LCi3E+77zQ7OImX3hYREGCKkVl9rb8x/pPWb/femDP6OweQeTF00WSNn7CII5MtvFfk5 l90nYtrbMRQNfHW/+Nbr8rZtwuQifr/cR74AIgPSqm2Mz5LN7WrhLRPMKkE8ntq8v85b GWGw== X-Gm-Message-State: AKaTC027bCVzwQCaZo8vWJW4bS+q5JVeX4gXSHBzc2H1IZluZjH3ap9N5OUSxjtDe+oCDcqv X-Received: by 10.28.69.217 with SMTP id l86mr1611473wmi.129.1479811317299; Tue, 22 Nov 2016 02:41:57 -0800 (PST) Received: from localhost.localdomain ([90.63.244.31]) by smtp.gmail.com with ESMTPSA id u81sm2228926wmu.10.2016.11.22.02.41.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Nov 2016 02:41:56 -0800 (PST) From: Bartosz Golaszewski To: Kevin Hilman , Michael Turquette , Sekhar Nori , Rob Herring , Frank Rowand , Mark Rutland , Peter Ujfalusi , Russell King Subject: [PATCH 1/3] of: base: add support to get machine compatible string Date: Tue, 22 Nov 2016 11:41:49 +0100 Message-Id: <1479811311-3080-2-git-send-email-bgolaszewski@baylibre.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1479811311-3080-1-git-send-email-bgolaszewski@baylibre.com> References: <1479811311-3080-1-git-send-email-bgolaszewski@baylibre.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161122_024219_690936_145ADD92 X-CRM114-Status: GOOD ( 13.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-devicetree , David Airlie , LKML , linux-drm , Bartosz Golaszewski , Tomi Valkeinen , Jyri Sarha , Sudeep Holla , Robin Murphy , arm-soc , Laurent Pinchart MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a function allowing to retrieve the compatible string of the root node of the device tree. Signed-off-by: Bartosz Golaszewski --- drivers/of/base.c | 22 ++++++++++++++++++++++ include/linux/of.h | 6 ++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/of/base.c b/drivers/of/base.c index a0bccb5..bbfe5e9 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -546,6 +546,28 @@ int of_machine_is_compatible(const char *compat) EXPORT_SYMBOL(of_machine_is_compatible); /** + * of_machine_get_compatible - Get the compatible property of the root node + * + * Returns a NULL-terminated string containing the compatible if it could + * be found, NULL otherwise. + */ +const char *of_machine_get_compatible(void) +{ + struct device_node *root; + const char *compatible; + int ret = -1; + + root = of_find_node_by_path("/"); + if (root) { + ret = of_property_read_string(root, "compatible", &compatible); + of_node_put(root); + } + + return ret ? NULL : compatible; +} +EXPORT_SYMBOL(of_machine_get_compatible); + +/** * __of_device_is_available - check if a device is available for use * * @device: Node to check for availability, with locks already held diff --git a/include/linux/of.h b/include/linux/of.h index 299aeb1..664b734 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -367,6 +367,7 @@ extern int of_alias_get_id(struct device_node *np, const char *stem); extern int of_alias_get_highest_id(const char *stem); extern int of_machine_is_compatible(const char *compat); +extern const char *of_machine_get_compatible(void); extern int of_add_property(struct device_node *np, struct property *prop); extern int of_remove_property(struct device_node *np, struct property *prop); @@ -788,6 +789,11 @@ static inline int of_machine_is_compatible(const char *compat) return 0; } +static inline const char *of_machine_get_compatible(void) +{ + return NULL; +} + static inline bool of_console_check(const struct device_node *dn, const char *name, int index) { return false;