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

gpio: loongson1: use new generic GPIO chip API

Convert the driver to using the new generic GPIO chip interfaces from
linux/gpio/generic.h.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250910-gpio-mmio-gpio-conv-part4-v2-2-f3d1a4c57124@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

+23 -17
+23 -17
drivers/gpio/gpio-loongson1.c
··· 5 5 * Copyright (C) 2015-2023 Keguang Zhang <keguang.zhang@gmail.com> 6 6 */ 7 7 8 + #include <linux/bitops.h> 8 9 #include <linux/module.h> 9 10 #include <linux/gpio/driver.h> 11 + #include <linux/gpio/generic.h> 10 12 #include <linux/platform_device.h> 11 - #include <linux/bitops.h> 12 13 13 14 /* Loongson 1 GPIO Register Definitions */ 14 15 #define GPIO_CFG 0x0 ··· 18 17 #define GPIO_OUTPUT 0x30 19 18 20 19 struct ls1x_gpio_chip { 21 - struct gpio_chip gc; 20 + struct gpio_generic_chip chip; 22 21 void __iomem *reg_base; 23 22 }; 24 23 25 24 static int ls1x_gpio_request(struct gpio_chip *gc, unsigned int offset) 26 25 { 27 26 struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc); 28 - unsigned long flags; 29 27 30 - raw_spin_lock_irqsave(&gc->bgpio_lock, flags); 28 + guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip); 29 + 31 30 __raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) | BIT(offset), 32 31 ls1x_gc->reg_base + GPIO_CFG); 33 - raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); 34 32 35 33 return 0; 36 34 } ··· 37 37 static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset) 38 38 { 39 39 struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc); 40 - unsigned long flags; 41 40 42 - raw_spin_lock_irqsave(&gc->bgpio_lock, flags); 41 + guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip); 42 + 43 43 __raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) & ~BIT(offset), 44 44 ls1x_gc->reg_base + GPIO_CFG); 45 - raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags); 46 45 } 47 46 48 47 static int ls1x_gpio_probe(struct platform_device *pdev) 49 48 { 49 + struct gpio_generic_chip_config config; 50 50 struct device *dev = &pdev->dev; 51 51 struct ls1x_gpio_chip *ls1x_gc; 52 52 int ret; ··· 59 59 if (IS_ERR(ls1x_gc->reg_base)) 60 60 return PTR_ERR(ls1x_gc->reg_base); 61 61 62 - ret = bgpio_init(&ls1x_gc->gc, dev, 4, ls1x_gc->reg_base + GPIO_DATA, 63 - ls1x_gc->reg_base + GPIO_OUTPUT, NULL, 64 - NULL, ls1x_gc->reg_base + GPIO_DIR, 0); 62 + config = (struct gpio_generic_chip_config) { 63 + .dev = dev, 64 + .sz = 4, 65 + .dat = ls1x_gc->reg_base + GPIO_DATA, 66 + .set = ls1x_gc->reg_base + GPIO_OUTPUT, 67 + .dirin = ls1x_gc->reg_base + GPIO_DIR, 68 + }; 69 + 70 + ret = gpio_generic_chip_init(&ls1x_gc->chip, &config); 65 71 if (ret) 66 72 goto err; 67 73 68 - ls1x_gc->gc.owner = THIS_MODULE; 69 - ls1x_gc->gc.request = ls1x_gpio_request; 70 - ls1x_gc->gc.free = ls1x_gpio_free; 74 + ls1x_gc->chip.gc.owner = THIS_MODULE; 75 + ls1x_gc->chip.gc.request = ls1x_gpio_request; 76 + ls1x_gc->chip.gc.free = ls1x_gpio_free; 71 77 /* 72 78 * Clear ngpio to let gpiolib get the correct number 73 79 * by reading ngpios property 74 80 */ 75 - ls1x_gc->gc.ngpio = 0; 81 + ls1x_gc->chip.gc.ngpio = 0; 76 82 77 - ret = devm_gpiochip_add_data(dev, &ls1x_gc->gc, ls1x_gc); 83 + ret = devm_gpiochip_add_data(dev, &ls1x_gc->chip.gc, ls1x_gc); 78 84 if (ret) 79 85 goto err; 80 86 81 87 platform_set_drvdata(pdev, ls1x_gc); 82 88 83 89 dev_info(dev, "GPIO controller registered with %d pins\n", 84 - ls1x_gc->gc.ngpio); 90 + ls1x_gc->chip.gc.ngpio); 85 91 86 92 return 0; 87 93 err: