omap2430.c 7.0 KB

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