Re: [PATCH v2 1/4] xhci: Introduce xhci_init_driver()

2014-08-19 Thread Yoshihiro Shimoda
Hi,

(2014/08/19 1:12), Andrew Bresticker wrote:
 Since the struct hc_driver is mostly the same across the xhci-pci,
 xhci-plat, and the upcoming xhci-tegra driver, introduce the function
 xhci_init_driver() which will populate the hc_driver with the default
 xHCI operations.  The caller must supply a setup function which will
 be used as the hc_driver's reset callback.
 
 Note that xhci-plat also overrides the default -start() callback so
 that it can do rcar-specific initialization.
 
 Signed-off-by: Andrew Bresticker abres...@chromium.org
 ---
 Changes from v1:
  - rebased on changes introduced by xhci-rcar driver
 snip 
 @@ -300,6 +249,8 @@ MODULE_ALIAS(platform:xhci-hcd);
  
  int xhci_register_plat(void)
  {
 + xhci_init_driver(xhci_plat_hc_driver, xhci_plat_setup);
 + xhci_plat_hc_drver.start = xhci_plat_start;

Thank you for the care of xhci-rcar driver.
However, this xhci_plat_hc_drver should be xhci_plat_hc_driver.

After I modified it by myself, I could build the xhci-plat-hcd.ko in my 
environment.

Best regards,
Yoshihiro Shimoda
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH] usb: gadget: USB_RENESAS_USBHS_UDC should depend on HAS_DMA

2014-09-03 Thread Yoshihiro Shimoda
Hi Geert,

