All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v3 0/7] sm8550: Add support for eUSB2 repeater
@ 2023-02-02 13:38 ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

This patchset adds support for the eUSB2 repeater found in pmic PM8550B,
used along with SM8550. Since there is no dedicated generic framework
for eUSB2 repeaters, the most appropriate subsystem to model it is the
generic phy. This patchset also adds support for such repeater to the
eUSB2 PHY found in SM8550. Basically, the eUSB2 PHY will have its own
"phy" which is actually a repeater.

This patchset is based on the following patchset:
https://lore.kernel.org/all/?q=20230126131415.1453741-1-abel.vesa%40linaro.org

Changes since v2:
 * moved the bindings qcom,spmi-pmic patch before the repeater schema
   patch in order to avoid the repeater schema validation failure due to
   phy pattern property not being found in qcom,spmi-pmic schema

Changes since v1:
 * the repeater driver is implemented now as a PHY rather than adding
   a new generic framework for USB repeaters

Abel Vesa (5):
  dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
  dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
  dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
  phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  arm64: dts: qcom: sm8550-mtp: Add eUSB2 repeater node

Neil Armstrong (2):
  phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
  arm64: dts: qcom: pm8550b: Add eUSB2 repeater node

 .../bindings/mfd/qcom,spmi-pmic.yaml          |   4 +
 .../bindings/phy/qcom,snps-eusb2-phy.yaml     |   9 +
 .../phy/qcom,snps-eusb2-repeater.yaml         |  48 +++
 arch/arm64/boot/dts/qcom/pm8550b.dtsi         |   6 +
 arch/arm64/boot/dts/qcom/sm8550-mtp.dts       |   8 +
 drivers/phy/qualcomm/Kconfig                  |   9 +
 drivers/phy/qualcomm/Makefile                 |   1 +
 .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
 drivers/phy/qualcomm/phy-qcom-snps-eusb2.c    |  18 +-
 9 files changed, 380 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
 create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c

-- 
2.34.1


^ permalink raw reply	[flat|nested] 38+ messages in thread

* [RFC v3 0/7] sm8550: Add support for eUSB2 repeater
@ 2023-02-02 13:38 ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

This patchset adds support for the eUSB2 repeater found in pmic PM8550B,
used along with SM8550. Since there is no dedicated generic framework
for eUSB2 repeaters, the most appropriate subsystem to model it is the
generic phy. This patchset also adds support for such repeater to the
eUSB2 PHY found in SM8550. Basically, the eUSB2 PHY will have its own
"phy" which is actually a repeater.

This patchset is based on the following patchset:
https://lore.kernel.org/all/?q=20230126131415.1453741-1-abel.vesa%40linaro.org

Changes since v2:
 * moved the bindings qcom,spmi-pmic patch before the repeater schema
   patch in order to avoid the repeater schema validation failure due to
   phy pattern property not being found in qcom,spmi-pmic schema

Changes since v1:
 * the repeater driver is implemented now as a PHY rather than adding
   a new generic framework for USB repeaters

Abel Vesa (5):
  dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
  dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
  dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
  phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  arm64: dts: qcom: sm8550-mtp: Add eUSB2 repeater node

Neil Armstrong (2):
  phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
  arm64: dts: qcom: pm8550b: Add eUSB2 repeater node

 .../bindings/mfd/qcom,spmi-pmic.yaml          |   4 +
 .../bindings/phy/qcom,snps-eusb2-phy.yaml     |   9 +
 .../phy/qcom,snps-eusb2-repeater.yaml         |  48 +++
 arch/arm64/boot/dts/qcom/pm8550b.dtsi         |   6 +
 arch/arm64/boot/dts/qcom/sm8550-mtp.dts       |   8 +
 drivers/phy/qualcomm/Kconfig                  |   9 +
 drivers/phy/qualcomm/Makefile                 |   1 +
 .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
 drivers/phy/qualcomm/phy-qcom-snps-eusb2.c    |  18 +-
 9 files changed, 380 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
 create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c

-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The phy pattern property will be used for providing eUSB2 repeater
functionality. This will be modelled as a Qualcomm PHY driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
index adf88245c409..1e6fadec1301 100644
--- a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
+++ b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
@@ -135,6 +135,10 @@ patternProperties:
     type: object
     $ref: /schemas/pinctrl/qcom,pmic-gpio.yaml#
 
+  "phy@[0-9a-f]+$":
+    type: object
+    $ref: /schemas/phy/qcom,snps-eusb2-repeater.yaml#
+
   "pon@[0-9a-f]+$":
     type: object
     $ref: /schemas/power/reset/qcom,pon.yaml#
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The phy pattern property will be used for providing eUSB2 repeater
functionality. This will be modelled as a Qualcomm PHY driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
index adf88245c409..1e6fadec1301 100644
--- a/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
+++ b/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
@@ -135,6 +135,10 @@ patternProperties:
     type: object
     $ref: /schemas/pinctrl/qcom,pmic-gpio.yaml#
 
+  "phy@[0-9a-f]+$":
+    type: object
+    $ref: /schemas/phy/qcom,snps-eusb2-repeater.yaml#
+
   "pon@[0-9a-f]+$":
     type: object
     $ref: /schemas/power/reset/qcom,pon.yaml#
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 2/7] dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The SM8550 SoC uses Synopsis eUSB2 repeater found in PM8550b.
Add a dt-binding schema for the new driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 .../phy/qcom,snps-eusb2-repeater.yaml         | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml

diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
new file mode 100644
index 000000000000..3b99038be74e
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/qcom,snps-eusb2-repeater.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Synopsis eUSB2 to USB 2.0 repeater
+
+maintainers:
+  - Abel Vesa <abel.vesa@linaro.org>
+
+properties:
+  compatible:
+    const: qcom,pm8550b-eusb2-repeater
+
+  reg:
+    maxItems: 1
+
+  "#phy-cells":
+    const: 0
+
+  vdd18-supply: true
+
+  vdd3-supply: true
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/spmi/spmi.h>
+    pm8550b: pmic@7 {
+        compatible = "qcom,pm8550", "qcom,spmi-pmic";
+        reg = <0x7 SPMI_USID>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pm8550b_eusb2_repeater: phy@fd00 {
+          compatible = "qcom,pm8550b-eusb2-repeater";
+          reg = <0xfd00>;
+          #phy-cells = <0>;
+        };
+    };
+...
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 2/7] dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The SM8550 SoC uses Synopsis eUSB2 repeater found in PM8550b.
Add a dt-binding schema for the new driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 .../phy/qcom,snps-eusb2-repeater.yaml         | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml

diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
new file mode 100644
index 000000000000..3b99038be74e
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/qcom,snps-eusb2-repeater.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Qualcomm Synopsis eUSB2 to USB 2.0 repeater
+
+maintainers:
+  - Abel Vesa <abel.vesa@linaro.org>
+
+properties:
+  compatible:
+    const: qcom,pm8550b-eusb2-repeater
+
+  reg:
+    maxItems: 1
+
+  "#phy-cells":
+    const: 0
+
+  vdd18-supply: true
+
+  vdd3-supply: true
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/spmi/spmi.h>
+    pm8550b: pmic@7 {
+        compatible = "qcom,pm8550", "qcom,spmi-pmic";
+        reg = <0x7 SPMI_USID>;
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        pm8550b_eusb2_repeater: phy@fd00 {
+          compatible = "qcom,pm8550b-eusb2-repeater";
+          reg = <0xfd00>;
+          #phy-cells = <0>;
+        };
+    };
+...
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 3/7] dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The phy properties are used for allowing the eusb2 to interface
with the repeater, which is modelled as a phy driver. Add the phys
and phy-names properties.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 .../devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml     | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
index de72577e34a4..8efb09b2dc5c 100644
--- a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
+++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
@@ -33,6 +33,15 @@ properties:
   resets:
     maxItems: 1
 
+  phys:
+    maxItems: 1
+    description:
+      Phandle to eUSB2 to USB 2.0 repeater
+
+  phy-names:
+    items:
+      - const: eusb2-repeater
+
   vdd-supply:
     description:
       Phandle to 0.88V regulator supply to PHY digital circuit.
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 3/7] dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

The phy properties are used for allowing the eusb2 to interface
with the repeater, which is modelled as a phy driver. Add the phys
and phy-names properties.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 .../devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml     | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
index de72577e34a4..8efb09b2dc5c 100644
--- a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
+++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
@@ -33,6 +33,15 @@ properties:
   resets:
     maxItems: 1
 
+  phys:
+    maxItems: 1
+    description:
+      Phandle to eUSB2 to USB 2.0 repeater
+
+  phy-names:
+    items:
+      - const: eusb2-repeater
+
   vdd-supply:
     description:
       Phandle to 0.88V regulator supply to PHY digital circuit.
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

PM8550B contains a eUSB2 repeater used for making the eUSB2 from
SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
So add a new phy driver for it.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/phy/qualcomm/Kconfig                  |   9 +
 drivers/phy/qualcomm/Makefile                 |   1 +
 .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
 3 files changed, 288 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c

diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
index 27b5a2a3637d..a70631b04522 100644
--- a/drivers/phy/qualcomm/Kconfig
+++ b/drivers/phy/qualcomm/Kconfig
@@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
 	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
 	  on Qualcomm SOCs.
 
+config PHY_QCOM_EUSB2_REPEATER
+	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
+	depends on OF && (ARCH_QCOM || COMPILE_TEST)
+	select GENERIC_PHY
+	help
+	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
+	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
+	  on Qualcomm SOCs.
+
 config PHY_QCOM_USB_HS
 	tristate "Qualcomm USB HS PHY module"
 	depends on USB_ULPI_BUS
diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
index 3ee118f4dfc7..7dcba9537b69 100644
--- a/drivers/phy/qualcomm/Makefile
+++ b/drivers/phy/qualcomm/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
 
 obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
 obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
+obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
 obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
 obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
 obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
new file mode 100644
index 000000000000..f7f822f2973f
--- /dev/null
+++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023, Linaro Limited
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regmap.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/phy/phy.h>
+
+/* eUSB2 status registers */
+#define EUSB2_RPTR_STATUS		0x08
+#define	RPTR_OK				BIT(7)
+
+/* eUSB2 control registers */
+#define EUSB2_EN_CTL1			0x46
+#define EUSB2_RPTR_EN			BIT(7)
+
+#define PHY_HOST_MODE			BIT(0)
+#define EUSB2_FORCE_EN_5		0xE8
+#define F_CLK_19P2M_EN			BIT(6)
+#define F_CLK_19P2M_EN_SHIFT		6
+
+#define EUSB2_FORCE_VAL_5		0xED
+#define V_CLK_19P2M_EN			BIT(6)
+#define V_CLK_19P2M_EN_SHIFT		6
+
+#define EUSB2_TUNE_IUSB2		0x51
+#define EUSB2_TUNE_SQUELCH_U		0x54
+#define EUSB2_TUNE_USB2_PREEM		0x57
+
+#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
+	{					\
+		.offset = o,			\
+		.val = v,			\
+	}
+
+enum repeater_mode {
+	REPEATER_HOST_MODE,
+	REPEATER_PERIPH_MODE,
+};
+
+struct eusb2_repeater_init_tbl {
+	unsigned int offset;
+	unsigned int val;
+};
+
+struct eusb2_repeater_cfg {
+	const struct eusb2_repeater_init_tbl *init_tbl;
+	int init_tbl_num;
+	/* regulators to be requested */
+	const char * const *vreg_list;
+	int num_vregs;
+};
+
+struct eusb2_repeater {
+	struct device *dev;
+	struct regmap *regmap;
+	struct phy *phy;
+	struct regulator_bulk_data *vregs;
+	const struct eusb2_repeater_cfg *cfg;
+	u16 base;
+	enum phy_mode mode;
+};
+
+static const char * const pm8550b_vreg_l[] = {
+	"vdd18", "vdd3",
+};
+
+static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
+};
+
+static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
+	.init_tbl	= pm8550b_init_tbl,
+	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
+	.vreg_list	= pm8550b_vreg_l,
+	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
+};
+
+static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
+{
+	int num = rptr->cfg->num_vregs;
+	struct device *dev = rptr->dev;
+	int i;
+
+	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
+	if (!rptr->vregs)
+		return -ENOMEM;
+
+	for (i = 0; i < num; i++)
+		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
+
+	return devm_regulator_bulk_get(dev, num, rptr->vregs);
+}
+
+static int eusb2_repeater_init(struct phy *phy)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
+	int num = rptr->cfg->init_tbl_num;
+	int ret = 0;
+	u32 val;
+	int i;
+
+	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
+	if (ret)
+		return ret;
+
+	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
+				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
+
+	for (i = 0; i < num; i++)
+		regmap_update_bits(rptr->regmap,
+					rptr->base + init_tbl[i].offset,
+					init_tbl[i].val, init_tbl[i].val);
+
+	ret = regmap_read_poll_timeout(rptr->regmap,
+					rptr->base + EUSB2_RPTR_STATUS, val,
+					val & RPTR_OK, 10, 5);
+	if (ret)
+		dev_err(rptr->dev, "initialization timed-out\n");
+
+	return ret;
+}
+
+static int eusb2_repeater_set_mode(struct phy *phy,
+					enum phy_mode mode, int submode)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+
+	switch (mode) {
+	case PHY_MODE_USB_HOST:
+		/*
+		 * CM.Lx is prohibited when repeater is already into Lx state as
+		 * per eUSB 1.2 Spec. Below implement software workaround until
+		 * PHY and controller is fixing seen observation.
+		 */
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
+				F_CLK_19P2M_EN, F_CLK_19P2M_EN);
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
+				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
+		break;
+	case PHY_MODE_USB_DEVICE:
+		/*
+		 * In device mode clear host mode related workaround as there
+		 * is no repeater reset available, and enable/disable of
+		 * repeater doesn't clear previous value due to shared
+		 * regulators (say host <-> device mode switch).
+		 */
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
+				F_CLK_19P2M_EN, 0);
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
+				V_CLK_19P2M_EN, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int eusb2_repeater_exit(struct phy *phy)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+
+	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
+}
+
+
+static const struct phy_ops eusb2_repeater_ops = {
+	.init		= eusb2_repeater_init,
+	.exit		= eusb2_repeater_exit,
+	.set_mode	= eusb2_repeater_set_mode,
+	.owner		= THIS_MODULE,
+};
+
+static int eusb2_repeater_probe(struct platform_device *pdev)
+{
+	struct eusb2_repeater *rptr;
+	struct device *dev = &pdev->dev;
+	struct phy_provider *phy_provider;
+	struct device_node *np;
+	u32 res;
+	int ret;
+
+	np = of_node_get(dev->of_node);
+
+	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
+	if (!rptr)
+		goto err_node_put;
+
+	rptr->dev = dev;
+	dev_set_drvdata(dev, rptr);
+
+	rptr->cfg = of_device_get_match_data(dev);
+	if (!rptr->cfg)
+		goto err_node_put;
+
+	rptr->regmap = dev_get_regmap(dev->parent, NULL);
+	if (!rptr->regmap)
+		goto err_node_put;
+
+	ret = of_property_read_u32(np, "reg", &res);
+	if (ret < 0)
+		goto err_node_put;
+
+	rptr->base = res;
+
+	ret = eusb2_repeater_init_vregs(rptr);
+	if (ret < 0) {
+		dev_err(dev, "unable to get supplies\n");
+		goto err_node_put;
+	}
+
+	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
+	if (IS_ERR(rptr->phy)) {
+		ret = PTR_ERR(rptr->phy);
+		dev_err(dev, "failed to create PHY: %d\n", ret);
+		goto err_node_put;
+	}
+
+	phy_set_drvdata(rptr->phy, rptr);
+
+	of_node_put(np);
+
+	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+	if (IS_ERR(phy_provider))
+		return PTR_ERR(phy_provider);
+
+	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
+
+	return 0;
+
+err_node_put:
+	of_node_put(np);
+	return ret;
+}
+
+static int eusb2_repeater_remove(struct platform_device *pdev)
+{
+	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
+
+	if (!rptr)
+		return 0;
+
+	eusb2_repeater_exit(rptr->phy);
+	return 0;
+}
+
+
+static const struct of_device_id eusb2_repeater_of_match_table[] = {
+	{
+		.compatible = "qcom,pm8550b-eusb2-repeater",
+		.data = &pm8550b_eusb2_cfg,
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
+
+static struct platform_driver eusb2_repeater_driver = {
+	.probe		= eusb2_repeater_probe,
+	.remove		= eusb2_repeater_remove,
+	.driver = {
+		.name	= "qcom-eusb2-repeater",
+		.of_match_table = eusb2_repeater_of_match_table,
+	},
+};
+
+module_platform_driver(eusb2_repeater_driver);
+
+MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
+MODULE_LICENSE("GPL v2");
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

PM8550B contains a eUSB2 repeater used for making the eUSB2 from
SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
So add a new phy driver for it.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 drivers/phy/qualcomm/Kconfig                  |   9 +
 drivers/phy/qualcomm/Makefile                 |   1 +
 .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
 3 files changed, 288 insertions(+)
 create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c

diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
index 27b5a2a3637d..a70631b04522 100644
--- a/drivers/phy/qualcomm/Kconfig
+++ b/drivers/phy/qualcomm/Kconfig
@@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
 	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
 	  on Qualcomm SOCs.
 
+config PHY_QCOM_EUSB2_REPEATER
+	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
+	depends on OF && (ARCH_QCOM || COMPILE_TEST)
+	select GENERIC_PHY
+	help
+	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
+	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
+	  on Qualcomm SOCs.
+
 config PHY_QCOM_USB_HS
 	tristate "Qualcomm USB HS PHY module"
 	depends on USB_ULPI_BUS
diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
index 3ee118f4dfc7..7dcba9537b69 100644
--- a/drivers/phy/qualcomm/Makefile
+++ b/drivers/phy/qualcomm/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
 
 obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
 obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
+obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
 obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
 obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
 obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
new file mode 100644
index 000000000000..f7f822f2973f
--- /dev/null
+++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
@@ -0,0 +1,278 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2023, Linaro Limited
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/regmap.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/phy/phy.h>
+
+/* eUSB2 status registers */
+#define EUSB2_RPTR_STATUS		0x08
+#define	RPTR_OK				BIT(7)
+
+/* eUSB2 control registers */
+#define EUSB2_EN_CTL1			0x46
+#define EUSB2_RPTR_EN			BIT(7)
+
+#define PHY_HOST_MODE			BIT(0)
+#define EUSB2_FORCE_EN_5		0xE8
+#define F_CLK_19P2M_EN			BIT(6)
+#define F_CLK_19P2M_EN_SHIFT		6
+
+#define EUSB2_FORCE_VAL_5		0xED
+#define V_CLK_19P2M_EN			BIT(6)
+#define V_CLK_19P2M_EN_SHIFT		6
+
+#define EUSB2_TUNE_IUSB2		0x51
+#define EUSB2_TUNE_SQUELCH_U		0x54
+#define EUSB2_TUNE_USB2_PREEM		0x57
+
+#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
+	{					\
+		.offset = o,			\
+		.val = v,			\
+	}
+
+enum repeater_mode {
+	REPEATER_HOST_MODE,
+	REPEATER_PERIPH_MODE,
+};
+
+struct eusb2_repeater_init_tbl {
+	unsigned int offset;
+	unsigned int val;
+};
+
+struct eusb2_repeater_cfg {
+	const struct eusb2_repeater_init_tbl *init_tbl;
+	int init_tbl_num;
+	/* regulators to be requested */
+	const char * const *vreg_list;
+	int num_vregs;
+};
+
+struct eusb2_repeater {
+	struct device *dev;
+	struct regmap *regmap;
+	struct phy *phy;
+	struct regulator_bulk_data *vregs;
+	const struct eusb2_repeater_cfg *cfg;
+	u16 base;
+	enum phy_mode mode;
+};
+
+static const char * const pm8550b_vreg_l[] = {
+	"vdd18", "vdd3",
+};
+
+static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
+	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
+};
+
+static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
+	.init_tbl	= pm8550b_init_tbl,
+	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
+	.vreg_list	= pm8550b_vreg_l,
+	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
+};
+
+static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
+{
+	int num = rptr->cfg->num_vregs;
+	struct device *dev = rptr->dev;
+	int i;
+
+	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
+	if (!rptr->vregs)
+		return -ENOMEM;
+
+	for (i = 0; i < num; i++)
+		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
+
+	return devm_regulator_bulk_get(dev, num, rptr->vregs);
+}
+
+static int eusb2_repeater_init(struct phy *phy)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
+	int num = rptr->cfg->init_tbl_num;
+	int ret = 0;
+	u32 val;
+	int i;
+
+	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
+	if (ret)
+		return ret;
+
+	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
+				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
+
+	for (i = 0; i < num; i++)
+		regmap_update_bits(rptr->regmap,
+					rptr->base + init_tbl[i].offset,
+					init_tbl[i].val, init_tbl[i].val);
+
+	ret = regmap_read_poll_timeout(rptr->regmap,
+					rptr->base + EUSB2_RPTR_STATUS, val,
+					val & RPTR_OK, 10, 5);
+	if (ret)
+		dev_err(rptr->dev, "initialization timed-out\n");
+
+	return ret;
+}
+
+static int eusb2_repeater_set_mode(struct phy *phy,
+					enum phy_mode mode, int submode)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+
+	switch (mode) {
+	case PHY_MODE_USB_HOST:
+		/*
+		 * CM.Lx is prohibited when repeater is already into Lx state as
+		 * per eUSB 1.2 Spec. Below implement software workaround until
+		 * PHY and controller is fixing seen observation.
+		 */
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
+				F_CLK_19P2M_EN, F_CLK_19P2M_EN);
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
+				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
+		break;
+	case PHY_MODE_USB_DEVICE:
+		/*
+		 * In device mode clear host mode related workaround as there
+		 * is no repeater reset available, and enable/disable of
+		 * repeater doesn't clear previous value due to shared
+		 * regulators (say host <-> device mode switch).
+		 */
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
+				F_CLK_19P2M_EN, 0);
+		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
+				V_CLK_19P2M_EN, 0);
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int eusb2_repeater_exit(struct phy *phy)
+{
+	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
+
+	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
+}
+
+
+static const struct phy_ops eusb2_repeater_ops = {
+	.init		= eusb2_repeater_init,
+	.exit		= eusb2_repeater_exit,
+	.set_mode	= eusb2_repeater_set_mode,
+	.owner		= THIS_MODULE,
+};
+
+static int eusb2_repeater_probe(struct platform_device *pdev)
+{
+	struct eusb2_repeater *rptr;
+	struct device *dev = &pdev->dev;
+	struct phy_provider *phy_provider;
+	struct device_node *np;
+	u32 res;
+	int ret;
+
+	np = of_node_get(dev->of_node);
+
+	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
+	if (!rptr)
+		goto err_node_put;
+
+	rptr->dev = dev;
+	dev_set_drvdata(dev, rptr);
+
+	rptr->cfg = of_device_get_match_data(dev);
+	if (!rptr->cfg)
+		goto err_node_put;
+
+	rptr->regmap = dev_get_regmap(dev->parent, NULL);
+	if (!rptr->regmap)
+		goto err_node_put;
+
+	ret = of_property_read_u32(np, "reg", &res);
+	if (ret < 0)
+		goto err_node_put;
+
+	rptr->base = res;
+
+	ret = eusb2_repeater_init_vregs(rptr);
+	if (ret < 0) {
+		dev_err(dev, "unable to get supplies\n");
+		goto err_node_put;
+	}
+
+	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
+	if (IS_ERR(rptr->phy)) {
+		ret = PTR_ERR(rptr->phy);
+		dev_err(dev, "failed to create PHY: %d\n", ret);
+		goto err_node_put;
+	}
+
+	phy_set_drvdata(rptr->phy, rptr);
+
+	of_node_put(np);
+
+	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
+	if (IS_ERR(phy_provider))
+		return PTR_ERR(phy_provider);
+
+	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
+
+	return 0;
+
+err_node_put:
+	of_node_put(np);
+	return ret;
+}
+
+static int eusb2_repeater_remove(struct platform_device *pdev)
+{
+	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
+
+	if (!rptr)
+		return 0;
+
+	eusb2_repeater_exit(rptr->phy);
+	return 0;
+}
+
+
+static const struct of_device_id eusb2_repeater_of_match_table[] = {
+	{
+		.compatible = "qcom,pm8550b-eusb2-repeater",
+		.data = &pm8550b_eusb2_cfg,
+	},
+	{ },
+};
+MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
+
+static struct platform_driver eusb2_repeater_driver = {
+	.probe		= eusb2_repeater_probe,
+	.remove		= eusb2_repeater_remove,
+	.driver = {
+		.name	= "qcom-eusb2-repeater",
+		.of_match_table = eusb2_repeater_of_match_table,
+	},
+};
+
+module_platform_driver(eusb2_repeater_driver);
+
+MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
+MODULE_LICENSE("GPL v2");
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

From: Neil Armstrong <neil.armstrong@linaro.org>

For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
initialize and reset it. So add repeater support

Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
index 23ec162cc3bd..8d972d49732b 100644
--- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
+++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
@@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
 	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
 
 	enum phy_mode mode;
+
+	struct phy *repeater;
 };
 
 static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
@@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
 
 	phy->mode = mode;
 
-	return 0;
+	return phy_set_mode_ext(phy->repeater, mode, submode);
 }
 
 static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
@@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
 	if (ret)
 		return ret;
 
+	ret = phy_init(phy->repeater);
+	if (ret) {
+		dev_err(&p->dev, "repeater init failed. %d\n", ret);
+		goto disable_vreg;
+	}
+
 	ret = clk_prepare_enable(phy->ref_clk);
 	if (ret) {
 		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
@@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
 
 	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
 
+	phy_exit(phy->repeater);
+
 	return 0;
 }
 
@@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
 	if (ret)
 		return dev_err_probe(dev, ret,
 				     "failed to get regulator supplies\n");
+
+	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
+	if (IS_ERR(phy->repeater))
+		return dev_err_probe(dev, PTR_ERR(phy->repeater),
+				     "failed to get repeater\n");
+
 	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
 	if (IS_ERR(generic_phy)) {
 		dev_err(dev, "failed to create phy %d\n", ret);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

From: Neil Armstrong <neil.armstrong@linaro.org>

For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
initialize and reset it. So add repeater support

Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
---
 drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
index 23ec162cc3bd..8d972d49732b 100644
--- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
+++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
@@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
 	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
 
 	enum phy_mode mode;
+
+	struct phy *repeater;
 };
 
 static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
