* [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support
@ 2026-07-16 17:35 Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 1/3] dt-bindings: vendor-prefixes: Add Cytron Technologies Paweł Wiśniewski
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Paweł Wiśniewski @ 2026-07-16 17:35 UTC (permalink / raw)
To: jic23
Cc: dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt, ak, linux-iio,
devicetree, linux-kernel
Add Device Tree binding and driver match support for the Cytron
HC-SR04 ultrasonic distance sensor.
The HC-SR04 uses separate trigger and echo GPIOs. A trigger pulse of
at least 10 us starts a measurement, and the echo pulse width reports
the ultrasonic round-trip time. This matches the protocol already
implemented by the SRF04 IIO driver.
The series adds the Cytron vendor prefix, documents the
cytron,hc-sr04 compatible, and uses the existing SRF04 configuration
in the driver.
The Cytron vendor attribution is based on the HC-SR04 Product User's
Manual V1.0 supplied by the retailer. The manual was prepared by
Cytron Technologies Sdn. Bhd. and contains Cytron warranty and
support information.
This is sent as an RFC because the vendor attribution and compatible
name should be reviewed.
Testing:
- make dt_binding_check: PASS
- srf04 module build: PASS
- Tested on Raspberry Pi 3 Model B+
- Kernel: 6.18.34+rpt-rpi-v8
- Device instantiated using only cytron,hc-sr04
- Trigger connected to GPIO17
- Echo connected to GPIO27 through a 5 V to 3.3 V resistor divider
- Driver bound and registered an IIO device
- in_distance_raw returned changing distance readings
Paweł Wiśniewski (3):
dt-bindings: vendor-prefixes: Add Cytron Technologies
dt-bindings: iio: proximity: Add Cytron HC-SR04
iio: proximity: srf04: Add Cytron HC-SR04 support
.../devicetree/bindings/iio/proximity/devantech-srf04.yaml | 5 ++++-
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
drivers/iio/proximity/Kconfig | 1 +
drivers/iio/proximity/srf04.c | 1 +
4 files changed, 8 insertions(+), 1 deletion(-)
base-commit: 37e2f878a7a660a216cc7a60459995fefd150f25
--
2.47.3
^ permalink raw reply [flat|nested] 7+ messages in thread
* [RFC PATCH 1/3] dt-bindings: vendor-prefixes: Add Cytron Technologies
2026-07-16 17:35 [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support Paweł Wiśniewski
@ 2026-07-16 17:35 ` Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04 Paweł Wiśniewski
` (2 subsequent siblings)
3 siblings, 0 replies; 7+ messages in thread
From: Paweł Wiśniewski @ 2026-07-16 17:35 UTC (permalink / raw)
To: jic23
Cc: dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt, ak, linux-iio,
devicetree, linux-kernel
Add a vendor prefix for Cytron Technologies Sdn. Bhd.
The prefix is used by the HC-SR04 ultrasonic ranging sensor binding.
Assisted-by: ChatGPT:GPT-5.6 Thinking
Signed-off-by: Paweł Wiśniewski <pawel.wis.me@gmail.com>
---
Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
1 file changed, 2 insertions(+)
diff --git a/Documentation/devicetree/bindings/vendor-prefixes.yaml b/Documentation/devicetree/bindings/vendor-prefixes.yaml
index 396044f368e7..cd4674569133 100644
--- a/Documentation/devicetree/bindings/vendor-prefixes.yaml
+++ b/Documentation/devicetree/bindings/vendor-prefixes.yaml
@@ -397,6 +397,8 @@ patternProperties:
description: CUI Devices
"^cypress,.*":
description: Cypress Semiconductor Corporation
+ "^cytron,.*":
+ description: Cytron Technologies Sdn. Bhd.
"^cyx,.*":
description: Shenzhen CYX Industrial Co., Ltd
"^cznic,.*":
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04
2026-07-16 17:35 [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 1/3] dt-bindings: vendor-prefixes: Add Cytron Technologies Paweł Wiśniewski
@ 2026-07-16 17:35 ` Paweł Wiśniewski
2026-07-16 17:45 ` sashiko-bot
2026-07-16 17:35 ` [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support Paweł Wiśniewski
2026-07-16 18:22 ` [RFC PATCH 0/3] iio: proximity: " Andy Shevchenko
3 siblings, 1 reply; 7+ messages in thread
From: Paweł Wiśniewski @ 2026-07-16 17:35 UTC (permalink / raw)
To: jic23
Cc: dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt, ak, linux-iio,
devicetree, linux-kernel
The Cytron HC-SR04 starts a ranging cycle with an active-high trigger
pulse of at least 10 us and reports the acoustic round-trip time as
the width of an active-high echo pulse.
Add the cytron,hc-sr04 compatible and a reference to the product
manual. Update the trigger GPIO description to account for the pulse
durations used by the supported devices.
The interface matches the two-GPIO protocol implemented by the
existing SRF04 driver.
Assisted-by: ChatGPT:GPT-5.6 Thinking
Signed-off-by: Paweł Wiśniewski <pawel.wis.me@gmail.com>
---
.../devicetree/bindings/iio/proximity/devantech-srf04.yaml | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml b/Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml
index ce795279839e..f4237ae612ab 100644
--- a/Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml
+++ b/Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml
@@ -4,7 +4,7 @@
$id: http://devicetree.org/schemas/iio/proximity/devantech-srf04.yaml#
$schema: http://devicetree.org/meta-schemas/core.yaml#
-title: Devantech SRF04 and Maxbotix mb1000 ultrasonic range finder
+title: Devantech SRF04 and Maxbotix mb1000 and Cytron HC-SR04 ultrasonic range finder
maintainers:
- Andreas Klinger <ak@it-klinger.de>
@@ -21,9 +21,12 @@ description: |
https://www.maxbotix.com/documents/LV-MaxSonar-EZ_Datasheet.pdf
+ https://botland.com.pl/index.php?controller=attachment&id_attachment=476
+
properties:
compatible:
enum:
+ - cytron,hc-sr04
- devantech,srf04
- maxbotix,mb1000
- maxbotix,mb1010
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support
2026-07-16 17:35 [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 1/3] dt-bindings: vendor-prefixes: Add Cytron Technologies Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04 Paweł Wiśniewski
@ 2026-07-16 17:35 ` Paweł Wiśniewski
2026-07-16 17:46 ` sashiko-bot
2026-07-16 18:22 ` [RFC PATCH 0/3] iio: proximity: " Andy Shevchenko
3 siblings, 1 reply; 7+ messages in thread
From: Paweł Wiśniewski @ 2026-07-16 17:35 UTC (permalink / raw)
To: jic23
Cc: dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt, ak, linux-iio,
devicetree, linux-kernel
Tested on a Raspberry Pi 3 Model B+ running
6.18.34+rpt-rpi-v8. The sensor was instantiated using only the
cytron,hc-sr04 compatible, with trigger connected to GPIO17 and echo
connected to GPIO27 through a 5 V to 3.3 V resistor divider. The
driver bound to the device, registered an IIO device, and returned
changing distance readings through in_distance_raw.
Assisted-by: ChatGPT:GPT-5.6 Thinking
Signed-off-by: Paweł Wiśniewski <pawel.wis.me@gmail.com>
---
drivers/iio/proximity/Kconfig | 1 +
drivers/iio/proximity/srf04.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/iio/proximity/Kconfig b/drivers/iio/proximity/Kconfig
index bb77fad2a1b3..89e9d57ceba6 100644
--- a/drivers/iio/proximity/Kconfig
+++ b/drivers/iio/proximity/Kconfig
@@ -139,6 +139,7 @@ config SRF04
ranger sensor. This driver can be used to measure the distance
of objects. It is using two GPIOs.
Actually Supported types are:
+ - Cytron HC-SR04
- Devantech SRF04
- Maxbotix mb1000
- Maxbotix mb1010
diff --git a/drivers/iio/proximity/srf04.c b/drivers/iio/proximity/srf04.c
index 7be50bdebfcb..f5ee7d6572b5 100644
--- a/drivers/iio/proximity/srf04.c
+++ b/drivers/iio/proximity/srf04.c
@@ -231,6 +231,7 @@ static const struct iio_chan_spec srf04_chan_spec[] = {
};
static const struct of_device_id of_srf04_match[] = {
+ { .compatible = "cytron,hc-sr04", .data = &srf04_cfg },
{ .compatible = "devantech,srf04", .data = &srf04_cfg },
{ .compatible = "maxbotix,mb1000", .data = &mb_lv_cfg },
{ .compatible = "maxbotix,mb1010", .data = &mb_lv_cfg },
--
2.47.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04
2026-07-16 17:35 ` [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04 Paweł Wiśniewski
@ 2026-07-16 17:45 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-16 17:45 UTC (permalink / raw)
To: Paweł Wiśniewski; +Cc: conor+dt, devicetree, robh
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The commit message claims to update the trigger GPIO description, but the patch does not actually modify it.
--
--- Patch [2]: [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04 ---
commit 319a9ebb7272df447013bc727d4e781b829dfcb0
Author: Paweł Wiśniewski <pawel.wis.me@gmail.com>
dt-bindings: iio: proximity: Add Cytron HC-SR04
This commit documents the Cytron HC-SR04 ultrasonic range finder by adding
the cytron,hc-sr04 compatible string and a reference link to the existing
devantech-srf04 binding.
> Add the cytron,hc-sr04 compatible and a reference to the product
> manual. Update the trigger GPIO description to account for the pulse
> durations used by the supported devices.
[Severity: Medium]
The commit message mentions an update to the trigger GPIO description to
account for pulse durations used by the supported devices, but the patch
does not appear to modify the trig-gpios property in the
Documentation/devicetree/bindings/iio/proximity/devantech-srf04.yaml file.
Was this documentation change accidentally omitted from the diff?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784221074.git.pawel.wis.me@gmail.com?part=2
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support
2026-07-16 17:35 ` [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support Paweł Wiśniewski
@ 2026-07-16 17:46 ` sashiko-bot
0 siblings, 0 replies; 7+ messages in thread
From: sashiko-bot @ 2026-07-16 17:46 UTC (permalink / raw)
To: Paweł Wiśniewski; +Cc: robh, devicetree, conor+dt
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues:
- [High] Unchecked return value from `device_get_match_data()` can cause a NULL pointer dereference.
- [High] Interrupt handler may miss the rising edge of the echo pulse due to interrupt latency.
--
--- Patch [3]: [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support ---
commit e27499a683a294e308b2d89b6fa06d4fd87a1cef
Author: Paweł Wiśniewski <pawel.wis.me@gmail.com>
iio: proximity: srf04: Add Cytron HC-SR04 support
This commit adds support for the Cytron HC-SR04 sensor to the srf04 driver.
It introduces the new compatible string "cytron,hc-sr04" and updates the
Kconfig to list the supported device.
> diff --git a/drivers/iio/proximity/srf04.c b/drivers/iio/proximity/srf04.c
> index 7be50bdebfcbc..f5ee7d6572b5b 100644
> --- a/drivers/iio/proximity/srf04.c
> +++ b/drivers/iio/proximity/srf04.c
[ ... ]
> @@ -231,6 +231,7 @@ static const struct iio_chan_spec srf04_chan_spec[] = {
> };
>
> static const struct of_device_id of_srf04_match[] = {
> + { .compatible = "cytron,hc-sr04", .data = &srf04_cfg },
[Severity: High]
This is a pre-existing issue, and was not introduced by the patch under
review, but could the unchecked return value from device_get_match_data()
cause a NULL pointer dereference?
In drivers/iio/proximity/srf04.c:srf04_probe(), the return value is assigned
without validation:
data->cfg = device_get_match_data(dev);
If the driver is instantiated via legacy platform device registration,
device_get_match_data() will return NULL. Later, in srf04_read(), this could
be dereferenced:
udelay(data->cfg->trigger_pulse_us);
Can this result in a kernel panic when a user reads from the IIO device?
[Severity: High]
This is a pre-existing issue, and was not introduced by the patch under
review, but could the interrupt handler miss the rising edge of the echo
pulse due to interrupt latency?
In drivers/iio/proximity/srf04.c:srf04_handle_irq(), the handler relies on
the live GPIO state:
if (gpiod_get_value(data->gpiod_echo)) {
If an object is close, the echo pulse is very short. If the system's
interrupt latency exceeds this duration, the GPIO will already have
transitioned back to low by the time the handler executes for the rising
edge. The handler will read low, complete the falling completion, and
ignore the rising edge.
This would cause the read operation to time out and fail in srf04_read():
ret = wait_for_completion_killable_timeout(&data->rising, HZ/50);
Could this cause the sensor to consistently fail to measure short distances
and return -ETIMEDOUT to userspace?
> { .compatible = "devantech,srf04", .data = &srf04_cfg },
> { .compatible = "maxbotix,mb1000", .data = &mb_lv_cfg },
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1784221074.git.pawel.wis.me@gmail.com?part=3
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support
2026-07-16 17:35 [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support Paweł Wiśniewski
` (2 preceding siblings ...)
2026-07-16 17:35 ` [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support Paweł Wiśniewski
@ 2026-07-16 18:22 ` Andy Shevchenko
3 siblings, 0 replies; 7+ messages in thread
From: Andy Shevchenko @ 2026-07-16 18:22 UTC (permalink / raw)
To: Paweł Wiśniewski
Cc: jic23, dlechner, nuno.sa, andy, robh, krzk+dt, conor+dt, ak,
linux-iio, devicetree, linux-kernel
On Thu, Jul 16, 2026 at 07:35:53PM +0200, Paweł Wiśniewski wrote:
> Add Device Tree binding and driver match support for the Cytron
> HC-SR04 ultrasonic distance sensor.
>
> The HC-SR04 uses separate trigger and echo GPIOs. A trigger pulse of
> at least 10 us starts a measurement, and the echo pulse width reports
> the ultrasonic round-trip time. This matches the protocol already
> implemented by the SRF04 IIO driver.
>
> The series adds the Cytron vendor prefix, documents the
> cytron,hc-sr04 compatible, and uses the existing SRF04 configuration
> in the driver.
>
> The Cytron vendor attribution is based on the HC-SR04 Product User's
> Manual V1.0 supplied by the retailer. The manual was prepared by
> Cytron Technologies Sdn. Bhd. and contains Cytron warranty and
> support information.
> This is sent as an RFC because the vendor attribution and compatible
> name should be reviewed.
But it's normal process, no? In any case the code in the driver is fine.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-07-16 18:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-16 17:35 [RFC PATCH 0/3] iio: proximity: Add Cytron HC-SR04 support Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 1/3] dt-bindings: vendor-prefixes: Add Cytron Technologies Paweł Wiśniewski
2026-07-16 17:35 ` [RFC PATCH 2/3] dt-bindings: iio: proximity: Add Cytron HC-SR04 Paweł Wiśniewski
2026-07-16 17:45 ` sashiko-bot
2026-07-16 17:35 ` [RFC PATCH 3/3] iio: proximity: srf04: Add Cytron HC-SR04 support Paweł Wiśniewski
2026-07-16 17:46 ` sashiko-bot
2026-07-16 18:22 ` [RFC PATCH 0/3] iio: proximity: " Andy Shevchenko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox