Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Copyright (c) 2009 Simtec Electronics
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *	http://armlinux.simtec.co.uk/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *	Ben Dooks <ben@simtec.co.uk>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * S3C24XX CPU Frequency scaling - debugfs status support
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/export.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/ioport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/cpufreq.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/debugfs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/seq_file.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/soc/samsung/s3c-cpufreq-core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static struct dentry *dbgfs_root;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) static struct dentry *dbgfs_file_io;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) static struct dentry *dbgfs_file_info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static struct dentry *dbgfs_file_board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define print_ns(x) ((x) / 10), ((x) % 10)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) static void show_max(struct seq_file *seq, struct s3c_freq *f)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	seq_printf(seq, "MAX: F=%lu, H=%lu, P=%lu, A=%lu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 		   f->fclk, f->hclk, f->pclk, f->armclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) static int board_show(struct seq_file *seq, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct s3c_cpufreq_config *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct s3c_cpufreq_board *brd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	cfg = s3c_cpufreq_getconfig();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 		seq_printf(seq, "no configuration registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	brd = cfg->board;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	if (!brd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 		seq_printf(seq, "no board definition set?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	seq_printf(seq, "SDRAM refresh %u ns\n", brd->refresh);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	seq_printf(seq, "auto_io=%u\n", brd->auto_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	seq_printf(seq, "need_io=%u\n", brd->need_io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	show_max(seq, &brd->max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) DEFINE_SHOW_ATTRIBUTE(board);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) static int info_show(struct seq_file *seq, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	struct s3c_cpufreq_config *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	cfg = s3c_cpufreq_getconfig();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		seq_printf(seq, "no configuration registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	seq_printf(seq, "  FCLK %ld Hz\n", cfg->freq.fclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	seq_printf(seq, "  HCLK %ld Hz (%lu.%lu ns)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		   cfg->freq.hclk, print_ns(cfg->freq.hclk_tns));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	seq_printf(seq, "  PCLK %ld Hz\n", cfg->freq.hclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	seq_printf(seq, "ARMCLK %ld Hz\n", cfg->freq.armclk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	seq_printf(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	show_max(seq, &cfg->max);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	seq_printf(seq, "Divisors: P=%d, H=%d, A=%d, dvs=%s\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		   cfg->divs.h_divisor, cfg->divs.p_divisor,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		   cfg->divs.arm_divisor, cfg->divs.dvs ? "on" : "off");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	seq_printf(seq, "\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	seq_printf(seq, "lock_pll=%u\n", cfg->lock_pll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) DEFINE_SHOW_ATTRIBUTE(info);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static int io_show(struct seq_file *seq, void *p)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	void (*show_bank)(struct seq_file *, struct s3c_cpufreq_config *, union s3c_iobank *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	struct s3c_cpufreq_config *cfg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	struct s3c_iotimings *iot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	union s3c_iobank *iob;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	int bank;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	cfg = s3c_cpufreq_getconfig();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	if (!cfg) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 		seq_printf(seq, "no configuration registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	show_bank = cfg->info->debug_io_show;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (!show_bank) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		seq_printf(seq, "no code to show bank timing\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	iot = s3c_cpufreq_getiotimings();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	if (!iot) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		seq_printf(seq, "no io timings registered\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	seq_printf(seq, "hclk period is %lu.%lu ns\n", print_ns(cfg->freq.hclk_tns));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	for (bank = 0; bank < MAX_BANKS; bank++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		iob = &iot->bank[bank];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 		seq_printf(seq, "bank %d: ", bank);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 		if (!iob->io_2410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			seq_printf(seq, "nothing set\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		show_bank(seq, cfg, iob);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) DEFINE_SHOW_ATTRIBUTE(io);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) static int __init s3c_freq_debugfs_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	dbgfs_root = debugfs_create_dir("s3c-cpufreq", NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	if (IS_ERR(dbgfs_root)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 		pr_err("%s: error creating debugfs root\n", __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return PTR_ERR(dbgfs_root);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	dbgfs_file_io = debugfs_create_file("io-timing", S_IRUGO, dbgfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 					    NULL, &io_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	dbgfs_file_info = debugfs_create_file("info", S_IRUGO, dbgfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					      NULL, &info_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	dbgfs_file_board = debugfs_create_file("board", S_IRUGO, dbgfs_root,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 					       NULL, &board_fops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) late_initcall(s3c_freq_debugfs_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163)