Lines Matching +full:echo +full:- +full:active +full:- +full:ms

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * pps-gpio.c -- PPS client driver using GPIO
9 #define PPS_GPIO_NAME "pps-gpio"
33 struct timer_list echo_timer; /* timer to reset echo active state */
36 unsigned int echo_active_ms; /* PPS echo active duration */
55 rising_edge = gpiod_get_value(info->gpio_pin); in pps_gpio_irq_handler()
56 if ((rising_edge && !info->assert_falling_edge) || in pps_gpio_irq_handler()
57 (!rising_edge && info->assert_falling_edge)) in pps_gpio_irq_handler()
58 pps_event(info->pps, &ts, PPS_CAPTUREASSERT, data); in pps_gpio_irq_handler()
59 else if (info->capture_clear && in pps_gpio_irq_handler()
60 ((rising_edge && info->assert_falling_edge) || in pps_gpio_irq_handler()
61 (!rising_edge && !info->assert_falling_edge))) in pps_gpio_irq_handler()
62 pps_event(info->pps, &ts, PPS_CAPTURECLEAR, data); in pps_gpio_irq_handler()
67 /* This function will only be called when an ECHO GPIO is defined */
70 /* add_timer() needs to write into info->echo_timer */ in pps_gpio_echo()
75 if (pps->params.mode & PPS_ECHOASSERT) in pps_gpio_echo()
76 gpiod_set_value(info->echo_pin, 1); in pps_gpio_echo()
80 if (pps->params.mode & PPS_ECHOCLEAR) in pps_gpio_echo()
81 gpiod_set_value(info->echo_pin, 1); in pps_gpio_echo()
86 if (info->pps->params.mode & (PPS_ECHOASSERT | PPS_ECHOCLEAR)) { in pps_gpio_echo()
87 info->echo_timer.expires = jiffies + info->echo_timeout; in pps_gpio_echo()
88 add_timer(&info->echo_timer); in pps_gpio_echo()
92 /* Timer callback to reset the echo pin to the inactive state */
99 gpiod_set_value(info->echo_pin, 0); in pps_gpio_echo_timer_callback()
108 data->gpio_pin = devm_gpiod_get(dev, NULL, GPIOD_IN); in pps_gpio_setup()
109 if (IS_ERR(data->gpio_pin)) in pps_gpio_setup()
110 return dev_err_probe(dev, PTR_ERR(data->gpio_pin), in pps_gpio_setup()
113 data->assert_falling_edge = in pps_gpio_setup()
114 device_property_read_bool(dev, "assert-falling-edge"); in pps_gpio_setup()
116 data->echo_pin = devm_gpiod_get_optional(dev, "echo", GPIOD_OUT_LOW); in pps_gpio_setup()
117 if (IS_ERR(data->echo_pin)) in pps_gpio_setup()
118 return dev_err_probe(dev, PTR_ERR(data->echo_pin), in pps_gpio_setup()
119 "failed to request ECHO GPIO\n"); in pps_gpio_setup()
121 if (!data->echo_pin) in pps_gpio_setup()
124 ret = device_property_read_u32(dev, "echo-active-ms", &value); in pps_gpio_setup()
126 dev_err(dev, "failed to get echo-active-ms from FW\n"); in pps_gpio_setup()
132 dev_err(dev, "echo-active-ms: %u - bad value from FW\n", value); in pps_gpio_setup()
133 return -EINVAL; in pps_gpio_setup()
136 data->echo_active_ms = value; in pps_gpio_setup()
144 unsigned long flags = data->assert_falling_edge ? in get_irqf_trigger_flags()
147 if (data->capture_clear) { in get_irqf_trigger_flags()
158 struct device *dev = &pdev->dev; in pps_gpio_probe()
165 return -ENOMEM; in pps_gpio_probe()
175 ret = gpiod_to_irq(data->gpio_pin); in pps_gpio_probe()
178 return -EINVAL; in pps_gpio_probe()
180 data->irq = ret; in pps_gpio_probe()
183 data->info.mode = PPS_CAPTUREASSERT | PPS_OFFSETASSERT | in pps_gpio_probe()
185 if (data->capture_clear) in pps_gpio_probe()
186 data->info.mode |= PPS_CAPTURECLEAR | PPS_OFFSETCLEAR | in pps_gpio_probe()
188 data->info.owner = THIS_MODULE; in pps_gpio_probe()
189 snprintf(data->info.name, PPS_MAX_NAME_LEN - 1, "%s.%d", in pps_gpio_probe()
190 pdev->name, pdev->id); in pps_gpio_probe()
191 if (data->echo_pin) { in pps_gpio_probe()
192 data->info.echo = pps_gpio_echo; in pps_gpio_probe()
193 data->echo_timeout = msecs_to_jiffies(data->echo_active_ms); in pps_gpio_probe()
194 timer_setup(&data->echo_timer, pps_gpio_echo_timer_callback, 0); in pps_gpio_probe()
199 if (data->capture_clear) in pps_gpio_probe()
201 data->pps = pps_register_source(&data->info, pps_default_params); in pps_gpio_probe()
202 if (IS_ERR(data->pps)) { in pps_gpio_probe()
204 data->irq); in pps_gpio_probe()
205 return PTR_ERR(data->pps); in pps_gpio_probe()
209 ret = devm_request_irq(dev, data->irq, pps_gpio_irq_handler, in pps_gpio_probe()
210 get_irqf_trigger_flags(data), data->info.name, data); in pps_gpio_probe()
212 pps_unregister_source(data->pps); in pps_gpio_probe()
213 dev_err(dev, "failed to acquire IRQ %d\n", data->irq); in pps_gpio_probe()
214 return -EINVAL; in pps_gpio_probe()
217 dev_info(data->pps->dev, "Registered IRQ %d as PPS source\n", in pps_gpio_probe()
218 data->irq); in pps_gpio_probe()
227 pps_unregister_source(data->pps); in pps_gpio_remove()
228 del_timer_sync(&data->echo_timer); in pps_gpio_remove()
229 /* reset echo pin in any case */ in pps_gpio_remove()
230 gpiod_set_value(data->echo_pin, 0); in pps_gpio_remove()
231 dev_info(&pdev->dev, "removed IRQ %d as PPS source\n", data->irq); in pps_gpio_remove()
235 { .compatible = "pps-gpio", },