clock-debug.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/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/ctype.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/clk.h>
  20. #include "clock.h"
  21. #include "clock-pcom.h"
  22. static int clock_debug_rate_set(void *data, u64 val)
  23. {
  24. struct clk *clock = data;
  25. int ret;
  26. /* Only increases to max rate will succeed, but that's actually good
  27. * for debugging purposes so we don't check for error. */
  28. if (clock->flags & CLK_MAX)
  29. clk_set_max_rate(clock, val);
  30. if (clock->flags & CLK_MIN)
  31. ret = clk_set_min_rate(clock, val);
  32. else
  33. ret = clk_set_rate(clock, val);
  34. if (ret != 0)
  35. printk(KERN_ERR "clk_set%s_rate failed (%d)\n",
  36. (clock->flags & CLK_MIN) ? "_min" : "", ret);
  37. return ret;
  38. }
  39. static int clock_debug_rate_get(void *data, u64 *val)
  40. {
  41. struct clk *clock = data;
  42. *val = clk_get_rate(clock);
  43. return 0;
  44. }
  45. DEFINE_SIMPLE_ATTRIBUTE(clock_rate_fops, clock_debug_rate_get,
  46. clock_debug_rate_set, "%llu\n");
  47. static int clock_debug_enable_set(void *data, u64 val)
  48. {
  49. struct clk *clock = data;
  50. int rc = 0;
  51. if (val)
  52. rc = clock->ops->enable(clock->id);
  53. else
  54. clock->ops->disable(clock->id);
  55. return rc;
  56. }
  57. static int clock_debug_enable_get(void *data, u64 *val)
  58. {
  59. struct clk *clock = data;
  60. *val = clock->ops->is_enabled(clock->id);
  61. return 0;
  62. }
  63. DEFINE_SIMPLE_ATTRIBUTE(clock_enable_fops, clock_debug_enable_get,
  64. clock_debug_enable_set, "%llu\n");
  65. static int clock_debug_local_get(void *data, u64 *val)
  66. {
  67. struct clk *clock = data;
  68. *val = clock->ops != &clk_ops_pcom;
  69. return 0;
  70. }
  71. DEFINE_SIMPLE_ATTRIBUTE(clock_local_fops, clock_debug_local_get,
  72. NULL, "%llu\n");
  73. static struct dentry *debugfs_base;
  74. int __init clock_debug_init(void)
  75. {
  76. debugfs_base = debugfs_create_dir("clk", NULL);
  77. if (!debugfs_base)
  78. return -ENOMEM;
  79. return 0;
  80. }
  81. int __init clock_debug_add(struct clk *clock)
  82. {
  83. char temp[50], *ptr;
  84. struct dentry *clk_dir;
  85. if (!debugfs_base)
  86. return -ENOMEM;
  87. strncpy(temp, clock->dbg_name, ARRAY_SIZE(temp)-1);
  88. for (ptr = temp; *ptr; ptr++)
  89. *ptr = tolower(*ptr);
  90. clk_dir = debugfs_create_dir(temp, debugfs_base);
  91. if (!clk_dir)
  92. return -ENOMEM;
  93. if (!debugfs_create_file("rate", S_IRUGO | S_IWUSR, clk_dir,
  94. clock, &clock_rate_fops))
  95. goto error;
  96. if (!debugfs_create_file("enable", S_IRUGO | S_IWUSR, clk_dir,
  97. clock, &clock_enable_fops))
  98. goto error;
  99. if (!debugfs_create_file("is_local", S_IRUGO, clk_dir, clock,
  100. &clock_local_fops))
  101. goto error;
  102. return 0;
  103. error:
  104. debugfs_remove_recursive(clk_dir);
  105. return -ENOMEM;
  106. }