All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Riesch <michael.riesch@wolfvision.net>
To: Quentin Schulz <foss+kernel@0leil.net>
Cc: linus.walleij@linaro.org, heiko@sntech.de,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>
Subject: Re: [RFC PATCH 1/1] pinctrl: rockchip: add support for per-pinmux io-domain dependency
Date: Thu, 11 Aug 2022 09:52:41 +0200	[thread overview]
Message-ID: <9b965d86-9b76-77a1-658e-3675c2138414@wolfvision.net> (raw)
In-Reply-To: <20220802095252.2486591-2-foss+kernel@0leil.net>

Hi Quentin,

Thank you for your efforts! This will solve several issues that are
bound to pop up if a board deviates from the Rockchip reference design.
It seems this does not happen very often, though, which would explain
the lack of responses to your initial query... :-/

A few comments inline:

On 8/2/22 11:52, Quentin Schulz wrote:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> On some Rockchip SoCs, some SoC pins are split in what are called IO
> domains.
> 
> An IO domain is supplied power externally, by regulators from a PMIC for
> example. This external power supply is then used by the IO domain as
> "supply" for the IO pins if they are outputs.
> 
> Each IO domain can configure which voltage the IO pins will be operating
> on (1.8V or 3.3V).

Just for the sake of completeness: 2.5V is possibly as well (at least on
RK356x), right?

> There already exists an IO domain driver for Rockchip SoCs[1]. This
> driver allows to explicit the relationship between the external power

...allows to model explicitly...?

> supplies and IO domains[2]. This makes sure the regulators are enabled
> by the Linux kernel so the IO domains are supplied with power and
> correctly configured as per the supplied voltage.
> This driver is a regulator consumer and does not offer any other
> interface for device dependency.
> 
> However, IO pins belonging to an IO domain need to have this IO domain
> correctly configured before they are being used otherwise they do not
> operate correctly (in our case, a pin configured as output clock was
> oscillating between 0 and 150mV instead of the expected 1V8).
> 
> In order to make this dependency transparent to the consumer of those
> pins and not add Rockchip-specific code to third party drivers (a camera
> driver in our case), it is hooked into the pinctrl driver which is
> Rockchip-specific obviously.

This approach seems reasonable. But just for my understanding: Does this
mean we need to edit e.g. rk3568-pinctrl.dtsi, iterate over all entries,
and add rockchip,iodomains = <&corresponding_io_domain>;?

If not, at which place are the rockchip,iodomains properties inserted?

