public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Roger Quadros <rogerq@kernel.org>
To: Maxime Ripard <mripard@kernel.org>,
	Simon Glass <sjg@chromium.org>,
	Joe Hershberger <joe.hershberger@ni.com>,
	Ramon Fried <rfried.dev@gmail.com>, Nishanth Menon <nm@ti.com>,
	Ravi Gunasekaran <r-gunasekaran@ti.com>
Cc: Javier Martinez Canillas <javierm@redhat.com>,
	Peter Robinson <pbrobinson@gmail.com>,
	u-boot@lists.denx.de
Subject: Re: [PATCH 1/4] pinctrl: Create a select_state variant with the ofnode
Date: Thu, 20 Jul 2023 18:56:14 +0300	[thread overview]
Message-ID: <38b4ede7-c862-49e6-cddb-15d6cfae489e@kernel.org> (raw)
In-Reply-To: <20230720-ti-mdio-pinmux-v1-1-0bd3bd1cf759@kernel.org>



On 20/07/2023 12:55, Maxime Ripard wrote:
> Some drivers might not follow entirely the driver/device association,
> and thus might support what should be multiple devices in a single
> driver.
> 
> Such a driver is am65-cpsw-nuss, where the MAC and MDIO controllers are
> different device tree nodes, with their own resources (including pinctrl
> pins) but supported by a single driver tied to the MAC device in U-Boot.
> 
> In order to get the proper pinctrl state, we would need to get the
> state from the MDIO device tree node, but tie it to the MAC device since
> it's the only thing we have access to.
> 
> Signed-off-by: Maxime Ripard <mripard@kernel.org>
> ---
>  drivers/pinctrl/pinctrl-uclass.c | 15 +++++++++------
>  include/dm/pinctrl.h             | 26 ++++++++++++++++++++------
>  2 files changed, 29 insertions(+), 12 deletions(-)
> 
> diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
> index 73dd7b1038bb..9e28f1858cbd 100644
> --- a/drivers/pinctrl/pinctrl-uclass.c
> +++ b/drivers/pinctrl/pinctrl-uclass.c
> @@ -53,7 +53,8 @@ static int pinctrl_config_one(struct udevice *config)
>   * @statename: state name, like "default"
>   * @return: 0 on success, or negative error code on failure
>   */
> -static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
> +static int pinctrl_select_state_full(struct udevice *dev, ofnode node,
> +				     const char *statename)
>  {
>  	char propname[32]; /* long enough */
>  	const fdt32_t *list;
> @@ -61,7 +62,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
>  	struct udevice *config;
>  	int state, size, i, ret;
>  
> -	state = dev_read_stringlist_search(dev, "pinctrl-names", statename);
> +	state = ofnode_stringlist_search(node, "pinctrl-names", statename);
>  	if (state < 0) {
>  		char *end;
>  		/*
> @@ -74,7 +75,7 @@ static int pinctrl_select_state_full(struct udevice *dev, const char *statename)
>  	}
>  
>  	snprintf(propname, sizeof(propname), "pinctrl-%d", state);
> -	list = dev_read_prop(dev, propname, &size);
> +	list = ofnode_get_property(node, propname, &size);
>  	if (!list)
>  		return -ENOSYS;
>  
> @@ -293,20 +294,22 @@ static int pinctrl_select_state_simple(struct udevice *dev)
>  	return ops->set_state_simple(pctldev, dev);
>  }
>  
> -int pinctrl_select_state(struct udevice *dev, const char *statename)
> +int pinctrl_select_state_by_ofnode(struct udevice *dev, ofnode node,
> +				   const char *statename)
>  {
>  	/*
>  	 * Some device which is logical like mmc.blk, do not have
>  	 * a valid ofnode.
>  	 */
> -	if (!dev_has_ofnode(dev))
> +	if (!ofnode_valid(node))
>  		return 0;
> +
>  	/*
>  	 * Try full-implemented pinctrl first.
>  	 * If it fails or is not implemented, try simple one.
>  	 */
>  	if (CONFIG_IS_ENABLED(PINCTRL_FULL))
> -		return pinctrl_select_state_full(dev, statename);
> +		return pinctrl_select_state_full(dev, node, statename);
>  
>  	return pinctrl_select_state_simple(dev);
>  }
> diff --git a/include/dm/pinctrl.h b/include/dm/pinctrl.h
> index e3e50afeaff0..be4679b7f20d 100644
> --- a/include/dm/pinctrl.h
> +++ b/include/dm/pinctrl.h
> @@ -502,6 +502,24 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev,
>  #endif
>  
>  #if CONFIG_IS_ENABLED(PINCTRL)
> +/**
> + * pinctrl_select_state_by_ofnode() - Set a device to a given state using the given ofnode
> + * @dev:	Peripheral device
> + * @ofnode:	Device Tree node to get the state from
> + * @statename:	State name, like "default"
> + *
> + * Return: 0 on success, or negative error code on failure
> + */
> +int pinctrl_select_state_by_ofnode(struct udevice *dev, ofnode node, const char *statename);
> +#else
> +static inline int pinctrl_select_state_by_ofnode(struct udevice *dev,
> +						 ofnode node,
> +						 const char *statename)
> +{
> +	return -ENOSYS;
> +}

This allows & encourages one device driver to change another devices pinctrl state
which doesn't look like a good idea to me.

Please see if an alternative solution pointed out in patch2 works
so we don't have to need this patch.

> +#endif
> +
>  /**
>   * pinctrl_select_state() - Set a device to a given state
>   * @dev:	Peripheral device
> @@ -509,14 +527,10 @@ static inline int pinctrl_generic_set_state(struct udevice *pctldev,
>   *
>   * Return: 0 on success, or negative error code on failure
>   */
> -int pinctrl_select_state(struct udevice *dev, const char *statename);
> -#else
> -static inline int pinctrl_select_state(struct udevice *dev,
> -				       const char *statename)
> +static inline int pinctrl_select_state(struct udevice *dev, const char *statename)
>  {
> -	return -ENOSYS;
> +	return pinctrl_select_state_by_ofnode(dev, dev_ofnode(dev), statename);
>  }
> -#endif
>  
>  /**
>   * pinctrl_request() - Request a particular pinctrl function
> 

-- 
cheers,
-roger

  reply	other threads:[~2023-07-20 15:56 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-20  9:55 [PATCH 0/4] net: ti: am65-cpsw-nuss: Fix DT binding handling of pinctrl Maxime Ripard
2023-07-20  9:55 ` [PATCH 1/4] pinctrl: Create a select_state variant with the ofnode Maxime Ripard
2023-07-20 15:56   ` Roger Quadros [this message]
2023-07-20  9:55 ` [PATCH 2/4] net: ti: am65-cpsw-nuss: Enforce pinctrl state on the MDIO child node Maxime Ripard
2023-07-20 15:47   ` Roger Quadros
2023-07-21 12:17     ` Maxime Ripard
2023-07-20  9:55 ` [PATCH 3/4] fixup! arm: dts: k3-am62: Bump dtsi from linux v6.5-rc1 Maxime Ripard
2023-07-20  9:55 ` [PATCH 4/4] " Maxime Ripard
2023-07-20 15:27   ` Roger Quadros
2023-07-21  7:46     ` Maxime Ripard
2023-07-21  9:14       ` Roger Quadros
2023-07-21  9:23         ` Maxime Ripard
2023-07-20 13:33 ` [PATCH 0/4] net: ti: am65-cpsw-nuss: Fix DT binding handling of pinctrl Ravi Gunasekaran
2023-07-20 13:56   ` Roger Quadros
2023-07-20 14:00     ` Nishanth Menon
2023-07-20 14:12       ` Maxime Ripard
2023-07-20 14:41         ` Roger Quadros
2023-07-20 14:52           ` Nishanth Menon
2023-07-26  9:14         ` Ravi Gunasekaran
2023-07-26 12:49           ` Maxime Ripard
2023-07-27  5:27             ` Ravi Gunasekaran
2023-07-26 12:52           ` Nishanth Menon
2023-07-27  5:36             ` Ravi Gunasekaran
2023-07-27  7:10               ` Roger Quadros

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=38b4ede7-c862-49e6-cddb-15d6cfae489e@kernel.org \
    --to=rogerq@kernel.org \
    --cc=javierm@redhat.com \
    --cc=joe.hershberger@ni.com \
    --cc=mripard@kernel.org \
    --cc=nm@ti.com \
    --cc=pbrobinson@gmail.com \
    --cc=r-gunasekaran@ti.com \
    --cc=rfried.dev@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /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