Re: [PATCH v3 0/9] device connection: Add support for device graphs

2019-02-18 Thread Greg Kroah-Hartman
On Fri, Feb 15, 2019 at 02:47:15PM +0200, Heikki Krogerus wrote:
> Hi Greg,
> 
> On Thu, Feb 14, 2019 at 11:10:44AM +0100, Greg Kroah-Hartman wrote:
> > On Wed, Feb 13, 2019 at 10:45:48AM +0300, Heikki Krogerus wrote:
> > > Hi,
> > > 
> > > This is the third version of my proposal to add device graph parsing
> > > to the device connection API. There was only one problem reported in
> > > v2 by Jun - kernel-doc entry was missing for the new fwnode member in
> > > struct usb_role_switch_desc - and it's now fixed.
> > > 
> > > The second version of the series:
> > > https://lkml.org/lkml/2019/1/30/622
> > > 
> > > The commit message from v1:
> > > 
> > > This series adds support for OF and ACPI device graph parsing to the
> > > device connection API.
> > > 
> > > Handling the graph is straightforward, but because I'm adding that
> > > fwnode member to struct device_connection, I had to make sure all the
> > > existing users consider it.
> > > 
> > > The plan is to only support matching with fwnode in the future, so no
> > > more device name matching. The software fwnodes that we now have in
> > > kernel should make that possible, once we add support for references
> > > to them.
> > > 
> > > The original RFC:
> > > https://lkml.org/lkml/2018/10/24/619
> > 
> > All now merged, thanks.
> 
> It looks like you have not followed the order of the patches in this
> series.
> 
> You applied at least the patch 4/9 ("device connection: Add fwnode
> member to struct device_connection") as the last patch to your
> usb-next branch. The rest of the series, patches starting from 5/9,
> depend on that patch.

Ugh, did I just apply them out of order?  I can't rewrite my tree now,
sorry about that, odd that my sorting didn't work.

I think all of the patches are now in the tree, so I didn't miss
anything, is there anything I can do now?  Want me to revert them and
then add them back in the correct order?

thanks,

greg k-h


Re: [PATCH 2/2] RTL8153-BD is used in Dell DA300 type-C dongle. It should be added to the whitelist of devices to activate MAC address pass through.

2019-02-18 Thread Oliver Neukum
On Mo, 2019-02-18 at 11:48 +0800, David Chen wrote:
> From: David Chen 
> 
> Per confirming with Realtek all devices containing RTL8153-BD should
> activate MAC pass through and there won't use pass through bit on efuse
> like in RTL8153-AD.
> 
> Signed-off-by: David Chen 
> ---
>  drivers/net/usb/r8152.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index ada6baf8847a..86c8c64fbb0f 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -1179,7 +1179,7 @@ static int vendor_mac_passthru_addr_read(struct r8152 
> *tp, struct sockaddr *sa)
>   } else {
>   /* test for RTL8153-BND and RTL8153-BD */
>   ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
> - if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK)) {
> + if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {

You are inverting the second half of the test. How can this possibly be
right? Had you dropped it, I would understand. But this? Are you sure?

Regards
Oliver



Re: [PATCH 2/2] RTL8153-BD is used in Dell DA300 type-C dongle. It should be added to the whitelist of devices to activate MAC address pass through.

2019-02-18 Thread David Chen
Hi Oliver,

Thanks for reviewing.  I have made some mistake, will correct it and resend.

Thanks and Regards,
-David

> Oliver Neukum  於 2019年2月18日 下午4:04 寫道:
> 
>> On Mo, 2019-02-18 at 11:48 +0800, David Chen wrote:
>> From: David Chen 
>> 
>> Per confirming with Realtek all devices containing RTL8153-BD should
>> activate MAC pass through and there won't use pass through bit on efuse
>> like in RTL8153-AD.
>> 
>> Signed-off-by: David Chen 
>> ---
>> drivers/net/usb/r8152.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
>> index ada6baf8847a..86c8c64fbb0f 100644
>> --- a/drivers/net/usb/r8152.c
>> +++ b/drivers/net/usb/r8152.c
>> @@ -1179,7 +1179,7 @@ static int vendor_mac_passthru_addr_read(struct r8152 
>> *tp, struct sockaddr *sa)
>>} else {
>>/* test for RTL8153-BND and RTL8153-BD */
>>ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
>> -if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK)) {
>> +if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {
> 
> You are inverting the second half of the test. How can this possibly be
> right? Had you dropped it, I would understand. But this? Are you sure?
> 
>Regards
>Oliver
> 


Re: [PATCH v3] usb: chipidea: Grab the (legacy) USB PHY by phandle first

2019-02-18 Thread Paul Kocialkowski
Hi,

On Mon, 2019-02-18 at 03:04 +, Peter Chen wrote:
> > According to the chipidea driver bindings, the USB PHY is specified via the 
> > "phys"
> > phandle node. However, this only takes effect for USB PHYs that use the 
> > common
> > PHY framework. For legacy USB PHYs, a simple lookup based on the USB PHY
> > type is done instead.
> > 
> > This does not play out well when more than one USB PHY is registered, since 
> > the
> > first registered PHY matching the type will always be returned regardless 
> > of what
> > the driver was bound to.
> > 
> > Fix this by looking up the PHY based on the "phys" phandle node.
> > Although generic PHYs are rather matched by their "phys-name" and not the 
> > "phys"
> > phandle directly, there is no helper for similar lookup on legacy PHYs and 
> > it's
> > probably not worth the effort to add it.
> > 
> > When no legacy USB PHY is found by phandle, fallback to grabbing any 
> > registered
> > USB2 PHY. This ensures backward compatibility if some users were actually 
> > relying
> > on this mechanism.
> > 
> > Signed-off-by: Paul Kocialkowski 
> > ---
> > Changes since v2:
> > * Fixed typos in commit message.
> > 
> > Changes since v1:
> > * Only consider legacy USB PHY error for fallback as suggested;
> > * Checked against EPROBE_DEFER before entering fallback.
> > 
> >  drivers/usb/chipidea/core.c | 9 -
> >  1 file changed, 8 insertions(+), 1 deletion(-)
> > 
> > diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index
> > 7bfcbb23c2a4..016e4004fe9d 100644
> > --- a/drivers/usb/chipidea/core.c
> > +++ b/drivers/usb/chipidea/core.c
> > @@ -954,8 +954,15 @@ static int ci_hdrc_probe(struct platform_device *pdev)
> > } else if (ci->platdata->usb_phy) {
> > ci->usb_phy = ci->platdata->usb_phy;
> > } else {
> > +   ci->usb_phy = devm_usb_get_phy_by_phandle(dev->parent, "phys",
> > + 0);
> > ci->phy = devm_phy_get(dev->parent, "usb-phy");
> > -   ci->usb_phy = devm_usb_get_phy(dev->parent,
> > USB_PHY_TYPE_USB2);
> > +
> > +   /* Fallback to grabbing any registered USB2 PHY */
> > +   if (IS_ERR(ci->usb_phy) &&
> > +   PTR_ERR(ci->usb_phy) != -EPROBE_DEFER)
> > +   ci->usb_phy = devm_usb_get_phy(dev->parent,
> > +  USB_PHY_TYPE_USB2);
> > 
> 
> I think you may need to do above if ci->phy is error, and not the error is 
> -EPROBE_DEFER.

As Thomas pointed out during the review of v1, the initial flow is to
try and get both ci->usb_phy and ci->phy and let the code use ci->phy
in priority later.

This change attempts to keep this flow intact. The EPROBE_DEFER check
is in case the initial ci->usb_phy is valid but deferred: we don't want
to overwrite it by calling devm_usb_get_phy which might return an
actual error and result in losing the EPROBE_DEFER information.

Does that make sense to you?

Cheers,

Paul

> Peter
> 
> > /* if both generic PHY and USB PHY layers aren't enabled */
> > if (PTR_ERR(ci->phy) == -ENOSYS &&
> > --
> > 2.20.1
-- 
Paul Kocialkowski, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com



Re: [PATCH v3 0/9] device connection: Add support for device graphs

2019-02-18 Thread Heikki Krogerus
On Mon, Feb 18, 2019 at 09:07:27AM +0100, Greg Kroah-Hartman wrote:
> On Fri, Feb 15, 2019 at 02:47:15PM +0200, Heikki Krogerus wrote:
> > Hi Greg,
> > 
> > On Thu, Feb 14, 2019 at 11:10:44AM +0100, Greg Kroah-Hartman wrote:
> > > On Wed, Feb 13, 2019 at 10:45:48AM +0300, Heikki Krogerus wrote:
> > > > Hi,
> > > > 
> > > > This is the third version of my proposal to add device graph parsing
> > > > to the device connection API. There was only one problem reported in
> > > > v2 by Jun - kernel-doc entry was missing for the new fwnode member in
> > > > struct usb_role_switch_desc - and it's now fixed.
> > > > 
> > > > The second version of the series:
> > > > https://lkml.org/lkml/2019/1/30/622
> > > > 
> > > > The commit message from v1:
> > > > 
> > > > This series adds support for OF and ACPI device graph parsing to the
> > > > device connection API.
> > > > 
> > > > Handling the graph is straightforward, but because I'm adding that
> > > > fwnode member to struct device_connection, I had to make sure all the
> > > > existing users consider it.
> > > > 
> > > > The plan is to only support matching with fwnode in the future, so no
> > > > more device name matching. The software fwnodes that we now have in
> > > > kernel should make that possible, once we add support for references
> > > > to them.
> > > > 
> > > > The original RFC:
> > > > https://lkml.org/lkml/2018/10/24/619
> > > 
> > > All now merged, thanks.
> > 
> > It looks like you have not followed the order of the patches in this
> > series.
> > 
> > You applied at least the patch 4/9 ("device connection: Add fwnode
> > member to struct device_connection") as the last patch to your
> > usb-next branch. The rest of the series, patches starting from 5/9,
> > depend on that patch.
> 
> Ugh, did I just apply them out of order?  I can't rewrite my tree now,
> sorry about that, odd that my sorting didn't work.
> 
> I think all of the patches are now in the tree, so I didn't miss
> anything, is there anything I can do now?  Want me to revert them and
> then add them back in the correct order?

The problem is with bisecting, so I'm not sure if reverting helps. I
don't think there's anything else that can be done about this now.


thanks,

-- 
heikki


Re: [PATCH v2] USB: serial: cp210x: Fix GPIO in autosuspend

2019-02-18 Thread Oliver Neukum
On So, 2019-02-17 at 18:59 +0100, Karoly Pados wrote:
> Current GPIO code in cp210x fails to take USB autosuspend into account,
> making it practically impossible to use GPIOs with autosuspend enabled
> without user configuration. Fix this like for ftdi_sio in a previous patch.
> Tested on a CP2102N.

Hi,

your patch is looking good to me, but I am afraid there are issues.
How do the GPIO lines on the device interact with USB reset and system
suspend?

Regards
Oliver



USB 3.0 device next to USB 2.0 receiver result in dysfunctional mouse

2019-02-18 Thread usbuser
Hello,

I build a new pc with the B450-I motherboard from Asus. My issue is the 
following: When I plug-in a USB 3.0 device next to the unifying receiver from 
logitech the mouse stops working. Meaning no movement, clicking or scrolling is 
registered. USB 2.0 devices do not result in a dysfunctional mouse. 
* Everything tested against linux 4.20.10 and 5.0.0-rc6[1].
* I only had sticks and HDDs to test with.
* USB 2.0 sticks can be used if a USB3.0 stick is next to it.
* The BIOS is up to date.
My only lead so far is the section from dmsg[2] about "ACPI Error: Method 
parse/execution failed \_SB.PCI0.GPP2.PTXH.RHUB.POT5._PLD, 
AE_AML_UNINITIALIZED_ELEMENT"

lsusb working mouse / no stick [3] 
lsusb non-working mouse / with stick [4] 
lspci [5] 

I hope I didn't miss any valuable information for you and followed the 
etiquette - what else can I do to fix that / help your helping me? 

Sincerely, 
Roland

[1] https://aur.archlinux.org/packages/linux-mainline/ 
[2] https://ptpb.pw/IjsW 
[3] https://ptpb.pw/0ycO 
[4] https://ptpb.pw/XMix 
[5] https://ptpb.pw/t42v


Re: 4.20.7: pl2303 not working (post-4.19 regression) (limited info so far, not yet bisected)

2019-02-18 Thread Nix
On 18 Feb 2019, Johan Hovold stated:

> On Sun, Feb 17, 2019 at 07:13:52PM +, Nix wrote:
>> I'm still fairly sure this is a regression -- my machines are often up
>> for a lot longer than that and I've never seen this before I upgraded to
>> 4.20.x -- but I don't think I'm going to identify it by mindless
>> bisection. I might have to actually *think* about it.
>
> I doubt it's a regression in usb-serial as essentially nothing changed
> with respect to pl2303 or core since 4.19.

Yeah, I came to that conclusion as well.

> The -ENOSPC you're seeing is returned by the host controller to
> indicate:
>
>   This request would overcommit the usb bandwidth reserved for
>   periodic transfers (interrupt, isochronous).

Side note: probably not related to *this* -ENOSPC, which I've been
seeing for a few releases now and which appears to break Chromium's U2F
negotiation when the USB bus has sufficiently weird devices on it (like,
uh, my wireless mouse):



(I say "probably not related" because it's much older and long predates
the pl2303 trouble.)

> but if you're saying you can reproduce this on "every box" it may not be
> related to any particular host-controller driver (or USB topology).

They are all xhci, at least. The pl2303 is USB 2. One machine, a
two-year-old Broadwell server, says:

xhci_hcd :00:14.0: xHCI Host Controller
xhci_hcd :00:14.0: new USB bus registered, assigned bus number 3
xhci_hcd :00:14.0: hcc params 0x200077c1 hci version 0x100 quirks 
0x9810
xhci_hcd :00:14.0: cache line size of 32 is not supported
hub 3-0:1.0: USB hub found
hub 3-0:1.0: 15 ports detected
xhci_hcd :00:14.0: xHCI Host Controller
xhci_hcd :00:14.0: new USB bus registered, assigned bus number 4
xhci_hcd :00:14.0: Host supports USB 3.0  SuperSpeed

00:14.0 USB controller: Intel Corporation C610/X99 series chipset USB xHCI Host 
Controller (rev 05) (prog-if 30 [XHCI])

The other, a 2012-era cheapish Ivy Bridge workstation:

xhci_hcd :03:00.0: xHCI Host Controller
xhci_hcd :03:00.0: new USB bus registered, assigned bus number 3
xhci_hcd :03:00.0: hcc params 0x014042cb hci version 0x96 quirks 
0x0004
hub 3-0:1.0: USB hub found
hub 3-0:1.0: 2 ports detected
xhci_hcd :03:00.0: xHCI Host Controller
xhci_hcd :03:00.0: new USB bus registered, assigned bus number 4
xhci_hcd :03:00.0: Host supports USB 3.0  SuperSpeed
usb usb4: We don't know the algorithms for LPM for this host, disabling LPM.
hub 4-0:1.0: USB hub found
hub 4-0:1.0: 2 ports detected
xhci_hcd :04:00.0: xHCI Host Controller
xhci_hcd :04:00.0: new USB bus registered, assigned bus number 5
xhci_hcd :04:00.0: hcc params 0x0200f180 hci version 0x96 quirks 
0x0008
hub 5-0:1.0: USB hub found
hub 5-0:1.0: 2 ports detected
xhci_hcd :04:00.0: xHCI Host Controller
xhci_hcd :04:00.0: new USB bus registered, assigned bus number 6
xhci_hcd :04:00.0: Host supports USB 3.0  SuperSpeed
usb usb6: We don't know the algorithms for LPM for this host, disabling LPM.

03:00.0 USB controller: NEC Corporation uPD720200 USB 3.0 Host Controller (rev 
03) (prog-if 30 [XHCI])
04:00.0 USB controller: ASMedia Technology Inc. ASM1042 SuperSpeed USB Host 
Controller (prog-if 30 [XHCI])

(I really don't know which of these is which. I suspect only one
actually has any visible ports on the outside of the case...)

So the quirks are all totally different, and the controllers are quite
different as well...


Re: [PATCH 2/8] dt-bindings: phy: Add Amlogic G12A USB3+PCIE Combo PHY Bindings

2019-02-18 Thread Neil Armstrong
On 17/02/2019 23:03, Martin Blumenstingl wrote:
> On Tue, Feb 12, 2019 at 4:15 PM Neil Armstrong  
> wrote:
>>
>> Add the Amlogic G12A Family USB3 + PCIE Combo PHY Bindings.
>>
>> This PHY can provide exclusively USB3 or PCIE support on shared I/Os.
>>
>> Signed-off-by: Neil Armstrong 
> one nit-pick below, but apart from that:
> Reviewed-by: Martin Blumenstingl 
> 
>> ---
>>  .../bindings/phy/meson-g12a-usb3-pcie-phy.txt | 25 +++
>>  1 file changed, 25 insertions(+)
>>  create mode 100644 
>> Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt
>>
>> diff --git 
>> a/Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt 
>> b/Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt
>> new file mode 100644
>> index ..714d751091f5
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/phy/meson-g12a-usb3-pcie-phy.txt
>> @@ -0,0 +1,25 @@
>> +* Amlogic G12A USB3 + PCIE Combo PHY binding
>> +
>> +Required properties:
>> +- compatible:  Should be "amlogic,meson-g12a-usb3-pcie-phy"
>> +- #phys-cells: must be 1. The cell number is used to select the phy mode
>> +  as defined in  between PHY_TYPE_USB3 and 
>> PHY_TYPE_PCIE
>> +- reg: The base address and length of the registers
>> +- clocks:  a phandle to the 100MHz reference clock of this PHY
>> +- clock-names: must be "ref_clk"
>> +- resets:  phandle to the reset lines for:
>> +   - the PHY control
>> +   - the USB3+PCIE PHY
>> +   - the PHY registers
> no reset-names (like in the G12A USB2 PHY bindings) here?
> even if you don't use them in the driver I suggest you add them for
> consistency (and maybe to make it easier to compare the bindings with
> the datasheet. I don't have access to the datasheet so I'm not sure if
> having the reset-names is relevant for this case)

You're right, it's better to have names here !

Neil

> 
> 
> Regards
> Martin
> 



[PATCH] usb: host: xhci-rcar: Add XHCI_TRUST_TX_LENGTH quirk

2019-02-18 Thread Spyridon Papageorgiou
From: Yasushi Asano 

When plugging BUFFALO LUA4-U3-AGT USB3.0 to Gigabit Ethernet LAN
Adapter, warning messages filled up dmesg.

[  101.098287] xhci-hcd ee00.usb: WARN Successful completion on short TX 
for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH quirk?
[  101.117463] xhci-hcd ee00.usb: WARN Successful completion on short TX 
for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH quirk?
[  101.136513] xhci-hcd ee00.usb: WARN Successful completion on short TX 
for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH quirk?

Adding the XHCI_TRUST_TX_LENGTH quirk resolves the issue.

Signed-off-by: Yasushi Asano 
Signed-off-by: Spyridon Papageorgiou 
---
 drivers/usb/host/xhci-rcar.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index a6e463715779..671bce18782c 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -246,6 +246,7 @@ int xhci_rcar_init_quirk(struct usb_hcd *hcd)
if (!xhci_rcar_wait_for_pll_active(hcd))
return -ETIMEDOUT;
 
+   xhci->quirks |= XHCI_TRUST_TX_LENGTH;
return xhci_rcar_download_firmware(hcd);
 }
 
-- 
2.20.1



Re: [PATCH 5/8] phy: amlogic: add Amlogic G12A USB2 PHY Driver

2019-02-18 Thread Neil Armstrong
Hi Martin,

On 17/02/2019 23:24, Martin Blumenstingl wrote:
> Hi Neil,
> 
> On Tue, Feb 12, 2019 at 4:15 PM Neil Armstrong  
> wrote:
>>
>> This adds support for the USB2 PHY found in the Amlogic G12A SoC Family.
>>
>> It supports Host and/or Peripheral mode, depending on it's position.
>> The first PHY is only used as Host, but the second supports Dual modes
>> defined by the USB Control Glue HW in front of the USB Controllers.
>>
>> Signed-off-by: Neil Armstrong 
>> ---
>>  drivers/phy/amlogic/Kconfig   |  12 ++
>>  drivers/phy/amlogic/Makefile  |   1 +
>>  drivers/phy/amlogic/phy-meson-g12a-usb2.c | 191 ++
>>  3 files changed, 204 insertions(+)
>>  create mode 100644 drivers/phy/amlogic/phy-meson-g12a-usb2.c
>>
>> diff --git a/drivers/phy/amlogic/Kconfig b/drivers/phy/amlogic/Kconfig
>> index 23fe1cda2f70..78d6e194dce9 100644
>> --- a/drivers/phy/amlogic/Kconfig
>> +++ b/drivers/phy/amlogic/Kconfig
>> @@ -36,3 +36,15 @@ config PHY_MESON_GXL_USB3
>>   Enable this to support the Meson USB3 PHY and OTG detection
>>   IP block found in Meson GXL and GXM SoCs.
>>   If unsure, say N.
>> +
>> +config PHY_MESON_G12A_USB2
>> +   tristate "Meson G12A USB2 PHY drivers"
> aw, there's a typo in the GXL driver names (from which this new
> Kconfig entry may have been copied): it should be "driver" instead of
> "drivers"

Will fix...

> 
>> +   default ARCH_MESON
>> +   depends on OF && (ARCH_MESON || COMPILE_TEST)
>> +   depends on USB_SUPPORT
> I don't think you need USB_SUPPORT (neither does PHY_MESON_GXL_USB2,
> but it seems that I accidentally left it in from an early development
> iteration), see below

Indeed, thanks for pointing this

> 
>> +   select GENERIC_PHY
>> +   select REGMAP_MMIO
>> +   help
>> + Enable this to support the Meson USB2 PHYs found in Meson
>> + G12A SoCs.
>> + If unsure, say N.
>> diff --git a/drivers/phy/amlogic/Makefile b/drivers/phy/amlogic/Makefile
>> index 4fd8848c194d..7d4d10f5a6b3 100644
>> --- a/drivers/phy/amlogic/Makefile
>> +++ b/drivers/phy/amlogic/Makefile
>> @@ -1,3 +1,4 @@
>>  obj-$(CONFIG_PHY_MESON8B_USB2) += phy-meson8b-usb2.o
>>  obj-$(CONFIG_PHY_MESON_GXL_USB2)   += phy-meson-gxl-usb2.o
>> +obj-$(CONFIG_PHY_MESON_G12A_USB2)  += phy-meson-g12a-usb2.o
>>  obj-$(CONFIG_PHY_MESON_GXL_USB3)   += phy-meson-gxl-usb3.o
>> diff --git a/drivers/phy/amlogic/phy-meson-g12a-usb2.c 
>> b/drivers/phy/amlogic/phy-meson-g12a-usb2.c
>> new file mode 100644
>> index ..3b6271a8be02
>> --- /dev/null
>> +++ b/drivers/phy/amlogic/phy-meson-g12a-usb2.c
>> @@ -0,0 +1,191 @@
>> +// SPDX-License-Identifier: GPL-2.0
>> +/*
>> + * Meson G12A USB2 PHY driver
>> + *
>> + * Copyright (C) 2017 Martin Blumenstingl 
>> 
>> + * Copyright (C) 2017 Amlogic, Inc. All rights reserved
>> + * Copyright (C) 2019 BayLibre, SAS
>> + * Author: Neil Armstrong 
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
> I don't see any syscon usage in the driver so you can drop this

Forgot to remove it

> 
>> +#include 
>> +#include 
>> +#include 
> do you need this? if you drop "depends on USB_SUPPORT" from Kconfig
> then you want to get rid of this as well

Indeed, no need to this

> 
>> +#include 
>> +
>> +#define PHY_CTRL_R00x0
>> +#define PHY_CTRL_R10x4
>> +#define PHY_CTRL_R20x8
>> +#define PHY_CTRL_R30xc
>> +#define PHY_CTRL_R40x10
>> +#define PHY_CTRL_R50x14
>> +#define PHY_CTRL_R60x18
>> +#define PHY_CTRL_R70x1c
>> +#define PHY_CTRL_R80x20
>> +#define PHY_CTRL_R90x24
>> +#define PHY_CTRL_R10   0x28
>> +#define PHY_CTRL_R11   0x2c
>> +#define PHY_CTRL_R12   0x30
>> +#define PHY_CTRL_R13   0x34
>> +#define PHY_CTRL_R14   0x38
>> +#define PHY_CTRL_R15   0x3c
>> +#define PHY_CTRL_R16   0x40
>> +#define PHY_CTRL_R17   0x44
>> +#define PHY_CTRL_R18   0x48
>> +#define PHY_CTRL_R19   0x4c
>> +#define PHY_CTRL_R20   0x50
>> +#define PHY_CTRL_R21   0x54
>> +#define PHY_CTRL_R22 

[PATCH v2 00/10] Add support for usb on Hikey960

2019-02-18 Thread Yu Chen
The patchset adds support for usb functionality of Hikey960, includes:
- dwc3 driver for Hisilicon Kirin Soc hi3660
- usb driver for HiKey960 board
- some adjustment in dwc3, usb gadget and typec driver
- dts for support usb of HiKey960

---
v2:
* This patchset based on patchset https://lkml.org/lkml/2019/1/25/344
of Heikki Krogerus
---

Yu Chen (10):
  dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY
  dt-bindings: misc: Add bindings for HiSilicon usb hub and data role
switch functionality on HiKey960
  usb: dwc3: dwc3-of-simple: Add support for dwc3 of Hisilicon Soc
Platform
  usb: dwc3: Add two quirks for Hisilicon Kirin Soc Platform
  phy: Add usb phy support for hi3660 Soc of Hisilicon
  usb: roles: Add usb role switch notifier.
  usb: dwc3: Registering a role switch in the DRD code.
  hikey960: Support usb functionality of Hikey960
  usb: gadget: Add configfs attribuite for controling
match_existing_only
  dts: hi3660: Add support for usb on Hikey960

 .../bindings/misc/hisilicon-hikey-usb.txt  |  35 
 .../devicetree/bindings/phy/phy-hi3660-usb3.txt|  21 ++
 MAINTAINERS|   8 +
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts  |  54 +
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi  |  73 +++
 drivers/misc/Kconfig   |   6 +
 drivers/misc/Makefile  |   1 +
 drivers/misc/hisi_hikey_usb.c  | 181 
 drivers/phy/hisilicon/Kconfig  |  10 +
 drivers/phy/hisilicon/Makefile |   1 +
 drivers/phy/hisilicon/phy-hi3660-usb3.c| 232 +
 drivers/usb/dwc3/core.c|  43 
 drivers/usb/dwc3/core.h|   9 +
 drivers/usb/dwc3/drd.c |  45 
 drivers/usb/dwc3/dwc3-of-simple.c  |   4 +-
 drivers/usb/dwc3/gadget.c  |   2 +-
 drivers/usb/gadget/configfs.c  |  32 +++
 drivers/usb/roles/class.c  |  20 +-
 include/linux/usb/role.h   |  46 
 19 files changed, 820 insertions(+), 3 deletions(-)
 create mode 100644 
Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt
 create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
 create mode 100644 drivers/misc/hisi_hikey_usb.c
 create mode 100644 drivers/phy/hisilicon/phy-hi3660-usb3.c

-- 
2.15.0-rc2



[PATCH v2 03/10] usb: dwc3: dwc3-of-simple: Add support for dwc3 of Hisilicon Soc Platform

2019-02-18 Thread Yu Chen
This patch adds support for the poweron and shutdown of dwc3 core
on Hisilicon Soc Platform.
---
 drivers/usb/dwc3/dwc3-of-simple.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/dwc3-of-simple.c 
b/drivers/usb/dwc3/dwc3-of-simple.c
index 4c2771c5e727..0ed09d876542 100644
--- a/drivers/usb/dwc3/dwc3-of-simple.c
+++ b/drivers/usb/dwc3/dwc3-of-simple.c
@@ -98,7 +98,8 @@ static int dwc3_of_simple_probe(struct platform_device *pdev)
 * Some controllers need to toggle the usb3-otg reset before trying to
 * initialize the PHY, otherwise the PHY times out.
 */
-   if (of_device_is_compatible(np, "rockchip,rk3399-dwc3"))
+   if (of_device_is_compatible(np, "rockchip,rk3399-dwc3") ||
+   of_device_is_compatible(np, "hisilicon,hi3660-dwc3"))
simple->need_reset = true;
 
if (of_device_is_compatible(np, "amlogic,meson-axg-dwc3") ||
@@ -243,6 +244,7 @@ static const struct of_device_id of_dwc3_simple_match[] = {
{ .compatible = "amlogic,meson-axg-dwc3" },
{ .compatible = "amlogic,meson-gxl-dwc3" },
{ .compatible = "allwinner,sun50i-h6-dwc3" },
+   { .compatible = "hisilicon,hi3660-dwc3" },
{ /* Sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, of_dwc3_simple_match);
-- 
2.15.0-rc2



[PATCH v2 07/10] usb: dwc3: Registering a role switch in the DRD code.

2019-02-18 Thread Yu Chen
The Type-C drivers use USB role switch API to inform the
system about the negotiated data role, so registering a role
switch in the DRD code in order to support platforms with
USB Type-C connectors.

Cc: John Stultz 
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: Heikki Krogerus 
Suggested-by: Heikki Krogerus 
Signed-off-by: Yu Chen 
---
v2:
* Assign fwnode in dwc3_role_switch.
---
---
 drivers/usb/dwc3/core.h |  2 ++
 drivers/usb/dwc3/drd.c  | 45 +
 2 files changed, 47 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 402b3c29eb26..7385544b9936 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -25,6 +25,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -1083,6 +1084,7 @@ struct dwc3 {
struct extcon_dev   *edev;
struct notifier_block   edev_nb;
enum usb_phy_interface  hsphy_mode;
+   struct usb_role_switch  *role_sw;
 
u32 fladj;
u32 irq_gadget;
diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index 869725d15c74..cf977bb0d62e 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -474,8 +474,42 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
return edev;
 }
 
+static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role)
+{
+   u32 mode;
+
+   switch (role) {
+   case USB_ROLE_HOST:
+   mode = DWC3_GCTL_PRTCAP_HOST;
+   break;
+   case USB_ROLE_DEVICE:
+   mode = DWC3_GCTL_PRTCAP_DEVICE;
+   break;
+   default:
+   mode = DWC3_GCTL_PRTCAP_HOST;
+   break;
+   };
+
+   dwc3_set_mode(dev_get_drvdata(dev), mode);
+   return 0;
+}
+
+static enum usb_role dwc3_usb_role_switch_get(struct device *dev)
+{
+   struct dwc3 *dwc = dev_get_drvdata(dev);
+   unsigned long flags;
+   enum usb_role role;
+
+   spin_lock_irqsave(&dwc->lock, flags);
+   role = dwc->current_otg_role;
+   spin_unlock_irqrestore(&dwc->lock, flags);
+
+   return role;
+}
+
 int dwc3_drd_init(struct dwc3 *dwc)
 {
+   struct usb_role_switch_desc dwc3_role_switch = {0};
int ret, irq;
 
dwc->edev = dwc3_get_extcon(dwc);
@@ -522,6 +556,15 @@ int dwc3_drd_init(struct dwc3 *dwc)
dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
}
 
+   dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
+   dwc3_role_switch.set = dwc3_usb_role_switch_set;
+   dwc3_role_switch.get = dwc3_usb_role_switch_get;
+   dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
+   if (ret) {
+   dwc3_drd_exit(dwc);
+   return PTR_ERR(dwc->role_sw);
+   }
+
return 0;
 }
 
@@ -557,4 +600,6 @@ void dwc3_drd_exit(struct dwc3 *dwc)
 
if (!dwc->edev)
free_irq(dwc->otg_irq, dwc);
+
+   usb_role_switch_unregister(dwc->role_sw);
 }
-- 
2.15.0-rc2



[PATCH v2 05/10] phy: Add usb phy support for hi3660 Soc of Hisilicon

2019-02-18 Thread Yu Chen
This driver handles usb phy power on and shutdown for hi3660 Soc of
Hisilicon.

Cc: Andy Shevchenko 
Cc: Kishon Vijay Abraham I 
Cc: "David S. Miller" 
Cc: Greg Kroah-Hartman 
Cc: Mauro Carvalho Chehab 
Cc: Andrew Morton 
Cc: Arnd Bergmann 
Cc: Shawn Guo 
Cc: Pengcheng Li 
Cc: Jianguo Sun 
Cc: Masahiro Yamada 
Cc: Jiancheng Xue 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v1:
* Remove unused code and add comment for time delay as suggested by
Kishon Vijay Abraham I.
v2:
* Fix license declaration.
* Remove redundant parens.
* Remove unused member variables in struct hi3660_priv.
---
---
 MAINTAINERS |   8 ++
 drivers/phy/hisilicon/Kconfig   |  10 ++
 drivers/phy/hisilicon/Makefile  |   1 +
 drivers/phy/hisilicon/phy-hi3660-usb3.c | 232 
 4 files changed, 251 insertions(+)
 create mode 100644 drivers/phy/hisilicon/phy-hi3660-usb3.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 4d04cebb4a71..8dc289faa2c4 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -15790,6 +15790,14 @@ L: linux-usb@vger.kernel.org
 S: Maintained
 F: drivers/usb/roles/intel-xhci-usb-role-switch.c
 
+USB IP DRIVER FOR HISILICON KIRIN
+M: Yu Chen 
+M: Binghui Wang 
+L: linux-usb@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
+F: drivers/phy/hisilicon/phy-hi3660-usb3.c
+
 USB ISP116X DRIVER
 M: Olav Kongas 
 L: linux-usb@vger.kernel.org
diff --git a/drivers/phy/hisilicon/Kconfig b/drivers/phy/hisilicon/Kconfig
index b40ee54a1a50..3c142f08987c 100644
--- a/drivers/phy/hisilicon/Kconfig
+++ b/drivers/phy/hisilicon/Kconfig
@@ -12,6 +12,16 @@ config PHY_HI6220_USB
 
  To compile this driver as a module, choose M here.
 
+config PHY_HI3660_USB
+   tristate "hi3660 USB PHY support"
+   depends on (ARCH_HISI && ARM64) || COMPILE_TEST
+   select GENERIC_PHY
+   select MFD_SYSCON
+   help
+ Enable this to support the HISILICON HI3660 USB PHY.
+
+ To compile this driver as a module, choose M here.
+
 config PHY_HISTB_COMBPHY
tristate "HiSilicon STB SoCs COMBPHY support"
depends on (ARCH_HISI && ARM64) || COMPILE_TEST
diff --git a/drivers/phy/hisilicon/Makefile b/drivers/phy/hisilicon/Makefile
index f662a4fe18d8..75ba64e2faf8 100644
--- a/drivers/phy/hisilicon/Makefile
+++ b/drivers/phy/hisilicon/Makefile
@@ -1,4 +1,5 @@
 obj-$(CONFIG_PHY_HI6220_USB)   += phy-hi6220-usb.o
+obj-$(CONFIG_PHY_HI3660_USB)   += phy-hi3660-usb3.o
 obj-$(CONFIG_PHY_HISTB_COMBPHY)+= phy-histb-combphy.o
 obj-$(CONFIG_PHY_HISI_INNO_USB2)   += phy-hisi-inno-usb2.o
 obj-$(CONFIG_PHY_HIX5HD2_SATA) += phy-hix5hd2-sata.o
diff --git a/drivers/phy/hisilicon/phy-hi3660-usb3.c 
b/drivers/phy/hisilicon/phy-hi3660-usb3.c
new file mode 100644
index ..97184e6f0d41
--- /dev/null
+++ b/drivers/phy/hisilicon/phy-hi3660-usb3.c
@@ -0,0 +1,232 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Phy provider for USB 3.0 controller on HiSilicon 3660 platform
+ *
+ * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd.
+ * http://www.huawei.com
+ *
+ * Authors: Yu Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define PERI_CRG_CLK_EN4   0x40
+#define PERI_CRG_CLK_DIS4  0x44
+#define GT_CLK_USB3OTG_REF BIT(0)
+#define GT_ACLK_USB3OTGBIT(1)
+
+#define PERI_CRG_RSTEN40x90
+#define PERI_CRG_RSTDIS4   0x94
+#define IP_RST_USB3OTGPHY_POR  BIT(3)
+#define IP_RST_USB3OTG BIT(5)
+
+#define PERI_CRG_ISODIS0x148
+#define USB_REFCLK_ISO_EN  BIT(25)
+
+#define PCTRL_PERI_CTRL3   0x10
+#define PCTRL_PERI_CTRL3_MSK_START 16
+#define USB_TCXO_ENBIT(1)
+
+#define PCTRL_PERI_CTRL24  0x64
+#define SC_CLK_USB3PHY_3MUX1_SEL   BIT(25)
+
+#define USBOTG3_CTRL0  0x00
+#define SC_USB3PHY_ABB_GT_EN   BIT(15)
+
+#define USBOTG3_CTRL2  0x08
+#define USBOTG3CTRL2_POWERDOWN_HSP BIT(0)
+#define USBOTG3CTRL2_POWERDOWN_SSP BIT(1)
+
+#define USBOTG3_CTRL3  0x0C
+#define USBOTG3_CTRL3_VBUSVLDEXT   BIT(6)
+#define USBOTG3_CTRL3_VBUSVLDEXTSELBIT(5)
+
+#define USBOTG3_CTRL4  0x10
+
+#define USBOTG3_CTRL7  0x1c
+#define REF_SSP_EN BIT(16)
+
+#define HI3660_USB_DEFAULT_PHY_PARAM   0x1c466e3
+
+struct hi3660_priv {
+   struct device *dev;
+   struct regmap *peri_crg;
+   struct regmap *pctrl;
+   struct regmap *otg_bc;
+   u32 eye_diagram_param;

[PATCH v2 10/10] dts: hi3660: Add support for usb on Hikey960

2019-02-18 Thread Yu Chen
This patch adds support for usb on Hikey960.

Cc: Wei Xu 
Cc: Rob Herring 
Cc: Mark Rutland 
Cc: linux-arm-ker...@lists.infradead.org
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v2:
* Remove device_type property.
* Add property "usb-role-switch".
---
---
 arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts | 54 +
 arch/arm64/boot/dts/hisilicon/hi3660.dtsi | 73 +++
 2 files changed, 127 insertions(+)

diff --git a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts 
b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
index 46435466f1ab..2cada9d44046 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
+++ b/arch/arm64/boot/dts/hisilicon/hi3660-hikey960.dts
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 
 / {
model = "HiKey960";
@@ -196,6 +197,27 @@
method = "smc";
};
};
+
+   hisi_hikey_usb: hisi_hikey_usb {
+   compatible = "hisilicon,hikey960_usb";
+   typec-vbus-gpios = <&gpio25 2 0>;
+   typec-vbus-enable-val = <1>;
+   otg-switch-gpios = <&gpio25 6 0>;
+   hub-vdd33-en-gpios = <&gpio5 6 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&usbhub5734_pmx_func>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   hikey_usb_ep: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <&dwc3_role_switch_notify>;
+   };
+   };
+   };
+
 };
 
 /*
@@ -526,6 +548,38 @@
 &i2c1 {
status = "okay";
 
+   rt1711h: rt1711h@4e {
+   compatible = "richtek,rt1711h";
+   reg = <0x4e>;
+   status = "ok";
+   interrupt-parent = <&gpio27>;
+   interrupts = <3 IRQ_TYPE_LEVEL_LOW>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb_cfg_func>;
+
+   usb_con: connector {
+   compatible = "usb-c-connector";
+   label = "USB-C";
+   data-role = "dual";
+   power-role = "dual";
+   try-power-role = "sink";
+   source-pdos = ;
+   sink-pdos = ;
+   op-sink-microwatt = <1000>;
+   };
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   rt1711h_ep: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <&dwc3_role_switch>;
+   };
+   };
+   };
+
adv7533: adv7533@39 {
status = "ok";
compatible = "adi,adv7533";
diff --git a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi 
b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
index 20ae40df61d5..a2808c53c538 100644
--- a/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
+++ b/arch/arm64/boot/dts/hisilicon/hi3660.dtsi
@@ -355,6 +355,12 @@
#clock-cells = <1>;
};
 
+   pmctrl: pmctrl@fff31000 {
+   compatible = "hisilicon,hi3660-pmctrl", "syscon";
+   reg = <0x0 0xfff31000 0x0 0x1000>;
+   #clock-cells = <1>;
+   };
+
pmuctrl: crg_ctrl@fff34000 {
compatible = "hisilicon,hi3660-pmuctrl", "syscon";
reg = <0x0 0xfff34000 0x0 0x1000>;
@@ -1134,5 +1140,72 @@
};
};
};
+
+   usb3_otg_bc: usb3_otg_bc@ff20 {
+   compatible = "syscon";
+   reg = <0x0 0xff20 0x0 0x1000>;
+   };
+
+   usb_phy: usb-phy {
+   compatible = "hisilicon,hi3660-usb-phy";
+   #phy-cells = <0>;
+   hisilicon,pericrg-syscon = <&crg_ctrl>;
+   hisilicon,pctrl-syscon = <&pctrl>;
+   hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;
+   hisilicon,eye-diagram-param = <0x22466e4>;
+   };
+
+   usb3: hisi_dwc3 {
+   compatible = "hisilicon,hi3660-dwc3";
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+
+   clocks = <&crg_ctrl HI3660_CLK_ABB_USB>,
+<&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+   clock-names = "clk_usb3phy_ref", "aclk_usb3otg";
+
+   assigned-clocks = <&crg_ctrl HI3660_ACLK_GATE_USB3OTG>;
+   assigned-clock-rates = <22900>;
+   resets = <&crg_rst 0x90 8>,
+  

[PATCH v2 09/10] usb: gadget: Add configfs attribuite for controling match_existing_only

2019-02-18 Thread Yu Chen
Currently the "match_existing_only" of usb_gadget_driver in configfs is
set to one which is not flexible.
Dwc3 udc will be removed when usb core switch to host mode. This causes
failure of writing name of dwc3 udc to configfs's UDC attribuite.
To fix this we need to add a way to change the config of
"match_existing_only".
There are systems like Android do not support udev, so adding
"match_existing_only" attribute to allow configuration by user is cost little.
This patch adds a configfs attribuite for controling match_existing_only
which allow user to config "match_existing_only".

Cc: Andy Shevchenko 
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
 drivers/usb/gadget/configfs.c | 32 
 1 file changed, 32 insertions(+)

diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c
index 025129942894..be85104bfab9 100644
--- a/drivers/usb/gadget/configfs.c
+++ b/drivers/usb/gadget/configfs.c
@@ -291,6 +291,36 @@ static ssize_t gadget_dev_desc_UDC_store(struct 
config_item *item,
return ret;
 }
 
+static ssize_t gadget_driver_match_existing_only_store(struct config_item 
*item,
+   const char *page, size_t len)
+{
+   struct gadget_info *gi = to_gadget_info(item);
+   struct usb_gadget_driver *gadget_driver = 
&(gi->composite.gadget_driver);
+   bool match_existing_only;
+   int ret;
+
+   ret = kstrtobool(page, &match_existing_only);
+   if (ret)
+   return ret;
+
+   if (match_existing_only)
+   gadget_driver->match_existing_only = 1;
+   else
+   gadget_driver->match_existing_only = 0;
+
+   return len;
+}
+
+static ssize_t gadget_driver_match_existing_only_show(struct config_item *item,
+   char *page)
+{
+   struct gadget_info *gi = to_gadget_info(item);
+   struct usb_gadget_driver *gadget_driver = 
&(gi->composite.gadget_driver);
+   bool match_existing_only = !!gadget_driver->match_existing_only;
+
+   return sprintf(page, "%s\n", match_existing_only ? "true" : "false");
+}
+
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceClass);
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceSubClass);
 CONFIGFS_ATTR(gadget_dev_desc_, bDeviceProtocol);
@@ -300,6 +330,7 @@ CONFIGFS_ATTR(gadget_dev_desc_, idProduct);
 CONFIGFS_ATTR(gadget_dev_desc_, bcdDevice);
 CONFIGFS_ATTR(gadget_dev_desc_, bcdUSB);
 CONFIGFS_ATTR(gadget_dev_desc_, UDC);
+CONFIGFS_ATTR(gadget_, driver_match_existing_only);
 
 static struct configfs_attribute *gadget_root_attrs[] = {
&gadget_dev_desc_attr_bDeviceClass,
@@ -311,6 +342,7 @@ static struct configfs_attribute *gadget_root_attrs[] = {
&gadget_dev_desc_attr_bcdDevice,
&gadget_dev_desc_attr_bcdUSB,
&gadget_dev_desc_attr_UDC,
+   &gadget_attr_driver_match_existing_only,
NULL,
 };
 
-- 
2.15.0-rc2



[PATCH v2 06/10] usb: roles: Add usb role switch notifier.

2019-02-18 Thread Yu Chen
This patch adds notifier for drivers want to be informed of the usb role switch.

Cc: Greg Kroah-Hartman 
Cc: Heikki Krogerus 
Cc: Hans de Goede 
Cc: Andy Shevchenko 
Cc: John Stultz 
Suggested-by: Heikki Krogerus 
Signed-off-by: Yu Chen 
---
 drivers/usb/roles/class.c | 20 +++-
 include/linux/usb/role.h  | 46 ++
 2 files changed, 65 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c
index f45d8df5cfb8..e2caaa665d6e 100644
--- a/drivers/usb/roles/class.c
+++ b/drivers/usb/roles/class.c
@@ -20,6 +20,7 @@ struct usb_role_switch {
struct device dev;
struct mutex lock; /* device lock*/
enum usb_role role;
+   struct blocking_notifier_head nh;
 
/* From descriptor */
struct device *usb2_port;
@@ -49,8 +50,10 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, 
enum usb_role role)
mutex_lock(&sw->lock);
 
ret = sw->set(sw->dev.parent, role);
-   if (!ret)
+   if (!ret) {
sw->role = role;
+   blocking_notifier_call_chain(&sw->nh, role, NULL);
+   }
 
mutex_unlock(&sw->lock);
 
@@ -58,6 +61,20 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, 
enum usb_role role)
 }
 EXPORT_SYMBOL_GPL(usb_role_switch_set_role);
 
+int usb_role_switch_register_notifier(struct usb_role_switch *sw,
+ struct notifier_block *nb)
+{
+   return blocking_notifier_chain_register(&sw->nh, nb);
+}
+EXPORT_SYMBOL_GPL(usb_role_switch_register_notifier);
+
+int usb_role_switch_unregister_notifier(struct usb_role_switch *sw,
+   struct notifier_block *nb)
+{
+   return blocking_notifier_chain_unregister(&sw->nh, nb);
+}
+EXPORT_SYMBOL_GPL(usb_role_switch_unregister_notifier);
+
 /**
  * usb_role_switch_get_role - Get the USB role for a switch
  * @sw: USB role switch
@@ -271,6 +288,7 @@ usb_role_switch_register(struct device *parent,
return ERR_PTR(-ENOMEM);
 
mutex_init(&sw->lock);
+   BLOCKING_INIT_NOTIFIER_HEAD(&sw->nh);
 
sw->allow_userspace_control = desc->allow_userspace_control;
sw->usb2_port = desc->usb2_port;
diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h
index 9684a8734757..9e1ca663387a 100644
--- a/include/linux/usb/role.h
+++ b/include/linux/usb/role.h
@@ -41,6 +41,8 @@ struct usb_role_switch_desc {
bool allow_userspace_control;
 };
 
+
+#if IS_ENABLED(CONFIG_USB_ROLE_SWITCH)
 int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role);
 enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw);
 struct usb_role_switch *usb_role_switch_get(struct device *dev);
@@ -50,5 +52,49 @@ struct usb_role_switch *
 usb_role_switch_register(struct device *parent,
 const struct usb_role_switch_desc *desc);
 void usb_role_switch_unregister(struct usb_role_switch *sw);
+int usb_role_switch_register_notifier(struct usb_role_switch *sw,
+ struct notifier_block *nb);
+int usb_role_switch_unregister_notifier(struct usb_role_switch *sw,
+   struct notifier_block *nb);
+#else
+static inline int usb_role_switch_set_role(struct usb_role_switch *sw,
+   enum usb_role role)
+{
+   return 0;
+}
+
+static inline enum usb_role usb_role_switch_get_role(struct usb_role_switch 
*sw)
+{
+   return USB_ROLE_NONE;
+}
+
+static inline struct usb_role_switch *usb_role_switch_get(struct device *dev)
+{
+   return ERR_PTR(-ENODEV);
+}
+
+static inline void usb_role_switch_put(struct usb_role_switch *sw) { }
+
+static inline struct usb_role_switch *
+usb_role_switch_register(struct device *parent,
+const struct usb_role_switch_desc *desc)
+{
+   return ERR_PTR(-ENODEV);
+}
+
+static inline void usb_role_switch_unregister(struct usb_role_switch *sw) { }
+
+static int usb_role_switch_register_notifier(struct usb_role_switch *sw,
+ struct notifier_block *nb)
+{
+   return -ENODEV;
+}
+
+static int usb_role_switch_unregister_notifier(struct usb_role_switch *sw,
+   struct notifier_block *nb)
+{
+   return -ENODEV;
+}
+#endif
 
 #endif /* __LINUX_USB_ROLE_H */
-- 
2.15.0-rc2



[PATCH v2 04/10] usb: dwc3: Add two quirks for Hisilicon Kirin Soc Platform

2019-02-18 Thread Yu Chen
There are tow quirks for DesignWare USB3 DRD Core of Hisilicon Kirin Soc.
1)SPLIT_BOUNDARY_DISABLE should be set for Host mode
2)A GCTL soft reset should be executed when switch mode

Cc: Andy Shevchenko 
Cc: Felipe Balbi 
Cc: Greg Kroah-Hartman 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v2:
* Fix data type of reg from int to u32.
---
---
 drivers/usb/dwc3/core.c   | 43 +++
 drivers/usb/dwc3/core.h   |  7 +++
 drivers/usb/dwc3/gadget.c |  2 +-
 3 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a1b126f90261..017b0527f6ab 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -112,11 +112,25 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
dwc->current_dr_role = mode;
 }
 
+static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc)
+{
+   u32 reg;
+
+   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+   reg |= (DWC3_GCTL_CORESOFTRESET);
+   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+
+   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
+   reg &= ~(DWC3_GCTL_CORESOFTRESET);
+   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
+}
+
 static void __dwc3_set_mode(struct work_struct *work)
 {
struct dwc3 *dwc = work_to_dwc(work);
unsigned long flags;
int ret;
+   u32 reg;
 
if (dwc->dr_mode != USB_DR_MODE_OTG)
return;
@@ -156,6 +170,10 @@ static void __dwc3_set_mode(struct work_struct *work)
 
dwc3_set_prtcap(dwc, dwc->desired_dr_role);
 
+   /* Execute a GCTL Core Soft Reset when switch mode */
+   if (dwc->gctl_reset_quirk)
+   dwc3_gctl_core_soft_reset(dwc);
+
spin_unlock_irqrestore(&dwc->lock, flags);
 
switch (dwc->desired_dr_role) {
@@ -169,6 +187,11 @@ static void __dwc3_set_mode(struct work_struct *work)
phy_set_mode(dwc->usb2_generic_phy, PHY_MODE_USB_HOST);
phy_set_mode(dwc->usb3_generic_phy, PHY_MODE_USB_HOST);
phy_calibrate(dwc->usb2_generic_phy);
+   if (dwc->dis_split_quirk) {
+   reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
+   reg |= DWC3_GUCTL3_SPLITDISABLE;
+   dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
+   }
}
break;
case DWC3_GCTL_PRTCAP_DEVICE:
@@ -1306,6 +1329,11 @@ static void dwc3_get_properties(struct dwc3 *dwc)
dwc->dis_metastability_quirk = device_property_read_bool(dev,
"snps,dis_metastability_quirk");
 
+   dwc->dis_split_quirk = device_property_read_bool(dev,
+   "snps,dis-split-quirk");
+   dwc->gctl_reset_quirk = device_property_read_bool(dev,
+   "snps,gctl-reset-quirk");
+
dwc->lpm_nyet_threshold = lpm_nyet_threshold;
dwc->tx_de_emphasis = tx_de_emphasis;
 
@@ -1825,10 +1853,25 @@ static int dwc3_resume(struct device *dev)
 
return 0;
 }
+
+static void dwc3_complete(struct device *dev)
+{
+   struct dwc3 *dwc = dev_get_drvdata(dev);
+   u32 reg;
+
+   if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
+   dwc->dis_split_quirk) {
+   dev_dbg(dwc->dev, "set DWC3_GUCTL3_SPLITDISABLE\n");
+   reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
+   reg |= DWC3_GUCTL3_SPLITDISABLE;
+   dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
+   }
+}
 #endif /* CONFIG_PM_SLEEP */
 
 static const struct dev_pm_ops dwc3_dev_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(dwc3_suspend, dwc3_resume)
+   .complete = dwc3_complete,
SET_RUNTIME_PM_OPS(dwc3_runtime_suspend, dwc3_runtime_resume,
dwc3_runtime_idle)
 };
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index df876418cb78..402b3c29eb26 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -136,6 +136,7 @@
 #define DWC3_GEVNTCOUNT(n) (0xc40c + ((n) * 0x10))
 
 #define DWC3_GHWPARAMS80xc600
+#define DWC3_GUCTL30xc60c
 #define DWC3_GFLADJ0xc630
 
 /* Device Registers */
@@ -370,6 +371,9 @@
 /* Global User Control Register 2 */
 #define DWC3_GUCTL2_RST_ACTBITLATERBIT(14)
 
+/* Global User Control Register 3 */
+#define DWC3_GUCTL3_SPLITDISABLE   BIT(14)
+
 /* Device Configuration Register */
 #define DWC3_DCFG_DEVADDR(addr)((addr) << 3)
 #define DWC3_DCFG_DEVADDR_MASK DWC3_DCFG_DEVADDR(0x7f)
@@ -1210,6 +1214,9 @@ struct dwc3 {
 
unsigneddis_metastability_quirk:1;
 
+   unsigneddis_split_quirk:1;
+   unsignedgctl_reset_quirk:1;
+
u16 imod_interval;
 };
 
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 07bd31bb

[PATCH v2 01/10] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-02-18 Thread Yu Chen
This patch adds binding documentation for supporting the hi3660 usb
phy on boards like the HiKey960.

Cc: Rob Herring 
Cc: Mark Rutland 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v1:
* Fix some format error as suggested by Rob.
v2:
* Change hi3660 usb PHY to hi3660 USB PHY
---
---
 .../devicetree/bindings/phy/phy-hi3660-usb3.txt | 21 +
 1 file changed, 21 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt

diff --git a/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt 
b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
new file mode 100644
index ..f9a3d56cfdd2
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
@@ -0,0 +1,21 @@
+Hisilicon hi3660 USB PHY
+---
+
+Required properties:
+- compatible: should be "hisilicon,hi3660-usb-phy"
+- #phy-cells: must be 0
+- hisilicon,pericrg-syscon: phandle of syscon used to control phy.
+- hisilicon,pctrl-syscon: phandle of syscon used to control phy.
+- hisilicon,usb3-otg-bc-syscon: phandle of syscon used to control phy.
+- hisilicon,eye-diagram-param: parameter set for phy
+Refer to phy/phy-bindings.txt for the generic PHY binding properties
+
+Example:
+   usb-phy {
+   compatible = "hisilicon,hi3660-usb-phy";
+   #phy-cells = <0>;
+   hisilicon,pericrg-syscon = <&crg_ctrl>;
+   hisilicon,pctrl-syscon = <&pctrl>;
+   hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;
+   hisilicon,eye-diagram-param = <0x22466e4>;
+   };
-- 
2.15.0-rc2



[PATCH v2 08/10] hikey960: Support usb functionality of Hikey960

2019-02-18 Thread Yu Chen
This driver handles usb hub power on and typeC port event of HiKey960 board:
1)DP&DM switching between usb hub and typeC port base on typeC port
state
2)Control power of usb hub on Hikey960
3)Control vbus of typeC port

Cc: Andy Shevchenko 
Cc: Arnd Bergmann 
Cc: Greg Kroah-Hartman 
Cc: John Stultz 
Cc: Binghui Wang 
Cc: Heikki Krogerus 
Signed-off-by: Yu Chen 

---
v1:
* Using gpiod API with the gpios.
* Removing registering usb role switch.
* Registering usb role switch notifier.
v2:
* Fix license declaration.
* Add configuration of  gpio direction.
* Remove some log print.
---
---
 drivers/misc/Kconfig  |   6 ++
 drivers/misc/Makefile |   1 +
 drivers/misc/hisi_hikey_usb.c | 181 ++
 3 files changed, 188 insertions(+)
 create mode 100644 drivers/misc/hisi_hikey_usb.c

diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index f417b06e11c5..8d8b717759e2 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -521,6 +521,12 @@ config PVPANIC
  a paravirtualized device provided by QEMU; it lets a virtual machine
  (guest) communicate panic events to the host.
 
+config HISI_HIKEY_USB
+   tristate "USB functionality of HiSilicon Hikey Platform"
+   depends on OF && GPIOLIB
+   help
+ If you say yes here you get support for usb functionality of 
HiSilicon Hikey Platform.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index e39ccbbc1b3a..dc8892b13a1a 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -59,3 +59,4 @@ obj-$(CONFIG_PCI_ENDPOINT_TEST)   += pci_endpoint_test.o
 obj-$(CONFIG_OCXL) += ocxl/
 obj-y  += cardreader/
 obj-$(CONFIG_PVPANIC)  += pvpanic.o
+obj-$(CONFIG_HISI_HIKEY_USB)   += hisi_hikey_usb.o
diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c
new file mode 100644
index ..70013f8e76f0
--- /dev/null
+++ b/drivers/misc/hisi_hikey_usb.c
@@ -0,0 +1,181 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Support for usb functionality of Hikey series boards
+ * based on Hisilicon Kirin Soc.
+ *
+ * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd.
+ * http://www.huawei.com
+ *
+ * Authors: Yu Chen 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define DEVICE_DRIVER_NAME "hisi_hikey_usb"
+
+#define HUB_VBUS_POWER_ON 1
+#define HUB_VBUS_POWER_OFF 0
+#define USB_SWITCH_TO_HUB 1
+#define USB_SWITCH_TO_TYPEC 0
+
+struct hisi_hikey_usb {
+   struct gpio_desc *otg_switch;
+   struct gpio_desc *typec_vbus;
+   struct gpio_desc *hub_vbus;
+   int typec_vbus_enable_val;
+
+   struct usb_role_switch *role_sw;
+   struct notifier_block nb;
+};
+
+static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value)
+{
+   gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value);
+}
+
+static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
+   int switch_to)
+{
+   gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to);
+}
+
+static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
+   int value)
+{
+   gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value);
+}
+
+static int hisi_hikey_role_switch(struct notifier_block *nb,
+   unsigned long state, void *data)
+{
+   struct hisi_hikey_usb *hisi_hikey_usb;
+
+   hisi_hikey_usb = container_of(nb, struct hisi_hikey_usb, nb);
+
+   switch (state) {
+   case USB_ROLE_NONE:
+   usb_typec_power_ctrl(hisi_hikey_usb,
+   !hisi_hikey_usb->typec_vbus_enable_val);
+   usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB);
+   hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON);
+   break;
+   case USB_ROLE_HOST:
+   usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
+   usb_typec_power_ctrl(hisi_hikey_usb,
+   hisi_hikey_usb->typec_vbus_enable_val);
+   break;
+   case USB_ROLE_DEVICE:
+   hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF);
+   usb_typec_power_ctrl(hisi_hikey_usb,
+   !hisi_hikey_usb->typec_vbus_enable_val);
+   usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
+   break;
+   default:
+   break;
+   }
+
+   return 0;
+}
+
+static int hisi_hikey_usb_probe(struct platform_device *pdev)
+{
+   struct device *dev = &pdev->dev;
+   struct device_node *root = dev->of_node;
+   struct hisi_hikey_usb *hisi_hikey_usb;
+   int ret;
+
+   hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL);
+   if (!hisi_hikey_usb)
+   return -ENOMEM;
+
+

[PATCH v2 02/10] dt-bindings: misc: Add bindings for HiSilicon usb hub and data role switch functionality on HiKey960

2019-02-18 Thread Yu Chen
This patch adds binding documentation to support usb hub and usb
data role switch of Hisilicon HiKey960 Board.

Cc: Sergei Shtylyov 
Cc: Rob Herring 
Cc: Mark Rutland 
Cc: John Stultz 
Cc: Binghui Wang 
Signed-off-by: Yu Chen 
---
v1:
* Fix some format errors as suggested by Sergei.
* Modify gpio description to use gpiod API.
v2:
* Remove information about Hikey.
* Fix gpio description.
* Remove device_type of endpoint.
---
---
 .../bindings/misc/hisilicon-hikey-usb.txt  | 35 ++
 1 file changed, 35 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt

diff --git a/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt 
b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt
new file mode 100644
index ..c2b789b515df
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/hisilicon-hikey-usb.txt
@@ -0,0 +1,35 @@
+Support usb hub and usb data role switch of Hisilicon HiKey960 Board.
+
+-
+
+Required properties:
+- compatible: "hisilicon,gpio-hubv1","hisilicon,hikey960-usb"
+- typec-vbus-gpios: gpio to control the vbus of typeC port
+- typec-vbus-enable-val: gpio value that enable the vbus of typeC port
+- otg-switch-gpios: gpio to switch DP & DM between the hub and typeC port
+- hub-vdd33-en-gpios: gpio to enable the power of hub
+- pinctrl-0: pinctrl config
+
+Example
+-
+
+   hisi_hikey_usb: hisi_hikey_usb {
+   compatible = "hisilicon,hikey960-usb";
+   typec-vbus-gpios = <&gpio25 2 0>;
+   typec-vbus-enable-val = <1>;
+   otg-switch-gpios = <&gpio25 6 0>;
+   hub-vdd33-en-gpios = <&gpio5 6 0>;
+   pinctrl-names = "default";
+   pinctrl-0 = <&usbhub5734_pmx_func>;
+
+   port {
+   #address-cells = <1>;
+   #size-cells = <0>;
+
+   hikey_usb_ep: endpoint@0 {
+   reg = <0>;
+   remote-endpoint = <&dwc3_role_switch_notify>;
+   };
+   };
+
+   };
-- 
2.15.0-rc2



Re: [PATCH v2 04/10] usb: dwc3: Add two quirks for Hisilicon Kirin Soc Platform

2019-02-18 Thread Andy Shevchenko
On Mon, Feb 18, 2019 at 1:23 PM Yu Chen  wrote:
>
> There are tow quirks for DesignWare USB3 DRD Core of Hisilicon Kirin Soc.
> 1)SPLIT_BOUNDARY_DISABLE should be set for Host mode
> 2)A GCTL soft reset should be executed when switch mode

Thus, it must be two patches, no?

> +static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc)
> +{
> +   u32 reg;
> +
> +   reg = dwc3_readl(dwc->regs, DWC3_GCTL);

> +   reg |= (DWC3_GCTL_CORESOFTRESET);

Redundant parens.

> +   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> +
> +   reg = dwc3_readl(dwc->regs, DWC3_GCTL);

> +   reg &= ~(DWC3_GCTL_CORESOFTRESET);

Ditto.

> +   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> +}

> +static void dwc3_complete(struct device *dev)
> +{

> +   struct dwc3 *dwc = dev_get_drvdata(dev);
> +   u32 reg;

Indentation style is different to the other functions in the same patch.
Use simple space here.

> +   if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
> +   dwc->dis_split_quirk) {
> +   dev_dbg(dwc->dev, "set DWC3_GUCTL3_SPLITDISABLE\n");
> +   reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
> +   reg |= DWC3_GUCTL3_SPLITDISABLE;
> +   dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
> +   }
> +}

