Re: [PATCH v2 1/2] usb: of: add functions to bind a companion controller

2017-02-27 Thread Peter Chen
On Tue, Feb 21, 2017 at 07:59:47PM +0900, Yoshihiro Shimoda wrote:
> EHCI controllers will have a companion controller. However, on platform
> bus, there was difficult to bind them in previous code. So, this
> patch adds helper functions to bind them using a "companion" property.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  Documentation/devicetree/bindings/usb/generic.txt |  1 +
>  drivers/usb/core/of.c | 23 
> +++
>  include/linux/usb/of.h|  5 +
>  3 files changed, 29 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/usb/generic.txt 
> b/Documentation/devicetree/bindings/usb/generic.txt
> index bfadeb1..0a74ab8 100644
> --- a/Documentation/devicetree/bindings/usb/generic.txt
> +++ b/Documentation/devicetree/bindings/usb/generic.txt
> @@ -22,6 +22,7 @@ Optional properties:
>   property is used if any real OTG features(HNP/SRP/ADP)
>   is enabled, if ADP is required, otg-rev should be
>   0x0200 or above.
> + - companion: phandle of a companion
>   - hnp-disable: tells OTG controllers we want to disable OTG HNP, normally 
> HNP
>   is the basic function of real OTG except you want it
>   to be a srp-capable only B device.
> diff --git a/drivers/usb/core/of.c b/drivers/usb/core/of.c
> index 3de4f88..d787f19 100644
> --- a/drivers/usb/core/of.c
> +++ b/drivers/usb/core/of.c
> @@ -18,6 +18,7 @@
>   */
>  
>  #include 
> +#include 
>  #include 
>  
>  /**
> @@ -46,3 +47,25 @@ struct device_node *usb_of_get_child_node(struct 
> device_node *parent,
>  }
>  EXPORT_SYMBOL_GPL(usb_of_get_child_node);
>  
> +/**
> + * usb_of_get_companion_dev - Find the companion device
> + * @dev: the device pointer to find a companion
> + *
> + * Find the companion device from platform bus.
> + *
> + * Return: On success, a pointer to the companion device, %NULL on failure.
> + */
> +struct device *usb_of_get_companion_dev(struct device *dev)
> +{
> + struct device_node *node;
> + struct platform_device *pdev = NULL;
> +
> + node = of_parse_phandle(dev->of_node, "companion", 0);
> + if (node)
> + pdev = of_find_device_by_node(node);
> +
> + of_node_put(node);
> +
> + return pdev ? >dev : NULL;
> +}
> +EXPORT_SYMBOL_GPL(usb_of_get_companion_dev);
> diff --git a/include/linux/usb/of.h b/include/linux/usb/of.h
> index 5ff9032..4031f47 100644
> --- a/include/linux/usb/of.h
> +++ b/include/linux/usb/of.h
> @@ -18,6 +18,7 @@ int of_usb_update_otg_caps(struct device_node *np,
>   struct usb_otg_caps *otg_caps);
>  struct device_node *usb_of_get_child_node(struct device_node *parent,
>   int portnum);
> +struct device *usb_of_get_companion_dev(struct device *dev);
>  #else
>  static inline enum usb_dr_mode
>  of_usb_get_dr_mode_by_phy(struct device_node *np, int arg0)
> @@ -38,6 +39,10 @@ static inline int of_usb_update_otg_caps(struct 
> device_node *np,
>  {
>       return NULL;
>  }
> +static inline struct device *usb_of_get_companion_dev(struct device *dev)
> +{
> + return NULL;
> +}
>  #endif
>  
>  #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_USB_SUPPORT)

Acked-by: Peter Chen <peter.c...@nxp.com>

-- 

Best Regards,
Peter Chen


Re: [PATCH v2 2/2] usb: host: ehci-platform: fix usb 1.1 device is not connected in system resume

2017-02-27 Thread Peter Chen
On Tue, Feb 21, 2017 at 07:59:48PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that a usb 1.1 device is not connected in
> system resume and then the following message appeared if debug messages
> are enabled:
>   usb 2-1: Waited 2000ms for CONNECT
> 
> To resolve this issue, the EHCI controller must be resumed after its
> companion controllers. So, this patch adds such code on the driver.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  drivers/usb/host/ehci-platform.c | 7 +++
>  1 file changed, 7 insertions(+)
> 
> diff --git a/drivers/usb/host/ehci-platform.c 
> b/drivers/usb/host/ehci-platform.c
> index a268d9e..3214300 100644
> --- a/drivers/usb/host/ehci-platform.c
> +++ b/drivers/usb/host/ehci-platform.c
> @@ -34,6 +34,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include "ehci.h"
>  
> @@ -297,6 +298,7 @@ static int ehci_platform_probe(struct platform_device 
> *dev)
>   goto err_power;
>  
>   device_wakeup_enable(hcd->self.controller);
> + device_enable_async_suspend(hcd->self.controller);
>   platform_set_drvdata(dev, hcd);
>  
>   return err;
> @@ -370,6 +372,7 @@ static int ehci_platform_resume(struct device *dev)
>   struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
>   struct platform_device *pdev = to_platform_device(dev);
>   struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
> + struct device *companion_dev;
>  
>   if (pdata->power_on) {
>   int err = pdata->power_on(pdev);
> @@ -377,6 +380,10 @@ static int ehci_platform_resume(struct device *dev)
>   return err;
>   }
>  
> + companion_dev = usb_of_get_companion_dev(hcd->self.controller);
> + if (companion_dev)
> + device_pm_wait_for_dev(hcd->self.controller, companion_dev);
> +
>   ehci_resume(hcd, priv->reset_on_resume);
>   return 0;

Reviewed-by: Peter Chen <peter.c...@nxp.com>

-- 

Best Regards,
Peter Chen


Re: [PATCH/RFC 2/2] usb: host: ehci-platform: fix usb 1.1 device is not connected in system resume

2017-02-21 Thread Peter Chen
On Mon, Feb 20, 2017 at 04:35:11PM +0900, Yoshihiro Shimoda wrote:
> This patch fixes an issue that a usb 1.1 device is not connected in
> system resume and then the following message appeared if debug messages
> are enabled:
>   usb 2-1: Waited 2000ms for CONNECT
> 
> To resolve this issue, the EHCI controller must be resumed after its
> companion controllers. So, this patch adds such code on the driver.
> 
> Signed-off-by: Yoshihiro Shimoda <yoshihiro.shimoda...@renesas.com>
> ---
>  drivers/usb/host/ehci-platform.c | 8 
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/usb/host/ehci-platform.c 
> b/drivers/usb/host/ehci-platform.c
> index a268d9e..65a7725 100644
> --- a/drivers/usb/host/ehci-platform.c
> +++ b/drivers/usb/host/ehci-platform.c
> @@ -34,6 +34,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include "ehci.h"
>  
> @@ -297,6 +298,8 @@ static int ehci_platform_probe(struct platform_device 
> *dev)
>   goto err_power;
>  
>   device_wakeup_enable(hcd->self.controller);
> + if (usb_of_has_companion(hcd->self.controller))

According to Alan's comments, all USB ehci platform device can be async
device, so this API can be skipped.

> + device_enable_async_suspend(hcd->self.controller);
>   platform_set_drvdata(dev, hcd);
>  
>   return err;
> @@ -370,6 +373,7 @@ static int ehci_platform_resume(struct device *dev)
>   struct usb_ehci_pdata *pdata = dev_get_platdata(dev);
>   struct platform_device *pdev = to_platform_device(dev);
>   struct ehci_platform_priv *priv = hcd_to_ehci_priv(hcd);
> + struct device *companion_dev;
>  
>   if (pdata->power_on) {
>   int err = pdata->power_on(pdev);
> @@ -377,6 +381,10 @@ static int ehci_platform_resume(struct device *dev)
>   return err;
>   }
>  
> + companion_dev = usb_of_get_companion_dev(hcd->self.controller);

Maybe other EHCI controller has companion controller too, so it is ok
for you to let it as a common API.

> + if (companion_dev)
> + device_pm_wait_for_dev(hcd->self.controller, companion_dev);
> +
>   ehci_resume(hcd, priv->reset_on_resume);
>   return 0;
>  }

