keystone-usb-phy.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Texas Instruments Incorporated - http://www.ti.com/
  4. * Written by Jean-Jacques Hiblot <jjhiblot@ti.com>
  5. */
  6. #include <common.h>
  7. #include <dm.h>
  8. #include <log.h>
  9. #include <dm/device.h>
  10. #include <generic-phy.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/psc_defs.h>
  13. #include <linux/bitops.h>
  14. #include <linux/delay.h>
  15. /* USB PHY control register offsets */
  16. #define USB_PHY_CTL_UTMI 0x0000
  17. #define USB_PHY_CTL_PIPE 0x0004
  18. #define USB_PHY_CTL_PARAM_1 0x0008
  19. #define USB_PHY_CTL_PARAM_2 0x000c
  20. #define USB_PHY_CTL_CLOCK 0x0010
  21. #define USB_PHY_CTL_PLL 0x0014
  22. #define PHY_OTG_VBUSVLDECTSEL BIT(16)
  23. #define PHY_REF_SSP_EN BIT(29)
  24. struct keystone_usb_phy {
  25. u32 psc_domain;
  26. void __iomem *reg;
  27. };
  28. static int keystone_usb_init(struct phy *phy)
  29. {
  30. u32 val;
  31. int rc;
  32. struct udevice *dev = phy->dev;
  33. struct keystone_usb_phy *keystone = dev_get_priv(dev);
  34. /* Release USB from reset */
  35. rc = psc_enable_module(keystone->psc_domain);
  36. if (rc) {
  37. debug("Cannot enable USB module");
  38. return -rc;
  39. }
  40. mdelay(10);
  41. /*
  42. * VBUSVLDEXTSEL has a default value of 1 in BootCfg but shouldn't.
  43. * It should always be cleared because our USB PHY has an onchip VBUS
  44. * analog comparator.
  45. */
  46. val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
  47. /* quit selecting the vbusvldextsel by default! */
  48. val &= ~PHY_OTG_VBUSVLDECTSEL;
  49. writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
  50. return 0;
  51. }
  52. static int keystone_usb_power_on(struct phy *phy)
  53. {
  54. u32 val;
  55. struct udevice *dev = phy->dev;
  56. struct keystone_usb_phy *keystone = dev_get_priv(dev);
  57. val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
  58. val |= PHY_REF_SSP_EN;
  59. writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
  60. return 0;
  61. }
  62. static int keystone_usb_power_off(struct phy *phy)
  63. {
  64. u32 val;
  65. struct udevice *dev = phy->dev;
  66. struct keystone_usb_phy *keystone = dev_get_priv(dev);
  67. val = readl(keystone->reg + USB_PHY_CTL_CLOCK);
  68. val &= ~PHY_REF_SSP_EN;
  69. writel(val, keystone->reg + USB_PHY_CTL_CLOCK);
  70. return 0;
  71. }
  72. static int keystone_usb_exit(struct phy *phy)
  73. {
  74. struct udevice *dev = phy->dev;
  75. struct keystone_usb_phy *keystone = dev_get_priv(dev);
  76. if (psc_disable_module(keystone->psc_domain))
  77. debug("failed to disable USB module!\n");
  78. return 0;
  79. }
  80. static int keystone_usb_phy_probe(struct udevice *dev)
  81. {
  82. int rc;
  83. struct keystone_usb_phy *keystone = dev_get_priv(dev);
  84. rc = dev_read_u32(dev, "psc-domain", &keystone->psc_domain);
  85. if (rc)
  86. return rc;
  87. keystone->reg = dev_remap_addr_index(dev, 0);
  88. if (!keystone->reg) {
  89. pr_err("unable to remap usb phy\n");
  90. return -EINVAL;
  91. }
  92. return 0;
  93. }
  94. static const struct udevice_id keystone_usb_phy_ids[] = {
  95. { .compatible = "ti,keystone-usbphy" },
  96. { }
  97. };
  98. static struct phy_ops keystone_usb_phy_ops = {
  99. .init = keystone_usb_init,
  100. .power_on = keystone_usb_power_on,
  101. .power_off = keystone_usb_power_off,
  102. .exit = keystone_usb_exit,
  103. };
  104. U_BOOT_DRIVER(keystone_usb_phy) = {
  105. .name = "keystone_usb_phy",
  106. .id = UCLASS_PHY,
  107. .of_match = keystone_usb_phy_ids,
  108. .ops = &keystone_usb_phy_ops,
  109. .probe = keystone_usb_phy_probe,
  110. .priv_auto = sizeof(struct keystone_usb_phy),
  111. };