phy.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * (C) Copyright 2007-2008
  3. * Stelian Pop <stelian@popies.net>
  4. * Lead Tech Design <www.leadtechdesign.com>
  5. *
  6. * (C) Copyright 2012
  7. * Markus Hubig <mhubig@imko.de>
  8. * IMKO GmbH <www.imko.de>
  9. *
  10. * Copyright (C) 2013 DENX Software Engineering, hs@denx.de
  11. *
  12. * SPDX-License-Identifier: GPL-2.0+
  13. */
  14. #include <common.h>
  15. #include <asm/io.h>
  16. #include <linux/sizes.h>
  17. #include <asm/arch/at91_rstc.h>
  18. #include <watchdog.h>
  19. void at91_phy_reset(void)
  20. {
  21. unsigned long erstl;
  22. unsigned long start = get_timer(0);
  23. unsigned long const timeout = 1000; /* 1000ms */
  24. at91_rstc_t *rstc = (at91_rstc_t *)ATMEL_BASE_RSTC;
  25. erstl = readl(&rstc->mr) & AT91_RSTC_MR_ERSTL_MASK;
  26. /*
  27. * Need to reset PHY -> 500ms reset
  28. * Reset PHY by pulling the NRST line for 500ms to low. To do so
  29. * disable user reset for low level on NRST pin and poll the NRST
  30. * level in reset status register.
  31. */
  32. writel(AT91_RSTC_KEY | AT91_RSTC_MR_ERSTL(0x0D) |
  33. AT91_RSTC_MR_URSTEN, &rstc->mr);
  34. writel(AT91_RSTC_KEY | AT91_RSTC_CR_EXTRST, &rstc->cr);
  35. /* Wait for end of hardware reset */
  36. while (!(readl(&rstc->sr) & AT91_RSTC_SR_NRSTL)) {
  37. /* avoid shutdown by watchdog */
  38. WATCHDOG_RESET();
  39. mdelay(10);
  40. /* timeout for not getting stuck in an endless loop */
  41. if (get_timer(start) >= timeout) {
  42. puts("*** ERROR: Timeout waiting for PHY reset!\n");
  43. break;
  44. }
  45. };
  46. /* Restore NRST value */
  47. writel(AT91_RSTC_KEY | erstl | AT91_RSTC_MR_URSTEN, &rstc->mr);
  48. }