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


Re: [PATCH] usb: dwc2: add support of hi6220

2015-11-22 Thread zhangfei



On 11/20/2015 11:34 PM, Felipe Balbi wrote:


John Youn  writes:



That's weird. I just sync'd to your testing/next and it seems to
apply fine.

Same with the series from Gregory Herrero.

Any chance it's something to do with your local repo?


odd. Seems like it works if I apply manually with git am, but fails if I
pipe message from emacs to git am. Oh well, let me try again.



Thanks Felipe & John, have verified hi6220 usb on testing/next.

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

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

Acked-by: Rob Herring 
Signed-off-by: Zhangfei Gao 
---
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 = <&fixed_5v_hub>;
+   hisilicon,peripheral-syscon = <&sys_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);
+}
+
+static int hi6220_phy_setup(stru

[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 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 
---
 .../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 = <&fixed_5v_hub>;
+   hisilicon,peripheral-syscon = <&sys_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 va

Re: [PATCH 00/19] usb: third series of updates for dwc2 driver

2015-03-15 Thread zhangfei



On 03/09/2015 11:04 PM, Mian Yousaf Kaukab wrote:

Hi,
This patchset consists of some bug fixes and feature enhancements for
the dwc2 driver. All the patches are verified on dwc2 v3.0a with
dedicated fifos. Main focus of testing was with dma enabled. Although
basic testing without dma was also done.

This is based on testing/next branch in Felipe's git.


Thanks Yousaf
Also verified on hikey board, dma mode, though it is also dwc2 v3.0a.

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

2015-02-26 Thread zhangfei

Hi, Roger

On 02/24/2015 06:13 PM, Roger Quadros wrote:

On Sat, Feb 21, 2015 at 11:03:05PM +0800, zhangfei wrote:

+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);


why is the PHY fiddling with pullups ?


We use this to enable/disable otg gadget mode.


I got that, but the pullups don't belong to the PHY, they belong to the
gadget.


The gpio_id & gpio_vbus are used to distinguish otg gadget mode or
host mode.
When micro usb or otg device attached to otg, gpio_vbus falling down.
And gpio_id = 1 is micro usb, gpio_id = 0 is otg device.


all of that I understood clearly :-)


So when micro usb attached, we enable gadget mode; while micro usb
detached, we disable gadget mode, and dwc2 will automatically set to
host mode.


that's all fine, I'm concerned about letting the PHY fiddle with
something it doesn't own. If I am to change pullups rules in udc-core,
this is likely to break down miserably and I don't want to have to go
through that.


Thanks for the clarifying.


no problem.


How about using usb_gadget_vbus_connect/disconnect, which are used in many
files under drivers/usb/phy.
There is no vbus_session in dwc2/gadget.c, I thought it would be same as
pullup.

However, usb_gadget_vbus_connect still need para gadget, where should we put
this file, drivers/usb/phy or drivers/phy


drivers/phy, if the framework misses anything you need, it's a great
opportunity to give back to the community by extending the framework.


Sorry, I am a little confused.
I need some concrete suggestion for the next step of this patch, which is 
required for the community board, hikey board.

Do you mean in the future we need use hsotg->phy instead of hsotg->uphy.
 struct phy *phy;
 struct usb_phy *uphy;
usb_phy has many members that struct phy does not have, including otg.
struct usb_otg  *otg;
Is that mean we need port such member from usb_phy to phy.


In my opinion otg structure should belong to the USB core part that takes care
of the OTG/DRD state machine. We still don't have a clear solution here and
I'm currently investigating this.
My current work is to get Dual role functionality working with DWC3 controller 
and TI
platforms.

Currently phy drivers take care of OTG operation themselves but there is an 
opportunity
to share code and centralize USB role switching.
The USB core should be the owner of the Host controller, Gadget controller and 
the OTG phy
and should take care of the that.


Good idea.
If you have any patch, I will be very happy to verify.

How about adding these things in drivers/phy/phy-core.c, it is also 
sharable, though not in usb core.


