Skip to content

Commit e7a6475

Browse files
chleroymaddy-kerneldev
authored andcommitted
gpio: mpc5200: Drop legacy-of-mm-gpiochip.h header
Remove legacy-of-mm-gpiochip.h header file. The above mentioned file provides an OF API that's deprecated. There is no agnostic alternatives to it and we have to open code the logic which was hidden behind of_mm_gpiochip_add_data(). Note, most of the GPIO drivers are using their own labeling schemas and resource retrieval that only a few may gain of the code deduplication, so whenever alternative is appear we can move drivers again to use that one. [text copied from commit 34064c8 ("powerpc/8xx: Drop legacy-of-mm-gpiochip.h header")] Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Madhavan Srinivasan <maddy@linux.ibm.com> Link: https://patch.msgid.link/9652736ef05b94d9113ea5ce7899734ef82343d1.1755520794.git.christophe.leroy@csgroup.eu
1 parent d2ad26e commit e7a6475

File tree

2 files changed

+43
-36
lines changed

2 files changed

+43
-36
lines changed

drivers/gpio/Kconfig

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,6 @@ config GPIO_MM_LANTIQ
485485
config GPIO_MPC5200
486486
def_bool y
487487
depends on PPC_MPC52xx
488-
select OF_GPIO_MM_GPIOCHIP
489488

490489
config GPIO_MPC8XXX
491490
bool "MPC512x/MPC8xxx/QorIQ GPIO support"

drivers/gpio/gpio-mpc5200.c

Lines changed: 43 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <linux/of.h>
99
#include <linux/kernel.h>
1010
#include <linux/slab.h>
11-
#include <linux/gpio/legacy-of-mm-gpiochip.h>
11+
#include <linux/gpio/driver.h>
1212
#include <linux/io.h>
1313
#include <linux/platform_device.h>
1414
#include <linux/module.h>
@@ -19,7 +19,8 @@
1919
static DEFINE_SPINLOCK(gpio_lock);
2020

