media: c8sectpfe: convert to gpio descriptors
PATCH 1/1 media: c8sectpfe: convert to gpio descriptors
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal gpiod_get() interface cannot be used here since the gpio is referenced by a child node of the device.
Using devm_fwnode_gpiod_get_index() is the best alternative here.
--- .../st/sti/c8sectpfe/c8sectpfe-core.c | 30 ++++++++----------- .../st/sti/c8sectpfe/c8sectpfe-core.h | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-)
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +12 -18
@@ -22,7 +22,7 @@#include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of_platform.h> #include <linux/pinctrl/consumer.h> #include <linux/pinctrl/pinctrl.h>
@@ -812,30 +812,24 @@ 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" ); + tsin->rst_gpio =devm_fwnode_gpiod_get_index (dev, +of_node_to_fwnode (child), +"reset-gpios" , +0 ,GPIOD_OUT_LOW , +"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_probe (dev, ret, +"reset gpio for tsin%d not valid\n" , + tsin->tsin_id); goto err_node_put; }if (!ret) {/* toggle reset lines */ -gpio_direction_output (tsin->rst_gpio,0 ); +gpiod_direction_output (tsin->rst_gpio,0 );usleep_range (3500 ,5000 ); -gpio_direction_output (tsin->rst_gpio,1 ); +gpiod_direction_output (tsin->rst_gpio,1 );usleep_range (3000 ,5000 ); }
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h +1 -1
@@ -25,7 +25,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;
Signature · 1 line
2.39.0
Quoted 8 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.Using
devm_fwnode_gpiod_get_index()is the best alternative here.
One topic to discuss below (but I'm fine with this version).
Quoted 43 lines
Signed-off-by Arnd Bergmann <[email protected]>--- .../st/sti/c8sectpfe/c8sectpfe-core.c | 30 ++++++++----------- .../st/sti/c8sectpfe/c8sectpfe-core.h | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +7
-14@@ -22,7 +22,7 @@#include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of_platform.h> #include <linux/pinctrl/consumer.h> #include <linux/pinctrl/pinctrl.h> @@ -812,30 +812,24 @@ 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" ); + tsin->rst_gpio =devm_fwnode_gpiod_get_index (dev, +of_node_to_fwnode (child), +"reset-gpios" , +0 ,GPIOD_OUT_LOW , +"NIM reset" ); + ret =PTR_ERR_OR_ZERO (tsin->rst_gpio);
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 829
Quoted 10 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +3
-2if (ret && ret != -EBUSY ) { -dev_err (dev,"Can't request tsin%d reset gpio\n" - , fei->channel_data[index]->tsin_id); +dev_err_probe (dev, ret, +"reset gpio for tsin%d not valid\n" , + tsin->tsin_id); goto err_node_put; }if (!ret) {
Can be
if (IS_ERR() && PTR_ERR() != -EBUSY) {
ret = dev_err_probe(dev, PTR_ERR(), ...);
...
}
if (!IS_ERR())(Up to you)
But -EBUSY check seems strange to me. What was the motivation behind? (As far as I can read the code the possibility to get this if and only
if we have requested GPIO too early at initcall level. Would it be ever a possibility to get it in real life?)
Quoted 25 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +2
-2/* toggle reset lines */ -gpio_direction_output (tsin->rst_gpio,0 ); +gpiod_direction_output (tsin->rst_gpio,0 );usleep_range (3500 ,5000 ); -gpio_direction_output (tsin->rst_gpio,1 ); +gpiod_direction_output (tsin->rst_gpio,1 );usleep_range (3000 ,5000 ); }drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.h +1
-1@@ -25,7 +25,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;Signature · 1 line
2.39.0
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 16 lines · Andy Shevchenko
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 828
Quoted 11 lines · Arnd Bergmann
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +4
-2+ 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_probe (dev, ret, +"reset gpio for tsin%d not valid\n" , + tsin->tsin_id); goto err_node_put; }if (!ret) {Can be
Quoted 8 lines
if (IS_ERR() && PTR_ERR() != -EBUSY) { ret = dev_err_probe(dev, PTR_ERR(), ...); ... } if (!IS_ERR())(Up to you)
I prefer the version that only has one PTR_ERR(), but either way is fine with me.
Quoted 4 lines
But
-EBUSYcheck seems strange to me. What was the motivation behind? (As far as I can read the code the possibility to get this if and only
if we have requested GPIO too early at initcall level. Would it be ever a possibility to get it in real life?)
I noticed this part as being odd as well, no idea why the code is like this. I just left the logic unchanged here.
Arnd
Quoted 30 lines · Arnd Bergmann
Quoted 16 lines · Andy Shevchenko
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 828
Quoted 11 lines · Arnd Bergmann
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +4
-2+ 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_probe (dev, ret, +"reset gpio for tsin%d not valid\n" , + tsin->tsin_id); goto err_node_put; }if (!ret) {Can be
Quoted 8 lines
if (IS_ERR() && PTR_ERR() != -EBUSY) { ret = dev_err_probe(dev, PTR_ERR(), ...); ... } if (!IS_ERR())(Up to you)
I prefer the version that only has one
PTR_ERR(), but either way is fine with me.
Quoted 7 lines
Quoted 4 lines
But
-EBUSYcheck seems strange to me. What was the motivation behind? (As far as I can read the code the possibility to get this if and only
if we have requested GPIO too early at initcall level. Would it be ever a possibility to get it in real life?)I noticed this part as being odd as well, no idea why the code is like this. I just left the logic unchanged here.
It could be they were trying to account for the possibility of the reset line being shared between several blocks, and so the first one to initialize would grab it and reset all chips, and the followers would be skipping the reset logic.
Signature · 1 line
Dmitry
Quoted 39 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.Using
devm_fwnode_gpiod_get_index()is the best alternative here.Signed-off-by Arnd Bergmann <[email protected]>--- .../st/sti/c8sectpfe/c8sectpfe-core.c | 30 ++++++++----------- .../st/sti/c8sectpfe/c8sectpfe-core.h | 2 +- 2 files changed, 13 insertions(+), 19 deletions(-)drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +1
-7@@ -22,7 +22,7 @@#include <linux/interrupt.h> #include <linux/io.h> #include <linux/module.h> -#include <linux/of_gpio.h> +#include <linux/gpio/consumer.h> #include <linux/of_platform.h> #include <linux/pinctrl/consumer.h> #include <linux/pinctrl/pinctrl.h> @@ -812,30 +812,24 @@ 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",
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 817
Quoted 10 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +3
-7- 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" ); + tsin->rst_gpio = devm_fwnode_gpiod_get_index(dev, + of_node_to_fwnode(child), + "reset-gpios",
Wrong name.
Quoted 6 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +3
-2+0 ,GPIOD_OUT_LOW , + "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);
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 830
Quoted 10 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +4
-1+dev_err_probe (dev, ret, +"reset gpio for tsin%d not valid\n" , + tsin->tsin_id); goto err_node_put; }if (!ret) {/* toggle reset lines */ -gpio_direction_output (tsin->rst_gpio,0 ); +gpiod_direction_output (tsin->rst_gpio,0 );
It is already set up as output, and you either need to use "raw" or fix polarity.
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 834
Quoted 5 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +1
-1usleep_range (3500 ,5000 ); -gpio_direction_output (tsin->rst_gpio,1 ); +gpiod_direction_output (tsin->rst_gpio,1 );usleep_range (3000 ,5000 ); }
Thanks.
Signature · 1 line
Dmitry
Quoted 1 line · Dmitry Torokhov
On Mon, Jan 30, 2023 at 5:31 AM Arnd Bergmann <[email protected]> wrote:
...
Quoted 2 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c static int c8sectpfe_probe(struct platform_device *pdev) · line 816
Quoted 2 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +2
-0+ tsin->rst_gpio = devm_fwnode_gpiod_get_index(dev, + of_node_to_fwnode(child),
Actually, please use of_fwnode_handle() and not IRQ framework custom grown duplicate.
Quoted 6 lines
Quoted 1 line
+ "reset-gpios",
Wrong name.
Quoted 2 lines
drivers/media/platform/st/sti/c8sectpfe/c8sectpfe-core.c +2
-0+0 ,GPIOD_OUT_LOW , + "NIM reset");
Signature · 9 lines
With Best Regards, Andy Shevchenko _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Hi Arnd,
Quoted 10 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.Using
devm_fwnode_gpiod_get_index()is the best alternative here.Signed-off-by Arnd Bergmann <[email protected]>
I've picked <URL:https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/> instead. I hope that's fine. Also cc Dmitry.
Signature · 3 lines
Kind regards, Sakari Ailus
Quoted 9 lines · Sakari Ailus
Hi Arnd,
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.
Quoted 8 lines
Quoted 4 lines
Using
devm_fwnode_gpiod_get_index()is the best alternative here.Signed-off-by Arnd Bergmann <[email protected]>I've picked <URL:https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/> instead. I hope that's fine. Also cc Dmitry.
What do you mean "instead"? This is the exact patch that started this thread, and it is broken (uses wrong name of the GPIO and wrong polarity).
I'd much rather you picked up
https://lore.kernel.org/all/Y92VLGLQJZ%[email protected]/
Thanks.
Signature · 1 line
Dmitry
Hi Dmitry,
Quoted 19 lines · Dmitry Torokhov
Quoted 9 lines · Sakari Ailus
Hi Arnd,
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.Quoted 8 lines
Quoted 4 lines
Using
devm_fwnode_gpiod_get_index()is the best alternative here.Signed-off-by Arnd Bergmann <[email protected]>I've picked <URL:https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/> instead. I hope that's fine. Also cc Dmitry.
Quoted 7 lines
What do you mean "instead"? This is the exact patch that started this thread, and it is broken (uses wrong name of the GPIO and wrong polarity).
I'd much rather you picked up
https://lore.kernel.org/all/Y92VLGLQJZ%[email protected]/Thanks.
Ah, the URL in my e-mail was wrong. I have <URL:https://patchwork.linuxtv.org/project/linux-media/patch/Y92VLGLQJZ/[email protected]/>, i.e. the same patch.
Signature · 8 lines
Regards, Sakari Ailus _______________________________________________ linux-arm-kernel mailing list [email protected] http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Quoted 25 lines · Sakari Ailus
Hi Dmitry,
Quoted 22 lines · Dmitry Torokhov
Quoted 9 lines · Sakari Ailus
Hi Arnd,
Quoted 6 lines · Arnd Bergmann
From: Arnd Bergmann <[email protected]>
The gpio usage in the function is fairly straightforward, but the normal
gpiod_get()interface cannot be used here since the gpio is referenced by a child node of the device.Quoted 8 lines
Quoted 4 lines
Using
devm_fwnode_gpiod_get_index()is the best alternative here.Signed-off-by Arnd Bergmann <[email protected]>I've picked <URL:https://patchwork.linuxtv.org/project/linux-media/patch/[email protected]/> instead. I hope that's fine. Also cc Dmitry.
What do you mean "instead"? This is the exact patch that started this thread, and it is broken (uses wrong name of the GPIO and wrong polarity).
Quoted 8 lines
Quoted 4 lines
I'd much rather you picked up
https://lore.kernel.org/all/Y92VLGLQJZ%[email protected]/Thanks.
Ah, the URL in my e-mail was wrong. I have <URL:https://patchwork.linuxtv.org/project/linux-media/patch/Y92VLGLQJZ/[email protected]/>, i.e. the same patch.
Ah, I see, thank you.
Signature · 1 line
Dmitry