Just tried adding one member struct usb_otg otg to struct phy, since not 
find any good member can hold usb_otg.
In drivers/phy/phy-core.c, adding extcon_register_interest, 
phy_vbus_notifier, phy_set_peripheral, it works for me, dwc2 on hikey board.






Besides, are you ok with using usb_gadget_vbus_connect/disconnect.


I don't think PHY is the right place for this even though older drivers seem to 
be doing so.
But at the same time there is nowhere else to add this at the moment.
The right place should be the USB core that is aware of host/gadget, phy and 
the state of the bus.


Understand.


Scratching one's own itch kinda thing...


+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);


looks like this should be using extcon

Not used extcon before.
However, we need gpio_vbus interrupt.
Checked phy-tahvo.c and phy-omap-otg.c, not find extcon related with
interrupt.
Will investigate tomorrow.


drivers/extcon/extcon-gpio.c

I think there is no need to use extcon, gpio is clear enough.
extcon-gpio.c even do not support dt.


well, add DT. The whole idea of free software is that we improve on
things we already have. EXTCON is *the* API to handle such things.




I wrote the extcon-gpio-usb.c driver for exactly your use case. It is
queued for v4.1
https://lkml.org/lkml/2015/2/2/187


That's great, thanks.


It takes care of debouncing for you. Although currently it supports only ID 
gpio,
it should be very easy to extend to VBUS sense GPIO.


I think I am still not understanding extcon-gpio, not sure why need use this 
API here.


several reasons. Let me list a few.
1) Code reuse. Every PHY driver doesn't need to implement GPIO/interrupt 
handling and de

Re: [PATCH v4 4/4] phy: add phy-hi6220-usb

2015-02-25 Thread zhangfei



On 02/23/2015 11:36 PM, Felipe Balbi wrote:

Hi,

On Sun, Feb 22, 2015 at 11:10:36AM +0800, zhangfei wrote:

+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);


why is the PHY fiddling with pullups ?


We use this to enable/disable otg gadget mode.


I got that, but the pullups don't belong to the PHY, they belong to the
gadget.


The gpio_id & gpio_vbus are used to distinguish otg gadget mode or
host mode.
When micro usb or otg device attached to otg, gpio_vbus falling down.
And gpio_id = 1 is micro usb, gpio_id = 0 is otg device.


all of that I understood clearly :-)


So when micro usb attached, we enable gadget mode; while micro usb
detached, we disable gadget mode, and dwc2 will automatically set to
host mode.


that's all fine, I'm concerned about letting the PHY fiddle with
something it doesn't own. If I am to change pullups rules in udc-core,
this is likely to break down miserably and I don't want to have to go
through that.


Thanks for the clarifying.


no problem.


How about using usb_gadget_vbus_connect/disconnect, which are used in many
files under drivers/usb/phy.
There is no vbus_session in dwc2/gadget.c, I thought it would be same as
pullup.

However, usb_gadget_vbus_connect still need para gadget, where should we put
this file, drivers/usb/phy or drivers/phy


drivers/phy, if the framework misses anything you need, it's a great
opportunity to give back to the community by extending the framework.


Sorry, I am a little confused.
I need some concrete suggestion for the next step of this patch, which is
required for the community board, hikey board.

Do you mean in the future we need use hsotg->phy instead of hsotg->uphy.
 struct phy *phy;
 struct usb_phy *uphy;


yes, we need to move everybody to use struct phy, instead of struct
usb_phy.


usb_phy has many members that struct phy does not have, including otg.
struct usb_otg  *otg;
Is that mean we need port such member from usb_phy to phy.


This means we have a little ground work to do before we can add your phy
driver to that framework, right ? As I said, if the framework is missing
anything, work with Kishon (generic phy maintainer) to add those missing
pieces generically.


OK, got it.



Besides, are you ok with using usb_gadget_vbus_connect/disconnect.



Scratching one's own itch kinda thing...


+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);


looks like this should be using extcon

Not used extcon before.
However, we need gpio_vbus interrupt.
Checked phy-tahvo.c and phy-omap-otg.c, not find extcon related with
interrupt.
Will investigate tomorrow.


