[PATCH v2 13/22] usb: dwc2: gadget: remove s3c_hsotg_ep_disable_force

2015-03-20 Thread Mian Yousaf Kaukab
Force argument is not used anymore. Clean up leftovers from
https://lkml.org/lkml/2014/12/9/283

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/gadget.c | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bbc25ec..b6b8ed1 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2764,7 +2764,7 @@ error:
  * s3c_hsotg_ep_disable - disable given endpoint
  * @ep: The endpoint to disable.
  */
-static int s3c_hsotg_ep_disable_force(struct usb_ep *ep, bool force)
+static int s3c_hsotg_ep_disable(struct usb_ep *ep)
 {
struct s3c_hsotg_ep *hs_ep = our_ep(ep);
struct dwc2_hsotg *hsotg = hs_ep->parent;
@@ -2807,10 +2807,6 @@ static int s3c_hsotg_ep_disable_force(struct usb_ep *ep, 
bool force)
return 0;
 }
 
-static int s3c_hsotg_ep_disable(struct usb_ep *ep)
-{
-   return s3c_hsotg_ep_disable_force(ep, false);
-}
 /**
  * on_list - check request is on the given endpoint
  * @ep: The endpoint to check.
-- 
1.9.1

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


[PATCH v2 15/22] usb: dwc2: host: add bus_suspend/bus_resume callback

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/hcd.c | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 36f0c69..0213763 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2305,6 +2305,22 @@ static void _dwc2_hcd_stop(struct usb_hcd *hcd)
usleep_range(1000, 3000);
 }
 
+static int _dwc2_hcd_suspend(struct usb_hcd *hcd)
+{
+   struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+
+   hsotg->lx_state = DWC2_L2;
+   return 0;
+}
+
+static int _dwc2_hcd_resume(struct usb_hcd *hcd)
+{
+   struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
+
+   hsotg->lx_state = DWC2_L0;
+   return 0;
+}
+
 /* Returns the current frame number */
 static int _dwc2_hcd_get_frame_number(struct usb_hcd *hcd)
 {
@@ -2675,6 +2691,9 @@ static struct hc_driver dwc2_hc_driver = {
.hub_status_data = _dwc2_hcd_hub_status_data,
.hub_control = _dwc2_hcd_hub_control,
.clear_tt_buffer_complete = _dwc2_hcd_clear_tt_buffer_complete,
+
+   .bus_suspend = _dwc2_hcd_suspend,
+   .bus_resume = _dwc2_hcd_resume,
 };
 
 /*
-- 
1.9.1

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


[PATCH v2 11/22] usb: dwc2: gadget: powerup controller if needed

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

During vbus session, usb controller needs to exit hibernation if it was
previously in suspend state.
Since controller will be resetted and configured, there is no need
to restore registers.

Moreover, set lx_state to L0 on B session. vbus_session callback may
not be used by all platforms. Thus, controller software state needs
to be set to L0 if the controller detects a valid B session.
Otherwise, lx_state will remain L2 and prevent any request submission.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/gadget.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 72df171..d94d0e8 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2515,6 +2515,7 @@ irq_retry:
kill_all_requests(hsotg, hsotg->eps_out[0],
  -ECONNRESET);
 
+   hsotg->lx_state = DWC2_L0;
s3c_hsotg_core_init_disconnected(hsotg, true);
}
}
@@ -3205,6 +3206,14 @@ static int s3c_hsotg_vbus_session(struct usb_gadget 
*gadget, int is_active)
spin_lock_irqsave(&hsotg->lock, flags);
 
if (is_active) {
+   /*
+* If controller is hibernated, it must exit from hibernation
+* before being initialized
+*/
+   if (hsotg->lx_state == DWC2_L2) {
+   dwc2_exit_hibernation(hsotg, false);
+   hsotg->lx_state = DWC2_L0;
+   }
/* Kill any ep0 requests as controller will be reinitialized */
kill_all_requests(hsotg, hsotg->eps_out[0], -ECONNRESET);
s3c_hsotg_core_init_disconnected(hsotg, false);
-- 
1.9.1

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


[PATCH v2 21/22] usb: dwc2: add hibernation core parameter

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

dwc2 may not be able to exit from hibernation if the hardware
does not provide a way to detect resume signalling in this state.
Thus, add the possibility to disable hibernation feature.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/core.c  | 24 
 drivers/usb/dwc2/core.h  |  7 +++
 drivers/usb/dwc2/core_intr.c |  7 ---
 drivers/usb/dwc2/platform.c  |  2 ++
 4 files changed, 37 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 7f461e3..e5b546f 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -342,6 +342,9 @@ int dwc2_exit_hibernation(struct dwc2_hsotg *hsotg, bool 
restore)
u32 pcgcctl;
int ret = 0;
 
+   if (!hsotg->core_params->hibernation)
+   return -ENOTSUPP;
+
pcgcctl = readl(hsotg->regs + PCGCTL);
pcgcctl &= ~PCGCTL_STOPPCLK;
writel(pcgcctl, hsotg->regs + PCGCTL);
@@ -392,6 +395,9 @@ int dwc2_enter_hibernation(struct dwc2_hsotg *hsotg)
u32 pcgcctl;
int ret = 0;
 
+   if (!hsotg->core_params->hibernation)
+   return -ENOTSUPP;
+
/* Backup all registers */
ret = dwc2_backup_global_registers(hsotg);
if (ret) {
@@ -2998,6 +3004,23 @@ static void dwc2_set_param_external_id_pin_ctl(struct 
dwc2_hsotg *hsotg,
hsotg->core_params->external_id_pin_ctl = val;
 }
 
+static void dwc2_set_param_hibernation(struct dwc2_hsotg *hsotg,
+   int val)
+{
+   if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
+   if (val >= 0) {
+   dev_err(hsotg->dev,
+   "'%d' invalid for parameter hibernation\n",
+   val);
+   dev_err(hsotg->dev, "hibernation must be 0 or 1\n");
+   }
+   val = 0;
+   dev_dbg(hsotg->dev, "Setting hibernation to %d\n", val);
+   }
+
+   hsotg->core_params->hibernation = val;
+}
+
 /*
  * This function is called during module intialization to pass module 
parameters
  * for the DWC_otg core.
@@ -3043,6 +3066,7 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
dwc2_set_param_otg_ver(hsotg, params->otg_ver);
dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
+   dwc2_set_param_hibernation(hsotg, params->hibernation);
 }
 
 /**
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index d7fb1f7..53b8de0 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -336,6 +336,12 @@ enum dwc2_ep0_state {
  *  case.
  *  0 - No (default)
  *  1 - Yes
+ * @hibernation:   Specifies whether the controller support hibernation.
+ * If hibernation is enabled, the controller will enter
+ * hibernation in both peripheral and host mode when
+ * needed.
+ * 0 - No (default)
+ * 1 - Yes
  *
  * The following parameters may be specified when starting the module. These
  * parameters define how the DWC_otg controller should be configured. A
@@ -374,6 +380,7 @@ struct dwc2_core_params {
int ahbcfg;
int uframe_sched;
int external_id_pin_ctl;
+   int hibernation;
 };
 
 /**
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index e66eb38..940582f 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -347,7 +347,7 @@ static void dwc2_handle_wakeup_detected_intr(struct 
dwc2_hsotg *hsotg)
dctl &= ~DCTL_RMTWKUPSIG;
writel(dctl, hsotg->regs + DCTL);
ret = dwc2_exit_hibernation(hsotg, true);
-   if (ret)
+   if (ret && (ret != -ENOTSUPP))
dev_err(hsotg->dev, "exit hibernation 
failed\n");
 
call_gadget(hsotg, resume);
@@ -425,8 +425,9 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg 
*hsotg)
 
ret = dwc2_enter_hibernation(hsotg);
if (ret) {
-   dev_err(hsotg->dev,
-   "enter hibernation failed\n");
+   if (ret != -ENOTSUPP)
+   dev_err(hsotg->dev,
+   "enter hibernation 
failed\n");
goto skip_power_saving;
}
 
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 2562c90..9093530 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -78,6 +78,7 @@ static const struct dwc2_core_params params_bcm2835 = {
.ahbcfg = 0x10,

[PATCH v2 19/22] usb: dwc2: host: implement test mode

2015-03-20 Thread Mian Yousaf Kaukab
From: Jingwu Lin 

Add support for SetPortFeature(PORT_TEST) for root port.

Signed-off-by: Jingwu Lin 
---
 drivers/usb/dwc2/hcd.c | 9 +
 1 file changed, 9 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 3c8f68c..c8a5005 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -1766,6 +1766,15 @@ static int dwc2_hcd_hub_control(struct dwc2_hsotg 
*hsotg, u16 typereq,
/* Not supported */
break;
 
+   case USB_PORT_FEAT_TEST:
+   hprt0 = dwc2_read_hprt0(hsotg);
+   dev_dbg(hsotg->dev,
+   "SetPortFeature - USB_PORT_FEAT_TEST\n");
+   hprt0 &= ~HPRT0_TSTCTL_MASK;
+   hprt0 |= (windex >> 8) << HPRT0_TSTCTL_SHIFT;
+   writel(hprt0, hsotg->regs + HPRT0);
+   break;
+
default:
retval = -EINVAL;
dev_err(hsotg->dev,
-- 
1.9.1

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


[PATCH v2 12/22] usb: dwc2: gadget: enable otg flag in dual role configuration

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/gadget.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index d94d0e8..bbc25ec 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3525,6 +3525,8 @@ int dwc2_gadget_init(struct dwc2_hsotg *hsotg, int irq)
hsotg->gadget.max_speed = USB_SPEED_HIGH;
hsotg->gadget.ops = &s3c_hsotg_gadget_ops;
hsotg->gadget.name = dev_name(dev);
+   if (hsotg->dr_mode == USB_DR_MODE_OTG)
+   hsotg->gadget.is_otg = 1;
 
/* reset the system */
 
-- 
1.9.1

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


[PATCH v2 20/22] usb: dwc2: remove dwc2_platform.ko

2015-03-20 Thread Mian Yousaf Kaukab
As dwc2 pci module is now exporting dwc2 platform device, include
platform.o in dwc2-y and remove USB_DWC2_PLATFORM configuration
option. Driver will be built as two modules, dwc2.ko and dwc2_pci.ko.
dwc2.ko is the new platform driver.

Remove all EXPORT_SYMBOL_GPL as they are not needed any more.

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/Kconfig | 8 
 drivers/usb/dwc2/Makefile| 5 +
 drivers/usb/dwc2/core.c  | 3 ---
 drivers/usb/dwc2/core_intr.c | 1 -
 drivers/usb/dwc2/debugfs.c   | 2 --
 drivers/usb/dwc2/gadget.c| 5 -
 drivers/usb/dwc2/hcd.c   | 2 --
 7 files changed, 1 insertion(+), 25 deletions(-)

diff --git a/drivers/usb/dwc2/Kconfig b/drivers/usb/dwc2/Kconfig
index 1bcb36a..fd95ba6 100644
--- a/drivers/usb/dwc2/Kconfig
+++ b/drivers/usb/dwc2/Kconfig
@@ -50,18 +50,10 @@ config USB_DWC2_DUAL_ROLE
  option requires USB_GADGET to be enabled.
 endchoice
 
-config USB_DWC2_PLATFORM
-   tristate "DWC2 Platform"
-   default USB_DWC2_HOST || USB_DWC2_PERIPHERAL
-help
-  The Designware USB2.0 platform interface module for
-  controllers directly connected to the CPU.
-
 config USB_DWC2_PCI
tristate "DWC2 PCI"
depends on PCI
default n
-   select USB_DWC2_PLATFORM
select NOP_USB_XCEIV
help
  The Designware USB2.0 PCI interface module for controllers
diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
index 147d759..1547002 100644
--- a/drivers/usb/dwc2/Makefile
+++ b/drivers/usb/dwc2/Makefile
@@ -2,7 +2,7 @@ ccflags-$(CONFIG_USB_DWC2_DEBUG)+= -DDEBUG
 ccflags-$(CONFIG_USB_DWC2_VERBOSE) += -DVERBOSE_DEBUG
 
 obj-$(CONFIG_USB_DWC2) += dwc2.o
-dwc2-y := core.o core_intr.o
+dwc2-y := core.o core_intr.o platform.o
 
 ifneq ($(filter y,$(CONFIG_USB_DWC2_HOST) $(CONFIG_USB_DWC2_DUAL_ROLE)),)
dwc2-y  += hcd.o hcd_intr.o
@@ -27,6 +27,3 @@ ifneq ($(CONFIG_USB_DWC2_PCI),)
obj-$(CONFIG_USB_DWC2)  += dwc2_pci.o
dwc2_pci-y  := pci.o
 endif
-
-obj-$(CONFIG_USB_DWC2_PLATFORM)+= dwc2_platform.o
-dwc2_platform-y:= platform.o
diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 6acbe90..7f461e3 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -3044,7 +3044,6 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
 }
-EXPORT_SYMBOL_GPL(dwc2_set_parameters);
 
 /**
  * During device initialization, read various hardware configuration
@@ -3211,7 +3210,6 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
 
return 0;
 }
-EXPORT_SYMBOL_GPL(dwc2_get_hwparams);
 
 /*
  * Sets all parameters to the given value.
@@ -3227,7 +3225,6 @@ void dwc2_set_all_params(struct dwc2_core_params *params, 
int value)
for (i = 0; i < size; i++)
p[i] = value;
 }
-EXPORT_SYMBOL_GPL(dwc2_set_all_params);
 
 
 u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg)
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index f5ef26e..e66eb38 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -556,4 +556,3 @@ out:
spin_unlock(&hsotg->lock);
return retval;
 }
-EXPORT_SYMBOL_GPL(dwc2_handle_common_intr);
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
index af89537..ef2ee3d 100644
--- a/drivers/usb/dwc2/debugfs.c
+++ b/drivers/usb/dwc2/debugfs.c
@@ -763,11 +763,9 @@ err1:
 err0:
return ret;
 }
-EXPORT_SYMBOL_GPL(dwc2_debugfs_init);
 
 void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg)
 {
debugfs_remove_recursive(hsotg->debug_root);
hsotg->debug_root = NULL;
 }
-EXPORT_SYMBOL_GPL(dwc2_debugfs_exit);
diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index b6b8ed1..b0adc63 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2190,7 +2190,6 @@ void s3c_hsotg_disconnect(struct dwc2_hsotg *hsotg)
 
call_gadget(hsotg, disconnect);
 }
-EXPORT_SYMBOL_GPL(s3c_hsotg_disconnect);
 
 /**
  * s3c_hsotg_irq_fifoempty - TX FIFO empty interrupt handler
@@ -3666,7 +3665,6 @@ err_clk:
 
return ret;
 }
-EXPORT_SYMBOL_GPL(dwc2_gadget_init);
 
 /**
  * s3c_hsotg_remove - remove function for hsotg driver
@@ -3679,7 +3677,6 @@ int s3c_hsotg_remove(struct dwc2_hsotg *hsotg)
 
return 0;
 }
-EXPORT_SYMBOL_GPL(s3c_hsotg_remove);
 
 int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
 {
@@ -3722,7 +3719,6 @@ int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
 
return ret;
 }
-EXPORT_SYMBOL_GPL(s3c_hsotg_suspend);
 
 int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
 {
@@ -3754,4 +3750,3 @@ int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
 
return ret

[PATCH v2 16/22] usb: dwc2: host: resume root hub on port connect

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Once hub is runtime suspended, dwc2 must resume it
on port connect event.
Else, roothub will stay in suspended state and will
not resume transfers.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/hcd_intr.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c
index 551ba87..6927bba 100644
--- a/drivers/usb/dwc2/hcd_intr.c
+++ b/drivers/usb/dwc2/hcd_intr.c
@@ -350,6 +350,9 @@ static void dwc2_port_intr(struct dwc2_hsotg *hsotg)
dev_vdbg(hsotg->dev,
 "--Port Interrupt HPRT0=0x%08x Port Connect 
Detected--\n",
 hprt0);
+   if (hsotg->lx_state != DWC2_L0)
+   usb_hcd_resume_root_hub(hsotg->priv);
+
hsotg->flags.b.port_connect_status_change = 1;
hsotg->flags.b.port_connect_status = 1;
hprt0_modify |= HPRT0_CONNDET;
-- 
1.9.1

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


[PATCH v2 10/22] usb: dwc2: gadget: prevent new request submission during suspend

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

If usb controller is in partial power down, any write to registers may
cause unpredictable behavior.
Thus, prevent any new request submission once controller is in partial
power down.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/gadget.c | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 539a3d4..72df171 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -790,6 +790,13 @@ static int s3c_hsotg_ep_queue(struct usb_ep *ep, struct 
usb_request *req,
ep->name, req, req->length, req->buf, req->no_interrupt,
req->zero, req->short_not_ok);
 
+   /* Prevent new request submission when controller is suspended */
+   if (hs->lx_state == DWC2_L2) {
+   dev_dbg(hs->dev, "%s: don't submit request while suspended\n",
+   __func__);
+   return -EAGAIN;
+   }
+
/* initialise status of the request */
INIT_LIST_HEAD(&hs_req->queue);
req->actual = 0;
-- 
1.9.1

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


[PATCH v2 06/22] usb: dwc2: add external_id_pin_ctl core parameter

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

This is required due to an Intel specific hardware issue. Where id-
pin setup causes glitches on the interrupt line when CONIDSTSCHG
interrupt is enabled.

Specify external_id_pin_ctl when an external driver (for example phy)
can handle id change, so that CONIDSTSCHG interrupt can be disabled
from the controller.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/core.c | 22 +-
 drivers/usb/dwc2/core.h |  6 ++
 drivers/usb/dwc2/platform.c |  2 ++
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 889dc5f..8c3bc84 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -454,8 +454,10 @@ static void dwc2_enable_common_interrupts(struct 
dwc2_hsotg *hsotg)
 
if (hsotg->core_params->dma_enable <= 0)
intmsk |= GINTSTS_RXFLVL;
+   if (hsotg->core_params->external_id_pin_ctl <= 0)
+   intmsk |= GINTSTS_CONIDSTSCHNG;
 
-   intmsk |= GINTSTS_CONIDSTSCHNG | GINTSTS_WKUPINT | GINTSTS_USBSUSP |
+   intmsk |= GINTSTS_WKUPINT | GINTSTS_USBSUSP |
  GINTSTS_SESSREQINT;
 
writel(intmsk, hsotg->regs + GINTMSK);
@@ -2979,6 +2981,23 @@ static void dwc2_set_param_uframe_sched(struct 
dwc2_hsotg *hsotg, int val)
hsotg->core_params->uframe_sched = val;
 }
 
+static void dwc2_set_param_external_id_pin_ctl(struct dwc2_hsotg *hsotg,
+   int val)
+{
+   if (DWC2_OUT_OF_BOUNDS(val, 0, 1)) {
+   if (val >= 0) {
+   dev_err(hsotg->dev,
+   "'%d' invalid for parameter 
external_id_pin_ctl\n",
+   val);
+   dev_err(hsotg->dev, "external_id_pin_ctl must be 0 or 
1\n");
+   }
+   val = 0;
+   dev_dbg(hsotg->dev, "Setting external_id_pin_ctl to %d\n", val);
+   }
+
+   hsotg->core_params->external_id_pin_ctl = val;
+}
+
 /*
  * This function is called during module intialization to pass module 
parameters
  * for the DWC_otg core.
@@ -3023,6 +3042,7 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
dwc2_set_param_ahbcfg(hsotg, params->ahbcfg);
dwc2_set_param_otg_ver(hsotg, params->otg_ver);
dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
+   dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
 }
 
 /**
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index e6abc28..e46304d 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -331,6 +331,11 @@ enum dwc2_ep0_state {
  *  by the driver and are ignored in this
  *  configuration value.
  * @uframe_sched:   True to enable the microframe scheduler
+ * @external_id_pin_ctl: Specifies whether ID pin is handled externally.
+ *  Disable CONIDSTSCHNG controller interrupt in such
+ *  case.
+ *  0 - No (default)
+ *  1 - Yes
  *
  * The following parameters may be specified when starting the module. These
  * parameters define how the DWC_otg controller should be configured. A
@@ -368,6 +373,7 @@ struct dwc2_core_params {
int reload_ctl;
int ahbcfg;
int uframe_sched;
+   int external_id_pin_ctl;
 };
 
 /**
diff --git a/drivers/usb/dwc2/platform.c b/drivers/usb/dwc2/platform.c
index 4fb058b..ce39e8a0 100644
--- a/drivers/usb/dwc2/platform.c
+++ b/drivers/usb/dwc2/platform.c
@@ -77,6 +77,7 @@ static const struct dwc2_core_params params_bcm2835 = {
.reload_ctl = 0,
.ahbcfg = 0x10,
.uframe_sched   = 0,
+   .external_id_pin_ctl= -1,
 };
 
 static const struct dwc2_core_params params_rk3066 = {
@@ -105,6 +106,7 @@ static const struct dwc2_core_params params_rk3066 = {
.reload_ctl = -1,
.ahbcfg = 0x7, /* INCR16 */
.uframe_sched   = -1,
+   .external_id_pin_ctl= -1,
 };
 
 /**
-- 
1.9.1

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


Re: [PATCH v2 08/22] usb: dwc2: gadget: use reset detect interrupt

2015-03-20 Thread Sergei Shtylyov

Hello.

On 03/20/2015 06:36 PM, Mian Yousaf Kaukab wrote:


From: Gregory Herrero 



ResetDet interrupt is used to detect a reset of the bus
while the controller is suspended.
This may happens for example when using Command Verifier.



Signed-off-by: Gregory Herrero 
---
  drivers/usb/dwc2/gadget.c | 19 ---
  1 file changed, 16 insertions(+), 3 deletions(-)



diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bed56dc..d528c02 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c

[...]

@@ -2475,7 +2476,19 @@ irq_retry:
}
}

-   if (gintsts & GINTSTS_USBRST) {
+   if (gintsts & GINTSTS_RESETDET) {
+   dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__);
+
+   writel(GINTSTS_RESETDET, hsotg->regs + GINTSTS);
+
+   /* This event must be used only if controller is suspended */
+   if (hsotg->lx_state == DWC2_L2) {
+   dwc2_exit_hibernation(hsotg, true);
+   hsotg->lx_state = DWC2_L0;
+   }
+   }
+
+   if ((gintsts & GINTSTS_USBRST) || (gintsts & GINTSTS_RESETDET)) {


if (gintsts & (GINTSTS_USBRST | GINTSTS_RESETDET)) {

[...]

WBR, Sergei

--
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 18/20] usb: dwc2: host: don't use dma_alloc_coherent with irqs disabled

2015-03-20 Thread Julius Werner
>> > -   qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size,
>> > - 
>> > &qh->dw_align_buf_dma,
>> > - GFP_ATOMIC);
>> > +   qh->dw_align_buf = kzalloc(buf_size, GFP_ATOMIC);
>>
>> Shouldn't this also set GFP_DMA? [...]
>
> No, it should be GFP_ATOMIC, as this can be reached from interrupt handler.

Are the two mutually exclusive? I meant that I think this should be
'kzalloc(buf_size, GFP_DMA | GFP_ATOMIC)', because I wouldn't be sure
that GFP_ATOMIC always returns DMA-able memory on systems that may
have limitations there.

>> > }
>> > }
>> >
>> > +   qh->dw_align_buf_dma = dma_map_single(hsotg->dev,
>> > +   qh->dw_align_buf, qh->dw_align_buf_size,
>> > + DMA_TO_DEVICE);
>>
>> Documentation/DMA-API.txt says that you must always use the same
>> arguments for matching dma_map_single() and dma_unmap_single()... so I
>> think this and all the unmaps should use DMA_BIDIRECTIONAL.
>
> The mapping is wrong. It should consider endpoint direction. Something like 
> chan->ep_is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE

Yeah, I think this should work as well.

However, looking at this again I think there are more problems on
unmapping. Since some of those calls are guarded by chan->ep_is_in,
you will not unmap the memory out OUT transfers. DMA map/unmap calls
must always be balanced.

I think in all the cases where the code previously had something like

if (chan->align_buf && chan->ep_is_in) {
  memcpy(...);
  ...;
}

you'll need to change it into

if (chan->align_buf) {
  if (chan->ep_is_in) {
memcpy(...);
dma_unmap_single(..., DMA_FROM_DEVICE);
...
  } else {
dma_unmap_single(..., DMA_TO_DEVICE);
  }
}

You might also want to double-check all abnormal error paths to ensure
you're not leaking a DMA mapping. The previous code might not have
been so careful (since for a really bad error you usually don't care
about memcpy()ing the receive buffer back), but if you use DMA
mappings you have to.
--
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 v3 1/2] make xhci platform driver use 64 bit or 32 bit DMA

2015-03-20 Thread Feng Kan
On Tue, Nov 25, 2014 at 1:19 PM, Mark Langsdorf  wrote:
> The xhci platform driver needs to work on systems that either only
> support 64-bit DMA or only support 32-bit DMA. Attempt to set a
> coherent dma mask for 64-bit DMA, and attempt again with 32-bit
> DMA if that fails.
>
> Signed-off-by: Mark Langsdorf 
> Tested-by: Mark Salter 
> ---
> Changes from v2:
> None
> Changes from v1:
> Consolidated to use dma_set_mask_and_coherent
> Got rid of the check against sizeof(dma_addr_t)
>
>  drivers/usb/host/xhci-plat.c | 16 
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 3d78b0c..34cbf65 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -96,14 +96,14 @@ static int xhci_plat_probe(struct platform_device *pdev)
> return ret;
> }
>
> -   /* Initialize dma_mask and coherent_dma_mask to 32-bits */
> -   ret = dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(32));
> -   if (ret)
> -   return ret;
> -   if (!pdev->dev.dma_mask)
> -   pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
> -   else
> -   dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
> +   /* Try setting the coherent_dma_mask to 64 bits, then try 32 bits */
> +   ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
> +   if (ret) {
> +   ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
> +   if (ret)
> +   return ret;
> +   }
> +
>
> hcd = usb_create_hcd(driver, &pdev->dev, dev_name(&pdev->dev));
> if (!hcd)
> --
> 1.9.3
>

Tested-by: Feng Kan 
> --
> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v2 00/13] musb: Add support for the Allwinner sunxi musb controller

2015-03-20 Thread Hans de Goede
Hi All,

Here is v2 of my patch-set to add support for the musb variant found on
Allwinner sunxi SoCs.

Changes since the original posting:
-Removed the sunxi specific phy functions, instead the id / vbus gpio polling
 has been moved to the phy-sun4i-usb driver and their status is exported
 through extcon for the sunxi-musb glue
-Stop using syscon, instead Maxime Ripard's sunxi SRAM controller driver is now
 used

This should address all review remarks against v1 of this patch-set, so
hopefully we can start merging this upstream.

The "musb: Add support for the Allwinner sunxi musb" commit relies on
Maxime's SRAM controller patches, so those need to get merged first,
but the phy-sun4i-usb and musb preparation patches can be merged already
(assuming there are no objections).

And then once the SRAM controller patches are in next we can also merge
the "musb: Add support for the Allwinner sunxi musb" commit and the dts
changes.

Regards,

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


[PATCH v2 04/13] musb: Do not use musb_read[b|w] / _write[b|w] wrappers in generic fifo functions

2015-03-20 Thread Hans de Goede
The generic fifo functions already use non wrapped accesses in various
cases through the iowrite#_rep functions, and all platforms which override
the default musb_read[b|w] / _write[b|w] functions also provide their own
fifo access functions, so we can safely drop the unnecessary indirection
from the fifo access functions.

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

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 01ed3a6..016b5b9 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -313,7 +313,7 @@ static void musb_default_write_fifo(struct musb_hw_ep 
*hw_ep, u16 len,
index += len & ~0x03;
}
if (len & 0x02) {
-   musb_writew(fifo, 0, *(u16 *)&src[index]);
+   __raw_writew(*(u16 *)&src[index], fifo);
index += 2;
}
} else {
@@ -323,7 +323,7 @@ static void musb_default_write_fifo(struct musb_hw_ep 
*hw_ep, u16 len,
}
}
if (len & 0x01)
-   musb_writeb(fifo, 0, src[index]);
+   __raw_writeb(src[index], fifo);
} else  {
/* byte aligned */
iowrite8_rep(fifo, src, len);
@@ -355,7 +355,7 @@ static void musb_default_read_fifo(struct musb_hw_ep 
*hw_ep, u16 len, u8 *dst)
index = len & ~0x03;
}
if (len & 0x02) {
-   *(u16 *)&dst[index] = musb_readw(fifo, 0);
+   *(u16 *)&dst[index] = __raw_readw(fifo);
index += 2;
}
} else {
@@ -365,7 +365,7 @@ static void musb_default_read_fifo(struct musb_hw_ep 
*hw_ep, u16 len, u8 *dst)
}
}
if (len & 0x01)
-   dst[index] = musb_readb(fifo, 0);
+   dst[index] = __raw_readb(fifo);
} else  {
/* byte aligned */
ioread8_rep(fifo, dst, len);
-- 
2.3.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 v2 05/13] musb: Fix platform code being unable to override ep access ops

2015-03-20 Thread Hans de Goede
musb-core was setting the ops to the default indexed or flat handlers after
checking for platform overrides. Reverse the order of this so that platform
overrides actually work.

Signed-off-by: Hans de Goede 
---
 drivers/usb/musb/musb_core.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 016b5b9..6e9b839 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -2021,13 +2021,7 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
if (musb->ops->quirks)
musb->io.quirks = musb->ops->quirks;
 
-   /* At least tusb6010 has it's own offsets.. */
-   if (musb->ops->ep_offset)
-   musb->io.ep_offset = musb->ops->ep_offset;
-   if (musb->ops->ep_select)
-   musb->io.ep_select = musb->ops->ep_select;
-
-   /* ..and some devices use indexed offset or flat offset */
+   /* Set default ep access to indexed offset or flat offset ops */
if (musb->io.quirks & MUSB_INDEXED_EP) {
musb->io.ep_offset = musb_indexed_ep_offset;
musb->io.ep_select = musb_indexed_ep_select;
@@ -2035,6 +2029,11 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
musb->io.ep_offset = musb_flat_ep_offset;
musb->io.ep_select = musb_flat_ep_select;
}
+   /* And override them with platform specific ops if specified. */
+   if (musb->ops->ep_offset)
+   musb->io.ep_offset = musb->ops->ep_offset;
+   if (musb->ops->ep_select)
+   musb->io.ep_select = musb->ops->ep_select;
 
if (musb->ops->fifo_mode)
fifo_mode = musb->ops->fifo_mode;
-- 
2.3.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 v2 03/13] musb: Make busctl_offset an io-op rather then a define

2015-03-20 Thread Hans de Goede
The Allwinner (sunxi) implementation of the musb has its busctl registers
indexed by the MUSB_INDEX register rather then in a flat address space.

This commit turns MUSB_BUSCTL_OFFSET from a macro into an io-op which can
be overridden from the platform ops.

Signed-off-by: Hans de Goede 
---
 drivers/usb/musb/musb_core.c | 34 +++-
 drivers/usb/musb/musb_core.h |  5 +++-
 drivers/usb/musb/musb_host.c | 12 -
 drivers/usb/musb/musb_io.h   |  2 ++
 drivers/usb/musb/musb_regs.h | 63 
 5 files changed, 68 insertions(+), 48 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index e2892fa..01ed3a6 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -250,6 +250,11 @@ static u32 musb_indexed_ep_offset(u8 epnum, u16 offset)
return 0x10 + offset;
 }
 
+static u32 musb_default_busctl_offset(u8 epnum, u16 offset)
+{
+   return 0x80 + (0x08 * epnum) + offset;
+}
+
 static u8 musb_default_readb(const void __iomem *addr, unsigned offset)
 {
return __raw_readb(addr + offset);
@@ -2041,6 +2046,11 @@ musb_init_controller(struct device *dev, int nIrq, void 
__iomem *ctrl)
else
musb->io.fifo_offset = musb_default_fifo_offset;
 
+   if (musb->ops->busctl_offset)
+   musb->io.busctl_offset = musb->ops->busctl_offset;
+   else
+   musb->io.busctl_offset = musb_default_busctl_offset;
+
if (musb->ops->readb)
musb_readb = musb->ops->readb;
if (musb->ops->writeb)
@@ -2314,18 +2324,18 @@ static void musb_save_context(struct musb *musb)
musb_readb(epio, MUSB_RXINTERVAL);
 
musb->context.index_regs[i].txfunaddr =
-   musb_read_txfunaddr(musb_base, i);
+   musb_read_txfunaddr(musb, i);
musb->context.index_regs[i].txhubaddr =
-   musb_read_txhubaddr(musb_base, i);
+   musb_read_txhubaddr(musb, i);
musb->context.index_regs[i].txhubport =
-   musb_read_txhubport(musb_base, i);
+   musb_read_txhubport(musb, i);
 
musb->context.index_regs[i].rxfunaddr =
-   musb_read_rxfunaddr(musb_base, i);
+   musb_read_rxfunaddr(musb, i);
musb->context.index_regs[i].rxhubaddr =
-   musb_read_rxhubaddr(musb_base, i);
+   musb_read_rxhubaddr(musb, i);
musb->context.index_regs[i].rxhubport =
-   musb_read_rxhubport(musb_base, i);
+   musb_read_rxhubport(musb, i);
}
 }
 
@@ -2393,18 +2403,18 @@ static void musb_restore_context(struct musb *musb)
musb_writeb(epio, MUSB_RXINTERVAL,
 
musb->context.index_regs[i].rxinterval);
-   musb_write_txfunaddr(musb_base, i,
+   musb_write_txfunaddr(musb, i,
musb->context.index_regs[i].txfunaddr);
-   musb_write_txhubaddr(musb_base, i,
+   musb_write_txhubaddr(musb, i,
musb->context.index_regs[i].txhubaddr);
-   musb_write_txhubport(musb_base, i,
+   musb_write_txhubport(musb, i,
musb->context.index_regs[i].txhubport);
 
-   musb_write_rxfunaddr(musb_base, i,
+   musb_write_rxfunaddr(musb, i,
musb->context.index_regs[i].rxfunaddr);
-   musb_write_rxhubaddr(musb_base, i,
+   musb_write_rxhubaddr(musb, i,
musb->context.index_regs[i].rxhubaddr);
-   musb_write_rxhubport(musb_base, i,
+   musb_write_rxhubport(musb, i,
musb->context.index_regs[i].rxhubport);
}
musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index a31d709..ba8dd78 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -67,7 +67,6 @@ struct musb_ep;
 #include "musb_dma.h"
 
 #include "musb_io.h"
-#include "musb_regs.h"
 
 #include "musb_gadget.h"
 #include 
@@ -186,6 +185,7 @@ struct musb_platform_ops {
void(*ep_select)(void __iomem *mbase, u8 epnum);
u16 fifo_mode;
u32 (*fifo_offset)(u8 epnum);
+   u32 (*busctl_offset)(u8 epnum, u16 offset);
u8  (*readb)(const void __iomem *addr, unsigned offset);
void(*writeb)(void __iomem *addr, unsigned offset, u8 data);
u16 (*readw)(const void __iomem *addr, unsigned offset);
@@ -435,6 +435,9 @@ struct musb {
 #endif
 };
 
+/* This must be included after struct musb is defined */
+#include "musb_regs.h"
+
 static inline struct musb *gadget_to_musb(stru

[PATCH v2 01/13] phy-sun4i-usb: Add full support for usb0 phy / OTG

2015-03-20 Thread Hans de Goede
The usb0 phy is connected to an OTG controller, and as such needs some special
handling:

1) It allows explicit control over the pullups, enable these on phy_init and
disable them on phy_exit.

2) It has bits to signal id and vbus detect to the musb-core, add support for
for monitoring id and vbus detect gpio-s for use in dual role mode, and set
these bits to the correct values for operating in host only mode when no
gpios are specified in the devicetree.

3) When in dual role mode the musb sunxi glue needs to know if the a host or
device cable is plugged in, so when in dual role mode register an extcon.

While updating the devicetree binding documentation also add documentation
for the sofar undocumented usage of regulators for vbus for all 3 phys.

Signed-off-by: Hans de Goede 
---
 .../devicetree/bindings/phy/sun4i-usb-phy.txt  |  18 +-
 drivers/phy/Kconfig|   1 +
 drivers/phy/phy-sun4i-usb.c| 269 -
 3 files changed, 277 insertions(+), 11 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt 
b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
index 16528b9..557fa99 100644
--- a/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
+++ b/Documentation/devicetree/bindings/phy/sun4i-usb-phy.txt
@@ -23,6 +23,13 @@ Required properties:
   * "usb1_reset"
   * "usb2_reset" for sun4i, sun6i or sun7i
 
+Optional properties:
+- usb0_id_det-gpios : gpio phandle for reading the otg id pin value
+- usb0_vbus_det-gpios : gpio phandle for detecting the presence of usb0 vbus
+- usb0_vbus-supply : regulator phandle for controller usb0 vbus
+- usb1_vbus-supply : regulator phandle for controller usb1 vbus
+- usb2_vbus-supply : regulator phandle for controller usb2 vbus
+
 Example:
usbphy: phy@0x01c13400 {
#phy-cells = <1>;
@@ -32,6 +39,13 @@ Example:
reg-names = "phy_ctrl", "pmu1", "pmu2";
clocks = <&usb_clk 8>;
clock-names = "usb_phy";
-   resets = <&usb_clk 1>, <&usb_clk 2>;
-   reset-names = "usb1_reset", "usb2_reset";
+   resets = <&usb_clk 0>, <&usb_clk 1>, <&usb_clk 2>;
+   reset-names = "usb0_reset", "usb1_reset", "usb2_reset";
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+   usb0_id_det-gpios = <&pio 7 19 GPIO_ACTIVE_HIGH>; /* PH19 */
+   usb0_vbus_det-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */
+   usb0_vbus-supply = <®_usb0_vbus>;
+   usb1_vbus-supply = <®_usb1_vbus>;
+   usb2_vbus-supply = <®_usb2_vbus>;
};
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 3e6b176..0795b3a 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -166,6 +166,7 @@ config PHY_SUN4I_USB
tristate "Allwinner sunxi SoC USB PHY driver"
depends on ARCH_SUNXI && HAS_IOMEM && OF
depends on RESET_CONTROLLER
+   select EXTCON
select GENERIC_PHY
help
  Enable this to support the transceiver that is part of Allwinner
diff --git a/drivers/phy/phy-sun4i-usb.c b/drivers/phy/phy-sun4i-usb.c
index a2b08f3c..221e8ab 100644
--- a/drivers/phy/phy-sun4i-usb.c
+++ b/drivers/phy/phy-sun4i-usb.c
@@ -1,7 +1,7 @@
 /*
  * Allwinner sun4i USB phy driver
  *
- * Copyright (C) 2014 Hans de Goede 
+ * Copyright (C) 2014-2015 Hans de Goede 
  *
  * Based on code from
  * Allwinner Technology Co., Ltd. 
@@ -23,16 +23,22 @@
 
 #include 
 #include 
+#include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
 #include 
+#include 
+
+#define DRIVER_NAME "sun4i-usb-phy"
 
 #define REG_ISCR   0x00
 #define REG_PHYCTL 0x04
@@ -46,6 +52,17 @@
 #define SUNXI_AHB_INCRX_ALIGN_EN   BIT(8)
 #define SUNXI_ULPI_BYPASS_EN   BIT(0)
 
+/* ISCR, Interface Status and Control bits */
+#define ISCR_ID_PULLUP_EN  (1 << 17)
+#define ISCR_DPDM_PULLUP_EN(1 << 16)
+/* sunxi has the phy id/vbus pins not connected, so we use the force bits */
+#define ISCR_FORCE_ID_MASK (3 << 14)
+#define ISCR_FORCE_ID_LOW  (2 << 14)
+#define ISCR_FORCE_ID_HIGH (3 << 14)
+#define ISCR_FORCE_VBUS_MASK   (3 << 12)
+#define ISCR_FORCE_VBUS_LOW(2 << 12)
+#define ISCR_FORCE_VBUS_HIGH   (3 << 12)
+
 /* Common Control Bits for Both PHYs */
 #define PHY_PLL_BW 0x03
 #define PHY_RES45_CAL_EN   0x0c
@@ -61,6 +78,13 @@
 
 #define MAX_PHYS   3
 
+/*
+ * Note do not raise the debounce time, we must report Vusb high within 100ms
+ * otherwise we get Vbus errors
+ */
+#define DEBOUNCE_TIME  msecs_to_jiffies(50)
+#define POLL_TIME  msecs_to_jiffies(250)
+
 struct sun4i_usb_phy_data {
void __iomem *base;
struct mutex 

[PATCH v2 13/13] ARM: dts: sun7i: Enable USB DRC on A20-OLinuxIno-Lime

2015-03-20 Thread Hans de Goede
Enable the otg/drc usb controller on the A20-OLinuxIno-Lime.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts | 28 ++
 1 file changed, 28 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts 
b/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
index 68efd2f..e3812e9 100644
--- a/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
+++ b/arch/arm/boot/dts/sun7i-a20-olinuxino-lime.dts
@@ -146,6 +146,20 @@
allwinner,drive = ;
allwinner,pull = ;
};
+
+   usb0_id_detect_pin: usb0_id_detect_pin@0 {
+   allwinner,pins = "PH4";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
+   usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+   allwinner,pins = "PH5";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
 };
 
 ®_ahci_5v {
@@ -154,6 +168,10 @@
status = "okay";
 };
 
+®_usb0_vbus {
+   status = "okay";
+};
+
 ®_usb1_vbus {
status = "okay";
 };
@@ -168,7 +186,17 @@
status = "okay";
 };
 
+&usb_otg {
+   dr_mode = "otg";
+   status = "okay";
+};
+
 &usbphy {
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+   usb0_id_det-gpio = <&pio 7 4 GPIO_ACTIVE_HIGH>; /* PH4 */
+   usb0_vbus_det-gpio = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
+   usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_usb1_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
status = "okay";
-- 
2.3.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 v2 12/13] ARM: dts: sun7i: Enable USB DRC on Cubietruck

2015-03-20 Thread Hans de Goede
From: Roman Byshko 

Enable the otg/drc usb controller on the cubietruck.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun7i-a20-cubietruck.dts | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts 
b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
index 5af1df7..e14c1a6 100644
--- a/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
+++ b/arch/arm/boot/dts/sun7i-a20-cubietruck.dts
@@ -224,6 +224,20 @@
allwinner,drive = ;
allwinner,pull = ;
};
+
+   usb0_id_detect_pin: usb0_id_detect_pin@0 {
+   allwinner,pins = "PH19";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
+   usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+   allwinner,pins = "PH22";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
 };
 
 &pwm {
@@ -285,7 +299,16 @@
status = "okay";
 };
 
+&usb_otg {
+   dr_mode = "otg";
+   status = "okay";
+};
+
 &usbphy {
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+   usb0_id_det-gpios = <&pio 7 19 GPIO_ACTIVE_HIGH>; /* PH19 */
+   usb0_vbus_det-gpios = <&pio 7 22 GPIO_ACTIVE_HIGH>; /* PH22 */
usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_usb1_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
-- 
2.3.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 v2 07/13] ARM: dts: sun4i: Add USB Dual Role Controller

2015-03-20 Thread Hans de Goede
Add a node for the otg/drc usb controller to sun4i-a10.dtsi.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun4i-a10.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/sun4i-a10.dtsi b/arch/arm/boot/dts/sun4i-a10.dtsi
index a932c1c..88f57b4 100644
--- a/arch/arm/boot/dts/sun4i-a10.dtsi
+++ b/arch/arm/boot/dts/sun4i-a10.dtsi
@@ -611,6 +611,17 @@
#size-cells = <0>;
};
 
+   usb_otg: usb@01c13000 {
+   compatible = "allwinner,sun4i-a10-musb";
+   reg = <0x01c13000 0x0400>;
+   clocks = <&ahb_gates 0>;
+   interrupts = <38>;
+   interrupt-names = "mc";
+   phys = <&usbphy 0>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun4i-a10-usb-phy";
-- 
2.3.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 v2 09/13] ARM: dts: sun7i: Add USB Dual Role Controller

2015-03-20 Thread Hans de Goede
From: Roman Byshko 

Add a node for the otg/drc usb controller to sun7i-a20.dtsi

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun7i-a20.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/sun7i-a20.dtsi b/arch/arm/boot/dts/sun7i-a20.dtsi
index fb911c9..7c04a24 100644
--- a/arch/arm/boot/dts/sun7i-a20.dtsi
+++ b/arch/arm/boot/dts/sun7i-a20.dtsi
@@ -696,6 +696,17 @@
#size-cells = <0>;
};
 
+   usb_otg: usb@01c13000 {
+   compatible = "allwinner,sun4i-a10-musb";
+   reg = <0x01c13000 0x0400>;
+   clocks = <&ahb_gates 0>;
+   interrupts = <0 38 4>;
+   interrupt-names = "mc";
+   phys = <&usbphy 0>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun7i-a20-usb-phy";
-- 
2.3.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 v2 02/13] musb: Make musb_write_rxfun* and musb_write_rxhub* work like their tx versions

2015-03-20 Thread Hans de Goede
For some reason the musb_write_rxfun* and musb_write_rxhub* functions had
a different function prototype and some extra magic needed on the caller side
compared to their tx counterparts, this commit makes them work the same as
their tx counterparts.

Signed-off-by: Hans de Goede 
---
 drivers/usb/musb/musb_core.c | 11 +++
 drivers/usb/musb/musb_core.h |  2 --
 drivers/usb/musb/musb_host.c | 12 ++--
 drivers/usb/musb/musb_regs.h | 31 ---
 4 files changed, 21 insertions(+), 35 deletions(-)

diff --git a/drivers/usb/musb/musb_core.c b/drivers/usb/musb/musb_core.c
index 067920f..e2892fa 100644
--- a/drivers/usb/musb/musb_core.c
+++ b/drivers/usb/musb/musb_core.c
@@ -1546,7 +1546,6 @@ static int musb_core_init(u16 musb_type, struct musb 
*musb)
 #endif
 
hw_ep->regs = musb->io.ep_offset(i, 0) + mbase;
-   hw_ep->target_regs = musb_read_target_reg_base(i, mbase);
hw_ep->rx_reinit = 1;
hw_ep->tx_reinit = 1;
 
