[PATCH 2/2] USB: EHCI: merge all cases that disable the IO watchdog

2016-10-22 Thread Lucas Stach
This merges the vendor NEC case with the INTEL and AMD one,
as those 3 do exactly the same thing: disabling of the IO
watchdog.

Signed-off-by: Lucas Stach 
---
v2: New patch in v2.
---
 drivers/usb/host/ehci-pci.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 0ed683c..9332697 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -258,8 +258,6 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
/* These workarounds need to be applied after ehci_setup() */
switch (pdev->vendor) {
case PCI_VENDOR_ID_NEC:
-   ehci->need_io_watchdog = 0;
-   break;
case PCI_VENDOR_ID_INTEL:
case PCI_VENDOR_ID_AMD:
ehci->need_io_watchdog = 0;
-- 
2.7.4

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


[PATCH 1/2] USB: EHCI: elide I/O watchdog on AMD parts

2016-10-22 Thread Lucas Stach
This removes 10 timer wakeups per second. I'm running this patch for
a while now and haven't spotted any adverse effects.

Signed-off-by: Lucas Stach 
---
v2: Merge vendor AMD case with vendor Intel case, as requested by
Alan Stern.
---
 drivers/usb/host/ehci-pci.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/host/ehci-pci.c b/drivers/usb/host/ehci-pci.c
index 3b3649d..0ed683c 100644
--- a/drivers/usb/host/ehci-pci.c
+++ b/drivers/usb/host/ehci-pci.c
@@ -261,6 +261,7 @@ static int ehci_pci_setup(struct usb_hcd *hcd)
ehci->need_io_watchdog = 0;
break;
case PCI_VENDOR_ID_INTEL:
+   case PCI_VENDOR_ID_AMD:
ehci->need_io_watchdog = 0;
break;
case PCI_VENDOR_ID_NVIDIA:
-- 
2.7.4

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


[PATCH v2 4/4] USB: ch341: add debug output for chip version

2016-10-22 Thread Aidan Thornton
Will probably be helpful if there are any more compatibility issues.

Signed-off-by: Aidan Thornton 
---
 drivers/usb/serial/ch341.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index af9edbe..2597b83 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -212,6 +212,7 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
r = ch341_control_in(dev, CH341_REQ_READ_VERSION, 0, 0, buffer, size);
if (r < 0)
goto out;
+   dev_dbg(>dev, "Chip version: 0x%02x\n", buffer[0]);
 
r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0, 0);
if (r < 0)
-- 
2.10.1

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


[PATCH v2 3/4] USB: ch341: add support for parity, frame length, stop bits

2016-10-22 Thread Aidan Thornton
With the new reinitialization method, configuring parity, different
frame lengths and different stop bit settings should work as expected
on both CH340G and CH341A. Tested on a loopback-connected CH340G
with a logic analyzer in a number of different configurations.

Based on a patch by Grigori Goronzy

