From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: Mauri Sandberg <maukka@ext.kapsi.fi>
Cc: Mauri Sandberg <sandberg@mailfence.com>,
Bartosz Golaszewski <bgolaszewski@baylibre.com>,
Geert Uytterhoeven <geert+renesas@glider.be>,
Linus Walleij <linus.walleij@linaro.org>,
"open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
Rob Herring <robh+dt@kernel.org>,
devicetree <devicetree@vger.kernel.org>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
Drew Fustini <drew@beagleboard.org>
Subject: Re: [PATCH v5 2/2] gpio: gpio-cascade: add generic GPIO cascade
Date: Mon, 21 Jun 2021 20:43:21 +0300 [thread overview]
Message-ID: <CAHp75VcjGpveAHNAW7Xf7d_Zf6LGSSyD6+qBiF9xxvb+EKs3tg@mail.gmail.com> (raw)
In-Reply-To: <20210621172053.107045-3-maukka@ext.kapsi.fi>
On Mon, Jun 21, 2021 at 8:25 PM Mauri Sandberg <maukka@ext.kapsi.fi> wrote:
>
> Adds support for a building cascades of GPIO lines. That is, it allows
for building
> setups when there is one upstream line and multiple cascaded lines, out
> of which one can be chosen at a time. The status of the upstream line
> can be conveyd to the selected cascaded line or, vice versa, the status
conveyed
> of the cascaded line can be conveyed to the upstream line.
>
> A gpio-mux is being used to select, which cascaded GPIO line is being
> used at any given time.
>
> At the moment only input direction is supported. In future it should be
> possible to add support for output direction, too.
Since in parallel there is a discussion about the virtio-gpio
interface, how will this work with it?
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * A generic GPIO cascade driver
> + *
> + * Copyright (C) 2021 Mauri Sandberg <maukka@ext.kapsi.fi>
> + *
> + * This allows building cascades of GPIO lines in a manner illustrated
> + * below:
> + *
> + * /|---- Cascaded GPIO line 0
> + * Upstream | |---- Cascaded GPIO line 1
> + * GPIO line ----+ | .
> + * | | .
> + * \|---- Cascaded GPIO line n
> + *
> + * A gpio-mux is being used to select, which cascaded line is being
> + * addressed at any given time.
> + *
> + * At the moment only input mode is supported due to lack of means for
> + * testing output functionality. At least theoretically output should be
> + * possible with an open drain constructions.
> + */
...
> +static int gpio_cascade_get_value(struct gpio_chip *gc, unsigned int offset)
> +{
> + struct gpio_cascade *cas;
> + int ret;
> + cas = chip_to_cascade(gc);
Doing this in the definition block above will save a LOC.
> + ret = mux_control_select(cas->mux_control, offset);
> + if (ret)
> + return ret;
> +
> + ret = gpiod_get_value(cas->upstream_line);
> + mux_control_deselect(cas->mux_control);
> + return ret;
> +}
...
> + struct device_node *np = pdev->dev.of_node;
Nope, see below.
...
> + cas = devm_kzalloc(dev, sizeof(struct gpio_cascade), GFP_KERNEL);
sizeof(*cas)
> + if (cas == NULL)
if (!cas)
> + return -ENOMEM;
...
> + mc = devm_mux_control_get(dev, NULL);
> + if (IS_ERR(mc)) {
> + err = (int) PTR_ERR(mc);
> + if (err != -EPROBE_DEFER)
> + dev_err(dev, "unable to get mux-control: %d\n", err);
> + return err;
Oh là là! No, the explicit castings are bad. besides the fact that all
above can be replaced by
return dev_err_probe(...);
> + }
> +
> + cas->mux_control = mc;
> + upstream = devm_gpiod_get(dev, "upstream", GPIOD_IN);
> + if (IS_ERR(upstream)) {
> + err = (int) PTR_ERR(upstream);
> + dev_err(dev, "unable to claim upstream GPIO line: %d\n", err);
No castings. Use proper printf() specifiers.
> + return err;
> + }
...
> + gc->of_node = np;
This should be guarded by CONFIG_OF_GPIO.
And no need to use the np temporary variable for one use like this.
...
> + err = gpiochip_add(&cas->gpio_chip);
Why not the devm variant?
> + if (err) {
> + dev_err(dev, "unable to add gpio chip, err=%d\n", err);
> + return err;
> + }
...
> + dev_info(dev, "registered %u cascaded GPIO lines\n", gc->ngpio);
No, we don't pollute logs when everything is fine.
...
> +static const struct of_device_id gpio_cascade_id[] = {
> + {
> + .compatible = "gpio-cascade",
> + .data = NULL,
Redundant.
> + },
All above may consume only a single LOC.
> + { /* sentinel */ }
> +};
> +MODULE_DEVICE_TABLE(of, gpio_cascade_id);
--
With Best Regards,
Andy Shevchenko
next prev parent reply other threads:[~2021-06-21 17:44 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20210325122832.119147-1-sandberg@mailfence.com>
2021-05-30 16:13 ` [PATCH v4 0/2] gpio: add generic gpio input multiplexer Mauri Sandberg
2021-05-30 16:13 ` [PATCH v4 1/2] dt-bindings: gpio-mux-input: add documentation Mauri Sandberg
2021-06-01 10:10 ` Linus Walleij
2021-06-01 10:44 ` Linus Walleij
2021-06-02 9:31 ` Mauri Sandberg
2021-06-02 10:35 ` Linus Walleij
2021-06-02 11:21 ` Mauri Sandberg
2021-06-04 7:51 ` Linus Walleij
2021-06-01 13:32 ` Rob Herring
2021-06-02 11:36 ` Mauri Sandberg
2021-05-30 16:13 ` [PATCH v4 2/2] gpio: gpio-mux-input: add generic gpio input multiplexer Mauri Sandberg
2021-05-30 18:09 ` Andy Shevchenko
2021-05-30 19:02 ` Mauri Sandberg
2021-05-30 19:38 ` Andy Shevchenko
2021-05-31 10:19 ` Mauri Sandberg
2021-06-01 10:38 ` Linus Walleij
2021-06-21 17:20 ` [PATCH v5 0/2] gpio: add generic gpio cascade Mauri Sandberg
2021-06-21 17:20 ` [PATCH v5 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-06-24 18:30 ` Rob Herring
2021-06-21 17:20 ` [PATCH v5 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-06-21 17:43 ` Andy Shevchenko [this message]
2021-06-21 18:31 ` Enrico Weigelt, metux IT consult
2021-10-15 12:56 ` Mauri Sandberg
2021-10-15 17:20 ` Andy Shevchenko
2021-10-19 12:57 ` [PATCH v6 0/2] " Mauri Sandberg
2021-10-19 12:57 ` [PATCH v6 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-19 12:57 ` [PATCH v6 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-10-19 13:12 ` Andy Shevchenko
2021-10-19 20:08 ` [PATCH v7 0/2] " Mauri Sandberg
2021-10-19 20:08 ` [PATCH v7 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-24 22:18 ` Linus Walleij
2021-10-19 20:08 ` [PATCH v7 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2021-10-24 22:17 ` Linus Walleij
2021-10-25 9:29 ` Andy Shevchenko
2021-10-26 19:15 ` [PATCH v8 0/2] " Mauri Sandberg
2021-10-26 19:15 ` [PATCH v8 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2021-10-26 19:15 ` [PATCH v8 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 0/2] " Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 1/2] dt-bindings: gpio-cascade: add documentation Mauri Sandberg
2022-02-05 21:59 ` [RESEND v8 2/2] gpio: gpio-cascade: add generic GPIO cascade Mauri Sandberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAHp75VcjGpveAHNAW7Xf7d_Zf6LGSSyD6+qBiF9xxvb+EKs3tg@mail.gmail.com \
--to=andy.shevchenko@gmail.com \
--cc=bgolaszewski@baylibre.com \
--cc=devicetree@vger.kernel.org \
--cc=drew@beagleboard.org \
--cc=geert+renesas@glider.be \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maukka@ext.kapsi.fi \
--cc=robh+dt@kernel.org \
--cc=sandberg@mailfence.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).