Skip to contentSkip to conversation

phy: sprd: Add Spreadtrum USB20 HSPHY Driver

PATCH NAK Pu Li 3 participants 5 messages Nov 1, 2023

Subsystems (3)
lore
Share & tools
lore

Pu Li

author
#0 lore raw

cover phy: sprd: Add Spreadtrum USB20 HSPHY Driver

This patchset is used to add spreadtrum usb20 high speed phy driver. Patch 1 is dt-binding Documentation supports, and patch 2 is the specific implementation.

Pu Li (2):
dt-bindings: phy: Add Spreadtrum usb20 hsphy yaml
phy: sprd: Add Spreadtrum usb20 hsphy driver

 .../bindings/phy/phy-sprd-usb20-hs.yaml       |   70 +
 drivers/phy/Kconfig                           |    1 +
 drivers/phy/Makefile                          |    1 +
 drivers/phy/sprd/Kconfig                      |   14 +
 drivers/phy/sprd/Makefile                     |    6 +
 drivers/phy/sprd/phy-sprd-usb20-hs.c          | 1324 +++++++++++++++++
 drivers/phy/sprd/phy-sprd-usb20-hs.h          |  525 +++++++
 7 files changed, 1941 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml
 create mode 100644 drivers/phy/sprd/Kconfig
 create mode 100644 drivers/phy/sprd/Makefile
 create mode 100644 drivers/phy/sprd/phy-sprd-usb20-hs.c
 create mode 100644 drivers/phy/sprd/phy-sprd-usb20-hs.h
Signature · 1 line
2.17.1
author
#1 lore raw

PATCH 1/2 dt-bindings: phy: Add Spreadtrum usb20 hsphy yaml

Add device tree binding Documentation details for Spreadtrum usb20 hsphy driver.

---
 .../bindings/phy/phy-sprd-usb20-hs.yaml       | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +70 -0
new file mode 100644
index 000000000000..102b49d3482e
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2020-2023 Unisoc Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/phy-sprd-usb20-hs.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Spreadtrum USB20 High Speed PHY
+
+maintainers:
+  - Pu Li <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - enum:
+              - sprd,pike2-phy
+              - sprd,sharkle-phy
+              - sprd,sharkl3-phy
+              - sprd,sharkl5-phy
+              - sprd,sharkl5pro-phy
+              - sprd,qogirl6-phy
+              - sprd,qogirn6lite-phy
+              - sprd,uis8520-phy
+
+  reg:
+    maxItems: 1
+
+  reg-names:
+    const: phy_glb_regs
+
+  sprd,syscon-enable:
+    description:
+      Phandle to aon apb syscon register region.
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+  sprd,syscon-ana:
+    description:
+      Phandle to analog syscon register region.
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+  sprd,vdd-voltage:
+    description:
+      It represents the value of one analog power supply of phy,
+      the unit is uV.
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  "#phy-cells":
+    const: 0
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    hsphy@64570000 {
+      compatible = "sprd,qogirl6-phy";
+      reg = <0x64570000 0x3030>;
+      reg-names = "phy_glb_regs";
+      sprd,syscon-enable = <&aon_apb_regs>;
+      sprd,syscon-ana = <&anlg_phy_g2_regs>;
+      sprd,vdd-voltage = <3300000>;
+      #phy-cells = <0>;
+    };
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] dt-bindings: phy: Add Spreadtrum usb20 hsphy yaml

Quoted 8 lines · Pu Li

Add device tree binding Documentation details for Spreadtrum usb20 hsphy driver.

---
 .../bindings/phy/phy-sprd-usb20-hs.yaml       | 70 +++++++++++++++++++
 1 file changed, 70 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml

Filename matching compatible syntax.

Quoted 12 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +5 -0
new file mode 100644
index 000000000000..102b49d3482e
@@ -0,0 +1,70 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+# Copyright 2020-2023 Unisoc Inc.
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/phy-sprd-usb20-hs.yaml#

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 15

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +10 -0
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Spreadtrum USB20 High Speed PHY
+
+maintainers:
+  - Pu Li <[email protected]>
+
+properties:
+  compatible:
+    oneOf:

