Skip to contentSkip to conversation

Enable firmware-managed USB resources on Qcom targets

RFC In review Sriram Dash 9 participants 34 messages Mar 5, 2024 – Mar 19, 2024

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

cover Enable firmware-managed USB resources on Qcom targets

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

fw-managed dt property allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

Sriram Dash (3):
dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains
USB: dwc3: qcom: Add support for firmware managed resources
arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed
resources

 .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        |  74 ++++--
 .../bindings/phy/qcom,usb-snps-femto-v2.yaml       |  49 +++-
 .../devicetree/bindings/usb/qcom,dwc3.yaml         |  37 ++-
 arch/arm64/boot/dts/qcom/sa8775p-ride.dts          |  96 +++++--
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c            | 290 ++++++++++++++++-----
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c      | 213 ++++++++++++---
 drivers/usb/dwc3/dwc3-qcom.c                       | 259 +++++++++++++-----
 7 files changed, 801 insertions(+), 217 deletions(-)
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#1 lore raw

RFC 1/3 dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
 .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
 .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
 .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
 3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +53 -21
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
     maxItems: 5
 
   power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qmp,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
 
   resets:
     maxItems: 2
@@ -70,14 +95,6 @@ properties:
 required:
   - compatible
   - reg
-  - clocks
-  - clock-names
-  - resets
-  - reset-names
-  - vdda-phy-supply
-  - vdda-pll-supply
-  - "#clock-cells"
-  - clock-output-names
   - "#phy-cells"
 
 allOf:
@@ -86,6 +103,33 @@ allOf:
         compatible:
           contains:
             enum:
+              - qcom,sa8775p-qmp-usb3-uni-phy
+              - qcom,sc8280xp-qmp-usb3-uni-phy
+              - qcom,x1e80100-qmp-usb3-uni-phy
+    then:
+      required:
+        - power-domains
+
+  - if:
+      not:
+        required:
+          - qmp,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - reset-names
+        - vdda-phy-supply
+        - vdda-pll-supply
+        - clock-output-names
+        - "#clock-cells"
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
               - qcom,ipq6018-qmp-usb3-phy
               - qcom,ipq8074-qmp-usb3-phy
               - qcom,ipq9574-qmp-usb3-phy
@@ -144,18 +188,6 @@ allOf:
             - const: com_aux
             - const: pipe
 
-  - if:
-      properties:
-        compatible:
-          contains:
-            enum:
-              - qcom,sa8775p-qmp-usb3-uni-phy
-              - qcom,sc8280xp-qmp-usb3-uni-phy
-              - qcom,x1e80100-qmp-usb3-uni-phy
-    then:
-      required:
-        - power-domains
-
 additionalProperties: false
 
 examples:
Documentation/devicetree/bindings/phy/qcom,usb-snps-femto-v2.yaml +43 -6

61 lines not on this page · raw message

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +34 -3
index 63d150b..5bf3a29 100644
@@ -64,7 +64,31 @@ properties:
 
   power-domains:
     description: specifies a phandle to PM domain provider node
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qcom,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
 
   required-opps:
     maxItems: 1
@@ -148,13 +172,20 @@ required:
   - "#address-cells"
   - "#size-cells"
   - ranges
-  - clocks
-  - clock-names
   - interrupts
   - interrupt-names
 
 allOf:
   - if:
+      not:
+        required:
+          - qcom,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+
+  - if:
       properties:
         compatible:
           contains:
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#2 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 24 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
 .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
 .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
 .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
 3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -0
index 1e2d4dd..53b9ba9 100644

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 47

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +1 -1
@@ -44,7 +44,32 @@ properties:
     maxItems: 5
 
   power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node

Please drop all redundant descriptions. Adding them is not even related to this patch.

Quoted 4 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +4 -0
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 61

Quoted 10 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +10 -0
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer

How is this related to fw-managed? I fail to see it. Don't mix independent problems in one patch.

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+
+  qmp,fw-managed:

Please do not upstream vendor code directly, but perform basic adjustment to upstream Linux kernel. There is no such company as gmp.

Run this first through your internal review process.

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 65

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+    description:
+      Some targets allow multiple resources to be managed by firmware.

You miss clear mapping between compatibles and this property - allOf restricting it to specific SoCs.

Is this different property than qcom,controlled-remotely?

Best regards,
Krzysztof

#3 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 27 lines · Krzysztof Kozlowski
Quoted 26 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
  .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
  .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
  .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
  3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -0
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
      maxItems: 5
 
Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 47

Quoted 3 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +1 -1
    power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node

Please drop all redundant descriptions. Adding them is not even related to this patch.

Thanks Krzysztof for the super quick response !
Sure. will drop the description for power-domain
and power-doamin-names.

Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +9 -0
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
Quoted 9 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 61

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +5 -0
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer

How is this related to fw-managed? I fail to see it. Don't mix independent problems in one patch.

Some of the the resources like clocks, regulators, etc will be controlled by the firmware instead of OS. However, some resources still will be controlled by OS (interrupts for example).

So, to support the management of partial resources in Linux, and
offload the other resource management to firmware, multiple power domains are introduced. They will be corresponding to different hw blocks.

Do you suggest splitting the addition of power-domain-names and addition of fw-managed property in separate patches for bindings!

Quoted 8 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+
+  qmp,fw-managed:

Please do not upstream vendor code directly, but perform basic adjustment to upstream Linux kernel. There is no such company as gmp.

Run this first through your internal review process.

This property is newly introduced for the qmp superspeed phy and similar dt properties are introduced for hsphy and dwc3 qcom controller glue layer driver. It will govern the suspend/ resume of the resources (by firmware or OS) as required.

Quoted 8 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 65

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+    description:
+      Some targets allow multiple resources to be managed by firmware.

You miss clear mapping between compatibles and this property - allOf restricting it to specific SoCs.

Is this different property than qcom,controlled-remotely?

No. unlike "qcom,controlled-remotely", which lets the OS know only to consume the resources, "qmp,fw-managed" property will decide the resource management and trigger the suspend/ resume from OS, which will be handled by the firmware.

Can we reuse the property "qcom,controlled-remotely" here? If so, we can replace the aformentioned property with qmp phy, hsphy, and controller glue layer property. Please suggest.

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#4 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 77 lines · Sriram Dash
Quoted 27 lines · Krzysztof Kozlowski
Quoted 26 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
  .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
  .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
  .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
  3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -0
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
      maxItems: 5
 
Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 47

Quoted 3 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +1 -1
    power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node

Please drop all redundant descriptions. Adding them is not even related to this patch.

Thanks Krzysztof for the super quick response !
Sure. will drop the description for power-domain
and power-doamin-names.

Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +9 -0
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
Quoted 9 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 61

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +5 -0
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer

How is this related to fw-managed? I fail to see it. Don't mix independent problems in one patch.

Some of the the resources like clocks, regulators, etc will be controlled by the firmware instead of OS. However, some resources still will be controlled by OS (interrupts for example).

So, to support the management of partial resources in Linux, and offload the other resource management to firmware, multiple power domains are introduced. They will be corresponding to different hw blocks.

Do you suggest splitting the addition of power-domain-names and addition of fw-managed property in separate patches for bindings!

Quoted 6 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+
+  qmp,fw-managed:

Please do not upstream vendor code directly, but perform basic adjustment to upstream Linux kernel. There is no such company as gmp.

Quoted 7 lines
Quoted 2 lines

Run this first through your internal review process.

This property is newly introduced for the qmp superspeed phy and similar dt properties are introduced for hsphy and dwc3 qcom controller glue layer driver. It will govern the suspend/ resume of the resources (by firmware or OS) as required.

So that's your answer to "there is no such company as gmp"? It's not relevant at all.

Please run it through internal review first.

Best regards,
Krzysztof

#5 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 86 lines · Krzysztof Kozlowski
Quoted 77 lines · Sriram Dash
Quoted 27 lines · Krzysztof Kozlowski
Quoted 26 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
   .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
   .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
   .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
   3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -0
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
       maxItems: 5
 
Quoted 7 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 47

Quoted 3 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +1 -1
     power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node

Please drop all redundant descriptions. Adding them is not even related to this patch.

Thanks Krzysztof for the super quick response !
Sure. will drop the description for power-domain
and power-doamin-names.

Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +9 -0
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
Quoted 9 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 61

Quoted 5 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +5 -0
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer

How is this related to fw-managed? I fail to see it. Don't mix independent problems in one patch.

Some of the the resources like clocks, regulators, etc will be controlled by the firmware instead of OS. However, some resources still will be controlled by OS (interrupts for example).

So, to support the management of partial resources in Linux, and offload the other resource management to firmware, multiple power domains are introduced. They will be corresponding to different hw blocks.

Do you suggest splitting the addition of power-domain-names and addition of fw-managed property in separate patches for bindings!

Quoted 6 lines

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml properties: · line 63

Quoted 2 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +2 -0
+
+  qmp,fw-managed:

Please do not upstream vendor code directly, but perform basic adjustment to upstream Linux kernel. There is no such company as gmp.

Quoted 7 lines
Quoted 2 lines

Run this first through your internal review process.

This property is newly introduced for the qmp superspeed phy and similar dt properties are introduced for hsphy and dwc3 qcom controller glue layer driver. It will govern the suspend/ resume of the resources (by firmware or OS) as required.

Quoted 6 lines

So that's your answer to "there is no such company as gmp"? It's not relevant at all.

Please run it through internal review first.

Hi Sriram,

QMP indicates the driver name "QMP Phy" (for super speed mode of
operation), not the company name. If this property is for identification of fw management to be done / (or not to be done) in QMP Phy, then please rename is appropriately. Check how other properties are defined in the QMP bindings and add "qcom" at beginning preferably. For reference as to how properties were added to femto phy driver: [1].

[1]: https://patchwork.kernel.org/project/linux-arm-msm/patch/[email protected]/

Regards,
Krishna,

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#6 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 100 lines · Krishna Kurapati PSSNV
Quoted 91 lines · Krzysztof Kozlowski
Quoted 82 lines · Sriram Dash
Quoted 22 lines · Krzysztof Kozlowski
Quoted 21 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
   .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74
++++++++++++++++------
   .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49
++++++++++++--
   .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-

   3 files changed, 130 insertions(+), 30 deletions(-)
Quoted 15 lines
Quoted 11 lines
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -1
index 1e2d4dd..53b9ba9 100644
--- 

a/Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml
+++
b/Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml

Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +0 -0
@@ -44,7 +44,32 @@ properties:

       maxItems: 5
     power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node

Please drop all redundant descriptions. Adding them is not even related to this patch.

Thanks Krzysztof for the super quick response !
Sure. will drop the description for power-domain
and power-doamin-names.

Quoted 11 lines
Quoted 11 lines

+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name

Quoted 9 lines
Quoted 5 lines

+      corresponding to the index of an SCMI domain provider can be +      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer

How is this related to fw-managed? I fail to see it. Don't mix independent problems in one patch.

Some of the the resources like clocks, regulators, etc will be controlled by the firmware instead of OS. However, some resources still will be controlled by OS (interrupts for example).

So, to support the management of partial resources in Linux, and offload the other resource management to firmware, multiple power domains are introduced. They will be corresponding to different hw blocks.

Do you suggest splitting the addition of power-domain-names and addition of fw-managed property in separate patches for bindings!

Quoted 6 lines
Quoted 2 lines

+
+  qmp,fw-managed:

Please do not upstream vendor code directly, but perform basic adjustment to upstream Linux kernel. There is no such company as gmp.

Quoted 7 lines
Quoted 2 lines

Run this first through your internal review process.

This property is newly introduced for the qmp superspeed phy and similar dt properties are introduced for hsphy and dwc3 qcom controller glue layer driver. It will govern the suspend/ resume of the resources (by firmware or OS) as required.

Quoted 6 lines

So that's your answer to "there is no such company as gmp"? It's not relevant at all.

Please run it through internal review first.

Quoted 7 lines

Hi Sriram,

 QMP indicates the driver name "QMP Phy" (for super speed mode of
operation), not the company name. If this property is for identification of fw management to be done / (or not to be done) in QMP Phy, then please rename is appropriately. Check how other properties are defined in the QMP bindings and add "qcom" at beginning preferably. For reference as to how properties were added to femto phy driver: [1].

[1]: https://patchwork.kernel.org/project/linux-arm-msm/patch/[email protected]/

Thanks for the references Krzysztof/Krishna. I got suggestion from Dmitry on the use of the property too. Indeed we will be the scmi based clock/ PD management on SA8775. So, we will introduce a new compatible string and take the decision in driver accordingly.

Quoted 2 lines

Regards,
Krishna,

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#7 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

In reply to Sriram Dash
Quoted 217 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
 .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
 .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
 .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
 3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +53 -21
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
     maxItems: 5
 
   power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qmp,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
 
   resets:
     maxItems: 2
@@ -70,14 +95,6 @@ properties:
 required:
   - compatible
   - reg
-  - clocks
-  - clock-names
-  - resets
-  - reset-names
-  - vdda-phy-supply
-  - vdda-pll-supply
-  - "#clock-cells"
-  - clock-output-names
   - "#phy-cells"
 
 allOf:
@@ -86,6 +103,33 @@ allOf:
         compatible:
           contains:
             enum:
+              - qcom,sa8775p-qmp-usb3-uni-phy
+              - qcom,sc8280xp-qmp-usb3-uni-phy
+              - qcom,x1e80100-qmp-usb3-uni-phy
+    then:
+      required:
+        - power-domains
+
+  - if:
+      not:
+        required:
+          - qmp,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - reset-names
+        - vdda-phy-supply
+        - vdda-pll-supply
+        - clock-output-names
+        - "#clock-cells"
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
               - qcom,ipq6018-qmp-usb3-phy
               - qcom,ipq8074-qmp-usb3-phy
               - qcom,ipq9574-qmp-usb3-phy
@@ -144,18 +188,6 @@ allOf:
             - const: com_aux
             - const: pipe
 
-  - if:
-      properties:
-        compatible:
-          contains:
-            enum:
-              - qcom,sa8775p-qmp-usb3-uni-phy
-              - qcom,sc8280xp-qmp-usb3-uni-phy
-              - qcom,x1e80100-qmp-usb3-uni-phy
-    then:
-      required:
-        - power-domains
-
 additionalProperties: false
 
 examples:
Documentation/devicetree/bindings/phy/qcom,usb-snps-femto-v2.yaml +43 -6
index 0f200e3..ad2f08f 100644
@@ -49,6 +49,34 @@ properties:
     items:
       - const: ref
 
+  power-domains:
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  hsphy,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
+
   resets:
     items:
       - description: PHY core reset
@@ -154,12 +182,21 @@ required:
   - compatible
   - reg
   - "#phy-cells"
-  - clocks
-  - clock-names
-  - resets
-  - vdda-pll-supply
-  - vdda18-supply
-  - vdda33-supply
+
+
+allOf:
+  - if:
+      not:
+        required:
+          - hsphy,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - vdda-pll-supply
+        - vdda18-supply
+        - vdda33-supply
 
 additionalProperties: false
 
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +15 -1
index 63d150b..5bf3a29 100644
@@ -64,7 +64,31 @@ properties:
 
   power-domains:
     description: specifies a phandle to PM domain provider node
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml properties: · line 91

Quoted 10 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +10 -0
+  qcom,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean

I think this is an overkill. You know that SA8775 is going to use SCMI-based clocks / PD management. Thus I'd suggest adding new bindings file targeting qcom,sa8775-dwc3. Also you can drop the qcom,fw-managed property at all, let the driver decide basing on the compat string.

Quoted 27 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +9 -3
   required-opps:
     maxItems: 1
@@ -148,13 +172,20 @@ required:
   - "#address-cells"
   - "#size-cells"
   - ranges
-  - clocks
-  - clock-names
   - interrupts
   - interrupt-names
 
 allOf:
   - if:
+      not:
+        required:
+          - qcom,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+
+  - if:
       properties:
         compatible:
           contains:
--
Quoted 3 lines

2.7.4

--
With best wishes
Dmitry

#8 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 226 lines · Dmitry Baryshkov
Quoted 225 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
  .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
  .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
  .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
  3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +53 -21
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
      maxItems: 5
 
    power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qmp,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
 
    resets:
      maxItems: 2
@@ -70,14 +95,6 @@ properties:
  required:
    - compatible
    - reg
-  - clocks
-  - clock-names
-  - resets
-  - reset-names
-  - vdda-phy-supply
-  - vdda-pll-supply
-  - "#clock-cells"
-  - clock-output-names
    - "#phy-cells"
 
  allOf:
@@ -86,6 +103,33 @@ allOf:
          compatible:
            contains:
              enum:
+              - qcom,sa8775p-qmp-usb3-uni-phy
+              - qcom,sc8280xp-qmp-usb3-uni-phy
+              - qcom,x1e80100-qmp-usb3-uni-phy
+    then:
+      required:
+        - power-domains
+
+  - if:
+      not:
+        required:
+          - qmp,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - reset-names
+        - vdda-phy-supply
+        - vdda-pll-supply
+        - clock-output-names
+        - "#clock-cells"
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
                - qcom,ipq6018-qmp-usb3-phy
                - qcom,ipq8074-qmp-usb3-phy
                - qcom,ipq9574-qmp-usb3-phy
@@ -144,18 +188,6 @@ allOf:
              - const: com_aux
              - const: pipe
 
-  - if:
-      properties:
-        compatible:
-          contains:
-            enum:
-              - qcom,sa8775p-qmp-usb3-uni-phy
-              - qcom,sc8280xp-qmp-usb3-uni-phy
-              - qcom,x1e80100-qmp-usb3-uni-phy
-    then:
-      required:
-        - power-domains
-
  additionalProperties: false
 
  examples:
Documentation/devicetree/bindings/phy/qcom,usb-snps-femto-v2.yaml +43 -6
index 0f200e3..ad2f08f 100644
@@ -49,6 +49,34 @@ properties:
      items:
        - const: ref
 
+  power-domains:
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  hsphy,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
+
    resets:
      items:
        - description: PHY core reset
@@ -154,12 +182,21 @@ required:
    - compatible
    - reg
    - "#phy-cells"
-  - clocks
-  - clock-names
-  - resets
-  - vdda-pll-supply
-  - vdda18-supply
-  - vdda33-supply
+
+
+allOf:
+  - if:
+      not:
+        required:
+          - hsphy,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - vdda-pll-supply
+        - vdda18-supply
+        - vdda33-supply
 
  additionalProperties: false
 
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +23 -1
index 63d150b..5bf3a29 100644
@@ -64,7 +64,31 @@ properties:
 
    power-domains:
      description: specifies a phandle to PM domain provider node
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qcom,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
Quoted 10 lines

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml properties: · line 91

Quoted 2 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +2 -0
+      OS.
+    type: boolean

I think this is an overkill. You know that SA8775 is going to use SCMI-based clocks / PD management. Thus I'd suggest adding new bindings file targeting qcom,sa8775-dwc3. Also you can drop the qcom,fw-managed property at all, let the driver decide basing on the compat string.

