From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-acpi@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
Bartosz Golaszewski <brgl@bgdev.pl>,
Andy Shevchenko <andy@kernel.org>,
Daniel Scally <djrscally@gmail.com>,
Heikki Krogerus <heikki.krogerus@linux.intel.com>,
Sakari Ailus <sakari.ailus@linux.intel.com>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Rob Herring <robh+dt@kernel.org>
Subject: [PATCH v1 1/3] device property: Implement device_is_big_endian()
Date: Wed, 25 Oct 2023 21:42:57 +0300 [thread overview]
Message-ID: <20231025184259.250588-2-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20231025184259.250588-1-andriy.shevchenko@linux.intel.com>
Some users want to use the struct device pointer to see if the
device is big endian in terms of Open Firmware specifications,
i.e. if it has a "big-endian" property, or if the kernel was
compiled for BE *and* the device has a "native-endian" property.
Provide inline helper for the users.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
include/linux/property.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/linux/property.h b/include/linux/property.h
index 2b8f07fc68a9..d1400a477b0a 100644
--- a/include/linux/property.h
+++ b/include/linux/property.h
@@ -80,12 +80,38 @@ int fwnode_property_match_string(const struct fwnode_handle *fwnode,
bool fwnode_device_is_available(const struct fwnode_handle *fwnode);
+static inline bool fwnode_device_is_big_endian(const struct fwnode_handle *fwnode)
+{
+ if (fwnode_property_present(fwnode, "big-endian"))
+ return true;
+ if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) &&
+ fwnode_property_present(fwnode, "native-endian"))
+ return true;
+ return false;
+}
+
static inline
bool fwnode_device_is_compatible(const struct fwnode_handle *fwnode, const char *compat)
{
return fwnode_property_match_string(fwnode, "compatible", compat) >= 0;
}
+/**
+ * device_is_big_endian - check if a device has BE registers
+ * @dev: Pointer to the struct device
+ *
+ * Returns: true if the device has a "big-endian" property, or if the kernel
+ * was compiled for BE *and* the device has a "native-endian" property.
+ * Returns false otherwise.
+ *
+ * Callers would nominally use ioread32be/iowrite32be if
+ * device_is_big_endian() == true, or readl/writel otherwise.
+ */
+static inline bool device_is_big_endian(const struct device *dev)
+{
+ return fwnode_device_is_big_endian(dev_fwnode(dev));
+}
+
/**
* device_is_compatible - match 'compatible' property of the device with a given string
* @dev: Pointer to the struct device
--
2.40.0.1.gaa8946217a0b
next prev parent reply other threads:[~2023-10-25 18:43 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-25 18:42 [PATCH v1 0/3] gpio: mmio: Make driver agnostic Andy Shevchenko
2023-10-25 18:42 ` Andy Shevchenko [this message]
2023-10-26 5:25 ` [PATCH v1 1/3] device property: Implement device_is_big_endian() Greg Kroah-Hartman
2023-10-26 12:27 ` Andy Shevchenko
2023-11-02 15:33 ` Andy Shevchenko
2023-11-02 15:58 ` Greg Kroah-Hartman
2023-11-02 16:47 ` Andy Shevchenko
2023-11-03 9:08 ` Bartosz Golaszewski
2023-11-15 14:58 ` Bartosz Golaszewski
2023-11-15 20:21 ` Greg Kroah-Hartman
2023-12-07 14:19 ` Andy Shevchenko
2023-12-15 14:49 ` Greg Kroah-Hartman
2023-12-15 15:08 ` Andy Shevchenko
2023-12-18 10:35 ` Bartosz Golaszewski
2023-12-18 10:55 ` Andy Shevchenko
2023-12-18 11:05 ` Bartosz Golaszewski
2023-12-18 11:18 ` Greg Kroah-Hartman
2023-12-18 12:38 ` Bartosz Golaszewski
2023-12-18 13:40 ` Andy Shevchenko
2023-12-18 11:08 ` Greg Kroah-Hartman
2023-10-25 18:42 ` [PATCH v1 2/3] gpio: mmio: Make use of device properties Andy Shevchenko
2023-10-25 18:42 ` [PATCH v1 3/3] gpio: mmio: Clean up headers Andy Shevchenko
2023-10-25 19:55 ` [PATCH v1 0/3] gpio: mmio: Make driver agnostic Linus Walleij
2023-12-18 12:43 ` Bartosz Golaszewski
[not found] ` <ZYBKn9UZIhY03DiV@smile.fi.intel.com>
2023-12-18 13:36 ` Andy Shevchenko
2023-12-18 13:37 ` Bartosz Golaszewski
2023-12-18 15:02 ` Andy Shevchenko
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=20231025184259.250588-2-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=andy@kernel.org \
--cc=brgl@bgdev.pl \
--cc=djrscally@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=heikki.krogerus@linux.intel.com \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=sakari.ailus@linux.intel.com \
/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).