Linux-GPIO Archive mirror
 help / color / mirror / Atom feed
From: Yuklin Soo <yuklin.soo@starfivetech.com>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	Hal Feng <hal.feng@starfivetech.com>,
	Leyfoon Tan <leyfoon.tan@starfivetech.com>,
	Jianlong Huang <jianlong.huang@starfivetech.com>,
	Emil Renner Berthing <kernel@esmil.dk>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Drew Fustini <drew@beagleboard.org>,
	"linux-gpio@vger.kernel.org" <linux-gpio@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-riscv@lists.infradead.org"
	<linux-riscv@lists.infradead.org>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Subject: RE: [RFC PATCH v2 2/6] pinctrl: starfive: jh8100: add main and sys_east driver
Date: Fri, 3 May 2024 11:12:11 +0000	[thread overview]
Message-ID: <ZQ0PR01MB1176F05E7988923C30A77095F61FA@ZQ0PR01MB1176.CHNPR01.prod.partner.outlook.cn> (raw)
In-Reply-To: <CACRpkdZd9WuLmvBEjEOF5R+R8Yrva_KiEPRCOXU98yLDkS=+ZQ@mail.gmail.com>



> -----Original Message-----
> From: Linus Walleij <linus.walleij@linaro.org>
> Sent: Thursday, February 29, 2024 9:03 PM
> To: Yuklin Soo <yuklin.soo@starfivetech.com>
> Cc: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>; Hal Feng
> <hal.feng@starfivetech.com>; Leyfoon Tan <leyfoon.tan@starfivetech.com>;
> Jianlong Huang <jianlong.huang@starfivetech.com>; Emil Renner Berthing
> <kernel@esmil.dk>; Rob Herring <robh@kernel.org>; Krzysztof Kozlowski
> <krzysztof.kozlowski+dt@linaro.org>; Conor Dooley <conor+dt@kernel.org>;
> Drew Fustini <drew@beagleboard.org>; linux-gpio@vger.kernel.org; linux-
> kernel@vger.kernel.org; devicetree@vger.kernel.org; linux-
> riscv@lists.infradead.org; Paul Walmsley <paul.walmsley@sifive.com>; Palmer
> Dabbelt <palmer@dabbelt.com>; Albert Ou <aou@eecs.berkeley.edu>
> Subject: Re: [RFC PATCH v2 2/6] pinctrl: starfive: jh8100: add main and sys_east
> driver
> 
> Thanks Alex,
> 
> this new version is much improved!
> 
> On Tue, Feb 20, 2024 at 7:43 AM Alex Soo <yuklin.soo@starfivetech.com> wrote:
> 
> > Add JH8100 pinctrl main and sys_east domain driver.
> >
> > Signed-off-by: Alex Soo <yuklin.soo@starfivetech.com>
> 
> This commit message should at least explain what we are adding here, that it's
> a core driver that will be used by all the domains, what the SoC is etc etc.

Will update the commit message of the main driver and sys_east domain subdriver to
to inform what SoC they are running on, and to explain that the main driver provides
common APIs to all the domain subdrivers to perform their respective tasks, and how
the main driver and domain drivers work together.

> 
> > +       select GPIOLIB_IRQCHIP
> (...)
> > +#include "../core.h"
> > +#include "../pinmux.h"
> > +#include "../pinconf.h"
> 
> Do you really need to poke around in the internals like this?
> 
> Please explain for each cross-include *why* you need to do this.

For subdrivers: “aon”, “sys-east”, “sys-west”, and ”sys-gmac” :

The cross-include “../pinmux.h” and “../pinconf.h” are redundant.

The cross-include “../core.h” provides reference to functions:
int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
int pinctrl_force_default(struct pinctrl_dev *pctldev);

Remove all cross-include “../core.h”, "../pinmux.h" and "../pinconf.h" from the subdrivers,
and move "#include "../core.h" to driver header file “pinctrl-starfive-jh8100.h”.

> 
> > +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh8100.c
> (...)
> > +#include <linux/of_gpio.h>
> 
> Never use this include. It is legacy and you should not be using it. Use
> <linux/gpio/consumer.h> solely. See comments below.

The header <linux/of_gpio.h> is removed and use only the gpiod interfaces in <linux/gpio/consumer.h>.

> 
> > +#include <linux/pinctrl/consumer.h>
> 
> Why?
> 
> > +#include "../core.h"
> > +#include "../pinctrl-utils.h"
> > +#include "../pinmux.h"
> > +#include "../pinconf.h"
> 
> Again all this. Explain for each one exactly why you need this.

Cross-includes:

 “../core.h” --

provides definitions for “struct pinctrl_dev” and “struct group_desc”.

also, provides reference to functions:

pinctrl_generic_get_group_count
pinctrl_generic_get_group_name
pinctrl_generic_get_group_pins
pinctrl_generic_get_group
pinctrl_generic_add_group

Suggest to move “../core.h” to the driver header file “pinctrl-starfive-jh8100.h”

“../pinctrl-utils.h” -- 

provides reference to function:

pinctrl_utils_free_map

Suggest removing “../pinctrl-utils.h” and add the “pinctrl_utils_free_map” 
function prototype to the driver header file “pinctrl-starfive-jh8100.h”.

“../pinmux.h” – 

provides reference to functions:

pinmux_generic_get_function_count
pinmux_generic_get_function_name
pinmux_generic_get_function_groups
pinmux_generic_add_function

Suggest removing “../pinmux.h” and add the above “pinmux_generic_*” 
function prototypes to the driver header file “pinctrl-starfive-jh8100.h”.

“../pinconf.h” – 

provides reference to function: 

pinconf_generic_parse_dt_config

Suggest removing “../pinconf.h” and add the above “pinconf_generic_parse_dt_config”
function prototype to driver header file “pinctrl-starfive-jh8100.h”.