You can send formal patch next time.

-- 

Best Regards,
Peter Chen


Re: [PATCH 05/12] usb: chipdata: Replace the extcon API

2016-12-01 Thread Peter Chen
On Wed, Nov 30, 2016 at 02:57:33PM +0900, Chanwoo Choi wrote:
> This patch uses the resource-managed extcon API for extcon_register_notifier()
> and replaces the deprecated extcon API as following:
> - extcon_get_cable_state_() -> extcon_get_state()
> 
> Signed-off-by: Chanwoo Choi <cw00.c...@samsung.com>
> ---
>  drivers/usb/chipidea/core.c | 30 ++
>  1 file changed, 6 insertions(+), 24 deletions(-)
> 
> diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c
> index 69426e644d17..a5b44963eaea 100644
> --- a/drivers/usb/chipidea/core.c
> +++ b/drivers/usb/chipidea/core.c
> @@ -742,7 +742,7 @@ static int ci_get_platdata(struct device *dev,
>   cable->edev = ext_vbus;
>  
>   if (!IS_ERR(ext_vbus)) {
> - ret = extcon_get_cable_state_(cable->edev, EXTCON_USB);
> + ret = extcon_get_state(cable->edev, EXTCON_USB);
>   if (ret)
>   cable->state = true;
>   else
> @@ -754,7 +754,7 @@ static int ci_get_platdata(struct device *dev,
>   cable->edev = ext_id;
>  
>   if (!IS_ERR(ext_id)) {
> - ret = extcon_get_cable_state_(cable->edev, EXTCON_USB_HOST);
> + ret = extcon_get_state(cable->edev, EXTCON_USB_HOST);
>   if (ret)
>   cable->state = false;
>   else
> @@ -771,8 +771,8 @@ static int ci_extcon_register(struct ci_hdrc *ci)
>   id = >platdata->id_extcon;
>   id->ci = ci;
>   if (!IS_ERR(id->edev)) {
> - ret = extcon_register_notifier(id->edev, EXTCON_USB_HOST,
> ->nb);
> + ret = devm_extcon_register_notifier(ci->dev, id->edev,
> + EXTCON_USB_HOST, >nb);
>   if (ret < 0) {
>   dev_err(ci->dev, "register ID failed\n");
>   return ret;
> @@ -782,11 +782,9 @@ static int ci_extcon_register(struct ci_hdrc *ci)
>   vbus = >platdata->vbus_extcon;
>   vbus->ci = ci;
>   if (!IS_ERR(vbus->edev)) {
> - ret = extcon_register_notifier(vbus->edev, EXTCON_USB,
> ->nb);
> + ret = devm_extcon_register_notifier(ci->dev, vbus->edev,
> + EXTCON_USB, >nb);
>   if (ret < 0) {
> - extcon_unregister_notifier(id->edev, EXTCON_USB_HOST,
> ->nb);
>   dev_err(ci->dev, "register VBUS failed\n");
>   return ret;
>   }
> @@ -795,20 +793,6 @@ static int ci_extcon_register(struct ci_hdrc *ci)
>   return 0;
>  }
>  
> -static void ci_extcon_unregister(struct ci_hdrc *ci)
> -{
> - struct ci_hdrc_cable *cable;
> -
> - cable = >platdata->id_extcon;
> - if (!IS_ERR(cable->edev))
> - extcon_unregister_notifier(cable->edev, EXTCON_USB_HOST,
> ->nb);
> -
> - cable = >platdata->vbus_extcon;
> - if (!IS_ERR(cable->edev))
> - extcon_unregister_notifier(cable->edev, EXTCON_USB, >nb);
> -}
> -
>  static DEFINE_IDA(ci_ida);
>  
>  struct platform_device *ci_hdrc_add_device(struct device *dev,
> @@ -1053,7 +1037,6 @@ static int ci_hdrc_probe(struct platform_device *pdev)
>   if (!ret)
>   return 0;
>  
> - ci_extcon_unregister(ci);
>  stop:
>   ci_role_destroy(ci);
>  deinit_phy:
> @@ -1073,7 +1056,6 @@ static int ci_hdrc_remove(struct platform_device *pdev)
>   }
>  
>   dbg_remove_files(ci);
> - ci_extcon_unregister(ci);
>   ci_role_destroy(ci);
>   ci_hdrc_enter_lpm(ci, true);
>   ci_usb_phy_exit(ci);
> -- 

Acked-by: Peter Chen <peter.c...@nxp.com>

-- 

Best Regards,
Peter Chen


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

2016-11-08 Thread Peter Chen
+
> + 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,
> +   const char *buf, size_t count)
> +{
> + struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
> + bool is_b_device, is_host, new_mode_is_host;
> +
> + if (!ch->has_otg || !ch->phy->init_count)
> + return -EIO;
> +
> + /*
> +  * is_b_device: true is B-Device. false is A-Device.
> +  * If {new_mode_}is_host: true is Host mode. false is Peripheral mode.
> +  */
> + is_b_device = rcar_gen3_check_id(ch);
> + is_host = rcar_gen3_is_host(ch);
> + if (!strncmp(buf, "host", strlen("host")))
> + new_mode_is_host = true;
> + else if (!strncmp(buf, "peripheral", strlen("peripheral")))
> +     new_mode_is_host = false;
> + else
> + return -EINVAL;
> +
> + /* 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) { /* And is_host must be false */
> + if (!is_b_device)   /* A-Peripheral */
> + rcar_gen3_init_from_a_peri_to_a_host(ch);
> + if (is_b_device)/* B-Peripheral */
> + rcar_gen3_init_for_b_host(ch);

Why not use if-else? The same to below.
After fixing it, you can add my:
Reviewed-by: Peter Chen <peter.c...@nxp.com>

Peter

> + } else {/* And is_host must be true */
> + if (!is_b_device)   /* A-Host */
> + rcar_gen3_init_for_a_peri(ch);
> + if (is_b_device)/* B-Host */
> + rcar_gen3_init_for_peri(ch);
> + }
> +
> + return count;
> +}
> +
> +static ssize_t role_show(struct device *dev, struct device_attribute *attr,
> +  char *buf)
> +{
> + struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
> +
> + if (!ch->has_otg || !ch->phy->init_count)
> + return -EIO;
> +
> + return sprintf(buf, "%s\n", rcar_gen3_is_host(ch) ? "host" :
> + "peripheral");
> +}
> +static DEVICE_ATTR_RW(role);
> +
>  static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
>  {
>   void __iomem *usb2_base = ch->base;
> @@ -351,21 +448,40 @@ static int rcar_gen3_phy_usb2_probe(struct 
> platform_device *pdev)
>   channel->vbus = NULL;
>   }
>  
> + platform_set_drvdata(pdev, channel);
>   phy_set_drvdata(channel->phy, channel);
>  
>   provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> - if (IS_ERR(provider))
> + if (IS_ERR(provider)) {
>   dev_err(dev, "Failed to register PHY provider\n");
> + } else if (channel->has_otg) {
> + int ret;
> +
> + ret = device_create_file(dev, _attr_role);
> + if (ret < 0)
> + return ret;
> + }
>  
>   return PTR_ERR_OR_ZERO(provider);
>  }
>  
> +static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
> +{
> + struct rcar_gen3_chan *channel = platform_get_drvdata(pdev);
> +
> + if (channel->has_otg)
> + device_remove_file(>dev, _attr_role);
> +
> + return 0;
> +};
> +
>  static struct platform_driver rcar_gen3_phy_usb2_driver = {
>   .driver = {
>   .name   = "phy_rcar_gen3_usb2",
>   .of_match_table = rcar_gen3_phy_usb2_match_table,
>   },
>   .probe  = rcar_gen3_phy_usb2_probe,
> + .remove = rcar_gen3_phy_usb2_remove,
>  };
>  module_platform_driver(rcar_gen3_phy_usb2_driver);
>  
> -- 
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

Best Regards,
Peter Chen


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

2016-11-08 Thread Peter Chen
; +
> + 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,
> +   const char *buf, size_t count)
> +{
> + struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
> + bool is_b_device, is_host, new_mode_is_host;
> +
> + if (!ch->has_otg || !ch->phy->init_count)
> + return -EIO;
> +
> + /*
> +  * is_b_device: true is B-Device. false is A-Device.
> +  * If {new_mode_}is_host: true is Host mode. false is Peripheral mode.
> +  */
> + is_b_device = rcar_gen3_check_id(ch);
> + is_host = rcar_gen3_is_host(ch);
> + if (!strncmp(buf, "host", strlen("host")))
> + new_mode_is_host = true;
> + else if (!strncmp(buf, "peripheral", strlen("peripheral")))
> + new_mode_is_host = false;
> + else
> + return -EINVAL;
> +
> + /* 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

> + } 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
> + }
> +
> + 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?

-- 

Best Regards,
Peter Chen


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

2016-11-01 Thread Peter Chen
eadl(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  disconnected
> + *   E5  a_host
> + *   E6  a_peripheral
> + * A-Device - a_peripheral:  E2  b_peripheral
> + *   E3  disconnected
> + *   E5  a_host
> + * B-Device - b_peripheral:  E3  disconnected
> + *   E7  b_wait_acon
> + * B-Device - b_wait_aconE3  disconnected
> + *   E8  b_host
> + * B-Device - b_host:E3  disconnected
> + *   E9  b_peripheral
> + * Events:
> + * E1: ID = 0 && Host detects D+ pull up,E2: ID = 1 && VBUS = 1
> + * E3: VBUS = 0 || ID is changed,E4: a_bus_req/
> + * E5: a_bus_drop,   E6: Turns D+ pull up off
> + * E7: b_bus_req,E8: Detects D+ pull up
> + * E9: b_bus_req/
> + */
> +static ssize_t otg_inputs_store(struct device *dev,
> + struct device_attribute *attr,
> + const char *buf, size_t count)
> +{
> + struct rcar_gen3_chan *ch = dev_get_drvdata(dev);
> + bool is_host, is_b_device;
> +
> + if (!ch->has_otg || !ch->phy->init_count)
> + return -EIO;
> +
> + is_b_device = rcar_gen3_check_id(ch);   /* true = B-Device */
> + is_host = !(readl(ch->base + USB2_COMMCTRL) & USB2_COMMCTRL_OTG_PERI);
> +
> + if (!strncmp(buf, "a_bus_req/", strlen("a_bus_req/"))) {
> + if (is_b_device)/* fail if B-device */
> + return -ENODEV;
> + rcar_gen3_init_for_a_peri(ch);
> + } else if (!strncmp(buf, "a_bus_drop", strlen("a_bus_drop"))) {
> + if (is_b_device || is_host) /* fail if B-device or A-host */
> + return -ENODEV;
> + rcar_gen3_init_from_a_peri_to_a_host(ch);
> + } else if (!strncmp(buf, "b_bus_req/", strlen("b_bus_req/"))) {
> + if (!is_b_device || !is_host)   /* fail if A-device or B-peri */
> + return -ENODEV;
> + rcar_gen3_init_for_peri(ch);
> + } else if (!strncmp(buf, "b_bus_req", strlen("b_bus_req"))) {
> + if (!is_b_device)   /* fail if A-device */
> + return -ENODEV;
> + rcar_gen3_init_for_b_host(ch);
> + } else {
> + return -EINVAL;
> + }
> +
> + return count;
> +}
> +static DEVICE_ATTR_WO(otg_inputs);
> +
>  static void rcar_gen3_init_otg(struct rcar_gen3_chan *ch)
>  {
>   void __iomem *usb2_base = ch->base;
> @@ -351,21 +454,40 @@ static int rcar_gen3_phy_usb2_probe(struct 
> platform_device *pdev)
>   channel->vbus = NULL;
>   }
>  
> + platform_set_drvdata(pdev, channel);
>   phy_set_drvdata(channel->phy, channel);
>  
>   provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
> - if (IS_ERR(provider))
> + if (IS_ERR(provider)) {
>   dev_err(dev, "Failed to register PHY provider\n");
> + } else if (channel->has_otg) {
> + int ret;
> +
> + ret = device_create_file(dev, _attr_otg_inputs);
> + if (ret < 0)
> + return ret;
> + }
>  
>   return PTR_ERR_OR_ZERO(provider);
>  }
>  
> +static int rcar_gen3_phy_usb2_remove(struct platform_device *pdev)
> +{
> + struct rcar_gen3_chan *channel = platform_get_drvdata(pdev);
> +
> + if (channel->has_otg)
> + device_remove_file(>dev, _attr_otg_inputs);
> +
> + return 0;
> +};
> +
>  static struct platform_driver rcar_gen3_phy_usb2_driver = {
>   .driver = {
>   .name   = "phy_rcar_gen3_usb2",
>   .of_match_table = rcar_gen3_phy_usb2_match_table,
>   },
>   .probe  = rcar_gen3_phy_usb2_probe,
> + .remove = rcar_gen3_phy_usb2_remove,
>  };
>  module_platform_driver(rcar_gen3_phy_usb2_driver);
>  
> -- 
> 1.9.1
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-usb" in
> the body of a message to majord...@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 

Best Regards,
Peter Chen


RE: [PATCH 4/7] bus: arm-cci: add missing of_node_put after calling of_parse_phandle

2016-07-04 Thread Peter Chen
 
>
>On Fri, Jul 01, 2016 at 11:29:58AM +0100, Suzuki K Poulose wrote:
>> On 01/07/16 10:41, Peter Chen wrote:
>> >of_node_put needs to be called when the device node which is got from
>> >of_parse_phandle has finished using.
>> >
>> >Cc: Will Deacon <will.dea...@arm.com>
>> >Cc: Suzuki K Poulose <suzuki.poul...@arm.com>
>> >Signed-off-by: Peter Chen <peter.c...@nxp.com>
>>
>> Thanks for the fix.
>>
>> >---
>> >  drivers/bus/arm-cci.c | 5 -
>> >  1 file changed, 4 insertions(+), 1 deletion(-)
>> >
>> >diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c index
>> >a49b283..e7b0b8c 100644
>> >--- a/drivers/bus/arm-cci.c
>> >+++ b/drivers/bus/arm-cci.c
>> >@@ -1912,9 +1912,12 @@ static int __cci_ace_get_port(struct device_node *dn,
>int type)
>> >cci_portn = of_parse_phandle(dn, "cci-control-port", 0);
>> >for (i = 0; i < nb_cci_ports; i++) {
>> >ace_match = ports[i].type == type;
>> >-   if (ace_match && cci_portn == ports[i].dn)
>> >+   if (ace_match && cci_portn == ports[i].dn) {
>> >+   of_node_put(cci_portn);
>> >return i;
>> >+   }
>> >}
>> >+   of_node_put(cci_portn);
>>
>> nit: Could we please do some thing like this ?
>>  if (ace_match && cci_portn == ports[i].dn)
>>  break;
>>  }
>>
>>  of_node_put(cci_portn);
>>  return (i < nb_cci_ports) ? i : -ENODEV ;
>>
>> Either way,
>>
>> Reviewed-by: Suzuki K Poulose <suzuki.poul...@arm.com>
>
>Please route this via arm-soc once you've addressed Suzuki's comment.
>

Hi Will, how to route patch via arm-soc?

Does it mean sending patch by adding a...@kernel.org at To or Cc list?

Peter


RE: [PATCH 2/7] arm: mach-shmobile: pm-rmobile: add missing of_node_put after calling of_parse_phandle

2016-07-04 Thread Peter Chen
 
>On Fri, Jul 1, 2016 at 11:41 AM, Peter Chen <peter.c...@nxp.com> wrote:
>> of_node_put needs to be called when the device node which is got from
>> of_parse_phandle has finished using.
>>
>> Cc: Simon Horman <ho...@verge.net.au>
>> Cc: Magnus Damm <magnus.d...@gmail.com>
>> Signed-off-by: Peter Chen <peter.c...@nxp.com>
>
>NAKed-by: Geert Uytterhoeven <geert+rene...@glider.be>
>
>> --- a/arch/arm/mach-shmobile/pm-rmobile.c
>> +++ b/arch/arm/mach-shmobile/pm-rmobile.c
>> @@ -209,6 +209,7 @@ static void __init add_special_pd(struct device_node *np,
>enum pd_types type)
>> special_pds[num_special_pds].pd = pd;
>
>The pd pointer is stored in the line above, and released later in 
>put_special_pds().
>
>> special_pds[num_special_pds].type = type;
>> num_special_pds++;
>> +   of_node_put(pd);
>
>Hence it must not be released here, as that would cause a double release when
>put_special_pds() is executed.
>

Thanks, Geert, it is my careless.

Please forget this patch.

Peter


[PATCH 0/7] add missing of_node_put after calling of_parse_phandle (1st)

2016-07-01 Thread Peter Chen
Hi all,

of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using, but there are many codes
do not follow that, this patch set fixes some of them.

Peter Chen (7):
  extcon: add missing of_node_put after calling of_parse_phandle
  arm: mach-shmobile: pm-rmobile: add missing of_node_put after calling
of_parse_phandle
  arm: mach-u300: regulator: add missing of_node_put after calling
of_parse_phandle
  bus: arm-cci: add missing of_node_put after calling of_parse_phandle
  bus: vexpress-config: add missing of_node_put after calling
of_parse_phandle
  devfreq: add missing of_node_put after calling of_parse_phandle
  devfreq: exynos-bus: add missing of_node_put after calling
of_parse_phandle

 arch/arm/mach-shmobile/pm-rmobile.c |  1 +
 arch/arm/mach-u300/regulator.c  | 12 +---
 drivers/bus/arm-cci.c   |  5 -
 drivers/bus/vexpress-config.c   |  1 +
 drivers/devfreq/devfreq.c   |  2 ++
 drivers/devfreq/exynos-bus.c|  9 ++---
 drivers/extcon/extcon.c |  2 ++
 7 files changed, 25 insertions(+), 7 deletions(-)

-- 
1.9.1



[PATCH 5/7] bus: vexpress-config: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: Liviu Dudau <liviu.du...@arm.com>
Cc: Sudeep Holla <sudeep.ho...@arm.com>
Cc: Lorenzo Pieralisi <lorenzo.pieral...@arm.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 drivers/bus/vexpress-config.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/bus/vexpress-config.c b/drivers/bus/vexpress-config.c
index c3cb76b..9efdf1d 100644
--- a/drivers/bus/vexpress-config.c
+++ b/drivers/bus/vexpress-config.c
@@ -178,6 +178,7 @@ static int vexpress_config_populate(struct device_node 
*node)
 
parent = class_find_device(vexpress_config_class, NULL, bridge,
vexpress_config_node_match);
+   of_node_put(bridge);
if (WARN_ON(!parent))
return -ENODEV;
 
-- 
1.9.1



[PATCH 4/7] bus: arm-cci: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: Will Deacon <will.dea...@arm.com>
Cc: Suzuki K Poulose <suzuki.poul...@arm.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 drivers/bus/arm-cci.c | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
index a49b283..e7b0b8c 100644
--- a/drivers/bus/arm-cci.c
+++ b/drivers/bus/arm-cci.c
@@ -1912,9 +1912,12 @@ static int __cci_ace_get_port(struct device_node *dn, 
int type)
cci_portn = of_parse_phandle(dn, "cci-control-port", 0);
for (i = 0; i < nb_cci_ports; i++) {
ace_match = ports[i].type == type;
-   if (ace_match && cci_portn == ports[i].dn)
+   if (ace_match && cci_portn == ports[i].dn) {
+   of_node_put(cci_portn);
return i;
+   }
}
+   of_node_put(cci_portn);
return -ENODEV;
 }
 
-- 
1.9.1



[PATCH 2/7] arm: mach-shmobile: pm-rmobile: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: Simon Horman <ho...@verge.net.au>
Cc: Magnus Damm <magnus.d...@gmail.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 arch/arm/mach-shmobile/pm-rmobile.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/mach-shmobile/pm-rmobile.c 
b/arch/arm/mach-shmobile/pm-rmobile.c
index c0b05e9..8eb2cb6 100644
--- a/arch/arm/mach-shmobile/pm-rmobile.c
+++ b/arch/arm/mach-shmobile/pm-rmobile.c
@@ -209,6 +209,7 @@ static void __init add_special_pd(struct device_node *np, 
enum pd_types type)
special_pds[num_special_pds].pd = pd;
special_pds[num_special_pds].type = type;
num_special_pds++;
+   of_node_put(pd);
 }
 
 static void __init get_special_pds(void)
-- 
1.9.1



[PATCH 1/7] extcon: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: MyungJoo Ham <myungjoo@samsung.com>
Cc: Chanwoo Choi <cw00.c...@samsung.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 drivers/extcon/extcon.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 21a123c..86ea14d 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -1107,10 +1107,12 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct 
device *dev, int index)
list_for_each_entry(edev, _dev_list, entry) {
if (edev->dev.parent && edev->dev.parent->of_node == node) {
mutex_unlock(_dev_list_lock);
+   of_node_put(node);
return edev;
}
}
mutex_unlock(_dev_list_lock);
+   of_node_put(node);
 
