aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Vorontsov <avorontsov@ru.mvista.com>2010-06-08 09:48:16 -0400
committerGrant Likely <grant.likely@secretlab.ca>2010-07-05 18:14:30 -0400
commita19e3da5bc5fc6c10ab73f310bea80f3845b4531 (patch)
tree49b6e952f48e56d9701f92e0c24044a14b676a34
parentcedb1881ba32f7e9cd49250bd79debccbe52b094 (diff)
of/gpio: Kill of_gpio_chip and add members directly to gpio_chip
The OF gpio infrastructure is great for describing GPIO connections within the device tree. However, using a GPIO binding still requires changes to the gpio controller just to add an of_gpio structure. In most cases, the gpio controller doesn't actually need any special support and the simple OF gpio mapping function is more than sufficient. Additional, the current scheme of using of_gpio_chip requires a convoluted scheme to maintain 1:1 mappings between of_gpio_chip and gpio_chip instances. If the struct of_gpio_chip data members were moved into struct gpio_chip, then it would simplify the processing of OF gpio bindings, and it would make it trivial to use device tree OF connections on existing gpiolib controller drivers. This patch eliminates the of_gpio_chip structure and moves the relevant fields into struct gpio_chip (conditional on CONFIG_OF_GPIO). This move simplifies the existing code and prepares for adding automatic device tree support to existing drivers. Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Anton Vorontsov <avorontsov@ru.mvista.com> Cc: Grant Likely <grant.likely@secretlab.ca> Cc: David Brownell <dbrownell@users.sourceforge.net> Cc: Bill Gatliff <bgat@billgatliff.com> Cc: Dmitry Eremin-Solenikov <dbaryshkov@gmail.com> Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org> Cc: Jean Delvare <khali@linux-fr.org>
-rw-r--r--arch/microblaze/kernel/reset.c12
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_gpio.c32
-rw-r--r--arch/powerpc/platforms/52xx/mpc52xx_gpt.c29
-rw-r--r--arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c15
-rw-r--r--arch/powerpc/platforms/86xx/gef_gpio.c24
-rw-r--r--arch/powerpc/sysdev/cpm1.c12
-rw-r--r--arch/powerpc/sysdev/cpm_common.c6
-rw-r--r--arch/powerpc/sysdev/mpc8xxx_gpio.c6
-rw-r--r--arch/powerpc/sysdev/ppc4xx_gpio.c6
-rw-r--r--arch/powerpc/sysdev/qe_lib/gpio.c32
-rw-r--r--arch/powerpc/sysdev/simple_gpio.c6
-rw-r--r--drivers/gpio/xilinx_gpio.c16
-rw-r--r--drivers/of/gpio.c50
-rw-r--r--include/asm-generic/gpio.h12
-rw-r--r--include/linux/of_gpio.h29
15 files changed, 129 insertions, 158 deletions
diff --git a/arch/microblaze/kernel/reset.c b/arch/microblaze/kernel/reset.c
index a1721a33042..5476d3caf04 100644
--- a/arch/microblaze/kernel/reset.c
+++ b/arch/microblaze/kernel/reset.c
@@ -24,8 +24,8 @@ static int of_reset_gpio_handle(void)
24 int ret; /* variable which stored handle reset gpio pin */ 24 int ret; /* variable which stored handle reset gpio pin */
25 struct device_node *root; /* root node */ 25 struct device_node *root; /* root node */
26 struct device_node *gpio; /* gpio node */ 26 struct device_node *gpio; /* gpio node */
27 struct of_gpio_chip *of_gc = NULL; 27 struct gpio_chip *gc;
28 enum of_gpio_flags flags ; 28 u32 flags;
29 const void *gpio_spec; 29 const void *gpio_spec;
30 30
31 /* find out root node */ 31 /* find out root node */
@@ -39,19 +39,19 @@ static int of_reset_gpio_handle(void)
39 goto err0; 39 goto err0;
40 } 40 }
41 41
42 of_gc = gpio->data; 42 gc = gpio->data;
43 if (!of_gc) { 43 if (!gc) {
44 pr_debug("%s: gpio controller %s isn't registered\n", 44 pr_debug("%s: gpio controller %s isn't registered\n",
45 root->full_name, gpio->full_name); 45 root->full_name, gpio->full_name);
46 ret = -ENODEV; 46 ret = -ENODEV;
47 goto err1; 47 goto err1;
48 } 48 }
49 49
50 ret = of_gc->xlate(of_gc, root, gpio_spec, &flags); 50 ret = gc->of_xlate(gc, root, gpio_spec, &flags);
51 if (ret < 0) 51 if (ret < 0)
52 goto err1; 52 goto err1;
53 53
54 ret += of_gc->gc.base; 54 ret += gc->base;
55err1: 55err1:
56 of_node_put(gpio); 56 of_node_put(gpio);
57err0: 57err0:
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpio.c b/arch/powerpc/platforms/52xx/mpc52xx_gpio.c
index ca5305a5bd6..fd0912eeffe 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_gpio.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_gpio.c
@@ -152,21 +152,21 @@ static int __devinit mpc52xx_wkup_gpiochip_probe(struct of_device *ofdev,
152{ 152{
153 struct mpc52xx_gpiochip *chip; 153 struct mpc52xx_gpiochip *chip;
154 struct mpc52xx_gpio_wkup __iomem *regs; 154 struct mpc52xx_gpio_wkup __iomem *regs;
155 struct of_gpio_chip *ofchip; 155 struct gpio_chip *gc;
156 int ret; 156 int ret;
157 157
158 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 158 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
159 if (!chip) 159 if (!chip)
160 return -ENOMEM; 160 return -ENOMEM;
161 161
162 ofchip = &chip->mmchip.of_gc; 162 gc = &chip->mmchip.gc;
163 163
164 ofchip->gpio_cells = 2; 164 gc->of_gpio_n_cells = 2;
165 ofchip->gc.ngpio = 8; 165 gc->ngpio = 8;
166 ofchip->gc.direction_input = mpc52xx_wkup_gpio_dir_in; 166 gc->direction_input = mpc52xx_wkup_gpio_dir_in;
167 ofchip->gc.direction_output = mpc52xx_wkup_gpio_dir_out; 167 gc->direction_output = mpc52xx_wkup_gpio_dir_out;
168 ofchip->gc.get = mpc52xx_wkup_gpio_get; 168 gc->get = mpc52xx_wkup_gpio_get;
169 ofchip->gc.set = mpc52xx_wkup_gpio_set; 169 gc->set = mpc52xx_wkup_gpio_set;
170 170
171 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip); 171 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
172 if (ret) 172 if (ret)
@@ -315,7 +315,7 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev,
315 const struct of_device_id *match) 315 const struct of_device_id *match)
316{ 316{
317 struct mpc52xx_gpiochip *chip; 317 struct mpc52xx_gpiochip *chip;
318 struct of_gpio_chip *ofchip; 318 struct gpio_chip *gc;
319 struct mpc52xx_gpio __iomem *regs; 319 struct mpc52xx_gpio __iomem *regs;
320 int ret; 320 int ret;
321 321
@@ -323,14 +323,14 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev,
323 if (!chip) 323 if (!chip)
324 return -ENOMEM; 324 return -ENOMEM;
325 325
326 ofchip = &chip->mmchip.of_gc; 326 gc = &chip->mmchip.gc;
327 327
328 ofchip->gpio_cells = 2; 328 gc->of_gpio_n_cells = 2;
329 ofchip->gc.ngpio = 32; 329 gc->ngpio = 32;
330 ofchip->gc.direction_input = mpc52xx_simple_gpio_dir_in; 330 gc->direction_input = mpc52xx_simple_gpio_dir_in;
331 ofchip->gc.direction_output = mpc52xx_simple_gpio_dir_out; 331 gc->direction_output = mpc52xx_simple_gpio_dir_out;
332 ofchip->gc.get = mpc52xx_simple_gpio_get; 332 gc->get = mpc52xx_simple_gpio_get;
333 ofchip->gc.set = mpc52xx_simple_gpio_set; 333 gc->set = mpc52xx_simple_gpio_set;
334 334
335 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip); 335 ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
336 if (ret) 336 if (ret)
diff --git a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
index 46c93578cbf..3f2ee47f1d0 100644
--- a/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
+++ b/arch/powerpc/platforms/52xx/mpc52xx_gpt.c
@@ -78,7 +78,7 @@ MODULE_LICENSE("GPL");
78 * @dev: pointer to device structure 78 * @dev: pointer to device structure
79 * @regs: virtual address of GPT registers 79 * @regs: virtual address of GPT registers
80 * @lock: spinlock to coordinate between different functions. 80 * @lock: spinlock to coordinate between different functions.
81 * @of_gc: of_gpio_chip instance structure; used when GPIO is enabled 81 * @gc: gpio_chip instance structure; used when GPIO is enabled
82 * @irqhost: Pointer to irq_host instance; used when IRQ mode is supported 82 * @irqhost: Pointer to irq_host instance; used when IRQ mode is supported
83 * @wdt_mode: only relevant for gpt0: bit 0 (MPC52xx_GPT_CAN_WDT) indicates 83 * @wdt_mode: only relevant for gpt0: bit 0 (MPC52xx_GPT_CAN_WDT) indicates
84 * if the gpt may be used as wdt, bit 1 (MPC52xx_GPT_IS_WDT) indicates 84 * if the gpt may be used as wdt, bit 1 (MPC52xx_GPT_IS_WDT) indicates
@@ -94,7 +94,7 @@ struct mpc52xx_gpt_priv {
94 u8 wdt_mode; 94 u8 wdt_mode;
95 95
96#if defined(CONFIG_GPIOLIB) 96#if defined(CONFIG_GPIOLIB)
97 struct of_gpio_chip of_gc; 97 struct gpio_chip gc;
98#endif 98#endif
99}; 99};
100 100
@@ -280,7 +280,7 @@ mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)
280#if defined(CONFIG_GPIOLIB) 280#if defined(CONFIG_GPIOLIB)
281static inline struct mpc52xx_gpt_priv *gc_to_mpc52xx_gpt(struct gpio_chip *gc) 281static inline struct mpc52xx_gpt_priv *gc_to_mpc52xx_gpt(struct gpio_chip *gc)
282{ 282{
283 return container_of(to_of_gpio_chip(gc), struct mpc52xx_gpt_priv,of_gc); 283 return container_of(gc, struct mpc52xx_gpt_priv, gc);
284} 284}
285 285
286static int mpc52xx_gpt_gpio_get(struct gpio_chip *gc, unsigned int gpio) 286static int mpc52xx_gpt_gpio_get(struct gpio_chip *gc, unsigned int gpio)
@@ -336,28 +336,27 @@ mpc52xx_gpt_gpio_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)
336 if (!of_find_property(node, "gpio-controller", NULL)) 336 if (!of_find_property(node, "gpio-controller", NULL))
337 return; 337 return;
338 338
339 gpt->of_gc.gc.label = kstrdup(node->full_name, GFP_KERNEL); 339 gpt->gc.label = kstrdup(node->full_name, GFP_KERNEL);
340 if (!gpt->of_gc.gc.label) { 340 if (!gpt->gc.label) {
341 dev_err(gpt->dev, "out of memory\n"); 341 dev_err(gpt->dev, "out of memory\n");
342 return; 342 return;
343 } 343 }
344 344
345 gpt->of_gc.gpio_cells = 2; 345 gpt->gc.ngpio = 1;
346 gpt->of_gc.gc.ngpio = 1; 346 gpt->gc.direction_input = mpc52xx_gpt_gpio_dir_in;
347 gpt->of_gc.gc.direction_input = mpc52xx_gpt_gpio_dir_in; 347 gpt->gc.direction_output = mpc52xx_gpt_gpio_dir_out;
348 gpt->of_gc.gc.direction_output = mpc52xx_gpt_gpio_dir_out; 348 gpt->gc.get = mpc52xx_gpt_gpio_get;
349 gpt->of_gc.gc.get = mpc52xx_gpt_gpio_get; 349 gpt->gc.set = mpc52xx_gpt_gpio_set;
350 gpt->of_gc.gc.set = mpc52xx_gpt_gpio_set; 350 gpt->gc.base = -1;
351 gpt->of_gc.gc.base = -1; 351 gpt->gc.of_gpio_n_cells = 2;
352 gpt->of_gc.xlate = of_gpio_simple_xlate; 352 gpt->gc.of_xlate = of_gpio_simple_xlate;
353 node->data = &gpt->of_gc;
354 of_node_get(node); 353 of_node_get(node);
355 354
356 /* Setup external pin in GPIO mode */ 355 /* Setup external pin in GPIO mode */
357 clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK, 356 clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK,
358 MPC52xx_GPT_MODE_MS_GPIO); 357 MPC52xx_GPT_MODE_MS_GPIO);
359 358
360 rc = gpiochip_add(&gpt->of_gc.gc); 359 rc = gpiochip_add(&gpt->gc);
361 if (rc) 360 if (rc)
362 dev_err(gpt->dev, "gpiochip_add() failed; rc=%i\n", rc); 361 dev_err(gpt->dev, "gpiochip_add() failed; rc=%i\n", rc);
363 362
diff --git a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
index d119a7c1c17..e49f4bd2f99 100644
--- a/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
+++ b/arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c
@@ -37,7 +37,7 @@ struct mcu {
37 struct mutex lock; 37 struct mutex lock;
38 struct device_node *np; 38 struct device_node *np;
39 struct i2c_client *client; 39 struct i2c_client *client;
40 struct of_gpio_chip of_gc; 40 struct gpio_chip gc;
41 u8 reg_ctrl; 41 u8 reg_ctrl;
42}; 42};
43 43
@@ -56,8 +56,7 @@ static void mcu_power_off(void)
56 56
57static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 57static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
58{ 58{
59 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc); 59 struct mcu *mcu = container_of(gc, struct mcu, gc);
60 struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
61 u8 bit = 1 << (4 + gpio); 60 u8 bit = 1 << (4 + gpio);
62 61
63 mutex_lock(&mcu->lock); 62 mutex_lock(&mcu->lock);
@@ -79,8 +78,7 @@ static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
79static int mcu_gpiochip_add(struct mcu *mcu) 78static int mcu_gpiochip_add(struct mcu *mcu)
80{ 79{
81 struct device_node *np; 80 struct device_node *np;
82 struct of_gpio_chip *of_gc = &mcu->of_gc; 81 struct gpio_chip *gc = &mcu->gc;
83 struct gpio_chip *gc = &of_gc->gc;
84 int ret; 82 int ret;
85 83
86 np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx"); 84 np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
@@ -94,10 +92,9 @@ static int mcu_gpiochip_add(struct mcu *mcu)
94 gc->base = -1; 92 gc->base = -1;
95 gc->set = mcu_gpio_set; 93 gc->set = mcu_gpio_set;
96 gc->direction_output = mcu_gpio_dir_out; 94 gc->direction_output = mcu_gpio_dir_out;
97 of_gc->gpio_cells = 2; 95 gc->of_gpio_n_cells = 2;
98 of_gc->xlate = of_gpio_simple_xlate; 96 gc->of_xlate = of_gpio_simple_xlate;
99 97
100 np->data = of_gc;
101 mcu->np = np; 98 mcu->np = np;
102 99
103 /* 100 /*
@@ -114,7 +111,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu)
114{ 111{
115 int ret; 112 int ret;
116 113
117 ret = gpiochip_remove(&mcu->of_gc.gc); 114 ret = gpiochip_remove(&mcu->gc);
118 if (ret) 115 if (ret)
119 return ret; 116 return ret;
120 of_node_put(mcu->np); 117 of_node_put(mcu->np);
diff --git a/arch/powerpc/platforms/86xx/gef_gpio.c b/arch/powerpc/platforms/86xx/gef_gpio.c
index b8cb08dbd89..4ff7b1e7bba 100644
--- a/arch/powerpc/platforms/86xx/gef_gpio.c
+++ b/arch/powerpc/platforms/86xx/gef_gpio.c
@@ -118,12 +118,12 @@ static int __init gef_gpio_init(void)
118 } 118 }
119 119
120 /* Setup pointers to chip functions */ 120 /* Setup pointers to chip functions */
121 gef_gpio_chip->of_gc.gpio_cells = 2; 121 gef_gpio_chip->gc.of_gpio_n_cells = 2;
122 gef_gpio_chip->of_gc.gc.ngpio = 19; 122 gef_gpio_chip->gc.ngpio = 19;
123 gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in; 123 gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
124 gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out; 124 gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
125 gef_gpio_chip->of_gc.gc.get = gef_gpio_get; 125 gef_gpio_chip->gc.get = gef_gpio_get;
126 gef_gpio_chip->of_gc.gc.set = gef_gpio_set; 126 gef_gpio_chip->gc.set = gef_gpio_set;
127 127
128 /* This function adds a memory mapped GPIO chip */ 128 /* This function adds a memory mapped GPIO chip */
129 retval = of_mm_gpiochip_add(np, gef_gpio_chip); 129 retval = of_mm_gpiochip_add(np, gef_gpio_chip);
@@ -146,12 +146,12 @@ static int __init gef_gpio_init(void)
146 } 146 }
147 147
148 /* Setup pointers to chip functions */ 148 /* Setup pointers to chip functions */
149 gef_gpio_chip->of_gc.gpio_cells = 2; 149 gef_gpio_chip->gc.of_gpio_n_cells = 2;
150 gef_gpio_chip->of_gc.gc.ngpio = 6; 150 gef_gpio_chip->gc.ngpio = 6;
151 gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in; 151 gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
152 gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out; 152 gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
153 gef_gpio_chip->of_gc.gc.get = gef_gpio_get; 153 gef_gpio_chip->gc.get = gef_gpio_get;
154 gef_gpio_chip->of_gc.gc.set = gef_gpio_set; 154 gef_gpio_chip->gc.set = gef_gpio_set;
155 155
156 /* This function adds a memory mapped GPIO chip */ 156 /* This function adds a memory mapped GPIO chip */
157 retval = of_mm_gpiochip_add(np, gef_gpio_chip); 157 retval = of_mm_gpiochip_add(np, gef_gpio_chip);
diff --git a/arch/powerpc/sysdev/cpm1.c b/arch/powerpc/sysdev/cpm1.c
index 8d103ca6d6a..d5cf7d4ccf8 100644
--- a/arch/powerpc/sysdev/cpm1.c
+++ b/arch/powerpc/sysdev/cpm1.c
@@ -621,7 +621,6 @@ int cpm1_gpiochip_add16(struct device_node *np)
621{ 621{
622 struct cpm1_gpio16_chip *cpm1_gc; 622 struct cpm1_gpio16_chip *cpm1_gc;
623 struct of_mm_gpio_chip *mm_gc; 623 struct of_mm_gpio_chip *mm_gc;
624 struct of_gpio_chip *of_gc;
625 struct gpio_chip *gc; 624 struct gpio_chip *gc;
626 625
627 cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL); 626 cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL);
@@ -631,11 +630,10 @@ int cpm1_gpiochip_add16(struct device_node *np)
631 spin_lock_init(&cpm1_gc->lock); 630 spin_lock_init(&cpm1_gc->lock);
632 631
633 mm_gc = &cpm1_gc->mm_gc; 632 mm_gc = &cpm1_gc->mm_gc;
634 of_gc = &mm_gc->of_gc; 633 gc = &mm_gc->gc;
635 gc = &of_gc->gc;
636 634
637 mm_gc->save_regs = cpm1_gpio16_save_regs; 635 mm_gc->save_regs = cpm1_gpio16_save_regs;
638 of_gc->gpio_cells = 2; 636 gc->of_gpio_n_cells = 2;
639 gc->ngpio = 16; 637 gc->ngpio = 16;
640 gc->direction_input = cpm1_gpio16_dir_in; 638 gc->direction_input = cpm1_gpio16_dir_in;
641 gc->direction_output = cpm1_gpio16_dir_out; 639 gc->direction_output = cpm1_gpio16_dir_out;
@@ -745,7 +743,6 @@ int cpm1_gpiochip_add32(struct device_node *np)
745{ 743{
746 struct cpm1_gpio32_chip *cpm1_gc; 744 struct cpm1_gpio32_chip *cpm1_gc;
747 struct of_mm_gpio_chip *mm_gc; 745 struct of_mm_gpio_chip *mm_gc;
748 struct of_gpio_chip *of_gc;
749 struct gpio_chip *gc; 746 struct gpio_chip *gc;
750 747
751 cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL); 748 cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL);
@@ -755,11 +752,10 @@ int cpm1_gpiochip_add32(struct device_node *np)
755 spin_lock_init(&cpm1_gc->lock); 752 spin_lock_init(&cpm1_gc->lock);
756 753
757 mm_gc = &cpm1_gc->mm_gc; 754 mm_gc = &cpm1_gc->mm_gc;
758 of_gc = &mm_gc->of_gc; 755 gc = &mm_gc->gc;
759 gc = &of_gc->gc;
760 756
761 mm_gc->save_regs = cpm1_gpio32_save_regs; 757 mm_gc->save_regs = cpm1_gpio32_save_regs;
762 of_gc->gpio_cells = 2; 758 gc->of_gpio_n_cells = 2;
763 gc->ngpio = 32; 759 gc->ngpio = 32;
764 gc->direction_input = cpm1_gpio32_dir_in; 760 gc->direction_input = cpm1_gpio32_dir_in;
765 gc->direction_output = cpm1_gpio32_dir_out; 761 gc->direction_output = cpm1_gpio32_dir_out;
diff --git a/arch/powerpc/sysdev/cpm_common.c b/arch/powerpc/sysdev/cpm_common.c
index 88b9812c854..67e9b47dcf8 100644
--- a/arch/powerpc/sysdev/cpm_common.c
+++ b/arch/powerpc/sysdev/cpm_common.c
@@ -325,7 +325,6 @@ int cpm2_gpiochip_add32(struct device_node *np)
325{ 325{
326 struct cpm2_gpio32_chip *cpm2_gc; 326 struct cpm2_gpio32_chip *cpm2_gc;
327 struct of_mm_gpio_chip *mm_gc; 327 struct of_mm_gpio_chip *mm_gc;
328 struct of_gpio_chip *of_gc;
329 struct gpio_chip *gc; 328 struct gpio_chip *gc;
330 329
331 cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL); 330 cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
@@ -335,11 +334,10 @@ int cpm2_gpiochip_add32(struct device_node *np)
335 spin_lock_init(&cpm2_gc->lock); 334 spin_lock_init(&cpm2_gc->lock);
336 335
337 mm_gc = &cpm2_gc->mm_gc; 336 mm_gc = &cpm2_gc->mm_gc;
338 of_gc = &mm_gc->of_gc; 337 gc = &mm_gc->gc;
339 gc = &of_gc->gc;
340 338
341 mm_gc->save_regs = cpm2_gpio32_save_regs; 339 mm_gc->save_regs = cpm2_gpio32_save_regs;
342 of_gc->gpio_cells = 2; 340 gc->of_gpio_n_cells = 2;
343 gc->ngpio = 32; 341 gc->ngpio = 32;
344 gc->direction_input = cpm2_gpio32_dir_in; 342 gc->direction_input = cpm2_gpio32_dir_in;
345 gc->direction_output = cpm2_gpio32_dir_out; 343 gc->direction_output = cpm2_gpio32_dir_out;
diff --git a/arch/powerpc/sysdev/mpc8xxx_gpio.c b/arch/powerpc/sysdev/mpc8xxx_gpio.c
index 83f519655fa..ec8fcd42101 100644
--- a/arch/powerpc/sysdev/mpc8xxx_gpio.c
+++ b/arch/powerpc/sysdev/mpc8xxx_gpio.c
@@ -257,7 +257,6 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
257{ 257{
258 struct mpc8xxx_gpio_chip *mpc8xxx_gc; 258 struct mpc8xxx_gpio_chip *mpc8xxx_gc;
259 struct of_mm_gpio_chip *mm_gc; 259 struct of_mm_gpio_chip *mm_gc;
260 struct of_gpio_chip *of_gc;
261 struct gpio_chip *gc; 260 struct gpio_chip *gc;
262 unsigned hwirq; 261 unsigned hwirq;
263 int ret; 262 int ret;
@@ -271,11 +270,10 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
271 spin_lock_init(&mpc8xxx_gc->lock); 270 spin_lock_init(&mpc8xxx_gc->lock);
272 271
273 mm_gc = &mpc8xxx_gc->mm_gc; 272 mm_gc = &mpc8xxx_gc->mm_gc;
274 of_gc = &mm_gc->of_gc; 273 gc = &mm_gc->gc;
275 gc = &of_gc->gc;
276 274
277 mm_gc->save_regs = mpc8xxx_gpio_save_regs; 275 mm_gc->save_regs = mpc8xxx_gpio_save_regs;
278 of_gc->gpio_cells = 2; 276 gc->of_gpio_n_cells = 2;
279 gc->ngpio = MPC8XXX_GPIO_PINS; 277 gc->ngpio = MPC8XXX_GPIO_PINS;
280 gc->direction_input = mpc8xxx_gpio_dir_in; 278 gc->direction_input = mpc8xxx_gpio_dir_in;
281 gc->direction_output = mpc8xxx_gpio_dir_out; 279 gc->direction_output = mpc8xxx_gpio_dir_out;
diff --git a/arch/powerpc/sysdev/ppc4xx_gpio.c b/arch/powerpc/sysdev/ppc4xx_gpio.c
index 3812fc366be..42e7a5eea66 100644
--- a/arch/powerpc/sysdev/ppc4xx_gpio.c
+++ b/arch/powerpc/sysdev/ppc4xx_gpio.c
@@ -181,7 +181,6 @@ static int __init ppc4xx_add_gpiochips(void)
181 int ret; 181 int ret;
182 struct ppc4xx_gpio_chip *ppc4xx_gc; 182 struct ppc4xx_gpio_chip *ppc4xx_gc;
183 struct of_mm_gpio_chip *mm_gc; 183 struct of_mm_gpio_chip *mm_gc;
184 struct of_gpio_chip *of_gc;
185 struct gpio_chip *gc; 184 struct gpio_chip *gc;
186 185
187 ppc4xx_gc = kzalloc(sizeof(*ppc4xx_gc), GFP_KERNEL); 186 ppc4xx_gc = kzalloc(sizeof(*ppc4xx_gc), GFP_KERNEL);
@@ -193,10 +192,9 @@ static int __init ppc4xx_add_gpiochips(void)
193 spin_lock_init(&ppc4xx_gc->lock); 192 spin_lock_init(&ppc4xx_gc->lock);
194 193
195 mm_gc = &ppc4xx_gc->mm_gc; 194 mm_gc = &ppc4xx_gc->mm_gc;
196 of_gc = &mm_gc->of_gc; 195 gc = &mm_gc->gc;
197 gc = &of_gc->gc;
198 196
199 of_gc->gpio_cells = 2; 197 gc->of_gpio_n_cells = 2;
200 gc->ngpio = 32; 198 gc->ngpio = 32;
201 gc->direction_input = ppc4xx_gpio_dir_in; 199 gc->direction_input = ppc4xx_gpio_dir_in;
202 gc->direction_output = ppc4xx_gpio_dir_out; 200 gc->direction_output = ppc4xx_gpio_dir_out;
diff --git a/arch/powerpc/sysdev/qe_lib/gpio.c b/arch/powerpc/sysdev/qe_lib/gpio.c
index dc8f8d61807..194478c2f4b 100644
--- a/arch/powerpc/sysdev/qe_lib/gpio.c
+++ b/arch/powerpc/sysdev/qe_lib/gpio.c
@@ -138,8 +138,8 @@ struct qe_pin {
138struct qe_pin *qe_pin_request(struct device_node *np, int index) 138struct qe_pin *qe_pin_request(struct device_node *np, int index)
139{ 139{
140 struct qe_pin *qe_pin; 140 struct qe_pin *qe_pin;
141 struct device_node *gc; 141 struct device_node *gpio_np;
142 struct of_gpio_chip *of_gc = NULL; 142 struct gpio_chip *gc;
143 struct of_mm_gpio_chip *mm_gc; 143 struct of_mm_gpio_chip *mm_gc;
144 struct qe_gpio_chip *qe_gc; 144 struct qe_gpio_chip *qe_gc;
145 int err; 145 int err;
@@ -155,40 +155,40 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
155 } 155 }
156 156
157 err = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, 157 err = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
158 &gc, &gpio_spec); 158 &gpio_np, &gpio_spec);
159 if (err) { 159 if (err) {
160 pr_debug("%s: can't parse gpios property\n", __func__); 160 pr_debug("%s: can't parse gpios property\n", __func__);
161 goto err0; 161 goto err0;
162 } 162 }
163 163
164 if (!of_device_is_compatible(gc, "fsl,mpc8323-qe-pario-bank")) { 164 if (!of_device_is_compatible(gpio_np, "fsl,mpc8323-qe-pario-bank")) {
165 pr_debug("%s: tried to get a non-qe pin\n", __func__); 165 pr_debug("%s: tried to get a non-qe pin\n", __func__);
166 err = -EINVAL; 166 err = -EINVAL;
167 goto err1; 167 goto err1;
168 } 168 }
169 169
170 of_gc = gc->data; 170 gc = gpio_np->data;
171 if (!of_gc) { 171 if (!gc) {
172 pr_debug("%s: gpio controller %s isn't registered\n", 172 pr_debug("%s: gpio controller %s isn't registered\n",
173 np->full_name, gc->full_name); 173 np->full_name, gpio_np->full_name);
174 err = -ENODEV; 174 err = -ENODEV;
175 goto err1; 175 goto err1;
176 } 176 }
177 177
178 gpio_cells = of_get_property(gc, "#gpio-cells", &size); 178 gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size);
179 if (!gpio_cells || size != sizeof(*gpio_cells) || 179 if (!gpio_cells || size != sizeof(*gpio_cells) ||
180 *gpio_cells != of_gc->gpio_cells) { 180 *gpio_cells != gc->of_gpio_n_cells) {
181 pr_debug("%s: wrong #gpio-cells for %s\n", 181 pr_debug("%s: wrong #gpio-cells for %s\n",
182 np->full_name, gc->full_name); 182 np->full_name, gpio_np->full_name);
183 err = -EINVAL; 183 err = -EINVAL;
184 goto err1; 184 goto err1;
185 } 185 }
186 186
187 err = of_gc->xlate(of_gc, np, gpio_spec, NULL); 187 err = gc->of_xlate(gc, np, gpio_spec, NULL);
188 if (err < 0) 188 if (err < 0)
189 goto err1; 189 goto err1;
190 190
191 mm_gc = to_of_mm_gpio_chip(&of_gc->gc); 191 mm_gc = to_of_mm_gpio_chip(gc);
192 qe_gc = to_qe_gpio_chip(mm_gc); 192 qe_gc = to_qe_gpio_chip(mm_gc);
193 193
194 spin_lock_irqsave(&qe_gc->lock, flags); 194 spin_lock_irqsave(&qe_gc->lock, flags);
@@ -206,7 +206,7 @@ struct qe_pin *qe_pin_request(struct device_node *np, int index)
206 if (!err) 206 if (!err)
207 return qe_pin; 207 return qe_pin;
208err1: 208err1:
209 of_node_put(gc); 209 of_node_put(gpio_np);
210err0: 210err0:
211 kfree(qe_pin); 211 kfree(qe_pin);
212 pr_debug("%s failed with status %d\n", __func__, err); 212 pr_debug("%s failed with status %d\n", __func__, err);
@@ -307,7 +307,6 @@ static int __init qe_add_gpiochips(void)
307 int ret; 307 int ret;
308 struct qe_gpio_chip *qe_gc; 308 struct qe_gpio_chip *qe_gc;
309 struct of_mm_gpio_chip *mm_gc; 309 struct of_mm_gpio_chip *mm_gc;
310 struct of_gpio_chip *of_gc;
311 struct gpio_chip *gc; 310 struct gpio_chip *gc;
312 311
313 qe_gc = kzalloc(sizeof(*qe_gc), GFP_KERNEL); 312 qe_gc = kzalloc(sizeof(*qe_gc), GFP_KERNEL);
@@ -319,11 +318,10 @@ static int __init qe_add_gpiochips(void)
319 spin_lock_init(&qe_gc->lock); 318 spin_lock_init(&qe_gc->lock);
320 319
321 mm_gc = &qe_gc->mm_gc; 320 mm_gc = &qe_gc->mm_gc;
322 of_gc = &mm_gc->of_gc; 321 gc = &mm_gc->gc;
323 gc = &of_gc->gc;
324 322
325 mm_gc->save_regs = qe_gpio_save_regs; 323 mm_gc->save_regs = qe_gpio_save_regs;
326 of_gc->gpio_cells = 2; 324 gc->of_gpio_n_cells = 2;
327 gc->ngpio = QE_PIO_PINS; 325 gc->ngpio = QE_PIO_PINS;
328 gc->direction_input = qe_gpio_dir_in; 326 gc->direction_input = qe_gpio_dir_in;
329 gc->direction_output = qe_gpio_dir_out; 327 gc->direction_output = qe_gpio_dir_out;
diff --git a/arch/powerpc/sysdev/simple_gpio.c b/arch/powerpc/sysdev/simple_gpio.c
index d5fb173e588..b7559aa0c16 100644
--- a/arch/powerpc/sysdev/simple_gpio.c
+++ b/arch/powerpc/sysdev/simple_gpio.c
@@ -91,7 +91,6 @@ static int __init u8_simple_gpiochip_add(struct device_node *np)
91 int ret; 91 int ret;
92 struct u8_gpio_chip *u8_gc; 92 struct u8_gpio_chip *u8_gc;
93 struct of_mm_gpio_chip *mm_gc; 93 struct of_mm_gpio_chip *mm_gc;
94 struct of_gpio_chip *of_gc;
95 struct gpio_chip *gc; 94 struct gpio_chip *gc;
96 95
97 u8_gc = kzalloc(sizeof(*u8_gc), GFP_KERNEL); 96 u8_gc = kzalloc(sizeof(*u8_gc), GFP_KERNEL);
@@ -101,11 +100,10 @@ static int __init u8_simple_gpiochip_add(struct device_node *np)
101 spin_lock_init(&u8_gc->lock); 100 spin_lock_init(&u8_gc->lock);
102 101
103 mm_gc = &u8_gc->mm_gc; 102 mm_gc = &u8_gc->mm_gc;
104 of_gc = &mm_gc->of_gc; 103 gc = &mm_gc->gc;
105 gc = &of_gc->gc;
106 104
107 mm_gc->save_regs = u8_gpio_save_regs; 105 mm_gc->save_regs = u8_gpio_save_regs;
108 of_gc->gpio_cells = 2; 106 gc->of_gpio_n_cells = 2;
109 gc->ngpio = 8; 107 gc->ngpio = 8;
110 gc->direction_input = u8_gpio_dir_in; 108 gc->direction_input = u8_gpio_dir_in;
111 gc->direction_output = u8_gpio_dir_out; 109 gc->direction_output = u8_gpio_dir_out;
diff --git a/drivers/gpio/xilinx_gpio.c b/drivers/gpio/xilinx_gpio.c
index b8fa65b5bfc..2993c40b48e 100644
--- a/drivers/gpio/xilinx_gpio.c
+++ b/drivers/gpio/xilinx_gpio.c
@@ -161,14 +161,12 @@ static void xgpio_save_regs(struct of_mm_gpio_chip *mm_gc)
161static int __devinit xgpio_of_probe(struct device_node *np) 161static int __devinit xgpio_of_probe(struct device_node *np)
162{ 162{
163 struct xgpio_instance *chip; 163 struct xgpio_instance *chip;
164 struct of_gpio_chip *ofchip;
165 int status = 0; 164 int status = 0;
166 const u32 *tree_info; 165 const u32 *tree_info;
167 166
168 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 167 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
169 if (!chip) 168 if (!chip)
170 return -ENOMEM; 169 return -ENOMEM;
171 ofchip = &chip->mmchip.of_gc;
172 170
173 /* Update GPIO state shadow register with default value */ 171 /* Update GPIO state shadow register with default value */
174 tree_info = of_get_property(np, "xlnx,dout-default", NULL); 172 tree_info = of_get_property(np, "xlnx,dout-default", NULL);
@@ -182,21 +180,21 @@ static int __devinit xgpio_of_probe(struct device_node *np)
182 chip->gpio_dir = *tree_info; 180 chip->gpio_dir = *tree_info;
183 181
184 /* Check device node and parent device node for device width */ 182 /* Check device node and parent device node for device width */
185 ofchip->gc.ngpio = 32; /* By default assume full GPIO controller */ 183 chip->mmchip.gc.ngpio = 32; /* By default assume full GPIO controller */
186 tree_info = of_get_property(np, "xlnx,gpio-width", NULL); 184 tree_info = of_get_property(np, "xlnx,gpio-width", NULL);
187 if (!tree_info) 185 if (!tree_info)
188 tree_info = of_get_property(np->parent, 186 tree_info = of_get_property(np->parent,
189 "xlnx,gpio-width", NULL); 187 "xlnx,gpio-width", NULL);
190 if (tree_info) 188 if (tree_info)
191 ofchip->gc.ngpio = *tree_info; 189 chip->mmchip.gc.ngpio = *tree_info;
192 190
193 spin_lock_init(&chip->gpio_lock); 191 spin_lock_init(&chip->gpio_lock);
194 192
195 ofchip->gpio_cells = 2; 193 chip->mmchip.gc.of_gpio_n_cells = 2;
196 ofchip->gc.direction_input = xgpio_dir_in; 194 chip->mmchip.gc.direction_input = xgpio_dir_in;
197 ofchip->gc.direction_output = xgpio_dir_out; 195 chip->mmchip.gc.direction_output = xgpio_dir_out;
198 ofchip->gc.get = xgpio_get; 196 chip->mmchip.gc.get = xgpio_get;
199 ofchip->gc.set = xgpio_set; 197 chip->mmchip.gc.set = xgpio_set;
200 198
201 chip->mmchip.save_regs = xgpio_save_regs; 199 chip->mmchip.save_regs = xgpio_save_regs;
202 200
diff --git a/drivers/of/gpio.c b/drivers/of/gpio.c
index a1b31a4abae..fde53a3a45a 100644
--- a/drivers/of/gpio.c
+++ b/drivers/of/gpio.c
@@ -33,32 +33,32 @@ int of_get_gpio_flags(struct device_node *np, int index,
33 enum of_gpio_flags *flags) 33 enum of_gpio_flags *flags)
34{ 34{
35 int ret; 35 int ret;
36 struct device_node *gc; 36 struct device_node *gpio_np;
37 struct of_gpio_chip *of_gc = NULL; 37 struct gpio_chip *gc;
38 int size; 38 int size;
39 const void *gpio_spec; 39 const void *gpio_spec;
40 const __be32 *gpio_cells; 40 const __be32 *gpio_cells;
41 41
42 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index, 42 ret = of_parse_phandles_with_args(np, "gpios", "#gpio-cells", index,
43 &gc, &gpio_spec); 43 &gpio_np, &gpio_spec);
44 if (ret) { 44 if (ret) {
45 pr_debug("%s: can't parse gpios property\n", __func__); 45 pr_debug("%s: can't parse gpios property\n", __func__);
46 goto err0; 46 goto err0;
47 } 47 }
48 48
49 of_gc = gc->data; 49 gc = gpio_np->data;
50 if (!of_gc) { 50 if (!gc) {
51 pr_debug("%s: gpio controller %s isn't registered\n", 51 pr_debug("%s: gpio controller %s isn't registered\n",
52 np->full_name, gc->full_name); 52 np->full_name, gpio_np->full_name);
53 ret = -ENODEV; 53 ret = -ENODEV;
54 goto err1; 54 goto err1;
55 } 55 }
56 56
57 gpio_cells = of_get_property(gc, "#gpio-cells", &size); 57 gpio_cells = of_get_property(gpio_np, "#gpio-cells", &size);
58 if (!gpio_cells || size != sizeof(*gpio_cells) || 58 if (!gpio_cells || size != sizeof(*gpio_cells) ||
59 be32_to_cpup(gpio_cells) != of_gc->gpio_cells) { 59 be32_to_cpup(gpio_cells) != gc->of_gpio_n_cells) {
60 pr_debug("%s: wrong #gpio-cells for %s\n", 60 pr_debug("%s: wrong #gpio-cells for %s\n",
61 np->full_name, gc->full_name); 61 np->full_name, gpio_np->full_name);
62 ret = -EINVAL; 62 ret = -EINVAL;
63 goto err1; 63 goto err1;
64 } 64 }
@@ -67,13 +67,13 @@ int of_get_gpio_flags(struct device_node *np, int index,
67 if (flags) 67 if (flags)
68 *flags = 0; 68 *flags = 0;
69 69
70 ret = of_gc->xlate(of_gc, np, gpio_spec, flags); 70 ret = gc->of_xlate(gc, np, gpio_spec, flags);
71 if (ret < 0) 71 if (ret < 0)
72 goto err1; 72 goto err1;
73 73
74 ret += of_gc->gc.base; 74 ret += gc->base;
75err1: 75err1:
76 of_node_put(gc); 76 of_node_put(gpio_np);
77err0: 77err0:
78 pr_debug("%s exited with status %d\n", __func__, ret); 78 pr_debug("%s exited with status %d\n", __func__, ret);
79 return ret; 79 return ret;
@@ -116,7 +116,7 @@ EXPORT_SYMBOL(of_gpio_count);
116 116
117/** 117/**
118 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags 118 * of_gpio_simple_xlate - translate gpio_spec to the GPIO number and flags
119 * @of_gc: pointer to the of_gpio_chip structure 119 * @gc: pointer to the gpio_chip structure
120 * @np: device node of the GPIO chip 120 * @np: device node of the GPIO chip
121 * @gpio_spec: gpio specifier as found in the device tree 121 * @gpio_spec: gpio specifier as found in the device tree
122 * @flags: a flags pointer to fill in 122 * @flags: a flags pointer to fill in
@@ -125,8 +125,8 @@ EXPORT_SYMBOL(of_gpio_count);
125 * gpio chips. This function performs only one sanity check: whether gpio 125 * gpio chips. This function performs only one sanity check: whether gpio
126 * is less than ngpios (that is specified in the gpio_chip). 126 * is less than ngpios (that is specified in the gpio_chip).
127 */ 127 */
128int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np, 128int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
129 const void *gpio_spec, enum of_gpio_flags *flags) 129 const void *gpio_spec, u32 *flags)
130{ 130{
131 const __be32 *gpio = gpio_spec; 131 const __be32 *gpio = gpio_spec;
132 const u32 n = be32_to_cpup(gpio); 132 const u32 n = be32_to_cpup(gpio);
@@ -137,12 +137,12 @@ int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, struct device_node *np,
137 * number and the flags from a single gpio cell -- this is possible, 137 * number and the flags from a single gpio cell -- this is possible,
138 * but not recommended). 138 * but not recommended).
139 */ 139 */
140 if (of_gc->gpio_cells < 2) { 140 if (gc->of_gpio_n_cells < 2) {
141 WARN_ON(1); 141 WARN_ON(1);
142 return -EINVAL; 142 return -EINVAL;
143 } 143 }
144 144
145 if (n > of_gc->gc.ngpio) 145 if (n > gc->ngpio)
146 return -EINVAL; 146 return -EINVAL;
147 147
148 if (flags) 148 if (flags)
@@ -161,10 +161,8 @@ EXPORT_SYMBOL(of_gpio_simple_xlate);
161 * 161 *
162 * 1) In the gpio_chip structure: 162 * 1) In the gpio_chip structure:
163 * - all the callbacks 163 * - all the callbacks
164 * 164 * - of_gpio_n_cells
165 * 2) In the of_gpio_chip structure: 165 * - of_xlate callback (optional)
166 * - gpio_cells
167 * - xlate callback (optional)
168 * 166 *
169 * 3) In the of_mm_gpio_chip structure: 167 * 3) In the of_mm_gpio_chip structure:
170 * - save_regs callback (optional) 168 * - save_regs callback (optional)
@@ -177,8 +175,7 @@ int of_mm_gpiochip_add(struct device_node *np,
177 struct of_mm_gpio_chip *mm_gc) 175 struct of_mm_gpio_chip *mm_gc)
178{ 176{
179 int ret = -ENOMEM; 177 int ret = -ENOMEM;
180 struct of_gpio_chip *of_gc = &mm_gc->of_gc; 178 struct gpio_chip *gc = &mm_gc->gc;
181 struct gpio_chip *gc = &of_gc->gc;
182 179
183 gc->label = kstrdup(np->full_name, GFP_KERNEL); 180 gc->label = kstrdup(np->full_name, GFP_KERNEL);
184 if (!gc->label) 181 if (!gc->label)
@@ -190,13 +187,14 @@ int of_mm_gpiochip_add(struct device_node *np,
190 187
191 gc->base = -1; 188 gc->base = -1;
192 189
193 if (!of_gc->xlate) 190 if (!gc->of_xlate)
194 of_gc->xlate = of_gpio_simple_xlate; 191 gc->of_xlate = of_gpio_simple_xlate;
195 192
196 if (mm_gc->save_regs) 193 if (mm_gc->save_regs)
197 mm_gc->save_regs(mm_gc); 194 mm_gc->save_regs(mm_gc);
198 195
199 np->data = of_gc; 196 np->data = &mm_gc->gc;
197 mm_gc->gc.of_node = np;
200 198
201 ret = gpiochip_add(gc); 199 ret = gpiochip_add(gc);
202 if (ret) 200 if (ret)
diff --git a/include/asm-generic/gpio.h b/include/asm-generic/gpio.h
index 4f3d75e1ad3..af2544ef0b5 100644
--- a/include/asm-generic/gpio.h
+++ b/include/asm-generic/gpio.h
@@ -31,6 +31,7 @@ static inline int gpio_is_valid(int number)
31struct device; 31struct device;
32struct seq_file; 32struct seq_file;
33struct module; 33struct module;
34struct device_node;
34 35
35/** 36/**
36 * struct gpio_chip - abstract a GPIO controller 37 * struct gpio_chip - abstract a GPIO controller
@@ -106,6 +107,17 @@ struct gpio_chip {
106 const char *const *names; 107 const char *const *names;
107 unsigned can_sleep:1; 108 unsigned can_sleep:1;
108 unsigned exported:1; 109 unsigned exported:1;
110
111#if defined(CONFIG_OF_GPIO)
112 /*
113 * If CONFIG_OF is enabled, then all GPIO controllers described in the
114 * device tree automatically may have an OF translation
115 */
116 struct device_node *of_node;
117 int of_gpio_n_cells;
118 int (*of_xlate)(struct gpio_chip *gc, struct device_node *np,
119 const void *gpio_spec, u32 *flags);
120#endif
109}; 121};
110 122
111extern const char *gpiochip_is_requested(struct gpio_chip *chip, 123extern const char *gpiochip_is_requested(struct gpio_chip *chip,
diff --git a/include/linux/of_gpio.h b/include/linux/of_gpio.h
index fc2472c3c25..460d6810c5e 100644
--- a/include/linux/of_gpio.h
+++ b/include/linux/of_gpio.h
@@ -33,34 +33,17 @@ enum of_gpio_flags {
33#ifdef CONFIG_OF_GPIO 33#ifdef CONFIG_OF_GPIO
34 34
35/* 35/*
36 * Generic OF GPIO chip
37 */
38struct of_gpio_chip {
39 struct gpio_chip gc;
40 int gpio_cells;
41 int (*xlate)(struct of_gpio_chip *of_gc, struct device_node *np,
42 const void *gpio_spec, enum of_gpio_flags *flags);
43};
44
45static inline struct of_gpio_chip *to_of_gpio_chip(struct gpio_chip *gc)
46{
47 return container_of(gc, struct of_gpio_chip, gc);
48}
49
50/*
51 * OF GPIO chip for memory mapped banks 36 * OF GPIO chip for memory mapped banks
52 */ 37 */
53struct of_mm_gpio_chip { 38struct of_mm_gpio_chip {
54 struct of_gpio_chip of_gc; 39 struct gpio_chip gc;
55 void (*save_regs)(struct of_mm_gpio_chip *mm_gc); 40 void (*save_regs)(struct of_mm_gpio_chip *mm_gc);
56 void __iomem *regs; 41 void __iomem *regs;
57}; 42};
58 43
59static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc) 44static inline struct of_mm_gpio_chip *to_of_mm_gpio_chip(struct gpio_chip *gc)
60{ 45{
61 struct of_gpio_chip *of_gc = to_of_gpio_chip(gc); 46 return container_of(gc, struct of_mm_gpio_chip, gc);
62
63 return container_of(of_gc, struct of_mm_gpio_chip, of_gc);
64} 47}
65 48
66extern int of_get_gpio_flags(struct device_node *np, int index, 49extern int of_get_gpio_flags(struct device_node *np, int index,
@@ -69,11 +52,9 @@ extern unsigned int of_gpio_count(struct device_node *np);
69 52
70extern int of_mm_gpiochip_add(struct device_node *np, 53extern int of_mm_gpiochip_add(struct device_node *np,
71 struct of_mm_gpio_chip *mm_gc); 54 struct of_mm_gpio_chip *mm_gc);
72extern int of_gpio_simple_xlate(struct of_gpio_chip *of_gc, 55extern int of_gpio_simple_xlate(struct gpio_chip *gc, struct device_node *np,
73 struct device_node *np, 56 const void *gpio_spec, u32 *flags);
74 const void *gpio_spec, 57#else /* CONFIG_OF_GPIO */
75 enum of_gpio_flags *flags);
76#else
77 58
78/* Drivers may not strictly depend on the GPIO support, so let them link. */ 59/* Drivers may not strictly depend on the GPIO support, so let them link. */
79static inline int of_get_gpio_flags(struct device_node *np, int index, 60static inline int of_get_gpio_flags(struct device_node *np, int index,