Skip to contentSkip to conversation

w1: add UART w1 bus driver

PATCH Superseded Christoph Winklhofer 4 participants 18 messages Jan 6, 2024 – Jan 16, 2024

Subsystems (5)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v4 cover w1: add UART w1 bus driver

Hello!

This patch contains a driver for a 1-Wire bus over UART. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns.

Changes in v4:
- rework baud-rate configuration: also check max bit-time, support higher baud-rates by adding a delay to complete 1-Wire cycle.
- dt-binding w1-uart: specify baud-rates for 1-Wire operations
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in v3:
- improve baud-rate configuration: use specific limits for 1-Wire
reset, touch-0 and touch-1 operation, compute in nanoseconds.
- remove unused header atomic.h
- use function instead of macro to compute bit-time from baud-rate
- switch to b4 util to publish patch: missing recipients
- Link to v2: https://lore.kernel.org/lkml/[email protected]

Changes in v2:
- add documentation for dt-binding
- allow onewire as serial child node
- support different baud-rates: The driver requests a baud-rate (9600
for reset and 115200 for write/read) and tries to adapt the
transmitted byte according to the actual baud-rate returned from
serdev.
- fix locking problem for serdev-receive and w1-master reset/touch: The received byte is now protected with a mutex - instead of the atomic, which was used before due to the concurrent store and load.
- explicit error in serdev-receive: Receiving more than one byte results in an error, since the w1-uart driver is the only writer, it writes a single-byte and should receive a single byte.
- fix variable names, errno-returns, wrong define CONFIG_OF
- fix log flooding
- fix driver remove (error-path for rxtx-function)
- Link to v1: https://lore.kernel.org/all/[email protected]
Krzysztof, thank your very much for your feedback!

It was tested on a "Raspberry Pi 3 Model B+" with a DS18B20 and on a "Variscite DART-6UL" with a DS18S20 temperature sensor.

Content:
- Patch 1: device tree binding 1-Wire
- Patch 2: allow onewire as serial child node
- Patch 3: driver and documentation

The patch was created against the w1 subsytem tree (branch w1-next):

The checkpatch.pl script reported the following error - which I am not sure how to fix:
WARNING: added, moved or deleted file(s), does MAINTAINERS need updating?

The technical details for 1-Wire over UART are in the document:

In short, the UART peripheral must support full-duplex and operate in
open-drain mode. The timing patterns are generated by a specific combination of baud-rate and transmitted byte, which corresponds to a 1-Wire read bit, write bit or reset pulse.

For instance the timing pattern for a 1-Wire reset and presence detect uses the baud-rate 9600, i.e. 104.2 us per bit. The transmitted byte 0xf0 over UART (least significant bit first, start-bit low) sets the reset low time for 1-Wire to 521 us. A present 1-Wire device changes the received byte by pulling the line low, which is used by the driver to evaluate the result of the 1-Wire operation.

Similar for a 1-Wire read bit or write bit, which uses the baud-rate 115200, i.e. 8.7 us per bit. The transmitted byte 0x00 is used for a Write-0 operation and the byte 0xff for Read-0, Read-1 and Write-1.

Hope the driver is helpful.

Thanks,
Christoph

Christoph Winklhofer (3):
dt-bindings: w1: UART 1-Wire bus
dt-bindings: serial: allow onewire as child node
w1: add UART w1 bus driver

 .../devicetree/bindings/serial/serial.yaml    |   2 +-
 .../devicetree/bindings/w1/w1-uart.yaml       |  44 +++
 Documentation/w1/masters/index.rst            |   1 +
 Documentation/w1/masters/w1-uart.rst          |  53 +++
 drivers/w1/masters/Kconfig                    |  10 +
 drivers/w1/masters/Makefile                   |   1 +
 drivers/w1/masters/w1-uart.c                  | 307 ++++++++++++++++++
 7 files changed, 417 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/w1/w1-uart.yaml
 create mode 100644 Documentation/w1/masters/w1-uart.rst
 create mode 100644 drivers/w1/masters/w1-uart.c

--
2.43.0

base-commit: efc19c44aa442197ddcbb157c6ca54a56eba8c4e
---
Christoph Winklhofer (3):
dt-bindings: w1: UART 1-Wire bus
dt-bindings: serial: allow onewire as child node
w1: add UART w1 bus driver

 .../devicetree/bindings/serial/serial.yaml         |   2 +-
 Documentation/devicetree/bindings/w1/w1-uart.yaml  |  62 ++++
 Documentation/w1/masters/index.rst                 |   1 +
 Documentation/w1/masters/w1-uart.rst               |  54 +++
 drivers/w1/masters/Kconfig                         |  10 +
 drivers/w1/masters/Makefile                        |   1 +
 drivers/w1/masters/w1-uart.c                       | 398 +++++++++++++++++++++
 7 files changed, 527 insertions(+), 1 deletion(-)

