[PATCH] phy: rockchip-inno-usb2: add COMMON_CLK dependency

2016-08-15 Thread Frank Wang
On kernel builds without COMMON_CLK, the newly added rockchip-inno-usb2
driver fails to build:

drivers/phy/phy-rockchip-inno-usb2.c:124:16: error: field 'clk480m_hw'
has incomplete type
   struct clk_hw clk480m_hw;

In file included from include/linux/clk.h:16:0
 from drivers/phy/phy-rockchip-inno-usb2.c:17:
include/linux/kernel.h:831:48: error: initialization from incompatible
pointer type [-Werror=incompatible-pointer-types]
   const typeof( ((type *)0)->member ) *__mptr = (ptr); \

  ... ...

Signed-off-by: Frank Wang 
---
 drivers/phy/Kconfig |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index f9bf981..c6d57e5 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -370,6 +370,7 @@ config PHY_ROCKCHIP_USB
 config PHY_ROCKCHIP_INNO_USB2
tristate "Rockchip INNO USB2PHY Driver"
depends on (ARCH_ROCKCHIP || COMPILE_TEST) && OF
+   depends on COMMON_CLK
select GENERIC_PHY
help
  Support for Rockchip USB2.0 PHY with Innosilicon IP block.
-- 
1.7.9.5


--
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 0/1] add COMMON_CLK dependency for rockchip-inno-usb2

2016-08-15 Thread Frank Wang
On kernel builds without COMMON_CLK, the newly added rockchip-inno-usb2 driver
fails to build, and this adds the required Kconfig dependency to fix it.

Frank Wang (1):
  phy: rockchip-inno-usb2: add COMMON_CLK dependency

 drivers/phy/Kconfig |1 +
 1 file changed, 1 insertion(+)

-- 
1.7.9.5


--
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 1/1] phy: rockchip-inno-usb2: add COMMON_CLK dependency

2016-08-15 Thread Frank Wang
On kernel builds without COMMON_CLK, the newly added rockchip-inno-usb2
driver fails to build:

drivers/phy/phy-rockchip-inno-usb2.c:124:16: error: field 'clk480m_hw'
has incomplete type
   struct clk_hw clk480m_hw;

In file included from include/linux/clk.h:16:0
 from drivers/phy/phy-rockchip-inno-usb2.c:17:
include/linux/kernel.h:831:48: error: initialization from incompatible
pointer type [-Werror=incompatible-pointer-types]
   const typeof( ((type *)0)->member ) *__mptr = (ptr); \

  ... ...

Signed-off-by: Frank Wang 
---
 drivers/phy/Kconfig |1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index f9bf981..c6d57e5 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -370,6 +370,7 @@ config PHY_ROCKCHIP_USB
 config PHY_ROCKCHIP_INNO_USB2
tristate "Rockchip INNO USB2PHY Driver"
depends on (ARCH_ROCKCHIP || COMPILE_TEST) && OF
+   depends on COMMON_CLK
select GENERIC_PHY
help
  Support for Rockchip USB2.0 PHY with Innosilicon IP block.
-- 
1.7.9.5


--
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] add COMMON_CLK dependency for rockchip-inno-usb2

2016-08-15 Thread Frank Wang
On kernel builds without COMMON_CLK, the newly added rockchip-inno-usb2 driver
fails to build, and this adds the required Kconfig dependency to fix it.

Frank Wang (1):
  phy: rockchip-inno-usb2: add COMMON_CLK dependency

 drivers/phy/Kconfig |1 +
 1 file changed, 1 insertion(+)

-- 
1.7.9.5


--
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] scsi: introduce a quirk for false cache reporting

2016-08-15 Thread Martin K. Petersen
> "Oliver" == Oliver Neukum  writes:

Oliver,

Oliver> wce_default_on controls the default if the device provides no
Oliver> indication. The problem here is that the indication the device
Oliver> provides must be overridden, as they are false.

Can't you just blacklist the mode select on the device in question?

Something like:

if (us->fflags & US_FL_ALWAYS_SYNC) {
sdev->skip_ms_page_3f = 1;
sdev->skip_ms_page_8 = 1;
sdev->wce_default_on = 1;
}

?

-- 
Martin K. Petersen  Oracle Linux Engineering
--
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: [lkp] [usb] ad05399d68: BUG: unable to handle kernel NULL pointer dereference at 0000000000000012

2016-08-15 Thread Ye Xiaolong
On 08/16, Peter Chen wrote:
>On Mon, Aug 15, 2016 at 10:49:55PM +0800, Ye Xiaolong wrote:
>> On 08/15, Peter Chen wrote:
>> > 
>> >>
>> >>
>> >>FYI, we noticed the following commit:
>> >>
>> >>https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next 
>> >>commit
>> >>ad05399d68b6ae1649cdcfc82ce3ffea1a7c5104 ("usb: udc: core: fix error 
>> >>handling")
>> >>
>> >
>> >Hi Xiaolong,
>> >
>> >You reported it one month ago, and said it is a false report. see below.
>> >Would you please double confirm it?
>> 
>> Hi, peter
>> 
>> Last time I reported stat "WARNING: CPU: 0 PID: 1 at
>> lib/list_debug.c:36" and it showed both in this commit and its parent,
>> this time, the observed change stat is "BUG: unable to handle kernel NULL
>> pointer dereference at 0012" and it doesn't show in parent
>> commit, however, the parent commit's dmesg would show kernel panic log
>> as:
>> 
>> [   10.338487] Kernel panic - not syncing: Attempted to kill init! 
>> exitcode=0x000b
>> [   10.338487] 
>> [   10.339911] CPU: 0 PID: 1 Comm: init Not tainted 4.8.0-rc1-00020-g0937a4d 
>> #1
>> [   10.341177] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
>> Debian-1.8.2-1 04/01/2014
>> [   10.342798]   88001e53bc28 8168cf8a 
>> 88001e534000
>> [   10.345177]  8256ef20 88001e53bcb8 88001e50ca50 
>> 88001e53bca8
>> [   10.346739]  8114e062 8810 88001e53bcb8 
>> 88001e53bc50
>> [   10.347970] Call Trace:
>> [   10.348690]  [] dump_stack+0x83/0xb9
>> [   10.351592]  [] panic+0xf3/0x2a9
>> [   10.352386]  [] do_exit+0x601/0xde0
>> [   10.352879]  [] ? __sigqueue_free+0x43/0x50
>> [   10.353511]  [] ? __dequeue_signal+0x1f7/0x210
>> [   10.354483]  [] do_group_exit+0xa2/0x100
>> [   10.355324]  [] get_signal+0x68e/0x740
>> [   10.356155]  [] do_signal+0x23/0x670
>> [   10.356983]  [] ? do_syslog+0x2c0/0x6a0
>> [   10.357832]  [] ? bad_area_nosemaphore+0x33/0x40
>> [   10.358825]  [] ? __do_page_fault+0x407/0x4d0
>> [   10.359738]  [] exit_to_usermode_loop+0x69/0xc0
>> [   10.360680]  [] prepare_exit_to_usermode+0x3d/0x70
>> [   10.361725]  [] retint_user+0x8/0x10
>> [   10.362650] Kernel Offset: disabled
>> 
>> The whole parent dmesg is attached.
>> 
>
>Then, what's the conclusion? Is this one is detect one or not?
>

It seems parent kernel lives longer than this commit, and the 
sysfs_kf_write bug shows up consistently in 3 boot tests in LKP
environment.

% compare -at ad05399d68b6ae1649cdcfc82ce3ffea1a7c5104
tests: 3
testcase/path_params/tbox_group/run: boot/1/vm-kbuild-yocto-x86_64

0937a4d787539e2f  ad05399d68b6ae1649cdcfc82c
  --
  fail:runs  %reproductionfail:runs
  | | |
 6:6 -100%:4 
kmsg.stc):gdata/new_proto/recv_or_reg_complete_cb_not_ready
 6:6 -100%:4 kmsg.fmdrv:st_unregister_failed
  :6  100%   4:4 
kmsg.list_del_corruption.prev->next_should_be#,but_was
  :6  100%   4:4 
dmesg.WARNING:at_lib/list_debug.c:#__list_del_entry
  :6  100%   4:4 dmesg.BUG:unable_to_handle_kernel
  :6  100%   4:4 dmesg.Oops
  :6  100%   4:4 dmesg.RIP:sysfs_kf_write
  :6  100%   4:4 
dmesg.Kernel_panic-not_syncing:Fatal_exception
 6:6 -100%:4 
dmesg.Kernel_panic-not_syncing:Attempted_to_kill_init!exitcode=

testcase/path_params/tbox_group/run: boot/1/vm-ivb41-yocto-ia32

0937a4d787539e2f  ad05399d68b6ae1649cdcfc82c
  --
 2:2 -100%:2 
kmsg.stc):gdata/new_proto/recv_or_reg_complete_cb_not_ready
 2:2 -100%:2 kmsg.fmdrv:st_unregister_failed
  :2  100%   2:2 dmesg.BUG:unable_to_handle_kernel
  :2  100%   2:2 dmesg.Oops
  :2  100%   2:2 dmesg.RIP:sysfs_kf_write
  :2  100%   2:2 
dmesg.Kernel_panic-not_syncing:Fatal_exception
 2:2 -100%:2 dmesg.BUG:kernel_test_hang

testcase/path_params/tbox_group/run: boot/1/vm-kbuild-1G

0937a4d787539e2f  ad05399d68b6ae1649cdcfc82c
  --
  :4  100%   4:4 
dmesg.WARNING:at_lib/list_debug.c:#__list_del_entry
  :4   75%   3:4 dmesg.BUG:unable_to_handle_kernel
  :4   75%   3:4 dmesg.Oops
  :4   75%   3:4 dmesg.RIP:sysfs_kf_write
  :4   75%   3:4 
dmesg.Kernel_panic-not_syncing:Fatal_exception
 4:4 -100%:4 
dmesg.BUG:kernel_oversize_in_test_stage


>Peter
>
>> Thanks,
>> Xiaolong
>> 
>> >
>> >On Wed, Jul 13, 2016 at 01:5

Re: [PATCH v2 3/3] usb: gadget: add f_uac1 variant based on new u_audio api

2016-08-15 Thread Peter Chen
On Sun, Aug 14, 2016 at 01:21:24AM +0300, Ruslan Bilovol wrote:
> This patch adds new function f_uac1_newapi that
> uses recently created u_audio api. This makes
> f_uac1_newapi implementation much simpler by
> reusing existing u_audio core utilities.
> 
> This also drops previous f_uac1 approach (write
> audio samples directly to existing ALSA sound
> card) and moves to more generic/flexible
> one - create an f_uac1 ALSA sound card that
> represents USB Audio function and allows to
> be used by userspace tools.
> 
> f_uac1_newapi also has capture support (gadget->host).
> By default, capture interface has 48000kHz/2ch
> configuration, same as playback channel has.
> 
> f_uac1_newapi descriptors naming conventios
> uses f_uac2 driver naming convention that
> makes it more common and meaningful.
> 
> Comparing to f_uac1, the f_uac1_newapi doesn't
> have volume/mute functionality. This is because
> the volume/mute feature unit was dummy
> implementation since that driver creation (2009)
> and never had real volume control or mute
> functionality.
> 
> g_audio can be built using one of existing
> uac functions (f_uac1, f_uac1_newapi or f_uac2)
> 
> Signed-off-by: Ruslan Bilovol 
> ---
>  .../ABI/testing/configfs-usb-gadget-uac1_newapi|  12 +
>  Documentation/usb/gadget-testing.txt   |  41 ++
>  drivers/usb/gadget/Kconfig |  21 +
>  drivers/usb/gadget/function/Makefile   |   2 +
>  drivers/usb/gadget/function/f_uac1_newapi.c| 795 
> +
>  drivers/usb/gadget/function/u_uac1_newapi.h|  39 +
>  drivers/usb/gadget/legacy/Kconfig  |  15 +-
>  drivers/usb/gadget/legacy/audio.c  |  52 ++
>  8 files changed, 975 insertions(+), 2 deletions(-)
>  create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
>  create mode 100644 drivers/usb/gadget/function/f_uac1_newapi.c
>  create mode 100644 drivers/usb/gadget/function/u_uac1_newapi.h
> 
> diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi 
> b/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
> new file mode 100644
> index 000..d355275
> --- /dev/null
> +++ b/Documentation/ABI/testing/configfs-usb-gadget-uac1_newapi
> @@ -0,0 +1,12 @@
> +What:/config/usb-gadget/gadget/functions/uac1_newapi.name
> +Date:Aug 2016
> +KernelVersion:   4.9
> +Description:
> + The attributes:
> +
> + c_chmask - capture channel mask
> + c_srate - capture sampling rate
> + c_ssize - capture sample size (bytes)
> + p_chmask - playback channel mask
> + p_srate - playback sampling rate
> + p_ssize - playback sample size (bytes)
> diff --git a/Documentation/usb/gadget-testing.txt 
> b/Documentation/usb/gadget-testing.txt
> index 5819605..4598d7f 100644
> --- a/Documentation/usb/gadget-testing.txt
> +++ b/Documentation/usb/gadget-testing.txt
> @@ -20,6 +20,7 @@ provided by gadgets.
>  17. UAC2 function
>  18. UVC function
>  19. PRINTER function
> +20. UAC1 function (new API)
>  
>  
>  1. ACM function
> @@ -770,3 +771,43 @@ host:
>  
>  More advanced testing can be done with the prn_example
>  described in Documentation/usb/gadget-printer.txt.
> +
> +
> +20. UAC1 function (new API, using u_audio)
> +=
> +
> +The function is provided by usb_f_uac1_newapi.ko module.
> +
> +Function-specific configfs interface
> +
> +
> +The function name to use when creating the function directory
> +is "uac1_newapi". The uac1_newapi function provides these attributes
> +in its function directory:
> +
> + c_chmask - capture channel mask
> + c_srate - capture sampling rate
> + c_ssize - capture sample size (bytes)
> + p_chmask - playback channel mask
> + p_srate - playback sampling rate
> + p_ssize - playback sample size (bytes)
> +
> +The attributes have sane default values.
> +
> +Testing the UAC1 function
> +-
> +
> +device: run the gadget
> +host: aplay -l # should list our USB Audio Gadget
> +
> +This function does not require real hardware support, it just
> +sends a stream of audio data to/from the host. In order to
> +actually hear something at the device side, a command similar
> +to this must be used at the device side:
> +
> +$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 &
> +
> +e.g.:
> +
> +$ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \
> +aplay -D default:CARD=OdroidU3
> diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig
> index a25afd8..abcb539 100644
> --- a/drivers/usb/gadget/Kconfig
> +++ b/drivers/usb/gadget/Kconfig
> @@ -194,6 +194,9 @@ config USB_F_FS
>  config USB_F_UAC1
>   tristate
>  
> +config USB_F_UAC1_NEWAPI
> + tristate
> +
>  config USB_F_UAC2
>   tristate
>  
> @@ -397,6 +400,24 @@ config USB_CONFIGFS_F_UAC1
> This driver requires a real Audio codec to 

Re: [PATCH 1/2] usb: dwc2: optionally assert phy "full reset" when waking up

