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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
|
/*
* sec_secure_touch.c - samsung secure touch driver
*
* Copyright (C) 2018 Samsung Electronics
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
*/
struct sec_secure_touch *g_ss_touch;
#include "sec_secure_touch.h"
#include <linux/notifier.h>
#include "sec_input.h"
int sec_secure_touch_set_device(struct sec_secure_touch *data, int dev_num);
void sec_secure_touch_sysfs_notify(struct sec_secure_touch *data);
int sec_secure_touch_set_device(struct sec_secure_touch *data, int dev_num)
{
int number = dev_num - 1;
int ret;
if (data->touch_driver[number].registered == 0)
return -ENODEV;
if (data->device_number > 1)
return -EBUSY;
mutex_lock(&data->lock);
ret = sysfs_create_link(&data->device->kobj, data->touch_driver[number].kobj, "secure");
if (ret < 0) {
mutex_unlock(&data->lock);
return -EINVAL;
}
pr_info("%s: %s: create link ret:%d, %s\n", SECLOG, __func__, ret, data->touch_driver[number].kobj->name);
data->touch_driver[number].enabled = 1;
mutex_unlock(&data->lock);
return ret;
}
struct sec_touch_driver *sec_secure_touch_register(void *drv_data, int dev_num, struct kobject *kobj)
{
struct sec_secure_touch *data = g_ss_touch;
int number = dev_num - 1;
if (!data) {
pr_info("%s %s: null\n", SECLOG, __func__);
return NULL;
}
pr_info("%s %s\n", SECLOG, __func__);
if (dev_num < 1) {
dev_err(&data->pdev->dev, "%s: invalid parameter:%d\n", __func__, dev_num);
return NULL;
}
if (data->touch_driver[number].registered) {
dev_info(&data->pdev->dev, "%s: already registered device number\n", __func__);
return NULL;
}
pr_info("%s %s: name is %s\n", SECLOG, __func__, kobj->name);
data->touch_driver[number].drv_number = dev_num;
data->touch_driver[number].drv_data = drv_data;
data->touch_driver[number].kobj = kobj;
data->touch_driver[number].registered = 1;
data->device_number++;
sec_secure_touch_set_device(data, dev_num);
return &data->touch_driver[number];
}
EXPORT_SYMBOL(sec_secure_touch_register);
void sec_secure_touch_unregister(int dev_num)
{
struct sec_secure_touch *data = g_ss_touch;
int number = dev_num - 1;
pr_info("%s: %s\n", SECLOG, __func__);
data->touch_driver[number].drv_number = 0;
data->touch_driver[number].drv_data = NULL;
data->touch_driver[number].kobj = NULL;
data->touch_driver[number].registered = 0;
data->device_number--;
}
void sec_secure_touch_sysfs_notify(struct sec_secure_touch *data)
{
if (!data)
sysfs_notify(&g_ss_touch->device->kobj, NULL, "secure_touch");
else
sysfs_notify(&data->device->kobj, NULL, "secure_touch");
dev_info(&g_ss_touch->pdev->dev, "%s\n", __func__);
}
static ssize_t secure_dev_count_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct sec_secure_touch *data = dev_get_drvdata(dev);
if (!data)
return -ENOMEM;
return snprintf(buf, PAGE_SIZE, "%d", data->device_number);
}
static DEVICE_ATTR(dev_count, 0444, secure_dev_count_show, NULL);
static struct attribute *sec_secure_touch_attrs[] = {
&dev_attr_dev_count.attr,
NULL,
};
static struct attribute_group sec_secure_touch_attr_group = {
.attrs = sec_secure_touch_attrs,
};
#if IS_ENABLED(CONFIG_TOUCHSCREEN_DUAL_FOLDABLE)
static void sec_secure_touch_hall_ic_work(struct work_struct *work)
{
struct sec_secure_touch *data = container_of(work, struct sec_secure_touch, folder_work.work);
int ret;
mutex_lock(&data->lock);
if (data->hall_ic == SECURE_TOUCH_FOLDER_OPEN) {
if (data->touch_driver[SECURE_TOUCH_SUB_DEV].enabled) {
if (data->touch_driver[SECURE_TOUCH_SUB_DEV].is_running) {
schedule_delayed_work(&data->folder_work, msecs_to_jiffies(10));
mutex_unlock(&data->lock);
return;
}
sysfs_remove_link(&data->device->kobj, "secure");
data->touch_driver[SECURE_TOUCH_SUB_DEV].enabled = 0;
} else {
pr_info("%s: %s: error: %d\n", SECLOG, __func__, __LINE__);
}
if (data->touch_driver[SECURE_TOUCH_MAIN_DEV].registered) {
if (data->touch_driver[SECURE_TOUCH_MAIN_DEV].enabled == 1) {
pr_info("%s: %s: already created\n", SECLOG, __func__);
mutex_unlock(&data->lock);
return;
}
ret = sysfs_create_link(&data->device->kobj, data->touch_driver[SECURE_TOUCH_MAIN_DEV].kobj, "secure");
if (ret < 0) {
mutex_unlock(&data->lock);
return;
}
pr_info("%s: %s: create link ret:%d, %s\n", SECLOG, __func__, ret, data->touch_driver[SECURE_TOUCH_MAIN_DEV].kobj->name);
data->touch_driver[SECURE_TOUCH_MAIN_DEV].enabled = 1;
} else {
pr_info("%s: %s: error: %d\n", SECLOG, __func__, __LINE__);
}
} else if (data->hall_ic == SECURE_TOUCH_FOLDER_CLOSE) {
if (data->touch_driver[SECURE_TOUCH_MAIN_DEV].enabled) {
if (data->touch_driver[SECURE_TOUCH_MAIN_DEV].is_running) {
schedule_delayed_work(&data->folder_work, msecs_to_jiffies(10));
mutex_unlock(&data->lock);
return;
}
sysfs_remove_link(&data->device->kobj, "secure");
data->touch_driver[SECURE_TOUCH_MAIN_DEV].enabled = 0;
} else {
pr_info("%s: %s: error: %d\n", SECLOG, __func__, __LINE__);
}
if (data->touch_driver[SECURE_TOUCH_SUB_DEV].registered) {
if (data->touch_driver[SECURE_TOUCH_SUB_DEV].enabled == 1) {
pr_info("%s: %s: already created\n", SECLOG, __func__);
mutex_unlock(&data->lock);
return;
}
ret = sysfs_create_link(&data->device->kobj, data->touch_driver[SECURE_TOUCH_SUB_DEV].kobj, "secure");
if (ret < 0) {
mutex_unlock(&data->lock);
return;
}
pr_info("%s: %s: create link ret:%d, %s\n", SECLOG, __func__, ret, data->touch_driver[SECURE_TOUCH_SUB_DEV].kobj->name);
data->touch_driver[SECURE_TOUCH_SUB_DEV].enabled = 1;
} else {
pr_info("%s: %s: error: %d\n", SECLOG, __func__, __LINE__);
}
} else {
mutex_unlock(&data->lock);
return;
}
mutex_unlock(&data->lock);
}
static int sec_secure_touch_hall_ic_notifier(struct notifier_block *nb, unsigned long hall_ic, void *ptr)
{
struct sec_secure_touch *data = container_of(nb, struct sec_secure_touch, nb);
if (!data)
return -ENOMEM;
if (data->device_number < 1)
return -ENODEV;
data->hall_ic = hall_ic;
pr_info("%s %s: device number:%d,%s %s%s\n", SECLOG, __func__, data->device_number,
data->hall_ic ? "CLOSE" : "OPEN",
data->touch_driver[SECURE_TOUCH_MAIN_DEV].is_running ? "tsp1" : "",
data->touch_driver[SECURE_TOUCH_SUB_DEV].is_running ? "tsp2" : "");
schedule_work(&data->folder_work.work);
return 0;
}
#endif
static int sec_secure_touch_probe(struct platform_device *pdev)
{
struct sec_secure_touch *data;
int ret;
data = kzalloc(sizeof(struct sec_secure_touch), GFP_KERNEL);
if (!data) {
pr_info("%s %s: failed probe: mem\n", SECLOG, __func__);
return -ENOMEM;
}
data->pdev = pdev;
data->device = sec_device_create(data, SECURE_TOUCH_DEV_NAME);
if (IS_ERR(data->device)) {
pr_info("%s %s: failed probe: create\n", SECLOG, __func__);
kfree(data);
return -ENODEV;
}
g_ss_touch = data;
dev_set_drvdata(data->device, data);
platform_set_drvdata(pdev, data);
mutex_init(&data->lock);
ret = sysfs_create_group(&data->device->kobj, &sec_secure_touch_attr_group);
if (ret < 0) {
pr_info("%s %s: failed probe: create sysfs\n", SECLOG, __func__);
sec_device_destroy(data->device->devt);
g_ss_touch = NULL;
kfree(data);
return -ENODEV;
}
#if IS_ENABLED(CONFIG_TOUCHSCREEN_DUAL_FOLDABLE)
data->nb.notifier_call = sec_secure_touch_hall_ic_notifier;
data->nb.priority = 1;
hall_ic_register_notify(&data->nb);
INIT_DELAYED_WORK(&data->folder_work, sec_secure_touch_hall_ic_work);
#else
sec_secure_touch_set_device(data, 1);
#endif
pr_info("%s: %s\n", SECLOG, __func__);
return 0;
}
static int sec_secure_touch_remove(struct platform_device *pdev)
{
struct sec_secure_touch *data = platform_get_drvdata(pdev);
int ii;
pr_info("%s: %s\n", SECLOG, __func__);
#if IS_ENABLED(CONFIG_TOUCHSCREEN_DUAL_FOLDABLE)
mutex_lock(&data->lock);
hall_ic_unregister_notify(&data->nb);
mutex_unlock(&data->lock);
#endif
for (ii = 0; ii < data->device_number; ii++) {
if (data->touch_driver[ii].enabled)
sysfs_remove_link(&data->device->kobj, "secure");
sysfs_remove_group(&data->device->kobj, &sec_secure_touch_attr_group);
}
mutex_destroy(&data->lock);
sec_device_destroy(data->device->devt);
g_ss_touch = NULL;
kfree(data);
return 0;
}
#if CONFIG_OF
static const struct of_device_id sec_secure_touch_dt_match[] = {
{ .compatible = "samsung,ss_touch" },
{}
};
#endif
struct platform_driver sec_secure_touch_driver = {
.probe = sec_secure_touch_probe,
.remove = sec_secure_touch_remove,
.driver = {
.name = "sec_secure_touch",
.owner = THIS_MODULE,
#if CONFIG_OF
.of_match_table = of_match_ptr(sec_secure_touch_dt_match),
#endif
},
};
static int __init sec_secure_touch_init(void)
{
pr_info("%s: %s\n", SECLOG, __func__);
platform_driver_register(&sec_secure_touch_driver);
return 0;
}
static void __exit sec_secure_touch_exit(void)
{
pr_info("%s; %s\n", SECLOG, __func__);
};
module_init(sec_secure_touch_init);
module_exit(sec_secure_touch_exit);
MODULE_DESCRIPTION("Samsung Secure Touch Driver");
MODULE_LICENSE("GPL");
|