RE: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller Interface driver (tcpci)

2016-09-30 Thread Jun Li
Hi,
> -Original Message-
> From: Guenter Roeck [mailto:gro...@google.com]
> Sent: Saturday, October 01, 2016 2:45 AM
> To: Jun Li 
> Cc: Guenter Roeck ; Felipe Balbi
> ; Chandra Sekhar Anagani
> ; Bruce Ashfield
> ; Bin Gao ; Pranav Tipnis
> ; Heikki Krogerus
> ; linux-ker...@vger.kernel.org; linux-
> u...@vger.kernel.org
> Subject: Re: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller
> Interface driver (tcpci)
> 
> On Thu, Sep 29, 2016 at 11:24 PM, Jun Li  wrote:
> > Hi Guenter,
> >
> >> -Original Message-
> >> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> >> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
> >> Sent: Wednesday, August 24, 2016 5:11 AM
> >> To: Felipe Balbi 
> >> Cc: Chandra Sekhar Anagani ; Bruce
> >> Ashfield ; Bin Gao ;
> >> Pranav Tipnis ; Heikki Krogerus
> >> ; linux-ker...@vger.kernel.org;
> >> linux- u...@vger.kernel.org; Guenter Roeck 
> >> Subject: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller
> >> Interface driver (tcpci)
> >>
> >> The port controller interface driver interconnects the Type-C Port
> >> Manager with a Type-C Port Controller Interface (TCPCI) compliant port
> controller.
> >>
> >> Signed-off-by: Guenter Roeck 
> >> ---
> >> v3:
> >> - No change
> >>
> >> v2:
> >> - Adjust to modified callbacks into tcpm code
> >>
> >>  drivers/usb/typec/Kconfig  |   9 +
> >>  drivers/usb/typec/Makefile |   1 +
> >>  drivers/usb/typec/tcpci.c  | 487
> >> +
> >>  drivers/usb/typec/tcpci.h  | 133 +
> >>  4 files changed, 630 insertions(+)
> >>  create mode 100644 drivers/usb/typec/tcpci.c  create mode 100644
> >> drivers/usb/typec/tcpci.h
> >>
> >> diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig
> >> index
> >> 113bb1b3589c..a92c9d1a3e00 100644
> >> --- a/drivers/usb/typec/Kconfig
> >> +++ b/drivers/usb/typec/Kconfig
> >> @@ -25,4 +25,13 @@ config TYPEC_TCPM
> >> The Type-C Port Controller Manager provides a USB PD and USB
> Type-C
> >> state machine for use with Type-C Port Controllers.
> >>
> >> +if TYPEC_TCPM
> >> +
> >> +config TYPEC_TCPCI
> >> + tristate "Type-C Port Controller Interface driver"
> >> + help
> >> +   Type-C Port Controller driver for TCPCI-compliant controller.
> >> +
> >> +endif
> >> +
> >>  endmenu
> >> diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile
> >> index bbe45721cf52..7dbaf8c3911d 100644
> >> --- a/drivers/usb/typec/Makefile
> >> +++ b/drivers/usb/typec/Makefile
> >> @@ -1,3 +1,4 @@
> >>  obj-$(CONFIG_TYPEC)  += typec.o
> >>  obj-$(CONFIG_TYPEC_WCOVE)+= typec_wcove.o
> >>  obj-$(CONFIG_TYPEC_TCPM) += tcpm.o
> >> +obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o
> >> diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c
> >> new file mode 100644 index ..af338218a1f3
> >> --- /dev/null
> >> +++ b/drivers/usb/typec/tcpci.c
> >> @@ -0,0 +1,487 @@
> >> +/*
> >> + * Copyright 2015-2016 Google, Inc
> >> + *
> >> + * This program is free software; you can redistribute it and/or
> >> +modify
> >> + * it under the terms of the GNU General Public License as published
> >> +by
> >> + * the Free Software Foundation; either version 2 of the License, or
> >> + * (at your option) any later version.
> >> + *
> >> + * This program is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> + * GNU General Public License for more details.
> >> + *
> >> + * USB Type-C Port Controller Interface.
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#include "tcpci.h"
> >> +#include "tcpm.h"
> >> +
> >> +#define PD_RETRY_COUNT 3
> >> +
> >> +struct tcpci {
> >> + struct device *dev;
> >> + struct i2c_client *client;
> >> +
> >> + struct tcpm_port *port;
> >> +
> >> + struct regmap *regmap;
> >> +
> >> + bool controls_vbus;
> >> +
> >> + struct tcpc_dev tcpc;
> >> +};
> >> +
> >> +static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) {
> >> + return container_of(tcpc, struct tcpci, tcpc); }
> >> +
> >> +static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
> >> + unsigned int *val) {
> >> + return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); }
> >> +
> >> +static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16
> >> +val) 

Re: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Guenter Roeck
On Fri, Sep 30, 2016 at 12:41 PM, Joe Perches  wrote:
> On Fri, 2016-09-30 at 12:06 -0700, Guenter Roeck wrote:
>> On Thu, Sep 29, 2016 at 11:37 PM, Jun Li  wrote:
> []
>> > diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> []
>> > +#define PDO_VAR(min_mv, max_mv, max_ma)   
>> >\
>> > + ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) | \
>> > +  min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) <<  \
>> > +   PDO_VAR_MIN_VOLT_SHIFT) | \
>> > +  max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) <<  \
>> > +   PDO_VAR_MAX_VOLT_SHIFT) | \
>> > +  max_ma) / 50) & PDO_VAR_MAX_CURR_MASK) <<  \
>>
>>
>> max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) <<  \
>
> This would be easier to read if laid out differently.
>
> #define PDO_VAR(min_mv, max_mv, max_ma)   
>   \
> ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) |   
>   \
>  min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) << 
> PDO_VAR_MIN_VOLT_SHIFT) |\
>  max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) << 
> PDO_VAR_MAX_VOLT_SHIFT) |\
>  max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) << 
> PDO_VAR_MAX_CURR_SHIFT))
>

Code now looks as follows.

#define PDO_VAR_MIN_VOLT(mv) mv) / 50) & PDO_VAR_MIN_VOLT_MASK) << \
  PDO_VAR_MIN_VOLT_SHIFT)
#define PDO_VAR_MAX_VOLT(mv) mv) / 50) & PDO_VAR_MAX_VOLT_MASK) << \
  PDO_VAR_MAX_VOLT_SHIFT)
#define PDO_VAR_MAX_CURR(ma) ma) / 10) & PDO_VAR_MAX_CURR_MASK) << \
  PDO_VAR_MAX_CURR_SHIFT)

#define PDO_VAR(min_mv, max_mv, max_ma) \
(PDO_TYPE(PDO_TYPE_VAR) | PDO_VAR_MIN_VOLT(min_mv) |\
 PDO_VAR_MAX_VOLT(max_mv) | PDO_VAR_MAX_CURR(max_ma))

Though maybe I should just ignore line length limits or use shorter defines.

Guenter
--
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: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Joe Perches
On Fri, 2016-09-30 at 12:06 -0700, Guenter Roeck wrote:
> On Thu, Sep 29, 2016 at 11:37 PM, Jun Li  wrote:
[]
> > diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
[]
> > +#define PDO_VAR(min_mv, max_mv, max_ma)
> >   \
> > + ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) | \
> > +  min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) <<  \
> > +   PDO_VAR_MIN_VOLT_SHIFT) | \
> > +  max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) <<  \
> > +   PDO_VAR_MAX_VOLT_SHIFT) | \
> > +  max_ma) / 50) & PDO_VAR_MAX_CURR_MASK) <<  \
> 
> 
> max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) <<  \

This would be easier to read if laid out differently.

#define PDO_VAR(min_mv, max_mv, max_ma) 
\
((PDO_TYPE_VAR << PDO_TYPE_SHIFT) | 
\
 min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) << PDO_VAR_MIN_VOLT_SHIFT) 
|\
 max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) << PDO_VAR_MAX_VOLT_SHIFT) 
|\
 max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) << PDO_VAR_MAX_CURR_SHIFT))

--
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: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Guenter Roeck
On Thu, Sep 29, 2016 at 11:37 PM, Jun Li  wrote:
> Hi Guenter,
>> -Original Message-
>> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
>> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
>> Sent: Wednesday, August 24, 2016 5:11 AM
>> To: Felipe Balbi 
>> Cc: Chandra Sekhar Anagani ; Bruce
>> Ashfield ; Bin Gao ;
>> Pranav Tipnis ; Heikki Krogerus
>> ; linux-ker...@vger.kernel.org; linux-
>> u...@vger.kernel.org; Guenter Roeck 
>> Subject: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)
>>
> ...
>> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
>> new file mode 100644
>> index ..6b1679af7a25
>> --- /dev/null
>> +++ b/include/linux/usb/pd.h
>
> ...
>
>> +#define PDO_VAR(min_mv, max_mv, max_ma) 
>>  \
>> + ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) | \
>> +  min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) <<  \
>> +   PDO_VAR_MIN_VOLT_SHIFT) | \
>> +  max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) <<  \
>> +   PDO_VAR_MAX_VOLT_SHIFT) | \
>> +  max_ma) / 50) & PDO_VAR_MAX_CURR_MASK) <<  \
>
> max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) <<  \
>

Thanks, fixed. PDO_BATT has a similar problem, which I noticed while
fixing the above.

Guenter
--
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/3] Revert "usb: dwc2: gadget: change variable name to more meaningful"

2016-09-30 Thread John Youn
This reverts commit ba48eab8866c ("usb: dwc2: gadget: change variable
name to more meaningful").

This is needed to cleanly revert commit aa381a7259c3 ("usb: dwc2:
gadget: fix TX FIFO size and address initialization") which may cause
regressions on some platforms.

Signed-off-by: John Youn 
Cc: Robert Baldyga 
Cc: Stefan Wahren 
---
 drivers/usb/dwc2/gadget.c | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 4cd6403..aac4af3 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -186,7 +186,7 @@ static void dwc2_hsotg_ctrl_epint(struct dwc2_hsotg *hsotg,
  */
 static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
 {
-   unsigned int fifo;
+   unsigned int ep;
unsigned int addr;
int timeout;
u32 dptxfsizn;
@@ -217,8 +217,8 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
 * them to endpoints dynamically according to maxpacket size value of
 * given endpoint.
 */
-   for (fifo = 1; fifo < MAX_EPS_CHANNELS; fifo++) {
-   dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(fifo));
+   for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
+   dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(ep));
 
