-
Notifications
You must be signed in to change notification settings - Fork 0
/
synaptics_dsx_core.c
4138 lines (3578 loc) · 107 KB
/
synaptics_dsx_core.c
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Synaptics DSX touchscreen driver
*
* Copyright (C) 2012 Synaptics Incorporated
*
* Copyright (C) 2012 Alexandra Chin <alexandra.chin@tw.synaptics.com>
* Copyright (C) 2012 Scott Lin <scott.lin@tw.synaptics.com>
* Copyright (c) 2014, The Linux Foundation. All rights reserved.
*
* 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/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/gpio.h>
#include <linux/platform_device.h>
#include <linux/regulator/consumer.h>
#include <linux/input/synaptics_dsx_v2.h>
#include "synaptics_dsx_core.h"
#ifdef KERNEL_ABOVE_2_6_38
#include <linux/input/mt.h>
#endif
#if defined(CONFIG_SECURE_TOUCH)
#include <linux/errno.h>
#endif
#define INPUT_PHYS_NAME "synaptics_dsx/input0"
#define DEBUGFS_DIR_NAME "ts_debug"
#ifdef KERNEL_ABOVE_2_6_38
#define TYPE_B_PROTOCOL
#endif
#define NO_0D_WHILE_2D
#define REPORT_2D_Z
#define REPORT_2D_W
#define F12_DATA_15_WORKAROUND
/*
#define IGNORE_FN_INIT_FAILURE
*/
#define RPT_TYPE (1 << 0)
#define RPT_X_LSB (1 << 1)
#define RPT_X_MSB (1 << 2)
#define RPT_Y_LSB (1 << 3)
#define RPT_Y_MSB (1 << 4)
#define RPT_Z (1 << 5)
#define RPT_WX (1 << 6)
#define RPT_WY (1 << 7)
#define RPT_DEFAULT (RPT_TYPE | RPT_X_LSB | RPT_X_MSB | RPT_Y_LSB | RPT_Y_MSB)
#define EXP_FN_WORK_DELAY_MS 1000 /* ms */
#define MAX_F11_TOUCH_WIDTH 15
#define CHECK_STATUS_TIMEOUT_MS 100
#define F01_STD_QUERY_LEN 21
#define F01_BUID_ID_OFFSET 18
#define F11_STD_QUERY_LEN 9
#define F11_STD_CTRL_LEN 10
#define F11_STD_DATA_LEN 12
#define STATUS_NO_ERROR 0x00
#define STATUS_RESET_OCCURRED 0x01
#define STATUS_INVALID_CONFIG 0x02
#define STATUS_DEVICE_FAILURE 0x03
#define STATUS_CONFIG_CRC_FAILURE 0x04
#define STATUS_FIRMWARE_CRC_FAILURE 0x05
#define STATUS_CRC_IN_PROGRESS 0x06
#define NORMAL_OPERATION (0 << 0)
#define SENSOR_SLEEP (1 << 0)
#define NO_SLEEP_OFF (0 << 2)
#define NO_SLEEP_ON (1 << 2)
#define CONFIGURED (1 << 7)
#define SYNA_F11_MAX 4096
#define SYNA_F12_MAX 65536
static int synaptics_rmi4_f12_set_enables(struct synaptics_rmi4_data *rmi4_data,
unsigned short ctrl28);
static int synaptics_rmi4_free_fingers(struct synaptics_rmi4_data *rmi4_data);
static int synaptics_rmi4_reinit_device(struct synaptics_rmi4_data *rmi4_data);
static int synaptics_rmi4_reset_device(struct synaptics_rmi4_data *rmi4_data);
static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
#if defined(CONFIG_FB)
static int fb_notifier_callback(struct notifier_block *self,
unsigned long event, void *data);
#elif defined(CONFIG_HAS_EARLYSUSPEND)
static void synaptics_rmi4_early_suspend(struct early_suspend *h);
static void synaptics_rmi4_late_resume(struct early_suspend *h);
#endif
static int synaptics_rmi4_suspend(struct device *dev);
static int synaptics_rmi4_resume(struct device *dev);
static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
static irqreturn_t synaptics_rmi4_irq(int irq, void *data);
#if defined(CONFIG_SECURE_TOUCH)
static ssize_t synaptics_secure_touch_enable_show(struct device *dev,
struct device_attribute *attr, char *buf);
static ssize_t synaptics_secure_touch_enable_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count);
static ssize_t synaptics_secure_touch_show(struct device *dev,
struct device_attribute *attr, char *buf);
#endif
struct synaptics_rmi4_f01_device_status {
union {
struct {
unsigned char status_code:4;
unsigned char reserved:2;
unsigned char flash_prog:1;
unsigned char unconfigured:1;
} __packed;
unsigned char data[1];
};
};
struct synaptics_rmi4_f12_query_5 {
union {
struct {
unsigned char size_of_query6;
struct {
unsigned char ctrl0_is_present:1;
unsigned char ctrl1_is_present:1;
unsigned char ctrl2_is_present:1;
unsigned char ctrl3_is_present:1;
unsigned char ctrl4_is_present:1;
unsigned char ctrl5_is_present:1;
unsigned char ctrl6_is_present:1;
unsigned char ctrl7_is_present:1;
} __packed;
struct {
unsigned char ctrl8_is_present:1;
unsigned char ctrl9_is_present:1;
unsigned char ctrl10_is_present:1;
unsigned char ctrl11_is_present:1;
unsigned char ctrl12_is_present:1;
unsigned char ctrl13_is_present:1;
unsigned char ctrl14_is_present:1;
unsigned char ctrl15_is_present:1;
} __packed;
struct {
unsigned char ctrl16_is_present:1;
unsigned char ctrl17_is_present:1;
unsigned char ctrl18_is_present:1;
unsigned char ctrl19_is_present:1;
unsigned char ctrl20_is_present:1;
unsigned char ctrl21_is_present:1;
unsigned char ctrl22_is_present:1;
unsigned char ctrl23_is_present:1;
} __packed;
struct {
unsigned char ctrl24_is_present:1;
unsigned char ctrl25_is_present:1;
unsigned char ctrl26_is_present:1;
unsigned char ctrl27_is_present:1;
unsigned char ctrl28_is_present:1;
unsigned char ctrl29_is_present:1;
unsigned char ctrl30_is_present:1;
unsigned char ctrl31_is_present:1;
} __packed;
};
unsigned char data[5];
};
};
struct synaptics_rmi4_f12_query_8 {
union {
struct {
unsigned char size_of_query9;
struct {
unsigned char data0_is_present:1;
unsigned char data1_is_present:1;
unsigned char data2_is_present:1;
unsigned char data3_is_present:1;
unsigned char data4_is_present:1;
unsigned char data5_is_present:1;
unsigned char data6_is_present:1;
unsigned char data7_is_present:1;
} __packed;
struct {
unsigned char data8_is_present:1;
unsigned char data9_is_present:1;
unsigned char data10_is_present:1;
unsigned char data11_is_present:1;
unsigned char data12_is_present:1;
unsigned char data13_is_present:1;
unsigned char data14_is_present:1;
unsigned char data15_is_present:1;
} __packed;
};
unsigned char data[3];
};
};
struct synaptics_rmi4_f12_ctrl_8 {
union {
struct {
unsigned char max_x_coord_lsb;
unsigned char max_x_coord_msb;
unsigned char max_y_coord_lsb;
unsigned char max_y_coord_msb;
unsigned char rx_pitch_lsb;
unsigned char rx_pitch_msb;
unsigned char tx_pitch_lsb;
unsigned char tx_pitch_msb;
unsigned char low_rx_clip;
unsigned char high_rx_clip;
unsigned char low_tx_clip;
unsigned char high_tx_clip;
unsigned char num_of_rx;
unsigned char num_of_tx;
};
unsigned char data[14];
};
};
struct synaptics_rmi4_f12_ctrl_23 {
union {
struct {
unsigned char obj_type_enable;
unsigned char max_reported_objects;
};
unsigned char data[2];
};
};
struct synaptics_rmi4_f12_finger_data {
unsigned char object_type_and_status;
unsigned char x_lsb;
unsigned char x_msb;
unsigned char y_lsb;
unsigned char y_msb;
#ifdef REPORT_2D_Z
unsigned char z;
#endif
#ifdef REPORT_2D_W
unsigned char wx;
unsigned char wy;
#endif
};
struct synaptics_rmi4_f1a_query {
union {
struct {
unsigned char max_button_count:3;
unsigned char reserved:5;
unsigned char has_general_control:1;
unsigned char has_interrupt_enable:1;
unsigned char has_multibutton_select:1;
unsigned char has_tx_rx_map:1;
unsigned char has_perbutton_threshold:1;
unsigned char has_release_threshold:1;
unsigned char has_strongestbtn_hysteresis:1;
unsigned char has_filter_strength:1;
} __packed;
unsigned char data[2];
};
};
struct synaptics_rmi4_f1a_control_0 {
union {
struct {
unsigned char multibutton_report:2;
unsigned char filter_mode:2;
unsigned char reserved:4;
} __packed;
unsigned char data[1];
};
};
struct synaptics_rmi4_f1a_control {
struct synaptics_rmi4_f1a_control_0 general_control;
unsigned char button_int_enable;
unsigned char multi_button;
unsigned char *txrx_map;
unsigned char *button_threshold;
unsigned char button_release_threshold;
unsigned char strongest_button_hysteresis;
unsigned char filter_strength;
};
struct synaptics_rmi4_f1a_handle {
int button_bitmask_size;
unsigned char max_count;
unsigned char valid_button_count;
unsigned char *button_data_buffer;
unsigned char *button_map;
struct synaptics_rmi4_f1a_query button_query;
struct synaptics_rmi4_f1a_control button_control;
};
struct synaptics_rmi4_exp_fhandler {
struct synaptics_rmi4_exp_fn *exp_fn;
bool insert;
bool remove;
struct list_head link;
};
struct synaptics_rmi4_exp_fn_data {
bool initialized;
bool queue_work;
struct mutex mutex;
struct list_head list;
struct delayed_work work;
struct workqueue_struct *workqueue;
struct synaptics_rmi4_data *rmi4_data;
};
static struct synaptics_rmi4_exp_fn_data exp_data;
static struct device_attribute attrs[] = {
__ATTR(full_pm_cycle, (S_IRUGO | S_IWUSR | S_IWGRP),
synaptics_rmi4_full_pm_cycle_show,
synaptics_rmi4_full_pm_cycle_store),
__ATTR(reset, (S_IWUSR | S_IWGRP),
NULL,
synaptics_rmi4_f01_reset_store),
__ATTR(productinfo, S_IRUGO,
synaptics_rmi4_f01_productinfo_show,
synaptics_rmi4_store_error),
__ATTR(buildid, S_IRUGO,
synaptics_rmi4_f01_buildid_show,
synaptics_rmi4_store_error),
__ATTR(flashprog, S_IRUGO,
synaptics_rmi4_f01_flashprog_show,
synaptics_rmi4_store_error),
__ATTR(0dbutton, (S_IRUGO | S_IWUSR | S_IWGRP),
synaptics_rmi4_0dbutton_show,
synaptics_rmi4_0dbutton_store),
#if defined(CONFIG_SECURE_TOUCH)
__ATTR(secure_touch_enable, (S_IRUGO | S_IWUGO),
synaptics_secure_touch_enable_show,
synaptics_secure_touch_enable_store),
__ATTR(secure_touch, S_IRUGO ,
synaptics_secure_touch_show,
NULL),
#endif
};
#define MAX_BUF_SIZE 256
#define VKEY_VER_CODE "0x01"
#define HEIGHT_SCALE_NUM 8
#define HEIGHT_SCALE_DENOM 10
/* numerator and denomenator for border equations */
#define BORDER_ADJUST_NUM 3
#define BORDER_ADJUST_DENOM 4
static struct kobject *vkey_kobj;
static char *vkey_buf;
static ssize_t vkey_show(struct kobject *obj,
struct kobj_attribute *attr, char *buf)
{
strlcpy(buf, vkey_buf, MAX_BUF_SIZE);
return strnlen(buf, MAX_BUF_SIZE);
}
static struct kobj_attribute vkey_obj_attr = {
.attr = {
.mode = S_IRUGO,
.name = "virtualkeys."PLATFORM_DRIVER_NAME,
},
.show = vkey_show,
};
static struct attribute *vkey_attr[] = {
&vkey_obj_attr.attr,
NULL,
};
static struct attribute_group vkey_grp = {
.attrs = vkey_attr,
};
static int synaptics_rmi4_debug_suspend_set(void *_data, u64 val)
{
struct synaptics_rmi4_data *rmi4_data = _data;
if (val)
synaptics_rmi4_suspend(&rmi4_data->input_dev->dev);
else
synaptics_rmi4_resume(&rmi4_data->input_dev->dev);
return 0;
}
static int synaptics_rmi4_debug_suspend_get(void *_data, u64 *val)
{
struct synaptics_rmi4_data *rmi4_data = _data;
*val = rmi4_data->suspended;
return 0;
}
DEFINE_SIMPLE_ATTRIBUTE(debug_suspend_fops, synaptics_rmi4_debug_suspend_get,
synaptics_rmi4_debug_suspend_set, "%lld\n");
#if defined(CONFIG_SECURE_TOUCH)
static void synaptics_secure_touch_init(struct synaptics_rmi4_data *data)
{
int ret = 0;
data->st_initialized = 0;
init_completion(&data->st_powerdown);
init_completion(&data->st_irq_processed);
/* Get clocks */
data->core_clk = clk_get(data->pdev->dev.parent, "core_clk");
if (IS_ERR(data->core_clk)) {
ret = PTR_ERR(data->core_clk);
dev_err(data->pdev->dev.parent,
"%s: error on clk_get(core_clk):%d\n", __func__, ret);
return;
}
data->iface_clk = clk_get(data->pdev->dev.parent, "iface_clk");
if (IS_ERR(data->iface_clk)) {
ret = PTR_ERR(data->iface_clk);
dev_err(data->pdev->dev.parent,
"%s: error on clk_get(iface_clk):%d\n", __func__, ret);
goto err_iface_clk;
}
data->st_initialized = 1;
return;
err_iface_clk:
clk_put(data->core_clk);
data->core_clk = NULL;
}
static void synaptics_secure_touch_notify(struct synaptics_rmi4_data *rmi4_data)
{
sysfs_notify(&rmi4_data->input_dev->dev.kobj, NULL, "secure_touch");
}
static irqreturn_t synaptics_filter_interrupt(
struct synaptics_rmi4_data *rmi4_data)
{
if (atomic_read(&rmi4_data->st_enabled)) {
if (atomic_cmpxchg(&rmi4_data->st_pending_irqs, 0, 1) == 0) {
synaptics_secure_touch_notify(rmi4_data);
wait_for_completion_interruptible(
&rmi4_data->st_irq_processed);
}
return IRQ_HANDLED;
}
return IRQ_NONE;
}
static void synaptics_secure_touch_stop(
struct synaptics_rmi4_data *rmi4_data,
int blocking)
{
if (atomic_read(&rmi4_data->st_enabled)) {
atomic_set(&rmi4_data->st_pending_irqs, -1);
synaptics_secure_touch_notify(rmi4_data);
if (blocking)
wait_for_completion_interruptible(
&rmi4_data->st_powerdown);
}
}
#else
static void synaptics_secure_touch_init(struct synaptics_rmi4_data *rmi4_data)
{
}
static irqreturn_t synaptics_filter_interrupt(
struct synaptics_rmi4_data *rmi4_data)
{
return IRQ_NONE;
}
static void synaptics_secure_touch_stop(
struct synaptics_rmi4_data *rmi4_data,
int blocking)
{
}
#endif
#if defined(CONFIG_SECURE_TOUCH)
static ssize_t synaptics_secure_touch_enable_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
return scnprintf(
buf,
PAGE_SIZE,
"%d",
atomic_read(&rmi4_data->st_enabled));
}
/*
* Accept only "0" and "1" valid values.
* "0" will reset the st_enabled flag, then wake up the reading process and
* the interrupt handler.
* The bus driver is notified via pm_runtime that it is not required to stay
* awake anymore.
* It will also make sure the queue of events is emptied in the controller,
* in case a touch happened in between the secure touch being disabled and
* the local ISR being ungated.
* "1" will set the st_enabled flag and clear the st_pending_irqs flag.
* The bus driver is requested via pm_runtime to stay awake.
*/
static ssize_t synaptics_secure_touch_enable_store(struct device *dev,
struct device_attribute *attr,
const char *buf, size_t count)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
unsigned long value;
int err = 0;
if (count > 2)
return -EINVAL;
err = kstrtoul(buf, 10, &value);
if (err != 0)
return err;
if (!rmi4_data->st_initialized)
return -EIO;
err = count;
switch (value) {
case 0:
if (atomic_read(&rmi4_data->st_enabled) == 0)
break;
synaptics_rmi4_bus_put(rmi4_data);
atomic_set(&rmi4_data->st_enabled, 0);
synaptics_secure_touch_notify(rmi4_data);
complete(&rmi4_data->st_irq_processed);
synaptics_rmi4_irq(rmi4_data->irq, rmi4_data);
complete(&rmi4_data->st_powerdown);
break;
case 1:
if (atomic_read(&rmi4_data->st_enabled)) {
err = -EBUSY;
break;
}
synchronize_irq(rmi4_data->irq);
if (synaptics_rmi4_bus_get(rmi4_data) < 0) {
dev_err(
rmi4_data->pdev->dev.parent,
"synaptics_rmi4_bus_get failed\n");
err = -EIO;
break;
}
INIT_COMPLETION(rmi4_data->st_powerdown);
INIT_COMPLETION(rmi4_data->st_irq_processed);
atomic_set(&rmi4_data->st_enabled, 1);
atomic_set(&rmi4_data->st_pending_irqs, 0);
break;
default:
dev_err(
rmi4_data->pdev->dev.parent,
"unsupported value: %lu\n", value);
err = -EINVAL;
break;
}
return err;
}
/*
* This function returns whether there are pending interrupts, or
* other error conditions that need to be signaled to the userspace library,
* according tot he following logic:
* - st_enabled is 0 if secure touch is not enabled, returning -EBADF
* - st_pending_irqs is -1 to signal that secure touch is in being stopped,
* returning -EINVAL
* - st_pending_irqs is 1 to signal that there is a pending irq, returning
* the value "1" to the sysfs read operation
* - st_pending_irqs is 0 (only remaining case left) if the pending interrupt
* has been processed, so the interrupt handler can be allowed to continue.
*/
static ssize_t synaptics_secure_touch_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
int val = 0;
if (atomic_read(&rmi4_data->st_enabled) == 0)
return -EBADF;
if (atomic_cmpxchg(&rmi4_data->st_pending_irqs, -1, 0) == -1)
return -EINVAL;
if (atomic_cmpxchg(&rmi4_data->st_pending_irqs, 1, 0) == 1)
val = 1;
else
complete(&rmi4_data->st_irq_processed);
return scnprintf(buf, PAGE_SIZE, "%u", val);
}
#endif
static ssize_t synaptics_rmi4_full_pm_cycle_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
return snprintf(buf, PAGE_SIZE, "%u\n",
rmi4_data->full_pm_cycle);
}
static ssize_t synaptics_rmi4_full_pm_cycle_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
unsigned int input;
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
if (sscanf(buf, "%u", &input) != 1)
return -EINVAL;
rmi4_data->full_pm_cycle = input > 0 ? 1 : 0;
return count;
}
static ssize_t synaptics_rmi4_f01_reset_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int retval;
unsigned int reset;
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
if (sscanf(buf, "%u", &reset) != 1)
return -EINVAL;
if (reset != 1)
return -EINVAL;
retval = synaptics_rmi4_reset_device(rmi4_data);
if (retval < 0) {
dev_err(rmi4_data->pdev->dev.parent,
"%s: Failed to issue reset command, error = %d\n",
__func__, retval);
return retval;
}
return count;
}
static ssize_t synaptics_rmi4_f01_productinfo_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
return snprintf(buf, PAGE_SIZE, "0x%02x 0x%02x\n",
(rmi4_data->rmi4_mod_info.product_info[0]),
(rmi4_data->rmi4_mod_info.product_info[1]));
}
static ssize_t synaptics_rmi4_f01_buildid_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
return snprintf(buf, PAGE_SIZE, "%u\n",
rmi4_data->firmware_id);
}
static ssize_t synaptics_rmi4_f01_flashprog_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int retval;
struct synaptics_rmi4_f01_device_status device_status;
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
retval = synaptics_rmi4_reg_read(rmi4_data,
rmi4_data->f01_data_base_addr,
device_status.data,
sizeof(device_status.data));
if (retval < 0) {
dev_err(rmi4_data->pdev->dev.parent,
"%s: Failed to read device status, error = %d\n",
__func__, retval);
return retval;
}
return snprintf(buf, PAGE_SIZE, "%u\n",
device_status.flash_prog);
}
static ssize_t synaptics_rmi4_0dbutton_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
return snprintf(buf, PAGE_SIZE, "%u\n",
rmi4_data->button_0d_enabled);
}
static ssize_t synaptics_rmi4_0dbutton_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
int retval;
unsigned int input;
unsigned char ii;
unsigned char intr_enable;
struct synaptics_rmi4_fn *fhandler;
struct synaptics_rmi4_data *rmi4_data = dev_get_drvdata(dev);
struct synaptics_rmi4_device_info *rmi;
rmi = &(rmi4_data->rmi4_mod_info);
if (sscanf(buf, "%u", &input) != 1)
return -EINVAL;
input = input > 0 ? 1 : 0;
if (rmi4_data->button_0d_enabled == input)
return count;
if (list_empty(&rmi->support_fn_list))
return -ENODEV;
list_for_each_entry(fhandler, &rmi->support_fn_list, link) {
if (fhandler->fn_number == SYNAPTICS_RMI4_F1A) {
ii = fhandler->intr_reg_num;
retval = synaptics_rmi4_reg_read(rmi4_data,
rmi4_data->f01_ctrl_base_addr + 1 + ii,
&intr_enable,
sizeof(intr_enable));
if (retval < 0)
return retval;
if (input == 1)
intr_enable |= fhandler->intr_mask;
else
intr_enable &= ~fhandler->intr_mask;
retval = synaptics_rmi4_reg_write(rmi4_data,
rmi4_data->f01_ctrl_base_addr + 1 + ii,
&intr_enable,
sizeof(intr_enable));
if (retval < 0)
return retval;
}
}
rmi4_data->button_0d_enabled = input;
return count;
}
/**
* synaptics_rmi4_f11_abs_report()
*
* Called by synaptics_rmi4_report_touch() when valid Function $11
* finger data has been detected.
*
* This function reads the Function $11 data registers, determines the
* status of each finger supported by the Function, processes any
* necessary coordinate manipulation, reports the finger data to
* the input subsystem, and returns the number of fingers detected.
*/
static int synaptics_rmi4_f11_abs_report(struct synaptics_rmi4_data *rmi4_data,
struct synaptics_rmi4_fn *fhandler)
{
int retval;
unsigned char touch_count = 0; /* number of touch points */
unsigned char reg_index;
unsigned char finger;
unsigned char fingers_supported;
unsigned char num_of_finger_status_regs;
unsigned char finger_shift;
unsigned char finger_status;
unsigned char data_reg_blk_size;
unsigned char finger_status_reg[3];
unsigned char data[F11_STD_DATA_LEN];
unsigned short data_addr;
unsigned short data_offset;
int x;
int y;
int wx;
int wy;
int temp;
/*
* The number of finger status registers is determined by the
* maximum number of fingers supported - 2 bits per finger. So
* the number of finger status registers to read is:
* register_count = ceil(max_num_of_fingers / 4)
*/
fingers_supported = fhandler->num_of_data_points;
num_of_finger_status_regs = (fingers_supported + 3) / 4;
data_addr = fhandler->full_addr.data_base;
data_reg_blk_size = fhandler->size_of_data_register_block;
retval = synaptics_rmi4_reg_read(rmi4_data,
data_addr,
finger_status_reg,
num_of_finger_status_regs);
if (retval < 0)
return 0;
for (finger = 0; finger < fingers_supported; finger++) {
reg_index = finger / 4;
finger_shift = (finger % 4) * 2;
finger_status = (finger_status_reg[reg_index] >> finger_shift)
& MASK_2BIT;
/*
* Each 2-bit finger status field represents the following:
* 00 = finger not present
* 01 = finger present and data accurate
* 10 = finger present but data may be inaccurate
* 11 = reserved
*/
#ifdef TYPE_B_PROTOCOL
input_mt_slot(rmi4_data->input_dev, finger);
input_mt_report_slot_state(rmi4_data->input_dev,
MT_TOOL_FINGER, finger_status);
#endif
if (finger_status) {
data_offset = data_addr +
num_of_finger_status_regs +
(finger * data_reg_blk_size);
retval = synaptics_rmi4_reg_read(rmi4_data,
data_offset,
data,
data_reg_blk_size);
if (retval < 0)
return 0;
x = (data[0] << 4) | (data[2] & MASK_4BIT);
y = (data[1] << 4) | ((data[2] >> 4) & MASK_4BIT);
wx = (data[3] & MASK_4BIT);
wy = (data[3] >> 4) & MASK_4BIT;
if (rmi4_data->hw_if->board_data->swap_axes) {
temp = x;
x = y;
y = temp;
temp = wx;
wx = wy;
wy = temp;
}
if (rmi4_data->hw_if->board_data->x_flip)
x = rmi4_data->sensor_max_x - x;
if (rmi4_data->hw_if->board_data->y_flip)
y = rmi4_data->sensor_max_y - y;
input_report_key(rmi4_data->input_dev,
BTN_TOUCH, 1);
input_report_key(rmi4_data->input_dev,
BTN_TOOL_FINGER, 1);
input_report_abs(rmi4_data->input_dev,
ABS_MT_POSITION_X, x);
input_report_abs(rmi4_data->input_dev,
ABS_MT_POSITION_Y, y);
#ifdef REPORT_2D_W
input_report_abs(rmi4_data->input_dev,
ABS_MT_TOUCH_MAJOR, max(wx, wy));
input_report_abs(rmi4_data->input_dev,
ABS_MT_TOUCH_MINOR, min(wx, wy));
#endif
#ifndef TYPE_B_PROTOCOL
input_mt_sync(rmi4_data->input_dev);
#endif
dev_dbg(rmi4_data->pdev->dev.parent,
"%s: Finger %d:\n"
"status = 0x%02x\n"
"x = %d\n"
"y = %d\n"
"wx = %d\n"
"wy = %d\n",
__func__, finger,
finger_status,
x, y, wx, wy);
touch_count++;
}
}
if (touch_count == 0) {
input_report_key(rmi4_data->input_dev,
BTN_TOUCH, 0);
input_report_key(rmi4_data->input_dev,
BTN_TOOL_FINGER, 0);
#ifndef TYPE_B_PROTOCOL
input_mt_sync(rmi4_data->input_dev);
#endif
}
input_sync(rmi4_data->input_dev);
return touch_count;
}
/**
* synaptics_rmi4_f12_abs_report()
*
* Called by synaptics_rmi4_report_touch() when valid Function $12
* finger data has been detected.
*
* This function reads the Function $12 data registers, determines the
* status of each finger supported by the Function, processes any
* necessary coordinate manipulation, reports the finger data to
* the input subsystem, and returns the number of fingers detected.
*/
static int synaptics_rmi4_f12_abs_report(struct synaptics_rmi4_data *rmi4_data,
struct synaptics_rmi4_fn *fhandler)
{
int retval;
unsigned char touch_count = 0; /* number of touch points */
unsigned char finger;
unsigned char fingers_to_process;
unsigned char finger_status;
unsigned char size_of_2d_data;
unsigned short data_addr;
int x;
int y;
int wx;
int wy;
int temp;
struct synaptics_rmi4_f12_extra_data *extra_data;
struct synaptics_rmi4_f12_finger_data *data;
struct synaptics_rmi4_f12_finger_data *finger_data;
#ifdef F12_DATA_15_WORKAROUND
static unsigned char fingers_already_present;
#endif
fingers_to_process = fhandler->num_of_data_points;
data_addr = fhandler->full_addr.data_base;
extra_data = (struct synaptics_rmi4_f12_extra_data *)fhandler->extra;
size_of_2d_data = sizeof(struct synaptics_rmi4_f12_finger_data);
/* Determine the total number of fingers to process */
if (extra_data->data15_size) {
retval = synaptics_rmi4_reg_read(rmi4_data,
data_addr + extra_data->data15_offset,
extra_data->data15_data,
extra_data->data15_size);
if (retval < 0)
return 0;
/* Start checking from the highest bit */
temp = extra_data->data15_size - 1; /* Highest byte */
finger = (fingers_to_process - 1) % 8; /* Highest bit */
do {
if (extra_data->data15_data[temp] & (1 << finger))
break;
if (finger) {
finger--;
} else {
temp--; /* Move to the next lower byte */