mirror of
https://github.com/torvalds/linux.git
synced 2026-05-31 18:43:33 +02:00
gpio: loongson-64bit: 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/20250825-gpio-mmio-gpio-conv-v1-8-356b4b1d5110@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
9215a4fb59
commit
4ba2193ce0
|
|
@ -11,6 +11,7 @@
|
|||
#include <linux/spinlock.h>
|
||||
#include <linux/err.h>
|
||||
#include <linux/gpio/driver.h>
|
||||
#include <linux/gpio/generic.h>
|
||||
#include <linux/platform_device.h>
|
||||
#include <linux/bitops.h>
|
||||
#include <asm/types.h>
|
||||
|
|
@ -30,7 +31,7 @@ struct loongson_gpio_chip_data {
|
|||
};
|
||||
|
||||
struct loongson_gpio_chip {
|
||||
struct gpio_chip chip;
|
||||
struct gpio_generic_chip chip;
|
||||
spinlock_t lock;
|
||||
void __iomem *reg_base;
|
||||
const struct loongson_gpio_chip_data *chip_data;
|
||||
|
|
@ -38,7 +39,8 @@ struct loongson_gpio_chip {
|
|||
|
||||
static inline struct loongson_gpio_chip *to_loongson_gpio_chip(struct gpio_chip *chip)
|
||||
{
|
||||
return container_of(chip, struct loongson_gpio_chip, chip);
|
||||
return container_of(to_gpio_generic_chip(chip),
|
||||
struct loongson_gpio_chip, chip);
|
||||
}
|
||||
|
||||
static inline void loongson_commit_direction(struct loongson_gpio_chip *lgpio, unsigned int pin,
|
||||
|
|
@ -138,36 +140,40 @@ static int loongson_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
|
|||
static int loongson_gpio_init(struct device *dev, struct loongson_gpio_chip *lgpio,
|
||||
void __iomem *reg_base)
|
||||
{
|
||||
struct gpio_generic_chip_config config;
|
||||
int ret;
|
||||
|
||||
lgpio->reg_base = reg_base;
|
||||
if (lgpio->chip_data->mode == BIT_CTRL_MODE) {
|
||||
ret = bgpio_init(&lgpio->chip, dev, 8,
|
||||
lgpio->reg_base + lgpio->chip_data->in_offset,
|
||||
lgpio->reg_base + lgpio->chip_data->out_offset,
|
||||
NULL, NULL,
|
||||
lgpio->reg_base + lgpio->chip_data->conf_offset,
|
||||
0);
|
||||
config = (typeof(config)){
|
||||
.dev = dev,
|
||||
.sz = 8,
|
||||
.dat = lgpio->reg_base + lgpio->chip_data->in_offset,
|
||||
.set = lgpio->reg_base + lgpio->chip_data->out_offset,
|
||||
.dirin = lgpio->reg_base + lgpio->chip_data->conf_offset,
|
||||
};
|
||||
|
||||
ret = gpio_generic_chip_init(&lgpio->chip, &config);
|
||||
if (ret) {
|
||||
dev_err(dev, "unable to init generic GPIO\n");
|
||||
return ret;
|
||||
}
|
||||
} else {
|
||||
lgpio->chip.direction_input = loongson_gpio_direction_input;
|
||||
lgpio->chip.get = loongson_gpio_get;
|
||||
lgpio->chip.get_direction = loongson_gpio_get_direction;
|
||||
lgpio->chip.direction_output = loongson_gpio_direction_output;
|
||||
lgpio->chip.set = loongson_gpio_set;
|
||||
lgpio->chip.parent = dev;
|
||||
lgpio->chip.gc.direction_input = loongson_gpio_direction_input;
|
||||
lgpio->chip.gc.get = loongson_gpio_get;
|
||||
lgpio->chip.gc.get_direction = loongson_gpio_get_direction;
|
||||
lgpio->chip.gc.direction_output = loongson_gpio_direction_output;
|
||||
lgpio->chip.gc.set = loongson_gpio_set;
|
||||
lgpio->chip.gc.parent = dev;
|
||||
spin_lock_init(&lgpio->lock);
|
||||
}
|
||||
|
||||
lgpio->chip.label = lgpio->chip_data->label;
|
||||
lgpio->chip.can_sleep = false;
|
||||
lgpio->chip.gc.label = lgpio->chip_data->label;
|
||||
lgpio->chip.gc.can_sleep = false;
|
||||
if (lgpio->chip_data->inten_offset)
|
||||
lgpio->chip.to_irq = loongson_gpio_to_irq;
|
||||
lgpio->chip.gc.to_irq = loongson_gpio_to_irq;
|
||||
|
||||
return devm_gpiochip_add_data(dev, &lgpio->chip, lgpio);
|
||||
return devm_gpiochip_add_data(dev, &lgpio->chip.gc, lgpio);
|
||||
}
|
||||
|
||||
static int loongson_gpio_probe(struct platform_device *pdev)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user