Skip to contentSkip to conversation

phy: ulpi bus

PATCH In review Heikki Krogerus 2 participants 15 messages Jan 20, 2015 – Jan 23, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover phy: ulpi bus

Heikki Krogerus (3):
phy: add bus for USB ULPI PHYs
usb: dwc3: add ULPI interface support
phy: ulpi: add driver for TI TUSB1210

 MAINTAINERS                        |   7 ++
 drivers/phy/Kconfig                |   2 +
 drivers/phy/Makefile               |   1 +
 drivers/phy/ulpi/Kconfig           |  20 +++
 drivers/phy/ulpi/Makefile          |   4 +
 drivers/phy/ulpi/tusb1210.c        | 131 ++++++++++++++++++++
 drivers/phy/ulpi/ulpi.c            | 246 +++++++++++++++++++++++++++++++++++++
 drivers/phy/ulpi/ulpi_phy.h        |  31 +++++
 drivers/usb/dwc3/Kconfig           |   7 ++
 drivers/usb/dwc3/Makefile          |   4 +
 drivers/usb/dwc3/core.c            |   9 +-
 drivers/usb/dwc3/core.h            |  22 ++++
 drivers/usb/dwc3/ulpi.c            | 102 +++++++++++++++
 include/linux/phy/ulpi/driver.h    |  58 +++++++++
 include/linux/phy/ulpi/interface.h |  23 ++++
 include/linux/phy/ulpi/regs.h      | 130 ++++++++++++++++++++
 include/linux/usb/ulpi.h           | 135 +-------------------
 17 files changed, 799 insertions(+), 133 deletions(-)
 create mode 100644 drivers/phy/ulpi/Kconfig
 create mode 100644 drivers/phy/ulpi/Makefile
 create mode 100644 drivers/phy/ulpi/tusb1210.c
 create mode 100644 drivers/phy/ulpi/ulpi.c
 create mode 100644 drivers/phy/ulpi/ulpi_phy.h
 create mode 100644 drivers/usb/dwc3/ulpi.c
 create mode 100644 include/linux/phy/ulpi/driver.h
 create mode 100644 include/linux/phy/ulpi/interface.h
 create mode 100644 include/linux/phy/ulpi/regs.h
Signature · 1 line
2.1.4
#1 lore raw

PATCH 1/3 phy: add bus for USB ULPI PHYs

UTMI+ Low Pin Interface (ULPI) is a commonly used PHY interface for USB 2.0. It describe a standard set of registers which the vendors can extend for their specific needs.

ULPI registers are accessed from the controller. The purpose of the bus is to provide nice way for the controller drivers to share that access with the actual PHY drivers.

---
 MAINTAINERS                        |   7 ++
 drivers/phy/Kconfig                |   2 +
 drivers/phy/Makefile               |   1 +
 drivers/phy/ulpi/Kconfig           |   9 ++
 drivers/phy/ulpi/Makefile          |   2 +
 drivers/phy/ulpi/ulpi.c            | 246 +++++++++++++++++++++++++++++++++++++
 drivers/phy/ulpi/ulpi_phy.h        |  31 +++++
 include/linux/phy/ulpi/driver.h    |  58 +++++++++
 include/linux/phy/ulpi/interface.h |  23 ++++
 include/linux/phy/ulpi/regs.h      | 130 ++++++++++++++++++++
 include/linux/usb/ulpi.h           | 135 +-------------------
 11 files changed, 512 insertions(+), 132 deletions(-)
 create mode 100644 drivers/phy/ulpi/Kconfig
 create mode 100644 drivers/phy/ulpi/Makefile
 create mode 100644 drivers/phy/ulpi/ulpi.c
 create mode 100644 drivers/phy/ulpi/ulpi_phy.h
 create mode 100644 include/linux/phy/ulpi/driver.h
 create mode 100644 include/linux/phy/ulpi/interface.h
 create mode 100644 include/linux/phy/ulpi/regs.h
MAINTAINERS +7 -0
index 4ef032a..fce81a4 100644
@@ -4233,6 +4233,13 @@ S:	Supported
 F:	drivers/phy/
 F:	include/linux/phy/
 
+ULPI PHY BUS
+M:	Heikki Krogerus <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/phy/ulpi/
+F:	include/linux/phy/ulpi/
+
 GENERIC UIO DRIVER FOR PCI DEVICES
 M:	"Michael S. Tsirkin" <[email protected]>
 L:	[email protected]
drivers/phy/Kconfig +2 -0
index ccad880..9bfb556 100644
@@ -277,4 +277,6 @@ config PHY_STIH41X_USB
 	  Enable this to support the USB transceiver that is part of
 	  STMicroelectronics STiH41x SoC series.
 
+source "drivers/phy/ulpi/Kconfig"
+
 endmenu
drivers/phy/Makefile +1 -0
index aa74f96..8914f3d 100644
@@ -34,3 +34,4 @@ obj-$(CONFIG_PHY_ST_SPEAR1340_MIPHY)	+= phy-spear1340-miphy.o
 obj-$(CONFIG_PHY_XGENE)			+= phy-xgene.o
 obj-$(CONFIG_PHY_STIH407_USB)		+= phy-stih407-usb.o
 obj-$(CONFIG_PHY_STIH41X_USB)		+= phy-stih41x-usb.o
