2021-10-19 20:12:31

by Mauri Sandberg

[permalink] [raw]
Subject: [PATCH v7 0/2] gpio: gpio-cascade: add generic GPIO cascade

Thanks for you prompt feedback Andy. Here are the highlights on this round:
- no changes in the bindings file.
- added better help text in Kconfig
- refactored the return code handling for claiming upstream gpio line
- refactored the return and exit at the end of the function

Thanks,
Mauri

rangediff v6 -> v7:
1: 1283751fadd4 = 1: 434637e7188e dt-bindings: gpio-cascade: add documentation
2: 46541776733a ! 2: a72e186f8e3b gpio: gpio-cascade: add generic GPIO cascade
@@ Commit message

Signed-off-by: Mauri Sandberg <[email protected]>
---
+ v6 -> v7:
+ - In Kconfig add info about module name
+ - adhere to new convention that allows lines longer than 80 chars
+ - use dev_probe_err with upstream gpio line too
+ - refactor for cleaner exit of probe function.
v5 -> v6:
- In Kconfig, remove dependency to OF_GPIO and select only MULTIPLEXER
- refactor code preferring one-liners
@@ drivers/gpio/Kconfig: config GPIO_VIRTIO
+ This allows building one-to-many cascades of GPIO lines using
+ different types of multiplexers readily available. At the
+ moment only input lines are supported.
++
++ To build the driver as a module choose 'm' and the resulting module
++ will be called 'gpio-cascade'.
+
endif

