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

2012-09-28 Thread ABRAHAM, KISHON VIJAY
Hi,

On Thu, Sep 27, 2012 at 7:48 PM, Russell King - ARM Linux
 wrote:
> On Thu, Sep 27, 2012 at 07:34:07PM +0530, Kishon Vijay Abraham I wrote:
>> +static int omap5_usb_phy_power(struct omap_usb *phy, bool on)
>> +{
>> + u32 val;
>> + unsigned long rate;
>> + struct clk *sys_clk;
>> +
>> + 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/100;
>> + 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.

Ok. Will post a patch fixing it.

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2012-09-27 Thread Russell King - ARM Linux
On Thu, Sep 27, 2012 at 07:34:07PM +0530, Kishon Vijay Abraham I wrote:
> +static int omap5_usb_phy_power(struct omap_usb *phy, bool on)
> +{
> + u32 val;
> + unsigned long rate;
> + struct clk *sys_clk;
> +
> + 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/100;
> + 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.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


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

2012-09-27 Thread Kishon Vijay Abraham I
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.

Signed-off-by: Kishon Vijay Abraham I 
Signed-off-by: Felipe Balbi 
Signed-off-by: Moiz Sonasath 
---
 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

diff --git a/Documentation/devicetree/bindings/usb/usb-phy.txt 
b/Documentation/devicetree/bindings/usb/usb-phy.txt
index 80d4148..7c5fd89 100644
--- a/Documentation/devicetree/bindings/usb/usb-phy.txt
+++ b/Documentation/devicetree/bindings/usb/usb-phy.txt
@@ -15,3 +15,21 @@ usb2phy@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@4a084400 {
+   compatible = "ti,omap-usb3";
+   reg = <0x0x4a084400 0x80>,
+ <0x4a084800 0x64>,
+ <0x4a084c00 0x40>,
+ <0x4a002370 0x4>;
+};
diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index 63c339b..353dc0c 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -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
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index b069f29..973b1e6 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -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
diff --git a/drivers/usb/phy/omap-usb3.c b/drivers/usb/phy/omap-usb3.c
new file mode 100644
index 000..cecfbd4
--- /dev/null
+++ b/drivers/usb/phy/omap-usb3.c
@@ -0,0 +1,412 @@
+/*
+ * omap-usb3 - USB PHY, talking to dwc3 controller in OMAP.
+ *
+ * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Author: Kishon Vijay Abraham I 
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#defineNUM_SYS_CLKS5
+#definePLL_STATUS  0x0004
+#definePLL_GO  0x0008
+#definePLL_CONFIGURATION1  0x000C
+#definePLL_CONFIGURATION2  0x0010
+#definePLL_CONFIGURATION3  0x0014
+#definePLL_CONFIGURATION4  0x0020
+
+#definePLL_REGM_MASK   0x001FFE00
+#definePLL_REGM_SHIFT  0x9
+#definePLL_REGM_F_MASK 0x0003
+#definePLL_REGM_F_SHIFT0x0
+#definePLL_REGN_MASK   0x01FE
+#definePLL_REGN_SHIFT  0x1
+#definePLL_SELFREQDCO_MASK 0x000E
+#definePLL_SELFREQDCO_SHIFT0x1
+#definePLL_SD_MASK 0x0003FC00
+#definePLL_SD_SHIFT0x9
+#defineSET_PLL_GO  0x1
+#definePLL_TICOPWDN0x1
+#definePLL_LOCK0x2
+#definePLL_IDLE0x1
+