ehci-atmel.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * (C) Copyright 2012
  3. * Atmel Semiconductor <www.atmel.com>
  4. * Written-by: Bo Shen <voice.shen@atmel.com>
  5. *
  6. * SPDX-License-Identifier: GPL-2.0+
  7. */
  8. #include <common.h>
  9. #include <watchdog.h>
  10. #include <usb.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/hardware.h>
  13. #include <asm/arch/at91_pmc.h>
  14. #include <asm/arch/clk.h>
  15. #include "ehci.h"
  16. /* Enable UTMI PLL time out 500us
  17. * 10 times as datasheet specified
  18. */
  19. #define EN_UPLL_TIMEOUT 500UL
  20. int ehci_hcd_init(int index, enum usb_init_type init,
  21. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  22. {
  23. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  24. ulong start_time, tmp_time;
  25. start_time = get_timer(0);
  26. /* Enable UTMI PLL */
  27. writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
  28. while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
  29. WATCHDOG_RESET();
  30. tmp_time = get_timer(0);
  31. if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
  32. printf("ERROR: failed to enable UPLL\n");
  33. return -1;
  34. }
  35. }
  36. /* Enable USB Host clock */
  37. writel(1 << ATMEL_ID_UHPHS, &pmc->pcer);
  38. *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
  39. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  40. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  41. return 0;
  42. }
  43. int ehci_hcd_stop(int index)
  44. {
  45. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  46. ulong start_time, tmp_time;
  47. /* Disable USB Host Clock */
  48. writel(1 << ATMEL_ID_UHPHS, &pmc->pcdr);
  49. start_time = get_timer(0);
  50. /* Disable UTMI PLL */
  51. writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
  52. while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
  53. WATCHDOG_RESET();
  54. tmp_time = get_timer(0);
  55. if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
  56. printf("ERROR: failed to stop UPLL\n");
  57. return -1;
  58. }
  59. }
  60. return 0;
  61. }