Signed-off-by: Aidan Thornton 
---
 drivers/usb/serial/ch341.c | 32 ++--
 1 file changed, 26 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index 096bc07..af9edbe 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -356,8 +356,33 @@ static void ch341_set_termios(struct tty_struct *tty,
baud_rate = tty_get_baud_rate(tty);
 
priv->baud_rate = baud_rate;
+   ctrl = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX;
 
-   ctrl = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX | CH341_LCR_CS8;
+   switch (C_CSIZE(tty)) {
+   case CS5:
+   ctrl |= CH341_LCR_CS5;
+   break;
+   case CS6:
+   ctrl |= CH341_LCR_CS6;
+   break;
+   case CS7:
+   ctrl |= CH341_LCR_CS7;
+   break;
+   case CS8:
+   ctrl |= CH341_LCR_CS8;
+   break;
+   }
+
+   if (C_PARENB(tty)) {
+   ctrl |= CH341_LCR_ENABLE_PAR;
+   if (C_PARODD(tty) == 0)
+   ctrl |= CH341_LCR_PAR_EVEN;
+   if (C_CMSPAR(tty))
+   ctrl |= CH341_LCR_MARK_SPACE;
+   }
+
+   if (C_CSTOPB(tty))
+   ctrl |= CH341_LCR_STOP_BITS_2;
 
if (baud_rate) {
spin_lock_irqsave(>lock, flags);
@@ -376,11 +401,6 @@ static void ch341_set_termios(struct tty_struct *tty,
 
ch341_set_handshake(port->serial->dev, priv->line_control);
 
-   /* Unimplemented:
-* (cflag & CSIZE) : data bits [5, 8]
-* (cflag & PARENB) : parity {NONE, EVEN, ODD}
-* (cflag & CSTOPB) : stop bits [1, 2]
-*/
 }
 
 static void ch341_break_ctl(struct tty_struct *tty, int break_state)
-- 
2.10.1

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


[PATCH v2 2/4] USB: ch341: reinitialize chip on reconfiguration

2016-10-22 Thread Aidan Thornton
Changing the LCR register after initialization does not seem to be reliable
on all chips (particularly not on CH341A). Restructure initialization and
configuration to always reinit the chip on configuration changes instead and
pass the LCR register value directly to the initialization command.

(Note that baud rates above 500kbaud are incorrect, but they're incorrect in
the same way both before and after this patch at least on the CH340G. Fixing
this isn't a priority as higher baud rates don't seem that reliable anyway.)

Cleaned-up version of a patch by Grigori Goronzy

Signed-off-by: Aidan Thornton 
---
 drivers/usb/serial/ch341.c | 37 -
 1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index bdf525f..096bc07 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -132,10 +132,10 @@ static int ch341_control_in(struct usb_device *dev,
return r;
 }
 
-static int ch341_set_baudrate(struct usb_device *dev,
- struct ch341_private *priv)
+static int ch341_init_set_baudrate(struct usb_device *dev,
+  struct ch341_private *priv, unsigned ctrl)
 {
-   short a, b;
+   short a;
int r;
unsigned long factor;
short divisor;
@@ -155,11 +155,10 @@ static int ch341_set_baudrate(struct usb_device *dev,
 
factor = 0x1 - factor;
a = (factor & 0xff00) | divisor;
-   b = factor & 0xff;
 
-   r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, a);
-   if (!r)
-   r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x0f2c, b);
+   /* 0x9c is "enable SFR_UART Control register and timer" */
+   r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT,
+ 0x9c | (ctrl << 8), a | 0x80);
 
return r;
 }
@@ -218,10 +217,6 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
if (r < 0)
goto out;
 
-   r = ch341_set_baudrate(dev, priv);
-   if (r < 0)
-   goto out;
-
/* expect two bytes 0x56 0x00 */
r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x2518, 0, buffer, size);
if (r < 0)
@@ -236,11 +231,7 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
if (r < 0)
goto out;
 
-   r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0x501f, 0xd90a);
-   if (r < 0)
-   goto out;
-
-   r = ch341_set_baudrate(dev, priv);
+   r = ch341_init_set_baudrate(dev, priv, 0);
if (r < 0)
goto out;
 
