omap_phy_internal.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. int omap4430_phy_init(struct device *dev)
  42. {
  43. ctrl_base = ioremap(OMAP443X_SCM_BASE, SZ_1K);
  44. if (!ctrl_base) {
  45. dev_err(dev, "control module ioremap failed\n");
  46. return -ENOMEM;
  47. }
  48. /* Power down the phy */
  49. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  50. phyclk = clk_get(dev, "ocp2scp_usb_phy_ick");
  51. if (IS_ERR(phyclk)) {
  52. dev_err(dev, "cannot clk_get ocp2scp_usb_phy_ick\n");
  53. iounmap(ctrl_base);
  54. return PTR_ERR(phyclk);
  55. }
  56. clk48m = clk_get(dev, "ocp2scp_usb_phy_phy_48m");
  57. if (IS_ERR(clk48m)) {
  58. dev_err(dev, "cannot clk_get ocp2scp_usb_phy_phy_48m\n");
  59. clk_put(phyclk);
  60. iounmap(ctrl_base);
  61. return PTR_ERR(clk48m);
  62. }
  63. clk32k = clk_get(dev, "usb_phy_cm_clk32k");
  64. if (IS_ERR(clk32k)) {
  65. dev_err(dev, "cannot clk_get usb_phy_cm_clk32k\n");
  66. clk_put(phyclk);
  67. clk_put(clk48m);
  68. iounmap(ctrl_base);
  69. return PTR_ERR(clk32k);
  70. }
  71. return 0;
  72. }
  73. int omap4430_phy_set_clk(struct device *dev, int on)
  74. {
  75. static int state;
  76. if (on && !state) {
  77. /* Enable the phy clocks */
  78. clk_enable(phyclk);
  79. clk_enable(clk48m);
  80. clk_enable(clk32k);
  81. state = 1;
  82. } else if (state) {
  83. /* Disable the phy clocks */
  84. clk_disable(phyclk);
  85. clk_disable(clk48m);
  86. clk_disable(clk32k);
  87. state = 0;
  88. }
  89. return 0;
  90. }
  91. int omap4430_phy_power(struct device *dev, int ID, int on)
  92. {
  93. if (on) {
  94. /* enabled the clocks */
  95. omap4430_phy_set_clk(dev, 1);
  96. /* power on the phy */
  97. if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) {
  98. __raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  99. mdelay(200);
  100. }
  101. if (ID)
  102. /* enable VBUS valid, IDDIG groung */
  103. __raw_writel(AVALID | VBUSVALID, ctrl_base +
  104. USBOTGHS_CONTROL);
  105. else
  106. /*
  107. * Enable VBUS Valid, AValid and IDDIG
  108. * high impedence
  109. */
  110. __raw_writel(IDDIG | AVALID | VBUSVALID,
  111. ctrl_base + USBOTGHS_CONTROL);
  112. } else {
  113. /* Enable session END and IDIG to high impedence. */
  114. __raw_writel(SESSEND | IDDIG, ctrl_base +
  115. USBOTGHS_CONTROL);
  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. }
  121. return 0;
  122. }
  123. int omap4430_phy_exit(struct device *dev)
  124. {
  125. if (ctrl_base)
  126. iounmap(ctrl_base);
  127. if (phyclk)
  128. clk_put(phyclk);
  129. if (clk48m)
  130. clk_put(clk48m);
  131. if (clk32k)
  132. clk_put(clk32k);
  133. return 0;
  134. }