diff mbox series

[2/3] gpio: gpio-regmap: Expose struct gpio_regmap in linux/gpio/regmap.h

Message ID 5c0354c87d4d2a082cf0c331076d5aad18a93169.1677547393.git.william.gray@linaro.org
State New
Headers show
Series Migrate PCIe-IDIO-24 GPIO driver to the regmap API | expand

Commit Message

William Breathitt Gray Feb. 28, 2023, 1:53 a.m. UTC
A struct gpio_regmap is passed as a parameter for reg_mask_xlate(), but
for callbacks to access its members the declaration must be exposed.
Move the struct gpio_regmap declaration from drivers/gpio/gpio-regmap.c
to include/linux/gpio/regmap.h so callbacks can properly interact with
struct gpio_regmap members.

Signed-off-by: William Breathitt Gray <william.gray@linaro.org>
---
 drivers/gpio/gpio-regmap.c  | 20 --------------------
 include/linux/gpio/regmap.h | 23 ++++++++++++++++++++++-
 2 files changed, 22 insertions(+), 21 deletions(-)

Comments

William Breathitt Gray Feb. 28, 2023, 3:12 a.m. UTC | #1
On Tue, Feb 28, 2023 at 09:44:02PM +0100, Michael Walle wrote:
> Hi,
> 
> Am 2023-02-28 02:53, schrieb William Breathitt Gray:
> > A struct gpio_regmap is passed as a parameter for reg_mask_xlate(), but
> > for callbacks to access its members the declaration must be exposed.
> 
> That parameter is only an opaque one to call any gpio_regmap_*().
> 
> > Move the struct gpio_regmap declaration from drivers/gpio/gpio-regmap.c
> > to include/linux/gpio/regmap.h so callbacks can properly interact with
> > struct gpio_regmap members.
> 
> That struct should be kept private. It seems you only need the
> regmap. Either introduce a gpio_regmap_get_regmap() or add the
> regmap to a private struct and use gpio_regmap_get_drvdata().
> 
> -michael

Ah, I'll drop this patch then and use gpio_regmap_get_drvdata() in v2
instead to get access to the regmap.

William Breathitt Gray
Michael Walle Feb. 28, 2023, 8:44 p.m. UTC | #2
Hi,

Am 2023-02-28 02:53, schrieb William Breathitt Gray:
> A struct gpio_regmap is passed as a parameter for reg_mask_xlate(), but
> for callbacks to access its members the declaration must be exposed.

That parameter is only an opaque one to call any gpio_regmap_*().

> Move the struct gpio_regmap declaration from drivers/gpio/gpio-regmap.c
> to include/linux/gpio/regmap.h so callbacks can properly interact with
> struct gpio_regmap members.

That struct should be kept private. It seems you only need the
regmap. Either introduce a gpio_regmap_get_regmap() or add the
regmap to a private struct and use gpio_regmap_get_drvdata().

-michael
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
index fca17d478984..ad34750779c7 100644
--- a/drivers/gpio/gpio-regmap.c
+++ b/drivers/gpio/gpio-regmap.c
@@ -11,26 +11,6 @@ 
 #include <linux/module.h>
 #include <linux/regmap.h>
 
-struct gpio_regmap {
-	struct device *parent;
-	struct regmap *regmap;
-	struct gpio_chip gpio_chip;
-
-	int reg_stride;
-	int ngpio_per_reg;
-	unsigned int reg_dat_base;
-	unsigned int reg_set_base;
-	unsigned int reg_clr_base;
-	unsigned int reg_dir_in_base;
-	unsigned int reg_dir_out_base;
-
-	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
-			      unsigned int offset, unsigned int *reg,
-			      unsigned int *mask);
-
-	void *driver_data;
-};
-
 static unsigned int gpio_regmap_addr(unsigned int addr)
 {
 	if (addr == GPIO_REGMAP_ADDR_ZERO)
diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h
index a9f7b7faf57b..1132c0f7e907 100644
--- a/include/linux/gpio/regmap.h
+++ b/include/linux/gpio/regmap.h
@@ -3,15 +3,36 @@ 
 #ifndef _LINUX_GPIO_REGMAP_H
 #define _LINUX_GPIO_REGMAP_H
 
+#include <linux/gpio/driver.h>
+
 struct device;
 struct fwnode_handle;
-struct gpio_regmap;
 struct irq_domain;
 struct regmap;
 
 #define GPIO_REGMAP_ADDR_ZERO ((unsigned int)(-1))
 #define GPIO_REGMAP_ADDR(addr) ((addr) ? : GPIO_REGMAP_ADDR_ZERO)
 
+struct gpio_regmap {
+	struct device *parent;
+	struct regmap *regmap;
+	struct gpio_chip gpio_chip;
+
+	int reg_stride;
+	int ngpio_per_reg;
+	unsigned int reg_dat_base;
+	unsigned int reg_set_base;
+	unsigned int reg_clr_base;
+	unsigned int reg_dir_in_base;
+	unsigned int reg_dir_out_base;
+
+	int (*reg_mask_xlate)(struct gpio_regmap *gpio, unsigned int base,
+			      unsigned int offset, unsigned int *reg,
+			      unsigned int *mask);
+
+	void *driver_data;
+};
+
 /**
  * struct gpio_regmap_config - Description of a generic regmap gpio_chip.
  * @parent:		The parent device