> --- a/drivers/usb/dwc3/gadget.c
> +++ b/drivers/usb/dwc3/gadget.c
> @@ -269,7 +269,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, unsigned 
> cmd,
>  {
> const struct usb_endpoint_descriptor *desc = dep->endpoint.desc;
> struct dwc3 *dwc = dep->dwc;

> -   u32 timeout = 1000;
> +   u32 timeout = 5000;

I don't see anything about this change in commit message. Moreoever,
it looks like it must be a separate logical change with its own
description.

> u32 saved_config = 0;
> u32 reg;


-- 
With Best Regards,
Andy Shevchenko


Re: [RESEND PATCH] dt-bindings: arm: atmel: add new sam9x60 SFR binding

2019-02-18 Thread Nicolas.Ferre
On 06/02/2019 at 19:04, Nicolas Ferre wrote:
> Add this SFR compatible definition for the sam9x60 SoC. Will be needed
> in OHCI driver: ohci-at91.c.
> 
> Signed-off-by: Nicolas Ferre 
> ---
> Hi Rob,
> It seems that this patch was lost in my series "[PATCH 0/8] ARM: at91/dt:
> update to existing drivers for the sam9x60 SoC". I split it and resend it only
> for USB tree.

Rob,

Ping...


> Hi Greg,
> 
> This DT bindind goes with the patch already queued in your usb-next tree "USB:
> host: ohci-at91: add sam9x60-sfr definition for ohci".
> 
> Once Rob added his tag, can you please queue it in your tree as I reviewed my
> first idea of adding it to the arm-soc tree?
> 
> Best regards,
>Nicolas
> 
>   Documentation/devicetree/bindings/arm/atmel-sysregs.txt | 1 +
>   1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/arm/atmel-sysregs.txt 
> b/Documentation/devicetree/bindings/arm/atmel-sysregs.txt
> index badce6ef3ab3..dfc91bc02b97 100644
> --- a/Documentation/devicetree/bindings/arm/atmel-sysregs.txt
> +++ b/Documentation/devicetree/bindings/arm/atmel-sysregs.txt
> @@ -148,6 +148,7 @@ required properties:
>   - compatible: Should be "atmel,-sfr", "syscon" or
>   "atmel,-sfrbu", "syscon"
>  can be "sama5d3", "sama5d4" or "sama5d2".
> +  It also can be "microchip,sam9x60-sfr", "syscon".
>   - reg: Should contain registers location and length
>   
>   sfr@f0038000 {
> 


-- 
Nicolas Ferre


Re: [PATCH v2 04/10] usb: dwc3: Add two quirks for Hisilicon Kirin Soc Platform

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/18 20:21, Andy Shevchenko wrote:
> On Mon, Feb 18, 2019 at 1:23 PM Yu Chen  wrote:
>>
>> There are tow quirks for DesignWare USB3 DRD Core of Hisilicon Kirin Soc.
>> 1)SPLIT_BOUNDARY_DISABLE should be set for Host mode
>> 2)A GCTL soft reset should be executed when switch mode
> 
> Thus, it must be two patches, no?
> 
>> +static void dwc3_gctl_core_soft_reset(struct dwc3 *dwc)
>> +{
>> +   u32 reg;
>> +
>> +   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
> 
>> +   reg |= (DWC3_GCTL_CORESOFTRESET);
> 
> Redundant parens.
> 
>> +   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>> +
>> +   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
> 
>> +   reg &= ~(DWC3_GCTL_CORESOFTRESET);
> 
> Ditto.
> 
>> +   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
>> +}
> 
>> +static void dwc3_complete(struct device *dev)
>> +{
> 
>> +   struct dwc3 *dwc = dev_get_drvdata(dev);
>> +   u32 reg;
> 
> Indentation style is different to the other functions in the same patch.
> Use simple space here.
> 
>> +   if (dwc->current_dr_role == DWC3_GCTL_PRTCAP_HOST &&
>> +   dwc->dis_split_quirk) {
>> +   dev_dbg(dwc->dev, "set DWC3_GUCTL3_SPLITDISABLE\n");
>> +   reg = dwc3_readl(dwc->regs, DWC3_GUCTL3);
>> +   reg |= DWC3_GUCTL3_SPLITDISABLE;
>> +   dwc3_writel(dwc->regs, DWC3_GUCTL3, reg);
>> +   }
>> +}
> 
>> --- a/drivers/usb/dwc3/gadget.c
>> +++ b/drivers/usb/dwc3/gadget.c
>> @@ -269,7 +269,7 @@ int dwc3_send_gadget_ep_cmd(struct dwc3_ep *dep, 
>> unsigned cmd,
>>  {
>> const struct usb_endpoint_descriptor *desc = dep->endpoint.desc;
>> struct dwc3 *dwc = dep->dwc;
> 
>> -   u32 timeout = 1000;
>> +   u32 timeout = 5000;
> 
> I don't see anything about this change in commit message. Moreoever,
> it looks like it must be a separate logical change with its own
> description.
> 
>> u32 saved_config = 0;
>> u32 reg;
> 
> 

I will separate these changes into different patches. Thanks!



[PATCH v1] usb: dwc3: drd: Defer probe if extcon device is not found

2019-02-18 Thread Andy Shevchenko
In case the "linux,extcon-name" property is defined but device itself
is not ready, defer the probe.

Cc: Felipe Balbi 
Signed-off-by: Andy Shevchenko 
---

This is a missed part of the v2 [1] of the commit 268784ba14a7

("usb: dwc3: drd: Add support for DR detection through extcon")

which seems to be v1 mistakenly applied.

Greg, it would be good to have this appended to v5.0 release,
if it's not too late.

[1]: https://patchwork.kernel.org/patch/10684311/

 drivers/usb/dwc3/drd.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index 869725d15c74..726100d1ac0d 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -457,8 +457,13 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 *dwc)
 * This device property is for kernel internal use only and
 * is expected to be set by the glue code.
 */
-   if (device_property_read_string(dev, "linux,extcon-name", &name) == 0)
-   return extcon_get_extcon_dev(name);
+   if (device_property_read_string(dev, "linux,extcon-name", &name) == 0) {
+   edev = extcon_get_extcon_dev(name);
+   if (!edev)
+   return ERR_PTR(-EPROBE_DEFER);
+
+   return edev;
+   }
 
np_phy = of_parse_phandle(dev->of_node, "phys", 0);
np_conn = of_graph_get_remote_node(np_phy, -1, -1);
-- 
2.20.1



Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Stanislaw Gruszka
On Sat, Feb 16, 2019 at 08:17:07PM +0100, Stefan Wahren wrote:
> this is a misunderstanding. The warning is about memory alignment to 32 bit 
> addresses, not about page alignment. This is a typical ARM restriction. Maybe 
> we need to make sure in mt76 that the DMA buffer needs to be aligned. But 
> it's also possible that the warning isn't the root cause of our problem.
> 

I see, it needs 4 bytes alignment . There is already dwc2 code checks
that and allocate new buffer if the alignment is not right:
dwc2_alloc_dma_aligned_buffer(), but it does nothing if urb->sg
is not NULL. I thought mt76usb already provide aligned buffers, but
looks it does not for one TX special case, which are PROBE REQUEST
frames. Other frames are aligned by inserting L2 header pad. One
solution for this would be just submit urb with  NULL sg (same as
Lorenzo's patches do, but still allocating buffers via buf->sg),
but I think, you have right, we should provide 4 bytes aligned buffers
by default as other DMA hardware may require that. I'm attaching yet
another patch to test, which fix up alignment for PROBE REQUEST frames.

> > Attached patch should fix this, plese test, thanks in advance.
> 
> Anyway i tested the following patch combinations against next with the same 
> results as 1,2,3 (no wifi, alignment warning):
> 1,3
> 1,2,3,4

I noticed on my setup that patch 4 can cause troubles, but still
device is workable here on my PC machines.

> > > Btw i can confirm a regression was introduced after 4.19, because in 4.19 
> > > there was no firmware timeout but even no working wifi:
> > 
> > You ment 'no working wifi' or 'working wifi'?
> 
> Wifi is broken in 4.19, 4.20, 5.0 and next. It only worked with Lorenzo's SG 
> avoid patches so far. Btw the regression (firmware timeout) started in 4.20. 
> I also tested it today.

That somewhat strange because 4.19 mt76x0u does not use SG.
On 4.19 there is phy calibration bug fixed in 4.19.5:

commit 0d9813319b40399a0d8fd761d2fcfedee5701487
Author: Lorenzo Bianconi 
Date:   Fri Sep 7 23:13:12 2018 +0200

mt76x0: run vco calibration for each channel configuration

It's possible that without this vco calibration fix, MT7610U device
does not see AP if it's signal is weak.

Stanislaw

>From d420961afd1ae2ca8590ee2c79defc0a48fa8e73 Mon Sep 17 00:00:00 2001
From: Stanislaw Gruszka 
Date: Mon, 18 Feb 2019 14:39:38 +0100
Subject: [PATCH] mt76x02: make sure probe request skb's are 4 bytes aligned

We add 2 bytes header pad if header length is not multiple of 4 bytes,
this assure most tx skb buffers are 4 bytes aligned. But this is not
true for probe request frames which have n*4 bytes header length and
are not aligned.

I think is ok to assume that frames have to be 4 bytes aligned
for DMA purpose, so mt76 driver should take care of that.

Signed-off-by: Stanislaw Gruszka 
---
 drivers/net/wireless/mediatek/mt76/mt76x02.h   |  2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c  |  5 +---
 .../net/wireless/mediatek/mt76/mt76x02_usb_core.c  |  2 +-
 drivers/net/wireless/mediatek/mt76/mt76x02_util.c  | 32 +++---
 4 files changed, 25 insertions(+), 16 deletions(-)

diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02.h 
b/drivers/net/wireless/mediatek/mt76/mt76x02.h
index 6d96766a6ed3..ad329db7de4e 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02.h
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02.h
@@ -155,7 +155,7 @@ void mt76x02_set_tx_ackto(struct mt76x02_dev *dev);
 void mt76x02_set_coverage_class(struct ieee80211_hw *hw,
s16 coverage_class);
 int mt76x02_set_rts_threshold(struct ieee80211_hw *hw, u32 val);
-int mt76x02_insert_hdr_pad(struct sk_buff *skb);
+void mt76x02_align_skb(struct sk_buff *skb);
 void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len);
 bool mt76x02_tx_status_data(struct mt76_dev *mdev, u8 *update);
 void mt76x02_queue_rx_skb(struct mt76_dev *mdev, enum mt76_rxq_id q,
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c 
b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
index a5413a309a0a..63c5520a65ca 100644
--- a/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
+++ b/drivers/net/wireless/mediatek/mt76/mt76x02_txrx.c
@@ -163,7 +163,6 @@ int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void 
*txwi_ptr,
struct mt76x02_txwi *txwi = txwi_ptr;
int qsel = MT_QSEL_EDCA;
int pid;
-   int ret;
 
if (q == &dev->mt76.q_tx[MT_TXQ_PSD] && wcid && wcid->idx < 128)
mt76x02_mac_wcid_set_drop(dev, wcid->idx, false);
@@ -173,9 +172,7 @@ int mt76x02_tx_prepare_skb(struct mt76_dev *mdev, void 
*txwi_ptr,
pid = mt76_tx_status_skb_add(mdev, wcid, skb);
txwi->pktid = pid;
 
-   ret = mt76x02_insert_hdr_pad(skb);
-   if (ret < 0)
-   return ret;
+   mt76x02_align_skb(skb);
 
if (pid >= MT_PACKET_ID_FIRST)
qsel = MT_QSEL_MGMT;
diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_usb_core.c 
b/driv

Re: [PATCH 4/5] usb: typec: ucsi: Preliminary support for alternate modes

2019-02-18 Thread Heikki Krogerus
Hi,

On Sat, Feb 16, 2019 at 01:36:05AM +, Michael Hsu wrote:
> > I think for clarity's sake I better fix the mode index issue now and send 
> > second
> > version of these patches so we can concentrate on the bigger problem, the 
> > two
> > connector DP alt modes.
> > 
> 
> Agreed.  Please update your patch for the mode index issue (being able to
> reliably match partner mode index with the connector mode index returned by
> UCSI).

I'll finish some other task before coming back to this. We shouldn't
be in any hurry with this. These are not going to v5.1 in any case.

> > > Here's a method of avoiding the above dilemma:
> > > - create partner sysfs alt mode nodes using UCSI GET_ALT_MODES (with
> > > recipient == connector)
> > > - also query UCSI GET_SUPPORTED_CAM
> > > - create partner sysfs alt modes only if GET_SUPPORT_CAM returns 1 bit
> > > for a particular connector alt mode index
> > 
> > No! We must not hide stuff like that from the user. Even if the connector 
> > does
> > not support a partner mode, we still show it to the user space.
> > 
> 
> OK, but this means the "active" sysfs node for a partner mode (which is not
> supported by GET_SUPPORTED_CAM) will always show "no".  And writing "yes"
> to it will silently fail...

They will not always say "no", but you can not change the value
without an alternate mode driver.

> Did this intentional?  Having some partner sysfs "active" nodes which do
> nothing without any warning to user that they don't work?

The key here is the driver. The user will know that partner alternate
mode can't be operated unless it has been bind to a driver. The ABI
for the alternate modes is defined for the typec bus, not the class.

So in real world the user space applications will not start doing
anything with an alternate mode, other than possible notifying the
user of its existence, until the user space sees kernel event
indicating that the alternate mode has been bind to a driver.


Br,

-- 
heikki


[PATCH] [V2]r8152: Add support for MAC address pass through on RTL8153-BD

2019-02-18 Thread David Chen
From: David Chen 

RTL8153-BD is used in Dell DA300 type-C dongle.
It should be added to the whitelist of devices to activate MAC address
pass through.

Per confirming with Realtek all devices containing RTL8153-BD should
activate MAC pass through and there won't use pass through bit on efuse
like in RTL8153-AD.

Signed-off-by: David Chen 
---
 drivers/net/usb/r8152.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
index 60dd1ec1665f..86c8c64fbb0f 100644
--- a/drivers/net/usb/r8152.c
+++ b/drivers/net/usb/r8152.c
@@ -557,6 +557,7 @@ enum spd_duplex {
 /* MAC PASSTHRU */
 #define AD_MASK0xfee0
 #define BND_MASK   0x0004
+#define BD_MASK0x0001
 #define EFUSE  0xcfdb
 #define PASS_THRU_MASK 0x1
 
@@ -1176,9 +1177,9 @@ static int vendor_mac_passthru_addr_read(struct r8152 
*tp, struct sockaddr *sa)
return -ENODEV;
}
} else {
-   /* test for RTL8153-BND */
+   /* test for RTL8153-BND and RTL8153-BD */
ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
-   if ((ocp_data & BND_MASK) == 0) {
+   if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {
netif_dbg(tp, probe, tp->netdev,
  "Invalid variant for MAC pass through\n");
return -ENODEV;
-- 
2.19.1



Re: [PATCH] [V2]r8152: Add support for MAC address pass through on RTL8153-BD

2019-02-18 Thread Jiri Slaby
On 18. 02. 19, 15:00, David Chen wrote:
> From: David Chen 
> 
> RTL8153-BD is used in Dell DA300 type-C dongle.
> It should be added to the whitelist of devices to activate MAC address
> pass through.
> 
> Per confirming with Realtek all devices containing RTL8153-BD should
> activate MAC pass through and there won't use pass through bit on efuse
> like in RTL8153-AD.
> 
> Signed-off-by: David Chen 
> ---
>  drivers/net/usb/r8152.c | 5 +++--
>  1 file changed, 3 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
> index 60dd1ec1665f..86c8c64fbb0f 100644
> --- a/drivers/net/usb/r8152.c
> +++ b/drivers/net/usb/r8152.c
> @@ -557,6 +557,7 @@ enum spd_duplex {
>  /* MAC PASSTHRU */
>  #define AD_MASK  0xfee0
>  #define BND_MASK 0x0004
> +#define BD_MASK  0x0001
>  #define EFUSE0xcfdb
>  #define PASS_THRU_MASK   0x1
>  
> @@ -1176,9 +1177,9 @@ static int vendor_mac_passthru_addr_read(struct r8152 
> *tp, struct sockaddr *sa)
>   return -ENODEV;
>   }
>   } else {
> - /* test for RTL8153-BND */
> + /* test for RTL8153-BND and RTL8153-BD */
>   ocp_data = ocp_read_byte(tp, MCU_TYPE_USB, USB_MISC_1);
> - if ((ocp_data & BND_MASK) == 0) {
> + if ((ocp_data & BND_MASK) == 0 && (ocp_data & BD_MASK) == 0) {

Can you ensure that BND won't have the BD's bit set and vice versa? I.e.
should the check be something like:
  if (isBND() && (ocp_data & BND_MASK) == 0 ||
  isBD() && (ocp_data & BD_MASK) == 0)
instead?

thanks,
-- 
js
suse labs


Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Lorenzo Bianconi
> commit 0d9813319b40399a0d8fd761d2fcfedee5701487
> Author: Lorenzo Bianconi 
> Date:   Fri Sep 7 23:13:12 2018 +0200

[...]

> diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
> b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> index 062614ad0d51..08425b1d2c30 100644
> --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> @@ -550,21 +550,33 @@ void mt76x02_sta_rate_tbl_update(struct ieee80211_hw 
> *hw,
>  }
>  EXPORT_SYMBOL_GPL(mt76x02_sta_rate_tbl_update);
>  
> -int mt76x02_insert_hdr_pad(struct sk_buff *skb)
> +void mt76x02_align_skb(struct sk_buff *skb)
>  {
> - int len = ieee80211_get_hdrlen_from_skb(skb);
> + int align = ((unsigned long) skb->data) & 3;
> + int hdrlen, skblen;
>  
> - if (len % 4 == 0)
> - return 0;
> + hdrlen = ieee80211_get_hdrlen_from_skb(skb);
> + WARN_ON_ONCE(align == 0 && (hdrlen & 3));
> +
> + if (align == 0)
> + return;

Hi Stanislaw,

is it possible that skb->data is 4 byte aligned but hdrlen is not? (e.g 4addr
data frames, not qos)?

>  
> - skb_push(skb, 2);
> - memmove(skb->data, skb->data + 2, len);
> + if (hdrlen & 3) {
> + /* Align frame and add 2 bytes pad after header. */
> + skb_push(skb, 2);
> + memmove(skb->data, skb->data + 2, hdrlen);
>  
> - skb->data[len] = 0;
> - skb->data[len + 1] = 0;
> - return 2;
> + skb->data[hdrlen] = 0;
> + skb->data[hdrlen + 1] = 0;
> + } else {
> + /* Only for probe request frames. */

are you sure this is true *only* for probe requests?
this could hit performances and it is used even in pci code

Regards,
Lorenzo

> + skblen = skb->len;
> + skb_push(skb, 2);
> + memmove(skb->data, skb->data + 2, skblen);
> + skb_trim(skb, skblen);
> + }
>  }
> -EXPORT_SYMBOL_GPL(mt76x02_insert_hdr_pad);
> +EXPORT_SYMBOL_GPL(mt76x02_align_skb);
>  
>  void mt76x02_remove_hdr_pad(struct sk_buff *skb, int len)
>  {
> -- 
> 2.7.5
> 



[PATCH -next] cdc-wdm: pass return value of recover_from_urb_loss

2019-02-18 Thread YueHaibing
'rv' is the correct return value, pass it upstream instead of 0

Fixes: 17d80d562fd7 ("USB: autosuspend for cdc-wdm")
Signed-off-by: YueHaibing 
---
 drivers/usb/class/cdc-wdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index bec581f..9e9caff 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -1099,7 +1099,7 @@ static int wdm_post_reset(struct usb_interface *intf)
rv = recover_from_urb_loss(desc);
mutex_unlock(&desc->wlock);
mutex_unlock(&desc->rlock);
-   return 0;
+   return rv;
 }
 
 static struct usb_driver wdm_driver = {
-- 
2.7.0




Re: [usb:usb-testing 63/64] drivers/usb/typec/mux.c:167 typec_mux_match() warn: unsigned 'nval' is never less than zero.

2019-02-18 Thread Heikki Krogerus
On Fri, Feb 15, 2019 at 07:51:56PM +0200, Andy Shevchenko wrote:
> On Fri, Feb 15, 2019 at 4:40 PM Heikki Krogerus
>  wrote:
> >
> > On Fri, Feb 15, 2019 at 11:19:47AM +0200, Andy Shevchenko wrote:
> > > On Fri, Feb 15, 2019 at 11:01 AM Heikki Krogerus
> > >  wrote:
> > > >
> > > > On Fri, Feb 15, 2019 at 01:33:24PM +0800, kbuild test robot wrote:
> > > > > tree:   
> > > > > https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
> > > > > usb-testing
> > > > > head:   09aa11cfda9d8186046bcd1adcd6498b688114f4
> > > > > commit: 96a6d031ca9930938bd66d0052fc7ed2b56e3583 [63/64] usb: typec: 
> > > > > mux: Find the muxes by also matching against the device node
> > > > >
> > > > > smatch warnings:
> > > > > drivers/usb/typec/mux.c:167 typec_mux_match() warn: unsigned 'nval' 
> > > > > is never less than zero.
> > > >
> > > > I'm assuming this means we should not use type 'size_t' in this case.
> > > >
> > > > I'll send a patch where I'll use 'int' instead if 'size_t'.
> > >
> > > Perhaps, in case of < 0 it should return it as error pointer to the 
> > > caller?
> >
> > It already does that.
> 
> Not in a line 159/160 AFAICS.

It get's tricky. We would then have to at least check that the error
value is not -ENODATA or -EINVAL, in those cases we should still
return NULL, but we can of course do that... Actually, now that I
think about it, we should return NULL also in case of -ENXIO. Even
that means we ignore the case.

I don't see a possible error path where we should return the error to
the caller when checking the number of elements.

> > > > > vim +/nval +167 drivers/usb/typec/mux.c
> > > > >
> > > > >124
> > > > >125static void *typec_mux_match(struct device_connection 
> > > > > *con, int ep, void *data)
> > > > >126{
> > > > >127const struct typec_altmode_desc *desc = data;
> > > > >128struct typec_mux *mux;
> > > > >129size_t nval;
> > > > >130bool match;
> > > > >131u16 *val;
> > > > >132int i;
> > > > >133
> > > > >134if (!con->fwnode) {
> > > > >135list_for_each_entry(mux, &mux_list, 
> > > > > entry)
> > > > >136if (!strcmp(con->endpoint[ep], 
> > > > > dev_name(mux->dev)))
> > > > >137return mux;
> > > > >138return ERR_PTR(-EPROBE_DEFER);
> > > > >139}
> > > > >140
> > > > >141/*
> > > > >142 * Check has the identifier already been 
> > > > > "consumed". If it
> > > > >143 * has, no need to do any extra connection 
> > > > > identification.
> > > > >144 */
> > > > >145match = !con->id;
> > > > >146if (match)
> > > > >147goto find_mux;
> > > > >148
> > > > >149/* Accessory Mode muxes */
> > > > >150if (!desc) {
> > > > >151match = 
> > > > > fwnode_property_present(con->fwnode, "accessory");
> > > > >152if (match)
> > > > >153goto find_mux;
> > > > >154return NULL;
> > > > >155}
> > > > >156
> > > > >157/* Alternate Mode muxes */
> > > > >158nval = 
> > > > > fwnode_property_read_u16_array(con->fwnode, "svid", NULL, 0);
> > > > >159if (nval <= 0)
> > > > >160return NULL;
> > > > >161
> > > > >162val = kcalloc(nval, sizeof(*val), GFP_KERNEL);
> > > > >163if (!val)
> > > > >164return ERR_PTR(-ENOMEM);
> > > > >165
> > > > >166nval = 
> > > > > fwnode_property_read_u16_array(con->fwnode, "svid", val, nval);
> > > > >  > 167if (nval < 0) {
> > > > >168kfree(val);
> > > > >169return ERR_PTR(nval);
> > > > >170}
> > > > >171
> > > > >172for (i = 0; i < nval; i++) {
> > > > >173match = val[i] == desc->svid;
> > > > >174if (match) {
> > > > >175kfree(val);
> > > > >176goto find_mux;
> > > > >177}
> > > > >178}
> > > > >179kfree(val);
> > > > >180return NULL;
> > > > >181
> > > > >182find_mux:
> > > > >183list_for_each_entry(mux, &mux_list, entry)
> > > > >184if (dev_fwnode(mux->dev) == con->fwnode)
> > > > >185return mux;
> > > > >186

Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Felix Fietkau
On 2019-02-18 14:52, Stanislaw Gruszka wrote:
> On Sat, Feb 16, 2019 at 08:17:07PM +0100, Stefan Wahren wrote:
>> this is a misunderstanding. The warning is about memory alignment to 32 bit 
>> addresses, not about page alignment. This is a typical ARM restriction. 
>> Maybe we need to make sure in mt76 that the DMA buffer needs to be aligned. 
>> But it's also possible that the warning isn't the root cause of our problem.
>> 
> 
> I see, it needs 4 bytes alignment . There is already dwc2 code checks
> that and allocate new buffer if the alignment is not right:
> dwc2_alloc_dma_aligned_buffer(), but it does nothing if urb->sg
> is not NULL. I thought mt76usb already provide aligned buffers, but
> looks it does not for one TX special case, which are PROBE REQUEST
> frames. Other frames are aligned by inserting L2 header pad. One
> solution for this would be just submit urb with  NULL sg (same as
> Lorenzo's patches do, but still allocating buffers via buf->sg),
> but I think, you have right, we should provide 4 bytes aligned buffers
> by default as other DMA hardware may require that. I'm attaching yet
> another patch to test, which fix up alignment for PROBE REQUEST frames.
This approach looks completely wrong to me. MMIO based hardware does not
need 4-byte aligned buffers at all, other USB controllers do not need
this either.
As Lorenzo already pointed out, re-aligning the buffer is *very*
expensive, so we should not do this in the driver just to work around
quirks in a particular USB host driver.
And I really don't think we can assume that this code path is going to
be hit for probe requests only.

The way I see it, we have two choices.
1. Fix dwc2 to do its alignment quirk for the urb->sg != NULL case
2. Rely on urb->transfer_buffer and keep urb->sg NULL

- Felix



Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Stanislaw Gruszka
On Mon, Feb 18, 2019 at 03:25:28PM +0100, Lorenzo Bianconi wrote:
> > commit 0d9813319b40399a0d8fd761d2fcfedee5701487
> > Author: Lorenzo Bianconi 
> > Date:   Fri Sep 7 23:13:12 2018 +0200
> 
> [...]
> 
> > diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c 
> > b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> > index 062614ad0d51..08425b1d2c30 100644
> > --- a/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> > +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_util.c
> > @@ -550,21 +550,33 @@ void mt76x02_sta_rate_tbl_update(struct ieee80211_hw 
> > *hw,
> >  }
> >  EXPORT_SYMBOL_GPL(mt76x02_sta_rate_tbl_update);
> >  
> > -int mt76x02_insert_hdr_pad(struct sk_buff *skb)
> > +void mt76x02_align_skb(struct sk_buff *skb)
> >  {
> > -   int len = ieee80211_get_hdrlen_from_skb(skb);
> > +   int align = ((unsigned long) skb->data) & 3;
> > +   int hdrlen, skblen;
> >  
> > -   if (len % 4 == 0)
> > -   return 0;
> > +   hdrlen = ieee80211_get_hdrlen_from_skb(skb);
> > +   WARN_ON_ONCE(align == 0 && (hdrlen & 3));
> > +
> > +   if (align == 0)
> > +   return;
> 
> Hi Stanislaw,
> 
> is it possible that skb->data is 4 byte aligned but hdrlen is not? (e.g 4addr
> data frames, not qos)?

It might be possible, so for now I add this 

WARN_ON_ONCE(align == 0 && (hdrlen & 3));

and plan to do some investigation on frame aliment.

> are you sure this is true *only* for probe requests?
> this could hit performances and it is used even in pci code

I'm not 100% sure, but I haven't seen any other frames with
that. All other unaligned frames I've seen in my tests had
unaligned header and adding header pad aligned them.
But obviously I've haven't tested all possible scenarios.

Stanislaw


Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Stanislaw Gruszka
On Mon, Feb 18, 2019 at 03:43:26PM +0100, Felix Fietkau wrote:
> On 2019-02-18 14:52, Stanislaw Gruszka wrote:
> > On Sat, Feb 16, 2019 at 08:17:07PM +0100, Stefan Wahren wrote:
> >> this is a misunderstanding. The warning is about memory alignment to 32 
> >> bit addresses, not about page alignment. This is a typical ARM 
> >> restriction. Maybe we need to make sure in mt76 that the DMA buffer needs 
> >> to be aligned. But it's also possible that the warning isn't the root 
> >> cause of our problem.
> >> 
> > 
> > I see, it needs 4 bytes alignment . There is already dwc2 code checks
> > that and allocate new buffer if the alignment is not right:
> > dwc2_alloc_dma_aligned_buffer(), but it does nothing if urb->sg
> > is not NULL. I thought mt76usb already provide aligned buffers, but
> > looks it does not for one TX special case, which are PROBE REQUEST
> > frames. Other frames are aligned by inserting L2 header pad. One
> > solution for this would be just submit urb with  NULL sg (same as
> > Lorenzo's patches do, but still allocating buffers via buf->sg),
> > but I think, you have right, we should provide 4 bytes aligned buffers
> > by default as other DMA hardware may require that. I'm attaching yet
> > another patch to test, which fix up alignment for PROBE REQUEST frames.
> This approach looks completely wrong to me. MMIO based hardware does not
> need 4-byte aligned buffers at all, other USB controllers do not need
> this either.
> As Lorenzo already pointed out, re-aligning the buffer is *very*
> expensive, so we should not do this in the driver just to work around
> quirks in a particular USB host driver.

I decided to this patch because I thought some other USB & MMIO DMA
platforms might also require this alignment. But it was never triggered
in MMIO because on those mt76 is used in AP mode, hence no PROBE
REQUEST frames (and scan can be passive on STA mode).

> The way I see it, we have two choices.
> 1. Fix dwc2 to do its alignment quirk for the urb->sg != NULL case
> 2. Rely on urb->transfer_buffer and keep urb->sg NULL

I agree, if this is only needed for dwc2. Though I would investigate
if this is not a bug on other platforms as well.

Stanislaw


Re: [PATCH v4 1/6] dt-bindings: add binding for USBSS-DRD controller.

2019-02-18 Thread Rob Herring
On Thu, 14 Feb 2019 19:45:09 +, Pawel Laszczak wrote:
> This patch aim at documenting USB related dt-bindings for the
> Cadence USBSS-DRD controller.
> 
> Signed-off-by: Pawel Laszczak 
> ---
>  .../devicetree/bindings/usb/cdns-usb3.txt | 30 +++
>  1 file changed, 30 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/usb/cdns-usb3.txt
> 

Reviewed-by: Rob Herring 


[PATCH v2] usb: musb: Fix urb->hcpriv value

2019-02-18 Thread Matwey V. Kornilov
urb->hcpriv != NULL is used to indicate that the URB is queued [1].
Also see __usb_hcd_giveback_urb() and usb_hcd_submit_urb() for
the reference.

In this code path, the URB is actually queued and valid qh is hep->hcpriv.

[1] https://lkml.org/lkml/2019/1/25/750

Fixes: 714bc5ef3eda ("musb: potential use after free")
Signed-off-by: Matwey V. Kornilov 
---
 drivers/usb/musb/musb_host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index b59ce9ad14ce..a60d52c7e112 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -2302,7 +2302,7 @@ static int musb_urb_enqueue(
 * odd, rare, error prone, but legal.
 */
kfree(qh);
-   qh = NULL;
+   qh = hep->hcpriv;
ret = 0;
} else
ret = musb_schedule(musb, qh,
-- 
2.16.4



Re: [PATCH v2 00/10] Add support for usb on Hikey960

2019-02-18 Thread Valentin Schneider
Hi,

On 18/02/2019 11:23, Yu Chen wrote:
> The patchset adds support for usb functionality of Hikey960, includes:
> - dwc3 driver for Hisilicon Kirin Soc hi3660
> - usb driver for HiKey960 board
> - some adjustment in dwc3, usb gadget and typec driver
> - dts for support usb of HiKey960
> 

I want to try this out on my HiKey960, but I can't get the USB A ports
working (tried USB stick and USB eth adapter).

On top of the arm64 defconfig, I've enabled (with menuconfig):

CONFIG_PHY_HI3660_USB
CONFIG_HISI_HIKEY_USB

Am I missing something? FYI up until now I've carried over Fan Ning's old
USB patch-set and that works fine, so I think it might just be a
configuration error from my end.

Thanks,
Valentin




Re: [PATCH v2 07/10] usb: dwc3: Registering a role switch in the DRD code.

2019-02-18 Thread Valentin Schneider
Hi,

On 18/02/2019 11:23, Yu Chen wrote:
[...]
> @@ -522,6 +556,15 @@ int dwc3_drd_init(struct dwc3 *dwc)
>   dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
>   }
>  
> + dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
> + dwc3_role_switch.set = dwc3_usb_role_switch_set;
> + dwc3_role_switch.get = dwc3_usb_role_switch_get;
> + dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);

Building arm64 defconfig gives me this:

drivers/usb/dwc3/drd.o: In function `dwc3_drd_exit':
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604: undefined reference to 
`usb_role_switch_unregister'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604:(.text+0x814): relocation 
truncated to fit: R_AARCH64_CALL26 against undefined symbol 
`usb_role_switch_unregister'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604: undefined reference to 
`usb_role_switch_unregister'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604:(.text+0x844): relocation 
truncated to fit: R_AARCH64_CALL26 against undefined symbol 
`usb_role_switch_unregister'
drivers/usb/dwc3/drd.o: In function `dwc3_drd_init':
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562: undefined reference to 
`usb_role_switch_register'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562:(.text+0xa20): relocation 
truncated to fit: R_AARCH64_CALL26 against undefined symbol 
`usb_role_switch_register'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562: undefined reference to 
`usb_role_switch_register'
/home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562:(.text+0xb4c): relocation 
truncated to fit: R_AARCH64_CALL26 against undefined symbol 
`usb_role_switch_register'
Makefile:1024: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

This has CONFIG_USB_ROLE_SWITCH=m, setting it as a built-in makes the thing
linkable.

I suppose that's because defconfig gives us

  CONFIG_USB_DWC3_DUAL_ROLE=y

but then that should probably force a CONFIG_USB_ROLE_SWITCH=y. My
immediate reaction to this would be to add:

---
diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 2b1494460d0c..661b1d2efc8b 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -44,6 +44,7 @@ config USB_DWC3_DUAL_ROLE
bool "Dual Role mode"
depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || 
USB_GADGET=USB_DWC3))
depends on (EXTCON=y || EXTCON=USB_DWC3)
+   select USB_ROLE_SWITCH
help
  This is the default mode of working of DWC3 controller where
  both host and gadget features are enabled.
---
  
Not sure how acceptable that is though.


> + if (ret) {
> + dwc3_drd_exit(dwc);
> + return PTR_ERR(dwc->role_sw);
> + }
> +
>   return 0;
>  }
>  
> @@ -557,4 +600,6 @@ void dwc3_drd_exit(struct dwc3 *dwc)
>  
>   if (!dwc->edev)
>   free_irq(dwc->otg_irq, dwc);
> +
> + usb_role_switch_unregister(dwc->role_sw);
>  }
> 


Re: [RFC PATCH 0/2] Fix for the internal card reader and suspend on MacBooks

2019-02-18 Thread Eric Blau
On Wed, Feb 13, 2019 at 1:14 PM Ivan Mironov  wrote:
>
> First patch adds code for this new quirk, and second patch enables this
> quirk for card reader device which is used in my macbook.

Hi Ivan,

Thanks for sending these patches along. I've applied them against
4.20.8 and they fix the suspend/resume issues I've hit since November
in the -stable series. On resume, I see logs indicating that the stuck
card reader on usb2-3 on my MacBook Pro is being reset. It shows up
fine afterwards.

Thanks,
Eric


Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Felix Fietkau
On 2019-02-18 16:03, Stanislaw Gruszka wrote:
> On Mon, Feb 18, 2019 at 03:43:26PM +0100, Felix Fietkau wrote:
>> On 2019-02-18 14:52, Stanislaw Gruszka wrote:
>> > On Sat, Feb 16, 2019 at 08:17:07PM +0100, Stefan Wahren wrote:
>> >> this is a misunderstanding. The warning is about memory alignment to 32 
>> >> bit addresses, not about page alignment. This is a typical ARM 
>> >> restriction. Maybe we need to make sure in mt76 that the DMA buffer needs 
>> >> to be aligned. But it's also possible that the warning isn't the root 
>> >> cause of our problem.
>> >> 
>> > 
>> > I see, it needs 4 bytes alignment . There is already dwc2 code checks
>> > that and allocate new buffer if the alignment is not right:
>> > dwc2_alloc_dma_aligned_buffer(), but it does nothing if urb->sg
>> > is not NULL. I thought mt76usb already provide aligned buffers, but
>> > looks it does not for one TX special case, which are PROBE REQUEST
>> > frames. Other frames are aligned by inserting L2 header pad. One
>> > solution for this would be just submit urb with  NULL sg (same as
>> > Lorenzo's patches do, but still allocating buffers via buf->sg),
>> > but I think, you have right, we should provide 4 bytes aligned buffers
>> > by default as other DMA hardware may require that. I'm attaching yet
>> > another patch to test, which fix up alignment for PROBE REQUEST frames.
>> This approach looks completely wrong to me. MMIO based hardware does not
>> need 4-byte aligned buffers at all, other USB controllers do not need
>> this either.
>> As Lorenzo already pointed out, re-aligning the buffer is *very*
>> expensive, so we should not do this in the driver just to work around
>> quirks in a particular USB host driver.
> 
> I decided to this patch because I thought some other USB & MMIO DMA
> platforms might also require this alignment. But it was never triggered
> in MMIO because on those mt76 is used in AP mode, hence no PROBE
> REQUEST frames (and scan can be passive on STA mode).
mt76 is regularly used and tested in STA and Mesh mode as well.
No DMA alignment related issues there.

>> The way I see it, we have two choices.
>> 1. Fix dwc2 to do its alignment quirk for the urb->sg != NULL case
>> 2. Rely on urb->transfer_buffer and keep urb->sg NULL
> 
> I agree, if this is only needed for dwc2. Though I would investigate
> if this is not a bug on other platforms as well.
>From what I can see, using Lorenzo's patches seems to be the better
solution, since they avoid these corner cases in dwc2 (and maybe other
drivers as well). I will apply them and then we'll see if we need to do
any further improvements later on.

- Felix


[PATCH] usb: dwc2: use struct_size() in kzalloc()

2019-02-18 Thread Gustavo A. R. Silva
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
int stuff;
struct boo entry[];
};

size = sizeof(struct foo) + count * sizeof(struct boo);
instance = kzalloc(size, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

Notice that, in this case, variable size is not necessary, hence
it is removed.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/usb/dwc2/hcd.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index dd82fa516f3f..3f087962f498 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -3981,10 +3981,8 @@ static struct dwc2_hcd_urb *dwc2_hcd_urb_alloc(struct 
dwc2_hsotg *hsotg,
   gfp_t mem_flags)
 {
struct dwc2_hcd_urb *urb;
-   u32 size = sizeof(*urb) + iso_desc_count *
-  sizeof(struct dwc2_hcd_iso_packet_desc);
 
-   urb = kzalloc(size, mem_flags);
+   urb = kzalloc(struct_size(urb, iso_descs, iso_desc_count), mem_flags);
if (urb)
urb->packet_count = iso_desc_count;
return urb;
-- 
2.20.1



[PATCH 09/14] media: usb: fix several typos

2019-02-18 Thread Mauro Carvalho Chehab
Use codespell to fix lots of typos over frontends.

Manually verified to avoid false-positives.

Signed-off-by: Mauro Carvalho Chehab 
---
 drivers/media/usb/au0828/au0828-core.c|  2 +-
 drivers/media/usb/au0828/au0828.h |  2 +-
 drivers/media/usb/cx231xx/cx231xx-avcore.c|  2 +-
 drivers/media/usb/cx231xx/cx231xx-pcb-cfg.h   |  2 +-
 drivers/media/usb/cx231xx/cx231xx.h   |  2 +-
 drivers/media/usb/dvb-usb-v2/dvb_usb.h|  2 +-
 drivers/media/usb/dvb-usb-v2/lmedm04.c|  8 
 drivers/media/usb/dvb-usb-v2/mxl111sf.c   |  4 ++--
 drivers/media/usb/dvb-usb/af9005.c|  2 +-
 drivers/media/usb/dvb-usb/cinergyT2-fe.c  |  2 +-
 drivers/media/usb/dvb-usb/cxusb.c |  2 +-
 drivers/media/usb/dvb-usb/dvb-usb-init.c  |  2 +-
 drivers/media/usb/dvb-usb/dvb-usb.h   |  2 +-
 drivers/media/usb/dvb-usb/pctv452e.c  |  4 ++--
 drivers/media/usb/em28xx/em28xx-i2c.c |  4 ++--
 drivers/media/usb/em28xx/em28xx-reg.h |  2 +-
 drivers/media/usb/gspca/Kconfig   |  2 +-
 drivers/media/usb/gspca/autogain_functions.c  |  2 +-
 drivers/media/usb/gspca/benq.c|  4 ++--
 drivers/media/usb/gspca/mr97310a.c| 10 +-
 drivers/media/usb/gspca/ov519.c   |  4 ++--
 drivers/media/usb/gspca/pac_common.h  |  2 +-
 drivers/media/usb/gspca/sn9c20x.c |  2 +-
 drivers/media/usb/gspca/sonixb.c  |  4 ++--
 drivers/media/usb/gspca/sonixj.c  |  2 +-
 drivers/media/usb/gspca/spca501.c |  2 +-
 drivers/media/usb/gspca/sq905.c   |  2 +-
 drivers/media/usb/gspca/sunplus.c |  4 ++--
 drivers/media/usb/gspca/t613.c|  2 +-
 drivers/media/usb/gspca/touptek.c |  4 ++--
 drivers/media/usb/gspca/w996Xcf.c |  2 +-
 drivers/media/usb/gspca/zc3xx-reg.h   |  2 +-
 drivers/media/usb/gspca/zc3xx.c   |  8 
 drivers/media/usb/hdpvr/hdpvr.h   |  2 +-
 drivers/media/usb/pwc/pwc-dec23.c |  4 ++--
 drivers/media/usb/pwc/pwc-if.c|  2 +-
 drivers/media/usb/pwc/pwc-misc.c  |  2 +-
 drivers/media/usb/siano/smsusb.c  |  2 +-
 drivers/media/usb/stk1160/stk1160-core.c  |  4 ++--
 drivers/media/usb/stk1160/stk1160-reg.h   |  4 ++--
 drivers/media/usb/stkwebcam/stk-webcam.c  |  2 +-
 drivers/media/usb/tm6000/tm6000-alsa.c|  2 +-
 drivers/media/usb/tm6000/tm6000-core.c|  4 ++--
 drivers/media/usb/tm6000/tm6000-dvb.c |  2 +-
 drivers/media/usb/tm6000/tm6000-i2c.c |  2 +-
 drivers/media/usb/tm6000/tm6000-stds.c|  2 +-
 drivers/media/usb/tm6000/tm6000-video.c   |  2 +-
 drivers/media/usb/ttusb-budget/dvb-ttusb-budget.c |  2 +-
 drivers/media/usb/ttusb-dec/ttusb_dec.c   |  2 +-
 drivers/media/usb/usbvision/usbvision-core.c  |  8 
 drivers/media/usb/usbvision/usbvision.h   |  8 
 drivers/media/usb/uvc/uvc_video.c |  2 +-
 drivers/media/usb/zr364xx/zr364xx.c   |  2 +-
 53 files changed, 81 insertions(+), 81 deletions(-)

diff --git a/drivers/media/usb/au0828/au0828-core.c 
b/drivers/media/usb/au0828/au0828-core.c
index 1fdb1601dc65..3f8c92a70116 100644
--- a/drivers/media/usb/au0828/au0828-core.c
+++ b/drivers/media/usb/au0828/au0828-core.c
@@ -234,7 +234,7 @@ static void au0828_media_graph_notify(struct media_entity 
*new,
if (!new) {
/*
 * Called during au0828 probe time to connect
-* entites that were created prior to registering
+* entities that were created prior to registering
 * the notify handler. Find mixer and decoder.
*/
media_device_for_each_entity(entity, dev->media_dev) {
diff --git a/drivers/media/usb/au0828/au0828.h 
b/drivers/media/usb/au0828/au0828.h
index 004eadef55c7..425c35d16057 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -52,7 +52,7 @@
 
 #define AU0828_INTERLACED_DEFAULT   1
 
-/* Defination for AU0828 USB transfer */
+/* Definition for AU0828 USB transfer */
 #define AU0828_MAX_ISO_BUFS12  /* maybe resize this value in the future */
 #define AU0828_ISO_PACKETS_PER_URB  128
 
diff --git a/drivers/media/usb/cx231xx/cx231xx-avcore.c 
b/drivers/media/usb/cx231xx/cx231xx-avcore.c
index fdd3c221fa0d..3374888b3021 100644
--- a/drivers/media/usb/cx231xx/cx231xx-avcore.c
+++ b/drivers/media/usb/cx231xx/cx231xx-avcore.c
@@ -2987,7 +2987,7 @@ int cx231xx_gpio_i2c_write_ack(struct cx231xx *dev)
 {
int status = 0;
 
-   /* set SDA to ouput */
+   /* set SDA to output */
dev->gpio_dir |= 1 << dev->board.

[PATCH] usb: core: config: Use struct_size() in kzalloc()

2019-02-18 Thread Gustavo A. R. Silva
One of the more common cases of allocation size calculations is finding
the size of a structure that has a zero-sized array at the end, along
with memory for some number of elements for that array. For example:

struct foo {
int stuff;
struct boo entry[];
};

size = sizeof(struct foo) + count * sizeof(struct boo);
instance = kzalloc(size, GFP_KERNEL);

Instead of leaving these open-coded and prone to type mistakes, we can
now use the new struct_size() helper:

instance = kzalloc(struct_size(instance, entry, count), GFP_KERNEL);

Notice that, in this case, variable len is not necessary, hence
it is removed.

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/usb/core/config.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/core/config.c b/drivers/usb/core/config.c
index 7bb6b1bd06c8..20ff036b4c22 100644
--- a/drivers/usb/core/config.c
+++ b/drivers/usb/core/config.c
@@ -552,7 +552,7 @@ static int usb_parse_configuration(struct usb_device *dev, 
int cfgidx,
unsigned char *buffer2;
int size2;
struct usb_descriptor_header *header;
-   int len, retval;
+   int retval;
u8 inums[USB_MAXINTERFACES], nalts[USB_MAXINTERFACES];
unsigned iad_num = 0;
 
@@ -707,8 +707,8 @@ static int usb_parse_configuration(struct usb_device *dev, 
int cfgidx,
nalts[i] = j = USB_MAXALTSETTING;
}
 
-   len = sizeof(*intfc) + sizeof(struct usb_host_interface) * j;
-   config->intf_cache[i] = intfc = kzalloc(len, GFP_KERNEL);
+   intfc = kzalloc(struct_size(intfc, altsetting, j), GFP_KERNEL);
+   config->intf_cache[i] = intfc;
if (!intfc)
return -ENOMEM;
kref_init(&intfc->ref);
-- 
2.20.1



Re: [PATCH 2/2] RTL8153-BD is used in Dell DA300 type-C dongle. It should be added to the whitelist of devices to activate MAC address pass through.

2019-02-18 Thread David Miller


Where is patch #1?


Re: [PATCH v2 01/10] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-02-18 Thread Rob Herring
On Mon, Feb 18, 2019 at 07:23:01PM +0800, Yu Chen wrote:
> This patch adds binding documentation for supporting the hi3660 usb
> phy on boards like the HiKey960.
> 
> Cc: Rob Herring 
> Cc: Mark Rutland 
> Cc: John Stultz 
> Cc: Binghui Wang 
> Signed-off-by: Yu Chen 
> ---
> v1:
> * Fix some format error as suggested by Rob.
> v2:
> * Change hi3660 usb PHY to hi3660 USB PHY
> ---
> ---
>  .../devicetree/bindings/phy/phy-hi3660-usb3.txt | 21 
> +
>  1 file changed, 21 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> 
> diff --git a/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt 
> b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> new file mode 100644
> index ..f9a3d56cfdd2
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> @@ -0,0 +1,21 @@
> +Hisilicon hi3660 USB PHY
> +---
> +
> +Required properties:
> +- compatible: should be "hisilicon,hi3660-usb-phy"
> +- #phy-cells: must be 0
> +- hisilicon,pericrg-syscon: phandle of syscon used to control phy.
> +- hisilicon,pctrl-syscon: phandle of syscon used to control phy.
> +- hisilicon,usb3-otg-bc-syscon: phandle of syscon used to control phy.
> +- hisilicon,eye-diagram-param: parameter set for phy
> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
> +
> +Example:
> + usb-phy {
> + compatible = "hisilicon,hi3660-usb-phy";
> + #phy-cells = <0>;
> + hisilicon,pericrg-syscon = <&crg_ctrl>;
> + hisilicon,pctrl-syscon = <&pctrl>;
> + hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;

Are most of the registers within one of these blocks? If so, make this 
node a child of that node.

> + hisilicon,eye-diagram-param = <0x22466e4>;
> + };
> -- 
> 2.15.0-rc2
> 


[PATCH] usb: wusbcore: wa-xfer: use struct_size() helper

2019-02-18 Thread Gustavo A. R. Silva
Make use of the struct_size() helper instead of an open-coded version
in order to avoid any potential type mistakes, in particular in the
context in which this code is being used.

So, change the following form:

sizeof(*packet_desc) + (sizeof(packet_desc->PacketLength[0]) * 
seg->isoc_frame_count)

to :

struct_size(packet_status, PacketStatus, seg->isoc_frame_count);

This code was detected with the help of Coccinelle.

Signed-off-by: Gustavo A. R. Silva 
---
 drivers/usb/wusbcore/wa-xfer.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
index 01f2f21830c0..abf88cea37bb 100644
--- a/drivers/usb/wusbcore/wa-xfer.c
+++ b/drivers/usb/wusbcore/wa-xfer.c
@@ -662,9 +662,9 @@ static void __wa_setup_isoc_packet_descr(
 
/* populate isoc packet descriptor. */
packet_desc->bPacketType = WA_XFER_ISO_PACKET_INFO;
-   packet_desc->wLength = cpu_to_le16(sizeof(*packet_desc) +
-   (sizeof(packet_desc->PacketLength[0]) *
-   seg->isoc_frame_count));
+   packet_desc->wLength = cpu_to_le16(struct_size(packet_desc,
+  PacketLength,
+  seg->isoc_frame_count));
for (frame_index = 0; frame_index < seg->isoc_frame_count;
++frame_index) {
int offset_index = frame_index + seg->isoc_frame_offset;
@@ -2438,7 +2438,7 @@ static int wa_process_iso_packet_status(struct wahc *wa, 
struct urb *urb)
struct wa_rpipe *rpipe;
unsigned done = 0, dti_busy = 0, data_frame_count = 0, seg_index;
unsigned first_frame_index = 0, rpipe_ready = 0;
-   int expected_size;
+   size_t expected_size;
 
/* We have a xfer result buffer; check it */
dev_dbg(dev, "DTI: isoc packet status %d bytes at %p\n",
@@ -2460,11 +2460,10 @@ static int wa_process_iso_packet_status(struct wahc 
*wa, struct urb *urb)
goto error_bad_seg;
seg = xfer->seg[wa->dti_isoc_xfer_seg];
rpipe = xfer->ep->hcpriv;
-   expected_size = sizeof(*packet_status) +
-   (sizeof(packet_status->PacketStatus[0]) *
-   seg->isoc_frame_count);
+   expected_size = struct_size(packet_status, PacketStatus,
+   seg->isoc_frame_count);
if (urb->actual_length != expected_size) {
-   dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d 
bytes vs %d needed)\n",
+   dev_err(dev, "DTI Error: isoc packet status--bad urb length (%d 
bytes vs %zu needed)\n",
urb->actual_length, expected_size);
goto error_bad_seg;
}
-- 
2.20.1



Re: [BUG] mt76x0u: Probing issues on Raspberry Pi 3 B+

2019-02-18 Thread Stefan Wahren
Hi,

> Stanislaw Gruszka  hat am 18. Februar 2019 um 14:52 
> geschrieben:
> 
> 
> On Sat, Feb 16, 2019 at 08:17:07PM +0100, Stefan Wahren wrote:
> > this is a misunderstanding. The warning is about memory alignment to 32 bit 
> > addresses, not about page alignment. This is a typical ARM restriction. 
> > Maybe we need to make sure in mt76 that the DMA buffer needs to be aligned. 
> > But it's also possible that the warning isn't the root cause of our problem.
> > 
> 
> I see, it needs 4 bytes alignment . There is already dwc2 code checks
> that and allocate new buffer if the alignment is not right:
> dwc2_alloc_dma_aligned_buffer(), but it does nothing if urb->sg
> is not NULL. I thought mt76usb already provide aligned buffers, but
> looks it does not for one TX special case, which are PROBE REQUEST
> frames. Other frames are aligned by inserting L2 header pad. One
> solution for this would be just submit urb with  NULL sg (same as
> Lorenzo's patches do, but still allocating buffers via buf->sg),
> but I think, you have right, we should provide 4 bytes aligned buffers
> by default as other DMA hardware may require that. I'm attaching yet
> another patch to test, which fix up alignment for PROBE REQUEST frames.
> 
> > > Attached patch should fix this, plese test, thanks in advance.

i saw Felix decided to use Lorenzo's approach.

The patches 1,3,5 applied on today's next fixed only the warning and wifi is 
still broken (authentication timeout).

Here are the logs for multi_v7_defconfig:
https://gist.github.com/lategoodbye/0a7c5cea7dbf25d0de7944c05d229d79

> > 
> > Anyway i tested the following patch combinations against next with the same 
> > results as 1,2,3 (no wifi, alignment warning):
> > 1,3
> > 1,2,3,4
> 
> I noticed on my setup that patch 4 can cause troubles, but still
> device is workable here on my PC machines.
> 
> > > > Btw i can confirm a regression was introduced after 4.19, because in 
> > > > 4.19 there was no firmware timeout but even no working wifi:
> > > 
> > > You ment 'no working wifi' or 'working wifi'?
> > 
> > Wifi is broken in 4.19, 4.20, 5.0 and next. It only worked with Lorenzo's 
> > SG avoid patches so far. Btw the regression (firmware timeout) started in 
> > 4.20. I also tested it today.
> 
> That somewhat strange because 4.19 mt76x0u does not use SG.
> On 4.19 there is phy calibration bug fixed in 4.19.5:

Sorry for being inprecise. I was talking about the branches not the exact tags. 
I tested 4.19.23 without luck.

Many thanks anyway
Stefan


Re: [PATCH] r8152: Add support for MAC address pass through on RTL8153-BD

2019-02-18 Thread David Miller
From: David Chen 
Date: Sat, 16 Feb 2019 17:16:42 +0800

> From: David Chen 
> 
> RTL8153-BD is used in Dell DA300 type-C dongle.
> It should be added to the whitelist of devices to activate MAC address
> pass through.
> 
> Per confirming with Realtek all devices containing RTL8153-BD should
> activate MAC pass through and there won't use pass through bit on efuse
> like in RTL8153-AD.
> 
> Signed-off-by: David Chen 

Applied, thanks.


Re: [PATCH v2 00/10] Add support for usb on Hikey960

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 1:30, Valentin Schneider wrote:
> Hi,
> 
> On 18/02/2019 11:23, Yu Chen wrote:
>> The patchset adds support for usb functionality of Hikey960, includes:
>> - dwc3 driver for Hisilicon Kirin Soc hi3660
>> - usb driver for HiKey960 board
>> - some adjustment in dwc3, usb gadget and typec driver
>> - dts for support usb of HiKey960
>>
> 
> I want to try this out on my HiKey960, but I can't get the USB A ports
> working (tried USB stick and USB eth adapter).
> 
> On top of the arm64 defconfig, I've enabled (with menuconfig):
> 
>   CONFIG_PHY_HI3660_USB
>   CONFIG_HISI_HIKEY_USB
> 
> Am I missing something? FYI up until now I've carried over Fan Ning's old
> USB patch-set and that works fine, so I think it might just be a
> configuration error from my end.

This patch set based on Heikki Krogerus's patches.
Have you applied https://do-db2.lkml.org/lkml/2019/2/13/106 first?
And these configs should be set to y:
CONFIG_TYPEC
CONFIG_TYPEC_TCPM
CONFIG_TYPEC_TCPCI
CONFIG_TYPEC_RT1711H

> 
> Thanks,
> Valentin
> 
> 
> 
> .
> 

Thanks,
Yu Chen



Re: [PATCH v2] scsi: sd: block: Fix regressions in read-only block device handling

2019-02-18 Thread Ming Lei
On Wed, Feb 13, 2019 at 5:01 PM Martin K. Petersen
 wrote:
>
> Some devices come online in write protected state and switch to
> read-write once they are ready to process I/O requests. These devices
> broke with commit 20bd1d026aac ("scsi: sd: Keep disk read-only when
> re-reading partition") because we had no way to distinguish between a
> user decision to set a block_device read-only and the actual hardware
> device being write-protected.
>
> Because partitions are dropped and recreated on revalidate we are
> unable to persist any user-provided policy in hd_struct. Introduce a
> bitmap in struct gendisk to track the user configuration. This bitmap
> is updated when BLKROSET is called on a given disk or partition.
>
> A helper function, get_user_ro(), is provided to determine whether the
> ioctl has forced read-only state for a given block device. This helper
> is used by set_disk_ro() and add_partition() to ensure that both
> existing and newly created partitions will get the correct state.

Hi Martin & Oleksii,

>From the Bugzilla, looks it is only reported on the "Kingston DT Ultimate G3"
USB flash drive.

If it is true, this particular issue might be addressed simply by applying one
quirk on this drive, such as, by adding one delay before calling
sd_spinup_disk()
in the 1st sd_revalidate_disk() to wait until it is ready to process
I/O requests.

Otherwise if there are many such devices, I think your approach is good.

Thanks,
Ming Lei


Re: [PATCH v2 07/10] usb: dwc3: Registering a role switch in the DRD code.

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 1:30, Valentin Schneider wrote:
> Hi,
> 
> On 18/02/2019 11:23, Yu Chen wrote:
> [...]
>> @@ -522,6 +556,15 @@ int dwc3_drd_init(struct dwc3 *dwc)
>>  dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
>>  }
>>  
>> +dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
>> +dwc3_role_switch.set = dwc3_usb_role_switch_set;
>> +dwc3_role_switch.get = dwc3_usb_role_switch_get;
>> +dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
> 
> Building arm64 defconfig gives me this:
> 
> drivers/usb/dwc3/drd.o: In function `dwc3_drd_exit':
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604: undefined reference to 
> `usb_role_switch_unregister'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604:(.text+0x814): 
> relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol 
> `usb_role_switch_unregister'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604: undefined reference to 
> `usb_role_switch_unregister'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:604:(.text+0x844): 
> relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol 
> `usb_role_switch_unregister'
> drivers/usb/dwc3/drd.o: In function `dwc3_drd_init':
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562: undefined reference to 
> `usb_role_switch_register'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562:(.text+0xa20): 
> relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol 
> `usb_role_switch_register'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562: undefined reference to 
> `usb_role_switch_register'
> /home/valsch01/Work/kernel/drivers/usb/dwc3/drd.c:562:(.text+0xb4c): 
> relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol 
> `usb_role_switch_register'
> Makefile:1024: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1
> 
> This has CONFIG_USB_ROLE_SWITCH=m, setting it as a built-in makes the thing
> linkable.
> 
> I suppose that's because defconfig gives us
> 
>   CONFIG_USB_DWC3_DUAL_ROLE=y
> 
> but then that should probably force a CONFIG_USB_ROLE_SWITCH=y. My
> immediate reaction to this would be to add:
> 
> ---
> diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
> index 2b1494460d0c..661b1d2efc8b 100644
> --- a/drivers/usb/dwc3/Kconfig
> +++ b/drivers/usb/dwc3/Kconfig
> @@ -44,6 +44,7 @@ config USB_DWC3_DUAL_ROLE
>   bool "Dual Role mode"
>   depends on ((USB=y || USB=USB_DWC3) && (USB_GADGET=y || 
> USB_GADGET=USB_DWC3))
>   depends on (EXTCON=y || EXTCON=USB_DWC3)
> + select USB_ROLE_SWITCH
>   help
> This is the default mode of working of DWC3 controller where
> both host and gadget features are enabled.
> ---
>   
> Not sure how acceptable that is though.
> 
Thanks for your notice! I will add this in next version.

> 
>> +if (ret) {
>> +dwc3_drd_exit(dwc);
>> +return PTR_ERR(dwc->role_sw);
>> +}
>> +
>>  return 0;
>>  }
>>  
>> @@ -557,4 +600,6 @@ void dwc3_drd_exit(struct dwc3 *dwc)
>>  
>>  if (!dwc->edev)
>>  free_irq(dwc->otg_irq, dwc);
>> +
>> +usb_role_switch_unregister(dwc->role_sw);
>>  }
>>
> 
> .
> 

Thanks
Yu Chen



Re: [PATCH v2 01/10] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 4:18, Rob Herring wrote:
> On Mon, Feb 18, 2019 at 07:23:01PM +0800, Yu Chen wrote:
>> This patch adds binding documentation for supporting the hi3660 usb
>> phy on boards like the HiKey960.
>>
>> Cc: Rob Herring 
>> Cc: Mark Rutland 
>> Cc: John Stultz 
>> Cc: Binghui Wang 
>> Signed-off-by: Yu Chen 
>> ---
>> v1:
>> * Fix some format error as suggested by Rob.
>> v2:
>> * Change hi3660 usb PHY to hi3660 USB PHY
>> ---
>> ---
>>  .../devicetree/bindings/phy/phy-hi3660-usb3.txt | 21 
>> +
>>  1 file changed, 21 insertions(+)
>>  create mode 100644 Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
>>
>> diff --git a/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt 
>> b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
>> new file mode 100644
>> index ..f9a3d56cfdd2
>> --- /dev/null
>> +++ b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
>> @@ -0,0 +1,21 @@
>> +Hisilicon hi3660 USB PHY
>> +---
>> +
>> +Required properties:
>> +- compatible: should be "hisilicon,hi3660-usb-phy"
>> +- #phy-cells: must be 0
>> +- hisilicon,pericrg-syscon: phandle of syscon used to control phy.
>> +- hisilicon,pctrl-syscon: phandle of syscon used to control phy.
>> +- hisilicon,usb3-otg-bc-syscon: phandle of syscon used to control phy.
>> +- hisilicon,eye-diagram-param: parameter set for phy
>> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
>> +
>> +Example:
>> +usb-phy {
>> +compatible = "hisilicon,hi3660-usb-phy";
>> +#phy-cells = <0>;
>> +hisilicon,pericrg-syscon = <&crg_ctrl>;
>> +hisilicon,pctrl-syscon = <&pctrl>;
>> +hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;
> 
> Are most of the registers within one of these blocks? If so, make this 
> node a child of that node.
I met a problem when I made this node a child of the syscon node,
the driver "phy-hi3660-usb3" was not probed.
Do you have any idea about how to make it probed when it is a child node?
> 
>> +hisilicon,eye-diagram-param = <0x22466e4>;
>> +};
>> -- 
>> 2.15.0-rc2
>>
> 
> .
> 

Thanks
Yu Chen



Re: [PATCH v2 08/10] hikey960: Support usb functionality of Hikey960

2019-02-18 Thread Chunfeng Yun
Hi,
On Mon, 2019-02-18 at 19:23 +0800, Yu Chen wrote:
> This driver handles usb hub power on and typeC port event of HiKey960 board:
> 1)DP&DM switching between usb hub and typeC port base on typeC port
> state
> 2)Control power of usb hub on Hikey960
> 3)Control vbus of typeC port
> 
> Cc: Andy Shevchenko 
> Cc: Arnd Bergmann 
> Cc: Greg Kroah-Hartman 
> Cc: John Stultz 
> Cc: Binghui Wang 
> Cc: Heikki Krogerus 
> Signed-off-by: Yu Chen 
> 
> ---
> v1:
> * Using gpiod API with the gpios.
> * Removing registering usb role switch.
> * Registering usb role switch notifier.
> v2:
> * Fix license declaration.
> * Add configuration of  gpio direction.
> * Remove some log print.
> ---
> ---
>  drivers/misc/Kconfig  |   6 ++
>  drivers/misc/Makefile |   1 +
>  drivers/misc/hisi_hikey_usb.c | 181 
> ++
>  3 files changed, 188 insertions(+)
>  create mode 100644 drivers/misc/hisi_hikey_usb.c
> 
> diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
> index f417b06e11c5..8d8b717759e2 100644
> --- a/drivers/misc/Kconfig
> +++ b/drivers/misc/Kconfig
> @@ -521,6 +521,12 @@ config PVPANIC
> a paravirtualized device provided by QEMU; it lets a virtual machine
> (guest) communicate panic events to the host.
>  
> +config HISI_HIKEY_USB
> + tristate "USB functionality of HiSilicon Hikey Platform"
> + depends on OF && GPIOLIB
> + help
> +   If you say yes here you get support for usb functionality of 
> HiSilicon Hikey Platform.
> +
>  source "drivers/misc/c2port/Kconfig"
>  source "drivers/misc/eeprom/Kconfig"
>  source "drivers/misc/cb710/Kconfig"
> diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
> index e39ccbbc1b3a..dc8892b13a1a 100644
> --- a/drivers/misc/Makefile
> +++ b/drivers/misc/Makefile
> @@ -59,3 +59,4 @@ obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o
>  obj-$(CONFIG_OCXL)   += ocxl/
>  obj-y+= cardreader/
>  obj-$(CONFIG_PVPANIC)+= pvpanic.o
> +obj-$(CONFIG_HISI_HIKEY_USB) += hisi_hikey_usb.o
> diff --git a/drivers/misc/hisi_hikey_usb.c b/drivers/misc/hisi_hikey_usb.c
> new file mode 100644
> index ..70013f8e76f0
> --- /dev/null
> +++ b/drivers/misc/hisi_hikey_usb.c
> @@ -0,0 +1,181 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Support for usb functionality of Hikey series boards
> + * based on Hisilicon Kirin Soc.
> + *
> + * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd.
> + *   http://www.huawei.com
> + *
> + * Authors: Yu Chen 
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define DEVICE_DRIVER_NAME "hisi_hikey_usb"
> +
> +#define HUB_VBUS_POWER_ON 1
> +#define HUB_VBUS_POWER_OFF 0
> +#define USB_SWITCH_TO_HUB 1
> +#define USB_SWITCH_TO_TYPEC 0
> +
> +struct hisi_hikey_usb {
> + struct gpio_desc *otg_switch;
> + struct gpio_desc *typec_vbus;
> + struct gpio_desc *hub_vbus;
> + int typec_vbus_enable_val;
> +
> + struct usb_role_switch *role_sw;
> + struct notifier_block nb;
> +};
> +
> +static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value)
> +{
> + gpiod_set_value_cansleep(hisi_hikey_usb->hub_vbus, value);
> +}
> +
> +static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
> + int switch_to)
> +{
> + gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to);
> +}
> +
> +static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb,
> + int value)
> +{
> + gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value);
> +}
> +
> +static int hisi_hikey_role_switch(struct notifier_block *nb,
> + unsigned long state, void *data)
> +{
> + struct hisi_hikey_usb *hisi_hikey_usb;
> +
> + hisi_hikey_usb = container_of(nb, struct hisi_hikey_usb, nb);
> +
> + switch (state) {
> + case USB_ROLE_NONE:
> + usb_typec_power_ctrl(hisi_hikey_usb,
> + !hisi_hikey_usb->typec_vbus_enable_val);
> + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB);
> + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON);
> + break;
> + case USB_ROLE_HOST:
> + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
> + usb_typec_power_ctrl(hisi_hikey_usb,
> + hisi_hikey_usb->typec_vbus_enable_val);
> + break;
> + case USB_ROLE_DEVICE:
> + hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF);
> + usb_typec_power_ctrl(hisi_hikey_usb,
> + !hisi_hikey_usb->typec_vbus_enable_val);
> + usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC);
> + break;
> + default:
> + break;
> + }
> +
> + return 0;
> +}
> +
> +static int hisi_hikey_usb_probe(struct platform_device *pdev)
> +{
> + struct device *dev =

Re: [PATCH v2 07/10] usb: dwc3: Registering a role switch in the DRD code.

2019-02-18 Thread Jun Li
Hi
Yu Chen  于2019年2月18日周一 下午7:34写道:
>
> The Type-C drivers use USB role switch API to inform the
> system about the negotiated data role, so registering a role
> switch in the DRD code in order to support platforms with
> USB Type-C connectors.
>
> Cc: John Stultz 
> Cc: Felipe Balbi 
> Cc: Greg Kroah-Hartman 
> Cc: Heikki Krogerus 
> Suggested-by: Heikki Krogerus 
> Signed-off-by: Yu Chen 
> ---
> v2:
> * Assign fwnode in dwc3_role_switch.
> ---
> ---
>  drivers/usb/dwc3/core.h |  2 ++
>  drivers/usb/dwc3/drd.c  | 45 +
>  2 files changed, 47 insertions(+)
>
> diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
> index 402b3c29eb26..7385544b9936 100644
> --- a/drivers/usb/dwc3/core.h
> +++ b/drivers/usb/dwc3/core.h
> @@ -25,6 +25,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>
>  #include 
> @@ -1083,6 +1084,7 @@ struct dwc3 {
> struct extcon_dev   *edev;
> struct notifier_block   edev_nb;
> enum usb_phy_interface  hsphy_mode;
> +   struct usb_role_switch  *role_sw;
>
> u32 fladj;
> u32 irq_gadget;
> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index 869725d15c74..cf977bb0d62e 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c
> @@ -474,8 +474,42 @@ static struct extcon_dev *dwc3_get_extcon(struct dwc3 
> *dwc)
> return edev;
>  }
>
> +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role)
> +{
> +   u32 mode;
> +
> +   switch (role) {
> +   case USB_ROLE_HOST:
> +   mode = DWC3_GCTL_PRTCAP_HOST;
> +   break;
> +   case USB_ROLE_DEVICE:
> +   mode = DWC3_GCTL_PRTCAP_DEVICE;
> +   break;
> +   default:
> +   mode = DWC3_GCTL_PRTCAP_HOST;

I'd propose let dwc3 stay at device mode at default case.

> +   break;
> +   };
> +
> +   dwc3_set_mode(dev_get_drvdata(dev), mode);
> +   return 0;
> +}
> +
> +static enum usb_role dwc3_usb_role_switch_get(struct device *dev)
> +{
> +   struct dwc3 *dwc = dev_get_drvdata(dev);
> +   unsigned long flags;
> +   enum usb_role role;
> +
> +   spin_lock_irqsave(&dwc->lock, flags);
> +   role = dwc->current_otg_role;
> +   spin_unlock_irqrestore(&dwc->lock, flags);
> +
> +   return role;
> +}
> +
>  int dwc3_drd_init(struct dwc3 *dwc)
>  {
> +   struct usb_role_switch_desc dwc3_role_switch = {0};
> int ret, irq;
>
> dwc->edev = dwc3_get_extcon(dwc);
> @@ -522,6 +556,15 @@ int dwc3_drd_init(struct dwc3 *dwc)
> dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
> }
>
> +   dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
> +   dwc3_role_switch.set = dwc3_usb_role_switch_set;
> +   dwc3_role_switch.get = dwc3_usb_role_switch_get;
> +   dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
> +   if (ret) {
> +   dwc3_drd_exit(dwc);
> +   return PTR_ERR(dwc->role_sw);
> +   }
> +

My understanding is, if you use usb role switch, you don't need either edev or
OTG block event, so this should be like:

if (device_property_read_bool(dwc->dev, "usb-role-switch")) {
   usb role switch register;
} else if (edev) {
...
} else {
...
}

Jun
> return 0;
>  }
>
> @@ -557,4 +600,6 @@ void dwc3_drd_exit(struct dwc3 *dwc)
>
> if (!dwc->edev)
> free_irq(dwc->otg_irq, dwc);
> +
> +   usb_role_switch_unregister(dwc->role_sw);
>  }
> --
> 2.15.0-rc2
>


