usb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * arch/arm/plat-omap/usb.c -- platform level USB initialization
  3. *
  4. * Copyright (C) 2004 Texas Instruments, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #undef DEBUG
  21. #include <linux/module.h>
  22. #include <linux/kernel.h>
  23. #include <linux/init.h>
  24. #include <linux/platform_device.h>
  25. #include <linux/io.h>
  26. #include <plat/usb.h>
  27. #include <plat/board.h>
  28. #include <mach/hardware.h>
  29. #include "../mach-omap2/common.h"
  30. #ifdef CONFIG_ARCH_OMAP_OTG
  31. void __init
  32. omap_otg_init(struct omap_usb_config *config)
  33. {
  34. u32 syscon;
  35. int status;
  36. int alt_pingroup = 0;
  37. /* NOTE: no bus or clock setup (yet?) */
  38. syscon = omap_readl(OTG_SYSCON_1) & 0xffff;
  39. if (!(syscon & OTG_RESET_DONE))
  40. pr_debug("USB resets not complete?\n");
  41. //omap_writew(0, OTG_IRQ_EN);
  42. /* pin muxing and transceiver pinouts */
  43. if (config->pins[0] > 2) /* alt pingroup 2 */
  44. alt_pingroup = 1;
  45. syscon |= config->usb0_init(config->pins[0], is_usb0_device(config));
  46. syscon |= config->usb1_init(config->pins[1]);
  47. syscon |= config->usb2_init(config->pins[2], alt_pingroup);
  48. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  49. omap_writel(syscon, OTG_SYSCON_1);
  50. syscon = config->hmc_mode;
  51. syscon |= USBX_SYNCHRO | (4 << 16) /* B_ASE0_BRST */;
  52. #ifdef CONFIG_USB_OTG
  53. if (config->otg)
  54. syscon |= OTG_EN;
  55. #endif
  56. if (cpu_class_is_omap1())
  57. pr_debug("USB_TRANSCEIVER_CTRL = %03x\n",
  58. omap_readl(USB_TRANSCEIVER_CTRL));
  59. pr_debug("OTG_SYSCON_2 = %08x\n", omap_readl(OTG_SYSCON_2));
  60. omap_writel(syscon, OTG_SYSCON_2);
  61. printk("USB: hmc %d", config->hmc_mode);
  62. if (!alt_pingroup)
  63. printk(", usb2 alt %d wires", config->pins[2]);
  64. else if (config->pins[0])
  65. printk(", usb0 %d wires%s", config->pins[0],
  66. is_usb0_device(config) ? " (dev)" : "");
  67. if (config->pins[1])
  68. printk(", usb1 %d wires", config->pins[1]);
  69. if (!alt_pingroup && config->pins[2])
  70. printk(", usb2 %d wires", config->pins[2]);
  71. if (config->otg)
  72. printk(", Mini-AB on usb%d", config->otg - 1);
  73. printk("\n");
  74. if (cpu_class_is_omap1()) {
  75. u16 w;
  76. /* leave USB clocks/controllers off until needed */
  77. w = omap_readw(ULPD_SOFT_REQ);
  78. w &= ~SOFT_USB_CLK_REQ;
  79. omap_writew(w, ULPD_SOFT_REQ);
  80. w = omap_readw(ULPD_CLOCK_CTRL);
  81. w &= ~USB_MCLK_EN;
  82. w |= DIS_USB_PVCI_CLK;
  83. omap_writew(w, ULPD_CLOCK_CTRL);
  84. }
  85. syscon = omap_readl(OTG_SYSCON_1);
  86. syscon |= HST_IDLE_EN|DEV_IDLE_EN|OTG_IDLE_EN;
  87. #ifdef CONFIG_USB_GADGET_OMAP
  88. if (config->otg || config->register_dev) {
  89. struct platform_device *udc_device = config->udc_device;
  90. syscon &= ~DEV_IDLE_EN;
  91. udc_device->dev.platform_data = config;
  92. status = platform_device_register(udc_device);
  93. if (status)
  94. pr_debug("can't register UDC device, %d\n", status);
  95. }
  96. #endif
  97. #if defined(CONFIG_USB_OHCI_HCD) || defined(CONFIG_USB_OHCI_HCD_MODULE)
  98. if (config->otg || config->register_host) {
  99. struct platform_device *ohci_device = config->ohci_device;
  100. syscon &= ~HST_IDLE_EN;
  101. ohci_device->dev.platform_data = config;
  102. status = platform_device_register(ohci_device);
  103. if (status)
  104. pr_debug("can't register OHCI device, %d\n", status);
  105. }
  106. #endif
  107. #ifdef CONFIG_USB_OTG
  108. if (config->otg) {
  109. struct platform_device *otg_device = config->otg_device;
  110. syscon &= ~OTG_IDLE_EN;
  111. otg_device->dev.platform_data = config;
  112. status = platform_device_register(otg_device);
  113. if (status)
  114. pr_debug("can't register OTG device, %d\n", status);
  115. }
  116. #endif
  117. pr_debug("OTG_SYSCON_1 = %08x\n", omap_readl(OTG_SYSCON_1));
  118. omap_writel(syscon, OTG_SYSCON_1);
  119. status = 0;
  120. }
  121. #else
  122. void omap_otg_init(struct omap_usb_config *config) {}
  123. #endif