blob: 0df87b6480fe7d54b108f551a36136a245634508 [file] [log] [blame]
Kukjin Kim09ec1d72013-01-31 16:54:38 -08001/*
Ben Dookse6d197a2009-07-30 23:23:42 +01002 * Copyright (c) 2009 Simtec Electronics
3 * http://armlinux.simtec.co.uk/
4 * Ben Dooks <ben@simtec.co.uk>
5 *
6 * S3C24XX CPU Frequency scaling - debugfs status support
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11*/
12
Joe Perches1c5864e2016-04-05 13:28:25 -070013#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
14
Ben Dookse6d197a2009-07-30 23:23:42 +010015#include <linux/init.h>
Kukjin Kima69e4c22011-11-17 01:14:38 +090016#include <linux/export.h>
Ben Dookse6d197a2009-07-30 23:23:42 +010017#include <linux/interrupt.h>
18#include <linux/ioport.h>
19#include <linux/cpufreq.h>
20#include <linux/debugfs.h>
21#include <linux/seq_file.h>
22#include <linux/err.h>
23
24#include <plat/cpu-freq-core.h>
25
26static struct dentry *dbgfs_root;
27static struct dentry *dbgfs_file_io;
28static struct dentry *dbgfs_file_info;
29static struct dentry *dbgfs_file_board;
30
31#define print_ns(x) ((x) / 10), ((x) % 10)
32
33static void show_max(struct seq_file *seq, struct s3c_freq *f)
34{
35 seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n",
36 f->fclk, f->hclk, f->pclk, f->armclk);
37}
38
39static int board_show(struct seq_file *seq, void *p)
40{
41 struct s3c_cpufreq_config *cfg;
42 struct s3c_cpufreq_board *brd;
43
44 cfg = s3c_cpufreq_getconfig();
45 if (!cfg) {
46 seq_printf(seq, "no configuration registered\n");
47 return 0;
48 }
49
50 brd = cfg->board;
51 if (!brd) {
52 seq_printf(seq, "no board definition set?\n");
53 return 0;
54 }
55
56 seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh);
57 seq_printf(seq, "auto_io=%u\n", brd->auto_io);
58 seq_printf(seq, "need_io=%u\n", brd->need_io);
59
60 show_max(seq, &brd->max);
61
62
63 return 0;
64}
65
Yangtao Li6e218d22018-11-07 11:13:46 -050066DEFINE_SHOW_ATTRIBUTE(board);
Ben Dookse6d197a2009-07-30 23:23:42 +010067
68static int info_show(struct seq_file *seq, void *p)
69{
70 struct s3c_cpufreq_config *cfg;
71
72 cfg = s3c_cpufreq_getconfig();
73 if (!cfg) {
74 seq_printf(seq, "no configuration registered\n");
75 return 0;
76 }
77
78 seq_printf(seq, " FCLK %ld Hz\n", cfg->freq.fclk);
79 seq_printf(seq, " HCLK %ld Hz (%lu.%lu ns)\n",
80 cfg->freq.hclk, print_ns(cfg->freq.hclk_tns));
81 seq_printf(seq, " PCLK %ld Hz\n", cfg->freq.hclk);
82 seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk);
83 seq_printf(seq, "\n");
84
85 show_max(seq, &cfg->max);
86
87 seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n",
88 cfg->divs.h_divisor, cfg->divs.p_divisor,
89 cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off");
90 seq_printf(seq, "\n");
91
92 seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll);
93
94 return 0;
95}
96
Yangtao Li6e218d22018-11-07 11:13:46 -050097DEFINE_SHOW_ATTRIBUTE(info);
Ben Dookse6d197a2009-07-30 23:23:42 +010098
99static int io_show(struct seq_file *seq, void *p)
100{
101 void (*show_bank)(struct seq_file *, struct s3c_cpufreq_config *, union s3c_iobank *);
102 struct s3c_cpufreq_config *cfg;
103 struct s3c_iotimings *iot;
104 union s3c_iobank *iob;
105 int bank;
106
107 cfg = s3c_cpufreq_getconfig();
108 if (!cfg) {
109 seq_printf(seq, "no configuration registered\n");
110 return 0;
111 }
112
113 show_bank = cfg->info->debug_io_show;
114 if (!show_bank) {
115 seq_printf(seq, "no code to show bank timing\n");
116 return 0;
117 }
118
119 iot = s3c_cpufreq_getiotimings();
120 if (!iot) {
121 seq_printf(seq, "no io timings registered\n");
122 return 0;
123 }
124
125 seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns));
126
127 for (bank = 0; bank < MAX_BANKS; bank++) {
128 iob = &iot->bank[bank];
129
130 seq_printf(seq, "bank %d: ", bank);
131
132 if (!iob->io_2410) {
133 seq_printf(seq, "nothing set\n");
134 continue;
135 }
136
137 show_bank(seq, cfg, iob);
138 }
139
140 return 0;
141}
142
Yangtao Li6e218d22018-11-07 11:13:46 -0500143DEFINE_SHOW_ATTRIBUTE(io);
Ben Dookse6d197a2009-07-30 23:23:42 +0100144
145static int __init s3c_freq_debugfs_init(void)
146{
147 dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL);
148 if (IS_ERR(dbgfs_root)) {
Joe Perchesb49c22a2016-04-05 13:28:24 -0700149 pr_err("%s: error creating debugfs root\n", __func__);
Ben Dookse6d197a2009-07-30 23:23:42 +0100150 return PTR_ERR(dbgfs_root);
151 }
152
153 dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root,
Yangtao Li6e218d22018-11-07 11:13:46 -0500154 NULL, &io_fops);
Ben Dookse6d197a2009-07-30 23:23:42 +0100155
156 dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root,
Yangtao Li6e218d22018-11-07 11:13:46 -0500157 NULL, &info_fops);
Ben Dookse6d197a2009-07-30 23:23:42 +0100158
159 dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root,
Yangtao Li6e218d22018-11-07 11:13:46 -0500160 NULL, &board_fops);
Ben Dookse6d197a2009-07-30 23:23:42 +0100161
162 return 0;
163}
164
165late_initcall(s3c_freq_debugfs_init);
166