Re: [PATCH v2 01/10] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-02-18 Thread Chunfeng Yun
Hi,
On Tue, 2019-02-19 at 09:50 +0800, Chen Yu wrote:
> Hi,
> 
> On 2019/2/19 4:18, Rob Herring wrote:
> > On Mon, Feb 18, 2019 at 07:23:01PM +0800, Yu Chen wrote:
> >> This patch adds binding documentation for supporting the hi3660 usb
> >> phy on boards like the HiKey960.
> >>
> >> Cc: Rob Herring 
> >> Cc: Mark Rutland 
> >> Cc: John Stultz 
> >> Cc: Binghui Wang 
> >> Signed-off-by: Yu Chen 
> >> ---
> >> v1:
> >> * Fix some format error as suggested by Rob.
> >> v2:
> >> * Change hi3660 usb PHY to hi3660 USB PHY
> >> ---
> >> ---
> >>  .../devicetree/bindings/phy/phy-hi3660-usb3.txt | 21 
> >> +
> >>  1 file changed, 21 insertions(+)
> >>  create mode 100644 
> >> Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> >>
> >> diff --git a/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt 
> >> b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> >> new file mode 100644
> >> index ..f9a3d56cfdd2
> >> --- /dev/null
> >> +++ b/Documentation/devicetree/bindings/phy/phy-hi3660-usb3.txt
> >> @@ -0,0 +1,21 @@
> >> +Hisilicon hi3660 USB PHY
> >> +---
> >> +
> >> +Required properties:
> >> +- compatible: should be "hisilicon,hi3660-usb-phy"
> >> +- #phy-cells: must be 0
> >> +- hisilicon,pericrg-syscon: phandle of syscon used to control phy.
> >> +- hisilicon,pctrl-syscon: phandle of syscon used to control phy.
> >> +- hisilicon,usb3-otg-bc-syscon: phandle of syscon used to control phy.
> >> +- hisilicon,eye-diagram-param: parameter set for phy
> >> +Refer to phy/phy-bindings.txt for the generic PHY binding properties
> >> +
> >> +Example:
> >> +  usb-phy {
> >> +  compatible = "hisilicon,hi3660-usb-phy";
> >> +  #phy-cells = <0>;
> >> +  hisilicon,pericrg-syscon = <&crg_ctrl>;
> >> +  hisilicon,pctrl-syscon = <&pctrl>;
> >> +  hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;
> > 
> > Are most of the registers within one of these blocks? If so, make this 
> > node a child of that node.
> I met a problem when I made this node a child of the syscon node,
> the driver "phy-hi3660-usb3" was not probed.
> Do you have any idea about how to make it probed when it is a child node?
call of_platform_populate() in parent node's driver,
but I don't know whether it's a standard way
> > 
> >> +  hisilicon,eye-diagram-param = <0x22466e4>;
> >> +  };
> >> -- 
> >> 2.15.0-rc2
> >>
> > 
> > .
> > 
> 
> Thanks
> Yu Chen
> 




