Re: [RFC] usb: phy: generic: get rid of VBUS handling

2016-07-28 Thread Zhangfei Gao
Hi, Balbi & Robert

Have one question about commit 7acc9973e3c4 ("usb: phy: generic: add
vbus support").
Sorry asking here.

Commit 7acc9973e3c4 ("usb: phy: generic: add vbus support") is adding
 GPIO-based VBUS handling for phy-generic.c

And now we are uploading usb phy to drivers/phy/, as Balbi mentioned
drivers/usb/phy/ will not accept new phy driver.

Any suggestion about handling vbus (gpio) for the phy under drivers/phy/

Thanks



On Fri, Jul 1, 2016 at 6:00 PM, Felipe Balbi
 wrote:
>
> Hi Robert,
>
> your commit 7acc9973e3c4 ("usb: phy: generic: add vbus support") added
> GPIO-based VBUS handling for phy-generic.c, but that ends up calling
> usb_gadget_vbus_connect() which forces NOP to depend on the gadget API.
>
> I was grepping around and couldn't find any users for that VBUS gpio
> _and_ we have phy-gpio-vbus.c which does the same thing.
>
> I'm wondering if we should drop the usb_gadget_vbus_connect() support so
> other phy-generic users (like ehci-omap) can rely on it without
> depending on the gadget API.
>
> Thoughts?
>
> --
> balbi
--
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] phy: add phy-hi6220-usb

2015-11-22 Thread Zhangfei Gao
Support hi6220 use phy for HiKey board

Acked-by: Rob Herring <r...@kernel.org>
Signed-off-by: Zhangfei Gao <zhangfei@linaro.org>
---
Rebase to  Linux 4.4-rc1
 
 .../devicetree/bindings/phy/phy-hi6220-usb.txt |  16 ++
 drivers/phy/Kconfig|   9 ++
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-hi6220-usb.c   | 168 +
 4 files changed, 194 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
 create mode 100644 drivers/phy/phy-hi6220-usb.c

diff --git a/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt 
b/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
new file mode 100644
index ..f17a56e2152f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
@@ -0,0 +1,16 @@
+Hisilicon hi6220 usb PHY
+---
+
+Required properties:
+- compatible: should be "hisilicon,hi6220-usb-phy"
+- #phy-cells: must be 0
+- hisilicon,peripheral-syscon: phandle of syscon used to control phy.
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usb_phy: usbphy {
+   compatible = "hisilicon,hi6220-usb-phy";
+   #phy-cells = <0>;
+   phy-supply = <_5v_hub>;
+   hisilicon,peripheral-syscon = <_ctrl>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 7eb5859dd035..e1090507f2cd 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -215,6 +215,15 @@ config PHY_MT65XX_USB3
  for mt65xx SoCs. it supports two usb2.0 ports and
  one usb3.0 port.
 
+config PHY_HI6220_USB
+   tristate "hi6220 USB PHY support"
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config PHY_SUN4I_USB
tristate "Allwinner sunxi SoC USB PHY driver"
depends on ARCH_SUNXI && HAS_IOMEM && OF
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 075db1a81aa5..faccda1f237f 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_TI_PIPE3)+= 
phy-ti-pipe3.o
 obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
 obj-$(CONFIG_PHY_EXYNOS5250_SATA)  += phy-exynos5250-sata.o
 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
+obj-$(CONFIG_PHY_HI6220_USB)   += phy-hi6220-usb.o
 obj-$(CONFIG_PHY_MT65XX_USB3)  += phy-mt65xx-usb3.o
 obj-$(CONFIG_PHY_SUN4I_USB)+= phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SUN9I_USB)+= phy-sun9i-usb.o
diff --git a/drivers/phy/phy-hi6220-usb.c b/drivers/phy/phy-hi6220-usb.c
new file mode 100644
index ..b2141cbd4cf6
--- /dev/null
+++ b/drivers/phy/phy-hi6220-usb.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct regmap *reg;
+   struct device *dev;
+};
+
+static void hi6220_phy_init(struct hi6220_priv *priv)
+{
+   struct regmap *reg = priv->reg;
+   u32 val, mask;
+
+   val = RST0_USBOTG_BUS | RST0_POR_PICOPHY |
+ RST0_USBOTG | RST0_USBOTG_32K;
+   mask = val;
+   regmap_update_bits(reg, SC_PERIPH_RSTEN0, mask, val);
+   regmap_update_bits(reg, SC_PERIPH_RSTDIS0, mask, val

[PATCH] usb: dwc2: add support of hi6220

2015-11-17 Thread Zhangfei Gao
Support hisilicon,hi6220-usb for HiKey board

Signed-off-by: Zhangfei Gao <zhangfei@linaro.org>
---
 Documentation/devicetree/bindings/usb/dwc2.txt |  1 +
 drivers/usb/dwc2/platform.c| 32 ++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - "rockchip,rk3188-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3188 Soc;
   - "rockchip,rk3288-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3288 Soc;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 5859b0f..a5cb1bf 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -54,6 +54,37 @@
 
 static const char dwc2_driver_name[] = "dwc2";
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+   .external_id_pin_ctl= -1,
+   .hibernation= -1,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -282,6 +313,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = "brcm,bcm2835-usb", .data = _bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = _hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = _rk3066 },
{ .compatible = "snps,dwc2", .data = NULL },
{ .compatible = "samsung,s3c6400-hsotg", .data = NULL},
-- 
1.9.1

--
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] usb: dwc2: add support of hi6220

2015-11-17 Thread Zhangfei Gao
Support hisilicon,hi6220-usb for HiKey board

Signed-off-by: Zhangfei Gao <zhangfei@linaro.org>
---
 Documentation/devicetree/bindings/usb/dwc2.txt |  1 +
 drivers/usb/dwc2/platform.c| 32 ++
 2 files changed, 33 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - "rockchip,rk3188-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3188 Soc;
   - "rockchip,rk3288-usb", "rockchip,rk3066-usb", "snps,dwc2": for rk3288 Soc;
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 5859b0f..a5cb1bf 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -54,6 +54,37 @@
 
 static const char dwc2_driver_name[] = "dwc2";
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 <<
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+   .external_id_pin_ctl= -1,
+   .hibernation= -1,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -282,6 +313,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = "brcm,bcm2835-usb", .data = _bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = _hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = _rk3066 },
{ .compatible = "snps,dwc2", .data = NULL },
{ .compatible = "samsung,s3c6400-hsotg", .data = NULL},
-- 
1.9.1

--
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] phy: add phy-hi6220-usb

2015-11-17 Thread Zhangfei Gao
Support hi6220 use phy for HiKey board

Signed-off-by: Zhangfei Gao <zhangfei@linaro.org>
---
 .../devicetree/bindings/phy/phy-hi6220-usb.txt |  16 ++
 drivers/phy/Kconfig|   9 ++
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-hi6220-usb.c   | 168 +
 4 files changed, 194 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
 create mode 100644 drivers/phy/phy-hi6220-usb.c

diff --git a/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt 
b/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
new file mode 100644
index 000..f17a56e
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-hi6220-usb.txt
@@ -0,0 +1,16 @@
+Hisilicon hi6220 usb PHY
+---
+
+Required properties:
+- compatible: should be "hisilicon,hi6220-usb-phy"
+- #phy-cells: must be 0
+- hisilicon,peripheral-syscon: phandle of syscon used to control phy.
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usb_phy: usbphy {
+   compatible = "hisilicon,hi6220-usb-phy";
+   #phy-cells = <0>;
+   phy-supply = <_5v_hub>;
+   hisilicon,peripheral-syscon = <_ctrl>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 47da573..c91a612 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -206,6 +206,15 @@ config PHY_HIX5HD2_SATA
help
  Support for SATA PHY on Hisilicon hix5hd2 Soc.
 
+config PHY_HI6220_USB
+   tristate "hi6220 USB PHY support"
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config PHY_SUN4I_USB
tristate "Allwinner sunxi SoC USB PHY driver"
depends on ARCH_SUNXI && HAS_IOMEM && OF
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a5b18c1..0c5ccc9 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_TI_PIPE3)+= 
phy-ti-pipe3.o
 obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
 obj-$(CONFIG_PHY_EXYNOS5250_SATA)  += phy-exynos5250-sata.o
 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
+obj-$(CONFIG_PHY_HI6220_USB)   += phy-hi6220-usb.o
 obj-$(CONFIG_PHY_SUN4I_USB)+= phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SUN9I_USB)+= phy-sun9i-usb.o
 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o
diff --git a/drivers/phy/phy-hi6220-usb.c b/drivers/phy/phy-hi6220-usb.c
new file mode 100644
index 000..b2141cb
--- /dev/null
+++ b/drivers/phy/phy-hi6220-usb.c
@@ -0,0 +1,168 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct regmap *reg;
+   struct device *dev;
+};
+
+static void hi6220_phy_init(struct hi6220_priv *priv)
+{
+   struct regmap *reg = priv->reg;
+   u32 val, mask;
+
+   val = RST0_USBOTG_BUS | RST0_POR_PICOPHY |
+ RST0_USBOTG | RST0_USBOTG_32K;
+   mask = val;
+   regmap_update_bits(reg, SC_PERIPH_RSTEN0, mask, val);
+   regmap_update_bits(reg, SC_PERIPH_RSTDIS0, mask, val);
+}
+
+static int hi6220_phy_setup(struct hi6220_priv *priv, bool on)
+{
+   struct regmap *reg = priv->reg;
+   u32 val,

[PATCH v3] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-15 Thread Zhangfei Gao
Reuse ahbcfg if assigned from platform

Input from John:
AHB_SINGLE, NOTI_ALL_DMA_WRIT, REM_MEM_SUPP, HBSTLEN,
and INV_DESC_ENDIANNESS only apply in DMA mode and are
ignored in slave mode operation.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/gadget.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 15aa578..5726fbe 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2314,14 +2314,19 @@ void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg 
*hsotg,
GINTSTS_USBSUSP | GINTSTS_WKUPINT,
hsotg-regs + GINTMSK);
 
+   if (hsotg-core_params  hsotg-core_params-ahbcfg != -1)
+   val = hsotg-core_params-ahbcfg  ~GAHBCFG_CTRL_MASK;
+   else
+   val = 0;
+
if (using_dma(hsotg))
writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN |
-  (GAHBCFG_HBSTLEN_INCR4  GAHBCFG_HBSTLEN_SHIFT),
-  hsotg-regs + GAHBCFG);
+  (val ? val : GAHBCFG_HBSTLEN_INCR4 
+  GAHBCFG_HBSTLEN_SHIFT), hsotg-regs + GAHBCFG);
else
writel(((hsotg-dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL |
GAHBCFG_P_TXF_EMP_LVL) : 0) 
|
-  GAHBCFG_GLBL_INTR_EN,
+  GAHBCFG_GLBL_INTR_EN | val,
   hsotg-regs + GAHBCFG);
 
