Thomas Gleixner | d2912cb | 2019-06-04 10:11:33 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kukjin Kim | 09ec1d7 | 2013-01-31 16:54:38 -0800 | [diff] [blame] | 2 | /* |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 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 |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 10 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 11 | |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 12 | #include <linux/init.h> |
Kukjin Kim | a69e4c2 | 2011-11-17 01:14:38 +0900 | [diff] [blame] | 13 | #include <linux/export.h> |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 14 | #include <linux/interrupt.h> |
| 15 | #include <linux/ioport.h> |
| 16 | #include <linux/cpufreq.h> |
| 17 | #include <linux/debugfs.h> |
| 18 | #include <linux/seq_file.h> |
| 19 | #include <linux/err.h> |
| 20 | |
Arnd Bergmann | 81b11a6 | 2020-08-06 20:20:52 +0200 | [diff] [blame] | 21 | #include <linux/soc/samsung/s3c-cpufreq-core.h> |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 22 | |
| 23 | static struct dentry *dbgfs_root; |
| 24 | static struct dentry *dbgfs_file_io; |
| 25 | static struct dentry *dbgfs_file_info; |
| 26 | static struct dentry *dbgfs_file_board; |
| 27 | |
| 28 | #define print_ns(x) ((x) / 10), ((x) % 10) |
| 29 | |
| 30 | static void show_max(struct seq_file *seq, struct s3c_freq *f) |
| 31 | { |
| 32 | seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n", |
| 33 | f->fclk, f->hclk, f->pclk, f->armclk); |
| 34 | } |
| 35 | |
| 36 | static int board_show(struct seq_file *seq, void *p) |
| 37 | { |
| 38 | struct s3c_cpufreq_config *cfg; |
| 39 | struct s3c_cpufreq_board *brd; |
| 40 | |
| 41 | cfg = s3c_cpufreq_getconfig(); |
| 42 | if (!cfg) { |
| 43 | seq_printf(seq, "no configuration registered\n"); |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | brd = cfg->board; |
| 48 | if (!brd) { |
| 49 | seq_printf(seq, "no board definition set?\n"); |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh); |
| 54 | seq_printf(seq, "auto_io=%u\n", brd->auto_io); |
| 55 | seq_printf(seq, "need_io=%u\n", brd->need_io); |
| 56 | |
| 57 | show_max(seq, &brd->max); |
| 58 | |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 63 | DEFINE_SHOW_ATTRIBUTE(board); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 64 | |
| 65 | static int info_show(struct seq_file *seq, void *p) |
| 66 | { |
| 67 | struct s3c_cpufreq_config *cfg; |
| 68 | |
| 69 | cfg = s3c_cpufreq_getconfig(); |
| 70 | if (!cfg) { |
| 71 | seq_printf(seq, "no configuration registered\n"); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | seq_printf(seq, " FCLK %ld Hz\n", cfg->freq.fclk); |
| 76 | seq_printf(seq, " HCLK %ld Hz (%lu.%lu ns)\n", |
| 77 | cfg->freq.hclk, print_ns(cfg->freq.hclk_tns)); |
| 78 | seq_printf(seq, " PCLK %ld Hz\n", cfg->freq.hclk); |
| 79 | seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk); |
| 80 | seq_printf(seq, "\n"); |
| 81 | |
| 82 | show_max(seq, &cfg->max); |
| 83 | |
| 84 | seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n", |
| 85 | cfg->divs.h_divisor, cfg->divs.p_divisor, |
| 86 | cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off"); |
| 87 | seq_printf(seq, "\n"); |
| 88 | |
| 89 | seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll); |
| 90 | |
| 91 | return 0; |
| 92 | } |
| 93 | |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 94 | DEFINE_SHOW_ATTRIBUTE(info); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 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 | |
| 104 | cfg = s3c_cpufreq_getconfig(); |
| 105 | if (!cfg) { |
| 106 | seq_printf(seq, "no configuration registered\n"); |
| 107 | return 0; |
| 108 | } |
| 109 | |
| 110 | show_bank = cfg->info->debug_io_show; |
| 111 | if (!show_bank) { |
| 112 | seq_printf(seq, "no code to show bank timing\n"); |
| 113 | return 0; |
| 114 | } |
| 115 | |
| 116 | iot = s3c_cpufreq_getiotimings(); |
| 117 | if (!iot) { |
| 118 | seq_printf(seq, "no io timings registered\n"); |
| 119 | return 0; |
| 120 | } |
| 121 | |
| 122 | seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns)); |
| 123 | |
| 124 | for (bank = 0; bank < MAX_BANKS; bank++) { |
| 125 | iob = &iot->bank[bank]; |
| 126 | |
| 127 | seq_printf(seq, "bank %d: ", bank); |
| 128 | |
| 129 | if (!iob->io_2410) { |
| 130 | seq_printf(seq, "nothing set\n"); |
| 131 | continue; |
| 132 | } |
| 133 | |
| 134 | show_bank(seq, cfg, iob); |
| 135 | } |
| 136 | |
| 137 | return 0; |
| 138 | } |
| 139 | |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 140 | DEFINE_SHOW_ATTRIBUTE(io); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 141 | |
| 142 | static int __init s3c_freq_debugfs_init(void) |
| 143 | { |
| 144 | dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL); |
| 145 | if (IS_ERR(dbgfs_root)) { |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 146 | pr_err("%s: error creating debugfs root\n", __func__); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 147 | return PTR_ERR(dbgfs_root); |
| 148 | } |
| 149 | |
| 150 | dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root, |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 151 | NULL, &io_fops); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 152 | |
| 153 | dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root, |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 154 | NULL, &info_fops); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 155 | |
| 156 | dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root, |
Yangtao Li | 6e218d2 | 2018-11-07 11:13:46 -0500 | [diff] [blame] | 157 | NULL, &board_fops); |
Ben Dooks | e6d197a | 2009-07-30 23:23:42 +0100 | [diff] [blame] | 158 | |
| 159 | return 0; |
| 160 | } |
| 161 | |
| 162 | late_initcall(s3c_freq_debugfs_init); |
| 163 | |