ehci-atmel.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2012
  4. * Atmel Semiconductor <www.atmel.com>
  5. * Written-by: Bo Shen <voice.shen@atmel.com>
  6. */
  7. #include <common.h>
  8. #include <clk.h>
  9. #include <dm.h>
  10. #include <malloc.h>
  11. #include <usb.h>
  12. #include <asm/io.h>
  13. #include <asm/arch/clk.h>
  14. #include "ehci.h"
  15. #if !CONFIG_IS_ENABLED(DM_USB)
  16. int ehci_hcd_init(int index, enum usb_init_type init,
  17. struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  18. {
  19. /* Enable UTMI PLL */
  20. if (at91_upll_clk_enable())
  21. return -1;
  22. /* Enable USB Host clock */
  23. at91_periph_clk_enable(ATMEL_ID_UHPHS);
  24. *hccr = (struct ehci_hccr *)ATMEL_BASE_EHCI;
  25. *hcor = (struct ehci_hcor *)((uint32_t)*hccr +
  26. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  27. return 0;
  28. }
  29. int ehci_hcd_stop(int index)
  30. {
  31. /* Disable USB Host Clock */
  32. at91_periph_clk_disable(ATMEL_ID_UHPHS);
  33. /* Disable UTMI PLL */
  34. if (at91_upll_clk_disable())
  35. return -1;
  36. return 0;
  37. }
  38. #else
  39. struct ehci_atmel_priv {
  40. struct ehci_ctrl ehci;
  41. };
  42. static int ehci_atmel_enable_clk(struct udevice *dev)
  43. {
  44. struct clk clk;
  45. int ret;
  46. ret = clk_get_by_index(dev, 0, &clk);
  47. if (ret)
  48. return ret;
  49. ret = clk_enable(&clk);
  50. if (ret)
  51. return ret;
  52. ret = clk_get_by_index(dev, 1, &clk);
  53. if (ret)
  54. return -EINVAL;
  55. ret = clk_enable(&clk);
  56. if (ret)
  57. return ret;
  58. clk_free(&clk);
  59. return 0;
  60. }
  61. static int ehci_atmel_probe(struct udevice *dev)
  62. {
  63. struct ehci_hccr *hccr;
  64. struct ehci_hcor *hcor;
  65. fdt_addr_t hcd_base;
  66. int ret;
  67. ret = ehci_atmel_enable_clk(dev);
  68. if (ret) {
  69. debug("Failed to enable USB Host clock\n");
  70. return ret;
  71. }
  72. /*
  73. * Get the base address for EHCI controller from the device node
  74. */
  75. hcd_base = devfdt_get_addr(dev);
  76. if (hcd_base == FDT_ADDR_T_NONE) {
  77. debug("Can't get the EHCI register base address\n");
  78. return -ENXIO;
  79. }
  80. hccr = (struct ehci_hccr *)hcd_base;
  81. hcor = (struct ehci_hcor *)
  82. ((u32)hccr + HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  83. debug("echi-atmel: init hccr %x and hcor %x hc_length %d\n",
  84. (u32)hccr, (u32)hcor,
  85. (u32)HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  86. return ehci_register(dev, hccr, hcor, NULL, 0, USB_INIT_HOST);
  87. }
  88. static const struct udevice_id ehci_usb_ids[] = {
  89. { .compatible = "atmel,at91sam9g45-ehci", },
  90. { }
  91. };
  92. U_BOOT_DRIVER(ehci_atmel) = {
  93. .name = "ehci_atmel",
  94. .id = UCLASS_USB,
  95. .of_match = ehci_usb_ids,
  96. .probe = ehci_atmel_probe,
  97. .remove = ehci_deregister,
  98. .ops = &ehci_usb_ops,
  99. .platdata_auto_alloc_size = sizeof(struct usb_platdata),
  100. .priv_auto_alloc_size = sizeof(struct ehci_atmel_priv),
  101. .flags = DM_FLAG_ALLOC_PRIV_DMA,
  102. };
  103. #endif