/*
-- 
1.9.1

--
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] usb: load usb phy earlier

2015-02-12 Thread Zhangfei Gao
USB PHY works proper is the base for the coming USB controller operation.
With this patch, it can avoid the controller drivers which are linked
earlier than USB PHY always being probed deferral.
Look at drivers/Makefile, it links phy first with the similar method.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
Acked-by: Peter Chen peter.c...@freescale.com
---
 drivers/usb/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 2f1e2aa..d8926c6 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -5,6 +5,7 @@
 # Object files in subdirectories
 
 obj-$(CONFIG_USB)  += core/
+obj-$(CONFIG_USB_SUPPORT)  += phy/
 
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_DWC2) += dwc2/
@@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_USB_SUPPORT)  += phy/
 obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
-- 
1.9.1

--
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 v4 4/4] phy: add phy-hi6220-usb

2015-02-11 Thread Zhangfei Gao
Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/phy/Kconfig  |   9 ++
 drivers/phy/Makefile |   1 +
 drivers/phy/phy-hi6220-usb.c | 306 +++
 3 files changed, 316 insertions(+)
 create mode 100644 drivers/phy/phy-hi6220-usb.c

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index ccad880..40a1ef1 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -162,6 +162,15 @@ config PHY_HIX5HD2_SATA
help
  Support for SATA PHY on Hisilicon hix5hd2 Soc.
 
+config PHY_HI6220_USB
+   tristate hi6220 USB PHY support
+   select USB_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config PHY_SUN4I_USB
tristate Allwinner sunxi SoC USB PHY driver
depends on ARCH_SUNXI  HAS_IOMEM  OF
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index aa74f96..ec43c2d 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_TI_PIPE3)+= 
phy-ti-pipe3.o
 obj-$(CONFIG_TWL4030_USB)  += phy-twl4030-usb.o
 obj-$(CONFIG_PHY_EXYNOS5250_SATA)  += phy-exynos5250-sata.o
 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
+obj-$(CONFIG_PHY_HI6220_USB)   += phy-hi6220-usb.o
 obj-$(CONFIG_PHY_SUN4I_USB)+= phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-exynos-usb2.o
 phy-exynos-usb2-y  += phy-samsung-usb2.o
diff --git a/drivers/phy/phy-hi6220-usb.c b/drivers/phy/phy-hi6220-usb.c
new file mode 100644
index 000..0d9f5ac
--- /dev/null
+++ b/drivers/phy/phy-hi6220-usb.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include linux/clk.h
+#include linux/mfd/syscon.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct usb_phy phy;
+   struct delayed_work work;
+   struct regmap *reg;
+   struct clk *clk;
+   struct regulator *vcc;
+   struct device *dev;
+   int gpio_vbus;
+   int gpio_id;
+   enum usb_otg_state state;
+};
+
+static void hi6220_start_peripheral(struct hi6220_priv *priv, bool on)
+{
+   struct usb_otg *otg = priv-phy.otg;
+
+   if (!otg-gadget)
+   return;
+
+   if (on)
+   usb_gadget_connect(otg-gadget);
+   else
+   usb_gadget_disconnect(otg-gadget);
+}
+
+static void hi6220_detect_work(struct work_struct *work)
+{
+   struct hi6220_priv *priv =
+   container_of(work, struct hi6220_priv, work.work);
+   int gpio_id, gpio_vbus;
+   enum usb_otg_state state;
+
+   if (!gpio_is_valid(priv-gpio_id) || !gpio_is_valid(priv-gpio_vbus))
+   return;
+
+   gpio_id = gpio_get_value_cansleep(priv-gpio_id);
+   gpio_vbus = gpio_get_value_cansleep(priv-gpio_vbus);
+
+   if (gpio_vbus == 0) {
+   if (gpio_id == 1)
+   state = OTG_STATE_B_PERIPHERAL;
+   else
+   state = OTG_STATE_A_HOST;
+   } else {
+   state = OTG_STATE_A_HOST;
+   }
+
+   if (priv-state != state) {
+   hi6220_start_peripheral(priv, state == OTG_STATE_B_PERIPHERAL);
+   priv-state = state;
+   }
+}
+
+static

[PATCH v4 0/4] add usb support for hi6220

2015-02-11 Thread Zhangfei Gao
v4:
Move drivers/usb/phy/phy-hi6220-usb.c to drivers/phy/phy-hi6220-usb.c, required 
by Balbi.
Modify dt bindings per comments from Mark and Sergei

v3:
fix typo and add -EPROBE_DEFER of regulator, pointed by Peter

v2:
address comments from Sergei and Peter
add hi6220_phy_setup(false) code

v1:
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host

Zhangfei Gao (4):
  Documentation: dt-bindings: add dt binding info for hi6220 dwc2
  Documentation: dt-bindings: add dt binding info for hi6220
  usb: dwc2: platform: add hi6220 support
  phy: add phy-hi6220-usb

 Documentation/devicetree/bindings/usb/dwc2.txt |   1 +
 .../devicetree/bindings/usb/hi6220-usb.txt |  49 
 drivers/phy/Kconfig|   9 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-hi6220-usb.c   | 306 +
 drivers/usb/dwc2/platform.c|  30 ++
 6 files changed, 396 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
 create mode 100644 drivers/phy/phy-hi6220-usb.c

-- 
1.9.1

--
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 v4 3/4] usb: dwc2: platform: add hi6220 support

2015-02-11 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/platform.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index ae095f0..f7c67db 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -50,6 +50,35 @@
 
 static const char dwc2_driver_name[] = dwc2;
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -129,6 +158,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = brcm,bcm2835-usb, .data = params_bcm2835 },
+   { .compatible = hisilicon,hi6220-usb, .data = params_hi6220 },
{ .compatible = rockchip,rk3066-usb, .data = params_rk3066 },
{ .compatible = snps,dwc2, .data = NULL },
{ .compatible = samsung,s3c6400-hsotg, .data = NULL},
-- 
1.9.1

--
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 v4 1/4] Documentation: dt-bindings: add dt binding info for hi6220 dwc2

2015-02-11 Thread Zhangfei Gao
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - rockchip,rk3188-usb, rockchip,rk3066-usb, snps,dwc2: for rk3188 Soc;
   - rockchip,rk3288-usb, rockchip,rk3066-usb, snps,dwc2: for rk3288 Soc;
-- 
1.9.1

--
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 v4 2/4] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-11 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt 
b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
new file mode 100644
index 000..b3a7b5a
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
@@ -0,0 +1,49 @@
+Hisilicon hi6220 SoC USB controller
+-
+
+usb controller is inherited from dwc2, refer dwc2.txt
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb
+Refer to dwc2.txt for dwc2 usb properties
+
+
+PHY:
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+- vcc-supply: phandle to the regulator that provides power to the PHY.
+- clocks: phandle and clock specifier of the PHY clock.
+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
+- hisilicon,vbus-gpios: gpio of detecting vbus.
+- hisilicon,id-gpios: gpio of detecting id.
+
+Example:
+
+   sys_ctrl: syscon@f703 {
+   compatible = hisilicon,sysctrl, syscon;
+   reg = 0x0 0xf703 0x0 0x1000;
+   };
+
+   usb_phy: usb-phy {
+   compatible = hisilicon,hi6220-usb-phy;
+   vcc-supply = fixed_5v_hub;
+   hisilicon,vbus-gpios = gpio2 6 0;
+   hisilicon,id-gpios = gpio2 5 0;
+   hisilicon,peripheral-syscon = sys_ctrl;
+   clocks = clock_sys HI6220_USBOTG_HCLK;
+   };
+
+   usb: usb@f72c {
+   compatible = hisilicon,hi6220-usb;
+   reg = 0x0 0xf72c 0x0 0x4;
+   phys = usb_phy;
+   dr_mode = otg;
+   g-use-dma;
+   g-rx-fifo-size = 512;
+   g-np-tx-fifo-size = 128;
+   g-tx-fifo-size = 128;
+   interrupts = 0 77 0x4;
+   };
-- 
1.9.1

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


[resend PATCH v3 0/4] add usb support for hi6220

2015-02-10 Thread Zhangfei Gao
v3:
fix typo and add -EPROBE_DEFER of regulator, pointed by Peter

v2:
address comments from Sergei and Peter
add hi6220_phy_setup(false) code

v1:
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host

Zhangfei Gao (4):
  Documentation: dt-bindings: add dt binding info for hi6220 dwc2
  Documentation: dt-bindings: add dt binding info for hi6220
  usb: dwc2: platform: add hi6220 support
  usb: phy: add phy-hi6220-usb

 Documentation/devicetree/bindings/usb/dwc2.txt |   1 +
 .../devicetree/bindings/usb/hi6220-usb.txt |  49 
 drivers/usb/dwc2/platform.c|  30 ++
 drivers/usb/phy/Kconfig|   9 +
 drivers/usb/phy/Makefile   |   1 +
 drivers/usb/phy/phy-hi6220-usb.c   | 306 +
 6 files changed, 396 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

-- 
1.9.1

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


[resend PATCH v3 2/4] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-10 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt 
b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
new file mode 100644
index 000..b8278de
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
@@ -0,0 +1,49 @@
+Hisilicon hi6220 SoC USB controller
+-
+
+usb controller is inherited from dwc2, refer dwc2.txt
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb
+Refer to dwc2.txt for dwc2 usb properties
+
+
+PHY:
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+- vcc-supply: phandle to the regulator that provides power to the PHY.
+- clocks: phandle and clock specifier of the PHY clock.
+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
+- hisilicon,gpio-vbus: gpio of detecting vbus.
+- hisilicon,gpio-id: gpio of detecting id.
+
+Example:
+
+   peripheral_ctrl: syscon@f703 {
+   compatible = syscon;
+   reg = 0x0 0xf703 0x0 0x1000;
+   };
+
+   usb2_phy: usbphy {
+   compatible = hisilicon,hi6220-usb-phy;
+   vcc-supply = fixed_5v_hub;
+   hisilicon,gpio-vbus = gpio2 6 0;
+   hisilicon,gpio-id = gpio2 5 0;
+   hisilicon,peripheral-syscon = peripheral_ctrl;
+   clocks = clock_sys HI6220_USBOTG_HCLK;
+   };
+
+   usb: usb@f72c {
+   compatible = hisilicon,hi6220-usb;
+   reg = 0x0 0xf72c 0x0 0x4;
+   phys = usb2_phy;
+   dr_mode = otg;
+   g-use-dma;
+   g-rx-fifo-size = 512;
+   g-np-tx-fifo-size = 128;
+   g-tx-fifo-size = 128;
+   interrupts = 0 77 0x4;
+   };
-- 
1.9.1

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


[resend PATCH v3 3/4] usb: dwc2: platform: add hi6220 support

2015-02-10 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/platform.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index ae095f0..f7c67db 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -50,6 +50,35 @@
 
 static const char dwc2_driver_name[] = dwc2;
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -129,6 +158,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = brcm,bcm2835-usb, .data = params_bcm2835 },
+   { .compatible = hisilicon,hi6220-usb, .data = params_hi6220 },
{ .compatible = rockchip,rk3066-usb, .data = params_rk3066 },
{ .compatible = snps,dwc2, .data = NULL },
{ .compatible = samsung,s3c6400-hsotg, .data = NULL},
-- 
1.9.1

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


[resend PATCH v3 1/4] Documentation: dt-bindings: add dt binding info for hi6220 dwc2

2015-02-10 Thread Zhangfei Gao
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - rockchip,rk3188-usb, rockchip,rk3066-usb, snps,dwc2: for rk3188 Soc;
   - rockchip,rk3288-usb, rockchip,rk3066-usb, snps,dwc2: for rk3288 Soc;
-- 
1.9.1

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


[resend PATCH v3 4/4] usb: phy: add phy-hi6220-usb

2015-02-10 Thread Zhangfei Gao
Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/phy/Kconfig  |   9 ++
 drivers/usb/phy/Makefile |   1 +
 drivers/usb/phy/phy-hi6220-usb.c | 306 +++
 3 files changed, 316 insertions(+)
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index c6d0c8e..405a3d0 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -173,6 +173,15 @@ config USB_MXS_PHY
 
  MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
 
+config USB_HI6220_PHY
+   tristate hi6220 USB PHY support
+   select USB_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config USB_RCAR_PHY
tristate Renesas R-Car USB PHY support
depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 75f2bba..00172d3 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY)  += phy-samsung-usb.o
 obj-$(CONFIG_TWL6030_USB)  += phy-twl6030-usb.o
 obj-$(CONFIG_USB_EHCI_TEGRA)   += phy-tegra-usb.o
 obj-$(CONFIG_USB_GPIO_VBUS)+= phy-gpio-vbus-usb.o
+obj-$(CONFIG_USB_HI6220_PHY)   += phy-hi6220-usb.o
 obj-$(CONFIG_USB_ISP1301)  += phy-isp1301.o
 obj-$(CONFIG_USB_MSM_OTG)  += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
diff --git a/drivers/usb/phy/phy-hi6220-usb.c b/drivers/usb/phy/phy-hi6220-usb.c
new file mode 100644
index 000..efb4bbb
--- /dev/null
+++ b/drivers/usb/phy/phy-hi6220-usb.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include linux/clk.h
+#include linux/mfd/syscon.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct usb_phy phy;
+   struct delayed_work work;
+   struct regmap *reg;
+   struct clk *clk;
+   struct regulator *vcc;
+   struct device *dev;
+   int gpio_vbus;
+   int gpio_id;
+   enum usb_otg_state state;
+};
+
+static void hi6220_start_periphrals(struct hi6220_priv *priv, bool on)
+{
+   struct usb_otg *otg = priv-phy.otg;
+
+   if (!otg-gadget)
+   return;
+
+   if (on)
+   usb_gadget_connect(otg-gadget);
+   else
+   usb_gadget_disconnect(otg-gadget);
+}
+
+static void hi6220_detect_work(struct work_struct *work)
+{
+   struct hi6220_priv *priv =
+   container_of(work, struct hi6220_priv, work.work);
+   int gpio_id, gpio_vbus;
+   enum usb_otg_state state;
+
+   if (!gpio_is_valid(priv-gpio_id) || !gpio_is_valid(priv-gpio_vbus))
+   return;
+
+   gpio_id = gpio_get_value_cansleep(priv-gpio_id);
+   gpio_vbus = gpio_get_value_cansleep(priv-gpio_vbus);
+
+   if (gpio_vbus == 0) {
+   if (gpio_id == 1)
+   state = OTG_STATE_B_PERIPHERAL;
+   else
+   state = OTG_STATE_A_HOST;
+   } else {
+   state = OTG_STATE_A_HOST;
+   }
+
+   if (priv-state != state) {
+   hi6220_start_periphrals(priv, state == OTG_STATE_B_PERIPHERAL);
+   priv-state = state

[PATCH] usb: load usb phy earlier

2015-02-10 Thread Zhangfei Gao
Since phy is definitely used in usb controller, load the phy
earlier to make boot time shorter.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
Acked-by: Peter Chen peter.c...@freescale.com
---
 drivers/usb/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 2f1e2aa..d8926c6 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -5,6 +5,7 @@
 # Object files in subdirectories
 
 obj-$(CONFIG_USB)  += core/
+obj-$(CONFIG_USB_SUPPORT)  += phy/
 
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_DWC2) += dwc2/
@@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_USB_SUPPORT)  += phy/
 obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
-- 
1.9.1

--
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 4/4] usb: phy: add phy-hi6220-usb

2015-02-09 Thread Zhangfei Gao
On 9 February 2015 at 22:26, zhangfei zhangfei@linaro.org wrote:


 On 02/09/2015 10:11 AM, Peter Chen wrote:

 +static void hi6220_detect_work(struct work_struct *work)
 +{
 +   struct hi6220_priv *priv =
 +   container_of(work, struct hi6220_priv, work.work);
 +   int gpio_id, gpio_vubs;


 %s/gpio_vubs/gpio_vbus


 Yes, typo


 +static void hi6220_phy_setup(struct hi6220_priv *priv, bool on)
 +{
 +   struct regmap *reg = priv-reg;
 +   u32 val, mask;
 +   int ret;
 +
 +   if (priv-reg == NULL)
 +   return;
 +
 +   if (on) {
 +   val = RST0_USBOTG_BUS | RST0_POR_PICOPHY |
 + RST0_USBOTG | RST0_USBOTG_32K;
 +   mask = val;
 +   ret = regmap_update_bits(reg, SC_PERIPH_RSTDIS0, mask,
 val);
 +   if (ret)
 +   return;
 +
 +   ret = regmap_read(reg, SC_PERIPH_CTRL5, val);
 +   val = CTRL5_USBOTG_RES_SEL | CTRL5_PICOPHY_ACAENB;
 +   mask = val | CTRL5_PICOPHY_BC_MODE;
 +   ret = regmap_update_bits(reg, SC_PERIPH_CTRL5, mask,
 val);
 +   if (ret)
 +   return;
 +
 +   val =  CTRL4_PICO_VBUSVLDEXT | CTRL4_PICO_VBUSVLDEXTSEL |
 +  CTRL4_OTG_PHY_SEL;
 +   mask = val | CTRL4_PICO_SIDDQ | CTRL4_PICO_OGDISABLE;
 +   ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask,
 val);
 +   if (ret)
 +   return;
 +
 +   ret = regmap_write(reg, SC_PERIPH_CTRL8,
 EYE_PATTERN_PARA);
 +   if (ret)
 +   return;
 +   } else {
 +   val = CTRL4_PICO_SIDDQ;
 +   mask = val;
 +   ret = regmap_update_bits(reg, SC_PERIPH_CTRL4, mask,
 val);
 +   if (ret)
 +   return;
 +
 +   ret = regmap_read(reg, SC_PERIPH_CTRL4, val);
 +
 +   val = RST0_USBOTG_BUS | RST0_POR_PICOPHY |
 + RST0_USBOTG | RST0_USBOTG_32K;
 +   mask = val;
 +   ret = regmap_update_bits(reg, SC_PERIPH_RSTEN0, mask,
 val);
 +   if (ret)
 +   return;
 +   }


 You have return value check for regmap API, but no error message or
 return value for hi6220_phy_setup, it looks strange.


 There was dev_err(priv-dev, failed to setup phy\n);
 Then I found priv-dev is the only one place to use, so I remove this for
 simple.



 +}
 +
 +static int hi6220_phy_probe(struct platform_device *pdev)
 +{
 +   struct hi6220_priv *priv;
 +   struct usb_otg *otg;
 +   struct device_node *np = pdev-dev.of_node;
 +   int ret, irq;
 +
 +   priv = devm_kzalloc(pdev-dev, sizeof(*priv), GFP_KERNEL);
 +   if (!priv)
 +   return -ENOMEM;
 +
 +   otg = devm_kzalloc(pdev-dev, sizeof(*otg), GFP_KERNEL);
 +   if (!otg)
 +   return -ENOMEM;
 +
 +   priv-phy.dev = pdev-dev;
 +   priv-phy.otg = otg;
 +   priv-phy.label = hi6220;
 +   priv-phy.type = USB_PHY_TYPE_USB2;
 +   otg-set_peripheral = hi6220_set_peripheral;
 +   platform_set_drvdata(pdev, priv);
 +
 +   priv-gpio_vbus = of_get_named_gpio(np, hisilicon,gpio-vbus,
 0);
 +   if (priv-gpio_vbus == -EPROBE_DEFER)
 +   return -EPROBE_DEFER;
 +   if (!gpio_is_valid(priv-gpio_vbus)) {
 +   dev_err(pdev-dev, invalid gpio %d\n,
 priv-gpio_vbus);
 +   return -ENODEV;
 +   }
 +
 +   priv-gpio_id = of_get_named_gpio(np, hisilicon,gpio-id, 0);
 +   if (priv-gpio_id == -EPROBE_DEFER)
 +   return -EPROBE_DEFER;
 +   if (!gpio_is_valid(priv-gpio_id)) {
 +   dev_err(pdev-dev, invalid gpio %d\n, priv-gpio_id);
 +   return -ENODEV;
 +   }
 +
 +   priv-reg = syscon_regmap_lookup_by_phandle(pdev-dev.of_node,
 +   hisilicon,peripheral-syscon);
 +   if (IS_ERR(priv-reg))
 +   priv-reg = NULL;
 +


 see my comments at your v1.

 As replied in v1, EPROBE_DEFER does not needed.
 syscon is register far earlier.


 +   INIT_DELAYED_WORK(priv-work, hi6220_detect_work);
 +
 +   ret = devm_gpio_request_one(pdev-dev, priv-gpio_vbus,
 +   GPIOF_IN, gpio_vbus);
 +   if (ret  0) {
 +   dev_err(pdev-dev, gpio request failed for
 gpio_vbus\n);
 +   return ret;
 +   }
 +
 +   ret = devm_gpio_request_one(pdev-dev, priv-gpio_id,
 +   GPIOF_IN, gpio_id);
 +   if (ret  0) {
 +   dev_err(pdev-dev, gpio request failed for gpio_id\n);
 +   return ret;
 +   }
 +
 +   priv-vcc = devm_regulator_get(pdev-dev, vcc);
 +   if (!IS_ERR(priv-vcc)) {


 EPROBE_DEFER?

 No, this is not needed, since regulator is registered earlier than device.

 drivers/Makefile
 # regulators early, since some subsystems 

[PATCH v3 2/5] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-09 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt 
b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
new file mode 100644
index 000..b8278de
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
@@ -0,0 +1,49 @@
+Hisilicon hi6220 SoC USB controller
+-
+
+usb controller is inherited from dwc2, refer dwc2.txt
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb
+Refer to dwc2.txt for dwc2 usb properties
+
+
+PHY:
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+- vcc-supply: phandle to the regulator that provides power to the PHY.
+- clocks: phandle and clock specifier of the PHY clock.
+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
+- hisilicon,gpio-vbus: gpio of detecting vbus.
+- hisilicon,gpio-id: gpio of detecting id.
+
+Example:
+
+   peripheral_ctrl: syscon@f703 {
+   compatible = syscon;
+   reg = 0x0 0xf703 0x0 0x1000;
+   };
+
+   usb2_phy: usbphy {
+   compatible = hisilicon,hi6220-usb-phy;
+   vcc-supply = fixed_5v_hub;
+   hisilicon,gpio-vbus = gpio2 6 0;
+   hisilicon,gpio-id = gpio2 5 0;
+   hisilicon,peripheral-syscon = peripheral_ctrl;
+   clocks = clock_sys HI6220_USBOTG_HCLK;
+   };
+
+   usb: usb@f72c {
+   compatible = hisilicon,hi6220-usb;
+   reg = 0x0 0xf72c 0x0 0x4;
+   phys = usb2_phy;
+   dr_mode = otg;
+   g-use-dma;
+   g-rx-fifo-size = 512;
+   g-np-tx-fifo-size = 128;
+   g-tx-fifo-size = 128;
+   interrupts = 0 77 0x4;
+   };
-- 
1.9.1

--
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 v3 5/5] usb: phy: add phy-hi6220-usb

2015-02-09 Thread Zhangfei Gao
Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/phy/Kconfig  |   9 ++
 drivers/usb/phy/Makefile |   1 +
 drivers/usb/phy/phy-hi6220-usb.c | 308 +++
 3 files changed, 318 insertions(+)
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index c6d0c8e..405a3d0 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -173,6 +173,15 @@ config USB_MXS_PHY
 
  MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
 
+config USB_HI6220_PHY
+   tristate hi6220 USB PHY support
+   select USB_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config USB_RCAR_PHY
tristate Renesas R-Car USB PHY support
depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 75f2bba..00172d3 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY)  += phy-samsung-usb.o
 obj-$(CONFIG_TWL6030_USB)  += phy-twl6030-usb.o
 obj-$(CONFIG_USB_EHCI_TEGRA)   += phy-tegra-usb.o
 obj-$(CONFIG_USB_GPIO_VBUS)+= phy-gpio-vbus-usb.o
+obj-$(CONFIG_USB_HI6220_PHY)   += phy-hi6220-usb.o
 obj-$(CONFIG_USB_ISP1301)  += phy-isp1301.o
 obj-$(CONFIG_USB_MSM_OTG)  += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
diff --git a/drivers/usb/phy/phy-hi6220-usb.c b/drivers/usb/phy/phy-hi6220-usb.c
new file mode 100644
index 000..b251e85
--- /dev/null
+++ b/drivers/usb/phy/phy-hi6220-usb.c
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include linux/clk.h
+#include linux/mfd/syscon.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct usb_phy phy;
+   struct delayed_work work;
+   struct regmap *reg;
+   struct clk *clk;
+   struct regulator *vcc;
+   struct device *dev;
+   int gpio_vbus;
+   int gpio_id;
+   enum usb_otg_state state;
+};
+
+static void hi6220_start_periphrals(struct hi6220_priv *priv, bool on)
+{
+   struct usb_otg *otg = priv-phy.otg;
+
+   if (!otg-gadget)
+   return;
+
+   if (on)
+   usb_gadget_connect(otg-gadget);
+   else
+   usb_gadget_disconnect(otg-gadget);
+}
+
+static void hi6220_detect_work(struct work_struct *work)
+{
+   struct hi6220_priv *priv =
+   container_of(work, struct hi6220_priv, work.work);
+   int gpio_id, gpio_vbus;
+   enum usb_otg_state state;
+
+   if (!gpio_is_valid(priv-gpio_id) || !gpio_is_valid(priv-gpio_vbus))
+   return;
+
+   gpio_id = gpio_get_value_cansleep(priv-gpio_id);
+   gpio_vbus = gpio_get_value_cansleep(priv-gpio_vbus);
+
+   if (gpio_vbus == 0) {
+   if (gpio_id == 1)
+   state = OTG_STATE_B_PERIPHERAL;
+   else
+   state = OTG_STATE_A_HOST;
+   } else {
+   state = OTG_STATE_A_HOST;
+   }
+
+   if (priv-state != state) {
+   hi6220_start_periphrals(priv, state == OTG_STATE_B_PERIPHERAL);
+   priv-state = state

[PATCH v3 4/5] usb: phy: load usb phy earlier

2015-02-09 Thread Zhangfei Gao
Since phy is definitely used in usb controller, load the phy
earlier to make boot time shorter.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
Acked-by: Peter Chen peter.c...@freescale.com
---
 drivers/usb/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 2f1e2aa..d8926c6 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -5,6 +5,7 @@
 # Object files in subdirectories
 
 obj-$(CONFIG_USB)  += core/
+obj-$(CONFIG_USB_SUPPORT)  += phy/
 
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_DWC2) += dwc2/
@@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_USB_SUPPORT)  += phy/
 obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
-- 
1.9.1

--
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 v3 3/5] usb: dwc2: platform: add hi6220 support

2015-02-09 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/platform.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index ae095f0..f7c67db 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -50,6 +50,35 @@
 
 static const char dwc2_driver_name[] = dwc2;
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -129,6 +158,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = brcm,bcm2835-usb, .data = params_bcm2835 },
+   { .compatible = hisilicon,hi6220-usb, .data = params_hi6220 },
{ .compatible = rockchip,rk3066-usb, .data = params_rk3066 },
{ .compatible = snps,dwc2, .data = NULL },
{ .compatible = samsung,s3c6400-hsotg, .data = NULL},
-- 
1.9.1

--
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 v3 1/5] Documentation: dt-bindings: add dt binding info for hi6220 dwc2

2015-02-09 Thread Zhangfei Gao
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - rockchip,rk3188-usb, rockchip,rk3066-usb, snps,dwc2: for rk3188 Soc;
   - rockchip,rk3288-usb, rockchip,rk3066-usb, snps,dwc2: for rk3288 Soc;
-- 
1.9.1

--
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 v3 0/5] add usb support for hi6220

2015-02-09 Thread Zhangfei Gao
v3:
fix typo and add -EPROBE_DEFER of regulator, pointed by Peter

v2:
address comments from Sergei and Peter
add hi6220_phy_setup(false) code

v1:
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host


Zhangfei Gao (5):
  Documentation: dt-bindings: add dt binding info for hi6220 dwc2
  Documentation: dt-bindings: add dt binding info for hi6220
  usb: dwc2: platform: add hi6220 support
  usb: phy: load usb phy earlier
  usb: phy: add phy-hi6220-usb

 Documentation/devicetree/bindings/usb/dwc2.txt |   1 +
 .../devicetree/bindings/usb/hi6220-usb.txt |  49 
 drivers/usb/Makefile   |   2 +-
 drivers/usb/dwc2/platform.c|  30 ++
 drivers/usb/phy/Kconfig|   9 +
 drivers/usb/phy/Makefile   |   1 +
 drivers/usb/phy/phy-hi6220-usb.c   | 308 +
 7 files changed, 399 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

-- 
1.9.1

--
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 4/4] usb: phy: add phy-hi6220

2015-02-08 Thread Zhangfei Gao
On 9 February 2015 at 09:57, Peter Chen peter.c...@freescale.com wrote:
  +static int hi6220_phy_probe(struct platform_device *pdev)
  +{
  + struct hi6220_priv *priv;
  + struct usb_otg *otg;
  + struct device_node *np = pdev-dev.of_node;
  + int ret, irq;
  +
  + priv = devm_kzalloc(pdev-dev, sizeof(*priv), GFP_KERNEL);
  + if (!priv)
  + return -ENOMEM;
  +
  + otg = devm_kzalloc(pdev-dev, sizeof(*otg), GFP_KERNEL);
  + if (!otg)
  + return -ENOMEM;
  +
  + priv-phy.dev = pdev-dev;
  + priv-phy.otg = otg;
  + priv-phy.label = hi6220;
  + platform_set_drvdata(pdev, priv);
  + otg-set_peripheral = mv_otg_set_peripheral;
  +
  + priv-gpio_vbus_det = of_get_named_gpio(np, 
  hisilicon,gpio_vbus_det, 0);
  + if (priv-gpio_vbus_det == -EPROBE_DEFER)
  + return -EPROBE_DEFER;
  + if (!gpio_is_valid(priv-gpio_vbus_det)) {
  + dev_err(pdev-dev, invalid gpio %d\n, 
  priv-gpio_vbus_det);
  + return -ENODEV;
  + }
  +
  + priv-gpio_id_det = of_get_named_gpio(np, hisilicon,gpio_id_det, 
  0);
  + if (priv-gpio_id_det == -EPROBE_DEFER)
  + return -EPROBE_DEFER;
  + if (!gpio_is_valid(priv-gpio_id_det)) {
  + dev_err(pdev-dev, invalid gpio %d\n, priv-gpio_id_det);
  + return -ENODEV;
  + }
  +
  + priv-reg = syscon_regmap_lookup_by_phandle(pdev-dev.of_node,
  + hisilicon,peripheral-syscon);
  + if (IS_ERR(priv-reg))
  + priv-reg = NULL;
 
  You may differentiate -ENODEV and other errors, for other errors, you
  can show an error, and return directly.

 Here I want to set this property as optional, in case other platform
 do not need this property.
 So phy_setup also add protection if (priv-reg == NULL) return;


 If syscon_regmap_lookup_by_phandle returns -EPROBE_DEFER, you may want
 to try later.

It should not.
syscon is postcore_initcall(syscon_init);

Thanks
--
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 4/4] usb: phy: add phy-hi6220-usb

2015-02-06 Thread Zhangfei Gao
Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/phy/Kconfig  |   9 ++
 drivers/usb/phy/Makefile |   1 +
 drivers/usb/phy/phy-hi6220-usb.c | 297 +++
 3 files changed, 307 insertions(+)
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index c6d0c8e..405a3d0 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -173,6 +173,15 @@ config USB_MXS_PHY
 
  MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
 
+config USB_HI6220_PHY
+   tristate hi6220 USB PHY support
+   select USB_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config USB_RCAR_PHY
tristate Renesas R-Car USB PHY support
depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 75f2bba..00172d3 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY)  += phy-samsung-usb.o
 obj-$(CONFIG_TWL6030_USB)  += phy-twl6030-usb.o
 obj-$(CONFIG_USB_EHCI_TEGRA)   += phy-tegra-usb.o
 obj-$(CONFIG_USB_GPIO_VBUS)+= phy-gpio-vbus-usb.o
+obj-$(CONFIG_USB_HI6220_PHY)   += phy-hi6220-usb.o
 obj-$(CONFIG_USB_ISP1301)  += phy-isp1301.o
 obj-$(CONFIG_USB_MSM_OTG)  += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
diff --git a/drivers/usb/phy/phy-hi6220-usb.c b/drivers/usb/phy/phy-hi6220-usb.c
new file mode 100644
index 000..8092bca
--- /dev/null
+++ b/drivers/usb/phy/phy-hi6220-usb.c
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include linux/clk.h
+#include linux/mfd/syscon.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
+
+#define SC_PERIPH_CTRL40x00c
+
+#define CTRL4_PICO_SIDDQ   BIT(6)
+#define CTRL4_PICO_OGDISABLE   BIT(8)
+#define CTRL4_PICO_VBUSVLDEXT  BIT(10)
+#define CTRL4_PICO_VBUSVLDEXTSEL   BIT(11)
+#define CTRL4_OTG_PHY_SEL  BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define CTRL5_USBOTG_RES_SEL   BIT(3)
+#define CTRL5_PICOPHY_ACAENB   BIT(4)
+#define CTRL5_PICOPHY_BC_MODE  BIT(5)
+#define CTRL5_PICOPHY_CHRGSEL  BIT(6)
+#define CTRL5_PICOPHY_VDATSRCEND   BIT(7)
+#define CTRL5_PICOPHY_VDATDETENB   BIT(8)
+#define CTRL5_PICOPHY_DCDENB   BIT(9)
+#define CTRL5_PICOPHY_IDDIGBIT(10)
+
+#define SC_PERIPH_CTRL80x018
+#define SC_PERIPH_RSTEN0   0x300
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define RST0_USBOTG_BUSBIT(4)
+#define RST0_POR_PICOPHY   BIT(5)
+#define RST0_USBOTGBIT(6)
+#define RST0_USBOTG_32KBIT(7)
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+struct hi6220_priv {
+   struct usb_phy phy;
+   struct delayed_work work;
+   struct regmap *reg;
+   struct clk *clk;
+   struct regulator *vcc;
+   int gpio_vbus;
+   int gpio_id;
+   enum usb_otg_state state;
+};
+
+static void hi6220_start_periphrals(struct hi6220_priv *priv, bool on)
+{
+   struct usb_otg *otg = priv-phy.otg;
+
+   if (!otg-gadget)
+   return;
+
+   if (on)
+   usb_gadget_connect(otg-gadget);
+   else
+   usb_gadget_disconnect(otg-gadget);
+}
+
+static void hi6220_detect_work(struct work_struct *work)
+{
+   struct hi6220_priv *priv =
+   container_of(work, struct hi6220_priv, work.work);
+   int gpio_id, gpio_vubs;
+   enum usb_otg_state state;
+
+   if (!gpio_is_valid(priv-gpio_id) || !gpio_is_valid(priv-gpio_vbus))
+   return;
+
+   gpio_id = gpio_get_value_cansleep(priv-gpio_id);
+   gpio_vubs = gpio_get_value_cansleep(priv-gpio_vbus);
+
+   if (gpio_vubs == 0) {
+   if (gpio_id == 1)
+   state = OTG_STATE_B_PERIPHERAL;
+   else
+   state = OTG_STATE_A_HOST;
+   } else {
+   state = OTG_STATE_A_HOST;
+   }
+
+   if (priv-state != state) {
+   hi6220_start_periphrals(priv, state == OTG_STATE_B_PERIPHERAL);
+   priv-state = state;
+   }
+}
+
+static

[PATCH v2 2/4] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-06 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 .../devicetree/bindings/usb/hi6220-usb.txt | 49 ++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt 
b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
new file mode 100644
index 000..b8278de
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
@@ -0,0 +1,49 @@
+Hisilicon hi6220 SoC USB controller
+-
+
+usb controller is inherited from dwc2, refer dwc2.txt
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb
+Refer to dwc2.txt for dwc2 usb properties
+
+
+PHY:
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+- vcc-supply: phandle to the regulator that provides power to the PHY.
+- clocks: phandle and clock specifier of the PHY clock.
+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
+- hisilicon,gpio-vbus: gpio of detecting vbus.
+- hisilicon,gpio-id: gpio of detecting id.
+
+Example:
+
+   peripheral_ctrl: syscon@f703 {
+   compatible = syscon;
+   reg = 0x0 0xf703 0x0 0x1000;
+   };
+
+   usb2_phy: usbphy {
+   compatible = hisilicon,hi6220-usb-phy;
+   vcc-supply = fixed_5v_hub;
+   hisilicon,gpio-vbus = gpio2 6 0;
+   hisilicon,gpio-id = gpio2 5 0;
+   hisilicon,peripheral-syscon = peripheral_ctrl;
+   clocks = clock_sys HI6220_USBOTG_HCLK;
+   };
+
+   usb: usb@f72c {
+   compatible = hisilicon,hi6220-usb;
+   reg = 0x0 0xf72c 0x0 0x4;
+   phys = usb2_phy;
+   dr_mode = otg;
+   g-use-dma;
+   g-rx-fifo-size = 512;
+   g-np-tx-fifo-size = 128;
+   g-tx-fifo-size = 128;
+   interrupts = 0 77 0x4;
+   };
-- 
1.9.1

--
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 0/4] add usb support for hi6220

2015-02-06 Thread Zhangfei Gao
v2:
address comments from Sergei and Peter
add hi6220_phy_setup(false) code

v1:
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host

Zhangfei Gao (4):
  Documentation: dt-bindings: add dt binding info for hi6220 dwc2
  Documentation: dt-bindings: add dt binding info for hi6220
  usb: dwc2: platform: add hi6220 support
  usb: phy: add phy-hi6220-usb

 Documentation/devicetree/bindings/usb/dwc2.txt |   1 +
 .../devicetree/bindings/usb/hi6220-usb.txt |  49 
 drivers/usb/dwc2/platform.c|  30 +++
 drivers/usb/phy/Kconfig|   9 +
 drivers/usb/phy/Makefile   |   1 +
 drivers/usb/phy/phy-hi6220-usb.c   | 297 +
 6 files changed, 387 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
 create mode 100644 drivers/usb/phy/phy-hi6220-usb.c

-- 
1.9.1

--
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/4] Documentation: dt-bindings: add dt binding info for hi6220 dwc2

2015-02-06 Thread Zhangfei Gao
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - rockchip,rk3188-usb, rockchip,rk3066-usb, snps,dwc2: for rk3188 Soc;
   - rockchip,rk3288-usb, rockchip,rk3066-usb, snps,dwc2: for rk3288 Soc;
-- 
1.9.1

--
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 3/4] usb: dwc2: platform: add hi6220 support

2015-02-06 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/platform.c | 30 ++
 1 file changed, 30 insertions(+)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index ae095f0..f7c67db 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -50,6 +50,35 @@
 
 static const char dwc2_driver_name[] = dwc2;
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = GAHBCFG_HBSTLEN_INCR16 
+ GAHBCFG_HBSTLEN_SHIFT,
+   .uframe_sched   = 0,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -129,6 +158,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = brcm,bcm2835-usb, .data = params_bcm2835 },
+   { .compatible = hisilicon,hi6220-usb, .data = params_hi6220 },
{ .compatible = rockchip,rk3066-usb, .data = params_rk3066 },
{ .compatible = snps,dwc2, .data = NULL },
{ .compatible = samsung,s3c6400-hsotg, .data = NULL},
-- 
1.9.1

--
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 4/4] usb: phy: add phy-hi6220

2015-02-06 Thread Zhangfei Gao
On 6 February 2015 at 16:41, Peter Chen peter.c...@freescale.com wrote:
 On Thu, Feb 05, 2015 at 10:47:00PM +0800, Zhangfei Gao wrote:

 @@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY)+= 
 phy-samsung-usb.o
  obj-$(CONFIG_TWL6030_USB)+= phy-twl6030-usb.o
  obj-$(CONFIG_USB_EHCI_TEGRA) += phy-tegra-usb.o
  obj-$(CONFIG_USB_GPIO_VBUS)  += phy-gpio-vbus-usb.o
 +obj-$(CONFIG_USB_HI6220_PHY) += phy-hi6220.o

 To align the naming method, phy-hi6220-usb is better.
Sure,


 +enum usb_mode {
 + USB_EMPTY,
 + GADGET_DEVICE,
 + OTG_HOST,
 +};

 This usb_mode is a little strange, what state you would like to
 use?

it is internal state machine, to distinguish otg gadget mode and host mode.
There are two gpio, we use gpio_vbus interrupt as well as gpio_id
status to distinguish gadget or host.

 +static irqreturn_t hiusb_gpio_intr(int irq, void *data)
 +{
 + struct hi6220_priv *priv = (struct hi6220_priv *)data;
 +
 + /* add debounce time */
 + schedule_delayed_work(priv-work, msecs_to_jiffies(100));
 + return IRQ_HANDLED;
 +}
 +
 +static int mv_otg_set_peripheral(struct usb_otg *otg,

 mv? You may want to use hi
Yes, my bad.


 +static void hi6220_phy_setup(struct hi6220_priv *priv)
 +{
 + u32 val, mask;
 + int ret;
 +
 + if (priv-reg == NULL)
 + return;
 +
 + val = PERIPH_RSTDIS0_USBOTG_BUS | PERIPH_RSTDIS0_POR_PICOPHY |
 +   PERIPH_RSTDIS0_USBOTG | PERIPH_RSTDIS0_USBOTG_32K;
 + mask = val;
 + ret = regmap_update_bits(priv-reg, SC_PERIPH_RSTDIS0, mask, val);
 + if (ret)
 + return;
 +
 + ret = regmap_read(priv-reg, SC_PERIPH_CTRL5, val);
 + val = PERIPH_CTRL5_USBOTG_RES_SEL | PERIPH_CTRL5_PICOPHY_ACAENB;
 + mask = val | PERIPH_CTRL5_PICOPHY_BC_MODE;
 + ret = regmap_update_bits(priv-reg, SC_PERIPH_CTRL5, mask, val);
 + if (ret)
 + return;
 +
 + val =  PERIPH_CTRL4_PICO_VBUSVLDEXT | PERIPH_CTRL4_PICO_VBUSVLDEXTSEL |
 +PERIPH_CTRL4_OTG_PHY_SEL;
 + mask = val | PERIPH_CTRL4_PICO_SIDDQ | PERIPH_CTRL4_PICO_OGDISABLE;
 + ret = regmap_update_bits(priv-reg, SC_PERIPH_CTRL4, mask, val);
 + if (ret)
 + return;
 +
 + ret = regmap_write(priv-reg, SC_PERIPH_CTRL8, EYE_PATTERN_PARA);
 + if (ret)
 + return;
 +}
 +
 +static int hi6220_phy_probe(struct platform_device *pdev)
 +{
 + struct hi6220_priv *priv;
 + struct usb_otg *otg;
 + struct device_node *np = pdev-dev.of_node;
 + int ret, irq;
 +
 + priv = devm_kzalloc(pdev-dev, sizeof(*priv), GFP_KERNEL);
 + if (!priv)
 + return -ENOMEM;
 +
 + otg = devm_kzalloc(pdev-dev, sizeof(*otg), GFP_KERNEL);
 + if (!otg)
 + return -ENOMEM;
 +
 + priv-phy.dev = pdev-dev;
 + priv-phy.otg = otg;
 + priv-phy.label = hi6220;
 + platform_set_drvdata(pdev, priv);
 + otg-set_peripheral = mv_otg_set_peripheral;
 +
 + priv-gpio_vbus_det = of_get_named_gpio(np, hisilicon,gpio_vbus_det, 
 0);
 + if (priv-gpio_vbus_det == -EPROBE_DEFER)
 + return -EPROBE_DEFER;
 + if (!gpio_is_valid(priv-gpio_vbus_det)) {
 + dev_err(pdev-dev, invalid gpio %d\n, priv-gpio_vbus_det);
 + return -ENODEV;
 + }
 +
 + priv-gpio_id_det = of_get_named_gpio(np, hisilicon,gpio_id_det, 0);
 + if (priv-gpio_id_det == -EPROBE_DEFER)
 + return -EPROBE_DEFER;
 + if (!gpio_is_valid(priv-gpio_id_det)) {
 + dev_err(pdev-dev, invalid gpio %d\n, priv-gpio_id_det);
 + return -ENODEV;
 + }
 +
 + priv-reg = syscon_regmap_lookup_by_phandle(pdev-dev.of_node,
 + hisilicon,peripheral-syscon);
 + if (IS_ERR(priv-reg))
 + priv-reg = NULL;

 You may differentiate -ENODEV and other errors, for other errors, you
 can show an error, and return directly.

Here I want to set this property as optional, in case other platform
do not need this property.
So phy_setup also add protection if (priv-reg == NULL) return;


 +
 + INIT_DELAYED_WORK(priv-work, hi6220_detect_work);
 +
 + ret = devm_gpio_request_one(pdev-dev, priv-gpio_vbus_det,
 + GPIOF_IN, gpio_vbus_det);
 + if (ret  0) {
 + dev_err(pdev-dev, gpio request failed for gpio_vbus_det\n);
 + return ret;
 + }
 +
 + ret = devm_gpio_request_one(pdev-dev, priv-gpio_id_det,
 + GPIOF_IN, gpio_id_det);
 + if (ret  0) {
 + dev_err(pdev-dev, gpio request failed for gpio_id_det\n);
 + return ret;
 + }
 +
 + priv-vcc = devm_regulator_get(pdev-dev, vcc);
 + if (!IS_ERR(priv-vcc)) {
 + ret = regulator_enable(priv-vcc);
 + if (ret) {
 + dev_err(pdev-dev, Failed to enable regulator\n);
 + return -ENODEV;
 + }
 + }
 +
 + priv-clk

Re: [PATCH 2/2] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-06 Thread Zhangfei Gao
On 6 February 2015 at 16:07, Kaukab, Yousaf yousaf.kau...@intel.com wrote:
  GAHBCFG_HBSTLEN_INCR4  diff --git a/drivers/usb/dwc2/gadget.c
  b/drivers/usb/dwc2/gadget.c index 15aa578..20085de 100644
  --- a/drivers/usb/dwc2/gadget.c
  +++ b/drivers/usb/dwc2/gadget.c
  @@ -2314,9 +2314,13 @@ void s3c_hsotg_core_init_disconnected(struct
  dwc2_hsotg *hsotg,
GINTSTS_USBSUSP | GINTSTS_WKUPINT,
hsotg-regs + GINTMSK);
 
  + if ((hsotg-core_params)  (hsotg-core_params-ahbcfg != -
  1))
  + val = hsotg-core_params-ahbcfg 
  ~GAHBCFG_CTRL_MASK;
  + else
  + val = GAHBCFG_HBSTLEN_INCR4 
  GAHBCFG_HBSTLEN_SHIFT;
  +
if (using_dma(hsotg))
  - writel(GAHBCFG_GLBL_INTR_EN |
  GAHBCFG_DMA_EN |
  -(GAHBCFG_HBSTLEN_INCR4 
  GAHBCFG_HBSTLEN_SHIFT),
  + writel(GAHBCFG_GLBL_INTR_EN |
  GAHBCFG_DMA_EN | val,
   hsotg-regs + GAHBCFG);
else
writel(((hsotg-dedicated_fifos) ?
  (GAHBCFG_NP_TXF_EMP_LVL |
 
  There are other bits in GAHBCFG that can be set from platform. They will be
 preserved by your patch, as they are not part of GAHBCFG_CTRL_MASK, but
 only in case dma is enabled. Perhaps preserve them in non-dma case as well.

 Here may have issue if also set hsotg-core_params-ahbcfg for non-dma case,
 since GAHBCFG[4:1] may be set.

 You can mask off HBstLen in that case. However, I don't think setting burst 
 length will be an issue in non DMA case as DWC2 will not act as a bus master. 
 John, can you please confirm if setting burst length will be an issue in 
 non-dma case?

It would be great if John has some input.
I am not sure, just doubt ahbcfg is specifically used for dma mode.

static int dwc2_gahbcfg_init(struct dwc2_hsotg *hsotg)
{
case GHWCFG2_INT_DMA_ARCH:
dev_dbg(hsotg-dev, Internal DMA Mode\n);
if (hsotg-core_params-ahbcfg != -1) {
ahbcfg = GAHBCFG_CTRL_MASK;
ahbcfg |= hsotg-core_params-ahbcfg 
  ~GAHBCFG_CTRL_MASK;
}
break;
}

Looks like only GHWCFG2_INT_DMA_ARCH case cares the value of ahbcfg.



 Though from drivers/usb/dwc2/core.h we can not see @ahbcfg is specifically
 used for dma case, most case in drivers/usb/dwc2/platform.c use ahbcfg is set
 hbstlen, GAHBCFG[4:1].
 For example, our platform set GAHBCFG_HBSTLEN_INCR16.

 So I just assume @ahbcfg is used for dma case.
 What do you think.

 While you are fixing it, why not fix it for other bits, for example 
 AHBSingle, InvDescEndianness etc.,  which are part of the same register and 
 will be overwritten at the same place.

Yes, understand.
Not sure other value need to be overwirtten, if only GAHBCFG[4:1],
burst len, maybe we can add another property?

Will update accordingly after John give some info.

Thanks Yousaf
--
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 2/4] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-05 Thread Zhangfei Gao
On 6 February 2015 at 02:24, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt
 b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
 new file mode 100644
 index 000..e926364
 --- /dev/null
 +++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
 @@ -0,0 +1,50 @@
 +Hisilicon hi6220  SoC USB controlle


Controller.
Yes, my mistake.
To prevent spelling error next time, will paste to google doc first
for the auto spelling check.


 +-
 +
 +usb controller is inherited from dwc2, refer dwc2.txt
 +-
 +
 +Required properties:
 +- compatible: hisilicon,hi6220-usb-phy


PHY? I thought you were describing the USB controller.
my bad
should be compatible: hisilicon,hi6220-usb


 +Refer to dwc2.txt for dwc2 usb properties
 +
 +
 +phy:
change to PHY:
 +-
 +
 +Required properties:
 +- compatible: hisilicon,hi6220-usb-phy
 +- vcc-supply: phandle to the regulator that provides power to the PHY.
 +- clocks: phandle to the PHY clock. Use as per Documentation/devicetree


Actually, it's phandle and clock specifier.
Change to
 - clocks: phandle and clock specifier of the PHY clock.


 +  /bindings/clock/clock-bindings.txt
 +- hisilicon,peripheral-syscon: phandle of syscon used to control
 peripheral.
 +- hisilicon,gpio_vbus_det: gpio of detecting vbus.
 +- hisilicon,gpio_id_det: gpio of detecting id.


Hyphens are preferred over underscores in the prop names.
Change to
- hisilicon,gpio-vbus-det: gpio of detecting vbus.
- hisilicon,gpio-id-det: gpio of detecting id.

Thanks Sergei
--
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: load usb phy earlier

2015-02-05 Thread Zhangfei Gao
Since phy is definitely used in usb controller, load the phy
earlier to make boot time shorter.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 2f1e2aa..d8926c6 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -5,6 +5,7 @@
 # Object files in subdirectories
 
 obj-$(CONFIG_USB)  += core/
+obj-$(CONFIG_USB_SUPPORT)  += phy/
 
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_DWC2) += dwc2/
@@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_USB_SUPPORT)  += phy/
 obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
-- 
1.9.1

--
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 2/2] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-05 Thread Zhangfei Gao
Gadget directly set GAHBCFG_HBSTLEN_INCR4, reuse ahbcfg if assigned from 
platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/core.c   | 2 +-
 drivers/usb/dwc2/gadget.c | 8 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index d5197d4..8d388cc 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -2563,7 +2563,7 @@ void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, 
int val)
 
 void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)
 {
-   if (val != -1)
+   if (val)
hsotg-core_params-ahbcfg = val;
else
hsotg-core_params-ahbcfg = GAHBCFG_HBSTLEN_INCR4 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 15aa578..82b520a 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2314,9 +2314,13 @@ void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg 
*hsotg,
GINTSTS_USBSUSP | GINTSTS_WKUPINT,
hsotg-regs + GINTMSK);
 
