Skip to contentSkip to conversation

usb: ulpi bus

PATCH Superseded Heikki Krogerus 4 participants 70 messages Jan 23, 2015 – Feb 13, 2015

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

cover usb: ulpi bus

Heikki Krogerus (8):
usb: add bus type for USB ULPI
usb: dwc3: USB2 PHY register access bits
usb: dwc3: store driver data earlier
usb: dwc3: cache hwparams earlier
usb: dwc3: ULPI or UTMI+ select
usb: dwc3: add ULPI interface support
phy: helpers for USB ULPI PHY registering
phy: add driver for TI TUSB1210 ULPI PHY

 MAINTAINERS                       |   7 ++
 drivers/phy/Kconfig               |   6 +
 drivers/phy/Makefile              |   1 +
 drivers/phy/phy-tusb1210.c        | 133 ++++++++++++++++++++
 drivers/phy/ulpi_phy.h            |  31 +++++
 drivers/usb/common/Makefile       |   3 +-
 drivers/usb/common/ulpi.c         | 253 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/Kconfig          |   8 ++
 drivers/usb/dwc3/Kconfig          |   7 ++
 drivers/usb/dwc3/Makefile         |   4 +
 drivers/usb/dwc3/core.c           |  12 +-
 drivers/usb/dwc3/core.h           |  22 ++++
 drivers/usb/dwc3/ulpi.c           | 112 +++++++++++++++++
 include/linux/mod_devicetable.h   |   6 +
 include/linux/ulpi/driver.h       |  62 ++++++++++
 include/linux/ulpi/interface.h    |  23 ++++
 include/linux/ulpi/regs.h         | 130 ++++++++++++++++++++
 include/linux/usb/ulpi.h          | 134 +-------------------
 scripts/mod/devicetable-offsets.c |   4 +
 scripts/mod/file2alias.c          |  13 ++
 20 files changed, 835 insertions(+), 136 deletions(-)
 create mode 100644 drivers/phy/phy-tusb1210.c
 create mode 100644 drivers/phy/ulpi_phy.h
 create mode 100644 drivers/usb/common/ulpi.c
 create mode 100644 drivers/usb/dwc3/ulpi.c
 create mode 100644 include/linux/ulpi/driver.h
 create mode 100644 include/linux/ulpi/interface.h
 create mode 100644 include/linux/ulpi/regs.h
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

PATCH 1/8 usb: add bus type for USB ULPI

UTMI+ Low Pin Interface (ULPI) is a commonly used PHY interface for USB 2.0. The ULPI specification describes a standard set of registers which the vendors can extend for their specific needs. ULPI PHYs provide often functions such as charger detection and ADP sensing and probing.

There are two major issues that the bus type is meant to tackle:

Firstly, ULPI registers are accessed from the controller. The bus provides convenient method for the controller drivers to share that access with the actual PHY drivers.

Secondly, there are already platforms that assume ULPI PHYs are runtime detected, such as many Intel Baytrail based platforms. They do not provide any kind of hardware description for the ULPI PHYs like separate ACPI device object that could be used to enumerate a device from.

---
 MAINTAINERS                       |   7 ++
 drivers/usb/common/Makefile       |   3 +-
 drivers/usb/common/ulpi.c         | 253 ++++++++++++++++++++++++++++++++++++++
 drivers/usb/core/Kconfig          |   8 ++
 include/linux/mod_devicetable.h   |   6 +
 include/linux/ulpi/driver.h       |  62 ++++++++++
 include/linux/ulpi/interface.h    |  23 ++++
 include/linux/ulpi/regs.h         | 130 ++++++++++++++++++++
 include/linux/usb/ulpi.h          | 134 +-------------------
 scripts/mod/devicetable-offsets.c |   4 +
 scripts/mod/file2alias.c          |  13 ++
 11 files changed, 510 insertions(+), 133 deletions(-)
 create mode 100644 drivers/usb/common/ulpi.c
 create mode 100644 include/linux/ulpi/driver.h
 create mode 100644 include/linux/ulpi/interface.h
 create mode 100644 include/linux/ulpi/regs.h
MAINTAINERS +7 -0
index 761a4a1..7d0c58c 100644
@@ -10234,6 +10234,13 @@ S:	Maintained
 F:	Documentation/video4linux/zr364xx.txt
 F:	drivers/media/usb/zr364xx/
 
+ULPI BUS
+M:	Heikki Krogerus <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/usb/common/ulpi.c
+F:	include/linux/ulpi/
+
 USER-MODE LINUX (UML)
 M:	Jeff Dike <[email protected]>
 M:	Richard Weinberger <[email protected]>
drivers/usb/common/Makefile +2 -1
index ca2f8bd..5791d6c 100644
@@ -6,4 +6,5 @@ obj-$(CONFIG_USB_COMMON)	  += usb-common.o
 usb-common-y			  += common.o
 usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
-obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
+obj-$(CONFIG_USB_OTG_FSM)	+= usb-otg-fsm.o
+obj-$(CONFIG_USB_ULPI_BUS)	+= ulpi.o
drivers/usb/common/ulpi.c new file +253 -0

253 lines not on this page · raw message

drivers/usb/core/Kconfig +8 -0
index cc0ced0..c0fc3b5 100644
@@ -84,3 +84,11 @@ config USB_OTG_FSM
 	  Implements OTG Finite State Machine as specified in On-The-Go
 	  and Embedded Host Supplement to the USB Revision 2.0 Specification.
 
+config USB_ULPI_BUS
+	bool "USB ULPI PHY interface support"
+	depends on USB || USB_GADGET
+	help
+	  Say yes if you have ULPI PHY attached to your USB controller.
+
+	  If unsure, say N.
+
include/linux/mod_devicetable.h +6 -0
index 745def8..6581615 100644
@@ -626,4 +626,10 @@ struct mcb_device_id {
 	kernel_ulong_t driver_data;
 };
 
+struct ulpi_device_id {
+	__u16 vendor;
+	__u16 product;
+	kernel_ulong_t driver_data;
+};
+
 #endif /* LINUX_MOD_DEVICETABLE_H */
include/linux/ulpi/driver.h new file +62 -0

62 lines not on this page · raw message

include/linux/ulpi/interface.h new file +23 -0
new file mode 100644
index 0000000..08753f7
@@ -0,0 +1,23 @@
+#ifndef __LINUX_ULPI_INTERFACE_H
+#define __LINUX_ULPI_INTERFACE_H
+
+#include <linux/types.h>
+
+struct ulpi;
+
+/**
+ * struct ulpi_ops - ULPI register access
+ * @dev: the interface provider
+ * @read: read opearation for ULPI register access
+ * @write: write opearation for ULPI register access
+ */
+struct ulpi_ops {
+	struct device *dev;
+	int (*read)(struct ulpi_ops *ops, u8 addr);
+	int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
+};
+
+struct ulpi *ulpi_register_interface(struct device *, struct ulpi_ops *);
+void ulpi_unregister_interface(struct ulpi *);
+
+#endif /* __LINUX_ULPI_INTERFACE_H */
include/linux/ulpi/regs.h new file +130 -0

130 lines not on this page · raw message

include/linux/usb/ulpi.h +2 -132

146 lines not on this page · raw message

scripts/mod/devicetable-offsets.c +4 -0
index f282516..2b55464 100644
@@ -186,5 +186,9 @@ int main(void)
 	DEVID_FIELD(rio_device_id, asm_did);
 	DEVID_FIELD(rio_device_id, asm_vid);
 
+	DEVID(ulpi_device_id);
+	DEVID_FIELD(ulpi_device_id, vendor);
+	DEVID_FIELD(ulpi_device_id, product);
+
 	return 0;
 }
scripts/mod/file2alias.c +13 -0
index e614ef6..753cb08 100644
@@ -1176,6 +1176,19 @@ static int do_rio_entry(const char *filename,
 }
 ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
 
+/* Looks like: mei:S */
+static int do_ulpi_entry(const char *filename, void *symval,
+			 char *alias)
+{
+	DEF_FIELD(symval, ulpi_device_id, vendor);
+	DEF_FIELD(symval, ulpi_device_id, product);
+
+	sprintf(alias, "ulpi:v%04xp%04x", vendor, product);
+
+	return 1;
+}
+ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
+
 /* Does namelen bytes of name exactly match the symbol? */
 static bool sym_is(const char *name, unsigned namelen, const char *symbol)
 {
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH 1/8] usb: add bus type for USB ULPI

Hi,

drivers/usb/common/Makefile obj-$(CONFIG_USB_COMMON) += usb-common.o · line 9

Quoted 6 lines · Heikki Krogerus
drivers/usb/common/Makefile +1 -1
@@ -6,4 +6,5 @@ obj-$(CONFIG_USB_COMMON)	  += usb-common.o
 usb-common-y			  += common.o
 usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
-obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
+obj-$(CONFIG_USB_OTG_FSM)	+= usb-otg-fsm.o

a bit of unrelated change here.

drivers/usb/core/Kconfig config USB_OTG_FSM · line 89

Quoted 11 lines
drivers/usb/core/Kconfig +3 -0
index cc0ced0..c0fc3b5 100644
@@ -84,3 +84,11 @@ config USB_OTG_FSM
 	  Implements OTG Finite State Machine as specified in On-The-Go
 	  and Embedded Host Supplement to the USB Revision 2.0 Specification.
 
+config USB_ULPI_BUS
+	bool "USB ULPI PHY interface support"
+	depends on USB || USB_GADGET

depends on USB_SUPPORT ?

drivers/usb/core/Kconfig config USB_OTG_FSM

Quoted 9 lines
drivers/usb/core/Kconfig +9 -0
+int ulpi_register_driver(struct ulpi_driver *drv);
+void ulpi_unregister_driver(struct ulpi_driver *drv);
+
+#define module_ulpi_driver(__ulpi_driver) \
+	module_driver(__ulpi_driver, ulpi_register_driver, \
+		      ulpi_unregister_driver)
+
+int ulpi_read(struct ulpi *ulpi, u8 addr);
+int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val);

no stubs ?

Signature · 1 line
balbi
author maintainer
#3 lore raw

Re: [PATCH 1/8] usb: add bus type for USB ULPI

Quoted 11 lines · Felipe Balbi

Hi,

drivers/usb/common/Makefile obj-$(CONFIG_USB_COMMON) += usb-common.o · line 9

Quoted 6 lines · Heikki Krogerus
drivers/usb/common/Makefile +1 -1
@@ -6,4 +6,5 @@ obj-$(CONFIG_USB_COMMON)	  += usb-common.o
 usb-common-y			  += common.o
 usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
-obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
+obj-$(CONFIG_USB_OTG_FSM)	+= usb-otg-fsm.o

a bit of unrelated change here.

OK

Quoted 8 lines
Quoted 8 lines
drivers/usb/core/Kconfig +0 -0
index cc0ced0..c0fc3b5 100644
@@ -84,3 +84,11 @@ config USB_OTG_FSM
 	  Implements OTG Finite State Machine as specified in On-The-Go
 	  and Embedded Host Supplement to the USB Revision 2.0 Specification.
 
Quoted 5 lines

drivers/usb/core/Kconfig config USB_OTG_FSM · line 89

Quoted 3 lines
drivers/usb/core/Kconfig +3 -0
+config USB_ULPI_BUS
+	bool "USB ULPI PHY interface support"
+	depends on USB || USB_GADGET

depends on USB_SUPPORT ?

sure

Quoted 11 lines

drivers/usb/core/Kconfig config USB_OTG_FSM

Quoted 9 lines
drivers/usb/core/Kconfig +9 -0
+int ulpi_register_driver(struct ulpi_driver *drv);
+void ulpi_unregister_driver(struct ulpi_driver *drv);
+
+#define module_ulpi_driver(__ulpi_driver) \
+	module_driver(__ulpi_driver, ulpi_register_driver, \
+		      ulpi_unregister_driver)
+
+int ulpi_read(struct ulpi *ulpi, u8 addr);
+int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val);

no stubs ?

Is there really need for them? Well, I'll add them.

Thanks,

Signature · 1 line
heikki
#4 lore raw

Re: [PATCH 1/8] usb: add bus type for USB ULPI

In reply to Heikki Krogerus

