Skip to contentSkip to conversation

Add support for Unisoc UFS host controller

PATCH In review Zhe Wang 3 participants 12 messages Nov 10, 2022 – Nov 11, 2022

Subsystems (4)
lore
Share & tools
lore

Zhe Wang

author
#0 lore raw

cover Add support for Unisoc UFS host controller

From: Zhe Wang <[email protected]>

Add this patchset to support the Unisoc UFS host controller.

Zhe Wang (2):
dt-bindings: ufs: Add document for Unisoc UFS host controller
scsi: ufs-unisoc: Add support for Unisoc UFS host controller

 .../devicetree/bindings/ufs/sprd,ufs.yaml     |  72 +++
 drivers/ufs/host/Kconfig                      |  12 +
 drivers/ufs/host/Makefile                     |   1 +
 drivers/ufs/host/ufs-sprd.c                   | 445 ++++++++++++++++++
 drivers/ufs/host/ufs-sprd.h                   | 125 +++++
 5 files changed, 655 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/sprd,ufs.yaml
 create mode 100644 drivers/ufs/host/ufs-sprd.c
 create mode 100644 drivers/ufs/host/ufs-sprd.h
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/2 dt-bindings: ufs: Add document for Unisoc UFS host controller

From: Zhe Wang <[email protected]>

Add Unisoc ums9620 ufs host controller devicetree document.

---
 .../devicetree/bindings/ufs/sprd,ufs.yaml     | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/sprd,ufs.yaml
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +72 -0
new file mode 100644
index 000000000000..88f2c670b0a4
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/ufs/sprd,ufs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc Universal Flash Storage (UFS) Controller
+
+maintainers:
+  - Zhe Wang <[email protected]>
+
+allOf:
+  - $ref: ufs-common.yaml
+
+properties:
+  compatible:
+    enum:
+      - sprd,ums9620-ufs
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: hclk
+      - const: hclk_source
+
+  resets:
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: ufs_soft_rst
+      - const: ufsdev_soft_rst
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.
+
+  sprd,aon-apb-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control always-on reg.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ufs: ufs@22000000 {
+        compatible = "sprd,ums9620-ufs";
+        reg = <0x22000000 0x3000>;
+        interrupts = <GIC_SPI 159 IRQ_TYPE_LEVEL_HIGH>;
+        vcc-supply = <&vddemmcore>;
+        vdd-mphy-supply = <&vddufs1v2>;
+        clocks-name = "ufs_eb", "ufs_cfg_eb",
+            "ufs_hclk", "ufs_hclk_source";
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;
+        reset-names = "ufs_soft_rst", "ufsdev_soft_rst";
+        resets = <&apahb_gate RESET_AP_AHB_UFS_SOFT_RST>,
+            <&aonapb_gate RESET_AON_APB_UFSDEV_SOFT_RST>;
+        sprd,ufs-anly-reg-syscon = <&anly_phy_g12_regs>;
+        sprd,aon-apb-syscon = <&aon_apb_regs>;
+        status = "disable";
+    };
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml

Quoted 15 lines · Zhe Wang

From: Zhe Wang <[email protected]>

Add Unisoc ums9620 ufs host controller devicetree document.

---
 .../devicetree/bindings/ufs/sprd,ufs.yaml     | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/sprd,ufs.yaml
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +0 -0
new file mode 100644
index 000000000000..88f2c670b0a4

Filename matching the compatible, so sprd,ums9620-ufs.yaml, unless you expect this to grow already? If so, can you post the rest?

Quoted 17 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +16 -0
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/ufs/sprd,ufs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc Universal Flash Storage (UFS) Controller
+
+maintainers:
+  - Zhe Wang <[email protected]>
+
+allOf:
+  - $ref: ufs-common.yaml
+
+properties:
+  compatible:

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 26

Quoted 10 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +10 -0
+    enum:
+      - sprd,ums9620-ufs
+
+  clocks:
+    maxItems: 2
+
+  clock-names:
+    items:
+      - const: hclk
+      - const: hclk_source