+   if (hsotg-core_params  hsotg-core_params-ahbcfg != -1)
+   val = hsotg-core_params-ahbcfg  ~GAHBCFG_CTRL_MASK;
+   else
+   val = GAHBCFG_HBSTLEN_INCR4  GAHBCFG_HBSTLEN_SHIFT;
+
if (using_dma(hsotg))
-   writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN |
-  (GAHBCFG_HBSTLEN_INCR4  GAHBCFG_HBSTLEN_SHIFT),
+   writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | val,
   hsotg-regs + GAHBCFG);
else
writel(((hsotg-dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL |
-- 
1.9.1

--
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 0/2] misc change

2015-02-05 Thread Zhangfei Gao
v2: 
remove parentheses mentioned by Sergei
assume @ahbcfg is used for dma case

Zhangfei Gao (2):
  usb: phy: load usb phy earlier
  usb: dwc2: gadget reuse ahbcfg assigned from platform

 drivers/usb/Makefile  | 2 +-
 drivers/usb/dwc2/core.c   | 2 +-
 drivers/usb/dwc2/gadget.c | 8 ++--
 3 files changed, 8 insertions(+), 4 deletions(-)

-- 
1.9.1

--
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 3/4] usb: dwc2: platform: add hi6220 support

2015-02-05 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/platform.c | 29 +
 1 file changed, 29 insertions(+)

diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index ae095f0..ceee385 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -50,6 +50,34 @@
 
 static const char dwc2_driver_name[] = dwc2;
 
+static const struct dwc2_core_params params_hi6220 = {
+   .otg_cap= 2,/* No HNP/SRP capable */
+   .otg_ver= 0,/* 1.3 */
+   .dma_enable = 1,
+   .dma_desc_enable= 0,
+   .speed  = 0,/* High Speed */
+   .enable_dynamic_fifo= 1,
+   .en_multiple_tx_fifo= 1,
+   .host_rx_fifo_size  = 512,
+   .host_nperio_tx_fifo_size   = 512,
+   .host_perio_tx_fifo_size= 512,
+   .max_transfer_size  = 65535,
+   .max_packet_count   = 511,
+   .host_channels  = 16,
+   .phy_type   = 1,/* UTMI */
+   .phy_utmi_width = 8,
+   .phy_ulpi_ddr   = 0,/* Single */
+   .phy_ulpi_ext_vbus  = 0,
+   .i2c_enable = 0,
+   .ulpi_fs_ls = 0,
+   .host_support_fs_ls_low_power   = 0,
+   .host_ls_low_power_phy_clk  = 0,/* 48 MHz */
+   .ts_dline   = 0,
+   .reload_ctl = 0,
+   .ahbcfg = 0x7  GAHBCFG_HBSTLEN_SHIFT, /* 
INCR16 */
+   .uframe_sched   = 0,
+};
+
 static const struct dwc2_core_params params_bcm2835 = {
.otg_cap= 0,/* HNP/SRP capable */
.otg_ver= 0,/* 1.3 */
@@ -129,6 +157,7 @@ static int dwc2_driver_remove(struct platform_device *dev)
 
 static const struct of_device_id dwc2_of_match_table[] = {
{ .compatible = brcm,bcm2835-usb, .data = params_bcm2835 },
+   { .compatible = hisilicon,hi6220-usb, .data = params_hi6220 },
{ .compatible = rockchip,rk3066-usb, .data = params_rk3066 },
{ .compatible = snps,dwc2, .data = NULL },
{ .compatible = samsung,s3c6400-hsotg, .data = NULL},
-- 
1.9.1

--
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 4/4] usb: phy: add phy-hi6220

2015-02-05 Thread Zhangfei Gao
Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/phy/Kconfig  |   9 ++
 drivers/usb/phy/Makefile |   1 +
 drivers/usb/phy/phy-hi6220.c | 290 +++
 3 files changed, 300 insertions(+)
 create mode 100644 drivers/usb/phy/phy-hi6220.c

diff --git a/drivers/usb/phy/Kconfig b/drivers/usb/phy/Kconfig
index c6d0c8e..405a3d0 100644
--- a/drivers/usb/phy/Kconfig
+++ b/drivers/usb/phy/Kconfig
@@ -173,6 +173,15 @@ config USB_MXS_PHY
 
  MXS Phy is used by some of the i.MX SoCs, for example imx23/28/6x.
 
+config USB_HI6220_PHY
+   tristate hi6220 USB PHY support
+   select USB_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI6220 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config USB_RCAR_PHY
tristate Renesas R-Car USB PHY support
depends on USB || USB_GADGET
diff --git a/drivers/usb/phy/Makefile b/drivers/usb/phy/Makefile
index 75f2bba..819283c 100644
--- a/drivers/usb/phy/Makefile
+++ b/drivers/usb/phy/Makefile
@@ -18,6 +18,7 @@ obj-$(CONFIG_SAMSUNG_USBPHY)  += phy-samsung-usb.o
 obj-$(CONFIG_TWL6030_USB)  += phy-twl6030-usb.o
 obj-$(CONFIG_USB_EHCI_TEGRA)   += phy-tegra-usb.o
 obj-$(CONFIG_USB_GPIO_VBUS)+= phy-gpio-vbus-usb.o
+obj-$(CONFIG_USB_HI6220_PHY)   += phy-hi6220.o
 obj-$(CONFIG_USB_ISP1301)  += phy-isp1301.o
 obj-$(CONFIG_USB_MSM_OTG)  += phy-msm-usb.o
 obj-$(CONFIG_USB_MV_OTG)   += phy-mv-usb.o
diff --git a/drivers/usb/phy/phy-hi6220.c b/drivers/usb/phy/phy-hi6220.c
new file mode 100644
index 000..87b1f0e
--- /dev/null
+++ b/drivers/usb/phy/phy-hi6220.c
@@ -0,0 +1,290 @@
+/*
+ * Copyright (c) 2015 Linaro Ltd.
+ * Copyright (c) 2015 Hisilicon Limited.
+ *
+ * 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.
+ */
+
+#include linux/clk.h
+#include linux/mfd/syscon.h
+#include linux/of_gpio.h
+#include linux/platform_device.h
+#include linux/regmap.h
+#include linux/regulator/consumer.h
+#include linux/usb/gadget.h
+#include linux/usb/otg.h
+
+#define SC_PERIPH_CTRL40x00c
+
+#define PERIPH_CTRL4_PICO_SIDDQBIT(6)
+#define PERIPH_CTRL4_PICO_OGDISABLEBIT(8)
+#define PERIPH_CTRL4_PICO_VBUSVLDEXT   BIT(10)
+#define PERIPH_CTRL4_PICO_VBUSVLDEXTSELBIT(11)
+#define PERIPH_CTRL4_OTG_PHY_SEL   BIT(21)
+
+#define SC_PERIPH_CTRL50x010
+
+#define PERIPH_CTRL5_USBOTG_RES_SELBIT(3)
+#define PERIPH_CTRL5_PICOPHY_ACAENBBIT(4)
+#define PERIPH_CTRL5_PICOPHY_BC_MODE   BIT(5)
+#define PERIPH_CTRL5_PICOPHY_CHRGSEL   BIT(6)
+#define PERIPH_CTRL5_PICOPHY_VDATSRCENDBIT(7)
+#define PERIPH_CTRL5_PICOPHY_VDATDETENBBIT(8)
+#define PERIPH_CTRL5_PICOPHY_DCDENBBIT(9)
+#define PERIPH_CTRL5_PICOPHY_IDDIG BIT(10)
+
+#define SC_PERIPH_CTRL80x018
+
+#define EYE_PATTERN_PARA   0x7053348c
+
+#define SC_PERIPH_RSTDIS0  0x304
+
+#define PERIPH_RSTDIS0_USBOTG_BUS  BIT(4)
+#define PERIPH_RSTDIS0_POR_PICOPHY BIT(5)
+#define PERIPH_RSTDIS0_USBOTG  BIT(6)
+#define PERIPH_RSTDIS0_USBOTG_32K  BIT(7)
+
+enum usb_mode {
+   USB_EMPTY,
+   GADGET_DEVICE,
+   OTG_HOST,
+};
+
+struct hi6220_priv {
+   struct usb_phy phy;
+   struct delayed_work work;
+   struct regmap *reg;
+   struct clk *clk;
+   struct regulator *vcc;
+   int gpio_vbus_det;
+   int gpio_id_det;
+   enum usb_mode mode;
+};
+
+static void hi6220_start_periphrals(struct hi6220_priv *priv, bool on)
+{
+   struct usb_otg *otg = priv-phy.otg;
+
+   if (!otg-gadget)
+   return;
+
+   if (on)
+   usb_gadget_connect(otg-gadget);
+   else
+   usb_gadget_disconnect(otg-gadget);
+}
+
+static void hi6220_detect_work(struct work_struct *work)
+{
+   struct hi6220_priv *priv =
+   container_of(work, struct hi6220_priv, work.work);
+   int id_det, vbus_det;
+   enum usb_mode mode;
+
+   if (!gpio_is_valid(priv-gpio_id_det) ||
+   !gpio_is_valid(priv-gpio_vbus_det))
+   return;
+
+   id_det = gpio_get_value_cansleep(priv-gpio_id_det);
+   vbus_det = gpio_get_value_cansleep(priv-gpio_vbus_det);
+
+   if (vbus_det == 0) {
+   if (id_det == 1)
+   mode = GADGET_DEVICE;
+   else
+   mode = OTG_HOST;
+   } else {
+   mode = USB_EMPTY;
+   }
+
+   if (mode == GADGET_DEVICE  priv-mode == USB_EMPTY)
+   hi6220_start_periphrals(priv, true);
+   if (mode == USB_EMPTY  priv-mode

[PATCH 1/4] Documentation: dt-bindings: add dt binding info for hi6220 dwc2

2015-02-05 Thread Zhangfei Gao
Add necessary dwc2 binding documentation for Hisilicon soc: hi6220

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index fd132cb..2213682 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -4,6 +4,7 @@ Platform DesignWare HS OTG USB 2.0 controller
 Required properties:
 - compatible : One of:
   - brcm,bcm2835-usb: The DWC2 USB controller instance in the BCM2835 SoC.
+  - hisilicon,hi6220-usb: The DWC2 USB controller instance in the hi6220 SoC.
   - rockchip,rk3066-usb: The DWC2 USB controller instance in the rk3066 Soc;
   - rockchip,rk3188-usb, rockchip,rk3066-usb, snps,dwc2: for rk3188 Soc;
   - rockchip,rk3288-usb, rockchip,rk3066-usb, snps,dwc2: for rk3288 Soc;
-- 
1.9.1

--
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 2/4] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-05 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 .../devicetree/bindings/usb/hi6220-usb.txt | 50 ++
 1 file changed, 50 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt

diff --git a/Documentation/devicetree/bindings/usb/hi6220-usb.txt 
b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
new file mode 100644
index 000..e926364
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/hi6220-usb.txt
@@ -0,0 +1,50 @@
+Hisilicon hi6220  SoC USB controlle
+-
+
+usb controller is inherited from dwc2, refer dwc2.txt
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+Refer to dwc2.txt for dwc2 usb properties
+
+
+phy:
+-
+
+Required properties:
+- compatible: hisilicon,hi6220-usb-phy
+- vcc-supply: phandle to the regulator that provides power to the PHY.
+- clocks: phandle to the PHY clock. Use as per Documentation/devicetree
+  /bindings/clock/clock-bindings.txt
+- hisilicon,peripheral-syscon: phandle of syscon used to control peripheral.
+- hisilicon,gpio_vbus_det: gpio of detecting vbus.
+- hisilicon,gpio_id_det: gpio of detecting id.
+
+Example:
+
+   peripheral_ctrl: syscon@f703 {
+   compatible = syscon;
+   reg = 0x0 0xf703 0x0 0x1000;
+   };
+
+   usb2_phy: usbphy {
+   compatible = hisilicon,hi6220-usb-phy;
+   vcc-supply = fixed_5v_hub;
+   hisilicon,gpio_vbus_det = gpio2 6 0;
+   hisilicon,gpio_id_det = gpio2 5 0;
+   hisilicon,peripheral-syscon = peripheral_ctrl;
+   clocks = clock_sys HI6220_USBOTG_HCLK;
+   };
+
+   usb: usb@f72c {
+   compatible = hisilicon,hi6220-usb;
+   reg = 0x0 0xf72c 0x0 0x4;
+   phys = usb2_phy;
+   dr_mode = otg;
+   g-use-dma;
+   g-rx-fifo-size = 512;
+   g-np-tx-fifo-size = 128;
+   g-tx-fifo-size = 128;
+   interrupts = 0 77 0x4;
+   };
-- 
1.9.1

--
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 0/4] add usb support for hi6220

2015-02-05 Thread Zhangfei Gao
hi6220 usb controller is inherited from dwc2
add phy accordingly
support otg gadget/host

Zhangfei Gao (4):
  Documentation: dt-bindings: add dt binding info for hi6220 dwc2
  Documentation: dt-bindings: add dt binding info for hi6220
  usb: dwc2: platform: add hi6220 support
  usb: phy: add phy-hi6220

 Documentation/devicetree/bindings/usb/dwc2.txt |   1 +
 .../devicetree/bindings/usb/hi6220-usb.txt |  50 
 drivers/usb/dwc2/platform.c|  29 +++
 drivers/usb/phy/Kconfig|   8 +
 drivers/usb/phy/Makefile   |   1 +
 drivers/usb/phy/phy-hi6220.c   | 290 +
 6 files changed, 379 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/hi6220-usb.txt
 create mode 100644 drivers/usb/phy/phy-hi6220.c

-- 
1.9.1

--
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 1/2] usb: phy: load usb phy earlier

2015-02-04 Thread Zhangfei Gao
Since phy is definitely used usb controller, load the phy
earlier rather than using defer probe to make boot time shorter.

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
index 2f1e2aa..d8926c6 100644
--- a/drivers/usb/Makefile
+++ b/drivers/usb/Makefile
@@ -5,6 +5,7 @@
 # Object files in subdirectories
 
 obj-$(CONFIG_USB)  += core/
+obj-$(CONFIG_USB_SUPPORT)  += phy/
 
 obj-$(CONFIG_USB_DWC3) += dwc3/
 obj-$(CONFIG_USB_DWC2) += dwc2/
@@ -48,7 +49,6 @@ obj-$(CONFIG_USB_MICROTEK)+= image/
 obj-$(CONFIG_USB_SERIAL)   += serial/
 
 obj-$(CONFIG_USB)  += misc/
-obj-$(CONFIG_USB_SUPPORT)  += phy/
 obj-$(CONFIG_EARLY_PRINTK_DBGP)+= early/
 
 obj-$(CONFIG_USB_ATM)  += atm/
-- 
1.9.1

--
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 2/2] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-04 Thread Zhangfei Gao
Gadget directly set GAHBCFG_HBSTLEN_INCR4, reuse ahbcfg if assigned from 
platform