@@ -2334,7 +2333,6 @@ static void musb_restore_context(struct musb *musb)
 {
int i;
void __iomem *musb_base = musb->mregs;
-   void __iomem *ep_target_regs;
void __iomem *epio;
u8 power;
 
@@ -2402,14 +2400,11 @@ static void musb_restore_context(struct musb *musb)
musb_write_txhubport(musb_base, i,
musb->context.index_regs[i].txhubport);
 
-   ep_target_regs =
-   musb_read_target_reg_base(i, musb_base);
-
-   musb_write_rxfunaddr(ep_target_regs,
+   musb_write_rxfunaddr(musb_base, i,
musb->context.index_regs[i].rxfunaddr);
-   musb_write_rxhubaddr(ep_target_regs,
+   musb_write_rxhubaddr(musb_base, i,
musb->context.index_regs[i].rxhubaddr);
-   musb_write_rxhubport(ep_target_regs,
+   musb_write_rxhubport(musb_base, i,
musb->context.index_regs[i].rxhubport);
}
musb_writeb(musb_base, MUSB_INDEX, musb->context.index);
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index 5e65958..a31d709 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -240,8 +240,6 @@ struct musb_hw_ep {
void __iomem*fifo_sync_va;
 #endif
 
-   void __iomem*target_regs;
-
/* currently scheduled peripheral endpoint */
struct musb_qh  *in_qh;
struct musb_qh  *out_qh;
diff --git a/drivers/usb/musb/musb_host.c b/drivers/usb/musb/musb_host.c
index c3d5fc9..c4732a7 100644
--- a/drivers/usb/musb/musb_host.c
+++ b/drivers/usb/musb/musb_host.c
@@ -555,8 +555,9 @@ musb_host_packet_rx(struct musb *musb, struct urb *urb, u8 
epnum, u8 iso_err)
  * the busy/not-empty tests are basically paranoia.
  */
 static void
-musb_rx_reinit(struct musb *musb, struct musb_qh *qh, struct musb_hw_ep *ep)
+musb_rx_reinit(struct musb *musb, struct musb_qh *qh, u8 epnum)
 {
+   struct musb_hw_ep *ep = musb->endpoints + epnum;
u16 csr;
 
/* NOTE:  we know the "rx" fifo reinit never triggers for ep0.
@@ -594,10 +595,9 @@ musb_rx_reinit(struct musb *musb, struct musb_qh *qh, 
struct musb_hw_ep *ep)
 
/* target addr and (for multipoint) hub addr/port */
if (musb->is_multipoint) {
-   musb_write_rxfunaddr(ep->target_regs, qh->addr_reg);
-   musb_write_rxhubaddr(ep->target_regs, qh->h_addr_reg);
-   musb_write_rxhubport(ep->target_regs, qh->h_port_reg);
-
+   musb_write_rxfunaddr(musb->mregs, epnum, qh->addr_reg);
+   musb_write_rxhubaddr(musb->mregs, epnum, qh->h_addr_reg);
+   musb_write_rxhubport(musb->mregs, epnum, qh->h_port_reg);
} else
musb_writeb(musb->mregs, MUSB_FADDR, qh->addr_reg);
 
@@ -875,7 +875,7 @@ finish:
u16 csr;
 
if (hw_ep->rx_reinit) {
-   musb_rx_reinit(musb, qh, hw_ep);
+   musb_rx_reinit(musb, qh, epnum);
 
/* init new state: toggle and NYET, maybe DMA later */
if (usb_gettoggle(urb->dev, qh->epnum, 0))
diff --git a/drivers/usb/musb/musb_regs.h b/drivers/usb/musb/musb_regs.h
index 11f0be0..edfc730 100644
--- a/drivers/usb/musb/musb_regs.h
+++ b/drivers/usb/musb/musb_regs.h
@@ -364,27 +364,25 @@ static inline u16 musb_read_hwvers(void __iomem *mbase)
return musb_readw(mbase, MUSB_HWVERS);
 }
 
-static inline void __iomem *musb_read_target_reg_base(u8 i, void __iomem 
*mbase)
-{
-   return (MUSB_BUSCTL_OFFSET(i, 0) + mbase);
-}
-
-static inline void musb_write_rxfunaddr(void __iomem *ep_target_regs,
+static inline void musb_write_rxfunaddr(void __iomem *mbase, u8 epnum,
u8 qh_addr_reg)
 {
-   musb_writeb(ep_target_regs, MUSB_RXFUNCADDR, qh_ad

[PATCH v2 11/13] ARM: dts: sun5i: Enable USB DRC on UTOO P66

2015-03-20 Thread Hans de Goede
Enable the OTG controller on the UTOO P66 tablet.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun5i-a13-utoo-p66.dts | 23 +++
 1 file changed, 23 insertions(+)

diff --git a/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts 
b/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
index d1d4d30..6c9f5f3 100644
--- a/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
+++ b/arch/arm/boot/dts/sun5i-a13-utoo-p66.dts
@@ -160,6 +160,20 @@
allwinner,pull = ;
};
 
+   usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+   allwinner,pins = "PG1";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
+   usb0_id_detect_pin: usb0_id_detect_pin@0 {
+   allwinner,pins = "PG2";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
i2c_lcd_pins: i2c_lcd_pin@0 {
allwinner,pins = "PG10", "PG12";
allwinner,function = "gpio_out";
@@ -218,7 +232,16 @@
status = "okay";
 };
 
+&usb_otg {
+   dr_mode = "otg";
+   status = "okay";
+};
+
 &usbphy {
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin>, <&usb0_vbus_detect_pin>;
+   usb0_id_det-gpio = <&pio 6 2 GPIO_ACTIVE_HIGH>; /* PG2 */
+   usb0_vbus_det-gpio = <&pio 6 1 GPIO_ACTIVE_HIGH>; /* PG1 */
usb0_vbus-supply = <®_usb0_vbus>;
usb1_vbus-supply = <®_ldo3>;
status = "okay";
-- 
2.3.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 v2 06/13] musb: Add support for the Allwinner sunxi musb controller

2015-03-20 Thread Hans de Goede
This is based on initial code to get the Allwinner sunxi musb controller
supported by Chen-Yu Tsai and Roman Byshko.

This adds support for the Allwinner sunxi musb controller in both host only
and otg mode. Peripheral only mode is not supported, as no boards use that.

This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
(A13 SoC) with a variety of devices in host mode and with the g_serial gadget
driver in peripheral mode, plugging otg / host cables in/out a lot of times
in all possible imaginable plug orders.

Signed-off-by: Hans de Goede 
---
 .../bindings/usb/allwinner,sun4i-a10-musb.txt  |  25 +
 drivers/usb/musb/Kconfig   |  12 +-
 drivers/usb/musb/Makefile  |   1 +
 drivers/usb/musb/musb_core.h   |   1 +
 drivers/usb/musb/musb_gadget.c |   6 +
 drivers/usb/musb/musb_virthub.c|   6 +
 drivers/usb/musb/sunxi.c   | 671 +
 7 files changed, 721 insertions(+), 1 deletion(-)
 create mode 100644 
Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
 create mode 100644 drivers/usb/musb/sunxi.c

diff --git a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt 
b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
new file mode 100644
index 000..21dfc7f
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
@@ -0,0 +1,25 @@
+Allwinner sun4i A10 musb DRC/OTG controller
+---
+
+Required properties:
+ - compatible  : "allwinner,sun4i-a10-musb"
+ - reg : mmio address range of the musb controller
+ - clocks  : clock specifier for the musb controller ahb gate clock
+ - interrupts  : interrupt to which the musb controller is connected
+ - interrupt-names : must be "mc"
+ - phys: phy specifier for the otg phy
+ - phy-names   : must be "usb"
+ - dr_mode : Dual-Role mode must be "host" or "otg"
+
+Example:
+
+   usb_otg: usb@01c13000 {
+   compatible = "allwinner,sun4i-a10-musb";
+   reg = <0x01c13000 0x0400>;
+   clocks = <&ahb_gates 0>;
+   interrupts = <38>;
+   interrupt-names = "mc";
+   phys = <&usbphy 0>;
+   phy-names = "usb";
+   status = "disabled";
+   };
diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 14e1628..c83cad1 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -5,7 +5,7 @@
 
 # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
 config USB_MUSB_HDRC
-   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
+   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
depends on (USB || USB_GADGET)
help
  Say Y here if your system has a dual role high speed USB
@@ -20,6 +20,8 @@ config USB_MUSB_HDRC
  Analog Devices parts using this IP include Blackfin BF54x,
  BF525 and BF527.
 
+ Allwinner SoCs using this IP include A10, A13, A20, ...
+
  If you do not know what this is, please say N.
 
  To compile this driver as a module, choose M here; the
@@ -60,6 +62,14 @@ endchoice
 
 comment "Platform Glue Layer"
 
+config USB_MUSB_SUNXI
+   tristate "Allwinner (sunxi)"
+   depends on ARCH_SUNXI
+   depends on NOP_USB_XCEIV
+   select EXTCON
+   select GENERIC_PHY
+   select SUNXI_SRAM
+
 config USB_MUSB_DAVINCI
tristate "DaVinci"
depends on ARCH_DAVINCI_DMx
diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
index ba49501..f95befe 100644
--- a/drivers/usb/musb/Makefile
+++ b/drivers/usb/musb/Makefile
@@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX)  += da8xx.o
 obj-$(CONFIG_USB_MUSB_BLACKFIN)+= blackfin.o
 obj-$(CONFIG_USB_MUSB_UX500)   += ux500.o
 obj-$(CONFIG_USB_MUSB_JZ4740)  += jz4740.o
+obj-$(CONFIG_USB_MUSB_SUNXI)   += sunxi.o
 
 
 obj-$(CONFIG_USB_MUSB_AM335X_CHILD)+= musb_am335x.o
diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
index ba8dd78..444b936 100644
--- a/drivers/usb/musb/musb_core.h
+++ b/drivers/usb/musb/musb_core.h
@@ -166,6 +166,7 @@ struct musb_io;
  */
 struct musb_platform_ops {
 
+#define MUSB_SUN4I BIT(7)
 #define MUSB_DMA_UX500 BIT(6)
 #define MUSB_DMA_CPPI41BIT(5)
 #define MUSB_DMA_CPPI  BIT(4)
diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
index b2d9040..7d13eb9 100644
--- a/drivers/usb/musb/musb_gadget.c
+++ b/drivers/usb/musb/musb_gadget.c
@@ -2041,6 +2041,12 @@ void musb_g_disconnect(struct musb *musb)
spin_lock(&musb->lock);
}
 
+   /* On sunxi ep0 FADDR must be 0 when (re)entering peripheral mode */
+   if (musb->io

[PATCH v2 08/13] ARM: dts: sun5i: Add USB Dual Role Controller

2015-03-20 Thread Hans de Goede
Add a node for the otg/drc usb controller to sun5i-a1*.dtsi.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun5i.dtsi | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/arch/arm/boot/dts/sun5i.dtsi b/arch/arm/boot/dts/sun5i.dtsi
index c3e11ec..eb5bce5 100644
--- a/arch/arm/boot/dts/sun5i.dtsi
+++ b/arch/arm/boot/dts/sun5i.dtsi
@@ -425,6 +425,17 @@
#size-cells = <0>;
};
 
+   usb_otg: usb@01c13000 {
+   compatible = "allwinner,sun4i-a10-musb";
+   reg = <0x01c13000 0x0400>;
+   clocks = <&ahb_gates 0>;
+   interrupts = <38>;
+   interrupt-names = "mc";
+   phys = <&usbphy 0>;
+   phy-names = "usb";
+   status = "disabled";
+   };
+
usbphy: phy@01c13400 {
#phy-cells = <1>;
compatible = "allwinner,sun5i-a13-usb-phy";
-- 
2.3.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 v2 10/13] ARM: dts: sun4i: Enable USB DRC on Chuwi V7 CW0825

2015-03-20 Thread Hans de Goede
Enable the otg/drc usb controller on the Chuwi V7 CW0825 tablet.

Signed-off-by: Hans de Goede 
---
 arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts | 31 +
 1 file changed, 31 insertions(+)

diff --git a/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts 
b/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
index 97fca89..8a2f4c5 100644
--- a/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
+++ b/arch/arm/boot/dts/sun4i-a10-chuwi-v7-cw0825.dts
@@ -111,6 +111,26 @@
status = "okay";
 };
 
+&pio {
+   usb0_id_detect_pin: usb0_id_detect_pin@0 {
+   allwinner,pins = "PH4";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+
+   usb0_vbus_detect_pin: usb0_vbus_detect_pin@0 {
+   allwinner,pins = "PH5";
+   allwinner,function = "gpio_in";
+   allwinner,drive = ;
+   allwinner,pull = ;
+   };
+};
+
+®_usb0_vbus {
+   status = "okay";
+};
+
 ®_usb2_vbus {
status = "okay";
 };
@@ -121,7 +141,18 @@
status = "okay";
 };
 
+&usb_otg {
+   dr_mode = "otg";
+   status = "okay";
+};
+
 &usbphy {
+   pinctrl-names = "default";
+   pinctrl-0 = <&usb0_id_detect_pin
+&usb0_vbus_detect_pin>;
+   usb0_id_det-gpio = <&pio 7 4 GPIO_ACTIVE_HIGH>; /* PH4 */
+   usb0_vbus_det-gpio = <&pio 7 5 GPIO_ACTIVE_HIGH>; /* PH5 */
+   usb0_vbus-supply = <®_usb0_vbus>;
usb2_vbus-supply = <®_usb2_vbus>;
status = "okay";
 };
-- 
2.3.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: [PATCH 2/3] cdc-wdm: unify error handling in write

2015-03-20 Thread Oliver Neukum
On Fri, 2015-03-20 at 16:11 +0100, Bjørn Mork wrote:
> Anyway, the "outnl" is only ever used with rv < 0, and with your
> changes
> all other cases where rv < 0 will jump to some other label.  So I
> don't
> think it makes much sense to keep the "return rv < 0 ? rv : count"
> even
> if you don't want the direct return.  Just move the "outnl" label
> (possibly with a more describing name) down to the "return rv" at the
> end.

Feel free to provide a patch.

Regards
Oliver


--
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 0/3] Add devm_of_phy_get_by_index and update platform drivers

2015-03-20 Thread Arun Ramamurthy
This patch set adds a new API to get phy by index when multiple 
phys are present. This patch is based on discussion with Arnd Bergmann
about dt bindings for multiple phys. 

Arun Ramamurthy (3):
  phy: core: Add devm_of_phy_get_by_index to phy-core
  usb: ehci-platform: Use devm_of_phy_get_by_index
  usb: ohci-platform: Use devm_of_phy_get_by_index

 drivers/phy/phy-core.c   | 30 ++
 drivers/usb/host/ehci-platform.c | 20 
 drivers/usb/host/ohci-platform.c | 20 
 include/linux/phy/phy.h  |  2 ++
 4 files changed, 40 insertions(+), 32 deletions(-)

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


[PATCH 2/3] usb: ehci-platform: Use devm_of_phy_get_by_index

2015-03-20 Thread Arun Ramamurthy
Getting phys by index instead of phy names so that the dt
bindings phy-names remain consistent when multiple phys are present

Reviewed-by: Ray Jui 
Reviewed-by: Scott Branden 
Signed-off-by: Arun Ramamurthy 
---
 drivers/usb/host/ehci-platform.c | 20 
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
index d8a75a5..8b0c7ae 100644
--- a/drivers/usb/host/ehci-platform.c
+++ b/drivers/usb/host/ehci-platform.c
@@ -154,7 +154,6 @@ static int ehci_platform_probe(struct platform_device *dev)
struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
struct ehci_platform_priv *priv;
struct ehci_hcd *ehci;
-   const char *phy_name;
int err, irq, phy_num, clk = 0;
 
if (usb_disabled())
@@ -212,21 +211,10 @@ static int ehci_platform_probe(struct platform_device 
*dev)
return -ENOMEM;
 
for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
-   err = of_property_read_string_index(
-   dev->dev.of_node,
-   "phy-names", phy_num,
-   &phy_name);
-
-   if (err < 0) {
-   if (priv->num_phys > 1) {
-   dev_err(&dev->dev, "phy-names 
not provided");
-   goto err_put_hcd;
-   } else
-   phy_name = "usb";
-   }
-
-   priv->phys[phy_num] = devm_phy_get(&dev->dev,
-   phy_name);
+   priv->phys[phy_num] =
+   devm_of_phy_get_by_index(&dev->dev,
+   dev->dev.of_node,
+   phy_num);
if (IS_ERR(priv->phys[phy_num])) {
err = PTR_ERR(priv->phys[phy_num]);
if ((priv->num_phys > 1) ||
-- 
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


[PATCH 3/3] usb: ohci-platform: Use devm_of_phy_get_by_index

2015-03-20 Thread Arun Ramamurthy
Getting phys by index instead of phy names so that the dt
bindings phy-names remain consistent when multiple phys are present

Reviewed-by: Ray Jui 
Reviewed-by: Scott Branden 
Signed-off-by: Arun Ramamurthy 
---
 drivers/usb/host/ohci-platform.c | 20 
 1 file changed, 4 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
index 185ceee..8b2ec4e 100644
--- a/drivers/usb/host/ohci-platform.c
+++ b/drivers/usb/host/ohci-platform.c
@@ -123,7 +123,6 @@ static int ohci_platform_probe(struct platform_device *dev)
struct usb_ohci_pdata *pdata = dev_get_platdata(&dev->dev);
struct ohci_platform_priv *priv;
struct ohci_hcd *ohci;
-   const char *phy_name;
int err, irq, phy_num, clk = 0;
 
if (usb_disabled())
@@ -182,21 +181,10 @@ static int ohci_platform_probe(struct platform_device 
*dev)
return -ENOMEM;
 
for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
-   err = of_property_read_string_index(
-   dev->dev.of_node,
-   "phy-names", phy_num,
-   &phy_name);
-
-   if (err < 0) {
-   if (priv->num_phys > 1) {
-   dev_err(&dev->dev, "phy-names 
not provided");
-   goto err_put_hcd;
-   } else
-   phy_name = "usb";
-   }
-
-   priv->phys[phy_num] = devm_phy_get(&dev->dev,
-   phy_name);
+   priv->phys[phy_num] =
+   devm_of_phy_get_by_index(&dev->dev,
+   dev->dev.of_node,
+   phy_num);
if (IS_ERR(priv->phys[phy_num])) {
err = PTR_ERR(priv->phys[phy_num]);
if ((priv->num_phys > 1) ||
-- 
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


[PATCH 1/3] phy: core: Add devm_of_phy_get_by_index to phy-core

2015-03-20 Thread Arun Ramamurthy
Adding devm_of_phy_get_by_index to get phys by supplying an index
and not a phy name when multiple phys are declared

Reviewed-by: Ray Jui 
Reviewed-by: Scott Branden 
Signed-off-by: Arun Ramamurthy 
---
 drivers/phy/phy-core.c  | 30 ++
 include/linux/phy/phy.h |  2 ++
 2 files changed, 32 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a12d353..0c03876 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -622,6 +622,36 @@ struct phy *devm_of_phy_get(struct device *dev, struct 
device_node *np,
 EXPORT_SYMBOL_GPL(devm_of_phy_get);
 
 /**
+ * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by 
index.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @index: index of the phy
+ *
+ * Gets the phy using _of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ *
+ */
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
*np,
+int index)
+{
+   struct phy **ptr, *phy;
+
+   ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
+   if (!ptr)
+   return ERR_PTR(-ENOMEM);
+
+   phy = _of_phy_get(np, index);
+   if (!IS_ERR(phy)) {
+   *ptr = phy;
+   devres_add(dev, ptr);
+   } else {
+   devres_free(ptr);
+   }
+
+   return phy;
+}
+/**
  * phy_create() - create a new phy
  * @dev: device that is creating the new phy
  * @node: device node of the phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index a0197fa..ae2ffaf 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -133,6 +133,8 @@ struct phy *devm_phy_get(struct device *dev, const char 
*string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
 struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
const char *con_id);
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
*np,
+int index);
 void phy_put(struct phy *phy);
 void devm_phy_put(struct device *dev, struct phy *phy);
 struct phy *of_phy_get(struct device_node *np, const char *con_id);
-- 
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


Re: [PATCH 1/3] phy: core: Add devm_of_phy_get_by_index to phy-core

2015-03-20 Thread Dmitry Torokhov
Hi Arun,

On Fri, Mar 20, 2015 at 02:07:08PM -0700, Arun Ramamurthy wrote:
> Adding devm_of_phy_get_by_index to get phys by supplying an index
> and not a phy name when multiple phys are declared
> 
> Reviewed-by: Ray Jui 
> Reviewed-by: Scott Branden 
> Signed-off-by: Arun Ramamurthy 
> ---
>  drivers/phy/phy-core.c  | 30 ++
>  include/linux/phy/phy.h |  2 ++
>  2 files changed, 32 insertions(+)
> 
> diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
> index a12d353..0c03876 100644
> --- a/drivers/phy/phy-core.c
> +++ b/drivers/phy/phy-core.c
> @@ -622,6 +622,36 @@ struct phy *devm_of_phy_get(struct device *dev, struct 
> device_node *np,
>  EXPORT_SYMBOL_GPL(devm_of_phy_get);
>  
>  /**
> + * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by 
> index.
> + * @dev: device that requests this phy
> + * @np: node containing the phy
> + * @index: index of the phy
> + *
> + * Gets the phy using _of_phy_get(), and associates a device with it using
> + * devres. On driver detach, release function is invoked on the devres data,
> + * then, devres data is freed.
> + *
> + */
> +struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
> *np,
> +  int index)
> +{
> + struct phy **ptr, *phy;
> +
> + ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
> + if (!ptr)
> + return ERR_PTR(-ENOMEM);
> +
> + phy = _of_phy_get(np, index);
> + if (!IS_ERR(phy)) {
> + *ptr = phy;
> + devres_add(dev, ptr);
> + } else {
> + devres_free(ptr);
> + }
> +
> + return phy;
> +}

You want EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); here.

> +/**
>   * phy_create() - create a new phy
>   * @dev: device that is creating the new phy
>   * @node: device node of the phy
> diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
> index a0197fa..ae2ffaf 100644
> --- a/include/linux/phy/phy.h
> +++ b/include/linux/phy/phy.h
> @@ -133,6 +133,8 @@ struct phy *devm_phy_get(struct device *dev, const char 
> *string);
>  struct phy *devm_phy_optional_get(struct device *dev, const char *string);
>  struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
>   const char *con_id);
> +struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
> *np,
> +  int index);
>  void phy_put(struct phy *phy);
>  void devm_phy_put(struct device *dev, struct phy *phy);
>  struct phy *of_phy_get(struct device_node *np, const char *con_id);
> -- 
> 2.3.2
> 

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


Re: [PATCH 1/3] phy: core: Add devm_of_phy_get_by_index to phy-core

2015-03-20 Thread Arun Ramamurthy



On 15-03-20 02:26 PM, Dmitry Torokhov wrote:

Hi Arun,

On Fri, Mar 20, 2015 at 02:07:08PM -0700, Arun Ramamurthy wrote:

Adding devm_of_phy_get_by_index to get phys by supplying an index
and not a phy name when multiple phys are declared

Reviewed-by: Ray Jui 
Reviewed-by: Scott Branden 
Signed-off-by: Arun Ramamurthy 
---
  drivers/phy/phy-core.c  | 30 ++
  include/linux/phy/phy.h |  2 ++
  2 files changed, 32 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index a12d353..0c03876 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -622,6 +622,36 @@ struct phy *devm_of_phy_get(struct device *dev, struct 
device_node *np,
  EXPORT_SYMBOL_GPL(devm_of_phy_get);

  /**
+ * devm_of_phy_get_by_index() - lookup and obtain a reference to a phy by 
index.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @index: index of the phy
+ *
+ * Gets the phy using _of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ *
+ */
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
*np,
+int index)
+{
+   struct phy **ptr, *phy;
+
+   ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
+   if (!ptr)
+   return ERR_PTR(-ENOMEM);
+
+   phy = _of_phy_get(np, index);
+   if (!IS_ERR(phy)) {
+   *ptr = phy;
+   devres_add(dev, ptr);
+   } else {
+   devres_free(ptr);
+   }
+
+   return phy;
+}


You want EXPORT_SYMBOL_GPL(devm_of_phy_get_by_index); here.

Ah, I missed that! Thanks Dmitry, Will update in next patch after any 
other comments.

+/**
   * phy_create() - create a new phy
   * @dev: device that is creating the new phy
   * @node: device node of the phy
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index a0197fa..ae2ffaf 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -133,6 +133,8 @@ struct phy *devm_phy_get(struct device *dev, const char 
*string);
  struct phy *devm_phy_optional_get(struct device *dev, const char *string);
  struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
const char *con_id);
+struct phy *devm_of_phy_get_by_index(struct device *dev, struct device_node 
*np,
+int index);
  void phy_put(struct phy *phy);
  void devm_phy_put(struct device *dev, struct phy *phy);
  struct phy *of_phy_get(struct device_node *np, const char *con_id);
--
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


Re: [PATCH 2/3] usb: ehci-platform: Use devm_of_phy_get_by_index

2015-03-20 Thread Dmitry Torokhov
Hi Arun,

On Fri, Mar 20, 2015 at 02:07:09PM -0700, Arun Ramamurthy wrote:
> Getting phys by index instead of phy names so that the dt
> bindings phy-names remain consistent when multiple phys are present
> 
> Reviewed-by: Ray Jui 
> Reviewed-by: Scott Branden 
> Signed-off-by: Arun Ramamurthy 
> ---
>  drivers/usb/host/ehci-platform.c | 20 
>  1 file changed, 4 insertions(+), 16 deletions(-)
> 
> diff --git a/drivers/usb/host/ehci-platform.c 
> b/drivers/usb/host/ehci-platform.c
> index d8a75a5..8b0c7ae 100644
> --- a/drivers/usb/host/ehci-platform.c
> +++ b/drivers/usb/host/ehci-platform.c
> @@ -154,7 +154,6 @@ static int ehci_platform_probe(struct platform_device 
> *dev)
>   struct usb_ehci_pdata *pdata = dev_get_platdata(&dev->dev);
>   struct ehci_platform_priv *priv;
>   struct ehci_hcd *ehci;
> - const char *phy_name;
>   int err, irq, phy_num, clk = 0;
>  
>   if (usb_disabled())
> @@ -212,21 +211,10 @@ static int ehci_platform_probe(struct platform_device 
> *dev)
>   return -ENOMEM;
>  
>   for (phy_num = 0; phy_num < priv->num_phys; phy_num++) {
> - err = of_property_read_string_index(
> - dev->dev.of_node,
> - "phy-names", phy_num,
> - &phy_name);
> -
> - if (err < 0) {
> - if (priv->num_phys > 1) {
> - dev_err(&dev->dev, "phy-names 
> not provided");
> - goto err_put_hcd;
> - } else
> - phy_name = "usb";
> - }
> -
> - priv->phys[phy_num] = devm_phy_get(&dev->dev,
> - phy_name);
> + priv->phys[phy_num] =
> + devm_of_phy_get_by_index(&dev->dev,
> + dev->dev.of_node,
> + phy_num);
>   if (IS_ERR(priv->phys[phy_num])) {
>   err = PTR_ERR(priv->phys[phy_num]);
>   if ((priv->num_phys > 1) ||

While you are fixing this can you please correct the wrong indentation
level and clean up that whole weird business of treating "phy" not
present in DT in a special way and, stuffing NULL pointer in priv->phys,
and checking it for NULL elsewhere?

Thanks!

-- 
Dmitry
--
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: musb: only set test mode once

2015-03-20 Thread Bin Liu
The MUSB test mode register can only be set once, otherwise the result
is undefined.

This prevents the debugfs testmode entry to set the register more than
once which causes test failure.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_debugfs.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 179d885..7119639 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -189,6 +189,12 @@ static ssize_t musb_test_mode_write(struct file *file,
u8  test = 0;
charbuf[18];
 
+   test = musb_readb(musb->mregs, MUSB_TESTMODE);
+   if (test) {
+   dev_err(musb->controller, "Error: test mode is running\n");
+   return -EINVAL;
+   }
+
memset(buf, 0x00, sizeof(buf));
 
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
-- 
1.8.4

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


RE: [PATCH] usb: musb: only set test mode once

2015-03-20 Thread Liu, Bin
Sorry, please ignore this one. Forgot to rebase.

Regards,
-Bin.

> -Original Message-
> From: Liu, Bin
> Sent: Friday, March 20, 2015 4:45 PM
> To: linux-usb@vger.kernel.org
> Cc: Balbi, Felipe; Liu, Bin
> Subject: [PATCH] usb: musb: only set test mode once
> 
> The MUSB test mode register can only be set once, otherwise the result is
> undefined.
> 
> This prevents the debugfs testmode entry to set the register more than once
> which causes test failure.
> 
> Signed-off-by: Bin Liu 
> ---
>  drivers/usb/musb/musb_debugfs.c | 6 ++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/drivers/usb/musb/musb_debugfs.c
> b/drivers/usb/musb/musb_debugfs.c index 179d885..7119639 100644
> --- a/drivers/usb/musb/musb_debugfs.c
> +++ b/drivers/usb/musb/musb_debugfs.c
> @@ -189,6 +189,12 @@ static ssize_t musb_test_mode_write(struct file *file,
>   u8  test = 0;
>   charbuf[18];
> 
> + test = musb_readb(musb->mregs, MUSB_TESTMODE);
> + if (test) {
> + dev_err(musb->controller, "Error: test mode is running\n");
> + return -EINVAL;
> + }
> +
>   memset(buf, 0x00, sizeof(buf));
> 
>   if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
> --
> 1.8.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: musb: only set test mode once

2015-03-20 Thread Bin Liu
The MUSB test mode register can only be set once, otherwise the result
is undefined.

This prevents the debugfs testmode entry to set the register more than
once which causes test failure.

Signed-off-by: Bin Liu 
---
 drivers/usb/musb/musb_debugfs.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/musb/musb_debugfs.c b/drivers/usb/musb/musb_debugfs.c
index 78a283e..cd0c381 100644
--- a/drivers/usb/musb/musb_debugfs.c
+++ b/drivers/usb/musb/musb_debugfs.c
@@ -194,6 +194,12 @@ static ssize_t musb_test_mode_write(struct file *file,
u8  test = 0;
charbuf[18];
 
+   test = musb_readb(musb->mregs, MUSB_TESTMODE);
+   if (test) {
+   dev_err(musb->controller, "Error: test mode is running\n");
+   return -EINVAL;
+   }
+
memset(buf, 0x00, sizeof(buf));
 
if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
-- 
1.8.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: gadget: Check for NULL pointer in disconnect

2015-03-20 Thread Badhri Jagan Sridharan
Added a safety net to make sure that
composite_disconnect does not end up disconneting
a NULL device. Prevents NULL pointer crash.

Signed-off-by: Badhri Jagan Sridharan 
---
 drivers/usb/gadget/composite.c | 5 +
 1 file changed, 5 insertions(+)

diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 13adfd1..90b37bd 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -1823,6 +1823,11 @@ void composite_disconnect(struct usb_gadget *gadget)
struct usb_composite_dev*cdev = get_gadget_data(gadget);
unsigned long   flags;
 
+   if (!cdev) {
+   WARN(1, "Trying to disconnect a NULL composite device\n");
+   return;
+   }
+
/* REVISIT:  should we have config and device level
 * disconnect callbacks?
 */
-- 
2.2.0.rc0.207.ga3a616c

--
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: Errata for Freescale root-hub TT?

2015-03-20 Thread Peter Chen
On Fri, Mar 20, 2015 at 10:16:49AM -0400, Alan Stern wrote:
> Peter:
> 
> Are there any known errata for the root-hub Transaction Translator in 
> the Freescale host controllers?
> 
> When debugging some problems in an i.MX51 system, I found that the host
> controller would never issue more than 4 full-speed isochronous packets
> in any frame, no matter how many siTDs were linked into the EHCI
> schedule.  Sometimes it would issue only 1 or 2 packets, even though
> eight were in the schedule!  The behavior was very erratic.
> 
> The controller seemed to work okay when the full-speed devices were 
> behind a high-speed hub.  The problems came up only when the host 
> controller was connected to a full-speed hub.
> 
> Alan Stern
> 

Hi Alan,

When look at below imx51 errata, it does not describe this issue, I will
talk with IC guys about it next Monday.

http://cache.freescale.com/files/dsp/doc/errata/IMX51CE.pdf

-- 

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


Re: [PATCH v2 00/22] usb: third series of updates for dwc2 driver

2015-03-20 Thread John Youn
On 3/20/2015 8:35 AM, Mian Yousaf Kaukab wrote:
> Hi,
> This patchset consists of some bug fixes and feature enhancements for
> the dwc2 driver. All the patches are verified on dwc2 v3.0a with
> dedicated fifos. Main focus of testing was with dma enabled. Although
> basic testing without dma was also done.
> 
> This is based on testing/next branch in Felipe's git.
> 

Hi Yousaf,

The last 3 patches don't apply against Felipe's testing/next.

Also, you can drop the last patch as it is addressed by this:
http://marc.info/?l=linux-usb&m=142661773703793&w=2

John

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


Re: [RFC][PATCH 2/9] usb: gadget: add usb_gadget_start/stop()

2015-03-20 Thread Peter Chen
On Fri, Mar 20, 2015 at 01:08:25PM +0200, Roger Quadros wrote:
> On 20/03/15 11:46, Roger Quadros wrote:
> > On 20/03/15 09:18, Peter Chen wrote:
> >> On Thu, Mar 19, 2015 at 04:50:31PM +0200, Roger Quadros wrote:
> >>> On 19/03/15 16:09, Li Jun wrote:
>  On Thu, Mar 19, 2015 at 12:14:39PM +0200, Roger Quadros wrote:
> > On 19/03/15 05:30, Peter Chen wrote:
> >> On Wed, Mar 18, 2015 at 03:55:56PM +0200, Roger Quadros wrote:
> >>> The OTG state machine needs a mechanism to start and
> >>> stop the gadget controller. Add usb_gadget_start()
> >>> and usb_gadget_stop().
> >>>
> >>> Signed-off-by: Roger Quadros 
> >>> ---
> >>>  drivers/usb/gadget/udc/udc-core.c | 166 
> >>> +++---
> >>>  include/linux/usb/gadget.h|   3 +
> >>>  2 files changed, 158 insertions(+), 11 deletions(-)
> >>>
> >>> diff --git a/drivers/usb/gadget/udc/udc-core.c 
> >>> b/drivers/usb/gadget/udc/udc-core.c
> >>> index 5a81cb0..69b4123 100644
> >>> --- a/drivers/usb/gadget/udc/udc-core.c
> >>> +++ b/drivers/usb/gadget/udc/udc-core.c
> >>> @@ -35,6 +35,8 @@
> >>>   * @dev - the child device to the actual controller
> >>>   * @gadget - the gadget. For use by the class code
> >>>   * @list - for use by the udc class driver
> >>> + * @running - udc is running
> >>
> >> Doesn't OTG FSM should know it?
> >
> > Not really, as the gadget driver might not have been loaded yet or 
> > userspace might
> > have disabled softconnect when the OTG FSM wants UDC to start.
> >
> > So only UDC knows if it has really started or not based on this flag.
> >
> 
>  why this can not be known by check the otg fsm state? i.e. if the device 
>  in
>  b_peripheral or a_peripheral state, udc should had started, isn't it?
> >>>
> >>> If gadget function driver (which is different from UDC driver) is not yet 
> >>> loaded
> >>> then we can't start UDC even if otg fsm is in b_peripheral.
> >>> Also, if userspace has disabled softconnect we can't start UDC.
> >>>
> >>> So, b_peripheral != UDC_started.
> >>>
> >>> I've tried to address this issue by adding the checks in 
> >>> usb_gadget_start().
> >>>
> >>
> >> Ok, maybe we have different understanding for 'B-Device' at software,
> >> In spec, it says the Micro-AB receptacle with nothing connected can be
> >> 'B-Device', but in fact, we may not enable device mode before loading
> >> gadget driver, in chipidea fsm design, if the gadget driver is not
> >> loaded, the FSM will not start, and it is at OTG_STATE_UNDEFINED.
> > 
> > Right. I mixed up into thinking that we should respect the softconnect
> > while in OTG mode. It seems that we should ignore it.
> > 
> >>
> >> One more thing is we may need to find a place to issue SRP when we
> >> load gadget driver, since we may at b_idle  at that time due to host
> >> closes the vbus (timeout for a_wait_bcon).
> > 
> > Issuing SRP should be done by the otg-fsm and not udc-core.
> > The udc-core can at the least call usb_otg_kick_fsm() after setting the 
> > gadget
> > driver so that otg-fsm knows that we now have a valid gadget and can take
> > necessary action. i.e. change from b_idle to b_srp_init and then to 
> > b_peripheral.
> 
> To clarify further. Is it right to assume that OTG FSM will not be started 
> till
> both gadget UDC driver _AND_ gadget function driver are loaded?
> 
> And it will be stopped when either of them unloads.
> 
> This simplifies things a lot.

Yes, you are right.

> 
> cheers,
> -roger
> 
> > 
> >>
> >> What is the "softconnect" used for? In otg fsm, we use b_bus_req for FSM.
> >>
> > I understand now that we shouldn't bother with softconnect when we are in 
> > OTG fsm mode.
> > That solves our problem with the running flags.
> > 
> > So now, b_peripheral == UDC_started.
> > 
> > I will address this in v2.
> > 
> > cheers,
> > -roger
> > --
> > 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
> > 
> 

-- 

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


Re: [PATCH v2 06/13] musb: Add support for the Allwinner sunxi musb controller

2015-03-20 Thread Chen-Yu Tsai
Hi,

On Sat, Mar 21, 2015 at 3:11 AM, Hans de Goede  wrote:
> This is based on initial code to get the Allwinner sunxi musb controller
> supported by Chen-Yu Tsai and Roman Byshko.
>
> This adds support for the Allwinner sunxi musb controller in both host only
> and otg mode. Peripheral only mode is not supported, as no boards use that.
>
> This has been tested on a cubietruck (A20 SoC) and an UTOO P66 tablet
> (A13 SoC) with a variety of devices in host mode and with the g_serial gadget
> driver in peripheral mode, plugging otg / host cables in/out a lot of times
> in all possible imaginable plug orders.
>
> Signed-off-by: Hans de Goede 
> ---
>  .../bindings/usb/allwinner,sun4i-a10-musb.txt  |  25 +
>  drivers/usb/musb/Kconfig   |  12 +-
>  drivers/usb/musb/Makefile  |   1 +
>  drivers/usb/musb/musb_core.h   |   1 +
>  drivers/usb/musb/musb_gadget.c |   6 +
>  drivers/usb/musb/musb_virthub.c|   6 +
>  drivers/usb/musb/sunxi.c   | 671 
> +
>  7 files changed, 721 insertions(+), 1 deletion(-)
>  create mode 100644 
> Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
>  create mode 100644 drivers/usb/musb/sunxi.c
>
> diff --git 
> a/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt 
> b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
> new file mode 100644
> index 000..21dfc7f
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/usb/allwinner,sun4i-a10-musb.txt
> @@ -0,0 +1,25 @@
> +Allwinner sun4i A10 musb DRC/OTG controller
> +---
> +
> +Required properties:
> + - compatible  : "allwinner,sun4i-a10-musb"
> + - reg : mmio address range of the musb controller
> + - clocks  : clock specifier for the musb controller ahb gate clock
> + - interrupts  : interrupt to which the musb controller is connected
> + - interrupt-names : must be "mc"
> + - phys: phy specifier for the otg phy
> + - phy-names   : must be "usb"
> + - dr_mode : Dual-Role mode must be "host" or "otg"
> +
> +Example:
> +
> +   usb_otg: usb@01c13000 {
> +   compatible = "allwinner,sun4i-a10-musb";
> +   reg = <0x01c13000 0x0400>;
> +   clocks = <&ahb_gates 0>;
> +   interrupts = <38>;
> +   interrupt-names = "mc";
> +   phys = <&usbphy 0>;
> +   phy-names = "usb";
> +   status = "disabled";
> +   };
> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
> index 14e1628..c83cad1 100644
> --- a/drivers/usb/musb/Kconfig
> +++ b/drivers/usb/musb/Kconfig
> @@ -5,7 +5,7 @@
>
>  # (M)HDRC = (Multipoint) Highspeed Dual-Role Controller
>  config USB_MUSB_HDRC
> -   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, ...)'
> +   tristate 'Inventra Highspeed Dual Role Controller (TI, ADI, AW, ...)'
> depends on (USB || USB_GADGET)
> help
>   Say Y here if your system has a dual role high speed USB
> @@ -20,6 +20,8 @@ config USB_MUSB_HDRC
>   Analog Devices parts using this IP include Blackfin BF54x,
>   BF525 and BF527.
>
> + Allwinner SoCs using this IP include A10, A13, A20, ...
> +
>   If you do not know what this is, please say N.
>
>   To compile this driver as a module, choose M here; the
> @@ -60,6 +62,14 @@ endchoice
>
>  comment "Platform Glue Layer"
>
> +config USB_MUSB_SUNXI
> +   tristate "Allwinner (sunxi)"
> +   depends on ARCH_SUNXI
> +   depends on NOP_USB_XCEIV
> +   select EXTCON
> +   select GENERIC_PHY
> +   select SUNXI_SRAM
> +
>  config USB_MUSB_DAVINCI
> tristate "DaVinci"
> depends on ARCH_DAVINCI_DMx
> diff --git a/drivers/usb/musb/Makefile b/drivers/usb/musb/Makefile
> index ba49501..f95befe 100644
> --- a/drivers/usb/musb/Makefile
> +++ b/drivers/usb/musb/Makefile
> @@ -20,6 +20,7 @@ obj-$(CONFIG_USB_MUSB_DA8XX)  += da8xx.o
>  obj-$(CONFIG_USB_MUSB_BLACKFIN)+= blackfin.o
>  obj-$(CONFIG_USB_MUSB_UX500)   += ux500.o
>  obj-$(CONFIG_USB_MUSB_JZ4740)  += jz4740.o
> +obj-$(CONFIG_USB_MUSB_SUNXI)   += sunxi.o
>
>
>  obj-$(CONFIG_USB_MUSB_AM335X_CHILD)+= musb_am335x.o
> diff --git a/drivers/usb/musb/musb_core.h b/drivers/usb/musb/musb_core.h
> index ba8dd78..444b936 100644
> --- a/drivers/usb/musb/musb_core.h
> +++ b/drivers/usb/musb/musb_core.h
> @@ -166,6 +166,7 @@ struct musb_io;
>   */
>  struct musb_platform_ops {
>
> +#define MUSB_SUN4I BIT(7)
>  #define MUSB_DMA_UX500 BIT(6)
>  #define MUSB_DMA_CPPI41BIT(5)
>  #define MUSB_DMA_CPPI  BIT(4)
> diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c
> index b2d9040..7d13eb9 100644
> 

[PATCH 1/3] usb: gadget: rndis: use rndis_params instead of configNr

2015-03-20 Thread Andrzej Pietrasiewicz
RNDIS function has a limitation on the number of allowed instances.
So far it has been RNDIS_MAX_CONFIGS, which happens to be one.
In order to eliminate this kind of arbitrary limitation we should not
preallocate a predefined (RNDIS_MAX_CONFIGS) array of struct rndis_params
instances but instead allow allocating them on demand.

This patch prepares the elimination of the said limit by converting all the
functions which accept rndis config number to accept a pointer to the
actual struct rndis_params. Consequently, rndis_register() returns
a pointer to a corresponding struct rndis_params instance. The pointer
is then always used by f_rndis.c instead of config number when it talks
to rndis.c API.

A nice side-effect of the changes is that many lines of code in rndis.c
become shorter and fit in 80 columns.

If a function prototype changes in rndis.h a style cleanup is made
at the same time, otherwise checkpatch complains that the patch
has style problems.

Signed-off-by: Andrzej Pietrasiewicz 
---
@Felipe:

For some reason the original version was missing an opening "("
at the prototype of rndis_free_response() in rndis.h.
Now it should be fine.

 drivers/usb/gadget/function/f_rndis.c |  38 +++---
 drivers/usb/gadget/function/rndis.c   | 213 +++---
 drivers/usb/gadget/function/rndis.h   |  29 ++---
 3 files changed, 129 insertions(+), 151 deletions(-)

diff --git a/drivers/usb/gadget/function/f_rndis.c 
b/drivers/usb/gadget/function/f_rndis.c
index 829edf8..2dafe72 100644
--- a/drivers/usb/gadget/function/f_rndis.c
+++ b/drivers/usb/gadget/function/f_rndis.c
@@ -76,7 +76,7 @@ struct f_rndis {
u8  ethaddr[ETH_ALEN];
u32 vendorID;
const char  *manufacturer;
-   int config;
+   struct rndis_params *params;
 
struct usb_ep   *notify;
struct usb_request  *notify_req;
@@ -453,7 +453,7 @@ static void rndis_command_complete(struct usb_ep *ep, 
struct usb_request *req)
 
/* received RNDIS command from USB_CDC_SEND_ENCAPSULATED_COMMAND */
 // spin_lock(&dev->lock);
-   status = rndis_msg_parser(rndis->config, (u8 *) req->buf);
+   status = rndis_msg_parser(rndis->params, (u8 *) req->buf);
if (status < 0)
pr_err("RNDIS command error %d, %d/%d\n",
status, req->actual, req->length);
@@ -499,12 +499,12 @@ rndis_setup(struct usb_function *f, const struct 
usb_ctrlrequest *ctrl)
u32 n;
 
/* return the result */
-   buf = rndis_get_next_response(rndis->config, &n);
+   buf = rndis_get_next_response(rndis->params, &n);
if (buf) {
memcpy(req->buf, buf, n);
req->complete = rndis_response_complete;
req->context = rndis;
-   rndis_free_response(rndis->config, buf);
+   rndis_free_response(rndis->params, buf);
value = n;
}
/* else stalls ... spec says to avoid that */
@@ -597,7 +597,7 @@ static int rndis_set_alt(struct usb_function *f, unsigned 
intf, unsigned alt)
if (IS_ERR(net))
return PTR_ERR(net);
 
-   rndis_set_param_dev(rndis->config, net,
+   rndis_set_param_dev(rndis->params, net,
&rndis->port.cdc_filter);
} else
goto fail;
@@ -617,7 +617,7 @@ static void rndis_disable(struct usb_function *f)
 
DBG(cdev, "rndis deactivated\n");
 
-   rndis_uninit(rndis->config);
+   rndis_uninit(rndis->params);
gether_disconnect(&rndis->port);
 
usb_ep_disable(rndis->notify);
@@ -640,9 +640,9 @@ static void rndis_open(struct gether *geth)
 
DBG(cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3,
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3,
bitrate(cdev->gadget) / 100);
-   rndis_signal_connect(rndis->config);
+   rndis_signal_connect(rndis->params);
 }
 
 static void rndis_close(struct gether *geth)
@@ -651,8 +651,8 @@ static void rndis_close(struct gether *geth)
 
DBG(geth->func.config->cdev, "%s\n", __func__);
 
-   rndis_set_param_medium(rndis->config, RNDIS_MEDIUM_802_3, 0);
-   rndis_signal_disconnect(rndis->config);
+   rndis_set_param_medium(rndis->params, RNDIS_MEDIUM_802_3, 0);
+   rndis_signal_disconnect(rndis->params);
 }
 
 /*-*/
@@ -796,11 +796,11 @@ rndis_bind(struct usb_configuration *c, struct 
usb_function *f)
rndis->port.open = rndis_open;
   

Re: [RFC][PATCH 2/9] usb: gadget: add usb_gadget_start/stop()

2015-03-20 Thread Peter Chen
On Thu, Mar 19, 2015 at 04:50:31PM +0200, Roger Quadros wrote:
> On 19/03/15 16:09, Li Jun wrote:
> > On Thu, Mar 19, 2015 at 12:14:39PM +0200, Roger Quadros wrote:
> >> On 19/03/15 05:30, Peter Chen wrote:
> >>> On Wed, Mar 18, 2015 at 03:55:56PM +0200, Roger Quadros wrote:
>  The OTG state machine needs a mechanism to start and
>  stop the gadget controller. Add usb_gadget_start()
>  and usb_gadget_stop().
> 
>  Signed-off-by: Roger Quadros 
>  ---
>   drivers/usb/gadget/udc/udc-core.c | 166 
>  +++---
>   include/linux/usb/gadget.h|   3 +
>   2 files changed, 158 insertions(+), 11 deletions(-)
> 
>  diff --git a/drivers/usb/gadget/udc/udc-core.c 
>  b/drivers/usb/gadget/udc/udc-core.c
>  index 5a81cb0..69b4123 100644
>  --- a/drivers/usb/gadget/udc/udc-core.c
>  +++ b/drivers/usb/gadget/udc/udc-core.c
>  @@ -35,6 +35,8 @@
>    * @dev - the child device to the actual controller
>    * @gadget - the gadget. For use by the class code
>    * @list - for use by the udc class driver
>  + * @running - udc is running
> >>>
> >>> Doesn't OTG FSM should know it?
> >>
> >> Not really, as the gadget driver might not have been loaded yet or 
> >> userspace might
> >> have disabled softconnect when the OTG FSM wants UDC to start.
> >>
> >> So only UDC knows if it has really started or not based on this flag.
> >>
> > 
> > why this can not be known by check the otg fsm state? i.e. if the device in
> > b_peripheral or a_peripheral state, udc should had started, isn't it?
> 
> If gadget function driver (which is different from UDC driver) is not yet 
> loaded
> then we can't start UDC even if otg fsm is in b_peripheral.
> Also, if userspace has disabled softconnect we can't start UDC.
> 
> So, b_peripheral != UDC_started.
> 
> I've tried to address this issue by adding the checks in usb_gadget_start().
> 

Ok, maybe we have different understanding for 'B-Device' at software,
In spec, it says the Micro-AB receptacle with nothing connected can be
'B-Device', but in fact, we may not enable device mode before loading
gadget driver, in chipidea fsm design, if the gadget driver is not
loaded, the FSM will not start, and it is at OTG_STATE_UNDEFINED.

One more thing is we may need to find a place to issue SRP when we
load gadget driver, since we may at b_idle  at that time due to host
closes the vbus (timeout for a_wait_bcon).

What is the "softconnect" used for? In otg fsm, we use b_bus_req for FSM.

-- 

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


Re: [RFC 01/19] extcon: add extcon-odroid-usbotg driver

2015-03-20 Thread Robert Baldyga
Hi Chanwoo,

On 03/19/2015 09:50 PM, Chanwoo Choi wrote:
> Hi Roger,
> 
> On Thu, Mar 19, 2015 at 11:45 PM, Roger Quadros  wrote:
>> On 19/03/15 14:19, George Cherian wrote:
>>> Hi Robert,
>>>
>>> +Roger
>>> On Thu, Mar 19, 2015 at 5:37 PM, Robert Baldyga  
>>> wrote:
 Hi George,

 On 03/19/2015 09:50 AM, George Cherian wrote:
> Hi Robert,
>
> This looks like a extcon driver based on gpio for USB.
>
> Roger posted a generic one a while back.
> https://lkml.org/lkml/2015/2/2/187
>
> Doesn't this serve the purpose rather than adding this driver?

 Roger's driver doesn't support VBUS state detection so it cannot handle
>>> I feel Roger's driver could be extended for supporting VBUS.
>>> Also I think Roger's driver is about to get merged.
>>> Probably, Roger or Chanwoo can better tell that
>>
>> It is already queued for 4.1 and is available in linux-next.
>>
>>>
 situation when USB cable is unpluged. In addition some of Odroid boards
 has only VBUS detection (without ID pin), so this driver cannot handle
 them at all.
>>
>> why not?
>>
>> x15-beagleboard also gets VBUS event over GPIO and I was planning to extent 
>> it
>> to support VBUS detection.
> 
> Sounds good to me to extent extcon-usb-gpio.c.
> I'd like to hold only one extcon driver to support both USB and
> USB-HOST with gpio .
> 
> There are one more extcon-gpio driver in mailing list as following:
> - extcon-usb-gpio.c (will be merged to Linux 4.1)
> - extcon-odroid-usbotg.c
> - extcon-otg_gpio.c [1]
> [1] https://lkml.org/lkml/2015/2/19/411
> 
> The each extcon gpio driver support both USB/USB-HOST cable by using
> different way,
> Because some board which detect USB/USB-HOST by gpio have a little
> different pin composition

These differences are small. In general we have three cases:

1. We have both VBUS and ID pin detection - we can detect USB, USB-HOST
and cable disconnection.

2. We have only VBUS detection - we can detect USB and cable disconnection.

3. We have ID pin only - we can distinguish between USB and USB-HOST but
without ability to detect cable disconnection.

> 
> I think only one extcon driver can support all cases with optional properties.

So my driver in current form is ready for that. Only thing it would need
to change is to make VBUS detection an option (for now is mandatory
because all of supported Odroid boards have it). Then boards with VBUS
detection only or ID pin detection only will be handled also. I can also
change name of the driver to more generic. I'm going to prepare V2 on my
patches today.

Thanks,
Robert Baldyga

> 
> Roger,
> I'd like you to share your plan to extent the extcon-usb-gpio.c for
> removing duplicate work.
> 
> [snip]
> 
> Thanks,
> Chanwoo Choi
> --
> 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
> 

--
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 01/19] extcon: add extcon-odroid-usbotg driver

2015-03-20 Thread Chanwoo Choi
Hi Robert,

On 03/20/2015 04:25 PM, Robert Baldyga wrote:
> Hi Chanwoo,
> 
> On 03/19/2015 09:50 PM, Chanwoo Choi wrote:
>> Hi Roger,
>>
>> On Thu, Mar 19, 2015 at 11:45 PM, Roger Quadros  wrote:
>>> On 19/03/15 14:19, George Cherian wrote:
 Hi Robert,

 +Roger
 On Thu, Mar 19, 2015 at 5:37 PM, Robert Baldyga  
 wrote:
> Hi George,
>
> On 03/19/2015 09:50 AM, George Cherian wrote:
>> Hi Robert,
>>
>> This looks like a extcon driver based on gpio for USB.
>>
>> Roger posted a generic one a while back.
>> https://lkml.org/lkml/2015/2/2/187
>>
>> Doesn't this serve the purpose rather than adding this driver?
>
> Roger's driver doesn't support VBUS state detection so it cannot handle
 I feel Roger's driver could be extended for supporting VBUS.
 Also I think Roger's driver is about to get merged.
 Probably, Roger or Chanwoo can better tell that
>>>
>>> It is already queued for 4.1 and is available in linux-next.
>>>

> situation when USB cable is unpluged. In addition some of Odroid boards
> has only VBUS detection (without ID pin), so this driver cannot handle
> them at all.
>>>
>>> why not?
>>>
>>> x15-beagleboard also gets VBUS event over GPIO and I was planning to extent 
>>> it
>>> to support VBUS detection.
>>
>> Sounds good to me to extent extcon-usb-gpio.c.
>> I'd like to hold only one extcon driver to support both USB and
>> USB-HOST with gpio .
>>
>> There are one more extcon-gpio driver in mailing list as following:
>> - extcon-usb-gpio.c (will be merged to Linux 4.1)
>> - extcon-odroid-usbotg.c
>> - extcon-otg_gpio.c [1]
>> [1] https://lkml.org/lkml/2015/2/19/411
>>
>> The each extcon gpio driver support both USB/USB-HOST cable by using
>> different way,
>> Because some board which detect USB/USB-HOST by gpio have a little
>> different pin composition
> 
> These differences are small. In general we have three cases:
> 
> 1. We have both VBUS and ID pin detection - we can detect USB, USB-HOST
> and cable disconnection.
> 
> 2. We have only VBUS detection - we can detect USB and cable disconnection.
> 
> 3. We have ID pin only - we can distinguish between USB and USB-HOST but
> without ability to detect cable disconnection.
> 
>>
>> I think only one extcon driver can support all cases with optional 
>> properties.
> 
> So my driver in current form is ready for that. Only thing it would need
> to change is to make VBUS detection an option (for now is mandatory
> because all of supported Odroid boards have it). Then boards with VBUS
> detection only or ID pin detection only will be handled also. I can also
> change name of the driver to more generic. I'm going to prepare V2 on my
> patches today.

Could you implement this feature on extcon-usb-gpio.c to support various pin 
composition?
because extcon-usb-gpio.c was already implemented by Roger.
If you implement other extcon driver to detect USB/USB-HOST cable by using gpio,
there will be similar two extcon gpio driver for USB cable.

And,
As Roger comment, he have the plan to extend the extcon-usb-gpio.c.
So, If you will implement some feature for extcon driver with gpio,
I'd like you to share your plan this thread to remove duplicat work.

Thanks,
Chanwoo Choi

> 
> Thanks,
> Robert Baldyga
> 
>>
>> Roger,
>> I'd like you to share your plan to extent the extcon-usb-gpio.c for
>> removing duplicate work.
>>
>> [snip]
>>
>> Thanks,
>> Chanwoo Choi
>> --
>> 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
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 

--
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 3/9] usb: otg: add OTG core

2015-03-20 Thread Peter Chen
On Thu, Mar 19, 2015 at 12:18:55PM +0200, Roger Quadros wrote:
> On 19/03/15 05:40, Peter Chen wrote:
> > On Wed, Mar 18, 2015 at 03:55:57PM +0200, Roger Quadros wrote:
> >> The OTG core instantiates the OTG Finite State Machine
> >> per OTG controller and manages starting/stopping the
> >> host and gadget controllers based on the bus state.
> >>
> >> It provides APIs for the following tasks
> >>
> >> - Registering an OTG capable controller
> >> - Registering Host and Gadget controllers to OTG core
> >> - Providing inputs to and kicking the OTG state machine
> >>
> >> TODO:
> >> - sysfs interface to allow application inputs to OTG state machine
> >> - otg class?
> >>
> >> Signed-off-by: Roger Quadros 
> >> ---
> >>  drivers/usb/Makefile |   1 +
> >>  drivers/usb/common/Makefile  |   1 +
> >>  drivers/usb/common/usb-otg.c | 732 
> >> +++
> >>  drivers/usb/common/usb-otg.h |  71 +
> >>  drivers/usb/core/Kconfig |   8 +
> >>  include/linux/usb/usb-otg.h  |  86 +
> >>  6 files changed, 899 insertions(+)
> >>  create mode 100644 drivers/usb/common/usb-otg.c
> >>  create mode 100644 drivers/usb/common/usb-otg.h
> >>  create mode 100644 include/linux/usb/usb-otg.h
> >>
> >> diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
> >> index 2f1e2aa..07f59a5 100644
> >> --- a/drivers/usb/Makefile
> >> +++ b/drivers/usb/Makefile
> >> @@ -60,5 +60,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS)  += renesas_usbhs/
> >>  obj-$(CONFIG_USB_GADGET)  += gadget/
> >>  
> >>  obj-$(CONFIG_USB_COMMON)  += common/
> >> +obj-$(CONFIG_USB_OTG_CORE)+= common/
> >>  
> >>  obj-$(CONFIG_USBIP_CORE)  += usbip/
> >> diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
> >> index ca2f8bd..573fc75 100644
> >> --- a/drivers/usb/common/Makefile
> >> +++ b/drivers/usb/common/Makefile
> >> @@ -7,3 +7,4 @@ usb-common-y += common.o
> >>  usb-common-$(CONFIG_USB_LED_TRIG) += led.o
> >>  
> >>  obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
> >> +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
> >> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> >> new file mode 100644
> >> index 000..1433fc9
> >> --- /dev/null
> >> +++ b/drivers/usb/common/usb-otg.c
> >> @@ -0,0 +1,732 @@
> >> +/**
> >> + * drivers/usb/common/usb-otg.c - USB OTG core
> >> + *
> >> + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
> >> + * Author: Roger Quadros 
> >> + *
> >> + * 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.
> >> + *
> >> + * This program is distributed in the hope that it will be useful,
> >> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> >> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> >> + * GNU General Public License for more details.
> >> + */
> >> +
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include 
> >> +#include /* enum usb_otg_state */
> >> +#include 
> >> +#include 
> >> +#include 
> >> +
> >> +#include "usb-otg.h"
> >> +
> >> +/* to link timer with callback data */
> >> +struct otg_timer {
> >> +  struct timer_list timer;
> >> +  /* callback data */
> >> +  int *timeout_bit;
> >> +  struct otg_data *otgd;
> >> +};
> >> +
> >> +struct otg_data {
> >> +  struct device *dev; /* HCD & GCD's parent device */
> >> +
> >> +  struct otg_fsm fsm;
> >> +  /* HCD, GCD and usb_otg_state are present in otg_fsm->otg
> >> +   * HCD is bus_to_hcd(fsm->otg->host)
> >> +   * GCD is fsm->otg->gadget
> >> +   */
> >> +  struct otg_fsm_ops fsm_ops; /* private copy for override */
> >> +  struct usb_otg otg;
> >> +  struct usb_hcd *shared_hcd; /* if shared HCD registered */
> >> +
> >> +  /* saved hooks to OTG device */
> >> +  int (*start_host)(struct otg_fsm *fsm, int on);
> >> +  int (*start_gadget)(struct otg_fsm *fsm, int on);
> >> +
> >> +  struct list_head list;
> >> +
> >> +  struct work_struct work;/* OTG FSM work */
> >> +  struct workqueue_struct *wq;
> >> +
> >> +  struct otg_timer timers[NUM_OTG_FSM_TIMERS];
> >> +
> >> +  bool fsm_running;
> >> +  bool gadget_can_start;  /* OTG FSM says gadget can start */
> >> +  bool host_can_start;/* OTG FSM says host can start */
> >> +
> >> +  /* use otg->fsm.lock for serializing access */
> >> +};
> > 
> > What's the relationship between struct usb_otg otg and this one?
> 
> Did you mean why struct usb_otg otg is there in struct otg_data?
> Just for easy allocation. fsm_ops only contains the pointer to struct usb_otg.
> 

The reason why I ask this question is the most structures at usb_otg
(only enum usb_otg_state)are useless for otg_fsm, this structure may
only for hardware otg fsm driver, so your OTG framework should only
for software FSM drivers, right?

Peter

> > 
> >> +
> >> +/* OTG device list */
> >> +LIST_HEAD(otg_list

[PATCH] cdc-acm: fix race between callback and unthrottle

2015-03-20 Thread Oliver Neukum
Abn URB may be may marked free only after the buffer has been
processed or there is a small window during which it could
be submitted on another CPU and overwrite an unprocessed buffer

Signed-off-by: Oliver Neukum 
---
 drivers/usb/class/cdc-acm.c | 12 ++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 6836177..58241ec 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -417,25 +417,33 @@ static void acm_read_bulk_callback(struct urb *urb)
struct acm_rb *rb = urb->context;
struct acm *acm = rb->instance;
unsigned long flags;
+   int status = urb->status;
 
dev_vdbg(&acm->data->dev, "%s - urb %d, len %d\n", __func__,
rb->index, urb->actual_length);
-   set_bit(rb->index, &acm->read_urbs_free);
 
if (!acm->dev) {
+   set_bit(rb->index, &acm->read_urbs_free);
dev_dbg(&acm->data->dev, "%s - disconnected\n", __func__);
return;
}
 
if (urb->status) {
+   set_bit(rb->index, &acm->read_urbs_free);
dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
-   __func__, urb->status);
+   __func__, status);
return;
}
 
usb_mark_last_busy(acm->dev);
 
acm_process_read_urb(acm, urb);
+   /*
+* Unthrottle may run on another CPU which needs to see events
+* in the same order. Submission has an implict barrier
+*/
+   smp_mb__before_atomic();
+   set_bit(rb->index, &acm->read_urbs_free);
 
/* throttle device if requested by tty */
spin_lock_irqsave(&acm->read_lock, flags);
-- 
2.1.4

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


[PATCH 3/5] usb: chipidea: use hrtimer for otg fsm timers

2015-03-20 Thread Peter Chen
From: Li Jun 

Current otg fsm timers are using controller 1ms irq and count it, this patch
is to replace it with hrtimer solution, use one hrtimer for all otg timers.

Signed-off-by: Li Jun 
Signed-off-by: Peter Chen 
---
 drivers/usb/chipidea/ci.h  |  10 +-
 drivers/usb/chipidea/otg_fsm.c | 364 -
 drivers/usb/chipidea/otg_fsm.h |  13 --
 3 files changed, 190 insertions(+), 197 deletions(-)

diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
index c09381d..6d6200e 100644
--- a/drivers/usb/chipidea/ci.h
+++ b/drivers/usb/chipidea/ci.h
@@ -162,7 +162,10 @@ struct hw_bank {
  * @role: current role
  * @is_otg: if the device is otg-capable
  * @fsm: otg finite state machine
- * @fsm_timer: pointer to timer list of otg fsm
+ * @otg_fsm_hrtimer: hrtimer for otg fsm timers
+ * @hr_timeouts: time out list for active otg fsm timers
+ * @enabled_otg_timer_bits: bits of enabled otg timers
+ * @next_otg_timer: next nearest enabled timer to be expired
  * @work: work for role changing
  * @wq: workqueue thread
  * @qh_pool: allocation pool for queue heads
@@ -205,7 +208,10 @@ struct ci_hdrc {
boolis_otg;
struct usb_otg  otg;
struct otg_fsm  fsm;
-   struct ci_otg_fsm_timer_list*fsm_timer;
+   struct hrtimer  otg_fsm_hrtimer;
+   ktime_t hr_timeouts[NUM_OTG_FSM_TIMERS];
+   unsignedenabled_otg_timer_bits;
+   enum otg_fsm_timer  next_otg_timer;
struct work_struct  work;
struct workqueue_struct *wq;
 
diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index ba2cb91..083acf4 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -30,22 +30,6 @@
 #include "otg.h"
 #include "otg_fsm.h"
 
-static struct ci_otg_fsm_timer *otg_timer_initializer
-(struct ci_hdrc *ci, void (*function)(void *, unsigned long),
-   unsigned long expires, unsigned long data)
-{
-   struct ci_otg_fsm_timer *timer;
-
-   timer = devm_kzalloc(ci->dev, sizeof(struct ci_otg_fsm_timer),
-   GFP_KERNEL);
-   if (!timer)
-   return NULL;
-   timer->function = function;
-   timer->expires = expires;
-   timer->data = data;
-   return timer;
-}
-
 /* Add for otg: interact with user space app */
 static ssize_t
 get_a_bus_req(struct device *dev, struct device_attribute *attr, char *buf)
@@ -204,36 +188,48 @@ static struct attribute_group inputs_attr_group = {
 };
 
 /*
+ * Keep this list in the same order as timers indexed
+ * by enum otg_fsm_timer in include/linux/usb/otg-fsm.h
+ */
+static unsigned otg_timer_ms[] = {
+   TA_WAIT_VRISE,
+   TA_WAIT_VFALL,
+   TA_WAIT_BCON,
+   TA_AIDL_BDIS,
+   TB_ASE0_BRST,
+   TA_BIDL_ADIS,
+   TB_SE0_SRP,
+   TB_SRP_FAIL,
+   0,
+   TB_DATA_PLS,
+   TB_SSEND_SRP,
+};
+
+/*
  * Add timer to active timer list
  */
 static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
 {
-   struct ci_otg_fsm_timer *tmp_timer;
-   struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
-   struct list_head *active_timers = &ci->fsm_timer->active_timers;
+   unsigned long flags, timer_sec, timer_nsec;
 
if (t >= NUM_OTG_FSM_TIMERS)
return;
 
-   /*
-* Check if the timer is already in the active list,
-* if so update timer count
-*/
-   list_for_each_entry(tmp_timer, active_timers, list)
-   if (tmp_timer == timer) {
-   timer->count = timer->expires;
-   return;
-   }
-
-   if (list_empty(active_timers))
-   pm_runtime_get(ci->dev);
-
-   timer->count = timer->expires;
-   list_add_tail(&timer->list, active_timers);
-
-   /* Enable 1ms irq */
-   if (!(hw_read_otgsc(ci, OTGSC_1MSIE)))
-   hw_write_otgsc(ci, OTGSC_1MSIE, OTGSC_1MSIE);
+   spin_lock_irqsave(&ci->lock, flags);
+   timer_sec = otg_timer_ms[t] / MSEC_PER_SEC;
+   timer_nsec = (otg_timer_ms[t] % MSEC_PER_SEC) * NSEC_PER_MSEC;
+   ci->hr_timeouts[t] = ktime_add(ktime_get(),
+   ktime_set(timer_sec, timer_nsec));
+   ci->enabled_otg_timer_bits |= (1 << t);
+   if ((ci->next_otg_timer == NUM_OTG_FSM_TIMERS) ||
+   (ci->hr_timeouts[ci->next_otg_timer].tv64 >
+   ci->hr_timeouts[t].tv64)) {
+   ci->next_otg_timer = t;
+   hrtimer_start_range_ns(&ci->otg_fsm_hrtimer,
+   ci->hr_timeouts[t], NSEC_PER_MSEC,
+   HRTIMER_MODE_ABS);
+   }
+   spin_unlock_

[PATCH 1/5] usb: chipidea: otg: remove unnecessary B_SESS_VLD timer

2015-03-20 Thread Peter Chen
From: Li Jun 

Since BSV irq is enabled for B-device all the time, so B_SESS_VLD timer
is not required, and also no need to check BSV status when B_ASE0_BRST
timer timeout.

Signed-off-by: Li Jun 
Signed-off-by: Peter Chen 
---
 drivers/usb/chipidea/otg_fsm.c | 31 +--
 drivers/usb/chipidea/otg_fsm.h |  3 ---
 2 files changed, 1 insertion(+), 33 deletions(-)

diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index e3cf5be..3014e2c 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -320,17 +320,6 @@ static void a_wait_vfall_tmout_func(void *ptr, unsigned 
long indicator)
ci_otg_queue_work(ci);
 }
 
-static void b_ase0_brst_tmout_func(void *ptr, unsigned long indicator)
-{
-   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
-
-   set_tmout(ci, indicator);
-   if (!hw_read_otgsc(ci, OTGSC_BSV))
-   ci->fsm.b_sess_vld = 0;
-
-   ci_otg_queue_work(ci);
-}
-
 static void b_ssend_srp_tmout_func(void *ptr, unsigned long indicator)
 {
struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
@@ -342,18 +331,6 @@ static void b_ssend_srp_tmout_func(void *ptr, unsigned 
long indicator)
ci_otg_queue_work(ci);
 }
 
-static void b_sess_vld_tmout_func(void *ptr, unsigned long indicator)
-{
-   struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
-
-   /* Check if A detached */
-   if (!(hw_read_otgsc(ci, OTGSC_BSV))) {
-   ci->fsm.b_sess_vld = 0;
-   ci_otg_add_timer(ci, B_SSEND_SRP);
-   ci_otg_queue_work(ci);
-   }
-}
-
 static void b_data_pulse_end(void *ptr, unsigned long indicator)
 {
struct ci_hdrc *ci = (struct ci_hdrc *)ptr;
@@ -405,7 +382,7 @@ static int ci_otg_init_timers(struct ci_hdrc *ci)
return -ENOMEM;
 
ci->fsm_timer->timer_list[B_ASE0_BRST] =
-   otg_timer_initializer(ci, &b_ase0_brst_tmout_func, TB_ASE0_BRST,
+   otg_timer_initializer(ci, &set_tmout_and_fsm, TB_ASE0_BRST,
(unsigned long)&fsm->b_ase0_brst_tmout);
if (ci->fsm_timer->timer_list[B_ASE0_BRST] == NULL)
return -ENOMEM;
@@ -433,11 +410,6 @@ static int ci_otg_init_timers(struct ci_hdrc *ci)
if (ci->fsm_timer->timer_list[B_DATA_PLS] == NULL)
return -ENOMEM;
 
-   ci->fsm_timer->timer_list[B_SESS_VLD] = otg_timer_initializer(ci,
-   &b_sess_vld_tmout_func, TB_SESS_VLD, 0);
-   if (ci->fsm_timer->timer_list[B_SESS_VLD] == NULL)
-   return -ENOMEM;
-
return 0;
 }
 
@@ -671,7 +643,6 @@ static void ci_otg_fsm_event(struct ci_hdrc *ci)
fsm->a_conn = 0;
fsm->b_bus_req = 0;
ci_otg_queue_work(ci);
-   ci_otg_add_timer(ci, B_SESS_VLD);
}
break;
case OTG_STATE_A_PERIPHERAL:
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
index 94c085f..d0ad4f9 100644
--- a/drivers/usb/chipidea/otg_fsm.h
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -62,8 +62,6 @@
 /* SSEND time before SRP */
 #define TB_SSEND_SRP (1500)/* minimum 1.5 sec, section:5.1.2 */
 
-#define TB_SESS_VLD  (1000)
-
 enum ci_otg_fsm_timer_index {
/*
 * CI specific timers, start from the end
@@ -71,7 +69,6 @@ enum ci_otg_fsm_timer_index {
 */
B_DATA_PLS = NUM_OTG_FSM_TIMERS,
B_SSEND_SRP,
-   B_SESS_VLD,
 
NUM_CI_OTG_FSM_TIMERS,
 };
-- 
1.9.1

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


[PATCH 2/5] usb: otg-fsm: move 2 otg fsm timers definition to otg_fsm_timer

2015-03-20 Thread Peter Chen
From: Li Jun 

B_DATA_PLS(data-line pulse time) and B_SSEND_SRP(session end to SRP init) are
also from OTG&EH 2.0 Specification and they are not chipidea specific.

Signed-off-by: Li Jun 
Signed-off-by: Peter Chen 
---
 drivers/usb/chipidea/otg_fsm.c |  8 
 drivers/usb/chipidea/otg_fsm.h | 13 +
 include/linux/usb/otg-fsm.h|  2 ++
 3 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
index 3014e2c..ba2cb91 100644
--- a/drivers/usb/chipidea/otg_fsm.c
+++ b/drivers/usb/chipidea/otg_fsm.c
@@ -206,13 +206,13 @@ static struct attribute_group inputs_attr_group = {
 /*
  * Add timer to active timer list
  */
-static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
+static void ci_otg_add_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
 {
struct ci_otg_fsm_timer *tmp_timer;
struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
struct list_head *active_timers = &ci->fsm_timer->active_timers;
 
-   if (t >= NUM_CI_OTG_FSM_TIMERS)
+   if (t >= NUM_OTG_FSM_TIMERS)
return;
 
/*
@@ -239,14 +239,14 @@ static void ci_otg_add_timer(struct ci_hdrc *ci, enum 
ci_otg_fsm_timer_index t)
 /*
  * Remove timer from active timer list
  */
-static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index t)
+static void ci_otg_del_timer(struct ci_hdrc *ci, enum otg_fsm_timer t)
 {
struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
struct list_head *active_timers = &ci->fsm_timer->active_timers;
int flag = 0;
 
-   if (t >= NUM_CI_OTG_FSM_TIMERS)
+   if (t >= NUM_OTG_FSM_TIMERS)
return;
 
list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list)
diff --git a/drivers/usb/chipidea/otg_fsm.h b/drivers/usb/chipidea/otg_fsm.h
index d0ad4f9..9e0fc4c 100644
--- a/drivers/usb/chipidea/otg_fsm.h
+++ b/drivers/usb/chipidea/otg_fsm.h
@@ -62,17 +62,6 @@
 /* SSEND time before SRP */
 #define TB_SSEND_SRP (1500)/* minimum 1.5 sec, section:5.1.2 */
 
-enum ci_otg_fsm_timer_index {
-   /*
-* CI specific timers, start from the end
-* of standard and auxiliary OTG timers
-*/
-   B_DATA_PLS = NUM_OTG_FSM_TIMERS,
-   B_SSEND_SRP,
-
-   NUM_CI_OTG_FSM_TIMERS,
-};
-
 struct ci_otg_fsm_timer {
unsigned long expires;  /* Number of count increase to timeout */
unsigned long count;/* Tick counter */
@@ -82,7 +71,7 @@ struct ci_otg_fsm_timer {
 };
 
 struct ci_otg_fsm_timer_list {
-   struct ci_otg_fsm_timer *timer_list[NUM_CI_OTG_FSM_TIMERS];
+   struct ci_otg_fsm_timer *timer_list[NUM_OTG_FSM_TIMERS];
struct list_head active_timers;
 };
 
diff --git a/include/linux/usb/otg-fsm.h b/include/linux/usb/otg-fsm.h
index b6ba1bf..f728f18 100644
--- a/include/linux/usb/otg-fsm.h
+++ b/include/linux/usb/otg-fsm.h
@@ -53,6 +53,8 @@ enum otg_fsm_timer {
B_SE0_SRP,
B_SRP_FAIL,
A_WAIT_ENUM,
+   B_DATA_PLS,
+   B_SSEND_SRP,
 
NUM_OTG_FSM_TIMERS,
 };
-- 
1.9.1

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


[PATCH 4/5] chipidea: introduce specific Kconfig options for glue drivers

2015-03-20 Thread Peter Chen
From: Andy Shevchenko 

This patch introduces USB_CHIPIDEA_PCI and USB_CHIPIDEA_OF Kconfig options, one
per each specific glue driver. This is needed to provide different dependencies
they have.

Signed-off-by: Andy Shevchenko 
Signed-off-by: Peter Chen 
---
 drivers/usb/chipidea/Kconfig  | 10 ++
 drivers/usb/chipidea/Makefile |  9 ++---
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index 77b47d8..8b0edb9 100644
--- a/drivers/usb/chipidea/Kconfig
+++ b/drivers/usb/chipidea/Kconfig
@@ -10,6 +10,16 @@ config USB_CHIPIDEA
 
 if USB_CHIPIDEA
 
+config USB_CHIPIDEA_OF
+   tristate
+   depends on OF
+   default USB_CHIPIDEA
+
+config USB_CHIPIDEA_PCI
+   tristate
+   depends on PCI
+   default USB_CHIPIDEA
+
 config USB_CHIPIDEA_UDC
bool "ChipIdea device controller"
depends on USB_GADGET
diff --git a/drivers/usb/chipidea/Makefile b/drivers/usb/chipidea/Makefile
index 1fc86a2..4decb12 100644
--- a/drivers/usb/chipidea/Makefile
+++ b/drivers/usb/chipidea/Makefile
@@ -14,11 +14,6 @@ obj-$(CONFIG_USB_CHIPIDEA)   += ci_hdrc_usb2.o
 obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_msm.o
 obj-$(CONFIG_USB_CHIPIDEA) += ci_hdrc_zevio.o
 
-# PCI doesn't provide stubs, need to check
-ifneq ($(CONFIG_PCI),)
-   obj-$(CONFIG_USB_CHIPIDEA)  += ci_hdrc_pci.o
-endif
+obj-$(CONFIG_USB_CHIPIDEA_PCI) += ci_hdrc_pci.o
 
-ifneq ($(CONFIG_OF),)
-   obj-$(CONFIG_USB_CHIPIDEA)  += usbmisc_imx.o ci_hdrc_imx.o
-endif
+obj-$(CONFIG_USB_CHIPIDEA_OF)  += usbmisc_imx.o ci_hdrc_imx.o
-- 
1.9.1

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


[PATCH 0/5] chipidea patches for v4.1 (for building error)

2015-03-20 Thread Peter Chen
Hi Greg,

There are two updates in this set, one for build error found
by kbuild test robot, the other is using hrtimer to replace
hardware 1ms timer for OTG fsm.

Andy Shevchenko (2):
  chipidea: introduce specific Kconfig options for glue drivers
  chipidea: pci: make it depends on NOP_USB_XCEIV

Li Jun (3):
  usb: chipidea: otg: remove unnecessary B_SESS_VLD timer
  usb: otg-fsm: move 2 otg fsm timers definition to otg_fsm_timer
  usb: chipidea: use hrtimer for otg fsm timers

 drivers/usb/chipidea/Kconfig   |  11 ++
 drivers/usb/chipidea/Makefile  |   9 +-
 drivers/usb/chipidea/ci.h  |  10 +-
 drivers/usb/chipidea/otg_fsm.c | 391 +++--
 drivers/usb/chipidea/otg_fsm.h |  27 ---
 include/linux/usb/otg-fsm.h|   2 +
 6 files changed, 204 insertions(+), 246 deletions(-)

-- 
1.9.1

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


[PATCH 5/5] chipidea: pci: make it depends on NOP_USB_XCEIV

2015-03-20 Thread Peter Chen
From: Andy Shevchenko 

After commit ba1aff67f99a (chipidea: pci: register nop PHY) the PCI glue driver
requires nop-PHY to be selected. Thus, make it an explicit dependency.

Reported-by: kbuild test robot 
Fixes: ba1aff67f99a (chipidea: pci: register nop PHY)
Signed-off-by: Andy Shevchenko 
Signed-off-by: Peter Chen 
---
 drivers/usb/chipidea/Kconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/chipidea/Kconfig b/drivers/usb/chipidea/Kconfig
index 8b0edb9..5ce3f1d 100644
--- a/drivers/usb/chipidea/Kconfig
+++ b/drivers/usb/chipidea/Kconfig
@@ -18,6 +18,7 @@ config USB_CHIPIDEA_OF
 config USB_CHIPIDEA_PCI
tristate
depends on PCI
+   depends on NOP_USB_XCEIV
default USB_CHIPIDEA
 
 config USB_CHIPIDEA_UDC
-- 
1.9.1

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


Re: [RFC 01/19] extcon: add extcon-odroid-usbotg driver

2015-03-20 Thread Roger Quadros
Chanwoo & Robert,

On 20/03/15 09:45, Chanwoo Choi wrote:
> Hi Robert,
> 
> On 03/20/2015 04:25 PM, Robert Baldyga wrote:
>> Hi Chanwoo,
>>
>> On 03/19/2015 09:50 PM, Chanwoo Choi wrote:
>>> Hi Roger,
>>>
>>> On Thu, Mar 19, 2015 at 11:45 PM, Roger Quadros  wrote:
 On 19/03/15 14:19, George Cherian wrote:
> Hi Robert,
>
> +Roger
> On Thu, Mar 19, 2015 at 5:37 PM, Robert Baldyga  
> wrote:
>> Hi George,
>>
>> On 03/19/2015 09:50 AM, George Cherian wrote:
>>> Hi Robert,
>>>
>>> This looks like a extcon driver based on gpio for USB.
>>>
>>> Roger posted a generic one a while back.
>>> https://lkml.org/lkml/2015/2/2/187
>>>
>>> Doesn't this serve the purpose rather than adding this driver?
>>
>> Roger's driver doesn't support VBUS state detection so it cannot handle
> I feel Roger's driver could be extended for supporting VBUS.
> Also I think Roger's driver is about to get merged.
> Probably, Roger or Chanwoo can better tell that

 It is already queued for 4.1 and is available in linux-next.

>
>> situation when USB cable is unpluged. In addition some of Odroid boards
>> has only VBUS detection (without ID pin), so this driver cannot handle
>> them at all.

 why not?

 x15-beagleboard also gets VBUS event over GPIO and I was planning to 
 extent it
 to support VBUS detection.
>>>
>>> Sounds good to me to extent extcon-usb-gpio.c.
>>> I'd like to hold only one extcon driver to support both USB and
>>> USB-HOST with gpio .
>>>
>>> There are one more extcon-gpio driver in mailing list as following:
>>> - extcon-usb-gpio.c (will be merged to Linux 4.1)
>>> - extcon-odroid-usbotg.c
>>> - extcon-otg_gpio.c [1]
>>> [1] https://lkml.org/lkml/2015/2/19/411
>>>
>>> The each extcon gpio driver support both USB/USB-HOST cable by using
>>> different way,
>>> Because some board which detect USB/USB-HOST by gpio have a little
>>> different pin composition
>>
>> These differences are small. In general we have three cases:
>>
>> 1. We have both VBUS and ID pin detection - we can detect USB, USB-HOST
>> and cable disconnection.
>>
>> 2. We have only VBUS detection - we can detect USB and cable disconnection.
>>
>> 3. We have ID pin only - we can distinguish between USB and USB-HOST but
>> without ability to detect cable disconnection.
>>
>>>
>>> I think only one extcon driver can support all cases with optional 
>>> properties.
>>
>> So my driver in current form is ready for that. Only thing it would need
>> to change is to make VBUS detection an option (for now is mandatory
>> because all of supported Odroid boards have it). Then boards with VBUS
>> detection only or ID pin detection only will be handled also. I can also
>> change name of the driver to more generic. I'm going to prepare V2 on my
>> patches today.
> 
> Could you implement this feature on extcon-usb-gpio.c to support various pin 
> composition?
> because extcon-usb-gpio.c was already implemented by Roger.
> If you implement other extcon driver to detect USB/USB-HOST cable by using 
> gpio,
> there will be similar two extcon gpio driver for USB cable.
> 
> And,
> As Roger comment, he have the plan to extend the extcon-usb-gpio.c.
> So, If you will implement some feature for extcon driver with gpio,
> I'd like you to share your plan this thread to remove duplicat work.

extcon-usb-gpio.c supports case (3). (only ID pin)
I have plans to support case (1). (both ID and VBUS)

But Robert can go ahead and implement (2) and (1) over extcon-usb-gpio.c
if he wishes. The driver can easily decide which logic to follow depending on 
the
availability of the GPIO pins in the device tree.

cheers,
-roger

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


Re: [PATCH] usb: Add driver for Altus Metrum ChaosKey device (v2)

2015-03-20 Thread Oliver Neukum
On Thu, 2015-03-19 at 20:36 -0700, Keith Packard wrote:
> This is a hardware random number generator. The driver provides both a
> /dev/chaoskeyX entry and hooks the entropy source up to the kernel
> hwrng interface. More information about the device can be found at

It looks good to me.

Regards
Oliver


--
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 3/9] usb: otg: add OTG core

2015-03-20 Thread Roger Quadros
On 20/03/15 09:45, Peter Chen wrote:
> On Thu, Mar 19, 2015 at 12:18:55PM +0200, Roger Quadros wrote:
>> On 19/03/15 05:40, Peter Chen wrote:
>>> On Wed, Mar 18, 2015 at 03:55:57PM +0200, Roger Quadros wrote:
 The OTG core instantiates the OTG Finite State Machine
 per OTG controller and manages starting/stopping the
 host and gadget controllers based on the bus state.

 It provides APIs for the following tasks

 - Registering an OTG capable controller
 - Registering Host and Gadget controllers to OTG core
 - Providing inputs to and kicking the OTG state machine

 TODO:
 - sysfs interface to allow application inputs to OTG state machine
 - otg class?

 Signed-off-by: Roger Quadros 
 ---
  drivers/usb/Makefile |   1 +
  drivers/usb/common/Makefile  |   1 +
  drivers/usb/common/usb-otg.c | 732 
 +++
  drivers/usb/common/usb-otg.h |  71 +
  drivers/usb/core/Kconfig |   8 +
  include/linux/usb/usb-otg.h  |  86 +
  6 files changed, 899 insertions(+)
  create mode 100644 drivers/usb/common/usb-otg.c
  create mode 100644 drivers/usb/common/usb-otg.h
  create mode 100644 include/linux/usb/usb-otg.h

 diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
 index 2f1e2aa..07f59a5 100644
 --- a/drivers/usb/Makefile
 +++ b/drivers/usb/Makefile
 @@ -60,5 +60,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS)  += renesas_usbhs/
  obj-$(CONFIG_USB_GADGET)  += gadget/
  
  obj-$(CONFIG_USB_COMMON)  += common/
 +obj-$(CONFIG_USB_OTG_CORE)+= common/
  
  obj-$(CONFIG_USBIP_CORE)  += usbip/
 diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
 index ca2f8bd..573fc75 100644
 --- a/drivers/usb/common/Makefile
 +++ b/drivers/usb/common/Makefile
 @@ -7,3 +7,4 @@ usb-common-y += common.o
  usb-common-$(CONFIG_USB_LED_TRIG) += led.o
  
  obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
 +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
 diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
 new file mode 100644
 index 000..1433fc9
 --- /dev/null
 +++ b/drivers/usb/common/usb-otg.c
 @@ -0,0 +1,732 @@
 +/**
 + * drivers/usb/common/usb-otg.c - USB OTG core
 + *
 + * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com
 + * Author: Roger Quadros 
 + *
 + * 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.
 + *
 + * This program is distributed in the hope that it will be useful,
 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 + * GNU General Public License for more details.
 + */
 +
 +#include 
 +#include 
 +#include 
 +#include 
 +#include /* enum usb_otg_state */
 +#include 
 +#include 
 +#include 
 +
 +#include "usb-otg.h"
 +
 +/* to link timer with callback data */
 +struct otg_timer {
 +  struct timer_list timer;
 +  /* callback data */
 +  int *timeout_bit;
 +  struct otg_data *otgd;
 +};
 +
 +struct otg_data {
 +  struct device *dev; /* HCD & GCD's parent device */
 +
 +  struct otg_fsm fsm;
 +  /* HCD, GCD and usb_otg_state are present in otg_fsm->otg
 +   * HCD is bus_to_hcd(fsm->otg->host)
 +   * GCD is fsm->otg->gadget
 +   */
 +  struct otg_fsm_ops fsm_ops; /* private copy for override */
 +  struct usb_otg otg;
 +  struct usb_hcd *shared_hcd; /* if shared HCD registered */
 +
 +  /* saved hooks to OTG device */
 +  int (*start_host)(struct otg_fsm *fsm, int on);
 +  int (*start_gadget)(struct otg_fsm *fsm, int on);
 +
 +  struct list_head list;
 +
 +  struct work_struct work;/* OTG FSM work */
 +  struct workqueue_struct *wq;
 +
 +  struct otg_timer timers[NUM_OTG_FSM_TIMERS];
 +
 +  bool fsm_running;
 +  bool gadget_can_start;  /* OTG FSM says gadget can start */
 +  bool host_can_start;/* OTG FSM says host can start */
 +
 +  /* use otg->fsm.lock for serializing access */
 +};
>>>
>>> What's the relationship between struct usb_otg otg and this one?
>>
>> Did you mean why struct usb_otg otg is there in struct otg_data?
>> Just for easy allocation. fsm_ops only contains the pointer to struct 
>> usb_otg.
>>
> 
> The reason why I ask this question is the most structures at usb_otg
> (only enum usb_otg_state)are useless for otg_fsm, this structure may
> only for hardware otg fsm driver, so your OTG framework should only
> for software FSM drivers, right?

right. we only n

RE: [RFC][PATCH 3/9] usb: otg: add OTG core

2015-03-20 Thread Peter Chen
 
> 
>  - Registering an OTG capable controller
>  - Registering Host and Gadget controllers to OTG core
>  - Providing inputs to and kicking the OTG state machine
> 
>  TODO:
>  - sysfs interface to allow application inputs to OTG state machine
>  - otg class?
> 
>  Signed-off-by: Roger Quadros 
>  ---
>   drivers/usb/Makefile |   1 +
>   drivers/usb/common/Makefile  |   1 +
>   drivers/usb/common/usb-otg.c | 732
>  +++
>   drivers/usb/common/usb-otg.h |  71 +
>   drivers/usb/core/Kconfig |   8 +
>   include/linux/usb/usb-otg.h  |  86 +
>   6 files changed, 899 insertions(+)  create mode 100644
>  drivers/usb/common/usb-otg.c  create mode 100644
>  drivers/usb/common/usb-otg.h  create mode 100644
>  include/linux/usb/usb-otg.h
> 
>  diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile index
>  2f1e2aa..07f59a5 100644
>  --- a/drivers/usb/Makefile
>  +++ b/drivers/usb/Makefile
>  @@ -60,5 +60,6 @@ obj-$(CONFIG_USB_RENESAS_USBHS)+=
> renesas_usbhs/
>   obj-$(CONFIG_USB_GADGET)+= gadget/
> 
>   obj-$(CONFIG_USB_COMMON)+= common/
>  +obj-$(CONFIG_USB_OTG_CORE)  += common/
> 
>   obj-$(CONFIG_USBIP_CORE)+= usbip/
>  diff --git a/drivers/usb/common/Makefile
>  b/drivers/usb/common/Makefile index ca2f8bd..573fc75 100644
>  --- a/drivers/usb/common/Makefile
>  +++ b/drivers/usb/common/Makefile
>  @@ -7,3 +7,4 @@ usb-common-y   += common.o
>   usb-common-$(CONFIG_USB_LED_TRIG) += led.o
> 
>   obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
>  +obj-$(CONFIG_USB_OTG_CORE) += usb-otg.o
>  diff --git a/drivers/usb/common/usb-otg.c
>  b/drivers/usb/common/usb-otg.c new file mode 100644 index
>  000..1433fc9
>  --- /dev/null
>  +++ b/drivers/usb/common/usb-otg.c
>  @@ -0,0 +1,732 @@
>  +/**
>  + * drivers/usb/common/usb-otg.c - USB OTG core
>  + *
>  + * Copyright (C) 2015 Texas Instruments Incorporated -
>  +http://www.ti.com
>  + * Author: Roger Quadros 
>  + *
>  + * 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.
>  + *
>  + * This program is distributed in the hope that it will be useful,
>  + * but WITHOUT ANY WARRANTY; without even the implied warranty of
>  + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
>  + * GNU General Public License for more details.
>  + */
>  +
>  +#include 
>  +#include 
>  +#include 
>  +#include 
>  +#include   /* enum usb_otg_state */
>  +#include 
>  +#include 
>  +#include 
>  +
>  +#include "usb-otg.h"
>  +
>  +/* to link timer with callback data */ struct otg_timer {
>  +struct timer_list timer;
>  +/* callback data */
>  +int *timeout_bit;
>  +struct otg_data *otgd;
>  +};
>  +
>  +struct otg_data {
>  +struct device *dev; /* HCD & GCD's parent device */
>  +
>  +struct otg_fsm fsm;
>  +/* HCD, GCD and usb_otg_state are present in otg_fsm->otg
>  + * HCD is bus_to_hcd(fsm->otg->host)
>  + * GCD is fsm->otg->gadget
>  + */
>  +struct otg_fsm_ops fsm_ops; /* private copy for override */
>  +struct usb_otg otg;
>  +struct usb_hcd *shared_hcd; /* if shared HCD registered */
>  +
>  +/* saved hooks to OTG device */
>  +int (*start_host)(struct otg_fsm *fsm, int on);
>  +int (*start_gadget)(struct otg_fsm *fsm, int on);
>  +
>  +struct list_head list;
>  +
>  +struct work_struct work;/* OTG FSM work */
>  +struct workqueue_struct *wq;
>  +
>  +struct otg_timer timers[NUM_OTG_FSM_TIMERS];
>  +
>  +bool fsm_running;
>  +bool gadget_can_start;  /* OTG FSM says gadget can 
>  start */
>  +bool host_can_start;/* OTG FSM says host can start 
>  */
>  +
>  +/* use otg->fsm.lock for serializing access */ };
> >>>
> >>> What's the relationship between struct usb_otg otg and this one?
> >>
> >> Did you mean why struct usb_otg otg is there in struct otg_data?
> >> Just for easy allocation. fsm_ops only contains the pointer to struct 
> >> usb_otg.
> >>
> >
> > The reason why I ask this question is the most structures at usb_otg
> > (only enum usb_otg_state)are useless for otg_fsm, this structure may
> > only for hardware otg fsm driver, so your OTG framework should only
> > for software FSM drivers, right?
> 
> right. we only 

Re: [PATCH] usb: Add driver for Altus Metrum ChaosKey device

2015-03-20 Thread Oliver Neukum
On Thu, 2015-03-19 at 20:25 -0700, Keith Packard wrote:
> > That is a violation of the DMA rules on non-coherent architectures.
> > The buffer must be allocated separately.
> 
> Ok, I'm not sure I understand the reasoning given that both come from
> kmalloc, but that's easy to do.


That happens on non-coherent architectures.
Suppose you do DMA into a buffer. The data will go into RAM and only
into RAM (by definition). So if you evaluate the buffer you must read
from RAM, not the cache. To assure that we write out and invalidate
the cache line. If, however, you read or write into the same cache line
the CPU will cache the buffer again. And if the line is laundered after
the DMA, the old content is written back.

kmalloc() on those architectures guarantees that separate allocations
don't share a cache line.

Regards
Oliver


--
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 2/9] usb: gadget: add usb_gadget_start/stop()

2015-03-20 Thread Roger Quadros
On 20/03/15 09:18, Peter Chen wrote:
> On Thu, Mar 19, 2015 at 04:50:31PM +0200, Roger Quadros wrote:
>> On 19/03/15 16:09, Li Jun wrote:
>>> On Thu, Mar 19, 2015 at 12:14:39PM +0200, Roger Quadros wrote:
 On 19/03/15 05:30, Peter Chen wrote:
> On Wed, Mar 18, 2015 at 03:55:56PM +0200, Roger Quadros wrote:
>> The OTG state machine needs a mechanism to start and
>> stop the gadget controller. Add usb_gadget_start()
>> and usb_gadget_stop().
>>
>> Signed-off-by: Roger Quadros 
>> ---
>>  drivers/usb/gadget/udc/udc-core.c | 166 
>> +++---
>>  include/linux/usb/gadget.h|   3 +
>>  2 files changed, 158 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/usb/gadget/udc/udc-core.c 
>> b/drivers/usb/gadget/udc/udc-core.c
>> index 5a81cb0..69b4123 100644
>> --- a/drivers/usb/gadget/udc/udc-core.c
>> +++ b/drivers/usb/gadget/udc/udc-core.c
>> @@ -35,6 +35,8 @@
>>   * @dev - the child device to the actual controller
>>   * @gadget - the gadget. For use by the class code
>>   * @list - for use by the udc class driver
>> + * @running - udc is running
>
> Doesn't OTG FSM should know it?

 Not really, as the gadget driver might not have been loaded yet or 
 userspace might
 have disabled softconnect when the OTG FSM wants UDC to start.

 So only UDC knows if it has really started or not based on this flag.

>>>
>>> why this can not be known by check the otg fsm state? i.e. if the device in
>>> b_peripheral or a_peripheral state, udc should had started, isn't it?
>>
>> If gadget function driver (which is different from UDC driver) is not yet 
>> loaded
>> then we can't start UDC even if otg fsm is in b_peripheral.
>> Also, if userspace has disabled softconnect we can't start UDC.
>>
>> So, b_peripheral != UDC_started.
>>
>> I've tried to address this issue by adding the checks in usb_gadget_start().
>>
> 
> Ok, maybe we have different understanding for 'B-Device' at software,
> In spec, it says the Micro-AB receptacle with nothing connected can be
> 'B-Device', but in fact, we may not enable device mode before loading
> gadget driver, in chipidea fsm design, if the gadget driver is not
> loaded, the FSM will not start, and it is at OTG_STATE_UNDEFINED.

Right. I mixed up into thinking that we should respect the softconnect
while in OTG mode. It seems that we should ignore it.

> 
> One more thing is we may need to find a place to issue SRP when we
> load gadget driver, since we may at b_idle  at that time due to host
> closes the vbus (timeout for a_wait_bcon).

Issuing SRP should be done by the otg-fsm and not udc-core.
The udc-core can at the least call usb_otg_kick_fsm() after setting the gadget
driver so that otg-fsm knows that we now have a valid gadget and can take
necessary action. i.e. change from b_idle to b_srp_init and then to 
b_peripheral.

> 
> What is the "softconnect" used for? In otg fsm, we use b_bus_req for FSM.
> 
I understand now that we shouldn't bother with softconnect when we are in OTG 
fsm mode.
That solves our problem with the running flags.

So now, b_peripheral == UDC_started.

I will address this in v2.

cheers,
-roger
--
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 1/9] usb: hcd: Introduce usb_start/stop_hcd()

2015-03-20 Thread Roger Quadros
On 20/03/15 08:32, Peter Chen wrote:
> On Thu, Mar 19, 2015 at 01:38:32PM +0200, Roger Quadros wrote:
>> On 18/03/15 21:49, Alan Stern wrote:
>>> On Wed, 18 Mar 2015, Roger Quadros wrote:
>>>
 To support OTG we want a mechanism to start and stop
 the HCD from the OTG state machine. Add usb_start_hcd()
 and usb_stop_hcd().

 Signed-off-by: Roger Quadros 
>>>
>>> There are a few problems in this proposed patch.
>>>
 +int usb_start_hcd(struct usb_hcd *hcd)
 +{
 +  int retval;
 +  struct usb_device *rhdev = hcd->self.root_hub;
 +
 +  if (hcd->state != HC_STATE_HALT) {
 +  dev_err(hcd->self.controller, "not starting a running HCD\n");
 +  return -EINVAL;
 +  }
 +
 +  hcd->state = HC_STATE_RUNNING;
 +  retval = hcd->driver->start(hcd);
 +  if (retval < 0) {
 +  dev_err(hcd->self.controller, "startup error %d\n", retval);
 +  hcd->state = HC_STATE_HALT;
 +  return retval;
 +  }
 +
 +  /* starting here, usbcore will pay attention to this root hub */
 +  if ((retval = register_root_hub(hcd)) != 0)
 +  goto err_register_root_hub;
>>>
>>> If the host controller is started more than once, you will end up
>>> unregistering and re-registering the root hub.  The device core does
>>> not allow this.  Once a device has been unregistered, you must not try
>>> to register it again -- you have to allocate a new device and register
>>> it instead.
>>
>> Understood.
>>
>>>
>>> Also, although you call the driver's ->start method multiple times, the
>>> ->reset method is called only once, when the controller is first 
>>> probed.  It's not clear that this will work in a situation where the HC 
>>> and the UDC share hardware state; after the UDC is stopped it may be 
>>> necessary to reset the HC before it can run again.
>>
>> Yes, good point.
>>>
>>> It might be possible to make this work, but I suspect quite a few 
>>> drivers would need rewriting first.  As another example of the problems 
>>> you face, consider how stopping a host controller will interact with 
>>> the driver's PM support (both system suspend and runtime suspend).
>>
>> Right. This needs more work than I thought.
>>>
>>> It would be a lot simpler to unbind the host controller driver
>>> completely when switching to device mode and rebind it when switching
>>> back.  I guess that is the sort of heavy-duty approach you want to
>>> avoid, but it may be the only practical way forward.
>>
>> So you mean directly calling usb_add/remove_hcd() from the OTG core?
>> I don't see any issues with that other than it being a heavy-duty operation
>> like you said and hope that it doesn't violate the OTG spec timing.
>>
>> Looking at Figure 5-3: "HNP Sequence of Events (FS)" of the OTG 2.0 spec
>> we have about 150ms (X10) to switch from B-Device detected A connect 
>> (b_wait_acon state)
>> to driving bus reset (b_host state). I don't think this should be an issue 
>> in modern SoCs
>> but I'm not very sure.
>>
> 
> It is not related toadd/remove hcd, it is the time from receiving PCD
> to issue BUS_RESET, the Linux stack can't satisfy OTG spec (150ms) due
> to there are some de-bounce waitings.

OK.

> 
>> In any case I can migrate to the add/remove hcd approach to simplify things.
>>
> 
> It should be no problem, we use it more than 1 years.
> 

Good to know this.

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


[PATCH] cdc-acm: surpress misleading message

2015-03-20 Thread Oliver Neukum
During the entry intro suspend a misleading message can be
printed. Surpress it by checking the specific error.

Signed-off-by: Oliver Neukum 0
---
 drivers/usb/class/cdc-acm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 58241ec..43cb058 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -360,7 +360,7 @@ static void acm_ctrl_irq(struct urb *urb)
}
 exit:
retval = usb_submit_urb(urb, GFP_ATOMIC);
-   if (retval)
+   if (retval && retval != -EPERM)
dev_err(&acm->control->dev, "%s - usb_submit_urb failed: %d\n",
__func__, retval);
 }
-- 
2.1.4

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


[PATCH] cdc-acm: convert to not directly using urb->status

2015-03-20 Thread Oliver Neukum
A step on the road to passing status as a parameter

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

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 43cb058..3e15add 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -428,7 +428,7 @@ static void acm_read_bulk_callback(struct urb *urb)
return;
}
 
-   if (urb->status) {
+   if (status) {
set_bit(rb->index, &acm->read_urbs_free);
dev_dbg(&acm->data->dev, "%s - non-zero urb status: %d\n",
__func__, status);
@@ -462,13 +462,14 @@ static void acm_write_bulk(struct urb *urb)
struct acm_wb *wb = urb->context;
struct acm *acm = wb->instance;
unsigned long flags;
+   int status = urb->status;
 
-   if (urb->status || (urb->actual_length != urb->transfer_buffer_length))
+   if (status || (urb->actual_length != urb->transfer_buffer_length))
dev_vdbg(&acm->data->dev, "%s - len %d/%d, status %d\n",
__func__,
urb->actual_length,
urb->transfer_buffer_length,
-   urb->status);
+   status);
 
spin_lock_irqsave(&acm->write_lock, flags);
acm_write_done(acm, wb);
-- 
2.1.4

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


Re: [RFC][PATCH 2/9] usb: gadget: add usb_gadget_start/stop()

2015-03-20 Thread Roger Quadros
On 20/03/15 11:46, Roger Quadros wrote:
> On 20/03/15 09:18, Peter Chen wrote:
>> On Thu, Mar 19, 2015 at 04:50:31PM +0200, Roger Quadros wrote:
>>> On 19/03/15 16:09, Li Jun wrote:
 On Thu, Mar 19, 2015 at 12:14:39PM +0200, Roger Quadros wrote:
> On 19/03/15 05:30, Peter Chen wrote:
>> On Wed, Mar 18, 2015 at 03:55:56PM +0200, Roger Quadros wrote:
>>> The OTG state machine needs a mechanism to start and
>>> stop the gadget controller. Add usb_gadget_start()
>>> and usb_gadget_stop().
>>>
>>> Signed-off-by: Roger Quadros 
>>> ---
>>>  drivers/usb/gadget/udc/udc-core.c | 166 
>>> +++---
>>>  include/linux/usb/gadget.h|   3 +
>>>  2 files changed, 158 insertions(+), 11 deletions(-)
>>>
>>> diff --git a/drivers/usb/gadget/udc/udc-core.c 
>>> b/drivers/usb/gadget/udc/udc-core.c
>>> index 5a81cb0..69b4123 100644
>>> --- a/drivers/usb/gadget/udc/udc-core.c
>>> +++ b/drivers/usb/gadget/udc/udc-core.c
>>> @@ -35,6 +35,8 @@
>>>   * @dev - the child device to the actual controller
>>>   * @gadget - the gadget. For use by the class code
>>>   * @list - for use by the udc class driver
>>> + * @running - udc is running
>>
>> Doesn't OTG FSM should know it?
>
> Not really, as the gadget driver might not have been loaded yet or 
> userspace might
> have disabled softconnect when the OTG FSM wants UDC to start.
>
> So only UDC knows if it has really started or not based on this flag.
>

 why this can not be known by check the otg fsm state? i.e. if the device in
 b_peripheral or a_peripheral state, udc should had started, isn't it?
>>>
>>> If gadget function driver (which is different from UDC driver) is not yet 
>>> loaded
>>> then we can't start UDC even if otg fsm is in b_peripheral.
>>> Also, if userspace has disabled softconnect we can't start UDC.
>>>
>>> So, b_peripheral != UDC_started.
>>>
>>> I've tried to address this issue by adding the checks in usb_gadget_start().
>>>
>>
>> Ok, maybe we have different understanding for 'B-Device' at software,
>> In spec, it says the Micro-AB receptacle with nothing connected can be
>> 'B-Device', but in fact, we may not enable device mode before loading
>> gadget driver, in chipidea fsm design, if the gadget driver is not
>> loaded, the FSM will not start, and it is at OTG_STATE_UNDEFINED.
> 
> Right. I mixed up into thinking that we should respect the softconnect
> while in OTG mode. It seems that we should ignore it.
> 
>>
>> One more thing is we may need to find a place to issue SRP when we
>> load gadget driver, since we may at b_idle  at that time due to host
>> closes the vbus (timeout for a_wait_bcon).
> 
> Issuing SRP should be done by the otg-fsm and not udc-core.
> The udc-core can at the least call usb_otg_kick_fsm() after setting the gadget
> driver so that otg-fsm knows that we now have a valid gadget and can take
> necessary action. i.e. change from b_idle to b_srp_init and then to 
> b_peripheral.

To clarify further. Is it right to assume that OTG FSM will not be started till
both gadget UDC driver _AND_ gadget function driver are loaded?

And it will be stopped when either of them unloads.

This simplifies things a lot.

cheers,
-roger

> 
>>
>> What is the "softconnect" used for? In otg fsm, we use b_bus_req for FSM.
>>
> I understand now that we shouldn't bother with softconnect when we are in OTG 
> fsm mode.
> That solves our problem with the running flags.
> 
> So now, b_peripheral == UDC_started.
> 
> I will address this in v2.
> 
> cheers,
> -roger
> --
> 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
> 

--
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: isp1760: fix spin unlock in the error path of isp1760_udc_start

2015-03-20 Thread Sudeep Holla
Commit a124820de5fd ("usb: isp1760: fix possible deadlock in
isp1760_udc_irq") replaced spin_{un,}lock with spin_{un,}lock_irq{save,restore}.
However it missed an error path resulting in the smatch warning as below:

drivers/usb/isp1760/isp1760-udc.c:1230 isp1760_udc_start() warn: inconsistent 
returns 'irqsave:flags'.
Locked on:   line 1207
Unlocked on: line 1199

This patch fixes the spin unlock in the error path in isp1760_udc_start
thereby removing the smatch warning mentioned above.

Reported-by: Dan Carpenter 
Cc: Laurent Pinchart 
Cc: Felipe Balbi 
Signed-off-by: Sudeep Holla 
---
 drivers/usb/isp1760/isp1760-udc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Hi Laurent, Felipe,

I am extremely sorry for missing this in my original patch.
Thanks to Dan Carpenter for reporting this.

Regards,
Sudeep

diff --git a/drivers/usb/isp1760/isp1760-udc.c 
b/drivers/usb/isp1760/isp1760-udc.c
index fbfbd59aae64..b7094eee0bdd 100644
--- a/drivers/usb/isp1760/isp1760-udc.c
+++ b/drivers/usb/isp1760/isp1760-udc.c
@@ -1203,7 +1203,7 @@ static int isp1760_udc_start(struct usb_gadget *gadget,
 
if (udc->driver) {
dev_err(udc->isp->dev, "UDC already has a gadget driver\n");
-   spin_unlock(&udc->lock);
+   spin_unlock_irqrestore(&udc->lock, flags);
return -EBUSY;
}
 
-- 
1.9.1

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


[PATCHv3 01/12] usb: add bus type for USB ULPI

2015-03-20 Thread Heikki Krogerus
UTMI+ Low Pin Interface (ULPI) is a commonly used PHY
interface for USB 2.0. The ULPI specification describes a
standard set of registers which the vendors can extend for
their specific needs. ULPI PHYs provide often functions
such as charger detection and ADP sensing and probing.

There are two major issues that the bus type is meant to
tackle:

Firstly, ULPI registers are accessed from the controller.
The bus provides convenient method for the controller
drivers to share that access with the actual PHY drivers.

Secondly, there are already platforms that assume ULPI PHYs
are runtime detected, such as many Intel Baytrail based
platforms. They do not provide any kind of hardware
description for the ULPI PHYs like separate ACPI device
object that could be used to enumerate a device from.

Signed-off-by: Heikki Krogerus 
---
 MAINTAINERS   |   7 ++
 drivers/usb/common/Makefile   |   1 +
 drivers/usb/common/ulpi.c | 246 ++
 drivers/usb/core/Kconfig  |   8 ++
 include/linux/mod_devicetable.h   |   6 +
 include/linux/ulpi/driver.h   |  62 ++
 include/linux/ulpi/interface.h|  23 
 include/linux/ulpi/regs.h | 130 
 include/linux/usb/ulpi.h  | 134 +
 scripts/mod/devicetable-offsets.c |   4 +
 scripts/mod/file2alias.c  |  13 ++
 11 files changed, 502 insertions(+), 132 deletions(-)
 create mode 100644 drivers/usb/common/ulpi.c
 create mode 100644 include/linux/ulpi/driver.h
 create mode 100644 include/linux/ulpi/interface.h
 create mode 100644 include/linux/ulpi/regs.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 83e8fd0..53fdd33 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -10427,6 +10427,13 @@ S: Maintained
 F: Documentation/video4linux/zr364xx.txt
 F: drivers/media/usb/zr364xx/
 
+ULPI BUS
+M: Heikki Krogerus 
+L: linux-usb@vger.kernel.org
+S: Maintained
+F: drivers/usb/common/ulpi.c
+F: include/linux/ulpi/
+
 USER-MODE LINUX (UML)
 M: Jeff Dike 
 M: Richard Weinberger 
diff --git a/drivers/usb/common/Makefile b/drivers/usb/common/Makefile
index ca2f8bd..6bbb3ec 100644
--- a/drivers/usb/common/Makefile
+++ b/drivers/usb/common/Makefile
@@ -7,3 +7,4 @@ usb-common-y  += common.o
 usb-common-$(CONFIG_USB_LED_TRIG) += led.o
 
 obj-$(CONFIG_USB_OTG_FSM) += usb-otg-fsm.o
+obj-$(CONFIG_USB_ULPI_BUS) += ulpi.o
diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c
new file mode 100644
index 000..1ab939c
--- /dev/null
+++ b/drivers/usb/common/ulpi.c
@@ -0,0 +1,246 @@
+/**
+ * ulpi.c - USB ULPI PHY bus
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * Author: Heikki Krogerus 
+ *
+ * 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 
+#include 
+
+/* -- 
*/
+
+int ulpi_read(struct ulpi *ulpi, u8 addr)
+{
+   return ulpi->ops->read(ulpi->ops, addr);
+}
+EXPORT_SYMBOL_GPL(ulpi_read);
+
+int ulpi_write(struct ulpi *ulpi, u8 addr, u8 val)
+{
+   return ulpi->ops->write(ulpi->ops, addr, val);
+}
+EXPORT_SYMBOL_GPL(ulpi_write);
+
+/* -- 
*/
+
+static int ulpi_match(struct device *dev, struct device_driver *driver)
+{
+   struct ulpi_driver *drv = to_ulpi_driver(driver);
+   struct ulpi *ulpi = to_ulpi_dev(dev);
+   const struct ulpi_device_id *id;
+
+   for (id = drv->id_table; id->vendor; id++)
+   if (id->vendor == ulpi->id.vendor &&
+   id->product == ulpi->id.product)
+   return 1;
+
+   return 0;
+}
+
+static int ulpi_uevent(struct device *dev, struct kobj_uevent_env *env)
+{
+   struct ulpi *ulpi = to_ulpi_dev(dev);
+
+   if (add_uevent_var(env, "MODALIAS=ulpi:v%04xp%04x",
+  ulpi->id.vendor, ulpi->id.product))
+   return -ENOMEM;
+   return 0;
+}
+
+static int ulpi_probe(struct device *dev)
+{
+   struct ulpi_driver *drv = to_ulpi_driver(dev->driver);
+
+   return drv->probe(to_ulpi_dev(dev));
+}
+
+static int ulpi_remove(struct device *dev)
+{
+   struct ulpi_driver *drv = to_ulpi_driver(dev->driver);
+
+   if (drv->remove)
+   drv->remove(to_ulpi_dev(dev));
+
+   return 0;
+}
+
+struct bus_type ulpi_bus = {
+   .name = "ulpi",
+   .match = ulpi_match,
+   .uevent = ulpi_uevent,
+   .probe = ulpi_probe,
+   .remove = ulpi_remove,
+};
+EXPORT_SYMBOL_GPL(ulpi_bus);
+
+/* -- 
*/
+
+static ssize_t modalias_show(struct device *dev, struct device_attribute *attr,
+char *buf)
+{
+ 

[PATCHv3 09/12] usb: dwc3: pci: add quirk for Baytrails

2015-03-20 Thread Heikki Krogerus
On some BYT platforms the USB2 PHY needs to be put into
operational mode by the controller driver with GPIOs
controlling the PHYs reset and cs signals.

Signed-off-by: Heikki Krogerus 
---
 drivers/usb/dwc3/dwc3-pci.c | 35 +++
 1 file changed, 35 insertions(+)

diff --git a/drivers/usb/dwc3/dwc3-pci.c b/drivers/usb/dwc3/dwc3-pci.c
index b773fb5..c3de883 100644
--- a/drivers/usb/dwc3/dwc3-pci.c
+++ b/drivers/usb/dwc3/dwc3-pci.c
@@ -21,6 +21,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 #include "platform_data.h"
 
@@ -31,6 +33,15 @@
 #define PCI_DEVICE_ID_INTEL_SPTLP  0x9d30
 #define PCI_DEVICE_ID_INTEL_SPTH   0xa130
 
+static const struct acpi_gpio_params reset_gpios = { 0, 0, false };
+static const struct acpi_gpio_params cs_gpios = { 1, 0, false };
+
+static const struct acpi_gpio_mapping acpi_dwc3_byt_gpios[] = {
+   { "reset-gpios", &reset_gpios, 1 },
+   { "cs-gpios", &cs_gpios, 1 },
+   { },
+};
+
 static int dwc3_pci_quirks(struct pci_dev *pdev)
 {
if (pdev->vendor == PCI_VENDOR_ID_AMD &&
@@ -65,6 +76,30 @@ static int dwc3_pci_quirks(struct pci_dev *pdev)
sizeof(pdata));
}
 
+   if (pdev->vendor == PCI_VENDOR_ID_INTEL &&
+   pdev->device == PCI_DEVICE_ID_INTEL_BYT) {
+   struct gpio_desc *gpio;
+
+   acpi_dev_add_driver_gpios(ACPI_COMPANION(&pdev->dev),
+ acpi_dwc3_byt_gpios);
+
+   /* These GPIOs will turn on the USB2 PHY */
+   gpio = gpiod_get(&pdev->dev, "cs");
+   if (!IS_ERR(gpio)) {
+   gpiod_direction_output(gpio, 0);
+   gpiod_set_value_cansleep(gpio, 1);
+   gpiod_put(gpio);
+   }
+
+   gpio = gpiod_get(&pdev->dev, "reset");
+   if (!IS_ERR(gpio)) {
+   gpiod_direction_output(gpio, 0);
+   gpiod_set_value_cansleep(gpio, 1);
+   gpiod_put(gpio);
+   msleep(10);
+   }
+   }
+
return 0;
 }
 
-- 
2.1.4

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


[PATCHv3 10/12] usb: dwc3: add ULPI interface support

2015-03-20 Thread Heikki Krogerus
Registers DWC3's ULPI interface with the ULPI bus when it's
available.

Signed-off-by: Heikki Krogerus 
---
 drivers/usb/dwc3/Kconfig  |  7 
 drivers/usb/dwc3/Makefile |  4 +++
 drivers/usb/dwc3/core.c   | 14 
 drivers/usb/dwc3/core.h   | 14 
 drivers/usb/dwc3/ulpi.c   | 91 +++
 5 files changed, 130 insertions(+)
 create mode 100644 drivers/usb/dwc3/ulpi.c

diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig
index 827c4f8..6f92b36 100644
--- a/drivers/usb/dwc3/Kconfig
+++ b/drivers/usb/dwc3/Kconfig
@@ -11,6 +11,13 @@ config USB_DWC3
 
 if USB_DWC3
 
+config USB_DWC3_ULPI
+   bool "Register ULPI PHY Interface"
+   depends on USB_ULPI_BUS
+   help
+ Select this if you have ULPI type PHY attached to your DWC3
+ controller.
+
 choice
bool "DWC3 Mode Selection"
default USB_DWC3_DUAL_ROLE if (USB && USB_GADGET)
diff --git a/drivers/usb/dwc3/Makefile b/drivers/usb/dwc3/Makefile
index 46172f4..c7076e3 100644
--- a/drivers/usb/dwc3/Makefile
+++ b/drivers/usb/dwc3/Makefile
@@ -15,6 +15,10 @@ ifneq ($(filter y,$(CONFIG_USB_DWC3_GADGET) 
$(CONFIG_USB_DWC3_DUAL_ROLE)),)
dwc3-y  += gadget.o ep0.o
 endif
 
+ifneq ($(CONFIG_USB_DWC3_ULPI),)
+   dwc3-y  += ulpi.o
+endif
+
 ifneq ($(CONFIG_DEBUG_FS),)
dwc3-y  += debugfs.o
 endif
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index b229ba1..4dce614 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -444,13 +444,25 @@ static int dwc3_phy_setup(struct dwc3 *dwc)
case DWC3_GHWPARAMS3_HSPHY_IFC_UTMI_ULPI:
if (!strncmp(dwc->hsphy_interface, "utmi", 4)) {
reg &= ~DWC3_GUSB2PHYCFG_ULPI_UTMI;
+   break;
} else if (!strncmp(dwc->hsphy_interface, "ulpi", 4)) {
reg |= DWC3_GUSB2PHYCFG_ULPI_UTMI;
+   dwc3_writel(dwc->regs, DWC3_GUSB2PHYCFG(0), reg);
} else {
dev_err(dwc->dev, "HSPHY Interface not defined\n");
return -EINVAL;
}
/* FALLTHROUGH */
+   case DWC3_GHWPARAMS3_HSPHY_IFC_ULPI:
+   /* Soft reset here to sync the clocks */
+   ret = dwc3_soft_reset(dwc);
+   if (ret)
+   return ret;
+
+   ret = dwc3_ulpi_init(dwc);
+   if (ret)
+   return ret;
+   /* FALLTHROUGH */
default:
break;
}
@@ -999,6 +1011,7 @@ err2:
 
 err1:
dwc3_free_event_buffers(dwc);
+   dwc3_ulpi_exit(dwc);
 
 err0:
/*
@@ -1034,6 +1047,7 @@ static int dwc3_remove(struct platform_device *pdev)
phy_power_off(dwc->usb3_generic_phy);
 
dwc3_core_exit(dwc);
+   dwc3_ulpi_exit(dwc);
 
pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 7b3ab64..d70da20 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -661,6 +662,7 @@ struct dwc3_scratchpad_array {
  * @usb3_phy: pointer to USB3 PHY
  * @usb2_generic_phy: pointer to USB2 PHY
  * @usb3_generic_phy: pointer to USB3 PHY
+ * @ulpi: pointer to ulpi interface
  * @dcfg: saved contents of DCFG register
  * @gctl: saved contents of GCTL register
  * @isoch_delay: wValue from Set Isochronous Delay request;
@@ -749,6 +751,8 @@ struct dwc3 {
struct phy  *usb2_generic_phy;
struct phy  *usb3_generic_phy;
 
+   struct ulpi *ulpi;
+
void __iomem*regs;
size_t  regs_size;
 
@@ -1047,4 +1051,14 @@ static inline int dwc3_gadget_resume(struct dwc3 *dwc)
 }
 #endif /* !IS_ENABLED(CONFIG_USB_DWC3_HOST) */
 
+#if IS_ENABLED(CONFIG_USB_DWC3_ULPI)
+int dwc3_ulpi_init(struct dwc3 *dwc);
+void dwc3_ulpi_exit(struct dwc3 *dwc);
+#else
+static inline int dwc3_ulpi_init(struct dwc3 *dwc)
+{ return 0; }
+static inline void dwc3_ulpi_exit(struct dwc3 *dwc)
+{ }
+#endif
+
 #endif /* __DRIVERS_USB_DWC3_CORE_H */
diff --git a/drivers/usb/dwc3/ulpi.c b/drivers/usb/dwc3/ulpi.c
new file mode 100644
index 000..4dfcc81
--- /dev/null
+++ b/drivers/usb/dwc3/ulpi.c
@@ -0,0 +1,91 @@
+/**
+ * ulpi.c - DesignWare USB3 Controller's ULPI PHY interface
+ *
+ * Copyright (C) 2015 Intel Corporation
+ *
+ * Author: Heikki Krogerus 
+ *
+ * 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 "core.h"
+#include "io.h"
+
+#define DWC3_ULPI_ADDR(a) \
+   ((a >= ULPI_EXT_VENDOR_SPECIFIC) ? \
+   DWC3_GU

[PATCH 1/3] cdc-wdm: return correct error codes

2015-03-20 Thread Oliver Neukum
Lieing to user space is wrong. The real reason for a failure
to write should be returned to user space.

Signed-off-by: Oliver Neukum 0
---
 drivers/usb/class/cdc-wdm.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 00871cf..21850a9 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -339,7 +339,7 @@ static ssize_t wdm_write
desc->werr = 0;
spin_unlock_irq(&desc->iuspin);
if (we < 0)
-   return -EIO;
+   return usb_translate_errors(we);
 
buf = kmalloc(count, GFP_KERNEL);
if (!buf) {
-- 
2.1.4

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


[PATCH 2/3] cdc-wdm: unify error handling in write

2015-03-20 Thread Oliver Neukum
This makes sure the error handling path is the same for
all error conditions, thus reducing code duplication.

Signed-off-by: Oliver Neukum 0
---
 drivers/usb/class/cdc-wdm.c | 31 ---
 1 file changed, 16 insertions(+), 15 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index 21850a9..b574f6d 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -349,30 +349,25 @@ static ssize_t wdm_write
 
r = copy_from_user(buf, buffer, count);
if (r > 0) {
-   kfree(buf);
rv = -EFAULT;
-   goto outnl;
+   goto out_free_mem;
}
 
/* concurrent writes and disconnect */
r = mutex_lock_interruptible(&desc->wlock);
rv = -ERESTARTSYS;
-   if (r) {
-   kfree(buf);
-   goto outnl;
-   }
+   if (r)
+   goto out_free_mem;
 
if (test_bit(WDM_DISCONNECTING, &desc->flags)) {
-   kfree(buf);
rv = -ENODEV;
-   goto outnp;
+   goto out_free_mem_lock;
}
 
r = usb_autopm_get_interface(desc->intf);
if (r < 0) {
-   kfree(buf);
rv = usb_translate_errors(r);
-   goto outnp;
+   goto out_free_mem_lock;
}
 
if (!(file->f_flags & O_NONBLOCK))
@@ -386,9 +381,8 @@ static ssize_t wdm_write
r = -EIO;
 
if (r < 0) {
-   kfree(buf);
rv = r;
-   goto out;
+   goto out_free_mem_pm;
}
 
req = desc->orq;
@@ -415,21 +409,28 @@ static ssize_t wdm_write
 
rv = usb_submit_urb(desc->command, GFP_KERNEL);
if (rv < 0) {
-   kfree(buf);
desc->outbuf = NULL;
clear_bit(WDM_IN_USE, &desc->flags);
dev_err(&desc->intf->dev, "Tx URB error: %d\n", rv);
rv = usb_translate_errors(rv);
+   goto out_free_mem_pm;
} else {
dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
req->wIndex);
}
-out:
+
usb_autopm_put_interface(desc->intf);
-outnp:
mutex_unlock(&desc->wlock);
 outnl:
return rv < 0 ? rv : count;
+
+out_free_mem_pm:
+   usb_autopm_put_interface(desc->intf);
+out_free_mem_lock:
+   mutex_unlock(&desc->wlock);
+out_free_mem:
+   kfree(buf);
+   return rv;
 }
 
 /*
-- 
2.1.4

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


[PATCH 3/3] cdc-wdm: fix endianness bug in debug statements

2015-03-20 Thread Oliver Neukum
Values directly from descriptors given in debug statements
must be converted to native endianness.

Signed-off-by: Oliver Neukum 
CC: sta...@vger.kernel.org
---
 drivers/usb/class/cdc-wdm.c | 12 +++-
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index b574f6d..dc13072 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -245,7 +245,7 @@ static void wdm_int_callback(struct urb *urb)
case USB_CDC_NOTIFY_RESPONSE_AVAILABLE:
dev_dbg(&desc->intf->dev,
"NOTIFY_RESPONSE_AVAILABLE received: index %d len %d",
-   dr->wIndex, dr->wLength);
+   le16_to_cpu(dr->wIndex), le16_to_cpu(dr->wLength));
break;
 
case USB_CDC_NOTIFY_NETWORK_CONNECTION:
@@ -262,7 +262,9 @@ static void wdm_int_callback(struct urb *urb)
clear_bit(WDM_POLL_RUNNING, &desc->flags);
dev_err(&desc->intf->dev,
"unknown notification %d received: index %d len %d\n",
-   dr->bNotificationType, dr->wIndex, dr->wLength);
+   dr->bNotificationType,
+   le16_to_cpu(dr->wIndex),
+   le16_to_cpu(dr->wLength));
goto exit;
}
 
@@ -402,7 +404,7 @@ static ssize_t wdm_write
 USB_RECIP_INTERFACE);
req->bRequest = USB_CDC_SEND_ENCAPSULATED_COMMAND;
req->wValue = 0;
-   req->wIndex = desc->inum;
+   req->wIndex = desc->inum; /* already converted */
req->wLength = cpu_to_le16(count);
set_bit(WDM_IN_USE, &desc->flags);
desc->outbuf = buf;
@@ -416,7 +418,7 @@ static ssize_t wdm_write
goto out_free_mem_pm;
} else {
dev_dbg(&desc->intf->dev, "Tx URB has been submitted index=%d",
-   req->wIndex);
+   le16_to_cpu(req->wIndex));
}
 
usb_autopm_put_interface(desc->intf);
@@ -822,7 +824,7 @@ static int wdm_create(struct usb_interface *intf, struct 
usb_endpoint_descriptor
desc->irq->bRequestType = (USB_DIR_IN | USB_TYPE_CLASS | 
USB_RECIP_INTERFACE);
desc->irq->bRequest = USB_CDC_GET_ENCAPSULATED_RESPONSE;
desc->irq->wValue = 0;
-   desc->irq->wIndex = desc->inum;
+   desc->irq->wIndex = desc->inum; /* already converted */
desc->irq->wLength = cpu_to_le16(desc->wMaxCommand);
 
usb_fill_control_urb(
-- 
2.1.4

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


RE: [PATCH v1 18/20] usb: dwc2: host: don't use dma_alloc_coherent with irqs disabled

2015-03-20 Thread Kaukab, Yousaf


> -Original Message-
> From: jwer...@google.com [mailto:jwer...@google.com] On Behalf Of Julius
> Werner
> Sent: Wednesday, March 18, 2015 11:43 PM
> To: Kaukab, Yousaf
> Cc: linux-usb@vger.kernel.org; Felipe Balbi; john.y...@synopsys.com; Herrero,
> Gregory; r.bald...@samsung.com; Dinh Nguyen; zhangfei@linaro.org
> Subject: Re: [PATCH v1 18/20] usb: dwc2: host: don't use dma_alloc_coherent
> with irqs disabled
> 
> [once more, without Gmail being stupid]
> 
> Nice! This also solves problems with exhausting coherent DMA memory when
> you plug too many devices in.
> 
> On Tue, Mar 17, 2015 at 2:54 AM, Mian Yousaf Kaukab
>  wrote:
> > From: Gregory Herrero 
> >
> > Align buffer must be allocated using kmalloc since irqs are disabled.
> > Coherency is handled through dma_map_single which can be used with
> > irqs disabled.
> >
> > Signed-off-by: Gregory Herrero 
> > ---
> >  drivers/usb/dwc2/hcd.c   |  7 ---
> >  drivers/usb/dwc2/hcd_intr.c  | 10 ++
> > drivers/usb/dwc2/hcd_queue.c |  7 ---
> >  3 files changed, 18 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c index
> > fd2ad25..54f58c1 100644
> > --- a/drivers/usb/dwc2/hcd.c
> > +++ b/drivers/usb/dwc2/hcd.c
> > @@ -710,9 +710,7 @@ static int dwc2_hc_setup_align_buf(struct
> dwc2_hsotg *hsotg, struct dwc2_qh *qh,
> > /* 3072 = 3 max-size Isoc packets */
> > buf_size = 3072;
> >
> > -   qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size,
> > - &qh->dw_align_buf_dma,
> > - GFP_ATOMIC);
> > +   qh->dw_align_buf = kzalloc(buf_size, GFP_ATOMIC);
> 
> Shouldn't this also set GFP_DMA? [...]

No, it should be GFP_ATOMIC, as this can be reached from interrupt handler.

> [...] (And does it need to be kzalloc()? I think
> kmalloc() should be enough and might avoid another memory
> transfer.)

kmalloc() is better.

> 
> > if (!qh->dw_align_buf)
> > return -ENOMEM;
> > qh->dw_align_buf_size = buf_size; @@ -737,6 +735,9 @@
> > static int dwc2_hc_setup_align_buf(struct dwc2_hsotg *hsotg, struct dwc2_qh
> *qh,
> > }
> > }
> >
> > +   qh->dw_align_buf_dma = dma_map_single(hsotg->dev,
> > +   qh->dw_align_buf, qh->dw_align_buf_size,
> > + DMA_TO_DEVICE);
> 
> Documentation/DMA-API.txt says that you must always use the same
> arguments for matching dma_map_single() and dma_unmap_single()... so I
> think this and all the unmaps should use DMA_BIDIRECTIONAL.

The mapping is wrong. It should consider endpoint direction. Something like 
chan->ep_is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE

> 
> > +
> > chan->align_buf = qh->dw_align_buf_dma;
> > return 0;
> >  }
> > diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c
> > index 6927bba..22f1476 100644
> > --- a/drivers/usb/dwc2/hcd_intr.c
> > +++ b/drivers/usb/dwc2/hcd_intr.c
> > @@ -468,6 +468,8 @@ static int dwc2_update_urb_state(struct dwc2_hsotg
> *hsotg,
> > /* Non DWORD-aligned buffer case handling */
> > if (chan->align_buf && xfer_length && chan->ep_is_in) {
> > dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
> > __func__);
> > +   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
> > +   chan->qh->dw_align_buf_size,
> > + DMA_FROM_DEVICE);
> > memcpy(urb->buf + urb->actual_length, 
> > chan->qh->dw_align_buf,
> >xfer_length);
> > }
> > @@ -559,6 +561,8 @@ static enum dwc2_halt_status
> dwc2_update_isoc_urb_state(
> > chan->ep_is_in) {
> > dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
> >  __func__);
> > +   dma_unmap_single(hsotg->dev, chan->qh-
> >dw_align_buf_dma,
> > +   chan->qh->dw_align_buf_size,
> > + DMA_FROM_DEVICE);
> > memcpy(urb->buf + frame_desc->offset +
> >qtd->isoc_split_offset, 
> > chan->qh->dw_align_buf,
> >frame_desc->actual_length); @@ -588,6
> > +592,8 @@ static enum dwc2_halt_status dwc2_update_isoc_urb_state(
> > chan->ep_is_in) {
> > dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
> >  __func__);
> > +   dma_unmap_single(hsotg->dev, chan->qh-
> >dw_align_buf_dma,
> > +   chan->qh->dw_align_buf_size,
> > + DMA_FROM_DEVICE);
> > memcpy(urb->buf + frame_desc->offset +
> >qtd->isoc_split_offset, 
> > chan->qh->dw_align_buf,
> >frame_desc->actual_length)