+obj-$(CONFIG_ULPI_PHY)			+= ulpi/
drivers/phy/ulpi/Kconfig new file +9 -0
new file mode 100644
index 0000000..8007df2
@@ -0,0 +1,9 @@
+
+config ULPI_PHY
+	bool "USB ULPI PHY interface support"
+	depends on USB || USB_GADGET
+	select GENERIC_PHY
+	help
+	  Say yes if you have ULPI PHY attached to your USB controller.
+
+	  If unsure, say N.
drivers/phy/ulpi/Makefile new file +2 -0
new file mode 100644
index 0000000..59e61cb
@@ -0,0 +1,2 @@
+ulpiphy-y			:= ulpi.o
+obj-$(CONFIG_ULPI_PHY)		+= ulpiphy.o
drivers/phy/ulpi/ulpi.c new file +246 -0

246 lines not on this page · raw message

drivers/phy/ulpi/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);
+}
include/linux/phy/ulpi/driver.h new file +58 -0

58 lines not on this page · raw message

include/linux/phy/ulpi/interface.h new file +23 -0
new file mode 100644
index 0000000..51569fe
@@ -0,0 +1,23 @@
+#ifndef __DRIVERS_PHY_ULPI_INTERFACE_H
+#define __DRIVERS_PHY_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 /* __DRIVERS_PHY_ULPI_INTERFACE_H */
include/linux/phy/ulpi/regs.h new file +130 -0

130 lines not on this page · raw message

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

147 lines not on this page · raw message

Signature · 1 line
2.1.4
#2 lore raw

PATCH 2/3 usb: dwc3: add ULPI interface support

In reply to Heikki Krogerus

Registers ULPI interface with the ULPI bus if HSPHY type is ULPI.

---
 drivers/usb/dwc3/Kconfig  |   7 ++++
 drivers/usb/dwc3/Makefile |   4 ++
 drivers/usb/dwc3/core.c   |   9 +++-
 drivers/usb/dwc3/core.h   |  22 ++++++++++
 drivers/usb/dwc3/ulpi.c   | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/dwc3/ulpi.c
drivers/usb/dwc3/Kconfig +7 -0
index 58b5b2c..6d0c5e6 100644
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+	bool "Provide ULPI PHY Interface"
+	depends on ULPI_PHY=y || ULPI_PHY=USB_DWC3
+	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 +8 -1
index 25ddc39..5219bc7 100644
@@ -876,12 +876,17 @@ 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_ulpi_init(dwc);
+	if (ret)
+		return ret;
+
 	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;
@@ -965,6 +970,7 @@ err1:
 
 err0:
 	dwc3_free_event_buffers(dwc);
+	dwc3_ulpi_exit(dwc);
 
 	return ret;
 }
@@ -984,6 +990,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 +22 -0
index 0842aa8..f6881a6 100644
@@ -32,6 +32,7 @@
 #include <linux/usb/otg.h>
 
 #include <linux/phy/phy.h>
+#include <linux/phy/ulpi/interface.h>
 
 #define DWC3_MSG_MAX	500
 
@@ -174,6 +175,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)
@@ -590,6 +599,7 @@ struct dwc3_hwparams {
 #define DWC3_NUM_INT(n)		(((n) & (0x3f << 15)) >> 15)
 
 /* HWPARAMS3 */
+#define DWC3_ULPI_HSPHY		(1 << 3)
 #define DWC3_NUM_IN_EPS_MASK	(0x1f << 18)
 #define DWC3_NUM_EPS_MASK	(0x3f << 12)
 #define DWC3_NUM_EPS(p)		(((p)->hwparams3 &		\
@@ -739,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;
 
@@ -1035,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 +102 -0

102 lines not on this page · raw message

Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH 2/3] usb: dwc3: add ULPI interface support

Hi,

Quoted 5 lines · Heikki Krogerus

Registers ULPI interface with the ULPI bus if HSPHY type is ULPI.

you're doing quite a bit in a single patch...

Quoted 52 lines
---
 drivers/usb/dwc3/Kconfig  |   7 ++++
 drivers/usb/dwc3/Makefile |   4 ++
 drivers/usb/dwc3/core.c   |   9 +++-
 drivers/usb/dwc3/core.h   |  22 ++++++++++
 drivers/usb/dwc3/ulpi.c   | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/dwc3/ulpi.c
drivers/usb/dwc3/Kconfig +7 -0
index 58b5b2c..6d0c5e6 100644
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+	bool "Provide ULPI PHY Interface"
+	depends on ULPI_PHY=y || ULPI_PHY=USB_DWC3
+	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 +2 -0
index 25ddc39..5219bc7 100644
@@ -876,12 +876,17 @@ static int dwc3_probe(struct platform_device *pdev)
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
 
+	platform_set_drvdata(pdev, dwc);
+

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

Quoted 10 lines
drivers/usb/dwc3/core.c +4 -1
+	ret = dwc3_ulpi_init(dwc);
+	if (ret)
+		return ret;
+
 	ret = dwc3_core_get_phy(dwc);
 	if (ret)
 		return ret;
 
 	spin_lock_init(&dwc->lock);
-	platform_set_drvdata(pdev, dwc);

why do you need to move this ? Looks like this should be a cleanup and split into a single patch.

it also appears that you need another patch moving dwc3_cache_hwparams() before all of these other calls, so you can use it from dwc3_ulpi_init().

