setup-usb-phy.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // SPDX-License-Identifier: GPL-2.0+
  2. //
  3. // Copyright (C) 2011 Samsung Electronics Co.Ltd
  4. // Author: Joonyoung Shim <jy0922.shim@samsung.com>
  5. #include <linux/clk.h>
  6. #include <linux/delay.h>
  7. #include <linux/err.h>
  8. #include <linux/io.h>
  9. #include <linux/platform_device.h>
  10. #include <mach/map.h>
  11. #include <plat/cpu.h>
  12. #include <plat/usb-phy.h>
  13. #include "regs-sys.h"
  14. #include "regs-usb-hsotg-phy.h"
  15. static int s3c_usb_otgphy_init(struct platform_device *pdev)
  16. {
  17. struct clk *xusbxti;
  18. u32 phyclk;
  19. writel(readl(S3C64XX_OTHERS) | S3C64XX_OTHERS_USBMASK, S3C64XX_OTHERS);
  20. /* set clock frequency for PLL */
  21. phyclk = readl(S3C_PHYCLK) & ~S3C_PHYCLK_CLKSEL_MASK;
  22. xusbxti = clk_get(&pdev->dev, "xusbxti");
  23. if (xusbxti && !IS_ERR(xusbxti)) {
  24. switch (clk_get_rate(xusbxti)) {
  25. case 12 * MHZ:
  26. phyclk |= S3C_PHYCLK_CLKSEL_12M;
  27. break;
  28. case 24 * MHZ:
  29. phyclk |= S3C_PHYCLK_CLKSEL_24M;
  30. break;
  31. default:
  32. case 48 * MHZ:
  33. /* default reference clock */
  34. break;
  35. }
  36. clk_put(xusbxti);
  37. }
  38. /* TODO: select external clock/oscillator */
  39. writel(phyclk | S3C_PHYCLK_CLK_FORCE, S3C_PHYCLK);
  40. /* set to normal OTG PHY */
  41. writel((readl(S3C_PHYPWR) & ~S3C_PHYPWR_NORMAL_MASK), S3C_PHYPWR);
  42. mdelay(1);
  43. /* reset OTG PHY and Link */
  44. writel(S3C_RSTCON_PHY | S3C_RSTCON_HCLK | S3C_RSTCON_PHYCLK,
  45. S3C_RSTCON);
  46. udelay(20); /* at-least 10uS */
  47. writel(0, S3C_RSTCON);
  48. return 0;
  49. }
  50. static int s3c_usb_otgphy_exit(struct platform_device *pdev)
  51. {
  52. writel((readl(S3C_PHYPWR) | S3C_PHYPWR_ANALOG_POWERDOWN |
  53. S3C_PHYPWR_OTG_DISABLE), S3C_PHYPWR);
  54. writel(readl(S3C64XX_OTHERS) & ~S3C64XX_OTHERS_USBMASK, S3C64XX_OTHERS);
  55. return 0;
  56. }
  57. int s5p_usb_phy_init(struct platform_device *pdev, int type)
  58. {
  59. if (type == USB_PHY_TYPE_DEVICE)
  60. return s3c_usb_otgphy_init(pdev);
  61. return -EINVAL;
  62. }
  63. int s5p_usb_phy_exit(struct platform_device *pdev, int type)
  64. {
  65. if (type == USB_PHY_TYPE_DEVICE)
  66. return s3c_usb_otgphy_exit(pdev);
  67. return -EINVAL;
  68. }