2022-09-26 08:50:16

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH v2 0/3] allow gpio simulator be used as interrupt controller

From: Wei Yongjun <[email protected]>

This series allow gpio simulator be used as interrupt controller, the use
case is mockup some device which using GPIO as interrupt controller, such
as mcp2515 CAN device. With the dts [1], we can mockup a mcp2515 device,
and trigger irq by following commands:

$ echo pull-down > /sys/bus/gpio/devices/gpiochip0/sim_gpio0/pull
$ echo pull-up > /sys/bus/gpio/devices/gpiochip0/sim_gpio0/pull

v1 -> v2:
- add use case to gpio-sim.rst

--[1]---------------------------------------------------------
/dts-v1/;

#include <dt-bindings/interrupt-controller/irq.h>

/ {
clk24m: clk24m {
compatible = "fixed-clock";
clock-output-names = "clk24m";
clock-frequency = <24000000>;
#clock-cells = <0>;
};

gpio-sim {
compatible = "gpio-simulator";

bank0: bank0 {
gpio-controller;
#gpio-cells = <2>;
ngpios = <16>;

interrupt-controller;
#interrupt-cells = <2>;

line_b-hog {
gpio-hog;
gpios = <0 1>;
input;
line-name = "irq-sim";
};
};
};

spi: spi {
compatible = "spi-mockup";

#address-cells = <1>;
#size-cells = <0>;

can0: can@1 {
compatible = "microchip,mcp2515";
reg = <1>;
clocks = <&clk24m>;
interrupt-parent = <&bank0>;
interrupts = <0 IRQ_TYPE_EDGE_BOTH>;
};

};
};
------------------------------><-----------------------------

Wei Yongjun (3):
genirq/irq_sim: Allow both one and two cell bindings
gpio: sim: make gpio simulator can be used as interrupt controller
gpio: sim: document use case for interrupt controller

Documentation/admin-guide/gpio/gpio-sim.rst | 44 +++++++++++++++++++++
drivers/gpio/gpio-sim.c | 2 +-
kernel/irq/irq_sim.c | 1 +
3 files changed, 46 insertions(+), 1 deletion(-)

--
2.34.1


2022-09-26 08:51:08

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH v2 2/3] gpio: sim: make gpio simulator can be used as interrupt controller

From: Wei Yongjun <[email protected]>

Some devices using GPIO as interrupt controller, such as mcp2515 CAN
device. To mockup those devices, gpio simulator should extend to be
used as interrupt controller form device tree.

Signed-off-by: Wei Yongjun <[email protected]>
---
drivers/gpio/gpio-sim.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpio/gpio-sim.c b/drivers/gpio/gpio-sim.c
index 1020c2feb249..f3cf6cec6207 100644
--- a/drivers/gpio/gpio-sim.c
+++ b/drivers/gpio/gpio-sim.c
@@ -398,7 +398,7 @@ static int gpio_sim_add_bank(struct fwnode_handle *swnode, struct device *dev)
if (!chip->pull_map)
return -ENOMEM;

- chip->irq_sim = devm_irq_domain_create_sim(dev, NULL, num_lines);
+ chip->irq_sim = devm_irq_domain_create_sim(dev, swnode, num_lines);
if (IS_ERR(chip->irq_sim))
return PTR_ERR(chip->irq_sim);

--
2.34.1

2022-09-26 09:12:39

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings

From: Wei Yongjun <[email protected]>

The IRQ simulator only support one cell binding now, this patch make it
works with either one or two cell bindings, where the cell values map
directly to the irq number and irq flags.

Signed-off-by: Wei Yongjun <[email protected]>
---
kernel/irq/irq_sim.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
index dd76323ea3fd..73a90b7b6022 100644
--- a/kernel/irq/irq_sim.c
+++ b/kernel/irq/irq_sim.c
@@ -149,6 +149,7 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq)
static const struct irq_domain_ops irq_sim_domain_ops = {
.map = irq_sim_domain_map,
.unmap = irq_sim_domain_unmap,
+ .xlate = irq_domain_xlate_onetwocell,
};

