From: Li Jun <jun.li@nxp.com>
To: heikki.krogerus@linux.intel.com, robh+dt@kernel.org, rafael@kernel.org
Cc: gregkh@linuxfoundation.org, andriy.shevchenko@linux.intel.com,
hdegoede@redhat.com, lee.jones@linaro.org,
mika.westerberg@linux.intel.com, dmitry.torokhov@gmail.com,
prabhakar.mahadev-lad.rj@bp.renesas.com,
laurent.pinchart+renesas@ideasonboard.com,
linux-usb@vger.kernel.org, devicetree@vger.kernel.org,
linux-imx@nxp.com, peter.chen@nxp.com
Subject: [PATCH v5 2/4] device property: Add fwnode_is_compatible() and device_is_compatible() helpers
Date: Tue, 3 Nov 2020 19:40:08 +0800 [thread overview]
Message-ID: <1604403610-16577-2-git-send-email-jun.li@nxp.com> (raw)
In-Reply-To: <1604403610-16577-1-git-send-email-jun.li@nxp.com>
From: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Since there are also some ACPI platforms where the
"compatible" property is used, introducing a generic helper
function fwnode_is_compatible() that can be used with
DT, ACPI and swnodes, and a wrapper function
device_is_compatible() with it.
The function calls of_device_is_comaptible() with OF nodes,
and with ACPI and swnodes it matches the given string
against the "compatible" string property array.
Signed-off-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Li Jun <jun.li@nxp.com>
---
change for v5
- A minor change to move the function return valure description
to a new paragraph.
New patch for v4.
drivers/base/property.c | 39 +++++++++++++++++++++++++++++++++++++++
include/linux/property.h | 2 ++
2 files changed, 41 insertions(+)
diff --git a/drivers/base/property.c b/drivers/base/property.c
index d58aa98..d1c1f30 100644
--- a/drivers/base/property.c
+++ b/drivers/base/property.c
@@ -1184,3 +1184,42 @@ const void *device_get_match_data(struct device *dev)
return fwnode_call_ptr_op(dev_fwnode(dev), device_get_match_data, dev);
}
EXPORT_SYMBOL_GPL(device_get_match_data);
+
+/**
+ * fwnode_is_compatible - Check does fwnode have the given compatible string
+ * @fwnode: fwnode with the "compatible" property
+ * @compat: The compatible string
+ *
+ * Match the compatible strings of @fwnode against @compat.
+ *
+ * Returns positive value on match, and 0 when no matching compatible
+ * string is found.
+ */
+int fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compat)
+{
+ int ret;
+
+ if (is_of_node(fwnode))
+ return of_device_is_compatible(to_of_node(fwnode), compat);
+
+ ret = fwnode_property_match_string(fwnode, "compatible", compat);
+
+ return ret < 0 ? 0 : 1;
+}
+EXPORT_SYMBOL_GPL(fwnode_is_compatible);
+
+/**
+ * device_is_compatible - Check does a device have the given compatible string
+ * @dev: Device with the "compatible" property
+ * @compat: The compatible string
+ *
+ * Match the compatible strings of @dev against @compat.
+ *
+ * Returns positive value on match, and 0 when no matching compatible
+ * string is found.
+ */
+int device_is_compatible(struct device *dev, const char *compat)
+{
+ return fwnode_is_compatible(dev_fwnode(dev), compat);
+}
+EXPORT_SYMBOL_GPL(device_is_compatible);
diff --git a/include/linux/property.h b/include/linux/property.h
index 9f805c4..42c1d99 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -48,6 +48,7 @@ int device_property_read_string(struct device *dev, const char *propname,
const char **val);
int device_property_match_string(struct device *dev,
const char *propname, const char *string);
+int device_is_compatible(struct device *dev, const char *compat);
bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
bool fwnode_property_present(const struct fwnode_handle *fwnode,
@@ -117,6 +118,7 @@ struct fwnode_handle *fwnode_handle_get(struct fwnode_handle *fwnode);
void fwnode_handle_put(struct fwnode_handle *fwnode);
int fwnode_irq_get(struct fwnode_handle *fwnode, unsigned int index);
+int fwnode_is_compatible(struct fwnode_handle *fwnode, const char *compat);
unsigned int device_get_child_node_count(struct device *dev);
--
2.7.4
next prev parent reply other threads:[~2020-11-03 11:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-03 11:40 [PATCH v5 1/4] dt-bindings: usb: add documentation for typec switch simple driver Li Jun
2020-11-03 11:40 ` Li Jun [this message]
2020-11-03 11:40 ` [PATCH v5 3/4] usb: typec: mux: add "compatible" property for switch match Li Jun
2020-11-10 10:51 ` Heikki Krogerus
2020-11-03 11:40 ` [PATCH v5 4/4] usb: typec: mux: add typec switch simple driver Li Jun
2020-11-09 8:36 ` Heikki Krogerus
2020-11-24 1:56 ` Jun Li
2020-11-05 22:25 ` [PATCH v5 1/4] dt-bindings: usb: add documentation for " Rob Herring
2020-11-06 11:07 ` Jun Li
2020-11-06 14:24 ` Rob Herring
2020-11-09 12:24 ` Jun Li
2020-11-09 14:37 ` Rob Herring
2020-11-11 15:40 ` Jun Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1604403610-16577-2-git-send-email-jun.li@nxp.com \
--to=jun.li@nxp.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=hdegoede@redhat.com \
--cc=heikki.krogerus@linux.intel.com \
--cc=laurent.pinchart+renesas@ideasonboard.com \
--cc=lee.jones@linaro.org \
--cc=linux-imx@nxp.com \
--cc=linux-usb@vger.kernel.org \
--cc=mika.westerberg@linux.intel.com \
--cc=peter.chen@nxp.com \
--cc=prabhakar.mahadev-lad.rj@bp.renesas.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).