Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758240AbcKCP1Y (ORCPT ); Thu, 3 Nov 2016 11:27:24 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:35223 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758115AbcKCP0Q (ORCPT ); Thu, 3 Nov 2016 11:26:16 -0400 From: Alexandre Bailon 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 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 Message-Id: <1478186765-19840-5-git-send-email-abailon@baylibre.com> X-Mailer: git-send-email 2.7.3 In-Reply-To: <1478186765-19840-1-git-send-email-abailon@baylibre.com> References: <1478186765-19840-1-git-send-email-abailon@baylibre.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2554 Lines: 70 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 --- 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 #include #include +#include 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