LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH v1 0/3] USB PHY driver for Broadcom's Cygnus chipse
@ 2015-03-20 21:25 Arun Ramamurthy
  2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
                   ` (2 more replies)
  0 siblings, 3 replies; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-20 21:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Arun Ramamurthy

This patchset adds the USB phy driver and documentation 
for Broadom's Cygnus chipset. The phy is configurable from device tree
and is capable of both device and host functions. It also provides
a clock and reset to the host controller

History:
v1:
    - Included Dmitry Torokhov's patch that addresed Kishon Vijay Abraham's 
    comments on multiple phy model
    - Inlucded Dmitry Torokhov's patch to use phy regulator
    - Addressed Arnd Bergmann's comments on usage of this phy driver by
    ehci-platform and ohci-platform driver in a separate patchset. 

Arun Ramamurthy (3):
  phy: phy-core: allow specifying supply at port level
  Phy: DT binding documentation for Broadcom Cygnus USB PHY driver
  phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver

 .../bindings/phy/brcm,cygnus-usb-phy.txt           |  65 +++
 drivers/phy/Kconfig                                |  12 +
 drivers/phy/Makefile                               |   1 +
 drivers/phy/phy-bcm-cygnus-usb.c                   | 499 +++++++++++++++++++++
 drivers/phy/phy-core.c                             |  30 +-
 5 files changed, 597 insertions(+), 10 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
 create mode 100644 drivers/phy/phy-bcm-cygnus-usb.c

-- 
2.3.2


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

* [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-20 21:25 [PATCH v1 0/3] USB PHY driver for Broadcom's Cygnus chipse Arun Ramamurthy
@ 2015-03-20 21:25 ` Arun Ramamurthy
  2015-03-20 21:31   ` Dmitry Torokhov
  2015-03-25 22:11   ` Kishon Vijay Abraham I
  2015-03-20 21:25 ` [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver Arun Ramamurthy
  2015-03-20 21:25 ` [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver Arun Ramamurthy
  2 siblings, 2 replies; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-20 21:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Arun Ramamurthy, Dmitry Torokhov

Multi-port phy's may have per-port power supplies. Let's change phy core
to first attempt to look up the supply at the port level, and then, if
not found, check parent device.

Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
---
 drivers/phy/phy-core.c | 30 ++++++++++++++++++++----------
 1 file changed, 20 insertions(+), 10 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a12d353..b43bb6b 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -650,16 +650,6 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
 		goto free_phy;
 	}
 
-	/* phy-supply */
-	phy->pwr = regulator_get_optional(dev, "phy");
-	if (IS_ERR(phy->pwr)) {
-		if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) {
-			ret = -EPROBE_DEFER;
-			goto free_ida;
-		}
-		phy->pwr = NULL;
-	}
-
 	device_initialize(&phy->dev);
 	mutex_init(&phy->mutex);
 
@@ -673,6 +663,26 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
 	if (ret)
 		goto put_dev;
 
+	/*
+	 * Locate phy-supply. We first try individual port and then,
+	 * if supply is not found, try parent device.
+	 */
+	phy->pwr = regulator_get_optional(&phy->dev, "phy");
+	if (IS_ERR(phy->pwr)) {
+		ret = PTR_ERR(phy->pwr);
+		if (ret == -EPROBE_DEFER)
+			goto free_ida;
+
+		phy->pwr = regulator_get_optional(phy->dev.parent, "phy");
+		if (IS_ERR(phy->pwr)) {
+			ret = PTR_ERR(phy->pwr);
+			if (ret == -EPROBE_DEFER)
+				goto free_ida;
+
+			phy->pwr = NULL;
+		}
+	}
+
 	ret = device_add(&phy->dev);
 	if (ret)
 		goto put_dev;
-- 
2.3.2


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

* [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver
  2015-03-20 21:25 [PATCH v1 0/3] USB PHY driver for Broadcom's Cygnus chipse Arun Ramamurthy
  2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
@ 2015-03-20 21:25 ` Arun Ramamurthy
  2015-03-25 22:16   ` Kishon Vijay Abraham I
  2015-03-20 21:25 ` [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver Arun Ramamurthy
  2 siblings, 1 reply; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-20 21:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Arun Ramamurthy

Broadcom's Cygnus chip has a USB 2.0 host controller connected to
three separate phys. One of the phs (port 2) is also connectd to
a usb 2.0 device controller

Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>

---
 .../bindings/phy/brcm,cygnus-usb-phy.txt           | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt

diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
new file mode 100644
index 0000000..002bd59
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
@@ -0,0 +1,65 @@
+BROADCOM CYGNUS USB PHY
+
+Required Properties:
+	- compatible:  brcm,cygnus-usb-phy
+	- reg : usbphy_regs - Base address of phy registers
+			usb2h_idm_regs - Base address of host idm registers
+			usb2d_idm_regs - Base address of device idm registers
+The node that uses the phy must provide one integers, 0 for device and 1 for host
+
+NOTE: port 0 and port 1 are host only and port 2 can be configured for host or device.
+
+Example of phy :
+	usbphy0: usbphy@0x0301c000 {
+		compatible = "brcm,cygnus-usb-phy";
+		reg = <0x0301c000 0x2000>,
+		      <0x18115000 0x1000>,
+		      <0x18111000 0x1000>;
+		status = "okay";
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+		usbphy0_0: usbphy0@0 {
+			#phy-cells = <1>;
+			reg = <0>;
+			status = "okay";
+			phy-supply = <&vbus_p0>;
+		};
+
+		usbphy0_1: usbphy0@1 {
+			#phy-cells = <1>;
+			reg = <1>;
+			status = "okay";
+		};
+
+		usbphy0_2: usbphy0@2 {
+			#phy-cells = <1>;
+			reg = <2>;
+			status = "okay";
+			phy-supply = <&vbus_p2>;
+		};
+	};
+
+Example of node using the phy:
+
+	/* This nodes declares all three ports as host */
+	
+	ehci0: usb@0x18048000 {
+		compatible = "generic-ehci";
+		reg = <0x18048000 0x100>;
+		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
+		phys = <&usbphy0_0 1 &usbphy0_1 1 &usbphy0_2 1>;
+		phy-names = "usb","usb","usb";
+		status = "okay";
+	};
+
+	/* This node declares port 2 phy
+	and configures it for device */
+
+	usbd_udc_dwc1: usbd_udc_dwc@0x1804c000 {
+		compatible = "iproc-udc";
+		reg = <0x1804c000 0x2000>;
+		interrupts = <GIC_SPI 123 IRQ_TYPE_LEVEL_HIGH>;
+		phys = <&usbphy0_2 0>;
+		phy-names = "usb";
+	};
-- 
2.3.2


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

* [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-20 21:25 [PATCH v1 0/3] USB PHY driver for Broadcom's Cygnus chipse Arun Ramamurthy
  2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
  2015-03-20 21:25 ` [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver Arun Ramamurthy
@ 2015-03-20 21:25 ` Arun Ramamurthy
  2015-03-25 22:28   ` Kishon Vijay Abraham I
  2 siblings, 1 reply; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-20 21:25 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Arun Ramamurthy, Dmitry Torokhov

This driver adds support for USB 2.0 host and device phy for
Broadcom's Cygnus chipset. The host controller is connected to
three separate phys and one of the phys (port 2) is connected to
the device controller


Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
Reviewed-by: Ray Jui <rjui@broadcom.com>
Reviewed-by: Scott Branden <sbranden@broadcom.com>
---
 drivers/phy/Kconfig              |  12 +
 drivers/phy/Makefile             |   1 +
 drivers/phy/phy-bcm-cygnus-usb.c | 499 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 512 insertions(+)
 create mode 100644 drivers/phy/phy-bcm-cygnus-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 2962de2..0aa62dc 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -291,4 +291,16 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_BCM_CYGNUS_USB
+	tristate "Broadcom Cygnus USB PHY support"
+	depends on OF
+	depends on ARCH_BCM_CYGNUS || COMPILE_TEST
+	select GENERIC_PHY
+	default ARCH_BCM_CYGNUS
+	help
+	  Enable this to support the USB PHY in Broadcom's Cygnus chip.
+	  The phys are capable of supporting host mode for all ports
+	  and device mode for port 2. The host or device configuration is
+	  read from the device tree.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index f080e1b..47a37fa 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -6,6 +6,7 @@ obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
 obj-$(CONFIG_PHY_BERLIN_USB)		+= phy-berlin-usb.o
 obj-$(CONFIG_PHY_BERLIN_SATA)		+= phy-berlin-sata.o
 obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY)	+= phy-armada375-usb2.o
+obj-$(CONFIG_PHY_BCM_CYGNUS_USB)	+= phy-bcm-cygnus-usb.o
 obj-$(CONFIG_BCM_KONA_USB2_PHY)		+= phy-bcm-kona-usb2.o
 obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO)	+= phy-exynos-dp-video.o
 obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO)	+= phy-exynos-mipi-video.o
