mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 15:04:27 +08:00
3c938cc5ce
In case of PREEMPT_RT, there is a raw_spinlock -> spinlock dependency as the lockdep report shows. __irq_set_handler irq_get_desc_buslock __irq_get_desc_lock raw_spin_lock_irqsave(&desc->lock, *flags); // raw spinlock get here __irq_do_set_handler mask_ack_irq dwapb_irq_ack spin_lock_irqsave(&gc->bgpio_lock, flags); // sleep able spinlock irq_put_desc_busunlock Replace with a raw lock to avoid BUGs. This lock is only used to access registers, and It's safe to replace with the raw lock without bad influence. [ 15.090359][ T1] ============================= [ 15.090365][ T1] [ BUG: Invalid wait context ] [ 15.090373][ T1] 5.10.59-rt52-00983-g186a6841c682-dirty #3 Not tainted [ 15.090386][ T1] ----------------------------- [ 15.090392][ T1] swapper/0/1 is trying to lock: [ 15.090402][ T1] 70ff00018507c188 (&gc->bgpio_lock){....}-{3:3}, at: _raw_spin_lock_irqsave+0x1c/0x28 [ 15.090470][ T1] other info that might help us debug this: [ 15.090477][ T1] context-{5:5} [ 15.090485][ T1] 3 locks held by swapper/0/1: [ 15.090497][ T1] #0: c2ff0001816de1a0 (&dev->mutex){....}-{4:4}, at: __device_driver_lock+0x98/0x104 [ 15.090553][ T1] #1: ffff90001485b4b8 (irq_domain_mutex){+.+.}-{4:4}, at: irq_domain_associate+0xbc/0x6d4 [ 15.090606][ T1] #2: 4bff000185d7a8e0 (lock_class){....}-{2:2}, at: _raw_spin_lock_irqsave+0x1c/0x28 [ 15.090654][ T1] stack backtrace: [ 15.090661][ T1] CPU: 4 PID: 1 Comm: swapper/0 Not tainted 5.10.59-rt52-00983-g186a6841c682-dirty #3 [ 15.090682][ T1] Hardware name: Horizon Robotics Journey 5 DVB (DT) [ 15.090692][ T1] Call trace: ...... [ 15.090811][ T1] _raw_spin_lock_irqsave+0x1c/0x28 [ 15.090828][ T1] dwapb_irq_ack+0xb4/0x300 [ 15.090846][ T1] __irq_do_set_handler+0x494/0xb2c [ 15.090864][ T1] __irq_set_handler+0x74/0x114 [ 15.090881][ T1] irq_set_chip_and_handler_name+0x44/0x58 [ 15.090900][ T1] gpiochip_irq_map+0x210/0x644 Signed-off-by: Schspa Shi <schspa@gmail.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Acked-by: Doug Berger <opendmb@gmail.com> Acked-by: Serge Semin <fancer.lancer@gmail.com> Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
156 lines
3.8 KiB
C
156 lines
3.8 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
|
|
#define PT_TOTAL_GPIO_EX 24
|
|
|
|
/* 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);
|
|
|
|
raw_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);
|
|
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 pt_gpio_chip *pt_gpio = gpiochip_get_data(gc);
|
|
unsigned long flags;
|
|
u32 using_pins;
|
|
|
|
raw_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);
|
|
|
|
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 device *dev = &pdev->dev;
|
|
struct pt_gpio_chip *pt_gpio;
|
|
int ret = 0;
|
|
|
|
if (!ACPI_COMPANION(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 = (uintptr_t)device_get_match_data(dev);
|
|
|
|
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", PT_TOTAL_GPIO },
|
|
{ "AMDIF030", PT_TOTAL_GPIO },
|
|
{ "AMDIF031", PT_TOTAL_GPIO_EX },
|
|
{ },
|
|
};
|
|
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");
|