Can you make these descriptive? "clk" is redundant, so basically you are saying name is "h" and "h_source"?

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 34

Quoted 8 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +8 -0
+
+  resets:
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: ufs_soft_rst
+      - const: ufsdev_soft_rst

Drop "_rst" from both.

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +4 -0
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 42

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+  sprd,aon-apb-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control always-on reg.

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

Quoted 10 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +10 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+
+unevaluatedProperties: false
+

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 62

Quoted 10 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +10 -0
+examples:
+  - |
+    ufs: ufs@22000000 {
+        compatible = "sprd,ums9620-ufs";
+        reg = <0x22000000 0x3000>;
+        interrupts = <GIC_SPI 159 IRQ_TYPE_LEVEL_HIGH>;
+        vcc-supply = <&vddemmcore>;
+        vdd-mphy-supply = <&vddufs1v2>;
+        clocks-name = "ufs_eb", "ufs_cfg_eb",
+            "ufs_hclk", "ufs_hclk_source";

Align the lines.

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 65

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;

Why this is empty? What's the use of empty table?

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 71

Quoted 6 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +6 -0
+        reset-names = "ufs_soft_rst", "ufsdev_soft_rst";
+        resets = <&apahb_gate RESET_AP_AHB_UFS_SOFT_RST>,
+            <&aonapb_gate RESET_AON_APB_UFSDEV_SOFT_RST>;
+        sprd,ufs-anly-reg-syscon = <&anly_phy_g12_regs>;
+        sprd,aon-apb-syscon = <&aon_apb_regs>;
+        status = "disable";

Drop status.

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 72

Quoted 1 line
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +1 -0
+    };

Best regards,
Krzysztof

author
#3 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Hi Krzysztof,

Thank you for your review!

Quoted 12 lines · Krzysztof Kozlowski
Quoted 10 lines · Zhe Wang

From: Zhe Wang <[email protected]>

Add Unisoc ums9620 ufs host controller devicetree document.

---
 .../devicetree/bindings/ufs/sprd,ufs.yaml     | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/sprd,ufs.yaml
Quoted 10 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml

Quoted 5 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +0 -0
new file mode 100644
index 000000000000..88f2c670b0a4

Filename matching the compatible, so sprd,ums9620-ufs.yaml, unless you expect this to grow already? If so, can you post the rest?

Currently only ums9620 will be uploaded, I'll fix it.

Quoted 22 lines
Quoted 22 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +21 -0
@@ -0,0 +1,72 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/ufs/sprd,ufs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Unisoc Universal Flash Storage (UFS) Controller
+
+maintainers:
+  - Zhe Wang <[email protected]>
+
+allOf:
+  - $ref: ufs-common.yaml
+
+properties:
+  compatible:
+    enum:
+      - sprd,ums9620-ufs
+
+  clocks:
+    maxItems: 2
Quoted 9 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 26

Quoted 5 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +5 -0
+
+  clock-names:
+    items:
+      - const: hclk
+      - const: hclk_source

Can you make these descriptive? "clk" is redundant, so basically you are saying name is "h" and "h_source"?

I'll fix it.

Quoted 11 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 34

Quoted 8 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +8 -0
+
+  resets:
+    maxItems: 2
+
+  reset-names:
+    items:
+      - const: ufs_soft_rst
+      - const: ufsdev_soft_rst

Drop "_rst" from both.

Will remove this.

Quoted 9 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +4 -0
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

I will modify it based on this example.

Quoted 7 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 42

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+  sprd,aon-apb-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control always-on reg.

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

I will modify it based on this example.