scripts/mod/file2alias.c static int do_rio_entry(const char *filename, · line 1179

Quoted 9 lines · Heikki Krogerus
scripts/mod/file2alias.c +1 -0
index e614ef6..753cb08 100644
@@ -1176,6 +1176,19 @@ static int do_rio_entry(const char *filename,
 }
 ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
 
+/* Looks like: mei:S */

This comment doesn't look right.

Quoted 12 lines
scripts/mod/file2alias.c +12 -0
+static int do_ulpi_entry(const char *filename, void *symval,
+			 char *alias)
+{
+	DEF_FIELD(symval, ulpi_device_id, vendor);
+	DEF_FIELD(symval, ulpi_device_id, product);
+
+	sprintf(alias, "ulpi:v%04xp%04x", vendor, product);
+
+	return 1;
+}
+ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
+
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
author maintainer
#5 lore raw

Re: [PATCH 1/8] usb: add bus type for USB ULPI

Quoted 9 lines · Stephen Boyd
Quoted 8 lines · Heikki Krogerus
scripts/mod/file2alias.c +0 -0
index e614ef6..753cb08 100644
@@ -1176,6 +1176,19 @@ static int do_rio_entry(const char *filename,
 }
 ADD_TO_DEVTABLE("rapidio", rio_device_id, do_rio_entry);
 
Quoted 3 lines

scripts/mod/file2alias.c static int do_rio_entry(const char *filename, · line 1179

Quoted 1 line
scripts/mod/file2alias.c +1 -0
+/* Looks like: mei:S */

This comment doesn't look right.

Oops. Thanks for catching that one.

Quoted 11 lines
Quoted 11 lines
scripts/mod/file2alias.c +11 -0
+static int do_ulpi_entry(const char *filename, void *symval,
+			 char *alias)
+{
+	DEF_FIELD(symval, ulpi_device_id, vendor);
+	DEF_FIELD(symval, ulpi_device_id, product);
+
+	sprintf(alias, "ulpi:v%04xp%04x", vendor, product);
+
+	return 1;
+}
+ADD_TO_DEVTABLE("ulpi", ulpi_device_id, do_ulpi_entry);
Signature · 1 line
heikki
author maintainer
#6 lore raw

PATCH 2/8 usb: dwc3: USB2 PHY register access bits

In reply to Heikki Krogerus

Definitions for Global USB2 PHY Vendor Control Register bits. We will need them to access ULPI PHY registers later.

---
 drivers/usb/dwc3/core.h | 8 ++++++++
 1 file changed, 8 insertions(+)
drivers/usb/dwc3/core.h +8 -0
index 0842aa8..be1c20e 100644
@@ -174,6 +174,14 @@
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
 #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
 
+/* Global USB2 PHY Vendor Control Register */
+#define DWC3_GUSB2PHYACC_NEWREGREQ	(1 << 25)
+#define DWC3_GUSB2PHYACC_BUSY		(1 << 23)
+#define DWC3_GUSB2PHYACC_WRITE		(1 << 22)
+#define DWC3_GUSB2PHYACC_ADDR(n)	(n << 16)
+#define DWC3_GUSB2PHYACC_EXTEND_ADDR(n)	(n << 8)
+#define DWC3_GUSB2PHYACC_DATA(n)	(n & 0xff)
+
 /* Global USB3 PIPE Control Register */
 #define DWC3_GUSB3PIPECTL_PHYSOFTRST	(1 << 31)
 #define DWC3_GUSB3PIPECTL_U2SSINP3OK	(1 << 29)
Signature · 1 line
2.1.4
author maintainer
#7 lore raw

PATCH 3/8 usb: dwc3: store driver data earlier

In reply to Heikki Krogerus

We need to store it before phys are handled, so we can later use it in ULPI interface support code.

---
 drivers/usb/dwc3/core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/usb/dwc3/core.c +2 -1
index 25ddc39..b06e88b 100644
@@ -876,12 +876,13 @@ static int dwc3_probe(struct platform_device *pdev)
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
 
+	platform_set_drvdata(pdev, dwc);
+
 	ret = dwc3_core_get_phy(dwc);
 	if (ret)
 		return ret;
 
 	spin_lock_init(&dwc->lock);
-	platform_set_drvdata(pdev, dwc);
 
 	if (!dev->dma_mask) {
 		dev->dma_mask = dev->parent->dma_mask;
Signature · 1 line
2.1.4
author maintainer
#8 lore raw

PATCH 4/8 usb: dwc3: cache hwparams earlier

In reply to Heikki Krogerus

So they are available when ULPI interface support is added.

---
 drivers/usb/dwc3/core.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/usb/dwc3/core.c +1 -2
index b06e88b..a8c9062 100644
@@ -877,6 +877,7 @@ static int dwc3_probe(struct platform_device *pdev)
 		| (dwc->is_utmi_l1_suspend << 4);
 
 	platform_set_drvdata(pdev, dwc);
+	dwc3_cache_hwparams(dwc);
 
 	ret = dwc3_core_get_phy(dwc);
 	if (ret)
@@ -894,8 +895,6 @@ static int dwc3_probe(struct platform_device *pdev)
 	pm_runtime_get_sync(dev);
 	pm_runtime_forbid(dev);
 
-	dwc3_cache_hwparams(dwc);
-
 	ret = dwc3_alloc_event_buffers(dwc, DWC3_EVENT_BUFFERS_SIZE);
 	if (ret) {
 		dev_err(dwc->dev, "failed to allocate event buffers\n");
Signature · 1 line
2.1.4
author maintainer
#9 lore raw

PATCH 5/8 usb: dwc3: ULPI or UTMI+ select

In reply to Heikki Krogerus

Make selection between ULPI and UTMI+ interfaces possible by providing definition for the bit in Global USB2 PHY Configuration Register that controls it.

---
 drivers/usb/dwc3/core.h | 1 +
 1 file changed, 1 insertion(+)
drivers/usb/dwc3/core.h +1 -0
index be1c20e..9b6f4c7 100644
@@ -173,6 +173,7 @@
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
 #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
+#define DWC3_GUSB2PHYCFG_ULPI_UTMI	(1 << 4)
 
 /* Global USB2 PHY Vendor Control Register */
 #define DWC3_GUSB2PHYACC_NEWREGREQ	(1 << 25)
Signature · 1 line
2.1.4
author maintainer
#10 lore raw

PATCH 6/8 usb: dwc3: add ULPI interface support

In reply to Heikki Krogerus

Registers DWC3's ULPI interface with the ULPI bus when it's available.

---
 drivers/usb/dwc3/Kconfig  |   7 +++
 drivers/usb/dwc3/Makefile |   4 ++
 drivers/usb/dwc3/core.c   |   6 +++
 drivers/usb/dwc3/core.h   |  13 ++++++
 drivers/usb/dwc3/ulpi.c   | 112 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 142 insertions(+)
 create mode 100644 drivers/usb/dwc3/ulpi.c
drivers/usb/dwc3/Kconfig +7 -0
index 58b5b2c..cda82ad 100644
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+	bool "Register ULPI PHY Interface"
+	depends on USB_ULPI_BUS=y
+	help
+	  Select this if you have ULPI type PHY attached to your DWC3
+	  controller.
+
 choice
 	bool "DWC3 Mode Selection"
 	default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
drivers/usb/dwc3/Makefile +4 -0
index bb34fbc..2fc44e0 100644
@@ -16,6 +16,10 @@ ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
 	dwc3-y				+= gadget.o ep0.o
 endif
 
+ifneq ($(CONFIG_USB_DWC3_ULPI),)
+	dwc3-y				+= ulpi.o
+endif
+
 ifneq ($(CONFIG_DEBUG_FS),)
 	dwc3-y				+= debugfs.o
 endif
drivers/usb/dwc3/core.c +6 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
+	ret = dwc3_ulpi_init(dwc);
+	if (ret)
+		return ret;
+
 	ret = dwc3_core_get_phy(dwc);
 	if (ret)
 		return ret;
@@ -965,6 +969,7 @@ err1:
 
 err0:
 	dwc3_free_event_buffers(dwc);
+	dwc3_ulpi_exit(dwc);
 
 	return ret;
 }
@@ -984,6 +989,7 @@ static int dwc3_remove(struct platform_device *pdev)
 	phy_power_off(dwc->usb3_generic_phy);
 
 	dwc3_core_exit(dwc);
+	dwc3_ulpi_exit(dwc);
 
 	pm_runtime_put_sync(&pdev->dev);
 	pm_runtime_disable(&pdev->dev);
drivers/usb/dwc3/core.h +13 -0
index 9b6f4c7..ad6b371 100644
@@ -30,6 +30,7 @@
 #include <linux/usb/ch9.h>
 #include <linux/usb/gadget.h>
 #include <linux/usb/otg.h>
+#include <linux/ulpi/interface.h>
 
 #include <linux/phy/phy.h>
 
@@ -748,6 +749,8 @@ struct dwc3 {
 	struct phy		*usb2_generic_phy;
 	struct phy		*usb3_generic_phy;
 
+	struct ulpi		*ulpi;
+
 	void __iomem		*regs;
 	size_t			regs_size;
 
@@ -1044,4 +1047,14 @@ static inline int dwc3_gadget_resume(struct dwc3 *dwc)
 }
 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
 
+#if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
+int dwc3_ulpi_init(struct dwc3 *dwc);
+void dwc3_ulpi_exit(struct dwc3 *dwc);
+#else
+static inline int dwc3_ulpi_init(struct dwc3 *dwc)
+{ return 0; }
+static inline void dwc3_ulpi_exit(struct dwc3 *dwc)
+{ }
+#endif
+
 #endif /* __DRIVERS_USB_DWC3_CORE_H */
drivers/usb/dwc3/ulpi.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.1.4
#11 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Hi,

Quoted 11 lines · Heikki Krogerus
drivers/usb/dwc3/ulpi.c new file +11 -0
+int dwc3_ulpi_init(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	/* First check USB2 PHY interface type */
+	switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
+	case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
+		/* Select ULPI Interface */
+		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+		reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
+		dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);

drivers/usb/dwc3/ulpi.c line 98

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		/* FALLTHROUGH */
+	case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
+		break;
+	default:
+		return 0;
+	}
+
+	/* Register the interface */
+	dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi);
+	if (IS_ERR(dwc->ulpi)) {

so, this will only build and link if DWC3_ULPI is enabled, in case of error you return early...

drivers/usb/dwc3/ulpi.c line 108

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		dev_err(dwc->dev, "failed to register ULPI interface");
+		return PTR_ERR(dwc->ulpi);
+	}
+
+	return 0;
+}
+
+void dwc3_ulpi_exit(struct dwc3 *dwc)
+{
+	if (dwc->ulpi) {

... looks like this branch is unnecessary.

Signature · 1 line
balbi
author maintainer
#12 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 26 lines · Felipe Balbi
Quoted 11 lines · Heikki Krogerus
drivers/usb/dwc3/ulpi.c new file +11 -0
+int dwc3_ulpi_init(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	/* First check USB2 PHY interface type */
+	switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
+	case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
+		/* Select ULPI Interface */
+		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+		reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
+		dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);

drivers/usb/dwc3/ulpi.c line 98

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		/* FALLTHROUGH */
+	case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
+		break;
+	default:
+		return 0;
+	}
+
+	/* Register the interface */
+	dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi);
+	if (IS_ERR(dwc->ulpi)) {

so, this will only build and link if DWC3_ULPI is enabled, in case of error you return early...

Quoted 12 lines

drivers/usb/dwc3/ulpi.c line 108

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		dev_err(dwc->dev, "failed to register ULPI interface");
+		return PTR_ERR(dwc->ulpi);
+	}
+
+	return 0;
+}
+
+void dwc3_ulpi_exit(struct dwc3 *dwc)
+{
+	if (dwc->ulpi) {

... looks like this branch is unnecessary.

We can't do that, or distros that select DWC3_ULPI option can only use dwc3 with hardware that really has ULPI PHY. So I guess we'll drop the DWC3_ULPI option and build the dwc3 ulpi support always if ULPI bus is enabled. OK?

Thanks,

Signature · 1 line
heikki
#13 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 40 lines · Heikki Krogerus
Quoted 26 lines · Felipe Balbi
Quoted 11 lines · Heikki Krogerus
drivers/usb/dwc3/ulpi.c new file +11 -0
+int dwc3_ulpi_init(struct dwc3 *dwc)
+{
+	u32 reg;
+
+	/* First check USB2 PHY interface type */
+	switch (DWC3_GHWPARAMS3_HSPHY_IFC(dwc->hwparams.hwparams3)) {
+	case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
+		/* Select ULPI Interface */
+		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
+		reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
+		dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);

drivers/usb/dwc3/ulpi.c line 98

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		/* FALLTHROUGH */
+	case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
+		break;
+	default:
+		return 0;
+	}
+
+	/* Register the interface */
+	dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi);
+	if (IS_ERR(dwc->ulpi)) {

so, this will only build and link if DWC3_ULPI is enabled, in case of error you return early...

Quoted 12 lines

drivers/usb/dwc3/ulpi.c line 108

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+		dev_err(dwc->dev, "failed to register ULPI interface");
+		return PTR_ERR(dwc->ulpi);
+	}
+
+	return 0;
+}
+
+void dwc3_ulpi_exit(struct dwc3 *dwc)
+{
+	if (dwc->ulpi) {

... looks like this branch is unnecessary.

Quoted 4 lines

We can't do that, or distros that select DWC3_ULPI option can only use dwc3 with hardware that really has ULPI PHY. So I guess we'll drop the DWC3_ULPI option and build the dwc3 ulpi support always if ULPI bus is enabled. OK?

look at your patch again. In case DWC3_ULPI isn't enabled, this file won't be linked at all. You're using stubs, so taht's fine.

In case it _is_ enabled, you're breaking out early if you can't register ulpi interface, meaning you're exitting probe() (which, in fact, seems wrong as I want to be able to run dwc3 with ULPI enabled on a platform that was configured with ULPI+UTMI, but uses UTMI PHY).

I still think this patch won't work in all cases.

Signature · 1 line
balbi
author maintainer
#14 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 9 lines

look at your patch again. In case DWC3_ULPI isn't enabled, this file won't be linked at all. You're using stubs, so taht's fine.

In case it _is_ enabled, you're breaking out early if you can't register ulpi interface, meaning you're exitting probe() (which, in fact, seems wrong as I want to be able to run dwc3 with ULPI enabled on a platform that was configured with ULPI+UTMI, but uses UTMI PHY).

I still think this patch won't work in all cases.

OK. So in case of ULPI+UTMI we'll try the ulpi interface, and if it fails, fall back to UTMI. Or can we use some other method to determine to which interface the PHY is really attached to in that case?

Thanks,

Signature · 1 line
heikki
#15 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 8 lines · Heikki Krogerus
Quoted 8 lines

look at your patch again. In case DWC3_ULPI isn't enabled, this file won't be linked at all. You're using stubs, so taht's fine.

In case it _is_ enabled, you're breaking out early if you can't register ulpi interface, meaning you're exitting probe() (which, in fact, seems wrong as I want to be able to run dwc3 with ULPI enabled on a platform that was configured with ULPI+UTMI, but uses UTMI PHY).

Quoted 5 lines
Quoted 1 line

I still think this patch won't work in all cases.

OK. So in case of ULPI+UTMI we'll try the ulpi interface, and if it fails, fall back to UTMI. Or can we use some other method to determine to which interface the PHY is really attached to in that case?

I think we would need a phy_interface_sel pdata/DT binding for those cases. It should be optional and probably only needed for a few odd devices.

Signature · 1 line
balbi
#16 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

In reply to Heikki Krogerus

Hi Heikki,

Quoted 51 lines · Heikki Krogerus

Registers DWC3's ULPI interface with the ULPI bus when it's available.

---
 drivers/usb/dwc3/Kconfig  |   7 +++
 drivers/usb/dwc3/Makefile |   4 ++
 drivers/usb/dwc3/core.c   |   6 +++
 drivers/usb/dwc3/core.h   |  13 ++++++
 drivers/usb/dwc3/ulpi.c   | 112 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 142 insertions(+)
 create mode 100644 drivers/usb/dwc3/ulpi.c
drivers/usb/dwc3/Kconfig +7 -0
index 58b5b2c..cda82ad 100644
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+	bool "Register ULPI PHY Interface"
+	depends on USB_ULPI_BUS=y
+	help
+	  Select this if you have ULPI type PHY attached to your DWC3
+	  controller.
+
 choice
 	bool "DWC3 Mode Selection"
 	default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
drivers/usb/dwc3/Makefile +4 -0
index bb34fbc..2fc44e0 100644
@@ -16,6 +16,10 @@ ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) $(CONFIG_USB_DWC3_DUAL_ROLE)),)
 	dwc3-y				+= gadget.o ep0.o
 endif
 
+ifneq ($(CONFIG_USB_DWC3_ULPI),)
+	dwc3-y				+= ulpi.o
+endif
+
 ifneq ($(CONFIG_DEBUG_FS),)
 	dwc3-y				+= debugfs.o
 endif
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 4 lines
drivers/usb/dwc3/core.c +1 -0
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Br, David

author maintainer
#17 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

So in practice when ever dwc3 is powered we will be able to access ULPI for as long as the USB2 PHY interface is not suspended separately with GUSB2PHYCFG SusPHY bit. And even then we would only need to resume it with the same bit and ULPI is accessible again.

Cheers,

Signature · 1 line
heikki
#18 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 15 lines · Heikki Krogerus
Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Quoted 4 lines

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

I just double checked DWC3 TRM.
You are correct, by the time we're executing dwc3_core_soft_reset() ULPI bus is already accessible. But the TRM also specifies an ULPI phy would be reset by DCTL's core soft reset, which is executed by dwc3_core_init() before calling dwc3_core_soft_reset(). It does mention DWC3 writes data to an ULPI phy register during reset, but it also mentions the clock sync happens during that time.

That makes no even OK, but more correct IMO to power on phy before core's soft reset (i.e. by ACPI methods). But it lets us in a grey area whether ULPI is reliably accessible before core's soft reset.

I believe if you move the dwc3_ulpi_init() to dwc3_core_init(), after core's soft reset we've got no more grey area.

Br, David

Quoted 11 lines

So in practice when ever dwc3 is powered we will be able to access ULPI for as long as the USB2 PHY interface is not suspended separately with GUSB2PHYCFG SusPHY bit. And even then we would only need to resume it with the same bit and ULPI is accessible again.

Cheers,

Signature · 1 line
heikki
#19 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 29 lines · David Cohen
Quoted 15 lines · Heikki Krogerus
Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Quoted 4 lines

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

I just double checked DWC3 TRM.
You are correct, by the time we're executing dwc3_core_soft_reset() ULPI bus is already accessible. But the TRM also specifies an ULPI phy would be reset by DCTL's core soft reset, which is executed by dwc3_core_init() before calling dwc3_core_soft_reset(). It does mention DWC3 writes data to an ULPI phy register during reset, but it also mentions the clock sync happens during that time.

Quoted 1 line

That makes no even OK, but more correct IMO to power on phy before

Sorry for the typo. I meant:
That makes not only OK, but more correct...

Quoted 19 lines

core's soft reset (i.e. by ACPI methods). But it lets us in a grey area whether ULPI is reliably accessible before core's soft reset.

I believe if you move the dwc3_ulpi_init() to dwc3_core_init(), after core's soft reset we've got no more grey area.

Br, David

Quoted 11 lines

So in practice when ever dwc3 is powered we will be able to access ULPI for as long as the USB2 PHY interface is not suspended separately with GUSB2PHYCFG SusPHY bit. And even then we would only need to resume it with the same bit and ULPI is accessible again.

Cheers,

Signature · 1 line
heikki
author maintainer
#20 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

In reply to David Cohen
Quoted 29 lines · David Cohen
Quoted 15 lines · Heikki Krogerus
Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Quoted 4 lines

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

I just double checked DWC3 TRM.
You are correct, by the time we're executing dwc3_core_soft_reset() ULPI bus is already accessible. But the TRM also specifies an ULPI phy would be reset by DCTL's core soft reset, which is executed by dwc3_core_init() before calling dwc3_core_soft_reset(). It does mention DWC3 writes data to an ULPI phy register during reset, but it also mentions the clock sync happens during that time.

Quoted 6 lines

That makes no even OK, but more correct IMO to power on phy before core's soft reset (i.e. by ACPI methods). But it lets us in a grey area whether ULPI is reliably accessible before core's soft reset.

I believe if you move the dwc3_ulpi_init() to dwc3_core_init(), after core's soft reset we've got no more grey area.

Well, we have already requested the phys in dwc3_probe before that so some refactoring will be needed. It's probable no a problem.

Btw, I'm sorry about telling this so late, but I'm going to be on vacation for the next two weeks.

Cheers,

Signature · 1 line
heikki
#21 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Hi Heikki,

Quoted 34 lines · Heikki Krogerus
Quoted 33 lines · David Cohen
Quoted 15 lines · Heikki Krogerus
Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Quoted 4 lines

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

I just double checked DWC3 TRM.
You are correct, by the time we're executing dwc3_core_soft_reset() ULPI bus is already accessible. But the TRM also specifies an ULPI phy would be reset by DCTL's core soft reset, which is executed by dwc3_core_init() before calling dwc3_core_soft_reset(). It does mention DWC3 writes data to an ULPI phy register during reset, but it also mentions the clock sync happens during that time.

That makes no even OK, but more correct IMO to power on phy before core's soft reset (i.e. by ACPI methods). But it lets us in a grey area whether ULPI is reliably accessible before core's soft reset.

Quoted 5 lines
Quoted 2 lines

I believe if you move the dwc3_ulpi_init() to dwc3_core_init(), after core's soft reset we've got no more grey area.

Well, we have already requested the phys in dwc3_probe before that so some refactoring will be needed. It's probable no a problem.

Sounds good :)

Quoted 3 lines

Btw, I'm sorry about telling this so late, but I'm going to be on vacation for the next two weeks.

Thanks for the notice.

Br, David

Quoted 6 lines

Cheers,

Signature · 1 line
heikki
#22 lore raw

Re: [PATCH 6/8] usb: dwc3: add ULPI interface support

Quoted 43 lines · David Cohen

Hi Heikki,

Quoted 34 lines · Heikki Krogerus
Quoted 33 lines · David Cohen
Quoted 15 lines · Heikki Krogerus
Quoted 8 lines
Quoted 8 lines
drivers/usb/dwc3/core.c +0 -0
index a8c9062..66cbf38 100644
@@ -879,6 +879,10 @@ static int dwc3_probe(struct platform_device *pdev)
 	platform_set_drvdata(pdev, dwc);
 	dwc3_cache_hwparams(dwc);
 
Quoted 6 lines

drivers/usb/dwc3/core.c static int dwc3_probe(struct platform_device *pdev) · line 882

Quoted 1 line
drivers/usb/dwc3/core.c +1 -0
+	ret = dwc3_ulpi_init(dwc);

If I understood correctly, this call will result in enumerating the phy via ULPI bus, then registering the correct ULPI device.
Can you guarantee ULPI will be always accessible at this point if we remove dwc3 module and load it again?

Quoted 4 lines

OK, got it. So yes, I can guarantee that ULPI will be acessible at this point. If we are in a state where we could soft reset dwc3, we know we can access ULPI. The fact that dwc3 itself expects to be able to write to the ULPI registers at that point guarantees it for us.

I just double checked DWC3 TRM.
You are correct, by the time we're executing dwc3_core_soft_reset() ULPI bus is already accessible. But the TRM also specifies an ULPI phy would be reset by DCTL's core soft reset, which is executed by dwc3_core_init() before calling dwc3_core_soft_reset(). It does mention DWC3 writes data to an ULPI phy register during reset, but it also mentions the clock sync happens during that time.

That makes no even OK, but more correct IMO to power on phy before core's soft reset (i.e. by ACPI methods). But it lets us in a grey area whether ULPI is reliably accessible before core's soft reset.

Quoted 5 lines
Quoted 2 lines

I believe if you move the dwc3_ulpi_init() to dwc3_core_init(), after core's soft reset we've got no more grey area.

Well, we have already requested the phys in dwc3_probe before that so some refactoring will be needed. It's probable no a problem.

Quoted 7 lines

Sounds good :)

Quoted 3 lines

Btw, I'm sorry about telling this so late, but I'm going to be on vacation for the next two weeks.

Thanks for the notice.

you'll be back right around merge window closing time :-) Not to worry, we'll have time to get this into the next merge window.

Signature · 1 line
balbi
author maintainer
#23 lore raw

PATCH 7/8 phy: helpers for USB ULPI PHY registering

In reply to Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +31 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));
+	if (ret) {
+		phy_destroy(phy);
+		return ERR_PTR(ret);
+	}
+
+	return phy;
+}
+
+/* Remove a PHY that was created with ulpi_phy_create() and it's lookup. */
+static inline void ulpi_phy_destroy(struct ulpi *ulpi, struct phy *phy)
+{
+	phy_remove_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));
+	phy_destroy(phy);
+}
Signature · 1 line
2.1.4
#24 lore raw

Re: [PATCH 7/8] phy: helpers for USB ULPI PHY registering

Quoted 25 lines · Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +7 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy

drivers/phy/ulpi_phy.h line 17

Quoted 10 lines
drivers/phy/ulpi_phy.h new file +10 -0
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));

I wonder if this would break DT-based boot where PHY phandle is available. Kishon ?

Signature · 1 line
balbi
author maintainer
#25 lore raw

Re: [PATCH 7/8] phy: helpers for USB ULPI PHY registering

Quoted 31 lines · Felipe Balbi
Quoted 30 lines · Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +12 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
Quoted 8 lines

drivers/phy/ulpi_phy.h line 17

Quoted 5 lines
drivers/phy/ulpi_phy.h new file +5 -0
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));

I wonder if this would break DT-based boot where PHY phandle is available. Kishon ?

If there are of_node for the PHY, we will not use this binding at all.

Br,

Signature · 1 line
heikki
#26 lore raw

Re: [PATCH 7/8] phy: helpers for USB ULPI PHY registering

Quoted 41 lines · Heikki Krogerus
Quoted 31 lines · Felipe Balbi
Quoted 30 lines · Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +12 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
Quoted 8 lines

drivers/phy/ulpi_phy.h line 17

Quoted 5 lines
drivers/phy/ulpi_phy.h new file +5 -0
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));

I wonder if this would break DT-based boot where PHY phandle is available. Kishon ?

Quoted 1 line

If there are of_node for the PHY, we will not use this binding at all.

where is that taken care of ? ulpi_phy_create() is called unconditionally.

Signature · 1 line
balbi
author maintainer
#27 lore raw

Re: [PATCH 7/8] phy: helpers for USB ULPI PHY registering

Quoted 42 lines · Felipe Balbi
Quoted 41 lines · Heikki Krogerus
Quoted 39 lines · Felipe Balbi
Quoted 25 lines · Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +7 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy

drivers/phy/ulpi_phy.h line 17

Quoted 10 lines
drivers/phy/ulpi_phy.h new file +10 -0
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));

I wonder if this would break DT-based boot where PHY phandle is available. Kishon ?

Quoted 4 lines
Quoted 1 line

If there are of_node for the PHY, we will not use this binding at all.

where is that taken care of ? ulpi_phy_create() is called unconditionally.

When you call phy_get().

Signature · 1 line
heikki
#28 lore raw

Re: [PATCH 7/8] phy: helpers for USB ULPI PHY registering

Quoted 43 lines · Heikki Krogerus
Quoted 42 lines · Felipe Balbi
Quoted 41 lines · Heikki Krogerus
Quoted 39 lines · Felipe Balbi
Quoted 25 lines · Heikki Krogerus

ULPI PHYs need to be bound to their controllers with a lookup. This adds helpers that the ULPI drivers can use to do both, the registration of the PHY and the lookup, at the same time.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/ulpi_phy.h | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
 create mode 100644 drivers/phy/ulpi_phy.h
drivers/phy/ulpi_phy.h new file +7 -0
new file mode 100644
index 0000000..ac49fb6
@@ -0,0 +1,31 @@
+#include <linux/phy/phy.h>
+
+/**
+ * Helper that registers PHY for a ULPI device and adds a lookup for binding it
+ * and it's controller, which is always the parent.
+ */
+static inline struct phy

drivers/phy/ulpi_phy.h line 17