Thank you for the suggestion Dmitry. I will include new compat string for SA8775 which will decide whether to use scmi based clock/ PD.

Quoted 35 lines
Quoted 27 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +9 -3
    required-opps:
      maxItems: 1
@@ -148,13 +172,20 @@ required:
    - "#address-cells"
    - "#size-cells"
    - ranges
-  - clocks
-  - clock-names
    - interrupts
    - interrupt-names
 
  allOf:
    - if:
+      not:
+        required:
+          - qcom,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+
+  - if:
        properties:
          compatible:
            contains:
--
Quoted 3 lines

2.7.4

--
With best wishes
Dmitry

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#9 lore raw

Re: [RFC 1/3] dt-bindings: usb: qcom,dwc3: Add support for multiple power-domains

Quoted 239 lines · Sriram Dash
Quoted 226 lines · Dmitry Baryshkov
Quoted 225 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

---
  .../phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml        | 74 ++++++++++++++++------
  .../bindings/phy/qcom,usb-snps-femto-v2.yaml       | 49 ++++++++++++--
  .../devicetree/bindings/usb/qcom,dwc3.yaml         | 37 ++++++++++-
  3 files changed, 130 insertions(+), 30 deletions(-)
Documentation/devicetree/bindings/phy/qcom,sc8280xp-qmp-usb3-uni-phy.yaml +53 -21
index 1e2d4dd..53b9ba9 100644
@@ -44,7 +44,32 @@ properties:
      maxItems: 5
 
    power-domains:
-    maxItems: 1
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qmp,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
 
    resets:
      maxItems: 2
@@ -70,14 +95,6 @@ properties:
  required:
    - compatible
    - reg
-  - clocks
-  - clock-names
-  - resets
-  - reset-names
-  - vdda-phy-supply
-  - vdda-pll-supply
-  - "#clock-cells"
-  - clock-output-names
    - "#phy-cells"
 
  allOf:
@@ -86,6 +103,33 @@ allOf:
          compatible:
            contains:
              enum:
+              - qcom,sa8775p-qmp-usb3-uni-phy
+              - qcom,sc8280xp-qmp-usb3-uni-phy
+              - qcom,x1e80100-qmp-usb3-uni-phy
+    then:
+      required:
+        - power-domains
+
+  - if:
+      not:
+        required:
+          - qmp,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - reset-names
+        - vdda-phy-supply
+        - vdda-pll-supply
+        - clock-output-names
+        - "#clock-cells"
+
+  - if:
+      properties:
+        compatible:
+          contains:
+            enum:
                - qcom,ipq6018-qmp-usb3-phy
                - qcom,ipq8074-qmp-usb3-phy
                - qcom,ipq9574-qmp-usb3-phy
@@ -144,18 +188,6 @@ allOf:
              - const: com_aux
              - const: pipe
 
-  - if:
-      properties:
-        compatible:
-          contains:
-            enum:
-              - qcom,sa8775p-qmp-usb3-uni-phy
-              - qcom,sc8280xp-qmp-usb3-uni-phy
-              - qcom,x1e80100-qmp-usb3-uni-phy
-    then:
-      required:
-        - power-domains
-
  additionalProperties: false
 
  examples:
Documentation/devicetree/bindings/phy/qcom,usb-snps-femto-v2.yaml +43 -6
index 0f200e3..ad2f08f 100644
@@ -49,6 +49,34 @@ properties:
      items:
        - const: ref
 
+  power-domains:
+    description: specifies a phandle to PM domain provider node
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  hsphy,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
+      OS.
+    type: boolean
+
    resets:
      items:
        - description: PHY core reset
@@ -154,12 +182,21 @@ required:
    - compatible
    - reg
    - "#phy-cells"
-  - clocks
-  - clock-names
-  - resets
-  - vdda-pll-supply
-  - vdda18-supply
-  - vdda33-supply
+
+
+allOf:
+  - if:
+      not:
+        required:
+          - hsphy,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+        - resets
+        - vdda-pll-supply
+        - vdda18-supply
+        - vdda33-supply
 
  additionalProperties: false
 
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +23 -1
index 63d150b..5bf3a29 100644
@@ -64,7 +64,31 @@ properties:
 
    power-domains:
      description: specifies a phandle to PM domain provider node
-    maxItems: 1
+    minItems: 1
+    maxItems: 2
+
+  power-domain-names:
+    description:
+      A list of power domain name strings sorted in the same order as the
+      power-domains property.
+
+      For platforms where some resource are firmware managed, the name
+      corresponding to the index of an SCMI domain provider can be
+      "usb_core" or "usb_transfer".
+    items:
+      - const: usb_core
+      - const: usb_transfer
+
+  qcom,fw-managed:
+    description:
+      Some targets allow multiple resources to be managed by firmware.
+      On these targets, tasks related to clocks, regulators, resets, and
+      interconnects can be delegated to the firmware, while the remaining
+      responsibilities are handled by Linux.
+
+      Decide if the target resources will be managed by firmware or High level
Quoted 10 lines

Documentation/devicetree/bindings/usb/qcom,dwc3.yaml properties: · line 91

Quoted 2 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +2 -0
+      OS.
+    type: boolean

I think this is an overkill. You know that SA8775 is going to use SCMI-based clocks / PD management. Thus I'd suggest adding new bindings file targeting qcom,sa8775-dwc3. Also you can drop the qcom,fw-managed property at all, let the driver decide basing on the compat string.

Quoted 3 lines

Thank you for the suggestion Dmitry. I will include new compat string for SA8775 which will decide whether to use scmi based clock/ PD.

As a reminder:
- same hardware = same compatible string
- existing DT better to continue to work. Or ask for explicit permission from Bjorn to break the ABI.

Quoted 36 lines
Quoted 36 lines
Quoted 28 lines
Documentation/devicetree/bindings/usb/qcom,dwc3.yaml +9 -3
    required-opps:
      maxItems: 1
@@ -148,13 +172,20 @@ required:
    - "#address-cells"
    - "#size-cells"
    - ranges
-  - clocks
-  - clock-names
    - interrupts
    - interrupt-names
 
  allOf:
    - if:
+      not:
+        required:
+          - qcom,fw-managed
+    then:
+      required:
+        - clocks
+        - clock-names
+
+  - if:
        properties:
          compatible:
            contains:
--
Quoted 3 lines

2.7.4

--
With best wishes
Dmitry

Signature · 2 lines
With best wishes
Dmitry
#10 lore raw

RFC 2/3 USB: dwc3: qcom: Add support for firmware managed resources

In reply to Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
 drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------
 3 files changed, 594 insertions(+), 168 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +223 -67
index 8525393..1ac1b50 100644
@@ -21,6 +21,9 @@
 
 #include "phy-qcom-qmp-common.h"
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
+
 #include "phy-qcom-qmp.h"
 #include "phy-qcom-qmp-pcs-misc-v3.h"
 #include "phy-qcom-qmp-pcs-misc-v4.h"
@@ -1212,6 +1215,9 @@ struct qmp_phy_cfg {
 	unsigned int pcs_usb_offset;
 };
 
+#define DOMAIN_GENPD_TRANSFER			0
+#define DOMAIN_GENPD_CORE			1
+
 struct qmp_usb {
 	struct device *dev;
 
@@ -1236,6 +1242,19 @@ struct qmp_usb {
 	struct phy *phy;
 
 	struct clk_fixed_rate pipe_clk_fixed;
+
+	struct dev_pm_domain_list *pd_list;
+	struct device *genpd_core;
+	struct device *genpd_transfer;
+
+	bool fw_managed;
+	/* separate resource management for fw_managed vs locally managed devices */
+	struct qmp_usb_device_ops {
+		int (*bus_resume_resource)(struct qmp_usb *qmp);
+		int (*runtime_resume_resource)(struct qmp_usb *qmp);
+		int (*bus_suspend_resource)(struct qmp_usb *qmp);
+		int (*runtime_suspend_resource)(struct qmp_usb *qmp);
+	} qmp_usb_device_ops;
 };
 
 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -1598,6 +1617,41 @@ static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = {
 	.regs			= qmp_v7_usb3phy_regs_layout,
 };
 
+static void qmp_fw_managed_domain_remove(struct qmp_usb *qmp)
+{
+	dev_pm_domain_detach_list(qmp->pd_list);
+}
+
+static int qmp_fw_managed_domain_init(struct qmp_usb *qmp)
+{
+	struct device *dev = qmp->dev;
+	struct dev_pm_domain_attach_data pd_data = {
+		.pd_flags	= PD_FLAG_NO_DEV_LINK,
+		.pd_names	= (const char*[]) { "usb_transfer", "usb_core" },
+		.num_pd_names	= 2,
+	};
+	int ret = 0;
+
+	if (!dev->pm_domain) {
+		ret = dev_pm_domain_attach_list(dev, &pd_data, &qmp->pd_list);
+		if (ret < 0) {
+			dev_err(dev, "domain attach failed %d)\n", ret);
+			return ret;
+		}
+
+		qmp->genpd_transfer = qmp->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+		qmp->genpd_core = qmp->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+
+		dev_dbg(dev, "domains attached successfully\n");
+	} else {
+		dev_dbg(dev, "domain attach fail\n");
+		return -ENODEV;
+	}
+
+	return 0;
+}
+
 static int qmp_usb_serdes_init(struct qmp_usb *qmp)
 {
 	const struct qmp_phy_cfg *cfg = qmp->cfg;
@@ -1610,11 +1664,20 @@ static int qmp_usb_serdes_init(struct qmp_usb *qmp)
 	return 0;
 }
 
-static int qmp_usb_init(struct phy *phy)
+static int fw_managed_ssphy_bus_init(struct qmp_usb *qmp)
+{
+	int ret = 0;
+
+	ret = pm_runtime_get_sync(qmp->genpd_core);
+	if (ret < 0)
+		dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+	return ret;
+}
+
+static int locally_managed_ssphy_bus_init(struct qmp_usb *qmp)
 {
-	struct qmp_usb *qmp = phy_get_drvdata(phy);
 	const struct qmp_phy_cfg *cfg = qmp->cfg;
-	void __iomem *pcs = qmp->pcs;
 	int ret;
 
 	ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
@@ -1639,8 +1702,11 @@ static int qmp_usb_init(struct phy *phy)
 	if (ret)
 		goto err_assert_reset;
 
-	qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
-
+	ret = clk_prepare_enable(qmp->pipe_clk);
+	if (ret) {
+		dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
+		return ret;
+	}
 	return 0;
 
 err_assert_reset:
@@ -1651,11 +1717,22 @@ static int qmp_usb_init(struct phy *phy)
 	return ret;
 }
 
-static int qmp_usb_exit(struct phy *phy)
+static int fw_managed_ssphy_bus_exit(struct qmp_usb *qmp)
+{
+	int ret = 0;
+
+	ret = pm_runtime_put_sync(qmp->genpd_core);
+	if (ret < 0)
+		dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+	return 0;
+}
+
+static int locally_managed_ssphy_bus_exit(struct qmp_usb *qmp)
 {
-	struct qmp_usb *qmp = phy_get_drvdata(phy);
 	const struct qmp_phy_cfg *cfg = qmp->cfg;
 
+	clk_disable_unprepare(qmp->pipe_clk);
 	reset_control_bulk_assert(qmp->num_resets, qmp->resets);
 
 	clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
@@ -1677,13 +1754,9 @@ static int qmp_usb_power_on(struct phy *phy)
 	unsigned int val;
 	int ret;
 
-	qmp_usb_serdes_init(qmp);
+	qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
 
-	ret = clk_prepare_enable(qmp->pipe_clk);
-	if (ret) {
-		dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
-		return ret;
-	}
+	qmp_usb_serdes_init(qmp);
 
 	/* Tx, Rx, and PCS configurations */
 	qmp_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1);
@@ -1708,15 +1781,10 @@ static int qmp_usb_power_on(struct phy *phy)
 				 PHY_INIT_COMPLETE_TIMEOUT);
 	if (ret) {
 		dev_err(qmp->dev, "phy initialization timed-out\n");
-		goto err_disable_pipe_clk;
+		return ret;
 	}
 
 	return 0;
-
-err_disable_pipe_clk:
-	clk_disable_unprepare(qmp->pipe_clk);
-
-	return ret;
 }
 
 static int qmp_usb_power_off(struct phy *phy)
@@ -1724,8 +1792,6 @@ static int qmp_usb_power_off(struct phy *phy)
 	struct qmp_usb *qmp = phy_get_drvdata(phy);
 	const struct qmp_phy_cfg *cfg = qmp->cfg;
 
-	clk_disable_unprepare(qmp->pipe_clk);
-
 	/* PHY reset */
 	qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
 
@@ -1742,27 +1808,30 @@ static int qmp_usb_power_off(struct phy *phy)
 
 static int qmp_usb_enable(struct phy *phy)
 {
+	struct qmp_usb *qmp = phy_get_drvdata(phy);
 	int ret;
 
-	ret = qmp_usb_init(phy);
+	ret = qmp->qmp_usb_device_ops.bus_resume_resource(qmp);
 	if (ret)
 		return ret;
 
 	ret = qmp_usb_power_on(phy);
 	if (ret)
-		qmp_usb_exit(phy);
+		qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
 
 	return ret;
 }
 
 static int qmp_usb_disable(struct phy *phy)
 {
+	struct qmp_usb *qmp = phy_get_drvdata(phy);
 	int ret;
 
 	ret = qmp_usb_power_off(phy);
 	if (ret)
 		return ret;
-	return qmp_usb_exit(phy);
+
+	return qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
 }
 
 static int qmp_usb_set_mode(struct phy *phy, enum phy_mode mode, int submode)
@@ -1828,6 +1897,25 @@ static void qmp_usb_disable_autonomous_mode(struct qmp_usb *qmp)
 	qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
 }
 
+static int locally_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+	clk_disable_unprepare(qmp->pipe_clk);
+	clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+
+	return 0;
+}
+
+static int fw_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+	int ret = 0;
+
+	ret = pm_runtime_put_sync(qmp->genpd_transfer);
+	if (ret < 0)
+		dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+	return 0;
+}
+
 static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
 {
 	struct qmp_usb *qmp = dev_get_drvdata(dev);
@@ -1841,16 +1929,44 @@ static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
 
 	qmp_usb_enable_autonomous_mode(qmp);
 
-	clk_disable_unprepare(qmp->pipe_clk);
-	clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+	qmp->qmp_usb_device_ops.runtime_suspend_resource(qmp);
 
 	return 0;
 }
 
+static int locally_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+	int ret = 0;
+
+	ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+	if (ret)
+		return ret;
+
+	ret = clk_prepare_enable(qmp->pipe_clk);
+	if (ret) {
+		dev_err(qmp->dev, "pipe_clk enable failed, err=%d\n", ret);
+		clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+		return ret;
+	}
+
+	return 0;
+}
+
+static int fw_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+	int ret = 0;
+
+	ret = pm_runtime_get_sync(qmp->genpd_transfer);
+	if (ret < 0)
+		dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+	return ret;
+}
+
 static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
 {
+	int ret;
 	struct qmp_usb *qmp = dev_get_drvdata(dev);
-	int ret = 0;
 
 	dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
 
@@ -1859,17 +1975,10 @@ static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
 		return 0;
 	}
 
-	ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+	ret = qmp->qmp_usb_device_ops.runtime_resume_resource(qmp);
 	if (ret)
 		return ret;
 
-	ret = clk_prepare_enable(qmp->pipe_clk);
-	if (ret) {
-		dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
-		clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
-		return ret;
-	}
-
 	qmp_usb_disable_autonomous_mode(qmp);
 
 	return 0;
@@ -2059,22 +2168,24 @@ static int qmp_usb_parse_dt_legacy(struct qmp_usb *qmp, struct device_node *np)
 		qmp->pcs_misc = NULL;
 	}
 
-	qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
-	if (IS_ERR(qmp->pipe_clk)) {
-		return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-				     "failed to get pipe clock\n");
-	}
+	if (!qmp->fw_managed) {
+		qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
+		if (IS_ERR(qmp->pipe_clk)) {
+			return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+					     "failed to get pipe clock\n");
+		}
 
-	ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
-	if (ret < 0)
-		return ret;
+		ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
+		if (ret < 0)
+			return ret;
 
-	qmp->num_clks = ret;
+		qmp->num_clks = ret;
 
-	ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
-				 ARRAY_SIZE(usb3phy_legacy_reset_l));
-	if (ret)
-		return ret;
+		ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
+					 ARRAY_SIZE(usb3phy_legacy_reset_l));
+		if (ret)
+			return ret;
+	}
 
 	return 0;
 }
@@ -2104,21 +2215,23 @@ static int qmp_usb_parse_dt(struct qmp_usb *qmp)
 	qmp->tx = base + offs->tx;
 	qmp->rx = base + offs->rx;
 
-	ret = qmp_usb_clk_init(qmp);
-	if (ret)
-		return ret;
-
-	qmp->pipe_clk = devm_clk_get(dev, "pipe");
-	if (IS_ERR(qmp->pipe_clk)) {
-		return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-				     "failed to get pipe clock\n");
+	if (!qmp->fw_managed) {
+		ret = qmp_usb_clk_init(qmp);
+		if (ret)
+			return ret;
+
+		qmp->pipe_clk = devm_clk_get(dev, "pipe");
+		if (IS_ERR(qmp->pipe_clk)) {
+			return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+					     "failed to get pipe clock\n");
+		}
+
+		ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
+					 ARRAY_SIZE(usb3phy_reset_l));
+		if (ret)
+			return ret;
 	}
 
-	ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
-				 ARRAY_SIZE(usb3phy_reset_l));
-	if (ret)
-		return ret;
-
 	return 0;
 }
 
@@ -2140,9 +2253,36 @@ static int qmp_usb_probe(struct platform_device *pdev)
 	if (!qmp->cfg)
 		return -EINVAL;
 
-	ret = qmp_usb_vreg_init(qmp);
-	if (ret)
-		return ret;
+	qmp->fw_managed  = device_property_read_bool(dev, "qmp,fw-managed");
+	if (qmp->fw_managed) {
+		ret = qmp_fw_managed_domain_init(qmp);
+		if (ret) {
+			dev_err(dev, "Failed to init domains. Bail out");
+			return ret;
+		}
+
+		qmp->qmp_usb_device_ops.bus_resume_resource =
+						fw_managed_ssphy_bus_init;
+		qmp->qmp_usb_device_ops.runtime_resume_resource =
+						fw_managed_ssphy_runtime_init;
+		qmp->qmp_usb_device_ops.bus_suspend_resource =
+						fw_managed_ssphy_bus_exit;
+		qmp->qmp_usb_device_ops.runtime_suspend_resource =
+						fw_managed_ssphy_runtime_exit;
+	} else {
+		ret = qmp_usb_vreg_init(qmp);
+		if (ret)
+			return ret;
+
+		qmp->qmp_usb_device_ops.bus_resume_resource =
+						locally_managed_ssphy_bus_init;
+		qmp->qmp_usb_device_ops.runtime_resume_resource =
+						locally_managed_ssphy_runtime_init;
+		qmp->qmp_usb_device_ops.bus_suspend_resource =
+						locally_managed_ssphy_bus_exit;
+		qmp->qmp_usb_device_ops.runtime_suspend_resource =
+						locally_managed_ssphy_runtime_exit;
+	}
 
 	/* Check for legacy binding with child node. */
 	np = of_get_next_available_child(dev->of_node, NULL);
