public inbox for devicetree@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Add USB support for Canaan K230
@ 2026-01-15  6:42 Jiayu Du
  2026-01-15  6:42 ` [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY Jiayu Du
                   ` (3 more replies)
  0 siblings, 4 replies; 10+ messages in thread
From: Jiayu Du @ 2026-01-15  6:42 UTC (permalink / raw)
  To: conor
  Cc: vkoul, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, jiayu.riscv, 18771902331, cyy, TroyMitchell988,
	kingxukai, linux-phy, linux-usb, devicetree, linux-kernel,
	linux-riscv, gaohan

Add support for the USB PHY and DWC2 IP which is used by Canaan K230,
and made relevant changes to the DTS.

This series is based on the initial 100ask K230 DshanPi series [1] which
is based on the clock and pinctrl series. Check the details in the link.

Link: https://lore.kernel.org/all/20260115060801.16819-1-jiayu.riscv@isrc.iscas.ac.cn/ [1]

Changes in v2:
- Fold the child into the parent in dtsi.
- Define one usbphy with phy-cells=1.
- Delete the clock of the usbphy as it is not needed.
- Link to v1: https://lore.kernel.org/all/20251230023725.15966-1-jiayu.riscv@isrc.iscas.ac.cn/

Jiayu Du (4):
  dt-bindings: phy: Add Canaan K230 USB PHY
  dt-bindings: usb: dwc2: Add support for Canaan K230 SoC
  phy: usb: Add driver for Canaan K230 USB 2.0 PHY
  riscv: dts: canaan: Add syscon and USB nodes for K230

 .../bindings/phy/canaan,k230-usb-phy.yaml     |  35 +++
 .../devicetree/bindings/usb/dwc2.yaml         |   3 +
 .../boot/dts/canaan/k230-canmv-dshanpi.dts    |  17 ++
 arch/riscv/boot/dts/canaan/k230.dtsi          |  35 +++
 drivers/phy/Kconfig                           |   1 +
 drivers/phy/Makefile                          |   1 +
 drivers/phy/canaan/Kconfig                    |  14 +
 drivers/phy/canaan/Makefile                   |   2 +
 drivers/phy/canaan/phy-k230-usb.c             | 271 ++++++++++++++++++
 9 files changed, 379 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml
 create mode 100644 drivers/phy/canaan/Kconfig
 create mode 100644 drivers/phy/canaan/Makefile
 create mode 100644 drivers/phy/canaan/phy-k230-usb.c

-- 
2.52.0


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