---
base-commit: efc19c44aa442197ddcbb157c6ca54a56eba8c4e
change-id: 20240104-w1-uart-ee8685a15a50

Best regards,

Signature · 1 line
Christoph Winklhofer <[email protected]>
#1 lore raw

PATCH v4 1/3 dt-bindings: w1: UART 1-Wire bus

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +62 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: UART 1-Wire Bus
+
+maintainers:
+  - Christoph Winklhofer <[email protected]>
+
+description: |
+  UART 1-wire bus. Utilizes the UART interface via the Serial Device Bus
+  to create the 1-Wire timing patterns.
+
+  The UART peripheral must support full-duplex and operate in open-drain
+  mode. The timing patterns are generated by a specific combination of
+  baud-rate and transmitted byte, which corresponds to a 1-Wire read bit,
+  write bit or reset pulse.
+
+  The default baud-rate for reset and presence detection is 9600 and for
+  a 1-Wire read or write operation 115200. In case the actual baud-rate
+  is different from the requested one, the transmitted byte is adapted
+  to generate the 1-Wire timing patterns.
+
+  https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html
+
+
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-0 cycle (touch bit 0).
+
+  touch_1-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-1 and read cycle (touch bit 1).
+
+required:
+  - compatible
+
+additionalProperties: false
+
+examples:
+  - |
+    serial {
+      onewire {
+        compatible = "w1-uart";
+      };
+    };
Signature · 1 line
2.43.0
maintainer
#2 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 39 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +26 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: UART 1-Wire Bus
+
+maintainers:
+  - Christoph Winklhofer <[email protected]>
+
+description: |
+  UART 1-wire bus. Utilizes the UART interface via the Serial Device Bus
+  to create the 1-Wire timing patterns.
+
+  The UART peripheral must support full-duplex and operate in open-drain
+  mode. The timing patterns are generated by a specific combination of
+  baud-rate and transmitted byte, which corresponds to a 1-Wire read bit,
+  write bit or reset pulse.
+
+  The default baud-rate for reset and presence detection is 9600 and for
+  a 1-Wire read or write operation 115200. In case the actual baud-rate
+  is different from the requested one, the transmitted byte is adapted
+  to generate the 1-Wire timing patterns.
+
+  https://www.analog.com/en/technical-articles/using-a-uart-to-implement-a-1wire-bus-master.html

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 10 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +10 -0
+
+
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

Quoted 5 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-0 cycle (touch bit 0).
+

Documentation/devicetree/bindings/w1/w1-uart.yaml line 54

Quoted 10 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +10 -0
+  touch_1-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-1 and read cycle (touch bit 1).
+
+required:
+  - compatible
+
+additionalProperties: false

w1.txt says there can be a child node for the 1-wire device. You need 'type: object'. Or w1.txt needs to be converted to schema and referenced here (along with using unevaluatedProperties here instead).

Rob

#3 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Quoted 20 lines
Quoted 5 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-0 cycle (touch bit 0).
+

Documentation/devicetree/bindings/w1/w1-uart.yaml line 54

Quoted 10 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +10 -0
+  touch_1-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-1 and read cycle (touch bit 1).
+
+required:
+  - compatible
+
+additionalProperties: false

w1.txt says there can be a child node for the 1-wire device. You need 'type: object'. Or w1.txt needs to be converted to schema and referenced here (along with using unevaluatedProperties here instead).

Quoted 1 line

Rob

Will change it to type object. However, I also tried to convert w1.txt to w1.yaml - I am not quite sure, so I add an excerpt of my attempt. The example in w1.txt builds fine. Is oneOf allowed as a top-level property, the documentation only mentions allOf?
Only one child should be allowed, but I did not find a way to restrict this.

# w1-uart.yaml:
unevaluatedProperties:
$ref: w1.yaml

# w1.yaml:
properties:
compatible:
enum:
- maxim,ds2760

oneOf:
- $ref: /schemas/power/supply/maxim,ds2760.yaml

unevaluatedProperties: false
#

Thank you for the review!

Kind regards,
Christoph

#4 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 46 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

Quoted 7 lines

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

Quoted 34 lines
Quoted 21 lines
Quoted 6 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-0 cycle (touch bit 0).
+

Documentation/devicetree/bindings/w1/w1-uart.yaml line 54

Quoted 10 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +10 -0
+  touch_1-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-1 and read cycle (touch bit 1).
+
+required:
+  - compatible
+
+additionalProperties: false

w1.txt says there can be a child node for the 1-wire device. You need 'type: object'. Or w1.txt needs to be converted to schema and referenced here (along with using unevaluatedProperties here instead).

