ehci-mxc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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/mx31-regs.h>
  22. #include <usb/ehci-fsl.h>
  23. #include <errno.h>
  24. #include "ehci.h"
  25. #include "ehci-core.h"
  26. #define USBCTRL_OTGBASE_OFFSET 0x600
  27. #define MX31_OTG_SIC_SHIFT 29
  28. #define MX31_OTG_SIC_MASK (0x3 << MX31_OTG_SIC_SHIFT)
  29. #define MX31_OTG_PM_BIT (1 << 24)
  30. #define MX31_H2_SIC_SHIFT 21
  31. #define MX31_H2_SIC_MASK (0x3 << MX31_H2_SIC_SHIFT)
  32. #define MX31_H2_PM_BIT (1 << 16)
  33. #define MX31_H2_DT_BIT (1 << 5)
  34. #define MX31_H1_SIC_SHIFT 13
  35. #define MX31_H1_SIC_MASK (0x3 << MX31_H1_SIC_SHIFT)
  36. #define MX31_H1_PM_BIT (1 << 8)
  37. #define MX31_H1_DT_BIT (1 << 4)
  38. static int mxc_set_usbcontrol(int port, unsigned int flags)
  39. {
  40. unsigned int v;
  41. #ifdef CONFIG_MX31
  42. v = readl(MX31_OTG_BASE_ADDR + USBCTRL_OTGBASE_OFFSET);
  43. switch (port) {
  44. case 0: /* OTG port */
  45. v &= ~(MX31_OTG_SIC_MASK | MX31_OTG_PM_BIT);
  46. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  47. << MX31_OTG_SIC_SHIFT;
  48. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  49. v |= MX31_OTG_PM_BIT;
  50. break;
  51. case 1: /* H1 port */
  52. v &= ~(MX31_H1_SIC_MASK | MX31_H1_PM_BIT |
  53. MX31_H1_DT_BIT);
  54. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  55. << MX31_H1_SIC_SHIFT;
  56. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  57. v |= MX31_H1_PM_BIT;
  58. if (!(flags & MXC_EHCI_TTL_ENABLED))
  59. v |= MX31_H1_DT_BIT;
  60. break;
  61. case 2: /* H2 port */
  62. v &= ~(MX31_H2_SIC_MASK | MX31_H2_PM_BIT |
  63. MX31_H2_DT_BIT);
  64. v |= (flags & MXC_EHCI_INTERFACE_MASK)
  65. << MX31_H2_SIC_SHIFT;
  66. if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
  67. v |= MX31_H2_PM_BIT;
  68. if (!(flags & MXC_EHCI_TTL_ENABLED))
  69. v |= MX31_H2_DT_BIT;
  70. break;
  71. default:
  72. return -EINVAL;
  73. }
  74. writel(v, MX31_OTG_BASE_ADDR +
  75. USBCTRL_OTGBASE_OFFSET);
  76. #endif
  77. return 0;
  78. }
  79. int ehci_hcd_init(void)
  80. {
  81. u32 tmp;
  82. struct usb_ehci *ehci;
  83. struct clock_control_regs *sc_regs =
  84. (struct clock_control_regs *)CCM_BASE;
  85. tmp = __raw_readl(&sc_regs->ccmr);
  86. __raw_writel(__raw_readl(&sc_regs->ccmr) | (1 << 9), &sc_regs->ccmr) ;
  87. udelay(80);
  88. /* Take USB2 */
  89. ehci = (struct usb_ehci *)(MX31_OTG_BASE_ADDR +
  90. (0x200 * CONFIG_MXC_USB_PORT));
  91. hccr = (struct ehci_hccr *)((uint32_t)&ehci->caplength);
  92. hcor = (struct ehci_hcor *)((uint32_t) hccr +
  93. HC_LENGTH(ehci_readl(&hccr->cr_capbase)));
  94. setbits_le32(&ehci->usbmode, CM_HOST);
  95. setbits_le32(&ehci->control, USB_EN);
  96. __raw_writel(CONFIG_MXC_USB_PORTSC, &ehci->portsc);
  97. mxc_set_usbcontrol(CONFIG_MXC_USB_PORT, CONFIG_MXC_USB_FLAGS);
  98. return 0;
  99. }
  100. /*
  101. * Destroy the appropriate control structures corresponding
  102. * the the EHCI host controller.
  103. */
  104. int ehci_hcd_stop(void)
  105. {
  106. return 0;
  107. }