> 
> > +static int jh8100_gpio_irq_setup(struct device *dev, struct
> > +jh8100_pinctrl *sfp) {
> > +       struct device_node *np = dev->of_node;
> > +       struct gpio_irq_chip *girq = &sfp->gc.irq;
> > +       struct gpio_desc *gpiod;
> > +       struct irq_desc *desc;
> > +       irq_hw_number_t hwirq;
> > +       int i, ret;
> > +       int dir;
> > +
> > +       if (!girq->domain) {
> > +               sfp->irq_domain = irq_domain_add_linear(np, sfp->gc.ngpio,
> > +                                                       &irq_domain_simple_ops,
> > +                                                       sfp);
> 
> When would this happen? I don't quite get it.
> 
> It looks like a probe order issue or something.

This condition is unlikely to happen. Will remove this if statement.

> 
> > +       } else {
> > +               sfp->irq_domain = girq->domain;
> > +       }
> > +
> > +       if (!sfp->irq_domain) {
> > +               dev_err(dev, "Couldn't allocate IRQ domain\n");
> > +               return -ENXIO;
> > +       }
> > +
> > +       for (i = 0; i < sfp->gc.ngpio; i++) {
> > +               int virq = irq_create_mapping(sfp->irq_domain, i);
> > +
> > +               irq_set_chip_and_handler(virq, &jh8100_irq_chip,
> > +                                        handle_edge_irq);
> > +               irq_set_chip_data(virq, &sfp->gc);
> > +       }
> 
> This duplicates core gpiolib irqchip handling, which you select using select
> GPIOLIB_IRQCHIP.
> 
> Can you please look into just using the gpiolib irqchip handling?

Yes, will use the gpiolib irqchip handling. Please see the implementation in
function gpiochip_wakeup_irq_setup() in drivers/gpio/gpiolib.c.

> 
> > +       sfp->wakeup_gpio = of_get_named_gpio(np, "wakeup-gpios", 0);
> 
> No using <linux/of_gpio.h> please.
> 
> Use just <linux/gpio/consumer.h> and something like:
> 
> struct gpio_desc *wakeup;
> wakeup = devm_gpiod_get_optional(dev, "wakeup", GPIOD_IN);

Will use only descriptor-based interface to handle the wakeup_gpio since the
integer-based interface is obsolete. Please see the implementation in
function gpiochip_wakeup_irq_setup() in drivers/gpio/gpiolib.c.

> 
> > +       if (gpio_is_valid(sfp->wakeup_gpio)) {
> > +               hwirq = pin_to_hwirq(sfp);
> > +               sfp->wakeup_irq = irq_find_mapping(sfp->irq_domain, hwirq);
> > +               desc = irq_to_desc(sfp->wakeup_irq);
> 
> if (wakeup) {
>      irq = gpiod_to_irq(wakeup);
>      .. convert to irq descriptor etc...
> 
> Actually: is this wakeup handling something we would like to add to the gpiolib
> irqchip so everyone can reuse it?
> In gpiochip_add_irqchip()?
> At least give it a thought.

I have removed the function jh8100_gpio_irq_setup() and the GPIO wakeup irq 
enablement in probe function from the main driver.
The function gpiochip_wakeup_irq_setup() is created in gpiolib core
"drivers/gpio/gpiolib.c" as a replacement of the codes removed from the main
driver. This function is a wakeup handling that automatically set up the gpio wakeup
irq if user had the “wakeup-source” and “wakeup-gpios” properties defined in their
device tree.
Initially, I tried to call gpiochip_wakeup_irq_setup() from function gpiochip_add_irqchip(),
but gpiod_to_irq() returns -517 (EPROBE_DEFER) when convert hwirq to virq. 
Eventually, this function is called at the end of function gpiochip_add_data_with_key().
The testing showed that when the GPIO logic level is toggled, the interrupt triggered
can wake up the system from sleep.

> 
> Yours,
> Linus Walleij

  reply	other threads:[~2024-05-03 11:26 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-20  6:42 [RFC PATCH v2 0/6] Add Pinctrl driver for Starfive JH8100 SoC Alex Soo
2024-02-20  6:42 ` [RFC PATCH v2 1/6] dt-bindings: pinctrl: starfive: Add JH8100 pinctrl Alex Soo
2024-02-20  8:11   ` Krzysztof Kozlowski
2024-02-20 19:10     ` Conor Dooley
2024-02-21  7:24       ` Krzysztof Kozlowski
2024-02-21 19:39         ` Conor Dooley
2024-02-23  0:24         ` Rob Herring
2024-02-24  8:46           ` Krzysztof Kozlowski
2024-02-24 19:20             ` Conor Dooley
2024-02-28 17:03               ` Rob Herring
2024-02-28 19:34                 ` Conor Dooley
2024-02-20  6:42 ` [RFC PATCH v2 2/6] pinctrl: starfive: jh8100: add main and sys_east driver Alex Soo
2024-02-29 13:03   ` Linus Walleij
2024-05-03 11:12     ` Yuklin Soo [this message]
2024-02-20  6:42 ` [RFC PATCH v2 3/6] pinctrl: starfive: jh8100: add pinctrl driver for sys_west domain Alex Soo
2024-02-20  6:42 ` [RFC PATCH v2 4/6] pinctrl: starfive: jh8100: add pinctrl driver for sys_gmac domain Alex Soo
2024-02-20  6:42 ` [RFC PATCH v2 5/6] pinctrl: starfive: jh8100: add pinctrl driver for AON domain Alex Soo
2024-02-20  6:42 ` [RFC PATCH v2 6/6] riscv: dts: starfive: jh8100: add pinctrl device tree nodes Alex Soo

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=ZQ0PR01MB1176F05E7988923C30A77095F61FA@ZQ0PR01MB1176.CHNPR01.prod.partner.outlook.cn \
    --to=yuklin.soo@starfivetech.com \
    --cc=aou@eecs.berkeley.edu \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=drew@beagleboard.org \
    --cc=hal.feng@starfivetech.com \
    --cc=jianlong.huang@starfivetech.com \
    --cc=kernel@esmil.dk \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=leyfoon.tan@starfivetech.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=robh@kernel.org \
    /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 read-only IMAP folder(s) and NNTP newsgroup(s).