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

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


--[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 (2):
  genirq/irq_sim: Allow both one and two cell bindings
  gpio: sim: make gpio simulator can be used as interrupt controller

 drivers/gpio/gpio-sim.c | 2 +-
 kernel/irq/irq_sim.c    | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
2.34.1


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

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

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] 6+ messages in thread

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

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] 6+ messages in thread

* Re: [PATCH -next 0/2] allow gpio simulator be used as interrupt controller
  2022-08-26  8:02 [PATCH -next 0/2] allow gpio simulator be used as interrupt controller Wei Yongjun
  2022-08-26  8:02 ` [PATCH -next 1/2] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
  2022-08-26  8:02 ` [PATCH -next 2/2] gpio: sim: make gpio simulator can be used as interrupt controller Wei Yongjun
@ 2022-08-31 16:08 ` Bartosz Golaszewski
  2022-09-26  6:57   ` Wei Yongjun
  2 siblings, 1 reply; 6+ messages in thread
From: Bartosz Golaszewski @ 2022-08-31 16:08 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Thomas Gleixner, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List

On Fri, Aug 26, 2022 at 9:44 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
>
> 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
>
>
> --[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";
>                         };

Why do you need this hog? The GPIO will be marked as requested once
the interrupt is taken by the driver.

>                 };
>         };
>
>         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 (2):
>   genirq/irq_sim: Allow both one and two cell bindings
>   gpio: sim: make gpio simulator can be used as interrupt controller
>
>  drivers/gpio/gpio-sim.c | 2 +-
>  kernel/irq/irq_sim.c    | 1 +
>  2 files changed, 2 insertions(+), 1 deletion(-)
>
> --
> 2.34.1
>

Can you add some info about this to the documentation?

Otherwise looks good.

Bart

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

* Re: [PATCH -next 0/2] allow gpio simulator be used as interrupt controller
  2022-08-31 16:08 ` [PATCH -next 0/2] allow gpio simulator " Bartosz Golaszewski
@ 2022-09-26  6:57   ` Wei Yongjun
  2022-09-26  7:38     ` Bartosz Golaszewski
  0 siblings, 1 reply; 6+ messages in thread
From: Wei Yongjun @ 2022-09-26  6:57 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Thomas Gleixner, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List



On 2022/9/1 0:08, Bartosz Golaszewski wrote:
> On Fri, Aug 26, 2022 at 9:44 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
>>
>> 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
>>
>>
>> --[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";
>>                         };
> 
> Why do you need this hog? The GPIO will be marked as requested once
> the interrupt is taken by the driver.

Sorry for reply later.

It seems that only if driver request gpio with fwnode_gpiod_get_index()
marks GPIO as request one.

If driver using request_threaded_irq() request one irq, the requested
status will not be marked. We need to use hog or request by userspace
to mark as requested.

> 
>>                 };
>>         };
>>
>>         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 (2):
>>   genirq/irq_sim: Allow both one and two cell bindings
>>   gpio: sim: make gpio simulator can be used as interrupt controller
>>
>>  drivers/gpio/gpio-sim.c | 2 +-
>>  kernel/irq/irq_sim.c    | 1 +
>>  2 files changed, 2 insertions(+), 1 deletion(-)
>>
>> --
>> 2.34.1
>>
> 
> Can you add some info about this to the documentation?

Will do that

Thanks,
Wei Yongjun

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

* Re: [PATCH -next 0/2] allow gpio simulator be used as interrupt controller
  2022-09-26  6:57   ` Wei Yongjun
@ 2022-09-26  7:38     ` Bartosz Golaszewski
  0 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2022-09-26  7:38 UTC (permalink / raw)
  To: Wei Yongjun
  Cc: Thomas Gleixner, Linus Walleij, open list:GPIO SUBSYSTEM,
	Linux Kernel Mailing List

On Mon, Sep 26, 2022 at 8:57 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
>
>
>
> On 2022/9/1 0:08, Bartosz Golaszewski wrote:
> > On Fri, Aug 26, 2022 at 9:44 AM Wei Yongjun <weiyongjun1@huawei.com> wrote:
> >>
> >> 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
> >>
> >>
> >> --[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";
> >>                         };
> >
> > Why do you need this hog? The GPIO will be marked as requested once
> > the interrupt is taken by the driver.
>
> Sorry for reply later.
>
> It seems that only if driver request gpio with fwnode_gpiod_get_index()
> marks GPIO as request one.
>
> If driver using request_threaded_irq() request one irq, the requested
> status will not be marked. We need to use hog or request by userspace
> to mark as requested.
>

Right, of course. Thanks.

> >
> >>                 };
> >>         };
> >>
> >>         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 (2):
> >>   genirq/irq_sim: Allow both one and two cell bindings
> >>   gpio: sim: make gpio simulator can be used as interrupt controller
> >>
> >>  drivers/gpio/gpio-sim.c | 2 +-
> >>  kernel/irq/irq_sim.c    | 1 +
> >>  2 files changed, 2 insertions(+), 1 deletion(-)
> >>
> >> --
> >> 2.34.1
> >>
> >
> > Can you add some info about this to the documentation?
>

Ok, I'll wait for v2.

And you can drop the -next prefix too, it doesn't fix anything in next.

Bart

> Will do that
>
> Thanks,
> Wei Yongjun

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

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

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-26  8:02 [PATCH -next 0/2] allow gpio simulator be used as interrupt controller Wei Yongjun
2022-08-26  8:02 ` [PATCH -next 1/2] genirq/irq_sim: Allow both one and two cell bindings Wei Yongjun
2022-08-26  8:02 ` [PATCH -next 2/2] gpio: sim: make gpio simulator can be used as interrupt controller Wei Yongjun
2022-08-31 16:08 ` [PATCH -next 0/2] allow gpio simulator " Bartosz Golaszewski
2022-09-26  6:57   ` Wei Yongjun
2022-09-26  7:38     ` Bartosz Golaszewski

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.