@@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
 
 	phy->mode = mode;
 
-	return 0;
+	return phy_set_mode_ext(phy->repeater, mode, submode);
 }
 
 static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
@@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
 	if (ret)
 		return ret;
 
+	ret = phy_init(phy->repeater);
+	if (ret) {
+		dev_err(&p->dev, "repeater init failed. %d\n", ret);
+		goto disable_vreg;
+	}
+
 	ret = clk_prepare_enable(phy->ref_clk);
 	if (ret) {
 		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
@@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
 
 	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
 
+	phy_exit(phy->repeater);
+
 	return 0;
 }
 
@@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
 	if (ret)
 		return dev_err_probe(dev, ret,
 				     "failed to get regulator supplies\n");
+
+	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
+	if (IS_ERR(phy->repeater))
+		return dev_err_probe(dev, PTR_ERR(phy->repeater),
+				     "failed to get repeater\n");
+
 	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
 	if (IS_ERR(generic_phy)) {
 		dev_err(dev, "failed to create phy %d\n", ret);
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 6/7] arm64: dts: qcom: pm8550b: Add eUSB2 repeater node
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

From: Neil Armstrong <neil.armstrong@linaro.org>

Add nodes for the eUSB2 repeater found on the pm8550b SPMI PMIC.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 arch/arm64/boot/dts/qcom/pm8550b.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/pm8550b.dtsi b/arch/arm64/boot/dts/qcom/pm8550b.dtsi
index 16bcfb64d735..72609f31c890 100644
--- a/arch/arm64/boot/dts/qcom/pm8550b.dtsi
+++ b/arch/arm64/boot/dts/qcom/pm8550b.dtsi
@@ -55,5 +55,11 @@ pm8550b_gpios: gpio@8800 {
 			interrupt-controller;
 			#interrupt-cells = <2>;
 		};
+
+		pm8550b_eusb2_repeater: phy@fd00 {
+			compatible = "qcom,pm8550b-eusb2-repeater";
+			reg = <0xfd00>;
+			#phy-cells = <0>;
+		};
 	};
 };
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 6/7] arm64: dts: qcom: pm8550b: Add eUSB2 repeater node
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

From: Neil Armstrong <neil.armstrong@linaro.org>

Add nodes for the eUSB2 repeater found on the pm8550b SPMI PMIC.

Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 arch/arm64/boot/dts/qcom/pm8550b.dtsi | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/pm8550b.dtsi b/arch/arm64/boot/dts/qcom/pm8550b.dtsi
index 16bcfb64d735..72609f31c890 100644
--- a/arch/arm64/boot/dts/qcom/pm8550b.dtsi
+++ b/arch/arm64/boot/dts/qcom/pm8550b.dtsi
@@ -55,5 +55,11 @@ pm8550b_gpios: gpio@8800 {
 			interrupt-controller;
 			#interrupt-cells = <2>;
 		};
+
+		pm8550b_eusb2_repeater: phy@fd00 {
+			compatible = "qcom,pm8550b-eusb2-repeater";
+			reg = <0xfd00>;
+			#phy-cells = <0>;
+		};
 	};
 };
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 7/7] arm64: dts: qcom: sm8550-mtp: Add eUSB2 repeater node
  2023-02-02 13:38 ` Abel Vesa
@ 2023-02-02 13:38   ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

Add the PMIC eUSB2 repeater node and add the usb-repeater
property to the eUSB2 PHY to allow it to be controlled by the
PHY driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 arch/arm64/boot/dts/qcom/sm8550-mtp.dts | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8550-mtp.dts b/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
index 03862132fe41..9aaddafa0088 100644
--- a/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
+++ b/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
@@ -456,6 +456,11 @@ sdc2_card_det_n: sdc2-card-det-state {
 	};
 };
 
+&pm8550b_eusb2_repeater {
+	vdd18-supply = <&vreg_l15b_1p8>;
+	vdd3-supply = <&vreg_l5b_3p1>;
+};
+
 &qupv3_id_0 {
 	status = "okay";
 };
@@ -562,6 +567,9 @@ &usb_1_hsphy {
 	vdd-supply = <&vreg_l1e_0p88>;
 	vdda12-supply = <&vreg_l3e_1p2>;
 
+	phys = <&pm8550b_eusb2_repeater>;
+	phy-names = "eusb2-repeater";
+
 	status = "okay";
 };
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 38+ messages in thread

* [RFC v3 7/7] arm64: dts: qcom: sm8550-mtp: Add eUSB2 repeater node
@ 2023-02-02 13:38   ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-02 13:38 UTC (permalink / raw)
  To: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

Add the PMIC eUSB2 repeater node and add the usb-repeater
property to the eUSB2 PHY to allow it to be controlled by the
PHY driver.

Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
---
 arch/arm64/boot/dts/qcom/sm8550-mtp.dts | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/arm64/boot/dts/qcom/sm8550-mtp.dts b/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
index 03862132fe41..9aaddafa0088 100644
--- a/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
+++ b/arch/arm64/boot/dts/qcom/sm8550-mtp.dts
@@ -456,6 +456,11 @@ sdc2_card_det_n: sdc2-card-det-state {
 	};
 };
 
+&pm8550b_eusb2_repeater {
+	vdd18-supply = <&vreg_l15b_1p8>;
+	vdd3-supply = <&vreg_l5b_3p1>;
+};
+
 &qupv3_id_0 {
 	status = "okay";
 };
@@ -562,6 +567,9 @@ &usb_1_hsphy {
 	vdd-supply = <&vreg_l1e_0p88>;
 	vdda12-supply = <&vreg_l3e_1p2>;
 
+	phys = <&pm8550b_eusb2_repeater>;
+	phy-names = "eusb2-repeater";
+
 	status = "okay";
 };
 
-- 
2.34.1


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply related	[flat|nested] 38+ messages in thread

* Re: [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-02 15:03     ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2023-02-02 15:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Linux Kernel Mailing List, linux-phy, Bjorn Andersson,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	Lee Jones, linux-arm-msm, Konrad Dybcio, Andy Gross, devicetree,
	vkoul


On Thu, 02 Feb 2023 15:38:10 +0200, Abel Vesa wrote:
> The phy pattern property will be used for providing eUSB2 repeater
> functionality. This will be modelled as a Qualcomm PHY driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 

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:
./Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml: Unable to find schema file matching $id: http://devicetree.org/schemas/phy/qcom,snps-eusb2-repeater.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230202133816.4026990-2-abel.vesa@linaro.org

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

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 after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 2/7] dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-02 15:03     ` Rob Herring
  -1 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2023-02-02 15:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: linux-arm-msm, devicetree, Rob Herring, vkoul,
	Kishon Vijay Abraham I, Krzysztof Kozlowski, Konrad Dybcio,
	Andy Gross, Bjorn Andersson, Lee Jones, linux-phy,
	Linux Kernel Mailing List


On Thu, 02 Feb 2023 15:38:11 +0200, Abel Vesa wrote:
> The SM8550 SoC uses Synopsis eUSB2 repeater found in PM8550b.
> Add a dt-binding schema for the new driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  .../phy/qcom,snps-eusb2-repeater.yaml         | 48 +++++++++++++++++++
>  1 file changed, 48 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.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:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: pmic@7: compatible:0: 'qcom,pm8550' is not one of ['qcom,pm6125', 'qcom,pm6150', 'qcom,pm6150l', 'qcom,pm6350', 'qcom,pm660', 'qcom,pm660l', 'qcom,pm7250b', 'qcom,pm7325', 'qcom,pm8004', 'qcom,pm8005', 'qcom,pm8009', 'qcom,pm8019', 'qcom,pm8028', 'qcom,pm8110', 'qcom,pm8150', 'qcom,pm8150b', 'qcom,pm8150c', 'qcom,pm8150l', 'qcom,pm8226', 'qcom,pm8350', 'qcom,pm8350b', 'qcom,pm8350c', 'qcom,pm8841', 'qcom,pm8909', 'qcom,pm8916', 'qcom,pm8941', 'qcom,pm8950', 'qcom,pm8953', 'qcom,pm8994', 'qcom,pm8998', 'qcom,pma8084', 'qcom,pmd9635', 'qcom,pmi8950', 'qcom,pmi8962', 'qcom,pmi8994', 'qcom,pmi8998', 'qcom,pmk8002', 'qcom,pmk8350', 'qcom,pmm8155au', 'qcom,pmp8074', 'qcom,pmr735a', 'qcom,pmr735b', 'qcom,pms405', 'qcom,pmx55', 'qcom,pmx65', 'qcom,smb2351']
	From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: pmic@7: 'phy@fd00' does not match any of the regexes: '(.*)?(wled|leds)@[0-9a-f]+$', '^adc-tm@[0-9a-f]+$', '^adc@[0-9a-f]+$', '^audio-codec@[0-9a-f]+$', '^charger@[0-9a-f]+$', '^mpps@[0-9a-f]+$', '^rtc@[0-9a-f]+$', '^temp-alarm@[0-9a-f]+$', '^usb-detect@[0-9a-f]+$', '^usb-vbus-regulator@[0-9a-f]+$', '^vibrator@[0-9a-f]+$', 'gpio@[0-9a-f]+$', 'pinctrl-[0-9]+', 'pon@[0-9a-f]+$'
	From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: /example-0/pmic@7: failed to match any schema with compatible: ['qcom,pm8550', 'qcom,spmi-pmic']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230202133816.4026990-3-abel.vesa@linaro.org

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

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 after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
@ 2023-02-02 15:03     ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2023-02-02 15:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Linux Kernel Mailing List, linux-phy, Bjorn Andersson,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	Lee Jones, linux-arm-msm, Konrad Dybcio, Andy Gross, devicetree,
	vkoul


On Thu, 02 Feb 2023 15:38:10 +0200, Abel Vesa wrote:
> The phy pattern property will be used for providing eUSB2 repeater
> functionality. This will be modelled as a Qualcomm PHY driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++
>  1 file changed, 4 insertions(+)
> 

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:
./Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml: Unable to find schema file matching $id: http://devicetree.org/schemas/phy/qcom,snps-eusb2-repeater.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230202133816.4026990-2-abel.vesa@linaro.org

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

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 after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 2/7] dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file
@ 2023-02-02 15:03     ` Rob Herring
  0 siblings, 0 replies; 38+ messages in thread
From: Rob Herring @ 2023-02-02 15:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: linux-arm-msm, devicetree, Rob Herring, vkoul,
	Kishon Vijay Abraham I, Krzysztof Kozlowski, Konrad Dybcio,
	Andy Gross, Bjorn Andersson, Lee Jones, linux-phy,
	Linux Kernel Mailing List


On Thu, 02 Feb 2023 15:38:11 +0200, Abel Vesa wrote:
> The SM8550 SoC uses Synopsis eUSB2 repeater found in PM8550b.
> Add a dt-binding schema for the new driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  .../phy/qcom,snps-eusb2-repeater.yaml         | 48 +++++++++++++++++++
>  1 file changed, 48 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.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:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: pmic@7: compatible:0: 'qcom,pm8550' is not one of ['qcom,pm6125', 'qcom,pm6150', 'qcom,pm6150l', 'qcom,pm6350', 'qcom,pm660', 'qcom,pm660l', 'qcom,pm7250b', 'qcom,pm7325', 'qcom,pm8004', 'qcom,pm8005', 'qcom,pm8009', 'qcom,pm8019', 'qcom,pm8028', 'qcom,pm8110', 'qcom,pm8150', 'qcom,pm8150b', 'qcom,pm8150c', 'qcom,pm8150l', 'qcom,pm8226', 'qcom,pm8350', 'qcom,pm8350b', 'qcom,pm8350c', 'qcom,pm8841', 'qcom,pm8909', 'qcom,pm8916', 'qcom,pm8941', 'qcom,pm8950', 'qcom,pm8953', 'qcom,pm8994', 'qcom,pm8998', 'qcom,pma8084', 'qcom,pmd9635', 'qcom,pmi8950', 'qcom,pmi8962', 'qcom,pmi8994', 'qcom,pmi8998', 'qcom,pmk8002', 'qcom,pmk8350', 'qcom,pmm8155au', 'qcom,pmp8074', 'qcom,pmr735a', 'qcom,pmr735b', 'qcom,pms405', 'qcom,pmx55', 'qcom,pmx65', 'qcom,smb2351']
	From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: pmic@7: 'phy@fd00' does not match any of the regexes: '(.*)?(wled|leds)@[0-9a-f]+$', '^adc-tm@[0-9a-f]+$', '^adc@[0-9a-f]+$', '^audio-codec@[0-9a-f]+$', '^charger@[0-9a-f]+$', '^mpps@[0-9a-f]+$', '^rtc@[0-9a-f]+$', '^temp-alarm@[0-9a-f]+$', '^usb-detect@[0-9a-f]+$', '^usb-vbus-regulator@[0-9a-f]+$', '^vibrator@[0-9a-f]+$', 'gpio@[0-9a-f]+$', 'pinctrl-[0-9]+', 'pon@[0-9a-f]+$'
	From schema: /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml
Documentation/devicetree/bindings/phy/qcom,snps-eusb2-repeater.example.dtb: /example-0/pmic@7: failed to match any schema with compatible: ['qcom,pm8550', 'qcom,spmi-pmic']

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230202133816.4026990-3-abel.vesa@linaro.org

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

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 after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-02 17:00     ` Krzysztof Kozlowski
  -1 siblings, 0 replies; 38+ messages in thread
