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

soc: fsl: qe: Change GPIO driver to a proper platform driver

In order to be able to add interrupts to the GPIOs, first change the
QE GPIO driver to the proper platform driver in order to allow
initialisation to be done in the right order, otherwise the GPIOs
get added before the interrupts are registered.

Remove linux/of.h and linux/property.h which are unused.

And to improve readability and reduce risk of errors, add a macro to
transform a pin number into the mask that matches the associated bit
in registers.

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

+49 -41
+49 -41
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/of.h> 16 15 #include <linux/gpio/legacy-of-mm-gpiochip.h> 17 16 #include <linux/gpio/consumer.h> 18 17 #include <linux/gpio/driver.h> 19 18 #include <linux/slab.h> 20 19 #include <linux/export.h> 21 - #include <linux/property.h> 20 + #include <linux/platform_device.h> 22 21 23 22 #include <soc/fsl/qe/qe.h> 23 + 24 + #define PIN_MASK(gpio) (1UL << (QE_PIO_PINS - 1 - (gpio))) 24 25 25 26 struct qe_gpio_chip { 26 27 struct of_mm_gpio_chip mm_gc; ··· 53 52 { 54 53 struct of_mm_gpio_chip *mm_gc = to_of_mm_gpio_chip(gc); 55 54 struct qe_pio_regs __iomem *regs = mm_gc->regs; 56 - u32 pin_mask = 1 << (QE_PIO_PINS - 1 - gpio); 55 + u32 pin_mask = PIN_MASK(gpio); 57 56 58 57 return !!(ioread32be(&regs->cpdata) & pin_mask); 59 58 } ··· 64 63 struct qe_gpio_chip *qe_gc = gpiochip_get_data(gc); 65 64 struct qe_pio_regs __iomem *regs = mm_gc->regs; 66 65 unsigned long flags; 67 - u32 pin_mask = 1 << (QE_PIO_PINS - 1 - gpio); 66 + u32 pin_mask = PIN_MASK(gpio); 68 67 69 68 spin_lock_irqsave(&qe_gc->lock, flags); 70 69 ··· 96 95 break; 97 96 if (__test_and_clear_bit(i, mask)) { 98 97 if (test_bit(i, bits)) 99 - qe_gc->cpdata |= (1U << (QE_PIO_PINS - 1 - i)); 98 + qe_gc->cpdata |= PIN_MASK(i); 100 99 else 101 - qe_gc->cpdata &= ~(1U << (QE_PIO_PINS - 1 - i)); 100 + qe_gc->cpdata &= ~PIN_MASK(i); 102 101 } 103 102 } 104 103 ··· 296 295 } 297 296 EXPORT_SYMBOL(qe_pin_set_gpio); 298 297 299 - static int __init qe_add_gpiochips(void) 298 + static int qe_gpio_probe(struct platform_device *ofdev) 300 299 { 301 - struct device_node *np; 300 + struct device *dev = &ofdev->dev; 301 + struct device_node *np = dev->of_node; 302 + struct qe_gpio_chip *qe_gc; 303 + struct of_mm_gpio_chip *mm_gc; 304 + struct gpio_chip *gc; 302 305 303 - for_each_compatible_node(np, NULL, "fsl,mpc8323-qe-pario-bank") { 304 - int ret; 305 - struct qe_gpio_chip *qe_gc; 306 - struct of_mm_gpio_chip *mm_gc; 307 - struct gpio_chip *gc; 306 + qe_gc = devm_kzalloc(dev, sizeof(*qe_gc), GFP_KERNEL); 307 + if (!qe_gc) 308 + return -ENOMEM; 308 309 309 - qe_gc = kzalloc(sizeof(*qe_gc), GFP_KERNEL); 310 - if (!qe_gc) { 311 - ret = -ENOMEM; 312 - goto err; 313 - } 310 + spin_lock_init(&qe_gc->lock); 314 311 315 - spin_lock_init(&qe_gc->lock); 312 + mm_gc = &qe_gc->mm_gc; 313 + gc = &mm_gc->gc; 316 314 317 - mm_gc = &qe_gc->mm_gc; 318 - gc = &mm_gc->gc; 315 + mm_gc->save_regs = qe_gpio_save_regs; 316 + gc->ngpio = QE_PIO_PINS; 317 + gc->direction_input = qe_gpio_dir_in; 318 + gc->direction_output = qe_gpio_dir_out; 319 + gc->get = qe_gpio_get; 320 + gc->set = qe_gpio_set; 321 + gc->set_multiple = qe_gpio_set_multiple; 319 322 320 - mm_gc->save_regs = qe_gpio_save_regs; 321 - gc->ngpio = QE_PIO_PINS; 322 - gc->direction_input = qe_gpio_dir_in; 323 - gc->direction_output = qe_gpio_dir_out; 324 - gc->get = qe_gpio_get; 325 - gc->set = qe_gpio_set; 326 - gc->set_multiple = qe_gpio_set_multiple; 327 - 328 - ret = of_mm_gpiochip_add_data(np, mm_gc, qe_gc); 329 - if (ret) 330 - goto err; 331 - continue; 332 - err: 333 - pr_err("%pOF: registration failed with status %d\n", 334 - np, ret); 335 - kfree(qe_gc); 336 - /* try others anyway */ 337 - } 338 - return 0; 323 + return of_mm_gpiochip_add_data(np, mm_gc, qe_gc); 339 324 } 340 - arch_initcall(qe_add_gpiochips); 325 + 326 + static const struct of_device_id qe_gpio_match[] = { 327 + { 328 + .compatible = "fsl,mpc8323-qe-pario-bank", 329 + }, 330 + {}, 331 + }; 332 + MODULE_DEVICE_TABLE(of, qe_gpio_match); 333 + 334 + static struct platform_driver qe_gpio_driver = { 335 + .probe = qe_gpio_probe, 336 + .driver = { 337 + .name = "qe-gpio", 338 + .of_match_table = qe_gpio_match, 339 + }, 340 + }; 341 + 342 + static int __init qe_gpio_init(void) 343 + { 344 + return platform_driver_register(&qe_gpio_driver); 345 + } 346 + arch_initcall(qe_gpio_init);