Skip to contentSkip to conversation

usb: phy: add usb3 phy driver

PATCH Superseded Kishon Vijay Abraham I 2 participants 5 messages Sep 27, 2012 – Sep 28, 2012

Subsystems (3)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover usb: phy: add usb3 phy driver

Added a driver for usb3 phy that handles the interaction between usb phy device and dwc3 controller. Currently writing to control module register is taken care in this driver which will be removed once the control module driver is in place.

Changes from v1:
* Added missing clk_put()
* Remove the patches usb: dwc3: Fix gadget pullup in SS mode and
usb: phy: omap-usb3: Decrease the number of transitions to recovery. Those are actually WA for hw issues which will be fixed in ES2.
* Removed the *has960mhzclk* property

This patch series was rebased on
git://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git xceiv However the dependent modules are not yet upstreamed and hence only compile tested in this tree

Kishon Vijay Abraham I (2):
usb: phy: add a new driver for usb3 phy
usb: phy: omap-usb2: enable 960Mhz clock for omap5

 Documentation/devicetree/bindings/usb/usb-phy.txt |   18 +
 drivers/usb/phy/Kconfig                           |    9 +
 drivers/usb/phy/Makefile                          |    1 +
 drivers/usb/phy/omap-usb2.c                       |   18 +-
 drivers/usb/phy/omap-usb3.c                       |  412 +++++++++++++++++++++
 include/linux/usb/omap_usb.h                      |   33 ++
 6 files changed, 489 insertions(+), 2 deletions(-)
 create mode 100644 drivers/usb/phy/omap-usb3.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v2 1/2 usb: phy: add a new driver for usb3 phy

Added a driver for usb3 phy that handles the interaction between usb phy device and dwc3 controller.

This also includes device tree support for usb3 phy driver and the documentation with device tree binding information is updated.

Currently writing to control module register is taken care in this driver which will be removed once the control module driver is in place.

---
 Documentation/devicetree/bindings/usb/usb-phy.txt |   18 +
 drivers/usb/phy/Kconfig                           |    9 +
 drivers/usb/phy/Makefile                          |    1 +
 drivers/usb/phy/omap-usb3.c                       |  412 +++++++++++++++++++++
 include/linux/usb/omap_usb.h                      |   33 ++
 5 files changed, 473 insertions(+)
 create mode 100644 drivers/usb/phy/omap-usb3.c
Documentation/devicetree/bindings/usb/usb-phy.txt +18 -0
index 80d4148..7c5fd89 100644
@@ -15,3 +15,21 @@ usb2phy at 4a0ad080 {
 	reg = <0x4a0ad080 0x58>,
 	      <0x4a002300 0x4>;
 };
+
+OMAP USB3 PHY
+
+Required properties:
+ - compatible: Should be "ti,omap-usb3"
+ - reg : Address and length of the register set for the device. Also
+add the address of control module phy power register until a driver for
+control module is added
+
+This is usually a subnode of ocp2scp to which it is connected.
+
+usb3phy at 4a084400 {
+	compatible = "ti,omap-usb3";
+	reg = <0x0x4a084400 0x80>,
+	      <0x4a084800 0x64>,
+	      <0x4a084c00 0x40>,
+	      <0x4a002370 0x4>;
+};
drivers/usb/phy/Kconfig +9 -0
index 63c339b..353dc0c 100644
@@ -13,6 +13,15 @@ config OMAP_USB2
 	  The USB OTG controller communicates with the comparator using this
 	  driver.
 
+config OMAP_USB3
+	tristate "OMAP USB3 PHY Driver"
+	select USB_OTG_UTILS
+	help
+	  Enable this to support the USB3 PHY that is part of SOC. This
+	  driver takes care of all the PHY functionality apart from comparator.
+	  The USB OTG controller communicates with the comparator using this
+	  driver.
+
 config USB_ISP1301
 	tristate "NXP ISP1301 USB transceiver support"
 	depends on USB || USB_GADGET
drivers/usb/phy/Makefile +1 -0
index b069f29..973b1e6 100644
@@ -5,6 +5,7 @@
 ccflags-$(CONFIG_USB_DEBUG) := -DDEBUG
 
 obj-$(CONFIG_OMAP_USB2)			+= omap-usb2.o
+obj-$(CONFIG_OMAP_USB3)			+= omap-usb3.o
 obj-$(CONFIG_USB_ISP1301)		+= isp1301.o
 obj-$(CONFIG_MV_U3D_PHY)		+= mv_u3d_phy.o
 obj-$(CONFIG_USB_EHCI_TEGRA)	+= tegra_usb_phy.o
drivers/usb/phy/omap-usb3.c new file +412 -0

412 lines not on this page · raw message

include/linux/usb/omap_usb.h +33 -0
index 0ea17f8..6947528 100644
@@ -19,19 +19,41 @@
 #ifndef __DRIVERS_OMAP_USB2_H
 #define __DRIVERS_OMAP_USB2_H
 
+#include <linux/io.h>
 #include <linux/usb/otg.h>
 
+struct usb_dpll_params {
+	u16	m;
+	u8	n;
+	u8	freq:3;
+	u8	sd;
+	u32	mf;
+};
+
 struct omap_usb {
 	struct usb_phy		phy;
 	struct phy_companion	*comparator;
+	void __iomem		*pll_ctrl_base;
 	struct device		*dev;
 	u32 __iomem		*control_dev;
 	struct clk		*wkupclk;
+	struct clk		*optclk;
 	u8			is_suspended:1;
 };
 
 #define	PHY_PD	0x1
 
