ehci-mxc.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify it
  5. * under the terms of the GNU General Public License as published by the
  6. * Free Software Foundation; either version 2 of the License, or (at your
  7. * option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful, but
  10. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  12. * for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software Foundation,
  16. * Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. #include <common.h>
  19. #include <usb.h>
  20. #include <asm/io.h>
  21. #include <asm/arch/imx-regs.h>
  22. #include <usb/ehci-fsl.h>
  23. #include <errno.h>
  24. #include "ehci.h"
  25. #define USBCTRL_OTGBASE_OFFSET 0x600
  26. #ifdef CONFIG_MX25
  27. #define MX25_USB_CTRL_IP_PUE_DOWN_BIT (1<<6)
  28. #define MX25_USB_CTRL_HSTD_BIT (1<<5)
  29. #define MX25_USB_CTRL_USBTE_BIT (1<<4)
  30. #define MX25_USB_CTRL_OCPOL_OTG_BIT (1<<3)
  31. #endif
  32. #ifdef CONFIG_MX31
  33. #define MX31_OTG_SIC_SHIFT 29
  34. #define MX31_OTG_SIC_MASK (0x3 << MX31_OTG_SIC_SHIFT)
  35. #define MX31_OTG_PM_BIT (1 << 24)
  36. #define MX31_H2_SIC_SHIFT 21
  37. #define MX31_H2_SIC_MASK (0x3 << MX31_H2_SIC_SHIFT)
  38. #define MX31_H2_PM_BIT (1 << 16)
  39. #define MX31_H2_DT_BIT (1 << 5)
  40. #define MX31_H1_SIC_SHIFT 13
  41. #define MX31_H1_SIC_MASK (0x3 << MX31_H1_SIC_SHIFT)
  42. #define MX31_H1_PM_BIT (1 << 8)
  43. #define MX31_H1_DT_BIT (1 << 4)
  44. #endif
  45. static int mxc_set_usbcontrol(int port, unsigned int flags)
  46. {
  47. unsigned int v;
  48. #ifdef CONFIG_MX25
  49. v = MX25_USB_CTRL_IP_PUE_DOWN_BIT | MX25_USB_CTRL_HSTD_BIT |
  50. MX25_USB_CTRL_USBTE_BIT | MX25_USB_CTRL_OCPOL_OTG_BIT;
  51. #endif
  52. #ifdef CONFIG_MX31
  53. v = readl(IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
  54. switch (port) {
  55. case 0: /* OTG port */
  56. v &= ~(MX31_OTG_SIC_MASK | MX31_OTG_PM_BIT);
  57. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  58. << MX31_OTG_SIC_SHIFT;
  59. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  60. v |= MX31_OTG_PM_BIT;
  61. break;
  62. case 1: /* H1 port */
  63. v &= ~(MX31_H1_SIC_MASK | MX31_H1_PM_BIT |
  64. MX31_H1_DT_BIT);
  65. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  66. << MX31_H1_SIC_SHIFT;
  67. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  68. v |= MX31_H1_PM_BIT;
  69. if (!(flags & MXC_EHCI_TTL_ENABLED))
  70. v |= MX31_H1_DT_BIT;
  71. break;
  72. case 2: /* H2 port */
  73. v &= ~(MX31_H2_SIC_MASK | MX31_H2_PM_BIT |
  74. MX31_H2_DT_BIT);
  75. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  76. << MX31_H2_SIC_SHIFT;
  77. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  78. v |= MX31_H2_PM_BIT;
  79. if (!(flags & MXC_EHCI_TTL_ENABLED))
  80. v |= MX31_H2_DT_BIT;
  81. break;
  82. default:
  83. return -EINVAL;
  84. }
  85. #endif
  86. writel(v, IMX_USB_BASE + USBCTRL_OTGBASE_OFFSET);
  87. return 0;
  88. }
  89. int ehci_hcd_init(int index, struct ehci_hccr **hccr, struct ehci_hcor **hcor)
  90. {
  91. struct usb_ehci *ehci;
  92. #ifdef CONFIG_MX31
  93. struct clock_control_regs *sc_regs =
  94. (struct clock_control_regs *)CCM_BASE;
  95. __raw_readl(&sc_regs->ccmr);
  96. __raw_writel(__raw_readl(&sc_regs->ccmr) | (1 << 9), &sc_regs->ccmr) ;
  97. #endif
  98. udelay(80);
  99. ehci = (struct usb_ehci *)(IMX_USB_BASE +
  100. (0x200 * CONFIG_MXC_USB_PORT));
  101. *hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  102. *hcor = (struct ehci_hcor *)((uint32_t) *hccr +
  103. HC_LENGTH(ehci_readl(&(*hccr)->cr_capbase)));
  104. setbits_le32(&ehci->usbmode, CM_HOST);
  105. __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
  106. mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
  107. udelay(10000);
  108. return 0;
  109. }
  110. /*
  111. * Destroy the appropriate control structures corresponding
  112. * the the EHCI host controller.
  113. */
  114. int ehci_hcd_stop(int index)
  115. {
  116. return 0;
  117. }