diff --git a/drivers/phy/phy-bcm-cygnus-usb.c b/drivers/phy/phy-bcm-cygnus-usb.c
new file mode 100644
index 0000000..c12918e
--- /dev/null
+++ b/drivers/phy/phy-bcm-cygnus-usb.c
@@ -0,0 +1,499 @@
+/*
+ * Copyright (C) 2015 Broadcom Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/module.h>
+#include <linux/platform_device.h>
+#include <linux/io.h>
+#include <linux/of.h>
+#include <linux/of_address.h>
+#include <linux/phy/phy.h>
+#include <linux/delay.h>
+
+#define CDRU_USBPHY_CLK_RST_SEL_OFFSET			0x11b4
+#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET		0x11b8
+#define CDRU_SPARE_REG_0_OFFSET				0x1238
+#define CRMU_USB_PHY_AON_CTRL_OFFSET			0x00028
+#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET		0x1210
+#define CDRU_USBPHY_P0_STATUS_OFFSET			0x11D0
+#define CDRU_USBPHY_P1_STATUS_OFFSET			0x11E8
+#define CDRU_USBPHY_P2_STATUS_OFFSET			0x1200
+#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG			1
+#define CDRU_USBPHY_USBPHY_PLL_LOCK			0
+#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE	0
+#define PHY2_DEV_HOST_CTRL_SEL_HOST			1
+
+#define CRMU_USBPHY_P0_AFE_CORERDY_VDDC			1
+#define CRMU_USBPHY_P0_RESETB				2
+#define CRMU_USBPHY_P1_AFE_CORERDY_VDDC			9
+#define CRMU_USBPHY_P1_RESETB				10
+#define CRMU_USBPHY_P2_AFE_CORERDY_VDDC			17
+#define CRMU_USBPHY_P2_RESETB				18
+
+#define USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET		0x0408
+#define USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable	0
+#define USB2_IDM_IDM_RESET_CONTROL_OFFSET		0x0800
+#define USB2_IDM_IDM_RESET_CONTROL__RESET		0
+
+#define PLL_LOCK_RETRY_COUNT	1000
+#define MAX_PHY_PORTS		3
+
+static int power_bit[] = {CRMU_USBPHY_P0_AFE_CORERDY_VDDC,
+				CRMU_USBPHY_P1_AFE_CORERDY_VDDC,
+				CRMU_USBPHY_P2_AFE_CORERDY_VDDC};
+static int reset_bit[] = {CRMU_USBPHY_P0_RESETB,
+				CRMU_USBPHY_P1_RESETB,
+				CRMU_USBPHY_P2_RESETB};
+static int status_reg[] = {CDRU_USBPHY_P0_STATUS_OFFSET,
+				CDRU_USBPHY_P1_STATUS_OFFSET,
+				CDRU_USBPHY_P2_STATUS_OFFSET};
+
+struct bcm_phy_instance;
+
+struct bcm_phy_driver {
+	void __iomem *usbphy_regs;
+	void __iomem *usb2h_idm_regs;
+	void __iomem *usb2d_idm_regs;
+	struct bcm_phy_instance *ports[MAX_PHY_PORTS];
+	spinlock_t lock;
+	bool idm_host_enabled;
+};
+
+struct bcm_phy_instance {
+	struct bcm_phy_driver *driver;
+	struct phy *generic_phy;
+	int port_no;
+	bool host_mode; /* true - Host, false - device */
+	bool power;
+};
+
+static inline int cdru_usbphy_status_wait(u32 usb_reg, int reg_bit,
+					  struct bcm_phy_driver *phy_driver)
+{
+	/* Wait for the PLL lock status */
+	int retry = PLL_LOCK_RETRY_COUNT;
+	u32 reg_val;
+
+	do {
+		udelay(1);
+		reg_val = readl(phy_driver->usbphy_regs +
+				usb_reg);
+		if (reg_val & (1 << reg_bit))
+			return 0;
+	} while (--retry > 0);
+
+	return -EBUSY;
+
+}
+
+static struct phy *bcm_usb_phy_xlate(struct device *dev,
+				     struct of_phandle_args *args)
+{
+	struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
+	struct bcm_phy_instance *port = NULL;
+	int i;
+
+	if (!phy_driver)
+		return ERR_PTR(-EINVAL);
+
+	if (WARN_ON(args->args_count != 1))
+		return ERR_PTR(-EINVAL);
+
+	if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
+		return ERR_PTR(-EINVAL);
+
+	for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
+		struct bcm_phy_instance *p = phy_driver->ports[i];
+
+		if (p && p->generic_phy->dev.of_node == args->np) {
+			port = p;
+			break;
+		}
+	}
+
+	if (!port) {
+		dev_err(dev, "Failed to locate phy %s\n", args->np->name);
+		return ERR_PTR(-EINVAL);
+	}
+
+	port->host_mode = args->args[0];
+
+	return port->generic_phy;
+}
+
+static int bcm_phy_init(struct phy *generic_phy)
+{
+	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
+	struct bcm_phy_driver *phy_driver = port->driver;
+	unsigned long flags;
+	u32 reg_val;
+
+	spin_lock_irqsave(&phy_driver->lock, flags);
+
+	/*
+	 * Only PORT 2 is capable of being device and host
+	 * Default setting is device, check if it is set to host.
+	 */
+	if (port->port_no == 2) {
+		if (port->host_mode) {
+			writel(PHY2_DEV_HOST_CTRL_SEL_HOST,
+				phy_driver->usbphy_regs +
+				CDRU_USBPHY2_HOST_DEV_SEL_OFFSET);
+		} else {
+			/*
+			 * Disable suspend/resume signals to device controller
+			 * when a port is in device mode.
+			 */
+			reg_val = readl(phy_driver->usbphy_regs +
+				      CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET);
+			reg_val |=
+				1 << CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE;
+			writel(reg_val, phy_driver->usbphy_regs +
+			       CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET);
+		}
+	}
+
+	spin_unlock_irqrestore(&phy_driver->lock, flags);
+	return 0;
+}
+
+static int bcm_phy_shutdown(struct phy *generic_phy)
+{
+	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
+	struct bcm_phy_driver *phy_driver = port->driver;
+	unsigned long flags;
+	int i;
+	u32 reg_val, powered_on_phy;
+	bool power_off_flag = true;
+
+	spin_lock_irqsave(&phy_driver->lock, flags);
+
+	/* power down the phy */
+	reg_val = readl(phy_driver->usbphy_regs +
+			CRMU_USB_PHY_AON_CTRL_OFFSET);
+	reg_val &= ~(1 << power_bit[port->port_no]);
+	reg_val &= ~(1 << reset_bit[port->port_no]);
+	writel(reg_val, phy_driver->usbphy_regs +
+		CRMU_USB_PHY_AON_CTRL_OFFSET);
+	port->power = false;
+
+	/*
+	 * If a port is configured to device and it is being shutdown,
+	 * turn off the clocks to the usb device controller.
+	 */
+	if (port->port_no == 2 && !port->host_mode) {
+		reg_val = readl(phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+		reg_val &= ~(1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable);
+		writel(reg_val, phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+
+		reg_val = readl(phy_driver->usb2d_idm_regs +
+				 USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+		reg_val |= 1 << USB2_IDM_IDM_RESET_CONTROL__RESET;
+		writel(reg_val, phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+	} else {
+		/*
+		 * If the phy being shutdown provides clock and reset to
+		 * the host controller, change it do a different powered on phy
+		 * If all phys are powered off, shut of the host controller
+		 */
+		reg_val = readl(phy_driver->usbphy_regs +
+				CDRU_USBPHY_CLK_RST_SEL_OFFSET);
+		powered_on_phy = reg_val;
+		if (reg_val == port->port_no) {
+			for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
+				if (phy_driver->ports[i] &&
+				    phy_driver->ports[i]->power &&
+				    phy_driver->ports[i]->host_mode) {
+					power_off_flag = false;
+					powered_on_phy = i;
+				}
+			}
+		}
+
+		if (power_off_flag) {
+			/*
+			 * Put the host controller into reset state and
+			 * disable clock.
+			 */
+			reg_val = readl(phy_driver->usb2h_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+			reg_val &=
+			  ~(1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable);
+			writel(reg_val, phy_driver->usb2h_idm_regs +
+					USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+
+			reg_val = readl(phy_driver->usb2h_idm_regs +
+					 USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+			reg_val |= (1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
+			writel(reg_val, phy_driver->usb2h_idm_regs +
+					USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+			phy_driver->idm_host_enabled = 0;
+		} else {
+			writel(powered_on_phy, phy_driver->usbphy_regs +
+				   CDRU_USBPHY_CLK_RST_SEL_OFFSET);
+		}
+	}
+
+	spin_unlock_irqrestore(&phy_driver->lock, flags);
+
+	return 0;
+}
+
+static int bcm_phy_poweron(struct phy *generic_phy)
+{
+	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
+	struct bcm_phy_driver *phy_driver = port->driver;
+	unsigned long flags;
+	int ret;
+	u32 reg_val;
+	bool clock_reset_flag = true;
+
+	spin_lock_irqsave(&phy_driver->lock, flags);
+
+	/* Bring the AFE block out of reset to start powering up the PHY */
+	reg_val = readl(phy_driver->usbphy_regs + CRMU_USB_PHY_AON_CTRL_OFFSET);
+	reg_val |= 1 << power_bit[port->port_no];
+	writel(reg_val, phy_driver->usbphy_regs + CRMU_USB_PHY_AON_CTRL_OFFSET);
+
+	/* Check for power on and PLL lock */
+	ret = cdru_usbphy_status_wait(status_reg[port->port_no],
+		   CDRU_USBPHY_USBPHY_ILDO_ON_FLAG, phy_driver);
+	if (ret < 0) {
+		dev_err(&generic_phy->dev,
+			"Timed out waiting for USBPHY_ILDO_ON_FLAG on port %d",
+			port->port_no);
+		goto err_shutdown;
+	}
+	ret = cdru_usbphy_status_wait(status_reg[port->port_no],
+		CDRU_USBPHY_USBPHY_PLL_LOCK, phy_driver);
+	if (ret < 0) {
+		dev_err(&generic_phy->dev,
+			"Timed out waiting for USBPHY_PLL_LOCK on port %d",
+			port->port_no);
+		goto err_shutdown;
+	}
+	port->power = true;
+
+	/* Check if the port 2 is configured for device */
+	if (port->port_no == 2 && !port->host_mode) {
+		/*
+		 * Enable clock to USB device and get the USB device
+		 * out of reset.
+		 */
+		reg_val = readl(phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+		reg_val |= 1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable;
+		writel(reg_val, phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+
+		reg_val = readl(phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+		reg_val &= ~(1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
+		writel(reg_val, phy_driver->usb2d_idm_regs +
+				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+
+	} else {
+		reg_val = readl(phy_driver->usbphy_regs +
+				CDRU_USBPHY_CLK_RST_SEL_OFFSET);
+
+		/*
+		 * Check if the phy that is configured to provide clock
+		 * and reset is powered on.
+		 */
+		if (reg_val >= 0 && reg_val < ARRAY_SIZE(phy_driver->ports))
+			if (phy_driver->ports[reg_val])
+				if (phy_driver->ports[reg_val]->power)
+					clock_reset_flag = false;
+
+		/* if not set the current phy */
+		if (clock_reset_flag) {
+			reg_val = port->port_no;
+			writel(reg_val, phy_driver->usbphy_regs +
+			       CDRU_USBPHY_CLK_RST_SEL_OFFSET);
+		}
+	}
+
+	if (!phy_driver->idm_host_enabled) {
+		/* Enable clock to USB and get the USB out of reset */
+		reg_val = readl(phy_driver->usb2h_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+		reg_val |= 1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable;
+		writel(reg_val, phy_driver->usb2h_idm_regs +
+				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
+
+		reg_val = readl(phy_driver->usb2h_idm_regs +
+				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+		reg_val &= ~(1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
+		writel(reg_val, phy_driver->usb2h_idm_regs +
+				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
+		phy_driver->idm_host_enabled = true;
+	}
+
+	spin_unlock_irqrestore(&phy_driver->lock, flags);
+	return 0;
+
+err_shutdown:
+	spin_unlock_irqrestore(&phy_driver->lock, flags);
+	bcm_phy_shutdown(generic_phy);
+	return ret;
+}
+
+static struct phy_ops ops = {
+	.init		= bcm_phy_init,
+	.power_on	= bcm_phy_poweron,
+	.power_off	= bcm_phy_shutdown,
+};
+
+static const struct of_device_id bcm_phy_dt_ids[] = {
+	{ .compatible = "brcm,cygnus-usb-phy", },
+	{ }
+};
+
+static int bcm_phy_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct bcm_phy_driver *phy_driver;
+	struct phy_provider *phy_provider;
+	struct device_node *child;
+	struct resource res;
+	int error;
+	u32 reg_val;
+
+	phy_driver = devm_kzalloc(dev, sizeof(struct bcm_phy_driver),
+				  GFP_KERNEL);
+	if (!phy_driver)
+		return -ENOMEM;
+
+	spin_lock_init(&phy_driver->lock);
+
+	error = of_address_to_resource(dev->of_node, 0, &res);
+	if (error) {
+		dev_err(dev, "Failed to obtain device tree resource usbphy_regs\n");
+		return error;
+	}
+
+	phy_driver->usbphy_regs = devm_ioremap_nocache(dev, res.start,
+						resource_size(&res));
+	if (!phy_driver->usbphy_regs) {
+		dev_err(dev, "Failed to remap usbphy_regs\n");
+		return -ENOMEM;
+	}
+
+	error = of_address_to_resource(dev->of_node, 1, &res);
+	if (error) {
+		dev_err(dev, "Failed to obtain device tree resource usb2h_idm_regs\n");
+		return error;
+	}
+
+	phy_driver->usb2h_idm_regs = devm_ioremap_nocache(dev, res.start,
+						  resource_size(&res));
+	if (!phy_driver->usb2h_idm_regs) {
+		dev_err(dev, "Failed to remap usb2h_idm_regs\n");
+		return -ENOMEM;
+	}
+
+	error = of_address_to_resource(dev->of_node, 2, &res);
+	if (error) {
+		dev_err(dev, "Failed to obtain device tree resource usb2d_idm_regs\n");
+		return error;
+	}
+
+	phy_driver->usb2d_idm_regs = devm_ioremap_nocache(dev, res.start,
+						   resource_size(&res));
+	if (!phy_driver->usb2d_idm_regs) {
+		dev_err(dev, "Failed to remap usb2d_idm_regs\n");
+		return -ENOMEM;
+	}
+
+	dev_set_drvdata(dev, phy_driver);
+
+	phy_driver->idm_host_enabled = false;
+
+	/* Shut down all ports. They can be powered up as required */
+	reg_val = readl(phy_driver->usbphy_regs +
+			CRMU_USB_PHY_AON_CTRL_OFFSET);
+	reg_val &= ~(1 << CRMU_USBPHY_P0_AFE_CORERDY_VDDC);
+	reg_val &= ~(1 << CRMU_USBPHY_P0_RESETB);
+	reg_val &= ~(1 << CRMU_USBPHY_P1_AFE_CORERDY_VDDC);
+	reg_val &= ~(1 << CRMU_USBPHY_P1_RESETB);
+	reg_val &= ~(1 << CRMU_USBPHY_P2_AFE_CORERDY_VDDC);
+	reg_val &= ~(1 << CRMU_USBPHY_P2_RESETB);
+	writel(reg_val, phy_driver->usbphy_regs +
+		CRMU_USB_PHY_AON_CTRL_OFFSET);
+
+	for_each_available_child_of_node(dev->of_node, child) {
+		struct bcm_phy_instance *port;
+		u32 port_no;
+
+		if (of_property_read_u32(child, "reg", &port_no)) {
+			dev_err(dev, "missing reg property in node %s\n",
+				child->name);
+			return -EINVAL;
+		}
+
+		if (port_no >= ARRAY_SIZE(phy_driver->ports)) {
+			dev_err(dev, "invalid reg in node %s: %u\n",
+				child->name, port_no);
+			return -EINVAL;
+		}
+
+		port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL);
+		if (!port)
+			return -ENOMEM;
+
+		port->generic_phy = devm_phy_create(dev, child, &ops);
+		if (IS_ERR(port->generic_phy)) {
+			error = PTR_ERR(port->generic_phy);
+			dev_err(dev, "Failed to create phy %u: %d",
+				port_no, error);
+			return error;
+		}
+
+		port->port_no = port_no;
+		port->driver = phy_driver;
+		phy_set_drvdata(port->generic_phy, port);
+
+		phy_driver->ports[port_no] = port;
+	}
+
+	phy_provider = devm_of_phy_provider_register(dev, bcm_usb_phy_xlate);
+	if (IS_ERR(phy_provider)) {
+		error = PTR_ERR(phy_provider);
+		dev_err(dev, "Failed to register as phy provider: %d\n",
+			error);
+		return error;
+	}
+
+	platform_set_drvdata(pdev, phy_driver);
+
+	return 0;
+
+}
+
+MODULE_DEVICE_TABLE(of, bcm_phy_dt_ids);
+
+static struct platform_driver bcm_phy_driver = {
+	.probe = bcm_phy_probe,
+	.driver = {
+		.name = "bcm-cygnus-usbphy",
+		.of_match_table = of_match_ptr(bcm_phy_dt_ids),
+	},
+};
+module_platform_driver(bcm_phy_driver);
+
+MODULE_ALIAS("platform:bcm-cygnus-usbphy");
+MODULE_AUTHOR("Broadcom");
+MODULE_DESCRIPTION("Broadcom Cygnus USB PHY driver");
+MODULE_LICENSE("GPL v2");
-- 
2.3.2


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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
@ 2015-03-20 21:31   ` Dmitry Torokhov
  2015-03-25 22:11   ` Kishon Vijay Abraham I
  1 sibling, 0 replies; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-20 21:31 UTC (permalink / raw)
  To: Arun Ramamurthy
  Cc: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

Hi Arun,

On Fri, Mar 20, 2015 at 02:25:25PM -0700, Arun Ramamurthy wrote:
> Multi-port phy's may have per-port power supplies. Let's change phy core
> to first attempt to look up the supply at the port level, and then, if
> not found, check parent device.
> 
> Reviewed-by: Ray Jui <rjui@broadcom.com>
> Reviewed-by: Scott Branden <sbranden@broadcom.com>
> Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
> Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
>

This should have had:

From: Dmitry Torokhov <dtor@chromium.org>

as first line of the body of e-mail as the patch was authored by me.

Thanks.

 ---
>  drivers/phy/phy-core.c | 30 ++++++++++++++++++++----------
>  1 file changed, 20 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index a12d353..b43bb6b 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -650,16 +650,6 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
>  		goto free_phy;
>  	}
>  
> -	/* phy-supply */
> -	phy->pwr = regulator_get_optional(dev, "phy");
> -	if (IS_ERR(phy->pwr)) {
> -		if (PTR_ERR(phy->pwr) == -EPROBE_DEFER) {
> -			ret = -EPROBE_DEFER;
> -			goto free_ida;
> -		}
> -		phy->pwr = NULL;
> -	}
> -
>  	device_initialize(&phy->dev);
>  	mutex_init(&phy->mutex);
>  
> @@ -673,6 +663,26 @@ struct phy *phy_create(struct device *dev, struct device_node *node,
>  	if (ret)
>  		goto put_dev;
>  
> +	/*
> +	 * Locate phy-supply. We first try individual port and then,
> +	 * if supply is not found, try parent device.
> +	 */
> +	phy->pwr = regulator_get_optional(&phy->dev, "phy");
> +	if (IS_ERR(phy->pwr)) {
> +		ret = PTR_ERR(phy->pwr);
> +		if (ret == -EPROBE_DEFER)
> +			goto free_ida;
> +
> +		phy->pwr = regulator_get_optional(phy->dev.parent, "phy");
> +		if (IS_ERR(phy->pwr)) {
> +			ret = PTR_ERR(phy->pwr);
> +			if (ret == -EPROBE_DEFER)
> +				goto free_ida;
> +
> +			phy->pwr = NULL;
> +		}
> +	}
> +
>  	ret = device_add(&phy->dev);
>  	if (ret)
>  		goto put_dev;
> -- 
> 2.3.2
> 

-- 
Dmitry

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
  2015-03-20 21:31   ` Dmitry Torokhov
@ 2015-03-25 22:11   ` Kishon Vijay Abraham I
  2015-03-25 22:17     ` Dmitry Torokhov
  1 sibling, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-25 22:11 UTC (permalink / raw)
  To: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Dmitry Torokhov

Hi,

On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> Multi-port phy's may have per-port power supplies. Let's change phy core
> to first attempt to look up the supply at the port level, and then, if
> not found, check parent device.

Why not just have every port provide the power supply if it needs?
I don't think checking for parent device should be present in the phy-core at
all.

Thanks
Kishon

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

* Re: [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver
  2015-03-20 21:25 ` [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver Arun Ramamurthy
@ 2015-03-25 22:16   ` Kishon Vijay Abraham I
  2015-03-26  0:04     ` Arun Ramamurthy
  0 siblings, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-25 22:16 UTC (permalink / raw)
  To: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui

Hi,

On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> Broadcom's Cygnus chip has a USB 2.0 host controller connected to
> three separate phys. One of the phs (port 2) is also connectd to
> a usb 2.0 device controller
> 
> Reviewed-by: Ray Jui <rjui@broadcom.com>
> Reviewed-by: Scott Branden <sbranden@broadcom.com>
> Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
> 
> ---
>  .../bindings/phy/brcm,cygnus-usb-phy.txt           | 65 ++++++++++++++++++++++
>  1 file changed, 65 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> 
> diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> new file mode 100644
> index 0000000..002bd59
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> @@ -0,0 +1,65 @@
> +BROADCOM CYGNUS USB PHY
> +
> +Required Properties:
> +	- compatible:  brcm,cygnus-usb-phy
> +	- reg : usbphy_regs - Base address of phy registers
> +			usb2h_idm_regs - Base address of host idm registers
> +			usb2d_idm_regs - Base address of device idm registers

where is #phy-cells documented?
> +The node that uses the phy must provide one integers, 0 for device and 1 for host

> +
> +NOTE: port 0 and port 1 are host only and port 2 can be configured for host or device.
> +
> +Example of phy :
> +	usbphy0: usbphy@0x0301c000 {
> +		compatible = "brcm,cygnus-usb-phy";
> +		reg = <0x0301c000 0x2000>,
> +		      <0x18115000 0x1000>,
> +		      <0x18111000 0x1000>;
> +		status = "okay";
> +
> +		#address-cells = <1>;
> +		#size-cells = <0>;
> +		usbphy0_0: usbphy0@0 {
> +			#phy-cells = <1>;
> +			reg = <0>;
> +			status = "okay";
> +			phy-supply = <&vbus_p0>;
> +		};
> +
> +		usbphy0_1: usbphy0@1 {
> +			#phy-cells = <1>;
> +			reg = <1>;
> +			status = "okay";
> +		};
> +
> +		usbphy0_2: usbphy0@2 {
> +			#phy-cells = <1>;
> +			reg = <2>;
> +			status = "okay";
> +			phy-supply = <&vbus_p2>;
> +		};
> +	};
> +
> +Example of node using the phy:
> +
> +	/* This nodes declares all three ports as host */
> +	
> +	ehci0: usb@0x18048000 {
> +		compatible = "generic-ehci";
> +		reg = <0x18048000 0x100>;
> +		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
> +		phys = <&usbphy0_0 1 &usbphy0_1 1 &usbphy0_2 1>;
> +		phy-names = "usb","usb","usb";

is it on purpose you use the same name for phy-names? it is wrong though.
> +		status = "okay";
> +	};
> +
> +	/* This node declares port 2 phy
> +	and configures it for device */

please use standard multi-line comment format.

Thanks
Kishon

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-25 22:11   ` Kishon Vijay Abraham I
@ 2015-03-25 22:17     ` Dmitry Torokhov
  2015-03-25 22:39       ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-25 22:17 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui,
	Dmitry Torokhov

On Wed, Mar 25, 2015 at 3:11 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
> Hi,
>
> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>> Multi-port phy's may have per-port power supplies. Let's change phy core
>> to first attempt to look up the supply at the port level, and then, if
>> not found, check parent device.
>
> Why not just have every port provide the power supply if it needs?
> I don't think checking for parent device should be present in the phy-core at
> all.

We need to do that if we want to keep compatibility with the current
DTSes: before this patch the supply would be always looked up on
device and not port level.

Thanks,
Dmitry

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

* Re: [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-20 21:25 ` [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver Arun Ramamurthy
@ 2015-03-25 22:28   ` Kishon Vijay Abraham I
  2015-03-25 22:42     ` Dmitry Torokhov
  0 siblings, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-25 22:28 UTC (permalink / raw)
  To: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui, Dmitry Torokhov

Hi,

On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> This driver adds support for USB 2.0 host and device phy for
> Broadcom's Cygnus chipset. The host controller is connected to
> three separate phys and one of the phys (port 2) is connected to
> the device controller
> 
> 
one blank line should suffice..
> Signed-off-by: Dmitry Torokhov <dtor@chromium.org>
> Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
> Reviewed-by: Ray Jui <rjui@broadcom.com>
> Reviewed-by: Scott Branden <sbranden@broadcom.com>
> ---
>  drivers/phy/Kconfig              |  12 +
>  drivers/phy/Makefile             |   1 +
>  drivers/phy/phy-bcm-cygnus-usb.c | 499 +++++++++++++++++++++++++++++++++++++++
>  3 files changed, 512 insertions(+)
>  create mode 100644 drivers/phy/phy-bcm-cygnus-usb.c
> 
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 2962de2..0aa62dc 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -291,4 +291,16 @@ config PHY_QCOM_UFS
>  	help
>  	  Support for UFS PHY on QCOM chipsets.
>  
> +config PHY_BCM_CYGNUS_USB
> +	tristate "Broadcom Cygnus USB PHY support"
> +	depends on OF
> +	depends on ARCH_BCM_CYGNUS || COMPILE_TEST
> +	select GENERIC_PHY
> +	default ARCH_BCM_CYGNUS
> +	help
> +	  Enable this to support the USB PHY in Broadcom's Cygnus chip.
> +	  The phys are capable of supporting host mode for all ports
> +	  and device mode for port 2. The host or device configuration is
> +	  read from the device tree.
> +
>  endmenu
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index f080e1b..47a37fa 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -6,6 +6,7 @@ obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
>  obj-$(CONFIG_PHY_BERLIN_USB)		+= phy-berlin-usb.o
>  obj-$(CONFIG_PHY_BERLIN_SATA)		+= phy-berlin-sata.o
>  obj-$(CONFIG_ARMADA375_USBCLUSTER_PHY)	+= phy-armada375-usb2.o
> +obj-$(CONFIG_PHY_BCM_CYGNUS_USB)	+= phy-bcm-cygnus-usb.o
>  obj-$(CONFIG_BCM_KONA_USB2_PHY)		+= phy-bcm-kona-usb2.o
>  obj-$(CONFIG_PHY_EXYNOS_DP_VIDEO)	+= phy-exynos-dp-video.o
>  obj-$(CONFIG_PHY_EXYNOS_MIPI_VIDEO)	+= phy-exynos-mipi-video.o
> diff --git a/drivers/phy/phy-bcm-cygnus-usb.c b/drivers/phy/phy-bcm-cygnus-usb.c
> new file mode 100644
> index 0000000..c12918e
> --- /dev/null
> +++ b/drivers/phy/phy-bcm-cygnus-usb.c
> @@ -0,0 +1,499 @@
> +/*
> + * Copyright (C) 2015 Broadcom Corporation
> + *
> + * This program is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU General Public License as
> + * published by the Free Software Foundation version 2.
> + *
> + * This program is distributed "as is" WITHOUT ANY WARRANTY of any
> + * kind, whether express or implied; without even the implied warranty
> + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + */
> +
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
> +#include <linux/io.h>
> +#include <linux/of.h>
> +#include <linux/of_address.h>
> +#include <linux/phy/phy.h>
> +#include <linux/delay.h>
> +
> +#define CDRU_USBPHY_CLK_RST_SEL_OFFSET			0x11b4
> +#define CDRU_USBPHY2_HOST_DEV_SEL_OFFSET		0x11b8
> +#define CDRU_SPARE_REG_0_OFFSET				0x1238
> +#define CRMU_USB_PHY_AON_CTRL_OFFSET			0x00028
> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET		0x1210
> +#define CDRU_USBPHY_P0_STATUS_OFFSET			0x11D0
> +#define CDRU_USBPHY_P1_STATUS_OFFSET			0x11E8
> +#define CDRU_USBPHY_P2_STATUS_OFFSET			0x1200
> +#define CDRU_USBPHY_USBPHY_ILDO_ON_FLAG			1
> +#define CDRU_USBPHY_USBPHY_PLL_LOCK			0
> +#define CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE	0
> +#define PHY2_DEV_HOST_CTRL_SEL_HOST			1
> +
> +#define CRMU_USBPHY_P0_AFE_CORERDY_VDDC			1
> +#define CRMU_USBPHY_P0_RESETB				2
> +#define CRMU_USBPHY_P1_AFE_CORERDY_VDDC			9
> +#define CRMU_USBPHY_P1_RESETB				10
> +#define CRMU_USBPHY_P2_AFE_CORERDY_VDDC			17
> +#define CRMU_USBPHY_P2_RESETB				18
> +
> +#define USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET		0x0408
> +#define USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable	0
> +#define USB2_IDM_IDM_RESET_CONTROL_OFFSET		0x0800
> +#define USB2_IDM_IDM_RESET_CONTROL__RESET		0
> +
> +#define PLL_LOCK_RETRY_COUNT	1000
> +#define MAX_PHY_PORTS		3
> +
> +static int power_bit[] = {CRMU_USBPHY_P0_AFE_CORERDY_VDDC,
> +				CRMU_USBPHY_P1_AFE_CORERDY_VDDC,
> +				CRMU_USBPHY_P2_AFE_CORERDY_VDDC};
> +static int reset_bit[] = {CRMU_USBPHY_P0_RESETB,
> +				CRMU_USBPHY_P1_RESETB,
> +				CRMU_USBPHY_P2_RESETB};
> +static int status_reg[] = {CDRU_USBPHY_P0_STATUS_OFFSET,
> +				CDRU_USBPHY_P1_STATUS_OFFSET,
> +				CDRU_USBPHY_P2_STATUS_OFFSET};
> +
> +struct bcm_phy_instance;

just declare bcm_phy_instance here..
> +
> +struct bcm_phy_driver {
> +	void __iomem *usbphy_regs;
> +	void __iomem *usb2h_idm_regs;
> +	void __iomem *usb2d_idm_regs;
> +	struct bcm_phy_instance *ports[MAX_PHY_PORTS];

er.. can't we allocate this dynamically?
> +	spinlock_t lock;
> +	bool idm_host_enabled;
> +};
> +
> +struct bcm_phy_instance {
> +	struct bcm_phy_driver *driver;
> +	struct phy *generic_phy;
> +	int port_no;
> +	bool host_mode; /* true - Host, false - device */
> +	bool power;
> +};
> +
> +static inline int cdru_usbphy_status_wait(u32 usb_reg, int reg_bit,
> +					  struct bcm_phy_driver *phy_driver)

please use a consistent prefix for all the functions in this driver..
> +{
> +	/* Wait for the PLL lock status */
> +	int retry = PLL_LOCK_RETRY_COUNT;
> +	u32 reg_val;
> +
> +	do {
> +		udelay(1);
> +		reg_val = readl(phy_driver->usbphy_regs +
> +				usb_reg);
> +		if (reg_val & (1 << reg_bit))
> +			return 0;
> +	} while (--retry > 0);

dev_err here?
> +
> +	return -EBUSY;
> +
> +}
> +
> +static struct phy *bcm_usb_phy_xlate(struct device *dev,
> +				     struct of_phandle_args *args)
> +{
> +	struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
> +	struct bcm_phy_instance *port = NULL;
> +	int i;
> +
> +	if (!phy_driver)
> +		return ERR_PTR(-EINVAL);
> +
> +	if (WARN_ON(args->args_count != 1))
> +		return ERR_PTR(-EINVAL);
> +
> +	if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
> +		return ERR_PTR(-EINVAL);
> +
> +	for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
> +		struct bcm_phy_instance *p = phy_driver->ports[i];
> +
> +		if (p && p->generic_phy->dev.of_node == args->np) {
> +			port = p;
> +			break;
> +		}
> +	}
> +
> +	if (!port) {
> +		dev_err(dev, "Failed to locate phy %s\n", args->np->name);
> +		return ERR_PTR(-EINVAL);
> +	}
> +
> +	port->host_mode = args->args[0];
> +
> +	return port->generic_phy;
> +}

The xlate function here shouldn't be needed at all. Use of_phy_simple_xlate
instead.
> +
> +static int bcm_phy_init(struct phy *generic_phy)
> +{
> +	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
> +	struct bcm_phy_driver *phy_driver = port->driver;
> +	unsigned long flags;
> +	u32 reg_val;
> +
> +	spin_lock_irqsave(&phy_driver->lock, flags);
> +
> +	/*
> +	 * Only PORT 2 is capable of being device and host
> +	 * Default setting is device, check if it is set to host.
> +	 */
> +	if (port->port_no == 2) {
> +		if (port->host_mode) {
> +			writel(PHY2_DEV_HOST_CTRL_SEL_HOST,
> +				phy_driver->usbphy_regs +
> +				CDRU_USBPHY2_HOST_DEV_SEL_OFFSET);
> +		} else {
> +			/*
> +			 * Disable suspend/resume signals to device controller
> +			 * when a port is in device mode.
> +			 */
> +			reg_val = readl(phy_driver->usbphy_regs +
> +				      CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET);
> +			reg_val |=
> +				1 << CDRU_USB_DEV_SUSPEND_RESUME_CTRL_DISABLE;
> +			writel(reg_val, phy_driver->usbphy_regs +
> +			       CDRU_USB_DEV_SUSPEND_RESUME_CTRL_OFFSET);
> +		}
> +	}
> +
> +	spin_unlock_irqrestore(&phy_driver->lock, flags);
> +	return 0;
> +}
> +
> +static int bcm_phy_shutdown(struct phy *generic_phy)
> +{
> +	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
> +	struct bcm_phy_driver *phy_driver = port->driver;
> +	unsigned long flags;
> +	int i;
> +	u32 reg_val, powered_on_phy;
> +	bool power_off_flag = true;
> +
> +	spin_lock_irqsave(&phy_driver->lock, flags);
> +
> +	/* power down the phy */
> +	reg_val = readl(phy_driver->usbphy_regs +
> +			CRMU_USB_PHY_AON_CTRL_OFFSET);
> +	reg_val &= ~(1 << power_bit[port->port_no]);
> +	reg_val &= ~(1 << reset_bit[port->port_no]);
> +	writel(reg_val, phy_driver->usbphy_regs +
> +		CRMU_USB_PHY_AON_CTRL_OFFSET);
> +	port->power = false;
> +
> +	/*
> +	 * If a port is configured to device and it is being shutdown,
> +	 * turn off the clocks to the usb device controller.
> +	 */
> +	if (port->port_no == 2 && !port->host_mode) {
> +		reg_val = readl(phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +		reg_val &= ~(1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable);
> +		writel(reg_val, phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +
> +		reg_val = readl(phy_driver->usb2d_idm_regs +
> +				 USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +		reg_val |= 1 << USB2_IDM_IDM_RESET_CONTROL__RESET;
> +		writel(reg_val, phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +	} else {
> +		/*
> +		 * If the phy being shutdown provides clock and reset to
> +		 * the host controller, change it do a different powered on phy
> +		 * If all phys are powered off, shut of the host controller
> +		 */
> +		reg_val = readl(phy_driver->usbphy_regs +
> +				CDRU_USBPHY_CLK_RST_SEL_OFFSET);
> +		powered_on_phy = reg_val;
> +		if (reg_val == port->port_no) {
> +			for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
> +				if (phy_driver->ports[i] &&
> +				    phy_driver->ports[i]->power &&
> +				    phy_driver->ports[i]->host_mode) {
> +					power_off_flag = false;
> +					powered_on_phy = i;
> +				}
> +			}
> +		}
> +
> +		if (power_off_flag) {
> +			/*
> +			 * Put the host controller into reset state and
> +			 * disable clock.
> +			 */
> +			reg_val = readl(phy_driver->usb2h_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +			reg_val &=
> +			  ~(1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable);
> +			writel(reg_val, phy_driver->usb2h_idm_regs +
> +					USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +
> +			reg_val = readl(phy_driver->usb2h_idm_regs +
> +					 USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +			reg_val |= (1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
> +			writel(reg_val, phy_driver->usb2h_idm_regs +
> +					USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +			phy_driver->idm_host_enabled = 0;
> +		} else {
> +			writel(powered_on_phy, phy_driver->usbphy_regs +
> +				   CDRU_USBPHY_CLK_RST_SEL_OFFSET);
> +		}
> +	}
> +
> +	spin_unlock_irqrestore(&phy_driver->lock, flags);
> +
> +	return 0;
> +}
> +
> +static int bcm_phy_poweron(struct phy *generic_phy)
> +{
> +	struct bcm_phy_instance *port = phy_get_drvdata(generic_phy);
> +	struct bcm_phy_driver *phy_driver = port->driver;
> +	unsigned long flags;
> +	int ret;
> +	u32 reg_val;
> +	bool clock_reset_flag = true;
> +
> +	spin_lock_irqsave(&phy_driver->lock, flags);
> +
> +	/* Bring the AFE block out of reset to start powering up the PHY */
> +	reg_val = readl(phy_driver->usbphy_regs + CRMU_USB_PHY_AON_CTRL_OFFSET);
> +	reg_val |= 1 << power_bit[port->port_no];
> +	writel(reg_val, phy_driver->usbphy_regs + CRMU_USB_PHY_AON_CTRL_OFFSET);
> +
> +	/* Check for power on and PLL lock */
> +	ret = cdru_usbphy_status_wait(status_reg[port->port_no],
> +		   CDRU_USBPHY_USBPHY_ILDO_ON_FLAG, phy_driver);
> +	if (ret < 0) {
> +		dev_err(&generic_phy->dev,
> +			"Timed out waiting for USBPHY_ILDO_ON_FLAG on port %d",
> +			port->port_no);
> +		goto err_shutdown;
> +	}
> +	ret = cdru_usbphy_status_wait(status_reg[port->port_no],
> +		CDRU_USBPHY_USBPHY_PLL_LOCK, phy_driver);
> +	if (ret < 0) {
> +		dev_err(&generic_phy->dev,
> +			"Timed out waiting for USBPHY_PLL_LOCK on port %d",
> +			port->port_no);
> +		goto err_shutdown;
> +	}
> +	port->power = true;
> +
> +	/* Check if the port 2 is configured for device */
> +	if (port->port_no == 2 && !port->host_mode) {
> +		/*
> +		 * Enable clock to USB device and get the USB device
> +		 * out of reset.
> +		 */
> +		reg_val = readl(phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +		reg_val |= 1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable;
> +		writel(reg_val, phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +
> +		reg_val = readl(phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +		reg_val &= ~(1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
> +		writel(reg_val, phy_driver->usb2d_idm_regs +
> +				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +
> +	} else {
> +		reg_val = readl(phy_driver->usbphy_regs +
> +				CDRU_USBPHY_CLK_RST_SEL_OFFSET);
> +
> +		/*
> +		 * Check if the phy that is configured to provide clock
> +		 * and reset is powered on.
> +		 */
> +		if (reg_val >= 0 && reg_val < ARRAY_SIZE(phy_driver->ports))
> +			if (phy_driver->ports[reg_val])
> +				if (phy_driver->ports[reg_val]->power)
> +					clock_reset_flag = false;
> +
> +		/* if not set the current phy */
> +		if (clock_reset_flag) {
> +			reg_val = port->port_no;
> +			writel(reg_val, phy_driver->usbphy_regs +
> +			       CDRU_USBPHY_CLK_RST_SEL_OFFSET);
> +		}
> +	}
> +
> +	if (!phy_driver->idm_host_enabled) {
> +		/* Enable clock to USB and get the USB out of reset */
> +		reg_val = readl(phy_driver->usb2h_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +		reg_val |= 1 << USB2_IDM_IDM_IO_CONTROL_DIRECT__clk_enable;
> +		writel(reg_val, phy_driver->usb2h_idm_regs +
> +				USB2_IDM_IDM_IO_CONTROL_DIRECT_OFFSET);
> +
> +		reg_val = readl(phy_driver->usb2h_idm_regs +
> +				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +		reg_val &= ~(1 << USB2_IDM_IDM_RESET_CONTROL__RESET);
> +		writel(reg_val, phy_driver->usb2h_idm_regs +
> +				USB2_IDM_IDM_RESET_CONTROL_OFFSET);
> +		phy_driver->idm_host_enabled = true;
> +	}
> +
> +	spin_unlock_irqrestore(&phy_driver->lock, flags);
> +	return 0;
> +
> +err_shutdown:
> +	spin_unlock_irqrestore(&phy_driver->lock, flags);
> +	bcm_phy_shutdown(generic_phy);
> +	return ret;
> +}
> +
> +static struct phy_ops ops = {
> +	.init		= bcm_phy_init,
> +	.power_on	= bcm_phy_poweron,
> +	.power_off	= bcm_phy_shutdown,
> +};
> +
> +static const struct of_device_id bcm_phy_dt_ids[] = {
> +	{ .compatible = "brcm,cygnus-usb-phy", },
> +	{ }
> +};
> +
> +static int bcm_phy_probe(struct platform_device *pdev)
> +{
> +	struct device *dev = &pdev->dev;
> +	struct bcm_phy_driver *phy_driver;
> +	struct phy_provider *phy_provider;
> +	struct device_node *child;
> +	struct resource res;
> +	int error;
> +	u32 reg_val;
> +
> +	phy_driver = devm_kzalloc(dev, sizeof(struct bcm_phy_driver),
> +				  GFP_KERNEL);
> +	if (!phy_driver)
> +		return -ENOMEM;
> +
> +	spin_lock_init(&phy_driver->lock);
> +
> +	error = of_address_to_resource(dev->of_node, 0, &res);

why not platform_get_resource?
> +	if (error) {
> +		dev_err(dev, "Failed to obtain device tree resource usbphy_regs\n");
> +		return error;
> +	}
> +
> +	phy_driver->usbphy_regs = devm_ioremap_nocache(dev, res.start,
> +						resource_size(&res));
> +	if (!phy_driver->usbphy_regs) {
> +		dev_err(dev, "Failed to remap usbphy_regs\n");
> +		return -ENOMEM;
> +	}
> +
> +	error = of_address_to_resource(dev->of_node, 1, &res);

same here..
> +	if (error) {
> +		dev_err(dev, "Failed to obtain device tree resource usb2h_idm_regs\n");
> +		return error;
> +	}
> +
> +	phy_driver->usb2h_idm_regs = devm_ioremap_nocache(dev, res.start,
> +						  resource_size(&res));
> +	if (!phy_driver->usb2h_idm_regs) {
> +		dev_err(dev, "Failed to remap usb2h_idm_regs\n");
> +		return -ENOMEM;
> +	}
> +
> +	error = of_address_to_resource(dev->of_node, 2, &res);
same here..

Thanks
Kishon

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-25 22:17     ` Dmitry Torokhov
@ 2015-03-25 22:39       ` Kishon Vijay Abraham I
  2015-03-25 22:49         ` Dmitry Torokhov
  0 siblings, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-25 22:39 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui,
	Dmitry Torokhov

Hi,

On Thursday 26 March 2015 03:47 AM, Dmitry Torokhov wrote:
> On Wed, Mar 25, 2015 at 3:11 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>> Hi,
>>
>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>>> Multi-port phy's may have per-port power supplies. Let's change phy core
>>> to first attempt to look up the supply at the port level, and then, if
>>> not found, check parent device.
>>
>> Why not just have every port provide the power supply if it needs?
>> I don't think checking for parent device should be present in the phy-core at
>> all.
> 
> We need to do that if we want to keep compatibility with the current
> DTSes: before this patch the supply would be always looked up on
> device and not port level.

ah okay.
so just using regulator_get_optional(&phy->dev, "phy"); should be sufficient
right? Why do we need regulator_get_optional(phy->dev.parent, "phy");?

Thanks
Kishon

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

* Re: [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-25 22:28   ` Kishon Vijay Abraham I
@ 2015-03-25 22:42     ` Dmitry Torokhov
  2015-03-26  0:01       ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-25 22:42 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

Hi Kishon,

On Thu, Mar 26, 2015 at 03:58:50AM +0530, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> > +struct bcm_phy_driver {
> > +	void __iomem *usbphy_regs;
> > +	void __iomem *usb2h_idm_regs;
> > +	void __iomem *usb2d_idm_regs;
> > +	struct bcm_phy_instance *ports[MAX_PHY_PORTS];
> 
> er.. can't we allocate this dynamically?

The chip has support for only 3 phys, so I believe allocating array of 3
pointers is simplest.

[...]

> > +
> > +static struct phy *bcm_usb_phy_xlate(struct device *dev,
> > +				     struct of_phandle_args *args)
> > +{
> > +	struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
> > +	struct bcm_phy_instance *port = NULL;
> > +	int i;
> > +
> > +	if (!phy_driver)
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	if (WARN_ON(args->args_count != 1))
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
> > +		return ERR_PTR(-EINVAL);
> > +
> > +	for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
> > +		struct bcm_phy_instance *p = phy_driver->ports[i];
> > +
> > +		if (p && p->generic_phy->dev.of_node == args->np) {
> > +			port = p;
> > +			break;
> > +		}
> > +	}
> > +
> > +	if (!port) {
> > +		dev_err(dev, "Failed to locate phy %s\n", args->np->name);
> > +		return ERR_PTR(-EINVAL);
> > +	}
> > +
> > +	port->host_mode = args->args[0];
> > +
> > +	return port->generic_phy;
> > +}
> 
> The xlate function here shouldn't be needed at all. Use of_phy_simple_xlate
> instead.

of_phy_simple_xlate() will not allow specifying host vs device mode when
requesting phy though...

Thanks.

-- 
Dmitry

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-25 22:39       ` Kishon Vijay Abraham I
@ 2015-03-25 22:49         ` Dmitry Torokhov
  2015-03-25 23:44           ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-25 22:49 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

On Thu, Mar 26, 2015 at 04:09:23AM +0530, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Thursday 26 March 2015 03:47 AM, Dmitry Torokhov wrote:
> > On Wed, Mar 25, 2015 at 3:11 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
> >> Hi,
> >>
> >> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> >>> Multi-port phy's may have per-port power supplies. Let's change phy core
> >>> to first attempt to look up the supply at the port level, and then, if
> >>> not found, check parent device.
> >>
> >> Why not just have every port provide the power supply if it needs?
> >> I don't think checking for parent device should be present in the phy-core at
> >> all.
> > 
> > We need to do that if we want to keep compatibility with the current
> > DTSes: before this patch the supply would be always looked up on
> > device and not port level.
> 
> ah okay.
> so just using regulator_get_optional(&phy->dev, "phy"); should be sufficient

This is for regulators specified at port level (&phy->dev represents
port).

> right? Why do we need regulator_get_optional(phy->dev.parent, "phy");?
> 

This is for compatibility with old multi-port bindings where supply is
specified at parent device level and phy_create() is called with dev and
node that is not NULL and not the same as dev->of_node. I have no idea
if such bindings exist in wild, but wanted to keep them working given
stated DT stability rules.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-25 22:49         ` Dmitry Torokhov
@ 2015-03-25 23:44           ` Kishon Vijay Abraham I
  2015-03-25 23:48             ` Dmitry Torokhov
  0 siblings, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-25 23:44 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

Hi,

On Thursday 26 March 2015 04:19 AM, Dmitry Torokhov wrote:
> On Thu, Mar 26, 2015 at 04:09:23AM +0530, Kishon Vijay Abraham I wrote:
>> Hi,
>>
>> On Thursday 26 March 2015 03:47 AM, Dmitry Torokhov wrote:
>>> On Wed, Mar 25, 2015 at 3:11 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
>>>> Hi,
>>>>
>>>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>>>>> Multi-port phy's may have per-port power supplies. Let's change phy core
>>>>> to first attempt to look up the supply at the port level, and then, if
>>>>> not found, check parent device.
>>>>
>>>> Why not just have every port provide the power supply if it needs?
>>>> I don't think checking for parent device should be present in the phy-core at
>>>> all.
>>>
>>> We need to do that if we want to keep compatibility with the current
>>> DTSes: before this patch the supply would be always looked up on
>>> device and not port level.
>>
>> ah okay.
>> so just using regulator_get_optional(&phy->dev, "phy"); should be sufficient
> 
> This is for regulators specified at port level (&phy->dev represents
> port).
> 
>> right? Why do we need regulator_get_optional(phy->dev.parent, "phy");?
>>
> 
> This is for compatibility with old multi-port bindings where supply is
> specified at parent device level and phy_create() is called with dev and
> node that is not NULL and not the same as dev->of_node. I have no idea
> if such bindings exist in wild, but wanted to keep them working given
> stated DT stability rules.

Such a binding doesn't exist. So let's keep only the
regulator_get_optional(&phy->dev, "phy"); part. Only TI SoCs and recently
sun9i started using phy-supply and none of them use multi-phy PHY provider.

Thanks
Kishon

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

* Re: [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level
  2015-03-25 23:44           ` Kishon Vijay Abraham I
@ 2015-03-25 23:48             ` Dmitry Torokhov
  0 siblings, 0 replies; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-25 23:48 UTC (permalink / raw)
  To: Kishon Vijay Abraham I
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

On Thu, Mar 26, 2015 at 05:14:07AM +0530, Kishon Vijay Abraham I wrote:
> Hi,
> 
> On Thursday 26 March 2015 04:19 AM, Dmitry Torokhov wrote:
> > On Thu, Mar 26, 2015 at 04:09:23AM +0530, Kishon Vijay Abraham I wrote:
> >> Hi,
> >>
> >> On Thursday 26 March 2015 03:47 AM, Dmitry Torokhov wrote:
> >>> On Wed, Mar 25, 2015 at 3:11 PM, Kishon Vijay Abraham I <kishon@ti.com> wrote:
> >>>> Hi,
> >>>>
> >>>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> >>>>> Multi-port phy's may have per-port power supplies. Let's change phy core
> >>>>> to first attempt to look up the supply at the port level, and then, if
> >>>>> not found, check parent device.
> >>>>
> >>>> Why not just have every port provide the power supply if it needs?
> >>>> I don't think checking for parent device should be present in the phy-core at
> >>>> all.
> >>>
> >>> We need to do that if we want to keep compatibility with the current
> >>> DTSes: before this patch the supply would be always looked up on
> >>> device and not port level.
> >>
> >> ah okay.
> >> so just using regulator_get_optional(&phy->dev, "phy"); should be sufficient
> > 
> > This is for regulators specified at port level (&phy->dev represents
> > port).
> > 
> >> right? Why do we need regulator_get_optional(phy->dev.parent, "phy");?
> >>
> > 
> > This is for compatibility with old multi-port bindings where supply is
> > specified at parent device level and phy_create() is called with dev and
> > node that is not NULL and not the same as dev->of_node. I have no idea
> > if such bindings exist in wild, but wanted to keep them working given
> > stated DT stability rules.
> 
> Such a binding doesn't exist. So let's keep only the
> regulator_get_optional(&phy->dev, "phy"); part. Only TI SoCs and recently
> sun9i started using phy-supply and none of them use multi-phy PHY provider.

OK, fair enough.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-25 22:42     ` Dmitry Torokhov
@ 2015-03-26  0:01       ` Kishon Vijay Abraham I
  2015-03-26  0:06         ` Arun Ramamurthy
  0 siblings, 1 reply; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-26  0:01 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: Arun Ramamurthy, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui



On Thursday 26 March 2015 04:12 AM, Dmitry Torokhov wrote:
> Hi Kishon,
> 
> On Thu, Mar 26, 2015 at 03:58:50AM +0530, Kishon Vijay Abraham I wrote:
>> Hi,
>>
>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>>> +struct bcm_phy_driver {
>>> +	void __iomem *usbphy_regs;
>>> +	void __iomem *usb2h_idm_regs;
>>> +	void __iomem *usb2d_idm_regs;
>>> +	struct bcm_phy_instance *ports[MAX_PHY_PORTS];
>>
>> er.. can't we allocate this dynamically?
> 
> The chip has support for only 3 phys, so I believe allocating array of 3
> pointers is simplest.
> 
> [...]
> 
>>> +
>>> +static struct phy *bcm_usb_phy_xlate(struct device *dev,
>>> +				     struct of_phandle_args *args)
>>> +{
>>> +	struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
>>> +	struct bcm_phy_instance *port = NULL;
>>> +	int i;
>>> +
>>> +	if (!phy_driver)
>>> +		return ERR_PTR(-EINVAL);
>>> +
>>> +	if (WARN_ON(args->args_count != 1))
>>> +		return ERR_PTR(-EINVAL);
>>> +
>>> +	if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
>>> +		return ERR_PTR(-EINVAL);
>>> +
>>> +	for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
>>> +		struct bcm_phy_instance *p = phy_driver->ports[i];
>>> +
>>> +		if (p && p->generic_phy->dev.of_node == args->np) {
>>> +			port = p;
>>> +			break;
>>> +		}
>>> +	}
>>> +
>>> +	if (!port) {
>>> +		dev_err(dev, "Failed to locate phy %s\n", args->np->name);
>>> +		return ERR_PTR(-EINVAL);
>>> +	}
>>> +
>>> +	port->host_mode = args->args[0];
>>> +
>>> +	return port->generic_phy;
>>> +}
>>
>> The xlate function here shouldn't be needed at all. Use of_phy_simple_xlate
>> instead.
> 
> of_phy_simple_xlate() will not allow specifying host vs device mode when
> requesting phy though...

indeed!

-Kishon

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

* Re: [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver
  2015-03-25 22:16   ` Kishon Vijay Abraham I
@ 2015-03-26  0:04     ` Arun Ramamurthy
  2015-03-26 23:02       ` Dmitry Torokhov
  0 siblings, 1 reply; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-26  0:04 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree
  Cc: linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Dmitry Torokhov, Anatol Pomazau, Jonathan Richardson,
	Scott Branden, Ray Jui



On 15-03-25 03:16 PM, Kishon Vijay Abraham I wrote:
> Hi,
>
> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>> Broadcom's Cygnus chip has a USB 2.0 host controller connected to
>> three separate phys. One of the phs (port 2) is also connectd to
>> a usb 2.0 device controller
>>
>> Reviewed-by: Ray Jui <rjui@broadcom.com>
>> Reviewed-by: Scott Branden <sbranden@broadcom.com>
>> Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
>>
>> ---
>>   .../bindings/phy/brcm,cygnus-usb-phy.txt           | 65 ++++++++++++++++++++++
>>   1 file changed, 65 insertions(+)
>>   create mode 100644 Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>>
>> diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>> new file mode 100644
>> index 0000000..002bd59
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
>> @@ -0,0 +1,65 @@
>> +BROADCOM CYGNUS USB PHY
>> +
>> +Required Properties:
>> +	- compatible:  brcm,cygnus-usb-phy
>> +	- reg : usbphy_regs - Base address of phy registers
>> +			usb2h_idm_regs - Base address of host idm registers
>> +			usb2d_idm_regs - Base address of device idm registers
>
> where is #phy-cells documented?
I dont follow, isnt phy-cells a standard binding, what documentation is 
required?
>> +The node that uses the phy must provide one integers, 0 for device and 1 for host
>
>> +
>> +NOTE: port 0 and port 1 are host only and port 2 can be configured for host or device.
>> +
>> +Example of phy :
>> +	usbphy0: usbphy@0x0301c000 {
>> +		compatible = "brcm,cygnus-usb-phy";
>> +		reg = <0x0301c000 0x2000>,
>> +		      <0x18115000 0x1000>,
>> +		      <0x18111000 0x1000>;
>> +		status = "okay";
>> +
>> +		#address-cells = <1>;
>> +		#size-cells = <0>;
>> +		usbphy0_0: usbphy0@0 {
>> +			#phy-cells = <1>;
>> +			reg = <0>;
>> +			status = "okay";
>> +			phy-supply = <&vbus_p0>;
>> +		};
>> +
>> +		usbphy0_1: usbphy0@1 {
>> +			#phy-cells = <1>;
>> +			reg = <1>;
>> +			status = "okay";
>> +		};
>> +
>> +		usbphy0_2: usbphy0@2 {
>> +			#phy-cells = <1>;
>> +			reg = <2>;
>> +			status = "okay";
>> +			phy-supply = <&vbus_p2>;
>> +		};
>> +	};
>> +
>> +Example of node using the phy:
>> +
>> +	/* This nodes declares all three ports as host */
>> +	
>> +	ehci0: usb@0x18048000 {
>> +		compatible = "generic-ehci";
>> +		reg = <0x18048000 0x100>;
>> +		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
>> +		phys = <&usbphy0_0 1 &usbphy0_1 1 &usbphy0_2 1>;
>> +		phy-names = "usb","usb","usb";
>
> is it on purpose you use the same name for phy-names? it is wrong though.
Kishon, I did use the same names on purpose. The phy-names are actually 
irrelevant because I used the new api I created 
devm_of_phy_get_by_index. I actually wasnt sure if  should take out the 
phy-name field altogether or leave it as phy-names = "usb" for 
compatibility with other bindings. What are your thoughts?
>> +		status = "okay";
>> +	};
>> +
>> +	/* This node declares port 2 phy
>> +	and configures it for device */
>
> please use standard multi-line comment format.
>
Ok will do.
> Thanks
> Kishon
>

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

* Re: [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-26  0:01       ` Kishon Vijay Abraham I
@ 2015-03-26  0:06         ` Arun Ramamurthy
  2015-03-31  6:16           ` Kishon Vijay Abraham I
  0 siblings, 1 reply; 19+ messages in thread
From: Arun Ramamurthy @ 2015-03-26  0:06 UTC (permalink / raw)
  To: Kishon Vijay Abraham I, Dmitry Torokhov
  Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	Arnd Bergmann, devicetree, linux-arm-kernel,
	bcm-kernel-feedback-list, linux-kernel, Anatol Pomazau,
	Jonathan Richardson, Scott Branden, Ray Jui



On 15-03-25 05:01 PM, Kishon Vijay Abraham I wrote:
>
>
> On Thursday 26 March 2015 04:12 AM, Dmitry Torokhov wrote:
>> Hi Kishon,
>>
>> On Thu, Mar 26, 2015 at 03:58:50AM +0530, Kishon Vijay Abraham I wrote:
>>> Hi,
>>>
>>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>>>> +struct bcm_phy_driver {
>>>> +	void __iomem *usbphy_regs;
>>>> +	void __iomem *usb2h_idm_regs;
>>>> +	void __iomem *usb2d_idm_regs;
>>>> +	struct bcm_phy_instance *ports[MAX_PHY_PORTS];
>>>
>>> er.. can't we allocate this dynamically?
>>
>> The chip has support for only 3 phys, so I believe allocating array of 3
>> pointers is simplest.
>>
>> [...]
>>
>>>> +
>>>> +static struct phy *bcm_usb_phy_xlate(struct device *dev,
>>>> +				     struct of_phandle_args *args)
>>>> +{
>>>> +	struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
>>>> +	struct bcm_phy_instance *port = NULL;
>>>> +	int i;
>>>> +
>>>> +	if (!phy_driver)
>>>> +		return ERR_PTR(-EINVAL);
>>>> +
>>>> +	if (WARN_ON(args->args_count != 1))
>>>> +		return ERR_PTR(-EINVAL);
>>>> +
>>>> +	if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
>>>> +		return ERR_PTR(-EINVAL);
>>>> +
>>>> +	for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
>>>> +		struct bcm_phy_instance *p = phy_driver->ports[i];
>>>> +
>>>> +		if (p && p->generic_phy->dev.of_node == args->np) {
>>>> +			port = p;
>>>> +			break;
>>>> +		}
>>>> +	}
>>>> +
>>>> +	if (!port) {
>>>> +		dev_err(dev, "Failed to locate phy %s\n", args->np->name);
>>>> +		return ERR_PTR(-EINVAL);
>>>> +	}
>>>> +
>>>> +	port->host_mode = args->args[0];
>>>> +
>>>> +	return port->generic_phy;
>>>> +}
>>>
>>> The xlate function here shouldn't be needed at all. Use of_phy_simple_xlate
>>> instead.
>>
>> of_phy_simple_xlate() will not allow specifying host vs device mode when
>> requesting phy though...
>
> indeed!
>
Kishon, to confirm , are the xlate function and the MAX_PHY_PORTS ok or 
are you recommending changes? Thanks
>

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

* Re: [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver
  2015-03-26  0:04     ` Arun Ramamurthy
@ 2015-03-26 23:02       ` Dmitry Torokhov
  0 siblings, 0 replies; 19+ messages in thread
From: Dmitry Torokhov @ 2015-03-26 23:02 UTC (permalink / raw)
  To: Arun Ramamurthy
  Cc: Kishon Vijay Abraham I, Rob Herring, Pawel Moll, Mark Rutland,
	Ian Campbell, Kumar Gala, Arnd Bergmann, devicetree,
	linux-arm-kernel, bcm-kernel-feedback-list, linux-kernel,
	Anatol Pomazau, Jonathan Richardson, Scott Branden, Ray Jui

Hi Arun,

On Wed, Mar 25, 2015 at 05:04:57PM -0700, Arun Ramamurthy wrote:
> 
> 
> On 15-03-25 03:16 PM, Kishon Vijay Abraham I wrote:
> >Hi,
> >
> >On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
> >>Broadcom's Cygnus chip has a USB 2.0 host controller connected to
> >>three separate phys. One of the phs (port 2) is also connectd to
> >>a usb 2.0 device controller
> >>
> >>Reviewed-by: Ray Jui <rjui@broadcom.com>
> >>Reviewed-by: Scott Branden <sbranden@broadcom.com>
> >>Signed-off-by: Arun Ramamurthy <arun.ramamurthy@broadcom.com>
> >>
> >>---
> >>  .../bindings/phy/brcm,cygnus-usb-phy.txt           | 65 ++++++++++++++++++++++
> >>  1 file changed, 65 insertions(+)
> >>  create mode 100644 Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> >>
> >>diff --git a/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> >>new file mode 100644
> >>index 0000000..002bd59
> >>--- /dev/null
> >>+++ b/Documentation/devicetree/bindings/phy/brcm,cygnus-usb-phy.txt
> >>@@ -0,0 +1,65 @@
> >>+BROADCOM CYGNUS USB PHY
> >>+
> >>+Required Properties:
> >>+	- compatible:  brcm,cygnus-usb-phy
> >>+	- reg : usbphy_regs - Base address of phy registers
> >>+			usb2h_idm_regs - Base address of host idm registers
> >>+			usb2d_idm_regs - Base address of device idm registers
> >
> >where is #phy-cells documented?
> I dont follow, isnt phy-cells a standard binding, what documentation
> is required?
> >>+The node that uses the phy must provide one integers, 0 for device and 1 for host
> >

"The node that uses phy must specify whether it should be configured as
host or device in the second cell of phy specification."

By the way, can we use not integers but symbolic constants for host and
device mode?

> >>+
> >>+NOTE: port 0 and port 1 are host only and port 2 can be configured for host or device.
> >>+
> >>+Example of phy :
> >>+	usbphy0: usbphy@0x0301c000 {
> >>+		compatible = "brcm,cygnus-usb-phy";
> >>+		reg = <0x0301c000 0x2000>,
> >>+		      <0x18115000 0x1000>,
> >>+		      <0x18111000 0x1000>;
> >>+		status = "okay";
> >>+
> >>+		#address-cells = <1>;
> >>+		#size-cells = <0>;
> >>+		usbphy0_0: usbphy0@0 {
> >>+			#phy-cells = <1>;
> >>+			reg = <0>;
> >>+			status = "okay";
> >>+			phy-supply = <&vbus_p0>;
> >>+		};
> >>+
> >>+		usbphy0_1: usbphy0@1 {
> >>+			#phy-cells = <1>;
> >>+			reg = <1>;
> >>+			status = "okay";
> >>+		};
> >>+
> >>+		usbphy0_2: usbphy0@2 {
> >>+			#phy-cells = <1>;
> >>+			reg = <2>;
> >>+			status = "okay";
> >>+			phy-supply = <&vbus_p2>;
> >>+		};
> >>+	};
> >>+
> >>+Example of node using the phy:
> >>+
> >>+	/* This nodes declares all three ports as host */
> >>+	
> >>+	ehci0: usb@0x18048000 {
> >>+		compatible = "generic-ehci";
> >>+		reg = <0x18048000 0x100>;
> >>+		interrupts = <GIC_SPI 72 IRQ_TYPE_LEVEL_HIGH>;
> >>+		phys = <&usbphy0_0 1 &usbphy0_1 1 &usbphy0_2 1>;
> >>+		phy-names = "usb","usb","usb";
> >
> >is it on purpose you use the same name for phy-names? it is wrong though.
> Kishon, I did use the same names on purpose. The phy-names are
> actually irrelevant because I used the new api I created
> devm_of_phy_get_by_index. I actually wasnt sure if  should take out
> the phy-name field altogether or leave it as phy-names = "usb" for
> compatibility with other bindings.

There is no issue of compatibility as existing mappings would only use 1
phy and we'll pick it up when getting phy by index. I think we should
simply drop phy-names altogether as driver does not use this property
anymore.

Thanks.

-- 
Dmitry

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

* Re: [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver
  2015-03-26  0:06         ` Arun Ramamurthy
@ 2015-03-31  6:16           ` Kishon Vijay Abraham I
  0 siblings, 0 replies; 19+ messages in thread
From: Kishon Vijay Abraham I @ 2015-03-31  6:16 UTC (permalink / raw)
  To: Arun Ramamurthy, Dmitry Torokhov
  Cc: Rob Herring, Pawel Moll, Mark Rutland, Ian Campbell, Kumar Gala,
	Arnd Bergmann, devicetree, linux-arm-kernel,
	bcm-kernel-feedback-list, linux-kernel, Anatol Pomazau,
	Jonathan Richardson, Scott Branden, Ray Jui

Hi,

On Thursday 26 March 2015 05:36 AM, Arun Ramamurthy wrote:
>
>
> On 15-03-25 05:01 PM, Kishon Vijay Abraham I wrote:
>>
>>
>> On Thursday 26 March 2015 04:12 AM, Dmitry Torokhov wrote:
>>> Hi Kishon,
>>>
>>> On Thu, Mar 26, 2015 at 03:58:50AM +0530, Kishon Vijay Abraham I wrote:
>>>> Hi,
>>>>
>>>> On Saturday 21 March 2015 02:55 AM, Arun Ramamurthy wrote:
>>>>> +struct bcm_phy_driver {
>>>>> +    void __iomem *usbphy_regs;
>>>>> +    void __iomem *usb2h_idm_regs;
>>>>> +    void __iomem *usb2d_idm_regs;
>>>>> +    struct bcm_phy_instance *ports[MAX_PHY_PORTS];
>>>>
>>>> er.. can't we allocate this dynamically?
>>>
>>> The chip has support for only 3 phys, so I believe allocating array of 3
>>> pointers is simplest.
>>>
>>> [...]
>>>
>>>>> +
>>>>> +static struct phy *bcm_usb_phy_xlate(struct device *dev,
>>>>> +                     struct of_phandle_args *args)
>>>>> +{
>>>>> +    struct bcm_phy_driver *phy_driver = dev_get_drvdata(dev);
>>>>> +    struct bcm_phy_instance *port = NULL;
>>>>> +    int i;
>>>>> +
>>>>> +    if (!phy_driver)
>>>>> +        return ERR_PTR(-EINVAL);
>>>>> +
>>>>> +    if (WARN_ON(args->args_count != 1))
>>>>> +        return ERR_PTR(-EINVAL);
>>>>> +
>>>>> +    if (WARN_ON(args->args[0] < 0 || args->args[0] > 1))
>>>>> +        return ERR_PTR(-EINVAL);
>>>>> +
>>>>> +    for (i = 0; i < ARRAY_SIZE(phy_driver->ports); i++) {
>>>>> +        struct bcm_phy_instance *p = phy_driver->ports[i];
>>>>> +
>>>>> +        if (p && p->generic_phy->dev.of_node == args->np) {
>>>>> +            port = p;
>>>>> +            break;
>>>>> +        }
>>>>> +    }
>>>>> +
>>>>> +    if (!port) {
>>>>> +        dev_err(dev, "Failed to locate phy %s\n", args->np->name);
>>>>> +        return ERR_PTR(-EINVAL);
>>>>> +    }
>>>>> +
>>>>> +    port->host_mode = args->args[0];
>>>>> +
>>>>> +    return port->generic_phy;
>>>>> +}
>>>>
>>>> The xlate function here shouldn't be needed at all. Use of_phy_simple_xlate
>>>> instead.
>>>
>>> of_phy_simple_xlate() will not allow specifying host vs device mode when
>>> requesting phy though...
>>
>> indeed!
>>
> Kishon, to confirm , are the xlate function and the MAX_PHY_PORTS ok or are you
> recommending changes? Thanks

as Dmitry pointed out you'll still need your own implementation of xlate.

Thanks
Kishon

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

end of thread, other threads:[~2015-03-31  6:17 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-20 21:25 [PATCH v1 0/3] USB PHY driver for Broadcom's Cygnus chipse Arun Ramamurthy
2015-03-20 21:25 ` [PATCH v1 1/3] phy: phy-core: allow specifying supply at port level Arun Ramamurthy
2015-03-20 21:31   ` Dmitry Torokhov
2015-03-25 22:11   ` Kishon Vijay Abraham I
2015-03-25 22:17     ` Dmitry Torokhov
2015-03-25 22:39       ` Kishon Vijay Abraham I
2015-03-25 22:49         ` Dmitry Torokhov
2015-03-25 23:44           ` Kishon Vijay Abraham I
2015-03-25 23:48             ` Dmitry Torokhov
2015-03-20 21:25 ` [PATCH v1 2/3] Phy: DT binding documentation for Broadcom Cygnus USB PHY driver Arun Ramamurthy
2015-03-25 22:16   ` Kishon Vijay Abraham I
2015-03-26  0:04     ` Arun Ramamurthy
2015-03-26 23:02       ` Dmitry Torokhov
2015-03-20 21:25 ` [PATCH v1 3/3] phy: cygnus-usbphy: Add Broadcom Cygnus USB phy driver Arun Ramamurthy
2015-03-25 22:28   ` Kishon Vijay Abraham I
2015-03-25 22:42     ` Dmitry Torokhov
2015-03-26  0:01       ` Kishon Vijay Abraham I
2015-03-26  0:06         ` Arun Ramamurthy
2015-03-31  6:16           ` Kishon Vijay Abraham I

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).