2121
struct mpc52xx_gpiochip {
22-
struct of_mm_gpio_chip mmchip;
22+
struct gpio_chip gc;
23+
void __iomem *regs;
2324
unsigned int shadow_dvo;
2425
unsigned int shadow_gpioe;
2526
unsigned int shadow_ddr;
@@ -43,8 +44,8 @@ struct mpc52xx_gpiochip {
4344
*/
4445
static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
4546
{
46-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
47-
struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
47+
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
48+
struct mpc52xx_gpio_wkup __iomem *regs = chip->regs;
4849
unsigned int ret;
4950

5051
ret = (in_8(&regs->wkup_ival) >> (7 - gpio)) & 1;
@@ -57,9 +58,8 @@ static int mpc52xx_wkup_gpio_get(struct gpio_chip *gc, unsigned int gpio)
5758
static inline void
5859
__mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
5960
{
60-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
6161
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
62-
struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
62+
struct mpc52xx_gpio_wkup __iomem *regs = chip->regs;
6363

6464
if (val)
6565
chip->shadow_dvo |= 1 << (7 - gpio);
@@ -87,9 +87,8 @@ mpc52xx_wkup_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
8787

8888
static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
8989
{
90-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
9190
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
92-
struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
91+
struct mpc52xx_gpio_wkup __iomem *regs = chip->regs;
9392
unsigned long flags;
9493

9594
spin_lock_irqsave(&gpio_lock, flags);
@@ -110,9 +109,8 @@ static int mpc52xx_wkup_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
110109
static int
111110
mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
112111
{
113-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
114-
struct mpc52xx_gpio_wkup __iomem *regs = mm_gc->regs;
115112
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
113+
struct mpc52xx_gpio_wkup __iomem *regs = chip->regs;
116114
unsigned long flags;
117115

118116
spin_lock_irqsave(&gpio_lock, flags);
@@ -136,44 +134,48 @@ mpc52xx_wkup_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
136134

137135
static int mpc52xx_wkup_gpiochip_probe(struct platform_device *ofdev)
138136
{
137+
struct device *dev = &ofdev->dev;
138+
struct device_node *np = dev->of_node;
139139
struct mpc52xx_gpiochip *chip;
140140
struct mpc52xx_gpio_wkup __iomem *regs;
141141
struct gpio_chip *gc;
142142
int ret;
143143

144-
chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
144+
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
145145
if (!chip)
146146
return -ENOMEM;
147147

148148
platform_set_drvdata(ofdev, chip);
149149

150-
gc = &chip->mmchip.gc;
150+
gc = &chip->gc;
151151

152+
gc->base = -1;
152153
gc->ngpio = 8;
153154
gc->direction_input = mpc52xx_wkup_gpio_dir_in;
154155
gc->direction_output = mpc52xx_wkup_gpio_dir_out;
155156
gc->get = mpc52xx_wkup_gpio_get;
156157
gc->set = mpc52xx_wkup_gpio_set;
157158

158-
ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
159+
gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
160+
if (!gc->label)
161+
return -ENOMEM;
162+
163+
chip->regs = devm_of_iomap(dev, np, 0, NULL);
164+
if (IS_ERR(chip->regs))
165+
return PTR_ERR(chip->regs);
166+
167+
ret = devm_gpiochip_add_data(dev, gc, chip);
159168
if (ret)
160169
return ret;
161170

162-
regs = chip->mmchip.regs;
171+
regs = chip->regs;
163172
chip->shadow_gpioe = in_8(&regs->wkup_gpioe);
164173
chip->shadow_ddr = in_8(&regs->wkup_ddr);
165174
chip->shadow_dvo = in_8(&regs->wkup_dvo);
166175

167176
return 0;
168177
}
169178

170-
static void mpc52xx_gpiochip_remove(struct platform_device *ofdev)
171-
{
172-
struct mpc52xx_gpiochip *chip = platform_get_drvdata(ofdev);
173-
174-
of_mm_gpiochip_remove(&chip->mmchip);
175-
}
176-
177179
static const struct of_device_id mpc52xx_wkup_gpiochip_match[] = {
178180
{ .compatible = "fsl,mpc5200-gpio-wkup", },
179181
{}
@@ -185,7 +187,6 @@ static struct platform_driver mpc52xx_wkup_gpiochip_driver = {
185187
.of_match_table = mpc52xx_wkup_gpiochip_match,
186188
},
187189
.probe = mpc52xx_wkup_gpiochip_probe,
188-
.remove = mpc52xx_gpiochip_remove,
189190
};
190191

191192
/*
@@ -207,8 +208,8 @@ static struct platform_driver mpc52xx_wkup_gpiochip_driver = {
207208
*/
208209
static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
209210
{
210-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
211-
struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
211+
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
212+
struct mpc52xx_gpio __iomem *regs = chip->regs;
212213
unsigned int ret;
213214

214215
ret = (in_be32(&regs->simple_ival) >> (31 - gpio)) & 1;
@@ -219,9 +220,8 @@ static int mpc52xx_simple_gpio_get(struct gpio_chip *gc, unsigned int gpio)
219220
static inline void
220221
__mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
221222
{
222-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
223223
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
224-
struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
224+
struct mpc52xx_gpio __iomem *regs = chip->regs;
225225

226226
if (val)
227227
chip->shadow_dvo |= 1 << (31 - gpio);
@@ -248,9 +248,8 @@ mpc52xx_simple_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
248248

249249
static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
250250
{
251-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
252251
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
253-
struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
252+
struct mpc52xx_gpio __iomem *regs = chip->regs;
254253
unsigned long flags;
255254

256255
spin_lock_irqsave(&gpio_lock, flags);
@@ -271,9 +270,8 @@ static int mpc52xx_simple_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio)
271270
static int
272271
mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
273272
{
274-
struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc);
275273
struct mpc52xx_gpiochip *chip = gpiochip_get_data(gc);
276-
struct mpc52xx_gpio __iomem *regs = mm_gc->regs;
274+
struct mpc52xx_gpio __iomem *regs = chip->regs;
277275
unsigned long flags;
278276

279277
spin_lock_irqsave(&gpio_lock, flags);
@@ -298,30 +296,41 @@ mpc52xx_simple_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val)
298296

299297
static int mpc52xx_simple_gpiochip_probe(struct platform_device *ofdev)
300298
{
299+
struct device *dev = &ofdev->dev;
300+
struct device_node *np = dev->of_node;
301301
struct mpc52xx_gpiochip *chip;
302302
struct gpio_chip *gc;
303303
struct mpc52xx_gpio __iomem *regs;
304304
int ret;
305305

306-
chip = devm_kzalloc(&ofdev->dev, sizeof(*chip), GFP_KERNEL);
306+
chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
307307
if (!chip)
308308
return -ENOMEM;
309309

310310
platform_set_drvdata(ofdev, chip);
311311

312-
gc = &chip->mmchip.gc;
312+
gc = &chip->gc;
313313

314+
gc->base = -1;
314315
gc->ngpio = 32;
315316
gc->direction_input = mpc52xx_simple_gpio_dir_in;
316317
gc->direction_output = mpc52xx_simple_gpio_dir_out;
317318
gc->get = mpc52xx_simple_gpio_get;
318319
gc->set = mpc52xx_simple_gpio_set;
319320

320-
ret = of_mm_gpiochip_add_data(ofdev->dev.of_node, &chip->mmchip, chip);
321+
gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np);
322+
if (!gc->label)
323+
return -ENOMEM;
324+
325+
chip->regs = devm_of_iomap(dev, np, 0, NULL);
326+
if (IS_ERR(chip->regs))
327+
return PTR_ERR(chip->regs);
328+
329+
ret = devm_gpiochip_add_data(dev, gc, chip);
321330
if (ret)
322331
return ret;
323332

324-
regs = chip->mmchip.regs;
333+
regs = chip->regs;
325334
chip->shadow_gpioe = in_be32(&regs->simple_gpioe);
326335
chip->shadow_ddr = in_be32(&regs->simple_ddr);
327336
chip->shadow_dvo = in_be32(&regs->simple_dvo);
@@ -340,7 +349,6 @@ static struct platform_driver mpc52xx_simple_gpiochip_driver = {
340349
.of_match_table = mpc52xx_simple_gpiochip_match,
341350
},
342351
.probe = mpc52xx_simple_gpiochip_probe,
343-
.remove = mpc52xx_gpiochip_remove,
344352
};
345353

346354
static struct platform_driver * const drivers[] = {

0 commit comments

Comments
 (0)