Quoted 14 lines
Quoted 14 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +14 -0
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - resets
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    ufs: ufs@22000000 {
+        compatible = "sprd,ums9620-ufs";
Quoted 9 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 62

Quoted 6 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +6 -0
+        reg = <0x22000000 0x3000>;
+        interrupts = <GIC_SPI 159 IRQ_TYPE_LEVEL_HIGH>;
+        vcc-supply = <&vddemmcore>;
+        vdd-mphy-supply = <&vddufs1v2>;
+        clocks-name = "ufs_eb", "ufs_cfg_eb",
+            "ufs_hclk", "ufs_hclk_source";

Align the lines.

I'll fix it.

Quoted 6 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 65

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;

Why this is empty? What's the use of empty table?

freq-table-hz is used to configure the maximum frequency and minimum frequency of clk, and an empty table means that no scaling up\down operation is requiredfor the frequency of these clks.

Quoted 9 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 71

Quoted 6 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +6 -0
+        reset-names = "ufs_soft_rst", "ufsdev_soft_rst";
+        resets = <&apahb_gate RESET_AP_AHB_UFS_SOFT_RST>,
+            <&aonapb_gate RESET_AON_APB_UFSDEV_SOFT_RST>;
+        sprd,ufs-anly-reg-syscon = <&anly_phy_g12_regs>;
+        sprd,aon-apb-syscon = <&aon_apb_regs>;
+        status = "disable";

Drop status.

Will remove this.

Best regards,
Zhe Wang

Quoted 5 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 72

Quoted 1 line
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +1 -0
+    };

Best regards,
Krzysztof

#4 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Quoted 8 lines · Zhe Wang
Quoted 1 line

I'll fix it.

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;
Quoted 6 lines
Quoted 2 lines

Why this is empty? What's the use of empty table?

freq-table-hz is used to configure the maximum frequency and minimum frequency of clk, and an empty table means that no scaling up\down operation is requiredfor the frequency of these clks.

No, to indicate lack of scaling you skip freq-table-hz entirely, not provide empty one.

Best regards,
Krzysztof

author
#5 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Hi Krzysztof,

Quoted 13 lines · Krzysztof Kozlowski
Quoted 11 lines · Zhe Wang
Quoted 1 line

I'll fix it.

Quoted 6 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 65

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;

Why this is empty? What's the use of empty table?

Quoted 8 lines
Quoted 3 lines

freq-table-hz is used to configure the maximum frequency and minimum frequency of clk, and an empty table means that no scaling up\down operation is requiredfor the frequency of these clks.

No, to indicate lack of scaling you skip freq-table-hz entirely, not provide empty one.

In the ufshcd-pltfrm.c file, the clock information is parsed by executing the function ufshcd_parse_clock_info, if the number of "freq-table-hz" is zero or if the number of "clock-names" and "freq-table-hz" does not match, the UFS CLK information in dts will not be obtained. Although we don't need to scaling freq, we also need the CLK information for the CLK GATE operations. So we cannot delete this freq-table here.

Quoted 3 lines

Best regards,
Krzysztof

According to the local test results just now, I would like to ask a question about the previous revisions.

Quoted 8 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 38

Quoted 4 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +4 -0
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

In the syntax of this example, reg is represented by phandle and offset, but I only need the information of phandle in this place,So in this scenario, whether my original syntax is fine? just describe the pandlle.

Best regards,
Zhe Wang

#6 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Quoted 26 lines · Zhe Wang

Hi Krzysztof,

Quoted 13 lines · Krzysztof Kozlowski
Quoted 11 lines · Zhe Wang
Quoted 1 line

I'll fix it.

Quoted 6 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 65

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;

Why this is empty? What's the use of empty table?

Quoted 8 lines
Quoted 3 lines

freq-table-hz is used to configure the maximum frequency and minimum frequency of clk, and an empty table means that no scaling up\down operation is requiredfor the frequency of these clks.

No, to indicate lack of scaling you skip freq-table-hz entirely, not provide empty one.

Quoted 7 lines

In the ufshcd-pltfrm.c file, the clock information is parsed by executing the function ufshcd_parse_clock_info, if the number of "freq-table-hz" is zero or if the number of "clock-names" and "freq-table-hz" does not match, the UFS CLK information in dts will not be obtained. Although we don't need to scaling freq, we also need the CLK information for the CLK GATE operations. So we cannot delete this freq-table here.

