Skip to contentSkip to conversation

Rework OpenFirmware GPIO handling

RFC In review Dmitry Eremin-Solenikov 7 participants 13 messages Nov 17, 2009 – Dec 9, 2009 3 messages not in the archive

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

cover Rework OpenFirmware GPIO handling

This is an RFC serie of patches containing rework of OpenFirmware GPIO binding.

It permits very simple binding of most i2c/spi/etc. GPIO expanders (e.g. to use pcf8574x driver I had only to patch in support for working w/o platform data, no OF-specific code at all).

Dmitry Eremin-Solenikov (5):
Rework OpenFirmware GPIO handling
mcu_mpc8349emitx: port to new of gpio interface
mpc8xxx_gpio: port to new of gpio interface
simple_gpio: port to new of gpio interface
qe_gpio: port to new of gpio interface

 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c |   11 +++---
 arch/powerpc/sysdev/mpc8xxx_gpio.c             |    2 +-
 arch/powerpc/sysdev/qe_lib/gpio.c              |    4 +-
 arch/powerpc/sysdev/simple_gpio.c              |    2 +-
 drivers/gpio/gpiolib.c                         |    6 +++
 drivers/of/gpio.c                              |   42 ++++++++++++++++++++---
 include/asm-generic/gpio.h                     |   19 +++++++++++
 include/linux/of_gpio.h                        |   29 +++++++++-------
 8 files changed, 86 insertions(+), 29 deletions(-)
#1 lore raw

RFC PATCH 1/5 Rework OpenFirmware GPIO handling

This patch improves OF GPIO bindings so, that most non-OF-specific gpio controllers don't need to call any of OF binding function:

0) Move of_gpio_chip into main gpio_chip structure.
1) Call of_gpio_init/destroy from gpiochip_add/remove.
2) By default supply reasonable defaults for gpio_cells/xlate

---
 drivers/gpio/gpiolib.c     |    6 ++++++
 drivers/of/gpio.c          |   42 ++++++++++++++++++++++++++++++++++++------
 include/asm-generic/gpio.h |   19 +++++++++++++++++++
 include/linux/of_gpio.h    |   29 ++++++++++++++++-------------
 4 files changed, 77 insertions(+), 19 deletions(-)
drivers/gpio/gpiolib.c +6 -0
index 50de0f5..7c998b3 100644
@@ -10,6 +10,8 @@
 #include <linux/gpio.h>
 #include <linux/idr.h>
 
+#include <linux/of_gpio.h>
+
 
 /* Optional implementation infrastructure for GPIO interfaces.
  *
@@ -963,6 +965,8 @@ unlock:
 	spin_unlock_irqrestore(&gpio_lock, flags);
 	if (status == 0)
 		status = gpiochip_export(chip);
+	if (status == 0)
+		of_gpio_init(chip);
 fail:
 	/* failures here can mean systems won't boot... */
 	if (status)
@@ -994,6 +998,8 @@ int gpiochip_remove(struct gpio_chip *chip)
 		}
 	}
 	if (status == 0) {
+		of_gpio_destroy(chip);
+
 		for (id = chip->base; id < chip->base + chip->ngpio; id++)
 			gpio_desc[id].chip = NULL;
 	}
drivers/of/gpio.c +36 -6

69 lines not on this page · raw message

include/asm-generic/gpio.h +19 -0
index 66d6106..3a70958 100644
@@ -31,6 +31,21 @@ static inline int gpio_is_valid(int number)
 struct seq_file;
 struct module;
 