Quoted 1 line

Rob

Will change it to type object. However, I also tried to convert w1.txt to w1.yaml - I am not quite sure, so I add an excerpt of my attempt. The example in w1.txt builds fine. Is oneOf allowed as a top-level property, the documentation only mentions allOf?
Only one child should be allowed, but I did not find a way to restrict this.

# w1-uart.yaml:
unevaluatedProperties:
$ref: w1.yaml

Quoted 5 lines

# w1.yaml:
properties:
compatible:
enum:
- maxim,ds2760

w1 describes entire class of the devices, so it should not have compatibles. Look how other buses do it.

Quoted 5 lines

oneOf:
- $ref: /schemas/power/supply/maxim,ds2760.yaml

unevaluatedProperties: false

Best regards,
Krzysztof

#5 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 51 lines · Krzysztof Kozlowski
Quoted 50 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

Quoted 7 lines
Quoted 3 lines

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

The serial.yaml uses prefix -speed for the baud rate but I can change it to -bps.

Quoted 35 lines
Quoted 35 lines
Quoted 22 lines
Quoted 7 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-0 cycle (touch bit 0).
+

Documentation/devicetree/bindings/w1/w1-uart.yaml line 54

Quoted 10 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +10 -0
+  touch_1-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 115200
+    description: |
+      The baud rate for the 1-Wire write-1 and read cycle (touch bit 1).
+
+required:
+  - compatible
+
+additionalProperties: false

w1.txt says there can be a child node for the 1-wire device. You need 'type: object'. Or w1.txt needs to be converted to schema and referenced here (along with using unevaluatedProperties here instead).

Quoted 1 line

Rob

Will change it to type object. However, I also tried to convert w1.txt to w1.yaml - I am not quite sure, so I add an excerpt of my attempt. The example in w1.txt builds fine. Is oneOf allowed as a top-level property, the documentation only mentions allOf?
Only one child should be allowed, but I did not find a way to restrict this.

# w1-uart.yaml:
unevaluatedProperties:
$ref: w1.yaml

Quoted 8 lines
Quoted 5 lines

# w1.yaml:
properties:
compatible:
enum:
- maxim,ds2760

w1 describes entire class of the devices, so it should not have compatibles. Look how other buses do it.

Thanks for the hint, looked at serial.yaml and usb.yaml. Hence w1.yaml should describe the properties common to all w1 bus controllers (property for child device) and w1-uart.yaml references it in allOf, like:

# w1.yaml
patternProperties:
  ".*":
    if:
      type: object
    then:
      description: Devices are listed...
      properties:
	compatible:
      required:
	- compatible
additionalProperties: true
# w1-uart.yaml
allOf:
 - $ref: w1.yaml#
unevaluatedProperties: false

Kind regards,
Christoph

#6 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 57 lines · Christoph Winklhofer
Quoted 56 lines · Krzysztof Kozlowski
Quoted 53 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Quoted 5 lines
Quoted 2 lines

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

The serial.yaml uses prefix -speed for the baud rate but I can change it to -bps.

Do you reference serial.yaml?

Quoted 1 line

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 58 lines · Krzysztof Kozlowski
Quoted 57 lines · Christoph Winklhofer
Quoted 56 lines · Krzysztof Kozlowski
Quoted 53 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 36

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml line 39

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

The serial.yaml uses prefix -speed for the baud rate but I can change it to -bps.

Do you reference serial.yaml?

No, serial.yaml is not referenced but 'onewire' will be a child-node of a serial-device which already defines baud rate related properties with -speed (e.g. max-speed although not used in w1-uart). Hence, I thought -speed is typically used for baud rates.

Thanks,
Christoph

#8 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 65 lines · Christoph Winklhofer
Quoted 64 lines · Krzysztof Kozlowski
Quoted 62 lines · Christoph Winklhofer
Quoted 51 lines · Krzysztof Kozlowski
Quoted 50 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

Quoted 7 lines
Quoted 3 lines

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

The serial.yaml uses prefix -speed for the baud rate but I can change it to -bps.

Quoted 7 lines
Quoted 2 lines

Do you reference serial.yaml?

No, serial.yaml is not referenced but 'onewire' will be a child-node of a serial-device which already defines baud rate related properties with -speed (e.g. max-speed although not used in w1-uart). Hence, I thought -speed is typically used for baud rates.

Ah, it defines max-speed for childre, so for onewire. Re-using that property would make sense, but since you are defining completely new properties, let's use proper (-bps) naming.

I still wonder, why would you use different baud rates for these three different operations?

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v4 1/3] dt-bindings: w1: UART 1-Wire bus