Quoted 29 lines
drivers/usb/dwc3/core.c +2 -0
@@ -965,6 +970,7 @@ err1:
 
 err0:
 	dwc3_free_event_buffers(dwc);
+	dwc3_ulpi_exit(dwc);
 
 	return ret;
 }
@@ -984,6 +990,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 +1 -0
index 0842aa8..f6881a6 100644
@@ -32,6 +32,7 @@
 #include <linux/usb/otg.h>
 
 #include <linux/phy/phy.h>
+#include <linux/phy/ulpi/interface.h>
 
 #define DWC3_MSG_MAX	500
 

drivers/usb/dwc3/core.h line 184

Quoted 10 lines
drivers/usb/dwc3/core.h +7 -0
@@ -174,6 +175,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)

separate patch

drivers/usb/dwc3/core.h struct dwc3_hwparams { · line 602

Quoted 5 lines
drivers/usb/dwc3/core.h +1 -0
@@ -590,6 +599,7 @@ struct dwc3_hwparams {
 #define DWC3_NUM_INT(n)		(((n) & (0x3f << 15)) >> 15)
 
 /* HWPARAMS3 */
+#define DWC3_ULPI_HSPHY		(1 << 3)

you also need a patch which defines this bit of HWPARAMS3. This is also the wrong definition. Which core revision do you have ? I can see that bit 3 is part of a 2 bit field called:

DWC_USB3_HSPHY_INTERFACE

moreover, there are systems which have both ULPI and UTMI enabled and you can't really know which one the PHY is using.

This needs a bit more thought.

Quoted 54 lines
drivers/usb/dwc3/core.h +12 -0
 #define DWC3_NUM_IN_EPS_MASK	(0x1f << 18)
 #define DWC3_NUM_EPS_MASK	(0x3f << 12)
 #define DWC3_NUM_EPS(p)		(((p)->hwparams3 &		\
@@ -739,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;
 
@@ -1035,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 +21 -0
new file mode 100644
index 0000000..ee3ebbe
@@ -0,0 +1,102 @@
+/**
+ * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface
+ *
+ * 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/phy/ulpi/regs.h>
+
+#include "core.h"
+#include "io.h"
+
+#define DWC3_ULPI_ADDR(a) \
+		((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \
+		DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \
+		DWC3_GUSB2PHYACC_EXTEND_ADDR(a) : DWC3_GUSB2PHYACC_ADDR(a))

drivers/usb/dwc3/ulpi.c line 31

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+
+static int dwc3_ulpi_busyloop(struct dwc3 *dwc)
+{
+	unsigned count = 1000;
+	u32 reg;
+
+	while (count--) {
+		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0));
+		if (!(reg & DWC3_GUSB2PHYACC_BUSY))
+			return 0;

this could use a cpu_relax();

Quoted 43 lines
drivers/usb/dwc3/ulpi.c new file +43 -0
+	}
+
+	return -ETIMEDOUT;
+}
+
+static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr)
+{
+	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	u32 reg;
+	int ret;
+
+	reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
+
+	ret = dwc3_ulpi_busyloop(dwc);
+	if (ret)
+		return ret;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0));
+
+	return DWC3_GUSB2PHYACC_DATA(reg);
+}
+
+static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val)
+{
+	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	u32 reg;
+	int ret;
+
+	reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
+	reg |= DWC3_GUSB2PHYACC_WRITE | val;
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
+
+	ret = dwc3_ulpi_busyloop(dwc);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static struct ulpi_ops dwc3_ulpi = {
+	.read = dwc3_ulpi_read,
+	.write = dwc3_ulpi_write,

drivers/usb/dwc3/ulpi.c line 84

Quoted 10 lines
drivers/usb/dwc3/ulpi.c new file +10 -0
+};
+
+int dwc3_ulpi_init(struct dwc3 *dwc)
+{
+	int ret;
+
+	/* First check if there is ULPI PHY */
+	ret = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
+	if (!(ret & DWC3_ULPI_HSPHY))
+		return 0;

should use the cached structure.

Quoted 20 lines
drivers/usb/dwc3/ulpi.c new file +17 -0
+	/* Register the interface */
+	dwc->ulpi = ulpi_register_interface(dwc->dev, &dwc3_ulpi);
+	if (IS_ERR(dwc->ulpi)) {
+		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) {
+		ulpi_unregister_interface(dwc->ulpi);
+		dwc->ulpi = NULL;
+	}
+}
Signature · 1 line
2.1.4
Signature · 1 line
balbi
#4 lore raw

Re: [PATCH 2/3] usb: dwc3: add ULPI interface support

Quoted 71 lines · Felipe Balbi

Hi,

Quoted 5 lines · Heikki Krogerus

Registers ULPI interface with the ULPI bus if HSPHY type is ULPI.

you're doing quite a bit in a single patch...

Quoted 60 lines
---
 drivers/usb/dwc3/Kconfig  |   7 ++++
 drivers/usb/dwc3/Makefile |   4 ++
 drivers/usb/dwc3/core.c   |   9 +++-
 drivers/usb/dwc3/core.h   |  22 ++++++++++
 drivers/usb/dwc3/ulpi.c   | 102 ++++++++++++++++++++++++++++++++++++++++++++++
 5 files changed, 143 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/dwc3/ulpi.c
drivers/usb/dwc3/Kconfig +7 -0
index 58b5b2c..6d0c5e6 100644
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+	bool "Provide ULPI PHY Interface"
+	depends on ULPI_PHY=y || ULPI_PHY=USB_DWC3
+	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 25ddc39..5219bc7 100644
@@ -876,12 +876,17 @@ 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_ulpi_init(dwc);
+	if (ret)
+		return ret;
+
 	ret = dwc3_core_get_phy(dwc);
 	if (ret)
 		return ret;
 
Quoted 5 lines

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

Quoted 2 lines
drivers/usb/dwc3/core.c +0 -1
 	spin_lock_init(&dwc->lock);
-	platform_set_drvdata(pdev, dwc);

why do you need to move this ? Looks like this should be a cleanup and split into a single patch.

OK.

Quoted 3 lines

it also appears that you need another patch moving dwc3_cache_hwparams() before all of these other calls, so you can use it from dwc3_ulpi_init().

OK.

Quoted 32 lines
Quoted 32 lines
drivers/usb/dwc3/core.c +2 -0
@@ -965,6 +970,7 @@ err1:
 
 err0:
 	dwc3_free_event_buffers(dwc);
+	dwc3_ulpi_exit(dwc);
 
 	return ret;
 }
