1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
#define pr_fmt(fmt) "["KBUILD_MODNAME"] " fmt
#include <linux/module.h>
#include <linux/device.h>
#include <linux/fs.h>
#include <linux/cdev.h>
#include <linux/interrupt.h>
#include <linux/spinlock.h>
#include <linux/uaccess.h>
#include <linux/mm.h>
#include <linux/kfifo.h>
#include <linux/firmware.h>
#include <linux/syscalls.h>
#include <linux/uaccess.h>
#include <linux/platform_device.h>
#include <linux/proc_fs.h>
#include <linux/of.h>
#include <linux/of_address.h>
#include <linux/printk.h>
#include <mach/mt_reg_base.h>
#include <mach/mt_typedefs.h>
#include <asm/setup.h>
#include <mach/mt_chip_common.h>
struct mt_chip_drv g_chip_drv = {
.info_bit_mask = CHIP_INFO_BIT(CHIP_INFO_ALL)
};
struct mt_chip_drv* get_mt_chip_drv(void)
{
return &g_chip_drv;
}
struct chip_inf_entry
{
const char* name;
chip_info_t id;
int (*to_str)(char* buf, size_t len, int val);
};
static int hex2str(char* buf, size_t len, int val)
{
return snprintf(buf, len, "%04X", val);
}
static int dec2str(char* buf, size_t len, int val)
{
return snprintf(buf, len, "%04d", val);
}
static int date2str(char* buf, size_t len, int val)
{
unsigned int year = ((val & 0x3C0) >> 6) + 2012;
unsigned int week = (val & 0x03F);
return snprintf(buf, len, "%04d%02d", year, week);
}
#define __chip_info(id) ((g_chip_drv.get_chip_info) ? (g_chip_drv.get_chip_info(id)) : (0x0000))
static struct proc_dir_entry *chip_proc = NULL;
static struct chip_inf_entry chip_ent[] =
{
{"hw_code", CHIP_INFO_HW_CODE, hex2str},
{"hw_subcode", CHIP_INFO_HW_SUBCODE, hex2str},
{"hw_ver", CHIP_INFO_HW_VER, hex2str},
{"sw_ver", CHIP_INFO_SW_VER, hex2str},
{"code_func", CHIP_INFO_FUNCTION_CODE,hex2str},
{"code_date", CHIP_INFO_DATE_CODE, date2str},
{"code_proj", CHIP_INFO_PROJECT_CODE, dec2str},
{"code_fab", CHIP_INFO_FAB_CODE, hex2str},
{"wafer_big_ver", CHIP_INFO_WAFER_BIG_VER, hex2str},
{"info", CHIP_INFO_ALL, NULL}
};
static int chip_proc_show(struct seq_file* s, void* v)
{
struct chip_inf_entry *ent = s->private;
if ((ent->id > CHIP_INFO_NONE) && (ent->id < CHIP_INFO_MAX)) {
seq_printf(s, "%04X\n", __chip_info(ent->id));
} else {
int idx = 0;
char buf[16];
for (idx = 0; idx < sizeof(chip_ent)/sizeof(chip_ent[0]); idx++) {
struct chip_inf_entry *ent = &chip_ent[idx];
unsigned int val = __chip_info(ent->id);
if (!CHIP_INFO_SUP(g_chip_drv.info_bit_mask, ent->id))
continue;
else if (!ent->to_str)
continue;
else if (0 < ent->to_str(buf, sizeof(buf), val))
seq_printf(s, "%-16s : %s (%04x)\n", ent->name, buf, val);
else
seq_printf(s, "%-16s : %s (%04x)\n", ent->name, "NULL", val);
}
seq_printf(s, "%-16s : %04X %04X %04X %04X\n", "reg",
__chip_info(CHIP_INFO_REG_HW_CODE),
__chip_info(CHIP_INFO_REG_HW_SUBCODE),
__chip_info(CHIP_INFO_REG_HW_VER),
__chip_info(CHIP_INFO_REG_SW_VER));
}
return 0;
}
static int chip_proc_open(struct inode *inode, struct file *file)
{
return single_open(file, chip_proc_show, PDE_DATA(file_inode(file)));
}
static const struct file_operations chip_proc_fops = {
.open = chip_proc_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release,
};
extern struct proc_dir_entry proc_root;
static void __init create_procfs(void)
{
int idx;
chip_proc = proc_mkdir_data("chip", 0, &proc_root, NULL);
if (NULL == chip_proc) {
pr_err("create /proc/chip fails\n");
return;
} else {
pr_alert("create /proc/chip(%x)\n", g_chip_drv.info_bit_mask);
}
for (idx = 0; idx < sizeof(chip_ent)/sizeof(chip_ent[0]); idx++) {
struct chip_inf_entry *ent = &chip_ent[idx];
if (!CHIP_INFO_SUP(g_chip_drv.info_bit_mask, ent->id))
continue;
if (NULL == proc_create_data(ent->name, S_IRUGO, chip_proc, &chip_proc_fops, ent)) {
pr_err("create /proc/chip/%s fail\n", ent->name);
return;
}
}
}
int __init chip_common_init(void)
{
create_procfs();
return 0;
}
arch_initcall(chip_common_init);
MODULE_DESCRIPTION("MTK Chip Common");
MODULE_LICENSE("GPL");
|