@@ drivers/gpio/gpio-cascade.c (new)
+ */
+
+#include <linux/module.h>
-+#include <linux/gpio/consumer.h>
-+#include <linux/gpio/driver.h>
+#include <linux/slab.h>
+#include <linux/platform_device.h>
+#include <linux/mux/consumer.h>
+
++#include <linux/gpio/consumer.h>
++#include <linux/gpio/driver.h>
++
+struct gpio_cascade {
+ struct device *parent;
+ struct gpio_chip gpio_chip;
@@ drivers/gpio/gpio-cascade.c (new)
+ struct mux_control *mc;
+ struct gpio_desc *upstream;
+ struct gpio_chip *gc;
-+ int err;
+
+ cas = devm_kzalloc(dev, sizeof(*cas), GFP_KERNEL);
+ if (!cas)
@@ drivers/gpio/gpio-cascade.c (new)
+
+ mc = devm_mux_control_get(dev, NULL);
+ if (IS_ERR(mc))
-+ return dev_err_probe(dev,
-+ PTR_ERR(mc),
-+ "unable to get mux-control\n");
++ return dev_err_probe(dev, PTR_ERR(mc), "unable to get mux-control\n");
+
+ cas->mux_control = mc;
+ upstream = devm_gpiod_get(dev, "upstream", GPIOD_IN);
-+ if (IS_ERR(upstream)) {
-+ dev_err(dev, "unable to claim upstream GPIO line\n");
-+ return -ENODEV;
-+ }
++ if (IS_ERR(upstream))
++ return dev_err_probe(dev, PTR_ERR(upstream), "unable to claim upstream GPIO line\n");
+
+ cas->upstream_line = upstream;
+ cas->parent = dev;
@@ drivers/gpio/gpio-cascade.c (new)
+ gc = &cas->gpio_chip;
+ gc->get = gpio_cascade_get_value;
+ gc->get_direction = gpio_cascade_get_direction;
-+
+ gc->base = -1;
+ gc->ngpio = mux_control_states(mc);
+ gc->label = dev_name(cas->parent);
+ gc->parent = cas->parent;
+ gc->owner = THIS_MODULE;
+
-+ err = devm_gpiochip_add_data(dev, &cas->gpio_chip, NULL);
-+ if (err) {
-+ dev_err(dev, "unable to add gpio chip\n");
-+ return err;
-+ }
-+
+ platform_set_drvdata(pdev, cas);
-+ return 0;
++ return devm_gpiochip_add_data(dev, &cas->gpio_chip, NULL);
+}
+
+static const struct of_device_id gpio_cascade_id[] = {

Mauri Sandberg (2):
dt-bindings: gpio-cascade: add documentation
gpio: gpio-cascade: add generic GPIO cascade

.../bindings/gpio/gpio-cascade.yaml | 103 +++++++++++++++
drivers/gpio/Kconfig | 15 +++
drivers/gpio/Makefile | 1 +
drivers/gpio/gpio-cascade.c | 118 ++++++++++++++++++
4 files changed, 237 insertions(+)
create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cascade.yaml
create mode 100644 drivers/gpio/gpio-cascade.c


base-commit: f4a20dfac88c06c9b529a41ff4cf9acba8f3fdff
--
2.25.1


2021-10-19 20:12:34

by Mauri Sandberg

[permalink] [raw]
Subject: [PATCH v7 1/2] dt-bindings: gpio-cascade: add documentation

Add documentation for a general GPIO cascade. It allows building
one-to-many cascades of GPIO lines using multiplexer to choose
the cascaded line.

Signed-off-by: Mauri Sandberg <[email protected]>
Reviewed-by: Rob Herring <[email protected]>
---
v5 -> v6:
- added Reviewed-by tag by Rob
v4 -> v5:
- renamed gpio-mux-input -> gpio-cascade
- changed vague term 'pin' to 'upstream line'
- added more verbose description for the module
- added missing 'mux-controls' entry
- dropped Tested-by and Reviewed-by due to changes in bindings
v3 -> v4:
- Changed author email
- Included Tested-by and Reviewed-by from Drew
v2 -> v3: added a complete example on dual 4-way multiplexer
v1 -> v2: added a little bit more text in the binding documenation
---
.../bindings/gpio/gpio-cascade.yaml | 103 ++++++++++++++++++
1 file changed, 103 insertions(+)
create mode 100644 Documentation/devicetree/bindings/gpio/gpio-cascade.yaml

diff --git a/Documentation/devicetree/bindings/gpio/gpio-cascade.yaml b/Documentation/devicetree/bindings/gpio/gpio-cascade.yaml
new file mode 100644
index 000000000000..46248f8e2ba5
--- /dev/null
+++ b/Documentation/devicetree/bindings/gpio/gpio-cascade.yaml
@@ -0,0 +1,103 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/gpio/gpio-cascade.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Generic GPIO cascade
+
+maintainers:
+ - Mauri Sandberg <[email protected]>
+
+description: |
+ A generic GPIO cascade
+
+ This hardware construction cascades (multiplexes) several GPIO lines from
+ one-to-many using a software controlled multiplexer. The most common use
+ case is probably reading several inputs by switching the multiplexer over
+ several input lines, which in practice works well since input lines has
+ high impedance.
+
+ Constructions with multiplexed outputs are also possible using open drain
+ electronics.
+
+ The number of cascaded GPIO lines is limited by the technology used to
+ switch over the cascaded lines. There are readily available dual/triple
+ 4-to-1 multiplexers, for example, and others.
+
+ Illustration (pins used to drive the multiplexer are omitted for clarity)
+
+ /|---- Cascaded GPIO line 0
+ Upstream | |---- Cascaded GPIO line 1
+ GPIO line ----+ | .
+ | | .
+ \|---- Cascaded GPIO line n
+
+properties:
+ compatible:
+ enum:
+ - gpio-cascade
+
+ gpio-controller: true
+
+ '#gpio-cells':
+ const: 2
+
+ mux-controls:
+ minItems: 1
+ maxItems: 1
+ description: |
+ The mux controller that will be driving the GPIO cascade.
+
+ upstream-gpios:
+ description: |
+ The GPIO line used as the upstream line will convey the status to/from
+ cascaded GPIO lines. In an input mode, by using this line, it is
+ possible to read the status from selected cascaded GPIO line.
+
+ In an output mode the status of the upstream GPIO will be conveyed to
+ the selected cascaded GPIO line.
+
+required:
+ - compatible
+ - gpio-controller
+ - "#gpio-cells"
+ - mux-controls
+ - upstream-gpios
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ mux: mux-controller {
+ compatible = "gpio-mux";
+ #mux-control-cells = <0>;
+
+ mux-gpios = <&gpio 9 GPIO_ACTIVE_HIGH>,
+ <&gpio 11 GPIO_ACTIVE_HIGH>;
+ };
+
+ gpio2: key-mux1 {
+ compatible = "gpio-cascade";
+ mux-controls = <&mux>;
+
+ gpio-controller;
+ #gpio-cells = <2>;
+
+ // GPIOs used by this node, upstream pin
+ upstream-gpios = <&gpio 12 GPIO_ACTIVE_HIGH>;
+ };
+
+ gpio3: key-mux2 {
+ compatible = "gpio-cascade";
+ mux-controls = <&mux>;
+
+ gpio-controller;
+ #gpio-cells = <2>;
+
+ // GPIOs used by this node, upstream pin
+ upstream-gpios = <&gpio 14 GPIO_ACTIVE_HIGH>;
+ };
+
+...
--
2.25.1

2021-10-24 22:24:24

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v7 1/2] dt-bindings: gpio-cascade: add documentation

On Tue, Oct 19, 2021 at 10:10 PM Mauri Sandberg <[email protected]> wrote:

> Add documentation for a general GPIO cascade. It allows building
> one-to-many cascades of GPIO lines using multiplexer to choose
> the cascaded line.
>
> Signed-off-by: Mauri Sandberg <[email protected]>
> Reviewed-by: Rob Herring <[email protected]>

Reviewed-by: Linus Walleij <[email protected]>

Yours,
Linus Walleij