usb.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. /*
  2. * Freescale 83xx USB SOC setup code
  3. *
  4. * Copyright (C) 2007 Freescale Semiconductor, Inc.
  5. * Author: Li Yang
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License as published by the
  9. * Free Software Foundation; either version 2 of the License, or (at your
  10. * option) any later version.
  11. */
  12. #include <linux/stddef.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/of.h>
  16. #include <asm/io.h>
  17. #include <asm/prom.h>
  18. #include <sysdev/fsl_soc.h>
  19. #include "mpc83xx.h"
  20. #ifdef CONFIG_PPC_MPC834x
  21. int mpc834x_usb_cfg(void)
  22. {
  23. unsigned long sccr, sicrl, sicrh;
  24. void __iomem *immap;
  25. struct device_node *np = NULL;
  26. int port0_is_dr = 0, port1_is_dr = 0;
  27. const void *prop, *dr_mode;
  28. immap = ioremap(get_immrbase(), 0x1000);
  29. if (!immap)
  30. return -ENOMEM;
  31. /* Read registers */
  32. /* Note: DR and MPH must use the same clock setting in SCCR */
  33. sccr = in_be32(immap + MPC83XX_SCCR_OFFS) & ~MPC83XX_SCCR_USB_MASK;
  34. sicrl = in_be32(immap + MPC83XX_SICRL_OFFS) & ~MPC834X_SICRL_USB_MASK;
  35. sicrh = in_be32(immap + MPC83XX_SICRH_OFFS) & ~MPC834X_SICRH_USB_UTMI;
  36. np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
  37. if (np) {
  38. sccr |= MPC83XX_SCCR_USB_DRCM_11; /* 1:3 */
  39. prop = of_get_property(np, "phy_type", NULL);
  40. port1_is_dr = 1;
  41. if (prop && (!strcmp(prop, "utmi") ||
  42. !strcmp(prop, "utmi_wide"))) {
  43. sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1;
  44. sicrh |= MPC834X_SICRH_USB_UTMI;
  45. port0_is_dr = 1;
  46. } else if (prop && !strcmp(prop, "serial")) {
  47. dr_mode = of_get_property(np, "dr_mode", NULL);
  48. if (dr_mode && !strcmp(dr_mode, "otg")) {
  49. sicrl |= MPC834X_SICRL_USB0 | MPC834X_SICRL_USB1;
  50. port0_is_dr = 1;
  51. } else {
  52. sicrl |= MPC834X_SICRL_USB1;
  53. }
  54. } else if (prop && !strcmp(prop, "ulpi")) {
  55. sicrl |= MPC834X_SICRL_USB1;
  56. } else {
  57. printk(KERN_WARNING "834x USB PHY type not supported\n");
  58. }
  59. of_node_put(np);
  60. }
  61. np = of_find_compatible_node(NULL, NULL, "fsl-usb2-mph");
  62. if (np) {
  63. sccr |= MPC83XX_SCCR_USB_MPHCM_11; /* 1:3 */
  64. prop = of_get_property(np, "port0", NULL);
  65. if (prop) {
  66. if (port0_is_dr)
  67. printk(KERN_WARNING
  68. "834x USB port0 can't be used by both DR and MPH!\n");
  69. sicrl &= ~MPC834X_SICRL_USB0;
  70. }
  71. prop = of_get_property(np, "port1", NULL);
  72. if (prop) {
  73. if (port1_is_dr)
  74. printk(KERN_WARNING
  75. "834x USB port1 can't be used by both DR and MPH!\n");
  76. sicrl &= ~MPC834X_SICRL_USB1;
  77. }
  78. of_node_put(np);
  79. }
  80. /* Write back */
  81. out_be32(immap + MPC83XX_SCCR_OFFS, sccr);
  82. out_be32(immap + MPC83XX_SICRL_OFFS, sicrl);
  83. out_be32(immap + MPC83XX_SICRH_OFFS, sicrh);
  84. iounmap(immap);
  85. return 0;
  86. }
  87. #endif /* CONFIG_PPC_MPC834x */
  88. #ifdef CONFIG_PPC_MPC831x
  89. int mpc831x_usb_cfg(void)
  90. {
  91. u32 temp;
  92. void __iomem *immap, *usb_regs;
  93. struct device_node *np = NULL;
  94. struct device_node *immr_node = NULL;
  95. const void *prop;
  96. struct resource res;
  97. int ret = 0;
  98. #ifdef CONFIG_USB_OTG
  99. const void *dr_mode;
  100. #endif
  101. np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
  102. if (!np)
  103. return -ENODEV;
  104. prop = of_get_property(np, "phy_type", NULL);
  105. /* Map IMMR space for pin and clock settings */
  106. immap = ioremap(get_immrbase(), 0x1000);
  107. if (!immap) {
  108. of_node_put(np);
  109. return -ENOMEM;
  110. }
  111. /* Configure clock */
  112. immr_node = of_get_parent(np);
  113. if (immr_node && (of_device_is_compatible(immr_node, "fsl,mpc8315-immr") ||
  114. of_device_is_compatible(immr_node, "fsl,mpc8308-immr")))
  115. clrsetbits_be32(immap + MPC83XX_SCCR_OFFS,
  116. MPC8315_SCCR_USB_MASK,
  117. MPC8315_SCCR_USB_DRCM_01);
  118. else
  119. clrsetbits_be32(immap + MPC83XX_SCCR_OFFS,
  120. MPC83XX_SCCR_USB_MASK,
  121. MPC83XX_SCCR_USB_DRCM_11);
  122. /* Configure pin mux for ULPI. There is no pin mux for UTMI */
  123. if (prop && !strcmp(prop, "ulpi")) {
  124. if (of_device_is_compatible(immr_node, "fsl,mpc8308-immr")) {
  125. clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
  126. MPC8308_SICRH_USB_MASK,
  127. MPC8308_SICRH_USB_ULPI);
  128. } else if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr")) {
  129. clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
  130. MPC8315_SICRL_USB_MASK,
  131. MPC8315_SICRL_USB_ULPI);
  132. clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
  133. MPC8315_SICRH_USB_MASK,
  134. MPC8315_SICRH_USB_ULPI);
  135. } else {
  136. clrsetbits_be32(immap + MPC83XX_SICRL_OFFS,
  137. MPC831X_SICRL_USB_MASK,
  138. MPC831X_SICRL_USB_ULPI);
  139. clrsetbits_be32(immap + MPC83XX_SICRH_OFFS,
  140. MPC831X_SICRH_USB_MASK,
  141. MPC831X_SICRH_USB_ULPI);
  142. }
  143. }
  144. iounmap(immap);
  145. of_node_put(immr_node);
  146. /* Map USB SOC space */
  147. ret = of_address_to_resource(np, 0, &res);
  148. if (ret) {
  149. of_node_put(np);
  150. return ret;
  151. }
  152. usb_regs = ioremap(res.start, resource_size(&res));
  153. /* Using on-chip PHY */
  154. if (prop && (!strcmp(prop, "utmi_wide") ||
  155. !strcmp(prop, "utmi"))) {
  156. u32 refsel;
  157. if (of_device_is_compatible(immr_node, "fsl,mpc8308-immr"))
  158. goto out;
  159. if (of_device_is_compatible(immr_node, "fsl,mpc8315-immr"))
  160. refsel = CONTROL_REFSEL_24MHZ;
  161. else
  162. refsel = CONTROL_REFSEL_48MHZ;
  163. /* Set UTMI_PHY_EN and REFSEL */
  164. out_be32(usb_regs + FSL_USB2_CONTROL_OFFS,
  165. CONTROL_UTMI_PHY_EN | refsel);
  166. /* Using external UPLI PHY */
  167. } else if (prop && !strcmp(prop, "ulpi")) {
  168. /* Set PHY_CLK_SEL to ULPI */
  169. temp = CONTROL_PHY_CLK_SEL_ULPI;
  170. #ifdef CONFIG_USB_OTG
  171. /* Set OTG_PORT */
  172. if (!of_device_is_compatible(immr_node, "fsl,mpc8308-immr")) {
  173. dr_mode = of_get_property(np, "dr_mode", NULL);
  174. if (dr_mode && !strcmp(dr_mode, "otg"))
  175. temp |= CONTROL_OTG_PORT;
  176. }
  177. #endif /* CONFIG_USB_OTG */
  178. out_be32(usb_regs + FSL_USB2_CONTROL_OFFS, temp);
  179. } else {
  180. printk(KERN_WARNING "831x USB PHY type not supported\n");
  181. ret = -EINVAL;
  182. }
  183. out:
  184. iounmap(usb_regs);
  185. of_node_put(np);
  186. return ret;
  187. }
  188. #endif /* CONFIG_PPC_MPC831x */
  189. #ifdef CONFIG_PPC_MPC837x
  190. int mpc837x_usb_cfg(void)
  191. {
  192. void __iomem *immap;
  193. struct device_node *np = NULL;
  194. const void *prop;
  195. int ret = 0;
  196. np = of_find_compatible_node(NULL, NULL, "fsl-usb2-dr");
  197. if (!np || !of_device_is_available(np))
  198. return -ENODEV;
  199. prop = of_get_property(np, "phy_type", NULL);
  200. if (!prop || (strcmp(prop, "ulpi") && strcmp(prop, "serial"))) {
  201. printk(KERN_WARNING "837x USB PHY type not supported\n");
  202. of_node_put(np);
  203. return -EINVAL;
  204. }
  205. /* Map IMMR space for pin and clock settings */
  206. immap = ioremap(get_immrbase(), 0x1000);
  207. if (!immap) {
  208. of_node_put(np);
  209. return -ENOMEM;
  210. }
  211. /* Configure clock */
  212. clrsetbits_be32(immap + MPC83XX_SCCR_OFFS, MPC837X_SCCR_USB_DRCM_11,
  213. MPC837X_SCCR_USB_DRCM_11);
  214. /* Configure pin mux for ULPI/serial */
  215. clrsetbits_be32(immap + MPC83XX_SICRL_OFFS, MPC837X_SICRL_USB_MASK,
  216. MPC837X_SICRL_USB_ULPI);
  217. iounmap(immap);
  218. of_node_put(np);
  219. return ret;
  220. }
  221. #endif /* CONFIG_PPC_MPC837x */