@@ -984,6 +990,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 +1 -0
index 0842aa8..f6881a6 100644
@@ -32,6 +32,7 @@
 #include <linux/usb/otg.h>
 
 #include <linux/phy/phy.h>
+#include <linux/phy/ulpi/interface.h>
 
 #define DWC3_MSG_MAX	500
 
@@ -174,6 +175,14 @@
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST	(1 << 31)
 #define DWC3_GUSB2PHYCFG_SUSPHY		(1 << 6)
 
Quoted 9 lines

drivers/usb/dwc3/core.h line 184

Quoted 7 lines
drivers/usb/dwc3/core.h +7 -0
+/* 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)

separate patch

OK.

Quoted 11 lines

drivers/usb/dwc3/core.h struct dwc3_hwparams { · line 602

Quoted 5 lines
drivers/usb/dwc3/core.h +1 -0
@@ -590,6 +599,7 @@ struct dwc3_hwparams {
 #define DWC3_NUM_INT(n)		(((n) & (0x3f << 15)) >> 15)
 
 /* HWPARAMS3 */
+#define DWC3_ULPI_HSPHY		(1 << 3)

you also need a patch which defines this bit of HWPARAMS3. This is also the wrong definition. Which core revision do you have ? I can see that bit 3 is part of a 2 bit field called:

DWC_USB3_HSPHY_INTERFACE

I have the same in my databook. I agree, it's not good like that.

Quoted 4 lines

moreover, there are systems which have both ULPI and UTMI enabled and you can't really know which one the PHY is using.

This needs a bit more thought.

Sure, I'll think of something better for this.

Quoted 58 lines
Quoted 58 lines
drivers/usb/dwc3/core.h +12 -0
 #define DWC3_NUM_IN_EPS_MASK	(0x1f << 18)
 #define DWC3_NUM_EPS_MASK	(0x3f << 12)
 #define DWC3_NUM_EPS(p)		(((p)->hwparams3 &		\
@@ -739,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;
 
@@ -1035,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 +25 -0
new file mode 100644
index 0000000..ee3ebbe
@@ -0,0 +1,102 @@
+/**
+ * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface
+ *
+ * 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/phy/ulpi/regs.h>
+
+#include "core.h"
+#include "io.h"
+
+#define DWC3_ULPI_ADDR(a) \
+		((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \
+		DWC3_GUSB2PHYACC_ADDR(ULPI_ACCESS_EXTENDED) | \
+		DWC3_GUSB2PHYACC_EXTEND_ADDR(a) : DWC3_GUSB2PHYACC_ADDR(a))
+
+static int dwc3_ulpi_busyloop(struct dwc3 *dwc)
+{
+	unsigned count = 1000;
Quoted 8 lines

drivers/usb/dwc3/ulpi.c line 31

Quoted 6 lines
drivers/usb/dwc3/ulpi.c new file +6 -0
+	u32 reg;
+
+	while (count--) {
+		reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0));
+		if (!(reg & DWC3_GUSB2PHYACC_BUSY))
+			return 0;

this could use a cpu_relax();

Agreed.

Quoted 47 lines
Quoted 47 lines
drivers/usb/dwc3/ulpi.c new file +47 -0
+	}
+
+	return -ETIMEDOUT;
+}
+
+static int dwc3_ulpi_read(struct ulpi_ops *ops, u8 addr)
+{
+	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	u32 reg;
+	int ret;
+
+	reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
+
+	ret = dwc3_ulpi_busyloop(dwc);
+	if (ret)
+		return ret;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYACC(0));
+
+	return DWC3_GUSB2PHYACC_DATA(reg);
+}
+
+static int dwc3_ulpi_write(struct ulpi_ops *ops, u8 addr, u8 val)
+{
+	struct dwc3 *dwc = dev_get_drvdata(ops->dev);
+	u32 reg;
+	int ret;
+
+	reg = DWC3_GUSB2PHYACC_NEWREGREQ | DWC3_ULPI_ADDR(addr);
+	reg |= DWC3_GUSB2PHYACC_WRITE | val;
+	dwc3_writel(dwc->regs, DWC3_GUSB2PHYACC(0), reg);
+
+	ret = dwc3_ulpi_busyloop(dwc);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static struct ulpi_ops dwc3_ulpi = {
+	.read = dwc3_ulpi_read,
+	.write = dwc3_ulpi_write,
+};
+
+int dwc3_ulpi_init(struct dwc3 *dwc)
+{
Quoted 8 lines

drivers/usb/dwc3/ulpi.c line 84

Quoted 6 lines
drivers/usb/dwc3/ulpi.c new file +6 -0
+	int ret;
+
+	/* First check if there is ULPI PHY */
+	ret = dwc3_readl(dwc->regs, DWC3_GHWPARAMS3);
+	if (!(ret & DWC3_ULPI_HSPHY))
+		return 0;