(2014/08/30 4:31), Geert Uytterhoeven wrote:
 If NO_DMA=y:
 
 drivers/built-in.o: In function `usbhsg_dma_map_ctrl':
 mod_gadget.c:(.text+0x53b226): undefined reference to `usb_gadget_map_request'
 mod_gadget.c:(.text+0x53b242): undefined reference to 
 `usb_gadget_unmap_request'
 
 Signed-off-by: Geert Uytterhoeven ge...@linux-m68k.org
 ---
  drivers/usb/gadget/udc/Kconfig | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
 
 diff --git a/drivers/usb/gadget/udc/Kconfig b/drivers/usb/gadget/udc/Kconfig
 index 5151f947a4f5..00171d436cf8 100644
 --- a/drivers/usb/gadget/udc/Kconfig
 +++ b/drivers/usb/gadget/udc/Kconfig
 @@ -163,7 +163,7 @@ config USB_R8A66597
  
  config USB_RENESAS_USBHS_UDC
   tristate 'Renesas USBHS controller'
 - depends on USB_RENESAS_USBHS
 + depends on USB_RENESAS_USBHS  HAS_DMA
   help
  Renesas USBHS is a discrete USB host and peripheral controller chip
  that supports both full and high speed USB 2.0 data transfers.
 

Acked-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com

Best regards,
Yoshihiro Shimoda

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


Re: [PATCH v2] usb: renesas_usbhs: fix driver dependencies

2014-09-03 Thread Yoshihiro Shimoda
(2014/09/02 8:39), Simon Horman wrote:
 On Mon, Sep 01, 2014 at 06:40:50PM +0200, Geert Uytterhoeven wrote:
 On Mon, Sep 1, 2014 at 4:24 PM, Bartlomiej Zolnierkiewicz
 b.zolnier...@samsung.com wrote:
 Renesas USBHS controller support should be available only on
 Renesas ARM SoCs and SuperH architecture.

 Signed-off-by: Bartlomiej Zolnierkiewicz b.zolnier...@samsung.com
 Acked-by: Kyungmin Park kyungmin.p...@samsung.com
 Cc: Simon Horman ho...@verge.net.au
 Cc: Magnus Damm magnus.d...@gmail.com
 ---
 v2:
 - s/ARCH_SH/SUPERH/ (thanks to Sergei Shtylyov)

 Acked-by: Geert Uytterhoeven geert+rene...@glider.be
 
 Acked-by: Simon Horman horms+rene...@verge.net.au

Acked-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com

Best regards,
Yoshihiro Shimoda

 --
 To unsubscribe from this list: send the line unsubscribe linux-sh in
 the body of a message to majord...@vger.kernel.org
 More majordomo info at  http://vger.kernel.org/majordomo-info.html
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] phy: phy-rcar-gen2: Fix USBHS_UGSTS_LOCK value

2015-04-02 Thread Yoshihiro Shimoda
According to the technical update (No. TN-RCS-B011A/E), the UGSTS LOCK
bit location is bit 8, not bits 1 and 0. It also says that the register
address offset of UGSTS is 0x88, not 0x90.
So, this patch fixes the USBHS_UGSTS_LOCK value and some comments.

Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com
---
 drivers/phy/phy-rcar-gen2.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen2.c b/drivers/phy/phy-rcar-gen2.c
index 778276a..97d45f4 100644
--- a/drivers/phy/phy-rcar-gen2.c
+++ b/drivers/phy/phy-rcar-gen2.c
@@ -23,7 +23,7 @@
 #define USBHS_LPSTS0x02
 #define USBHS_UGCTRL   0x80
 #define USBHS_UGCTRL2  0x84
-#define USBHS_UGSTS0x88/* The manuals have 0x90 */
+#define USBHS_UGSTS0x88/* From technical update */
 
 /* Low Power Status register (LPSTS) */
 #define USBHS_LPSTS_SUSPM  0x4000
@@ -41,7 +41,7 @@
 #define USBHS_UGCTRL2_USB0SEL_HS_USB   0x0030
 
 /* USB General status register (UGSTS) */
-#define USBHS_UGSTS_LOCK   0x0300 /* The manuals have 0x3 */
+#define USBHS_UGSTS_LOCK   0x0100 /* From technical update */
 
 #define PHYS_PER_CHANNEL   2
 
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] phy: phy-rcar-gen2: Fix USBHS_UGSTS_LOCK value

2015-05-08 Thread Yoshihiro Shimoda
Hi Kishon,

 Sent: Thursday, April 02, 2015 5:01 PM
 
 According to the technical update (No. TN-RCS-B011A/E), the UGSTS LOCK
 bit location is bit 8, not bits 1 and 0. It also says that the register
 address offset of UGSTS is 0x88, not 0x90.
 So, this patch fixes the USBHS_UGSTS_LOCK value and some comments.
 
 Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com

Would you apply this patch to your repository?
I tried to apply this patch on the current fixes branch of linux-phy today,
this patch could be applied without any error.

Best regards,
Yoshihiro Shimoda

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] phy: phy-rcar-gen2: Fix USBHS_UGSTS_LOCK value

2015-05-08 Thread Yoshihiro Shimoda
Hi,

 On Friday 08 May 2015 12:54 PM, Yoshihiro Shimoda wrote:
  Hi Kishon,
 
  Sent: Thursday, April 02, 2015 5:01 PM
 
  According to the technical update (No. TN-RCS-B011A/E), the UGSTS LOCK
  bit location is bit 8, not bits 1 and 0. It also says that the register
  address offset of UGSTS is 0x88, not 0x90.
  So, this patch fixes the USBHS_UGSTS_LOCK value and some comments.
 
  Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com
 
  Would you apply this patch to your repository?
  I tried to apply this patch on the current fixes branch of linux-phy today,
  this patch could be applied without any error.
 
 applied now.

Thank you very much for the prompt reply!

Best regards,
Yoshihiro Shimoda

 Thanks
 Kishon
 
  Best regards,
  Yoshihiro Shimoda
 
--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] phy: rcar-gen2: Add support for R-Car E2

2015-05-18 Thread Yoshihiro Shimoda
This patch adds a compatible string to support for R-Car E2.

Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com
---
 Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt | 1 +
 drivers/phy/phy-rcar-gen2.c | 1 +
 2 files changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt
index 00fc52a..d564ba4 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen2-phy.txt
@@ -6,6 +6,7 @@ This file provides information on what the device node for the 
R-Car generation
 Required properties:
 - compatible: renesas,usb-phy-r8a7790 if the device is a part of R8A7790 SoC.
  renesas,usb-phy-r8a7791 if the device is a part of R8A7791 SoC.
+ renesas,usb-phy-r8a7794 if the device is a part of R8A7794 SoC.
 - reg: offset and length of the register block.
 - #address-cells: number of address cells for the USB channel subnodes, must
  be 1.
diff --git a/drivers/phy/phy-rcar-gen2.c b/drivers/phy/phy-rcar-gen2.c
index f47bfd8..0050301 100644
--- a/drivers/phy/phy-rcar-gen2.c
+++ b/drivers/phy/phy-rcar-gen2.c
@@ -195,6 +195,7 @@ static struct phy_ops rcar_gen2_phy_ops = {
 static const struct of_device_id rcar_gen2_phy_match_table[] = {
{ .compatible = renesas,usb-phy-r8a7790 },
{ .compatible = renesas,usb-phy-r8a7791 },
+   { .compatible = renesas,usb-phy-r8a7794 },
{ }
 };
 MODULE_DEVICE_TABLE(of, rcar_gen2_phy_match_table);
-- 
1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v3] usb: renesas_usbhs: Allow an OTG PHY driver to provide VBUS

2015-07-06 Thread Yoshihiro Shimoda
Hi Phil-san,

 Sent: Thursday, July 02, 2015 7:27 PM
 
 These changes allow a PHY driver to trigger a VBUS interrupt and
 to provide the value of VBUS.
 
 Signed-off-by: Phil Edworthy phil.edwor...@renesas.com

Thank you for the patch!

However, if I tested this patch, a kernel panic happened when
I did rmmod g_mass_storage on koelsch:

root@192:~/usb# rmmod g_mass_storage
Unable to handle kernel NULL pointer dereference at virtual address 0004
pgd = eebd4bc0
[0004] *pgd=
Internal error: Oops: 205 [#1] SMP ARM
Modules linked in: g_mass_storage(-) usb_f_mass_storage libcomposite
CPU: 0 PID: 2496 Comm: rmmod Not tainted 4.1.0-dirty #32
Hardware name: Generic R8A7791 (Flattened Device Tree)
task: eeb64ac0 ti: ee022000 task.ti: ee022000
PC is at usbhs_pkt_pop+0x1c/0x100
LR is at usbhsg_ep_dequeue+0x28/0x40
pc : [c036d934]lr : [c036e364]psr: 2013
sp : ee023e70  ip : ee023e98  fp : ee023e94
r10:   r9 : ee022000  r8 : c00101e4
r7 : 00200200  r6 : 00100100  r5 :   r4 : eeb917f8
r3 : c036e33c  r2 : 0041  r1 : eeb917f8  r0 : 
Flags: nzCv  IRQs on  FIQs on  Mode SVC_32  ISA ARM  Segment user
Control: 30c5307d  Table: 6ebd4bc0  DAC: fffd
Process rmmod (pid: 2496, stack limit = 0xee022210)
Stack: (0xee023e70 to 0xee024000)
3e60: ee1b1400 eeb917c0 00100100 00200200
3e80: c00101e4 ee022000 ee023eac ee023e98 c036e364 c036d924 eeb34180 eeb341c0
3ea0: ee023ecc ee023eb0 bf002f20 c036e348 eeb34180 0001 ee1b1800 eeb341b8
3ec0: ee023eec ee023ed0 bf002fec bf002e5c ee181600 bf01d624 bed3ff0d 0081
3ee0: ee023efc ee023ef0 bf003028 bf002f78 ee023f14 ee023f00 c036fb88 bf003018
3f00: ee181600 bf01d624 ee023f2c ee023f18 c036fc10 c036fb34 bf01d694 7f64cd30
3f20: ee023f3c ee023f30 bf0013d0 c036fbbc ee023f4c ee023f40 bf01d26c bf0013c0
3f40: ee023fa4 ee023f50 c0090bd8 bf01d248 ee023f6c 616d5f67 735f7373 61726f74
3f60: 6567 ee023f70 c00460f4 c052a8c0 c00101e4 ee022010 ee023fb0 ee022000
3f80: ee023fac ee023f90 c00136c4 00046038 0001 7f64cd00  ee023fa8
3fa0: c0010040 c0090adc 0001 7f64cd00 7f64cd30 0800 ccd5c100 ccd5c100
3fc0: 0001 7f64cd00 bed3ff0d 0081 7f64c008  0002 0800
3fe0: bed3fe0c bed3fb98 b6eeb068 b6e4f05c 6010 7f64cd30  
Backtrace:
[c036d918] (usbhs_pkt_pop) from [c036e364] (usbhsg_ep_dequeue+0x28/0x40)
 r9:ee022000 r8:c00101e4 r7:00200200 r6:00100100 r5:eeb917c0 r4:ee1b1400
[c036e33c] (usbhsg_ep_dequeue) from [bf002f20] 
(composite_dev_cleanup+0xd0/0x11c [libcomposite])
 r5:eeb341c0 r4:eeb34180
[bf002e50] (composite_dev_cleanup [libcomposite]) from [bf002fec] 
(__composite_unbind+0x80/0xa0 [libcomposite])
 r7:eeb341b8 r6:ee1b1800 r5:0001 r4:eeb34180
[bf002f6c] (__composite_unbind [libcomposite]) from [bf003028] 
(composite_unbind+0x1c/0x20 [libcomposite])
 r7:0081 r6:bed3ff0d r5:bf01d624 r4:ee181600
[bf00300c] (composite_unbind [libcomposite]) from [c036fb88] 
(usb_gadget_remove_driver+0x60/0x88)
[c036fb28] (usb_gadget_remove_driver) from [c036fc10] 
(usb_gadget_unregister_driver+0x60/0xa0)
 r5:bf01d624 r4:ee181600
[c036fbb0] (usb_gadget_unregister_driver) from [bf0013d0] 
(usb_composite_unregister+0x1c/0x20 [libcomposite])
 r5:7f64cd30 r4:bf01d694
[bf0013b4] (usb_composite_unregister [libcomposite]) from [bf01d26c] 
(msg_cleanup+0x30/0x3c [g_mass_storage])
[bf01d23c] (msg_cleanup [g_mass_storage]) from [c0090bd8] 
(SyS_delete_module+0x108/0x1c4)
[c0090ad0] (SyS_delete_module) from [c0010040] (ret_fast_syscall+0x0/0x3c)
 r5:7f64cd00 r4:0001
Code: e52de004 e8bd4000 e1a05000 e1a04001 (e5907004)
---[ end trace 8152e492b3f02f66 ]---


I don't know why this kernel panic happened after I applied this patch.
But, if I added the following code in the mod_gadget.c, this issue disappeared:

@@ -682,7 +684,8 @@ static int usbhsg_ep_dequeue(struct usb_ep *ep, struct usb_r
struct usbhsg_request *ureq = usbhsg_req_to_ureq(req);
struct usbhs_pipe *pipe = usbhsg_uep_to_pipe(uep);

-   usbhs_pkt_pop(pipe, usbhsg_ureq_to_pkt(ureq));
+   if (pipe)
+   usbhs_pkt_pop(pipe, usbhsg_ureq_to_pkt(ureq));
usbhsg_queue_pop(uep, ureq, -ECONNRESET);

return 0;

Best regards,
Yoshihiro Shimoda


--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH v2] phy: rcar-gen2 usb: Add Host/Function switching for USB0

2015-07-06 Thread Yoshihiro Shimoda
Hi Phil-san,

Thank you very much for the patch!

 Sent: Thursday, July 02, 2015 5:06 PM
 snip 
 +/* VBUS change IRQ handler */
 +static irqreturn_t gpio_vbus_irq(int irq, void *data)
 +{
 + struct rcar_gen2_channel *channel = data;
 +
 + /* Wait 20ms before doing anything as VBUS needs to settle */
 + schedule_delayed_work(channel-work, msecs_to_jiffies(20));
 +
 + return IRQ_HANDLED;
 +}
 +
 +static int probe_otg(struct platform_device *pdev,
 + struct rcar_gen2_phy_driver *drv)
 +{
 + struct device *dev = pdev-dev;
 + struct rcar_gen2_channel *ch = drv-channels;
 + int irq;
 + int ret;
 +
 + /* GPIOs for Host/Fn switching */
 + ch-gpio_id = of_get_named_gpio_flags(dev-of_node,
 + renesas,id-gpio, 0, NULL);
 + ch-gpio_vbus = of_get_named_gpio_flags(dev-of_node,
 + renesas,vbus-gpio, 0, NULL);
 +
 + /* Need valid ID and VBUS gpios for Host/Fn switching */
 + if (gpio_is_valid(ch-gpio_id)  gpio_is_valid(ch-gpio_vbus)) {
 + ch-use_otg = 1;
 +
 + /* GPIO for ID input */
 + ret = devm_gpio_request_one(dev, ch-gpio_id, GPIOF_IN, id);
 + if (ret)
 + return ret;
 +
 + /* GPIO for VBUS input */
 + ret = devm_gpio_request_one(dev, ch-gpio_vbus, GPIOF_IN, 
 vbus);

According to the checkpatch.pl, line over 80 characters.

 + if (ret)
 + return ret;
 +
 + irq = gpio_to_irq(ch-gpio_vbus);
 + ret = devm_request_irq(dev, irq, gpio_vbus_irq, VBUS_IRQ_FLAGS,
 + vbus_detect, ch);
 + if (ret)
 + return ret;
 +
 + /* Optional GPIO for VBUS power */
 + ch-gpio_vbus_pwr = of_get_named_gpio_flags(dev-of_node,
 + renesas,vbus-pwr-gpio, 0, 
 NULL);

Same above.

 + if (gpio_is_valid(ch-gpio_id)) {
 + ret = devm_gpio_request_one(dev, ch-gpio_vbus_pwr,
 + GPIOF_OUT_INIT_LOW, vbus-pwr);
 + if (ret)
 + return ret;
 + }
 +
 + } else if (gpio_is_valid(ch-gpio_id)) {
 + dev_err(dev, Failed to get VBUS gpio\n);
 + return ch-gpio_vbus;
 + } else if (gpio_is_valid(ch-gpio_vbus)) {
 + dev_err(dev, Failed to get ID gpio\n);
 + return ch-gpio_id;
 + }
 +
 + return 0;
 +}
 +
 +/* bind/unbind the peripheral controller */
 +static int rcar_gen2_usb_set_peripheral(struct usb_otg *otg,
 + struct usb_gadget *gadget)
 +{
 + otg-gadget = gadget;
 + if (!gadget) {
 + usb_gadget_vbus_disconnect(otg-gadget);

Since the otg-gadget is NULL, this driver should not call this function here.

 + otg-state = OTG_STATE_UNDEFINED;
 + }
 +
 + return 0;
 +}
 +
  static int rcar_gen2_phy_probe(struct platform_device *pdev)
  {
   struct device *dev = pdev-dev;
 snip 
 @@ -323,6 +540,14 @@ static int rcar_gen2_phy_probe(struct platform_device 
 *pdev)
 
   dev_set_drvdata(dev, drv);
 
 + /*
 +  * If we already have something plugged into USB0, we won't get an edge
 +  * on VBUS, so we have to manually schedule work to look at the VBUS
 +  * and ID signals.
 +  */
 + if (drv-channels-use_otg)
 + schedule_delayed_work(drv-channels-work, 
 msecs_to_jiffies(100));

This line is also line over 80 characters.

Best regards,
Yoshihiro Shimoda

 +
   return 0;
  }
 
 --
 1.9.1

--
To unsubscribe from this list: send the line unsubscribe linux-kernel in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-08-20 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 +++
 drivers/phy/Kconfig|   6 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 262 +
 4 files changed, 306 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..1e8437f
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: renesas,usb2-phy-r8a7795 if the device is a part of R8A7795 
SoC.
+- reg: offset and length of the USB2.0 host register block.
+- reg-names: must be usb2.
+- clocks: clock phandle and specifier pair.
+- clock-names: string, clock input name, must be usb2, and optional hsusb.
+- #phy-cells: see phy-bindings.txt in the same directory, must be 0.
+
+Optional proparies:
+To use a USB channel which EHCI/OHCI and HSUSB are combined, the device tree
+node should set HSUSB proparies to reg and reg-names proparies:
+- reg: offset and length of the HSUSB register block.
+- reg-names: must be hsusb.
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = renesas,usb2-phy-r8a7795;
+   reg = 0 0xee080200 0 0x6ff, 0 0xe6590100 0 0x100;
+   reg-names = usb2, hsusb;
+   clocks = mstp7_clks R8A7795_CLK_EHCI0,
+mstp7_clks R8A7795_CLK_HSUSB;
+   clock-names = usb2, hsusb;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = renesas,usb2-phy-r8a7795;
+   reg = 0 0xee0a0200 0 0x6ff;
+   reg-names = usb2;
+   clocks = mstp7_clks R8A7795_CLK_EHCI0;
+   clock-names = usb2;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 47da573..ee300fa 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,12 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate Renesas R-Car generation 3 USB 2.0 PHY driver
+   depends on GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate OMAP CONTROL PHY Driver
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a5b18c1..97e83bc 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..e319eaf
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,262 @@
+/*
+ * Renesas R-Car Gen3 for USB2.0 PHY driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ *
+ * This is based on the phy-rcar-gen2 driver:
+ * Copyright (C) 2014 Renesas Solutions Corp.
+ * Copyright (C) 2014 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/clk.h
+#include linux/io.h
+#include linux/module.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/phy/phy.h
+#include linux/platform_device.h
+#include linux/spinlock.h
+
+#include asm/cmpxchg.h
+
+/*** USB2.0 Host registers (original offset is +0x200) ***/
+#define USB2_INT_ENABLE0x000
+#define USB2_USBCTR0x00c
+#define USB2_SPD_RSM_TIMSET0x10c
+#define USB2_OC_TIMSET 0x110
+
+/* INT_ENABLE */
+#define

RE: [PATCH] serial: sh-sci: Fix length of scatterlist

2015-10-22 Thread Yoshihiro Shimoda
Hi Geert-san,

> Sent: Tuesday, October 20, 2015 9:22 PM
> 
> Hi Shimoda-san,
> 
> On Tue, Oct 20, 2015 at 2:18 PM, Yoshihiro Shimoda
> <yoshihiro.shimoda...@renesas.com> wrote:
> > This patch fixes an issue that the "length" of scatterlist should be
> > set using sh_dma_length(). Otherwise, a dmaengine driver cannot work
> 
> sg_dma_len()?

Thank you for the point. I will fix it.

> > correctly if CONFIG_NEED_SG_DMA_LENGTH=y.
> >
> > Fixes: 7b39d90184 (serial: sh-sci: Fix NULL pointer dereference if HIGHMEM 
> > is enabled)
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  drivers/tty/serial/sh-sci.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
> > index 960e50a..284a872 100644
> > --- a/drivers/tty/serial/sh-sci.c
> > +++ b/drivers/tty/serial/sh-sci.c
> > @@ -1437,7 +1437,7 @@ static void sci_request_dma(struct uart_port *port)
> > sg_init_table(sg, 1);
> > s->rx_buf[i] = buf;
> > sg_dma_address(sg) = dma;
> > -   sg->length = s->buf_len_rx;
> > +   sg_dma_length(sg) = s->buf_len_rx;
> 
> There's no definition for "sg_dma_length" in my tree?? sg_dma_len()?

Oops! Thank you for the point. I will fix 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
N�r��yb�X��ǧv�^�)޺{.n�+{zX����ܨ}���Ơz�:+v���zZ+��+zf���h���~i���z��w���?�&�)ߢf��^jǫy�m��@A�a���
0��h���i

[PATCH] serial: sh-sci: Fix length of scatterlist

2015-10-22 Thread Yoshihiro Shimoda
This patch fixes an issue that the "length" of scatterlist should be
set using sg_dma_len(). Otherwise, a dmaengine driver cannot work
correctly if CONFIG_NEED_SG_DMA_LENGTH=y.

Fixes: 7b39d90184 (serial: sh-sci: Fix NULL pointer dereference if HIGHMEM is 
enabled)
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 Changes from v1:
  - Fix using implicit declaration of function "sg_dma_length".

 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 960e50a..51c7507 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1437,7 +1437,7 @@ static void sci_request_dma(struct uart_port *port)
sg_init_table(sg, 1);
s->rx_buf[i] = buf;
sg_dma_address(sg) = dma;
-   sg->length = s->buf_len_rx;
+   sg_dma_len(sg) = s->buf_len_rx;
 
buf += s->buf_len_rx;
dma += s->buf_len_rx;
-- 
1.9.1

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


RE: [PATCH v4 3/3] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection

2015-10-19 Thread Yoshihiro Shimoda
Hi,

> Sent: Saturday, October 17, 2015 10:54 AM
> 
> Hi,
> 
> On Tuesday 13 October 2015 03:52 PM, Yoshihiro Shimoda wrote:
> > This patch adds support for runtime ID/VBUS pin detection if
> > the channel 0 of R-Car gen3 is used. So, we are able to use
> > the channel as both host and peripheral.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 +
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 43 
> > +-
> >  2 files changed, 44 insertions(+), 1 deletion(-)
> >
> > diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > index 589f5c0..b30a98a 100644
> > --- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > @@ -18,6 +18,7 @@ properties. This is because HSUSB has registers to select 
> > USB 2.0 host or
> >  peripheral at that channel:
> >  - reg: offset and length of the partial HSUSB register block.
> >  - reg-names: must be "hsusb".
> > +- interrupts: interrupt specifier for the PHY.
> >
> >  Example (R-Car H3):
> >
> > @@ -25,6 +26,7 @@ Example (R-Car H3):
> > compatible = "renesas,usb2-phy-r8a7795";
> > reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
> > reg-names = "usb2_host", "hsusb";
> > +   interrupts = ;
> > clocks = <_clks R8A7795_CLK_EHCI0>,
> >  <_clks R8A7795_CLK_HSUSB>;
> > };
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index 03d7079..40d0005 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -12,6 +12,7 @@
> >   * published by the Free Software Foundation.
> >   */
> >
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -26,14 +27,18 @@
> >  #define USB2_SPD_RSM_TIMSET0x10c
> >  #define USB2_OC_TIMSET 0x110
> >  #define USB2_COMMCTRL  0x600
> > +#define USB2_OBINTSTA  0x604
> > +#define USB2_OBINTEN   0x608
> >  #define USB2_VBCTRL0x60c
> >  #define USB2_LINECTRL1 0x610
> >  #define USB2_ADPCTRL   0x630
> >
> >  /* INT_ENABLE */
> > +#define USB2_INT_ENABLE_UCOM_INTEN BIT(3)
> >  #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
> >  #define USB2_INT_ENABLE_USBH_INTA_EN   BIT(1)
> > -#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_USBH_INTB_EN | 
> > \
> > +#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_UCOM_INTEN | \
> > +USB2_INT_ENABLE_USBH_INTB_EN | \
> >  USB2_INT_ENABLE_USBH_INTA_EN)
> >
> >  /* USBCTR */
> > @@ -49,6 +54,12 @@
> >  /* COMMCTRL */
> >  #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode 
> > */
> >
> > +/* OBINTSTA and OBINTEN */
> > +#define USB2_OBINT_SESSVLDCHG  BIT(12)
> > +#define USB2_OBINT_IDDIGCHGBIT(11)
> > +#define USB2_OBINT_BITS(USB2_OBINT_SESSVLDCHG | \
> > +USB2_OBINT_IDDIGCHG)
> > +
> >  /* VBCTRL */
> >  #define USB2_VBCTRL_DRVVBUSSEL BIT(8)
> >
> > @@ -178,6 +189,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan 
> > *ch)
> >
> > tmp = readl(usb2_base + USB2_VBCTRL);
> > writel(tmp | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
> > +   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
> > +   tmp = readl(usb2_base + USB2_OBINTEN);
> > +   writel(tmp | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
> > tmp = readl(usb2_base + USB2_ADPCTRL);
> > writel(tmp | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
> > tmp = readl(usb2_base + USB2_LINECTRL1);
> > @@ -289,6 +303,23 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = {
> > .owner  = THIS_MODULE,
> >  };
> >
> > +static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
> > +{
> > +   struct rcar_gen3_chan *ch = _ch;
> > +   void __iomem *usb2_base = ch->usb2.base;
> > +   u32 status = readl(usb2_base + USB2_OBINTSTA);
> > +   irqreturn_t ret = IRQ_N

RE: [PATCH v4 2/3] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel

2015-10-19 Thread Yoshihiro Shimoda
Hi,

> Sent: Saturday, October 17, 2015 10:48 AM
> 
> Hi,
> 
> On Tuesday 13 October 2015 03:52 PM, Yoshihiro Shimoda wrote:
> > To use the channel 0 of R-Car gen3 as periperal mode, This patch changes
> > the mode to OTG instead of HOST. Then, this driver needs to set some
> > registers to enable host mode and detects ID pin and VBUS pin at
> > phy_init() timing.
> >
> > For now, the channel 0 can be used as host mode only.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  drivers/phy/phy-rcar-gen3-usb2.c | 126 
> > ++-
> >  1 file changed, 124 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index d90dfcf..03d7079 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -25,6 +25,10 @@
> >  #define USB2_USBCTR0x00c
> >  #define USB2_SPD_RSM_TIMSET0x10c
> >  #define USB2_OC_TIMSET 0x110
> > +#define USB2_COMMCTRL  0x600
> > +#define USB2_VBCTRL0x60c
> > +#define USB2_LINECTRL1 0x610
> > +#define USB2_ADPCTRL   0x630
> >
> >  /* INT_ENABLE */
> >  #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
> > @@ -42,6 +46,24 @@
> >  /* OC_TIMSET */
> >  #define USB2_OC_TIMSET_INIT0x000209ab
> >
> > +/* COMMCTRL */
> > +#define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode 
> > */
> > +
> > +/* VBCTRL */
> > +#define USB2_VBCTRL_DRVVBUSSEL BIT(8)
> > +
> > +/* LINECTRL1 */
> > +#define USB2_LINECTRL1_DPRPD_ENBIT(19)
> > +#define USB2_LINECTRL1_DP_RPD  BIT(18)
> > +#define USB2_LINECTRL1_DMRPD_ENBIT(17)
> > +#define USB2_LINECTRL1_DM_RPD  BIT(16)
> > +
> > +/* ADPCTRL */
> > +#define USB2_ADPCTRL_OTGSESSVLDBIT(20)
> > +#define USB2_ADPCTRL_IDDIG BIT(19)
> > +#define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is 
> > enabled */
> > +#define USB2_ADPCTRL_DRVVBUS   BIT(4)
> > +
> >  /*** HSUSB registers (original offset is +0x100) ***/
> >  #define HSUSB_LPSTS0x02
> >  #define HSUSB_UGCTRL2  0x84
> > @@ -68,6 +90,104 @@ struct rcar_gen3_chan {
> > spinlock_t lock;
> >  };
> >
> > +static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
> > +{
> > +   void __iomem *usb2_base = ch->usb2.base;
> > +   u32 tmp = readl(usb2_base + USB2_COMMCTRL);
> 
> It's your preference but I'd like to have something like val instead of tmp.

I got it. I will change the name.

> > +
> > +   dev_dbg(>phy->dev, "%s: %08x, %d\n", __func__, tmp, host);
> 
> This shoulod be dev_vdbg.

I got it. I will fix it.

> > +   if (host)
> > +   tmp &= ~USB2_COMMCTRL_OTG_PERI;
> > +   else
> > +   tmp |= USB2_COMMCTRL_OTG_PERI;
> > +   writel(tmp, usb2_base + USB2_COMMCTRL);
> > +}
> > +
> > +static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int 
> > dm)
> > +{
> > +   void __iomem *usb2_base = ch->usb2.base;
> > +   u32 tmp = readl(usb2_base + USB2_LINECTRL1);
> > +
> > +   dev_dbg(>phy->dev, "%s: %08x, %d, %d\n", __func__, tmp, dp, dm);
> 
> same here.

I got it.

> > +   tmp &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
> > +   if (dp)
> > +   tmp |= USB2_LINECTRL1_DP_RPD;
> > +   if (dm)
> > +   tmp |= USB2_LINECTRL1_DM_RPD;
> > +   writel(tmp, usb2_base + USB2_LINECTRL1);
> > +}
> > +
> > +static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
> > +{
> > +   void __iomem *usb2_base = ch->usb2.base;
> > +   u32 tmp = readl(usb2_base + USB2_ADPCTRL);
> > +
> > +   dev_dbg(>phy->dev, "%s: %08x, %d\n", __func__, tmp, vbus);
> 
> here too.

I will fix it.

> > +   if (vbus)
> > +   tmp |= USB2_ADPCTRL_DRVVBUS;
> > +   else
> > +   tmp &= ~USB2_ADPCTRL_DRVVBUS;
> > +   writel(tmp, usb2_base + USB2_ADPCTRL);
> > +}
> > +
> > +static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch)
> > +{
> > +   rcar_gen3_set_linectrl(ch, 1, 1);
> > +   rcar_gen3_set_host_mode(ch, 1);
> > +   rcar_gen3_enable_vbus_ctrl(ch, 1);
&

RE: [PATCH v4 1/3] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-19 Thread Yoshihiro Shimoda
Hi,

> Sent: Saturday, October 17, 2015 10:44 AM
> 
> Hi,
> 
> On Tuesday 13 October 2015 03:52 PM, Yoshihiro Shimoda wrote:
< snip >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 7eb5859d..45c6131 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -118,6 +118,14 @@ config PHY_RCAR_GEN2
> > help
> >   Support for USB PHY found on Renesas R-Car generation 2 SoCs.
> >
> > +config PHY_RCAR_GEN3_USB2
> > +   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
> > +   depends on OF
> > +   depends on ARCH_SHMOBILE
> 
> The depends on can be moved to a single line.

Thank you for the review!
I will fix this.

> > +   depends on GENERIC_PHY
> 
> all the PHY drivers inside drivers/phy directory use select PHY. Please
> use select here.

Oops, I will fix it.

> > +   help
> > + Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
> > +
> >  config OMAP_CONTROL_PHY
> > tristate "OMAP CONTROL PHY Driver"
> > depends on ARCH_OMAP2PLUS || COMPILE_TEST
< snip >
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > new file mode 100644
> > index 000..d90dfcf
> > --- /dev/null
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> 
> Add a MAINTAINER entry for this file if there is no one else.

I got it. I will add a MAINTAINER entry.

> > @@ -0,0 +1,240 @@
> > +/*
> > + * Renesas R-Car Gen3 for USB2.0 PHY driver
> > + *
> > + * Copyright (C) 2015 Renesas Electronics Corporation
> > + *
> > + * This is based on the phy-rcar-gen2 driver:
> > + * Copyright (C) 2014 Renesas Solutions Corp.
> > + * Copyright (C) 2014 Cogent Embedded, Inc.
> > + *
> > + * This program is free software; you can redistribute it and/or modify
> > + * it under the terms of the GNU General Public License version 2 as
> > + * published by the Free Software Foundation.
> > + */
> > +
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +#include 
> > +
> > +/*** USB2.0 Host registers (original offset is +0x200) ***/
> > +#define USB2_INT_ENABLE0x000
> > +#define USB2_USBCTR0x00c
> > +#define USB2_SPD_RSM_TIMSET0x10c
> > +#define USB2_OC_TIMSET 0x110
> > +
> > +/* INT_ENABLE */
> > +#define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
> > +#define USB2_INT_ENABLE_USBH_INTA_EN   BIT(1)
> > +#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_USBH_INTB_EN | 
> > \
> > +USB2_INT_ENABLE_USBH_INTA_EN)
> > +
> > +/* USBCTR */
> > +#define USB2_USBCTR_DIRPD  BIT(2)
> > +#define USB2_USBCTR_PLL_RSTBIT(1)
> > +
> > +/* SPD_RSM_TIMSET */
> > +#define USB2_SPD_RSM_TIMSET_INIT   0x014e029b
> > +
> > +/* OC_TIMSET */
> > +#define USB2_OC_TIMSET_INIT0x000209ab
> > +
> > +/*** HSUSB registers (original offset is +0x100) ***/
> > +#define HSUSB_LPSTS0x02
> > +#define HSUSB_UGCTRL2  0x84
> > +
> > +/* Low Power Status register (LPSTS) */
> > +#define HSUSB_LPSTS_SUSPM  0x4000
> > +
> > +/* USB General control register 2 (UGCTRL2) */
> > +#define HSUSB_UGCTRL2_MASK 0x0031 /* bit[31:6] should be 0 */
> > +#define HSUSB_UGCTRL2_USB0SEL  0x0030
> > +#define HSUSB_UGCTRL2_USB0SEL_HOST 0x0010
> > +#define HSUSB_UGCTRL2_USB0SEL_HS_USB   0x0020
> > +#define HSUSB_UGCTRL2_USB0SEL_OTG  0x0030
> > +
> > +struct rcar_gen3_data {
> > +   void __iomem *base;
> > +   struct clk *clk;
> > +};
> > +
> > +struct rcar_gen3_chan {
> > +   struct rcar_gen3_data usb2;
> > +   struct rcar_gen3_data hsusb;
> > +   struct phy *phy;
> > +   spinlock_t lock;
> 
> Why do you need a spinlock? It seems like a single PHY phy-provider? Is
> it for future modifications?

I used this spinlock to protect updating some registers from CPU(s).
I will remove it if it is not really needed.

> > +};
> > +
> > +static int rcar_gen3_phy_usb2_init(struct phy *p)
> > +{
> > +   struct rcar_gen3_chan *channel = phy_get_drvdata(p);
> > +   unsigned long flags;
> > +   void __iomem *usb2_base = channel->usb2.base;
> > +   void __iomem *hsusb_base = channel->hsusb.base;
> > +   u32 tmp;
> > +
> > +   spin_lock_irqsave(>lock,

[PATCH v5 1/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-20 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device. And each channel has
independent registers about the PHYs.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 
 drivers/phy/Kconfig|   7 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 219 +
 4 files changed, 264 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..affa0f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
+ SoC.
+- reg: offset and length of the partial USB 2.0 Host register block.
+- reg-names: must be "usb2_host".
+- clocks: clock phandle and specifier pair(s).
+- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
+
+Optional properties:
+To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
+combined, the device tree node should set HSUSB properties to reg and reg-names
+properties. This is because HSUSB has registers to select USB 2.0 host or
+peripheral at that channel:
+- reg: offset and length of the partial HSUSB register block.
+- reg-names: must be "hsusb".
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
+   reg-names = "usb2_host", "hsusb";
+   clocks = <_clks R8A7795_CLK_EHCI0>,
+<_clks R8A7795_CLK_HSUSB>;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee0a0200 0 0x700>;
+   reg-names = "usb2_host";
+   clocks = <_clks R8A7795_CLK_EHCI0>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 7eb5859d..e9ab088 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,13 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
+   depends on OF && ARCH_SHMOBILE
+   select GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate "OMAP CONTROL PHY Driver"
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 075db1a..91d7a62 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..9d9cf26
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,219 @@
+/*
+ * Renesas R-Car Gen3 for USB2.0 PHY driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ *
+ * This is based on the phy-rcar-gen2 driver:
+ * Copyright (C) 2014 Renesas Solutions Corp.
+ * Copyright (C) 2014 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*** USB2.0 Host registers (original offset is +0x200) ***/
+#define USB2_INT_ENABLE0x000
+#define USB2_U

[PATCH v5 3/4] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection

2015-10-20 Thread Yoshihiro Shimoda
This patch adds support for runtime ID/VBUS pin detection if
the channel 0 of R-Car gen3 is used. So, we are able to use
the channel as both host and peripheral.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 43 +-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index affa0f7..2390e4e 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -18,6 +18,7 @@ properties. This is because HSUSB has registers to select USB 
2.0 host or
 peripheral at that channel:
 - reg: offset and length of the partial HSUSB register block.
 - reg-names: must be "hsusb".
+- interrupts: interrupt specifier for the PHY.
 
 Example (R-Car H3):
 
@@ -25,6 +26,7 @@ Example (R-Car H3):
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
reg-names = "usb2_host", "hsusb";
+   interrupts = ;
clocks = <_clks R8A7795_CLK_EHCI0>,
 <_clks R8A7795_CLK_HSUSB>;
};
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index cf91f9f..3c6805c 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -12,6 +12,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -25,14 +26,18 @@
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
 #define USB2_COMMCTRL  0x600
+#define USB2_OBINTSTA  0x604
+#define USB2_OBINTEN   0x608
 #define USB2_VBCTRL0x60c
 #define USB2_LINECTRL1 0x610
 #define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
+#define USB2_INT_ENABLE_UCOM_INTEN BIT(3)
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
 #define USB2_INT_ENABLE_USBH_INTA_EN   BIT(1)
-#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_USBH_INTB_EN | \
+#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_UCOM_INTEN | \
+USB2_INT_ENABLE_USBH_INTB_EN | \
 USB2_INT_ENABLE_USBH_INTA_EN)
 
 /* USBCTR */
@@ -48,6 +53,12 @@
 /* COMMCTRL */
 #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
 
+/* OBINTSTA and OBINTEN */
+#define USB2_OBINT_SESSVLDCHG  BIT(12)
+#define USB2_OBINT_IDDIGCHGBIT(11)
+#define USB2_OBINT_BITS(USB2_OBINT_SESSVLDCHG | \
+USB2_OBINT_IDDIGCHG)
+
 /* VBCTRL */
 #define USB2_VBCTRL_DRVVBUSSEL BIT(8)
 
@@ -174,6 +185,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 
val = readl(usb2_base + USB2_VBCTRL);
writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
val = readl(usb2_base + USB2_ADPCTRL);
writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
val = readl(usb2_base + USB2_LINECTRL1);
@@ -270,6 +284,23 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = {
.owner  = THIS_MODULE,
 };
 
+static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
+{
+   struct rcar_gen3_chan *ch = _ch;
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 status = readl(usb2_base + USB2_OBINTSTA);
+   irqreturn_t ret = IRQ_NONE;
+
+   if (status & USB2_OBINT_BITS) {
+   dev_vdbg(>phy->dev, "%s: %08x\n", __func__, status);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   rcar_gen3_device_recognition(ch);
+   ret = IRQ_HANDLED;
+   }
+
+   return ret;
+}
+
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
{ .compatible = "renesas,usb2-phy-r8a7795" },
{ }
@@ -302,9 +333,19 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
 
/* To avoid error message by devm_ioremap_resource() */
if (res) {
+   int irq;
+
channel->hsusb.base = devm_ioremap_resource(dev, res);
if (IS_ERR(channel->hsusb.base))
channel->hsusb.base = NULL;
+   /* call request_irq for OTG */
+   irq = platform_get_irq(pdev, 0);
+   if (irq >= 0)
+   irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
+   

[PATCH v5 2/4] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel

2015-10-20 Thread Yoshihiro Shimoda
To use the channel 0 of R-Car gen3 as periperal mode, This patch changes
the mode to OTG instead of HOST. Then, this driver needs to set some
registers to enable host mode and detects ID pin and VBUS pin at
phy_init() timing.

For now, the channel 0 can be used as host mode only.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 124 ++-
 1 file changed, 122 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 9d9cf26..cf91f9f 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -24,6 +24,10 @@
 #define USB2_USBCTR0x00c
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
+#define USB2_COMMCTRL  0x600
+#define USB2_VBCTRL0x60c
+#define USB2_LINECTRL1 0x610
+#define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
@@ -41,6 +45,24 @@
 /* OC_TIMSET */
 #define USB2_OC_TIMSET_INIT0x000209ab
 
+/* COMMCTRL */
+#define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
+
+/* VBCTRL */
+#define USB2_VBCTRL_DRVVBUSSEL BIT(8)
+
+/* LINECTRL1 */
+#define USB2_LINECTRL1_DPRPD_ENBIT(19)
+#define USB2_LINECTRL1_DP_RPD  BIT(18)
+#define USB2_LINECTRL1_DMRPD_ENBIT(17)
+#define USB2_LINECTRL1_DM_RPD  BIT(16)
+
+/* ADPCTRL */
+#define USB2_ADPCTRL_OTGSESSVLDBIT(20)
+#define USB2_ADPCTRL_IDDIG BIT(19)
+#define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is enabled */
+#define USB2_ADPCTRL_DRVVBUS   BIT(4)
+
 /*** HSUSB registers (original offset is +0x100) ***/
 #define HSUSB_LPSTS0x02
 #define HSUSB_UGCTRL2  0x84
@@ -66,6 +88,102 @@ struct rcar_gen3_chan {
struct phy *phy;
 };
 
+static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_COMMCTRL);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, host);
+   if (host)
+   val &= ~USB2_COMMCTRL_OTG_PERI;
+   else
+   val |= USB2_COMMCTRL_OTG_PERI;
+   writel(val, usb2_base + USB2_COMMCTRL);
+}
+
+static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_LINECTRL1);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm);
+   val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
+   if (dp)
+   val |= USB2_LINECTRL1_DP_RPD;
+   if (dm)
+   val |= USB2_LINECTRL1_DM_RPD;
+   writel(val, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_ADPCTRL);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, vbus);
+   if (vbus)
+   val |= USB2_ADPCTRL_DRVVBUS;
+   else
+   val &= ~USB2_ADPCTRL_DRVVBUS;
+   writel(val, usb2_base + USB2_ADPCTRL);
+}
+
+static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+}
+
+static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) &
+ USB2_ADPCTRL_OTGSESSVLD);
+}
+
+static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
+}
+
+static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
+{
+   bool is_host = true;
+
+   /* B-device? */
+   if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch))
+   is_host = false;
+
+   if (is_host)
+   rcar_gen3_init_for_host(ch);
+   else
+   rcar_gen3_init_for_peri(ch);
+}
+
+static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_VBCTRL);
+   writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   val = readl(usb2_base + USB2_ADPCTRL);
+   writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
+   val = readl(usb2_base + USB2_LINECTRL1);
+   rcar_gen3_set_linectrl(ch, 0, 0);
+   write

[PATCH v5 4/4] MAINTAINERS: add Renesas usb2 phy driver

2015-10-20 Thread Yoshihiro Shimoda
Add Renesas usb2 phy driver to maintainer entry.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index be0055c..ecff678 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8742,6 +8742,12 @@ F:   drivers/rpmsg/
 F: Documentation/rpmsg.txt
 F: include/linux/rpmsg.h
 
+RENESAS USB2 PHY DRIVER
+M: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+L: linux...@vger.kernel.org
+S: Maintained
+F: drivers/phy/phy-rcar-gen3-usb2.c
+
 RESET CONTROLLER FRAMEWORK
 M: Philipp Zabel <p.za...@pengutronix.de>
 S: Maintained
-- 
1.9.1

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


[PATCH v5 0/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-20 Thread Yoshihiro Shimoda
This patch is based on the latest linux-phy / next branch.
(commit id = 0f8669e343982ac66f4420335777cb5456b8abb0)

 Changes from v4:
  - Modify Kconfig to "depends on OF && ARCH_SHMOBILE".
  - Modify Kconfig to "select GENERIC_PHY" instead of "depends on GENERIC_PHY".
  - Modify device tree documentation about "reg" of example.
  - Remove spinlock handling because phy-core driver calls mutex_lock().
  - Change valiable name to val instead of tmp.
  - Remove dev_set_drvdata.
  - Use dev_vdbg() instead of dev_dbg().
  - Change rcar_gen3_device_recognition()'s condition as one line.
  - Remove unnecessary value in rcar_gen3_phy_usb2_probe().
  - Modify MAINTAINERS about this driver.

 Changes from v3:
  - Shorten structure names to avoid new line if we add a long function name.
  - Add ID/VBUS pin detection for peripheral mode.

 Changes from v2:
  - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
  - Add more information in the dt document.
  - Change reg-names from "usb2" to "usb2_host".

 Changes from v1:
  - Revise some typos.
  - Remove using clk API to enable/disable the clocks.
(In other words, this driver expects to enable/disable the clocks by
 Runtime PM API by the phy-core driver.)
  - Remove an unnecessary header file (asm/cmpxchg.h).

Yoshihiro Shimoda (4):
  phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver
  phy: rcar-gen3-usb2: change the mode to OTG on the combined channel
  phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection
  MAINTAINERS: add Renesas usb2 phy driver

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  39 +++
 MAINTAINERS|   6 +
 drivers/phy/Kconfig|   7 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 380 +
 5 files changed, 433 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

-- 
1.9.1

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


[PATCH] serial: sh-sci: Fix length of scatterlist

2015-10-20 Thread Yoshihiro Shimoda
This patch fixes an issue that the "length" of scatterlist should be
set using sh_dma_length(). Otherwise, a dmaengine driver cannot work
correctly if CONFIG_NEED_SG_DMA_LENGTH=y.

Fixes: 7b39d90184 (serial: sh-sci: Fix NULL pointer dereference if HIGHMEM is 
enabled)
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/tty/serial/sh-sci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 960e50a..284a872 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1437,7 +1437,7 @@ static void sci_request_dma(struct uart_port *port)
sg_init_table(sg, 1);
s->rx_buf[i] = buf;
sg_dma_address(sg) = dma;
-   sg->length = s->buf_len_rx;
+   sg_dma_length(sg) = s->buf_len_rx;
 
buf += s->buf_len_rx;
dma += s->buf_len_rx;
-- 
1.9.1

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


[PATCH v4 3/3] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection

2015-10-13 Thread Yoshihiro Shimoda
This patch adds support for runtime ID/VBUS pin detection if
the channel 0 of R-Car gen3 is used. So, we are able to use
the channel as both host and peripheral.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 43 +-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index 589f5c0..b30a98a 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -18,6 +18,7 @@ properties. This is because HSUSB has registers to select USB 
2.0 host or
 peripheral at that channel:
 - reg: offset and length of the partial HSUSB register block.
 - reg-names: must be "hsusb".
+- interrupts: interrupt specifier for the PHY.
 
 Example (R-Car H3):
 
@@ -25,6 +26,7 @@ Example (R-Car H3):
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
reg-names = "usb2_host", "hsusb";
+   interrupts = ;
clocks = <_clks R8A7795_CLK_EHCI0>,
 <_clks R8A7795_CLK_HSUSB>;
};
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 03d7079..40d0005 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -12,6 +12,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -26,14 +27,18 @@
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
 #define USB2_COMMCTRL  0x600
+#define USB2_OBINTSTA  0x604
+#define USB2_OBINTEN   0x608
 #define USB2_VBCTRL0x60c
 #define USB2_LINECTRL1 0x610
 #define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
+#define USB2_INT_ENABLE_UCOM_INTEN BIT(3)
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
 #define USB2_INT_ENABLE_USBH_INTA_EN   BIT(1)
-#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_USBH_INTB_EN | \
+#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_UCOM_INTEN | \
+USB2_INT_ENABLE_USBH_INTB_EN | \
 USB2_INT_ENABLE_USBH_INTA_EN)
 
 /* USBCTR */
@@ -49,6 +54,12 @@
 /* COMMCTRL */
 #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
 
+/* OBINTSTA and OBINTEN */
+#define USB2_OBINT_SESSVLDCHG  BIT(12)
+#define USB2_OBINT_IDDIGCHGBIT(11)
+#define USB2_OBINT_BITS(USB2_OBINT_SESSVLDCHG | \
+USB2_OBINT_IDDIGCHG)
+
 /* VBCTRL */
 #define USB2_VBCTRL_DRVVBUSSEL BIT(8)
 
@@ -178,6 +189,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 
tmp = readl(usb2_base + USB2_VBCTRL);
writel(tmp | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   tmp = readl(usb2_base + USB2_OBINTEN);
+   writel(tmp | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
tmp = readl(usb2_base + USB2_ADPCTRL);
writel(tmp | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
tmp = readl(usb2_base + USB2_LINECTRL1);
@@ -289,6 +303,23 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = {
.owner  = THIS_MODULE,
 };
 
+static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
+{
+   struct rcar_gen3_chan *ch = _ch;
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 status = readl(usb2_base + USB2_OBINTSTA);
+   irqreturn_t ret = IRQ_NONE;
+
+   if (status & USB2_OBINT_BITS) {
+   dev_dbg(>phy->dev, "%s: %08x\n", __func__, status);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   rcar_gen3_device_recognition(ch);
+   ret = IRQ_HANDLED;
+   }
+
+   return ret;
+}
+
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
{ .compatible = "renesas,usb2-phy-r8a7795" },
{ }
@@ -323,9 +354,19 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
 
/* To avoid error message by devm_ioremap_resource() */
if (res) {
+   int ret, irq;
+
channel->hsusb.base = devm_ioremap_resource(dev, res);
if (IS_ERR(channel->hsusb.base))
channel->hsusb.base = NULL;
+   /* call request_irq for OTG */
+   ret = irq = platform_get_irq(pdev, 0);
+   if (irq >= 0)
+   ret = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
+   

[PATCH v4 1/3] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-13 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device. And each channel has
independent registers about the PHYs.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 
 drivers/phy/Kconfig|   8 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 240 +
 4 files changed, 286 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..589f5c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
+ SoC.
+- reg: offset and length of the partial USB 2.0 Host register block.
+- reg-names: must be "usb2_host".
+- clocks: clock phandle and specifier pair(s).
+- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
+
+Optional properties:
+To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
+combined, the device tree node should set HSUSB properties to reg and reg-names
+properties. This is because HSUSB has registers to select USB 2.0 host or
+peripheral at that channel:
+- reg: offset and length of the partial HSUSB register block.
+- reg-names: must be "hsusb".
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
+   reg-names = "usb2_host", "hsusb";
+   clocks = <_clks R8A7795_CLK_EHCI0>,
+<_clks R8A7795_CLK_HSUSB>;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee0a0200 0 0x6ff>;
+   reg-names = "usb2_host";
+   clocks = <_clks R8A7795_CLK_EHCI0>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 7eb5859d..45c6131 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,14 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
+   depends on OF
+   depends on ARCH_SHMOBILE
+   depends on GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate "OMAP CONTROL PHY Driver"
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 075db1a..91d7a62 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..d90dfcf
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,240 @@
+/*
+ * Renesas R-Car Gen3 for USB2.0 PHY driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ *
+ * This is based on the phy-rcar-gen2 driver:
+ * Copyright (C) 2014 Renesas Solutions Corp.
+ * Copyright (C) 2014 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*** USB2.0 Host registers (original offset is +0x200) ***/
+#define USB2_INT_ENABLE

[PATCH v4 0/3] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-13 Thread Yoshihiro Shimoda
This patch is based on the latest linux-phy / next branch.
(commit id = 882fed73420e85c0b06447c036e3096862fc73ba)

In this v4 patch set, it has a new feature (ID/VBUS pin detection).
To ease review, I don't add this intp the patch 1/3. If I should add
it into the patch 1/3, please let me know!

 Changes from v3:
  - Shorten structure names to avoid new line if we add a long function name.
  - Add ID/VBUS pin detection for peripheral mode.

 Changes from v2:
  - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
  - Add more information in the dt document.
  - Change reg-names from "usb2" to "usb2_host".

 Changes from v1:
  - Revise some typos.
  - Remove using clk API to enable/disable the clocks.
(In other words, this driver expects to enable/disable the clocks by
 Runtime PM API by the phy-core driver.)
  - Remove an unnecessary header file (asm/cmpxchg.h).

Yoshihiro Shimoda (3):
  phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver
  phy: rcar-gen3-usb2: change the mode to OTG on the combined channel
  phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  39 ++
 drivers/phy/Kconfig|   8 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 403 +
 4 files changed, 451 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

-- 
1.9.1

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


RE: [PATCH v3] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-13 Thread Yoshihiro Shimoda
Hi,

I sent v4 patch set today. So, please ignore this version.

Best regards,
Yoshihiro Shimoda

> Sent: Thursday, October 01, 2015 7:11 PM
> 
> This patch adds support for R-Car generation 3 USB2 PHY driver.
> This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
> with the HSUSB (USB2.0 peripheral) device. And each channel has
> independent registers about the PHYs.
> 
> So, the purpose of this driver is:
>  1) initializes some registers of SoC specific to use the
> {ehci,ohci}-platform driver.
> 
>  2) detects id pin to select host or peripheral on the channel 0.
> 
> For now, this driver only supports 1) above.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  This patch is based on the latest linux-phy / next branch.
>  (commit id = 6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f)
> 
>  Changes from v2:
>   - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
>   - Add more information in the dt document.
>   - Change reg-names from "usb2" to "usb2_host".
> 
>  Changes from v1:
>   - Revise some typos.
>   - Remove using clk API to enable/disable the clocks.
> (In other words, this driver expects to enable/disable the clocks by
>  Runtime PM API by the phy-core driver.)
>   - Remove an unnecessary header file (asm/cmpxchg.h).
> 
>  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 
>  drivers/phy/Kconfig|   8 +
>  drivers/phy/Makefile   |   1 +
>  drivers/phy/phy-rcar-gen3-usb2.c   | 240 
> +
>  4 files changed, 286 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
>  create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c
> 
> diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> new file mode 100644
> index 000..589f5c0
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> @@ -0,0 +1,37 @@
> +* Renesas R-Car generation 3 USB 2.0 PHY
> +
> +This file provides information on what the device node for the R-Car 
> generation
> +3 USB 2.0 PHY contains.
> +
> +Required properties:
> +- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an 
> R8A7795
> +   SoC.
> +- reg: offset and length of the partial USB 2.0 Host register block.
> +- reg-names: must be "usb2_host".
> +- clocks: clock phandle and specifier pair(s).
> +- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
> +
> +Optional properties:
> +To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
> +combined, the device tree node should set HSUSB properties to reg and 
> reg-names
> +properties. This is because HSUSB has registers to select USB 2.0 host or
> +peripheral at that channel:
> +- reg: offset and length of the partial HSUSB register block.
> +- reg-names: must be "hsusb".
> +
> +Example (R-Car H3):
> +
> + usb-phy@ee080200 {
> + compatible = "renesas,usb2-phy-r8a7795";
> + reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
> + reg-names = "usb2_host", "hsusb";
> + clocks = <_clks R8A7795_CLK_EHCI0>,
> +  <_clks R8A7795_CLK_HSUSB>;
> + };
> +
> + usb-phy@ee0a0200 {
> + compatible = "renesas,usb2-phy-r8a7795";
> + reg = <0 0xee0a0200 0 0x6ff>;
> + reg-names = "usb2_host";
> + clocks = <_clks R8A7795_CLK_EHCI0>;
> + };
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 47da573..ae3ba34 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -118,6 +118,14 @@ config PHY_RCAR_GEN2
>   help
> Support for USB PHY found on Renesas R-Car generation 2 SoCs.
> 
> +config PHY_RCAR_GEN3_USB2
> + tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
> + depends on OF
> + depends on ARCH_SHMOBILE
> + depends on GENERIC_PHY
> + help
> +   Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
> +
>  config OMAP_CONTROL_PHY
>   tristate "OMAP CONTROL PHY Driver"
>   depends on ARCH_OMAP2PLUS || COMPILE_TEST
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index a5b18c1..97e83bc 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)+= 

[PATCH v4 2/3] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel

2015-10-13 Thread Yoshihiro Shimoda
To use the channel 0 of R-Car gen3 as periperal mode, This patch changes
the mode to OTG instead of HOST. Then, this driver needs to set some
registers to enable host mode and detects ID pin and VBUS pin at
phy_init() timing.

For now, the channel 0 can be used as host mode only.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 126 ++-
 1 file changed, 124 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index d90dfcf..03d7079 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -25,6 +25,10 @@
 #define USB2_USBCTR0x00c
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
+#define USB2_COMMCTRL  0x600
+#define USB2_VBCTRL0x60c
+#define USB2_LINECTRL1 0x610
+#define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
@@ -42,6 +46,24 @@
 /* OC_TIMSET */
 #define USB2_OC_TIMSET_INIT0x000209ab
 
+/* COMMCTRL */
+#define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
+
+/* VBCTRL */
+#define USB2_VBCTRL_DRVVBUSSEL BIT(8)
+
+/* LINECTRL1 */
+#define USB2_LINECTRL1_DPRPD_ENBIT(19)
+#define USB2_LINECTRL1_DP_RPD  BIT(18)
+#define USB2_LINECTRL1_DMRPD_ENBIT(17)
+#define USB2_LINECTRL1_DM_RPD  BIT(16)
+
+/* ADPCTRL */
+#define USB2_ADPCTRL_OTGSESSVLDBIT(20)
+#define USB2_ADPCTRL_IDDIG BIT(19)
+#define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is enabled */
+#define USB2_ADPCTRL_DRVVBUS   BIT(4)
+
 /*** HSUSB registers (original offset is +0x100) ***/
 #define HSUSB_LPSTS0x02
 #define HSUSB_UGCTRL2  0x84
@@ -68,6 +90,104 @@ struct rcar_gen3_chan {
spinlock_t lock;
 };
 
+static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 tmp = readl(usb2_base + USB2_COMMCTRL);
+
+   dev_dbg(>phy->dev, "%s: %08x, %d\n", __func__, tmp, host);
+   if (host)
+   tmp &= ~USB2_COMMCTRL_OTG_PERI;
+   else
+   tmp |= USB2_COMMCTRL_OTG_PERI;
+   writel(tmp, usb2_base + USB2_COMMCTRL);
+}
+
+static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 tmp = readl(usb2_base + USB2_LINECTRL1);
+
+   dev_dbg(>phy->dev, "%s: %08x, %d, %d\n", __func__, tmp, dp, dm);
+   tmp &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
+   if (dp)
+   tmp |= USB2_LINECTRL1_DP_RPD;
+   if (dm)
+   tmp |= USB2_LINECTRL1_DM_RPD;
+   writel(tmp, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 tmp = readl(usb2_base + USB2_ADPCTRL);
+
+   dev_dbg(>phy->dev, "%s: %08x, %d\n", __func__, tmp, vbus);
+   if (vbus)
+   tmp |= USB2_ADPCTRL_DRVVBUS;
+   else
+   tmp &= ~USB2_ADPCTRL_DRVVBUS;
+   writel(tmp, usb2_base + USB2_ADPCTRL);
+}
+
+static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+}
+
+static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) &
+ USB2_ADPCTRL_OTGSESSVLD);
+}
+
+static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
+}
+
+static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
+{
+   bool is_host = true;
+
+   if (rcar_gen3_check_id(ch)) {
+   /* B-device? */
+   if (rcar_gen3_check_vbus(ch))
+   is_host = false;
+   }
+
+   if (is_host)
+   rcar_gen3_init_for_host(ch);
+   else
+   rcar_gen3_init_for_peri(ch);
+}
+
+static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 tmp;
+
+   tmp = readl(usb2_base + USB2_VBCTRL);
+   writel(tmp | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   tmp = readl(usb2_base + USB2_ADPCTRL);
+   writel(tmp | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
+   tmp = readl(usb2_base + USB2_LINECTRL1);
+   rcar_gen3_set_linectrl(ch, 0, 0);
+   

RE: [PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-08-24 Thread Yoshihiro Shimoda
Hi Geert-san,

 Sent: Monday, August 24, 2015 9:13 PM
 
 Hi Shimoda-san,
 
 On Thu, Aug 20, 2015 at 8:28 AM, Yoshihiro Shimoda
 yoshihiro.shimoda...@renesas.com wrote:
  This patch adds support for R-Car generation 3 USB2 PHY driver.
  This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
  with the HSUSB (USB2.0 peripheral) device.
 
  So, the purpose of this driver is:
   1) initializes some registers of SoC specific to use the
  {ehci,ohci}-platform driver.
 
   2) detects id pin to select host or peripheral on the channel 0.
 
  For now, this driver only supports 1) above.
 
 Thanks for your patch!

Thank you very much for your review!

  --- /dev/null
  +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
  @@ -0,0 +1,37 @@
  +* Renesas R-Car generation 3 USB 2.0 PHY
  +
  +This file provides information on what the device node for the R-Car 
  generation
  +3 USB 2.0 PHY contains.
  +
  +Required properties:
  +- compatible: renesas,usb2-phy-r8a7795 if the device is a part of 
  R8A7795 SoC.
 
 an R8A7795 SoC.

I will fix this in v2.
(I will submit v2 patch late today.)

  +- reg: offset and length of the USB2.0 host register block.
  +- reg-names: must be usb2.
  +- clocks: clock phandle and specifier pair.
 
 pair(s).

I will fix this.

  +- clock-names: string, clock input name, must be usb2, and optional 
  hsusb.
 
 names

Thank you for the point.
As you mentioned about runtime PM below, I will remove this property.

  +- #phy-cells: see phy-bindings.txt in the same directory, must be 0.
  +
  +Optional proparies:
 
 properties

Oops, I will fix it.
I should have done aspell command before I submitted.
If I did that command, I found other typo in this patch :)

  +To use a USB channel which EHCI/OHCI and HSUSB are combined, the device 
  tree
 
 s/which/where/
 
  +node should set HSUSB proparies to reg and reg-names proparies:
 
 properties (x2)

I will fix it.

  +- reg: offset and length of the HSUSB register block.
  +- reg-names: must be hsusb.
  +
  +Example (R-Car H3):
  +
  +   usb-phy@ee080200 {
  +   compatible = renesas,usb2-phy-r8a7795;
  +   reg = 0 0xee080200 0 0x6ff, 0 0xe6590100 0 0x100;
  +   reg-names = usb2, hsusb;
  +   clocks = mstp7_clks R8A7795_CLK_EHCI0,
  +mstp7_clks R8A7795_CLK_HSUSB;
 
 If you ever want to enable Runtime PM, do you want the first MSTP clock to be
 managed automatically?
 What about the second optional clock?

Thank you very much for the point.
I didn't take care about Runtime PM. However, I want to enable Runtime PM
because usb host and function drivers support it.

  +   clock-names = usb2, hsusb;
  +   };
  +
  +   usb-phy@ee0a0200 {
  +   compatible = renesas,usb2-phy-r8a7795;
  +   reg = 0 0xee0a0200 0 0x6ff;
  +   reg-names = usb2;
  +   clocks = mstp7_clks R8A7795_CLK_EHCI0;
  +   clock-names = usb2;
  +   };
 
  --- /dev/null
  +++ b/drivers/phy/phy-rcar-gen3-usb2.c
 
  +static int rcar_gen3_phy_usb2_init(struct phy *p)
  +{
  +   struct rcar_gen3_phy_usb2_channel *channel = phy_get_drvdata(p);
  +   unsigned long flags;
  +   void __iomem *usb2_base = channel-usb2.base;
  +   void __iomem *hsusb_base = channel-hsusb.base;
  +   u32 tmp;
  +
  +   /* Since ops-init() is called once, this driver enables both 
  clocks */
  +   clk_prepare_enable(channel-usb2.clk);
  +   clk_prepare_enable(channel-hsusb.clk);
 
 So this driver manages its clock(s) itself, and doesn't support Runtime PM.

So, I will use remove clk APIs in this driver.

Best regards,
Yoshihiro Shimoda

  +static int rcar_gen3_phy_usb2_exit(struct phy *p)
  +{
  +   struct rcar_gen3_phy_usb2_channel *channel = phy_get_drvdata(p);
  +
  +   writel(0, channel-usb2.base + USB2_INT_ENABLE);
  +
  +   clk_disable_unprepare(channel-hsusb.clk);
  +   clk_disable_unprepare(channel-usb2.clk);
  +
  +   return 0;
  +}
 
 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
N�r��yb�X��ǧv�^�)޺{.n�+{zX����ܨ}���Ơz�j:+v���zZ+��+zf���h���~i���z��w���?��)ߢf��^jǫy�m��@A�a���
0��h���i

[PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-08-25 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda yoshihiro.shimoda...@renesas.com
---
 This patch is based on the latest linux-phy / next branch.
 (commit id = cfd093bbb5fe84ec8c7bb069fe618159a8b601f5)

 Changes from v1:
  - Revise some typos.
  - Remove using clk API to enable/disable the clocks.
(In other words, this driver expects to enable/disable the clocks by
 Runtime PM API by the phy-core driver.)
  - Remove an unnecessary header file (asm/cmpxchg.h).

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  35 +++
 drivers/phy/Kconfig|   6 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 240 +
 4 files changed, 282 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..1d57766
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,35 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: renesas,usb2-phy-r8a7795 if the device is a part of an R8A7795
+ SoC.
+- reg: offset and length of the USB2.0 host register block.
+- reg-names: must be usb2.
+- clocks: clock phandle and specifier pair(s).
+- #phy-cells: see phy-bindings.txt in the same directory, must be 0.
+
+Optional properties:
+To use a USB channel where EHCI/OHCI and HSUSB are combined, the device tree
+node should set HSUSB properties to reg and reg-names properties:
+- reg: offset and length of the HSUSB register block.
+- reg-names: must be hsusb.
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = renesas,usb2-phy-r8a7795;
+   reg = 0 0xee080200 0 0x6ff, 0 0xe6590100 0 0x100;
+   reg-names = usb2, hsusb;
+   clocks = mstp7_clks R8A7795_CLK_EHCI0,
+mstp7_clks R8A7795_CLK_HSUSB;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = renesas,usb2-phy-r8a7795;
+   reg = 0 0xee0a0200 0 0x6ff;
+   reg-names = usb2;
+   clocks = mstp7_clks R8A7795_CLK_EHCI0;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 0fe9bff..406dc43 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -116,6 +116,12 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate Renesas R-Car generation 3 USB 2.0 PHY driver
+   depends on GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate OMAP CONTROL PHY Driver
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a5b18c1..97e83bc 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..2c2fcf9
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,240 @@
+/*
+ * Renesas R-Car Gen3 for USB2.0 PHY driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ *
+ * This is based on the phy-rcar-gen2 driver:
+ * Copyright (C) 2014 Renesas Solutions Corp.
+ * Copyright (C) 2014 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include linux/io.h
+#include linux/module.h
+#include linux/of.h
+#include linux/of_address.h
+#include linux/phy/phy.h
+#include linux/platform_device.h
+#include linux/spinlock.h
+
+/*** USB2.0 Host registers (original offset

RE: [PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-09-17 Thread Yoshihiro Shimoda
Hi Kishon,

> Sent: Tuesday, August 25, 2015 6:11 PM
> 
> This patch adds support for R-Car generation 3 USB2 PHY driver.
> This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
> with the HSUSB (USB2.0 peripheral) device.
> 
> So, the purpose of this driver is:
>  1) initializes some registers of SoC specific to use the
> {ehci,ohci}-platform driver.
> 
>  2) detects id pin to select host or peripheral on the channel 0.
> 
> For now, this driver only supports 1) above.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  This patch is based on the latest linux-phy / next branch.
>  (commit id = cfd093bbb5fe84ec8c7bb069fe618159a8b601f5)

Would you review this patch? Since the latest linux-phy.git / next branch
is the same as the above id, this patch can be applied on the repository, I 
think.

Best regards,
Yoshihiro Shimoda

>  Changes from v1:
>   - Revise some typos.
>   - Remove using clk API to enable/disable the clocks.
> (In other words, this driver expects to enable/disable the clocks by
>  Runtime PM API by the phy-core driver.)
>   - Remove an unnecessary header file (asm/cmpxchg.h).
> 
>  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  35 +++
>  drivers/phy/Kconfig|   6 +
>  drivers/phy/Makefile   |   1 +
>  drivers/phy/phy-rcar-gen3-usb2.c   | 240 
> +
>  4 files changed, 282 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
>  create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c
> 
> diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> new file mode 100644
> index 000..1d57766
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> @@ -0,0 +1,35 @@
> +* Renesas R-Car generation 3 USB 2.0 PHY
> +
> +This file provides information on what the device node for the R-Car 
> generation
> +3 USB 2.0 PHY contains.
> +
> +Required properties:
> +- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an 
> R8A7795
> +   SoC.
> +- reg: offset and length of the USB2.0 host register block.
> +- reg-names: must be "usb2".
> +- clocks: clock phandle and specifier pair(s).
> +- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
> +
> +Optional properties:
> +To use a USB channel where EHCI/OHCI and HSUSB are combined, the device tree
> +node should set HSUSB properties to reg and reg-names properties:
> +- reg: offset and length of the HSUSB register block.
> +- reg-names: must be "hsusb".
> +
> +Example (R-Car H3):
> +
> + usb-phy@ee080200 {
> + compatible = "renesas,usb2-phy-r8a7795";
> + reg = <0 0xee080200 0 0x6ff>, <0 0xe6590100 0 0x100>;
> + reg-names = "usb2", "hsusb";
> + clocks = <_clks R8A7795_CLK_EHCI0>,
> +  <_clks R8A7795_CLK_HSUSB>;
> + };
> +
> + usb-phy@ee0a0200 {
> + compatible = "renesas,usb2-phy-r8a7795";
> + reg = <0 0xee0a0200 0 0x6ff>;
> + reg-names = "usb2";
> + clocks = <_clks R8A7795_CLK_EHCI0>;
> + };
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 0fe9bff..406dc43 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -116,6 +116,12 @@ config PHY_RCAR_GEN2
>   help
> Support for USB PHY found on Renesas R-Car generation 2 SoCs.
> 
> +config PHY_RCAR_GEN3_USB2
> + tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
> + depends on GENERIC_PHY
> + help
> +   Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
> +
>  config OMAP_CONTROL_PHY
>   tristate "OMAP CONTROL PHY Driver"
>   depends on ARCH_OMAP2PLUS || COMPILE_TEST
> diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
> index a5b18c1..97e83bc 100644
> --- a/drivers/phy/Makefile
> +++ b/drivers/phy/Makefile
> @@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)+= 
> phy-mvebu-sata.o
>  obj-$(CONFIG_PHY_MIPHY28LP)  += phy-miphy28lp.o
>  obj-$(CONFIG_PHY_MIPHY365X)  += phy-miphy365x.o
>  obj-$(CONFIG_PHY_RCAR_GEN2)  += phy-rcar-gen2.o
> +obj-$(CONFIG_PHY_RCAR_GEN3_USB2) += phy-rcar-gen3-usb2.o
>  obj-$(CONFIG_OMAP_CONTROL_PHY)   += phy-omap-control.o
>  obj-$(CONFIG_OMAP_USB2)  += phy-omap-usb2.o
>  obj-$(CONFIG_TI_P

[PATCH v3] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-01 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device. And each channel has
independent registers about the PHYs.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the latest linux-phy / next branch.
 (commit id = 6ff33f3902c3b1c5d0db6b1e2c70b6d76fba357f)

 Changes from v2:
  - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
  - Add more information in the dt document.
  - Change reg-names from "usb2" to "usb2_host".

 Changes from v1:
  - Revise some typos.
  - Remove using clk API to enable/disable the clocks.
(In other words, this driver expects to enable/disable the clocks by
 Runtime PM API by the phy-core driver.)
  - Remove an unnecessary header file (asm/cmpxchg.h).

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 
 drivers/phy/Kconfig|   8 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 240 +
 4 files changed, 286 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..589f5c0
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
+ SoC.
+- reg: offset and length of the partial USB 2.0 Host register block.
+- reg-names: must be "usb2_host".
+- clocks: clock phandle and specifier pair(s).
+- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
+
+Optional properties:
+To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
+combined, the device tree node should set HSUSB properties to reg and reg-names
+properties. This is because HSUSB has registers to select USB 2.0 host or
+peripheral at that channel:
+- reg: offset and length of the partial HSUSB register block.
+- reg-names: must be "hsusb".
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
+   reg-names = "usb2_host", "hsusb";
+   clocks = <_clks R8A7795_CLK_EHCI0>,
+<_clks R8A7795_CLK_HSUSB>;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee0a0200 0 0x6ff>;
+   reg-names = "usb2_host";
+   clocks = <_clks R8A7795_CLK_EHCI0>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 47da573..ae3ba34 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,14 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
+   depends on OF
+   depends on ARCH_SHMOBILE
+   depends on GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate "OMAP CONTROL PHY Driver"
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index a5b18c1..97e83bc 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..f934e21
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,240 @@
+/*
+ * Renesas 

RE: [PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-10-01 Thread Yoshihiro Shimoda
Hi Rob,

> Sent: Friday, September 25, 2015 9:42 PM
> 
> Hi Rob,
> 
> Thank you for your comment!
> And, I'm sorry for the delayed response.
> 
> > Sent: Monday, September 21, 2015 11:01 PM
> >
> > On 09/18/2015 01:08 AM, Kishon Vijay Abraham I wrote:
< snip >
> > >> +Example (R-Car H3):
> > >> +
> > >> +usb-phy@ee080200 {
> > >> +compatible = "renesas,usb2-phy-r8a7795";
> > >> +reg = <0 0xee080200 0 0x6ff>, <0 0xe6590100 0 0x100>;
> > >> +reg-names = "usb2", "hsusb";
> > >
> > > hsusb is missing in Documentation.
> >
> > usb2 is the host controller? It is questionable that these should be
> > combined. Does this appear under another node? If so, don't overlap
> > resources in the DT.
> 
> Thank you for the point.
> I don't think that this appears under another node.
> However, to avoid such a situation, I should change the name somehow.

Perhaps I misunderstood your point. So, let me comment below again:

- This "usb2" means the partial registers of USB 2.0 host block.
  That host registers can control the USB2.0 PHY.
  This "hsusb" means the partial registers of USB 2.0 peripheral block.
  That peripheral registers can control the selector (host or peripheral).
  So, these should be combined in this driver.

- These resources don't appear under another nodes.

Best regards,
Yoshihiro Shimoda

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


RE: [PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-09-25 Thread Yoshihiro Shimoda
Hi Kishon,

Thank you for the review!
And I'm sorry for the delayed response.

> Sent: Friday, September 18, 2015 3:08 PM
> 
> Hi,
> 
> On Tuesday 25 August 2015 02:40 PM, Yoshihiro Shimoda wrote:
> > This patch adds support for R-Car generation 3 USB2 PHY driver.
> > This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
> > with the HSUSB (USB2.0 peripheral) device.
> 
> From the description it looks like it's a single PHY with multiple
> channels. In that case you should have a singe dt node for the PHY
> provider and each channel should be modelled as the child node of the
> PHY provider dt node.

Sorry for my lack information.
As my understanding, each EHCI/OHCI channel has a PHY because the following
things are differnce:
 - Memory map
  - ch0 = 0xee08
  - ch1 = 0xee0a
  - ch2 = 0xee0c

 - Clock ("module stop")
  - Each channel has a specific clock ("module stop bit").

< snip >
> > --- /dev/null
> > +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > @@ -0,0 +1,35 @@
> > +* Renesas R-Car generation 3 USB 2.0 PHY
> > +
> > +This file provides information on what the device node for the R-Car 
> > generation
> > +3 USB 2.0 PHY contains.
> > +
> > +Required properties:
> > +- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an 
> > R8A7795
> > + SoC.
> > +- reg: offset and length of the USB2.0 host register block.
> > +- reg-names: must be "usb2".
> > +- clocks: clock phandle and specifier pair(s).
> > +- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
> > +
> > +Optional properties:
> > +To use a USB channel where EHCI/OHCI and HSUSB are combined, the device 
> > tree
> > +node should set HSUSB properties to reg and reg-names properties:
> > +- reg: offset and length of the HSUSB register block.
> > +- reg-names: must be "hsusb".
> > +
> > +Example (R-Car H3):
> > +
> > +   usb-phy@ee080200 {
> > +   compatible = "renesas,usb2-phy-r8a7795";
> > +   reg = <0 0xee080200 0 0x6ff>, <0 0xe6590100 0 0x100>;
> > +   reg-names = "usb2", "hsusb";
> 
> hsusb is missing in Documentation.

I wrote the "hsusb" as Optional properties in the Documentation.
Or, Is my understanding about your comment wrong?

< snip >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 0fe9bff..406dc43 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -116,6 +116,12 @@ config PHY_RCAR_GEN2
> > help
> >   Support for USB PHY found on Renesas R-Car generation 2 SoCs.
> >
> > +config PHY_RCAR_GEN3_USB2
> > +   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
> > +   depends on GENERIC_PHY
> 
> depends on OF?

Thank you for the point. I will fix it.

Best regards,
Yoshihiro Shimoda

> Thanks
> Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


RE: [PATCH] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-09-25 Thread Yoshihiro Shimoda
Hi Rob,

Thank you for your comment!
And, I'm sorry for the delayed response.

> Sent: Monday, September 21, 2015 11:01 PM
> 
> On 09/18/2015 01:08 AM, Kishon Vijay Abraham I wrote:
> > Hi,
> >
> > On Tuesday 25 August 2015 02:40 PM, Yoshihiro Shimoda wrote:
> >> This patch adds support for R-Car generation 3 USB2 PHY driver.
> >> This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
> >> with the HSUSB (USB2.0 peripheral) device.
> >
> > From the description it looks like it's a single PHY with multiple
> > channels. In that case you should have a singe dt node for the PHY
> > provider and each channel should be modelled as the child node of the
> > PHY provider dt node.
> 
> You only need sub-nodes if you need per channel properties. Otherwise,
> #phy-cells can be 1 and the cell value can be the channel number.

Thank you for the information. I got it.

< snip >
> >> diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> >> new file mode 100644
> >> index 000..1d57766
> >> --- /dev/null
> >> +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> >> @@ -0,0 +1,35 @@
> >> +* Renesas R-Car generation 3 USB 2.0 PHY
> >> +
> >> +This file provides information on what the device node for the R-Car 
> >> generation
> >> +3 USB 2.0 PHY contains.
> >> +
> >> +Required properties:
> >> +- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an 
> >> R8A7795
> >> +SoC.
> >> +- reg: offset and length of the USB2.0 host register block.
> 
> host register block? You mean phy register block?

Oops, thank you for the point. I will fix it.

> >> +- reg-names: must be "usb2".
> >> +- clocks: clock phandle and specifier pair(s).
> >> +- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
> >> +
> >> +Optional properties:
> >> +To use a USB channel where EHCI/OHCI and HSUSB are combined, the device 
> >> tree
> >> +node should set HSUSB properties to reg and reg-names properties:
> >> +- reg: offset and length of the HSUSB register block.
> >> +- reg-names: must be "hsusb".
> >> +
> >> +Example (R-Car H3):
> >> +
> >> +  usb-phy@ee080200 {
> >> +  compatible = "renesas,usb2-phy-r8a7795";
> >> +  reg = <0 0xee080200 0 0x6ff>, <0 0xe6590100 0 0x100>;
> >> +  reg-names = "usb2", "hsusb";
> >
> > hsusb is missing in Documentation.
> 
> usb2 is the host controller? It is questionable that these should be
> combined. Does this appear under another node? If so, don't overlap
> resources in the DT.

Thank you for the point.
I don't think that this appears under another node.
However, to avoid such a situation, I should change the name somehow.

Best regards,
Yoshihiro Shimoda

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


[PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling

2016-01-07 Thread Yoshihiro Shimoda
Since the related driver (CPG/MSSR driver) only manages the first module
clock, this driver should not handle the HSUSB registers. So, this patch
removes the HSUSB registers handling.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the linux-phy / next branch.
 (commit id = 9955a7835bf376e12482583958b2661f501b868b)

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 15 ++--
 drivers/phy/phy-rcar-gen3-usb2.c   | 83 +++---
 2 files changed, 15 insertions(+), 83 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index 2390e4e..eaf7e9b 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -7,33 +7,26 @@ Required properties:
 - compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
  SoC.
 - reg: offset and length of the partial USB 2.0 Host register block.
-- reg-names: must be "usb2_host".
 - clocks: clock phandle and specifier pair(s).
 - #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
 
 Optional properties:
 To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
-combined, the device tree node should set HSUSB properties to reg and reg-names
-properties. This is because HSUSB has registers to select USB 2.0 host or
-peripheral at that channel:
-- reg: offset and length of the partial HSUSB register block.
-- reg-names: must be "hsusb".
+combined, the device tree node should set interrupt properties to use the
+channel as USB OTG:
 - interrupts: interrupt specifier for the PHY.
 
 Example (R-Car H3):
 
usb-phy@ee080200 {
compatible = "renesas,usb2-phy-r8a7795";
-   reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
-   reg-names = "usb2_host", "hsusb";
+   reg = <0 0xee080200 0 0x700>;
interrupts = ;
-   clocks = <_clks R8A7795_CLK_EHCI0>,
-<_clks R8A7795_CLK_HSUSB>;
+   clocks = <_clks R8A7795_CLK_EHCI0>;
};
 
usb-phy@ee0a0200 {
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee0a0200 0 0x700>;
-   reg-names = "usb2_host";
clocks = <_clks R8A7795_CLK_EHCI0>;
};
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index ef332ef..bc4f7dd 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -74,20 +74,6 @@
 #define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is enabled */
 #define USB2_ADPCTRL_DRVVBUS   BIT(4)
 
-/*** HSUSB registers (original offset is +0x100) ***/
-#define HSUSB_LPSTS0x02
-#define HSUSB_UGCTRL2  0x84
-
-/* Low Power Status register (LPSTS) */
-#define HSUSB_LPSTS_SUSPM  0x4000
-
-/* USB General control register 2 (UGCTRL2) */
-#define HSUSB_UGCTRL2_MASK 0x0031 /* bit[31:6] should be 0 */
-#define HSUSB_UGCTRL2_USB0SEL  0x0030
-#define HSUSB_UGCTRL2_USB0SEL_HOST 0x0010
-#define HSUSB_UGCTRL2_USB0SEL_HS_USB   0x0020
-#define HSUSB_UGCTRL2_USB0SEL_OTG  0x0030
-
 struct rcar_gen3_data {
void __iomem *base;
struct clk *clk;
@@ -95,8 +81,8 @@ struct rcar_gen3_data {
 
 struct rcar_gen3_chan {
struct rcar_gen3_data usb2;
-   struct rcar_gen3_data hsusb;
struct phy *phy;
+   bool has_otg;
 };
 
 static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
@@ -202,24 +188,15 @@ static int rcar_gen3_phy_usb2_init(struct phy *p)
 {
struct rcar_gen3_chan *channel = phy_get_drvdata(p);
void __iomem *usb2_base = channel->usb2.base;
-   void __iomem *hsusb_base = channel->hsusb.base;
-   u32 val;
 
/* Initialize USB2 part */
writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE);
writel(USB2_SPD_RSM_TIMSET_INIT, usb2_base + USB2_SPD_RSM_TIMSET);
writel(USB2_OC_TIMSET_INIT, usb2_base + USB2_OC_TIMSET);
 
-   /* Initialize HSUSB part */
-   if (hsusb_base) {
-   val = readl(hsusb_base + HSUSB_UGCTRL2);
-   val = (val & ~HSUSB_UGCTRL2_USB0SEL) |
- HSUSB_UGCTRL2_USB0SEL_OTG;
-   writel(val & HSUSB_UGCTRL2_MASK, hsusb_base + HSUSB_UGCTRL2);
-
-   /* Initialize otg part */
+   /* Initialize otg part */
+   if (channel->has_otg)
rcar_gen3_init_otg(channel);
-   }
 
return 0;
 }
@@ -237,7 +214,6 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
 {
struct rcar_gen3_chan *channel = phy

RE: [PATCH v5 1/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-11-26 Thread Yoshihiro Shimoda
Hi,

Thank you for the review!

> From: Kishon Vijay Abraham I [mailto:kis...@ti.com]
> Sent: Friday, November 27, 2015 2:21 PM
> 
> Hi,
> 
> On Tuesday 20 October 2015 02:27 PM, Yoshihiro Shimoda wrote:
> > This patch adds support for R-Car generation 3 USB2 PHY driver.
> > This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
> > with the HSUSB (USB2.0 peripheral) device. And each channel has
> > independent registers about the PHYs.
> >
> > So, the purpose of this driver is:
> >  1) initializes some registers of SoC specific to use the
> > {ehci,ohci}-platform driver.
> >
> >  2) detects id pin to select host or peripheral on the channel 0.
> >
> > For now, this driver only supports 1) above.
> 
> When you do 2), make sure to use the extcon framework.

Thank you for your proposal! I will use the extcon framework for it.

> One minor comment below and then I can queue it for 4.5.

Thank you!

< snip >
> > +   provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> > +   if (IS_ERR(provider)) {
> > +   dev_err(dev, "Failed to register PHY provider\n");
> > +   return PTR_ERR(provider);
> > +   }
> > +
> > +   return 0;
> 
> This can simply be replaced with return PTR_ERR_OR_ZERO(provider);

Yes, I tested that this could simply be replaced with "return 
PTR_ERR_OR_ZERO(provider);".
So, should I send v6 patch?

Best regards,
Yoshihiro Shimoda

> Thanks
> Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/


[PATCH v6 0/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-11-29 Thread Yoshihiro Shimoda
This patch is based on the latest linux-phy / next branch.
(commit id = 8005c49d9aea74d382f474ce11afbbc7d7130bec)

 Changes from v5:
 - Minor modify the rcar_gen3_phy_usb2_probe() in patch 1.
 - Rebase the latest linux-phy / next branch.

 Changes from v4:
  - Modify Kconfig to "depends on OF && ARCH_SHMOBILE".
  - Modify Kconfig to "select GENERIC_PHY" instead of "depends on GENERIC_PHY".
  - Modify device tree documentation about "reg" of example.
  - Remove spinlock handling because phy-core driver calls mutex_lock().
  - Change valiable name to val instead of tmp.
  - Remove dev_set_drvdata.
  - Use dev_vdbg() instead of dev_dbg().
  - Change rcar_gen3_device_recognition()'s condition as one line.
  - Remove unnecessary value in rcar_gen3_phy_usb2_probe().
  - Modify MAINTAINERS about this driver.

 Changes from v3:
  - Shorten structure names to avoid new line if we add a long function name.
  - Add ID/VBUS pin detection for peripheral mode.

 Changes from v2:
  - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
  - Add more information in the dt document.
  - Change reg-names from "usb2" to "usb2_host".

 Changes from v1:
  - Revise some typos.
  - Remove using clk API to enable/disable the clocks.
(In other words, this driver expects to enable/disable the clocks by
 Runtime PM API by the phy-core driver.)
  - Remove an unnecessary header file (asm/cmpxchg.h).

Yoshihiro Shimoda (4):
  phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver
  phy: rcar-gen3-usb2: change the mode to OTG on the combined channel
  phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection
  MAINTAINERS: add Renesas usb2 phy driver

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  39 +++
 MAINTAINERS|   6 +
 drivers/phy/Kconfig|   7 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 378 +
 5 files changed, 431 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

-- 
1.9.1

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


[PATCH v6 4/4] MAINTAINERS: add Renesas usb2 phy driver

2015-11-29 Thread Yoshihiro Shimoda
Add Renesas usb2 phy driver to maintainer entry.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 MAINTAINERS | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/MAINTAINERS b/MAINTAINERS
index e9caa4b..ac1e301 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -8928,6 +8928,12 @@ F:   drivers/rpmsg/
 F: Documentation/rpmsg.txt
 F: include/linux/rpmsg.h
 
+RENESAS USB2 PHY DRIVER
+M: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+L: linux...@vger.kernel.org
+S: Maintained
+F: drivers/phy/phy-rcar-gen3-usb2.c
+
 RESET CONTROLLER FRAMEWORK
 M: Philipp Zabel <p.za...@pengutronix.de>
 S: Maintained
-- 
1.9.1

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


[PATCH v6 1/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-11-29 Thread Yoshihiro Shimoda
This patch adds support for R-Car generation 3 USB2 PHY driver.
This SoC has 3 EHCI/OHCI channels, and the channel 0 is shared
with the HSUSB (USB2.0 peripheral) device. And each channel has
independent registers about the PHYs.

So, the purpose of this driver is:
 1) initializes some registers of SoC specific to use the
{ehci,ohci}-platform driver.

 2) detects id pin to select host or peripheral on the channel 0.

For now, this driver only supports 1) above.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  37 
 drivers/phy/Kconfig|   7 +
 drivers/phy/Makefile   |   1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 217 +
 4 files changed, 262 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
 create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
new file mode 100644
index 000..affa0f7
--- /dev/null
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -0,0 +1,37 @@
+* Renesas R-Car generation 3 USB 2.0 PHY
+
+This file provides information on what the device node for the R-Car generation
+3 USB 2.0 PHY contains.
+
+Required properties:
+- compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
+ SoC.
+- reg: offset and length of the partial USB 2.0 Host register block.
+- reg-names: must be "usb2_host".
+- clocks: clock phandle and specifier pair(s).
+- #phy-cells: see phy-bindings.txt in the same directory, must be <0>.
+
+Optional properties:
+To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 Peripheral) are
+combined, the device tree node should set HSUSB properties to reg and reg-names
+properties. This is because HSUSB has registers to select USB 2.0 host or
+peripheral at that channel:
+- reg: offset and length of the partial HSUSB register block.
+- reg-names: must be "hsusb".
+
+Example (R-Car H3):
+
+   usb-phy@ee080200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
+   reg-names = "usb2_host", "hsusb";
+   clocks = <_clks R8A7795_CLK_EHCI0>,
+<_clks R8A7795_CLK_HSUSB>;
+   };
+
+   usb-phy@ee0a0200 {
+   compatible = "renesas,usb2-phy-r8a7795";
+   reg = <0 0xee0a0200 0 0x700>;
+   reg-names = "usb2_host";
+   clocks = <_clks R8A7795_CLK_EHCI0>;
+   };
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 7eb5859d..e9ab088 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -118,6 +118,13 @@ config PHY_RCAR_GEN2
help
  Support for USB PHY found on Renesas R-Car generation 2 SoCs.
 
+config PHY_RCAR_GEN3_USB2
+   tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
+   depends on OF && ARCH_SHMOBILE
+   select GENERIC_PHY
+   help
+ Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
+
 config OMAP_CONTROL_PHY
tristate "OMAP CONTROL PHY Driver"
depends on ARCH_OMAP2PLUS || COMPILE_TEST
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 075db1a..91d7a62 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_PHY_MVEBU_SATA)  += phy-mvebu-sata.o
 obj-$(CONFIG_PHY_MIPHY28LP)+= phy-miphy28lp.o
 obj-$(CONFIG_PHY_MIPHY365X)+= phy-miphy365x.o
 obj-$(CONFIG_PHY_RCAR_GEN2)+= phy-rcar-gen2.o
+obj-$(CONFIG_PHY_RCAR_GEN3_USB2)   += phy-rcar-gen3-usb2.o
 obj-$(CONFIG_OMAP_CONTROL_PHY) += phy-omap-control.o
 obj-$(CONFIG_OMAP_USB2)+= phy-omap-usb2.o
 obj-$(CONFIG_TI_PIPE3) += phy-ti-pipe3.o
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
new file mode 100644
index 000..2696152
--- /dev/null
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -0,0 +1,217 @@
+/*
+ * Renesas R-Car Gen3 for USB2.0 PHY driver
+ *
+ * Copyright (C) 2015 Renesas Electronics Corporation
+ *
+ * This is based on the phy-rcar-gen2 driver:
+ * Copyright (C) 2014 Renesas Solutions Corp.
+ * Copyright (C) 2014 Cogent Embedded, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/*** USB2.0 Host registers (original offset is +0x200) ***/
+#define USB2_INT_ENABLE0x000
+#define USB2_U

[PATCH v6 2/4] phy: rcar-gen3-usb2: change the mode to OTG on the combined channel

2015-11-29 Thread Yoshihiro Shimoda
To use the channel 0 of R-Car gen3 as periperal mode, This patch changes
the mode to OTG instead of HOST. Then, this driver needs to set some
registers to enable host mode and detects ID pin and VBUS pin at
phy_init() timing.

For now, the channel 0 can be used as host mode only.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 124 ++-
 1 file changed, 122 insertions(+), 2 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 2696152..2b5d890 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -24,6 +24,10 @@
 #define USB2_USBCTR0x00c
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
+#define USB2_COMMCTRL  0x600
+#define USB2_VBCTRL0x60c
+#define USB2_LINECTRL1 0x610
+#define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
@@ -41,6 +45,24 @@
 /* OC_TIMSET */
 #define USB2_OC_TIMSET_INIT0x000209ab
 
+/* COMMCTRL */
+#define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
+
+/* VBCTRL */
+#define USB2_VBCTRL_DRVVBUSSEL BIT(8)
+
+/* LINECTRL1 */
+#define USB2_LINECTRL1_DPRPD_ENBIT(19)
+#define USB2_LINECTRL1_DP_RPD  BIT(18)
+#define USB2_LINECTRL1_DMRPD_ENBIT(17)
+#define USB2_LINECTRL1_DM_RPD  BIT(16)
+
+/* ADPCTRL */
+#define USB2_ADPCTRL_OTGSESSVLDBIT(20)
+#define USB2_ADPCTRL_IDDIG BIT(19)
+#define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is enabled */
+#define USB2_ADPCTRL_DRVVBUS   BIT(4)
+
 /*** HSUSB registers (original offset is +0x100) ***/
 #define HSUSB_LPSTS0x02
 #define HSUSB_UGCTRL2  0x84
@@ -66,6 +88,102 @@ struct rcar_gen3_chan {
struct phy *phy;
 };
 
+static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_COMMCTRL);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, host);
+   if (host)
+   val &= ~USB2_COMMCTRL_OTG_PERI;
+   else
+   val |= USB2_COMMCTRL_OTG_PERI;
+   writel(val, usb2_base + USB2_COMMCTRL);
+}
+
+static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_LINECTRL1);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm);
+   val &= ~(USB2_LINECTRL1_DP_RPD | USB2_LINECTRL1_DM_RPD);
+   if (dp)
+   val |= USB2_LINECTRL1_DP_RPD;
+   if (dm)
+   val |= USB2_LINECTRL1_DM_RPD;
+   writel(val, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val = readl(usb2_base + USB2_ADPCTRL);
+
+   dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, vbus);
+   if (vbus)
+   val |= USB2_ADPCTRL_DRVVBUS;
+   else
+   val &= ~USB2_ADPCTRL_DRVVBUS;
+   writel(val, usb2_base + USB2_ADPCTRL);
+}
+
+static void rcar_gen3_init_for_host(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+}
+
+static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) &
+ USB2_ADPCTRL_OTGSESSVLD);
+}
+
+static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
+{
+   return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
+}
+
+static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
+{
+   bool is_host = true;
+
+   /* B-device? */
+   if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch))
+   is_host = false;
+
+   if (is_host)
+   rcar_gen3_init_for_host(ch);
+   else
+   rcar_gen3_init_for_peri(ch);
+}
+
+static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_VBCTRL);
+   writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   val = readl(usb2_base + USB2_ADPCTRL);
+   writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
+   val = readl(usb2_base + USB2_LINECTRL1);
+   rcar_gen3_set_linectrl(ch, 0, 0);
+   write

[PATCH v6 3/4] phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection

2015-11-29 Thread Yoshihiro Shimoda
This patch adds support for runtime ID/VBUS pin detection if
the channel 0 of R-Car gen3 is used. So, we are able to use
the channel as both host and peripheral.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 43 +-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index affa0f7..2390e4e 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -18,6 +18,7 @@ properties. This is because HSUSB has registers to select USB 
2.0 host or
 peripheral at that channel:
 - reg: offset and length of the partial HSUSB register block.
 - reg-names: must be "hsusb".
+- interrupts: interrupt specifier for the PHY.
 
 Example (R-Car H3):
 
@@ -25,6 +26,7 @@ Example (R-Car H3):
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee080200 0 0x700>, <0 0xe6590100 0 0x100>;
reg-names = "usb2_host", "hsusb";
+   interrupts = ;
clocks = <_clks R8A7795_CLK_EHCI0>,
 <_clks R8A7795_CLK_HSUSB>;
};
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 2b5d890..ef332ef 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -12,6 +12,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -25,14 +26,18 @@
 #define USB2_SPD_RSM_TIMSET0x10c
 #define USB2_OC_TIMSET 0x110
 #define USB2_COMMCTRL  0x600
+#define USB2_OBINTSTA  0x604
+#define USB2_OBINTEN   0x608
 #define USB2_VBCTRL0x60c
 #define USB2_LINECTRL1 0x610
 #define USB2_ADPCTRL   0x630
 
 /* INT_ENABLE */
+#define USB2_INT_ENABLE_UCOM_INTEN BIT(3)
 #define USB2_INT_ENABLE_USBH_INTB_EN   BIT(2)
 #define USB2_INT_ENABLE_USBH_INTA_EN   BIT(1)
-#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_USBH_INTB_EN | \
+#define USB2_INT_ENABLE_INIT   (USB2_INT_ENABLE_UCOM_INTEN | \
+USB2_INT_ENABLE_USBH_INTB_EN | \
 USB2_INT_ENABLE_USBH_INTA_EN)
 
 /* USBCTR */
@@ -48,6 +53,12 @@
 /* COMMCTRL */
 #define USB2_COMMCTRL_OTG_PERI BIT(31) /* 1 = Peripheral mode */
 
+/* OBINTSTA and OBINTEN */
+#define USB2_OBINT_SESSVLDCHG  BIT(12)
+#define USB2_OBINT_IDDIGCHGBIT(11)
+#define USB2_OBINT_BITS(USB2_OBINT_SESSVLDCHG | \
+USB2_OBINT_IDDIGCHG)
+
 /* VBCTRL */
 #define USB2_VBCTRL_DRVVBUSSEL BIT(8)
 
@@ -174,6 +185,9 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 
val = readl(usb2_base + USB2_VBCTRL);
writel(val | USB2_VBCTRL_DRVVBUSSEL, usb2_base + USB2_VBCTRL);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
val = readl(usb2_base + USB2_ADPCTRL);
writel(val | USB2_ADPCTRL_IDPULLUP, usb2_base + USB2_ADPCTRL);
val = readl(usb2_base + USB2_LINECTRL1);
@@ -270,6 +284,23 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = {
.owner  = THIS_MODULE,
 };
 
+static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
+{
+   struct rcar_gen3_chan *ch = _ch;
+   void __iomem *usb2_base = ch->usb2.base;
+   u32 status = readl(usb2_base + USB2_OBINTSTA);
+   irqreturn_t ret = IRQ_NONE;
+
+   if (status & USB2_OBINT_BITS) {
+   dev_vdbg(>phy->dev, "%s: %08x\n", __func__, status);
+   writel(USB2_OBINT_BITS, usb2_base + USB2_OBINTSTA);
+   rcar_gen3_device_recognition(ch);
+   ret = IRQ_HANDLED;
+   }
+
+   return ret;
+}
+
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
{ .compatible = "renesas,usb2-phy-r8a7795" },
{ }
@@ -302,9 +333,19 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
 
/* To avoid error message by devm_ioremap_resource() */
if (res) {
+   int irq;
+
channel->hsusb.base = devm_ioremap_resource(dev, res);
if (IS_ERR(channel->hsusb.base))
channel->hsusb.base = NULL;
+   /* call request_irq for OTG */
+   irq = platform_get_irq(pdev, 0);
+   if (irq >= 0)
+   irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
+   

RE: [PATCH v5 0/4] phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver

2015-11-23 Thread Yoshihiro Shimoda
Hi Kishon,

> From: Yoshihiro Shimoda
> Sent: Tuesday, October 20, 2015 5:58 PM
> 
> This patch is based on the latest linux-phy / next branch.
> (commit id = 0f8669e343982ac66f4420335777cb5456b8abb0)

Would you review this patch set?
I confirmed the patch set could apply the latest linux-phy / next branch 
correctly.
(commit id = 8005c49d9aea74d382f474ce11afbbc7d7130bec)

Best regards,
Yoshihiro Shimoda

>  Changes from v4:
>   - Modify Kconfig to "depends on OF && ARCH_SHMOBILE".
>   - Modify Kconfig to "select GENERIC_PHY" instead of "depends on 
> GENERIC_PHY".
>   - Modify device tree documentation about "reg" of example.
>   - Remove spinlock handling because phy-core driver calls mutex_lock().
>   - Change valiable name to val instead of tmp.
>   - Remove dev_set_drvdata.
>   - Use dev_vdbg() instead of dev_dbg().
>   - Change rcar_gen3_device_recognition()'s condition as one line.
>   - Remove unnecessary value in rcar_gen3_phy_usb2_probe().
>   - Modify MAINTAINERS about this driver.
> 
>  Changes from v3:
>   - Shorten structure names to avoid new line if we add a long function name.
>   - Add ID/VBUS pin detection for peripheral mode.
> 
>  Changes from v2:
>   - Modify Kconfig to add "depends on OF" and "depends on ARCH_SHMOBILE".
>   - Add more information in the dt document.
>   - Change reg-names from "usb2" to "usb2_host".
> 
>  Changes from v1:
>   - Revise some typos.
>   - Remove using clk API to enable/disable the clocks.
>     (In other words, this driver expects to enable/disable the clocks by
>  Runtime PM API by the phy-core driver.)
>   - Remove an unnecessary header file (asm/cmpxchg.h).
> 
> Yoshihiro Shimoda (4):
>   phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver
>   phy: rcar-gen3-usb2: change the mode to OTG on the combined channel
>   phy: rcar-gen3-usb2: add runtime ID/VBUS pin detection
>   MAINTAINERS: add Renesas usb2 phy driver
> 
>  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  39 +++
>  MAINTAINERS|   6 +
>  drivers/phy/Kconfig|   7 +
>  drivers/phy/Makefile   |   1 +
>  drivers/phy/phy-rcar-gen3-usb2.c   | 380 
> +
>  5 files changed, 433 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
>  create mode 100644 drivers/phy/phy-rcar-gen3-usb2.c
> 
> --
> 1.9.1

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


RE: [PATCH v9 00/14] USB OTG/dual-role framework

2016-06-09 Thread Yoshihiro Shimoda
Hi Roger,

> From: Roger Quadros
> Sent: Thursday, June 09, 2016 4:31 PM
> 
> Peter & Yoshihiro,
> 
> On 09/06/16 08:27, Peter Chen wrote:
> > On Wed, Jun 8, 2016 at 5:03 PM, Roger Quadros <rog...@ti.com> wrote:
> >> Hi,
> >>
> >> This series centralizes OTG/Dual-role functionality in the kernel.
> >> As of now I've got Dual-role functionality working pretty reliably on
> >> dra7-evm and am437x-gp-evm.
> >>
> >> DWC3 controller and TI platform related patches will be sent separately.
> >>
> >> Series is based on v4.7-rc1.
> >>
> >
> > Roger, I will wait your dwc3 and TI patch set since one framework needs
> > one user at least, thanks.
> 
> Sure I will post the dwc3 patch.
> 
> Yoshihiro,
> 
> could you please post the platform side patches for your platform
> that enables dual-role using this framework? Thanks.

Sure. I will do that.

Best regards,
Yoshihiro Shimoda

> --
> cheers,
> -roger


RE: [PATCH v9 13/14] usb: gadget: udc: adapt to OTG core

2016-06-09 Thread Yoshihiro Shimoda
Hi Roger,

> From: Roger Quadros
> Sent: Wednesday, June 08, 2016 6:04 PM
> 
> The OTG state machine needs a mechanism to start and
> stop the gadget controller as well as connect/disconnect
> from the bus. Add usb_gadget_start(), usb_gadget_stop()
> and usb_gadget_connect_control().
> 
> Introduce usb_otg_add_gadget_udc() to allow controller drivers
> to register a gadget controller that is part of an OTG instance.
> 
> Register with OTG core when UDC is added in usb_add_gadget_udc_release()
> and unregister on usb_del_gadget_udc().
> 
> Notify the OTG core when gadget function driver is available on
> udc_bind_to_driver() and when it is removed in usb_gadget_remove_driver().
> 
> We need to unlock the usb_lock mutex before calling
> usb_otg_register_gadget() else it will cause a circular
> locking dependency.
> 
> Ignore softconnect sysfs control when we're in OTG
> mode as OTG FSM should care of gadget softconnect using
> the b_bus_req mechanism.
> 
> Signed-off-by: Roger Quadros <rog...@ti.com>
> ---
>  drivers/usb/gadget/udc/udc-core.c | 202 
> --
>  include/linux/usb/gadget.h|   4 +
>  2 files changed, 196 insertions(+), 10 deletions(-)

I tried to apply this patch on the Felipe's usb.git / testing/next branch,
but I couldn't apply because the udc-core.c was renamed to core.c.
https://git.kernel.org/cgit/linux/kernel/git/balbi/usb.git/commit/?h=testing/next=a22b539c7082b6a3046b3a9cebb356a047a2d81d

I guess this patch needs rebase for that.

Best regards,
Yoshihiro Shimoda



[PATCH] phy: rcar-gen3-usb2: fix unexpected repeat interrupts of VBUS change

2016-05-31 Thread Yoshihiro Shimoda
This patch fixes an issue that the driver is possible to cause
unexpected repeat interrupts if a board condition is wrong
(e.g. even if the ID pin is as function, a board supplies the VBUS.)

The reason why unexpected repeat interrupts happen is:
 1) The driver changed the mode to function if it detected the ID pin
is high and the VBUS is high.
 2) After the driver changed function mode, it disabled the "VBUS control"
feature. Then, the VBUS signal will be low.
 3) Since the VBUS change interruption happened, the driver checked
the ID pin and VBUS.
 4) Since VBUS was low, the driver changed the mode to host and enabled
the "VBUS control" feature. Then the VBUS signal will be high.
 5) Since the VBUS change interruption happened, the driver did 1) above.

So, this patch modified the condition in rcar_gen3_device_recognition()
to check the ID pin only.

Fixes: 1114e2d (phy: rcar-gen3-usb2: change the mode to OTG on the combined 
channel)
Cc: <sta...@vger.kernel.org> # v4.5+
Reported-by: Simon Horman <ho...@verge.net.au>
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 76bb88f..4be3f5d 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -144,12 +144,6 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
 }
 
-static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
-{
-   return !!(readl(ch->base + USB2_ADPCTRL) &
- USB2_ADPCTRL_OTGSESSVLD);
-}
-
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -157,13 +151,7 @@ static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 
 static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
 {
-   bool is_host = true;
-
-   /* B-device? */
-   if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch))
-   is_host = false;
-
-   if (is_host)
+   if (!rcar_gen3_check_id(ch))
rcar_gen3_init_for_host(ch);
else
rcar_gen3_init_for_peri(ch);
-- 
1.9.1



RE: [PATCH] phy: rcar-gen3-usb2: fix unexpected repeat interrupts of VBUS change

2016-06-16 Thread Yoshihiro Shimoda
Hi Kishon,

Would you review this patch?

Best regards,
Yoshihiro Shimoda

> -Original Message-
> From: Yoshihiro Shimoda
> Sent: Tuesday, May 31, 2016 9:47 PM
> To: kis...@ti.com
> Cc: linux-kernel@vger.kernel.org; linux-renesas-...@vger.kernel.org; 
> sta...@vger.kernel.org; Yoshihiro Shimoda
> <yoshihiro.shimoda...@renesas.com>
> Subject: [PATCH] phy: rcar-gen3-usb2: fix unexpected repeat interrupts of 
> VBUS change
> 
> This patch fixes an issue that the driver is possible to cause
> unexpected repeat interrupts if a board condition is wrong
> (e.g. even if the ID pin is as function, a board supplies the VBUS.)
> 
> The reason why unexpected repeat interrupts happen is:
>  1) The driver changed the mode to function if it detected the ID pin
> is high and the VBUS is high.
>  2) After the driver changed function mode, it disabled the "VBUS control"
> feature. Then, the VBUS signal will be low.
>  3) Since the VBUS change interruption happened, the driver checked
> the ID pin and VBUS.
>  4) Since VBUS was low, the driver changed the mode to host and enabled
> the "VBUS control" feature. Then the VBUS signal will be high.
>  5) Since the VBUS change interruption happened, the driver did 1) above.
> 
> So, this patch modified the condition in rcar_gen3_device_recognition()
> to check the ID pin only.
> 
> Fixes: 1114e2d (phy: rcar-gen3-usb2: change the mode to OTG on the combined 
> channel)
> Cc: <sta...@vger.kernel.org> # v4.5+
> Reported-by: Simon Horman <ho...@verge.net.au>
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  drivers/phy/phy-rcar-gen3-usb2.c | 14 +-
>  1 file changed, 1 insertion(+), 13 deletions(-)
> 
> diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> b/drivers/phy/phy-rcar-gen3-usb2.c
> index 76bb88f..4be3f5d 100644
> --- a/drivers/phy/phy-rcar-gen3-usb2.c
> +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> @@ -144,12 +144,6 @@ static void rcar_gen3_init_for_peri(struct 
> rcar_gen3_chan *ch)
>   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
>  }
> 
> -static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
> -{
> - return !!(readl(ch->base + USB2_ADPCTRL) &
> -   USB2_ADPCTRL_OTGSESSVLD);
> -}
> -
>  static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
>  {
>   return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
> @@ -157,13 +151,7 @@ static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
> 
>  static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
>  {
> - bool is_host = true;
> -
> - /* B-device? */
> - if (rcar_gen3_check_id(ch) && rcar_gen3_check_vbus(ch))
> - is_host = false;
> -
> - if (is_host)
> + if (!rcar_gen3_check_id(ch))
>   rcar_gen3_init_for_host(ch);
>   else
>   rcar_gen3_init_for_peri(ch);
> --
> 1.9.1



RE: [PATCH v11 08/14] usb: otg: add OTG/dual-role core

2016-06-23 Thread Yoshihiro Shimoda
Hi Roger-san,

< snip >
> >>>> commit 11c011a5e777c83819078a18672543f04482b3ec
> >>>> Author: Srinivas Kandagatla <srinivas.kandaga...@linaro.org>
> >>>> Date:   Thu May 19 11:12:56 2016 +0100
> >>>>
> >>>> usb: echi-hcd: Add ehci_setup check before echi_shutdown
> >>>>
> >>>>
> >>>>
> >>>> In some cases, the USB code (gadget/hcd->start/stop) needs to be called
> >>>> during the role swap. For example, if you have mux driver, you may
> >>>> need to call usb_remove_hcd when ID from 0 to 1. Without Roger's 
> >>>> framework,
> >>>> how can we do that?
> >>>
> >>> You don't really need to remove the gadget. Just mask its interrupts and
> >>> ignore any calls to any gadget_driver ops, right? Likewise for
> >>> XHCI. Just clear RUN/STOP and no events will ever reach XHCI. But, from
> >>> the point of view of dwc3, it's simpler to unregister the platform
> >>> device we create for xhci-plat.c. I need no changes in XHCI to do that
> >>> and driver model will make sure to call xhci-plat's ->remove() which
> >>> will handle everything for me correctly.
> >>>
> >>
> >> I admit it can do in a IP driver, eg both host and peripheral for the
> >> single IP, eg chipidea, dwc3, etc. But how can we clear RUN/STOP bit
> >> or what else for HCD at mux driver?
> >
> > dwc3's OTG block has control of that, however, what I'll do is
> > platform_device_del() xhci-plat's device. Not one line changes inside
> > XHCI.
> >
> 
> Let's talk about how non dwc3 based platforms can get it done.
> 
> Yoshihiro-san, could you please share your platform requirements from 
> dual-role
> perspective?

My platform requirements about dual-role are:
- Initial settings of all host, gadget and OTG IP registers are needed before 
enters [AB]-device recognition procedure.
- In the recognition procedures, a software needs:
 - to check ID pin related register in OTG
 - to set OTG IP registers to change the role
  - and then host or gadget can start.
- In the disconnect detection procedures, a software needs similar 
checkings/settings with the recognition.

Best regards,
Yoshihiro Shimoda

> cheers,
> -roger



RE: [PATCH v11 08/14] usb: otg: add OTG/dual-role core

2016-06-23 Thread Yoshihiro Shimoda
rted and which shouldn't be
> > touched unless it's for debugging purposes. When I implemented that, our
> > ->probe() went from 400ms down to about 50us.
> >
> > Coupled with that, the OTG chapter also became a lot clearer to the
> > point that it states you just don't initialize anything other than the
> > OTG block, and just wait for OTG interrupt to do whatever it is you need
> > to do.
> >
> > This meant that we could actually afford to do full reinitialization of
> > dwc3 on role swap (it's now only 50us anyway) and we knew how to swap
> > roles properly.
> >
> > (The reason for needing soft-reset during role swap is kinda long. But
> > in summary dwc3 shadows register writes to both host and peripheral
> > sides)
> >
> > > just discuss if it is necessary for dual-role switch.
> >
> > fair. However, if we have a single user we don't have a Generic
> > layer. There's not enough variance to come up with truly generic
> > architecture for this.
> >
> > --
> 
> I have put some points in my last reply [1], I summery it here to
> see if a generic framework is deserved or not?
> 
> 1. If there are some parts we can use during the role switch
> - The common start/stop host and peripheral operation
> eg, when switch from host to peripheral, all drivers can use
> usb_remove_hcd to finish it.
> - A common workqueue to handle vbus and id event
> - sysfs for role switch
> 
> 2. Does a mux driver can do it well? Yoshihiro, here we need your
> point. The main point is if we need to call USB API to change
> roles (eg, usb_remove_hcd) during the role switch, thanks.

In my platform, it doesn't need to call USB API (usb_remove_hcd) when
"A-host" is changed to "A-peripheral".
(Since this is a prototype local code, the code is not upstreaming yet though.)

Best regards,
Yoshihiro Shimoda

> 
> [1] http://www.spinics.net/lists/linux-usb/msg142974.html
> --
> 
> Best Regards,
> Peter Chen


RE: [PATCH] usb: xhci: handle uPD720201 and uPD720202 w/o ROM

2016-06-21 Thread Yoshihiro Shimoda
Hello,

> From: Christian Lamparter
> Sent: Tuesday, June 21, 2016 12:32 AM
> 
> On Wednesday, June 08, 2016 12:14:57 AM Christian Lamparter wrote:
> > This patch adds a firmware check for the uPD720201K8-711-BAC-A
> > and uPD720202K8-711-BAA-A variant. Both of these chips are listed
> > in Renesas' R19UH0078EJ0500 Rev.5.00 "User's Manual: Hardware" as
> > devices which need a firmware in order to work as they do not have
> > support to load the firmware from an external ROM.
> >
> > Currently, the xhci-pci driver is unable to initialize the hcd in
> > this case. Instead it will wait for 30 seconds and cause a timeout
> > in xhci_handshake() and fails.
> >
> > [5.116990] xhci_hcd :45:00.0: new USB bus registered ...
> > [   32.335215] xhci_hcd :45:00.0: can't setup: -110
> > [   32.340179] xhci_hcd :45:00.0: USB bus 2 deregistered
> > [   32.345587] xhci_hcd :45:00.0: init :45:00.0 fail, -110
> > [   32.351496] xhci_hcd: probe of :45:00.0 failed with error -110
> >
> > Cc: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > Signed-off-by: Christian Lamparter <chunk...@gmail.com>
> Hello?
> 
> Are there any news on this? Or is there anything else that I'm missing
> which blocks this patch? If it's because the device won't be working
> either with this patch, then please let me know.

Thank you for the patch with CC me.
However, I'm afraid but I don't know the detail of the Renesas xHCI PCI 
controller.
(My job is for R-Car environment for now.)

By the way, the issue seems similar with R-Car environment though :)
http://thread.gmane.org/gmane.linux.kernel.stable/175457/focus=140699

and fix patch for it:
http://thread.gmane.org/gmane.linux.kernel.stable/177524

Best regards,
Yoshihiro Shimoda

> either with this patch, then please let me know. If Renesas is willing
> to add the uPD720201/2 firmware (Like they did for their R-Car controllers)
> to linux-firmware, I can write the  necessary firmware loader from
> the PDF for this device and put it into xhci-quirks.
> 
> Regards,
> Christian



RE: [PATCH v11 08/14] usb: otg: add OTG/dual-role core

2016-06-20 Thread Yoshihiro Shimoda
Hi Roger,

> From: Roger Quadros
> Sent: Monday, June 20, 2016 7:13 PM
> 
> Hi,
> 
> On 20/06/16 10:45, Felipe Balbi wrote:
< snip >
> >> diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
> >> index f4fc0aa..1d74fb8 100644
> >> --- a/include/linux/usb/gadget.h
> >> +++ b/include/linux/usb/gadget.h
> >> @@ -328,6 +328,7 @@ struct usb_gadget_ops {
> >>   * @in_epnum: last used in ep number
> >>   * @mA: last set mA value
> >>   * @otg_caps: OTG capabilities of this gadget.
> >> + * @otg_dev: OTG controller device, if needs to be used with OTG core.
> >
> > do you really know of any platform which has a separate OTG controller?
> >
> 
> Andrew had pointed out in [1] that Tegra210 has separate blocks for OTG, host
> and gadget.
> 
> [1] http://article.gmane.org/gmane.linux.ports.tegra/22969
> 
> Yoshihiro,
> 
> How is the dual-role architecture on your Renesas platform?

About the dual-role architecture, Renesas platform (R-Car H3) has a USB 2.0 
host controller (EHCI/OHCI)
with OTG function and a separate USB 2.0 peripheral controller (HS-USB).
The OTG function is related to some PHY control registers, so I intend to add 
the OTG/Dual-role core
support into the phy driver (drivers/phy/phy-rcar-gen3-usb2.c).

Best regards,
Yoshihiro Shimoda



[PATCH] phy: rcar-gen3-usb2: fix mutex_lock calling in interrupt

2016-06-27 Thread Yoshihiro Shimoda
This patch fixes an issue that the extcon_set_cable_state_() is possible
to cause "BUG: scheduling while atomic" because this driver calls
extcon_set_cable_state_() in the interrupt handler and mutex_lock()
is possible to be called by like the following call trace.
So, this patch adds a workqueue function to resolve this issue.

[9.706504] BUG: scheduling while atomic: systemd-journal/25893/0x00010303
[9.714569] Modules linked in:
[9.717629] CPU: 0 PID: 25893 Comm: systemd-journal Not tainted 4.7.0-rc4+ 
#86
[9.724844] Hardware name: Renesas Salvator-X board based on r8a7795 (DT)
[9.731624] Call trace:
[9.734077] [] dump_backtrace+0x0/0x1a8
[9.739470] [] show_stack+0x14/0x20
[9.744520] [] dump_stack+0x94/0xb8
[9.749568] [] __schedule_bug+0x44/0x58
[9.754966] [] __schedule+0x4e4/0x598
[9.760185] [] schedule+0x3c/0xa8
[9.765057] [] schedule_preempt_disabled+0x20/0x38
[9.771408] [] mutex_optimistic_spin+0x18c/0x1d0
[9.777583] [] __mutex_lock_slowpath+0x38/0x140
[9.783669] [] mutex_lock+0x44/0x60
[9.788717] [] kobject_uevent_env+0x250/0x500
[9.794634] [] extcon_update_state+0x220/0x298
[9.800634] [] extcon_set_cable_state_+0x78/0x88
[9.806812] [] rcar_gen3_device_recognition+0x5c/0xe0
[9.813420] [] rcar_gen3_phy_usb2_irq+0x3c/0x48
[9.819509] [] handle_irq_event_percpu+0x94/0x140
[9.825769] [] handle_irq_event+0x48/0x78
[9.831334] [] handle_fasteoi_irq+0xb8/0x1b0
[9.837162] [] generic_handle_irq+0x24/0x38
[9.842900] [] __handle_domain_irq+0x5c/0xb8
[9.848727] [] gic_handle_irq+0x58/0xb0

Reported-by: Simon Horman <ho...@verge.net.au>
Fixes: 2b38543c8db1 ("phy: rcar-gen3-usb2: add extcon support")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 26 ++
 1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 4be3f5d..31156c9 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -21,6 +21,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*** USB2.0 Host registers (original offset is +0x200) ***/
 #define USB2_INT_ENABLE0x000
@@ -81,9 +82,25 @@ struct rcar_gen3_chan {
struct extcon_dev *extcon;
struct phy *phy;
struct regulator *vbus;
+   struct work_struct work;
+   bool extcon_host;
bool has_otg;
 };
 
+static void rcar_gen3_phy_usb2_work(struct work_struct *work)
+{
+   struct rcar_gen3_chan *ch = container_of(work, struct rcar_gen3_chan,
+work);
+
+   if (ch->extcon_host) {
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, true);
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB, false);
+   } else {
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, false);
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
+   }
+}
+
 static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
 {
void __iomem *usb2_base = ch->base;
@@ -130,8 +147,8 @@ static void rcar_gen3_init_for_host(struct rcar_gen3_chan 
*ch)
rcar_gen3_set_host_mode(ch, 1);
rcar_gen3_enable_vbus_ctrl(ch, 1);
 
-   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, true);
-   extcon_set_cable_state_(ch->extcon, EXTCON_USB, false);
+   ch->extcon_host = true;
+   schedule_work(>work);
 }
 
 static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
@@ -140,8 +157,8 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
rcar_gen3_set_host_mode(ch, 0);
rcar_gen3_enable_vbus_ctrl(ch, 0);
 
-   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, false);
-   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
+   ch->extcon_host = false;
+   schedule_work(>work);
 }
 
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
@@ -301,6 +318,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
if (irq >= 0) {
int ret;
 
+   INIT_WORK(>work, rcar_gen3_phy_usb2_work);
irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
   IRQF_SHARED, dev_name(dev), channel);
if (irq < 0)
-- 
1.9.1



RE: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling

2016-02-02 Thread Yoshihiro Shimoda
Hi Kishon,

Would you review this patch?
I checked the latest linux-phy.git / next branch today, and it is the same as 
the following.

> >  This patch is based on the linux-phy / next branch.
> >  (commit id = 9955a7835bf376e12482583958b2661f501b868b)

Best regards,
Yoshihiro Shimoda

> From: Rob Herring [mailto:r...@kernel.org]
> Sent: Sunday, January 10, 2016 7:33 AM
> To: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> Cc: kis...@ti.com; pawel.m...@arm.com; mark.rutl...@arm.com; 
> ijc+devicet...@hellion.org.uk; ga...@codeaurora.org;
> linux-kernel@vger.kernel.org; devicet...@vger.kernel.org; 
> linux...@vger.kernel.org
> Subject: Re: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling
> 
> On Thu, Jan 07, 2016 at 06:16:44PM +0900, Yoshihiro Shimoda wrote:
> > Since the related driver (CPG/MSSR driver) only manages the first module
> > clock, this driver should not handle the HSUSB registers. So, this patch
> > removes the HSUSB registers handling.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  This patch is based on the linux-phy / next branch.
> >  (commit id = 9955a7835bf376e12482583958b2661f501b868b)
> >
> >  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 15 ++--
> 
> Acked-by: Rob Herring <r...@kernel.org>
> 
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 83 
> > +++---
> >  2 files changed, 15 insertions(+), 83 deletions(-)
> 



RE: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling

2016-02-22 Thread Yoshihiro Shimoda
Hi Kishon,

Would you review this patch?

I checked the latest linux-phy.git / next branch today,
this patch can be applied on the top of branch.

commit 6b825eb7323a634cdd1014a4aa9a8ff07cf8040c
Author: Heiko Stuebner <he...@sntech.de>
Date:   Mon Feb 22 12:55:01 2016 +0100

phy: rockchip-usb: add handler for usb-uart functionality

Best regards,
Yoshihiro Shimoda

> -Original Message-
> From: Yoshihiro Shimoda
> Sent: Tuesday, February 02, 2016 5:29 PM
> To: kis...@ti.com
> Cc: pawel.m...@arm.com; mark.rutl...@arm.com; ijc+devicet...@hellion.org.uk; 
> ga...@codeaurora.org;
> linux-kernel@vger.kernel.org; devicet...@vger.kernel.org; 
> linux...@vger.kernel.org; 'Rob Herring' <r...@kernel.org>;
> linux-renesas-...@vger.kernel.org
> Subject: RE: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling
> 
> Hi Kishon,
> 
> Would you review this patch?
> I checked the latest linux-phy.git / next branch today, and it is the same as 
> the following.
> 
> > >  This patch is based on the linux-phy / next branch.
> > >  (commit id = 9955a7835bf376e12482583958b2661f501b868b)
> 
> Best regards,
> Yoshihiro Shimoda
> 
> > From: Rob Herring [mailto:r...@kernel.org]
> > Sent: Sunday, January 10, 2016 7:33 AM
> > To: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > Cc: kis...@ti.com; pawel.m...@arm.com; mark.rutl...@arm.com; 
> > ijc+devicet...@hellion.org.uk; ga...@codeaurora.org;
> > linux-kernel@vger.kernel.org; devicet...@vger.kernel.org; 
> > linux...@vger.kernel.org
> > Subject: Re: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling
> >
> > On Thu, Jan 07, 2016 at 06:16:44PM +0900, Yoshihiro Shimoda wrote:
> > > Since the related driver (CPG/MSSR driver) only manages the first module
> > > clock, this driver should not handle the HSUSB registers. So, this patch
> > > removes the HSUSB registers handling.
> > >
> > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > > ---
> > >  This patch is based on the linux-phy / next branch.
> > >  (commit id = 9955a7835bf376e12482583958b2661f501b868b)
> > >
> > >  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 15 ++--
> >
> > Acked-by: Rob Herring <r...@kernel.org>
> >
> > >  drivers/phy/phy-rcar-gen3-usb2.c   | 83 
> > > +++---
> > >  2 files changed, 15 insertions(+), 83 deletions(-)
> >



RE: [PATCH] phy: rcar-gen3-usb2: remove HSUSB registers handling

2016-02-22 Thread Yoshihiro Shimoda
Hi,

> Hi,
> 
> On Tuesday 23 February 2016 11:54 AM, Yoshihiro Shimoda wrote:
> > Hi Kishon,
> >
> > Would you review this patch?
> 
> merged it now. Thanks for reminding.

Thank you!

Best regards,
Yoshihiro Shimoda

> -Kishon
> 



RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-08 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Thursday, April 07, 2016 8:45 PM
> 
> Hi,
> 
> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
> > Hi,
> >
> >> From: Roger Quadros
> >> Sent: Tuesday, April 05, 2016 11:05 PM
< snip >
> > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > index 41e762a..4d7f043 100644
> > --- a/drivers/usb/common/usb-otg.c
> > +++ b/drivers/usb/common/usb-otg.c
> > @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> > unsigned int irqnum,
> > if (otg->primary_hcd.hcd) {
> > /* probably a shared HCD ? */
> > if (usb_otg_hcd_is_primary_hcd(hcd)) {
> > +   if (hcd->driver->flags & HCD_USB11) {
> > +   dev_info(otg_dev, "this assumes usb 1.1 hc is 
> > as shared_hcd\n");
> > +   goto check_shared_hcd;
> > +   }
> > dev_err(otg_dev, "otg: primary host already 
> > registered\n");
> > goto err;
> > }
> >
> > if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> > +check_shared_hcd:
> > if (otg->shared_hcd.hcd) {
> > dev_err(otg_dev, "otg: shared host already 
> > registered\n");
> > goto err;
> >
> > What do you think this local hack?
> 
> Is it guaranteed that EHCI hcd registers before OHCI hcd?

Thank you for the comment. No, it is not guaranteed.

> If not we need to improve the code still.
> We will also need to remove the constraint that primary_hcd must be registered
> first in usb_otg_register_hcd(). I think that constraint is no longer
> needed anyways.

I got it.
So, I made a patch to avoid the constraint using an additional property 
"otg-hcds".
The patch is in this end of email. What do you think about the patch?

> If EHCI & OHCI HCDs register before OTG driver then things will break unless
> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
> populate wait->shared_hcd.

I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy driver
will calls usb_otg_register(), the order is right. In other words,
EHCI & OHCI HCDs never register before OTG driver because even if EHCI driver
is probed first, the driver will be deferred (EHCI driver needs the phy driver).

> > I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
> > For example of xHCI:
> >  - otg->hcds[0] = primary_hcd
> >  - otg->hcds[1] = shared_hcd
> >
> > For example of EHCI/OHCI:
> >  - otg->hcds[0] = primary_hcd of EHCI
> >  - otg->hcds[1] = primary_hcd of OHCI
> 
> The bigger problem is that how do we know in the OHCI/EHCI case that we need 
> to wait
> for both of them before starting the OTG FSM?
> Some systems might use just OHCI or just EHCI.
>
> There is no guarantee that OTG driver registers before the HCDs so this piece
> of information must come from the HCD itself. i.e. whether it needs a 
> companion or not.

I understood these problems. I wonder if my patch can resolve these problems.

Best regards,
Yoshihiro Shimoda
---
diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
b/Documentation/devicetree/bindings/usb/generic.txt
index f6866c1..518b9eb 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -27,6 +27,12 @@ Optional properties:
  - otg-controller: phandle to otg controller. Host or gadget controllers can
contain this property to link it to a particular OTG
controller.
+ - otg-hcds: phandle to host controller(s). An OTG controller can contain this
+property. The first one is as "primary", and (optional) the second
+one is as "shared".
+- For example for xHCI:otg-hcds = <>, <>;
+- For example for EHCI/OHCI:   otg-hcds = <>, <>;
+- For example for just EHCI:   otg-hcds = <>;
 
 This is an attribute to a USB controller such as:
 
diff --git a/arch/arm64/boot/dts/renesas/r8a7795.dtsi 
b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
index 741d9d2..9dcf76ac 100644
--- a/arch/arm64/boot/dts/renesas/r8a7795.dtsi
+++ b/arch/arm64/boot/dts/renesas/r8a7795.dtsi
@@ -1253,6 +1253,7 @@
compatible = "renesas,usb2-phy-r8a7795";
reg = <0 0xee080200 0 0x700>;
interrupts = ;
+   otg-hcds = <>, <>;
  

RE: [PATCH 2/3] phy: rcar-gen3-usb2: Add vbus-supply to handle VBUS on/off

2016-04-05 Thread Yoshihiro Shimoda
Hi,

> From: Kishon Vijay Abraham I
> Sent: Tuesday, April 05, 2016 7:54 PM
> 
> Hi,
> 
> On Thursday 03 March 2016 03:39 PM, Yoshihiro Shimoda wrote:
> > To handle the VBUS on/off by a regulator driver, this patch adds
> > regulator APIs calling in the driver and description about vbus-supply
> > in the rcar-gen3-phy-usb2.txt.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > Acked-by: Rob Herring <r...@kernel.org>
> > ---
> >  .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 ++
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 28 
> > ++
> >  2 files changed, 30 insertions(+)
> >
> > diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > index 86826ca..7243b3b 100644
> > --- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > +++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
> > @@ -21,6 +21,8 @@ To use a USB channel where USB 2.0 Host and HSUSB (USB 
> > 2.0 Peripheral) are
> >  combined, the device tree node should set interrupt properties to use the
> >  channel as USB OTG:
> >  - interrupts: interrupt specifier for the PHY.
> > +- vbus-supply: Phandle to a regulator that provides power to the VBUS. This
> > +  regulator will be managed during the PHY power on/off sequence.
> 
> Why not use phy-supply from the generic PHY binding? It can then be managed by
> the phy core during power_on/power_off.

Thank you for the review!

I'm afraid, I should have added your address as CC when I sent RFC patch set.
Anyway, Rob had a comment about "phy-supply":
http://thread.gmane.org/gmane.linux.kernel.renesas-soc/366/focus=406

I agreed with Rob because the document mentioned the followings:

Optional Properties:
phy-supply: Phandle to a regulator that provides power to the PHY. This
regulator will be managed during the PHY power on/off sequence.

https://git.kernel.org/cgit/linux/kernel/git/kishon/linux-phy.git/tree/Documentation/devicetree/bindings/phy/phy-bindings.txt?h=next#n13

And then, I changed the "phy-supply" to "vbus-supply" and this driver managed 
the "vbus-supply".
Or, do I misunderstand the document?

Best regards,
Yoshihiro Shimoda

> Thanks
> Kishon
> 
> >
> >  Example (R-Car H3):
> >
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index 3c647cd..7b14244 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -19,6 +19,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  /*** USB2.0 Host registers (original offset is +0x200) ***/
> >  #define USB2_INT_ENABLE0x000
> > @@ -77,6 +78,7 @@
> >  struct rcar_gen3_chan {
> > void __iomem *base;
> > struct phy *phy;
> > +   struct regulator *vbus;
> > bool has_otg;
> >  };
> >
> > @@ -210,6 +212,13 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
> > struct rcar_gen3_chan *channel = phy_get_drvdata(p);
> > void __iomem *usb2_base = channel->base;
> > u32 val;
> > +   int ret;
> > +
> > +   if (channel->vbus) {
> > +   ret = regulator_enable(channel->vbus);
> > +   if (ret)
> > +   return ret;
> > +   }
> >
> > val = readl(usb2_base + USB2_USBCTR);
> > val |= USB2_USBCTR_PLL_RST;
> > @@ -220,10 +229,22 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
> > return 0;
> >  }
> >
> > +static int rcar_gen3_phy_usb2_power_off(struct phy *p)
> > +{
> > +   struct rcar_gen3_chan *channel = phy_get_drvdata(p);
> > +   int ret = 0;
> > +
> > +   if (channel->vbus)
> > +   ret = regulator_disable(channel->vbus);
> > +
> > +   return ret;
> > +}
> > +
> >  static struct phy_ops rcar_gen3_phy_usb2_ops = {
> > .init   = rcar_gen3_phy_usb2_init,
> > .exit   = rcar_gen3_phy_usb2_exit,
> > .power_on   = rcar_gen3_phy_usb2_power_on,
> > +   .power_off  = rcar_gen3_phy_usb2_power_off,
> > .owner  = THIS_MODULE,
> >  };
> >
> > @@ -290,6 +311,13 @@ static int rcar_gen3_phy_usb2_probe(struct 
> > platform_device *pdev)
> > return PTR_ERR(channel->phy);
> > }
> >
> > +   channel->vbus = devm_regulator_get_optional(dev, "vbus");
> > +   if (IS_ERR(channel->vbus)) {
> > +   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
> > +   return PTR_ERR(channel->vbus);
> > +   channel->vbus = NULL;
> > +   }
> > +
> > phy_set_drvdata(channel->phy, channel);
> >
> > provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> >


RE: [PATCH v6 12/12] usb: host: xhci-plat: Add otg device to platform data

2016-04-05 Thread Yoshihiro Shimoda
Hi,

> Sent: Tuesday, April 05, 2016 11:05 PM
> 
> Host controllers that are part of an OTG/dual-role instance
> need to somehow pass the OTG controller device information
> to the HCD core.
> 
> We use platform data to pass the OTG controller device.
> 
> Signed-off-by: Roger Quadros <rog...@ti.com>
> ---
>  drivers/usb/host/xhci-plat.c | 35 ---
>  include/linux/usb/xhci_pdriver.h |  3 +++
>  2 files changed, 31 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
> index 5c15e9b..3d0f597 100644
> --- a/drivers/usb/host/xhci-plat.c
> +++ b/drivers/usb/host/xhci-plat.c
> @@ -230,11 +230,20 @@ static int xhci_plat_probe(struct platform_device *pdev)
>   goto put_usb3_hcd;
>   }
> 
> - ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
> + if (pdata->otg_dev)

I think that this should be changed like below:
if (pdata && pdata->otg_dev)

Otherwise, panic happened on my environment (arm64 / r8a7795 board) because the 
pdata was NULL.

> + ret = usb_otg_add_hcd(hcd, irq, IRQF_SHARED, pdata->otg_dev);
> + else
> + ret = usb_add_hcd(hcd, irq, IRQF_SHARED);
> +
>   if (ret)
>   goto disable_usb_phy;
> 
> - ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> + if (pdata->otg_dev)

Ditto.

> + ret = usb_otg_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED,
> +   pdata->otg_dev);
> + else
> + ret = usb_add_hcd(xhci->shared_hcd, irq, IRQF_SHARED);
> +
>   if (ret)
>   goto dealloc_usb2_hcd;
> 
> @@ -242,7 +251,10 @@ static int xhci_plat_probe(struct platform_device *pdev)
> 
> 
>  dealloc_usb2_hcd:
> - usb_remove_hcd(hcd);
> + if (pdata->otg_dev)

Ditto.

> + usb_otg_remove_hcd(hcd);
> + else
> + usb_remove_hcd(hcd);
> 
>  disable_usb_phy:
>   usb_phy_shutdown(hcd->usb_phy);
> @@ -260,16 +272,25 @@ put_hcd:
>   return ret;
>  }
> 
> -static int xhci_plat_remove(struct platform_device *dev)
> +static int xhci_plat_remove(struct platform_device *pdev)
>  {
> - struct usb_hcd  *hcd = platform_get_drvdata(dev);
> + struct usb_hcd  *hcd = platform_get_drvdata(pdev);
>   struct xhci_hcd *xhci = hcd_to_xhci(hcd);
>   struct clk *clk = xhci->clk;
> + struct usb_xhci_pdata *pdata = dev_get_platdata(>dev);
> +
> + if (pdata->otg_dev)

Ditto.

> + usb_otg_remove_hcd(xhci->shared_hcd);
> + else
> + usb_remove_hcd(xhci->shared_hcd);
> 
> - usb_remove_hcd(xhci->shared_hcd);
>   usb_phy_shutdown(hcd->usb_phy);
> 
> - usb_remove_hcd(hcd);
> + if (pdata->otg_dev)

Ditto.

Best regards,
Yoshihiro Shimoda

> + usb_otg_remove_hcd(hcd);
> + else
> + usb_remove_hcd(hcd);
> +
>   usb_put_hcd(xhci->shared_hcd);
> 
>   if (!IS_ERR(clk))
> diff --git a/include/linux/usb/xhci_pdriver.h 
> b/include/linux/usb/xhci_pdriver.h
> index 376654b..5c68b83 100644
> --- a/include/linux/usb/xhci_pdriver.h
> +++ b/include/linux/usb/xhci_pdriver.h
> @@ -18,10 +18,13 @@
>   *
>   * @usb3_lpm_capable:determines if this xhci platform supports USB3
>   *   LPM capability
> + * @otg_dev: OTG controller device. Only requied if part of
> + *   OTG/dual-role.
>   *
>   */
>  struct usb_xhci_pdata {
>   unsignedusb3_lpm_capable:1;
> + struct device   *otg_dev;
>  };
> 
>  #endif /* __USB_CORE_XHCI_PDRIVER_H */
> --
> 2.5.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-07 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Tuesday, April 05, 2016 11:05 PM
> 
> It provides APIs for the following tasks
> 
> - Registering an OTG/dual-role capable controller
> - Registering Host and Gadget controllers to OTG core
> - Providing inputs to and kicking the OTG state machine
> 
> Provide a dual-role device (DRD) state machine.
> DRD mode is a reduced functionality OTG mode. In this mode
> we don't support SRP, HNP and dynamic role-swap.
> 
> In DRD operation, the controller mode (Host or Peripheral)
> is decided based on the ID pin status. Once a cable plug (Type-A
> or Type-B) is attached the controller selects the state
> and doesn't change till the cable in unplugged and a different
> cable type is inserted.
> 
> As we don't need most of the complex OTG states and OTG timers
> we implement a lean DRD state machine in usb-otg.c.
> The DRD state machine is only interested in 2 hardware inputs
> 'id' and 'b_sess_vld'.
> 
> Signed-off-by: Roger Quadros <rog...@ti.com>
> ---

I tried to implement this framework on my environment,
and it seemed work if I added a local hack to this patch :)

< snip >
> + /* HCD will be started by OTG fsm when needed */
> + mutex_lock(>fsm.lock);
> + if (otg->primary_hcd.hcd) {
> + /* probably a shared HCD ? */
> + if (usb_otg_hcd_is_primary_hcd(hcd)) {
> + dev_err(otg_dev, "otg: primary host already 
> registered\n");

My environment is arm64 / r8a7795, renesas_usbhs (as a gadget), EHCI and OHCI.
In this case, OHCI driver is also a primary_hcd. So, this error happened.
To avoid this, I assumes that the OHCI hcd is as shared_hcd like a patch below:

diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..4d7f043 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned 
int irqnum,
if (otg->primary_hcd.hcd) {
/* probably a shared HCD ? */
if (usb_otg_hcd_is_primary_hcd(hcd)) {
+   if (hcd->driver->flags & HCD_USB11) {
+   dev_info(otg_dev, "this assumes usb 1.1 hc is 
as shared_hcd\n");
+   goto check_shared_hcd;
+   }
dev_err(otg_dev, "otg: primary host already 
registered\n");
goto err;
}
 
if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+check_shared_hcd:
if (otg->shared_hcd.hcd) {
dev_err(otg_dev, "otg: shared host already 
registered\n");
goto err;

What do you think this local hack?
I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
For example of xHCI:
 - otg->hcds[0] = primary_hcd
 - otg->hcds[1] = shared_hcd

For example of EHCI/OHCI:
 - otg->hcds[0] = primary_hcd of EHCI
 - otg->hcds[1] = primary_hcd of OHCI

Best regards,
Yoshihiro Shimoda



[PATCH 0/3] phy: rcar-gen3-usb2: add vbus-supply and extcon

2016-03-03 Thread Yoshihiro Shimoda
This patch set is based on the latest linux-phy / next branch
(commit id = 89636adde4a05953e3bf18807ba1f6f205572f67)
and the following patches:

http://thread.gmane.org/gmane.linux.kernel/2166364
http://thread.gmane.org/gmane.linux.kernel.renesas-soc/1512/focus=1514

The patch "Add vbus-supply to handle VBUS on/off" has
Rob's Acked-by as the followings:
http://thread.gmane.org/gmane.linux.kernel.renesas-soc/1087/focus=1153

Yoshihiro Shimoda (3):
  phy: rcar-gen3-usb2: remove unnecesary struct rcar_gen3_data
  phy: rcar-gen3-usb2: Add vbus-supply to handle VBUS on/off
  phy: rcar-gen3-usb2: add extcon support

 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 +
 drivers/phy/Kconfig|  1 +
 drivers/phy/phy-rcar-gen3-usb2.c   | 87 +-
 3 files changed, 71 insertions(+), 19 deletions(-)

-- 
1.9.1



RE: [PATCH] phy: rcar-gen3-usb2, rcar-gen2: Use ARCH_RENESAS

2016-03-03 Thread Yoshihiro Shimoda
Hi Simon-san,

> Sent: Wednesday, March 02, 2016 6:37 PM
> 
> On Wed, Mar 2, 2016 at 3:25 AM, Simon Horman <horms+rene...@verge.net.au> 
> wrote:
> > Make use of ARCH_RENESAS in place of ARCH_SHMOBILE.
> >
> > This is part of an ongoing process to migrate from ARCH_SHMOBILE to
> > ARCH_RENESAS the motivation for which being that RENESAS seems to be a more
> > appropriate name than SHMOBILE for the majority of Renesas ARM based SoCs.
> >
> > Signed-off-by: Simon Horman <horms+rene...@verge.net.au>
> 
> Acked-by: Geert Uytterhoeven <geert+rene...@glider.be>

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>

Best regards,
Yoshihiro Shimoda



RE: [PATCH v2 2/2] phy: rcar-gen3-usb2: add fallback binding

2016-03-03 Thread Yoshihiro Shimoda
Hi Simon-san,

> Sent: Thursday, March 03, 2016 5:13 PM
> 
> On Thu, Mar 3, 2016 at 1:38 AM, Simon Horman <horms+rene...@verge.net.au> 
> wrote:
> > In the case of Renesas R-Car hardware we know that there are generations of
> > SoCs, e.g. Gen 2 and Gen 3. But beyond that its not clear what the
> > relationship between IP blocks might be. For example, I believe that
> > r8a7790 is older than r8a7791 but that doesn't imply that the latter is a
> > descendant of the former or vice versa.
> >
> > We can, however, by examining the documentation and behaviour of the
> > hardware at run-time observe that the current driver implementation appears
> > to be compatible with the IP blocks on SoCs within a given generation.
> >
> > For the above reasons and convenience when enabling new SoCs a
> > per-generation fallback compatibility string scheme being adopted for
> > drivers for Renesas SoCs.
> >
> > Signed-off-by: Simon Horman <horms+rene...@verge.net.au>
> 
> Acked-by: Geert Uytterhoeven <geert+rene...@glider.be>

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>

Best regards,
Yoshihiro Shimoda



[PATCH 3/3] phy: rcar-gen3-usb2: add extcon support

2016-03-03 Thread Yoshihiro Shimoda
This patch adds extcon support for otg related channel.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/Kconfig  |  1 +
 drivers/phy/phy-rcar-gen3-usb2.c | 26 ++
 2 files changed, 27 insertions(+)

diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index ba68f14..db57d6c 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -121,6 +121,7 @@ config PHY_RCAR_GEN2
 config PHY_RCAR_GEN3_USB2
tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
depends on OF && ARCH_RENESAS
+   depends on EXTCON
select GENERIC_PHY
help
  Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 7b14244..76bb88f 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -12,6 +12,7 @@
  * published by the Free Software Foundation.
  */
 
+#include 
 #include 
 #include 
 #include 
@@ -77,6 +78,7 @@
 
 struct rcar_gen3_chan {
void __iomem *base;
+   struct extcon_dev *extcon;
struct phy *phy;
struct regulator *vbus;
bool has_otg;
@@ -127,6 +129,9 @@ static void rcar_gen3_init_for_host(struct rcar_gen3_chan 
*ch)
rcar_gen3_set_linectrl(ch, 1, 1);
rcar_gen3_set_host_mode(ch, 1);
rcar_gen3_enable_vbus_ctrl(ch, 1);
+
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, true);
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB, false);
 }
 
 static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
@@ -134,6 +139,9 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
rcar_gen3_set_linectrl(ch, 0, 1);
rcar_gen3_set_host_mode(ch, 0);
rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, false);
+   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
 }
 
 static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
@@ -272,6 +280,12 @@ static const struct of_device_id 
rcar_gen3_phy_usb2_match_table[] = {
 };
 MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
 
+static const unsigned int rcar_gen3_phy_cable[] = {
+   EXTCON_USB,
+   EXTCON_USB_HOST,
+   EXTCON_NONE,
+};
+
 static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
@@ -297,11 +311,23 @@ static int rcar_gen3_phy_usb2_probe(struct 
platform_device *pdev)
/* call request_irq for OTG */
irq = platform_get_irq(pdev, 0);
if (irq >= 0) {
+   int ret;
+
irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
   IRQF_SHARED, dev_name(dev), channel);
if (irq < 0)
dev_err(dev, "No irq handler (%d)\n", irq);
channel->has_otg = true;
+   channel->extcon = devm_extcon_dev_allocate(dev,
+   rcar_gen3_phy_cable);
+   if (IS_ERR(channel->extcon))
+   return PTR_ERR(channel->extcon);
+
+   ret = devm_extcon_dev_register(dev, channel->extcon);
+   if (ret < 0) {
+   dev_err(dev, "Failed to register extcon\n");
+   return ret;
+   }
}
 
/* devm_phy_create() will call pm_runtime_enable(dev); */
-- 
1.9.1



[PATCH 2/3] phy: rcar-gen3-usb2: Add vbus-supply to handle VBUS on/off

2016-03-03 Thread Yoshihiro Shimoda
To handle the VBUS on/off by a regulator driver, this patch adds
regulator APIs calling in the driver and description about vbus-supply
in the rcar-gen3-phy-usb2.txt.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
Acked-by: Rob Herring <r...@kernel.org>
---
 .../devicetree/bindings/phy/rcar-gen3-phy-usb2.txt |  2 ++
 drivers/phy/phy-rcar-gen3-usb2.c   | 28 ++
 2 files changed, 30 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index 86826ca..7243b3b 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -21,6 +21,8 @@ To use a USB channel where USB 2.0 Host and HSUSB (USB 2.0 
Peripheral) are
 combined, the device tree node should set interrupt properties to use the
 channel as USB OTG:
 - interrupts: interrupt specifier for the PHY.
+- vbus-supply: Phandle to a regulator that provides power to the VBUS. This
+  regulator will be managed during the PHY power on/off sequence.
 
 Example (R-Car H3):
 
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3c647cd..7b14244 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -19,6 +19,7 @@
 #include 
 #include 
 #include 
+#include 
 
 /*** USB2.0 Host registers (original offset is +0x200) ***/
 #define USB2_INT_ENABLE0x000
@@ -77,6 +78,7 @@
 struct rcar_gen3_chan {
void __iomem *base;
struct phy *phy;
+   struct regulator *vbus;
bool has_otg;
 };
 
@@ -210,6 +212,13 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
struct rcar_gen3_chan *channel = phy_get_drvdata(p);
void __iomem *usb2_base = channel->base;
u32 val;
+   int ret;
+
+   if (channel->vbus) {
+   ret = regulator_enable(channel->vbus);
+   if (ret)
+   return ret;
+   }
 
val = readl(usb2_base + USB2_USBCTR);
val |= USB2_USBCTR_PLL_RST;
@@ -220,10 +229,22 @@ static int rcar_gen3_phy_usb2_power_on(struct phy *p)
return 0;
 }
 
+static int rcar_gen3_phy_usb2_power_off(struct phy *p)
+{
+   struct rcar_gen3_chan *channel = phy_get_drvdata(p);
+   int ret = 0;
+
+   if (channel->vbus)
+   ret = regulator_disable(channel->vbus);
+
+   return ret;
+}
+
 static struct phy_ops rcar_gen3_phy_usb2_ops = {
.init   = rcar_gen3_phy_usb2_init,
.exit   = rcar_gen3_phy_usb2_exit,
.power_on   = rcar_gen3_phy_usb2_power_on,
+   .power_off  = rcar_gen3_phy_usb2_power_off,
.owner  = THIS_MODULE,
 };
 
@@ -290,6 +311,13 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
return PTR_ERR(channel->phy);
}
 
+   channel->vbus = devm_regulator_get_optional(dev, "vbus");
+   if (IS_ERR(channel->vbus)) {
+   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
+   return PTR_ERR(channel->vbus);
+   channel->vbus = NULL;
+   }
+
phy_set_drvdata(channel->phy, channel);
 
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
-- 
1.9.1



[PATCH 1/3] phy: rcar-gen3-usb2: remove unnecesary struct rcar_gen3_data

2016-03-03 Thread Yoshihiro Shimoda
Since this driver uses the struct rcar_gen3_data in struct rcar_gen3_chan
only, we can remove the rcar_gen3_data.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 33 ++---
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 257be74..3c647cd 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -74,20 +74,15 @@
 #define USB2_ADPCTRL_IDPULLUP  BIT(5)  /* 1 = ID sampling is enabled */
 #define USB2_ADPCTRL_DRVVBUS   BIT(4)
 
-struct rcar_gen3_data {
-   void __iomem *base;
-   struct clk *clk;
-};
-
 struct rcar_gen3_chan {
-   struct rcar_gen3_data usb2;
+   void __iomem *base;
struct phy *phy;
bool has_otg;
 };
 
 static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
 {
-   void __iomem *usb2_base = ch->usb2.base;
+   void __iomem *usb2_base = ch->base;
u32 val = readl(usb2_base + USB2_COMMCTRL);
 
dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, host);
@@ -100,7 +95,7 @@ static void rcar_gen3_set_host_mode(struct rcar_gen3_chan 
*ch, int host)
 
 static void rcar_gen3_set_linectrl(struct rcar_gen3_chan *ch, int dp, int dm)
 {
-   void __iomem *usb2_base = ch->usb2.base;
+   void __iomem *usb2_base = ch->base;
u32 val = readl(usb2_base + USB2_LINECTRL1);
 
dev_vdbg(>phy->dev, "%s: %08x, %d, %d\n", __func__, val, dp, dm);
@@ -114,7 +109,7 @@ static void rcar_gen3_set_linectrl(struct rcar_gen3_chan 
*ch, int dp, int dm)
 
 static void rcar_gen3_enable_vbus_ctrl(struct rcar_gen3_chan *ch, int vbus)
 {
-   void __iomem *usb2_base = ch->usb2.base;
+   void __iomem *usb2_base = ch->base;
u32 val = readl(usb2_base + USB2_ADPCTRL);
 
dev_vdbg(>phy->dev, "%s: %08x, %d\n", __func__, val, vbus);
@@ -141,13 +136,13 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
 
 static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
 {
-   return !!(readl(ch->usb2.base + USB2_ADPCTRL) &
+   return !!(readl(ch->base + USB2_ADPCTRL) &
  USB2_ADPCTRL_OTGSESSVLD);
 }
 
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
-   return !!(readl(ch->usb2.base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
+   return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
 }
 
 static void rcar_gen3_device_recognition(struct rcar_gen3_chan *ch)
@@ -166,7 +161,7 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
 
 static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 {
-   void __iomem *usb2_base = ch->usb2.base;
+   void __iomem *usb2_base = ch->base;
u32 val;
 
val = readl(usb2_base + USB2_VBCTRL);
@@ -187,7 +182,7 @@ static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
 static int rcar_gen3_phy_usb2_init(struct phy *p)
 {
struct rcar_gen3_chan *channel = phy_get_drvdata(p);
-   void __iomem *usb2_base = channel->usb2.base;
+   void __iomem *usb2_base = channel->base;
 
/* Initialize USB2 part */
writel(USB2_INT_ENABLE_INIT, usb2_base + USB2_INT_ENABLE);
@@ -205,7 +200,7 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)
 {
struct rcar_gen3_chan *channel = phy_get_drvdata(p);
 
-   writel(0, channel->usb2.base + USB2_INT_ENABLE);
+   writel(0, channel->base + USB2_INT_ENABLE);
 
return 0;
 }
@@ -213,7 +208,7 @@ static int rcar_gen3_phy_usb2_exit(struct phy *p)
 static int rcar_gen3_phy_usb2_power_on(struct phy *p)
 {
struct rcar_gen3_chan *channel = phy_get_drvdata(p);
-   void __iomem *usb2_base = channel->usb2.base;
+   void __iomem *usb2_base = channel->base;
u32 val;
 
val = readl(usb2_base + USB2_USBCTR);
@@ -235,7 +230,7 @@ static struct phy_ops rcar_gen3_phy_usb2_ops = {
 static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void *_ch)
 {
struct rcar_gen3_chan *ch = _ch;
-   void __iomem *usb2_base = ch->usb2.base;
+   void __iomem *usb2_base = ch->base;
u32 status = readl(usb2_base + USB2_OBINTSTA);
irqreturn_t ret = IRQ_NONE;
 
@@ -274,9 +269,9 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
return -ENOMEM;
 
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-   channel->usb2.base = devm_ioremap_resource(dev, res);
-   if (IS_ERR(channel->usb2.base))
-   return PTR_ERR(channel->usb2.base);
+   channel->base = devm_ioremap_resource(dev, res);
+   if (IS_ERR(channel->base))
+   return PTR_ERR(channel->base);
 
/* call request_irq for OTG */
irq = platform_get_irq(pdev, 0);
-- 
1.9.1



RE: [PATCH] usb: gadget: udc-core: remove manual dma configuration

2016-04-05 Thread Yoshihiro Shimoda
Hi,

> From: Grygorii Strashko [mailto:grygorii.stras...@ti.com]
> Sent: Monday, April 04, 2016 8:32 PM
> 
> Since commit 7ace8fc8219e ("usb: gadget: udc: core: Fix argument of
> dma_map_single for IOMMU") it is not necessary to configure DMA for
> usb_gadget device manually, because all DMA operation are performed
> using parent/controller device.
> 
> Cc: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> Signed-off-by: Grygorii Strashko <grygorii.stras...@ti.com>

My environment could work correctly after I applied this patch.
So,

Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>


I realized that the commit 7ace8fc8219e is not suitable for my environment.
(Especially I realized it could use all of DMAC channels when IOMMU was 
enabled.)
So, I will submit RFC patch set for udc-core.c / renesas_usbhs later :)

Best regards,
Yoshihiro Shimoda



RE: [PATCH 3/3] phy: rcar-gen3-usb2: add extcon support

2016-04-05 Thread Yoshihiro Shimoda
Hi Kishon,

Would you review this patch set?
As I said on the cover letter, this patch set is based on some patches.
http://thread.gmane.org/gmane.linux.drivers.devicetree/158563


Hi Chanwoo,

Thank you very much for the review about extcon usage!

Best regards,
Yoshihiro Shimoda

> From: Chanwoo Choi [mailto:cw00.c...@samsung.com]
> Sent: Monday, March 14, 2016 12:36 PM
> 
> Hi Yoshihiro,
> 
> On 2016년 03월 03일 19:09, Yoshihiro Shimoda wrote:
> > This patch adds extcon support for otg related channel.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  drivers/phy/Kconfig  |  1 +
> >  drivers/phy/phy-rcar-gen3-usb2.c | 26 ++
> >  2 files changed, 27 insertions(+)
> >
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index ba68f14..db57d6c 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -121,6 +121,7 @@ config PHY_RCAR_GEN2
> >  config PHY_RCAR_GEN3_USB2
> > tristate "Renesas R-Car generation 3 USB 2.0 PHY driver"
> > depends on OF && ARCH_RENESAS
> > +   depends on EXTCON
> > select GENERIC_PHY
> > help
> >   Support for USB 2.0 PHY found on Renesas R-Car generation 3 SoCs.
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index 7b14244..76bb88f 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -12,6 +12,7 @@
> >   * published by the Free Software Foundation.
> >   */
> >
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -77,6 +78,7 @@
> >
> >  struct rcar_gen3_chan {
> > void __iomem *base;
> > +   struct extcon_dev *extcon;
> > struct phy *phy;
> > struct regulator *vbus;
> > bool has_otg;
> > @@ -127,6 +129,9 @@ static void rcar_gen3_init_for_host(struct 
> > rcar_gen3_chan *ch)
> > rcar_gen3_set_linectrl(ch, 1, 1);
> > rcar_gen3_set_host_mode(ch, 1);
> > rcar_gen3_enable_vbus_ctrl(ch, 1);
> > +
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, true);
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB, false);
> >  }
> >
> >  static void rcar_gen3_init_for_peri(struct rcar_gen3_chan *ch)
> > @@ -134,6 +139,9 @@ static void rcar_gen3_init_for_peri(struct 
> > rcar_gen3_chan *ch)
> > rcar_gen3_set_linectrl(ch, 0, 1);
> > rcar_gen3_set_host_mode(ch, 0);
> > rcar_gen3_enable_vbus_ctrl(ch, 0);
> > +
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, false);
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
> >  }
> >
> >  static bool rcar_gen3_check_vbus(struct rcar_gen3_chan *ch)
> > @@ -272,6 +280,12 @@ static const struct of_device_id 
> > rcar_gen3_phy_usb2_match_table[] = {
> >  };
> >  MODULE_DEVICE_TABLE(of, rcar_gen3_phy_usb2_match_table);
> >
> > +static const unsigned int rcar_gen3_phy_cable[] = {
> > +   EXTCON_USB,
> > +   EXTCON_USB_HOST,
> > +   EXTCON_NONE,
> > +};
> > +
> >  static int rcar_gen3_phy_usb2_probe(struct platform_device *pdev)
> >  {
> > struct device *dev = >dev;
> > @@ -297,11 +311,23 @@ static int rcar_gen3_phy_usb2_probe(struct 
> > platform_device *pdev)
> > /* call request_irq for OTG */
> > irq = platform_get_irq(pdev, 0);
> > if (irq >= 0) {
> > +   int ret;
> > +
> > irq = devm_request_irq(dev, irq, rcar_gen3_phy_usb2_irq,
> >IRQF_SHARED, dev_name(dev), channel);
> > if (irq < 0)
> > dev_err(dev, "No irq handler (%d)\n", irq);
> > channel->has_otg = true;
> > +   channel->extcon = devm_extcon_dev_allocate(dev,
> > +   rcar_gen3_phy_cable);
> > +   if (IS_ERR(channel->extcon))
> > +   return PTR_ERR(channel->extcon);
> > +
> > +   ret = devm_extcon_dev_register(dev, channel->extcon);
> > +   if (ret < 0) {
> > +   dev_err(dev, "Failed to register extcon\n");
> > +   return ret;
> > +   }
> > }
> >
> > /* devm_phy_create() will call pm_runtime_enable(dev); */
> >
> 
> Looks good to me about extcon usgae.
> 
> Reviewed-by: Chanwoo Choi <cw00.c...@samsung.com>
> 
> Best Regards,
> Chanwoo Choi



RE: [PATCH] usb: host: xhci-plat: Make enum xhci_plat_type start at a non zero value

2016-03-28 Thread Yoshihiro Shimoda
Hi,

> Sent: Monday, March 28, 2016 5:30 PM
> 
> Hi,
> 
> Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com> writes:
> >> > ps: there might be bugs there, but it's a holiday and I really shouldn't
> >> > be spending time on this right now ;-)
> >>
> >> I'm also off on holiday now until Sunday 10th April... yay :-)
> >> >
> >> > Anyway, have fun testing. Let me know if it doesn't work.
> >>
> >> I only have access to STi platforms which were broken by this change.
> >> Not any of the platforms which rely on the functionality which
> >> was introduced (although I can't see any reason why your patch wouldn't 
> >> work).
> >>
> >> Maybe Yoshihiro (on CC) could test this on the Renesas platforms and 
> >> confirm?
> >
> > Thank you for sending the email to me on CC.
> >
> > I tested Felipe's patch on Renesas platfroms (R-Car Gen2 and Gen3) and
> > I fixed the patch like the following.
> >
> > However, my fixes patch might need to clean the code up more.
> >
> > Changes from Felipe's patch:
> > - Change function names of xhci_rcar_init_quirk() to xhci_rcar_setup_quirk()
> 
> I'm not sure renaming that function fits on the same patch ;-) Sounds
> like it should be a separate patch altogether. I'll work on this
> tomorrow if it's okay for you guys to test on your respective platforms :-)

Thank you for the comment!
I also think it should be separate patch ;)
Also I'm okay to test your patch(es) on my platforms :)

Best regards,
Yoshihiro Shimoda

> --
> balbi


RE: [PATCH] usb: host: xhci-plat: Make enum xhci_plat_type start at a non zero value

2016-03-28 Thread Yoshihiro Shimoda
Hi,

> Sent: Saturday, March 26, 2016 6:11 PM
< snip >
> > ps: there might be bugs there, but it's a holiday and I really shouldn't
> > be spending time on this right now ;-)
> 
> I'm also off on holiday now until Sunday 10th April... yay :-)
> >
> > Anyway, have fun testing. Let me know if it doesn't work.
> 
> I only have access to STi platforms which were broken by this change.
> Not any of the platforms which rely on the functionality which
> was introduced (although I can't see any reason why your patch wouldn't work).
> 
> Maybe Yoshihiro (on CC) could test this on the Renesas platforms and confirm?

Thank you for sending the email to me on CC.
I tested Felipe's patch on Renesas platfroms (R-Car Gen2 and Gen3) and I fixed 
the patch like the following.
However, my fixes patch might need to clean the code up more.

Changes from Felipe's patch:
- Change function names of xhci_rcar_init_quirk() to xhci_rcar_setup_quirk()
- Add setup_quirk() member and use it for rcar's function.
- Some minor fixes.

---
diff --git a/drivers/usb/host/xhci-mvebu.c b/drivers/usb/host/xhci-mvebu.c
index 1eefc98..1ea6c18 100644
--- a/drivers/usb/host/xhci-mvebu.c
+++ b/drivers/usb/host/xhci-mvebu.c
@@ -41,8 +41,9 @@ static void xhci_mvebu_mbus_config(void __iomem *base,
}
 }
 
-int xhci_mvebu_mbus_init_quirk(struct platform_device *pdev)
+int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd)
 {
+   struct platform_device *pdev = to_platform_device(hcd->self.controller);
struct resource *res;
void __iomem *base;
const struct mbus_dram_target_info *dram;
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c
index d39d6bf..d28513a 100644
--- a/drivers/usb/host/xhci-plat.c
+++ b/drivers/usb/host/xhci-plat.c
@@ -47,43 +47,57 @@ static void xhci_plat_quirks(struct device *dev, struct 
xhci_hcd *xhci)
xhci->quirks |= XHCI_PLAT;
 }
 
+static void xhci_priv_plat_start(struct usb_hcd *hcd)
+{
+   struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
+
+   if (priv->plat_start)
+   priv->plat_start(hcd);
+}
+
+static int xhci_priv_setup_quirk(struct usb_hcd *hcd)
+{
+   struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
+
+   if (!priv->setup_quirk)
+   return 0;
+
+   return priv->setup_quirk(hcd);
+}
+
 /* called during probe() after chip reset completes */
 static int xhci_plat_setup(struct usb_hcd *hcd)
 {
int ret;
 
-   if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2) ||
-   xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3)) {
-   ret = xhci_rcar_init_quirk(hcd);
-   if (ret)
-   return ret;
-   }
+   ret = xhci_priv_setup_quirk(hcd);
+   if (ret)
+   return ret;
 
return xhci_gen_setup(hcd, xhci_plat_quirks);
 }
 
 static int xhci_plat_start(struct usb_hcd *hcd)
 {
-   if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2) ||
-   xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3))
-   xhci_rcar_start(hcd);
-
+   xhci_priv_plat_start(hcd);
return xhci_run(hcd);
 }
 
 #ifdef CONFIG_OF
 static const struct xhci_plat_priv xhci_plat_marvell_armada = {
-   .type = XHCI_PLAT_TYPE_MARVELL_ARMADA,
+   .init_quirk = xhci_mvebu_mbus_init_quirk,
 };
 
 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen2 = {
-   .type = XHCI_PLAT_TYPE_RENESAS_RCAR_GEN2,
.firmware_name = XHCI_RCAR_FIRMWARE_NAME_V1,
+   .setup_quirk = xhci_rcar_setup_quirk,
+   .plat_start = xhci_rcar_start,
 };
 
 static const struct xhci_plat_priv xhci_plat_renesas_rcar_gen3 = {
-   .type = XHCI_PLAT_TYPE_RENESAS_RCAR_GEN3,
.firmware_name = XHCI_RCAR_FIRMWARE_NAME_V2,
+   .setup_quirk = xhci_rcar_setup_quirk,
+   .plat_start = xhci_rcar_start,
 };
 
 static const struct of_device_id usb_xhci_of_match[] = {
@@ -119,6 +133,7 @@ static int xhci_plat_probe(struct platform_device *pdev)
 {
struct device_node  *node = pdev->dev.of_node;
struct usb_xhci_pdata   *pdata = dev_get_platdata(>dev);
+   struct xhci_plat_priv   *priv;
const struct of_device_id *match;
const struct hc_driver  *driver;
struct xhci_hcd *xhci;
@@ -178,18 +193,18 @@ static int xhci_plat_probe(struct platform_device *pdev)
}
 
xhci = hcd_to_xhci(hcd);
+   priv = hcd_to_xhci_priv(hcd);
match = of_match_node(usb_xhci_of_match, node);
if (match) {
const struct xhci_plat_priv *priv_match = match->data;
-   struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd);
 
/* Just copy data for now */
if (priv_match)
*priv = *priv_match;
}
 
-   if (xhci_plat_type_is(hcd, XHCI_PLAT_TYPE_MARVELL_ARMADA)) {
-   ret = xhci_mvebu_mbus_init_quirk(pdev);
+   if (priv->init_quirk) {
+   ret = 

RE: [PATCH] usb: renesas_usbhs: fix signed-unsigned return

2016-04-14 Thread Yoshihiro Shimoda
Hi,

> From: Sudip Mukherjee
> Sent: Saturday, April 09, 2016 12:05 AM
> 
> The return type of usbhsp_setup_pipecfg() was u16 but it was returning
> a negative value (-EINVAL). Instead lets return a pointer to u16 which
> will hold the value to be returned or in case of error, return the
> error code in ERR_PTR.

Thank you for the patch!
I also think this usbhsp_setup_pipecfg() should return error code using correct 
variable type.

However, I would like to avoid to use ERR_PTR and kmalloc() somehow because
I feel this patch is complex a little.
How about the usbhsp_setup_pipecfg() prototype is changed like the following?

static int usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
int is_host, int dir_in, u16 *pipecfg);

Best regards,
Yoshihiro Shimoda

> Signed-off-by: Sudip Mukherjee <sudip.mukher...@codethink.co.uk>
> ---
>  drivers/usb/renesas_usbhs/pipe.c | 38 +-
>  1 file changed, 25 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/usb/renesas_usbhs/pipe.c 
> b/drivers/usb/renesas_usbhs/pipe.c
> index 78e9dba..00d595c 100644
> --- a/drivers/usb/renesas_usbhs/pipe.c
> +++ b/drivers/usb/renesas_usbhs/pipe.c
> @@ -391,9 +391,9 @@ void usbhs_pipe_set_trans_count_if_bulk(struct usbhs_pipe 
> *pipe, int len)
>  /*
>   *   pipe setup
>   */
> -static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
> - int is_host,
> - int dir_in)
> +static u16 *usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
> +  int is_host,
> +  int dir_in)
>  {
>   u16 type = 0;
>   u16 bfre = 0;
> @@ -407,9 +407,13 @@ static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
>   [USB_ENDPOINT_XFER_INT]  = TYPE_INT,
>   [USB_ENDPOINT_XFER_ISOC] = TYPE_ISO,
>   };
> + u16 *result;
> 
>   if (usbhs_pipe_is_dcp(pipe))
> - return -EINVAL;
> + return ERR_PTR(-EINVAL);
> + result = kmalloc(sizeof(u16), GFP_KERNEL);
> + if (!result)
> + return ERR_PTR(-ENOMEM);
> 
>   /*
>* PIPECFG
> @@ -451,14 +455,14 @@ static u16 usbhsp_setup_pipecfg(struct usbhs_pipe *pipe,
> 
>   /* EPNUM */
>   epnum = 0; /* see usbhs_pipe_config_update() */
> -
> - return  type|
> - bfre|
> - dblb|
> - cntmd   |
> - dir |
> - shtnak  |
> - epnum;
> + *result = type   |
> +   bfre   |
> +   dblb   |
> +   cntmd  |
> +   dir|
> +   shtnak |
> +   epnum;
> + return result;
>  }
> 
>  static u16 usbhsp_setup_pipebuff(struct usbhs_pipe *pipe)
> @@ -683,6 +687,7 @@ struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv 
> *priv,
>   int is_host = usbhs_mod_is_host(priv);
>   int ret;
>   u16 pipecfg, pipebuf;
> + u16 *result;
> 
>   pipe = usbhsp_get_pipe(priv, endpoint_type);
>   if (!pipe) {
> @@ -702,7 +707,14 @@ struct usbhs_pipe *usbhs_pipe_malloc(struct usbhs_priv 
> *priv,
>   return NULL;
>   }
> 
> - pipecfg  = usbhsp_setup_pipecfg(pipe, is_host, dir_in);
> + result = usbhsp_setup_pipecfg(pipe, is_host, dir_in);
> + if (IS_ERR(result)) {
> + dev_err(dev, "can't setup pipe\n");
> + return NULL;
> + }
> + pipecfg = *result;
> + kfree(result);
> +
>   pipebuf  = usbhsp_setup_pipebuff(pipe);
> 
>   usbhsp_pipe_select(pipe);
> --
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-14 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Thursday, April 14, 2016 8:00 PM
> 
> On 14/04/16 11:36, Yoshihiro Shimoda wrote:
> > Hi,
> >
< snip >
> > diff --git a/drivers/usb/common/common.c b/drivers/usb/common/common.c
> > index e3d0161..8b74715 100644
> > --- a/drivers/usb/common/common.c
> > +++ b/drivers/usb/common/common.c
> > @@ -233,6 +233,8 @@ int of_usb_update_otg_caps(struct device_node *np,
> > if (of_find_property(np, "adp-disable", NULL) ||
> > (otg_caps->otg_rev < 0x0200))
> > otg_caps->adp_support = false;
> > +   if (of_find_property(np, "hcd-needs-companion", NULL))
> > +   otg_caps->needs_companion = true;
> 
> I'm not sure if otg_caps structure is a right place for this. Maybe Peter can 
> confirm
> if this is OK or not.
> 
> I was thinking more about adding this bit in the otg_config structure.

I see. I also think the otg_config is more suitable.

> >
> > return 0;
> >  }
> > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > index 41e762a..e0df839 100644
> > --- a/drivers/usb/common/usb-otg.c
> > +++ b/drivers/usb/common/usb-otg.c
> > @@ -823,13 +823,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> > unsigned int irqnum,
> > /* HCD will be started by OTG fsm when needed */
> > mutex_lock(>fsm.lock);
> > if (otg->primary_hcd.hcd) {
> > -   /* probably a shared HCD ? */
> > -   if (usb_otg_hcd_is_primary_hcd(hcd)) {
> > +   /* probably a shared HCD or a companion OHCI HCD ? */
> > +   if (!otg->caps->needs_companion &&
> > +   usb_otg_hcd_is_primary_hcd(hcd)) {
> > dev_err(otg_dev, "otg: primary host already 
> > registered\n");
> > goto err;
> > }
> >
> > -   if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> > +   if (otg->caps->needs_companion ||
> > +   (hcd->shared_hcd == otg->primary_hcd.hcd)) {
> > if (otg->shared_hcd.hcd) {
> > dev_err(otg_dev, "otg: shared host already 
> > registered\n");
> > goto err;
> > @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned 
> > int irqnum,
> >  * we're ready only if we have shared HCD
> >  * or we don't need shared HCD.
> >  */
> > -   if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > +   if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > +   !otg->primary_hcd.hcd->shared_hcd)) {
> > otg->host = hcd_to_bus(hcd);
> > /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> >
> 
> These changes look good to me. Thanks.

Thank you for the comment.
If we change the "needs_companion" place to the otg_config,
do we need to add a flag into the otg, instead of otg->caps?

> > diff --git a/include/linux/usb/otg.h b/include/linux/usb/otg.h
> > index b094352..64a7db8 100644
> > --- a/include/linux/usb/otg.h
> > +++ b/include/linux/usb/otg.h
> > @@ -112,12 +112,14 @@ struct usb_otg {
> >   * @hnp_support: Indicates if the device supports HNP.
> >   * @srp_support: Indicates if the device supports SRP.
> >   * @adp_support: Indicates if the device supports ADP.
> > + * @needs_companion: Indicates if the device needs a companion controller.
> 
> Description is not exact. How about this.
> "Indicates if host controller needs a companion controller"
> 
> Is hcd_needs_companion is better than just needs_companion?

I agree with you.

So, I will modify my local patch and test it tomorrow.

Best regards,
Yoshihiro Shimoda

> 
> >   */
> >  struct usb_otg_caps {
> > u16 otg_rev;
> > bool hnp_support;
> > bool srp_support;
> > bool adp_support;
> > +   bool needs_companion;
> >  };
> >
> >  /**
> >
> 
> cheers,
> -roger


RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-21 Thread Yoshihiro Shimoda
Hi,

> From: Peter Chen
> Sent: Friday, April 22, 2016 12:34 PM
> 
> On Fri, Apr 22, 2016 at 09:26:46AM +0800, Peter Chen wrote:
> > On Fri, Apr 15, 2016 at 10:03:16AM +, Yoshihiro Shimoda wrote:
> > > Hi,
> > >
> > > > From: Yoshihiro Shimoda
> > > > Sent: Friday, April 15, 2016 6:59 PM
> > > >
> > > > Hi,
> > > >
> > > > > From: Roger Quadros
> > > > > Sent: Thursday, April 14, 2016 8:32 PM
> > > > >
> > > > > On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > > > > > Hi,
> > > > > >
> > > > < snip >
> > > > > >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> > > > > >>> unsigned int irqnum,
> > > > > >>>* we're ready only if we have shared HCD
> > > > > >>>* or we don't need shared HCD.
> > > > > >>>*/
> > > > > >>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > > > > >>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > > > > >>> + !otg->primary_hcd.hcd->shared_hcd)) 
> > > > > >>> {
> > > > > >>>   otg->host = hcd_to_bus(hcd);
> > > > > >>>   /* FIXME: set bus->otg_port if this is true OTG port 
> > > > > >>> with HNP */
> > > > > >>>
> > > > > >>
> > > > > >> These changes look good to me. Thanks.
> > > > > >
> > > > > > Thank you for the comment.
> > > > > > If we change the "needs_companion" place to the otg_config,
> > > > > > do we need to add a flag into the otg, instead of otg->caps?
> > > > >
> > > > > Yes we can add a flag in struct usb_otg.
> > > >
> > > > Thank you for the comment.
> > > >
> > > > I made a fixed patch.
> > > > So, should I send this patch to ML after you sent v7 patches?
> > > > Or, would you apply this patch before you send v7 patches?
> > >
> > > Oops, I sent this email without my patch...
> > >
> > > ---
> > > Subject: [PATCH] usb: otg: add hcd companion support
> > >
> > > Since some host controller (e.g. EHCI) needs a companion host controller
> > > (e.g. OHCI), this patch adds such a configuration to use it in the OTG
> > > core.
> > >
> > > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > > ---
> > >  Documentation/devicetree/bindings/usb/generic.txt |  3 +++
> > >  drivers/usb/common/usb-otg.c  | 17 +
> > >  include/linux/usb/otg.h   |  7 ++-
> > >  3 files changed, 22 insertions(+), 5 deletions(-)
> > >
> > > diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
> > > b/Documentation/devicetree/bindings/usb/generic.txt
> > > index f6866c1..1db1c33 100644
> > > --- a/Documentation/devicetree/bindings/usb/generic.txt
> > > +++ b/Documentation/devicetree/bindings/usb/generic.txt
> > > @@ -27,6 +27,9 @@ Optional properties:
> > >   - otg-controller: phandle to otg controller. Host or gadget controllers 
> > > can
> > >   contain this property to link it to a particular OTG
> > >   controller.
> > > + - hcd-needs-companion: must be present if otg controller is dealing with
> > > + EHCI host controller that needs a companion OHCI host
> > > + controller.
> > >
> > >  This is an attribute to a USB controller such as:
> > >
> > > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > > index 41e762a..83c8c96 100644
> > > --- a/drivers/usb/common/usb-otg.c
> > > +++ b/drivers/usb/common/usb-otg.c
> > > @@ -20,6 +20,7 @@
> > >  #include 
> > >  #include 
> > >  #include 
> > > +#include 
> > >  #include 
> > >  #include 
> > >  #include 
> > > @@ -600,6 +601,10 @@ struct usb_otg *usb_otg_register(struct device *dev,
> > >   else
> > >   INIT_WORK(>work, usb_otg_work);
> > >
> > > + if (of_find_property(dev->of_node, "hcd-needs-compan

RE: [PATCH v7 10/14] usb: otg: add hcd companion support

2016-05-11 Thread Yoshihiro Shimoda
Hi,

> From: Alan Stern
> Sent: Wednesday, May 11, 2016 11:47 PM
> 
> On Wed, 11 May 2016, Roger Quadros wrote:
> 
> > > What I mean is if you have 2 EHCI controllers with 2 companion
> > > controllers, don't you need to know which companion goes with which EHCI
> > > controller? Just like you do for the otg-controller property.
> > >
> >
> > That is a very good point. I'm not very sure and it seems that current code 
> > won't work
> > with multiple EHCI + companion instances.

I may misunderstand this topic, but if I use the following environment, it 
works correctly.

< My environment >
- an otg controller: Sets hcd-needs-companion.
- ehci0 and ohci0 and a function: They connect to the otg controller using 
"otg-controller" property.
- ehci1 and ohci1: No "otg-controller" property.
- ehci2 and ohci2: No "otg-controller" property.

In this environment, all hosts works correctly.
Also I think if we have 2 otg controlelrs, it should be work because otg_dev 
instance differs.
Or, does this topic assume an otg controller handles 2 EHCI controllers?
I'm not sure such environment actually exists.

> > Alan, does USB core even know which EHCI and OHCI are linked to the same 
> > port
> > or the handoff is software transparent?
> 
> The core knows.  It doesn't use the information for a whole lot of
> things, but it does use it in a couple of places.  Search for
> "companion" in core/hcd-pci.c and you'll see.

Thank you for the information. I didn't know this code.
If my understanding is correct, the core/hcd-pci.c code will not be used by 
non-PCI devices.
In other words, nobody sets "hcd->self.hs_companion" if we use such a device.
So, I will try to add such a code if needed.

Best regards,
Yoshihiro Shimoda

> Alan Stern



RE: [PATCH v7 10/14] usb: otg: add hcd companion support

2016-05-12 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Thursday, May 12, 2016 6:32 PM
> 
> Hi,
> 
> On 12/05/16 11:34, Roger Quadros wrote:
> > On 12/05/16 07:00, Yoshihiro Shimoda wrote:
> >> Hi,
> >>
> >>> From: Alan Stern
> >>> Sent: Wednesday, May 11, 2016 11:47 PM
> >>>
> >>> On Wed, 11 May 2016, Roger Quadros wrote:
> >>>
> >>>>> What I mean is if you have 2 EHCI controllers with 2 companion
> >>>>> controllers, don't you need to know which companion goes with which EHCI
> >>>>> controller? Just like you do for the otg-controller property.
> >>>>>
> >>>>
> >>>> That is a very good point. I'm not very sure and it seems that current 
> >>>> code won't work
> >>>> with multiple EHCI + companion instances.
> >>
> >> I may misunderstand this topic, but if I use the following environment, it 
> >> works correctly.
> >>
> >> < My environment >
> >> - an otg controller: Sets hcd-needs-companion.
> >> - ehci0 and ohci0 and a function: They connect to the otg controller using 
> >> "otg-controller" property.
> >> - ehci1 and ohci1: No "otg-controller" property.
> >> - ehci2 and ohci2: No "otg-controller" property.
> >>
> >> In this environment, all hosts works correctly.
> >> Also I think if we have 2 otg controlelrs, it should be work because 
> >> otg_dev instance differs.
> >
> > The topic is about more than one otg controllers and how to tie the right 
> > ehci and ohci
> > to the correct otg_dev instance especially in cases where we can't depend 
> > on probe order.
> >
> >> Or, does this topic assume an otg controller handles 2 EHCI controllers?
> >> I'm not sure such environment actually exists.
> >
> > No it is not about that.

Thank you for the reply. I understood it.

> >>>> Alan, does USB core even know which EHCI and OHCI are linked to the same 
> >>>> port
> >>>> or the handoff is software transparent?
> >>>
> >>> The core knows.  It doesn't use the information for a whole lot of
> >>> things, but it does use it in a couple of places.  Search for
> >>> "companion" in core/hcd-pci.c and you'll see.
> >>
> >> Thank you for the information. I didn't know this code.
> >> If my understanding is correct, the core/hcd-pci.c code will not be used 
> >> by non-PCI devices.
> >
> > That is correct.
> >
> >> In other words, nobody sets "hcd->self.hs_companion" if we use such a 
> >> device.
> >> So, I will try to add such a code if needed.
> >
> > I think OTG core would have to rely on USB core in providing the right 
> > companion device,
> > just like we rely on it for the primary vs shared HCD case.
> >
> 
> OK, it is not so simple.
> 
> EHCI and companion port handoff is really meant to be software transparent.
> 
> non-PCI devices really don't have knowledge of which OHCI instance is 
> companion to the EHCI.
> With device tree we could provide this mapping but for non-device tree case 
> we can't do
> anything.
> 
> So my suggestion would be to keep dual role implementation limited to one 
> instance for
> EHCI + companion case for non-DT.
> For PCI case I don't see how dual role can be implemented. I don't think we 
> have any
> dual-role PCI cards.

R-Car Gen2 SoCs (r8a779[0134] / arm32) has USB 2.0 host controllers via PCI bus 
and
one high speed function controller via AXI bus.
One of channel can be used as host or function.

> For DT case we could have a DT binding to tie the EHCI and companion and use 
> that
> in the OTG framework.

R-Car Gen3 SoC (r8a7795 / arm64) will be this type.
(Both USB 2.0 host/function controllers connect to AXI bus.)

> Any objections?

I don't have any objections because I'm just focus on R-Car Gen3 SoC for now.
If someone needs for PCI case, I think it is possible to add such a code 
somehow later.

Best regards,
Yoshihiro Shimoda

> cheers,
> -roger


RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-19 Thread Yoshihiro Shimoda
Hi,

> From: Peter Chen
> Sent: Tuesday, April 19, 2016 6:18 PM
> 
> On Fri, Apr 15, 2016 at 10:03:16AM +0000, Yoshihiro Shimoda wrote:
> > Hi,
> >
> > > From: Yoshihiro Shimoda
> > > Sent: Friday, April 15, 2016 6:59 PM
> > >
> > > Hi,
> > >
> > > > From: Roger Quadros
> > > > Sent: Thursday, April 14, 2016 8:32 PM
> > > >
> > > > On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > > > > Hi,
> > > > >
> > > < snip >
> > > > >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> > > > >>> unsigned int irqnum,
> > > > >>>  * we're ready only if we have shared HCD
> > > > >>>  * or we don't need shared HCD.
> > > > >>>  */
> > > > >>> -   if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > > > >>> +   if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > > > >>> +   !otg->primary_hcd.hcd->shared_hcd)) 
> > > > >>> {
> > > > >>> otg->host = hcd_to_bus(hcd);
> > > > >>> /* FIXME: set bus->otg_port if this is true OTG port 
> > > > >>> with HNP */
> > > > >>>
> > > > >>
> > > > >> These changes look good to me. Thanks.
> > > > >
> > > > > Thank you for the comment.
> > > > > If we change the "needs_companion" place to the otg_config,
> > > > > do we need to add a flag into the otg, instead of otg->caps?
> > > >
> > > > Yes we can add a flag in struct usb_otg.
> > >
> > > Thank you for the comment.
> > >
> > > I made a fixed patch.
> > > So, should I send this patch to ML after you sent v7 patches?
> > > Or, would you apply this patch before you send v7 patches?
> >
> > Oops, I sent this email without my patch...
> >
> > ---
> > Subject: [PATCH] usb: otg: add hcd companion support
> >
> > Since some host controller (e.g. EHCI) needs a companion host controller
> > (e.g. OHCI), this patch adds such a configuration to use it in the OTG
> > core.
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  Documentation/devicetree/bindings/usb/generic.txt |  3 +++
> >  drivers/usb/common/usb-otg.c  | 17 +
> >  include/linux/usb/otg.h   |  7 ++-
> >  3 files changed, 22 insertions(+), 5 deletions(-)
> >
> > diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
> > b/Documentation/devicetree/bindings/usb/generic.txt
> > index f6866c1..1db1c33 100644
> > --- a/Documentation/devicetree/bindings/usb/generic.txt
> > +++ b/Documentation/devicetree/bindings/usb/generic.txt
> > @@ -27,6 +27,9 @@ Optional properties:
> >   - otg-controller: phandle to otg controller. Host or gadget controllers 
> > can
> > contain this property to link it to a particular OTG
> > controller.
> > + - hcd-needs-companion: must be present if otg controller is dealing with
> > +   EHCI host controller that needs a companion OHCI host
> > +   controller.
> >
> >  This is an attribute to a USB controller such as:
> >
> > diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> > index 41e762a..83c8c96 100644
> > --- a/drivers/usb/common/usb-otg.c
> > +++ b/drivers/usb/common/usb-otg.c
> > @@ -20,6 +20,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >  #include 
> >  #include 
> >  #include 
> > @@ -600,6 +601,10 @@ struct usb_otg *usb_otg_register(struct device *dev,
> > else
> > INIT_WORK(>work, usb_otg_work);
> >
> > +   if (of_find_property(dev->of_node, "hcd-needs-companion", NULL) ||
> > +   config->hcd_needs_companion)/* needs comanion ? */
> 
> %s/comanion/companion

Thank you for pointing it out!

Roger, would you fix this in your v7 patch set?

> I have a little puzzled with companion controller and shared hcd, let me
> post a topic for it.

I looked at the email thread.
It is very useful information to me! :)

Best regards,
Yoshihiro Shimoda

> Peter
> 
> > +   otg->flags |= OTG_FLAG_HCD_NEED

RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-14 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Monday, April 11, 2016 7:55 PM
> 
> On 08/04/16 14:22, Yoshihiro Shimoda wrote:
> > Hi,
> >
> >> From: Roger Quadros
> >> Sent: Thursday, April 07, 2016 8:45 PM
> >>
> >> Hi,
> >>
> >> On 07/04/16 11:52, Yoshihiro Shimoda wrote:
> >>> Hi,
> >>>
> >>>> From: Roger Quadros
> >>>> Sent: Tuesday, April 05, 2016 11:05 PM
> > < snip >
> >>> diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
> >>> index 41e762a..4d7f043 100644
> >>> --- a/drivers/usb/common/usb-otg.c
> >>> +++ b/drivers/usb/common/usb-otg.c
> >>> @@ -825,11 +825,16 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> >>> unsigned int irqnum,
> >>>   if (otg->primary_hcd.hcd) {
> >>>   /* probably a shared HCD ? */
> >>>   if (usb_otg_hcd_is_primary_hcd(hcd)) {
> >>> + if (hcd->driver->flags & HCD_USB11) {
> >>> + dev_info(otg_dev, "this assumes usb 1.1 hc is 
> >>> as shared_hcd\n");
> >>> + goto check_shared_hcd;
> >>> + }
> >>>   dev_err(otg_dev, "otg: primary host already 
> >>> registered\n");
> >>>   goto err;
> >>>   }
> >>>
> >>>   if (hcd->shared_hcd == otg->primary_hcd.hcd) {
> >>> +check_shared_hcd:
> >>>   if (otg->shared_hcd.hcd) {
> >>>   dev_err(otg_dev, "otg: shared host already 
> >>> registered\n");
> >>>   goto err;
> >>>
> >>> What do you think this local hack?
> >>
> >> Is it guaranteed that EHCI hcd registers before OHCI hcd?
> >
> > Thank you for the comment. No, it is not guaranteed.
> >
> >> If not we need to improve the code still.
> >> We will also need to remove the constraint that primary_hcd must be 
> >> registered
> >> first in usb_otg_register_hcd(). I think that constraint is no longer
> >> needed anyways.
> >
> > I got it.
> > So, I made a patch to avoid the constraint using an additional property 
> > "otg-hcds".
> > The patch is in this end of email. What do you think about the patch?
> 
> This might only solve the issue for device tree but what about non-device 
> tree?
> We need to deal with both cases.

Thank you for the comment. I got it.

> >> If EHCI & OHCI HCDs register before OTG driver then things will break 
> >> unless
> >> we fix usb_otg_hcd_wait_add(). We need to add this HCD_USB11 check there to
> >> populate wait->shared_hcd.
> >
> > I see. In my environment, since EHCI & OHCI HCDs need phy driver and phy 
> > driver
> > will calls usb_otg_register(), the order is right. In other words,
> > EHCI & OHCI HCDs never register before OTG driver because even if EHCI 
> > driver
> > is probed first, the driver will be deferred (EHCI driver needs the phy 
> > driver).
> 
> But still we cannot assume this is true for all platforms. OTG driver can also
> be a separate entity than PHY driver.

I understood it.

> >>> I also wonder if array of hcd may be good for both xHCI and EHCI/OHCI.
> >>> For example of xHCI:
> >>>  - otg->hcds[0] = primary_hcd
> >>>  - otg->hcds[1] = shared_hcd
> >>>
> >>> For example of EHCI/OHCI:
> >>>  - otg->hcds[0] = primary_hcd of EHCI
> >>>  - otg->hcds[1] = primary_hcd of OHCI
> >>
> >> The bigger problem is that how do we know in the OHCI/EHCI case that we 
> >> need to wait
> >> for both of them before starting the OTG FSM?
> >> Some systems might use just OHCI or just EHCI.
> >>
> >> There is no guarantee that OTG driver registers before the HCDs so this 
> >> piece
> >> of information must come from the HCD itself. i.e. whether it needs a 
> >> companion or not.
> >
> > I understood these problems. I wonder if my patch can resolve these 
> > problems.
> >
> > Best regards,
> > Yoshihiro Shimoda
> > ---
> > diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
> > b/Documentation/devicetree/bindings/usb/generic.txt
> > index f6866c1..518b9eb 100644
> > --- a/Documentation/devicetree/bindings/

RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-15 Thread Yoshihiro Shimoda
Hi,

> From: Roger Quadros
> Sent: Thursday, April 14, 2016 8:32 PM
> 
> On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > Hi,
> >
< snip >
> >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> >>> unsigned int irqnum,
> >>>* we're ready only if we have shared HCD
> >>>* or we don't need shared HCD.
> >>>*/
> >>> - if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> >>> + if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> >>> + !otg->primary_hcd.hcd->shared_hcd)) {
> >>>   otg->host = hcd_to_bus(hcd);
> >>>   /* FIXME: set bus->otg_port if this is true OTG port with HNP */
> >>>
> >>
> >> These changes look good to me. Thanks.
> >
> > Thank you for the comment.
> > If we change the "needs_companion" place to the otg_config,
> > do we need to add a flag into the otg, instead of otg->caps?
> 
> Yes we can add a flag in struct usb_otg.

Thank you for the comment.

I made a fixed patch.
So, should I send this patch to ML after you sent v7 patches?
Or, would you apply this patch before you send v7 patches?

Best regards,
Yoshihiro Shimoda

---




RE: [PATCH v6 07/12] usb: otg: add OTG/dual-role core

2016-04-15 Thread Yoshihiro Shimoda
Hi,

> From: Yoshihiro Shimoda
> Sent: Friday, April 15, 2016 6:59 PM
> 
> Hi,
> 
> > From: Roger Quadros
> > Sent: Thursday, April 14, 2016 8:32 PM
> >
> > On 14/04/16 14:15, Yoshihiro Shimoda wrote:
> > > Hi,
> > >
> < snip >
> > >>> @@ -865,7 +867,8 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, 
> > >>> unsigned int irqnum,
> > >>>  * we're ready only if we have shared HCD
> > >>>  * or we don't need shared HCD.
> > >>>  */
> > >>> -   if (otg->shared_hcd.hcd || !otg->primary_hcd.hcd->shared_hcd) {
> > >>> +   if (otg->shared_hcd.hcd || (!otg->caps->needs_companion &&
> > >>> +   !otg->primary_hcd.hcd->shared_hcd)) 
> > >>> {
> > >>> otg->host = hcd_to_bus(hcd);
> > >>> /* FIXME: set bus->otg_port if this is true OTG port 
> > >>> with HNP */
> > >>>
> > >>
> > >> These changes look good to me. Thanks.
> > >
> > > Thank you for the comment.
> > > If we change the "needs_companion" place to the otg_config,
> > > do we need to add a flag into the otg, instead of otg->caps?
> >
> > Yes we can add a flag in struct usb_otg.
> 
> Thank you for the comment.
> 
> I made a fixed patch.
> So, should I send this patch to ML after you sent v7 patches?
> Or, would you apply this patch before you send v7 patches?

Oops, I sent this email without my patch...

---
Subject: [PATCH] usb: otg: add hcd companion support

Since some host controller (e.g. EHCI) needs a companion host controller
(e.g. OHCI), this patch adds such a configuration to use it in the OTG
core.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 Documentation/devicetree/bindings/usb/generic.txt |  3 +++
 drivers/usb/common/usb-otg.c  | 17 +
 include/linux/usb/otg.h   |  7 ++-
 3 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
b/Documentation/devicetree/bindings/usb/generic.txt
index f6866c1..1db1c33 100644
--- a/Documentation/devicetree/bindings/usb/generic.txt
+++ b/Documentation/devicetree/bindings/usb/generic.txt
@@ -27,6 +27,9 @@ Optional properties:
  - otg-controller: phandle to otg controller. Host or gadget controllers can
contain this property to link it to a particular OTG
controller.
+ - hcd-needs-companion: must be present if otg controller is dealing with
+   EHCI host controller that needs a companion OHCI host
+   controller.
 
 This is an attribute to a USB controller such as:
 
diff --git a/drivers/usb/common/usb-otg.c b/drivers/usb/common/usb-otg.c
index 41e762a..83c8c96 100644
--- a/drivers/usb/common/usb-otg.c
+++ b/drivers/usb/common/usb-otg.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -600,6 +601,10 @@ struct usb_otg *usb_otg_register(struct device *dev,
else
INIT_WORK(>work, usb_otg_work);
 
+   if (of_find_property(dev->of_node, "hcd-needs-companion", NULL) ||
+   config->hcd_needs_companion)/* needs comanion ? */
+   otg->flags |= OTG_FLAG_HCD_NEEDS_COMPANION;
+
otg->wq = create_singlethread_workqueue("usb_otg");
if (!otg->wq) {
dev_err(dev, "otg: %s: can't create workqueue\n",
@@ -823,13 +828,15 @@ int usb_otg_register_hcd(struct usb_hcd *hcd, unsigned 
int irqnum,
/* HCD will be started by OTG fsm when needed */
mutex_lock(>fsm.lock);
if (otg->primary_hcd.hcd) {
-   /* probably a shared HCD ? */
-   if (usb_otg_hcd_is_primary_hcd(hcd)) {
+   /* probably a shared HCD or a companion OHCI HCD ? */
+   if (!(otg->flags & OTG_FLAG_HCD_NEEDS_COMPANION) &&
+   usb_otg_hcd_is_primary_hcd(hcd)) {
dev_err(otg_dev, "otg: primary host already 
registered\n");
goto err;
}
 
-   if (hcd->shared_hcd == otg->primary_hcd.hcd) {
+   if (otg->flags & OTG_FLAG_HCD_NEEDS_COMPANION ||
+   (hcd->shared_hcd == otg->primary_hcd.hcd)) {
if (otg->shared_hcd.hcd) {
dev_err(otg_dev, "otg: shared host already 
registered\n");
goto err;
@@ -865,7 +872,9 @@ int usb_otg_register_hcd(struct usb_

RE: [PATCH] phy: rcar-gen3-usb2: fix mutex_lock calling in interrupt

2016-06-29 Thread Yoshihiro Shimoda
Hi,

> From: Kishon Vijay Abraham I
> Sent: Wednesday, June 29, 2016 11:04 PM
> 
> +Chanwoo
> 
> Hi,
> 
> On Monday 27 June 2016 12:06 PM, Yoshihiro Shimoda wrote:
> > This patch fixes an issue that the extcon_set_cable_state_() is possible
> > to cause "BUG: scheduling while atomic" because this driver calls
> > extcon_set_cable_state_() in the interrupt handler and mutex_lock()
> 
> Doesn't extcon_set_cable_state_() use spin_lock?

If my understanding is correct, this issue is caused by kobject_uevent_env() 
finally.
(I should have wrote so in the commit log though...)

The kobject_uevent_env() has a global mutex value "uevent_sock_mutex".
Since it can be used other software, if other software get the mutext first and
the phy-rcar-gen3-usb2 will call extcon_set_cable_state_() from interrupt 
handler,
the kobject_uevent_env() is possible to be in interrupt, and then this BUG() 
happened.

Best regards,
Yoshihiro Shimoda

> Thanks
> Kishon
> 
> > is possible to be called by like the following call trace.
> > So, this patch adds a workqueue function to resolve this issue.
> >
> > [9.706504] BUG: scheduling while atomic: 
> > systemd-journal/25893/0x00010303
> > [9.714569] Modules linked in:
> > [9.717629] CPU: 0 PID: 25893 Comm: systemd-journal Not tainted 
> > 4.7.0-rc4+ #86
> > [9.724844] Hardware name: Renesas Salvator-X board based on r8a7795 (DT)
> > [9.731624] Call trace:
> > [9.734077] [] dump_backtrace+0x0/0x1a8
> > [9.739470] [] show_stack+0x14/0x20
> > [9.744520] [] dump_stack+0x94/0xb8
> > [9.749568] [] __schedule_bug+0x44/0x58
> > [9.754966] [] __schedule+0x4e4/0x598
> > [9.760185] [] schedule+0x3c/0xa8
> > [9.765057] [] schedule_preempt_disabled+0x20/0x38
> > [9.771408] [] mutex_optimistic_spin+0x18c/0x1d0
> > [9.777583] [] __mutex_lock_slowpath+0x38/0x140
> > [9.783669] [] mutex_lock+0x44/0x60
> > [9.788717] [] kobject_uevent_env+0x250/0x500
> > [9.794634] [] extcon_update_state+0x220/0x298
> > [9.800634] [] extcon_set_cable_state_+0x78/0x88
> > [9.806812] [] rcar_gen3_device_recognition+0x5c/0xe0
> > [9.813420] [] rcar_gen3_phy_usb2_irq+0x3c/0x48
> > [9.819509] [] handle_irq_event_percpu+0x94/0x140
> > [9.825769] [] handle_irq_event+0x48/0x78
> > [9.831334] [] handle_fasteoi_irq+0xb8/0x1b0
> > [9.837162] [] generic_handle_irq+0x24/0x38
> > [9.842900] [] __handle_domain_irq+0x5c/0xb8
> > [9.848727] [] gic_handle_irq+0x58/0xb0
> >
> > Reported-by: Simon Horman <ho...@verge.net.au>
> > Fixes: 2b38543c8db1 ("phy: rcar-gen3-usb2: add extcon support")
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  drivers/phy/phy-rcar-gen3-usb2.c | 26 ++
> >  1 file changed, 22 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index 4be3f5d..31156c9 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -21,6 +21,7 @@
> >  #include 
> >  #include 
> >  #include 
> > +#include 
> >
> >  /*** USB2.0 Host registers (original offset is +0x200) ***/
> >  #define USB2_INT_ENABLE0x000
> > @@ -81,9 +82,25 @@ struct rcar_gen3_chan {
> > struct extcon_dev *extcon;
> > struct phy *phy;
> > struct regulator *vbus;
> > +   struct work_struct work;
> > +   bool extcon_host;
> > bool has_otg;
> >  };
> >
> > +static void rcar_gen3_phy_usb2_work(struct work_struct *work)
> > +{
> > +   struct rcar_gen3_chan *ch = container_of(work, struct rcar_gen3_chan,
> > +work);
> > +
> > +   if (ch->extcon_host) {
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, true);
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB, false);
> > +   } else {
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB_HOST, false);
> > +   extcon_set_cable_state_(ch->extcon, EXTCON_USB, true);
> > +   }
> > +}
> > +
> >  static void rcar_gen3_set_host_mode(struct rcar_gen3_chan *ch, int host)
> >  {
> > void __iomem *usb2_base = ch->base;
> > @@ -130,8 +147,8 @@ static void rcar_gen3_init_for_host(struct 
> > rcar_gen3_chan *ch)
> > rcar_gen3_set_host_mode(ch, 1);
> > rcar_gen3_enable_vbus_ctrl(ch, 1);
> >
> > -   extcon_set_cabl

[PATCH] serial: sh-sci: Fix panic when serial console and DMA are enabled

2017-02-26 Thread Yoshihiro Shimoda
From: Takatoshi Akiyama <takatoshi.akiyama...@ps.hitachi-solutions.com>

This patch fixes an issue that kernel panic happens when DMA is enabled
and we press enter key while the kernel booting on the serial console.

* An interrupt may occur after sci_request_irq().
* DMA transfer area is initialized by setup_timer() in sci_request_dma()
  and used in interrupt.

If an interrupt occurred between sci_request_irq() and setup_timer() in
sci_request_dma(), DMA transfer area has not been initialized yet.
So, this patch changes the order of sci_request_irq() and
sci_request_dma().

Fixes: 73a19e4c0301 ("serial: sh-sci: Add DMA support.")
Signed-off-by: Takatoshi Akiyama <takatoshi.akiyama...@ps.hitachi-solutions.com>
[Shimoda changes the commit log]
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the following repo and tag:
  - renesas-drivers.git / renesas-drivers-2017-02-21-v4.10 tag

 drivers/tty/serial/sh-sci.c | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/drivers/tty/serial/sh-sci.c b/drivers/tty/serial/sh-sci.c
index 1d6f953..681e469 100644
--- a/drivers/tty/serial/sh-sci.c
+++ b/drivers/tty/serial/sh-sci.c
@@ -1985,11 +1985,13 @@ static int sci_startup(struct uart_port *port)
 
dev_dbg(port->dev, "%s(%d)\n", __func__, port->line);
 
+   sci_request_dma(port);
+
ret = sci_request_irq(s);
-   if (unlikely(ret < 0))
+   if (unlikely(ret < 0)) {
+   sci_free_dma(port);
return ret;
-
-   sci_request_dma(port);
+   }
 
return 0;
 }
@@ -2021,8 +2023,8 @@ static void sci_shutdown(struct uart_port *port)
}
 #endif
 
-   sci_free_dma(port);
sci_free_irq(s);
+   sci_free_dma(port);
 }
 
 static int sci_sck_calc(struct sci_port *s, unsigned int bps,
-- 
1.9.1



[PATCH 2/2] phy: rcar-gen3-usb2: Add a compatible string for r8a7796

2016-08-24 Thread Yoshihiro Shimoda
This driver can support for r8a7796 SoC. So, this patch adds it.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 2 ++
 drivers/phy/phy-rcar-gen3-usb2.c | 1 +
 2 files changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index b54fb36..ace9cce 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -6,6 +6,8 @@ This file provides information on what the device node for the 
R-Car generation
 Required properties:
 - compatible: "renesas,usb2-phy-r8a7795" if the device is a part of an R8A7795
  SoC.
+ "renesas,usb2-phy-r8a7796" if the device is a part of an R8A7796
+ SoC.
  "renesas,rcar-gen3-usb2-phy" for a generic R-Car Gen3 compatible 
device.
 
  When compatible with the generic version, nodes must list the
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 31156c9..3d97ead 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -280,6 +280,7 @@ static irqreturn_t rcar_gen3_phy_usb2_irq(int irq, void 
*_ch)
 
 static const struct of_device_id rcar_gen3_phy_usb2_match_table[] = {
{ .compatible = "renesas,usb2-phy-r8a7795" },
+   { .compatible = "renesas,usb2-phy-r8a7796" },
{ .compatible = "renesas,rcar-gen3-usb2-phy" },
{ }
 };
-- 
1.9.1



[PATCH 0/2] phy: rcar-gen3-usb2: revise the dt doc and add support for r8a7796

2016-08-24 Thread Yoshihiro Shimoda
This patch set is based on the latest linux-phy.git / next branch.
(commit id = d9a6e11e10d657df9af1d321c0eccdead184f72a)

Yoshihiro Shimoda (2):
  phy: rcar-gen3-usb2: revise the example of device tree doc
  phy: rcar-gen3-usb2: Add a compatible string for r8a7796

 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 6 --
 drivers/phy/phy-rcar-gen3-usb2.c | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

-- 
1.9.1



[PATCH 1/2] phy: rcar-gen3-usb2: revise the example of device tree doc

2016-08-24 Thread Yoshihiro Shimoda
The clocks property should be set to , not _clks.

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt 
b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
index 2281d6c..b54fb36 100644
--- a/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
+++ b/Documentation/devicetree/bindings/phy/rcar-gen3-phy-usb2.txt
@@ -30,11 +30,11 @@ Example (R-Car H3):
compatible = "renesas,usb2-phy-r8a7795", 
"renesas,rcar-gen3-usb2-phy";
reg = <0 0xee080200 0 0x700>;
interrupts = ;
-   clocks = <_clks R8A7795_CLK_EHCI0>;
+   clocks = < CPG_MOD 703>;
};
 
usb-phy@ee0a0200 {
compatible = "renesas,usb2-phy-r8a7795", 
"renesas,rcar-gen3-usb2-phy";
reg = <0 0xee0a0200 0 0x700>;
-   clocks = <_clks R8A7795_CLK_EHCI0>;
+   clocks = < CPG_MOD 702>;
};
-- 
1.9.1



RE: [PATCH v2 3/3] usb: renesas_usbhs: cleanup with list_first_entry_or_null()

2016-09-27 Thread Yoshihiro Shimoda
Hi Yamada-san,

> From: Masahiro Yamada
> Sent: Monday, September 19, 2016 1:03 AM
> 
> The combo of list_empty() check and return list_first_entry()
> can be replaced with list_first_entry_or_null().
> 
> Signed-off-by: Masahiro Yamada <yamada.masah...@socionext.com>

Thank you for the patch!

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>

Best regards,
Yoshihiro Shimoda



[PATCH v5] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-08 Thread Yoshihiro Shimoda
This patch adds sysfs "role" for usb role swap. This parameter can be
read and write. If you use this file as the following, you can swap
the usb role.

For example:
 1) Connect a usb cable using 2 Salvator-x boards
 2) On A-Device (ID pin is low), you input the following command:
   # echo peripheral > /sys/devices/platform/soc/ee080200.usb-phy/role
 3) On B-Device (ID pin is high), you input the following command:
   # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Then, the A-device acts as a peripheral and the B-device acts as a host.
Please note that A-Device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the A-Device keeps to act as
peripheral.)
 # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
Reviewed-by: Peter Chen <peter.c...@nxp.com>
---
 This patch is based on the latest linux-phy.git / next branch.
 (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)

 Since this patch is related to usb, I added email addresses of Greg, Felipe,
 Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)

 Changes from v4:
  - Use if-else about the is_b_device check in role_store().
  - Add "Reviewed-by: Peter Chen <peter.c...@nxp.com>"

 Changes from v3:
  - Clean up redundant conditions in role_store().

 Changes from v2:
  - Modify the sysfs file name to "role", and the argument is "host" or
"peripheral". Peter suggested this. Thank you!

 Changes from v1:
  - rebase the latest next branch.

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  15 +++
 drivers/phy/phy-rcar-gen3-usb2.c   | 118 -
 2 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..6212697
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,15 @@
+What:  /sys/devices/platform//role
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+Description:
+   This file can be read and write.
+   The file can show/change the phy mode for role swap of usb.
+
+   Write the following strings to change the mode:
+"host" - switching mode from peripheral to host.
+"peripheral" - switching mode from host to peripheral.
+
+   Read the file, then it shows the following strings:
+"host" - The mode is host now.
+"peripheral" - The mode is peripheral now.
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..c63da1b 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(>work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,65 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
   

RE: [PATCH v4] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-08 Thread Yoshihiro Shimoda
Hi Peter-san,

> From: Peter Chen
> Sent: Wednesday, November 09, 2016 10:39 AM
> 
> On Tue, Nov 08, 2016 at 08:14:58PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds sysfs "role" for usb role swap. This parameter can be
> > read and write. If you use this file as the following, you can swap
> > the usb role.
> >
> > For example:
> >  1) Connect a usb cable using 2 Salvator-x boards
> >  2) On A-Device (ID pin is low), you input the following command:
> ># echo peripheral > /sys/devices/platform/soc/ee080200.usb-phy/role
> >  3) On B-Device (ID pin is high), you input the following command:
> ># echo host > /sys/devices/platform/soc/ee080200.usb-phy/role
> >
> > Then, the A-device acts as a peripheral and the B-device acts as a host.
> > Please note that A-Device must input the following command if you
> > want the board to act as a host again. (even if you disconnect the usb
> > cable, since id state may be the same, the A-Device keeps to act as
> > peripheral.)
> >  # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  This patch is based on the latest linux-phy.git / next branch.
> >  (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)
> >
> >  Since this patch is related to usb, I added email addresses of Greg, 
> > Felipe,
> >  Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)
> >
> >  Changes from v3:
> >   - Clean up redundant conditions in role_store().
> >
> >  Changes from v2:
> >   - Modify the sysfs file name to "role", and the argument is "host" or
> > "peripheral". Peter suggested this. Thank you!
> >
> >  Changes from v1:
> >   - rebase the latest next branch.
> >
> >  .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  15 +++
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 118 
> > -
> >  2 files changed, 132 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> >
> > diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > new file mode 100644
> > index 000..6212697
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > @@ -0,0 +1,15 @@
> > +What:  /sys/devices/platform//role
> > +Date:  October 2016
> > +KernelVersion: 4.10
> > +Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > +Description:
> > +   This file can be read and write.
> > +   The file can show/change the phy mode for role swap of usb.
> > +
> > +   Write the following strings to change the mode:
> > +"host" - switching mode from peripheral to host.
> > +"peripheral" - switching mode from host to peripheral.
> > +
> > +   Read the file, then it shows the following strings:
> > +"host" - The mode is host now.
> > +"peripheral" - The mode is peripheral now.
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index 3d97ead..3f712b4 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> > @@ -70,6 +70,7 @@
> >  #define USB2_LINECTRL1_DP_RPD  BIT(18)
> >  #define USB2_LINECTRL1_DMRPD_ENBIT(17)
> >  #define USB2_LINECTRL1_DM_RPD  BIT(16)
> > +#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
> >
> >  /* ADPCTRL */
> >  #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
> > @@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct 
> > rcar_gen3_chan *ch)
> > schedule_work(>work);
> >  }
> >
> > +static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
> > +{
> > +   void __iomem *usb2_base = ch->base;
> > +   u32 val;
> > +
> > +   val = readl(usb2_base + USB2_LINECTRL1);
> > +   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
> > +
> > +   rcar_gen3_set_linectrl(ch, 1, 1);
> > +   rcar_gen3_set_host_mode(ch, 1);
> > +   rcar_gen3_enable_vbus_ctrl(ch, 0);
> > +
> > +   val = readl(usb2_base + USB2_LINECTRL1);
> > +   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
> > +}
&g

RE: [PATCH] usb: renesas_usbhs: simplify list handling

2016-11-07 Thread Yoshihiro Shimoda
Hi,

> From: Nicholas Mc Guire
> Sent: Tuesday, November 08, 2016 4:07 AM
> 
> The current code is effectively equivalent to list_first_entry_or_null()
> so simply switch and simplify the code.
> 
> Fixes: 6acb95d4e070 ("usb: renesas_usbhs: modify packet queue control method")
> Signed-off-by: Nicholas Mc Guire <hof...@osadl.org>
> ---
> Found by simple coccinelle scanner
> 
> Compile tested with: multi_v7_defconfig (implies
> CONFIG_USB_RENESAS_USBHS=m)
> 
> Patch is against 4.9.0-rc2 (localversion-next is next-20161028)

Thank you for the patch!
However, such a patch is already merged in the Felipe's usb.git repository 
unfortunately...
https://git.kernel.org/cgit/linux/kernel/git/balbi/usb.git/commit/?h=testing/next=31faf878bd8c7e2c078a3b75f65efe64f23b0f18
So, the patch will appear in linux-next repository in the future.

Best regards,
Yoshihiro Shimoda



RE: [PATCH v3] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-08 Thread Yoshihiro Shimoda
Hi,

> From: Peter Chen
> Sent: Tuesday, November 08, 2016 6:25 PM
> 
> On Wed, Nov 02, 2016 at 03:47:12PM +0900, Yoshihiro Shimoda wrote:
< snip >
> > +   /* If current and new mode is the same, this returns the error */
> > +   if (is_host == new_mode_is_host)
> > +   return -EINVAL;
> > +
> > +   if (new_mode_is_host) {
> > +   if (!is_b_device && !is_host)   /* A-Peripheral */
> > +   rcar_gen3_init_from_a_peri_to_a_host(ch);
> > +   if (is_b_device && !is_host)/* B-Peripheral */
> > +   rcar_gen3_init_for_b_host(ch);
> 
> is_host must be false here

Thank you for the review!
I will clean up the code and submit v4 patch soon.

> > +   } else {
> > +   if (!is_b_device && is_host)/* A-Host */
> > +   rcar_gen3_init_for_a_peri(ch);
> > +   if (is_b_device && is_host) /* B-Host */
> > +   rcar_gen3_init_for_peri(ch);
> 
> is_host must be true here

Same the above.

> > +   }
> > +
> > +   return count;
> > +}
> > +
> 
> How can you handle the case which ID pin is incorrect, eg, ID is 0, but
> it is peripheral mode at the initialization?

This driver always checks the ID pin and sets the suitable mode in 
initialization timing.
So, we can ignore such a situation.

< In detail >
 phy_init() @ drivers/phy/phy-core.c
 --> rcar_gen3_phy_usb2_init()
  --> rcar_gen3_phy_init_otg()
   --> rcar_gen3_device_recognition()
--> if (!rcar_gen3_check_id(ch))
  rcar_gen3_init_for_host(ch);   <-- Sets the mode as host
else
  rcar_gen3_init_for_peri(ch);   <-- Sets the mode as peripheral
++phy->init_count;  @ drivers/phy/phy-core.c

Best regards,
Yoshihiro Shimoda

> --
> 
> Best Regards,
> Peter Chen


[PATCH v4] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-08 Thread Yoshihiro Shimoda
This patch adds sysfs "role" for usb role swap. This parameter can be
read and write. If you use this file as the following, you can swap
the usb role.

For example:
 1) Connect a usb cable using 2 Salvator-x boards
 2) On A-Device (ID pin is low), you input the following command:
   # echo peripheral > /sys/devices/platform/soc/ee080200.usb-phy/role
 3) On B-Device (ID pin is high), you input the following command:
   # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Then, the A-device acts as a peripheral and the B-device acts as a host.
Please note that A-Device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the A-Device keeps to act as
peripheral.)
 # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the latest linux-phy.git / next branch.
 (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)

 Since this patch is related to usb, I added email addresses of Greg, Felipe,
 Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)

 Changes from v3:
  - Clean up redundant conditions in role_store().

 Changes from v2:
  - Modify the sysfs file name to "role", and the argument is "host" or
"peripheral". Peter suggested this. Thank you!

 Changes from v1:
  - rebase the latest next branch.

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  15 +++
 drivers/phy/phy-rcar-gen3-usb2.c   | 118 -
 2 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..6212697
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,15 @@
+What:  /sys/devices/platform//role
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+Description:
+   This file can be read and write.
+   The file can show/change the phy mode for role swap of usb.
+
+   Write the following strings to change the mode:
+"host" - switching mode from peripheral to host.
+"peripheral" - switching mode from host to peripheral.
+
+   Read the file, then it shows the following strings:
+"host" - The mode is host now.
+"peripheral" - The mode is peripheral now.
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..3f712b4 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(>work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,65 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
rcar_gen3_init_for_peri(ch);
 }
 
+static bool rcar_gen3_is_host(struct rcar_gen3_chan *ch)
+{
+   return !(readl(ch->base + USB2_COMMCTRL) & USB2_COMMCTRL_OTG_PERI);
+}
+
+static ssize_t role_store(struct d

[PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-10-17 Thread Yoshihiro Shimoda
This patch adds sysfs "otg_inputs" for usb role swap. This parameter
is write-only and if you use them as the following, you can swap
the usb role.

For example:
 1) connect a usb cable using 2 salvator-x boards
 2) On A-device (as host), you input the following command:
   # echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
 3) On B-device (as peripheral), you input the following command:
   # echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Then, the A-device acts as a peripheral (A-peripheral) and the B-device
acts as a host (B-host).
Please note that A-device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the condition keeps "A-peripheral".)
 # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Also you can use the following command if you want the B-device board to
act as a peripheral again.
 # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the linux-phy.git / phy-for-4.9-resolved_v3 tag.
 (commit id = c4b0bf82f705747ed7de90c5736b07248cbb29cd)

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
 drivers/phy/phy-rcar-gen3-usb2.c   | 124 -
 2 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..c7e715af
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,11 @@
+What:  /sys/devices/platform//otg-inputs
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+Description:
+   This write-only file changes the phy mode for role swap of usb.
+   This file accepts the following strings:
+"a_bus_req/" - switching from A-Host to A-Peripheral
+"a_bus_drop" - switching from A-Peripheral to A-Host
+"b_bus_req"  - switching from B-Peripheral to B-Host
+"b_bus_req/" - switching from B-Host to B-Peripheral
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..80f5bcc 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(>work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
rcar_gen3_init_for_peri(ch);
 }
 
+/*
+ * The following table is a state transition for usb phy mode:
+ * State   Event   Next state
+ * disconnected:   E1  a_host
+ * E2  b_peripheral
+ * A-Device - a_host:  E2  b_peripheral
+ * E3  disconnected
+ * E4  a_suspend
+ * A-Device - a_suspend:   E2  b_peripheral
+ * E3  disc

RE: [PATCH v2 RESEND] drivers/usb: Skip auto handoff for TI and RENESAS usb controllers

2016-10-24 Thread Yoshihiro Shimoda
Hi,

> From: Mathias Nyman
> Sent: Monday, October 24, 2016 6:58 PM
> 
> On 22.10.2016 01:25, Babu Moger wrote:
> > Never seen XHCI auto handoff working on TI and RENESAS cards.
> > Eventually, we force handoff. This code forces the handoff
> > unconditionally. It saves 5 seconds boot time for each card.
> >
> > Signed-off-by: Babu Moger <babu.mo...@oracle.com>
> 
> Do the Renesas and TI controllers still advertise the extended capability
> for the handoff? (XHCI_EXT_CAPS_LEGACY)
> 
> Is this some known issue with these vendors controllers? Is there some 
> documentation
> about this, errata or anything?
> 
> Adding Yoshihiro Shimoda, he might know about the Renesas controller.

Thank you for adding me on this email.
However, unfortunately I don't know the detail about Renesas PCIe xHCI 
controllers.
(I know the xHCI controller of R-Car SoCs for now.)

Best regards,
Yoshihiro Shimoda



RE: [PATCH] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-10-18 Thread Yoshihiro Shimoda
Hi Geert-san,

> From: geert.uytterhoe...@gmail.com
> Sent: Monday, October 17, 2016 9:28 PM
> 
> Hi Shimoda-san,
> 
> On Mon, Oct 17, 2016 at 9:10 AM, Yoshihiro Shimoda
> <yoshihiro.shimoda...@renesas.com> wrote:
> > This patch adds sysfs "otg_inputs" for usb role swap. This parameter
> > is write-only and if you use them as the following, you can swap
> > the usb role.
> 
> Thank you for your patch!

Thank you for the review!

> > For example:
> >  1) connect a usb cable using 2 salvator-x boards
> >  2) On A-device (as host), you input the following command:
> ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >  3) On B-device (as peripheral), you input the following command:
> ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> 
> At first, I thought the trailing "/" was a typo...
> 
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > @@ -0,0 +1,11 @@
> > +What:  /sys/devices/platform//otg-inputs
> > +Date:  October 2016
> > +KernelVersion: 4.10
> > +Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > +Description:
> > +   This write-only file changes the phy mode for role swap of 
> > usb.
> > +   This file accepts the following strings:
> > +"a_bus_req/" - switching from A-Host to A-Peripheral
> > +"a_bus_drop" - switching from A-Peripheral to A-Host
> > +"b_bus_req"  - switching from B-Peripheral to B-Host
> > +"b_bus_req/" - switching from B-Host to B-Peripheral
> 
> ... until I read the above.
> 
> What's the rationale of doing it like this? I.e.
>   1. Why differentiate by trailing "/"?

This usb role swap feature is not compatible with USB OTG though,
but this strings are from the manual that usb.org released:
http://www.usb.org/developers/docs/usb20_docs/
 --> usb_20_091216.zip
  --> USB OTG and Embedded Host/USB_OTG_and_EH_2-0-version 1_1a.pdf
   Please refer to the following figures:
- Figure 7-1: OTG A-device with HNP State Diagram
- Figure 7-4: OTG B-device with HNP State Diagram

So, it seems the "/" means FALSE.

>   2. Why the asymmetry ("a_bus_drop" vs. "a_bus_req")?

This is also related the document.
 - From "a_host" to "a_suspend" state if "a_bus_req/" event happens.
 - From "a_suspend" to "a_host" state if "a_bus_req" event happens.
  (But the driver doesn't support it and we can use "a_bus_drop".)
 - From "a_peripheral" to "a_wait_vfall" state if "a_bus_drop" event happens.

> I do not really follow USB development, so I please accepty my apologies if
> I missed the discussion and valid arguments that lead to this.
> 
> I did find Documentation/ABI/testing/sysfs-platform-chipidea-usb-otg,
> which uses similar naming, but a slightly different mechanism (multiple
> sysfs virtual files with 0/1 states).

I also did look at the document. But, I prefer one parameter to control it.

Best regards,
Yoshihiro Shimoda

> Thanks!
> 
> 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 v2] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-01 Thread Yoshihiro Shimoda
This patch adds sysfs "otg_inputs" for usb role swap. This parameter
is write-only and if you use them as the following, you can swap
the usb role.

For example:
 1) connect a usb cable using 2 salvator-x boards
 2) On A-device (as host), you input the following command:
   # echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
 3) On B-device (as peripheral), you input the following command:
   # echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Then, the A-device acts as a peripheral (A-peripheral) and the B-device
acts as a host (B-host).
Please note that A-device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the condition keeps "A-peripheral".)
 # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Also you can use the following command if you want the B-device board to
act as a peripheral again.
 # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the latest linux-phy.git / next branch.
 (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)

 Since this patch is related to usb, I added email addresses of Greg, Felipe,
 Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)

 Changed from v1:
  - rebase the latest next branch.

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
 drivers/phy/phy-rcar-gen3-usb2.c   | 124 -
 2 files changed, 134 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..c7e715af
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,11 @@
+What:  /sys/devices/platform//otg-inputs
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+Description:
+   This write-only file changes the phy mode for role swap of usb.
+   This file accepts the following strings:
+"a_bus_req/" - switching from A-Host to A-Peripheral
+"a_bus_drop" - switching from A-Peripheral to A-Host
+"b_bus_req"  - switching from B-Peripheral to B-Host
+"b_bus_req/" - switching from B-Host to B-Peripheral
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..80f5bcc 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(>work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,71 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
rcar_gen3_init_for_peri(ch);
 }
 
+/*
+ * The following table is a state transition for usb phy mode:
+ * State   Event   Next state
+ * disconnected:   E1  a_host
+ * E2  b_peripheral
+ * A-Device - a_host:  E2  b_peripheral
+ *

[PATCH v3] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-02 Thread Yoshihiro Shimoda
This patch adds sysfs "role" for usb role swap. This parameter can be
read and write. If you use this file as the following, you can swap
the usb role.

For example:
 1) Connect a usb cable using 2 Salvator-x boards
 2) On A-Device (ID pin is low), you input the following command:
   # echo peripheral > /sys/devices/platform/soc/ee080200.usb-phy/role
 3) On B-Device (ID pin is high), you input the following command:
   # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Then, the A-device acts as a peripheral and the B-device acts as a host.
Please note that A-Device must input the following command if you
want the board to act as a host again. (even if you disconnect the usb
cable, since id state may be the same, the A-Device keeps to act as
peripheral.)
 # echo host > /sys/devices/platform/soc/ee080200.usb-phy/role

Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 This patch is based on the latest linux-phy.git / next branch.
 (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)

 Since this patch is related to usb, I added email addresses of Greg, Felipe,
 Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)

 Changes from v2:
  - Modify the sysfs file name to "role", and the argument is "host" or
"peripheral". Peter suggested this. Thank you!

 Changes from v1:
  - rebase the latest next branch.

 .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  15 +++
 drivers/phy/phy-rcar-gen3-usb2.c   | 118 -
 2 files changed, 132 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2

diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2 
b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
new file mode 100644
index 000..6212697
--- /dev/null
+++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
@@ -0,0 +1,15 @@
+What:  /sys/devices/platform//role
+Date:  October 2016
+KernelVersion: 4.10
+Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
+Description:
+   This file can be read and write.
+   The file can show/change the phy mode for role swap of usb.
+
+   Write the following strings to change the mode:
+"host" - switching mode from peripheral to host.
+"peripheral" - switching mode from host to peripheral.
+
+   Read the file, then it shows the following strings:
+"host" - The mode is host now.
+"peripheral" - The mode is peripheral now.
diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index 3d97ead..cfc9956 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -70,6 +70,7 @@
 #define USB2_LINECTRL1_DP_RPD  BIT(18)
 #define USB2_LINECTRL1_DMRPD_ENBIT(17)
 #define USB2_LINECTRL1_DM_RPD  BIT(16)
+#define USB2_LINECTRL1_OPMODE_NODRVBIT(6)
 
 /* ADPCTRL */
 #define USB2_ADPCTRL_OTGSESSVLDBIT(20)
@@ -161,6 +162,43 @@ static void rcar_gen3_init_for_peri(struct rcar_gen3_chan 
*ch)
schedule_work(>work);
 }
 
+static void rcar_gen3_init_for_b_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val | USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+
+   rcar_gen3_set_linectrl(ch, 1, 1);
+   rcar_gen3_set_host_mode(ch, 1);
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+
+   val = readl(usb2_base + USB2_LINECTRL1);
+   writel(val & ~USB2_LINECTRL1_OPMODE_NODRV, usb2_base + USB2_LINECTRL1);
+}
+
+static void rcar_gen3_init_for_a_peri(struct rcar_gen3_chan *ch)
+{
+   rcar_gen3_set_linectrl(ch, 0, 1);
+   rcar_gen3_set_host_mode(ch, 0);
+   rcar_gen3_enable_vbus_ctrl(ch, 1);
+}
+
+static void rcar_gen3_init_from_a_peri_to_a_host(struct rcar_gen3_chan *ch)
+{
+   void __iomem *usb2_base = ch->base;
+   u32 val;
+
+   val = readl(usb2_base + USB2_OBINTEN);
+   writel(val & ~USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+
+   rcar_gen3_enable_vbus_ctrl(ch, 0);
+   rcar_gen3_init_for_host(ch);
+
+   writel(val | USB2_OBINT_BITS, usb2_base + USB2_OBINTEN);
+}
+
 static bool rcar_gen3_check_id(struct rcar_gen3_chan *ch)
 {
return !!(readl(ch->base + USB2_ADPCTRL) & USB2_ADPCTRL_IDDIG);
@@ -174,6 +212,65 @@ static void rcar_gen3_device_recognition(struct 
rcar_gen3_chan *ch)
rcar_gen3_init_for_peri(ch);
 }
 
+static bool rcar_gen3_is_host(struct rcar_gen3_chan *ch)
+{
+   return !(readl(ch->base + USB2_COMMCTRL) & USB2_COMMCTRL_OTG_PERI);
+}
+
+static ssize_t role_store(struct device *dev, struct device_attribute *attr,
+  

RE: [PATCH v2] phy: rcar-gen3-usb2: add sysfs for usb role swap

2016-11-01 Thread Yoshihiro Shimoda
Hi Peter,

> From: Peter Chen [mailto:hzpeterc...@gmail.com]
> Sent: Tuesday, November 01, 2016 8:38 PM
> 
> On Tue, Nov 01, 2016 at 04:01:58PM +0900, Yoshihiro Shimoda wrote:
> > This patch adds sysfs "otg_inputs" for usb role swap. This parameter
> > is write-only and if you use them as the following, you can swap
> > the usb role.
> >
> > For example:
> >  1) connect a usb cable using 2 salvator-x boards
> >  2) On A-device (as host), you input the following command:
> ># echo a_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >  3) On B-device (as peripheral), you input the following command:
> ># echo b_bus_req > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Then, the A-device acts as a peripheral (A-peripheral) and the B-device
> > acts as a host (B-host).
> > Please note that A-device must input the following command if you
> > want the board to act as a host again. (even if you disconnect the usb
> > cable, since id state may be the same, the condition keeps "A-peripheral".)
> >  # echo a_bus_drop > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Also you can use the following command if you want the B-device board to
> > act as a peripheral again.
> >  # echo b_bus_req/ > /sys/devices/platform/soc/ee080200.usb-phy/otg_inputs
> >
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  This patch is based on the latest linux-phy.git / next branch.
> >  (commit id = 7809cd2ce6abd4f431e4b14e6b1276a7cc842ac4)
> >
> >  Since this patch is related to usb, I added email addresses of Greg, 
> > Felipe,
> >  Peter and USB ML as CC. (This patch doesn't use USB OTG FSM though.)
> >
> >  Changed from v1:
> >   - rebase the latest next branch.
> >
> >  .../ABI/testing/sysfs-platform-phy-rcar-gen3-usb2  |  11 ++
> >  drivers/phy/phy-rcar-gen3-usb2.c   | 124 
> > -
> >  2 files changed, 134 insertions(+), 1 deletion(-)
> >  create mode 100644 
> > Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> >
> > diff --git a/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > new file mode 100644
> > index 000..c7e715af
> > --- /dev/null
> > +++ b/Documentation/ABI/testing/sysfs-platform-phy-rcar-gen3-usb2
> > @@ -0,0 +1,11 @@
> > +What:  /sys/devices/platform//otg-inputs
> > +Date:  October 2016
> > +KernelVersion: 4.10
> > +Contact:   Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > +Description:
> > +   This write-only file changes the phy mode for role swap of usb.
> > +   This file accepts the following strings:
> > +"a_bus_req/" - switching from A-Host to A-Peripheral
> > +"a_bus_drop" - switching from A-Peripheral to A-Host
> > +"b_bus_req"  - switching from B-Peripheral to B-Host
> > +    "b_bus_req/" - switching from B-Host to B-Peripheral
> 
> Would you really care OTG FSM state machine? If not, you could just use
> "host" and "peripheral" to stand for current USB role, and implement
> role switch sysfs like: /sys/devices/platform//role.

Thank you for the comment!
Since I would not care OTG FSM state machine for now, I will modify the patch to
use "host" and "peripheral" that you suggested.

Best regards,
Yoshihiro Shimoda

> Peter
> 


RE: [PATCH 12/12] usb: renesas_usbhs: Replace the deprecated extcon API

2016-12-05 Thread Yoshihiro Shimoda
Hi,

> From: Chanwoo Choi
> Sent: Wednesday, November 30, 2016 2:58 PM
> 
> This patch replaces the deprecated extcon API as following:
> - extcon_get_cable_state_() -> extcon_get_state()
> 
> Signed-off-by: Chanwoo Choi <cw00.c...@samsung.com>

Thank you for the patch!

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>

Best regards,
Yoshihiro Shimoda



RE: [PATCH 01/12] phy: rcar-gen3-usb2: Replace the deprecated extcon API

2016-12-05 Thread Yoshihiro Shimoda
Hi,

> From: Chanwoo Choi
> Sent: Wednesday, November 30, 2016 2:57 PM
> 
> This patch replaces the deprecated extcon API as following:
> - extcon_set_cable_state_() -> extcon_set_state_sync()
> 
> Signed-off-by: Chanwoo Choi <cw00.c...@samsung.com>

Thank you for the patch!

Acked-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>

Best regards,
Yoshihiro Shimoda




RE: [PATCH v3] phy: rcar-gen3-usb2: fix implementation for runtime PM

2017-04-04 Thread Yoshihiro Shimoda
Hi Kishon,

> From: Yoshihiro Shimoda, Sent: Tuesday, March 14, 2017 8:38 AM
> 
> This patch fixes an issue that this driver doesn't take care of the runtime
> PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev),
> but it misunderstood the dev_phy_create()'s specification.
> This driver should call its own pm_runtime_enable() before dev_phy_create().
> 
> Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver")
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  Changes from v2:
>   - revise the commit log (s/pm_runtime_pm/pm_runtime_enable)
> 
>  Changes from v1:
>   - revise the commit log (s/the own/its own/)
>   - simplify return code in probe().

I'm afraid but would you review this patch?

Best regards,
Yoshihiro Shimoda

>  drivers/phy/phy-rcar-gen3-usb2.c | 31 ---
>  1 file changed, 24 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> b/drivers/phy/phy-rcar-gen3-usb2.c
> index afb4d04..54c3429 100644
> --- a/drivers/phy/phy-rcar-gen3-usb2.c
> +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> @@ -20,6 +20,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
> 
> @@ -395,7 +396,7 @@ static int rcar_gen3_phy_usb2_probe(struct 
> platform_device *pdev)
>   struct rcar_gen3_chan *channel;
>   struct phy_provider *provider;
>   struct resource *res;
> - int irq;
> + int irq, ret = 0;
> 
>   if (!dev->of_node) {
>   dev_err(dev, "This driver needs device tree\n");
> @@ -434,17 +435,24 @@ static int rcar_gen3_phy_usb2_probe(struct 
> platform_device *pdev)
>   }
>   }
> 
> - /* devm_phy_create() will call pm_runtime_enable(dev); */
> + /*
> +  * devm_phy_create() will call pm_runtime_enable(>dev);
> +  * And then, phy-core will manage runtime pm for this device.
> +  */
> + pm_runtime_enable(dev);
>   channel->phy = devm_phy_create(dev, NULL, _gen3_phy_usb2_ops);
>   if (IS_ERR(channel->phy)) {
>   dev_err(dev, "Failed to create USB2 PHY\n");
> - return PTR_ERR(channel->phy);
> + ret = PTR_ERR(channel->phy);
> + goto error;
>   }
> 
>   channel->vbus = devm_regulator_get_optional(dev, "vbus");
>   if (IS_ERR(channel->vbus)) {
> - if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
> - return PTR_ERR(channel->vbus);
> + if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
> + ret = PTR_ERR(channel->vbus);
> + goto error;
> + }
>   channel->vbus = NULL;
>   }
> 
> @@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct 
> platform_device *pdev)
>   provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
>   if (IS_ERR(provider)) {
>   dev_err(dev, "Failed to register PHY provider\n");
> + ret = PTR_ERR(provider);
> + goto error;
>   } else if (channel->has_otg) {
>   int ret;
> 
>   ret = device_create_file(dev, _attr_role);
>   if (ret < 0)
> - return ret;
> + goto error;
>   }
> 
> - return PTR_ERR_OR_ZERO(provider);
> + return 0;
> +
> +error:
> + pm_runtime_disable(dev);
> +
> + return ret;
>  }
> 
>  static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
> @@ -472,6 +487,8 @@ static int rcar_gen3_phy_usb2_remove(struct 
> platform_device *pdev)
>   if (channel->has_otg)
>   device_remove_file(>dev, _attr_role);
> 
> + pm_runtime_disable(>dev);
> +
>   return 0;
>  };
> 
> --
> 1.9.1



[PATCH] phy: rcar-gen3-usb2: fix implementation for runtime PM

2017-03-13 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver doesn't take care of the runtime
PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev),
but it misunderstood the dev_phy_create()'s specification.
This driver should call the own pm_runtime_pm() before dev_phy_create().

Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 drivers/phy/phy-rcar-gen3-usb2.c | 29 +++--
 1 file changed, 23 insertions(+), 6 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index afb4d04..23c4e86 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -395,7 +396,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
struct rcar_gen3_chan *channel;
struct phy_provider *provider;
struct resource *res;
-   int irq;
+   int irq, ret = 0;
 
if (!dev->of_node) {
dev_err(dev, "This driver needs device tree\n");
@@ -434,17 +435,24 @@ static int rcar_gen3_phy_usb2_probe(struct 
platform_device *pdev)
}
}
 
-   /* devm_phy_create() will call pm_runtime_enable(dev); */
+   /*
+* devm_phy_create() will call pm_runtime_enable(>dev);
+* And then, phy-core will manage runtime pm for this device.
+*/
+   pm_runtime_enable(dev);
channel->phy = devm_phy_create(dev, NULL, _gen3_phy_usb2_ops);
if (IS_ERR(channel->phy)) {
dev_err(dev, "Failed to create USB2 PHY\n");
-   return PTR_ERR(channel->phy);
+   ret = PTR_ERR(channel->phy);
+   goto error;
}
 
channel->vbus = devm_regulator_get_optional(dev, "vbus");
if (IS_ERR(channel->vbus)) {
-   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
-   return PTR_ERR(channel->vbus);
+   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
+   ret = PTR_ERR(channel->vbus);
+   goto error;
+   }
channel->vbus = NULL;
}
 
@@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct 
platform_device *pdev)
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
if (IS_ERR(provider)) {
dev_err(dev, "Failed to register PHY provider\n");
+   ret = PTR_ERR(provider);
+   goto error;
} else if (channel->has_otg) {
int ret;
 
ret = device_create_file(dev, _attr_role);
if (ret < 0)
-   return ret;
+   goto error;
}
 
return PTR_ERR_OR_ZERO(provider);
+
+error:
+   pm_runtime_disable(dev);
+
+   return ret;
 }
 
 static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
@@ -472,6 +487,8 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device 
*pdev)
if (channel->has_otg)
device_remove_file(>dev, _attr_role);
 
+   pm_runtime_disable(>dev);
+
return 0;
 };
 
-- 
1.9.1



[PATCH v2] phy: rcar-gen3-usb2: fix implementation for runtime PM

2017-03-13 Thread Yoshihiro Shimoda
This patch fixes an issue that this driver doesn't take care of the runtime
PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev),
but it misunderstood the dev_phy_create()'s specification.
This driver should call its own pm_runtime_pm() before dev_phy_create().

Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver")
Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
---
 Changes from v1:
  - revise the commit log (s/the own/its own/)
  - simplify return code in probe().

 drivers/phy/phy-rcar-gen3-usb2.c | 31 ---
 1 file changed, 24 insertions(+), 7 deletions(-)

diff --git a/drivers/phy/phy-rcar-gen3-usb2.c b/drivers/phy/phy-rcar-gen3-usb2.c
index afb4d04..54c3429 100644
--- a/drivers/phy/phy-rcar-gen3-usb2.c
+++ b/drivers/phy/phy-rcar-gen3-usb2.c
@@ -20,6 +20,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 
@@ -395,7 +396,7 @@ static int rcar_gen3_phy_usb2_probe(struct platform_device 
*pdev)
struct rcar_gen3_chan *channel;
struct phy_provider *provider;
struct resource *res;
-   int irq;
+   int irq, ret = 0;
 
if (!dev->of_node) {
dev_err(dev, "This driver needs device tree\n");
@@ -434,17 +435,24 @@ static int rcar_gen3_phy_usb2_probe(struct 
platform_device *pdev)
}
}
 
-   /* devm_phy_create() will call pm_runtime_enable(dev); */
+   /*
+* devm_phy_create() will call pm_runtime_enable(>dev);
+* And then, phy-core will manage runtime pm for this device.
+*/
+   pm_runtime_enable(dev);
channel->phy = devm_phy_create(dev, NULL, _gen3_phy_usb2_ops);
if (IS_ERR(channel->phy)) {
dev_err(dev, "Failed to create USB2 PHY\n");
-   return PTR_ERR(channel->phy);
+   ret = PTR_ERR(channel->phy);
+   goto error;
}
 
channel->vbus = devm_regulator_get_optional(dev, "vbus");
if (IS_ERR(channel->vbus)) {
-   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER)
-   return PTR_ERR(channel->vbus);
+   if (PTR_ERR(channel->vbus) == -EPROBE_DEFER) {
+   ret = PTR_ERR(channel->vbus);
+   goto error;
+   }
channel->vbus = NULL;
}
 
@@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct 
platform_device *pdev)
provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
if (IS_ERR(provider)) {
dev_err(dev, "Failed to register PHY provider\n");
+   ret = PTR_ERR(provider);
+   goto error;
} else if (channel->has_otg) {
int ret;
 
ret = device_create_file(dev, _attr_role);
if (ret < 0)
-   return ret;
+   goto error;
}
 
-   return PTR_ERR_OR_ZERO(provider);
+   return 0;
+
+error:
+   pm_runtime_disable(dev);
+
+   return ret;
 }
 
 static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
@@ -472,6 +487,8 @@ static int rcar_gen3_phy_usb2_remove(struct platform_device 
*pdev)
if (channel->has_otg)
device_remove_file(>dev, _attr_role);
 
+   pm_runtime_disable(>dev);
+
return 0;
 };
 
-- 
1.9.1



RE: [PATCH] phy: rcar-gen3-usb2: fix implementation for runtime PM

2017-03-13 Thread Yoshihiro Shimoda
Hello!

> -Original Message-
> From: Sergei Shtylyov
> Sent: Monday, March 13, 2017 6:04 PM
> 
> Hello!
> 
> On 3/13/2017 9:24 AM, Yoshihiro Shimoda wrote:
> 
> > This patch fixes an issue that this driver doesn't take care of the runtime
> > PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev),
> > but it misunderstood the dev_phy_create()'s specification.
> > This driver should call the own pm_runtime_pm() before dev_phy_create().
> 
> Its own?

Yes. So, I will revise it.

> > Fixes: f3b5a8d9b50d ("phy: rcar-gen3-usb2: Add R-Car Gen3 USB2 PHY driver")
> > Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> > ---
> >  drivers/phy/phy-rcar-gen3-usb2.c | 29 +++--
> >  1 file changed, 23 insertions(+), 6 deletions(-)
> >
> > diff --git a/drivers/phy/phy-rcar-gen3-usb2.c 
> > b/drivers/phy/phy-rcar-gen3-usb2.c
> > index afb4d04..23c4e86 100644
> > --- a/drivers/phy/phy-rcar-gen3-usb2.c
> > +++ b/drivers/phy/phy-rcar-gen3-usb2.c
> [...]
> > @@ -454,15 +462,22 @@ static int rcar_gen3_phy_usb2_probe(struct 
> > platform_device *pdev)
> > provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> > if (IS_ERR(provider)) {
> > dev_err(dev, "Failed to register PHY provider\n");
> > +   ret = PTR_ERR(provider);
> > +   goto error;
> > } else if (channel->has_otg) {
> > int ret;
> >
> > ret = device_create_file(dev, _attr_role);
> > if (ret < 0)
> > -   return ret;
> > +   goto error;
> > }
> >
> > return PTR_ERR_OR_ZERO(provider);
> 
> Here 'provider' can no longer contain error -- *return* 0 seems to fit 
> better.

Oops, I will fix it.

Best regards,
Yoshihiro Shimoda

> > +
> > +error:
> > +   pm_runtime_disable(dev);
> > +
> > +   return ret;
> >  }
> >
> >  static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
> [...]
> 
> MBR, Sergei



RE: [PATCH v2] phy: rcar-gen3-usb2: fix implementation for runtime PM

2017-03-13 Thread Yoshihiro Shimoda
Hi!

> From: Sergei Shtylyov
> Sent: Monday, March 13, 2017 8:57 PM
> 
> On 03/13/2017 12:39 PM, Yoshihiro Shimoda wrote:
> 
> > This patch fixes an issue that this driver doesn't take care of the runtime
> > PM. This code assumed that devm_phy_create() called pm_runtime_enable(dev),
> > but it misunderstood the dev_phy_create()'s specification.
> > This driver should call its own pm_runtime_pm() before dev_phy_create().
> 
> You probably meant pm_runtime_enable()? Sorry for not noticing the 1st 
> time...

Yes, I meant pm_runtime_enable(). Thank you for the review again and again.

Best regards,
Yoshihiro Shimoda



  1   2   3   4   5   6   7   >