+#ifdef CONFIG_OF_GPIO
+struct device_node;
+enum of_gpio_flags;
+
+/*
+ * Generic OF GPIO chip
+ */
+struct of_gpio_chip {
+	int gpio_cells;
+	int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
+		     const void *gpio_spec, enum of_gpio_flags *flags);
+};
+#endif
+
+
 /**
  * struct gpio_chip - abstract a GPIO controller
  * @label: for diagnostics
@@ -76,6 +91,10 @@ struct gpio_chip {
 	struct device		*dev;
 	struct module		*owner;
 
+#ifdef CONFIG_OF_GPIO
+	struct of_gpio_chip	of_gc;
+#endif
+
 	int			(*request)(struct gpio_chip *chip,
 						unsigned offset);
 	void			(*free)(struct gpio_chip *chip,
include/linux/of_gpio.h +16 -13
index fc2472c..99cf84f 100644
@@ -32,25 +32,16 @@ enum of_gpio_flags {
 
 #ifdef CONFIG_OF_GPIO
 
-/*
- * Generic OF GPIO chip
- */
-struct of_gpio_chip {
-	struct gpio_chip gc;
-	int gpio_cells;
-	int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
-		     const void *gpio_spec, enum of_gpio_flags *flags);
-};
-
-static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc)
+static inline struct gpio_chip *to_gpio_chip_of(struct of_gpio_chip *of_gc)
 {
-	return container_of(gc, struct of_gpio_chip, gc);
+	return container_of(of_gc, struct gpio_chip, of_gc);
 }
 
 /*
  * OF GPIO chip for memory mapped banks
  */
 struct of_mm_gpio_chip {
+	struct gpio_chip gc;
 	struct of_gpio_chip of_gc;
 	void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
 	void __iomem *regs;
@@ -58,8 +49,11 @@ struct of_mm_gpio_chip {
 
 static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
 {
-	struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
+	return container_of(gc, struct of_mm_gpio_chip, gc);
+}
 
+static inline struct of_mm_gpio_chip *to_of_mm_of_chip(struct of_gpio_chip *of_gc)
+{
 	return container_of(of_gc, struct of_mm_gpio_chip, of_gc);
 }
 
@@ -73,6 +67,9 @@ extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc,
 				struct device_node *np,
 				const void *gpio_spec,
 				enum of_gpio_flags *flags);
+
+extern void of_gpio_init(struct gpio_chip *gc);
+extern void of_gpio_destroy(struct gpio_chip *gc);
 #else
 
 /* Drivers may not strictly depend on the GPIO support, so let them link. */
@@ -87,6 +84,12 @@ static inline unsigned int of_gpio_count(struct device_node *np)
 	return 0;
 }
 
