Re: [PATCH 06/18] irqchip: add sl28cpld interrupt controller support
From: Guenter Roeck
Date: Wed Mar 18 2020 - 16:36:38 EST
On 3/18/20 10:06 AM, Michael Walle wrote:
> Am 2020-03-18 17:53, schrieb Guenter Roeck:
>> On 3/17/20 1:50 PM, Michael Walle wrote:
>>> This patch adds support for the interrupt controller inside the sl28
>>> CPLD management controller.
>>>
>>> Signed-off-by: Michael Walle <michael@xxxxxxxx>
>>> ---
>>> Âdrivers/irqchip/KconfigÂÂÂÂÂÂÂ |Â 3 ++
>>> Âdrivers/irqchip/MakefileÂÂÂÂÂÂ |Â 1 +
>>> Âdrivers/irqchip/irq-sl28cpld.c | 92 ++++++++++++++++++++++++++++++++++
>>> Âdrivers/mfd/KconfigÂÂÂÂÂÂÂÂÂÂÂ |Â 4 +-
>>> Â4 files changed, 98 insertions(+), 2 deletions(-)
>>> Âcreate mode 100644 drivers/irqchip/irq-sl28cpld.c
>>>
>>> diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
>>> index 24fe08702ef7..3fd7415c8b55 100644
>>> --- a/drivers/irqchip/Kconfig
>>> +++ b/drivers/irqchip/Kconfig
>>> @@ -246,6 +246,9 @@ config RENESAS_RZA1_IRQC
>>> ÂÂÂÂÂÂ Enable support for the Renesas RZ/A1 Interrupt Controller, to use up
>>> ÂÂÂÂÂÂ to 8 external interrupts with configurable sense select.
>>>
>>> +config SL28CPLD_INTC
>>> +ÂÂÂ bool
>>> +
>>> Âconfig ST_IRQCHIP
>>> ÂÂÂÂ bool
>>> ÂÂÂÂ select REGMAP
>>> diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
>>> index eae0d78cbf22..0f4a37782609 100644
>>> --- a/drivers/irqchip/Makefile
>>> +++ b/drivers/irqchip/Makefile
>>> @@ -105,3 +105,4 @@ obj-$(CONFIG_MADERA_IRQ)ÂÂÂÂÂÂÂ += irq-madera.o
>>> Âobj-$(CONFIG_LS1X_IRQ)ÂÂÂÂÂÂÂÂÂÂÂ += irq-ls1x.o
>>> Âobj-$(CONFIG_TI_SCI_INTR_IRQCHIP)ÂÂÂ += irq-ti-sci-intr.o
>>> Âobj-$(CONFIG_TI_SCI_INTA_IRQCHIP)ÂÂÂ += irq-ti-sci-inta.o
>>> +obj-$(CONFIG_SL28CPLD_INTC)ÂÂÂÂÂÂÂ += irq-sl28cpld.o
>>> diff --git a/drivers/irqchip/irq-sl28cpld.c b/drivers/irqchip/irq-sl28cpld.c
>>> new file mode 100644
>>> index 000000000000..fa52ed79137b
>>> --- /dev/null
>>> +++ b/drivers/irqchip/irq-sl28cpld.c
>>> @@ -0,0 +1,92 @@
>>> +// SPDX-License-Identifier: GPL-2.0-only
>>> +/*
>>> + * SMARC-sAL28 Interrupt core driver.
>>> + *
>>> + * Copyright 2019 Kontron Europe GmbH
>>> + */
>>> +
>>> +#include <linux/kernel.h>
>>> +#include <linux/module.h>
>>> +#include <linux/of.h>
>>> +#include <linux/of_address.h>
>>> +#include <linux/of_platform.h>
>>> +#include <linux/i2c.h>
>>> +#include <linux/regmap.h>
>>> +#include <linux/interrupt.h>
>>> +#include <linux/mfd/core.h>
>>> +
>>> +#define INTC_IE 0
>>> +#define INTC_IP 1
>>> +
>>> +static const struct regmap_irq sl28cpld_irqs[] = {
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(0, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(1, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(2, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(3, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(4, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(5, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(6, 8),
>>> +ÂÂÂ REGMAP_IRQ_REG_LINE(7, 8),
>>> +};
>>> +
>>> +struct sl28cpld_intc {
>>> +ÂÂÂ struct regmap *regmap;
>>> +ÂÂÂ struct regmap_irq_chip chip;
>>> +ÂÂÂ struct regmap_irq_chip_data *irq_data;
>>> +};
>>> +
>>> +static int sl28cpld_intc_probe(struct platform_device *pdev)
>>> +{
>>> +ÂÂÂ struct sl28cpld_intc *irqchip;
>>> +ÂÂÂ struct resource *res;
>>> +ÂÂÂ unsigned int irq;
>>> +ÂÂÂ int ret;
>>> +
>>> +ÂÂÂ irqchip = devm_kzalloc(&pdev->dev, sizeof(*irqchip), GFP_KERNEL);
>>> +ÂÂÂ if (!irqchip)
>>> +ÂÂÂÂÂÂÂ return -ENOMEM;
>>> +
>>> +ÂÂÂ if (!pdev->dev.parent)
>>> +ÂÂÂÂÂÂÂ return -ENODEV;
>>> +
>>> +ÂÂÂ irqchip->regmap = dev_get_regmap(pdev->dev.parent, NULL);
>>> +ÂÂÂ if (!irqchip->regmap)
>>> +ÂÂÂÂÂÂÂ return -ENODEV;
>>> +
>>> +ÂÂÂ irq = platform_get_irq(pdev, 0);
>>> +ÂÂÂ if (irq < 0)
>>> +ÂÂÂÂÂÂÂ return irq;
>>> +
>>> +ÂÂÂ res = platform_get_resource(pdev, IORESOURCE_REG, 0);
>>> +ÂÂÂ if (!res)
>>> +ÂÂÂÂÂÂÂ return -EINVAL;
>>> +
>>> +ÂÂÂ irqchip->chip.name = "sl28cpld-intc";
>>> +ÂÂÂ irqchip->chip.irqs = sl28cpld_irqs;
>>> +ÂÂÂ irqchip->chip.num_irqs = ARRAY_SIZE(sl28cpld_irqs);
>>> +ÂÂÂ irqchip->chip.num_regs = 1;
>>> +ÂÂÂ irqchip->chip.status_base = res->start + INTC_IP;
>>> +ÂÂÂ irqchip->chip.mask_base = res->start + INTC_IE;
>>> +ÂÂÂ irqchip->chip.mask_invert = true,
>>> +ÂÂÂ irqchip->chip.ack_base = res->start + INTC_IP;
>>> +
>>> +ÂÂÂ ret = devm_regmap_add_irq_chip(&pdev->dev, irqchip->regmap, irq,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ IRQF_SHARED | IRQF_ONESHOT, 0,
>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &irqchip->chip, &irqchip->irq_data);
>>> +ÂÂÂ if (ret)
>>> +ÂÂÂÂÂÂÂ return ret;
>>> +ÂÂÂ dev_info(&pdev->dev, "registered IRQ %d\n", irq);
>>> +
>>> +ÂÂÂ return 0;
>>> +}
>>> +
>>> +static struct platform_driver sl28cpld_intc_driver = {
>>> +ÂÂÂ .probeÂÂÂ = sl28cpld_intc_probe,
>>> +ÂÂÂ .driver = {
>>> +ÂÂÂÂÂÂÂ .name = "sl28cpld-intc",
>>> +ÂÂÂ }
>>> +};
>>> +module_platform_driver(sl28cpld_intc_driver);
>>> +
>>> +MODULE_DESCRIPTION("sl28cpld Interrupt Controller Driver");
>>> +MODULE_LICENSE("GPL");
>>> diff --git a/drivers/mfd/Kconfig b/drivers/mfd/Kconfig
>>> index 01588c366476..4f741d640705 100644
>>> --- a/drivers/mfd/Kconfig
>>> +++ b/drivers/mfd/Kconfig
>>> @@ -2060,12 +2060,12 @@ config SGI_MFD_IOC3
>>> ÂÂÂÂÂÂ then say Y. Otherwise say N.
>>>
>>> Âconfig MFD_SL28CPLD
>>> -ÂÂÂ tristate "Kontron sl28 core driver"
>>> +ÂÂÂ bool "Kontron sl28 core driver"
>>
>> This is .... unusual. Why declare it tristate only to re-declare it
>> bool in the next patch ?
>
> I though it was a good idea to have that gradually build up, esp. since
> these patches might go through different reviewers/trees. That being said,
> I'll change it though.
>
Gradually build up is fine, but that doesn't mean to do it one way first and
change it later. This only results in feedback like mine - I2C=y just
didn't make sense in the previous patch. Please keep in mind that doing
things one way first and then changing them later only wastes people's time.
It would be much better to mention in the previous patch that the symbol is
declared bool because a subsequent patch introduces an interrupt controller
driver which needs to be built-in.
Thanks,
Guenter
>> It does explain the I2C=y, but I really think it should be bool from
>> the start if it ends up
>> there.
>
> Ok.
>
>>
>>> ÂÂÂÂ depends on I2C=y
>>> ÂÂÂÂ depends on OF
>>> ÂÂÂÂ select REGMAP_I2C
>>> ÂÂÂÂ select REGMAP_IRQ
>>> -ÂÂÂ select SL28CPLD_IRQ
>>> +ÂÂÂ select SL28CPLD_INTC
>>
>> What is the point of introducing SL28CPLD_IRQ in the first place ?
>
> oh damn. this is a left-over which slipped through. There should just
> be a SL28CPLD_INTC.
>
> -michael
>
>>
>>> ÂÂÂÂ select MFD_CORE
>>> ÂÂÂÂ help
>>> ÂÂÂÂÂÂ This option enables support for the board management controller
>>>