cpu-freq-debugfs.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* linux/arch/arm/plat-s3c24xx/cpu-freq-debugfs.c
  2. *
  3. * Copyright (c) 2009 Simtec Electronics
  4. * http://armlinux.simtec.co.uk/
  5. * Ben Dooks <ben@simtec.co.uk>
  6. *
  7. * S3C24XX CPU Frequency scaling - debugfs status support
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/ioport.h>
  17. #include <linux/cpufreq.h>
  18. #include <linux/debugfs.h>
  19. #include <linux/seq_file.h>
  20. #include <linux/err.h>
  21. #include <plat/cpu-freq-core.h>
  22. static struct dentry *dbgfs_root;
  23. static struct dentry *dbgfs_file_io;
  24. static struct dentry *dbgfs_file_info;
  25. static struct dentry *dbgfs_file_board;
  26. #define print_ns(x) ((x) / 10), ((x) % 10)
  27. static void show_max(struct seq_file *seq, struct s3c_freq *f)
  28. {
  29. seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n",
  30. f->fclk, f->hclk, f->pclk, f->armclk);
  31. }
  32. static int board_show(struct seq_file *seq, void *p)
  33. {
  34. struct s3c_cpufreq_config *cfg;
  35. struct s3c_cpufreq_board *brd;
  36. cfg = s3c_cpufreq_getconfig();
  37. if (!cfg) {
  38. seq_printf(seq, "no configuration registered\n");
  39. return 0;
  40. }
  41. brd = cfg->board;
  42. if (!brd) {
  43. seq_printf(seq, "no board definition set?\n");
  44. return 0;
  45. }
  46. seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh);
  47. seq_printf(seq, "auto_io=%u\n", brd->auto_io);
  48. seq_printf(seq, "need_io=%u\n", brd->need_io);
  49. show_max(seq, &brd->max);
  50. return 0;
  51. }
  52. static int fops_board_open(struct inode *inode, struct file *file)
  53. {
  54. return single_open(file, board_show, NULL);
  55. }
  56. static const struct file_operations fops_board = {
  57. .open = fops_board_open,
  58. .read = seq_read,
  59. .llseek = seq_lseek,
  60. .release = single_release,
  61. .owner = THIS_MODULE,
  62. };
  63. static int info_show(struct seq_file *seq, void *p)
  64. {
  65. struct s3c_cpufreq_config *cfg;
  66. cfg = s3c_cpufreq_getconfig();
  67. if (!cfg) {
  68. seq_printf(seq, "no configuration registered\n");
  69. return 0;
  70. }
  71. seq_printf(seq, " FCLK %ld Hz\n", cfg->freq.fclk);
  72. seq_printf(seq, " HCLK %ld Hz (%lu.%lu ns)\n",
  73. cfg->freq.hclk, print_ns(cfg->freq.hclk_tns));
  74. seq_printf(seq, " PCLK %ld Hz\n", cfg->freq.hclk);
  75. seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk);
  76. seq_printf(seq, "\n");
  77. show_max(seq, &cfg->max);
  78. seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n",
  79. cfg->divs.h_divisor, cfg->divs.p_divisor,
  80. cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off");
  81. seq_printf(seq, "\n");
  82. seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll);
  83. return 0;
  84. }
  85. static int fops_info_open(struct inode *inode, struct file *file)
  86. {
  87. return single_open(file, info_show, NULL);
  88. }
  89. static const struct file_operations fops_info = {
  90. .open = fops_info_open,
  91. .read = seq_read,
  92. .llseek = seq_lseek,
  93. .release = single_release,
  94. .owner = THIS_MODULE,
  95. };
  96. static int io_show(struct seq_file *seq, void *p)
  97. {
  98. void (*show_bank)(struct seq_file *, struct s3c_cpufreq_config *, union s3c_iobank *);
  99. struct s3c_cpufreq_config *cfg;
  100. struct s3c_iotimings *iot;
  101. union s3c_iobank *iob;
  102. int bank;
  103. cfg = s3c_cpufreq_getconfig();
  104. if (!cfg) {
  105. seq_printf(seq, "no configuration registered\n");
  106. return 0;
  107. }
  108. show_bank = cfg->info->debug_io_show;
  109. if (!show_bank) {
  110. seq_printf(seq, "no code to show bank timing\n");
  111. return 0;
  112. }
  113. iot = s3c_cpufreq_getiotimings();
  114. if (!iot) {
  115. seq_printf(seq, "no io timings registered\n");
  116. return 0;
  117. }
  118. seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns));
  119. for (bank = 0; bank < MAX_BANKS; bank++) {
  120. iob = &iot->bank[bank];
  121. seq_printf(seq, "bank %d: ", bank);
  122. if (!iob->io_2410) {
  123. seq_printf(seq, "nothing set\n");
  124. continue;
  125. }
  126. show_bank(seq, cfg, iob);
  127. }
  128. return 0;
  129. }
  130. static int fops_io_open(struct inode *inode, struct file *file)
  131. {
  132. return single_open(file, io_show, NULL);
  133. }
  134. static const struct file_operations fops_io = {
  135. .open = fops_io_open,
  136. .read = seq_read,
  137. .llseek = seq_lseek,
  138. .release = single_release,
  139. .owner = THIS_MODULE,
  140. };
  141. static int __init s3c_freq_debugfs_init(void)
  142. {
  143. dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL);
  144. if (IS_ERR(dbgfs_root)) {
  145. printk(KERN_ERR "%s: error creating debugfs root\n", __func__);
  146. return PTR_ERR(dbgfs_root);
  147. }
  148. dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root,
  149. NULL, &fops_io);
  150. dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root,
  151. NULL, &fops_info);
  152. dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root,
  153. NULL, &fops_board);
  154. return 0;
  155. }
  156. late_initcall(s3c_freq_debugfs_init);