s3c24xx-cpufreq-debugfs.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // SPDX-License-Identifier: GPL-2.0-only
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  10. #include <linux/init.h>
  11. #include <linux/export.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/ioport.h>
  14. #include <linux/cpufreq.h>
  15. #include <linux/debugfs.h>
  16. #include <linux/seq_file.h>
  17. #include <linux/err.h>
  18. #include <linux/soc/samsung/s3c-cpufreq-core.h>
  19. static struct dentry *dbgfs_root;
  20. static struct dentry *dbgfs_file_io;
  21. static struct dentry *dbgfs_file_info;
  22. static struct dentry *dbgfs_file_board;
  23. #define print_ns(x) ((x) / 10), ((x) % 10)
  24. static void show_max(struct seq_file *seq, struct s3c_freq *f)
  25. {
  26. seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n",
  27. f->fclk, f->hclk, f->pclk, f->armclk);
  28. }
  29. static int board_show(struct seq_file *seq, void *p)
  30. {
  31. struct s3c_cpufreq_config *cfg;
  32. struct s3c_cpufreq_board *brd;
  33. cfg = s3c_cpufreq_getconfig();
  34. if (!cfg) {
  35. seq_printf(seq, "no configuration registered\n");
  36. return 0;
  37. }
  38. brd = cfg->board;
  39. if (!brd) {
  40. seq_printf(seq, "no board definition set?\n");
  41. return 0;
  42. }
  43. seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh);
  44. seq_printf(seq, "auto_io=%u\n", brd->auto_io);
  45. seq_printf(seq, "need_io=%u\n", brd->need_io);
  46. show_max(seq, &brd->max);
  47. return 0;
  48. }
  49. DEFINE_SHOW_ATTRIBUTE(board);
  50. static int info_show(struct seq_file *seq, void *p)
  51. {
  52. struct s3c_cpufreq_config *cfg;
  53. cfg = s3c_cpufreq_getconfig();
  54. if (!cfg) {
  55. seq_printf(seq, "no configuration registered\n");
  56. return 0;
  57. }
  58. seq_printf(seq, " FCLK %ld Hz\n", cfg->freq.fclk);
  59. seq_printf(seq, " HCLK %ld Hz (%lu.%lu ns)\n",
  60. cfg->freq.hclk, print_ns(cfg->freq.hclk_tns));
  61. seq_printf(seq, " PCLK %ld Hz\n", cfg->freq.hclk);
  62. seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk);
  63. seq_printf(seq, "\n");
  64. show_max(seq, &cfg->max);
  65. seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n",
  66. cfg->divs.h_divisor, cfg->divs.p_divisor,
  67. cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off");
  68. seq_printf(seq, "\n");
  69. seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll);
  70. return 0;
  71. }
  72. DEFINE_SHOW_ATTRIBUTE(info);
  73. static int io_show(struct seq_file *seq, void *p)
  74. {
  75. void (*show_bank)(struct seq_file *, struct s3c_cpufreq_config *, union s3c_iobank *);
  76. struct s3c_cpufreq_config *cfg;
  77. struct s3c_iotimings *iot;
  78. union s3c_iobank *iob;
  79. int bank;
  80. cfg = s3c_cpufreq_getconfig();
  81. if (!cfg) {
  82. seq_printf(seq, "no configuration registered\n");
  83. return 0;
  84. }
  85. show_bank = cfg->info->debug_io_show;
  86. if (!show_bank) {
  87. seq_printf(seq, "no code to show bank timing\n");
  88. return 0;
  89. }
  90. iot = s3c_cpufreq_getiotimings();
  91. if (!iot) {
  92. seq_printf(seq, "no io timings registered\n");
  93. return 0;
  94. }
  95. seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns));
  96. for (bank = 0; bank < MAX_BANKS; bank++) {
  97. iob = &iot->bank[bank];
  98. seq_printf(seq, "bank %d: ", bank);
  99. if (!iob->io_2410) {
  100. seq_printf(seq, "nothing set\n");
  101. continue;
  102. }
  103. show_bank(seq, cfg, iob);
  104. }
  105. return 0;
  106. }
  107. DEFINE_SHOW_ATTRIBUTE(io);
  108. static int __init s3c_freq_debugfs_init(void)
  109. {
  110. dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL);
  111. if (IS_ERR(dbgfs_root)) {
  112. pr_err("%s: error creating debugfs root\n", __func__);
  113. return PTR_ERR(dbgfs_root);
  114. }
  115. dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root,
  116. NULL, &io_fops);
  117. dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root,
  118. NULL, &info_fops);
  119. dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root,
  120. NULL, &board_fops);
  121. return 0;
  122. }
  123. late_initcall(s3c_freq_debugfs_init);