return ERR_PTR(-EPROBE_DEFER);
 }
-- 
1.9.1



[PATCH 6/7] devfreq: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: MyungJoo Ham <myungjoo@samsung.com>
Cc: Kyungmin Park <kyungmin.p...@samsung.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 drivers/devfreq/devfreq.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
index 1d6c803..3f2142f 100644
--- a/drivers/devfreq/devfreq.c
+++ b/drivers/devfreq/devfreq.c
@@ -706,10 +706,12 @@ struct devfreq *devfreq_get_devfreq_by_phandle(struct 
device *dev, int index)
if (devfreq->dev.parent
&& devfreq->dev.parent->of_node == node) {
mutex_unlock(_list_lock);
+   of_node_put(node);
return devfreq;
}
}
mutex_unlock(_list_lock);
+   of_node_put(node);
 
return ERR_PTR(-EPROBE_DEFER);
 }
-- 
1.9.1



[PATCH 3/7] arm: mach-u300: regulator: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: Linus Walleij <linus.wall...@linaro.org>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 arch/arm/mach-u300/regulator.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/arch/arm/mach-u300/regulator.c b/arch/arm/mach-u300/regulator.c
index 595b574..509643e 100644
--- a/arch/arm/mach-u300/regulator.c
+++ b/arch/arm/mach-u300/regulator.c
@@ -71,19 +71,21 @@ static int __init __u300_init_boardpower(struct 
platform_device *pdev)
regmap = syscon_node_to_regmap(syscon_np);
if (IS_ERR(regmap)) {
pr_crit("U300: could not locate syscon regmap\n");
-   return PTR_ERR(regmap);
+   err = PTR_ERR(regmap);
+   goto error;
}
 
