ehci-atmel.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #ifdef CPU_HAS_PCR
  38. at91_periph_clk_enable(ATMEL_ID_UHPHS);
  39. #else
  40. writel(1 << ATMEL_ID_UHPHS, &pmc->pcer);
  41. #endif
  42. *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
  43. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  44. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  45. return 0;
  46. }
  47. int ehci_hcd_stop(int index)
  48. {
  49. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  50. ulong start_time, tmp_time;
  51. /* Disable USB Host Clock */
  52. #ifdef CPU_HAS_PCR
  53. at91_periph_clk_disable(ATMEL_ID_UHPHS);
  54. #else
  55. writel(1 << ATMEL_ID_UHPHS, &pmc->pcdr);
  56. #endif
  57. start_time = get_timer(0);
  58. /* Disable UTMI PLL */
  59. writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
  60. while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
  61. WATCHDOG_RESET();
  62. tmp_time = get_timer(0);
  63. if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
  64. printf("ERROR: failed to stop UPLL\n");
  65. return -1;
  66. }
  67. }
  68. return 0;
  69. }