All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] allow gpio simulator be used as interrupt controller
@ 2022-09-26  8:44 Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Wei Yongjun @ 2022-09-26  8:44 UTC (permalink / raw)
  To: Bartosz Golaszewski, Thomas Gleixner, Linus Walleij
  Cc: Wei Yongjun, linux-gpio, linux-kernel

From: Wei Yongjun <weiyongjun1@huawei.com>

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings
  2022-09-26  8:44 [PATCH v2 0/3] allow gpio simulator be used as interrupt controller Wei Yongjun
@ 2022-09-26  8:44 ` Wei Yongjun
  2022-09-26 11:24   ` Bartosz Golaszewski
  2022-09-26  8:44 ` [PATCH v2 2/3] gpio: sim: make gpio simulator can be used as interrupt controller Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 3/3] gpio: sim: document use case for " Wei Yongjun
  2 siblings, 1 reply; 8+ messages in thread
From: Wei Yongjun @ 2022-09-26  8:44 UTC (permalink / raw)
  To: Bartosz Golaszewski, Thomas Gleixner, Linus Walleij
  Cc: Wei Yongjun, linux-gpio, linux-kernel

From: Wei Yongjun <weiyongjun1@huawei.com>

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 <weiyongjun1@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 2/3] gpio: sim: make gpio simulator can be used as interrupt controller
  2022-09-26  8:44 [PATCH v2 0/3] allow gpio simulator be used as interrupt controller Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
@ 2022-09-26  8:44 ` Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 3/3] gpio: sim: document use case for " Wei Yongjun
  2 siblings, 0 replies; 8+ messages in thread
From: Wei Yongjun @ 2022-09-26  8:44 UTC (permalink / raw)
  To: Bartosz Golaszewski, Thomas Gleixner, Linus Walleij
  Cc: Wei Yongjun, linux-gpio, linux-kernel

From: Wei Yongjun <weiyongjun1@huawei.com>

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 <weiyongjun1@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v2 3/3] gpio: sim: document use case for interrupt controller
  2022-09-26  8:44 [PATCH v2 0/3] allow gpio simulator be used as interrupt controller Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
  2022-09-26  8:44 ` [PATCH v2 2/3] gpio: sim: make gpio simulator can be used as interrupt controller Wei Yongjun
@ 2022-09-26  8:44 ` Wei Yongjun
  2 siblings, 0 replies; 8+ messages in thread
From: Wei Yongjun @ 2022-09-26  8:44 UTC (permalink / raw)
  To: Bartosz Golaszewski, Thomas Gleixner, Linus Walleij
  Cc: Wei Yongjun, linux-gpio, linux-kernel

From: Wei Yongjun <weiyongjun1@huawei.com>

Add document for using GPIO sim as interrupt controller.

Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings
  2022-09-26  8:44 ` [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
@ 2022-09-26 11:24   ` Bartosz Golaszewski
  2022-09-26 12:55     ` Marc Zyngier
  0 siblings, 1 reply; 8+ messages in thread
From: Bartosz Golaszewski @ 2022-09-26 11:24 UTC (permalink / raw)
  To: Wei Yongjun, Marc Zyngier
  Cc: Thomas Gleixner, Linus Walleij, Wei Yongjun, linux-gpio, linux-kernel

On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <weiyongjun@huaweicloud.com> wrote:
>
> From: Wei Yongjun <weiyongjun1@huawei.com>
>
> 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 <weiyongjun1@huawei.com>
> ---
>  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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings
  2022-09-26 11:24   ` Bartosz Golaszewski
@ 2022-09-26 12:55     ` Marc Zyngier
  2022-09-28  7:32       ` Wei Yongjun
  0 siblings, 1 reply; 8+ messages in thread
From: Marc Zyngier @ 2022-09-26 12:55 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Wei Yongjun, Thomas Gleixner, Linus Walleij, Wei Yongjun,
	linux-gpio, linux-kernel

On Mon, 26 Sep 2022 07:24:48 -0400,
Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> 
> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <weiyongjun@huaweicloud.com> wrote:
> >
> > From: Wei Yongjun <weiyongjun1@huawei.com>
> >
> > 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 <weiyongjun1@huawei.com>
> > ---
> >  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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings
  2022-09-26 12:55     ` Marc Zyngier
@ 2022-09-28  7:32       ` Wei Yongjun
  2022-09-28  7:47         ` Marc Zyngier
  0 siblings, 1 reply; 8+ messages in thread
From: Wei Yongjun @ 2022-09-28  7:32 UTC (permalink / raw)
  To: Marc Zyngier, Bartosz Golaszewski
  Cc: Wei Yongjun, Thomas Gleixner, Linus Walleij, linux-gpio, linux-kernel



On 2022/9/26 20:55, Marc Zyngier wrote:
> On Mon, 26 Sep 2022 07:24:48 -0400,
> Bartosz Golaszewski <brgl@bgdev.pl> wrote:
>>
>> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <weiyongjun@huaweicloud.com> wrote:
>>>
>>> From: Wei Yongjun <weiyongjun1@huawei.com>
>>>
>>> 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 <weiyongjun1@huawei.com>
>>> ---
>>>  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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings
  2022-09-28  7:32       ` Wei Yongjun
@ 2022-09-28  7:47         ` Marc Zyngier
  0 siblings, 0 replies; 8+ messages in thread
From: Marc Zyngier @ 2022-09-28  7:47 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Bartosz Golaszewski, Wei Yongjun, Thomas Gleixner, Linus Walleij,
	linux-gpio, linux-kernel

On Wed, 28 Sep 2022 08:32:25 +0100,
Wei Yongjun <weiyongjun1@huawei.com> wrote:
> 
> 
> 
> On 2022/9/26 20:55, Marc Zyngier wrote:
> > On Mon, 26 Sep 2022 07:24:48 -0400,
> > Bartosz Golaszewski <brgl@bgdev.pl> wrote:
> >>
> >> On Mon, Sep 26, 2022 at 10:27 AM Wei Yongjun <weiyongjun@huaweicloud.com> wrote:
> >>>
> >>> From: Wei Yongjun <weiyongjun1@huawei.com>
> >>>
> >>> 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 <weiyongjun1@huawei.com>
> >>> ---
> >>>  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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-28  7:55 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26  8:44 [PATCH v2 0/3] allow gpio simulator be used as interrupt controller Wei Yongjun
2022-09-26  8:44 ` [PATCH v2 1/3] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
2022-09-26 11:24   ` Bartosz Golaszewski
2022-09-26 12:55     ` Marc Zyngier
2022-09-28  7:32       ` Wei Yongjun
2022-09-28  7:47         ` Marc Zyngier
2022-09-26  8:44 ` [PATCH v2 2/3] gpio: sim: make gpio simulator can be used as interrupt controller Wei Yongjun
2022-09-26  8:44 ` [PATCH v2 3/3] gpio: sim: document use case for " Wei Yongjun

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.