Re: [PATCH v2 08/10] hikey960: Support usb functionality of Hikey960

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 10:50, Chunfeng Yun wrote:
>> +if (ret)
>> +hisi_hikey_usb->typec_vbus_enable_val = 1;
>> +
>> +hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus",
>> +hisi_hikey_usb->typec_vbus_enable_val ?
>> +GPIOD_OUT_LOW : GPIOD_OUT_HIGH);
>> +if (!hisi_hikey_usb->typec_vbus)
>> +return -ENOENT;
>> +else if (IS_ERR(hisi_hikey_usb->typec_vbus))
>> +return PTR_ERR(hisi_hikey_usb->typec_vbus);
>> +
>> +gpiod_direction_output(hisi_hikey_usb->typec_vbus,
>> +!hisi_hikey_usb->typec_vbus_enable_val);
> maybe a simple way if use fixed regulator?
> 
The hardware of the Hikey960 board has been fixed, and the type-c
port can act as UFP. So it is better to close the vbus when Hikey960
connect to host(e.g PC).
>> +
>> +hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", 
>> GPIOD_IN);
>> +if (!hisi_hikey_usb->otg_switch)
>> +return -ENOENT;
>> +else if (IS_ERR(hisi_hikey_usb->otg_switch))
>> +return PTR_ERR(hisi_hikey_usb->otg_switch);
>> +
>> +gpiod_direction_output(hisi_hikey_usb->otg_switch, USB_SWITCH_TO_HUB);
>> +
>> +/* hub-vdd33-en is optional */
>> +hisi_hikey_usb->hub_vbus = devm_gpiod_get(dev, "hub-vdd33-en",
>> +GPIOD_OUT_LOW);
>> +if (IS_ERR(hisi_hikey_usb->hub_vbus))
>> +return PTR_ERR(hisi_hikey_usb->hub_vbus);
>> +
>> +gpiod_direction_output(hisi_hikey_usb->hub_vbus, HUB_VBUS_POWER_ON);
> ditto
>> +
>> +hisi_hikey_usb->role_sw = usb_role_switch_get(dev);
>> +if (!hisi_hikey_usb->role_sw)
>> +return -EPROBE_DEFER;
>> +else if (IS_ERR(hisi_hikey_usb->role_sw))
>> +return PTR_ERR(hisi_hikey_usb->role_sw);
>> +

Thanks
Yu Chen



Re: [PATCH v2 07/10] usb: dwc3: Registering a role switch in the DRD code.

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 10:57, Jun Li wrote:
>>
>> +static int dwc3_usb_role_switch_set(struct device *dev, enum usb_role role)
>> +{
>> +   u32 mode;
>> +
>> +   switch (role) {
>> +   case USB_ROLE_HOST:
>> +   mode = DWC3_GCTL_PRTCAP_HOST;
>> +   break;
>> +   case USB_ROLE_DEVICE:
>> +   mode = DWC3_GCTL_PRTCAP_DEVICE;
>> +   break;
>> +   default:
>> +   mode = DWC3_GCTL_PRTCAP_HOST;
> 
> I'd propose let dwc3 stay at device mode at default case.
> 
Setting mode to DWC3_GCTL_PRTCAP_HOST at default case due to the
requirement of Hikey960 board. When there is no cable connected to
type-C port, dwc3 should be set to HOST mode and the hub on the
Hikey960 will be power on.
Here is the details of the Hikey960:

https://www.96boards.org/documentation/consumer/hikey/hikey960/hardware-docs/hardware-user-manual.md.html

But I will check the code to see if it is possible to make dwc3
set to device mode at default case.

>> +   break;
>> +   };
>> +
>> +   dwc3_set_mode(dev_get_drvdata(dev), mode);
>> +   return 0;
>> +}
>> +
>> +static enum usb_role dwc3_usb_role_switch_get(struct device *dev)
>> +{
>> +   struct dwc3 *dwc = dev_get_drvdata(dev);
>> +   unsigned long flags;
>> +   enum usb_role role;
>> +
>> +   spin_lock_irqsave(&dwc->lock, flags);
>> +   role = dwc->current_otg_role;
>> +   spin_unlock_irqrestore(&dwc->lock, flags);
>> +
>> +   return role;
>> +}
>> +
>>  int dwc3_drd_init(struct dwc3 *dwc)
>>  {
>> +   struct usb_role_switch_desc dwc3_role_switch = {0};
>> int ret, irq;
>>
>> dwc->edev = dwc3_get_extcon(dwc);
>> @@ -522,6 +556,15 @@ int dwc3_drd_init(struct dwc3 *dwc)
>> dwc3_set_mode(dwc, DWC3_GCTL_PRTCAP_OTG);
>> }
>>
>> +   dwc3_role_switch.fwnode = dev_fwnode(dwc->dev);
>> +   dwc3_role_switch.set = dwc3_usb_role_switch_set;
>> +   dwc3_role_switch.get = dwc3_usb_role_switch_get;
>> +   dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
>> +   if (ret) {
>> +   dwc3_drd_exit(dwc);
>> +   return PTR_ERR(dwc->role_sw);
>> +   }
>> +
> 
> My understanding is, if you use usb role switch, you don't need either edev or
> OTG block event, so this should be like:
> 
> if (device_property_read_bool(dwc->dev, "usb-role-switch")) {
>usb role switch register;
> } else if (edev) {
> ...
> } else {
> ...
> }
Yes. Thanks!

> 
> Jun
>> return 0;
>>  }
>>
>> @@ -557,4 +600,6 @@ void dwc3_drd_exit(struct dwc3 *dwc)
>>
>> if (!dwc->edev)
>> free_irq(dwc->otg_irq, dwc);
>> +
>> +   usb_role_switch_unregister(dwc->role_sw);
>>  }
>> --
>> 2.15.0-rc2
>>
> 
> .
> 

Thanks
Yu Chen



Re: [PATCH v2 01/10] dt-bindings: phy: Add support for HiSilicon's hi3660 USB PHY

2019-02-18 Thread Chen Yu
Hi,

On 2019/2/19 11:03, Chunfeng Yun wrote:
 +
 +Example:
 +  usb-phy {
 +  compatible = "hisilicon,hi3660-usb-phy";
 +  #phy-cells = <0>;
 +  hisilicon,pericrg-syscon = <&crg_ctrl>;
 +  hisilicon,pctrl-syscon = <&pctrl>;
 +  hisilicon,usb3-otg-bc-syscon = <&usb3_otg_bc>;
>>>
>>> Are most of the registers within one of these blocks? If so, make this 
>>> node a child of that node.
>> I met a problem when I made this node a child of the syscon node,
>> the driver "phy-hi3660-usb3" was not probed.
>> Do you have any idea about how to make it probed when it is a child node?
> call of_platform_populate() in parent node's driver,
> but I don't know whether it's a standard way
Yes, this function is used in dwc3 driver to probe the child node.
But I think it is not a good way to modify the syscon driver.
>>>
 +  hisilicon,eye-diagram-param = <0x22466e4>;
 +  };
 -- 
 2.15.0-rc2


Thanks
Yu Chen



Re: [PATCH] [v2]USB:serial:pl2303:add new Pull-Up mode to support PL2303HXD (TYPE_HX)

2019-02-18 Thread Charles Yeh
Hi Johan & Greg,


Do you have received a new patch"[PATCH] [v2]USB:serial:pl2303:add new
Pull-Up mode to support PL2303HXD (TYPE_HX)"?

If you have received a new patch, has the content been confirmed?

Or tell me where needs to be modified.