should use the cached structure.

Sure.

Thanks,

Signature · 1 line
heikki
#5 lore raw

PATCH 3/3 phy: ulpi: add driver for TI TUSB1210

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.

---
 drivers/phy/ulpi/Kconfig    |  11 ++++
 drivers/phy/ulpi/Makefile   |   2 +
 drivers/phy/ulpi/tusb1210.c | 131 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/phy/ulpi/tusb1210.c
drivers/phy/ulpi/Kconfig +11 -0
index 8007df2..7cd6f82 100644
@@ -7,3 +7,14 @@ config ULPI_PHY
 	  Say yes if you have ULPI PHY attached to your USB controller.
 
 	  If unsure, say N.
+
+if ULPI_PHY
+
+config ULPI_TUSB1210
+	tristate "TI TUSB1210 USB PHY module"
+	depends on POWER_SUPPLY
+	select USB_PHY
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
+endif
drivers/phy/ulpi/Makefile +2 -0
index 59e61cb..7ee6679 100644
@@ -1,2 +1,4 @@
 ulpiphy-y			:= ulpi.o
 obj-$(CONFIG_ULPI_PHY)		+= ulpiphy.o
+
+obj-$(CONFIG_ULPI_TUSB1210)	+= tusb1210.o
drivers/phy/ulpi/tusb1210.c new file +131 -0

131 lines not on this page · raw message

Signature · 1 line
2.1.4
#6 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Hi,

drivers/phy/ulpi/tusb1210.c

Quoted 47 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.

---
 drivers/phy/ulpi/Kconfig    |  11 ++++
 drivers/phy/ulpi/Makefile   |   2 +
 drivers/phy/ulpi/tusb1210.c | 131 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/phy/ulpi/tusb1210.c
drivers/phy/ulpi/Kconfig +11 -0
index 8007df2..7cd6f82 100644
@@ -7,3 +7,14 @@ config ULPI_PHY
 	  Say yes if you have ULPI PHY attached to your USB controller.
 
 	  If unsure, say N.
+
+if ULPI_PHY
+
+config ULPI_TUSB1210
+	tristate "TI TUSB1210 USB PHY module"
+	depends on POWER_SUPPLY
+	select USB_PHY
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
+endif
drivers/phy/ulpi/Makefile +2 -0
index 59e61cb..7ee6679 100644
@@ -1,2 +1,4 @@
 ulpiphy-y			:= ulpi.o
 obj-$(CONFIG_ULPI_PHY)		+= ulpiphy.o
+
+obj-$(CONFIG_ULPI_TUSB1210)	+= tusb1210.o
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

I wonder if phy-tusb1210.c as a name would be enough.

Quoted 76 lines
drivers/phy/ulpi/tusb1210.c new file +75 -0
@@ -0,0 +1,131 @@
+/**
+ * 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/phy/ulpi/driver.h>
+#include <linux/phy/ulpi/regs.h>
+#include <linux/gpio/consumer.h>
+
+#include "ulpi_phy.h"
+
+struct tusb1210 {
+	struct ulpi *ulpi;
+	struct phy *phy;
+	struct gpio_desc *gpio_reset;
+	struct gpio_desc *gpio_cs;
+	u8 ctx[1];
+};
+
+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 optimisation value */
+	ulpi_write(tusb->ulpi, ULPI_EXT_VENDOR_SPECIFIC, tusb->ctx[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);
+	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/ulpi/tusb1210.c line 85

Quoted 10 lines
drivers/phy/ulpi/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;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, ULPI_EXT_VENDOR_SPECIFIC);

do they *all* use this register for eye diagram optimization or is this something that Intel decided to do ?

(sorry, don't know much about tusb1210 other than it sucks like hell :-)

Quoted 9 lines
drivers/phy/ulpi/tusb1210.c new file +9 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->ctx[0] = ret;
+
+	tusb->phy = ulpi_phy_create(ulpi, &phy_ops);
+	if (IS_ERR(tusb->phy))
+		return PTR_ERR(tusb->phy);
+

drivers/phy/ulpi/tusb1210.c line 104

Quoted 10 lines
drivers/phy/ulpi/tusb1210.c new file +10 -0
+	tusb->ulpi = ulpi;
+
+	phy_set_drvdata(tusb->phy, tusb);
+	dev_set_drvdata(&ulpi->dev, tusb);
+	return 0;
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = dev_get_drvdata(&ulpi->dev);

completely unrelated to $subject, but we might want to have a ulpi_{set,get}_drvdata() at some point.

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

Quoted 16 lines
drivers/phy/ulpi/tusb1210.c new file +16 -0
+
+	ulpi_phy_destroy(ulpi, tusb->phy);
+}
+
+#define TI_VENDOR_ID 0x0451
+
+static 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,

drivers/phy/ulpi/tusb1210.c line 130

