gpio-sim: configfs-based GPIO simulator
Subsystems (4)
v11 cover gpio-sim: configfs-based GPIO simulator
Here's the eleventh revision of the simulator.
As there was no reasoning with configfs maintainers for many months, this time the whole concept of committable items has been dropped. Instead, each configfs chip item (or rather a group - more on that later) exposes a new attribute called 'live'. Writing 1 to it brings the chip on-line (registers the platform device) and writing 0 tears it down.
There are some caveats to that approach - for example: we can't block the user-space from deleting chip items when chips are live but is just handled by silently destroying the chip device in the background.
In v11 the configfs structure has been deepened to allow creating multiple banks per platform device. The sysfs interface has changed so that the gpio_simX attributes are now under the bank's device node and not the platform device's.
v1 -> v2:
- add selftests for gpio-sim
- add helper programs for selftests
- update the configfs rename callback to work with the new API introduced in v5.11
- fix a missing quote in the documentation
- use !! whenever using bits operation that are required to return 0 or 1
- use provided bitmap API instead of reimplementing copy or fill operations
- fix a deadlock in gpio_sim_direction_output()
- add new read-only configfs attributes for mapping of configfs items to GPIO device names
- and address other minor issues pointed out in reviews of v1
v2 -> v3:
- use devm_bitmap_alloc() instead of the zalloc variant if we're initializing the bitmap with 1s
- drop the patch exporting device_is_bound()
- don't return -ENODEV from dev_nam and chip_name configfs attributes, return a string indicating that the device is not available yet ('n/a')
- fix indentation where it makes sense
- don't protect IDA functions which use their own locking and where it's not needed
- use kmemdup() instead of kzalloc() + memcpy()
- collected review tags
- minor coding style fixes
v3 -> v4:
- return 'none' instead of 'n/a' from dev_name and chip_name before the device is registered
- use sysfs_emit() instead of s*printf()
- drop GPIO_SIM_MAX_PROP as it's only used in an array's definition where it's fine to hardcode the value
v4 -> v5:
- drop lib patches that are already upstream
- use BIT() instead of (1UL << bit) for flags
- fix refcounting for the configfs_dirent in rename()
- drop d_move() from the rename() callback
- free memory allocated for the live and pending groups in configfs_d_iput() and not in detach_groups()
- make sure that if a group of some name is in the live directory, a new group with the same name cannot be created in the pending directory
v5 -> v6:
- go back to using (1UL << bit) instead of BIT()
- if the live group dentry doesn't exist for whatever reason at the time when mkdir() in the pending group is called (would be a BUG()), return -ENOENT instead of -EEXIST which should only be returned if given subsystem already exists in either live or pending group
v6 -> v7:
- as detailed by Andy in commit 6fda593f3082 ("gpio: mockup: Convert to use software nodes") removing device properties after the platform device is removed but before the GPIO device gets dropped can lead to a use-after-free bug - use software nodes to manually control the freeing of the properties
v7 -> v8:
- fixed some minor coding style issues as pointed out by Andy
v8 -> v9:
- dropped the patches implementing committable-items and reworked the driver to not use them
- reworked the gpio-line-names property and configuring specific lines in general
- many smaller tweaks here and there
v9 -> v10:
- make writing to 'live' wait for the probe to finish and report an error to user-space if it failed
- add the ability to hog lines from the kernel-space
- rework locking (drop separate locks for line context objects)
- rework the sysfs interface (create a separate group for each line with a constant number of attributes instead of going the other way around)
v10 -> v11:
- rework the configfs structure to represent a deeper hierarchy that gpiolib supports, namely: multiple banks per platform device
Bartosz Golaszewski (6):
gpiolib: provide gpiod_remove_hogs()
gpiolib: allow to specify the firmware node in struct gpio_chip
gpio: sim: new testing module
selftests: gpio: provide a helper for reading chip info
selftests: gpio: add a helper for reading GPIO line names
selftests: gpio: add test cases for gpio-sim
Documentation/admin-guide/gpio/gpio-sim.rst | 93 + drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1592 +++++++++++++++++ drivers/gpio/gpiolib.c | 26 +- include/linux/gpio/driver.h | 2 + include/linux/gpio/machine.h | 2 + tools/testing/selftests/gpio/.gitignore | 2 + tools/testing/selftests/gpio/Makefile | 4 +- tools/testing/selftests/gpio/config | 1 + tools/testing/selftests/gpio/gpio-chip-info.c | 57 + tools/testing/selftests/gpio/gpio-line-name.c | 55 + tools/testing/selftests/gpio/gpio-sim.sh | 396 ++++ 13 files changed, 2236 insertions(+), 3 deletions(-) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.c create mode 100644 tools/testing/selftests/gpio/gpio-chip-info.c create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c create mode 100755 tools/testing/selftests/gpio/gpio-sim.sh
Signature · 1 line
2.25.1
PATCH v11 1/6 gpiolib: provide gpiod_remove_hogs()
Currently all users of gpiod_add_hogs() call it only once at system init so there never was any need for a mechanism allowing to remove them. Now the upcoming gpio-sim will need to tear down chips with hogged lines so provide a function that allows to remove hogs.
--- drivers/gpio/gpiolib.c | 11 +++++++++++ include/linux/gpio/machine.h | 2 ++ 2 files changed, 13 insertions(+)
drivers/gpio/gpiolib.c +11 -0
@@ -3540,6 +3540,17 @@ void gpiod_add_hogs(struct gpiod_hog *hogs) }EXPORT_SYMBOL_GPL (gpiod_add_hogs); +void gpiod_remove_hogs (struct gpiod_hog *hogs) +{ +struct gpiod_hog *hog; + +mutex_lock (&gpio_machine_hogs_mutex); +for (hog = &hogs[0 ]; hog->chip_label; hog++) +list_del (&hog->list); +mutex_unlock (&gpio_machine_hogs_mutex); +} +EXPORT_SYMBOL_GPL (gpiod_remove_hogs); +static struct gpiod_lookup_table *gpiod_find_lookup_table (struct device *dev) {const char *dev_id = dev ?dev_name (dev) :NULL ;
include/linux/gpio/machine.h +2 -0
@@ -100,6 +100,7 @@ void gpiod_add_lookup_table(struct gpiod_lookup_table *table);void gpiod_add_lookup_tables (struct gpiod_lookup_table **tables,size_t n);void gpiod_remove_lookup_table (struct gpiod_lookup_table *table);void gpiod_add_hogs (struct gpiod_hog *hogs); +void gpiod_remove_hogs (struct gpiod_hog *hogs);#else /* ! CONFIG_GPIOLIB */ static inline void gpiod_add_lookup_table (struct gpiod_lookup_table *table) {}
@@ -108,6 +109,7 @@ void gpiod_add_lookup_tables(struct gpiod_lookup_table **tables, size_t n) {}static inline void gpiod_remove_lookup_table (struct gpiod_lookup_table *table) {}static inline void gpiod_add_hogs (struct gpiod_hog *hogs) {} +static inline void gpiod_remove_hogs (struct gpiod_hog *hogs) {}#endif /* CONFIG_GPIOLIB */ #endif /* __LINUX_GPIO_MACHINE_H */
Signature · 1 line
2.25.1
PATCH v11 2/6 gpiolib: allow to specify the firmware node in struct gpio_chip
In reply to Bartosz GolaszewskiSoftware nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib core however doesn't offer any way of passing this information from the drivers.
This extends struct gpio_chip with a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.
This is similar to how we handle device-tree sub-nodes with CONFIG_OF_GPIO enabled.
--- drivers/gpio/gpiolib.c | 15 ++++++++++++++- include/linux/gpio/driver.h | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +14 -1
@@ -593,13 +593,26 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,struct lock_class_key *lock_key, struct lock_class_key *request_key) { - struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; + struct fwnode_handle *fwnode = NULL;unsigned long flags;int ret =0 ;unsigned i;int base = gc->base;struct gpio_device *gdev; +#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ + +if (gc->fwnode) + fwnode = gc->fwnode; +else if (gc->parent) + fwnode =dev_fwnode (gc->parent); +/* * First: allocate and populate the internal stat container, and * set up the struct device.
include/linux/gpio/driver.h +2 -0
@@ -289,6 +289,7 @@ struct gpio_irq_chip {* number or the name of the SoC IP-block implementing it. * @gpiodev: the internal state holder, opaque struct * @parent: optional parent device providing the GPIOs +* @fwnode: optional fwnode providing this controller's properties * @owner: helps prevent removal of modules exporting active GPIOs * @request: optional hook for chip-specific activation, such as * enabling module power and clock; may sleep
@@ -377,6 +378,7 @@ struct gpio_chip {const char *label;struct gpio_device *gpiodev;struct device *parent; +struct fwnode_handle *fwnode;struct module *owner; int (*request)(struct gpio_chip *gc,
Signature · 1 line
2.25.1
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib core
core .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.
Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */
I don't like this. It seems like a hack right now.
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the of_node assignment).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 1 line · Andy Shevchenko
On Tue, Nov 30, 2021 at 04:41:23PM +0100, Bartosz Golaszewski wrote:
...
Quoted 5 lines
Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
Have you seen these:
drivers/gpio/gpio-dwapb.c
drivers/mfd/intel_quark_i2c_gpio.c
?
GPIO driver has a main (controller level) node along with children on per bank basis. Currently it works with the provided approach (see second driver).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 11 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko
On Tue, Nov 30, 2021 at 04:41:23PM +0100, Bartosz Golaszewski wrote:
...
Quoted 5 lines
Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
Quoted 7 lines
Have you seen these:
drivers/gpio/gpio-dwapb.c
drivers/mfd/intel_quark_i2c_gpio.c
?GPIO driver has a main (controller level) node along with children on per bank basis. Currently it works with the provided approach (see second driver).
Btw, may be helpful to debug swnodes application
https://lore.kernel.org/lkml/[email protected]/#t
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
In reply to Andy ShevchenkoQuoted 17 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko
On Tue, Nov 30, 2021 at 04:41:23PM +0100, Bartosz Golaszewski wrote:
...
Quoted 5 lines
Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
Have you seen these:
drivers/gpio/gpio-dwapb.c
drivers/mfd/intel_quark_i2c_gpio.c
?
Quoted 8 lines
GPIO driver has a main (controller level) node along with children on per bank basis. Currently it works with the provided approach (see second driver).
--
With Best Regards,
Andy Shevchenko
Yep, I know dwapd. What happens in probe is that each bank device is created using the properties from the associated child fwnode but the parent device's fwnode is actually assigned as the gpiochip's fwnode. This is logically wrong and OF doesn't do it - it assigns the child of_node to the child device if gpio_chip->of_node is assigned in the driver. I'm not sure if ACPI does this.
Non-OF drivers don't have a way to do this and this patch enables it.
I want to add it mostly because gpio-sim can then use the software node to identify the device in the configfs by that software node but IMO this is logically correct too.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 19 lines · Bartosz Golaszewski
Quoted 17 lines · Andy Shevchenko
Quoted 1 line · Andy Shevchenko
On Tue, Nov 30, 2021 at 04:41:23PM +0100, Bartosz Golaszewski wrote:
...
Quoted 5 lines
Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
Have you seen these:
drivers/gpio/gpio-dwapb.c
drivers/mfd/intel_quark_i2c_gpio.c
?
Quoted 6 lines
Quoted 2 lines
GPIO driver has a main (controller level) node along with children on per bank basis. Currently it works with the provided approach (see second driver).
Yep, I know dwapd. What happens in probe is that each bank device is created using the properties from the associated child fwnode but the parent device's fwnode is actually assigned as the gpiochip's fwnode.
The first device is the physical device of the GPIO controller, the
,-> fwnode of the physical device
|
GPIO -> portA -> gpiodev A (child fwnode A)
`-> portB -> gpiodev B (child fwnode B)
...Quoted 1 line
This is logically wrong
I don't see how, it represents hardware as is.
Quoted 3 lines
and OF doesn't do it - it assigns the child
of_nodeto the child device ifgpio_chip->of_nodeis assigned in the driver.
And this is exactly what happens.
Quoted 1 line
I'm not sure if ACPI does this.
Depending on the device description. In the case of dwapb on Galileo platform the ACPI just misses that, that's why board files (see second driver).
Quoted 1 line
Non-OF drivers don't have a way to do this and this patch enables it.
You meant non-FW drivers, right? How come? What am I missing?
I don't see the issue here. When user wants to have GPIO device, first we instantiate it with its own fwnode (in your case swnode), followed by additional (child) swnode per bank.
Quoted 3 lines
I want to add it mostly because gpio-sim can then use the software node to identify the device in the configfs by that software node but IMO this is logically correct too.
I also think so.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
In reply to Andy ShevchenkoQuoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ I don't like this. It seems like a hack right now.
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).
Yes, it's definitely a good idea but I would be careful with just dropping the of_node assignments as callbacks may depend on them later. Also it's not just about the gpio_chip of_node assignment - drivers also use a bunch of OF APIs all around the place. I would prefer that it be done one by one and every modified driver be tested.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 37 lines · Bartosz Golaszewski
Quoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ I don't like this. It seems like a hack right now.
Quoted 8 lines
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).Yes, it's definitely a good idea but I would be careful with just dropping the
of_nodeassignments as callbacks may depend on them later.
GPIO library does it for us among these lines:
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; of_gpio_dev_init(gc, gdev); <<< HERE! acpi_gpio_dev_init(gc, gdev); /* * Assign fwnode depending on the result of the previous calls, * if none of them succeed, assign it to the parent's one. */ gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;
Quoted 3 lines
Also it's not just about the
gpio_chipof_nodeassignment - drivers also use a bunch of OF APIs all around the place. I would prefer that it be done one by one and every modified driver be tested.
That's why we want to eliminate dev->fwnode explicit dereference as a first step (see dev_fwnode() / device_set_node() APIs).
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ I don't like this. It seems like a hack right now.
Quoted 8 lines
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).Yes, it's definitely a good idea but I would be careful with just dropping the
of_nodeassignments as callbacks may depend on them later.GPIO library does it for us among these lines:
Quoted 11 lines
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL;
of_gpio_dev_init(gc, gdev); <<< HERE!
acpi_gpio_dev_init(gc, gdev);
/*
* Assign fwnode depending on the result of the previous calls,
* if none of them succeed, assign it to the parent's one.
*/
gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;Except that it doesn't and I noticed that when working on the subsequent patch. The child gpiochipX devices all had the parent's fwnode assigned as their primary fwnode and no secondary fwnode.
Note that this driver doesn't use neither OF nor ACPI in which case gdev->dev has no fwnode and the parent's one is used. This patch addresses it. If you have a better idea, let me know.
Bart
Quoted 13 lines
Quoted 4 lines
Also it's not just about the
gpio_chipof_nodeassignment - drivers also use a bunch of OF APIs all around the place. I would prefer that it be done one by one and every modified driver be tested.That's why we want to eliminate
dev->fwnodeexplicit dereference as a first step (seedev_fwnode()/device_set_node()APIs).--
With Best Regards,
Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 69 lines · Bartosz Golaszewski
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ I don't like this. It seems like a hack right now.
Quoted 8 lines
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).Yes, it's definitely a good idea but I would be careful with just dropping the
of_nodeassignments as callbacks may depend on them later.GPIO library does it for us among these lines:
Quoted 11 lines
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; of_gpio_dev_init(gc, gdev); <<< HERE! acpi_gpio_dev_init(gc, gdev); /* * Assign fwnode depending on the result of the previous calls, * if none of them succeed, assign it to the parent's one. */ gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;Except that it doesn't and I noticed that when working on the subsequent patch. The child gpiochipX devices all had the parent's fwnode assigned as their primary fwnode and no secondary fwnode.
Quoted 5 lines
Note that this driver doesn't use neither OF nor ACPI in which case
gdev->devhas no fwnode and the parent's one is used. This patch addresses it. If you have a better idea, let me know.Bart
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the gc->of_node = some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.
Linus: Do you have anything against this change?
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 84 lines · Bartosz Golaszewski
Quoted 69 lines · Bartosz Golaszewski
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
drivers/gpio/gpiolib.c int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, · line 609
Quoted 7 lines
drivers/gpio/gpiolib.c +7
-0+#if IS_ENABLED (CONFIG_OF_GPIO ) +if (gc->of_node && gc->fwnode) { +pr_err ("%s: tried to set both the of_node and fwnode in gpio_chip\n" , + __func__); +return -EINVAL ; + } +#endif /* CONFIG_OF_GPIO */ I don't like this. It seems like a hack right now.
Quoted 8 lines
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).Yes, it's definitely a good idea but I would be careful with just dropping the
of_nodeassignments as callbacks may depend on them later.GPIO library does it for us among these lines:
Quoted 11 lines
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; of_gpio_dev_init(gc, gdev); <<< HERE! acpi_gpio_dev_init(gc, gdev); /* * Assign fwnode depending on the result of the previous calls, * if none of them succeed, assign it to the parent's one. */ gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;Except that it doesn't and I noticed that when working on the subsequent patch. The child gpiochipX devices all had the parent's fwnode assigned as their primary fwnode and no secondary fwnode.
Quoted 5 lines
Note that this driver doesn't use neither OF nor ACPI in which case
gdev->devhas no fwnode and the parent's one is used. This patch addresses it. If you have a better idea, let me know.Bart
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.
I still don't see how you set up hierarchy of primary/secondary fwnodes.
And I don't like this change. It seems it band-aids some issue with fwnode usage. What the easiest way to reproduce the issue with your series applied (without this change)?
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 92 lines · Andy Shevchenko
Quoted 84 lines · Bartosz Golaszewski
Quoted 69 lines · Bartosz Golaszewski
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 35 lines · Andy Shevchenko
Quoted 3 lines · Bartosz Golaszewski
Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance:
banks of GPIOs under a common GPIO expander. The core gpiolib corecore .. core ?!
Quoted 8 lines
however doesn't offer any way of passing this information from the drivers.
This extends struct
gpio_chipwith a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes.This is similar to how we handle device-tree sub-nodes with
CONFIG_OF_GPIOenabled.Not sure I understand the proposal. Can you provide couple of (simplest) examples?
And also it sounds like reinventing a wheel. What problem do you have that you need to solve this way?
...
Review
Quoted 7 lines
(quoted diff) +7
-0+#if IS_ENABLED(CONFIG_OF_GPIO) + if (gc->of_node && gc->fwnode) { + pr_err("%s: tried to set both the of_node and fwnode in gpio_chip\n", + __func__); + return -EINVAL; + } +#endif /* CONFIG_OF_GPIO */I don't like this. It seems like a hack right now.
Quoted 8 lines
Quoted 4 lines
Is it possible to convert all GPIO controller drivers to provide an fwnode rather than doing this? (I believe in most of the drivers we can drop completely the
of_nodeassignment).Yes, it's definitely a good idea but I would be careful with just dropping the
of_nodeassignments as callbacks may depend on them later.GPIO library does it for us among these lines:
Quoted 11 lines
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; of_gpio_dev_init(gc, gdev); <<< HERE! acpi_gpio_dev_init(gc, gdev); /* * Assign fwnode depending on the result of the previous calls, * if none of them succeed, assign it to the parent's one. */ gdev->dev.fwnode = dev_fwnode(&gdev->dev) ?: fwnode;Except that it doesn't and I noticed that when working on the subsequent patch. The child gpiochipX devices all had the parent's fwnode assigned as their primary fwnode and no secondary fwnode.
Quoted 5 lines
Note that this driver doesn't use neither OF nor ACPI in which case
gdev->devhas no fwnode and the parent's one is used. This patch addresses it. If you have a better idea, let me know.Bart
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.
Quoted 6 lines
I still don't see how you set up hierarchy of primary/secondary fwnodes.
And I don't like this change. It seems it band-aids some issue with fwnode usage. What the easiest way to reproduce the issue with your series applied (without this change)?
Drop this patch and drop the line where the fwnode is assigned in gpio-sim.c. Then probe the device and print the addresses of the parent and child swnodes. See how they are the same and don't match the swnode hierarchy we created. You can then apply this patch and see how it becomes correct.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 4 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 20 lines
Quoted 14 lines
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 5 lines
I still don't see how you set up hierarchy of primary/secondary fwnodes.
And I don't like this change. It seems it band-aids some issue with fwnode usage. What the easiest way to reproduce the issue with your series applied (without this change)?
Quoted 5 lines
Drop this patch and drop the line where the fwnode is assigned in
gpio-sim.c. Then probe the device and print the addresses of the parent and child swnodes. See how they are the same and don't match the swnode hierarchy we created. You can then apply this patch and see how it becomes correct.
Thanks. I will give a spin.
Note, it seems I have to revert your older code first...
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 34 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 20 lines
Quoted 14 lines
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 5 lines
I still don't see how you set up hierarchy of primary/secondary fwnodes.
And I don't like this change. It seems it band-aids some issue with fwnode usage. What the easiest way to reproduce the issue with your series applied (without this change)?
Quoted 5 lines
Drop this patch and drop the line where the fwnode is assigned in
gpio-sim.c. Then probe the device and print the addresses of the parent and child swnodes. See how they are the same and don't match the swnode hierarchy we created. You can then apply this patch and see how it becomes correct.
Quoted 3 lines
Thanks. I will give a spin.
Note, it seems I have to revert your older code first...
Okay, I have to postpone because simple revert doesn't work for me. Can you clean up the next, please and I can use it starting from tomorrow?
$ git tag --contains 5065e08e4ef3 DONT-USE-next-20211105 next-20211101 next-20211102 next-20211103 next-20211104 next-20211105 next-20211106 next-20211108 next-20211109 next-20211110 next-20211111 next-20211112 next-20211115 next-20211116 next-20211117 next-20211118 next-20211123 next-20211124 next-20211125 next-20211126 next-20211129 next-20211130 next-20211201
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 69 lines · Andy Shevchenko
Quoted 34 lines · Andy Shevchenko
Quoted 4 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 20 lines
Quoted 14 lines
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 5 lines
I still don't see how you set up hierarchy of primary/secondary fwnodes.
And I don't like this change. It seems it band-aids some issue with fwnode usage. What the easiest way to reproduce the issue with your series applied (without this change)?
Quoted 5 lines
Drop this patch and drop the line where the fwnode is assigned in
gpio-sim.c. Then probe the device and print the addresses of the parent and child swnodes. See how they are the same and don't match the swnode hierarchy we created. You can then apply this patch and see how it becomes correct.Quoted 3 lines
Thanks. I will give a spin.
Note, it seems I have to revert your older code first...
Okay, I have to postpone because simple revert doesn't work for me. Can you clean up the next, please and I can use it starting from tomorrow?
$ git tag --contains 5065e08e4ef3 DONT-USE-next-20211105 next-20211101 next-20211102 next-20211103 next-20211104 next-20211105 next-20211106 next-20211108 next-20211109 next-20211110 next-20211111 next-20211112 next-20211115 next-20211116 next-20211117 next-20211118 next-20211123 next-20211124 next-20211125 next-20211126 next-20211129 next-20211130 next-20211201
Quoted 5 lines
--
With Best Regards,
Andy Shevchenko
None of this is in next, please use:
https://github.com/brgl/linux/tree/topic/gpio-sim-v12 if you want a branch.
I just thought you were going to simply apply these patches.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 48 lines · Bartosz Golaszewski
Quoted 37 lines · Andy Shevchenko
Quoted 12 lines · Andy Shevchenko
Quoted 10 lines · Bartosz Golaszewski
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
Drop this patch and drop the line where the fwnode is assigned in
gpio-sim.c. Then probe the device and print the addresses of the parent and child swnodes. See how they are the same and don't match the swnode hierarchy we created. You can then apply this patch and see how it becomes correct.Quoted 3 lines
Thanks. I will give a spin.
Note, it seems I have to revert your older code first...
Okay, I have to postpone because simple revert doesn't work for me. Can you clean up the next, please and I can use it starting from tomorrow?
$ git tag --contains 5065e08e4ef3 DONT-USE-next-20211105 next-20211101 next-20211102 next-20211103 next-20211104 next-20211105 next-20211106 next-20211108 next-20211109 next-20211110 next-20211111 next-20211112 next-20211115 next-20211116 next-20211117Quoted 8 lines
next-20211118 next-20211123 next-20211124 next-20211125 next-20211126 next-20211129 next-20211130 next-20211201
Quoted 3 lines
None of this is in next, please use:
https://github.com/brgl/linux/tree/topic/gpio-sim-v12 if you want a branch.
It the old version that prevents me to apply (my branches based on next).
Quoted 1 line
I just thought you were going to simply apply these patches.
That's correct, but see above.
Anyway, I'm already switched tasks for today. Maybe I will have some time later on.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
In reply to Bartosz GolaszewskiQuoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace of_node by fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.
Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.
But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing of_nodes with fwnodes in drivers and eventually we'd drop the of_node pointer from gpio_chip entirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at gpiolib-acpi.c I don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.
As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with gpio_chips to identify the gpiodevs from configfs callbacks.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 37 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.
Quoted 8 lines
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.
Then we need to replace of_node by fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 43 lines · Andy Shevchenko
Quoted 42 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.
Quoted 7 lines
Quoted 3 lines
As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.
Let me kick this off by sending couple of patches.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 53 lines · Andy Shevchenko
Quoted 43 lines · Andy Shevchenko
Quoted 42 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.Quoted 7 lines
Quoted 3 lines
As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.
Quoted 7 lines
Let me kick this off by sending couple of patches.
--
With Best Regards,
Andy Shevchenko
Are you fine with merging this in the meantime to get gpio-sim into mainline?
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 51 lines · Bartosz Golaszewski
Quoted 49 lines · Andy Shevchenko
Quoted 47 lines · Andy Shevchenko
Quoted 45 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.Let me kick this off by sending couple of patches.
Are you fine with merging this in the meantime to get gpio-sim into mainline?
gpio-sim, yes, (though I may bikeshed about naming of the configfs attributes, etc) but not this patch.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 57 lines · Andy Shevchenko
Quoted 55 lines · Bartosz Golaszewski
Quoted 53 lines · Andy Shevchenko
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Quoted 8 lines
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Let me kick this off by sending couple of patches.
Are you fine with merging this in the meantime to get gpio-sim into mainline?
gpio-sim, yes, (though I may bikeshed about naming of the configfs attributes, etc) but not this patch.
There's no way around it though AFAIK. First - the 'gpio-line-names' property will not work for banks. 'ngpios' will only work because we read it manually in probe() to figure out the number of sysfs groups. And also configfs callbacks will not be able to associate bank devices with configfs groups. I would really like to hear an alternative - even if it's just an idea and not actual implementation.
I'm really curious to see how you'll remove the of_node pointer and not introduce the corresponding fwnode pointer actually.
Bart
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 74 lines · Bartosz Golaszewski
Quoted 57 lines · Andy Shevchenko
Quoted 55 lines · Bartosz Golaszewski
Quoted 53 lines · Andy Shevchenko
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Quoted 8 lines
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Let me kick this off by sending couple of patches.
Are you fine with merging this in the meantime to get gpio-sim into mainline?
gpio-sim, yes, (though I may bikeshed about naming of the configfs attributes, etc) but not this patch.
There's no way around it though AFAIK. First - the 'gpio-line-names' property will not work for banks. 'ngpios' will only work because we read it manually in
probe()to figure out the number of sysfs groups. And also configfs callbacks will not be able to associate bank devices with configfs groups. I would really like to hear an alternative - even if it's just an idea and not actual implementation.
Quoted 2 lines
I'm really curious to see how you'll remove the
of_nodepointer and not introduce the corresponding fwnode pointer actually.
Seems I was unclear, fwnode pointer will be needed, but what I'm against of is having of_node and fwnode at the same time in the struct gpio_chip.
Yes, we may modify this patch to work without that ugly ifdeffery and with both in the structure, but I don't think it's a good solution.
Now clearly we have to clean up of_node first.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 76 lines · Andy Shevchenko
Quoted 74 lines · Bartosz Golaszewski
Quoted 57 lines · Andy Shevchenko
Quoted 55 lines · Bartosz Golaszewski
Quoted 53 lines · Andy Shevchenko
Quoted 50 lines · Andy Shevchenko
Quoted 37 lines · Bartosz Golaszewski
Quoted 20 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Quoted 8 lines
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Let me kick this off by sending couple of patches.
Are you fine with merging this in the meantime to get gpio-sim into mainline?
gpio-sim, yes, (though I may bikeshed about naming of the configfs attributes, etc) but not this patch.
There's no way around it though AFAIK. First - the 'gpio-line-names' property will not work for banks. 'ngpios' will only work because we read it manually in
probe()to figure out the number of sysfs groups. And also configfs callbacks will not be able to associate bank devices with configfs groups. I would really like to hear an alternative - even if it's just an idea and not actual implementation.
Quoted 9 lines
Quoted 2 lines
I'm really curious to see how you'll remove the
of_nodepointer and not introduce the corresponding fwnode pointer actually.Seems I was unclear, fwnode pointer will be needed, but what I'm against of is having
of_nodeand fwnode at the same time in the structgpio_chip.Yes, we may modify this patch to work without that ugly ifdeffery and with both in the structure, but I don't think it's a good solution.
It may not be the best solution but we can't simply convert all the drivers to fwnode and pray they work. I would like every converted driver to be well tested because there can be some issues lurking in the fwnode <-> of_node conversion. That will take time.
Meanwhile, this would block gpio-sim for months again. I don't believe this patch is wrong as it fixes a real issue and as you said: fwnode will most likely stay in gpio_chip.
IMO we should introduce fwnode, convert gpiolib and drivers to using it gradually, remove of_node once there are no more users.
Bart
Quoted 2 lines
Now clearly we have to clean up
of_nodefirst.
Re: [PATCH v11 2/6] gpiolib: allow to specify the firmware node in struct gpio_chip
Quoted 84 lines · Bartosz Golaszewski
Quoted 72 lines · Andy Shevchenko
Quoted 71 lines · Bartosz Golaszewski
Quoted 54 lines · Andy Shevchenko
Quoted 53 lines · Bartosz Golaszewski
Quoted 51 lines · Andy Shevchenko
Quoted 49 lines · Andy Shevchenko
Quoted 36 lines · Bartosz Golaszewski
Quoted 19 lines · Andy Shevchenko
Quoted 1 line · Bartosz Golaszewski
On Tue, Nov 30, 2021 at 10:04 PM Bartosz Golaszewski <[email protected]> wrote:
...
Quoted 8 lines
Let me maybe rephrase the problem: currently, for GPIO devices instantiating multiple banks created outside of the OF or ACPI frameworks (e.g. instantiated manually and configured using a hierarchy of software nodes with a single parent swnode and a number of child swnodes representing the children), it is impossible to assign firmware nodes other than the one representing the top GPIO device to the gpiochip child devices.
Quoted 5 lines
In fact if we want to drop the OF APIs entirely from gpiolib - this would be the right first step as for gpio-sim it actually replaces the
gc->of_node=some_of_node; assignment that OF-based drivers do for sub-nodes defining banks and it does work with device-tree (I verified that too) thanks to the fwnode abstraction layer.Quoted 6 lines
In exchange of acknowledgements I confirm that I understood the issue you are describing. What I still don't like is this band-aid:ish approach. What we really need is to replace
of_nodeby fwnode in GPIO library once for all. But it can be done later after your simulation series (or before, i.o.w. independently), hence I propose to update TODO and do it separately.But this is what we already do for OF. How would the core gpiolib know how the firmware nodes represent the banks? It's the driver's job to tell the framework which node corresponds with what. If anything, we should start replacing
of_nodeswith fwnodes in drivers and eventually we'd drop theof_nodepointer fromgpio_chipentirely, but we'd keep the fwnode pointer I added as the driver still needs to assign it itself.Quoted 8 lines
Again: I may be missing something here but I've been going through this on and on and can't figure out any other way. Looking at
gpiolib-acpi.cI don't see it correctly assigning fwnodes to sub-devices either but I don't have any HW to test it.As for this series: I can't really drop this patch as gpio-sim relies on swnodes being correctly associated with
gpio_chipsto identify the gpiodevs from configfs callbacks.Then we need to replace
of_nodeby fwnode as a first step. I have looked briefly into the list of drivers that may have been cleaned up and it doesn't look too long.Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Let me kick this off by sending couple of patches.
Are you fine with merging this in the meantime to get gpio-sim into mainline?
gpio-sim, yes, (though I may bikeshed about naming of the configfs attributes, etc) but not this patch.
There's no way around it though AFAIK. First - the 'gpio-line-names' property will not work for banks. 'ngpios' will only work because we read it manually in
probe()to figure out the number of sysfs groups. And also configfs callbacks will not be able to associate bank devices with configfs groups. I would really like to hear an alternative - even if it's just an idea and not actual implementation.Quoted 9 lines
Quoted 2 lines
I'm really curious to see how you'll remove the
of_nodepointer and not introduce the corresponding fwnode pointer actually.Seems I was unclear, fwnode pointer will be needed, but what I'm against of is having
of_nodeand fwnode at the same time in the structgpio_chip.Yes, we may modify this patch to work without that ugly ifdeffery and with both in the structure, but I don't think it's a good solution.
Quoted 8 lines
It may not be the best solution but we can't simply convert all the drivers to fwnode and pray they work. I would like every converted driver to be well tested because there can be some issues lurking in the fwnode <->
of_nodeconversion. That will take time.Meanwhile, this would block gpio-sim for months again. I don't believe this patch is wrong as it fixes a real issue and as you said: fwnode will most likely stay in gpio_chip.o
It doesn't strictly speaking "fix". But it allows to get things right.
Quoted 2 lines
IMO we should introduce fwnode, convert gpiolib and drivers to using it gradually, remove
of_nodeonce there are no more users.
I may accept the change after some amendments done:
- get rid of ifdeffery (remove that block completely)
- add TODO entry
- add "deprecated" keyword to of_node
- ...I hope I haven't miss anything else...
Quoted 1 line
Quoted 1 line
Now clearly we have to clean up
of_nodefirst.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v11 3/6 gpio: sim: new testing module
In reply to Bartosz GolaszewskiImplement a new, modern GPIO testing module controlled by configfs attributes instead of module parameters. The goal of this driver is to provide a replacement for gpio-mockup that will be easily extensible with new features and doesn't require reloading the module to change the setup.
--- Documentation/admin-guide/gpio/gpio-sim.rst | 93 ++ drivers/gpio/Kconfig | 8 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-sim.c | 1592 +++++++++++++++++++ 4 files changed, 1694 insertions(+) create mode 100644 Documentation/admin-guide/gpio/gpio-sim.rst create mode 100644 drivers/gpio/gpio-sim.c
Documentation/admin-guide/gpio/gpio-sim.rst new file +93 -0
@@ -0,0 +1,93 @@ +.. SPDX-License-Identifier: GPL-2.0-or-later + +Configfs GPIO Simulator +======================= + +The configfs GPIO Simulator (gpio-sim) provides a way to create simulated GPIO +chips for testing purposes. The lines exposed by these chips can be accessed +using the standard GPIO character device interface as well as manipulated +using sysfs attributes. + +Creating simulated chips +------------------------ + +The gpio-sim module registers a configfs subsystem called 'gpio-sim'. For +details of the configfs filesystem, please refer to the configfs documentaion. + +The user can create a hierarchy of configfs groups and items as well as modify +values of exposed attributes. Once the chip is instantiated, this hierarchy +will be translated to appropriate device properties. The general structure is: + +Group: /config/gpio-sim + +This is the top directory of the gpio-sim configfs tree. + +Group: /config/gpio-sim/gpio-device +Attribute: /config/gpio-sim/gpio-device/dev_name +Attribute: /config/gpio-sim/gpio-device/live + +This is a directory representing a GPIO platform device. The 'dev_name' +attribute is read-only and allows the user-space to read the platform device +name (e.g. 'gpio-sim.0'). The 'live' attribute allows to trigger the actual +creation of the device once it's fully configured. The accepted values are: +'1' to enable the simulated device and '0' to disable and tear it down. + +Group: /config/gpio-sim/gpio-device/gpio-bankX/ +Attribute: /config/gpio-sim/gpio-device/gpio-bankX/chip_name +Attribute: /config/gpio-sim/gpio-device/gpio-bankX/num_lines + +This group represents a bank of GPIOs under the top platform device. The +'chip_name' attribute is read-only and allows the user-space to read the +device name of the bank device. The 'num_lines' attribute allows to specify +the number of lines exposed by this bank. + +Group: /config/gpio-sim/gpio-device/gpio-bankX/lineY +Attribute: /config/gpio-sim/gpio-device/gpio-bankX/lineY/name + +This group represents a single line at the offset Y. The 'name' attribute +allows to set the line name as represented by the 'gpio-line-names' property. + +Item: /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog +Attribute: /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/name +Attribute: /config/gpio-sim/gpio-device/gpio-bankX/lineY/hog/direction + +This item makes the gpio-sim module hog the associated line. The 'name' +attribute specifies the in-kernel consumer name to use. The 'direction' +attribute specifies the hog direction and must be one of: 'input', +'output-high' and 'output-low'. + +Inside each bank directory, there's a set of attributes that can be used to +configure the new chip. Additionally the user can mkdir() subdirectories inside +the chip's directory that allow to pass additional configuration for specific +lines. The name of those subdirectories must take the form of: 'line<offset>' +(e.g. 'line0', 'line20', etc.) as the name will be used by the module to assign +the config to the specific line at given offset. + +Once the confiuration is complete, the 'live' attribute must be set to 1 in +order to instantiate the chip. It can be set back to 0 to destroy the simulated +chip. The module will synchronously wait for the new simulated device to be +successfully probed and if this doesn't happen, writing to 'live' will result +in an error. + +Simulated GPIO chips can also be defined in device-tree. The compatible string +must be: "gpio-simulator". Supported properties are: + + "gpio-sim,label" - chip label + +Other standard GPIO properties (like "gpio-line-names", "ngpios" or gpio-hog) +are also supported. + +Manipulating simulated lines +---------------------------- + +Each simulated GPIO chip creates a separate sysfs group under its device +directory for each exposed line +(e.g. /sys/devices/platform/gpio-sim.X/gpiochipY/). The name of each group +is of the form: 'sim_gpioX' where X is the offset of the line. Inside each +group there are two attibutes: + + pull - allows to read and set the current simulated pull setting for every + line, when writing the value must be one of: 'pull-up', 'pull-down' + + value - allows to read the current value of the line which may be different + from the pull if the line is being driven from user-space
drivers/gpio/Kconfig +8 -0
@@ -1694,6 +1694,14 @@ config GPIO_VIRTIO These virtual GPIOs can be routed to real GPIOs or attached to simulators on the host (like QEMU). +config GPIO_SIM + tristate "GPIO Simulator Module" + select IRQ_SIM + select CONFIGFS_FS + help + This enables the GPIO simulator - a configfs-based GPIO testing + driver. + endmenu endif
drivers/gpio/Makefile +1 -0
@@ -133,6 +133,7 @@ obj-$(CONFIG_GPIO_SAMA5D2_PIOBU) += gpio-sama5d2-piobu.o obj-$(CONFIG_GPIO_SCH311X) += gpio-sch311x.o obj-$(CONFIG_GPIO_SCH) += gpio-sch.o obj-$(CONFIG_GPIO_SIFIVE) += gpio-sifive.o +obj-$(CONFIG_GPIO_SIM) += gpio-sim.o obj-$(CONFIG_GPIO_SIOX) += gpio-siox.o obj-$(CONFIG_GPIO_SL28CPLD) += gpio-sl28cpld.o obj-$(CONFIG_GPIO_SODAVILLE) += gpio-sodaville.o
drivers/gpio/gpio-sim.c new file +1592 -0
1,592 lines not on this page · raw message
Signature · 1 line
2.25.1
kernel test robot
build botRe: [PATCH v11 3/6] gpio: sim: new testing module
I love your patch! Perhaps something to improve:
Hi Bartosz,
I love your patch! Perhaps something to improve:
[auto build test WARNING on v5.16-rc3]
[cannot apply to shuah-kselftest/next linusw-gpio/for-next next-20211130] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]
url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211130-234338 base: d58071a8a76d779eedab38033ae4c821c30295a5 config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20211201/202112011018.3gANFz4h-lkp(a)intel.com/config) compiler: sh4-linux-gcc (GCC) 11.2.0
reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1e50c35dae10799b1e2bbed56f68cfbac59bea08
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211130-234338 git checkout 1e50c35dae10799b1e2bbed56f68cfbac59bea08
# save the config file to linux build tree
mkdir build_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bash drivers/ security//
If you fix the issue, kindly add following tag as appropriate
All warnings (new ones prefixed by >>):
>> drivers/gpio/gpio-sim.c:807:23: warning: no previous prototype for 'gpio_sim_make_bank_swnode' [-Wmissing-prototypes]
807 | struct fwnode_handle *gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
vim +/gpio_sim_make_bank_swnode +807 drivers/gpio/gpio-sim.c
806
> 807 struct fwnode_handle *gpio_sim_make_bank_swnode(struct gpio_sim_bank *bank,
808 struct fwnode_handle *parent)
809 {
810 struct property_entry properties[GPIO_SIM_PROP_MAX];
811 unsigned int prop_idx = 0, line_names_size = 0;
812 struct fwnode_handle *swnode;
813 char **line_names;
814
815 memset(properties, 0, sizeof(properties));
816
817 properties[prop_idx++] = PROPERTY_ENTRY_U32("ngpios", bank->num_lines);
818
819 if (bank->label)
820 properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label",
821 bank->label);
822
823 line_names = gpio_sim_make_line_names(bank, &line_names_size);
824 if (IS_ERR(line_names))
825 return ERR_CAST(line_names);
826
827 if (line_names)
828 properties[prop_idx++] = PROPERTY_ENTRY_STRING_ARRAY_LEN(
829 "gpio-line-names",
830 line_names, line_names_size);
831
832 swnode = fwnode_create_software_node(properties, parent);
833 kfree(line_names);
834 return swnode;
835 }
836
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
Re: [PATCH v11 3/6] gpio: sim: new testing module
Quoted 36 lines · kernel test robot
Hi Bartosz,
I love your patch! Perhaps something to improve:
[auto build test WARNING on v5.16-rc3]
[cannot apply to shuah-kselftest/next linusw-gpio/for-next next-20211130] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch]url: https://github.com/0day-ci/linux/commits/Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211130-234338 base: d58071a8a76d779eedab38033ae4c821c30295a5 config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20211201/202112011018.3gANFz4h-lkp(a)intel.com/config) compiler: sh4-linux-gcc (GCC) 11.2.0reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/0day-ci/linux/commit/1e50c35dae10799b1e2bbed56f68cfbac59bea08
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Bartosz-Golaszewski/gpio-sim-configfs-based-GPIO-simulator/20211130-234338 git checkout1e50c35dae10799b1e2bbed56f68cfbac59bea08
# save the config file to linux build tree
mkdirbuild_dir
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.2.0 make.cross O=build_dir ARCH=sh SHELL=/bin/bashdrivers/security//If you fix the issue, kindly add following tag as appropriate
Reported-by kernel test robot <[email protected]>All warnings (new ones prefixed by >>):
Quoted 1 line
Quoted 1 line
drivers/gpio/gpio-sim.c:807:23: warning: no previous prototype for 'gpio_sim_make_bank_swnode' [-Wmissing-prototypes]807 | struct
fwnode_handle*gpio_sim_make_bank_swnode(structgpio_sim_bank*bank,
| ^~~~~~~~~~~~~~~~~~~~~~~~~
Quoted 6 lines
vim +/gpio_sim_make_bank_swnode +807
drivers/gpio/gpio-sim.c806Quoted 1 line
807 struct
fwnode_handle*gpio_sim_make_bank_swnode(structgpio_sim_bank*bank,808 struct
fwnode_handle*parent)
809 {
Will statify it in v12.
Bart
Quoted 31 lines
810 struct property_entry properties[GPIO_SIM_PROP_MAX]; 811 unsigned int prop_idx = 0, line_names_size = 0; 812 struct fwnode_handle *swnode; 813 char **line_names; 814 815 memset(properties, 0, sizeof(properties)); 816 817 properties[prop_idx++] = PROPERTY_ENTRY_U32("ngpios", bank->num_lines); 818 819 if (bank->label) 820 properties[prop_idx++] = PROPERTY_ENTRY_STRING("gpio-sim,label", 821 bank->label); 822 823 line_names = gpio_sim_make_line_names(bank, &line_names_size); 824 if (IS_ERR(line_names)) 825 return ERR_CAST(line_names); 826 827 if (line_names) 828 properties[prop_idx++] = PROPERTY_ENTRY_STRING_ARRAY_LEN( 829 "gpio-line-names", 830 line_names, line_names_size); 831 832 swnode = fwnode_create_software_node(properties, parent); 833 kfree(line_names); 834 return swnode; 835 } 836---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
PATCH v11 4/6 selftests: gpio: provide a helper for reading chip info
In reply to Bartosz GolaszewskiAdd a simple program that allows to retrieve chip properties from the GPIO character device. This will be used in gpio-sim selftests.
--- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-chip-info.c | 57 +++++++++++++++++++ 3 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-chip-info.c
tools/testing/selftests/gpio/.gitignore +1 -0
@@ -1,2 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev +gpio-chip-info
tools/testing/selftests/gpio/Makefile +1 -1
@@ -2,7 +2,7 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info CFLAGS += -O2 -g -Wall -I../../../../usr/include/ include ../lib.mk
tools/testing/selftests/gpio/gpio-chip-info.c new file +57 -0
57 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v11 5/6 selftests: gpio: add a helper for reading GPIO line names
In reply to Bartosz GolaszewskiAdd a simple program that allows to read GPIO line names from the character device. This will be used in gpio-sim selftests.
--- tools/testing/selftests/gpio/.gitignore | 1 + tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/gpio-line-name.c | 55 +++++++++++++++++++ 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/gpio/gpio-line-name.c
tools/testing/selftests/gpio/.gitignore +1 -0
@@ -1,3 +1,4 @@ # SPDX-License-Identifier: GPL-2.0-only gpio-mockup-cdev gpio-chip-info +gpio-line-name
tools/testing/selftests/gpio/Makefile +1 -1
@@ -2,7 +2,7 @@ TEST_PROGS := gpio-mockup.sh TEST_FILES := gpio-mockup-sysfs.sh -TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info +TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -O2 -g -Wall -I../../../../usr/include/ include ../lib.mk
tools/testing/selftests/gpio/gpio-line-name.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v11 6/6 selftests: gpio: add test cases for gpio-sim
In reply to Bartosz GolaszewskiAdd a set of tests for the new gpio-sim module. This is a pure shell test-suite and uses the helper programs available in the gpio selftests directory. These test-cases only test the functionalities exposed by the gpio-sim driver, not those handled by core gpiolib code.
--- tools/testing/selftests/gpio/Makefile | 2 +- tools/testing/selftests/gpio/config | 1 + tools/testing/selftests/gpio/gpio-sim.sh | 396 +++++++++++++++++++++++ 3 files changed, 398 insertions(+), 1 deletion(-) create mode 100755 tools/testing/selftests/gpio/gpio-sim.sh
tools/testing/selftests/gpio/Makefile +1 -1
@@ -1,6 +1,6 @@ # SPDX-License-Identifier: GPL-2.0 -TEST_PROGS := gpio-mockup.sh +TEST_PROGS := gpio-mockup.sh gpio-sim.sh TEST_FILES := gpio-mockup-sysfs.sh TEST_GEN_PROGS_EXTENDED := gpio-mockup-cdev gpio-chip-info gpio-line-name CFLAGS += -O2 -g -Wall -I../../../../usr/include/
tools/testing/selftests/gpio/config +1 -0
@@ -1,3 +1,4 @@ CONFIG_GPIOLIB=y CONFIG_GPIO_CDEV=y CONFIG_GPIO_MOCKUP=m +CONFIG_GPIO_SIM=m
tools/testing/selftests/gpio/gpio-sim.sh new file +396 -0
396 lines not on this page · raw message
Signature · 1 line
2.25.1