+#define	CONTROL_PHY_POWER_USB		0x00000370
+
+#define	USB_PWRCTL_CLK_CMD_MASK		0x003FC000
+#define	USB_PWRCTL_CLK_CMD_SHIFT	0xE
+
+#define	USB_PWRCTL_CLK_FREQ_MASK	0xFFC00000
+#define	USB_PWRCTL_CLK_FREQ_SHIFT	0x16
+
+#define	USB3_PHY_TX_RX_POWERON		0x3
+#define	USB3_PHY_TX_RX_POWEROFF		0x0
+
 #define	phy_to_omapusb(x)	container_of((x), struct omap_usb, phy)
 
 #if defined(CONFIG_OMAP_USB2) || defined(CONFIG_OMAP_USB2_MODULE)
@@ -43,4 +65,15 @@ static inline int omap_usb2_set_comparator(struct phy_companion *comparator)
 }
 #endif
 
+static inline u32 omap_usb_readl(const void __iomem *addr, unsigned offset)
+{
+	return __raw_readl(addr + offset);
+}
+
+static inline void omap_usb_writel(const void __iomem *addr, unsigned offset,
+								u32 data)
+{
+	__raw_writel(data, addr + offset);
+}
+
 #endif /* __DRIVERS_OMAP_USB_H */
Signature · 1 line
1.7.9.5
#2 lore raw

Re: [PATCH v2 1/2] usb: phy: add a new driver for usb3 phy

Quoted 5 lines · Kishon Vijay Abraham I
drivers/usb/phy/omap-usb3.c new file +5 -0
+static int omap5_usb_phy_power(struct omap_usb *phy, bool on)
+{
+	u32 val;
+	unsigned long rate;
+	struct clk *sys_clk;

drivers/usb/phy/omap-usb3.c line 99

Quoted 10 lines
drivers/usb/phy/omap-usb3.c new file +10 -0
+
+	sys_clk = clk_get(NULL, "sys_clkin");
+	if (IS_ERR(sys_clk)) {
+		pr_err("%s: unable to get sys_clkin\n", __func__);
+		return -EINVAL;
+	}
+
+	rate = clk_get_rate(sys_clk);
+	rate = rate/1000000;
+	clk_put(sys_clk);

Actually, you're supposed to hold on to the struct clk all the time your driver is making use of that - you're not supposed to drop it.

That has several advantages: if clk_get() fails, then you're failing earlier on (when the driver is being probed) and when some event occurs.

#3 lore raw

Re: [PATCH v2 1/2] usb: phy: add a new driver for usb3 phy

Hi,

Quoted 20 lines · Russell King - ARM Linux
Quoted 5 lines · Kishon Vijay Abraham I
drivers/usb/phy/omap-usb3.c new file +5 -0
+static int omap5_usb_phy_power(struct omap_usb *phy, bool on)
+{
+     u32 val;
+     unsigned long rate;
+     struct clk *sys_clk;

drivers/usb/phy/omap-usb3.c line 99

Quoted 10 lines
drivers/usb/phy/omap-usb3.c new file +10 -0
+
+     sys_clk = clk_get(NULL, "sys_clkin");
+     if (IS_ERR(sys_clk)) {
+             pr_err("%s: unable to get sys_clkin\n", __func__);
+             return -EINVAL;
+     }
+
+     rate = clk_get_rate(sys_clk);
+     rate = rate/1000000;
+     clk_put(sys_clk);

Actually, you're supposed to hold on to the struct clk all the time your driver is making use of that - you're not supposed to drop it.

Quoted 2 lines

That has several advantages: if clk_get() fails, then you're failing earlier on (when the driver is being probed) and when some event occurs.

Ok. Will post a patch fixing it.

Thanks
Kishon

#4 lore raw

PATCH v2 2/2 usb: phy: omap-usb2: enable 960Mhz clock for omap5

In reply to Kishon Vijay Abraham I

"usb_otg_ss_refclk960m" is needed for usb2 phy present in omap5. For omap4, the clk_get of this clock will fail since it does not have this clock.

---
 drivers/usb/phy/omap-usb2.c |   18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/usb/phy/omap-usb2.c +16 -2
index d36c282..5512207 100644
@@ -190,6 +190,12 @@ static int __devinit omap_usb2_probe(struct platform_device *pdev)
 	}
 	clk_prepare(phy->wkupclk);
 
+	phy->optclk = devm_clk_get(phy->dev, "usb_otg_ss_refclk960m");
+	if (IS_ERR(phy->optclk))
+		dev_vdbg(&pdev->dev, "unable to get refclk960m\n");
+	else
+		clk_prepare(phy->optclk);
+
 	usb_add_phy(&phy->phy, USB_PHY_TYPE_USB2);
 
 	platform_set_drvdata(pdev, phy);
@@ -204,6 +210,7 @@ static int __devexit omap_usb2_remove(struct platform_device *pdev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	clk_unprepare(phy->wkupclk);
+	clk_unprepare(phy->optclk);
 	usb_remove_phy(&phy->phy);
 
 	return 0;
@@ -217,6 +224,7 @@ static int omap_usb2_runtime_suspend(struct device *dev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	clk_disable(phy->wkupclk);
+	clk_disable(phy->optclk);
 
 	return 0;
 }
@@ -228,10 +236,16 @@ static int omap_usb2_runtime_resume(struct device *dev)
 	struct omap_usb	*phy = platform_get_drvdata(pdev);
 
 	ret = clk_enable(phy->wkupclk);
-	if (ret < 0)
+	if (ret < 0) {
 		dev_err(phy->dev, "Failed to enable wkupclk %d\n", ret);
+		return ret;
+	}
 
-	return ret;
+	ret = clk_enable(phy->optclk);
+	if (ret < 0)
+		dev_vdbg(phy->dev, "Failed to enable optclk %d\n", ret);
+
+	return 0;
 }
 
 static const struct dev_pm_ops omap_usb2_pm_ops = {
Signature · 1 line
1.7.9.5