msm8916-usbh-phy.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2018 Ramon Fried <ramon.fried@gmail.com>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <generic-phy.h>
  8. #include <linux/bitops.h>
  9. #include <usb/ehci-ci.h>
  10. #include <usb/ulpi.h>
  11. #include <asm/io.h>
  12. /* PHY viewport regs */
  13. #define ULPI_MISC_A_READ 0x96
  14. #define ULPI_MISC_A_SET 0x97
  15. #define ULPI_MISC_A_CLEAR 0x98
  16. #define ULPI_MISC_A_VBUSVLDEXT BIT(0)
  17. #define ULPI_MISC_A_VBUSVLDEXTSEL BIT(1)
  18. #define GEN2_SESS_VLD_CTRL_EN BIT(7)
  19. #define SESS_VLD_CTRL BIT(25)
  20. struct msm_phy_priv {
  21. void __iomem *regs;
  22. struct usb_ehci *ehci; /* Start of IP core*/
  23. struct ulpi_viewport ulpi_vp; /* ULPI Viewport */
  24. };
  25. static int msm_phy_power_on(struct phy *phy)
  26. {
  27. struct msm_phy_priv *priv = dev_get_priv(phy->dev);
  28. /* Select and enable external configuration with USB PHY */
  29. ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_SET,
  30. ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
  31. return 0;
  32. }
  33. static int msm_phy_power_off(struct phy *phy)
  34. {
  35. struct msm_phy_priv *priv = dev_get_priv(phy->dev);
  36. /* Disable VBUS mimicing in the controller. */
  37. ulpi_write(&priv->ulpi_vp, (u8 *)ULPI_MISC_A_CLEAR,
  38. ULPI_MISC_A_VBUSVLDEXTSEL | ULPI_MISC_A_VBUSVLDEXT);
  39. return 0;
  40. }
  41. static int msm_phy_reset(struct phy *phy)
  42. {
  43. struct msm_phy_priv *p = dev_get_priv(phy->dev);
  44. /* select ULPI phy */
  45. writel(PORT_PTS_ULPI, &p->ehci->portsc);
  46. /* Enable sess_vld */
  47. setbits_le32(&p->ehci->genconfig2, GEN2_SESS_VLD_CTRL_EN);
  48. /* Enable external vbus configuration in the LINK */
  49. setbits_le32(&p->ehci->usbcmd, SESS_VLD_CTRL);
  50. /* USB_OTG_HS_AHB_BURST */
  51. writel(0x0, &p->ehci->sbuscfg);
  52. /* USB_OTG_HS_AHB_MODE: HPROT_MODE */
  53. /* Bus access related config. */
  54. writel(0x08, &p->ehci->sbusmode);
  55. return 0;
  56. }
  57. static int msm_phy_probe(struct udevice *dev)
  58. {
  59. struct msm_phy_priv *priv = dev_get_priv(dev);
  60. priv->regs = dev_remap_addr(dev);
  61. if (!priv->regs)
  62. return -EINVAL;
  63. priv->ehci = (struct usb_ehci *)priv->regs;
  64. priv->ulpi_vp.port_num = 0;
  65. /* Warning: this will not work if viewport address is > 64 bit due to
  66. * ULPI design.
  67. */
  68. priv->ulpi_vp.viewport_addr = (phys_addr_t)&priv->ehci->ulpi_viewpoint;
  69. return 0;
  70. }
  71. static struct phy_ops msm_phy_ops = {
  72. .power_on = msm_phy_power_on,
  73. .power_off = msm_phy_power_off,
  74. .reset = msm_phy_reset,
  75. };
  76. static const struct udevice_id msm_phy_ids[] = {
  77. { .compatible = "qcom,apq8016-usbphy" },
  78. { }
  79. };
  80. U_BOOT_DRIVER(msm8916_usbphy) = {
  81. .name = "msm8916_usbphy",
  82. .id = UCLASS_PHY,
  83. .of_match = msm_phy_ids,
  84. .ops = &msm_phy_ops,
  85. .probe = msm_phy_probe,
  86. .priv_auto = sizeof(struct msm_phy_priv),
  87. };