omap_phy_internal.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  24. #include <linux/types.h>
  25. #include <linux/delay.h>
  26. #include <linux/clk.h>
  27. #include <linux/io.h>
  28. #include <linux/err.h>
  29. #include <linux/usb.h>
  30. #include <linux/usb/musb.h>
  31. #include "soc.h"
  32. #include "control.h"
  33. #include "usb.h"
  34. #define CONTROL_DEV_CONF 0x300
  35. #define PHY_PD 0x1
  36. /**
  37. * omap4430_phy_power_down: disable MUSB PHY during early init
  38. *
  39. * OMAP4 MUSB PHY module is enabled by default on reset, but this will
  40. * prevent core retention if not disabled by SW. USB driver will
  41. * later on enable this, once and if the driver needs it.
  42. */
  43. static int __init omap4430_phy_power_down(void)
  44. {
  45. void __iomem *ctrl_base;
  46. if (!cpu_is_omap44xx())
  47. return 0;
  48. ctrl_base = ioremap(OMAP443X_SCM_BASE, SZ_1K);
  49. if (!ctrl_base) {
  50. pr_err("control module ioremap failed\n");
  51. return -ENOMEM;
  52. }
  53. /* Power down the phy */
  54. writel_relaxed(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  55. iounmap(ctrl_base);
  56. return 0;
  57. }
  58. omap_early_initcall(omap4430_phy_power_down);
  59. void am35x_musb_reset(void)
  60. {
  61. u32 regval;
  62. /* Reset the musb interface */
  63. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  64. regval |= AM35XX_USBOTGSS_SW_RST;
  65. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  66. regval &= ~AM35XX_USBOTGSS_SW_RST;
  67. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  68. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  69. }
  70. void am35x_musb_phy_power(u8 on)
  71. {
  72. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  73. u32 devconf2;
  74. if (on) {
  75. /*
  76. * Start the on-chip PHY and its PLL.
  77. */
  78. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  79. devconf2 &= ~(CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN);
  80. devconf2 |= CONF2_PHY_PLLON;
  81. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  82. pr_info("Waiting for PHY clock good...\n");
  83. while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
  84. & CONF2_PHYCLKGD)) {
  85. cpu_relax();
  86. if (time_after(jiffies, timeout)) {
  87. pr_err("musb PHY clock good timed out\n");
  88. break;
  89. }
  90. }
  91. } else {
  92. /*
  93. * Power down the on-chip PHY.
  94. */
  95. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  96. devconf2 &= ~CONF2_PHY_PLLON;
  97. devconf2 |= CONF2_PHYPWRDN | CONF2_OTGPWRDN;
  98. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  99. }
  100. }
  101. void am35x_musb_clear_irq(void)
  102. {
  103. u32 regval;
  104. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  105. regval |= AM35XX_USBOTGSS_INT_CLR;
  106. omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
  107. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  108. }
  109. void am35x_set_mode(u8 musb_mode)
  110. {
  111. u32 devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  112. devconf2 &= ~CONF2_OTGMODE;
  113. switch (musb_mode) {
  114. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  115. devconf2 |= CONF2_FORCE_HOST;
  116. break;
  117. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  118. devconf2 |= CONF2_FORCE_DEVICE;
  119. break;
  120. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  121. devconf2 |= CONF2_NO_OVERRIDE;
  122. break;
  123. default:
  124. pr_info("Unsupported mode %u\n", musb_mode);
  125. }
  126. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  127. }