omap_phy_internal.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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 "control.h"
  31. /* OMAP control module register for UTMI PHY */
  32. #define CONTROL_DEV_CONF 0x300
  33. #define PHY_PD 0x1
  34. #define USBOTGHS_CONTROL 0x33c
  35. #define AVALID BIT(0)
  36. #define BVALID BIT(1)
  37. #define VBUSVALID BIT(2)
  38. #define SESSEND BIT(3)
  39. #define IDDIG BIT(4)
  40. static struct clk *phyclk, *clk48m, *clk32k;
  41. static void __iomem *ctrl_base;
  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. /* enabled the clocks */
  96. omap4430_phy_set_clk(dev, 1);
  97. /* power on the phy */
  98. if (__raw_readl(ctrl_base + CONTROL_DEV_CONF) & PHY_PD) {
  99. __raw_writel(~PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  100. mdelay(200);
  101. }
  102. if (ID)
  103. /* enable VBUS valid, IDDIG groung */
  104. __raw_writel(AVALID | VBUSVALID, ctrl_base +
  105. USBOTGHS_CONTROL);
  106. else
  107. /*
  108. * Enable VBUS Valid, AValid and IDDIG
  109. * high impedence
  110. */
  111. __raw_writel(IDDIG | AVALID | VBUSVALID,
  112. ctrl_base + USBOTGHS_CONTROL);
  113. } else {
  114. /* Enable session END and IDIG to high impedence. */
  115. __raw_writel(SESSEND | IDDIG, ctrl_base +
  116. USBOTGHS_CONTROL);
  117. /* Disable the clocks */
  118. omap4430_phy_set_clk(dev, 0);
  119. /* Power down the phy */
  120. __raw_writel(PHY_PD, ctrl_base + CONTROL_DEV_CONF);
  121. }
  122. return 0;
  123. }
  124. int omap4430_phy_exit(struct device *dev)
  125. {
  126. if (ctrl_base)
  127. iounmap(ctrl_base);
  128. if (phyclk)
  129. clk_put(phyclk);
  130. if (clk48m)
  131. clk_put(clk48m);
  132. if (clk32k)
  133. clk_put(clk32k);
  134. return 0;
  135. }
  136. void am35x_musb_reset(void)
  137. {
  138. u32 regval;
  139. /* Reset the musb interface */
  140. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  141. regval |= AM35XX_USBOTGSS_SW_RST;
  142. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  143. regval &= ~AM35XX_USBOTGSS_SW_RST;
  144. omap_ctrl_writel(regval, AM35XX_CONTROL_IP_SW_RESET);
  145. regval = omap_ctrl_readl(AM35XX_CONTROL_IP_SW_RESET);
  146. }
  147. void am35x_musb_phy_power(u8 on)
  148. {
  149. unsigned long timeout = jiffies + msecs_to_jiffies(100);
  150. u32 devconf2;
  151. if (on) {
  152. /*
  153. * Start the on-chip PHY and its PLL.
  154. */
  155. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  156. devconf2 &= ~(CONF2_RESET | CONF2_PHYPWRDN | CONF2_OTGPWRDN);
  157. devconf2 |= CONF2_PHY_PLLON;
  158. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  159. pr_info(KERN_INFO "Waiting for PHY clock good...\n");
  160. while (!(omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2)
  161. & CONF2_PHYCLKGD)) {
  162. cpu_relax();
  163. if (time_after(jiffies, timeout)) {
  164. pr_err(KERN_ERR "musb PHY clock good timed out\n");
  165. break;
  166. }
  167. }
  168. } else {
  169. /*
  170. * Power down the on-chip PHY.
  171. */
  172. devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  173. devconf2 &= ~CONF2_PHY_PLLON;
  174. devconf2 |= CONF2_PHYPWRDN | CONF2_OTGPWRDN;
  175. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  176. }
  177. }
  178. void am35x_musb_clear_irq(void)
  179. {
  180. u32 regval;
  181. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  182. regval |= AM35XX_USBOTGSS_INT_CLR;
  183. omap_ctrl_writel(regval, AM35XX_CONTROL_LVL_INTR_CLEAR);
  184. regval = omap_ctrl_readl(AM35XX_CONTROL_LVL_INTR_CLEAR);
  185. }
  186. void am35x_musb_set_mode(u8 musb_mode)
  187. {
  188. u32 devconf2 = omap_ctrl_readl(AM35XX_CONTROL_DEVCONF2);
  189. devconf2 &= ~CONF2_OTGMODE;
  190. switch (musb_mode) {
  191. #ifdef CONFIG_USB_MUSB_HDRC_HCD
  192. case MUSB_HOST: /* Force VBUS valid, ID = 0 */
  193. devconf2 |= CONF2_FORCE_HOST;
  194. break;
  195. #endif
  196. #ifdef CONFIG_USB_GADGET_MUSB_HDRC
  197. case MUSB_PERIPHERAL: /* Force VBUS valid, ID = 1 */
  198. devconf2 |= CONF2_FORCE_DEVICE;
  199. break;
  200. #endif
  201. #ifdef CONFIG_USB_MUSB_OTG
  202. case MUSB_OTG: /* Don't override the VBUS/ID comparators */
  203. devconf2 |= CONF2_NO_OVERRIDE;
  204. break;
  205. #endif
  206. default:
  207. pr_info(KERN_INFO "Unsupported mode %u\n", musb_mode);
  208. }
  209. omap_ctrl_writel(devconf2, AM35XX_CONTROL_DEVCONF2);
  210. }