RE: [PATCH v2] usb: gadget: udc: renesas_usb3: add suspend event support

2019-09-04 Thread Yoshihiro Shimoda
Hi Veeraiyan,

Thank you for the patch!

> From: Veeraiyan Chidambaram, Sent: Wednesday, September 4, 2019 11:48 PM

> --- a/drivers/usb/gadget/udc/renesas_usb3.c
> +++ b/drivers/usb/gadget/udc/renesas_usb3.c
> @@ -767,6 +767,20 @@ static void usb3_irq_epc_int_1_resume(struct 
> renesas_usb3 *usb3)
>   usb3_transition_to_default_state(usb3, false);
>  }
> 
> +static void usb3_irq_epc_int_1_suspend(struct renesas_usb3 *usb3)
> +{
> + usb3_disable_irq_1(usb3, USB_INT_1_B2_SPND);
> +
> + if (usb3->driver &&
> + usb3->driver->suspend &&

As I mentioned on v1 patch [1], I'd like to remove these conditions.
After fixed it,

Reviewed-by: Yoshihiro Shimoda 

[1] https://patchwork.kernel.org/patch/11129797/#22862513

Best regards,
Yoshihiro Shimoda

> + usb3->gadget.speed != USB_SPEED_UNKNOWN &&
> + usb3->gadget.state != USB_STATE_NOTATTACHED) {
> + if (usb3->driver && usb3->driver->suspend)
> + usb3->driver->suspend(&usb3->gadget);
> + usb_gadget_set_state(&usb3->gadget, USB_STATE_SUSPENDED);
> + }
> +}
> +
>  static void usb3_irq_epc_int_1_disable(struct renesas_usb3 *usb3)
>  {
>   usb3_stop_usb3_connection(usb3);
> @@ -852,6 +866,9 @@ static void usb3_irq_epc_int_1(struct renesas_usb3 *usb3, 
> u32 int_sta_1)
>   if (int_sta_1 & USB_INT_1_B2_RSUM)
>   usb3_irq_epc_int_1_resume(usb3);
> 
> + if (int_sta_1 & USB_INT_1_B2_SPND)
> + usb3_irq_epc_int_1_suspend(usb3);
> +
>   if (int_sta_1 & USB_INT_1_SPEED)
>   usb3_irq_epc_int_1_speed(usb3);
> 
> --
> 2.7.4



RE: [PATCH] usb: host: xhci: rcar: Fix typo in compatible string matching

2019-08-27 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Tuesday, August 27, 2019 9:51 PM
> 
> It's spelled "renesas", not "renensas".
> 
> Due to this typo, RZ/G1M and RZ/G1N were not covered by the check.
> 
> Fixes: 2dc240a3308b269a ("usb: host: xhci: rcar: retire use of 
> xhci_plat_type_is()")
> Signed-off-by: Geert Uytterhoeven 

Oops! Thank you for your patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH 1/4] usb: host: xhci-plat: add quirks member into struct xhci_plat_priv

2019-08-27 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Tuesday, August 27, 2019 9:36 PM
> 
> Hi Shimoda-san,
> 
> On Tue, Aug 27, 2019 at 12:05 PM Yoshihiro Shimoda
>  wrote:
> > To simplify adding xhci->quirks instead of the .init_quirk()
> > function, this patch adds a new parameter "quirks" into
> > the struct xhci_plat_priv.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> 
> Reviewed-by: Geert Uytterhoeven 

Thank you for your review!

> > --- a/drivers/usb/host/xhci-plat.h
> > +++ b/drivers/usb/host/xhci-plat.h
> > @@ -12,10 +12,12 @@
> >
> >  struct xhci_plat_priv {
> > const char *firmware_name;
> > +   unsigned long long quirks;
> > void (*plat_start)(struct usb_hcd *);
> > int (*init_quirk)(struct usb_hcd *);
> > int (*resume_quirk)(struct usb_hcd *);
> >  };
> >
> >  #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
> > +#define xhci_to_priv(x) ((struct xhci_plat_priv *)(x)->priv)
> 
> Just wondering: is x->priv guaranteed to be of type struct xhci_plat_priv *,
> also in the future?
> 
> struct xhci_hcd {
> ...
> unsigned long   priv[0] __aligned(sizeof(s64));

It seems so. But, I'm not sure that we can change type of the priv[0] to
struct xhci_plat_priv *, because this implementation is related to all usb_hcd 
drivers:

< Details if you are interested in :) >
--- include/linux/usb/hcd.h ---
struct usb_hcd {
...
/* The HC driver's private data is stored at the end of
 * this structure.
 */
unsigned long hcd_priv[0]
__attribute__ ((aligned(sizeof(s64;
};

--- drivers/usb/host/xhci.c ---
static const struct hc_driver xhci_hc_driver = {
...
.hcd_priv_size =sizeof(struct xhci_hcd),

and

void xhci_init_driver(struct hc_driver *drv,
  const struct xhci_driver_overrides *over)
{
BUG_ON(!over);

/* Copy the generic table to drv then apply the overrides */
*drv = xhci_hc_driver;

if (over) {
drv->hcd_priv_size += over->extra_priv_size;

--- drivers/usb/host/xhci-plat.c ---
static const struct xhci_driver_overrides xhci_plat_overrides __initconst = {
.extra_priv_size = sizeof(struct xhci_plat_priv),

void xhci_init_driver(struct hc_driver *drv,
  const struct xhci_driver_overrides *over)
{
BUG_ON(!over);

/* Copy the generic table to drv then apply the overrides */
*drv = xhci_hc_driver;

if (over) {
drv->hcd_priv_size += over->extra_priv_size;

--- drivers/usb/core/hcd.c ---
struct usb_hcd *__usb_create_hcd(const struct hc_driver *driver,
struct device *sysdev, struct device *dev, const char *bus_name,
struct usb_hcd *primary_hcd)
{
struct usb_hcd *hcd;

hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);
--

Best regards,
Yoshihiro Shimoda

> 
> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds


[PATCH 4/4] usb: host: xhci-rcar: avoid 60s wait by request_firmware() in system booting

2019-08-27 Thread Yoshihiro Shimoda
If CONFIG_FW_LOADER_USER_HELPER_FALLBACK=y and CONFIG_USB_XHCI_RCAR=y,
request_firmware() in xhci_rcar_download_firmware() waits for 60s to
sysfs fallback for the firmware like below.

[1.599701] xhci-hcd ee00.usb: xHCI Host Controller
[1.604948] xhci-hcd ee00.usb: new USB bus registered, assigned bus 
number 3
[1.612403] xhci-hcd ee00.usb: Direct firmware load for 
r8a779x_usb3_v3.dlmem failed with error -2
[1.621726] xhci-hcd ee00.usb: Falling back to sysfs fallback for: 
r8a779x_usb3_v3.dlmem
[1.707953] ata1: link resume succeeded after 1 retries
[1.819379] ata1: SATA link down (SStatus 0 SControl 300)
[   62.436012] xhci-hcd ee00.usb: can't setup: -11
[   62.440901] xhci-hcd ee00.usb: USB bus 3 deregistered
[   62.446361] xhci-hcd: probe of ee00.usb failed with error -11

To avoid this 60s wait, this patch adds to check the system_state
condition and if the system is not running,
xhci_rcar_download_firmware() calls request_firmware_direct()
instead of request_firmware() as a workaround.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/host/xhci-rcar.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 34761be..c90cf46 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -6,6 +6,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -146,7 +147,10 @@ static int xhci_rcar_download_firmware(struct usb_hcd *hcd)
firmware_name = priv->firmware_name;
 
/* request R-Car USB3.0 firmware */
-   retval = request_firmware(&fw, firmware_name, dev);
+   if (system_state < SYSTEM_RUNNING)
+   retval = request_firmware_direct(&fw, firmware_name, dev);
+   else
+   retval = request_firmware(&fw, firmware_name, dev);
if (retval)
return retval;
 
-- 
2.7.4



[PATCH 0/4] usb: host: xhci-{plat,rcar}: clean up and add a workaround

2019-08-27 Thread Yoshihiro Shimoda
This patch series is based on the latest Greg's linux-usb.git /
usb-next branch.

>From patch 1 to 3 are clean-up patches and patch 4 is adding
a workaround code for a specific condition. So, I don't think
the patch 4 is not a fixed patch.

Yoshihiro Shimoda (4):
  usb: host: xhci-plat: add quirks member into struct xhci_plat_priv
  usb: host: xhci-rcar: Add a helper macro to set xhci_plat_priv
  usb: host: xhci-rcar: Use xhci_plat_priv.quirks instead of code
settings
  usb: host: xhci-rcar: avoid 60s wait by request_firmware() in system
booting

 drivers/usb/host/xhci-plat.c | 14 +-
 drivers/usb/host/xhci-plat.h |  2 ++
 drivers/usb/host/xhci-rcar.c | 34 +-
 drivers/usb/host/xhci-rcar.h | 21 +
 4 files changed, 33 insertions(+), 38 deletions(-)

-- 
2.7.4



[PATCH 3/4] usb: host: xhci-rcar: Use xhci_plat_priv.quirks instead of code settings

2019-08-27 Thread Yoshihiro Shimoda
This patch uses xhci_plat_priv.quirks to simplify. The previous
code had conditions to set some quirks in xhci_rcar_init_quirk().
But, the xhci_rcar_init_quirk() is called at the same conditions.
So, no behavior change.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/host/xhci-rcar.c | 28 
 drivers/usb/host/xhci-rcar.h | 14 ++
 2 files changed, 14 insertions(+), 28 deletions(-)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 8616c52..34761be 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -107,15 +107,6 @@ static int xhci_rcar_is_gen2(struct device *dev)
of_device_is_compatible(node, "renensas,rcar-gen2-xhci");
 }
 
-static int xhci_rcar_is_gen3(struct device *dev)
-{
-   struct device_node *node = dev->of_node;
-
-   return of_device_is_compatible(node, "renesas,xhci-r8a7795") ||
-   of_device_is_compatible(node, "renesas,xhci-r8a7796") ||
-   of_device_is_compatible(node, "renesas,rcar-gen3-xhci");
-}
-
 void xhci_rcar_start(struct usb_hcd *hcd)
 {
u32 temp;
@@ -226,32 +217,13 @@ static bool xhci_rcar_wait_for_pll_active(struct usb_hcd 
*hcd)
 /* This function needs to initialize a "phy" of usb before */
 int xhci_rcar_init_quirk(struct usb_hcd *hcd)
 {
-   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
-
/* If hcd->regs is NULL, we don't just call the following function */
if (!hcd->regs)
return 0;
 
-   /*
-* On R-Car Gen2 and Gen3, the AC64 bit (bit 0) of HCCPARAMS1 is set
-* to 1. However, these SoCs don't support 64-bit address memory
-* pointers. So, this driver clears the AC64 bit of xhci->hcc_params
-* to call dma_set_coherent_mask(dev, DMA_BIT_MASK(32)) in
-* xhci_gen_setup().
-*
-* And, since the firmware/internal CPU control the USBSTS.STS_HALT
-* and the process speed is down when the roothub port enters U3,
-* long delay for the handshake of STS_HALT is neeed in xhci_suspend().
-*/
-   if (xhci_rcar_is_gen2(hcd->self.controller) ||
-   xhci_rcar_is_gen3(hcd->self.controller)) {
-   xhci->quirks |= XHCI_NO_64BIT_SUPPORT | XHCI_SLOW_SUSPEND;
-   }
-
if (!xhci_rcar_wait_for_pll_active(hcd))
return -ETIMEDOUT;
 
-   xhci->quirks |= XHCI_TRUST_TX_LENGTH;
return xhci_rcar_download_firmware(hcd);
 }
 
diff --git a/drivers/usb/host/xhci-rcar.h b/drivers/usb/host/xhci-rcar.h
index 1f8c225..012744a 100644
--- a/drivers/usb/host/xhci-rcar.h
+++ b/drivers/usb/host/xhci-rcar.h
@@ -32,8 +32,22 @@ static inline int xhci_rcar_resume_quirk(struct usb_hcd *hcd)
 }
 #endif
 
+/*
+ * On R-Car Gen2 and Gen3, the AC64 bit (bit 0) of HCCPARAMS1 is set
+ * to 1. However, these SoCs don't support 64-bit address memory
+ * pointers. So, this driver clears the AC64 bit of xhci->hcc_params
+ * to call dma_set_coherent_mask(dev, DMA_BIT_MASK(32)) in
+ * xhci_gen_setup() by using the XHCI_NO_64BIT_SUPPORT quirk.
+ *
+ * And, since the firmware/internal CPU control the USBSTS.STS_HALT
+ * and the process speed is down when the roothub port enters U3,
+ * long delay for the handshake of STS_HALT is neeed in xhci_suspend()
+ * by using the XHCI_SLOW_SUSPEND quirk.
+ */
 #define SET_XHCI_PLAT_PRIV_FOR_RCAR(firmware)  \
.firmware_name = firmware,  \
+   .quirks = XHCI_NO_64BIT_SUPPORT | XHCI_TRUST_TX_LENGTH |\
+ XHCI_SLOW_SUSPEND,\
.init_quirk = xhci_rcar_init_quirk, \
.plat_start = xhci_rcar_start,  \
.resume_quirk = xhci_rcar_resume_quirk,
-- 
2.7.4



[PATCH 2/4] usb: host: xhci-rcar: Add a helper macro to set xhci_plat_priv

2019-08-27 Thread Yoshihiro Shimoda
To avoid copy-and-paste setting of xhci_plat_priv for R-Car SoCs,
this patch add a helper macro SET_XHCI_PLAT_PRIV_FOR_RCAR.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/host/xhci-plat.c | 10 ++
 drivers/usb/host/xhci-rcar.h |  7 +++
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index 1843b69..d90cd5e 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -105,17 +105,11 @@ static const struct xhci_plat_priv 
xhci_plat_marvell_armada3700 = {
 };
 
 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = {
-   .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V1,
-   .init_quirk = xhci_rcar_init_quirk,
-   .plat_start = xhci_rcar_start,
-   .resume_quirk = xhci_rcar_resume_quirk,
+   SET_XHCI_PLAT_PRIV_FOR_RCAR(XHCI_RCAR_FIRMWARE_NAME_V1)
 };
 
 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
-   .firmware_name = XHCI_RCAR_FIRMWARE_NAME_V3,
-   .init_quirk = xhci_rcar_init_quirk,
-   .plat_start = xhci_rcar_start,
-   .resume_quirk = xhci_rcar_resume_quirk,
+   SET_XHCI_PLAT_PRIV_FOR_RCAR(XHCI_RCAR_FIRMWARE_NAME_V3)
 };
 
 static const struct of_device_id usb_xhci_of_match[] = {
diff --git a/drivers/usb/host/xhci-rcar.h b/drivers/usb/host/xhci-rcar.h
index 804b6ab..1f8c225 100644
--- a/drivers/usb/host/xhci-rcar.h
+++ b/drivers/usb/host/xhci-rcar.h
@@ -31,4 +31,11 @@ static inline int xhci_rcar_resume_quirk(struct usb_hcd *hcd)
return 0;
 }
 #endif
+
+#define SET_XHCI_PLAT_PRIV_FOR_RCAR(firmware)  \
+   .firmware_name = firmware,  \
+   .init_quirk = xhci_rcar_init_quirk, \
+   .plat_start = xhci_rcar_start,  \
+   .resume_quirk = xhci_rcar_resume_quirk,
+
 #endif /* _XHCI_RCAR_H */
-- 
2.7.4



[PATCH 1/4] usb: host: xhci-plat: add quirks member into struct xhci_plat_priv

2019-08-27 Thread Yoshihiro Shimoda
To simplify adding xhci->quirks instead of the .init_quirk()
function, this patch adds a new parameter "quirks" into
the struct xhci_plat_priv.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/host/xhci-plat.c | 4 +++-
 drivers/usb/host/xhci-plat.h | 2 ++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index a1e5ce4..1843b69 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -66,12 +66,14 @@ static int xhci_priv_resume_quirk(struct usb_hcd *hcd)
 
 static void xhci_plat_quirks(struct device *dev, struct xhci_hcd *xhci)
 {
+   struct xhci_plat_priv *priv = xhci_to_priv(xhci);
+
/*
 * As of now platform drivers don't provide MSI support so we ensure
 * here that the generic code does not try to make a pci_dev from our
 * dev struct in order to setup MSI
 */
-   xhci->quirks |= XHCI_PLAT;
+   xhci->quirks |= XHCI_PLAT | priv->quirks;
 }
 
 /* called during probe() after chip reset completes */
diff --git a/drivers/usb/host/xhci-plat.h b/drivers/usb/host/xhci-plat.h
index ae29f22..5681723 100644
--- a/drivers/usb/host/xhci-plat.h
+++ b/drivers/usb/host/xhci-plat.h
@@ -12,10 +12,12 @@
 
 struct xhci_plat_priv {
const char *firmware_name;
+   unsigned long long quirks;
void (*plat_start)(struct usb_hcd *);
int (*init_quirk)(struct usb_hcd *);
int (*resume_quirk)(struct usb_hcd *);
 };
 
 #define hcd_to_xhci_priv(h) ((struct xhci_plat_priv *)hcd_to_xhci(h)->priv)
+#define xhci_to_priv(x) ((struct xhci_plat_priv *)(x)->priv)
 #endif /* _XHCI_PLAT_H */
-- 
2.7.4



[PATCH v3] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-26 Thread Yoshihiro Shimoda
This patch fixes an issue that the following error is
possible to happen when ohci hardware causes an interruption
and the system is shutting down at the same time.

[   34.851754] usb 2-1: USB disconnect, device number 2
[   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
[   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
[   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on 
r8a77965 (DT)
[   35.187886] Workqueue: usb_hub_wq hub_event
[   35.192063] Call trace:
[   35.194509]  dump_backtrace+0x0/0x150
[   35.198165]  show_stack+0x14/0x20
[   35.201475]  dump_stack+0xa0/0xc4
[   35.204785]  __report_bad_irq+0x34/0xe8
[   35.208614]  note_interrupt+0x2cc/0x318
[   35.212446]  handle_irq_event_percpu+0x5c/0x88
[   35.216883]  handle_irq_event+0x48/0x78
[   35.220712]  handle_fasteoi_irq+0xb4/0x188
[   35.224802]  generic_handle_irq+0x24/0x38
[   35.228804]  __handle_domain_irq+0x5c/0xb0
[   35.232893]  gic_handle_irq+0x58/0xa8
[   35.236548]  el1_irq+0xb8/0x180
[   35.239681]  __do_softirq+0x94/0x23c
[   35.243253]  irq_exit+0xd0/0xd8
[   35.246387]  __handle_domain_irq+0x60/0xb0
[   35.250475]  gic_handle_irq+0x58/0xa8
[   35.254130]  el1_irq+0xb8/0x180
[   35.257268]  kernfs_find_ns+0x5c/0x120
[   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
[   35.265361]  sysfs_unmerge_group+0x20/0x68
[   35.269454]  dpm_sysfs_remove+0x2c/0x68
[   35.273284]  device_del+0x80/0x370
[   35.276683]  hid_destroy_device+0x28/0x60
[   35.280686]  usbhid_disconnect+0x4c/0x80
[   35.284602]  usb_unbind_interface+0x6c/0x268
[   35.288867]  device_release_driver_internal+0xe4/0x1b0
[   35.293998]  device_release_driver+0x14/0x20
[   35.298261]  bus_remove_device+0x110/0x128
[   35.302350]  device_del+0x148/0x370
[   35.305832]  usb_disable_device+0x8c/0x1d0
[   35.309921]  usb_disconnect+0xc8/0x2d0
[   35.313663]  hub_event+0x6e0/0x1128
[   35.317146]  process_one_work+0x1e0/0x320
[   35.321148]  worker_thread+0x40/0x450
[   35.324805]  kthread+0x124/0x128
[   35.328027]  ret_from_fork+0x10/0x18
[   35.331594] handlers:
[   35.333862] [<79300c1d>] usb_hcd_irq
[   35.338126] [<79300c1d>] usb_hcd_irq
[   35.342389] Disabling IRQ #156

ohci_shutdown() disables all the interrupt and rh_state is set to
OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
is possible to be set by start_ed_unlink() which is called:
 ohci_irq()
  -> process_done_list()
   -> takeback_td()
-> start_ed_unlink()

So, ohci_irq() has the following condition, the issue happens by
&ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
ohci->rh_state = OHCI_RH_HALTED:

/* interrupt for some other device? */
if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
return IRQ_NOTMINE;

To fix the issue, ohci_shutdown() holds the spin lock while disabling
the interruption and changing the rh_state flag to prevent reenable
the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also
calls the ohci_shutdown() and it already held the spin lock, so that
the patch makes a new function as _ohci_shutdown().

This patch is inspired by a Renesas R-Car Gen3 BSP patch
from Tho Vu.

Signed-off-by: Yoshihiro Shimoda 
---
Changes from v2:
 - Since a sentence is lacked on v2, revise the commit log.
https://patchwork.kernel.org/patch/5947/

Changes from v1:
 - Add more comments in the commit log.
https://patchwork.kernel.org/patch/1459/

 drivers/usb/host/ohci-hcd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b457fda..1fe3dee 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -419,8 +419,7 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
  * other cases where the next software may expect clean state from the
  * "firmware".  this is bus-neutral, unlike shutdown() methods.
  */
-static void
-ohci_shutdown (struct usb_hcd *hcd)
+static void _ohci_shutdown(struct usb_hcd *hcd)
 {
struct ohci_hcd *ohci;
 
@@ -436,6 +435,16 @@ ohci_shutdown (struct usb_hcd *hcd)
ohci->rh_state = OHCI_RH_HALTED;
 }
 
+static void ohci_shutdown(struct usb_hcd *hcd)
+{
+   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   unsigned long flags;
+
+   spin_lock_irqsave(&ohci->lock, flags);
+   _ohci_shutdown(hcd);
+   spin_unlock_irqrestore(&ohci->lock, flags);
+}
+
 /*-*
  * HC functions
  *-*/
@@ -760,7 +769,7 @@ static void io_watchdog_func(struct timer_list *t)
  died:
usb_hc_died(ohci_to_hcd(ohci));
ohci_dump(ohci);
-   ohci_shutdown(o

RE: [PATCH v2] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-26 Thread Yoshihiro Shimoda
Hi Greg, Alan,

I'm afraid but, I would like to recall this patch because
I lacked the last sentence in the commit log.
I'll submit v3 patch soon.

Best regards,
Yoshihiro Shimoda

> -Original Message-
> From: Yoshihiro Shimoda 
> Sent: Tuesday, August 27, 2019 10:57 AM
> To: gre...@linuxfoundation.org; st...@rowland.harvard.edu
> Cc: linux-usb@vger.kernel.org; linux-renesas-...@vger.kernel.org; Yoshihiro 
> Shimoda 
> Subject: [PATCH v2] usb: host: ohci: fix a race condition between shutdown 
> and irq
> 
> This patch fixes an issue that the following error is
> possible to happen when ohci hardware causes an interruption
> and the system is shutting down at the same time.
> 
> [   34.851754] usb 2-1: USB disconnect, device number 2
> [   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
> [   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
> [   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on 
> r8a77965 (DT)
> [   35.187886] Workqueue: usb_hub_wq hub_event
> [   35.192063] Call trace:
> [   35.194509]  dump_backtrace+0x0/0x150
> [   35.198165]  show_stack+0x14/0x20
> [   35.201475]  dump_stack+0xa0/0xc4
> [   35.204785]  __report_bad_irq+0x34/0xe8
> [   35.208614]  note_interrupt+0x2cc/0x318
> [   35.212446]  handle_irq_event_percpu+0x5c/0x88
> [   35.216883]  handle_irq_event+0x48/0x78
> [   35.220712]  handle_fasteoi_irq+0xb4/0x188
> [   35.224802]  generic_handle_irq+0x24/0x38
> [   35.228804]  __handle_domain_irq+0x5c/0xb0
> [   35.232893]  gic_handle_irq+0x58/0xa8
> [   35.236548]  el1_irq+0xb8/0x180
> [   35.239681]  __do_softirq+0x94/0x23c
> [   35.243253]  irq_exit+0xd0/0xd8
> [   35.246387]  __handle_domain_irq+0x60/0xb0
> [   35.250475]  gic_handle_irq+0x58/0xa8
> [   35.254130]  el1_irq+0xb8/0x180
> [   35.257268]  kernfs_find_ns+0x5c/0x120
> [   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
> [   35.265361]  sysfs_unmerge_group+0x20/0x68
> [   35.269454]  dpm_sysfs_remove+0x2c/0x68
> [   35.273284]  device_del+0x80/0x370
> [   35.276683]  hid_destroy_device+0x28/0x60
> [   35.280686]  usbhid_disconnect+0x4c/0x80
> [   35.284602]  usb_unbind_interface+0x6c/0x268
> [   35.288867]  device_release_driver_internal+0xe4/0x1b0
> [   35.293998]  device_release_driver+0x14/0x20
> [   35.298261]  bus_remove_device+0x110/0x128
> [   35.302350]  device_del+0x148/0x370
> [   35.305832]  usb_disable_device+0x8c/0x1d0
> [   35.309921]  usb_disconnect+0xc8/0x2d0
> [   35.313663]  hub_event+0x6e0/0x1128
> [   35.317146]  process_one_work+0x1e0/0x320
> [   35.321148]  worker_thread+0x40/0x450
> [   35.324805]  kthread+0x124/0x128
> [   35.328027]  ret_from_fork+0x10/0x18
> [   35.331594] handlers:
> [   35.333862] [<79300c1d>] usb_hcd_irq
> [   35.338126] [<79300c1d>] usb_hcd_irq
> [   35.342389] Disabling IRQ #156
> 
> ohci_shutdown() disables all the interrupt and rh_state is set to
> OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
> OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
> is possible to be set by start_ed_unlink() which is called:
>  ohci_irq()
>   -> process_done_list()
>-> takeback_td()
> -> start_ed_unlink()
> 
> So, ohci_irq() has the following condition, the issue happens by
> &ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
> ohci->rh_state = OHCI_RH_HALTED:
> 
>   /* interrupt for some other device? */
>   if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
>   return IRQ_NOTMINE;
> 
> To fix the issue, ohci_shutdown() holds the spin lock while disabling
> the interruption and changing the rh_state flag to prevent reenable
> the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also
> calls the ohci_shutdown() and it already held the spin lock, so that
> the patch makes a new function as _ohci_shutdown().
> 
> Signed-off-by: Yoshihiro Shimoda 
> ---
> Changes from v1:
>  - Add more comments in the commit log.
> https://patchwork.kernel.org/patch/1459/
> 
>  drivers/usb/host/ohci-hcd.c | 15 ---
>  1 file changed, 12 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
> index b457fda..1fe3dee 100644
> --- a/drivers/usb/host/ohci-hcd.c
> +++ b/drivers/usb/host/ohci-hcd.c
> @@ -419,8 +419,7 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
>   * other cases where the next software may expect clean state from the
>   * "firmware".  this is bus-neutral, unlike shutdown() methods.
>   */
> -static void
> -ohci_shutdown (struct usb_hcd *hcd)
> +static void _ohci_shutdown(

RE: [PATCH] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-26 Thread Yoshihiro Shimoda
Hi Alan,

> From: Alan Stern, Sent: Tuesday, August 27, 2019 12:58 AM
> 
> On Mon, 26 Aug 2019, Yoshihiro Shimoda wrote:
> 
> > Hi Alan,
> >
> > > From: Alan Stern, Sent: Saturday, August 24, 2019 12:33 AM
> > >
> > > On Fri, 23 Aug 2019, Yoshihiro Shimoda wrote:

> > > > The ohci_shutdown() should hold the spin lock while disabling
> > > > the interruption and changing the rh_state flag. Note that
> > > > io_watchdog_func() also calls the ohci_shutdown() and it
> > > > already held the spin lock, so that the patch makes a new
> > > > function as _ohci_shutdown().
> > >
> > > I don't understand this description.  It sounds like the OHCI
> > > controller generates an interrupt request, and then ohci_shutdown()
> > > disables the interrupt request before the handler can run.  When the
> > > handler does run, it sees that no interrupts are enabled and so it
> > > returns IRQ_NOTMINE, leading to the error shown above.
> > >
> > > How will holding the spinlock fix this problem?
> >
> > I'm sorry for lacking description. I should have described the following
> > descriptions instead of that. What do you think?
> >
> > --
> > ohci_shutdown() disables all the interrupt and rh_state is set to
> > OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
> > OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
> > is possible to be set by start_ed_unlink() which is called:
> >  ohci_irq()
> >   -> process_done_list()
> >-> takeback_td()
> > -> start_ed_unlink()
> >
> > So, ohci_irq() has the following condition, the issue happens by
> > &ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
> > ohci->rh_state = OHCI_RH_HALTED:
> >
> > /* interrupt for some other device? */
> > if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
> > return IRQ_NOTMINE;
> >
> > To fix the issue, ohci_shutdown() holds the spin lock while disabling
> > the interruption and changing the rh_state flag to prevent reenable
> > the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also calls
> > the ohci_shutdown() and it already held the spin lock, so that the patch
> > makes a new function as _ohci_shutdown().
> 
> Okay, that's a lot better.  Please resubmit the patch with the new
> description.

Thank you for your review! I have submitted v2 patch as the following:
https://patchwork.kernel.org/patch/5947/

Best regards,
Yoshihiro Shimoda



[PATCH v2] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-26 Thread Yoshihiro Shimoda
This patch fixes an issue that the following error is
possible to happen when ohci hardware causes an interruption
and the system is shutting down at the same time.

[   34.851754] usb 2-1: USB disconnect, device number 2
[   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
[   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
[   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on 
r8a77965 (DT)
[   35.187886] Workqueue: usb_hub_wq hub_event
[   35.192063] Call trace:
[   35.194509]  dump_backtrace+0x0/0x150
[   35.198165]  show_stack+0x14/0x20
[   35.201475]  dump_stack+0xa0/0xc4
[   35.204785]  __report_bad_irq+0x34/0xe8
[   35.208614]  note_interrupt+0x2cc/0x318
[   35.212446]  handle_irq_event_percpu+0x5c/0x88
[   35.216883]  handle_irq_event+0x48/0x78
[   35.220712]  handle_fasteoi_irq+0xb4/0x188
[   35.224802]  generic_handle_irq+0x24/0x38
[   35.228804]  __handle_domain_irq+0x5c/0xb0
[   35.232893]  gic_handle_irq+0x58/0xa8
[   35.236548]  el1_irq+0xb8/0x180
[   35.239681]  __do_softirq+0x94/0x23c
[   35.243253]  irq_exit+0xd0/0xd8
[   35.246387]  __handle_domain_irq+0x60/0xb0
[   35.250475]  gic_handle_irq+0x58/0xa8
[   35.254130]  el1_irq+0xb8/0x180
[   35.257268]  kernfs_find_ns+0x5c/0x120
[   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
[   35.265361]  sysfs_unmerge_group+0x20/0x68
[   35.269454]  dpm_sysfs_remove+0x2c/0x68
[   35.273284]  device_del+0x80/0x370
[   35.276683]  hid_destroy_device+0x28/0x60
[   35.280686]  usbhid_disconnect+0x4c/0x80
[   35.284602]  usb_unbind_interface+0x6c/0x268
[   35.288867]  device_release_driver_internal+0xe4/0x1b0
[   35.293998]  device_release_driver+0x14/0x20
[   35.298261]  bus_remove_device+0x110/0x128
[   35.302350]  device_del+0x148/0x370
[   35.305832]  usb_disable_device+0x8c/0x1d0
[   35.309921]  usb_disconnect+0xc8/0x2d0
[   35.313663]  hub_event+0x6e0/0x1128
[   35.317146]  process_one_work+0x1e0/0x320
[   35.321148]  worker_thread+0x40/0x450
[   35.324805]  kthread+0x124/0x128
[   35.328027]  ret_from_fork+0x10/0x18
[   35.331594] handlers:
[   35.333862] [<79300c1d>] usb_hcd_irq
[   35.338126] [<79300c1d>] usb_hcd_irq
[   35.342389] Disabling IRQ #156

ohci_shutdown() disables all the interrupt and rh_state is set to
OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
is possible to be set by start_ed_unlink() which is called:
 ohci_irq()
  -> process_done_list()
   -> takeback_td()
-> start_ed_unlink()

So, ohci_irq() has the following condition, the issue happens by
&ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
ohci->rh_state = OHCI_RH_HALTED:

/* interrupt for some other device? */
if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
return IRQ_NOTMINE;

To fix the issue, ohci_shutdown() holds the spin lock while disabling
the interruption and changing the rh_state flag to prevent reenable
the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also
calls the ohci_shutdown() and it already held the spin lock, so that
the patch makes a new function as _ohci_shutdown().

Signed-off-by: Yoshihiro Shimoda 
---
Changes from v1:
 - Add more comments in the commit log.
https://patchwork.kernel.org/patch/1459/

 drivers/usb/host/ohci-hcd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b457fda..1fe3dee 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -419,8 +419,7 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
  * other cases where the next software may expect clean state from the
  * "firmware".  this is bus-neutral, unlike shutdown() methods.
  */
-static void
-ohci_shutdown (struct usb_hcd *hcd)
+static void _ohci_shutdown(struct usb_hcd *hcd)
 {
struct ohci_hcd *ohci;
 
@@ -436,6 +435,16 @@ ohci_shutdown (struct usb_hcd *hcd)
ohci->rh_state = OHCI_RH_HALTED;
 }
 
+static void ohci_shutdown(struct usb_hcd *hcd)
+{
+   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   unsigned long flags;
+
+   spin_lock_irqsave(&ohci->lock, flags);
+   _ohci_shutdown(hcd);
+   spin_unlock_irqrestore(&ohci->lock, flags);
+}
+
 /*-*
  * HC functions
  *-*/
@@ -760,7 +769,7 @@ static void io_watchdog_func(struct timer_list *t)
  died:
usb_hc_died(ohci_to_hcd(ohci));
ohci_dump(ohci);
-   ohci_shutdown(ohci_to_hcd(ohci));
+   _ohci_shutdown(ohci_to_hcd(ohci));
goto done;
} else {
/* No write back because the done queue was empty */
-- 
2.7.4



RE: [PATCH] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-25 Thread Yoshihiro Shimoda
Hi Alan,

> From: Alan Stern, Sent: Saturday, August 24, 2019 12:33 AM
> 
> On Fri, 23 Aug 2019, Yoshihiro Shimoda wrote:
> 
> > This patch fixes an issue that the following error is
> > possible to happen when ohci hardware causes an interruption
> > and the system is shutting down at the same time.
> >
> > [   34.851754] usb 2-1: USB disconnect, device number 2
> > [   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
> > [   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
> > [   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on 
> > r8a77965 (DT)
> > [   35.187886] Workqueue: usb_hub_wq hub_event
> > [   35.192063] Call trace:
> > [   35.194509]  dump_backtrace+0x0/0x150
> > [   35.198165]  show_stack+0x14/0x20
> > [   35.201475]  dump_stack+0xa0/0xc4
> > [   35.204785]  __report_bad_irq+0x34/0xe8
> > [   35.208614]  note_interrupt+0x2cc/0x318
> > [   35.212446]  handle_irq_event_percpu+0x5c/0x88
> > [   35.216883]  handle_irq_event+0x48/0x78
> > [   35.220712]  handle_fasteoi_irq+0xb4/0x188
> > [   35.224802]  generic_handle_irq+0x24/0x38
> > [   35.228804]  __handle_domain_irq+0x5c/0xb0
> > [   35.232893]  gic_handle_irq+0x58/0xa8
> > [   35.236548]  el1_irq+0xb8/0x180
> > [   35.239681]  __do_softirq+0x94/0x23c
> > [   35.243253]  irq_exit+0xd0/0xd8
> > [   35.246387]  __handle_domain_irq+0x60/0xb0
> > [   35.250475]  gic_handle_irq+0x58/0xa8
> > [   35.254130]  el1_irq+0xb8/0x180
> > [   35.257268]  kernfs_find_ns+0x5c/0x120
> > [   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
> > [   35.265361]  sysfs_unmerge_group+0x20/0x68
> > [   35.269454]  dpm_sysfs_remove+0x2c/0x68
> > [   35.273284]  device_del+0x80/0x370
> > [   35.276683]  hid_destroy_device+0x28/0x60
> > [   35.280686]  usbhid_disconnect+0x4c/0x80
> > [   35.284602]  usb_unbind_interface+0x6c/0x268
> > [   35.288867]  device_release_driver_internal+0xe4/0x1b0
> > [   35.293998]  device_release_driver+0x14/0x20
> > [   35.298261]  bus_remove_device+0x110/0x128
> > [   35.302350]  device_del+0x148/0x370
> > [   35.305832]  usb_disable_device+0x8c/0x1d0
> > [   35.309921]  usb_disconnect+0xc8/0x2d0
> > [   35.313663]  hub_event+0x6e0/0x1128
> > [   35.317146]  process_one_work+0x1e0/0x320
> > [   35.321148]  worker_thread+0x40/0x450
> > [   35.324805]  kthread+0x124/0x128
> > [   35.328027]  ret_from_fork+0x10/0x18
> > [   35.331594] handlers:
> > [   35.333862] [<79300c1d>] usb_hcd_irq
> > [   35.338126] [<79300c1d>] usb_hcd_irq
> > [   35.342389] Disabling IRQ #156
> >
> > The ohci_shutdown() should hold the spin lock while disabling
> > the interruption and changing the rh_state flag. Note that
> > io_watchdog_func() also calls the ohci_shutdown() and it
> > already held the spin lock, so that the patch makes a new
> > function as _ohci_shutdown().
> 
> I don't understand this description.  It sounds like the OHCI
> controller generates an interrupt request, and then ohci_shutdown()
> disables the interrupt request before the handler can run.  When the
> handler does run, it sees that no interrupts are enabled and so it
> returns IRQ_NOTMINE, leading to the error shown above.
> 
> How will holding the spinlock fix this problem?

I'm sorry for lacking description. I should have described the following
descriptions instead of that. What do you think?

--
ohci_shutdown() disables all the interrupt and rh_state is set to
OHCI_RH_HALTED. In other hand, ohci_irq() is possible to enable
OHCI_INTR_SF and OHCI_INTR_MIE on ohci_irq(). Note that OHCI_INTR_SF
is possible to be set by start_ed_unlink() which is called:
 ohci_irq()
  -> process_done_list()
   -> takeback_td()
-> start_ed_unlink()

So, ohci_irq() has the following condition, the issue happens by
&ohci->regs->intrenable = OHCI_INTR_MIE | OHCI_INTR_SF and
ohci->rh_state = OHCI_RH_HALTED:

/* interrupt for some other device? */
if (ints == 0 || unlikely(ohci->rh_state == OHCI_RH_HALTED))
return IRQ_NOTMINE;

To fix the issue, ohci_shutdown() holds the spin lock while disabling
the interruption and changing the rh_state flag to prevent reenable
the OHCI_INTR_MIE unexpectedly. Note that io_watchdog_func() also calls
the ohci_shutdown() and it already held the spin lock, so that the patch
makes a new function as _ohci_shutdown().
--

Best regards,
Yoshihiro Shimoda

> Alan Stern



[PATCH] usb: host: ohci: fix a race condition between shutdown and irq

2019-08-23 Thread Yoshihiro Shimoda
This patch fixes an issue that the following error is
possible to happen when ohci hardware causes an interruption
and the system is shutting down at the same time.

[   34.851754] usb 2-1: USB disconnect, device number 2
[   35.166658] irq 156: nobody cared (try booting with the "irqpoll" option)
[   35.173445] CPU: 0 PID: 22 Comm: kworker/0:1 Not tainted 5.3.0-rc5 #85
[   35.179964] Hardware name: Renesas Salvator-X 2nd version board based on 
r8a77965 (DT)
[   35.187886] Workqueue: usb_hub_wq hub_event
[   35.192063] Call trace:
[   35.194509]  dump_backtrace+0x0/0x150
[   35.198165]  show_stack+0x14/0x20
[   35.201475]  dump_stack+0xa0/0xc4
[   35.204785]  __report_bad_irq+0x34/0xe8
[   35.208614]  note_interrupt+0x2cc/0x318
[   35.212446]  handle_irq_event_percpu+0x5c/0x88
[   35.216883]  handle_irq_event+0x48/0x78
[   35.220712]  handle_fasteoi_irq+0xb4/0x188
[   35.224802]  generic_handle_irq+0x24/0x38
[   35.228804]  __handle_domain_irq+0x5c/0xb0
[   35.232893]  gic_handle_irq+0x58/0xa8
[   35.236548]  el1_irq+0xb8/0x180
[   35.239681]  __do_softirq+0x94/0x23c
[   35.243253]  irq_exit+0xd0/0xd8
[   35.246387]  __handle_domain_irq+0x60/0xb0
[   35.250475]  gic_handle_irq+0x58/0xa8
[   35.254130]  el1_irq+0xb8/0x180
[   35.257268]  kernfs_find_ns+0x5c/0x120
[   35.261010]  kernfs_find_and_get_ns+0x3c/0x60
[   35.265361]  sysfs_unmerge_group+0x20/0x68
[   35.269454]  dpm_sysfs_remove+0x2c/0x68
[   35.273284]  device_del+0x80/0x370
[   35.276683]  hid_destroy_device+0x28/0x60
[   35.280686]  usbhid_disconnect+0x4c/0x80
[   35.284602]  usb_unbind_interface+0x6c/0x268
[   35.288867]  device_release_driver_internal+0xe4/0x1b0
[   35.293998]  device_release_driver+0x14/0x20
[   35.298261]  bus_remove_device+0x110/0x128
[   35.302350]  device_del+0x148/0x370
[   35.305832]  usb_disable_device+0x8c/0x1d0
[   35.309921]  usb_disconnect+0xc8/0x2d0
[   35.313663]  hub_event+0x6e0/0x1128
[   35.317146]  process_one_work+0x1e0/0x320
[   35.321148]  worker_thread+0x40/0x450
[   35.324805]  kthread+0x124/0x128
[   35.328027]  ret_from_fork+0x10/0x18
[   35.331594] handlers:
[   35.333862] [<79300c1d>] usb_hcd_irq
[   35.338126] [<79300c1d>] usb_hcd_irq
[   35.342389] Disabling IRQ #156

The ohci_shutdown() should hold the spin lock while disabling
the interruption and changing the rh_state flag. Note that
io_watchdog_func() also calls the ohci_shutdown() and it
already held the spin lock, so that the patch makes a new
function as _ohci_shutdown().

This patch is inspired by a Renesas R-Car Gen3 BSP patch
from Tho Vu.

Signed-off-by: Yoshihiro Shimoda 
---
 I think I should have added "Fixes:" tag on the patch, but
 I have no idea how to find the suitable commit...

 drivers/usb/host/ohci-hcd.c | 15 ---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/ohci-hcd.c b/drivers/usb/host/ohci-hcd.c
index b457fda..1fe3dee 100644
--- a/drivers/usb/host/ohci-hcd.c
+++ b/drivers/usb/host/ohci-hcd.c
@@ -419,8 +419,7 @@ static void ohci_usb_reset (struct ohci_hcd *ohci)
  * other cases where the next software may expect clean state from the
  * "firmware".  this is bus-neutral, unlike shutdown() methods.
  */
-static void
-ohci_shutdown (struct usb_hcd *hcd)
+static void _ohci_shutdown(struct usb_hcd *hcd)
 {
struct ohci_hcd *ohci;
 
@@ -436,6 +435,16 @@ ohci_shutdown (struct usb_hcd *hcd)
ohci->rh_state = OHCI_RH_HALTED;
 }
 
+static void ohci_shutdown(struct usb_hcd *hcd)
+{
+   struct ohci_hcd *ohci = hcd_to_ohci(hcd);
+   unsigned long flags;
+
+   spin_lock_irqsave(&ohci->lock, flags);
+   _ohci_shutdown(hcd);
+   spin_unlock_irqrestore(&ohci->lock, flags);
+}
+
 /*-*
  * HC functions
  *-*/
@@ -760,7 +769,7 @@ static void io_watchdog_func(struct timer_list *t)
  died:
usb_hc_died(ohci_to_hcd(ohci));
ohci_dump(ohci);
-   ohci_shutdown(ohci_to_hcd(ohci));
+   _ohci_shutdown(ohci_to_hcd(ohci));
goto done;
} else {
/* No write back because the done queue was empty */
-- 
2.7.4



[PATCH] usb: host: xhci-rcar: Fix timeout in xhci_suspend()

2019-08-02 Thread Yoshihiro Shimoda
When a USB device is connected to the host controller and
the system enters suspend, the following error happens
in xhci_suspend():

xhci-hcd ee00.usb: WARN: xHC CMD_RUN timeout

Since the firmware/internal CPU control the USBSTS.STS_HALT
and the process speed is down when the roothub port enters U3,
long delay for the handshake of STS_HALT is neeed in xhci_suspend().
So, this patch adds to set the XHCI_SLOW_SUSPEND.

Fixes: 435cc1138ec9 ("usb: host: xhci-plat: set resume_quirk() for R-Car 
controllers")
Cc:  # v4.12+
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/host/xhci-rcar.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
index 671bce1..8616c52 100644
--- a/drivers/usb/host/xhci-rcar.c
+++ b/drivers/usb/host/xhci-rcar.c
@@ -238,10 +238,15 @@ int xhci_rcar_init_quirk(struct usb_hcd *hcd)
 * pointers. So, this driver clears the AC64 bit of xhci->hcc_params
 * to call dma_set_coherent_mask(dev, DMA_BIT_MASK(32)) in
 * xhci_gen_setup().
+*
+* And, since the firmware/internal CPU control the USBSTS.STS_HALT
+* and the process speed is down when the roothub port enters U3,
+* long delay for the handshake of STS_HALT is neeed in xhci_suspend().
 */
if (xhci_rcar_is_gen2(hcd->self.controller) ||
-   xhci_rcar_is_gen3(hcd->self.controller))
-   xhci->quirks |= XHCI_NO_64BIT_SUPPORT;
+   xhci_rcar_is_gen3(hcd->self.controller)) {
+   xhci->quirks |= XHCI_NO_64BIT_SUPPORT | XHCI_SLOW_SUSPEND;
+   }
 
if (!xhci_rcar_wait_for_pll_active(hcd))
return -ETIMEDOUT;
-- 
2.7.4



[PATCH] usb: gadget: udc: renesas_usb3: Fix sysfs interface of "role"

2019-07-31 Thread Yoshihiro Shimoda
Since the role_store() uses strncmp(), it's possible to refer
out-of-memory if the sysfs data size is smaller than strlen("host").
This patch fixes it by using sysfs_streq() instead of strncmp().

Fixes: cc995c9ec118 ("usb: gadget: udc: renesas_usb3: add support for usb role 
swap")
Cc:  # v4.12+
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 7dc2485..b6eec81 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -2378,9 +2379,9 @@ static ssize_t role_store(struct device *dev, struct 
device_attribute *attr,
if (usb3->forced_b_device)
return -EBUSY;
 
-   if (!strncmp(buf, "host", strlen("host")))
+   if (sysfs_streq(buf, "host"))
new_mode_is_host = true;
-   else if (!strncmp(buf, "peripheral", strlen("peripheral")))
+   else if (sysfs_streq(buf, "peripheral"))
new_mode_is_host = false;
else
return -EINVAL;
-- 
2.7.4



RE: [PATCH v2 2/2] dt-bindings: usb: renesas_gen3: Rename bindings documentation file

2019-07-29 Thread Yoshihiro Shimoda
Hi Simon-san,

> From: Simon Horman, Sent: Monday, July 29, 2019 5:15 PM

> > > > > Unfortunately the previous version has already made it into usb-next
> > > > > 23c46801d14cb647 dt-bindings: usb: renesas_gen3: Rename bindings
> > > > > documentation file
> > > >
> > > > Ok, I guess we should go with that version.
> > >
> > > So can you resend this series based on 5.3-rc1 so I know what to apply?
> >
> > Since your usb-testing branch already has it which is merged from Felipe's 
> > usb-next branch,
> > I don't think Simon has to resend this series.
> >
> > https://www.spinics.net/lists/linux-usb/msg182103.html
> 
> Thanks and sorry for the confusion.
> 
> In v5.2-rc1 we had:
> 
>   devicetree/bindings/usb/renesas_usb3.txt
>   devicetree/bindings/usb/renesas_usbhs.txt
> 
> 
> In v5.3-rc1 we have:
> 
>   devicetree/bindings/usb/renesas,usb3.txt
>   devicetree/bindings/usb/renesas,usbhs.txt
> 
> Which reflects v1 of this patchset. And I think this is an improvement.
> 
> Shimoda-san, can you let me know if you would like me to rebase v2
> on v5.3-rc1? That would would give us:
> 
>   devicetree/bindings/usb/renesas,usb3-peri.txt
>   devicetree/bindings/usb/renesas,usbhs.txt   [unchanged]

Thank you for the detail. I would like you to rebase v2 like that, if possible.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2 2/2] dt-bindings: usb: renesas_gen3: Rename bindings documentation file

2019-07-25 Thread Yoshihiro Shimoda
Hi Greg,

> From: Greg Kroah-Hartman, Sent: Thursday, July 25, 2019 6:10 PM
> 
> On Thu, Jul 11, 2019 at 10:03:03AM +0200, Simon Horman wrote:
> > On Wed, Jul 03, 2019 at 02:28:51PM +0200, Geert Uytterhoeven wrote:
> > > Hi Simon,
> > >
> > > On Wed, Jul 3, 2019 at 10:35 AM Simon Horman  
> > > wrote:
> > > > For consistency with the naming of (most) other documentation files for 
> > > > DT
> > > > bindings for Renesas IP blocks rename the Renesas USB3.0 peripheral
> > > > documentation file from renesas-gen3.txt to renesas,usb3-peri.txt
> > > >
> > > > Signed-off-by: Simon Horman 
> > > > Reviewed-by: Geert Uytterhoeven 
> > > > Reviewed-by: Yoshihiro Shimoda 
> > > > Reviewed-by: Niklas Söderlund 
> > > >
> > > > ---
> > > > v2
> > > > * Accumulate review tags
> > > > * Use renesas,usb3-peri.txt as new filename as suggested by Shimoda-san
> > >
> > > Unfortunately the previous version has already made it into usb-next
> > > 23c46801d14cb647 dt-bindings: usb: renesas_gen3: Rename bindings
> > > documentation file
> >
> > Ok, I guess we should go with that version.
> 
> So can you resend this series based on 5.3-rc1 so I know what to apply?

Since your usb-testing branch already has it which is merged from Felipe's 
usb-next branch,
I don't think Simon has to resend this series.

https://www.spinics.net/lists/linux-usb/msg182103.html

Best regards,
Yoshihiro Shimoda

> thanks,
> 
> greg k-h


[PATCH v3] usb-storage: Add a limitation for blk_queue_max_hw_sectors()

2019-07-22 Thread Yoshihiro Shimoda
This patch fixes an issue that the following error happens on
swiotlb environment:

xhci-hcd ee00.usb: swiotlb buffer is full (sz: 524288 bytes), total 
32768 (slots), used 1338 (slots)

On the kernel v5.1, block settings of a usb-storage with SuperSpeed
were the following so that the block layer will allocate buffers
up to 64 KiB, and then the issue didn't happen.

max_segment_size = 65536
max_hw_sectors_kb = 1024

After the commit 09324d32d2a0 ("block: force an unlimited segment
size on queues with a virt boundary") is applied, the block settings
are the following. So, the block layer will allocate buffers up to
1024 KiB, and then the issue happens:

max_segment_size = 4294967295
max_hw_sectors_kb = 1024

To fix the issue, the usb-storage driver checks the maximum size of
a mapping for the device and then adjusts the max_hw_sectors_kb
if required. After this patch is applied, the block settings will
be the following, and then the issue doesn't happen.

max_segment_size = 4294967295
max_hw_sectors_kb = 256

Fixes: 09324d32d2a0 ("block: force an unlimited segment size on queues with a 
virt boundary")
Signed-off-by: Yoshihiro Shimoda 
Acked-by: Alan Stern 
---
 This patch can be applied on v5.3-rc1.

 Changes from v2:
 - Add Alan's Acked-by.
 https://patchwork.kernel.org/patch/10992539/

 Changes from v1:
 - Call blk_queue_max_hw_sectors() for the maximum size of mapping
   unconditionally to simplify the code by using read the value back
   from the queue in the end.
 - Add a comment on the code.
 - On v1, I got Reviewed-by from Christoph. But, I changed the code a little,
   I removed the Reviewed-by.
 https://patchwork.kernel.org/patch/10992985/

 drivers/usb/storage/scsiglue.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/storage/scsiglue.c b/drivers/usb/storage/scsiglue.c
index 3079024..05b8021 100644
--- a/drivers/usb/storage/scsiglue.c
+++ b/drivers/usb/storage/scsiglue.c
@@ -28,6 +28,8 @@
  * status of a command.
  */
 
+#include 
+#include 
 #include 
 #include 
 
@@ -99,6 +101,7 @@ static int slave_alloc (struct scsi_device *sdev)
 static int slave_configure(struct scsi_device *sdev)
 {
struct us_data *us = host_to_us(sdev->host);
+   struct device *dev = us->pusb_dev->bus->sysdev;
 
/*
 * Many devices have trouble transferring more than 32KB at a time,
@@ -129,6 +132,14 @@ static int slave_configure(struct scsi_device *sdev)
}
 
/*
+* The max_hw_sectors should be up to maximum size of a mapping for
+* the device. Otherwise, a DMA API might fail on swiotlb environment.
+*/
+   blk_queue_max_hw_sectors(sdev->request_queue,
+   min_t(size_t, queue_max_hw_sectors(sdev->request_queue),
+ dma_max_mapping_size(dev) >> SECTOR_SHIFT));
+
+   /*
 * Some USB host controllers can't do DMA; they have to use PIO.
 * They indicate this by setting their dma_mask to NULL.  For
 * such controllers we need to make sure the block layer sets
-- 
2.7.4



RE: [PATCH v3 10/15] usb: renesas_usbhs: support byte addressable CFIFO

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san again,

> From: Yoshihiro Shimoda, Sent: Wednesday, May 15, 2019 4:48 PM
> 
> Hi Chris-san,
> 
> > From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> >
> > Some SoC have a CFIFO register that is byte addressable. This means
> > when the CFIFO access is set to 32-bit, you can write 8-bit values to
> > addresses CFIFO+0, CFIFO+1, CFIFO+2, CFIFO+3.
> >
> > Signed-off-by: Chris Brandt 
> 
> Thank you for the patch!
> 

Oops! I didn't write my tag...

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> Best regards,
> Yoshihiro Shimoda



RE: [PATCH v3 12/15] dt-bindings: usb: renesas_usbhs: Add support for r7s9210

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Add support for r7s9210 (RZ/A2M) SoC
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 11/15] usb: renesas_usbhs: Add support for RZ/A2

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

Thank you for the patch!

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> The RZ/A2 is similar to the R-Car Gen3 with some small differences.
> 
> Signed-off-by: Chris Brandt 
> ---
> v3:
>  * Removed check for CONFIG_GENERIC_PHY
>  * rebase on top of Shimoda-san (v2) patch
> v2:
>  * combined RZA1 and RZA2 for fifo setting
>  * added braces to make code easier to read
>  * fixed and clean up usbhs_rza2_power_ctrl()
> ---
>  drivers/usb/renesas_usbhs/Makefile |  2 +-
>  drivers/usb/renesas_usbhs/common.c | 15 
>  drivers/usb/renesas_usbhs/rza.h|  1 +
>  drivers/usb/renesas_usbhs/rza2.c   | 75 
> ++
>  include/linux/usb/renesas_usbhs.h  |  1 +
>  5 files changed, 93 insertions(+), 1 deletion(-)
>  create mode 100644 drivers/usb/renesas_usbhs/rza2.c

> diff --git a/drivers/usb/renesas_usbhs/rza2.c 
> b/drivers/usb/renesas_usbhs/rza2.c
> new file mode 100644
> index ..56409cbae33c
> --- /dev/null
> +++ b/drivers/usb/renesas_usbhs/rza2.c
> @@ -0,0 +1,75 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Renesas USB driver RZ/A2 initialization and power control
> + *
> + * Copyright (C) 2019 Chris Brandt
> + * Copyright (C) 2019 Renesas Electronics Corporation
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include "common.h"
> +#include "rza.h"
> +
> +

I should have realized this on v2 patch though, this double blank lines
should be a line. After fixed it,

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 10/15] usb: renesas_usbhs: support byte addressable CFIFO

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Some SoC have a CFIFO register that is byte addressable. This means
> when the CFIFO access is set to 32-bit, you can write 8-bit values to
> addresses CFIFO+0, CFIFO+1, CFIFO+2, CFIFO+3.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 09/15] usb: renesas_usbhs: add support for CNEN bit

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> For some SoC, CNEN must be set for USB Device mode operation.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 08/15] usb: renesas_usbhs: move flags to param

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Move options from 'flags' field in private structure to param structure
> where other options are already being kept.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 07/15] dt-bindings: rcar-gen3-phy-usb2: Add r7s9210 support

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Document RZ/A2 (R7S9210) SoC bindings.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 06/15] dt-bindings: rcar-gen3-phy-usb2: Document dr_mode

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Document the optional dr_mode property
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 05/15] phy: renesas: rcar-gen3-usb2: Check dr_mode when not using OTG

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> When not using OTG, the PHY will need to know if it should function as
> host or peripheral by checking dr_mode in the PHY node (not the parent
> controller node).
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 04/15] dt-bindings: rcar-gen3-phy-usb2: Document use of usb_x1

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> Document the USB_X1 input and add clock-names to identify
> functional and USB_X1 clocks.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3 03/15] phy: renesas: rcar-gen3-usb2: detect usb_x1 clock

2019-05-15 Thread Yoshihiro Shimoda
Hi Chris-san,

> From: Chris Brandt, Sent: Tuesday, May 14, 2019 11:56 PM
> 
> The RZ/A2 has an optional dedicated 48MHz clock input for the PLL.
> If a clock node named 'usb_x1' exists and set to non-zero, then we can
> assume we want it use it.
> 
> Signed-off-by: Chris Brandt 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2] usb: renesas_usbhs: Use specific struct instead of USBHS_TYPE_* enums

2019-05-14 Thread Yoshihiro Shimoda
Hi Simon-san,

> From: Simon Horman, Sent: Monday, May 13, 2019 9:01 PM
> 
> On Mon, May 13, 2019 at 11:40:29AM +0900, Yoshihiro Shimoda wrote:
> > This patch adds a specific struct "usbhs_of_data" to add a new SoC
> > data easily instead of code basis in the future.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > Reviewed-by: Geert Uytterhoeven 
> 
> Hi Shimoda-san,
> 
> the minor suggestion below not withstanding this looks good to me.
> 
> Reviewed-by: Simon Horman 

Thank you for your review!

> > ---
> >  Changes from v1 [1]:
> >  - Use sizeof(variable) instead of sizeof(type).
> >  - Add Geert-san's reviewed-by (thanks!).
> >
> > [1]
> > https://patchwork.kernel.org/patch/10938575/
> >
> >  drivers/usb/renesas_usbhs/common.c | 112 
> > +
> >  drivers/usb/renesas_usbhs/common.h |   5 ++
> >  2 files changed, 70 insertions(+), 47 deletions(-)
> >
> > diff --git a/drivers/usb/renesas_usbhs/common.c 
> > b/drivers/usb/renesas_usbhs/common.c
> > index 249fbee..0ca89de 100644
> > --- a/drivers/usb/renesas_usbhs/common.c
> > +++ b/drivers/usb/renesas_usbhs/common.c

> > @@ -598,8 +638,15 @@ static struct renesas_usbhs_platform_info 
> > *usbhs_parse_dt(struct device *dev)
> > if (!info)
> > return NULL;
> >
> > +   data = of_device_get_match_data(dev);
> > +   if (!data)
> > +   return NULL;
> > +
> > dparam = &info->driver_param;
> > -   dparam->type = (uintptr_t)of_device_get_match_data(dev);
> > +   memcpy(dparam, &data->param, sizeof(data->param));
> > +   memcpy(&info->platform_callback, data->platform_callback,
> > +  sizeof(*data->platform_callback));
> 
> Can we avoid the error-proneness of calls to sizeof() as follows?
> 
> *dparam = data->param;
> info->platform_callback = *data->platform_callback;

Since Chris-san has submitted a patch series [1] that is based on this patch 
today,
I'd like to submit an incremental patch to avoid the error-proneness in the 
renesas_usbhs
(common.c and mod_host.c) later, if possible.

Greg-san, is it acceptable?

[1]
https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=117459

Best regards,
Yoshihiro Shimoda

> > +
> > if (!of_property_read_u32(dev->of_node, "renesas,buswait", &tmp))
> > dparam->buswait_bwait = tmp;
> > gpio = of_get_named_gpio_flags(dev->of_node, "renesas,enable-gpio", 0,
> > @@ -607,19 +654,6 @@ static struct renesas_usbhs_platform_info 
> > *usbhs_parse_dt(struct device *dev)
> > if (gpio > 0)
> > dparam->enable_gpio = gpio;
> >
> > -   if (dparam->type == USBHS_TYPE_RCAR_GEN2 ||
> > -   dparam->type == USBHS_TYPE_RCAR_GEN3 ||
> > -   dparam->type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
> > -   dparam->has_usb_dmac = 1;
> > -   dparam->pipe_configs = usbhsc_new_pipe;
> > -   dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe);
> > -   }
> > -
> > -   if (dparam->type == USBHS_TYPE_RZA1) {
> > -   dparam->pipe_configs = usbhsc_new_pipe;
> > -   dparam->pipe_size = ARRAY_SIZE(usbhsc_new_pipe);
> > -   }
> > -
> > return info;
> >  }
> >
> > @@ -676,29 +710,13 @@ static int usbhs_probe(struct platform_device *pdev)
> >&info->driver_param,
> >sizeof(struct renesas_usbhs_driver_param));
> 
> Likewise in the (otherwise unchanged) use of memcpy above.
> 
> >
> > -   switch (priv->dparam.type) {
> > -   case USBHS_TYPE_RCAR_GEN2:
> > -   priv->pfunc = usbhs_rcar2_ops;
> > -   break;
> > -   case USBHS_TYPE_RCAR_GEN3:
> > -   priv->pfunc = usbhs_rcar3_ops;
> > -   break;
> > -   case USBHS_TYPE_RCAR_GEN3_WITH_PLL:
> > -   priv->pfunc = usbhs_rcar3_with_pll_ops;
> > -   break;
> > -   case USBHS_TYPE_RZA1:
> > -   priv->pfunc = usbhs_rza1_ops;
> > -   break;
> > -   default:
> > -   if (!info->platform_callback.get_id) {
> > -   dev_err(&pdev->dev, "no platform callbacks");
> > -   return -EINVAL;
> > -   }
> > -   memcpy(&priv->pfunc,
> > -  &info->platform_callback,
> > -  sizeof(struct renesas_usbhs_platform_callback));
> > -   break;
> >

[PATCH v2] usb: renesas_usbhs: Use specific struct instead of USBHS_TYPE_* enums

2019-05-12 Thread Yoshihiro Shimoda
This patch adds a specific struct "usbhs_of_data" to add a new SoC
data easily instead of code basis in the future.

Signed-off-by: Yoshihiro Shimoda 
Reviewed-by: Geert Uytterhoeven 
---
 Changes from v1 [1]:
 - Use sizeof(variable) instead of sizeof(type).
 - Add Geert-san's reviewed-by (thanks!).

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

 drivers/usb/renesas_usbhs/common.c | 112 +
 drivers/usb/renesas_usbhs/common.h |   5 ++
 2 files changed, 70 insertions(+), 47 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 249fbee..0ca89de 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -535,53 +535,92 @@ static int usbhsc_drvcllbck_notify_hotplug(struct 
platform_device *pdev)
return 0;
 }
 
+static const struct usbhs_of_data rcar_gen2_data = {
+   .platform_callback = &usbhs_rcar2_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN2,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rcar_gen3_data = {
+   .platform_callback = &usbhs_rcar3_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN3,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rcar_gen3_with_pll_data = {
+   .platform_callback = &usbhs_rcar3_with_pll_ops,
+   .param = {
+   .type = USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .has_usb_dmac = 1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
+static const struct usbhs_of_data rza1_data = {
+   .platform_callback = &usbhs_rza1_ops,
+   .param = {
+   .type = USBHS_TYPE_RZA1,
+   .pipe_configs = usbhsc_new_pipe,
+   .pipe_size = ARRAY_SIZE(usbhsc_new_pipe),
+   }
+};
+
 /*
  * platform functions
  */
 static const struct of_device_id usbhs_of_match[] = {
{
.compatible = "renesas,usbhs-r8a774c0",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,usbhs-r8a7790",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7791",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7794",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,usbhs-r8a7795",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,usbhs-r8a7796",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,usbhs-r8a77990",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,usbhs-r8a77995",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   .data = &rcar_gen3_with_pll_data,
},
{
.compatible = "renesas,rcar-gen2-usbhs",
-   .data = (void *)USBHS_TYPE_RCAR_GEN2,
+   .data = &rcar_gen2_data,
},
{
.compatible = "renesas,rcar-gen3-usbhs",
-   .data = (void *)USBHS_TYPE_RCAR_GEN3,
+   .data = &rcar_gen3_data,
},
{
.compatible = "renesas,rza1-usbhs",
-   .data = (void *)USBHS_TYPE_RZA1,
+   .data = &rza1_data,
},
{ },
 };
@@ -591,6 +630,7 @@ static struct renesas_usbhs_platform_info 
*usbhs_parse_dt(struct device *dev)
 {
struct renesas_usbhs_platform_info *info;
struct renesas_usbhs_driver_param *dparam;
+   const struct usbhs_of_data *data;
u32 tmp;
int gpio;
 
@@ -598,8 +638,15 @@ static struct renesas_usbhs_platform_info 
*usbhs_parse_dt(struct device *dev)
if (!info)
return NULL;
 
+   data = of_device_get_match_data(dev);
+   if (!data)
+   return NULL;
+
dparam = &info->driver_param;
-   dparam->type = (uintptr_t)of_device_get_match_dat

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

2019-02-26 Thread Yoshihiro Shimoda
Hi,

> From: Spyridon Papageorgiou, Sent: Monday, February 18, 2019 7:27 PM
> To: mathias.ny...@intel.com
> Cc: gre...@linuxfoundation.org; yas...@jp.adit-jv.com; REE 
> ero...@de.adit-jv.com ;
> linux-usb@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] usb: host: xhci-rcar: Add XHCI_TRUST_TX_LENGTH quirk
> 
> From: Yasushi Asano 
> 
> When plugging BUFFALO LUA4-U3-AGT USB3.0 to Gigabit Ethernet LAN
> Adapter, warning messages filled up dmesg.
> 
> [  101.098287] xhci-hcd ee00.usb: WARN Successful completion on short TX 
> for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH
> quirk?
> [  101.117463] xhci-hcd ee00.usb: WARN Successful completion on short TX 
> for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH
> quirk?
> [  101.136513] xhci-hcd ee00.usb: WARN Successful completion on short TX 
> for slot 1 ep 4: needs XHCI_TRUST_TX_LENGTH
> quirk?
> 
> Adding the XHCI_TRUST_TX_LENGTH quirk resolves the issue.
> 
> Signed-off-by: Yasushi Asano 
> Signed-off-by: Spyridon Papageorgiou 

Thank you for the patch!

I don't know why R-Car xHCI needs this quirk though...
However, other xHCI controllers [1] also seem unclear why this quirk needs.
So,

Acked-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

[1]
---
commit da99706689481717998d1d48edd389f339eea979
Author: Daniel Thompson 
Date:   Thu Dec 21 15:06:15 2017 +0200

usb: xhci: Add XHCI_TRUST_TX_LENGTH for Renesas uPD720201
---
commit d2f48f05cd2a2a0a708fbfa45f1a00a87660d937
Author: Corentin Labbe 
Date:   Fri Jun 9 14:48:41 2017 +0300

usb: xhci: ASMedia ASM1042A chipset need shorts TX quirk
---
commit 2597fe99bb0259387111d0431691f5daac84f5a5
Author: Huang Rui 
Date:   Tue Aug 19 15:17:57 2014 +0300

usb: xhci: amd chipset also needs short TX quirk
---

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



RE: [PATCH] USB: renesas_usbhs: fix spelling mistake "doens't" -> "doesn't"

2019-02-17 Thread Yoshihiro Shimoda
Hi,

> From: Colin King, Sent: Monday, February 18, 2019 7:44 AM
> 
> From: Colin Ian King 
> 
> There is a spelling mistake in a dev_err message. Fix it.
> 
> Signed-off-by: Colin Ian King 

Thank you for the patch!

Acked-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> ---
>  drivers/usb/renesas_usbhs/mod_host.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/mod_host.c 
> b/drivers/usb/renesas_usbhs/mod_host.c
> index 4e59c649db81..ddd3be48f948 100644
> --- a/drivers/usb/renesas_usbhs/mod_host.c
> +++ b/drivers/usb/renesas_usbhs/mod_host.c
> @@ -340,7 +340,7 @@ static void usbhsh_pipe_detach(struct usbhsh_hpriv *hpriv,
>   pipe = usbhsh_uep_to_pipe(uep);
> 
>   if (unlikely(!pipe)) {
> - dev_err(dev, "uep doens't have pipe\n");
> + dev_err(dev, "uep doesn't have pipe\n");
>   } else if (1 == uep->counter--) { /* last user */
>   struct usb_host_endpoint *ep = usbhsh_uep_to_ep(uep);
>   struct usbhsh_device *udev = usbhsh_uep_to_udev(uep);
> --
> 2.20.1



[PATCH] usb: renesas_usbhs: replace udelay() with usleep_range()

2019-01-16 Thread Yoshihiro Shimoda
According to Documentation/timers/timers-howto.txt, a driver should
use usleep_range() instead of udelay() on NON-ATOMIC CONTEXT if
"SLEEPING FOR ~USECS OR SMALL MSECS ( 10us - 20ms)".

Since the .hardware_init() and .power_ctrl() will run on NON-ATOMIC
CONTEXT, this patch replaces udelay() with usleep_range().

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/rcar3.c | 2 +-
 drivers/usb/renesas_usbhs/rza.c   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/rcar3.c 
b/drivers/usb/renesas_usbhs/rcar3.c
index aa38204..5e730e9 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -59,7 +59,7 @@ static int usbhs_rcar3_power_ctrl(struct platform_device 
*pdev,
if (enable) {
usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
/* The controller on R-Car Gen3 needs to wait up to 45 usec */
-   udelay(45);
+   usleep_range(45, 90);
} else {
usbhs_bset(priv, LPSTS, LPSTS_SUSPM, 0);
}
diff --git a/drivers/usb/renesas_usbhs/rza.c b/drivers/usb/renesas_usbhs/rza.c
index 5b28725..8c739bd 100644
--- a/drivers/usb/renesas_usbhs/rza.c
+++ b/drivers/usb/renesas_usbhs/rza.c
@@ -35,7 +35,7 @@ static int usbhs_rza1_hardware_init(struct platform_device 
*pdev)
 
/* Enable USB PLL (NOTE: ch0 controls both ch0 and ch1) */
usbhs_bset(priv, SYSCFG, UPLLE, UPLLE);
-   udelay(1000);
+   usleep_range(1000, 2000);
usbhs_bset(priv, SUSPMODE, SUSPM, SUSPM);
 
return 0;
-- 
1.9.1



RE: [PATCH] dt-bindings: usb: renesas_usbhs: Add r8a774c0 support

2018-12-14 Thread Yoshihiro Shimoda
Hello Fabrizio-san,

> From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:16 PM
> 
> Hello Yoshihiro-san,
> 
> Thank you for your feedback!
> 
> > From: Yoshihiro Shimoda
> > Sent: 14 December 2018 06:01
> > Subject: RE: [PATCH] dt-bindings: usb: renesas_usbhs: Add r8a774c0 support
> >
> > Hi Fabrizio,
> >
> > > From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:21 AM
> > >
> > > Document RZ/G2E (R8A774C0) SoC bindings.
> > >
> > > Signed-off-by: Fabrizio Castro 
> >
> > Thank you for the patch!
> >
> > Reviewed-by: Yoshihiro Shimoda 
> >
> > By the way, I'm not sure, but I'm wondering that we need to add
> > .compatible renesas,usbhs-r8a774c0 with .data USBHS_TYPE_RCAR_GEN3_WITH_PLL
> > like r8a77990 to the drivers/usb/renesas_usbhs/common.c.
> > What do you think?
> 
> Yeah, you are right, I am going to send a patch for that shortly.

Thank you for submitting a patch!
I have reviewed you patch and submitted my Acked-by.

Best regards,
Yoshihiro Shimoda



RE: [PATCH] usb: renesas_usbhs: add support for RZ/G2E

2018-12-14 Thread Yoshihiro Shimoda
Hi Fabrizio,

> From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:27 PM
> 
> HS-USB found in RZ/G2E (a.k.a. r8a774c0) is very similar to the
> one found in R-Car E3 (a.k.a. r8a77990), as it needs to release
> the PLL reset by the UGCTRL register like R-Car E3, therefore add
> r8a774c0 support in a similar fashion to what was done for the
> r8a77990.
> 
> Signed-off-by: Fabrizio Castro 

Thank you for the patch!

Acked-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> ---
>  drivers/usb/renesas_usbhs/common.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.c 
> b/drivers/usb/renesas_usbhs/common.c
> index 2ff7991..249fbee 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -540,6 +540,10 @@ static int usbhsc_drvcllbck_notify_hotplug(struct 
> platform_device *pdev)
>   */
>  static const struct of_device_id usbhs_of_match[] = {
>   {
> + .compatible = "renesas,usbhs-r8a774c0",
> + .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
> + },
> + {
>   .compatible = "renesas,usbhs-r8a7790",
>   .data = (void *)USBHS_TYPE_RCAR_GEN2,
>   },
> --
> 2.7.4



RE: [PATCH] usb: gadget: udc: renesas_usb3: add support for r8a774c0

2018-12-14 Thread Yoshihiro Shimoda
Hi Fabrizio,

> From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:24 AM
> 
> RZ/G2E USB 3.0 implementation is like the one found on R-Car E3,
> therefore add the same quirk.
> 
> Signed-off-by: Fabrizio Castro 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> ---
>  drivers/usb/gadget/udc/renesas_usb3.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
> b/drivers/usb/gadget/udc/renesas_usb3.c
> index cdffbd1..18444a8 100644
> --- a/drivers/usb/gadget/udc/renesas_usb3.c
> +++ b/drivers/usb/gadget/udc/renesas_usb3.c
> @@ -2625,6 +2625,10 @@ MODULE_DEVICE_TABLE(of, usb3_of_match);
> 
>  static const struct soc_device_attribute renesas_usb3_quirks_match[] = {
>   {
> + .soc_id = "r8a774c0",
> + .data = &renesas_usb3_priv_r8a77990,
> + },
> + {
>   .soc_id = "r8a7795", .revision = "ES1.*",
>   .data = &renesas_usb3_priv_r8a7795_es1,
>   },
> --
> 2.7.4



RE: [PATCH] usb: gadget: udc: renesas_usb3: Add bindings for r8a774c0

2018-12-14 Thread Yoshihiro Shimoda
Hi Fabrizio,

> From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:22 AM
> 
> Document RZ/G2E (R8A774C0) SoC bindings.
> 
> Signed-off-by: Fabrizio Castro 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> ---
>  Documentation/devicetree/bindings/usb/renesas_usb3.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> index d366555..35039e7 100644
> --- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> +++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> @@ -3,6 +3,7 @@ Renesas Electronics USB3.0 Peripheral driver
>  Required properties:
>- compatible: Must contain one of the following:
>   - "renesas,r8a774a1-usb3-peri"
> + - "renesas,r8a774c0-usb3-peri"
>   - "renesas,r8a7795-usb3-peri"
>   - "renesas,r8a7796-usb3-peri"
>   - "renesas,r8a77965-usb3-peri"
> --
> 2.7.4



RE: [PATCH] dt-bindings: usb: renesas_usbhs: Add r8a774c0 support

2018-12-13 Thread Yoshihiro Shimoda
Hi Fabrizio,

> From: Fabrizio Castro, Sent: Friday, December 14, 2018 5:21 AM
> 
> Document RZ/G2E (R8A774C0) SoC bindings.
> 
> Signed-off-by: Fabrizio Castro 

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

By the way, I'm not sure, but I'm wondering that we need to add
.compatible renesas,usbhs-r8a774c0 with .data USBHS_TYPE_RCAR_GEN3_WITH_PLL
like r8a77990 to the drivers/usb/renesas_usbhs/common.c.
What do you think?

Best regards,
Yoshihiro Shimoda

> ---
>  Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> index 90719f5..d93b6a1 100644
> --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> +++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> @@ -7,6 +7,7 @@ Required properties:
>   - "renesas,usbhs-r8a7744" for r8a7744 (RZ/G1N) compatible device
>   - "renesas,usbhs-r8a7745" for r8a7745 (RZ/G1E) compatible device
>   - "renesas,usbhs-r8a774a1" for r8a774a1 (RZ/G2M) compatible device
> + - "renesas,usbhs-r8a774c0" for r8a774c0 (RZ/G2E) compatible device
>   - "renesas,usbhs-r8a7790" for r8a7790 (R-Car H2) compatible device
>   - "renesas,usbhs-r8a7791" for r8a7791 (R-Car M2-W) compatible device
>   - "renesas,usbhs-r8a7792" for r8a7792 (R-Car V2H) compatible device
> --
> 2.7.4



RE: [PATCH -next] usb: renesas_usbhs: Fix unused function warning when CONFIG_PM not set

2018-12-12 Thread Yoshihiro Shimoda
Hi,

> From: YueHaibing, Sent: Thursday, December 13, 2018 12:19 PM
> 
> with CONFIG_PM not set, gcc warning this:
> drivers/usb/renesas_usbhs/common.c:844:12:
>  warning: 'usbhsc_suspend' defined but not used [-Wunused-function]
> drivers/usb/renesas_usbhs/common.c:860:12:
>  warning: 'usbhsc_resume' defined but not used [-Wunused-function]
> 
> fix this by adding #ifdef around it.
> 
> Signed-off-by: YueHaibing 

Thank you for the patch.
However, this issue is already fixed on the Greg's usb.git / usb-next branch:
https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git/commit/?h=usb-next&id=eaf3074e0a8c2a39c4c14aa8ef1c2ec09ace9c79

Best regards,
Yoshihiro Shimoda



RE: [PATCH] usb: renesas_usbhs: mark PM functions as __maybe_unused

2018-12-11 Thread Yoshihiro Shimoda
Hi Arnd,

Thank you for the patch!

> From: Arnd Bergmann, Sent: Tuesday, December 11, 2018 7:06 PM
> To: Greg Kroah-Hartman 
> Cc: Arnd Bergmann ; Yoshihiro Shimoda 
> ; Felipe Balbi
> ; Simon Horman ; 
> Chris Brandt ;
> linux-usb@vger.kernel.org; linux-ker...@vger.kernel.org
> Subject: [PATCH] usb: renesas_usbhs: mark PM functions as __maybe_unused
> 
> Without CONFIG_PM, we get a new build warning here:
> 
> drivers/usb/renesas_usbhs/common.c:860:12: error: 'usbhsc_resume' defined but 
> not used [-Werror=unused-function]
>  static int usbhsc_resume(struct device *dev)
> ^
> drivers/usb/renesas_usbhs/common.c:844:12: error: 'usbhsc_suspend' defined 
> but not used [-Werror=unused-function]
>  static int usbhsc_suspend(struct device *dev)
> ^~
> 
> No idea why this never happened before, but it's trivial to work
> around by marking the functions as __maybe_unused so the compiler
> can silently discard them.

This build warning cause the commit d54d334e75b9 ("usb: renesas_usbhs:
Use SIMPLE_DEV_PM_OPS macro").

So, I'd like to add the following tag on this commit log.

Fixes: d54d334e75b9 ("usb: renesas_usbhs: Use SIMPLE_DEV_PM_OPS macro")

Also, we can remove "No idea why this never happened before, but"
from the commit log.

> Signed-off-by: Arnd Bergmann 

After revised the commit log a little:

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

> ---
>  drivers/usb/renesas_usbhs/common.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.c 
> b/drivers/usb/renesas_usbhs/common.c
> index 02c1d2bf4f86..2ff7991f4517 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -841,7 +841,7 @@ static int usbhs_remove(struct platform_device *pdev)
>   return 0;
>  }
> 
> -static int usbhsc_suspend(struct device *dev)
> +static __maybe_unused int usbhsc_suspend(struct device *dev)
>  {
>   struct usbhs_priv *priv = dev_get_drvdata(dev);
>   struct usbhs_mod *mod = usbhs_mod_get_current(priv);
> @@ -857,7 +857,7 @@ static int usbhsc_suspend(struct device *dev)
>   return 0;
>  }
> 
> -static int usbhsc_resume(struct device *dev)
> +static __maybe_unused int usbhsc_resume(struct device *dev)
>  {
>   struct usbhs_priv *priv = dev_get_drvdata(dev);
>   struct platform_device *pdev = usbhs_priv_to_pdev(priv);
> --
> 2.20.0



[PATCH 0/2] usb: renesas_usbhs: clean up the code around dev_pm_ops

2018-11-20 Thread Yoshihiro Shimoda
This patch set is based on the Felipe's usb.git / testing/next branch
(commit id = 9c5f54eb289b244dc9f5e24f56c9a9373582ef35).

The patch 1 comes from the following:
 https://patchwork.kernel.org/patch/10654679/


Jarkko Nikula (1):
  usb: renesas_usbhs: Remove dummy runtime PM callbacks

Yoshihiro Shimoda (1):
  usb: renesas_usbhs: Use SIMPLE_DEV_PM_OPS macro

 drivers/usb/renesas_usbhs/common.c | 19 +--
 1 file changed, 1 insertion(+), 18 deletions(-)

-- 
1.9.1



[PATCH 2/2] usb: renesas_usbhs: Use SIMPLE_DEV_PM_OPS macro

2018-11-20 Thread Yoshihiro Shimoda
This patch uses SIMPLE_DEV_PM_OPS macro instead of struct dev_pm_ops
directly.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 5 +
 1 file changed, 1 insertion(+), 4 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 0e760f2..02c1d2b 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -874,10 +874,7 @@ static int usbhsc_resume(struct device *dev)
return 0;
 }
 
-static const struct dev_pm_ops usbhsc_pm_ops = {
-   .suspend= usbhsc_suspend,
-   .resume = usbhsc_resume,
-};
+static SIMPLE_DEV_PM_OPS(usbhsc_pm_ops, usbhsc_suspend, usbhsc_resume);
 
 static struct platform_driver renesas_usbhs_driver = {
.driver = {
-- 
1.9.1



[PATCH 1/2] usb: renesas_usbhs: Remove dummy runtime PM callbacks

2018-11-20 Thread Yoshihiro Shimoda
From: Jarkko Nikula 

Platform drivers don't need dummy runtime PM callbacks that just return
success in order to have runtime PM happening. This has changed since
following commits:

commit 05aa55dddb9e ("PM / Runtime: Lenient generic runtime pm callbacks")
commit 543f2503a956 ("PM / platform_bus: Allow runtime PM by default")
commit 8b313a38ecff ("PM / Platform: Use generic runtime PM callbacks directly")

Signed-off-by: Jarkko Nikula 
Reviewed-by: Yoshihiro Shimoda 
Acked-by: Wolfram Sang 
[shimoda: revise git commit description style]
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 14 --
 1 file changed, 14 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index a3e1290..0e760f2 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -874,23 +874,9 @@ static int usbhsc_resume(struct device *dev)
return 0;
 }
 
-static int usbhsc_runtime_nop(struct device *dev)
-{
-   /* Runtime PM callback shared between ->runtime_suspend()
-* and ->runtime_resume(). Simply returns success.
-*
-* This driver re-initializes all registers after
-* pm_runtime_get_sync() anyway so there is no need
-* to save and restore registers here.
-*/
-   return 0;
-}
-
 static const struct dev_pm_ops usbhsc_pm_ops = {
.suspend= usbhsc_suspend,
.resume = usbhsc_resume,
-   .runtime_suspend= usbhsc_runtime_nop,
-   .runtime_resume = usbhsc_runtime_nop,
 };
 
 static struct platform_driver renesas_usbhs_driver = {
-- 
1.9.1



[PATCH] usb: gadget: udc: renesas_usb3: add a safety connection way for forced_b_device

2018-11-09 Thread Yoshihiro Shimoda
This patch adds a safety connection way for "forced_b_device" with
"workaround_for_vbus" like below:

< Example for R-Car E3 Ebisu >
 # modprobe 
 # echo 1 > /sys/kernel/debug/ee02.usb/b_device
 (connect a usb cable to host side.)
 # echo 2 > /sys/kernel/debug/ee02.usb/b_device

Previous code should have connected a usb cable before the "b_device"
is set to 1 on the Ebisu board. However, if xHCI driver on the board
is probed, it causes some troubles:
 - Conflicts USB VBUS/signals between the board and another host.
 - "Cannot enable. Maybe the USB cable is bad?" might happen on
   both the board and another host with a usb hub.
 - Cannot enumerate a usb gadget correctly because an interruption
   of VBUS change happens unexpectedly.

Reported-by: Kazuya Mizuguchi 
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 15 ++-
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index cdffbd1..6e34f95 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -358,6 +358,7 @@ struct renesas_usb3 {
bool extcon_host;   /* check id and set EXTCON_USB_HOST */
bool extcon_usb;/* check vbus and set EXTCON_USB */
bool forced_b_device;
+   bool start_to_connect;
 };
 
 #define gadget_to_renesas_usb3(_gadget)\
@@ -476,7 +477,8 @@ static void usb3_init_axi_bridge(struct renesas_usb3 *usb3)
 static void usb3_init_epc_registers(struct renesas_usb3 *usb3)
 {
usb3_write(usb3, ~0, USB3_USB_INT_STA_1);
-   usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG);
+   if (!usb3->workaround_for_vbus)
+   usb3_enable_irq_1(usb3, USB_INT_1_VBUS_CNG);
 }
 
 static bool usb3_wakeup_usb2_phy(struct renesas_usb3 *usb3)
@@ -700,8 +702,7 @@ static void usb3_mode_config(struct renesas_usb3 *usb3, 
bool host, bool a_dev)
usb3_set_mode_by_role_sw(usb3, host);
usb3_vbus_out(usb3, a_dev);
/* for A-Peripheral or forced B-device mode */
-   if ((!host && a_dev) ||
-   (usb3->workaround_for_vbus && usb3->forced_b_device))
+   if ((!host && a_dev) || usb3->start_to_connect)
usb3_connect(usb3);
spin_unlock_irqrestore(&usb3->lock, flags);
 }
@@ -2432,7 +2433,11 @@ static ssize_t renesas_usb3_b_device_write(struct file 
*file,
if (copy_from_user(&buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
return -EFAULT;
 
-   if (!strncmp(buf, "1", 1))
+   usb3->start_to_connect = false;
+   if (usb3->workaround_for_vbus && usb3->forced_b_device &&
+   !strncmp(buf, "2", 1))
+   usb3->start_to_connect = true;
+   else if (!strncmp(buf, "1", 1))
usb3->forced_b_device = true;
else
usb3->forced_b_device = false;
@@ -2440,7 +2445,7 @@ static ssize_t renesas_usb3_b_device_write(struct file 
*file,
if (usb3->workaround_for_vbus)
usb3_disconnect(usb3);
 
-   /* Let this driver call usb3_connect() anyway */
+   /* Let this driver call usb3_connect() if needed */
usb3_check_id(usb3);
 
return count;
-- 
1.9.1



RE: [PATCH 3/3] usb: renesas_usbhs: Remove dummy runtime PM callbacks

2018-10-25 Thread Yoshihiro Shimoda
Hi Wolfram-san,

> From: Wolfram Sang, Sent: Friday, October 26, 2018 7:58 AM

> >  static const struct dev_pm_ops usbhsc_pm_ops = {
> > .suspend= usbhsc_suspend,
> > .resume = usbhsc_resume,
> 
> Unrelated to this patch, but I wonder right now: is there a reason not
> to use SET_SYSTEM_SLEEP_PM_OPS here? Shimoda-san?

I don't know why because this code is contributed from Morimoto-san.
I'm guessing this code seems to come from sh_eth.c or i2c-sh_mobile.c
and we don't have the SET_SYSTEM_SLEEP_PM_OPS macro at 2009.
Morimoto-san contributed this code at 2010, but it seems not to realize
we have such macro.

Anyway, I'll try to use SET_SYSTEM_SLEEP_PM_OPS on the renesas_usbhs driver.

Best regards,
Yoshihiro Shimoda



RE: [PATCH 3/3] usb: renesas_usbhs: Remove dummy runtime PM callbacks

2018-10-24 Thread Yoshihiro Shimoda
Hi Jarkko,

> From: Jarkko Nikula, Sent: Wednesday, October 24, 2018 10:52 PM
> 
> Platform drivers don't need dummy runtime PM callbacks that just return
> success in order to have runtime PM happening. This has changed since
> following commits:
> 
> 05aa55dddb9e ("PM / Runtime: Lenient generic runtime pm callbacks")
> 543f2503a956 ("PM / platform_bus: Allow runtime PM by default")
> 8b313a38ecff ("PM / Platform: Use generic runtime PM callbacks directly")
> 
> Signed-off-by: Jarkko Nikula 
> ---
> Only build tested.

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

> ---
>  drivers/usb/renesas_usbhs/common.c | 14 --
>  1 file changed, 14 deletions(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.c 
> b/drivers/usb/renesas_usbhs/common.c
> index a3e1290d682d..0e760f228dd8 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -874,23 +874,9 @@ static int usbhsc_resume(struct device *dev)
>   return 0;
>  }
> 
> -static int usbhsc_runtime_nop(struct device *dev)
> -{
> - /* Runtime PM callback shared between ->runtime_suspend()
> -  * and ->runtime_resume(). Simply returns success.
> -  *
> -  * This driver re-initializes all registers after
> -  * pm_runtime_get_sync() anyway so there is no need
> -  * to save and restore registers here.
> -  */

I guess this code came from i2c-sh_mobile.c or sh_eth.c
and we didn't realize this code didn't need at that time (Oct 10 2011).

Best regards,
Yoshihiro Shimoda

> - return 0;
> -}
> -
>  static const struct dev_pm_ops usbhsc_pm_ops = {
>   .suspend= usbhsc_suspend,
>   .resume = usbhsc_resume,
> - .runtime_suspend= usbhsc_runtime_nop,
> - .runtime_resume = usbhsc_runtime_nop,
>  };
> 
>  static struct platform_driver renesas_usbhs_driver = {
> --
> 2.19.1



RE: [PATCH 1/2] dt-bindings: usb: renesas_usb3: add bindings for r8a77990

2018-10-02 Thread Yoshihiro Shimoda
Hi Felipe-san,

> From: Felipe Balbi, Sent: Tuesday, October 2, 2018 9:18 PM
> 
> Yoshihiro Shimoda  writes:
> 
> > This patch adds bindings for r8a77990 (R-Car E3).
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > ---
> >  Documentation/devicetree/bindings/usb/renesas_usb3.txt | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > index b22f0a5..d366555 100644
> > --- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > +++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > @@ -6,6 +6,7 @@ Required properties:
> > - "renesas,r8a7795-usb3-peri"
> > - "renesas,r8a7796-usb3-peri"
> > - "renesas,r8a77965-usb3-peri"
> > +   - "renesas,r8a77990-usb3-peri"
> > - "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 or RZ/G2
> >   compatible device
> 
> oops:
> 
> checking file Documentation/devicetree/bindings/usb/renesas_usb3.txt
> Hunk #1 FAILED at 6.
> 1 out of 1 hunk FAILED
> 
> could you rebase against testing/next?

Sorry for lack information.
If possible, would you review/apply the following patch at first?

https://patchwork.kernel.org/patch/10574879/

Greg-san's repo already merged the patch like below:

commit 28da90f19cdec24d669d75942fec227f4de37abd
Author: Fabrizio Castro 
Date:   Fri Aug 24 08:56:15 2018 +0100

usb: gadget: udc: renesas_usb3: Add r8a774a1 support

    Document RZ/G2M (R8A774A1) SoC bindings.

Signed-off-by: Fabrizio Castro 
Reviewed-by: Biju Das 
Reviewed-by: Simon Horman 
Reviewed-by: Rob Herring 
Reviewed-by: Yoshihiro Shimoda 
Signed-off-by: Greg Kroah-Hartman 


I think that almost all patches I or other guys sent for usb gadget are already
merged into Greg-san's repo like below:

29f7915 Merge 4.19-rc6 into usb-next

4d2a863 usb: renesas_usbhs: add support for R-Car E3
bcddbd3 dt-bindings: usb: renesas_usbhs: add bindings for r8a77990
6b983ac usb: renesas_usbhs: rcar3: Use OTG mode for R-Car D3
eb757ff Revert "usb: renesas_usbhs: set the mode by using extcon state for non-o
91b20c5 Revert "usb: renesas_usbhs: add extcon notifier to set mode for non-otg

3df0e24 usb: renesas_usbhs: Add multiple clocks management
8e0d368 dt-bindings: usb: renesas_usbhs: add clock-names property
f181dbb usb: renesas_usbhs: Add reset_control

28da90f usb: gadget: udc: renesas_usb3: Add r8a774a1 support
3938e13 dt-bindings: usb: renesas_usbhs: Add r8a774a1 support
...

Best regards,
Yoshihiro Shimoda

> --
> balbi


[PATCH 1/2] dt-bindings: usb: renesas_usb3: add bindings for r8a77990

2018-10-02 Thread Yoshihiro Shimoda
This patch adds bindings for r8a77990 (R-Car E3).

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usb3.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt 
b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
index b22f0a5..d366555 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
@@ -6,6 +6,7 @@ Required properties:
- "renesas,r8a7795-usb3-peri"
- "renesas,r8a7796-usb3-peri"
- "renesas,r8a77965-usb3-peri"
+   - "renesas,r8a77990-usb3-peri"
- "renesas,rcar-gen3-usb3-peri" for a generic R-Car Gen3 or RZ/G2
  compatible device
 
-- 
1.9.1



[PATCH 0/2] usb: gadget: udc: renesas_usb3: add support for r8a77990

2018-10-02 Thread Yoshihiro Shimoda
This patch set is based on the latest Greg's usb.git / usb-testing branch.

Yoshihiro Shimoda (2):
  dt-bindings: usb: renesas_usb3: add bindings for r8a77990
  usb: gadget: udc: renesas_usb3: add support for r8a77990

 Documentation/devicetree/bindings/usb/renesas_usb3.txt |  1 +
 drivers/usb/gadget/udc/renesas_usb3.c  | 11 +++
 2 files changed, 12 insertions(+)

-- 
1.9.1



[PATCH 2/2] usb: gadget: udc: renesas_usb3: add support for r8a77990

2018-10-02 Thread Yoshihiro Shimoda
Since r8a77990 (R-Car E3) doesn't have VBUS detect pin and
number of ramif is 4, this patch adds a new renesas_usb3_priv
variable for the SoC.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index e1656f3..100e9fa 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2600,6 +2600,13 @@ static void renesas_usb3_init_ram(struct renesas_usb3 
*usb3, struct device *dev,
.ramsize_per_pipe = SZ_4K,
 };
 
+static const struct renesas_usb3_priv renesas_usb3_priv_r8a77990 = {
+   .ramsize_per_ramif = SZ_16K,
+   .num_ramif = 4,
+   .ramsize_per_pipe = SZ_4K,
+   .workaround_for_vbus = true,
+};
+
 static const struct of_device_id usb3_of_match[] = {
{
.compatible = "renesas,r8a7795-usb3-peri",
@@ -2618,6 +2625,10 @@ static void renesas_usb3_init_ram(struct renesas_usb3 
*usb3, struct device *dev,
.soc_id = "r8a7795", .revision = "ES1.*",
.data = &renesas_usb3_priv_r8a7795_es1,
},
+   {
+   .soc_id = "r8a77990",
+   .data = &renesas_usb3_priv_r8a77990,
+   },
{ /* sentinel */ },
 };
 
-- 
1.9.1



[PATCH] usb: gadget: udc: renesas_usb3: Fix b-device mode for "workaround"

2018-10-02 Thread Yoshihiro Shimoda
If the "workaround_for_vbus" is true, the driver will not call
usb_disconnect(). So, since the controller keeps some registers'
value, the driver doesn't re-enumarate suitable speed after
the b-device mode is disabled. To fix the issue, this patch
adds usb_disconnect() calling in renesas_usb3_b_device_write()
if workaround_for_vbus is true.

Fixes: 43ba968b00ea ("usb: gadget: udc: renesas_usb3: add debugfs to set the 
b-device mode")
Cc:  # v4.14+
Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/gadget/udc/renesas_usb3.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index e1656f3..67d8a50 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -2437,6 +2437,9 @@ static ssize_t renesas_usb3_b_device_write(struct file 
*file,
else
usb3->forced_b_device = false;
 
+   if (usb3->workaround_for_vbus)
+   usb3_disconnect(usb3);
+
/* Let this driver call usb3_connect() anyway */
usb3_check_id(usb3);
 
-- 
1.9.1



[PATCH 5/5] usb: renesas_usbhs: add support for R-Car E3

2018-09-21 Thread Yoshihiro Shimoda
This patch adds support for R-Car E3. This SoC needs to release
the PLL reset by the UGCTRL register like R-Car D3. So, this patch
adds a usbhs_of_match entry for this SoC with
"USBHS_TYPE_RCAR_GEN3_WITH_PLL".

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 4 
 1 file changed, 4 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 522cc09..a3e1290 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -560,6 +560,10 @@ static int usbhsc_drvcllbck_notify_hotplug(struct 
platform_device *pdev)
.data = (void *)USBHS_TYPE_RCAR_GEN3,
},
{
+   .compatible = "renesas,usbhs-r8a77990",
+   .data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
+   },
+   {
.compatible = "renesas,usbhs-r8a77995",
.data = (void *)USBHS_TYPE_RCAR_GEN3_WITH_PLL,
},
-- 
1.9.1



[PATCH 2/5] Revert "usb: renesas_usbhs: set the mode by using extcon state for non-otg channel"

2018-09-21 Thread Yoshihiro Shimoda
This reverts commit cd14247d5c14b9b20bb3d3dfcaa899ca22c8dccc.

R-Car D3 can use OTG mode in fact. So, the commit doesn't need anymore.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/rcar3.c | 15 +--
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/rcar3.c 
b/drivers/usb/renesas_usbhs/rcar3.c
index b9a8453..50e5fb5 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -27,7 +27,6 @@
  * Remarks: bit[31:11] and bit[9:6] should be 0
  */
 #define UGCTRL2_RESERVED_3 0x0001  /* bit[3:0] should be B'0001 */
-#define UGCTRL2_USB0SEL_EHCI   0x0010
 #define UGCTRL2_USB0SEL_HSUSB  0x0020
 #define UGCTRL2_USB0SEL_OTG0x0030
 #define UGCTRL2_VBUSSEL0x0400
@@ -50,14 +49,6 @@ static void usbhs_rcar3_set_ugctrl2(struct usbhs_priv *priv, 
u32 val)
usbhs_write32(priv, UGCTRL2, val | UGCTRL2_RESERVED_3);
 }
 
-static void usbhs_rcar3_set_usbsel(struct usbhs_priv *priv, bool ehci)
-{
-   if (ehci)
-   usbhs_rcar3_set_ugctrl2(priv, UGCTRL2_USB0SEL_EHCI);
-   else
-   usbhs_rcar3_set_ugctrl2(priv, UGCTRL2_USB0SEL_HSUSB);
-}
-
 static int usbhs_rcar3_power_ctrl(struct platform_device *pdev,
void __iomem *base, int enable)
 {
@@ -83,14 +74,10 @@ static int usbhs_rcar3_power_and_pll_ctrl(struct 
platform_device *pdev,
struct usbhs_priv *priv = usbhs_pdev_to_priv(pdev);
u32 val;
int timeout = 1000;
-   bool is_host = false;
 
if (enable) {
usbhs_write32(priv, UGCTRL, 0); /* release PLLRESET */
-   if (priv->edev)
-   is_host = extcon_get_state(priv->edev, EXTCON_USB_HOST);
-
-   usbhs_rcar3_set_usbsel(priv, is_host);
+   usbhs_rcar3_set_ugctrl2(priv, UGCTRL2_USB0SEL_HSUSB);
 
usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
do {
-- 
1.9.1



[PATCH 4/5] dt-bindings: usb: renesas_usbhs: add bindings for r8a77990

2018-09-21 Thread Yoshihiro Shimoda
This patch adds bindings for r8a77990 (R-Car E3).

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 15fb3b3..a649329 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -14,6 +14,7 @@ Required properties:
- "renesas,usbhs-r8a7795" for r8a7795 (R-Car H3) compatible device
- "renesas,usbhs-r8a7796" for r8a7796 (R-Car M3-W) compatible device
- "renesas,usbhs-r8a77965" for r8a77965 (R-Car M3-N) compatible device
+   - "renesas,usbhs-r8a77990" for r8a77990 (R-Car E3) compatible device
- "renesas,usbhs-r8a77995" for r8a77995 (R-Car D3) compatible device
- "renesas,usbhs-r7s72100" for r7s72100 (RZ/A1) compatible device
- "renesas,rcar-gen2-usbhs" for R-Car Gen2 or RZ/G1 compatible devices
-- 
1.9.1



[PATCH 3/5] usb: renesas_usbhs: rcar3: Use OTG mode for R-Car D3

2018-09-21 Thread Yoshihiro Shimoda
Since R-Car D3 can use OTG mode, this patch changes the UGCTRL2
value to UGCTRL2_USB0SEL_OTG and UGCTRL2_VBUSSEL like other R-Car
Gen3 SoCs.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/rcar3.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/renesas_usbhs/rcar3.c 
b/drivers/usb/renesas_usbhs/rcar3.c
index 50e5fb5..aa38204 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -77,7 +77,8 @@ static int usbhs_rcar3_power_and_pll_ctrl(struct 
platform_device *pdev,
 
if (enable) {
usbhs_write32(priv, UGCTRL, 0); /* release PLLRESET */
-   usbhs_rcar3_set_ugctrl2(priv, UGCTRL2_USB0SEL_HSUSB);
+   usbhs_rcar3_set_ugctrl2(priv,
+   UGCTRL2_USB0SEL_OTG | UGCTRL2_VBUSSEL);
 
usbhs_bset(priv, LPSTS, LPSTS_SUSPM, LPSTS_SUSPM);
do {
-- 
1.9.1



[PATCH 0/5] usb: renesas_usbhs: use otg mode and add support for R-Car E3

2018-09-21 Thread Yoshihiro Shimoda
This patch set is based on the latest Greg's usb.git / usb-testing branch
(the commit id is ae8a2ca8a2215c7e31e6d874f7303801bb15fbbc)

The previous code set the mode as peripheral mode by the UGCTRL2 register
for R-Car D3. But, this SoC can select OTG mode in fact. So, at first,
I'd like to revert related patches I submitted in patch 1 and 2.
Then, in patch 3, it sets the mode as "OTG" and in patch 4 and 5, it
supports for R-Car E3.

To use this controller for R-Car D3 and E3, we need the following
patch set. Otherwize, the mode will not be changed to peripheral mode
by the phy's COMMCTRL register:
 https://patchwork.kernel.org/project/linux-renesas-soc/list/?series=21629


Yoshihiro Shimoda (5):
  Revert "usb: renesas_usbhs: add extcon notifier to set mode for
non-otg channel"
  Revert "usb: renesas_usbhs: set the mode by using extcon state for
non-otg channel"
  usb: renesas_usbhs: rcar3: Use OTG mode for R-Car D3
  dt-bindings: usb: renesas_usbhs: add bindings for r8a77990
  usb: renesas_usbhs: add support for R-Car E3

 .../devicetree/bindings/usb/renesas_usbhs.txt  |  1 +
 drivers/usb/renesas_usbhs/common.c | 13 ---
 drivers/usb/renesas_usbhs/common.h |  1 -
 drivers/usb/renesas_usbhs/rcar3.c  | 27 ++
 4 files changed, 7 insertions(+), 35 deletions(-)

-- 
1.9.1



[PATCH 1/5] Revert "usb: renesas_usbhs: add extcon notifier to set mode for non-otg channel"

2018-09-21 Thread Yoshihiro Shimoda
This reverts commit 8ada211d0383b72878582bd312b984a9eae62b30.

R-Car D3 can use OTG mode in fact. So, the commit doesn't need anymore.
In other words, like other R-Car Gen3 SoCs, R-Car D3 can change the mode
by using the phy-rcar-gen3-usb2 driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c |  9 -
 drivers/usb/renesas_usbhs/common.h |  1 -
 drivers/usb/renesas_usbhs/rcar3.c  | 11 ---
 3 files changed, 21 deletions(-)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index d6c39ba..522cc09 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -677,15 +677,6 @@ static int usbhs_probe(struct platform_device *pdev)
break;
case USBHS_TYPE_RCAR_GEN3_WITH_PLL:
priv->pfunc = usbhs_rcar3_with_pll_ops;
-   if (!IS_ERR_OR_NULL(priv->edev)) {
-   priv->nb.notifier_call = priv->pfunc.notifier;
-   ret = devm_extcon_register_notifier(&pdev->dev,
-   priv->edev,
-   EXTCON_USB_HOST,
-   &priv->nb);
-   if (ret < 0)
-   dev_err(&pdev->dev, "no notifier registered\n");
-   }
break;
case USBHS_TYPE_RZA1:
priv->pfunc = usbhs_rza1_ops;
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 555b3e7..3777af8 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -257,7 +257,6 @@ struct usbhs_priv {
struct platform_device *pdev;
 
struct extcon_dev *edev;
-   struct notifier_block nb;
 
spinlock_t  lock;
 
diff --git a/drivers/usb/renesas_usbhs/rcar3.c 
b/drivers/usb/renesas_usbhs/rcar3.c
index d0ea4ff..b9a8453 100644
--- a/drivers/usb/renesas_usbhs/rcar3.c
+++ b/drivers/usb/renesas_usbhs/rcar3.c
@@ -112,16 +112,6 @@ static int usbhs_rcar3_get_id(struct platform_device *pdev)
return USBHS_GADGET;
 }
 
-static int usbhs_rcar3_notifier(struct notifier_block *nb, unsigned long event,
-   void *data)
-{
-   struct usbhs_priv *priv = container_of(nb, struct usbhs_priv, nb);
-
-   usbhs_rcar3_set_usbsel(priv, !!event);
-
-   return NOTIFY_DONE;
-}
-
 const struct renesas_usbhs_platform_callback usbhs_rcar3_ops = {
.power_ctrl = usbhs_rcar3_power_ctrl,
.get_id = usbhs_rcar3_get_id,
@@ -130,5 +120,4 @@ static int usbhs_rcar3_notifier(struct notifier_block *nb, 
unsigned long event,
 const struct renesas_usbhs_platform_callback usbhs_rcar3_with_pll_ops = {
.power_ctrl = usbhs_rcar3_power_and_pll_ctrl,
.get_id = usbhs_rcar3_get_id,
-   .notifier = usbhs_rcar3_notifier,
 };
-- 
1.9.1



[PATCH v5 0/3] usb: renesas_usbhs: add reset_control and multiple clocks management

2018-09-11 Thread Yoshihiro Shimoda
This patch set is based on Felipe's usb.git / testing/next branch
(the commit id is 5b394b2ddf0347bef56e50c69a58773c94343ff3) with
the following patch:
  https://patchwork.kernel.org/patch/10574875/

Changes from v4:
 - Revise the dt-bindings to add how many clocks are required and expect
   for "renesas,rcar-gen3-usbhs".

Changes from v3:
 - Change the dt-bindings not to use clock-names in patch 2.
 - To achieve backward compatibility with old DT, the driver should get
   the first clock and the second clock is an optional.
 - Add "clk_put" calling in the remove function.

Changes from v2:
 - Use clk_bulk_enable_prepare() instead of two functions on patch 3/3.

Changes from v1:
 - Fix error path on patch 3/3.
 - Use clk_bulk_disable_unprepare() instead of two functions on patch 3/3.
 - Use staic array of struct clk_bulk_data instead of a pointer on patch 3/3.
 

Yoshihiro Shimoda (3):
  usb: renesas_usbhs: Add reset_control
  dt-bindings: usb: renesas_usbhs: add clock-names property
  usb: renesas_usbhs: Add multiple clocks management

 .../devicetree/bindings/usb/renesas_usbhs.txt  |   6 +-
 drivers/usb/renesas_usbhs/common.c | 100 +
 drivers/usb/renesas_usbhs/common.h |   4 +
 3 files changed, 109 insertions(+), 1 deletion(-)

-- 
1.9.1



[PATCH v5 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-09-11 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Otherwise, other side device cannot work correctly. So, this patch
adds a property of clock-names for R-Car Gen3 as an optional.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 087140a..15fb3b3 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -26,7 +26,11 @@ Required properties:
 
   - reg: Base address and length of the register for the USBHS
   - interrupts: Interrupt specifier for the USBHS
-  - clocks: A list of phandle + clock specifier pairs
+  - clocks: A list of phandle + clock specifier pairs.
+   - In case of "renesas,rcar-gen3-usbhs", two clocks are required.
+ First clock should be peripheral and second one should be host.
+   - In case of except above, one clock is required. First clock
+ should be peripheral.
 
 Optional properties:
   - renesas,buswait: Integer to use BUSWAIT register
-- 
1.9.1



[PATCH v5 1/3] usb: renesas_usbhs: Add reset_control

2018-09-11 Thread Yoshihiro Shimoda
R-Car Gen3 needs to deassert resets of both host and peripheral.
Since [eo]hci-platform is possible to assert the reset(s) when
the probing failed, renesas_usbhs driver doesn't work correctly
regardless of finished probing. To fix this issue, this patch adds
reset_control on this renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 12 
 drivers/usb/renesas_usbhs/common.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 4310df4..1d355d5 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "common.h"
@@ -574,6 +575,10 @@ static int usbhs_probe(struct platform_device *pdev)
return PTR_ERR(priv->edev);
}
 
+   priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
+   if (IS_ERR(priv->rsts))
+   return PTR_ERR(priv->rsts);
+
/*
 * care platform info
 */
@@ -658,6 +663,10 @@ static int usbhs_probe(struct platform_device *pdev)
/* dev_set_drvdata should be called after usbhs_mod_init */
platform_set_drvdata(pdev, priv);
 
+   ret = reset_control_deassert(priv->rsts);
+   if (ret)
+   goto probe_fail_rst;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -711,6 +720,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   reset_control_assert(priv->rsts);
+probe_fail_rst:
usbhs_mod_remove(priv);
 probe_end_fifo_exit:
usbhs_fifo_remove(priv);
@@ -739,6 +750,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
usbhs_pipe_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 6137f79..bce7d35 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct usbhs_priv;
@@ -277,6 +278,7 @@ struct usbhs_priv {
struct usbhs_fifo_info fifo_info;
 
struct phy *phy;
+   struct reset_control *rsts;
 };
 
 /*
-- 
1.9.1



[PATCH v5 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-09-11 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Since [eo]hci-platform disables the reset(s) when the drivers are
removed, renesas_usbhs driver doesn't work correctly. To fix this
issue, this patch adds multiple clocks management on this
renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 88 ++
 drivers/usb/renesas_usbhs/common.h |  2 +
 2 files changed, 90 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 1d355d5..d6c39ba 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2011 Renesas Solutions Corp.
  * Kuninori Morimoto 
  */
+#include 
 #include 
 #include 
 #include 
@@ -291,6 +292,79 @@ static void usbhsc_set_buswait(struct usbhs_priv *priv)
usbhs_bset(priv, BUSWAIT, 0x000F, wait);
 }
 
+static bool usbhsc_is_multi_clks(struct usbhs_priv *priv)
+{
+   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
+   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL)
+   return true;
+
+   return false;
+}
+
+static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv)
+{
+   if (!usbhsc_is_multi_clks(priv))
+   return 0;
+
+   /* The first clock should exist */
+   priv->clks[0] = of_clk_get(dev->of_node, 0);
+   if (IS_ERR(priv->clks[0]))
+   return PTR_ERR(priv->clks[0]);
+
+   /*
+* To backward compatibility with old DT, this driver checks the return
+* value if it's -ENOENT or not.
+*/
+   priv->clks[1] = of_clk_get(dev->of_node, 1);
+   if (PTR_ERR(priv->clks[1]) == -ENOENT)
+   priv->clks[1] = NULL;
+   else if (IS_ERR(priv->clks[1]))
+   return PTR_ERR(priv->clks[1]);
+
+   return 0;
+}
+
+static void usbhsc_clk_put(struct usbhs_priv *priv)
+{
+   int i;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
+   clk_put(priv->clks[i]);
+}
+
+static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv)
+{
+   int i, ret;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return 0;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++) {
+   ret = clk_prepare_enable(priv->clks[i]);
+   if (ret) {
+   while (--i >= 0)
+   clk_disable_unprepare(priv->clks[i]);
+   return ret;
+   }
+   }
+
+   return ret;
+}
+
+static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv)
+{
+   int i;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
+   clk_disable_unprepare(priv->clks[i]);
+}
+
 /*
  * platform default param
  */
@@ -341,6 +415,10 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* enable PM */
pm_runtime_get_sync(dev);
 
+   /* enable clks */
+   if (usbhsc_clk_prepare_enable(priv))
+   return;
+
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
@@ -353,6 +431,9 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* disable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
+   /* disable clks */
+   usbhsc_clk_disable_unprepare(priv);
+
/* disable PM */
pm_runtime_put_sync(dev);
}
@@ -667,6 +748,10 @@ static int usbhs_probe(struct platform_device *pdev)
if (ret)
goto probe_fail_rst;
 
+   ret = usbhsc_clk_get(&pdev->dev, priv);
+   if (ret)
+   goto probe_fail_clks;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -720,6 +805,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   usbhsc_clk_put(priv);
+probe_fail_clks:
reset_control_assert(priv->rsts);
 probe_fail_rst:
usbhs_mod_remove(priv);
@@ -750,6 +837,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   usbhsc_clk_put(priv);
reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index bce7d35..555b3e7 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -8,6 +8,7 @@
 #ifndef RENESAS_

RE: [PATCH v4 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-09-10 Thread Yoshihiro Shimoda
Hi Rob,

> From: Rob Herring, Sent: Tuesday, September 11, 2018 3:27 AM
> 
> On Mon, Sep 10, 2018 at 06:52:19PM +0900, Yoshihiro Shimoda wrote:
> > R-Car Gen3 needs to enable clocks of both host and peripheral.
> > Otherwise, other side device cannot work correctly. So, this patch
> > adds a property of clock-names for R-Car Gen3 as an optional.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > ---
> >  Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> > index 087140a..dbdb92c 100644
> > --- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> > +++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
> > @@ -26,7 +26,9 @@ Required properties:
> >
> >- reg: Base address and length of the register for the USBHS
> >- interrupts: Interrupt specifier for the USBHS
> > -  - clocks: A list of phandle + clock specifier pairs
> > +  - clocks: A list of phandle + clock specifier pairs. In case of
> > +   "renesas,rcar-gen3-usbhs" compatible device, first clock should be
> > +   peripheral and second one should be host.
> 
> This should have said how many clocks. That's still not clear except for
> "renesas,rcar-gen3-usbhs".

Thank you for your comments! I'll revise it.

Best regards,
Yoshihiro Shimoda

> Rob


[PATCH 2/2] dt-bindings: usb: ohci: Add clocks description for R-Car Gen3

2018-09-10 Thread Yoshihiro Shimoda
This patch adds detailed information of an optional property "clocks"
description for R-Car Gen3.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/usb-ohci.txt | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-ohci.txt 
b/Documentation/devicetree/bindings/usb/usb-ohci.txt
index a8d2103..525 100644
--- a/Documentation/devicetree/bindings/usb/usb-ohci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-ohci.txt
@@ -12,7 +12,11 @@ Optional properties:
 - no-big-frame-no : boolean, set if frame_no lives in bits [15:0] of HCCA
 - remote-wakeup-connected: remote wakeup is wired on the platform
 - num-ports : u32, to override the detected port count
-- clocks : a list of phandle + clock specifier pairs
+- clocks : a list of phandle + clock specifier pairs. In case of Renesas
+  R-Car Gen3 SoCs:
+  - if a host only channel: first clock should be host.
+  - if a USB DRD channel: first clock should be host and second one
+  should be peripheral.
 - phys : see usb-hcd.txt in the current directory
 - resets : a list of phandle + reset specifier pairs
 
-- 
1.9.1



[PATCH 0/2] dt-bindings: usb: [eo]hci: Add clocks description for R-Car Gen3

2018-09-10 Thread Yoshihiro Shimoda
This patch is based on the latest Greg's usb.git / usb-next branch
(the commit id = 57361846b52bc686112da6ca5368d11210796804).

Since the current dt-bindings document is unclear about usb-[eo]hci.txt
for R-Car Gen3 SoCs clocks descriptions, this patch adds detailed
information for the SoCs.

Yoshihiro Shimoda (2):
  dt-bindings: usb: ehci: Add clocks description for R-Car Gen3
  dt-bindings: usb: ohci: Add clocks description for R-Car Gen3

 Documentation/devicetree/bindings/usb/usb-ehci.txt | 6 +-
 Documentation/devicetree/bindings/usb/usb-ohci.txt | 6 +-
 2 files changed, 10 insertions(+), 2 deletions(-)

-- 
1.9.1



[PATCH 1/2] dt-bindings: usb: ehci: Add clocks description for R-Car Gen3

2018-09-10 Thread Yoshihiro Shimoda
This patch adds detailed information of an optional property "clocks"
description for R-Car Gen3.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/usb-ehci.txt | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/usb-ehci.txt 
b/Documentation/devicetree/bindings/usb/usb-ehci.txt
index 0f1b753..406252d 100644
--- a/Documentation/devicetree/bindings/usb/usb-ehci.txt
+++ b/Documentation/devicetree/bindings/usb/usb-ehci.txt
@@ -15,7 +15,11 @@ Optional properties:
  - needs-reset-on-resume : boolean, set this to force EHCI reset after resume
  - has-transaction-translator : boolean, set this if EHCI have a Transaction
Translator built into the root hub.
- - clocks : a list of phandle + clock specifier pairs
+ - clocks : a list of phandle + clock specifier pairs. In case of Renesas
+   R-Car Gen3 SoCs:
+   - if a host only channel: first clock should be host.
+   - if a USB DRD channel: first clock should be host and second one
+   should be peripheral.
  - phys : see usb-hcd.txt in the current directory
  - resets : phandle + reset specifier pair
 
-- 
1.9.1



[PATCH v4 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-09-10 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Since [eo]hci-platform disables the reset(s) when the drivers are
removed, renesas_usbhs driver doesn't work correctly. To fix this
issue, this patch adds multiple clocks management on this
renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 88 ++
 drivers/usb/renesas_usbhs/common.h |  2 +
 2 files changed, 90 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 1d355d5..d6c39ba 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2011 Renesas Solutions Corp.
  * Kuninori Morimoto 
  */
+#include 
 #include 
 #include 
 #include 
@@ -291,6 +292,79 @@ static void usbhsc_set_buswait(struct usbhs_priv *priv)
usbhs_bset(priv, BUSWAIT, 0x000F, wait);
 }
 
+static bool usbhsc_is_multi_clks(struct usbhs_priv *priv)
+{
+   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
+   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL)
+   return true;
+
+   return false;
+}
+
+static int usbhsc_clk_get(struct device *dev, struct usbhs_priv *priv)
+{
+   if (!usbhsc_is_multi_clks(priv))
+   return 0;
+
+   /* The first clock should exist */
+   priv->clks[0] = of_clk_get(dev->of_node, 0);
+   if (IS_ERR(priv->clks[0]))
+   return PTR_ERR(priv->clks[0]);
+
+   /*
+* To backward compatibility with old DT, this driver checks the return
+* value if it's -ENOENT or not.
+*/
+   priv->clks[1] = of_clk_get(dev->of_node, 1);
+   if (PTR_ERR(priv->clks[1]) == -ENOENT)
+   priv->clks[1] = NULL;
+   else if (IS_ERR(priv->clks[1]))
+   return PTR_ERR(priv->clks[1]);
+
+   return 0;
+}
+
+static void usbhsc_clk_put(struct usbhs_priv *priv)
+{
+   int i;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
+   clk_put(priv->clks[i]);
+}
+
+static int usbhsc_clk_prepare_enable(struct usbhs_priv *priv)
+{
+   int i, ret;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return 0;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++) {
+   ret = clk_prepare_enable(priv->clks[i]);
+   if (ret) {
+   while (--i >= 0)
+   clk_disable_unprepare(priv->clks[i]);
+   return ret;
+   }
+   }
+
+   return ret;
+}
+
+static void usbhsc_clk_disable_unprepare(struct usbhs_priv *priv)
+{
+   int i;
+
+   if (!usbhsc_is_multi_clks(priv))
+   return;
+
+   for (i = 0; i < ARRAY_SIZE(priv->clks); i++)
+   clk_disable_unprepare(priv->clks[i]);
+}
+
 /*
  * platform default param
  */
@@ -341,6 +415,10 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* enable PM */
pm_runtime_get_sync(dev);
 
+   /* enable clks */
+   if (usbhsc_clk_prepare_enable(priv))
+   return;
+
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
@@ -353,6 +431,9 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* disable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
+   /* disable clks */
+   usbhsc_clk_disable_unprepare(priv);
+
/* disable PM */
pm_runtime_put_sync(dev);
}
@@ -667,6 +748,10 @@ static int usbhs_probe(struct platform_device *pdev)
if (ret)
goto probe_fail_rst;
 
+   ret = usbhsc_clk_get(&pdev->dev, priv);
+   if (ret)
+   goto probe_fail_clks;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -720,6 +805,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   usbhsc_clk_put(priv);
+probe_fail_clks:
reset_control_assert(priv->rsts);
 probe_fail_rst:
usbhs_mod_remove(priv);
@@ -750,6 +837,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   usbhsc_clk_put(priv);
reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index bce7d35..555b3e7 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -8,6 +8,7 @@
 #ifndef RENESAS_

[PATCH v4 1/3] usb: renesas_usbhs: Add reset_control

2018-09-10 Thread Yoshihiro Shimoda
R-Car Gen3 needs to deassert resets of both host and peripheral.
Since [eo]hci-platform is possible to assert the reset(s) when
the probing failed, renesas_usbhs driver doesn't work correctly
regardless of finished probing. To fix this issue, this patch adds
reset_control on this renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 12 
 drivers/usb/renesas_usbhs/common.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 4310df4..1d355d5 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "common.h"
@@ -574,6 +575,10 @@ static int usbhs_probe(struct platform_device *pdev)
return PTR_ERR(priv->edev);
}
 
+   priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
+   if (IS_ERR(priv->rsts))
+   return PTR_ERR(priv->rsts);
+
/*
 * care platform info
 */
@@ -658,6 +663,10 @@ static int usbhs_probe(struct platform_device *pdev)
/* dev_set_drvdata should be called after usbhs_mod_init */
platform_set_drvdata(pdev, priv);
 
+   ret = reset_control_deassert(priv->rsts);
+   if (ret)
+   goto probe_fail_rst;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -711,6 +720,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   reset_control_assert(priv->rsts);
+probe_fail_rst:
usbhs_mod_remove(priv);
 probe_end_fifo_exit:
usbhs_fifo_remove(priv);
@@ -739,6 +750,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
usbhs_pipe_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 6137f79..bce7d35 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct usbhs_priv;
@@ -277,6 +278,7 @@ struct usbhs_priv {
struct usbhs_fifo_info fifo_info;
 
struct phy *phy;
+   struct reset_control *rsts;
 };
 
 /*
-- 
1.9.1



[PATCH v4 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-09-10 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Otherwise, other side device cannot work correctly. So, this patch
adds a property of clock-names for R-Car Gen3 as an optional.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 087140a..dbdb92c 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -26,7 +26,9 @@ Required properties:
 
   - reg: Base address and length of the register for the USBHS
   - interrupts: Interrupt specifier for the USBHS
-  - clocks: A list of phandle + clock specifier pairs
+  - clocks: A list of phandle + clock specifier pairs. In case of
+   "renesas,rcar-gen3-usbhs" compatible device, first clock should be
+   peripheral and second one should be host.
 
 Optional properties:
   - renesas,buswait: Integer to use BUSWAIT register
-- 
1.9.1



[PATCH v4 0/3] usb: renesas_usbhs: add reset_control and multiple clocks management

2018-09-10 Thread Yoshihiro Shimoda
This patch set is based on Felipe's usb.git / testing/next branch
(the commit id is 5b394b2ddf0347bef56e50c69a58773c94343ff3) with
the following patch:
  https://patchwork.kernel.org/patch/10574875/

Changes from v3:
 - Change the dt-bindings not to use clock-names in patch 2.
 - To achieve backward compatibility with old DT, the driver should get
   the first clock and the second clock is an optional.
 - Add "clk_put" calling in the remove function.

Changes from v2:
 - Use clk_bulk_enable_prepare() instead of two functions on patch 3/3.

Changes from v1:
 - Fix error path on patch 3/3.
 - Use clk_bulk_disable_unprepare() instead of two functions on patch 3/3.
 - Use staic array of struct clk_bulk_data instead of a pointer on patch 3/3.


Yoshihiro Shimoda (3):
  usb: renesas_usbhs: Add reset_control
  dt-bindings: usb: renesas_usbhs: add clock-names property
  usb: renesas_usbhs: Add multiple clocks management

 .../devicetree/bindings/usb/renesas_usbhs.txt  |   4 +-
 drivers/usb/renesas_usbhs/common.c | 100 +
 drivers/usb/renesas_usbhs/common.h |   4 +
 3 files changed, 107 insertions(+), 1 deletion(-)

-- 
1.9.1



RE: [PATCH v3 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-09-06 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Thursday, September 6, 2018 4:28 PM
> 
> Hi Shimoda-san,
> 
> On Thu, Sep 6, 2018 at 7:52 AM Yoshihiro Shimoda
>  wrote:
> > R-Car Gen3 needs to enable clocks of both host and peripheral.
> > Since [eo]hci-platform disables the reset(s) when the drivers are
> > removed, renesas_usbhs driver doesn't work correctly. To fix this
> > issue, this patch adds multiple clocks management on this
> > renesas_usbhs driver.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> 
> > --- a/drivers/usb/renesas_usbhs/common.c
> > +++ b/drivers/usb/renesas_usbhs/common.c
> 
> > @@ -667,6 +684,12 @@ static int usbhs_probe(struct platform_device *pdev)
> > if (ret)
> > goto probe_fail_rst;
> >
> > +   if (priv->num_clks) {
> > +   ret = clk_bulk_get(&pdev->dev, priv->num_clks, priv->clks);
> 
> (inspired by Morimoto-san) clk_bulk_get() is a no-op if num_clks is zero.

That's right. Thank you for your comment.

> > +   if (ret == -EPROBE_DEFER)
> 
> Why this special handling for -EPROBE_DEFER only?
> Shouldn't all errors be considered fatal?
> 
> Perhaps this is needed for backwards compatibility with old DT?

Yes, this is needed for backward s compatibility with old DT.

> In that case, you should do more thorough checking (first clock should
> exist, second should return -ENOENT).

I understood it. (For backwards compatibility with old DT, if second clock
returns -ENOENT, the driver should do a special handling.)
I'll fix this patch.

Best regards,
Yoshihiro Shimoda

> > +   goto probe_fail_clks;
> > +   }
> > +
> > /*
> >  * deviece reset here because
> >  * USB device might be used in boot loader.
> 
> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds


[PATCH v3 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-09-05 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Since [eo]hci-platform disables the reset(s) when the drivers are
removed, renesas_usbhs driver doesn't work correctly. To fix this
issue, this patch adds multiple clocks management on this
renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 25 +
 drivers/usb/renesas_usbhs/common.h |  3 +++
 2 files changed, 28 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 1d355d5..d1e37cc 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2011 Renesas Solutions Corp.
  * Kuninori Morimoto 
  */
+#include 
 #include 
 #include 
 #include 
@@ -341,6 +342,11 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* enable PM */
pm_runtime_get_sync(dev);
 
+   /* enable clks if exist */
+   if (priv->num_clks &&
+   clk_bulk_prepare_enable(priv->num_clks, priv->clks))
+   return;
+
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
@@ -353,6 +359,10 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* disable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
+   /* disable clks if exist */
+   if (priv->num_clks)
+   clk_bulk_disable_unprepare(priv->num_clks, priv->clks);
+
/* disable PM */
pm_runtime_put_sync(dev);
}
@@ -620,6 +630,13 @@ static int usbhs_probe(struct platform_device *pdev)
break;
}
 
+   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
+   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
+   priv->clks[0].id = "hsusb";
+   priv->clks[1].id = "ehci/ohci";
+   priv->num_clks = ARRAY_SIZE(priv->clks);
+   };
+
/* set driver callback functions for platform */
dfunc   = &info->driver_callback;
dfunc->notify_hotplug   = usbhsc_drvcllbck_notify_hotplug;
@@ -667,6 +684,12 @@ static int usbhs_probe(struct platform_device *pdev)
if (ret)
goto probe_fail_rst;
 
+   if (priv->num_clks) {
+   ret = clk_bulk_get(&pdev->dev, priv->num_clks, priv->clks);
+   if (ret == -EPROBE_DEFER)
+   goto probe_fail_clks;
+   }
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -720,6 +743,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   clk_bulk_put(priv->num_clks, priv->clks);
+probe_fail_clks:
reset_control_assert(priv->rsts);
 probe_fail_rst:
usbhs_mod_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index bce7d35..6e7c5f2 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -8,6 +8,7 @@
 #ifndef RENESAS_USB_DRIVER_H
 #define RENESAS_USB_DRIVER_H
 
+#include 
 #include 
 #include 
 #include 
@@ -279,6 +280,8 @@ struct usbhs_priv {
 
struct phy *phy;
struct reset_control *rsts;
+   struct clk_bulk_data clks[2];
+   int num_clks;
 };
 
 /*
-- 
1.9.1



[PATCH v3 1/3] usb: renesas_usbhs: Add reset_control

2018-09-05 Thread Yoshihiro Shimoda
R-Car Gen3 needs to deassert resets of both host and peripheral.
Since [eo]hci-platform is possible to assert the reset(s) when
the probing failed, renesas_usbhs driver doesn't work correctly
regardless of finished probing. To fix this issue, this patch adds
reset_control on this renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 12 
 drivers/usb/renesas_usbhs/common.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 4310df4..1d355d5 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "common.h"
@@ -574,6 +575,10 @@ static int usbhs_probe(struct platform_device *pdev)
return PTR_ERR(priv->edev);
}
 
+   priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
+   if (IS_ERR(priv->rsts))
+   return PTR_ERR(priv->rsts);
+
/*
 * care platform info
 */
@@ -658,6 +663,10 @@ static int usbhs_probe(struct platform_device *pdev)
/* dev_set_drvdata should be called after usbhs_mod_init */
platform_set_drvdata(pdev, priv);
 
+   ret = reset_control_deassert(priv->rsts);
+   if (ret)
+   goto probe_fail_rst;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -711,6 +720,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   reset_control_assert(priv->rsts);
+probe_fail_rst:
usbhs_mod_remove(priv);
 probe_end_fifo_exit:
usbhs_fifo_remove(priv);
@@ -739,6 +750,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
usbhs_pipe_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 6137f79..bce7d35 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct usbhs_priv;
@@ -277,6 +278,7 @@ struct usbhs_priv {
struct usbhs_fifo_info fifo_info;
 
struct phy *phy;
+   struct reset_control *rsts;
 };
 
 /*
-- 
1.9.1



[PATCH v3 0/3] usb: renesas_usbhs: add reset_control and multiple clocks management

2018-09-05 Thread Yoshihiro Shimoda
This patch set is based on Felipe's usb.git / testing/next branch
(the commit id is 5b394b2ddf0347bef56e50c69a58773c94343ff3) with
the following patch:
  https://patchwork.kernel.org/patch/10574875/

Changes from v2:
 - Use clk_bulk_enable_prepare() instead of two functions on patch 3/3.

Changes from v1:
 - Fix error path on patch 3/3.
 - Use clk_bulk_disable_unprepare() instead of two functions on patch 3/3.
 - Use staic array of struct clk_bulk_data instead of a pointer on patch 3/3.

Yoshihiro Shimoda (3):
  usb: renesas_usbhs: Add reset_control
  dt-bindings: usb: renesas_usbhs: add clock-names property
  usb: renesas_usbhs: Add multiple clocks management

 .../devicetree/bindings/usb/renesas_usbhs.txt  |  2 ++
 drivers/usb/renesas_usbhs/common.c | 37 ++
 drivers/usb/renesas_usbhs/common.h |  5 +++
 3 files changed, 44 insertions(+)

-- 
1.9.1



[PATCH v3 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-09-05 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Otherwise, other side device cannot work correctly. So, this patch
adds a property of clock-names for R-Car Gen3 as an optional.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 087140a..a8fa3ec 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -37,6 +37,8 @@ Optional properties:
   - dmas: Must contain a list of references to DMA specifiers.
   - dma-names : named "ch%d", where %d is the channel number ranging from zero
 to the number of channels (DnFIFOs) minus one.
+  - clock-names: For a "renesas,rcar-gen3-usbhs" compatible device,
+"hsusb" and "ehci/ohci" can be set.
 
 Example:
usbhs: usb@e659 {
-- 
1.9.1



RE: [PATCH] usb: Change usb_of_get_companion_dev() place to usb/common

2018-09-05 Thread Yoshihiro Shimoda
Hi Greg, Felipe,
(Add John's email to CC)

> From: Yoshihiro Shimoda, Sent: Tuesday, August 21, 2018 10:59 AM
> 
> Hi,
> 
> > From: Yoshihiro Shimoda, Sent: Monday, August 20, 2018 12:10 PM
> >
> > Since renesas_usb3 udc driver calls usb_of_get_companion_dev()
> > which is on usb/core/of.c, build error like below happens if we
> > disable CONFIG_USB because the usb/core/ needs CONFIG_USB:
> >
> > ERROR: "usb_of_get_companion_dev" [drivers/usb/gadget/udc/renesas_usb3.ko] 
> > undefined!
> >
> > According to the usb/gadget/Kconfig, "NOTE:  Gadget support
> > ** DOES NOT ** depend on host-side CONFIG_USB !!".
> > So, to fix the issue, this patch changes the usb_of_get_companion_dev()
> > place from usb/core/of.c to usb/common/common.c to be called by both
> > host and gadget.
> >
> > Reported-by: John Garry 
> > Fixes: 39facfa01c9f ("usb: gadget: udc: renesas_usb3: Add register of usb 
> > role switch")
> > Signed-off-by: Yoshihiro Shimoda 
> 
> On other email thread [1], Arnd said I have his Ack on this patch.
> So,
> 
> Acked-by: Arnd Bergmann 
> 
> [1]
> https://lkml.org/lkml/2018/8/20/216

I'm afraid but, would you apply this patch for linux v4.19?

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-09-05 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Wednesday, September 5, 2018 11:00 PM
> 
> Hi Shimoda-san,
> 
> On Fri, Aug 31, 2018 at 12:36 PM Yoshihiro Shimoda
>  wrote:
> > R-Car Gen3 needs to enable clocks of both host and peripheral.
> > Since [eo]hci-platform disables the reset(s) when the drivers are
> > removed, renesas_usbhs driver doesn't work correctly. To fix this
> > issue, this patch adds multiple clocks management on this
> > renesas_usbhs driver.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> 
> Thanks for your patch!
> 
> > --- a/drivers/usb/renesas_usbhs/common.c
> > +++ b/drivers/usb/renesas_usbhs/common.c
> 
> > @@ -336,11 +337,26 @@ static void usbhsc_power_ctrl(struct usbhs_priv 
> > *priv, int enable)
> >  {
> > struct platform_device *pdev = usbhs_priv_to_pdev(priv);
> > struct device *dev = usbhs_priv_to_dev(priv);
> > +   int ret;
> >
> > if (enable) {
> > /* enable PM */
> > pm_runtime_get_sync(dev);
> >
> > +   /* enable clks if exist */
> > +   if (priv->num_clks) {
> > +   ret = clk_bulk_prepare(priv->num_clks, priv->clks);
> > +   if (!ret) {
> > +   ret = clk_bulk_enable(priv->num_clks,
> > + priv->clks);
> > +   if (ret) {
> > +   clk_bulk_unprepare(priv->num_clks,
> > +  priv->clks);
> > +   return;
> > +   }
> > +   }
> 
> I think you misunderstood my comment: you can replace the calls to
> clk_bulk_prepare() and clk_bulk_enable() by a single call to
> clk_bulk_prepare_enable().

Oops! I overlooked the clk_bulk_prepare_enable()..
I'll submit v3 patch.

Best regards,
Yoshihiro Shimoda

> 
> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds


RE: linux-next: Tree for Aug 31 (drivers/usb/gadget/udc/renesas_usb3)

2018-09-02 Thread Yoshihiro Shimoda
Hi,

> From: Randy Dunlap, Sent: Saturday, September 1, 2018 12:43 AM
> 
> On 08/30/2018 08:03 PM, Stephen Rothwell wrote:
> > Hi all,
> >
> > Changes since 20180830:
> >
> 
> on i386:
> 
> drivers/usb/gadget/udc/renesas_usb3.o: In function `renesas_usb3_probe':
> renesas_usb3.c:(.text+0x16da): undefined reference to 
> `usb_of_get_companion_dev'
> 
> 
> Full randconfig file is attached.

Thank you for the report!
I already submitted a fix patch [1]. But this patch is not applied yet.

[1]
https://marc.info/?l=linux-usb&m=153476263226681&w=2


Related ML archives:
https://marc.info/?l=linux-usb&m=153382696712253&w=2
https://marc.info/?l=linux-usb&m=153419699328537&w=2

Best regards,
Yoshihiro Shimoda


> --
> ~Randy


[PATCH v2 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-08-31 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Since [eo]hci-platform disables the reset(s) when the drivers are
removed, renesas_usbhs driver doesn't work correctly. To fix this
issue, this patch adds multiple clocks management on this
renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 35 +++
 drivers/usb/renesas_usbhs/common.h |  3 +++
 2 files changed, 38 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 1d355d5..39ed714 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2011 Renesas Solutions Corp.
  * Kuninori Morimoto 
  */
+#include 
 #include 
 #include 
 #include 
@@ -336,11 +337,26 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, 
int enable)
 {
struct platform_device *pdev = usbhs_priv_to_pdev(priv);
struct device *dev = usbhs_priv_to_dev(priv);
+   int ret;
 
if (enable) {
/* enable PM */
pm_runtime_get_sync(dev);
 
+   /* enable clks if exist */
+   if (priv->num_clks) {
+   ret = clk_bulk_prepare(priv->num_clks, priv->clks);
+   if (!ret) {
+   ret = clk_bulk_enable(priv->num_clks,
+ priv->clks);
+   if (ret) {
+   clk_bulk_unprepare(priv->num_clks,
+  priv->clks);
+   return;
+   }
+   }
+   }
+
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
@@ -353,6 +369,10 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* disable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
+   /* disable clks if exist */
+   if (priv->num_clks)
+   clk_bulk_disable_unprepare(priv->num_clks, priv->clks);
+
/* disable PM */
pm_runtime_put_sync(dev);
}
@@ -620,6 +640,13 @@ static int usbhs_probe(struct platform_device *pdev)
break;
}
 
+   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
+   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
+   priv->clks[0].id = "hsusb";
+   priv->clks[1].id = "ehci/ohci";
+   priv->num_clks = ARRAY_SIZE(priv->clks);
+   };
+
/* set driver callback functions for platform */
dfunc   = &info->driver_callback;
dfunc->notify_hotplug   = usbhsc_drvcllbck_notify_hotplug;
@@ -667,6 +694,12 @@ static int usbhs_probe(struct platform_device *pdev)
if (ret)
goto probe_fail_rst;
 
+   if (priv->num_clks) {
+   ret = clk_bulk_get(&pdev->dev, priv->num_clks, priv->clks);
+   if (ret == -EPROBE_DEFER)
+   goto probe_fail_clks;
+   }
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -720,6 +753,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   clk_bulk_put(priv->num_clks, priv->clks);
+probe_fail_clks:
reset_control_assert(priv->rsts);
 probe_fail_rst:
usbhs_mod_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index bce7d35..6e7c5f2 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -8,6 +8,7 @@
 #ifndef RENESAS_USB_DRIVER_H
 #define RENESAS_USB_DRIVER_H
 
+#include 
 #include 
 #include 
 #include 
@@ -279,6 +280,8 @@ struct usbhs_priv {
 
struct phy *phy;
struct reset_control *rsts;
+   struct clk_bulk_data clks[2];
+   int num_clks;
 };
 
 /*
-- 
1.9.1



[PATCH v2 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-08-31 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Otherwise, other side device cannot work correctly. So, this patch
adds a property of clock-names for R-Car Gen3 as an optional.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 087140a..a8fa3ec 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -37,6 +37,8 @@ Optional properties:
   - dmas: Must contain a list of references to DMA specifiers.
   - dma-names : named "ch%d", where %d is the channel number ranging from zero
 to the number of channels (DnFIFOs) minus one.
+  - clock-names: For a "renesas,rcar-gen3-usbhs" compatible device,
+"hsusb" and "ehci/ohci" can be set.
 
 Example:
usbhs: usb@e659 {
-- 
1.9.1



[PATCH v2 1/3] usb: renesas_usbhs: Add reset_control

2018-08-31 Thread Yoshihiro Shimoda
R-Car Gen3 needs to deassert resets of both host and peripheral.
Since [eo]hci-platform is possible to assert the reset(s) when
the probing failed, renesas_usbhs driver doesn't work correctly
regardless of finished probing. To fix this issue, this patch adds
reset_control on this renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 12 
 drivers/usb/renesas_usbhs/common.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 4310df4..1d355d5 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "common.h"
@@ -574,6 +575,10 @@ static int usbhs_probe(struct platform_device *pdev)
return PTR_ERR(priv->edev);
}
 
+   priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
+   if (IS_ERR(priv->rsts))
+   return PTR_ERR(priv->rsts);
+
/*
 * care platform info
 */
@@ -658,6 +663,10 @@ static int usbhs_probe(struct platform_device *pdev)
/* dev_set_drvdata should be called after usbhs_mod_init */
platform_set_drvdata(pdev, priv);
 
+   ret = reset_control_deassert(priv->rsts);
+   if (ret)
+   goto probe_fail_rst;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -711,6 +720,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   reset_control_assert(priv->rsts);
+probe_fail_rst:
usbhs_mod_remove(priv);
 probe_end_fifo_exit:
usbhs_fifo_remove(priv);
@@ -739,6 +750,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
usbhs_pipe_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 6137f79..bce7d35 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct usbhs_priv;
@@ -277,6 +278,7 @@ struct usbhs_priv {
struct usbhs_fifo_info fifo_info;
 
struct phy *phy;
+   struct reset_control *rsts;
 };
 
 /*
-- 
1.9.1



[PATCH v2 0/3] usb: renesas_usbhs: add reset_control and multiple clocks management

2018-08-31 Thread Yoshihiro Shimoda
This patch set is based on Felipe's usb.git / testing/next branch
(the commit id is 5b394b2ddf0347bef56e50c69a58773c94343ff3) with
the following patch:
  https://patchwork.kernel.org/patch/10574875/

Changes from v1:
 - Fix error path on patch 3/3.
 - Use clk_bulk_disable_unprepare() instead of two functions on patch 3/3.
 - Use staic array of struct clk_bulk_data instead of a pointer on patch 3/3.


Yoshihiro Shimoda (3):
  usb: renesas_usbhs: Add reset_control
  dt-bindings: usb: renesas_usbhs: add clock-names property
  usb: renesas_usbhs: Add multiple clocks management

 .../devicetree/bindings/usb/renesas_usbhs.txt  |  2 +
 drivers/usb/renesas_usbhs/common.c | 47 ++
 drivers/usb/renesas_usbhs/common.h |  5 +++
 3 files changed, 54 insertions(+)

-- 
1.9.1



RE: [PATCH 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-08-31 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: Geert Uytterhoeven, Sent: Friday, August 31, 2018 4:22 PM
> 
> Hi Shimoda-san,
> 
> On Fri, Aug 31, 2018 at 8:50 AM Yoshihiro Shimoda
>  wrote:
> > R-Car Gen3 needs to enable clocks of both host and peripheral.
> > Since [eo]hci-platform disables the reset(s) when the drivers are
> > removed, renesas_usbhs driver doesn't work correctly. To fix this
> > issue, this patch adds multiple clocks management on this
> > renesas_usbhs driver.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> 
> Thanks for your patch!

Thank you for your review!

> > --- a/drivers/usb/renesas_usbhs/common.c
> > +++ b/drivers/usb/renesas_usbhs/common.c
> > @@ -5,6 +5,7 @@
> >   * Copyright (C) 2011 Renesas Solutions Corp.
> >   * Kuninori Morimoto 
> >   */
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -336,11 +337,23 @@ static void usbhsc_power_ctrl(struct usbhs_priv 
> > *priv, int enable)
> >  {
> > struct platform_device *pdev = usbhs_priv_to_pdev(priv);
> > struct device *dev = usbhs_priv_to_dev(priv);
> > +   int ret;
> >
> > if (enable) {
> > /* enable PM */
> > pm_runtime_get_sync(dev);
> >
> > +   /* enable clks if exist */
> > +   if (priv->clks) {
> > +   ret = clk_bulk_prepare(priv->num_clks, priv->clks);
> > +   if (!ret) {
> > +   ret = clk_bulk_enable(priv->num_clks,
> > + priv->clks);
> > +   if (ret)
> > +   return;
> 
> clk_bulk_prepare_enable(), which also takes care of unpreparing all
> clocks if any clock fails to enabled.

Oops! I'll fix this in v2.

> > +   }
> > +   }
> > +
> > /* enable platform power */
> > usbhs_platform_call(priv, power_ctrl, pdev, priv->base, 
> > enable);
> >
> > @@ -353,6 +366,12 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, 
> > int enable)
> > /* disable platform power */
> > usbhs_platform_call(priv, power_ctrl, pdev, priv->base, 
> > enable);
> >
> > +   /* disable clks if exist */
> > +   if (priv->clks) {
> > +   clk_bulk_disable(priv->num_clks, priv->clks);
> > +   clk_bulk_unprepare(priv->num_clks, priv->clks);
> 
> clk_bulk_disable_unprepare()

Thank you for the indicate. I'll fix this in v2.

> > +   }
> > +
> > /* disable PM */
> > pm_runtime_put_sync(dev);
> > }
> > @@ -534,6 +553,11 @@ static struct renesas_usbhs_platform_info 
> > *usbhs_parse_dt(struct device *dev)
> > return info;
> >  }
> >
> > +static const struct clk_bulk_data usbhs_rcar3_clks[] = {
> > +   { .id = "hsusb" },
> > +   { .id = "ehci/ohci" },
> > +};
> 
> This structure contains space for the clock pointers, which are not really
> needed here (the struct is copied).
> 
> Perhaps you can replace "struct clk_bulk_data *clks" in struct usbhs_priv
> replace by "struct clk_bulk_data clks[2]", ...
> 
> > +
> >  static int usbhs_probe(struct platform_device *pdev)
> >  {
> > struct renesas_usbhs_platform_info *info = 
> > renesas_usbhs_get_info(pdev);
> > @@ -620,6 +644,15 @@ static int usbhs_probe(struct platform_device *pdev)
> > break;
> > }
> >
> > +   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
> > +   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
> > +   priv->clks = devm_kmemdup(&pdev->dev, usbhs_rcar3_clks,
> > + sizeof(usbhs_rcar3_clks), 
> > GFP_KERNEL);
> > +   if (!priv->clks)
> > +   return -ENOMEM;
> 
> ... and instead of allocating/copying, fill in the clock names here:
> 
> priv->clks[0].id = "hsusb";
> priv->clks[1].id = "ehci/ohci";
> 
> As priv->clks will no longer be a pointer, all checks for it should be
> replaced by checks for priv->num_clks.
> 
> What do you think?

I think your suggestion is better than this patch. So, I'll modify the code in 
v2.

Best regards,
Yoshihiro Shimoda

> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds


[PATCH 0/3] usb: renesas_usbhs: add reset_control and multiple clocks management

2018-08-30 Thread Yoshihiro Shimoda
This patch set is based on Felipe's usb.git / testing/next branch
(the commit id is 5b394b2ddf0347bef56e50c69a58773c94343ff3) with
the following patch:

https://patchwork.kernel.org/patch/10574875/

Yoshihiro Shimoda (3):
  usb: renesas_usbhs: Add reset_control
  dt-bindings: usb: renesas_usbhs: add clock-names property
  usb: renesas_usbhs: Add multiple clocks management

 .../devicetree/bindings/usb/renesas_usbhs.txt  |  2 +
 drivers/usb/renesas_usbhs/common.c | 53 ++
 drivers/usb/renesas_usbhs/common.h |  5 ++
 3 files changed, 60 insertions(+)

-- 
1.9.1



[PATCH 1/3] usb: renesas_usbhs: Add reset_control

2018-08-30 Thread Yoshihiro Shimoda
R-Car Gen3 needs to deassert resets of both host and peripheral.
Since [eo]hci-platform is possible to assert the reset(s) when
the probing failed, renesas_usbhs driver doesn't work correctly
regardless of finished probing. To fix this issue, this patch adds
reset_control on this renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 12 
 drivers/usb/renesas_usbhs/common.h |  2 ++
 2 files changed, 14 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 4310df4..1d355d5 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -12,6 +12,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include "common.h"
@@ -574,6 +575,10 @@ static int usbhs_probe(struct platform_device *pdev)
return PTR_ERR(priv->edev);
}
 
+   priv->rsts = devm_reset_control_array_get_optional_shared(&pdev->dev);
+   if (IS_ERR(priv->rsts))
+   return PTR_ERR(priv->rsts);
+
/*
 * care platform info
 */
@@ -658,6 +663,10 @@ static int usbhs_probe(struct platform_device *pdev)
/* dev_set_drvdata should be called after usbhs_mod_init */
platform_set_drvdata(pdev, priv);
 
+   ret = reset_control_deassert(priv->rsts);
+   if (ret)
+   goto probe_fail_rst;
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -711,6 +720,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   reset_control_assert(priv->rsts);
+probe_fail_rst:
usbhs_mod_remove(priv);
 probe_end_fifo_exit:
usbhs_fifo_remove(priv);
@@ -739,6 +750,7 @@ static int usbhs_remove(struct platform_device *pdev)
pm_runtime_disable(&pdev->dev);
 
usbhs_platform_call(priv, hardware_exit, pdev);
+   reset_control_assert(priv->rsts);
usbhs_mod_remove(priv);
usbhs_fifo_remove(priv);
usbhs_pipe_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index 6137f79..bce7d35 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -10,6 +10,7 @@
 
 #include 
 #include 
+#include 
 #include 
 
 struct usbhs_priv;
@@ -277,6 +278,7 @@ struct usbhs_priv {
struct usbhs_fifo_info fifo_info;
 
struct phy *phy;
+   struct reset_control *rsts;
 };
 
 /*
-- 
1.9.1



[PATCH 3/3] usb: renesas_usbhs: Add multiple clocks management

2018-08-30 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Since [eo]hci-platform disables the reset(s) when the drivers are
removed, renesas_usbhs driver doesn't work correctly. To fix this
issue, this patch adds multiple clocks management on this
renesas_usbhs driver.

Signed-off-by: Yoshihiro Shimoda 
---
 drivers/usb/renesas_usbhs/common.c | 41 ++
 drivers/usb/renesas_usbhs/common.h |  3 +++
 2 files changed, 44 insertions(+)

diff --git a/drivers/usb/renesas_usbhs/common.c 
b/drivers/usb/renesas_usbhs/common.c
index 1d355d5..00d32d1 100644
--- a/drivers/usb/renesas_usbhs/common.c
+++ b/drivers/usb/renesas_usbhs/common.c
@@ -5,6 +5,7 @@
  * Copyright (C) 2011 Renesas Solutions Corp.
  * Kuninori Morimoto 
  */
+#include 
 #include 
 #include 
 #include 
@@ -336,11 +337,23 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, 
int enable)
 {
struct platform_device *pdev = usbhs_priv_to_pdev(priv);
struct device *dev = usbhs_priv_to_dev(priv);
+   int ret;
 
if (enable) {
/* enable PM */
pm_runtime_get_sync(dev);
 
+   /* enable clks if exist */
+   if (priv->clks) {
+   ret = clk_bulk_prepare(priv->num_clks, priv->clks);
+   if (!ret) {
+   ret = clk_bulk_enable(priv->num_clks,
+ priv->clks);
+   if (ret)
+   return;
+   }
+   }
+
/* enable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
@@ -353,6 +366,12 @@ static void usbhsc_power_ctrl(struct usbhs_priv *priv, int 
enable)
/* disable platform power */
usbhs_platform_call(priv, power_ctrl, pdev, priv->base, enable);
 
+   /* disable clks if exist */
+   if (priv->clks) {
+   clk_bulk_disable(priv->num_clks, priv->clks);
+   clk_bulk_unprepare(priv->num_clks, priv->clks);
+   }
+
/* disable PM */
pm_runtime_put_sync(dev);
}
@@ -534,6 +553,11 @@ static struct renesas_usbhs_platform_info 
*usbhs_parse_dt(struct device *dev)
return info;
 }
 
+static const struct clk_bulk_data usbhs_rcar3_clks[] = {
+   { .id = "hsusb" },
+   { .id = "ehci/ohci" },
+};
+
 static int usbhs_probe(struct platform_device *pdev)
 {
struct renesas_usbhs_platform_info *info = renesas_usbhs_get_info(pdev);
@@ -620,6 +644,15 @@ static int usbhs_probe(struct platform_device *pdev)
break;
}
 
+   if (priv->dparam.type == USBHS_TYPE_RCAR_GEN3 ||
+   priv->dparam.type == USBHS_TYPE_RCAR_GEN3_WITH_PLL) {
+   priv->clks = devm_kmemdup(&pdev->dev, usbhs_rcar3_clks,
+ sizeof(usbhs_rcar3_clks), GFP_KERNEL);
+   if (!priv->clks)
+   return -ENOMEM;
+   priv->num_clks = ARRAY_SIZE(usbhs_rcar3_clks);
+   }
+
/* set driver callback functions for platform */
dfunc   = &info->driver_callback;
dfunc->notify_hotplug   = usbhsc_drvcllbck_notify_hotplug;
@@ -667,6 +700,12 @@ static int usbhs_probe(struct platform_device *pdev)
if (ret)
goto probe_fail_rst;
 
+   if (priv->clks) {
+   ret = clk_bulk_get(&pdev->dev, priv->num_clks, priv->clks);
+   if (ret == -EPROBE_DEFER)
+   goto probe_fail_clks;
+   }
+
/*
 * deviece reset here because
 * USB device might be used in boot loader.
@@ -720,6 +759,8 @@ static int usbhs_probe(struct platform_device *pdev)
return ret;
 
 probe_end_mod_exit:
+   clk_bulk_put(priv->num_clks, priv->clks);
+probe_fail_clks:
reset_control_assert(priv->rsts);
 probe_fail_rst:
usbhs_mod_remove(priv);
diff --git a/drivers/usb/renesas_usbhs/common.h 
b/drivers/usb/renesas_usbhs/common.h
index bce7d35..9105ee0 100644
--- a/drivers/usb/renesas_usbhs/common.h
+++ b/drivers/usb/renesas_usbhs/common.h
@@ -8,6 +8,7 @@
 #ifndef RENESAS_USB_DRIVER_H
 #define RENESAS_USB_DRIVER_H
 
+#include 
 #include 
 #include 
 #include 
@@ -279,6 +280,8 @@ struct usbhs_priv {
 
struct phy *phy;
struct reset_control *rsts;
+   struct clk_bulk_data *clks;
+   int num_clks;
 };
 
 /*
-- 
1.9.1



[PATCH 2/3] dt-bindings: usb: renesas_usbhs: add clock-names property

2018-08-30 Thread Yoshihiro Shimoda
R-Car Gen3 needs to enable clocks of both host and peripheral.
Otherwise, other side device cannot work correctly. So, this patch
adds a property of clock-names for R-Car Gen3 as an optional.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/devicetree/bindings/usb/renesas_usbhs.txt | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt 
b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
index 087140a..a8fa3ec 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usbhs.txt
@@ -37,6 +37,8 @@ Optional properties:
   - dmas: Must contain a list of references to DMA specifiers.
   - dma-names : named "ch%d", where %d is the channel number ranging from zero
 to the number of channels (DnFIFOs) minus one.
+  - clock-names: For a "renesas,rcar-gen3-usbhs" compatible device,
+"hsusb" and "ehci/ohci" can be set.
 
 Example:
usbhs: usb@e659 {
-- 
1.9.1



RE: [PATCH 2/3] usb: renesas_usbhs: enable DVSE interrupt

2018-08-30 Thread Yoshihiro Shimoda
Hi Eugeniu,

> From: Eugeniu Rosca, Sent: Thursday, August 30, 2018 7:54 PM
> 
> Commit [1] enabled the possibility of checking the DVST (Device State
> Transition) bit of INTSTS0 (Interrupt Status Register 0) and calling
> the irq_dev_state() handler if the DVST bit is set. But neither
> commit [1] nor commit [2] actually enabled the DVSE (Device State
> Transition Interrupt Enable) bit in the INTENB0 (Interrupt Enable
> Register 0). As a consequence, irq_dev_state() handler is getting
> called as a side effect of other (non-DVSE) interrupts being fired,
> which definitely can't be relied upon, if DVST notifications are of
> any value.
> 
> Why this doesn't hurt is because usbhsg_irq_dev_state() currently
> doesn't do much except of a dev_dbg(). Once more work is added to
> the handler (e.g. detecting device "Suspended" state and notifying
> other USB gadget components about it), enabling DVSE becomes a hard
> requirement. Do it in a standalone commit for better visibility and
> clear explanation.
> 
> [1] f1407d5c6624 ("usb: renesas_usbhs: Add Renesas USBHS common code")
> [2] 2f98382dcdfe ("usb: renesas_usbhs: Add Renesas USBHS Gadget")
> 
> Signed-off-by: Eugeniu Rosca 
> ---

Thank you for the patch!

Reviewed-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda



RE: [PATCH 3/3] usb: renesas_usbhs: add suspend event support in gadget mode

2018-08-30 Thread Yoshihiro Shimoda
Hi Eugeniu,

Thank you very much for the patches!

> From: Eugeniu Rosca, Sent: Thursday, August 30, 2018 7:54 PM
> 
> From: Veeraiyan Chidambaram 
> 
> When RCAR3 is in Gadget mode, if host is detached an interrupt
> will be generated and Suspended state bit is set in interrupt status
> register. Interrupt handler will call driver->suspend(composite_suspend)
> if suspended state bit is set. composite_suspend will call
> ffs_func_suspend which will post FUNCTIONFS_SUSPEND and will be consumed
> by user space application via /dev/ep0.
> 
> To be able to detect host detach, extend the DVSQ_MASK to cover the
> Suspended bit of the DVSQ[2:0] bitfield from the Interrupt Status
> Register 0 (INTSTS0) register and perform appropriate action in the
> DVST interrupt handler (usbhsg_irq_dev_state).
> 
> Without this commit, disconnection of the phone from R-Car-H3 ES2.0
> Salvator-X CN9 port is not recognized and reverse role switch does
> not not happen. If phone is connected again it does not enumerate.

I think s/not not/not/.

> With this commit, disconnection will be recognized and reverse role
> switch will happen. If phone is connected again it will enumerate

IIUC, reverse role switch will happen by a user space application.
Is it correct?

> properly and will become visible in the output of 'lsusb'.
> 
> Signed-off-by: Veeraiyan Chidambaram 
> Signed-off-by: Eugeniu Rosca 
> ---
>  drivers/usb/renesas_usbhs/common.h |  3 ++-
>  drivers/usb/renesas_usbhs/mod_gadget.c | 13 ++---
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.h 
> b/drivers/usb/renesas_usbhs/common.h
> index 6e02aa3e287f..9eb69d2a4640 100644
> --- a/drivers/usb/renesas_usbhs/common.h
> +++ b/drivers/usb/renesas_usbhs/common.h
> @@ -163,11 +163,12 @@ struct usbhs_priv;
>  #define VBSTS(1 << 7)/* VBUS_0 and VBUSIN_0 Input Status */
>  #define VALID(1 << 3)/* USB Request Receive */
> 
> -#define DVSQ_MASK(0x3 << 4)  /* Device State */
> +#define DVSQ_MASK(0x7 << 4)  /* Device State */
>  #define  POWER_STATE (0 << 4)
>  #define  DEFAULT_STATE   (1 << 4)
>  #define  ADDRESS_STATE   (2 << 4)
>  #define  CONFIGURATION_STATE (3 << 4)
> +#define  SUSPENDED_STATE (4 << 4)
> 
>  #define CTSQ_MASK(0x7)   /* Control Transfer Stage */
>  #define  IDLE_SETUP_STAGE0   /* Idle stage or setup stage */
> diff --git a/drivers/usb/renesas_usbhs/mod_gadget.c 
> b/drivers/usb/renesas_usbhs/mod_gadget.c
> index c068b673420b..1af8034d17c5 100644
> --- a/drivers/usb/renesas_usbhs/mod_gadget.c
> +++ b/drivers/usb/renesas_usbhs/mod_gadget.c
> @@ -465,12 +465,19 @@ static int usbhsg_irq_dev_state(struct usbhs_priv *priv,
>  {
>   struct usbhsg_gpriv *gpriv = usbhsg_priv_to_gpriv(priv);
>   struct device *dev = usbhsg_gpriv_to_dev(gpriv);
> + int state = usbhs_status_get_device_state(irq_state);
> 
>   gpriv->gadget.speed = usbhs_bus_get_speed(priv);
> 
> - dev_dbg(dev, "state = %x : speed : %d\n",
> - usbhs_status_get_device_state(irq_state),
> - gpriv->gadget.speed);
> + dev_dbg(dev, "state = %x : speed : %d\n", state, gpriv->gadget.speed);
> +
> + if (gpriv->driver &&
> + gpriv->driver->suspend &&
> + gpriv->gadget.speed != USB_SPEED_UNKNOWN &&
> + (state & SUSPENDED_STATE)) {
> + gpriv->driver->suspend(&gpriv->gadget);
> + usb_gadget_set_state(&gpriv->gadget, USB_STATE_SUSPENDED);
> + }

I think we also call gpriv->driver->resume() somehow. Otherwise,
/sys/devices/platform/soc/e659.usb/gadget/suspended value on R-Car H3
keeps 1 forever after the driver detects suspend state.

If we call the ->resume(), I think we also call usb_gadget_set_state() with
other USB_STATE_* value. So, I'm thinking if usbhs_status_get_device_state() 
returns
enum usb_device_state value, it's useful.

What do you think?

Best regards,
Yoshihiro Shimoda

>   return 0;
>  }
> --
> 2.18.0



RE: [PATCH] usb: host: xhci-rcar: Add support for r8a774a1

2018-08-26 Thread Yoshihiro Shimoda
Hi Biju-san,

Thank you for the patch!

> From: Biju Das, Sent: Friday, August 24, 2018 7:17 PM
> 
> This patch adds support for r8a774a1 (RZ/G2M).
> 
> Signed-off-by: Biju Das 
> Reviewed-by: Fabrizio Castro 
> ---
>  drivers/usb/host/xhci-rcar.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/host/xhci-rcar.c b/drivers/usb/host/xhci-rcar.c
> index f33ffc2..c906b13 100644
> --- a/drivers/usb/host/xhci-rcar.c
> +++ b/drivers/usb/host/xhci-rcar.c
> @@ -72,6 +72,10 @@ MODULE_FIRMWARE(XHCI_RCAR_FIRMWARE_NAME_V3);
> 
>  static const struct soc_device_attribute rcar_quirks_match[]  = {
>   {
> + .soc_id = "r8a774a1",
> + .data = (void *)RCAR_XHCI_FIRMWARE_V3,
> + },
> + {

I also don't think you need this patch actually because
you submitted adding a bindings patch for usb-xhci [1]
and it had "renesas,rcar-gen3-xhci" for RZ/G2.
In other words, if a xhci node of RZ/G2 dtsi has "renesas,rcar-gen3-xhci" 
compatible,
this can probe the xhci-plat/rcar driver with the firmware V3.

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

Best regards,
Yoshihiro Shimoda

>   .soc_id = "r8a7795", .revision = "ES1.*",
>   .data = (void *)RCAR_XHCI_FIRMWARE_V2,
>   },
> --
> 2.7.4



RE: [PATCH] usb: renesas_usbhs: Add a compatible string for r8a774a1

2018-08-26 Thread Yoshihiro Shimoda
Hi Biju-san,

Thank you for the patch!

> From: Biju Das, Sent: Friday, August 24, 2018 7:09 PM
> 
> This patch adds support for r8a774a1 (RZ/G2M).
> 
> Signed-off-by: Biju Das 
> Reviewed-by: Fabrizio Castro 
> ---
>  drivers/usb/renesas_usbhs/common.c | 4 
>  1 file changed, 4 insertions(+)
> 
> diff --git a/drivers/usb/renesas_usbhs/common.c 
> b/drivers/usb/renesas_usbhs/common.c
> index 4310df4..f1a1694 100644
> --- a/drivers/usb/renesas_usbhs/common.c
> +++ b/drivers/usb/renesas_usbhs/common.c
> @@ -458,6 +458,10 @@ static int usbhsc_drvcllbck_notify_hotplug(struct 
> platform_device *pdev)
>   */
>  static const struct of_device_id usbhs_of_match[] = {
>   {
> + .compatible = "renesas,usbhs-r8a774a1",
> + .data = (void *)USBHS_TYPE_RCAR_GEN3,
> + },
> + {

I don't think you need this adding entry for r8a774a1 actually because
you also submitted a bindings patch [1] and it had "renesas,rcar-gen3-usbhs" 
for RZ/G2.

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

Best regards,
Yoshihiro Shimoda

>   .compatible = "renesas,usbhs-r8a7790",
>   .data = (void *)USBHS_TYPE_RCAR_GEN2,
>   },
> --
> 2.7.4



RE: linux-next build broken for renesas-usb3?

2018-08-21 Thread Yoshihiro Shimoda
Hi,

> From: John Garry, Sent: Tuesday, August 21, 2018 7:30 PM
> 
> On 20/08/2018 04:15, Yoshihiro Shimoda wrote:
> > Hi John, Felipe,
> >
> >> From: John Garry, Sent: Wednesday, August 15, 2018 9:55 PM
> >>
> >> On 10/08/2018 07:24, Felipe Balbi wrote:
> >>>
> >>> Hi Yoshihiro,
> >>>
> >>
> >> I see Arnd is fixing it here:
> >> https://lore.kernel.org/patchwork/patch/974025/
> >>
> >> I am not on that thread, so will comment here:
> >>   >tristate 'Renesas USB3.0 Peripheral controller'
> >>   >depends on ARCH_RENESAS || COMPILE_TEST
> >>   >depends on EXTCON
> >>   > +  depends on USB || !USB
> >>
> >> Considering this following comment in the same Makefile, is this ok:
> >> NOTE:  Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !!
> >
> > Thank you very much for your reports and sorry for the delayed response.
> > # I had a vacation in last week.
> >
> > I submitted a patch to fix the issue as below:
> > https://patchwork.kernel.org/patch/10569847/
> >
> 
> ok, thanks. It would have been better to cc me on that.

Thank you for your confirmation!
And I'm sorry for missing your email address to cc on that...

Best regards,
Yoshihiro Shimoda

> John
> 
> > I think this patch can resolve the NOTE.
> >
> > Best regards,
> > Yoshihiro Shimoda
> >
> >
> >
> 



RE: linux-next build broken for renesas-usb3?

2018-08-19 Thread Yoshihiro Shimoda
Hi John, Felipe,

> From: John Garry, Sent: Wednesday, August 15, 2018 9:55 PM
> 
> On 10/08/2018 07:24, Felipe Balbi wrote:
> >
> > Hi Yoshihiro,
> >
> 
> I see Arnd is fixing it here:
> https://lore.kernel.org/patchwork/patch/974025/
> 
> I am not on that thread, so will comment here:
>   >   tristate 'Renesas USB3.0 Peripheral controller'
>   >   depends on ARCH_RENESAS || COMPILE_TEST
>   >   depends on EXTCON
>   > + depends on USB || !USB
> 
> Considering this following comment in the same Makefile, is this ok:
> NOTE:  Gadget support ** DOES NOT ** depend on host-side CONFIG_USB !!

Thank you very much for your reports and sorry for the delayed response.
# I had a vacation in last week.

I submitted a patch to fix the issue as below:
https://patchwork.kernel.org/patch/10569847/

I think this patch can resolve the NOTE.

Best regards,
Yoshihiro Shimoda



RE: [PATCH 21/22] USB: gadget: udc: renesas_usb3: no need to check return value of debugfs_create functions

2018-05-30 Thread Yoshihiro Shimoda
> From: Greg Kroah-Hartman, Sent: Wednesday, May 30, 2018 12:31 AM
> 
> When calling debugfs functions, there is no need to ever check the
> return value.  The function can work or not, but the code logic should
> never do something different based on this.
> 
> Cc: Felipe Balbi 
> Cc: Yoshihiro Shimoda 
> Cc: Simon Horman 
> Cc: Geert Uytterhoeven 
> Signed-off-by: Greg Kroah-Hartman 
> ---

I tested on r8a7795-salvator-xs. So,

Acked-by: Yoshihiro Shimoda 

Best regards,
Yoshihiro Shimoda

--
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 v5] usb: gadget: udc: renesas_usb3: Add register of usb role switch

2018-05-25 Thread Yoshihiro Shimoda
This patch adds role switch support for R-Car SoCs into the USB 3.0
peripheral driver. Some R-Car SoCs (e.g. R-Car H3) have USB 3.0
dual-role device controller which has the USB 3.0 xHCI host and
Renesas USB 3.0 peripheral.

Unfortunately, the mode change register (DRD_CON) contains
the USB 3.0 peripheral controller side only. So, this renesas_usb3
driver manages the DRD_CON now. However, in peripheral mode, the host
should stop. Also the host hardware needs to reinitialize its own
registers when the mode changes from peripheral to host mode.
Otherwise, the host cannot work correctly (e.g. detect a device
as high-speed).

To achieve this reinitialization by a driver, this driver also
registers a role switch driver to manage the DRD_CON and get
a device pointer of usb 3.0 host from "companion" property of OF.
Then, when the usb role is changed, renesas_usb3_role_switch_set()
will attach/release the xhci-plat driver to reinitialize the host
hardware.

Signed-off-by: Yoshihiro Shimoda 
---
This patch set is based on Felipe's usb.git / testing/next branch
(commit id = 47265c067c0d129f3a0e94bc221293a780af9d78).

I remove RFC on this v5 patch because it's simple and acceptable
for upstream, I think :)

Changes from RFC v4:
 - Use "companion" device tree property simply instead of device_connection
   APIs with OF graph.
 - Merge patch 2 and 3 to one.
 - Revise the commit log (I should had revised this on RFC v4 though).

Changes from RFC v3:
 - Rebase latest usb.git / testing/next branch.
 - Add graph parse into device_connection_find_match().
 - Use workqueue to call _usb3_set_mode() in patch 3.
   (I realized renesas_usb3_role_switch_set() cannot run on atomic because
device_attach() might sleep.)

Changes from RFC v2:
 - Add registering usb role switch into drivers/usb/gadget/udc/renesas_usb3
   because hardware resource (a register) is shared and remove individual
   usb role switch driver/dt-bindings for R-Car.
 - Remove "usb_role_switch_get_by_graph" API because the renesas_usb3 driver
   doesn't need such API now.

Changes from RFC:
 - Remove "device-connection-id" and "usb role switch driver" dt-bingings.
 - Remove drivers/of code.
 - Add a new API for find the connection by using graph on devcon.c and roles.c.
 - Use each new API on the rcar usb role switch and renesas_usb3 drivers.
 - Update the dtsi file for r8a7795.

 drivers/usb/gadget/udc/Kconfig|  1 +
 drivers/usb/gadget/udc/renesas_usb3.c | 84 ++-
 2 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index b838cae..78823cd 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -193,6 +193,7 @@ config USB_RENESAS_USB3
tristate 'Renesas USB3.0 Peripheral controller'
depends on ARCH_RENESAS || COMPILE_TEST
depends on EXTCON && HAS_DMA
+   select USB_ROLE_SWITCH
help
   Renesas USB3.0 Peripheral controller is a USB peripheral controller
   that supports super, high, and full speed USB 3.0 data transfers.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 5caf78b..c1a1824 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -23,6 +23,8 @@
 #include 
 #include 
 #include 
+#include 
+#include 
 
 /* register definitions */
 #define USB3_AXI_INT_STA   0x008
@@ -335,6 +337,11 @@ struct renesas_usb3 {
struct phy *phy;
struct dentry *dentry;
 
+   struct usb_role_switch *role_sw;
+   struct device *host_dev;
+   struct work_struct role_work;
+   enum usb_role role;
+
struct renesas_usb3_ep *usb3_ep;
int num_usb3_eps;
 
@@ -651,7 +658,15 @@ static void usb3_check_vbus(struct renesas_usb3 *usb3)
}
 }
 
-static void usb3_set_mode(struct renesas_usb3 *usb3, bool host)
+static void renesas_usb3_role_work(struct work_struct *work)
+{
+   struct renesas_usb3 *usb3 = container_of(work, struct renesas_usb3,
+role_work);
+
+   usb_role_switch_set_role(usb3->role_sw, usb3->role);
+}
+
+static void _usb3_set_mode(struct renesas_usb3 *usb3, bool host)
 {
if (host)
usb3_clear_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
@@ -659,6 +674,16 @@ static void usb3_set_mode(struct renesas_usb3 *usb3, bool 
host)
usb3_set_bit(usb3, DRD_CON_PERI_CON, USB3_DRD_CON);
 }
 
+static void usb3_set_mode(struct renesas_usb3 *usb3, bool host)
+{
+   if (usb3->role_sw) {
+   usb3->role = host ? USB_ROLE_HOST : USB_ROLE_DEVICE;
+   schedule_work(&usb3->role_work);
+   } else {
+   _usb3_set_mode(usb3, host);
+   }
+}
+
 static void usb3_vbus_out(struct renesas_usb3 *usb3, bool enable)
 {
if (

RE: [PATCH/RFC v4 2/4] usb: gadget: udc: renesas_usb3: Add register of usb role switch

2018-05-24 Thread Yoshihiro Shimoda
Hi Rob, Geert-san,

> From: Geert Uytterhoeven, Sent: Thursday, May 24, 2018 5:18 PM
> 
> Hi Rob,
> 
> On Wed, May 23, 2018 at 5:00 PM, Rob Herring  wrote:

> >>> >  Optional properties:
> >>> >- phys: phandle + phy specifier pair
> >>> >- phy-names: must be "usb"
> >>> > +  - The connection to a usb3.0 host node needs by using OF graph 
> >>> > bindings for
> >>> > +usb role switch.
> >>> > +   - port@0 = USB3.0 host port.
> >>>
> >>> On the host side, this might conflict with the USB connector binding.
> >>>
> >>> I would either make sure this can work with the connector binding by
> >>> having 2 endpoints on the HS or SS port or just use the 'companion'
> >>> property defined in usb-generic.txt.
> >>
> >> I don't understand the first one now... This means the renesas_usb3 should 
> >> follow
> >> USB connector binding and have 2 endpoints for the usb role switch to avoid
> >> the conflict like below?
> >>  - port1@0: Super Speed (SS), present in SS capable connectors (from 
> >> usb-connector.txt).
> >>  - port1@1: USB3.0 host port.
> >
> > I'm confused, SS and USB3.0 are the same essentially. It would be:
> >
> > port@1/endpoint@0: SS host port
> > port@1/endpoint@1: SS device port

Thank you for the comment. It's better than my description.

> >> About the 'companion' in usb-generic.txt, the property intends to be used 
> >> for EHCI or host side
> >> like the commit log [1]. If there is accept to use 'companion' for this 
> >> patch, I think it will
> >> be simple to achieve this role switch feature. However, in last month, I 
> >> submitted a similar patch [2]
> >> that has "renesas,host" property, but I got reply from Andy [3] and Heikki 
> >> [4]. So, I'm
> >> trying to improve the device connection framework [5] now.
> >
> > I think this case is rare enough that we don't need a general solution
> > using OF graph, so I'm fine with a simple, single property to link the
> > 2 nodes. Either reusing "companion" or "renesas,host" is fine by me.
> 
> I'd go for the standard "companion" over "renesas,host"[*].
> 
> [*] Doh, we have another one ("renesas,bonding"), invented when I wasn't
> aware of the existence of "companion" yet...

Thank you for the comments. So, I'll reuse "companion" for it.

Best regards,
Yoshihiro Shimoda

> Gr{oetje,eeting}s,
> 
> Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- 
> ge...@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like 
> that.
> -- Linus Torvalds


RE: [PATCH/RFC v4 2/4] usb: gadget: udc: renesas_usb3: Add register of usb role switch

2018-05-22 Thread Yoshihiro Shimoda
Hi Rob,

Thank you for the review!

> From: Rob Herring, Sent: Wednesday, May 23, 2018 2:13 AM
> 
> On Tue, May 22, 2018 at 09:01:07PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds role switch support for R-Car SoCs into the USB 3.0
> > peripheral driver. Some R-Car SoCs (e.g. R-Car H3) have USB 3.0
> > dual-role device controller which has the USB 3.0 xHCI host and
> > Renesas USB 3.0 peripheral.
> >
> > Unfortunately, the mode change register contains the USB 3.0 peripheral
> > controller side only. So, the USB 3.0 peripheral driver (renesas_usb3)
> > manages this register now. However, in peripheral mode, the host
> > should stop. Also the host hardware needs to reinitialize its own
> > registers when the mode changes from peripheral to host mode.
> > Otherwise, the host cannot work correctly (e.g. detect a device as
> > high-speed).
> >
> > To achieve this by a driver, this role switch driver manages
> > the mode change register and attach/release the xhci-plat driver.
> >
> > Signed-off-by: Yoshihiro Shimoda 
> > ---
> >  .../devicetree/bindings/usb/renesas_usb3.txt   | 15 
> 
> Please split bindings to a separate patch.

Oops. I got it.

> >  drivers/usb/gadget/udc/Kconfig |  1 +
> >  drivers/usb/gadget/udc/renesas_usb3.c  | 82 
> > ++
> >  3 files changed, 98 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > index 2c071bb5..f6105aa 100644
> > --- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > +++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
> > @@ -19,6 +19,9 @@ Required properties:
> >  Optional properties:
> >- phys: phandle + phy specifier pair
> >- phy-names: must be "usb"
> > +  - The connection to a usb3.0 host node needs by using OF graph bindings 
> > for
> > +usb role switch.
> > +   - port@0 = USB3.0 host port.
> 
> On the host side, this might conflict with the USB connector binding.
> 
> I would either make sure this can work with the connector binding by
> having 2 endpoints on the HS or SS port or just use the 'companion'
> property defined in usb-generic.txt.

I don't understand the first one now... This means the renesas_usb3 should 
follow
USB connector binding and have 2 endpoints for the usb role switch to avoid
the conflict like below?
 - port1@0: Super Speed (SS), present in SS capable connectors (from 
usb-connector.txt).
 - port1@1: USB3.0 host port.

About the 'companion' in usb-generic.txt, the property intends to be used for 
EHCI or host side
like the commit log [1]. If there is accept to use 'companion' for this patch, 
I think it will
be simple to achieve this role switch feature. However, in last month, I 
submitted a similar patch [2]
that has "renesas,host" property, but I got reply from Andy [3] and Heikki [4]. 
So, I'm
trying to improve the device connection framework [5] now.

[1]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/Documentation/devicetree/bindings/usb/generic.txt?h=v4.17-rc6&id=5095cb89c62acc78b4cfaeb9a4072979d010510a

[2]
https://www.spinics.net/lists/linux-usb/msg167773.html

[3]
https://www.spinics.net/lists/linux-usb/msg167780.html

[4]
https://www.spinics.net/lists/linux-usb/msg167806.html

[5]
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/driver-api/device_connection.rst

Best regards,
Yoshihiro Shimoda

> Rob
--
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/RFC v4 2/4] usb: gadget: udc: renesas_usb3: Add register of usb role switch

2018-05-22 Thread Yoshihiro Shimoda
This patch adds role switch support for R-Car SoCs into the USB 3.0
peripheral driver. Some R-Car SoCs (e.g. R-Car H3) have USB 3.0
dual-role device controller which has the USB 3.0 xHCI host and
Renesas USB 3.0 peripheral.

Unfortunately, the mode change register contains the USB 3.0 peripheral
controller side only. So, the USB 3.0 peripheral driver (renesas_usb3)
manages this register now. However, in peripheral mode, the host
should stop. Also the host hardware needs to reinitialize its own
registers when the mode changes from peripheral to host mode.
Otherwise, the host cannot work correctly (e.g. detect a device as
high-speed).

To achieve this by a driver, this role switch driver manages
the mode change register and attach/release the xhci-plat driver.

Signed-off-by: Yoshihiro Shimoda 
---
 .../devicetree/bindings/usb/renesas_usb3.txt   | 15 
 drivers/usb/gadget/udc/Kconfig |  1 +
 drivers/usb/gadget/udc/renesas_usb3.c  | 82 ++
 3 files changed, 98 insertions(+)

diff --git a/Documentation/devicetree/bindings/usb/renesas_usb3.txt 
b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
index 2c071bb5..f6105aa 100644
--- a/Documentation/devicetree/bindings/usb/renesas_usb3.txt
+++ b/Documentation/devicetree/bindings/usb/renesas_usb3.txt
@@ -19,6 +19,9 @@ Required properties:
 Optional properties:
   - phys: phandle + phy specifier pair
   - phy-names: must be "usb"
+  - The connection to a usb3.0 host node needs by using OF graph bindings for
+usb role switch.
+   - port@0 = USB3.0 host port.
 
 Example of R-Car H3 ES1.x:
usb3_peri0: usb@ee02 {
@@ -27,6 +30,12 @@ Example of R-Car H3 ES1.x:
reg = <0 0xee02 0 0x400>;
interrupts = ;
clocks = <&cpg CPG_MOD 328>;
+
+   port {
+   usb3_peri0_ep: endpoint {
+   remote-endpoint = <&usb3_host0_ep>;
+   };
+   };
};
 
usb3_peri1: usb@ee06 {
@@ -35,4 +44,10 @@ Example of R-Car H3 ES1.x:
reg = <0 0xee06 0 0x400>;
interrupts = ;
clocks = <&cpg CPG_MOD 327>;
+
+   port {
+   usb3_peri1_ep: endpoint {
+   remote-endpoint = <&usb3_host1_ep>;
+   };
+   };
};
diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
index b838cae..78823cd 100644
--- a/drivers/usb/gadget/udc/Kconfig
+++ b/drivers/usb/gadget/udc/Kconfig
@@ -193,6 +193,7 @@ config USB_RENESAS_USB3
tristate 'Renesas USB3.0 Peripheral controller'
depends on ARCH_RENESAS || COMPILE_TEST
depends on EXTCON && HAS_DMA
+   select USB_ROLE_SWITCH
help
   Renesas USB3.0 Peripheral controller is a USB peripheral controller
   that supports super, high, and full speed USB 3.0 data transfers.
diff --git a/drivers/usb/gadget/udc/renesas_usb3.c 
b/drivers/usb/gadget/udc/renesas_usb3.c
index 5caf78b..9667a5e 100644
--- a/drivers/usb/gadget/udc/renesas_usb3.c
+++ b/drivers/usb/gadget/udc/renesas_usb3.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /* register definitions */
 #define USB3_AXI_INT_STA   0x008
@@ -335,6 +336,9 @@ struct renesas_usb3 {
struct phy *phy;
struct dentry *dentry;
 
+   struct usb_role_switch *role_sw;
+   struct device *host_dev;
+
struct renesas_usb3_ep *usb3_ep;
int num_usb3_eps;
 
@@ -2302,6 +2306,41 @@ static int renesas_usb3_set_selfpowered(struct 
usb_gadget *gadget, int is_self)
.set_selfpowered= renesas_usb3_set_selfpowered,
 };
 
+static enum usb_role renesas_usb3_role_switch_get(struct device *dev)
+{
+   struct renesas_usb3 *usb3 = dev_get_drvdata(dev);
+   enum usb_role cur_role;
+
+   pm_runtime_get_sync(dev);
+   cur_role = usb3_is_host(usb3) ? USB_ROLE_HOST : USB_ROLE_DEVICE;
+   pm_runtime_put(dev);
+
+   return cur_role;
+}
+
+static int renesas_usb3_role_switch_set(struct device *dev,
+   enum usb_role role)
+{
+   struct renesas_usb3 *usb3 = dev_get_drvdata(dev);
+   struct device *host = usb3->host_dev;
+   enum usb_role cur_role = renesas_usb3_role_switch_get(dev);
+
+   pm_runtime_get_sync(dev);
+   if (cur_role == USB_ROLE_HOST && role == USB_ROLE_DEVICE) {
+   device_release_driver(host);
+   usb3_set_mode(usb3, false);
+   } else if (cur_role == USB_ROLE_DEVICE && role == USB_ROLE_HOST) {
+   /* Must set the mode before device_attach of the host */
+   usb3_set_mode(usb3, true);
+   /* This device_attach() might sleep */
+   if (device_attach(host) < 0)
+   dev_er

[PATCH/RFC v4 1/4] base: devcon: add graph parse in device_connection_find_match()

2018-05-22 Thread Yoshihiro Shimoda
This patch adds graph parsing in device_connection_find_match().
The match function will be called with fwnode pointer in struct
device_connection. So, a caller can check the matching by using it.

Signed-off-by: Yoshihiro Shimoda 
---
 Documentation/driver-api/device_connection.rst |  2 +-
 drivers/base/devcon.c  | 15 +++
 include/linux/device.h |  2 ++
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/Documentation/driver-api/device_connection.rst 
b/Documentation/driver-api/device_connection.rst
index affbc556..cc6b1da 100644
--- a/Documentation/driver-api/device_connection.rst
+++ b/Documentation/driver-api/device_connection.rst
@@ -19,7 +19,7 @@ Device connections alone do not create a dependency between 
the two devices.
 They are only descriptions which are not tied to either of the devices 
directly.
 A dependency between the two devices exists only if one of the two endpoint
 devices requests a reference to the other. The descriptions themselves can be
-defined in firmware (not yet supported) or they can be built-in.
+defined in firmware or they can be built-in.
 
 Usage
 -
diff --git a/drivers/base/devcon.c b/drivers/base/devcon.c
index d427e80..374bb39 100644
--- a/drivers/base/devcon.c
+++ b/drivers/base/devcon.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 
 static DEFINE_MUTEX(devcon_lock);
 static LIST_HEAD(devcon_list);
@@ -31,10 +32,24 @@ void *device_connection_find_match(struct device *dev, 
const char *con_id,
struct device_connection *con;
void *ret = NULL;
int ep;
+   struct device_connection graph;
+   struct fwnode_handle *fwnode_ep;
+   struct fwnode_handle *remote;
 
if (!match)
return NULL;
 
+   fwnode_graph_for_each_endpoint(dev->fwnode, fwnode_ep) {
+   remote = fwnode_graph_get_remote_port_parent(fwnode_ep);
+   if (!remote)
+   continue;
+
+   graph.fwnode = remote;
+   ret = match(&graph, 0, data);
+   if (!IS_ERR(ret))
+   return ret;
+   }
+
mutex_lock(&devcon_lock);
 
list_for_each_entry(con, &devcon_list, list) {
diff --git a/include/linux/device.h b/include/linux/device.h
index 0059b99..175907b 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -734,11 +734,13 @@ struct device_dma_parameters {
  * struct device_connection - Device Connection Descriptor
  * @endpoint: The names of the two devices connected together
  * @id: Unique identifier for the connection
+ * @fwnode: fwnode pointer for finding a connection from graph
  * @list: List head, private, for internal use only
  */
 struct device_connection {
const char  *endpoint[2];
const char  *id;
+   struct fwnode_handle*fwnode;
struct list_headlist;
 };
 
-- 
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


  1   2   3   4   5   6   7   8   >