I did not check the driver implementation, but if that's the case it does not match bindings. Before adding empty useless tables, please either fix bindings or driver. I think the latter - the driver - becasue clocks are not depending logically on freq-table-hz.

Quoted 12 lines
Quoted 4 lines

Best regards,
Krzysztof

According to the local test results just now, I would like to ask a question about the previous revisions.

Quoted 5 lines
Quoted 4 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +4 -0
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.
Quoted 6 lines
Quoted 3 lines

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

In the syntax of this example, reg is represented by phandle and offset, but I only need the information of phandle in this place,

No. You wrote "analog reg". So one reg. Not regs.

Quoted 3 lines

So in
this scenario, whether my original syntax is fine? just describe the pandlle.

No, because your description said one reg.

Best regards,
Krzysztof

author
#7 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

Hi Krzysztof,

Quoted 36 lines · Krzysztof Kozlowski
Quoted 26 lines · Zhe Wang

Hi Krzysztof,

Quoted 13 lines · Krzysztof Kozlowski
Quoted 11 lines · Zhe Wang
Quoted 1 line

I'll fix it.

Quoted 6 lines

Documentation/devicetree/bindings/ufs/sprd,ufs.yaml line 65

Quoted 3 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +3 -0
+        clocks = <&apahb_gate CLK_UFS_EB>, <&apahb_gate CLK_UFS_CFG_EB>,
+            <&onapb_clk CLK_UFS_AON>, <&g51_pll CLK_TGPLL_256M>;
+        freq-table-hz = <0 0>, <0 0>, <0 0>, <0 0>;

Why this is empty? What's the use of empty table?

Quoted 8 lines
Quoted 3 lines

freq-table-hz is used to configure the maximum frequency and minimum frequency of clk, and an empty table means that no scaling up\down operation is requiredfor the frequency of these clks.

No, to indicate lack of scaling you skip freq-table-hz entirely, not provide empty one.

Quoted 7 lines

In the ufshcd-pltfrm.c file, the clock information is parsed by executing the function ufshcd_parse_clock_info, if the number of "freq-table-hz" is zero or if the number of "clock-names" and "freq-table-hz" does not match, the UFS CLK information in dts will not be obtained. Although we don't need to scaling freq, we also need the CLK information for the CLK GATE operations. So we cannot delete this freq-table here.

Quoted 5 lines

I did not check the driver implementation, but if that's the case it does not match bindings. Before adding empty useless tables, please either fix bindings or driver. I think the latter - the driver - becasue clocks are not depending logically on freq-table-hz.

OK, I will think about how to solve this problem.

Quoted 19 lines
Quoted 12 lines
Quoted 4 lines

Best regards,
Krzysztof

According to the local test results just now, I would like to ask a question about the previous revisions.

Quoted 5 lines
Quoted 4 lines
Documentation/devicetree/bindings/ufs/sprd,ufs.yaml new file +4 -0
+
+  sprd,ufs-anly-reg-syscon:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description: phandle of syscon used to control ufs analog reg.
Quoted 6 lines
Quoted 3 lines

It's a reg? Then such syntax is expected:
https://elixir.bootlin.com/linux/v5.18-rc1/source/Documentation/devicetree/bindings/soc/samsung/exynos-usi.yaml#L42

In the syntax of this example, reg is represented by phandle and offset, but I only need the information of phandle in this place,

Quoted 8 lines

No. You wrote "analog reg". So one reg. Not regs.

Quoted 3 lines

So in
this scenario, whether my original syntax is fine? just describe the pandlle.

No, because your description said one reg.

This is my mistake, the description is wrong, it's regs. Thank you for your review!

Best regards,
Zhe Wang

Quoted 3 lines

Best regards,
Krzysztof

maintainer
#8 lore raw

Re: [PATCH 1/2] dt-bindings: ufs: Add document for Unisoc UFS host controller

In reply to Zhe Wang
Quoted 10 lines · Zhe Wang

From: Zhe Wang <[email protected]>

