linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] media: c8sectpfe: switch to using gpiod API
@ 2023-02-03 23:13 Dmitry Torokhov
  2023-03-10 16:52 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Dmitry Torokhov @ 2023-02-03 23:13 UTC (permalink / raw)
  To: Patrice Chotard, Mauro Carvalho Chehab
  Cc: Arnd Bergmann, Andy Shevchenko, Hans Verkuil, Liang He,
	Wan Jiabing, Hugues Fruchet, linux-arm-kernel, linux-media,
	linux-kernel

This switches the driver from using legacy gpio API and to the newer
gpiod API. Since ordinary gpiod APIs operate on logical and not
electrical levels, handling of the reset GPIO is adjusted accordingly.

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 .../st/sti/c8sectpfe/c8sectpfe-core.c         | 31 ++++++++-----------
 .../st/sti/c8sectpfe/c8sectpfe-core.h         |  4 ++-
 2 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
index c38b62d4f1ae..dd8141e0828d 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
+++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
@@ -16,8 +16,10 @@
 #include <linux/dma-mapping.h>
 #include <linux/dvb/dmx.h>
 #include <linux/dvb/frontend.h>
+#include <linux/err.h>
 #include <linux/errno.h>
 #include <linux/firmware.h>
+#include <linux/gpio/consumer.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/io.h>
@@ -812,30 +814,23 @@ static int c8sectpfe_probe(struct platform_device *pdev)
 		}
 		of_node_put(i2c_bus);
 
-		tsin->rst_gpio = of_get_named_gpio(child, "reset-gpios", 0);
-
-		ret = gpio_is_valid(tsin->rst_gpio);
-		if (!ret) {
-			dev_err(dev,
-				"reset gpio for tsin%d not valid (gpio=%d)\n",
-				tsin->tsin_id, tsin->rst_gpio);
-			ret = -EINVAL;
-			goto err_node_put;
-		}
-
-		ret = devm_gpio_request_one(dev, tsin->rst_gpio,
-					GPIOF_OUT_INIT_LOW, "NIM reset");
+		/* Acquire reset GPIO and activate it */
+		tsin->rst_gpio = devm_fwnode_gpiod_get(dev,
+						       of_fwnode_handle(child),
+						       "reset", GPIOD_OUT_HIGH,
+						       "NIM reset");
+		ret = PTR_ERR_OR_ZERO(tsin->rst_gpio);
 		if (ret && ret != -EBUSY) {
-			dev_err(dev, "Can't request tsin%d reset gpio\n"
-				, fei->channel_data[index]->tsin_id);
+			dev_err(dev, "Can't request tsin%d reset gpio\n",
+				fei->channel_data[index]->tsin_id);
 			goto err_node_put;
 		}
 
 		if (!ret) {
-			/* toggle reset lines */
-			gpio_direction_output(tsin->rst_gpio, 0);
+			/* wait for the chip to reset */
 			usleep_range(3500, 5000);
-			gpio_direction_output(tsin->rst_gpio, 1);
+			/* release the reset line */
+			gpiod_set_value_cansleep(tsin->rst_gpio, 0);
 			usleep_range(3000, 5000);
 		}
 
diff --git a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h
index c9d6021904cd..bf377cc82225 100644
--- a/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h
+++ b/drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h
@@ -16,6 +16,8 @@
 
 #define C8SECTPFE_MAX_TSIN_CHAN 8
 
+struct gpio_desc;
+
 struct channel_info {
 
 	int tsin_id;
@@ -25,7 +27,7 @@ struct channel_info {
 	int i2c;
 	int dvb_card;
 
-	int rst_gpio;
+	struct gpio_desc *rst_gpio;
 
 	struct i2c_adapter  *i2c_adapter;
 	struct i2c_adapter  *tuner_i2c;
-- 
2.39.1.519.gcb327c4b5f-goog


-- 
Dmitry

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] media: c8sectpfe: switch to using gpiod API
  2023-02-03 23:13 [PATCH] media: c8sectpfe: switch to using gpiod API Dmitry Torokhov
@ 2023-03-10 16:52 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2023-03-10 16:52 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Patrice Chotard, Mauro Carvalho Chehab, Arnd Bergmann,
	Hans Verkuil, Liang He, Wan Jiabing, Hugues Fruchet,
	linux-arm-kernel, linux-media, linux-kernel

On Fri, Feb 03, 2023 at 03:13:48PM -0800, Dmitry Torokhov wrote:
> This switches the driver from using legacy gpio API and to the newer
> gpiod API. Since ordinary gpiod APIs operate on logical and not
> electrical levels, handling of the reset GPIO is adjusted accordingly.

Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>

This is an important patch for the further cleanups in the GPIO subsystem.
Can we have this applied, please?

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-03-10 16:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-03 23:13 [PATCH] media: c8sectpfe: switch to using gpiod API Dmitry Torokhov
2023-03-10 16:52 ` Andy Shevchenko

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).