clock-debugfs.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (C) 2010, Lars-Peter Clausen <lars@metafoo.de>
  3. * JZ4740 SoC clock support debugfs entries
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * You should have received a copy of the GNU General Public License along
  11. * with this program; if not, write to the Free Software Foundation, Inc.,
  12. * 675 Mass Ave, Cambridge, MA 02139, USA.
  13. *
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/module.h>
  17. #include <linux/clk.h>
  18. #include <linux/err.h>
  19. #include <linux/debugfs.h>
  20. #include <linux/uaccess.h>
  21. #include <asm/mach-jz4740/clock.h>
  22. #include "clock.h"
  23. static struct dentry *jz4740_clock_debugfs;
  24. static int jz4740_clock_debugfs_show_enabled(void *data, uint64_t *value)
  25. {
  26. struct clk *clk = data;
  27. *value = clk_is_enabled(clk);
  28. return 0;
  29. }
  30. static int jz4740_clock_debugfs_set_enabled(void *data, uint64_t value)
  31. {
  32. struct clk *clk = data;
  33. if (value)
  34. return clk_enable(clk);
  35. else
  36. clk_disable(clk);
  37. return 0;
  38. }
  39. DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_enabled,
  40. jz4740_clock_debugfs_show_enabled,
  41. jz4740_clock_debugfs_set_enabled,
  42. "%llu\n");
  43. static int jz4740_clock_debugfs_show_rate(void *data, uint64_t *value)
  44. {
  45. struct clk *clk = data;
  46. *value = clk_get_rate(clk);
  47. return 0;
  48. }
  49. DEFINE_SIMPLE_ATTRIBUTE(jz4740_clock_debugfs_ops_rate,
  50. jz4740_clock_debugfs_show_rate,
  51. NULL,
  52. "%llu\n");
  53. void jz4740_clock_debugfs_add_clk(struct clk *clk)
  54. {
  55. if (!jz4740_clock_debugfs)
  56. return;
  57. clk->debugfs_entry = debugfs_create_dir(clk->name, jz4740_clock_debugfs);
  58. debugfs_create_file("rate", S_IWUGO | S_IRUGO, clk->debugfs_entry, clk,
  59. &jz4740_clock_debugfs_ops_rate);
  60. debugfs_create_file("enabled", S_IRUGO, clk->debugfs_entry, clk,
  61. &jz4740_clock_debugfs_ops_enabled);
  62. if (clk->parent) {
  63. char parent_path[100];
  64. snprintf(parent_path, 100, "../%s", clk->parent->name);
  65. clk->debugfs_parent_entry = debugfs_create_symlink("parent",
  66. clk->debugfs_entry,
  67. parent_path);
  68. }
  69. }
  70. /* TODO: Locking */
  71. void jz4740_clock_debugfs_update_parent(struct clk *clk)
  72. {
  73. if (clk->debugfs_parent_entry)
  74. debugfs_remove(clk->debugfs_parent_entry);
  75. if (clk->parent) {
  76. char parent_path[100];
  77. snprintf(parent_path, 100, "../%s", clk->parent->name);
  78. clk->debugfs_parent_entry = debugfs_create_symlink("parent",
  79. clk->debugfs_entry,
  80. parent_path);
  81. } else {
  82. clk->debugfs_parent_entry = NULL;
  83. }
  84. }
  85. void jz4740_clock_debugfs_init(void)
  86. {
  87. jz4740_clock_debugfs = debugfs_create_dir("jz4740-clock", NULL);
  88. if (IS_ERR(jz4740_clock_debugfs))
  89. jz4740_clock_debugfs = NULL;
  90. }