2 * Copyright (c) 2009 Simtec Electronics
3 * http://armlinux.simtec.co.uk/
4 * Ben Dooks <ben@simtec.co.uk>
6 * S3C24XX CPU Frequency scaling - debugfs status support
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.
13 #include <linux/init.h>
14 #include <linux/export.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>
22 #include <plat/cpu-freq-core.h>
24 static struct dentry *dbgfs_root;
25 static struct dentry *dbgfs_file_io;
26 static struct dentry *dbgfs_file_info;
27 static struct dentry *dbgfs_file_board;
29 #define print_ns(x) ((x) / 10), ((x) % 10)
31 static void show_max(struct seq_file *seq, struct s3c_freq *f)
33 seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n",
34 f->fclk, f->hclk, f->pclk, f->armclk);
37 static int board_show(struct seq_file *seq, void *p)
39 struct s3c_cpufreq_config *cfg;
40 struct s3c_cpufreq_board *brd;
42 cfg = s3c_cpufreq_getconfig();
44 seq_printf(seq, "no configuration registered\n");
50 seq_printf(seq, "no board definition set?\n");
54 seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh);
55 seq_printf(seq, "auto_io=%u\n", brd->auto_io);
56 seq_printf(seq, "need_io=%u\n", brd->need_io);
58 show_max(seq, &brd->max);
64 static int fops_board_open(struct inode *inode, struct file *file)
66 return single_open(file, board_show, NULL);
69 static const struct file_operations fops_board = {
70 .open = fops_board_open,
73 .release = single_release,
77 static int info_show(struct seq_file *seq, void *p)
79 struct s3c_cpufreq_config *cfg;
81 cfg = s3c_cpufreq_getconfig();
83 seq_printf(seq, "no configuration registered\n");
87 seq_printf(seq, " FCLK %ld Hz\n", cfg->freq.fclk);
88 seq_printf(seq, " HCLK %ld Hz (%lu.%lu ns)\n",
89 cfg->freq.hclk, print_ns(cfg->freq.hclk_tns));
90 seq_printf(seq, " PCLK %ld Hz\n", cfg->freq.hclk);
91 seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk);
92 seq_printf(seq, "\n");
94 show_max(seq, &cfg->max);
96 seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n",
97 cfg->divs.h_divisor, cfg->divs.p_divisor,
98 cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off");
99 seq_printf(seq, "\n");
101 seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll);
106 static int fops_info_open(struct inode *inode, struct file *file)
108 return single_open(file, info_show, NULL);
111 static const struct file_operations fops_info = {
112 .open = fops_info_open,
115 .release = single_release,
116 .owner = THIS_MODULE,
119 static int io_show(struct seq_file *seq, void *p)
121 void (*show_bank)(struct seq_file *, struct s3c_cpufreq_config *, union s3c_iobank *);
122 struct s3c_cpufreq_config *cfg;
123 struct s3c_iotimings *iot;
124 union s3c_iobank *iob;
127 cfg = s3c_cpufreq_getconfig();
129 seq_printf(seq, "no configuration registered\n");
133 show_bank = cfg->info->debug_io_show;
135 seq_printf(seq, "no code to show bank timing\n");
139 iot = s3c_cpufreq_getiotimings();
141 seq_printf(seq, "no io timings registered\n");
145 seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns));
147 for (bank = 0; bank < MAX_BANKS; bank++) {
148 iob = &iot->bank[bank];
150 seq_printf(seq, "bank %d: ", bank);
153 seq_printf(seq, "nothing set\n");
157 show_bank(seq, cfg, iob);
163 static int fops_io_open(struct inode *inode, struct file *file)
165 return single_open(file, io_show, NULL);
168 static const struct file_operations fops_io = {
169 .open = fops_io_open,
172 .release = single_release,
173 .owner = THIS_MODULE,
177 static int __init s3c_freq_debugfs_init(void)
179 dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL);
180 if (IS_ERR(dbgfs_root)) {
181 printk(KERN_ERR "%s: error creating debugfs root\n", __func__);
182 return PTR_ERR(dbgfs_root);
185 dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root,
188 dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root,
191 dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root,
197 late_initcall(s3c_freq_debugfs_init);