Add Unisoc ums9620 ufs host controller devicetree document.

---
 .../devicetree/bindings/ufs/sprd,ufs.yaml     | 72 +++++++++++++++++++
 1 file changed, 72 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/ufs/sprd,ufs.yaml

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check' on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/ufs/sprd,ufs.example.dts:24.27-28 syntax error FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:406: Documentation/devicetree/bindings/ufs/sprd,ufs.example.dtb] Error 1 make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1492: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/

This check can fail if there are any dependencies. The base for a patch series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above error(s), then make sure 'yamllint' is installed and dt-schema is up to date:

pip3 install dtschema --upgrade

Please check and re-submit.

author
#9 lore raw

PATCH 2/2 scsi: ufs-unisoc: Add support for Unisoc UFS host controller

In reply to Zhe Wang

From: Zhe Wang <[email protected]>

Add driver code for Unisoc ufs host controller, along with ufs initialization.

---
 drivers/ufs/host/Kconfig    |  12 +
 drivers/ufs/host/Makefile   |   1 +
 drivers/ufs/host/ufs-sprd.c | 445 ++++++++++++++++++++++++++++++++++++
 drivers/ufs/host/ufs-sprd.h | 125 ++++++++++
 4 files changed, 583 insertions(+)
 create mode 100644 drivers/ufs/host/ufs-sprd.c
 create mode 100644 drivers/ufs/host/ufs-sprd.h
drivers/ufs/host/Kconfig +12 -0
index 4cc2dbd79ed0..90a7142ec846 100644
@@ -124,3 +124,15 @@ config SCSI_UFS_EXYNOS
 
 	  Select this if you have UFS host controller on Samsung Exynos SoC.
 	  If unsure, say N.
+
+config SCSI_UFS_SPRD
+	tristate "Unisoc specific hooks to UFS controller platform driver"
+	depends on SCSI_UFSHCD_PLATFORM && (ARCH_SPRD || COMPILE_TEST)
+	help
+	  This selects the Unisoc specific additions to UFSHCD platform driver.
+	  UFS host on Unisoc needs some vendor specific configuration before
+	  accessing the hardware which includes PHY configuration and vendor
+	  specific registers.
+
+	  Select this if you have UFS controller on Unisoc chipset.
+	  If unsure, say N.
drivers/ufs/host/Makefile +1 -0
index 7717ca93e7d5..a946c3b35c9d 100644
@@ -13,3 +13,4 @@ obj-$(CONFIG_SCSI_UFS_HISI) += ufs-hisi.o
 obj-$(CONFIG_SCSI_UFS_MEDIATEK) += ufs-mediatek.o
 obj-$(CONFIG_SCSI_UFS_RENESAS) += ufs-renesas.o
 obj-$(CONFIG_SCSI_UFS_TI_J721E) += ti-j721e-ufs.o
+obj-$(CONFIG_SCSI_UFS_SPRD) += ufs-sprd.o
drivers/ufs/host/ufs-sprd.c new file +445 -0

445 lines not on this page · raw message

drivers/ufs/host/ufs-sprd.h new file +125 -0

125 lines not on this page · raw message

Signature · 1 line
2.17.1
#10 lore raw

Re: [PATCH 2/2] scsi: ufs-unisoc: Add support for Unisoc UFS host controller

Quoted 4 lines · Zhe Wang

From: Zhe Wang <[email protected]>

Add driver code for Unisoc ufs host controller, along with ufs initialization.

(...)

drivers/ufs/host/ufs-sprd.c line 438

