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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
/* abc_motto.c
*
* Abnormal Behavior Catcher MOTTO Support
*
* Copyright (C) 2020 Samsung Electronics
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*/
#include <linux/sti/abc_common.h>
extern struct device *sec_abc;
/*
* 1. MOTTO_INFO_REG_BOOTCHECK
*
* *******************************************************
* 31...............24 | 23...............16 | 15...............8 | 7...............0 |
* magic : 0x69 | | max boot time | second max boot time
* ...............................................................................................|
* *******************************************************
*
* 2. MOTTO_INFO_REG_DEVICE : max 255
*
* *******************************************************
* 31...............24 | 23...............16 | 15...............8 | 7...............0 |
* magic : 0x69 | camera | decon | gpu fault |
* ...............................................................................................|
* *******************************************************
*/
#define MOTTO_MAGIC_MASK (0x69)
#define MASK_0_TO_7 (0)
#define MASK_8_TO_15 (8)
#define MASK_16_TO_23 (16)
#define MASK_24_TO_31 (24)
#define ABC_MOTTO_INFO_CNT 3
enum motto_info_reg_type {
MOTTO_INFO_REG_BOOTCHECK,
MOTTO_INFO_REG_DEVICE,
};
enum motto_event_type {
MOTTO_GPU,
MOTTO_DECON,
MOTTO_CAMERA,
};
char motto_event_type_str[ABC_MOTTO_INFO_CNT][ABC_BUFFER_MAX] = {"gpu_fault", "fence_timeout", "camera_error"};
u32 readl_phys(phys_addr_t addr)
{
u32 ret;
void __iomem *virt = ioremap(addr, 0x10);
ret = readl(virt);
ABC_PRINT("%pa = 0x%08x\n", &addr, ret);
iounmap(virt);
return ret;
}
void writel_phys(unsigned int val, phys_addr_t addr)
{
void __iomem *virt = ioremap(addr, 0x10);
writel(val, virt);
ABC_PRINT("%pa <= 0x%08x\n", &addr, val);
iounmap(virt);
}
void init_motto_magic(void)
{
u32 info_val;
struct abc_info *pinfo;
struct abc_motto_data *cmotto;
u32 val, mask;
pinfo = dev_get_drvdata(sec_abc);
cmotto = pinfo->pdata->motto_data;
// MOTTO_INFO_REG_DEVICE
info_val = readl_phys(cmotto->info_device_base);
mask = MASK_24_TO_31;
val = (info_val >> mask) & 0xFF;
if (val == MOTTO_MAGIC_MASK) { // valid magic
ABC_PRINT("valid motto MOTTO_INFO_REG_DEVICE reg\n");
} else {
val = MOTTO_MAGIC_MASK << mask;
mask = 0xFF << mask;
val = val | (info_val & ~mask);
writel_phys(val, cmotto->info_device_base);
}
// MOTTO_INFO_REG_BOOTCHECK
info_val = readl_phys(cmotto->info_bootcheck_base);
mask = MASK_24_TO_31;
val = (info_val >> mask) & 0xFF;
if (val == MOTTO_MAGIC_MASK) { // valid magic
ABC_PRINT("valid motto MOTTO_INFO_REG_BOOTCHECK reg\n");
} else {
val = MOTTO_MAGIC_MASK << mask;
mask = 0xFF << mask;
val = val | (info_val & ~mask);
writel_phys(val, cmotto->info_bootcheck_base);
}
}
static void motto_update_info(enum motto_info_reg_type reg_type, int info)
{
u32 info_val;
struct abc_info *pinfo;
struct abc_motto_data *cmotto;
u32 val, mask;
u32 first_boot_time, second_boot_time, cur_boot_time;
pinfo = dev_get_drvdata(sec_abc);
cmotto = pinfo->pdata->motto_data;
if (reg_type == MOTTO_INFO_REG_DEVICE) {
info_val = readl_phys(cmotto->info_device_base);
mask = MASK_24_TO_31;
val = (info_val >> mask) & 0xFF;
if (val == MOTTO_MAGIC_MASK) { // valid magic
if (info == MOTTO_GPU) {
mask = MASK_0_TO_7;
} else if (info == MOTTO_DECON) {
mask = MASK_8_TO_15;
} else { // MOTTO_CAMERA
mask = MASK_16_TO_23;
}
val = (info_val >> mask) & 0xFF;
val++;
if (val >= 0xFF)
val = 0xFF;
val = val << mask;
mask = 0xFF << mask;
val = val | (info_val & ~mask);
writel_phys(val, cmotto->info_device_base);
} else { // invalid info reg . clear info reg
ABC_PRINT("invalid motto info reg\n");
val = MOTTO_MAGIC_MASK << MASK_24_TO_31;
writel_phys(val, cmotto->info_device_base);
}
} else if (reg_type == MOTTO_INFO_REG_BOOTCHECK) {
info_val = readl_phys(cmotto->info_bootcheck_base);
mask = MASK_24_TO_31;
val = (info_val >> mask) & 0xFF;
if (val == MOTTO_MAGIC_MASK) { // valid magic
cur_boot_time = (info >= 0xFF) ? 0xFF : (u32)info;
first_boot_time = (info_val >> MASK_8_TO_15) & 0xFF;
second_boot_time = (info_val >> MASK_0_TO_7) & 0xFF;
if (cur_boot_time > first_boot_time) {
second_boot_time = first_boot_time;
first_boot_time = cur_boot_time;
} else if (cur_boot_time > second_boot_time) {
second_boot_time = cur_boot_time;
}
first_boot_time = first_boot_time << MASK_8_TO_15;
second_boot_time = second_boot_time << MASK_0_TO_7;
val = first_boot_time | second_boot_time | (info_val & 0xFFFF0000);
writel_phys(val, cmotto->info_bootcheck_base);
} else { // invalid info reg . clear info reg
ABC_PRINT("invalid motto info reg\n");
val = MOTTO_MAGIC_MASK << MASK_24_TO_31;
writel_phys(val, cmotto->info_bootcheck_base);
}
} else {
ABC_PRINT("invalid motto reg_type : %d\n", reg_type);
}
}
static int motto_event_to_idx(char *event)
{
int i;
for (i = 0; i < ABC_MOTTO_INFO_CNT; i++) {
if (!strcmp(motto_event_type_str[i], event))
return i;
}
return -EINVAL;
}
void motto_send_device_info(char *event_type)
{
int event_type_idx = motto_event_to_idx(event_type);
if (event_type_idx >= 0) {
ABC_PRINT("%s : %s\n", __func__, event_type);
motto_update_info(MOTTO_INFO_REG_DEVICE, event_type_idx);
}
}
void motto_send_bootcheck_info(int boot_time)
{
ABC_PRINT("%s : %d\n", __func__, boot_time);
motto_update_info(MOTTO_INFO_REG_BOOTCHECK, boot_time);
}
EXPORT_SYMBOL(motto_send_bootcheck_info);
void get_motto_info(struct device *dev,
u32 *ret_info_boot, u32 *ret_info_device)
{
struct abc_motto_data *cmotto;
struct abc_info *pinfo = dev_get_drvdata(dev);
cmotto = pinfo->pdata->motto_data;
*ret_info_boot = readl_phys(cmotto->info_bootcheck_base);
*ret_info_device = readl_phys(cmotto->info_device_base);
}
int parse_motto_data(struct device *dev,
struct abc_platform_data *pdata,
struct device_node *np)
{
struct abc_motto_data *cmotto;
cmotto = pdata->motto_data;
cmotto->desc = of_get_property(np, "motto,label", NULL);
if (of_property_read_u32(np, "motto,info_bootcheck_base", &cmotto->info_bootcheck_base)) {
dev_err(dev, "Failed to get motto info_bootcheck_base: node not exist\n");
return -EINVAL;
}
if (of_property_read_u32(np, "motto,info_device_base", &cmotto->info_device_base)) {
dev_err(dev, "Failed to get motto info_device_base: node not exist\n");
return -EINVAL;
}
ABC_PRINT("MOTTO_INFO_REG_BOOTCHECK = 0x%08x , MOTTO_INFO_REG_DEVICE = 0x%08x\n",
cmotto->info_bootcheck_base, cmotto->info_device_base);
return 0;
}
MODULE_DESCRIPTION("Samsung ABC Driver");
MODULE_AUTHOR("Samsung Electronics");
MODULE_LICENSE("GPL");
|