Signed-off-by: Zhangfei Gao zhangfei@linaro.org
---
 drivers/usb/dwc2/core.c   | 2 +-
 drivers/usb/dwc2/gadget.c | 8 ++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index d5197d4..8d388cc 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -2563,7 +2563,7 @@ void dwc2_set_param_reload_ctl(struct dwc2_hsotg *hsotg, 
int val)
 
 void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)
 {
-   if (val != -1)
+   if (val)
hsotg-core_params-ahbcfg = val;
else
hsotg-core_params-ahbcfg = GAHBCFG_HBSTLEN_INCR4 
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 15aa578..20085de 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2314,9 +2314,13 @@ void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg 
*hsotg,
GINTSTS_USBSUSP | GINTSTS_WKUPINT,
hsotg-regs + GINTMSK);
 
+   if ((hsotg-core_params)  (hsotg-core_params-ahbcfg != -1))
+   val = hsotg-core_params-ahbcfg  ~GAHBCFG_CTRL_MASK;
+   else
+   val = GAHBCFG_HBSTLEN_INCR4  GAHBCFG_HBSTLEN_SHIFT;
+
if (using_dma(hsotg))
-   writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN |
-  (GAHBCFG_HBSTLEN_INCR4  GAHBCFG_HBSTLEN_SHIFT),
+   writel(GAHBCFG_GLBL_INTR_EN | GAHBCFG_DMA_EN | val,
   hsotg-regs + GAHBCFG);