drivers/extcon/extcon-gpio.c

I think there is no need to use extcon, gpio is clear enough.
extcon-gpio.c even do not support dt.


well, add DT. The whole idea of free software is that we improve on
things we already have. EXTCON is *the* API to handle such things.


I think I am still not understanding extcon-gpio, not sure why need
use this API here.


because extcon is the API to use for external connectors. The same way
you use regulator framework to control that single GPIO tied to an
enable signal of a fixed regulator, you use extcon when you need to read
that gpio signal tied to id pin of the USB connector.


Here two gpio requires, one gpio as interrupt, in the interrupt
handler, we detect the gpio status judging the otg status.
extcon-gpio.c use the interrupt, then can we also use the gpio
interrupt.  Using extcon-gpio is used for saving gpio_request?


extcon is used to hide gpio_request from dwc2. dwc2 only knows about
extcon, not gpios. extcon will request the gpio and use it as interrupt
source. When an IRQ fires, it will read the gpio state and decide if it
should broadcast a message to tell dwc2 to become host or peripheral.


Thanks for the kind education, understand now.





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


Re: [PATCH v2 1/2] usb: phy: load usb phy earlier

2015-02-25 Thread zhangfei



On 02/23/2015 11:28 PM, Felipe Balbi wrote:

On Fri, Feb 06, 2015 at 09:01:16AM +0800, Peter Chen wrote:

On Thu, Feb 05, 2015 at 09:24:02PM +0800, Zhangfei Gao wrote:

Since phy is definitely used in usb controller, load the phy
earlier to make boot time shorter.

Signed-off-by: Zhangfei Gao 
---
  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



After thinking more, I think it is a good patch, USB PHY works proper
is the base for 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 drivers
follow the similar method.

Acked-by: Peter Chen 


the problem, though, is that this also hides drivers which are not
handling unordered initializations properly. If everything is built as a
module, udev might device to load modules in whatever order it might see
fit.


But this should not be the reason we intentionally move phy ahead of 
controller, which must use phy as base.


Besides, there are many examples in drivers/Makefile

# Many drivers will want to use DMA so this has to be made available 

# really early. 


obj-$(CONFIG_DMADEVICES)+= dma/

# regulators early, since some subsystems rely on them to initialize 

obj-$(CONFIG_REGULATOR) += regulator/ 




# reset controllers early, since gpu drivers might rely on them to 
initialize

obj-$(CONFIG_RESET_CONTROLLER)  += reset/


Zhangfei, you're claiming boot time is shorter with this patch. How much
shorter ? How have you measured the time you saved ?


Not measure precisely.
Load ramfs from 5.354419 to 5.302098,

However, as you said, new phy should be in driver/phy, then no such 
issue in the future.


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

2015-02-21 Thread zhangfei

Hi, Balbi

On 02/22/2015 12:21 AM, Felipe Balbi wrote:

Hi,

On Sat, Feb 21, 2015 at 11:03:05PM +0800, zhangfei wrote:

+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);


why is the PHY fiddling with pullups ?


We use this to enable/disable otg gadget mode.


I got that, but the pullups don't belong to the PHY, they belong to the
gadget.


The gpio_id & gpio_vbus are used to distinguish otg gadget mode or
host mode.
When micro usb or otg device attached to otg, gpio_vbus falling down.
And gpio_id = 1 is micro usb, gpio_id = 0 is otg device.


all of that I understood clearly :-)


So when micro usb attached, we enable gadget mode; while micro usb
detached, we disable gadget mode, and dwc2 will automatically set to
host mode.


that's all fine, I'm concerned about letting the PHY fiddle with
something it doesn't own. If I am to change pullups rules in udc-core,
this is likely to break down miserably and I don't want to have to go
through that.


Thanks for the clarifying.


no problem.


How about using usb_gadget_vbus_connect/disconnect, which are used in many
files under drivers/usb/phy.
There is no vbus_session in dwc2/gadget.c, I thought it would be same as
pullup.