From: Krzysztof Kozlowski @ 2023-02-02 17:00 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 14:38, Abel Vesa wrote:
> The phy pattern property will be used for providing eUSB2 repeater
> functionality. This will be modelled as a Qualcomm PHY driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++

You need to re-order your patches to keep everything bisectable.

Best regards,
Krzysztof


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy
@ 2023-02-02 17:00     ` Krzysztof Kozlowski
  0 siblings, 0 replies; 38+ messages in thread
From: Krzysztof Kozlowski @ 2023-02-02 17:00 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 14:38, Abel Vesa wrote:
> The phy pattern property will be used for providing eUSB2 repeater
> functionality. This will be modelled as a Qualcomm PHY driver.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  Documentation/devicetree/bindings/mfd/qcom,spmi-pmic.yaml | 4 ++++

You need to re-order your patches to keep everything bisectable.

Best regards,
Krzysztof


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-03 13:48     ` Vinod Koul
  -1 siblings, 0 replies; 38+ messages in thread
From: Vinod Koul @ 2023-02-03 13:48 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02-02-23, 15:38, Abel Vesa wrote:
> PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> So add a new phy driver for it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  drivers/phy/qualcomm/Kconfig                  |   9 +
>  drivers/phy/qualcomm/Makefile                 |   1 +
>  .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
>  3 files changed, 288 insertions(+)
>  create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> 
> diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
> index 27b5a2a3637d..a70631b04522 100644
> --- a/drivers/phy/qualcomm/Kconfig
> +++ b/drivers/phy/qualcomm/Kconfig
> @@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
>  	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
>  	  on Qualcomm SOCs.
>  
> +config PHY_QCOM_EUSB2_REPEATER
> +	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
> +	depends on OF && (ARCH_QCOM || COMPILE_TEST)
> +	select GENERIC_PHY
> +	help
> +	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
> +	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
> +	  on Qualcomm SOCs.
> +
>  config PHY_QCOM_USB_HS
>  	tristate "Qualcomm USB HS PHY module"
>  	depends on USB_ULPI_BUS
> diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
> index 3ee118f4dfc7..7dcba9537b69 100644
> --- a/drivers/phy/qualcomm/Makefile
> +++ b/drivers/phy/qualcomm/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
>  
>  obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
>  obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
> +obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
>  obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
>  obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
>  obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
> diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> new file mode 100644
> index 000000000000..f7f822f2973f
> --- /dev/null
> +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> @@ -0,0 +1,278 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023, Linaro Limited
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/phy/phy.h>
> +
> +/* eUSB2 status registers */
> +#define EUSB2_RPTR_STATUS		0x08
> +#define	RPTR_OK				BIT(7)
> +
> +/* eUSB2 control registers */
> +#define EUSB2_EN_CTL1			0x46
> +#define EUSB2_RPTR_EN			BIT(7)
> +
> +#define PHY_HOST_MODE			BIT(0)
> +#define EUSB2_FORCE_EN_5		0xE8
> +#define F_CLK_19P2M_EN			BIT(6)
> +#define F_CLK_19P2M_EN_SHIFT		6

Why use shifts, use FIELD_{PREP|GET} instead

