ehci-imx5.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. /*
  2. * Copyright (c) 2009 Daniel Mack <daniel@caiaq.de>
  3. * Copyright (C) 2010 Freescale Semiconductor, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  12. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  13. * for more details.
  14. */
  15. #include <linux/platform_device.h>
  16. #include <linux/io.h>
  17. #include <linux/platform_data/usb-ehci-mxc.h>
  18. #include "hardware.h"
  19. #define MXC_OTG_OFFSET 0
  20. #define MXC_H1_OFFSET 0x200
  21. #define MXC_H2_OFFSET 0x400
  22. /* USB_CTRL */
  23. #define MXC_OTG_UCTRL_OWIE_BIT (1 << 27) /* OTG wakeup intr enable */
  24. #define MXC_OTG_UCTRL_OPM_BIT (1 << 24) /* OTG power mask */
  25. #define MXC_H1_UCTRL_H1UIE_BIT (1 << 12) /* Host1 ULPI interrupt enable */
  26. #define MXC_H1_UCTRL_H1WIE_BIT (1 << 11) /* HOST1 wakeup intr enable */
  27. #define MXC_H1_UCTRL_H1PM_BIT (1 << 8) /* HOST1 power mask */
  28. /* USB_PHY_CTRL_FUNC */
  29. #define MXC_OTG_PHYCTRL_OC_POL_BIT (1 << 9) /* OTG Polarity of Overcurrent */
  30. #define MXC_OTG_PHYCTRL_OC_DIS_BIT (1 << 8) /* OTG Disable Overcurrent Event */
  31. #define MXC_H1_OC_POL_BIT (1 << 6) /* UH1 Polarity of Overcurrent */
  32. #define MXC_H1_OC_DIS_BIT (1 << 5) /* UH1 Disable Overcurrent Event */
  33. #define MXC_OTG_PHYCTRL_PWR_POL_BIT (1 << 3) /* OTG Power Pin Polarity */
  34. /* USBH2CTRL */
  35. #define MXC_H2_UCTRL_H2UIE_BIT (1 << 8)
  36. #define MXC_H2_UCTRL_H2WIE_BIT (1 << 7)
  37. #define MXC_H2_UCTRL_H2PM_BIT (1 << 4)
  38. #define MXC_USBCMD_OFFSET 0x140
  39. /* USBCMD */
  40. #define MXC_UCMD_ITC_NO_THRESHOLD_MASK (~(0xff << 16)) /* Interrupt Threshold Control */
  41. int mx51_initialize_usb_hw(int port, unsigned int flags)
  42. {
  43. unsigned int v;
  44. void __iomem *usb_base;
  45. void __iomem *usbotg_base;
  46. void __iomem *usbother_base;
  47. int ret = 0;
  48. usb_base = ioremap(MX51_USB_OTG_BASE_ADDR, SZ_4K);
  49. if (!usb_base) {
  50. printk(KERN_ERR "%s(): ioremap failed\n", __func__);
  51. return -ENOMEM;
  52. }
  53. switch (port) {
  54. case 0: /* OTG port */
  55. usbotg_base = usb_base + MXC_OTG_OFFSET;
  56. break;
  57. case 1: /* Host 1 port */
  58. usbotg_base = usb_base + MXC_H1_OFFSET;
  59. break;
  60. case 2: /* Host 2 port */
  61. usbotg_base = usb_base + MXC_H2_OFFSET;
  62. break;
  63. default:
  64. printk(KERN_ERR"%s no such port %d\n", __func__, port);
  65. ret = -ENOENT;
  66. goto error;
  67. }
  68. usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
  69. switch (port) {
  70. case 0: /*OTG port */
  71. if (flags & MXC_EHCI_INTERNAL_PHY) {
  72. v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  73. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  74. v |= MXC_OTG_PHYCTRL_OC_POL_BIT;
  75. else
  76. v &= ~MXC_OTG_PHYCTRL_OC_POL_BIT;
  77. if (flags & MXC_EHCI_POWER_PINS_ENABLED) {
  78. /* OC/USBPWR is used */
  79. v &= ~MXC_OTG_PHYCTRL_OC_DIS_BIT;
  80. } else {
  81. /* OC/USBPWR is not used */
  82. v |= MXC_OTG_PHYCTRL_OC_DIS_BIT;
  83. }
  84. if (flags & MXC_EHCI_PWR_PIN_ACTIVE_HIGH)
  85. v |= MXC_OTG_PHYCTRL_PWR_POL_BIT;
  86. else
  87. v &= ~MXC_OTG_PHYCTRL_PWR_POL_BIT;
  88. __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  89. v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
  90. if (flags & MXC_EHCI_WAKEUP_ENABLED)
  91. v |= MXC_OTG_UCTRL_OWIE_BIT;/* OTG wakeup enable */
  92. else
  93. v &= ~MXC_OTG_UCTRL_OWIE_BIT;/* OTG wakeup disable */
  94. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  95. v &= ~MXC_OTG_UCTRL_OPM_BIT;
  96. else
  97. v |= MXC_OTG_UCTRL_OPM_BIT;
  98. __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
  99. }
  100. break;
  101. case 1: /* Host 1 */
  102. /*Host ULPI */
  103. v = __raw_readl(usbother_base + MXC_USBCTRL_OFFSET);
  104. if (flags & MXC_EHCI_WAKEUP_ENABLED) {
  105. /* HOST1 wakeup/ULPI intr enable */
  106. v |= (MXC_H1_UCTRL_H1WIE_BIT | MXC_H1_UCTRL_H1UIE_BIT);
  107. } else {
  108. /* HOST1 wakeup/ULPI intr disable */
  109. v &= ~(MXC_H1_UCTRL_H1WIE_BIT | MXC_H1_UCTRL_H1UIE_BIT);
  110. }
  111. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  112. v &= ~MXC_H1_UCTRL_H1PM_BIT; /* HOST1 power mask unused*/
  113. else
  114. v |= MXC_H1_UCTRL_H1PM_BIT; /* HOST1 power mask used*/
  115. __raw_writel(v, usbother_base + MXC_USBCTRL_OFFSET);
  116. v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  117. if (flags & MXC_EHCI_OC_PIN_ACTIVE_LOW)
  118. v |= MXC_H1_OC_POL_BIT;
  119. else
  120. v &= ~MXC_H1_OC_POL_BIT;
  121. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  122. v &= ~MXC_H1_OC_DIS_BIT; /* OC is used */
  123. else
  124. v |= MXC_H1_OC_DIS_BIT; /* OC is not used */
  125. __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC_OFFSET);
  126. v = __raw_readl(usbotg_base + MXC_USBCMD_OFFSET);
  127. if (flags & MXC_EHCI_ITC_NO_THRESHOLD)
  128. /* Interrupt Threshold Control:Immediate (no threshold) */
  129. v &= MXC_UCMD_ITC_NO_THRESHOLD_MASK;
  130. __raw_writel(v, usbotg_base + MXC_USBCMD_OFFSET);
  131. break;
  132. case 2: /* Host 2 ULPI */
  133. v = __raw_readl(usbother_base + MXC_USBH2CTRL_OFFSET);
  134. if (flags & MXC_EHCI_WAKEUP_ENABLED) {
  135. /* HOST1 wakeup/ULPI intr enable */
  136. v |= (MXC_H2_UCTRL_H2WIE_BIT | MXC_H2_UCTRL_H2UIE_BIT);
  137. } else {
  138. /* HOST1 wakeup/ULPI intr disable */
  139. v &= ~(MXC_H2_UCTRL_H2WIE_BIT | MXC_H2_UCTRL_H2UIE_BIT);
  140. }
  141. if (flags & MXC_EHCI_POWER_PINS_ENABLED)
  142. v &= ~MXC_H2_UCTRL_H2PM_BIT; /* HOST2 power mask unused*/
  143. else
  144. v |= MXC_H2_UCTRL_H2PM_BIT; /* HOST2 power mask used*/
  145. __raw_writel(v, usbother_base + MXC_USBH2CTRL_OFFSET);
  146. break;
  147. }
  148. error:
  149. iounmap(usb_base);
  150. return ret;
  151. }