setup-usb-phy.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2012 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
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundationr
  8. */
  9. #include <linux/clk.h>
  10. #include <linux/delay.h>
  11. #include <linux/err.h>
  12. #include <linux/io.h>
  13. #include <linux/platform_device.h>
  14. #include <mach/map.h>
  15. #include <mach/regs-sys.h>
  16. #include <plat/cpu.h>
  17. #include <plat/regs-usb-hsotg-phy.h>
  18. #include <plat/usb-phy.h>
  19. static int s5pv210_usb_otgphy_init(struct platform_device *pdev)
  20. {
  21. struct clk *xusbxti;
  22. u32 phyclk;
  23. writel(readl(S5PV210_USB_PHY_CON) | S5PV210_USB_PHY0_EN,
  24. S5PV210_USB_PHY_CON);
  25. /* set clock frequency for PLL */
  26. phyclk = readl(S3C_PHYCLK) & ~S3C_PHYCLK_CLKSEL_MASK;
  27. xusbxti = clk_get(&pdev->dev, "xusbxti");
  28. if (xusbxti && !IS_ERR(xusbxti)) {
  29. switch (clk_get_rate(xusbxti)) {
  30. case 12 * MHZ:
  31. phyclk |= S3C_PHYCLK_CLKSEL_12M;
  32. break;
  33. case 24 * MHZ:
  34. phyclk |= S3C_PHYCLK_CLKSEL_24M;
  35. break;
  36. default:
  37. case 48 * MHZ:
  38. /* default reference clock */
  39. break;
  40. }
  41. clk_put(xusbxti);
  42. }
  43. /* TODO: select external clock/oscillator */
  44. writel(phyclk | S3C_PHYCLK_CLK_FORCE, S3C_PHYCLK);
  45. /* set to normal OTG PHY */
  46. writel((readl(S3C_PHYPWR) & ~S3C_PHYPWR_NORMAL_MASK), S3C_PHYPWR);
  47. mdelay(1);
  48. /* reset OTG PHY and Link */
  49. writel(S3C_RSTCON_PHY | S3C_RSTCON_HCLK | S3C_RSTCON_PHYCLK,
  50. S3C_RSTCON);
  51. udelay(20); /* at-least 10uS */
  52. writel(0, S3C_RSTCON);
  53. return 0;
  54. }
  55. static int s5pv210_usb_otgphy_exit(struct platform_device *pdev)
  56. {
  57. writel((readl(S3C_PHYPWR) | S3C_PHYPWR_ANALOG_POWERDOWN |
  58. S3C_PHYPWR_OTG_DISABLE), S3C_PHYPWR);
  59. writel(readl(S5PV210_USB_PHY_CON) & ~S5PV210_USB_PHY0_EN,
  60. S5PV210_USB_PHY_CON);
  61. return 0;
  62. }
  63. int s5p_usb_phy_init(struct platform_device *pdev, int type)
  64. {
  65. if (type == S5P_USB_PHY_DEVICE)
  66. return s5pv210_usb_otgphy_init(pdev);
  67. return -EINVAL;
  68. }
  69. int s5p_usb_phy_exit(struct platform_device *pdev, int type)
  70. {
  71. if (type == S5P_USB_PHY_DEVICE)
  72. return s5pv210_usb_otgphy_exit(pdev);
  73. return -EINVAL;
  74. }