clock-debug.c 3.0 KB

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