All of lore.kernel.org
 help / color / mirror / Atom feed
* Is a multiplexer using latches a gpio controller?
@ 2022-07-18 20:22 Uwe Kleine-König
  2022-07-18 22:05 ` Andy Shevchenko
  2022-07-18 22:54 ` Linus Walleij
  0 siblings, 2 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2022-07-18 20:22 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski; +Cc: linux-gpio, kernel

[-- Attachment #1: Type: text/plain, Size: 2382 bytes --]

Hello,

we have a customer board here that uses two 8 port latches to drive
LEDs. The setup looks as follows:

CLK0 ----------------------.        ,--------.
CLK1 -------------------.  `--------|>    #0 |
                        |           |        |
IN0 -----------------+--|-----------|D0    Q0|-----|◁
IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
       | | | | | | | |  |           `--------'
       | | | | | | | |  |
       | | | | | | | |  |           ,--------.
       | | | | | | | |  `-----------|>    #1 |
       | | | | | | | |              |        |
       | | | | | | | `--------------|D0    Q0|-----|◁
       | | | | | | `----------------|D1    Q1|-----|◁
       | | | | | `------------------|D2    Q2|-----|◁
       | | | | `--------------------|D3    Q3|-----|◁
       | | | `----------------------|D4    Q4|-----|◁
       | | `------------------------|D5    Q5|-----|◁
       | `--------------------------|D6    Q6|-----|◁
       `----------------------------|D7    Q7|-----|◁
                                    `--------'


So to change output 2 of latch #1 you have to apply the changed level on
IN2, apply the previous level on the other inputs (to keep the other
outputs constant) and toggle CLK1 once.

This way you can drive 16 LEDs (or in general outputs) using only 10
GPIOs. (And with a higher number of latches the proportion becomes a bit
more useful.)

Actually this construct is a general GPO (no input :-) controller, and I
wonder if you would accept a driver that models it as a gpio controller.

The dt binding could look as follows:

latch-gpo {
	compatible = "latch-gpo";
	pinctrl-0 = <...>;
	pinctrl-names = <...>;

	clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
	data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
};

What do you think?

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 20:22 Is a multiplexer using latches a gpio controller? Uwe Kleine-König
@ 2022-07-18 22:05 ` Andy Shevchenko
  2022-07-18 22:11   ` Andy Shevchenko
  2022-07-18 22:54 ` Linus Walleij
  1 sibling, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2022-07-18 22:05 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	Sascha Hauer

On Mon, Jul 18, 2022 at 10:27 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
>
> Hello,
>
> we have a customer board here that uses two 8 port latches to drive
> LEDs. The setup looks as follows:
>
> CLK0 ----------------------.        ,--------.
> CLK1 -------------------.  `--------|>    #0 |
>                         |           |        |
> IN0 -----------------+--|-----------|D0    Q0|-----|◁
> IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
> IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
> IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
> IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
> IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
> IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
> IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
>        | | | | | | | |  |           `--------'
>        | | | | | | | |  |
>        | | | | | | | |  |           ,--------.
>        | | | | | | | |  `-----------|>    #1 |
>        | | | | | | | |              |        |
>        | | | | | | | `--------------|D0    Q0|-----|◁
>        | | | | | | `----------------|D1    Q1|-----|◁
>        | | | | | `------------------|D2    Q2|-----|◁
>        | | | | `--------------------|D3    Q3|-----|◁
>        | | | `----------------------|D4    Q4|-----|◁
>        | | `------------------------|D5    Q5|-----|◁
>        | `--------------------------|D6    Q6|-----|◁
>        `----------------------------|D7    Q7|-----|◁
>                                     `--------'
>
>
> So to change output 2 of latch #1 you have to apply the changed level on
> IN2, apply the previous level on the other inputs (to keep the other
> outputs constant) and toggle CLK1 once.
>
> This way you can drive 16 LEDs (or in general outputs) using only 10
> GPIOs. (And with a higher number of latches the proportion becomes a bit
> more useful.)
>
> Actually this construct is a general GPO (no input :-) controller, and I
> wonder if you would accept a driver that models it as a gpio controller.
>
> The dt binding could look as follows:
>
> latch-gpo {
>         compatible = "latch-gpo";
>         pinctrl-0 = <...>;
>         pinctrl-names = <...>;
>
>         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
>         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> };
>
> What do you think?

Bart, what happened to the [1]? Is it abandoned, forgotten?

Uwe, isn't it what you need?

[1]: https://lore.kernel.org/linux-gpio/20220205215918.8924-1-maukka@ext.kapsi.fi/

-- 
With Best Regards,
Andy Shevchenko

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 22:05 ` Andy Shevchenko
@ 2022-07-18 22:11   ` Andy Shevchenko
  2022-07-19  7:19     ` Uwe Kleine-König
  0 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2022-07-18 22:11 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Linus Walleij, Bartosz Golaszewski, open list:GPIO SUBSYSTEM,
	Sascha Hauer

On Tue, Jul 19, 2022 at 12:05 AM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Mon, Jul 18, 2022 at 10:27 PM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> >
> > Hello,
> >
> > we have a customer board here that uses two 8 port latches to drive
> > LEDs. The setup looks as follows:
> >
> > CLK0 ----------------------.        ,--------.
> > CLK1 -------------------.  `--------|>    #0 |
> >                         |           |        |
> > IN0 -----------------+--|-----------|D0    Q0|-----|◁
> > IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
> > IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
> > IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
> > IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
> > IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
> > IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
> > IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
> >        | | | | | | | |  |           `--------'
> >        | | | | | | | |  |
> >        | | | | | | | |  |           ,--------.
> >        | | | | | | | |  `-----------|>    #1 |
> >        | | | | | | | |              |        |
> >        | | | | | | | `--------------|D0    Q0|-----|◁
> >        | | | | | | `----------------|D1    Q1|-----|◁
> >        | | | | | `------------------|D2    Q2|-----|◁
> >        | | | | `--------------------|D3    Q3|-----|◁
> >        | | | `----------------------|D4    Q4|-----|◁
> >        | | `------------------------|D5    Q5|-----|◁
> >        | `--------------------------|D6    Q6|-----|◁
> >        `----------------------------|D7    Q7|-----|◁
> >                                     `--------'
> >
> >
> > So to change output 2 of latch #1 you have to apply the changed level on
> > IN2, apply the previous level on the other inputs (to keep the other
> > outputs constant) and toggle CLK1 once.
> >
> > This way you can drive 16 LEDs (or in general outputs) using only 10
> > GPIOs. (And with a higher number of latches the proportion becomes a bit
> > more useful.)
> >
> > Actually this construct is a general GPO (no input :-) controller, and I
> > wonder if you would accept a driver that models it as a gpio controller.
> >
> > The dt binding could look as follows:
> >
> > latch-gpo {
> >         compatible = "latch-gpo";
> >         pinctrl-0 = <...>;
> >         pinctrl-names = <...>;
> >
> >         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
> >         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> > };
> >
> > What do you think?
>
> Bart, what happened to the [1]? Is it abandoned, forgotten?
>
> Uwe, isn't it what you need?

It needs "downstream" GPIO and ->get_direction(), etc should act accordingly.

> [1]: https://lore.kernel.org/linux-gpio/20220205215918.8924-1-maukka@ext.kapsi.fi/

-- 
With Best Regards,
Andy Shevchenko

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 20:22 Is a multiplexer using latches a gpio controller? Uwe Kleine-König
  2022-07-18 22:05 ` Andy Shevchenko
@ 2022-07-18 22:54 ` Linus Walleij
  2022-07-18 23:11   ` Andy Shevchenko
  2022-07-19  7:49   ` Uwe Kleine-König
  1 sibling, 2 replies; 11+ messages in thread
From: Linus Walleij @ 2022-07-18 22:54 UTC (permalink / raw)
  To: Uwe Kleine-König; +Cc: Bartosz Golaszewski, linux-gpio, kernel

On Mon, Jul 18, 2022 at 10:22 PM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:

> we have a customer board here that uses two 8 port latches to drive
> LEDs. The setup looks as follows:

Very nice drawing!

> So to change output 2 of latch #1 you have to apply the changed level on
> IN2, apply the previous level on the other inputs (to keep the other
> outputs constant) and toggle CLK1 once.
>
> This way you can drive 16 LEDs (or in general outputs) using only 10
> GPIOs. (And with a higher number of latches the proportion becomes a bit
> more useful.)
>
> Actually this construct is a general GPO (no input :-) controller, and I
> wonder if you would accept a driver that models it as a gpio controller.

In my opinion, yes.

> The dt binding could look as follows:
>
> latch-gpo {
>         compatible = "latch-gpo";
>         pinctrl-0 = <...>;
>         pinctrl-names = <...>;
>
>         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
>         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> };
>
> What do you think?

I would use the actual 74xx numbers for the TTL circuits in the compatible.
I have actually merged this placeholder (without bindings nor driver):

        /*
         * 74HC4094 which is used as a rudimentary GPIO expander
         * FIXME:
         * - Create device tree bindings for this as GPIO expander
         * - Write a pure DT GPIO driver using these bindings
         * - Support cascading in the style of gpio-74x164.c (cannot
be reused, very different)
         */
        gpio_74: gpio-74hc4094 {
                compatible = "nxp,74hc4094";
                cp-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
                d-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
                str-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
                /* oe-gpios is optional */
                gpio-controller;
                #gpio-cells = <2>;
                /* We are not cascaded */
                registers-number = <1>;
                gpio-line-names = "CONTROL_HSS0_CLK_INT",
"CONTROL_HSS1_CLK_INT", "CONTROL_HSS0_DTR_N",
                                "CONTROL_HSS1_DTR_N", "CONTROL_EXT",
"CONTROL_AUTO_RESET",
                                "CONTROL_PCI_RESET_N", "CONTROL_EEPROM_WC_N";
        };

What's nice with 74HC4094 is that it has a strobe (str) signal so you can send
out all the values and then strobe them out in one go. But your construction
makes sense too!

Yours,
Linus Walleij

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 22:54 ` Linus Walleij
@ 2022-07-18 23:11   ` Andy Shevchenko
  2022-07-19  7:49   ` Uwe Kleine-König
  1 sibling, 0 replies; 11+ messages in thread
From: Andy Shevchenko @ 2022-07-18 23:11 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Uwe Kleine-König, Bartosz Golaszewski,
	open list:GPIO SUBSYSTEM, Sascha Hauer

On Tue, Jul 19, 2022 at 12:58 AM Linus Walleij <linus.walleij@linaro.org> wrote:
>
> On Mon, Jul 18, 2022 at 10:22 PM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:

...

> I would use the actual 74xx numbers for the TTL circuits in the compatible.
> I have actually merged this placeholder (without bindings nor driver):
>
>         /*
>          * 74HC4094 which is used as a rudimentary GPIO expander
>          * FIXME:
>          * - Create device tree bindings for this as GPIO expander
>          * - Write a pure DT GPIO driver using these bindings
>          * - Support cascading in the style of gpio-74x164.c (cannot
> be reused, very different)
>          */
>         gpio_74: gpio-74hc4094 {
>                 compatible = "nxp,74hc4094";
>                 cp-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
>                 d-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
>                 str-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
>                 /* oe-gpios is optional */
>                 gpio-controller;
>                 #gpio-cells = <2>;
>                 /* We are not cascaded */
>                 registers-number = <1>;
>                 gpio-line-names = "CONTROL_HSS0_CLK_INT",
> "CONTROL_HSS1_CLK_INT", "CONTROL_HSS0_DTR_N",
>                                 "CONTROL_HSS1_DTR_N", "CONTROL_EXT",
> "CONTROL_AUTO_RESET",
>                                 "CONTROL_PCI_RESET_N", "CONTROL_EEPROM_WC_N";
>         };
>
> What's nice with 74HC4094 is that it has a strobe (str) signal so you can send
> out all the values and then strobe them out in one go. But your construction
> makes sense too!

But 4094 is SPI and covered by 74x164 driver, while Uwe's case is
parallel drivers, which covered by
74xx driver.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 22:11   ` Andy Shevchenko
@ 2022-07-19  7:19     ` Uwe Kleine-König
  2022-07-25  9:19       ` Andy Shevchenko
  0 siblings, 1 reply; 11+ messages in thread
From: Uwe Kleine-König @ 2022-07-19  7:19 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Bartosz Golaszewski,
	Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 3627 bytes --]

