Skip to content

Commit 9321fa6

Browse files
Lyle_Linalex3788
authored andcommitted
Add node /proc/board_info to display board info
cat /proc/board_info Display project id, RAM id, PCB id. Change-Id: I5163fb1004d967e367e74b57e89a93464cd19283 Reviewed-on: https://tp-biosrd-v02/gerrit/80253 Reviewed-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com> Tested-by: Alex Cheng(鄭富元) <Alex_Cheng@asus.com>
1 parent 1302d80 commit 9321fa6

3 files changed

Lines changed: 219 additions & 0 deletions

File tree

drivers/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,4 @@ obj-$(CONFIG_RK_NAND) += rk_nand/
178178
obj-$(CONFIG_RK_HEADSET) += headset_observe/
179179

180180
obj-y += miniarm/
181+
obj-y += board-info/

drivers/board-info/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
obj-y += board-info.o

drivers/board-info/board-info.c

Lines changed: 217 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,217 @@
1+
/* NOTICE:
2+
* This file is for asus project id pins,
3+
*/
4+
5+
#include <linux/kernel.h>
6+
#include <linux/proc_fs.h>
7+
#include <linux/seq_file.h>
8+
#include <linux/gpio.h>
9+
#include <linux/init.h>
10+
#include <linux/module.h>
11+
12+
#include <linux/rockchip/iomap.h>
13+
#include <linux/rockchip/grf.h>
14+
15+
16+
/* Project id (GPIO2_A3, GPIO2_A2, GPIO2_A1)
17+
* Ram id (GPIO2_B6, GPIO2_B5, GPIO2_B4)
18+
* PCB id (GPIO2_B2, GPIO2_B1 ,GPIO2_B0)
19+
*/
20+
#define GPIO2_A1 57
21+
#define GPIO2_A2 58
22+
#define GPIO2_A3 59
23+
#define GPIO2_B0 64
24+
#define GPIO2_B1 65
25+
#define GPIO2_B2 66
26+
#define GPIO2_B4 68
27+
#define GPIO2_B5 69
28+
#define GPIO2_B6 70
29+
30+
/* board hardware parameter*/
31+
int project_id_0, project_id_1, project_id_2;
32+
int ram_id_0, ram_id_1, ram_id_2;
33+
int pcb_id_0, pcb_id_1, pcb_id_2;
34+
35+
void *regs;
36+
int err;
37+
38+
char *board_type = "Unknown Board type";
39+
char *ram_size = "Unknown RAM size";
40+
char *pcb = "Unknown PCB";
41+
42+
static struct proc_dir_entry *project_id_proc_file;
43+
44+
static void read_project_id(void)
45+
{
46+
err = gpio_request(GPIO2_A1, "project_id_0");
47+
if (err < 0) {
48+
printk("%s: gpio_request failed for GPIO2_A1 %d\n", __func__, GPIO2_A1);
49+
return ;
50+
} else {
51+
gpio_direction_input(GPIO2_A1);
52+
project_id_0 = gpio_get_value(GPIO2_A1);
53+
}
54+
err = gpio_request(GPIO2_A2, "project_id_1");
55+
if (err < 0) {
56+
printk("%s: gpio_request failed for GPIO2_A2 %d\n", __func__, GPIO2_A2);
57+
return ;
58+
} else {
59+
gpio_direction_input(GPIO2_A2);
60+
project_id_1 = gpio_get_value(GPIO2_A2);
61+
}
62+
err = gpio_request(GPIO2_A3, "project_id_2");
63+
if (err < 0) {
64+
printk("%s: gpio_request failed for GPIO2_A3 %d\n", __func__, GPIO2_A3);
65+
return ;
66+
} else {
67+
gpio_direction_input(GPIO2_A3);
68+
project_id_2 = gpio_get_value(GPIO2_A3);
69+
}
70+
71+
printk("project_id_2:0x%x, project_id_1:0x%x, project_id_0:0x%x \n",
72+
project_id_2, project_id_1, project_id_0);
73+
74+
if (project_id_2 == 0 && project_id_1 == 0 && project_id_0 == 0)
75+
board_type = "Tinker Board S";
76+
else if (project_id_2 == 1 && project_id_1 == 1 && project_id_0 == 1)
77+
board_type = "Tinker Board";
78+
else
79+
board_type = "unknown board name";
80+
}
81+
82+
static void read_ram_id(void)
83+
{
84+
err = gpio_request(GPIO2_B4, "ram_id_0");
85+
if (err < 0) {
86+
printk("%s: gpio_request failed for GPIO2_B4 %d\n", __func__, GPIO2_B4);
87+
return ;
88+
} else {
89+
gpio_direction_input(GPIO2_B4);
90+
ram_id_0 = gpio_get_value(GPIO2_B4);
91+
}
92+
err = gpio_request(GPIO2_B5, "ram_id_1");
93+
if (err < 0) {
94+
printk("%s: gpio_request failed for GPIO2_B5 %d\n", __func__, GPIO2_B5);
95+
return ;
96+
} else {
97+
gpio_direction_input(GPIO2_B5);
98+
ram_id_1 = gpio_get_value(GPIO2_B5);
99+
}
100+
err = gpio_request(GPIO2_B6, "ram_id_2");
101+
if (err < 0) {
102+
printk("%s: gpio_request failed for GPIO2_B6 %d\n", __func__, GPIO2_B6);
103+
return ;
104+
} else {
105+
gpio_direction_input(GPIO2_B6);
106+
ram_id_2 = gpio_get_value(GPIO2_B6);
107+
}
108+
109+
printk("ram_id_2:0x%x, ram_id_1:0x%x, ram_id_0:0x%x \n",
110+
ram_id_2, ram_id_1, ram_id_0);
111+
112+
if (ram_id_2 == 0 && ram_id_1 == 0 && ram_id_0 == 0)
113+
ram_size = "4 GB";
114+
else if (ram_id_2 == 0 && ram_id_1 == 1 && ram_id_0 == 0)
115+
ram_size = "2 GB";
116+
else if (ram_id_2 == 1 && ram_id_1 == 0 && ram_id_0 == 0)
117+
ram_size = "1 GB";
118+
else
119+
ram_size = "unknown ram";
120+
}
121+
122+
static void read_pcb_id(void)
123+
{
124+
err = gpio_request(GPIO2_B0, "pcb_id_0");
125+
if (err < 0) {
126+
printk("%s: gpio_request failed for GPIO2_B0 %d\n", __func__, GPIO2_B0);
127+
return ;
128+
} else {
129+
gpio_direction_input(GPIO2_B0);
130+
pcb_id_0 = gpio_get_value(GPIO2_B0);
131+
}
132+
err = gpio_request(GPIO2_B1, "pcb_id_1");
133+
if (err < 0) {
134+
printk("%s: gpio_request failed for GPIO2_B1 %d\n", __func__, GPIO2_B1);
135+
return ;
136+
} else {
137+
gpio_direction_input(GPIO2_B1);
138+
pcb_id_1 = gpio_get_value(GPIO2_B1);
139+
}
140+
err = gpio_request(GPIO2_B2, "pcb_id_2");
141+
if (err < 0) {
142+
printk("%s: gpio_request failed for GPIO2_B2 %d\n", __func__, GPIO2_B2);
143+
return ;
144+
} else {
145+
gpio_direction_input(GPIO2_B2);
146+
pcb_id_2 = gpio_get_value(GPIO2_B2);
147+
}
148+
149+
printk("pcb_id_2:0x%x, pcb_id_1:0x%x, pcb_id_0:0x%x \n",
150+
pcb_id_2, pcb_id_1, pcb_id_0);
151+
152+
if (pcb_id_2 == 0 && pcb_id_1 == 0 && pcb_id_0 == 0)
153+
pcb = "SR";
154+
else if (pcb_id_2 == 0 && pcb_id_1 == 0 && pcb_id_0 == 1)
155+
pcb = "ER";
156+
else if (pcb_id_2 == 0 && pcb_id_1 == 1 && pcb_id_0 == 0)
157+
pcb = "PR";
158+
else
159+
pcb = "unknown pcb";
160+
}
161+
162+
static int board_info_proc_read(struct seq_file *buf, void *v)
163+
{
164+
/* Board info display */
165+
seq_printf(buf, "%s\n%s\n%s\n", board_type, ram_size, pcb);
166+
printk("[board_info] %s board_type=\'%s\' ram_size=\'%s' pcb=\'%s\'\n",
167+
__func__, board_type, ram_size, pcb);
168+
return 0;
169+
}
170+
171+
static int project_id_proc_open(struct inode *inode, struct file *file)
172+
{
173+
return single_open(file, board_info_proc_read, NULL);
174+
}
175+
176+
177+
static struct file_operations project_id_proc_ops = {
178+
.open = project_id_proc_open,
179+
.read = seq_read,
180+
.release = single_release,
181+
};
182+
183+
static void create_project_id_proc_file(void)
184+
{
185+
project_id_proc_file = proc_create("board_info", 0444, NULL,
186+
&project_id_proc_ops);
187+
if (project_id_proc_file) {
188+
printk("[board_info] create Board_info_proc_file sucessed!\n");
189+
} else {
190+
printk("[board_info] create Board_info_proc_file failed!\n");
191+
}
192+
193+
/* Pull up GPIO2 A1 A2 A3*/
194+
regs = ioremap(RK3288_GRF_PHYS, 64*1024);
195+
if (regs == NULL) {
196+
printk("[board_info] ioremap failed");
197+
return ;
198+
}
199+
writel((readl(regs + RK3288_GRF_GPIO2A_P) & ~(0x3f << 18) & ~(0x3f << 2))
200+
| (0x3f << 18) | (0x15 << 2), regs + RK3288_GRF_GPIO2A_P);
201+
// printk("[board_info] %x\n", readl(regs + RK3288_GRF_GPIO2A_P));
202+
203+
iounmap(regs);
204+
205+
/* Read GPIO */
206+
read_project_id();
207+
read_ram_id();
208+
read_pcb_id();
209+
}
210+
211+
static int __init proc_asusPRJ_init(void)
212+
{
213+
create_project_id_proc_file();
214+
return 0;
215+
}
216+
217+
module_init(proc_asusPRJ_init);

0 commit comments

Comments
 (0)