Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: host: xhci: mvebu: make USB 3.0 PHY optional for Armada 3720

Older ATF does not provide SMC call for USB 3.0 phy power on functionality
and therefore initialization of xhci-hcd is failing when older version of
ATF is used. In this case phy_power_on() function returns -EOPNOTSUPP.

[ 3.108467] mvebu-a3700-comphy d0018300.phy: unsupported SMC call, try updating your firmware
[ 3.117250] phy phy-d0018300.phy.0: phy poweron failed --> -95
[ 3.123465] xhci-hcd: probe of d0058000.usb failed with error -95

This patch introduces a new plat_setup callback for xhci platform drivers
which is called prior calling usb_add_hcd() function. This function at its
beginning skips PHY init if hcd->skip_phy_initialization is set.

Current init_quirk callback for xhci platform drivers is called from
xhci_plat_setup() function which is called after chip reset completes.
It happens in the middle of the usb_add_hcd() function and therefore this
callback cannot be used for setting if PHY init should be skipped or not.

For Armada 3720 this patch introduce a new xhci_mvebu_a3700_plat_setup()
function configured as a xhci platform plat_setup callback. This new
function calls phy_power_on() and in case it returns -EOPNOTSUPP then
XHCI_SKIP_PHY_INIT quirk is set to instruct xhci-plat to skip PHY
initialization.

This patch fixes above failure by ignoring 'not supported' error in
xhci-hcd driver. In this case it is expected that phy is already power on.

It fixes initialization of xhci-hcd on Espressobin boards where is older
Marvell's Arm Trusted Firmware without SMC call for USB 3.0 phy power.

This is regression introduced in commit bd3d25b07342 ("arm64: dts: marvell:
armada-37xx: link USB hosts with their PHYs") where USB 3.0 phy was defined
and therefore xhci-hcd on Espressobin with older ATF started failing.

Fixes: bd3d25b07342 ("arm64: dts: marvell: armada-37xx: link USB hosts with their PHYs")
Cc: <stable@vger.kernel.org> # 5.1+: ea17a0f153af: phy: marvell: comphy: Convert internal SMCC firmware return codes to errno
Cc: <stable@vger.kernel.org> # 5.1+: f768e718911e: usb: host: xhci-plat: add priv quirk for skip PHY initialization
Tested-by: Tomasz Maciej Nowak <tmn505@gmail.com>
Tested-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> # On R-Car
Reviewed-by: Yoshihiro Shimoda <yoshihiro.shimoda.uh@renesas.com> # xhci-plat
Acked-by: Mathias Nyman <mathias.nyman@linux.intel.com>
Signed-off-by: Pali Rohár <pali@kernel.org>
Link: https://lore.kernel.org/r/20210201150803.7305-1-pali@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Pali Rohár and committed by
Greg Kroah-Hartman
3241929b a50ea34d

+68 -1
+42
drivers/usb/host/xhci-mvebu.c
··· 8 8 #include <linux/mbus.h> 9 9 #include <linux/of.h> 10 10 #include <linux/platform_device.h> 11 + #include <linux/phy/phy.h> 11 12 12 13 #include <linux/usb.h> 13 14 #include <linux/usb/hcd.h> ··· 71 70 * windows, and is therefore no longer useful. 72 71 */ 73 72 iounmap(base); 73 + 74 + return 0; 75 + } 76 + 77 + int xhci_mvebu_a3700_plat_setup(struct usb_hcd *hcd) 78 + { 79 + struct xhci_hcd *xhci = hcd_to_xhci(hcd); 80 + struct device *dev = hcd->self.controller; 81 + struct phy *phy; 82 + int ret; 83 + 84 + /* Old bindings miss the PHY handle */ 85 + phy = of_phy_get(dev->of_node, "usb3-phy"); 86 + if (IS_ERR(phy) && PTR_ERR(phy) == -EPROBE_DEFER) 87 + return -EPROBE_DEFER; 88 + else if (IS_ERR(phy)) 89 + goto phy_out; 90 + 91 + ret = phy_init(phy); 92 + if (ret) 93 + goto phy_put; 94 + 95 + ret = phy_set_mode(phy, PHY_MODE_USB_HOST_SS); 96 + if (ret) 97 + goto phy_exit; 98 + 99 + ret = phy_power_on(phy); 100 + if (ret == -EOPNOTSUPP) { 101 + /* Skip initializatin of XHCI PHY when it is unsupported by firmware */ 102 + dev_warn(dev, "PHY unsupported by firmware\n"); 103 + xhci->quirks |= XHCI_SKIP_PHY_INIT; 104 + } 105 + if (ret) 106 + goto phy_exit; 107 + 108 + phy_power_off(phy); 109 + phy_exit: 110 + phy_exit(phy); 111 + phy_put: 112 + of_phy_put(phy); 113 + phy_out: 74 114 75 115 return 0; 76 116 }
+6
drivers/usb/host/xhci-mvebu.h
··· 12 12 13 13 #if IS_ENABLED(CONFIG_USB_XHCI_MVEBU) 14 14 int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd); 15 + int xhci_mvebu_a3700_plat_setup(struct usb_hcd *hcd); 15 16 int xhci_mvebu_a3700_init_quirk(struct usb_hcd *hcd); 16 17 #else 17 18 static inline int xhci_mvebu_mbus_init_quirk(struct usb_hcd *hcd) 19 + { 20 + return 0; 21 + } 22 + 23 + static inline int xhci_mvebu_a3700_plat_setup(struct usb_hcd *hcd) 18 24 { 19 25 return 0; 20 26 }
+19 -1
drivers/usb/host/xhci-plat.c
··· 44 44 priv->plat_start(hcd); 45 45 } 46 46 47 + static int xhci_priv_plat_setup(struct usb_hcd *hcd) 48 + { 49 + struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); 50 + 51 + if (!priv->plat_setup) 52 + return 0; 53 + 54 + return priv->plat_setup(hcd); 55 + } 56 + 47 57 static int xhci_priv_init_quirk(struct usb_hcd *hcd) 48 58 { 49 59 struct xhci_plat_priv *priv = hcd_to_xhci_priv(hcd); ··· 121 111 }; 122 112 123 113 static const struct xhci_plat_priv xhci_plat_marvell_armada3700 = { 114 + .plat_setup = xhci_mvebu_a3700_plat_setup, 124 115 .init_quirk = xhci_mvebu_a3700_init_quirk, 125 116 }; 126 117 ··· 341 330 342 331 hcd->tpl_support = of_usb_host_tpl_support(sysdev->of_node); 343 332 xhci->shared_hcd->tpl_support = hcd->tpl_support; 344 - if (priv && (priv->quirks & XHCI_SKIP_PHY_INIT)) 333 + 334 + if (priv) { 335 + ret = xhci_priv_plat_setup(hcd); 336 + if (ret) 337 + goto disable_usb_phy; 338 + } 339 + 340 + if ((xhci->quirks & XHCI_SKIP_PHY_INIT) || (priv && (priv->quirks & XHCI_SKIP_PHY_INIT))) 345 341 hcd->skip_phy_initialization = 1; 346 342 347 343 if (priv && (priv->quirks & XHCI_SG_TRB_CACHE_SIZE_QUIRK))
+1
drivers/usb/host/xhci-plat.h
··· 13 13 struct xhci_plat_priv { 14 14 const char *firmware_name; 15 15 unsigned long long quirks; 16 + int (*plat_setup)(struct usb_hcd *); 16 17 void (*plat_start)(struct usb_hcd *); 17 18 int (*init_quirk)(struct usb_hcd *); 18 19 int (*suspend_quirk)(struct usb_hcd *);