clock-debug.c 2.7 KB

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