Re: [PATCH v6 02/15] gpio: regmap: set gpio_chip of_node

From: Michael Walle
Date: Wed Mar 10 2021 - 13:28:51 EST


Am 2021-03-10 13:54, schrieb Álvaro Fernández Rojas:
This is needed for properly registering GPIO regmap as a child of a regmap
pin controller.

Signed-off-by: Álvaro Fernández Rojas <noltari@xxxxxxxxx>
Reviewed-by: Michael Walle <michael@xxxxxxxx>
---
v6: add comment and simplify of_node assignment

Ah, I see you add the comment for the documentation. Nice. But I'd
like to see it in the code, too. See below.

v5: switch to fwnode
v4: fix documentation
v3: introduce patch needed for properly parsing gpio-range

drivers/gpio/gpio-regmap.c | 1 +
include/linux/gpio/regmap.h | 4 ++++
2 files changed, 5 insertions(+)

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index 5412cb3b0b2a..d4fc656e70b0 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -249,6 +249,7 @@ struct gpio_regmap *gpio_regmap_register(const
struct gpio_regmap_config *config

chip = &gpio->gpio_chip;
chip->parent = config->parent;

If there will be a new version, please add the following comment:

/* gpiolib will use of_node of the parent if chip->of_node is NULL */

+ chip->of_node = to_of_node(config->fwnode);

Otherwise, it is not obvious that config->fwnode is optional.

-michael

+ chip->of_node = to_of_node(config->fwnode);
chip->base = -1;
chip->ngpio = config->ngpio;
chip->names = config->names;
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index ad76f3d0a6ba..334dd928042b 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -4,6 +4,7 @@
#define _LINUX_GPIO_REGMAP_H

struct device;
+struct fwnode_handle;
struct gpio_regmap;
struct irq_domain;
struct regmap;
@@ -16,6 +17,8 @@ struct regmap;
* @parent: The parent device
* @regmap: The regmap used to access the registers
* given, the name of the device is used
+ * @fwnode: (Optional) The firmware node.
+ * If not given, the fwnode of the parent is used.
* @label: (Optional) Descriptive name for GPIO controller.
* If not given, the name of the device is used.
* @ngpio: Number of GPIOs
@@ -57,6 +60,7 @@ struct regmap;
struct gpio_regmap_config {
struct device *parent;
struct regmap *regmap;
+ struct fwnode_handle *fwnode;

const char *label;
int ngpio;