@@ -355,16 +346,28 @@ static void ch341_set_termios(struct tty_struct *tty,
struct ch341_private *priv = usb_get_serial_port_data(port);
unsigned baud_rate;
unsigned long flags;
+   unsigned char ctrl;
+   int r;
+
+   /* redundant changes may cause the chip to lose bytes */
+   if (old_termios && !tty_termios_hw_change(>termios, old_termios))
+   return;
 
baud_rate = tty_get_baud_rate(tty);
 
priv->baud_rate = baud_rate;
 
+   ctrl = CH341_LCR_ENABLE_RX | CH341_LCR_ENABLE_TX | CH341_LCR_CS8;
+
if (baud_rate) {
spin_lock_irqsave(>lock, flags);
priv->line_control |= (CH341_BIT_DTR | CH341_BIT_RTS);
spin_unlock_irqrestore(>lock, flags);
-   ch341_set_baudrate(port->serial->dev, priv);
+   r = ch341_init_set_baudrate(port->serial->dev, priv, ctrl);
+   if (r < 0 && old_termios) {
+   priv->baud_rate = tty_termios_baud_rate(old_termios);
+   tty_termios_copy_hw(>termios, old_termios);
+   }
} else {
spin_lock_irqsave(>lock, flags);
priv->line_control &= ~(CH341_BIT_DTR | CH341_BIT_RTS);
-- 
2.10.1

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


[PATCH v2 0/4] ch341 cleanup and parity etc support

2016-10-22 Thread Aidan Thornton
This is an attempt to clean-up and resubmit some patches by Grigori
Goronzy a few months back adding support for parity, frame length, and
2 stop bits to the CH340/1 driver and cleaning up some magic constants.
His later patches (for RTS/CTS hardware flow and other things) are not
included in this series due to not having a way to test them.

Tested on the CH340G, previous version also tested on CH341A by Grigori

v2: clean up formatting, remove unnecessary change to init sequence

Aidan Thornton (4):
  USB: ch341: add register and USB request definitions
  USB: ch341: reinitialize chip on reconfiguration
  USB: ch341: add support for parity, frame length, stop bits
  USB: ch341: add debug output for chip version

 drivers/usb/serial/ch341.c | 113 ++---
 1 file changed, 75 insertions(+), 38 deletions(-)

-- 
2.10.1

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


[PATCH v2 1/4] USB: ch341: add register and USB request definitions

2016-10-22 Thread Aidan Thornton
No functional changes, this just gives names to some registers and USB
requests based on Grigori Goronzy's work and WinChipTech's Linux driver
(which reassuringly agree), then uses them in place of magic numbers.
This also renames the misnamed BREAK2 register (actually UART config)

Signed-off-by: Aidan Thornton 
---
 drivers/usb/serial/ch341.c | 51 +-
 1 file changed, 32 insertions(+), 19 deletions(-)

diff --git a/drivers/usb/serial/ch341.c b/drivers/usb/serial/ch341.c
index f139488..bdf525f 100644
--- a/drivers/usb/serial/ch341.c
+++ b/drivers/usb/serial/ch341.c
@@ -61,13 +61,26 @@
  * the Net/FreeBSD uchcom.c driver by Takanori Watanabe.  Domo arigato.
  */
 
+#define CH341_REQ_READ_VERSION 0x5F
 #define CH341_REQ_WRITE_REG0x9A
 #define CH341_REQ_READ_REG 0x95
-#define CH341_REG_BREAK1   0x05
-#define CH341_REG_BREAK2   0x18
-#define CH341_NBREAK_BITS_REG1 0x01
-#define CH341_NBREAK_BITS_REG2 0x40
-
+#define CH341_REQ_SERIAL_INIT  0xA1
+#define CH341_REQ_MODEM_CTRL   0xA4
+
+#define CH341_REG_BREAK0x05
+#define CH341_REG_LCR  0x18
+#define CH341_NBREAK_BITS  0x01
+
+#define CH341_LCR_ENABLE_RX0x80
+#define CH341_LCR_ENABLE_TX0x40
+#define CH341_LCR_MARK_SPACE   0x20
+#define CH341_LCR_PAR_EVEN 0x10
+#define CH341_LCR_ENABLE_PAR   0x08
+#define CH341_LCR_STOP_BITS_2  0x04
+#define CH341_LCR_CS8  0x03
+#define CH341_LCR_CS7  0x02
+#define CH341_LCR_CS6  0x01
+#define CH341_LCR_CS5  0x00
 
 static const struct usb_device_id id_table[] = {
{ USB_DEVICE(0x4348, 0x5523) },
@@ -144,16 +157,16 @@ static int ch341_set_baudrate(struct usb_device *dev,
a = (factor & 0xff00) | divisor;
b = factor & 0xff;
 
-   r = ch341_control_out(dev, 0x9a, 0x1312, a);
+   r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x1312, a);
if (!r)
-   r = ch341_control_out(dev, 0x9a, 0x0f2c, b);
+   r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x0f2c, b);
 
return r;
 }
 
 static int ch341_set_handshake(struct usb_device *dev, u8 control)
 {
-   return ch341_control_out(dev, 0xa4, ~control, 0);
+   return ch341_control_out(dev, CH341_REQ_MODEM_CTRL, ~control, 0);
 }
 
 static int ch341_get_status(struct usb_device *dev, struct ch341_private *priv)
@@ -167,7 +180,7 @@ static int ch341_get_status(struct usb_device *dev, struct 
ch341_private *priv)
if (!buffer)
return -ENOMEM;
 
-   r = ch341_control_in(dev, 0x95, 0x0706, 0, buffer, size);
+   r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x0706, 0, buffer, size);
if (r < 0)
goto out;
 