Quoted 9 lines
drivers/ufs/host/ufs-sprd.c new file +9 -0
+
+static struct platform_driver ufs_sprd_pltform = {
+	.probe = ufs_sprd_probe,
+	.remove = ufs_sprd_remove,
+	.shutdown = ufshcd_pltfrm_shutdown,
+	.driver = {
+		.name = "ufshcd-sprd",
+		.pm = &ufs_sprd_pm_ops,
+		.of_match_table = of_match_ptr(ufs_sprd_of_match),

Drop of_match_ptr

Quoted 126 lines
drivers/ufs/host/ufs-sprd.c new file +7 -0
+	},
+};
+module_platform_driver(ufs_sprd_pltform);
+
+MODULE_AUTHOR("Zhe Wang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc UFS Host Driver");
+MODULE_LICENSE("GPL v2");
drivers/ufs/host/ufs-sprd.h new file +113 -0
new file mode 100644
index 000000000000..215e7483d1e8
@@ -0,0 +1,125 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * UNISOC UFS Host Controller driver
+ *
+ * Copyright (C) 2022 Unisoc, Inc.
+ * Author: Zhe Wang <[email protected]>
+ */
+
+#ifndef _UFS_SPRD_H_
+#define _UFS_SPRD_H_
+
+#define APB_UFSDEV_REG		0xCE8
+#define APB_UFSDEV_REFCLK_EN	0x2
+#define APB_USB31PLL_CTRL	0xCFC
+#define APB_USB31PLLV_REF2MPHY	0x1
+
+#define SPRD_SIP_SVC_STORAGE_UFS_CRYPTO_ENABLE				\
+	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,				\
+			   ARM_SMCCC_SMC_32,				\
+			   ARM_SMCCC_OWNER_SIP,				\
+			   0x0301)
+
+enum SPRD_UFS_CLK_INDEX {
+	SPRD_UFS_HCLK,
+	SPRD_UFS_HCLK_SOURCE,
+
+	SPRD_UFS_CLK_MAX
+};
+
+enum SPRD_UFS_RST_INDEX {
+	SPRD_UFSHCI_SOFT_RST,
+	SPRD_UFS_DEV_RST,
+
+	SPRD_UFS_RST_MAX
+};
+
+enum SPRD_UFS_SYSCON_INDEX {
+	SPRD_UFS_ANLG_REG,
+	SPRD_UFS_AON_APB,
+
+	SPRD_UFS_SYSCON_MAX
+};
+
+enum SPRD_UFS_VREG_INDEX {
+	SPRD_UFS_VDD_MPHY,
+
+	SPRD_UFS_VREG_MAX
+};
+
+struct ufs_sprd_clk {
+	const char *name;
+	struct clk *clk;
+};
+
+struct ufs_sprd_rst {
+	const char *name;
+	struct reset_control *rc;
+};
+
+struct ufs_sprd_syscon {
+	const char *name;
+	struct regmap *regmap;
+};
+
+struct ufs_sprd_vreg {
+	const char *name;
+	struct regulator *vreg;
+};
+
+struct ufs_sprd_priv {
+	struct ufs_sprd_clk clki[SPRD_UFS_CLK_MAX];
+	struct ufs_sprd_rst rci[SPRD_UFS_RST_MAX];
+	struct ufs_sprd_syscon sysci[SPRD_UFS_SYSCON_MAX];
+	struct ufs_sprd_vreg vregi[SPRD_UFS_VREG_MAX];
+	const struct ufs_hba_variant_ops ufs_hba_sprd_vops;
+};
+
+struct ufs_sprd_host {
+	struct ufs_hba *hba;
+	struct ufs_sprd_priv *priv;
+	void __iomem *ufs_dbg_mmio;
+
+	enum ufs_unipro_ver unipro_ver;
+};
+
+static inline struct ufs_sprd_priv *ufs_sprd_get_priv_data(struct ufs_hba *hba)
+{
+	struct ufs_sprd_host *host = ufshcd_get_variant(hba);
+
+	WARN_ON(!host->priv);
+	return host->priv;
+}
+
+static inline void ufs_sprd_regmap_update(struct ufs_sprd_priv *priv, unsigned int index,
+		unsigned int reg, unsigned int bits,  unsigned int val)
+{
+	regmap_update_bits(priv->sysci[index].regmap, reg, bits, val);
+}
+
+static inline void ufs_sprd_regmap_read(struct ufs_sprd_priv *priv, unsigned int index,
+		unsigned int reg, unsigned int *val)
+{
+	regmap_read(priv->sysci[index].regmap, reg, val);
+}
+
+static inline void ufs_sprd_get_unipro_ver(struct ufs_hba *hba)
+{
+	struct ufs_sprd_host *host = ufshcd_get_variant(hba);
+
+	if (ufshcd_dme_get(hba, UIC_ARG_MIB(PA_LOCALVERINFO), &host->unipro_ver))
+		host->unipro_ver = 0;
+}
+