Charles Yeh  於 2019年2月12日 週二 下午8:51寫道:
>
> Pull-Up mode is disabled (default) in PL2303HXD.
> When the Pull-Up mode is activated, its TX/DTR/RTS external resistor will 
> start the output function.
>
> How to enable the Pull-Up mode of PL2303HXD
> 1.TX/DTR/RTS external resistor is required on the circuit diagram (PCB)
> 2.PL2303HXD OTP needs to be programmed to have a Pull-Up mode through 6.5V 
> (USB_VCC,5V->6.5V)
>
> The patch driver will read whether the PL2303HXD has a Pull-Up mode,and if so,
> it will be set to enable Pull-Up mode function.
>
> Signed-off-by: Charles Yeh 
> ---
>  drivers/usb/serial/pl2303.c | 24 
>  1 file changed, 24 insertions(+)
>
> diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
> index bb3f9aa4a909..e5d00e4a495d 100644
> --- a/drivers/usb/serial/pl2303.c
> +++ b/drivers/usb/serial/pl2303.c
> @@ -145,6 +145,16 @@ MODULE_DEVICE_TABLE(usb, id_table);
>  #define UART_OVERRUN_ERROR 0x40
>  #define UART_CTS   0x80
>
> +#defineTYPE_HX_READ_PUM_STATUS_REG 0x8484
> +#defineTYPE_HX_READ_PUM_ADD0x0404
> +#defineTYPE_HX_READ_PUM_DATA_REG   0x8383
> +#defineTYPE_HX_PULLUP_MODE_DATA0x08
> +#defineTYPE_HX_PULLUP_MODE_REG 0x09
> +#defineTYPE_HX_PUM_ADD00x00
> +#defineTYPE_HX_PUM_DATA0   0x31
> +#defineTYPE_HX_PUM_ADD10x01
> +#defineTYPE_HX_PUM_DATA1   0x08
> +
>  static void pl2303_set_break(struct usb_serial_port *port, bool enable);
>
>  enum pl2303_type {
> @@ -688,6 +698,20 @@ static void pl2303_set_termios(struct tty_struct *tty,
> pl2303_vendor_write(serial, 0x0, 0x0);
> }
>
> +   if (spriv->type == &pl2303_type_data[TYPE_HX]) {
> +   pl2303_vendor_read(serial, TYPE_HX_READ_PUM_STATUS_REG, buf);
> +   pl2303_vendor_write(serial, TYPE_HX_READ_PUM_ADD,
> +   TYPE_HX_PULLUP_MODE_REG);
> +   pl2303_vendor_read(serial, TYPE_HX_READ_PUM_STATUS_REG, buf);
> +   pl2303_vendor_read(serial, TYPE_HX_READ_PUM_DATA_REG, buf);
> +   if (*buf == TYPE_HX_PULLUP_MODE_DATA) {
> +   pl2303_vendor_write(serial, TYPE_HX_PUM_ADD0,
> +   TYPE_HX_PUM_DATA0);
> +   pl2303_vendor_write(serial, TYPE_HX_PUM_ADD1,
> +   TYPE_HX_PUM_DATA1);
> +   }
> +   }
> +
> kfree(buf);
>  }
>
> --
> 2.19.1
>


Re: [PATCH] USB:serial:pl2303:Add new PID to support PL2303HXN (TYPE_HXN)

2019-02-18 Thread Charles Yeh
Hi Johan & Greg,


Do you have received a new patch"[PATCH] USB:serial:pl2303:Add new PID
to support PL2303HXN (TYPE_HXN)"?

If you have received a new patch, has the content been confirmed?

Or tell me where needs to be modified.

Thanks!

Charles.


Charles Yeh  於 2019年2月13日 週三 下午8:30寫道:


>
> Prolific has developed a new USB to UART chip: PL2303HXN 
> (PL2303GC/PL2303GS/PL2303GT/PL2303GL/PL2303GE)
> The Vendor request used by the PL2303HXN (TYPE_HXN) is different from the 
> existing PL2303 series (TYPE_HX & TYPE_01).
> Therefore, different Vendor requests are used to issue related commands.
>
> 1. Added a new TYPE_HXN type in pl2303_type_data, and then executes new 
> Vendor request,
>new flow control and other related instructions if TYPE_HXN is recognized.
>
> 2. Because the new PL2303HXN can only accept the new Vendor request,
>the old Vendor request cannot be accepted (the error message will be 
> returned)
>So first determine the TYPE_HX or TYPE_HXN through TYPE_HX_READ_STATUS_REG 
> in pl2303_startup.
>
>   2.1 If the return message is "1", then the PL2303 is the existing TYPE_HX/ 
> TYPE_01 series.
>   The other settings in pl2303_startup are to continue execution.
>   2.2 If the return message is "not 1", then the PL2303 is the new TYPE_HXN 
> series.
>   The other settings in pl2303_startup are ignored.
>   (PL2303HXN will directly use the default value in the hardware,
>no need to add additional settings through the software)
>
> 3. In pl2303_open: Because TYPE_HXN is different from the instruction of 
> down/up stream used by TYPE_HX.
>Therefore, we will also execute different instructions here.
>
> 4. In pl2303_set_termios: The UART flow control instructions used by 
> TYPE_HXN/TYPE_HX/TYPE_01 are different.
>Therefore, we will also execute different instructions here.
>
> 5. In pl2303_vendor_read & pl2303_vendor_write, since TYPE_HXN is different 
> from the vendor request
>instruction used by TYPE_HX/TYPE_01, it will also execute different 
> instructions here.
>
> Signed-off-by: Charles Yeh 
> ---
>  drivers/usb/serial/pl2303.c | 131 +---
>  drivers/usb/serial/pl2303.h |   7 ++
>  2 files changed, 113 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/usb/serial/pl2303.c b/drivers/usb/serial/pl2303.c
> index bb3f9aa4a909..d7d557e01390 100644
> --- a/drivers/usb/serial/pl2303.c
> +++ b/drivers/usb/serial/pl2303.c
> @@ -47,6 +47,12 @@ static const struct usb_device_id id_table[] = {
> { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_MOTOROLA) },
> { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_ZTEK) },
> { USB_DEVICE(PL2303_VENDOR_ID, PL2303_PRODUCT_ID_TB) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GC) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GB) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GT) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GL) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GE) },
> +   { USB_DEVICE(PL2303_VENDOR_ID, PL2303G_PRODUCT_ID_GS) },
> { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID) },
> { USB_DEVICE(IODATA_VENDOR_ID, IODATA_PRODUCT_ID_RSAQ5) },
> { USB_DEVICE(ATEN_VENDOR_ID, ATEN_PRODUCT_ID),
> @@ -129,9 +135,11 @@ MODULE_DEVICE_TABLE(usb, id_table);
>
>  #define VENDOR_WRITE_REQUEST_TYPE  0x40
>  #define VENDOR_WRITE_REQUEST   0x01
> +#define VENDOR_WRITE_NREQUEST  0x80
>
>  #define VENDOR_READ_REQUEST_TYPE   0xc0
>  #define VENDOR_READ_REQUEST0x01
> +#define VENDOR_READ_NREQUEST   0x81
>
>  #define UART_STATE_INDEX   8
>  #define UART_STATE_MSR_MASK0x8b
> @@ -145,11 +153,30 @@ MODULE_DEVICE_TABLE(usb, id_table);
>  #define UART_OVERRUN_ERROR 0x40
>  #define UART_CTS   0x80
>
> +#define TYPE_HX_READ_STATUS_REG0x8080
> +#define TYPE_HXN_FLOWCONTROL_REG   0x0A
> +#define TYPE_HXN_HARDWAREFLOW_DATA 0xFA
> +#define TYPE_HXN_SOFTWAREFLOW_DATA 0xEE
> +#define TYPE_HXN_NOFLOW_DATA   0xFF
> +#define TYPE_HX_01_FLOWCONTROL_REG 0x00
> +#define TYPE_01_HARDWAREFLOW_DATA  0x41
> +#define TYPE_HX_HARDWAREFLOW_DATA  0x61
> +#define TYPE_HX_01_SOFTWAREFLOW_DATA   0xC0
> +#define TYPE_HX_01_NOFLOW_DATA 0x00
> +#define UART_XON_CHAR  0x11
> +#define UART_XOFF_CHAR 0x13
> +#define HX_RESET_DOWN_UPSTREAM_REG10x08
> +#define HX_RESET_DOWN_UPSTREAM_REG20x09
> +#define HX_RESET_DOWN_UPSTREAM_DATA0x00
> +#define HXN_RESET_DOWN_UPSTREAM_REG0x07
> +#define HXN_RESET_DOWN_UPSTREAM_DATA   0x00
> +
>  static void pl2303_set_break(struct usb_serial_port *port, bool enable);
>
>  enum pl2303_type {
> TYPE_01,/* Type 0 and 1 (difference unknown) */
> TYPE_HX,/* HX version of the pl2303 chip */
> +   TYPE_HXN,   /* HXN version of

[PATCH -next] usb: typec: mux: Fix unsigned comparison with less than zero

2019-02-18 Thread YueHaibing
The return from the call to fwnode_property_read_u16_array is int, 
it can be a negative error code however this is being assigned to
an size_t variable 'nval', hence the check is always false.
Fix this by making 'nval' an int.

Detected by Coccinelle ("Unsigned expression compared with
zero: nval < 0")

Fixes: 96a6d031ca99 ("usb: typec: mux: Find the muxes by also matching against 
the device node")
Signed-off-by: YueHaibing 
---
 drivers/usb/typec/mux.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
index a5947d9..54d7497 100644
--- a/drivers/usb/typec/mux.c
+++ b/drivers/usb/typec/mux.c
@@ -126,7 +126,7 @@ static void *typec_mux_match(struct device_connection *con, 
int ep, void *data)
 {
const struct typec_altmode_desc *desc = data;
struct typec_mux *mux;
-   size_t nval;
+   int nval;
bool match;
u16 *val;
int i;
-- 
2.7.0




[PATCH v2 2/2] usb: dwc3: Add workaround for host mode VBUS glitch when boot

2019-02-18 Thread Ran Wang
When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS
(or its control signal) will be turned on immediately on related Root Hub
ports. Then, the VBUS is turned off for a little while(15us) when do xhci
reset (conducted by xhci driver) and back to normal finally, we can
observe a negative glitch of related signal happen.

This VBUS glitch might cause some USB devices enumeration fail if kernel
boot with them connected. Such as LS1012AFWRY/LS1043ARDB/LX2160AQDS
/LS1088ARDB with Kingston 16GB USB2.0/Kingston USB3.0/JetFlash Transcend
4GB USB2.0 drives. The fail cases include enumerated as full-speed device
or report wrong device descriptor, etc.

One SW workaround which can fix this is by programing all xhci PORTSC[PP]
to 0 to turn off VBUS immediately after setting host mode in DWC3 driver
(per signal measurement result, it will be too late to do it in
xhci-plat.c or xhci.c). Then, after xhci reset complete in xhci driver,
PORTSC[PP]s' value will back to 1 automatically and VBUS on at that time,
no glitch happen and normal enumeration process has no impact.

Signed-off-by: Ran Wang 
---
Changes in v2:
  - Rename related property to 'snps,host-vbus-glitches'
  - Rename related dwc member to 'host_vbus_glitches'
  - Add member 'host_vbus_glitches' description in 'dwc3'

 drivers/usb/dwc3/core.c |   47 +++
 drivers/usb/dwc3/core.h |   12 +++-
 2 files changed, 58 insertions(+), 1 deletions(-)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a1b126f..02d11bc 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -100,6 +100,41 @@ static int dwc3_get_dr_mode(struct dwc3 *dwc)
return 0;
 }
 
+/*
+ * dwc3_power_of_all_roothub_ports - Power off all Root hub ports
+ * @dwc3: Pointer to our controller context structure
+ */
+static void dwc3_power_off_all_roothub_ports(struct dwc3 *dwc)
+{
+   int i, port_num;
+   u32 reg, op_regs_base, offset;
+   void __iomem*xhci_regs;
+
+   /* xhci regs is not mapped yet, do it temperary here */
+   if (dwc->xhci_resources[0].start) {
+   xhci_regs = ioremap(dwc->xhci_resources[0].start,
+   DWC3_XHCI_REGS_END);
+   if (IS_ERR(xhci_regs)) {
+   dev_err(dwc->dev, "Failed to ioremap xhci_regs\n");
+   return;
+   }
+
+   op_regs_base = HC_LENGTH(readl(xhci_regs));
+   reg = readl(xhci_regs + XHCI_HCSPARAMS1);
+   port_num = HCS_MAX_PORTS(reg);
+
+   for (i = 1; i <= port_num; i++) {
+   offset = op_regs_base + XHCI_PORTSC_BASE + 0x10*(i-1);
+   reg = readl(xhci_regs + offset);
+   reg &= ~PORT_POWER;
+   writel(reg, xhci_regs + offset);
+   }
+
+   iounmap(xhci_regs);
+   } else
+   dev_err(dwc->dev, "xhci base reg invalid\n");
+}
+
 void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
 {
u32 reg;
@@ -109,6 +144,15 @@ void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode)
reg |= DWC3_GCTL_PRTCAPDIR(mode);
dwc3_writel(dwc->regs, DWC3_GCTL, reg);
 
+   /*
+* We have to power off all Root hub ports immediately after DWC3 set
+* to host mode to avoid VBUS glitch happen when xhci get reset later.
+*/
+   if (dwc->host_vbus_glitches) {
+   if (mode == DWC3_GCTL_PRTCAP_HOST)
+   dwc3_power_off_all_roothub_ports(dwc);
+   }
+
dwc->current_dr_role = mode;
 }
 
@@ -1306,6 +1350,9 @@ static void dwc3_get_properties(struct dwc3 *dwc)
dwc->dis_metastability_quirk = device_property_read_bool(dev,
"snps,dis_metastability_quirk");
 
+   dwc->host_vbus_glitches = device_property_read_bool(dev,
+   "snps,host-vbus-glitches");
+
dwc->lpm_nyet_threshold = lpm_nyet_threshold;
dwc->tx_de_emphasis = tx_de_emphasis;
 
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index df87641..9b3a7ed 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -606,6 +606,14 @@
 #define DWC3_OSTS_VBUSVLD  BIT(1)
 #define DWC3_OSTS_CONIDSTS BIT(0)
 
+/* Partial XHCI Register and Bit fields for quirk */
+#define XHCI_HCSPARAMS10x4
+#define XHCI_PORTSC_BASE   0x400
+#define PORT_POWER (1 << 9)
+#define HCS_MAX_PORTS(p)   (((p) >> 24) & 0x7f)
+#define XHCI_HC_LENGTH(p)  (((p)>>00)&0x00ff)
+#define HC_LENGTH(p)   XHCI_HC_LENGTH(p)
+
 /* Structures */
 
 struct dwc3_trb;
@@ -1024,6 +1032,8 @@ struct dwc3_scratchpad_array {
  * 2   - No de-emphasis
  * 3   - Reserved
  * @dis_metastability_quirk: set to disable metastability quirk.
+ * @host-vbus-glitches: set to avoid vbus glitch during
+ *  xhci reset.
 

[PATCH v2 1/2] usb: dwc3: Add avoiding vbus glitch happen during xhci reset

2019-02-18 Thread Ran Wang
When DWC3 is set to host mode by programming register DWC3_GCTL, VBUS
(or its control signal) will turn on immediately on related Root Hub
ports. Then the VBUS will be de-asserted for a little while during xhci
reset (conducted by xhci driver) for a little while and back to normal.

This VBUS glitch might cause some USB devices emuration fail if kernel
boot with them connected. One SW workaround which can fix this is to
program all PORTSC[PP] to 0 to turn off VBUS immediately after setting
host mode in DWC3 driver(per signal measurement result, it will be too
late to do it in xhci-plat.c or xhci.c).

Signed-off-by: Ran Wang 
---
Changes in v2:
  - Correct typos
  - Shorten the name to snps,host-vbus-glitches

 Documentation/devicetree/bindings/usb/dwc3.txt |3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index 8e5265e..453f562 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -106,6 +106,9 @@ Optional properties:
When just one value, which means INCRX burst mode 
enabled. When
more than one value, which means undefined length INCR 
burst type
enabled. The values can be 1, 4, 8, 16, 32, 64, 128 and 
256.
+ - snps,host-vbus-glitches: Power off all Root Hub ports immediately after
+   setting host mode to avoid vbus (negative) glitch 
happen in later
+   xhci reset. And the vbus will back to 5V automatically 
when reset done.
 
  - in addition all properties from usb-xhci.txt from the current directory are
supported as well
-- 
1.7.1



[PATCH v5 1/6] dt-bindings: usb: musb: Add support for MediaTek musb controller

2019-02-18 Thread min.guo
From: Min Guo 

This adds support for MediaTek musb controller in
host, peripheral and otg mode.

Signed-off-by: Min Guo 
---
changes in v5:
suggested by Rob:
1. Modify compatible as 
- compatible : should be one of:
   "mediatek,mt-2701"
   ...
   followed by "mediatek,mtk-musb"
2. Add usb connector child node

changes in v4:
suggested by Sergei:
1. String alignment

changes in v3:
1. no changes

changes in v2:
suggested by Bin:
1. Modify DRC to DRD
suggested by Rob:
2. Drop the "-musb" in compatible
3. Remove phy-names
4. Add space after comma in clock-names
---
 .../devicetree/bindings/usb/mediatek,musb.txt  | 54 ++
 1 file changed, 54 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/mediatek,musb.txt

diff --git a/Documentation/devicetree/bindings/usb/mediatek,musb.txt 
b/Documentation/devicetree/bindings/usb/mediatek,musb.txt
new file mode 100644
index 000..0632e6e
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/mediatek,musb.txt
@@ -0,0 +1,54 @@
+MediaTek musb DRD/OTG controller
+---
+
+Required properties:
+ - compatible  : should be one of:
+ "mediatek,mt-2701"
+ ...
+ followed by "mediatek,mtk-musb"
+ - reg : specifies physical base address and size of
+ the registers
+ - interrupts  : interrupt used by musb controller
+ - interrupt-names : must be "mc"
+ - phys: PHY specifier for the OTG phy
+ - dr_mode : should be one of "host", "peripheral" or "otg",
+ refer to usb/generic.txt
+ - clocks  : a list of phandle + clock-specifier pairs, one for
+ each entry in clock-names
+ - clock-names : must contain "main", "mcu", "univpll"
+ for clocks of controller
+
+Optional properties:
+ - power-domains   : a phandle to USB power domain node to control USB's
+ MTCMOS
+
+Required child nodes:
+ usb connector node as defined in bindings/connector/usb-connector.txt
+ - extcon  : for VBUS and ID pin changes detection, needed when
+ supports dual-role mode
+ - vbus-supply : reference to the VBUS regulator, needed when supports
+ dual-role mode
+
+Example:
+
+usb2: usb@1120 {
+   compatible = "mediatek,mt2701-musb",
+"mediatek,mtk-musb";
+   reg = <0 0x1120 0 0x1000>;
+   interrupts = ;
+   interrupt-names = "mc";
+   phys = <&u2port2 PHY_TYPE_USB2>;
+   dr_mode = "otg";
+   clocks = <&pericfg CLK_PERI_USB0>,
+<&pericfg CLK_PERI_USB0_MCU>,
+<&pericfg CLK_PERI_USB_SLV>;
+   clock-names = "main","mcu","univpll";
+   power-domains = <&scpsys MT2701_POWER_DOMAIN_IFR_MSC>;
+   usb_con: connector{
+   compatible = "usb-b-connector";
+   label = "micro-USB";
+   type = "micro";
+   extcon = <&extcon_usb>;
+   vbus-supply = <&usb_vbus>;
+   };
+};
-- 
1.9.1



[PATCH v5 0/6] Add MediaTek MUSB Controller Driver

2019-02-18 Thread min.guo
From: Min Guo 

These patches introduce the MediaTek MUSB controller driver.

The driver can be configured as Dual-Role Device (DRD),
Peripheral Only and Host Only modes. This has beed tested on
MT2701 with a variety of devices in host mode and with the 
f_mass gadget driver in peripheral mode, plugging otg cables
in/out a lot of times in all possible imaginable plug orders.

changes in v5:
changes of dt-bindings suggested by Rob:
1. Modify compatible as 
- compatible : should be one of:
   "mediatek,mt-2701"
   ...
   followed by "mediatek,mtk-musb"
2. Add usb connector child node
changes of DTS:
1. Add usb connector child node
changes of driver suggested by Bin:
1. Replace musb_readb() with musb_clearb() to clear dma pending interrupts
2. Replace musb_readb() with musb_clearb() to clear common/tx/rx pending 
interrupts
3. Make musb_clearb/w() return the value of musb_readb/w()

changes in v4:
changes of dt-bindings suggested by Sergei:
1. String alignment
changes of driver suggested by Tony and Bin:
1. Add a new patch for set/get_toggle()
2. Add a new patch for noirq type of dma
3. Add a new patch musb_clearb/w()
4. Abondon patch "usb: musb: Delete the const attribute of addr parameter in 
readb/w/l hooks"

changes in v3:
changes of driver suggested by Bin:
1. Add a new patch for musb_readb/w/l() to remove const attribute 
2. Use is_out as function parameter in set_toggle/get_toggle() hooks
3. Remove 'u8/u16 data' parameter in clearb/w() hooks
4. Remove musb_default_clearb/w()
5. Replace musb_readb/w() with musb_clearb/w() to clear pending interrupts 
6. Add comments to clearb/w() hooks
7. Replace musb_save_toggle() with musb->io.get_toggle()
8. Replace musb_set_toggle() with musb->io.set_toggle()

changes in v2:
changes of dt-bindings suggested by Rob and Bin:
1. Modify DRC to DRD
2. Drop the "-musb" in compatible
3. Remove phy-names
4. Add space after comma in clock-names
dtsi:
1. Remove phy-names
changes of driver suggested by Bin:
1. Add a new patch for musb_set_toggle
2. Add summarize of MediaTek musb controller differences in the commit log
3. Abondon patch "usb: musb: Move musbhsdma macro definition to musb_dma.h"
4. Add "|| COMPILE_TEST" in Kconfig
5. Add musb_clearb() and musb_clearw() hooks
6. Add get_toggle() and set_toggle() hooks
7. Replace musb_readl() with musb_readw() to read 16bit toggle register
8. Move MediaTek's private toggle registers from musb_regs.h to mediatek.c
9. Create musbhs_dma_controller_create_noirq()

Min Guo (6):
  dt-bindings: usb: musb: Add support for MediaTek musb controller
  arm: dts: mt2701: Add usb2 device nodes
  usb: musb: Add get/set toggle hooks
  usb: musb: Add noirq type of dma create interface
  usb: musb: Add musb_clearb/w() interface
  usb: musb: Add support for MediaTek musb controller

 .../devicetree/bindings/usb/mediatek,musb.txt  |  54 ++
 arch/arm/boot/dts/mt2701-evb.dts   |  26 +
 arch/arm/boot/dts/mt2701.dtsi  |  33 ++
 drivers/usb/musb/Kconfig   |   8 +-
 drivers/usb/musb/Makefile  |   1 +
 drivers/usb/musb/mediatek.c| 629 +
 drivers/usb/musb/musb_core.c   |  74 ++-
 drivers/usb/musb/musb_core.h   |  13 +-
 drivers/usb/musb/musb_dma.h|   9 +
 drivers/usb/musb/musb_host.c   |  46 +-
 drivers/usb/musb/musb_io.h |  12 +-
 drivers/usb/musb/musbhsdma.c   |  56 +-
 drivers/usb/musb/sunxi.c   |   4 +-
 drivers/usb/musb/tusb6010.c|   2 +-
 14 files changed, 895 insertions(+), 72 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/usb/mediatek,musb.txt
 create mode 100644 drivers/usb/musb/mediatek.c

-- 
1.9.1



[PATCH v5 2/6] arm: dts: mt2701: Add usb2 device nodes

2019-02-18 Thread min.guo
From: Min Guo 

Add musb nodes and usb2 phy nodes for MT2701

Signed-off-by: Min Guo 
---
changes in v5:
1. Add usb connector child node

changes in v4:
1. no changes

changes in v3:
1. no changes

changes in v2:
1. Remove phy-names
---
 arch/arm/boot/dts/mt2701-evb.dts | 26 ++
 arch/arm/boot/dts/mt2701.dtsi| 33 +
 2 files changed, 59 insertions(+)

diff --git a/arch/arm/boot/dts/mt2701-evb.dts b/arch/arm/boot/dts/mt2701-evb.dts
index be0edb3..95458ea 100644
--- a/arch/arm/boot/dts/mt2701-evb.dts
+++ b/arch/arm/boot/dts/mt2701-evb.dts
@@ -6,6 +6,7 @@
  */
 
 /dts-v1/;
+#include 
 #include "mt2701.dtsi"
 
 / {
@@ -60,6 +61,20 @@
>;
default-brightness-level = <9>;
};
+
+   extcon_usb: extcon_iddig {
+   compatible = "linux,extcon-usb-gpio";
+   id-gpio = <&pio 44 GPIO_ACTIVE_HIGH>;
+   };
+
+   usb_vbus: regulator@0 {
+   compatible = "regulator-fixed";
+   regulator-name = "usb_vbus";
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+   gpio = <&pio 45 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
 };
 
 &auxadc {
@@ -229,3 +244,14 @@
 &uart0 {
status = "okay";
 };
+
+&usb2 {
+   status = "okay";
+   usb_con: connector{
+   compatible = "usb-b-connector";
+   label = "micro-USB";
+   type = "micro";
+   extcon = <&extcon_usb>;
+   vbus-supply = <&usb_vbus>;
+   };
+};
diff --git a/arch/arm/boot/dts/mt2701.dtsi b/arch/arm/boot/dts/mt2701.dtsi
index 180377e..a6b1434 100644
--- a/arch/arm/boot/dts/mt2701.dtsi
+++ b/arch/arm/boot/dts/mt2701.dtsi
@@ -670,6 +670,39 @@
};
};
 
+   usb2: usb@1120 {
+   compatible = "mediatek,mt2701-musb",
+"mediatek,mtk-musb";
+   reg = <0 0x1120 0 0x1000>;
+   interrupts = ;
+   interrupt-names = "mc";
+   phys = <&u2port2 PHY_TYPE_USB2>;
+   dr_mode = "otg";
+   clocks = <&pericfg CLK_PERI_USB0>,
+<&pericfg CLK_PERI_USB0_MCU>,
+<&pericfg CLK_PERI_USB_SLV>;
+   clock-names = "main","mcu","univpll";
+   power-domains = <&scpsys MT2701_POWER_DOMAIN_IFR_MSC>;
+   status = "disabled";
+   };
+
+   u2phy0: usb-phy@1121 {
+   compatible = "mediatek,generic-tphy-v1";
+   reg = <0 0x1121 0 0x0800>;
+   #address-cells = <2>;
+   #size-cells = <2>;
+   ranges;
+   status = "okay";
+
+   u2port2: usb-phy@1a1c4800 {
+   reg = <0 0x11210800 0 0x0100>;
+   clocks = <&topckgen CLK_TOP_USB_PHY48M>;
+   clock-names = "ref";
+   #phy-cells = <1>;
+   status = "okay";
+   };
+   };
+
ethsys: syscon@1b00 {
compatible = "mediatek,mt2701-ethsys", "syscon";
reg = <0 0x1b00 0 0x1000>;
-- 
1.9.1



[PATCH v5 5/6] usb: musb: Add musb_clearb/w() interface

2019-02-18 Thread min.guo
From: Min Guo 

Delete the const attribute of addr parameter in readb/w/l hooks, these
changes are for implementing clearing W1C registers.
Replace musb_readb/w with musb_clearb/w to clear the interrupt status.

Signed-off-by: Min Guo 
---
changes in v5:
1. Replace musb_readb() with musb_clearb() to clear dma pending interrupts

new patch based on v4:
---
 drivers/usb/musb/musb_core.c | 32 +++-
 drivers/usb/musb/musb_core.h |  8 ++--
 drivers/usb/musb/musb_io.h   |  8 +---
 drivers/usb/musb/musbhsdma.c |  2 +-
 drivers/usb/musb/sunxi.c |  4 ++--
 drivers/usb/musb/tusb6010.c  |  2 +-
 6 files changed, 38 insertions(+), 18 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 2fe5225..5ef8848 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -246,7 +246,7 @@ static u32 musb_default_busctl_offset(u8 epnum, u16 offset)
return 0x80 + (0x08 * epnum) + offset;
 }
 
-static u8 musb_default_readb(const void __iomem *addr, unsigned offset)
+static u8 musb_default_readb(void __iomem *addr, unsigned offset)
 {
u8 data =  __raw_readb(addr + offset);
 
@@ -260,7 +260,7 @@ static void musb_default_writeb(void __iomem *addr, 
unsigned offset, u8 data)
__raw_writeb(data, addr + offset);
 }
 
-static u16 musb_default_readw(const void __iomem *addr, unsigned offset)
+static u16 musb_default_readw(void __iomem *addr, unsigned offset)
 {
u16 data = __raw_readw(addr + offset);
 
@@ -396,19 +396,25 @@ static void musb_default_read_fifo(struct musb_hw_ep 
*hw_ep, u16 len, u8 *dst)
 /*
  * Old style IO functions
  */
-u8 (*musb_readb)(const void __iomem *addr, unsigned offset);
+u8 (*musb_readb)(void __iomem *addr, unsigned offset);
 EXPORT_SYMBOL_GPL(musb_readb);
 
 void (*musb_writeb)(void __iomem *addr, unsigned offset, u8 data);
 EXPORT_SYMBOL_GPL(musb_writeb);
 
-u16 (*musb_readw)(const void __iomem *addr, unsigned offset);
+u8 (*musb_clearb)(void __iomem *addr, unsigned int offset);
+EXPORT_SYMBOL_GPL(musb_clearb);
+
+u16 (*musb_readw)(void __iomem *addr, unsigned offset);
 EXPORT_SYMBOL_GPL(musb_readw);
 
 void (*musb_writew)(void __iomem *addr, unsigned offset, u16 data);
 EXPORT_SYMBOL_GPL(musb_writew);
 
-u32 musb_readl(const void __iomem *addr, unsigned offset)
+u16 (*musb_clearw)(void __iomem *addr, unsigned int offset);
+EXPORT_SYMBOL_GPL(musb_clearw);
+
+u32 musb_readl(void __iomem *addr, unsigned offset)
 {
u32 data = __raw_readl(addr + offset);
 
@@ -1047,7 +1053,6 @@ static irqreturn_t musb_stage0_irq(struct musb *musb, u8 
int_usb,
 static void musb_disable_interrupts(struct musb *musb)
 {
void __iomem*mbase = musb->mregs;
-   u16 temp;
 
/* disable interrupts */
musb_writeb(mbase, MUSB_INTRUSBE, 0);
@@ -1057,9 +1062,9 @@ static void musb_disable_interrupts(struct musb *musb)
musb_writew(mbase, MUSB_INTRRXE, 0);
 
/*  flush pending interrupts */
-   temp = musb_readb(mbase, MUSB_INTRUSB);
-   temp = musb_readw(mbase, MUSB_INTRTX);
-   temp = musb_readw(mbase, MUSB_INTRRX);
+   musb_clearb(mbase, MUSB_INTRUSB);
+   musb_clearw(mbase, MUSB_INTRTX);
+   musb_clearw(mbase, MUSB_INTRRX);
 }
 
 static void musb_enable_interrupts(struct musb *musb)
@@ -2284,10 +2289,19 @@ static void musb_deassert_reset(struct work_struct 
*work)
musb_readb = musb->ops->readb;
if (musb->ops->writeb)
musb_writeb = musb->ops->writeb;
+   if (musb->ops->clearb)
+   musb_clearb = musb->ops->clearb;
+   else
+   musb_clearb = musb_readb;
+
if (musb->ops->readw)
musb_readw = musb->ops->readw;
if (musb->ops->writew)
musb_writew = musb->ops->writew;
+   if (musb->ops->clearw)
+   musb_clearw = musb->ops->clearw;
+   else
+   musb_clearw = musb_readw;
 
 #ifndef CONFIG_MUSB_PIO_ONLY
if (!musb->ops->dma_init || !musb->ops->dma_exit) {
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 9f5a69c..0d9a35f 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -120,8 +120,10 @@ enum musb_g_ep0_state {
  * @fifo_offset: returns the fifo offset
  * @readb: read 8 bits
  * @writeb:write 8 bits
+ * @clearb:could be clear-on-readb or W1C
  * @readw: read 16 bits
  * @writew:write 16 bits
+ * @clearw:could be clear-on-readw or W1C
  * @read_fifo: reads the fifo
  * @write_fifo:writes to fifo
  * @get_toggle:platform specific get toggle function
@@ -164,10 +166,12 @@ struct musb_platform_ops {
u16 fifo_mode;
u32 (*fifo_offset)(u8 epnum);
u32 (*busctl_offset)(u8 epnum, u16 offset);
-   u8  (*readb)(const void __iomem *addr, unsigned offset);
+   u8  (*readb)(void __iomem *addr, unsigned offset);
void(*writeb)(void __iomem *addr

[PATCH v5 4/6] usb: musb: Add noirq type of dma create interface

2019-02-18 Thread min.guo
From: Min Guo 

Add noirq type of dma create interface for platform which do not
have dedicated DMA interrupt line, move musbhsdma macro definition
to musb_dma.h

Signed-off-by: Min Guo 
---
changes in v5:
1. no changes

new patch based on v4:
---
 drivers/usb/musb/musb_dma.h  |  9 
 drivers/usb/musb/musbhsdma.c | 54 ++--
 2 files changed, 46 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/musb/musb_dma.h b/drivers/usb/musb/musb_dma.h
index 8f60271..05103ea 100644
--- a/drivers/usb/musb/musb_dma.h
+++ b/drivers/usb/musb/musb_dma.h
@@ -35,6 +35,12 @@
  *whether shared with the Inventra core or separate.
  */
 
+#define MUSB_HSDMA_BASE0x200
+#define MUSB_HSDMA_INTR(MUSB_HSDMA_BASE + 0)
+#define MUSB_HSDMA_CONTROL 0x4
+#define MUSB_HSDMA_ADDRESS 0x8
+#define MUSB_HSDMA_COUNT   0xc
+
 #defineDMA_ADDR_INVALID(~(dma_addr_t)0)
 
 #ifdef CONFIG_MUSB_PIO_ONLY
@@ -191,6 +197,9 @@ static inline void musb_dma_controller_destroy(struct 
dma_controller *d) { }
 extern struct dma_controller *
 musbhs_dma_controller_create(struct musb *musb, void __iomem *base);
 extern void musbhs_dma_controller_destroy(struct dma_controller *c);
+extern struct dma_controller *
+musbhs_dma_controller_create_noirq(struct musb *musb, void __iomem *base);
+extern irqreturn_t dma_controller_irq(int irq, void *private_data);
 
 extern struct dma_controller *
 tusb_dma_controller_create(struct musb *musb, void __iomem *base);
diff --git a/drivers/usb/musb/musbhsdma.c b/drivers/usb/musb/musbhsdma.c
index a688f7f..b2394a7 100644
--- a/drivers/usb/musb/musbhsdma.c
+++ b/drivers/usb/musb/musbhsdma.c
@@ -10,12 +10,7 @@
 #include 
 #include 
 #include "musb_core.h"
-
-#define MUSB_HSDMA_BASE0x200
-#define MUSB_HSDMA_INTR(MUSB_HSDMA_BASE + 0)
-#define MUSB_HSDMA_CONTROL 0x4
-#define MUSB_HSDMA_ADDRESS 0x8
-#define MUSB_HSDMA_COUNT   0xc
+#include "musb_dma.h"
 
 #define MUSB_HSDMA_CHANNEL_OFFSET(_bchannel, _offset)  \
(MUSB_HSDMA_BASE + (_bchannel << 4) + _offset)
@@ -268,7 +263,7 @@ static int dma_channel_abort(struct dma_channel *channel)
return 0;
 }
 
-static irqreturn_t dma_controller_irq(int irq, void *private_data)
+irqreturn_t dma_controller_irq(int irq, void *private_data)
 {
struct musb_dma_controller *controller = private_data;
struct musb *musb = controller->private_data;
@@ -382,6 +377,7 @@ static irqreturn_t dma_controller_irq(int irq, void 
*private_data)
spin_unlock_irqrestore(&musb->lock, flags);
return retval;
 }
+EXPORT_SYMBOL_GPL(dma_controller_irq);
 
 void musbhs_dma_controller_destroy(struct dma_controller *c)
 {
@@ -397,18 +393,10 @@ void musbhs_dma_controller_destroy(struct dma_controller 
*c)
 }
 EXPORT_SYMBOL_GPL(musbhs_dma_controller_destroy);
 
-struct dma_controller *musbhs_dma_controller_create(struct musb *musb,
-   void __iomem *base)
+static struct musb_dma_controller *
+dma_controller_alloc(struct musb *musb, void __iomem *base)
 {
struct musb_dma_controller *controller;
-   struct device *dev = musb->controller;
-   struct platform_device *pdev = to_platform_device(dev);
-   int irq = platform_get_irq_byname(pdev, "dma");
-
-   if (irq <= 0) {
-   dev_err(dev, "No DMA interrupt line!\n");
-   return NULL;
-   }
 
controller = kzalloc(sizeof(*controller), GFP_KERNEL);
if (!controller)
@@ -422,6 +410,25 @@ struct dma_controller *musbhs_dma_controller_create(struct 
musb *musb,
controller->controller.channel_release = dma_channel_release;
controller->controller.channel_program = dma_channel_program;
controller->controller.channel_abort = dma_channel_abort;
+   return controller;
+}
+
+struct dma_controller *
+musbhs_dma_controller_create(struct musb *musb, void __iomem *base)
+{
+   struct musb_dma_controller *controller;
+   struct device *dev = musb->controller;
+   struct platform_device *pdev = to_platform_device(dev);
+   int irq = platform_get_irq_byname(pdev, "dma");
+
+   if (irq <= 0) {
+   dev_err(dev, "No DMA interrupt line!\n");
+   return NULL;
+   }
+
+   controller = dma_controller_alloc(musb, base);
+   if (!controller)
+   return NULL;
 
if (request_irq(irq, dma_controller_irq, 0,
dev_name(musb->controller), &controller->controller)) {
@@ -436,3 +443,16 @@ struct dma_controller *musbhs_dma_controller_create(struct 
musb *musb,
return &controller->controller;
 }
 EXPORT_SYMBOL_GPL(musbhs_dma_controller_create);
+
+struct dma_controller *
+musbhs_dma_controller_create_noirq(struct musb *musb, void __iomem *base)
+{
+   struct musb_dma_controller *controller;
+
+   controller =

[PATCH v5 6/6] usb: musb: Add support for MediaTek musb controller

2019-02-18 Thread min.guo
From: Min Guo 

This adds support for MediaTek musb controller in
host, peripheral and otg mode.
There are some quirk of MediaTek musb controller, such as:
 -W1C interrupt status registers
 -Private data toggle registers
 -No dedicated DMA interrupt line

Signed-off-by: Min Guo 
Signed-off-by: Yonglong Wu 
---
changes in v5:
1. Replace musb_readb() with musb_clearb() to clear common/tx/rx pending 
interrupts
2. Make musb_clearb/w() return the value of musb_readb/w()
3. Add driver to get child nodes of usb connector and extcon device

changes in v4:
1. no changes

changes in v3:
suggested by Bin:
1. Remove 'u8/u16 data' parameter in clearb/w() hooks
2. Replace musb_readb/w() with musb_clearb/w() to clear interrupts status

changes in v2:
suggested by Bin:
1. Add summarize of MediaTek musb controller differences in the commit log
2. Add "|| COMPILE_TEST" in Kconfig
3. Move MediaTek's private toggle registers from musb_regs.h to mediatek.c
4. Replace musb_readl() with musb_readw() to read 16bit toggle register
---
 drivers/usb/musb/Kconfig|   8 +-
 drivers/usb/musb/Makefile   |   1 +
 drivers/usb/musb/mediatek.c | 629 
 3 files changed, 637 insertions(+), 1 deletion(-)
 create mode 100644 drivers/usb/musb/mediatek.c

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index ad08895..b72b7c1 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -115,6 +115,12 @@ config USB_MUSB_JZ4740
depends on USB_MUSB_GADGET
depends on USB_OTG_BLACKLIST_HUB
 
+config USB_MUSB_MEDIATEK
+   tristate "MediaTek platforms"
+   depends on ARCH_MEDIATEK || COMPILE_TEST
+   depends on NOP_USB_XCEIV
+   depends on GENERIC_PHY
+
 config USB_MUSB_AM335X_CHILD
tristate
 
@@ -141,7 +147,7 @@ config USB_UX500_DMA
 
 config USB_INVENTRA_DMA
bool 'Inventra'
-   depends on USB_MUSB_OMAP2PLUS
+   depends on USB_MUSB_OMAP2PLUS || USB_MUSB_MEDIATEK
help
  Enable DMA transfers using Mentor's engine.
 
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index 3a88c79..63d82d0 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX)  += da8xx.o
 obj-$(CONFIG_USB_MUSB_UX500)   += ux500.o
 obj-$(CONFIG_USB_MUSB_JZ4740)  += jz4740.o
 obj-$(CONFIG_USB_MUSB_SUNXI)   += sunxi.o
+obj-$(CONFIG_USB_MUSB_MEDIATEK)+= mediatek.o
 
 
 obj-$(CONFIG_USB_MUSB_AM335X_CHILD)+= musb_am335x.o
diff --git a/drivers/usb/musb/mediatek.c b/drivers/usb/musb/mediatek.c
new file mode 100644
index 000..946b453
--- /dev/null
+++ b/drivers/usb/musb/mediatek.c
@@ -0,0 +1,629 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2018 MediaTek Inc.
+ *
+ * Author:
+ *  Min Guo 
+ *  Yonglong Wu 
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include "musb_core.h"
+#include "musb_dma.h"
+
+#define USB_L1INTS 0x00a0
+#define USB_L1INTM 0x00a4
+#define MTK_MUSB_TXFUNCADDR0x0480
+
+/* MediaTek controller toggle enable and status reg */
+#define MUSB_RXTOG 0x80
+#define MUSB_RXTOGEN   0x82
+#define MUSB_TXTOG 0x84
+#define MUSB_TXTOGEN   0x86
+
+#define TX_INT_STATUS  BIT(0)
+#define RX_INT_STATUS  BIT(1)
+#define USBCOM_INT_STATUS  BIT(2)
+#define DMA_INT_STATUS BIT(3)
+
+#define DMA_INTR_STATUS_MSKGENMASK(7, 0)
+#define DMA_INTR_UNMASK_SET_MSKGENMASK(31, 24)
+
+enum mtk_vbus_id_state {
+   MTK_ID_FLOAT = 1,
+   MTK_ID_GROUND,
+   MTK_VBUS_OFF,
+   MTK_VBUS_VALID,
+};
+
+struct mtk_glue {
+   struct device *dev;
+   struct musb *musb;
+   struct platform_device *musb_pdev;
+   struct platform_device *usb_phy;
+   struct phy *phy;
+   struct usb_phy *xceiv;
+   enum phy_mode phy_mode;
+   struct clk *main;
+   struct clk *mcu;
+   struct clk *univpll;
+   struct regulator *vbus;
+   struct extcon_dev *edev;
+   struct notifier_block vbus_nb;
+   struct notifier_block id_nb;
+};
+
+static int mtk_musb_clks_get(struct mtk_glue *glue)
+{
+   struct device *dev = glue->dev;
+
+   glue->main = devm_clk_get(dev, "main");
+   if (IS_ERR(glue->main)) {
+   dev_err(dev, "fail to get main clock\n");
+   return PTR_ERR(glue->main);
+   }
+
+   glue->mcu = devm_clk_get(dev, "mcu");
+   if (IS_ERR(glue->mcu)) {
+   dev_err(dev, "fail to get mcu clock\n");
+   return PTR_ERR(glue->mcu);
+   }
+
+   glue->univpll = devm_clk_get(dev, "univpll");
+   if (IS_ERR(glue->univpll)) {
+   dev_err(dev, "fail to get univpll clock\n");
+   return PTR_ERR(glue->univpll);
+   }
+
+   return 0;
+}
+
+static int mtk_musb_clks_enable(struct mtk_glue *glue)
+{
+   int ret;
+
+

[PATCH v5 3/6] usb: musb: Add get/set toggle hooks

2019-02-18 Thread min.guo
From: Min Guo 

Add get/set toggle hooks in struct musb_io and struct musb_platform_ops
for special platform; remove function musb_save_toggle, use the set/get
callback to handle toggle.

Signed-off-by: Min Guo 
---
changes in v5:
1. no changes

new patch based on v4:
---
 drivers/usb/musb/musb_core.c | 42 
 drivers/usb/musb/musb_core.h |  5 +
 drivers/usb/musb/musb_host.c | 46 ++--
 drivers/usb/musb/musb_io.h   |  4 
 4 files changed, 61 insertions(+), 36 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index b7d5627..2fe5225 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -274,6 +274,38 @@ static void musb_default_writew(void __iomem *addr, 
unsigned offset, u16 data)
__raw_writew(data, addr + offset);
 }
 
+static u16 musb_default_get_toggle(struct musb_qh *qh, int is_out)
+{
+   void __iomem *epio = qh->hw_ep->regs;
+   u16 csr;
+
+   if (is_out)
+   csr = musb_readw(epio, MUSB_TXCSR) & MUSB_TXCSR_H_DATATOGGLE;
+   else
+   csr = musb_readw(epio, MUSB_RXCSR) & MUSB_RXCSR_H_DATATOGGLE;
+
+   return csr;
+}
+
+static u16 musb_default_set_toggle(struct musb_qh *qh, int is_out,
+  struct urb *urb)
+{
+   u16 csr;
+   u16 toggle;
+
+   toggle = usb_gettoggle(urb->dev, qh->epnum, is_out);
+
+   if (is_out)
+   csr = toggle ? (MUSB_TXCSR_H_WR_DATATOGGLE
+   | MUSB_TXCSR_H_DATATOGGLE)
+   : MUSB_TXCSR_CLRDATATOG;
+   else
+   csr = toggle ? (MUSB_RXCSR_H_WR_DATATOGGLE
+   | MUSB_RXCSR_H_DATATOGGLE) : 0;
+
+   return csr;
+}
+
 /*
  * Load an endpoint's FIFO
  */
@@ -2277,6 +2309,16 @@ static void musb_deassert_reset(struct work_struct *work)
else
musb->io.write_fifo = musb_default_write_fifo;
 
+   if (musb->ops->get_toggle)
+   musb->io.get_toggle = musb->ops->get_toggle;
+   else
+   musb->io.get_toggle = musb_default_get_toggle;
+
+   if (musb->ops->set_toggle)
+   musb->io.set_toggle = musb->ops->set_toggle;
+   else
+   musb->io.set_toggle = musb_default_set_toggle;
+
if (!musb->xceiv->io_ops) {
musb->xceiv->io_dev = musb->controller;
musb->xceiv->io_priv = musb->mregs;
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 04203b7..9f5a69c 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -27,6 +27,7 @@
 struct musb;
 struct musb_hw_ep;
 struct musb_ep;
+struct musb_qh;
 
 /* Helper defines for struct musb->hwvers */
 #define MUSB_HWVERS_MAJOR(x)   ((x >> 10) & 0x1f)
@@ -123,6 +124,8 @@ enum musb_g_ep0_state {
  * @writew:write 16 bits
  * @read_fifo: reads the fifo
  * @write_fifo:writes to fifo
+ * @get_toggle:platform specific get toggle function
+ * @set_toggle:platform specific set toggle function
  * @dma_init:  platform specific dma init function
  * @dma_exit:  platform specific dma exit function
  * @init:  turns on clocks, sets up platform-specific registers, etc
@@ -167,6 +170,8 @@ struct musb_platform_ops {
void(*writew)(void __iomem *addr, unsigned offset, u16 data);
void(*read_fifo)(struct musb_hw_ep *hw_ep, u16 len, u8 *buf);
void(*write_fifo)(struct musb_hw_ep *hw_ep, u16 len, const u8 *buf);
+   u16 (*get_toggle)(struct musb_qh *qh, int is_out);
+   u16 (*set_toggle)(struct musb_qh *qh, int is_out, struct urb *urb);
struct dma_controller *
(*dma_init) (struct musb *musb, void __iomem *base);
void(*dma_exit)(struct dma_controller *c);
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index b59ce9a..b97fbf9 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -286,26 +286,6 @@ static void musb_giveback(struct musb *musb, struct urb 
*urb, int status)
spin_lock(&musb->lock);
 }
 
-/* For bulk/interrupt endpoints only */
-static inline void musb_save_toggle(struct musb_qh *qh, int is_in,
-   struct urb *urb)
-{
-   void __iomem*epio = qh->hw_ep->regs;
-   u16 csr;
-
-   /*
-* FIXME: the current Mentor DMA code seems to have
-* problems getting toggle correct.
-*/
-
-   if (is_in)
-   csr = musb_readw(epio, MUSB_RXCSR) & MUSB_RXCSR_H_DATATOGGLE;
-   else
-   csr = musb_readw(epio, MUSB_TXCSR) & MUSB_TXCSR_H_DATATOGGLE;
-
-   usb_settoggle(urb->dev, qh->epnum, !is_in, csr ? 1 : 0);
-}
-
 /*
  * Advance this hardware endpoint's queue, completing the specified URB and
  * advancing to either the next URB queued to that qh, or else invalidatin

Re: [PATCH -next] usb: typec: mux: Fix unsigned comparison with less than zero

2019-02-18 Thread Heikki Krogerus
On Tue, Feb 19, 2019 at 02:57:50PM +0800, YueHaibing wrote:
> The return from the call to fwnode_property_read_u16_array is int, 
> it can be a negative error code however this is being assigned to
> an size_t variable 'nval', hence the check is always false.
> Fix this by making 'nval' an int.
> 
> Detected by Coccinelle ("Unsigned expression compared with
> zero: nval < 0")
> 
> Fixes: 96a6d031ca99 ("usb: typec: mux: Find the muxes by also matching 
> against the device node")
> Signed-off-by: YueHaibing 

Acked-by: Heikki Krogerus 

> ---
>  drivers/usb/typec/mux.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/typec/mux.c b/drivers/usb/typec/mux.c
> index a5947d9..54d7497 100644
> --- a/drivers/usb/typec/mux.c
> +++ b/drivers/usb/typec/mux.c
> @@ -126,7 +126,7 @@ static void *typec_mux_match(struct device_connection 
> *con, int ep, void *data)
>  {
>   const struct typec_altmode_desc *desc = data;
>   struct typec_mux *mux;
> - size_t nval;
> + int nval;
>   bool match;
>   u16 *val;
>   int i;

thanks,

-- 
heikki