> +
> +#define EUSB2_FORCE_VAL_5		0xED
> +#define V_CLK_19P2M_EN			BIT(6)
> +#define V_CLK_19P2M_EN_SHIFT		6
> +
> +#define EUSB2_TUNE_IUSB2		0x51
> +#define EUSB2_TUNE_SQUELCH_U		0x54
> +#define EUSB2_TUNE_USB2_PREEM		0x57
> +
> +#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
> +	{					\
> +		.offset = o,			\
> +		.val = v,			\
> +	}
> +
> +enum repeater_mode {
> +	REPEATER_HOST_MODE,
> +	REPEATER_PERIPH_MODE,
> +};
> +
> +struct eusb2_repeater_init_tbl {
> +	unsigned int offset;
> +	unsigned int val;
> +};
> +
> +struct eusb2_repeater_cfg {
> +	const struct eusb2_repeater_init_tbl *init_tbl;
> +	int init_tbl_num;
> +	/* regulators to be requested */

this comments is not very useful! either drop or add a meaningful
comment

> +	const char * const *vreg_list;
> +	int num_vregs;
> +};
> +
> +struct eusb2_repeater {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct phy *phy;
> +	struct regulator_bulk_data *vregs;
> +	const struct eusb2_repeater_cfg *cfg;
> +	u16 base;
> +	enum phy_mode mode;
> +};
> +
> +static const char * const pm8550b_vreg_l[] = {
> +	"vdd18", "vdd3",
> +};
> +
> +static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
> +};
> +
> +static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
> +	.init_tbl	= pm8550b_init_tbl,
> +	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
> +	.vreg_list	= pm8550b_vreg_l,
> +	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
> +};
> +
> +static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
> +{
> +	int num = rptr->cfg->num_vregs;
> +	struct device *dev = rptr->dev;
> +	int i;
> +
> +	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
> +	if (!rptr->vregs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < num; i++)
> +		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
> +
> +	return devm_regulator_bulk_get(dev, num, rptr->vregs);
> +}
> +
> +static int eusb2_repeater_init(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> +	int num = rptr->cfg->init_tbl_num;
> +	int ret = 0;

superfluous init

> +	u32 val;
> +	int i;
> +
> +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> +	if (ret)
> +		return ret;
> +
> +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> +
> +	for (i = 0; i < num; i++)
> +		regmap_update_bits(rptr->regmap,
> +					rptr->base + init_tbl[i].offset,
> +					init_tbl[i].val, init_tbl[i].val);
> +
> +	ret = regmap_read_poll_timeout(rptr->regmap,
> +					rptr->base + EUSB2_RPTR_STATUS, val,
> +					val & RPTR_OK, 10, 5);
> +	if (ret)
> +		dev_err(rptr->dev, "initialization timed-out\n");
> +
> +	return ret;
> +}
> +
> +static int eusb2_repeater_set_mode(struct phy *phy,
> +					enum phy_mode mode, int submode)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	switch (mode) {
> +	case PHY_MODE_USB_HOST:
> +		/*
> +		 * CM.Lx is prohibited when repeater is already into Lx state as
> +		 * per eUSB 1.2 Spec. Below implement software workaround until
> +		 * PHY and controller is fixing seen observation.
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, F_CLK_19P2M_EN);

pls align to preceding open brace (hint checkpatch --strict would warn
you for this)

> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
> +		break;
> +	case PHY_MODE_USB_DEVICE:
> +		/*
> +		 * In device mode clear host mode related workaround as there
> +		 * is no repeater reset available, and enable/disable of
> +		 * repeater doesn't clear previous value due to shared
> +		 * regulators (say host <-> device mode switch).
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, 0);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, 0);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int eusb2_repeater_exit(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
> +}
> +
> +
> +static const struct phy_ops eusb2_repeater_ops = {
> +	.init		= eusb2_repeater_init,
> +	.exit		= eusb2_repeater_exit,
> +	.set_mode	= eusb2_repeater_set_mode,
> +	.owner		= THIS_MODULE,
> +};
> +
> +static int eusb2_repeater_probe(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *phy_provider;
> +	struct device_node *np;
> +	u32 res;
> +	int ret;
> +
> +	np = of_node_get(dev->of_node);
> +
> +	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
> +	if (!rptr)
> +		goto err_node_put;
> +
> +	rptr->dev = dev;
> +	dev_set_drvdata(dev, rptr);
> +
> +	rptr->cfg = of_device_get_match_data(dev);
> +	if (!rptr->cfg)
> +		goto err_node_put;
> +
> +	rptr->regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!rptr->regmap)
> +		goto err_node_put;
> +
> +	ret = of_property_read_u32(np, "reg", &res);
> +	if (ret < 0)
> +		goto err_node_put;
> +
> +	rptr->base = res;
> +
> +	ret = eusb2_repeater_init_vregs(rptr);
> +	if (ret < 0) {
> +		dev_err(dev, "unable to get supplies\n");
> +		goto err_node_put;
> +	}
> +
> +	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
> +	if (IS_ERR(rptr->phy)) {
> +		ret = PTR_ERR(rptr->phy);
> +		dev_err(dev, "failed to create PHY: %d\n", ret);
> +		goto err_node_put;
> +	}
> +
> +	phy_set_drvdata(rptr->phy, rptr);
> +
> +	of_node_put(np);
> +
> +	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> +	if (IS_ERR(phy_provider))
> +		return PTR_ERR(phy_provider);
> +
> +	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
> +
> +	return 0;
> +
> +err_node_put:
> +	of_node_put(np);
> +	return ret;
> +}
> +
> +static int eusb2_repeater_remove(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
> +
> +	if (!rptr)
> +		return 0;
> +
> +	eusb2_repeater_exit(rptr->phy);
> +	return 0;
> +}
> +
> +
> +static const struct of_device_id eusb2_repeater_of_match_table[] = {
> +	{
> +		.compatible = "qcom,pm8550b-eusb2-repeater",
> +		.data = &pm8550b_eusb2_cfg,
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
> +
> +static struct platform_driver eusb2_repeater_driver = {
> +	.probe		= eusb2_repeater_probe,
> +	.remove		= eusb2_repeater_remove,
> +	.driver = {
> +		.name	= "qcom-eusb2-repeater",
> +		.of_match_table = eusb2_repeater_of_match_table,
> +	},
> +};
> +
> +module_platform_driver(eusb2_repeater_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> 2.34.1

-- 
~Vinod

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-03 13:48     ` Vinod Koul
  0 siblings, 0 replies; 38+ messages in thread
From: Vinod Koul @ 2023-02-03 13:48 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02-02-23, 15:38, Abel Vesa wrote:
> PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> So add a new phy driver for it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>  drivers/phy/qualcomm/Kconfig                  |   9 +
>  drivers/phy/qualcomm/Makefile                 |   1 +
>  .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
>  3 files changed, 288 insertions(+)
>  create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> 
> diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
> index 27b5a2a3637d..a70631b04522 100644
> --- a/drivers/phy/qualcomm/Kconfig
> +++ b/drivers/phy/qualcomm/Kconfig
> @@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
>  	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
>  	  on Qualcomm SOCs.
>  
> +config PHY_QCOM_EUSB2_REPEATER
> +	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
> +	depends on OF && (ARCH_QCOM || COMPILE_TEST)
> +	select GENERIC_PHY
> +	help
> +	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
> +	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
> +	  on Qualcomm SOCs.
> +
>  config PHY_QCOM_USB_HS
>  	tristate "Qualcomm USB HS PHY module"
>  	depends on USB_ULPI_BUS
> diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
> index 3ee118f4dfc7..7dcba9537b69 100644
> --- a/drivers/phy/qualcomm/Makefile
> +++ b/drivers/phy/qualcomm/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
>  
>  obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
>  obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
> +obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
>  obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
>  obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
>  obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
> diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> new file mode 100644
> index 000000000000..f7f822f2973f
> --- /dev/null
> +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> @@ -0,0 +1,278 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023, Linaro Limited
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/phy/phy.h>
> +
> +/* eUSB2 status registers */
> +#define EUSB2_RPTR_STATUS		0x08
> +#define	RPTR_OK				BIT(7)
> +
> +/* eUSB2 control registers */
> +#define EUSB2_EN_CTL1			0x46
> +#define EUSB2_RPTR_EN			BIT(7)
> +
> +#define PHY_HOST_MODE			BIT(0)
> +#define EUSB2_FORCE_EN_5		0xE8
> +#define F_CLK_19P2M_EN			BIT(6)
> +#define F_CLK_19P2M_EN_SHIFT		6

Why use shifts, use FIELD_{PREP|GET} instead

> +
> +#define EUSB2_FORCE_VAL_5		0xED
> +#define V_CLK_19P2M_EN			BIT(6)
> +#define V_CLK_19P2M_EN_SHIFT		6
> +
> +#define EUSB2_TUNE_IUSB2		0x51
> +#define EUSB2_TUNE_SQUELCH_U		0x54
> +#define EUSB2_TUNE_USB2_PREEM		0x57
> +
> +#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
> +	{					\
> +		.offset = o,			\
> +		.val = v,			\
> +	}
> +
> +enum repeater_mode {
> +	REPEATER_HOST_MODE,
> +	REPEATER_PERIPH_MODE,
> +};
> +
> +struct eusb2_repeater_init_tbl {
> +	unsigned int offset;
> +	unsigned int val;
> +};
> +
> +struct eusb2_repeater_cfg {
> +	const struct eusb2_repeater_init_tbl *init_tbl;
> +	int init_tbl_num;
> +	/* regulators to be requested */

this comments is not very useful! either drop or add a meaningful
comment

> +	const char * const *vreg_list;
> +	int num_vregs;
> +};
> +
> +struct eusb2_repeater {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct phy *phy;
> +	struct regulator_bulk_data *vregs;
> +	const struct eusb2_repeater_cfg *cfg;
> +	u16 base;
> +	enum phy_mode mode;
> +};
> +
> +static const char * const pm8550b_vreg_l[] = {
> +	"vdd18", "vdd3",
> +};
> +
> +static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
> +};
> +
> +static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
> +	.init_tbl	= pm8550b_init_tbl,
> +	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
> +	.vreg_list	= pm8550b_vreg_l,
> +	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
> +};
> +
> +static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
> +{
> +	int num = rptr->cfg->num_vregs;
> +	struct device *dev = rptr->dev;
> +	int i;
> +
> +	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
> +	if (!rptr->vregs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < num; i++)
> +		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
> +
> +	return devm_regulator_bulk_get(dev, num, rptr->vregs);
> +}
> +
> +static int eusb2_repeater_init(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> +	int num = rptr->cfg->init_tbl_num;
> +	int ret = 0;

superfluous init

> +	u32 val;
> +	int i;
> +
> +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> +	if (ret)
> +		return ret;
> +
> +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> +
> +	for (i = 0; i < num; i++)
> +		regmap_update_bits(rptr->regmap,
> +					rptr->base + init_tbl[i].offset,
> +					init_tbl[i].val, init_tbl[i].val);
> +
> +	ret = regmap_read_poll_timeout(rptr->regmap,
> +					rptr->base + EUSB2_RPTR_STATUS, val,
> +					val & RPTR_OK, 10, 5);
> +	if (ret)
> +		dev_err(rptr->dev, "initialization timed-out\n");
> +
> +	return ret;
> +}
> +
> +static int eusb2_repeater_set_mode(struct phy *phy,
> +					enum phy_mode mode, int submode)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	switch (mode) {
> +	case PHY_MODE_USB_HOST:
> +		/*
> +		 * CM.Lx is prohibited when repeater is already into Lx state as
> +		 * per eUSB 1.2 Spec. Below implement software workaround until
> +		 * PHY and controller is fixing seen observation.
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, F_CLK_19P2M_EN);

pls align to preceding open brace (hint checkpatch --strict would warn
you for this)

> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
> +		break;
> +	case PHY_MODE_USB_DEVICE:
> +		/*
> +		 * In device mode clear host mode related workaround as there
> +		 * is no repeater reset available, and enable/disable of
> +		 * repeater doesn't clear previous value due to shared
> +		 * regulators (say host <-> device mode switch).
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, 0);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, 0);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int eusb2_repeater_exit(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
> +}
> +
> +
> +static const struct phy_ops eusb2_repeater_ops = {
> +	.init		= eusb2_repeater_init,
> +	.exit		= eusb2_repeater_exit,
> +	.set_mode	= eusb2_repeater_set_mode,
> +	.owner		= THIS_MODULE,
> +};
> +
> +static int eusb2_repeater_probe(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *phy_provider;
> +	struct device_node *np;
> +	u32 res;
> +	int ret;
> +
> +	np = of_node_get(dev->of_node);
> +
> +	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
> +	if (!rptr)
> +		goto err_node_put;
> +
> +	rptr->dev = dev;
> +	dev_set_drvdata(dev, rptr);
> +
> +	rptr->cfg = of_device_get_match_data(dev);
> +	if (!rptr->cfg)
> +		goto err_node_put;
> +
> +	rptr->regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!rptr->regmap)
> +		goto err_node_put;
> +
> +	ret = of_property_read_u32(np, "reg", &res);
> +	if (ret < 0)
> +		goto err_node_put;
> +
> +	rptr->base = res;
> +
> +	ret = eusb2_repeater_init_vregs(rptr);
> +	if (ret < 0) {
> +		dev_err(dev, "unable to get supplies\n");
> +		goto err_node_put;
> +	}
> +
> +	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
> +	if (IS_ERR(rptr->phy)) {
> +		ret = PTR_ERR(rptr->phy);
> +		dev_err(dev, "failed to create PHY: %d\n", ret);
> +		goto err_node_put;
> +	}
> +
> +	phy_set_drvdata(rptr->phy, rptr);
> +
> +	of_node_put(np);
> +
> +	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> +	if (IS_ERR(phy_provider))
> +		return PTR_ERR(phy_provider);
> +
> +	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
> +
> +	return 0;
> +
> +err_node_put:
> +	of_node_put(np);
> +	return ret;
> +}
> +
> +static int eusb2_repeater_remove(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
> +
> +	if (!rptr)
> +		return 0;
> +
> +	eusb2_repeater_exit(rptr->phy);
> +	return 0;
> +}
> +
> +
> +static const struct of_device_id eusb2_repeater_of_match_table[] = {
> +	{
> +		.compatible = "qcom,pm8550b-eusb2-repeater",
> +		.data = &pm8550b_eusb2_cfg,
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
> +
> +static struct platform_driver eusb2_repeater_driver = {
> +	.probe		= eusb2_repeater_probe,
> +	.remove		= eusb2_repeater_remove,
> +	.driver = {
> +		.name	= "qcom-eusb2-repeater",
> +		.of_match_table = eusb2_repeater_of_match_table,
> +	},
> +};
> +
> +module_platform_driver(eusb2_repeater_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
> +MODULE_LICENSE("GPL v2");
> -- 
> 2.34.1

-- 
~Vinod

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-03 13:49     ` Vinod Koul
  -1 siblings, 0 replies; 38+ messages in thread
From: Vinod Koul @ 2023-02-03 13:49 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

On 02-02-23, 15:38, Abel Vesa wrote:
> From: Neil Armstrong <neil.armstrong@linaro.org>
> 
> For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
> initialize and reset it. So add repeater support
> 
> Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> ---
>  drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> index 23ec162cc3bd..8d972d49732b 100644
> --- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> @@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
>  	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
>  
>  	enum phy_mode mode;
> +
> +	struct phy *repeater;
>  };
>  
>  static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
> @@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
>  
>  	phy->mode = mode;
>  
> -	return 0;
> +	return phy_set_mode_ext(phy->repeater, mode, submode);
>  }
>  
>  static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
> @@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
>  	if (ret)
>  		return ret;
>  
> +	ret = phy_init(phy->repeater);
> +	if (ret) {
> +		dev_err(&p->dev, "repeater init failed. %d\n", ret);
> +		goto disable_vreg;
> +	}
> +
>  	ret = clk_prepare_enable(phy->ref_clk);
>  	if (ret) {
>  		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
> @@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
>  
>  	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
>  
> +	phy_exit(phy->repeater);
> +
>  	return 0;
>  }
>  
> @@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
>  	if (ret)
>  		return dev_err_probe(dev, ret,
>  				     "failed to get regulator supplies\n");
> +
> +	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
> +	if (IS_ERR(phy->repeater))
> +		return dev_err_probe(dev, PTR_ERR(phy->repeater),
> +				     "failed to get repeater\n");

That implies repeater is assumed to be there for all designs, how about
older devices, they may not have a repeater?

> +
>  	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
>  	if (IS_ERR(generic_phy)) {
>  		dev_err(dev, "failed to create phy %d\n", ret);
> -- 
> 2.34.1

-- 
~Vinod

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
@ 2023-02-03 13:49     ` Vinod Koul
  0 siblings, 0 replies; 38+ messages in thread
From: Vinod Koul @ 2023-02-03 13:49 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

On 02-02-23, 15:38, Abel Vesa wrote:
> From: Neil Armstrong <neil.armstrong@linaro.org>
> 
> For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
> initialize and reset it. So add repeater support
> 
> Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> ---
>  drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
>  1 file changed, 17 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> index 23ec162cc3bd..8d972d49732b 100644
> --- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> +++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> @@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
>  	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
>  
>  	enum phy_mode mode;
> +
> +	struct phy *repeater;
>  };
>  
>  static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
> @@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
>  
>  	phy->mode = mode;
>  
> -	return 0;
> +	return phy_set_mode_ext(phy->repeater, mode, submode);
>  }
>  
>  static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
> @@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
>  	if (ret)
>  		return ret;
>  
> +	ret = phy_init(phy->repeater);
> +	if (ret) {
> +		dev_err(&p->dev, "repeater init failed. %d\n", ret);
> +		goto disable_vreg;
> +	}
> +
>  	ret = clk_prepare_enable(phy->ref_clk);
>  	if (ret) {
>  		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
> @@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
>  
>  	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
>  
> +	phy_exit(phy->repeater);
> +
>  	return 0;
>  }
>  
> @@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
>  	if (ret)
>  		return dev_err_probe(dev, ret,
>  				     "failed to get regulator supplies\n");
> +
> +	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
> +	if (IS_ERR(phy->repeater))
> +		return dev_err_probe(dev, PTR_ERR(phy->repeater),
> +				     "failed to get repeater\n");

That implies repeater is assumed to be there for all designs, how about
older devices, they may not have a repeater?

> +
>  	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
>  	if (IS_ERR(generic_phy)) {
>  		dev_err(dev, "failed to create phy %d\n", ret);
> -- 
> 2.34.1

-- 
~Vinod

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 3/7] dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-03 16:37     ` Dmitry Baryshkov
  -1 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-03 16:37 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 15:38, Abel Vesa wrote:
> The phy properties are used for allowing the eusb2 to interface
> with the repeater, which is modelled as a phy driver. Add the phys
> and phy-names properties.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>   .../devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml     | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> index de72577e34a4..8efb09b2dc5c 100644
> --- a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> +++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> @@ -33,6 +33,15 @@ properties:
>     resets:
>       maxItems: 1
>   
> +  phys:
> +    maxItems: 1
> +    description:
> +      Phandle to eUSB2 to USB 2.0 repeater
> +
> +  phy-names:
> +    items:
> +      - const: eusb2-repeater
> +

Do we really need the phy-names? There is a single PHY.

-- 
With best wishes
Dmitry


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 3/7] dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties
@ 2023-02-03 16:37     ` Dmitry Baryshkov
  0 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-03 16:37 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 15:38, Abel Vesa wrote:
> The phy properties are used for allowing the eusb2 to interface
> with the repeater, which is modelled as a phy driver. Add the phys
> and phy-names properties.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>   .../devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml     | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> index de72577e34a4..8efb09b2dc5c 100644
> --- a/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> +++ b/Documentation/devicetree/bindings/phy/qcom,snps-eusb2-phy.yaml
> @@ -33,6 +33,15 @@ properties:
>     resets:
>       maxItems: 1
>   
> +  phys:
> +    maxItems: 1
> +    description:
> +      Phandle to eUSB2 to USB 2.0 repeater
> +
> +  phy-names:
> +    items:
> +      - const: eusb2-repeater
> +

Do we really need the phy-names? There is a single PHY.

-- 
With best wishes
Dmitry


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-02 13:38   ` Abel Vesa
@ 2023-02-03 16:51     ` Dmitry Baryshkov
  -1 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-03 16:51 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 15:38, Abel Vesa wrote:
> PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> So add a new phy driver for it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>   drivers/phy/qualcomm/Kconfig                  |   9 +
>   drivers/phy/qualcomm/Makefile                 |   1 +
>   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
>   3 files changed, 288 insertions(+)
>   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> 
> diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
> index 27b5a2a3637d..a70631b04522 100644
> --- a/drivers/phy/qualcomm/Kconfig
> +++ b/drivers/phy/qualcomm/Kconfig
> @@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
>   	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
>   	  on Qualcomm SOCs.
>   
> +config PHY_QCOM_EUSB2_REPEATER
> +	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
> +	depends on OF && (ARCH_QCOM || COMPILE_TEST)
> +	select GENERIC_PHY
> +	help
> +	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
> +	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
> +	  on Qualcomm SOCs.
> +
>   config PHY_QCOM_USB_HS
>   	tristate "Qualcomm USB HS PHY module"
>   	depends on USB_ULPI_BUS
> diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
> index 3ee118f4dfc7..7dcba9537b69 100644
> --- a/drivers/phy/qualcomm/Makefile
> +++ b/drivers/phy/qualcomm/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
>   
>   obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
>   obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
> +obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
>   obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
>   obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
>   obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
> diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> new file mode 100644
> index 000000000000..f7f822f2973f
> --- /dev/null
> +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> @@ -0,0 +1,278 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023, Linaro Limited
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/phy/phy.h>
> +
> +/* eUSB2 status registers */
> +#define EUSB2_RPTR_STATUS		0x08
> +#define	RPTR_OK				BIT(7)
> +
> +/* eUSB2 control registers */
> +#define EUSB2_EN_CTL1			0x46
> +#define EUSB2_RPTR_EN			BIT(7)
> +
> +#define PHY_HOST_MODE			BIT(0)
> +#define EUSB2_FORCE_EN_5		0xE8
> +#define F_CLK_19P2M_EN			BIT(6)
> +#define F_CLK_19P2M_EN_SHIFT		6

Drop the _SHIFT defines please, they don't add anything on top of 
previous defines (and don't seem to be used anyway).

> +
> +#define EUSB2_FORCE_VAL_5		0xED
> +#define V_CLK_19P2M_EN			BIT(6)
> +#define V_CLK_19P2M_EN_SHIFT		6
> +
> +#define EUSB2_TUNE_IUSB2		0x51
> +#define EUSB2_TUNE_SQUELCH_U		0x54
> +#define EUSB2_TUNE_USB2_PREEM		0x57
> +
> +#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
> +	{					\
> +		.offset = o,			\
> +		.val = v,			\
> +	}
> +
> +enum repeater_mode {
> +	REPEATER_HOST_MODE,
> +	REPEATER_PERIPH_MODE,
> +};

I think this is unused now.

> +
> +struct eusb2_repeater_init_tbl {
> +	unsigned int offset;
> +	unsigned int val;
> +};
> +
> +struct eusb2_repeater_cfg {
> +	const struct eusb2_repeater_init_tbl *init_tbl;
> +	int init_tbl_num;
> +	/* regulators to be requested */
> +	const char * const *vreg_list;
> +	int num_vregs;
> +};
> +
> +struct eusb2_repeater {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct phy *phy;
> +	struct regulator_bulk_data *vregs;
> +	const struct eusb2_repeater_cfg *cfg;
> +	u16 base;
> +	enum phy_mode mode;
> +};
> +
> +static const char * const pm8550b_vreg_l[] = {
> +	"vdd18", "vdd3",
> +};
> +
> +static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
> +};
> +
> +static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
> +	.init_tbl	= pm8550b_init_tbl,
> +	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
> +	.vreg_list	= pm8550b_vreg_l,
> +	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
> +};
> +
> +static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
> +{
> +	int num = rptr->cfg->num_vregs;
> +	struct device *dev = rptr->dev;
> +	int i;
> +
> +	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
> +	if (!rptr->vregs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < num; i++)
> +		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
> +
> +	return devm_regulator_bulk_get(dev, num, rptr->vregs);
> +}
> +
> +static int eusb2_repeater_init(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> +	int num = rptr->cfg->init_tbl_num;
> +	int ret = 0;
> +	u32 val;
> +	int i;
> +
> +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> +	if (ret)
> +		return ret;
> +
> +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> +
> +	for (i = 0; i < num; i++)
> +		regmap_update_bits(rptr->regmap,
> +					rptr->base + init_tbl[i].offset,
> +					init_tbl[i].val, init_tbl[i].val);

I'd move this to a separate function. Then you can use it in the 
set_mode() too.

> +
> +	ret = regmap_read_poll_timeout(rptr->regmap,
> +					rptr->base + EUSB2_RPTR_STATUS, val,
> +					val & RPTR_OK, 10, 5);
> +	if (ret)
> +		dev_err(rptr->dev, "initialization timed-out\n");
> +
> +	return ret;
> +}
> +
> +static int eusb2_repeater_set_mode(struct phy *phy,
> +					enum phy_mode mode, int submode)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	switch (mode) {
> +	case PHY_MODE_USB_HOST:
> +		/*
> +		 * CM.Lx is prohibited when repeater is already into Lx state as
> +		 * per eUSB 1.2 Spec. Below implement software workaround until
> +		 * PHY and controller is fixing seen observation.
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, F_CLK_19P2M_EN);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
> +		break;
> +	case PHY_MODE_USB_DEVICE:
> +		/*
> +		 * In device mode clear host mode related workaround as there
> +		 * is no repeater reset available, and enable/disable of
> +		 * repeater doesn't clear previous value due to shared
> +		 * regulators (say host <-> device mode switch).
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, 0);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, 0);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int eusb2_repeater_exit(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
> +}
> +
> +
> +static const struct phy_ops eusb2_repeater_ops = {
> +	.init		= eusb2_repeater_init,
> +	.exit		= eusb2_repeater_exit,
> +	.set_mode	= eusb2_repeater_set_mode,
> +	.owner		= THIS_MODULE,
> +};
> +
> +static int eusb2_repeater_probe(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *phy_provider;
> +	struct device_node *np;
> +	u32 res;
> +	int ret;
> +
> +	np = of_node_get(dev->of_node);

Do you really need to increase the refcount here? I thought that we can 
use dev->of_node straight away.

> +
> +	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
> +	if (!rptr)
> +		goto err_node_put;
> +
> +	rptr->dev = dev;
> +	dev_set_drvdata(dev, rptr);
> +
> +	rptr->cfg = of_device_get_match_data(dev);
> +	if (!rptr->cfg)
> +		goto err_node_put;
> +
> +	rptr->regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!rptr->regmap)
> +		goto err_node_put;
> +
> +	ret = of_property_read_u32(np, "reg", &res);
> +	if (ret < 0)
> +		goto err_node_put;
> +
> +	rptr->base = res;
> +
> +	ret = eusb2_repeater_init_vregs(rptr);
> +	if (ret < 0) {
> +		dev_err(dev, "unable to get supplies\n");
> +		goto err_node_put;
> +	}
> +
> +	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
> +	if (IS_ERR(rptr->phy)) {
> +		ret = PTR_ERR(rptr->phy);
> +		dev_err(dev, "failed to create PHY: %d\n", ret);
> +		goto err_node_put;
> +	}
> +
> +	phy_set_drvdata(rptr->phy, rptr);
> +
> +	of_node_put(np);
> +
> +	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> +	if (IS_ERR(phy_provider))
> +		return PTR_ERR(phy_provider);
> +
> +	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
> +
> +	return 0;
> +
> +err_node_put:
> +	of_node_put(np);
> +	return ret;
> +}
> +
> +static int eusb2_repeater_remove(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
> +
> +	if (!rptr)
> +		return 0;
> +
> +	eusb2_repeater_exit(rptr->phy);
> +	return 0;
> +}
> +
> +
> +static const struct of_device_id eusb2_repeater_of_match_table[] = {
> +	{
> +		.compatible = "qcom,pm8550b-eusb2-repeater",
> +		.data = &pm8550b_eusb2_cfg,
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
> +
> +static struct platform_driver eusb2_repeater_driver = {
> +	.probe		= eusb2_repeater_probe,
> +	.remove		= eusb2_repeater_remove,
> +	.driver = {
> +		.name	= "qcom-eusb2-repeater",
> +		.of_match_table = eusb2_repeater_of_match_table,
> +	},
> +};
> +
> +module_platform_driver(eusb2_repeater_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
> +MODULE_LICENSE("GPL v2");

-- 
With best wishes
Dmitry


^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-03 16:51     ` Dmitry Baryshkov
  0 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-03 16:51 UTC (permalink / raw)
  To: Abel Vesa, Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I
  Cc: linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 02/02/2023 15:38, Abel Vesa wrote:
> PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> So add a new phy driver for it.
> 
> Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> ---
>   drivers/phy/qualcomm/Kconfig                  |   9 +
>   drivers/phy/qualcomm/Makefile                 |   1 +
>   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
>   3 files changed, 288 insertions(+)
>   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> 
> diff --git a/drivers/phy/qualcomm/Kconfig b/drivers/phy/qualcomm/Kconfig
> index 27b5a2a3637d..a70631b04522 100644
> --- a/drivers/phy/qualcomm/Kconfig
> +++ b/drivers/phy/qualcomm/Kconfig
> @@ -79,6 +79,15 @@ config PHY_QCOM_SNPS_EUSB2
>   	  chipsets. The PHY is paired with a Synopsys DWC3 USB controller
>   	  on Qualcomm SOCs.
>   
> +config PHY_QCOM_EUSB2_REPEATER
> +	tristate "Qualcomm SNPS eUSB2 Repeater Driver"
> +	depends on OF && (ARCH_QCOM || COMPILE_TEST)
> +	select GENERIC_PHY
> +	help
> +	  Enable support for the USB high-speed SNPS eUSB2 repeater on Qualcomm
> +	  PMICs. The repeater is paired with a Synopsys eUSB2 Phy
> +	  on Qualcomm SOCs.
> +
>   config PHY_QCOM_USB_HS
>   	tristate "Qualcomm USB HS PHY module"
>   	depends on USB_ULPI_BUS
> diff --git a/drivers/phy/qualcomm/Makefile b/drivers/phy/qualcomm/Makefile
> index 3ee118f4dfc7..7dcba9537b69 100644
> --- a/drivers/phy/qualcomm/Makefile
> +++ b/drivers/phy/qualcomm/Makefile
> @@ -14,6 +14,7 @@ obj-$(CONFIG_PHY_QCOM_QMP)		+= \
>   
>   obj-$(CONFIG_PHY_QCOM_QUSB2)		+= phy-qcom-qusb2.o
>   obj-$(CONFIG_PHY_QCOM_SNPS_EUSB2)	+= phy-qcom-snps-eusb2.o
> +obj-$(CONFIG_PHY_QCOM_EUSB2_REPEATER)	+= phy-qcom-eusb2-repeater.o
>   obj-$(CONFIG_PHY_QCOM_USB_HS) 		+= phy-qcom-usb-hs.o
>   obj-$(CONFIG_PHY_QCOM_USB_HSIC) 	+= phy-qcom-usb-hsic.o
>   obj-$(CONFIG_PHY_QCOM_USB_HS_28NM)	+= phy-qcom-usb-hs-28nm.o
> diff --git a/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> new file mode 100644
> index 000000000000..f7f822f2973f
> --- /dev/null
> +++ b/drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> @@ -0,0 +1,278 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (c) 2023, Linaro Limited
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
> +#include <linux/regmap.h>
> +#include <linux/of.h>
> +#include <linux/of_device.h>
> +#include <linux/phy/phy.h>
> +
> +/* eUSB2 status registers */
> +#define EUSB2_RPTR_STATUS		0x08
> +#define	RPTR_OK				BIT(7)
> +
> +/* eUSB2 control registers */
> +#define EUSB2_EN_CTL1			0x46
> +#define EUSB2_RPTR_EN			BIT(7)
> +
> +#define PHY_HOST_MODE			BIT(0)
> +#define EUSB2_FORCE_EN_5		0xE8
> +#define F_CLK_19P2M_EN			BIT(6)
> +#define F_CLK_19P2M_EN_SHIFT		6

Drop the _SHIFT defines please, they don't add anything on top of 
previous defines (and don't seem to be used anyway).

> +
> +#define EUSB2_FORCE_VAL_5		0xED
> +#define V_CLK_19P2M_EN			BIT(6)
> +#define V_CLK_19P2M_EN_SHIFT		6
> +
> +#define EUSB2_TUNE_IUSB2		0x51
> +#define EUSB2_TUNE_SQUELCH_U		0x54
> +#define EUSB2_TUNE_USB2_PREEM		0x57
> +
> +#define QCOM_EUSB2_REPEATER_INIT_CFG(o, v)	\
> +	{					\
> +		.offset = o,			\
> +		.val = v,			\
> +	}
> +
> +enum repeater_mode {
> +	REPEATER_HOST_MODE,
> +	REPEATER_PERIPH_MODE,
> +};

I think this is unused now.

> +
> +struct eusb2_repeater_init_tbl {
> +	unsigned int offset;
> +	unsigned int val;
> +};
> +
> +struct eusb2_repeater_cfg {
> +	const struct eusb2_repeater_init_tbl *init_tbl;
> +	int init_tbl_num;
> +	/* regulators to be requested */
> +	const char * const *vreg_list;
> +	int num_vregs;
> +};
> +
> +struct eusb2_repeater {
> +	struct device *dev;
> +	struct regmap *regmap;
> +	struct phy *phy;
> +	struct regulator_bulk_data *vregs;
> +	const struct eusb2_repeater_cfg *cfg;
> +	u16 base;
> +	enum phy_mode mode;
> +};
> +
> +static const char * const pm8550b_vreg_l[] = {
> +	"vdd18", "vdd3",
> +};
> +
> +static const struct eusb2_repeater_init_tbl pm8550b_init_tbl[] = {
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_IUSB2, 0x8),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_SQUELCH_U, 0x3),
> +	QCOM_EUSB2_REPEATER_INIT_CFG(EUSB2_TUNE_USB2_PREEM, 0x5),
> +};
> +
> +static const struct eusb2_repeater_cfg pm8550b_eusb2_cfg = {
> +	.init_tbl	= pm8550b_init_tbl,
> +	.init_tbl_num	= ARRAY_SIZE(pm8550b_init_tbl),
> +	.vreg_list	= pm8550b_vreg_l,
> +	.num_vregs	= ARRAY_SIZE(pm8550b_vreg_l),
> +};
> +
> +static int eusb2_repeater_init_vregs(struct eusb2_repeater *rptr)
> +{
> +	int num = rptr->cfg->num_vregs;
> +	struct device *dev = rptr->dev;
> +	int i;
> +
> +	rptr->vregs = devm_kcalloc(dev, num, sizeof(*rptr->vregs), GFP_KERNEL);
> +	if (!rptr->vregs)
> +		return -ENOMEM;
> +
> +	for (i = 0; i < num; i++)
> +		rptr->vregs[i].supply = rptr->cfg->vreg_list[i];
> +
> +	return devm_regulator_bulk_get(dev, num, rptr->vregs);
> +}
> +
> +static int eusb2_repeater_init(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> +	int num = rptr->cfg->init_tbl_num;
> +	int ret = 0;
> +	u32 val;
> +	int i;
> +
> +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> +	if (ret)
> +		return ret;
> +
> +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> +
> +	for (i = 0; i < num; i++)
> +		regmap_update_bits(rptr->regmap,
> +					rptr->base + init_tbl[i].offset,
> +					init_tbl[i].val, init_tbl[i].val);

I'd move this to a separate function. Then you can use it in the 
set_mode() too.

> +
> +	ret = regmap_read_poll_timeout(rptr->regmap,
> +					rptr->base + EUSB2_RPTR_STATUS, val,
> +					val & RPTR_OK, 10, 5);
> +	if (ret)
> +		dev_err(rptr->dev, "initialization timed-out\n");
> +
> +	return ret;
> +}
> +
> +static int eusb2_repeater_set_mode(struct phy *phy,
> +					enum phy_mode mode, int submode)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	switch (mode) {
> +	case PHY_MODE_USB_HOST:
> +		/*
> +		 * CM.Lx is prohibited when repeater is already into Lx state as
> +		 * per eUSB 1.2 Spec. Below implement software workaround until
> +		 * PHY and controller is fixing seen observation.
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, F_CLK_19P2M_EN);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, V_CLK_19P2M_EN);
> +		break;
> +	case PHY_MODE_USB_DEVICE:
> +		/*
> +		 * In device mode clear host mode related workaround as there
> +		 * is no repeater reset available, and enable/disable of
> +		 * repeater doesn't clear previous value due to shared
> +		 * regulators (say host <-> device mode switch).
> +		 */
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_EN_5,
> +				F_CLK_19P2M_EN, 0);
> +		regmap_update_bits(rptr->regmap, rptr->base + EUSB2_FORCE_VAL_5,
> +				V_CLK_19P2M_EN, 0);
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	return 0;
> +}
> +
> +static int eusb2_repeater_exit(struct phy *phy)
> +{
> +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> +
> +	return regulator_bulk_disable(rptr->cfg->num_vregs, rptr->vregs);
> +}
> +
> +
> +static const struct phy_ops eusb2_repeater_ops = {
> +	.init		= eusb2_repeater_init,
> +	.exit		= eusb2_repeater_exit,
> +	.set_mode	= eusb2_repeater_set_mode,
> +	.owner		= THIS_MODULE,
> +};
> +
> +static int eusb2_repeater_probe(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *phy_provider;
> +	struct device_node *np;
> +	u32 res;
> +	int ret;
> +
> +	np = of_node_get(dev->of_node);

Do you really need to increase the refcount here? I thought that we can 
use dev->of_node straight away.

> +
> +	rptr = devm_kzalloc(dev, sizeof(*rptr), GFP_KERNEL);
> +	if (!rptr)
> +		goto err_node_put;
> +
> +	rptr->dev = dev;
> +	dev_set_drvdata(dev, rptr);
> +
> +	rptr->cfg = of_device_get_match_data(dev);
> +	if (!rptr->cfg)
> +		goto err_node_put;
> +
> +	rptr->regmap = dev_get_regmap(dev->parent, NULL);
> +	if (!rptr->regmap)
> +		goto err_node_put;
> +
> +	ret = of_property_read_u32(np, "reg", &res);
> +	if (ret < 0)
> +		goto err_node_put;
> +
> +	rptr->base = res;
> +
> +	ret = eusb2_repeater_init_vregs(rptr);
> +	if (ret < 0) {
> +		dev_err(dev, "unable to get supplies\n");
> +		goto err_node_put;
> +	}
> +
> +	rptr->phy = devm_phy_create(dev, np, &eusb2_repeater_ops);
> +	if (IS_ERR(rptr->phy)) {
> +		ret = PTR_ERR(rptr->phy);
> +		dev_err(dev, "failed to create PHY: %d\n", ret);
> +		goto err_node_put;
> +	}
> +
> +	phy_set_drvdata(rptr->phy, rptr);
> +
> +	of_node_put(np);
> +
> +	phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> +	if (IS_ERR(phy_provider))
> +		return PTR_ERR(phy_provider);
> +
> +	dev_info(dev, "Registered Qcom-eUSB2 repeater\n");
> +
> +	return 0;
> +
> +err_node_put:
> +	of_node_put(np);
> +	return ret;
> +}
> +
> +static int eusb2_repeater_remove(struct platform_device *pdev)
> +{
> +	struct eusb2_repeater *rptr = platform_get_drvdata(pdev);
> +
> +	if (!rptr)
> +		return 0;
> +
> +	eusb2_repeater_exit(rptr->phy);
> +	return 0;
> +}
> +
> +
> +static const struct of_device_id eusb2_repeater_of_match_table[] = {
> +	{
> +		.compatible = "qcom,pm8550b-eusb2-repeater",
> +		.data = &pm8550b_eusb2_cfg,
> +	},
> +	{ },
> +};
> +MODULE_DEVICE_TABLE(of, eusb2_repeater_of_match_table);
> +
> +static struct platform_driver eusb2_repeater_driver = {
> +	.probe		= eusb2_repeater_probe,
> +	.remove		= eusb2_repeater_remove,
> +	.driver = {
> +		.name	= "qcom-eusb2-repeater",
> +		.of_match_table = eusb2_repeater_of_match_table,
> +	},
> +};
> +
> +module_platform_driver(eusb2_repeater_driver);
> +
> +MODULE_DESCRIPTION("Qualcomm PMIC eUSB2 Repeater driver");
> +MODULE_LICENSE("GPL v2");