Re: [PATCH 2/3] cdc-wdm: unify error handling in write

2015-03-20 Thread Bjørn Mork
Oliver Neukum  writes:

> This makes sure the error handling path is the same for
> all error conditions, thus reducing code duplication.

Great!  This looks like I nice cleanup.  Will test it out.  Just a quick
comment based on the first glance:

>  outnl:
>   return rv < 0 ? rv : count;

How about changing the single remaining error without any rewinding into
a direct "return -ENOMEM", and then drop the "outnl" label and simplify
this to "return count"?


Bjørn
--
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 00/20] usb: third series of updates for dwc2 driver

2015-03-20 Thread Kaukab, Yousaf


> -Original Message-
> From: John Youn [mailto:john.y...@synopsys.com]
> Sent: Thursday, March 19, 2015 11:55 PM
> To: Kaukab, Yousaf; John Youn; linux-usb@vger.kernel.org; ba...@ti.com
> Cc: Herrero, Gregory; r.bald...@samsung.com;
> dingu...@opensource.altera.com; zhangfei@linaro.org
> Subject: Re: [PATCH v1 00/20] usb: third series of updates for dwc2 driver
> 
> On 3/19/2015 8:53 AM, Kaukab, Yousaf wrote:
> >
> >
> >> -Original Message-
> >> From: John Youn [mailto:john.y...@synopsys.com]
> >> Sent: Wednesday, March 18, 2015 8:14 PM
> >> To: Kaukab, Yousaf; John Youn; linux-usb@vger.kernel.org;
> >> ba...@ti.com
> >> Cc: Herrero, Gregory; r.bald...@samsung.com;
> >> dingu...@opensource.altera.com; zhangfei@linaro.org
> >> Subject: Re: [PATCH v1 00/20] usb: third series of updates for dwc2
> >> driver
> >>
> >> On 3/18/2015 8:45 AM, Kaukab, Yousaf wrote:
> >>>
> >>>
>  -Original Message-
>  From: John Youn [mailto:john.y...@synopsys.com]
>  Sent: Wednesday, March 18, 2015 3:33 AM
>  To: Kaukab, Yousaf; linux-usb@vger.kernel.org; ba...@ti.com;
>  john.y...@synopsys.com
>  Cc: Herrero, Gregory; r.bald...@samsung.com;
>  dingu...@opensource.altera.com; zhangfei@linaro.org
>  Subject: Re: [PATCH v1 00/20] usb: third series of updates for dwc2
>  driver
> 
>  On 3/17/2015 2:54 AM, Mian Yousaf Kaukab wrote:
> > Hi,
> > This patchset consists of some bug fixes and feature enhancements
> > for the dwc2 driver. All the patches are verified on dwc2 v3.0a
> > with dedicated fifos. Main focus of testing was with dma enabled.
> > Although basic testing without dma was also done.
> >
> > This is based on testing/next branch in Felipe's git.
> >
> > Thank you,
> >
> > Best regards,
> > Yousaf
> >
> 
>  Hi Yousaf,
> 
>  Patch 15 and 16 introduce regressions in two systems that I tested with.
> >>>
> >>> :( sorry for that. I will try to fix this asap.
> >>>
> 
>  After patch 15, the host fails to work at all.
> >>>
> >>> My understanding is that functionality can break within the patchset
> >>> but it
> >> should build at any point. If that's not correct, is merging patch 15
> >> and 16 OK for you?
> >>>
> >>
> >> Ok that's fine. Just thought I'd point out where the breakage started.
> >>
> >>
> 
>  After patch 16, the host works but the device fails enumeration
>  whenever switching from an A to B cable, going from host to
>  peripheral. After this fails, if you unplug and replug the B cable
>  it will enumerate. But whenever you switch from A to B it always fails.
> 
>  Tested on a Synopsys (2.94a) and Altera (2.93a) system.
> 
>  I don't have any logs right now but I can get those tomorrow if you
>  need
> >> them.
> >>>
> >>> It will be very helpful if you can provide log after
> >> CONFUG_USB_DWC2_DEBUG enabled and also function trace of dwc2
> driver.
> >>>
> >>
> >> Logs attached. First is device connection after driver load. Second
> >> is after role switch.
> >>
> >> Seems to fail both times with similar error.
> >>
> >> Relevant snippet:
> >>
> >> [   77.814073] dwc2 dwc2.1.auto: gintsts=44008020  gintmsk=d08c3cd4
> >> [   77.814079] dwc2 dwc2.1.auto: ++Session Request Interrupt++
> >> [   77.814091] dwc2 dwc2.1.auto: s3c_hsotg_irq: 04008020 
> >> (d08c3cd4) retry 8
> >> [   77.817097] dwc2 dwc2.1.auto: s3c_hsotg_irq: 04008420 0400
> >> (d08c3cd4) retry 8
> >> [   77.817102] dwc2 dwc2.1.auto: GINTSTS_ErlySusp
> >> [   77.820189] dwc2 dwc2.1.auto: gintsts=04008820  gintmsk=d08c3cd4
> >> [   77.820194] dwc2 dwc2.1.auto: USB SUSPEND
> >> [   77.820202] dwc2 dwc2.1.auto: DSTS=0x3
> >> [   77.820204] dwc2 dwc2.1.auto: DSTS.Suspend Status=1 HWCFG4.Power
> >> Optimize=0
> >> [   77.820213] dwc2 dwc2.1.auto: s3c_hsotg_irq: 04008020 
> >> (d08c3cd4) retry 8
> >> [   78.074297] dwc2 dwc2.1.auto: s3c_hsotg_irq: 04009020 1000
> >> (d08c3cd4) retry 8
> >> [   78.074305] dwc2 dwc2.1.auto: s3c_hsotg_irq: USBRst
> >> [   78.074310] dwc2 dwc2.1.auto: GNPTXSTS=00040400
> >> [   78.074314] dwc2 dwc2.1.auto: complete: ep 8800d50ce618 ep0, req
> >> 8800d524ae80, -104 => a042be00
> >> [   78.074317] dwc2 dwc2.1.auto: s3c_hsotg_complete_setup: failed -104
> >> [   78.074326] dwc2 dwc2.1.auto: FIFOs reset, timeout at 100
> >> [   78.074343] dwc2 dwc2.1.auto: EP0: DIEPCTL0=0x8000,
> >> DOEPCTL0=0x80008000
> >> [   78.074347] dwc2 dwc2.1.auto: gsintmsk now 0xd08c3cc4
> >> [   78.074351] dwc2 dwc2.1.auto: gsintmsk now 0xd08c3cd4
> >> [   78.074361] dwc2 dwc2.1.auto: DCTL=0x
> >> [   78.074362] dwc2 dwc2.1.auto: s3c_hsotg_enqueue_setup: queueing setup
> >> request
> >> [   78.074363] dwc2 dwc2.1.auto: ep0: req 8800d524ae80:
> >> 8@8801199df798, noi=0, zero=0, snok=0
> >> [   78.074364] dwc2 dwc2.1.auto: s3c_hsotg_ep_queue: don't submit request
> >> while suspended
> >> [   78.074365] 

Errata for Freescale root-hub TT?

2015-03-20 Thread Alan Stern
Peter:

Are there any known errata for the root-hub Transaction Translator in 
the Freescale host controllers?

When debugging some problems in an i.MX51 system, I found that the host
controller would never issue more than 4 full-speed isochronous packets
in any frame, no matter how many siTDs were linked into the EHCI
schedule.  Sometimes it would issue only 1 or 2 packets, even though
eight were in the schedule!  The behavior was very erratic.

The controller seemed to work okay when the full-speed devices were 
behind a high-speed hub.  The problems came up only when the host 
controller was connected to a full-speed hub.

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: [PATCH] usb: isp1760: fix spin unlock in the error path of isp1760_udc_start

2015-03-20 Thread Laurent Pinchart
Hi Sudeep,

Thank you for the patch.

On Friday 20 March 2015 11:42:17 Sudeep Holla wrote:
> Commit a124820de5fd ("usb: isp1760: fix possible deadlock in
> isp1760_udc_irq") replaced spin_{un,}lock with
> spin_{un,}lock_irq{save,restore}. However it missed an error path resulting
> in the smatch warning as below:
> 
> drivers/usb/isp1760/isp1760-udc.c:1230 isp1760_udc_start() warn:
> inconsistent returns 'irqsave:flags'. Locked on:   line 1207
> Unlocked on: line 1199
> 
> This patch fixes the spin unlock in the error path in isp1760_udc_start
> thereby removing the smatch warning mentioned above.
> 
> Reported-by: Dan Carpenter 
> Cc: Laurent Pinchart 
> Cc: Felipe Balbi 
> Signed-off-by: Sudeep Holla 

Acked-by: Laurent Pinchart 

> ---
>  drivers/usb/isp1760/isp1760-udc.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> Hi Laurent, Felipe,
> 
> I am extremely sorry for missing this in my original patch.

I hope you will be ashamed for the 7 generations to come for this totally 
unacceptable low quality standard.

Just kidding of course, to err is human :-) Thank you for fixing it.

> Thanks to Dan Carpenter for reporting this.
> 
> Regards,
> Sudeep
> 
> diff --git a/drivers/usb/isp1760/isp1760-udc.c
> b/drivers/usb/isp1760/isp1760-udc.c index fbfbd59aae64..b7094eee0bdd 100644
> --- a/drivers/usb/isp1760/isp1760-udc.c
> +++ b/drivers/usb/isp1760/isp1760-udc.c
> @@ -1203,7 +1203,7 @@ static int isp1760_udc_start(struct usb_gadget
> *gadget,
> 
>   if (udc->driver) {
>   dev_err(udc->isp->dev, "UDC already has a gadget driver\n");
> - spin_unlock(&udc->lock);
> + spin_unlock_irqrestore(&udc->lock, flags);
>   return -EBUSY;
>   }

-- 
Regards,

Laurent Pinchart

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


Re: [PATCH 2/3] cdc-wdm: unify error handling in write

2015-03-20 Thread Oliver Neukum
On Fri, 2015-03-20 at 15:02 +0100, Bjørn Mork wrote:
> Oliver Neukum  writes:
> 
> > This makes sure the error handling path is the same for
> > all error conditions, thus reducing code duplication.
> 
> Great!  This looks like I nice cleanup.  Will test it out.  Just a quick
> comment based on the first glance:
> 
> >  outnl:
> > return rv < 0 ? rv : count;
> 
> How about changing the single remaining error without any rewinding into
> a direct "return -ENOMEM", and then drop the "outnl" label and simplify
> this to "return count"?

That would be the direct opposite of what this patch tries to do.
Direct returns in a function with lock are not what I prefer to do.

Regards
Oliver


--
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 RESEND] usb: gadget: configfs: Fix interfaces array NULL-termination

2015-03-20 Thread Krzysztof Opasiak
memset() to 0 interfaces array before reusing
usb_configuration structure.

This commit fix bug:

ln -s functions/acm.1 configs/c.1
ln -s functions/acm.2 configs/c.1
ln -s functions/acm.3 configs/c.1
echo "UDC name" > UDC
echo "" > UDC
rm configs/c.1/acm.*
rmdir functions/*
mkdir functions/ecm.usb0
ln -s functions/ecm.usb0 configs/c.1
echo "UDC name" > UDC

[   82.220969] Unable to handle kernel NULL pointer dereference at virtual 
address 
[   82.229009] pgd = c0004000
[   82.231698] [] *pgd=
[   82.235260] Internal error: Oops: 17 [#1] PREEMPT SMP ARM
[   82.240638] Modules linked in:
[   82.243681] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 4.0.0-rc2 #39
[   82.249926] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree)
[   82.256003] task: c07cd2f0 ti: c07c8000 task.ti: c07c8000
[   82.261393] PC is at composite_setup+0xe3c/0x1674
[   82.266073] LR is at composite_setup+0xf20/0x1674
[   82.270760] pc : []lr : []psr: 61d3
[   82.270760] sp : c07c9df0  ip : c0806448  fp : ed8c9c9c
[   82.282216] r10: 0001  r9 :   r8 : edaae918
[   82.287425] r7 : ed551cc0  r6 : 7fff  r5 :   r4 : ed799634
[   82.293934] r3 : 0003  r2 : 00010002  r1 : edaae918  r0 : 002e
[   82.300446] Flags: nZCv  IRQs off  FIQs off  Mode SVC_32  ISA ARM  Segment 
kernel
[   82.307910] Control: 10c5387d  Table: 6bc1804a  DAC: 0015
[   82.313638] Process swapper/0 (pid: 0, stack limit = 0xc07c8210)
[   82.319627] Stack: (0xc07c9df0 to 0xc07ca000)
[   82.323969] 9de0:  c06e65f4 
 c07c9f68
[   82.332130] 9e00: 0067 c07c59ac 03f7 edaae918 ed8c9c98 ed799690 
eca2f140 21d3
[   82.340289] 9e20: ee79a2d8 c07c9e88 c07c5304 55db 00010002 edaae810 
edaae860 eda96d50
[   82.348448] 9e40: 0009 ee264510 0007 c07ca444 edaae860 c0340890 
c0827a40 55e0
[   82.356607] 9e60: c0827a40 eda96e40 ee264510 edaae810  edaae860 
0007 c07ca444
[   82.364766] 9e80: edaae860 c0354170 c03407dc c033db4c edaae810  
 0010
[   82.372925] 9ea0: 0032 c0341670   0001 eda96e00 
 
[   82.381084] 9ec0:  0032 c0803a23 ee1aa840 0001 c005d54c 
249e2450 
[   82.389244] 9ee0: 21d3 ee1aa840 ee1aa8a0 ed84f4c0  c07c9f68 
0067 c07c59ac
[   82.397403] 9f00:  c005d688 ee1aa840 ee1aa8a0 c07db4b4 c006009c 
0032 
[   82.405562] 9f20: 0001 c005ce20 c07c59ac c005cf34 f002000c c07ca780 
c07c9f68 0057
[   82.413722] 9f40: f002 413fc090 0001 c00086b4 c000f804 6053 
 c07c9f9c
[   82.421880] 9f60: c0803a20 c0011fc0   c07c9fb8 c001bee0 
c07ca4f0 c057004c
[   82.430040] 9f80: c07ca4fc c0803a20 c0803a20 413fc090 0001  
0100 c07c9fb0
[   82.438199] 9fa0: c000f800 c000f804 6053   c0050e70 
c0803bc0 c0783bd8
[   82.446358] 9fc0:   c0783664   c07b13e8 
 c0803e54
[   82.454517] 9fe0: c07ca480 c07b13e4 c07ce40c 4000406a  40008074 
 
[   82.462689] [] (composite_setup) from [] 
(s3c_hsotg_complete_setup+0xb4/0x418)
[   82.471626] [] (s3c_hsotg_complete_setup) from [] 
(usb_gadget_giveback_request+0xc/0x10)
[   82.481429] [] (usb_gadget_giveback_request) from [] 
(s3c_hsotg_complete_request+0xcc/0x12c)
[   82.491583] [] (s3c_hsotg_complete_request) from [] 
(s3c_hsotg_irq+0x4fc/0x558)
[   82.500614] [] (s3c_hsotg_irq) from [] 
(handle_irq_event_percpu+0x50/0x150)
[   82.509291] [] (handle_irq_event_percpu) from [] 
(handle_irq_event+0x3c/0x5c)
[   82.518145] [] (handle_irq_event) from [] 
(handle_fasteoi_irq+0xd4/0x18c)
[   82.526650] [] (handle_fasteoi_irq) from [] 
(generic_handle_irq+0x20/0x30)
[   82.535242] [] (generic_handle_irq) from [] 
(__handle_domain_irq+0x6c/0xdc)
[   82.543923] [] (__handle_domain_irq) from [] 
(gic_handle_irq+0x2c/0x6c)
[   82.552256] [] (gic_handle_irq) from [] 
(__irq_svc+0x40/0x74)
[   82.559716] Exception stack(0xc07c9f68 to 0xc07c9fb0)
[   82.564753] 9f60:     c07c9fb8 c001bee0 
c07ca4f0 c057004c
[   82.572913] 9f80: c07ca4fc c0803a20 c0803a20 413fc090 0001  
0100 c07c9fb0
[   82.581069] 9fa0: c000f800 c000f804 6053 
[   82.586113] [] (__irq_svc) from [] 
(arch_cpu_idle+0x30/0x3c)
[   82.593491] [] (arch_cpu_idle) from [] 
(cpu_startup_entry+0x128/0x1a4)
[   82.601740] [] (cpu_startup_entry) from [] 
(start_kernel+0x350/0x3bc)
[   82.609890] Code: 0a02 e3530005 05975010 15975008 (e5953000)
[   82.615965] ---[ end trace f57d5f599a5f1bfa ]---

Most of kernel code assume that interface array in
struct usb_configuration is NULL terminated.

When gadget is composed with configfs configuration
structure may be reused for different functions set.

This bug happens because purge_configs_funcs() sets
only next_interface_id to 0. Interface array still
contains pointers to already freed interfaces. If 

Re: [PATCH] usb: isp1760: fix spin unlock in the error path of isp1760_udc_start

2015-03-20 Thread Sudeep Holla

Hi Laurent,

On 20/03/15 14:20, Laurent Pinchart wrote:

Hi Sudeep,

Thank you for the patch.

On Friday 20 March 2015 11:42:17 Sudeep Holla wrote:

Commit a124820de5fd ("usb: isp1760: fix possible deadlock in
isp1760_udc_irq") replaced spin_{un,}lock with
spin_{un,}lock_irq{save,restore}. However it missed an error path resulting
in the smatch warning as below:

drivers/usb/isp1760/isp1760-udc.c:1230 isp1760_udc_start() warn:
inconsistent returns 'irqsave:flags'. Locked on:   line 1207
Unlocked on: line 1199

This patch fixes the spin unlock in the error path in isp1760_udc_start
thereby removing the smatch warning mentioned above.

Reported-by: Dan Carpenter 
Cc: Laurent Pinchart 
Cc: Felipe Balbi 
Signed-off-by: Sudeep Holla 


Acked-by: Laurent Pinchart 



Thanks


---
  drivers/usb/isp1760/isp1760-udc.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)

Hi Laurent, Felipe,

I am extremely sorry for missing this in my original patch.


I hope you will be ashamed for the 7 generations to come for this totally
unacceptable low quality standard.



Yes ;)

Regards,
Sudeep


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


Re: [PATCH 2/3] cdc-wdm: unify error handling in write

2015-03-20 Thread Bjørn Mork
Oliver Neukum  writes:

> On Fri, 2015-03-20 at 15:02 +0100, Bjørn Mork wrote:
>> Oliver Neukum  writes:
>> 
>> > This makes sure the error handling path is the same for
>> > all error conditions, thus reducing code duplication.
>> 
>> Great!  This looks like I nice cleanup.  Will test it out.  Just a quick
>> comment based on the first glance:
>> 
>> >  outnl:
>> >return rv < 0 ? rv : count;
>> 
>> How about changing the single remaining error without any rewinding into
>> a direct "return -ENOMEM", and then drop the "outnl" label and simplify
>> this to "return count"?
>
> That would be the direct opposite of what this patch tries to do.
> Direct returns in a function with lock are not what I prefer to do.

OK.  I just noticed that you left the direct return just prior to this
one, after fixing up the error translation.

Anyway, the "outnl" is only ever used with rv < 0, and with your changes
all other cases where rv < 0 will jump to some other label.  So I don't
think it makes much sense to keep the "return rv < 0 ? rv : count" even
if you don't want the direct return.  Just move the "outnl" label
(possibly with a more describing name) down to the "return rv" at the
end.


I.e something like this:


bjorn@nemi:/usr/local/src/git/linux$ git diff
diff --git a/drivers/usb/class/cdc-wdm.c b/drivers/usb/class/cdc-wdm.c
index b78aa6f2a8c1..daa1ac300ac5 100644
--- a/drivers/usb/class/cdc-wdm.c
+++ b/drivers/usb/class/cdc-wdm.c
@@ -430,8 +430,7 @@ static ssize_t wdm_write
 
usb_autopm_put_interface(desc->intf);
mutex_unlock(&desc->wlock);
-outnl:
-   return rv < 0 ? rv : count;
+   return count;
 
 out_free_mem_pm:
usb_autopm_put_interface(desc->intf);
@@ -439,6 +438,7 @@ out_free_mem_lock:
mutex_unlock(&desc->wlock);
 out_free_mem:
kfree(buf);
+outnl:
return rv;
 }




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


[PATCH v2 00/22] usb: third series of updates for dwc2 driver

2015-03-20 Thread Mian Yousaf Kaukab
Hi,
This patchset consists of some bug fixes and feature enhancements for
the dwc2 driver. All the patches are verified on dwc2 v3.0a with
dedicated fifos. Main focus of testing was with dma enabled. Although
basic testing without dma was also done.

This is based on testing/next branch in Felipe's git.

Thank you,

Best regards,
Yousaf

History:
v2:
 - Fixed comments from John Youn and Julius Werner
 - Fixed regression, found by John, when switching to gadget mode
   after running host mode
 - Added patch to add core parameter for enabling/disabling hibernation
 - Added patch to build dwc2_pci.ko independent from dwc2.ko
v1:
 - Fixed comments from John Youn and Robert Baldyga
 - Dropped all changes to pci.c due to
   http://permalink.gmane.org/gmane.linux.usb.general/123411
 - Added patch to remove unnecessary EXPORT_SYMBOL_GPL calls

Gregory Herrero (14):
  usb: dwc2: add controller hibernation support
  usb: dwc2: implement hibernation during bus suspend/resume
  usb: dwc2: controller must update lx_state before releasing lock
  usb: dwc2: add external_id_pin_ctl core parameter
  usb: dwc2: gadget: use reset detect interrupt
  usb: dwc2: gadget: ignore pm suspend/resume in L2
  usb: dwc2: gadget: prevent new request submission during suspend
  usb: dwc2: gadget: powerup controller if needed
  usb: dwc2: gadget: enable otg flag in dual role configuration
  usb: dwc2: host: add bus_suspend/bus_resume callback
  usb: dwc2: host: resume root hub on port connect
  usb: dwc2: host: spinlock urb_enqueue
  usb: dwc2: host: don't use dma_alloc_coherent with irqs disabled
  usb: dwc2: add hibernation core parameter

Jingwu Lin (1):
  usb: dwc2: host: implement test mode

Mian Yousaf Kaukab (7):
  usb: dwc2: move debugfs code to a separate file
  usb: dwc2: debugfs: add support for complete register dump
  usb: dwc2: set parameter values in probe function
  usb: dwc2: gadget: remove s3c_hsotg_ep_disable_force
  usb: dwc2: host: register handle to the phy
  usb: dwc2: remove dwc2_platform.ko
  usb: dwc2: allow dwc2_pci to be a module even when dwc2 is statically
linked

 drivers/usb/dwc2/Kconfig |   8 -
 drivers/usb/dwc2/Makefile|  11 +-
 drivers/usb/dwc2/core.c  | 439 +++-
 drivers/usb/dwc2/core.h  | 120 ++-
 drivers/usb/dwc2/core_intr.c |  45 ++-
 drivers/usb/dwc2/debug.h |  27 ++
 drivers/usb/dwc2/debugfs.c   | 771 +++
 drivers/usb/dwc2/gadget.c| 459 +++---
 drivers/usb/dwc2/hcd.c   |  95 +++---
 drivers/usb/dwc2/hcd.h   |   7 +-
 drivers/usb/dwc2/hcd_intr.c  |  13 +
 drivers/usb/dwc2/hcd_queue.c |  15 +-
 drivers/usb/dwc2/platform.c  |  25 +-
 13 files changed, 1528 insertions(+), 507 deletions(-)
 create mode 100644 drivers/usb/dwc2/debug.h
 create mode 100644 drivers/usb/dwc2/debugfs.c

-- 
1.9.1

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


[PATCH v2 02/22] usb: dwc2: debugfs: add support for complete register dump

2015-03-20 Thread Mian Yousaf Kaukab
Dump all registers to take a complete snapshot of dwc2 state.
Code is inspired by dwc3/debugfs.c

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/core.h|   1 +
 drivers/usb/dwc2/debugfs.c | 357 +
 2 files changed, 358 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 3695c6f..1fd8d2b 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -615,6 +615,7 @@ struct dwc2_hsotg {
enum dwc2_lx_state lx_state;
 
struct dentry *debug_root;
+   struct debugfs_regset32 *regset;
 
/* DWC OTG HW Release versions */
 #define DWC2_CORE_REV_2_71a0x4f54271a
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
index e57e554..af89537 100644
--- a/drivers/usb/dwc2/debugfs.c
+++ b/drivers/usb/dwc2/debugfs.c
@@ -391,9 +391,344 @@ static inline void s3c_hsotg_create_debug(struct 
dwc2_hsotg *hsotg) {}
 
 /* s3c_hsotg_delete_debug is removed as cleanup in done in dwc2_debugfs_exit */
 
+#define dump_register(nm)  \
+{  \
+   .name   = #nm,  \
+   .offset = nm,   \
+}
+
+static const struct debugfs_reg32 dwc2_regs[] = {
+   /*
+* Accessing registers like this can trigger mode mismatch interrupt.
+* However, according to dwc2 databook, the register access, in this
+* case, is completed on the processor bus but is ignored by the core
+* and does not affect its operation.
+*/
+   dump_register(GOTGCTL),
+   dump_register(GOTGINT),
+   dump_register(GAHBCFG),
+   dump_register(GUSBCFG),
+   dump_register(GRSTCTL),
+   dump_register(GINTSTS),
+   dump_register(GINTMSK),
+   dump_register(GRXSTSR),
+   dump_register(GRXSTSP),
+   dump_register(GRXFSIZ),
+   dump_register(GNPTXFSIZ),
+   dump_register(GNPTXSTS),
+   dump_register(GI2CCTL),
+   dump_register(GPVNDCTL),
+   dump_register(GGPIO),
+   dump_register(GUID),
+   dump_register(GSNPSID),
+   dump_register(GHWCFG1),
+   dump_register(GHWCFG2),
+   dump_register(GHWCFG3),
+   dump_register(GHWCFG4),
+   dump_register(GLPMCFG),
+   dump_register(GPWRDN),
+   dump_register(GDFIFOCFG),
+   dump_register(ADPCTL),
+   dump_register(HPTXFSIZ),
+   dump_register(DPTXFSIZN(1)),
+   dump_register(DPTXFSIZN(2)),
+   dump_register(DPTXFSIZN(3)),
+   dump_register(DPTXFSIZN(4)),
+   dump_register(DPTXFSIZN(5)),
+   dump_register(DPTXFSIZN(6)),
+   dump_register(DPTXFSIZN(7)),
+   dump_register(DPTXFSIZN(8)),
+   dump_register(DPTXFSIZN(9)),
+   dump_register(DPTXFSIZN(10)),
+   dump_register(DPTXFSIZN(11)),
+   dump_register(DPTXFSIZN(12)),
+   dump_register(DPTXFSIZN(13)),
+   dump_register(DPTXFSIZN(14)),
+   dump_register(DPTXFSIZN(15)),
+   dump_register(DCFG),
+   dump_register(DCTL),
+   dump_register(DSTS),
+   dump_register(DIEPMSK),
+   dump_register(DOEPMSK),
+   dump_register(DAINT),
+   dump_register(DAINTMSK),
+   dump_register(DTKNQR1),
+   dump_register(DTKNQR2),
+   dump_register(DTKNQR3),
+   dump_register(DTKNQR4),
+   dump_register(DVBUSDIS),
+   dump_register(DVBUSPULSE),
+   dump_register(DIEPCTL(0)),
+   dump_register(DIEPCTL(1)),
+   dump_register(DIEPCTL(2)),
+   dump_register(DIEPCTL(3)),
+   dump_register(DIEPCTL(4)),
+   dump_register(DIEPCTL(5)),
+   dump_register(DIEPCTL(6)),
+   dump_register(DIEPCTL(7)),
+   dump_register(DIEPCTL(8)),
+   dump_register(DIEPCTL(9)),
+   dump_register(DIEPCTL(10)),
+   dump_register(DIEPCTL(11)),
+   dump_register(DIEPCTL(12)),
+   dump_register(DIEPCTL(13)),
+   dump_register(DIEPCTL(14)),
+   dump_register(DIEPCTL(15)),
+   dump_register(DOEPCTL(0)),
+   dump_register(DOEPCTL(1)),
+   dump_register(DOEPCTL(2)),
+   dump_register(DOEPCTL(3)),
+   dump_register(DOEPCTL(4)),
+   dump_register(DOEPCTL(5)),
+   dump_register(DOEPCTL(6)),
+   dump_register(DOEPCTL(7)),
+   dump_register(DOEPCTL(8)),
+   dump_register(DOEPCTL(9)),
+   dump_register(DOEPCTL(10)),
+   dump_register(DOEPCTL(11)),
+   dump_register(DOEPCTL(12)),
+   dump_register(DOEPCTL(13)),
+   dump_register(DOEPCTL(14)),
+   dump_register(DOEPCTL(15)),
+   dump_register(DIEPINT(0)),
+   dump_register(DIEPINT(1)),
+   dump_register(DIEPINT(2)),
+   dump_register(DIEPINT(3)),
+   dump_register(DIEPINT(4)),
+   dump_register(DIEPINT(5)),
+   dump_register(DIEPINT(6)),
+   dump_register(DIEPINT(7)),
+   dump_register(DIEPINT(8)),
+   dump_register(DIEPINT(9)),
+   dump_register(DIEPINT(10)),
+   dump_register(DIEPINT(11)),
+   dump_register(DIEPINT(12)),
+   dump_register(DIEPINT(13)),
+   dump_register(DIEPINT(14)),
+   dum

[PATCH v2 01/22] usb: dwc2: move debugfs code to a separate file

2015-03-20 Thread Mian Yousaf Kaukab
Prepare to add more debug code. Moreover, don't save dentry * for
each file in struct dwc2_hsotg as clean up is done with
debugfs_remove_recursive(). s3c_hsotg_delete_debug() is removed
altogether for the same reason.

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/Makefile   |   4 +
 drivers/usb/dwc2/core.h |   7 +-
 drivers/usb/dwc2/debug.h|  27 +++
 drivers/usb/dwc2/debugfs.c  | 416 
 drivers/usb/dwc2/gadget.c   | 405 +-
 drivers/usb/dwc2/platform.c |   4 +
 6 files changed, 456 insertions(+), 407 deletions(-)
 create mode 100644 drivers/usb/dwc2/debug.h
 create mode 100644 drivers/usb/dwc2/debugfs.c

diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
index 8f75267..147d759 100644
--- a/drivers/usb/dwc2/Makefile
+++ b/drivers/usb/dwc2/Makefile
@@ -13,6 +13,10 @@ ifneq ($(filter y,$(CONFIG_USB_DWC2_PERIPHERAL) 
$(CONFIG_USB_DWC2_DUAL_ROLE)),)
dwc2-y  += gadget.o
 endif
 
+ifneq ($(CONFIG_DEBUG_FS),)
+   dwc2-y  += debugfs.o
+endif
+
 # NOTE: The previous s3c-hsotg peripheral mode only driver has been moved to
 # this location and renamed gadget.c. When building for dynamically linked
 # modules, dwc2.ko will get built for host mode, peripheral mode, and dual-role
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index 836c012..3695c6f 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -615,9 +615,6 @@ struct dwc2_hsotg {
enum dwc2_lx_state lx_state;
 
struct dentry *debug_root;
-   struct dentry *debug_file;
-   struct dentry *debug_testmode;
-   struct dentry *debug_fifo;
 
/* DWC OTG HW Release versions */
 #define DWC2_CORE_REV_2_71a0x4f54271a
@@ -1005,6 +1002,7 @@ extern void s3c_hsotg_core_init_disconnected(struct 
dwc2_hsotg *dwc2,
bool reset);
 extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg);
 extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2);
+extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
 #else
 static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2)
 { return 0; }