No need for oneOf.

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 16

Quoted 1 line
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +1 -0
+      - items:

No need of ritems,

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 25

Quoted 9 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +9 -0
+          - enum:
+              - sprd,pike2-phy
+              - sprd,sharkle-phy
+              - sprd,sharkl3-phy
+              - sprd,sharkl5-phy
+              - sprd,sharkl5pro-phy
+              - sprd,qogirl6-phy
+              - sprd,qogirn6lite-phy
+              - sprd,uis8520-phy

What are these? pike2 is the SoC and the binding covers all phys? All?

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 31

Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +6 -0
+
+  reg:
+    maxItems: 1
+
+  reg-names:
+    const: phy_glb_regs

Drop, not needed for one entry.

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 35

Quoted 4 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +4 -0
+
+  sprd,syscon-enable:
+    description:
+      Phandle to aon apb syscon register region.

You called it syscon-enable but write aon-apb-syscon. Decide which one. Also, you need to describe the purpose.

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 40

Quoted 5 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +5 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+  sprd,syscon-ana:
+    description:
+      Phandle to analog syscon register region.

Two syscons? Nope, do not use syscons instead of regular abstractions.

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 46

Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +6 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+
+  sprd,vdd-voltage:
+    description:
+      It represents the value of one analog power supply of phy,
+      the unit is uV.

Then you must use -microvolt unit suffix.

Quoted 6 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +6 -0
+    $ref: /schemas/types.yaml#/definitions/uint32
+
+  "#phy-cells":
+    const: 0
+
+required:

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 62

