Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Lu Baolu


On 03/04/2016 09:44 AM, Greg Kroah-Hartman wrote:
> On Fri, Mar 04, 2016 at 09:38:58AM +0800, Lu Baolu wrote:
>>
>> On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
>>> On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
 Several Intel PCHs and SOCs have an internal mux that is used to
 share one USB port between device controller and host controller.
 The mux is handled through the Dual Role Configuration Register.

 Signed-off-by: Heikki Krogerus 
 Signed-off-by: Lu Baolu 
 Signed-off-by: Wu Hao 
 Reviewed-by: Felipe Balbi 
 ---
  MAINTAINERS|   1 +
  drivers/usb/misc/Kconfig   |   7 ++
  drivers/usb/misc/Makefile  |   1 +
  drivers/usb/misc/intel-mux-drcfg.c | 174 
 +
  4 files changed, 183 insertions(+)
  create mode 100644 drivers/usb/misc/intel-mux-drcfg.c

 diff --git a/MAINTAINERS b/MAINTAINERS
 index 0f321e4..20eb873 100644
 --- a/MAINTAINERS
 +++ b/MAINTAINERS
 @@ -11396,6 +11396,7 @@ S: Supported
  F:drivers/usb/misc/mux.c
  F:include/linux/usb/mux.h
  F:drivers/usb/misc/intel-mux-gpio.c
 +F:drivers/usb/misc/intel-mux-drcfg.c
  
  USB PRINTER DRIVER (usblp)
  M:Pete Zaitcev 
 diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
 index 33e6386..befd910 100644
 --- a/drivers/usb/misc/Kconfig
 +++ b/drivers/usb/misc/Kconfig
 @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
