This source file includes following definitions.
- rmi_f11_rel_pos_report
- rmi_f11_abs_pos_process
- rmi_f11_parse_finger_state
- rmi_f11_finger_handler
- f11_2d_construct_data
- f11_read_control_regs
- f11_write_control_regs
- rmi_f11_get_query_parameters
- rmi_f11_initialize
- rmi_f11_config
- rmi_f11_attention
- rmi_f11_resume
- rmi_f11_probe
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
311 struct 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
432 struct 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
471 struct 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
497 struct 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 };
514
515 enum f11_finger_state {
516 F11_NO_FINGER = 0x00,
517 F11_PRESENT = 0x01,
518 F11_INACCURATE = 0x02,
519 F11_RESERVED = 0x03
520 };
521
522 static void rmi_f11_rel_pos_report(struct f11_data *f11, u8 n_finger)
523 {
524 struct rmi_2d_sensor *sensor = &f11->sensor;
525 struct f11_2d_data *data = &f11->data;
526 s8 x, y;
527
528 x = data->rel_pos[n_finger * RMI_F11_REL_BYTES];
529 y = data->rel_pos[n_finger * RMI_F11_REL_BYTES + 1];
530
531 rmi_2d_sensor_rel_report(sensor, x, y);
532 }
533
534 static void rmi_f11_abs_pos_process(struct f11_data *f11,
535 struct rmi_2d_sensor *sensor,
536 struct rmi_2d_sensor_abs_object *obj,
537 enum f11_finger_state finger_state,
538 u8 n_finger)
539 {
540 struct f11_2d_data *data = &f11->data;
541 u8 *pos_data = &data->abs_pos[n_finger * RMI_F11_ABS_BYTES];
542 int tool_type = MT_TOOL_FINGER;
543
544 switch (finger_state) {
545 case F11_PRESENT:
546 obj->type = RMI_2D_OBJECT_FINGER;
547 break;
548 default:
549 obj->type = RMI_2D_OBJECT_NONE;
550 }
551
552 obj->mt_tool = tool_type;
553 obj->x = (pos_data[0] << 4) | (pos_data[2] & 0x0F);
554 obj->y = (pos_data[1] << 4) | (pos_data[2] >> 4);
555 obj->z = pos_data[4];
556 obj->wx = pos_data[3] & 0x0f;
557 obj->wy = pos_data[3] >> 4;
558
559 rmi_2d_sensor_abs_process(sensor, obj, n_finger);
560 }
561
562 static inline u8 rmi_f11_parse_finger_state(const u8 *f_state, u8 n_finger)
563 {
564 return (f_state[n_finger / 4] >> (2 * (n_finger % 4))) &
565 FINGER_STATE_MASK;
566 }
567
568 static void rmi_f11_finger_handler(struct f11_data *f11,
569 struct rmi_2d_sensor *sensor, int size)
570 {
571 const u8 *f_state = f11->data.f_state;
572 u8 finger_state;
573 u8 i;
574 int abs_fingers;
575 int rel_fingers;
576 int abs_size = sensor->nbr_fingers * RMI_F11_ABS_BYTES;
577
578 if (sensor->report_abs) {
579 if (abs_size > size)
580 abs_fingers = size / RMI_F11_ABS_BYTES;
581 else
582 abs_fingers = sensor->nbr_fingers;
583
584 for (i = 0; i < abs_fingers; i++) {
585
586 finger_state = rmi_f11_parse_finger_state(f_state, i);
587 if (finger_state == F11_RESERVED) {
588 pr_err("Invalid finger state[%d]: 0x%02x", i,
589 finger_state);
590 continue;
591 }
592
593 rmi_f11_abs_pos_process(f11, sensor, &sensor->objs[i],
594 finger_state, i);
595 }
596
597
598
599
600
601 if (sensor->kernel_tracking)
602 input_mt_assign_slots(sensor->input,
603 sensor->tracking_slots,
604 sensor->tracking_pos,
605 sensor->nbr_fingers,
606 sensor->dmax);
607
608 for (i = 0; i < abs_fingers; i++) {
609 finger_state = rmi_f11_parse_finger_state(f_state, i);
610 if (finger_state == F11_RESERVED)
611
612 continue;
613
614 rmi_2d_sensor_abs_report(sensor, &sensor->objs[i], i);
615 }
616
617 input_mt_sync_frame(sensor->input);
618 } else if (sensor->report_rel) {
619 if ((abs_size + sensor->nbr_fingers * RMI_F11_REL_BYTES) > size)
620 rel_fingers = (size - abs_size) / RMI_F11_REL_BYTES;
621 else
622 rel_fingers = sensor->nbr_fingers;
623
624 for (i = 0; i < rel_fingers; i++)
625 rmi_f11_rel_pos_report(f11, i);
626 }
627
628 }
629
630 static int f11_2d_construct_data(struct f11_data *f11)
631 {
632 struct rmi_2d_sensor *sensor = &f11->sensor;
633 struct f11_2d_sensor_queries *query = &f11->sens_query;
634 struct f11_2d_data *data = &f11->data;
635 int i;
636
637 sensor->nbr_fingers = (query->nr_fingers == 5 ? 10 :
638 query->nr_fingers + 1);
639
640 sensor->pkt_size = DIV_ROUND_UP(sensor->nbr_fingers, 4);
641
642 if (query->has_abs) {
643 sensor->pkt_size += (sensor->nbr_fingers * 5);
644 sensor->attn_size = sensor->pkt_size;
645 }
646
647 if (query->has_rel)
648 sensor->pkt_size += (sensor->nbr_fingers * 2);
649
650
651 if (query->query7_nonzero)
652 sensor->pkt_size += sizeof(u8);
653
654
655 if (query->query7_nonzero || query->query8_nonzero)
656 sensor->pkt_size += sizeof(u8);
657
658 if (query->has_pinch || query->has_flick || query->has_rotate) {
659 sensor->pkt_size += 3;
660 if (!query->has_flick)
661 sensor->pkt_size--;
662 if (!query->has_rotate)
663 sensor->pkt_size--;
664 }
665
666 if (query->has_touch_shapes)
667 sensor->pkt_size +=
668 DIV_ROUND_UP(query->nr_touch_shapes + 1, 8);
669
670 sensor->data_pkt = devm_kzalloc(&sensor->fn->dev, sensor->pkt_size,
671 GFP_KERNEL);
672 if (!sensor->data_pkt)
673 return -ENOMEM;
674
675 data->f_state = sensor->data_pkt;
676 i = DIV_ROUND_UP(sensor->nbr_fingers, 4);
677
678 if (query->has_abs) {
679 data->abs_pos = &sensor->data_pkt[i];
680 i += (sensor->nbr_fingers * RMI_F11_ABS_BYTES);
681 }
682
683 if (query->has_rel) {
684 data->rel_pos = &sensor->data_pkt[i];
685 i += (sensor->nbr_fingers * RMI_F11_REL_BYTES);
686 }
687
688 if (query->query7_nonzero) {
689 data->gest_1 = &sensor->data_pkt[i];
690 i++;
691 }
692
693 if (query->query7_nonzero || query->query8_nonzero) {
694 data->gest_2 = &sensor->data_pkt[i];
695 i++;
696 }
697
698 if (query->has_pinch) {
699 data->pinch = &sensor->data_pkt[i];
700 i++;
701 }
702
703 if (query->has_flick) {
704 if (query->has_pinch) {
705 data->flick = data->pinch;
706 i += 2;
707 } else {
708 data->flick = &sensor->data_pkt[i];
709 i += 3;
710 }
711 }
712
713 if (query->has_rotate) {
714 if (query->has_flick) {
715 data->rotate = data->flick + 1;
716 } else {
717 data->rotate = &sensor->data_pkt[i];
718 i += 2;
719 }
720 }
721
722 if (query->has_touch_shapes)
723 data->shapes = &sensor->data_pkt[i];
724
725 return 0;
726 }
727
728 static int f11_read_control_regs(struct rmi_function *fn,
729 struct f11_2d_ctrl *ctrl, u16 ctrl_base_addr) {
730 struct rmi_device *rmi_dev = fn->rmi_dev;
731 int error = 0;
732
733 ctrl->ctrl0_11_address = ctrl_base_addr;
734 error = rmi_read_block(rmi_dev, ctrl_base_addr, ctrl->ctrl0_11,
735 RMI_F11_CTRL_REG_COUNT);
736 if (error < 0) {
737 dev_err(&fn->dev, "Failed to read ctrl0, code: %d.\n", error);
738 return error;
739 }
740
741 return 0;
742 }
743
744 static int f11_write_control_regs(struct rmi_function *fn,
745 struct f11_2d_sensor_queries *query,
746 struct f11_2d_ctrl *ctrl,
747 u16 ctrl_base_addr)
748 {
749 struct rmi_device *rmi_dev = fn->rmi_dev;
750 int error;
751
752 error = rmi_write_block(rmi_dev, ctrl_base_addr, ctrl->ctrl0_11,
753 RMI_F11_CTRL_REG_COUNT);
754 if (error < 0)
755 return error;
756
757 return 0;
758 }
759
760 static int rmi_f11_get_query_parameters(struct rmi_device *rmi_dev,
761 struct f11_data *f11,
762 struct f11_2d_sensor_queries *sensor_query,
763 u16 query_base_addr)
764 {
765 int query_size;
766 int rc;
767 u8 query_buf[RMI_F11_QUERY_SIZE];
768 bool has_query36 = false;
769
770 rc = rmi_read_block(rmi_dev, query_base_addr, query_buf,
771 RMI_F11_QUERY_SIZE);
772 if (rc < 0)
773 return rc;
774
775 sensor_query->nr_fingers = query_buf[0] & RMI_F11_NR_FINGERS_MASK;
776 sensor_query->has_rel = !!(query_buf[0] & RMI_F11_HAS_REL);
777 sensor_query->has_abs = !!(query_buf[0] & RMI_F11_HAS_ABS);
778 sensor_query->has_gestures = !!(query_buf[0] & RMI_F11_HAS_GESTURES);
779 sensor_query->has_sensitivity_adjust =
780 !!(query_buf[0] & RMI_F11_HAS_SENSITIVITY_ADJ);
781 sensor_query->configurable = !!(query_buf[0] & RMI_F11_CONFIGURABLE);
782
783 sensor_query->nr_x_electrodes =
784 query_buf[1] & RMI_F11_NR_ELECTRODES_MASK;
785 sensor_query->nr_y_electrodes =
786 query_buf[2] & RMI_F11_NR_ELECTRODES_MASK;
787 sensor_query->max_electrodes =
788 query_buf[3] & RMI_F11_NR_ELECTRODES_MASK;
789
790 query_size = RMI_F11_QUERY_SIZE;
791
792 if (sensor_query->has_abs) {
793 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
794 if (rc < 0)
795 return rc;
796
797 sensor_query->abs_data_size =
798 query_buf[0] & RMI_F11_ABS_DATA_SIZE_MASK;
799 sensor_query->has_anchored_finger =
800 !!(query_buf[0] & RMI_F11_HAS_ANCHORED_FINGER);
801 sensor_query->has_adj_hyst =
802 !!(query_buf[0] & RMI_F11_HAS_ADJ_HYST);
803 sensor_query->has_dribble =
804 !!(query_buf[0] & RMI_F11_HAS_DRIBBLE);
805 sensor_query->has_bending_correction =
806 !!(query_buf[0] & RMI_F11_HAS_BENDING_CORRECTION);
807 sensor_query->has_large_object_suppression =
808 !!(query_buf[0] & RMI_F11_HAS_LARGE_OBJECT_SUPPRESSION);
809 sensor_query->has_jitter_filter =
810 !!(query_buf[0] & RMI_F11_HAS_JITTER_FILTER);
811 query_size++;
812 }
813
814 if (sensor_query->has_rel) {
815 rc = rmi_read(rmi_dev, query_base_addr + query_size,
816 &sensor_query->f11_2d_query6);
817 if (rc < 0)
818 return rc;
819 query_size++;
820 }
821
822 if (sensor_query->has_gestures) {
823 rc = rmi_read_block(rmi_dev, query_base_addr + query_size,
824 query_buf, RMI_F11_QUERY_GESTURE_SIZE);
825 if (rc < 0)
826 return rc;
827
828 sensor_query->has_single_tap =
829 !!(query_buf[0] & RMI_F11_HAS_SINGLE_TAP);
830 sensor_query->has_tap_n_hold =
831 !!(query_buf[0] & RMI_F11_HAS_TAP_AND_HOLD);
832 sensor_query->has_double_tap =
833 !!(query_buf[0] & RMI_F11_HAS_DOUBLE_TAP);
834 sensor_query->has_early_tap =
835 !!(query_buf[0] & RMI_F11_HAS_EARLY_TAP);
836 sensor_query->has_flick =
837 !!(query_buf[0] & RMI_F11_HAS_FLICK);
838 sensor_query->has_press =
839 !!(query_buf[0] & RMI_F11_HAS_PRESS);
840 sensor_query->has_pinch =
841 !!(query_buf[0] & RMI_F11_HAS_PINCH);
842 sensor_query->has_chiral =
843 !!(query_buf[0] & RMI_F11_HAS_CHIRAL);
844
845
846 sensor_query->has_palm_det =
847 !!(query_buf[1] & RMI_F11_HAS_PALM_DET);
848 sensor_query->has_rotate =
849 !!(query_buf[1] & RMI_F11_HAS_ROTATE);
850 sensor_query->has_touch_shapes =
851 !!(query_buf[1] & RMI_F11_HAS_TOUCH_SHAPES);
852 sensor_query->has_scroll_zones =
853 !!(query_buf[1] & RMI_F11_HAS_SCROLL_ZONES);
854 sensor_query->has_individual_scroll_zones =
855 !!(query_buf[1] & RMI_F11_HAS_INDIVIDUAL_SCROLL_ZONES);
856 sensor_query->has_mf_scroll =
857 !!(query_buf[1] & RMI_F11_HAS_MF_SCROLL);
858 sensor_query->has_mf_edge_motion =
859 !!(query_buf[1] & RMI_F11_HAS_MF_EDGE_MOTION);
860 sensor_query->has_mf_scroll_inertia =
861 !!(query_buf[1] & RMI_F11_HAS_MF_SCROLL_INERTIA);
862
863 sensor_query->query7_nonzero = !!(query_buf[0]);
864 sensor_query->query8_nonzero = !!(query_buf[1]);
865
866 query_size += 2;
867 }
868
869 if (f11->has_query9) {
870 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
871 if (rc < 0)
872 return rc;
873
874 sensor_query->has_pen =
875 !!(query_buf[0] & RMI_F11_HAS_PEN);
876 sensor_query->has_proximity =
877 !!(query_buf[0] & RMI_F11_HAS_PROXIMITY);
878 sensor_query->has_palm_det_sensitivity =
879 !!(query_buf[0] & RMI_F11_HAS_PALM_DET_SENSITIVITY);
880 sensor_query->has_suppress_on_palm_detect =
881 !!(query_buf[0] & RMI_F11_HAS_SUPPRESS_ON_PALM_DETECT);
882 sensor_query->has_two_pen_thresholds =
883 !!(query_buf[0] & RMI_F11_HAS_TWO_PEN_THRESHOLDS);
884 sensor_query->has_contact_geometry =
885 !!(query_buf[0] & RMI_F11_HAS_CONTACT_GEOMETRY);
886 sensor_query->has_pen_hover_discrimination =
887 !!(query_buf[0] & RMI_F11_HAS_PEN_HOVER_DISCRIMINATION);
888 sensor_query->has_pen_filters =
889 !!(query_buf[0] & RMI_F11_HAS_PEN_FILTERS);
890
891 query_size++;
892 }
893
894 if (sensor_query->has_touch_shapes) {
895 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
896 if (rc < 0)
897 return rc;
898
899 sensor_query->nr_touch_shapes = query_buf[0] &
900 RMI_F11_NR_TOUCH_SHAPES_MASK;
901
902 query_size++;
903 }
904
905 if (f11->has_query11) {
906 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
907 if (rc < 0)
908 return rc;
909
910 sensor_query->has_z_tuning =
911 !!(query_buf[0] & RMI_F11_HAS_Z_TUNING);
912 sensor_query->has_algorithm_selection =
913 !!(query_buf[0] & RMI_F11_HAS_ALGORITHM_SELECTION);
914 sensor_query->has_w_tuning =
915 !!(query_buf[0] & RMI_F11_HAS_W_TUNING);
916 sensor_query->has_pitch_info =
917 !!(query_buf[0] & RMI_F11_HAS_PITCH_INFO);
918 sensor_query->has_finger_size =
919 !!(query_buf[0] & RMI_F11_HAS_FINGER_SIZE);
920 sensor_query->has_segmentation_aggressiveness =
921 !!(query_buf[0] &
922 RMI_F11_HAS_SEGMENTATION_AGGRESSIVENESS);
923 sensor_query->has_XY_clip =
924 !!(query_buf[0] & RMI_F11_HAS_XY_CLIP);
925 sensor_query->has_drumming_filter =
926 !!(query_buf[0] & RMI_F11_HAS_DRUMMING_FILTER);
927
928 query_size++;
929 }
930
931 if (f11->has_query12) {
932 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
933 if (rc < 0)
934 return rc;
935
936 sensor_query->has_gapless_finger =
937 !!(query_buf[0] & RMI_F11_HAS_GAPLESS_FINGER);
938 sensor_query->has_gapless_finger_tuning =
939 !!(query_buf[0] & RMI_F11_HAS_GAPLESS_FINGER_TUNING);
940 sensor_query->has_8bit_w =
941 !!(query_buf[0] & RMI_F11_HAS_8BIT_W);
942 sensor_query->has_adjustable_mapping =
943 !!(query_buf[0] & RMI_F11_HAS_ADJUSTABLE_MAPPING);
944 sensor_query->has_info2 =
945 !!(query_buf[0] & RMI_F11_HAS_INFO2);
946 sensor_query->has_physical_props =
947 !!(query_buf[0] & RMI_F11_HAS_PHYSICAL_PROPS);
948 sensor_query->has_finger_limit =
949 !!(query_buf[0] & RMI_F11_HAS_FINGER_LIMIT);
950 sensor_query->has_linear_coeff_2 =
951 !!(query_buf[0] & RMI_F11_HAS_LINEAR_COEFF);
952
953 query_size++;
954 }
955
956 if (sensor_query->has_jitter_filter) {
957 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
958 if (rc < 0)
959 return rc;
960
961 sensor_query->jitter_window_size = query_buf[0] &
962 RMI_F11_JITTER_WINDOW_MASK;
963 sensor_query->jitter_filter_type = (query_buf[0] &
964 RMI_F11_JITTER_FILTER_MASK) >>
965 RMI_F11_JITTER_FILTER_SHIFT;
966
967 query_size++;
968 }
969
970 if (sensor_query->has_info2) {
971 rc = rmi_read(rmi_dev, query_base_addr + query_size, query_buf);
972 if (rc < 0)
973 return rc;
974
975 sensor_query->light_control =
976 query_buf[0] & RMI_F11_LIGHT_CONTROL_MASK;
977 sensor_query->is_clear =
978 !!(query_buf[0] & RMI_F11_IS_CLEAR);
979 sensor_query->clickpad_props =
980 (query_buf[0] & RMI_F11_CLICKPAD_PROPS_MASK) >>
981 RMI_F11_CLICKPAD_PROPS_SHIFT;
982 sensor_query->mouse_buttons =
983 (query_buf[0] & RMI_F11_MOUSE_BUTTONS_MASK) >>
984 RMI_F11_MOUSE_BUTTONS_SHIFT;
985 sensor_query->has_advanced_gestures =
986 !!(query_buf[0] & RMI_F11_HAS_ADVANCED_GESTURES);
987
988 query_size++;
989 }
990
991 if (sensor_query->has_physical_props) {
992 rc = rmi_read_block(rmi_dev, query_base_addr
993 + query_size, query_buf, 4);
994 if (rc < 0)
995 return rc;
996
997 sensor_query->x_sensor_size_mm =
998 (query_buf[0] | (query_buf[1] << 8)) / 10;
999 sensor_query->y_sensor_size_mm =
1000 (query_buf[2] | (query_buf[3] << 8)) / 10;
1001
1002
1003
1004
1005
1006 query_size += 12;
1007 }
1008
1009 if (f11->has_query27)
1010 ++query_size;
1011
1012 if (f11->has_query28) {
1013 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1014 query_buf);
1015 if (rc < 0)
1016 return rc;
1017
1018 has_query36 = !!(query_buf[0] & BIT(6));
1019 }
1020
1021 if (has_query36) {
1022 query_size += 2;
1023 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1024 query_buf);
1025 if (rc < 0)
1026 return rc;
1027
1028 if (!!(query_buf[0] & BIT(5)))
1029 f11->has_acm = true;
1030 }
1031
1032 return query_size;
1033 }
1034
1035 static int rmi_f11_initialize(struct rmi_function *fn)
1036 {
1037 struct rmi_device *rmi_dev = fn->rmi_dev;
1038 struct f11_data *f11;
1039 struct f11_2d_ctrl *ctrl;
1040 u8 query_offset;
1041 u16 query_base_addr;
1042 u16 control_base_addr;
1043 u16 max_x_pos, max_y_pos;
1044 int rc;
1045 const struct rmi_device_platform_data *pdata =
1046 rmi_get_platform_data(rmi_dev);
1047 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
1048 struct rmi_2d_sensor *sensor;
1049 u8 buf;
1050 int mask_size;
1051
1052 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Initializing F11 values.\n");
1053
1054 mask_size = BITS_TO_LONGS(drvdata->irq_count) * sizeof(unsigned long);
1055
1056
1057
1058
1059 f11 = devm_kzalloc(&fn->dev, sizeof(struct f11_data) + mask_size * 2,
1060 GFP_KERNEL);
1061 if (!f11)
1062 return -ENOMEM;
1063
1064 if (fn->dev.of_node) {
1065 rc = rmi_2d_sensor_of_probe(&fn->dev, &f11->sensor_pdata);
1066 if (rc)
1067 return rc;
1068 } else {
1069 f11->sensor_pdata = pdata->sensor_pdata;
1070 }
1071
1072 f11->rezero_wait_ms = f11->sensor_pdata.rezero_wait;
1073
1074 f11->abs_mask = (unsigned long *)((char *)f11
1075 + sizeof(struct f11_data));
1076 f11->rel_mask = (unsigned long *)((char *)f11
1077 + sizeof(struct f11_data) + mask_size);
1078
1079 set_bit(fn->irq_pos, f11->abs_mask);
1080 set_bit(fn->irq_pos + 1, f11->rel_mask);
1081
1082 query_base_addr = fn->fd.query_base_addr;
1083 control_base_addr = fn->fd.control_base_addr;
1084
1085 rc = rmi_read(rmi_dev, query_base_addr, &buf);
1086 if (rc < 0)
1087 return rc;
1088
1089 f11->has_query9 = !!(buf & RMI_F11_HAS_QUERY9);
1090 f11->has_query11 = !!(buf & RMI_F11_HAS_QUERY11);
1091 f11->has_query12 = !!(buf & RMI_F11_HAS_QUERY12);
1092 f11->has_query27 = !!(buf & RMI_F11_HAS_QUERY27);
1093 f11->has_query28 = !!(buf & RMI_F11_HAS_QUERY28);
1094
1095 query_offset = (query_base_addr + 1);
1096 sensor = &f11->sensor;
1097 sensor->fn = fn;
1098
1099 rc = rmi_f11_get_query_parameters(rmi_dev, f11,
1100 &f11->sens_query, query_offset);
1101 if (rc < 0)
1102 return rc;
1103 query_offset += rc;
1104
1105 rc = f11_read_control_regs(fn, &f11->dev_controls,
1106 control_base_addr);
1107 if (rc < 0) {
1108 dev_err(&fn->dev,
1109 "Failed to read F11 control params.\n");
1110 return rc;
1111 }
1112
1113 if (f11->sens_query.has_info2) {
1114 if (f11->sens_query.is_clear)
1115 f11->sensor.sensor_type = rmi_sensor_touchscreen;
1116 else
1117 f11->sensor.sensor_type = rmi_sensor_touchpad;
1118 }
1119
1120 sensor->report_abs = f11->sens_query.has_abs;
1121
1122 sensor->axis_align =
1123 f11->sensor_pdata.axis_align;
1124
1125 sensor->topbuttonpad = f11->sensor_pdata.topbuttonpad;
1126 sensor->kernel_tracking = f11->sensor_pdata.kernel_tracking;
1127 sensor->dmax = f11->sensor_pdata.dmax;
1128 sensor->dribble = f11->sensor_pdata.dribble;
1129 sensor->palm_detect = f11->sensor_pdata.palm_detect;
1130
1131 if (f11->sens_query.has_physical_props) {
1132 sensor->x_mm = f11->sens_query.x_sensor_size_mm;
1133 sensor->y_mm = f11->sens_query.y_sensor_size_mm;
1134 } else {
1135 sensor->x_mm = f11->sensor_pdata.x_mm;
1136 sensor->y_mm = f11->sensor_pdata.y_mm;
1137 }
1138
1139 if (sensor->sensor_type == rmi_sensor_default)
1140 sensor->sensor_type =
1141 f11->sensor_pdata.sensor_type;
1142
1143 sensor->report_abs = sensor->report_abs
1144 && !(f11->sensor_pdata.disable_report_mask
1145 & RMI_F11_DISABLE_ABS_REPORT);
1146
1147 if (!sensor->report_abs)
1148
1149
1150
1151
1152 sensor->report_rel = f11->sens_query.has_rel;
1153
1154 rc = rmi_read_block(rmi_dev,
1155 control_base_addr + F11_CTRL_SENSOR_MAX_X_POS_OFFSET,
1156 (u8 *)&max_x_pos, sizeof(max_x_pos));
1157 if (rc < 0)
1158 return rc;
1159
1160 rc = rmi_read_block(rmi_dev,
1161 control_base_addr + F11_CTRL_SENSOR_MAX_Y_POS_OFFSET,
1162 (u8 *)&max_y_pos, sizeof(max_y_pos));
1163 if (rc < 0)
1164 return rc;
1165
1166 sensor->max_x = max_x_pos;
1167 sensor->max_y = max_y_pos;
1168
1169 rc = f11_2d_construct_data(f11);
1170 if (rc < 0)
1171 return rc;
1172
1173 if (f11->has_acm)
1174 f11->sensor.attn_size += f11->sensor.nbr_fingers * 2;
1175
1176
1177 sensor->tracking_pos = devm_kcalloc(&fn->dev,
1178 sensor->nbr_fingers, sizeof(struct input_mt_pos),
1179 GFP_KERNEL);
1180 sensor->tracking_slots = devm_kcalloc(&fn->dev,
1181 sensor->nbr_fingers, sizeof(int), GFP_KERNEL);
1182 sensor->objs = devm_kcalloc(&fn->dev,
1183 sensor->nbr_fingers,
1184 sizeof(struct rmi_2d_sensor_abs_object),
1185 GFP_KERNEL);
1186 if (!sensor->tracking_pos || !sensor->tracking_slots || !sensor->objs)
1187 return -ENOMEM;
1188
1189 ctrl = &f11->dev_controls;
1190 if (sensor->axis_align.delta_x_threshold)
1191 ctrl->ctrl0_11[RMI_F11_DELTA_X_THRESHOLD] =
1192 sensor->axis_align.delta_x_threshold;
1193
1194 if (sensor->axis_align.delta_y_threshold)
1195 ctrl->ctrl0_11[RMI_F11_DELTA_Y_THRESHOLD] =
1196 sensor->axis_align.delta_y_threshold;
1197
1198 if (f11->sens_query.has_dribble) {
1199 switch (sensor->dribble) {
1200 case RMI_REG_STATE_OFF:
1201 ctrl->ctrl0_11[0] &= ~BIT(6);
1202 break;
1203 case RMI_REG_STATE_ON:
1204 ctrl->ctrl0_11[0] |= BIT(6);
1205 break;
1206 case RMI_REG_STATE_DEFAULT:
1207 default:
1208 break;
1209 }
1210 }
1211
1212 if (f11->sens_query.has_palm_det) {
1213 switch (sensor->palm_detect) {
1214 case RMI_REG_STATE_OFF:
1215 ctrl->ctrl0_11[11] &= ~BIT(0);
1216 break;
1217 case RMI_REG_STATE_ON:
1218 ctrl->ctrl0_11[11] |= BIT(0);
1219 break;
1220 case RMI_REG_STATE_DEFAULT:
1221 default:
1222 break;
1223 }
1224 }
1225
1226 rc = f11_write_control_regs(fn, &f11->sens_query,
1227 &f11->dev_controls, fn->fd.control_base_addr);
1228 if (rc)
1229 dev_warn(&fn->dev, "Failed to write control registers\n");
1230
1231 mutex_init(&f11->dev_controls_mutex);
1232
1233 dev_set_drvdata(&fn->dev, f11);
1234
1235 return 0;
1236 }
1237
1238 static int rmi_f11_config(struct rmi_function *fn)
1239 {
1240 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1241 struct rmi_driver *drv = fn->rmi_dev->driver;
1242 struct rmi_2d_sensor *sensor = &f11->sensor;
1243 int rc;
1244
1245 if (!sensor->report_abs)
1246 drv->clear_irq_bits(fn->rmi_dev, f11->abs_mask);
1247 else
1248 drv->set_irq_bits(fn->rmi_dev, f11->abs_mask);
1249
1250 if (!sensor->report_rel)
1251 drv->clear_irq_bits(fn->rmi_dev, f11->rel_mask);
1252 else
1253 drv->set_irq_bits(fn->rmi_dev, f11->rel_mask);
1254
1255 rc = f11_write_control_regs(fn, &f11->sens_query,
1256 &f11->dev_controls, fn->fd.query_base_addr);
1257 if (rc < 0)
1258 return rc;
1259
1260 return 0;
1261 }
1262
1263 static irqreturn_t rmi_f11_attention(int irq, void *ctx)
1264 {
1265 struct rmi_function *fn = ctx;
1266 struct rmi_device *rmi_dev = fn->rmi_dev;
1267 struct rmi_driver_data *drvdata = dev_get_drvdata(&rmi_dev->dev);
1268 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1269 u16 data_base_addr = fn->fd.data_base_addr;
1270 int error;
1271 int valid_bytes = f11->sensor.pkt_size;
1272
1273 if (drvdata->attn_data.data) {
1274
1275
1276
1277
1278 if (f11->sensor.attn_size > drvdata->attn_data.size)
1279 valid_bytes = drvdata->attn_data.size;
1280 else
1281 valid_bytes = f11->sensor.attn_size;
1282 memcpy(f11->sensor.data_pkt, drvdata->attn_data.data,
1283 valid_bytes);
1284 drvdata->attn_data.data += valid_bytes;
1285 drvdata->attn_data.size -= valid_bytes;
1286 } else {
1287 error = rmi_read_block(rmi_dev,
1288 data_base_addr, f11->sensor.data_pkt,
1289 f11->sensor.pkt_size);
1290 if (error < 0)
1291 return IRQ_RETVAL(error);
1292 }
1293
1294 rmi_f11_finger_handler(f11, &f11->sensor, valid_bytes);
1295
1296 return IRQ_HANDLED;
1297 }
1298
1299 static int rmi_f11_resume(struct rmi_function *fn)
1300 {
1301 struct f11_data *f11 = dev_get_drvdata(&fn->dev);
1302 int error;
1303
1304 rmi_dbg(RMI_DEBUG_FN, &fn->dev, "Resuming...\n");
1305 if (!f11->rezero_wait_ms)
1306 return 0;
1307
1308 mdelay(f11->rezero_wait_ms);
1309
1310 error = rmi_write(fn->rmi_dev, fn->fd.command_base_addr,
1311 RMI_F11_REZERO);
1312 if (error) {
1313 dev_err(&fn->dev,
1314 "%s: failed to issue rezero command, error = %d.",
1315 __func__, error);
1316 return error;
1317 }
1318
1319 return 0;
1320 }
1321
1322 static int rmi_f11_probe(struct rmi_function *fn)
1323 {
1324 int error;
1325 struct f11_data *f11;
1326
1327 error = rmi_f11_initialize(fn);
1328 if (error)
1329 return error;
1330
1331 f11 = dev_get_drvdata(&fn->dev);
1332 error = rmi_2d_sensor_configure_input(fn, &f11->sensor);
1333 if (error)
1334 return error;
1335
1336 return 0;
1337 }
1338
1339 struct rmi_function_handler rmi_f11_handler = {
1340 .driver = {
1341 .name = "rmi4_f11",
1342 },
1343 .func = 0x11,
1344 .probe = rmi_f11_probe,
1345 .config = rmi_f11_config,
1346 .attention = rmi_f11_attention,
1347 .resume = rmi_f11_resume,
1348 };