omap_phy_internal.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. /*
  2. * This file configures the internal USB PHY in OMAP4430. Used
  3. * with TWL6030 transceiver and MUSB on OMAP4430.
  4. *
  5. * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com
  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. * Author: Hema HK <hemahk@ti.com>
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. */
  23. #include <linux/types.h>
  24. #include <linux/delay.h>
  25. #include <linux/clk.h>
  26. #include <linux/io.h>
  27. #include <linux/err.h>
  28. #include <linux/usb.h>
  29. #include <plat/usb.h>
  30. #include "soc.h"
  31. #include "control.h"
  32. #define CONTROL_DEV_CONF 0x300
  33. #define PHY_PD 0x1
  34. /**
  35. * omap4430_phy_power_down: disable MUSB PHY during early init
  36. *
  37. * OMAP4 MUSB PHY module is enabled by default on reset, but this will
  38. * prevent core retention if not disabled by SW. USB driver will
  39. * later on enable this, once and if the driver needs it.
  40. */
  41. static int __init omap4430_phy_power_down(void)
  42. {
  43. void __iomem *ctrl_base;
  44. if (!cpu_is_omap44xx())
  45. return 0;
  46. ctrl_base = ioremap(OMAP443X_SCM_BASE, SZ_1K);
  47. if (!ctrl_base) {
  48. pr_err("control module ioremap failed\n");
  49. return -ENOMEM;
  50. }
  51. /* Power down the phy */
  52. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  53. iounmap(ctrl_base);
  54. return 0;
  55. }
  56. early_initcall(omap4430_phy_power_down);
  57. void am35x_musb_reset(void)
  58. {
  59. u32 regval;
  60. /* Reset the musb interface */
  61. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  62. regval |= AM35XX_USBOTGSS_SW_RST;
  63. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  64. regval &= ~AM35XX_USBOTGSS_SW_RST;
  65. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  66. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  67. }
  68. void am35x_musb_phy_power(u8 on)
  69. {
  70. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  71. u32 devconf2;
  72. if (on) {
  73. /*
  74. * Start the on-chip PHY and its PLL.
  75. */
  76. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  77. devconf2 &= ~(CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN);
  78. devconf2 |= CONF2_PHY_PLLON;
  79. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  80. pr_info(KERN_INFO "Waiting for PHY clock good...\n");
  81. while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
  82. & CONF2_PHYCLKGD)) {
  83. cpu_relax();
  84. if (time_after(jiffies, timeout)) {
  85. pr_err(KERN_ERR "musb PHY clock good timed out\n");
  86. break;
  87. }
  88. }
  89. } else {
  90. /*
  91. * Power down the on-chip PHY.
  92. */
  93. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  94. devconf2 &= ~CONF2_PHY_PLLON;
  95. devconf2 |= CONF2_PHYPWRDN | CONF2_OTGPWRDN;
  96. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  97. }
  98. }
  99. void am35x_musb_clear_irq(void)
  100. {
  101. u32 regval;
  102. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  103. regval |= AM35XX_USBOTGSS_INT_CLR;
  104. omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
  105. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  106. }
  107. void am35x_set_mode(u8 musb_mode)
  108. {
  109. u32 devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  110. devconf2 &= ~CONF2_OTGMODE;
  111. switch (musb_mode) {
  112. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  113. devconf2 |= CONF2_FORCE_HOST;
  114. break;
  115. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  116. devconf2 |= CONF2_FORCE_DEVICE;
  117. break;
  118. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  119. devconf2 |= CONF2_NO_OVERRIDE;
  120. break;
  121. default:
  122. pr_info(KERN_INFO "Unsupported mode %u\n", musb_mode);
  123. }
  124. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  125. }
  126. void ti81xx_musb_phy_power(u8 on)
  127. {
  128. void __iomem *scm_base = NULL;
  129. u32 usbphycfg;
  130. scm_base = ioremap(TI81XX_SCM_BASE, SZ_2K);
  131. if (!scm_base) {
  132. pr_err("system control module ioremap failed\n");
  133. return;
  134. }
  135. usbphycfg = __raw_readl(scm_base + USBCTRL0);
  136. if (on) {
  137. if (cpu_is_ti816x()) {
  138. usbphycfg |= TI816X_USBPHY0_NORMAL_MODE;
  139. usbphycfg &= ~TI816X_USBPHY_REFCLK_OSC;
  140. } else if (cpu_is_ti814x()) {
  141. usbphycfg &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN
  142. | USBPHY_DPINPUT | USBPHY_DMINPUT);
  143. usbphycfg |= (USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN
  144. | USBPHY_DPOPBUFCTL | USBPHY_DMOPBUFCTL);
  145. }
  146. } else {
  147. if (cpu_is_ti816x())
  148. usbphycfg &= ~TI816X_USBPHY0_NORMAL_MODE;
  149. else if (cpu_is_ti814x())
  150. usbphycfg |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
  151. }
  152. __raw_writel(usbphycfg, scm_base + USBCTRL0);
  153. iounmap(scm_base);
  154. }