-- 
With best wishes
Dmitry


-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
  2023-02-03 13:49     ` Vinod Koul
@ 2023-02-07  7:11       ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07  7:11 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

On 23-02-03 19:19:22, Vinod Koul wrote:
> On 02-02-23, 15:38, Abel Vesa wrote:
> > From: Neil Armstrong <neil.armstrong@linaro.org>
> > 
> > For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
> > initialize and reset it. So add repeater support
> > 
> > Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> > ---
> >  drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > index 23ec162cc3bd..8d972d49732b 100644
> > --- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > +++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > @@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
> >  	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
> >  
> >  	enum phy_mode mode;
> > +
> > +	struct phy *repeater;
> >  };
> >  
> >  static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
> > @@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
> >  
> >  	phy->mode = mode;
> >  
> > -	return 0;
> > +	return phy_set_mode_ext(phy->repeater, mode, submode);
> >  }
> >  
> >  static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
> > @@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
> >  	if (ret)
> >  		return ret;
> >  
> > +	ret = phy_init(phy->repeater);
> > +	if (ret) {
> > +		dev_err(&p->dev, "repeater init failed. %d\n", ret);
> > +		goto disable_vreg;
> > +	}
> > +
> >  	ret = clk_prepare_enable(phy->ref_clk);
> >  	if (ret) {
> >  		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
> > @@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
> >  
> >  	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
> >  
> > +	phy_exit(phy->repeater);
> > +
> >  	return 0;
> >  }
> >  
> > @@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return dev_err_probe(dev, ret,
> >  				     "failed to get regulator supplies\n");
> > +
> > +	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
> > +	if (IS_ERR(phy->repeater))
> > +		return dev_err_probe(dev, PTR_ERR(phy->repeater),
> > +				     "failed to get repeater\n");
> 
> That implies repeater is assumed to be there for all designs, how about
> older devices, they may not have a repeater?

Well, no other (older) platform has eUSB2 support, IIRC.

And the eUSB2 can't be used as USB 2.0 without the repeater.

> 
> > +
> >  	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
> >  	if (IS_ERR(generic_phy)) {
> >  		dev_err(dev, "failed to create phy %d\n", ret);
> > -- 
> > 2.34.1
> 
> -- 
> ~Vinod

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater
@ 2023-02-07  7:11       ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07  7:11 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy,
	Neil Armstrong

On 23-02-03 19:19:22, Vinod Koul wrote:
> On 02-02-23, 15:38, Abel Vesa wrote:
> > From: Neil Armstrong <neil.armstrong@linaro.org>
> > 
> > For USB 2.0 compliance, eUSB2 needs a repeater. The PHY needs to
> > initialize and reset it. So add repeater support
> > 
> > Co-developed-by: Abel Vesa <abel.vesa@linaro.org>
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > Signed-off-by: Neil Armstrong <neil.armstrong@linaro.org>
> > ---
> >  drivers/phy/qualcomm/phy-qcom-snps-eusb2.c | 18 +++++++++++++++++-
> >  1 file changed, 17 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > index 23ec162cc3bd..8d972d49732b 100644
> > --- a/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > +++ b/drivers/phy/qualcomm/phy-qcom-snps-eusb2.c
> > @@ -128,6 +128,8 @@ struct qcom_snps_eusb2_hsphy {
> >  	struct regulator_bulk_data vregs[EUSB2_NUM_VREGS];
> >  
> >  	enum phy_mode mode;
> > +
> > +	struct phy *repeater;
> >  };
> >  
> >  static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int submode)
> > @@ -136,7 +138,7 @@ static int qcom_snps_eusb2_hsphy_set_mode(struct phy *p, enum phy_mode mode, int
> >  
> >  	phy->mode = mode;
> >  
> > -	return 0;
> > +	return phy_set_mode_ext(phy->repeater, mode, submode);
> >  }
> >  
> >  static void qcom_snps_eusb2_hsphy_write_mask(void __iomem *base, u32 offset,
> > @@ -235,6 +237,12 @@ static int qcom_snps_eusb2_hsphy_init(struct phy *p)
> >  	if (ret)
> >  		return ret;
> >  
> > +	ret = phy_init(phy->repeater);
> > +	if (ret) {
> > +		dev_err(&p->dev, "repeater init failed. %d\n", ret);
> > +		goto disable_vreg;
> > +	}
> > +
> >  	ret = clk_prepare_enable(phy->ref_clk);
> >  	if (ret) {
> >  		dev_err(&p->dev, "failed to enable ref clock, %d\n", ret);
> > @@ -342,6 +350,8 @@ static int qcom_snps_eusb2_hsphy_exit(struct phy *p)
> >  
> >  	regulator_bulk_disable(ARRAY_SIZE(phy->vregs), phy->vregs);
> >  
> > +	phy_exit(phy->repeater);
> > +
> >  	return 0;
> >  }
> >  
> > @@ -386,6 +396,12 @@ static int qcom_snps_eusb2_hsphy_probe(struct platform_device *pdev)
> >  	if (ret)
> >  		return dev_err_probe(dev, ret,
> >  				     "failed to get regulator supplies\n");
> > +
> > +	phy->repeater = devm_phy_get(dev, "eusb2-repeater");
> > +	if (IS_ERR(phy->repeater))
> > +		return dev_err_probe(dev, PTR_ERR(phy->repeater),
> > +				     "failed to get repeater\n");
> 
> That implies repeater is assumed to be there for all designs, how about
> older devices, they may not have a repeater?

Well, no other (older) platform has eUSB2 support, IIRC.

And the eUSB2 can't be used as USB 2.0 without the repeater.

> 
> > +
> >  	generic_phy = devm_phy_create(dev, NULL, &qcom_snps_eusb2_hsphy_ops);
> >  	if (IS_ERR(generic_phy)) {
> >  		dev_err(dev, "failed to create phy %d\n", ret);
> > -- 
> > 2.34.1
> 
> -- 
> ~Vinod

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-03 16:51     ` Dmitry Baryshkov
@ 2023-02-07 12:25       ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07 12:25 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> On 02/02/2023 15:38, Abel Vesa wrote:
> > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > So add a new phy driver for it.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > ---
> >   drivers/phy/qualcomm/Kconfig                  |   9 +
> >   drivers/phy/qualcomm/Makefile                 |   1 +
> >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> >   3 files changed, 288 insertions(+)
> >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > 