Quoted 69 lines · Krzysztof Kozlowski
Quoted 68 lines · Christoph Winklhofer
Quoted 66 lines · Krzysztof Kozlowski
Quoted 57 lines · Christoph Winklhofer
Quoted 56 lines · Krzysztof Kozlowski
Quoted 53 lines · Christoph Winklhofer
Quoted 19 lines · Rob Herring
Quoted 18 lines · Christoph Winklhofer

Add device tree binding for UART 1-Wire bus.

---
 Documentation/devicetree/bindings/w1/w1-uart.yaml | 62 +++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +5 -0
new file mode 100644
index 000000000000..6b90693b2ca0
@@ -0,0 +1,62 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/w1/w1-uart.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

...

Quoted 11 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml

Quoted 8 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +8 -0
+properties:
+  compatible:
+    const: w1-uart
+
+  reset-speed:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    default: 9600
+    description: |

Don't need '|' if no formatting

Ok.

Quoted 10 lines

Documentation/devicetree/bindings/w1/w1-uart.yaml

Quoted 3 lines
Documentation/devicetree/bindings/w1/w1-uart.yaml new file +3 -0
+      The baud rate for the 1-Wire reset and presence detect.
+
+  touch_0-speed:

Don't use '_' in property names.

I'm somewhat familar with 1-wire, but I don't get what 'touch' means here. I assume these are low and high times which are a function of the baudrate.

I change the name to 'write-0-speed' and 'write-1-speed'. The function in the w1-framework is named 'touch_bit' - therefore the previous naming.

It is the baud-rate used in the 1-Wire cycle to write a 0-Bit (write-0-speed) and to perform a 1-Wire cycle that writes a 1-Bit and reads a 0-Bit or 1-Bit (write-1-speed).

Quoted 5 lines
Quoted 2 lines

Then probably -bps:
https://github.com/devicetree-org/dt-schema/blob/main/dtschema/schemas/property-units.yaml

The serial.yaml uses prefix -speed for the baud rate but I can change it to -bps.

Do you reference serial.yaml?

Quoted 9 lines
Quoted 4 lines

No, serial.yaml is not referenced but 'onewire' will be a child-node of a serial-device which already defines baud rate related properties with -speed (e.g. max-speed although not used in w1-uart). Hence, I thought -speed is typically used for baud rates.

Ah, it defines max-speed for childre, so for onewire. Re-using that property would make sense, but since you are defining completely new properties, let's use proper (-bps) naming.

Ok.

Quoted 2 lines

I still wonder, why would you use different baud rates for these three different operations?

The timing for the pulse on the 1-Wire bus, to perform a 1-Wire reset or read/write is too different to use the same baud rate for them. The pulse can only be generated with the transmission of a single byte (to initiate the operation and to evaluate the response), since every UART packet starts low and ends high, only a limited set of baud rates are possible.

Read-0/1 and Write-1 have the same low-time and therefore share the same baud rate setting, actually this baud could be higher. Otherwise, for Write-0 the maximum baud-rate is somewhere near 115200.

The table lists the low-time range for the 1-Wire standard speed (overdrive is currently not implemented by the driver):

Operation | Low-Time (usec) | Baud rate (default)
----------+-----------------+--------------------

  Reset     | 480 - 640       | 9600
  Read-0/1  |   5 -  15       | 115200
  Write-1   |   5 -  15       | 115200
  Write-0   |  60 - 120       | 115200

I thought it makes sense to have the option to overwrite the default baud rates. Alternatively, the driver could probe a fixed set of different baud rates that are able to generate the timing patterns. Initially, the driver always used 9600 and 115200 - however some UART devices may not support these bauds. Now the driver requests a baud rate and checks if it can create the timing pattern with the returned one.

Kind regards,
Christoph

#10 lore raw

PATCH v4 2/3 dt-bindings: serial: allow onewire as child node

In reply to Christoph Winklhofer

The UART 1-Wire bus utilizes the Serial Device Bus to create the 1-wire timing patterns.

---
 Documentation/devicetree/bindings/serial/serial.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/devicetree/bindings/serial/serial.yaml +1 -1
index 65804ca274ae..ffc9198ae214 100644
@@ -88,7 +88,7 @@ properties:
       TX FIFO threshold configuration (in bytes).
 
 patternProperties:
-  "^(bluetooth|bluetooth-gnss|gnss|gps|mcu)$":
+  "^(bluetooth|bluetooth-gnss|gnss|gps|mcu|onewire)$":
     if:
       type: object
     then:
Signature · 1 line
2.43.0
maintainer Acked-by on v4 2/3
#11 lore raw

Re: [PATCH v4 2/3] dt-bindings: serial: allow onewire as child node

Quoted 8 lines · Christoph Winklhofer

The UART 1-Wire bus utilizes the Serial Device Bus to create the 1-wire timing patterns.

---
 Documentation/devicetree/bindings/serial/serial.yaml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
#12 lore raw

PATCH v4 3/3 w1: add UART w1 bus driver

In reply to Christoph Winklhofer

Add a UART 1-Wire bus driver. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns. The driver was tested on a "Raspberry Pi 3B" with a DS18B20 and on a "Variscite DART-6UL" with a DS18S20 temperature sensor.

The 1-Wire timing pattern and the corresponding UART baud-rate with the interpretation of the transferred bytes are described in the document:

In short, the UART peripheral must support full-duplex and operate in open-drain mode. The timing patterns are generated by a specific combination of baud-rate and transmitted byte, which corresponds to a 1-Wire read bit, write bit or reset.

---
 Documentation/w1/masters/index.rst   |   1 +
 Documentation/w1/masters/w1-uart.rst |  54 +++++
 drivers/w1/masters/Kconfig           |  10 +
 drivers/w1/masters/Makefile          |   1 +
 drivers/w1/masters/w1-uart.c         | 398 +++++++++++++++++++++++++++++++++++
 5 files changed, 464 insertions(+)
Documentation/w1/masters/index.rst +1 -0
index 4442a98850ad..cc40189909fd 100644
@@ -12,3 +12,4 @@
    mxc-w1
    omap-hdq
    w1-gpio
+   w1-uart
Documentation/w1/masters/w1-uart.rst new file +54 -0

54 lines not on this page · raw message

drivers/w1/masters/Kconfig +10 -0
index 513c0b114337..e6049a75b35b 100644
@@ -78,5 +78,15 @@ config W1_MASTER_SGI
 	  This support is also available as a module.  If so, the module
 	  will be called sgi_w1.
 
+config W1_MASTER_UART
+	tristate "UART 1-wire driver"
+	depends on SERIAL_DEV_BUS
+	help
+	  Say Y here if you want to communicate with your 1-wire devices using
+	  UART interface.
+
+	  This support is also available as a module.  If so, the module
+	  will be called w1-uart.
+
 endmenu
 
drivers/w1/masters/Makefile +1 -0
index 6c5a21f9b88c..227f80987e69 100644
@@ -12,3 +12,4 @@ obj-$(CONFIG_W1_MASTER_MXC)		+= mxc_w1.o
 obj-$(CONFIG_W1_MASTER_GPIO)		+= w1-gpio.o
 obj-$(CONFIG_HDQ_MASTER_OMAP)		+= omap_hdq.o
 obj-$(CONFIG_W1_MASTER_SGI)		+= sgi_w1.o
+obj-$(CONFIG_W1_MASTER_UART)		+= w1-uart.o
drivers/w1/masters/w1-uart.c new file +398 -0

398 lines not on this page · raw message

Signature · 1 line
2.43.0
maintainer
#13 lore raw
Quoted 16 lines · On 06. 01. 24, 17:02, Christoph Winklhofer via B4 Relay wrote:

From: Christoph Winklhofer <[email protected]>

Add a UART 1-Wire bus driver. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns. The driver was tested on a "Raspberry Pi 3B" with a DS18B20 and on a "Variscite DART-6UL" with a DS18S20 temperature sensor.

The 1-Wire timing pattern and the corresponding UART baud-rate with the interpretation of the transferred bytes are described in the document:

In short, the UART peripheral must support full-duplex and operate in open-drain mode. The timing patterns are generated by a specific combination of baud-rate and transmitted byte, which corresponds to a 1-Wire read bit, write bit or reset.

...

Quoted 29 lines
drivers/w1/masters/w1-uart.c new file +26 -0
@@ -0,0 +1,398 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * w1-uart - UART 1-Wire bus driver
+ *
+ * Uses the UART interface (via Serial Device Bus) to create the 1-Wire
+ * timing patterns. Implements the following 1-Wire master interface:
+ *
+ * - reset_bus: requests baud-rate 9600
+ *
+ * - touch_bit: requests baud-rate 115200
+ *
+ * Author: Christoph Winklhofer <[email protected]>
+ */
+
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
+#include <linux/w1.h>
+
+#define W1_UART_TIMEOUT msecs_to_jiffies(500)
+
+/*

drivers/w1/masters/w1-uart.c line 36

Quoted 10 lines
drivers/w1/masters/w1-uart.c new file +10 -0
+ * struct w1_uart_config - configuration for 1-Wire operation
+ *
+ * @baudrate: baud-rate returned from serdev
+ * @delay_us: delay to complete a 1-Wire cycle (in us)
+ * @tx_byte: byte to generate 1-Wire timing pattern
+ */
+struct w1_uart_config {
+	unsigned int baudrate;
+	unsigned int delay_us;
+	unsigned char tx_byte;

If it is a "byte", it should be u8.

drivers/w1/masters/w1-uart.c line 48

Quoted 12 lines
drivers/w1/masters/w1-uart.c new file +12 -0
+};
+
+struct w1_uart_device {
+	struct serdev_device *serdev;
+	struct w1_bus_master bus;
+
+	struct w1_uart_config cfg_reset;
+	struct w1_uart_config cfg_touch_0;
+	struct w1_uart_config cfg_touch_1;
+
+	struct completion rx_byte_received;
+	unsigned char rx_byte;

The same here.

Quoted 15 lines
drivers/w1/masters/w1-uart.c new file +15 -0
+	int rx_err;
+
+	struct mutex mutex;
+};
+
+/*
+ * struct w1_uart_limits - limits for 1-Wire operations
+ *
+ * @baudrate: Requested baud-rate to create 1-Wire timing pattern
+ * @bit_min_us: minimum time for a bit (in us)
+ * @bit_max_us: maximum time for a bit (in us)
+ * @sample_us: timespan to sample 1-Wire response
+ * @cycle_us: duration of the 1-Wire cycle
+ */
+struct w1_uart_limits {

drivers/w1/masters/w1-uart.c line 73

Quoted 10 lines
drivers/w1/masters/w1-uart.c new file +10 -0
+	unsigned int baudrate;
+	unsigned int bit_min_us;
+	unsigned int bit_max_us;
+	unsigned int sample_us;
+	unsigned int cycle_us;
+};
+
+static inline unsigned int baud_to_bit_ns(unsigned int baud)
+{
+	return 1000000000 / baud;

NSEC_PER_SEC

drivers/w1/masters/w1-uart.c line 78

Quoted 5 lines
drivers/w1/masters/w1-uart.c new file +5 -0
+}
+
+static inline unsigned int to_ns(unsigned int us)
+{
+	return us * 1000;

NSEC_PER_USEC

Quoted 27 lines
drivers/w1/masters/w1-uart.c new file +27 -0
+}
+
+/*
+ * Set baud-rate, delay and tx-byte to create a 1-Wire pulse and adapt
+ * the tx-byte according to the actual baud-rate.
+ *
+ * Reject when:
+ * - time for a bit outside min/max range
+ * - a 1-Wire response is not detectable for sent byte
+ */
+static int w1_uart_set_config(struct serdev_device *serdev,
+			      const struct w1_uart_limits *limits,
+			      struct w1_uart_config *w1cfg)
+{
+	unsigned int bits_low;
+	unsigned int bit_ns;
+	unsigned int low_ns;
+
+	w1cfg->baudrate = serdev_device_set_baudrate(serdev, limits->baudrate);
+	if (w1cfg->baudrate == 0)
+		return -EINVAL;
+
+	/* Compute in nanoseconds for accuracy */
+	bit_ns = baud_to_bit_ns(w1cfg->baudrate);
+	bits_low = to_ns(limits->bit_min_us) / bit_ns;
+	/* start bit is always low */
+	low_ns = bit_ns * (bits_low + 1);

drivers/w1/masters/w1-uart.c line 115

Quoted 10 lines
drivers/w1/masters/w1-uart.c new file +10 -0
+
+	if (low_ns < to_ns(limits->bit_min_us))
+		return -EINVAL;
+
+	if (low_ns > to_ns(limits->bit_max_us))
+		return -EINVAL;
+
+	/* 1-Wire response detectable for sent byte */
+	if (limits->sample_us > 0 &&
+	    bit_ns * 8 < low_ns + to_ns(limits->sample_us))

BITS_PER_BYTE

drivers/w1/masters/w1-uart.c line 120

Quoted 5 lines
drivers/w1/masters/w1-uart.c new file +5 -0
+		return -EINVAL;
+
+	/* delay to complete 1-Wire cycle, include start and stop-bit */
+	w1cfg->delay_us = 0;
+	if (bit_ns * 10 < to_ns(limits->cycle_us))

What is this 10? Dub it.

drivers/w1/masters/w1-uart.c line 122

Quoted 2 lines
drivers/w1/masters/w1-uart.c new file +2 -0
+		w1cfg->delay_us =
+			(to_ns(limits->cycle_us) - bit_ns * 10) / 1000;

And this 10?

The end: / NSEC_PER_USEC

Quoted 6 lines
drivers/w1/masters/w1-uart.c new file +6 -0
+
+	/* byte to create 1-Wire pulse */
+	w1cfg->tx_byte = 0xff << bits_low;
+
+	return 0;
+}

...

drivers/w1/masters/w1-uart.c line 240

Quoted 3 lines
drivers/w1/masters/w1-uart.c new file +3 -0
+static int w1_uart_serdev_tx_rx(struct w1_uart_device *w1dev,
+				const struct w1_uart_config *w1cfg,
+				unsigned char *rx_byte)

u8 *

Quoted 1 line

+{

...

drivers/w1/masters/w1-uart.c line 277

Quoted 4 lines
drivers/w1/masters/w1-uart.c new file +4 -0
+}
+
+static int w1_uart_serdev_receive_buf(struct serdev_device *serdev,
+				      const unsigned char *buf, size_t count)

serdev already uses u8 * here. You are basing on the top of some old tree.

regards,

Signature · 2 lines
js
suse labs
#14 lore raw
Quoted 51 lines · Jiri Slaby
Quoted 16 lines · On 06. 01. 24, 17:02, Christoph Winklhofer via B4 Relay wrote:

From: Christoph Winklhofer <[email protected]>

Add a UART 1-Wire bus driver. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns. The driver was tested on a "Raspberry Pi 3B" with a DS18B20 and on a "Variscite DART-6UL" with a DS18S20 temperature sensor.

The 1-Wire timing pattern and the corresponding UART baud-rate with the interpretation of the transferred bytes are described in the document:

In short, the UART peripheral must support full-duplex and operate in open-drain mode. The timing patterns are generated by a specific combination of baud-rate and transmitted byte, which corresponds to a 1-Wire read bit, write bit or reset.

...

Quoted 33 lines
drivers/w1/masters/w1-uart.c new file +30 -0
@@ -0,0 +1,398 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * w1-uart - UART 1-Wire bus driver
+ *
+ * Uses the UART interface (via Serial Device Bus) to create the 1-Wire
+ * timing patterns. Implements the following 1-Wire master interface:
+ *
+ * - reset_bus: requests baud-rate 9600
+ *
+ * - touch_bit: requests baud-rate 115200
+ *
+ * Author: Christoph Winklhofer <[email protected]>
+ */
+
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/jiffies.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/of.h>
+#include <linux/serdev.h>
+#include <linux/w1.h>
+
+#define W1_UART_TIMEOUT msecs_to_jiffies(500)
+
+/*
+ * struct w1_uart_config - configuration for 1-Wire operation
+ *
+ * @baudrate: baud-rate returned from serdev
+ * @delay_us: delay to complete a 1-Wire cycle (in us)
Quoted 9 lines

drivers/w1/masters/w1-uart.c line 36

Quoted 6 lines
drivers/w1/masters/w1-uart.c new file +6 -0
+ * @tx_byte: byte to generate 1-Wire timing pattern
+ */
+struct w1_uart_config {
+	unsigned int baudrate;
+	unsigned int delay_us;
+	unsigned char tx_byte;

If it is a "byte", it should be u8.

will change this and all others to u8.

...

Quoted 7 lines

drivers/w1/masters/w1-uart.c line 73

Quoted 4 lines
drivers/w1/masters/w1-uart.c new file +4 -0
+
+static inline unsigned int baud_to_bit_ns(unsigned int baud)
+{
+	return 1000000000 / baud;

NSEC_PER_SEC

Quoted 8 lines

drivers/w1/masters/w1-uart.c line 78

Quoted 5 lines
drivers/w1/masters/w1-uart.c new file +5 -0
+}
+
+static inline unsigned int to_ns(unsigned int us)
+{
+	return us * 1000;

NSEC_PER_USEC

and use the correct constants.

...

Quoted 14 lines
Quoted 14 lines
drivers/w1/masters/w1-uart.c new file +14 -0
+}
+
+/*
+ * Set baud-rate, delay and tx-byte to create a 1-Wire pulse and adapt
+ * the tx-byte according to the actual baud-rate.
+ *
+ * Reject when:
+ * - time for a bit outside min/max range
+ * - a 1-Wire response is not detectable for sent byte
+ */
+static int w1_uart_set_config(struct serdev_device *serdev,
+			      const struct w1_uart_limits *limits,
+			      struct w1_uart_config *w1cfg)
+{

...

Quoted 6 lines

drivers/w1/masters/w1-uart.c line 115

Quoted 3 lines
drivers/w1/masters/w1-uart.c new file +3 -0
+	/* 1-Wire response detectable for sent byte */
+	if (limits->sample_us > 0 &&
+	    bit_ns * 8 < low_ns + to_ns(limits->sample_us))

BITS_PER_BYTE

ok, change it (it is the time for the UART data-frame).

Quoted 8 lines

drivers/w1/masters/w1-uart.c line 120

Quoted 5 lines
drivers/w1/masters/w1-uart.c new file +5 -0
+		return -EINVAL;
+
+	/* delay to complete 1-Wire cycle, include start and stop-bit */
+	w1cfg->delay_us = 0;
+	if (bit_ns * 10 < to_ns(limits->cycle_us))

What is this 10? Dub it.

Quoted 7 lines

drivers/w1/masters/w1-uart.c line 122

Quoted 2 lines
drivers/w1/masters/w1-uart.c new file +2 -0
+		w1cfg->delay_us =
+			(to_ns(limits->cycle_us) - bit_ns * 10) / 1000;

And this 10?

The end: / NSEC_PER_USEC

will be more explicit (it is the time for the UART packet:
BITS_PER_BYTE + 2 (start and stop-bit).

...

Quoted 4 lines

drivers/w1/masters/w1-uart.c line 277

Quoted 2 lines
drivers/w1/masters/w1-uart.c new file +2 -0
+static int w1_uart_serdev_receive_buf(struct serdev_device *serdev,
+				      const unsigned char *buf, size_t count)

serdev already uses u8 * here. You are basing on the top of some old tree.

Yes, this patch is based on the w1-next branch of
git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-w1.git
was not sure from where to start. I guess that this change is probably in the w1-tree after the next stable release.

Quoted 6 lines

regards,

Signature · 2 lines
js
suse labs

Thanks Jiri for the review!

Kind regards,
Christoph

#15 lore raw
Quoted 5 lines · Christoph Winklhofer

...

Quoted 4 lines

drivers/w1/masters/w1-uart.c line 277

Quoted 2 lines
drivers/w1/masters/w1-uart.c new file +2 -0
+static int w1_uart_serdev_receive_buf(struct serdev_device *serdev,
+				      const unsigned char *buf, size_t count)

serdev already uses u8 * here. You are basing on the top of some old tree.

Old? Your change came for v6.8 and this was sent when all trees were based on v6.7-rc1. What newer tree could have this been?

Quoted 4 lines

Yes, this patch is based on the w1-next branch of
git://git.kernel.org/pub/scm/linux/kernel/git/krzk/linux-w1.git
was not sure from where to start. I guess that this change is probably in the w1-tree after the next stable release.

That's a timing issue. For that particular case, where this was targeting next-next cycle, you should have based this on linux-next. In other cases this would require cross-tree merging due to dependencies which none of us were aware, so no harm.

Best regards,
Krzysztof

#16 lore raw
In reply to Christoph Winklhofer
Quoted 6 lines · On 06/01/2024 17:02, Christoph Winklhofer via B4 Relay wrote:

Hello!

This patch contains a driver for a 1-Wire bus over UART. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns.

Quoted 6 lines

Changes in v4:
- rework baud-rate configuration: also check max bit-time, support higher baud-rates by adding a delay to complete 1-Wire cycle.
- dt-binding w1-uart: specify baud-rates for 1-Wire operations
- Link to v3: https://lore.kernel.org/r/[email protected]

You can slow down a bit. You sent v2 too late to be applied. Then you sent v3 and next day v4.

While I like approach to release early, release often, it does not necessarily apply to the bindings. Bindings should be complete, which means they should describe the hardware as fully as possible.

About the driver, you can develop it incrementally, it is a good idea, however since ~rc6 my w1 tree is closed. It will remain closed till next rc1 is released (merge window finished). Nothing will get applied during that time, so if you intend to add new features, better to send v5 after the merge window (instead v4 now, v5 tomorrow, v6 next week and then v7 after rc1).

Best regards,
Krzysztof

#17 lore raw
Quoted 28 lines · Krzysztof Kozlowski
Quoted 6 lines · On 06/01/2024 17:02, Christoph Winklhofer via B4 Relay wrote:

Hello!

This patch contains a driver for a 1-Wire bus over UART. The driver utilizes the UART interface via the Serial Device Bus to create the 1-Wire timing patterns.

Quoted 6 lines

Changes in v4:
- rework baud-rate configuration: also check max bit-time, support higher baud-rates by adding a delay to complete 1-Wire cycle.
- dt-binding w1-uart: specify baud-rates for 1-Wire operations
- Link to v3: https://lore.kernel.org/r/[email protected]

You can slow down a bit. You sent v2 too late to be applied. Then you sent v3 and next day v4.

While I like approach to release early, release often, it does not necessarily apply to the bindings. Bindings should be complete, which means they should describe the hardware as fully as possible.

About the driver, you can develop it incrementally, it is a good idea, however since ~rc6 my w1 tree is closed. It will remain closed till next rc1 is released (merge window finished). Nothing will get applied during that time, so if you intend to add new features, better to send v5 after the merge window (instead v4 now, v5 tomorrow, v6 next week and then v7 after rc1).

Quoted 3 lines

Best regards,
Krzysztof

Ok sorry, understood - thank you for the clarification.

Kind regards,
Christoph