@@ -2165,9 +2305,11 @@ static int qmp_usb_probe(struct platform_device *pdev)
 	 */
 	pm_runtime_forbid(dev);
 
-	ret = phy_pipe_clk_register(qmp, np);
-	if (ret)
-		goto err_node_put;
+	if (!qmp->fw_managed) {
+		ret = phy_pipe_clk_register(qmp, np);
+		if (ret)
+			goto err_node_put;
+	}
 
 	qmp->phy = devm_phy_create(dev, np, &qmp_usb_phy_ops);
 	if (IS_ERR(qmp->phy)) {
@@ -2186,9 +2328,22 @@ static int qmp_usb_probe(struct platform_device *pdev)
 
 err_node_put:
 	of_node_put(np);
+	if (qmp->fw_managed)
+		qmp_fw_managed_domain_remove(qmp);
 	return ret;
 }
 
+static void qmp_usb_remove(struct platform_device *pdev)
+{
+	struct qmp_usb *qmp = platform_get_drvdata(pdev);
+
+	if (qmp->fw_managed) {
+		pm_runtime_put_sync(qmp->genpd_core);
+		qmp_fw_managed_domain_remove(qmp);
+	}
+}
+
+
 static const struct of_device_id qmp_usb_of_match_table[] = {
 	{
 		.compatible = "qcom,ipq6018-qmp-usb3-phy",
@@ -2239,6 +2394,7 @@ MODULE_DEVICE_TABLE(of, qmp_usb_of_match_table);
 
 static struct platform_driver qmp_usb_driver = {
 	.probe		= qmp_usb_probe,
+	.remove_new	= qmp_usb_remove,
 	.driver = {
 		.name	= "qcom-qmp-usb-phy",
 		.pm	= &qmp_usb_pm_ops,
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +171 -42

355 lines not on this page · raw message

drivers/usb/dwc3/dwc3-qcom.c +200 -59

348 lines not on this page · raw message

Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#11 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

Quoted 11 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

Quoted 5 lines

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of

No "futhermore"s please, separate matters should be proposed as separate patches. Perhaps these can be sent separately and merged immediately?

Quoted 8 lines

the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
 drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------

You're making independent changes across three different drivers across two different subsystems, with different maintainers, this is not acceptable as a single patch.

drivers/phy/qualcomm/phy-qcom-qmp-usb.c line 25

Quoted 12 lines
 3 files changed, 594 insertions(+), 168 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +2 -0
index 8525393..1ac1b50 100644
@@ -21,6 +21,9 @@
 
 #include "phy-qcom-qmp-common.h"
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>

Why are these includes alone here? Integrate your changes with the driver properly.

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_phy_cfg { · line 1219

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +3 -0
+
 #include "phy-qcom-qmp.h"
 #include "phy-qcom-qmp-pcs-misc-v3.h"
 #include "phy-qcom-qmp-pcs-misc-v4.h"
@@ -1212,6 +1215,9 @@ struct qmp_phy_cfg {
 	unsigned int pcs_usb_offset;
 };
 
+#define DOMAIN_GENPD_TRANSFER			0
+#define DOMAIN_GENPD_CORE			1

Does this really represent the hardware? What hardware constructs does "transfer" and "core" maps to?

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+
 struct qmp_usb {
 	struct device *dev;
 
@@ -1236,6 +1242,19 @@ struct qmp_usb {
 	struct phy *phy;
 

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1253

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +9 -0
 	struct clk_fixed_rate pipe_clk_fixed;
+
+	struct dev_pm_domain_list *pd_list;
+	struct device *genpd_core;
+	struct device *genpd_transfer;
+
+	bool fw_managed;
+	/* separate resource management for fw_managed vs locally managed devices */
+	struct qmp_usb_device_ops {
+		int (*bus_resume_resource)(struct qmp_usb *qmp);

Not only does these function pointers make the drivers much harder to follow, your naming of these seems chosen to maximize the confusion.

In your managed case this doesn't seem to relate to any "bus", in the "local" case, this doesn't relate to a "bus", and these callbacks are decoupled from the actual runtime resume and suspend cycle of the QMP device itself...

Quoted 11 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +4 -0
+		int (*runtime_resume_resource)(struct qmp_usb *qmp);
+		int (*bus_suspend_resource)(struct qmp_usb *qmp);
+		int (*runtime_suspend_resource)(struct qmp_usb *qmp);
+	} qmp_usb_device_ops;
 };
 
 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -1598,6 +1617,41 @@ static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = {
 	.regs			= qmp_v7_usb3phy_regs_layout,
 };
 

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1629

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +10 -0
+static void qmp_fw_managed_domain_remove(struct qmp_usb *qmp)
+{
+	dev_pm_domain_detach_list(qmp->pd_list);
+}
+
+static int qmp_fw_managed_domain_init(struct qmp_usb *qmp)
+{
+	struct device *dev = qmp->dev;
+	struct dev_pm_domain_attach_data pd_data = {
+		.pd_flags	= PD_FLAG_NO_DEV_LINK,

Iiuc, you attach the two power-domains with NO_DEV_LINK, such that the pm runtime state of the device itself won't reflect on the power domains, and then you hand-code all the involved logic yourself?

Why can't you integrate with the device and use its runtime state? Please clearly explain why you're doing it like this in your commit messages.

Regards,
Bjorn

#12 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

Quoted 12 lines · Bjorn Andersson
Quoted 11 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

Quoted 9 lines
Quoted 5 lines

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of

No "futhermore"s please, separate matters should be proposed as separate patches. Perhaps these can be sent separately and merged immediately?

Thanks Bjorn.
Will take this separately.

Quoted 9 lines
Quoted 8 lines

the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

---
  drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
  drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
  drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------
Quoted 4 lines

You're making independent changes across three different drivers across two different subsystems, with different maintainers, this is not acceptable as a single patch.

Sure. will split the patches in next version.

Quoted 8 lines
Quoted 8 lines
  3 files changed, 594 insertions(+), 168 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +0 -0
index 8525393..1ac1b50 100644
@@ -21,6 +21,9 @@
 
Quoted 8 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c line 25

Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +2 -0
  #include "phy-qcom-qmp-common.h"
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>

Why are these includes alone here? Integrate your changes with the driver properly.

Sure. will take care in the next version.

Quoted 8 lines
Quoted 8 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+
  #include "phy-qcom-qmp.h"
  #include "phy-qcom-qmp-pcs-misc-v3.h"
  #include "phy-qcom-qmp-pcs-misc-v4.h"
@@ -1212,6 +1215,9 @@ struct qmp_phy_cfg {
  	unsigned int pcs_usb_offset;
  };
 
Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_phy_cfg { · line 1219

Quoted 2 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +2 -0
+#define DOMAIN_GENPD_TRANSFER			0
+#define DOMAIN_GENPD_CORE			1

Does this really represent the hardware? What hardware constructs does "transfer" and "core" maps to?

The idea was to club the resources in 2 buckets. Which are essential for the IP core to be active (ex : regulators, gdsc ) form the part or genpd core and the resources which are controlled from Clock cluster in another bucket, used for transfers.

Quoted 21 lines
Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+
  struct qmp_usb {
  	struct device *dev;
 
@@ -1236,6 +1242,19 @@ struct qmp_usb {
  	struct phy *phy;
 

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1253

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +9 -0
  	struct clk_fixed_rate pipe_clk_fixed;
+
+	struct dev_pm_domain_list *pd_list;
+	struct device *genpd_core;
+	struct device *genpd_transfer;
+
+	bool fw_managed;
+	/* separate resource management for fw_managed vs locally managed devices */
+	struct qmp_usb_device_ops {
+		int (*bus_resume_resource)(struct qmp_usb *qmp);

Not only does these function pointers make the drivers much harder to follow, your naming of these seems chosen to maximize the confusion.

Quoted 5 lines

In your managed case this doesn't seem to relate to any "bus", in the "local" case, this doesn't relate to a "bus", and these callbacks are decoupled from the actual runtime resume and suspend cycle of the QMP device itself...

Understood. Will make the decision to use fw managed method or local management of resources based on the fw_managed property rather than fixing it to function pointer.

Quoted 25 lines
Quoted 11 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +4 -0
+		int (*runtime_resume_resource)(struct qmp_usb *qmp);
+		int (*bus_suspend_resource)(struct qmp_usb *qmp);
+		int (*runtime_suspend_resource)(struct qmp_usb *qmp);
+	} qmp_usb_device_ops;
  };
 
  static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -1598,6 +1617,41 @@ static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = {
  	.regs			= qmp_v7_usb3phy_regs_layout,
  };
 

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1629

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +10 -0
+static void qmp_fw_managed_domain_remove(struct qmp_usb *qmp)
+{
+	dev_pm_domain_detach_list(qmp->pd_list);
+}
+
+static int qmp_fw_managed_domain_init(struct qmp_usb *qmp)
+{
+	struct device *dev = qmp->dev;
+	struct dev_pm_domain_attach_data pd_data = {
+		.pd_flags	= PD_FLAG_NO_DEV_LINK,

Iiuc, you attach the two power-domains with NO_DEV_LINK, such that the pm runtime state of the device itself won't reflect on the power domains, and then you hand-code all the involved logic yourself?

Quoted 4 lines
Quoted 1 line

Why can't you integrate with the device and use its runtime state?

Please clearly explain why you're doing it like this in your commit messages.

OK.
Got suggestion from Dmitry to either pass empty list or dev_pm_domain_attach twice. I will use the later.

Quoted 2 lines

Regards,
Bjorn

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#13 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

In reply to Sriram Dash
Quoted 20 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

Quoted 5 lines
---
 drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
 drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------

Thank you for mixing three different drivers in a single patch. This saves us from sending two more letters. In future please abstain from doing that and group your changes logically and atomically. Although QMP and SNPS PHYs are maintained within the same subsystem, changing them are two separate patches, as the changes are similar but unrelated.

Quoted 17 lines
 3 files changed, 594 insertions(+), 168 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +3 -0
index 8525393..1ac1b50 100644
@@ -21,6 +21,9 @@
 
 #include "phy-qcom-qmp-common.h"
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
+
 #include "phy-qcom-qmp.h"
 #include "phy-qcom-qmp-pcs-misc-v3.h"
 #include "phy-qcom-qmp-pcs-misc-v4.h"

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_phy_cfg { · line 1219

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +2 -0
@@ -1212,6 +1215,9 @@ struct qmp_phy_cfg {
        unsigned int pcs_usb_offset;
 };
 
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

Why do you need them defined on a global level if later you copy necessary data away from the list?

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+
 struct qmp_usb {
        struct device *dev;
 
@@ -1236,6 +1242,19 @@ struct qmp_usb {
        struct phy *phy;

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1252

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +8 -0
 
        struct clk_fixed_rate pipe_clk_fixed;
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+
+       bool fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct qmp_usb_device_ops {

Do you see nested structure definitions in this file? I don't think so.

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1257

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -0
+               int (*bus_resume_resource)(struct qmp_usb *qmp);
+               int (*runtime_resume_resource)(struct qmp_usb *qmp);
+               int (*bus_suspend_resource)(struct qmp_usb *qmp);
+               int (*runtime_suspend_resource)(struct qmp_usb *qmp);
+       } qmp_usb_device_ops;

Just ops, pm_ops or bus_pm_ops.

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1622

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +3 -0
 };
 
 static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -1598,6 +1617,41 @@ static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = {
        .regs                   = qmp_v7_usb3phy_regs_layout,
 };
 
+static void qmp_fw_managed_domain_remove(struct qmp_usb *qmp)
+{
+       dev_pm_domain_detach_list(qmp->pd_list);

This looks like a candidate for devm_add_action_or_reset

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1632

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +10 -0
+}
+
+static int qmp_fw_managed_domain_init(struct qmp_usb *qmp)
+{
+       struct device *dev = qmp->dev;
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };

Can you pass an empty list instead? Or instead call dev_pm_domain_attach twice, if you are not using the pd_list later on?

Quoted 26 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +22 -0
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &qmp->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               qmp->genpd_transfer = qmp->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               qmp->genpd_core = qmp->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
 static int qmp_usb_serdes_init(struct qmp_usb *qmp)
 {
        const struct qmp_phy_cfg *cfg = qmp->cfg;

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_serdes_init(struct qmp_usb *qmp) · line 1667

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -1
@@ -1610,11 +1664,20 @@ static int qmp_usb_serdes_init(struct qmp_usb *qmp)
        return 0;
 }
 
-static int qmp_usb_init(struct phy *phy)
+static int fw_managed_ssphy_bus_init(struct qmp_usb *qmp)

Please take a look around. All functions have a common naming structure, which you are not following. Please do not do that _ever_.

Quoted 19 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +11 -2
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qmp->genpd_core);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static int locally_managed_ssphy_bus_init(struct qmp_usb *qmp)
 {
-       struct qmp_usb *qmp = phy_get_drvdata(phy);
        const struct qmp_phy_cfg *cfg = qmp->cfg;
-       void __iomem *pcs = qmp->pcs;
        int ret;
 
        ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_init(struct phy *phy) · line 1709

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -2
@@ -1639,8 +1702,11 @@ static int qmp_usb_init(struct phy *phy)
        if (ret)
                goto err_assert_reset;
 
-       qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
-
+       ret = clk_prepare_enable(qmp->pipe_clk);
+       if (ret) {
+               dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
+               return ret;
+       }

Here (and further in the file) you are changing the order of SW_PWRDN bit toggling and pipe_clk enablement / disablement. Is this a safe change?
Have you tested it? If so, on which platforms?

Quoted 285 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +109 -59
        return 0;
 
 err_assert_reset:
@@ -1651,11 +1717,22 @@ static int qmp_usb_init(struct phy *phy)
        return ret;
 }
 
-static int qmp_usb_exit(struct phy *phy)
+static int fw_managed_ssphy_bus_exit(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qmp->genpd_core);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
+static int locally_managed_ssphy_bus_exit(struct qmp_usb *qmp)
 {
-       struct qmp_usb *qmp = phy_get_drvdata(phy);
        const struct qmp_phy_cfg *cfg = qmp->cfg;
 
+       clk_disable_unprepare(qmp->pipe_clk);
        reset_control_bulk_assert(qmp->num_resets, qmp->resets);
 
        clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
@@ -1677,13 +1754,9 @@ static int qmp_usb_power_on(struct phy *phy)
        unsigned int val;
        int ret;
 
-       qmp_usb_serdes_init(qmp);
+       qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
 
-       ret = clk_prepare_enable(qmp->pipe_clk);
-       if (ret) {
-               dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
-               return ret;
-       }
+       qmp_usb_serdes_init(qmp);
 
        /* Tx, Rx, and PCS configurations */
        qmp_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1);
@@ -1708,15 +1781,10 @@ static int qmp_usb_power_on(struct phy *phy)
                                 PHY_INIT_COMPLETE_TIMEOUT);
        if (ret) {
                dev_err(qmp->dev, "phy initialization timed-out\n");
-               goto err_disable_pipe_clk;
+               return ret;
        }
 
        return 0;
-
-err_disable_pipe_clk:
-       clk_disable_unprepare(qmp->pipe_clk);
-
-       return ret;
 }
 
 static int qmp_usb_power_off(struct phy *phy)
@@ -1724,8 +1792,6 @@ static int qmp_usb_power_off(struct phy *phy)
        struct qmp_usb *qmp = phy_get_drvdata(phy);
        const struct qmp_phy_cfg *cfg = qmp->cfg;
 
-       clk_disable_unprepare(qmp->pipe_clk);
-
        /* PHY reset */
        qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
 
@@ -1742,27 +1808,30 @@ static int qmp_usb_power_off(struct phy *phy)
 
 static int qmp_usb_enable(struct phy *phy)
 {
+       struct qmp_usb *qmp = phy_get_drvdata(phy);
        int ret;
 
-       ret = qmp_usb_init(phy);
+       ret = qmp->qmp_usb_device_ops.bus_resume_resource(qmp);
        if (ret)
                return ret;
 
        ret = qmp_usb_power_on(phy);
        if (ret)
-               qmp_usb_exit(phy);
+               qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
 
        return ret;
 }
 
 static int qmp_usb_disable(struct phy *phy)
 {
+       struct qmp_usb *qmp = phy_get_drvdata(phy);
        int ret;
 
        ret = qmp_usb_power_off(phy);
        if (ret)
                return ret;
-       return qmp_usb_exit(phy);
+
+       return qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
 }
 
 static int qmp_usb_set_mode(struct phy *phy, enum phy_mode mode, int submode)
@@ -1828,6 +1897,25 @@ static void qmp_usb_disable_autonomous_mode(struct qmp_usb *qmp)
        qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
 }
 
+static int locally_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+       clk_disable_unprepare(qmp->pipe_clk);
+       clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+
+       return 0;
+}
+
+static int fw_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qmp->genpd_transfer);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
 static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
 {
        struct qmp_usb *qmp = dev_get_drvdata(dev);
@@ -1841,16 +1929,44 @@ static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
 
        qmp_usb_enable_autonomous_mode(qmp);
 
-       clk_disable_unprepare(qmp->pipe_clk);
-       clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+       qmp->qmp_usb_device_ops.runtime_suspend_resource(qmp);
 
        return 0;
 }
 
+static int locally_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+       if (ret)
+               return ret;
+
+       ret = clk_prepare_enable(qmp->pipe_clk);
+       if (ret) {
+               dev_err(qmp->dev, "pipe_clk enable failed, err=%d\n", ret);
+               clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int fw_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qmp->genpd_transfer);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
 static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
 {
+       int ret;
        struct qmp_usb *qmp = dev_get_drvdata(dev);
-       int ret = 0;
 
        dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
 
@@ -1859,17 +1975,10 @@ static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
                return 0;
        }
 
-       ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+       ret = qmp->qmp_usb_device_ops.runtime_resume_resource(qmp);
        if (ret)
                return ret;
 
-       ret = clk_prepare_enable(qmp->pipe_clk);
-       if (ret) {
-               dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
-               clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
-               return ret;
-       }
-
        qmp_usb_disable_autonomous_mode(qmp);
 
        return 0;
@@ -2059,22 +2168,24 @@ static int qmp_usb_parse_dt_legacy(struct qmp_usb *qmp, struct device_node *np)
                qmp->pcs_misc = NULL;
        }
 
-       qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
-       if (IS_ERR(qmp->pipe_clk)) {
-               return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-                                    "failed to get pipe clock\n");
-       }
+       if (!qmp->fw_managed) {
+               qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
+               if (IS_ERR(qmp->pipe_clk)) {
+                       return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+                                            "failed to get pipe clock\n");
+               }
 
-       ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
-       if (ret < 0)
-               return ret;
+               ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
+               if (ret < 0)
+                       return ret;
 
-       qmp->num_clks = ret;
+               qmp->num_clks = ret;
 
-       ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
-                                ARRAY_SIZE(usb3phy_legacy_reset_l));
-       if (ret)
-               return ret;
+               ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
+                                        ARRAY_SIZE(usb3phy_legacy_reset_l));
+               if (ret)
+                       return ret;
+       }
 
        return 0;
 }
@@ -2104,21 +2215,23 @@ static int qmp_usb_parse_dt(struct qmp_usb *qmp)
        qmp->tx = base + offs->tx;
        qmp->rx = base + offs->rx;
 
-       ret = qmp_usb_clk_init(qmp);
-       if (ret)
-               return ret;
-
-       qmp->pipe_clk = devm_clk_get(dev, "pipe");
-       if (IS_ERR(qmp->pipe_clk)) {
-               return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-                                    "failed to get pipe clock\n");
+       if (!qmp->fw_managed) {
+               ret = qmp_usb_clk_init(qmp);
+               if (ret)
+                       return ret;
+
+               qmp->pipe_clk = devm_clk_get(dev, "pipe");
+               if (IS_ERR(qmp->pipe_clk)) {
+                       return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+                                            "failed to get pipe clock\n");
+               }
+
+               ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
+                                        ARRAY_SIZE(usb3phy_reset_l));
+               if (ret)
+                       return ret;
        }
 
