Skip to content

Commit 116eadc

Browse files
author
Bartosz Golaszewski
committed
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>
1 parent 80d7319 commit 116eadc

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

drivers/gpio/gpio-loongson1.c

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
* Copyright (C) 2015-2023 Keguang Zhang <keguang.zhang@gmail.com>
66
*/
77

8+
#include <linux/bitops.h>
89
#include <linux/module.h>
910
#include <linux/gpio/driver.h>
11+
#include <linux/gpio/generic.h>
1012
#include <linux/platform_device.h>
11-
#include <linux/bitops.h>
1213

1314
/* Loongson 1 GPIO Register Definitions */
1415
#define GPIO_CFG 0x0
@@ -17,36 +18,35 @@
1718
#define GPIO_OUTPUT 0x30
1819

1920
struct ls1x_gpio_chip {
20-
struct gpio_chip gc;
21+
struct gpio_generic_chip chip;
2122
void __iomem *reg_base;
2223
};
2324

2425
static int ls1x_gpio_request(struct gpio_chip *gc, unsigned int offset)
2526
{
2627
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
27-
unsigned long flags;
2828

29-
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
29+
guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip);
30+
3031
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) | BIT(offset),
3132
ls1x_gc->reg_base + GPIO_CFG);
32-
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
3333

3434
return 0;
3535
}
3636

3737
static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset)
3838
{
3939
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
40-
unsigned long flags;
4140

42-
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
41+
guard(gpio_generic_lock_irqsave)(&ls1x_gc->chip);
42+
4343
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) & ~BIT(offset),
4444
ls1x_gc->reg_base + GPIO_CFG);
45-
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
4645
}
4746

4847
static int ls1x_gpio_probe(struct platform_device *pdev)
4948
{
49+
struct gpio_generic_chip_config config;
5050
struct device *dev = &pdev->dev;
5151
struct ls1x_gpio_chip *ls1x_gc;
5252
int ret;
@@ -59,29 +59,35 @@ static int ls1x_gpio_probe(struct platform_device *pdev)
5959
if (IS_ERR(ls1x_gc->reg_base))
6060
return PTR_ERR(ls1x_gc->reg_base);
6161

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);
6571
if (ret)
6672
goto err;
6773

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;
7177
/*
7278
* Clear ngpio to let gpiolib get the correct number
7379
* by reading ngpios property
7480
*/
75-
ls1x_gc->gc.ngpio = 0;
81+
ls1x_gc->chip.gc.ngpio = 0;
7682

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);
7884
if (ret)
7985
goto err;
8086

8187
platform_set_drvdata(pdev, ls1x_gc);
8288

8389
dev_info(dev, "GPIO controller registered with %d pins\n",
84-
ls1x_gc->gc.ngpio);
90+
ls1x_gc->chip.gc.ngpio);
8591

8692
return 0;
8793
err:

0 commit comments

Comments
 (0)