phy-da8xx-usb.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Based on the DA8xx "glue layer" code.
  4. * Copyright (c) 2008-2019, MontaVista Software, Inc. <source@mvista.com>
  5. *
  6. * DT support added by: Adam Ford <aford173@gmail.com>
  7. */
  8. #include <common.h>
  9. #include <dm.h>
  10. #include <log.h>
  11. #include <dm/device-internal.h>
  12. #include <dm/lists.h>
  13. #include <asm/arch/hardware.h>
  14. #include <asm/arch/da8xx-usb.h>
  15. #include <asm/io.h>
  16. #include <generic-phy.h>
  17. static int da8xx_usb_phy_power_on(struct phy *phy)
  18. {
  19. unsigned long timeout;
  20. clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
  21. CFGCHIP2_RESET | CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN |
  22. CFGCHIP2_OTGMODE | CFGCHIP2_REFFREQ,
  23. CFGCHIP2_SESENDEN | CFGCHIP2_VBDTCTEN |
  24. CFGCHIP2_PHY_PLLON | CFGCHIP2_REFFREQ_24MHZ);
  25. /* wait until the usb phy pll locks */
  26. timeout = get_timer(0);
  27. while (get_timer(timeout) < 10) {
  28. if (readl(&davinci_syscfg_regs->cfgchip2) & CFGCHIP2_PHYCLKGD)
  29. return 0;
  30. }
  31. debug("Phy was not turned on\n");
  32. return -ENODEV;
  33. }
  34. static int da8xx_usb_phy_power_off(struct phy *phy)
  35. {
  36. clrsetbits_le32(&davinci_syscfg_regs->cfgchip2,
  37. CFGCHIP2_PHY_PLLON,
  38. CFGCHIP2_PHYPWRDN | CFGCHIP2_OTGPWRDN);
  39. return 0;
  40. }
  41. static const struct udevice_id da8xx_phy_ids[] = {
  42. { .compatible = "ti,da830-usb-phy" },
  43. { }
  44. };
  45. static struct phy_ops da8xx_phy_ops = {
  46. .power_on = da8xx_usb_phy_power_on,
  47. .power_off = da8xx_usb_phy_power_off,
  48. };
  49. U_BOOT_DRIVER(da8xx_phy) = {
  50. .name = "da8xx-usb-phy",
  51. .id = UCLASS_PHY,
  52. .of_match = da8xx_phy_ids,
  53. .ops = &da8xx_phy_ops,
  54. };