media: c8sectpfe: switch to using gpiod API
authorDmitry Torokhov <dmitry.torokhov@gmail.com>
Fri, 3 Feb 2023 23:13:48 +0000 (15:13 -0800)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 25 May 2023 14:21:23 +0000 (16:21 +0200)
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>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h

index 1208309..03d5d6e 100644 (file)
 #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);
                }
 
index c9d6021..bf377cc 100644 (file)
@@ -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;