help
  Say Y here to enable support for Intel dual role port mux
  controlled by GPIOs.
 +
 +config INTEL_MUX_DRCFG
 +  tristate "Intel dual role port mux controlled by register"
 +  select USB_MUX
 +  help
 +Say Y here to enable support for Intel dual role port mux
 +controlled by the Dual Role Configuration Registers.
 diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
 index da4fb4e..c4d19a0 100644
 --- a/drivers/usb/misc/Makefile
 +++ b/drivers/usb/misc/Makefile
 @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST)+= lvstest.o
  
  obj-$(CONFIG_USB_MUX) += mux.o
  obj-$(CONFIG_INTEL_MUX_GPIO)  += intel-mux-gpio.o
 +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
 diff --git a/drivers/usb/misc/intel-mux-drcfg.c 
 b/drivers/usb/misc/intel-mux-drcfg.c
 new file mode 100644
 index 000..29081c5
 --- /dev/null
 +++ b/drivers/usb/misc/intel-mux-drcfg.c
 @@ -0,0 +1,174 @@
 +/**
 + * intel-mux-drcfg.c - Driver for Intel USB mux via register
 + *
 + * Copyright (C) 2016 Intel Corporation
 + * Author: Heikki Krogerus 
 + * Author: Lu Baolu 
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License version 2 as
 + * published by the Free Software Foundation.
 + */
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +#include 
 +
 +#define INTEL_MUX_CFG00x00
 +#define INTEL_MUX_CFG10x04
 +#define CFG0_SW_IDPIN BIT(20)
 +#define CFG0_SW_IDPIN_EN  BIT(21)
 +#define CFG0_SW_VBUS_VALIDBIT(24)
 +#define CFG1_SW_MODE  BIT(29)
 +#define CFG1_POLL_TIMEOUT 1000
 +
 +struct intel_usb_mux {
 +  struct usb_mux_dev umdev;
 +  void __iomem *regs;
 +  u32 cfg0_ctx;
 +};
 +
 +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool 
 host)
 +{
 +  struct intel_usb_mux *mux;
 +  unsigned long timeout;
 +  u32 data;
 +
 +  mux = container_of(umdev, struct intel_usb_mux, umdev);
 +
 +  /* Check and set mux to SW controlled mode */
 +  data = readl(mux->regs + INTEL_MUX_CFG0);
 +  if (!(data & CFG0_SW_IDPIN_EN)) {
 +  data |= CFG0_SW_IDPIN_EN;
 +  writel(data, mux->regs + INTEL_MUX_CFG0);
 +  }
 +
 +  /*
 +   * Configure CFG0 to switch the mux and VBUS_VALID bit is
 +   * required for device mode.
 +   */
 +  data = readl(mux->regs + INTEL_MUX_CFG0);
 +  if (host)
 +  data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
 +  else
 +  data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
 +  writel(data, mux->regs + INTEL_MUX_CFG0);
 +
 +  /*
 +   * Polling CFG1 for safety, most case it takes about 600ms
 +   * to finish mode switching, set TIMEOUT long enough.
 +   */
 +  timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
 +
 +  /* Polling on CFG1 register to confirm mode switch. */
 +  while 

Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Greg Kroah-Hartman
On Fri, Mar 04, 2016 at 09:38:58AM +0800, Lu Baolu wrote:
> 
> 
> On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
> > On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
> >> Several Intel PCHs and SOCs have an internal mux that is used to
> >> share one USB port between device controller and host controller.
> >> The mux is handled through the Dual Role Configuration Register.
> >>
> >> Signed-off-by: Heikki Krogerus 
> >> Signed-off-by: Lu Baolu 
> >> Signed-off-by: Wu Hao 
> >> Reviewed-by: Felipe Balbi 
> >> ---
> >>  MAINTAINERS|   1 +
> >>  drivers/usb/misc/Kconfig   |   7 ++
> >>  drivers/usb/misc/Makefile  |   1 +
> >>  drivers/usb/misc/intel-mux-drcfg.c | 174 
> >> +
> >>  4 files changed, 183 insertions(+)
> >>  create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
> >>
> >> diff --git a/MAINTAINERS b/MAINTAINERS
> >> index 0f321e4..20eb873 100644
> >> --- a/MAINTAINERS
> >> +++ b/MAINTAINERS
> >> @@ -11396,6 +11396,7 @@ S: Supported
> >>  F:drivers/usb/misc/mux.c
> >>  F:include/linux/usb/mux.h
> >>  F:drivers/usb/misc/intel-mux-gpio.c
> >> +F:drivers/usb/misc/intel-mux-drcfg.c
> >>  
> >>  USB PRINTER DRIVER (usblp)
> >>  M:Pete Zaitcev 
> >> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
> >> index 33e6386..befd910 100644
> >> --- a/drivers/usb/misc/Kconfig
> >> +++ b/drivers/usb/misc/Kconfig
> >> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
> >>help
> >>  Say Y here to enable support for Intel dual role port mux
> >>  controlled by GPIOs.
> >> +
> >> +config INTEL_MUX_DRCFG
> >> +  tristate "Intel dual role port mux controlled by register"
> >> +  select USB_MUX
> >> +  help
> >> +Say Y here to enable support for Intel dual role port mux
> >> +controlled by the Dual Role Configuration Registers.
> >> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
> >> index da4fb4e..c4d19a0 100644
> >> --- a/drivers/usb/misc/Makefile
> >> +++ b/drivers/usb/misc/Makefile
> >> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST)+= lvstest.o
> >>  
> >>  obj-$(CONFIG_USB_MUX) += mux.o
> >>  obj-$(CONFIG_INTEL_MUX_GPIO)  += intel-mux-gpio.o
> >> +obj-$(CONFIG_INTEL_MUX_DRCFG) += intel-mux-drcfg.o
> >> diff --git a/drivers/usb/misc/intel-mux-drcfg.c 
> >> b/drivers/usb/misc/intel-mux-drcfg.c
> >> new file mode 100644
> >> index 000..29081c5
> >> --- /dev/null
> >> +++ b/drivers/usb/misc/intel-mux-drcfg.c
> >> @@ -0,0 +1,174 @@
> >> +/**
> >> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
> >> + *
> >> + * Copyright (C) 2016 Intel Corporation
> >> + * Author: Heikki Krogerus 
> >> + * Author: Lu Baolu 
> >> + *
> >> + * This program is free software; you can redistribute it and/or modify
> >> + * it under the terms of the GNU General Public License version 2 as
> >> + * published by the Free Software Foundation.
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#define INTEL_MUX_CFG00x00
> >> +#define INTEL_MUX_CFG10x04
> >> +#define CFG0_SW_IDPIN BIT(20)
> >> +#define CFG0_SW_IDPIN_EN  BIT(21)
> >> +#define CFG0_SW_VBUS_VALIDBIT(24)
> >> +#define CFG1_SW_MODE  BIT(29)
> >> +#define CFG1_POLL_TIMEOUT 1000
> >> +
> >> +struct intel_usb_mux {
> >> +  struct usb_mux_dev umdev;
> >> +  void __iomem *regs;
> >> +  u32 cfg0_ctx;
> >> +};
> >> +
> >> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool 
> >> host)
> >> +{
> >> +  struct intel_usb_mux *mux;
> >> +  unsigned long timeout;
> >> +  u32 data;
> >> +
> >> +  mux = container_of(umdev, struct intel_usb_mux, umdev);
> >> +
> >> +  /* Check and set mux to SW controlled mode */
> >> +  data = readl(mux->regs + INTEL_MUX_CFG0);
> >> +  if (!(data & CFG0_SW_IDPIN_EN)) {
> >> +  data |= CFG0_SW_IDPIN_EN;
> >> +  writel(data, mux->regs + INTEL_MUX_CFG0);
> >> +  }
> >> +
> >> +  /*
> >> +   * Configure CFG0 to switch the mux and VBUS_VALID bit is
> >> +   * required for device mode.
> >> +   */
> >> +  data = readl(mux->regs + INTEL_MUX_CFG0);
> >> +  if (host)
> >> +  data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> >> +  else
> >> +  data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> >> +  writel(data, mux->regs + INTEL_MUX_CFG0);
> >> +
> >> +  /*
> >> +   * Polling CFG1 for safety, most case it takes about 600ms
> >> +   * to finish mode switching, set TIMEOUT long enough.
> >> +   */
> >> +  timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
> >> +
> >> +  /* Polling on CFG1 register to confirm mode switch. */
> >> +  while (!time_after(jiffies, timeout)) {
> >> +  data = 

Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Lu Baolu


On 03/04/2016 12:12 AM, Greg Kroah-Hartman wrote:
> On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
>> Several Intel PCHs and SOCs have an internal mux that is used to
>> share one USB port between device controller and host controller.
>> The mux is handled through the Dual Role Configuration Register.
>>
>> Signed-off-by: Heikki Krogerus 
>> Signed-off-by: Lu Baolu 
>> Signed-off-by: Wu Hao 
>> Reviewed-by: Felipe Balbi 
>> ---
>>  MAINTAINERS|   1 +
>>  drivers/usb/misc/Kconfig   |   7 ++
>>  drivers/usb/misc/Makefile  |   1 +
>>  drivers/usb/misc/intel-mux-drcfg.c | 174 
>> +
> If you are going to start having a bunch of these, please make a new
> directory, drivers/usb/mux/ ?

Sure. I can put them in drivers/usb/mux.
--
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 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Lu Baolu


On 03/04/2016 12:14 AM, Greg Kroah-Hartman wrote:
> On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
>> Several Intel PCHs and SOCs have an internal mux that is used to
>> share one USB port between device controller and host controller.
>> The mux is handled through the Dual Role Configuration Register.
>>
>> Signed-off-by: Heikki Krogerus 
>> Signed-off-by: Lu Baolu 
>> Signed-off-by: Wu Hao 
>> Reviewed-by: Felipe Balbi 
>> ---
>>  MAINTAINERS|   1 +
>>  drivers/usb/misc/Kconfig   |   7 ++
>>  drivers/usb/misc/Makefile  |   1 +
>>  drivers/usb/misc/intel-mux-drcfg.c | 174 
>> +
>>  4 files changed, 183 insertions(+)
>>  create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
>>
>> diff --git a/MAINTAINERS b/MAINTAINERS
>> index 0f321e4..20eb873 100644
>> --- a/MAINTAINERS
>> +++ b/MAINTAINERS
>> @@ -11396,6 +11396,7 @@ S:   Supported
>>  F:  drivers/usb/misc/mux.c
>>  F:  include/linux/usb/mux.h
>>  F:  drivers/usb/misc/intel-mux-gpio.c
>> +F:  drivers/usb/misc/intel-mux-drcfg.c
>>  
>>  USB PRINTER DRIVER (usblp)
>>  M:  Pete Zaitcev 
>> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
>> index 33e6386..befd910 100644
>> --- a/drivers/usb/misc/Kconfig
>> +++ b/drivers/usb/misc/Kconfig
>> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
>>  help
>>Say Y here to enable support for Intel dual role port mux
>>controlled by GPIOs.
>> +
>> +config INTEL_MUX_DRCFG
>> +tristate "Intel dual role port mux controlled by register"
>> +select USB_MUX
>> +help
>> +  Say Y here to enable support for Intel dual role port mux
>> +  controlled by the Dual Role Configuration Registers.
>> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
>> index da4fb4e..c4d19a0 100644
>> --- a/drivers/usb/misc/Makefile
>> +++ b/drivers/usb/misc/Makefile
>> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST)  += lvstest.o
>>  
>>  obj-$(CONFIG_USB_MUX)   += mux.o
>>  obj-$(CONFIG_INTEL_MUX_GPIO)+= intel-mux-gpio.o
>> +obj-$(CONFIG_INTEL_MUX_DRCFG)   += intel-mux-drcfg.o
>> diff --git a/drivers/usb/misc/intel-mux-drcfg.c 
>> b/drivers/usb/misc/intel-mux-drcfg.c
>> new file mode 100644
>> index 000..29081c5
>> --- /dev/null
>> +++ b/drivers/usb/misc/intel-mux-drcfg.c
>> @@ -0,0 +1,174 @@
>> +/**
>> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
>> + *
>> + * Copyright (C) 2016 Intel Corporation
>> + * Author: Heikki Krogerus 
>> + * Author: Lu Baolu 
>> + *
>> + * This program is free software; you can redistribute it and/or modify
>> + * it under the terms of the GNU General Public License version 2 as
>> + * published by the Free Software Foundation.
>> + */
>> +
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +#include 
>> +
>> +#define INTEL_MUX_CFG0  0x00
>> +#define INTEL_MUX_CFG1  0x04
>> +#define CFG0_SW_IDPIN   BIT(20)
>> +#define CFG0_SW_IDPIN_ENBIT(21)
>> +#define CFG0_SW_VBUS_VALID  BIT(24)
>> +#define CFG1_SW_MODEBIT(29)
>> +#define CFG1_POLL_TIMEOUT   1000
>> +
>> +struct intel_usb_mux {
>> +struct usb_mux_dev umdev;
>> +void __iomem *regs;
>> +u32 cfg0_ctx;
>> +};
>> +
>> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool 
>> host)
>> +{
>> +struct intel_usb_mux *mux;
>> +unsigned long timeout;
>> +u32 data;
>> +
>> +mux = container_of(umdev, struct intel_usb_mux, umdev);
>> +
>> +/* Check and set mux to SW controlled mode */
>> +data = readl(mux->regs + INTEL_MUX_CFG0);
>> +if (!(data & CFG0_SW_IDPIN_EN)) {
>> +data |= CFG0_SW_IDPIN_EN;
>> +writel(data, mux->regs + INTEL_MUX_CFG0);
>> +}
>> +
>> +/*
>> + * Configure CFG0 to switch the mux and VBUS_VALID bit is
>> + * required for device mode.
>> + */
>> +data = readl(mux->regs + INTEL_MUX_CFG0);
>> +if (host)
>> +data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>> +else
>> +data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
>> +writel(data, mux->regs + INTEL_MUX_CFG0);
>> +
>> +/*
>> + * Polling CFG1 for safety, most case it takes about 600ms
>> + * to finish mode switching, set TIMEOUT long enough.
>> + */
>> +timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
>> +
>> +/* Polling on CFG1 register to confirm mode switch. */
>> +while (!time_after(jiffies, timeout)) {
>> +data = readl(mux->regs + INTEL_MUX_CFG1);
>> +if (!(host ^ (data & CFG1_SW_MODE)))
>> +return 0;
>> +/* interval for polling is set to about 5ms */
>> +usleep_range(5000, 5100);
>> +}
>> +
>> +return 

Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Greg Kroah-Hartman
On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
> Several Intel PCHs and SOCs have an internal mux that is used to
> share one USB port between device controller and host controller.
> The mux is handled through the Dual Role Configuration Register.
> 
> Signed-off-by: Heikki Krogerus 
> Signed-off-by: Lu Baolu 
> Signed-off-by: Wu Hao 
> Reviewed-by: Felipe Balbi 
> ---
>  MAINTAINERS|   1 +
>  drivers/usb/misc/Kconfig   |   7 ++
>  drivers/usb/misc/Makefile  |   1 +
>  drivers/usb/misc/intel-mux-drcfg.c | 174 
> +
>  4 files changed, 183 insertions(+)
>  create mode 100644 drivers/usb/misc/intel-mux-drcfg.c
> 
> diff --git a/MAINTAINERS b/MAINTAINERS
> index 0f321e4..20eb873 100644
> --- a/MAINTAINERS
> +++ b/MAINTAINERS
> @@ -11396,6 +11396,7 @@ S:Supported
>  F:   drivers/usb/misc/mux.c
>  F:   include/linux/usb/mux.h
>  F:   drivers/usb/misc/intel-mux-gpio.c
> +F:   drivers/usb/misc/intel-mux-drcfg.c
>  
>  USB PRINTER DRIVER (usblp)
>  M:   Pete Zaitcev 
> diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
> index 33e6386..befd910 100644
> --- a/drivers/usb/misc/Kconfig
> +++ b/drivers/usb/misc/Kconfig
> @@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
>   help
> Say Y here to enable support for Intel dual role port mux
> controlled by GPIOs.
> +
> +config INTEL_MUX_DRCFG
> + tristate "Intel dual role port mux controlled by register"
> + select USB_MUX
> + help
> +   Say Y here to enable support for Intel dual role port mux
> +   controlled by the Dual Role Configuration Registers.
> diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
> index da4fb4e..c4d19a0 100644
> --- a/drivers/usb/misc/Makefile
> +++ b/drivers/usb/misc/Makefile
> @@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST)   += lvstest.o
>  
>  obj-$(CONFIG_USB_MUX)+= mux.o
>  obj-$(CONFIG_INTEL_MUX_GPIO) += intel-mux-gpio.o
> +obj-$(CONFIG_INTEL_MUX_DRCFG)+= intel-mux-drcfg.o
> diff --git a/drivers/usb/misc/intel-mux-drcfg.c 
> b/drivers/usb/misc/intel-mux-drcfg.c
> new file mode 100644
> index 000..29081c5
> --- /dev/null
> +++ b/drivers/usb/misc/intel-mux-drcfg.c
> @@ -0,0 +1,174 @@
> +/**
> + * intel-mux-drcfg.c - Driver for Intel USB mux via register
> + *
> + * Copyright (C) 2016 Intel Corporation
> + * Author: Heikki Krogerus 
> + * Author: Lu Baolu 
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2 as
> + * published by the Free Software Foundation.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#define INTEL_MUX_CFG0   0x00
> +#define INTEL_MUX_CFG1   0x04
> +#define CFG0_SW_IDPINBIT(20)
> +#define CFG0_SW_IDPIN_EN BIT(21)
> +#define CFG0_SW_VBUS_VALID   BIT(24)
> +#define CFG1_SW_MODE BIT(29)
> +#define CFG1_POLL_TIMEOUT1000
> +
> +struct intel_usb_mux {
> + struct usb_mux_dev umdev;
> + void __iomem *regs;
> + u32 cfg0_ctx;
> +};
> +
> +static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool 
> host)
> +{
> + struct intel_usb_mux *mux;
> + unsigned long timeout;
> + u32 data;
> +
> + mux = container_of(umdev, struct intel_usb_mux, umdev);
> +
> + /* Check and set mux to SW controlled mode */
> + data = readl(mux->regs + INTEL_MUX_CFG0);
> + if (!(data & CFG0_SW_IDPIN_EN)) {
> + data |= CFG0_SW_IDPIN_EN;
> + writel(data, mux->regs + INTEL_MUX_CFG0);
> + }
> +
> + /*
> +  * Configure CFG0 to switch the mux and VBUS_VALID bit is
> +  * required for device mode.
> +  */
> + data = readl(mux->regs + INTEL_MUX_CFG0);
> + if (host)
> + data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> + else
> + data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
> + writel(data, mux->regs + INTEL_MUX_CFG0);
> +
> + /*
> +  * Polling CFG1 for safety, most case it takes about 600ms
> +  * to finish mode switching, set TIMEOUT long enough.
> +  */
> + timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
> +
> + /* Polling on CFG1 register to confirm mode switch. */
> + while (!time_after(jiffies, timeout)) {
> + data = readl(mux->regs + INTEL_MUX_CFG1);
> + if (!(host ^ (data & CFG1_SW_MODE)))
> + return 0;
> + /* interval for polling is set to about 5ms */
> + usleep_range(5000, 5100);
> + }
> +
> + return -ETIMEDOUT;
> +}
> +
> +static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
> +{
> + dev_dbg(umdev->dev, "drcfg mux switch to 

Re: [PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread Greg Kroah-Hartman
On Thu, Mar 03, 2016 at 02:37:42PM +0800, Lu Baolu wrote:
> Several Intel PCHs and SOCs have an internal mux that is used to
> share one USB port between device controller and host controller.
> The mux is handled through the Dual Role Configuration Register.
> 
> Signed-off-by: Heikki Krogerus 
> Signed-off-by: Lu Baolu 
> Signed-off-by: Wu Hao 
> Reviewed-by: Felipe Balbi 
> ---
>  MAINTAINERS|   1 +
>  drivers/usb/misc/Kconfig   |   7 ++
>  drivers/usb/misc/Makefile  |   1 +
>  drivers/usb/misc/intel-mux-drcfg.c | 174 
> +

If you are going to start having a bunch of these, please make a new
directory, drivers/usb/mux/ ?

--
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 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-03 Thread kbuild test robot
Hi Lu,

[auto build test ERROR on usb/usb-testing]
[also build test ERROR on v4.5-rc6 next-20160303]
[if your patch is applied to the wrong git tree, please drop us a note to help 
improving the system]

url:
https://github.com/0day-ci/linux/commits/Lu-Baolu/usb-add-support-for-Intel-dual-role-port-mux/20160303-144241
base:   https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git 
usb-testing
config: arm64-allyesconfig (attached as .config)
reproduce:
wget 
https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross
 -O ~/bin/make.cross
chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64 

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

   drivers/usb/misc/intel-mux-drcfg.c: In function 'intel_mux_drcfg_switch':
>> drivers/usb/misc/intel-mux-drcfg.c:42:2: error: implicit declaration of 
>> function 'readl' [-Werror=implicit-function-declaration]
 data = readl(mux->regs + INTEL_MUX_CFG0);
 ^
>> drivers/usb/misc/intel-mux-drcfg.c:45:3: error: implicit declaration of 
>> function 'writel' [-Werror=implicit-function-declaration]
  writel(data, mux->regs + INTEL_MUX_CFG0);
  ^
   drivers/usb/misc/intel-mux-drcfg.c: In function 'intel_mux_drcfg_probe':
>> drivers/usb/misc/intel-mux-drcfg.c:108:2: error: implicit declaration of 
>> function 'devm_ioremap_nocache' [-Werror=implicit-function-declaration]
 mux->regs = devm_ioremap_nocache(dev, start, size);
 ^
>> drivers/usb/misc/intel-mux-drcfg.c:108:12: warning: assignment makes pointer 
>> from integer without a cast
 mux->regs = devm_ioremap_nocache(dev, start, size);
   ^
   cc1: some warnings being treated as errors

vim +/readl +42 drivers/usb/misc/intel-mux-drcfg.c

36  unsigned long timeout;
37  u32 data;
38  
39  mux = container_of(umdev, struct intel_usb_mux, umdev);
40  
41  /* Check and set mux to SW controlled mode */
  > 42  data = readl(mux->regs + INTEL_MUX_CFG0);
43  if (!(data & CFG0_SW_IDPIN_EN)) {
44  data |= CFG0_SW_IDPIN_EN;
  > 45  writel(data, mux->regs + INTEL_MUX_CFG0);
46  }
47  
48  /*
49   * Configure CFG0 to switch the mux and VBUS_VALID bit is
50   * required for device mode.
51   */
52  data = readl(mux->regs + INTEL_MUX_CFG0);
53  if (host)
54  data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
55  else
56  data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
57  writel(data, mux->regs + INTEL_MUX_CFG0);
58  
59  /*
60   * Polling CFG1 for safety, most case it takes about 600ms
61   * to finish mode switching, set TIMEOUT long enough.
62   */
63  timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
64  
65  /* Polling on CFG1 register to confirm mode switch. */
66  while (!time_after(jiffies, timeout)) {
67  data = readl(mux->regs + INTEL_MUX_CFG1);
68  if (!(host ^ (data & CFG1_SW_MODE)))
69  return 0;
70  /* interval for polling is set to about 5ms */
71  usleep_range(5000, 5100);
72  }
73  
74  return -ETIMEDOUT;
75  }
76  
77  static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
78  {
79  dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
80  
81  return intel_mux_drcfg_switch(umdev, true);
82  }
83  
84  static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
85  {
86  dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
87  
88  return intel_mux_drcfg_switch(umdev, false);
89  }
90  
91  static int intel_mux_drcfg_probe(struct platform_device *pdev)
92  {
93  struct intel_usb_mux *mux;
94  struct usb_mux_dev *umdev;
95  struct device *dev = >dev;
96  u64 start, size;
97  int ret;
98  
99  mux = devm_kzalloc(dev, sizeof(*mux), GFP_KERNEL);
   100  if (!mux)
   101  return -ENOMEM;
   102  
   103  ret = device_property_read_u64(dev, "reg-start", );
   104  ret |= device_property_read_u64(dev, "reg-size", );
   105  if (ret)
   106  return -ENODEV;
   107  
 > 108  mux->regs = devm_ioremap_nocache(dev, start, size);
   109  if (!mux->regs)
   110  return -ENOMEM;
   111  

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


.config.gz
Description: Binary data


[PATCH 5/7] usb: misc: add driver for Intel drcfg controlled port mux

2016-03-02 Thread Lu Baolu
Several Intel PCHs and SOCs have an internal mux that is used to
share one USB port between device controller and host controller.
The mux is handled through the Dual Role Configuration Register.

Signed-off-by: Heikki Krogerus 
Signed-off-by: Lu Baolu 
Signed-off-by: Wu Hao 
Reviewed-by: Felipe Balbi 
---
 MAINTAINERS|   1 +
 drivers/usb/misc/Kconfig   |   7 ++
 drivers/usb/misc/Makefile  |   1 +
 drivers/usb/misc/intel-mux-drcfg.c | 174 +
 4 files changed, 183 insertions(+)
 create mode 100644 drivers/usb/misc/intel-mux-drcfg.c

diff --git a/MAINTAINERS b/MAINTAINERS
index 0f321e4..20eb873 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -11396,6 +11396,7 @@ S:  Supported
 F: drivers/usb/misc/mux.c
 F: include/linux/usb/mux.h
 F: drivers/usb/misc/intel-mux-gpio.c
+F: drivers/usb/misc/intel-mux-drcfg.c
 
 USB PRINTER DRIVER (usblp)
 M: Pete Zaitcev 
diff --git a/drivers/usb/misc/Kconfig b/drivers/usb/misc/Kconfig
index 33e6386..befd910 100644
--- a/drivers/usb/misc/Kconfig
+++ b/drivers/usb/misc/Kconfig
@@ -281,3 +281,10 @@ config INTEL_MUX_GPIO
help
  Say Y here to enable support for Intel dual role port mux
  controlled by GPIOs.
+
+config INTEL_MUX_DRCFG
+   tristate "Intel dual role port mux controlled by register"
+   select USB_MUX
+   help
+ Say Y here to enable support for Intel dual role port mux
+ controlled by the Dual Role Configuration Registers.
diff --git a/drivers/usb/misc/Makefile b/drivers/usb/misc/Makefile
index da4fb4e..c4d19a0 100644
--- a/drivers/usb/misc/Makefile
+++ b/drivers/usb/misc/Makefile
@@ -32,3 +32,4 @@ obj-$(CONFIG_USB_LINK_LAYER_TEST) += lvstest.o
 
 obj-$(CONFIG_USB_MUX)  += mux.o
 obj-$(CONFIG_INTEL_MUX_GPIO)   += intel-mux-gpio.o
+obj-$(CONFIG_INTEL_MUX_DRCFG)  += intel-mux-drcfg.o
diff --git a/drivers/usb/misc/intel-mux-drcfg.c 
b/drivers/usb/misc/intel-mux-drcfg.c
new file mode 100644
index 000..29081c5
--- /dev/null
+++ b/drivers/usb/misc/intel-mux-drcfg.c
@@ -0,0 +1,174 @@
+/**
+ * intel-mux-drcfg.c - Driver for Intel USB mux via register
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Author: Heikki Krogerus 
+ * Author: Lu Baolu 
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define INTEL_MUX_CFG0 0x00
+#define INTEL_MUX_CFG1 0x04
+#define CFG0_SW_IDPIN  BIT(20)
+#define CFG0_SW_IDPIN_EN   BIT(21)
+#define CFG0_SW_VBUS_VALID BIT(24)
+#define CFG1_SW_MODE   BIT(29)
+#define CFG1_POLL_TIMEOUT  1000
+
+struct intel_usb_mux {
+   struct usb_mux_dev umdev;
+   void __iomem *regs;
+   u32 cfg0_ctx;
+};
+
+static inline int intel_mux_drcfg_switch(struct usb_mux_dev *umdev, bool host)
+{
+   struct intel_usb_mux *mux;
+   unsigned long timeout;
+   u32 data;
+
+   mux = container_of(umdev, struct intel_usb_mux, umdev);
+
+   /* Check and set mux to SW controlled mode */
+   data = readl(mux->regs + INTEL_MUX_CFG0);
+   if (!(data & CFG0_SW_IDPIN_EN)) {
+   data |= CFG0_SW_IDPIN_EN;
+   writel(data, mux->regs + INTEL_MUX_CFG0);
+   }
+
+   /*
+* Configure CFG0 to switch the mux and VBUS_VALID bit is
+* required for device mode.
+*/
+   data = readl(mux->regs + INTEL_MUX_CFG0);
+   if (host)
+   data &= ~(CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+   else
+   data |= (CFG0_SW_IDPIN | CFG0_SW_VBUS_VALID);
+   writel(data, mux->regs + INTEL_MUX_CFG0);
+
+   /*
+* Polling CFG1 for safety, most case it takes about 600ms
+* to finish mode switching, set TIMEOUT long enough.
+*/
+   timeout = jiffies + msecs_to_jiffies(CFG1_POLL_TIMEOUT);
+
+   /* Polling on CFG1 register to confirm mode switch. */
+   while (!time_after(jiffies, timeout)) {
+   data = readl(mux->regs + INTEL_MUX_CFG1);
+   if (!(host ^ (data & CFG1_SW_MODE)))
+   return 0;
+   /* interval for polling is set to about 5ms */
+   usleep_range(5000, 5100);
+   }
+
+   return -ETIMEDOUT;
+}
+
+static int intel_mux_drcfg_cable_set(struct usb_mux_dev *umdev)
+{
+   dev_dbg(umdev->dev, "drcfg mux switch to HOST\n");
+
+   return intel_mux_drcfg_switch(umdev, true);
+}
+
+static int intel_mux_drcfg_cable_unset(struct usb_mux_dev *umdev)
+{
+   dev_dbg(umdev->dev, "drcfg mux switch to DEVICE\n");
+
+   return intel_mux_drcfg_switch(umdev, false);
+}
+