On Tue, Jul 19, 2022 at 12:11:56AM +0200, Andy Shevchenko wrote:
> On Tue, Jul 19, 2022 at 12:05 AM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> >
> > On Mon, Jul 18, 2022 at 10:27 PM Uwe Kleine-König
> > <u.kleine-koenig@pengutronix.de> wrote:
> > >
> > > Hello,
> > >
> > > we have a customer board here that uses two 8 port latches to drive
> > > LEDs. The setup looks as follows:
> > >
> > > CLK0 ----------------------.        ,--------.
> > > CLK1 -------------------.  `--------|>    #0 |
> > >                         |           |        |
> > > IN0 -----------------+--|-----------|D0    Q0|-----|◁
> > > IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
> > > IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
> > > IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
> > > IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
> > > IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
> > > IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
> > > IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
> > >        | | | | | | | |  |           `--------'
> > >        | | | | | | | |  |
> > >        | | | | | | | |  |           ,--------.
> > >        | | | | | | | |  `-----------|>    #1 |
> > >        | | | | | | | |              |        |
> > >        | | | | | | | `--------------|D0    Q0|-----|◁
> > >        | | | | | | `----------------|D1    Q1|-----|◁
> > >        | | | | | `------------------|D2    Q2|-----|◁
> > >        | | | | `--------------------|D3    Q3|-----|◁
> > >        | | | `----------------------|D4    Q4|-----|◁
> > >        | | `------------------------|D5    Q5|-----|◁
> > >        | `--------------------------|D6    Q6|-----|◁
> > >        `----------------------------|D7    Q7|-----|◁
> > >                                     `--------'
> > >
> > >
> > > So to change output 2 of latch #1 you have to apply the changed level on
> > > IN2, apply the previous level on the other inputs (to keep the other
> > > outputs constant) and toggle CLK1 once.
> > >
> > > This way you can drive 16 LEDs (or in general outputs) using only 10
> > > GPIOs. (And with a higher number of latches the proportion becomes a bit
> > > more useful.)
> > >
> > > Actually this construct is a general GPO (no input :-) controller, and I
> > > wonder if you would accept a driver that models it as a gpio controller.
> > >
> > > The dt binding could look as follows:
> > >
> > > latch-gpo {
> > >         compatible = "latch-gpo";
> > >         pinctrl-0 = <...>;
> > >         pinctrl-names = <...>;
> > >
> > >         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
> > >         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> > > };
> > >
> > > What do you think?
> >
> > Bart, what happened to the [1]? Is it abandoned, forgotten?
> >
> > Uwe, isn't it what you need?
> 
> It needs "downstream" GPIO and ->get_direction(), etc should act accordingly.