@@ -1018,6 +1016,9 @@ static inline void 
s3c_hsotg_core_init_disconnected(struct dwc2_hsotg *dwc2,
bool reset) {}
 static inline void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg) {}
 static inline void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2) {}
+static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
+   int testmode)
+{ return 0; }
 #endif
 
 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
diff --git a/drivers/usb/dwc2/debug.h b/drivers/usb/dwc2/debug.h
new file mode 100644
index 000..12dbd1d
--- /dev/null
+++ b/drivers/usb/dwc2/debug.h
@@ -0,0 +1,27 @@
+/**
+ * debug.h - Designware USB2 DRD controller debug header
+ *
+ * Copyright (C) 2015 Intel Corporation
+ * Mian Yousaf Kaukab 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include "core.h"
+
+#ifdef CONFIG_DEBUG_FS
+extern int dwc2_debugfs_init(struct dwc2_hsotg *);
+extern void dwc2_debugfs_exit(struct dwc2_hsotg *);
+#else
+static inline int dwc2_debugfs_init(struct dwc2_hsotg *hsotg)
+{  return 0;  }
+static inline void dwc2_debugfs_exit(struct dwc2_hsotg *hsotg)
+{  }
+#endif
diff --git a/drivers/usb/dwc2/debugfs.c b/drivers/usb/dwc2/debugfs.c
new file mode 100644
index 000..e57e554
--- /dev/null
+++ b/drivers/usb/dwc2/debugfs.c
@@ -0,0 +1,416 @@
+/**
+ * debugfs.c - Designware USB2 DRD controller debugfs
+ *
+ * Copyright (C) 2015 Intel Corporation
+ * Mian Yousaf Kaukab 
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2  of
+ * the License as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include 
+#include 
+#include 
+#include 
+
+#include "core.h"
+#include "debug.h"
+
+#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
+   IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
+/**
+ * testmode_write - debugfs: change usb test mode
+ * @seq: The seq file to write to.
+ * @v: Unused parameter.
+ *
+ * This debugfs entry modify the current usb test mode.
+ */
+static ssize_t testm