@@ -197,11 +210,11 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
return -ENOMEM;
 
/* expect two bytes 0x27 0x00 */
-   r = ch341_control_in(dev, 0x5f, 0, 0, buffer, size);
+   r = ch341_control_in(dev, CH341_REQ_READ_VERSION, 0, 0, buffer, size);
if (r < 0)
goto out;
 
-   r = ch341_control_out(dev, 0xa1, 0, 0);
+   r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0, 0);
if (r < 0)
goto out;
 
@@ -210,11 +223,11 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
goto out;
 
/* expect two bytes 0x56 0x00 */
-   r = ch341_control_in(dev, 0x95, 0x2518, 0, buffer, size);
+   r = ch341_control_in(dev, CH341_REQ_READ_REG, 0x2518, 0, buffer, size);
if (r < 0)
goto out;
 
-   r = ch341_control_out(dev, 0x9a, 0x2518, 0x0050);
+   r = ch341_control_out(dev, CH341_REQ_WRITE_REG, 0x2518, 0x0050);
if (r < 0)
goto out;
 
@@ -223,7 +236,7 @@ static int ch341_configure(struct usb_device *dev, struct 
ch341_private *priv)
if (r < 0)
goto out;
 
-   r = ch341_control_out(dev, 0xa1, 0x501f, 0xd90a);
+   r = ch341_control_out(dev, CH341_REQ_SERIAL_INIT, 0x501f, 0xd90a);
if (r < 0)
goto out;
 