Quoted 10 lines
drivers/phy/ulpi/tusb1210.c new file +10 -0
+	.driver = {
+		.name = "tusb1210",
+		.owner = THIS_MODULE,
+	},
+};
+
+module_ulpi_driver(tusb1210_driver);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL");

comment says GPL 2 only, this says GPL 2+

Signature · 1 line
balbi
#7 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Quoted 53 lines · Felipe Balbi

Hi,

drivers/phy/ulpi/tusb1210.c

Quoted 47 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.

---
 drivers/phy/ulpi/Kconfig    |  11 ++++
 drivers/phy/ulpi/Makefile   |   2 +
 drivers/phy/ulpi/tusb1210.c | 131 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/phy/ulpi/tusb1210.c
drivers/phy/ulpi/Kconfig +11 -0
index 8007df2..7cd6f82 100644
@@ -7,3 +7,14 @@ config ULPI_PHY
 	  Say yes if you have ULPI PHY attached to your USB controller.
 
 	  If unsure, say N.
+
+if ULPI_PHY
+
+config ULPI_TUSB1210
+	tristate "TI TUSB1210 USB PHY module"
+	depends on POWER_SUPPLY
+	select USB_PHY
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
+endif
drivers/phy/ulpi/Makefile +2 -0
index 59e61cb..7ee6679 100644
@@ -1,2 +1,4 @@
 ulpiphy-y			:= ulpi.o
 obj-$(CONFIG_ULPI_PHY)		+= ulpiphy.o
+
+obj-$(CONFIG_ULPI_TUSB1210)	+= tusb1210.o
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

Quoted 90 lines
Quoted 76 lines
drivers/phy/ulpi/tusb1210.c new file +75 -0
@@ -0,0 +1,131 @@
+/**
+ * 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/phy/ulpi/driver.h>
+#include <linux/phy/ulpi/regs.h>
+#include <linux/gpio/consumer.h>
+
+#include "ulpi_phy.h"
+
+struct tusb1210 {
+	struct ulpi *ulpi;
+	struct phy *phy;
+	struct gpio_desc *gpio_reset;
+	struct gpio_desc *gpio_cs;
+	u8 ctx[1];
+};
+
+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 optimisation value */
+	ulpi_write(tusb->ulpi, ULPI_EXT_VENDOR_SPECIFIC, tusb->ctx[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);
+	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/ulpi/tusb1210.c line 85

Quoted 10 lines
drivers/phy/ulpi/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;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, ULPI_EXT_VENDOR_SPECIFIC);

do they *all* use this register for eye diagram optimization or is this something that Intel decided to do ?

Quoted 1 line

(sorry, don't know much about tusb1210 other than it sucks like hell :-)

All I know that somebody needs to save the value. The ones using this PHY who don't need to save it can most likely live without the driver.

Quoted 14 lines
Quoted 14 lines
drivers/phy/ulpi/tusb1210.c new file +14 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->ctx[0] = 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);
+	dev_set_drvdata(&ulpi->dev, tusb);
+	return 0;
Quoted 8 lines

drivers/phy/ulpi/tusb1210.c line 104

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +5 -0
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = dev_get_drvdata(&ulpi->dev);

completely unrelated to $subject, but we might want to have a ulpi_{set,get}_drvdata() at some point.

Makes sense.

Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

Quoted 20 lines
Quoted 20 lines
drivers/phy/ulpi/tusb1210.c new file +20 -0
+
+	ulpi_phy_destroy(ulpi, tusb->phy);
+}
+
+#define TI_VENDOR_ID 0x0451
+
+static 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,
+	},
Quoted 8 lines

drivers/phy/ulpi/tusb1210.c line 130

Quoted 6 lines
drivers/phy/ulpi/tusb1210.c new file +6 -0
+};
+
+module_ulpi_driver(tusb1210_driver);
+
+MODULE_AUTHOR("Intel Corporation");
+MODULE_LICENSE("GPL");

comment says GPL 2 only, this says GPL 2+

True. I'll fix it.

Thanks!

Signature · 1 line
heikki
#8 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Hi,

Quoted 9 lines · Heikki Krogerus
Quoted 8 lines · Felipe Balbi

drivers/phy/ulpi/tusb1210.c

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 4 lines
Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

A correction to this comment. I probable don't need this folder. Like you said, phy-tusb1210.c should be enough..

<snip>

Quoted 5 lines
Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

..I talked with Alex about this :). So I think the bus belongs under drivers/usb/core/ instead of driver/phy/. It's not really tied to the Generic PHY framework in any way, but ULPI is of course USB specific.

Cheers,

Signature · 1 line
heikki
#9 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Quoted 25 lines · Heikki Krogerus

Hi,

Quoted 9 lines · Heikki Krogerus
Quoted 8 lines · Felipe Balbi

drivers/phy/ulpi/tusb1210.c

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 4 lines
Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

A correction to this comment. I probable don't need this folder. Like you said, phy-tusb1210.c should be enough..

<snip>

Quoted 3 lines
Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

Quoted 6 lines
Quoted 2 lines

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

..I talked with Alex about this :). So I think the bus belongs under drivers/usb/core/ instead of driver/phy/. It's not really tied to the Generic PHY framework in any way, but ULPI is of course USB specific.

right, maybe drivers/usb/ulpi or maybe drivers/ulpi, and have phy-tusb1201 register under that ulpi_bus_type instead of platform_bus_type, but still use drivers/phy to register itself a phy provider ;-)