val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr;
addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT;
@@ -226,7 +226,7 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
if (addr > hsotg->fifo_mem)
break;
 
-   dwc2_writel(val, hsotg->regs + DPTXFSIZN(fifo));
+   dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
}
 
/*
-- 
2.10.0

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


[PATCH 2/3] Revert "usb: dwc2: gadget: fix TX FIFO size and address initialization"

2016-09-30 Thread John Youn
This reverts commit aa381a7259c3 ("usb: dwc2: gadget: fix TX FIFO size
and address initialization").

The original commit removed the FIFO size programming per endpoint. The
DPTXFSIZn register is also used for DIEPTXFn and the SIZE field is r/w
in dedicated fifo mode. So it isn't appropriate to simply remove this
initialization as it might break existing behavior.

Also, some cores might not have enough fifo space to handle the
programming method used in the reverted patch, resulting in fifo
initialization failure.

Signed-off-by: John Youn 
Cc: Robert Baldyga 
Cc: Stefan Wahren 
---
 drivers/usb/dwc2/core.h   |  7 +++
 drivers/usb/dwc2/gadget.c | 47 +++
 2 files changed, 46 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index aad4107..2a21a04 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -259,6 +259,13 @@ enum dwc2_lx_state {
DWC2_L3,/* Off state */
 };
 
+/*
+ * Gadget periodic tx fifo sizes as used by legacy driver
+ * EP0 is not included
+ */
+#define DWC2_G_P_LEGACY_TX_FIFO_SIZE {256, 256, 256, 256, 768, 768, 768, \
+  768, 0, 0, 0, 0, 0, 0, 0}
+
 /* Gadget ep0 states */
 enum dwc2_ep0_state {
DWC2_EP0_SETUP,
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index aac4af3..24fbebc 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -189,7 +189,6 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
unsigned int ep;
unsigned int addr;
int timeout;
-   u32 dptxfsizn;
u32 val;
 
/* Reset fifo map if not correctly cleared during previous session */
@@ -218,13 +217,13 @@ static void dwc2_hsotg_init_fifo(struct dwc2_hsotg *hsotg)
 * given endpoint.
 */
for (ep = 1; ep < MAX_EPS_CHANNELS; ep++) {
-   dptxfsizn = dwc2_readl(hsotg->regs + DPTXFSIZN(ep));
-
-   val = (dptxfsizn & FIFOSIZE_DEPTH_MASK) | addr;
-   addr += dptxfsizn >> FIFOSIZE_DEPTH_SHIFT;
-
-   if (addr > hsotg->fifo_mem)
-   break;
+   if (!hsotg->g_tx_fifo_sz[ep])
+   continue;
+   val = addr;
+   val |= hsotg->g_tx_fifo_sz[ep] << FIFOSIZE_DEPTH_SHIFT;
+   WARN_ONCE(addr + hsotg->g_tx_fifo_sz[ep] > hsotg->fifo_mem,
+ "insufficient fifo memory");
+   addr += hsotg->g_tx_fifo_sz[ep];
 
dwc2_writel(val, hsotg->regs + DPTXFSIZN(ep));
}
@@ -3807,10 +3806,36 @@ static void dwc2_hsotg_dump(struct dwc2_hsotg *hsotg)
 static void dwc2_hsotg_of_probe(struct dwc2_hsotg *hsotg)
 {
struct device_node *np = hsotg->dev->of_node;
+   u32 len = 0;
+   u32 i = 0;
 
/* Enable dma if requested in device tree */
hsotg->g_using_dma = of_property_read_bool(np, "g-use-dma");
 
+   /*
+   * Register TX periodic fifo size per endpoint.
+   * EP0 is excluded since it has no fifo configuration.
+   */
+   if (!of_find_property(np, "g-tx-fifo-size", ))
+   goto rx_fifo;
+
+   len /= sizeof(u32);
+
+   /* Read tx fifo sizes other than ep0 */
+   if (of_property_read_u32_array(np, "g-tx-fifo-size",
+   >g_tx_fifo_sz[1], len))
+   goto rx_fifo;
+
+   /* Add ep0 */
+   len++;
+
+   /* Make remaining TX fifos unavailable */
+   if (len < MAX_EPS_CHANNELS) {
+   for (i = len; i < MAX_EPS_CHANNELS; i++)
+   hsotg->g_tx_fifo_sz[i] = 0;
+   }
+
+rx_fifo:
/* Register RX fifo size */
of_property_read_u32(np, "g-rx-fifo-size", >g_rx_fifo_sz);
 
@@ -3832,10 +3857,13 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
struct device *dev = hsotg->dev;
int epnum;
int ret;
+   int i;
+   u32 p_tx_fifo[] = DWC2_G_P_LEGACY_TX_FIFO_SIZE;
 
/* Initialize to legacy fifo configuration values */
hsotg->g_rx_fifo_sz = 2048;
hsotg->g_np_g_tx_fifo_sz = 1024;
+   memcpy(>g_tx_fifo_sz[1], p_tx_fifo, sizeof(p_tx_fifo));
/* Device tree specific probe */
dwc2_hsotg_of_probe(hsotg);
 
@@ -3853,6 +3881,9 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
dev_dbg(dev, "NonPeriodic TXFIFO size: %d\n",
hsotg->g_np_g_tx_fifo_sz);
dev_dbg(dev, "RXFIFO size: %d\n", hsotg->g_rx_fifo_sz);
+   for (i = 0; i < MAX_EPS_CHANNELS; i++)
+   dev_dbg(dev, "Periodic TXFIFO%2d size: %d\n", i,
+   hsotg->g_tx_fifo_sz[i]);
 
hsotg->gadget.max_speed = USB_SPEED_HIGH;
hsotg->gadget.ops = _hsotg_gadget_ops;
-- 
2.10.0

--
To unsubscribe from this 

[PATCH 3/3] Revert "Documentation: devicetree: dwc2: Deprecate g-tx-fifo-size"

2016-09-30 Thread John Youn
This binding was deprecated due to commit aa381a7259c3 ("usb: dwc2:
gadget: fix TX FIFO size and address initialization"). However that
commit is now reverted, so also revert this commit.

The binding is valid and shouldn't be deprecated.

This reverts commit 65e1ff7f4b5b ("Documentation: devicetree: dwc2:
Deprecate g-tx-fifo-size").

Signed-off-by: John Youn 
---
 Documentation/devicetree/bindings/usb/dwc2.txt | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc2.txt 
b/Documentation/devicetree/bindings/usb/dwc2.txt
index 7d16ebf..20a68bf 100644
--- a/Documentation/devicetree/bindings/usb/dwc2.txt
+++ b/Documentation/devicetree/bindings/usb/dwc2.txt
@@ -26,10 +26,7 @@ Refer to phy/phy-bindings.txt for generic phy consumer 
properties
 - g-use-dma: enable dma usage in gadget driver.
 - g-rx-fifo-size: size of rx fifo size in gadget mode.
 - g-np-tx-fifo-size: size of non-periodic tx fifo size in gadget mode.
-
-Deprecated properties:
-- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0)
-  in gadget mode.
+- g-tx-fifo-size: size of periodic tx fifo per endpoint (except ep0) in gadget 
mode.
 
 Example:
 
-- 
2.10.0

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


Re: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller Interface driver (tcpci)

2016-09-30 Thread Guenter Roeck
On Thu, Sep 29, 2016 at 11:24 PM, Jun Li  wrote:
> Hi Guenter,
>
>> -Original Message-
>> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
>> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
>> Sent: Wednesday, August 24, 2016 5:11 AM
>> To: Felipe Balbi 
>> Cc: Chandra Sekhar Anagani ; Bruce
>> Ashfield ; Bin Gao ;
>> Pranav Tipnis ; Heikki Krogerus
>> ; linux-ker...@vger.kernel.org; linux-
>> u...@vger.kernel.org; Guenter Roeck 
>> Subject: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller Interface
>> driver (tcpci)
>>
>> The port controller interface driver interconnects the Type-C Port Manager
>> with a Type-C Port Controller Interface (TCPCI) compliant port controller.
>>
>> Signed-off-by: Guenter Roeck 
>> ---
>> v3:
>> - No change
>>
>> v2:
>> - Adjust to modified callbacks into tcpm code
>>
>>  drivers/usb/typec/Kconfig  |   9 +
>>  drivers/usb/typec/Makefile |   1 +
>>  drivers/usb/typec/tcpci.c  | 487
>> +
>>  drivers/usb/typec/tcpci.h  | 133 +
>>  4 files changed, 630 insertions(+)
>>  create mode 100644 drivers/usb/typec/tcpci.c  create mode 100644
>> drivers/usb/typec/tcpci.h
>>
>> diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig index
>> 113bb1b3589c..a92c9d1a3e00 100644
>> --- a/drivers/usb/typec/Kconfig
>> +++ b/drivers/usb/typec/Kconfig
>> @@ -25,4 +25,13 @@ config TYPEC_TCPM
>> The Type-C Port Controller Manager provides a USB PD and USB Type-C
>> state machine for use with Type-C Port Controllers.
>>
>> +if TYPEC_TCPM
>> +
>> +config TYPEC_TCPCI
>> + tristate "Type-C Port Controller Interface driver"
>> + help
>> +   Type-C Port Controller driver for TCPCI-compliant controller.
>> +
>> +endif
>> +
>>  endmenu
>> diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index
>> bbe45721cf52..7dbaf8c3911d 100644
>> --- a/drivers/usb/typec/Makefile
>> +++ b/drivers/usb/typec/Makefile
>> @@ -1,3 +1,4 @@
>>  obj-$(CONFIG_TYPEC)  += typec.o
>>  obj-$(CONFIG_TYPEC_WCOVE)+= typec_wcove.o
>>  obj-$(CONFIG_TYPEC_TCPM) += tcpm.o
>> +obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o
>> diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c new
>> file mode 100644 index ..af338218a1f3
>> --- /dev/null
>> +++ b/drivers/usb/typec/tcpci.c
>> @@ -0,0 +1,487 @@
>> +/*
>> + * Copyright 2015-2016 Google, Inc
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License as published by
>> + * the Free Software Foundation; either version 2 of the License, or
>> + * (at your option) any later version.
>> + *
>> + * This program is distributed in the hope that it will be useful,
>> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>> + * GNU General Public License for more details.
>> + *
>> + * USB Type-C Port Controller Interface.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#include "tcpci.h"
>> +#include "tcpm.h"
>> +
>> +#define PD_RETRY_COUNT 3
>> +
>> +struct tcpci {
>> + struct device *dev;
>> + struct i2c_client *client;
>> +
>> + struct tcpm_port *port;
>> +
>> + struct regmap *regmap;
>> +
>> + bool controls_vbus;
>> +
>> + struct tcpc_dev tcpc;
>> +};
>> +
>> +static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) {
>> + return container_of(tcpc, struct tcpci, tcpc); }
>> +
>> +static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
>> + unsigned int *val)
>> +{
>> + return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); }
>> +
>> +static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16
>> +val) {
>> + return regmap_raw_write(tcpci->regmap, reg, , sizeof(u16)); }
>> +
>> +static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
>> +{
>> + struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
>> + unsigned int reg;
>> + int ret;
>> +
>> + switch (cc) {
>> + case TYPEC_CC_RA:
>> + reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) |
>> + (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
>> + break;
>> + case TYPEC_CC_RD:
>> + reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
>> + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
>> + break;
>> + case TYPEC_CC_RP_DEF:
>> + reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
>> + (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
>> +  

[PATCH 0/2] Fixes for two more musb regressions

2016-09-30 Thread Tony Lindgren
Hi all,

Looks like we have two more regressions caused by my attempts
to make musb PM simpler. As it's very close to the merge window
opening, these are against current Linux next.

Once reviewed, tested and merged to the mainline kernel we can
request these to be included also into v4.8.y kernel. Maybe Bin
can tag these as cc stable v4.8 already when applying.

Regards,

Tony

Tony Lindgren (2):
  usb: musb: Fix hardirq-safe hardirq-unsafe lock order error
  usb: musb: Call pm_runtime from musb_gadget_queue

 drivers/usb/musb/musb_gadget.c | 4 
 drivers/usb/musb/omap2430.c| 7 ++-
 2 files changed, 6 insertions(+), 5 deletions(-)

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


[PATCH 2/2] usb: musb: Call pm_runtime from musb_gadget_queue

2016-09-30 Thread Tony Lindgren
If we're booting pandaboard using NFSroot over built-in g_ether, we
can get the following after booting once and doing a warm reset:

g_ether gadget: ecm_open
g_ether gadget: notify connect true
...
WARNING: CPU: 0 PID: 1 at drivers/bus/omap_l3_noc.c:147
l3_interrupt_handler+0x220/0x34c
4400.ocp:L3 Custom Error: MASTER MPU TARGET L4CFG (Read):
Data Access in User mode du ring Functional access
...

Fix the issue by calling pm_runtime functions from
musb_gadget_queue.

Note that in the long run we should be able to queue the pending
transfers if pm_runtime is not active, and flush the queue from
pm_runtime_resume.

Reported-by: Laurent Pinchart 
Tested-by: Laurent Pinchart 
Signed-off-by: Tony Lindgren 
---
 drivers/usb/musb/musb_gadget.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -1255,6 +1255,7 @@ static int musb_gadget_queue(struct usb_ep *ep, struct 
usb_request *req,
 
map_dma_buffer(request, musb, musb_ep);
 
+   pm_runtime_get_sync(musb->controller);
spin_lock_irqsave(>lock, lockflags);
 
/* don't queue if the ep is down */
@@ -1275,6 +1276,9 @@ static int musb_gadget_queue(struct usb_ep *ep, struct 
usb_request *req,
 
 unlock:
spin_unlock_irqrestore(>lock, lockflags);
+   pm_runtime_mark_last_busy(musb->controller);
+   pm_runtime_put_autosuspend(musb->controller);
+
return status;
 }
 
-- 
2.9.3
--
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: musb: Fix hardirq-safe hardirq-unsafe lock order error

2016-09-30 Thread Tony Lindgren
If we configure musb with 2430 glue as a peripheral, and then rmmod
omap2430 module, we'll get the following error:

[ INFO: HARDIRQ-safe -> HARDIRQ-unsafe lock order detected ]
...
rmmod/413 [HC0[0]:SC0[0]:HE0:SE1] is trying to acquire:
 (>mutex){+.+.+.}, at: [] phy_power_off+0x1c/0xb8
[  204.678710]
   and this task is already holding:
 (&(>lock)->rlock){-.-...}, at: []
 musb_gadget_stop+0x24/0xec [musb_hdrc]
which would create a new lock dependency:
 (&(>lock)->rlock){-.-...} -> (>mutex){+.+.+.}
...

This is because some glue layers expect musb_platform_enable/disable
to be called with spinlock held, and 2430 glue layer has USB PHY on
the I2C bus using a mutex.

We could fix the glue layers to take the spinlock, but we still have
a problem of musb_plaform_enable/disable being called in an unbalanced
manner. So that would still lead into USB PHY enable/disable related
problems for omap2430 glue layer.

While it makes sense to only enable USB PHY when needed from PM point
of view, in this case we just can't do it yet without breaking things.
So let's just revert phy_enable/disable related changes instead and
reconsider this after we have fixed musb_platform_enable/disable to
be balanced.

Fixes: a83e17d0f73b ("usb: musb: Improve PM runtime and phy handling
for 2430 glue layer")
Signed-off-by: Tony Lindgren 
---
 drivers/usb/musb/omap2430.c | 7 ++-
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/musb/omap2430.c b/drivers/usb/musb/omap2430.c
--- a/drivers/usb/musb/omap2430.c
+++ b/drivers/usb/musb/omap2430.c
@@ -287,6 +287,7 @@ static int omap2430_musb_init(struct musb *musb)
}
musb->isr = omap2430_musb_interrupt;
phy_init(musb->phy);
+   phy_power_on(musb->phy);
 
l = musb_readl(musb->mregs, OTG_INTERFSEL);
 
@@ -323,8 +324,6 @@ static void omap2430_musb_enable(struct musb *musb)
struct musb_hdrc_platform_data *pdata = dev_get_platdata(dev);
struct omap_musb_board_data *data = pdata->board_data;
 
-   if (!WARN_ON(!musb->phy))
-   phy_power_on(musb->phy);
 
switch (glue->status) {
 
@@ -361,9 +360,6 @@ static void omap2430_musb_disable(struct musb *musb)
struct device *dev = musb->controller;
struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
 
-   if (!WARN_ON(!musb->phy))
-   phy_power_off(musb->phy);
-
if (glue->status != MUSB_UNKNOWN)
omap_control_usb_set_mode(glue->control_otghs,
USB_MODE_DISCONNECT);
@@ -375,6 +371,7 @@ static int omap2430_musb_exit(struct musb *musb)
struct omap2430_glue *glue = dev_get_drvdata(dev->parent);
 
omap2430_low_level_exit(musb);
+   phy_power_off(musb->phy);
phy_exit(musb->phy);
musb->phy = NULL;
cancel_work_sync(>omap_musb_mailbox_work);
-- 
2.9.3
--
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: [PATCHv2] usb: musb: Fix unbalanced platform_disable

2016-09-30 Thread Tony Lindgren
* Laurent Pinchart  [160929 02:38]:
> Hi Tony,
> 
> On Wednesday 28 Sep 2016 11:42:35 Tony Lindgren wrote:
> > * Tony Lindgren  [160920 11:37]:
> > > * Tony Lindgren  [160920 10:11]:
> > >> * Laurent Pinchart  [160919 23:36]:
> > >>> No, I perform the following steps:
> > >>> 
> > >>> - Connect the panda board to the USB through USB (which powers the
> > >>> board on) - Let the board boot over NFS
> > >>> - Log in as root, run 'reboot'
> > >>> 
> > >>> The second boot produces the warning.
> > >> 
> > >> Oh I was looking at the errors while shutting down things.. OK yeah I
> > >> get that too along with a bunch of DSS related warnings with your
> > >> .config. Probably I did not notice it earlier because of the DSS
> > >> warnings. Will take a look.
> > > 
> > > The patch below fixes the issue for me, care to give it a try?
> > > 
> > > If that works for you I'll repost with a proper patch description.
> > 
> > Laurent, any news on when you may be able to test this one?
> 
> I just did and your patch fixes the problem for me, thanks.
> 
> Tested-by: Laurent Pinchart 

OK thanks for testing, will send out the two pending fixes today.

Regards,

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


[PATCH] usb: fix a typo in usb_class_driver documentation

2016-09-30 Thread Amitesh Singh
replace usb_unregister_dev by usb_deregister_dev

Signed-off-by: Amitesh Singh 
---
 include/linux/usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/usb.h b/include/linux/usb.h
index eba1f10..7e68259 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1160,7 +1160,7 @@ extern struct bus_type usb_bus_type;
  * @minor_base: the start of the minor range for this driver.
  *
  * This structure is used for the usb_register_dev() and
- * usb_unregister_dev() functions, to consolidate a number of the
+ * usb_deregister_dev() functions, to consolidate a number of the
  * parameters used for them.
  */
 struct usb_class_driver {
-- 
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] usb: fix a typo in usb_class_driver documentation

2016-09-30 Thread Amitesh Singh
replace usb_unregister_dev by usb_deregister_dev

Signed-off-by: Amitesh Singh 
---
 include/linux/usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/linux/usb.h b/include/linux/usb.h
index eba1f10..7e68259 100644
--- a/include/linux/usb.h
+++ b/include/linux/usb.h
@@ -1160,7 +1160,7 @@ extern struct bus_type usb_bus_type;
  * @minor_base: the start of the minor range for this driver.
  *
  * This structure is used for the usb_register_dev() and
- * usb_unregister_dev() functions, to consolidate a number of the
+ * usb_deregister_dev() functions, to consolidate a number of the
  * parameters used for them.
  */
 struct usb_class_driver {
-- 
2.7.4

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


Re: [PATCH] ARM64: dts: meson-gxbb-odroidc2: Enable USB Nodes

2016-09-30 Thread Kevin Hilman
Brian Kim  writes:

> Enable both gxbb USB controller and add a 5V regulator for the OTG port
> VBUS
>
> Signed-off-by: Brian Kim 

Thanks for the patch.

In the future, please state what branch the patch should apply to when
not using mainline.  Because of the sd_emmc nodes in your patch, I could
tell that it was based on my integ branch so was able to figure it out,
but it's very helpful to maintainers if you state the branch and/or any
dependencies explicity.

> ---
>  .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 29 
> ++
>  1 file changed, 29 insertions(+)
>
> diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts 
> b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
> index 8d89edc..997c671 100644
> --- a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
> +++ b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
> @@ -64,6 +64,18 @@
>   reg = <0x0 0x0 0x0 0x8000>;
>   };
>  
> + usb_pwr: regulator-usb-pwrs {

minor nit: since this is specific to the OTG part, can you call this
usb_otg_pwr? ...

> + compatible = "regulator-fixed";
> +
> + regulator-name = "USB_PWR";

... and rename this also?

> + regulator-min-microvolt = <500>;
> + regulator-max-microvolt = <500>;
> +
> + gpio = <_ao GPIOAO_5 GPIO_ACTIVE_HIGH>;
> + enable-active-high;
> + };
> +

Thanks

Kevin
--
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: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Guenter Roeck
On Thu, Sep 29, 2016 at 11:41 PM, Jun Li  wrote:
> Hi,
>
>> -Original Message-
>> From: Guenter Roeck [mailto:gro...@google.com]
>> Sent: Friday, September 30, 2016 12:37 AM
>> To: Jun Li 
>> Cc: Guenter Roeck ; Felipe Balbi
>> ; Chandra Sekhar Anagani
>> ; Bruce Ashfield
>> ; Bin Gao ; Pranav Tipnis
>> ; Heikki Krogerus
>> ; linux-ker...@vger.kernel.org; linux-
>> u...@vger.kernel.org
>> Subject: Re: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)
>>
>> On Thu, Sep 29, 2016 at 7:35 AM, Jun Li  wrote:
>> > Hi Guenter,
>> >
>> >> -Original Message-
>> >> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
>> >> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
>> >> Sent: Wednesday, August 24, 2016 5:11 AM
>> >> To: Felipe Balbi 
>> >> Cc: Chandra Sekhar Anagani ; Bruce
>> >> Ashfield ; Bin Gao ;
>> >> Pranav Tipnis ; Heikki Krogerus
>> >> ; linux-ker...@vger.kernel.org;
>> >> linux- u...@vger.kernel.org; Guenter Roeck 
>> >> Subject: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager
>> >> (tcpm)
>> >>
>> >> This driver implements the USB Type-C Power Delivery state machine
>> >> for both source and sink ports. Alternate mode support is not fully
>> >> implemented.
>> >>
>> >> The driver attaches to the USB Type-C class code implemented in the
>> >> following patches.
>> >>
>> >>   usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
>> >>   usb: USB Type-C connector class
>> >>
>> >> This driver only implements the state machine. Lower level drivers
>> >> are responsible for
>> >> - Reporting VBUS status and activating VBUS
>> >> - Setting CC lines and providing CC line status
>> >> - Setting line polarity
>> >> - Activating and deactivating VCONN
>> >> - Setting the current limit
>> >> - Activating and deactivating PD message transfers
>> >> - Sending and receiving PD messages
>> >>
>> >> The driver provides both a functional API as well as callbacks for
>> >> lower level drivers.
>> >>
>> >> Signed-off-by: Guenter Roeck 
>> >> ---
>> >> v3:
>> >> - Improve TCPM state machine resiliency if there are spurious CC line
>> >> changes
>> >>   while the state machine is in a transient change (waiting for a
>> >> timeout)
>> >> - Update current limit after CC voltage level changes on a port which
>> >> is not
>> >>   PD capable.
>> >>
>> >> v2:
>> >> - Only update polarity if setting it was successful
>> >>   If setting the CC line polarity in the driver was not successful,
>> >>   don't update the internal polarity state.
>> >> - All PD messages are little endian; convert to and from CPU endianness.
>> >> - Avoid comparisons against NULL.
>> >> - Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
>> >> - Callbacks into tcpm need to be lockless to avoid timing problems
>> >>   in low level drivers.
>> >> - Simplify callbacks; tcpm can request the current state of cc/vbus
>> >>   when it is ready to use it.
>> >>
>> >>  drivers/usb/typec/Kconfig  |7 +
>> >>  drivers/usb/typec/Makefile |1 +
>> >>  drivers/usb/typec/tcpm.c   | 3163
>> >> 
>> >>  drivers/usb/typec/tcpm.h   |  137 ++
>> >>  include/linux/usb/pd.h |  282 
>> >>  include/linux/usb/pd_bdo.h |   31 +
>> >>  include/linux/usb/pd_vdo.h |  412 ++
>> >>  7 files changed, 4033 insertions(+)
>> >>  create mode 100644 drivers/usb/typec/tcpm.c  create mode 100644
>> >> drivers/usb/typec/tcpm.h  create mode 100644 include/linux/usb/pd.h
>> >> create mode 100644 include/linux/usb/pd_bdo.h  create mode 100644
>> >> include/linux/usb/pd_vdo.h
>> >>
>> >
>> > ...
>> >
>> >> +
>> >> +static void run_state_machine(struct tcpm_port *port) {
>> >> + int ret;
>> >> +
>> >> + port->enter_state = port->state;
>> >> + switch (port->state) {
>> >> + /* SRC states */
>> >> + case SRC_UNATTACHED:
>> >> + tcpm_swap_complete(port, -ENOTCONN);
>> >> + tcpm_src_detach(port);
>> >> + tcpm_set_cc(port, TYPEC_CC_RP_DEF);
>> >> + if (port->typec_caps.type == TYPEC_PORT_DRP)
>> >> + tcpm_set_state(port, SNK_UNATTACHED,
>> >> + PD_T_DRP_SNK);
>> >
>> > With this and below, after disconnect, the DRP port state machine will
>> > be in infinite loop of state transition between SRC_UNATTACHED <-->
>> > SNK_UNATTACHED, correct?
>> >
>>
>> Only while disconnected. It tries to alternatively connect as source and
>> as sink (being configured as DRP). Once a CC line state change is reported
>> it will transition out. I have a 

[PATCH] USB: serial: ftdi_sio: add support for Infineon TriBoard TC2X7

2016-09-30 Thread Stefan Tauner
Signed-off-by: Stefan Tauner 
---
 drivers/usb/serial/ftdi_sio.c | 3 ++-
 drivers/usb/serial/ftdi_sio_ids.h | 5 +++--
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/serial/ftdi_sio.c b/drivers/usb/serial/ftdi_sio.c
index b2d767e..0ff7f38 100644
--- a/drivers/usb/serial/ftdi_sio.c
+++ b/drivers/usb/serial/ftdi_sio.c
@@ -986,7 +986,8 @@ static const struct usb_device_id id_table_combined[] = {
/* ekey Devices */
{ USB_DEVICE(FTDI_VID, FTDI_EKEY_CONV_USB_PID) },
/* Infineon Devices */
-   { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, INFINEON_TRIBOARD_PID, 1) },
+   { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, 
INFINEON_TRIBOARD_TC1798_PID, 1) },
+   { USB_DEVICE_INTERFACE_NUMBER(INFINEON_VID, 
INFINEON_TRIBOARD_TC2X7_PID, 1) },
/* GE Healthcare devices */
{ USB_DEVICE(GE_HEALTHCARE_VID, GE_HEALTHCARE_NEMO_TRACKER_PID) },
/* Active Research (Actisense) devices */
diff --git a/drivers/usb/serial/ftdi_sio_ids.h 
b/drivers/usb/serial/ftdi_sio_ids.h
index f87a938..21011c0 100644
--- a/drivers/usb/serial/ftdi_sio_ids.h
+++ b/drivers/usb/serial/ftdi_sio_ids.h
@@ -626,8 +626,9 @@
 /*
  * Infineon Technologies
  */
-#define INFINEON_VID   0x058b
-#define INFINEON_TRIBOARD_PID  0x0028 /* DAS JTAG TriBoard TC1798 V1.0 */
+#define INFINEON_VID   0x058b
+#define INFINEON_TRIBOARD_TC1798_PID   0x0028 /* DAS JTAG TriBoard TC1798 V1.0 
*/
+#define INFINEON_TRIBOARD_TC2X7_PID0x0043 /* DAS JTAG TriBoard TC2X7 V1.0 
*/
 
 /*
  * Acton Research Corp.
-- 
2.3.2

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


[no subject]

2016-09-30 Thread Amitesh Singh
auth e47dc987 subscribe linux-usb singh.amit...@gmail.com
--
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: [RFC/PATCH 24/45] usb: host: ehci: make use of new usb_endpoint_maxp_mult()

2016-09-30 Thread Alan Stern
On Fri, 30 Sep 2016, Felipe Balbi wrote:

> > There are lots of other places where the new helpers might be used.  
> > Search for "max_packet" and "hb_mult" in ehci-q.c and ehci-sched.c.
> 
> Here's a new version:

Looks good in general.  I have just two comments...

> 8<--
> From f4daa62bbbd1c03e349e576aef8f2a5f039afb1a Mon Sep 17 00:00:00 2001
> From: Felipe Balbi 
> Date: Wed, 28 Sep 2016 13:38:18 +0300
> Subject: [PATCH] usb: host: ehci: make use of new usb_endpoint_maxp_mult()
> 
> We have introduced a helper to calculate multiplier
> value from wMaxPacketSize. Start using it.
> 
> Cc: Alan Stern 
> Cc: 
> Signed-off-by: Felipe Balbi 
> ---
>  drivers/usb/host/ehci-q.c | 10 ++
>  drivers/usb/host/ehci-sched.c |  2 +-
>  2 files changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
> index eca3710d8fc4..a45a5dc7ed9f 100644
> --- a/drivers/usb/host/ehci-q.c
> +++ b/drivers/usb/host/ehci-q.c
> @@ -550,8 +550,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
>  
>  /*-*/
>  
> -// high bandwidth multiplier, as encoded in highspeed endpoint descriptors
> -#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
>  // ... and packet size, for any kind of endpoint descriptor
>  #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
>  
> @@ -770,9 +768,11 @@ qh_make (
>   gfp_t   flags
>  ) {
>   struct ehci_qh  *qh = ehci_qh_alloc (ehci, flags);
> + struct usb_host_endpoint *ep;
>   u32 info1 = 0, info2 = 0;
>   int is_input, type;
>   int maxp = 0;
> + int mult;
>   struct usb_tt   *tt = urb->dev->tt;
>   struct ehci_qh_hw   *hw;
>  
> @@ -787,7 +787,9 @@ qh_make (
>  
>   is_input = usb_pipein (urb->pipe);
>   type = usb_pipetype (urb->pipe);
> + ep = usb_pipe_endpoint (urb->dev, urb->pipe);

You don't need to compute this; you can use urb->ep directly.

Also, my policy is not to put a space before the open paren in a
function call (Dave's original style) when adding new code or updating
existing code.

Otherwise it's good.  Thank you.

Alan Stern

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


RE: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Jun Li
Hi,

> -Original Message-
> From: Guenter Roeck [mailto:gro...@google.com]
> Sent: Friday, September 30, 2016 12:37 AM
> To: Jun Li 
> Cc: Guenter Roeck ; Felipe Balbi
> ; Chandra Sekhar Anagani
> ; Bruce Ashfield
> ; Bin Gao ; Pranav Tipnis
> ; Heikki Krogerus
> ; linux-ker...@vger.kernel.org; linux-
> u...@vger.kernel.org
> Subject: Re: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)
> 
> On Thu, Sep 29, 2016 at 7:35 AM, Jun Li  wrote:
> > Hi Guenter,
> >
> >> -Original Message-
> >> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> >> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
> >> Sent: Wednesday, August 24, 2016 5:11 AM
> >> To: Felipe Balbi 
> >> Cc: Chandra Sekhar Anagani ; Bruce
> >> Ashfield ; Bin Gao ;
> >> Pranav Tipnis ; Heikki Krogerus
> >> ; linux-ker...@vger.kernel.org;
> >> linux- u...@vger.kernel.org; Guenter Roeck 
> >> Subject: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager
> >> (tcpm)
> >>
> >> This driver implements the USB Type-C Power Delivery state machine
> >> for both source and sink ports. Alternate mode support is not fully
> >> implemented.
> >>
> >> The driver attaches to the USB Type-C class code implemented in the
> >> following patches.
> >>
> >>   usb: typec: add driver for Intel Whiskey Cove PMIC USB Type-C PHY
> >>   usb: USB Type-C connector class
> >>
> >> This driver only implements the state machine. Lower level drivers
> >> are responsible for
> >> - Reporting VBUS status and activating VBUS
> >> - Setting CC lines and providing CC line status
> >> - Setting line polarity
> >> - Activating and deactivating VCONN
> >> - Setting the current limit
> >> - Activating and deactivating PD message transfers
> >> - Sending and receiving PD messages
> >>
> >> The driver provides both a functional API as well as callbacks for
> >> lower level drivers.
> >>
> >> Signed-off-by: Guenter Roeck 
> >> ---
> >> v3:
> >> - Improve TCPM state machine resiliency if there are spurious CC line
> >> changes
> >>   while the state machine is in a transient change (waiting for a
> >> timeout)
> >> - Update current limit after CC voltage level changes on a port which
> >> is not
> >>   PD capable.
> >>
> >> v2:
> >> - Only update polarity if setting it was successful
> >>   If setting the CC line polarity in the driver was not successful,
> >>   don't update the internal polarity state.
> >> - All PD messages are little endian; convert to and from CPU endianness.
> >> - Avoid comparisons against NULL.
> >> - Use u8/u16/u32 instead of uint8_t/uint16_t/uint32_t consistently.
> >> - Callbacks into tcpm need to be lockless to avoid timing problems
> >>   in low level drivers.
> >> - Simplify callbacks; tcpm can request the current state of cc/vbus
> >>   when it is ready to use it.
> >>
> >>  drivers/usb/typec/Kconfig  |7 +
> >>  drivers/usb/typec/Makefile |1 +
> >>  drivers/usb/typec/tcpm.c   | 3163
> >> 
> >>  drivers/usb/typec/tcpm.h   |  137 ++
> >>  include/linux/usb/pd.h |  282 
> >>  include/linux/usb/pd_bdo.h |   31 +
> >>  include/linux/usb/pd_vdo.h |  412 ++
> >>  7 files changed, 4033 insertions(+)
> >>  create mode 100644 drivers/usb/typec/tcpm.c  create mode 100644
> >> drivers/usb/typec/tcpm.h  create mode 100644 include/linux/usb/pd.h
> >> create mode 100644 include/linux/usb/pd_bdo.h  create mode 100644
> >> include/linux/usb/pd_vdo.h
> >>
> >
> > ...
> >
> >> +
> >> +static void run_state_machine(struct tcpm_port *port) {
> >> + int ret;
> >> +
> >> + port->enter_state = port->state;
> >> + switch (port->state) {
> >> + /* SRC states */
> >> + case SRC_UNATTACHED:
> >> + tcpm_swap_complete(port, -ENOTCONN);
> >> + tcpm_src_detach(port);
> >> + tcpm_set_cc(port, TYPEC_CC_RP_DEF);
> >> + if (port->typec_caps.type == TYPEC_PORT_DRP)
> >> + tcpm_set_state(port, SNK_UNATTACHED,
> >> + PD_T_DRP_SNK);
> >
> > With this and below, after disconnect, the DRP port state machine will
> > be in infinite loop of state transition between SRC_UNATTACHED <-->
> > SNK_UNATTACHED, correct?
> >
> 
> Only while disconnected. It tries to alternatively connect as source and
> as sink (being configured as DRP). Once a CC line state change is reported
> it will transition out. I have a newer version of the patch (not yet
> published) which supports DRP toggling by the TCPC. With that enabled,
> TCPM does not change states until a CC state change is reported.
> 

RE: [LINUX PATCH] usb: gadget: Configure data verification through module parameter in gadget zero

2016-09-30 Thread Manish Narani
Hi Greg,

Thanks for the suggestion. I will fix it and send you in next version. :)

Regards,
Manish

-Original Message-
From: Greg KH [mailto:gre...@linuxfoundation.org]
Sent: Thursday, September 29, 2016 4:56 PM
To: Manish Narani 
Cc: ba...@kernel.org; k.opas...@samsung.com; r.bald...@samsung.com; 
peter.c...@freescale.com; Manish Narani ; 
john.y...@synopsys.com; e...@felipetonello.com; i.kotrasi...@samsung.com; 
linux-usb@vger.kernel.org; linux-ker...@vger.kernel.org; Anurag Kumar Vulisha 
; Punnaiah Choudary Kalluri 
Subject: Re: [LINUX PATCH] usb: gadget: Configure data verification through 
module parameter in gadget zero

On Thu, Sep 29, 2016 at 02:18:54PM +0530, Manish Narani wrote:
> This patch adds support to configure data verification through module
> parameter. This parameter can be used to disable data verification in
> case if one wants to measure peak Bulk/Isoc-IN/OUT performance
>
> Signed-off-by: Manish Narani 

Minor question, why would this be anything other than a LINUX PATCH?  :)

Just "PATCH" is usually fine here.

And again, please no new module parameters if at all possible.

thanks,

greg k-h


This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.

--
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: [LINUX PATCH] usb: gadget: Configure bulk maxburst through module parameter in gadget zero.

2016-09-30 Thread Manish Narani
Hi Greg,

Thanks for the suggestion. I will fix it and send you in next version. :)

Regards,
Manish

-Original Message-
From: Greg KH [mailto:gre...@linuxfoundation.org]
Sent: Thursday, September 29, 2016 2:24 PM
To: Manish Narani 
Cc: ba...@kernel.org; k.opas...@samsung.com; r.bald...@samsung.com; 
peter.c...@freescale.com; Manish Narani ; 
john.y...@synopsys.com; e...@felipetonello.com; i.kotrasi...@samsung.com; 
linux-usb@vger.kernel.org; linux-ker...@vger.kernel.org; Anurag Kumar Vulisha 
; Punnaiah Choudary Kalluri 
Subject: Re: [LINUX PATCH] usb: gadget: Configure bulk maxburst through module 
parameter in gadget zero.

On Thu, Sep 29, 2016 at 02:16:44PM +0530, Manish Narani wrote:
> This patch adds support to configure bulk maxburst through module
> parameter. This parameter can be used to modify bulk maxburst in case
> if one wants to measure peak Bulk/Isoc-IN/OUT performance.

Eeek, this isn't the 1990's, please don't add new module parameters :)

We have much better ways of handling configuration options for a device, why 
not use them (configfs, sysfs files, etc.)?

Ugh, it looks like iso_maxburst is handled this way as well.

Felipe, why is this?

thanks,

greg k-h


This email and any attachments are intended for the sole use of the named 
recipient(s) and contain(s) confidential information that may be proprietary, 
privileged or copyrighted under applicable law. If you are not the intended 
recipient, do not read, copy, or forward this email message or any attachments. 
Delete this email message and any attachments immediately.

--
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 v1 1/1] usbip: deletion of incorrect socket descriptor checking

2016-09-30 Thread David Laight
From: Nobuo Iwata
> Sent: 30 September 2016 06:44
> This patch removes checking of socket descriptor value in daemons.
> 
> It was checked to be less than FD_SETSIZE(1024 usually) but it's not
> correct.
> 
> To be exact, the maximum value of descriptor comes from
> rlimit(RLIMIT_NOFILE).
> 
> Following kernel code determines the value :
> get_unused_fd_flags() : fs/files.c
> __alloc_fd() : fs/files.c
> expand_files() : fs/files.c
> 
> The defalut (soft limit) is defines as INR_OPEN_CUR(1024) in
> include/linux/fs.h which is referenced form INIT_RLIMS in
> include/asm-generic/resource.h. The value may be modified with ulimt,
> sysctl, security configuration and etc.
> 
> With the kernel code above, when socket() system call returns positive
> value, the value must be within rlimit(RLIMIT_NOFILE). No extra
> checking is needed when socket() returns positive.

I'm guessing that the problem is that the code wants to use select()
on the socket.
The value of RLIMIT_NOFILE isn't really relevant.
If fd >= FD_SETSIZE then you can't use select.

In reality any program that has anywhere near that number of open fd
would be better off using something other than select().

David

--
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] mos7840: fix chars_in_buffer() return value

2016-09-30 Thread Johan Hovold
On Fri, Sep 30, 2016 at 12:00:30AM +0300, Stas Sergeev wrote:
> 29.09.2016 13:09, Johan Hovold пишет:
> > On Sat, Sep 24, 2016 at 06:00:57PM +0300, Stas Sergeev wrote:
> >> The TIOCOUTQ ioctl calls chars_in_buffer(), and some apps depend on
> >> a correct behaviour of that.
> >> mos7840 implements it wrongly: if you write just one char, TIOCOUTQ
> >> will return 32.
> >> This patch should fix it by accounting the number of chars actually
> >> written.
> >> This patch, unfortunately, misses the Tested-by tag.
> >> The reporter didn't test it, and I don't have the hardware in question.

> > Why do you think the driver returns 32b in chars_in_buffer after writing
> > a single character?

> Hi Johan, this actually came from this ancient bug report:
> https://bugzilla.kernel.org/show_bug.cgi?id=45791
> I was trying to add you back then and now, but your e-mail
> doesn't seem to be registered in a bug tracker.

Yeah, Greg does good job at direction bug reports to the usb mailing
list.

> The code in question was different when I submitted the
> original patch:
> https://bugzilla.kernel.org/attachment.cgi?id=77241
> Maybe the bug was since fixed.

It does seem to have been addressed by commit 5c263b92f828 ("usb:
serial: mos7840: Fixup mos7840_chars_in_buffer()") around the time of
your original report in 2012.

> In that case sorry for the noise.

No worries. 

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


[PATCH] ARM64: dts: meson-gxbb-odroidc2: Enable USB Nodes

2016-09-30 Thread Brian Kim
Enable both gxbb USB controller and add a 5V regulator for the OTG port
VBUS

Signed-off-by: Brian Kim 
---
 .../arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts | 29 ++
 1 file changed, 29 insertions(+)

diff --git a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts 
b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
index 8d89edc..997c671 100644
--- a/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
+++ b/arch/arm64/boot/dts/amlogic/meson-gxbb-odroidc2.dts
@@ -64,6 +64,18 @@
reg = <0x0 0x0 0x0 0x8000>;
};
 
+   usb_pwr: regulator-usb-pwrs {
+   compatible = "regulator-fixed";
+
+   regulator-name = "USB_PWR";
+
+   regulator-min-microvolt = <500>;
+   regulator-max-microvolt = <500>;
+
+   gpio = <_ao GPIOAO_5 GPIO_ACTIVE_HIGH>;
+   enable-active-high;
+   };
+
leds {
compatible = "gpio-leds";
blue {
@@ -149,6 +161,23 @@
pinctrl-names = "default";
 };
 
+_phy {
+   status = "okay";
+   phy-supply = <_pwr>;
+};
+
+_phy {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
+ {
+   status = "okay";
+};
+
 /* SD */
 _emmc_b {
status = "okay";
-- 
2.7.4

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


Re: USB hot-plug not working (ASUS TP301UA-C4028T)

2016-09-30 Thread Mathias Nyman

On 29.09.2016 23:36, Pierre de Villemereuil wrote:

Hi Mathias,

It seems you are right: entering
echo on > /sys/bus/pci/devices/\:00\:14.0/power/control
does tame USB to behave properly.

However, every time the AC is plugged/unplugged, this value gets overridden. 
Any way to make this permanent? (I realise this would harm a tiny bit of my 
battery life, but I guess not enough for me to realise it).



There's probably something like laptop-mode-tools that sets these, I'm not 
really familiar, or using it myself but
I'd start looking in

/etc/laptop-mode/laptop-mode.conf
/etc/laptop-mode/conf.d/*

and try to find the configuration that enables runtime power management for usb 
host while on battery.

-Mathias

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


Re: [RFC/PATCH 24/45] usb: host: ehci: make use of new usb_endpoint_maxp_mult()

2016-09-30 Thread Felipe Balbi

Hi,

Alan Stern  writes:
> On Wed, 28 Sep 2016, Felipe Balbi wrote:
>
>> We have introduced a helper to calculate multiplier
>> value from wMaxPacketSize. Start using it.
>> 
>> Cc: Alan Stern 
>> Cc: 
>> Signed-off-by: Felipe Balbi 
>> ---
>>  drivers/usb/host/ehci-sched.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
>> index 1dfe54f14737..6a9fa2c3a24e 100644
>> --- a/drivers/usb/host/ehci-sched.c
>> +++ b/drivers/usb/host/ehci-sched.c
>> @@ -1064,7 +1064,7 @@ iso_stream_init(
>>  
>>  /* knows about ITD vs SITD */
>>  if (dev->speed == USB_SPEED_HIGH) {
>> -unsigned multi = hb_mult(maxp);
>> +unsigned multi = usb_endpoint_maxp_mult(>ep->desc);
>>  
>>  stream->highspeed = 1;
>
> There are lots of other places where the new helpers might be used.  
> Search for "max_packet" and "hb_mult" in ehci-q.c and ehci-sched.c.

Here's a new version:

8<--
From f4daa62bbbd1c03e349e576aef8f2a5f039afb1a Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Wed, 28 Sep 2016 13:38:18 +0300
Subject: [PATCH] usb: host: ehci: make use of new usb_endpoint_maxp_mult()

We have introduced a helper to calculate multiplier
value from wMaxPacketSize. Start using it.

Cc: Alan Stern 
Cc: 
Signed-off-by: Felipe Balbi 
---
 drivers/usb/host/ehci-q.c | 10 ++
 drivers/usb/host/ehci-sched.c |  2 +-
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/host/ehci-q.c b/drivers/usb/host/ehci-q.c
index eca3710d8fc4..a45a5dc7ed9f 100644
--- a/drivers/usb/host/ehci-q.c
+++ b/drivers/usb/host/ehci-q.c
@@ -550,8 +550,6 @@ qh_completions (struct ehci_hcd *ehci, struct ehci_qh *qh)
 
 /*-*/
 
-// high bandwidth multiplier, as encoded in highspeed endpoint descriptors
-#define hb_mult(wMaxPacketSize) (1 + (((wMaxPacketSize) >> 11) & 0x03))
 // ... and packet size, for any kind of endpoint descriptor
 #define max_packet(wMaxPacketSize) ((wMaxPacketSize) & 0x07ff)
 
@@ -770,9 +768,11 @@ qh_make (
gfp_t   flags
 ) {
struct ehci_qh  *qh = ehci_qh_alloc (ehci, flags);
+   struct usb_host_endpoint *ep;
u32 info1 = 0, info2 = 0;
int is_input, type;
int maxp = 0;
+   int mult;
struct usb_tt   *tt = urb->dev->tt;
struct ehci_qh_hw   *hw;
 
@@ -787,7 +787,9 @@ qh_make (
 
is_input = usb_pipein (urb->pipe);
type = usb_pipetype (urb->pipe);
+   ep = usb_pipe_endpoint (urb->dev, urb->pipe);
maxp = usb_maxpacket (urb->dev, urb->pipe, !is_input);
+   mult = usb_endpoint_maxp_mult (>desc);
 
/* 1024 byte maxpacket is a hardware ceiling.  High bandwidth
 * acts like up to 3KB, but is built from smaller packets.
@@ -810,7 +812,7 @@ qh_make (
 
qh->ps.usecs = NS_TO_US(usb_calc_bus_time(USB_SPEED_HIGH,
is_input, 0,
-   hb_mult(maxp) * max_packet(maxp)));
+   mult * max_packet(maxp)));
qh->ps.phase = NO_FRAME;
 
if (urb->dev->speed == USB_SPEED_HIGH) {
@@ -929,7 +931,7 @@ qh_make (
info2 |= (EHCI_TUNE_MULT_HS << 30);
} else {/* PIPE_INTERRUPT */
info1 |= max_packet (maxp) << 16;
-   info2 |= hb_mult (maxp) << 30;
+   info2 |= mult << 30;
}
break;
default:
diff --git a/drivers/usb/host/ehci-sched.c b/drivers/usb/host/ehci-sched.c
index 1dfe54f14737..6a9fa2c3a24e 100644
--- a/drivers/usb/host/ehci-sched.c
+++ b/drivers/usb/host/ehci-sched.c
@@ -1064,7 +1064,7 @@ iso_stream_init(
 
/* knows about ITD vs SITD */
if (dev->speed == USB_SPEED_HIGH) {
-   unsigned multi = hb_mult(maxp);
+   unsigned multi = usb_endpoint_maxp_mult(>ep->desc);
 
stream->highspeed = 1;
 
-- 
2.10.0.440.g21f862b


And I have also removed max_packet() macro as a separate patch. I'll
resend this series later with these patches included, but I wanted to
check if you're okay with the changes.

8<--
From 79361c0d6cc8c9815c7741b0801629460d0906fe Mon Sep 17 00:00:00 2001
From: Felipe Balbi 
Date: Fri, 30 Sep 2016 11:24:59 +0300
Subject: [PATCH] usb: host: ehci: remove unnecessary max_packet() 

RE: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller Interface driver (tcpci)

2016-09-30 Thread Jun Li
Hi Guenter,

> -Original Message-
> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
> Sent: Wednesday, August 24, 2016 5:11 AM
> To: Felipe Balbi 
> Cc: Chandra Sekhar Anagani ; Bruce
> Ashfield ; Bin Gao ;
> Pranav Tipnis ; Heikki Krogerus
> ; linux-ker...@vger.kernel.org; linux-
> u...@vger.kernel.org; Guenter Roeck 
> Subject: [RFC PATCH v3 2/2] usb: typec: Type-C Port Controller Interface
> driver (tcpci)
> 
> The port controller interface driver interconnects the Type-C Port Manager
> with a Type-C Port Controller Interface (TCPCI) compliant port controller.
> 
> Signed-off-by: Guenter Roeck 
> ---
> v3:
> - No change
> 
> v2:
> - Adjust to modified callbacks into tcpm code
> 
>  drivers/usb/typec/Kconfig  |   9 +
>  drivers/usb/typec/Makefile |   1 +
>  drivers/usb/typec/tcpci.c  | 487
> +
>  drivers/usb/typec/tcpci.h  | 133 +
>  4 files changed, 630 insertions(+)
>  create mode 100644 drivers/usb/typec/tcpci.c  create mode 100644
> drivers/usb/typec/tcpci.h
> 
> diff --git a/drivers/usb/typec/Kconfig b/drivers/usb/typec/Kconfig index
> 113bb1b3589c..a92c9d1a3e00 100644
> --- a/drivers/usb/typec/Kconfig
> +++ b/drivers/usb/typec/Kconfig
> @@ -25,4 +25,13 @@ config TYPEC_TCPM
> The Type-C Port Controller Manager provides a USB PD and USB Type-C
> state machine for use with Type-C Port Controllers.
> 
> +if TYPEC_TCPM
> +
> +config TYPEC_TCPCI
> + tristate "Type-C Port Controller Interface driver"
> + help
> +   Type-C Port Controller driver for TCPCI-compliant controller.
> +
> +endif
> +
>  endmenu
> diff --git a/drivers/usb/typec/Makefile b/drivers/usb/typec/Makefile index
> bbe45721cf52..7dbaf8c3911d 100644
> --- a/drivers/usb/typec/Makefile
> +++ b/drivers/usb/typec/Makefile
> @@ -1,3 +1,4 @@
>  obj-$(CONFIG_TYPEC)  += typec.o
>  obj-$(CONFIG_TYPEC_WCOVE)+= typec_wcove.o
>  obj-$(CONFIG_TYPEC_TCPM) += tcpm.o
> +obj-$(CONFIG_TYPEC_TCPCI)+= tcpci.o
> diff --git a/drivers/usb/typec/tcpci.c b/drivers/usb/typec/tcpci.c new
> file mode 100644 index ..af338218a1f3
> --- /dev/null
> +++ b/drivers/usb/typec/tcpci.c
> @@ -0,0 +1,487 @@
> +/*
> + * Copyright 2015-2016 Google, Inc
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License as published by
> + * the Free Software Foundation; either version 2 of the License, or
> + * (at your option) any later version.
> + *
> + * This program is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> + * GNU General Public License for more details.
> + *
> + * USB Type-C Port Controller Interface.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "tcpci.h"
> +#include "tcpm.h"
> +
> +#define PD_RETRY_COUNT 3
> +
> +struct tcpci {
> + struct device *dev;
> + struct i2c_client *client;
> +
> + struct tcpm_port *port;
> +
> + struct regmap *regmap;
> +
> + bool controls_vbus;
> +
> + struct tcpc_dev tcpc;
> +};
> +
> +static inline struct tcpci *tcpc_to_tcpci(struct tcpc_dev *tcpc) {
> + return container_of(tcpc, struct tcpci, tcpc); }
> +
> +static int tcpci_read16(struct tcpci *tcpci, unsigned int reg,
> + unsigned int *val)
> +{
> + return regmap_raw_read(tcpci->regmap, reg, val, sizeof(u16)); }
> +
> +static int tcpci_write16(struct tcpci *tcpci, unsigned int reg, u16
> +val) {
> + return regmap_raw_write(tcpci->regmap, reg, , sizeof(u16)); }
> +
> +static int tcpci_set_cc(struct tcpc_dev *tcpc, enum typec_cc_status cc)
> +{
> + struct tcpci *tcpci = tcpc_to_tcpci(tcpc);
> + unsigned int reg;
> + int ret;
> +
> + switch (cc) {
> + case TYPEC_CC_RA:
> + reg = (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC1_SHIFT) |
> + (TCPC_ROLE_CTRL_CC_RA << TCPC_ROLE_CTRL_CC2_SHIFT);
> + break;
> + case TYPEC_CC_RD:
> + reg = (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC1_SHIFT) |
> + (TCPC_ROLE_CTRL_CC_RD << TCPC_ROLE_CTRL_CC2_SHIFT);
> + break;
> + case TYPEC_CC_RP_DEF:
> + reg = (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC1_SHIFT) |
> + (TCPC_ROLE_CTRL_CC_RP << TCPC_ROLE_CTRL_CC2_SHIFT) |
> + (TCPC_ROLE_CTRL_RP_VAL_DEF <<
> +  TCPC_ROLE_CTRL_RP_VAL_SHIFT);
> + break;
> + case TYPEC_CC_RP_1_5:
> + reg = (TCPC_ROLE_CTRL_CC_RP << 

RE: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)

2016-09-30 Thread Jun Li
Hi Guenter,
> -Original Message-
> From: linux-usb-ow...@vger.kernel.org [mailto:linux-usb-
> ow...@vger.kernel.org] On Behalf Of Guenter Roeck
> Sent: Wednesday, August 24, 2016 5:11 AM
> To: Felipe Balbi 
> Cc: Chandra Sekhar Anagani ; Bruce
> Ashfield ; Bin Gao ;
> Pranav Tipnis ; Heikki Krogerus
> ; linux-ker...@vger.kernel.org; linux-
> u...@vger.kernel.org; Guenter Roeck 
> Subject: [RFC PATCH v3 1/2] usb: typec: USB Type-C Port Manager (tcpm)
> 
...
> diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h
> new file mode 100644
> index ..6b1679af7a25
> --- /dev/null
> +++ b/include/linux/usb/pd.h

...

> +#define PDO_VAR(min_mv, max_mv, max_ma)  
> \
> + ((PDO_TYPE_VAR << PDO_TYPE_SHIFT) | \
> +  min_mv) / 50) & PDO_VAR_MIN_VOLT_MASK) <<  \
> +   PDO_VAR_MIN_VOLT_SHIFT) | \
> +  max_mv) / 50) & PDO_VAR_MAX_VOLT_MASK) <<  \
> +   PDO_VAR_MAX_VOLT_SHIFT) | \
> +  max_ma) / 50) & PDO_VAR_MAX_CURR_MASK) <<  \

max_ma) / 10) & PDO_VAR_MAX_CURR_MASK) <<  \

Li Jun

--
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: ARM juno R2 board USB Issue (EHCI probe failed)

2016-09-30 Thread Sajjan, Vikas C
Hi Sudeep,

-Original Message-
From: Sudeep Holla [mailto:sudeep.ho...@arm.com] 
Sent: Tuesday, September 27, 2016 2:38 PM
To: Sajjan, Vikas C ; Vikas Sajjan 
; linux-usb@vger.kernel.org; 
linux-arm-ker...@lists.infradead.org; linux-a...@vger.kernel.org
Cc: Sudeep Holla ; mark.rutl...@arm.com; 
lorenzo.pieral...@arm.com
Subject: Re: ARM juno R2 board USB Issue (EHCI probe failed)



On 27/09/16 09:55, Sajjan, Vikas C wrote:
> Hi Sudeep,
>
> -Original Message-
> From: Sudeep Holla [mailto:sudeep.ho...@arm.com]
> Sent: Tuesday, September 27, 2016 2:21 PM
> To: Vikas Sajjan ; linux-usb@vger.kernel.org; 
> linux-arm-ker...@lists.infradead.org; linux-a...@vger.kernel.org
> Cc: Sudeep Holla ; mark.rutl...@arm.com; 
> lorenzo.pieral...@arm.com; Sajjan, Vikas C 
> Subject: Re: ARM juno R2 board USB Issue (EHCI probe failed)
>
> Hi Vikas,
>
> On 27/09/16 09:14, Vikas Sajjan wrote:
>> Adding USB mailing list.
>>
>>
>> On Tue, Sep 27, 2016 at 12:33 PM, Sajjan, Vikas C 
>>  wrote:
>>> Hi All,
>>>
>>> I working on ARM juno R2 board, with latest kernel 4.8.rc7 and I get 
>>> below USB EHCI probe error while booting with acpi=force.
>>>
>
> Are you using the latest UEFI EDK2 ?
> No, I am still using the UEFI binary which came as part of the Juno board.
>
>
>>> [1.223662] VFIO - User Level meta-driver version: 0.3
>>> [1.229335] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
>>> [1.235882] ehci-pci: EHCI PCI platform driver
>>> [1.240359] ehci-platform: EHCI generic platform driver
>>> [1.245619] ehci-platform ARMH0D20:00: Error: DMA mask configuration 
>>> failed
>>> [1.272491] ehci-platform: probe of ARMH0D20:00 failed with error -5
>>> [1.278876] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
>>> [1.285071] ohci-pci: OHCI PCI platform driver
>>> [1.289548] ohci-platform: OHCI generic platform driver
>>> [1.294884] usbcore: registered new interface driver usb-storage
>>> [1.301231] mousedev: PS/2 mouse device common for all mice
>>> [1.307197] rtc-efi rtc-efi: rtc core: registered rtc-efi as rtc0
>>>
>>> But this error goes off, if I don't force ACPI booting, i.e., if I 
>>> remove acpi=force from kernel command line , USB is detected  and my 
>>> RFS which is in the usb drive, gets mounted successfully.
>>>
>
> As I mentioned in private, I do get the same error if I drop _CCA in 
> USB object of ACPI DSDT. Can you give it a spin with latest UEFI ?
>
> Sure, will try with latest UEFI.
>

I bet that's 8-12 months old. It puts the banner during boot with the build 
date. You can try to follow [1] or access it from [2]

I was able boot the kernel without any EHCI failure and could get to the shell 
prompt using the EDK2 in [2].
Thanks for help.

Thanks and Regards
Vikas Sajjan
--
Regards,
Sudeep

[1] https://community.arm.com/docs/DOC-11395
[2]
http://snapshots.linaro.org/member-builds/armlt-platforms-release/32/juno-uefi.zip
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v6 1/2] usbip: vhci extension: modifications to userspace

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

Changed corresponding to new vhci_sysfs.c.

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

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

status[.N] in sysfs are used.

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

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

Wording inconsistencies are fixed according to the rule below.

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

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

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

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

2016-09-30 Thread Nobuo Iwata
Refactoring to the daemon.

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

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

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

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

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

[PATCH v11 7/9] usbip: exporting devices: new application-side daemon

2016-09-30 Thread Nobuo Iwata
New application(vhci)-side daemon.

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

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

[PATCH v11 0/9] usbip: exporting devices

2016-09-30 Thread Nobuo Iwata
Dear all,

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

1. Overview

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

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

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

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

 Bind and unbind are done in connect and disconnect internally.

2. The use cases

EXISTING)

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

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

NEW)

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

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

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

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

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

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

# usbip connect  -> # usbipa
 (passed)

3. Combination with vUDC

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

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

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

Please, see also cover letter about wording.

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

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

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


[PATCH v6 0/2] usbip: vhci number of ports extension

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

1. Background

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

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

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

2. About this patch set

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

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

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

3. Dynamic extension

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

4. Wording

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

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

5. Dependencies

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

---
Version information

v6)
# Recreated based on linux-next 20160928.
# Was '3/1 usbip: vhci extension: modifications to vhci driver' is 
excluded because it has been merged.

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

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

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

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

*** BLURB HERE ***

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

 drivers/usb/usbip/Kconfig|  17 +-
 drivers/usb/usbip/vhci.h |  36 ++-
 drivers/usb/usbip/vhci_hcd.c | 250 ++---
 drivers/usb/usbip/vhci_rx.c  |  10 +-
 drivers/usb/usbip/vhci_sysfs.c   |  49 ++--
 drivers/usb/usbip/vhci_tx.c  |   6 +-
 tools/usb/usbip/libsrc/vhci_driver.c | 398 +++
 tools/usb/usbip/libsrc/vhci_driver.h |  45 +--
 tools/usb/usbip/src/usbip_attach.c   |   8 +-
 tools/usb/usbip/src/usbip_port.c |  13 +-
 tools/usb/usbip/src/usbipd_app.c |  48 ++--
 11 files changed, 546 insertions(+), 334 deletions(-)

-- 
2.1.0

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