2016-03-03 10:09:29

by Yoshihiro Shimoda

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

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


2016-03-03 10:09:33

by Yoshihiro Shimoda

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

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 <[email protected]>
---
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(&ch->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(&ch->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(&ch->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

2016-03-03 10:09:39

by Yoshihiro Shimoda

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

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 <[email protected]>
Acked-by: Rob Herring <[email protected]>
---
.../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 <linux/of_address.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
+#include <linux/regulator/consumer.h>

/******* USB2.0 Host registers (original offset is +0x200) *******/
#define USB2_INT_ENABLE 0x000
@@ -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

2016-03-03 10:09:50

by Yoshihiro Shimoda

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

This patch adds extcon support for otg related channel.

Signed-off-by: Yoshihiro Shimoda <[email protected]>
---
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 <linux/extcon.h>
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/module.h>
@@ -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 = &pdev->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

2016-03-14 03:36:36

by Chanwoo Choi

[permalink] [raw]
Subject: Re: [PATCH 3/3] phy: rcar-gen3-usb2: add extcon support

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 <[email protected]>
> ---
> 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 <linux/extcon.h>
> #include <linux/interrupt.h>
> #include <linux/io.h>
> #include <linux/module.h>
> @@ -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 = &pdev->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 <[email protected]>

Best Regards,
Chanwoo Choi

2016-04-05 09:56:39

by Yoshihiro Shimoda

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

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:[email protected]]
> 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 <[email protected]>
> > ---
> > 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 <linux/extcon.h>
> > #include <linux/interrupt.h>
> > #include <linux/io.h>
> > #include <linux/module.h>
> > @@ -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 = &pdev->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 <[email protected]>
>
> Best Regards,
> Chanwoo Choi


2016-04-05 10:53:58

by Kishon Vijay Abraham I

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

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 <[email protected]>
> Acked-by: Rob Herring <[email protected]>
> ---
> .../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.

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 <linux/of_address.h>
> #include <linux/phy/phy.h>
> #include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
>
> /******* USB2.0 Host registers (original offset is +0x200) *******/
> #define USB2_INT_ENABLE 0x000
> @@ -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);
>

2016-04-06 00:25:38

by Yoshihiro Shimoda

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

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 <[email protected]>
> > Acked-by: Rob Herring <[email protected]>
> > ---
> > .../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 <linux/of_address.h>
> > #include <linux/phy/phy.h>
> > #include <linux/platform_device.h>
> > +#include <linux/regulator/consumer.h>
> >
> > /******* USB2.0 Host registers (original offset is +0x200) *******/
> > #define USB2_INT_ENABLE 0x000
> > @@ -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);
> >

2016-04-06 12:45:52

by Kishon Vijay Abraham I

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

Hi,

On Wednesday 06 April 2016 05:55 AM, Yoshihiro Shimoda wrote:
> 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 <[email protected]>
>>> Acked-by: Rob Herring <[email protected]>
>>> ---
>>> .../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?

All right. Will queue this for 4.7.

Thanks
Kishon

>
> 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 <linux/of_address.h>
>>> #include <linux/phy/phy.h>
>>> #include <linux/platform_device.h>
>>> +#include <linux/regulator/consumer.h>
>>>
>>> /******* USB2.0 Host registers (original offset is +0x200) *******/
>>> #define USB2_INT_ENABLE 0x000
>>> @@ -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);
>>>

2016-04-29 12:10:06

by Kishon Vijay Abraham I

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



On Thursday 03 March 2016 03:39 PM, Yoshihiro Shimoda wrote:
> 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

merged, thanks.

-Kishon
>
> 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(-)
>