All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Balamanikandan Gunasundar  <balamanikandan.gunasundar@microchip.com>
Cc: ludovic.desroches@microchip.com, ulf.hansson@linaro.org,
	nicolas.ferre@microchip.com, alexandre.belloni@bootlin.com,
	3chas3@gmail.com, linux-mmc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org,
	linux-atm-general@lists.sourceforge.net, netdev@vger.kernel.org
Subject: Re: [PATCH] mmc: atmel-mci: Convert to gpio descriptors
Date: Thu, 10 Nov 2022 14:41:51 -0800	[thread overview]
Message-ID: <Y21+L01BcPQ35FYi@google.com> (raw)
In-Reply-To: <20221109043845.16617-1-balamanikandan.gunasundar@microchip.com>

Hi Balamanikandan,

On Wed, Nov 09, 2022 at 10:08:45AM +0530, Balamanikandan Gunasundar wrote:
> Replace the legacy GPIO APIs with gpio descriptor consumer interface.
> 
> To maintain backward compatibility, we rely on the "cd-inverted"
> property to manage the invertion flag instead of GPIO property.
> 
> Signed-off-by: Balamanikandan Gunasundar <balamanikandan.gunasundar@microchip.com>
> ---
>  drivers/mmc/host/atmel-mci.c | 79 ++++++++++++++++++------------------
>  include/linux/atmel-mci.h    |  4 +-
>  2 files changed, 41 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
> index 67b2cd166e56..1df90966e104 100644
> --- a/drivers/mmc/host/atmel-mci.c
> +++ b/drivers/mmc/host/atmel-mci.c
> @@ -19,7 +19,8 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> -#include <linux/of_gpio.h>
> +#include <linux/irq.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/platform_device.h>
>  #include <linux/scatterlist.h>
>  #include <linux/seq_file.h>
> @@ -389,8 +390,8 @@ struct atmel_mci_slot {
>  #define ATMCI_CARD_NEED_INIT	1
>  #define ATMCI_SHUTDOWN		2
>  
> -	int			detect_pin;
> -	int			wp_pin;
> +	struct gpio_desc        *detect_pin;
> +	struct gpio_desc	*wp_pin;
>  	bool			detect_is_active_high;
>  
>  	struct timer_list	detect_timer;
> @@ -638,7 +639,11 @@ atmci_of_init(struct platform_device *pdev)
>  			pdata->slot[slot_id].bus_width = 1;
>  
>  		pdata->slot[slot_id].detect_pin =
> -			of_get_named_gpio(cnp, "cd-gpios", 0);
> +			devm_gpiod_get_from_of_node(&pdev->dev, cnp,
> +						    "cd-gpios",
> +						    0, GPIOD_IN, "cd-gpios");

As I mentioned in another email, please use devm_fwnode_gpiod_get()
instead of devm_gpiod_get_from_of_node() which is going away.

> +		if (IS_ERR(pdata->slot[slot_id].detect_pin))
> +			pdata->slot[slot_id].detect_pin = NULL;

I think it would be much better if we had proper error handling and did
something like:

		err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].detect_pin);
		if (err) {
			if (err != -ENOENT)
				return ERR_PTR(err);
			pdata->slot[slot_id].detect_pin = NULL;
		}

This will help with proper deferral handling.

>  
>  		pdata->slot[slot_id].detect_is_active_high =
>  			of_property_read_bool(cnp, "cd-inverted");

Instead of doing gpiod_set_value_raw() below I would recommend handling
it here via gpiod_is_active_low() and gpiod_toggle_active_low() and
removing the flag from atmel_mci_slot structure.