Signature · 1 line
balbi
#10 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Quoted 29 lines · Felipe Balbi
Quoted 28 lines · Heikki Krogerus

Hi,

Quoted 9 lines · Heikki Krogerus
Quoted 8 lines · Felipe Balbi

drivers/phy/ulpi/tusb1210.c

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 4 lines
Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

A correction to this comment. I probable don't need this folder. Like you said, phy-tusb1210.c should be enough..

<snip>

Quoted 5 lines
Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

Quoted 8 lines
Quoted 3 lines

..I talked with Alex about this :). So I think the bus belongs under drivers/usb/core/ instead of driver/phy/. It's not really tied to the Generic PHY framework in any way, but ULPI is of course USB specific.

right, maybe drivers/usb/ulpi or maybe drivers/ulpi, and have phy-tusb1201 register under that ulpi_bus_type instead of platform_bus_type, but still use drivers/phy to register itself a phy provider ;-)

So just for the record: This driver does not register under platform_bus_type bus but instead already under ulpi_bus_type.

I'll prepare new version out of these today and try to figure out proper place for the code (maybe drivers/usb/ulpi?).

Cheers,

Signature · 1 line
heikki
#11 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Quoted 34 lines · Heikki Krogerus
Quoted 33 lines · Felipe Balbi
Quoted 31 lines · Heikki Krogerus

Hi,

Quoted 9 lines · Heikki Krogerus
Quoted 8 lines · Felipe Balbi

drivers/phy/ulpi/tusb1210.c

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 4 lines
Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

A correction to this comment. I probable don't need this folder. Like you said, phy-tusb1210.c should be enough..

<snip>

Quoted 5 lines
Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

..I talked with Alex about this :). So I think the bus belongs under drivers/usb/core/ instead of driver/phy/. It's not really tied to the Generic PHY framework in any way, but ULPI is of course USB specific.

Quoted 7 lines
Quoted 4 lines

right, maybe drivers/usb/ulpi or maybe drivers/ulpi, and have phy-tusb1201 register under that ulpi_bus_type instead of platform_bus_type, but still use drivers/phy to register itself a phy provider ;-)

So just for the record: This driver does not register under platform_bus_type bus but instead already under ulpi_bus_type.

hah! :-)

Quoted 2 lines

I'll prepare new version out of these today and try to figure out proper place for the code (maybe drivers/usb/ulpi?).

drivers/phy is fine, it is a phy driver anyway... I just should've read it to see there was a ulpi_bus_type :-)

Signature · 1 line
balbi
#12 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

In reply to Heikki Krogerus

Hi,

Quoted 50 lines · Heikki Krogerus
Quoted 50 lines

drivers/phy/ulpi/tusb1210.c

Quoted 47 lines

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.

---
 drivers/phy/ulpi/Kconfig    |  11 ++++
 drivers/phy/ulpi/Makefile   |   2 +
 drivers/phy/ulpi/tusb1210.c | 131 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 144 insertions(+)
 create mode 100644 drivers/phy/ulpi/tusb1210.c
drivers/phy/ulpi/Kconfig +11 -0
index 8007df2..7cd6f82 100644
@@ -7,3 +7,14 @@ config ULPI_PHY
 	  Say yes if you have ULPI PHY attached to your USB controller.
 
 	  If unsure, say N.
+
+if ULPI_PHY
+
+config ULPI_TUSB1210
+	tristate "TI TUSB1210 USB PHY module"
+	depends on POWER_SUPPLY
+	select USB_PHY
+	help
+	  Support for TI TUSB1210 USB ULPI PHY.
+
+endif
drivers/phy/ulpi/Makefile +2 -0
index 59e61cb..7ee6679 100644
@@ -1,2 +1,4 @@
 ulpiphy-y			:= ulpi.o
 obj-$(CONFIG_ULPI_PHY)		+= ulpiphy.o
+
+obj-$(CONFIG_ULPI_TUSB1210)	+= tusb1210.o
drivers/phy/ulpi/tusb1210.c new file +0 -0
new file mode 100644
index 0000000..ac77f98

do you really need this extra ulpi directory ?

Quoted 4 lines
Quoted 1 line

I wonder if phy-tusb1210.c as a name would be enough.

IMO grouping the ULPI PHY drivers and other ULPI bus code into separate folder from the start is the right thing to do.

because... :-)

Quoted 90 lines
Quoted 90 lines
Quoted 76 lines
drivers/phy/ulpi/tusb1210.c new file +75 -0
@@ -0,0 +1,131 @@
+/**
+ * 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/phy/ulpi/driver.h>
+#include <linux/phy/ulpi/regs.h>
+#include <linux/gpio/consumer.h>
+
+#include "ulpi_phy.h"
+
+struct tusb1210 {
+	struct ulpi *ulpi;
+	struct phy *phy;
+	struct gpio_desc *gpio_reset;
+	struct gpio_desc *gpio_cs;
+	u8 ctx[1];
+};
+
+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 optimisation value */
+	ulpi_write(tusb->ulpi, ULPI_EXT_VENDOR_SPECIFIC, tusb->ctx[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);
+	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/ulpi/tusb1210.c line 85

Quoted 10 lines
drivers/phy/ulpi/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;
+	}
+
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, ULPI_EXT_VENDOR_SPECIFIC);

do they *all* use this register for eye diagram optimization or is this something that Intel decided to do ?

