2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-10-19 11:07:37 +08:00
|
|
|
/*
|
|
|
|
* 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
|
2021-12-10 17:03:15 +08:00
|
|
|
#define PT_TOTAL_GPIO_EX 24
|
2015-10-19 11:07:37 +08:00
|
|
|
|
|
|
|
/* 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)
|
|
|
|
{
|
2015-12-04 22:29:41 +08:00
|
|
|
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
2015-10-19 11:07:37 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 using_pins;
|
|
|
|
|
2015-11-04 16:56:26 +08:00
|
|
|
dev_dbg(gc->parent, "pt_gpio_request offset=%x\n", offset);
|
2015-10-19 11:07:37 +08:00
|
|
|
|
2022-04-19 09:28:10 +08:00
|
|
|
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
|
2015-10-19 11:07:37 +08:00
|
|
|
|
|
|
|
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
if (using_pins & BIT(offset)) {
|
2015-11-04 16:56:26 +08:00
|
|
|
dev_warn(gc->parent, "PT GPIO pin %x reconfigured\n",
|
|
|
|
offset);
|
2022-04-19 09:28:10 +08:00
|
|
|
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
2015-10-19 11:07:37 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel(using_pins | BIT(offset), pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
|
2022-04-19 09:28:10 +08:00
|
|
|
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
2015-10-19 11:07:37 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void pt_gpio_free(struct gpio_chip *gc, unsigned offset)
|
|
|
|
{
|
2015-12-04 22:29:41 +08:00
|
|
|
struct pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
2015-10-19 11:07:37 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 using_pins;
|
|
|
|
|
2022-04-19 09:28:10 +08:00
|
|
|
raw_spin_lock_irqsave(&gc->bgpio_lock, flags);
|
2015-10-19 11:07:37 +08:00
|
|
|
|
|
|
|
using_pins = readl(pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
using_pins &= ~BIT(offset);
|
|
|
|
writel(using_pins, pt_gpio->reg_base + PT_SYNC_REG);
|
|
|
|
|
2022-04-19 09:28:10 +08:00
|
|
|
raw_spin_unlock_irqrestore(&gc->bgpio_lock, flags);
|
2015-10-19 11:07:37 +08:00
|
|
|
|
2015-11-04 16:56:26 +08:00
|
|
|
dev_dbg(gc->parent, "pt_gpio_free offset=%x\n", offset);
|
2015-10-19 11:07:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int pt_gpio_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct pt_gpio_chip *pt_gpio;
|
|
|
|
int ret = 0;
|
|
|
|
|
2021-10-14 00:06:40 +08:00
|
|
|
if (!ACPI_COMPANION(dev)) {
|
2015-10-19 11:07:37 +08:00
|
|
|
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;
|
|
|
|
|
2019-03-12 02:54:41 +08:00
|
|
|
pt_gpio->reg_base = devm_platform_ioremap_resource(pdev, 0);
|
2015-10-19 11:07:37 +08:00
|
|
|
if (IS_ERR(pt_gpio->reg_base)) {
|
2019-06-18 00:49:15 +08:00
|
|
|
dev_err(dev, "Failed to map MMIO resource for PT GPIO.\n");
|
2015-10-19 11:07:37 +08:00
|
|
|
return PTR_ERR(pt_gpio->reg_base);
|
|
|
|
}
|
|
|
|
|
2016-02-29 22:00:01 +08:00
|
|
|
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) {
|
2019-06-18 00:49:15 +08:00
|
|
|
dev_err(dev, "bgpio_init failed\n");
|
2016-02-29 22:00:01 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2015-10-19 11:07:37 +08:00
|
|
|
|
|
|
|
pt_gpio->gc.owner = THIS_MODULE;
|
|
|
|
pt_gpio->gc.request = pt_gpio_request;
|
|
|
|
pt_gpio->gc.free = pt_gpio_free;
|
2021-12-10 17:03:15 +08:00
|
|
|
pt_gpio->gc.ngpio = (uintptr_t)device_get_match_data(dev);
|
2021-12-18 00:39:35 +08:00
|
|
|
|
2015-12-04 22:29:41 +08:00
|
|
|
ret = gpiochip_add_data(&pt_gpio->gc, pt_gpio);
|
2015-10-19 11:07:37 +08:00
|
|
|
if (ret) {
|
2019-06-18 00:49:15 +08:00
|
|
|
dev_err(dev, "Failed to register GPIO lib\n");
|
2015-10-19 11:07:37 +08:00
|
|
|
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);
|
|
|
|
|
2019-06-18 00:49:15 +08:00
|
|
|
dev_dbg(dev, "PT GPIO driver loaded\n");
|
2015-10-19 11:07:37 +08:00
|
|
|
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[] = {
|
2021-12-10 17:03:15 +08:00
|
|
|
{ "AMDF030", PT_TOTAL_GPIO },
|
|
|
|
{ "AMDIF030", PT_TOTAL_GPIO },
|
|
|
|
{ "AMDIF031", PT_TOTAL_GPIO_EX },
|
2015-10-19 11:07:37 +08:00
|
|
|
{ },
|
|
|
|
};
|
|
|
|
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");
|