2016-08-15 Thread John Youn
On 8/15/2016 6:11 PM, Randy Li wrote:
> 
> 
> On 08/16/2016 06:19 AM, John Youn wrote:
>> On 7/19/2016 5:06 AM, Randy Li wrote:
>>> From: Doug Anderson 
>>>
>>> On the rk3288 USB host-only port (the one that's not the OTG-enabled
>>> port) the PHY can get into a bad state when a wakeup is asserted (not
>>> just a wakeup from full system suspend but also a wakeup from
>>> autosuspend). The problem is caused by a design fault in IC, Rockchip
>>> have confirmed it and fix this problem in the future IC model.
>>>
>>> We can get the PHY out of its bad state by asserting its "port reset",
>>> but unfortunately that seems to assert a reset onto the USB bus so it
>>> could confuse things if we don't actually deenumerate / reenumerate the
>>> device.
>>>
>>> We can also get the PHY out of its bad state by fully resetting it using
>>> the reset from the CRU (clock reset unit), which does a more full
>>> reset.  The CRU-based reset appears to actually cause devices on the bus
>>> to be removed and reinserted, which fixes the problem (albeit in a hacky
>>> way).
>>>
>>> It's unfortunate that we need to do a full re-enumeration of devices at
>>> wakeup time, but this is better than alternative of letting the bus get
>>> wedged.
>>>
>>> Signed-off-by: Douglas Anderson 
>>> Signed-off-by: Yunzhi Li 
>>> Reviewed-by: Randy Li 
>>> ---
>>>  Documentation/devicetree/bindings/usb/dwc2.txt |  7 +++
>>>  drivers/usb/dwc2/core.h|  5 +
>>>  drivers/usb/dwc2/core_intr.c   | 14 ++
>>>  drivers/usb/dwc2/platform.c| 13 +
>>>  4 files changed, 39 insertions(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
>>> b/Documentation/devicetree/bindings/usb/dwc2.txt
>>> index 20a68bf..40c63ae 100644
>>> --- a/Documentation/devicetree/bindings/usb/dwc2.txt
>>> +++ b/Documentation/devicetree/bindings/usb/dwc2.txt
>>> @@ -20,6 +20,13 @@ Refer to clk/clock-bindings.txt for generic clock 
>>> consumer properties
>>>  Optional properties:
>>>  - phys: phy provider specifier
>>>  - phy-names: shall be "usb2-phy"
>>> +- snps,need-phy-full-reset-on-wake: if present indicates that we need to 
>>> reset
>>> +  the PHY when we detect a wakeup due to a hardware errata.  If present you
>>> +  must specify a "phy-full-reset" reset.
>>> +
>>> +Resets:
>>> +- phy-full-reset (optional): Fully resets the PHY (Only used by rk3288 
>>> Soc).
>>> +
>>>  Refer to phy/phy-bindings.txt for generic phy consumer properties
>>>  - dr_mode: shall be one of "host", "peripheral" and "otg"
>>>Refer to usb/generic.txt
>>> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
>>> index dec0b21..951abe0 100644
>>> --- a/drivers/usb/dwc2/core.h
>>> +++ b/drivers/usb/dwc2/core.h
>>> @@ -719,8 +719,11 @@ struct dwc2_hregs_backup {
>>>   * @hcd_enabledHost mode sub-driver initialization indicator.
>>>   * @gadget_enabled Peripheral mode sub-driver initialization indicator.
>>>   * @ll_hw_enabled  Status of low-level hardware resources.
>>> + * @need_phy_full_reset_on_wake: Quirk saying that we should assert
>>> + *   phy_full_reset on a remote wakeup.
>>>   * @phy:The otg phy transceiver structure for phy control.
>>>   * @uphy:   The otg phy transceiver structure for old USB phy 
>>> control.
>>> + * @phy_full_reset: Reset control for the PHY's "full reset".
>>>   * @plat:   The platform specific configuration data. This can 
>>> be removed once
>>>   *  all SoCs support usb transceiver.
>>>   * @supplies:   Definition of USB power supplies
>>> @@ -853,9 +856,11 @@ struct dwc2_hsotg {
>>> unsigned int hcd_enabled:1;
>>> unsigned int gadget_enabled:1;
>>> unsigned int ll_hw_enabled:1;
>>> +   unsigned int need_phy_full_reset_on_wake:1;
>>>
>>> struct phy *phy;
>>> struct usb_phy *uphy;
>>> +   struct reset_control *phy_full_reset;
>>> struct dwc2_hsotg_plat *plat;
>>> struct regulator_bulk_data 
>>> supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
>>> u32 phyif;
>>> diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
>>> index d85c5c9..53d8327 100644
>>> --- a/drivers/usb/dwc2/core_intr.c
>>> +++ b/drivers/usb/dwc2/core_intr.c
>>> @@ -45,6 +45,7 @@
>>>  #include 
>>>  #include 
>>>  #include 
>>> +#include 
>>>  #include 
>>>
>>>  #include 
>>> @@ -379,6 +380,19 @@ static void dwc2_handle_wakeup_detected_intr(struct 
>>> dwc2_hsotg *hsotg)
>>> /* Restart the Phy Clock */
>>> pcgcctl &= ~PCGCTL_STOPPCLK;
>>> dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
>>> +
>>> +   /*
>>> +* If we've got this quirk then the PHY is stuck upon
>>> +* wakeup.  Assert reset.  This will propagate out and
>>> +* eventually we'll re-enumerate the device.  Not great
>>> +

Re: [PATCH] usb: chipidea: host: disable io watchdog

2016-08-15 Thread Peter Chen
On Mon, Aug 15, 2016 at 04:09:07PM +0200, Lucas Stach wrote:
> The Chipidea EHCI core seems to behave sanely and doesn't need
> the IO watchdog. This kills off 10 non-deferrable wakeup events
> per second when the controller is otherwise idle.
> 
> Signed-off-by: Lucas Stach 
> Tested-by: Stefan Agner 
> ---
>  drivers/usb/chipidea/host.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
> index 053bac9d983c..96ae69502c86 100644
> --- a/drivers/usb/chipidea/host.c
> +++ b/drivers/usb/chipidea/host.c
> @@ -81,12 +81,15 @@ static int ehci_ci_reset(struct usb_hcd *hcd)
>  {
>   struct device *dev = hcd->self.controller;
>   struct ci_hdrc *ci = dev_get_drvdata(dev);
> + struct ehci_hcd *ehci = hcd_to_ehci(hcd);
>   int ret;
>  
>   ret = ehci_setup(hcd);
>   if (ret)
>   return ret;
>  
> + ehci->need_io_watchdog = 0;
> +
>   ci_platform_configure(ci);
>  
>   return ret;
> -- 
> 2.8.1
> 

I will test it

-- 

Best Regards,
Peter Chen
--
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: [lkp] [usb] ad05399d68: BUG: unable to handle kernel NULL pointer dereference at 0000000000000012

2016-08-15 Thread Peter Chen
On Mon, Aug 15, 2016 at 10:49:55PM +0800, Ye Xiaolong wrote:
> On 08/15, Peter Chen wrote:
> > 
> >>
> >>
> >>FYI, we noticed the following commit:
> >>
> >>https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next 
> >>commit
> >>ad05399d68b6ae1649cdcfc82ce3ffea1a7c5104 ("usb: udc: core: fix error 
> >>handling")
> >>
> >
> >Hi Xiaolong,
> >
> >You reported it one month ago, and said it is a false report. see below.
> >Would you please double confirm it?
> 
> Hi, peter
> 
> Last time I reported stat "WARNING: CPU: 0 PID: 1 at
> lib/list_debug.c:36" and it showed both in this commit and its parent,
> this time, the observed change stat is "BUG: unable to handle kernel NULL
> pointer dereference at 0012" and it doesn't show in parent
> commit, however, the parent commit's dmesg would show kernel panic log
> as:
> 
> [   10.338487] Kernel panic - not syncing: Attempted to kill init! 
> exitcode=0x000b
> [   10.338487] 
> [   10.339911] CPU: 0 PID: 1 Comm: init Not tainted 4.8.0-rc1-00020-g0937a4d 
> #1
> [   10.341177] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
> Debian-1.8.2-1 04/01/2014
> [   10.342798]   88001e53bc28 8168cf8a 
> 88001e534000
> [   10.345177]  8256ef20 88001e53bcb8 88001e50ca50 
> 88001e53bca8
> [   10.346739]  8114e062 8810 88001e53bcb8 
> 88001e53bc50
> [   10.347970] Call Trace:
> [   10.348690]  [] dump_stack+0x83/0xb9
> [   10.351592]  [] panic+0xf3/0x2a9
> [   10.352386]  [] do_exit+0x601/0xde0
> [   10.352879]  [] ? __sigqueue_free+0x43/0x50
> [   10.353511]  [] ? __dequeue_signal+0x1f7/0x210
> [   10.354483]  [] do_group_exit+0xa2/0x100
> [   10.355324]  [] get_signal+0x68e/0x740
> [   10.356155]  [] do_signal+0x23/0x670
> [   10.356983]  [] ? do_syslog+0x2c0/0x6a0
> [   10.357832]  [] ? bad_area_nosemaphore+0x33/0x40
> [   10.358825]  [] ? __do_page_fault+0x407/0x4d0
> [   10.359738]  [] exit_to_usermode_loop+0x69/0xc0
> [   10.360680]  [] prepare_exit_to_usermode+0x3d/0x70
> [   10.361725]  [] retint_user+0x8/0x10
> [   10.362650] Kernel Offset: disabled
> 
> The whole parent dmesg is attached.
> 

Then, what's the conclusion? Is this one is detect one or not?

Peter

> Thanks,
> Xiaolong
> 
> >
> >On Wed, Jul 13, 2016 at 01:55:26AM +, Peter Chen wrote:
> >> 
> >>
> >>>-Original Message-
> >>>From: lkp-requ...@eclists.intel.com 
> >>>[mailto:lkp-requ...@eclists.intel.com] On Behalf Of kernel test robot
> >>>Sent: Wednesday, July 13, 2016 9:28 AM
> >>>To: Peter Chen 
> >>>Cc: 0day robot ; LKML 
> >>>; l...@01.org
> >>>Subject: [lkp] [usb] 9696ef14de: WARNING: CPU: 0 PID: 1 at 
> >>>lib/list_debug.c:36
> >>>__list_add+0x104/0x188
> >>>
> >>>
> >>>FYI, we noticed the following commit:
> >>>
> >>>https://github.com/0day-ci/linux Peter-Chen/usb-udc-core-fix-error-
> >>>handling/20160711-100832
> >>>commit 9696ef14ded07fb0847f8e1cdda6d98a89ecd4f2 ("usb: udc: core: fix 
> >>>error
> >>>handling")
> >>>
> >>
> >>Thanks,  but I really can't find the relationship between my patch and dump.
> >>Can you reproduce it after running again or without my patch?
> >>
> >
> >Sorry, it's a false report, the error dump also showed in parent commit, 
> >please ignore the report and sorry for the noise.
> >
> >Thanks,
> >Xiaolong
> >
> >
> >
> >
> >Peter
> >
> >>in testcase: boot
> >>
> >>on test machine: 1 threads qemu-system-x86_64 -enable-kvm -cpu SandyBridge
> >>with 512M memory
> >>
> >>caused below changes:
> >>
> >>
> >>+---+++
> >>|   | 0937a4d787
> >>| | ad05399d68 |
> >>+---+++
> >>| boot_successes| 0  | 
> >>0  |
> >>| boot_failures | 12 | 
> >>12 |
> >>| WARNING:at_lib/list_debug.c:#__list_del_entry | 2  | 
> >>12 |
> >>| BUG:kernel_test_hang  | 2  |  
> >>  |
> >>| backtrace:kernel_restart  | 2  |  
> >>  |
> >>| backtrace:SyS_reboot  | 2  |  
> >>  |
> >>| BUG:kernel_oversize_in_test_stage | 4  |  
> >>  |
> >>| Kernel_panic-not_syncing:Attempted_to_kill_init!exitcode= | 6  |  
> >>  |
> >>| BUG:unable_to_handle_kernel   | 0  | 
> >>11 |
> >>| Oops  | 0  | 
> >>11 |
> >>| RIP:sysfs_kf_write| 0  | 
> >>11 |
> >>| Kernel_panic-not_syncing:Fatal_exception  | 0  | 
> >>11 |
> >>| backtrace:serio

Re: [PATCH] USB: core: of: Check device_node before parsing in usb_of_get_child_node()

2016-08-15 Thread Peter Chen
On Mon, Aug 15, 2016 at 11:31:10AM -0700, Vaibhav Hiremath wrote:
> In case of HUB devices connected to USB ports, we may not have DT
> node representing it inside USB, and when devices connected to hub
> gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
> dereference.
> 
> In the usecase we have, where EHCI port is connected to USB HUB
> device, and downward ports of HUB are connected to further USB
> devices. When those devices gets enumerated, in order,
>  1. USB HUB ->
>   -> Call to usb_of_get_child_node() is OK, as
>   parent->dev.of_node is pointing to host node.
>  2. Devices connected to downward port of USB HUB
>   -> Call to usb_of_get_child_node() leads to NULL
>   pointer dereference as parent->dev.of_node = NULL,
>   as USB HUB DTS node may be empty.
> 
> Fix this NULL pointer dereference by adding check for pointer
> device_node inside usb_of_get_child_node() fn.
> 
> Signed-off-by: Vaibhav Hiremath 
> ---
> Testing: I have build tested it against mainline.
> 
>  drivers/usb/core/of.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index 2289700..dc667a3 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -34,6 +34,9 @@ struct device_node *usb_of_get_child_node(struct 
> device_node *parent,
>   struct device_node *node;
>   u32 port;
>  
> + if (!parent)
> + return NULL;
> +
>   for_each_child_of_node(parent, node) {
>   if (!of_property_read_u32(node, "reg", &port)) {
>   if (port == portnum)

I am afraid I can't reproduce it, would you please show me your dump
when null pointer dereference occurs? From what I find the
__of_get_next_child checks null pointer for parent node.

-- 

Best Regards,
Peter Chen
--
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 RFC 1/6] usb: dwc2: core: Avoid nonsense error in gadget mode

2016-08-15 Thread John Youn
On 7/26/2016 11:54 AM, Stefan Wahren wrote:
> In gadget mode On bcm2835 platform the host tx fifo size could be zero.
> So add zero to range and avoid such nonsense errors:
> 
> dwc2 2098.usb: 0 invalid for host_nperio_tx_fifo_size.
> dwc2 2098.usb: Setting host_nperio_tx_fifo_size to 0
> dwc2 2098.usb: 0 invalid for host_perio_tx_fifo_size.
> dwc2 2098.usb: Setting host_perio_tx_fifo_size to 0

Hi Stefan,

Are those the power on reset values of GNPTXFSIZ and HPTXFSIZ?

If these values can be 0, I think the patch is ok. But I'm not sure
about that. I can check with some hardware engineers to see under what
conditions this is possible.

Regards,
John


> 
> Signed-off-by: Stefan Wahren 
> ---
>  drivers/usb/dwc2/core.c |   10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index 4135a5f..5645528 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -819,7 +819,10 @@ void dwc2_set_param_host_nperio_tx_fifo_size(struct 
> dwc2_hsotg *hsotg, int val)
>  {
>   int valid = 1;
>  
> - if (val < 16 || val > hsotg->hw_params.host_nperio_tx_fifo_size)
> + if (val && (val < 16))
> + valid = 0;
> +
> + if (val > hsotg->hw_params.host_nperio_tx_fifo_size)
>   valid = 0;
>  
>   if (!valid) {
> @@ -839,7 +842,10 @@ void dwc2_set_param_host_perio_tx_fifo_size(struct 
> dwc2_hsotg *hsotg, int val)
>  {
>   int valid = 1;
>  
> - if (val < 16 || val > hsotg->hw_params.host_perio_tx_fifo_size)
> + if (val && (val < 16))
> + valid = 0;
> +
> + if (val > hsotg->hw_params.host_perio_tx_fifo_size)
>   valid = 0;
>  
>   if (!valid) {
> 
--
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: Kconfig: move ulpi bus to common

2016-08-15 Thread Peter Chen
On Mon, Aug 15, 2016 at 04:07:14PM +0300, Heikki Krogerus wrote:
> Hi,
> 
> On Fri, Jul 08, 2016 at 04:15:23PM +0800, Peter Chen wrote:
> > The ULPI bus is not only for host, but for device mode too, so move
> > it out from host's Kconfig.
> > 
> > Cc: Heikki Krogerus 
> > Signed-off-by: Peter Chen 
> > ---
> >  drivers/usb/common/Kconfig | 21 +
> >  drivers/usb/core/Kconfig   | 21 -
> >  2 files changed, 21 insertions(+), 21 deletions(-)
> > 
> > diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig
> > index 951b1d0..e251aec 100644
> > --- a/drivers/usb/common/Kconfig
> > +++ b/drivers/usb/common/Kconfig
> > @@ -7,3 +7,24 @@ config USB_LED_TRIG
> >   Say Y here if you are working on a system with led-class supported
> >   LEDs and you want to use them as activity indicators for USB host or
> >   gadget.
> > +
> > +config USB_ULPI_BUS
> > +   tristate "USB ULPI PHY interface support"
> > +   depends on USB_SUPPORT
> > +   help
> > + UTMI+ Low Pin Interface (ULPI) is specification for a commonly used
> > + USB 2.0 PHY interface. The ULPI specification defines a standard set
> > + of registers that can be used to detect the vendor and product which
> > + allows ULPI to be handled as a bus. This module is the driver for that
> > + bus.
> > +
> > + The ULPI interfaces (the buses) are registered by the drivers for USB
> > + controllers which support ULPI register access and have ULPI PHY
> > + attached to them. The ULPI PHY drivers themselves are normal PHY
> > + drivers.
> > +
> > + ULPI PHYs provide often functions such as ADP sensing/probing (OTG
> > + protocol) and USB charger detection.
> > +
> > + To compile this driver as a module, choose M here: the module will
> > + be called ulpi.
> > diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
> > index dd28010..d6e43ce 100644
> > --- a/drivers/usb/core/Kconfig
> > +++ b/drivers/usb/core/Kconfig
> > @@ -82,24 +82,3 @@ config USB_OTG_FSM
> > help
> >   Implements OTG Finite State Machine as specified in On-The-Go
> >   and Embedded Host Supplement to the USB Revision 2.0 Specification.
> > -
> > -config USB_ULPI_BUS
> > -   tristate "USB ULPI PHY interface support"
> > -   depends on USB_SUPPORT
> 
> This patch does not apply. The above line has been removed at one
> point.
> 
> Once you resend, please re-add the dependency once you move the config
> to drivers/usb/common/Kconfig.
> 

But Greg doesn't agree with move configurations from drivers/usb/Kconfig to 
drivers/usb/common/Kconfig, I move it to drivers/usb/Kconfig?

-- 

Best Regards,
Peter Chen
--
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: dwc2: optionally assert phy "full reset" when waking up

2016-08-15 Thread Randy Li



On 08/16/2016 06:19 AM, John Youn wrote:

On 7/19/2016 5:06 AM, Randy Li wrote:

From: Doug Anderson 

On the rk3288 USB host-only port (the one that's not the OTG-enabled
port) the PHY can get into a bad state when a wakeup is asserted (not
just a wakeup from full system suspend but also a wakeup from
autosuspend). The problem is caused by a design fault in IC, Rockchip
have confirmed it and fix this problem in the future IC model.

We can get the PHY out of its bad state by asserting its "port reset",
but unfortunately that seems to assert a reset onto the USB bus so it
could confuse things if we don't actually deenumerate / reenumerate the
device.

We can also get the PHY out of its bad state by fully resetting it using
the reset from the CRU (clock reset unit), which does a more full
reset.  The CRU-based reset appears to actually cause devices on the bus
to be removed and reinserted, which fixes the problem (albeit in a hacky
way).

It's unfortunate that we need to do a full re-enumeration of devices at
wakeup time, but this is better than alternative of letting the bus get
wedged.

Signed-off-by: Douglas Anderson 
Signed-off-by: Yunzhi Li 
Reviewed-by: Randy Li 
---
 Documentation/devicetree/bindings/usb/dwc2.txt |  7 +++
 drivers/usb/dwc2/core.h|  5 +
 drivers/usb/dwc2/core_intr.c   | 14 ++
 drivers/usb/dwc2/platform.c| 13 +
 4 files changed, 39 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index 20a68bf..40c63ae 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -20,6 +20,13 @@ Refer to clk/clock-bindings.txt for generic clock consumer 
properties
 Optional properties:
 - phys: phy provider specifier
 - phy-names: shall be "usb2-phy"
+- snps,need-phy-full-reset-on-wake: if present indicates that we need to reset
+  the PHY when we detect a wakeup due to a hardware errata.  If present you
+  must specify a "phy-full-reset" reset.
+
+Resets:
+- phy-full-reset (optional): Fully resets the PHY (Only used by rk3288 Soc).
+
 Refer to phy/phy-bindings.txt for generic phy consumer properties
 - dr_mode: shall be one of "host", "peripheral" and "otg"
   Refer to usb/generic.txt
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index dec0b21..951abe0 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -719,8 +719,11 @@ struct dwc2_hregs_backup {
  * @hcd_enabledHost mode sub-driver initialization indicator.
  * @gadget_enabled Peripheral mode sub-driver initialization indicator.
  * @ll_hw_enabled  Status of low-level hardware resources.
+ * @need_phy_full_reset_on_wake: Quirk saying that we should assert
+ *   phy_full_reset on a remote wakeup.
  * @phy:The otg phy transceiver structure for phy control.
  * @uphy:   The otg phy transceiver structure for old USB phy 
control.
+ * @phy_full_reset: Reset control for the PHY's "full reset".
  * @plat:   The platform specific configuration data. This can be 
removed once
  *  all SoCs support usb transceiver.
  * @supplies:   Definition of USB power supplies
@@ -853,9 +856,11 @@ struct dwc2_hsotg {
unsigned int hcd_enabled:1;
unsigned int gadget_enabled:1;
unsigned int ll_hw_enabled:1;
+   unsigned int need_phy_full_reset_on_wake:1;

struct phy *phy;
struct usb_phy *uphy;
+   struct reset_control *phy_full_reset;
struct dwc2_hsotg_plat *plat;
struct regulator_bulk_data 
supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
u32 phyif;
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index d85c5c9..53d8327 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -45,6 +45,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 

 #include 
@@ -379,6 +380,19 @@ static void dwc2_handle_wakeup_detected_intr(struct 
dwc2_hsotg *hsotg)
/* Restart the Phy Clock */
pcgcctl &= ~PCGCTL_STOPPCLK;
dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
+
+   /*
+* If we've got this quirk then the PHY is stuck upon
+* wakeup.  Assert reset.  This will propagate out and
+* eventually we'll re-enumerate the device.  Not great
+* but the best we can do.
+*/
+   if (hsotg->need_phy_full_reset_on_wake) {
+   reset_control_assert(hsotg->phy_full_reset);
+   udelay(50);
+   reset_control_deassert(hsotg->phy_full_reset);
+   }
+
mod_timer(&hso

Re: [PATCH] whci: Remove deprecated create_singlethread_workqueue

2016-08-15 Thread Tejun Heo
On Sat, Aug 13, 2016 at 09:20:40PM +0530, Bhaktipriya Shridhar wrote:
> alloc_ordered_workqueue replaces the deprecated
> create_singlethread_workqueue.
> 
> The workqueue "workqueue" has multiple workitems which may require
> ordering. Hence, a dedicated ordered workqueue has been used.
> Since the workqueue is not being used on a memory reclaim path,
> WQ_MEM_RECLAIM has not been set.
> 
> Signed-off-by: Bhaktipriya Shridhar 

Acked-by: Tejun Heo 

Thanks.

-- 
tejun
--
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 reset control to dwc2

2016-08-15 Thread John Youn
Hi Felipe,

On 8/10/2016 6:53 AM, Dinh Nguyen wrote:
> From: Dinh Nguyen 
> 
> Allow for platforms that have a reset controller driver in place to bring
> the USB IP out of reset.
> 
> Signed-off-by: Dinh Nguyen 
> Acked-by: John Youn 
> Tested-by: Stefan Wahren 
> ---
> Hi Felipe,
> 
> Can you please take this patch through your USB tree? This patch was dependent
> on "168d7c4e8bb2 reset: Return -ENOTSUPP when not configured" and is now in
> v3.8-rc1.
> 
> The discussion is highlight here:
> 
> https://lkml.org/lkml/2016/7/7/291
> 
> Thanks,
> Dinh
> ---
> v7: Use devm_reset_control_get_optional()
> v6: fix 80 line checkpatch warning in dev_err print
> v5: updated error conditions for not finding the reset property
> v4: use dev_dbg() if not a -EPROBE_DEFER
> v3: fix compile error
> v2: move to lowlevel_hw_init()
> ---
>  drivers/usb/dwc2/core.h |  1 +
>  drivers/usb/dwc2/platform.c | 22 ++
>  2 files changed, 23 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index 9fae029..d645512 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -868,6 +868,7 @@ struct dwc2_hsotg {
>   void *priv;
>   int irq;
>   struct clk *clk;
> + struct reset_control *reset;
>  
>   unsigned int queuing_high_bandwidth:1;
>   unsigned int srp_success:1;
> diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
> index fc6f525..530959a 100644
> --- a/drivers/usb/dwc2/platform.c
> +++ b/drivers/usb/dwc2/platform.c
> @@ -45,6 +45,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include 
>  
> @@ -337,6 +338,24 @@ static int dwc2_lowlevel_hw_init(struct dwc2_hsotg 
> *hsotg)
>  {
>   int i, ret;
>  
> + hsotg->reset = devm_reset_control_get_optional(hsotg->dev, "dwc2");
> + if (IS_ERR(hsotg->reset)) {
> + ret = PTR_ERR(hsotg->reset);
> + switch (ret) {
> + case -ENOENT:
> + case -ENOTSUPP:
> + hsotg->reset = NULL;
> + break;
> + default:
> + dev_err(hsotg->dev, "error getting reset control %d\n",
> + ret);
> + return ret;
> + }
> + }
> +
> + if (hsotg->reset)
> + reset_control_deassert(hsotg->reset);
> +
>   /* Set default UTMI width */
>   hsotg->phyif = GUSBCFG_PHYIF16;
>  
> @@ -434,6 +453,9 @@ static int dwc2_driver_remove(struct platform_device *dev)
>   if (hsotg->ll_hw_enabled)
>   dwc2_lowlevel_hw_disable(hsotg);
>  
> + if (hsotg->reset)
> + reset_control_assert(hsotg->reset);
> +
>   return 0;
>  }
>  
> 

Can you take this for 4.8-rc? All the dependencies are in place now.

Thanks,
John
--
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: dwc2: optionally assert phy "full reset" when waking up

2016-08-15 Thread John Youn
On 7/19/2016 5:06 AM, Randy Li wrote:
> From: Doug Anderson 
> 
> On the rk3288 USB host-only port (the one that's not the OTG-enabled
> port) the PHY can get into a bad state when a wakeup is asserted (not
> just a wakeup from full system suspend but also a wakeup from
> autosuspend). The problem is caused by a design fault in IC, Rockchip
> have confirmed it and fix this problem in the future IC model.
> 
> We can get the PHY out of its bad state by asserting its "port reset",
> but unfortunately that seems to assert a reset onto the USB bus so it
> could confuse things if we don't actually deenumerate / reenumerate the
> device.
> 
> We can also get the PHY out of its bad state by fully resetting it using
> the reset from the CRU (clock reset unit), which does a more full
> reset.  The CRU-based reset appears to actually cause devices on the bus
> to be removed and reinserted, which fixes the problem (albeit in a hacky
> way).
> 
> It's unfortunate that we need to do a full re-enumeration of devices at
> wakeup time, but this is better than alternative of letting the bus get
> wedged.
> 
> Signed-off-by: Douglas Anderson 
> Signed-off-by: Yunzhi Li 
> Reviewed-by: Randy Li 
> ---
>  Documentation/devicetree/bindings/usb/dwc2.txt |  7 +++
>  drivers/usb/dwc2/core.h|  5 +
>  drivers/usb/dwc2/core_intr.c   | 14 ++
>  drivers/usb/dwc2/platform.c| 13 +
>  4 files changed, 39 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
> b/Documentation/devicetree/bindings/usb/dwc2.txt
> index 20a68bf..40c63ae 100644
> --- a/Documentation/devicetree/bindings/usb/dwc2.txt
> +++ b/Documentation/devicetree/bindings/usb/dwc2.txt
> @@ -20,6 +20,13 @@ Refer to clk/clock-bindings.txt for generic clock consumer 
> properties
>  Optional properties:
>  - phys: phy provider specifier
>  - phy-names: shall be "usb2-phy"
> +- snps,need-phy-full-reset-on-wake: if present indicates that we need to 
> reset
> +  the PHY when we detect a wakeup due to a hardware errata.  If present you
> +  must specify a "phy-full-reset" reset.
> +
> +Resets:
> +- phy-full-reset (optional): Fully resets the PHY (Only used by rk3288 Soc).
> +
>  Refer to phy/phy-bindings.txt for generic phy consumer properties
>  - dr_mode: shall be one of "host", "peripheral" and "otg"
>Refer to usb/generic.txt
> diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
> index dec0b21..951abe0 100644
> --- a/drivers/usb/dwc2/core.h
> +++ b/drivers/usb/dwc2/core.h
> @@ -719,8 +719,11 @@ struct dwc2_hregs_backup {
>   * @hcd_enabled  Host mode sub-driver initialization indicator.
>   * @gadget_enabled   Peripheral mode sub-driver initialization indicator.
>   * @ll_hw_enabledStatus of low-level hardware resources.
> + * @need_phy_full_reset_on_wake: Quirk saying that we should assert
> + *   phy_full_reset on a remote wakeup.
>   * @phy:The otg phy transceiver structure for phy control.
>   * @uphy:   The otg phy transceiver structure for old USB phy 
> control.
> + * @phy_full_reset: Reset control for the PHY's "full reset".
>   * @plat:   The platform specific configuration data. This can 
> be removed once
>   *  all SoCs support usb transceiver.
>   * @supplies:   Definition of USB power supplies
> @@ -853,9 +856,11 @@ struct dwc2_hsotg {
>   unsigned int hcd_enabled:1;
>   unsigned int gadget_enabled:1;
>   unsigned int ll_hw_enabled:1;
> + unsigned int need_phy_full_reset_on_wake:1;
>  
>   struct phy *phy;
>   struct usb_phy *uphy;
> + struct reset_control *phy_full_reset;
>   struct dwc2_hsotg_plat *plat;
>   struct regulator_bulk_data 
> supplies[ARRAY_SIZE(dwc2_hsotg_supply_names)];
>   u32 phyif;
> diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
> index d85c5c9..53d8327 100644
> --- a/drivers/usb/dwc2/core_intr.c
> +++ b/drivers/usb/dwc2/core_intr.c
> @@ -45,6 +45,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  
>  #include 
> @@ -379,6 +380,19 @@ static void dwc2_handle_wakeup_detected_intr(struct 
> dwc2_hsotg *hsotg)
>   /* Restart the Phy Clock */
>   pcgcctl &= ~PCGCTL_STOPPCLK;
>   dwc2_writel(pcgcctl, hsotg->regs + PCGCTL);
> +
> + /*
> +  * If we've got this quirk then the PHY is stuck upon
> +  * wakeup.  Assert reset.  This will propagate out and
> +  * eventually we'll re-enumerate the device.  Not great
> +  * but the best we can do.
> +  */
> + if (hsotg->need_phy_full_reset_on_wake) {
> + reset_control_assert(hsotg->phy_full_reset);
> + udelay(50);
> +   

Re: How can I tell who created my usb0 network device?

2016-08-15 Thread Patrick Doyle
On Mon, Aug 15, 2016 at 5:02 PM, Greg KH  wrote:
> ls -l /sys/class/net/usb0/device/driver
>
> sysfs is fun :)
Yes it is... I also managed to find
/sys/devices/pci:00/:00:11.0/dwc3-device.1/gadget/net/usb0
with

$ find /sys -name usb0 -prune

Apparently, usb0 gets created because my system loads the g_multi
gadget.  But when I plug a hub into the USB port, (to which  a cdc_eem
device is attached), the driver configures itself as a host,
enumerates my device, and sets up usb1.  Poking around the kernel
configuration, I see that "DWC3 Mode selection" is set to "Gadget only
mode".  I am guessing that "Gadget only mode" means something
different than I would have expected, which is a good thing, because
I'm not sure I ever would have tracked that down based on the path I
was following previously.

Anyway, all is well that ends well.

Thanks for the tip.

--wpd
--
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: How can I tell who created my usb0 network device?

2016-08-15 Thread Greg KH
On Mon, Aug 15, 2016 at 03:52:10PM -0400, Patrick Doyle wrote:
> I have both usb0 and usb1 network devices.
> 
> At this point, I'm perfectly happy with my usb1 device, but, after
> having spent all of this time trying to configure usb0 correctly, I
> would like to learn what module created usb0.
> 
> How can I figure that out?

ls -l /sys/class/net/usb0/device/driver

sysfs is fun :)
--
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: musb: am3358: having performance problem with usb1

2016-08-15 Thread ayaka



On 08/13/2016 01:44 AM, Greg KH wrote:

On Sat, Aug 13, 2016 at 12:38:46AM +0800, ayaka wrote:


On 08/12/2016 03:40 PM, Greg KH wrote:

On Fri, Aug 12, 2016 at 10:23:15AM +0800, ayaka wrote:

Hello all:
I recently add a support for customize am3358 board using the branch
processor-sdk-linux-03.00.00 from Ti git. But I meet a problem with musb
at the peripheral mode.

Then you are going to have to get support from TI for this, nothing we
can do here about random vendor kernel trees, sorry.

If you can use the 4.7 tree, or better yet, the 4.8-rc tree, then we

I have tried the 4.8-rc1, I meet the same problem.

What problem is that exactly?

OK, I would said it is a performance problem.
First it can't work with DMA
brd: module loaded
loop: module loaded
ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
ehci-platform: EHCI generic platform driver
ehci-omap: OMAP-EHCI Host Controller driver
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
musb-hdrc musb-hdrc.0.auto: Failed to request rx1.
musb-hdrc musb-hdrc.0.auto: musb_init_controller failed with status -517
i2c /dev entries driver
omap_wdt: OMAP Watchdog Timer Rev 0x01: initial timeout 60 sec
sdhci: Secure Digital Host Controller Interface driver


Second, the USB1 is always work on usb 2.0 full speed when I used it as 
a gadget device.

But it should support high speed mode.




I have enabled the CONFIG_OMAP_USB2, I don't find at ti's kernel.

I don't understand, is that your hardware you are using?

thanks,

greg k-h


Here is the usb part of dts I wrote, should I give you a full dts?
&usb {
status = "okay";
};

&usb_ctrl_mod {
status = "okay";
};

&usb1_phy {
vcc-supply = <&v33_reg>;
status = "okay";
};

&usb1 {
status = "okay";
dr_mode = "peripheral";
};

&cppi41dma  {
status = "okay";
};


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


How can I tell who created my usb0 network device?

2016-08-15 Thread Patrick Doyle
I have both usb0 and usb1 network devices.

At this point, I'm perfectly happy with my usb1 device, but, after
having spent all of this time trying to configure usb0 correctly, I
would like to learn what module created usb0.

How can I figure that out?

--wpd
--
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: dwc3: gadget: don't rely on jiffies while holding spinlock

2016-08-15 Thread Nicolas Saenz Julienne
__dwc3_gadget_wakeup() is called while holding a spinlock, then depends on
jiffies in order to timeout while polling the USB core for a link state
update. In the case the wakeup failed, the timeout will never happen and
will also cause the cpu to stall until rcu_preempt kicks in.

This switches to a "decrement variable and wait" timeout scheme.

Signed-off-by: Nicolas Saenz Julienne 
---
 drivers/usb/dwc3/gadget.c | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 8f8c215..d0c711f 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1433,7 +1433,7 @@ static int dwc3_gadget_get_frame(struct usb_gadget *g)
 
 static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
 {
-   unsigned long   timeout;
+   int retries;
 
int ret;
u32 reg;
@@ -1484,14 +1484,16 @@ static int __dwc3_gadget_wakeup(struct dwc3 *dwc)
}
 
/* poll until Link State changes to ON */
-   timeout = jiffies + msecs_to_jiffies(100);
+   retries = 2;
 
-   while (!time_after(jiffies, timeout)) {
+   while (retries--) {
reg = dwc3_readl(dwc->regs, DWC3_DSTS);
 
/* in HS, means ON */
if (DWC3_DSTS_USBLNKST(reg) == DWC3_LINK_STATE_U0)
break;
+
+   udelay(5);
}
 
if (DWC3_DSTS_USBLNKST(reg) != DWC3_LINK_STATE_U0) {
-- 
2.7.4

--
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: core: of: Check device_node before parsing in usb_of_get_child_node()

2016-08-15 Thread Alan Stern
On Mon, 15 Aug 2016, Greg KH wrote:

> On Mon, Aug 15, 2016 at 11:31:10AM -0700, Vaibhav Hiremath wrote:
> > In case of HUB devices connected to USB ports, we may not have DT
> > node representing it inside USB, and when devices connected to hub
> > gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
> > dereference.
> 
> Really?  That seems messed up.
> 
> > In the usecase we have, where EHCI port is connected to USB HUB
> > device, and downward ports of HUB are connected to further USB
> > devices. When those devices gets enumerated, in order,
> >  1. USB HUB ->
> > -> Call to usb_of_get_child_node() is OK, as
> > parent->dev.of_node is pointing to host node.
> >  2. Devices connected to downward port of USB HUB
> > -> Call to usb_of_get_child_node() leads to NULL
> > pointer dereference as parent->dev.of_node = NULL,
> > as USB HUB DTS node may be empty.
> 
> Why is the hub DTS empty?  Shouldn't that be the fix here?

It's empty because there's no DT entry for the hub.  That's normal; 
most USB devices aren't represented in DT because they aren't part of 
the original system -- they are added plugged in later.

Or, it's possible that the hub _is_ part of the original system and it 
was left out of the DT database.

Alan Stern

--
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 7/7] musb: sunxi: Add support for platform_set_mode

2016-08-15 Thread Hans de Goede
This allows run-time dr_mode switching support via the "mode" musb
sysfs attribute.

Signed-off-by: Hans de Goede 
---
 drivers/usb/musb/sunxi.c | 52 
 1 file changed, 48 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/musb/sunxi.c b/drivers/usb/musb/sunxi.c
index c6ee166..1fe7451 100644
--- a/drivers/usb/musb/sunxi.c
+++ b/drivers/usb/musb/sunxi.c
@@ -74,6 +74,7 @@
 #define SUNXI_MUSB_FL_HAS_SRAM 5
 #define SUNXI_MUSB_FL_HAS_RESET6
 #define SUNXI_MUSB_FL_NO_CONFIGDATA7
+#define SUNXI_MUSB_FL_PHY_MODE_PEND8
 
 /* Our read/write methods need access and do not get passed in a musb ref :| */
 static struct musb *sunxi_musb;
@@ -87,6 +88,7 @@ struct sunxi_glue {
struct phy  *phy;
struct platform_device  *usb_phy;
struct usb_phy  *xceiv;
+   enum phy_mode   phy_mode;
unsigned long   flags;
struct work_struct  work;
struct extcon_dev   *extcon;
@@ -140,6 +142,9 @@ static void sunxi_musb_work(struct work_struct *work)
clear_bit(SUNXI_MUSB_FL_PHY_ON, &glue->flags);
}
}
+
+   if (test_and_clear_bit(SUNXI_MUSB_FL_PHY_MODE_PEND, &glue->flags))
+   phy_set_mode(glue->phy, glue->phy_mode);
 }
 
 static void sunxi_musb_set_vbus(struct musb *musb, int is_on)
@@ -341,6 +346,41 @@ static void sunxi_musb_dma_controller_destroy(struct 
dma_controller *c)
 {
 }
 
+static int sunxi_musb_set_mode(struct musb *musb, u8 mode)
+{
+   struct sunxi_glue *glue = dev_get_drvdata(musb->controller->parent);
+   enum phy_mode new_mode;
+
+   switch (mode) {
+   case MUSB_HOST: new_mode = PHY_MODE_USB_HOST; break;
+   case MUSB_PERIPHERAL:   new_mode = PHY_MODE_USB_DEVICE; break;
+   case MUSB_OTG:  new_mode = PHY_MODE_USB_OTG; break;
+   default:
+   dev_err(musb->controller->parent,
+   "Error requested mode not supported by this kernel\n");
+   return -EINVAL;
+   }
+
+   if (glue->phy_mode == new_mode)
+   return 0;
+
+   if (musb->port_mode != MUSB_PORT_MODE_DUAL_ROLE) {
+   dev_err(musb->controller->parent,
+   "Error changing modes is only supported in dual role 
mode\n");
+   return -EINVAL;
+   }
+
+   /*
+* phy_set_mode may sleep, and we're called with a spinlock held,
+* so let sunxi_musb_work deal with it.
+*/
+   glue->phy_mode = new_mode;
+   set_bit(SUNXI_MUSB_FL_PHY_MODE_PEND, &glue->flags);
+   schedule_work(&glue->work);
+
+   return 0;
+}
+
 /*
  * sunxi musb register layout
  * 0x00 - 0x17 fifo regs, 1 long per fifo
@@ -568,6 +608,7 @@ static const struct musb_platform_ops sunxi_musb_ops = {
.writew = sunxi_musb_writew,
.dma_init   = sunxi_musb_dma_controller_create,
.dma_exit   = sunxi_musb_dma_controller_destroy,
+   .set_mode   = sunxi_musb_set_mode,
.set_vbus   = sunxi_musb_set_vbus,
.pre_root_reset_end = sunxi_musb_pre_root_reset_end,
.post_root_reset_end = sunxi_musb_post_root_reset_end,
@@ -614,21 +655,28 @@ static int sunxi_musb_probe(struct platform_device *pdev)
return -EINVAL;
}
 
+   glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
+   if (!glue)
+   return -ENOMEM;
+
memset(&pdata, 0, sizeof(pdata));
switch (usb_get_dr_mode(&pdev->dev)) {
 #if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_HOST
case USB_DR_MODE_HOST:
pdata.mode = MUSB_PORT_MODE_HOST;
+   glue->phy_mode = PHY_MODE_USB_HOST;
break;
 #endif
 #if defined CONFIG_USB_MUSB_DUAL_ROLE || defined CONFIG_USB_MUSB_GADGET
case USB_DR_MODE_PERIPHERAL:
pdata.mode = MUSB_PORT_MODE_GADGET;
+   glue->phy_mode = PHY_MODE_USB_DEVICE;
break;
 #endif
 #ifdef CONFIG_USB_MUSB_DUAL_ROLE
case USB_DR_MODE_OTG:
pdata.mode = MUSB_PORT_MODE_DUAL_ROLE;
+   glue->phy_mode = PHY_MODE_USB_OTG;
break;
 #endif
default:
@@ -638,10 +686,6 @@ static int sunxi_musb_probe(struct platform_device *pdev)
pdata.platform_ops  = &sunxi_musb_ops;
pdata.config= &sunxi_musb_hdrc_config;
 
-   glue = devm_kzalloc(&pdev->dev, sizeof(*glue), GFP_KERNEL);
-   if (!glue)
-   return -ENOMEM;
-
glue->dev = &pdev->dev;
INIT_WORK(&glue->work, sunxi_musb_work);
glue->host_nb.notifier_call = sunxi_musb_host_notifier;
-- 
2.7.4

--
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 6/7] phy-sun4i-usb: Add "allwinner,usb0-usb-a-connector" dt property

2016-08-15 Thread Hans de Goede
On some devices the musb otg controller can be used in both device and
host mode, but requires software mode switching since there is no id pin
connected. The usb0 phy code will default to device mode in this case.

On some systems usb0 is connected to a female USB-A port. It can still
be used in device mode when using software mode switching and a USB
A to A cable. To configure the controller to support both modes we must
set its "dr_mode" dt property to "otg" (*). For these setups the device
mode default is wrong, for a female USB-A port the default should be
host mode.

This commit adds support to the sun4i phy code for a new
"allwinner,usb0-usb-a-connector" dt property which can be used in dt
files to indicate this scenario and when present it changes the default
mode to host mode.

*) dr_mode = "host" is used when device mode is _never_ used. E.g.
a wifi module soldered onto the PCB is connected to the musb controller.

Signed-off-by: Hans de Goede 
---
Changes in v2:
-New patch in v2 of this patchset
---
 Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt | 2 ++
 drivers/phy/phy-sun4i-usb.c | 9 -
 2 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 287150d..8646b53 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -35,6 +35,8 @@ Optional properties:
 - usb0_vbus-supply : regulator phandle for controller usb0 vbus
 - usb1_vbus-supply : regulator phandle for controller usb1 vbus
 - usb2_vbus-supply : regulator phandle for controller usb2 vbus
+- allwinner,usb0-usb-a-connector: usb0 is connected to an USB-A connector,
+ rather then an USB-B connector as one would expect (bool)
 
 Example:
usbphy: phy@0x01c13400 {
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index c17b099..82fb46a 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -137,6 +137,7 @@ struct sun4i_usb_phy_data {
int vbus_det_irq;
int id_det;
int vbus_det;
+   int id_det_default;
struct delayed_work detect;
 };
 
@@ -328,7 +329,7 @@ static int sun4i_usb_phy0_get_id_det(struct 
sun4i_usb_phy_data *data)
if (data->id_det_gpio)
return gpiod_get_value_cansleep(data->id_det_gpio);
else
-   return 1; /* Fallback to peripheral mode */
+   return data->id_det_default;
case USB_DR_MODE_HOST:
return 0;
case USB_DR_MODE_PERIPHERAL:
@@ -621,6 +622,12 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
if (IS_ERR(data->base))
return PTR_ERR(data->base);
 
+   /* Set id-det default for when there is no id-det gpio */
+   if (of_property_read_bool(np, "allwinner,usb0-usb-a-connector"))
+   data->id_det_default = 0; /* Host (USB-A connector) */
+   else
+   data->id_det_default = 1; /* Device (USB-B connector) */
+
data->id_det_gpio = devm_gpiod_get_optional(dev, "usb0_id_det",
GPIOD_IN);
if (IS_ERR(data->id_det_gpio))
-- 
2.7.4

--
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/7] musb: sunxi: Add support for run-time changing dr-mode through sysfs

2016-08-15 Thread Hans de Goede
Hi All,

Here is a patch series which implements run-time changing the dr-mode
of sunxi musb controllers through the (already existing) musb "mode"
sysfs attribute.

This is useful on boards where there is no id pin, e.g. some tv-boxes
use the musb controller to get an extra usb A port without needing
a hub chip. Except for the missing id pin when using a usb A<->A cable
these ports can do peripheral mode just fine. This series makes it
possible to do e.g. this by doing echo "peripheral" > mode before
plugging in the usb A<->A cable.

This series has both sun4i-usb-phy driver and sunxi-musb-glue changes,
both are necessary for the run-time changing to work, but they can be
merged independently without breaking anything.

Changed in v2:

After sleeping on it a night I realized that always passing port_mode =
DUAL_ROLE to the musb-core was wrong. There is a distintion between
the id-pin not working properly which we can work around with software
mode switching (and we want to register both the host and udc driver
in this case) vs cases where we really only want to register a host
(wifi module connected to musb soldered onto the PCB).

So v2 of this series drops the
"musb: sunxi: Always register both host and udc when build with dual-role 
support"
patch.

Instead systems which are dual-role capable, but lack an id-pin should use
dr_mode = "otg" in the dts file. There is one problem with this, some
systems are dual-role capable but use a female USB-A connector connected
to the musb controller. These should come up in host mode by default,
rather then peripheral mode which is the default for systems which lack an
id-pin. This patch set introduces:

"phy-sun4i-usb: Add "allwinner,usb0-usb-a-connector" dt property"

Which allows specifying the use of a female USB-A connector for the
musb controller in the phy dt node, the presence of this dt property
changes the default to host mode.

Please review (and if no issues are found merge).

Thanks & Regards,

Hans
--
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/7] phy-sun4i-usb: Use bool where appropriate

2016-08-15 Thread Hans de Goede
We're using bool as true/false type in most places in phy-sun4i-usb.c
for consistency fixup the remaining uses of ints which are ever only
0 or 1 to be bools too.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index fcf4d95e..1cb84a8 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -445,7 +445,8 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
struct sun4i_usb_phy_data *data =
container_of(work, struct sun4i_usb_phy_data, detect.work);
struct phy *phy0 = data->phys[0].phy;
-   int id_det, vbus_det, id_notify = 0, vbus_notify = 0;
+   bool id_notify = false, vbus_notify = false;
+   int id_det, vbus_det;
 
if (phy0 == NULL)
return;
@@ -474,13 +475,13 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
}
sun4i_usb_phy0_set_id_detect(phy0, id_det);
data->id_det = id_det;
-   id_notify = 1;
+   id_notify = true;
}
 
if (vbus_det != data->vbus_det) {
sun4i_usb_phy0_set_vbus_detect(phy0, vbus_det);
data->vbus_det = vbus_det;
-   vbus_notify = 1;
+   vbus_notify = true;
}
 
mutex_unlock(&phy0->mutex);
-- 
2.7.4

--
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 5/7] phy-sun4i-usb: Warn when external vbus is detected

2016-08-15 Thread Hans de Goede
Warn when external vbus is detected when we're trying to enable our
own vbus.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index d369081..c17b099 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -390,8 +390,10 @@ static int sun4i_usb_phy_power_on(struct phy *_phy)
 
/* For phy0 only turn on Vbus if we don't have an ext. Vbus */
if (phy->index == 0 && sun4i_usb_phy0_have_vbus_det(data) &&
-   data->vbus_det)
+   data->vbus_det) {
+   dev_warn(&_phy->dev, "External vbus detected, not enabling our 
own vbus\n");
return 0;
+   }
 
ret = regulator_enable(phy->vbus);
if (ret)
-- 
2.7.4

--
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/7] phy-sun4i-usb: Refactor forced session ending

2016-08-15 Thread Hans de Goede
The phy-sun4i-usb code supports forced ending a session on systems
which lack Vbus detection, to allow switching between host and peripheral
mode on such systems.

Role switching via the musb driver "mode" sysfs attribute requires force
ending the session too. This commit refactors the code to allow other
parts of the phy-sun4i-usb code to request a forced session end.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 27 +--
 1 file changed, 13 insertions(+), 14 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 1cb84a8..02cb65e 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -133,6 +133,7 @@ struct sun4i_usb_phy_data {
struct power_supply *vbus_power_supply;
struct notifier_block vbus_power_nb;
bool vbus_power_nb_registered;
+   bool force_session_end;
int id_det_irq;
int vbus_det_irq;
int id_det;
@@ -445,7 +446,7 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
struct sun4i_usb_phy_data *data =
container_of(work, struct sun4i_usb_phy_data, detect.work);
struct phy *phy0 = data->phys[0].phy;
-   bool id_notify = false, vbus_notify = false;
+   bool force_session_end, id_notify = false, vbus_notify = false;
int id_det, vbus_det;
 
if (phy0 == NULL)
@@ -461,14 +462,17 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
return;
}
 
+   force_session_end = data->force_session_end;
+   data->force_session_end = false;
+
if (id_det != data->id_det) {
-   /*
-* When a host cable (id == 0) gets plugged in on systems
-* without vbus detection report vbus low for long enough for
-* the musb-ip to end the current device session.
-*/
+   /* id-change, force session end if we've no vbus detection */
if (data->dr_mode == USB_DR_MODE_OTG &&
-   !sun4i_usb_phy0_have_vbus_det(data) && id_det == 0) {
+   !sun4i_usb_phy0_have_vbus_det(data))
+   force_session_end = true;
+
+   /* When entering host mode (id = 0) force end the session now */
+   if (force_session_end && id_det == 0) {
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
msleep(200);
sun4i_usb_phy0_set_vbus_detect(phy0, 1);
@@ -489,13 +493,8 @@ static void sun4i_usb_phy0_id_vbus_det_scan(struct 
work_struct *work)
if (id_notify) {
extcon_set_cable_state_(data->extcon, EXTCON_USB_HOST,
!id_det);
-   /*
-* When a host cable gets unplugged (id == 1) on systems
-* without vbus detection report vbus low for long enough to
-* the musb-ip to end the current host session.
-*/
-   if (data->dr_mode == USB_DR_MODE_OTG &&
-   !sun4i_usb_phy0_have_vbus_det(data) && id_det == 1) {
+   /* When leaving host mode force end the session here */
+   if (force_session_end && id_det == 1) {
mutex_lock(&phy0->mutex);
sun4i_usb_phy0_set_vbus_detect(phy0, 0);
msleep(1000);
-- 
2.7.4

--
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/7] phy-sun4i-usb: Add support for phy_set_mode

2016-08-15 Thread Hans de Goede
Together with some musb sunxi glue changes this allows run-time dr_mode
switching support via the "mode" musb sysfs attribute.

Signed-off-by: Hans de Goede 
---
 drivers/phy/phy-sun4i-usb.c | 24 
 1 file changed, 24 insertions(+)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index fb2d4f3..d369081 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -427,6 +427,29 @@ static int sun4i_usb_phy_power_off(struct phy *_phy)
return 0;
 }
 
+static int sun4i_usb_phy_set_mode(struct phy *_phy, enum phy_mode mode)
+{
+   struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
+   struct sun4i_usb_phy_data *data = to_sun4i_usb_phy_data(phy);
+
+   if (phy->index != 0)
+   return -EINVAL;
+
+   switch (mode) {
+   case PHY_MODE_USB_HOST:   data->dr_mode = USB_DR_MODE_HOST; break;
+   case PHY_MODE_USB_DEVICE: data->dr_mode = USB_DR_MODE_PERIPHERAL; break;
+   case PHY_MODE_USB_OTG:data->dr_mode = USB_DR_MODE_OTG; break;
+   default:
+   return -EINVAL;
+   }
+
+   dev_info(&_phy->dev, "Changing dr_mode to %d\n", (int)data->dr_mode);
+   data->force_session_end = true;
+   queue_delayed_work(system_wq, &data->detect, 0);
+
+   return 0;
+}
+
 void sun4i_usb_phy_set_squelch_detect(struct phy *_phy, bool enabled)
 {
struct sun4i_usb_phy *phy = phy_get_drvdata(_phy);
@@ -440,6 +463,7 @@ static const struct phy_ops sun4i_usb_phy_ops = {
.exit   = sun4i_usb_phy_exit,
.power_on   = sun4i_usb_phy_power_on,
.power_off  = sun4i_usb_phy_power_off,
+   .set_mode   = sun4i_usb_phy_set_mode,
.owner  = THIS_MODULE,
 };
 
-- 
2.7.4

--
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/7] phy-sun4i-usb: Simplify missing dr_mode handling

2016-08-15 Thread Hans de Goede
If we cannot get dr_mode or no id gpio is specified simply assume
peripheral mode, as this is always safe.

Signed-off-by: Hans de Goede 
---
Changes in v2:
-Keep sun4i_usb_phy0_get_id_det() logic as is rather then re-ordering
 the switch-case
---
 drivers/phy/phy-sun4i-usb.c | 42 ++
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index 02cb65e..fb2d4f3 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -124,7 +124,6 @@ struct sun4i_usb_phy_data {
bool regulator_on;
int index;
} phys[MAX_PHYS];
-   int first_phy;
/* phy0 / otg related variables */
struct extcon_dev *extcon;
bool phy0_init;
@@ -326,7 +325,10 @@ static int sun4i_usb_phy0_get_id_det(struct 
sun4i_usb_phy_data *data)
 {
switch (data->dr_mode) {
case USB_DR_MODE_OTG:
-   return gpiod_get_value_cansleep(data->id_det_gpio);
+   if (data->id_det_gpio)
+   return gpiod_get_value_cansleep(data->id_det_gpio);
+   else
+   return 1; /* Fallback to peripheral mode */
case USB_DR_MODE_HOST:
return 0;
case USB_DR_MODE_PERIPHERAL:
@@ -539,8 +541,7 @@ static struct phy *sun4i_usb_phy_xlate(struct device *dev,
 {
struct sun4i_usb_phy_data *data = dev_get_drvdata(dev);
 
-   if (args->args[0] < data->first_phy ||
-   args->args[0] >= data->cfg->num_phys)
+   if (args->args[0] >= data->cfg->num_phys)
return ERR_PTR(-ENODEV);
 
return data->phys[args->args[0]].phy;
@@ -615,33 +616,18 @@ static int sun4i_usb_phy_probe(struct platform_device 
*pdev)
}
 
data->dr_mode = of_usb_get_dr_mode_by_phy(np, 0);
-   switch (data->dr_mode) {
-   case USB_DR_MODE_OTG:
-   /* otg without id_det makes no sense, and is not supported */
-   if (!data->id_det_gpio) {
-   dev_err(dev, "usb0_id_det missing or invalid\n");
-   return -ENODEV;
-   }
-   /* fall through */
-   case USB_DR_MODE_HOST:
-   case USB_DR_MODE_PERIPHERAL:
-   data->extcon = devm_extcon_dev_allocate(dev,
-   sun4i_usb_phy0_cable);
-   if (IS_ERR(data->extcon))
-   return PTR_ERR(data->extcon);
 
-   ret = devm_extcon_dev_register(dev, data->extcon);
-   if (ret) {
-   dev_err(dev, "failed to register extcon: %d\n", ret);
-   return ret;
-   }
-   break;
-   default:
-   dev_info(dev, "dr_mode unknown, not registering usb phy0\n");
-   data->first_phy = 1;
+   data->extcon = devm_extcon_dev_allocate(dev, sun4i_usb_phy0_cable);
+   if (IS_ERR(data->extcon))
+   return PTR_ERR(data->extcon);
+
+   ret = devm_extcon_dev_register(dev, data->extcon);
+   if (ret) {
+   dev_err(dev, "failed to register extcon: %d\n", ret);
+   return ret;
}
 
-   for (i = data->first_phy; i < data->cfg->num_phys; i++) {
+   for (i = 0; i < data->cfg->num_phys; i++) {
struct sun4i_usb_phy *phy = data->phys + i;
char name[16];
 
-- 
2.7.4

--
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: core: of: Check device_node before parsing in usb_of_get_child_node()

2016-08-15 Thread Vaibhav Hiremath



On Monday 15 August 2016 11:41 AM, Greg KH wrote:

On Mon, Aug 15, 2016 at 11:31:10AM -0700, Vaibhav Hiremath wrote:

In case of HUB devices connected to USB ports, we may not have DT
node representing it inside USB, and when devices connected to hub
gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
dereference.

Really?  That seems messed up.


unfortunately yes :)


In the usecase we have, where EHCI port is connected to USB HUB
device, and downward ports of HUB are connected to further USB
devices. When those devices gets enumerated, in order,
  1. USB HUB ->
-> Call to usb_of_get_child_node() is OK, as
parent->dev.of_node is pointing to host node.
  2. Devices connected to downward port of USB HUB
-> Call to usb_of_get_child_node() leads to NULL
pointer dereference as parent->dev.of_node = NULL,
as USB HUB DTS node may be empty.

Why is the hub DTS empty?  Shouldn't that be the fix here?


Because HUB can be enumerated dynamically and one possible
reason could be you don't need to do anything to bring up HUB.
May be one of following could be the reason -

 1. HUB automatically comes up on power ON, and USB host enumerates it.
   There is no control path for HUB

 2. HUB has different control path, in our case it is over I2C.
   So HUB configuration and bringup happens as part of I2C client driver.



So you may not need DTS for HUB as a child node inside USB host.
What I am trying to say here is,


&usb_ehci {
...

status = "ok";
};

This would enumerate HUB first, and then devices connected to HUB, right?
So this will lead to kernel crash.



Reference DTS with HUB and downward devices -

&usb_ehci {
status = "ok";

usb_hub: usb_hub {
compatible = "usb";
reg = <1>;

usb_dev: usb_dev {
compatible = "usb";
reg = <1>;

...
};
   };
};


Thanks,
Vaibhav
--
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: core: of: Check device_node before parsing in usb_of_get_child_node()

2016-08-15 Thread Greg KH
On Mon, Aug 15, 2016 at 11:31:10AM -0700, Vaibhav Hiremath wrote:
> In case of HUB devices connected to USB ports, we may not have DT
> node representing it inside USB, and when devices connected to hub
> gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
> dereference.

Really?  That seems messed up.

> In the usecase we have, where EHCI port is connected to USB HUB
> device, and downward ports of HUB are connected to further USB
> devices. When those devices gets enumerated, in order,
>  1. USB HUB ->
>   -> Call to usb_of_get_child_node() is OK, as
>   parent->dev.of_node is pointing to host node.
>  2. Devices connected to downward port of USB HUB
>   -> Call to usb_of_get_child_node() leads to NULL
>   pointer dereference as parent->dev.of_node = NULL,
>   as USB HUB DTS node may be empty.

Why is the hub DTS empty?  Shouldn't that be the fix here?

thanks,

greg k-h
--
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: core: of: Check device_node before parsing in usb_of_get_child_node()

2016-08-15 Thread Vaibhav Hiremath
In case of HUB devices connected to USB ports, we may not have DT
node representing it inside USB, and when devices connected to hub
gets enumerated, call to usb_of_get_child_node() leads to NULL pointer
dereference.

In the usecase we have, where EHCI port is connected to USB HUB
device, and downward ports of HUB are connected to further USB
devices. When those devices gets enumerated, in order,
 1. USB HUB ->
-> Call to usb_of_get_child_node() is OK, as
parent->dev.of_node is pointing to host node.
 2. Devices connected to downward port of USB HUB
-> Call to usb_of_get_child_node() leads to NULL
pointer dereference as parent->dev.of_node = NULL,
as USB HUB DTS node may be empty.

Fix this NULL pointer dereference by adding check for pointer
device_node inside usb_of_get_child_node() fn.

Signed-off-by: Vaibhav Hiremath 
---
Testing: I have build tested it against mainline.

 drivers/usb/core/of.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
index 2289700..dc667a3 100644
--- a/drivers/usb/core/of.c
+++ b/drivers/usb/core/of.c
@@ -34,6 +34,9 @@ struct device_node *usb_of_get_child_node(struct device_node 
*parent,
struct device_node *node;
u32 port;
 
+   if (!parent)
+   return NULL;
+
for_each_child_of_node(parent, node) {
if (!of_property_read_u32(node, "reg", &port)) {
if (port == portnum)
-- 
2.7.4

--
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 v10 5/5] usb: dwc3: add rockchip specific glue layer

2016-08-15 Thread kbuild test robot
Hi William,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.8-rc2 next-20160815]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/William-Wu/support-rockchip-dwc3-driver/20160815-165927
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: arm-arm67 (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 5.4.0-6) 5.4.0 20160609
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm 

All errors (new ones prefixed by >>):

>> ERROR: "dwc3_trace" [drivers/usb/dwc3/dwc3-rockchip.ko] undefined!
>> ERROR: "dwc3_phy_setup" [drivers/usb/dwc3/dwc3-rockchip.ko] undefined!
>> ERROR: "dwc3_set_mode" [drivers/usb/dwc3/dwc3-rockchip.ko] undefined!
>> ERROR: "__tracepoint_dwc3_readl" [drivers/usb/dwc3/dwc3-rockchip.ko] 
>> undefined!

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [lkp] [usb] ad05399d68: BUG: unable to handle kernel NULL pointer dereference at 0000000000000012

2016-08-15 Thread Ye Xiaolong
On 08/15, Peter Chen wrote:
> 
>>
>>
>>FYI, we noticed the following commit:
>>
>>https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next 
>>commit
>>ad05399d68b6ae1649cdcfc82ce3ffea1a7c5104 ("usb: udc: core: fix error 
>>handling")
>>
>
>Hi Xiaolong,
>
>You reported it one month ago, and said it is a false report. see below.
>Would you please double confirm it?

Hi, peter

Last time I reported stat "WARNING: CPU: 0 PID: 1 at
lib/list_debug.c:36" and it showed both in this commit and its parent,
this time, the observed change stat is "BUG: unable to handle kernel NULL
pointer dereference at 0012" and it doesn't show in parent
commit, however, the parent commit's dmesg would show kernel panic log
as:

[   10.338487] Kernel panic - not syncing: Attempted to kill init! 
exitcode=0x000b
[   10.338487] 
[   10.339911] CPU: 0 PID: 1 Comm: init Not tainted 4.8.0-rc1-00020-g0937a4d #1
[   10.341177] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 
Debian-1.8.2-1 04/01/2014
[   10.342798]   88001e53bc28 8168cf8a 
88001e534000
[   10.345177]  8256ef20 88001e53bcb8 88001e50ca50 
88001e53bca8
[   10.346739]  8114e062 8810 88001e53bcb8 
88001e53bc50
[   10.347970] Call Trace:
[   10.348690]  [] dump_stack+0x83/0xb9
[   10.351592]  [] panic+0xf3/0x2a9
[   10.352386]  [] do_exit+0x601/0xde0
[   10.352879]  [] ? __sigqueue_free+0x43/0x50
[   10.353511]  [] ? __dequeue_signal+0x1f7/0x210
[   10.354483]  [] do_group_exit+0xa2/0x100
[   10.355324]  [] get_signal+0x68e/0x740
[   10.356155]  [] do_signal+0x23/0x670
[   10.356983]  [] ? do_syslog+0x2c0/0x6a0
[   10.357832]  [] ? bad_area_nosemaphore+0x33/0x40
[   10.358825]  [] ? __do_page_fault+0x407/0x4d0
[   10.359738]  [] exit_to_usermode_loop+0x69/0xc0
[   10.360680]  [] prepare_exit_to_usermode+0x3d/0x70
[   10.361725]  [] retint_user+0x8/0x10
[   10.362650] Kernel Offset: disabled

The whole parent dmesg is attached.

Thanks,
Xiaolong

>
>On Wed, Jul 13, 2016 at 01:55:26AM +, Peter Chen wrote:
>> 
>>
>>>-Original Message-
>>>From: lkp-requ...@eclists.intel.com 
>>>[mailto:lkp-requ...@eclists.intel.com] On Behalf Of kernel test robot
>>>Sent: Wednesday, July 13, 2016 9:28 AM
>>>To: Peter Chen 
>>>Cc: 0day robot ; LKML 
>>>; l...@01.org
>>>Subject: [lkp] [usb] 9696ef14de: WARNING: CPU: 0 PID: 1 at 
>>>lib/list_debug.c:36
>>>__list_add+0x104/0x188
>>>
>>>
>>>FYI, we noticed the following commit:
>>>
>>>https://github.com/0day-ci/linux Peter-Chen/usb-udc-core-fix-error-
>>>handling/20160711-100832
>>>commit 9696ef14ded07fb0847f8e1cdda6d98a89ecd4f2 ("usb: udc: core: fix 
>>>error
>>>handling")
>>>
>>
>>Thanks,  but I really can't find the relationship between my patch and dump.
>>Can you reproduce it after running again or without my patch?
>>
>
>Sorry, it's a false report, the error dump also showed in parent commit, 
>please ignore the report and sorry for the noise.
>
>Thanks,
>Xiaolong
>
>
>
>
>Peter
>
>>in testcase: boot
>>
>>on test machine: 1 threads qemu-system-x86_64 -enable-kvm -cpu SandyBridge
>>with 512M memory
>>
>>caused below changes:
>>
>>
>>+---+++
>>|   | 0937a4d787
>>| | ad05399d68 |
>>+---+++
>>| boot_successes| 0  | 0  
>>|
>>| boot_failures | 12 | 12 
>>|
>>| WARNING:at_lib/list_debug.c:#__list_del_entry | 2  | 12 
>>|
>>| BUG:kernel_test_hang  | 2  |
>>|
>>| backtrace:kernel_restart  | 2  |
>>|
>>| backtrace:SyS_reboot  | 2  |
>>|
>>| BUG:kernel_oversize_in_test_stage | 4  |
>>|
>>| Kernel_panic-not_syncing:Attempted_to_kill_init!exitcode= | 6  |
>>|
>>| BUG:unable_to_handle_kernel   | 0  | 11 
>>|
>>| Oops  | 0  | 11 
>>|
>>| RIP:sysfs_kf_write| 0  | 11 
>>|
>>| Kernel_panic-not_syncing:Fatal_exception  | 0  | 11 
>>|
>>| backtrace:serio_handle_event  | 0  | 12 
>>|
>>| backtrace:vfs_write   | 0  | 11 
>>|
>>| backtrace:SyS_write   | 0  | 11 
>>|
>>+---+++
>>
>>
>>[   12.161205] BUG: unable to handle kernel NULL poi

Re: [PATCH] usb: host: xhci-rcar: update firmware for R-Car H3 and M3-W

2016-08-15 Thread Kyle McMartin
On Wed, Aug 10, 2016 at 07:56:39PM +0900, Yoshihiro Shimoda wrote:
> This patch updates the firmware files for R-Car H3 and M3-W to fix
> the device detection issue.
> 
> The md5sum of the files are:
> 645db7e9056029efa15f158e51cc8a11  r8a779x_usb3_v2.dlmem
> 687d5d42f38f9850f8d5a6071dca3109  r8a779x_usb3_v3.dlmem
> 
> Signed-off-by: Yoshihiro Shimoda 
> ---
>  r8a779x_usb3_v2.dlmem | Bin 9472 -> 9416 bytes
>  r8a779x_usb3_v3.dlmem | Bin 9472 -> 9416 bytes
>  2 files changed, 0 insertions(+), 0 deletions(-)
> 

applied, thanks!

--kyle
--
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: chipidea: host: disable io watchdog

2016-08-15 Thread Lucas Stach
The Chipidea EHCI core seems to behave sanely and doesn't need
the IO watchdog. This kills off 10 non-deferrable wakeup events
per second when the controller is otherwise idle.

Signed-off-by: Lucas Stach 
Tested-by: Stefan Agner 
---
 drivers/usb/chipidea/host.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/chipidea/host.c b/drivers/usb/chipidea/host.c
index 053bac9d983c..96ae69502c86 100644
--- a/drivers/usb/chipidea/host.c
+++ b/drivers/usb/chipidea/host.c
@@ -81,12 +81,15 @@ static int ehci_ci_reset(struct usb_hcd *hcd)
 {
struct device *dev = hcd->self.controller;
struct ci_hdrc *ci = dev_get_drvdata(dev);
+   struct ehci_hcd *ehci = hcd_to_ehci(hcd);
int ret;
 
ret = ehci_setup(hcd);
if (ret)
return ret;
 
+   ehci->need_io_watchdog = 0;
+
ci_platform_configure(ci);
 
return ret;
-- 
2.8.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: Kconfig: move ulpi bus to common

2016-08-15 Thread Heikki Krogerus
Hi,

On Fri, Jul 08, 2016 at 04:15:23PM +0800, Peter Chen wrote:
> The ULPI bus is not only for host, but for device mode too, so move
> it out from host's Kconfig.
> 
> Cc: Heikki Krogerus 
> Signed-off-by: Peter Chen 
> ---
>  drivers/usb/common/Kconfig | 21 +
>  drivers/usb/core/Kconfig   | 21 -
>  2 files changed, 21 insertions(+), 21 deletions(-)
> 
> diff --git a/drivers/usb/common/Kconfig b/drivers/usb/common/Kconfig
> index 951b1d0..e251aec 100644
> --- a/drivers/usb/common/Kconfig
> +++ b/drivers/usb/common/Kconfig
> @@ -7,3 +7,24 @@ config USB_LED_TRIG
> Say Y here if you are working on a system with led-class supported
> LEDs and you want to use them as activity indicators for USB host or
> gadget.
> +
> +config USB_ULPI_BUS
> + tristate "USB ULPI PHY interface support"
> + depends on USB_SUPPORT
> + help
> +   UTMI+ Low Pin Interface (ULPI) is specification for a commonly used
> +   USB 2.0 PHY interface. The ULPI specification defines a standard set
> +   of registers that can be used to detect the vendor and product which
> +   allows ULPI to be handled as a bus. This module is the driver for that
> +   bus.
> +
> +   The ULPI interfaces (the buses) are registered by the drivers for USB
> +   controllers which support ULPI register access and have ULPI PHY
> +   attached to them. The ULPI PHY drivers themselves are normal PHY
> +   drivers.
> +
> +   ULPI PHYs provide often functions such as ADP sensing/probing (OTG
> +   protocol) and USB charger detection.
> +
> +   To compile this driver as a module, choose M here: the module will
> +   be called ulpi.
> diff --git a/drivers/usb/core/Kconfig b/drivers/usb/core/Kconfig
> index dd28010..d6e43ce 100644
> --- a/drivers/usb/core/Kconfig
> +++ b/drivers/usb/core/Kconfig
> @@ -82,24 +82,3 @@ config USB_OTG_FSM
>   help
> Implements OTG Finite State Machine as specified in On-The-Go
> and Embedded Host Supplement to the USB Revision 2.0 Specification.
> -
> -config USB_ULPI_BUS
> - tristate "USB ULPI PHY interface support"
> - depends on USB_SUPPORT

This patch does not apply. The above line has been removed at one
point.

Once you resend, please re-add the dependency once you move the config
to drivers/usb/common/Kconfig.


Thanks,

-- 
heikki
--
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 00/10] usb: ulpi: remove "dev" field from struct ulpi_ops

2016-08-15 Thread Heikki Krogerus
Hi,

Please forgive me for taking so long to reply. I just returned from
paternal leave.

On Mon, Aug 01, 2016 at 09:15:48PM +0300, Tal Shorer wrote:
> struct ulpi_ops is defined as follows:
> 
> struct ulpi_ops {
> struct device *dev;
> int (*read)(struct ulpi_ops *ops, u8 addr);
> int (*write)(struct ulpi_ops *ops, u8 addr, u8 val);
> };
> 
> Upon calling ulpi_register_interface(), the struct device argument is
> put inside the struct ulpi_ops argument's dev field. Later, when
> calling the actual read()/write() operations, the struct ulpi_ops is
> passed to them and they use the stored device to access whatever
> private data they need.
> 
> This means that if one wishes to reuse the same oprations for multiple
> interfaces (e.g if we have multiple instances of the same controller),
> any but the last interface registered will not operate properly (and
> the one that does work will be at the mercy of the others to not mess
> it up).
> 
> I understand that barely any driver uses this bus right now, but I
> suppose it's there to be used at some point. We might as well fix the
> design here before we hit this bug.
> 
> This series fixes this by passing the given struct device directly to
> the operation functions via ulpi->dev.parent in ulpi_read() and
> ulpi_write(). It also changes the operations struct to be constant
> since now nobody has a reason to modify it.

If there are multiple instances of the same controller, the controller
driver just needs to provide a separate ops for every one of them.
This isn't really a problem as you describe it. But I'm not against
API improvements even if they don't fix anything. I'll test these
tomorrow.


Thanks,

-- 
heikki
--
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 6/6] usb: dwc3: gadget: improve increment request->actual

2016-08-15 Thread Felipe Balbi
No functional changes, just a slight cosmetic
change.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 8 ++--
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 998e433c2c01..c6fe9a3bacab 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1860,6 +1860,7 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
unsigned inttrb_status;
 
dep->queued_requests--;
+   dwc3_ep_inc_deq(dep);
trace_dwc3_complete_trb(dep, trb);
 
/*
@@ -1879,6 +1880,7 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
return 1;
 
count = trb->size & DWC3_TRB_SIZE_MASK;
+   req->request.actual += count;
 
if (dep->direction) {
if (count) {
@@ -1931,7 +1933,6 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 {
struct dwc3_request *req, *n;
struct dwc3_trb *trb;
-   int count = 0;
int ret;
 
list_for_each_entry_safe(req, n, &dep->started_list, list) {
@@ -1949,8 +1950,6 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 
for_each_sg(sg, s, pending, i) {
trb = &dep->trb_pool[dep->trb_dequeue];
-   count += trb->size & DWC3_TRB_SIZE_MASK;
-   dwc3_ep_inc_deq(dep);
 
req->sg = sg_next(s);
req->num_pending_sgs--;
@@ -1962,9 +1961,6 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
}
} else {
trb = &dep->trb_pool[dep->trb_dequeue];
-   count += trb->size & DWC3_TRB_SIZE_MASK;
-   dwc3_ep_inc_deq(dep);
-
ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
event, status, chain);
}
-- 
2.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/6] usb: dwc3: gadget: avoid while (1) loop on completion

2016-08-15 Thread Felipe Balbi
We know that we have to iterate over the list of
started requests. Instead of looping forever, we can
rely on list_for_each_entry(). Likewise, instead of
a do {} while loop over all, maybe available,
scatterlist entries, we can detect if $this request
uses scatterlist and rely on for_each_sg().

This makes the code easier to follow while making
sure that we will *always* break out of the loop.

Signed-off-by: Felipe Balbi 
---

Changes since v1:

- switch to list_for_each_entry_safe() so we're safe against entry
  removal

 drivers/usb/dwc3/gadget.c | 32 +++-
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 3cf4c9016b75..c776fb7f524a 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1926,31 +1926,37 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, struct dwc3_ep *dep,
const struct dwc3_event_depevt *event, int status)
 {
-   struct dwc3_request *req;
+   struct dwc3_request *req, *n;
struct dwc3_trb *trb;
-   unsigned inti;
int count = 0;
int ret;
 
-   do {
-   int chain;
+   list_for_each_entry_safe(req, n, &dep->started_list, list) {
 
-   req = next_request(&dep->started_list);
-   if (!req)
-   return 1;
+   int chain;
 
chain = req->request.num_mapped_sgs > 0;
-   i = 0;
-   do {
+   if (chain) {
+   struct scatterlist *sg = req->request.sg;
+   struct scatterlist *s;
+   unsigned int i;
+
+   for_each_sg(sg, s, req->request.num_mapped_sgs, i) {
+   trb = &dep->trb_pool[dep->trb_dequeue];
+   count += trb->size & DWC3_TRB_SIZE_MASK;
+   dwc3_ep_inc_deq(dep);
+
+   ret = __dwc3_cleanup_done_trbs(dwc, dep, req, 
trb,
+   event, status, chain);
+   }
+   } else {
trb = &dep->trb_pool[dep->trb_dequeue];
count += trb->size & DWC3_TRB_SIZE_MASK;
dwc3_ep_inc_deq(dep);
 
ret = __dwc3_cleanup_done_trbs(dwc, dep, req, trb,
event, status, chain);
-   if (ret)
-   break;
-   } while (++i < req->request.num_mapped_sgs);
+   }
 
/*
 * We assume here we will always receive the entire data block
@@ -1964,7 +1970,7 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 
if (ret)
break;
-   } while (1);
+   }
 
/*
 * Our endpoint might get disabled by another thread during
-- 
2.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 5/6] usb: dwc3: gadget: remove condition that never happens

2016-08-15 Thread Felipe Balbi
We don't use LST bit anymore, so this condition will
never trigger.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 6483991c8013..998e433c2c01 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -1918,13 +1918,11 @@ static int __dwc3_cleanup_done_trbs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 
if (s_pkt && !chain)
return 1;
-   if ((event->status & DEPEVT_STATUS_LST) &&
-   (trb->ctrl & (DWC3_TRB_CTRL_LST |
-   DWC3_TRB_CTRL_HWO)))
-   return 1;
+
if ((event->status & DEPEVT_STATUS_IOC) &&
(trb->ctrl & DWC3_TRB_CTRL_IOC))
return 1;
+
return 0;
 }
 
-- 
2.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/6] usb: dwc3: gadget: interrupt on ring full too

2016-08-15 Thread Felipe Balbi
If the ring is full and we are processing a big
sglist, then let's interrupt so we can, later, add
more TRBs to the ring.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index c776fb7f524a..90b3d7965136 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -758,6 +758,8 @@ static void dwc3_gadget_ep_free_request(struct usb_ep *ep,
kfree(req);
 }
 
+static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep);
+
 /**
  * dwc3_prepare_one_trb - setup one TRB from one request
  * @dep: endpoint for which this request is prepared
@@ -818,7 +820,8 @@ static void dwc3_prepare_one_trb(struct dwc3_ep *dep,
/* always enable Continue on Short Packet */
trb->ctrl |= DWC3_TRB_CTRL_CSP;
 
-   if (!req->request.no_interrupt && !chain)
+   if ((!req->request.no_interrupt && !chain) ||
+   (dwc3_calc_trbs_left(dep) == 0))
trb->ctrl |= DWC3_TRB_CTRL_IOC | DWC3_TRB_CTRL_ISP_IMI;
 
if (chain)
-- 
2.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 4/6] usb: dwc3: gadget: add remaining sg entries to ring

2016-08-15 Thread Felipe Balbi
Upon transfer completion after a full ring, let's
add more TRBs to our ring in order to complete our
request successfully.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/gadget.c | 36 
 1 file changed, 24 insertions(+), 12 deletions(-)

diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 90b3d7965136..6483991c8013 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -888,14 +888,13 @@ static u32 dwc3_calc_trbs_left(struct dwc3_ep *dep)
 static void dwc3_prepare_one_trb_sg(struct dwc3_ep *dep,
struct dwc3_request *req, unsigned int trbs_left)
 {
-   struct usb_request *request = &req->request;
-   struct scatterlist *sg = request->sg;
+   struct scatterlist *sg = req->sg;
struct scatterlist *s;
unsigned intlength;
dma_addr_t  dma;
int i;
 
-   for_each_sg(sg, s, request->num_mapped_sgs, i) {
+   for_each_sg(sg, s, req->num_pending_sgs, i) {
unsigned chain = true;
 
length = sg_dma_len(s);
@@ -945,7 +944,7 @@ static void dwc3_prepare_trbs(struct dwc3_ep *dep)
return;
 
list_for_each_entry_safe(req, n, &dep->pending_list, list) {
-   if (req->request.num_mapped_sgs > 0)
+   if (req->num_pending_sgs > 0)
dwc3_prepare_one_trb_sg(dep, req, trbs_left--);
else
dwc3_prepare_one_trb_linear(dep, req, trbs_left--);
@@ -1071,6 +1070,9 @@ static int __dwc3_gadget_ep_queue(struct dwc3_ep *dep, 
struct dwc3_request *req)
if (ret)
return ret;
 
+   req->sg = req->request.sg;
+   req->num_pending_sgs= req->request.num_mapped_sgs;
+
list_add_tail(&req->list, &dep->pending_list);
 
if (usb_endpoint_xfer_isoc(dep->endpoint.desc) &&
@@ -1935,22 +1937,30 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
int ret;
 
list_for_each_entry_safe(req, n, &dep->started_list, list) {
-
+   unsigned length;
+   unsigned actual;
int chain;
 
-   chain = req->request.num_mapped_sgs > 0;
+   length = req->request.length;
+   chain = req->num_pending_sgs > 0;
if (chain) {
-   struct scatterlist *sg = req->request.sg;
+   struct scatterlist *sg = req->sg;
struct scatterlist *s;
+   unsigned int pending = req->num_pending_sgs;
unsigned int i;
 
-   for_each_sg(sg, s, req->request.num_mapped_sgs, i) {
+   for_each_sg(sg, s, pending, i) {
trb = &dep->trb_pool[dep->trb_dequeue];
count += trb->size & DWC3_TRB_SIZE_MASK;
dwc3_ep_inc_deq(dep);
 
+   req->sg = sg_next(s);
+   req->num_pending_sgs--;
+
ret = __dwc3_cleanup_done_trbs(dwc, dep, req, 
trb,
event, status, chain);
+   if (ret)
+   break;
}
} else {
trb = &dep->trb_pool[dep->trb_dequeue];
@@ -1968,11 +1978,13 @@ static int dwc3_cleanup_done_reqs(struct dwc3 *dwc, 
struct dwc3_ep *dep,
 * should receive and we simply bounce the request back to the
 * gadget driver for further processing.
 */
-   req->request.actual += req->request.length - count;
-   dwc3_gadget_giveback(dep, req, status);
+   actual = length - req->request.actual;
+   req->request.actual = actual;
 
-   if (ret)
-   break;
+   if (ret && chain && (actual < length) && req->num_pending_sgs)
+   return __dwc3_gadget_kick_transfer(dep, 0);
+
+   dwc3_gadget_giveback(dep, req, status);
}
 
/*
-- 
2.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/6] usb: dwc3: gadget: add sg and num_pending_sgs to dwc3_request

2016-08-15 Thread Felipe Balbi
These two fields will be used in a follow-up patch
to track how many entries of request's sglist we
have already processed. The reason is that if a
gadget driver sends an sglist with more entries then
we can fit in the ring, we will have to continue
processing remaining afterwards.

Signed-off-by: Felipe Balbi 
---
 drivers/usb/dwc3/core.h | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 45d6de5107c7..1a6cc48fc7c4 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -685,6 +685,8 @@ struct dwc3_hwparams {
  * @request: struct usb_request to be transferred
  * @list: a list_head used for request queueing
  * @dep: struct dwc3_ep owning this request
+ * @sg: pointer to first incomplete sg
+ * @num_pending_sgs: counter to pending sgs
  * @first_trb_index: index to first trb used by this request
  * @epnum: endpoint number to which this request refers
  * @trb: pointer to struct dwc3_trb
@@ -697,7 +699,9 @@ struct dwc3_request {
struct usb_request  request;
struct list_headlist;
struct dwc3_ep  *dep;
+   struct scatterlist  *sg;
 
+   unsignednum_pending_sgs;
u8  first_trb_index;
u8  epnum;
struct dwc3_trb *trb;
-- 
2.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 v10 5/5] usb: dwc3: add rockchip specific glue layer

2016-08-15 Thread kbuild test robot
Hi William,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.8-rc2 next-20160815]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/William-Wu/support-rockchip-dwc3-driver/20160815-165927
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: m68k-allyesconfig (attached as .config)
compiler: m68k-linux-gcc (GCC) 4.9.0
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=m68k 

All errors (new ones prefixed by >>):

   drivers/usb/dwc3/dwc3-rockchip.c: In function 'dwc3_rockchip_probe':
>> drivers/usb/dwc3/dwc3-rockchip.c:239:2: error: implicit declaration of 
>> function 'of_clk_get_parent_count' [-Werror=implicit-function-declaration]
 count = of_clk_get_parent_count(np);
 ^
   cc1: some warnings being treated as errors

vim +/of_clk_get_parent_count +239 drivers/usb/dwc3/dwc3-rockchip.c

   233  
   234  rockchip = devm_kzalloc(dev, sizeof(*rockchip), GFP_KERNEL);
   235  
   236  if (!rockchip)
   237  return -ENOMEM;
   238  
 > 239  count = of_clk_get_parent_count(np);
   240  if (!count)
   241  return -ENOENT;
   242  

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


Re: [PATCH] xhci: really enqueue zero length TRBs.

2016-08-15 Thread Mathias Nyman

On 12.08.2016 19:45, Alban Browaeys wrote:

Enqueue the first TRB even if full_len is zero.
Without this "adb install " freezes the system.

Signed-off-by: Alban Browaeys 
Fixes: 86065c2719a5 ("xhci: don't rely on precalculated value of needed trbs in the 
enqueue loop")
---
  drivers/usb/host/xhci-ring.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 918e0c739b79..ecefc0e9a037 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -3243,7 +3243,8 @@ int xhci_queue_bulk_tx(struct xhci_hcd *xhci, gfp_t 
mem_flags,
send_addr = addr;

/* Queue the TRBs, even if they are zero-length */
-   for (enqd_len = 0; enqd_len < full_len; enqd_len += trb_buff_len) {
+   for (enqd_len = 0; first_trb || enqd_len < full_len;
+   enqd_len += trb_buff_len) {
field = TRB_TYPE(TRB_NORMAL);

/* TRB buffer should not cross 64KB boundaries */



Nice catch, thanks, I'll send it forward

-Mathias
--
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 v6 4/8] usb: core: add power sequence handling for USB devices

2016-08-15 Thread Peter Chen
Some hard-wired USB devices need to do power sequence to let the
device work normally, the typical power sequence like: enable USB
PHY clock, toggle reset pin, etc. But current Linux USB driver
lacks of such code to do it, it may cause some hard-wired USB devices
works abnormal or can't be recognized by controller at all.

In this patch, it calls power sequence library APIs to finish
the power sequence events. At first, it calls pwrseq_alloc_generic
to create a generic power sequence instance, then it will do power
on sequence at hub's probe for all devices under this hub
(includes root hub).

At hub_disconnect, it will do power off sequence which is at powered
on list.

Signed-off-by: Peter Chen 
Tested-by Joshua Clayton 
---
 drivers/usb/core/Makefile |   1 +
 drivers/usb/core/hub.c|  12 --
 drivers/usb/core/hub.h|  12 ++
 drivers/usb/core/pwrseq.c | 100 ++
 4 files changed, 122 insertions(+), 3 deletions(-)
 create mode 100644 drivers/usb/core/pwrseq.c

diff --git a/drivers/usb/core/Makefile b/drivers/usb/core/Makefile
index 9780877..39f2149 100644
--- a/drivers/usb/core/Makefile
+++ b/drivers/usb/core/Makefile
@@ -9,5 +9,6 @@ usbcore-y += port.o of.o
 
 usbcore-$(CONFIG_PCI)  += hcd-pci.o
 usbcore-$(CONFIG_ACPI) += usb-acpi.o
+usbcore-$(CONFIG_PWRSEQ_GENERIC) += pwrseq.o
 
 obj-$(CONFIG_USB)  += usbcore.o
diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index bee1351..a346a8b 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -1700,6 +1700,7 @@ static void hub_disconnect(struct usb_interface *intf)
hub->error = 0;
hub_quiesce(hub, HUB_DISCONNECT);
 
+   hub_pwrseq_off(hub);
mutex_lock(&usb_port_peer_mutex);
 
/* Avoid races with recursively_mark_NOTATTACHED() */
@@ -1733,6 +1734,7 @@ static int hub_probe(struct usb_interface *intf, const 
struct usb_device_id *id)
struct usb_endpoint_descriptor *endpoint;
struct usb_device *hdev;
struct usb_hub *hub;
+   int ret = -ENODEV;
 
desc = intf->cur_altsetting;
hdev = interface_to_usbdev(intf);
@@ -1839,6 +1841,7 @@ descriptor_error:
INIT_DELAYED_WORK(&hub->leds, led_work);
INIT_DELAYED_WORK(&hub->init_work, NULL);
INIT_WORK(&hub->events, hub_event);
+   INIT_LIST_HEAD(&hub->pwrseq_on_list);
usb_get_intf(intf);
usb_get_dev(hdev);
 
@@ -1852,11 +1855,14 @@ descriptor_error:
if (id->driver_info & HUB_QUIRK_CHECK_PORT_AUTOSUSPEND)
hub->quirk_check_port_auto_suspend = 1;
 
-   if (hub_configure(hub, endpoint) >= 0)
-   return 0;
+   if (hub_configure(hub, endpoint) >= 0) {
+   ret = hub_pwrseq_on(hub);
+   if (!ret)
+   return 0;
+   }
 
hub_disconnect(intf);
-   return -ENODEV;
+   return ret;
 }
 
 static int
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 34c1a7e..9473f6f 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -78,6 +78,7 @@ struct usb_hub {
struct delayed_work init_work;
struct work_struct  events;
struct usb_port **ports;
+   struct list_headpwrseq_on_list; /* powered pwrseq node list */
 };
 
 /**
@@ -166,3 +167,14 @@ static inline int hub_port_debounce_be_stable(struct 
usb_hub *hub,
 {
return hub_port_debounce(hub, port1, false);
 }
+
+#if IS_ENABLED(CONFIG_PWRSEQ_GENERIC)
+int hub_pwrseq_on(struct usb_hub *hub);
+void hub_pwrseq_off(struct usb_hub *hub);
+#else
+static inline int hub_pwrseq_on(struct usb_hub *hub)
+{
+   return 0;
+}
+static inline void hub_pwrseq_off(struct usb_hub *hub) {}
+#endif /* CONFIG_PWRSEQ_GENERIC */
diff --git a/drivers/usb/core/pwrseq.c b/drivers/usb/core/pwrseq.c
new file mode 100644
index 000..837fe66
--- /dev/null
+++ b/drivers/usb/core/pwrseq.c
@@ -0,0 +1,100 @@
+/*
+ * pwrseq.cUSB device power sequence management
+ *
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Author: Peter Chen 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "hub.h"
+
+struct usb_pwrseq_node {
+   struct pwrseq *pwrseq;
+   struct list_head list;
+};
+
+static int hub_of_pwrseq_on(struct device_node *np, struct usb_hub *hub)
+{
+   

[PATCH v6 6/8] ARM: dts: imx6qdl: Enable usb node children with

2016-08-15 Thread Peter Chen
From: Joshua Clayton 

Give usb nodes #address and #size attributes, so that a child node
representing a permanently connected device such as an onboard hub may
be addressed with a  attribute

Signed-off-by: Joshua Clayton 
Signed-off-by: Peter Chen 
---
 arch/arm/boot/dts/imx6qdl.dtsi | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/arch/arm/boot/dts/imx6qdl.dtsi b/arch/arm/boot/dts/imx6qdl.dtsi
index b620ac8..379ace5 100644
--- a/arch/arm/boot/dts/imx6qdl.dtsi
+++ b/arch/arm/boot/dts/imx6qdl.dtsi
@@ -935,6 +935,8 @@
 
usbh1: usb@02184200 {
compatible = "fsl,imx6q-usb", "fsl,imx27-usb";
+   #address-cells = <1>;
+   #size-cells = <0>;
reg = <0x02184200 0x200>;
interrupts = <0 40 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6QDL_CLK_USBOH3>;
@@ -949,6 +951,8 @@
 
usbh2: usb@02184400 {
compatible = "fsl,imx6q-usb", "fsl,imx27-usb";
+   #address-cells = <1>;
+   #size-cells = <0>;
reg = <0x02184400 0x200>;
interrupts = <0 41 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6QDL_CLK_USBOH3>;
@@ -962,6 +966,8 @@
 
usbh3: usb@02184600 {
compatible = "fsl,imx6q-usb", "fsl,imx27-usb";
+   #address-cells = <1>;
+   #size-cells = <0>;
reg = <0x02184600 0x200>;
interrupts = <0 42 IRQ_TYPE_LEVEL_HIGH>;
clocks = <&clks IMX6QDL_CLK_USBOH3>;
-- 
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 v6 7/8] ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property

2016-08-15 Thread Peter Chen
The current dts describes USB HUB's property at USB controller's
entry, it is improper. The USB HUB should be the child node
under USB controller, and power sequence properties are under
it. Besides, using gpio pinctrl setting for USB2415's reset pin.

Signed-off-by: Peter Chen 
Signed-off-by: Joshua Clayton 
---
 arch/arm/boot/dts/imx6qdl-udoo.dtsi | 26 --
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/arch/arm/boot/dts/imx6qdl-udoo.dtsi 
b/arch/arm/boot/dts/imx6qdl-udoo.dtsi
index 3bee2f9..87fe31f 100644
--- a/arch/arm/boot/dts/imx6qdl-udoo.dtsi
+++ b/arch/arm/boot/dts/imx6qdl-udoo.dtsi
@@ -9,6 +9,8 @@
  *
  */
 
+#include 
+
 / {
aliases {
backlight = &backlight;
@@ -58,17 +60,6 @@
#address-cells = <1>;
#size-cells = <0>;
 
-   reg_usb_h1_vbus: regulator@0 {
-   compatible = "regulator-fixed";
-   reg = <0>;
-   regulator-name = "usb_h1_vbus";
-   regulator-min-microvolt = <500>;
-   regulator-max-microvolt = <500>;
-   enable-active-high;
-   startup-delay-us = <2>; /* USB2415 requires a POR of 1 
us minimum */
-   gpio = <&gpio7 12 0>;
-   };
-
reg_panel: regulator@1 {
compatible = "regulator-fixed";
reg = <1>;
@@ -188,7 +179,7 @@
 
pinctrl_usbh: usbhgrp {
fsl,pins = <
-   MX6QDL_PAD_GPIO_17__GPIO7_IO12 0x8000
+   MX6QDL_PAD_GPIO_17__GPIO7_IO12  0x1b0b0
MX6QDL_PAD_NANDF_CS2__CCM_CLKO2 0x130b0
>;
};
@@ -259,9 +250,16 @@
 &usbh1 {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_usbh>;
-   vbus-supply = <®_usb_h1_vbus>;
-   clocks = <&clks IMX6QDL_CLK_CKO>;
status = "okay";
+
+   usb2415: hub@1 {
+   compatible = "usb424,2514";
+   reg = <1>;
+
+   clocks = <&clks IMX6QDL_CLK_CKO>;
+   reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>;
+   reset-duration-us = <3000>;
+   };
 };
 
 &usdhc3 {
-- 
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 v6 8/8] ARM: dts: imx6q-evi: Fix onboard hub reset line

2016-08-15 Thread Peter Chen
From: Joshua Clayton 

Previously the onboard hub was made to work by treating its
reset gpio as a regulator enable.
Get rid of that kludge now that pwseq has added reset gpio support
Move pin muxing the hub reset pin into the usbh1 group

Signed-off-by: Joshua Clayton 
Signed-off-by: Peter Chen 
---
 arch/arm/boot/dts/imx6q-evi.dts | 25 +++--
 1 file changed, 7 insertions(+), 18 deletions(-)

diff --git a/arch/arm/boot/dts/imx6q-evi.dts b/arch/arm/boot/dts/imx6q-evi.dts
index 4fa5601..49c6f61 100644
--- a/arch/arm/boot/dts/imx6q-evi.dts
+++ b/arch/arm/boot/dts/imx6q-evi.dts
@@ -54,18 +54,6 @@
reg = <0x1000 0x4000>;
};
 
-   reg_usbh1_vbus: regulator-usbhubreset {
-   compatible = "regulator-fixed";
-   regulator-name = "usbh1_vbus";
-   regulator-min-microvolt = <500>;
-   regulator-max-microvolt = <500>;
-   enable-active-high;
-   startup-delay-us = <2>;
-   pinctrl-names = "default";
-   pinctrl-0 = <&pinctrl_usbh1_hubreset>;
-   gpio = <&gpio7 12 GPIO_ACTIVE_HIGH>;
-   };
-
reg_usb_otg_vbus: regulator-usbotgvbus {
compatible = "regulator-fixed";
regulator-name = "usb_otg_vbus";
@@ -204,12 +192,18 @@
 };
 
 &usbh1 {
-   vbus-supply = <®_usbh1_vbus>;
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_usbh1>;
dr_mode = "host";
disable-over-current;
status = "okay";
+
+   usb2415host: hub@1 {
+   compatible = "usb424,2513";
+   reg = <1>;
+   reset-gpios = <&gpio7 12 GPIO_ACTIVE_LOW>;
+   reset-duration-us = <3000>;
+   };
 };
 
 &usbotg {
@@ -467,11 +461,6 @@
MX6QDL_PAD_GPIO_3__USB_H1_OC 0x1b0b0
/* usbh1_b OC */
MX6QDL_PAD_GPIO_0__GPIO1_IO00 0x1b0b0
-   >;
-   };
-
-   pinctrl_usbh1_hubreset: usbh1hubresetgrp {
-   fsl,pins = <
MX6QDL_PAD_GPIO_17__GPIO7_IO12 0x1b0b0
>;
};
-- 
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 v6 5/8] usb: chipidea: let chipidea core device of_node equal's glue layer device of_node

2016-08-15 Thread Peter Chen
From: Peter Chen 

At device tree, we have no device node for chipidea core,
the glue layer's node is the parent node for host and udc
device. But in related driver, the parent device is chipidea
core. So, in order to let the common driver get parent's node,
we let the core's device node equals glue layer device node.

Signed-off-by: Peter Chen 
Tested-by: Maciej S. Szmigiero 
Tested-by Joshua Clayton 
---
 drivers/usb/chipidea/core.c | 27 ++-
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
index 69426e6..6839e19 100644
--- a/drivers/usb/chipidea/core.c
+++ b/drivers/usb/chipidea/core.c
@@ -927,6 +927,16 @@ static int ci_hdrc_probe(struct platform_device *pdev)
return -ENODEV;
}
 
+   /*
+* At device tree, we have no device node for chipidea core,
+* the glue layer's node is the parent node for host and udc
+* device. But in related driver, the parent device is chipidea
+* core. So, in order to let the common driver get parent's node,
+* we let the core's device node equals glue layer's node.
+*/
+   if (dev->parent && dev->parent->of_node)
+   dev->of_node = dev->parent->of_node;
+
if (ci->platdata->phy) {
ci->phy = ci->platdata->phy;
} else if (ci->platdata->usb_phy) {
@@ -937,11 +947,15 @@ static int ci_hdrc_probe(struct platform_device *pdev)
 
/* if both generic PHY and USB PHY layers aren't enabled */
if (PTR_ERR(ci->phy) == -ENOSYS &&
-   PTR_ERR(ci->usb_phy) == -ENXIO)
-   return -ENXIO;
+   PTR_ERR(ci->usb_phy) == -ENXIO) {
+   ret = -ENXIO;
+   goto clear_of_node;
+   }
 
-   if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy))
-   return -EPROBE_DEFER;
+   if (IS_ERR(ci->phy) && IS_ERR(ci->usb_phy)) {
+   ret = -EPROBE_DEFER;
+   goto clear_of_node;
+   }
 
if (IS_ERR(ci->phy))
ci->phy = NULL;
@@ -952,7 +966,7 @@ static int ci_hdrc_probe(struct platform_device *pdev)
ret = ci_usb_phy_init(ci);
if (ret) {
dev_err(dev, "unable to init phy: %d\n", ret);
-   return ret;
+   goto clear_of_node;
}
 
ci->hw_bank.phys = res->start;
@@ -1058,6 +1072,8 @@ stop:
ci_role_destroy(ci);
 deinit_phy:
ci_usb_phy_exit(ci);
+clear_of_node:
+   dev->of_node = NULL;
 
return ret;
 }
@@ -1076,6 +1092,7 @@ static int ci_hdrc_remove(struct platform_device *pdev)
ci_extcon_unregister(ci);
ci_role_destroy(ci);
ci_hdrc_enter_lpm(ci, true);
+   ci->dev->of_node = NULL;
ci_usb_phy_exit(ci);
 
return 0;
-- 
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 v6 2/8] power: add power sequence library

2016-08-15 Thread Peter Chen
We have an well-known problem that the device needs to do some power
sequence before it can be recognized by related host, the typical
example like hard-wired mmc devices and usb devices.

This power sequence is hard to be described at device tree and handled by
related host driver, so we have created a common power sequence
library to cover this requirement. The core code has supplied
some common helpers for host driver, and individual power sequence
libraries handle kinds of power sequence for devices.

pwrseq_generic is intended for general purpose of power sequence, which
handles gpios and clocks currently, and can cover regulator and pinctrl
in future. The host driver calls pwrseq_alloc_generic to create
an generic pwrseq instance.

Signed-off-by: Peter Chen 
Tested-by Joshua Clayton 
Reviewed-by: Matthias Kaehlcke 
Tested-by: Matthias Kaehlcke 
---
 MAINTAINERS   |   9 ++
 drivers/power/Kconfig |   1 +
 drivers/power/Makefile|   1 +
 drivers/power/pwrseq/Kconfig  |  20 
 drivers/power/pwrseq/Makefile |   2 +
 drivers/power/pwrseq/core.c   |  62 +
 drivers/power/pwrseq/pwrseq_generic.c | 168 ++
 include/linux/power/pwrseq.h  |  47 ++
 8 files changed, 310 insertions(+)
 create mode 100644 drivers/power/pwrseq/Kconfig
 create mode 100644 drivers/power/pwrseq/Makefile
 create mode 100644 drivers/power/pwrseq/core.c
 create mode 100644 drivers/power/pwrseq/pwrseq_generic.c
 create mode 100644 include/linux/power/pwrseq.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 1ae6c84..407254b 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -9283,6 +9283,15 @@ F:   include/linux/pm_*
 F: include/linux/powercap.h
 F: drivers/powercap/
 
+POWER SEQUENCE LIBRARY
+M: Peter Chen 
+T: git git://git.kernel.org/pub/scm/linux/kernel/git/peter.chen/usb.git
+L: linux...@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/power/pwrseq/
+F: drivers/power/pwrseq/
+F: include/linux/power/pwrseq.h/
+
 POWER SUPPLY CLASS/SUBSYSTEM and DRIVERS
 M: Sebastian Reichel 
 M: Dmitry Eremin-Solenikov 
diff --git a/drivers/power/Kconfig b/drivers/power/Kconfig
index acd4a15..f6aa4fd 100644
--- a/drivers/power/Kconfig
+++ b/drivers/power/Kconfig
@@ -515,3 +515,4 @@ endif # POWER_SUPPLY
 
 source "drivers/power/reset/Kconfig"
 source "drivers/power/avs/Kconfig"
+source "drivers/power/pwrseq/Kconfig"
diff --git a/drivers/power/Makefile b/drivers/power/Makefile
index e46b75d..4ed2e12 100644
--- a/drivers/power/Makefile
+++ b/drivers/power/Makefile
@@ -74,3 +74,4 @@ obj-$(CONFIG_CHARGER_TPS65217)+= tps65217_charger.o
 obj-$(CONFIG_POWER_RESET)  += reset/
 obj-$(CONFIG_AXP288_FUEL_GAUGE) += axp288_fuel_gauge.o
 obj-$(CONFIG_AXP288_CHARGER)   += axp288_charger.o
+obj-$(CONFIG_POWER_SEQUENCE)   += pwrseq/
diff --git a/drivers/power/pwrseq/Kconfig b/drivers/power/pwrseq/Kconfig
new file mode 100644
index 000..188729e
--- /dev/null
+++ b/drivers/power/pwrseq/Kconfig
@@ -0,0 +1,20 @@
+#
+# Power Sequence library
+#
+
+config POWER_SEQUENCE
+   bool
+
+menu "Power Sequence Support"
+
+config PWRSEQ_GENERIC
+   bool "Generic power sequence control"
+   depends on OF
+   select POWER_SEQUENCE
+   help
+ It is used for drivers which needs to do power sequence
+ (eg, turn on clock, toggle reset gpio) before the related
+ devices can be found by hardware. This generic one can be
+ used for common power sequence control.
+
+endmenu
diff --git a/drivers/power/pwrseq/Makefile b/drivers/power/pwrseq/Makefile
new file mode 100644
index 000..ad82389
--- /dev/null
+++ b/drivers/power/pwrseq/Makefile
@@ -0,0 +1,2 @@
+obj-$(CONFIG_POWER_SEQUENCE) += core.o
+obj-$(CONFIG_PWRSEQ_GENERIC) += pwrseq_generic.o
diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c
new file mode 100644
index 000..dcf96c4
--- /dev/null
+++ b/drivers/power/pwrseq/core.c
@@ -0,0 +1,62 @@
+/*
+ * core.c  power sequence core file
+ *
+ * Copyright (C) 2016 Freescale Semiconductor, Inc.
+ * Author: Peter Chen 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see .
+ */
+
+#include 
+
+static DEFINE_MUTEX(pwrseq_list_mutex);
+static LIST_HEAD(pwrseq_list);
+
+int pwrseq_get(struct device_node *np, struct pwrseq *p)
+{
+   if (p && p->get)
+

[PATCH v6 1/8] binding-doc: power: pwrseq-generic: add binding doc for generic power sequence library

2016-08-15 Thread Peter Chen
Add binding doc for generic power sequence library.

Signed-off-by: Peter Chen 
Acked-by: Philipp Zabel 
Acked-by: Rob Herring 
---
 .../bindings/power/pwrseq/pwrseq-generic.txt   | 48 ++
 1 file changed, 48 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt

diff --git a/Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt 
b/Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt
new file mode 100644
index 000..ebf0d47
--- /dev/null
+++ b/Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt
@@ -0,0 +1,48 @@
+The generic power sequence library
+
+Some hard-wired devices (eg USB/MMC) need to do power sequence before
+the device can be enumerated on the bus, the typical power sequence
+like: enable USB PHY clock, toggle reset pin, etc. But current
+Linux device driver lacks of such code to do it, it may cause some
+hard-wired devices works abnormal or can't be recognized by
+controller at all. The power sequence will be done before this device
+can be found at the bus.
+
+The power sequence properties is under the device node.
+
+Optional properties:
+- clocks: the input clocks for device.
+- reset-gpios: Should specify the GPIO for reset.
+- reset-duration-us: the duration in microsecond for assert reset signal.
+
+Below is the example of USB power sequence properties on USB device
+nodes which have two level USB hubs.
+
+&usbotg1 {
+   vbus-supply = <®_usb_otg1_vbus>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&pinctrl_usb_otg1_id>;
+   status = "okay";
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+   genesys: hub@1 {
+   compatible = "usb5e3,608";
+   reg = <1>;
+
+   clocks = <&clks IMX6SX_CLK_CKO>;
+   reset-gpios = <&gpio4 5 GPIO_ACTIVE_LOW>; /* hub reset pin */
+   reset-duration-us = <10>;
+
+   #address-cells = <1>;
+   #size-cells = <0>;
+   asix: ethernet@1 {
+   compatible = "usbb95,1708";
+   reg = <1>;
+
+   clocks = <&clks IMX6SX_CLK_IPG>;
+   reset-gpios = <&gpio4 6 GPIO_ACTIVE_LOW>; /* 
ethernet_rst */
+   reset-duration-us = <15>;
+   };
+   };
+};
-- 
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 v6 3/8] binding-doc: usb: usb-device: add optional properties for power sequence

2016-08-15 Thread Peter Chen
Add optional properties for power sequence.

Signed-off-by: Peter Chen 
Acked-by: Rob Herring 
---
 Documentation/devicetree/bindings/usb/usb-device.txt | 10 +-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-device.txt 
b/Documentation/devicetree/bindings/usb/usb-device.txt
index 1c35e7b..3661dd2 100644
--- a/Documentation/devicetree/bindings/usb/usb-device.txt
+++ b/Documentation/devicetree/bindings/usb/usb-device.txt
@@ -13,6 +13,10 @@ Required properties:
 - reg: the port number which this device is connecting to, the range
   is 1-31.
 
+Optional properties:
+power sequence properties, see
+Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt for detail
+
 Example:
 
 &usb1 {
@@ -21,8 +25,12 @@ Example:
#address-cells = <1>;
#size-cells = <0>;
 
-   hub: genesys@1 {
+   genesys: hub@1 {
compatible = "usb5e3,608";
reg = <1>;
+
+   clocks = <&clks IMX6SX_CLK_CKO>;
+   reset-gpios = <&gpio4 5 GPIO_ACTIVE_LOW>; /* hub reset pin */
+   reset-duration-us = <10>;
};
 }
-- 
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 v6 0/8] power: add power sequence library

2016-08-15 Thread Peter Chen
Hi all,

This is a follow-up for my last power sequence framework patch set [1].
According to Rob Herring and Ulf Hansson's comments[2], I use a generic
power sequence library for parsing the power sequence elements on DT,
and implement generic power sequence on library. The host driver
can allocate power sequence instance, and calls pwrseq APIs accordingly.

In future, if there are special power sequence requirements, the special
power sequence library can be created.

This patch set is tested on i.mx6 sabresx evk using a dts change, I use
two hot-plug devices to simulate this use case, the related binding
change is updated at patch [1/6], The udoo board changes were tested
using my last power sequence patch set.[3]

Except for hard-wired MMC and USB devices, I find the USB ULPI PHY also
need to power on itself before it can be found by ULPI bus.

[1] http://www.spinics.net/lists/linux-usb/msg142755.html
[2] http://www.spinics.net/lists/linux-usb/msg143106.html
[3] http://www.spinics.net/lists/linux-usb/msg142815.html

Changes for v6:
- Add Matthias Kaehlcke's Reviewed-by and Tested-by. (patch [2/6])
- Change chipidea core of_node assignment for coming user. (patch [5/6])
- Applies Joshua Clayton's three dts changes for two boards,
  the USB device's reg has only #address-cells, but without #size-cells.

Changes for v5:
- Delete pwrseq_register/pwrseq_unregister, which is useless currently
- Fix the linker error when the pwrseq user is compiled as module

Changes for v4:
- Create the patch on next-20160722 
- Fix the of_node is not NULL after chipidea driver is unbinded [Patch 5/6]
- Using more friendly wait method for reset gpio [Patch 2/6]
- Support multiple input clocks [Patch 2/6]
- Add Rob Herring's ack for DT changes
- Add Joshua Clayton's Tested-by

Changes for v3:
- Delete "power-sequence" property at binding-doc, and change related code
  at both library and user code.
- Change binding-doc example node name with Rob's comments
- of_get_named_gpio_flags only gets the gpio, but without setting gpio flags,
  add additional code request gpio with proper gpio flags
- Add Philipp Zabel's Ack and MAINTAINER's entry

Changes for v2:
- Delete "pwrseq" prefix and clock-names for properties at dt binding
- Should use structure not but its pointer for kzalloc
- Since chipidea core has no of_node, let core's of_node equals glue
  layer's at core's probe

Joshua Clayton (2):
  ARM: dts: imx6qdl: Enable usb node children with 
  ARM: dts: imx6q-evi: Fix onboard hub reset line

Peter Chen (6):
  binding-doc: power: pwrseq-generic: add binding doc for generic power
sequence library
  power: add power sequence library
  binding-doc: usb: usb-device: add optional properties for power
sequence
  usb: core: add power sequence handling for USB devices
  usb: chipidea: let chipidea core device of_node equal's glue layer
device of_node
  ARM: dts: imx6qdl-udoo.dtsi: fix onboard USB HUB property

 .../bindings/power/pwrseq/pwrseq-generic.txt   |  48 ++
 .../devicetree/bindings/usb/usb-device.txt |  10 +-
 MAINTAINERS|   9 ++
 arch/arm/boot/dts/imx6q-evi.dts|  25 +--
 arch/arm/boot/dts/imx6qdl-udoo.dtsi|  26 ++--
 arch/arm/boot/dts/imx6qdl.dtsi |   6 +
 drivers/power/Kconfig  |   1 +
 drivers/power/Makefile |   1 +
 drivers/power/pwrseq/Kconfig   |  20 +++
 drivers/power/pwrseq/Makefile  |   2 +
 drivers/power/pwrseq/core.c|  62 
 drivers/power/pwrseq/pwrseq_generic.c  | 168 +
 drivers/usb/chipidea/core.c|  27 +++-
 drivers/usb/core/Makefile  |   1 +
 drivers/usb/core/hub.c |  12 +-
 drivers/usb/core/hub.h |  12 ++
 drivers/usb/core/pwrseq.c  | 100 
 include/linux/power/pwrseq.h   |  47 ++
 18 files changed, 536 insertions(+), 41 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/power/pwrseq/pwrseq-generic.txt
 create mode 100644 drivers/power/pwrseq/Kconfig
 create mode 100644 drivers/power/pwrseq/Makefile
 create mode 100644 drivers/power/pwrseq/core.c
 create mode 100644 drivers/power/pwrseq/pwrseq_generic.c
 create mode 100644 drivers/usb/core/pwrseq.c
 create mode 100644 include/linux/power/pwrseq.h

-- 
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] cdc-wdm: cleanup debug messages

2016-08-15 Thread Oliver Neukum
Dynamic debugging will already add the function (and the line number)
to a debug message if one requests that. It makes no sense to add
them unconditionally in a driver.

Signed-off-by: Oliver Neukum 
---
 drivers/usb/class/cdc-wdm.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 56d3ab8..bf4bb58 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -314,8 +314,7 @@ static void wdm_int_callback(struct urb *urb)
&& !test_bit(WDM_DISCONNECTING, &desc->flags)
&& !test_bit(WDM_SUSPENDING, &desc->flags)) {
rv = usb_submit_urb(desc->response, GFP_ATOMIC);
-   dev_dbg(&desc->intf->dev, "%s: usb_submit_urb %d",
-   __func__, rv);
+   dev_dbg(&desc->intf->dev, "submit response URB %d", rv);
}
spin_unlock(&desc->iuspin);
if (rv < 0) {
@@ -574,7 +573,7 @@ retry:
}
 
if (!desc->reslength) { /* zero length read */
-   dev_dbg(&desc->intf->dev, "%s: zero length - clearing 
WDM_READ\n", __func__);
+   dev_dbg(&desc->intf->dev, "zero length - clearing 
WDM_READ");
clear_bit(WDM_READ, &desc->flags);
rv = service_outstanding_interrupt(desc);
spin_unlock_irq(&desc->iuspin);
@@ -1081,7 +1080,7 @@ static void wdm_disconnect(struct usb_interface *intf)
if (!desc->count)
cleanup(desc);
else
-   dev_dbg(&intf->dev, "%s: %d open files - postponing cleanup\n", 
__func__, desc->count);
+   dev_dbg(&intf->dev, "%d open files - postponing cleanup\n", 
desc->count);
mutex_unlock(&wdm_mutex);
 }
 
-- 
2.1.4

--
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 v10 5/5] usb: dwc3: add rockchip specific glue layer

2016-08-15 Thread William Wu
Add rockchip specific glue layer to support USB3 Peripheral mode
and Host mode on rockchip platforms (e.g. rk3399).

The DesignWare USB3 integrated in rockchip SoCs is a configurable
IP Core which can be instantiated as Dual-Role Device (DRD), Host
Only (XHCI) and Peripheral Only configurations.

We use extcon notifier to manage usb cable detection and mode switch.
Enable DWC3 PM runtime auto suspend to allow core enter runtime_suspend
if USB cable is dettached. For host mode, it requires to keep whole
DWC3 controller in reset state to hold pipe power state in P2 before
initializing PHY. And it need to reconfigure USB PHY interface of DWC3
core after deassert DWC3 controller reset.

The current driver supports Host only and Peripheral Only well, for
now, we will add support for OTG after we have it all stabilized.

Signed-off-by: William Wu 
---
Changes in v10:
- fix building error

Changes in v9:
- Add a new dwc3-rockchip.c driver for rk3399, rather than use dwc3-of-simple.c

 drivers/usb/dwc3/Kconfig |   9 +
 drivers/usb/dwc3/Makefile|   1 +
 drivers/usb/dwc3/core.c  |   2 +-
 drivers/usb/dwc3/core.h  |   1 +
 drivers/usb/dwc3/dwc3-rockchip.c | 441 +++
 5 files changed, 453 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/dwc3/dwc3-rockchip.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index a64ce1c..3d5ec30 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -96,6 +96,15 @@ config USB_DWC3_OF_SIMPLE
 Currently supports Xilinx and Qualcomm DWC USB3 IP.
 Say 'Y' or 'M' if you have one such device.
 
+config USB_DWC3_ROCKCHIP
+   tristate "Rockchip Platforms"
+   depends on EXTCON && (ARCH_ROCKCHIP || COMPILE_TEST)
+   depends on OF
+   default USB_DWC3
+   help
+ Support of USB2/3 functionality in Rockchip platforms.
+ say 'Y' or 'M' if you have one such device.
+
 config USB_DWC3_ST
tristate "STMicroelectronics Platforms"
depends on ARCH_STI && OF
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 22420e1..86fc4fd 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -38,4 +38,5 @@ obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
 obj-$(CONFIG_USB_DWC3_KEYSTONE)+= dwc3-keystone.o
 obj-$(CONFIG_USB_DWC3_OF_SIMPLE)   += dwc3-of-simple.o
+obj-$(CONFIG_USB_DWC3_ROCKCHIP)+= dwc3-rockchip.o
 obj-$(CONFIG_USB_DWC3_ST)  += dwc3-st.o
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index e887b38..3da6215 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -405,7 +405,7 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc)
  * initialized. The PHY interfaces and the PHYs get initialized together with
  * the core in dwc3_core_init.
  */
-static int dwc3_phy_setup(struct dwc3 *dwc)
+int dwc3_phy_setup(struct dwc3 *dwc)
 {
u32 reg;
int ret;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 3d94acd..79403ff 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1123,6 +1123,7 @@ struct dwc3_gadget_ep_cmd_params {
 /* prototypes */
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
+int dwc3_phy_setup(struct dwc3 *dwc);
 
 /* check whether we are on the DWC_usb31 core */
 static inline bool dwc3_is_usb31(struct dwc3 *dwc)
diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
new file mode 100644
index 000..eeae1a9
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-rockchip.c
@@ -0,0 +1,441 @@
+/**
+ * dwc3-rockchip.c - Rockchip Specific Glue layer
+ *
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *
+ * Authors: William Wu 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+#include "io.h"
+
+#define DWC3_ROCKCHIP_AUTOSUSPEND_DELAY  500 /* ms */
+
+struct dwc3_rockchip {
+   int num_clocks;
+   struct device   *dev;
+   struct clk  **clks;
+   struct dwc3 *dwc;
+   struct reset_control*otg_rst;
+   struct extcon_dev   *edev;
+   struct notifier_block   device_nb;
+   struct notifier_block   host_nb;
+   struct work_struct  otg_work;
+};
+

[PATCH v10 4/5] usb: dwc3: rockchip: add devicetree bindings documentation

2016-08-15 Thread William Wu
This patch adds the devicetree documentation required for Rockchip
USB3.0 core wrapper consisting of USB3.0 IP from Synopsys.

It supports DRD mode, and could operate in device mode (SS, HS, FS)
and host mode (SS, HS, FS, LS).

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v10:
- None

Changes in v9:
- add required properties "resets" and "reset-names"
- add optional property "extcon"

Changes in v8:
- None

Changes in v7:
- add Acked-by (Rob Herring)

Changes in v6:
- rename bus_clk, and add usbdrd3_1 node as an example (Heiko)

Changes in v5:
- rename clock-names, and remove unnecessary clocks (Heiko)

Changes in v4:
- modify commit log, and add phy documentation location (Sergei)

Changes in v3:
- add dwc3 address (balbi)

Changes in v2:
- add rockchip,dwc3.txt to Documentation/devicetree/bindings/ (balbi, Brian)

 .../devicetree/bindings/usb/rockchip,dwc3.txt  | 71 ++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/rockchip,dwc3.txt

diff --git a/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt 
b/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
new file mode 100644
index 000..3a79be8
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
@@ -0,0 +1,71 @@
+Rockchip SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:  should contain "rockchip,rk3399-dwc3" for rk3399 SoC
+- clocks:  A list of phandle + clock-specifier pairs for the
+   clocks listed in clock-names
+- clock-names: Should contain the following:
+  "ref_clk"Controller reference clk, have to be 24 MHz
+  "suspend_clk"Controller suspend clk, have to be 24 MHz or 32 KHz
+  "bus_clk"Master/Core clock, have to be >= 62.5 MHz for SS
+   operation and >= 30MHz for HS operation
+  "grf_clk"Controller grf clk
+- resets:  List of phandle and reset specifier pairs. Should contain
+   softreset line of the DWC3 controller
+- reset-names: List of reset signal names. Names should contain "usb3-otg"
+   for DWC3 controller reset.
+
+Optional properties:
+- extcon:  Phandles to external connector devices, which provide
+   "EXTCON_USB" and "EXTCON_USB_HOST" cable events.
+
+Required child node:
+A child node must exist to represent the core DWC3 IP block. The name of
+the node is not important. The content of the node is defined in dwc3.txt.
+
+Phy documentation is provided in the following places:
+Documentation/devicetree/bindings/phy/rockchip,dwc3-usb-phy.txt
+
+Example device nodes:
+
+   usbdrd3_0: usb@fe80 {
+   compatible = "rockchip,rk3399-dwc3";
+   clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>,
+<&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_GRF>;
+   clock-names = "ref_clk", "suspend_clk",
+ "bus_clk", "grf_clk";
+   resets = <&cru SRST_A_USB3_OTG0>;
+   reset-names = "usb3-otg";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "disabled";
+   usbdrd_dwc3_0: dwc3@fe80 {
+   compatible = "snps,dwc3";
+   reg = <0x0 0xfe80 0x0 0x10>;
+   interrupts = ;
+   dr_mode = "otg";
+   status = "disabled";
+   };
+   };
+
+   usbdrd3_1: usb@fe90 {
+   compatible = "rockchip,rk3399-dwc3";
+   clocks = <&cru SCLK_USB3OTG1_REF>, <&cru SCLK_USB3OTG1_SUSPEND>,
+<&cru ACLK_USB3OTG1>, <&cru ACLK_USB3_GRF>;
+   clock-names = "ref_clk", "suspend_clk",
+ "bus_clk", "grf_clk";
+   resets = <&cru SRST_A_USB3_OTG1>;
+   reset-names = "usb3-otg";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "disabled";
+   usbdrd_dwc3_1: dwc3@fe90 {
+   compatible = "snps,dwc3";
+   reg = <0x0 0xfe90 0x0 0x10>;
+   interrupts = ;
+   dr_mode = "otg";
+   status = "disabled";
+   };
+   };
-- 
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 v10 3/5] usb: dwc3: add dis_del_phy_power_chg_quirk

2016-08-15 Thread William Wu
Add a quirk to clear the GUSB3PIPECTL.DELAYP1TRANS bit,
which specifies whether disable delay PHY power change
from P0 to P1/P2/P3 when link state changing from U0
to U1/U2/U3 respectively.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v10:
- None

Changes in v9:
- None

Changes in v8:
- add Acked-by (Rob Herring)

Changes in v7:
- None

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- None

 Documentation/devicetree/bindings/usb/dwc3.txt | 2 ++
 drivers/usb/dwc3/core.c| 5 +
 drivers/usb/dwc3/core.h| 3 +++
 3 files changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index 020b0e9..e96bfc2 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -42,6 +42,8 @@ Optional properties:
  - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists
in GUSB2PHYCFG, specify that USB2 PHY doesn't provide
a free-running PHY clock.
+ - snps,dis-del-phy-power-chg-quirk: when set core will change PHY power
+   from P0 to P1/P2/P3 without delay.
  - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
utmi_l1_suspend_n, false when asserts utmi_sleep_n
  - snps,hird-threshold: HIRD threshold
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index cdac019..e887b38 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -448,6 +448,9 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
if (dwc->dis_u3_susphy_quirk)
reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
 
+   if (dwc->dis_del_phy_power_chg_quirk)
+   reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE;
+
dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
 
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
@@ -947,6 +950,8 @@ static int dwc3_probe(struct platform_device *pdev)
"snps,dis_rxdet_inp3_quirk");
dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
"snps,dis-u2-freeclk-exists-quirk");
+   dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
+   "snps,dis-del-phy-power-chg-quirk");
 
dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
"snps,tx_de_emphasis_quirk");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index cc4f551..3d94acd 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -818,6 +818,8 @@ struct dwc3_scratchpad_array {
  * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
  * in GUSB2PHYCFG, specify that USB2 PHY doesn't
  * provide a free-running PHY clock.
+ * @dis_del_phy_power_chg_quirk: set if we disable delay phy power
+ * change quirk.
  * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  * @tx_de_emphasis: Tx de-emphasis value
  * 0   - -6dB de-emphasis
@@ -963,6 +965,7 @@ struct dwc3 {
unsigneddis_enblslpm_quirk:1;
unsigneddis_rxdet_inp3_quirk:1;
unsigneddis_u2_freeclk_exists_quirk:1;
+   unsigneddis_del_phy_power_chg_quirk:1;
 
unsignedtx_de_emphasis_quirk:1;
unsignedtx_de_emphasis:2;
-- 
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 v10 2/5] usb: dwc3: make usb2 phy utmi interface configurable

2016-08-15 Thread William Wu
Support to configure the UTMI+ PHY with an 8- or 16-bit
interface via DT. The UTMI+ PHY interface is a hardware
capability, and it's platform dependent. Normally, the
PHYIF can be configured during coreconsultant.

But for some specific USB cores(e.g. rk3399 SoC DWC3),
the default PHYIF configuration value is false, so we
need to reconfigure it by software.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v10:
- None

Changes in v9:
- None

Changes in v8:
- configure utmi interface via phy_type property in DT (Heiko, Rob Herring)
- add Acked-by (Rob Herring)
- modify commit message (Rob Herring)

Changes in v7:
- remove quirk and use only one property to configure utmi (Heiko, Rob Herring)

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- add a quirk for phyif_utmi (balbi)

 Documentation/devicetree/bindings/usb/generic.txt |  6 ++
 drivers/usb/dwc3/core.c   | 18 ++
 drivers/usb/dwc3/core.h   | 12 
 3 files changed, 36 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
b/Documentation/devicetree/bindings/usb/generic.txt
index bba8257..bfadeb1 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -11,6 +11,11 @@ Optional properties:
"peripheral" and "otg". In case this attribute isn't
passed via DT, USB DRD controllers should default to
OTG.
+ - phy_type: tells USB controllers that we want to configure the core to 
support
+   a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+   selected. Valid arguments are "utmi" and "utmi_wide".
+   In case this isn't passed via DT, USB controllers should
+   default to HW capability.
  - otg-rev: tells usb driver the release number of the OTG and EH supplement
with which the device and its descriptors are compliant,
in binary-coded decimal (i.e. 2.0 is 0200H). This
@@ -34,6 +39,7 @@ dwc3@4a03 {
usb-phy = <&usb2_phy>, <&usb3,phy>;
maximum-speed = "super-speed";
dr_mode = "otg";
+   phy_type = "utmi_wide";
otg-rev = <0x0200>;
adp-disable;
 };
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 14316e5..cdac019 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -485,6 +485,23 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
break;
}
 
+   switch (dwc->hsphy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+  DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
+  DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+  DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
+  DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
+   break;
+   default:
+   break;
+   }
+
/*
 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
 * '0' during coreConsultant configuration. So default value will
@@ -891,6 +908,7 @@ static int dwc3_probe(struct platform_device *pdev)
 
dwc->maximum_speed = usb_get_maximum_speed(dev);
dwc->dr_mode = usb_get_dr_mode(dev);
+   dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
 
dwc->has_lpm_erratum = device_property_read_bool(dev,
"snps,has-lpm-erratum");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 08ed9e0..cc4f551 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -203,6 +203,14 @@
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
 #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4)
 #define DWC3_GUSB2PHYCFG_ENBLSLPM  (1 << 8)
+#define DWC3_GUSB2PHYCFG_PHYIF(n)  (n << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_MASKDWC3_GUSB2PHYCFG_PHYIF(1)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM(n)  (n << 10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASKDWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
+#define USBTRDTIM_UTMI_8_BIT   9
+#define USBTRDTIM_UTMI_16_BIT  5
+#define UTMI_PHYIF_16_BIT  1
+#define UTMI_PHYIF_8_BIT   0
 
 /* Global USB2 PHY Vendor Control Register */
 #define DWC3_GUSB2PHYACC_NEWREGREQ (1 << 25)
@@ -748,6 +756,9 @@ struct dwc3_scratchpad_array {
  * @maximum_speed: maximum speed requested (mainly for testing purposes)
  * @revision: revision register

[PATCH v10 1/5] usb: dwc3: add dis_u2_freeclk_exists_quirk

2016-08-15 Thread William Wu
Add a quirk to clear the GUSB2PHYCFG.U2_FREECLK_EXISTS bit,
which specifies whether the USB2.0 PHY provides a free-running
PHY clock, which is active when the clock control input is active.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v10:
- None

Changes in v9:
- None

Changes in v8:
- add Acked-by (Rob Herring)

Changes in v7:
- None

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- None

 Documentation/devicetree/bindings/usb/dwc3.txt | 3 +++
 drivers/usb/dwc3/core.c| 5 +
 drivers/usb/dwc3/core.h| 5 +
 3 files changed, 13 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index 7d7ce08..020b0e9 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -39,6 +39,9 @@ Optional properties:
disabling the suspend signal to the PHY.
  - snps,dis_rxdet_inp3_quirk: when set core will disable receiver detection
in PHY P3 power state.
+ - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists
+   in GUSB2PHYCFG, specify that USB2 PHY doesn't provide
+   a free-running PHY clock.
  - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
utmi_l1_suspend_n, false when asserts utmi_sleep_n
  - snps,hird-threshold: HIRD threshold
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 35d0924..14316e5 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -500,6 +500,9 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
if (dwc->dis_enblslpm_quirk)
reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
 
+   if (dwc->dis_u2_freeclk_exists_quirk)
+   reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS;
+
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
return 0;
@@ -924,6 +927,8 @@ static int dwc3_probe(struct platform_device *pdev)
"snps,dis_enblslpm_quirk");
dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
"snps,dis_rxdet_inp3_quirk");
+   dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
+   "snps,dis-u2-freeclk-exists-quirk");
 
dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
"snps,tx_de_emphasis_quirk");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 1a6cc48..08ed9e0 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -199,6 +199,7 @@
 
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST(1 << 31)
+#define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30)
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
 #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4)
 #define DWC3_GUSB2PHYCFG_ENBLSLPM  (1 << 8)
@@ -803,6 +804,9 @@ struct dwc3_scratchpad_array {
  * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
  * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG,
  *  disabling the suspend signal to the PHY.
+ * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
+ * in GUSB2PHYCFG, specify that USB2 PHY doesn't
+ * provide a free-running PHY clock.
  * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  * @tx_de_emphasis: Tx de-emphasis value
  * 0   - -6dB de-emphasis
@@ -946,6 +950,7 @@ struct dwc3 {
unsigneddis_u2_susphy_quirk:1;
unsigneddis_enblslpm_quirk:1;
unsigneddis_rxdet_inp3_quirk:1;
+   unsigneddis_u2_freeclk_exists_quirk:1;
 
unsignedtx_de_emphasis_quirk:1;
unsignedtx_de_emphasis:2;
-- 
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 v10 0/5] support rockchip dwc3 driver

2016-08-15 Thread William Wu
This series add support for rockchip DWC3 driver,
and add additional optional properties for specific
platforms (e.g., rockchip rk3399 platform).

And because rockchip DWC3 need additional handling of
cable events and mode switch to support DRD mode, so
we add a new dwc3-rockchip driver, rather than use the
generic of glue layer which merely enable some clocks
and populate its children.

William Wu (5):
  usb: dwc3: add dis_u2_freeclk_exists_quirk
  usb: dwc3: make usb2 phy utmi interface configurable
  usb: dwc3: add dis_del_phy_power_chg_quirk
  usb: dwc3: rockchip: add devicetree bindings documentation
  usb: dwc3: add rockchip specific glue layer

 Documentation/devicetree/bindings/usb/dwc3.txt |   5 +
 Documentation/devicetree/bindings/usb/generic.txt  |   6 +
 .../devicetree/bindings/usb/rockchip,dwc3.txt  |  71 
 drivers/usb/dwc3/Kconfig   |   9 +
 drivers/usb/dwc3/Makefile  |   1 +
 drivers/usb/dwc3/core.c|  30 +-
 drivers/usb/dwc3/core.h|  21 +
 drivers/usb/dwc3/dwc3-rockchip.c   | 441 +
 8 files changed, 583 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
 create mode 100644 drivers/usb/dwc3/dwc3-rockchip.c

-- 
1.9.1


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


Re: [PATCH 2/2] USB: mos7840: fix non-atomic allocation in write path

2016-08-15 Thread Johan Hovold
On Fri, Aug 12, 2016 at 01:05:09AM +0300, Alexey Khoroshilov wrote:
> There is an allocation with GFP_KERNEL flag in mos7840_write(),
> while it may be called from interrupt context.
> 
> Follow-up for commit 191252837626 ("USB: kobil_sct: fix non-atomic allocation 
> in write path")
> 
> Found by Linux Driver Verification project (linuxtesting.org).
> 
> Signed-off-by: Alexey Khoroshilov 
> ---
>  drivers/usb/serial/mos7840.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/serial/mos7840.c b/drivers/usb/serial/mos7840.c
> index ed378fb232e7..1de2c01c078d 100644
> --- a/drivers/usb/serial/mos7840.c
> +++ b/drivers/usb/serial/mos7840.c
> @@ -1341,7 +1341,7 @@ static int mos7840_write(struct tty_struct *tty, struct 
> usb_serial_port *port,
>  
>   if (urb->transfer_buffer == NULL) {
>   urb->transfer_buffer =
> - kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_KERNEL);
> + kmalloc(URB_TRANSFER_BUFFER_SIZE, GFP_ATOMIC);

Both patches now applied. I fixed up the odd indentation here while at
it.

Thanks,
Johan
--
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: chipidea: udc: don't touch DP when controller is in host mode

2016-08-15 Thread Peter Chen
On Fri, Aug 12, 2016 at 09:18:59AM +, Jun Li wrote:
> Hi,
> > -Original Message-
> > From: Peter Chen [mailto:hzpeterc...@gmail.com]
> > Sent: Friday, August 12, 2016 4:48 PM
> > To: Jun Li 
> > Cc: Peter Chen ; linux-usb@vger.kernel.org
> > Subject: Re: [PATCH] usb: chipidea: udc: don't touch DP when controller is
> > in host mode
> > 
> > On Thu, Aug 11, 2016 at 06:52:45PM +0800, Li Jun wrote:
> > > When the controller is configured to be dual role and it's in host
> > > mode, if bind udc and gadgt driver, those gadget operations will do
> > > gadget disconnect and finally pull down DP line, which will break host
> > function.
> > >
> > > Signed-off-by: Li Jun 
> > > ---
> > >  drivers/usb/chipidea/udc.c | 7 +--
> > >  1 file changed, 5 insertions(+), 2 deletions(-)
> > >
> > > diff --git a/drivers/usb/chipidea/udc.c b/drivers/usb/chipidea/udc.c
> > > index 761b804..846b77bc 100644
> > > --- a/drivers/usb/chipidea/udc.c
> > > +++ b/drivers/usb/chipidea/udc.c
> > > @@ -1593,8 +1593,11 @@ static int ci_udc_pullup(struct usb_gadget
> > > *_gadget, int is_on)  {
> > >   struct ci_hdrc *ci = container_of(_gadget, struct ci_hdrc, gadget);
> > >
> > > - /* Data+ pullup controlled by OTG state machine in OTG fsm mode */
> > > - if (ci_otg_is_fsm_mode(ci))
> > > + /*
> > > +  * Data+ pullup controlled by OTG state machine in OTG fsm mode;
> > > +  * and don't touch Data+ in host mode for dual role config.
> > > +  */
> > > + if (ci_otg_is_fsm_mode(ci) || ci->role == CI_ROLE_HOST)
> > >   return 0;
> > >
> > >   pm_runtime_get_sync(&ci->gadget.dev);
> > > --
> > 
> > Would you show me how to reproduce it? I can't reproduce it.
> > According to your description, the ci->vbus_active is false,
> > then the pullup operation will NOT do real pull up.
> 
> A pull *down*(not pull up) will be done when gadget driver load.
> How to reproduce:
> 1. Switch to host mode by ID cable + usb device
> 2. Load a gadget driver, e.g. modprobe g_ether
> 3. You will see the RS bit is cleared.
> 

Good catch, please CC stable.

-- 

Best Regards,
Peter Chen
--
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] usb: gadget: Add per-lun inquiry string

2016-08-15 Thread Philipp Gesang
Ping.

@Krzysztof The resubmitted patch bounced from the Cc: to you due
to your MX blocking one of our hosters. I can resend in case you
didn’t receive the mail from the list.

Best,
Philipp

-<| Quoting Philipp Gesang , on Monday, 
2016-08-01 17:04:19 |>-
> Introduce an attribute "inquiry_string" to the lun.
> 
> In some environments, e. g. BIOS boot menus, the inquiry string
> is the only information about devices presented to the user. The
> default string depends on the "cdrom" bit of the first lun as
> well as the kernel version and allows no further customization.
> So without access to the client it is not obvious which gadget is
> active at a given point and what any of the available luns might
> contain.
> 
> If "inquiry_string" is ignored or set to the empty string, the
> old behavior is preserved.
> 
> Signed-off-by: Philipp Gesang 
> ---
>  drivers/usb/gadget/function/f_mass_storage.c | 28 
> ++--
>  drivers/usb/gadget/function/f_mass_storage.h |  1 +
>  drivers/usb/gadget/function/storage_common.c | 24 
>  drivers/usb/gadget/function/storage_common.h | 10 ++
>  4 files changed, 57 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/f_mass_storage.c 
> b/drivers/usb/gadget/function/f_mass_storage.c
> index 5c6d4d7..efcc3de 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.c
> +++ b/drivers/usb/gadget/function/f_mass_storage.c
> @@ -311,11 +311,7 @@ struct fsg_common {
>   /* Gadget's private data. */
>   void*private_data;
>  
> - /*
> -  * Vendor (8 chars), product (16 chars), release (4
> -  * hexadecimal digits) and NUL byte
> -  */
> - char inquiry_string[8 + 16 + 4 + 1];
> + char inquiry_string[INQUIRY_STRING_LEN];
>  
>   struct kref ref;
>  };
> @@ -1107,7 +1103,12 @@ static int do_inquiry(struct fsg_common *common, 
> struct fsg_buffhd *bh)
>   buf[5] = 0; /* No special options */
>   buf[6] = 0;
>   buf[7] = 0;
> - memcpy(buf + 8, common->inquiry_string, sizeof common->inquiry_string);
> + if (curlun->inquiry_string[0])
> + memcpy(buf + 8, curlun->inquiry_string,
> +sizeof(curlun->inquiry_string));
> + else
> + memcpy(buf + 8, common->inquiry_string,
> +sizeof(common->inquiry_string));
>   return 36;
>  }
>  
> @@ -3225,12 +3226,27 @@ static ssize_t fsg_lun_opts_nofua_store(struct 
> config_item *item,
>  
>  CONFIGFS_ATTR(fsg_lun_opts_, nofua);
>  
> +static ssize_t fsg_lun_opts_inquiry_string_show(struct config_item *item,
> + char *page)
> +{
> + return fsg_show_inquiry_string(to_fsg_lun_opts(item)->lun, page);
> +}
> +
> +static ssize_t fsg_lun_opts_inquiry_string_store(struct config_item *item,
> +  const char *page, size_t len)
> +{
> + return fsg_store_inquiry_string(to_fsg_lun_opts(item)->lun, page, len);
> +}
> +
> +CONFIGFS_ATTR(fsg_lun_opts_, inquiry_string);
> +
>  static struct configfs_attribute *fsg_lun_attrs[] = {
>   &fsg_lun_opts_attr_file,
>   &fsg_lun_opts_attr_ro,
>   &fsg_lun_opts_attr_removable,
>   &fsg_lun_opts_attr_cdrom,
>   &fsg_lun_opts_attr_nofua,
> + &fsg_lun_opts_attr_inquiry_string,
>   NULL,
>  };
>  
> diff --git a/drivers/usb/gadget/function/f_mass_storage.h 
> b/drivers/usb/gadget/function/f_mass_storage.h
> index b6a9918..d390231 100644
> --- a/drivers/usb/gadget/function/f_mass_storage.h
> +++ b/drivers/usb/gadget/function/f_mass_storage.h
> @@ -100,6 +100,7 @@ struct fsg_lun_config {
>   char removable;
>   char cdrom;
>   char nofua;
> + char inquiry_string[INQUIRY_STRING_LEN];
>  };
>  
>  struct fsg_config {
> diff --git a/drivers/usb/gadget/function/storage_common.c 
> b/drivers/usb/gadget/function/storage_common.c
> index 990df22..8fbf686 100644
> --- a/drivers/usb/gadget/function/storage_common.c
> +++ b/drivers/usb/gadget/function/storage_common.c
> @@ -369,6 +369,12 @@ ssize_t fsg_show_removable(struct fsg_lun *curlun, char 
> *buf)
>  }
>  EXPORT_SYMBOL_GPL(fsg_show_removable);
>  
> +ssize_t fsg_show_inquiry_string(struct fsg_lun *curlun, char *buf)
> +{
> + return sprintf(buf, "%s\n", curlun->inquiry_string);
> +}
> +EXPORT_SYMBOL_GPL(fsg_show_inquiry_string);
> +
>  /*
>   * The caller must hold fsg->filesem for reading when calling this function.
>   */
> @@ -499,4 +505,22 @@ ssize_t fsg_store_removable(struct fsg_lun *curlun, 
> const char *buf,
>  }
>  EXPORT_SYMBOL_GPL(fsg_store_removable);
>  
> +ssize_t fsg_store_inquiry_string(struct fsg_lun *curlun, const char *buf,
> +  size_t count)
> +{
> + const size_t len = min(count, sizeof(curlun->inquiry_string));
> +
> + if (len == 0 || buf[0] == '\n') {
> + curlun->inquiry_string[0] = 0;
> + } else {
> + snprintf(curlun->inq

Re: [PATCH v9 5/5] usb: dwc3: add rockchip specific glue layer

2016-08-15 Thread kbuild test robot
Hi William,

[auto build test ERROR on balbi-usb/next]
[also build test ERROR on v4.8-rc2 next-20160815]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improve the system]

url:
https://github.com/0day-ci/linux/commits/William-Wu/support-rockchip-dwc3-driver/20160815-151035
base:   https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next
config: x86_64-allmodconfig (attached as .config)
compiler: gcc-6 (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
# save the attached .config to linux build tree
make ARCH=x86_64 

All error/warnings (new ones prefixed by >>):

   In file included from drivers/usb/dwc3/dwc3-rockchip.c:18:0:
>> drivers/usb/dwc3/dwc3-rockchip.c:424:25: error: 'of_dwc3_rockchip_match' 
>> undeclared here (not in a function)
MODULE_DEVICE_TABLE(of, of_dwc3_rockchip_match);
^
   include/linux/module.h:223:21: note: in definition of macro 
'MODULE_DEVICE_TABLE'
extern const typeof(name) __mod_##type##__##name##_device_table  \
^~~~
>> include/linux/module.h:223:27: error: 
>> '__mod_of__of_dwc3_rockchip_match_device_table' aliased to undefined symbol 
>> 'of_dwc3_rockchip_match'
extern const typeof(name) __mod_##type##__##name##_device_table  \
  ^
>> drivers/usb/dwc3/dwc3-rockchip.c:424:1: note: in expansion of macro 
>> 'MODULE_DEVICE_TABLE'
MODULE_DEVICE_TABLE(of, of_dwc3_rockchip_match);
^~~

vim +/of_dwc3_rockchip_match +424 drivers/usb/dwc3/dwc3-rockchip.c

   418  
   419  static const struct of_device_id rockchip_dwc3_match[] = {
   420  { .compatible = "rockchip,rk3399-dwc3" },
   421  { /* Sentinel */ }
   422  };
   423  
 > 424  MODULE_DEVICE_TABLE(of, of_dwc3_rockchip_match);
   425  
   426  static struct platform_driver dwc3_rockchip_driver = {
   427  .probe  = dwc3_rockchip_probe,

---
0-DAY kernel test infrastructureOpen Source Technology Center
https://lists.01.org/pipermail/kbuild-all   Intel Corporation


.config.gz
Description: Binary data


[PATCH v5 3/3] usbip: vhci extension: dynamic extension

2016-08-15 Thread Nobuo Iwata
Modification for dynamic device registration and unregistration.

1. kernel config

Followings are added.

USBIP_VHCI_HC_PORTS: Number of ports per USB/IP virtual host 
controller. The default is 8 - same as current VHCI_NPORTS.
USBIP_VHCI_MAX_HCS: Muximum number of USB/IP virtual host controllers. 
The default is 1.
USBIP_VHCI_INIT_HCS: Initial number of USB/IP virtual host controllers. 
The default is 1.
Static number of devices: USBIP_VHCI_NR_HCS in patch 1/3 is removed 
with this patch.

2. view from sysfs

Sysfs structure is changed as following.

BEFORE this patchset:
/sys/devices/platform
+-- vhci
+-- status
+-- attach
+-- detach
+-- usbip_debug

AFTER: example for CONFIG_USBIP_INIT_HCS=2 CONFIG_USBIP_MAX_HCS=4
At the beginning
/sys/devices/platform
+-- vhci
|   +-- nports
|   +-- status
|   +-- status.1
|   +-- status.2
|   +-- status.3
|   +-- attach
|   +-- detach
|   +-- usbip_debug
+-- vhci.1

The status files are shown to the maximum number of devices. Port 
status in status.2 and status.3 represents as free but corresponding 
devices are not yes registered.
When all ports in status and status.1 are used, userspace tool requests 
'attach' to a port in status.2 then vhci.2 will be registred. The limit 
is defined with USBIP_VHCI_MAX_NCS.

By preparing muximum number of status files, there's no need to 
introduce additional operations for userspace tool.

When number of free ports becomes more than USBIP_VHCI_HC_PORTS * 
VHCI_FREE_HCS(2), a free controller other than the first one will be 
unregistered. It will be invoked by 'detach' operation and other error 
situations which ports are released.

Signed-off-by: Nobuo Iwata 
---
 drivers/usb/usbip/Kconfig  |  17 ++-
 drivers/usb/usbip/vhci.h   |  36 -
 drivers/usb/usbip/vhci_hcd.c   | 251 -
 drivers/usb/usbip/vhci_rx.c|  10 +-
 drivers/usb/usbip/vhci_sysfs.c |  49 ---
 drivers/usb/usbip/vhci_tx.c|   6 +-
 6 files changed, 294 insertions(+), 75 deletions(-)

diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig
index 29492c7..d11b548 100644
--- a/drivers/usb/usbip/Kconfig
+++ b/drivers/usb/usbip/Kconfig
@@ -34,8 +34,8 @@ config USBIP_VHCI_HC_PORTS
  host controller driver, this defines number of ports per
  USB/IP virtual host controller.
 
-config USBIP_VHCI_NR_HCS
-   int "Number of USB/IP virtual host controllers"
+config USBIP_VHCI_MAX_HCS
+   int "Maximum number of USB/IP virtual host controllers"
range 1 128
default 1
depends on USBIP_VHCI_HCD
@@ -43,7 +43,18 @@ config USBIP_VHCI_NR_HCS
  To increase number of ports available for USB/IP virtual
  host controller driver, this defines number of USB/IP
  virtual host controllers as if adding physical host
- controllers.
+ controllers. This defines the maximum number.
+
+config USBIP_VHCI_INIT_HCS
+   int "Initial number of USB/IP virtual host controllers"
+   range 1 USBIP_VHCI_MAX_HCS
+   default 1
+   depends on USBIP_VHCI_MAX_HCS
+   ---help---
+ To increase number of ports available for USB/IP virtual
+ host controller driver, this defines number of USB/IP
+ virtual host controllers as if adding physical host
+ controllers. This defines the number at initializing.
 
 config USBIP_HOST
tristate "Host driver"
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index 88b71c4..ba893a7 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -51,6 +51,9 @@ struct vhci_device {
 
/* vhci_tx thread sleeps for this queue */
wait_queue_head_t waitq_tx;
+
+   /* denotes port is in-use */
+   atomic_t using_port;
 };
 
 /* urb->hcpriv, use container_of() */
@@ -79,12 +82,21 @@ struct vhci_unlink {
 #define VHCI_HC_PORTS 8
 #endif
 
-#ifdef CONFIG_USBIP_VHCI_NR_HCS
-#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
+#ifdef CONFIG_USBIP_VHCI_MAX_HCS
+#define VHCI_MAX_HCS CONFIG_USBIP_VHCI_MAX_HCS
+#else
+#define VHCI_MAX_HCS 1
+#endif
+
+#ifdef CONFIG_USBIP_VHCI_INIT_HCS
+#define VHCI_INIT_HCS CONFIG_USBIP_VHCI_INIT_HCS
 #else
-#define VHCI_NR_HCS 1
+#define VHCI_INIT_HCS 1
 #endif
 
+/* VHCI_FREE_HCS * VHCI_HC_PORTS: ports to keep free at unregister */
+#define VHCI_FREE_HCS 2
+
 #define MAX_STATUS_NAME 16
 
 /* for usb_bus.hcpriv */
@@ -98,6 +110,8 @@ struct vhci_hcd {
 
atomic_t seqnum;
 
+   unsigned int using_ports;
+
/*
 * NOTE:
 * wIndex shows the port number and begins from 1.
@@ -106,12 +120,18 @@ struct vhci_hcd {
struct vhci_device vdev[VHCI_HC_PORTS];
 };
 
+extern int vhci_max_controllers;
+extern int vhci_init_controllers;
 extern int vhci_num_controllers;
 extern struct platform_device **vhci_pdevs;
 extern struct attribute_group vhci_attr_grou

[PATCH v5 2/3] usbip: vhci extension: modifications to userspace

2016-08-15 Thread Nobuo Iwata
Modification to the userspace tools including usbip/libsrc and 
usbip/src.

Changed corresponding to new vhci_sysfs.c.

nports in sysfs is used to get total number of ports. 

Old get_nports() ignores the last status line because 
udev_device_get_sysattr_value() drops last new line. New version uses 
nports attribute so it's doesn't have this problem.

status[.N] in sysfs are used.

parse_status() which reads all status lines is broken into open, close, 
read-line and parse-line. Parse-line is reused to find free port and 
get imported device.

In daemon, status was loaded into memory by 
usbip_vhci_refresh_device_list() at receiving every request. The loaded 
status is used to find free port. It is changed to read status directly 
to find free port.

Wording inconsistencies are fixed according to the rule below.

rhport, HC_PORTS: ports within a controller (or root hub).
port, nports: ports across the controllers.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 398 +++
 tools/usb/usbip/libsrc/vhci_driver.h |  45 +--
 tools/usb/usbip/src/usbip_attach.c   |   8 +-
 tools/usb/usbip/src/usbip_port.c |  13 +-
 tools/usb/usbip/src/usbipd_app.c |  48 ++--
 5 files changed, 253 insertions(+), 259 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index 50c723d..4d1b986 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -15,11 +15,24 @@
 #undef  PROGNAME
 #define PROGNAME "libusbip"
 
-struct usbip_vhci_driver *vhci_driver;
-struct udev *udev_context;
+static struct udev_device *vhci_hc_device;
+static struct udev *udev_context;
+static int vhci_nports;
 
-static struct usbip_imported_device *
-imported_device_init(struct usbip_imported_device *idev, char *busid)
+struct usbip_vhci_device {
+   int port;
+   uint32_t status;
+
+   uint32_t devid;
+
+   uint8_t busnum;
+   uint8_t devnum;
+
+   /* usbip_class_device list */
+   struct usbip_usb_device udev;
+};
+
+static int imported_device_init(struct usbip_vhci_device *vdev, char *busid)
 {
struct udev_device *sudev;
 
@@ -27,132 +40,131 @@ imported_device_init(struct usbip_imported_device *idev, 
char *busid)
   "usb", busid);
if (!sudev) {
dbg("udev_device_new_from_subsystem_sysname failed: %s", busid);
-   goto err;
+   return -1;
}
-   read_usb_device(sudev, &idev->udev);
+   read_usb_device(sudev, &vdev->udev);
udev_device_unref(sudev);
 
-   return idev;
-
-err:
-   return NULL;
+   return 0;
 }
 
+struct status_context {
+   int controller;
+   const char *c;
+};
 
+#define OPEN_MODE_FIRST  0
+#define OPEN_MODE_REOPEN 1
 
-static int parse_status(const char *value)
-{
-   int ret = 0;
-   char *c;
+static int open_hc_device(int mode);
 
+#define MAX_STATUS_NAME 16
 
-   for (int i = 0; i < vhci_driver->nports; i++)
-   memset(&vhci_driver->idev[i], 0, sizeof(vhci_driver->idev[i]));
+static int open_status(struct status_context *ctx, int mode)
+{
+   char name[MAX_STATUS_NAME+1];
 
+   if (mode == OPEN_MODE_FIRST)
+   ctx->controller = 0;
+   else
+   (ctx->controller)++;
 
-   /* skip a header line */
-   c = strchr(value, '\n');
-   if (!c)
+   if (open_hc_device(OPEN_MODE_REOPEN))
return -1;
-   c++;
-
-   while (*c != '\0') {
-   int port, status, speed, devid;
-   unsigned long socket;
-   char lbusid[SYSFS_BUS_ID_SIZE];
-
-   ret = sscanf(c, "%d %d %d %x %lx %31s\n",
-   &port, &status, &speed,
-   &devid, &socket, lbusid);
-
-   if (ret < 5) {
-   dbg("sscanf failed: %d", ret);
-   BUG();
-   }
 
-   dbg("port %d status %d speed %d devid %x",
-   port, status, speed, devid);
-   dbg("socket %lx lbusid %s", socket, lbusid);
+   if (ctx->controller == 0)
+   strcpy(name, "status");
+   else
+   snprintf(name, MAX_STATUS_NAME + 1,
+   "status.%d", ctx->controller);
+   ctx->c = udev_device_get_sysattr_value(vhci_hc_device, name);
+   if (ctx->c == NULL)
+   return -1;
 
+   return 0;
+}
 
-   /* if a device is connected, look at it */
-   {
-   struct usbip_imported_device *idev = 
&vhci_driver->idev[port];
+static void close_status(struct status_context *ctx)
+{
+   ctx->c = NULL;
+}
 
-   idev->port  = port;
-   idev->status= status;
+static int next_status_line(struct status_context *ctx)
+{
+   const char *c = ctx->c;

[PATCH v5 1/3] usbip: vhci extension: modifications to vhci driver

2016-08-15 Thread Nobuo Iwata
Modification to Kconfig, vhci_hc.c, vhci.h and vhci_sysfs.c.

1. kernel config

Followings are added.

USBIP_VHCI_HC_PORTS: Number of ports per USB/IP virtual host 
controller. The default is 8 - same as current VHCI_NPORTS.
USBIP_VHCI_NR_HCS: Number of USB/IP virtual host controllers. The 
default is 1. This paratmeter is replaced with USBIP_VHCI_INIT_HCS and 
USBIP_VHCI_MAX_HCS included in succeeding dynamic extension patch.

2. the_controller to controllers

the_controller is changed to vhci_pdevs: array of struct 
platform_device.

3. vhci_sysfs.c

Sysfs structure is changed as following.

BEFORE:
/sys/devices/platform
+-- vhci
+-- status
+-- attach
+-- detach
+-- usbip_debug

AFTER: example for CONFIG_USBIP_NR_HCS=4
/sys/devices/platform
+-- vhci
|   +-- nports
|   +-- status
|   +-- status.1
|   +-- status.2
|   +-- status.3
|   +-- attach
|   +-- detach
|   +-- usbip_debug
+-- vhci.1
+-- vhci.2
+-- vhci.3

vhci[.N] is shown for each host controller kobj. vhch.1, vhci.2, ... 
are shown only when CONFIG_USBIP_NR_HCS is more than 1. Only 'vhci' 
(without number) has user space interfaces. 'nports' is newly added to 
give ports-per-controller and number of controlles. Before that, number 
of ports is acquired by reading status lines. Status is divided for 
each controller to avoid page size (4KB) limitation.

Old userspace tool binaries work with the first status within the first 
controller.

Inconsistency between status header and content is fixed.
4th and 5th column are
header:  "dev bus"
content(unused): "000 000"
content(used):   "%08x", devid
Only 1st and 2nd column are used by program. In old version, sscanf() 
in parse_status expect no bus column. And bus_id string is shown in the 
last column. Then bus in the header is removed and unused content is 
replaced with 8 zeros. The sscanf() expects more than 5 columns and new 
has 6 columns so there's no compatibility issue in this change.

Signed-off-by: Nobuo Iwata 
---
 drivers/usb/usbip/Kconfig  |  21 +++
 drivers/usb/usbip/vhci.h   |  54 --
 drivers/usb/usbip/vhci_hcd.c   | 285 ---
 drivers/usb/usbip/vhci_rx.c|  21 +--
 drivers/usb/usbip/vhci_sysfs.c | 297 +
 5 files changed, 498 insertions(+), 180 deletions(-)

diff --git a/drivers/usb/usbip/Kconfig b/drivers/usb/usbip/Kconfig
index 17646b2..29492c7 100644
--- a/drivers/usb/usbip/Kconfig
+++ b/drivers/usb/usbip/Kconfig
@@ -24,6 +24,27 @@ config USBIP_VHCI_HCD
  To compile this driver as a module, choose M here: the
  module will be called vhci-hcd.
 
+config USBIP_VHCI_HC_PORTS
+   int "Number of ports per USB/IP virtual host controller"
+   range 1 31
+   default 8
+   depends on USBIP_VHCI_HCD
+   ---help---
+ To increase number of ports available for USB/IP virtual
+ host controller driver, this defines number of ports per
+ USB/IP virtual host controller.
+
+config USBIP_VHCI_NR_HCS
+   int "Number of USB/IP virtual host controllers"
+   range 1 128
+   default 1
+   depends on USBIP_VHCI_HCD
+   ---help---
+ To increase number of ports available for USB/IP virtual
+ host controller driver, this defines number of USB/IP
+ virtual host controllers as if adding physical host
+ controllers.
+
 config USBIP_HOST
tristate "Host driver"
depends on USBIP_CORE && USB
diff --git a/drivers/usb/usbip/vhci.h b/drivers/usb/usbip/vhci.h
index a863a98..88b71c4 100644
--- a/drivers/usb/usbip/vhci.h
+++ b/drivers/usb/usbip/vhci.h
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2003-2008 Takahiro Hirofuchi
+ * Copyright (C) 2015 Nobuo Iwata
  *
  * This is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -72,13 +73,25 @@ struct vhci_unlink {
 };
 
 /* Number of supported ports. Value has an upperbound of USB_MAXCHILDREN */
-#define VHCI_NPORTS 8
+#ifdef CONFIG_USBIP_VHCI_HC_PORTS
+#define VHCI_HC_PORTS CONFIG_USBIP_VHCI_HC_PORTS
+#else
+#define VHCI_HC_PORTS 8
+#endif
+
+#ifdef CONFIG_USBIP_VHCI_NR_HCS
+#define VHCI_NR_HCS CONFIG_USBIP_VHCI_NR_HCS
+#else
+#define VHCI_NR_HCS 1
+#endif
+
+#define MAX_STATUS_NAME 16
 
 /* for usb_bus.hcpriv */
 struct vhci_hcd {
spinlock_t lock;
 
-   u32 port_status[VHCI_NPORTS];
+   u32 port_status[VHCI_HC_PORTS];
 
unsigned resuming:1;
unsigned long re_timeout;
@@ -90,14 +103,19 @@ struct vhci_hcd {
 * wIndex shows the port number and begins from 1.
 * But, the index of this array begins from 0.
 */
-   struct vhci_device vdev[VHCI_NPORTS];
+   struct vhci_device vdev[VHCI_HC_PORTS];
 };
 
-extern struct vhci_hcd *the_controller;
-extern const struct attribute_group dev_attr_gr

[PATCH v5 0/3] usbip: vhci number of ports extension

2016-08-15 Thread Nobuo Iwata
This series of patches extends number of ports limitaion in application 
(vhci) side.

1. Background

Assuming a system shown below that services distributerd devices in 
home or office via USB/IP, if the devices are set at every doors and 
windows, number devices may be up to tens.

Home/SOHO/Enterprise Intranet/Internet
 +--+   +--+ USB/IP+-+
+|device|--+|Linux |---|Service  |
|+--+  |+--+---|on Linux |
+--+   +--++-+
ex)
Device  Service
 sensors ... environment analysis
 cameras ... monitoring, recording
 ID/biometric readers .. authentication

If USB/IP is used for ubiqitous devices or IoT devices, many devices 
might be handled. 

2. About this patch set

In current USB/IP, available number of ports (ie. number of supported 
devices) is VHCI_NPORTS(8) in drivers/usb/usbip/vhci.h. The value of 
the macro can be altered to USB_MAXCHILDREN(31). This limit is came 
from hub status bit array. See also the comment at USB_MAXCHILDREN 
include/uapi/linux/usb/ch11.h.

There are two way to increase number of available ports. The first way 
is to put hub emulator under vhci. This can add ports up to 255 - the 
limit of USB 2.0 host controller. The second way is to add host 
controller. It's as same as machines have several host controllers: 
most desktop or note PCs have more than one host controller.

Current USB/IP supports only one controller defined as 'the_controller' 
in drivers/usb/usbip/vhci_hcd.c. This patch takes the second way 
described above and adds virtual controllers. In this patch, the number 
is specified by kernel configuration. 

3. Dynamic extension

According to kernel configuration, vhci devices (platform device) will 
be added and removed when they are not used. When the vhci driver is 
loaded, USBIP_VHCI_INIT_HCS (default is 1) drivers are registered. They 
will be further registered upto USBIP_VHCI_MAX_HCS (default is 1). They 
are unregistered when number of free devices becomes more than 
VHCI_FREE_HCS(2) except the first device.

4. Wording

Wording inconsistencies in function and variable names are corrected 
according to the rule below. They were not strict because only one host 
controller was handled.

rhport, HC_PORTS: ports within a controller (or root hub).
port, nports: ports across the controllers.

5. Dependencies

This series depends on 'usbip: exporting devices' patch set because 
this includes changes to application side daemon which introduced the 
patch set.

---
Version information

v5)
# Fixed dynamically allocated sysfs attribute checking error when 
CONFIG_DEBUG_LOCK_ALLOC is set.
# Recreated based on linux-next 20160810.

v4)
# Changed the method to set number of controllers from a module 
parameter to kernel config.
# Excluded event thread patch merged to 4.7-rc1.
# Added dynamic extension.

v3)
# Fixed conflicts against linux-next 20160209.
# Changed sysfs object and attribute name for old tools compatibility.
# Changed nports status format not to include num_controllers value.
# Fixed checkpatch errors and warnings.

v2)
# Added static to some functions and variables not called from other 
files. 

*** BLURB HERE ***

Nobuo Iwata (3):
  usbip: vhci extension: modifications to vhci driver
  usbip: vhci extension: modifications to userspace
  usbip: vhci extension: dynamic extension

 drivers/usb/usbip/Kconfig|  32 ++
 drivers/usb/usbip/vhci.h |  84 -
 drivers/usb/usbip/vhci_hcd.c | 468 +--
 drivers/usb/usbip/vhci_rx.c  |  31 +-
 drivers/usb/usbip/vhci_sysfs.c   | 304 +
 drivers/usb/usbip/vhci_tx.c  |   6 +-
 tools/usb/usbip/libsrc/vhci_driver.c | 398 ---
 tools/usb/usbip/libsrc/vhci_driver.h |  45 +--
 tools/usb/usbip/src/usbip_attach.c   |   8 +-
 tools/usb/usbip/src/usbip_port.c |  13 +-
 tools/usb/usbip/src/usbipd_app.c |  48 ++-
 11 files changed, 984 insertions(+), 453 deletions(-)

-- 
2.1.0

--
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 v10 9/9] usbip: exporting devices: chage to documenattion

2016-08-15 Thread Nobuo Iwata
This patch adds function and usage of new connect operation, disconnect 
operation and application(vhci)-side daemon to README and manuals.

At this point, the wording, 'server' and 'client' are ambiguous in 
several place.

For existing attach command, the daemon runs device side machine and 
attach command is executed in application side machine. Then 'server' 
is used for device side and 'client' is for application side.

For the new connect command, the daemon runs applications side machine 
and connect command is executed in device side machine. Now, 'server' 
and 'client' run in different machine than before.

So, to avoid confusion, words 'device side (machine)' and 'application 
side (machine)' are used instead of 'client' and 'server' as needed.

Please, see also diagrams in the cover letter.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/Makefile.am  |   2 +-
 tools/usb/usbip/README   |  70 --
 tools/usb/usbip/doc/usbip.8  | 136 ---
 tools/usb/usbip/doc/usbipa.8 |  78 
 tools/usb/usbip/doc/usbipd.8 |  37 ++
 5 files changed, 263 insertions(+), 60 deletions(-)

diff --git a/tools/usb/usbip/Makefile.am b/tools/usb/usbip/Makefile.am
index 66f8bf0..f371ed9 100644
--- a/tools/usb/usbip/Makefile.am
+++ b/tools/usb/usbip/Makefile.am
@@ -3,4 +3,4 @@ includedir = @includedir@/usbip
 include_HEADERS := $(addprefix libsrc/, \
 usbip_common.h vhci_driver.h usbip_host_driver.h)
 
-dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8)
+dist_man_MANS := $(addprefix doc/, usbip.8 usbipd.8 usbipa.8)
diff --git a/tools/usb/usbip/README b/tools/usb/usbip/README
index 831f49f..74f4afb 100644
--- a/tools/usb/usbip/README
+++ b/tools/usb/usbip/README
@@ -1,7 +1,8 @@
 #
 # README for usbip-utils
 #
-# Copyright (C) 2011 matt mooney 
+# Copyright (C) 2015 Nobuo Iwata
+#   2011 matt mooney 
 #   2005-2008 Takahiro Hirofuchi
 
 
@@ -36,41 +37,70 @@
 
 
 [Usage]
-server:# (Physically attach your USB device.)
+Device-side: a machine has USB device(s).
+Application-side: a machine runs an application software uses remote USB 
device.
 
-server:# insmod usbip-core.ko
-server:# insmod usbip-host.ko
+1) Connect from application-side to device-side.
 
-server:# usbipd -D
+dev:# (Physically attach your USB device.)
+
+dev:# insmod usbip-core.ko
+dev:# insmod usbip-host.ko
+
+dev:# usbipd -D
- Start usbip daemon.
 
-server:# usbip list -l
-   - List driver assignments for USB devices.
+dev:# usbip list -l
+   - List driver assignments for USB devices and their busid.
 
-server:# usbip bind --busid 1-2
-   - Bind usbip-host.ko to the device with busid 1-2.
-   - The USB device 1-2 is now exportable to other hosts!
-   - Use `usbip unbind --busid 1-2' to stop exporting the device.
+dev:# usbip bind --busid 
+   - Bind usbip-host.ko to the device with .
+   - The USB device with  is now exportable to other hosts!
+   - Use `usbip unbind --busid ` to stop exporting the device.
 
-client:# insmod usbip-core.ko
-client:# insmod vhci-hcd.ko
+app:# insmod usbip-core.ko
+app:# insmod vhci-hcd.ko
 
-client:# usbip list --remote 
+app:# usbip list --remote 
- List exported USB devices on the .
 
-client:# usbip attach --remote  --busid 1-2
+app:# usbip attach --remote  --busid 
- Connect the remote USB device.
 
-client:# usbip port
+app:# usbip port
- Show virtual port status.
 
-client:# usbip detach --port 
+app:# usbip detach --port 
- Detach the USB device.
 
+2) Connect from device-side to application-side.
+
+app:# insmod usbip-core.ko
+app:# insmod vhci-hcd.ko
+
+app:# usbipa -D
+   - Start usbip daemon.
+
+dev:# (Physically attach your USB device.)
+
+dev:# insmod usbip-core.ko
+dev:# insmod usbip-host.ko
+
+dev:# usbip list -l
+   - List driver assignments for USB devices and their busid.
+
+dev:# usbip connect --remote  --busid 
+   - Bind usbip-host.ko to the device with .
+   - The USB device of  is connected to remote host!
+
+dev:# usbip disconnect --remote  --busid 
+   - The USB device with  is disconnected from remote host.
+   - Unbind usbip-host.ko from the device.
+
 
 [Example]
 ---
-   SERVER SIDE
+   DEVICE SIDE
 ---
 Physically attach your USB devices to this host.
 
@@ -131,7 +161,7 @@ Mark the device of busid 3-3.2 as exportable:
 ...
 
 ---
-   CLIENT SIDE
+ APPLICATION SIDE
 ---
 First, let's list available remote devices that are marked as
 exportable on the host.
@@ -170,7 +200,7 @@ Attach a remote USB device:
 deux:# usbip attach --remote 10.0.0.3 --busid 1-1
 port 0 attached
 
-Show the devices attached to this client:
+Show the devices att

[PATCH v10 8/9] usbip: exporting devices: change to usbip_list.c

2016-08-15 Thread Nobuo Iwata
Correction to wording inconsistency around import and export in 
usbip_list.c.

Please, see also cover letter about wording.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/usbip_list.c | 22 --
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/tools/usb/usbip/src/usbip_list.c b/tools/usb/usbip/src/usbip_list.c
index f1b38e8..37f9afa 100644
--- a/tools/usb/usbip/src/usbip_list.c
+++ b/tools/usb/usbip/src/usbip_list.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  * Copyright (C) 2015-2016 Samsung Electronics
  *   Igor Kotrasinski 
@@ -42,9 +43,9 @@
 #include "usbip.h"
 
 static const char usbip_list_usage_string[] =
-   "usbip list [-p|--parsable] \n"
+   "usbip list \n"
"-p, --parsable Parsable list format\n"
-   "-r, --remote=List the exportable USB devices on \n"
+   "-r, --remote=List the importable USB devices on \n"
"-l, --localList the local USB devices\n";
 
 void usbip_list_usage(void)
@@ -52,7 +53,7 @@ void usbip_list_usage(void)
printf("usage: %s", usbip_list_usage_string);
 }
 
-static int get_exported_devices(char *host, int sockfd)
+static int get_importable_devices(char *host, int sockfd)
 {
char product_name[100];
char class_name[100];
@@ -82,14 +83,14 @@ static int get_exported_devices(char *host, int sockfd)
return -1;
}
PACK_OP_DEVLIST_REPLY(0, &reply);
-   dbg("exportable devices: %d\n", reply.ndev);
+   dbg("importable devices: %d\n", reply.ndev);
 
if (reply.ndev == 0) {
-   info("no exportable devices found on %s", host);
+   info("no importable devices found on %s", host);
return 0;
}
 
-   printf("Exportable USB devices\n");
+   printf("Importable USB devices\n");
printf("==\n");
printf(" - %s\n", host);
 
@@ -134,7 +135,7 @@ static int get_exported_devices(char *host, int sockfd)
return 0;
 }
 
-static int list_exported_devices(char *host)
+static int list_importable_devices(char *host)
 {
int rc;
int sockfd;
@@ -147,9 +148,10 @@ static int list_exported_devices(char *host)
}
dbg("connected to %s:%s", host, usbip_port_string);
 
-   rc = get_exported_devices(host, sockfd);
+   rc = get_importable_devices(host, sockfd);
if (rc < 0) {
err("failed to get device list from %s", host);
+   close(sockfd);
return -1;
}
 
@@ -351,7 +353,7 @@ int usbip_list(int argc, char *argv[])
parsable = true;
break;
case 'r':
-   ret = list_exported_devices(optarg);
+   ret = list_importable_devices(optarg);
goto out;
case 'l':
ret = list_devices(parsable);
-- 
2.1.0

--
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 v10 7/9] usbip: exporting devices: new application-side daemon

2016-08-15 Thread Nobuo Iwata
New application(vhci)-side daemon.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c |  19 +++
 tools/usb/usbip/libsrc/vhci_driver.h |   1 +
 tools/usb/usbip/src/Makefile.am  |   7 +-
 tools/usb/usbip/src/usbipd.c |  12 +-
 tools/usb/usbip/src/usbipd_app.c | 242 +++
 5 files changed, 279 insertions(+), 2 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index b7ca63d..50c723d 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -314,6 +314,25 @@ int usbip_vhci_get_free_port(void)
return -1;
 }
 
+struct usbip_imported_device *usbip_vhci_find_device(char *host, char *busid)
+{
+   int ret;
+   char rhost[NI_MAXHOST] = "unknown host";
+   char rserv[NI_MAXSERV] = "unknown port";
+   char rbusid[SYSFS_BUS_ID_SIZE];
+
+   for (int i = 0; i < vhci_driver->nports; i++) {
+   ret = read_record(vhci_driver->idev[i].port, rhost, NI_MAXHOST,
+   rserv, NI_MAXSERV, rbusid);
+   if (!ret &&
+   !strncmp(host, rhost, NI_MAXHOST) &&
+   !strncmp(busid, rbusid, SYSFS_BUS_ID_SIZE)) {
+   return vhci_driver->idev + i;
+   }
+   }
+   return NULL;
+}
+
 int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed) {
char buff[200]; /* what size should be ? */
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
b/tools/usb/usbip/libsrc/vhci_driver.h
index f955ada..acb427d 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -46,6 +46,7 @@ int  usbip_vhci_refresh_device_list(void);
 
 
 int usbip_vhci_get_free_port(void);
+struct usbip_imported_device *usbip_vhci_find_device(char *host, char *busid);
 int usbip_vhci_attach_device2(uint8_t port, int sockfd, uint32_t devid,
uint32_t speed);
 
diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 1aa5156..8fdebce 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -2,11 +2,16 @@ AM_CPPFLAGS = -I$(top_srcdir)/libsrc 
-DUSBIDS_FILE='"@USBIDS_DIR@/usb.ids"'
 AM_CFLAGS   = @EXTRA_CFLAGS@
 LDADD   = $(top_builddir)/libsrc/libusbip.la
 
-sbin_PROGRAMS := usbip usbipd
+sbin_PROGRAMS := usbip usbipd usbipa
 
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
 usbip_connect.c usbip_disconnect.c
+usbip_CFLAGS := $(AM_CFLAGS)
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c
+usbipd_CFLAGS := $(AM_CFLAGS)
+
+usbipa_SOURCES := usbip_network.h usbipd.c usbipd_app.c usbip_network.c
+usbipa_CFLAGS := $(AM_CFLAGS) -DUSBIP_DAEMON_APP
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index 0ca5de5..4e8bee6 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -64,11 +64,13 @@ static const char usbipd_help_string[] =
"   -6, --ipv6\n"
"   Bind to IPv6. Default is both.\n"
"\n"
+#ifndef USBIP_DAEMON_APP
"   -e, --device\n"
"   Run in device mode.\n"
"   Rather than drive an attached device, create\n"
"   a virtual UDC to bind gadgets to.\n"
"\n"
+#endif
"   -D, --daemon\n"
"   Run as a daemon process.\n"
"\n"
@@ -404,7 +406,9 @@ int main(int argc, char *argv[])
{ "ipv6", no_argument,   NULL, '6' },
{ "daemon",   no_argument,   NULL, 'D' },
{ "debug",no_argument,   NULL, 'd' },
+#ifndef USBIP_DAEMON_APP
{ "device",   no_argument,   NULL, 'e' },
+#endif
{ "pid",  optional_argument, NULL, 'P' },
{ "tcp-port", required_argument, NULL, 't' },
{ "help", no_argument,   NULL, 'h' },
@@ -433,7 +437,11 @@ int main(int argc, char *argv[])
cmd = cmd_standalone_mode;
usbip_init_driver();
for (;;) {
-   opt = getopt_long(argc, argv, "46DdeP::t:hv", longopts, NULL);
+   opt = getopt_long(argc, argv, "46Dd"
+#ifndef USBIP_DAEMON_APP
+ "e"
+#endif
+ "P::t:hv", longopts, NULL);
 
if (opt == -1)
break;
@@ -463,9 +471,11 @@ int main(int argc, char *argv[])
case 'v':
cmd = cmd_version;
break;
+#ifndef USBIP_DAEMON_APP
case 'e':
usbip_update_driver();
break;
+#endif
case '?':
usbipd_help();
   

[PATCH v10 6/9] usbip: exporting devices: modifications to attach and detach

2016-08-15 Thread Nobuo Iwata
Refactoring to attach and detatch operation. Common parts to new 
application(vhci)-side daemon are moved to libsrc/vhci_driver.c. 

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/vhci_driver.c | 99 
 tools/usb/usbip/libsrc/vhci_driver.h |  6 +-
 tools/usb/usbip/src/usbip_attach.c   | 50 ++
 tools/usb/usbip/src/usbip_detach.c   | 13 ++--
 4 files changed, 100 insertions(+), 68 deletions(-)

diff --git a/tools/usb/usbip/libsrc/vhci_driver.c 
b/tools/usb/usbip/libsrc/vhci_driver.c
index ad92047..b7ca63d 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.c
+++ b/tools/usb/usbip/libsrc/vhci_driver.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2005-2007 Takahiro Hirofuchi
  */
 
 #include "usbip_common.h"
@@ -7,6 +8,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 #include "sysfs_utils.h"
 
 #undef  PROGNAME
@@ -215,6 +218,25 @@ static int read_record(int rhport, char *host, unsigned 
long host_len,
return 0;
 }
 
+#define OPEN_HC_MODE_FIRST 0
+#define OPEN_HC_MODE_REOPEN1
+
+static int open_hc_device(int mode)
+{
+   if (mode == OPEN_HC_MODE_REOPEN)
+   udev_device_unref(vhci_driver->hc_device);
+
+   vhci_driver->hc_device =
+   udev_device_new_from_subsystem_sysname(udev_context,
+  USBIP_VHCI_BUS_TYPE,
+  USBIP_VHCI_DRV_NAME);
+   if (!vhci_driver->hc_device) {
+   err("udev_device_new_from_subsystem_sysname failed");
+   return -1;
+   }
+   return 0;
+}
+
 /* -- */
 
 int usbip_vhci_driver_open(void)
@@ -227,28 +249,21 @@ int usbip_vhci_driver_open(void)
 
vhci_driver = calloc(1, sizeof(struct usbip_vhci_driver));
 
-   /* will be freed in usbip_driver_close() */
-   vhci_driver->hc_device =
-   udev_device_new_from_subsystem_sysname(udev_context,
-  USBIP_VHCI_BUS_TYPE,
-  USBIP_VHCI_DRV_NAME);
-   if (!vhci_driver->hc_device) {
-   err("udev_device_new_from_subsystem_sysname failed");
-   goto err;
-   }
+   if (open_hc_device(OPEN_HC_MODE_FIRST))
+   goto err_free_driver;
 
vhci_driver->nports = get_nports();
 
dbg("available ports: %d", vhci_driver->nports);
 
if (refresh_imported_device_list())
-   goto err;
+   goto err_unref_device;
 
return 0;
 
-err:
+err_unref_device:
udev_device_unref(vhci_driver->hc_device);
-
+err_free_driver:
if (vhci_driver)
free(vhci_driver);
 
@@ -277,7 +292,8 @@ void usbip_vhci_driver_close(void)
 
 int usbip_vhci_refresh_device_list(void)
 {
-
+   if (open_hc_device(OPEN_HC_MODE_REOPEN))
+   goto err;
if (refresh_imported_device_list())
goto err;
 
@@ -409,3 +425,58 @@ int usbip_vhci_imported_device_dump(struct 
usbip_imported_device *idev)
 
return 0;
 }
+
+#define MAX_BUFF 100
+int usbip_vhci_create_record(char *host, char *port, char *busid, int rhport)
+{
+   int fd;
+   char path[PATH_MAX+1];
+   char buff[MAX_BUFF+1];
+   int ret;
+
+   ret = mkdir(VHCI_STATE_PATH, 0700);
+   if (ret < 0) {
+   /* if VHCI_STATE_PATH exists, then it better be a directory */
+   if (errno == EEXIST) {
+   struct stat s;
+
+   ret = stat(VHCI_STATE_PATH, &s);
+   if (ret < 0)
+   return -1;
+   if (!(s.st_mode & S_IFDIR))
+   return -1;
+   } else
+   return -1;
+   }
+
+   snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport);
+
+   fd = open(path, O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU);
+   if (fd < 0)
+   return -1;
+
+   snprintf(buff, MAX_BUFF, "%s %s %s\n",
+   host, port, busid);
+
+   ret = write(fd, buff, strlen(buff));
+   if (ret != (ssize_t) strlen(buff)) {
+   close(fd);
+   return -1;
+   }
+
+   close(fd);
+
+   return 0;
+}
+
+int usbip_vhci_delete_record(int rhport)
+{
+   char path[PATH_MAX+1];
+
+   snprintf(path, PATH_MAX, VHCI_STATE_PATH"/port%d", rhport);
+
+   remove(path);
+   rmdir(VHCI_STATE_PATH);
+
+   return 0;
+}
diff --git a/tools/usb/usbip/libsrc/vhci_driver.h 
b/tools/usb/usbip/libsrc/vhci_driver.h
index fa2316c..f955ada 100644
--- a/tools/usb/usbip/libsrc/vhci_driver.h
+++ b/tools/usb/usbip/libsrc/vhci_driver.h
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2005-2007 Takahiro Hirofuchi
+ * Copyright (C) 2015 Nobuo Iwata
+ *   20

[PATCH v10 4/9] usbip: exporting devices: new disconnect operation

2016-08-15 Thread Nobuo Iwata
New disconnect operation.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/Makefile.am|   2 +-
 tools/usb/usbip/src/usbip.c|   6 +
 tools/usb/usbip/src/usbip.h|   2 +
 tools/usb/usbip/src/usbip_disconnect.c | 215 +
 4 files changed, 224 insertions(+), 1 deletion(-)

diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 0947476..42760c3 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -7,6 +7,6 @@ sbin_PROGRAMS := usbip usbipd
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
-usbip_connect.c
+usbip_connect.c usbip_disconnect.c
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c
index 584d7d5..f0e9e06 100644
--- a/tools/usb/usbip/src/usbip.c
+++ b/tools/usb/usbip/src/usbip.c
@@ -83,6 +83,12 @@ static const struct command cmds[] = {
.usage = usbip_connect_usage
},
{
+   .name  = "disconnect",
+   .fn= usbip_disconnect,
+   .help  = "Disconnect a USB device from a remote computer",
+   .usage = usbip_disconnect_usage
+   },
+   {
.name  = "list",
.fn= usbip_list,
.help  = "List exportable or local USB devices",
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index f365353..a8cbd16 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -32,6 +32,7 @@ int usbip_bind(int argc, char *argv[]);
 int usbip_unbind(int argc, char *argv[]);
 int usbip_port_show(int argc, char *argv[]);
 int usbip_connect(int argc, char *argv[]);
+int usbip_disconnect(int argc, char *argv[]);
 
 void usbip_attach_usage(void);
 void usbip_detach_usage(void);
@@ -39,6 +40,7 @@ void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
 void usbip_connect_usage(void);
+void usbip_disconnect_usage(void);
 
 int usbip_bind_device(char *busid);
 int usbip_unbind_device(char *busid);
diff --git a/tools/usb/usbip/src/usbip_disconnect.c 
b/tools/usb/usbip/src/usbip_disconnect.c
new file mode 100644
index 000..8155384
--- /dev/null
+++ b/tools/usb/usbip/src/usbip_disconnect.c
@@ -0,0 +1,215 @@
+/*
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
+ *   2005-2007 Takahiro Hirofuchi
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "usbip_host_driver.h"
+#include "usbip_host_common.h"
+#include "usbip_device_driver.h"
+#include "usbip_common.h"
+#include "usbip_network.h"
+#include "usbip.h"
+
+static struct usbip_host_driver *driver = &host_driver;
+
+static const char usbip_disconnect_usage_string[] =
+   "usbip disconnect \n"
+   "-r, --remote=Address of a remote computer\n"
+   "-b, --busid=Bus ID of a device to be disconnected\n"
+   "-d, --device   Run with an alternate driver, e.g. vUDC\n";
+
+void usbip_disconnect_usage(void)
+{
+   printf("usage: %s", usbip_disconnect_usage_string);
+}
+
+static int send_unexport_device(int sockfd, struct usbip_usb_device *udev)
+{
+   int rc;
+   struct op_unexport_request request;
+   struct op_unexport_reply   reply;
+   uint16_t code = OP_REP_UNEXPORT;
+
+   memset(&request, 0, sizeof(request));
+   memset(&reply, 0, sizeof(reply));
+
+   /* send a request */
+   rc = usbip_net_send_op_common(sockfd, OP_REQ_UNEXPORT, 0);
+   if (rc < 0) {
+   err("send op_common");
+   return -1;
+   }
+
+   memcpy(&request.udev, udev, sizeof(struct usbip_usb_device));
+
+   PACK_OP_UNEXPORT_REQUEST(0, &request);
+
+   rc = usbip_net_send(sockfd, (void *) &request, sizeof(request));
+   if (rc < 0) {
+   err("send op_export_request");
+   return -1;
+   }
+
+   /* receive a reply */
+   rc = usbip_net_recv_op_common(sockfd, &code);
+   if (rc < 0) {
+   err("recv op_common");
+   return -1;
+   }
+
+  

[PATCH v10 5/9] usbip: exporting devices: modifications to daemon

2016-08-15 Thread Nobuo Iwata
Refactoring to the daemon.

usbipd_dev.c is device-side specific code extracted from usbipd.c.

usbipd.c is left as common parts for both device(stub)-side and 
application(vhci)-side daemon.

usbip_net_set_nodelay() is the middle of device side daemon operation 
and it does not make mush sence. In the client operation, it's in right 
after connect(). So, in daemon, it is moved to right after accept() to 
affect it both device and application side.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/doc/usbipd.8 |   1 -
 tools/usb/usbip/src/Makefile.am  |   2 +-
 tools/usb/usbip/src/usbipd.c | 238 +++--
 tools/usb/usbip/src/usbipd.h |  39 +
 tools/usb/usbip/src/usbipd_dev.c | 252 +++
 5 files changed, 315 insertions(+), 217 deletions(-)

diff --git a/tools/usb/usbip/doc/usbipd.8 b/tools/usb/usbip/doc/usbipd.8
index ac4635d..6e1a008 100644
--- a/tools/usb/usbip/doc/usbipd.8
+++ b/tools/usb/usbip/doc/usbipd.8
@@ -88,4 +88,3 @@ USB/IP client can connect and use exported devices.
 
 .SH "SEE ALSO"
 \fBusbip\fP\fB(8)\fB\fP
-
diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index 42760c3..1aa5156 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -9,4 +9,4 @@ usbip_SOURCES := usbip.h utils.h usbip.c utils.c 
usbip_network.c \
 usbip_bind.c usbip_unbind.c usbip_port.c \
 usbip_connect.c usbip_disconnect.c
 
-usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
+usbipd_SOURCES := usbip_network.h usbipd.c usbipd_dev.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbipd.c b/tools/usb/usbip/src/usbipd.c
index a0972de..0ca5de5 100644
--- a/tools/usb/usbip/src/usbipd.c
+++ b/tools/usb/usbip/src/usbipd.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  * Copyright (C) 2015-2016 Samsung Electronics
  *   Igor Kotrasinski 
@@ -43,25 +44,19 @@
 #include 
 #include 
 
-#include "usbip_host_driver.h"
-#include "usbip_host_common.h"
-#include "usbip_device_driver.h"
 #include "usbip_common.h"
 #include "usbip_network.h"
+#include "usbipd.h"
 #include "list.h"
 
-#undef  PROGNAME
-#define PROGNAME "usbipd"
 #define MAXSOCKFD 20
 
 #define MAIN_LOOP_TIMEOUT 10
 
-#define DEFAULT_PID_FILE "/var/run/" PROGNAME ".pid"
-
 static const char usbip_version_string[] = PACKAGE_STRING;
 
 static const char usbipd_help_string[] =
-   "usage: usbipd [options]\n"
+   "usage: %s [options]\n"
"\n"
"   -4, --ipv4\n"
"   Bind to IPv4. Default is both.\n"
@@ -82,7 +77,7 @@ static const char usbipd_help_string[] =
"\n"
"   -PFILE, --pid FILE\n"
"   Write process id to FILE.\n"
-   "   If no FILE specified, use " DEFAULT_PID_FILE "\n"
+   "   If no FILE specified, use %s.\n"
"\n"
"   -tPORT, --tcp-port PORT\n"
"   Listen on TCP/IP port PORT.\n"
@@ -93,198 +88,9 @@ static const char usbipd_help_string[] =
"   -v, --version\n"
"   Show version.\n";
 
-static struct usbip_host_driver *driver;
-
 static void usbipd_help(void)
 {
-   printf("%s\n", usbipd_help_string);
-}
-
-static int recv_request_import(int sockfd)
-{
-   struct op_import_request req;
-   struct usbip_exported_device *edev;
-   struct usbip_usb_device pdu_udev;
-   struct list_head *i;
-   int found = 0;
-   int error = 0;
-   int rc;
-
-   memset(&req, 0, sizeof(req));
-
-   rc = usbip_net_recv(sockfd, &req, sizeof(req));
-   if (rc < 0) {
-   dbg("usbip_net_recv failed: import request");
-   return -1;
-   }
-   PACK_OP_IMPORT_REQUEST(0, &req);
-
-   list_for_each(i, &driver->edev_list) {
-   edev = list_entry(i, struct usbip_exported_device, node);
-   if (!strncmp(req.busid, edev->udev.busid, SYSFS_BUS_ID_SIZE)) {
-   info("found requested device: %s", req.busid);
-   found = 1;
-   break;
-   }
-   }
-
-   if (found) {
-   /* should set TCP_NODELAY for usbip */
-   usbip_net_set_nodelay(sockfd);
-
-   /* export device needs a TCP/IP socket descriptor */
-   rc = usbip_export_device(edev, sockfd);
-   if (rc < 0)
-   error = 1;
-   } else {
-   info("requested device not found: %s", req.busid);
-   error = 1;
-   }
-
-   rc = usbip_net_send_op_common(sockfd, OP_REP_IMPORT,
- (!error ? ST_OK : ST_NA));
-   if (rc < 0) {
-   dbg("usbip_net_send_op_common failed: %#0x", OP_REP_IMPORT);
-   return -1;
-   }
-
-   if (error) 

[PATCH v10 1/9] usbip: exporting devices: modifications to network header

2016-08-15 Thread Nobuo Iwata
Modification to export and un-export response in 
tools/usb/usbip/src/usbip_network.h. It just changes return code type 
from int to uint32_t as same as other responses.

Added export and un-export request/response to 
Documentation/usb/usbip_protocol.txt.

Signed-off-by: Nobuo Iwata 
---
 Documentation/usb/usbip_protocol.txt | 204 ---
 tools/usb/usbip/src/usbip_network.h  |   5 +-
 2 files changed, 184 insertions(+), 25 deletions(-)

diff --git a/Documentation/usb/usbip_protocol.txt 
b/Documentation/usb/usbip_protocol.txt
index 16b6fe2..d4be5b6 100644
--- a/Documentation/usb/usbip_protocol.txt
+++ b/Documentation/usb/usbip_protocol.txt
@@ -1,20 +1,26 @@
 PRELIMINARY DRAFT, MAY CONTAIN MISTAKES!
 28 Jun 2011
+MODIFIED FOR CONNECT AND DISCONNECT OPERARION.
+07 March 2016
 
-The USB/IP protocol follows a server/client architecture. The server exports 
the
-USB devices and the clients imports them. The device driver for the exported
-USB device runs on the client machine.
+The USB/IP protocol follows a server/client architecture between two computers
+one has USB devices and the other runs application using the devices. There are
+two ways for initiation.
 
-The client may ask for the list of the exported USB devices. To get the list 
the
-client opens a TCP/IP connection towards the server, and sends an 
OP_REQ_DEVLIST
-packet on top of the TCP/IP connection (so the actual OP_REQ_DEVLIST may be 
sent
-in one or more pieces at the low level transport layer). The server sends back
-the OP_REP_DEVLIST packet which lists the exported USB devices. Finally the
-TCP/IP connection is closed.
+The first way is to import devices from application-side. In this way, the
+server runs in device-side and the client runs in application-side. In device
+side user makes devices importable with 'bind' operation.
 
+The client may ask for the list of the importable USB devices. To get the list
+the client opens a TCP/IP connection towards the server, and sends an
+OP_REQ_DEVLIST packet on top of the TCP/IP connection (so the actual
+OP_REQ_DEVLIST may be sent in one or more pieces at the low level transport
+layer). The server sends back the OP_REP_DEVLIST packet which lists the
+importable USB devices. Finally the TCP/IP connection is closed.
+
+   application-sidedevice-side
  virtual host controller usb host
-  "client"   "server"
-  (imports USB devices) (exports USB devices)
+  "client" (lists importable devices)"server"
   | |
   |  OP_REQ_DEVLIST |
   | --> |
@@ -23,18 +29,13 @@ TCP/IP connection is closed.
   | <-- |
   | |
 
-Once the client knows the list of exported USB devices it may decide to use one
-of them. First the client opens a TCP/IP connection towards the server and
-sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT. If the
-import was successful the TCP/IP connection remains open and will be used
-to transfer the URB traffic between the client and the server. The client may
-send two types of packets: the USBIP_CMD_SUBMIT to submit an URB, and
-USBIP_CMD_UNLINK to unlink a previously submitted URB. The answers of the
-server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK respectively.
+Once the client knows the list of importable USB devices it may decide to use
+one of them. First the client opens a TCP/IP connection towards the server and
+sends an OP_REQ_IMPORT packet. The server replies with OP_REP_IMPORT.
 
+   application-sidedevice-side
  virtual host controller usb host
-  "client"   "server"
-  (imports USB devices) (exports USB devices)
+  "client"   (imports a USB device)  "server"
   | |
   |  OP_REQ_IMPORT  |
   | --> |
@@ -42,6 +43,32 @@ server may be USBIP_RET_SUBMIT and USBIP_RET_UNLINK 
respectively.
   |  OP_REP_IMPORT  |
   | <-- |
   | |
+
+The second way is to export devices from device-side. In this way, the server
+runs in application-side and the client runs in device-side. The client binds a
+device to export, opens a TCP/IP connection towards the server and sends an
+OP_REQ_EXPORT packet. The server replies with OP_REP_EXPORT.
+
+   application-side

[PATCH v10 3/9] usbip: exporting devices: new connect operation

2016-08-15 Thread Nobuo Iwata
New connect operation.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/src/Makefile.am |   3 +-
 tools/usb/usbip/src/usbip.c |   9 +-
 tools/usb/usbip/src/usbip.h |   5 +-
 tools/usb/usbip/src/usbip_connect.c | 228 
 4 files changed, 242 insertions(+), 3 deletions(-)

diff --git a/tools/usb/usbip/src/Makefile.am b/tools/usb/usbip/src/Makefile.am
index e81a4eb..0947476 100644
--- a/tools/usb/usbip/src/Makefile.am
+++ b/tools/usb/usbip/src/Makefile.am
@@ -6,6 +6,7 @@ sbin_PROGRAMS := usbip usbipd
 
 usbip_SOURCES := usbip.h utils.h usbip.c utils.c usbip_network.c \
 usbip_attach.c usbip_detach.c usbip_list.c \
-usbip_bind.c usbip_unbind.c usbip_port.c
+usbip_bind.c usbip_unbind.c usbip_port.c \
+usbip_connect.c
 
 usbipd_SOURCES := usbip_network.h usbipd.c usbip_network.c
diff --git a/tools/usb/usbip/src/usbip.c b/tools/usb/usbip/src/usbip.c
index d7599d9..584d7d5 100644
--- a/tools/usb/usbip/src/usbip.c
+++ b/tools/usb/usbip/src/usbip.c
@@ -2,7 +2,8 @@
  * command structure borrowed from udev
  * (git://git.kernel.org/pub/scm/linux/hotplug/udev.git)
  *
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -76,6 +77,12 @@ static const struct command cmds[] = {
.usage = usbip_detach_usage
},
{
+   .name  = "connect",
+   .fn= usbip_connect,
+   .help  = "Connect a USB device to a remote computer",
+   .usage = usbip_connect_usage
+   },
+   {
.name  = "list",
.fn= usbip_list,
.help  = "List exportable or local USB devices",
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index c296910..f365353 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -30,12 +31,14 @@ int usbip_list(int argc, char *argv[]);
 int usbip_bind(int argc, char *argv[]);
 int usbip_unbind(int argc, char *argv[]);
 int usbip_port_show(int argc, char *argv[]);
+int usbip_connect(int argc, char *argv[]);
 
 void usbip_attach_usage(void);
 void usbip_detach_usage(void);
 void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
+void usbip_connect_usage(void);
 
 int usbip_bind_device(char *busid);
 int usbip_unbind_device(char *busid);
diff --git a/tools/usb/usbip/src/usbip_connect.c 
b/tools/usb/usbip/src/usbip_connect.c
new file mode 100644
index 000..bbecc7e
--- /dev/null
+++ b/tools/usb/usbip/src/usbip_connect.c
@@ -0,0 +1,228 @@
+/*
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
+ *   2005-2007 Takahiro Hirofuchi
+ *
+ * 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.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#include "usbip_host_driver.h"
+#include "usbip_host_common.h"
+#include "usbip_device_driver.h"
+#include "usbip_common.h"
+#include "usbip_network.h"
+#include "usbip.h"
+
+static struct usbip_host_driver *driver = &host_driver;
+
+static const char usbip_connect_usage_string[] =
+   "usbip connect \n"
+   "-r, --remote=Address of a remote computer\n"
+   "-b, --busid=Bus ID of a device to be connected\n"
+   "-d, --device   Run with an alternate driver, e.g. vUDC\n";
+
+void usbip_connect_usage(void)
+{
+   printf("usage: %s", usbip_connect_usage_string);
+}
+
+static int send_export_device(int sockfd, struct usbip_usb_device *udev)
+{
+   int rc;
+   struct op_export_request request;
+   struct op_export_reply   reply;
+   uint16_t code = OP_REP_EXPORT;
+
+   memset(&request, 0, sizeof(request));
+   memset(&reply, 0, sizeof(reply));
+
+   /* send a request */
+   rc = usbip_net_send_op_common(sockfd, OP_REQ_EXPORT, 0);
+   if (rc < 0) {
+   err("send op_common");
+   return -1;
+  

[PATCH v10 0/9] usbip: exporting devices

2016-08-15 Thread Nobuo Iwata
Dear all,

This series of patches adds exporting device operation to USB/IP.

1. Overview

Exporting devices may not be a new idea. The request and response PDU 
have been defined in tools/usbip/usbip/src/usbip_network.h.
#define OP_EXPORT   0x06
#define OP_REQ_EXPORT   (OP_REQUEST | OP_EXPORT)
#define OP_REP_EXPORT   (OP_REPLY   | OP_EXPORT)
# struct op_export_request
# struct op_export_reply
#define OP_UNEXPORT 0x07
#define OP_REQ_UNEXPORT (OP_REQUEST | OP_UNEXPORT)
#define OP_REP_UNEXPORT (OP_REPLY   | OP_UNEXPORT)
# struct op_unexport_request
# struct op_unexport_reply 

But they have not been used yet. This series adds new operations: 
'connect' and 'disconnect' using these PDUs.

EXISTING) - invites devices from application(vhci)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
 1) usbipd ... start daemon
 = = =
 2) usbip list --local
 3) usbip bind
<--- list bound devices ---   4) usbip list --remote
<--- import a device --   5) usbip attach
 = = =
   X disconnected 6) usbip detach
 7) usbip unbind

NEW) - dedicates devices from device(stb)-side
 +--+ +--+
 device--+ STUB | | application/VHCI |
 +--+ +--+
  1) usbipa ... start daemon
 = = =
 2) usbip list --local
 3) usbip connect --- export a device -->
 = = =
 4) usbip disconnect  --- un-export a device --->

 Bind and unbind are done in connect and disconnect internally.

2. The use cases

EXISTING)

In existing way, computers in small distance, having same user account, 
can be easily managed by a same user. Bind in local machine and attach 
in remote machine by the user. The devices can be exporsed 
automatically in the local machine, for example, at strat up. They can 
be attached from remote.

When there are distributes linux nodes with USB devices in internet, 
they are exposed by bind operation at start upr, server behind firewall 
can list and attach the devices.  
   Internet  
 Exposed   +--+++++
 +--+  |Linux |+   |Router, ||Service |
+|device|--|Controller||---|proxy,  ||on  |
|+--+  +--+|   |firewall||Linux   |
+--++--+   ++++
   <--- attach(import)
  USB/IP + WS proxy   WS proxy + USB/IP

NEW)

Assuming that a server computer which runs application and VHCI is in a 
server room and device side machines are small distributed nodes 
outside of the server room, the operator of the server compter is 
different form the distributed nodes. The server computer may be in 
unattended operation. In the new way, after the daemon has been 
started, device can be connected with connect command in the 
distributed nodes. If the distributed nodes doesn't have user 
interface, the connect command can be executed from start up procedure.

In another senario to connect devices to a Linux based cloud service 
using WebSocket proxy, it's needed to establish connection from a 
device inside of firewall to a service outside. Exporting is suitable 
for the senario.

   Home/SOHO/Intranet   Internet  
   +--+ ++   ++
 +--+  |Linux |+|Router, |   |Internet|
+|device|--|Controller|||proxy,  |---|service |
|+--+  +--+||firewall|   |on Linux|
+--++--+++   ++
   connect(export) -->
  USB/IP + WS proxy   WS proxy + USB/IP
ex)
DeviceService 
 sensors . environment analysis 
 cameras . monitoring, recording
 ID/biometric readers  authentication

Connection from outside firewall is usually blocked.
So existing import request sent with attach command doesn't work.

# usbipd (blocked)|| <- # usbip attach

Firewall opens some ports, usually HTTP(80) and HTTPS(443), from inside.
Then export request sent with new connect command works.

# usbip connect  -> # usbipa
 (passed)

3. Combination with vUDC

New operations work with vUDC. --device option specifies vUDC mode as 
well as list operaion. With stub, connect and disconnect execute bind 
and unbind internally. With vUDC, the

[PATCH v10 2/9] usbip: exporting devices: modifications to host side libraries

2016-08-15 Thread Nobuo Iwata
usbip_get_device() method in usbip_host_driver_ops was not used. It is 
modified as a function to find an exported device for new operations 
'connect' and 'disconnect'.

bind and unbind function are exported for the new operations.

Signed-off-by: Nobuo Iwata 
---
 tools/usb/usbip/libsrc/usbip_host_common.c | 6 ++
 tools/usb/usbip/libsrc/usbip_host_common.h | 8 
 tools/usb/usbip/src/usbip.h| 3 +++
 tools/usb/usbip/src/usbip_bind.c   | 7 ---
 tools/usb/usbip/src/usbip_unbind.c | 7 ---
 5 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/tools/usb/usbip/libsrc/usbip_host_common.c 
b/tools/usb/usbip/libsrc/usbip_host_common.c
index 9d41522..6a98d6c 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.c
+++ b/tools/usb/usbip/libsrc/usbip_host_common.c
@@ -256,17 +256,15 @@ int usbip_export_device(struct usbip_exported_device 
*edev, int sockfd)
 }
 
 struct usbip_exported_device *usbip_generic_get_device(
-   struct usbip_host_driver *hdriver, int num)
+   struct usbip_host_driver *hdriver, char *busid)
 {
struct list_head *i;
struct usbip_exported_device *edev;
-   int cnt = 0;
 
list_for_each(i, &hdriver->edev_list) {
edev = list_entry(i, struct usbip_exported_device, node);
-   if (num == cnt)
+   if (!strncmp(busid, edev->udev.busid, SYSFS_BUS_ID_SIZE))
return edev;
-   cnt++;
}
 
return NULL;
diff --git a/tools/usb/usbip/libsrc/usbip_host_common.h 
b/tools/usb/usbip/libsrc/usbip_host_common.h
index a64b803..f9a9def 100644
--- a/tools/usb/usbip/libsrc/usbip_host_common.h
+++ b/tools/usb/usbip/libsrc/usbip_host_common.h
@@ -38,7 +38,7 @@ struct usbip_host_driver_ops {
void (*close)(struct usbip_host_driver *hdriver);
int (*refresh_device_list)(struct usbip_host_driver *hdriver);
struct usbip_exported_device * (*get_device)(
-   struct usbip_host_driver *hdriver, int num);
+   struct usbip_host_driver *hdriver, char *busid);
 
int (*read_device)(struct udev_device *sdev,
   struct usbip_usb_device *dev);
@@ -86,11 +86,11 @@ static inline int usbip_refresh_device_list(struct 
usbip_host_driver *hdriver)
 }
 
 static inline struct usbip_exported_device *
-usbip_get_device(struct usbip_host_driver *hdriver, int num)
+usbip_get_device(struct usbip_host_driver *hdriver, char *busid)
 {
if (!hdriver->ops.get_device)
return NULL;
-   return hdriver->ops.get_device(hdriver, num);
+   return hdriver->ops.get_device(hdriver, busid);
 }
 
 /* Helper functions for implementing driver backend */
@@ -99,6 +99,6 @@ void usbip_generic_driver_close(struct usbip_host_driver 
*hdriver);
 int usbip_generic_refresh_device_list(struct usbip_host_driver *hdriver);
 int usbip_export_device(struct usbip_exported_device *edev, int sockfd);
 struct usbip_exported_device *usbip_generic_get_device(
-   struct usbip_host_driver *hdriver, int num);
+   struct usbip_host_driver *hdriver, char *busid);
 
 #endif /* __USBIP_HOST_COMMON_H */
diff --git a/tools/usb/usbip/src/usbip.h b/tools/usb/usbip/src/usbip.h
index 84fe66a..c296910 100644
--- a/tools/usb/usbip/src/usbip.h
+++ b/tools/usb/usbip/src/usbip.h
@@ -37,4 +37,7 @@ void usbip_list_usage(void);
 void usbip_bind_usage(void);
 void usbip_unbind_usage(void);
 
+int usbip_bind_device(char *busid);
+int usbip_unbind_device(char *busid);
+
 #endif /* __USBIP_H */
diff --git a/tools/usb/usbip/src/usbip_bind.c b/tools/usb/usbip/src/usbip_bind.c
index fa46141..1c09338 100644
--- a/tools/usb/usbip/src/usbip_bind.c
+++ b/tools/usb/usbip/src/usbip_bind.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -139,7 +140,7 @@ out:
return status;
 }
 
-static int bind_device(char *busid)
+int usbip_bind_device(char *busid)
 {
int rc;
struct udev *udev;
@@ -200,7 +201,7 @@ int usbip_bind(int argc, char *argv[])
 
switch (opt) {
case 'b':
-   ret = bind_device(optarg);
+   ret = usbip_bind_device(optarg);
goto out;
default:
goto err_out;
diff --git a/tools/usb/usbip/src/usbip_unbind.c 
b/tools/usb/usbip/src/usbip_unbind.c
index a4a496c..cc1ff26 100644
--- a/tools/usb/usbip/src/usbip_unbind.c
+++ b/tools/usb/usbip/src/usbip_unbind.c
@@ -1,5 +1,6 @@
 /*
- * Copyright (C) 2011 matt mooney 
+ * Copyright (C) 2015 Nobuo Iwata
+ *   2011 matt mooney 
  *   2005-2007 Takahiro Hirofuchi
  *
  * This program is free software: you can redistribute it and/or modify
@@ -39,7 +40,7 @@ void usbip_

RE: [lkp] [usb] ad05399d68: BUG: unable to handle kernel NULL pointer dereference at 0000000000000012

2016-08-15 Thread Peter Chen
 
>
>
>FYI, we noticed the following commit:
>
>https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git testing/next 
>commit
>ad05399d68b6ae1649cdcfc82ce3ffea1a7c5104 ("usb: udc: core: fix error handling")
>

Hi Xiaolong,

You reported it one month ago, and said it is a false report. see below.
Would you please double confirm it?

On Wed, Jul 13, 2016 at 01:55:26AM +, Peter Chen wrote:
> 
>
>>-Original Message-
>>From: lkp-requ...@eclists.intel.com 
>>[mailto:lkp-requ...@eclists.intel.com] On Behalf Of kernel test robot
>>Sent: Wednesday, July 13, 2016 9:28 AM
>>To: Peter Chen 
>>Cc: 0day robot ; LKML 
>>; l...@01.org
>>Subject: [lkp] [usb] 9696ef14de: WARNING: CPU: 0 PID: 1 at 
>>lib/list_debug.c:36
>>__list_add+0x104/0x188
>>
>>
>>FYI, we noticed the following commit:
>>
>>https://github.com/0day-ci/linux Peter-Chen/usb-udc-core-fix-error-
>>handling/20160711-100832
>>commit 9696ef14ded07fb0847f8e1cdda6d98a89ecd4f2 ("usb: udc: core: fix 
>>error
>>handling")
>>
>
>Thanks,  but I really can't find the relationship between my patch and dump.
>Can you reproduce it after running again or without my patch?
>

Sorry, it's a false report, the error dump also showed in parent commit, please 
ignore the report and sorry for the noise.

Thanks,
Xiaolong




Peter

>in testcase: boot
>
>on test machine: 1 threads qemu-system-x86_64 -enable-kvm -cpu SandyBridge
>with 512M memory
>
>caused below changes:
>
>
>+---+++
>|   | 0937a4d787
>| | ad05399d68 |
>+---+++
>| boot_successes| 0  | 0   
>   |
>| boot_failures | 12 | 12  
>   |
>| WARNING:at_lib/list_debug.c:#__list_del_entry | 2  | 12  
>   |
>| BUG:kernel_test_hang  | 2  | 
>   |
>| backtrace:kernel_restart  | 2  | 
>   |
>| backtrace:SyS_reboot  | 2  | 
>   |
>| BUG:kernel_oversize_in_test_stage | 4  | 
>   |
>| Kernel_panic-not_syncing:Attempted_to_kill_init!exitcode= | 6  | 
>   |
>| BUG:unable_to_handle_kernel   | 0  | 11  
>   |
>| Oops  | 0  | 11  
>   |
>| RIP:sysfs_kf_write| 0  | 11  
>   |
>| Kernel_panic-not_syncing:Fatal_exception  | 0  | 11  
>   |
>| backtrace:serio_handle_event  | 0  | 12  
>   |
>| backtrace:vfs_write   | 0  | 11  
>   |
>| backtrace:SyS_write   | 0  | 11  
>   |
>+---+++
>
>
>[   12.161205] BUG: unable to handle kernel NULL pointer dereference at
>0012
>[   12.162485] IP: [] sysfs_kf_write+0x4f/0x70
>[   12.163414] PGD 1a380067 PUD 1a357067 PMD 0
>[   12.164242] Oops:  [#1] PREEMPT SMP
>[   12.164952] CPU: 0 PID: 240 Comm: udevadm Tainted: GW   
>4.8.0-rc1-
>00021-gad05399 #1
>[   12.166477] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS
>Debian-1.8.2-1 04/01/2014
>[   12.167885] task: 88001a3701c0 task.stack: 88001a374000
>[   12.168789] RIP: 0010:[]  []
>sysfs_kf_write+0x4f/0x70
>[   12.170082] RSP: 0018:88001a377dc0  EFLAGS: 00010297
>[   12.171001] RAX: 88001aad9260 RBX:  RCX:
>0003
>[   12.172252] RDX: 88001a253020 RSI: 82888fa0 RDI: 
>88001aada1f8
>[   12.186536] RBP: 88001a377de8 R08:  R09:
>
>[   12.187769] R10: 55aab65f R11: 0001 R12:
>0003
>[   12.189058] R13: 88001a393000 R14: 000a R15:
>88001a253020
>[   12.190274] FS:  7f1f13d8f700() GS:88001f40()
>knlGS:
>[   12.191514] CS:  0010 DS:  ES:  CR0: 80050033
>[   12.192393] CR2: 0012 CR3: 1a341000 CR4:
>000406b0
>[   12.193518] Stack:
>[   12.193884]  88001a253020 88001a393000 0003
>81245e80
>[   12.195278]  88001a393018 88001a377e28 81244e44
>88001a377f20
>[   12.196679]  88001dc6fc40 81244cf0 88001a377f20
>0003
>[   12.197896] Call Trace:
>[   12.198289]  [] ? sysfs_file_ops+0x90/0x90
>[   12.199162]  [] kernfs_fop_write+0x154/0x200
>[   12.211238]  [] ? kernfs_vma_page_mkwrite+0xb0/0xb0
>[   12.212330]  [] __vfs_write+0x43/0x1b0
>[   12.213150]  [] ? __sb_start_write+0xb

[PATCH v9 5/5] usb: dwc3: add rockchip specific glue layer

2016-08-15 Thread William Wu
Add rockchip specific glue layer to support USB3 Peripheral mode
and Host mode on rockchip platforms (e.g. rk3399).

The DesignWare USB3 integrated in rockchip SoCs is a configurable
IP Core which can be instantiated as Dual-Role Device (DRD), Host
Only (XHCI) and Peripheral Only configurations.

We use extcon notifier to manage usb cable detection and mode switch.
Enable DWC3 PM runtime auto suspend to allow core enter runtime_suspend
if USB cable is dettached. For host mode, it requires to keep whole
DWC3 controller in reset state to hold pipe power state in P2 before
initializing PHY. And it need to reconfigure USB PHY interface of DWC3
core after deassert DWC3 controller reset.

The current driver supports Host only and Peripheral Only well, for
now, we will add support for OTG after we have it all stabilized.

Signed-off-by: William Wu 
---
 drivers/usb/dwc3/Kconfig |   9 +
 drivers/usb/dwc3/Makefile|   1 +
 drivers/usb/dwc3/core.c  |   2 +-
 drivers/usb/dwc3/core.h  |   1 +
 drivers/usb/dwc3/dwc3-rockchip.c | 441 +++
 5 files changed, 453 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/dwc3/dwc3-rockchip.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index a64ce1c..3d5ec30 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -96,6 +96,15 @@ config USB_DWC3_OF_SIMPLE
 Currently supports Xilinx and Qualcomm DWC USB3 IP.
 Say 'Y' or 'M' if you have one such device.
 
+config USB_DWC3_ROCKCHIP
+   tristate "Rockchip Platforms"
+   depends on EXTCON && (ARCH_ROCKCHIP || COMPILE_TEST)
+   depends on OF
+   default USB_DWC3
+   help
+ Support of USB2/3 functionality in Rockchip platforms.
+ say 'Y' or 'M' if you have one such device.
+
 config USB_DWC3_ST
tristate "STMicroelectronics Platforms"
depends on ARCH_STI && OF
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 22420e1..86fc4fd 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -38,4 +38,5 @@ obj-$(CONFIG_USB_DWC3_EXYNOS) += dwc3-exynos.o
 obj-$(CONFIG_USB_DWC3_PCI) += dwc3-pci.o
 obj-$(CONFIG_USB_DWC3_KEYSTONE)+= dwc3-keystone.o
 obj-$(CONFIG_USB_DWC3_OF_SIMPLE)   += dwc3-of-simple.o
+obj-$(CONFIG_USB_DWC3_ROCKCHIP)+= dwc3-rockchip.o
 obj-$(CONFIG_USB_DWC3_ST)  += dwc3-st.o
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index e887b38..3da6215 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -405,7 +405,7 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc)
  * initialized. The PHY interfaces and the PHYs get initialized together with
  * the core in dwc3_core_init.
  */
-static int dwc3_phy_setup(struct dwc3 *dwc)
+int dwc3_phy_setup(struct dwc3 *dwc)
 {
u32 reg;
int ret;
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 3d94acd..79403ff 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -1123,6 +1123,7 @@ struct dwc3_gadget_ep_cmd_params {
 /* prototypes */
 void dwc3_set_mode(struct dwc3 *dwc, u32 mode);
 u32 dwc3_core_fifo_space(struct dwc3_ep *dep, u8 type);
+int dwc3_phy_setup(struct dwc3 *dwc);
 
 /* check whether we are on the DWC_usb31 core */
 static inline bool dwc3_is_usb31(struct dwc3 *dwc)
diff --git a/drivers/usb/dwc3/dwc3-rockchip.c b/drivers/usb/dwc3/dwc3-rockchip.c
new file mode 100644
index 000..632bbb9
--- /dev/null
+++ b/drivers/usb/dwc3/dwc3-rockchip.c
@@ -0,0 +1,441 @@
+/**
+ * dwc3-rockchip.c - Rockchip Specific Glue layer
+ *
+ * Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
+ *
+ * Authors: William Wu 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+#include "io.h"
+
+#define DWC3_ROCKCHIP_AUTOSUSPEND_DELAY  500 /* ms */
+
+struct dwc3_rockchip {
+   int num_clocks;
+   struct device   *dev;
+   struct clk  **clks;
+   struct dwc3 *dwc;
+   struct reset_control*otg_rst;
+   struct extcon_dev   *edev;
+   struct notifier_block   device_nb;
+   struct notifier_block   host_nb;
+   struct work_struct  otg_work;
+};
+
+static int dwc3_rockchip_device_notifier(struct notifier_block *nb,
+unsigned long event, vo

[PATCH v9 4/5] usb: dwc3: rockchip: add devicetree bindings documentation

2016-08-15 Thread William Wu
This patch adds the devicetree documentation required for Rockchip
USB3.0 core wrapper consisting of USB3.0 IP from Synopsys.

It supports DRD mode, and could operate in device mode (SS, HS, FS)
and host mode (SS, HS, FS, LS).

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v9:
- add required properties "resets" and "reset-names"
- add optional property "extcon"

Changes in v8:
- None

Changes in v7:
- add Acked-by (Rob Herring)

Changes in v6:
- rename bus_clk, and add usbdrd3_1 node as an example (Heiko)

Changes in v5:
- rename clock-names, and remove unnecessary clocks (Heiko)

Changes in v4:
- modify commit log, and add phy documentation location (Sergei)

Changes in v3:
- add dwc3 address (balbi)

Changes in v2:
- add rockchip,dwc3.txt to Documentation/devicetree/bindings/ (balbi, Brian)

 .../devicetree/bindings/usb/rockchip,dwc3.txt  | 71 ++
 1 file changed, 71 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/rockchip,dwc3.txt

diff --git a/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt 
b/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
new file mode 100644
index 000..3a79be8
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
@@ -0,0 +1,71 @@
+Rockchip SuperSpeed DWC3 USB SoC controller
+
+Required properties:
+- compatible:  should contain "rockchip,rk3399-dwc3" for rk3399 SoC
+- clocks:  A list of phandle + clock-specifier pairs for the
+   clocks listed in clock-names
+- clock-names: Should contain the following:
+  "ref_clk"Controller reference clk, have to be 24 MHz
+  "suspend_clk"Controller suspend clk, have to be 24 MHz or 32 KHz
+  "bus_clk"Master/Core clock, have to be >= 62.5 MHz for SS
+   operation and >= 30MHz for HS operation
+  "grf_clk"Controller grf clk
+- resets:  List of phandle and reset specifier pairs. Should contain
+   softreset line of the DWC3 controller
+- reset-names: List of reset signal names. Names should contain "usb3-otg"
+   for DWC3 controller reset.
+
+Optional properties:
+- extcon:  Phandles to external connector devices, which provide
+   "EXTCON_USB" and "EXTCON_USB_HOST" cable events.
+
+Required child node:
+A child node must exist to represent the core DWC3 IP block. The name of
+the node is not important. The content of the node is defined in dwc3.txt.
+
+Phy documentation is provided in the following places:
+Documentation/devicetree/bindings/phy/rockchip,dwc3-usb-phy.txt
+
+Example device nodes:
+
+   usbdrd3_0: usb@fe80 {
+   compatible = "rockchip,rk3399-dwc3";
+   clocks = <&cru SCLK_USB3OTG0_REF>, <&cru SCLK_USB3OTG0_SUSPEND>,
+<&cru ACLK_USB3OTG0>, <&cru ACLK_USB3_GRF>;
+   clock-names = "ref_clk", "suspend_clk",
+ "bus_clk", "grf_clk";
+   resets = <&cru SRST_A_USB3_OTG0>;
+   reset-names = "usb3-otg";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "disabled";
+   usbdrd_dwc3_0: dwc3@fe80 {
+   compatible = "snps,dwc3";
+   reg = <0x0 0xfe80 0x0 0x10>;
+   interrupts = ;
+   dr_mode = "otg";
+   status = "disabled";
+   };
+   };
+
+   usbdrd3_1: usb@fe90 {
+   compatible = "rockchip,rk3399-dwc3";
+   clocks = <&cru SCLK_USB3OTG1_REF>, <&cru SCLK_USB3OTG1_SUSPEND>,
+<&cru ACLK_USB3OTG1>, <&cru ACLK_USB3_GRF>;
+   clock-names = "ref_clk", "suspend_clk",
+ "bus_clk", "grf_clk";
+   resets = <&cru SRST_A_USB3_OTG1>;
+   reset-names = "usb3-otg";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "disabled";
+   usbdrd_dwc3_1: dwc3@fe90 {
+   compatible = "snps,dwc3";
+   reg = <0x0 0xfe90 0x0 0x10>;
+   interrupts = ;
+   dr_mode = "otg";
+   status = "disabled";
+   };
+   };
-- 
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 v9 2/5] usb: dwc3: make usb2 phy utmi interface configurable

2016-08-15 Thread William Wu
Support to configure the UTMI+ PHY with an 8- or 16-bit
interface via DT. The UTMI+ PHY interface is a hardware
capability, and it's platform dependent. Normally, the
PHYIF can be configured during coreconsultant.

But for some specific USB cores(e.g. rk3399 SoC DWC3),
the default PHYIF configuration value is false, so we
need to reconfigure it by software.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v9:
- None

Changes in v8:
- configure utmi interface via phy_type property in DT (Heiko, Rob Herring)
- add Acked-by (Rob Herring)
- modify commit message (Rob Herring)

Changes in v7:
- remove quirk and use only one property to configure utmi (Heiko, Rob Herring)

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- add a quirk for phyif_utmi (balbi)

 Documentation/devicetree/bindings/usb/generic.txt |  6 ++
 drivers/usb/dwc3/core.c   | 18 ++
 drivers/usb/dwc3/core.h   | 12 
 3 files changed, 36 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
b/Documentation/devicetree/bindings/usb/generic.txt
index bba8257..bfadeb1 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -11,6 +11,11 @@ Optional properties:
"peripheral" and "otg". In case this attribute isn't
passed via DT, USB DRD controllers should default to
OTG.
+ - phy_type: tells USB controllers that we want to configure the core to 
support
+   a UTMI+ PHY with an 8- or 16-bit interface if UTMI+ is
+   selected. Valid arguments are "utmi" and "utmi_wide".
+   In case this isn't passed via DT, USB controllers should
+   default to HW capability.
  - otg-rev: tells usb driver the release number of the OTG and EH supplement
with which the device and its descriptors are compliant,
in binary-coded decimal (i.e. 2.0 is 0200H). This
@@ -34,6 +39,7 @@ dwc3@4a03 {
usb-phy = <&usb2_phy>, <&usb3,phy>;
maximum-speed = "super-speed";
dr_mode = "otg";
+   phy_type = "utmi_wide";
otg-rev = <0x0200>;
adp-disable;
 };
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 14316e5..cdac019 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -485,6 +485,23 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
break;
}
 
+   switch (dwc->hsphy_mode) {
+   case USBPHY_INTERFACE_MODE_UTMI:
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+  DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_8_BIT) |
+  DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_8_BIT);
+   break;
+   case USBPHY_INTERFACE_MODE_UTMIW:
+   reg &= ~(DWC3_GUSB2PHYCFG_PHYIF_MASK |
+  DWC3_GUSB2PHYCFG_USBTRDTIM_MASK);
+   reg |= DWC3_GUSB2PHYCFG_PHYIF(UTMI_PHYIF_16_BIT) |
+  DWC3_GUSB2PHYCFG_USBTRDTIM(USBTRDTIM_UTMI_16_BIT);
+   break;
+   default:
+   break;
+   }
+
/*
 * Above 1.94a, it is recommended to set DWC3_GUSB2PHYCFG_SUSPHY to
 * '0' during coreConsultant configuration. So default value will
@@ -891,6 +908,7 @@ static int dwc3_probe(struct platform_device *pdev)
 
dwc->maximum_speed = usb_get_maximum_speed(dev);
dwc->dr_mode = usb_get_dr_mode(dev);
+   dwc->hsphy_mode = of_usb_get_phy_mode(dev->of_node);
 
dwc->has_lpm_erratum = device_property_read_bool(dev,
"snps,has-lpm-erratum");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 08ed9e0..cc4f551 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -203,6 +203,14 @@
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
 #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4)
 #define DWC3_GUSB2PHYCFG_ENBLSLPM  (1 << 8)
+#define DWC3_GUSB2PHYCFG_PHYIF(n)  (n << 3)
+#define DWC3_GUSB2PHYCFG_PHYIF_MASKDWC3_GUSB2PHYCFG_PHYIF(1)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM(n)  (n << 10)
+#define DWC3_GUSB2PHYCFG_USBTRDTIM_MASKDWC3_GUSB2PHYCFG_USBTRDTIM(0xf)
+#define USBTRDTIM_UTMI_8_BIT   9
+#define USBTRDTIM_UTMI_16_BIT  5
+#define UTMI_PHYIF_16_BIT  1
+#define UTMI_PHYIF_8_BIT   0
 
 /* Global USB2 PHY Vendor Control Register */
 #define DWC3_GUSB2PHYACC_NEWREGREQ (1 << 25)
@@ -748,6 +756,9 @@ struct dwc3_scratchpad_array {
  * @maximum_speed: maximum speed requested (mainly for testing purposes)
  * @revision: revision register contents
  * @dr_mode: 

[PATCH v9 3/5] usb: dwc3: add dis_del_phy_power_chg_quirk

2016-08-15 Thread William Wu
Add a quirk to clear the GUSB3PIPECTL.DELAYP1TRANS bit,
which specifies whether disable delay PHY power change
from P0 to P1/P2/P3 when link state changing from U0
to U1/U2/U3 respectively.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v9:
- None

Changes in v8:
- add Acked-by (Rob Herring)

Changes in v7:
- None

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- None

 Documentation/devicetree/bindings/usb/dwc3.txt | 2 ++
 drivers/usb/dwc3/core.c| 5 +
 drivers/usb/dwc3/core.h| 3 +++
 3 files changed, 10 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index 020b0e9..e96bfc2 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -42,6 +42,8 @@ Optional properties:
  - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists
in GUSB2PHYCFG, specify that USB2 PHY doesn't provide
a free-running PHY clock.
+ - snps,dis-del-phy-power-chg-quirk: when set core will change PHY power
+   from P0 to P1/P2/P3 without delay.
  - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
utmi_l1_suspend_n, false when asserts utmi_sleep_n
  - snps,hird-threshold: HIRD threshold
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index cdac019..e887b38 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -448,6 +448,9 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
if (dwc->dis_u3_susphy_quirk)
reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
 
+   if (dwc->dis_del_phy_power_chg_quirk)
+   reg &= ~DWC3_GUSB3PIPECTL_DEPOCHANGE;
+
dwc3_writel(dwc->regs, DWC3_GUSB3PIPECTL(0), reg);
 
reg = dwc3_readl(dwc->regs, DWC3_GUSB2PHYCFG(0));
@@ -947,6 +950,8 @@ static int dwc3_probe(struct platform_device *pdev)
"snps,dis_rxdet_inp3_quirk");
dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
"snps,dis-u2-freeclk-exists-quirk");
+   dwc->dis_del_phy_power_chg_quirk = device_property_read_bool(dev,
+   "snps,dis-del-phy-power-chg-quirk");
 
dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
"snps,tx_de_emphasis_quirk");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index cc4f551..3d94acd 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -818,6 +818,8 @@ struct dwc3_scratchpad_array {
  * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
  * in GUSB2PHYCFG, specify that USB2 PHY doesn't
  * provide a free-running PHY clock.
+ * @dis_del_phy_power_chg_quirk: set if we disable delay phy power
+ * change quirk.
  * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  * @tx_de_emphasis: Tx de-emphasis value
  * 0   - -6dB de-emphasis
@@ -963,6 +965,7 @@ struct dwc3 {
unsigneddis_enblslpm_quirk:1;
unsigneddis_rxdet_inp3_quirk:1;
unsigneddis_u2_freeclk_exists_quirk:1;
+   unsigneddis_del_phy_power_chg_quirk:1;
 
unsignedtx_de_emphasis_quirk:1;
unsignedtx_de_emphasis:2;
-- 
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 v9 0/5] support rockchip dwc3 driver

2016-08-15 Thread William Wu
This series add support for rockchip DWC3 driver,
and add additional optional properties for specific
platforms (e.g., rockchip rk3399 platform).

And because rockchip DWC3 need additional handling of
cable events and mode switch to support DRD mode, so
we add a new dwc3-rockchip driver, but not use the
generic of glue layer which merely enable some clocks
and populate its children.

William Wu (5):
  usb: dwc3: add dis_u2_freeclk_exists_quirk
  usb: dwc3: make usb2 phy utmi interface configurable
  usb: dwc3: add dis_del_phy_power_chg_quirk
  usb: dwc3: rockchip: add devicetree bindings documentation
  usb: dwc3: add rockchip specific glue layer

 Documentation/devicetree/bindings/usb/dwc3.txt |   5 +
 Documentation/devicetree/bindings/usb/generic.txt  |   6 +
 .../devicetree/bindings/usb/rockchip,dwc3.txt  |  71 
 drivers/usb/dwc3/Kconfig   |   9 +
 drivers/usb/dwc3/Makefile  |   1 +
 drivers/usb/dwc3/core.c|  30 +-
 drivers/usb/dwc3/core.h|  21 +
 drivers/usb/dwc3/dwc3-rockchip.c   | 441 +
 8 files changed, 583 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/devicetree/bindings/usb/rockchip,dwc3.txt
 create mode 100644 drivers/usb/dwc3/dwc3-rockchip.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 v9 1/5] usb: dwc3: add dis_u2_freeclk_exists_quirk

2016-08-15 Thread William Wu
Add a quirk to clear the GUSB2PHYCFG.U2_FREECLK_EXISTS bit,
which specifies whether the USB2.0 PHY provides a free-running
PHY clock, which is active when the clock control input is active.

Signed-off-by: William Wu 
Acked-by: Rob Herring 
---
Changes in v9:
- None

Changes in v8:
- add Acked-by (Rob Herring)

Changes in v7:
- None

Changes in v6:
- use '-' instead of '_' in dts (Rob Herring)

Changes in v5:
- None

Changes in v4:
- rebase on top of balbi testing/next, remove pdata (balbi)

Changes in v3:
- None

Changes in v2:
- None

 Documentation/devicetree/bindings/usb/dwc3.txt | 3 +++
 drivers/usb/dwc3/core.c| 5 +
 drivers/usb/dwc3/core.h| 5 +
 3 files changed, 13 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index 7d7ce08..020b0e9 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -39,6 +39,9 @@ Optional properties:
disabling the suspend signal to the PHY.
  - snps,dis_rxdet_inp3_quirk: when set core will disable receiver detection
in PHY P3 power state.
+ - snps,dis-u2-freeclk-exists-quirk: when set, clear the u2_freeclk_exists
+   in GUSB2PHYCFG, specify that USB2 PHY doesn't provide
+   a free-running PHY clock.
  - snps,is-utmi-l1-suspend: true when DWC3 asserts output signal
utmi_l1_suspend_n, false when asserts utmi_sleep_n
  - snps,hird-threshold: HIRD threshold
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 35d0924..14316e5 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -500,6 +500,9 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
if (dwc->dis_enblslpm_quirk)
reg &= ~DWC3_GUSB2PHYCFG_ENBLSLPM;
 
+   if (dwc->dis_u2_freeclk_exists_quirk)
+   reg &= ~DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS;
+
dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
 
return 0;
@@ -924,6 +927,8 @@ static int dwc3_probe(struct platform_device *pdev)
"snps,dis_enblslpm_quirk");
dwc->dis_rxdet_inp3_quirk = device_property_read_bool(dev,
"snps,dis_rxdet_inp3_quirk");
+   dwc->dis_u2_freeclk_exists_quirk = device_property_read_bool(dev,
+   "snps,dis-u2-freeclk-exists-quirk");
 
dwc->tx_de_emphasis_quirk = device_property_read_bool(dev,
"snps,tx_de_emphasis_quirk");
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 1a6cc48..08ed9e0 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -199,6 +199,7 @@
 
 /* Global USB2 PHY Configuration Register */
 #define DWC3_GUSB2PHYCFG_PHYSOFTRST(1 << 31)
+#define DWC3_GUSB2PHYCFG_U2_FREECLK_EXISTS (1 << 30)
 #define DWC3_GUSB2PHYCFG_SUSPHY(1 << 6)
 #define DWC3_GUSB2PHYCFG_ULPI_UTMI (1 << 4)
 #define DWC3_GUSB2PHYCFG_ENBLSLPM  (1 << 8)
@@ -803,6 +804,9 @@ struct dwc3_scratchpad_array {
  * @dis_u2_susphy_quirk: set if we disable usb2 suspend phy
  * @dis_enblslpm_quirk: set if we clear enblslpm in GUSB2PHYCFG,
  *  disabling the suspend signal to the PHY.
+ * @dis_u2_freeclk_exists_quirk : set if we clear u2_freeclk_exists
+ * in GUSB2PHYCFG, specify that USB2 PHY doesn't
+ * provide a free-running PHY clock.
  * @tx_de_emphasis_quirk: set if we enable Tx de-emphasis quirk
  * @tx_de_emphasis: Tx de-emphasis value
  * 0   - -6dB de-emphasis
@@ -946,6 +950,7 @@ struct dwc3 {
unsigneddis_u2_susphy_quirk:1;
unsigneddis_enblslpm_quirk:1;
unsigneddis_rxdet_inp3_quirk:1;
+   unsigneddis_u2_freeclk_exists_quirk:1;
 
unsignedtx_de_emphasis_quirk:1;
unsignedtx_de_emphasis:2;
-- 
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