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 <linux/usb/musb.h>
  30. #include "soc.h"
  31. #include "control.h"
  32. #include "usb.h"
  33. #define CONTROL_DEV_CONF 0x300
  34. #define PHY_PD 0x1
  35. /**
  36. * omap4430_phy_power_down: disable MUSB PHY during early init
  37. *
  38. * OMAP4 MUSB PHY module is enabled by default on reset, but this will
  39. * prevent core retention if not disabled by SW. USB driver will
  40. * later on enable this, once and if the driver needs it.
  41. */
  42. static int __init omap4430_phy_power_down(void)
  43. {
  44. void __iomem *ctrl_base;
  45. if (!cpu_is_omap44xx())
  46. return 0;
  47. ctrl_base = ioremap(OMAP443X_SCM_BASE, SZ_1K);
  48. if (!ctrl_base) {
  49. pr_err("control module ioremap failed\n");
  50. return -ENOMEM;
  51. }
  52. /* Power down the phy */
  53. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  54. iounmap(ctrl_base);
  55. return 0;
  56. }
  57. omap_early_initcall(omap4430_phy_power_down);
  58. void am35x_musb_reset(void)
  59. {
  60. u32 regval;
  61. /* Reset the musb interface */
  62. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  63. regval |= AM35XX_USBOTGSS_SW_RST;
  64. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  65. regval &= ~AM35XX_USBOTGSS_SW_RST;
  66. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  67. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  68. }
  69. void am35x_musb_phy_power(u8 on)
  70. {
  71. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  72. u32 devconf2;
  73. if (on) {
  74. /*
  75. * Start the on-chip PHY and its PLL.
  76. */
  77. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  78. devconf2 &= ~(CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN);
  79. devconf2 |= CONF2_PHY_PLLON;
  80. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  81. pr_info(KERN_INFO "Waiting for PHY clock good...\n");
  82. while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
  83. & CONF2_PHYCLKGD)) {
  84. cpu_relax();
  85. if (time_after(jiffies, timeout)) {
  86. pr_err(KERN_ERR "musb PHY clock good timed out\n");
  87. break;
  88. }
  89. }
  90. } else {
  91. /*
  92. * Power down the on-chip PHY.
  93. */
  94. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  95. devconf2 &= ~CONF2_PHY_PLLON;
  96. devconf2 |= CONF2_PHYPWRDN | CONF2_OTGPWRDN;
  97. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  98. }
  99. }
  100. void am35x_musb_clear_irq(void)
  101. {
  102. u32 regval;
  103. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  104. regval |= AM35XX_USBOTGSS_INT_CLR;
  105. omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
  106. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  107. }
  108. void am35x_set_mode(u8 musb_mode)
  109. {
  110. u32 devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  111. devconf2 &= ~CONF2_OTGMODE;
  112. switch (musb_mode) {
  113. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  114. devconf2 |= CONF2_FORCE_HOST;
  115. break;
  116. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  117. devconf2 |= CONF2_FORCE_DEVICE;
  118. break;
  119. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  120. devconf2 |= CONF2_NO_OVERRIDE;
  121. break;
  122. default:
  123. pr_info(KERN_INFO "Unsupported mode %u\n", musb_mode);
  124. }
  125. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  126. }
  127. void ti81xx_musb_phy_power(u8 on)
  128. {
  129. void __iomem *scm_base = NULL;
  130. u32 usbphycfg;
  131. scm_base = ioremap(TI81XX_SCM_BASE, SZ_2K);
  132. if (!scm_base) {
  133. pr_err("system control module ioremap failed\n");
  134. return;
  135. }
  136. usbphycfg = __raw_readl(scm_base + USBCTRL0);
  137. if (on) {
  138. if (cpu_is_ti816x()) {
  139. usbphycfg |= TI816X_USBPHY0_NORMAL_MODE;
  140. usbphycfg &= ~TI816X_USBPHY_REFCLK_OSC;
  141. } else if (cpu_is_ti814x()) {
  142. usbphycfg &= ~(USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN
  143. | USBPHY_DPINPUT | USBPHY_DMINPUT);
  144. usbphycfg |= (USBPHY_OTGVDET_EN | USBPHY_OTGSESSEND_EN
  145. | USBPHY_DPOPBUFCTL | USBPHY_DMOPBUFCTL);
  146. }
  147. } else {
  148. if (cpu_is_ti816x())
  149. usbphycfg &= ~TI816X_USBPHY0_NORMAL_MODE;
  150. else if (cpu_is_ti814x())
  151. usbphycfg |= USBPHY_CM_PWRDN | USBPHY_OTG_PWRDN;
  152. }
  153. __raw_writel(usbphycfg, scm_base + USBCTRL0);
  154. iounmap(scm_base);
  155. }