drivers/ufs/host/ufs-sprd.h line 123

Quoted 10 lines
drivers/ufs/host/ufs-sprd.h new file +10 -0
+static inline void ufs_sprd_ctrl_uic_compl(struct ufs_hba *hba, bool enable)
+{
+	u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
+
+	if (enable == true)
+		set |= UIC_COMMAND_COMPL;
+	else
+		set &= ~UIC_COMMAND_COMPL;
+	ufshcd_writel(hba, set, REG_INTERRUPT_ENABLE);
+}

Drop functions from headers. These are not stubs and your task is not to micro-optimize code.

drivers/ufs/host/ufs-sprd.h line 125

Quoted 2 lines
drivers/ufs/host/ufs-sprd.h new file +2 -0
+
+#endif /* _UFS_SPRD_H_ */

Best regards,
Krzysztof

author
#11 lore raw

Re: [PATCH 2/2] scsi: ufs-unisoc: Add support for Unisoc UFS host controller

Hi Krzysztof,

Thank you for your review!

Quoted 9 lines · Krzysztof Kozlowski
Quoted 4 lines · Zhe Wang

From: Zhe Wang <[email protected]>

Add driver code for Unisoc ufs host controller, along with ufs initialization.

(...)

Quoted 12 lines

drivers/ufs/host/ufs-sprd.c line 438

