mirror of
https://github.com/torvalds/linux.git
synced 2024-12-30 06:41:43 +00:00
2ec98f5678
Core: - When a gpio_chip request GPIOs from itself, it can now fully control the line characteristics, both machine and consumer flags. This makes a lot of sense, but took some time before I figured out that this is how it has to work. - Several smallish documentation fixes. New drivers: - The PCA953x driver now supports the TI TCA9539. - The DaVinci driver now supports the K3 AM654 SoCs. Driver improvements: - Major overhaul and hardening of the OMAP driver by Russell King. - Starting to move some drivers to the new API passing irq_chip along with the gpio_chip when adding the gpio_chip instead of adding it separately. Unrelated: - Delete the FMC subsystem. -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEElDRnuGcz/wPCXQWMQRCzN7AZXXMFAl0i7gEACgkQQRCzN7AZ XXOeUA/+JKyI2zebTWBcgtxhn6VQCufMCtFmQl2JkEcy4pT7aBJcGWqFQCBW2Szf VTtqc8nNa90SZoOzsNbkeQgRjNKGZruMbh0ARUPcW4v3ZJHtUNUEDLTo8c3iyTgS 9k/FTeaTLt4WSZujeAO0O7G4KNnOOlTKLh58dr0PmXUR+0v+fbMhcJqJ9ABueV+V qENdpkTuG1ZcvzgLhBBEXdt3Plw9ICLWmPXtwY+784ewucVPbyQX7jV4+bBZ25fL DerCuMIgL5vRWWdiFO6/Jp603rHzZpTnjLJJocXUFiD6zA5rvU2jTWxsnUttjisg 8cTLMyQspsDvBxhEhCJVTuIKotbKH900TSaz+vx20W72/A1euy4y6uVi8FGZo4Ww KDkzB7anwHyEFKGnlYgHzDrfctgZrhQoyFz808DQRYg1JseZB5oGVDvScrPBD43j nbNDd8gwG4yp3tFnDx9xjIwQy3Ax4d510rAZyUN2801IlbA1bueq4t6Z2cCucWzX XA1gCKlXe4BUeitRAoZtqZNZG1ymEysW4jXy1V8xrwtAf8+QSN+xO98akz3VpnQL ae9q+HtF76fDBY1xFSXT37Ma3+4OR2vMF9QWuo4TCb9j1cL7llf8ZxtUq9LEHbDu erKLSSnwSFmqJNGSEA5SulGOCR/tRPkClngE9x0XEM6gOD+bs6E= =8zSV -----END PGP SIGNATURE----- Merge tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio Pull GPIO updates from Linus Walleij: "This is the big slew of GPIO changes for the v5.3 kernel cycle. This is mostly incremental work this time. Three important things: - The FMC subsystem is deleted through my tree. This happens through GPIO as its demise was discussed in relation to a patch decoupling its GPIO implementation from the standard way of handling GPIO. As it turns out, that is not the only subsystem it reimplements and the authors think it is better do scratch it and start over using the proper kernel subsystems than try to polish the rust shiny. See the commit (ACKed by the maintainers) for details. - Arnd made a small devres patch that was ACKed by Greg and goes into the device core. - SPDX header change colissions may happen, because at times I've seen that quite a lot changed during the -rc:s in regards to SPDX. (It is good stuff, tglx has me convinced, and it is worth the occasional pain.) Apart from this is is nothing controversial or problematic. Summary: Core: - When a gpio_chip request GPIOs from itself, it can now fully control the line characteristics, both machine and consumer flags. This makes a lot of sense, but took some time before I figured out that this is how it has to work. - Several smallish documentation fixes. New drivers: - The PCA953x driver now supports the TI TCA9539. - The DaVinci driver now supports the K3 AM654 SoCs. Driver improvements: - Major overhaul and hardening of the OMAP driver by Russell King. - Starting to move some drivers to the new API passing irq_chip along with the gpio_chip when adding the gpio_chip instead of adding it separately. Unrelated: - Delete the FMC subsystem" * tag 'gpio-v5.3-1' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio: (87 commits) Revert "gpio: tegra: Clean-up debugfs initialisation" gpiolib: Use spinlock_t instead of struct spinlock gpio: stp-xway: allow compile-testing gpio: stp-xway: get rid of the #include <lantiq_soc.h> dependency gpio: stp-xway: improve module clock error handling gpio: stp-xway: simplify error handling in xway_stp_probe() gpiolib: Clarify use of non-sleeping functions gpiolib: Fix references to gpiod_[gs]et_*value_cansleep() variants gpiolib: Document new gpio_chip.init_valid_mask field Documentation: gpio: Fix reference to gpiod_get_array() gpio: pl061: drop duplicate printing of device name gpio: altera: Pass irqchip when adding gpiochip gpio: siox: Use devm_ managed gpiochip gpio: siox: Add struct device *dev helper variable gpio: siox: Pass irqchip when adding gpiochip drivers: gpio: amd-fch: make resource struct const devres: allow const resource arguments gpio: ath79: Pass irqchip when adding gpiochip gpio: tegra: Clean-up debugfs initialisation gpio: siox: Switch to IRQ_TYPE_NONE ...
158 lines
3.9 KiB
C
158 lines
3.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
/*
|
|
* AMD Promontory GPIO driver
|
|
*
|
|
* Copyright (C) 2015 ASMedia Technology Inc.
|
|
* Author: YD Tseng <yd_tseng@asmedia.com.tw>
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
#include <linux/module.h>
|
|
#include <linux/gpio/driver.h>
|
|
#include <linux/spinlock.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/platform_device.h>
|
|
|
|
#define PT_TOTAL_GPIO 8
|
|
|
|
/* PCI-E MMIO register offsets */
|
|
#define PT_DIRECTION_REG 0x00
|
|
#define PT_INPUTDATA_REG 0x04
|
|
#define PT_OUTPUTDATA_REG 0x08
|
|
#define PT_CLOCKRATE_REG 0x0C
|
|
#define PT_SYNC_REG 0x28
|
|
|
|
struct pt_gpio_chip {
|
|
struct gpio_chip gc;
|
|
void __iomem *reg_base;
|
|
};
|
|
|
|
static int pt_gpio_request(struct gpio_chip *gc, unsigned offset)
|
|
{
|
|
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);
|
|
|
|
spin_lock_irqsave(&gc->bgpio_lock, flags);
|
|
|
|
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);
|
|
spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
|
return -EINVAL;
|
|
}
|
|
|
|
writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
|
|
{
|
|
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
|
unsigned long flags;
|
|
u32 using_pins;
|
|
|
|
spin_lock_irqsave(&gc->bgpio_lock, flags);
|
|
|
|
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
|
|
using_pins &= ~BIT(offset);
|
|
writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
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 device *dev = &pdev->dev;
|
|
struct acpi_device *acpi_dev;
|
|
acpi_handle handle = ACPI_HANDLE(dev);
|
|
struct pt_gpio_chip *pt_gpio;
|
|
int ret = 0;
|
|
|
|
if (acpi_bus_get_device(handle, &acpi_dev)) {
|
|
dev_err(dev, "PT GPIO device node not found\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
pt_gpio = devm_kzalloc(dev, sizeof(struct pt_gpio_chip), GFP_KERNEL);
|
|
if (!pt_gpio)
|
|
return -ENOMEM;
|
|
|
|
pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
|
|
if (IS_ERR(pt_gpio->reg_base)) {
|
|
dev_err(dev, "Failed to map MMIO resource for PT GPIO.\n");
|
|
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);
|
|
if (ret) {
|
|
dev_err(dev, "bgpio_init failed\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 = PT_TOTAL_GPIO;
|
|
#if defined(CONFIG_OF_GPIO)
|
|
pt_gpio->gc.of_node = dev->of_node;
|
|
#endif
|
|
ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio);
|
|
if (ret) {
|
|
dev_err(dev, "Failed to register GPIO lib\n");
|
|
return ret;
|
|
}
|
|
|
|
platform_set_drvdata(pdev, pt_gpio);
|
|
|
|
/* initialize register setting */
|
|
writel(0, pt_gpio->reg_base + PT_SYNC_REG);
|
|
writel(0, pt_gpio->reg_base + PT_CLOCKRATE_REG);
|
|
|
|
dev_dbg(dev, "PT GPIO driver loaded\n");
|
|
return ret;
|
|
}
|
|
|
|
static int pt_gpio_remove(struct platform_device *pdev)
|
|
{
|
|
struct pt_gpio_chip *pt_gpio = platform_get_drvdata(pdev);
|
|
|
|
gpiochip_remove(&pt_gpio->gc);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct acpi_device_id pt_gpio_acpi_match[] = {
|
|
{ "AMDF030", 0 },
|
|
{ "AMDIF030", 0 },
|
|
{ },
|
|
};
|
|
MODULE_DEVICE_TABLE(acpi, pt_gpio_acpi_match);
|
|
|
|
static struct platform_driver pt_gpio_driver = {
|
|
.driver = {
|
|
.name = "pt-gpio",
|
|
.acpi_match_table = ACPI_PTR(pt_gpio_acpi_match),
|
|
},
|
|
.probe = pt_gpio_probe,
|
|
.remove = pt_gpio_remove,
|
|
};
|
|
|
|
module_platform_driver(pt_gpio_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("YD Tseng <yd_tseng@asmedia.com.tw>");
|
|
MODULE_DESCRIPTION("AMD Promontory GPIO Driver");
|