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

usb: tegra: Move utmi-pads reset from ehci-tegra to tegra-phy

UTMI pads are shared by USB controllers and reset of UTMI pads is shared
with the reset of USB1 controller. Currently reset of UTMI pads is done by
the EHCI driver and ChipIdea UDC works because EHCI driver always happen
to be probed first. Move reset controls from ehci-tegra to tegra-phy in
order to resolve the problem.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Dmitry Osipenko and committed by
Greg Kroah-Hartman
14347036 f59cd940

+117 -55
+41 -50
drivers/usb/host/ehci-tegra.c
··· 36 36 #define DRV_NAME "tegra-ehci" 37 37 38 38 static struct hc_driver __read_mostly tegra_ehci_hc_driver; 39 - static bool usb1_reset_attempted; 40 39 41 40 struct tegra_ehci_soc_config { 42 41 bool has_hostpc; ··· 50 51 enum tegra_usb_phy_port_speed port_speed; 51 52 }; 52 53 53 - /* 54 - * The 1st USB controller contains some UTMI pad registers that are global for 55 - * all the controllers on the chip. Those registers are also cleared when 56 - * reset is asserted to the 1st controller. This means that the 1st controller 57 - * can only be reset when no other controlled has finished probing. So we'll 58 - * reset the 1st controller before doing any other setup on any of the 59 - * controllers, and then never again. 60 - * 61 - * Since this is a PHY issue, the Tegra PHY driver should probably be doing 62 - * the resetting of the USB controllers. But to keep compatibility with old 63 - * device trees that don't have reset phandles in the PHYs, do it here. 64 - * Those old DTs will be vulnerable to total USB breakage if the 1st EHCI 65 - * device isn't the first one to finish probing, so warn them. 66 - */ 67 54 static int tegra_reset_usb_controller(struct platform_device *pdev) 68 55 { 69 56 struct device_node *phy_np; 70 57 struct usb_hcd *hcd = platform_get_drvdata(pdev); 71 58 struct tegra_ehci_hcd *tegra = 72 59 (struct tegra_ehci_hcd *)hcd_to_ehci(hcd)->priv; 73 - bool has_utmi_pad_registers = false; 60 + struct reset_control *rst; 61 + int err; 74 62 75 63 phy_np = of_parse_phandle(pdev->dev.of_node, "nvidia,phy", 0); 76 64 if (!phy_np) 77 65 return -ENOENT; 78 66 79 - if (of_property_read_bool(phy_np, "nvidia,has-utmi-pad-registers")) 80 - has_utmi_pad_registers = true; 81 - 82 - if (!usb1_reset_attempted) { 83 - struct reset_control *usb1_reset; 84 - 85 - if (!has_utmi_pad_registers) 86 - usb1_reset = of_reset_control_get(phy_np, "utmi-pads"); 87 - else 88 - usb1_reset = tegra->rst; 89 - 90 - if (IS_ERR(usb1_reset)) { 91 - dev_warn(&pdev->dev, 92 - "can't get utmi-pads reset from the PHY\n"); 93 - dev_warn(&pdev->dev, 94 - "continuing, but please update your DT\n"); 95 - } else { 96 - reset_control_assert(usb1_reset); 97 - udelay(1); 98 - reset_control_deassert(usb1_reset); 99 - 100 - if (!has_utmi_pad_registers) 101 - reset_control_put(usb1_reset); 102 - } 103 - 104 - usb1_reset_attempted = true; 105 - } 106 - 107 - if (!has_utmi_pad_registers) { 108 - reset_control_assert(tegra->rst); 109 - udelay(1); 110 - reset_control_deassert(tegra->rst); 67 + /* 68 + * The 1st USB controller contains some UTMI pad registers that are 69 + * global for all the controllers on the chip. Those registers are 70 + * also cleared when reset is asserted to the 1st controller. 71 + */ 72 + rst = of_reset_control_get_shared(phy_np, "utmi-pads"); 73 + if (IS_ERR(rst)) { 74 + dev_warn(&pdev->dev, 75 + "can't get utmi-pads reset from the PHY\n"); 76 + dev_warn(&pdev->dev, 77 + "continuing, but please update your DT\n"); 78 + } else { 79 + /* 80 + * PHY driver performs UTMI-pads reset in a case of 81 + * non-legacy DT. 82 + */ 83 + reset_control_put(rst); 111 84 } 112 85 113 86 of_node_put(phy_np); 87 + 88 + /* reset control is shared, hence initialize it first */ 89 + err = reset_control_deassert(tegra->rst); 90 + if (err) 91 + return err; 92 + 93 + err = reset_control_assert(tegra->rst); 94 + if (err) 95 + return err; 96 + 97 + udelay(1); 98 + 99 + err = reset_control_deassert(tegra->rst); 100 + if (err) 101 + return err; 114 102 115 103 return 0; 116 104 } ··· 426 440 goto cleanup_hcd_create; 427 441 } 428 442 429 - tegra->rst = devm_reset_control_get(&pdev->dev, "usb"); 443 + tegra->rst = devm_reset_control_get_shared(&pdev->dev, "usb"); 430 444 if (IS_ERR(tegra->rst)) { 431 445 dev_err(&pdev->dev, "Can't get ehci reset\n"); 432 446 err = PTR_ERR(tegra->rst); ··· 438 452 goto cleanup_hcd_create; 439 453 440 454 err = tegra_reset_usb_controller(pdev); 441 - if (err) 455 + if (err) { 456 + dev_err(&pdev->dev, "Failed to reset controller\n"); 442 457 goto cleanup_clk_en; 458 + } 443 459 444 460 u_phy = devm_usb_get_phy_by_phandle(&pdev->dev, "nvidia,phy", 0); 445 461 if (IS_ERR(u_phy)) { ··· 525 537 526 538 usb_phy_shutdown(hcd->usb_phy); 527 539 usb_remove_hcd(hcd); 540 + 541 + reset_control_assert(tegra->rst); 542 + udelay(1); 528 543 529 544 clk_disable_unprepare(tegra->clk); 530 545
+74 -5
drivers/usb/phy/phy-tegra-usb.c
··· 236 236 237 237 static int utmip_pad_open(struct tegra_usb_phy *phy) 238 238 { 239 - int err; 239 + int ret; 240 240 241 241 phy->pad_clk = devm_clk_get(phy->u_phy.dev, "utmi-pads"); 242 242 if (IS_ERR(phy->pad_clk)) { 243 - err = PTR_ERR(phy->pad_clk); 243 + ret = PTR_ERR(phy->pad_clk); 244 244 dev_err(phy->u_phy.dev, 245 - "Failed to get UTMIP pad clock: %d\n", err); 246 - return err; 245 + "Failed to get UTMIP pad clock: %d\n", ret); 246 + return ret; 247 247 } 248 248 249 - return 0; 249 + phy->pad_rst = devm_reset_control_get_optional_shared( 250 + phy->u_phy.dev, "utmi-pads"); 251 + if (IS_ERR(phy->pad_rst)) { 252 + ret = PTR_ERR(phy->pad_rst); 253 + dev_err(phy->u_phy.dev, 254 + "Failed to get UTMI-pads reset: %d\n", ret); 255 + return ret; 256 + } 257 + 258 + ret = clk_prepare_enable(phy->pad_clk); 259 + if (ret) { 260 + dev_err(phy->u_phy.dev, 261 + "Failed to enable UTMI-pads clock: %d\n", ret); 262 + return ret; 263 + } 264 + 265 + spin_lock(&utmip_pad_lock); 266 + 267 + ret = reset_control_deassert(phy->pad_rst); 268 + if (ret) { 269 + dev_err(phy->u_phy.dev, 270 + "Failed to initialize UTMI-pads reset: %d\n", ret); 271 + goto unlock; 272 + } 273 + 274 + ret = reset_control_assert(phy->pad_rst); 275 + if (ret) { 276 + dev_err(phy->u_phy.dev, 277 + "Failed to assert UTMI-pads reset: %d\n", ret); 278 + goto unlock; 279 + } 280 + 281 + udelay(1); 282 + 283 + ret = reset_control_deassert(phy->pad_rst); 284 + if (ret) 285 + dev_err(phy->u_phy.dev, 286 + "Failed to deassert UTMI-pads reset: %d\n", ret); 287 + unlock: 288 + spin_unlock(&utmip_pad_lock); 289 + 290 + clk_disable_unprepare(phy->pad_clk); 291 + 292 + return ret; 293 + } 294 + 295 + static int utmip_pad_close(struct tegra_usb_phy *phy) 296 + { 297 + int ret; 298 + 299 + ret = clk_prepare_enable(phy->pad_clk); 300 + if (ret) { 301 + dev_err(phy->u_phy.dev, 302 + "Failed to enable UTMI-pads clock: %d\n", ret); 303 + return ret; 304 + } 305 + 306 + ret = reset_control_assert(phy->pad_rst); 307 + if (ret) 308 + dev_err(phy->u_phy.dev, 309 + "Failed to assert UTMI-pads reset: %d\n", ret); 310 + 311 + udelay(1); 312 + 313 + clk_disable_unprepare(phy->pad_clk); 314 + 315 + return ret; 250 316 } 251 317 252 318 static void utmip_pad_power_on(struct tegra_usb_phy *phy) ··· 765 699 { 766 700 if (!IS_ERR(phy->vbus)) 767 701 regulator_disable(phy->vbus); 702 + 703 + if (!phy->is_ulpi_phy) 704 + utmip_pad_close(phy); 768 705 769 706 clk_disable_unprepare(phy->pll_u); 770 707 }
+2
include/linux/usb/tegra_usb_phy.h
··· 17 17 #define __TEGRA_USB_PHY_H 18 18 19 19 #include <linux/clk.h> 20 + #include <linux/reset.h> 20 21 #include <linux/usb/otg.h> 21 22 22 23 /* ··· 77 76 bool is_legacy_phy; 78 77 bool is_ulpi_phy; 79 78 int reset_gpio; 79 + struct reset_control *pad_rst; 80 80 }; 81 81 82 82 void tegra_usb_phy_preresume(struct usb_phy *phy);