/**
--
2.34.1

2022-09-26 09:16:45

by Wei Yongjun

[permalink] [raw]
Subject: [PATCH v2 3/3] gpio: sim: document use case for interrupt controller

From: Wei Yongjun <[email protected]>

Add document for using GPIO sim as interrupt controller.

Signed-off-by: Wei Yongjun <[email protected]>
---
Documentation/admin-guide/gpio/gpio-sim.rst | 44 +++++++++++++++++++++
1 file changed, 44 insertions(+)

diff --git a/Documentation/admin-guide/gpio/gpio-sim.rst b/Documentation/admin-guide/gpio/gpio-sim.rst
index d8a90c81b9ee..7ccb3f80c90e 100644
--- a/Documentation/admin-guide/gpio/gpio-sim.rst
+++ b/Documentation/admin-guide/gpio/gpio-sim.rst
@@ -132,3 +132,47 @@ group there are two attibutes:
``value`` - allows to read the current value of the line which may be
different from the pull if the line is being driven from
user-space
+
+An example device-tree code defining a GPIO simulator as interrupt controller:
+
+.. code-block :: none
+
+ gpio-sim {
+ compatible = "gpio-simulator";
+
+ bank0 {
+ gpio-controller;
+ #gpio-cells = <2>;
+ ngpios = <16>;
+
+ interrupt-controller;
+ #interrupt-cells = <2>;
+
+ line0 {
+ gpio-hog;
+ gpios = <0 1>;
+ input;
+ line-name = "irq-sim";
+ }
+ };
+ };
+
+ spi: spi {
+ compatible = "spi-mockup";
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ can0: can@1 {
+ compatible = "microchip,mcp2515";
+ reg = <1>;
+ interrupt-parent = <&bank0>;
+ interrupts = <0 IRQ_TYPE_EDGE_BOTH>;
+ }
+ };
+
+Trigger irq by writing value to pull setting:
+
+.. code-block :: none
+
+ $ echo pull-down > /sys/devices/platform/gpio-sim/gpiochipX/sim_gpio0/pull
+ $ echo pull-up > /sys/devices/platform/gpio-sim/gpiochipX/sim_gpio0/pull
--
2.34.1

2022-09-26 13:31:37

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings

On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <[email protected]> wrote:
>
> From: Wei Yongjun <[email protected]>
>
> The IRQ simulator only support one cell binding now, this patch make it
> works with either one or two cell bindings, where the cell values map
> directly to the irq number and irq flags.
>
> Signed-off-by: Wei Yongjun <[email protected]>
> ---
> kernel/irq/irq_sim.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
> index dd76323ea3fd..73a90b7b6022 100644
> --- a/kernel/irq/irq_sim.c
> +++ b/kernel/irq/irq_sim.c
> @@ -149,6 +149,7 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq)
> static const struct irq_domain_ops irq_sim_domain_ops = {
> .map = irq_sim_domain_map,
> .unmap = irq_sim_domain_unmap,
> + .xlate = irq_domain_xlate_onetwocell,
> };
>
> /**
> --
> 2.34.1
>

You'll need Marc's (Cc'ed) Ack here.

Bart

2022-09-26 14:49:14

by Marc Zyngier

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings

On Mon, 26 Sep 2022 07:24:48 -0400,
Bartosz Golaszewski <[email protected]> wrote:
>
> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <[email protected]> wrote:
> >
> > From: Wei Yongjun <[email protected]>
> >
> > The IRQ simulator only support one cell binding now, this patch make it
> > works with either one or two cell bindings, where the cell values map
> > directly to the irq number and irq flags.
> >
> > Signed-off-by: Wei Yongjun <[email protected]>
> > ---
> > kernel/irq/irq_sim.c | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
> > index dd76323ea3fd..73a90b7b6022 100644
> > --- a/kernel/irq/irq_sim.c
> > +++ b/kernel/irq/irq_sim.c
> > @@ -149,6 +149,7 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq)
> > static const struct irq_domain_ops irq_sim_domain_ops = {
> > .map = irq_sim_domain_map,
> > .unmap = irq_sim_domain_unmap,
> > + .xlate = irq_domain_xlate_onetwocell,
> > };
> >
> > /**
> > --
> > 2.34.1
> >
>
> You'll need Marc's (Cc'ed) Ack here.

The question is what will the simulator code do with this information.
Throw it away? What of 3/4/5 cell bindings? I'd rather see the
simulator being extended to deal with arbitrary bindings instead of
trading a harcoded limit for another one. And also give some
semantics to the extra cells.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.

2022-09-28 08:18:54

by Wei Yongjun

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings



On 2022/9/26 20:55, Marc Zyngier wrote:
> On Mon, 26 Sep 2022 07:24:48 -0400,
> Bartosz Golaszewski <[email protected]> wrote:
>>
>> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <[email protected]> wrote:
>>>
>>> From: Wei Yongjun <[email protected]>
>>>
>>> The IRQ simulator only support one cell binding now, this patch make it
>>> works with either one or two cell bindings, where the cell values map
>>> directly to the irq number and irq flags.
>>>
>>> Signed-off-by: Wei Yongjun <[email protected]>
>>> ---
>>> kernel/irq/irq_sim.c | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
>>> index dd76323ea3fd..73a90b7b6022 100644
>>> --- a/kernel/irq/irq_sim.c
>>> +++ b/kernel/irq/irq_sim.c
>>> @@ -149,6 +149,7 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq)
>>> static const struct irq_domain_ops irq_sim_domain_ops = {
>>> .map = irq_sim_domain_map,
>>> .unmap = irq_sim_domain_unmap,
>>> + .xlate = irq_domain_xlate_onetwocell,
>>> };
>>>
>>> /**
>>> --
>>> 2.34.1
>>>
>>
>> You'll need Marc's (Cc'ed) Ack here.

Hi Marc,

>
> The question is what will the simulator code do with this information.
> Throw it away? What of 3/4/5 cell bindings? I'd rather see the

The 3/4/5 cell bindings is selience ignored currently.

> simulator being extended to deal with arbitrary bindings instead of
> trading a harcoded limit for another one. And also give some
> semantics to the extra cells.

Would you means we should allow the users to overwrite the xlate callback
or overwrite the domain_ops?

Regards,
Wei Yongjun

2022-09-28 08:19:08

by Marc Zyngier

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings

On Wed, 28 Sep 2022 08:32:25 +0100,
Wei Yongjun <[email protected]> wrote:
>
>
>
> On 2022/9/26 20:55, Marc Zyngier wrote:
> > On Mon, 26 Sep 2022 07:24:48 -0400,
> > Bartosz Golaszewski <[email protected]> wrote:
> >>
> >> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <[email protected]> wrote:
> >>>
> >>> From: Wei Yongjun <[email protected]>
> >>>
> >>> The IRQ simulator only support one cell binding now, this patch make it
> >>> works with either one or two cell bindings, where the cell values map
> >>> directly to the irq number and irq flags.
> >>>
> >>> Signed-off-by: Wei Yongjun <[email protected]>
> >>> ---
> >>> kernel/irq/irq_sim.c | 1 +
> >>> 1 file changed, 1 insertion(+)
> >>>
> >>> diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c
> >>> index dd76323ea3fd..73a90b7b6022 100644
> >>> --- a/kernel/irq/irq_sim.c
> >>> +++ b/kernel/irq/irq_sim.c
> >>> @@ -149,6 +149,7 @@ static void irq_sim_domain_unmap(struct irq_domain *domain, unsigned int virq)
> >>> static const struct irq_domain_ops irq_sim_domain_ops = {
> >>> .map = irq_sim_domain_map,
> >>> .unmap = irq_sim_domain_unmap,
> >>> + .xlate = irq_domain_xlate_onetwocell,
> >>> };
> >>>
> >>> /**
> >>> --
> >>> 2.34.1
> >>>
> >>
> >> You'll need Marc's (Cc'ed) Ack here.
>
> Hi Marc,
>
> >
> > The question is what will the simulator code do with this information.
> > Throw it away? What of 3/4/5 cell bindings? I'd rather see the
>
> The 3/4/5 cell bindings is selience ignored currently.
>
> > simulator being extended to deal with arbitrary bindings instead of
> > trading a harcoded limit for another one. And also give some
> > semantics to the extra cells.
>
> Would you means we should allow the users to overwrite the xlate callback
> or overwrite the domain_ops?

Neither. I think the caller should provide an irq_domain_ops structure
at domain creation, with the .xlate member populated, and the irq_sim
code would add its own ops to it.

Providing NULL would ensure we fallback to the existing behaviour.

Thanks,

M.

--
Without deviation from the norm, progress is not possible.