else
writel(((hsotg-dedicated_fifos) ? (GAHBCFG_NP_TXF_EMP_LVL |
-- 
1.9.1

--
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 0/2] misc change

2015-02-04 Thread Zhangfei Gao
two misc changes, no function impact

Zhangfei Gao (2):
  usb: phy: load usb phy earlier
  usb: dwc2: gadget reuse ahbcfg assigned from platform

 drivers/usb/Makefile  | 2 +-
 drivers/usb/dwc2/core.c   | 2 +-
 drivers/usb/dwc2/gadget.c | 8 ++--
 3 files changed, 8 insertions(+), 4 deletions(-)

-- 
1.9.1

--
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 2/2] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-04 Thread Zhangfei Gao
Hi Yousaf

On 4 February 2015 at 17:41, Kaukab, Yousaf yousaf.kau...@intel.com wrote:
 diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c index
 d5197d4..8d388cc 100644
 --- a/drivers/usb/dwc2/core.c
 +++ b/drivers/usb/dwc2/core.c
 @@ -2563,7 +2563,7 @@ void dwc2_set_param_reload_ctl(struct dwc2_hsotg
 *hsotg, int val)

  void dwc2_set_param_ahbcfg(struct dwc2_hsotg *hsotg, int val)  {
 - if (val != -1)
 + if (val)
   hsotg-core_params-ahbcfg = val;
   else
   hsotg-core_params-ahbcfg =
 GAHBCFG_HBSTLEN_INCR4  diff --git a/drivers/usb/dwc2/gadget.c
 b/drivers/usb/dwc2/gadget.c index 15aa578..20085de 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2314,9 +2314,13 @@ void s3c_hsotg_core_init_disconnected(struct
 dwc2_hsotg *hsotg,
   GINTSTS_USBSUSP | GINTSTS_WKUPINT,
   hsotg-regs + GINTMSK);

 + if ((hsotg-core_params)  (hsotg-core_params-ahbcfg != -
 1))
 + val = hsotg-core_params-ahbcfg 
 ~GAHBCFG_CTRL_MASK;
 + else
 + val = GAHBCFG_HBSTLEN_INCR4 
 GAHBCFG_HBSTLEN_SHIFT;
 +
   if (using_dma(hsotg))
 - writel(GAHBCFG_GLBL_INTR_EN |
 GAHBCFG_DMA_EN |
 -(GAHBCFG_HBSTLEN_INCR4 
 GAHBCFG_HBSTLEN_SHIFT),
 + writel(GAHBCFG_GLBL_INTR_EN |
 GAHBCFG_DMA_EN | val,
  hsotg-regs + GAHBCFG);
   else
   writel(((hsotg-dedicated_fifos) ?
 (GAHBCFG_NP_TXF_EMP_LVL |

 There are other bits in GAHBCFG that can be set from platform. They will be 
 preserved by your patch, as they are not part of GAHBCFG_CTRL_MASK, but only 
 in case dma is enabled. Perhaps preserve them in non-dma case as well.

Here may have issue if also set hsotg-core_params-ahbcfg for non-dma case,
since GAHBCFG[4:1] may be set.

Though from drivers/usb/dwc2/core.h we can not see @ahbcfg is
specifically used for dma case,
most case in drivers/usb/dwc2/platform.c use ahbcfg is set hbstlen,
GAHBCFG[4:1].
For example, our platform set GAHBCFG_HBSTLEN_INCR16.

So I just assume @ahbcfg is used for dma case.
What do you think.

Thanks
--
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 2/2] usb: dwc2: gadget reuse ahbcfg assigned from platform

2015-02-04 Thread Zhangfei Gao
On 4 February 2015 at 21:51, Sergei Shtylyov
sergei.shtyl...@cogentembedded.com wrote:
 diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
 index 15aa578..20085de 100644
 --- a/drivers/usb/dwc2/gadget.c
 +++ b/drivers/usb/dwc2/gadget.c
 @@ -2314,9 +2314,13 @@ void s3c_hsotg_core_init_disconnected(struct
 dwc2_hsotg *hsotg,
 GINTSTS_USBSUSP | GINTSTS_WKUPINT,
 hsotg-regs + GINTMSK);

 +   if ((hsotg-core_params)  (hsotg-core_params-ahbcfg != -1))


Inner pares not needed, especially the first ones.

Yes, definitely.
Thanks Sergei.
--
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


usb dwc2 too much sof in host mode

2015-02-02 Thread Zhangfei Gao
Thanks to Yousaf, the latest dwc2 code from latest testing/next works
well for both gadget and host.
When remove the usb, it will switch to host mode by default.

However, at this time, I found too much sof generating in our
platform, if no device attached.
1, usb gadget,
2, remove usb,
3, cat /proc/interrupt, then too much usb interrupt generated quickly.

Same phenomenon if setting usb host to low speed and attach usb disk
or keyboard.
1, usb gadget,
2, remove usb,
3. attach usb keyboard
4, cat /proc/interrupt, then too much usb interrupt generated quickly.

usb_hcd_submit_urb
{
  if (is_root_hub(urb-dev)) {
status = rh_urb_enqueue(hcd, urb);
} else {
status = hcd-driver-urb_enqueue(hcd, urb, mem_flags);
}
}

dwc2_hcd_qh_add
{
if (!hsotg-periodic_qh_count) {
intr_mask = readl(hsotg-regs + GINTMSK);
intr_mask |= GINTSTS_SOF;
writel(intr_mask, hsotg-regs + GINTMSK);
}
}

When usb is removed, urb-dev-parent will be generated after
usb 1-1: new full-speed USB device number 2 using dwc2
Then the next USB_ENDPOINT_XFER_INT will set GINTSTS_SOF, and will
cause sof since then.

I am wandering is it expected behavior or abnormal behavior, the sof
interrupt is generated too quickly.

Besides, the dwc2 controller is 2.93a, 0xf72c0040 = 0x4F54300A

Thanks
--
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