linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver
@ 2022-03-24  7:34 Aswath Govindraju
  2022-03-24  7:34 ` [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module Aswath Govindraju
                   ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Aswath Govindraju @ 2022-03-24  7:34 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

The following series of patches add support for AM62 USB wrapper driver
and its corresponding bindings.

changes since v1:
- Fixed the error with dev_pm_ops uninitialization, in patch 2.
  This was reported by kernel test bot
- In patch 1, made correction in grammer of clocks property description
  and added maxItems in the interrupts property based on comments
  received from Roger
- In patch 1, corrected the title, fixed the description of
  ti,syscon-phy-pll-refclk, added pattern properties and child node
  in the example based on the comments from Krzysztof.

Aswath Govindraju (2):
  dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  drivers: usb: dwc3: Add AM62 USB wrapper driver

 .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++
 drivers/usb/dwc3/Kconfig                      |   9 +
 drivers/usb/dwc3/Makefile                     |   1 +
 drivers/usb/dwc3/dwc3-am62.c                  | 581 ++++++++++++++++++
 4 files changed, 708 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
 create mode 100644 drivers/usb/dwc3/dwc3-am62.c

-- 
2.17.1


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

* [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-03-24  7:34 [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver Aswath Govindraju
@ 2022-03-24  7:34 ` Aswath Govindraju
  2022-03-24 11:07   ` Krzysztof Kozlowski
  2022-03-24  7:34 ` [PATCH v2 2/2] drivers: usb: dwc3: Add AM62 USB wrapper driver Aswath Govindraju
  2022-04-07  5:32 ` [PATCH v2 0/2] AM62: Add support for " Aswath Govindraju
  2 siblings, 1 reply; 11+ messages in thread
From: Aswath Govindraju @ 2022-03-24  7:34 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
controller.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
---

Changes since v1:
- made correction in grammer of clocks property description
  and added maxItems in the interrupts property based on comments
  received from Roger
- corrected the title, fixed the description of
  ti,syscon-phy-pll-refclk, added pattern properties and child node
  in the example based on the comments from Krzysztof.

 .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
 1 file changed, 117 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml

diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
new file mode 100644
index 000000000000..452bfdc6fb09
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
@@ -0,0 +1,117 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
+
+maintainers:
+  - Aswath Govindraju <a-govindraju@ti.com>
+
+properties:
+  compatible:
+    const: ti,am62-usb
+
+  reg:
+    maxItems: 1
+
+  ranges: true
+
+  power-domains:
+    description:
+      PM domain provider node and an args specifier containing
+      the USB ISO device id value. See,
+      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
+    maxItems: 1
+
+  clocks:
+    description: Clock phandle to usb2_refclk
+    maxItems: 1
+
+  clock-names:
+    items:
+      - const: ref
+
+  id-gpio:
+    description:
+      GPIO to be used as ID pin
+    maxItems: 1
+
+  interrupts:
+    description:
+      interrupt line to be used for detecting changes in VBUS
+    maxItems: 1
+
+  ti,vbus-divider:
+    description:
+      Should be present if USB VBUS line is connected to the
+      VBUS pin of the SoC via a 1/3 voltage divider.
+    type: boolean
+
+  ti,syscon-phy-pll-refclk:
+    $ref: /schemas/types.yaml#/definitions/phandle-array
+    items:
+      - items:
+          - description: Phandle to the SYSCON entry
+          - description: USB phy control register offset within SYSCON
+    description:
+      Specifier for conveying frequency of ref clock input, for the
+      operation of USB2PHY.
+
+  '#address-cells':
+    const: 2
+
+  '#size-cells':
+    const: 2
+
+patternProperties:
+  "^usb@[0-9a-f]+$":
+    $ref: snps,dwc3.yaml#
+    description: Required child node
+
+required:
+  - compatible
+  - reg
+  - power-domains
+  - clocks
+  - clock-names
+  - interrupts
+  - ti,syscon-phy-pll-refclk
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/soc/ti,sci_pm_domain.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    #include <dt-bindings/gpio/gpio.h>
+
+    bus {
+      #address-cells = <2>;
+      #size-cells = <2>;
+
+      usbss1: usb@f910000 {
+        compatible = "ti,am62-usb";
+        reg = <0x00 0x0f910000 0x00 0x800>;
+        interrupts = <GIC_SPI 234 IRQ_TYPE_LEVEL_HIGH>; /* MISC IRQ */
+        clocks = <&k3_clks 162 3>;
+        clock-names = "ref";
+        ti,syscon-phy-pll-refclk = <&wkup_conf 0x4018>;
+        power-domains = <&k3_pds 179 TI_SCI_PD_EXCLUSIVE>;
+        id-gpio = <&main_gpio1 51 GPIO_ACTIVE_LOW>;
+        #address-cells = <2>;
+        #size-cells = <2>;
+
+        usb@31100000 {
+          compatible = "snps,dwc3";
+          reg =<0x00 0x31100000 0x00 0x50000>;
+          interrupts = <GIC_SPI 226 IRQ_TYPE_LEVEL_HIGH>, /* irq.0 */
+                       <GIC_SPI 226 IRQ_TYPE_LEVEL_HIGH>; /* irq.0 */
+          interrupt-names = "host", "peripheral";
+          maximum-speed = "high-speed";
+          extcon = <&usbss1>;
+          dr_mode = "otg";
+        };
+      };
+    };
-- 
2.17.1


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

* [PATCH v2 2/2] drivers: usb: dwc3: Add AM62 USB wrapper driver
  2022-03-24  7:34 [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver Aswath Govindraju
  2022-03-24  7:34 ` [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module Aswath Govindraju
@ 2022-03-24  7:34 ` Aswath Govindraju
  2022-04-07  5:32 ` [PATCH v2 0/2] AM62: Add support for " Aswath Govindraju
  2 siblings, 0 replies; 11+ messages in thread
From: Aswath Govindraju @ 2022-03-24  7:34 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I,
	Aswath Govindraju

In AM62 SoC, the Designware Core USB3 IP is progammed to operate in USB2.0
only mode. The ID pin and VBUS state changes are detected in the
wrapper and the role is indicated to the dwc3 core driver using extcon.
Therefore, add driver for AM62 USB DWC3 Wrapper driver.

Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
---

Changes since v1:
- Fixed the error with dev_pm_ops uninitialization. This was 
  reported by kernel test bot.

 drivers/usb/dwc3/Kconfig     |   9 +
 drivers/usb/dwc3/Makefile    |   1 +
 drivers/usb/dwc3/dwc3-am62.c | 581 +++++++++++++++++++++++++++++++++++
 3 files changed, 591 insertions(+)
 create mode 100644 drivers/usb/dwc3/dwc3-am62.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index c483f28b695d..cd9a734522a7 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -159,4 +159,13 @@ config USB_DWC3_XILINX
 	  This driver handles both ZynqMP and Versal SoC operations.
 	  Say 'Y' or 'M' if you have one such device.
 
+config USB_DWC3_AM62
+	tristate "Texas Instruments AM62 Platforms"
+	depends on ARCH_K3 || COMPILE_TEST
+	default USB_DWC3
+	help
+	  Support TI's AM62 platforms with DesignWare Core USB3 IP.
+	  The Designware Core USB3 IP is progammed to operate in
+	  in USB 2.0 mode only.
+	  Say 'Y' or 'M' here if you have one such device
 endif
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 2d499de6f66a..9f66bd82b639 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -42,6 +42,7 @@ endif
 # and allyesconfig builds.
 ##
 
+obj-$(CONFIG_USB_DWC3_AM62)		+= dwc3-am62.o
 obj-$(CONFIG_USB_DWC3_OMAP)		+= dwc3-omap.o
 obj-$(CONFIG_USB_DWC3_EXYNOS)		+= dwc3-exynos.o
 obj-$(CONFIG_USB_DWC3_PCI)		+= dwc3-pci.o
diff --git a/drivers/usb/dwc3/dwc3-am62.c b/drivers/usb/dwc3/dwc3-am62.c
new file mode 100644
index 000000000000..40b5c3bf4b9d
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-am62.c
@@ -0,0 +1,581 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * dwc3-am62.c - TI specific Glue layer for AM62 DWC3 USB Controller
+ *
+ * Copyright (C) 2022 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include <linux/extcon-provider.h>
+#include <linux/gpio/consumer.h>
+#include <linux/init.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/extcon.h>
+#include <linux/workqueue.h>
+#include <linux/mfd/syscon.h>
+#include <linux/of.h>
+#include <linux/of_device.h>
+#include <linux/pm_runtime.h>
+#include <linux/clk.h>
+#include <linux/regmap.h>
+#include <linux/devm-helpers.h>
+#include <linux/pinctrl/consumer.h>
+
+/* USB WRAPPER register offsets */
+#define USBSS_PID			0x0
+#define USBSS_OVERCURRENT_CTRL		0x4
+#define USBSS_PHY_CONFIG		0x8
+#define USBSS_PHY_TEST			0xc
+#define USBSS_CORE_STAT			0x14
+#define USBSS_HOST_VBUS_CTRL		0x18
+#define USBSS_MODE_CONTROL		0x1c
+#define USBSS_WAKEUP_CONFIG		0x30
+#define USBSS_WAKEUP_STAT		0x34
+#define USBSS_OVERRIDE_CONFIG		0x38
+#define USBSS_IRQ_MISC_STATUS_RAW	0x430
+#define USBSS_IRQ_MISC_STATUS		0x434
+#define USBSS_IRQ_MISC_ENABLE_SET	0x438
+#define USBSS_IRQ_MISC_ENABLE_CLR	0x43c
+#define USBSS_IRQ_MISC_EOI		0x440
+#define USBSS_INTR_TEST			0x490
+#define USBSS_VBUS_FILTER		0x614
+#define USBSS_VBUS_STAT			0x618
+#define USBSS_DEBUG_CFG			0x708
+#define USBSS_DEBUG_DATA		0x70c
+#define USBSS_HOST_HUB_CTRL		0x714
+
+/* PHY CONFIG register bits */
+#define USBSS_PHY_VBUS_SEL_MASK		GENMASK(2, 1)
+#define USBSS_PHY_VBUS_SEL_SHIFT	1
+#define USBSS_PHY_LANE_REVERSE		BIT(0)
+
+/* MODE CONTROL register bits */
+#define USBSS_MODE_VALID	BIT(0)
+
+/* WAKEUP CONFIG register bits */
+#define USBSS_WAKEUP_CFG_OVERCURRENT_EN	BIT(3)
+#define USBSS_WAKEUP_CFG_LINESTATE_EN	BIT(2)
+#define USBSS_WAKEUP_CFG_SESSVALID_EN	BIT(1)
+#define USBSS_WAKEUP_CFG_VBUSVALID_EN	BIT(0)
+
+/* WAKEUP STAT register bits */
+#define USBSS_WAKEUP_STAT_OVERCURRENT	BIT(4)
+#define USBSS_WAKEUP_STAT_LINESTATE	BIT(3)
+#define USBSS_WAKEUP_STAT_SESSVALID	BIT(2)
+#define USBSS_WAKEUP_STAT_VBUSVALID	BIT(1)
+#define USBSS_WAKEUP_STAT_CLR		BIT(0)
+
+/* IRQ_MISC_STATUS_RAW register bits */
+#define USBSS_IRQ_MISC_RAW_VBUSVALID	BIT(22)
+#define USBSS_IRQ_MISC_RAW_SESSVALID	BIT(20)
+
+/* IRQ_MISC_STATUS register bits */
+#define USBSS_IRQ_MISC_VBUSVALID	BIT(22)
+#define USBSS_IRQ_MISC_SESSVALID	BIT(20)
+
+/* IRQ_MISC_ENABLE_SET register bits */
+#define USBSS_IRQ_MISC_ENABLE_SET_VBUSVALID	BIT(22)
+#define USBSS_IRQ_MISC_ENABLE_SET_SESSVALID	BIT(20)
+
+/* IRQ_MISC_ENABLE_CLR register bits */
+#define USBSS_IRQ_MISC_ENABLE_CLR_VBUSVALID	BIT(22)
+#define USBSS_IRQ_MISC_ENABLE_CLR_SESSVALID	BIT(20)
+
+/* IRQ_MISC_EOI register bits */
+#define USBSS_IRQ_MISC_EOI_VECTOR	BIT(0)
+
+/* VBUS_STAT register bits */
+#define USBSS_VBUS_STAT_SESSVALID	BIT(2)
+#define USBSS_VBUS_STAT_VBUSVALID	BIT(0)
+
+/* Mask for PHY PLL REFCLK */
+#define PHY_PLL_REFCLK_MASK	GENMASK(3, 0)
+
+#define DWC3_AM62_AUTOSUSPEND_DELAY	100
+
+enum role {
+	DEVICE,
+	HOST,
+};
+
+struct id_gpio_data {
+	struct gpio_desc *gpiod;
+	int id_irq;
+};
+
+struct dwc3_data {
+	struct device *dev;
+	void __iomem *usbss;
+	struct clk *usb2_refclk;
+	struct extcon_dev *edev;
+	unsigned int extcon_id;
+	struct id_gpio_data *id_gpio;
+	struct work_struct work;
+	int vbus_irq;
+	int rate_code;
+	enum role current_role;
+	int connect;
+	struct regmap *syscon;
+	unsigned int offset;
+	unsigned int vbus_divider;
+};
+
+static const int dwc3_ti_rate_table[] = {	/* in KHZ */
+	9600,
+	10000,
+	12000,
+	19200,
+	20000,
+	24000,
+	25000,
+	26000,
+	38400,
+	40000,
+	58000,
+	50000,
+	52000,
+};
+
+static const unsigned int usb_extcon_cable[] = {
+	EXTCON_USB,
+	EXTCON_USB_HOST,
+};
+
+static inline u32 dwc3_ti_readl(struct dwc3_data *data, u32 offset)
+{
+	return readl((data->usbss) + offset);
+}
+
+static inline void dwc3_ti_writel(struct dwc3_data *data, u32 offset, u32 value)
+{
+	writel(value, (data->usbss) + offset);
+}
+
+static void role_detect_work(struct work_struct *work)
+{
+	struct dwc3_data *data =
+		container_of(work, struct dwc3_data, work);
+	u32 vbus_state, reg;
+	int id_state = 0;
+	enum role detect_role;
+	int connect = 0;
+
+	/* Read the status for VBUS valid register */
+	vbus_state = dwc3_ti_readl(data, USBSS_VBUS_STAT);
+	vbus_state = vbus_state & USBSS_VBUS_STAT_VBUSVALID;
+
+	/* Read the status of ID GPIO */
+	if (data->id_gpio)
+		id_state = gpiod_get_value_cansleep(data->id_gpio->gpiod);
+
+	/*
+	 * ID | VBUS | STATE
+	 * -----------------
+	 * 0  | 0    | HOST
+	 * 0  | 1    | HOST
+	 * 1  | 0    | Disconnected (set mode valid to 0)
+	 * 1  | 1    | Device
+	 *
+	 */
+	/* detemine the role or find out if disconnect event */
+	if (id_state) {
+		detect_role = DEVICE;
+		if (vbus_state)
+			connect = 1;
+	} else {
+		detect_role = HOST;
+		connect = 1;
+	}
+
+	/* Set or clear mode valid bit based on connect or disconnect event */
+	if (data->connect != connect) {
+		reg = dwc3_ti_readl(data, USBSS_MODE_CONTROL);
+		if (connect)
+			reg |= USBSS_MODE_VALID;
+		else
+			reg &= ~USBSS_MODE_VALID;
+
+		dwc3_ti_writel(data, USBSS_MODE_CONTROL, reg);
+		data->connect = connect;
+	}
+
+	/* Send extcon sync signal to the dwc3 controller driver */
+	if (data->current_role != detect_role) {
+		if (detect_role == HOST)
+			extcon_set_state_sync(data->edev, EXTCON_USB_HOST, true);
+		else
+			extcon_set_state_sync(data->edev, EXTCON_USB_HOST, false);
+
+		data->current_role = detect_role;
+	}
+}
+
+static irqreturn_t role_detect_irq_handler(int irq, void *dev_id)
+{
+	struct dwc3_data *data = dev_id;
+	u32 reg;
+
+	/* Clear VBUS interrupt always to aviod queuing up redundant work items */
+	reg = dwc3_ti_readl(data, USBSS_IRQ_MISC_STATUS);
+	reg |= USBSS_IRQ_MISC_VBUSVALID;
+	dwc3_ti_writel(data, USBSS_IRQ_MISC_STATUS, reg);
+
+	queue_work(system_power_efficient_wq, &data->work);
+
+	reg = dwc3_ti_readl(data, USBSS_IRQ_MISC_EOI);
+	reg &= ~USBSS_IRQ_MISC_EOI_VECTOR;
+	dwc3_ti_writel(data, USBSS_IRQ_MISC_EOI, reg);
+	return IRQ_HANDLED;
+}
+
+static int dwc3_ti_vbus_irq_setup(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct dwc3_data *data = platform_get_drvdata(pdev);
+	int irq, ret;
+
+	/* Get the misc interrupt */
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0)
+		return irq;
+
+	ret = devm_request_irq(dev, irq, role_detect_irq_handler, IRQF_SHARED,
+			       dev_name(dev), data);
+	if (ret) {
+		dev_err(dev, "failed to required IRQ #%d-->%d\n",
+			irq, ret);
+		return ret;
+	}
+
+	data->vbus_irq = irq;
+
+	return 0;
+}
+
+/* Allocate the memory and register the extcon device */
+static int dwc3_ti_register_extcon(struct dwc3_data *data)
+{
+	int ret;
+
+	data->edev = devm_extcon_dev_allocate(data->dev, usb_extcon_cable);
+	if (IS_ERR(data->edev)) {
+		dev_err(data->dev, "failed to allocate extcon device\n");
+		return -ENOMEM;
+	}
+
+	ret = devm_extcon_dev_register(data->dev, data->edev);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int dwc3_ti_get_id_gpio(struct dwc3_data *data)
+{
+	struct id_gpio_data *id_gpio;
+	struct device	*dev = data->dev;
+	unsigned long irq_flags;
+	int irq, ret;
+
+	/* create the extcon device */
+	id_gpio = devm_kzalloc(dev, sizeof(struct id_gpio_data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	/* Read id-gpio property */
+	id_gpio->gpiod = devm_gpiod_get_optional(dev, "id", GPIOD_IN);
+	if (IS_ERR(id_gpio->gpiod))
+		return PTR_ERR(id_gpio->gpiod);
+
+	/* If id-gpio property is not present */
+	if (!id_gpio->gpiod)
+		return 0;
+
+	irq = gpiod_to_irq(id_gpio->gpiod);
+	if (irq <= 0)
+		return irq;
+	id_gpio->id_irq = irq;
+
+	/* SET irq flags
+	 * Use both edges for detecting connect and disconnect events
+	 */
+	irq_flags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING;
+
+	ret = devm_request_any_context_irq(dev, irq,
+					   role_detect_irq_handler, irq_flags,
+					   "id_gpio", data);
+	if (ret < 0)
+		return ret;
+
+	/* To be enabled only after probing dwc3 core */
+	disable_irq(irq);
+	data->id_gpio = id_gpio;
+	return 0;
+}
+
+static int phy_syscon_pll_refclk(struct dwc3_data *data)
+{
+	struct device *dev = data->dev;
+	struct device_node *node = dev->of_node;
+	struct of_phandle_args args;
+	struct regmap *syscon;
+	int ret;
+
+	syscon = syscon_regmap_lookup_by_phandle(node, "ti,syscon-phy-pll-refclk");
+	if (IS_ERR(syscon)) {
+		dev_err(dev, "unable to get ti,syscon-phy-pll-refclk regmap\n");
+		return PTR_ERR(syscon);
+	}
+
+	data->syscon = syscon;
+
+	ret = of_parse_phandle_with_fixed_args(node, "ti,syscon-phy-pll-refclk", 1,
+					       0, &args);
+	if (ret)
+		return ret;
+
+	data->offset = args.args[0];
+
+	ret = regmap_update_bits(data->syscon, data->offset, PHY_PLL_REFCLK_MASK, data->rate_code);
+	if (ret) {
+		dev_err(dev, "failed to set phy pll reference clock rate\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void dwc3_ti_enable_irqs(struct dwc3_data *data)
+{
+	u32 reg;
+
+	/* enable VBUSVALID interrupt */
+	reg = dwc3_ti_readl(data, USBSS_IRQ_MISC_ENABLE_SET);
+	reg |= USBSS_IRQ_MISC_ENABLE_SET_VBUSVALID;
+	dwc3_ti_writel(data, USBSS_IRQ_MISC_ENABLE_SET, reg);
+
+	/* enable id-gpio interrupt */
+	if (data->id_gpio)
+		enable_irq(data->id_gpio->id_irq);
+}
+
+static void dwc3_ti_disable_irqs(struct dwc3_data *data)
+{
+	u32 reg;
+
+	/* disable VBUSVALID interrupt */
+	reg = dwc3_ti_readl(data, USBSS_IRQ_MISC_ENABLE_CLR);
+	reg |= USBSS_IRQ_MISC_ENABLE_CLR_VBUSVALID;
+	dwc3_ti_writel(data, USBSS_IRQ_MISC_ENABLE_CLR, reg);
+
+	/* disable id-gpio interrupt */
+	if (data->id_gpio)
+		disable_irq(data->id_gpio->id_irq);
+}
+
+static int dwc3_ti_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct device_node *node = pdev->dev.of_node;
+	struct dwc3_data *data;
+	int i, ret;
+	unsigned long rate;
+	u32 reg;
+
+	data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
+	if (!data)
+		return -ENOMEM;
+
+	data->dev = dev;
+	platform_set_drvdata(pdev, data);
+
+	data->usbss = devm_platform_ioremap_resource(pdev, 0);
+	if (IS_ERR(data->usbss)) {
+		dev_err(dev, "can't map IOMEM resource\n");
+		return PTR_ERR(data->usbss);
+	}
+
+	data->usb2_refclk = devm_clk_get(dev, "ref");
+	if (IS_ERR(data->usb2_refclk)) {
+		dev_err(dev, "can't get usb2_refclk\n");
+		return PTR_ERR(data->usb2_refclk);
+	}
+
+	/*Calculate the rate code */
+	rate = clk_get_rate(data->usb2_refclk);
+	rate /= 1000;	// To KHz
+	for (i = 0; i < ARRAY_SIZE(dwc3_ti_rate_table); i++) {
+		if (dwc3_ti_rate_table[i] == rate)
+			break;
+	}
+
+	if (i == ARRAY_SIZE(dwc3_ti_rate_table)) {
+		dev_err(dev, "unsupported usb2_refclk rate: %lu KHz\n", rate);
+		ret = -EINVAL;
+		goto err_clk_disable;
+	}
+
+	data->rate_code = i;
+
+	/* Read the syscon property and set the rate code */
+	ret = phy_syscon_pll_refclk(data);
+	if (ret)
+		goto err_clk_disable;
+
+	/* VBUS divider select */
+	data->vbus_divider = device_property_read_bool(dev, "ti,vbus-divider");
+	reg = dwc3_ti_readl(data, USBSS_PHY_CONFIG);
+	if (data->vbus_divider)
+		reg |= 1 << USBSS_PHY_VBUS_SEL_SHIFT;
+
+	dwc3_ti_writel(data, USBSS_PHY_CONFIG, reg);
+
+	/* Register as an extcon device */
+	ret = dwc3_ti_register_extcon(data);
+	if (ret)
+		goto err_clk_disable;
+
+	/* Initialize a work queue */
+	ret = devm_work_autocancel(dev, &data->work, role_detect_work);
+	if (ret)
+		goto err_clk_disable;
+
+	/* Get struct gpio and irq for ID pin */
+	ret = dwc3_ti_get_id_gpio(data);
+	if (ret) {
+		dev_err(dev, "error reading id-gpio property");
+		goto err_clk_disable;
+	}
+
+	/* Read and set VBUS IRQ */
+	ret = dwc3_ti_vbus_irq_setup(pdev);
+	if (ret)
+		goto err_clk_disable;
+
+	pm_runtime_set_active(dev);
+	pm_runtime_enable(dev);
+	/*
+	 * Don't ignore its dependencies with its children
+	 */
+	pm_suspend_ignore_children(dev, false);
+	clk_prepare_enable(data->usb2_refclk);
+	pm_runtime_get_noresume(dev);
+
+	ret = of_platform_populate(node, NULL, NULL, dev);
+	if (ret) {
+		dev_err(dev, "failed to create dwc3 core: %d\n", ret);
+		goto err_pm_disable;
+	}
+
+	/* Enable gpio and vbus irqs */
+	dwc3_ti_enable_irqs(data);
+
+	role_detect_work(&data->work);
+
+	/* Setting up autosuspend */
+	pm_runtime_set_autosuspend_delay(dev, DWC3_AM62_AUTOSUSPEND_DELAY);
+	pm_runtime_use_autosuspend(dev);
+	pm_runtime_mark_last_busy(dev);
+	pm_runtime_put_autosuspend(dev);
+	return 0;
+
+err_pm_disable:
+	clk_disable_unprepare(data->usb2_refclk);
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+err_clk_disable:
+	clk_put(data->usb2_refclk);
+	return ret;
+}
+
+static int dwc3_ti_remove_core(struct device *dev, void *c)
+{
+	struct platform_device *pdev = to_platform_device(dev);
+
+	platform_device_unregister(pdev);
+	return 0;
+}
+
+static int dwc3_ti_remove(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct dwc3_data *data = platform_get_drvdata(pdev);
+	u32 reg;
+
+	dwc3_ti_disable_irqs(data);
+
+	device_for_each_child(dev, NULL, dwc3_ti_remove_core);
+
+	/* Clear mode valid bit */
+	reg = dwc3_ti_readl(data, USBSS_MODE_CONTROL);
+	reg &= ~USBSS_MODE_VALID;
+	dwc3_ti_writel(data, USBSS_MODE_CONTROL, reg);
+
+	pm_runtime_put_sync(dev);
+	clk_disable_unprepare(data->usb2_refclk);
+	pm_runtime_disable(dev);
+	pm_runtime_set_suspended(dev);
+
+	clk_put(data->usb2_refclk);
+	platform_set_drvdata(pdev, NULL);
+	return 0;
+}
+
+#ifdef CONFIG_PM
+static int dwc3_ti_suspend_common(struct device *dev)
+{
+	struct dwc3_data *data = dev_get_drvdata(dev);
+
+	/* disable irqs */
+	dwc3_ti_disable_irqs(data);
+
+	clk_disable_unprepare(data->usb2_refclk);
+
+	return 0;
+}
+
+static int dwc3_ti_resume_common(struct device *dev)
+{
+	struct dwc3_data *data = dev_get_drvdata(dev);
+
+	clk_prepare_enable(data->usb2_refclk);
+
+	/* Enable irqs */
+	dwc3_ti_enable_irqs(data);
+
+	return 0;
+}
+
+static UNIVERSAL_DEV_PM_OPS(dwc3_ti_pm_ops, dwc3_ti_suspend_common,
+			    dwc3_ti_resume_common, NULL);
+
+#define DEV_PM_OPS	(&dwc3_ti_pm_ops)
+#else
+#define DEV_PM_OPS	NULL
+#endif /* CONFIG_PM */
+
+static const struct of_device_id dwc3_ti_of_match[] = {
+	{ .compatible = "ti,am62-usb"},
+	{},
+};
+MODULE_DEVICE_TABLE(of, dwc3_ti_of_match);
+
+static struct platform_driver dwc3_ti_driver = {
+	.probe		= dwc3_ti_probe,
+	.remove		= dwc3_ti_remove,
+	.driver		= {
+		.name	= "dwc3-am62",
+		.pm	= DEV_PM_OPS,
+		.of_match_table = dwc3_ti_of_match,
+	},
+};
+
+module_platform_driver(dwc3_ti_driver);
+
+MODULE_ALIAS("platform:dwc3-am62");
+MODULE_AUTHOR("Aswath Govindraju <a-govindraju@ti.com>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("DesignWare USB3 TI Glue Layer");
-- 
2.17.1


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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-03-24  7:34 ` [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module Aswath Govindraju
@ 2022-03-24 11:07   ` Krzysztof Kozlowski
  2022-03-24 11:40     ` Aswath Govindraju
  0 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2022-03-24 11:07 UTC (permalink / raw)
  To: Aswath Govindraju
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I

On 24/03/2022 08:34, Aswath Govindraju wrote:
> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
> controller.
> 
> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
> ---
> 
> Changes since v1:
> - made correction in grammer of clocks property description
>   and added maxItems in the interrupts property based on comments
>   received from Roger
> - corrected the title, fixed the description of
>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>   in the example based on the comments from Krzysztof.
> 
>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>  1 file changed, 117 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> 
> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> new file mode 100644
> index 000000000000..452bfdc6fb09
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> @@ -0,0 +1,117 @@
> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
> +
> +maintainers:
> +  - Aswath Govindraju <a-govindraju@ti.com>
> +
> +properties:
> +  compatible:
> +    const: ti,am62-usb
> +
> +  reg:
> +    maxItems: 1
> +
> +  ranges: true
> +
> +  power-domains:
> +    description:
> +      PM domain provider node and an args specifier containing
> +      the USB ISO device id value. See,
> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
> +    maxItems: 1
> +
> +  clocks:
> +    description: Clock phandle to usb2_refclk
> +    maxItems: 1
> +
> +  clock-names:
> +    items:
> +      - const: ref
> +
> +  id-gpio:
> +    description:
> +      GPIO to be used as ID pin
> +    maxItems: 1

I have doubts about this. If you USB controller handles the ID pin, then
probably this should be moved to usb-connector.yaml. I did not see
id-gpio in any other USB controller blocks.


Best regards,
Krzysztof

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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-03-24 11:07   ` Krzysztof Kozlowski
@ 2022-03-24 11:40     ` Aswath Govindraju
  2022-03-24 11:53       ` Krzysztof Kozlowski
  0 siblings, 1 reply; 11+ messages in thread
From: Aswath Govindraju @ 2022-03-24 11:40 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I

Hi Krzysztof,

On 24/03/22 16:37, Krzysztof Kozlowski wrote:
> On 24/03/2022 08:34, Aswath Govindraju wrote:
>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
>> controller.
>>
>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
>> ---
>>
>> Changes since v1:
>> - made correction in grammer of clocks property description
>>   and added maxItems in the interrupts property based on comments
>>   received from Roger
>> - corrected the title, fixed the description of
>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>>   in the example based on the comments from Krzysztof.
>>
>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>>  1 file changed, 117 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>
>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>> new file mode 100644
>> index 000000000000..452bfdc6fb09
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>> @@ -0,0 +1,117 @@
>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>> +%YAML 1.2
>> +---
>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>> +
>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
>> +
>> +maintainers:
>> +  - Aswath Govindraju <a-govindraju@ti.com>
>> +
>> +properties:
>> +  compatible:
>> +    const: ti,am62-usb
>> +
>> +  reg:
>> +    maxItems: 1
>> +
>> +  ranges: true
>> +
>> +  power-domains:
>> +    description:
>> +      PM domain provider node and an args specifier containing
>> +      the USB ISO device id value. See,
>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
>> +    maxItems: 1
>> +
>> +  clocks:
>> +    description: Clock phandle to usb2_refclk
>> +    maxItems: 1
>> +
>> +  clock-names:
>> +    items:
>> +      - const: ref
>> +
>> +  id-gpio:
>> +    description:
>> +      GPIO to be used as ID pin
>> +    maxItems: 1
> 
> I have doubts about this. If you USB controller handles the ID pin, then
> probably this should be moved to usb-connector.yaml. I did not see
> id-gpio in any other USB controller blocks.
> 

Yes, the USB wrapper handles the ID pin operation only. It also reads
the status of VBUS by reading a register from its MMR and not using a
gpio. After evaluating the role the based on the states if id pin and
VBUS, this role is communicated to the dwc3 core driver using extcon.
There is no way for the dwc3 driver to detect the role on its own.


The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
be implemented for driving the VBUS, based on ID and VBUS pin status.
However, in case of the above implementation we need to communicate the
detected role to the dwc3 core driver. Also, the wrapper does not
control VBUS but it is the dwc3 core driver that drives the VBUS.
Therefore, I think the usb-connector implementation cannot be used here.

Thanks,
Aswath

> 
> Best regards,
> Krzysztof


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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-03-24 11:40     ` Aswath Govindraju
@ 2022-03-24 11:53       ` Krzysztof Kozlowski
  2022-04-01  0:20         ` Rob Herring
  0 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2022-03-24 11:53 UTC (permalink / raw)
  To: Aswath Govindraju, Rob Herring
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Greg Kroah-Hartman, Roger Quadros,
	Vignesh Raghavendra, Kishon Vijay Abraham I

On 24/03/2022 12:40, Aswath Govindraju wrote:
> Hi Krzysztof,
> 
> On 24/03/22 16:37, Krzysztof Kozlowski wrote:
>> On 24/03/2022 08:34, Aswath Govindraju wrote:
>>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
>>> controller.
>>>
>>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
>>> ---
>>>
>>> Changes since v1:
>>> - made correction in grammer of clocks property description
>>>   and added maxItems in the interrupts property based on comments
>>>   received from Roger
>>> - corrected the title, fixed the description of
>>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>>>   in the example based on the comments from Krzysztof.
>>>
>>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>>>  1 file changed, 117 insertions(+)
>>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>
>>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>> new file mode 100644
>>> index 000000000000..452bfdc6fb09
>>> --- /dev/null
>>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>> @@ -0,0 +1,117 @@
>>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>>> +%YAML 1.2
>>> +---
>>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>> +
>>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
>>> +
>>> +maintainers:
>>> +  - Aswath Govindraju <a-govindraju@ti.com>
>>> +
>>> +properties:
>>> +  compatible:
>>> +    const: ti,am62-usb
>>> +
>>> +  reg:
>>> +    maxItems: 1
>>> +
>>> +  ranges: true
>>> +
>>> +  power-domains:
>>> +    description:
>>> +      PM domain provider node and an args specifier containing
>>> +      the USB ISO device id value. See,
>>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
>>> +    maxItems: 1
>>> +
>>> +  clocks:
>>> +    description: Clock phandle to usb2_refclk
>>> +    maxItems: 1
>>> +
>>> +  clock-names:
>>> +    items:
>>> +      - const: ref
>>> +
>>> +  id-gpio:
>>> +    description:
>>> +      GPIO to be used as ID pin
>>> +    maxItems: 1
>>
>> I have doubts about this. If you USB controller handles the ID pin, then
>> probably this should be moved to usb-connector.yaml. I did not see
>> id-gpio in any other USB controller blocks.
>>
> 
> Yes, the USB wrapper handles the ID pin operation only. It also reads
> the status of VBUS by reading a register from its MMR and not using a
> gpio. After evaluating the role the based on the states if id pin and
> VBUS, this role is communicated to the dwc3 core driver using extcon.
> There is no way for the dwc3 driver to detect the role on its own.
> 
> 
> The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
> be implemented for driving the VBUS, based on ID and VBUS pin status.
> However, in case of the above implementation we need to communicate the
> detected role to the dwc3 core driver. Also, the wrapper does not
> control VBUS but it is the dwc3 core driver that drives the VBUS.
> Therefore, I think the usb-connector implementation cannot be used here.

I don't think about usb-conn-gpio.c but using the binding generic
binding for usb-X-connector and define a connector with ID.

Actually Rob could help here.

Rob,
Should the id-gpio be modeled as a property in this glue/wrapper driver
or rather as part of usb-connector child node?


Best regards,
Krzysztof

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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-03-24 11:53       ` Krzysztof Kozlowski
@ 2022-04-01  0:20         ` Rob Herring
  2022-04-01  5:04           ` Aswath Govindraju
  0 siblings, 1 reply; 11+ messages in thread
From: Rob Herring @ 2022-04-01  0:20 UTC (permalink / raw)
  To: Krzysztof Kozlowski
  Cc: Aswath Govindraju, linux-kernel, devicetree, linux-usb,
	Felipe Balbi, Krzysztof Kozlowski, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I

On Thu, Mar 24, 2022 at 12:53:08PM +0100, Krzysztof Kozlowski wrote:
> On 24/03/2022 12:40, Aswath Govindraju wrote:
> > Hi Krzysztof,
> > 
> > On 24/03/22 16:37, Krzysztof Kozlowski wrote:
> >> On 24/03/2022 08:34, Aswath Govindraju wrote:
> >>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
> >>> controller.
> >>>
> >>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
> >>> ---
> >>>
> >>> Changes since v1:
> >>> - made correction in grammer of clocks property description
> >>>   and added maxItems in the interrupts property based on comments
> >>>   received from Roger
> >>> - corrected the title, fixed the description of
> >>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
> >>>   in the example based on the comments from Krzysztof.
> >>>
> >>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
> >>>  1 file changed, 117 insertions(+)
> >>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> >>>
> >>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> >>> new file mode 100644
> >>> index 000000000000..452bfdc6fb09
> >>> --- /dev/null
> >>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
> >>> @@ -0,0 +1,117 @@
> >>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
> >>> +%YAML 1.2
> >>> +---
> >>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
> >>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> >>> +
> >>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
> >>> +
> >>> +maintainers:
> >>> +  - Aswath Govindraju <a-govindraju@ti.com>
> >>> +
> >>> +properties:
> >>> +  compatible:
> >>> +    const: ti,am62-usb
> >>> +
> >>> +  reg:
> >>> +    maxItems: 1
> >>> +
> >>> +  ranges: true
> >>> +
> >>> +  power-domains:
> >>> +    description:
> >>> +      PM domain provider node and an args specifier containing
> >>> +      the USB ISO device id value. See,
> >>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
> >>> +    maxItems: 1
> >>> +
> >>> +  clocks:
> >>> +    description: Clock phandle to usb2_refclk
> >>> +    maxItems: 1
> >>> +
> >>> +  clock-names:
> >>> +    items:
> >>> +      - const: ref
> >>> +
> >>> +  id-gpio:
> >>> +    description:
> >>> +      GPIO to be used as ID pin
> >>> +    maxItems: 1
> >>
> >> I have doubts about this. If you USB controller handles the ID pin, then
> >> probably this should be moved to usb-connector.yaml. I did not see
> >> id-gpio in any other USB controller blocks.
> >>
> > 
> > Yes, the USB wrapper handles the ID pin operation only. It also reads
> > the status of VBUS by reading a register from its MMR and not using a
> > gpio. After evaluating the role the based on the states if id pin and
> > VBUS, this role is communicated to the dwc3 core driver using extcon.
> > There is no way for the dwc3 driver to detect the role on its own.
> > 
> > 
> > The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
> > be implemented for driving the VBUS, based on ID and VBUS pin status.
> > However, in case of the above implementation we need to communicate the
> > detected role to the dwc3 core driver. Also, the wrapper does not
> > control VBUS but it is the dwc3 core driver that drives the VBUS.
> > Therefore, I think the usb-connector implementation cannot be used here.
> 
> I don't think about usb-conn-gpio.c but using the binding generic
> binding for usb-X-connector and define a connector with ID.
> 
> Actually Rob could help here.
> 
> Rob,
> Should the id-gpio be modeled as a property in this glue/wrapper driver
> or rather as part of usb-connector child node?

That's a simple question. Where does the ID GPIO signal go to? The 
connector, so it goes in the connector node.

If we have a driver for the usb-connector node, that's news to me. Not 
that we couldn't, but that has nothing to do with designing the binding.

Rob

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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-04-01  0:20         ` Rob Herring
@ 2022-04-01  5:04           ` Aswath Govindraju
  2022-04-01  7:49             ` Krzysztof Kozlowski
  0 siblings, 1 reply; 11+ messages in thread
From: Aswath Govindraju @ 2022-04-01  5:04 UTC (permalink / raw)
  To: Rob Herring, Krzysztof Kozlowski
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Greg Kroah-Hartman, Roger Quadros,
	Vignesh Raghavendra, Kishon Vijay Abraham I

Hi Rob,

On 01/04/22 05:50, Rob Herring wrote:
> On Thu, Mar 24, 2022 at 12:53:08PM +0100, Krzysztof Kozlowski wrote:
>> On 24/03/2022 12:40, Aswath Govindraju wrote:
>>> Hi Krzysztof,
>>>
>>> On 24/03/22 16:37, Krzysztof Kozlowski wrote:
>>>> On 24/03/2022 08:34, Aswath Govindraju wrote:
>>>>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
>>>>> controller.
>>>>>
>>>>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
>>>>> ---
>>>>>
>>>>> Changes since v1:
>>>>> - made correction in grammer of clocks property description
>>>>>   and added maxItems in the interrupts property based on comments
>>>>>   received from Roger
>>>>> - corrected the title, fixed the description of
>>>>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>>>>>   in the example based on the comments from Krzysztof.
>>>>>
>>>>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>>>>>  1 file changed, 117 insertions(+)
>>>>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>
>>>>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>> new file mode 100644
>>>>> index 000000000000..452bfdc6fb09
>>>>> --- /dev/null
>>>>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>> @@ -0,0 +1,117 @@
>>>>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>>>>> +%YAML 1.2
>>>>> +---
>>>>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
>>>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>>>> +
>>>>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
>>>>> +
>>>>> +maintainers:
>>>>> +  - Aswath Govindraju <a-govindraju@ti.com>
>>>>> +
>>>>> +properties:
>>>>> +  compatible:
>>>>> +    const: ti,am62-usb
>>>>> +
>>>>> +  reg:
>>>>> +    maxItems: 1
>>>>> +
>>>>> +  ranges: true
>>>>> +
>>>>> +  power-domains:
>>>>> +    description:
>>>>> +      PM domain provider node and an args specifier containing
>>>>> +      the USB ISO device id value. See,
>>>>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
>>>>> +    maxItems: 1
>>>>> +
>>>>> +  clocks:
>>>>> +    description: Clock phandle to usb2_refclk
>>>>> +    maxItems: 1
>>>>> +
>>>>> +  clock-names:
>>>>> +    items:
>>>>> +      - const: ref
>>>>> +
>>>>> +  id-gpio:
>>>>> +    description:
>>>>> +      GPIO to be used as ID pin
>>>>> +    maxItems: 1
>>>>
>>>> I have doubts about this. If you USB controller handles the ID pin, then
>>>> probably this should be moved to usb-connector.yaml. I did not see
>>>> id-gpio in any other USB controller blocks.
>>>>
>>>
>>> Yes, the USB wrapper handles the ID pin operation only. It also reads
>>> the status of VBUS by reading a register from its MMR and not using a
>>> gpio. After evaluating the role the based on the states if id pin and
>>> VBUS, this role is communicated to the dwc3 core driver using extcon.
>>> There is no way for the dwc3 driver to detect the role on its own.
>>>
>>>
>>> The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
>>> be implemented for driving the VBUS, based on ID and VBUS pin status.
>>> However, in case of the above implementation we need to communicate the
>>> detected role to the dwc3 core driver. Also, the wrapper does not
>>> control VBUS but it is the dwc3 core driver that drives the VBUS.
>>> Therefore, I think the usb-connector implementation cannot be used here.
>>
>> I don't think about usb-conn-gpio.c but using the binding generic
>> binding for usb-X-connector and define a connector with ID.
>>
>> Actually Rob could help here.
>>
>> Rob,
>> Should the id-gpio be modeled as a property in this glue/wrapper driver
>> or rather as part of usb-connector child node?
> 
> That's a simple question. Where does the ID GPIO signal go to? The 
> connector, so it goes in the connector node.
> 

Thank you for the clarification. Here ID-gpio is directly read by the
wrapper and hence, I have modeled it as a property in the wrapper dt
node. May I know if this wrong and should the modelling be looked at
differently?

Thanks,
Aswath

> If we have a driver for the usb-connector node, that's news to me. Not 
> that we couldn't, but that has nothing to do with designing the binding.
> 
> Rob


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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-04-01  5:04           ` Aswath Govindraju
@ 2022-04-01  7:49             ` Krzysztof Kozlowski
  2022-04-01  8:05               ` Aswath Govindraju
  0 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2022-04-01  7:49 UTC (permalink / raw)
  To: Aswath Govindraju, Rob Herring
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Greg Kroah-Hartman, Roger Quadros,
	Vignesh Raghavendra, Kishon Vijay Abraham I

On 01/04/2022 07:04, Aswath Govindraju wrote:
> Hi Rob,
> 
> On 01/04/22 05:50, Rob Herring wrote:
>> On Thu, Mar 24, 2022 at 12:53:08PM +0100, Krzysztof Kozlowski wrote:
>>> On 24/03/2022 12:40, Aswath Govindraju wrote:
>>>> Hi Krzysztof,
>>>>
>>>> On 24/03/22 16:37, Krzysztof Kozlowski wrote:
>>>>> On 24/03/2022 08:34, Aswath Govindraju wrote:
>>>>>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
>>>>>> controller.
>>>>>>
>>>>>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
>>>>>> ---
>>>>>>
>>>>>> Changes since v1:
>>>>>> - made correction in grammer of clocks property description
>>>>>>   and added maxItems in the interrupts property based on comments
>>>>>>   received from Roger
>>>>>> - corrected the title, fixed the description of
>>>>>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>>>>>>   in the example based on the comments from Krzysztof.
>>>>>>
>>>>>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>>>>>>  1 file changed, 117 insertions(+)
>>>>>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>>
>>>>>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>> new file mode 100644
>>>>>> index 000000000000..452bfdc6fb09
>>>>>> --- /dev/null
>>>>>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>> @@ -0,0 +1,117 @@
>>>>>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>>>>>> +%YAML 1.2
>>>>>> +---
>>>>>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
>>>>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>>>>> +
>>>>>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
>>>>>> +
>>>>>> +maintainers:
>>>>>> +  - Aswath Govindraju <a-govindraju@ti.com>
>>>>>> +
>>>>>> +properties:
>>>>>> +  compatible:
>>>>>> +    const: ti,am62-usb
>>>>>> +
>>>>>> +  reg:
>>>>>> +    maxItems: 1
>>>>>> +
>>>>>> +  ranges: true
>>>>>> +
>>>>>> +  power-domains:
>>>>>> +    description:
>>>>>> +      PM domain provider node and an args specifier containing
>>>>>> +      the USB ISO device id value. See,
>>>>>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
>>>>>> +    maxItems: 1
>>>>>> +
>>>>>> +  clocks:
>>>>>> +    description: Clock phandle to usb2_refclk
>>>>>> +    maxItems: 1
>>>>>> +
>>>>>> +  clock-names:
>>>>>> +    items:
>>>>>> +      - const: ref
>>>>>> +
>>>>>> +  id-gpio:
>>>>>> +    description:
>>>>>> +      GPIO to be used as ID pin
>>>>>> +    maxItems: 1
>>>>>
>>>>> I have doubts about this. If you USB controller handles the ID pin, then
>>>>> probably this should be moved to usb-connector.yaml. I did not see
>>>>> id-gpio in any other USB controller blocks.
>>>>>
>>>>
>>>> Yes, the USB wrapper handles the ID pin operation only. It also reads
>>>> the status of VBUS by reading a register from its MMR and not using a
>>>> gpio. After evaluating the role the based on the states if id pin and
>>>> VBUS, this role is communicated to the dwc3 core driver using extcon.
>>>> There is no way for the dwc3 driver to detect the role on its own.
>>>>
>>>>
>>>> The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
>>>> be implemented for driving the VBUS, based on ID and VBUS pin status.
>>>> However, in case of the above implementation we need to communicate the
>>>> detected role to the dwc3 core driver. Also, the wrapper does not
>>>> control VBUS but it is the dwc3 core driver that drives the VBUS.
>>>> Therefore, I think the usb-connector implementation cannot be used here.
>>>
>>> I don't think about usb-conn-gpio.c but using the binding generic
>>> binding for usb-X-connector and define a connector with ID.
>>>
>>> Actually Rob could help here.
>>>
>>> Rob,
>>> Should the id-gpio be modeled as a property in this glue/wrapper driver
>>> or rather as part of usb-connector child node?
>>
>> That's a simple question. Where does the ID GPIO signal go to? The 
>> connector, so it goes in the connector node.
>>
> 
> Thank you for the clarification. Here ID-gpio is directly read by the
> wrapper and hence, I have modeled it as a property in the wrapper dt
> node. May I know if this wrong and should the modelling be looked at
> differently?

What do you mean here by "read"? If you refer to the driver reading the
pin value, it is less related to the hardware, right?


Best regards,
Krzysztof

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

* Re: [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module
  2022-04-01  7:49             ` Krzysztof Kozlowski
@ 2022-04-01  8:05               ` Aswath Govindraju
  0 siblings, 0 replies; 11+ messages in thread
From: Aswath Govindraju @ 2022-04-01  8:05 UTC (permalink / raw)
  To: Krzysztof Kozlowski, Rob Herring
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Greg Kroah-Hartman, Roger Quadros,
	Vignesh Raghavendra, Kishon Vijay Abraham I

Hi Krzysztof, Rob,

On 01/04/22 13:19, Krzysztof Kozlowski wrote:
> On 01/04/2022 07:04, Aswath Govindraju wrote:
>> Hi Rob,
>>
>> On 01/04/22 05:50, Rob Herring wrote:
>>> On Thu, Mar 24, 2022 at 12:53:08PM +0100, Krzysztof Kozlowski wrote:
>>>> On 24/03/2022 12:40, Aswath Govindraju wrote:
>>>>> Hi Krzysztof,
>>>>>
>>>>> On 24/03/22 16:37, Krzysztof Kozlowski wrote:
>>>>>> On 24/03/2022 08:34, Aswath Govindraju wrote:
>>>>>>> Add bindings for the TI's AM62 wrapper module for the Synopsys USBSS-DRD
>>>>>>> controller.
>>>>>>>
>>>>>>> Signed-off-by: Aswath Govindraju <a-govindraju@ti.com>
>>>>>>> ---
>>>>>>>
>>>>>>> Changes since v1:
>>>>>>> - made correction in grammer of clocks property description
>>>>>>>   and added maxItems in the interrupts property based on comments
>>>>>>>   received from Roger
>>>>>>> - corrected the title, fixed the description of
>>>>>>>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>>>>>>>   in the example based on the comments from Krzysztof.
>>>>>>>
>>>>>>>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++++++++++++++++
>>>>>>>  1 file changed, 117 insertions(+)
>>>>>>>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>>>
>>>>>>> diff --git a/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>>> new file mode 100644
>>>>>>> index 000000000000..452bfdc6fb09
>>>>>>> --- /dev/null
>>>>>>> +++ b/Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>>>>>>> @@ -0,0 +1,117 @@
>>>>>>> +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
>>>>>>> +%YAML 1.2
>>>>>>> +---
>>>>>>> +$id: http://devicetree.org/schemas/usb/ti,am62-usb.yaml#
>>>>>>> +$schema: http://devicetree.org/meta-schemas/core.yaml#
>>>>>>> +
>>>>>>> +title: TI's AM62 wrapper module for the Synopsys USBSS-DRD controller
>>>>>>> +
>>>>>>> +maintainers:
>>>>>>> +  - Aswath Govindraju <a-govindraju@ti.com>
>>>>>>> +
>>>>>>> +properties:
>>>>>>> +  compatible:
>>>>>>> +    const: ti,am62-usb
>>>>>>> +
>>>>>>> +  reg:
>>>>>>> +    maxItems: 1
>>>>>>> +
>>>>>>> +  ranges: true
>>>>>>> +
>>>>>>> +  power-domains:
>>>>>>> +    description:
>>>>>>> +      PM domain provider node and an args specifier containing
>>>>>>> +      the USB ISO device id value. See,
>>>>>>> +      Documentation/devicetree/bindings/soc/ti/sci-pm-domain.yaml
>>>>>>> +    maxItems: 1
>>>>>>> +
>>>>>>> +  clocks:
>>>>>>> +    description: Clock phandle to usb2_refclk
>>>>>>> +    maxItems: 1
>>>>>>> +
>>>>>>> +  clock-names:
>>>>>>> +    items:
>>>>>>> +      - const: ref
>>>>>>> +
>>>>>>> +  id-gpio:
>>>>>>> +    description:
>>>>>>> +      GPIO to be used as ID pin
>>>>>>> +    maxItems: 1
>>>>>>
>>>>>> I have doubts about this. If you USB controller handles the ID pin, then
>>>>>> probably this should be moved to usb-connector.yaml. I did not see
>>>>>> id-gpio in any other USB controller blocks.
>>>>>>
>>>>>
>>>>> Yes, the USB wrapper handles the ID pin operation only. It also reads
>>>>> the status of VBUS by reading a register from its MMR and not using a
>>>>> gpio. After evaluating the role the based on the states if id pin and
>>>>> VBUS, this role is communicated to the dwc3 core driver using extcon.
>>>>> There is no way for the dwc3 driver to detect the role on its own.
>>>>>
>>>>>
>>>>> The usb-connector(drivers/usb/common/usb-conn-gpio.c) driver, seems to
>>>>> be implemented for driving the VBUS, based on ID and VBUS pin status.
>>>>> However, in case of the above implementation we need to communicate the
>>>>> detected role to the dwc3 core driver. Also, the wrapper does not
>>>>> control VBUS but it is the dwc3 core driver that drives the VBUS.
>>>>> Therefore, I think the usb-connector implementation cannot be used here.
>>>>
>>>> I don't think about usb-conn-gpio.c but using the binding generic
>>>> binding for usb-X-connector and define a connector with ID.
>>>>
>>>> Actually Rob could help here.
>>>>
>>>> Rob,
>>>> Should the id-gpio be modeled as a property in this glue/wrapper driver
>>>> or rather as part of usb-connector child node?
>>>
>>> That's a simple question. Where does the ID GPIO signal go to? The 
>>> connector, so it goes in the connector node.
>>>
>>
>> Thank you for the clarification. Here ID-gpio is directly read by the
>> wrapper and hence, I have modeled it as a property in the wrapper dt
>> node. May I know if this wrong and should the modelling be looked at
>> differently?
> 
> What do you mean here by "read"? If you refer to the driver reading the
> pin value, it is less related to the hardware, right?
> 
> 

Thank you for clarification. Now I understood, I was looking at it in
the wrong way and when looking at in in terms hardware I understood the
mistake that I have been doing. So, the id-gpio is actually not an
inherent part of the wrapper but rather something that it gets from the
connector. So, there needs to be different node describing this.

Thanks,
Aswath

> Best regards,
> Krzysztof



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

* Re: [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver
  2022-03-24  7:34 [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver Aswath Govindraju
  2022-03-24  7:34 ` [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module Aswath Govindraju
  2022-03-24  7:34 ` [PATCH v2 2/2] drivers: usb: dwc3: Add AM62 USB wrapper driver Aswath Govindraju
@ 2022-04-07  5:32 ` Aswath Govindraju
  2 siblings, 0 replies; 11+ messages in thread
From: Aswath Govindraju @ 2022-04-07  5:32 UTC (permalink / raw)
  Cc: linux-kernel, devicetree, linux-usb, Felipe Balbi,
	Krzysztof Kozlowski, Rob Herring, Greg Kroah-Hartman,
	Roger Quadros, Vignesh Raghavendra, Kishon Vijay Abraham I

Hi All,

On 24/03/22 13:04, Aswath Govindraju wrote:
> The following series of patches add support for AM62 USB wrapper driver
> and its corresponding bindings.
> 
> changes since v1:
> - Fixed the error with dev_pm_ops uninitialization, in patch 2.
>   This was reported by kernel test bot
> - In patch 1, made correction in grammer of clocks property description
>   and added maxItems in the interrupts property based on comments
>   received from Roger
> - In patch 1, corrected the title, fixed the description of
>   ti,syscon-phy-pll-refclk, added pattern properties and child node
>   in the example based on the comments from Krzysztof.
> 

Thank you for all the review and comments. I have posted respin(v3) for
this patch series. Here is the link to the series

https://patchwork.kernel.org/project/linux-usb/list/?series=629613

Regards,
Aswath

> Aswath Govindraju (2):
>   dt-bindings: usb: Add documentation for AM62 USB Wrapper module
>   drivers: usb: dwc3: Add AM62 USB wrapper driver
> 
>  .../devicetree/bindings/usb/ti,am62-usb.yaml  | 117 ++++
>  drivers/usb/dwc3/Kconfig                      |   9 +
>  drivers/usb/dwc3/Makefile                     |   1 +
>  drivers/usb/dwc3/dwc3-am62.c                  | 581 ++++++++++++++++++
>  4 files changed, 708 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/ti,am62-usb.yaml
>  create mode 100644 drivers/usb/dwc3/dwc3-am62.c
> 

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

end of thread, other threads:[~2022-04-07  5:32 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-24  7:34 [PATCH v2 0/2] AM62: Add support for AM62 USB wrapper driver Aswath Govindraju
2022-03-24  7:34 ` [PATCH v2 1/2] dt-bindings: usb: Add documentation for AM62 USB Wrapper module Aswath Govindraju
2022-03-24 11:07   ` Krzysztof Kozlowski
2022-03-24 11:40     ` Aswath Govindraju
2022-03-24 11:53       ` Krzysztof Kozlowski
2022-04-01  0:20         ` Rob Herring
2022-04-01  5:04           ` Aswath Govindraju
2022-04-01  7:49             ` Krzysztof Kozlowski
2022-04-01  8:05               ` Aswath Govindraju
2022-03-24  7:34 ` [PATCH v2 2/2] drivers: usb: dwc3: Add AM62 USB wrapper driver Aswath Govindraju
2022-04-07  5:32 ` [PATCH v2 0/2] AM62: Add support for " Aswath Govindraju

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).