ehci-atmel.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * (C) Copyright 2012
  3. * Atmel Semiconductor <www.atmel.com>
  4. * Written-by: Bo Shen <voice.shen@atmel.com>
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  22. * MA 02110-1301 USA
  23. */
  24. #include <common.h>
  25. #include <watchdog.h>
  26. #include <usb.h>
  27. #include <asm/io.h>
  28. #include <asm/arch/hardware.h>
  29. #include <asm/arch/at91_pmc.h>
  30. #include <asm/arch/clk.h>
  31. #include "ehci.h"
  32. /* Enable UTMI PLL time out 500us
  33. * 10 times as datasheet specified
  34. */
  35. #define EN_UPLL_TIMEOUT 500UL
  36. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  37. {
  38. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  39. ulong start_time, tmp_time;
  40. start_time = get_timer(0);
  41. /* Enable UTMI PLL */
  42. writel(AT91_PMC_UPLLEN | AT91_PMC_BIASEN, &pmc->uckr);
  43. while ((readl(&pmc->sr) & AT91_PMC_LOCKU) != AT91_PMC_LOCKU) {
  44. WATCHDOG_RESET();
  45. tmp_time = get_timer(0);
  46. if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
  47. printf("ERROR: failed to enable UPLL\n");
  48. return -1;
  49. }
  50. }
  51. /* Enable USB Host clock */
  52. writel(1 << ATMEL_ID_UHPHS, &pmc->pcer);
  53. *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
  54. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  55. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  56. return 0;
  57. }
  58. int ehci_hcd_stop(int index)
  59. {
  60. at91_pmc_t *pmc = (at91_pmc_t *)ATMEL_BASE_PMC;
  61. ulong start_time, tmp_time;
  62. /* Disable USB Host Clock */
  63. writel(1 << ATMEL_ID_UHPHS, &pmc->pcdr);
  64. start_time = get_timer(0);
  65. /* Disable UTMI PLL */
  66. writel(readl(&pmc->uckr) & ~AT91_PMC_UPLLEN, &pmc->uckr);
  67. while ((readl(&pmc->sr) & AT91_PMC_LOCKU) == AT91_PMC_LOCKU) {
  68. WATCHDOG_RESET();
  69. tmp_time = get_timer(0);
  70. if ((tmp_time - start_time) > EN_UPLL_TIMEOUT) {
  71. printf("ERROR: failed to stop UPLL\n");
  72. return -1;
  73. }
  74. }
  75. return 0;
  76. }