No, IIUC this is different. With a multiplexer there can always only be
a single line that is controlled (or read) and the other lines are (I
assume) high-z.

The latch approach above is about 16 outputs and at all times the state
off all 16 lines is fixed because the latches keep their state when the
clk line is kept stable.

Best regards
Uwe

> > [1]: https://lore.kernel.org/linux-gpio/20220205215918.8924-1-maukka@ext.kapsi.fi/

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-18 22:54 ` Linus Walleij
  2022-07-18 23:11   ` Andy Shevchenko
@ 2022-07-19  7:49   ` Uwe Kleine-König
  2022-07-19  9:13     ` Andy Shevchenko
  1 sibling, 1 reply; 11+ messages in thread
From: Uwe Kleine-König @ 2022-07-19  7:49 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Bartosz Golaszewski, kernel

[-- Attachment #1: Type: text/plain, Size: 4017 bytes --]

On Tue, Jul 19, 2022 at 12:54:18AM +0200, Linus Walleij wrote:
> On Mon, Jul 18, 2022 at 10:22 PM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> 
> > we have a customer board here that uses two 8 port latches to drive
> > LEDs. The setup looks as follows:
> 
> Very nice drawing!
> 
> > So to change output 2 of latch #1 you have to apply the changed level on
> > IN2, apply the previous level on the other inputs (to keep the other
> > outputs constant) and toggle CLK1 once.
> >
> > This way you can drive 16 LEDs (or in general outputs) using only 10
> > GPIOs. (And with a higher number of latches the proportion becomes a bit
> > more useful.)
> >
> > Actually this construct is a general GPO (no input :-) controller, and I
> > wonder if you would accept a driver that models it as a gpio controller.
> 
> In my opinion, yes.

ok, fine.

> > The dt binding could look as follows:
> >
> > latch-gpo {
> >         compatible = "latch-gpo";
> >         pinctrl-0 = <...>;
> >         pinctrl-names = <...>;
> >
> >         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
> >         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> > };
> >
> > What do you think?
> 
> I would use the actual 74xx numbers for the TTL circuits in the compatible.

To be actually useful I need at least two latches. In my case their
name is SN74LS273. (https://www.ti.com/lit/ds/symlink/sn74ls273.pdf)
So I hesitate to call this "ti,sn74ls273" because that would suggest a
single such chip?!

> I have actually merged this placeholder (without bindings nor driver):
> 
>         /*
>          * 74HC4094 which is used as a rudimentary GPIO expander
>          * FIXME:
>          * - Create device tree bindings for this as GPIO expander
>          * - Write a pure DT GPIO driver using these bindings
>          * - Support cascading in the style of gpio-74x164.c (cannot
> be reused, very different)
>          */
>         gpio_74: gpio-74hc4094 {
>                 compatible = "nxp,74hc4094";
>                 cp-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
>                 d-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
>                 str-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
>                 /* oe-gpios is optional */
>                 gpio-controller;
>                 #gpio-cells = <2>;
>                 /* We are not cascaded */
>                 registers-number = <1>;
>                 gpio-line-names = "CONTROL_HSS0_CLK_INT",
> "CONTROL_HSS1_CLK_INT", "CONTROL_HSS0_DTR_N",
>                                 "CONTROL_HSS1_DTR_N", "CONTROL_EXT",
> "CONTROL_AUTO_RESET",
>                                 "CONTROL_PCI_RESET_N", "CONTROL_EEPROM_WC_N";
>         };

This is different (as Andy pointed out): With this chip you have to
clock in the $n values serially while with my approach you have a
parallel input.

I think for the serial approach you don't even need to consider a
register-number. IIUC a cascade just behaves like a single chip with
more stages, right? Then I'd not specify a "registers-number" but a
number of stages. And then that's just (as Andy pointed out) a spi
device. I would represent that as follows:

	
	spi {
		compatible = "spi-gpio";
		#address-cells = <0x1>;
		#size-cells = <0x0>;

		sck-gpios = <&gpio0 0 GPIO_ACTIVE_HIGH>;
		//miso-gpios = ??
		mosi-gpios = <&gpio0 1 GPIO_ACTIVE_HIGH>;
		cs-gpios = <&gpio0 2 GPIO_ACTIVE_HIGH>;
		num-chipselects = <1>;

		gpio-74hc4094 {
			compatible = "nxp,74hc4094";
			reg = <0>;

			oe-gpios = <...>; /* optional */
			num-stages = <8>; /* = default value */

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

			gpio-line-names = ...;
		};
	}

(And if you have a "native" spi bus, even better.) This way the
nxp,74hc4094 driver becomes way easier.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-19  7:49   ` Uwe Kleine-König
@ 2022-07-19  9:13     ` Andy Shevchenko
  2022-07-20  5:25       ` Uwe Kleine-König
  0 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2022-07-19  9:13 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Linus Walleij, open list:GPIO SUBSYSTEM, Bartosz Golaszewski,
	Sascha Hauer

On Tue, Jul 19, 2022 at 9:50 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Tue, Jul 19, 2022 at 12:54:18AM +0200, Linus Walleij wrote:

...

> (And if you have a "native" spi bus, even better.) This way the
> nxp,74hc4094 driver becomes way easier.

Just to say (point out again?) that
1) The SPI can be bitbanging in this case, so GPIO lines can be used;
2) We have a driver already, which is called gpio-74x164.

-- 
With Best Regards,
Andy Shevchenko

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-19  9:13     ` Andy Shevchenko
@ 2022-07-20  5:25       ` Uwe Kleine-König
  0 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2022-07-20  5:25 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Bartosz Golaszewski,
	Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 926 bytes --]

Hello,

On Tue, Jul 19, 2022 at 11:13:11AM +0200, Andy Shevchenko wrote:
> On Tue, Jul 19, 2022 at 9:50 AM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Tue, Jul 19, 2022 at 12:54:18AM +0200, Linus Walleij wrote:
> 
> ...
> 
> > (And if you have a "native" spi bus, even better.) This way the
> > nxp,74hc4094 driver becomes way easier.
> 
> Just to say (point out again?) that
> 1) The SPI can be bitbanging in this case, so GPIO lines can be used;

Yeah, in my example GPIO lines were used.

> 2) We have a driver already, which is called gpio-74x164.

I'm also aware. My reply was on Linus's binding example which *only*
supports bit-banging and which is different to what the 74x164 driver
consumes.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-19  7:19     ` Uwe Kleine-König
@ 2022-07-25  9:19       ` Andy Shevchenko
  2022-07-25 19:07         ` Uwe Kleine-König
  0 siblings, 1 reply; 11+ messages in thread
From: Andy Shevchenko @ 2022-07-25  9:19 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Bartosz Golaszewski,
	Sascha Hauer

On Tue, Jul 19, 2022 at 9:19 AM Uwe Kleine-König
<u.kleine-koenig@pengutronix.de> wrote:
> On Tue, Jul 19, 2022 at 12:11:56AM +0200, Andy Shevchenko wrote:
> > On Tue, Jul 19, 2022 at 12:05 AM Andy Shevchenko
> > <andy.shevchenko@gmail.com> wrote:
> > > On Mon, Jul 18, 2022 at 10:27 PM Uwe Kleine-König
> > > <u.kleine-koenig@pengutronix.de> wrote:

> > > > we have a customer board here that uses two 8 port latches to drive
> > > > LEDs. The setup looks as follows:
> > > >
> > > > CLK0 ----------------------.        ,--------.
> > > > CLK1 -------------------.  `--------|>    #0 |
> > > >                         |           |        |
> > > > IN0 -----------------+--|-----------|D0    Q0|-----|◁
> > > > IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
> > > > IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
> > > > IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
> > > > IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
> > > > IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
> > > > IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
> > > > IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
> > > >        | | | | | | | |  |           `--------'
> > > >        | | | | | | | |  |
> > > >        | | | | | | | |  |           ,--------.
> > > >        | | | | | | | |  `-----------|>    #1 |
> > > >        | | | | | | | |              |        |
> > > >        | | | | | | | `--------------|D0    Q0|-----|◁
> > > >        | | | | | | `----------------|D1    Q1|-----|◁
> > > >        | | | | | `------------------|D2    Q2|-----|◁
> > > >        | | | | `--------------------|D3    Q3|-----|◁
> > > >        | | | `----------------------|D4    Q4|-----|◁
> > > >        | | `------------------------|D5    Q5|-----|◁
> > > >        | `--------------------------|D6    Q6|-----|◁
> > > >        `----------------------------|D7    Q7|-----|◁
> > > >                                     `--------'
> > > >
> > > >
> > > > So to change output 2 of latch #1 you have to apply the changed level on
> > > > IN2, apply the previous level on the other inputs (to keep the other
> > > > outputs constant) and toggle CLK1 once.
> > > >
> > > > This way you can drive 16 LEDs (or in general outputs) using only 10
> > > > GPIOs. (And with a higher number of latches the proportion becomes a bit
> > > > more useful.)
> > > >
> > > > Actually this construct is a general GPO (no input :-) controller, and I
> > > > wonder if you would accept a driver that models it as a gpio controller.
> > > >
> > > > The dt binding could look as follows:
> > > >
> > > > latch-gpo {
> > > >         compatible = "latch-gpo";
> > > >         pinctrl-0 = <...>;
> > > >         pinctrl-names = <...>;
> > > >
> > > >         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
> > > >         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> > > > };
> > > >
> > > > What do you think?
> > >
> > > Bart, what happened to the [1]? Is it abandoned, forgotten?
> > >
> > > Uwe, isn't it what you need?
> >
> > It needs "downstream" GPIO and ->get_direction(), etc should act accordingly.
>
> No, IIUC this is different. With a multiplexer there can always only be
> a single line that is controlled (or read) and the other lines are (I
> assume) high-z.

I don't know the Linux mux framework implementation, but from a
hardware perspective the mux is what you have. In the GPIO (mux)
driver you need to be able to switch banks as you wish, the rest is
the drivers' business. If gpio-cascade gives no possibility to do that
due to broken mux in Linux, then indeed, it can't be accepted at all
and I have to withdraw my tags from that.

> The latch approach above is about 16 outputs and at all times the state
> off all 16 lines is fixed because the latches keep their state when the
> clk line is kept stable.

> > > [1]: https://lore.kernel.org/linux-gpio/20220205215918.8924-1-maukka@ext.kapsi.fi/

-- 
With Best Regards,
Andy Shevchenko

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

* Re: Is a multiplexer using latches a gpio controller?
  2022-07-25  9:19       ` Andy Shevchenko
@ 2022-07-25 19:07         ` Uwe Kleine-König
  0 siblings, 0 replies; 11+ messages in thread
From: Uwe Kleine-König @ 2022-07-25 19:07 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Bartosz Golaszewski,
	Sascha Hauer

[-- Attachment #1: Type: text/plain, Size: 4861 bytes --]

On Mon, Jul 25, 2022 at 11:19:54AM +0200, Andy Shevchenko wrote:
> On Tue, Jul 19, 2022 at 9:19 AM Uwe Kleine-König
> <u.kleine-koenig@pengutronix.de> wrote:
> > On Tue, Jul 19, 2022 at 12:11:56AM +0200, Andy Shevchenko wrote:
> > > On Tue, Jul 19, 2022 at 12:05 AM Andy Shevchenko
> > > <andy.shevchenko@gmail.com> wrote:
> > > > On Mon, Jul 18, 2022 at 10:27 PM Uwe Kleine-König
> > > > <u.kleine-koenig@pengutronix.de> wrote:
> 
> > > > > we have a customer board here that uses two 8 port latches to drive
> > > > > LEDs. The setup looks as follows:
> > > > >
> > > > > CLK0 ----------------------.        ,--------.
> > > > > CLK1 -------------------.  `--------|>    #0 |
> > > > >                         |           |        |
> > > > > IN0 -----------------+--|-----------|D0    Q0|-----|◁
> > > > > IN1 ---------------+-|--|-----------|D1    Q1|-----|◁
> > > > > IN2 -------------+-|-|--|-----------|D2    Q2|-----|◁
> > > > > IN3 -----------+-|-|-|--|-----------|D3    Q3|-----|◁
> > > > > IN4 ---------+-|-|-|-|--|-----------|D4    Q4|-----|◁
> > > > > IN5 -------+-|-|-|-|-|--|-----------|D5    Q5|-----|◁
> > > > > IN6 -----+-|-|-|-|-|-|--|-----------|D6    Q6|-----|◁
> > > > > IN7 ---+-|-|-|-|-|-|-|--|-----------|D7    Q7|-----|◁
> > > > >        | | | | | | | |  |           `--------'
> > > > >        | | | | | | | |  |
> > > > >        | | | | | | | |  |           ,--------.
> > > > >        | | | | | | | |  `-----------|>    #1 |
> > > > >        | | | | | | | |              |        |
> > > > >        | | | | | | | `--------------|D0    Q0|-----|◁
> > > > >        | | | | | | `----------------|D1    Q1|-----|◁
> > > > >        | | | | | `------------------|D2    Q2|-----|◁
> > > > >        | | | | `--------------------|D3    Q3|-----|◁
> > > > >        | | | `----------------------|D4    Q4|-----|◁
> > > > >        | | `------------------------|D5    Q5|-----|◁
> > > > >        | `--------------------------|D6    Q6|-----|◁
> > > > >        `----------------------------|D7    Q7|-----|◁
> > > > >                                     `--------'
> > > > >
> > > > >
> > > > > So to change output 2 of latch #1 you have to apply the changed level on
> > > > > IN2, apply the previous level on the other inputs (to keep the other
> > > > > outputs constant) and toggle CLK1 once.
> > > > >
> > > > > This way you can drive 16 LEDs (or in general outputs) using only 10
> > > > > GPIOs. (And with a higher number of latches the proportion becomes a bit
> > > > > more useful.)
> > > > >
> > > > > Actually this construct is a general GPO (no input :-) controller, and I
> > > > > wonder if you would accept a driver that models it as a gpio controller.
> > > > >
> > > > > The dt binding could look as follows:
> > > > >
> > > > > latch-gpo {
> > > > >         compatible = "latch-gpo";
> > > > >         pinctrl-0 = <...>;
> > > > >         pinctrl-names = <...>;
> > > > >
> > > > >         clk-gpios = /* CLK0 */ <...>, /* CLK1 */ <...>;
> > > > >         data-gpios = /* IN0 */ <...>, /* IN1 */ <...>, ...;
> > > > > };
> > > > >
> > > > > What do you think?
> > > >
> > > > Bart, what happened to the [1]? Is it abandoned, forgotten?
> > > >
> > > > Uwe, isn't it what you need?
> > >
> > > It needs "downstream" GPIO and ->get_direction(), etc should act accordingly.
> >
> > No, IIUC this is different. With a multiplexer there can always only be
> > a single line that is controlled (or read) and the other lines are (I
> > assume) high-z.
> 
> I don't know the Linux mux framework implementation, but from a
> hardware perspective the mux is what you have. In the GPIO (mux)
> driver you need to be able to switch banks as you wish, the rest is
> the drivers' business. If gpio-cascade gives no possibility to do that
> due to broken mux in Linux, then indeed, it can't be accepted at all
> and I have to withdraw my tags from that.

I think you didn't understand what I said (or I didn't understand the
problem you describe).

The thing that is supported by gpio-mux-input is:

	CTRL  ---.  .
	          \/|
	          / |
	          | |---<-- INPUTA
	GPIO --<--| |
	          | |---<-- INPUTB
	          \ |
	           \|
	            '

This is about inputs. CTRL selects which of the inputs on the right is
forwarded to GPIO and the other lines are tristated. Theoretically you
can also drive one of the lines on the right side, but only one and only
while no other line is read.

The hardware construct I have is about outputs and there is no problem
with highz lines, all lines are always driven.

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

end of thread, other threads:[~2022-07-25 19:07 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-18 20:22 Is a multiplexer using latches a gpio controller? Uwe Kleine-König
2022-07-18 22:05 ` Andy Shevchenko
2022-07-18 22:11   ` Andy Shevchenko
2022-07-19  7:19     ` Uwe Kleine-König
2022-07-25  9:19       ` Andy Shevchenko
2022-07-25 19:07         ` Uwe Kleine-König
2022-07-18 22:54 ` Linus Walleij
2022-07-18 23:11   ` Andy Shevchenko
2022-07-19  7:49   ` Uwe Kleine-König
2022-07-19  9:13     ` Andy Shevchenko
2022-07-20  5:25       ` Uwe Kleine-König

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.