fsl_mx3_udc.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. static struct clk *mxc_ahb_clk;
  20. static struct clk *mxc_usb_clk;
  21. int fsl_udc_clk_init(struct platform_device *pdev)
  22. {
  23. struct fsl_usb2_platform_data *pdata;
  24. unsigned long freq;
  25. int ret;
  26. pdata = pdev->dev.platform_data;
  27. mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb");
  28. if (IS_ERR(mxc_ahb_clk))
  29. return PTR_ERR(mxc_ahb_clk);
  30. ret = clk_enable(mxc_ahb_clk);
  31. if (ret < 0) {
  32. dev_err(&pdev->dev, "clk_enable(\"usb_ahb\") failed\n");
  33. goto eenahb;
  34. }
  35. /* make sure USB_CLK is running at 60 MHz +/- 1000 Hz */
  36. mxc_usb_clk = clk_get(&pdev->dev, "usb");
  37. if (IS_ERR(mxc_usb_clk)) {
  38. dev_err(&pdev->dev, "clk_get(\"usb\") failed\n");
  39. ret = PTR_ERR(mxc_usb_clk);
  40. goto egusb;
  41. }
  42. freq = clk_get_rate(mxc_usb_clk);
  43. if (pdata->phy_mode != FSL_USB2_PHY_ULPI &&
  44. (freq < 59999000 || freq > 60001000)) {
  45. dev_err(&pdev->dev, "USB_CLK=%lu, should be 60MHz\n", freq);
  46. goto eclkrate;
  47. }
  48. ret = clk_enable(mxc_usb_clk);
  49. if (ret < 0) {
  50. dev_err(&pdev->dev, "clk_enable(\"usb_clk\") failed\n");
  51. goto eenusb;
  52. }
  53. return 0;
  54. eenusb:
  55. eclkrate:
  56. clk_put(mxc_usb_clk);
  57. mxc_usb_clk = NULL;
  58. egusb:
  59. clk_disable(mxc_ahb_clk);
  60. eenahb:
  61. clk_put(mxc_ahb_clk);
  62. return ret;
  63. }
  64. void fsl_udc_clk_finalize(struct platform_device *pdev)
  65. {
  66. struct fsl_usb2_platform_data *pdata = pdev->dev.platform_data;
  67. /* ULPI transceivers don't need usbpll */
  68. if (pdata->phy_mode == FSL_USB2_PHY_ULPI) {
  69. clk_disable(mxc_usb_clk);
  70. clk_put(mxc_usb_clk);
  71. mxc_usb_clk = NULL;
  72. }
  73. }
  74. void fsl_udc_clk_release(void)
  75. {
  76. if (mxc_usb_clk) {
  77. clk_disable(mxc_usb_clk);
  78. clk_put(mxc_usb_clk);
  79. }
  80. clk_disable(mxc_ahb_clk);
  81. clk_put(mxc_ahb_clk);
  82. }