* [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY
  2026-01-15  6:42 [PATCH v2 0/4] Add USB support for Canaan K230 Jiayu Du
@ 2026-01-15  6:42 ` Jiayu Du
  2026-01-15 20:03   ` Rob Herring (Arm)
  2026-01-15  6:42 ` [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC Jiayu Du
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 10+ messages in thread
From: Jiayu Du @ 2026-01-15  6:42 UTC (permalink / raw)
  To: conor
  Cc: vkoul, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, jiayu.riscv, 18771902331, cyy, TroyMitchell988,
	kingxukai, linux-phy, linux-usb, devicetree, linux-kernel,
	linux-riscv, gaohan

K230 SoC USB PHY requires configuring registers for control and
configuration. Add USB phy bindings for K230 SoC.

Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
---
 .../bindings/phy/canaan,k230-usb-phy.yaml     | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml

diff --git a/Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml b/Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml
new file mode 100644
index 000000000000..be54efd612ac
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml
@@ -0,0 +1,35 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/phy/canaan,k230-usb-phy.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Canaan K230 USB2.0 PHY
+
+maintainers:
+  - Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
+
+properties:
+  compatible:
+    const: canaan,k230-usb-phy
+
+  reg:
+    maxItems: 1
+
+  "#phy-cells":
+    const: 1
+
+required:
+  - compatible
+  - reg
+  - "#phy-cells"
+
+additionalProperties: false
+
+examples:
+  - |
+    usbphy: usb-phy@91585000 {
+        compatible = "canaan,k230-usb-phy";
+        reg = <0x0 0x91585000 0x0 0x400>;
+        #phy-cells = <1>;
+    };
-- 
2.52.0


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

* [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC
  2026-01-15  6:42 [PATCH v2 0/4] Add USB support for Canaan K230 Jiayu Du
  2026-01-15  6:42 ` [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY Jiayu Du
@ 2026-01-15  6:42 ` Jiayu Du
  2026-01-15  8:30   ` Rob Herring (Arm)
  2026-01-15  6:42 ` [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY Jiayu Du
  2026-01-15  6:42 ` [PATCH v2 4/4] riscv: dts: canaan: Add syscon and USB nodes for K230 Jiayu Du
  3 siblings, 1 reply; 10+ messages in thread
From: Jiayu Du @ 2026-01-15  6:42 UTC (permalink / raw)
  To: conor
  Cc: vkoul, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, jiayu.riscv, 18771902331, cyy, TroyMitchell988,
	kingxukai, linux-phy, linux-usb, devicetree, linux-kernel,
	linux-riscv, gaohan

Add 'canaan,k230-usb' compatible string with 'snps,dwc2' as fallback
for the DWC2 IP which is used by Canaan K230.

Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
---
 Documentation/devicetree/bindings/usb/dwc2.yaml | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.yaml b/Documentation/devicetree/bindings/usb/dwc2.yaml
index 6c3a10991b8b..352487c6392a 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.yaml
+++ b/Documentation/devicetree/bindings/usb/dwc2.yaml
@@ -17,6 +17,9 @@ properties:
   compatible:
     oneOf:
       - const: brcm,bcm2835-usb
+      - items:
+          - const: canaan,k230-usb
+          - const: snps,dwc2
       - const: hisilicon,hi6220-usb
       - const: ingenic,jz4775-otg
       - const: ingenic,jz4780-otg
-- 
2.52.0


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

* [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY
  2026-01-15  6:42 [PATCH v2 0/4] Add USB support for Canaan K230 Jiayu Du
  2026-01-15  6:42 ` [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY Jiayu Du
  2026-01-15  6:42 ` [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC Jiayu Du
@ 2026-01-15  6:42 ` Jiayu Du
  2026-01-15 12:05   ` Vinod Koul
  2026-01-15  6:42 ` [PATCH v2 4/4] riscv: dts: canaan: Add syscon and USB nodes for K230 Jiayu Du
  3 siblings, 1 reply; 10+ messages in thread
From: Jiayu Du @ 2026-01-15  6:42 UTC (permalink / raw)
  To: conor
  Cc: vkoul, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, jiayu.riscv, 18771902331, cyy, TroyMitchell988,
	kingxukai, linux-phy, linux-usb, devicetree, linux-kernel,
	linux-riscv, gaohan

Add driver for the USB 2.0 PHY in Canaan K230 SoC, which supports PHY
initialization and power management.

Add Kconfig/Makefile under drivers/phy/canaan/.

Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
---
 drivers/phy/Kconfig               |   1 +
 drivers/phy/Makefile              |   1 +
 drivers/phy/canaan/Kconfig        |  14 ++
 drivers/phy/canaan/Makefile       |   2 +
 drivers/phy/canaan/phy-k230-usb.c | 271 ++++++++++++++++++++++++++++++
 5 files changed, 289 insertions(+)
 create mode 100644 drivers/phy/canaan/Kconfig
 create mode 100644 drivers/phy/canaan/Makefile
 create mode 100644 drivers/phy/canaan/phy-k230-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 678dd0452f0a..95e630749350 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -105,6 +105,7 @@ source "drivers/phy/allwinner/Kconfig"
 source "drivers/phy/amlogic/Kconfig"
 source "drivers/phy/broadcom/Kconfig"
 source "drivers/phy/cadence/Kconfig"
+source "drivers/phy/canaan/Kconfig"
 source "drivers/phy/freescale/Kconfig"
 source "drivers/phy/hisilicon/Kconfig"
 source "drivers/phy/ingenic/Kconfig"
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index bfb27fb5a494..f07c68f2e283 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-y					+= allwinner/	\
 					   amlogic/	\
 					   broadcom/	\
 					   cadence/	\
+					   canaan/	\
 					   freescale/	\
 					   hisilicon/	\
 					   ingenic/	\
diff --git a/drivers/phy/canaan/Kconfig b/drivers/phy/canaan/Kconfig
new file mode 100644
index 000000000000..1ff8831846d5
--- /dev/null
+++ b/drivers/phy/canaan/Kconfig
@@ -0,0 +1,14 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Phy drivers for Canaan platforms
+#
+config PHY_CANAAN_USB
+	tristate "Canaan USB2 PHY Driver"
+	depends on (ARCH_CANAAN || COMPILE_TEST) && OF
+	select GENERIC_PHY
+	help
+	Enable this driver to support the USB 2.0 PHY controller
+	on Canaan K230 RISC-V SoCs. This PHY controller
+	provides physical layer functionality for USB 2.0 devices.
+	If you have a Canaan K230 board and need USB 2.0 support,
+	say Y or M here.
diff --git a/drivers/phy/canaan/Makefile b/drivers/phy/canaan/Makefile
new file mode 100644
index 000000000000..d73857ba284e
--- /dev/null
+++ b/drivers/phy/canaan/Makefile
@@ -0,0 +1,2 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_PHY_CANAAN_USB)		+= phy-k230-usb.o
diff --git a/drivers/phy/canaan/phy-k230-usb.c b/drivers/phy/canaan/phy-k230-usb.c
new file mode 100644
index 000000000000..e4bd98aa4e89
--- /dev/null
+++ b/drivers/phy/canaan/phy-k230-usb.c
@@ -0,0 +1,271 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Canaan usb PHY driver
+ *
+ * Copyright (C) 2025 Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/io.h>
+#include <linux/of_address.h>
+#include <linux/phy/phy.h>
+#include <linux/platform_device.h>
+
+#define CTL0_OFFSET		0x00
+#define CTL1_OFFSET		0x04
+#define TEST_CTL3_OFFSET	0x0c
+
+#define USB_IDPULLUP0		BIT(4)
+#define USB_DMPULLDOWN0		BIT(8)
+#define USB_DPPULLDOWN0		BIT(9)
+
+#define MAX_PHYS		2
+
+/* USB control register 0 in HiSysConfig system controller */
+/* PLL Integral Path Tune */
+#define USB_CTL0_PLLITUNE_MASK		GENMASK(23, 22)
+
+/* PLL Proportional Path Tune */
+#define USB_CTL0_PLLPTUNE_MASK		GENMASK(21, 18)
+
+/* PLL Bandwidth Adjustment */
+#define USB_CTL0_PLLBTUNE_MASK		GENMASK(17, 17)
+
+/* VReg18 Bypass Control */
+#define USB_CTL0_VREGBYPASS_MASK	GENMASK(16, 16)
+
+/* Retention Mode Enable */
+#define USB_CTL0_RETENABLEN_MASK	GENMASK(15, 15)
+
+/* Reserved Request Input */
+#define USB_CTL0_RESREQIN_MASK		GENMASK(14, 14)
+
+/* External VBUS Valid Select */
+#define USB_CTL0_VBUSVLDEXTSEL0_MASK	GENMASK(13, 13)
+
+/* OTG Block Disable Control */
+#define USB_CTL0_OTGDISABLE0_MASK	GENMASK(12, 12)
+
+/* Drive VBUS Enable */
+#define USB_CTL0_DRVVBUS0_MASK		GENMASK(11, 11)
+
+/* Autoresume Mode Enable */
+#define USB_CTL0_AUTORSMENB0_MASK	GENMASK(10, 10)
+
+/* HS Transceiver Asynchronous Control */
+#define USB_CTL0_HSXCVREXTCTL0_MASK	GENMASK(9, 9)
+
+/* USB 1.1 Transmit Data */
+#define USB_CTL0_FSDATAEXT0_MASK	GENMASK(8, 8)
+
+/* USB 1.1 SE0 Generation */
+#define USB_CTL0_FSSE0EXT0_MASK		GENMASK(7, 7)
+
+/* USB 1.1 Data Enable */
+#define USB_CTL0_TXENABLEN0_MASK	GENMASK(6, 6)
+
+/* Disconnect Threshold */
+#define USB_CTL0_COMPDISTUNE0_MASK	GENMASK(5, 3)
+
+/* Squelch Threshold */
+#define USB_CTL0_SQRXTUNE0_MASK		GENMASK(2, 0)
+
+/* USB control register 1 in HiSysConfig system controller */
+/* Data Detect Voltage */
+#define USB_CTL1_VDATREFTUNE0_MASK	GENMASK(23, 22)
+
+/* VBUS Valid Threshold */
+#define USB_CTL1_OTGTUNE0_MASK		GENMASK(21, 19)
+
+/* Transmitter High-Speed Crossover */
+#define USB_CTL1_TXHSXVTUNE0_MASK	GENMASK(18, 17)
+
+/* FS/LS Source Impedance */
+#define USB_CTL1_TXFSLSTUNE0_MASK	GENMASK(16, 13)
+
+/* HS DC Voltage Level */
+#define USB_CTL1_TXVREFTUNE0_MASK	GENMASK(12, 9)
+
+/* HS Transmitter Rise/Fall Time */
+#define USB_CTL1_TXRISETUNE0_MASK	GENMASK(8, 7)
+
+/* USB Source Impedance */
+#define USB_CTL1_TXRESTUNE0_MASK	GENMASK(6, 5)
+
+/* HS Transmitter Pre-Emphasis Current Control */
+#define USB_CTL1_TXPREEMPAMPTUNE0_MASK	GENMASK(4, 3)
+
+/* HS Transmitter Pre-Emphasis Duration Control */
+#define USB_CTL1_TXPREEMPPULSETUNE0_MASK	GENMASK(2, 2)
+
+/* charging detection */
+#define USB_CTL1_CHRGSRCPUENB0_MASK	GENMASK(1, 0)
+
+#define K230_PHY_CTL0_VAL \
+( \
+	FIELD_PREP(USB_CTL0_PLLITUNE_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_PLLPTUNE_MASK, 0xc) | \
+	FIELD_PREP(USB_CTL0_PLLBTUNE_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL0_VREGBYPASS_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL0_RETENABLEN_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL0_RESREQIN_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_VBUSVLDEXTSEL0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_OTGDISABLE0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_DRVVBUS0_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL0_AUTORSMENB0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_HSXCVREXTCTL0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_FSDATAEXT0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_FSSE0EXT0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_TXENABLEN0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL0_COMPDISTUNE0_MASK, 0x3) | \
+	FIELD_PREP(USB_CTL0_SQRXTUNE0_MASK, 0x3) \
+)
+
+#define K230_PHY_CTL1_VAL \
+( \
+	FIELD_PREP(USB_CTL1_VDATREFTUNE0_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL1_OTGTUNE0_MASK, 0x3) | \
+	FIELD_PREP(USB_CTL1_TXHSXVTUNE0_MASK, 0x3) | \
+	FIELD_PREP(USB_CTL1_TXFSLSTUNE0_MASK, 0x3) | \
+	FIELD_PREP(USB_CTL1_TXVREFTUNE0_MASK, 0x3) | \
+	FIELD_PREP(USB_CTL1_TXRISETUNE0_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL1_TXRESTUNE0_MASK, 0x1) | \
+	FIELD_PREP(USB_CTL1_TXPREEMPAMPTUNE0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL1_TXPREEMPPULSETUNE0_MASK, 0x0) | \
+	FIELD_PREP(USB_CTL1_CHRGSRCPUENB0_MASK, 0x0) \
+)
+struct k230_usb_phy_global {
+	u32 reg_test_offset[MAX_PHYS];
+	u32 reg_ctl_offset[MAX_PHYS];
+	void __iomem *base;
+};
+
+struct k230_usb_phy_instance {
+	struct k230_usb_phy_global *global;
+	int index;
+};
+
+static int k230_usb_phy_power_on(struct phy *_phy)
+{
+	struct k230_usb_phy_instance *phy_inst = phy_get_drvdata(_phy);
+	struct k230_usb_phy_global *global = phy_inst->global;
+	u32 val;
+
+	writel(K230_PHY_CTL0_VAL, global->base +
+	       global->reg_ctl_offset[phy_inst->index] + CTL0_OFFSET);
+
+	writel(K230_PHY_CTL1_VAL, global->base +
+	       global->reg_ctl_offset[phy_inst->index] + CTL1_OFFSET);
+
+	val = readl(global->base +
+		    global->reg_test_offset[phy_inst->index] +
+		    TEST_CTL3_OFFSET);
+
+	val |= USB_IDPULLUP0;
+	if (phy_inst->index == 1)
+		val |= (USB_DMPULLDOWN0 | USB_DPPULLDOWN0);
+	else
+		val &= ~(USB_DMPULLDOWN0 | USB_DPPULLDOWN0);
+
+	writel(val, global->base +
+	       global->reg_test_offset[phy_inst->index] +
+	       TEST_CTL3_OFFSET);
+
+	return 0;
+}
+
+static int k230_usb_phy_power_off(struct phy *_phy)
+{
+	struct k230_usb_phy_instance *phy_inst = phy_get_drvdata(_phy);
+	struct k230_usb_phy_global *global = phy_inst->global;
+	u32 val;
+
+	val = readl(global->base +
+		    global->reg_test_offset[phy_inst->index] +
+		    TEST_CTL3_OFFSET);
+
+	val &= ~(USB_DMPULLDOWN0 | USB_DPPULLDOWN0);
+
+	writel(val, global->base +
+	       global->reg_test_offset[phy_inst->index] +
+	       TEST_CTL3_OFFSET);
+
+	return 0;
+}
+
+static const struct phy_ops k230_usb_phy_ops = {
+	.power_on = k230_usb_phy_power_on,
+	.power_off = k230_usb_phy_power_off,
+	.owner = THIS_MODULE,
+};
+
+static struct phy *k230_usb_phy_xlate(struct device *dev,
+				      const struct of_phandle_args *args)
+{
+	struct k230_usb_phy_global *global = dev_get_drvdata(dev);
+	struct k230_usb_phy_instance *phy_inst;
+	struct phy *phy;
+
+	if (args->args[0] >= MAX_PHYS)
+		return ERR_PTR(-EINVAL);
+
+	phy_inst = devm_kzalloc(dev, sizeof(*phy_inst), GFP_KERNEL);
+	if (!phy_inst)
+		return ERR_PTR(-ENOMEM);
+
+	phy_inst->global = global;
+	phy_inst->index = args->args[0];
+
+	phy = devm_phy_create(dev, NULL, &k230_usb_phy_ops);
+	if (IS_ERR(phy))
+		return ERR_PTR(PTR_ERR(phy));
+
+	phy_set_drvdata(phy, phy_inst);
+
+	return phy;
+}
+
+static int k230_usb_phy_probe(struct platform_device *pdev)
+{
+	struct k230_usb_phy_global *global;
+	struct device *dev = &pdev->dev;
+	struct phy_provider *provider;
+
+	global = devm_kzalloc(dev, sizeof(*global), GFP_KERNEL);
+	if (!global)
+		return -ENOMEM;
+	dev_set_drvdata(dev, global);
+
+	global->base = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(global->base))
+		return dev_err_probe(dev, PTR_ERR(global->base),
+				     "ioremap failed\n");
+
+	global->reg_test_offset[0] = 0x70;
+	global->reg_ctl_offset[0] = 0xb0;
+	global->reg_test_offset[1] = 0x90;
+	global->reg_ctl_offset[1] = 0xb8;
+
+	provider = devm_of_phy_provider_register(dev, k230_usb_phy_xlate);
+
+	return 0;
+}
+
+static const struct of_device_id k230_usb_phy_of_match[] = {
+	{ .compatible = "canaan,k230-usb-phy" },
+	{}
+};
+MODULE_DEVICE_TABLE(of, k230_usb_phy_of_match);
+
+static struct platform_driver k230_usb_phy_driver = {
+	.probe = k230_usb_phy_probe,
+	.driver = {
+		.name = "k230-usb-phy",
+		.of_match_table = k230_usb_phy_of_match,
+	},
+};
+module_platform_driver(k230_usb_phy_driver);
+
+MODULE_DESCRIPTION("Canaan Kendryte K230 USB 2.0 PHY driver");
+MODULE_AUTHOR("Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>");
+MODULE_LICENSE("GPL");
-- 
2.52.0


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

* [PATCH v2 4/4] riscv: dts: canaan: Add syscon and USB nodes for K230
  2026-01-15  6:42 [PATCH v2 0/4] Add USB support for Canaan K230 Jiayu Du
                   ` (2 preceding siblings ...)
  2026-01-15  6:42 ` [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY Jiayu Du
@ 2026-01-15  6:42 ` Jiayu Du
  3 siblings, 0 replies; 10+ messages in thread
From: Jiayu Du @ 2026-01-15  6:42 UTC (permalink / raw)
  To: conor
  Cc: vkoul, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, jiayu.riscv, 18771902331, cyy, TroyMitchell988,
	kingxukai, linux-phy, linux-usb, devicetree, linux-kernel,
	linux-riscv, gaohan

Add top syscon and USB PHY subdevice nodes, USB0/USB1 dwc2 controller
to K230 DTSI, and enable UART0 and USB0/USB1 in DshanPI DT.

Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
---
 .../boot/dts/canaan/k230-canmv-dshanpi.dts    | 17 +++++++++
 arch/riscv/boot/dts/canaan/k230.dtsi          | 35 +++++++++++++++++++
 2 files changed, 52 insertions(+)

diff --git a/arch/riscv/boot/dts/canaan/k230-canmv-dshanpi.dts b/arch/riscv/boot/dts/canaan/k230-canmv-dshanpi.dts
index 4f95b534ee87..55197cfc25b4 100644
--- a/arch/riscv/boot/dts/canaan/k230-canmv-dshanpi.dts
+++ b/arch/riscv/boot/dts/canaan/k230-canmv-dshanpi.dts
@@ -80,3 +80,20 @@ &uart0 {
 	pinctrl-0 = <&uart0_pins>;
 	status = "okay";
 };
+
+&usb0 {
+	vusb_d-supply = <&vdd_3v3>;
+	vusb_a-supply = <&vdd_1v8>;
+	status = "okay";
+};
+
+&usb1 {
+	dr_mode = "host";
+	vusb_d-supply = <&vdd_3v3>;
+	vusb_a-supply = <&vdd_1v8>;
+	status = "okay";
+};
+
+&usbphy {
+	status = "okay";
+};
diff --git a/arch/riscv/boot/dts/canaan/k230.dtsi b/arch/riscv/boot/dts/canaan/k230.dtsi
index b815a65e02b9..6dcb086f7046 100644
--- a/arch/riscv/boot/dts/canaan/k230.dtsi
+++ b/arch/riscv/boot/dts/canaan/k230.dtsi
@@ -148,5 +148,40 @@ uart4: serial@91404000 {
 			reg-shift = <2>;
 			status = "disabled";
 		};
+
+		usb0: usb@91500000 {
+			compatible = "canaan,k230-usb", "snps,dwc2";
+			reg = <0x0 0x91500000 0x0 0x40000>;
+			interrupts = <173 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&sysclk K230_HS_USB0_AHB_GATE>;
+			clock-names = "otg";
+			g-rx-fifo-size = <512>;
+			g-np-tx-fifo-size = <64>;
+			g-tx-fifo-size = <512 1024 64 64 64 64>;
+			phys = <&usbphy 0>;
+			phy-names = "usb2-phy";
+			status = "disabled";
+		};
+
+		usb1: usb@91540000 {
+			compatible = "canaan,k230-usb", "snps,dwc2";
+			reg = <0x0 0x91540000 0x0 0x40000>;
+			interrupts = <174 IRQ_TYPE_LEVEL_HIGH>;
+			clocks = <&sysclk K230_HS_USB1_AHB_GATE>;
+			clock-names = "otg";
+			g-rx-fifo-size = <512>;
+			g-np-tx-fifo-size = <64>;
+			g-tx-fifo-size = <512 1024 64 64 64 64>;
+			phys = <&usbphy 1>;
+			phy-names = "usb2-phy";
+			status = "disabled";
+		};
+
+		usbphy: usb-phy@91585000 {
+			compatible = "canaan,k230-usb-phy";
+			reg = <0x0 0x91585000 0x0 0x400>;
+			#phy-cells = <1>;
+			status = "disabled";
+		};
 	};
 };
-- 
2.52.0


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

* Re: [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC
  2026-01-15  6:42 ` [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC Jiayu Du
@ 2026-01-15  8:30   ` Rob Herring (Arm)
  2026-01-15 11:39     ` Jiayu Du
  0 siblings, 1 reply; 10+ messages in thread
From: Rob Herring (Arm) @ 2026-01-15  8:30 UTC (permalink / raw)
  To: Jiayu Du
  Cc: vkoul, linux-usb, conor+dt, krzk+dt, linux-kernel, cyy, alex, pjw,
	kingxukai, conor, aou, linux-riscv, palmer, neil.armstrong,
	gaohan, linux-phy, gregkh, 18771902331, devicetree,
	TroyMitchell988


On Thu, 15 Jan 2026 14:42:20 +0800, Jiayu Du wrote:
> Add 'canaan,k230-usb' compatible string with 'snps,dwc2' as fallback
> for the DWC2 IP which is used by Canaan K230.
> 
> Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
> ---
>  Documentation/devicetree/bindings/usb/dwc2.yaml | 3 +++
>  1 file changed, 3 insertions(+)
> 

My bot found errors running 'make dt_binding_check' on your patch:

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.example.dtb: usb-phy@91585000 (canaan,k230-usb-phy): reg: [[0, 2438483968], [0, 1024]] is too long
	from schema $id: http://devicetree.org/schemas/phy/canaan,k230-usb-phy.yaml

doc reference errors (make refcheckdocs):

See https://patchwork.kernel.org/project/devicetree/patch/20260115064223.21926-3-jiayu.riscv@isrc.iscas.ac.cn

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] 10+ messages in thread

* Re: [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC
  2026-01-15  8:30   ` Rob Herring (Arm)
@ 2026-01-15 11:39     ` Jiayu Du
  0 siblings, 0 replies; 10+ messages in thread
From: Jiayu Du @ 2026-01-15 11:39 UTC (permalink / raw)
  To: Rob Herring (Arm)
  Cc: vkoul, linux-usb, conor+dt, krzk+dt, linux-kernel, cyy, alex, pjw,
	kingxukai, conor, aou, linux-riscv, palmer, neil.armstrong,
	gaohan, linux-phy, gregkh, 18771902331, devicetree,
	TroyMitchell988

On Thu, Jan 15, 2026 at 02:30:03AM -0600, Rob Herring (Arm) wrote:
> 
> On Thu, 15 Jan 2026 14:42:20 +0800, Jiayu Du wrote:
> > Add 'canaan,k230-usb' compatible string with 'snps,dwc2' as fallback
> > for the DWC2 IP which is used by Canaan K230.
> > 
> > Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
> > ---
> >  Documentation/devicetree/bindings/usb/dwc2.yaml | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> 
> My bot found errors running 'make dt_binding_check' on your patch:
> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> /builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.example.dtb: usb-phy@91585000 (canaan,k230-usb-phy): reg: [[0, 2438483968], [0, 1024]] is too long
> 	from schema $id: http://devicetree.org/schemas/phy/canaan,k230-usb-phy.yaml
> 
> doc reference errors (make refcheckdocs):
> 
> See https://patchwork.kernel.org/project/devicetree/patch/20260115064223.21926-3-jiayu.riscv@isrc.iscas.ac.cn
> 
> 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.
I will run the make dt_binding_check, and then fix it in v3.

Regards,
Jiayu Du


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

* Re: [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY
  2026-01-15  6:42 ` [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY Jiayu Du
@ 2026-01-15 12:05   ` Vinod Koul
  2026-01-15 14:35     ` Jiayu Du
  0 siblings, 1 reply; 10+ messages in thread
From: Vinod Koul @ 2026-01-15 12:05 UTC (permalink / raw)
  To: Jiayu Du
  Cc: conor, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, 18771902331, cyy, TroyMitchell988, kingxukai,
	linux-phy, linux-usb, devicetree, linux-kernel, linux-riscv,
	gaohan

On 15-01-26, 14:42, Jiayu Du wrote:

> +static struct phy *k230_usb_phy_xlate(struct device *dev,
> +				      const struct of_phandle_args *args)
> +{
> +	struct k230_usb_phy_global *global = dev_get_drvdata(dev);
> +	struct k230_usb_phy_instance *phy_inst;
> +	struct phy *phy;
> +
> +	if (args->args[0] >= MAX_PHYS)
> +		return ERR_PTR(-EINVAL);
> +
> +	phy_inst = devm_kzalloc(dev, sizeof(*phy_inst), GFP_KERNEL);
> +	if (!phy_inst)
> +		return ERR_PTR(-ENOMEM);
> +
> +	phy_inst->global = global;
> +	phy_inst->index = args->args[0];
> +
> +	phy = devm_phy_create(dev, NULL, &k230_usb_phy_ops);
> +	if (IS_ERR(phy))
> +		return ERR_PTR(PTR_ERR(phy));
> +
> +	phy_set_drvdata(phy, phy_inst);

This seems wrong place, why is this not done in the driver probe?

> +
> +	return phy;
> +}
> +
> +static int k230_usb_phy_probe(struct platform_device *pdev)
> +{
> +	struct k230_usb_phy_global *global;
> +	struct device *dev = &pdev->dev;
> +	struct phy_provider *provider;
> +
> +	global = devm_kzalloc(dev, sizeof(*global), GFP_KERNEL);
> +	if (!global)
> +		return -ENOMEM;
> +	dev_set_drvdata(dev, global);
> +
> +	global->base = devm_platform_ioremap_resource(pdev, 0);
> +	if (IS_ERR(global->base))
> +		return dev_err_probe(dev, PTR_ERR(global->base),
> +				     "ioremap failed\n");
> +
> +	global->reg_test_offset[0] = 0x70;
> +	global->reg_ctl_offset[0] = 0xb0;
> +	global->reg_test_offset[1] = 0x90;
> +	global->reg_ctl_offset[1] = 0xb8;

Where are these magic values coming from?

-- 
~Vinod

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

* Re: [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY
  2026-01-15 12:05   ` Vinod Koul
@ 2026-01-15 14:35     ` Jiayu Du
  0 siblings, 0 replies; 10+ messages in thread
From: Jiayu Du @ 2026-01-15 14:35 UTC (permalink / raw)
  To: Vinod Koul
  Cc: conor, neil.armstrong, gregkh, robh, krzk+dt, conor+dt, pjw,
	palmer, aou, alex, 18771902331, cyy, TroyMitchell988, kingxukai,
	linux-phy, linux-usb, devicetree, linux-kernel, linux-riscv,
	gaohan

On Thu, Jan 15, 2026 at 05:35:48PM +0530, Vinod Koul wrote:
> On 15-01-26, 14:42, Jiayu Du wrote:
> 
> > +static struct phy *k230_usb_phy_xlate(struct device *dev,
> > +				      const struct of_phandle_args *args)
> > +{
> > +	struct k230_usb_phy_global *global = dev_get_drvdata(dev);
> > +	struct k230_usb_phy_instance *phy_inst;
> > +	struct phy *phy;
> > +
> > +	if (args->args[0] >= MAX_PHYS)
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	phy_inst = devm_kzalloc(dev, sizeof(*phy_inst), GFP_KERNEL);
> > +	if (!phy_inst)
> > +		return ERR_PTR(-ENOMEM);
> > +
> > +	phy_inst->global = global;
> > +	phy_inst->index = args->args[0];
> > +
> > +	phy = devm_phy_create(dev, NULL, &k230_usb_phy_ops);
> > +	if (IS_ERR(phy))
> > +		return ERR_PTR(PTR_ERR(phy));
> > +
> > +	phy_set_drvdata(phy, phy_inst);
> 
> This seems wrong place, why is this not done in the driver probe?

You are right, creating phy instances in the xlate function is not
the right place. I will move the allocation and devm_phy_creat to
the probe phase to create both instances.

> > +	global->reg_test_offset[0] = 0x70;
> > +	global->reg_ctl_offset[0] = 0xb0;
> > +	global->reg_test_offset[1] = 0x90;
> > +	global->reg_ctl_offset[1] = 0xb8;
> 
> Where are these magic values coming from?

These offsets are from K230 Technical Reference Manual section 12.6.4.2.
The TRM is here[1]. I will define them as macros with descriptive names.

Link:
https://kendryte-download.canaan-creative.com/developer/k230/HDK/K230%E7%A1%AC%E4%BB%B6%E6%96%87%E6%A1%A3/K230_Technical_Reference_Manual_V0.3.1_20241118.pdf[1]

I will send v2 with these changes soon.

Regards,
Jiayu Du


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

* Re: [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY
  2026-01-15  6:42 ` [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY Jiayu Du
@ 2026-01-15 20:03   ` Rob Herring (Arm)
  0 siblings, 0 replies; 10+ messages in thread
From: Rob Herring (Arm) @ 2026-01-15 20:03 UTC (permalink / raw)
  To: Jiayu Du
  Cc: devicetree, vkoul, TroyMitchell988, linux-usb, conor, kingxukai,
	linux-riscv, alex, pjw, linux-kernel, krzk+dt, gaohan, cyy,
	gregkh, linux-phy, aou, neil.armstrong, conor+dt, palmer,
	18771902331


On Thu, 15 Jan 2026 14:42:19 +0800, Jiayu Du wrote:
> K230 SoC USB PHY requires configuring registers for control and
> configuration. Add USB phy bindings for K230 SoC.
> 
> Signed-off-by: Jiayu Du <jiayu.riscv@isrc.iscas.ac.cn>
> ---
>  .../bindings/phy/canaan,k230-usb-phy.yaml     | 35 +++++++++++++++++++
>  1 file changed, 35 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/canaan,k230-usb-phy.yaml
> 

Reviewed-by: Rob Herring (Arm) <robh@kernel.org>


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

end of thread, other threads:[~2026-01-15 20:03 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-15  6:42 [PATCH v2 0/4] Add USB support for Canaan K230 Jiayu Du
2026-01-15  6:42 ` [PATCH v2 1/4] dt-bindings: phy: Add Canaan K230 USB PHY Jiayu Du
2026-01-15 20:03   ` Rob Herring (Arm)
2026-01-15  6:42 ` [PATCH v2 2/4] dt-bindings: usb: dwc2: Add support for Canaan K230 SoC Jiayu Du
2026-01-15  8:30   ` Rob Herring (Arm)
2026-01-15 11:39     ` Jiayu Du
2026-01-15  6:42 ` [PATCH v2 3/4] phy: usb: Add driver for Canaan K230 USB 2.0 PHY Jiayu Du
2026-01-15 12:05   ` Vinod Koul
2026-01-15 14:35     ` Jiayu Du
2026-01-15  6:42 ` [PATCH v2 4/4] riscv: dts: canaan: Add syscon and USB nodes for K230 Jiayu Du

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox