Skip to content

Commit 990f675

Browse files
committed
gpiolib: allow to specify the firmware node in struct gpio_chip
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 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. Signed-off-by: Bartosz Golaszewski <[email protected]> Reviewed-by: Andy Shevchenko <[email protected]> Acked-by: Linus Walleij <[email protected]>
1 parent dd61b29 commit 990f675

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

drivers/gpio/gpiolib.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,14 +593,19 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
593593
struct lock_class_key *lock_key,
594594
struct lock_class_key *request_key)
595595
{
596-
struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL;
596+
struct fwnode_handle *fwnode = NULL;
597597
struct gpio_device *gdev;
598598
unsigned long flags;
599599
int base = gc->base;
600600
unsigned int i;
601601
int ret = 0;
602602
u32 ngpios;
603603

604+
if (gc->fwnode)
605+
fwnode = gc->fwnode;
606+
else if (gc->parent)
607+
fwnode = dev_fwnode(gc->parent);
608+
604609
/*
605610
* First: allocate and populate the internal stat container, and
606611
* set up the struct device.

include/linux/gpio/driver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ struct gpio_irq_chip {
289289
* number or the name of the SoC IP-block implementing it.
290290
* @gpiodev: the internal state holder, opaque struct
291291
* @parent: optional parent device providing the GPIOs
292+
* @fwnode: optional fwnode providing this controller's properties
292293
* @owner: helps prevent removal of modules exporting active GPIOs
293294
* @request: optional hook for chip-specific activation, such as
294295
* enabling module power and clock; may sleep
@@ -377,6 +378,7 @@ struct gpio_chip {
377378
const char *label;
378379
struct gpio_device *gpiodev;
379380
struct device *parent;
381+
struct fwnode_handle *fwnode;
380382
struct module *owner;
381383

382384
int (*request)(struct gpio_chip *gc,

0 commit comments

Comments
 (0)