public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Alexandre Bailon <abailon@baylibre.com>
To: david@lechnology.com, b-liu@ti.com, balbi@kernel.org
Cc: kishon@ti.com, khilman@baylibre.com,
	linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org,
	nsekhar@ti.com, Alexandre Bailon <abailon@baylibre.com>
Subject: [PATCH v3 4/5] phy: da8xx-usb: Use usb20_force_mode property to configure the phy mode
Date: Thu,  3 Nov 2016 16:26:04 +0100	[thread overview]
Message-ID: <1478186765-19840-5-git-send-email-abailon@baylibre.com> (raw)
In-Reply-To: <1478186765-19840-1-git-send-email-abailon@baylibre.com>

The USB PHY is able to operate in OTG, host or peripheral.
Some board may be wired to work act only as host or peripheral.
In such case, the dr_mode property of controller must be set to
host or peripheral. But doing that will also configure the PHY
in host or peripheral mode whereas OTG is able to detect which
role the USB controller should take.
The PHY's host or peripheral mode are actually only useful when
hardware doesn't allow OTG to detect it's role.

There is some issues when the PHY is forced in peripheral or host mode,
and it worth to let the PHY in OTG when that is possible.
Only force the PHY in a specific mode if usb20_force_mode is set in DT.

Signed-off-by: Alexandre Bailon <abailon@baylibre.com>
---
 drivers/phy/phy-da8xx-usb.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/phy/phy-da8xx-usb.c b/drivers/phy/phy-da8xx-usb.c
index fd39292..bf1b3af 100644
--- a/drivers/phy/phy-da8xx-usb.c
+++ b/drivers/phy/phy-da8xx-usb.c
@@ -22,6 +22,7 @@
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
+#include <linux/usb/of.h>
 
 struct da8xx_usb_phy {
 	struct phy_provider	*phy_provider;
@@ -109,6 +110,7 @@ static int da8xx_usb20_phy_set_mode(struct phy *phy, enum phy_mode mode)
 	case PHY_MODE_USB_DEVICE:	/* Force VBUS valid, ID = 1 */
 		val |= CFGCHIP2_OTGMODE_FORCE_DEVICE;
 		break;
+	case PHY_MODE_INVALID:
 	case PHY_MODE_USB_OTG:	/* Don't override the VBUS/ID comparators */
 		val |= CFGCHIP2_OTGMODE_NO_OVERRIDE |
 			CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN;
@@ -152,6 +154,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 	struct device		*dev = &pdev->dev;
 	struct device_node	*node = dev->of_node;
 	struct da8xx_usb_phy	*d_phy;
+	enum usb_dr_mode	dr_mode = PHY_MODE_INVALID;
 
 	d_phy = devm_kzalloc(dev, sizeof(*d_phy), GFP_KERNEL);
 	if (!d_phy)
@@ -202,6 +205,13 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 			dev_err(dev, "Failed to create phy provider\n");
 			return PTR_ERR(d_phy->phy_provider);
 		}
+
+		if (of_find_property(node, "usb20-force-mode", NULL)) {
+			dr_mode = of_usb_get_dr_mode_by_phy(node, 0);
+			if (dr_mode == USB_DR_MODE_UNKNOWN ||
+				dr_mode == USB_DR_MODE_OTG)
+				dev_warn(dev, "dr_mode is not properly set\n");
+		}
 	} else {
 		int ret;
 
@@ -213,6 +223,7 @@ static int da8xx_usb_phy_probe(struct platform_device *pdev)
 		if (ret)
 			dev_warn(dev, "Failed to create usb20 phy lookup\n");
 	}
+	da8xx_usb20_phy_set_mode(d_phy->usb20_phy, dr_mode);
 
 	return 0;
 }
-- 
2.7.3

  parent reply	other threads:[~2016-11-03 15:27 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-03 15:26 [PATCH v3 0/5] usb: musb: da8xx: Fix few issues Alexandre Bailon
2016-11-03 15:26 ` [PATCH v3 1/5] usb: musb: da8xx: Call earlier clk_prepare_enable() Alexandre Bailon
2016-11-03 15:26 ` [PATCH v3 2/5] phy: da8xx-usb: Configure CFGCHIP2 to support OTG workaround Alexandre Bailon
2016-11-03 17:00   ` David Lechner
2016-11-03 15:26 ` [PATCH v3 3/5] dt/bindings: Add a new property to DA8xx USB PHY Alexandre Bailon
2016-11-03 16:34   ` Kishon Vijay Abraham I
2016-11-03 17:26     ` Alexandre Bailon
2016-11-03 17:50       ` Kishon Vijay Abraham I
2016-11-04 11:07         ` Alexandre Bailon
2016-11-03 16:53   ` David Lechner
2016-11-03 17:33     ` Alexandre Bailon
2016-11-03 17:53       ` David Lechner
2016-11-03 15:26 ` Alexandre Bailon [this message]
2016-11-03 15:26 ` [PATCH v3 5/5] usb: musb: da8xx: Remove set_mode callback Alexandre Bailon
2016-11-03 17:18   ` David Lechner
2016-11-03 17:27     ` Bin Liu
2016-11-03 17:42       ` Alexandre Bailon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1478186765-19840-5-git-send-email-abailon@baylibre.com \
    --to=abailon@baylibre.com \
    --cc=b-liu@ti.com \
    --cc=balbi@kernel.org \
    --cc=david@lechnology.com \
    --cc=khilman@baylibre.com \
    --cc=kishon@ti.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nsekhar@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox