[PATCH 5/5] pps: clients: gpio: enable pps pulse-width calculations based on device-tree

From: Eliav Farber
Date: Sun Jun 25 2023 - 10:21:46 EST


This change adds setting of PPS_WIDTHASSERT and PPS_WIDTHCLEAR modes to
enable PPS pulse-width calculation.

Width calculation will be enabled if
- assert-pulse-width
- clear-pulse-width
boolean properties exist in device-tree.

Signed-off-by: Eliav Farber <farbere@xxxxxxxxxx>
---
drivers/pps/clients/pps-gpio.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/pps/clients/pps-gpio.c b/drivers/pps/clients/pps-gpio.c
index a61dc1299ce9..ca4b8047e924 100644
--- a/drivers/pps/clients/pps-gpio.c
+++ b/drivers/pps/clients/pps-gpio.c
@@ -33,6 +33,8 @@ struct pps_gpio_device_data {
struct timer_list echo_timer; /* timer to reset echo active state */
bool assert_falling_edge;
bool capture_clear;
+ bool assert_pulse_width;
+ bool clear_pulse_width;
unsigned int echo_active_ms; /* PPS echo active duration */
unsigned long echo_timeout; /* timer timeout value in jiffies */
};
@@ -113,6 +115,10 @@ static int pps_gpio_setup(struct device *dev)
data->assert_falling_edge =
device_property_read_bool(dev, "assert-falling-edge");
data->capture_clear = device_property_read_bool(dev, "capture-clear");
+ data->assert_pulse_width =
+ device_property_read_bool(dev, "assert-pulse-width");
+ data->clear_pulse_width =
+ device_property_read_bool(dev, "clear-pulse-width");

data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW);
if (IS_ERR(data->echo_pin))
@@ -186,6 +192,10 @@ static int pps_gpio_probe(struct platform_device *pdev)
if (data->capture_clear)
data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR |
PPS_ECHOCLEAR;
+ if (data->assert_pulse_width)
+ data->info.mode |= PPS_WIDTHASSERT;
+ if (data->clear_pulse_width)
+ data->info.mode |= PPS_WIDTHCLEAR;
data->info.owner = THIS_MODULE;
snprintf(data->info.name, PPS_MAX_NAME_LEN - 1, "%s.%d",
pdev->name, pdev->id);
@@ -199,6 +209,10 @@ static int pps_gpio_probe(struct platform_device *pdev)
pps_default_params = PPS_CAPTUREASSERT | PPS_OFFSETASSERT;
if (data->capture_clear)
pps_default_params |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR;
+ if (data->assert_pulse_width)
+ pps_default_params |= PPS_WIDTHASSERT;
+ if (data->clear_pulse_width)
+ pps_default_params |= PPS_WIDTHCLEAR;
data->pps = pps_register_source(&data->info, pps_default_params);
if (IS_ERR(data->pps)) {
dev_err(dev, "failed to register IRQ %d as PPS source\n",
--
2.40.1