setup-usb-phy.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co.Ltd
  3. * Author: Joonyoung Shim <jy0922.shim@samsung.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. */
  11. #include <linux/clk.h>
  12. #include <linux/delay.h>
  13. #include <linux/err.h>
  14. #include <linux/io.h>
  15. #include <linux/platform_device.h>
  16. #include <mach/regs-pmu.h>
  17. #include <mach/regs-usb-phy.h>
  18. #include <plat/cpu.h>
  19. #include <plat/usb-phy.h>
  20. static int exynos4_usb_phy1_init(struct platform_device *pdev)
  21. {
  22. struct clk *otg_clk;
  23. struct clk *xusbxti_clk;
  24. u32 phyclk;
  25. u32 rstcon;
  26. int err;
  27. otg_clk = clk_get(&pdev->dev, "otg");
  28. if (IS_ERR(otg_clk)) {
  29. dev_err(&pdev->dev, "Failed to get otg clock\n");
  30. return PTR_ERR(otg_clk);
  31. }
  32. err = clk_enable(otg_clk);
  33. if (err) {
  34. clk_put(otg_clk);
  35. return err;
  36. }
  37. writel(readl(S5P_USBHOST_PHY_CONTROL) | S5P_USBHOST_PHY_ENABLE,
  38. S5P_USBHOST_PHY_CONTROL);
  39. /* set clock frequency for PLL */
  40. phyclk = readl(EXYNOS4_PHYCLK) & ~CLKSEL_MASK;
  41. xusbxti_clk = clk_get(&pdev->dev, "xusbxti");
  42. if (xusbxti_clk && !IS_ERR(xusbxti_clk)) {
  43. switch (clk_get_rate(xusbxti_clk)) {
  44. case 12 * MHZ:
  45. phyclk |= CLKSEL_12M;
  46. break;
  47. case 24 * MHZ:
  48. phyclk |= CLKSEL_24M;
  49. break;
  50. default:
  51. case 48 * MHZ:
  52. /* default reference clock */
  53. break;
  54. }
  55. clk_put(xusbxti_clk);
  56. }
  57. writel(phyclk, EXYNOS4_PHYCLK);
  58. /* floating prevention logic: disable */
  59. writel((readl(EXYNOS4_PHY1CON) | FPENABLEN), EXYNOS4_PHY1CON);
  60. /* set to normal HSIC 0 and 1 of PHY1 */
  61. writel((readl(EXYNOS4_PHYPWR) & ~PHY1_HSIC_NORMAL_MASK),
  62. EXYNOS4_PHYPWR);
  63. /* set to normal standard USB of PHY1 */
  64. writel((readl(EXYNOS4_PHYPWR) & ~PHY1_STD_NORMAL_MASK), EXYNOS4_PHYPWR);
  65. /* reset all ports of both PHY and Link */
  66. rstcon = readl(EXYNOS4_RSTCON) | HOST_LINK_PORT_SWRST_MASK |
  67. PHY1_SWRST_MASK;
  68. writel(rstcon, EXYNOS4_RSTCON);
  69. udelay(10);
  70. rstcon &= ~(HOST_LINK_PORT_SWRST_MASK | PHY1_SWRST_MASK);
  71. writel(rstcon, EXYNOS4_RSTCON);
  72. udelay(50);
  73. clk_disable(otg_clk);
  74. clk_put(otg_clk);
  75. return 0;
  76. }
  77. static int exynos4_usb_phy1_exit(struct platform_device *pdev)
  78. {
  79. struct clk *otg_clk;
  80. int err;
  81. otg_clk = clk_get(&pdev->dev, "otg");
  82. if (IS_ERR(otg_clk)) {
  83. dev_err(&pdev->dev, "Failed to get otg clock\n");
  84. return PTR_ERR(otg_clk);
  85. }
  86. err = clk_enable(otg_clk);
  87. if (err) {
  88. clk_put(otg_clk);
  89. return err;
  90. }
  91. writel((readl(EXYNOS4_PHYPWR) | PHY1_STD_ANALOG_POWERDOWN),
  92. EXYNOS4_PHYPWR);
  93. writel(readl(S5P_USBHOST_PHY_CONTROL) & ~S5P_USBHOST_PHY_ENABLE,
  94. S5P_USBHOST_PHY_CONTROL);
  95. clk_disable(otg_clk);
  96. clk_put(otg_clk);
  97. return 0;
  98. }
  99. int s5p_usb_phy_init(struct platform_device *pdev, int type)
  100. {
  101. if (type == S5P_USB_PHY_HOST)
  102. return exynos4_usb_phy1_init(pdev);
  103. return -EINVAL;
  104. }
  105. int s5p_usb_phy_exit(struct platform_device *pdev, int type)
  106. {
  107. if (type == S5P_USB_PHY_HOST)
  108. return exynos4_usb_phy1_exit(pdev);
  109. return -EINVAL;
  110. }