> @@ -647,7 +652,11 @@ atmci_of_init(struct platform_device *pdev)
>  			of_property_read_bool(cnp, "non-removable");
>  
>  		pdata->slot[slot_id].wp_pin =
> -			of_get_named_gpio(cnp, "wp-gpios", 0);
> +			devm_gpiod_get_from_of_node(&pdev->dev, cnp,
> +						    "wp-gpios",
> +						    0, GPIOD_IN, "wp-gpios");
> +		if (IS_ERR(pdata->slot[slot_id].wp_pin))
> +			pdata->slot[slot_id].wp_pin = NULL;
>  	}
>  
>  	return pdata;
> @@ -1511,8 +1520,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
>  	int			read_only = -ENOSYS;
>  	struct atmel_mci_slot	*slot = mmc_priv(mmc);
>  
> -	if (gpio_is_valid(slot->wp_pin)) {
> -		read_only = gpio_get_value(slot->wp_pin);
> +	if (slot->wp_pin) {
> +		read_only = gpiod_get_value(slot->wp_pin);

Consider using "cansleep" variants.

Thanks.

-- 
Dmitry

WARNING: multiple messages have this Message-ID (diff)
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Balamanikandan Gunasundar <balamanikandan.gunasundar@microchip.com>
Cc: ulf.hansson@linaro.org, linux-kernel@vger.kernel.org,
	linux-atm-general@lists.sourceforge.net,
	linux-mmc@vger.kernel.org, alexandre.belloni@bootlin.com,
	ludovic.desroches@microchip.com, 3chas3@gmail.com,
	netdev@vger.kernel.org, linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH] mmc: atmel-mci: Convert to gpio descriptors
Date: Thu, 10 Nov 2022 14:41:51 -0800	[thread overview]
Message-ID: <Y21+L01BcPQ35FYi@google.com> (raw)
In-Reply-To: <20221109043845.16617-1-balamanikandan.gunasundar@microchip.com>

Hi Balamanikandan,

On Wed, Nov 09, 2022 at 10:08:45AM +0530, Balamanikandan Gunasundar wrote:
> Replace the legacy GPIO APIs with gpio descriptor consumer interface.
> 
> To maintain backward compatibility, we rely on the "cd-inverted"
> property to manage the invertion flag instead of GPIO property.
> 
> Signed-off-by: Balamanikandan Gunasundar <balamanikandan.gunasundar@microchip.com>
> ---
>  drivers/mmc/host/atmel-mci.c | 79 ++++++++++++++++++------------------
>  include/linux/atmel-mci.h    |  4 +-
>  2 files changed, 41 insertions(+), 42 deletions(-)
> 
> diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
> index 67b2cd166e56..1df90966e104 100644
> --- a/drivers/mmc/host/atmel-mci.c
> +++ b/drivers/mmc/host/atmel-mci.c
> @@ -19,7 +19,8 @@
>  #include <linux/module.h>
>  #include <linux/of.h>
>  #include <linux/of_device.h>
> -#include <linux/of_gpio.h>
> +#include <linux/irq.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/platform_device.h>
>  #include <linux/scatterlist.h>
>  #include <linux/seq_file.h>
> @@ -389,8 +390,8 @@ struct atmel_mci_slot {
>  #define ATMCI_CARD_NEED_INIT	1
>  #define ATMCI_SHUTDOWN		2
>  
> -	int			detect_pin;
> -	int			wp_pin;
> +	struct gpio_desc        *detect_pin;
> +	struct gpio_desc	*wp_pin;
>  	bool			detect_is_active_high;
>  
>  	struct timer_list	detect_timer;
> @@ -638,7 +639,11 @@ atmci_of_init(struct platform_device *pdev)
>  			pdata->slot[slot_id].bus_width = 1;
>  
>  		pdata->slot[slot_id].detect_pin =
> -			of_get_named_gpio(cnp, "cd-gpios", 0);
> +			devm_gpiod_get_from_of_node(&pdev->dev, cnp,
> +						    "cd-gpios",
> +						    0, GPIOD_IN, "cd-gpios");

As I mentioned in another email, please use devm_fwnode_gpiod_get()
instead of devm_gpiod_get_from_of_node() which is going away.

> +		if (IS_ERR(pdata->slot[slot_id].detect_pin))
> +			pdata->slot[slot_id].detect_pin = NULL;

I think it would be much better if we had proper error handling and did
something like:

		err = PTR_ERR_OR_ZERO(pdata->slot[slot_id].detect_pin);
		if (err) {
			if (err != -ENOENT)
				return ERR_PTR(err);
			pdata->slot[slot_id].detect_pin = NULL;
		}

This will help with proper deferral handling.

>  
>  		pdata->slot[slot_id].detect_is_active_high =
>  			of_property_read_bool(cnp, "cd-inverted");

Instead of doing gpiod_set_value_raw() below I would recommend handling
it here via gpiod_is_active_low() and gpiod_toggle_active_low() and
removing the flag from atmel_mci_slot structure.


> @@ -647,7 +652,11 @@ atmci_of_init(struct platform_device *pdev)
>  			of_property_read_bool(cnp, "non-removable");
>  
>  		pdata->slot[slot_id].wp_pin =
> -			of_get_named_gpio(cnp, "wp-gpios", 0);
> +			devm_gpiod_get_from_of_node(&pdev->dev, cnp,
> +						    "wp-gpios",
> +						    0, GPIOD_IN, "wp-gpios");
> +		if (IS_ERR(pdata->slot[slot_id].wp_pin))
> +			pdata->slot[slot_id].wp_pin = NULL;
>  	}
>  
>  	return pdata;
> @@ -1511,8 +1520,8 @@ static int atmci_get_ro(struct mmc_host *mmc)
>  	int			read_only = -ENOSYS;
>  	struct atmel_mci_slot	*slot = mmc_priv(mmc);
>  
> -	if (gpio_is_valid(slot->wp_pin)) {
> -		read_only = gpio_get_value(slot->wp_pin);
> +	if (slot->wp_pin) {
> +		read_only = gpiod_get_value(slot->wp_pin);

Consider using "cansleep" variants.

Thanks.

-- 
Dmitry

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

  parent reply	other threads:[~2022-11-10 22:42 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-09  4:38 [PATCH] mmc: atmel-mci: Convert to gpio descriptors Balamanikandan Gunasundar
2022-11-09  4:38 ` Balamanikandan Gunasundar
2022-11-09 12:38 ` Ulf Hansson
2022-11-09 12:38   ` Ulf Hansson
2022-11-09 14:48   ` Linus Walleij
2022-11-09 14:48     ` Linus Walleij
2022-11-10 22:33     ` Dmitry Torokhov
2022-11-10 22:33       ` Dmitry Torokhov
2022-11-09 17:16 ` Andrew Lunn
2022-11-09 17:16   ` Andrew Lunn
2022-11-10  8:05   ` Arnd Bergmann
2022-11-10  8:05     ` Arnd Bergmann
2022-11-10  9:02     ` Arnd Bergmann
2022-11-10  9:02       ` Arnd Bergmann
2022-11-10 22:41 ` Dmitry Torokhov [this message]
2022-11-10 22:41   ` Dmitry Torokhov

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=Y21+L01BcPQ35FYi@google.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=3chas3@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=balamanikandan.gunasundar@microchip.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-atm-general@lists.sourceforge.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=ludovic.desroches@microchip.com \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=ulf.hansson@linaro.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 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.