-       ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
-                                ARRAY_SIZE(usb3phy_reset_l));
-       if (ret)
-               return ret;
-
        return 0;
 }
 
@@ -2140,9 +2253,36 @@ static int qmp_usb_probe(struct platform_device *pdev)
        if (!qmp->cfg)
                return -EINVAL;
 
-       ret = qmp_usb_vreg_init(qmp);
-       if (ret)
-               return ret;
+       qmp->fw_managed  = device_property_read_bool(dev, "qmp,fw-managed");
+       if (qmp->fw_managed) {
+               ret = qmp_fw_managed_domain_init(qmp);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out");
+                       return ret;

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_probe(struct platform_device *pdev) · line 2271

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +10 -0
+               }
+
+               qmp->qmp_usb_device_ops.bus_resume_resource =
+                                               fw_managed_ssphy_bus_init;
+               qmp->qmp_usb_device_ops.runtime_resume_resource =
+                                               fw_managed_ssphy_runtime_init;
+               qmp->qmp_usb_device_ops.bus_suspend_resource =
+                                               fw_managed_ssphy_bus_exit;
+               qmp->qmp_usb_device_ops.runtime_suspend_resource =
+                                               fw_managed_ssphy_runtime_exit;

Use a pointer to ops and constant data instead of setting function pointers manually.

Quoted 18 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +14 -0
+       } else {
+               ret = qmp_usb_vreg_init(qmp);
+               if (ret)
+                       return ret;
+
+               qmp->qmp_usb_device_ops.bus_resume_resource =
+                                               locally_managed_ssphy_bus_init;
+               qmp->qmp_usb_device_ops.runtime_resume_resource =
+                                               locally_managed_ssphy_runtime_init;
+               qmp->qmp_usb_device_ops.bus_suspend_resource =
+                                               locally_managed_ssphy_bus_exit;
+               qmp->qmp_usb_device_ops.runtime_suspend_resource =
+                                               locally_managed_ssphy_runtime_exit;
+       }
 
        /* Check for legacy binding with child node. */
        np = of_get_next_available_child(dev->of_node, NULL);

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_probe(struct platform_device *pdev) · line 2311

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +4 -3
@@ -2165,9 +2305,11 @@ static int qmp_usb_probe(struct platform_device *pdev)
         */
        pm_runtime_forbid(dev);
 
-       ret = phy_pipe_clk_register(qmp, np);
-       if (ret)
-               goto err_node_put;
+       if (!qmp->fw_managed) {
+               ret = phy_pipe_clk_register(qmp, np);
+               if (ret)
+                       goto err_node_put;

pipe_clk is an input to the GCC. If you are not registering it here, how would GCC get it?

Quoted 59 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +15 -0
+       }
 
        qmp->phy = devm_phy_create(dev, np, &qmp_usb_phy_ops);
        if (IS_ERR(qmp->phy)) {
@@ -2186,9 +2328,22 @@ static int qmp_usb_probe(struct platform_device *pdev)
 
 err_node_put:
        of_node_put(np);
+       if (qmp->fw_managed)
+               qmp_fw_managed_domain_remove(qmp);
        return ret;
 }
 
+static void qmp_usb_remove(struct platform_device *pdev)
+{
+       struct qmp_usb *qmp = platform_get_drvdata(pdev);
+
+       if (qmp->fw_managed) {
+               pm_runtime_put_sync(qmp->genpd_core);
+               qmp_fw_managed_domain_remove(qmp);
+       }
+}
+
+
 static const struct of_device_id qmp_usb_of_match_table[] = {
        {
                .compatible = "qcom,ipq6018-qmp-usb3-phy",
@@ -2239,6 +2394,7 @@ MODULE_DEVICE_TABLE(of, qmp_usb_of_match_table);
 
 static struct platform_driver qmp_usb_driver = {
        .probe          = qmp_usb_probe,
+       .remove_new     = qmp_usb_remove,
        .driver = {
                .name   = "qcom-qmp-usb-phy",
                .pm     = &qmp_usb_pm_ops,
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +4 -1
index eb0b0f6..9a1377f 100644
@@ -17,6 +17,9 @@
 #include <linux/reset.h>
 #include <linux/slab.h>
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
+
 #define USB2_PHY_USB_PHY_UTMI_CTRL0            (0x3c)
 #define SLEEPM                                 BIT(0)
 #define OPMODE_MASK                            GENMASK(4, 3)
@@ -89,7 +92,7 @@ struct override_param {
        u8      reg_val;
 };
 
-struct override_param_map {
+struct snps_femto_v2_priv_data {
        const char *prop_name;
        const struct override_param *param_table;
        u8 table_size;

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c struct phy_override_seq { · line 113

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -0
@@ -106,6 +109,9 @@ struct phy_override_seq {
 
 #define NUM_HSPHY_TUNING_PARAMS        (9)
 
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

You guessed it, see my comments for the QMP PHY changes.

Quoted 13 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +6 -0
+
 /**
  * struct qcom_snps_hsphy - snps hs phy attributes
  *
@@ -136,8 +142,54 @@ struct qcom_snps_hsphy {
        bool phy_initialized;
        enum phy_mode mode;
        struct phy_override_seq update_seq_cfg[NUM_HSPHY_TUNING_PARAMS];
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c struct qcom_snps_hsphy { · line 159

Quoted 10 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +8 -0
+       bool fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct snps_femto_v2_device_ops {
+               int (*resume_resource)(struct qcom_snps_hsphy *hsphy);
+               int (*suspend_resource)(struct qcom_snps_hsphy *hsphy);
+       } snps_femto_v2_device_ops;
+
 };
 
+static void hsphy_fw_managed_domain_remove(struct qcom_snps_hsphy *hsphy)

qcom_snps_hsphy_ prefix.

Quoted 37 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +33 -0
+{
+       dev_pm_domain_detach_list(hsphy->pd_list);
+}
+
+static int hsphy_fw_managed_domain_init(struct qcom_snps_hsphy *hsphy)
+{
+       struct device *dev = hsphy->dev;
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &hsphy->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               hsphy->genpd_transfer = hsphy->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               hsphy->genpd_core = hsphy->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
 static int qcom_snps_hsphy_clk_init(struct qcom_snps_hsphy *hsphy)
 {
        struct device *dev = hsphy->dev;

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param ls_fs_output_impedance_sc7280[] = { · line 371

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -1
@@ -316,27 +368,27 @@ static const struct override_param ls_fs_output_impedance_sc7280[] = {
        { 1310, 0 },
 };
 
-static const struct override_param_map sc7280_snps_7nm_phy[] = {
+static const struct snps_femto_v2_priv_data sc7280_snps_7nm_phy[] = {

What does this have in common with the clocks / regulators being fw-managed or not?

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param ls_fs_output_impedance_sc7280[] = { · line 377

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -1
        {
                "qcom,hs-disconnect-bp",
                hs_disconnect_sc7280,
                ARRAY_SIZE(hs_disconnect_sc7280),
                USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-               HS_DISCONNECT_MASK
+               HS_DISCONNECT_MASK,

Why? Does it require to be changed?

Quoted 37 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +4 -4
        },
        {
                "qcom,squelch-detector-bp",
                squelch_det_threshold_sc7280,
                ARRAY_SIZE(squelch_det_threshold_sc7280),
                USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-               SQUELCH_DETECTOR_MASK
+               SQUELCH_DETECTOR_MASK,
        },
        {
                "qcom,hs-amplitude-bp",
                hs_amplitude_sc7280,
                ARRAY_SIZE(hs_amplitude_sc7280),
                USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X1,
-               HS_AMPLITUDE_MASK
+               HS_AMPLITUDE_MASK,
        },
        {
                "qcom,pre-emphasis-duration-bp",
@@ -357,14 +409,14 @@ static const struct override_param_map sc7280_snps_7nm_phy[] = {
                hs_rise_fall_time_sc7280,
                ARRAY_SIZE(hs_rise_fall_time_sc7280),
                USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-               HS_RISE_FALL_MASK
+               HS_RISE_FALL_MASK,
        },
        {
                "qcom,hs-crossover-voltage-microvolt",
                hs_crossover_voltage_sc7280,
                ARRAY_SIZE(hs_crossover_voltage_sc7280),
                USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-               HS_CROSSOVER_VOLTAGE_MASK
+               HS_CROSSOVER_VOLTAGE_MASK,
        },
        {
                "qcom,hs-output-impedance-micro-ohms",

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param_map sc7280_snps_7nm_phy[] = { · line 440

Quoted 9 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -3
@@ -383,12 +435,31 @@ static const struct override_param_map sc7280_snps_7nm_phy[] = {
        {},
 };
 
-static int qcom_snps_hsphy_init(struct phy *phy)
+static int fw_managed_hsphy_init(struct qcom_snps_hsphy *hsphy)
 {
-       struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
-       int ret, i;
+       int ret = 0;

Why do you need a value here if later on you set it again?

Quoted 117 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +63 -14
-       dev_vdbg(&phy->dev, "%s(): Initializing SNPS HS phy\n", __func__);
+       ret = pm_runtime_get_sync(hsphy->genpd_core);
+       if (ret < 0)
+               dev_err(hsphy->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static int fw_managed_hsphy_exit(struct qcom_snps_hsphy *hsphy)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(hsphy->genpd_core);
+       if (ret < 0)
+               dev_err(hsphy->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
+static int locally_managed_hsphy_init(struct qcom_snps_hsphy *hsphy)
+{
+       int ret;
 
        ret = regulator_bulk_enable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
        if (ret)
@@ -396,13 +467,13 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
        ret = clk_bulk_prepare_enable(hsphy->num_clks, hsphy->clks);
        if (ret) {
-               dev_err(&phy->dev, "failed to enable clocks, %d\n", ret);
+               dev_err(hsphy->dev, "failed to enable clocks, %d\n", ret);
                goto poweroff_phy;
        }
 
        ret = reset_control_assert(hsphy->phy_reset);
        if (ret) {
-               dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
+               dev_err(hsphy->dev, "failed to assert phy_reset, %d\n", ret);
                goto disable_clks;
        }
 
@@ -410,10 +481,42 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
        ret = reset_control_deassert(hsphy->phy_reset);
        if (ret) {
-               dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
+               dev_err(hsphy->dev, "failed to de-assert phy_reset, %d\n", ret);
                goto disable_clks;
        }
 
+       return 0;
+
+disable_clks:
+       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
+poweroff_phy:
+       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
+
+       return ret;
+}
+
+static int locally_managed_hsphy_exit(struct qcom_snps_hsphy *hsphy)
+{
+       reset_control_assert(hsphy->phy_reset);
+       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
+       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
+
+       return 0;
+}
+
+static int qcom_snps_hsphy_init(struct phy *phy)
+{
+       struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
+       int ret, i;
+
+       dev_vdbg(&phy->dev, "%s(): Initializing SNPS HS phy\n", __func__);
+
+       ret = hsphy->snps_femto_v2_device_ops.resume_resource(hsphy);
+       if (ret) {
+               dev_err(&phy->dev, "Error resumeing hsphy resources %d\n", ret);
+               return ret;
+       }
+
        qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
                                        UTMI_PHY_CMN_CTRL_OVERRIDE_EN,
                                        UTMI_PHY_CMN_CTRL_OVERRIDE_EN);
@@ -467,22 +570,19 @@ static int qcom_snps_hsphy_init(struct phy *phy)
        hsphy->phy_initialized = true;
 
        return 0;
-
-disable_clks:
-       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
-poweroff_phy:
-       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
-
-       return ret;
 }
 
 static int qcom_snps_hsphy_exit(struct phy *phy)
 {
        struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
+       int ret = 0;
+
+       ret = hsphy->snps_femto_v2_device_ops.suspend_resource(hsphy);
+       if (ret) {
+               dev_err(&phy->dev, "Error suspending hsphy resources %d\n", ret);
+               return ret;
+       }
 
-       reset_control_assert(hsphy->phy_reset);
-       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
-       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
        hsphy->phy_initialized = false;
 
        return 0;

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct phy_ops qcom_snps_hsphy_gen_ops = { · line 601

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -1
@@ -497,7 +597,8 @@ static const struct phy_ops qcom_snps_hsphy_gen_ops = {
 
 static const struct of_device_id qcom_snps_hsphy_of_match_table[] = {
        { .compatible   = "qcom,sm8150-usb-hs-phy", },
-       { .compatible   = "qcom,usb-snps-hs-5nm-phy", },
+       { .compatible   = "qcom,sa8775p-usb-hs-phy", },
+       { .compatible   = "qcom,sc8280xp-usb-hs-phy", },

WTF? Please keep the fallback entry in place. It looks to me that somebody didn't read documentation on the OF device matching. Please read the code first.

Quoted 119 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +45 -17
        {
                .compatible     = "qcom,usb-snps-hs-7nm-phy",
                .data           = &sc7280_snps_7nm_phy,
@@ -513,7 +614,7 @@ static const struct dev_pm_ops qcom_snps_hsphy_pm_ops = {
 };
 
 static void qcom_snps_hsphy_override_param_update_val(
-                       const struct override_param_map map,
+                       const struct snps_femto_v2_priv_data map,
                        s32 dt_val, struct phy_override_seq *seq_entry)
 {
        int i;
@@ -541,7 +642,7 @@ static void qcom_snps_hsphy_read_override_param_seq(struct device *dev)
        s32 val;
        int ret, i;
        struct qcom_snps_hsphy *hsphy;
-       const struct override_param_map *cfg = of_device_get_match_data(dev);
+       const struct snps_femto_v2_priv_data *cfg = of_device_get_match_data(dev);
 
        if (!cfg)
                return;
@@ -580,24 +681,39 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
        if (IS_ERR(hsphy->base))
                return PTR_ERR(hsphy->base);
 
-       ret = qcom_snps_hsphy_clk_init(hsphy);
-       if (ret)
-               return dev_err_probe(dev, ret, "failed to initialize clocks\n");
 
-       hsphy->phy_reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-       if (IS_ERR(hsphy->phy_reset)) {
-               dev_err(dev, "failed to get phy core reset\n");
-               return PTR_ERR(hsphy->phy_reset);
-       }
+       hsphy->fw_managed  = device_property_read_bool(dev, "hsphy,fw-managed");
+       if (hsphy->fw_managed) {
+               ret = hsphy_fw_managed_domain_init(hsphy);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out");
+                       return ret;
+               }
 
-       num = ARRAY_SIZE(hsphy->vregs);
-       for (i = 0; i < num; i++)
-               hsphy->vregs[i].supply = qcom_snps_hsphy_vreg_names[i];
+               hsphy->snps_femto_v2_device_ops.resume_resource = fw_managed_hsphy_init;
+               hsphy->snps_femto_v2_device_ops.suspend_resource = fw_managed_hsphy_exit;
+       } else {
+               ret = qcom_snps_hsphy_clk_init(hsphy);
+               if (ret)
+                       return dev_err_probe(dev, ret, "failed to initialize clocks\n");
 
-       ret = devm_regulator_bulk_get(dev, num, hsphy->vregs);
-       if (ret)
-               return dev_err_probe(dev, ret,
-                                    "failed to get regulator supplies\n");
+               hsphy->phy_reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+               if (IS_ERR(hsphy->phy_reset)) {
+                       dev_err(dev, "failed to get phy core reset\n");
+                       return PTR_ERR(hsphy->phy_reset);
+               }
+
+               num = ARRAY_SIZE(hsphy->vregs);
+               for (i = 0; i < num; i++)
+                       hsphy->vregs[i].supply = qcom_snps_hsphy_vreg_names[i];
+
+               ret = devm_regulator_bulk_get(dev, num, hsphy->vregs);
+               if (ret)
+                       return dev_err_probe(dev, ret,
+                                            "failed to get regulator supplies\n");
+               hsphy->snps_femto_v2_device_ops.resume_resource = locally_managed_hsphy_init;
+               hsphy->snps_femto_v2_device_ops.suspend_resource = locally_managed_hsphy_exit;
+       }
 
        pm_runtime_set_active(dev);
        pm_runtime_enable(dev);
@@ -609,6 +725,8 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
 
        generic_phy = devm_phy_create(dev, NULL, &qcom_snps_hsphy_gen_ops);
        if (IS_ERR(generic_phy)) {
+               if (hsphy->fw_managed)
+                       hsphy_fw_managed_domain_remove(hsphy);
                ret = PTR_ERR(generic_phy);
                dev_err(dev, "failed to create phy, %d\n", ret);
                return ret;
@@ -628,8 +746,19 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
        return PTR_ERR_OR_ZERO(phy_provider);
 }
 
+static void qcom_snps_hsphy_remove(struct platform_device *pdev)
+{
+       struct qcom_snps_hsphy *hsphy = platform_get_drvdata(pdev);
+
+       if (hsphy->fw_managed) {
+               pm_runtime_put_sync(hsphy->genpd_core);
+               hsphy_fw_managed_domain_remove(hsphy);
+       }
+}
+
 static struct platform_driver qcom_snps_hsphy_driver = {
        .probe          = qcom_snps_hsphy_probe,
+       .remove_new     = qcom_snps_hsphy_remove,
        .driver = {
                .name   = "qcom-snps-hs-femto-v2-phy",
                .pm = &qcom_snps_hsphy_pm_ops,
drivers/usb/dwc3/dwc3-qcom.c +2 -0
index dbd6a5b..aea11d0 100644
@@ -22,6 +22,8 @@
 #include <linux/iopoll.h>
 #include <linux/usb/hcd.h>
 #include <linux/usb.h>
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
 #include "core.h"
 
 /* USB QSCRATCH Hardware registers */

drivers/usb/dwc3/dwc3-qcom.c line 59

Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c +2 -0
@@ -53,6 +55,9 @@
 #define APPS_USB_AVG_BW 0
 #define APPS_USB_PEAK_BW MBps_to_icc(40)
 
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

Same comments as before

Quoted 149 lines
drivers/usb/dwc3/dwc3-qcom.c +125 -1
+
 struct dwc3_acpi_pdata {
        u32                     qscratch_base_offset;
        u32                     qscratch_base_size;
@@ -91,8 +96,54 @@ struct dwc3_qcom {
        bool                    pm_suspended;
        struct icc_path         *icc_path_ddr;
        struct icc_path         *icc_path_apps;
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+
+       bool                    fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct qcom_dwc3_device_ops {
+               int (*resume_resource)(struct dwc3_qcom *qcom);
+               void (*suspend_resource)(struct dwc3_qcom *qcom);
+               void (*exit_resource)(struct dwc3_qcom *qcom);
+       } qcom_dwc3_device_ops;
 };
 
+static void dwc3_qcom_fw_managed_domain_remove(struct dwc3_qcom *qcom)
+{
+       dev_pm_domain_detach_list(qcom->pd_list);
+}
+
+static int dwc3_qcom_fw_managed_domain_init(struct dwc3_qcom *qcom)
+{
+       struct device *dev = qcom->dev;
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &qcom->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               qcom->genpd_transfer = qcom->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               qcom->genpd_core = qcom->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
 static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
 {
        u32 reg;
@@ -417,10 +468,87 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
        dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq, 0);
 }
 
+static void locally_managed_exit_resource(struct dwc3_qcom *qcom)
+{
+       int i;
+
+       for (i = qcom->num_clocks - 1; i >= 0; i--) {
+               clk_disable_unprepare(qcom->clks[i]);
+               clk_put(qcom->clks[i]);
+       }
+       qcom->num_clocks = 0;
+
+       dwc3_qcom_interconnect_exit(qcom);
+       reset_control_assert(qcom->resets);
+}
+
+static void fw_managed_exit_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qcom->genpd_core);
+
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to disable fw managed resources");
+
+       dwc3_qcom_fw_managed_domain_remove(qcom);
+}
+
+static int locally_managed_resume_resource(struct dwc3_qcom *qcom)
+{
+       int ret, i;
+
+       for (i = 0; i < qcom->num_clocks; i++) {
+               ret = clk_prepare_enable(qcom->clks[i]);
+               if (ret < 0) {
+                       while (--i >= 0)
+                               clk_disable_unprepare(qcom->clks[i]);
+                       return ret;
+               }
+       }
+
+       ret = dwc3_qcom_interconnect_enable(qcom);
+       if (ret)
+               dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+
+       return 0;
+}
+
+static int fw_managed_resume_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qcom->genpd_transfer);
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static void locally_managed_suspend_resource(struct dwc3_qcom *qcom)
+{
+       int i, ret;
+
+       for (i = qcom->num_clocks - 1; i >= 0; i--)
+               clk_disable_unprepare(qcom->clks[i]);
+
+       ret = dwc3_qcom_interconnect_disable(qcom);
+       if (ret)
+               dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+}
+
+static void fw_managed_suspend_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qcom->genpd_transfer);
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to disable fw managed resources");
+}
+
 static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
 {
        u32 val;
-       int i, ret;
 
        if (qcom->is_suspended)
                return 0;

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup) · line 560

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +1 -6
@@ -429,12 +557,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
        if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
                dev_err(qcom->dev, "HS-PHY not in L2\n");
 
-       for (i = qcom->num_clocks - 1; i >= 0; i--)
-               clk_disable_unprepare(qcom->clks[i]);
-
-       ret = dwc3_qcom_interconnect_disable(qcom);
-       if (ret)
-               dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+       qcom->qcom_dwc3_device_ops.suspend_resource(qcom);

Does SCMI manage interconnects too?

Quoted 140 lines
drivers/usb/dwc3/dwc3-qcom.c +58 -38
        /*
         * The role is stable during suspend as role switching is done from a
@@ -453,7 +576,6 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
 static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
 {
        int ret;
-       int i;
 
        if (!qcom->is_suspended)
                return 0;
@@ -461,18 +583,9 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
        if (dwc3_qcom_is_host(qcom) && wakeup)
                dwc3_qcom_disable_interrupts(qcom);
 
-       for (i = 0; i < qcom->num_clocks; i++) {
-               ret = clk_prepare_enable(qcom->clks[i]);
-               if (ret < 0) {
-                       while (--i >= 0)
-                               clk_disable_unprepare(qcom->clks[i]);
-                       return ret;
-               }
-       }
-
-       ret = dwc3_qcom_interconnect_enable(qcom);
-       if (ret)
-               dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+       ret = qcom->qcom_dwc3_device_ops.resume_resource(qcom);
+       if (ret < 0)
+               return ret;
 
        /* Clear existing events from PHY related to L2 in/out */
        dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG,
@@ -833,30 +946,54 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
                }
        }
 
-       qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
-       if (IS_ERR(qcom->resets)) {
-               return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
-                                    "failed to get resets\n");
-       }
+       qcom->fw_managed  = device_property_read_bool(dev, "qcom,fw-managed");
+       if (qcom->fw_managed) {
+               ret = dwc3_qcom_fw_managed_domain_init(qcom);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out\n");
+                       return ret;
+               }
+               ret = pm_runtime_resume_and_get(qcom->genpd_core);
+               if (ret < 0) {
+                       dev_err(qcom->dev, "Failed to enable %s", __func__);
+                       dwc3_qcom_fw_managed_domain_remove(qcom);
+                       return ret;
+               }
 
-       ret = reset_control_assert(qcom->resets);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
-               return ret;
-       }
+               qcom->qcom_dwc3_device_ops.resume_resource = fw_managed_resume_resource;
+               qcom->qcom_dwc3_device_ops.exit_resource = fw_managed_exit_resource;
+               qcom->qcom_dwc3_device_ops.suspend_resource = fw_managed_suspend_resource;
+       } else {
+               qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
+               if (IS_ERR(qcom->resets)) {
+                       return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
+                                            "failed to get resets\n");
+               }
 