@@ -370,7 +383,7 @@ static void ch341_set_termios(struct tty_struct *tty,
 static void ch341_break_ctl(struct tty_struct *tty, int break_state)
 {
const uint16_t ch341_break_reg =
-   ((uint16_t) CH341_REG_BREAK2 << 8) | CH341_REG_BREAK1;
+   ((uint16_t) CH341_REG_LCR << 8) | CH341_REG_BREAK;
struct usb_serial_port *port = tty->driver_data;
int r;
uint16_t reg_contents;
@@ -391,12 +404,12 @@ static void ch341_break_ctl(struct tty_struct *tty, int 
break_state)
__func__, break_reg[0], break_reg[1]);
if (break_state != 0) {
dev_dbg(>dev, "%s - Enter break state requested\n", 
__func__);
-   break_reg[0] &= ~CH341_NBREAK_BITS_REG1;
-   break_reg[1] &= ~CH341_NBREAK_BITS_REG2;
+   break_reg[0] &= ~CH341_NBREAK_BITS;
+

Re: [PATCH 2/4] USB: ch341: reinitialize chip on reconfiguration

2016-10-22 Thread Johan Hovold
On Sat, Oct 22, 2016 at 03:24:56PM +0100, Aidan Thornton wrote:
> On 19 Oct 2016 09:42, "Johan Hovold"  wrote:
> >
> > On Wed, Oct 19, 2016 at 09:26:39AM +0200, Grigori Goronzy wrote:
> > > So let's just undo the change to the initialization sequence and get
> > > this merged.  Then we can tune or simplify the init sequence in the next
> > > series.  That is the process you propose, right?
> >
> > Yes. That LCR write could either stay or be removed completely from this
> > series, and then the rest can be cleaned up through follow-ons using the
> > vendor driver as inspiration.
> 
> OK, guess I'll submit a version of the patch series which doesn't change
> that LCR write since it doesn't have any obvious detrimental effect and the
> init sequence will probably want cleaning up later anyway, unless you have
> any objections. Probably later today, sorry for the delay.

Sounds good to me.

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


Re: [GIT PULL] USB-serial fixes for v4.9-rc2

2016-10-22 Thread Greg Kroah-Hartman
On Fri, Oct 21, 2016 at 05:04:06PM +0200, Johan Hovold wrote:
> Hi Greg,
> 
> Here are some fixes for 4.9-rc2. Details below.
> 
> Thanks,
> Johan
> 
> 
> The following changes since commit 1001354ca34179f3db924eb66672442a173147dc:
> 
>   Linux 4.9-rc1 (2016-10-15 12:17:50 -0700)
> 
> are available in the git repository at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/johan/usb-serial.git 
> tags/usb-serial-4.9-rc2

Pulled and pushed out, thanks.

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


Re: [PATCH 2/2] USB: UHCI: report non-PME wakeup signalling for Intel hardware

2016-10-22 Thread Greg KH
On Fri, Oct 21, 2016 at 04:49:07PM -0400, Alan Stern wrote:
> The UHCI controllers in Intel chipsets rely on a platform-specific
> non-PME mechanism for wakeup signalling.  They can generate wakeup
> signals even though they don't support PME.
> 
> We need to let the USB core know this so that it will enable runtime
> suspend for UHCI controllers.
> 
> Signed-off-by: Alan Stern 
> CC: 
> 
> ---
> 
> Greg:
> 
> This patch is somewhat independent of the 1/2 patch I sent to Bjorn.  
> Still, it will help to keep them together.  Is it okay to have him
> merge both of them through his tree?

Fine with me:

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


RE: [RESEND PATCH] usb: chipidea: Configure DMA properties and ops from DT

2016-10-22 Thread Sriram Dash
>From: Stephen Boyd [mailto:sb...@codeaurora.org]
>On 10/21, Bjorn Andersson wrote:
>> hcd_alloc_coherent() and usb_alloc_coherent() ends up allocating
>> coherent memory on behalf of ci_hdrc driver. But as the ci_hdrc is
>> instantiated manually it will not have any dma_mem or dma_ops
>> assigned, which makes the
>> dma_alloc_coherent() fail on some platforms (e.g. arm64). This patch
>> solves this by assigning the dma_mem and dma_ops based on the parent's
>> DeviceTree node.
>>
>> Cc: Stephen Boyd 
>> Signed-off-by: Bjorn Andersson 
>> ---
>>
>> Hi Peter,
>>
>> After (once more) debugging why USB doesn't work up on the 64-bit
>> Qualcomm systems I realized that we never concluded on this patch.
>> Unfortunately I can't find it in my mailbox either, so resending it to 
>> restart the
>discussion.
>>
>
>I thought we were going to go down the route that Arnd has been pushing[1]? 
>That
>should work, but I haven't tried it yet and there are some more fixes on top 
>from
>Sriram. I think Sriram is taking over the patch now?
>

Yes Stephen. I am incorporating the idea from Arnd and working on those patches.

Regards,
Sriram

>[1] https://patchwork.kernel.org/patch/9319527/
>
>--
>Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux
>Foundation Collaborative Project
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html