fsl_mx3_udc.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright (C) 2009
  3. * Guennadi Liakhovetski, DENX Software Engineering, <lg@denx.de>
  4. *
  5. * Description:
  6. * Helper routines for i.MX3x SoCs from Freescale, needed by the fsl_usb2_udc.c
  7. * driver to function correctly on these systems.
  8. *
  9. * This program is free software; you can redistribute it and/or modify it
  10. * under the terms of the GNU General Public License as published by the
  11. * Free Software Foundation; either version 2 of the License, or (at your
  12. * option) any later version.
  13. */
  14. #include <linux/clk.h>
  15. #include <linux/delay.h>
  16. #include <linux/err.h>
  17. #include <linux/fsl_devices.h>
  18. #include <linux/platform_device.h>
  19. #include <mach/hardware.h>
  20. static struct clk *mxc_ahb_clk;
  21. static struct clk *mxc_usb_clk;
  22. int fsl_udc_clk_init(struct platform_device *pdev)
  23. {
  24. struct fsl_usb2_platform_data *pdata;
  25. unsigned long freq;
  26. int ret;
  27. pdata = pdev->dev.platform_data;
  28. if (!cpu_is_mx35()) {
  29. mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb");
  30. if (IS_ERR(mxc_ahb_clk))
  31. return PTR_ERR(mxc_ahb_clk);
  32. ret = clk_enable(mxc_ahb_clk);
  33. if (ret < 0) {
  34. dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n");
  35. goto eenahb;
  36. }
  37. }
  38. /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
  39. mxc_usb_clk = clk_get(&pdev->dev, "usb");
  40. if (IS_ERR(mxc_usb_clk)) {
  41. dev_err(&pdev->dev, "clk_get(\"usb\") failed\n");
  42. ret = PTR_ERR(mxc_usb_clk);
  43. goto egusb;
  44. }
  45. freq = clk_get_rate(mxc_usb_clk);
  46. if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
  47. (freq < 59999000 || freq > 60001000)) {
  48. dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
  49. ret = -EINVAL;
  50. goto eclkrate;
  51. }
  52. ret = clk_enable(mxc_usb_clk);
  53. if (ret < 0) {
  54. dev_err(&pdev->dev, "clk_enable(\"usb_clk\") failed\n");
  55. goto eenusb;
  56. }
  57. return 0;
  58. eenusb:
  59. eclkrate:
  60. clk_put(mxc_usb_clk);
  61. mxc_usb_clk = NULL;
  62. egusb:
  63. if (!cpu_is_mx35())
  64. clk_disable(mxc_ahb_clk);
  65. eenahb:
  66. if (!cpu_is_mx35())
  67. clk_put(mxc_ahb_clk);
  68. return ret;
  69. }
  70. void fsl_udc_clk_finalize(struct platform_device *pdev)
  71. {
  72. struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  73. /* ULPI transceivers don't need usbpll */
  74. if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
  75. clk_disable(mxc_usb_clk);
  76. clk_put(mxc_usb_clk);
  77. mxc_usb_clk = NULL;
  78. }
  79. }
  80. void fsl_udc_clk_release(void)
  81. {
  82. if (mxc_usb_clk) {
  83. clk_disable(mxc_usb_clk);
  84. clk_put(mxc_usb_clk);
  85. }
  86. if (!cpu_is_mx35()) {
  87. clk_disable(mxc_ahb_clk);
  88. clk_put(mxc_ahb_clk);
  89. }
  90. }