However, usb_gadget_vbus_connect still need para gadget, where should we put
this file, drivers/usb/phy or drivers/phy


drivers/phy, if the framework misses anything you need, it's a great
opportunity to give back to the community by extending the framework.


Sorry, I am a little confused.
I need some concrete suggestion for the next step of this patch, which 
is required for the community board, hikey board.


Do you mean in the future we need use hsotg->phy instead of hsotg->uphy.
struct phy *phy;
struct usb_phy *uphy;
usb_phy has many members that struct phy does not have, including otg.
struct usb_otg  *otg;
Is that mean we need port such member from usb_phy to phy.

Besides, are you ok with using usb_gadget_vbus_connect/disconnect.



Scratching one's own itch kinda thing...


+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);


looks like this should be using extcon

Not used extcon before.
However, we need gpio_vbus interrupt.
Checked phy-tahvo.c and phy-omap-otg.c, not find extcon related with
interrupt.
Will investigate tomorrow.


drivers/extcon/extcon-gpio.c

I think there is no need to use extcon, gpio is clear enough.
extcon-gpio.c even do not support dt.


well, add DT. The whole idea of free software is that we improve on
things we already have. EXTCON is *the* API to handle such things.


I think I am still not understanding extcon-gpio, not sure why need use 
this API here.


Here two gpio requires, one gpio as interrupt, in the interrupt handler, 
we detect the gpio status judging the otg status.

extcon-gpio.c use the interrupt, then can we also use the gpio interrupt.
Using extcon-gpio is used for saving gpio_request?



Quite frankly, though, Roger Quadros (now in Cc) has been working to get
DT support on extcon-gpio, so perhaps wait for that and base your
patches on top of his.

Now your statement that GPIO is clear enough is completely bogus to me.

Why do we have fixed regulators with GPIO enable signals, right ? Might
as well just fiddle with the GPIO directly, right ? Wrong, the idea of
using these frameworks is to encapsulate implementation details and make
sure that if things change from one board to another, we can still use
our SW without major modifications.


+   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 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));


this is really bad. We have threaded interrupt support, right ?


Since we use two gpio to distinguish gadget mode or host mode.
Debounce time can int

Re: [PATCH v4 4/4] phy: add phy-hi6220-usb

2015-02-21 Thread zhangfei

Hi, Balbi

On 02/21/2015 12:06 AM, Felipe Balbi wrote:

Hi,

On Fri, Feb 20, 2015 at 11:44:37PM +0800, zhangfei wrote:

Hi, Balbi

On 02/20/2015 10:41 PM, Felipe Balbi wrote:


+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);


why is the PHY fiddling with pullups ?


We use this to enable/disable otg gadget mode.


I got that, but the pullups don't belong to the PHY, they belong to the
gadget.


The gpio_id & gpio_vbus are used to distinguish otg gadget mode or
host mode.
When micro usb or otg device attached to otg, gpio_vbus falling down.
And gpio_id = 1 is micro usb, gpio_id = 0 is otg device.


all of that I understood clearly :-)


So when micro usb attached, we enable gadget mode; while micro usb
detached, we disable gadget mode, and dwc2 will automatically set to
host mode.


that's all fine, I'm concerned about letting the PHY fiddle with
something it doesn't own. If I am to change pullups rules in udc-core,
this is likely to break down miserably and I don't want to have to go
through that.


Thanks for the clarifying.

How about using usb_gadget_vbus_connect/disconnect, which are used in 
many files under drivers/usb/phy.
There is no vbus_session in dwc2/gadget.c, I thought it would be same as 
pullup.


However, usb_gadget_vbus_connect still need para gadget, where should we 
put this file, drivers/usb/phy or drivers/phy





+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);


looks like this should be using extcon

Not used extcon before.
However, we need gpio_vbus interrupt.
Checked phy-tahvo.c and phy-omap-otg.c, not find extcon related with
interrupt.
Will investigate tomorrow.


drivers/extcon/extcon-gpio.c

I think there is no need to use extcon, gpio is clear enough.
extcon-gpio.c even do not support dt.