[ ... ]

> > +
> > +static int eusb2_repeater_init(struct phy *phy)
> > +{
> > +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > +	int num = rptr->cfg->init_tbl_num;
> > +	int ret = 0;
> > +	u32 val;
> > +	int i;
> > +
> > +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > +	if (ret)
> > +		return ret;
> > +
> > +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > +
> > +	for (i = 0; i < num; i++)
> > +		regmap_update_bits(rptr->regmap,
> > +					rptr->base + init_tbl[i].offset,
> > +					init_tbl[i].val, init_tbl[i].val);
> 
> I'd move this to a separate function. Then you can use it in the set_mode()
> too.
> 

I don't think this is necessary in set_mode.

> > +
> > +	ret = regmap_read_poll_timeout(rptr->regmap,
> > +					rptr->base + EUSB2_RPTR_STATUS, val,
> > +					val & RPTR_OK, 10, 5);
> > +	if (ret)
> > +		dev_err(rptr->dev, "initialization timed-out\n");
> > +
> > +	return ret;
> > +}
> > +

[ ... ]

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-07 12:25       ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07 12:25 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> On 02/02/2023 15:38, Abel Vesa wrote:
> > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > So add a new phy driver for it.
> > 
> > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > ---
> >   drivers/phy/qualcomm/Kconfig                  |   9 +
> >   drivers/phy/qualcomm/Makefile                 |   1 +
> >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> >   3 files changed, 288 insertions(+)
> >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > 

[ ... ]

> > +
> > +static int eusb2_repeater_init(struct phy *phy)
> > +{
> > +	struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > +	const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > +	int num = rptr->cfg->init_tbl_num;
> > +	int ret = 0;
> > +	u32 val;
> > +	int i;
> > +
> > +	ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > +	if (ret)
> > +		return ret;
> > +
> > +	regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > +				EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > +
> > +	for (i = 0; i < num; i++)
> > +		regmap_update_bits(rptr->regmap,
> > +					rptr->base + init_tbl[i].offset,
> > +					init_tbl[i].val, init_tbl[i].val);
> 
> I'd move this to a separate function. Then you can use it in the set_mode()
> too.
> 

I don't think this is necessary in set_mode.

> > +
> > +	ret = regmap_read_poll_timeout(rptr->regmap,
> > +					rptr->base + EUSB2_RPTR_STATUS, val,
> > +					val & RPTR_OK, 10, 5);
> > +	if (ret)
> > +		dev_err(rptr->dev, "initialization timed-out\n");
> > +
> > +	return ret;
> > +}
> > +

