aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2016-02-25 08:22:10 -0500
committerLinus Walleij <linus.walleij@linaro.org>2016-02-25 08:22:10 -0500
commit725e3b7d40dffa10dbe0a24ba70676a3127f79fc (patch)
tree3b4cfc0973de0f6459a5a340c997a78ae1dfcdb1
parentea1361fd5f26f1dbb369f85b3ad42a84c133e7e1 (diff)
parent9d113c696f4081bf95dd7553d6369998a666b0fa (diff)
Merge branch 'devm_gpiochip' of https://github.com/ldewangan/linux-upstream into devm-gpiochip-add-data
-rw-r--r--Documentation/driver-model/devres.txt5
-rw-r--r--README.md2
-rw-r--r--drivers/gpio/gpio-74xx-mmio.c11
-rw-r--r--drivers/gpio/gpio-adnp.c11
-rw-r--r--drivers/gpio/gpio-adp5520.c13
-rw-r--r--drivers/gpio/gpio-adp5588.c4
-rw-r--r--drivers/gpio/gpio-altera.c5
-rw-r--r--drivers/gpio/gpio-arizona.c12
-rw-r--r--drivers/gpio/gpio-bcm-kona.c2
-rw-r--r--drivers/gpio/gpio-clps711x.c11
-rw-r--r--drivers/gpio/gpio-crystalcove.c9
-rw-r--r--drivers/gpio/gpio-cs5535.c20
-rw-r--r--drivers/gpio/gpio-da9052.c11
-rw-r--r--drivers/gpio/gpio-da9055.c16
-rw-r--r--drivers/gpio/gpio-davinci.c7
-rw-r--r--drivers/gpio/gpio-dln2.c16
-rw-r--r--drivers/gpio/gpio-ep93xx.c2
-rw-r--r--drivers/gpio/gpio-f7188x.c26
-rw-r--r--drivers/gpio/gpio-ge.c2
-rw-r--r--drivers/gpio/gpio-generic.c11
-rw-r--r--drivers/gpio/gpio-iop.c2
-rw-r--r--drivers/gpio/gpio-janz-ttl.c12
-rw-r--r--drivers/gpio/gpio-kempld.c11
-rw-r--r--drivers/gpio/gpio-lp3943.c12
-rw-r--r--drivers/gpio/gpio-lpc32xx.c2
-rw-r--r--drivers/gpio/gpio-lynxpoint.c4
-rw-r--r--drivers/gpio/gpio-mc9s08dz60.c13
-rw-r--r--drivers/gpio/gpio-moxart.c2
-rw-r--r--drivers/gpio/gpio-mvebu.c11
-rw-r--r--drivers/gpio/gpio-mxc.c6
-rw-r--r--drivers/gpio/gpio-octeon.c10
-rw-r--r--drivers/gpio/gpio-palmas.c12
-rw-r--r--drivers/gpio/gpio-pca953x.c4
-rw-r--r--drivers/gpio/gpio-pcf857x.c10
-rw-r--r--drivers/gpio/gpio-rc5t583.c12
-rw-r--r--drivers/gpio/gpio-rdc321x.c13
-rw-r--r--drivers/gpio/gpio-sch.c11
-rw-r--r--drivers/gpio/gpio-spear-spics.c2
-rw-r--r--drivers/gpio/gpio-sta2x11.c2
-rw-r--r--drivers/gpio/gpio-stp-xway.c2
-rw-r--r--drivers/gpio/gpio-sx150x.c18
-rw-r--r--drivers/gpio/gpio-syscon.c11
-rw-r--r--drivers/gpio/gpio-tb10x.c22
-rw-r--r--drivers/gpio/gpio-tc3589x.c13
-rw-r--r--drivers/gpio/gpio-tegra.c2
-rw-r--r--drivers/gpio/gpio-timberdale.c4
-rw-r--r--drivers/gpio/gpio-tps6586x.c12
-rw-r--r--drivers/gpio/gpio-tps65910.c12
-rw-r--r--drivers/gpio/gpio-tps65912.c12
-rw-r--r--drivers/gpio/gpio-ts4800.c12
-rw-r--r--drivers/gpio/gpio-ts5500.c9
-rw-r--r--drivers/gpio/gpio-twl6040.c9
-rw-r--r--drivers/gpio/gpio-ucb1400.c3
-rw-r--r--drivers/gpio/gpio-viperboard.c24
-rw-r--r--drivers/gpio/gpio-vx855.c12
-rw-r--r--drivers/gpio/gpio-wm831x.c12
-rw-r--r--drivers/gpio/gpio-wm8350.c12
-rw-r--r--drivers/gpio/gpio-wm8994.c17
-rw-r--r--drivers/gpio/gpio-xgene-sb.c3
-rw-r--r--drivers/gpio/gpio-xgene.c11
-rw-r--r--drivers/gpio/gpiolib.c74
-rw-r--r--include/linux/gpio/driver.h4
62 files changed, 187 insertions, 470 deletions
diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt
index 831a5363f6be..73b98dfbcea4 100644
--- a/Documentation/driver-model/devres.txt
+++ b/Documentation/driver-model/devres.txt
@@ -252,6 +252,11 @@ GPIO
252 devm_gpiod_get_index_optional() 252 devm_gpiod_get_index_optional()
253 devm_gpiod_get_optional() 253 devm_gpiod_get_optional()
254 devm_gpiod_put() 254 devm_gpiod_put()
255 devm_gpiochip_add_data()
256 devm_gpiochip_remove()
257 devm_gpio_request()
258 devm_gpio_request_one()
259 devm_gpio_free()
255 260
256IIO 261IIO
257 devm_iio_device_alloc() 262 devm_iio_device_alloc()
diff --git a/README.md b/README.md
new file mode 100644
index 000000000000..1301bb12d52d
--- /dev/null
+++ b/README.md
@@ -0,0 +1,2 @@
1# linux-upstream
2This is for sharing upstreaming activities.
diff --git a/drivers/gpio/gpio-74xx-mmio.c b/drivers/gpio/gpio-74xx-mmio.c
index 372b0e01adc6..0475e8ec96d0 100644
--- a/drivers/gpio/gpio-74xx-mmio.c
+++ b/drivers/gpio/gpio-74xx-mmio.c
@@ -140,15 +140,7 @@ static int mmio_74xx_gpio_probe(struct platform_device *pdev)
140 140
141 platform_set_drvdata(pdev, priv); 141 platform_set_drvdata(pdev, priv);
142 142
143 return gpiochip_add_data(&priv->gc, priv); 143 return devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv);
144}
145
146static int mmio_74xx_gpio_remove(struct platform_device *pdev)
147{
148 struct mmio_74xx_gpio_priv *priv = platform_get_drvdata(pdev);
149
150 gpiochip_remove(&priv->gc);
151 return 0;
152} 144}
153 145
154static struct platform_driver mmio_74xx_gpio_driver = { 146static struct platform_driver mmio_74xx_gpio_driver = {
@@ -157,7 +149,6 @@ static struct platform_driver mmio_74xx_gpio_driver = {
157 .of_match_table = mmio_74xx_gpio_ids, 149 .of_match_table = mmio_74xx_gpio_ids,
158 }, 150 },
159 .probe = mmio_74xx_gpio_probe, 151 .probe = mmio_74xx_gpio_probe,
160 .remove = mmio_74xx_gpio_remove,
161}; 152};
162module_platform_driver(mmio_74xx_gpio_driver); 153module_platform_driver(mmio_74xx_gpio_driver);
163 154
diff --git a/drivers/gpio/gpio-adnp.c b/drivers/gpio/gpio-adnp.c
index fb5b47b69f14..8ff7b0d3eac6 100644
--- a/drivers/gpio/gpio-adnp.c
+++ b/drivers/gpio/gpio-adnp.c
@@ -265,7 +265,7 @@ static int adnp_gpio_setup(struct adnp *adnp, unsigned int num_gpios)
265 chip->of_node = chip->parent->of_node; 265 chip->of_node = chip->parent->of_node;
266 chip->owner = THIS_MODULE; 266 chip->owner = THIS_MODULE;
267 267
268 err = gpiochip_add_data(chip, adnp); 268 err = devm_gpiochip_add_data(&adnp->client->dev, chip, adnp);
269 if (err) 269 if (err)
270 return err; 270 return err;
271 271
@@ -520,14 +520,6 @@ static int adnp_i2c_probe(struct i2c_client *client,
520 return 0; 520 return 0;
521} 521}
522 522
523static int adnp_i2c_remove(struct i2c_client *client)
524{
525 struct adnp *adnp = i2c_get_clientdata(client);
526
527 gpiochip_remove(&adnp->gpio);
528 return 0;
529}
530
531static const struct i2c_device_id adnp_i2c_id[] = { 523static const struct i2c_device_id adnp_i2c_id[] = {
532 { "gpio-adnp" }, 524 { "gpio-adnp" },
533 { }, 525 { },
@@ -546,7 +538,6 @@ static struct i2c_driver adnp_i2c_driver = {
546 .of_match_table = adnp_of_match, 538 .of_match_table = adnp_of_match,
547 }, 539 },
548 .probe = adnp_i2c_probe, 540 .probe = adnp_i2c_probe,
549 .remove = adnp_i2c_remove,
550 .id_table = adnp_i2c_id, 541 .id_table = adnp_i2c_id,
551}; 542};
552module_i2c_driver(adnp_i2c_driver); 543module_i2c_driver(adnp_i2c_driver);
diff --git a/drivers/gpio/gpio-adp5520.c b/drivers/gpio/gpio-adp5520.c
index 4fa7ff1fec9a..abf199609546 100644
--- a/drivers/gpio/gpio-adp5520.c
+++ b/drivers/gpio/gpio-adp5520.c
@@ -153,7 +153,7 @@ static int adp5520_gpio_probe(struct platform_device *pdev)
153 goto err; 153 goto err;
154 } 154 }
155 155
156 ret = gpiochip_add_data(&dev->gpio_chip, dev); 156 ret = devm_gpiochip_add_data(&pdev->dev, &dev->gpio_chip, dev);
157 if (ret) 157 if (ret)
158 goto err; 158 goto err;
159 159
@@ -164,22 +164,11 @@ err:
164 return ret; 164 return ret;
165} 165}
166 166
167static int adp5520_gpio_remove(struct platform_device *pdev)
168{
169 struct adp5520_gpio *dev;
170
171 dev = platform_get_drvdata(pdev);
172 gpiochip_remove(&dev->gpio_chip);
173
174 return 0;
175}
176
177static struct platform_driver adp5520_gpio_driver = { 167static struct platform_driver adp5520_gpio_driver = {
178 .driver = { 168 .driver = {
179 .name = "adp5520-gpio", 169 .name = "adp5520-gpio",
180 }, 170 },
181 .probe = adp5520_gpio_probe, 171 .probe = adp5520_gpio_probe,
182 .remove = adp5520_gpio_remove,
183}; 172};
184 173
185module_platform_driver(adp5520_gpio_driver); 174module_platform_driver(adp5520_gpio_driver);
diff --git a/drivers/gpio/gpio-adp5588.c b/drivers/gpio/gpio-adp5588.c
index 19a0eba1e942..c0f718b12317 100644
--- a/drivers/gpio/gpio-adp5588.c
+++ b/drivers/gpio/gpio-adp5588.c
@@ -414,7 +414,7 @@ static int adp5588_gpio_probe(struct i2c_client *client,
414 } 414 }
415 } 415 }
416 416
417 ret = gpiochip_add_data(&dev->gpio_chip, dev); 417 ret = devm_gpiochip_add_data(&client->dev, &dev->gpio_chip, dev);
418 if (ret) 418 if (ret)
419 goto err_irq; 419 goto err_irq;
420 420
@@ -457,8 +457,6 @@ static int adp5588_gpio_remove(struct i2c_client *client)
457 if (dev->irq_base) 457 if (dev->irq_base)
458 free_irq(dev->client->irq, dev); 458 free_irq(dev->client->irq, dev);
459 459
460 gpiochip_remove(&dev->gpio_chip);
461
462 return 0; 460 return 0;
463} 461}
464 462
diff --git a/drivers/gpio/gpio-altera.c b/drivers/gpio/gpio-altera.c
index 2aeaebd1c6e7..3f87a03abc22 100644
--- a/drivers/gpio/gpio-altera.c
+++ b/drivers/gpio/gpio-altera.c
@@ -312,8 +312,8 @@ static int altera_gpio_probe(struct platform_device *pdev)
312 handle_simple_irq, IRQ_TYPE_NONE); 312 handle_simple_irq, IRQ_TYPE_NONE);
313 313
314 if (ret) { 314 if (ret) {
315 dev_info(&pdev->dev, "could not add irqchip\n"); 315 dev_err(&pdev->dev, "could not add irqchip\n");
316 return ret; 316 goto teardown;
317 } 317 }
318 318
319 gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc, 319 gpiochip_set_chained_irqchip(&altera_gc->mmchip.gc,
@@ -326,6 +326,7 @@ static int altera_gpio_probe(struct platform_device *pdev)
326skip_irq: 326skip_irq:
327 return 0; 327 return 0;
328teardown: 328teardown:
329 of_mm_gpiochip_remove(&altera_gc->mmchip);
329 pr_err("%s: registration failed with status %d\n", 330 pr_err("%s: registration failed with status %d\n",
330 node->full_name, ret); 331 node->full_name, ret);
331 332
diff --git a/drivers/gpio/gpio-arizona.c b/drivers/gpio/gpio-arizona.c
index e910c1f41d93..991370494922 100644
--- a/drivers/gpio/gpio-arizona.c
+++ b/drivers/gpio/gpio-arizona.c
@@ -132,7 +132,8 @@ static int arizona_gpio_probe(struct platform_device *pdev)
132 else 132 else
133 arizona_gpio->gpio_chip.base = -1; 133 arizona_gpio->gpio_chip.base = -1;
134 134
135 ret = gpiochip_add_data(&arizona_gpio->gpio_chip, arizona_gpio); 135 ret = devm_gpiochip_add_data(&pdev->dev, &arizona_gpio->gpio_chip,
136 arizona_gpio);
136 if (ret < 0) { 137 if (ret < 0) {
137 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 138 dev_err(&pdev->dev, "Could not register gpiochip, %d\n",
138 ret); 139 ret);
@@ -147,18 +148,9 @@ err:
147 return ret; 148 return ret;
148} 149}
149 150
150static int arizona_gpio_remove(struct platform_device *pdev)
151{
152 struct arizona_gpio *arizona_gpio = platform_get_drvdata(pdev);
153
154 gpiochip_remove(&arizona_gpio->gpio_chip);
155 return 0;
156}
157
158static struct platform_driver arizona_gpio_driver = { 151static struct platform_driver arizona_gpio_driver = {
159 .driver.name = "arizona-gpio", 152 .driver.name = "arizona-gpio",
160 .probe = arizona_gpio_probe, 153 .probe = arizona_gpio_probe,
161 .remove = arizona_gpio_remove,
162}; 154};
163 155
164module_platform_driver(arizona_gpio_driver); 156module_platform_driver(arizona_gpio_driver);
diff --git a/drivers/gpio/gpio-bcm-kona.c b/drivers/gpio/gpio-bcm-kona.c
index b6c5abe85daf..2fd38d598f3d 100644
--- a/drivers/gpio/gpio-bcm-kona.c
+++ b/drivers/gpio/gpio-bcm-kona.c
@@ -630,7 +630,7 @@ static int bcm_kona_gpio_probe(struct platform_device *pdev)
630 630
631 bcm_kona_gpio_reset(kona_gpio); 631 bcm_kona_gpio_reset(kona_gpio);
632 632
633 ret = gpiochip_add_data(chip, kona_gpio); 633 ret = devm_gpiochip_add_data(dev, chip, kona_gpio);
634 if (ret < 0) { 634 if (ret < 0) {
635 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret); 635 dev_err(dev, "Couldn't add GPIO chip -- %d\n", ret);
636 goto err_irq_domain; 636 goto err_irq_domain;
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index c84f9551f108..5a690256af9b 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -67,15 +67,7 @@ static int clps711x_gpio_probe(struct platform_device *pdev)
67 gc->owner = THIS_MODULE; 67 gc->owner = THIS_MODULE;
68 platform_set_drvdata(pdev, gc); 68 platform_set_drvdata(pdev, gc);
69 69
70 return gpiochip_add_data(gc, NULL); 70 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
71}
72
73static int clps711x_gpio_remove(struct platform_device *pdev)
74{
75 struct gpio_chip *gc = platform_get_drvdata(pdev);
76
77 gpiochip_remove(gc);
78 return 0;
79} 71}
80 72
81static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = { 73static const struct of_device_id __maybe_unused clps711x_gpio_ids[] = {
@@ -90,7 +82,6 @@ static struct platform_driver clps711x_gpio_driver = {
90 .of_match_table = of_match_ptr(clps711x_gpio_ids), 82 .of_match_table = of_match_ptr(clps711x_gpio_ids),
91 }, 83 },
92 .probe = clps711x_gpio_probe, 84 .probe = clps711x_gpio_probe,
93 .remove = clps711x_gpio_remove,
94}; 85};
95module_platform_driver(clps711x_gpio_driver); 86module_platform_driver(clps711x_gpio_driver);
96 87
diff --git a/drivers/gpio/gpio-crystalcove.c b/drivers/gpio/gpio-crystalcove.c
index 7865ef0d3352..7c446d118cd6 100644
--- a/drivers/gpio/gpio-crystalcove.c
+++ b/drivers/gpio/gpio-crystalcove.c
@@ -345,7 +345,7 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
345 cg->chip.dbg_show = crystalcove_gpio_dbg_show; 345 cg->chip.dbg_show = crystalcove_gpio_dbg_show;
346 cg->regmap = pmic->regmap; 346 cg->regmap = pmic->regmap;
347 347
348 retval = gpiochip_add_data(&cg->chip, cg); 348 retval = devm_gpiochip_add_data(&pdev->dev, &cg->chip, cg);
349 if (retval) { 349 if (retval) {
350 dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval); 350 dev_warn(&pdev->dev, "add gpio chip error: %d\n", retval);
351 return retval; 351 return retval;
@@ -359,14 +359,10 @@ static int crystalcove_gpio_probe(struct platform_device *pdev)
359 359
360 if (retval) { 360 if (retval) {
361 dev_warn(&pdev->dev, "request irq failed: %d\n", retval); 361 dev_warn(&pdev->dev, "request irq failed: %d\n", retval);
362 goto out_remove_gpio; 362 return retval;
363 } 363 }
364 364
365 return 0; 365 return 0;
366
367out_remove_gpio:
368 gpiochip_remove(&cg->chip);
369 return retval;
370} 366}
371 367
372static int crystalcove_gpio_remove(struct platform_device *pdev) 368static int crystalcove_gpio_remove(struct platform_device *pdev)
@@ -374,7 +370,6 @@ static int crystalcove_gpio_remove(struct platform_device *pdev)
374 struct crystalcove_gpio *cg = platform_get_drvdata(pdev); 370 struct crystalcove_gpio *cg = platform_get_drvdata(pdev);
375 int irq = platform_get_irq(pdev, 0); 371 int irq = platform_get_irq(pdev, 0);
376 372
377 gpiochip_remove(&cg->chip);
378 if (irq >= 0) 373 if (irq >= 0)
379 free_irq(irq, cg); 374 free_irq(irq, cg);
380 return 0; 375 return 0;
diff --git a/drivers/gpio/gpio-cs5535.c b/drivers/gpio/gpio-cs5535.c
index eccb712e09fb..90278b19aa0e 100644
--- a/drivers/gpio/gpio-cs5535.c
+++ b/drivers/gpio/gpio-cs5535.c
@@ -320,13 +320,13 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
320 res = platform_get_resource(pdev, IORESOURCE_IO, 0); 320 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
321 if (!res) { 321 if (!res) {
322 dev_err(&pdev->dev, "can't fetch device resource info\n"); 322 dev_err(&pdev->dev, "can't fetch device resource info\n");
323 goto done; 323 return err;
324 } 324 }
325 325
326 if (!devm_request_region(&pdev->dev, res->start, resource_size(res), 326 if (!devm_request_region(&pdev->dev, res->start, resource_size(res),
327 pdev->name)) { 327 pdev->name)) {
328 dev_err(&pdev->dev, "can't request region\n"); 328 dev_err(&pdev->dev, "can't request region\n");
329 goto done; 329 return err;
330 } 330 }
331 331
332 /* set up the driver-specific struct */ 332 /* set up the driver-specific struct */
@@ -348,19 +348,10 @@ static int cs5535_gpio_probe(struct platform_device *pdev)
348 mask_orig, mask); 348 mask_orig, mask);
349 349
350 /* finally, register with the generic GPIO API */ 350 /* finally, register with the generic GPIO API */
351 err = gpiochip_add_data(&cs5535_gpio_chip.chip, &cs5535_gpio_chip); 351 err = devm_gpiochip_add_data(&pdev->dev, &cs5535_gpio_chip.chip,
352 &cs5535_gpio_chip);
352 if (err) 353 if (err)
353 goto done; 354 return err;
354
355 return 0;
356
357done:
358 return err;
359}
360
361static int cs5535_gpio_remove(struct platform_device *pdev)
362{
363 gpiochip_remove(&cs5535_gpio_chip.chip);
364 355
365 return 0; 356 return 0;
366} 357}
@@ -370,7 +361,6 @@ static struct platform_driver cs5535_gpio_driver = {
370 .name = DRV_NAME, 361 .name = DRV_NAME,
371 }, 362 },
372 .probe = cs5535_gpio_probe, 363 .probe = cs5535_gpio_probe,
373 .remove = cs5535_gpio_remove,
374}; 364};
375 365
376module_platform_driver(cs5535_gpio_driver); 366module_platform_driver(cs5535_gpio_driver);
diff --git a/drivers/gpio/gpio-da9052.c b/drivers/gpio/gpio-da9052.c
index f9b3247ad14b..e29553b7ccdb 100644
--- a/drivers/gpio/gpio-da9052.c
+++ b/drivers/gpio/gpio-da9052.c
@@ -214,7 +214,7 @@ static int da9052_gpio_probe(struct platform_device *pdev)
214 if (pdata && pdata->gpio_base) 214 if (pdata && pdata->gpio_base)
215 gpio->gp.base = pdata->gpio_base; 215 gpio->gp.base = pdata->gpio_base;
216 216
217 ret = gpiochip_add_data(&gpio->gp, gpio); 217 ret = devm_gpiochip_add_data(&pdev->dev, &gpio->gp, gpio);
218 if (ret < 0) { 218 if (ret < 0) {
219 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 219 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
220 return ret; 220 return ret;
@@ -225,17 +225,8 @@ static int da9052_gpio_probe(struct platform_device *pdev)
225 return 0; 225 return 0;
226} 226}
227 227
228static int da9052_gpio_remove(struct platform_device *pdev)
229{
230 struct da9052_gpio *gpio = platform_get_drvdata(pdev);
231
232 gpiochip_remove(&gpio->gp);
233 return 0;
234}
235
236static struct platform_driver da9052_gpio_driver = { 228static struct platform_driver da9052_gpio_driver = {
237 .probe = da9052_gpio_probe, 229 .probe = da9052_gpio_probe,
238 .remove = da9052_gpio_remove,
239 .driver = { 230 .driver = {
240 .name = "da9052-gpio", 231 .name = "da9052-gpio",
241 }, 232 },
diff --git a/drivers/gpio/gpio-da9055.c b/drivers/gpio/gpio-da9055.c
index 18210fb2cb13..2c2c18dc6c4f 100644
--- a/drivers/gpio/gpio-da9055.c
+++ b/drivers/gpio/gpio-da9055.c
@@ -151,31 +151,19 @@ static int da9055_gpio_probe(struct platform_device *pdev)
151 if (pdata && pdata->gpio_base) 151 if (pdata && pdata->gpio_base)
152 gpio->gp.base = pdata->gpio_base; 152 gpio->gp.base = pdata->gpio_base;
153 153
154 ret = gpiochip_add_data(&gpio->gp, gpio); 154 ret = devm_gpiochip_add_data(&pdev->dev, &gpio->gp, gpio);
155 if (ret < 0) { 155 if (ret < 0) {
156 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 156 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
157 goto err_mem; 157 return ret;
158 } 158 }
159 159
160 platform_set_drvdata(pdev, gpio); 160 platform_set_drvdata(pdev, gpio);
161 161
162 return 0; 162 return 0;
163
164err_mem:
165 return ret;
166}
167
168static int da9055_gpio_remove(struct platform_device *pdev)
169{
170 struct da9055_gpio *gpio = platform_get_drvdata(pdev);
171
172 gpiochip_remove(&gpio->gp);
173 return 0;
174} 163}
175 164
176static struct platform_driver da9055_gpio_driver = { 165static struct platform_driver da9055_gpio_driver = {
177 .probe = da9055_gpio_probe, 166 .probe = da9055_gpio_probe,
178 .remove = da9055_gpio_remove,
179 .driver = { 167 .driver = {
180 .name = "da9055-gpio", 168 .name = "da9055-gpio",
181 }, 169 },
diff --git a/drivers/gpio/gpio-davinci.c b/drivers/gpio/gpio-davinci.c
index 96332f19e775..dd262f00295d 100644
--- a/drivers/gpio/gpio-davinci.c
+++ b/drivers/gpio/gpio-davinci.c
@@ -195,7 +195,7 @@ static int davinci_gpio_of_xlate(struct gpio_chip *gc,
195static int davinci_gpio_probe(struct platform_device *pdev) 195static int davinci_gpio_probe(struct platform_device *pdev)
196{ 196{
197 int i, base; 197 int i, base;
198 unsigned ngpio; 198 unsigned ngpio, nbank;
199 struct davinci_gpio_controller *chips; 199 struct davinci_gpio_controller *chips;
200 struct davinci_gpio_platform_data *pdata; 200 struct davinci_gpio_platform_data *pdata;
201 struct davinci_gpio_regs __iomem *regs; 201 struct davinci_gpio_regs __iomem *regs;
@@ -224,8 +224,9 @@ static int davinci_gpio_probe(struct platform_device *pdev)
224 if (WARN_ON(ARCH_NR_GPIOS < ngpio)) 224 if (WARN_ON(ARCH_NR_GPIOS < ngpio))
225 ngpio = ARCH_NR_GPIOS; 225 ngpio = ARCH_NR_GPIOS;
226 226
227 nbank = DIV_ROUND_UP(ngpio, 32);
227 chips = devm_kzalloc(dev, 228 chips = devm_kzalloc(dev,
228 ngpio * sizeof(struct davinci_gpio_controller), 229 nbank * sizeof(struct davinci_gpio_controller),
229 GFP_KERNEL); 230 GFP_KERNEL);
230 if (!chips) 231 if (!chips)
231 return -ENOMEM; 232 return -ENOMEM;
@@ -512,7 +513,7 @@ static int davinci_gpio_irq_setup(struct platform_device *pdev)
512 return irq; 513 return irq;
513 } 514 }
514 515
515 irq_domain = irq_domain_add_legacy(NULL, ngpio, irq, 0, 516 irq_domain = irq_domain_add_legacy(dev->of_node, ngpio, irq, 0,
516 &davinci_gpio_irq_ops, 517 &davinci_gpio_irq_ops,
517 chips); 518 chips);
518 if (!irq_domain) { 519 if (!irq_domain) {
diff --git a/drivers/gpio/gpio-dln2.c b/drivers/gpio/gpio-dln2.c
index e11a7d126e74..f7a60a441e95 100644
--- a/drivers/gpio/gpio-dln2.c
+++ b/drivers/gpio/gpio-dln2.c
@@ -479,40 +479,32 @@ static int dln2_gpio_probe(struct platform_device *pdev)
479 479
480 platform_set_drvdata(pdev, dln2); 480 platform_set_drvdata(pdev, dln2);
481 481
482 ret = gpiochip_add_data(&dln2->gpio, dln2); 482 ret = devm_gpiochip_add_data(dev, &dln2->gpio, dln2);
483 if (ret < 0) { 483 if (ret < 0) {
484 dev_err(dev, "failed to add gpio chip: %d\n", ret); 484 dev_err(dev, "failed to add gpio chip: %d\n", ret);
485 goto out; 485 return ret;
486 } 486 }
487 487
488 ret = gpiochip_irqchip_add(&dln2->gpio, &dln2_gpio_irqchip, 0, 488 ret = gpiochip_irqchip_add(&dln2->gpio, &dln2_gpio_irqchip, 0,
489 handle_simple_irq, IRQ_TYPE_NONE); 489 handle_simple_irq, IRQ_TYPE_NONE);
490 if (ret < 0) { 490 if (ret < 0) {
491 dev_err(dev, "failed to add irq chip: %d\n", ret); 491 dev_err(dev, "failed to add irq chip: %d\n", ret);
492 goto out_gpiochip_remove; 492 return ret;
493 } 493 }
494 494
495 ret = dln2_register_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV, 495 ret = dln2_register_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV,
496 dln2_gpio_event); 496 dln2_gpio_event);
497 if (ret) { 497 if (ret) {
498 dev_err(dev, "failed to register event cb: %d\n", ret); 498 dev_err(dev, "failed to register event cb: %d\n", ret);
499 goto out_gpiochip_remove; 499 return ret;
500 } 500 }
501 501
502 return 0; 502 return 0;
503
504out_gpiochip_remove:
505 gpiochip_remove(&dln2->gpio);
506out:
507 return ret;
508} 503}
509 504
510static int dln2_gpio_remove(struct platform_device *pdev) 505static int dln2_gpio_remove(struct platform_device *pdev)
511{ 506{
512 struct dln2_gpio *dln2 = platform_get_drvdata(pdev);
513
514 dln2_unregister_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV); 507 dln2_unregister_event_cb(pdev, DLN2_GPIO_CONDITION_MET_EV);
515 gpiochip_remove(&dln2->gpio);
516 508
517 return 0; 509 return 0;
518} 510}
diff --git a/drivers/gpio/gpio-ep93xx.c b/drivers/gpio/gpio-ep93xx.c
index ad279078fed7..d054219e18b9 100644
--- a/drivers/gpio/gpio-ep93xx.c
+++ b/drivers/gpio/gpio-ep93xx.c
@@ -339,7 +339,7 @@ static int ep93xx_gpio_add_bank(struct gpio_chip *gc, struct device *dev,
339 gc->to_irq = ep93xx_gpio_to_irq; 339 gc->to_irq = ep93xx_gpio_to_irq;
340 } 340 }
341 341
342 return gpiochip_add_data(gc, NULL); 342 return devm_gpiochip_add_data(dev, gc, NULL);
343} 343}
344 344
345static int ep93xx_gpio_probe(struct platform_device *pdev) 345static int ep93xx_gpio_probe(struct platform_device *pdev)
diff --git a/drivers/gpio/gpio-f7188x.c b/drivers/gpio/gpio-f7188x.c
index 0417798c45f1..daac2d480db1 100644
--- a/drivers/gpio/gpio-f7188x.c
+++ b/drivers/gpio/gpio-f7188x.c
@@ -350,37 +350,16 @@ static int f7188x_gpio_probe(struct platform_device *pdev)
350 bank->chip.parent = &pdev->dev; 350 bank->chip.parent = &pdev->dev;
351 bank->data = data; 351 bank->data = data;
352 352
353 err = gpiochip_add_data(&bank->chip, bank); 353 err = devm_gpiochip_add_data(&pdev->dev, &bank->chip, bank);
354 if (err) { 354 if (err) {
355 dev_err(&pdev->dev, 355 dev_err(&pdev->dev,
356 "Failed to register gpiochip %d: %d\n", 356 "Failed to register gpiochip %d: %d\n",
357 i, err); 357 i, err);
358 goto err_gpiochip; 358 return err;
359 } 359 }
360 } 360 }
361 361
362 return 0; 362 return 0;
363
364err_gpiochip:
365 for (i = i - 1; i >= 0; i--) {
366 struct f7188x_gpio_bank *bank = &data->bank[i];
367 gpiochip_remove(&bank->chip);
368 }
369
370 return err;
371}
372
373static int f7188x_gpio_remove(struct platform_device *pdev)
374{
375 int i;
376 struct f7188x_gpio_data *data = platform_get_drvdata(pdev);
377
378 for (i = 0; i < data->nr_bank; i++) {
379 struct f7188x_gpio_bank *bank = &data->bank[i];
380 gpiochip_remove(&bank->chip);
381 }
382
383 return 0;
384} 363}
385 364
386static int __init f7188x_find(int addr, struct f7188x_sio *sio) 365static int __init f7188x_find(int addr, struct f7188x_sio *sio)
@@ -476,7 +455,6 @@ static struct platform_driver f7188x_gpio_driver = {
476 .name = DRVNAME, 455 .name = DRVNAME,
477 }, 456 },
478 .probe = f7188x_gpio_probe, 457 .probe = f7188x_gpio_probe,
479 .remove = f7188x_gpio_remove,
480}; 458};
481 459
482static int __init f7188x_gpio_init(void) 460static int __init f7188x_gpio_init(void)
diff --git a/drivers/gpio/gpio-ge.c b/drivers/gpio/gpio-ge.c
index cbbec838a9d1..8650b2916f87 100644
--- a/drivers/gpio/gpio-ge.c
+++ b/drivers/gpio/gpio-ge.c
@@ -89,7 +89,7 @@ static int __init gef_gpio_probe(struct platform_device *pdev)
89 gc->of_node = pdev->dev.of_node; 89 gc->of_node = pdev->dev.of_node;
90 90
91 /* This function adds a memory mapped GPIO chip */ 91 /* This function adds a memory mapped GPIO chip */
92 ret = gpiochip_add_data(gc, NULL); 92 ret = devm_gpiochip_add_data(&pdev->dev, gc, NULL);
93 if (ret) 93 if (ret)
94 goto err0; 94 goto err0;
95 95
diff --git a/drivers/gpio/gpio-generic.c b/drivers/gpio/gpio-generic.c
index 2a4f2333a50b..54cddfa98f50 100644
--- a/drivers/gpio/gpio-generic.c
+++ b/drivers/gpio/gpio-generic.c
@@ -628,15 +628,7 @@ static int bgpio_pdev_probe(struct platform_device *pdev)
628 628
629 platform_set_drvdata(pdev, gc); 629 platform_set_drvdata(pdev, gc);
630 630
631 return gpiochip_add_data(gc, NULL); 631 return devm_gpiochip_add_data(&pdev->dev, gc, NULL);
632}
633
634static int bgpio_pdev_remove(struct platform_device *pdev)
635{
636 struct gpio_chip *gc = platform_get_drvdata(pdev);
637
638 gpiochip_remove(gc);
639 return 0;
640} 632}
641 633
642static const struct platform_device_id bgpio_id_table[] = { 634static const struct platform_device_id bgpio_id_table[] = {
@@ -657,7 +649,6 @@ static struct platform_driver bgpio_driver = {
657 }, 649 },
658 .id_table = bgpio_id_table, 650 .id_table = bgpio_id_table,
659 .probe = bgpio_pdev_probe, 651 .probe = bgpio_pdev_probe,
660 .remove = bgpio_pdev_remove,
661}; 652};
662 653
663module_platform_driver(bgpio_driver); 654module_platform_driver(bgpio_driver);
diff --git a/drivers/gpio/gpio-iop.c b/drivers/gpio/gpio-iop.c
index fb65e5850e0c..860c535922fd 100644
--- a/drivers/gpio/gpio-iop.c
+++ b/drivers/gpio/gpio-iop.c
@@ -114,7 +114,7 @@ static int iop3xx_gpio_probe(struct platform_device *pdev)
114 if (IS_ERR(base)) 114 if (IS_ERR(base))
115 return PTR_ERR(base); 115 return PTR_ERR(base);
116 116
117 return gpiochip_add_data(&iop3xx_chip, NULL); 117 return devm_gpiochip_add_data(&pdev->dev, &iop3xx_chip, NULL);
118} 118}
119 119
120static struct platform_driver iop3xx_gpio_driver = { 120static struct platform_driver iop3xx_gpio_driver = {
diff --git a/drivers/gpio/gpio-janz-ttl.c b/drivers/gpio/gpio-janz-ttl.c
index 482aa0353868..a8d0a6b8025a 100644
--- a/drivers/gpio/gpio-janz-ttl.c
+++ b/drivers/gpio/gpio-janz-ttl.c
@@ -182,7 +182,7 @@ static int ttl_probe(struct platform_device *pdev)
182 gpio->base = -1; 182 gpio->base = -1;
183 gpio->ngpio = 20; 183 gpio->ngpio = 20;
184 184
185 ret = gpiochip_add_data(gpio, NULL); 185 ret = devm_gpiochip_add_data(dev, gpio, NULL);
186 if (ret) { 186 if (ret) {
187 dev_err(dev, "unable to add GPIO chip\n"); 187 dev_err(dev, "unable to add GPIO chip\n");
188 return ret; 188 return ret;
@@ -191,21 +191,11 @@ static int ttl_probe(struct platform_device *pdev)
191 return 0; 191 return 0;
192} 192}
193 193
194static int ttl_remove(struct platform_device *pdev)
195{
196 struct ttl_module *mod = platform_get_drvdata(pdev);
197
198 gpiochip_remove(&mod->gpio);
199
200 return 0;
201}
202
203static struct platform_driver ttl_driver = { 194static struct platform_driver ttl_driver = {
204 .driver = { 195 .driver = {
205 .name = DRV_NAME, 196 .name = DRV_NAME,
206 }, 197 },
207 .probe = ttl_probe, 198 .probe = ttl_probe,
208 .remove = ttl_remove,
209}; 199};
210 200
211module_platform_driver(ttl_driver); 201module_platform_driver(ttl_driver);
diff --git a/drivers/gpio/gpio-kempld.c b/drivers/gpio/gpio-kempld.c
index 01117747b965..701f1510328c 100644
--- a/drivers/gpio/gpio-kempld.c
+++ b/drivers/gpio/gpio-kempld.c
@@ -178,7 +178,7 @@ static int kempld_gpio_probe(struct platform_device *pdev)
178 return -ENODEV; 178 return -ENODEV;
179 } 179 }
180 180
181 ret = gpiochip_add_data(chip, gpio); 181 ret = devm_gpiochip_add_data(dev, chip, gpio);
182 if (ret) { 182 if (ret) {
183 dev_err(dev, "Could not register GPIO chip\n"); 183 dev_err(dev, "Could not register GPIO chip\n");
184 return ret; 184 return ret;
@@ -190,20 +190,11 @@ static int kempld_gpio_probe(struct platform_device *pdev)
190 return 0; 190 return 0;
191} 191}
192 192
193static int kempld_gpio_remove(struct platform_device *pdev)
194{
195 struct kempld_gpio_data *gpio = platform_get_drvdata(pdev);
196
197 gpiochip_remove(&gpio->chip);
198 return 0;
199}
200
201static struct platform_driver kempld_gpio_driver = { 193static struct platform_driver kempld_gpio_driver = {
202 .driver = { 194 .driver = {
203 .name = "kempld-gpio", 195 .name = "kempld-gpio",
204 }, 196 },
205 .probe = kempld_gpio_probe, 197 .probe = kempld_gpio_probe,
206 .remove = kempld_gpio_remove,
207}; 198};
208 199
209module_platform_driver(kempld_gpio_driver); 200module_platform_driver(kempld_gpio_driver);
diff --git a/drivers/gpio/gpio-lp3943.c b/drivers/gpio/gpio-lp3943.c
index 1c8e2ae26938..6dc6725403ec 100644
--- a/drivers/gpio/gpio-lp3943.c
+++ b/drivers/gpio/gpio-lp3943.c
@@ -204,15 +204,8 @@ static int lp3943_gpio_probe(struct platform_device *pdev)
204 204
205 platform_set_drvdata(pdev, lp3943_gpio); 205 platform_set_drvdata(pdev, lp3943_gpio);
206 206
207 return gpiochip_add_data(&lp3943_gpio->chip, lp3943_gpio); 207 return devm_gpiochip_add_data(&pdev->dev, &lp3943_gpio->chip,
208} 208 lp3943_gpio);
209
210static int lp3943_gpio_remove(struct platform_device *pdev)
211{
212 struct lp3943_gpio *lp3943_gpio = platform_get_drvdata(pdev);
213
214 gpiochip_remove(&lp3943_gpio->chip);
215 return 0;
216} 209}
217 210
218static const struct of_device_id lp3943_gpio_of_match[] = { 211static const struct of_device_id lp3943_gpio_of_match[] = {
@@ -223,7 +216,6 @@ MODULE_DEVICE_TABLE(of, lp3943_gpio_of_match);
223 216
224static struct platform_driver lp3943_gpio_driver = { 217static struct platform_driver lp3943_gpio_driver = {
225 .probe = lp3943_gpio_probe, 218 .probe = lp3943_gpio_probe,
226 .remove = lp3943_gpio_remove,
227 .driver = { 219 .driver = {
228 .name = "lp3943-gpio", 220 .name = "lp3943-gpio",
229 .of_match_table = lp3943_gpio_of_match, 221 .of_match_table = lp3943_gpio_of_match,
diff --git a/drivers/gpio/gpio-lpc32xx.c b/drivers/gpio/gpio-lpc32xx.c
index 4cecf4ce96c1..d39014daeef9 100644
--- a/drivers/gpio/gpio-lpc32xx.c
+++ b/drivers/gpio/gpio-lpc32xx.c
@@ -547,7 +547,7 @@ static int lpc32xx_gpio_probe(struct platform_device *pdev)
547 lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3; 547 lpc32xx_gpiochip[i].chip.of_gpio_n_cells = 3;
548 lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node; 548 lpc32xx_gpiochip[i].chip.of_node = pdev->dev.of_node;
549 } 549 }
550 gpiochip_add_data(&lpc32xx_gpiochip[i].chip, 550 devm_gpiochip_add_data(&pdev->dev, &lpc32xx_gpiochip[i].chip,
551 &lpc32xx_gpiochip[i]); 551 &lpc32xx_gpiochip[i]);
552 } 552 }
553 553
diff --git a/drivers/gpio/gpio-lynxpoint.c b/drivers/gpio/gpio-lynxpoint.c
index 13107772be4f..9df015e85ad9 100644
--- a/drivers/gpio/gpio-lynxpoint.c
+++ b/drivers/gpio/gpio-lynxpoint.c
@@ -370,7 +370,7 @@ static int lp_gpio_probe(struct platform_device *pdev)
370 gc->can_sleep = false; 370 gc->can_sleep = false;
371 gc->parent = dev; 371 gc->parent = dev;
372 372
373 ret = gpiochip_add_data(gc, lg); 373 ret = devm_gpiochip_add_data(dev, gc, lg);
374 if (ret) { 374 if (ret) {
375 dev_err(dev, "failed adding lp-gpio chip\n"); 375 dev_err(dev, "failed adding lp-gpio chip\n");
376 return ret; 376 return ret;
@@ -439,9 +439,7 @@ MODULE_DEVICE_TABLE(acpi, lynxpoint_gpio_acpi_match);
439 439
440static int lp_gpio_remove(struct platform_device *pdev) 440static int lp_gpio_remove(struct platform_device *pdev)
441{ 441{
442 struct lp_gpio *lg = platform_get_drvdata(pdev);
443 pm_runtime_disable(&pdev->dev); 442 pm_runtime_disable(&pdev->dev);
444 gpiochip_remove(&lg->chip);
445 return 0; 443 return 0;
446} 444}
447 445
diff --git a/drivers/gpio/gpio-mc9s08dz60.c b/drivers/gpio/gpio-mc9s08dz60.c
index ba22fb92a6e7..14f252f9eb29 100644
--- a/drivers/gpio/gpio-mc9s08dz60.c
+++ b/drivers/gpio/gpio-mc9s08dz60.c
@@ -103,17 +103,7 @@ static int mc9s08dz60_probe(struct i2c_client *client,
103 mc9s->client = client; 103 mc9s->client = client;
104 i2c_set_clientdata(client, mc9s); 104 i2c_set_clientdata(client, mc9s);
105 105
106 return gpiochip_add_data(&mc9s->chip, mc9s); 106 return devm_gpiochip_add_data(&client->dev, &mc9s->chip, mc9s);
107}
108
109static int mc9s08dz60_remove(struct i2c_client *client)
110{
111 struct mc9s08dz60 *mc9s;
112
113 mc9s = i2c_get_clientdata(client);
114
115 gpiochip_remove(&mc9s->chip);
116 return 0;
117} 107}
118 108
119static const struct i2c_device_id mc9s08dz60_id[] = { 109static const struct i2c_device_id mc9s08dz60_id[] = {
@@ -128,7 +118,6 @@ static struct i2c_driver mc9s08dz60_i2c_driver = {
128 .name = "mc9s08dz60", 118 .name = "mc9s08dz60",
129 }, 119 },
130 .probe = mc9s08dz60_probe, 120 .probe = mc9s08dz60_probe,
131 .remove = mc9s08dz60_remove,
132 .id_table = mc9s08dz60_id, 121 .id_table = mc9s08dz60_id,
133}; 122};
134 123
diff --git a/drivers/gpio/gpio-moxart.c b/drivers/gpio/gpio-moxart.c
index ca604538ebf7..869002b7a571 100644
--- a/drivers/gpio/gpio-moxart.c
+++ b/drivers/gpio/gpio-moxart.c
@@ -63,7 +63,7 @@ static int moxart_gpio_probe(struct platform_device *pdev)
63 gc->parent = dev; 63 gc->parent = dev;
64 gc->owner = THIS_MODULE; 64 gc->owner = THIS_MODULE;
65 65
66 ret = gpiochip_add_data(gc, NULL); 66 ret = devm_gpiochip_add_data(dev, gc, NULL);
67 if (ret) { 67 if (ret) {
68 dev_err(dev, "%s: gpiochip_add failed\n", 68 dev_err(dev, "%s: gpiochip_add failed\n",
69 dev->of_node->full_name); 69 dev->of_node->full_name);
diff --git a/drivers/gpio/gpio-mvebu.c b/drivers/gpio/gpio-mvebu.c
index a5eacc1dff09..11c6582ef0a6 100644
--- a/drivers/gpio/gpio-mvebu.c
+++ b/drivers/gpio/gpio-mvebu.c
@@ -756,7 +756,7 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
756 BUG(); 756 BUG();
757 } 757 }
758 758
759 gpiochip_add_data(&mvchip->chip, mvchip); 759 devm_gpiochip_add_data(&pdev->dev, &mvchip->chip, mvchip);
760 760
761 /* Some gpio controllers do not provide irq support */ 761 /* Some gpio controllers do not provide irq support */
762 if (!of_irq_count(np)) 762 if (!of_irq_count(np))
@@ -777,16 +777,14 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
777 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1); 777 mvchip->irqbase = irq_alloc_descs(-1, 0, ngpios, -1);
778 if (mvchip->irqbase < 0) { 778 if (mvchip->irqbase < 0) {
779 dev_err(&pdev->dev, "no irqs\n"); 779 dev_err(&pdev->dev, "no irqs\n");
780 err = mvchip->irqbase; 780 return mvchip->irqbase;
781 goto err_gpiochip_add;
782 } 781 }
783 782
784 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase, 783 gc = irq_alloc_generic_chip("mvebu_gpio_irq", 2, mvchip->irqbase,
785 mvchip->membase, handle_level_irq); 784 mvchip->membase, handle_level_irq);
786 if (!gc) { 785 if (!gc) {
787 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n"); 786 dev_err(&pdev->dev, "Cannot allocate generic irq_chip\n");
788 err = -ENOMEM; 787 return -ENOMEM;
789 goto err_gpiochip_add;
790 } 788 }
791 789
792 gc->private = mvchip; 790 gc->private = mvchip;
@@ -828,9 +826,6 @@ err_generic_chip:
828 IRQ_LEVEL | IRQ_NOPROBE); 826 IRQ_LEVEL | IRQ_NOPROBE);
829 kfree(gc); 827 kfree(gc);
830 828
831err_gpiochip_add:
832 gpiochip_remove(&mvchip->chip);
833
834 return err; 829 return err;
835} 830}
836 831
diff --git a/drivers/gpio/gpio-mxc.c b/drivers/gpio/gpio-mxc.c
index 7fd21cb53c81..1b342a3842c8 100644
--- a/drivers/gpio/gpio-mxc.c
+++ b/drivers/gpio/gpio-mxc.c
@@ -462,14 +462,14 @@ static int mxc_gpio_probe(struct platform_device *pdev)
462 port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 : 462 port->gc.base = (pdev->id < 0) ? of_alias_get_id(np, "gpio") * 32 :
463 pdev->id * 32; 463 pdev->id * 32;
464 464
465 err = gpiochip_add_data(&port->gc, port); 465 err = devm_gpiochip_add_data(&pdev->dev, &port->gc, port);
466 if (err) 466 if (err)
467 goto out_bgio; 467 goto out_bgio;
468 468
469 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id()); 469 irq_base = irq_alloc_descs(-1, 0, 32, numa_node_id());
470 if (irq_base < 0) { 470 if (irq_base < 0) {
471 err = irq_base; 471 err = irq_base;
472 goto out_gpiochip_remove; 472 goto out_bgio;
473 } 473 }
474 474
475 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0, 475 port->domain = irq_domain_add_legacy(np, 32, irq_base, 0,
@@ -492,8 +492,6 @@ out_irqdomain_remove:
492 irq_domain_remove(port->domain); 492 irq_domain_remove(port->domain);
493out_irqdesc_free: 493out_irqdesc_free:
494 irq_free_descs(irq_base, 32); 494 irq_free_descs(irq_base, 32);
495out_gpiochip_remove:
496 gpiochip_remove(&port->gc);
497out_bgio: 495out_bgio:
498 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err); 496 dev_info(&pdev->dev, "%s failed with errno %d\n", __func__, err);
499 return err; 497 return err;
diff --git a/drivers/gpio/gpio-octeon.c b/drivers/gpio/gpio-octeon.c
index 7665ebcd0c1d..47aead1ed1cc 100644
--- a/drivers/gpio/gpio-octeon.c
+++ b/drivers/gpio/gpio-octeon.c
@@ -117,7 +117,7 @@ static int octeon_gpio_probe(struct platform_device *pdev)
117 chip->get = octeon_gpio_get; 117 chip->get = octeon_gpio_get;
118 chip->direction_output = octeon_gpio_dir_out; 118 chip->direction_output = octeon_gpio_dir_out;
119 chip->set = octeon_gpio_set; 119 chip->set = octeon_gpio_set;
120 err = gpiochip_add_data(chip, gpio); 120 err = devm_gpiochip_add_data(&pdev->dev, chip, gpio);
121 if (err) 121 if (err)
122 goto out; 122 goto out;
123 123
@@ -126,13 +126,6 @@ out:
126 return err; 126 return err;
127} 127}
128 128
129static int octeon_gpio_remove(struct platform_device *pdev)
130{
131 struct gpio_chip *chip = dev_get_platdata(&pdev->dev);
132 gpiochip_remove(chip);
133 return 0;
134}
135
136static struct of_device_id octeon_gpio_match[] = { 129static struct of_device_id octeon_gpio_match[] = {
137 { 130 {
138 .compatible = "cavium,octeon-3860-gpio", 131 .compatible = "cavium,octeon-3860-gpio",
@@ -147,7 +140,6 @@ static struct platform_driver octeon_gpio_driver = {
147 .of_match_table = octeon_gpio_match, 140 .of_match_table = octeon_gpio_match,
148 }, 141 },
149 .probe = octeon_gpio_probe, 142 .probe = octeon_gpio_probe,
150 .remove = octeon_gpio_remove,
151}; 143};
152 144
153module_platform_driver(octeon_gpio_driver); 145module_platform_driver(octeon_gpio_driver);
diff --git a/drivers/gpio/gpio-palmas.c b/drivers/gpio/gpio-palmas.c
index fdfb3b1e0def..6f27b3d94d53 100644
--- a/drivers/gpio/gpio-palmas.c
+++ b/drivers/gpio/gpio-palmas.c
@@ -195,7 +195,8 @@ static int palmas_gpio_probe(struct platform_device *pdev)
195 else 195 else
196 palmas_gpio->gpio_chip.base = -1; 196 palmas_gpio->gpio_chip.base = -1;
197 197
198 ret = gpiochip_add_data(&palmas_gpio->gpio_chip, palmas_gpio); 198 ret = devm_gpiochip_add_data(&pdev->dev, &palmas_gpio->gpio_chip,
199 palmas_gpio);
199 if (ret < 0) { 200 if (ret < 0) {
200 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 201 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
201 return ret; 202 return ret;
@@ -205,20 +206,11 @@ static int palmas_gpio_probe(struct platform_device *pdev)
205 return ret; 206 return ret;
206} 207}
207 208
208static int palmas_gpio_remove(struct platform_device *pdev)
209{
210 struct palmas_gpio *palmas_gpio = platform_get_drvdata(pdev);
211
212 gpiochip_remove(&palmas_gpio->gpio_chip);
213 return 0;
214}
215
216static struct platform_driver palmas_gpio_driver = { 209static struct platform_driver palmas_gpio_driver = {
217 .driver.name = "palmas-gpio", 210 .driver.name = "palmas-gpio",
218 .driver.owner = THIS_MODULE, 211 .driver.owner = THIS_MODULE,
219 .driver.of_match_table = of_palmas_gpio_match, 212 .driver.of_match_table = of_palmas_gpio_match,
220 .probe = palmas_gpio_probe, 213 .probe = palmas_gpio_probe,
221 .remove = palmas_gpio_remove,
222}; 214};
223 215
224static int __init palmas_gpio_init(void) 216static int __init palmas_gpio_init(void)
diff --git a/drivers/gpio/gpio-pca953x.c b/drivers/gpio/gpio-pca953x.c
index 23196c5fc17c..b7fe5d5e3488 100644
--- a/drivers/gpio/gpio-pca953x.c
+++ b/drivers/gpio/gpio-pca953x.c
@@ -754,7 +754,7 @@ static int pca953x_probe(struct i2c_client *client,
754 if (ret) 754 if (ret)
755 return ret; 755 return ret;
756 756
757 ret = gpiochip_add_data(&chip->gpio_chip, chip); 757 ret = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip);
758 if (ret) 758 if (ret)
759 return ret; 759 return ret;
760 760
@@ -789,8 +789,6 @@ static int pca953x_remove(struct i2c_client *client)
789 } 789 }
790 } 790 }
791 791
792 gpiochip_remove(&chip->gpio_chip);
793
794 return 0; 792 return 0;
795} 793}
796 794
diff --git a/drivers/gpio/gpio-pcf857x.c b/drivers/gpio/gpio-pcf857x.c
index 709cd3fc2a70..169c09aa33c8 100644
--- a/drivers/gpio/gpio-pcf857x.c
+++ b/drivers/gpio/gpio-pcf857x.c
@@ -372,7 +372,7 @@ static int pcf857x_probe(struct i2c_client *client,
372 gpio->out = ~n_latch; 372 gpio->out = ~n_latch;
373 gpio->status = gpio->out; 373 gpio->status = gpio->out;
374 374
375 status = gpiochip_add_data(&gpio->chip, gpio); 375 status = devm_gpiochip_add_data(&client->dev, &gpio->chip, gpio);
376 if (status < 0) 376 if (status < 0)
377 goto fail; 377 goto fail;
378 378
@@ -383,7 +383,7 @@ static int pcf857x_probe(struct i2c_client *client,
383 IRQ_TYPE_NONE); 383 IRQ_TYPE_NONE);
384 if (status) { 384 if (status) {
385 dev_err(&client->dev, "cannot add irqchip\n"); 385 dev_err(&client->dev, "cannot add irqchip\n");
386 goto fail_irq; 386 goto fail;
387 } 387 }
388 388
389 status = devm_request_threaded_irq(&client->dev, client->irq, 389 status = devm_request_threaded_irq(&client->dev, client->irq,
@@ -391,7 +391,7 @@ static int pcf857x_probe(struct i2c_client *client,
391 IRQF_TRIGGER_FALLING | IRQF_SHARED, 391 IRQF_TRIGGER_FALLING | IRQF_SHARED,
392 dev_name(&client->dev), gpio); 392 dev_name(&client->dev), gpio);
393 if (status) 393 if (status)
394 goto fail_irq; 394 goto fail;
395 395
396 gpiochip_set_chained_irqchip(&gpio->chip, &pcf857x_irq_chip, 396 gpiochip_set_chained_irqchip(&gpio->chip, &pcf857x_irq_chip,
397 client->irq, NULL); 397 client->irq, NULL);
@@ -413,9 +413,6 @@ static int pcf857x_probe(struct i2c_client *client,
413 413
414 return 0; 414 return 0;
415 415
416fail_irq:
417 gpiochip_remove(&gpio->chip);
418
419fail: 416fail:
420 dev_dbg(&client->dev, "probe error %d for '%s'\n", status, 417 dev_dbg(&client->dev, "probe error %d for '%s'\n", status,
421 client->name); 418 client->name);
@@ -440,7 +437,6 @@ static int pcf857x_remove(struct i2c_client *client)
440 } 437 }
441 } 438 }
442 439
443 gpiochip_remove(&gpio->chip);
444 return status; 440 return status;
445} 441}
446 442
diff --git a/drivers/gpio/gpio-rc5t583.c b/drivers/gpio/gpio-rc5t583.c
index 1e2d210b3369..1d6100fa312a 100644
--- a/drivers/gpio/gpio-rc5t583.c
+++ b/drivers/gpio/gpio-rc5t583.c
@@ -136,15 +136,8 @@ static int rc5t583_gpio_probe(struct platform_device *pdev)
136 136
137 platform_set_drvdata(pdev, rc5t583_gpio); 137 platform_set_drvdata(pdev, rc5t583_gpio);
138 138
139 return gpiochip_add_data(&rc5t583_gpio->gpio_chip, rc5t583_gpio); 139 return devm_gpiochip_add_data(&pdev->dev, &rc5t583_gpio->gpio_chip,
140} 140 rc5t583_gpio);
141
142static int rc5t583_gpio_remove(struct platform_device *pdev)
143{
144 struct rc5t583_gpio *rc5t583_gpio = platform_get_drvdata(pdev);
145
146 gpiochip_remove(&rc5t583_gpio->gpio_chip);
147 return 0;
148} 141}
149 142
150static struct platform_driver rc5t583_gpio_driver = { 143static struct platform_driver rc5t583_gpio_driver = {
@@ -152,7 +145,6 @@ static struct platform_driver rc5t583_gpio_driver = {
152 .name = "rc5t583-gpio", 145 .name = "rc5t583-gpio",
153 }, 146 },
154 .probe = rc5t583_gpio_probe, 147 .probe = rc5t583_gpio_probe,
155 .remove = rc5t583_gpio_remove,
156}; 148};
157 149
158static int __init rc5t583_gpio_init(void) 150static int __init rc5t583_gpio_init(void)
diff --git a/drivers/gpio/gpio-rdc321x.c b/drivers/gpio/gpio-rdc321x.c
index 96ddee3f464a..ec945b90f54d 100644
--- a/drivers/gpio/gpio-rdc321x.c
+++ b/drivers/gpio/gpio-rdc321x.c
@@ -194,23 +194,14 @@ static int rdc321x_gpio_probe(struct platform_device *pdev)
194 194
195 dev_info(&pdev->dev, "registering %d GPIOs\n", 195 dev_info(&pdev->dev, "registering %d GPIOs\n",
196 rdc321x_gpio_dev->chip.ngpio); 196 rdc321x_gpio_dev->chip.ngpio);
197 return gpiochip_add_data(&rdc321x_gpio_dev->chip, rdc321x_gpio_dev); 197 return devm_gpiochip_add_data(&pdev->dev, &rdc321x_gpio_dev->chip,
198} 198 rdc321x_gpio_dev);
199
200static int rdc321x_gpio_remove(struct platform_device *pdev)
201{
202 struct rdc321x_gpio *rdc321x_gpio_dev = platform_get_drvdata(pdev);
203
204 gpiochip_remove(&rdc321x_gpio_dev->chip);
205
206 return 0;
207} 199}
208 200
209static struct platform_driver rdc321x_gpio_driver = { 201static struct platform_driver rdc321x_gpio_driver = {
210 .driver.name = "rdc321x-gpio", 202 .driver.name = "rdc321x-gpio",
211 .driver.owner = THIS_MODULE, 203 .driver.owner = THIS_MODULE,
212 .probe = rdc321x_gpio_probe, 204 .probe = rdc321x_gpio_probe,
213 .remove = rdc321x_gpio_remove,
214}; 205};
215 206
216module_platform_driver(rdc321x_gpio_driver); 207module_platform_driver(rdc321x_gpio_driver);
diff --git a/drivers/gpio/gpio-sch.c b/drivers/gpio/gpio-sch.c
index 5314ee4b947d..e85e7539cf5d 100644
--- a/drivers/gpio/gpio-sch.c
+++ b/drivers/gpio/gpio-sch.c
@@ -215,15 +215,7 @@ static int sch_gpio_probe(struct platform_device *pdev)
215 215
216 platform_set_drvdata(pdev, sch); 216 platform_set_drvdata(pdev, sch);
217 217
218 return gpiochip_add_data(&sch->chip, sch); 218 return devm_gpiochip_add_data(&pdev->dev, &sch->chip, sch);
219}
220
221static int sch_gpio_remove(struct platform_device *pdev)
222{
223 struct sch_gpio *sch = platform_get_drvdata(pdev);
224
225 gpiochip_remove(&sch->chip);
226 return 0;
227} 219}
228 220
229static struct platform_driver sch_gpio_driver = { 221static struct platform_driver sch_gpio_driver = {
@@ -231,7 +223,6 @@ static struct platform_driver sch_gpio_driver = {
231 .name = "sch_gpio", 223 .name = "sch_gpio",
232 }, 224 },
233 .probe = sch_gpio_probe, 225 .probe = sch_gpio_probe,
234 .remove = sch_gpio_remove,
235}; 226};
236 227
237module_platform_driver(sch_gpio_driver); 228module_platform_driver(sch_gpio_driver);
diff --git a/drivers/gpio/gpio-spear-spics.c b/drivers/gpio/gpio-spear-spics.c
index 50fb09080a6b..7ffd16495286 100644
--- a/drivers/gpio/gpio-spear-spics.c
+++ b/drivers/gpio/gpio-spear-spics.c
@@ -165,7 +165,7 @@ static int spics_gpio_probe(struct platform_device *pdev)
165 spics->chip.owner = THIS_MODULE; 165 spics->chip.owner = THIS_MODULE;
166 spics->last_off = -1; 166 spics->last_off = -1;
167 167
168 ret = gpiochip_add_data(&spics->chip, spics); 168 ret = devm_gpiochip_add_data(&pdev->dev, &spics->chip, spics);
169 if (ret) { 169 if (ret) {
170 dev_err(&pdev->dev, "unable to add gpio chip\n"); 170 dev_err(&pdev->dev, "unable to add gpio chip\n");
171 return ret; 171 return ret;
diff --git a/drivers/gpio/gpio-sta2x11.c b/drivers/gpio/gpio-sta2x11.c
index 83af1cb36333..0d5b8c525dd9 100644
--- a/drivers/gpio/gpio-sta2x11.c
+++ b/drivers/gpio/gpio-sta2x11.c
@@ -409,7 +409,7 @@ static int gsta_probe(struct platform_device *dev)
409 goto err_free_descs; 409 goto err_free_descs;
410 } 410 }
411 411
412 err = gpiochip_add_data(&chip->gpio, chip); 412 err = devm_gpiochip_add_data(&dev->dev, &chip->gpio, chip);
413 if (err < 0) { 413 if (err < 0) {
414 dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n", 414 dev_err(&dev->dev, "sta2x11 gpio: Can't register (%i)\n",
415 -err); 415 -err);
diff --git a/drivers/gpio/gpio-stp-xway.c b/drivers/gpio/gpio-stp-xway.c
index d11dd48570b2..19e654f88b3a 100644
--- a/drivers/gpio/gpio-stp-xway.c
+++ b/drivers/gpio/gpio-stp-xway.c
@@ -258,7 +258,7 @@ static int xway_stp_probe(struct platform_device *pdev)
258 258
259 ret = xway_stp_hw_init(chip); 259 ret = xway_stp_hw_init(chip);
260 if (!ret) 260 if (!ret)
261 ret = gpiochip_add_data(&chip->gc, chip); 261 ret = devm_gpiochip_add_data(&pdev->dev, &chip->gc, chip);
262 262
263 if (!ret) 263 if (!ret)
264 dev_info(&pdev->dev, "Init done\n"); 264 dev_info(&pdev->dev, "Init done\n");
diff --git a/drivers/gpio/gpio-sx150x.c b/drivers/gpio/gpio-sx150x.c
index e6cff1cabd0c..d387eb524bf3 100644
--- a/drivers/gpio/gpio-sx150x.c
+++ b/drivers/gpio/gpio-sx150x.c
@@ -687,7 +687,7 @@ static int sx150x_probe(struct i2c_client *client,
687 if (rc < 0) 687 if (rc < 0)
688 return rc; 688 return rc;
689 689
690 rc = gpiochip_add_data(&chip->gpio_chip, chip); 690 rc = devm_gpiochip_add_data(&client->dev, &chip->gpio_chip, chip);
691 if (rc) 691 if (rc)
692 return rc; 692 return rc;
693 693
@@ -696,25 +696,12 @@ static int sx150x_probe(struct i2c_client *client,
696 pdata->irq_summary, 696 pdata->irq_summary,
697 pdata->irq_base); 697 pdata->irq_base);
698 if (rc < 0) 698 if (rc < 0)
699 goto probe_fail_post_gpiochip_add; 699 return rc;
700 } 700 }
701 701
702 i2c_set_clientdata(client, chip); 702 i2c_set_clientdata(client, chip);
703 703
704 return 0; 704 return 0;
705probe_fail_post_gpiochip_add:
706 gpiochip_remove(&chip->gpio_chip);
707 return rc;
708}
709
710static int sx150x_remove(struct i2c_client *client)
711{
712 struct sx150x_chip *chip;
713
714 chip = i2c_get_clientdata(client);
715 gpiochip_remove(&chip->gpio_chip);
716
717 return 0;
718} 705}
719 706
720static struct i2c_driver sx150x_driver = { 707static struct i2c_driver sx150x_driver = {
@@ -723,7 +710,6 @@ static struct i2c_driver sx150x_driver = {
723 .of_match_table = of_match_ptr(sx150x_of_match), 710 .of_match_table = of_match_ptr(sx150x_of_match),
724 }, 711 },
725 .probe = sx150x_probe, 712 .probe = sx150x_probe,
726 .remove = sx150x_remove,
727 .id_table = sx150x_id, 713 .id_table = sx150x_id,
728}; 714};
729 715
diff --git a/drivers/gpio/gpio-syscon.c b/drivers/gpio/gpio-syscon.c
index e5c5b6205886..24b6d643ecdb 100644
--- a/drivers/gpio/gpio-syscon.c
+++ b/drivers/gpio/gpio-syscon.c
@@ -238,15 +238,7 @@ static int syscon_gpio_probe(struct platform_device *pdev)
238 238
239 platform_set_drvdata(pdev, priv); 239 platform_set_drvdata(pdev, priv);
240 240
241 return gpiochip_add_data(&priv->chip, priv); 241 return devm_gpiochip_add_data(&pdev->dev, &priv->chip, priv);
242}
243
244static int syscon_gpio_remove(struct platform_device *pdev)
245{
246 struct syscon_gpio_priv *priv = platform_get_drvdata(pdev);
247
248 gpiochip_remove(&priv->chip);
249 return 0;
250} 242}
251 243
252static struct platform_driver syscon_gpio_driver = { 244static struct platform_driver syscon_gpio_driver = {
@@ -255,7 +247,6 @@ static struct platform_driver syscon_gpio_driver = {
255 .of_match_table = syscon_gpio_ids, 247 .of_match_table = syscon_gpio_ids,
256 }, 248 },
257 .probe = syscon_gpio_probe, 249 .probe = syscon_gpio_probe,
258 .remove = syscon_gpio_remove,
259}; 250};
260module_platform_driver(syscon_gpio_driver); 251module_platform_driver(syscon_gpio_driver);
261 252
diff --git a/drivers/gpio/gpio-tb10x.c b/drivers/gpio/gpio-tb10x.c
index 5eaec20ddbc7..80b6959ae995 100644
--- a/drivers/gpio/gpio-tb10x.c
+++ b/drivers/gpio/gpio-tb10x.c
@@ -205,10 +205,10 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
205 tb10x_gpio->gc.can_sleep = false; 205 tb10x_gpio->gc.can_sleep = false;
206 206
207 207
208 ret = gpiochip_add_data(&tb10x_gpio->gc, tb10x_gpio); 208 ret = devm_gpiochip_add_data(&pdev->dev, &tb10x_gpio->gc, tb10x_gpio);
209 if (ret < 0) { 209 if (ret < 0) {
210 dev_err(&pdev->dev, "Could not add gpiochip.\n"); 210 dev_err(&pdev->dev, "Could not add gpiochip.\n");
211 goto fail_gpiochip_registration; 211 return ret;
212 } 212 }
213 213
214 platform_set_drvdata(pdev, tb10x_gpio); 214 platform_set_drvdata(pdev, tb10x_gpio);
@@ -219,7 +219,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
219 ret = platform_get_irq(pdev, 0); 219 ret = platform_get_irq(pdev, 0);
220 if (ret < 0) { 220 if (ret < 0) {
221 dev_err(&pdev->dev, "No interrupt specified.\n"); 221 dev_err(&pdev->dev, "No interrupt specified.\n");
222 goto fail_get_irq; 222 return ret;
223 } 223 }
224 224
225 tb10x_gpio->gc.to_irq = tb10x_gpio_to_irq; 225 tb10x_gpio->gc.to_irq = tb10x_gpio_to_irq;
@@ -229,14 +229,13 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
229 IRQF_TRIGGER_NONE | IRQF_SHARED, 229 IRQF_TRIGGER_NONE | IRQF_SHARED,
230 dev_name(&pdev->dev), tb10x_gpio); 230 dev_name(&pdev->dev), tb10x_gpio);
231 if (ret != 0) 231 if (ret != 0)
232 goto fail_request_irq; 232 return ret;
233 233
234 tb10x_gpio->domain = irq_domain_add_linear(dn, 234 tb10x_gpio->domain = irq_domain_add_linear(dn,
235 tb10x_gpio->gc.ngpio, 235 tb10x_gpio->gc.ngpio,
236 &irq_generic_chip_ops, NULL); 236 &irq_generic_chip_ops, NULL);
237 if (!tb10x_gpio->domain) { 237 if (!tb10x_gpio->domain) {
238 ret = -ENOMEM; 238 return -ENOMEM;
239 goto fail_irq_domain;
240 } 239 }
241 240
242 ret = irq_alloc_domain_generic_chips(tb10x_gpio->domain, 241 ret = irq_alloc_domain_generic_chips(tb10x_gpio->domain,
@@ -244,7 +243,7 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
244 handle_edge_irq, IRQ_NOREQUEST, IRQ_NOPROBE, 243 handle_edge_irq, IRQ_NOREQUEST, IRQ_NOPROBE,
245 IRQ_GC_INIT_MASK_CACHE); 244 IRQ_GC_INIT_MASK_CACHE);
246 if (ret) 245 if (ret)
247 goto fail_irq_domain; 246 return ret;
248 247
249 gc = tb10x_gpio->domain->gc->gc[0]; 248 gc = tb10x_gpio->domain->gc->gc[0];
250 gc->reg_base = tb10x_gpio->base; 249 gc->reg_base = tb10x_gpio->base;
@@ -258,14 +257,6 @@ static int tb10x_gpio_probe(struct platform_device *pdev)
258 } 257 }
259 258
260 return 0; 259 return 0;
261
262fail_irq_domain:
263fail_request_irq:
264fail_get_irq:
265 gpiochip_remove(&tb10x_gpio->gc);
266fail_gpiochip_registration:
267fail_ioremap:
268 return ret;
269} 260}
270 261
271static int tb10x_gpio_remove(struct platform_device *pdev) 262static int tb10x_gpio_remove(struct platform_device *pdev)
@@ -278,7 +269,6 @@ static int tb10x_gpio_remove(struct platform_device *pdev)
278 kfree(tb10x_gpio->domain->gc); 269 kfree(tb10x_gpio->domain->gc);
279 irq_domain_remove(tb10x_gpio->domain); 270 irq_domain_remove(tb10x_gpio->domain);
280 } 271 }
281 gpiochip_remove(&tb10x_gpio->gc);
282 272
283 return 0; 273 return 0;
284} 274}
diff --git a/drivers/gpio/gpio-tc3589x.c b/drivers/gpio/gpio-tc3589x.c
index 05a27ec55add..4f566e6b81f1 100644
--- a/drivers/gpio/gpio-tc3589x.c
+++ b/drivers/gpio/gpio-tc3589x.c
@@ -272,7 +272,8 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
272 return ret; 272 return ret;
273 } 273 }
274 274
275 ret = gpiochip_add_data(&tc3589x_gpio->chip, tc3589x_gpio); 275 ret = devm_gpiochip_add_data(&pdev->dev, &tc3589x_gpio->chip,
276 tc3589x_gpio);
276 if (ret) { 277 if (ret) {
277 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret); 278 dev_err(&pdev->dev, "unable to add gpiochip: %d\n", ret);
278 return ret; 279 return ret;
@@ -299,20 +300,10 @@ static int tc3589x_gpio_probe(struct platform_device *pdev)
299 return 0; 300 return 0;
300} 301}
301 302
302static int tc3589x_gpio_remove(struct platform_device *pdev)
303{
304 struct tc3589x_gpio *tc3589x_gpio = platform_get_drvdata(pdev);
305
306 gpiochip_remove(&tc3589x_gpio->chip);
307
308 return 0;
309}
310
311static struct platform_driver tc3589x_gpio_driver = { 303static struct platform_driver tc3589x_gpio_driver = {
312 .driver.name = "tc3589x-gpio", 304 .driver.name = "tc3589x-gpio",
313 .driver.owner = THIS_MODULE, 305 .driver.owner = THIS_MODULE,
314 .probe = tc3589x_gpio_probe, 306 .probe = tc3589x_gpio_probe,
315 .remove = tc3589x_gpio_remove,
316}; 307};
317 308
318static int __init tc3589x_gpio_init(void) 309static int __init tc3589x_gpio_init(void)
diff --git a/drivers/gpio/gpio-tegra.c b/drivers/gpio/gpio-tegra.c
index 9a1a7e2ef388..790bb111b2cb 100644
--- a/drivers/gpio/gpio-tegra.c
+++ b/drivers/gpio/gpio-tegra.c
@@ -545,7 +545,7 @@ static int tegra_gpio_probe(struct platform_device *pdev)
545 545
546 tegra_gpio_chip.of_node = pdev->dev.of_node; 546 tegra_gpio_chip.of_node = pdev->dev.of_node;
547 547
548 ret = gpiochip_add_data(&tegra_gpio_chip, NULL); 548 ret = devm_gpiochip_add_data(&pdev->dev, &tegra_gpio_chip, NULL);
549 if (ret < 0) { 549 if (ret < 0) {
550 irq_domain_remove(irq_domain); 550 irq_domain_remove(irq_domain);
551 return ret; 551 return ret;
diff --git a/drivers/gpio/gpio-timberdale.c b/drivers/gpio/gpio-timberdale.c
index a6de10c5275b..f0164ec43921 100644
--- a/drivers/gpio/gpio-timberdale.c
+++ b/drivers/gpio/gpio-timberdale.c
@@ -279,7 +279,7 @@ static int timbgpio_probe(struct platform_device *pdev)
279 gc->ngpio = pdata->nr_pins; 279 gc->ngpio = pdata->nr_pins;
280 gc->can_sleep = false; 280 gc->can_sleep = false;
281 281
282 err = gpiochip_add_data(gc, tgpio); 282 err = devm_gpiochip_add_data(&pdev->dev, gc, tgpio);
283 if (err) 283 if (err)
284 return err; 284 return err;
285 285
@@ -320,8 +320,6 @@ static int timbgpio_remove(struct platform_device *pdev)
320 irq_set_handler_data(irq, NULL); 320 irq_set_handler_data(irq, NULL);
321 } 321 }
322 322
323 gpiochip_remove(&tgpio->gpio);
324
325 return 0; 323 return 0;
326} 324}
327 325
diff --git a/drivers/gpio/gpio-tps6586x.c b/drivers/gpio/gpio-tps6586x.c
index 87de5486a29e..c88bdc8ee2c9 100644
--- a/drivers/gpio/gpio-tps6586x.c
+++ b/drivers/gpio/gpio-tps6586x.c
@@ -117,7 +117,8 @@ static int tps6586x_gpio_probe(struct platform_device *pdev)
117 else 117 else
118 tps6586x_gpio->gpio_chip.base = -1; 118 tps6586x_gpio->gpio_chip.base = -1;
119 119
120 ret = gpiochip_add_data(&tps6586x_gpio->gpio_chip, tps6586x_gpio); 120 ret = devm_gpiochip_add_data(&pdev->dev, &tps6586x_gpio->gpio_chip,
121 tps6586x_gpio);
121 if (ret < 0) { 122 if (ret < 0) {
122 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 123 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
123 return ret; 124 return ret;
@@ -128,19 +129,10 @@ static int tps6586x_gpio_probe(struct platform_device *pdev)
128 return ret; 129 return ret;
129} 130}
130 131
131static int tps6586x_gpio_remove(struct platform_device *pdev)
132{
133 struct tps6586x_gpio *tps6586x_gpio = platform_get_drvdata(pdev);
134
135 gpiochip_remove(&tps6586x_gpio->gpio_chip);
136 return 0;
137}
138
139static struct platform_driver tps6586x_gpio_driver = { 132static struct platform_driver tps6586x_gpio_driver = {
140 .driver.name = "tps6586x-gpio", 133 .driver.name = "tps6586x-gpio",
141 .driver.owner = THIS_MODULE, 134 .driver.owner = THIS_MODULE,
142 .probe = tps6586x_gpio_probe, 135 .probe = tps6586x_gpio_probe,
143 .remove = tps6586x_gpio_remove,
144}; 136};
145 137
146static int __init tps6586x_gpio_init(void) 138static int __init tps6586x_gpio_init(void)
diff --git a/drivers/gpio/gpio-tps65910.c b/drivers/gpio/gpio-tps65910.c
index e81eee7627a3..cdbd7c740043 100644
--- a/drivers/gpio/gpio-tps65910.c
+++ b/drivers/gpio/gpio-tps65910.c
@@ -170,7 +170,8 @@ static int tps65910_gpio_probe(struct platform_device *pdev)
170 } 170 }
171 171
172skip_init: 172skip_init:
173 ret = gpiochip_add_data(&tps65910_gpio->gpio_chip, tps65910_gpio); 173 ret = devm_gpiochip_add_data(&pdev->dev, &tps65910_gpio->gpio_chip,
174 tps65910_gpio);
174 if (ret < 0) { 175 if (ret < 0) {
175 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 176 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
176 return ret; 177 return ret;
@@ -181,19 +182,10 @@ skip_init:
181 return ret; 182 return ret;
182} 183}
183 184
184static int tps65910_gpio_remove(struct platform_device *pdev)
185{
186 struct tps65910_gpio *tps65910_gpio = platform_get_drvdata(pdev);
187
188 gpiochip_remove(&tps65910_gpio->gpio_chip);
189 return 0;
190}
191
192static struct platform_driver tps65910_gpio_driver = { 185static struct platform_driver tps65910_gpio_driver = {
193 .driver.name = "tps65910-gpio", 186 .driver.name = "tps65910-gpio",
194 .driver.owner = THIS_MODULE, 187 .driver.owner = THIS_MODULE,
195 .probe = tps65910_gpio_probe, 188 .probe = tps65910_gpio_probe,
196 .remove = tps65910_gpio_remove,
197}; 189};
198 190
199static int __init tps65910_gpio_init(void) 191static int __init tps65910_gpio_init(void)
diff --git a/drivers/gpio/gpio-tps65912.c b/drivers/gpio/gpio-tps65912.c
index 4f2029c7da3a..e72302d2461a 100644
--- a/drivers/gpio/gpio-tps65912.c
+++ b/drivers/gpio/gpio-tps65912.c
@@ -106,7 +106,8 @@ static int tps65912_gpio_probe(struct platform_device *pdev)
106 if (pdata && pdata->gpio_base) 106 if (pdata && pdata->gpio_base)
107 tps65912_gpio->gpio_chip.base = pdata->gpio_base; 107 tps65912_gpio->gpio_chip.base = pdata->gpio_base;
108 108
109 ret = gpiochip_add_data(&tps65912_gpio->gpio_chip, tps65912_gpio); 109 ret = devm_gpiochip_add_data(&pdev->dev, &tps65912_gpio->gpio_chip,
110 tps65912_gpio);
110 if (ret < 0) { 111 if (ret < 0) {
111 dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret); 112 dev_err(&pdev->dev, "Failed to register gpiochip, %d\n", ret);
112 return ret; 113 return ret;
@@ -117,20 +118,11 @@ static int tps65912_gpio_probe(struct platform_device *pdev)
117 return ret; 118 return ret;
118} 119}
119 120
120static int tps65912_gpio_remove(struct platform_device *pdev)
121{
122 struct tps65912_gpio_data *tps65912_gpio = platform_get_drvdata(pdev);
123
124 gpiochip_remove(&tps65912_gpio->gpio_chip);
125 return 0;
126}
127
128static struct platform_driver tps65912_gpio_driver = { 121static struct platform_driver tps65912_gpio_driver = {
129 .driver = { 122 .driver = {
130 .name = "tps65912-gpio", 123 .name = "tps65912-gpio",
131 }, 124 },
132 .probe = tps65912_gpio_probe, 125 .probe = tps65912_gpio_probe,
133 .remove = tps65912_gpio_remove,
134}; 126};
135 127
136static int __init tps65912_gpio_init(void) 128static int __init tps65912_gpio_init(void)
diff --git a/drivers/gpio/gpio-ts4800.c b/drivers/gpio/gpio-ts4800.c
index 147824554253..0c144a72f9af 100644
--- a/drivers/gpio/gpio-ts4800.c
+++ b/drivers/gpio/gpio-ts4800.c
@@ -58,16 +58,7 @@ static int ts4800_gpio_probe(struct platform_device *pdev)
58 58
59 platform_set_drvdata(pdev, chip); 59 platform_set_drvdata(pdev, chip);
60 60
61 return gpiochip_add_data(chip, NULL); 61 return devm_gpiochip_add_data(&pdev->dev, chip, NULL);
62}
63
64static int ts4800_gpio_remove(struct platform_device *pdev)
65{
66 struct gpio_chip *chip = platform_get_drvdata(pdev);
67
68 gpiochip_remove(chip);
69
70 return 0;
71} 62}
72 63
73static const struct of_device_id ts4800_gpio_of_match[] = { 64static const struct of_device_id ts4800_gpio_of_match[] = {
@@ -81,7 +72,6 @@ static struct platform_driver ts4800_gpio_driver = {
81 .of_match_table = ts4800_gpio_of_match, 72 .of_match_table = ts4800_gpio_of_match,
82 }, 73 },
83 .probe = ts4800_gpio_probe, 74 .probe = ts4800_gpio_probe,
84 .remove = ts4800_gpio_remove,
85}; 75};
86 76
87module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe); 77module_platform_driver_probe(ts4800_gpio_driver, ts4800_gpio_probe);
diff --git a/drivers/gpio/gpio-ts5500.c b/drivers/gpio/gpio-ts5500.c
index 5f945083f9d8..6cfeba07f882 100644
--- a/drivers/gpio/gpio-ts5500.c
+++ b/drivers/gpio/gpio-ts5500.c
@@ -409,7 +409,7 @@ static int ts5500_dio_probe(struct platform_device *pdev)
409 break; 409 break;
410 } 410 }
411 411
412 ret = gpiochip_add_data(&priv->gpio_chip, priv); 412 ret = devm_gpiochip_add_data(dev, &priv->gpio_chip, priv);
413 if (ret) { 413 if (ret) {
414 dev_err(dev, "failed to register the gpio chip\n"); 414 dev_err(dev, "failed to register the gpio chip\n");
415 return ret; 415 return ret;
@@ -418,13 +418,10 @@ static int ts5500_dio_probe(struct platform_device *pdev)
418 ret = ts5500_enable_irq(priv); 418 ret = ts5500_enable_irq(priv);
419 if (ret) { 419 if (ret) {
420 dev_err(dev, "invalid interrupt %d\n", priv->hwirq); 420 dev_err(dev, "invalid interrupt %d\n", priv->hwirq);
421 goto cleanup; 421 return ret;
422 } 422 }
423 423
424 return 0; 424 return 0;
425cleanup:
426 gpiochip_remove(&priv->gpio_chip);
427 return ret;
428} 425}
429 426
430static int ts5500_dio_remove(struct platform_device *pdev) 427static int ts5500_dio_remove(struct platform_device *pdev)
@@ -432,7 +429,7 @@ static int ts5500_dio_remove(struct platform_device *pdev)
432 struct ts5500_priv *priv = platform_get_drvdata(pdev); 429 struct ts5500_priv *priv = platform_get_drvdata(pdev);
433 430
434 ts5500_disable_irq(priv); 431 ts5500_disable_irq(priv);
435 gpiochip_remove(&priv->gpio_chip); 432
436 return 0; 433 return 0;
437} 434}
438 435
diff --git a/drivers/gpio/gpio-twl6040.c b/drivers/gpio/gpio-twl6040.c
index 8e9e9853f3bd..b780314cdfc9 100644
--- a/drivers/gpio/gpio-twl6040.c
+++ b/drivers/gpio/gpio-twl6040.c
@@ -100,7 +100,7 @@ static int gpo_twl6040_probe(struct platform_device *pdev)
100 twl6040gpo_chip.of_node = twl6040_core_dev->of_node; 100 twl6040gpo_chip.of_node = twl6040_core_dev->of_node;
101#endif 101#endif
102 102
103 ret = gpiochip_add_data(&twl6040gpo_chip, NULL); 103 ret = devm_gpiochip_add_data(&pdev->dev, &twl6040gpo_chip, NULL);
104 if (ret < 0) { 104 if (ret < 0) {
105 dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret); 105 dev_err(&pdev->dev, "could not register gpiochip, %d\n", ret);
106 twl6040gpo_chip.ngpio = 0; 106 twl6040gpo_chip.ngpio = 0;
@@ -109,12 +109,6 @@ static int gpo_twl6040_probe(struct platform_device *pdev)
109 return ret; 109 return ret;
110} 110}
111 111
112static int gpo_twl6040_remove(struct platform_device *pdev)
113{
114 gpiochip_remove(&twl6040gpo_chip);
115 return 0;
116}
117
118/* Note: this hardware lives inside an I2C-based multi-function device. */ 112/* Note: this hardware lives inside an I2C-based multi-function device. */
119MODULE_ALIAS("platform:twl6040-gpo"); 113MODULE_ALIAS("platform:twl6040-gpo");
120 114
@@ -123,7 +117,6 @@ static struct platform_driver gpo_twl6040_driver = {
123 .name = "twl6040-gpo", 117 .name = "twl6040-gpo",
124 }, 118 },
125 .probe = gpo_twl6040_probe, 119 .probe = gpo_twl6040_probe,
126 .remove = gpo_twl6040_remove,
127}; 120};
128 121
129module_platform_driver(gpo_twl6040_driver); 122module_platform_driver(gpo_twl6040_driver);
diff --git a/drivers/gpio/gpio-ucb1400.c b/drivers/gpio/gpio-ucb1400.c
index 2c5cd46bfa6e..5dbe31bf6699 100644
--- a/drivers/gpio/gpio-ucb1400.c
+++ b/drivers/gpio/gpio-ucb1400.c
@@ -67,7 +67,7 @@ static int ucb1400_gpio_probe(struct platform_device *dev)
67 ucb->gc.set = ucb1400_gpio_set; 67 ucb->gc.set = ucb1400_gpio_set;
68 ucb->gc.can_sleep = true; 68 ucb->gc.can_sleep = true;
69 69
70 err = gpiochip_add_data(&ucb->gc, ucb); 70 err = devm_gpiochip_add_data(&dev->dev, &ucb->gc, ucb);
71 if (err) 71 if (err)
72 goto err; 72 goto err;
73 73
@@ -90,7 +90,6 @@ static int ucb1400_gpio_remove(struct platform_device *dev)
90 return err; 90 return err;
91 } 91 }
92 92
93 gpiochip_remove(&ucb->gc);
94 return err; 93 return err;
95} 94}
96 95
diff --git a/drivers/gpio/gpio-viperboard.c b/drivers/gpio/gpio-viperboard.c
index 1170b035cb92..dec47aafd5cd 100644
--- a/drivers/gpio/gpio-viperboard.c
+++ b/drivers/gpio/gpio-viperboard.c
@@ -410,10 +410,10 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
410 vb_gpio->gpioa.get = vprbrd_gpioa_get; 410 vb_gpio->gpioa.get = vprbrd_gpioa_get;
411 vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input; 411 vb_gpio->gpioa.direction_input = vprbrd_gpioa_direction_input;
412 vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output; 412 vb_gpio->gpioa.direction_output = vprbrd_gpioa_direction_output;
413 ret = gpiochip_add_data(&vb_gpio->gpioa, vb_gpio); 413 ret = devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpioa, vb_gpio);
414 if (ret < 0) { 414 if (ret < 0) {
415 dev_err(vb_gpio->gpioa.parent, "could not add gpio a"); 415 dev_err(vb_gpio->gpioa.parent, "could not add gpio a");
416 goto err_gpioa; 416 return ret;
417 } 417 }
418 418
419 /* registering gpio b */ 419 /* registering gpio b */
@@ -427,37 +427,21 @@ static int vprbrd_gpio_probe(struct platform_device *pdev)
427 vb_gpio->gpiob.get = vprbrd_gpiob_get; 427 vb_gpio->gpiob.get = vprbrd_gpiob_get;
428 vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input; 428 vb_gpio->gpiob.direction_input = vprbrd_gpiob_direction_input;
429 vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output; 429 vb_gpio->gpiob.direction_output = vprbrd_gpiob_direction_output;
430 ret = gpiochip_add_data(&vb_gpio->gpiob, vb_gpio); 430 ret = devm_gpiochip_add_data(&pdev->dev, &vb_gpio->gpiob, vb_gpio);
431 if (ret < 0) { 431 if (ret < 0) {
432 dev_err(vb_gpio->gpiob.parent, "could not add gpio b"); 432 dev_err(vb_gpio->gpiob.parent, "could not add gpio b");
433 goto err_gpiob; 433 return ret;
434 } 434 }
435 435
436 platform_set_drvdata(pdev, vb_gpio); 436 platform_set_drvdata(pdev, vb_gpio);
437 437
438 return ret; 438 return ret;
439
440err_gpiob:
441 gpiochip_remove(&vb_gpio->gpioa);
442
443err_gpioa:
444 return ret;
445}
446
447static int vprbrd_gpio_remove(struct platform_device *pdev)
448{
449 struct vprbrd_gpio *vb_gpio = platform_get_drvdata(pdev);
450
451 gpiochip_remove(&vb_gpio->gpiob);
452
453 return 0;
454} 439}
455 440
456static struct platform_driver vprbrd_gpio_driver = { 441static struct platform_driver vprbrd_gpio_driver = {
457 .driver.name = "viperboard-gpio", 442 .driver.name = "viperboard-gpio",
458 .driver.owner = THIS_MODULE, 443 .driver.owner = THIS_MODULE,
459 .probe = vprbrd_gpio_probe, 444 .probe = vprbrd_gpio_probe,
460 .remove = vprbrd_gpio_remove,
461}; 445};
462 446
463static int __init vprbrd_gpio_init(void) 447static int __init vprbrd_gpio_init(void)
diff --git a/drivers/gpio/gpio-vx855.c b/drivers/gpio/gpio-vx855.c
index 764999cc0794..8cdb9f7ec7e0 100644
--- a/drivers/gpio/gpio-vx855.c
+++ b/drivers/gpio/gpio-vx855.c
@@ -259,16 +259,7 @@ static int vx855gpio_probe(struct platform_device *pdev)
259 259
260 vx855gpio_gpio_setup(vg); 260 vx855gpio_gpio_setup(vg);
261 261
262 return gpiochip_add_data(&vg->gpio, vg); 262 return devm_gpiochip_add_data(&pdev->dev, &vg->gpio, vg);
263}
264
265static int vx855gpio_remove(struct platform_device *pdev)
266{
267 struct vx855_gpio *vg = platform_get_drvdata(pdev);
268
269 gpiochip_remove(&vg->gpio);
270
271 return 0;
272} 263}
273 264
274static struct platform_driver vx855gpio_driver = { 265static struct platform_driver vx855gpio_driver = {
@@ -276,7 +267,6 @@ static struct platform_driver vx855gpio_driver = {
276 .name = MODULE_NAME, 267 .name = MODULE_NAME,
277 }, 268 },
278 .probe = vx855gpio_probe, 269 .probe = vx855gpio_probe,
279 .remove = vx855gpio_remove,
280}; 270};
281 271
282module_platform_driver(vx855gpio_driver); 272module_platform_driver(vx855gpio_driver);
diff --git a/drivers/gpio/gpio-wm831x.c b/drivers/gpio/gpio-wm831x.c
index 98390070fb64..18cb0f534b91 100644
--- a/drivers/gpio/gpio-wm831x.c
+++ b/drivers/gpio/gpio-wm831x.c
@@ -259,7 +259,8 @@ static int wm831x_gpio_probe(struct platform_device *pdev)
259 else 259 else
260 wm831x_gpio->gpio_chip.base = -1; 260 wm831x_gpio->gpio_chip.base = -1;
261 261
262 ret = gpiochip_add_data(&wm831x_gpio->gpio_chip, wm831x_gpio); 262 ret = devm_gpiochip_add_data(&pdev->dev, &wm831x_gpio->gpio_chip,
263 wm831x_gpio);
263 if (ret < 0) { 264 if (ret < 0) {
264 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 265 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
265 return ret; 266 return ret;
@@ -270,19 +271,10 @@ static int wm831x_gpio_probe(struct platform_device *pdev)
270 return ret; 271 return ret;
271} 272}
272 273
273static int wm831x_gpio_remove(struct platform_device *pdev)
274{
275 struct wm831x_gpio *wm831x_gpio = platform_get_drvdata(pdev);
276
277 gpiochip_remove(&wm831x_gpio->gpio_chip);
278 return 0;
279}
280
281static struct platform_driver wm831x_gpio_driver = { 274static struct platform_driver wm831x_gpio_driver = {
282 .driver.name = "wm831x-gpio", 275 .driver.name = "wm831x-gpio",
283 .driver.owner = THIS_MODULE, 276 .driver.owner = THIS_MODULE,
284 .probe = wm831x_gpio_probe, 277 .probe = wm831x_gpio_probe,
285 .remove = wm831x_gpio_remove,
286}; 278};
287 279
288static int __init wm831x_gpio_init(void) 280static int __init wm831x_gpio_init(void)
diff --git a/drivers/gpio/gpio-wm8350.c b/drivers/gpio/gpio-wm8350.c
index 0a306b4baa73..07d45a3b205a 100644
--- a/drivers/gpio/gpio-wm8350.c
+++ b/drivers/gpio/gpio-wm8350.c
@@ -125,7 +125,8 @@ static int wm8350_gpio_probe(struct platform_device *pdev)
125 else 125 else
126 wm8350_gpio->gpio_chip.base = -1; 126 wm8350_gpio->gpio_chip.base = -1;
127 127
128 ret = gpiochip_add_data(&wm8350_gpio->gpio_chip, wm8350_gpio); 128 ret = devm_gpiochip_add_data(&pdev->dev, &wm8350_gpio->gpio_chip,
129 wm8350_gpio);
129 if (ret < 0) { 130 if (ret < 0) {
130 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret); 131 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", ret);
131 return ret; 132 return ret;
@@ -136,19 +137,10 @@ static int wm8350_gpio_probe(struct platform_device *pdev)
136 return ret; 137 return ret;
137} 138}
138 139
139static int wm8350_gpio_remove(struct platform_device *pdev)
140{
141 struct wm8350_gpio_data *wm8350_gpio = platform_get_drvdata(pdev);
142
143 gpiochip_remove(&wm8350_gpio->gpio_chip);
144 return 0;
145}
146
147static struct platform_driver wm8350_gpio_driver = { 140static struct platform_driver wm8350_gpio_driver = {
148 .driver.name = "wm8350-gpio", 141 .driver.name = "wm8350-gpio",
149 .driver.owner = THIS_MODULE, 142 .driver.owner = THIS_MODULE,
150 .probe = wm8350_gpio_probe, 143 .probe = wm8350_gpio_probe,
151 .remove = wm8350_gpio_remove,
152}; 144};
153 145
154static int __init wm8350_gpio_init(void) 146static int __init wm8350_gpio_init(void)
diff --git a/drivers/gpio/gpio-wm8994.c b/drivers/gpio/gpio-wm8994.c
index 3ae4c1597494..b089df99a0d0 100644
--- a/drivers/gpio/gpio-wm8994.c
+++ b/drivers/gpio/gpio-wm8994.c
@@ -261,34 +261,23 @@ static int wm8994_gpio_probe(struct platform_device *pdev)
261 else 261 else
262 wm8994_gpio->gpio_chip.base = -1; 262 wm8994_gpio->gpio_chip.base = -1;
263 263
264 ret = gpiochip_add_data(&wm8994_gpio->gpio_chip, wm8994_gpio); 264 ret = devm_gpiochip_add_data(&pdev->dev, &wm8994_gpio->gpio_chip,
265 wm8994_gpio);
265 if (ret < 0) { 266 if (ret < 0) {
266 dev_err(&pdev->dev, "Could not register gpiochip, %d\n", 267 dev_err(&pdev->dev, "Could not register gpiochip, %d\n",
267 ret); 268 ret);
268 goto err; 269 return ret;
269 } 270 }
270 271
271 platform_set_drvdata(pdev, wm8994_gpio); 272 platform_set_drvdata(pdev, wm8994_gpio);
272 273
273 return ret; 274 return ret;
274
275err:
276 return ret;
277}
278
279static int wm8994_gpio_remove(struct platform_device *pdev)
280{
281 struct wm8994_gpio *wm8994_gpio = platform_get_drvdata(pdev);
282
283 gpiochip_remove(&wm8994_gpio->gpio_chip);
284 return 0;
285} 275}
286 276
287static struct platform_driver wm8994_gpio_driver = { 277static struct platform_driver wm8994_gpio_driver = {
288 .driver.name = "wm8994-gpio", 278 .driver.name = "wm8994-gpio",
289 .driver.owner = THIS_MODULE, 279 .driver.owner = THIS_MODULE,
290 .probe = wm8994_gpio_probe, 280 .probe = wm8994_gpio_probe,
291 .remove = wm8994_gpio_remove,
292}; 281};
293 282
294static int __init wm8994_gpio_init(void) 283static int __init wm8994_gpio_init(void)
diff --git a/drivers/gpio/gpio-xgene-sb.c b/drivers/gpio/gpio-xgene-sb.c
index fd81ebc8d365..31cbcb84cfaf 100644
--- a/drivers/gpio/gpio-xgene-sb.c
+++ b/drivers/gpio/gpio-xgene-sb.c
@@ -311,7 +311,7 @@ static int xgene_gpio_sb_probe(struct platform_device *pdev)
311 311
312 priv->gc.irqdomain = priv->irq_domain; 312 priv->gc.irqdomain = priv->irq_domain;
313 313
314 ret = gpiochip_add_data(&priv->gc, priv); 314 ret = devm_gpiochip_add_data(&pdev->dev, &priv->gc, priv);
315 if (ret) { 315 if (ret) {
316 dev_err(&pdev->dev, 316 dev_err(&pdev->dev,
317 "failed to register X-Gene GPIO Standby driver\n"); 317 "failed to register X-Gene GPIO Standby driver\n");
@@ -339,7 +339,6 @@ static int xgene_gpio_sb_remove(struct platform_device *pdev)
339 339
340 irq_domain_remove(priv->irq_domain); 340 irq_domain_remove(priv->irq_domain);
341 341
342 gpiochip_remove(&priv->gc);
343 return 0; 342 return 0;
344} 343}
345 344
diff --git a/drivers/gpio/gpio-xgene.c b/drivers/gpio/gpio-xgene.c
index 592e9cdf9c53..c0aa387664bf 100644
--- a/drivers/gpio/gpio-xgene.c
+++ b/drivers/gpio/gpio-xgene.c
@@ -193,7 +193,7 @@ static int xgene_gpio_probe(struct platform_device *pdev)
193 193
194 platform_set_drvdata(pdev, gpio); 194 platform_set_drvdata(pdev, gpio);
195 195
196 err = gpiochip_add_data(&gpio->chip, gpio); 196 err = devm_gpiochip_add_data(&pdev->dev, &gpio->chip, gpio);
197 if (err) { 197 if (err) {
198 dev_err(&pdev->dev, 198 dev_err(&pdev->dev,
199 "failed to register gpiochip.\n"); 199 "failed to register gpiochip.\n");
@@ -207,14 +207,6 @@ err:
207 return err; 207 return err;
208} 208}
209 209
210static int xgene_gpio_remove(struct platform_device *pdev)
211{
212 struct xgene_gpio *gpio = platform_get_drvdata(pdev);
213
214 gpiochip_remove(&gpio->chip);
215 return 0;
216}
217
218static const struct of_device_id xgene_gpio_of_match[] = { 210static const struct of_device_id xgene_gpio_of_match[] = {
219 { .compatible = "apm,xgene-gpio", }, 211 { .compatible = "apm,xgene-gpio", },
220 {}, 212 {},
@@ -228,7 +220,6 @@ static struct platform_driver xgene_gpio_driver = {
228 .pm = XGENE_GPIO_PM_OPS, 220 .pm = XGENE_GPIO_PM_OPS,
229 }, 221 },
230 .probe = xgene_gpio_probe, 222 .probe = xgene_gpio_probe,
231 .remove = xgene_gpio_remove,
232}; 223};
233 224
234module_platform_driver(xgene_gpio_driver); 225module_platform_driver(xgene_gpio_driver);
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 872774a404f1..e31d0a1e6f7c 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -723,6 +723,80 @@ void gpiochip_remove(struct gpio_chip *chip)
723} 723}
724EXPORT_SYMBOL_GPL(gpiochip_remove); 724EXPORT_SYMBOL_GPL(gpiochip_remove);
725 725
726static void devm_gpio_chip_release(struct device *dev, void *res)
727{
728 struct gpio_chip *chip = *(struct gpio_chip **)res;
729
730 gpiochip_remove(chip);
731}
732
733static int devm_gpio_chip_match(struct device *dev, void *res, void *data)
734
735{
736 struct gpio_chip **r = res;
737
738 if (!r || !*r) {
739 WARN_ON(!r || !*r);
740 return 0;
741 }
742
743 return *r == data;
744}
745
746/**
747 * devm_gpiochip_add_data() - Resource manager piochip_add_data()
748 * @dev: the device pointer on which irq_chip belongs to.
749 * @chip: the chip to register, with chip->base initialized
750 * Context: potentially before irqs will work
751 *
752 * Returns a negative errno if the chip can't be registered, such as
753 * because the chip->base is invalid or already associated with a
754 * different chip. Otherwise it returns zero as a success code.
755 *
756 * The gpio chip automatically be released when the device is unbound.
757 */
758int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip,
759 void *data)
760{
761 struct gpio_chip **ptr;
762 int ret;
763
764 ptr = devres_alloc(devm_gpio_chip_release, sizeof(*ptr),
765 GFP_KERNEL);
766 if (!ptr)
767 return -ENOMEM;
768
769 ret = gpiochip_add_data(chip, data);
770 if (ret < 0) {
771 devres_free(ptr);
772 return ret;
773 }
774
775 *ptr = chip;
776 devres_add(dev, ptr);
777
778 return 0;
779}
780EXPORT_SYMBOL_GPL(devm_gpiochip_add_data);
781
782/**
783 * devm_gpiochip_remove() - Resource manager of gpiochip_remove()
784 * @dev: device for which which resource was allocated
785 * @chip: the chip to remove
786 *
787 * A gpio_chip with any GPIOs still requested may not be removed.
788 */
789void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip)
790{
791 int ret;
792
793 ret = devres_release(dev, devm_gpio_chip_release,
794 devm_gpio_chip_match, chip);
795 if (!ret)
796 WARN_ON(ret);
797}
798EXPORT_SYMBOL_GPL(devm_gpiochip_remove);
799
726/** 800/**
727 * gpiochip_find() - iterator for locating a specific gpio_chip 801 * gpiochip_find() - iterator for locating a specific gpio_chip
728 * @data: data to pass to match function 802 * @data: data to pass to match function
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index 639607658ed8..bee976f82788 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -192,6 +192,10 @@ static inline int gpiochip_add(struct gpio_chip *chip)
192 return gpiochip_add_data(chip, NULL); 192 return gpiochip_add_data(chip, NULL);
193} 193}
194extern void gpiochip_remove(struct gpio_chip *chip); 194extern void gpiochip_remove(struct gpio_chip *chip);
195extern int devm_gpiochip_add_data(struct device *dev, struct gpio_chip *chip,
196 void *data);
197extern void devm_gpiochip_remove(struct device *dev, struct gpio_chip *chip);
198
195extern struct gpio_chip *gpiochip_find(void *data, 199extern struct gpio_chip *gpiochip_find(void *data,
196 int (*match)(struct gpio_chip *chip, void *data)); 200 int (*match)(struct gpio_chip *chip, void *data));
197 201