linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Sylwester Nawrocki <s.nawrocki@samsung.com>,
	Andrzej Hajda <andrzej.hajda@intel.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	linux-kernel@vger.kernel.org, linux-media@vger.kernel.org
Subject: Re: [PATCH 2/4] media: i2c: s5k5baf: switch to using gpiod API
Date: Thu, 17 Nov 2022 11:54:32 +0100	[thread overview]
Message-ID: <20221117105432.GB2725180@tom-ThinkPad-T14s-Gen-2i> (raw)
In-Reply-To: <20221115221145.2550572-2-dmitry.torokhov@gmail.com>

Hi Dmitry,

On Tue, Nov 15, 2022 at 02:11:43PM -0800, Dmitry Torokhov wrote:
> This patch switches the driver away from legacy gpio/of_gpio API to
> gpiod API, and removes use of of_get_named_gpio_flags() which I want to
> make private to gpiolib.
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> ---
>  drivers/media/i2c/s5k5baf.c | 64 +++++++++++--------------------------
>  1 file changed, 18 insertions(+), 46 deletions(-)
> 
> diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
> index 5c2253ab3b6f..960fbf6428ea 100644
> --- a/drivers/media/i2c/s5k5baf.c
> +++ b/drivers/media/i2c/s5k5baf.c
> @@ -13,11 +13,10 @@
>  #include <linux/clk.h>
>  #include <linux/delay.h>
>  #include <linux/firmware.h>
> -#include <linux/gpio.h>
> +#include <linux/gpio/consumer.h>
>  #include <linux/i2c.h>
>  #include <linux/media.h>
>  #include <linux/module.h>
> -#include <linux/of_gpio.h>
>  #include <linux/of_graph.h>
>  #include <linux/regulator/consumer.h>
>  #include <linux/slab.h>
> @@ -228,11 +227,6 @@ static const char * const s5k5baf_supply_names[] = {
>  };
>  #define S5K5BAF_NUM_SUPPLIES ARRAY_SIZE(s5k5baf_supply_names)
>  
> -struct s5k5baf_gpio {
> -	int gpio;
> -	int level;
> -};
> -
>  enum s5k5baf_gpio_id {
>  	STBY,
>  	RSET,
> @@ -284,7 +278,7 @@ struct s5k5baf_fw {
>  };
>  
>  struct s5k5baf {
> -	struct s5k5baf_gpio gpios[NUM_GPIOS];
> +	struct gpio_desc *gpios[NUM_GPIOS];
>  	enum v4l2_mbus_type bus_type;
>  	u8 nlanes;
>  	struct regulator_bulk_data supplies[S5K5BAF_NUM_SUPPLIES];
> @@ -936,16 +930,12 @@ static void s5k5baf_hw_set_test_pattern(struct s5k5baf *state, int id)
>  
>  static void s5k5baf_gpio_assert(struct s5k5baf *state, int id)
>  {
> -	struct s5k5baf_gpio *gpio = &state->gpios[id];
> -
> -	gpio_set_value(gpio->gpio, gpio->level);
> +	gpiod_set_value_cansleep(state->gpios[id], 1);
>  }
>  
>  static void s5k5baf_gpio_deassert(struct s5k5baf *state, int id)
>  {
> -	struct s5k5baf_gpio *gpio = &state->gpios[id];
> -
> -	gpio_set_value(gpio->gpio, !gpio->level);
> +	gpiod_set_value_cansleep(state->gpios[id], 0);
>  }
>  
>  static int s5k5baf_power_on(struct s5k5baf *state)
> @@ -1799,44 +1789,30 @@ static const struct v4l2_subdev_ops s5k5baf_subdev_ops = {
>  
>  static int s5k5baf_configure_gpios(struct s5k5baf *state)
>  {
> -	static const char * const name[] = { "S5K5BAF_STBY", "S5K5BAF_RST" };
> +	static const char * const name[] = { "stbyn", "rstn" };
> +	static const char * const label[] = { "S5K5BAF_STBY", "S5K5BAF_RST" };
>  	struct i2c_client *c = v4l2_get_subdevdata(&state->sd);
> -	struct s5k5baf_gpio *g = state->gpios;
> +	struct gpio_desc *gpio;
>  	int ret, i;
>  
>  	for (i = 0; i < NUM_GPIOS; ++i) {
> -		int flags = GPIOF_DIR_OUT;
> -		if (g[i].level)
> -			flags |= GPIOF_INIT_HIGH;
> -		ret = devm_gpio_request_one(&c->dev, g[i].gpio, flags, name[i]);
> -		if (ret < 0) {
> -			v4l2_err(c, "failed to request gpio %s\n", name[i]);
> +		gpio = devm_gpiod_get(&c->dev, name[i], GPIOD_OUT_HIGH);
> +		ret = PTR_ERR_OR_ZERO(gpio);
> +		if (ret) {
> +			v4l2_err(c, "failed to request gpio %s: %d\n",
> +				 name[i], ret);
>  			return ret;
>  		}
> -	}
> -	return 0;
> -}
> -
> -static int s5k5baf_parse_gpios(struct s5k5baf_gpio *gpios, struct device *dev)
> -{
> -	static const char * const names[] = {
> -		"stbyn-gpios",
> -		"rstn-gpios",
> -	};
> -	struct device_node *node = dev->of_node;
> -	enum of_gpio_flags flags;
> -	int ret, i;
>  
> -	for (i = 0; i < NUM_GPIOS; ++i) {
> -		ret = of_get_named_gpio_flags(node, names[i], 0, &flags);
> -		if (ret < 0) {
> -			dev_err(dev, "no %s GPIO pin provided\n", names[i]);
> +		ret = gpiod_set_consumer_name(gpio, label[i]);
> +		if (ret) {
> +			v4l2_err(c, "failed to set up name for gpio %s: %d\n",
> +				 name[i], ret);
>  			return ret;
>  		}
> -		gpios[i].gpio = ret;
> -		gpios[i].level = !(flags & OF_GPIO_ACTIVE_LOW);
> -	}
>  
> +		state->gpios[i] = gpio;
> +	}
>  	return 0;
>  }
>  
> @@ -1860,10 +1836,6 @@ static int s5k5baf_parse_device_node(struct s5k5baf *state, struct device *dev)
>  			 state->mclk_frequency);
>  	}
>  
> -	ret = s5k5baf_parse_gpios(state->gpios, dev);
> -	if (ret < 0)
> -		return ret;
> -
>  	node_ep = of_graph_get_next_endpoint(node, NULL);
>  	if (!node_ep) {
>  		dev_err(dev, "no endpoint defined at node %pOF\n", node);
> -- 
> 2.38.1.431.g37b22c650d-goog
> 

Looks good to me.

Reviewed-by: Tommaso Merciai <tommaso.merciai@amarulasolutions.com>

Regards,
Tommaso

-- 
Tommaso Merciai
Embedded Linux Engineer
tommaso.merciai@amarulasolutions.com
__________________________________

Amarula Solutions SRL
Via Le Canevare 30, 31100 Treviso, Veneto, IT
T. +39 042 243 5310
info@amarulasolutions.com
www.amarulasolutions.com

  reply	other threads:[~2022-11-17 10:57 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-15 22:11 [PATCH 1/4] media: i2c: s5k6a3: switch to using gpiod API Dmitry Torokhov
2022-11-15 22:11 ` [PATCH 2/4] media: i2c: s5k5baf: " Dmitry Torokhov
2022-11-17 10:54   ` Tommaso Merciai [this message]
2022-11-15 22:11 ` [PATCH 3/4] media: i2c: s5c73m3: remove support for platform data Dmitry Torokhov
2022-11-17 11:05   ` Tommaso Merciai
2022-11-28  8:39   ` Hans Verkuil
2022-11-28 19:50     ` Dmitry Torokhov
2022-11-15 22:11 ` [PATCH 4/4] media: i2c: s5c73m3: switch to using gpiod API Dmitry Torokhov
2022-11-17  9:06   ` Linus Walleij
2022-11-26 10:34     ` Hans Verkuil
2022-11-26 10:39       ` Hans Verkuil
2022-11-26 21:49       ` Linus Walleij
2022-11-17 11:06   ` Tommaso Merciai
2022-11-17  9:04 ` [PATCH 1/4] media: i2c: s5k6a3: " Linus Walleij
2022-11-17  9:11 ` Tommaso Merciai

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=20221117105432.GB2725180@tom-ThinkPad-T14s-Gen-2i \
    --to=tommaso.merciai@amarulasolutions.com \
    --cc=andrzej.hajda@intel.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=s.nawrocki@samsung.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).