Quoted 9 lines
drivers/ufs/host/ufs-sprd.c new file +9 -0
+
+static struct platform_driver ufs_sprd_pltform = {
+     .probe = ufs_sprd_probe,
+     .remove = ufs_sprd_remove,
+     .shutdown = ufshcd_pltfrm_shutdown,
+     .driver = {
+             .name = "ufshcd-sprd",
+             .pm = &ufs_sprd_pm_ops,
+             .of_match_table = of_match_ptr(ufs_sprd_of_match),

Drop of_match_ptr

I'll drop this.

Quoted 131 lines
Quoted 131 lines
drivers/ufs/host/ufs-sprd.c new file +7 -0
+     },
+};
+module_platform_driver(ufs_sprd_pltform);
+
+MODULE_AUTHOR("Zhe Wang <[email protected]>");
+MODULE_DESCRIPTION("Unisoc UFS Host Driver");
+MODULE_LICENSE("GPL v2");
drivers/ufs/host/ufs-sprd.h new file +118 -0
new file mode 100644
index 000000000000..215e7483d1e8
@@ -0,0 +1,125 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * UNISOC UFS Host Controller driver
+ *
+ * Copyright (C) 2022 Unisoc, Inc.
+ * Author: Zhe Wang <[email protected]>
+ */
+
+#ifndef _UFS_SPRD_H_
+#define _UFS_SPRD_H_
+
+#define APB_UFSDEV_REG               0xCE8
+#define APB_UFSDEV_REFCLK_EN 0x2
+#define APB_USB31PLL_CTRL    0xCFC
+#define APB_USB31PLLV_REF2MPHY       0x1
+
+#define SPRD_SIP_SVC_STORAGE_UFS_CRYPTO_ENABLE                               \
+     ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL,                         \
+                        ARM_SMCCC_SMC_32,                            \
+                        ARM_SMCCC_OWNER_SIP,                         \
+                        0x0301)
+
+enum SPRD_UFS_CLK_INDEX {
+     SPRD_UFS_HCLK,
+     SPRD_UFS_HCLK_SOURCE,
+
+     SPRD_UFS_CLK_MAX
+};
+
+enum SPRD_UFS_RST_INDEX {
+     SPRD_UFSHCI_SOFT_RST,
+     SPRD_UFS_DEV_RST,
+
+     SPRD_UFS_RST_MAX
+};
+
+enum SPRD_UFS_SYSCON_INDEX {
+     SPRD_UFS_ANLG_REG,
+     SPRD_UFS_AON_APB,
+
+     SPRD_UFS_SYSCON_MAX
+};
+
+enum SPRD_UFS_VREG_INDEX {
+     SPRD_UFS_VDD_MPHY,
+
+     SPRD_UFS_VREG_MAX
+};
+
+struct ufs_sprd_clk {
+     const char *name;
+     struct clk *clk;
+};
+
+struct ufs_sprd_rst {
+     const char *name;
+     struct reset_control *rc;
+};
+
+struct ufs_sprd_syscon {
+     const char *name;
+     struct regmap *regmap;
+};
+
+struct ufs_sprd_vreg {
+     const char *name;
+     struct regulator *vreg;
+};
+
+struct ufs_sprd_priv {
+     struct ufs_sprd_clk clki[SPRD_UFS_CLK_MAX];
+     struct ufs_sprd_rst rci[SPRD_UFS_RST_MAX];
+     struct ufs_sprd_syscon sysci[SPRD_UFS_SYSCON_MAX];
+     struct ufs_sprd_vreg vregi[SPRD_UFS_VREG_MAX];
+     const struct ufs_hba_variant_ops ufs_hba_sprd_vops;
+};
+
+struct ufs_sprd_host {
+     struct ufs_hba *hba;
+     struct ufs_sprd_priv *priv;
+     void __iomem *ufs_dbg_mmio;
+
+     enum ufs_unipro_ver unipro_ver;
+};
+
+static inline struct ufs_sprd_priv *ufs_sprd_get_priv_data(struct ufs_hba *hba)
+{
+     struct ufs_sprd_host *host = ufshcd_get_variant(hba);
+
+     WARN_ON(!host->priv);
+     return host->priv;
+}
+
+static inline void ufs_sprd_regmap_update(struct ufs_sprd_priv *priv, unsigned int index,
+             unsigned int reg, unsigned int bits,  unsigned int val)
+{
+     regmap_update_bits(priv->sysci[index].regmap, reg, bits, val);
+}
+
+static inline void ufs_sprd_regmap_read(struct ufs_sprd_priv *priv, unsigned int index,
+             unsigned int reg, unsigned int *val)
+{
+     regmap_read(priv->sysci[index].regmap, reg, val);
+}
+
+static inline void ufs_sprd_get_unipro_ver(struct ufs_hba *hba)
+{
+     struct ufs_sprd_host *host = ufshcd_get_variant(hba);
+
+     if (ufshcd_dme_get(hba, UIC_ARG_MIB(PA_LOCALVERINFO), &host->unipro_ver))
+             host->unipro_ver = 0;
+}
+
+static inline void ufs_sprd_ctrl_uic_compl(struct ufs_hba *hba, bool enable)
+{
+     u32 set = ufshcd_readl(hba, REG_INTERRUPT_ENABLE);
+
+     if (enable == true)
Quoted 9 lines

drivers/ufs/host/ufs-sprd.h line 123

Quoted 5 lines
drivers/ufs/host/ufs-sprd.h new file +5 -0
+             set |= UIC_COMMAND_COMPL;
+     else
+             set &= ~UIC_COMMAND_COMPL;
+     ufshcd_writel(hba, set, REG_INTERRUPT_ENABLE);
+}

Drop functions from headers. These are not stubs and your task is not to micro-optimize code.

Will move these functions to c file.

Best regards,
Zhe Wang

Quoted 6 lines

drivers/ufs/host/ufs-sprd.h line 125

Quoted 2 lines
drivers/ufs/host/ufs-sprd.h new file +2 -0
+
+#endif /* _UFS_SPRD_H_ */

Best regards,
Krzysztof