[PATCH v2 03/22] usb: dwc2: add controller hibernation support

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

When suspending usb bus, phy driver may disable controller power.
In this case, registers need to be saved on suspend and restored
on resume.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/core.c | 377 
 drivers/usb/dwc2/core.h |  84 +++
 2 files changed, 461 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index d5197d4..889dc5f 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -56,6 +56,383 @@
 #include "core.h"
 #include "hcd.h"
 
+#if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
+/**
+ * dwc2_backup_host_registers() - Backup controller host registers.
+ * When suspending usb bus, registers needs to be backuped
+ * if controller power is disabled once suspended.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
+{
+   struct dwc2_hregs_backup *hr;
+   int i;
+
+   dev_dbg(hsotg->dev, "%s\n", __func__);
+
+   /* Backup Host regs */
+   hr = hsotg->hr_backup;
+   if (!hr) {
+   hr = devm_kzalloc(hsotg->dev, sizeof(*hr), GFP_KERNEL);
+   if (!hr) {
+   dev_err(hsotg->dev, "%s: can't allocate host regs\n",
+   __func__);
+   return -ENOMEM;
+   }
+
+   hsotg->hr_backup = hr;
+   }
+   hr->hcfg = readl(hsotg->regs + HCFG);
+   hr->haintmsk = readl(hsotg->regs + HAINTMSK);
+   for (i = 0; i < hsotg->core_params->host_channels; ++i)
+   hr->hcintmsk[i] = readl(hsotg->regs + HCINTMSK(i));
+
+   hr->hprt0 = readl(hsotg->regs + HPRT0);
+   hr->hfir = readl(hsotg->regs + HFIR);
+
+   return 0;
+}
+
+/**
+ * dwc2_restore_host_registers() - Restore controller host registers.
+ * When resuming usb bus, device registers needs to be restored
+ * if controller power were disabled.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
+{
+   struct dwc2_hregs_backup *hr;
+   int i;
+
+   dev_dbg(hsotg->dev, "%s\n", __func__);
+
+   /* Restore host regs */
+   hr = hsotg->hr_backup;
+   if (!hr) {
+   dev_err(hsotg->dev, "%s: no host registers to restore\n",
+   __func__);
+   return -EINVAL;
+   }
+
+   writel(hr->hcfg, hsotg->regs + HCFG);
+   writel(hr->haintmsk, hsotg->regs + HAINTMSK);
+
+   for (i = 0; i < hsotg->core_params->host_channels; ++i)
+   writel(hr->hcintmsk[i], hsotg->regs + HCINTMSK(i));
+
+   writel(hr->hprt0, hsotg->regs + HPRT0);
+   writel(hr->hfir, hsotg->regs + HFIR);
+
+   return 0;
+}
+#else
+static inline int dwc2_backup_host_registers(struct dwc2_hsotg *hsotg)
+{ return 0; }
+
+static inline int dwc2_restore_host_registers(struct dwc2_hsotg *hsotg)
+{ return 0; }
+#endif
+
+#if IS_ENABLED(CONFIG_USB_DWC2_PERIPHERAL) || \
+   IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
+/**
+ * dwc2_backup_device_registers() - Backup controller device registers.
+ * When suspending usb bus, registers needs to be backuped
+ * if controller power is disabled once suspended.
+ *
+ * @hsotg: Programming view of the DWC_otg controller
+ */
+static int dwc2_backup_device_registers(struct dwc2_hsotg *hsotg)
+{
+   struct dwc2_dregs_backup *dr;
+   int i;
+
+   dev_dbg(hsotg->dev, "%s\n", __func__);
+
+   /* Backup dev regs */
+   dr = hsotg->dr_backup;
+   if (!dr) {
+   dr = devm_kzalloc(hsotg->dev, sizeof(*dr), GFP_KERNEL);
+   if (!dr) {
+   dev_err(hsotg->dev, "%s: can't allocate device regs\n",
+   __func__);
+   return -ENOMEM;
+   }
+
+   hsotg->dr_backup = dr;
+   }
+
+   dr->dcfg = readl(hsotg->regs + DCFG);
+   dr->dctl = readl(hsotg->regs + DCTL);
+   dr->daintmsk = readl(hsotg->regs + DAINTMSK);
+   dr->diepmsk = readl(hsotg->regs + DIEPMSK);
+   dr->doepmsk = readl(hsotg->regs + DOEPMSK);
+
+   for (i = 0; i < hsotg->num_of_eps; i++) {
+   /* Backup IN EPs */
+   dr->diepctl[i] = readl(hsotg->regs + DIEPCTL(i));
+
+   /* Ensure DATA PID is correctly configured */
+   if (dr->diepctl[i] & DXEPCTL_DPID)
+   dr->diepctl[i] |= DXEPCTL_SETD1PID;
+   else
+   dr->diepctl[i] |= DXEPCTL_SETD0PID;
+
+   dr->dieptsiz[i] = readl(hsotg->regs + DIEPTSIZ(i));
+   dr->diepdma[i] = readl(hsotg->regs + DIEPDMA(i));
+
+   /* Backup OUT EPs */
+   dr->doepctl[i] = readl(hsotg->regs + DOEPCTL(i));
+
+   /* Ensure DATA PID is correctly configured */
+   if (dr->doepctl[i] &

[PATCH v2 05/22] usb: dwc2: controller must update lx_state before releasing lock

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

During suspend, there could a race condition between ep_queue and
suspend interrupt if lx_state is updated after releasing spinlock in
call_gadget(hsotg, suspend).

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/core_intr.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 42f2fd5..f5ef26e 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -436,6 +436,12 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg 
*hsotg)
if (!IS_ERR_OR_NULL(hsotg->uphy))
usb_phy_set_suspend(hsotg->uphy, true);
 skip_power_saving:
+   /*
+* Change to L2 (suspend) state before releasing
+* spinlock
+*/
+   hsotg->lx_state = DWC2_L2;
+
/* Call gadget suspend callback */
call_gadget(hsotg, suspend);
}
@@ -443,6 +449,8 @@ skip_power_saving:
if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
 
+   /* Change to L2 (suspend) state */
+   hsotg->lx_state = DWC2_L2;
/* Clear the a_peripheral flag, back to a_host */
spin_unlock(&hsotg->lock);
dwc2_hcd_start(hsotg);
@@ -451,9 +459,6 @@ skip_power_saving:
}
}
 