[ ... ]

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-07 12:25       ` Abel Vesa
@ 2023-02-07 13:03         ` Dmitry Baryshkov
  -1 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-07 13:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On Tue, 7 Feb 2023 at 14:25, Abel Vesa <abel.vesa@linaro.org> wrote:
>
> On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> > On 02/02/2023 15:38, Abel Vesa wrote:
> > > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > > So add a new phy driver for it.
> > >
> > > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > > ---
> > >   drivers/phy/qualcomm/Kconfig                  |   9 +
> > >   drivers/phy/qualcomm/Makefile                 |   1 +
> > >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> > >   3 files changed, 288 insertions(+)
> > >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > >
>
> [ ... ]
>
> > > +
> > > +static int eusb2_repeater_init(struct phy *phy)
> > > +{
> > > +   struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > > +   const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > > +   int num = rptr->cfg->init_tbl_num;
> > > +   int ret = 0;
> > > +   u32 val;
> > > +   int i;
> > > +
> > > +   ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > > +   if (ret)
> > > +           return ret;
> > > +
> > > +   regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > > +                           EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > > +
> > > +   for (i = 0; i < num; i++)
> > > +           regmap_update_bits(rptr->regmap,
> > > +                                   rptr->base + init_tbl[i].offset,
> > > +                                   init_tbl[i].val, init_tbl[i].val);
> >
> > I'd move this to a separate function. Then you can use it in the set_mode()
> > too.
> >
>
> I don't think this is necessary in set_mode.

It's not necessary. However as set_mode() is also a sequence of simple
register updates, it might be easy to have everything as an
offset-mask-value table.

>
> > > +
> > > +   ret = regmap_read_poll_timeout(rptr->regmap,
> > > +                                   rptr->base + EUSB2_RPTR_STATUS, val,
> > > +                                   val & RPTR_OK, 10, 5);
> > > +   if (ret)
> > > +           dev_err(rptr->dev, "initialization timed-out\n");
> > > +
> > > +   return ret;
> > > +}
> > > +
>
> [ ... ]



-- 
With best wishes
Dmitry

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-07 13:03         ` Dmitry Baryshkov
  0 siblings, 0 replies; 38+ messages in thread
From: Dmitry Baryshkov @ 2023-02-07 13:03 UTC (permalink / raw)
  To: Abel Vesa
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On Tue, 7 Feb 2023 at 14:25, Abel Vesa <abel.vesa@linaro.org> wrote:
>
> On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> > On 02/02/2023 15:38, Abel Vesa wrote:
> > > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > > So add a new phy driver for it.
> > >
> > > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > > ---
> > >   drivers/phy/qualcomm/Kconfig                  |   9 +
> > >   drivers/phy/qualcomm/Makefile                 |   1 +
> > >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> > >   3 files changed, 288 insertions(+)
> > >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > >
>
> [ ... ]
>
> > > +
> > > +static int eusb2_repeater_init(struct phy *phy)
> > > +{
> > > +   struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > > +   const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > > +   int num = rptr->cfg->init_tbl_num;
> > > +   int ret = 0;
> > > +   u32 val;
> > > +   int i;
> > > +
> > > +   ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > > +   if (ret)
> > > +           return ret;
> > > +
> > > +   regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > > +                           EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > > +
> > > +   for (i = 0; i < num; i++)
> > > +           regmap_update_bits(rptr->regmap,
> > > +                                   rptr->base + init_tbl[i].offset,
> > > +                                   init_tbl[i].val, init_tbl[i].val);
> >
> > I'd move this to a separate function. Then you can use it in the set_mode()
> > too.
> >
>
> I don't think this is necessary in set_mode.

It's not necessary. However as set_mode() is also a sequence of simple
register updates, it might be easy to have everything as an
offset-mask-value table.

>
> > > +
> > > +   ret = regmap_read_poll_timeout(rptr->regmap,
> > > +                                   rptr->base + EUSB2_RPTR_STATUS, val,
> > > +                                   val & RPTR_OK, 10, 5);
> > > +   if (ret)
> > > +           dev_err(rptr->dev, "initialization timed-out\n");
> > > +
> > > +   return ret;
> > > +}
> > > +
>
> [ ... ]



-- 
With best wishes
Dmitry

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
  2023-02-07 13:03         ` Dmitry Baryshkov
@ 2023-02-07 13:10           ` Abel Vesa
  -1 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07 13:10 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 23-02-07 15:03:39, Dmitry Baryshkov wrote:
> On Tue, 7 Feb 2023 at 14:25, Abel Vesa <abel.vesa@linaro.org> wrote:
> >
> > On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> > > On 02/02/2023 15:38, Abel Vesa wrote:
> > > > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > > > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > > > So add a new phy driver for it.
> > > >
> > > > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > > > ---
> > > >   drivers/phy/qualcomm/Kconfig                  |   9 +
> > > >   drivers/phy/qualcomm/Makefile                 |   1 +
> > > >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> > > >   3 files changed, 288 insertions(+)
> > > >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > > >
> >
> > [ ... ]
> >
> > > > +
> > > > +static int eusb2_repeater_init(struct phy *phy)
> > > > +{
> > > > +   struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > > > +   const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > > > +   int num = rptr->cfg->init_tbl_num;
> > > > +   int ret = 0;
> > > > +   u32 val;
> > > > +   int i;
> > > > +
> > > > +   ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > > > +   if (ret)
> > > > +           return ret;
> > > > +
> > > > +   regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > > > +                           EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > > > +
> > > > +   for (i = 0; i < num; i++)
> > > > +           regmap_update_bits(rptr->regmap,
> > > > +                                   rptr->base + init_tbl[i].offset,
> > > > +                                   init_tbl[i].val, init_tbl[i].val);
> > >
> > > I'd move this to a separate function. Then you can use it in the set_mode()
> > > too.
> > >
> >
> > I don't think this is necessary in set_mode.
> 
> It's not necessary. However as set_mode() is also a sequence of simple
> register updates, it might be easy to have everything as an
> offset-mask-value table.

Yeah, but then you would reinit the repeater on set_mode, which should
not be done.

> 
> >
> > > > +
> > > > +   ret = regmap_read_poll_timeout(rptr->regmap,
> > > > +                                   rptr->base + EUSB2_RPTR_STATUS, val,
> > > > +                                   val & RPTR_OK, 10, 5);
> > > > +   if (ret)
> > > > +           dev_err(rptr->dev, "initialization timed-out\n");
> > > > +
> > > > +   return ret;
> > > > +}
> > > > +
> >
> > [ ... ]
> 
> 
> 
> -- 
> With best wishes
> Dmitry

^ permalink raw reply	[flat|nested] 38+ messages in thread

* Re: [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver
@ 2023-02-07 13:10           ` Abel Vesa
  0 siblings, 0 replies; 38+ messages in thread
From: Abel Vesa @ 2023-02-07 13:10 UTC (permalink / raw)
  To: Dmitry Baryshkov
  Cc: Andy Gross, Bjorn Andersson, Konrad Dybcio, Lee Jones,
	Rob Herring, Krzysztof Kozlowski, vkoul, Kishon Vijay Abraham I,
	linux-arm-msm, devicetree, Linux Kernel Mailing List, linux-phy

On 23-02-07 15:03:39, Dmitry Baryshkov wrote:
> On Tue, 7 Feb 2023 at 14:25, Abel Vesa <abel.vesa@linaro.org> wrote:
> >
> > On 23-02-03 18:51:13, Dmitry Baryshkov wrote:
> > > On 02/02/2023 15:38, Abel Vesa wrote:
> > > > PM8550B contains a eUSB2 repeater used for making the eUSB2 from
> > > > SM8550 USB 2.0 compliant. This can be modelled SW-wise as a Phy.
> > > > So add a new phy driver for it.
> > > >
> > > > Signed-off-by: Abel Vesa <abel.vesa@linaro.org>
> > > > ---
> > > >   drivers/phy/qualcomm/Kconfig                  |   9 +
> > > >   drivers/phy/qualcomm/Makefile                 |   1 +
> > > >   .../phy/qualcomm/phy-qcom-eusb2-repeater.c    | 278 ++++++++++++++++++
> > > >   3 files changed, 288 insertions(+)
> > > >   create mode 100644 drivers/phy/qualcomm/phy-qcom-eusb2-repeater.c
> > > >
> >
> > [ ... ]
> >
> > > > +
> > > > +static int eusb2_repeater_init(struct phy *phy)
> > > > +{
> > > > +   struct eusb2_repeater *rptr = phy_get_drvdata(phy);
> > > > +   const struct eusb2_repeater_init_tbl *init_tbl = rptr->cfg->init_tbl;
> > > > +   int num = rptr->cfg->init_tbl_num;
> > > > +   int ret = 0;
> > > > +   u32 val;
> > > > +   int i;
> > > > +
> > > > +   ret = regulator_bulk_enable(rptr->cfg->num_vregs, rptr->vregs);
> > > > +   if (ret)
> > > > +           return ret;
> > > > +
> > > > +   regmap_update_bits(rptr->regmap, rptr->base + EUSB2_EN_CTL1,
> > > > +                           EUSB2_RPTR_EN, EUSB2_RPTR_EN);
> > > > +
> > > > +   for (i = 0; i < num; i++)
> > > > +           regmap_update_bits(rptr->regmap,
> > > > +                                   rptr->base + init_tbl[i].offset,
> > > > +                                   init_tbl[i].val, init_tbl[i].val);
> > >
> > > I'd move this to a separate function. Then you can use it in the set_mode()
> > > too.
> > >
> >
> > I don't think this is necessary in set_mode.
> 
> It's not necessary. However as set_mode() is also a sequence of simple
> register updates, it might be easy to have everything as an
> offset-mask-value table.

Yeah, but then you would reinit the repeater on set_mode, which should
not be done.

> 
> >
> > > > +
> > > > +   ret = regmap_read_poll_timeout(rptr->regmap,
> > > > +                                   rptr->base + EUSB2_RPTR_STATUS, val,
> > > > +                                   val & RPTR_OK, 10, 5);
> > > > +   if (ret)
> > > > +           dev_err(rptr->dev, "initialization timed-out\n");
> > > > +
> > > > +   return ret;
> > > > +}
> > > > +
> >
> > [ ... ]
> 
> 
> 
> -- 
> With best wishes
> Dmitry

-- 
linux-phy mailing list
linux-phy@lists.infradead.org
https://lists.infradead.org/mailman/listinfo/linux-phy

^ permalink raw reply	[flat|nested] 38+ messages in thread

end of thread, other threads:[~2023-02-07 13:12 UTC | newest]

Thread overview: 38+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 13:38 [RFC v3 0/7] sm8550: Add support for eUSB2 repeater Abel Vesa
2023-02-02 13:38 ` Abel Vesa
2023-02-02 13:38 ` [RFC v3 1/7] dt-bindings: mfd: qcom,spmi-pmic: Add pattern property for phy Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-02 15:03   ` Rob Herring
2023-02-02 15:03     ` Rob Herring
2023-02-02 17:00   ` Krzysztof Kozlowski
2023-02-02 17:00     ` Krzysztof Kozlowski
2023-02-02 13:38 ` [RFC v3 2/7] dt-bindings: phy: Add qcom,snps-eusb2-repeater schema file Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-02 15:03   ` Rob Herring
2023-02-02 15:03     ` Rob Herring
2023-02-02 13:38 ` [RFC v3 3/7] dt-bindings: phy: qcom,snps-eusb2-repeater: Add phy related properties Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-03 16:37   ` Dmitry Baryshkov
2023-02-03 16:37     ` Dmitry Baryshkov
2023-02-02 13:38 ` [RFC v3 4/7] phy: qcom: Add QCOM SNPS eUSB2 repeater driver Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-03 13:48   ` Vinod Koul
2023-02-03 13:48     ` Vinod Koul
2023-02-03 16:51   ` Dmitry Baryshkov
2023-02-03 16:51     ` Dmitry Baryshkov
2023-02-07 12:25     ` Abel Vesa
2023-02-07 12:25       ` Abel Vesa
2023-02-07 13:03       ` Dmitry Baryshkov
2023-02-07 13:03         ` Dmitry Baryshkov
2023-02-07 13:10         ` Abel Vesa
2023-02-07 13:10           ` Abel Vesa
2023-02-02 13:38 ` [RFC v3 5/7] phy: qcom: phy-qcom-snps-eusb2: Add support for eUSB2 repeater Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-03 13:49   ` Vinod Koul
2023-02-03 13:49     ` Vinod Koul
2023-02-07  7:11     ` Abel Vesa
2023-02-07  7:11       ` Abel Vesa
2023-02-02 13:38 ` [RFC v3 6/7] arm64: dts: qcom: pm8550b: Add eUSB2 repeater node Abel Vesa
2023-02-02 13:38   ` Abel Vesa
2023-02-02 13:38 ` [RFC v3 7/7] arm64: dts: qcom: sm8550-mtp: " Abel Vesa
2023-02-02 13:38   ` Abel Vesa

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.