> [1] drivers/soc/rockchip/io-domain.c
> [2] Documentation/devicetree/bindings/power/rockchip-io-domain.yaml
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 19 +++++++++++++++++++
>  drivers/pinctrl/pinctrl-rockchip.h |  1 +
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
> index 32e41395fc76..c3c2801237b5 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.c
> +++ b/drivers/pinctrl/pinctrl-rockchip.c
> @@ -24,6 +24,8 @@
>  #include <linux/of_address.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
>  #include <linux/pinctrl/machine.h>
>  #include <linux/pinctrl/pinconf.h>
>  #include <linux/pinctrl/pinctrl.h>
> @@ -2370,6 +2372,12 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
>  	dev_dbg(dev, "enable function %s group %s\n",
>  		info->functions[selector].name, info->groups[group].name);
>  
> +	if (info->groups[group].io_domain &&
> +	    !platform_get_drvdata(info->groups[group].io_domain)) {
> +		dev_err(info->dev, "IO domain device is required but not probed yet, deferring...");

Probably this has been left in there for debugging, but should be
removed to avoid spamming dmesg. IIUC this condition could occur several
times.

> +		return -EPROBE_DEFER;
> +	}
> +
>  	/*
>  	 * for each pin in the pin group selected, program the corresponding
>  	 * pin function number in the config register.
> @@ -2663,6 +2671,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  {
>  	struct device *dev = info->dev;
>  	struct rockchip_pin_bank *bank;
> +	struct device_node *node;
>  	int size;
>  	const __be32 *list;
>  	int num;
> @@ -2684,6 +2693,16 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  	if (!size || size % 4)
>  		return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n");
>  
> +	node = of_parse_phandle(np, "rockchip,io-domains", 0);
> +	if (node) {
> +		grp->io_domain = of_find_device_by_node(node);
> +		of_node_put(node);
> +		if (!grp->io_domain) {
> +			dev_err(info->dev, "couldn't find IO domain device\n");
> +			return -ENODEV;

Again just for my understanding: The property is optional in order to
provide compatibility with older device trees, right?

> +		}
> +	}
> +
>  	grp->npins = size / 4;
>  
>  	grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL);
> diff --git a/drivers/pinctrl/pinctrl-rockchip.h b/drivers/pinctrl/pinctrl-rockchip.h
> index ec46f8815ac9..56bc008eb7df 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.h
> +++ b/drivers/pinctrl/pinctrl-rockchip.h
> @@ -434,6 +434,7 @@ struct rockchip_pin_group {
>  	unsigned int			npins;
>  	unsigned int			*pins;
>  	struct rockchip_pin_config	*data;
> +	struct platform_device		*io_domain;
>  };
>  
>  /**

Looking forward to the v1 of this series, which I'd be happy to test.

Best regards,
Michael

WARNING: multiple messages have this Message-ID (diff)
From: Michael Riesch <michael.riesch@wolfvision.net>
To: Quentin Schulz <foss+kernel@0leil.net>
Cc: linus.walleij@linaro.org, heiko@sntech.de,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>
Subject: Re: [RFC PATCH 1/1] pinctrl: rockchip: add support for per-pinmux io-domain dependency
Date: Thu, 11 Aug 2022 09:52:41 +0200	[thread overview]
Message-ID: <9b965d86-9b76-77a1-658e-3675c2138414@wolfvision.net> (raw)
In-Reply-To: <20220802095252.2486591-2-foss+kernel@0leil.net>

Hi Quentin,

Thank you for your efforts! This will solve several issues that are
bound to pop up if a board deviates from the Rockchip reference design.
It seems this does not happen very often, though, which would explain
the lack of responses to your initial query... :-/

A few comments inline:

On 8/2/22 11:52, Quentin Schulz wrote:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> On some Rockchip SoCs, some SoC pins are split in what are called IO
> domains.
> 
> An IO domain is supplied power externally, by regulators from a PMIC for
> example. This external power supply is then used by the IO domain as
> "supply" for the IO pins if they are outputs.
> 
> Each IO domain can configure which voltage the IO pins will be operating
> on (1.8V or 3.3V).

Just for the sake of completeness: 2.5V is possibly as well (at least on
RK356x), right?

> There already exists an IO domain driver for Rockchip SoCs[1]. This
> driver allows to explicit the relationship between the external power

...allows to model explicitly...?

> supplies and IO domains[2]. This makes sure the regulators are enabled
> by the Linux kernel so the IO domains are supplied with power and
> correctly configured as per the supplied voltage.
> This driver is a regulator consumer and does not offer any other
> interface for device dependency.
> 
> However, IO pins belonging to an IO domain need to have this IO domain
> correctly configured before they are being used otherwise they do not
> operate correctly (in our case, a pin configured as output clock was
> oscillating between 0 and 150mV instead of the expected 1V8).
> 
> In order to make this dependency transparent to the consumer of those
> pins and not add Rockchip-specific code to third party drivers (a camera
> driver in our case), it is hooked into the pinctrl driver which is
> Rockchip-specific obviously.

This approach seems reasonable. But just for my understanding: Does this
mean we need to edit e.g. rk3568-pinctrl.dtsi, iterate over all entries,
and add rockchip,iodomains = <&corresponding_io_domain>;?

If not, at which place are the rockchip,iodomains properties inserted?

> [1] drivers/soc/rockchip/io-domain.c
> [2] Documentation/devicetree/bindings/power/rockchip-io-domain.yaml
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 19 +++++++++++++++++++
>  drivers/pinctrl/pinctrl-rockchip.h |  1 +
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
> index 32e41395fc76..c3c2801237b5 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.c
> +++ b/drivers/pinctrl/pinctrl-rockchip.c
> @@ -24,6 +24,8 @@
>  #include <linux/of_address.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
>  #include <linux/pinctrl/machine.h>
>  #include <linux/pinctrl/pinconf.h>
>  #include <linux/pinctrl/pinctrl.h>
> @@ -2370,6 +2372,12 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
>  	dev_dbg(dev, "enable function %s group %s\n",
>  		info->functions[selector].name, info->groups[group].name);
>  
> +	if (info->groups[group].io_domain &&
> +	    !platform_get_drvdata(info->groups[group].io_domain)) {
> +		dev_err(info->dev, "IO domain device is required but not probed yet, deferring...");

Probably this has been left in there for debugging, but should be
removed to avoid spamming dmesg. IIUC this condition could occur several
times.

> +		return -EPROBE_DEFER;
> +	}
> +
>  	/*
>  	 * for each pin in the pin group selected, program the corresponding
>  	 * pin function number in the config register.
> @@ -2663,6 +2671,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  {
>  	struct device *dev = info->dev;
>  	struct rockchip_pin_bank *bank;
> +	struct device_node *node;
>  	int size;
>  	const __be32 *list;
>  	int num;
> @@ -2684,6 +2693,16 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  	if (!size || size % 4)
>  		return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n");
>  
> +	node = of_parse_phandle(np, "rockchip,io-domains", 0);
> +	if (node) {
> +		grp->io_domain = of_find_device_by_node(node);
> +		of_node_put(node);
> +		if (!grp->io_domain) {
> +			dev_err(info->dev, "couldn't find IO domain device\n");
> +			return -ENODEV;

Again just for my understanding: The property is optional in order to
provide compatibility with older device trees, right?

> +		}
> +	}
> +
>  	grp->npins = size / 4;
>  
>  	grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL);
> diff --git a/drivers/pinctrl/pinctrl-rockchip.h b/drivers/pinctrl/pinctrl-rockchip.h
> index ec46f8815ac9..56bc008eb7df 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.h
> +++ b/drivers/pinctrl/pinctrl-rockchip.h
> @@ -434,6 +434,7 @@ struct rockchip_pin_group {
>  	unsigned int			npins;
>  	unsigned int			*pins;
>  	struct rockchip_pin_config	*data;
> +	struct platform_device		*io_domain;
>  };
>  
>  /**

Looking forward to the v1 of this series, which I'd be happy to test.

Best regards,
Michael

_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: Michael Riesch <michael.riesch@wolfvision.net>
To: Quentin Schulz <foss+kernel@0leil.net>
Cc: linus.walleij@linaro.org, heiko@sntech.de,
	linux-gpio@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org,
	Quentin Schulz <quentin.schulz@theobroma-systems.com>
Subject: Re: [RFC PATCH 1/1] pinctrl: rockchip: add support for per-pinmux io-domain dependency
Date: Thu, 11 Aug 2022 09:52:41 +0200	[thread overview]
Message-ID: <9b965d86-9b76-77a1-658e-3675c2138414@wolfvision.net> (raw)
In-Reply-To: <20220802095252.2486591-2-foss+kernel@0leil.net>

Hi Quentin,

Thank you for your efforts! This will solve several issues that are
bound to pop up if a board deviates from the Rockchip reference design.
It seems this does not happen very often, though, which would explain
the lack of responses to your initial query... :-/

A few comments inline:

On 8/2/22 11:52, Quentin Schulz wrote:
> From: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> 
> On some Rockchip SoCs, some SoC pins are split in what are called IO
> domains.
> 
> An IO domain is supplied power externally, by regulators from a PMIC for
> example. This external power supply is then used by the IO domain as
> "supply" for the IO pins if they are outputs.
> 
> Each IO domain can configure which voltage the IO pins will be operating
> on (1.8V or 3.3V).

Just for the sake of completeness: 2.5V is possibly as well (at least on
RK356x), right?

> There already exists an IO domain driver for Rockchip SoCs[1]. This
> driver allows to explicit the relationship between the external power

...allows to model explicitly...?

> supplies and IO domains[2]. This makes sure the regulators are enabled
> by the Linux kernel so the IO domains are supplied with power and
> correctly configured as per the supplied voltage.
> This driver is a regulator consumer and does not offer any other
> interface for device dependency.
> 
> However, IO pins belonging to an IO domain need to have this IO domain
> correctly configured before they are being used otherwise they do not
> operate correctly (in our case, a pin configured as output clock was
> oscillating between 0 and 150mV instead of the expected 1V8).
> 
> In order to make this dependency transparent to the consumer of those
> pins and not add Rockchip-specific code to third party drivers (a camera
> driver in our case), it is hooked into the pinctrl driver which is
> Rockchip-specific obviously.

This approach seems reasonable. But just for my understanding: Does this
mean we need to edit e.g. rk3568-pinctrl.dtsi, iterate over all entries,
and add rockchip,iodomains = <&corresponding_io_domain>;?

If not, at which place are the rockchip,iodomains properties inserted?

> [1] drivers/soc/rockchip/io-domain.c
> [2] Documentation/devicetree/bindings/power/rockchip-io-domain.yaml
> 
> Signed-off-by: Quentin Schulz <quentin.schulz@theobroma-systems.com>
> ---
>  drivers/pinctrl/pinctrl-rockchip.c | 19 +++++++++++++++++++
>  drivers/pinctrl/pinctrl-rockchip.h |  1 +
>  2 files changed, 20 insertions(+)
> 
> diff --git a/drivers/pinctrl/pinctrl-rockchip.c b/drivers/pinctrl/pinctrl-rockchip.c
> index 32e41395fc76..c3c2801237b5 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.c
> +++ b/drivers/pinctrl/pinctrl-rockchip.c
> @@ -24,6 +24,8 @@
>  #include <linux/of_address.h>
>  #include <linux/of_device.h>
>  #include <linux/of_irq.h>
> +#include <linux/of_platform.h>
> +#include <linux/platform_device.h>
>  #include <linux/pinctrl/machine.h>
>  #include <linux/pinctrl/pinconf.h>
>  #include <linux/pinctrl/pinctrl.h>
> @@ -2370,6 +2372,12 @@ static int rockchip_pmx_set(struct pinctrl_dev *pctldev, unsigned selector,
>  	dev_dbg(dev, "enable function %s group %s\n",
>  		info->functions[selector].name, info->groups[group].name);
>  
> +	if (info->groups[group].io_domain &&
> +	    !platform_get_drvdata(info->groups[group].io_domain)) {
> +		dev_err(info->dev, "IO domain device is required but not probed yet, deferring...");

Probably this has been left in there for debugging, but should be
removed to avoid spamming dmesg. IIUC this condition could occur several
times.

> +		return -EPROBE_DEFER;
> +	}
> +
>  	/*
>  	 * for each pin in the pin group selected, program the corresponding
>  	 * pin function number in the config register.
> @@ -2663,6 +2671,7 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  {
>  	struct device *dev = info->dev;
>  	struct rockchip_pin_bank *bank;
> +	struct device_node *node;
>  	int size;
>  	const __be32 *list;
>  	int num;
> @@ -2684,6 +2693,16 @@ static int rockchip_pinctrl_parse_groups(struct device_node *np,
>  	if (!size || size % 4)
>  		return dev_err_probe(dev, -EINVAL, "wrong pins number or pins and configs should be by 4\n");
>  
> +	node = of_parse_phandle(np, "rockchip,io-domains", 0);
> +	if (node) {
> +		grp->io_domain = of_find_device_by_node(node);
> +		of_node_put(node);
> +		if (!grp->io_domain) {
> +			dev_err(info->dev, "couldn't find IO domain device\n");
> +			return -ENODEV;

Again just for my understanding: The property is optional in order to
provide compatibility with older device trees, right?

> +		}
> +	}
> +
>  	grp->npins = size / 4;
>  
>  	grp->pins = devm_kcalloc(dev, grp->npins, sizeof(*grp->pins), GFP_KERNEL);
> diff --git a/drivers/pinctrl/pinctrl-rockchip.h b/drivers/pinctrl/pinctrl-rockchip.h
> index ec46f8815ac9..56bc008eb7df 100644
> --- a/drivers/pinctrl/pinctrl-rockchip.h
> +++ b/drivers/pinctrl/pinctrl-rockchip.h
> @@ -434,6 +434,7 @@ struct rockchip_pin_group {
>  	unsigned int			npins;
>  	unsigned int			*pins;
>  	struct rockchip_pin_config	*data;
> +	struct platform_device		*io_domain;
>  };
>  
>  /**

Looking forward to the v1 of this series, which I'd be happy to test.

Best regards,
Michael

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-08-11  7:53 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-02  9:52 [RFC PATCH 0/1] Making Rockchip IO domains dependency from other devices explicit Quentin Schulz
2022-08-02  9:52 ` Quentin Schulz
2022-08-02  9:52 ` Quentin Schulz
2022-08-02  9:52 ` [RFC PATCH 1/1] pinctrl: rockchip: add support for per-pinmux io-domain dependency Quentin Schulz
2022-08-02  9:52   ` Quentin Schulz
2022-08-02  9:52   ` Quentin Schulz
2022-08-11  7:52   ` Michael Riesch [this message]
2022-08-11  7:52     ` Michael Riesch
2022-08-11  7:52     ` Michael Riesch
2022-08-11  8:45     ` Quentin Schulz
2022-08-11  8:45       ` Quentin Schulz
2022-08-11  8:45       ` Quentin Schulz
2022-08-11  9:26       ` Heiko Stübner
2022-08-11  9:26         ` Heiko Stübner
2022-08-11  9:26         ` Heiko Stübner
2022-08-11 10:21         ` Quentin Schulz
2022-08-11 10:21           ` Quentin Schulz
2022-08-11 10:21           ` Quentin Schulz
2023-02-15 10:23   ` Sascha Hauer
2023-02-15 10:23     ` Sascha Hauer
2023-02-15 10:23     ` Sascha Hauer
2023-02-21 12:14     ` Quentin Schulz
2023-02-21 12:14       ` Quentin Schulz
2023-02-21 12:14       ` Quentin Schulz
2023-02-22 12:05       ` Sascha Hauer
2023-02-22 12:05         ` Sascha Hauer
2023-02-22 12:05         ` Sascha Hauer
2022-08-22  8:38 ` [RFC PATCH 0/1] Making Rockchip IO domains dependency from other devices explicit Linus Walleij
2022-08-22  8:38   ` Linus Walleij
2022-08-22  8:38   ` Linus Walleij
2022-08-22 23:43   ` Heiko Stübner
2022-08-22 23:43     ` Heiko Stübner
2022-08-22 23:43     ` Heiko Stübner

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=9b965d86-9b76-77a1-658e-3675c2138414@wolfvision.net \
    --to=michael.riesch@wolfvision.net \
    --cc=foss+kernel@0leil.net \
    --cc=heiko@sntech.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=quentin.schulz@theobroma-systems.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 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.