-       usleep_range(10, 1000);
+               ret = reset_control_assert(qcom->resets);
+               if (ret) {
+                       dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
+                       return ret;
+               }
 
-       ret = reset_control_deassert(qcom->resets);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
-               goto reset_assert;
-       }
+               usleep_range(10, 1000);
 
-       ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
-       if (ret) {
-               dev_err_probe(dev, ret, "failed to get clocks\n");
-               goto reset_assert;
+               ret = reset_control_deassert(qcom->resets);
+               if (ret) {
+                       dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
+                       goto reset_assert;
+               }
+
+               ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
+               if (ret) {
+                       dev_err_probe(dev, ret, "failed to get clocks\n");
+                       goto reset_assert;
+               }
+
+               //Map the functions here for suspend resume
+               qcom->qcom_dwc3_device_ops.resume_resource = locally_managed_resume_resource;
+               qcom->qcom_dwc3_device_ops.exit_resource = locally_managed_exit_resource;
+               qcom->qcom_dwc3_device_ops.suspend_resource = locally_managed_suspend_resource;
        }
 
        res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -916,9 +1053,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
                goto free_urs;
        }
 
-       ret = dwc3_qcom_interconnect_init(qcom);
-       if (ret)
-               goto depopulate;
+       if (!qcom->fw_managed) {
+               ret = dwc3_qcom_interconnect_init(qcom);
+               if (ret)
+                       goto depopulate;
+       }
 
        qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev);
 
@@ -928,8 +1067,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
        /* register extcon to override sw_vbus on Vbus change later */
        ret = dwc3_qcom_register_extcon(qcom);
-       if (ret)
-               goto interconnect_exit;
+       if (ret) {
+               if (!qcom->fw_managed)
+                       goto interconnect_exit;
+               else
+                       goto depopulate;
+       }
 
        wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
        device_init_wakeup(&pdev->dev, wakeup_source);
@@ -956,13 +1099,19 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
        if (qcom->urs_usb)

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_probe(struct platform_device *pdev) · line 1106

Quoted 10 lines
drivers/usb/dwc3/dwc3-qcom.c +5 -3
                dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
 clk_disable:
-       for (i = qcom->num_clocks - 1; i >= 0; i--) {
-               clk_disable_unprepare(qcom->clks[i]);
-               clk_put(qcom->clks[i]);
+       if (!qcom->fw_managed) {
+               for (i = qcom->num_clocks - 1; i >= 0; i--) {
+                       clk_disable_unprepare(qcom->clks[i]);
+                       clk_put(qcom->clks[i]);
+               }

Please stick to a single style. Either have ops and functions or fw_managed checks through the code. Mixing both of them doesn't look good.

Quoted 41 lines
drivers/usb/dwc3/dwc3-qcom.c +7 -12
        }
 reset_assert:
-       reset_control_assert(qcom->resets);
-
+       if (qcom->fw_managed) {
+               pm_runtime_put_sync(qcom->genpd_core);
+               dwc3_qcom_fw_managed_domain_remove(qcom);
+       } else {
+               reset_control_assert(qcom->resets);
+       }
        return ret;
 }
 
@@ -971,7 +1120,6 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
        struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
        struct device_node *np = pdev->dev.of_node;
        struct device *dev = &pdev->dev;
-       int i;
 
        if (np) {
                of_platform_depopulate(&pdev->dev);
@@ -984,14 +1132,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
        if (qcom->urs_usb)
                dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
 
-       for (i = qcom->num_clocks - 1; i >= 0; i--) {
-               clk_disable_unprepare(qcom->clks[i]);
-               clk_put(qcom->clks[i]);
-       }
-       qcom->num_clocks = 0;
-
-       dwc3_qcom_interconnect_exit(qcom);
-       reset_control_assert(qcom->resets);
+       qcom->qcom_dwc3_device_ops.exit_resource(qcom);
 
        pm_runtime_allow(dev);
        pm_runtime_disable(dev);
--

2.7.4

Signature · 2 lines
With best wishes
Dmitry
#14 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

Quoted 27 lines · Dmitry Baryshkov
Quoted 20 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

Quoted 5 lines
---
  drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
  drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
  drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------
Quoted 7 lines

Thank you for mixing three different drivers in a single patch. This saves us from sending two more letters. In future please abstain from doing that and group your changes logically and atomically. Although QMP and SNPS PHYs are maintained within the same subsystem, changing them are two separate patches, as the changes are similar but unrelated.

Thanks for the Review Dmitry. Will take care next time.

Quoted 20 lines
Quoted 20 lines
  3 files changed, 594 insertions(+), 168 deletions(-)
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +3 -0
index 8525393..1ac1b50 100644
@@ -21,6 +21,9 @@
 
  #include "phy-qcom-qmp-common.h"
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
+
  #include "phy-qcom-qmp.h"
  #include "phy-qcom-qmp-pcs-misc-v3.h"
  #include "phy-qcom-qmp-pcs-misc-v4.h"
@@ -1212,6 +1215,9 @@ struct qmp_phy_cfg {
         unsigned int pcs_usb_offset;
  };
 
Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_phy_cfg { · line 1219

Quoted 2 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +2 -0
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

Why do you need them defined on a global level if later you copy necessary data away from the list?

OK.
They will not be needed if i use the dev_pm_domain_attach. Will update in the next revision.

Quoted 7 lines
Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+
  struct qmp_usb {
         struct device *dev;
 
@@ -1236,6 +1242,19 @@ struct qmp_usb {
         struct phy *phy;
 
Quoted 12 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1252

Quoted 9 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +8 -0
         struct clk_fixed_rate pipe_clk_fixed;
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+
+       bool fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct qmp_usb_device_ops {

Do you see nested structure definitions in this file? I don't think so.

Will drop the ops. As suggested to follow single approach, will make descision according to "fw_managed" which is unavoidable.

Quoted 15 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c struct qmp_usb { · line 1257

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -0
+               int (*bus_resume_resource)(struct qmp_usb *qmp);
+               int (*runtime_resume_resource)(struct qmp_usb *qmp);
+               int (*bus_suspend_resource)(struct qmp_usb *qmp);
+               int (*runtime_suspend_resource)(struct qmp_usb *qmp);
+       } qmp_usb_device_ops;

Just ops, pm_ops or bus_pm_ops.

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +0 -0
  };
 
  static inline void qphy_setbits(void __iomem *base, u32 offset, u32 val)
@@ -1598,6 +1617,41 @@ static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = {
         .regs                   = qmp_v7_usb3phy_regs_layout,
  };
 
Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1622

Quoted 3 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +3 -0
+static void qmp_fw_managed_domain_remove(struct qmp_usb *qmp)
+{
+       dev_pm_domain_detach_list(qmp->pd_list);

This looks like a candidate for devm_add_action_or_reset

With the dev_pm_domain_attach*, will change it to dev_pm_domain_detach

Quoted 5 lines
Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -0
+}
+
+static int qmp_fw_managed_domain_init(struct qmp_usb *qmp)
+{
+       struct device *dev = qmp->dev;
Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static const struct qmp_phy_cfg x1e80100_usb3_uniphy_cfg = { · line 1632

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -0
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };

Can you pass an empty list instead? Or instead call dev_pm_domain_attach twice, if you are not using the pd_list later on?

Thanks for the suggestion. will use dev_pm_domain_attach*.

Quoted 29 lines
Quoted 29 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +22 -0
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &qmp->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               qmp->genpd_transfer = qmp->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               qmp->genpd_core = qmp->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
  static int qmp_usb_serdes_init(struct qmp_usb *qmp)
  {
         const struct qmp_phy_cfg *cfg = qmp->cfg;
@@ -1610,11 +1664,20 @@ static int qmp_usb_serdes_init(struct qmp_usb *qmp)
         return 0;
  }
 
Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_serdes_init(struct qmp_usb *qmp) · line 1667

Quoted 2 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -1
-static int qmp_usb_init(struct phy *phy)
+static int fw_managed_ssphy_bus_init(struct qmp_usb *qmp)

Please take a look around. All functions have a common naming structure, which you are not following. Please do not do that _ever_.

Sure. will take care in next version.

Quoted 22 lines
Quoted 22 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +11 -2
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qmp->genpd_core);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static int locally_managed_ssphy_bus_init(struct qmp_usb *qmp)
  {
-       struct qmp_usb *qmp = phy_get_drvdata(phy);
         const struct qmp_phy_cfg *cfg = qmp->cfg;
-       void __iomem *pcs = qmp->pcs;
         int ret;
 
         ret = regulator_bulk_enable(cfg->num_vregs, qmp->vregs);
@@ -1639,8 +1702,11 @@ static int qmp_usb_init(struct phy *phy)
         if (ret)
                 goto err_assert_reset;
 
Quoted 13 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_init(struct phy *phy) · line 1709

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -2
-       qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
-
+       ret = clk_prepare_enable(qmp->pipe_clk);
+       if (ret) {
+               dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
+               return ret;
+       }

Here (and further in the file) you are changing the order of SW_PWRDN bit toggling and pipe_clk enablement / disablement. Is this a safe change?
Have you tested it? If so, on which platforms?

Yes. This is OK.
For the qmp usb enable, we are enabling the regulators first, then enabling the clocks and signalling phy power up, then configuring and intialising the phy.

This sequence is tested on SA8775 and SC8280.

However, as we will be deciding the sequence wrt fw_managed flag, we can keep the sequence unchanged.

Quoted 290 lines
Quoted 290 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +114 -59
         return 0;
 
  err_assert_reset:
@@ -1651,11 +1717,22 @@ static int qmp_usb_init(struct phy *phy)
         return ret;
  }
 
-static int qmp_usb_exit(struct phy *phy)
+static int fw_managed_ssphy_bus_exit(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qmp->genpd_core);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
+static int locally_managed_ssphy_bus_exit(struct qmp_usb *qmp)
  {
-       struct qmp_usb *qmp = phy_get_drvdata(phy);
         const struct qmp_phy_cfg *cfg = qmp->cfg;
 
+       clk_disable_unprepare(qmp->pipe_clk);
         reset_control_bulk_assert(qmp->num_resets, qmp->resets);
 
         clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
@@ -1677,13 +1754,9 @@ static int qmp_usb_power_on(struct phy *phy)
         unsigned int val;
         int ret;
 
-       qmp_usb_serdes_init(qmp);
+       qphy_setbits(pcs, cfg->regs[QPHY_PCS_POWER_DOWN_CONTROL], SW_PWRDN);
 
-       ret = clk_prepare_enable(qmp->pipe_clk);
-       if (ret) {
-               dev_err(qmp->dev, "pipe_clk enable failed err=%d\n", ret);
-               return ret;
-       }
+       qmp_usb_serdes_init(qmp);
 
         /* Tx, Rx, and PCS configurations */
         qmp_configure_lane(tx, cfg->tx_tbl, cfg->tx_tbl_num, 1);
@@ -1708,15 +1781,10 @@ static int qmp_usb_power_on(struct phy *phy)
                                  PHY_INIT_COMPLETE_TIMEOUT);
         if (ret) {
                 dev_err(qmp->dev, "phy initialization timed-out\n");
-               goto err_disable_pipe_clk;
+               return ret;
         }
 
         return 0;
-
-err_disable_pipe_clk:
-       clk_disable_unprepare(qmp->pipe_clk);
-
-       return ret;
  }
 
  static int qmp_usb_power_off(struct phy *phy)
@@ -1724,8 +1792,6 @@ static int qmp_usb_power_off(struct phy *phy)
         struct qmp_usb *qmp = phy_get_drvdata(phy);
         const struct qmp_phy_cfg *cfg = qmp->cfg;
 
-       clk_disable_unprepare(qmp->pipe_clk);
-
         /* PHY reset */
         qphy_setbits(qmp->pcs, cfg->regs[QPHY_SW_RESET], SW_RESET);
 
@@ -1742,27 +1808,30 @@ static int qmp_usb_power_off(struct phy *phy)
 
  static int qmp_usb_enable(struct phy *phy)
  {
+       struct qmp_usb *qmp = phy_get_drvdata(phy);
         int ret;
 
-       ret = qmp_usb_init(phy);
+       ret = qmp->qmp_usb_device_ops.bus_resume_resource(qmp);
         if (ret)
                 return ret;
 
         ret = qmp_usb_power_on(phy);
         if (ret)
-               qmp_usb_exit(phy);
+               qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
 
         return ret;
  }
 
  static int qmp_usb_disable(struct phy *phy)
  {
+       struct qmp_usb *qmp = phy_get_drvdata(phy);
         int ret;
 
         ret = qmp_usb_power_off(phy);
         if (ret)
                 return ret;
-       return qmp_usb_exit(phy);
+
+       return qmp->qmp_usb_device_ops.bus_suspend_resource(qmp);
  }
 
  static int qmp_usb_set_mode(struct phy *phy, enum phy_mode mode, int submode)
@@ -1828,6 +1897,25 @@ static void qmp_usb_disable_autonomous_mode(struct qmp_usb *qmp)
         qphy_clrbits(pcs_usb, cfg->regs[QPHY_PCS_LFPS_RXTERM_IRQ_CLEAR], IRQ_CLEAR);
  }
 
+static int locally_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+       clk_disable_unprepare(qmp->pipe_clk);
+       clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+
+       return 0;
+}
+
+static int fw_managed_ssphy_runtime_exit(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qmp->genpd_transfer);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
  static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
  {
         struct qmp_usb *qmp = dev_get_drvdata(dev);
@@ -1841,16 +1929,44 @@ static int __maybe_unused qmp_usb_runtime_suspend(struct device *dev)
 
         qmp_usb_enable_autonomous_mode(qmp);
 
-       clk_disable_unprepare(qmp->pipe_clk);
-       clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+       qmp->qmp_usb_device_ops.runtime_suspend_resource(qmp);
 
         return 0;
  }
 
+static int locally_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+       if (ret)
+               return ret;
+
+       ret = clk_prepare_enable(qmp->pipe_clk);
+       if (ret) {
+               dev_err(qmp->dev, "pipe_clk enable failed, err=%d\n", ret);
+               clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
+               return ret;
+       }
+
+       return 0;
+}
+
+static int fw_managed_ssphy_runtime_init(struct qmp_usb *qmp)
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qmp->genpd_transfer);
+       if (ret < 0)
+               dev_err(qmp->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
  static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
  {
+       int ret;
         struct qmp_usb *qmp = dev_get_drvdata(dev);
-       int ret = 0;
 
         dev_vdbg(dev, "Resuming QMP phy, mode:%d\n", qmp->mode);
 
@@ -1859,17 +1975,10 @@ static int __maybe_unused qmp_usb_runtime_resume(struct device *dev)
                 return 0;
         }
 
-       ret = clk_bulk_prepare_enable(qmp->num_clks, qmp->clks);
+       ret = qmp->qmp_usb_device_ops.runtime_resume_resource(qmp);
         if (ret)
                 return ret;
 
-       ret = clk_prepare_enable(qmp->pipe_clk);
-       if (ret) {
-               dev_err(dev, "pipe_clk enable failed, err=%d\n", ret);
-               clk_bulk_disable_unprepare(qmp->num_clks, qmp->clks);
-               return ret;
-       }
-
         qmp_usb_disable_autonomous_mode(qmp);
 
         return 0;
@@ -2059,22 +2168,24 @@ static int qmp_usb_parse_dt_legacy(struct qmp_usb *qmp, struct device_node *np)
                 qmp->pcs_misc = NULL;
         }
 