main_power_15 = regulator_get(>dev, "vana15");
 
if (IS_ERR(main_power_15)) {
pr_err("could not get vana15");
-   return PTR_ERR(main_power_15);
+   err = PTR_ERR(main_power_15);
+   goto error;
}
err = regulator_enable(main_power_15);
if (err) {
pr_err("could not enable vana15\n");
-   return err;
+   goto error;
}
 
/*
@@ -99,8 +101,12 @@ static int __init __u300_init_boardpower(struct 
platform_device *pdev)
 
/* Register globally exported PM poweroff hook */
pm_power_off = u300_pm_poweroff;
+   of_node_put(syscon_np);
 
return 0;
+error:
+   of_node_put(syscon_np);
+   return err;
 }
 
 static int __init s365_board_probe(struct platform_device *pdev)
-- 
1.9.1



[PATCH 7/7] devfreq: exynos-bus: add missing of_node_put after calling of_parse_phandle

2016-07-01 Thread Peter Chen
of_node_put needs to be called when the device node which is got
from of_parse_phandle has finished using.

Cc: Chanwoo Choi <cw00.c...@samsung.com>
Cc: MyungJoo Ham <myungjoo@samsung.com>
Cc: Kyungmin Park <kyungmin.p...@samsung.com>
Cc: Kukjin Kim <kg...@kernel.org>
Cc: Krzysztof Kozlowski <k.kozlow...@samsung.com>
Signed-off-by: Peter Chen <peter.c...@nxp.com>
---
 drivers/devfreq/exynos-bus.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/devfreq/exynos-bus.c b/drivers/devfreq/exynos-bus.c
index 2363d0a..a38b5ec 100644
--- a/drivers/devfreq/exynos-bus.c
+++ b/drivers/devfreq/exynos-bus.c
@@ -383,7 +383,7 @@ err_clk:
 static int exynos_bus_probe(struct platform_device *pdev)
 {
struct device *dev = >dev;
-   struct device_node *np = dev->of_node;
+   struct device_node *np = dev->of_node, node;
struct devfreq_dev_profile *profile;
struct devfreq_simple_ondemand_data *ondemand_data;
struct devfreq_passive_data *passive_data;
@@ -415,10 +415,13 @@ static int exynos_bus_probe(struct platform_device *pdev)
goto err;
}
 
-   if (of_parse_phandle(dev->of_node, "devfreq", 0))
+   node = of_parse_phandle(dev->of_node, "devfreq", 0);
+   if (node) {
+   of_node_put(node);
goto passive;
-   else
+   } else {
ret = exynos_bus_parent_parse_of(np, bus);
+   }
 
if (ret < 0)
goto err;
-- 
1.9.1