Quoted 10 lines
drivers/phy/ulpi_phy.h new file +10 -0
+*ulpi_phy_create(struct ulpi *ulpi, struct phy_ops *ops)
+{
+	struct phy *phy;
+	int ret;
+
+	phy = phy_create(&ulpi->dev, NULL, ops);
+	if (IS_ERR(phy))
+		return phy;
+
+	ret = phy_create_lookup(phy, "usb2-phy", dev_name(ulpi->dev.parent));

I wonder if this would break DT-based boot where PHY phandle is available. Kishon ?

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

If there are of_node for the PHY, we will not use this binding at all.

where is that taken care of ? ulpi_phy_create() is called unconditionally.

When you call phy_get().

tks

Signature · 1 line
balbi
author maintainer
#29 lore raw

PATCH 8/8 phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/Kconfig        |   6 ++
 drivers/phy/Makefile       |   1 +
 drivers/phy/phy-tusb1210.c | 133 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/phy/phy-tusb1210.c
drivers/phy/Kconfig +6 -0
index 26a7623..52ee720 100644
@@ -284,4 +284,10 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_TUSB1210
+	tristate "TI TUSB1210 ULPI PHY module"
+	depends on USB_ULPI_BUS
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
 endmenu
drivers/phy/Makefile +1 -0
index cfbb720..03f3d85 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-20nm.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-14nm.o
+obj-$(CONFIG_PHY_TUSB1210)		+= phy-tusb1210.o
drivers/phy/phy-tusb1210.c new file +133 -0

133 lines not on this page · raw message

Signature · 1 line
2.1.4
#30 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi Heikki,

Quoted 72 lines · Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/Kconfig        |   6 ++
 drivers/phy/Makefile       |   1 +
 drivers/phy/phy-tusb1210.c | 133 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/phy/phy-tusb1210.c
drivers/phy/Kconfig +6 -0
index 26a7623..52ee720 100644
@@ -284,4 +284,10 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_TUSB1210
+	tristate "TI TUSB1210 ULPI PHY module"
+	depends on USB_ULPI_BUS
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
 endmenu
drivers/phy/Makefile +1 -0
index cfbb720..03f3d85 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-20nm.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-14nm.o
+obj-$(CONFIG_PHY_TUSB1210)		+= phy-tusb1210.o
drivers/phy/phy-tusb1210.c new file +27 -0
new file mode 100644
index 0000000..1551ae8
@@ -0,0 +1,133 @@
+/**
+ * tusb1210.c - TUSB1210 USB ULPI PHY driver
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * Author: Heikki Krogerus <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/ulpi/driver.h>
+#include <linux/gpio/consumer.h>
+
+#include "ulpi_phy.h"
+
+#define TUSB1210_VENDOR_SPECIFIC2 0x80
+
+struct tusb1210 {
+	struct ulpi *ulpi;
+	struct phy *phy;
+	struct gpio_desc *gpio_reset;
+	struct gpio_desc *gpio_cs;
+	u8 eye_diagram_tuning;
+};
+

drivers/phy/phy-tusb1210.c line 37

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);

After you power on phy, ulpi bus may not be available right away. In intel case, phy power on happens during dwc3 power on. ULPI bus is not available until OTG controller and phy are in sync.

In resume, you can't restore eye diagram from here.

Quoted 29 lines
drivers/phy/phy-tusb1210.c new file +29 -0
+
+	return 0;
+}
+
+static int tusb1210_power_off(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 0);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 0);
+
+	return 0;
+}
+
+static struct phy_ops phy_ops = {
+	.power_on = tusb1210_power_on,
+	.power_off = tusb1210_power_off,
+	.init = tusb1210_power_on,
+	.exit = tusb1210_power_off,
+	.owner = THIS_MODULE,
+};
+
+static int tusb1210_probe(struct ulpi *ulpi)
+{
+	struct gpio_desc *gpio;
+	struct tusb1210 *tusb;
+	int ret;
+
+	tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);

drivers/phy/phy-tusb1210.c line 76

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+	if (!tusb)
+		return -ENOMEM;
+
+	gpio = devm_gpiod_get(&ulpi->dev, "reset");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_reset = gpio;
+	}

You cannot proceed with probe if gpio reset is not available. Different from CS, it's a mandatory pin to toggle in order to power on/off phy and get it in sync with OTG controller.

drivers/phy/phy-tusb1210.c line 87

Quoted 11 lines
drivers/phy/phy-tusb1210.c new file +11 -0
+
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_cs = gpio;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

It's unclear if ulpi is accessible at this point. You can't read it at this point.

Br, David

Quoted 53 lines
drivers/phy/phy-tusb1210.c new file +46 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->eye_diagram_tuning = ret;
+
+	tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
+	if (IS_ERR(tusb->phy))
+		return PTR_ERR(tusb->phy);
+
+	tusb->ulpi = ulpi;
+
+	phy_set_drvdata(tusb->phy, tusb);
+	ulpi_set_drvdata(ulpi, tusb);
+	return 0;
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = ulpi_get_drvdata(ulpi);
+
+	ulpi_phy_destroy(ulpi, tusb->phy);
+}
+
+#define TI_VENDOR_ID 0x0451
+
+static const struct ulpi_device_id tusb1210_ulpi_id[] = {
+	{ TI_VENDOR_ID, 0x1508, },
+	{ },
+};
+MODULE_DEVICE_TABLE(ulpi, tusb1210_ulpi_id);
+
+static struct ulpi_driver tusb1210_driver = {
+	.id_table = tusb1210_ulpi_id,
+	.probe = tusb1210_probe,
+	.remove = tusb1210_remove,
+	.driver = {
+		.name = "tusb1210",
+		.owner = THIS_MODULE,
+	},
+};
+
+module_ulpi_driver(tusb1210_driver);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("TUSB1210 ULPI PHY driver");
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#31 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi David,

Quoted 15 lines · David Cohen

drivers/phy/phy-tusb1210.c line 37

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);

After you power on phy, ulpi bus may not be available right away. In intel case, phy power on happens during dwc3 power on. ULPI bus is not available until OTG controller and phy are in sync.

Quoted 1 line

In resume, you can't restore eye diagram from here.

I'm sorry but I don't think I understand? Where do we power on the phy before dwc3 is powered on? Or is this a Baytrail-CR specific problem? I can't see any problems with the hardware I have.

In any case, this sounds like purely dwc3 issue and not tusb1210 issue.

Quoted 13 lines
Quoted 13 lines
drivers/phy/phy-tusb1210.c new file +13 -0
+static int tusb1210_probe(struct ulpi *ulpi)
+{
+	struct gpio_desc *gpio;
+	struct tusb1210 *tusb;
+	int ret;
+
+	tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
+	if (!tusb)
+		return -ENOMEM;
+
+	gpio = devm_gpiod_get(&ulpi->dev, "reset");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
Quoted 8 lines

drivers/phy/phy-tusb1210.c line 76

Quoted 4 lines
drivers/phy/phy-tusb1210.c new file +4 -0
+		if (ret)
+			return ret;
+		tusb->gpio_reset = gpio;
+	}

You cannot proceed with probe if gpio reset is not available. Different from CS, it's a mandatory pin to toggle in order to power on/off phy and get it in sync with OTG controller.

Well, let's check -ENOENT and -ENODEV return values separately. The reset pin is not used on all platforms so getting this gpio is optional. This is the case even with some Intel's platforms using TUSB1210.

Quoted 6 lines
Quoted 6 lines
drivers/phy/phy-tusb1210.c new file +6 -0
+
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
Quoted 8 lines

drivers/phy/phy-tusb1210.c line 87

Quoted 5 lines
drivers/phy/phy-tusb1210.c new file +5 -0
+		tusb->gpio_cs = gpio;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

It's unclear if ulpi is accessible at this point. You can't read it at this point.

We wouldn't have reached this point if ulpi wasn't accessible. Registering the ulpi interface would have already failed so no driver would have been probed.

Thanks!

Signature · 1 line
heikki
#32 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi Heikki,

Quoted 18 lines · Heikki Krogerus

Hi David,

Quoted 15 lines · David Cohen

drivers/phy/phy-tusb1210.c line 37

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);

After you power on phy, ulpi bus may not be available right away. In intel case, phy power on happens during dwc3 power on. ULPI bus is not available until OTG controller and phy are in sync.

Quoted 5 lines
Quoted 1 line

In resume, you can't restore eye diagram from here.

I'm sorry but I don't think I understand? Where do we power on the phy before dwc3 is powered on? Or is this a Baytrail-CR specific problem? I can't see any problems with the hardware I have.

You can't see in single accesses. But you may see when running stability tests overnight.

Anyway, look for dwc3_core_soft_reset() function:
- dwc3 goes to reset state
- phy is initialized (or at least gets ready to sync clocks)
- dwc3 goes out or reset state

During tusb1210 phy init from dwc3, you shouldn't access ulpi bus.

Quoted 3 lines

In any case, this sounds like purely dwc3 issue and not tusb1210 issue.

That's neither purely dwc3's not tusb1210's, that's your problem :) Since it's a potential bug introduced by your patch set here.

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/phy/phy-tusb1210.c new file +13 -0
+static int tusb1210_probe(struct ulpi *ulpi)
+{
+	struct gpio_desc *gpio;
+	struct tusb1210 *tusb;
+	int ret;
+
+	tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
+	if (!tusb)
+		return -ENOMEM;
+
+	gpio = devm_gpiod_get(&ulpi->dev, "reset");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
Quoted 8 lines

drivers/phy/phy-tusb1210.c line 76

Quoted 4 lines
drivers/phy/phy-tusb1210.c new file +4 -0
+		if (ret)
+			return ret;
+		tusb->gpio_reset = gpio;
+	}

You cannot proceed with probe if gpio reset is not available. Different from CS, it's a mandatory pin to toggle in order to power on/off phy and get it in sync with OTG controller.

Quoted 4 lines

Well, let's check -ENOENT and -ENODEV return values separately. The reset pin is not used on all platforms so getting this gpio is optional. This is the case even with some Intel's platforms using TUSB1210.

I doublechecked the tusb1210 datasheet. Despite the power on sequence mentions RESET toggling as required, it has a comment later on that it can be tied to VDDIO.
So as you mentioned, it'd be better to ignore -ENOENT and -ENODEV and raise error otherwise.

Quoted 16 lines
Quoted 15 lines

drivers/phy/phy-tusb1210.c line 87

Quoted 12 lines
drivers/phy/phy-tusb1210.c new file +11 -0
+
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_cs = gpio;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

It's unclear if ulpi is accessible at this point. You can't read it at this point.

Quoted 3 lines

We wouldn't have reached this point if ulpi wasn't accessible. Registering the ulpi interface would have already failed so no driver would have been probed.

You have a chicken/egg problem here:
- dwc3 needs phy to complete soft reset during probe
- tusb1210 needs dwc3 soft reset completed to be accessible via ULPI

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

Br, David

Quoted 6 lines

Thanks!

Signature · 1 line
heikki
author maintainer
#33 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 23 lines · David Cohen
Quoted 16 lines · Heikki Krogerus
Quoted 15 lines · David Cohen

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);

After you power on phy, ulpi bus may not be available right away. In intel case, phy power on happens during dwc3 power on. ULPI bus is not available until OTG controller and phy are in sync.

Quoted 5 lines
Quoted 1 line

In resume, you can't restore eye diagram from here.

I'm sorry but I don't think I understand? Where do we power on the phy before dwc3 is powered on? Or is this a Baytrail-CR specific problem? I can't see any problems with the hardware I have.

Quoted 7 lines

You can't see in single accesses. But you may see when running stability tests overnight.

Anyway, look for dwc3_core_soft_reset() function:
- dwc3 goes to reset state
- phy is initialized (or at least gets ready to sync clocks)
- dwc3 goes out or reset state

And if you look at dwc3_probe, you'll notice that it calls phy_power_on after that, and ulpi will most definitely be accessible at that point.

I'm only using the init and exit hooks instead of just power_on/power_off because I'm not sure which the controllers will use. For example, now dwc3 calls phy_init() in it's resume routine and not phy_power_on() like I would expect. I know the problem has been pointed out by others, so I'm expecting we'll get guidelines for it later. But before we do, I see no harm in having both init and power_on hooks in this driver.

Quoted 1 line

During tusb1210 phy init from dwc3, you shouldn't access ulpi bus.

We will end up executing one failed write followed by write that we know will succeed. Ideally we didn't have to do the first one at all, but I don't see any risk here.

Quoted 18 lines
Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
(quoted diff) +5 -0
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
Quoted 8 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+		tusb->gpio_cs = gpio;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

It's unclear if ulpi is accessible at this point. You can't read it at this point.

Quoted 3 lines

We wouldn't have reached this point if ulpi wasn't accessible. Registering the ulpi interface would have already failed so no driver would have been probed.

Quoted 8 lines

You have a chicken/egg problem here:
- dwc3 needs phy to complete soft reset during probe
- tusb1210 needs dwc3 soft reset completed to be accessible via ULPI

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

Thanks,

Signature · 1 line
heikki
drivers/usb/dwc3/dwc3-pci.c +19 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
 		struct dwc3_platform_data pdata;
author maintainer
#34 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi guys,

Quoted 7 lines

I'm only using the init and exit hooks instead of just power_on/power_off because I'm not sure which the controllers will use. For example, now dwc3 calls phy_init() in it's resume routine and not phy_power_on() like I would expect. I know the problem has been pointed out by others, so I'm expecting we'll get guidelines for it later. But before we do, I see no harm in having both init and power_on hooks in this driver.

I'm unable to find the thread where somebody mentioned that, but I don't actually think there is any reason why we couldn't just call phy_power_on/off instead of phy_init/exit in dwc3_suspend/resume like I think we should. I'll add one more patch where I'll change it.

Felipe, is it OK?

Thanks,

Signature · 1 line
heikki
#35 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus
Quoted 36 lines · Heikki Krogerus
Quoted 23 lines · David Cohen
Quoted 16 lines · Heikki Krogerus
Quoted 15 lines · David Cohen

Review

Quoted 10 lines
(quoted diff) +10 -0
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);

After you power on phy, ulpi bus may not be available right away. In intel case, phy power on happens during dwc3 power on. ULPI bus is not available until OTG controller and phy are in sync.

Quoted 5 lines
Quoted 1 line

In resume, you can't restore eye diagram from here.

I'm sorry but I don't think I understand? Where do we power on the phy before dwc3 is powered on? Or is this a Baytrail-CR specific problem? I can't see any problems with the hardware I have.

Quoted 7 lines

You can't see in single accesses. But you may see when running stability tests overnight.

Anyway, look for dwc3_core_soft_reset() function:
- dwc3 goes to reset state
- phy is initialized (or at least gets ready to sync clocks)
- dwc3 goes out or reset state

And if you look at dwc3_probe, you'll notice that it calls phy_power_on after that, and ulpi will most definitely be accessible at that point.

Quoted 7 lines

I'm only using the init and exit hooks instead of just power_on/power_off because I'm not sure which the controllers will use. For example, now dwc3 calls phy_init() in it's resume routine and not phy_power_on() like I would expect. I know the problem has been pointed out by others, so I'm expecting we'll get guidelines for it later. But before we do, I see no harm in having both init and power_on hooks in this driver.

It sounds hackish to me. You could clearly change the logic on init/power_on callbacks to avoid this problem.

Quoted 6 lines
Quoted 2 lines

During tusb1210 phy init from dwc3, you shouldn't access ulpi bus.

We will end up executing one failed write followed by write that we know will succeed. Ideally we didn't have to do the first one at all, but I don't see any risk here.

Ditto.

Quoted 23 lines
Quoted 23 lines
Quoted 15 lines
Quoted 14 lines

Review

Quoted 11 lines
(quoted diff) +10 -0
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_cs = gpio;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

It's unclear if ulpi is accessible at this point. You can't read it at this point.

Quoted 3 lines

We wouldn't have reached this point if ulpi wasn't accessible. Registering the ulpi interface would have already failed so no driver would have been probed.

You have a chicken/egg problem here:
- dwc3 needs phy to complete soft reset during probe
- tusb1210 needs dwc3 soft reset completed to be accessible via ULPI

Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state. The real problem is what I stated above. With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

Quoted 6 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

Br, David

Quoted 44 lines

Thanks,

Signature · 1 line
heikki
drivers/usb/dwc3/dwc3-pci.c +19 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
 		struct dwc3_platform_data pdata;
author maintainer
#36 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi,

Quoted 21 lines
Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

Quoted 3 lines

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state.

But it is. If we want to use ULPI as a bus like we do, then the PHY will be no different then devices attached to many other buses. We have made firmware fixes like that before. All the devices need to be in a state, operational enough after bootup, so we can probe them in OS without the need for hacks where they are separately enabled before it's possible.

Quoted 4 lines

The real problem is what I stated above.
With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

The moment we register the ulpi interface with the ulpi bus in dwc3_probe(), we know dwc3 has it's PHY interface in operational mode and register access to ULPI PHY is possible. And that is all dwc3 needs to/can do.

I don't think you are seeing the whole "ulpi bus" in these patches, but in any case; Like I said, this problem is purely BYT-CR specific, which IMO really should be fixed in the firmware.

Quoted 10 lines
Quoted 5 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

I think you are now talking about the platform devices for the legacy USB PHY framework created in dwc3-pci.c, which btw. were removed. Please note that we are not using platform bus with the ULPI devices, and those devices are created by the bus driver and not dwc3.

I'm pretty sure now that you are not seeing the whole point with this set, which is to provide new bus type for ULPI. If so, then could you please review the whole series.

Thanks,

Signature · 1 line
heikki
#37 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 27 lines · Heikki Krogerus

Hi,

Quoted 21 lines
Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

Quoted 3 lines

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state.

Quoted 6 lines

But it is. If we want to use ULPI as a bus like we do, then the PHY will be no different then devices attached to many other buses. We have made firmware fixes like that before. All the devices need to be in a state, operational enough after bootup, so we can probe them in OS without the need for hacks where they are separately enabled before it's possible.

That makes no sense. Not only dwc3 and phy could live as modules (which means they may probe far away from device's boot time) but we have examples of buses not behaving like you said. E.g. I2C needs master to be probed to have bus working and no BIOS needs to make I2C controller functional in order to probe its controller's driver.

Quoted 6 lines
Quoted 5 lines

The real problem is what I stated above.
With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

Quoted 8 lines

The moment we register the ulpi interface with the ulpi bus in dwc3_probe(), we know dwc3 has it's PHY interface in operational mode and register access to ULPI PHY is possible. And that is all dwc3 needs to/can do.

I don't think you are seeing the whole "ulpi bus" in these patches, but in any case; Like I said, this problem is purely BYT-CR specific, which IMO really should be fixed in the firmware.

The proposed design has a flaw that breaks products on market simply because they don't have BIOS (unnecessarily) powering on phy. You're labeling that as BYT-CR specific issue because BYT-CR needs to be PM efficient and then it won't power on hw components in moment they don't need to. FW developers won't like this suggestion and I'd have to agree with them.

Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

Quoted 4 lines

I think you are now talking about the platform devices for the legacy USB PHY framework created in dwc3-pci.c, which btw. were removed. Please note that we are not using platform bus with the ULPI devices, and those devices are created by the bus driver and not dwc3.

Yes, that the one. Current products' BIOS on market didn't know about new ULPI bus. They rely on platform devices created by pci probe. Your ULPI bus proposal is way better to handle that problem and got my support since they beginning you showed that to me, but it does not justify breaking current working devices. Removing the platform device registration for phy with firmwares that rely on that was a mistake and any ACPI work related to fix that is unnecessary. These legacy ACPI tables gave the phy-related GPIOs to dwc3. Just mark is as legacy situation and let the legacy hw's happy. No vendor will change their BIOS after market due to non-buggy situation.

Quoted 4 lines

I'm pretty sure now that you are not seeing the whole point with this set, which is to provide new bus type for ULPI. If so, then could you please review the whole series.

I'll review the whole series. But pls note your design requires vendors to change their FW (including but not limited to ACPI table) after market. That won't happen.

Br, David

Quoted 6 lines

Thanks,

Signature · 1 line
heikki
author maintainer
#38 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 32 lines
Quoted 25 lines
Quoted 21 lines
Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

Quoted 3 lines

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state.

Quoted 6 lines

But it is. If we want to use ULPI as a bus like we do, then the PHY will be no different then devices attached to many other buses. We have made firmware fixes like that before. All the devices need to be in a state, operational enough after bootup, so we can probe them in OS without the need for hacks where they are separately enabled before it's possible.

Quoted 5 lines

That makes no sense. Not only dwc3 and phy could live as modules (which means they may probe far away from device's boot time) but we have examples of buses not behaving like you said. E.g. I2C needs master to be probed to have bus working and no BIOS needs to make I2C controller functional in order to probe its controller's driver.

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 14 lines
Quoted 5 lines
Quoted 4 lines

The real problem is what I stated above.
With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

Quoted 8 lines

The moment we register the ulpi interface with the ulpi bus in dwc3_probe(), we know dwc3 has it's PHY interface in operational mode and register access to ULPI PHY is possible. And that is all dwc3 needs to/can do.

I don't think you are seeing the whole "ulpi bus" in these patches, but in any case; Like I said, this problem is purely BYT-CR specific, which IMO really should be fixed in the firmware.

Quoted 6 lines

The proposed design has a flaw that breaks products on market simply because they don't have BIOS (unnecessarily) powering on phy. You're labeling that as BYT-CR specific issue because BYT-CR needs to be PM efficient and then it won't power on hw components in moment they don't need to. FW developers won't like this suggestion and I'd have to agree with them.

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

Quoted 4 lines

I think you are now talking about the platform devices for the legacy USB PHY framework created in dwc3-pci.c, which btw. were removed. Please note that we are not using platform bus with the ULPI devices, and those devices are created by the bus driver and not dwc3.

Quoted 10 lines

Yes, that the one. Current products' BIOS on market didn't know about new ULPI bus. They rely on platform devices created by pci probe. Your ULPI bus proposal is way better to handle that problem and got my support since they beginning you showed that to me, but it does not justify breaking current working devices. Removing the platform device registration for phy with firmwares that rely on that was a mistake and any ACPI work related to fix that is unnecessary. These legacy ACPI tables gave the phy-related GPIOs to dwc3. Just mark is as legacy situation and let the legacy hw's happy. No vendor will change their BIOS after market due to non-buggy situation.

Well, I'm really not expecting any BIOS updates any more. I assumed that was clear. Why else would I have started the whole planning of the GPIO forwarding. But if it wasn't, then sorry. Now you know.

BYT-CR's USB is not supported in mainline yet unless I'm completely mistaken, but we have the plan for it. Instead of trying to take any shortcuts, let's follow that plan.

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

Then we'll pass the GPIO to the PHY driver in the same quirk once we have the support for it in gpiolib.

Thanks,

Signature · 1 line
heikki
drivers/usb/dwc3/dwc3-pci.c +19 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
 		struct dwc3_platform_data pdata;
#39 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi

Quoted 32 lines · Heikki Krogerus
Quoted 32 lines
Quoted 31 lines
Quoted 21 lines
Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

Quoted 3 lines

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state.

But it is. If we want to use ULPI as a bus like we do, then the PHY will be no different then devices attached to many other buses. We have made firmware fixes like that before. All the devices need to be in a state, operational enough after bootup, so we can probe them in OS without the need for hacks where they are separately enabled before it's possible.

Quoted 8 lines
Quoted 5 lines

That makes no sense. Not only dwc3 and phy could live as modules (which means they may probe far away from device's boot time) but we have examples of buses not behaving like you said. E.g. I2C needs master to be probed to have bus working and no BIOS needs to make I2C controller functional in order to probe its controller's driver.

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

Quoted 21 lines
Quoted 14 lines
Quoted 5 lines
Quoted 4 lines

The real problem is what I stated above.
With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

Quoted 8 lines

The moment we register the ulpi interface with the ulpi bus in dwc3_probe(), we know dwc3 has it's PHY interface in operational mode and register access to ULPI PHY is possible. And that is all dwc3 needs to/can do.

I don't think you are seeing the whole "ulpi bus" in these patches, but in any case; Like I said, this problem is purely BYT-CR specific, which IMO really should be fixed in the firmware.

Quoted 6 lines

The proposed design has a flaw that breaks products on market simply because they don't have BIOS (unnecessarily) powering on phy. You're labeling that as BYT-CR specific issue because BYT-CR needs to be PM efficient and then it won't power on hw components in moment they don't need to. FW developers won't like this suggestion and I'd have to agree with them.

Quoted 3 lines

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

one comment below on this.

Quoted 5 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

Quoted 31 lines
Quoted 16 lines
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

Quoted 4 lines

I think you are now talking about the platform devices for the legacy USB PHY framework created in dwc3-pci.c, which btw. were removed. Please note that we are not using platform bus with the ULPI devices, and those devices are created by the bus driver and not dwc3.

Quoted 10 lines

Yes, that the one. Current products' BIOS on market didn't know about new ULPI bus. They rely on platform devices created by pci probe. Your ULPI bus proposal is way better to handle that problem and got my support since they beginning you showed that to me, but it does not justify breaking current working devices. Removing the platform device registration for phy with firmwares that rely on that was a mistake and any ACPI work related to fix that is unnecessary. These legacy ACPI tables gave the phy-related GPIOs to dwc3. Just mark is as legacy situation and let the legacy hw's happy. No vendor will change their BIOS after market due to non-buggy situation.

Well, I'm really not expecting any BIOS updates any more. I assumed that was clear. Why else would I have started the whole planning of the GPIO forwarding. But if it wasn't, then sorry. Now you know.

Quoted 6 lines

BYT-CR's USB is not supported in mainline yet unless I'm completely mistaken, but we have the plan for it. Instead of trying to take any shortcuts, let's follow that plan.

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Quoted 23 lines
drivers/usb/dwc3/dwc3-pci.c +8 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);

drivers/usb/dwc3/dwc3-pci.c line 55

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Signature · 1 line
balbi
#40 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi Heikki, Felipe,

Quoted 41 lines · Felipe Balbi

Hi

Quoted 38 lines · Heikki Krogerus
Quoted 37 lines
Quoted 25 lines
Quoted 21 lines
Quoted 7 lines
Quoted 4 lines

Can you share how tusb1210 is connected on the platform you're using as test for this patch? I don't think this driver would work reliably with this device:
http://liliputing.com/2014/11/trekstor-launches-first-android-tablet-based-intels-irda-reference-design.html

The only reason why that board doesn't work is because of very much Baytrail-CR specific problems. These are are two issues, but the first

That's not BYT-CR specific problems. That's just dwc3 and tusb1210 interacting as they're expecting to.

Quoted 9 lines

one is critical for getting it working. Both will be handled, but separately from this set:

1) The firmware leaves the PHY in reset, forcing us to enable it somehow in OS before accessing ulpi. Unless we can get a firmware fix for that (it's starting to look like it's not going to happen; please correct me if you know something else!), we need to add a quirk for Baytrails (attached), which is probable still OK. But IMO this really should be fixed in the firmware.

Quoted 3 lines

It seems you're expecting the PHY to be fully operational in order to probe it. That's wrong assumption. BYT-CR's BIOS is doing nothing wrong by leaving PHY on reset state.

Quoted 6 lines

But it is. If we want to use ULPI as a bus like we do, then the PHY will be no different then devices attached to many other buses. We have made firmware fixes like that before. All the devices need to be in a state, operational enough after bootup, so we can probe them in OS without the need for hacks where they are separately enabled before it's possible.

That makes no sense. Not only dwc3 and phy could live as modules (which means they may probe far away from device's boot time) but we have examples of buses not behaving like you said. E.g. I2C needs master to be probed to have bus working and no BIOS needs to make I2C controller functional in order to probe its controller's driver.

Quoted 30 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

Quoted 24 lines
Quoted 14 lines
Quoted 5 lines
Quoted 4 lines

The real problem is what I stated above.
With your current logic, you'll get stuck with checking/egg problem: you need phy probed to probe dwc3, but need dwc3 probed to power on phy. You need a logic to break this circular dependency.

Quoted 8 lines

The moment we register the ulpi interface with the ulpi bus in dwc3_probe(), we know dwc3 has it's PHY interface in operational mode and register access to ULPI PHY is possible. And that is all dwc3 needs to/can do.

I don't think you are seeing the whole "ulpi bus" in these patches, but in any case; Like I said, this problem is purely BYT-CR specific, which IMO really should be fixed in the firmware.

Quoted 6 lines

The proposed design has a flaw that breaks products on market simply because they don't have BIOS (unnecessarily) powering on phy. You're labeling that as BYT-CR specific issue because BYT-CR needs to be PM efficient and then it won't power on hw components in moment they don't need to. FW developers won't like this suggestion and I'd have to agree with them.

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

It used to work with mainline with minor restrictions. It stopped working (and I failed to catch it during patch review) when NOP phy enumeration was removed from dwc3-pci.c (but my understanding is that Felipe is expecting to add it back as default phy in case no phy is found by dwc3).

BYT-CR worked well except for operations that needed to access phy's registers via ULPI bus (e.g. eye optimization). But to power on i.e. TUSB1210 all you need it to toggle GPIOs, which is done by generic phy. The need for ULPI bus was to complement this missing features, but instead we're breaking BYT-CR :/

Quoted 10 lines

one comment below on this.

Quoted 5 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Let's propose this non-BYT-CR scenario:
You have dwc3/phy powered on by BIOS and dwc3 + phy as modules. You probe the modules for the first time and it works because phy was accessible. Then we remove the modules and load it again. By removing the modules phy is not functional anymore (remove operation will put them in reset state). Then you load the modules again. It certainly will fail to access ULPI bus during phy's probe this time. BYT-CR is just an example where BIOS lets phy in reset during probe, but you can get this same behavior on other platforms too.

Quoted 7 lines
Quoted 6 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

Quoted 5 lines

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

Agree.

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

2) Since the gpio resources are given to the controller device in ACPI tables and there isn't separate device object for the PHY at all, we need to deliver the gpios somehow separately to the phy driver. There is a thread where we are talking about how to do that:
https://lkml.org/lkml/2014/12/18/82

How about just leave the logic the way it is:
dwc3-pci.c registers platform_device with gpio as resource if the GPIOs are provided to dwc3. If not, then dwc3-pci.c will expect phy to have its own ACPI id.

Quoted 4 lines

I think you are now talking about the platform devices for the legacy USB PHY framework created in dwc3-pci.c, which btw. were removed. Please note that we are not using platform bus with the ULPI devices, and those devices are created by the bus driver and not dwc3.

Yes, that the one. Current products' BIOS on market didn't know about new ULPI bus. They rely on platform devices created by pci probe. Your ULPI bus proposal is way better to handle that problem and got my support since they beginning you showed that to me, but it does not justify breaking current working devices. Removing the platform device registration for phy with firmwares that rely on that was a mistake and any ACPI work related to fix that is unnecessary. These legacy ACPI tables gave the phy-related GPIOs to dwc3. Just mark is as legacy situation and let the legacy hw's happy. No vendor will change their BIOS after market due to non-buggy situation.

Quoted 7 lines
Quoted 7 lines

Well, I'm really not expecting any BIOS updates any more. I assumed that was clear. Why else would I have started the whole planning of the GPIO forwarding. But if it wasn't, then sorry. Now you know.

BYT-CR's USB is not supported in mainline yet unless I'm completely mistaken, but we have the plan for it. Instead of trying to take any shortcuts, let's follow that plan.

It is supported, as I stated above. I don't know where you got the idea it wasn't. I made BYT-T (and BYT-CR) + Merrifield USB device layer work with mainline since 3.14. But this patch made the regression to stop working:
https://www.mail-archive.com/[email protected]/msg54400.html

Quoted 5 lines
Quoted 3 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

I agree if we find a way to accomodate products already on market.

Quoted 7 lines
Quoted 4 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Agree with that.

Quoted 29 lines
Quoted 29 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

I'd prefer to go back to platform device case (which is less ugly) for products on market (i.e. legacy and unwanted way for future platforms).

Br, David

Quoted 3 lines
Signature · 2 lines
-- 
balbi
author maintainer
#41 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi,

Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

It used to work with mainline with minor restrictions. It stopped working (and I failed to catch it during patch review) when NOP phy enumeration was removed from dwc3-pci.c (but my understanding is that Felipe is expecting to add it back as default phy in case no phy is found by dwc3).

Quoted 5 lines

BYT-CR worked well except for operations that needed to access phy's registers via ULPI bus (e.g. eye optimization). But to power on i.e. TUSB1210 all you need it to toggle GPIOs, which is done by generic phy. The need for ULPI bus was to complement this missing features, but instead we're breaking BYT-CR :/

So what you are saying that if I get one of those devices you mentioned and try vanilla kernel on it, the USB will work without any modifications to the kernel?

Quoted 9 lines

Let's propose this non-BYT-CR scenario:
You have dwc3/phy powered on by BIOS and dwc3 + phy as modules. You probe the modules for the first time and it works because phy was accessible. Then we remove the modules and load it again. By removing the modules phy is not functional anymore (remove operation will put them in reset state). Then you load the modules again. It certainly will fail to access ULPI bus during phy's probe this time. BYT-CR is just an example where BIOS lets phy in reset during probe, but you can get this same behavior on other platforms too.

You have a point here. I'm curious now what you reply to my question about the possibility to modify DSDT in my previous mail. Because the properties would be a way out of the PHY powering issue.

You know, even if we can't make changes to the DSDT (like I suspect) we can still use the properties once this is accepted:
http://www.spinics.net/lists/linux-acpi/msg55337.html

So we can pass the "ulpi,vendor" and "ulpi,product" also with these generic properties. I'm attaching a patch where I'm converting the platform data AMD uses to them as an example how they could be used.

Quoted 9 lines
Quoted 3 lines
Quoted 3 lines

BYT-CR's USB is not supported in mainline yet unless I'm completely mistaken, but we have the plan for it. Instead of trying to take any shortcuts, let's follow that plan.

It is supported, as I stated above. I don't know where you got the idea it wasn't. I made BYT-T (and BYT-CR) + Merrifield USB device layer work with mainline since 3.14. But this patch made the regression to stop working:
https://www.mail-archive.com/[email protected]/msg54400.html

How can it work with mainline if there was nothing toggling the gpios yet?

Quoted 2 lines

I'd prefer to go back to platform device case (which is less ugly) for products on market (i.e. legacy and unwanted way for future platforms).

We really can't go back to what we had. Please keep in mind that it tied us to the USB PHY framework, possibly forever, and we shouldn't have to depend on two different PHY frameworks. If we have to register the PHY device in dwc3-pci.c then you should create new nop phy for the generic phy framework and use that instead. But before you do that, we better be damn sure there is no way to make ulpi bus work, and we are not there yet.

Have nice weekend guys,

Signature · 1 line
heikki
Quoted 1 line

From 0afd47616c03d268d1c0e2ad5f4108f7f1a2401d Mon Sep 17 00:00:00 2001

From: Heikki Krogerus <[email protected]>
Date: Mon, 12 Jan 2015 16:15:10 +0200
Subject: [PATCH] usb: dwc3: pci: remove use of platform_data

This replaces the platform_data used on AMD Nolan SoC with generic device property.

---
 drivers/usb/dwc3/dwc3-pci.c | 53 ++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 25 deletions(-)
drivers/usb/dwc3/dwc3-pci.c +28 -25
index 8d95056..0f20139 100644
@@ -22,8 +22,6 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 
-#include "platform_data.h"
-
 /* FIXME define these in <linux/pci_ids.h> */
 #define PCI_VENDOR_ID_SYNOPSYS		0x16c3
 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3	0xabcd
@@ -37,34 +35,39 @@ static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
-		struct dwc3_platform_data pdata;
-
-		memset(&pdata, 0, sizeof(pdata));
-
-		pdata.has_lpm_erratum = true;
-		pdata.lpm_nyet_threshold = 0xf;
-
-		pdata.u2exit_lfps_quirk = true;
-		pdata.u2ss_inp3_quirk = true;
-		pdata.req_p1p2p3_quirk = true;
-		pdata.del_p1p2p3_quirk = true;
-		pdata.del_phy_power_chg_quirk = true;
-		pdata.lfps_filter_quirk = true;
-		pdata.rx_detect_poll_quirk = true;
-
-		pdata.tx_de_emphasis_quirk = true;
-		pdata.tx_de_emphasis = 1;
-
+		struct platform_device *dwc3 = pci_get_drvdata(pdev);
+		struct dev_gen_prop *prop;
+
+		prop = devm_kcalloc(&pdev->dev, 14, sizeof(*prop), GFP_KERNEL);
+		if (!prop)
+			return -ENOMEM;
+
+		prop[1].num = devm_kzalloc(&pdev->dev, sizeof(u8 *),
+					   GFP_KERNEL);
+		if (!prop[1].num)
+			return -ENOMEM;
+
+		prop[0].name = "snps,has-lpm-erratum";
+		prop[1].name = "snps,lpm-nyet-threshold";
+		prop[1].nval = 1;
+		prop[1].num[0] = 0xf;
+		prop[2].name = "snps,u2exit_lfps_quirk";
+		prop[3].name = "snps,u2ss_inp3_quirk";
+		prop[4].name = "snps,req_p1p2p3_quirk";
+		prop[5].name = "snps,del_p1p2p3_quirk";
+		prop[6].name = "snps,del_phy_power_chg_quirk";
+		prop[7].name = "snps,lfps_filter_quirk";
+		prop[8].name = "snps,rx_detect_poll_quirk";
+		prop[9].name = "snps,tx_de_emphasis_quirk";
 		/*
 		 * FIXME these quirks should be removed when AMD NL
 		 * taps out
 		 */
-		pdata.disable_scramble_quirk = true;
-		pdata.dis_u3_susphy_quirk = true;
-		pdata.dis_u2_susphy_quirk = true;
+		prop[10].name = "snps,disable_scramble_quirk";
+		prop[11].name = "snps,dis_u3_susphy_quirk";
+		prop[12].name = "snps,dis_u2_susphy_quirk";
 
-		return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
-						sizeof(pdata));
+		dwc3->dev.gen_prop = prop;
 	}
 
 	return 0;
Signature · 1 line
2.1.4
#42 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 18 lines · Heikki Krogerus

Hi,

Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

It used to work with mainline with minor restrictions. It stopped working (and I failed to catch it during patch review) when NOP phy enumeration was removed from dwc3-pci.c (but my understanding is that Felipe is expecting to add it back as default phy in case no phy is found by dwc3).

Quoted 5 lines

BYT-CR worked well except for operations that needed to access phy's registers via ULPI bus (e.g. eye optimization). But to power on i.e. TUSB1210 all you need it to toggle GPIOs, which is done by generic phy. The need for ULPI bus was to complement this missing features, but instead we're breaking BYT-CR :/

Quoted 3 lines

So what you are saying that if I get one of those devices you mentioned and try vanilla kernel on it, the USB will work without any modifications to the kernel?

You're misunderstanding BYT-CR SoC and external board components. The only reason that prevents most of BYT-CR boards' USB device work out-of-the-box is a switch device muxing D+/D- between host and device controllers (they depend on a single GPIO level to be toggled to get USB device working). I started discussion on how to upstream this case, but this is board related, not BYT-CR related. Some boards have also an i2c switch which requires extra i2c driver to get USB device working. But it doesn't mean the phy/otg controllers aren't fully functional with dwc3 + generic phy drivers.

FWIW if you test a board without such switch (e.g. a reference BYT-T board called FFRD8 - BYT-CR is a derivation of BYT-T) it will work out-of-the-box.

Quoted 11 lines
Quoted 10 lines

Let's propose this non-BYT-CR scenario:
You have dwc3/phy powered on by BIOS and dwc3 + phy as modules. You probe the modules for the first time and it works because phy was accessible. Then we remove the modules and load it again. By removing the modules phy is not functional anymore (remove operation will put them in reset state). Then you load the modules again. It certainly will fail to access ULPI bus during phy's probe this time. BYT-CR is just an example where BIOS lets phy in reset during probe, but you can get this same behavior on other platforms too.

Quoted 3 lines

You have a point here. I'm curious now what you reply to my question about the possibility to modify DSDT in my previous mail. Because the properties would be a way out of the PHY powering issue.

You missed my question. Have you tried to remove and reload dwc3 and phy modules with your test case?

Quoted 13 lines

You know, even if we can't make changes to the DSDT (like I suspect) we can still use the properties once this is accepted:
http://www.spinics.net/lists/linux-acpi/msg55337.html

So we can pass the "ulpi,vendor" and "ulpi,product" also with these generic properties. I'm attaching a patch where I'm converting the platform data AMD uses to them as an example how they could be used.

Quoted 4 lines
Quoted 3 lines
Quoted 3 lines

BYT-CR's USB is not supported in mainline yet unless I'm completely mistaken, but we have the plan for it. Instead of trying to take any shortcuts, let's follow that plan.

Quoted 8 lines
Quoted 5 lines

It is supported, as I stated above. I don't know where you got the idea it wasn't. I made BYT-T (and BYT-CR) + Merrifield USB device layer work with mainline since 3.14. But this patch made the regression to stop working:
https://www.mail-archive.com/[email protected]/msg54400.html

How can it work with mainline if there was nothing toggling the gpios yet?

Again, that's board related, not BYT-CR. See my reply above and redo your tests using BYT-T reference board.

Quoted 11 lines
Quoted 3 lines

I'd prefer to go back to platform device case (which is less ugly) for products on market (i.e. legacy and unwanted way for future platforms).

We really can't go back to what we had. Please keep in mind that it tied us to the USB PHY framework, possibly forever, and we shouldn't have to depend on two different PHY frameworks. If we have to register the PHY device in dwc3-pci.c then you should create new nop phy for the generic phy framework and use that instead. But before you do that, we better be damn sure there is no way to make ulpi bus work, and we are not there yet.

You have a point. But the transition should happen without creating regressions. You cannot remove previous design while we don't have the next one merged and functional.

Quoted 4 lines

Have nice weekend guys,

You too :)

Br, David

Quoted 95 lines
Signature · 14 lines
heikki

From 0afd47616c03d268d1c0e2ad5f4108f7f1a2401d Mon Sep 17 00:00:00 2001
From: Heikki Krogerus <[email protected]>
Date: Mon, 12 Jan 2015 16:15:10 +0200
Subject: [PATCH] usb: dwc3: pci: remove use of platform_data

This replaces the platform_data used on AMD Nolan SoC with
generic device property.

Signed-off-by: Heikki Krogerus <[email protected]>
---
 drivers/usb/dwc3/dwc3-pci.c | 53 ++++++++++++++++++++++++---------------------
 1 file changed, 28 insertions(+), 25 deletions(-)
drivers/usb/dwc3/dwc3-pci.c +28 -25
index 8d95056..0f20139 100644
@@ -22,8 +22,6 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 
-#include "platform_data.h"
-
 /* FIXME define these in <linux/pci_ids.h> */
 #define PCI_VENDOR_ID_SYNOPSYS		0x16c3
 #define PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3	0xabcd
@@ -37,34 +35,39 @@ static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
-		struct dwc3_platform_data pdata;
-
-		memset(&pdata, 0, sizeof(pdata));
-
-		pdata.has_lpm_erratum = true;
-		pdata.lpm_nyet_threshold = 0xf;
-
-		pdata.u2exit_lfps_quirk = true;
-		pdata.u2ss_inp3_quirk = true;
-		pdata.req_p1p2p3_quirk = true;
-		pdata.del_p1p2p3_quirk = true;
-		pdata.del_phy_power_chg_quirk = true;
-		pdata.lfps_filter_quirk = true;
-		pdata.rx_detect_poll_quirk = true;
-
-		pdata.tx_de_emphasis_quirk = true;
-		pdata.tx_de_emphasis = 1;
-
+		struct platform_device *dwc3 = pci_get_drvdata(pdev);
+		struct dev_gen_prop *prop;
+
+		prop = devm_kcalloc(&pdev->dev, 14, sizeof(*prop), GFP_KERNEL);
+		if (!prop)
+			return -ENOMEM;
+
+		prop[1].num = devm_kzalloc(&pdev->dev, sizeof(u8 *),
+					   GFP_KERNEL);
+		if (!prop[1].num)
+			return -ENOMEM;
+
+		prop[0].name = "snps,has-lpm-erratum";
+		prop[1].name = "snps,lpm-nyet-threshold";
+		prop[1].nval = 1;
+		prop[1].num[0] = 0xf;
+		prop[2].name = "snps,u2exit_lfps_quirk";
+		prop[3].name = "snps,u2ss_inp3_quirk";
+		prop[4].name = "snps,req_p1p2p3_quirk";
+		prop[5].name = "snps,del_p1p2p3_quirk";
+		prop[6].name = "snps,del_phy_power_chg_quirk";
+		prop[7].name = "snps,lfps_filter_quirk";
+		prop[8].name = "snps,rx_detect_poll_quirk";
+		prop[9].name = "snps,tx_de_emphasis_quirk";
 		/*
 		 * FIXME these quirks should be removed when AMD NL
 		 * taps out
 		 */
-		pdata.disable_scramble_quirk = true;
-		pdata.dis_u3_susphy_quirk = true;
-		pdata.dis_u2_susphy_quirk = true;
+		prop[10].name = "snps,disable_scramble_quirk";
+		prop[11].name = "snps,dis_u3_susphy_quirk";
+		prop[12].name = "snps,dis_u2_susphy_quirk";
 
-		return platform_device_add_data(pci_get_drvdata(pdev), &pdata,
-						sizeof(pdata));
+		dwc3->dev.gen_prop = prop;
 	}
 
 	return 0;
Signature · 1 line
2.1.4
author maintainer
#43 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi David,

Quoted 20 lines
Quoted 16 lines
Quoted 10 lines
Quoted 3 lines
Quoted 3 lines

What exactly are we breaking here? The USB on BYT-CR does not work yet with the mainline kernel, or does it? To enable it, I already suggested the BYT quirk (attached again).

It used to work with mainline with minor restrictions. It stopped working (and I failed to catch it during patch review) when NOP phy enumeration was removed from dwc3-pci.c (but my understanding is that Felipe is expecting to add it back as default phy in case no phy is found by dwc3).

Quoted 5 lines

BYT-CR worked well except for operations that needed to access phy's registers via ULPI bus (e.g. eye optimization). But to power on i.e. TUSB1210 all you need it to toggle GPIOs, which is done by generic phy. The need for ULPI bus was to complement this missing features, but instead we're breaking BYT-CR :/

Quoted 3 lines

So what you are saying that if I get one of those devices you mentioned and try vanilla kernel on it, the USB will work without any modifications to the kernel?

Quoted 9 lines

You're misunderstanding BYT-CR SoC and external board components. The only reason that prevents most of BYT-CR boards' USB device work out-of-the-box is a switch device muxing D+/D- between host and device controllers (they depend on a single GPIO level to be toggled to get USB device working). I started discussion on how to upstream this case, but this is board related, not BYT-CR related. Some boards have also an i2c switch which requires extra i2c driver to get USB device working. But it doesn't mean the phy/otg controllers aren't fully functional with dwc3 + generic phy drivers.

OK, so after we add driver for the mux, are you saying that USB device mode works without need for any patches to dwc3 or the nop phy driver for example with v3.18?

In the code that we had in v3.18, the nop phy platform data had the reset gpio value set to -1 (invalid) by the dwc3-pci, so there was nothing toggling the reset gpio yet and the cs gpio was not handled at all. So unless you are saying we don't need to toggle the gpios before the USB became operational, you would have had to patch both dwc3-pci and phy-generic in order to get it operational. And of course if we didn't need to toggle them, there would not be any need for the nop phy at all.

Quoted 3 lines

FWIW if you test a board without such switch (e.g. a reference BYT-T board called FFRD8 - BYT-CR is a derivation of BYT-T) it will work out-of-the-box.

And it continues to work out-of-the-box even after we removed the creation of the PHY platform device because it does not need to toggle the gpios, right?

BYT-T boards are actually one of the reason why we would really need the ulpi bus, because most them have tusb1211 (so not tusb1210) as the phy and they use it to detect the charger among other things.

Quoted 2 lines

You missed my question. Have you tried to remove and reload dwc3 and phy modules with your test case?

I do test unloading all the modules and reloading them back every time, and with the hack I suggested everything works just fine.

Quoted 11 lines
Quoted 7 lines

We really can't go back to what we had. Please keep in mind that it tied us to the USB PHY framework, possibly forever, and we shouldn't have to depend on two different PHY frameworks. If we have to register the PHY device in dwc3-pci.c then you should create new nop phy for the generic phy framework and use that instead. But before you do that, we better be damn sure there is no way to make ulpi bus work, and we are not there yet.

You have a point. But the transition should happen without creating regressions. You cannot remove previous design while we don't have the next one merged and functional.

But I still don't see any regressions?

Thanks,

Signature · 1 line
heikki
author maintainer
#44 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Felipe Balbi

Hi,

Quoted 5 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

Quoted 7 lines
Quoted 5 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Yes.

Quoted 11 lines
Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

Quoted 11 lines
Quoted 2 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Thanks,

Signature · 1 line
heikki
#45 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 5 lines · Heikki Krogerus

Hi,

Quoted 3 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 7 lines
Quoted 2 lines

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

it doesn't make sense, what you say just doesn't make sense. You're assuming that a) only intel writes BIOS and b) you *always* have access to BIOS writers. You forget that companies other than Intel make x86 devices too.

If the BIOS left the thing switched off, there's no "oh man, if only I had asked them to leave it on"... that's nonsense, just have the kernel deal with it.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

Quoted 3 lines

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can

sure Heikki, no arguments there. But the fact of the matter is that the product David mentioned is *already* in the market.

Quoted 11 lines

influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

until then, we just have to deal with current state of affairs.

Quoted 51 lines
Quoted 11 lines
Quoted 2 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

and what's the problem on doing this within PHY's probe ? The solution is simple:

tusb1210_phy_probe()

{
	...

	gpiod_get(...);
	gpiod_direction_output(reset, 0);
	gpiod_set_value_cansleep(reset, 1);

	gpiod_get(...);
	gpiod_direction_output(cs, 0);
	gpiod_set_value_cansleep(cs, 1);

	eye = ulpi_read();

	gpiod_set_value_cansleep(cs, 0);
	gpiod_put(cs);

	gpiod_set_value_cansleep(reset, 0);
	gpiod_put(reset);

	...

	return 0;
}

This will have no effect on devices where PHY is already turned on and will cope with the device David mentioned. If, however, there's a way to get that eye diagram optimization without needing a ulpi_read() that's *even* better, otherwise, above should fine in all cases.

cheers

Signature · 1 line
balbi
#46 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 138 lines · Felipe Balbi
Quoted 5 lines · Heikki Krogerus

Hi,

Quoted 3 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 7 lines
Quoted 2 lines

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

it doesn't make sense, what you say just doesn't make sense. You're assuming that a) only intel writes BIOS and b) you *always* have access to BIOS writers. You forget that companies other than Intel make x86 devices too.

If the BIOS left the thing switched off, there's no "oh man, if only I had asked them to leave it on"... that's nonsense, just have the kernel deal with it.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

Quoted 3 lines

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can

sure Heikki, no arguments there. But the fact of the matter is that the product David mentioned is *already* in the market.

Quoted 11 lines

influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

until then, we just have to deal with current state of affairs.

Quoted 51 lines
Quoted 11 lines
Quoted 2 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

and what's the problem on doing this within PHY's probe ? The solution is simple:

tusb1210_phy_probe()

{
	...

	gpiod_get(...);
	gpiod_direction_output(reset, 0);
	gpiod_set_value_cansleep(reset, 1);

	gpiod_get(...);
	gpiod_direction_output(cs, 0);
	gpiod_set_value_cansleep(cs, 1);

	eye = ulpi_read();

	gpiod_set_value_cansleep(cs, 0);
	gpiod_put(cs);

	gpiod_set_value_cansleep(reset, 0);
	gpiod_put(reset);

	...

	return 0;
}
Quoted 4 lines

This will have no effect on devices where PHY is already turned on and will cope with the device David mentioned. If, however, there's a way to get that eye diagram optimization without needing a ulpi_read() that's *even* better, otherwise, above should fine in all cases.

A comment here. The ulpi_read() works for eye diagram only and only if there is no reset on PHY between boot and probe. It is assuming the BIOS set the correct value and then we just save it right away. As soon as we reset the PHY this value is lost. So the GPIO toggling breaks the current eye diagram request proposal. IMHO this should really come from _DSD which will maintain the value regardless to what happens with phy.

Br, David

Quoted 5 lines

cheers

Signature · 1 line
balbi
#47 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 144 lines · David Cohen
Quoted 138 lines · Felipe Balbi
Quoted 5 lines · Heikki Krogerus

Hi,

Quoted 3 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 7 lines
Quoted 2 lines

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

it doesn't make sense, what you say just doesn't make sense. You're assuming that a) only intel writes BIOS and b) you *always* have access to BIOS writers. You forget that companies other than Intel make x86 devices too.

If the BIOS left the thing switched off, there's no "oh man, if only I had asked them to leave it on"... that's nonsense, just have the kernel deal with it.

Quoted 12 lines
Quoted 11 lines
Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

Quoted 3 lines

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can

sure Heikki, no arguments there. But the fact of the matter is that the product David mentioned is *already* in the market.

Quoted 11 lines

influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

until then, we just have to deal with current state of affairs.

Quoted 51 lines
Quoted 11 lines
Quoted 2 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

and what's the problem on doing this within PHY's probe ? The solution is simple:

tusb1210_phy_probe()

{
	...

	gpiod_get(...);
	gpiod_direction_output(reset, 0);
	gpiod_set_value_cansleep(reset, 1);

	gpiod_get(...);
	gpiod_direction_output(cs, 0);
	gpiod_set_value_cansleep(cs, 1);

	eye = ulpi_read();

	gpiod_set_value_cansleep(cs, 0);
	gpiod_put(cs);

	gpiod_set_value_cansleep(reset, 0);
	gpiod_put(reset);

	...

	return 0;
}
Quoted 4 lines

This will have no effect on devices where PHY is already turned on and will cope with the device David mentioned. If, however, there's a way to get that eye diagram optimization without needing a ulpi_read() that's *even* better, otherwise, above should fine in all cases.

Quoted 6 lines

A comment here. The ulpi_read() works for eye diagram only and only if there is no reset on PHY between boot and probe. It is assuming the BIOS set the correct value and then we just save it right away. As soon as we reset the PHY this value is lost. So the GPIO toggling breaks the current eye diagram request proposal. IMHO this should really come from _DSD which will maintain the value regardless to what happens with phy.

fair enough.

Signature · 1 line
balbi
#48 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus
Quoted 5 lines · Heikki Krogerus

Hi,

Quoted 3 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 7 lines
Quoted 2 lines

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

That's a really wrong assumption. ULPI bus depends on dwc3 to be functional and dwc3 depends on phy to be functional to complete its power on sequence. We can't ask BIOS to let both up and running all the time.

FWIW we *cannot* rely on ULPI bus enumeration to probe ULPI devices, because it requires the ULPI device to be previously functional which can't happen before the enumeration. Even if we ask BIOS to let phy functional after boot, what happens when we remove modules and load it again? Should we ask BIOS to power on the components again in order to probe and power it on? It's a circular dependency you're creating.

Quoted 10 lines
Quoted 8 lines
Quoted 6 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Yes.

And that's wrong assumption. Not all fw will power on PHY. Maybe we should stop all of other discussions and concentrate on this one:
BIOS will not guarantee phy will be functional after boot. And if we remove modules and load again, it won't be functional regardless what BIOS did during boot.

Quoted 22 lines
Quoted 7 lines
Quoted 6 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

Quoted 5 lines

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

Quoted 5 lines

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

Quoted 52 lines
Quoted 4 lines
Quoted 3 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

Quoted 8 lines

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 28 lines
Quoted 28 lines
drivers/usb/dwc3/dwc3-pci.c +13 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
Quoted 8 lines

drivers/usb/dwc3/dwc3-pci.c line 54

Quoted 5 lines
drivers/usb/dwc3/dwc3-pci.c +5 -0
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

Br, David

Quoted 6 lines

Thanks,

Signature · 1 line
heikki
#49 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 19 lines · David Cohen
Quoted 5 lines · Heikki Krogerus

Hi,

Quoted 3 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

Quoted 7 lines
Quoted 2 lines

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

That's a really wrong assumption. ULPI bus depends on dwc3 to be functional and dwc3 depends on phy to be functional to complete its power on sequence. We can't ask BIOS to let both up and running all the time.

Quoted 6 lines

FWIW we *cannot* rely on ULPI bus enumeration to probe ULPI devices, because it requires the ULPI device to be previously functional which can't happen before the enumeration. Even if we ask BIOS to let phy functional after boot, what happens when we remove modules and load it again? Should we ask BIOS to power on the components again in order to probe and power it on? It's a circular dependency you're creating.

do we need both CS and RESET for phy to be functional ? Since we need PHY functional during ulpi bus enumeration phase, the only way would be to have the ULPI bus code itself grab those GPIOs (as long as it's gpiod_get_optional() we should be fine) and toggle them before enumerating the bus.

The only problem is doing that for every driver_register() :-s

Signature · 1 line
balbi
author maintainer
#50 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to David Cohen
Quoted 32 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

That's a really wrong assumption. ULPI bus depends on dwc3 to be functional and dwc3 depends on phy to be functional to complete its power on sequence. We can't ask BIOS to let both up and running all the time.

FWIW we *cannot* rely on ULPI bus enumeration to probe ULPI devices, because it requires the ULPI device to be previously functional which can't happen before the enumeration. Even if we ask BIOS to let phy functional after boot, what happens when we remove modules and load it again? Should we ask BIOS to power on the components again in order to probe and power it on? It's a circular dependency you're creating.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Quoted 7 lines
Quoted 1 line

Yes.

And that's wrong assumption. Not all fw will power on PHY. Maybe we should stop all of other discussions and concentrate on this one:
BIOS will not guarantee phy will be functional after boot. And if we remove modules and load again, it won't be functional regardless what BIOS did during boot.

I was wrong when I talked about BIOS powering the PHY before bootup. I admit it. I'm saying this again as a reminder to myself: We can't mix BIOS (or any FW) and ACPI. I mix them constantly. And I definitely need to stop talking about bootup.

How this is handled is by letting the ACPI Power State methods of the dwc3 device take care of the toggling of the gpios. It is done with the help of something called GPIO OperationRegion. In case you are not familiar with ACPI, then if you send me ACPI dump of one of those devices (or just copy /sys/firmware/acpi/tables/DSDT), I can try to modify the DSDT for you so you can use to test it, and provide you with the ASL snippet.

You will see that the PHY is indeed in reset after bootup like it is now (BIOS does nothing differently), but the gpios are automatically toggled by the DSDT code. So every time you load dwc3 module, the PHY will be operational when we need it, and when you unload dwc3, it will be left in reset again. The OS does not have to do anything.

I really think that this BYT-CR case will be one of really rare exception we will see, especially if we manage to put together the ACPI table review that has been though about.

Quoted 27 lines
Quoted 21 lines
Quoted 11 lines
Quoted 5 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

Quoted 5 lines

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

Quoted 5 lines

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

I don't understand what you are saying here?

Quoted 51 lines
Quoted 51 lines
Quoted 11 lines
Quoted 2 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 36 lines
Quoted 23 lines
drivers/usb/dwc3/dwc3-pci.c +8 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);

drivers/usb/dwc3/dwc3-pci.c line 55

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 4 lines
Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

The platform device would in any case need to be created only for this case. We can't any more just create the phy device unconditionally for every PCI platform like it was created before, as it's clear now the PHY device can be be created from other sources. It was a risk always.

But the big problem is that since the PHY on your board is ULPI PHY, it will make it really difficult to add the ULPI bus support. And like I said in my previous mail, we would really need it for the boards that expect the PHY driver to provide functions like charger detection. We don't need it only for BYT based boards.

So on top of the above, since the GPIO resources are given to dwc3, I actually think that my hack is better then the platform device.

Thanks,

Signature · 1 line
heikki
author maintainer
#51 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi David, Felipe,

Quoted 13 lines
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

The platform device would in any case need to be created only for this case. We can't any more just create the phy device unconditionally for every PCI platform like it was created before, as it's clear now the PHY device can be be created from other sources. It was a risk always.

Quoted 8 lines

But the big problem is that since the PHY on your board is ULPI PHY, it will make it really difficult to add the ULPI bus support. And like I said in my previous mail, we would really need it for the boards that expect the PHY driver to provide functions like charger detection. We don't need it only for BYT based boards.

So on top of the above, since the GPIO resources are given to dwc3, I actually think that my hack is better then the platform device.

So what do you guys think we should do? I can't figure out how would we make the platform device work with ulpi bus. If we think about handling this in ulpi bus driver by setting setting the gpios before attempting to access the phy, which I'm not completely against, we have couple of problems.

Firstly, the gpio resources are given to the dwc3 in this case, while normally they will be given to separate device object for the phy.

Secondly, these gpios were not labeled in DSDT, but apparently requesting the gpios with index will be deprecated and not acceptable any more. With the remaining platforms that have not labeled the gpios we have to bind the gpios to labels separately in the drivers. With ACPI platforms the labels are introduced in struct acpi_gpio_mapping which needs to be registered with acpi_dev_add_driver_gpios(). Check net/rfkill/rfkill-gpio.c as an example how to use it.

I think those points would make this too platform specific case to be handled in the ulpi bus driver.

Suggestions? I still think the correct thing to do is to handle this in the quirk in dwc3-pci.c.

Cheers,

