>From 265a4a0e3574f5a610a33a04717532cd2603e17b Mon Sep 17 00:00:00 2001
From: Anton Vorontsov <avorontsov@ru.mvista.com>
Date: Fri, 1 May 2009 18:36:09 +0400
Subject: [PATCH 2/4] of/gpio: implement of_dev_gpiochip_{add,remove} calls

And let the gpiolib forward all dev_gpiochip_ calls to of_ versions, there
we can glue the gpiochips with the device tree.

Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
---
 drivers/of/gpio.c       |   56 +++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_gpio.h |    4 +++
 2 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index 148030f..1ae92dd 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -236,3 +236,59 @@ err0:
 	return ret;
 }
 EXPORT_SYMBOL(of_mm_gpiochip_add);
+
+/**
+ * of_gpiochip_register_simple - Register a chip with the OF GPIO subsystem
+ * @chip	pointer to a GPIO chip
+ * @np:		device node to register the GPIO chip with
+ *
+ * This function registers a GPIO chip with the OF infrastructure. It is
+ * assumed that the chip was previsously allocated and added to a generic
+ * GPIOLIB framework (using gpiochip_add() function).
+ *
+ * The `simple' name means that the chip is using simple two-cells scheme for
+ * the gpio-specifier.
+ */
+int of_gpiochip_register_simple(struct gpio_chip *chip, struct device_node *np)
+{
+	struct of_gpio_chip *of_gc;
+
+	if (np->data) {
+		WARN_ON(1);
+		return -EBUSY;
+	}
+
+	of_gc = kzalloc(sizeof(*of_gc), GFP_KERNEL);
+	if (!of_gc)
+		return -ENOMEM;
+
+	of_gc->gpio_cells = 2;
+	of_gc->xlate = of_gpio_simple_xlate;
+	of_gc->chip = chip;
+	np->data = of_gc;
+	of_node_get(np);
+	return 0;
+}
+EXPORT_SYMBOL(of_gpiochip_register_simple);
+
+/**
+ * of_gpiochip_unregister - Unregister a GPIO chip
+ * @chip	pointer to a GPIO chip
+ * @np:		device node for which the GPIO chip was previously registered
+ *
+ * This function unregisters a GPIO chip that was previsously registered
+ * with of_gpiochip_register*().
+ */
+void of_gpiochip_unregister(struct gpio_chip *chip, struct device_node *np)
+{
+	struct of_gpio_chip *of_gc = np->data;
+
+	if (!of_gc || of_gc->chip != chip) {
+		WARN_ON(1);
+		return;
+	}
+	np->data = NULL;
+	kfree(of_gc);
+	of_node_put(np);
+}
+EXPORT_SYMBOL(of_gpiochip_unregister);
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index fb859dd..323e6d4 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -70,6 +70,10 @@ extern unsigned int of_gpio_count(struct device_node *np);
 
 extern int of_mm_gpiochip_add(struct device_node *np,
 			      struct of_mm_gpio_chip *mm_gc);
+extern int of_gpiochip_register_simple(struct gpio_chip *chip,
+				       struct device_node *np);
+extern void of_gpiochip_unregister(struct gpio_chip *chip,
+				   struct device_node *np);
 extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc,
 				struct device_node *np,
 				const void *gpio_spec,
-- 
1.6.3.3