Quoted 10 lines
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +10 -0
+  - compatible
+  - reg
+  - reg-names
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    hsphy@64570000 {

phy@

Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml line 63

Quoted 1 line
Documentation/devicetree/bindings/phy/phy-sprd-usb20-hs.yaml new file +1 -0
+      compatible = "sprd,qogirl6-phy";

Best regards,
Krzysztof

author
#3 lore raw

PATCH 2/2 phy: sprd: Add Spreadtrum usb20 hsphy driver

In reply to Pu Li

Add Spreadtrum platform USB20 HSPHY driver support. This driver takes care of all the PHY functionality, normally paired with DesignWare USB20 (DRD) Controller or Spreadtrum musb phy (DRD )controller.

---
 drivers/phy/Kconfig                  |    1 +
 drivers/phy/Makefile                 |    1 +
 drivers/phy/sprd/Kconfig             |   14 +
 drivers/phy/sprd/Makefile            |    6 +
 drivers/phy/sprd/phy-sprd-usb20-hs.c | 1324 ++++++++++++++++++++++++++
 drivers/phy/sprd/phy-sprd-usb20-hs.h |  525 ++++++++++
 6 files changed, 1871 insertions(+)
 create mode 100644 drivers/phy/sprd/Kconfig
 create mode 100644 drivers/phy/sprd/Makefile
 create mode 100644 drivers/phy/sprd/phy-sprd-usb20-hs.c
 create mode 100644 drivers/phy/sprd/phy-sprd-usb20-hs.h
drivers/phy/Kconfig +1 -0
index d1670bbe6d6b..309eb623f8b3 100644
@@ -92,6 +92,7 @@ source "drivers/phy/renesas/Kconfig"
 source "drivers/phy/rockchip/Kconfig"
 source "drivers/phy/samsung/Kconfig"
 source "drivers/phy/socionext/Kconfig"
+source "drivers/phy/sprd/Kconfig"
 source "drivers/phy/st/Kconfig"
 source "drivers/phy/starfive/Kconfig"
 source "drivers/phy/sunplus/Kconfig"
drivers/phy/Makefile +1 -0
index 868a220ed0f6..d83cb5917d08 100644
@@ -31,6 +31,7 @@ obj-y					+= allwinner/	\
 					   rockchip/	\
 					   samsung/	\
 					   socionext/	\
+					   sprd/	\
 					   st/		\
 					   starfive/	\
 					   sunplus/	\
drivers/phy/sprd/Kconfig new file +14 -0
new file mode 100644
index 000000000000..c43884012ef8
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Phy drivers for Spreadtrum platforms
+#
+
+config SPRD_USB20_HSPHY
+	tristate "Spreadtrum USB20 HSPHY Driver"
+	select USB_PHY
+	depends on ARCH_SPRD || COMPILE_TEST
+	help
+	  Enable this to support the SPRD USB20 High Speed PHY that is part of SOC.
+	  This driver takes care of all the PHY functionality,
+	  normally paired with DesignWare USB20 (DRD) Controller or
+	  Spreadtrum musb phy (DRD )controller.
drivers/phy/sprd/Makefile new file +6 -0
new file mode 100644
index 000000000000..b102f3515d47
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# Makefile for physical layer drivers
+#
+
+obj-$(CONFIG_SPRD_USB20_HSPHY)     	+= phy-sprd-usb20-hs.o
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +1324 -0

1,324 lines not on this page · raw message

drivers/phy/sprd/phy-sprd-usb20-hs.h new file +525 -0

525 lines not on this page · raw message

Signature · 1 line
2.17.1
#4 lore raw

Re: [PATCH 2/2] phy: sprd: Add Spreadtrum usb20 hsphy driver

Quoted 17 lines · Pu Li

Add Spreadtrum platform USB20 HSPHY driver support. This driver takes care of all the PHY functionality, normally paired with DesignWare USB20 (DRD) Controller or Spreadtrum musb phy (DRD )controller.

---

drivers/phy/sprd/phy-sprd-usb20-hs.c new file +9 -0
+
+#include <linux/delay.h>
+#include <linux/device.h>
+#include <linux/io.h>
+#include <linux/iio/consumer.h>
+#include <linux/mfd/syscon.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/of_platform.h>

drivers/phy/sprd/phy-sprd-usb20-hs.c line 23

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>
+#include <linux/slab.h>
+#include <linux/timer.h>
+#include <linux/usb/otg.h>
+#include <uapi/linux/usb/charger.h>
+
+#include "phy-sprd-usb20-hs.h"
+
+static const struct sprd_hsphy_cfg *phy_cfg;

File-scope variables do not look good.

Quoted 1 line

+

...

Quoted 6 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +6 -0
+
+static int sprd_hsphy_cali_mode(void)
+{
+	struct device_node *cmdline_node;
+	const char *cmdline, *mode;
+	int ret;

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1108

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+
+	cmdline_node = of_find_node_by_path("/chosen");
+	ret = of_property_read_string(cmdline_node, "bootargs", &cmdline);
+
+	if (ret) {
+		pr_err("Can't not parse bootargs\n");
+		return 0;
+	}
+
+	mode = strstr(cmdline, "androidboot.mode=cali");

NAK, drop this nonsense.

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1112

Quoted 4 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +4 -0
+	if (mode)
+		return 1;
+
+	mode = strstr(cmdline, "sprdboot.mode=cali");

NAK, drop this nonsense.

Quoted 36 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +36 -0
+	if (mode)
+		return 1;
+
+	return 0;
+}
+
+static int sprd_hsphy_probe(struct platform_device *pdev)
+{
+	struct sprd_hsphy *phy;
+	struct resource *res;
+	struct device *dev = &pdev->dev;
+	int ret = 0, calimode = 0;
+	struct usb_otg *otg;
+
+	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
+	if (!phy)
+		return -ENOMEM;
+
+	otg = devm_kzalloc(dev, sizeof(*otg), GFP_KERNEL);
+	if (!otg)
+		return -ENOMEM;
+
+	/* phy cfg data */
+	phy_cfg = of_device_get_match_data(dev);
+	if (!phy_cfg) {
+		dev_err(dev, "no matching driver data found\n");
+		return -EINVAL;
+	}
+
+	/* set vdd */
+	ret = of_property_read_u32(dev->of_node, "sprd,vdd-voltage",
+				   &phy->vdd_vol);
+	if (ret < 0) {
+		dev_err(dev, "unable to read hsphy vdd voltage\n");
+		return ret;
+	}

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1158

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+
+	calimode = sprd_hsphy_cali_mode();
+	if (calimode) {
+		phy->vdd_vol = phy_cfg->parameters[FULLSPEED_USB33_TUNE];
+		dev_info(dev, "calimode vdd_vol:%d\n", phy->vdd_vol);
+	}
+
+	phy->vdd = devm_regulator_get(dev, "vdd");
+	if (IS_ERR(phy->vdd)) {
+		dev_err(dev, "unable to get hsphy vdd supply\n");

You do not have regulators. You clearly did not test the code, DTS or the bindings. Maybe nothing here was tested.

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1159

Quoted 1 line
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +1 -0
+		return PTR_ERR(phy->vdd);

Syntax is anyway return dev_err_probe().

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1171

Quoted 12 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +12 -0
+	}
+
+	ret = regulator_set_voltage(phy->vdd, phy->vdd_vol, phy->vdd_vol);
+	if (ret < 0) {
+		dev_err(dev, "fail to set hsphy vdd voltage at %dmV\n",
+			phy->vdd_vol);
+		return ret;
+	}
+
+	/* phy tune */
+	if (phy_cfg->phy_version == VERSION1) {
+		ret = of_property_read_u32(dev->of_node, "sprd,tune-value",

Nope, it is not allowed in your bindings.

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1182

Quoted 11 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +11 -0
+					&phy->phy_tune);
+		if (ret < 0) {
+			dev_err(dev, "unable to read hsphy usb phy tune\n");
+			return ret;
+		}
+	}
+
+	/* phy base */
+	if (phy_cfg->phy_version == VERSION1 ||
+		phy_cfg->phy_version == VERSION2) {
+		res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy_glb_regs");

This was not expressed in the bindings.

Quoted 7 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +7 -0
+		if (!res) {
+			dev_err(dev, "missing USB PHY registers resource\n");
+			return -ENODEV;
+		}
+
+		phy->base = devm_ioremap(dev, res->start, resource_size(res));
+		if (IS_ERR(phy->base)) {

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1199

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+			dev_err(dev, "unable to get phy base!\n");
+			return PTR_ERR(phy->base);
+		}
+	}
+
+	/* analog & aoapb & apahb regmap */
+	phy->aon_apb = syscon_regmap_lookup_by_phandle(dev->of_node,
+				 "sprd,syscon-enable");
+	if (IS_ERR(phy->aon_apb)) {
+		dev_err(dev, "USB aon apb syscon failed!\n");

return dev_err_probe, if it stays

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1205

Quoted 8 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +6 -0
+		return PTR_ERR(phy->aon_apb);
+	}
+
+	if (phy_cfg->phy_version == VERSION2) {
 
 
+		phy->ap_ahb = syscon_regmap_lookup_by_phandle(dev->of_node,
+				 "sprd,syscon-apahb");

NAK, there is no such property!

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1212

Quoted 8 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +7 -0
+		if (IS_ERR(phy->ap_ahb)) {
+			dev_err(dev, "USB apahb syscon failed!\n");
 
+			return PTR_ERR(phy->ap_ahb);
+		}
+	}
+
+	if (phy_cfg->phy_version != VERSION1) {

This was not expressed in your bindings

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1217

Quoted 7 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +5 -0
+		phy->analog = syscon_regmap_lookup_by_phandle(dev->of_node,
+				 "sprd,syscon-ana");
 
 
+		if (IS_ERR(phy->analog)) {
+			dev_err(dev, "USB analog syscon failed!\n");
+			return PTR_ERR(phy->analog);

return dev_err_probe, if it stays, but I insist to remove it.

Quoted 42 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +42 -0
+		}
+	}
+
+	/* prepare eye pattern */
+	ret = sprd_eye_pattern_prepared(phy, dev);
+	if (ret < 0)
+		dev_warn(dev, "sprd_eye_pattern_prepared failed, ret = %d\n", ret);
+
+	/* enable usb module */
+	if (phy_cfg->phy_version == VERSION2 ||
+		phy_cfg->phy_version == VERSION3) {
+		phy_cfg->cfg_ops->usb_enable_ctrl(phy, CTRL2);
+	}
+
+	/* usb phy power down */
+	if (phy_cfg->phy_version != VERSION4)
+		phy_cfg->cfg_ops->usb_phy_power_ctrl(phy, CTRL2);
+
+	phy->dev = dev;
+	phy->phy.dev = dev;
+	phy->phy.label = "sprd-hsphy";
+	phy->phy.otg = otg;
+	phy->phy.init = sprd_hsphy_init;
+	phy->phy.shutdown = sprd_hsphy_shutdown;
+	phy->phy.set_vbus = sprd_hostphy_set;
+	phy->phy.type = USB_PHY_TYPE_USB2;
+	phy->phy.vbus_nb.notifier_call = sprd_hsphy_vbus_notify;
+	otg->usb_phy = &phy->phy;
+
+	device_init_wakeup(phy->dev, true);
+	phy->wake_lock = wakeup_source_register(phy->dev, "sprd-hsphy");
+	if (!phy->wake_lock) {
+		dev_err(dev, "fail to register wakeup lock.\n");
+		return -ENOMEM;
+	}
+	INIT_WORK(&phy->work, sprd_hsphy_charger_detect_work);
+	platform_set_drvdata(pdev, phy);
+
+	ret = usb_add_phy_dev(&phy->phy);
+	if (ret) {
+		dev_err(dev, "fail to add phy\n");
+		return ret;

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1269

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+	}
+
+	ret = sysfs_create_groups(&dev->kobj, usb_hsphy_groups);
+	if (ret)
+		dev_warn(dev, "failed to create usb hsphy attributes\n");
+
+	if (extcon_get_state(phy->phy.edev, EXTCON_USB) > 0)
+		usb_phy_set_charger_state(&phy->phy, USB_CHARGER_PRESENT);
+
+	dev_info(dev, "sprd usb phy probe ok !\n");

Drop. This code looks very, very poor :(. Lack of testing is even worse.

Quoted 3 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +3 -0
+
+	return ret;
+}

...

Quoted 4 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +4 -0
+static int __init sprd_hsphy_driver_init(void)
+{
+	return platform_driver_register(&sprd_hsphy_driver);
+}

drivers/phy/sprd/phy-sprd-usb20-hs.c line 1321

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +10 -0
+
+static void __exit sprd_hsphy_driver_exit(void)
+{
+	platform_driver_unregister(&sprd_hsphy_driver);
+}
+
+late_initcall(sprd_hsphy_driver_init);
+module_exit(sprd_hsphy_driver_exit);
+
+MODULE_ALIAS("platform:spreadtrum-usb20-hsphy");

You should not need MODULE_ALIAS() in normal cases. If you need it, usually it means your device ID table is wrong (e.g. misses either entries or MODULE_DEVICE_TABLE()). MODULE_ALIAS() is not a substitute for incomplete ID table.

Quoted 174 lines
drivers/phy/sprd/phy-sprd-usb20-hs.c new file +3 -0
+MODULE_AUTHOR("Pu Li <[email protected]>");
+MODULE_DESCRIPTION("Spreadtrum USB20 HSPHY driver");
+MODULE_LICENSE("GPL");
drivers/phy/sprd/phy-sprd-usb20-hs.h new file +165 -0
new file mode 100644
index 000000000000..897ee5e64482
@@ -0,0 +1,525 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * phy-sprd-usb20-hs.h - Spreadtrum usb20 phy Glue layer h file
+ *
+ * Copyright 2020-2023 Unisoc Inc.
+ */
+
+#ifndef __SPRD_USB20_HS_H
+#define __SPRD_USB20_HS_H
+
+#include <linux/regmap.h>
+#include <linux/usb/phy.h>
+
+struct sprd_hsphy {
+	struct device		*dev;
+	struct usb_phy		phy;
+	void __iomem		*base;
+	struct regulator	*vdd;
+	struct regmap           *aon_apb;
+	struct regmap           *ap_ahb;
+	struct regmap           *analog;
+	struct wakeup_source	*wake_lock;
+	struct work_struct	work;
+	unsigned long event;
+	u32			vdd_vol;
+	u32			phy_tune;
+	u32			host_eye_pattern;
+	u32			device_eye_pattern;
+	u32			host_otg_ctrl0;
+	u32			device_otg_ctrl0;
+	u32			host_otg_ctrl1;
+	u32			device_otg_ctrl1;
+	atomic_t		reset;
+	atomic_t		inited;
+	bool			is_host;
+};
+
+enum hsphy_parameters {
+	TUNEHSAMP_SHIFT,
+	TUNEEQ_SHIFT,
+	TFREGRES_SHIFT,
+	FULLSPEED_USB33_TUNE,
+};
+
+enum sprd_hsphy_reg_layout {
+	REG_AON_APB_APB_RST1,
+	REG_AON_APB_APB_RST2,
+	REG_AON_APB_APB_EB1,
+	REG_AON_APB_APB_EB2,
+	REG_AON_APB_CGM_REG1,
+	REG_AON_APB_OTG_PHY_TEST,
+	REG_AON_APB_OTG_PHY_CTRL,
+	REG_AON_APB_PWR_CTRL,
+	REG_AON_APB_AON_SOC_USB_CTRL,
+	REG_AON_APB_MIPI_CSI_POWER_CTRL,
+	REG_AP_AHB_AHB_EB,
+	REG_AP_AHB_AHB_RST,
+	REG_AP_AHB_OTG_CTRL0,
+	REG_AP_AHB_OTG_CTRL1,
+	REG_AP_AHB_OTG_PHY_CTRL,
+	REG_AP_AHB_OTG_PHY_TUNE,
+	REG_AP_AHB_OTG_PHY_TEST,
+	REG_ANALOG_USB20_USB20_ISO_SW,
+	REG_ANALOG_USB20_USB20_BATTER_PLL,
+	REG_ANALOG_USB20_USB20_UTMI_CTL1,
+	REG_ANALOG_USB20_USB20_TRIMMING,
+	REG_ANALOG_USB20_USB20_UTMI_CTL2,
+	REG_ANALOG_USB20_REG_SEL_CFG_0,
+	REG_ANALOG_USB20_IDDG,
+	REG_ANALOG_USB20_USB20_PHY,
+};
+
+enum sprd_hsphy_mask_layout {
+	MASK_AON_APB_USB_PHY_PD_S,
+	MASK_AON_APB_USB_PHY_PD_L,
+	MASK_AON_APB_ANLG_APB_EB,
+	MASK_AON_APB_ANLG_EB,
+	MASK_AON_APB_OTG_REF_EB,
+	MASK_AON_APB_ANA_EB,
+	MASK_AON_APB_OTG_UTMI_EB,
+	MASK_AON_APB_AON_USB2_TOP_EB,
+	MASK_AON_APB_OTG_PHY_EB,
+	MASK_AON_APB_CGM_OTG_REF_EN,
+	MASK_AON_APB_CGM_DPHY_REF_EN,
+	MASK_AON_APB_USB_ISO_SW_EN,
+	MASK_AON_APB_OTG_PHY_SOFT_RST,
+	MASK_AON_APB_OTG_UTMI_SOFT_RST,
+	MASK_AON_APB_OTG_VBUS_VALID_PHYREG,
+	MASK_AON_APB_USB2_PHY_IDDIG,
+	MASK_AON_APB_UTMI_WIDTH_SEL,
+	MASK_AON_APB_USB20_CTRL_MUX_REG,
+	MASK_AON_APB_USB20_ISO_SW_EN,
+	MASK_AON_APB_C2G_ANALOG_USB20_USB20_PS_PD_S,
+	MASK_AON_APB_C2G_ANALOG_USB20_USB20_PS_PD_L,
+	MASK_AP_AHB_OTG_EB,
+	MASK_AP_AHB_OTG_PHY_SOFT_RST,
+	MASK_AP_AHB_OTG_UTMI_SOFT_RST,
+	MASK_AP_AHB_OTG_SOFT_RST,
+	MASK_AP_AHB_USB2_PHY_IDDIG,
+	MASK_AP_AHB_OTG_DPPULLDOWN,
+	MASK_AP_AHB_OTG_DMPULLDOWN,
+	MASK_AP_AHB_OTG_VBUS_VALID_EXT,
+	MASK_AP_AHB_OTG_VBUS_VALID_PHYREG,
+	MASK_AP_AHB_UTMI_WIDTH_SEL,
+	MASK_AP_AHB_USB2_DATABUS16_8,
+	MASK_AP_AHB_USB20_SAMPLER_SEL,
+	MASK_AP_AHB_USB20_TUNEHSAMP,
+	MASK_AP_AHB_USB20_TUNEEQ,
+	MASK_AP_AHB_USB20_TFREGRES,
+	MASK_ANALOG_USB20_USB20_VBUSVLDEXT,
+	MASK_ANALOG_USB20_USB20_DATABUS16_8,
+	MASK_DBG_SEL_ANALOG_USB20_USB20_DMPULLDOWN,
+	MASK_DBG_SEL_ANALOG_USB20_USB20_DPPULLDOWN,
+	MASK_ANALOG_USB20_USB20_DMPULLDOWN,
+	MASK_ANALOG_USB20_USB20_DPPULLDOWN,
+	MASK_ANALOG_USB20_UTMIOTG_IDDG,
+	MASK_ANALOG_USB20_USB20_PS_PD_S,
+	MASK_ANALOG_USB20_USB20_PS_PD_L,
+	MASK_ANALOG_USB20_USB20_RESERVED,
+	MASK_ANALOG_USB20_USB20_ISO_SW_EN,
+	MASK_ANALOG_USB20_USB20_TUNEHSAMP,
+	MASK_ANALOG_USB20_USB20_TUNEEQ,
+	MASK_ANALOG_USB20_USB20_TFREGRES,
+};
+
+enum {
+	CTRL0 = 0,
+	CTRL1,
+	CTRL2,
+};
+
+struct sprd_hsphy_cfg_ops {
+	void (*usb_enable_ctrl)(struct sprd_hsphy *phy, int on);
+	void (*usb_phy_power_ctrl)(struct sprd_hsphy *phy, int on);
+	void (*usb_vbus_ctrl)(struct sprd_hsphy *phy, int on);
+	void (*utmi_width_sel)(struct sprd_hsphy *phy);
+	void (*reset_core)(struct sprd_hsphy *phy);
+	int (*set_mode)(struct sprd_hsphy *phy, int on);
+};
+
+enum hsphy_ip_version {
+	VERSION1,
+	VERSION2,
+	VERSION3,
+	VERSION4,
+};
+
+enum hsphy_owner {
+	PIKE2,
+	SHARKLE,
+	SHARKL3,
+	SHARKL5,
+	SHARKL5PRO,
+	QOGIRL6,
+	QOGIRN6LITE,
+	UIS8520,
+};
+
+struct sprd_hsphy_cfg {
+	/* array of registers with different offsets */
+	const unsigned int *regs;
+
+	const unsigned int *masks;
+
+	/* private ops for each SOC */

drivers/phy/sprd/phy-sprd-usb20-hs.h line 175

Quoted 10 lines
drivers/phy/sprd/phy-sprd-usb20-hs.h new file +10 -0
+	const struct sprd_hsphy_cfg_ops *cfg_ops;
+
+	const unsigned int *parameters;
+
+	enum hsphy_ip_version phy_version;
+
+	enum hsphy_owner	owner;
+};
+
+static const unsigned int pike2_regs_layout[] = {

Static data allocated in every unit including this header? No, this does not look like correct code (yeah, it compiles but it is just wrong).

Best regards,
Krzysztof