Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

soc: fsl: qe: Drop legacy-of-mm-gpiochip.h header from GPIO driver

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.

As a side effect this change fixes a potential memory leak on
an error path, if of_mm_gpiochip_add_data() fails.

[Text copied from commit 34064c8267a6 ("powerpc/8xx: Drop
legacy-of-mm-gpiochip.h header")]

Suggested-by: Bartosz Golaszewski <brgl@bgdev.pl>
Reviewed-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Link: https://lore.kernel.org/r/e8a5d2c5b72233bd36da7fecc0a551ca54d39478.1758212309.git.christophe.leroy@csgroup.eu
Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu>

+27 -25
-1
arch/powerpc/platforms/Kconfig
··· 232 232 bool "QE GPIO support" 233 233 depends on QUICC_ENGINE 234 234 select GPIOLIB 235 - select OF_GPIO_MM_GPIOCHIP 236 235 help 237 236 Say Y here if you're going to use hardware that connects to the 238 237 QE GPIOs.
+27 -24
drivers/soc/fsl/qe/gpio.c
··· 12 12 #include <linux/spinlock.h> 13 13 #include <linux/err.h> 14 14 #include <linux/io.h> 15 - #include <linux/gpio/legacy-of-mm-gpiochip.h> 16 15 #include <linux/gpio/consumer.h> 17 16 #include <linux/gpio/driver.h> 18 17 #include <linux/slab.h> ··· 23 24 #define PIN_MASK(gpio) (1UL << (QE_PIO_PINS - 1 - (gpio))) 24 25 25 26 struct qe_gpio_chip { 26 - struct of_mm_gpio_chip mm_gc; 27 + struct gpio_chip gc; 28 + void __iomem *regs; 27 29 spinlock_t lock; 28 30 29 31 /* shadowed data register to clear/set bits safely */ ··· 34 34 struct qe_pio_regs saved_regs; 35 35 }; 36 36 37 - static void qe_gpio_save_regs(struct of_mm_gpio_chip *mm_gc) 37 + static void qe_gpio_save_regs(struct qe_gpio_chip *qe_gc) 38 38 { 39 - struct qe_gpio_chip *qe_gc = 40 - container_of(mm_gc, struct qe_gpio_chip, mm_gc); 41 - struct qe_pio_regs __iomem *regs = mm_gc->regs; 39 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 42 40 43 41 qe_gc->cpdata = ioread32be(&regs->cpdata); 44 42 qe_gc->saved_regs.cpdata = qe_gc->cpdata; ··· 49 51 50 52 static int qe_gpio_get(struct gpio_chip *gc, unsigned int gpio) 51 53 { 52 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 53 - struct qe_pio_regs __iomem *regs = mm_gc->regs; 54 + struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 55 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 54 56 u32 pin_mask = PIN_MASK(gpio); 55 57 56 58 return !!(ioread32be(&regs->cpdata) & pin_mask); ··· 58 60 59 61 static int qe_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val) 60 62 { 61 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 62 63 struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 63 - struct qe_pio_regs __iomem *regs = mm_gc->regs; 64 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 64 65 unsigned long flags; 65 66 u32 pin_mask = PIN_MASK(gpio); 66 67 ··· 80 83 static int qe_gpio_set_multiple(struct gpio_chip *gc, 81 84 unsigned long *mask, unsigned long *bits) 82 85 { 83 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 84 86 struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 85 - struct qe_pio_regs __iomem *regs = mm_gc->regs; 87 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 86 88 unsigned long flags; 87 89 int i; 88 90 ··· 107 111 108 112 static int qe_gpio_dir_in(struct gpio_chip *gc, unsigned int gpio) 109 113 { 110 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 111 114 struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 112 115 unsigned long flags; 113 116 114 117 spin_lock_irqsave(&qe_gc->lock, flags); 115 118 116 - __par_io_config_pin(mm_gc->regs, gpio, QE_PIO_DIR_IN, 0, 0, 0); 119 + __par_io_config_pin(qe_gc->regs, gpio, QE_PIO_DIR_IN, 0, 0, 0); 117 120 118 121 spin_unlock_irqrestore(&qe_gc->lock, flags); 119 122 ··· 121 126 122 127 static int qe_gpio_dir_out(struct gpio_chip *gc, unsigned int gpio, int val) 123 128 { 124 - struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 125 129 struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 126 130 unsigned long flags; 127 131 ··· 128 134 129 135 spin_lock_irqsave(&qe_gc->lock, flags); 130 136 131 - __par_io_config_pin(mm_gc->regs, gpio, QE_PIO_DIR_OUT, 0, 0, 0); 137 + __par_io_config_pin(qe_gc->regs, gpio, QE_PIO_DIR_OUT, 0, 0, 0); 132 138 133 139 spin_unlock_irqrestore(&qe_gc->lock, flags); 134 140 ··· 234 240 void qe_pin_set_dedicated(struct qe_pin *qe_pin) 235 241 { 236 242 struct qe_gpio_chip *qe_gc = qe_pin->controller; 237 - struct qe_pio_regs __iomem *regs = qe_gc->mm_gc.regs; 243 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 238 244 struct qe_pio_regs *sregs = &qe_gc->saved_regs; 239 245 int pin = qe_pin->num; 240 246 u32 mask1 = 1 << (QE_PIO_PINS - (pin + 1)); ··· 263 269 264 270 iowrite32be(qe_gc->cpdata, &regs->cpdata); 265 271 qe_clrsetbits_be32(&regs->cpodr, mask1, sregs->cpodr & mask1); 266 - 267 272 spin_unlock_irqrestore(&qe_gc->lock, flags); 268 273 } 269 274 EXPORT_SYMBOL(qe_pin_set_dedicated); ··· 277 284 void qe_pin_set_gpio(struct qe_pin *qe_pin) 278 285 { 279 286 struct qe_gpio_chip *qe_gc = qe_pin->controller; 280 - struct qe_pio_regs __iomem *regs = qe_gc->mm_gc.regs; 287 + struct qe_pio_regs __iomem *regs = qe_gc->regs; 281 288 unsigned long flags; 282 289 283 290 spin_lock_irqsave(&qe_gc->lock, flags); ··· 294 301 struct device *dev = &ofdev->dev; 295 302 struct device_node *np = dev->of_node; 296 303 struct qe_gpio_chip *qe_gc; 297 - struct of_mm_gpio_chip *mm_gc; 298 304 struct gpio_chip *gc; 299 305 300 306 qe_gc = devm_kzalloc(dev, sizeof(*qe_gc), GFP_KERNEL); ··· 302 310 303 311 spin_lock_init(&qe_gc->lock); 304 312 305 - mm_gc = &qe_gc->mm_gc; 306 - gc = &mm_gc->gc; 313 + gc = &qe_gc->gc; 307 314 308 - mm_gc->save_regs = qe_gpio_save_regs; 315 + gc->base = -1; 309 316 gc->ngpio = QE_PIO_PINS; 310 317 gc->direction_input = qe_gpio_dir_in; 311 318 gc->direction_output = qe_gpio_dir_out; 312 319 gc->get = qe_gpio_get; 313 320 gc->set = qe_gpio_set; 314 321 gc->set_multiple = qe_gpio_set_multiple; 322 + gc->parent = dev; 323 + gc->owner = THIS_MODULE; 315 324 316 - return of_mm_gpiochip_add_data(np, mm_gc, qe_gc); 325 + gc->label = devm_kasprintf(dev, GFP_KERNEL, "%pOF", np); 326 + if (!gc->label) 327 + return -ENOMEM; 328 + 329 + qe_gc->regs = devm_of_iomap(dev, np, 0, NULL); 330 + if (IS_ERR(qe_gc->regs)) 331 + return PTR_ERR(qe_gc->regs); 332 + 333 + qe_gpio_save_regs(qe_gc); 334 + 335 + return devm_gpiochip_add_data(dev, gc, qe_gc); 317 336 } 318 337 319 338 static const struct of_device_id qe_gpio_match[] = {