-       qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
-       if (IS_ERR(qmp->pipe_clk)) {
-               return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-                                    "failed to get pipe clock\n");
-       }
+       if (!qmp->fw_managed) {
+               qmp->pipe_clk = devm_get_clk_from_child(dev, np, NULL);
+               if (IS_ERR(qmp->pipe_clk)) {
+                       return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+                                            "failed to get pipe clock\n");
+               }
 
-       ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
-       if (ret < 0)
-               return ret;
+               ret = devm_clk_bulk_get_all(qmp->dev, &qmp->clks);
+               if (ret < 0)
+                       return ret;
 
-       qmp->num_clks = ret;
+               qmp->num_clks = ret;
 
-       ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
-                                ARRAY_SIZE(usb3phy_legacy_reset_l));
-       if (ret)
-               return ret;
+               ret = qmp_usb_reset_init(qmp, usb3phy_legacy_reset_l,
+                                        ARRAY_SIZE(usb3phy_legacy_reset_l));
+               if (ret)
+                       return ret;
+       }
 
         return 0;
  }
@@ -2104,21 +2215,23 @@ static int qmp_usb_parse_dt(struct qmp_usb *qmp)
         qmp->tx = base + offs->tx;
         qmp->rx = base + offs->rx;
 
-       ret = qmp_usb_clk_init(qmp);
-       if (ret)
-               return ret;
-
-       qmp->pipe_clk = devm_clk_get(dev, "pipe");
-       if (IS_ERR(qmp->pipe_clk)) {
-               return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
-                                    "failed to get pipe clock\n");
+       if (!qmp->fw_managed) {
+               ret = qmp_usb_clk_init(qmp);
+               if (ret)
+                       return ret;
+
+               qmp->pipe_clk = devm_clk_get(dev, "pipe");
+               if (IS_ERR(qmp->pipe_clk)) {
+                       return dev_err_probe(dev, PTR_ERR(qmp->pipe_clk),
+                                            "failed to get pipe clock\n");
+               }
+
+               ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
+                                        ARRAY_SIZE(usb3phy_reset_l));
+               if (ret)
+                       return ret;
         }
 
-       ret = qmp_usb_reset_init(qmp, usb3phy_reset_l,
-                                ARRAY_SIZE(usb3phy_reset_l));
-       if (ret)
-               return ret;
-
         return 0;
  }
 
@@ -2140,9 +2253,36 @@ static int qmp_usb_probe(struct platform_device *pdev)
         if (!qmp->cfg)
                 return -EINVAL;
 
-       ret = qmp_usb_vreg_init(qmp);
-       if (ret)
-               return ret;
+       qmp->fw_managed  = device_property_read_bool(dev, "qmp,fw-managed");
+       if (qmp->fw_managed) {
+               ret = qmp_fw_managed_domain_init(qmp);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out");
+                       return ret;
+               }
+
+               qmp->qmp_usb_device_ops.bus_resume_resource =
+                                               fw_managed_ssphy_bus_init;
+               qmp->qmp_usb_device_ops.runtime_resume_resource =
Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_probe(struct platform_device *pdev) · line 2271

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +5 -0
+                                               fw_managed_ssphy_runtime_init;
+               qmp->qmp_usb_device_ops.bus_suspend_resource =
+                                               fw_managed_ssphy_bus_exit;
+               qmp->qmp_usb_device_ops.runtime_suspend_resource =
+                                               fw_managed_ssphy_runtime_exit;

Use a pointer to ops and constant data instead of setting function pointers manually.

Will drop the ops and use fw_managed.

Quoted 21 lines
Quoted 21 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +14 -0
+       } else {
+               ret = qmp_usb_vreg_init(qmp);
+               if (ret)
+                       return ret;
+
+               qmp->qmp_usb_device_ops.bus_resume_resource =
+                                               locally_managed_ssphy_bus_init;
+               qmp->qmp_usb_device_ops.runtime_resume_resource =
+                                               locally_managed_ssphy_runtime_init;
+               qmp->qmp_usb_device_ops.bus_suspend_resource =
+                                               locally_managed_ssphy_bus_exit;
+               qmp->qmp_usb_device_ops.runtime_suspend_resource =
+                                               locally_managed_ssphy_runtime_exit;
+       }
 
         /* Check for legacy binding with child node. */
         np = of_get_next_available_child(dev->of_node, NULL);
@@ -2165,9 +2305,11 @@ static int qmp_usb_probe(struct platform_device *pdev)
          */
         pm_runtime_forbid(dev);
 
Quoted 11 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_probe(struct platform_device *pdev) · line 2311

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +4 -3
-       ret = phy_pipe_clk_register(qmp, np);
-       if (ret)
-               goto err_node_put;
+       if (!qmp->fw_managed) {
+               ret = phy_pipe_clk_register(qmp, np);
+               if (ret)
+                       goto err_node_put;

pipe_clk is an input to the GCC. If you are not registering it here, how would GCC get it?

The pipe clk will be managed by the firmware.

Quoted 89 lines
Quoted 59 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +15 -0
+       }
 
         qmp->phy = devm_phy_create(dev, np, &qmp_usb_phy_ops);
         if (IS_ERR(qmp->phy)) {
@@ -2186,9 +2328,22 @@ static int qmp_usb_probe(struct platform_device *pdev)
 
  err_node_put:
         of_node_put(np);
+       if (qmp->fw_managed)
+               qmp_fw_managed_domain_remove(qmp);
         return ret;
  }
 