Signature · 1 line
heikki
#52 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 1 line · Heikki Krogerus

Hi David, Felipe,

Hi Heikki,

Quoted 20 lines
Quoted 20 lines
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

The platform device would in any case need to be created only for this case. We can't any more just create the phy device unconditionally for every PCI platform like it was created before, as it's clear now the PHY device can be be created from other sources. It was a risk always.

But the big problem is that since the PHY on your board is ULPI PHY, it will make it really difficult to add the ULPI bus support. And like I said in my previous mail, we would really need it for the boards that expect the PHY driver to provide functions like charger detection. We don't need it only for BYT based boards.

Quoted 8 lines
Quoted 2 lines

So on top of the above, since the GPIO resources are given to dwc3, I actually think that my hack is better then the platform device.

So what do you guys think we should do? I can't figure out how would we make the platform device work with ulpi bus. If we think about handling this in ulpi bus driver by setting setting the gpios before attempting to access the phy, which I'm not completely against, we have couple of problems.

It's still not enough :/
In order to make the phy functional (in BYT case) you need to bring DWC3 to reset state, then toggle these gpios to reset and power on phy, then remove DWC3 from reset state so both can sync clocks.
You can still reset and power on phy before DWC3 goes to and from reset, but then there's a chance phy may become unstable. It's then expected to fail long stability tests.

Quoted 4 lines

Firstly, the gpio resources are given to the dwc3 in this case, while normally they will be given to separate device object for the phy.

Yup. You're correct. We can influence new products to not repeat this issue, but we still need to support legacy ones.

Quoted 8 lines

Secondly, these gpios were not labeled in DSDT, but apparently requesting the gpios with index will be deprecated and not acceptable any more. With the remaining platforms that have not labeled the gpios we have to bind the gpios to labels separately in the drivers. With ACPI platforms the labels are introduced in struct acpi_gpio_mapping which needs to be registered with acpi_dev_add_driver_gpios(). Check net/rfkill/rfkill-gpio.c as an example how to use it.

For new products, certanly.

Quoted 6 lines

I think those points would make this too platform specific case to be handled in the ulpi bus driver.

Suggestions? I still think the correct thing to do is to handle this in the quirk in dwc3-pci.c.

IMO it would make things uglier than it was before.

BR, David

Quoted 6 lines

Cheers,

Signature · 1 line
heikki
#53 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus
Quoted 53 lines · Heikki Krogerus
Quoted 32 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

That's a really wrong assumption. ULPI bus depends on dwc3 to be functional and dwc3 depends on phy to be functional to complete its power on sequence. We can't ask BIOS to let both up and running all the time.

FWIW we *cannot* rely on ULPI bus enumeration to probe ULPI devices, because it requires the ULPI device to be previously functional which can't happen before the enumeration. Even if we ask BIOS to let phy functional after boot, what happens when we remove modules and load it again? Should we ask BIOS to power on the components again in order to probe and power it on? It's a circular dependency you're creating.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Quoted 7 lines
Quoted 1 line

Yes.

And that's wrong assumption. Not all fw will power on PHY. Maybe we should stop all of other discussions and concentrate on this one:
BIOS will not guarantee phy will be functional after boot. And if we remove modules and load again, it won't be functional regardless what BIOS did during boot.

I was wrong when I talked about BIOS powering the PHY before bootup. I admit it. I'm saying this again as a reminder to myself: We can't mix BIOS (or any FW) and ACPI. I mix them constantly. And I definitely need to stop talking about bootup.

How this is handled is by letting the ACPI Power State methods of the dwc3 device take care of the toggling of the gpios. It is done with the help of something called GPIO OperationRegion. In case you are not familiar with ACPI, then if you send me ACPI dump of one of those devices (or just copy /sys/firmware/acpi/tables/DSDT), I can try to modify the DSDT for you so you can use to test it, and provide you with the ASL snippet.

Quoted 5 lines

You will see that the PHY is indeed in reset after bootup like it is now (BIOS does nothing differently), but the gpios are automatically toggled by the DSDT code. So every time you load dwc3 module, the PHY will be operational when we need it, and when you unload dwc3, it will be left in reset again. The OS does not have to do anything.

Hm. That changes everything :)
It's a feasible direction to push vendors.

Quoted 4 lines

I really think that this BYT-CR case will be one of really rare exception we will see, especially if we manage to put together the ACPI table review that has been though about.

I hope it will.

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 7 lines
Quoted 6 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

Quoted 5 lines

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

Quoted 7 lines
Quoted 5 lines

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

I don't understand what you are saying here?

TUSB1210 needs to come out of reset only when DWC3 is in reset state. This is how current code works in dwc3_core_soft_reset():
- dwc3 goes to reset
- phy goes to reset
- phy gets out of reset
- dwc3 gets out of reset

This is how you're proposing:
- phy goes to reset (DSDT code, when loading module)
- phy gets out of reset (DSDT code, when loading module)

- dwc3 goes to reset (dwc3_core_soft_reset())
- dwc3 gets our of reset (dwc3_core_soft_reset())

Felipe, do you see a problem with this new context? If not, I'm satisfied with Heikki's ULPI bus proposal considering my comment below.

Quoted 62 lines
Quoted 52 lines
Quoted 52 lines
Quoted 4 lines
Quoted 3 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

Quoted 8 lines

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 36 lines
Quoted 23 lines
drivers/usb/dwc3/dwc3-pci.c +8 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);

drivers/usb/dwc3/dwc3-pci.c line 55

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 4 lines
Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

The platform device would in any case need to be created only for this case. We can't any more just create the phy device unconditionally for every PCI platform like it was created before, as it's clear now the PHY device can be be created from other sources. It was a risk always.

Quoted 8 lines

But the big problem is that since the PHY on your board is ULPI PHY, it will make it really difficult to add the ULPI bus support. And like I said in my previous mail, we would really need it for the boards that expect the PHY driver to provide functions like charger detection. We don't need it only for BYT based boards.

So on top of the above, since the GPIO resources are given to dwc3, I actually think that my hack is better then the platform device.

This would bring support to current BYT-CR products, but it's a lot ugly :/ But current DSDT is a lot ugly too.

Felipe, we do need ULPI bus working for BYT-CR due to 2 scenarios:
- we need eye optimization
- we need to pull down D+/- on phy after cable disconnection so charging detection module can detect CDP connection during next cable plug in.

I see no way to make current BYT-CR platforms work with Heikki's ULPI bus proposal without crippling it if we don't toggle these GPIOs outside ULPI's device probe.

Quoted 1 line

From my side, the quirk is acceptable as a trade off to not damage his

design due to legacy platforms.

Br, David

Quoted 6 lines

Thanks,

Signature · 1 line
heikki
#54 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 117 lines · David Cohen
Quoted 53 lines · Heikki Krogerus
Quoted 32 lines
Quoted 10 lines
Quoted 5 lines
Quoted 2 lines

You can't really compare a bus like i2c, which can't enumerate devices natively, to ULPI which can.

why not ? The BIOS might not need to use the PHY (or USB) at all, it can very well decide to never turn it on, right ?

If ULPI was seen as a bus, then no. BIOS would have definitely left the PHY on. In fact, if we would have just asked the BIOS writers to leave it on, they would not have any problem with that, even without the bus.

That's a really wrong assumption. ULPI bus depends on dwc3 to be functional and dwc3 depends on phy to be functional to complete its power on sequence. We can't ask BIOS to let both up and running all the time.

FWIW we *cannot* rely on ULPI bus enumeration to probe ULPI devices, because it requires the ULPI device to be previously functional which can't happen before the enumeration. Even if we ask BIOS to let phy functional after boot, what happens when we remove modules and load it again? Should we ask BIOS to power on the components again in order to probe and power it on? It's a circular dependency you're creating.

Quoted 9 lines
Quoted 8 lines
Quoted 6 lines

I don't think the other boards we have which use TUSB1210, like the BYT-I ones and I think some Merrifield based boards, expect any less from PM efficiency then BYT-CR, but we don't need to do any tricks with them in order to use ULPI bus. That is what I mean when I say this is BYT-CR specific problem.

perhaps because firmware on those other boards are powering up the PHY ?

Quoted 7 lines
Quoted 1 line

Yes.

And that's wrong assumption. Not all fw will power on PHY. Maybe we should stop all of other discussions and concentrate on this one:
BIOS will not guarantee phy will be functional after boot. And if we remove modules and load again, it won't be functional regardless what BIOS did during boot.

I was wrong when I talked about BIOS powering the PHY before bootup. I admit it. I'm saying this again as a reminder to myself: We can't mix BIOS (or any FW) and ACPI. I mix them constantly. And I definitely need to stop talking about bootup.

How this is handled is by letting the ACPI Power State methods of the dwc3 device take care of the toggling of the gpios. It is done with the help of something called GPIO OperationRegion. In case you are not familiar with ACPI, then if you send me ACPI dump of one of those devices (or just copy /sys/firmware/acpi/tables/DSDT), I can try to modify the DSDT for you so you can use to test it, and provide you with the ASL snippet.

Quoted 5 lines

You will see that the PHY is indeed in reset after bootup like it is now (BIOS does nothing differently), but the gpios are automatically toggled by the DSDT code. So every time you load dwc3 module, the PHY will be operational when we need it, and when you unload dwc3, it will be left in reset again. The OS does not have to do anything.

Hm. That changes everything :)
It's a feasible direction to push vendors.

Quoted 4 lines

I really think that this BYT-CR case will be one of really rare exception we will see, especially if we manage to put together the ACPI table review that has been though about.

I hope it will.

Quoted 28 lines
Quoted 28 lines
Quoted 27 lines
Quoted 7 lines
Quoted 6 lines

I don't agree with PM arguments if it means that we should be ready to accept loosing possibility for a generic solution in OS with a single device like our PHY. I seriously doubt it would prevent the products using these boards of achieving their PM requirements. But this conversation is outside our topic.

Quoted 5 lines

we're not loosing anything. We're just considering what's the best way to tackle that ulpi_read() inside probe(). TUSB1210 driver _has_ to cope with situations where reset_gpio/cs_gpio are in unexpected state. Saying we will just "fix the firmware", as if that was a simple feat, is counter-productive.

You know guys, we shouldn't always just lay down and say, "we just have to accept it can be anything" or "we just have to try to prepare for everything". We can influence these things, and we should. We can influence these things inside our own companies before any products is launched using our SoCs, and since more and more companies are releasing their code into the public before their product are launched, we even have a change to influence others. Lack of standards does not mean we should not try to achieve consistency.

For example, now I should probable write to Documentation that "ULPI PHY needs to be in condition where it's register can be accessed before the interface is registered.", and I'm pretty sure it would be enough to have an effect on many of the new platforms that use ULPI PHYs.

Quoted 7 lines
Quoted 5 lines

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

I don't understand what you are saying here?

TUSB1210 needs to come out of reset only when DWC3 is in reset state. This is how current code works in dwc3_core_soft_reset():
- dwc3 goes to reset
- phy goes to reset
- phy gets out of reset
- dwc3 gets out of reset

This is how you're proposing:
- phy goes to reset (DSDT code, when loading module)
- phy gets out of reset (DSDT code, when loading module)

Quoted 5 lines

- dwc3 goes to reset (dwc3_core_soft_reset())
- dwc3 gets our of reset (dwc3_core_soft_reset())

Felipe, do you see a problem with this new context? If not, I'm satisfied with Heikki's ULPI bus proposal considering my comment below.

Sorry, guess I spoke too soon :/
I am satisfied with the phy case, but I forgot about the chicken/egg problem I reported earlier:
DWC3 will not be functional when reloading the module after it went to reset state. Then ULPI enumeration can't happen regardless DSDT code powered on phy.

Heikki, do you have a proposal for that? IMHO that's the main missing point if we forget about BYT-CR legacy.

Br, David

Quoted 99 lines
Quoted 63 lines
Quoted 53 lines
Quoted 53 lines
Quoted 5 lines
Quoted 4 lines

Because of the need to write to the ULPI registers, I don't think we should try anything else except to use ULPI bus straight away. We'll

Quoted 8 lines

I'll agree with this.

Quoted 3 lines

start by making use of ULPI bus possible by adding the quirk for BYT (attached), which to me is perfectly OK solution. I would appreciate if you gave it a review.

it's not perfectly ok for dwc3 to toggle PHY's GPIOs. Have the PHY driver to that.

Oh, I agree with that..

Quoted 36 lines
Quoted 23 lines
drivers/usb/dwc3/dwc3-pci.c +8 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);

drivers/usb/dwc3/dwc3-pci.c line 55

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}

why would you have dwc3 mess around with the PHY's gpios ? Doesn't look very good.

Quoted 4 lines
Quoted 2 lines

..but unfortunately we can't use the bus without it :(. We depend on being able to read the vendor and product id's in the bus driver.

Doesn't the ugly platform device case look less ugly than this?

The platform device would in any case need to be created only for this case. We can't any more just create the phy device unconditionally for every PCI platform like it was created before, as it's clear now the PHY device can be be created from other sources. It was a risk always.

Quoted 8 lines

But the big problem is that since the PHY on your board is ULPI PHY, it will make it really difficult to add the ULPI bus support. And like I said in my previous mail, we would really need it for the boards that expect the PHY driver to provide functions like charger detection. We don't need it only for BYT based boards.

So on top of the above, since the GPIO resources are given to dwc3, I actually think that my hack is better then the platform device.

This would bring support to current BYT-CR products, but it's a lot ugly :/ But current DSDT is a lot ugly too.

Felipe, we do need ULPI bus working for BYT-CR due to 2 scenarios:
- we need eye optimization
- we need to pull down D+/- on phy after cable disconnection so charging detection module can detect CDP connection during next cable plug in.

I see no way to make current BYT-CR platforms work with Heikki's ULPI bus proposal without crippling it if we don't toggle these GPIOs outside ULPI's device probe.

From my side, the quirk is acceptable as a trade off to not damage his design due to legacy platforms.

Br, David

Quoted 6 lines

Thanks,

Signature · 1 line
heikki

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author maintainer
#55 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi David,

Quoted 25 lines
Quoted 19 lines
Quoted 7 lines
Quoted 5 lines

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

I don't understand what you are saying here?

TUSB1210 needs to come out of reset only when DWC3 is in reset state. This is how current code works in dwc3_core_soft_reset():
- dwc3 goes to reset
- phy goes to reset
- phy gets out of reset
- dwc3 gets out of reset

This is how you're proposing:
- phy goes to reset (DSDT code, when loading module)
- phy gets out of reset (DSDT code, when loading module)

Quoted 5 lines

- dwc3 goes to reset (dwc3_core_soft_reset())
- dwc3 gets our of reset (dwc3_core_soft_reset())

Felipe, do you see a problem with this new context? If not, I'm satisfied with Heikki's ULPI bus proposal considering my comment below.

Quoted 6 lines

Sorry, guess I spoke too soon :/
I am satisfied with the phy case, but I forgot about the chicken/egg problem I reported earlier:
DWC3 will not be functional when reloading the module after it went to reset state. Then ULPI enumeration can't happen regardless DSDT code powered on phy.

One point here. If we have DSDT handling the gpios with the operation region, those gpio resources don't need to be given to any device (actually I think they really shouldn't be given to anything in that case).

Quoted 2 lines

Heikki, do you have a proposal for that? IMHO that's the main missing point if we forget about BYT-CR legacy.

I'm sorry but I'm still not sure about the scenario you are talking about.

When we load dwc3, we end up autoloading phy-tusb1210 in this case and increasing the phy devices ref count i.e. preventing phy-tusb1210 module from being unloaded before dwc3 is unloaded.

If we unload dwc3 we can also unload phy-tusb1210 if we like but if after that we load dwc3 again, the ULPI will be accessible the moment we register the ulpi interface as it was before.

That I believe is actually a must in case of ULPI. When dwc3 is reset with GCTL or DCTL SoftReset, it will first write to the ULPI FunctionControl register's reset bit in order to but the PHY to reset (PHYSoftRst has no effect in case of ULPI), so ULPI really has to be accessible before the core is soft reset.

Thanks,

Signature · 1 line
heikki
#56 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 1 line · Heikki Krogerus

Hi David,

Hi Heikki,

Quoted 33 lines
Quoted 26 lines
Quoted 20 lines
Quoted 8 lines
Quoted 6 lines

In order for phy to be functional, it does not depend only on toggling GPIOs. It depends on DWC3 going to reset state, then phy executes power on sequence, then DWC3 going out of reset state to sync clocks with phy. You're saying we should tell BIOS is concurrently mess with dwc3 together with dwc3 driver?

I don't understand what you are saying here?

TUSB1210 needs to come out of reset only when DWC3 is in reset state. This is how current code works in dwc3_core_soft_reset():
- dwc3 goes to reset
- phy goes to reset
- phy gets out of reset
- dwc3 gets out of reset

This is how you're proposing:
- phy goes to reset (DSDT code, when loading module)
- phy gets out of reset (DSDT code, when loading module)

Quoted 5 lines

- dwc3 goes to reset (dwc3_core_soft_reset())
- dwc3 gets our of reset (dwc3_core_soft_reset())

Felipe, do you see a problem with this new context? If not, I'm satisfied with Heikki's ULPI bus proposal considering my comment below.

Quoted 6 lines

Sorry, guess I spoke too soon :/
I am satisfied with the phy case, but I forgot about the chicken/egg problem I reported earlier:
DWC3 will not be functional when reloading the module after it went to reset state. Then ULPI enumeration can't happen regardless DSDT code powered on phy.

Quoted 4 lines

One point here. If we have DSDT handling the gpios with the operation region, those gpio resources don't need to be given to any device (actually I think they really shouldn't be given to anything in that case).

Agree with that.

Quoted 6 lines
Quoted 3 lines

Heikki, do you have a proposal for that? IMHO that's the main missing point if we forget about BYT-CR legacy.

I'm sorry but I'm still not sure about the scenario you are talking about.

Probably because I'm asking this question in the wrong place. It is regarding patch 6/8. I resent the question there.

Br, David

#57 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus

Hi Felipe,

[snip]

Quoted 24 lines
drivers/usb/dwc3/dwc3-pci.c +9 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);

drivers/usb/dwc3/dwc3-pci.c line 56

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+

A lot has been discussed in other branches of this thread.

But in resume, this is the last open point to make Heikki's proposal good on my side. If you accept this ugly quirk (but necessary for current BYT-CR products when ULPI bus enumerates phy), everything seems good to me. If you don't accept, we need to figure out a way to get the platform driver code back to give gpio to phy as platform data in a way that it could live together with ULPI bus (BYT-CR needs the ULPI bus too).

Br, David

Quoted 3 lines
drivers/usb/dwc3/dwc3-pci.c +0 -0
 	if (pdev->vendor == PCI_VENDOR_ID_AMD &&
 	    pdev->device == PCI_DEVICE_ID_AMD_NL_USB) {
 		struct dwc3_platform_data pdata;
#58 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 41 lines · David Cohen

Hi Felipe,

[snip]

Quoted 24 lines
drivers/usb/dwc3/dwc3-pci.c +9 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);

drivers/usb/dwc3/dwc3-pci.c line 56

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+

A lot has been discussed in other branches of this thread.

Quoted 6 lines

But in resume, this is the last open point to make Heikki's proposal good on my side. If you accept this ugly quirk (but necessary for current BYT-CR products when ULPI bus enumerates phy), everything seems good to me. If you don't accept, we need to figure out a way to get the platform driver code back to give gpio to phy as platform data in a way that it could live together with ULPI bus (BYT-CR needs the ULPI bus too).

Is this needed to *all* Baytrail devices or could we have devices with updated firmware which won't need this ? I wonder if we should apply the quirk for each known product that actually needs this.

Also, I will only accept the series, after I'm shown logs that it works with your known-to-be-broken device.

cheers

Signature · 1 line
balbi
#59 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 49 lines · Felipe Balbi
Quoted 41 lines · David Cohen

Hi Felipe,

[snip]

Quoted 24 lines
drivers/usb/dwc3/dwc3-pci.c +9 -0
index 8d95056..53902ea 100644
@@ -21,6 +21,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
+#include <linux/gpio/consumer.h>
 
 #include "platform_data.h"
 
@@ -35,6 +36,24 @@
 
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
+	if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+	    pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+		struct gpio_desc *gpio;
+
+		gpio = gpiod_get_index(&pdev->dev, "reset", 0);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);

drivers/usb/dwc3/dwc3-pci.c line 56

Quoted 10 lines
drivers/usb/dwc3/dwc3-pci.c +10 -0
+			gpiod_put(gpio);
+		}
+		gpio = gpiod_get_index(&pdev->dev, "cs", 1);
+		if (!IS_ERR(gpio)) {
+			gpiod_direction_output(gpio, 0);
+			gpiod_set_value_cansleep(gpio, 1);
+			gpiod_put(gpio);
+		}
+	}
+

A lot has been discussed in other branches of this thread.

Quoted 6 lines

But in resume, this is the last open point to make Heikki's proposal good on my side. If you accept this ugly quirk (but necessary for current BYT-CR products when ULPI bus enumerates phy), everything seems good to me. If you don't accept, we need to figure out a way to get the platform driver code back to give gpio to phy as platform data in a way that it could live together with ULPI bus (BYT-CR needs the ULPI bus too).

Quoted 3 lines

Is this needed to *all* Baytrail devices or could we have devices with updated firmware which won't need this ? I wonder if we should apply the quirk for each known product that actually needs this.

The products that need this quirk will have the gpios on DSDT, otherwise it won't be there. Except for the order of gpios (CS needs to be enabled first and it's index 0 AFAIR), the quirk should follow Heikki's logic
here: if gpio isn't found we silently ignore it.

Quoted 3 lines

Also, I will only accept the series, after I'm shown logs that it works with your known-to-be-broken device.

I can provide that when Heikki resends his patch set.

Br, David

Quoted 5 lines

cheers

Signature · 1 line
balbi
#60 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus
Quoted 91 lines · Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>
---
 drivers/phy/Kconfig        |   6 ++
 drivers/phy/Makefile       |   1 +
 drivers/phy/phy-tusb1210.c | 133 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 140 insertions(+)
 create mode 100644 drivers/phy/phy-tusb1210.c
drivers/phy/Kconfig +6 -0
index 26a7623..52ee720 100644
@@ -284,4 +284,10 @@ config PHY_QCOM_UFS
 	help
 	  Support for UFS PHY on QCOM chipsets.
 
+config PHY_TUSB1210
+	tristate "TI TUSB1210 ULPI PHY module"
+	depends on USB_ULPI_BUS
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
 endmenu
drivers/phy/Makefile +1 -0
index cfbb720..03f3d85 100644
@@ -37,3 +37,4 @@ obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-20nm.o
 obj-$(CONFIG_PHY_QCOM_UFS) 	+= phy-qcom-ufs-qmp-14nm.o
+obj-$(CONFIG_PHY_TUSB1210)		+= phy-tusb1210.o
drivers/phy/phy-tusb1210.c new file +46 -0
new file mode 100644
index 0000000..1551ae8
@@ -0,0 +1,133 @@
+/**
+ * tusb1210.c - TUSB1210 USB ULPI PHY driver
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * Author: Heikki Krogerus <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/module.h>
+#include <linux/ulpi/driver.h>
+#include <linux/gpio/consumer.h>
+
+#include "ulpi_phy.h"
+
+#define TUSB1210_VENDOR_SPECIFIC2 0x80
+
+struct tusb1210 {
+	struct ulpi *ulpi;
+	struct phy *phy;
+	struct gpio_desc *gpio_reset;
+	struct gpio_desc *gpio_cs;
+	u8 eye_diagram_tuning;
+};
+
+static int tusb1210_power_on(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 1);
+	gpiod_set_value_cansleep(tusb->gpio_cs, 1);
+
+	/* Restore eye diagram optimisation value */
+	ulpi_write(tusb->ulpi, TUSB1210_VENDOR_SPECIFIC2,
+		   tusb->eye_diagram_tuning);
+
+	return 0;
+}
+
+static int tusb1210_power_off(struct phy *phy)
+{
+	struct tusb1210 *tusb = phy_get_drvdata(phy);
+
+	gpiod_set_value_cansleep(tusb->gpio_reset, 0);

drivers/phy/phy-tusb1210.c line 56

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+	gpiod_set_value_cansleep(tusb->gpio_cs, 0);
+
+	return 0;
+}
+
+static struct phy_ops phy_ops = {
+	.power_on = tusb1210_power_on,
+	.power_off = tusb1210_power_off,
+	.init = tusb1210_power_on,
+	.exit = tusb1210_power_off,

these should not be the same. It looks like what you want is for reset and cs gpios to be handle on init/exit and ulpi_write() from power_on().

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

Quoted 19 lines
drivers/phy/phy-tusb1210.c new file +19 -0
+	.owner = THIS_MODULE,
+};
+
+static int tusb1210_probe(struct ulpi *ulpi)
+{
+	struct gpio_desc *gpio;
+	struct tusb1210 *tusb;
+	int ret;
+
+	tusb = devm_kzalloc(&ulpi->dev, sizeof(*tusb), GFP_KERNEL);
+	if (!tusb)
+		return -ENOMEM;
+
+	gpio = devm_gpiod_get(&ulpi->dev, "reset");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_reset = gpio;

drivers/phy/phy-tusb1210.c line 85

Quoted 10 lines
drivers/phy/phy-tusb1210.c new file +10 -0
+	}
+
+	gpio = devm_gpiod_get(&ulpi->dev, "cs");
+	if (!IS_ERR(gpio)) {
+		ret = gpiod_direction_output(gpio, 0);
+		if (ret)
+			return ret;
+		tusb->gpio_cs = gpio;
+	}
+

right before this call, you really don't know the state of either CS nor RESET gpios, so it could very well be that firmware left it disabled.

There are cases where that extra uW of runtime power consumption matters, you probably still remember the weeks we spent optimizing regulator usage on both twl4030-usb and isp17xx (whatever that was) on N900.

Either wrap this call with proper gpio handling (if there's really no other way to get the eye diagram data), or remove it from here completely and use the BIOS hook which, apparently, exists.

Wrapping it with GPIOs has the added benefit of making sure the PHY is powered down after probe in case firmware left it running. We really can't make assumptions as to when the PHY will be needed.

Signature · 1 line
balbi
author maintainer
#61 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 7 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

Thanks,

Signature · 1 line
heikki
#62 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 10 lines · Heikki Krogerus
Quoted 7 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

David ? Care to comment ?

Signature · 1 line
balbi
#63 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 6 lines · Felipe Balbi
Quoted 5 lines · Heikki Krogerus
Quoted 5 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

David ? Care to comment ?

I agree with Heikki's proposal to use BIOS hook and remove ulpi_read() from probe(). That address one of my chicken/egg concerns.

Br, David

Quoted 3 lines
Signature · 2 lines
-- 
balbi
#64 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 10 lines · David Cohen
Quoted 9 lines · Felipe Balbi
Quoted 8 lines · Heikki Krogerus
Quoted 7 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

David ? Care to comment ?

I agree with Heikki's proposal to use BIOS hook and remove ulpi_read() from probe(). That address one of my chicken/egg concerns.

Oops. I misinterpreted the thread. Heikki didn't propose that :) Let me get things mature and reply to here.

Br, David

Quoted 8 lines

Br, David

Quoted 3 lines
Signature · 2 lines
-- 
balbi
#65 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 14 lines · David Cohen
Quoted 13 lines · David Cohen
Quoted 12 lines · Felipe Balbi
Quoted 10 lines · Heikki Krogerus
Quoted 7 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

David ? Care to comment ?

I agree with Heikki's proposal to use BIOS hook and remove ulpi_read() from probe(). That address one of my chicken/egg concerns.

Oops. I misinterpreted the thread. Heikki didn't propose that :) Let me get things mature and reply to here.

I talked to David Box (CC'ed him to this reply).
We can add an integer value to ACPI and request it during phy's probe using ACPI's Device Specific Data (_DSD). That would end the need to have phy functional during probe (being compatible to BYT-CR and to module support) and would be more compatible to DT as well.

Br, David

Quoted 11 lines

Br, David

Quoted 8 lines

Br, David

Quoted 3 lines
Signature · 2 lines
-- 
balbi
author maintainer
#66 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

Also, I was chatting in private with David and, apparently, there's a way to request for eye diagram data from BIOS straight. That's more in-line with what we would do for DT-based boots, passing that eye-diagram data as a DT attribute.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

Care to comment ? If that's the case, I'd rather use that BIOS hook and remove ulpi_read() from probe().

I'm not familiar with such method. But if there is one, I'm not against it. I need to check it.

David ? Care to comment ?

I agree with Heikki's proposal to use BIOS hook and remove ulpi_read() from probe(). That address one of my chicken/egg concerns.

Quoted 8 lines
Quoted 2 lines

Oops. I misinterpreted the thread. Heikki didn't propose that :) Let me get things mature and reply to here.

I talked to David Box (CC'ed him to this reply).
We can add an integer value to ACPI and request it during phy's probe using ACPI's Device Specific Data (_DSD). That would end the need to have phy functional during probe (being compatible to BYT-CR and to module support) and would be more compatible to DT as well.

You can still make modifications to the DSDT?!

I am familiar with _DSD, and it does not just allow us to add integer values, but complete named key to value properties compatible with dt, including strings. And in case you guys were not familiar with the unified device property interface, it's a wrapper for apci and dt, and should btw. be used instead of acpi_* or of_* to get properties in drivers from now on.

So if we add these properties for the dwc3 device object:
"ulpi,vendor", "ulpi,product", we can check them in ULPI bus driver as an alternative for reading the vendor and product registers, and indeed be able to bind the PHY to a driver before it's powered on!

P.S. We should not mix BIOS to ACPI.

Thanks!

Signature · 1 line
heikki
#67 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

In reply to Heikki Krogerus

Hi Heikki,

Sorry I am starting a new branch on this thread. I need to go back to another topic on this same patch.

Quoted 9 lines · Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>

---

[snip]

drivers/phy/phy-tusb1210.c line 87

Quoted 2 lines
drivers/phy/phy-tusb1210.c new file +2 -0
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

We can't rely on eye diagram optimization value here. It's possible the phy went through reset (e.g. module unloading/loading).
We need a more consistent method. Could we use _DSD instead? That would be more compatible with DT too.

Br, David

Quoted 16 lines
drivers/phy/phy-tusb1210.c new file +16 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->eye_diagram_tuning = ret;
+
+	tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
+	if (IS_ERR(tusb->phy))
+		return PTR_ERR(tusb->phy);
+
+	tusb->ulpi = ulpi;
+
+	phy_set_drvdata(tusb->phy, tusb);
+	ulpi_set_drvdata(ulpi, tusb);
+	return 0;
+}
+
author maintainer
#68 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Hi,

Quoted 18 lines · David Cohen

Hi Heikki,

Sorry I am starting a new branch on this thread. I need to go back to another topic on this same patch.

Quoted 9 lines · Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>

---

[snip]

Quoted 7 lines

drivers/phy/phy-tusb1210.c line 87

Quoted 2 lines
drivers/phy/phy-tusb1210.c new file +2 -0
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

We can't rely on eye diagram optimization value here. It's possible the phy went through reset (e.g. module unloading/loading).
We need a more consistent method. Could we use _DSD instead? That would be more compatible with DT too.

I'm don't have any problem with getting the value from a property. Sounds like the correct thing to do. Are you thinking about putting that _DSD method to the ACPI device object for the dwc3? The correct place would probable be separate device object for the PHY, but if we do that we need to consider how that object is bound to the ulpi device. There are few ways we can do that, so it requires some thinking.

In any case this driver we can already implement so that it expects to get the value from property. We just need the name for it.

The register has actually separate fields for High speed output impedance configuration and High speed output driver strength configuration for eye diagram tuning, plus control bit for DP/DM swap.

Maybe we should actually get them from three separate properties:

        device_property_read_u8(dev, "datapolarity", &val);
        ...
        device_property_read_u8(dev, "zhsdrv", &val);
        ...
        device_property_read_u8(dev, "ihstx", &val);
        ...

What do you think?

Cheers,

Signature · 1 line
heikki
#69 lore raw

Re: [PATCH 8/8] phy: add driver for TI TUSB1210 ULPI PHY

Quoted 46 lines · Heikki Krogerus

Hi,

Quoted 18 lines · David Cohen

Hi Heikki,

Sorry I am starting a new branch on this thread. I need to go back to another topic on this same patch.

Quoted 9 lines · Heikki Krogerus

TUSB1210 ULPI PHY has vendor specific register for eye diagram tuning. On some platforms the system firmware has set optimized value to it. In order to not loose the optimized value, the driver stores it during probe and restores it every time the PHY is powered back on.

Cc Kishon Vijay Abraham I <[email protected]>

---

[snip]

Quoted 7 lines

drivers/phy/phy-tusb1210.c line 87

Quoted 2 lines
drivers/phy/phy-tusb1210.c new file +2 -0
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, TUSB1210_VENDOR_SPECIFIC2);

We can't rely on eye diagram optimization value here. It's possible the phy went through reset (e.g. module unloading/loading).
We need a more consistent method. Could we use _DSD instead? That would be more compatible with DT too.

I'm don't have any problem with getting the value from a property. Sounds like the correct thing to do. Are you thinking about putting that _DSD method to the ACPI device object for the dwc3? The correct place would probable be separate device object for the PHY, but if we do that we need to consider how that object is bound to the ulpi device. There are few ways we can do that, so it requires some thinking.

In any case this driver we can already implement so that it expects to get the value from property. We just need the name for it.

The register has actually separate fields for High speed output impedance configuration and High speed output driver strength configuration for eye diagram tuning, plus control bit for DP/DM swap.

Maybe we should actually get them from three separate properties:

Quoted 8 lines
        device_property_read_u8(dev, "datapolarity", &val);
        ...
        device_property_read_u8(dev, "zhsdrv", &val);
        ...
        device_property_read_u8(dev, "ihstx", &val);
        ...

What do you think?

it's probably better to pass each value and let the driver calculate the register contents like this.

Signature · 1 line
balbi