omap_phy_internal.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. /* OMAP control module register for UTMI PHY */
  31. #define CONTROL_DEV_CONF 0x300
  32. #define PHY_PD 0x1
  33. #define USBOTGHS_CONTROL 0x33c
  34. #define AVALID BIT(0)
  35. #define BVALID BIT(1)
  36. #define VBUSVALID BIT(2)
  37. #define SESSEND BIT(3)
  38. #define IDDIG BIT(4)
  39. static struct clk *phyclk, *clk48m, *clk32k;
  40. static void __iomem *ctrl_base;
  41. static int usbotghs_control;
  42. int omap4430_phy_init(struct device *dev)
  43. {
  44. ctrl_base = ioremap(OMAP443X_SCM_BASE, SZ_1K);
  45. if (!ctrl_base) {
  46. dev_err(dev, "control module ioremap failed\n");
  47. return -ENOMEM;
  48. }
  49. /* Power down the phy */
  50. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  51. phyclk = clk_get(dev, "ocp2scp_usb_phy_ick");
  52. if (IS_ERR(phyclk)) {
  53. dev_err(dev, "cannot clk_get ocp2scp_usb_phy_ick\n");
  54. iounmap(ctrl_base);
  55. return PTR_ERR(phyclk);
  56. }
  57. clk48m = clk_get(dev, "ocp2scp_usb_phy_phy_48m");
  58. if (IS_ERR(clk48m)) {
  59. dev_err(dev, "cannot clk_get ocp2scp_usb_phy_phy_48m\n");
  60. clk_put(phyclk);
  61. iounmap(ctrl_base);
  62. return PTR_ERR(clk48m);
  63. }
  64. clk32k = clk_get(dev, "usb_phy_cm_clk32k");
  65. if (IS_ERR(clk32k)) {
  66. dev_err(dev, "cannot clk_get usb_phy_cm_clk32k\n");
  67. clk_put(phyclk);
  68. clk_put(clk48m);
  69. iounmap(ctrl_base);
  70. return PTR_ERR(clk32k);
  71. }
  72. return 0;
  73. }
  74. int omap4430_phy_set_clk(struct device *dev, int on)
  75. {
  76. static int state;
  77. if (on && !state) {
  78. /* Enable the phy clocks */
  79. clk_enable(phyclk);
  80. clk_enable(clk48m);
  81. clk_enable(clk32k);
  82. state = 1;
  83. } else if (state) {
  84. /* Disable the phy clocks */
  85. clk_disable(phyclk);
  86. clk_disable(clk48m);
  87. clk_disable(clk32k);
  88. state = 0;
  89. }
  90. return 0;
  91. }
  92. int omap4430_phy_power(struct device *dev, int ID, int on)
  93. {
  94. if (on) {
  95. if (ID)
  96. /* enable VBUS valid, IDDIG groung */
  97. __raw_writel(AVALID | VBUSVALID, ctrl_base +
  98. USBOTGHS_CONTROL);
  99. else
  100. /*
  101. * Enable VBUS Valid, AValid and IDDIG
  102. * high impedence
  103. */
  104. __raw_writel(IDDIG | AVALID | VBUSVALID,
  105. ctrl_base + USBOTGHS_CONTROL);
  106. } else {
  107. /* Enable session END and IDIG to high impedence. */
  108. __raw_writel(SESSEND | IDDIG, ctrl_base +
  109. USBOTGHS_CONTROL);
  110. }
  111. return 0;
  112. }
  113. int omap4430_phy_suspend(struct device *dev, int suspend)
  114. {
  115. if (suspend) {
  116. /* Disable the clocks */
  117. omap4430_phy_set_clk(dev, 0);
  118. /* Power down the phy */
  119. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  120. /* save the context */
  121. usbotghs_control = __raw_readl(ctrl_base + USBOTGHS_CONTROL);
  122. } else {
  123. /* Enable the internel phy clcoks */
  124. omap4430_phy_set_clk(dev, 1);
  125. /* power on the phy */
  126. if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) {
  127. __raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  128. mdelay(200);
  129. }
  130. /* restore the context */
  131. __raw_writel(usbotghs_control, ctrl_base + USBOTGHS_CONTROL);
  132. }
  133. return 0;
  134. }
  135. int omap4430_phy_exit(struct device *dev)
  136. {
  137. if (ctrl_base)
  138. iounmap(ctrl_base);
  139. if (phyclk)
  140. clk_put(phyclk);
  141. if (clk48m)
  142. clk_put(clk48m);
  143. if (clk32k)
  144. clk_put(clk32k);
  145. return 0;
  146. }