+static void qmp_usb_remove(struct platform_device *pdev)
+{
+       struct qmp_usb *qmp = platform_get_drvdata(pdev);
+
+       if (qmp->fw_managed) {
+               pm_runtime_put_sync(qmp->genpd_core);
+               qmp_fw_managed_domain_remove(qmp);
+       }
+}
+
+
  static const struct of_device_id qmp_usb_of_match_table[] = {
         {
                 .compatible = "qcom,ipq6018-qmp-usb3-phy",
@@ -2239,6 +2394,7 @@ MODULE_DEVICE_TABLE(of, qmp_usb_of_match_table);
 
  static struct platform_driver qmp_usb_driver = {
         .probe          = qmp_usb_probe,
+       .remove_new     = qmp_usb_remove,
         .driver = {
                 .name   = "qcom-qmp-usb-phy",
                 .pm     = &qmp_usb_pm_ops,
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +4 -1
index eb0b0f6..9a1377f 100644
@@ -17,6 +17,9 @@
  #include <linux/reset.h>
  #include <linux/slab.h>
 
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
+
  #define USB2_PHY_USB_PHY_UTMI_CTRL0            (0x3c)
  #define SLEEPM                                 BIT(0)
  #define OPMODE_MASK                            GENMASK(4, 3)
@@ -89,7 +92,7 @@ struct override_param {
         u8      reg_val;
  };
 
-struct override_param_map {
+struct snps_femto_v2_priv_data {
         const char *prop_name;
         const struct override_param *param_table;
         u8 table_size;

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c struct phy_override_seq { · line 113

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -0
@@ -106,6 +109,9 @@ struct phy_override_seq {
 
  #define NUM_HSPHY_TUNING_PARAMS        (9)
 
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

You guessed it, see my comments for the QMP PHY changes.

Quoted 22 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +13 -0
+
  /**
   * struct qcom_snps_hsphy - snps hs phy attributes
   *
@@ -136,8 +142,54 @@ struct qcom_snps_hsphy {
         bool phy_initialized;
         enum phy_mode mode;
         struct phy_override_seq update_seq_cfg[NUM_HSPHY_TUNING_PARAMS];
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+
+       bool fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct snps_femto_v2_device_ops {
+               int (*resume_resource)(struct qcom_snps_hsphy *hsphy);
+               int (*suspend_resource)(struct qcom_snps_hsphy *hsphy);
+       } snps_femto_v2_device_ops;
+
  };
 
Quoted 4 lines

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c struct qcom_snps_hsphy { · line 159

Quoted 1 line
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -0
+static void hsphy_fw_managed_domain_remove(struct qcom_snps_hsphy *hsphy)

qcom_snps_hsphy_ prefix.

Sure. will take care in next version.

Quoted 40 lines
Quoted 40 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +33 -0
+{
+       dev_pm_domain_detach_list(hsphy->pd_list);
+}
+
+static int hsphy_fw_managed_domain_init(struct qcom_snps_hsphy *hsphy)
+{
+       struct device *dev = hsphy->dev;
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &hsphy->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               hsphy->genpd_transfer = hsphy->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               hsphy->genpd_core = hsphy->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
  static int qcom_snps_hsphy_clk_init(struct qcom_snps_hsphy *hsphy)
  {
         struct device *dev = hsphy->dev;
@@ -316,27 +368,27 @@ static const struct override_param ls_fs_output_impedance_sc7280[] = {
         { 1310, 0 },
  };
 
Quoted 6 lines

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param ls_fs_output_impedance_sc7280[] = { · line 371

Quoted 2 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -1
-static const struct override_param_map sc7280_snps_7nm_phy[] = {
+static const struct snps_femto_v2_priv_data sc7280_snps_7nm_phy[] = {

What does this have in common with the clocks / regulators being fw-managed or not?

Will update this separate to the fw managed changes.

Quoted 50 lines

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param ls_fs_output_impedance_sc7280[] = { · line 377

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +1 -1
         {
                 "qcom,hs-disconnect-bp",
                 hs_disconnect_sc7280,
                 ARRAY_SIZE(hs_disconnect_sc7280),
                 USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-               HS_DISCONNECT_MASK
+               HS_DISCONNECT_MASK,

Why? Does it require to be changed?

Quoted 40 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +4 -4
         },
         {
                 "qcom,squelch-detector-bp",
                 squelch_det_threshold_sc7280,
                 ARRAY_SIZE(squelch_det_threshold_sc7280),
                 USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X0,
-               SQUELCH_DETECTOR_MASK
+               SQUELCH_DETECTOR_MASK,
         },
         {
                 "qcom,hs-amplitude-bp",
                 hs_amplitude_sc7280,
                 ARRAY_SIZE(hs_amplitude_sc7280),
                 USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X1,
-               HS_AMPLITUDE_MASK
+               HS_AMPLITUDE_MASK,
         },
         {
                 "qcom,pre-emphasis-duration-bp",
@@ -357,14 +409,14 @@ static const struct override_param_map sc7280_snps_7nm_phy[] = {
                 hs_rise_fall_time_sc7280,
                 ARRAY_SIZE(hs_rise_fall_time_sc7280),
                 USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-               HS_RISE_FALL_MASK
+               HS_RISE_FALL_MASK,
         },
         {
                 "qcom,hs-crossover-voltage-microvolt",
                 hs_crossover_voltage_sc7280,
                 ARRAY_SIZE(hs_crossover_voltage_sc7280),
                 USB2_PHY_USB_PHY_HS_PHY_OVERRIDE_X2,
-               HS_CROSSOVER_VOLTAGE_MASK
+               HS_CROSSOVER_VOLTAGE_MASK,
         },
         {
                 "qcom,hs-output-impedance-micro-ohms",
@@ -383,12 +435,31 @@ static const struct override_param_map sc7280_snps_7nm_phy[] = {
         {},
  };
 
Quoted 9 lines

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct override_param_map sc7280_snps_7nm_phy[] = { · line 440

Quoted 6 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -3
-static int qcom_snps_hsphy_init(struct phy *phy)
+static int fw_managed_hsphy_init(struct qcom_snps_hsphy *hsphy)
  {
-       struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
-       int ret, i;
+       int ret = 0;

Why do you need a value here if later on you set it again?

Thanks.
Will not be required once we switch to fw_managed descision from ops.

Quoted 118 lines
Quoted 118 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +63 -14
-       dev_vdbg(&phy->dev, "%s(): Initializing SNPS HS phy\n", __func__);
+       ret = pm_runtime_get_sync(hsphy->genpd_core);
+       if (ret < 0)
+               dev_err(hsphy->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static int fw_managed_hsphy_exit(struct qcom_snps_hsphy *hsphy)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(hsphy->genpd_core);
+       if (ret < 0)
+               dev_err(hsphy->dev, "Failed to disable fw managed resources");
+
+       return 0;
+}
+
+static int locally_managed_hsphy_init(struct qcom_snps_hsphy *hsphy)
+{
+       int ret;
 
         ret = regulator_bulk_enable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
         if (ret)
@@ -396,13 +467,13 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
         ret = clk_bulk_prepare_enable(hsphy->num_clks, hsphy->clks);
         if (ret) {
-               dev_err(&phy->dev, "failed to enable clocks, %d\n", ret);
+               dev_err(hsphy->dev, "failed to enable clocks, %d\n", ret);
                 goto poweroff_phy;
         }
 
         ret = reset_control_assert(hsphy->phy_reset);
         if (ret) {
-               dev_err(&phy->dev, "failed to assert phy_reset, %d\n", ret);
+               dev_err(hsphy->dev, "failed to assert phy_reset, %d\n", ret);
                 goto disable_clks;
         }
 
@@ -410,10 +481,42 @@ static int qcom_snps_hsphy_init(struct phy *phy)
 
         ret = reset_control_deassert(hsphy->phy_reset);
         if (ret) {
-               dev_err(&phy->dev, "failed to de-assert phy_reset, %d\n", ret);
+               dev_err(hsphy->dev, "failed to de-assert phy_reset, %d\n", ret);
                 goto disable_clks;
         }
 
+       return 0;
+
+disable_clks:
+       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
+poweroff_phy:
+       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
+
+       return ret;
+}
+
+static int locally_managed_hsphy_exit(struct qcom_snps_hsphy *hsphy)
+{
+       reset_control_assert(hsphy->phy_reset);
+       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
+       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
+
+       return 0;
+}
+
+static int qcom_snps_hsphy_init(struct phy *phy)
+{
+       struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
+       int ret, i;
+
+       dev_vdbg(&phy->dev, "%s(): Initializing SNPS HS phy\n", __func__);
+
+       ret = hsphy->snps_femto_v2_device_ops.resume_resource(hsphy);
+       if (ret) {
+               dev_err(&phy->dev, "Error resumeing hsphy resources %d\n", ret);
+               return ret;
+       }
+
         qcom_snps_hsphy_write_mask(hsphy->base, USB2_PHY_USB_PHY_CFG0,
                                         UTMI_PHY_CMN_CTRL_OVERRIDE_EN,
                                         UTMI_PHY_CMN_CTRL_OVERRIDE_EN);
@@ -467,22 +570,19 @@ static int qcom_snps_hsphy_init(struct phy *phy)
         hsphy->phy_initialized = true;
 
         return 0;
-
-disable_clks:
-       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
-poweroff_phy:
-       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
-
-       return ret;
  }
 
  static int qcom_snps_hsphy_exit(struct phy *phy)
  {
         struct qcom_snps_hsphy *hsphy = phy_get_drvdata(phy);
+       int ret = 0;
+
+       ret = hsphy->snps_femto_v2_device_ops.suspend_resource(hsphy);
+       if (ret) {
+               dev_err(&phy->dev, "Error suspending hsphy resources %d\n", ret);
+               return ret;
+       }
 
-       reset_control_assert(hsphy->phy_reset);
-       clk_bulk_disable_unprepare(hsphy->num_clks, hsphy->clks);
-       regulator_bulk_disable(ARRAY_SIZE(hsphy->vregs), hsphy->vregs);
         hsphy->phy_initialized = false;
 
         return 0;
@@ -497,7 +597,8 @@ static const struct phy_ops qcom_snps_hsphy_gen_ops = {
 
Quoted 10 lines

drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c static const struct phy_ops qcom_snps_hsphy_gen_ops = { · line 601

Quoted 5 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +2 -1
  static const struct of_device_id qcom_snps_hsphy_of_match_table[] = {
         { .compatible   = "qcom,sm8150-usb-hs-phy", },
-       { .compatible   = "qcom,usb-snps-hs-5nm-phy", },
+       { .compatible   = "qcom,sa8775p-usb-hs-phy", },
+       { .compatible   = "qcom,sc8280xp-usb-hs-phy", },

WTF? Please keep the fallback entry in place. It looks to me that somebody didn't read documentation on the OF device matching. Please read the code first.

Will take it separately.

Quoted 279 lines
Quoted 119 lines
drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c +45 -17
         {
                 .compatible     = "qcom,usb-snps-hs-7nm-phy",
                 .data           = &sc7280_snps_7nm_phy,
@@ -513,7 +614,7 @@ static const struct dev_pm_ops qcom_snps_hsphy_pm_ops = {
  };
 
  static void qcom_snps_hsphy_override_param_update_val(
-                       const struct override_param_map map,
+                       const struct snps_femto_v2_priv_data map,
                         s32 dt_val, struct phy_override_seq *seq_entry)
  {
         int i;
@@ -541,7 +642,7 @@ static void qcom_snps_hsphy_read_override_param_seq(struct device *dev)
         s32 val;
         int ret, i;
         struct qcom_snps_hsphy *hsphy;
-       const struct override_param_map *cfg = of_device_get_match_data(dev);
+       const struct snps_femto_v2_priv_data *cfg = of_device_get_match_data(dev);
 
         if (!cfg)
                 return;
@@ -580,24 +681,39 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
         if (IS_ERR(hsphy->base))
                 return PTR_ERR(hsphy->base);
 
-       ret = qcom_snps_hsphy_clk_init(hsphy);
-       if (ret)
-               return dev_err_probe(dev, ret, "failed to initialize clocks\n");
 
-       hsphy->phy_reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
-       if (IS_ERR(hsphy->phy_reset)) {
-               dev_err(dev, "failed to get phy core reset\n");
-               return PTR_ERR(hsphy->phy_reset);
-       }
+       hsphy->fw_managed  = device_property_read_bool(dev, "hsphy,fw-managed");
+       if (hsphy->fw_managed) {
+               ret = hsphy_fw_managed_domain_init(hsphy);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out");
+                       return ret;
+               }
 
-       num = ARRAY_SIZE(hsphy->vregs);
-       for (i = 0; i < num; i++)
-               hsphy->vregs[i].supply = qcom_snps_hsphy_vreg_names[i];
+               hsphy->snps_femto_v2_device_ops.resume_resource = fw_managed_hsphy_init;
+               hsphy->snps_femto_v2_device_ops.suspend_resource = fw_managed_hsphy_exit;
+       } else {
+               ret = qcom_snps_hsphy_clk_init(hsphy);
+               if (ret)
+                       return dev_err_probe(dev, ret, "failed to initialize clocks\n");
 
-       ret = devm_regulator_bulk_get(dev, num, hsphy->vregs);
-       if (ret)
-               return dev_err_probe(dev, ret,
-                                    "failed to get regulator supplies\n");
+               hsphy->phy_reset = devm_reset_control_get_exclusive(&pdev->dev, NULL);
+               if (IS_ERR(hsphy->phy_reset)) {
+                       dev_err(dev, "failed to get phy core reset\n");
+                       return PTR_ERR(hsphy->phy_reset);
+               }
+
+               num = ARRAY_SIZE(hsphy->vregs);
+               for (i = 0; i < num; i++)
+                       hsphy->vregs[i].supply = qcom_snps_hsphy_vreg_names[i];
+
+               ret = devm_regulator_bulk_get(dev, num, hsphy->vregs);
+               if (ret)
+                       return dev_err_probe(dev, ret,
+                                            "failed to get regulator supplies\n");
+               hsphy->snps_femto_v2_device_ops.resume_resource = locally_managed_hsphy_init;
+               hsphy->snps_femto_v2_device_ops.suspend_resource = locally_managed_hsphy_exit;
+       }
 
         pm_runtime_set_active(dev);
         pm_runtime_enable(dev);
@@ -609,6 +725,8 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
 
         generic_phy = devm_phy_create(dev, NULL, &qcom_snps_hsphy_gen_ops);
         if (IS_ERR(generic_phy)) {
+               if (hsphy->fw_managed)
+                       hsphy_fw_managed_domain_remove(hsphy);
                 ret = PTR_ERR(generic_phy);
                 dev_err(dev, "failed to create phy, %d\n", ret);
                 return ret;
@@ -628,8 +746,19 @@ static int qcom_snps_hsphy_probe(struct platform_device *pdev)
         return PTR_ERR_OR_ZERO(phy_provider);
  }
 
+static void qcom_snps_hsphy_remove(struct platform_device *pdev)
+{
+       struct qcom_snps_hsphy *hsphy = platform_get_drvdata(pdev);
+
+       if (hsphy->fw_managed) {
+               pm_runtime_put_sync(hsphy->genpd_core);
+               hsphy_fw_managed_domain_remove(hsphy);
+       }
+}
+
  static struct platform_driver qcom_snps_hsphy_driver = {
         .probe          = qcom_snps_hsphy_probe,
+       .remove_new     = qcom_snps_hsphy_remove,
         .driver = {
                 .name   = "qcom-snps-hs-femto-v2-phy",
                 .pm = &qcom_snps_hsphy_pm_ops,
drivers/usb/dwc3/dwc3-qcom.c +2 -0
index dbd6a5b..aea11d0 100644
@@ -22,6 +22,8 @@
  #include <linux/iopoll.h>
  #include <linux/usb/hcd.h>
  #include <linux/usb.h>
+#include <linux/pm_opp.h>
+#include <linux/pm_domain.h>
  #include "core.h"
 
  /* USB QSCRATCH Hardware registers */

drivers/usb/dwc3/dwc3-qcom.c line 59

Quoted 5 lines
drivers/usb/dwc3/dwc3-qcom.c +2 -0
@@ -53,6 +55,9 @@
  #define APPS_USB_AVG_BW 0
  #define APPS_USB_PEAK_BW MBps_to_icc(40)
 
+#define DOMAIN_GENPD_TRANSFER                  0
+#define DOMAIN_GENPD_CORE                      1

Same comments as before

Quoted 152 lines
drivers/usb/dwc3/dwc3-qcom.c +125 -1
+
  struct dwc3_acpi_pdata {
         u32                     qscratch_base_offset;
         u32                     qscratch_base_size;
@@ -91,8 +96,54 @@ struct dwc3_qcom {
         bool                    pm_suspended;
         struct icc_path         *icc_path_ddr;
         struct icc_path         *icc_path_apps;
+
+       struct dev_pm_domain_list *pd_list;
+       struct device *genpd_core;
+       struct device *genpd_transfer;
+
+       bool                    fw_managed;
+       /* separate resource management for fw_managed vs locally managed devices */
+       struct qcom_dwc3_device_ops {
+               int (*resume_resource)(struct dwc3_qcom *qcom);
+               void (*suspend_resource)(struct dwc3_qcom *qcom);
+               void (*exit_resource)(struct dwc3_qcom *qcom);
+       } qcom_dwc3_device_ops;
  };
 
+static void dwc3_qcom_fw_managed_domain_remove(struct dwc3_qcom *qcom)
+{
+       dev_pm_domain_detach_list(qcom->pd_list);
+}
+
+static int dwc3_qcom_fw_managed_domain_init(struct dwc3_qcom *qcom)
+{
+       struct device *dev = qcom->dev;
+       struct dev_pm_domain_attach_data pd_data = {
+               .pd_flags       = PD_FLAG_NO_DEV_LINK,
+               .pd_names       = (const char*[]) { "usb_transfer", "usb_core" },
+               .num_pd_names   = 2,
+       };
+       int ret = 0;
+
+       if (!dev->pm_domain) {
+               ret = dev_pm_domain_attach_list(dev, &pd_data, &qcom->pd_list);
+               if (ret < 0) {
+                       dev_err(dev, "domain attach failed %d)\n", ret);
+                       return ret;
+               }
+
+               qcom->genpd_transfer = qcom->pd_list->pd_devs[DOMAIN_GENPD_TRANSFER];
+               qcom->genpd_core = qcom->pd_list->pd_devs[DOMAIN_GENPD_CORE];
+
+               dev_dbg(dev, "domains attached successfully\n");
+       } else {
+               dev_dbg(dev, "domain attach fail\n");
+               return -ENODEV;
+       }
+
+       return 0;
+}
+
  static inline void dwc3_qcom_setbits(void __iomem *base, u32 offset, u32 val)
  {
         u32 reg;
@@ -417,10 +468,87 @@ static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom)
         dwc3_qcom_enable_wakeup_irq(qcom->ss_phy_irq, 0);
  }
 
+static void locally_managed_exit_resource(struct dwc3_qcom *qcom)
+{
+       int i;
+
+       for (i = qcom->num_clocks - 1; i >= 0; i--) {
+               clk_disable_unprepare(qcom->clks[i]);
+               clk_put(qcom->clks[i]);
+       }
+       qcom->num_clocks = 0;
+
+       dwc3_qcom_interconnect_exit(qcom);
+       reset_control_assert(qcom->resets);
+}
+
+static void fw_managed_exit_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qcom->genpd_core);
+
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to disable fw managed resources");
+
+       dwc3_qcom_fw_managed_domain_remove(qcom);
+}
+
+static int locally_managed_resume_resource(struct dwc3_qcom *qcom)
+{
+       int ret, i;
+
+       for (i = 0; i < qcom->num_clocks; i++) {
+               ret = clk_prepare_enable(qcom->clks[i]);
+               if (ret < 0) {
+                       while (--i >= 0)
+                               clk_disable_unprepare(qcom->clks[i]);
+                       return ret;
+               }
+       }
+
+       ret = dwc3_qcom_interconnect_enable(qcom);
+       if (ret)
+               dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+
+       return 0;
+}
+
+static int fw_managed_resume_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_get_sync(qcom->genpd_transfer);
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to enable fw managed resources");
+
+       return ret;
+}
+
+static void locally_managed_suspend_resource(struct dwc3_qcom *qcom)
+{
+       int i, ret;
+
+       for (i = qcom->num_clocks - 1; i >= 0; i--)
+               clk_disable_unprepare(qcom->clks[i]);
+
+       ret = dwc3_qcom_interconnect_disable(qcom);
+       if (ret)
+               dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+}
+
+static void fw_managed_suspend_resource(struct dwc3_qcom *qcom)
+{
+       int ret = 0;
+
+       ret = pm_runtime_put_sync(qcom->genpd_transfer);
+       if (ret < 0)
+               dev_err(qcom->dev, "Failed to disable fw managed resources");
+}
+
  static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
  {
         u32 val;
-       int i, ret;
 
         if (qcom->is_suspended)
                 return 0;
@@ -429,12 +557,7 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
         if (!(val & PWR_EVNT_LPM_IN_L2_MASK))
                 dev_err(qcom->dev, "HS-PHY not in L2\n");
 
Quoted 10 lines

drivers/usb/dwc3/dwc3-qcom.c static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup) · line 560

Quoted 7 lines
drivers/usb/dwc3/dwc3-qcom.c +1 -6
-       for (i = qcom->num_clocks - 1; i >= 0; i--)
-               clk_disable_unprepare(qcom->clks[i]);
-
-       ret = dwc3_qcom_interconnect_disable(qcom);
-       if (ret)
-               dev_warn(qcom->dev, "failed to disable interconnect: %d\n", ret);
+       qcom->qcom_dwc3_device_ops.suspend_resource(qcom);

Does SCMI manage interconnects too?

Yes. SCMI will be handling interconnect also.

Quoted 146 lines
Quoted 146 lines
drivers/usb/dwc3/dwc3-qcom.c +59 -41
         /*
          * The role is stable during suspend as role switching is done from a
@@ -453,7 +576,6 @@ static int dwc3_qcom_suspend(struct dwc3_qcom *qcom, bool wakeup)
  static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
  {
         int ret;
-       int i;
 
         if (!qcom->is_suspended)
                 return 0;
@@ -461,18 +583,9 @@ static int dwc3_qcom_resume(struct dwc3_qcom *qcom, bool wakeup)
         if (dwc3_qcom_is_host(qcom) && wakeup)
                 dwc3_qcom_disable_interrupts(qcom);
 
-       for (i = 0; i < qcom->num_clocks; i++) {
-               ret = clk_prepare_enable(qcom->clks[i]);
-               if (ret < 0) {
-                       while (--i >= 0)
-                               clk_disable_unprepare(qcom->clks[i]);
-                       return ret;
-               }
-       }
-
-       ret = dwc3_qcom_interconnect_enable(qcom);
-       if (ret)
-               dev_warn(qcom->dev, "failed to enable interconnect: %d\n", ret);
+       ret = qcom->qcom_dwc3_device_ops.resume_resource(qcom);
+       if (ret < 0)
+               return ret;
 
         /* Clear existing events from PHY related to L2 in/out */
         dwc3_qcom_setbits(qcom->qscratch_base, PWR_EVNT_IRQ_STAT_REG,
@@ -833,30 +946,54 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
                 }
         }
 
-       qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
-       if (IS_ERR(qcom->resets)) {
-               return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
-                                    "failed to get resets\n");
-       }
+       qcom->fw_managed  = device_property_read_bool(dev, "qcom,fw-managed");
+       if (qcom->fw_managed) {
+               ret = dwc3_qcom_fw_managed_domain_init(qcom);
+               if (ret) {
+                       dev_err(dev, "Failed to init domains. Bail out\n");
+                       return ret;
+               }
+               ret = pm_runtime_resume_and_get(qcom->genpd_core);
+               if (ret < 0) {
+                       dev_err(qcom->dev, "Failed to enable %s", __func__);
+                       dwc3_qcom_fw_managed_domain_remove(qcom);
+                       return ret;
+               }
 
-       ret = reset_control_assert(qcom->resets);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
-               return ret;
-       }
+               qcom->qcom_dwc3_device_ops.resume_resource = fw_managed_resume_resource;
+               qcom->qcom_dwc3_device_ops.exit_resource = fw_managed_exit_resource;
+               qcom->qcom_dwc3_device_ops.suspend_resource = fw_managed_suspend_resource;
+       } else {
+               qcom->resets = devm_reset_control_array_get_optional_exclusive(dev);
+               if (IS_ERR(qcom->resets)) {
+                       return dev_err_probe(&pdev->dev, PTR_ERR(qcom->resets),
+                                            "failed to get resets\n");
+               }
 
-       usleep_range(10, 1000);
+               ret = reset_control_assert(qcom->resets);
+               if (ret) {
+                       dev_err(&pdev->dev, "failed to assert resets, err=%d\n", ret);
+                       return ret;
+               }
 
-       ret = reset_control_deassert(qcom->resets);
-       if (ret) {
-               dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
-               goto reset_assert;
-       }
+               usleep_range(10, 1000);
 
-       ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
-       if (ret) {
-               dev_err_probe(dev, ret, "failed to get clocks\n");
-               goto reset_assert;
+               ret = reset_control_deassert(qcom->resets);
+               if (ret) {
+                       dev_err(&pdev->dev, "failed to deassert resets, err=%d\n", ret);
+                       goto reset_assert;
+               }
+
+               ret = dwc3_qcom_clk_init(qcom, of_clk_get_parent_count(np));
+               if (ret) {
+                       dev_err_probe(dev, ret, "failed to get clocks\n");
+                       goto reset_assert;
+               }
+
+               //Map the functions here for suspend resume
+               qcom->qcom_dwc3_device_ops.resume_resource = locally_managed_resume_resource;
+               qcom->qcom_dwc3_device_ops.exit_resource = locally_managed_exit_resource;
+               qcom->qcom_dwc3_device_ops.suspend_resource = locally_managed_suspend_resource;
         }
 
         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -916,9 +1053,11 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
                 goto free_urs;
         }
 
-       ret = dwc3_qcom_interconnect_init(qcom);
-       if (ret)
-               goto depopulate;
+       if (!qcom->fw_managed) {
+               ret = dwc3_qcom_interconnect_init(qcom);
+               if (ret)
+                       goto depopulate;
+       }
 
         qcom->mode = usb_get_dr_mode(&qcom->dwc3->dev);
 
@@ -928,8 +1067,12 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
 
         /* register extcon to override sw_vbus on Vbus change later */
         ret = dwc3_qcom_register_extcon(qcom);
-       if (ret)
-               goto interconnect_exit;
+       if (ret) {
+               if (!qcom->fw_managed)
+                       goto interconnect_exit;
+               else
+                       goto depopulate;
+       }
 
         wakeup_source = of_property_read_bool(dev->of_node, "wakeup-source");
         device_init_wakeup(&pdev->dev, wakeup_source);
@@ -956,13 +1099,19 @@ static int dwc3_qcom_probe(struct platform_device *pdev)
         if (qcom->urs_usb)
                 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
  clk_disable:
-       for (i = qcom->num_clocks - 1; i >= 0; i--) {
-               clk_disable_unprepare(qcom->clks[i]);
-               clk_put(qcom->clks[i]);
+       if (!qcom->fw_managed) {
Quoted 9 lines

drivers/usb/dwc3/dwc3-qcom.c static void dwc3_qcom_enable_interrupts(struct dwc3_qcom *qcom) · line 478

Quoted 4 lines
drivers/usb/dwc3/dwc3-qcom.c +4 -0
+               for (i = qcom->num_clocks - 1; i >= 0; i--) {
+                       clk_disable_unprepare(qcom->clks[i]);
+                       clk_put(qcom->clks[i]);
+               }

Please stick to a single style. Either have ops and functions or fw_managed checks through the code. Mixing both of them doesn't look good.

Sure. will go with fw_managed check.

Quoted 43 lines
Quoted 41 lines
drivers/usb/dwc3/dwc3-qcom.c +7 -12
         }
  reset_assert:
-       reset_control_assert(qcom->resets);
-
+       if (qcom->fw_managed) {
+               pm_runtime_put_sync(qcom->genpd_core);
+               dwc3_qcom_fw_managed_domain_remove(qcom);
+       } else {
+               reset_control_assert(qcom->resets);
+       }
         return ret;
  }
 
@@ -971,7 +1120,6 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
         struct dwc3_qcom *qcom = platform_get_drvdata(pdev);
         struct device_node *np = pdev->dev.of_node;
         struct device *dev = &pdev->dev;
-       int i;
 
         if (np) {
                 of_platform_depopulate(&pdev->dev);
@@ -984,14 +1132,7 @@ static void dwc3_qcom_remove(struct platform_device *pdev)
         if (qcom->urs_usb)
                 dwc3_qcom_destroy_urs_usb_platdev(qcom->urs_usb);
 
-       for (i = qcom->num_clocks - 1; i >= 0; i--) {
-               clk_disable_unprepare(qcom->clks[i]);
-               clk_put(qcom->clks[i]);
-       }
-       qcom->num_clocks = 0;
-
-       dwc3_qcom_interconnect_exit(qcom);
-       reset_control_assert(qcom->resets);
+       qcom->qcom_dwc3_device_ops.exit_resource(qcom);
 
         pm_runtime_allow(dev);
         pm_runtime_disable(dev);
--

2.7.4

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#15 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

Quoted 28 lines · Sriram Dash
Quoted 26 lines · Dmitry Baryshkov
Quoted 25 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This differentiation logic allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

Furthermore, minor cleanup is performed for the private data of the SNPS Femto PHY. However, ACPI handling is omitted due to the absence of clients on the ACPI side.

---
  drivers/phy/qualcomm/phy-qcom-qmp-usb.c       | 290 ++++++++++++++++++++------
  drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c | 213 +++++++++++++++----
  drivers/usb/dwc3/dwc3-qcom.c                  | 259 +++++++++++++++++------

[skipped]

Quoted 16 lines
Quoted 4 lines
Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +0 -0
@@ -2165,9 +2305,11 @@ static int qmp_usb_probe(struct platform_device *pdev)
          */
         pm_runtime_forbid(dev);
 
Quoted 11 lines

drivers/phy/qualcomm/phy-qcom-qmp-usb.c static int qmp_usb_probe(struct platform_device *pdev) · line 2311

Quoted 7 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +4 -3
-       ret = phy_pipe_clk_register(qmp, np);
-       if (ret)
-               goto err_node_put;
+       if (!qmp->fw_managed) {
+               ret = phy_pipe_clk_register(qmp, np);
+               if (ret)
+                       goto err_node_put;

pipe_clk is an input to the GCC. If you are not registering it here, how would GCC get it?

Quoted 1 line

The pipe clk will be managed by the firmware.

Which pipe clk? Coming from the PHY to GCC or from GCC back to the PHY?

Anyway, you can not drop this, this will break the ABI. The rule of
thumb: existing DTB files MUST continue to work.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/phy/qualcomm/phy-qcom-qmp-usb.c +1 -0
+       }
 
         qmp->phy = devm_phy_create(dev, np, &qmp_usb_phy_ops);
         if (IS_ERR(qmp->phy)) {
Signature · 2 lines
With best wishes
Dmitry
#16 lore raw

Re: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources

In reply to Sriram Dash
kernel test robot noticed the following build warnings:

Hi Sriram,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build warnings:

[auto build test WARNING on next-20240305]
[cannot apply to robh/for-next usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.8-rc7 v6.8-rc6 v6.8-rc5 v6.8-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sriram-Dash/dt-bindings-usb-qcom-dwc3-Add-support-for-multiple-power-domains/20240306-010051
base:   next-20240305
patch link:    https://lore.kernel.org/r/1709657858-8563-3-git-send-email-quic_sriramd%40quicinc.com
patch subject: [RFC 2/3] USB: dwc3: qcom: Add support for firmware managed resources
config: sh-allmodconfig (https://download.01.org/0day-ci/archive/20240308/[email protected]/config)
compiler: sh4-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

>> drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c:157: warning: Function parameter or struct member 'pd_list' not described in 'qcom_snps_hsphy'
>> drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c:157: warning: Function parameter or struct member 'genpd_core' not described in 'qcom_snps_hsphy'
>> drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c:157: warning: Function parameter or struct member 'genpd_transfer' not described in 'qcom_snps_hsphy'
>> drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c:157: warning: Function parameter or struct member 'fw_managed' not described in 'qcom_snps_hsphy'
>> drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c:157: warning: Function parameter or struct member 'snps_femto_v2_device_ops' not described in 'qcom_snps_hsphy'

vim +157 drivers/phy/qualcomm/phy-qcom-snps-femto-v2.c

114
115 /**
116 * struct qcom_snps_hsphy - snps hs phy attributes
117 *
118 * @dev: device structure
119 *
120 * @phy: generic phy
121 * @base: iomapped memory space for snps hs phy
122 *
123 * @num_clks: number of clocks
124 * @clks: array of clocks
125 * @phy_reset: phy reset control
126 * @vregs: regulator supplies bulk data
127 * @phy_initialized: if PHY has been initialized correctly
128 * @mode: contains the current mode the PHY is in
129 * @update_seq_cfg: tuning parameters for phy init
130 */
131 struct qcom_snps_hsphy {
132 struct device *dev;
133
134 struct phy *phy;
135 void __iomem *base;
136
137 int num_clks;
138 struct clk_bulk_data *clks;
139 struct reset_control *phy_reset;
140 struct regulator_bulk_data vregs[SNPS_HS_NUM_VREGS];
141
142 bool phy_initialized;
143 enum phy_mode mode;
144 struct phy_override_seq update_seq_cfg[NUM_HSPHY_TUNING_PARAMS];
145
146 struct dev_pm_domain_list *pd_list;
147 struct device *genpd_core;
148 struct device *genpd_transfer;
149
150 bool fw_managed;
151 /* separate resource management for fw_managed vs locally managed devices */
152 struct snps_femto_v2_device_ops {
153 int (*resume_resource)(struct qcom_snps_hsphy *hsphy);
154 int (*suspend_resource)(struct qcom_snps_hsphy *hsphy);
155 } snps_femto_v2_device_ops;
156

 > 157	};

158

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#17 lore raw

RFC 3/3 arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

In reply to Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
 arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 19 deletions(-)
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +77 -19
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
 };
 
 &usb_0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb0_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	qcom,fw-managed;
 
 	status = "okay";
 };
@@ -775,23 +785,45 @@
 };
 
 &usb_0_hsphy {
-	vdda-pll-supply = <&vreg_l7a>;
-	vdda18-supply = <&vreg_l6c>;
-	vdda33-supply = <&vreg_l9a>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ resets;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	hsphy,fw-managed;
 
 	status = "okay";
 };
 
 &usb_0_qmpphy {
-	vdda-phy-supply = <&vreg_l1c>;
-	vdda-pll-supply = <&vreg_l7a>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ resets;
+	/delete-property/ reset-names;
+	/delete-property/ #clock-cells;
+	/delete-property/ clock-output-names;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	qmp,fw-managed;
 
 	status = "okay";
 };
 
 &usb_1 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb1_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	qcom,fw-managed;
 
 	status = "okay";
 };
@@ -801,23 +833,45 @@
 };
 
 &usb_1_hsphy {
-	vdda-pll-supply = <&vreg_l7a>;
-	vdda18-supply = <&vreg_l6c>;
-	vdda33-supply = <&vreg_l9a>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ resets;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	hsphy,fw-managed;
 
 	status = "okay";
 };
 
 &usb_1_qmpphy {
-	vdda-phy-supply = <&vreg_l1c>;
-	vdda-pll-supply = <&vreg_l7a>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ resets;
+	/delete-property/ reset-names;
+	/delete-property/ #clock-cells;
+	/delete-property/ clock-output-names;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	qmp,fw-managed;
 
 	status = "okay";
 };
 
 &usb_2 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb2_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	qcom,fw-managed;
 
 	status = "okay";
 };
