1/* 2 * 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 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> 21 22#include <plat/cpu-freq-core.h> 23 24static struct dentry *dbgfs_root; 25static struct dentry *dbgfs_file_io; 26static struct dentry *dbgfs_file_info; 27static struct dentry *dbgfs_file_board; 28 29#define print_ns(x) ((x) / 10), ((x) % 10) 30 31static void show_max(struct seq_file *seq, struct s3c_freq *f) 32{ 33 seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n", 34 f->fclk, f->hclk, f->pclk, f->armclk); 35} 36 37static int board_show(struct seq_file *seq, void *p) 38{ 39 struct s3c_cpufreq_config *cfg; 40 struct s3c_cpufreq_board *brd; 41 42 cfg = s3c_cpufreq_getconfig(); 43 if (!cfg) { 44 seq_printf(seq, "no configuration registered\n"); 45 return 0; 46 } 47 48 brd = cfg->board; 49 if (!brd) { 50 seq_printf(seq, "no board definition set?\n"); 51 return 0; 52 } 53 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); 57 58 show_max(seq, &brd->max); 59 60 61 return 0; 62} 63 64static int fops_board_open(struct inode *inode, struct file *file) 65{ 66 return single_open(file, board_show, NULL); 67} 68 69static const struct file_operations fops_board = { 70 .open = fops_board_open, 71 .read = seq_read, 72 .llseek = seq_lseek, 73 .release = single_release, 74 .owner = THIS_MODULE, 75}; 76 77static int info_show(struct seq_file *seq, void *p) 78{ 79 struct s3c_cpufreq_config *cfg; 80 81 cfg = s3c_cpufreq_getconfig(); 82 if (!cfg) { 83 seq_printf(seq, "no configuration registered\n"); 84 return 0; 85 } 86 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"); 93 94 show_max(seq, &cfg->max); 95 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"); 100 101 seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll); 102 103 return 0; 104} 105 106static int fops_info_open(struct inode *inode, struct file *file) 107{ 108 return single_open(file, info_show, NULL); 109} 110 111static const struct file_operations fops_info = { 112 .open = fops_info_open, 113 .read = seq_read, 114 .llseek = seq_lseek, 115 .release = single_release, 116 .owner = THIS_MODULE, 117}; 118 119static int io_show(struct seq_file *seq, void *p) 120{ 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; 125 int bank; 126 127 cfg = s3c_cpufreq_getconfig(); 128 if (!cfg) { 129 seq_printf(seq, "no configuration registered\n"); 130 return 0; 131 } 132 133 show_bank = cfg->info->debug_io_show; 134 if (!show_bank) { 135 seq_printf(seq, "no code to show bank timing\n"); 136 return 0; 137 } 138 139 iot = s3c_cpufreq_getiotimings(); 140 if (!iot) { 141 seq_printf(seq, "no io timings registered\n"); 142 return 0; 143 } 144 145 seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns)); 146 147 for (bank = 0; bank < MAX_BANKS; bank++) { 148 iob = &iot->bank[bank]; 149 150 seq_printf(seq, "bank %d: ", bank); 151 152 if (!iob->io_2410) { 153 seq_printf(seq, "nothing set\n"); 154 continue; 155 } 156 157 show_bank(seq, cfg, iob); 158 } 159 160 return 0; 161} 162 163static int fops_io_open(struct inode *inode, struct file *file) 164{ 165 return single_open(file, io_show, NULL); 166} 167 168static const struct file_operations fops_io = { 169 .open = fops_io_open, 170 .read = seq_read, 171 .llseek = seq_lseek, 172 .release = single_release, 173 .owner = THIS_MODULE, 174}; 175 176 177static int __init s3c_freq_debugfs_init(void) 178{ 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); 183 } 184 185 dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root, 186 NULL, &fops_io); 187 188 dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root, 189 NULL, &fops_info); 190 191 dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root, 192 NULL, &fops_board); 193 194 return 0; 195} 196 197late_initcall(s3c_freq_debugfs_init); 198 199