When requesting optional GPIO echo line, bail out on error,
so user will know that something wrong with the existing property.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pps/clients/pps-gpio.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index e0de1df2ede0..f89c31aa66f1 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -119,12 +119,12 @@ static int pps_gpio_setup(struct platform_device *pdev)
data->echo_pin = devm_gpiod_get_optional(&pdev->dev,
"echo",
GPIOD_OUT_LOW);
- if (data->echo_pin) {
- if (IS_ERR(data->echo_pin)) {
- dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
- return PTR_ERR(data->echo_pin);
- }
+ if (IS_ERR(data->echo_pin)) {
+ dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
+ return PTR_ERR(data->echo_pin);
+ }
+ if (data->echo_pin) {
ret = of_property_read_u32(np,
"echo-active-ms",
&value);
--
2.30.1
The timer along with GPIO API are NULL-aware, there is no need to test
against existing GPIO echo line.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pps/clients/pps-gpio.c | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index 78c9680e8063..dc9ed6fc3dae 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -240,11 +240,9 @@ static int pps_gpio_remove(struct platform_device *pdev)
struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
pps_unregister_source(data->pps);
- if (data->echo_pin) {
- del_timer_sync(&data->echo_timer);
- /* reset echo pin in any case */
- gpiod_set_value(data->echo_pin, 0);
- }
+ del_timer_sync(&data->echo_timer);
+ /* reset echo pin in any case */
+ gpiod_set_value(data->echo_pin, 0);
dev_info(&pdev->dev, "removed IRQ %d as PPS source\n", data->irq);
return 0;
}
--
2.30.1
Platform data is a legacy interface to supply device properties
to the driver. In this case we even don't have in-kernel users
for it. Just remove it for good.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pps/clients/pps-gpio.c | 17 +++--------------
include/linux/pps-gpio.h | 19 -------------------
2 files changed, 3 insertions(+), 33 deletions(-)
delete mode 100644 include/linux/pps-gpio.h
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index dc9ed6fc3dae..291240dce79e 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -16,7 +16,6 @@
#include <linux/platform_device.h>
#include <linux/slab.h>
#include <linux/pps_kernel.h>
-#include <linux/pps-gpio.h>
#include <linux/gpio/consumer.h>
#include <linux/list.h>
#include <linux/of_device.h>
@@ -164,7 +163,6 @@ static int pps_gpio_probe(struct platform_device *pdev)
struct pps_gpio_device_data *data;
int ret;
int pps_default_params;
- const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
/* allocate space for device info */
data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
@@ -173,18 +171,9 @@ static int pps_gpio_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, data);
/* GPIO setup */
- if (pdata) {
- data->gpio_pin = pdata->gpio_pin;
- data->echo_pin = pdata->echo_pin;
-
- data->assert_falling_edge = pdata->assert_falling_edge;
- data->capture_clear = pdata->capture_clear;
- data->echo_active_ms = pdata->echo_active_ms;
- } else {
- ret = pps_gpio_setup(pdev);
- if (ret)
- return -EINVAL;
- }
+ ret = pps_gpio_setup(pdev);
+ if (ret)
+ return -EINVAL;
/* IRQ setup */
ret = gpiod_to_irq(data->gpio_pin);
diff --git a/include/linux/pps-gpio.h b/include/linux/pps-gpio.h
deleted file mode 100644
index 7bf49908be06..000000000000
--- a/include/linux/pps-gpio.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-or-later */
-/*
- * pps-gpio.h -- PPS client for GPIOs
- *
- * Copyright (C) 2011 James Nuss <[email protected]>
- */
-
-#ifndef _PPS_GPIO_H
-#define _PPS_GPIO_H
-
-struct pps_gpio_platform_data {
- struct gpio_desc *gpio_pin;
- struct gpio_desc *echo_pin;
- bool assert_falling_edge;
- bool capture_clear;
- unsigned int echo_active_ms;
-};
-
-#endif /* _PPS_GPIO_H */
--
2.30.1
Rearrange optional stuff in pps_gpio_setup() so it will go after mandatory one
and with reduced indentation. This will increase readability of the sources.
Signed-off-by: Andy Shevchenko <[email protected]>
---
drivers/pps/clients/pps-gpio.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index b097da5a659a..35799e6401c9 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -110,28 +110,31 @@ static int pps_gpio_setup(struct device *dev)
return dev_err_probe(dev, PTR_ERR(data->gpio_pin),
"failed to request PPS GPIO\n");
+ data->assert_falling_edge =
+ device_property_read_bool(dev, "assert-falling-edge");
+
data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
if (IS_ERR(data->echo_pin))
return dev_err_probe(dev, PTR_ERR(data->echo_pin),
"failed to request ECHO GPIO\n");
- if (data->echo_pin) {
- ret = device_property_read_u32(dev, "echo-active-ms", &value);
- if (ret) {
- dev_err(dev, "failed to get echo-active-ms from FW\n");
- return ret;
- }
- data->echo_active_ms = value;
- /* sanity check on echo_active_ms */
- if (!data->echo_active_ms || data->echo_active_ms > 999) {
- dev_err(dev, "echo-active-ms: %u - bad value from FW\n",
- data->echo_active_ms);
- return -EINVAL;
- }
+ if (!data->echo_pin)
+ return 0;
+
+ ret = device_property_read_u32(dev, "echo-active-ms", &value);
+ if (ret) {
+ dev_err(dev, "failed to get echo-active-ms from FW\n");
+ return ret;
}
- data->assert_falling_edge =
- device_property_read_bool(dev, "assert-falling-edge");
+ /* sanity check on echo_active_ms */
+ if (!value || value > 999) {
+ dev_err(dev, "echo-active-ms: %u - bad value from FW\n", value);
+ return -EINVAL;
+ }
+
+ data->echo_active_ms = value;
+
return 0;
}
--
2.30.1
On 09/03/21 12:23, Andy Shevchenko wrote:
> When requesting optional GPIO echo line, bail out on error,
> so user will know that something wrong with the existing property.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/pps/clients/pps-gpio.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index e0de1df2ede0..f89c31aa66f1 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -119,12 +119,12 @@ static int pps_gpio_setup(struct platform_device *pdev)
> data->echo_pin = devm_gpiod_get_optional(&pdev->dev,
> "echo",
> GPIOD_OUT_LOW);
> - if (data->echo_pin) {
> - if (IS_ERR(data->echo_pin)) {
> - dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
> - return PTR_ERR(data->echo_pin);
> - }
> + if (IS_ERR(data->echo_pin)) {
> + dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
> + return PTR_ERR(data->echo_pin);
> + }
>
> + if (data->echo_pin) {
> ret = of_property_read_u32(np,
> "echo-active-ms",
> &value);
>
Acked-by: Rodolfo Giometti <[email protected]>
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On 09/03/21 12:23, Andy Shevchenko wrote:
> The timer along with GPIO API are NULL-aware, there is no need to test
> against existing GPIO echo line.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/pps/clients/pps-gpio.c | 8 +++-----
> 1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index 78c9680e8063..dc9ed6fc3dae 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -240,11 +240,9 @@ static int pps_gpio_remove(struct platform_device *pdev)
> struct pps_gpio_device_data *data = platform_get_drvdata(pdev);
>
> pps_unregister_source(data->pps);
> - if (data->echo_pin) {
> - del_timer_sync(&data->echo_timer);
> - /* reset echo pin in any case */
> - gpiod_set_value(data->echo_pin, 0);
> - }
> + del_timer_sync(&data->echo_timer);
> + /* reset echo pin in any case */
> + gpiod_set_value(data->echo_pin, 0);
> dev_info(&pdev->dev, "removed IRQ %d as PPS source\n", data->irq);
> return 0;
> }
>
Acked-by: Rodolfo Giometti <[email protected]>
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On 09/03/21 12:24, Andy Shevchenko wrote:
> Platform data is a legacy interface to supply device properties
> to the driver. In this case we even don't have in-kernel users
> for it. Just remove it for good.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/pps/clients/pps-gpio.c | 17 +++--------------
> include/linux/pps-gpio.h | 19 -------------------
> 2 files changed, 3 insertions(+), 33 deletions(-)
> delete mode 100644 include/linux/pps-gpio.h
>
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index dc9ed6fc3dae..291240dce79e 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -16,7 +16,6 @@
> #include <linux/platform_device.h>
> #include <linux/slab.h>
> #include <linux/pps_kernel.h>
> -#include <linux/pps-gpio.h>
> #include <linux/gpio/consumer.h>
> #include <linux/list.h>
> #include <linux/of_device.h>
> @@ -164,7 +163,6 @@ static int pps_gpio_probe(struct platform_device *pdev)
> struct pps_gpio_device_data *data;
> int ret;
> int pps_default_params;
> - const struct pps_gpio_platform_data *pdata = pdev->dev.platform_data;
>
> /* allocate space for device info */
> data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL);
> @@ -173,18 +171,9 @@ static int pps_gpio_probe(struct platform_device *pdev)
> platform_set_drvdata(pdev, data);
>
> /* GPIO setup */
> - if (pdata) {
> - data->gpio_pin = pdata->gpio_pin;
> - data->echo_pin = pdata->echo_pin;
> -
> - data->assert_falling_edge = pdata->assert_falling_edge;
> - data->capture_clear = pdata->capture_clear;
> - data->echo_active_ms = pdata->echo_active_ms;
> - } else {
> - ret = pps_gpio_setup(pdev);
> - if (ret)
> - return -EINVAL;
> - }
> + ret = pps_gpio_setup(pdev);
> + if (ret)
> + return -EINVAL;
>
> /* IRQ setup */
> ret = gpiod_to_irq(data->gpio_pin);
> diff --git a/include/linux/pps-gpio.h b/include/linux/pps-gpio.h
> deleted file mode 100644
> index 7bf49908be06..000000000000
> --- a/include/linux/pps-gpio.h
> +++ /dev/null
> @@ -1,19 +0,0 @@
> -/* SPDX-License-Identifier: GPL-2.0-or-later */
> -/*
> - * pps-gpio.h -- PPS client for GPIOs
> - *
> - * Copyright (C) 2011 James Nuss <[email protected]>
> - */
> -
> -#ifndef _PPS_GPIO_H
> -#define _PPS_GPIO_H
> -
> -struct pps_gpio_platform_data {
> - struct gpio_desc *gpio_pin;
> - struct gpio_desc *echo_pin;
> - bool assert_falling_edge;
> - bool capture_clear;
> - unsigned int echo_active_ms;
> -};
> -
> -#endif /* _PPS_GPIO_H */
>
Acked-by: Rodolfo Giometti <[email protected]>
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On 09/03/21 12:24, Andy Shevchenko wrote:
> Rearrange optional stuff in pps_gpio_setup() so it will go after mandatory one
> and with reduced indentation. This will increase readability of the sources.
>
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/pps/clients/pps-gpio.c | 33 ++++++++++++++++++---------------
> 1 file changed, 18 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index b097da5a659a..35799e6401c9 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -110,28 +110,31 @@ static int pps_gpio_setup(struct device *dev)
> return dev_err_probe(dev, PTR_ERR(data->gpio_pin),
> "failed to request PPS GPIO\n");
>
> + data->assert_falling_edge =
> + device_property_read_bool(dev, "assert-falling-edge");
> +
> data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
> if (IS_ERR(data->echo_pin))
> return dev_err_probe(dev, PTR_ERR(data->echo_pin),
> "failed to request ECHO GPIO\n");
>
> - if (data->echo_pin) {
> - ret = device_property_read_u32(dev, "echo-active-ms", &value);
> - if (ret) {
> - dev_err(dev, "failed to get echo-active-ms from FW\n");
> - return ret;
> - }
> - data->echo_active_ms = value;
> - /* sanity check on echo_active_ms */
> - if (!data->echo_active_ms || data->echo_active_ms > 999) {
> - dev_err(dev, "echo-active-ms: %u - bad value from FW\n",
> - data->echo_active_ms);
> - return -EINVAL;
> - }
> + if (!data->echo_pin)
> + return 0;
> +
> + ret = device_property_read_u32(dev, "echo-active-ms", &value);
> + if (ret) {
> + dev_err(dev, "failed to get echo-active-ms from FW\n");
> + return ret;
> }
>
> - data->assert_falling_edge =
> - device_property_read_bool(dev, "assert-falling-edge");
> + /* sanity check on echo_active_ms */
> + if (!value || value > 999) {
> + dev_err(dev, "echo-active-ms: %u - bad value from FW\n", value);
> + return -EINVAL;
> + }
> +
> + data->echo_active_ms = value;
> +
> return 0;
> }
>
>
Acked-by: Rodolfo Giometti <[email protected]>
--
GNU/Linux Solutions e-mail: [email protected]
Linux Device Driver [email protected]
Embedded Systems phone: +39 349 2432127
UNIX programming skype: rodolfo.giometti
On Tue, Mar 09, 2021 at 01:23:57PM +0200, Andy Shevchenko wrote:
> When requesting optional GPIO echo line, bail out on error,
> so user will know that something wrong with the existing property.
Greg, can you apply this series?
> Signed-off-by: Andy Shevchenko <[email protected]>
> ---
> drivers/pps/clients/pps-gpio.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
> index e0de1df2ede0..f89c31aa66f1 100644
> --- a/drivers/pps/clients/pps-gpio.c
> +++ b/drivers/pps/clients/pps-gpio.c
> @@ -119,12 +119,12 @@ static int pps_gpio_setup(struct platform_device *pdev)
> data->echo_pin = devm_gpiod_get_optional(&pdev->dev,
> "echo",
> GPIOD_OUT_LOW);
> - if (data->echo_pin) {
> - if (IS_ERR(data->echo_pin)) {
> - dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
> - return PTR_ERR(data->echo_pin);
> - }
> + if (IS_ERR(data->echo_pin)) {
> + dev_err(&pdev->dev, "failed to request ECHO GPIO\n");
> + return PTR_ERR(data->echo_pin);
> + }
>
> + if (data->echo_pin) {
> ret = of_property_read_u32(np,
> "echo-active-ms",
> &value);
> --
> 2.30.1
>
--
With Best Regards,
Andy Shevchenko