mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 01:53:29 +02:00
gpio: amdpt: 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-10-356b4b1d5110@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
84bebb7e7e
commit
728e0ca4e1
|
|
@ -9,6 +9,7 @@
|
|||
#include <linux/kernel.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/gpio/driver.h>
|
||||
#include <linux/gpio/generic.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/acpi.h>
|
||||
#include <linux/platform_device.h>
|
||||
|
|
@ -24,54 +25,50 @@
|
|||
#define PT_SYNC_REG 0x28
|
||||
|
||||
struct pt_gpio_chip {
|
||||
struct gpio_chip gc;
|
||||
struct gpio_generic_chip chip;
|
||||
void __iomem *reg_base;
|
||||
};
|
||||
|
||||
static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
|
||||
{
|
||||
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
|
||||
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
||||
unsigned long flags;
|
||||
u32 using_pins;
|
||||
|
||||
dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
|
||||
|
||||
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
|
||||
guard(gpio_generic_lock_irqsave)(gen_gc);
|
||||
|
||||
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
|
||||
if (using_pins & BIT(offset)) {
|
||||
dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
|
||||
offset);
|
||||
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
|
||||
|
||||
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
|
||||
{
|
||||
struct gpio_generic_chip *gen_gc = to_gpio_generic_chip(gc);
|
||||
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
||||
unsigned long flags;
|
||||
u32 using_pins;
|
||||
|
||||
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
|
||||
guard(gpio_generic_lock_irqsave)(gen_gc);
|
||||
|
||||
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
|
||||
using_pins &= ~BIT(offset);
|
||||
writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
|
||||
|
||||
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
||||
|
||||
dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
|
||||
}
|
||||
|
||||
static int pt_gpio_probe(struct platform_device *pdev)
|
||||
{
|
||||
struct gpio_generic_chip_config config;
|
||||
struct device *dev = &pdev->dev;
|
||||
struct pt_gpio_chip *pt_gpio;
|
||||
int ret = 0;
|
||||
|
|
@ -91,22 +88,27 @@ static int pt_gpio_probe(struct platform_device *pdev)
|
|||
return PTR_ERR(pt_gpio->reg_base);
|
||||
}
|
||||
|
||||
ret = bgpio_init(&pt_gpio->gc, dev, 4,
|
||||
pt_gpio->reg_base + PT_INPUTDATA_REG,
|
||||
pt_gpio->reg_base + PT_OUTPUTDATA_REG, NULL,
|
||||
pt_gpio->reg_base + PT_DIRECTION_REG, NULL,
|
||||
BGPIOF_READ_OUTPUT_REG_SET);
|
||||
config = (typeof(config)){
|
||||
.dev = dev,
|
||||
.sz = 4,
|
||||
.dat = pt_gpio->reg_base + PT_INPUTDATA_REG,
|
||||
.set = pt_gpio->reg_base + PT_OUTPUTDATA_REG,
|
||||
.dirout = pt_gpio->reg_base + PT_DIRECTION_REG,
|
||||
.flags = BGPIOF_READ_OUTPUT_REG_SET,
|
||||
};
|
||||
|
||||
ret = gpio_generic_chip_init(&pt_gpio->chip, &config);
|
||||
if (ret) {
|
||||
dev_err(dev, "bgpio_init failed\n");
|
||||
dev_err(dev, "failed to initialize the generic GPIO chip\n");
|
||||
return ret;
|
||||
}
|
||||
|
||||
pt_gpio->gc.owner = THIS_MODULE;
|
||||
pt_gpio->gc.request = pt_gpio_request;
|
||||
pt_gpio->gc.free = pt_gpio_free;
|
||||
pt_gpio->gc.ngpio = (uintptr_t)device_get_match_data(dev);
|
||||
pt_gpio->chip.gc.owner = THIS_MODULE;
|
||||
pt_gpio->chip.gc.request = pt_gpio_request;
|
||||
pt_gpio->chip.gc.free = pt_gpio_free;
|
||||
pt_gpio->chip.gc.ngpio = (uintptr_t)device_get_match_data(dev);
|
||||
|
||||
ret = devm_gpiochip_add_data(dev, &pt_gpio->gc, pt_gpio);
|
||||
ret = devm_gpiochip_add_data(dev, &pt_gpio->chip.gc, pt_gpio);
|
||||
if (ret) {
|
||||
dev_err(dev, "Failed to register GPIO lib\n");
|
||||
return ret;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user