Quoted 4 lines
Quoted 1 line

(sorry, don't know much about tusb1210 other than it sucks like hell :-)

All I know that somebody needs to save the value. The ones using this PHY who don't need to save it can most likely live without the driver.

right, but what I mean is: is it mandatory that Eye diagram configuration be stored in *this* register? Or is it more like a scratch register which Intel just happens to be using for Eye diagram data ?

Quoted 23 lines
Quoted 14 lines
Quoted 14 lines
drivers/phy/ulpi/tusb1210.c new file +14 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->ctx[0] = 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);
+	dev_set_drvdata(&ulpi->dev, tusb);
+	return 0;
Quoted 8 lines

drivers/phy/ulpi/tusb1210.c line 104

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +5 -0
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = dev_get_drvdata(&ulpi->dev);

completely unrelated to $subject, but we might want to have a ulpi_{set,get}_drvdata() at some point.

Quoted 7 lines

Makes sense.

Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

I mean introducing a real struct bus ulpi_bus_type :-) With match, probe, remove, etc.

Signature · 1 line
balbi
#13 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Hi,

Quoted 7 lines · Felipe Balbi
Quoted 6 lines · Heikki Krogerus
Quoted 6 lines

drivers/phy/ulpi/tusb1210.c line 85

Quoted 2 lines
drivers/phy/ulpi/tusb1210.c new file +2 -0
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, ULPI_EXT_VENDOR_SPECIFIC);

do they *all* use this register for eye diagram optimization or is this something that Intel decided to do ?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

(sorry, don't know much about tusb1210 other than it sucks like hell :-)

All I know that somebody needs to save the value. The ones using this PHY who don't need to save it can most likely live without the driver.

right, but what I mean is: is it mandatory that Eye diagram configuration be stored in *this* register? Or is it more like a scratch register which Intel just happens to be using for Eye diagram data ?

The eye diagram tuning is in that register. Here's the spec:
http://www.ti.com/lit/ds/symlink/tusb1210.pdf

I'll add definition for the register (which is colourfully named "VENDOR_SPECIFIC2").

Quoted 25 lines
Quoted 25 lines
Quoted 14 lines
Quoted 14 lines
drivers/phy/ulpi/tusb1210.c new file +14 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->ctx[0] = 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);
+	dev_set_drvdata(&ulpi->dev, tusb);
+	return 0;
Quoted 8 lines

drivers/phy/ulpi/tusb1210.c line 104

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +5 -0
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = dev_get_drvdata(&ulpi->dev);

completely unrelated to $subject, but we might want to have a ulpi_{set,get}_drvdata() at some point.

Makes sense.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

I mean introducing a real struct bus ulpi_bus_type :-) With match, probe, remove, etc.

I'm already doing that. Please check the first patch in this set:
"phy: add bus for USB ULPI PHYs".

Cheers,

Signature · 1 line
heikki
#14 lore raw

Re: [PATCH 3/3] phy: ulpi: add driver for TI TUSB1210

Quoted 19 lines · Heikki Krogerus

Hi,

Quoted 7 lines · Felipe Balbi
Quoted 6 lines · Heikki Krogerus
Quoted 6 lines

drivers/phy/ulpi/tusb1210.c line 85

Quoted 2 lines
drivers/phy/ulpi/tusb1210.c new file +2 -0
+	/* Store initial eye diagram optimisation value */
+	ret = ulpi_read(ulpi, ULPI_EXT_VENDOR_SPECIFIC);

do they *all* use this register for eye diagram optimization or is this something that Intel decided to do ?

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

(sorry, don't know much about tusb1210 other than it sucks like hell :-)

All I know that somebody needs to save the value. The ones using this PHY who don't need to save it can most likely live without the driver.

right, but what I mean is: is it mandatory that Eye diagram configuration be stored in *this* register? Or is it more like a scratch register which Intel just happens to be using for Eye diagram data ?

Quoted 5 lines

The eye diagram tuning is in that register. Here's the spec:
http://www.ti.com/lit/ds/symlink/tusb1210.pdf

I'll add definition for the register (which is colourfully named "VENDOR_SPECIFIC2").

alright, thanks.

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 14 lines
Quoted 14 lines
drivers/phy/ulpi/tusb1210.c new file +14 -0
+	if (ret < 0)
+		return ret;
+
+	tusb->ctx[0] = 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);
+	dev_set_drvdata(&ulpi->dev, tusb);
+	return 0;
Quoted 8 lines

drivers/phy/ulpi/tusb1210.c line 104

Quoted 5 lines
drivers/phy/ulpi/tusb1210.c new file +5 -0
+}
+
+static void tusb1210_remove(struct ulpi *ulpi)
+{
+	struct tusb1210 *tusb = dev_get_drvdata(&ulpi->dev);

completely unrelated to $subject, but we might want to have a ulpi_{set,get}_drvdata() at some point.

Makes sense.

Quoted 2 lines

In fact, we might decide to add an entire ULPI bus, eventually, though I'm still considering if there's any benefit to that.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

I don't think I understand this comment? ULPI bus is what I'm introducing in this set (the first patch in it)?

I mean introducing a real struct bus ulpi_bus_type :-) With match, probe, remove, etc.

I'm already doing that. Please check the first patch in this set:
"phy: add bus for USB ULPI PHYs".

yeah, sorry about that.

Signature · 1 line
balbi