Skip to content

Commit 31b6ec6

Browse files
kelvincheungBartosz Golaszewski
authored andcommitted
gpio: loongson1: Introduce ls1x_gpio_chip struct
This patch introduces and allocates ls1x_gpio_chip struct containing gpio_chip and reg_base to avoid global gpio_reg_base. Signed-off-by: Keguang Zhang <keguang.zhang@gmail.com> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
1 parent a9b4678 commit 31b6ec6

1 file changed

Lines changed: 25 additions & 20 deletions

File tree

drivers/gpio/gpio-loongson1.c

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,60 +16,65 @@
1616
#define GPIO_DATA 0x20
1717
#define GPIO_OUTPUT 0x30
1818

19-
static void __iomem *gpio_reg_base;
19+
struct ls1x_gpio_chip {
20+
struct gpio_chip gc;
21+
void __iomem *reg_base;
22+
};
2023

2124
static int ls1x_gpio_request(struct gpio_chip *gc, unsigned int offset)
2225
{
26+
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
2327
unsigned long flags;
2428

2529
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
26-
__raw_writel(__raw_readl(gpio_reg_base + GPIO_CFG) | BIT(offset),
27-
gpio_reg_base + GPIO_CFG);
30+
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) | BIT(offset),
31+
ls1x_gc->reg_base + GPIO_CFG);
2832
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
2933

3034
return 0;
3135
}
3236

3337
static void ls1x_gpio_free(struct gpio_chip *gc, unsigned int offset)
3438
{
39+
struct ls1x_gpio_chip *ls1x_gc = gpiochip_get_data(gc);
3540
unsigned long flags;
3641

3742
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
38-
__raw_writel(__raw_readl(gpio_reg_base + GPIO_CFG) & ~BIT(offset),
39-
gpio_reg_base + GPIO_CFG);
43+
__raw_writel(__raw_readl(ls1x_gc->reg_base + GPIO_CFG) & ~BIT(offset),
44+
ls1x_gc->reg_base + GPIO_CFG);
4045
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
4146
}
4247

4348
static int ls1x_gpio_probe(struct platform_device *pdev)
4449
{
4550
struct device *dev = &pdev->dev;
46-
struct gpio_chip *gc;
51+
struct ls1x_gpio_chip *ls1x_gc;
4752
int ret;
4853

49-
gc = devm_kzalloc(dev, sizeof(*gc), GFP_KERNEL);
50-
if (!gc)
54+
ls1x_gc = devm_kzalloc(dev, sizeof(*ls1x_gc), GFP_KERNEL);
55+
if (!ls1x_gc)
5156
return -ENOMEM;
5257

53-
gpio_reg_base = devm_platform_ioremap_resource(pdev, 0);
54-
if (IS_ERR(gpio_reg_base))
55-
return PTR_ERR(gpio_reg_base);
58+
ls1x_gc->reg_base = devm_platform_ioremap_resource(pdev, 0);
59+
if (IS_ERR(ls1x_gc->reg_base))
60+
return PTR_ERR(ls1x_gc->reg_base);
5661

57-
ret = bgpio_init(gc, dev, 4, gpio_reg_base + GPIO_DATA,
58-
gpio_reg_base + GPIO_OUTPUT, NULL,
59-
NULL, gpio_reg_base + GPIO_DIR, 0);
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);
6065
if (ret)
6166
goto err;
6267

63-
gc->owner = THIS_MODULE;
64-
gc->request = ls1x_gpio_request;
65-
gc->free = ls1x_gpio_free;
66-
gc->base = pdev->id * 32;
68+
ls1x_gc->gc.owner = THIS_MODULE;
69+
ls1x_gc->gc.request = ls1x_gpio_request;
70+
ls1x_gc->gc.free = ls1x_gpio_free;
71+
ls1x_gc->gc.base = pdev->id * 32;
6772

68-
ret = devm_gpiochip_add_data(dev, gc, NULL);
73+
ret = devm_gpiochip_add_data(dev, &ls1x_gc->gc, ls1x_gc);
6974
if (ret)
7075
goto err;
7176

72-
platform_set_drvdata(pdev, gc);
77+
platform_set_drvdata(pdev, ls1x_gc);
7378
dev_info(dev, "Loongson1 GPIO driver registered\n");
7479

7580
return 0;

0 commit comments

Comments
 (0)