1
2
3
4
5
6
7#include <linux/kernel.h>
8#include <linux/delay.h>
9#include <linux/device.h>
10#include <linux/input.h>
11#include <linux/input/mt.h>
12#include <linux/rmi.h>
13#include <linux/slab.h>
14#include <linux/of.h>
15#include "rmi_driver.h"
16#include "rmi_2d_sensor.h"
17
18#define F11_MAX_NUM_OF_FINGERS 10
19#define F11_MAX_NUM_OF_TOUCH_SHAPES 16
20
21#define FINGER_STATE_MASK 0x03
22
23#define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6
24#define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8
25
26#define DEFAULT_XY_MAX 9999
27#define DEFAULT_MAX_ABS_MT_PRESSURE 255
28#define DEFAULT_MAX_ABS_MT_TOUCH 15
29#define DEFAULT_MAX_ABS_MT_ORIENTATION 1
30#define DEFAULT_MIN_ABS_MT_TRACKING_ID 1
31#define DEFAULT_MAX_ABS_MT_TRACKING_ID 10
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#define DMAX 10
64
65
66
67
68
69#define RMI_F11_REZERO 0x01
70
71#define RMI_F11_HAS_QUERY9 (1 << 3)
72#define RMI_F11_HAS_QUERY11 (1 << 4)
73#define RMI_F11_HAS_QUERY12 (1 << 5)
74#define RMI_F11_HAS_QUERY27 (1 << 6)
75#define RMI_F11_HAS_QUERY28 (1 << 7)
76
77
78
79#define RMI_F11_NR_FINGERS_MASK 0x07
80#define RMI_F11_HAS_REL (1 << 3)
81#define RMI_F11_HAS_ABS (1 << 4)
82#define RMI_F11_HAS_GESTURES (1 << 5)
83#define RMI_F11_HAS_SENSITIVITY_ADJ (1 << 6)
84#define RMI_F11_CONFIGURABLE (1 << 7)
85
86
87#define RMI_F11_NR_ELECTRODES_MASK 0x7F
88
89
90
91#define RMI_F11_ABS_DATA_SIZE_MASK 0x03
92#define RMI_F11_HAS_ANCHORED_FINGER (1 << 2)
93#define RMI_F11_HAS_ADJ_HYST (1 << 3)
94#define RMI_F11_HAS_DRIBBLE (1 << 4)
95#define RMI_F11_HAS_BENDING_CORRECTION (1 << 5)
96#define RMI_F11_HAS_LARGE_OBJECT_SUPPRESSION (1 << 6)
97#define RMI_F11_HAS_JITTER_FILTER (1 << 7)
98
99
100#define RMI_F11_HAS_SINGLE_TAP (1 << 0)
101#define RMI_F11_HAS_TAP_AND_HOLD (1 << 1)
102#define RMI_F11_HAS_DOUBLE_TAP (1 << 2)
103#define RMI_F11_HAS_EARLY_TAP (1 << 3)
104#define RMI_F11_HAS_FLICK (1 << 4)
105#define RMI_F11_HAS_PRESS (1 << 5)
106#define RMI_F11_HAS_PINCH (1 << 6)
107#define RMI_F11_HAS_CHIRAL (1 << 7)
108
109
110#define RMI_F11_HAS_PALM_DET (1 << 0)
111#define RMI_F11_HAS_ROTATE (1 << 1)
112#define RMI_F11_HAS_TOUCH_SHAPES (1 << 2)
113#define RMI_F11_HAS_SCROLL_ZONES (1 << 3)
114#define RMI_F11_HAS_INDIVIDUAL_SCROLL_ZONES (1 << 4)
115#define RMI_F11_HAS_MF_SCROLL (1 << 5)
116#define RMI_F11_HAS_MF_EDGE_MOTION (1 << 6)
117#define RMI_F11_HAS_MF_SCROLL_INERTIA (1 << 7)
118
119
120#define RMI_F11_HAS_PEN (1 << 0)
121#define RMI_F11_HAS_PROXIMITY (1 << 1)
122#define RMI_F11_HAS_PALM_DET_SENSITIVITY (1 << 2)
123#define RMI_F11_HAS_SUPPRESS_ON_PALM_DETECT (1 << 3)
124#define RMI_F11_HAS_TWO_PEN_THRESHOLDS (1 << 4)
125#define RMI_F11_HAS_CONTACT_GEOMETRY (1 << 5)
126#define RMI_F11_HAS_PEN_HOVER_DISCRIMINATION (1 << 6)
127#define RMI_F11_HAS_PEN_FILTERS (1 << 7)
128
129
130#define RMI_F11_NR_TOUCH_SHAPES_MASK 0x1F
131
132
133
134#define RMI_F11_HAS_Z_TUNING (1 << 0)
135#define RMI_F11_HAS_ALGORITHM_SELECTION (1 << 1)
136#define RMI_F11_HAS_W_TUNING (1 << 2)
137#define RMI_F11_HAS_PITCH_INFO (1 << 3)
138#define RMI_F11_HAS_FINGER_SIZE (1 << 4)
139#define RMI_F11_HAS_SEGMENTATION_AGGRESSIVENESS (1 << 5)
140#define RMI_F11_HAS_XY_CLIP (1 << 6)
141#define RMI_F11_HAS_DRUMMING_FILTER (1 << 7)
142
143
144
145#define RMI_F11_HAS_GAPLESS_FINGER (1 << 0)
146#define RMI_F11_HAS_GAPLESS_FINGER_TUNING (1 << 1)
147#define RMI_F11_HAS_8BIT_W (1 << 2)
148#define RMI_F11_HAS_ADJUSTABLE_MAPPING (1 << 3)
149#define RMI_F11_HAS_INFO2 (1 << 4)
150#define RMI_F11_HAS_PHYSICAL_PROPS (1 << 5)
151#define RMI_F11_HAS_FINGER_LIMIT (1 << 6)
152#define RMI_F11_HAS_LINEAR_COEFF (1 << 7)
153
154
155
156#define RMI_F11_JITTER_WINDOW_MASK 0x1F
157#define RMI_F11_JITTER_FILTER_MASK 0x60
158#define RMI_F11_JITTER_FILTER_SHIFT 5
159
160
161#define RMI_F11_LIGHT_CONTROL_MASK 0x03
162#define RMI_F11_IS_CLEAR (1 << 2)
163#define RMI_F11_CLICKPAD_PROPS_MASK 0x18
164#define RMI_F11_CLICKPAD_PROPS_SHIFT 3
165#define RMI_F11_MOUSE_BUTTONS_MASK 0x60
166#define RMI_F11_MOUSE_BUTTONS_SHIFT 5
167#define RMI_F11_HAS_ADVANCED_GESTURES (1 << 7)
168
169#define RMI_F11_QUERY_SIZE 4
170#define RMI_F11_QUERY_GESTURE_SIZE 2
171
172#define F11_LIGHT_CTL_NONE 0x00
173#define F11_LUXPAD 0x01
174#define F11_DUAL_MODE 0x02
175
176#define F11_NOT_CLICKPAD 0x00
177#define F11_HINGED_CLICKPAD 0x01
178#define F11_UNIFORM_CLICKPAD 0x02
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
311struct f11_2d_sensor_queries {
312
313 u8 nr_fingers;
314 bool has_rel;
315 bool has_abs;
316 bool has_gestures;
317 bool has_sensitivity_adjust;
318 bool configurable;
319
320
321 u8 nr_x_electrodes;
322
323
324 u8 nr_y_electrodes;
325
326
327 u8 max_electrodes;
328
329
330 u8 abs_data_size;
331 bool has_anchored_finger;
332 bool has_adj_hyst;
333 bool has_dribble;
334 bool has_bending_correction;
335 bool has_large_object_suppression;
336 bool has_jitter_filter;
337
338 u8 f11_2d_query6;
339
340
341 bool has_single_tap;
342 bool has_tap_n_hold;
343 bool has_double_tap;
344 bool has_early_tap;
345 bool has_flick;
346 bool has_press;
347 bool has_pinch;
348 bool has_chiral;
349
350 bool query7_nonzero;
351
352
353 bool has_palm_det;
354 bool has_rotate;
355 bool has_touch_shapes;
356 bool has_scroll_zones;
357 bool has_individual_scroll_zones;
358 bool has_mf_scroll;
359 bool has_mf_edge_motion;
360 bool has_mf_scroll_inertia;
361
362 bool query8_nonzero;
363
364
365 bool has_pen;
366 bool has_proximity;
367 bool has_palm_det_sensitivity;
368 bool has_suppress_on_palm_detect;
369 bool has_two_pen_thresholds;
370 bool has_contact_geometry;
371 bool has_pen_hover_discrimination;
372 bool has_pen_filters;
373
374
375 u8 nr_touch_shapes;
376
377
378 bool has_z_tuning;
379 bool has_algorithm_selection;
380 bool has_w_tuning;
381 bool has_pitch_info;
382 bool has_finger_size;
383 bool has_segmentation_aggressiveness;
384 bool has_XY_clip;
385 bool has_drumming_filter;
386
387
388 bool has_gapless_finger;
389 bool has_gapless_finger_tuning;
390 bool has_8bit_w;
391 bool has_adjustable_mapping;
392 bool has_info2;
393 bool has_physical_props;
394 bool has_finger_limit;
395 bool has_linear_coeff_2;
396
397
398 u8 jitter_window_size;
399 u8 jitter_filter_type;
400
401
402 u8 light_control;
403 bool is_clear;
404 u8 clickpad_props;
405 u8 mouse_buttons;
406 bool has_advanced_gestures;
407
408
409 u16 x_sensor_size_mm;
410 u16 y_sensor_size_mm;
411};
412
413
414#define RMI_F11_REPORT_MODE_MASK 0x07
415#define RMI_F11_ABS_POS_FILT (1 << 3)
416#define RMI_F11_REL_POS_FILT (1 << 4)
417#define RMI_F11_REL_BALLISTICS (1 << 5)
418#define RMI_F11_DRIBBLE (1 << 6)
419#define RMI_F11_REPORT_BEYOND_CLIP (1 << 7)
420
421
422#define RMI_F11_PALM_DETECT_THRESH_MASK 0x0F
423#define RMI_F11_MOTION_SENSITIVITY_MASK 0x30
424#define RMI_F11_MANUAL_TRACKING (1 << 6)
425#define RMI_F11_MANUAL_TRACKED_FINGER (1 << 7)
426
427#define RMI_F11_DELTA_X_THRESHOLD 2
428#define RMI_F11_DELTA_Y_THRESHOLD 3
429
430#define RMI_F11_CTRL_REG_COUNT 12
431
432struct f11_2d_ctrl {
433 u8 ctrl0_11[RMI_F11_CTRL_REG_COUNT];
434 u16 ctrl0_11_address;
435};
436
437#define RMI_F11_ABS_BYTES 5
438#define RMI_F11_REL_BYTES 2
439
440
441
442#define RMI_F11_SINGLE_TAP (1 << 0)
443#define RMI_F11_TAP_AND_HOLD (1 << 1)
444#define RMI_F11_DOUBLE_TAP (1 << 2)
445#define RMI_F11_EARLY_TAP (1 << 3)
446#define RMI_F11_FLICK (1 << 4)
447#define RMI_F11_PRESS (1 << 5)
448#define RMI_F11_PINCH (1 << 6)
449
450
451
452#define RMI_F11_PALM_DETECT (1 << 0)
453#define RMI_F11_ROTATE (1 << 1)
454#define RMI_F11_SHAPE (1 << 2)
455#define RMI_F11_SCROLLZONE (1 << 3)
456#define RMI_F11_GESTURE_FINGER_COUNT_MASK 0x70
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471struct f11_2d_data {
472 u8 *f_state;
473 u8 *abs_pos;
474 s8 *rel_pos;
475 u8 *gest_1;
476 u8 *gest_2;
477 s8 *pinch;
478 u8 *flick;
479 u8 *rotate;
480 u8 *shapes;
481 s8 *multi_scroll;
482 s8 *scroll_zones;
483};
484
485
486
487
488
489
490
491
492
493
494
495
496
497struct f11_data {
498 bool has_query9;
499 bool has_query11;
500 bool has_query12;
501 bool has_query27;
502 bool has_query28;
503 bool has_acm;
504 struct f11_2d_ctrl dev_controls;
505 struct mutex dev_controls_mutex;
506 u16 rezero_wait_ms;
507 struct rmi_2d_sensor sensor;
508 struct f11_2d_sensor_queries sens_query;
509 struct f11_2d_data data;
510 struct rmi_2d_sensor_platform_data sensor_pdata;
511 unsigned long *abs_mask;
512 unsigned long *rel_mask;
513 unsigned long *result_bits;
514};
515
516enum f11_finger_state {
517 F11_NO_FINGER = 0x00,
518 F11_PRESENT = 0x01,
519 F11_INACCURATE = 0x02,
520 F11_RESERVED = 0x03
521};
522
523static void rmi_f11_rel_pos_report(struct f11_data *f11, u8 n_finger)
524{
525 struct rmi_2d_sensor *sensor = &f11->sensor;
526 struct f11_2d_data *data = &f11->data;
527 s8 x, y;
528
529 x = data->rel_pos[n_finger * RMI_F11_REL_BYTES];
530 y = data->rel_pos[n_finger * RMI_F11_REL_BYTES + 1];
531
532 rmi_2d_sensor_rel_report(sensor, x, y);
533}
534
535static void rmi_f11_abs_pos_process(struct f11_data *f11,
536 struct rmi_2d_sensor *sensor,
537 struct rmi_2d_sensor_abs_object *obj,
538 enum f11_finger_state finger_state,
539 u8 n_finger)
540{
541 struct f11_2d_data *data = &f11->data;
542 u8 *pos_data = &data->abs_pos[n_finger * RMI_F11_ABS_BYTES];
543 int tool_type = MT_TOOL_FINGER;
544
545 switch (finger_state) {
546 case F11_PRESENT:
547 obj->type = RMI_2D_OBJECT_FINGER;
548 break;
549 default:
550 obj->type = RMI_2D_OBJECT_NONE;
551 }
552
553 obj->mt_tool = tool_type;
554 obj->x = (pos_data[0] << 4) | (pos_data[2] & 0x0F);
555 obj->y = (pos_data[1] << 4) | (pos_data[2] >> 4);
556 obj->z = pos_data[4];
557 obj->wx = pos_data[3] & 0x0f;
558 obj->wy = pos_data[3] >> 4;
559
560 rmi_2d_sensor_abs_process(sensor, obj, n_finger);
561}
562
563static inline u8 rmi_f11_parse_finger_state(const u8 *f_state, u8 n_finger)
564{
565 return (f_state[n_finger / 4] >> (2 * (n_finger % 4))) &
566 FINGER_STATE_MASK;
567}
568
569static void rmi_f11_finger_handler(struct f11_data *f11,
570 struct rmi_2d_sensor *sensor, int size)
571{
572 const u8 *f_state = f11->data.f_state;
573 u8 finger_state;
574 u8 i;
575 int abs_fingers;
576 int rel_fingers;
577 int abs_size = sensor->nbr_fingers * RMI_F11_ABS_BYTES;
578
579 if (sensor->report_abs) {
580 if (abs_size > size)
581 abs_fingers = size / RMI_F11_ABS_BYTES;
582 else
583 abs_fingers = sensor->nbr_fingers;
584
585 for (i = 0; i < abs_fingers; i++) {
586
587 finger_state = rmi_f11_parse_finger_state(f_state, i);
588 if (finger_state == F11_RESERVED) {
589 pr_err("Invalid finger state[%d]: 0x%02x", i,
590 finger_state);
591 continue;
592 }
593
594 rmi_f11_abs_pos_process(f11, sensor, &sensor->objs[i],
595 finger_state, i);
596 }
597
598
599
600
601
602 if (sensor->kernel_tracking)
603 input_mt_assign_slots(sensor->input,
604 sensor->tracking_slots,
605 sensor->tracking_pos,
606 sensor->nbr_fingers,
607 sensor->dmax);
608
609 for (i = 0; i < abs_fingers; i++) {
610 finger_state = rmi_f11_parse_finger_state(f_state, i);
611 if (finger_state == F11_RESERVED)
612
613 continue;
614
615 rmi_2d_sensor_abs_report(sensor, &sensor->objs[i], i);
616 }
617
618 input_mt_sync_frame(sensor->input);
619 } else if (sensor->report_rel) {
620 if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size)
621 rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES;
622 else
623 rel_fingers = sensor->nbr_fingers;
624
625 for (i = 0; i < rel_fingers; i++)
626 rmi_f11_rel_pos_report(f11, i);
627 }
628
629}
630
631static int f11_2d_construct_data(struct f11_data *f11)
632{
633 struct rmi_2d_sensor *sensor = &f11->sensor;
634 struct f11_2d_sensor_queries *query = &f11->sens_query;
635 struct f11_2d_data *data = &f11->data;
636 int i;
637
638 sensor->nbr_fingers = (query->nr_fingers == 5 ? 10 :
639 query->nr_fingers + 1);
640
641 sensor->pkt_size = DIV_ROUND_UP(sensor->nbr_fingers, 4);
642
643 if (query->has_abs) {
644 sensor->pkt_size += (sensor->nbr_fingers * 5);
645 sensor->attn_size = sensor->pkt_size;
646 }
647
648 if (query->has_rel)
649 sensor->pkt_size += (sensor->nbr_fingers * 2);
650
651
652 if (query->query7_nonzero)
653 sensor->pkt_size += sizeof(u8);
654
655
656 if (query->query7_nonzero || query->query8_nonzero)
657 sensor->pkt_size += sizeof(u8);
658
659 if (query->has_pinch || query->has_flick || query->has_rotate) {
660 sensor->pkt_size += 3;
661 if (!query->has_flick)
662 sensor->pkt_size--;
663 if (!query->has_rotate)
664 sensor->pkt_size--;
665 }
666
667 if (query->has_touch_shapes)
668 sensor->pkt_size +=
669 DIV_ROUND_UP(query->nr_touch_shapes + 1, 8);
670
671 sensor->data_pkt = devm_kzalloc(&sensor->fn->dev, sensor->pkt_size,
672 GFP_KERNEL);
673 if (!sensor->data_pkt)
674 return -ENOMEM;
675
676 data->f_state = sensor->data_pkt;
677 i = DIV_ROUND_UP(sensor->nbr_fingers, 4);
678
679 if (query->has_abs) {
680 data->abs_pos = &sensor->data_pkt[i];
681 i += (sensor->nbr_fingers * RMI_F11_ABS_BYTES);
682 }
683
684 if (query->has_rel) {
685 data->rel_pos = &sensor->data_pkt[i];
686 i += (sensor->nbr_fingers * RMI_F11_REL_BYTES);
687 }
688
689 if (query->query7_nonzero) {
690 data->gest_1 = &sensor->data_pkt[i];
691 i++;
692 }
693
694 if (query->query7_nonzero || query->query8_nonzero) {
695 data->gest_2 = &sensor->data_pkt[i];
696 i++;
697 }
698
699 if (query->has_pinch) {
700 data->pinch = &sensor->data_pkt[i];
701 i++;
702 }
703
704 if (query->has_flick) {
705 if (query->has_pinch) {
706 data->flick = data->pinch;
707 i += 2;
708 } else {
709 data->flick = &sensor->data_pkt[i];
710 i += 3;
711 }
712 }
713
714 if (query->has_rotate) {
715 if (query->has_flick) {
716 data->rotate = data->flick + 1;
717 } else {
718 data->rotate = &sensor->data_pkt[i];
719 i += 2;
720 }
721 }
722
723 if (query->has_touch_shapes)
724 data->shapes = &sensor->data_pkt[i];
725
726 return 0;
727}
728
729static int f11_read_control_regs(struct rmi_function *fn,
730 struct f11_2d_ctrl *ctrl, u16 ctrl_base_addr) {
731 struct rmi_device *rmi_dev = fn->rmi_dev;
732 int error = 0;
733
734 ctrl->ctrl0_11_address = ctrl_base_addr;
735 error = rmi_read_block(rmi_dev, ctrl_base_addr, ctrl->ctrl0_11,
736 RMI_F11_CTRL_REG_COUNT);
737 if (error < 0) {
738 dev_err(&fn->dev, "Failed to read ctrl0, code: %d.\n", error);
739 return error;
740 }
741
742 return 0;
743}
744
745static int f11_write_control_regs(struct rmi_function *fn,
746 struct f11_2d_sensor_queries *query,
747 struct f11_2d_ctrl *ctrl,
748 u16 ctrl_base_addr)
749{
750 struct rmi_device *rmi_dev = fn->rmi_dev;
751 int error;
752
753 error = rmi_write_block(rmi_dev, ctrl_base_addr, ctrl->ctrl0_11,
754 RMI_F11_CTRL_REG_COUNT);
755 if (error < 0)
756 return error;
757
758 return 0;
759}
760
761static int rmi_f11_get_query_parameters(struct rmi_device *rmi_dev,
762 struct f11_data *f11,
763 struct f11_2d_sensor_queries *sensor_query,
764 u16 query_base_addr)
765{
766 int query_size;
767 int rc;
768 u8 query_buf[RMI_F11_QUERY_SIZE];
769 bool has_query36 = false;
770
771 rc = rmi_read_block(rmi_dev, query_base_addr, query_buf,
772 RMI_F11_QUERY_SIZE);
773 if (rc < 0)
774 return rc;
775
776 sensor_query->nr_fingers = query_buf[0] & RMI_F11_NR_FINGERS_MASK;
777 sensor_query->has_rel = !!(query_buf[0] & RMI_F11_HAS_REL);
778 sensor_query->has_abs = !!(query_buf[0] & RMI_F11_HAS_ABS);
779 sensor_query->has_gestures = !!(query_buf[0] & RMI_F11_HAS_GESTURES);
780 sensor_query->has_sensitivity_adjust =
781 !!(query_buf[0] & RMI_F11_HAS_SENSITIVITY_ADJ);
782 sensor_query->configurable = !!(query_buf[0] & RMI_F11_CONFIGURABLE);
783
784 sensor_query->nr_x_electrodes =
785 query_buf[1] & RMI_F11_NR_ELECTRODES_MASK;
786 sensor_query->nr_y_electrodes =
787 query_buf[2] & RMI_F11_NR_ELECTRODES_MASK;
788 sensor_query->max_electrodes =
789 query_buf[3] & RMI_F11_NR_ELECTRODES_MASK;
790
791 query_size = RMI_F11_QUERY_SIZE;
792
793 if (sensor_query->has_abs) {
794 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
795 if (rc < 0)
796 return rc;
797
798 sensor_query->abs_data_size =
799 query_buf[0] & RMI_F11_ABS_DATA_SIZE_MASK;
800 sensor_query->has_anchored_finger =
801 !!(query_buf[0] & RMI_F11_HAS_ANCHORED_FINGER);
802 sensor_query->has_adj_hyst =
803 !!(query_buf[0] & RMI_F11_HAS_ADJ_HYST);
804 sensor_query->has_dribble =
805 !!(query_buf[0] & RMI_F11_HAS_DRIBBLE);
806 sensor_query->has_bending_correction =
807 !!(query_buf[0] & RMI_F11_HAS_BENDING_CORRECTION);
808 sensor_query->has_large_object_suppression =
809 !!(query_buf[0] & RMI_F11_HAS_LARGE_OBJECT_SUPPRESSION);
810 sensor_query->has_jitter_filter =
811 !!(query_buf[0] & RMI_F11_HAS_JITTER_FILTER);
812 query_size++;
813 }
814
815 if (sensor_query->has_rel) {
816 rc = rmi_read(rmi_dev, query_base_addr + query_size,
817 &sensor_query->f11_2d_query6);
818 if (rc < 0)
819 return rc;
820 query_size++;
821 }
822
823 if (sensor_query->has_gestures) {
824 rc = rmi_read_block(rmi_dev, query_base_addr + query_size,
825 query_buf, RMI_F11_QUERY_GESTURE_SIZE);
826 if (rc < 0)
827 return rc;
828
829 sensor_query->has_single_tap =
830 !!(query_buf[0] & RMI_F11_HAS_SINGLE_TAP);
831 sensor_query->has_tap_n_hold =
832 !!(query_buf[0] & RMI_F11_HAS_TAP_AND_HOLD);
833 sensor_query->has_double_tap =
834 !!(query_buf[0] & RMI_F11_HAS_DOUBLE_TAP);
835 sensor_query->has_early_tap =
836 !!(query_buf[0] & RMI_F11_HAS_EARLY_TAP);
837 sensor_query->has_flick =
838 !!(query_buf[0] & RMI_F11_HAS_FLICK);
839 sensor_query->has_press =
840 !!(query_buf[0] & RMI_F11_HAS_PRESS);
841 sensor_query->has_pinch =
842 !!(query_buf[0] & RMI_F11_HAS_PINCH);
843 sensor_query->has_chiral =
844 !!(query_buf[0] & RMI_F11_HAS_CHIRAL);
845
846
847 sensor_query->has_palm_det =
848 !!(query_buf[1] & RMI_F11_HAS_PALM_DET);
849 sensor_query->has_rotate =
850 !!(query_buf[1] & RMI_F11_HAS_ROTATE);
851 sensor_query->has_touch_shapes =
852 !!(query_buf[1] & RMI_F11_HAS_TOUCH_SHAPES);
853 sensor_query->has_scroll_zones =
854 !!(query_buf[1] & RMI_F11_HAS_SCROLL_ZONES);
855 sensor_query->has_individual_scroll_zones =
856 !!(query_buf[1] & RMI_F11_HAS_INDIVIDUAL_SCROLL_ZONES);
857 sensor_query->has_mf_scroll =
858 !!(query_buf[1] & RMI_F11_HAS_MF_SCROLL);
859 sensor_query->has_mf_edge_motion =
860 !!(query_buf[1] & RMI_F11_HAS_MF_EDGE_MOTION);
861 sensor_query->has_mf_scroll_inertia =
862 !!(query_buf[1] & RMI_F11_HAS_MF_SCROLL_INERTIA);
863
864 sensor_query->query7_nonzero = !!(query_buf[0]);
865 sensor_query->query8_nonzero = !!(query_buf[1]);
866
867 query_size += 2;
868 }
869
870 if (f11->has_query9) {
871 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
872 if (rc < 0)
873 return rc;
874
875 sensor_query->has_pen =
876 !!(query_buf[0] & RMI_F11_HAS_PEN);
877 sensor_query->has_proximity =
878 !!(query_buf[0] & RMI_F11_HAS_PROXIMITY);
879 sensor_query->has_palm_det_sensitivity =
880 !!(query_buf[0] & RMI_F11_HAS_PALM_DET_SENSITIVITY);
881 sensor_query->has_suppress_on_palm_detect =
882 !!(query_buf[0] & RMI_F11_HAS_SUPPRESS_ON_PALM_DETECT);
883 sensor_query->has_two_pen_thresholds =
884 !!(query_buf[0] & RMI_F11_HAS_TWO_PEN_THRESHOLDS);
885 sensor_query->has_contact_geometry =
886 !!(query_buf[0] & RMI_F11_HAS_CONTACT_GEOMETRY);
887 sensor_query->has_pen_hover_discrimination =
888 !!(query_buf[0] & RMI_F11_HAS_PEN_HOVER_DISCRIMINATION);
889 sensor_query->has_pen_filters =
890 !!(query_buf[0] & RMI_F11_HAS_PEN_FILTERS);
891
892 query_size++;
893 }
894
895 if (sensor_query->has_touch_shapes) {
896 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
897 if (rc < 0)
898 return rc;
899
900 sensor_query->nr_touch_shapes = query_buf[0] &
901 RMI_F11_NR_TOUCH_SHAPES_MASK;
902
903 query_size++;
904 }
905
906 if (f11->has_query11) {
907 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
908 if (rc < 0)
909 return rc;
910
911 sensor_query->has_z_tuning =
912 !!(query_buf[0] & RMI_F11_HAS_Z_TUNING);
913 sensor_query->has_algorithm_selection =
914 !!(query_buf[0] & RMI_F11_HAS_ALGORITHM_SELECTION);
915 sensor_query->has_w_tuning =
916 !!(query_buf[0] & RMI_F11_HAS_W_TUNING);
917 sensor_query->has_pitch_info =
918 !!(query_buf[0] & RMI_F11_HAS_PITCH_INFO);
919 sensor_query->has_finger_size =
920 !!(query_buf[0] & RMI_F11_HAS_FINGER_SIZE);
921 sensor_query->has_segmentation_aggressiveness =
922 !!(query_buf[0] &
923 RMI_F11_HAS_SEGMENTATION_AGGRESSIVENESS);
924 sensor_query->has_XY_clip =
925 !!(query_buf[0] & RMI_F11_HAS_XY_CLIP);
926 sensor_query->has_drumming_filter =
927 !!(query_buf[0] & RMI_F11_HAS_DRUMMING_FILTER);
928
929 query_size++;
930 }
931
932 if (f11->has_query12) {
933 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
934 if (rc < 0)
935 return rc;
936
937 sensor_query->has_gapless_finger =
938 !!(query_buf[0] & RMI_F11_HAS_GAPLESS_FINGER);
939 sensor_query->has_gapless_finger_tuning =
940 !!(query_buf[0] & RMI_F11_HAS_GAPLESS_FINGER_TUNING);
941 sensor_query->has_8bit_w =
942 !!(query_buf[0] & RMI_F11_HAS_8BIT_W);
943 sensor_query->has_adjustable_mapping =
944 !!(query_buf[0] & RMI_F11_HAS_ADJUSTABLE_MAPPING);
945 sensor_query->has_info2 =
946 !!(query_buf[0] & RMI_F11_HAS_INFO2);
947 sensor_query->has_physical_props =
948 !!(query_buf[0] & RMI_F11_HAS_PHYSICAL_PROPS);
949 sensor_query->has_finger_limit =
950 !!(query_buf[0] & RMI_F11_HAS_FINGER_LIMIT);
951 sensor_query->has_linear_coeff_2 =
952 !!(query_buf[0] & RMI_F11_HAS_LINEAR_COEFF);
953
954 query_size++;
955 }
956
957 if (sensor_query->has_jitter_filter) {
958 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
959 if (rc < 0)
960 return rc;
961
962 sensor_query->jitter_window_size = query_buf[0] &
963 RMI_F11_JITTER_WINDOW_MASK;
964 sensor_query->jitter_filter_type = (query_buf[0] &
965 RMI_F11_JITTER_FILTER_MASK) >>
966 RMI_F11_JITTER_FILTER_SHIFT;
967
968 query_size++;
969 }
970
971 if (sensor_query->has_info2) {
972 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
973 if (rc < 0)
974 return rc;
975
976 sensor_query->light_control =
977 query_buf[0] & RMI_F11_LIGHT_CONTROL_MASK;
978 sensor_query->is_clear =
979 !!(query_buf[0] & RMI_F11_IS_CLEAR);
980 sensor_query->clickpad_props =
981 (query_buf[0] & RMI_F11_CLICKPAD_PROPS_MASK) >>
982 RMI_F11_CLICKPAD_PROPS_SHIFT;
983 sensor_query->mouse_buttons =
984 (query_buf[0] & RMI_F11_MOUSE_BUTTONS_MASK) >>
985 RMI_F11_MOUSE_BUTTONS_SHIFT;
986 sensor_query->has_advanced_gestures =
987 !!(query_buf[0] & RMI_F11_HAS_ADVANCED_GESTURES);
988
989 query_size++;
990 }
991
992 if (sensor_query->has_physical_props) {
993 rc = rmi_read_block(rmi_dev, query_base_addr
994 + query_size, query_buf, 4);
995 if (rc < 0)
996 return rc;
997
998 sensor_query->x_sensor_size_mm =
999 (query_buf[0] | (query_buf[1] << 8)) / 10;
1000 sensor_query->y_sensor_size_mm =
1001 (query_buf[2] | (query_buf[3] << 8)) / 10;
1002
1003
1004
1005
1006
1007 query_size += 12;
1008 }
1009
1010 if (f11->has_query27)
1011 ++query_size;
1012
1013 if (f11->has_query28) {
1014 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1015 query_buf);
1016 if (rc < 0)
1017 return rc;
1018
1019 has_query36 = !!(query_buf[0] & BIT(6));
1020 }
1021
1022 if (has_query36) {
1023 query_size += 2;
1024 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1025 query_buf);
1026 if (rc < 0)
1027 return rc;
1028
1029 if (!!(query_buf[0] & BIT(5)))
1030 f11->has_acm = true;
1031 }
1032
1033 return query_size;
1034}
1035
1036static int rmi_f11_initialize(struct rmi_function *fn)
1037{
1038 struct rmi_device *rmi_dev = fn->rmi_dev;
1039 struct f11_data *f11;
1040 struct f11_2d_ctrl *ctrl;
1041 u8 query_offset;
1042 u16 query_base_addr;
1043 u16 control_base_addr;
1044 u16 max_x_pos, max_y_pos;
1045 int rc;
1046 const struct rmi_device_platform_data *pdata =
1047 rmi_get_platform_data(rmi_dev);
1048 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
1049 struct rmi_2d_sensor *sensor;
1050 u8 buf;
1051 int mask_size;
1052
1053 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Initializing F11 values.\n");
1054
1055 mask_size = BITS_TO_LONGS(drvdata->irq_count) * sizeof(unsigned long);
1056
1057
1058
1059
1060 f11 = devm_kzalloc(&fn->dev, sizeof(struct f11_data) + mask_size * 3,
1061 GFP_KERNEL);
1062 if (!f11)
1063 return -ENOMEM;
1064
1065 if (fn->dev.of_node) {
1066 rc = rmi_2d_sensor_of_probe(&fn->dev, &f11->sensor_pdata);
1067 if (rc)
1068 return rc;
1069 } else {
1070 f11->sensor_pdata = pdata->sensor_pdata;
1071 }
1072
1073 f11->rezero_wait_ms = f11->sensor_pdata.rezero_wait;
1074
1075 f11->abs_mask = (unsigned long *)((char *)f11
1076 + sizeof(struct f11_data));
1077 f11->rel_mask = (unsigned long *)((char *)f11
1078 + sizeof(struct f11_data) + mask_size);
1079 f11->result_bits = (unsigned long *)((char *)f11
1080 + sizeof(struct f11_data) + mask_size * 2);
1081
1082 set_bit(fn->irq_pos, f11->abs_mask);
1083 set_bit(fn->irq_pos + 1, f11->rel_mask);
1084
1085 query_base_addr = fn->fd.query_base_addr;
1086 control_base_addr = fn->fd.control_base_addr;
1087
1088 rc = rmi_read(rmi_dev, query_base_addr, &buf);
1089 if (rc < 0)
1090 return rc;
1091
1092 f11->has_query9 = !!(buf & RMI_F11_HAS_QUERY9);
1093 f11->has_query11 = !!(buf & RMI_F11_HAS_QUERY11);
1094 f11->has_query12 = !!(buf & RMI_F11_HAS_QUERY12);
1095 f11->has_query27 = !!(buf & RMI_F11_HAS_QUERY27);
1096 f11->has_query28 = !!(buf & RMI_F11_HAS_QUERY28);
1097
1098 query_offset = (query_base_addr + 1);
1099 sensor = &f11->sensor;
1100 sensor->fn = fn;
1101
1102 rc = rmi_f11_get_query_parameters(rmi_dev, f11,
1103 &f11->sens_query, query_offset);
1104 if (rc < 0)
1105 return rc;
1106 query_offset += rc;
1107
1108 rc = f11_read_control_regs(fn, &f11->dev_controls,
1109 control_base_addr);
1110 if (rc < 0) {
1111 dev_err(&fn->dev,
1112 "Failed to read F11 control params.\n");
1113 return rc;
1114 }
1115
1116 if (f11->sens_query.has_info2) {
1117 if (f11->sens_query.is_clear)
1118 f11->sensor.sensor_type = rmi_sensor_touchscreen;
1119 else
1120 f11->sensor.sensor_type = rmi_sensor_touchpad;
1121 }
1122
1123 sensor->report_abs = f11->sens_query.has_abs;
1124
1125 sensor->axis_align =
1126 f11->sensor_pdata.axis_align;
1127
1128 sensor->topbuttonpad = f11->sensor_pdata.topbuttonpad;
1129 sensor->kernel_tracking = f11->sensor_pdata.kernel_tracking;
1130 sensor->dmax = f11->sensor_pdata.dmax;
1131 sensor->dribble = f11->sensor_pdata.dribble;
1132 sensor->palm_detect = f11->sensor_pdata.palm_detect;
1133
1134 if (f11->sens_query.has_physical_props) {
1135 sensor->x_mm = f11->sens_query.x_sensor_size_mm;
1136 sensor->y_mm = f11->sens_query.y_sensor_size_mm;
1137 } else {
1138 sensor->x_mm = f11->sensor_pdata.x_mm;
1139 sensor->y_mm = f11->sensor_pdata.y_mm;
1140 }
1141
1142 if (sensor->sensor_type == rmi_sensor_default)
1143 sensor->sensor_type =
1144 f11->sensor_pdata.sensor_type;
1145
1146 sensor->report_abs = sensor->report_abs
1147 && !(f11->sensor_pdata.disable_report_mask
1148 & RMI_F11_DISABLE_ABS_REPORT);
1149
1150 if (!sensor->report_abs)
1151
1152
1153
1154
1155 sensor->report_rel = f11->sens_query.has_rel;
1156
1157 rc = rmi_read_block(rmi_dev,
1158 control_base_addr + F11_CTRL_SENSOR_MAX_X_POS_OFFSET,
1159 (u8 *)&max_x_pos, sizeof(max_x_pos));
1160 if (rc < 0)
1161 return rc;
1162
1163 rc = rmi_read_block(rmi_dev,
1164 control_base_addr + F11_CTRL_SENSOR_MAX_Y_POS_OFFSET,
1165 (u8 *)&max_y_pos, sizeof(max_y_pos));
1166 if (rc < 0)
1167 return rc;
1168
1169 sensor->max_x = max_x_pos;
1170 sensor->max_y = max_y_pos;
1171
1172 rc = f11_2d_construct_data(f11);
1173 if (rc < 0)
1174 return rc;
1175
1176 if (f11->has_acm)
1177 f11->sensor.attn_size += f11->sensor.nbr_fingers * 2;
1178
1179
1180 sensor->tracking_pos = devm_kcalloc(&fn->dev,
1181 sensor->nbr_fingers, sizeof(struct input_mt_pos),
1182 GFP_KERNEL);
1183 sensor->tracking_slots = devm_kcalloc(&fn->dev,
1184 sensor->nbr_fingers, sizeof(int), GFP_KERNEL);
1185 sensor->objs = devm_kcalloc(&fn->dev,
1186 sensor->nbr_fingers,
1187 sizeof(struct rmi_2d_sensor_abs_object),
1188 GFP_KERNEL);
1189 if (!sensor->tracking_pos || !sensor->tracking_slots || !sensor->objs)
1190 return -ENOMEM;
1191
1192 ctrl = &f11->dev_controls;
1193 if (sensor->axis_align.delta_x_threshold)
1194 ctrl->ctrl0_11[RMI_F11_DELTA_X_THRESHOLD] =
1195 sensor->axis_align.delta_x_threshold;
1196
1197 if (sensor->axis_align.delta_y_threshold)
1198 ctrl->ctrl0_11[RMI_F11_DELTA_Y_THRESHOLD] =
1199 sensor->axis_align.delta_y_threshold;
1200
1201 if (f11->sens_query.has_dribble) {
1202 switch (sensor->dribble) {
1203 case RMI_REG_STATE_OFF:
1204 ctrl->ctrl0_11[0] &= ~BIT(6);
1205 break;
1206 case RMI_REG_STATE_ON:
1207 ctrl->ctrl0_11[0] |= BIT(6);
1208 break;
1209 case RMI_REG_STATE_DEFAULT:
1210 default:
1211 break;
1212 }
1213 }
1214
1215 if (f11->sens_query.has_palm_det) {
1216 switch (sensor->palm_detect) {
1217 case RMI_REG_STATE_OFF:
1218 ctrl->ctrl0_11[11] &= ~BIT(0);
1219 break;
1220 case RMI_REG_STATE_ON:
1221 ctrl->ctrl0_11[11] |= BIT(0);
1222 break;
1223 case RMI_REG_STATE_DEFAULT:
1224 default:
1225 break;
1226 }
1227 }
1228
1229 rc = f11_write_control_regs(fn, &f11->sens_query,
1230 &f11->dev_controls, fn->fd.control_base_addr);
1231 if (rc)
1232 dev_warn(&fn->dev, "Failed to write control registers\n");
1233
1234 mutex_init(&f11->dev_controls_mutex);
1235
1236 dev_set_drvdata(&fn->dev, f11);
1237
1238 return 0;
1239}
1240
1241static int rmi_f11_config(struct rmi_function *fn)
1242{
1243 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1244 struct rmi_driver *drv = fn->rmi_dev->driver;
1245 struct rmi_2d_sensor *sensor = &f11->sensor;
1246 int rc;
1247
1248 if (!sensor->report_abs)
1249 drv->clear_irq_bits(fn->rmi_dev, f11->abs_mask);
1250 else
1251 drv->set_irq_bits(fn->rmi_dev, f11->abs_mask);
1252
1253 if (!sensor->report_rel)
1254 drv->clear_irq_bits(fn->rmi_dev, f11->rel_mask);
1255 else
1256 drv->set_irq_bits(fn->rmi_dev, f11->rel_mask);
1257
1258 rc = f11_write_control_regs(fn, &f11->sens_query,
1259 &f11->dev_controls, fn->fd.query_base_addr);
1260 if (rc < 0)
1261 return rc;
1262
1263 return 0;
1264}
1265
1266static irqreturn_t rmi_f11_attention(int irq, void *ctx)
1267{
1268 struct rmi_function *fn = ctx;
1269 struct rmi_device *rmi_dev = fn->rmi_dev;
1270 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
1271 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1272 u16 data_base_addr = fn->fd.data_base_addr;
1273 int error;
1274 int valid_bytes = f11->sensor.pkt_size;
1275
1276 if (drvdata->attn_data.data) {
1277
1278
1279
1280
1281 if (f11->sensor.attn_size > drvdata->attn_data.size)
1282 valid_bytes = drvdata->attn_data.size;
1283 else
1284 valid_bytes = f11->sensor.attn_size;
1285 memcpy(f11->sensor.data_pkt, drvdata->attn_data.data,
1286 valid_bytes);
1287 drvdata->attn_data.data += f11->sensor.attn_size;
1288 drvdata->attn_data.size -= f11->sensor.attn_size;
1289 } else {
1290 error = rmi_read_block(rmi_dev,
1291 data_base_addr, f11->sensor.data_pkt,
1292 f11->sensor.pkt_size);
1293 if (error < 0)
1294 return IRQ_RETVAL(error);
1295 }
1296
1297 rmi_f11_finger_handler(f11, &f11->sensor, valid_bytes);
1298
1299 return IRQ_HANDLED;
1300}
1301
1302static int rmi_f11_resume(struct rmi_function *fn)
1303{
1304 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1305 int error;
1306
1307 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Resuming...\n");
1308 if (!f11->rezero_wait_ms)
1309 return 0;
1310
1311 mdelay(f11->rezero_wait_ms);
1312
1313 error = rmi_write(fn->rmi_dev, fn->fd.command_base_addr,
1314 RMI_F11_REZERO);
1315 if (error) {
1316 dev_err(&fn->dev,
1317 "%s: failed to issue rezero command, error = %d.",
1318 __func__, error);
1319 return error;
1320 }
1321
1322 return 0;
1323}
1324
1325static int rmi_f11_probe(struct rmi_function *fn)
1326{
1327 int error;
1328 struct f11_data *f11;
1329
1330 error = rmi_f11_initialize(fn);
1331 if (error)
1332 return error;
1333
1334 f11 = dev_get_drvdata(&fn->dev);
1335 error = rmi_2d_sensor_configure_input(fn, &f11->sensor);
1336 if (error)
1337 return error;
1338
1339 return 0;
1340}
1341
1342struct rmi_function_handler rmi_f11_handler = {
1343 .driver = {
1344 .name = "rmi4_f11",
1345 },
1346 .func = 0x11,
1347 .probe = rmi_f11_probe,
1348 .config = rmi_f11_config,
1349 .attention = rmi_f11_attention,
1350 .resume = rmi_f11_resume,
1351};
1352