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: 83378 Delivered-To: patch@linaro.org Received: by 10.182.1.168 with SMTP id 8csp2060095obn; Tue, 22 Nov 2016 02:42:39 -0800 (PST) X-Received: by 10.99.228.5 with SMTP id a5mr37992564pgi.1.1479811359476; Tue, 22 Nov 2016 02:42:39 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n127si27848246pga.323.2016.11.22.02.42.39; Tue, 22 Nov 2016 02:42:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@baylibre-com.20150623.gappssmtp.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932739AbcKVKma (ORCPT + 26 others); Tue, 22 Nov 2016 05:42:30 -0500 Received: from mail-wm0-f45.google.com ([74.125.82.45]:37432 "EHLO mail-wm0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755318AbcKVKmB (ORCPT ); Tue, 22 Nov 2016 05:42:01 -0500 Received: by mail-wm0-f45.google.com with SMTP id t79so17734978wmt.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=DOJlF92s5wrXzAtoqBZzYP+C3Z0iC4jF7ypH/hhk3hL8m8kG0uZ8aesPCn+sEXprWG nQNrkjuJo4wexha3SldCR5ggSkV04DLG4pFdYmw4c05mVcPcfJcrjZvyi1D57sJ3/R0W UVn4D/NXay6551QCLfFBmbXYXsNK16N0Ps69qWcwJiw0rH6kLKCeOTkL1B7MyvMX/FuQ g00ztWK1CALBCxkmaNrhgZPHLHQBb6a7XGOASAqkZZPOQ954jzocFC0Q7wLIkGAjSheO QrOVX/0lViyUj2tBBnWu5LdZGoiHyvTLZNDQexOzKsKvOpo5rRLl+wkbUrVQqgefWsmQ TSMg== X-Gm-Message-State: AKaTC02FvGUGNR4tjTTfdfgEY/Pqa0uijKNRmz8IV6lQ07OioreDzi7Qox5luCXIez9BXX9w 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 Cc: LKML , arm-soc , linux-drm , linux-devicetree , Jyri Sarha , Tomi Valkeinen , David Airlie , Laurent Pinchart , Robin Murphy , Sudeep Holla , Bartosz Golaszewski 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> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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(+) -- 2.9.3 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;