clock-pcom.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2007 Google, Inc.
  3. * Copyright (c) 2007-2010, Code Aurora Forum. All rights reserved.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #include <linux/err.h>
  16. #include <linux/ctype.h>
  17. #include <linux/stddef.h>
  18. #include <mach/clk.h>
  19. #include "proc_comm.h"
  20. #include "clock.h"
  21. /*
  22. * glue for the proc_comm interface
  23. */
  24. int pc_clk_enable(unsigned id)
  25. {
  26. int rc = msm_proc_comm(PCOM_CLKCTL_RPC_ENABLE, &id, NULL);
  27. if (rc < 0)
  28. return rc;
  29. else
  30. return (int)id < 0 ? -EINVAL : 0;
  31. }
  32. void pc_clk_disable(unsigned id)
  33. {
  34. msm_proc_comm(PCOM_CLKCTL_RPC_DISABLE, &id, NULL);
  35. }
  36. int pc_clk_reset(unsigned id, enum clk_reset_action action)
  37. {
  38. int rc;
  39. if (action == CLK_RESET_ASSERT)
  40. rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_ASSERT, &id, NULL);
  41. else
  42. rc = msm_proc_comm(PCOM_CLKCTL_RPC_RESET_DEASSERT, &id, NULL);
  43. if (rc < 0)
  44. return rc;
  45. else
  46. return (int)id < 0 ? -EINVAL : 0;
  47. }
  48. int pc_clk_set_rate(unsigned id, unsigned rate)
  49. {
  50. /* The rate _might_ be rounded off to the nearest KHz value by the
  51. * remote function. So a return value of 0 doesn't necessarily mean
  52. * that the exact rate was set successfully.
  53. */
  54. int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_RATE, &id, &rate);
  55. if (rc < 0)
  56. return rc;
  57. else
  58. return (int)id < 0 ? -EINVAL : 0;
  59. }
  60. int pc_clk_set_min_rate(unsigned id, unsigned rate)
  61. {
  62. int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MIN_RATE, &id, &rate);
  63. if (rc < 0)
  64. return rc;
  65. else
  66. return (int)id < 0 ? -EINVAL : 0;
  67. }
  68. int pc_clk_set_max_rate(unsigned id, unsigned rate)
  69. {
  70. int rc = msm_proc_comm(PCOM_CLKCTL_RPC_MAX_RATE, &id, &rate);
  71. if (rc < 0)
  72. return rc;
  73. else
  74. return (int)id < 0 ? -EINVAL : 0;
  75. }
  76. int pc_clk_set_flags(unsigned id, unsigned flags)
  77. {
  78. int rc = msm_proc_comm(PCOM_CLKCTL_RPC_SET_FLAGS, &id, &flags);
  79. if (rc < 0)
  80. return rc;
  81. else
  82. return (int)id < 0 ? -EINVAL : 0;
  83. }
  84. unsigned pc_clk_get_rate(unsigned id)
  85. {
  86. if (msm_proc_comm(PCOM_CLKCTL_RPC_RATE, &id, NULL))
  87. return 0;
  88. else
  89. return id;
  90. }
  91. unsigned pc_clk_is_enabled(unsigned id)
  92. {
  93. if (msm_proc_comm(PCOM_CLKCTL_RPC_ENABLED, &id, NULL))
  94. return 0;
  95. else
  96. return id;
  97. }
  98. long pc_clk_round_rate(unsigned id, unsigned rate)
  99. {
  100. /* Not really supported; pc_clk_set_rate() does rounding on it's own. */
  101. return rate;
  102. }
  103. struct clk_ops clk_ops_pcom = {
  104. .enable = pc_clk_enable,
  105. .disable = pc_clk_disable,
  106. .auto_off = pc_clk_disable,
  107. .reset = pc_clk_reset,
  108. .set_rate = pc_clk_set_rate,
  109. .set_min_rate = pc_clk_set_min_rate,
  110. .set_max_rate = pc_clk_set_max_rate,
  111. .set_flags = pc_clk_set_flags,
  112. .get_rate = pc_clk_get_rate,
  113. .is_enabled = pc_clk_is_enabled,
  114. .round_rate = pc_clk_round_rate,
  115. };