@@ -827,9 +881,13 @@
 };
 
 &usb_2_hsphy {
-	vdda-pll-supply = <&vreg_l7a>;
-	vdda18-supply = <&vreg_l6c>;
-	vdda33-supply = <&vreg_l9a>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ resets;
+
+	power-domains = <TODO>, <TODO>;
+	power-domain-names = "usb_transfer", "usb_core";
+	hsphy,fw-managed;
 
 	status = "okay";
 };
Signature · 7 lines
2.7.4


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#18 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 9 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
 arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------
 1 file changed, 77 insertions(+), 19 deletions(-)

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Quoted 11 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +0 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
 };
 
 &usb_0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb0_en_state>;

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 776

Quoted 10 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +10 -0
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;

This wasn't even tested.

Best regards,
Krzysztof

#19 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 11 lines · Krzysztof Kozlowski
Quoted 9 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
  arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------
  1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 8 lines
Quoted 8 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +0 -0
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
  };
 
Quoted 16 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 776

Quoted 13 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +10 -2
  &usb_0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb0_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;

This wasn't even tested.

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#20 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 51 lines · Sriram Dash
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
  arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96
+++++++++++++++++++++++++------

  1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +4 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
   };
   &usb_0 {
-    pinctrl-names = "default";
-    pinctrl-0 = <&usb0_en_state>;
+    /delete-property/ clocks;
+    /delete-property/ clock-names;
+    /delete-property/ assigned-clocks;
+    /delete-property/ assigned-clock-rates;
Quoted 9 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 776

Quoted 6 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +6 -0
+    /delete-property/ required-opps;
+    /delete-property/ resets;
+    /delete-property/ interconnects;
+    /delete-property/ interconnect-names;
+
+    power-domains = <TODO>, <TODO>;

This wasn't even tested.

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#21 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 31 lines · Sriram Dash
Quoted 30 lines · Sriram Dash
Quoted 11 lines · Krzysztof Kozlowski
Quoted 9 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
  arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------

  1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 10 lines
Quoted 10 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +0 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
   };
   &usb_0 {
-    pinctrl-names = "default";
-    pinctrl-0 = <&usb0_en_state>;
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 774

Quoted 8 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +8 -0
+    /delete-property/ clocks;
+    /delete-property/ clock-names;
+    /delete-property/ assigned-clocks;
+    /delete-property/ assigned-clock-rates;
+    /delete-property/ required-opps;
+    /delete-property/ resets;
+    /delete-property/ interconnects;
+    /delete-property/ interconnect-names;

This is totally unacceptable.. And especially makes no sense given ride is likely the only sa8775 board in existence..

Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 775

Quoted 2 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +2 -0
+
+    power-domains = <TODO>, <TODO>;

This wasn't even tested.

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

I'm sorry, but "break compilation successfully" is not a valid test result..

Konrad

#22 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 38 lines · Konrad Dybcio
Quoted 35 lines · Sriram Dash
Quoted 34 lines · Sriram Dash
Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
  arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96
+++++++++++++++++++++++++------

  1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 13 lines
Quoted 13 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +3 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
   };
   &usb_0 {
-    pinctrl-names = "default";
-    pinctrl-0 = <&usb0_en_state>;
+    /delete-property/ clocks;
+    /delete-property/ clock-names;
+    /delete-property/ assigned-clocks;
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 774

Quoted 5 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +5 -0
+    /delete-property/ assigned-clock-rates;
+    /delete-property/ required-opps;
+    /delete-property/ resets;
+    /delete-property/ interconnects;
+    /delete-property/ interconnect-names;

This is totally unacceptable.. And especially makes no sense given ride is likely the only sa8775 board in existence..

Sure Konrad.
Will update the patches on top of the scmi based dt for sa8775.

Quoted 13 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 775

Quoted 2 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +2 -0
+
+    power-domains = <TODO>, <TODO>;

This wasn't even tested.

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

I'm sorry, but "break compilation successfully" is not a valid test result..

Konrad

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
maintainer
#23 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

In reply to Sriram Dash
Quoted 44 lines · Sriram Dash
Quoted 11 lines · Krzysztof Kozlowski
Quoted 9 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
  arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------
  1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +4 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
  };
  &usb_0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb0_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
Quoted 9 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 776

Quoted 6 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +6 -0
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;

This wasn't even tested.

Quoted 3 lines

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

So you tested this on v6.8-rcN, but you're not able to upstream this dependency? The code wouldn't compile if this patch is applied, so what do you expect that I should do with it?

Develop on upstream, test on upstream, send code that improves upstream!

Thank you,
Bjorn

Quoted 3 lines
Quoted 3 lines

Best regards,
Krzysztof

#24 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

Quoted 49 lines · Bjorn Andersson
Quoted 44 lines · Sriram Dash
Quoted 11 lines · Krzysztof Kozlowski
Quoted 9 lines · Sriram Dash

Establish the channel and domain mapping for the power domains to connect with firmware, enabling the firmware to handle the assigned resources. Since these delegated resources will remain invisible to the operating system, ensure that any references to them are removed.

---
   arch/arm64/boot/dts/qcom/sa8775p-ride.dts | 96 +++++++++++++++++++++++++------
   1 file changed, 77 insertions(+), 19 deletions(-)
Quoted 5 lines

Do not mix DTS patches with submissions to netdev or USB.

Please put it inside your internal guides, so you will not be repeating this over and over.

Sure. Will take care. Thanks.

Quoted 14 lines
Quoted 14 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +4 -2
index 26ad05b..b6c9cac 100644
@@ -764,8 +764,18 @@
   };
   &usb_0 {
-	pinctrl-names = "default";
-	pinctrl-0 = <&usb0_en_state>;
+	/delete-property/ clocks;
+	/delete-property/ clock-names;
+	/delete-property/ assigned-clocks;
+	/delete-property/ assigned-clock-rates;
Quoted 9 lines

arch/arm64/boot/dts/qcom/sa8775p-ride.dts line 776

Quoted 6 lines
arch/arm64/boot/dts/qcom/sa8775p-ride.dts +6 -0
+	/delete-property/ required-opps;
+	/delete-property/ resets;
+	/delete-property/ interconnects;
+	/delete-property/ interconnect-names;
+
+	power-domains = <TODO>, <TODO>;

This wasn't even tested.

Quoted 3 lines

This is tested with the specific power domains in place of <TODO>. SCMI interface is used for the power domains.

Quoted 6 lines

So you tested this on v6.8-rcN, but you're not able to upstream this dependency? The code wouldn't compile if this patch is applied, so what do you expect that I should do with it?

Develop on upstream, test on upstream, send code that improves upstream!

Thanks Bjorn.
Sure. I will wait for the scmi based dt support
for SA8775 and then update the patches on top.

Quoted 6 lines

Thank you,
Bjorn

Quoted 3 lines
Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#25 lore raw

Re: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources

In reply to Sriram Dash
kernel test robot noticed the following build errors:

Hi Sriram,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on next-20240305]
[cannot apply to robh/for-next usb/usb-testing usb/usb-next usb/usb-linus linus/master v6.8-rc7 v6.8-rc6 v6.8-rc5 v6.8-rc7] [If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Sriram-Dash/dt-bindings-usb-qcom-dwc3-Add-support-for-multiple-power-domains/20240306-010051
base:   next-20240305
patch link:    https://lore.kernel.org/r/1709657858-8563-4-git-send-email-quic_sriramd%40quicinc.com
patch subject: [RFC 3/3] arm64: dts: qcom: sa8775p-ride: Enable support for firmware managed resources
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20240308/[email protected]/config)
compiler: aarch64-linux-gcc (GCC) 13.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240308/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

>> Error: arch/arm64/boot/dts/qcom/sa8775p-ride.dts:776.19-20 syntax error

FATAL ERROR: Unable to parse input tree

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#26 lore raw
In reply to Sriram Dash
Quoted 1 line · Sriram Dash

Some target systems allow multiple resources to be managed by firmware.

Which? Why this is so vague...

Quoted 8 lines

On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

Quoted 8 lines

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This will break the ABI. Sorry, come with an ABI stable solution.

Best regards,
Krzysztof

#27 lore raw
Quoted 5 lines · Krzysztof Kozlowski
Quoted 1 line · Sriram Dash

Some target systems allow multiple resources to be managed by firmware.

Which? Why this is so vague...

SA8775 will be using it as pilot. Will include the target name.

Quoted 11 lines
Quoted 11 lines

On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

Quoted 8 lines
Quoted 5 lines

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This will break the ABI. Sorry, come with an ABI stable solution.

The plan is to include multiple power-domains and fw-managed property or similar in the device tree and fw-managed property will be deciding if we need some resource management offloaded to firmware. So, OS is always in control here. The decision making will be done in the drivers. Also, there will be no separate vendor hooks.

Quoted 3 lines

Best regards,
Krzysztof

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#28 lore raw
Quoted 29 lines · Sriram Dash
Quoted 5 lines · Krzysztof Kozlowski
Quoted 1 line · Sriram Dash

Some target systems allow multiple resources to be managed by firmware.

Which? Why this is so vague...

SA8775 will be using it as pilot. Will include the target name.

Quoted 11 lines
Quoted 11 lines

On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

Quoted 8 lines
Quoted 5 lines

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This will break the ABI. Sorry, come with an ABI stable solution.

Quoted 6 lines

The plan is to include multiple power-domains and fw-managed property or similar in the device tree and fw-managed property will be deciding if we need some resource management offloaded to firmware. So, OS is always in control here. The decision making will be done in the drivers. Also, there will be no separate vendor hooks.

This does not answer ABI breakage. Also, I don't have a clue what are "vendor hooks".

Best regards,
Krzysztof

#29 lore raw
Quoted 37 lines · Krzysztof Kozlowski
Quoted 29 lines · Sriram Dash
Quoted 5 lines · Krzysztof Kozlowski
Quoted 1 line · Sriram Dash

Some target systems allow multiple resources to be managed by firmware.

Which? Why this is so vague...

SA8775 will be using it as pilot. Will include the target name.

Quoted 11 lines
Quoted 11 lines

On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

Quoted 8 lines
Quoted 5 lines

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

This will break the ABI. Sorry, come with an ABI stable solution.

Quoted 6 lines

The plan is to include multiple power-domains and fw-managed property or similar in the device tree and fw-managed property will be deciding if we need some resource management offloaded to firmware. So, OS is always in control here. The decision making will be done in the drivers. Also, there will be no separate vendor hooks.

Quoted 3 lines

This does not answer ABI breakage. Also, I don't have a clue what are "vendor hooks".

Apologies for the confusion, Krysztof.
The bindings will depict whether the compatible will use clocks/ regulators, etc or not. Will take care in the next version on top of the scmi based dt solution.

Quoted 3 lines

Best regards,
Krzysztof

#30 lore raw
In reply to Sriram Dash
Quoted 4 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

Aside from the comments you already got from others, please change [RFC m/n] to [PATCH RFC m/n] so that your series isn't filtered out out maintainers' inboxes due to the missing PATCH keyword..

Konrad

#31 lore raw
Quoted 12 lines · Konrad Dybcio
Quoted 4 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

Aside from the comments you already got from others, please change [RFC m/n] to [PATCH RFC m/n] so that your series isn't filtered out out maintainers' inboxes due to the missing PATCH keyword..

Sure. thanks Konrad.

Quoted 1 line

Konrad

Signature · 3 lines
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#32 lore raw
In reply to Sriram Dash
Quoted 4 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

What is some target? What does "target" means?

Signature · 7 lines
---Trilok Soni


-- 
linux-phy mailing list
[email protected]
https://lists.infradead.org/mailman/listinfo/linux-phy
#33 lore raw
In reply to Sriram Dash
Quoted 9 lines · Sriram Dash

Some target systems allow multiple resources to be managed by firmware. On these targets, tasks related to clocks, regulators, resets, and interconnects can be delegated to the firmware, while the remaining responsibilities are handled by Linux.

To support the management of partial resources in Linux and leave the rest to firmware, multiple power domains are introduced. Each power domain can manage one or more resources, depending on the specific use case.

Currently it is just 2 IIUC. Better to be specific with more details and point to the exact binding.

Quoted 9 lines

These power domains handle SCMI calls to the firmware, enabling the activation and deactivation of firmware-managed resources.

The driver is responsible for managing multiple power domains and linking them to consumers as needed. Incase there is only single power domain, it is considered to be a standard GDSC hooked on to the qcom dt node which is read and assigned to device structure (by genpd framework) before the driver probe even begins.

Quoted 4 lines

fw-managed dt property allows the driver to determine whether device resources are managed by Linux or firmware, ensuring backward compatibility.

And provide the reason why this additional property is a must ? Why can't the implementation deal with absence of it on these systems ?

Not sure if you have seen/followed this[1] discussion before, but please do now if not already and contribute. It is definitely related to this patch set and all possible very similar patch sets Qcom might have in the future across various subsystems in the Linux kernel.

In general, Qcom must stop pushing such changes to individual drivers in isolation and confuse the reviewers to some extent without giving the complete view(or rather providing partial view) which may result in them agreeing with proposed solution without considering the overall impact on various subsystems and DT bindings.

--
Regards,
Sudeep

[1] https://lore.kernel.org/all/[email protected]/