public inbox for driver-core@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH RFT] driver core: faux: allow to set the firmware node for a faux device
@ 2026-03-06 13:45 Bartosz Golaszewski
  2026-03-06 13:54 ` Greg Kroah-Hartman
  0 siblings, 1 reply; 13+ messages in thread
From: Bartosz Golaszewski @ 2026-03-06 13:45 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rafael J. Wysocki, Danilo Krummrich,
	Shivendra Pratap
  Cc: linux-arm-msm, driver-core, linux-kernel, brgl,
	Bartosz Golaszewski

Add a new variant of faux_device_create() taking a firmware node handle
as argument and attaching it to the created faux device. This allows
users to define and read device properties using the standard property
accessors.

While at it: order includes in faux.c alphabetically for easier
maintenance.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Hi Shivendra et al!

This patch is related to my response to your reboot-mode patch[1].

You should be able to use the new function like:

  faux_device_create_full("psci-reboot-mode", NULL, NULL, NULL, of_fwnode_handle(np));

If it works for you and driver core maintainers accept it, please
integrate it into your series.

[1] https://lore.kernel.org/all/20260304-arm-psci-system_reset2-vendor-reboots-v20-6-cf7d346b8372@oss.qualcomm.com/
---
 drivers/base/faux.c         | 64 ++++++++++++++++++++++++++++++++++++++-------
 include/linux/device/faux.h |  5 ++++
 2 files changed, 60 insertions(+), 9 deletions(-)

diff --git a/drivers/base/faux.c b/drivers/base/faux.c
index fb3e42f213624ac8854764f58e81b9c2bc58cc86..27b3923b461df14bccc07eab701c6e8070de631a 100644
--- a/drivers/base/faux.c
+++ b/drivers/base/faux.c
@@ -10,12 +10,15 @@
  * intended to be very simple, with only a create and a destroy function
  * available.
  */
+
+#include <linux/container_of.h>
+#include <linux/device/faux.h>
 #include <linux/err.h>
+#include <linux/fwnode.h>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/string.h>
-#include <linux/container_of.h>
-#include <linux/device/faux.h>
+
 #include "base.h"
 
 /*
@@ -95,9 +98,10 @@ static void faux_device_release(struct device *dev)
 }
 
 /**
- * faux_device_create_with_groups - Create and register with the driver
- *		core a faux device and populate the device with an initial
- *		set of sysfs attributes.
+ * faux_device_create_full - Create and register with the driver
+ *		core a faux device described by the properties of the firmware
+ *		node and populate the device with an initial set of sysfs
+ *		attributes.
  * @name:	The name of the device we are adding, must be unique for
  *		all faux devices.
  * @parent:	Pointer to a potential parent struct device.  If set to
@@ -107,6 +111,7 @@ static void faux_device_release(struct device *dev)
  *		into, can be NULL.
  * @groups:	The set of sysfs attributes that will be created for this
  *		device when it is registered with the driver core.
+ * @fwnode:	Firmware node describing this device.
  *
  * Create a new faux device and register it in the driver core properly.
  * If present, callbacks in @faux_ops will be called with the device that
@@ -123,10 +128,11 @@ static void faux_device_release(struct device *dev)
  * * NULL if an error happened with creating the device
  * * pointer to a valid struct faux_device that is registered with sysfs
  */
-struct faux_device *faux_device_create_with_groups(const char *name,
-						   struct device *parent,
-						   const struct faux_device_ops *faux_ops,
-						   const struct attribute_group **groups)
+struct faux_device *faux_device_create_full(const char *name,
+					    struct device *parent,
+					    const struct faux_device_ops *faux_ops,
+					    const struct attribute_group **groups,
+					    struct fwnode_handle *fwnode)
 {
 	struct faux_object *faux_obj;
 	struct faux_device *faux_dev;
@@ -153,6 +159,8 @@ struct faux_device *faux_device_create_with_groups(const char *name,
 		dev->parent = faux_bus_root;
 	dev->bus = &faux_bus_type;
 	dev_set_name(dev, "%s", name);
+	if (fwnode)
+		device_set_node(dev, fwnode);
 	device_set_pm_not_required(dev);
 
 	ret = device_add(dev);
@@ -176,6 +184,44 @@ struct faux_device *faux_device_create_with_groups(const char *name,
 
 	return faux_dev;
 }
+EXPORT_SYMBOL_GPL(faux_device_create_full);
+
+/**
+ * faux_device_create_with_groups - Create and register with the driver
+ *		core a faux device and populate the device with an initial
+ *		set of sysfs attributes.
+ * @name:	The name of the device we are adding, must be unique for
+ *		all faux devices.
+ * @parent:	Pointer to a potential parent struct device.  If set to
+ *		NULL, the device will be created in the "root" of the faux
+ *		device tree in sysfs.
+ * @faux_ops:	struct faux_device_ops that the new device will call back
+ *		into, can be NULL.
+ * @groups:	The set of sysfs attributes that will be created for this
+ *		device when it is registered with the driver core.
+ *
+ * Create a new faux device and register it in the driver core properly.
+ * If present, callbacks in @faux_ops will be called with the device that
+ * for the caller to do something with at the proper time given the
+ * device's lifecycle.
+ *
+ * Note, when this function is called, the functions specified in struct
+ * faux_ops can be called before the function returns, so be prepared for
+ * everything to be properly initialized before that point in time.  If the
+ * probe callback (if one is present) does NOT succeed, the creation of the
+ * device will fail and NULL will be returned.
+ *
+ * Return:
+ * * NULL if an error happened with creating the device
+ * * pointer to a valid struct faux_device that is registered with sysfs
+ */
+struct faux_device *faux_device_create_with_groups(const char *name,
+						   struct device *parent,
+						   const struct faux_device_ops *faux_ops,
+						   const struct attribute_group **groups)
+{
+	return faux_device_create_full(name, parent, faux_ops, groups, NULL);
+}
 EXPORT_SYMBOL_GPL(faux_device_create_with_groups);
 
 /**
diff --git a/include/linux/device/faux.h b/include/linux/device/faux.h
index 9f43c0e46aa45bf492788adcdc081df5cc0c5fc0..ecad00221590e10e63d13698db9234b3c138a492 100644
--- a/include/linux/device/faux.h
+++ b/include/linux/device/faux.h
@@ -54,6 +54,11 @@ struct faux_device *faux_device_create_with_groups(const char *name,
 						   struct device *parent,
 						   const struct faux_device_ops *faux_ops,
 						   const struct attribute_group **groups);
+struct faux_device *faux_device_create_full(const char *name,
+					    struct device *parent,
+					    const struct faux_device_ops *faux_ops,
+					    const struct attribute_group **groups,
+					    struct fwnode_handle *fwnode);
 void faux_device_destroy(struct faux_device *faux_dev);
 
 static inline void *faux_device_get_drvdata(const struct faux_device *faux_dev)

---
base-commit: fc7b1a72c6cd5cbbd989c6c32a6486e3e4e3594d
change-id: 20260306-faux-dev-with-fwnode-5a66c1738158

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2026-03-12 15:25 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-06 13:45 [PATCH RFT] driver core: faux: allow to set the firmware node for a faux device Bartosz Golaszewski
2026-03-06 13:54 ` Greg Kroah-Hartman
2026-03-06 14:07   ` Bartosz Golaszewski
2026-03-06 14:13     ` Greg Kroah-Hartman
2026-03-06 14:24       ` Bartosz Golaszewski
2026-03-09 15:46         ` Shivendra Pratap
2026-03-09 15:55           ` Greg Kroah-Hartman
2026-03-10 12:29             ` Bartosz Golaszewski
2026-03-10 12:43               ` Greg Kroah-Hartman
2026-03-10 13:18                 ` Bartosz Golaszewski
2026-03-12 15:25                   ` Greg Kroah-Hartman
2026-03-10 13:16               ` Bartosz Golaszewski
2026-03-10 13:21                 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox