Skip to contentSkip to conversation

Add support for "pd-timers" DT property in TCPM

RFC Superseded Amit Sunil Dhamne 4 participants 13 messages Sep 11, 2024 – Oct 7, 2024

Subsystems (4)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover Add support for "pd-timers" DT property in TCPM

USB PD specification defines a bunch of timers that can have a range of acceptable values instead of specific values. These values have to be tuned based on the platform. However, TCPM currently sets them to a default value without providing a mechanism to set platform specific values.

This patchset adds a new DT property called "pd-timers" to allow users to define platform specific values.

Amit Sunil Dhamne (2):
dt-bindings: connector: Add property to set pd timer values
usb: typec: tcpm: Add support for pd-timers DT property

 .../bindings/connector/usb-connector.yaml     |  23 ++++
 drivers/usb/typec/tcpm/tcpm.c                 | 110 +++++++++++++++---
 include/dt-bindings/usb/pd.h                  |   8 ++
 3 files changed, 123 insertions(+), 18 deletions(-)

base-commit: f299cd11f7539482e87b2d2d527968a26b33f0ec

Signature · 1 line
2.46.0.598.g6f2099f65c-goog
#1 lore raw

RFC 1/2 dt-bindings: connector: Add property to set pd timer values

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
 .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
 include/dt-bindings/usb/pd.h                  |  8 +++++++
 2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +23 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
     additionalProperties: false
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+
 dependencies:
   sink-vdos-v1: [ sink-vdos ]
   sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
             };
         };
     };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;
+        };
+    };
include/dt-bindings/usb/pd.h +8 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
 	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
 	 | ((gi) & 0x3f) << 1 | (ct))
 
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2
+
 #endif /* __DT_POWER_DELIVERY_H */
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
#2 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Quoted 20 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
 .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
 include/dt-bindings/usb/pd.h                  |  8 +++++++
 2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
     additionalProperties: false

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +9 -0
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Quoted 41 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +14 -0
+
 dependencies:
   sink-vdos-v1: [ sink-vdos ]
   sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
             };
         };
     };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;
+        };
+    };
include/dt-bindings/usb/pd.h +8 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
 	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
 	 | ((gi) & 0x3f) << 1 | (ct))
 
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2
+
 #endif /* __DT_POWER_DELIVERY_H */
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Signature · 2 lines
With best wishes
Dmitry
#3 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Hi Dmitry,

Quoted 22 lines · Dmitry Baryshkov
Quoted 21 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
      additionalProperties: false
 
Quoted 12 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 9 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +9 -0
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Thanks for the review. The reason I did it this way was for convenience. If in the future someone else wants add a new timer, it'd be convenient to just add it as a new macro definition in pd.h rather than having to define a new property each time, especially if folks want to add more timers (scales better).
There are 3 timers already and I am working to add a fourth in a follow up patch if the current RFC gets accepted.

Please let me know what do you think?

Regards,

Amit

Quoted 41 lines
Quoted 41 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +14 -0
+
  dependencies:
    sink-vdos-v1: [ sink-vdos ]
    sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
              };
          };
      };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;
+        };
+    };
include/dt-bindings/usb/pd.h +8 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
  	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
  	 | ((gi) & 0x3f) << 1 | (ct))
 
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2
+
  #endif /* __DT_POWER_DELIVERY_H */
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
#4 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Quoted 44 lines · Amit Sunil Dhamne

Hi Dmitry,

Quoted 24 lines · Dmitry Baryshkov
Quoted 23 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +4 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
      additionalProperties: false
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Thanks for the review. The reason I did it this way was for convenience. If in the future someone else wants add a new timer, it'd be convenient to just add it as a new macro definition in pd.h rather than having to define a new property each time, especially if folks want to add more timers (scales better).
There are 3 timers already and I am working to add a fourth in a follow up patch if the current RFC gets accepted.

Quoted 1 line

Please let me know what do you think?

I'd leave the decision to DT maintainers, but in my opinion multiple properties scale better. Having a single value per property is easier to handle rather than changing the tagged array.

Quoted 45 lines

Regards,

Amit

Quoted 40 lines
Quoted 40 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +14 -0
+
  dependencies:
    sink-vdos-v1: [ sink-vdos ]
    sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
              };
          };
      };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;
+        };
+    };
include/dt-bindings/usb/pd.h +8 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
  	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
  	 | ((gi) & 0x3f) << 1 | (ct))
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2
+
  #endif /* __DT_POWER_DELIVERY_H */
Signature · 1 line
2.46.0.598.g6f2099f65c-goog
Signature · 2 lines
With best wishes
Dmitry
maintainer
#5 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Quoted 45 lines · Dmitry Baryshkov
Quoted 44 lines · Amit Sunil Dhamne

Hi Dmitry,

Quoted 24 lines · Dmitry Baryshkov
Quoted 23 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +4 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
      additionalProperties: false
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Thanks for the review. The reason I did it this way was for convenience. If in the future someone else wants add a new timer, it'd be convenient to just add it as a new macro definition in pd.h rather than having to define a new property each time, especially if folks want to add more timers (scales better).
There are 3 timers already and I am working to add a fourth in a follow up patch if the current RFC gets accepted.

Quoted 5 lines
Quoted 1 line

Please let me know what do you think?

I'd leave the decision to DT maintainers, but in my opinion multiple properties scale better. Having a single value per property is easier to handle rather than changing the tagged array.

I agree. And it avoids what looks like a made up number space with the defines.

And note that an array of tuples is a matrix in DT defined types, not an array.

Rob

#6 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Hi Rob,

Quoted 46 lines · Rob Herring
Quoted 45 lines · Dmitry Baryshkov
Quoted 44 lines · Amit Sunil Dhamne

Hi Dmitry,

Quoted 24 lines · Dmitry Baryshkov
Quoted 23 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
   .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
   include/dt-bindings/usb/pd.h                  |  8 +++++++
   2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +4 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
       additionalProperties: false
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Thanks for the review. The reason I did it this way was for convenience. If in the future someone else wants add a new timer, it'd be convenient to just add it as a new macro definition in pd.h rather than having to define a new property each time, especially if folks want to add more timers (scales better).
There are 3 timers already and I am working to add a fourth in a follow up patch if the current RFC gets accepted.

Please let me know what do you think?

Quoted 8 lines
Quoted 3 lines

I'd leave the decision to DT maintainers, but in my opinion multiple properties scale better. Having a single value per property is easier to handle rather than changing the tagged array.

I agree. And it avoids what looks like a made up number space with the defines.

And note that an array of tuples is a matrix in DT defined types, not an array.

Thanks for the review! I will incorporate the suggested comments in the next revision by creating a "single value per timer" property.

Regards,

Amit

Quoted 2 lines

Rob

#7 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

In reply to Amit Sunil Dhamne
Quoted 46 lines · Amit Sunil Dhamne

Hi Dmitry,

Quoted 22 lines · Dmitry Baryshkov
Quoted 21 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
      additionalProperties: false
 
Quoted 12 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 9 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +9 -0
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.
+    $ref: /schemas/types.yaml#/definitions/uint32-array

Is it really necessary to use the array property? I think it's easier and more logical to define corresponding individual properties, one per the timer.

Thanks for the review. The reason I did it this way was for convenience. If in the future someone else wants add a new timer, it'd be convenient to just add it as a new macro definition in pd.h rather than having to define a new property each time, especially if folks want to add more timers (scales better).
There are 3 timers already and I am working to add a fourth in a follow up patch if the current RFC gets accepted.

Quoted 1 line

Please let me know what do you think?

Binding is supposed to be complete. You already know this is not complete...

Best regards,
Krzysztof

#8 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

In reply to Amit Sunil Dhamne
Quoted 8 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

Please work on mainline, not ancient tree. You cannot get my CC address like that from mainline. It's not possible. So either you don't develop on mainline or you don't use get_maintainers.pl/b4/patman.

Quoted 10 lines
---
 .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
 include/dt-bindings/usb/pd.h                  |  8 +++++++
 2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 258

Quoted 6 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
@@ -253,6 +253,16 @@ properties:
 
     additionalProperties: false
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer

timer of what? OS behavior?

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 261

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user

Do not describe what DT is. We all know what DT properties allow. Instead describe how this relates to hardware or boards.

All this is wrongly wrapped. See Coding style (and I am not telling you the value on purpose, so you will read the coding style) .

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 263

Quoted 2 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.

And what is the default?

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 1 line
Documentation/devicetree/bindings/connector/usb-connector.yaml +1 -0
+    $ref: /schemas/types.yaml#/definitions/uint32-array

I guess you want matrix here.

Quoted 9 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+
 dependencies:
   sink-vdos-v1: [ sink-vdos ]
   sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
             };
         };
     };
+

Documentation/devicetree/bindings/connector/usb-connector.yaml examples: · line 501

Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +10 -0
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;

Incorporate it into existing example.

include/dt-bindings/usb/pd.h line 469

Quoted 12 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+        };
+    };
include/dt-bindings/usb/pd.h +2 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
 	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
 	 | ((gi) & 0x3f) << 1 | (ct))
 
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */

Please expand this a bit, so we won't have to reach to external sources.

include/dt-bindings/usb/pd.h line 474

Quoted 5 lines
include/dt-bindings/usb/pd.h +5 -0
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2

Best regards,
Krzysztof

#9 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Hi Krzysztof,

Thanks for the review!

Quoted 11 lines · Krzysztof Kozlowski
Quoted 8 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

Please work on mainline, not ancient tree. You cannot get my CC address like that from mainline.

I was working off gregkh's tree on usb-next branch as that's suggested for USB development.

Quoted 3 lines

It's not possible. So either you don't develop
on mainline or you don't use get_maintainers.pl/b4/patman.

The above branch and even the tree on Linus' master branch has you listed as a maintainer
(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n17181).
I guess that's why the get_maintainers script probably returned your email id when I ran it. Please let me know if I missed something :).

Quoted 11 lines
Quoted 11 lines
---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
Quoted 6 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 258

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
      additionalProperties: false
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer

timer of what? OS behavior?

In the context of USB Type C Power Delivery (PD), timers are run on the typec protocol driver
(usb/typec/tcpm/tcpm.c).
These are used to keep track of min/max or range of time required to enter a PD state with the
goal of a successful USB typec capabilities negotiation.  Eg., the timer PD_TIMER_SINK_WAIT_CAP (referred to as SinkWaitCapTimer in spec)would be responsible to keep track of whether a power source sent us (as sink) PD source capabilities pkts within 600ms (say), if yes, then we would transition to the next state or do a state machine reset. USB PD 3.1 spec refers to these elements as timers and therefore referred to as such here.

Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 261

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user

Do not describe what DT is. We all know what DT properties allow. Instead describe how this relates to hardware or boards.

All this is wrongly wrapped. See Coding style (and I am not telling you the value on purpose, so you will read the coding style) .

Ack. Thanks for pointing it out, I will fix both the above in the next revision.

Quoted 4 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 263

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.

And what is the default?

Defaults are given in (include/linux/usb/pd.h). But I guess I should have probably mentioned that here.

Quoted 3 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 2 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +1 -0
+    $ref: /schemas/types.yaml#/definitions/uint32-array

I guess you want matrix here.

Yes, I should have. Though, I will be re-implementing this such that each timer is represented as a separate property based on Rob and Dmitry's suggestion in
https://lore.kernel.org/lkml/[email protected]/ .

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+
  dependencies:
    sink-vdos-v1: [ sink-vdos ]
    sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
              };
          };
      };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
Quoted 9 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml examples: · line 501

Quoted 7 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +7 -0
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;

Incorporate it into existing example.

Ack.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+        };
+    };
include/dt-bindings/usb/pd.h +0 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
  	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
  	 | ((gi) & 0x3f) << 1 | (ct))
 
Quoted 3 lines

include/dt-bindings/usb/pd.h line 469

Quoted 2 lines
include/dt-bindings/usb/pd.h +2 -0
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */

Please expand this a bit, so we won't have to reach to external sources.

Ack.

I will incorporate all of your review comments.

Since you are no longer maintaining the
"OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" component, please let me know if you'd still like to be CC'ed in the subsequent revisions.

Thanks,

Amit

Quoted 9 lines

include/dt-bindings/usb/pd.h line 474

Quoted 5 lines
include/dt-bindings/usb/pd.h +5 -0
+#define PD_TIMER_SINK_WAIT_CAP		0
+/* tPSSourceOff (Table 6-68 Time Values, USB PD3.1 Spec) */
+#define PD_TIMER_PS_SOURCE_OFF		1
+/* tCCDebounce (Table 4-33 CC Timing, USB Type-C Cable & Connector Spec Rel2.2) */
+#define PD_TIMER_CC_DEBOUNCE		2

Best regards,
Krzysztof

#10 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Quoted 20 lines · Amit Sunil Dhamne

Hi Krzysztof,

Thanks for the review!

Quoted 11 lines · Krzysztof Kozlowski
Quoted 8 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

Please work on mainline, not ancient tree. You cannot get my CC address like that from mainline.

I was working off gregkh's tree on usb-next branch as that's suggested for USB development.

Quoted 8 lines
Quoted 3 lines

It's not possible. So either you don't develop
on mainline or you don't use get_maintainers.pl/b4/patman.

The above branch and even the tree on Linus' master branch has you listed as a maintainer
(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n17181).
I guess that's why the get_maintainers script probably returned your email id when I ran it. Please let me know if I missed something :).

You really just skimmed over my email... I know how maintainers work.

So I REPEAT: You cannot get this email address you Cced. Point me to the line in your tree having such email. The one here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n17181

does not have it.

Quoted 104 lines
Quoted 13 lines
Quoted 13 lines

---
  .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
  include/dt-bindings/usb/pd.h                  |  8 +++++++
  2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
Quoted 6 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 258

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
      additionalProperties: false
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer

timer of what? OS behavior?

In the context of USB Type C Power Delivery (PD), timers are run on the typec protocol driver
(usb/typec/tcpm/tcpm.c).
These are used to keep track of min/max or range of time required to enter a PD state with the
goal of a successful USB typec capabilities negotiation.  Eg., the timer PD_TIMER_SINK_WAIT_CAP (referred to as SinkWaitCapTimer in spec)would be responsible to keep track of whether a power source sent us (as sink) PD source capabilities pkts within 600ms (say), if yes, then we would transition to the next state or do a state machine reset. USB PD 3.1 spec refers to these elements as timers and therefore referred to as such here.

Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 261

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user

Do not describe what DT is. We all know what DT properties allow. Instead describe how this relates to hardware or boards.

All this is wrongly wrapped. See Coding style (and I am not telling you the value on purpose, so you will read the coding style) .

Ack. Thanks for pointing it out, I will fix both the above in the next revision.

Quoted 4 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 263

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.

And what is the default?

Defaults are given in (include/linux/usb/pd.h). But I guess I should have probably mentioned
that here.

Quoted 3 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 2 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +1 -0
+    $ref: /schemas/types.yaml#/definitions/uint32-array

I guess you want matrix here.

Yes, I should have. Though, I will be re-implementing this such that each timer is represented
as a separate property based on Rob and Dmitry's suggestion in
https://lore.kernel.org/lkml/[email protected]/ .

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+
  dependencies:
    sink-vdos-v1: [ sink-vdos ]
    sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
              };
          };
      };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
Quoted 9 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml examples: · line 501

Quoted 7 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +7 -0
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;

Incorporate it into existing example.

Ack.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+        };
+    };
include/dt-bindings/usb/pd.h +0 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
  	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
  	 | ((gi) & 0x3f) << 1 | (ct))
 
Quoted 3 lines

include/dt-bindings/usb/pd.h line 469

Quoted 2 lines
include/dt-bindings/usb/pd.h +2 -0
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */

Please expand this a bit, so we won't have to reach to external sources.

Quoted 6 lines

Ack.

I will incorporate all of your review comments.

Since you are no longer maintaining the
"OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" component, please let

Who said that? You CC wrong emails because either you work on ancient tree or you do not use tools like get_maintainers.pl or b4. You cannot get this email from proper process. It is not physically possible because that email is nowhere mentioned.

Quoted 2 lines

me know
if you'd still like to be CC'ed in the subsequent revisions.

Damn, just use standard tools. You are not supposed to invent maintainers.

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.
</form letter>

Best regards,
Krzysztof

#11 lore raw

Re: [RFC 1/2] dt-bindings: connector: Add property to set pd timer values

Hi Krzysztof,

Quoted 29 lines · Krzysztof Kozlowski
Quoted 20 lines · Amit Sunil Dhamne

Hi Krzysztof,

Thanks for the review!

Quoted 11 lines · Krzysztof Kozlowski
Quoted 8 lines · Amit Sunil Dhamne

This commit adds a new property "pd-timers" to enable setting of platform/board specific pd timer values for timers that have a range of acceptable values.

Please work on mainline, not ancient tree. You cannot get my CC address like that from mainline.

I was working off gregkh's tree on usb-next branch as that's suggested for USB development.

Quoted 8 lines
Quoted 3 lines

It's not possible. So either you don't develop
on mainline or you don't use get_maintainers.pl/b4/patman.

The above branch and even the tree on Linus' master branch has you listed as a maintainer
(https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n17181).
I guess that's why the get_maintainers script probably returned your email id when I ran it. Please let me know if I missed something :).

Quoted 7 lines

You really just skimmed over my email... I know how maintainers work.

So I REPEAT: You cannot get this email address you Cced. Point me to the line in your tree having such email. The one here:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/MAINTAINERS#n17181

does not have it.

Sorry I misunderstood. Will fix it henceforth in subsequent work.

Quoted 128 lines
Quoted 97 lines
Quoted 12 lines
Quoted 12 lines
---
   .../bindings/connector/usb-connector.yaml     | 23 +++++++++++++++++++
   include/dt-bindings/usb/pd.h                  |  8 +++++++
   2 files changed, 31 insertions(+)
Documentation/devicetree/bindings/connector/usb-connector.yaml +0 -0
index fb216ce68bb3..9be4ed12f13c 100644
@@ -253,6 +253,16 @@ properties:
 
Quoted 6 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 258

Quoted 5 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
       additionalProperties: false
 
+  pd-timers:
+    description: An array of u32 integers, where an even index (i) is the timer (referenced in
+      dt-bindings/usb/pd.h) and the odd index (i+1) is the timer value in ms (refer

timer of what? OS behavior?

In the context of USB Type C Power Delivery (PD), timers are run on the typec protocol driver
(usb/typec/tcpm/tcpm.c).
These are used to keep track of min/max or range of time required to enter a PD state with the
goal of a successful USB typec capabilities negotiation.  Eg., the timer PD_TIMER_SINK_WAIT_CAP (referred to as SinkWaitCapTimer in spec)would be responsible to keep track of whether a power source sent us (as sink) PD source capabilities pkts within 600ms (say), if yes, then we would transition to the next state or do a state machine reset. USB PD 3.1 spec refers to these elements as timers and therefore referred to as such here.

Quoted 8 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 261

Quoted 3 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +3 -0
+      "Table 6-68 Time Values" of "USB Power Delivery Specification Revision 3.0, Version 1.2 " for
+      the appropriate value). For certain timers the PD spec defines a range rather than a fixed
+      value. The timers may need to be tuned based on the platform. This dt property allows the user

Do not describe what DT is. We all know what DT properties allow. Instead describe how this relates to hardware or boards.

All this is wrongly wrapped. See Coding style (and I am not telling you the value on purpose, so you will read the coding style) .

Ack. Thanks for pointing it out, I will fix both the above in the next revision.

Quoted 3 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 263

Quoted 2 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+      to assign specific values based on the platform. If these values are not explicitly defined,
+      TCPM will use a valid default value for such timers.

And what is the default?

Defaults are given in (include/linux/usb/pd.h). But I guess I should have probably mentioned
that here.

Quoted 2 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml properties: · line 264

Quoted 1 line
Documentation/devicetree/bindings/connector/usb-connector.yaml +1 -0
+    $ref: /schemas/types.yaml#/definitions/uint32-array

I guess you want matrix here.

Yes, I should have. Though, I will be re-implementing this such that each timer is represented
as a separate property based on Rob and Dmitry's suggestion in
https://lore.kernel.org/lkml/[email protected]/ .

Quoted 12 lines
Quoted 12 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +5 -0
+
   dependencies:
     sink-vdos-v1: [ sink-vdos ]
     sink-vdos: [ sink-vdos-v1 ]
@@ -478,3 +488,16 @@ examples:
               };
           };
       };
+
+  # USB-C connector with PD timers
+  - |
+    #include <dt-bindings/usb/pd.h>
Quoted 9 lines

Documentation/devicetree/bindings/connector/usb-connector.yaml examples: · line 501

Quoted 7 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +7 -0
+    usb {
+        connector {
+            compatible = "usb-c-connector";
+            label = "USB-C";
+            pd-timers =
+                <PD_TIMER_SINK_WAIT_CAP 600>,
+                <PD_TIMER_CC_DEBOUNCE 170>;

Incorporate it into existing example.

Ack.

Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/connector/usb-connector.yaml +2 -0
+        };
+    };
include/dt-bindings/usb/pd.h +0 -0
index e6526b138174..6c58c30f3f39 100644
@@ -465,4 +465,12 @@
   	 | ((vbm) & 0x3) << 15 | (curr) << 14 | ((vbi) & 0x3f) << 7	\
   	 | ((gi) & 0x3f) << 1 | (ct))
 
Quoted 3 lines

include/dt-bindings/usb/pd.h line 469

Quoted 2 lines
include/dt-bindings/usb/pd.h +2 -0
+/* PD Timer definitions */
+/* tTypeCSinkWaitCap (Table 6-68 Time Values, USB PD3.1 Spec) */

Please expand this a bit, so we won't have to reach to external sources.

Quoted 6 lines

Ack.

I will incorporate all of your review comments.

Since you are no longer maintaining the
"OPEN FIRMWARE AND FLATTENED DEVICE TREE BINDINGS" component, please let

Who said that? You CC wrong emails because either you work on ancient tree or you do not use tools like get_maintainers.pl or b4. You cannot get this email from proper process. It is not physically possible because that email is nowhere mentioned.

Quoted 2 lines

me know
if you'd still like to be CC'ed in the subsequent revisions.

Damn, just use standard tools. You are not supposed to invent maintainers.

<form letter>
Please use scripts/get_maintainers.pl to get a list of necessary people and lists to CC (and consider --no-git-fallback argument). It might happen, that command when run on an older kernel, gives you outdated entries. Therefore please be sure you base your patches on recent Linux kernel.

Tools like b4 or scripts/get_maintainer.pl provide you proper list of people, so fix your workflow. Tools might also fail if you work on some ancient tree (don't, instead use mainline) or work on fork of kernel (don't, instead use mainline). Just use b4 and everything should be fine, although remember about b4 prep --auto-to-cc if you added new patches to the patchset.
</form letter>

Quoted 2 lines

Best regards,
Krzysztof

Thanks for the tips! I will make sure to follow these henceforth.

Regards,

Amit

#12 lore raw

RFC 2/2 usb: typec: tcpm: Add support for pd-timers DT property

In reply to Amit Sunil Dhamne

Add support for DT property "pd-timers" to allow users to define platform specific values. For values that have not been explicitly defined in DT using this attribute, default values will be set. Therefore making this change backward compatible.

---
 drivers/usb/typec/tcpm/tcpm.c | 110 ++++++++++++++++++++++++++++------
 1 file changed, 92 insertions(+), 18 deletions(-)
drivers/usb/typec/tcpm/tcpm.c +92 -18
index 4b02d6474259..596d19ff85ac 100644
@@ -574,6 +574,31 @@ static const char * const pd_rev[] = {
 	[PD_REV30]		= "rev3",
 };
 
+/*
+ * Though "pd-timers" is a 1D array, it can be imagined as a table with 2
+ * columns, key at even index (that represents timer definition) & value
+ * at odd index (that represents timer values in ms).
+ */
+#define NUM_TIMER_TABLE_COLS		2
+
+/*
+ * PD Timer definitions for timers that can be tuned based on platform/board via DT.
+ * The timer definition value should always match that of macros defined in
+ * dt-bindings/usb/pd.h.
+ */
+enum pd_timer {
+	PD_TIMER_SINK_WAIT_CAP,
+	PD_TIMER_PS_SOURCE_OFF,
+	PD_TIMER_CC_DEBOUNCE,
+	PD_NUM_TIMERS
+};
+
+static u32 pd_timers[PD_NUM_TIMERS] = {
+	[PD_TIMER_SINK_WAIT_CAP] = PD_T_SINK_WAIT_CAP,
+	[PD_TIMER_PS_SOURCE_OFF] = PD_T_PS_SOURCE_OFF,
+	[PD_TIMER_CC_DEBOUNCE] = PD_T_CC_DEBOUNCE,
+};
+
 #define tcpm_cc_is_sink(cc) \
 	((cc) == TYPEC_CC_RP_DEF || (cc) == TYPEC_CC_RP_1_5 || \
 	 (cc) == TYPEC_CC_RP_3_0)
@@ -4601,7 +4626,7 @@ static void run_state_machine(struct tcpm_port *port)
 {
 	int ret;
 	enum typec_pwr_opmode opmode;
-	unsigned int msecs;
+	unsigned int msecs, timer_val_msecs;
 	enum tcpm_state upcoming_state;
 
 	if (port->tcpc->check_contaminant && port->state != CHECK_CONTAMINANT)
@@ -4637,17 +4662,18 @@ static void run_state_machine(struct tcpm_port *port)
 			tcpm_set_state(port, SNK_UNATTACHED, PD_T_DRP_SNK);
 		break;
 	case SRC_ATTACH_WAIT:
+		timer_val_msecs = pd_timers[PD_TIMER_CC_DEBOUNCE];
 		if (tcpm_port_is_debug(port))
 			tcpm_set_state(port, DEBUG_ACC_ATTACHED,
-				       PD_T_CC_DEBOUNCE);
+				       timer_val_msecs);
 		else if (tcpm_port_is_audio(port))
 			tcpm_set_state(port, AUDIO_ACC_ATTACHED,
-				       PD_T_CC_DEBOUNCE);
+				       timer_val_msecs);
 		else if (tcpm_port_is_source(port) && port->vbus_vsafe0v)
 			tcpm_set_state(port,
 				       tcpm_try_snk(port) ? SNK_TRY
 							  : SRC_ATTACHED,
-				       PD_T_CC_DEBOUNCE);
+				       timer_val_msecs);
 		break;
 
 	case SNK_TRY:
@@ -4698,7 +4724,7 @@ static void run_state_machine(struct tcpm_port *port)
 		}
 		break;
 	case SRC_TRYWAIT_DEBOUNCE:
-		tcpm_set_state(port, SRC_ATTACHED, PD_T_CC_DEBOUNCE);
+		tcpm_set_state(port, SRC_ATTACHED, pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 	case SRC_TRYWAIT_UNATTACHED:
 		tcpm_set_state(port, SNK_UNATTACHED, 0);
@@ -4896,12 +4922,13 @@ static void run_state_machine(struct tcpm_port *port)
 			tcpm_set_state(port, SRC_UNATTACHED, PD_T_DRP_SRC);
 		break;
 	case SNK_ATTACH_WAIT:
+		timer_val_msecs = pd_timers[PD_TIMER_CC_DEBOUNCE];
 		if ((port->cc1 == TYPEC_CC_OPEN &&
 		     port->cc2 != TYPEC_CC_OPEN) ||
 		    (port->cc1 != TYPEC_CC_OPEN &&
 		     port->cc2 == TYPEC_CC_OPEN))
 			tcpm_set_state(port, SNK_DEBOUNCED,
-				       PD_T_CC_DEBOUNCE);
+				       timer_val_msecs);
 		else if (tcpm_port_is_disconnected(port))
 			tcpm_set_state(port, SNK_UNATTACHED,
 				       PD_T_PD_DEBOUNCE);
@@ -4941,7 +4968,7 @@ static void run_state_machine(struct tcpm_port *port)
 		break;
 	case SNK_TRYWAIT:
 		tcpm_set_cc(port, TYPEC_CC_RD);
-		tcpm_set_state(port, SNK_TRYWAIT_VBUS, PD_T_CC_DEBOUNCE);
+		tcpm_set_state(port, SNK_TRYWAIT_VBUS, pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 	case SNK_TRYWAIT_VBUS:
 		/*
@@ -5014,7 +5041,7 @@ static void run_state_machine(struct tcpm_port *port)
 		break;
 	case SNK_DISCOVERY_DEBOUNCE:
 		tcpm_set_state(port, SNK_DISCOVERY_DEBOUNCE_DONE,
-			       PD_T_CC_DEBOUNCE);
+			       pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 	case SNK_DISCOVERY_DEBOUNCE_DONE:
 		if (!tcpm_port_is_disconnected(port) &&
@@ -5032,6 +5059,7 @@ static void run_state_machine(struct tcpm_port *port)
 			tcpm_set_state(port, SNK_READY, 0);
 			break;
 		}
+		timer_val_msecs = pd_timers[PD_TIMER_SINK_WAIT_CAP];
 		/*
 		 * If VBUS has never been low, and we time out waiting
 		 * for source cap, try a soft reset first, in case we
@@ -5041,10 +5069,10 @@ static void run_state_machine(struct tcpm_port *port)
 		if (port->vbus_never_low) {
 			port->vbus_never_low = false;
 			tcpm_set_state(port, SNK_SOFT_RESET,
-				       PD_T_SINK_WAIT_CAP);
+				       timer_val_msecs);
 		} else {
 			tcpm_set_state(port, SNK_WAIT_CAPABILITIES_TIMEOUT,
-				       PD_T_SINK_WAIT_CAP);
+				       timer_val_msecs);
 		}
 		break;
 	case SNK_WAIT_CAPABILITIES_TIMEOUT:
@@ -5054,7 +5082,7 @@ static void run_state_machine(struct tcpm_port *port)
 		 * sending Source Capability messages after a soft reset. The
 		 * specification suggests to do a hard reset when no Source
 		 * capability message is received within PD_T_SINK_WAIT_CAP,
-		 * but that might effectively kil the machine's power source.
+		 * but that might effectively kill the machine's power source.
 		 *
 		 * This slightly diverges from the specification and tries to
 		 * recover from this by explicitly asking for the capabilities
@@ -5066,7 +5094,8 @@ static void run_state_machine(struct tcpm_port *port)
 		if (tcpm_pd_send_control(port, PD_CTRL_GET_SOURCE_CAP, TCPC_TX_SOP))
 			tcpm_set_state_cond(port, hard_reset_state(port), 0);
 		else
-			tcpm_set_state(port, hard_reset_state(port), PD_T_SINK_WAIT_CAP);
+			tcpm_set_state(port, hard_reset_state(port),
+				       pd_timers[PD_TIMER_SINK_WAIT_CAP]);
 		break;
 	case SNK_NEGOTIATE_CAPABILITIES:
 		port->pd_capable = true;
@@ -5203,7 +5232,7 @@ static void run_state_machine(struct tcpm_port *port)
 			tcpm_set_state(port, ACC_UNATTACHED, 0);
 		break;
 	case AUDIO_ACC_DEBOUNCE:
-		tcpm_set_state(port, ACC_UNATTACHED, PD_T_CC_DEBOUNCE);
+		tcpm_set_state(port, ACC_UNATTACHED, pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 
 	/* Hard_Reset states */
@@ -5420,7 +5449,7 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_state(port, ERROR_RECOVERY, 0);
 		break;
 	case FR_SWAP_SNK_SRC_TRANSITION_TO_OFF:
-		tcpm_set_state(port, ERROR_RECOVERY, PD_T_PS_SOURCE_OFF);
+		tcpm_set_state(port, ERROR_RECOVERY, pd_timers[PD_TIMER_PS_SOURCE_OFF]);
 		break;
 	case FR_SWAP_SNK_SRC_NEW_SINK_READY:
 		if (port->vbus_source)
@@ -5475,7 +5504,7 @@ static void run_state_machine(struct tcpm_port *port)
 		tcpm_set_cc(port, TYPEC_CC_RD);
 		/* allow CC debounce */
 		tcpm_set_state(port, PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED,
-			       PD_T_CC_DEBOUNCE);
+			       pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 	case PR_SWAP_SRC_SNK_SOURCE_OFF_CC_DEBOUNCED:
 		/*
@@ -5510,7 +5539,7 @@ static void run_state_machine(struct tcpm_port *port)
 						       port->pps_data.active, 0);
 		tcpm_set_charge(port, false);
 		tcpm_set_state(port, hard_reset_state(port),
-			       PD_T_PS_SOURCE_OFF);
+			       pd_timers[PD_TIMER_PS_SOURCE_OFF]);
 		break;
 	case PR_SWAP_SNK_SRC_SOURCE_ON:
 		tcpm_enable_auto_vbus_discharge(port, true);
@@ -5666,7 +5695,7 @@ static void run_state_machine(struct tcpm_port *port)
 	case PORT_RESET_WAIT_OFF:
 		tcpm_set_state(port,
 			       tcpm_default_state(port),
-			       port->vbus_present ? PD_T_PS_SOURCE_OFF : 0);
+			       port->vbus_present ? pd_timers[PD_TIMER_PS_SOURCE_OFF] : 0);
 		break;
 
 	/* AMS intermediate state */
@@ -6157,7 +6186,7 @@ static void _tcpm_pd_vbus_vsafe0v(struct tcpm_port *port)
 	case SRC_ATTACH_WAIT:
 		if (tcpm_port_is_source(port))
 			tcpm_set_state(port, tcpm_try_snk(port) ? SNK_TRY : SRC_ATTACHED,
-				       PD_T_CC_DEBOUNCE);
+				       pd_timers[PD_TIMER_CC_DEBOUNCE]);
 		break;
 	case SRC_STARTUP:
 	case SRC_SEND_CAPABILITIES:
@@ -7273,6 +7302,47 @@ static int tcpm_fw_get_snk_vdos(struct tcpm_port *port, struct fwnode_handle *fw
 	return 0;
 }
 
+static int tcpm_fw_get_pd_timers(struct tcpm_port *port, struct fwnode_handle *fwnode)
+{
+	int ret, i, len;
+	u32 *buf;
+
+	/* pd-timers is an optional property */
+	ret = fwnode_property_count_u32(fwnode, "pd-timers");
+	if (ret < 0) {
+		tcpm_log(port, "Unable to locate 'pd-timers' connector property (%d)", ret);
+		return 0;
+	}
+
+	if (ret % NUM_TIMER_TABLE_COLS || ret == 0) {
+		tcpm_log(port, "Incorrect 'pd-timers' value. Found %d u32 elements in array", ret);
+		return 0;
+	}
+
+	len = min(ret, PD_NUM_TIMERS * NUM_TIMER_TABLE_COLS);
+
+	buf = kcalloc(len, sizeof(*buf), GFP_KERNEL);
+	if (!buf)
+		return -ENOMEM;
+
+	ret = fwnode_property_read_u32_array(fwnode, "pd-timers", buf, len);
+	if (ret) {
+		dev_err(port->dev, "Unable to read pd-timers property (%d)", ret);
+		goto done;
+	}
+
+	for (i = 0; i < len - 1; i += NUM_TIMER_TABLE_COLS) {
+		if (buf[i] >= PD_NUM_TIMERS)
+			tcpm_log(port, "Unable to find timer index %d, skipping.", buf[i]);
+		else
+			pd_timers[buf[i]] = buf[i + 1];
+	}
+
+done:
+	kfree(buf);
+	return ret;
+}
+
 /* Power Supply access to expose source power information */
 enum tcpm_psy_online_states {
 	TCPM_PSY_OFFLINE = 0,
@@ -7608,6 +7678,10 @@ struct tcpm_port *tcpm_register_port(struct device *dev, struct tcpc_dev *tcpc)
 	init_completion(&port->pps_complete);
 	tcpm_debugfs_init(port);
 
+	err = tcpm_fw_get_pd_timers(port, tcpc->fwnode);
+	if (err)
+		goto out_destroy_wq;
+
 	err = tcpm_fw_get_caps(port, tcpc->fwnode);
 	if (err < 0)
 		goto out_destroy_wq;
Signature · 1 line
2.46.0.598.g6f2099f65c-goog