+static inline void of_gpio_init(struct gpio_chip *gc)
+{
+}
+static inline void of_gpio_destroy(struct gpio_chip *gc)
+{
+}
 #endif /* CONFIG_OF_GPIO */
 
 /**
Signature · 1 line
1.6.5
#2 lore raw
Quoted 6 lines · Dmitry Eremin-Solenikov

This patch improves OF GPIO bindings so, that most non-OF-specific gpio controllers don't need to call any of OF binding function:

0) Move of_gpio_chip into main gpio_chip structure.
1) Call of_gpio_init/destroy from gpiochip_add/remove.
2) By default supply reasonable defaults for gpio_cells/xlate

Heh.. you didn't google before writing the code, did you? ;-)

I don't really think that David will like this approach, just as he didn't like the previous one (which was even less intrusive, but still wrong):

http://lkml.org/lkml/2008/10/16/248 (a huge thread, but worth reading)

Both of the approaches do not solve the pdata issue.

There are some of David's [absolutely legitimate] comments:
http://lkml.org/lkml/2008/10/20/43

Some more thoughts:
http://lkml.org/lkml/2008/10/20/182

And it turned out that the only sane solution is to write OF-pdata-hooks for the each driver (that we do for many drivers already):

http://lkml.org/lkml/2008/10/22/471

And for this, you'll need the patches that I sent to you yesterday.

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2

A message that is not in the archive (sent off-list or not yet received): 20091117161244.GA6849-wnGakbxT3iijyJ0x5qLZdcN33GVbZNy3@public.gmane.org

#4 lore raw
Quoted 3 lines

And it turned out that the only sane solution is to write OF-pdata-hooks for the each driver (that we do for many drivers already):

Or to support Grant in getting rid of of_platform :)

Signature · 2 lines
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

_______________________________________________
devicetree-discuss mailing list devicetree-discuss-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/devicetree-discuss

#5 lore raw
Quoted 5 lines · Wolfram Sang
Quoted 3 lines

And it turned out that the only sane solution is to write OF-pdata-hooks for the each driver (that we do for many drivers already):

Or to support Grant in getting rid of of_platform :)

No, of_platform is completely other stuff. This won't help I2C/SPI drivers.

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#6 lore raw
In reply to Dmitry Eremin-Solenikov
Quoted 6 lines · Dmitry Eremin-Solenikov

This patch improves OF GPIO bindings so, that most non-OF-specific gpio controllers don't need to call any of OF binding function:

0) Move of_gpio_chip into main gpio_chip structure.
1) Call of_gpio_init/destroy from gpiochip_add/remove.
2) By default supply reasonable defaults for gpio_cells/xlate

I think this change approaches the problem from the wrong way around. It is not appropriate to try and build OF hooks into gpiolib. gpiolib should be completely agnostic to any layers around them used to get data about how they are configured up. If anything, OF helpers should wrap around the gpiolib functions so that drivers can use them if it is useful to do so.

g.

A message that is not in the archive (sent off-list or not yet received): fa686aa40911201237y4a41dd63wee3fb4e0a5858e87-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#8 lore raw
Quoted 9 lines · Grant Likely
Quoted 6 lines · Dmitry Eremin-Solenikov

This patch improves OF GPIO bindings so, that most non-OF-specific gpio controllers don't need to call any of OF binding function:

0) Move of_gpio_chip into main gpio_chip structure.
1) Call of_gpio_init/destroy from gpiochip_add/remove.
2) By default supply reasonable defaults for gpio_cells/xlate

Quoted 6 lines

I think this change approaches the problem from the wrong way around. It is not appropriate to try and build OF hooks into gpiolib. gpiolib should be completely agnostic to any layers around them used to get data about how they are configured up.  If anything, OF helpers should wrap around the gpiolib functions so that drivers can use them if it is useful to do so.

Hmmm... okay, I didn't read your patch closely enough the first time around. I understand what you're trying to do now. I appreciate wanting to make GPIO binding transparent to GPIO providers. However, I'm still leery of inserting OF hooks into gpiolib. I'm not convinced that it is the correct approach. What *might* work is to add a notifier API to GPIOLIB so that interested subsystems (like OF) can register hooks to be told when GPIO pins are added and removed. That keeps things all the OF implementation details abstracted away from gpiolib.

Cheers,
g.

#9 lore raw

RFC PATCH 2/5 mcu_mpc8349emitx: port to new of gpio interface

In reply to Dmitry Eremin-Solenikov
---
 arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +5 -6
index 82a9bcb..4ba8b16 100644
@@ -36,7 +36,7 @@ struct mcu {
 	struct mutex lock;
 	struct device_node *np;
 	struct i2c_client *client;
-	struct of_gpio_chip of_gc;
+	struct gpio_chip gc;
 	u8 reg_ctrl;
 };
 
@@ -55,8 +55,7 @@ static void mcu_power_off(void)
 
 static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 {
-	struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
-	struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
+	struct mcu *mcu = container_of(gc, struct mcu, gc);
 	u8 bit = 1 << (4 + gpio);
 
 	mutex_lock(&mcu->lock);
@@ -78,8 +77,8 @@ static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
 static int mcu_gpiochip_add(struct mcu *mcu)
 {
 	struct device_node *np;
-	struct of_gpio_chip *of_gc = &mcu->of_gc;
-	struct gpio_chip *gc = &of_gc->gc;
+	struct gpio_chip *gc = &mcu->gc;
+	struct of_gpio_chip *of_gc = &gc->of_gc;
 	int ret;
 
 	np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
@@ -113,7 +112,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu)
 {
 	int ret;
 
-	ret = gpiochip_remove(&mcu->of_gc.gc);
+	ret = gpiochip_remove(&mcu->gc);
 	if (ret)
 		return ret;
 	of_node_put(mcu->np);
Signature · 1 line
1.6.5

A message that is not in the archive (sent off-list or not yet received): 1258472546-31343-3-git-send-email-dbaryshkov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org

#11 lore raw

Re: [RFC PATCH 2/5] mcu_mpc8349emitx: port to new of gpio interface

Quoted 4 lines · Dmitry Eremin-Solenikov

---
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)

Minding reviewing for me.

- k

Quoted 51 lines
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c +5 -6
index 82a9bcb..4ba8b16 100644
@@ -36,7 +36,7 @@ struct mcu {
 	struct mutex lock;
 	struct device_node *np;
 	struct i2c_client *client;
-	struct of_gpio_chip of_gc;
+	struct gpio_chip gc;
 	u8 reg_ctrl;
 };
 
@@ -55,8 +55,7 @@ static void mcu_power_off(void)
 
 static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
 {
-	struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
-	struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
+	struct mcu *mcu = container_of(gc, struct mcu, gc);
 	u8 bit = 1 << (4 + gpio);
 
 	mutex_lock(&mcu->lock);
@@ -78,8 +77,8 @@ static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
 static int mcu_gpiochip_add(struct mcu *mcu)
 {
 	struct device_node *np;
-	struct of_gpio_chip *of_gc = &mcu->of_gc;
-	struct gpio_chip *gc = &of_gc->gc;
+	struct gpio_chip *gc = &mcu->gc;
+	struct of_gpio_chip *of_gc = &gc->of_gc;
 	int ret;
 
 	np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
@@ -113,7 +112,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu)
 {
 	int ret;
 
-	ret = gpiochip_remove(&mcu->of_gc.gc);
+	ret = gpiochip_remove(&mcu->gc);
 	if (ret)
 		return ret;
 	of_node_put(mcu->np);
Signature · 6 lines
1.6.5

_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev-uLR06cmDAlY/[email protected]
https://lists.ozlabs.org/listinfo/linuxppc-dev
#12 lore raw

Re: [RFC PATCH 2/5] mcu_mpc8349emitx: port to new of gpio interface

Quoted 8 lines · Kumar Gala
Quoted 4 lines · Dmitry Eremin-Solenikov

---
arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c | 11 +++++------

1 files changed, 5 insertions(+), 6 deletions(-)

Minding reviewing for me.

The whole approach was reviewed, and rejected.

http://lists.ozlabs.org/pipermail/devicetree-discuss/2009-November/001330.html
and
http://lists.ozlabs.org/pipermail/devicetree-discuss/2009-November/001328.html

Thanks,

Signature · 3 lines
Anton Vorontsov
email: [email protected]
irc://irc.freenode.net/bd2
#13 lore raw

RFC PATCH 3/5 mpc8xxx_gpio: port to new of gpio interface

In reply to Dmitry Eremin-Solenikov
---
 arch/powerpc/sysdev/mpc8xxx_gpio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/sysdev/mpc8xxx_gpio.c +1 -1
index 103eace..9e8f4b4 100644
@@ -129,7 +129,7 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
 
 	mm_gc = &mpc8xxx_gc->mm_gc;
 	of_gc = &mm_gc->of_gc;
-	gc = &of_gc->gc;
+	gc = &mm_gc->gc;
 
 	mm_gc->save_regs = mpc8xxx_gpio_save_regs;
 	of_gc->gpio_cells = 2;
Signature · 1 line
1.6.5
#14 lore raw

RFC PATCH 4/5 simple_gpio: port to new of gpio interface

In reply to Dmitry Eremin-Solenikov
---
 arch/powerpc/sysdev/simple_gpio.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
arch/powerpc/sysdev/simple_gpio.c +1 -1
index 43c4569..5ad1e23 100644
@@ -101,7 +101,7 @@ static int __init u8_simple_gpiochip_add(struct device_node *np)
 
 	mm_gc = &u8_gc->mm_gc;
 	of_gc = &mm_gc->of_gc;
-	gc = &of_gc->gc;
+	gc = &mm_gc->gc;
 
 	mm_gc->save_regs = u8_gpio_save_regs;
 	of_gc->gpio_cells = 2;
Signature · 1 line
1.6.5
#15 lore raw

RFC PATCH 5/5 qe_gpio: port to new of gpio interface

In reply to Dmitry Eremin-Solenikov
---
 arch/powerpc/sysdev/qe_lib/gpio.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
arch/powerpc/sysdev/qe_lib/gpio.c +2 -2
index 8e7a776..b85eab8 100644
@@ -187,7 +187,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
 	if (err < 0)
 		goto err1;
 
-	mm_gc = to_of_mm_gpio_chip(&of_gc->gc);
+	mm_gc = to_of_mm_of_chip(of_gc);
 	qe_gc = to_qe_gpio_chip(mm_gc);
 
 	spin_lock_irqsave(&qe_gc->lock, flags);
@@ -319,7 +319,7 @@ static int __init qe_add_gpiochips(void)
 
 		mm_gc = &qe_gc->mm_gc;
 		of_gc = &mm_gc->of_gc;
-		gc = &of_gc->gc;
+		gc = &mm_gc->gc;
 
 		mm_gc->save_regs = qe_gpio_save_regs;
 		of_gc->gpio_cells = 2;
Signature · 1 line
1.6.5