omap2430.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Copyright (C) 2005-2007 by Texas Instruments
  4. * Some code has been taken from tusb6010.c
  5. * Copyrights for that are attributable to:
  6. * Copyright (C) 2006 Nokia Corporation
  7. * Tony Lindgren <tony@atomide.com>
  8. *
  9. * This file is part of the Inventra Controller Driver for Linux.
  10. */
  11. #include <common.h>
  12. #include <dm.h>
  13. #include <dm/device-internal.h>
  14. #include <dm/lists.h>
  15. #include <linux/usb/otg.h>
  16. #include <asm/omap_common.h>
  17. #include <asm/omap_musb.h>
  18. #include <twl4030.h>
  19. #include <twl6030.h>
  20. #include "linux-compat.h"
  21. #include "musb_core.h"
  22. #include "omap2430.h"
  23. #include "musb_uboot.h"
  24. static inline void omap2430_low_level_exit(struct musb *musb)
  25. {
  26. u32 l;
  27. /* in any role */
  28. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  29. l |= ENABLEFORCE; /* enable MSTANDBY */
  30. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  31. }
  32. static inline void omap2430_low_level_init(struct musb *musb)
  33. {
  34. u32 l;
  35. l = musb_readl(musb->mregs, OTG_FORCESTDBY);
  36. l &= ~ENABLEFORCE; /* disable MSTANDBY */
  37. musb_writel(musb->mregs, OTG_FORCESTDBY, l);
  38. }
  39. static int omap2430_musb_init(struct musb *musb)
  40. {
  41. u32 l;
  42. int status = 0;
  43. unsigned long int start;
  44. struct omap_musb_board_data *data =
  45. (struct omap_musb_board_data *)musb->controller;
  46. /* Reset the controller */
  47. musb_writel(musb->mregs, OTG_SYSCONFIG, SOFTRST);
  48. start = get_timer(0);
  49. while (1) {
  50. l = musb_readl(musb->mregs, OTG_SYSCONFIG);
  51. if ((l & SOFTRST) == 0)
  52. break;
  53. if (get_timer(start) > (CONFIG_SYS_HZ / 1000)) {
  54. dev_err(musb->controller, "MUSB reset is taking too long\n");
  55. return -ENODEV;
  56. }
  57. }
  58. l = musb_readl(musb->mregs, OTG_INTERFSEL);
  59. if (data->interface_type == MUSB_INTERFACE_UTMI) {
  60. /* OMAP4 uses Internal PHY GS70 which uses UTMI interface */
  61. l &= ~ULPI_12PIN; /* Disable ULPI */
  62. l |= UTMI_8BIT; /* Enable UTMI */
  63. } else {
  64. l |= ULPI_12PIN;
  65. }
  66. musb_writel(musb->mregs, OTG_INTERFSEL, l);
  67. pr_debug("HS USB OTG: revision 0x%x, sysconfig 0x%02x, "
  68. "sysstatus 0x%x, intrfsel 0x%x, simenable 0x%x\n",
  69. musb_readl(musb->mregs, OTG_REVISION),
  70. musb_readl(musb->mregs, OTG_SYSCONFIG),
  71. musb_readl(musb->mregs, OTG_SYSSTATUS),
  72. musb_readl(musb->mregs, OTG_INTERFSEL),
  73. musb_readl(musb->mregs, OTG_SIMENABLE));
  74. return 0;
  75. err1:
  76. return status;
  77. }
  78. static int omap2430_musb_enable(struct musb *musb)
  79. {
  80. #ifdef CONFIG_TWL4030_USB
  81. if (twl4030_usb_ulpi_init()) {
  82. serial_printf("ERROR: %s Could not initialize PHY\n",
  83. __PRETTY_FUNCTION__);
  84. }
  85. #endif
  86. #ifdef CONFIG_TWL6030_POWER
  87. twl6030_usb_device_settings();
  88. #endif
  89. #ifdef CONFIG_OMAP44XX
  90. u32 *usbotghs_control = (u32 *)((*ctrl)->control_usbotghs_ctrl);
  91. *usbotghs_control = USBOTGHS_CONTROL_AVALID |
  92. USBOTGHS_CONTROL_VBUSVALID | USBOTGHS_CONTROL_IDDIG;
  93. #endif
  94. return 0;
  95. }
  96. static void omap2430_musb_disable(struct musb *musb)
  97. {
  98. }
  99. static int omap2430_musb_exit(struct musb *musb)
  100. {
  101. del_timer_sync(&musb_idle_timer);
  102. omap2430_low_level_exit(musb);
  103. return 0;
  104. }
  105. const struct musb_platform_ops omap2430_ops = {
  106. .init = omap2430_musb_init,
  107. .exit = omap2430_musb_exit,
  108. .enable = omap2430_musb_enable,
  109. .disable = omap2430_musb_disable,
  110. };
  111. #if defined(CONFIG_DM_USB)
  112. struct omap2430_musb_platdata {
  113. void *base;
  114. void *ctrl_mod_base;
  115. struct musb_hdrc_platform_data plat;
  116. struct musb_hdrc_config musb_config;
  117. struct omap_musb_board_data otg_board_data;
  118. };
  119. static int omap2430_musb_ofdata_to_platdata(struct udevice *dev)
  120. {
  121. struct omap2430_musb_platdata *platdata = dev_get_platdata(dev);
  122. const void *fdt = gd->fdt_blob;
  123. int node = dev_of_offset(dev);
  124. platdata->base = (void *)dev_read_addr_ptr(dev);
  125. platdata->musb_config.multipoint = fdtdec_get_int(fdt, node,
  126. "multipoint",
  127. -1);
  128. if (platdata->musb_config.multipoint < 0) {
  129. pr_err("MUSB multipoint DT entry missing\n");
  130. return -ENOENT;
  131. }
  132. platdata->musb_config.dyn_fifo = 1;
  133. platdata->musb_config.num_eps = fdtdec_get_int(fdt, node,
  134. "num-eps", -1);
  135. if (platdata->musb_config.num_eps < 0) {
  136. pr_err("MUSB num-eps DT entry missing\n");
  137. return -ENOENT;
  138. }
  139. platdata->musb_config.ram_bits = fdtdec_get_int(fdt, node,
  140. "ram-bits", -1);
  141. if (platdata->musb_config.ram_bits < 0) {
  142. pr_err("MUSB ram-bits DT entry missing\n");
  143. return -ENOENT;
  144. }
  145. platdata->plat.power = fdtdec_get_int(fdt, node,
  146. "power", -1);
  147. if (platdata->plat.power < 0) {
  148. pr_err("MUSB power DT entry missing\n");
  149. return -ENOENT;
  150. }
  151. platdata->otg_board_data.interface_type = fdtdec_get_int(fdt, node,
  152. "interface-type", -1);
  153. if (platdata->otg_board_data.interface_type < 0) {
  154. pr_err("MUSB interface-type DT entry missing\n");
  155. return -ENOENT;
  156. }
  157. #if 0 /* In a perfect world, mode would be set to OTG, mode 3 from DT */
  158. platdata->plat.mode = fdtdec_get_int(fdt, node,
  159. "mode", -1);
  160. if (platdata->plat.mode < 0) {
  161. pr_err("MUSB mode DT entry missing\n");
  162. return -ENOENT;
  163. }
  164. #else /* MUSB_OTG, it doesn't work */
  165. #ifdef CONFIG_USB_MUSB_HOST /* Host seems to be the only option that works */
  166. platdata->plat.mode = MUSB_HOST;
  167. #else /* For that matter, MUSB_PERIPHERAL doesn't either */
  168. platdata->plat.mode = MUSB_PERIPHERAL;
  169. #endif
  170. #endif
  171. platdata->otg_board_data.dev = dev;
  172. platdata->plat.config = &platdata->musb_config;
  173. platdata->plat.platform_ops = &omap2430_ops;
  174. platdata->plat.board_data = &platdata->otg_board_data;
  175. return 0;
  176. }
  177. static int omap2430_musb_probe(struct udevice *dev)
  178. {
  179. #ifdef CONFIG_USB_MUSB_HOST
  180. struct musb_host_data *host = dev_get_priv(dev);
  181. #endif
  182. struct omap2430_musb_platdata *platdata = dev_get_platdata(dev);
  183. struct usb_bus_priv *priv = dev_get_uclass_priv(dev);
  184. struct omap_musb_board_data *otg_board_data;
  185. int ret;
  186. void *base = dev_read_addr_ptr(dev);
  187. priv->desc_before_addr = true;
  188. otg_board_data = &platdata->otg_board_data;
  189. #ifdef CONFIG_USB_MUSB_HOST
  190. host->host = musb_init_controller(&platdata->plat,
  191. (struct device *)otg_board_data,
  192. platdata->base);
  193. if (!host->host) {
  194. return -EIO;
  195. }
  196. ret = musb_lowlevel_init(host);
  197. #else
  198. ret = musb_register(&platdata->plat,
  199. (struct device *)otg_board_data,
  200. platdata->base);
  201. #endif
  202. return ret;
  203. }
  204. static int omap2430_musb_remove(struct udevice *dev)
  205. {
  206. struct musb_host_data *host = dev_get_priv(dev);
  207. musb_stop(host->host);
  208. return 0;
  209. }
  210. static const struct udevice_id omap2430_musb_ids[] = {
  211. { .compatible = "ti,omap3-musb" },
  212. { .compatible = "ti,omap4-musb" },
  213. { }
  214. };
  215. U_BOOT_DRIVER(omap2430_musb) = {
  216. .name = "omap2430-musb",
  217. #ifdef CONFIG_USB_MUSB_HOST
  218. .id = UCLASS_USB,
  219. #else
  220. .id = UCLASS_USB_DEV_GENERIC,
  221. #endif
  222. .of_match = omap2430_musb_ids,
  223. .ofdata_to_platdata = omap2430_musb_ofdata_to_platdata,
  224. .probe = omap2430_musb_probe,
  225. .remove = omap2430_musb_remove,
  226. #ifdef CONFIG_USB_MUSB_HOST
  227. .ops = &musb_usb_ops,
  228. #endif
  229. .platdata_auto_alloc_size = sizeof(struct omap2430_musb_platdata),
  230. .priv_auto_alloc_size = sizeof(struct musb_host_data),
  231. };
  232. #endif /* CONFIG_DM_USB */