-   /* Change to L2 (suspend) state */
-   hsotg->lx_state = DWC2_L2;
-
 clear_int:
/* Clear interrupt */
writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS);
-- 
1.9.1

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


[PATCH v2 04/22] usb: dwc2: implement hibernation during bus suspend/resume

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Allow controller to enter in hibernation during usb bus suspend and
inform both phy and gadget about the suspended state.
While in hibernation, the controller can't detect the resume condition.
An external mechanism must call usb_phy_set_suspend on resume.
Exit hibernation when controller gets the resume interrupt and inform
only gadget driver about it.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/core.h  |  2 ++
 drivers/usb/dwc2/core_intr.c | 32 
 2 files changed, 34 insertions(+)

diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index b0ee951..e6abc28 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1088,6 +1088,7 @@ extern void s3c_hsotg_core_init_disconnected(struct 
dwc2_hsotg *dwc2,
 extern void s3c_hsotg_core_connect(struct dwc2_hsotg *hsotg);
 extern void s3c_hsotg_disconnect(struct dwc2_hsotg *dwc2);
 extern int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg, int testmode);
+#define dwc2_is_device_connected(hsotg) (hsotg->connected)
 #else
 static inline int s3c_hsotg_remove(struct dwc2_hsotg *dwc2)
 { return 0; }
@@ -1104,6 +1105,7 @@ static inline void s3c_hsotg_disconnect(struct dwc2_hsotg 
*dwc2) {}
 static inline int s3c_hsotg_set_test_mode(struct dwc2_hsotg *hsotg,
int testmode)
 { return 0; }
+#define dwc2_is_device_connected(hsotg) (0)
 #endif
 
 #if IS_ENABLED(CONFIG_USB_DWC2_HOST) || IS_ENABLED(CONFIG_USB_DWC2_DUAL_ROLE)
diff --git a/drivers/usb/dwc2/core_intr.c b/drivers/usb/dwc2/core_intr.c
index 02e3e2d..42f2fd5 100644
--- a/drivers/usb/dwc2/core_intr.c
+++ b/drivers/usb/dwc2/core_intr.c
@@ -334,6 +334,7 @@ static void dwc2_handle_session_req_intr(struct dwc2_hsotg 
*hsotg)
  */
 static void dwc2_handle_wakeup_detected_intr(struct dwc2_hsotg *hsotg)
 {
+   int ret;
dev_dbg(hsotg->dev, "++Resume or Remote Wakeup Detected Interrupt++\n");
dev_dbg(hsotg->dev, "%s lxstate = %d\n", __func__, hsotg->lx_state);
 
@@ -345,6 +346,11 @@ static void dwc2_handle_wakeup_detected_intr(struct 
dwc2_hsotg *hsotg)
/* Clear Remote Wakeup Signaling */
dctl &= ~DCTL_RMTWKUPSIG;
writel(dctl, hsotg->regs + DCTL);
+   ret = dwc2_exit_hibernation(hsotg, true);
+   if (ret)
+   dev_err(hsotg->dev, "exit hibernation 
failed\n");
+
+   call_gadget(hsotg, resume);
}
/* Change to L0 state */
hsotg->lx_state = DWC2_L0;
@@ -394,6 +400,7 @@ static void dwc2_handle_disconnect_intr(struct dwc2_hsotg 
*hsotg)
 static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg *hsotg)
 {
u32 dsts;
+   int ret;
 
dev_dbg(hsotg->dev, "USB SUSPEND\n");
 
@@ -408,6 +415,30 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg 
*hsotg)
"DSTS.Suspend Status=%d HWCFG4.Power Optimize=%d\n",
!!(dsts & DSTS_SUSPSTS),
hsotg->hw_params.power_optimized);
+   if ((dsts & DSTS_SUSPSTS) && hsotg->hw_params.power_optimized) {
+   /* Ignore suspend request before enumeration */
+   if (!dwc2_is_device_connected(hsotg)) {
+   dev_dbg(hsotg->dev,
+   "ignore suspend request before 
enumeration\n");
+   goto clear_int;
+   }
+
+   ret = dwc2_enter_hibernation(hsotg);
+   if (ret) {
+   dev_err(hsotg->dev,
+   "enter hibernation failed\n");
+   goto skip_power_saving;
+   }
+
+   udelay(100);
+
+   /* Ask phy to be suspended */
+   if (!IS_ERR_OR_NULL(hsotg->uphy))
+   usb_phy_set_suspend(hsotg->uphy, true);
+skip_power_saving:
+   /* Call gadget suspend callback */
+   call_gadget(hsotg, suspend);
+   }
} else {
if (hsotg->op_state == OTG_STATE_A_PERIPHERAL) {
dev_dbg(hsotg->dev, "a_peripheral->a_host\n");
@@ -423,6 +454,7 @@ static void dwc2_handle_usb_suspend_intr(struct dwc2_hsotg 
*hsotg)
/* Change to L2 (suspend) state */
hsotg->lx_state = DWC2_L2;
 
+clear_int:
/* Clear interrupt */
writel(GINTSTS_USBSUSP, hsotg->regs + GINTSTS);
 }
-- 
1.9.1

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


[PATCH v2 22/22] usb: dwc2: allow dwc2_pci to be a module even when dwc2 is statically linked

2015-03-20 Thread Mian Yousaf Kaukab
There is no need for dwc2_pci to depend on dwc2 configuration

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/Makefile | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/dwc2/Makefile b/drivers/usb/dwc2/Makefile
index 1547002..de65b94 100644
--- a/drivers/usb/dwc2/Makefile
+++ b/drivers/usb/dwc2/Makefile
@@ -24,6 +24,6 @@ endif
 # interface module will be called dwc2_platform.ko.
 
 ifneq ($(CONFIG_USB_DWC2_PCI),)
-   obj-$(CONFIG_USB_DWC2)  += dwc2_pci.o
+   obj-$(CONFIG_USB_DWC2_PCI)  += dwc2_pci.o
dwc2_pci-y  := pci.o
 endif
-- 
1.9.1

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


[PATCH v2 09/22] usb: dwc2: gadget: ignore pm suspend/resume in L2

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Nothing to be done in pm suspend/resume when controller is in L2.
Don't disconnect or reset. State is already saved when putting
controller in hibernation and will be restored on USB bus resume.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/gadget.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index d528c02..539a3d4 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -3672,6 +3672,9 @@ int s3c_hsotg_suspend(struct dwc2_hsotg *hsotg)
unsigned long flags;
int ret = 0;
 
+   if (hsotg->lx_state != DWC2_L0)
+   return ret;
+
mutex_lock(&hsotg->init_mutex);
 
if (hsotg->driver) {
@@ -3712,6 +3715,9 @@ int s3c_hsotg_resume(struct dwc2_hsotg *hsotg)
unsigned long flags;
int ret = 0;
 
+   if (hsotg->lx_state == DWC2_L2)
+   return ret;
+
mutex_lock(&hsotg->init_mutex);
 
if (hsotg->driver) {
-- 
1.9.1

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


[PATCH v2 07/22] usb: dwc2: set parameter values in probe function

2015-03-20 Thread Mian Yousaf Kaukab
So the parameters can be used in both host and gadget modes.
Also consolidate param functions in the core.h

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/core.c | 19 +++
 drivers/usb/dwc2/core.h | 13 ++---
 drivers/usb/dwc2/hcd.c  | 36 +---
 drivers/usb/dwc2/hcd.h  |  7 +--
 drivers/usb/dwc2/platform.c | 17 -
 5 files changed, 47 insertions(+), 45 deletions(-)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 8c3bc84..6acbe90 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -3044,6 +3044,7 @@ void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
dwc2_set_param_uframe_sched(hsotg, params->uframe_sched);
dwc2_set_param_external_id_pin_ctl(hsotg, params->external_id_pin_ctl);
 }
+EXPORT_SYMBOL_GPL(dwc2_set_parameters);
 
 /**
  * During device initialization, read various hardware configuration
@@ -3210,6 +3211,24 @@ int dwc2_get_hwparams(struct dwc2_hsotg *hsotg)
 
return 0;
 }
+EXPORT_SYMBOL_GPL(dwc2_get_hwparams);
+
+/*
+ * Sets all parameters to the given value.
+ *
+ * Assumes that the dwc2_core_params struct contains only integers.
+ */
+void dwc2_set_all_params(struct dwc2_core_params *params, int value)
+{
+   int *p = (int *)params;
+   size_t size = sizeof(*params) / sizeof(*p);
+   int i;
+
+   for (i = 0; i < size; i++)
+   p[i] = value;
+}
+EXPORT_SYMBOL_GPL(dwc2_set_all_params);
+
 
 u16 dwc2_get_otg_version(struct dwc2_hsotg *hsotg)
 {
diff --git a/drivers/usb/dwc2/core.h b/drivers/usb/dwc2/core.h
index e46304d..d7fb1f7 100644
--- a/drivers/usb/dwc2/core.h
+++ b/drivers/usb/dwc2/core.h
@@ -1071,6 +1071,15 @@ extern void dwc2_set_param_ahbcfg(struct dwc2_hsotg 
*hsotg, int val);
 
 extern void dwc2_set_param_otg_ver(struct dwc2_hsotg *hsotg, int val);
 
+extern void dwc2_set_parameters(struct dwc2_hsotg *hsotg,
+   const struct dwc2_core_params *params);
+
+extern void dwc2_set_all_params(struct dwc2_core_params *params, int value);
+
+extern int dwc2_get_hwparams(struct dwc2_hsotg *hsotg);
+
+
+
 /*
  * Dump core registers and SPRAM
  */
@@ -1119,14 +1128,12 @@ extern int dwc2_hcd_get_frame_number(struct dwc2_hsotg 
*hsotg);
 extern void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg);
 extern void dwc2_hcd_start(struct dwc2_hsotg *hsotg);
 #else
-static inline void dwc2_set_all_params(struct dwc2_core_params *params, int 
value) {}
 static inline int dwc2_hcd_get_frame_number(struct dwc2_hsotg *hsotg)
 { return 0; }
 static inline void dwc2_hcd_disconnect(struct dwc2_hsotg *hsotg) {}
 static inline void dwc2_hcd_start(struct dwc2_hsotg *hsotg) {}
 static inline void dwc2_hcd_remove(struct dwc2_hsotg *hsotg) {}
-static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
-   const struct dwc2_core_params *params)
+static inline int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
 { return 0; }
 #endif
 
diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index c78c874..cc6f394 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2740,8 +2740,6 @@ static void dwc2_hcd_free(struct dwc2_hsotg *hsotg)
destroy_workqueue(hsotg->wq_otg);
}
 
-   kfree(hsotg->core_params);
-   hsotg->core_params = NULL;
del_timer(&hsotg->wkp_timer);
 }
 
@@ -2754,29 +2752,12 @@ static void dwc2_hcd_release(struct dwc2_hsotg *hsotg)
 }
 
 /*
- * Sets all parameters to the given value.
- *
- * Assumes that the dwc2_core_params struct contains only integers.
- */
-void dwc2_set_all_params(struct dwc2_core_params *params, int value)
-{
-   int *p = (int *)params;
-   size_t size = sizeof(*params) / sizeof(*p);
-   int i;
-
-   for (i = 0; i < size; i++)
-   p[i] = value;
-}
-EXPORT_SYMBOL_GPL(dwc2_set_all_params);
-
-/*
  * Initializes the HCD. This function allocates memory for and initializes the
  * static parts of the usb_hcd and dwc2_hsotg structures. It also registers the
  * USB bus with the core and calls the hc_driver->start() function. It returns
  * a negative error on failure.
  */
-int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
- const struct dwc2_core_params *params)
+int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
 {
struct usb_hcd *hcd;
struct dwc2_host_chan *channel;
@@ -2789,12 +2770,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
 
dev_dbg(hsotg->dev, "DWC OTG HCD INIT\n");
 
-   /* Detect config values from hardware */
-   retval = dwc2_get_hwparams(hsotg);
-
-   if (retval)
-   return retval;
-
retval = -ENOMEM;
 
hcfg = readl(hsotg->regs + HCFG);
@@ -2813,15 +2788,6 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq,
hsotg->last_frame_num = HFNUM_MAX_FRNUM;
 #endif
 
-   hsotg->core_params = kzalloc(sizeof(*hsotg->core_params), GFP_KERNEL);
-  

[PATCH v2 14/22] usb: dwc2: host: register handle to the phy

2015-03-20 Thread Mian Yousaf Kaukab
If phy driver is present register hcd handle to it.

Signed-off-by: Mian Yousaf Kaukab 
---
 drivers/usb/dwc2/hcd.c | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index cc6f394..36f0c69 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -2905,6 +2905,9 @@ int dwc2_hcd_init(struct dwc2_hsotg *hsotg, int irq)
/* Don't support SG list at this point */
hcd->self.sg_tablesize = 0;
 
+   if (!IS_ERR_OR_NULL(hsotg->uphy))
+   otg_set_host(hsotg->uphy->otg, &hcd->self);
+
/*
 * Finish generic HCD initialization and start the HCD. This function
 * allocates the DMA buffer pool, registers the USB bus, requests the
@@ -2958,6 +2961,9 @@ void dwc2_hcd_remove(struct dwc2_hsotg *hsotg)
return;
}
 
+   if (!IS_ERR_OR_NULL(hsotg->uphy))
+   otg_set_host(hsotg->uphy->otg, NULL);
+
usb_remove_hcd(hcd);
hsotg->priv = NULL;
dwc2_hcd_release(hsotg);
-- 
1.9.1

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


[PATCH v2 17/22] usb: dwc2: host: spinlock urb_enqueue

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

During urb_enqueue, if the urb can't be queued to the endpoint,
the urb is freed without any spinlock protection.
This leads to memory corruption when concurrent urb_dequeue try to free
same urb->hcpriv.
Thus, ensure the whole urb_enqueue in spinlocked.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/hcd.c   | 15 ++-
 drivers/usb/dwc2/hcd_queue.c |  8 +---
 2 files changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 0213763..06be7f2 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -349,12 +349,12 @@ void dwc2_hcd_stop(struct dwc2_hsotg *hsotg)
writel(0, hsotg->regs + HPRT0);
 }
 
+/* Caller must hold driver lock */
 static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg,
struct dwc2_hcd_urb *urb, void **ep_handle,
gfp_t mem_flags)
 {
struct dwc2_qtd *qtd;
-   unsigned long flags;
u32 intr_mask;
int retval;
int dev_speed;
@@ -405,11 +405,9 @@ static int dwc2_hcd_urb_enqueue(struct dwc2_hsotg *hsotg,
 */
return 0;
 
-   spin_lock_irqsave(&hsotg->lock, flags);
tr_type = dwc2_hcd_select_transactions(hsotg);
if (tr_type != DWC2_TRANSACTION_NONE)
dwc2_hcd_queue_transactions(hsotg, tr_type);
-   spin_unlock_irqrestore(&hsotg->lock, flags);
}
 
return 0;
@@ -2476,7 +2474,7 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, 
struct urb *urb,
"%s: unaligned transfer with no 
transfer_buffer",
__func__);
retval = -EINVAL;
-   goto fail1;
+   goto fail0;
}
}
 
@@ -2504,7 +2502,6 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, 
struct urb *urb,
 
spin_lock_irqsave(&hsotg->lock, flags);
retval = usb_hcd_link_urb_to_ep(hcd, urb);
-   spin_unlock_irqrestore(&hsotg->lock, flags);
if (retval)
goto fail1;
 
@@ -2513,22 +2510,22 @@ static int _dwc2_hcd_urb_enqueue(struct usb_hcd *hcd, 
struct urb *urb,
goto fail2;
 
if (alloc_bandwidth) {
-   spin_lock_irqsave(&hsotg->lock, flags);
dwc2_allocate_bus_bandwidth(hcd,
dwc2_hcd_get_ep_bandwidth(hsotg, ep),
urb);
-   spin_unlock_irqrestore(&hsotg->lock, flags);
}
 
+   spin_unlock_irqrestore(&hsotg->lock, flags);
+
return 0;
 
 fail2:
-   spin_lock_irqsave(&hsotg->lock, flags);
dwc2_urb->priv = NULL;
usb_hcd_unlink_urb_from_ep(hcd, urb);
-   spin_unlock_irqrestore(&hsotg->lock, flags);
 fail1:
+   spin_unlock_irqrestore(&hsotg->lock, flags);
urb->hcpriv = NULL;
+fail0:
kfree(dwc2_urb);
 
return retval;
diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
index bb97838..63207dc 100644
--- a/drivers/usb/dwc2/hcd_queue.c
+++ b/drivers/usb/dwc2/hcd_queue.c
@@ -761,6 +761,7 @@ void dwc2_hcd_qtd_init(struct dwc2_qtd *qtd, struct 
dwc2_hcd_urb *urb)
 
 /**
  * dwc2_hcd_qtd_add() - Adds a QTD to the QTD-list of a QH
+ * Caller must hold driver lock.
  *
  * @hsotg:The DWC HCD structure
  * @qtd:  The QTD to add
@@ -777,7 +778,6 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct 
dwc2_qtd *qtd,
 struct dwc2_qh **qh, gfp_t mem_flags)
 {
struct dwc2_hcd_urb *urb = qtd->urb;
-   unsigned long flags;
int allocated = 0;
int retval;
 
@@ -792,15 +792,12 @@ int dwc2_hcd_qtd_add(struct dwc2_hsotg *hsotg, struct 
dwc2_qtd *qtd,
allocated = 1;
}
 
-   spin_lock_irqsave(&hsotg->lock, flags);
-
retval = dwc2_hcd_qh_add(hsotg, *qh);
if (retval)
goto fail;
 
qtd->qh = *qh;
list_add_tail(&qtd->qtd_list_entry, &(*qh)->qtd_list);
-   spin_unlock_irqrestore(&hsotg->lock, flags);
 
return 0;
 
@@ -817,10 +814,7 @@ fail:
 qtd_list_entry)
dwc2_hcd_qtd_unlink_and_free(hsotg, qtd2, qh_tmp);
 
-   spin_unlock_irqrestore(&hsotg->lock, flags);
dwc2_hcd_qh_free(hsotg, qh_tmp);
-   } else {
-   spin_unlock_irqrestore(&hsotg->lock, flags);
}
 
return retval;
-- 
1.9.1

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


[PATCH v2 08/22] usb: dwc2: gadget: use reset detect interrupt

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

ResetDet interrupt is used to detect a reset of the bus
while the controller is suspended.
This may happens for example when using Command Verifier.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/gadget.c | 19 ---
 1 file changed, 16 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index bed56dc..d528c02 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -2308,8 +2308,9 @@ void s3c_hsotg_core_init_disconnected(struct dwc2_hsotg 
*hsotg,
writel(GINTSTS_ERLYSUSP | GINTSTS_SESSREQINT |
GINTSTS_GOUTNAKEFF | GINTSTS_GINNAKEFF |
GINTSTS_CONIDSTSCHNG | GINTSTS_USBRST |
-   GINTSTS_ENUMDONE | GINTSTS_OTGINT |
-   GINTSTS_USBSUSP | GINTSTS_WKUPINT,
+   GINTSTS_RESETDET | GINTSTS_ENUMDONE |
+   GINTSTS_OTGINT | GINTSTS_USBSUSP |
+   GINTSTS_WKUPINT,
hsotg->regs + GINTMSK);
 
if (using_dma(hsotg))
@@ -2475,7 +2476,19 @@ irq_retry:
}
}
 
-   if (gintsts & GINTSTS_USBRST) {
+   if (gintsts & GINTSTS_RESETDET) {
+   dev_dbg(hsotg->dev, "%s: USBRstDet\n", __func__);
+
+   writel(GINTSTS_RESETDET, hsotg->regs + GINTSTS);
+
+   /* This event must be used only if controller is suspended */
+   if (hsotg->lx_state == DWC2_L2) {
+   dwc2_exit_hibernation(hsotg, true);
+   hsotg->lx_state = DWC2_L0;
+   }
+   }
+
+   if ((gintsts & GINTSTS_USBRST) || (gintsts & GINTSTS_RESETDET)) {
 
u32 usb_status = readl(hsotg->regs + GOTGCTL);
 
-- 
1.9.1

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


[PATCH v2 18/22] usb: dwc2: host: don't use dma_alloc_coherent with irqs disabled

2015-03-20 Thread Mian Yousaf Kaukab
From: Gregory Herrero 

Align buffer must be allocated using kmalloc since irqs are disabled.
Coherency is handled through dma_map_single which can be used with irqs
disabled.

Signed-off-by: Gregory Herrero 
---
 drivers/usb/dwc2/hcd.c   |  8 +---
 drivers/usb/dwc2/hcd_intr.c  | 10 ++
 drivers/usb/dwc2/hcd_queue.c |  7 ---
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
index 06be7f2..3c8f68c 100644
--- a/drivers/usb/dwc2/hcd.c
+++ b/drivers/usb/dwc2/hcd.c
@@ -711,9 +711,7 @@ static int dwc2_hc_setup_align_buf(struct dwc2_hsotg 
*hsotg, struct dwc2_qh *qh,
/* 3072 = 3 max-size Isoc packets */
buf_size = 3072;
 
-   qh->dw_align_buf = dma_alloc_coherent(hsotg->dev, buf_size,
- &qh->dw_align_buf_dma,
- GFP_ATOMIC);
+   qh->dw_align_buf = kmalloc(buf_size, GFP_ATOMIC);
if (!qh->dw_align_buf)
return -ENOMEM;
qh->dw_align_buf_size = buf_size;
@@ -738,6 +736,10 @@ static int dwc2_hc_setup_align_buf(struct dwc2_hsotg 
*hsotg, struct dwc2_qh *qh,
}
}
 
+   qh->dw_align_buf_dma = dma_map_single(hsotg->dev,
+   qh->dw_align_buf, qh->dw_align_buf_size,
+   chan->ep_is_in ? DMA_FROM_DEVICE : DMA_TO_DEVICE);
+
chan->align_buf = qh->dw_align_buf_dma;
return 0;
 }
diff --git a/drivers/usb/dwc2/hcd_intr.c b/drivers/usb/dwc2/hcd_intr.c
index 6927bba..22f1476 100644
--- a/drivers/usb/dwc2/hcd_intr.c
+++ b/drivers/usb/dwc2/hcd_intr.c
@@ -468,6 +468,8 @@ static int dwc2_update_urb_state(struct dwc2_hsotg *hsotg,
/* Non DWORD-aligned buffer case handling */
if (chan->align_buf && xfer_length && chan->ep_is_in) {
dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
+   chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
   xfer_length);
}
@@ -559,6 +561,8 @@ static enum dwc2_halt_status dwc2_update_isoc_urb_state(
chan->ep_is_in) {
dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
 __func__);
+   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
+   chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
memcpy(urb->buf + frame_desc->offset +
   qtd->isoc_split_offset, chan->qh->dw_align_buf,
   frame_desc->actual_length);
@@ -588,6 +592,8 @@ static enum dwc2_halt_status dwc2_update_isoc_urb_state(
chan->ep_is_in) {
dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n",
 __func__);
+   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
+   chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
memcpy(urb->buf + frame_desc->offset +
   qtd->isoc_split_offset, chan->qh->dw_align_buf,
   frame_desc->actual_length);
@@ -926,6 +932,8 @@ static int dwc2_xfercomp_isoc_split_in(struct dwc2_hsotg 
*hsotg,
 
if (chan->align_buf) {
dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
+   chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
memcpy(qtd->urb->buf + frame_desc->offset +
   qtd->isoc_split_offset, chan->qh->dw_align_buf, len);
}
@@ -1155,6 +1163,8 @@ static void dwc2_update_urb_state_abn(struct dwc2_hsotg 
*hsotg,
/* Non DWORD-aligned buffer case handling */
if (chan->align_buf && xfer_length && chan->ep_is_in) {
dev_vdbg(hsotg->dev, "%s(): non-aligned buffer\n", __func__);
+   dma_unmap_single(hsotg->dev, chan->qh->dw_align_buf_dma,
+   chan->qh->dw_align_buf_size, DMA_FROM_DEVICE);
memcpy(urb->buf + urb->actual_length, chan->qh->dw_align_buf,
   xfer_length);
}
diff --git a/drivers/usb/dwc2/hcd_queue.c b/drivers/usb/dwc2/hcd_queue.c
index 63207dc..3735ae6 100644
--- a/drivers/usb/dwc2/hcd_queue.c
+++ b/drivers/usb/dwc2/hcd_queue.c
@@ -231,9 +231,10 @@ void dwc2_hcd_qh_free(struct dwc2_hsotg *hsotg, struct 
dwc2_qh *qh)
 {
if (hsotg->core_params->dma_desc_enable > 0)
dwc2_hcd_qh_free_ddma(hsotg, qh);
-   else if (qh->dw_align_buf)
-   dma_free_coherent(hsotg->dev, qh->dw_align_b