pm_bus.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Runtime PM support code for OMAP1
  3. *
  4. * Author: Kevin Hilman, Deep Root Systems, LLC
  5. *
  6. * Copyright (C) 2010 Texas Instruments, Inc.
  7. *
  8. * This file is licensed under the terms of the GNU General Public
  9. * License version 2. This program is licensed "as is" without any
  10. * warranty of any kind, whether express or implied.
  11. */
  12. #include <linux/init.h>
  13. #include <linux/kernel.h>
  14. #include <linux/io.h>
  15. #include <linux/pm_runtime.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/mutex.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <plat/omap_device.h>
  21. #include <plat/omap-pm.h>
  22. #ifdef CONFIG_PM_RUNTIME
  23. static int omap1_pm_runtime_suspend(struct device *dev)
  24. {
  25. struct clk *iclk, *fclk;
  26. int ret = 0;
  27. dev_dbg(dev, "%s\n", __func__);
  28. ret = pm_generic_runtime_suspend(dev);
  29. fclk = clk_get(dev, "fck");
  30. if (!IS_ERR(fclk)) {
  31. clk_disable(fclk);
  32. clk_put(fclk);
  33. }
  34. iclk = clk_get(dev, "ick");
  35. if (!IS_ERR(iclk)) {
  36. clk_disable(iclk);
  37. clk_put(iclk);
  38. }
  39. return 0;
  40. };
  41. static int omap1_pm_runtime_resume(struct device *dev)
  42. {
  43. struct clk *iclk, *fclk;
  44. dev_dbg(dev, "%s\n", __func__);
  45. iclk = clk_get(dev, "ick");
  46. if (!IS_ERR(iclk)) {
  47. clk_enable(iclk);
  48. clk_put(iclk);
  49. }
  50. fclk = clk_get(dev, "fck");
  51. if (!IS_ERR(fclk)) {
  52. clk_enable(fclk);
  53. clk_put(fclk);
  54. }
  55. return pm_generic_runtime_resume(dev);
  56. };
  57. static int __init omap1_pm_runtime_init(void)
  58. {
  59. const struct dev_pm_ops *pm;
  60. struct dev_pm_ops *omap_pm;
  61. if (!cpu_class_is_omap1())
  62. return -ENODEV;
  63. pm = platform_bus_get_pm_ops();
  64. if (!pm) {
  65. pr_err("%s: unable to get dev_pm_ops from platform_bus\n",
  66. __func__);
  67. return -ENODEV;
  68. }
  69. omap_pm = kmemdup(pm, sizeof(struct dev_pm_ops), GFP_KERNEL);
  70. if (!omap_pm) {
  71. pr_err("%s: unable to alloc memory for new dev_pm_ops\n",
  72. __func__);
  73. return -ENOMEM;
  74. }
  75. omap_pm->runtime_suspend = omap1_pm_runtime_suspend;
  76. omap_pm->runtime_resume = omap1_pm_runtime_resume;
  77. platform_bus_set_pm_ops(omap_pm);
  78. return 0;
  79. }
  80. core_initcall(omap1_pm_runtime_init);
  81. #endif /* CONFIG_PM_RUNTIME */