+   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 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));


this is really bad. We have threaded interrupt support, right ?


Since we use two gpio to distinguish gadget mode or host mode.
Debounce time can introduce more accuracy.


gpio_set_debounce() ?

Not all gpio.c support set_debounce, including gpio-pl061.c.




I think threaded interrupt can not be used for adding debounce time.
Here add debounce is just for safety.


add the debounce to the gpio itself.


Here the debounce added only for safety.
gpio_id may mis-report when unplug usb, but it is correct for plug usb & 
otg device.

So debounce can be omitted.
If you think using delayed work for debounce is ugly, it is fine switch 
to threaded_irq.


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

2015-02-20 Thread zhangfei

Hi, John

On 02/21/2015 08:35 AM, John Youn wrote:

On 2/15/2015 5:50 AM, Zhangfei Gao wrote:

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

/*



Hi Zhangfei,

It looks like currently that the hsotg->core_params structure is not designed 
to be accessed by the gadget part (or this structure was overlooked during the 
integration of these drivers). It is only initialized in the host mode and this 
should crash if host mode is not configured.


If dwc2_hcd_init only called in host mode, hsotg->core_params = NULL.
So add judgement if (hsotg->core_params) here to prevent crash.


Until this is fixed properly we shouldn't access this here.


OK.
This mismatch does not impact function after all.

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

2015-02-20 Thread zhangfei

Hi, Balbi

On 02/20/2015 10:41 PM, Felipe Balbi wrote:


+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);


why is the PHY fiddling with pullups ?


We use this to enable/disable otg gadget mode.

The gpio_id & gpio_vbus are used to distinguish otg gadget mode or host 
mode.

When micro usb or otg device attached to otg, gpio_vbus falling down.
And gpio_id = 1 is micro usb, gpio_id = 0 is otg device.

So when micro usb attached, we enable gadget mode; while micro usb 
detached, we disable gadget mode, and dwc2 will automatically set to 
host mode.





+}
+
+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);


looks like this should be using extcon

Not used extcon before.
However, we need gpio_vbus interrupt.
Checked phy-tahvo.c and phy-omap-otg.c, not find extcon related with 
interrupt.

Will investigate tomorrow.




+
+   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 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));


this is really bad. We have threaded interrupt support, right ?


Since we use two gpio to distinguish gadget mode or host mode.
Debounce time can introduce more accuracy.
I think threaded interrupt can not be used for adding debounce time.
Here add debounce is just for safety.

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

2015-02-20 Thread zhangfei



On 02/20/2015 12:38 PM, Felipe Balbi wrote:

On Fri, Feb 20, 2015 at 11:07:21AM +0800, zhangfei wrote:

Hi, Balbi

On 02/18/2015 10:35 PM, Felipe Balbi wrote:

On Wed, Feb 18, 2015 at 01:44:21PM +0800, zhangfei wrote:

Hi, Kishon

On 02/18/2015 01:35 PM, Kishon Vijay Abraham I wrote:

Hi,

On Thursday 12 February 2015 01:07 PM, Zhangfei Gao wrote:

Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao 
---
  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


why is this driver in drivers/phy when it doesn't use the generic PHY
framework at all?



Balbi recommended "new drivers only on drivers/phy/", including usb
phy.


but it should use the API too. It's not only about a directory, you need
to use the new API.


So Move drivers/usb/phy/phy-hi6220-usb.c to
drivers/phy/phy-hi6220-usb.c, required by Balbi.


you're reading what I stated the way you like.


Sorry for my bad understanding.

Still not clear about the otg_set_peripheral, which is required in
phy-hi6220-usb.c

1. drivers/usb/dwc2/gadget.c use
otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget);

2. include/linux/phy/phy.h
struct phy do not have member otg, while struct usb_phy has.

Could you give more hints?


your set_peripheral doesn't do anything, just holds a pointer. Might as
well not implement it. I'll review your driver more fully tomorrow.

There a few things which must be changed.



Thanks in advance.

We need this call back set_peripheral setting otg->gadget, which used in 
usb_gadget_connect/disconnect(otg->gadget).


The workable method test here is not provide phy-names = "usb2-phy";
Then dwc2 will still use hsotg->uphy instead of hsotg->phy.
Though devm_phy_create is used in phy-hi6220-usb.c, phy_ops is not used 
in fact.


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

2015-02-19 Thread zhangfei

Hi, Balbi

On 02/18/2015 10:35 PM, Felipe Balbi wrote:

On Wed, Feb 18, 2015 at 01:44:21PM +0800, zhangfei wrote:

Hi, Kishon

On 02/18/2015 01:35 PM, Kishon Vijay Abraham I wrote:

Hi,

On Thursday 12 February 2015 01:07 PM, Zhangfei Gao wrote:

Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao 
---
  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


why is this driver in drivers/phy when it doesn't use the generic PHY
framework at all?



Balbi recommended "new drivers only on drivers/phy/", including usb
phy.


but it should use the API too. It's not only about a directory, you need
to use the new API.


So Move drivers/usb/phy/phy-hi6220-usb.c to
drivers/phy/phy-hi6220-usb.c, required by Balbi.


you're reading what I stated the way you like.


Sorry for my bad understanding.

Still not clear about the otg_set_peripheral, which is required in 
phy-hi6220-usb.c


1. drivers/usb/dwc2/gadget.c use
otg_set_peripheral(hsotg->uphy->otg, &hsotg->gadget);

2. include/linux/phy/phy.h
struct phy do not have member otg, while struct usb_phy has.

Could you give more hints?

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

2015-02-17 Thread zhangfei

Hi, Kishon

On 02/18/2015 01:35 PM, Kishon Vijay Abraham I wrote:

Hi,

On Thursday 12 February 2015 01:07 PM, Zhangfei Gao wrote:

Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao 
---
  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


why is this driver in drivers/phy when it doesn't use the generic PHY
framework at all?



Balbi recommended "new drivers only on drivers/phy/", including usb phy.
So Move drivers/usb/phy/phy-hi6220-usb.c to 
drivers/phy/phy-hi6220-usb.c, required by Balbi.


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 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 
---
 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 
Acked-by: Peter Chen 
---
 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 
---
 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 
+#include 
+#include 
+#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 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 irqreturn_t hiusb_gpio_intr(int irq, void *data)
+{
+   struct hi6220_priv 

[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 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 
---
 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 
---
 .../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


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

2015-02-11 Thread zhangfei



On 02/10/2015 10:48 PM, Felipe Balbi wrote:


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


new drivers only on drivers/phy/, sorry.


One more quesiton.
Should I also move Documentation/devicetree/bindings/usb/hi6220-usb.txt 
to Documentation/devicetree/bindings/phy/?


I describing both usb controller and phy here, is it still should be put 
under Documentation/devicetree/bindings/usb/?


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




--
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 v3 4/5] usb: phy: load usb phy earlier

2015-02-10 Thread zhangfei



On 02/10/2015 10:49 PM, Felipe Balbi wrote:

On Tue, Feb 10, 2015 at 03:04:28PM +0800, Peter Chen wrote:

This patch does not belong to phy, so, doesn't need to
add phy in subject, meanwhile, please add GregKH as TO list,
he is the right one to queue this patch.

Reply-To:
In-Reply-To: <1423554627-694-5-git-send-email-zhangfei@linaro.org>

On Tue, Feb 10, 2015 at 03:50:26PM +0800, Zhangfei Gao wrote:

Since phy is definitely used in usb controller, load the phy
earlier to make boot time shorter.

Signed-off-by: Zhangfei Gao 
Acked-by: Peter Chen 


NAK, make sure there are no such dependencies with your controller
driver. They should know how to defer probing if their resources aren't
available yet.


Sorry for the confusion,
There is no dependencies at all, just for optimization.
Peter already told me this patch should not be put here, causing confusion.
And I resend in another thread.

The controller is dwc2, which use defer probe. And dwc2 controller defer 
probe every time even the phy driver in the same folder.
Since we know the calling sequence, we can simply change the sequence to 
load the phy earlier.



However, as you said the new driver will be put in drivers/phy, there 
should be no such issue in the future.

It is OK not using this patch.

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

2015-02-10 Thread zhangfei



On 02/10/2015 10:48 PM, Felipe Balbi wrote:

On Tue, Feb 10, 2015 at 05:10:04PM +0800, Zhangfei Gao wrote:

Add usb phy controller for hi6220 platform

Signed-off-by: Zhangfei Gao 
---
  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


new drivers only on drivers/phy/, sorry.


OK, thanks for the info, I don't know this at all.
So even usb phy should be put under drivers/phy/.

Will change that.

Thanks Felipe
--
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: 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 
Acked-by: Peter Chen 
---
 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


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

2015-02-10 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 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 
---
 .../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 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 
---
 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 
---
 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 
+#include 
+#include 
+#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 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;
+   }
+}
+
+static irqreturn_t hiusb_gpio_intr(int irq, void *data)
+{
+   str

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

2015-02-10 Thread zhangfei



On 02/10/2015 03:04 PM, Peter Chen wrote:

This patch does not belong to phy, so, doesn't need to
add phy in subject, meanwhile, please add GregKH as TO list,
he is the right one to queue this patch.

Reply-To:
In-Reply-To: <1423554627-694-5-git-send-email-zhangfei@linaro.org>


OK, thanks Peter.
Will resend this patchset and drop this one.

--
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 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 
Acked-by: Peter Chen 
---
 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 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 
---
 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 
+#include 
+#include 
+#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 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;
+   }
+}
+
+static irqreturn_t hiusb_gpio_intr(int irq, void *data)
+{
+   str

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

2015-02-09 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 2/5] Documentation: dt-bindings: add dt binding info for hi6220

2015-02-09 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 .../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 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


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


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

Re: [PATCH v2 4/4] usb: phy: add phy-hi6220-usb

2015-02-09 Thread zhangfei



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 rely on them to initialize
obj-$(CONFIG_REGULATOR) += regulator/

EPROBE_DEFER should be the last option we rely on.


Thank

Re: [PATCH 4/4] usb: phy: add phy-hi6220

2015-02-08 Thread Zhangfei Gao
On 9 February 2015 at 09:57, Peter Chen  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 
---
 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 
+#include 
+#include 
+#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 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 irqreturn_t hiusb_gpio_intr(int irq, void *data)
+{
+   struct hi6220_priv *priv = (struct 

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

2015-02-06 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 .../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 3/4] usb: dwc2: platform: add hi6220 support

2015-02-06 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 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  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 4/4] usb: phy: add phy-hi6220

2015-02-06 Thread Zhangfei Gao
On 6 February 2015 at 16:41, Peter Chen  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, i

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
 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 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 
---
 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#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 == GADGET_DEVICE)
+   hi6220_start_periphrals(priv, false);
+
+   p

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

2015-02-05 Thread Zhangfei Gao
Signed-off-by: Zhangfei Gao 
---
 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 = ¶ms_bcm2835 },
+   { .compatible = "hisilicon,hi6220-usb", .data = ¶ms_hi6220 },
{ .compatible = "rockchip,rk3066-usb", .data = ¶ms_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 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 
---
 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 
---
 .../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 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 
---
 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 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 
---
 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 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  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
 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


Re: [PATCH 1/2] usb: phy: load usb phy earlier

2015-02-04 Thread zhangfei



On 02/04/2015 04:16 PM, Peter Chen wrote:

On Wed, Feb 4, 2015 at 4:01 PM, Zhangfei Gao  wrote:

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


The similar patch posted before, you may use probe deferral in your controller
driver if the PHY is not ready, besides, both controller and phy
driver may be built
as modules.


Yes, probe deferral is still used in the controller.
For example, dwc2 every time use defer probe to wait phy probe complete.

However since they are in the same folder, and we already know the 
sequence, is it better to change the sequence to make it quicker.


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


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


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