Skip to content

Commit a19e3da

Browse files
Anton Vorontsovglikely
authored andcommitted
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>
1 parent cedb188 commit a19e3da

15 files changed

Lines changed: 129 additions & 158 deletions

File tree

‎arch/microblaze/kernel/reset.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ static int of_reset_gpio_handle(void)
2424
int ret; /* variable which stored handle reset gpio pin */
2525
struct device_node *root; /* root node */
2626
struct device_node *gpio; /* gpio node */
27-
struct of_gpio_chip *of_gc = NULL;
28-
enum of_gpio_flags flags ;
27+
struct gpio_chip *gc;
28+
u32 flags;
2929
const void *gpio_spec;
3030

3131
/* find out root node */
@@ -39,19 +39,19 @@ static int of_reset_gpio_handle(void)
3939
goto err0;
4040
}
4141

42-
of_gc = gpio->data;
43-
if (!of_gc) {
42+
gc = gpio->data;
43+
if (!gc) {
4444
pr_debug("%s: gpio controller %s isn't registered\n",
4545
root->full_name, gpio->full_name);
4646
ret = -ENODEV;
4747
goto err1;
4848
}
4949

50-
ret = of_gc->xlate(of_gc, root, gpio_spec, &flags);
50+
ret = gc->of_xlate(gc, root, gpio_spec, &flags);
5151
if (ret < 0)
5252
goto err1;
5353

54-
ret += of_gc->gc.base;
54+
ret += gc->base;
5555
err1:
5656
of_node_put(gpio);
5757
err0:

‎arch/powerpc/platforms/52xx/mpc52xx_gpio.c‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -152,21 +152,21 @@ static int __devinit mpc52xx_wkup_gpiochip_probe(struct of_device *ofdev,
152152
{
153153
struct mpc52xx_gpiochip *chip;
154154
struct mpc52xx_gpio_wkup __iomem *regs;
155-
struct of_gpio_chip *ofchip;
155+
struct gpio_chip *gc;
156156
int ret;
157157

158158
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
159159
if (!chip)
160160
return -ENOMEM;
161161

162-
ofchip = &chip->mmchip.of_gc;
162+
gc = &chip->mmchip.gc;
163163

164-
ofchip->gpio_cells = 2;
165-
ofchip->gc.ngpio = 8;
166-
ofchip->gc.direction_input = mpc52xx_wkup_gpio_dir_in;
167-
ofchip->gc.direction_output = mpc52xx_wkup_gpio_dir_out;
168-
ofchip->gc.get = mpc52xx_wkup_gpio_get;
169-
ofchip->gc.set = mpc52xx_wkup_gpio_set;
164+
gc->of_gpio_n_cells = 2;
165+
gc->ngpio = 8;
166+
gc->direction_input = mpc52xx_wkup_gpio_dir_in;
167+
gc->direction_output = mpc52xx_wkup_gpio_dir_out;
168+
gc->get = mpc52xx_wkup_gpio_get;
169+
gc->set = mpc52xx_wkup_gpio_set;
170170

171171
ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
172172
if (ret)
@@ -315,22 +315,22 @@ static int __devinit mpc52xx_simple_gpiochip_probe(struct of_device *ofdev,
315315
const struct of_device_id *match)
316316
{
317317
struct mpc52xx_gpiochip *chip;
318-
struct of_gpio_chip *ofchip;
318+
struct gpio_chip *gc;
319319
struct mpc52xx_gpio __iomem *regs;
320320
int ret;
321321

322322
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
323323
if (!chip)
324324
return -ENOMEM;
325325

326-
ofchip = &chip->mmchip.of_gc;
326+
gc = &chip->mmchip.gc;
327327

328-
ofchip->gpio_cells = 2;
329-
ofchip->gc.ngpio = 32;
330-
ofchip->gc.direction_input = mpc52xx_simple_gpio_dir_in;
331-
ofchip->gc.direction_output = mpc52xx_simple_gpio_dir_out;
332-
ofchip->gc.get = mpc52xx_simple_gpio_get;
333-
ofchip->gc.set = mpc52xx_simple_gpio_set;
328+
gc->of_gpio_n_cells = 2;
329+
gc->ngpio = 32;
330+
gc->direction_input = mpc52xx_simple_gpio_dir_in;
331+
gc->direction_output = mpc52xx_simple_gpio_dir_out;
332+
gc->get = mpc52xx_simple_gpio_get;
333+
gc->set = mpc52xx_simple_gpio_set;
334334

335335
ret = of_mm_gpiochip_add(ofdev->dev.of_node, &chip->mmchip);
336336
if (ret)

‎arch/powerpc/platforms/52xx/mpc52xx_gpt.c‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ MODULE_LICENSE("GPL");
7878
* @dev: pointer to device structure
7979
* @regs: virtual address of GPT registers
8080
* @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
8282
* @irqhost: Pointer to irq_host instance; used when IRQ mode is supported
8383
* @wdt_mode: only relevant for gpt0: bit 0 (MPC52xx_GPT_CAN_WDT) indicates
8484
* if the gpt may be used as wdt, bit 1 (MPC52xx_GPT_IS_WDT) indicates
@@ -94,7 +94,7 @@ struct mpc52xx_gpt_priv {
9494
u8 wdt_mode;
9595

9696
#if defined(CONFIG_GPIOLIB)
97-
struct of_gpio_chip of_gc;
97+
struct gpio_chip gc;
9898
#endif
9999
};
100100

@@ -280,7 +280,7 @@ mpc52xx_gpt_irq_setup(struct mpc52xx_gpt_priv *gpt, struct device_node *node)
280280
#if defined(CONFIG_GPIOLIB)
281281
static inline struct mpc52xx_gpt_priv *gc_to_mpc52xx_gpt(struct gpio_chip *gc)
282282
{
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);
284284
}
285285

286286
static 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)
336336
if (!of_find_property(node, "gpio-controller", NULL))
337337
return;
338338

339-
gpt->of_gc.gc.label = kstrdup(node->full_name, GFP_KERNEL);
340-
if (!gpt->of_gc.gc.label) {
339+
gpt->gc.label = kstrdup(node->full_name, GFP_KERNEL);
340+
if (!gpt->gc.label) {
341341
dev_err(gpt->dev, "out of memory\n");
342342
return;
343343
}
344344

345-
gpt->of_gc.gpio_cells = 2;
346-
gpt->of_gc.gc.ngpio = 1;
347-
gpt->of_gc.gc.direction_input = mpc52xx_gpt_gpio_dir_in;
348-
gpt->of_gc.gc.direction_output = mpc52xx_gpt_gpio_dir_out;
349-
gpt->of_gc.gc.get = mpc52xx_gpt_gpio_get;
350-
gpt->of_gc.gc.set = mpc52xx_gpt_gpio_set;
351-
gpt->of_gc.gc.base = -1;
352-
gpt->of_gc.xlate = of_gpio_simple_xlate;
353-
node->data = &gpt->of_gc;
345+
gpt->gc.ngpio = 1;
346+
gpt->gc.direction_input = mpc52xx_gpt_gpio_dir_in;
347+
gpt->gc.direction_output = mpc52xx_gpt_gpio_dir_out;
348+
gpt->gc.get = mpc52xx_gpt_gpio_get;
349+
gpt->gc.set = mpc52xx_gpt_gpio_set;
350+
gpt->gc.base = -1;
351+
gpt->gc.of_gpio_n_cells = 2;
352+
gpt->gc.of_xlate = of_gpio_simple_xlate;
354353
of_node_get(node);
355354

356355
/* Setup external pin in GPIO mode */
357356
clrsetbits_be32(&gpt->regs->mode, MPC52xx_GPT_MODE_MS_MASK,
358357
MPC52xx_GPT_MODE_MS_GPIO);
359358

360-
rc = gpiochip_add(&gpt->of_gc.gc);
359+
rc = gpiochip_add(&gpt->gc);
361360
if (rc)
362361
dev_err(gpt->dev, "gpiochip_add() failed; rc=%i\n", rc);
363362

‎arch/powerpc/platforms/83xx/mcu_mpc8349emitx.c‎

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct mcu {
3737
struct mutex lock;
3838
struct device_node *np;
3939
struct i2c_client *client;
40-
struct of_gpio_chip of_gc;
40+
struct gpio_chip gc;
4141
u8 reg_ctrl;
4242
};
4343

@@ -56,8 +56,7 @@ static void mcu_power_off(void)
5656

5757
static void mcu_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
5858
{
59-
struct of_gpio_chip *of_gc = to_of_gpio_chip(gc);
60-
struct mcu *mcu = container_of(of_gc, struct mcu, of_gc);
59+
struct mcu *mcu = container_of(gc, struct mcu, gc);
6160
u8 bit = 1 << (4 + gpio);
6261

6362
mutex_lock(&mcu->lock);
@@ -79,8 +78,7 @@ static int mcu_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
7978
static int mcu_gpiochip_add(struct mcu *mcu)
8079
{
8180
struct device_node *np;
82-
struct of_gpio_chip *of_gc = &mcu->of_gc;
83-
struct gpio_chip *gc = &of_gc->gc;
81+
struct gpio_chip *gc = &mcu->gc;
8482
int ret;
8583

8684
np = of_find_compatible_node(NULL, NULL, "fsl,mcu-mpc8349emitx");
@@ -94,10 +92,9 @@ static int mcu_gpiochip_add(struct mcu *mcu)
9492
gc->base = -1;
9593
gc->set = mcu_gpio_set;
9694
gc->direction_output = mcu_gpio_dir_out;
97-
of_gc->gpio_cells = 2;
98-
of_gc->xlate = of_gpio_simple_xlate;
95+
gc->of_gpio_n_cells = 2;
96+
gc->of_xlate = of_gpio_simple_xlate;
9997

100-
np->data = of_gc;
10198
mcu->np = np;
10299

103100
/*
@@ -114,7 +111,7 @@ static int mcu_gpiochip_remove(struct mcu *mcu)
114111
{
115112
int ret;
116113

117-
ret = gpiochip_remove(&mcu->of_gc.gc);
114+
ret = gpiochip_remove(&mcu->gc);
118115
if (ret)
119116
return ret;
120117
of_node_put(mcu->np);

‎arch/powerpc/platforms/86xx/gef_gpio.c‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,12 +118,12 @@ static int __init gef_gpio_init(void)
118118
}
119119

120120
/* Setup pointers to chip functions */
121-
gef_gpio_chip->of_gc.gpio_cells = 2;
122-
gef_gpio_chip->of_gc.gc.ngpio = 19;
123-
gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in;
124-
gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out;
125-
gef_gpio_chip->of_gc.gc.get = gef_gpio_get;
126-
gef_gpio_chip->of_gc.gc.set = gef_gpio_set;
121+
gef_gpio_chip->gc.of_gpio_n_cells = 2;
122+
gef_gpio_chip->gc.ngpio = 19;
123+
gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
124+
gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
125+
gef_gpio_chip->gc.get = gef_gpio_get;
126+
gef_gpio_chip->gc.set = gef_gpio_set;
127127

128128
/* This function adds a memory mapped GPIO chip */
129129
retval = of_mm_gpiochip_add(np, gef_gpio_chip);
@@ -146,12 +146,12 @@ static int __init gef_gpio_init(void)
146146
}
147147

148148
/* Setup pointers to chip functions */
149-
gef_gpio_chip->of_gc.gpio_cells = 2;
150-
gef_gpio_chip->of_gc.gc.ngpio = 6;
151-
gef_gpio_chip->of_gc.gc.direction_input = gef_gpio_dir_in;
152-
gef_gpio_chip->of_gc.gc.direction_output = gef_gpio_dir_out;
153-
gef_gpio_chip->of_gc.gc.get = gef_gpio_get;
154-
gef_gpio_chip->of_gc.gc.set = gef_gpio_set;
149+
gef_gpio_chip->gc.of_gpio_n_cells = 2;
150+
gef_gpio_chip->gc.ngpio = 6;
151+
gef_gpio_chip->gc.direction_input = gef_gpio_dir_in;
152+
gef_gpio_chip->gc.direction_output = gef_gpio_dir_out;
153+
gef_gpio_chip->gc.get = gef_gpio_get;
154+
gef_gpio_chip->gc.set = gef_gpio_set;
155155

156156
/* This function adds a memory mapped GPIO chip */
157157
retval = of_mm_gpiochip_add(np, gef_gpio_chip);

‎arch/powerpc/sysdev/cpm1.c‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,6 @@ int cpm1_gpiochip_add16(struct device_node *np)
621621
{
622622
struct cpm1_gpio16_chip *cpm1_gc;
623623
struct of_mm_gpio_chip *mm_gc;
624-
struct of_gpio_chip *of_gc;
625624
struct gpio_chip *gc;
626625

627626
cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL);
@@ -631,11 +630,10 @@ int cpm1_gpiochip_add16(struct device_node *np)
631630
spin_lock_init(&cpm1_gc->lock);
632631

633632
mm_gc = &cpm1_gc->mm_gc;
634-
of_gc = &mm_gc->of_gc;
635-
gc = &of_gc->gc;
633+
gc = &mm_gc->gc;
636634

637635
mm_gc->save_regs = cpm1_gpio16_save_regs;
638-
of_gc->gpio_cells = 2;
636+
gc->of_gpio_n_cells = 2;
639637
gc->ngpio = 16;
640638
gc->direction_input = cpm1_gpio16_dir_in;
641639
gc->direction_output = cpm1_gpio16_dir_out;
@@ -745,7 +743,6 @@ int cpm1_gpiochip_add32(struct device_node *np)
745743
{
746744
struct cpm1_gpio32_chip *cpm1_gc;
747745
struct of_mm_gpio_chip *mm_gc;
748-
struct of_gpio_chip *of_gc;
749746
struct gpio_chip *gc;
750747

751748
cpm1_gc = kzalloc(sizeof(*cpm1_gc), GFP_KERNEL);
@@ -755,11 +752,10 @@ int cpm1_gpiochip_add32(struct device_node *np)
755752
spin_lock_init(&cpm1_gc->lock);
756753

757754
mm_gc = &cpm1_gc->mm_gc;
758-
of_gc = &mm_gc->of_gc;
759-
gc = &of_gc->gc;
755+
gc = &mm_gc->gc;
760756

761757
mm_gc->save_regs = cpm1_gpio32_save_regs;
762-
of_gc->gpio_cells = 2;
758+
gc->of_gpio_n_cells = 2;
763759
gc->ngpio = 32;
764760
gc->direction_input = cpm1_gpio32_dir_in;
765761
gc->direction_output = cpm1_gpio32_dir_out;

‎arch/powerpc/sysdev/cpm_common.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ int cpm2_gpiochip_add32(struct device_node *np)
325325
{
326326
struct cpm2_gpio32_chip *cpm2_gc;
327327
struct of_mm_gpio_chip *mm_gc;
328-
struct of_gpio_chip *of_gc;
329328
struct gpio_chip *gc;
330329

331330
cpm2_gc = kzalloc(sizeof(*cpm2_gc), GFP_KERNEL);
@@ -335,11 +334,10 @@ int cpm2_gpiochip_add32(struct device_node *np)
335334
spin_lock_init(&cpm2_gc->lock);
336335

337336
mm_gc = &cpm2_gc->mm_gc;
338-
of_gc = &mm_gc->of_gc;
339-
gc = &of_gc->gc;
337+
gc = &mm_gc->gc;
340338

341339
mm_gc->save_regs = cpm2_gpio32_save_regs;
342-
of_gc->gpio_cells = 2;
340+
gc->of_gpio_n_cells = 2;
343341
gc->ngpio = 32;
344342
gc->direction_input = cpm2_gpio32_dir_in;
345343
gc->direction_output = cpm2_gpio32_dir_out;

‎arch/powerpc/sysdev/mpc8xxx_gpio.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,6 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
257257
{
258258
struct mpc8xxx_gpio_chip *mpc8xxx_gc;
259259
struct of_mm_gpio_chip *mm_gc;
260-
struct of_gpio_chip *of_gc;
261260
struct gpio_chip *gc;
262261
unsigned hwirq;
263262
int ret;
@@ -271,11 +270,10 @@ static void __init mpc8xxx_add_controller(struct device_node *np)
271270
spin_lock_init(&mpc8xxx_gc->lock);
272271

273272
mm_gc = &mpc8xxx_gc->mm_gc;
274-
of_gc = &mm_gc->of_gc;
275-
gc = &of_gc->gc;
273+
gc = &mm_gc->gc;
276274

277275
mm_gc->save_regs = mpc8xxx_gpio_save_regs;
278-
of_gc->gpio_cells = 2;
276+
gc->of_gpio_n_cells = 2;
279277
gc->ngpio = MPC8XXX_GPIO_PINS;
280278
gc->direction_input = mpc8xxx_gpio_dir_in;
281279
gc->direction_output = mpc8xxx_gpio_dir_out;

‎arch/powerpc/sysdev/ppc4xx_gpio.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ static int __init ppc4xx_add_gpiochips(void)
181181
int ret;
182182
struct ppc4xx_gpio_chip *ppc4xx_gc;
183183
struct of_mm_gpio_chip *mm_gc;
184-
struct of_gpio_chip *of_gc;
185184
struct gpio_chip *gc;
186185

187186
ppc4xx_gc = kzalloc(sizeof(*ppc4xx_gc), GFP_KERNEL);
@@ -193,10 +192,9 @@ static int __init ppc4xx_add_gpiochips(void)
193192
spin_lock_init(&ppc4xx_gc->lock);
194193

195194
mm_gc = &ppc4xx_gc->mm_gc;
196-
of_gc = &mm_gc->of_gc;
197-
gc = &of_gc->gc;
195+
gc = &mm_gc->gc;
198196

199-
of_gc->gpio_cells = 2;
197+
gc->of_gpio_n_cells = 2;
200198
gc->ngpio = 32;
201199
gc->direction_input = ppc4xx_gpio_dir_in;
202200
gc->direction_output = ppc4xx_gpio_dir_out;

0 commit comments

Comments
 (0)