2 * Copyright (c) 2011 Synaptics Incorporated
3 * Copyright (c) 2011 Unixphere
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include <linux/kernel.h>
21 #include <linux/slab.h>
22 #include <linux/input.h>
23 #include <linux/input/mt.h>
24 #include <linux/rmi.h>
25 #include "rmi_driver.h"
26 #define RESUME_REZERO (1 && defined(CONFIG_PM))
28 #include <linux/delay.h>
29 #define DEFAULT_REZERO_WAIT_MS 40
33 #define MT_TOOL_MAX MT_TOOL_PEN
36 #define F11_MAX_NUM_OF_SENSORS 8
37 #define F11_MAX_NUM_OF_FINGERS 10
38 #define F11_MAX_NUM_OF_TOUCH_SHAPES 16
40 #define F11_REL_POS_MIN -128
41 #define F11_REL_POS_MAX 127
43 #define FINGER_STATE_MASK 0x03
44 #define GET_FINGER_STATE(f_states, i) \
45 ((f_states[i / 4] >> (2 * (i % 4))) & FINGER_STATE_MASK)
47 #define F11_CTRL_SENSOR_MAX_X_POS_OFFSET 6
48 #define F11_CTRL_SENSOR_MAX_Y_POS_OFFSET 8
50 #define F11_CEIL(x, y) (((x) + ((y)-1)) / (y))
51 #define INBOX(x, y, box) (x >= box.x && x < (box.x + box.width) \
52 && y >= box.y && y < (box.y + box.height))
54 #define DEFAULT_XY_MAX 9999
55 #define DEFAULT_MAX_ABS_MT_PRESSURE 255
56 #define DEFAULT_MAX_ABS_MT_TOUCH 15
57 #define DEFAULT_MAX_ABS_MT_ORIENTATION 1
58 #define DEFAULT_MIN_ABS_MT_TRACKING_ID 1
59 #define DEFAULT_MAX_ABS_MT_TRACKING_ID 10
60 #define MAX_NAME_LENGTH 256
62 #define SYNAPTICS_MAX_POINTS (10)
63 static ssize_t f11_flip_show(struct device *dev,
64 struct device_attribute *attr, char *buf);
66 static ssize_t f11_flip_store(struct device *dev,
67 struct device_attribute *attr,
68 const char *buf, size_t count);
70 static ssize_t f11_clip_show(struct device *dev,
71 struct device_attribute *attr, char *buf);
73 static ssize_t f11_clip_store(struct device *dev,
74 struct device_attribute *attr,
75 const char *buf, size_t count);
77 static ssize_t f11_offset_show(struct device *dev,
78 struct device_attribute *attr, char *buf);
80 static ssize_t f11_offset_store(struct device *dev,
81 struct device_attribute *attr,
82 const char *buf, size_t count);
84 static ssize_t f11_swap_show(struct device *dev,
85 struct device_attribute *attr, char *buf);
87 static ssize_t f11_swap_store(struct device *dev,
88 struct device_attribute *attr,
89 const char *buf, size_t count);
91 static ssize_t f11_relreport_show(struct device *dev,
92 struct device_attribute *attr,
95 static ssize_t f11_relreport_store(struct device *dev,
96 struct device_attribute *attr,
97 const char *buf, size_t count);
99 static ssize_t f11_maxPos_show(struct device *dev,
100 struct device_attribute *attr, char *buf);
102 static ssize_t f11_rezero_store(struct device *dev,
103 struct device_attribute *attr,
104 const char *buf, size_t count);
107 static ssize_t f11_rezeroOnResume_show(struct device *dev,
108 struct device_attribute *attr,
111 static ssize_t f11_rezeroOnResume_store(struct device *dev,
112 struct device_attribute *attr,
113 const char *buf, size_t count);
114 static ssize_t f11_rezeroWait_show(struct device *dev,
115 struct device_attribute *attr,
118 static ssize_t f11_rezeroWait_store(struct device *dev,
119 struct device_attribute *attr,
120 const char *buf, size_t count);
124 static void rmi_f11_free_memory(struct rmi_function_container *fc);
126 static int rmi_f11_initialize(struct rmi_function_container *fc);
128 static int rmi_f11_create_sysfs(struct rmi_function_container *fc);
130 static int rmi_f11_config(struct rmi_function_container *fc);
132 static int rmi_f11_reset(struct rmi_function_container *fc);
134 static int rmi_f11_register_devices(struct rmi_function_container *fc);
136 static void rmi_f11_free_devices(struct rmi_function_container *fc);
139 static struct device_attribute attrs[] = {
140 __ATTR(flip, RMI_RW_ATTR, f11_flip_show, f11_flip_store),
141 __ATTR(clip, RMI_RW_ATTR, f11_clip_show, f11_clip_store),
142 __ATTR(offset, RMI_RW_ATTR, f11_offset_show, f11_offset_store),
143 __ATTR(swap, RMI_RW_ATTR, f11_swap_show, f11_swap_store),
144 __ATTR(relreport, RMI_RW_ATTR, f11_relreport_show, f11_relreport_store),
145 __ATTR(maxPos, RMI_RO_ATTR, f11_maxPos_show, rmi_store_error),
147 __ATTR(rezeroOnResume, RMI_RW_ATTR, f11_rezeroOnResume_show,
148 f11_rezeroOnResume_store),
149 __ATTR(rezeroWait, RMI_RW_ATTR, f11_rezeroWait_show,
150 f11_rezeroWait_store),
152 __ATTR(rezero, RMI_WO_ATTR, rmi_show_error, f11_rezero_store)
156 union f11_2d_commands {
163 struct f11_2d_device_query {
176 u8 has_pos_interpolation_tuning:1;
179 u8 has_default_finger_width:1;
180 u8 has_segmentation_aggressiveness:1;
182 u8 has_drumming_correction:1;
188 union f11_2d_query9 {
192 u8 has_palm_det_sensitivity:1;
193 u8 has_suppress_on_palm_detect:1;
194 u8 has_two_pen_thresholds:1;
195 u8 has_contact_geometry:1;
200 struct f11_2d_sensor_query {
204 u8 number_of_fingers:3;
208 u8 has_sensitivity_adjust:1;
211 u8 num_of_x_electrodes:7;
213 u8 num_of_y_electrodes:7;
217 u8 f11_2d_query1__4[4];
223 u8 has_anchored_finger:1;
245 u8 has_touch_shapes:1;
246 u8 has_scroll_zones:1;
247 u8 has_individual_scroll_zones:1;
248 u8 has_multi_finger_scroll:1;
250 u8 f11_2d_query7__8[2];
253 union f11_2d_query9 query9;
257 u8 nbr_touch_shapes:5;
263 union f11_2d_ctrl10 {
265 u8 single_tap_int_enable:1;
266 u8 tap_n_hold_int_enable:1;
267 u8 double_tap_int_enable:1;
268 u8 early_tap_int_enable:1;
269 u8 flick_int_enable:1;
270 u8 press_int_enable:1;
271 u8 pinch_int_enable:1;
276 union f11_2d_ctrl11 {
278 u8 palm_detect_int_enable:1;
279 u8 rotate_int_enable:1;
280 u8 touch_shape_int_enable:1;
281 u8 scroll_zone_int_enable:1;
282 u8 multi_finger_scroll_int_enable:1;
287 union f11_2d_ctrl12 {
295 union f11_2d_ctrl14 {
297 u8 sens_adjustment:5;
298 u8 hyst_adjustment:3;
303 union f11_2d_ctrl15 {
310 union f11_2d_ctrl16 {
317 union f11_2d_ctrl17 {
319 u8 max_tap_distance:8;
324 union f11_2d_ctrl18_19 {
326 u8 min_flick_distance:8;
327 u8 min_flick_speed:8;
332 union f11_2d_ctrl20_21 {
334 u8 pen_detect_enable:1;
335 u8 pen_jitter_filter_enable:1;
336 u8 ctrl20_reserved:6;
337 u8 pen_z_threshold:8;
352 u8 report_beyond_clip:1;
354 u8 palm_detect_thres:4;
355 u8 motion_sensitivity:2;
357 u8 man_tracked_finger:1;
358 /* F11_2D_Ctrl2 and 3 */
359 u8 delta_x_threshold:8;
360 u8 delta_y_threshold:8;
361 /* F11_2D_Ctrl4 and 5 */
364 /* F11_2D_Ctrl6 thru 9 */
365 u16 sensor_max_x_pos:12;
367 u16 sensor_max_y_pos:12;
373 union f11_2d_ctrl10 *ctrl10;
374 union f11_2d_ctrl11 *ctrl11;
375 union f11_2d_ctrl12 *ctrl12;
377 union f11_2d_ctrl14 *ctrl14;
378 union f11_2d_ctrl15 *ctrl15;
379 union f11_2d_ctrl16 *ctrl16;
380 union f11_2d_ctrl17 *ctrl17;
381 union f11_2d_ctrl18_19 *ctrl18_19;
382 union f11_2d_ctrl20_21 *ctrl20_21;
385 struct f11_2d_data_1_5 {
395 struct f11_2d_data_6_7 {
400 struct f11_2d_data_8 {
410 struct f11_2d_data_9 {
418 struct f11_2d_data_10 {
422 struct f11_2d_data_10_12 {
428 struct f11_2d_data_11_12 {
430 u8 finger_separation;
433 struct f11_2d_data_13 {
437 struct f11_2d_data_14_15 {
442 struct f11_2d_data_14_17 {
451 const struct f11_2d_data_1_5 *abs_pos;
452 const struct f11_2d_data_6_7 *rel_pos;
453 const struct f11_2d_data_8 *gest_1;
454 const struct f11_2d_data_9 *gest_2;
455 const struct f11_2d_data_10 *pinch;
456 const struct f11_2d_data_10_12 *flick;
457 const struct f11_2d_data_11_12 *rotate;
458 const struct f11_2d_data_13 *shapes;
459 const struct f11_2d_data_14_15 *multi_scroll;
460 const struct f11_2d_data_14_17 *scroll_zones;
463 struct f11_2d_sensor {
464 struct rmi_f11_2d_axis_alignment axis_align;
465 struct f11_2d_sensor_query sens_query;
466 struct f11_2d_data data;
470 u8 finger_tracker[F11_MAX_NUM_OF_FINGERS];
474 struct rmi_f11_virtualbutton_map virtualbutton_map;
475 char input_name[MAX_NAME_LENGTH];
476 char input_phys[MAX_NAME_LENGTH];
477 struct input_dev *input;
478 struct input_dev *mouse_input;
482 struct f11_2d_device_query dev_query;
483 struct f11_2d_ctrl dev_controls;
486 bool rezero_on_resume;
488 struct f11_2d_sensor sensors[F11_MAX_NUM_OF_SENSORS];
491 enum finger_state_values {
492 F11_NO_FINGER = 0x00,
494 F11_INACCURATE = 0x02,
498 /** F11_INACCURATE state is overloaded to indicate pen present. */
499 #define F11_PEN F11_INACCURATE
501 static int get_tool_type(struct f11_2d_sensor *sensor, u8 finger_state) {
502 if (sensor->sens_query.query9.has_pen && finger_state == F11_PEN)
504 return MT_TOOL_FINGER;
507 static void rmi_f11_rel_pos_report(struct f11_2d_sensor *sensor, u8 n_finger)
509 struct f11_2d_data *data = &sensor->data;
510 struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align;
514 x = data->rel_pos[n_finger].delta_x;
515 y = data->rel_pos[n_finger].delta_y;
517 x = min(F11_REL_POS_MAX, max(F11_REL_POS_MIN, (int)x));
518 y = min(F11_REL_POS_MAX, max(F11_REL_POS_MIN, (int)y));
520 if (axis_align->swap_axes) {
525 if (axis_align->flip_x)
526 x = min(F11_REL_POS_MAX, -x);
527 if (axis_align->flip_y)
528 y = min(F11_REL_POS_MAX, -y);
531 input_report_rel(sensor->input, REL_X, x);
532 input_report_rel(sensor->input, REL_Y, y);
533 input_report_rel(sensor->mouse_input, REL_X, x);
534 input_report_rel(sensor->mouse_input, REL_Y, y);
536 input_sync(sensor->mouse_input);
539 static void rmi_f11_abs_pos_report(struct f11_2d_sensor *sensor,
540 u8 finger_state, u8 n_finger)
542 struct f11_2d_data *data = &sensor->data;
543 struct rmi_f11_2d_axis_alignment *axis_align = &sensor->axis_align;
544 int prev_state = sensor->finger_tracker[n_finger];
546 int w_x, w_y, w_max, w_min, orient;
549 if (prev_state && !finger_state) {
550 /* this is a release */
551 x = y = z = w_max = w_min = orient = 0;
552 input_mt_slot(sensor->input, n_finger);
553 input_mt_report_slot_state(sensor->input, MT_TOOL_FINGER, false);
554 input_report_abs(sensor->input, ABS_MT_TRACKING_ID, -1);
555 } else if (!prev_state && !finger_state) {
556 /* nothing to report */
559 x = ((data->abs_pos[n_finger].x_msb << 4) |
560 data->abs_pos[n_finger].x_lsb);
561 y = ((data->abs_pos[n_finger].y_msb << 4) |
562 data->abs_pos[n_finger].y_lsb);
563 z = data->abs_pos[n_finger].z;
564 w_x = data->abs_pos[n_finger].w_x;
565 w_y = data->abs_pos[n_finger].w_y;
566 w_max = max(w_x, w_y);
567 w_min = min(w_x, w_y);
568 if (axis_align->swap_axes) {
577 orient = w_x > w_y ? 1 : 0;
579 if (axis_align->flip_x)
580 x = max(sensor->max_x - x, 0);
582 if (axis_align->flip_y)
583 y = max(sensor->max_y - y, 0);
586 ** here checking if X offset or y offset are specified is
587 ** redundant. We just add the offsets or, clip the values
589 ** note: offsets need to be done before clipping occurs,
590 ** or we could get funny values that are outside
591 ** clipping boundaries.
593 x += axis_align->offset_X;
594 y += axis_align->offset_Y;
595 x = max(axis_align->clip_X_low, x);
596 y = max(axis_align->clip_Y_low, y);
597 if (axis_align->clip_X_high)
598 x = min(axis_align->clip_X_high, x);
599 if (axis_align->clip_Y_high)
600 y = min(axis_align->clip_Y_high, y);
602 pr_debug("%s: f_state[%d]:%d - x:%d y:%d z:%d w_max:%d w_min:%d\n",
603 __func__, n_finger, finger_state, x, y, z, w_max, w_min);
604 #ifndef CONFIG_RMI4_F11_PEN
605 /* Some UIs ignore W of zero, so we fudge it to 1 for pens. */
606 if (sensor->sens_query.query9.has_pen &&
607 get_tool_type(sensor, finger_state) == MT_TOOL_PEN) {
608 w_max = max(1, w_max);
609 w_min = max(1, w_min);
612 //printk("+finger:%d, state:%d x:%d, y:%d\n",n_finger, finger_state, x , y);
613 input_mt_slot(sensor->input, n_finger);
614 input_mt_report_slot_state(sensor->input, MT_TOOL_FINGER, true);
615 input_report_abs(sensor->input, ABS_MT_TRACKING_ID, n_finger);
616 input_report_abs(sensor->input, ABS_MT_TOUCH_MAJOR, w_max);
617 input_report_abs(sensor->input, ABS_MT_PRESSURE, z);
618 input_report_abs(sensor->input, ABS_MT_TOUCH_MINOR, w_min);
619 input_report_abs(sensor->input, ABS_MT_ORIENTATION, orient);
620 input_report_abs(sensor->input, ABS_MT_POSITION_X, x);
621 input_report_abs(sensor->input, ABS_MT_POSITION_Y, y);
623 #ifdef CONFIG_RMI4_F11_PEN
624 if (sensor->sens_query.query9.has_pen) {
625 input_report_abs(sensor->input, ABS_MT_TOOL_TYPE,
626 get_tool_type(sensor, finger_state));
631 sensor->finger_tracker[n_finger] = finger_state;
634 #ifdef CONFIG_RMI4_VIRTUAL_BUTTON
635 static int rmi_f11_virtual_button_handler(struct f11_2d_sensor *sensor)
640 struct rmi_f11_virtualbutton_map *virtualbutton_map;
641 if (sensor->sens_query.has_gestures &&
642 sensor->data.gest_1->single_tap) {
643 virtualbutton_map = &sensor->virtualbutton_map;
644 x = ((sensor->data.abs_pos[0].x_msb << 4) |
645 sensor->data.abs_pos[0].x_lsb);
646 y = ((sensor->data.abs_pos[0].y_msb << 4) |
647 sensor->data.abs_pos[0].y_lsb);
648 for (i = 0; i < virtualbutton_map->buttons; i++) {
649 if (INBOX(x, y, virtualbutton_map->map[i])) {
650 input_report_key(sensor->input,
651 virtualbutton_map->map[i].code, 1);
652 input_report_key(sensor->input,
653 virtualbutton_map->map[i].code, 0);
654 input_sync(sensor->input);
662 #define rmi_f11_virtual_button_handler(sensor)
665 static void rmi_f11_finger_handler(struct f11_2d_sensor *sensor)
667 const u8 *f_state = sensor->data.f_state;
669 u8 finger_pressed_count;
671 for (i = 0, finger_pressed_count = 0; i < sensor->nbr_fingers; i++) {
672 /* Possible of having 4 fingers per f_statet register */
673 finger_state = GET_FINGER_STATE(f_state, i);
675 if (finger_state == F11_RESERVED) {
676 pr_err("%s: Invalid finger state[%d]:0x%02x.", __func__,
679 } else if (finger_state == F11_PRESENT) {
680 finger_pressed_count++;
681 } else if (finger_state == F11_INACCURATE) {
685 if (sensor->data.abs_pos)
686 rmi_f11_abs_pos_report(sensor, finger_state, i);
688 if (sensor->data.rel_pos)
689 rmi_f11_rel_pos_report(sensor, i);
691 input_report_key(sensor->input, BTN_TOUCH, finger_pressed_count);
692 input_sync(sensor->input);
695 static int f11_2d_construct_data(struct f11_2d_sensor *sensor)
697 struct f11_2d_sensor_query *query = &sensor->sens_query;
698 struct f11_2d_data *data = &sensor->data;
701 sensor->nbr_fingers = (query->number_of_fingers == 5 ? 10 :
702 query->number_of_fingers + 1);
704 sensor->pkt_size = F11_CEIL(sensor->nbr_fingers, 4);
707 sensor->pkt_size += (sensor->nbr_fingers * 5);
710 sensor->pkt_size += (sensor->nbr_fingers * 2);
712 /* Check if F11_2D_Query7 is non-zero */
713 if (query->f11_2d_query7__8[0])
714 sensor->pkt_size += sizeof(u8);
716 /* Check if F11_2D_Query7 or F11_2D_Query8 is non-zero */
717 if (query->f11_2d_query7__8[0] || query->f11_2d_query7__8[1])
718 sensor->pkt_size += sizeof(u8);
720 if (query->has_pinch || query->has_flick || query->has_rotate) {
721 sensor->pkt_size += 3;
722 if (!query->has_flick)
724 if (!query->has_rotate)
728 if (query->has_touch_shapes)
729 sensor->pkt_size += F11_CEIL(query->nbr_touch_shapes + 1, 8);
731 sensor->data_pkt = kzalloc(sensor->pkt_size, GFP_KERNEL);
732 if (!sensor->data_pkt)
735 data->f_state = sensor->data_pkt;
736 i = F11_CEIL(sensor->nbr_fingers, 4);
738 if (query->has_abs) {
739 data->abs_pos = (struct f11_2d_data_1_5 *)
740 &sensor->data_pkt[i];
741 i += (sensor->nbr_fingers * 5);
744 if (query->has_rel) {
745 data->rel_pos = (struct f11_2d_data_6_7 *)
746 &sensor->data_pkt[i];
747 i += (sensor->nbr_fingers * 2);
750 if (query->f11_2d_query7__8[0]) {
751 data->gest_1 = (struct f11_2d_data_8 *)&sensor->data_pkt[i];
755 if (query->f11_2d_query7__8[0] || query->f11_2d_query7__8[1]) {
756 data->gest_2 = (struct f11_2d_data_9 *)&sensor->data_pkt[i];
760 if (query->has_pinch) {
761 data->pinch = (struct f11_2d_data_10 *)&sensor->data_pkt[i];
765 if (query->has_flick) {
766 if (query->has_pinch) {
767 data->flick = (struct f11_2d_data_10_12 *)data->pinch;
770 data->flick = (struct f11_2d_data_10_12 *)
771 &sensor->data_pkt[i];
776 if (query->has_rotate) {
777 if (query->has_flick) {
778 data->rotate = (struct f11_2d_data_11_12 *)
781 data->rotate = (struct f11_2d_data_11_12 *)
782 &sensor->data_pkt[i];
787 if (query->has_touch_shapes)
788 data->shapes = (struct f11_2d_data_13 *)&sensor->data_pkt[i];
793 static void f11_free_control_regs(struct f11_2d_ctrl *ctrl)
801 kfree(ctrl->ctrl18_19);
802 kfree(ctrl->ctrl20_21);
809 ctrl->ctrl18_19 = NULL;
810 ctrl->ctrl20_21 = NULL;
813 static int f11_read_control_regs(struct rmi_device *rmi_dev,
814 struct f11_2d_ctrl *ctrl,
815 int ctrl_base_addr) {
816 int read_address = ctrl_base_addr;
819 error = rmi_read_block(rmi_dev, read_address, ctrl->ctrl0_9,
820 sizeof(ctrl->ctrl0_9));
822 dev_err(&rmi_dev->dev,
823 "Failed to read F11 ctrl0, code: %d.\n", error);
826 read_address = read_address + sizeof(ctrl->ctrl0_9);
829 error = rmi_read_block(rmi_dev, read_address,
830 &ctrl->ctrl10->reg, sizeof(union f11_2d_ctrl10));
832 dev_err(&rmi_dev->dev,
833 "Failed to read F11 ctrl10, code: %d.\n",
837 read_address = read_address + sizeof(union f11_2d_ctrl10);
841 error = rmi_read_block(rmi_dev, read_address,
842 &ctrl->ctrl11->reg, sizeof(union f11_2d_ctrl11));
844 dev_err(&rmi_dev->dev,
845 "Failed to read F11 ctrl11, code: %d.\n",
849 read_address = read_address + sizeof(union f11_2d_ctrl11);
853 error = rmi_read_block(rmi_dev, read_address,
854 &ctrl->ctrl14->reg, sizeof(union f11_2d_ctrl14));
856 dev_err(&rmi_dev->dev,
857 "Failed to read F11 ctrl14, code: %d.\n",
861 read_address = read_address + sizeof(union f11_2d_ctrl14);
865 error = rmi_read_block(rmi_dev, read_address,
866 &ctrl->ctrl15->reg, sizeof(union f11_2d_ctrl15));
868 dev_err(&rmi_dev->dev,
869 "Failed to read F11 ctrl15, code: %d.\n",
873 read_address = read_address + sizeof(union f11_2d_ctrl15);
877 error = rmi_read_block(rmi_dev, read_address,
878 &ctrl->ctrl16->reg, sizeof(union f11_2d_ctrl16));
880 dev_err(&rmi_dev->dev,
881 "Failed to read F11 ctrl16, code: %d.\n",
885 read_address = read_address + sizeof(union f11_2d_ctrl16);
889 error = rmi_read_block(rmi_dev, read_address,
890 &ctrl->ctrl17->reg, sizeof(union f11_2d_ctrl17));
892 dev_err(&rmi_dev->dev,
893 "Failed to read F11 ctrl17, code: %d.\n",
897 read_address = read_address + sizeof(union f11_2d_ctrl17);
900 if (ctrl->ctrl18_19) {
901 error = rmi_read_block(rmi_dev, read_address,
902 ctrl->ctrl18_19->reg, sizeof(union f11_2d_ctrl18_19));
904 dev_err(&rmi_dev->dev,
905 "Failed to read F11 ctrl18_19, code: %d.\n",
909 read_address = read_address + sizeof(union f11_2d_ctrl18_19);
912 if (ctrl->ctrl20_21) {
913 error = rmi_read_block(rmi_dev, read_address,
914 ctrl->ctrl20_21->reg, sizeof(union f11_2d_ctrl20_21));
916 dev_err(&rmi_dev->dev,
917 "Failed to read F11 ctrl20_21, code: %d.\n",
921 read_address = read_address + sizeof(union f11_2d_ctrl20_21);
927 static int f11_allocate_control_regs(struct rmi_device *rmi_dev,
928 struct f11_2d_device_query *device_query,
929 struct f11_2d_sensor_query *sensor_query,
930 struct f11_2d_ctrl *ctrl,
931 int ctrl_base_addr) {
934 if (sensor_query->f11_2d_query7__8[0]) {
935 ctrl->ctrl10 = kzalloc(sizeof(union f11_2d_ctrl10),
943 if (sensor_query->f11_2d_query7__8[1]) {
944 ctrl->ctrl11 = kzalloc(sizeof(union f11_2d_ctrl11),
952 if (device_query->has_query9 && sensor_query->query9.has_pen) {
953 ctrl->ctrl20_21 = kzalloc(sizeof(union f11_2d_ctrl20_21),
955 if (!ctrl->ctrl20_21) {
961 return f11_read_control_regs(rmi_dev, ctrl, ctrl_base_addr);
964 f11_free_control_regs(ctrl);
968 static int f11_write_control_regs(struct rmi_device *rmi_dev,
969 struct f11_2d_sensor_query *query,
970 struct f11_2d_ctrl *ctrl,
973 int write_address = ctrl_base_addr;
976 error = rmi_write_block(rmi_dev, write_address,
977 ctrl->ctrl0_9, sizeof(ctrl->ctrl0_9));
980 write_address += sizeof(ctrl->ctrl0_9);
983 error = rmi_write_block(rmi_dev, write_address,
984 &ctrl->ctrl10->reg, 1);
991 error = rmi_write_block(rmi_dev, write_address,
992 &ctrl->ctrl11->reg, 1);
998 if (ctrl->ctrl12 && ctrl->ctrl12_size && query->configurable) {
999 if (ctrl->ctrl12_size > query->max_electrodes) {
1000 dev_err(&rmi_dev->dev,
1001 "%s: invalid cfg size:%d, should be < %d.\n",
1002 __func__, ctrl->ctrl12_size,
1003 query->max_electrodes);
1006 error = rmi_write_block(rmi_dev, write_address,
1011 write_address += ctrl->ctrl12_size;
1015 error = rmi_write_block(rmi_dev, write_address,
1016 &ctrl->ctrl14->reg, 1);
1023 error = rmi_write_block(rmi_dev, write_address,
1024 &ctrl->ctrl15->reg, 1);
1031 error = rmi_write_block(rmi_dev, write_address,
1032 &ctrl->ctrl16->reg, 1);
1039 error = rmi_write_block(rmi_dev, write_address,
1040 &ctrl->ctrl17->reg, 1);
1046 if (ctrl->ctrl18_19) {
1047 error = rmi_write_block(rmi_dev, write_address,
1048 ctrl->ctrl18_19->reg, sizeof(union f11_2d_ctrl18_19));
1051 write_address += sizeof(union f11_2d_ctrl18_19);
1054 if (ctrl->ctrl20_21) {
1055 error = rmi_write_block(rmi_dev, write_address,
1056 ctrl->ctrl20_21->reg,
1057 sizeof(union f11_2d_ctrl20_21));
1060 write_address += sizeof(union f11_2d_ctrl20_21);
1066 static int rmi_f11_get_query_parameters(struct rmi_device *rmi_dev,
1067 struct f11_2d_sensor_query *query, u8 query_base_addr)
1072 rc = rmi_read_block(rmi_dev, query_base_addr, query->f11_2d_query1__4,
1073 sizeof(query->f11_2d_query1__4));
1078 if (query->has_abs) {
1079 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1080 &query->f11_2d_query5);
1086 if (query->has_rel) {
1087 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1088 &query->f11_2d_query6);
1094 if (query->has_gestures) {
1095 rc = rmi_read_block(rmi_dev, query_base_addr + query_size,
1096 query->f11_2d_query7__8,
1097 sizeof(query->f11_2d_query7__8));
1100 query_size += sizeof(query->f11_2d_query7__8);
1103 if (query->has_touch_shapes) {
1104 rc = rmi_read(rmi_dev, query_base_addr + query_size,
1105 &query->f11_2d_query10);
1114 /* This operation is done in a number of places, so we have a handy routine
1117 static void f11_set_abs_params(struct rmi_function_container *fc, int index)
1119 struct f11_data *instance_data = fc->data;
1120 struct f11_2d_sensor *sensor = &instance_data->sensors[index];
1121 struct input_dev *input = sensor->input;
1123 instance_data->dev_controls.sensor_max_x_pos;
1125 instance_data->dev_controls.sensor_max_y_pos;
1126 int x_min, x_max, y_min, y_max;
1128 if (sensor->axis_align.swap_axes) {
1129 int temp = device_x_max;
1130 device_x_max = device_y_max;
1131 device_y_max = temp;
1134 /* Use the max X and max Y read from the device, or the clip values,
1135 * whichever is stricter.
1137 x_min = sensor->axis_align.clip_X_low;
1138 if (sensor->axis_align.clip_X_high)
1139 x_max = min((int) device_x_max,
1140 sensor->axis_align.clip_X_high);
1142 x_max = device_x_max;
1144 y_min = sensor->axis_align.clip_Y_low;
1145 if (sensor->axis_align.clip_Y_high)
1146 y_max = min((int) device_y_max,
1147 sensor->axis_align.clip_Y_high);
1149 y_max = device_y_max;
1151 dev_dbg(&fc->dev, "Set ranges X=[%d..%d] Y=[%d..%d].",
1152 x_min, x_max, y_min, y_max);
1154 __set_bit(INPUT_PROP_DIRECT, input->propbit);
1155 __set_bit(EV_ABS, input->evbit);
1156 input_mt_init_slots(input, SYNAPTICS_MAX_POINTS);
1157 input_set_abs_params(input, ABS_MT_PRESSURE, 0, DEFAULT_MAX_ABS_MT_PRESSURE, 0, 0);
1158 input_set_abs_params(input, ABS_MT_TOUCH_MAJOR, 0, DEFAULT_MAX_ABS_MT_TOUCH, 0, 0);
1159 input_set_abs_params(input, ABS_MT_TOUCH_MINOR, 0, DEFAULT_MAX_ABS_MT_TOUCH, 0, 0);
1160 input_set_abs_params(input, ABS_MT_ORIENTATION, 0, DEFAULT_MAX_ABS_MT_ORIENTATION, 0, 0);
1161 input_set_abs_params(input, ABS_MT_TRACKING_ID,
1162 DEFAULT_MIN_ABS_MT_TRACKING_ID,
1163 DEFAULT_MAX_ABS_MT_TRACKING_ID, 0, 0);
1164 /* TODO get max_x_pos (and y) from control registers. */
1165 input_set_abs_params(input, ABS_MT_POSITION_X, x_min, x_max, 0, 0);
1166 input_set_abs_params(input, ABS_MT_POSITION_Y, y_min, y_max, 0, 0);
1167 #ifdef CONFIG_RMI4_F11_PEN
1168 if (sensor->sens_query.query9.has_pen)
1169 input_set_abs_params(input, ABS_MT_TOOL_TYPE,
1170 0, MT_TOOL_MAX, 0, 0);
1174 static int rmi_f11_init(struct rmi_function_container *fc)
1178 rc = rmi_f11_initialize(fc);
1182 rc = rmi_f11_register_devices(fc);
1186 rc = rmi_f11_create_sysfs(fc);
1190 //hhb@rock-chips.com
1193 rmi_write_block(fc->rmi_dev, fc->fd.control_base_addr, buf, 1);
1197 rmi_f11_free_memory(fc);
1202 static void rmi_f11_free_memory(struct rmi_function_container *fc)
1204 struct f11_data *f11 = fc->data;
1208 f11_free_control_regs(&f11->dev_controls);
1209 for (i = 0; i < f11->dev_query.nbr_of_sensors + 1; i++)
1210 kfree(f11->sensors[i].virtualbutton_map.map);
1217 static int rmi_f11_initialize(struct rmi_function_container *fc)
1219 struct rmi_device *rmi_dev = fc->rmi_dev;
1220 struct f11_data *f11;
1223 u8 control_base_addr;
1224 u16 max_x_pos, max_y_pos, temp;
1227 struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
1229 dev_dbg(&fc->dev, "Initializing F11 values for %s.\n",
1230 pdata->sensor_name);
1233 ** init instance data, fill in values and create any sysfs files
1235 f11 = kzalloc(sizeof(struct f11_data), GFP_KERNEL);
1241 f11->rezero_on_resume = true;
1242 f11->rezero_wait_ms = DEFAULT_REZERO_WAIT_MS;
1245 query_base_addr = fc->fd.query_base_addr;
1246 control_base_addr = fc->fd.control_base_addr;
1248 rc = rmi_read(rmi_dev, query_base_addr, &f11->dev_query.f11_2d_query0);
1252 query_offset = (query_base_addr + 1);
1253 /* Increase with one since number of sensors is zero based */
1254 for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
1255 f11->sensors[i].sensor_index = i;
1257 rc = rmi_f11_get_query_parameters(rmi_dev,
1258 &f11->sensors[i].sens_query,
1264 if (f11->dev_query.has_query9) {
1265 rc = rmi_read(rmi_dev, query_offset,
1266 &f11->sensors[i].sens_query.query9.reg);
1268 dev_err(&fc->dev, "Failed to read query 9.\n");
1274 rc = f11_allocate_control_regs(rmi_dev,
1275 &f11->dev_query, &f11->sensors[i].sens_query,
1276 &f11->dev_controls, control_base_addr);
1279 "Failed to initialize F11 control params.\n");
1283 f11->sensors[i].axis_align = pdata->axis_align;
1285 rc = rmi_read_block(rmi_dev,
1286 control_base_addr + F11_CTRL_SENSOR_MAX_X_POS_OFFSET,
1287 (u8 *)&max_x_pos, sizeof(max_x_pos));
1291 rc = rmi_read_block(rmi_dev,
1292 control_base_addr + F11_CTRL_SENSOR_MAX_Y_POS_OFFSET,
1293 (u8 *)&max_y_pos, sizeof(max_y_pos));
1297 if (pdata->axis_align.swap_axes) {
1299 max_x_pos = max_y_pos;
1302 f11->sensors[i].max_x = max_x_pos;
1303 f11->sensors[i].max_y = max_y_pos;
1305 rc = f11_2d_construct_data(&f11->sensors[i]);
1313 static int rmi_f11_register_devices(struct rmi_function_container *fc)
1315 struct rmi_device *rmi_dev = fc->rmi_dev;
1316 struct f11_data *f11 = fc->data;
1317 struct input_dev *input_dev;
1318 struct input_dev *input_dev_mouse;
1319 int sensors_itertd = 0;
1322 #ifdef CONFIG_RMI4_VIRTUAL_BUTTON
1323 struct rmi_f11_virtualbutton_map *vm_sensor;
1324 struct rmi_f11_virtualbutton_map *vm_pdata;
1325 struct rmi_device_platform_data *pdata = to_rmi_platform_data(rmi_dev);
1328 for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
1330 input_dev = input_allocate_device();
1333 goto error_unregister;
1336 f11->sensors[i].input = input_dev;
1337 /* TODO how to modify the dev name and
1338 * phys name for input device */
1339 sprintf(f11->sensors[i].input_name, "%sfn%02x",
1340 dev_name(&rmi_dev->dev), fc->fd.function_number);
1341 input_dev->name = f11->sensors[i].input_name;
1342 sprintf(f11->sensors[i].input_phys, "%s/input0",
1344 input_dev->phys = f11->sensors[i].input_phys;
1345 input_dev->dev.parent = &rmi_dev->dev;
1346 input_set_drvdata(input_dev, f11);
1348 set_bit(EV_SYN, input_dev->evbit);
1349 set_bit(EV_KEY, input_dev->evbit);
1350 set_bit(EV_ABS, input_dev->evbit);
1352 f11_set_abs_params(fc, i);
1354 dev_dbg(&fc->dev, "%s: Sensor %d hasRel %d.\n",
1355 __func__, i, f11->sensors[i].sens_query.has_rel);
1356 if (f11->sensors[i].sens_query.has_rel) {
1357 set_bit(EV_REL, input_dev->evbit);
1358 set_bit(REL_X, input_dev->relbit);
1359 set_bit(REL_Y, input_dev->relbit);
1361 rc = input_register_device(input_dev);
1363 input_free_device(input_dev);
1364 f11->sensors[i].input = NULL;
1365 goto error_unregister;
1368 /* how to register the virtualbutton device */
1369 #ifdef CONFIG_RMI4_VIRTUAL_BUTTON
1370 if (f11->sensors[i].sens_query.has_gestures) {
1373 vm_sensor = &f11->sensors[i].virtualbutton_map;
1374 vm_pdata = pdata->virtualbutton_map;
1376 dev_err(&fc->dev, "Failed to get the pdata virtualbutton map.\n");
1377 goto error_unregister;
1379 vm_sensor->buttons = vm_pdata->buttons;
1380 vm_sensor->map = kcalloc(vm_pdata->buttons,
1381 sizeof(struct virtualbutton_map),
1383 if (!vm_sensor->map) {
1384 dev_err(&fc->dev, "Failed to allocate the virtualbutton map.\n");
1386 goto error_unregister;
1388 /* set bits for each button... */
1389 for (j = 0; j < vm_pdata->buttons; j++) {
1390 memcpy(&vm_sensor->map[j], &vm_pdata->map[j],
1391 sizeof(struct virtualbutton_map));
1392 set_bit(vm_sensor->map[j].code,
1393 f11->sensors[i].input->keybit);
1399 if (f11->sensors[i].sens_query.has_rel) {
1400 /*create input device for mouse events */
1401 input_dev_mouse = input_allocate_device();
1402 if (!input_dev_mouse) {
1404 goto error_unregister;
1407 f11->sensors[i].mouse_input = input_dev_mouse;
1408 input_dev_mouse->name = "rmi_mouse";
1409 input_dev_mouse->phys = "rmi_f11/input0";
1411 input_dev_mouse->id.vendor = 0x18d1;
1412 input_dev_mouse->id.product = 0x0210;
1413 input_dev_mouse->id.version = 0x0100;
1415 set_bit(EV_REL, input_dev_mouse->evbit);
1416 set_bit(REL_X, input_dev_mouse->relbit);
1417 set_bit(REL_Y, input_dev_mouse->relbit);
1419 set_bit(BTN_MOUSE, input_dev_mouse->evbit);
1420 /* Register device's buttons and keys */
1421 set_bit(EV_KEY, input_dev_mouse->evbit);
1422 set_bit(BTN_LEFT, input_dev_mouse->keybit);
1423 set_bit(BTN_MIDDLE, input_dev_mouse->keybit);
1424 set_bit(BTN_RIGHT, input_dev_mouse->keybit);
1426 rc = input_register_device(input_dev_mouse);
1428 input_free_device(input_dev_mouse);
1429 f11->sensors[i].mouse_input = NULL;
1430 goto error_unregister;
1433 set_bit(BTN_RIGHT, input_dev_mouse->keybit);
1441 for (; sensors_itertd > 0; sensors_itertd--) {
1442 if (f11->sensors[sensors_itertd].input) {
1443 if (f11->sensors[sensors_itertd].mouse_input) {
1444 input_unregister_device(
1445 f11->sensors[sensors_itertd].mouse_input);
1446 f11->sensors[sensors_itertd].mouse_input = NULL;
1448 input_unregister_device(f11->sensors[i].input);
1449 f11->sensors[i].input = NULL;
1451 kfree(f11->sensors[i].virtualbutton_map.map);
1457 static void rmi_f11_free_devices(struct rmi_function_container *fc)
1459 struct f11_data *f11 = fc->data;
1462 for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
1463 if (f11->sensors[i].input)
1464 input_unregister_device(f11->sensors[i].input);
1465 if (f11->sensors[i].sens_query.has_rel &&
1466 f11->sensors[i].mouse_input)
1467 input_unregister_device(f11->sensors[i].mouse_input);
1471 static int rmi_f11_create_sysfs(struct rmi_function_container *fc)
1476 dev_dbg(&fc->dev, "Creating sysfs files.\n");
1477 /* Set up sysfs device attributes. */
1478 for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
1479 if (sysfs_create_file
1480 (&fc->dev.kobj, &attrs[attr_count].attr) < 0) {
1482 "Failed to create sysfs file for %s.",
1483 attrs[attr_count].attr.name);
1485 goto err_remove_sysfs;
1492 for (attr_count--; attr_count >= 0; attr_count--)
1493 sysfs_remove_file(&fc->dev.kobj,
1494 &attrs[attr_count].attr);
1498 static int rmi_f11_config(struct rmi_function_container *fc)
1500 struct f11_data *f11 = fc->data;
1504 for (i = 0; i < (f11->dev_query.nbr_of_sensors + 1); i++) {
1505 rc = f11_write_control_regs(fc->rmi_dev,
1506 &f11->sensors[i].sens_query,
1508 fc->fd.query_base_addr);
1515 static int rmi_f11_reset(struct rmi_function_container *fc)
1517 /* we do nothing here */
1521 int rmi_f11_attention(struct rmi_function_container *fc, u8 *irq_bits)
1523 struct rmi_device *rmi_dev = fc->rmi_dev;
1524 struct f11_data *f11 = fc->data;
1525 u8 data_base_addr = fc->fd.data_base_addr;
1526 int data_base_addr_offset = 0;
1530 for (i = 0; i < f11->dev_query.nbr_of_sensors + 1; i++) {
1531 error = rmi_read_block(rmi_dev,
1532 data_base_addr + data_base_addr_offset,
1533 f11->sensors[i].data_pkt,
1534 f11->sensors[i].pkt_size);
1538 rmi_f11_finger_handler(&f11->sensors[i]);
1539 rmi_f11_virtual_button_handler(&f11->sensors[i]);
1540 data_base_addr_offset += f11->sensors[i].pkt_size;
1547 static int rmi_f11_resume(struct rmi_function_container *fc)
1549 struct rmi_device *rmi_dev = fc->rmi_dev;
1550 struct f11_data *data = fc->data;
1551 /* Command register always reads as 0, so we can just use a local. */
1552 union f11_2d_commands commands = {};
1555 dev_dbg(&fc->dev, "Resuming...\n");
1556 if (!data->rezero_on_resume)
1559 if (data->rezero_wait_ms)
1560 mdelay(data->rezero_wait_ms);
1562 commands.rezero = 1;
1563 retval = rmi_write_block(rmi_dev, fc->fd.command_base_addr,
1564 &commands.reg, sizeof(commands.reg));
1566 dev_err(&rmi_dev->dev, "%s: failed to issue rezero command, error = %d.",
1573 #endif /* RESUME_REZERO */
1575 static void rmi_f11_remove(struct rmi_function_container *fc)
1579 for (attr_count = 0; attr_count < ARRAY_SIZE(attrs); attr_count++) {
1580 sysfs_remove_file(&fc->dev.kobj,
1581 &attrs[attr_count].attr);
1584 rmi_f11_free_devices(fc);
1586 rmi_f11_free_memory(fc);
1590 static struct rmi_function_handler function_handler = {
1592 .init = rmi_f11_init,
1593 .config = rmi_f11_config,
1594 .reset = rmi_f11_reset,
1595 .attention = rmi_f11_attention,
1596 .remove = rmi_f11_remove
1598 #ifdef CONFIG_HAS_EARLYSUSPEND
1600 .late_resume = rmi_f11_resume
1602 .resume = rmi_f11_resume
1603 #endif /* CONFIG_HAS_EARLYSUSPEND */
1607 static int __init rmi_f11_module_init(void)
1611 error = rmi_register_function_driver(&function_handler);
1613 pr_err("%s: register failed!\n", __func__);
1620 static void __exit rmi_f11_module_exit(void)
1622 rmi_unregister_function_driver(&function_handler);
1625 static ssize_t f11_maxPos_show(struct device *dev,
1626 struct device_attribute *attr,
1629 struct rmi_function_container *fc;
1630 struct f11_data *data;
1632 fc = to_rmi_function_container(dev);
1635 return snprintf(buf, PAGE_SIZE, "%u %u\n",
1636 data->sensors[0].max_x, data->sensors[0].max_y);
1639 static ssize_t f11_flip_show(struct device *dev,
1640 struct device_attribute *attr,
1643 struct rmi_function_container *fc;
1644 struct f11_data *data;
1646 fc = to_rmi_function_container(dev);
1649 return snprintf(buf, PAGE_SIZE, "%u %u\n",
1650 data->sensors[0].axis_align.flip_x,
1651 data->sensors[0].axis_align.flip_y);
1654 static ssize_t f11_flip_store(struct device *dev,
1655 struct device_attribute *attr,
1659 struct rmi_function_container *fc;
1660 struct f11_data *instance_data;
1661 unsigned int new_X, new_Y;
1663 fc = to_rmi_function_container(dev);
1664 instance_data = fc->data;
1667 if (sscanf(buf, "%u %u", &new_X, &new_Y) != 2)
1669 if (new_X < 0 || new_X > 1 || new_Y < 0 || new_Y > 1)
1671 instance_data->sensors[0].axis_align.flip_x = new_X;
1672 instance_data->sensors[0].axis_align.flip_y = new_Y;
1677 static ssize_t f11_swap_show(struct device *dev,
1678 struct device_attribute *attr, char *buf)
1680 struct rmi_function_container *fc;
1681 struct f11_data *instance_data;
1683 fc = to_rmi_function_container(dev);
1684 instance_data = fc->data;
1686 return snprintf(buf, PAGE_SIZE, "%u\n",
1687 instance_data->sensors[0].axis_align.swap_axes);
1690 static ssize_t f11_swap_store(struct device *dev,
1691 struct device_attribute *attr,
1692 const char *buf, size_t count)
1694 struct rmi_function_container *fc;
1695 struct f11_data *instance_data;
1696 unsigned int newSwap;
1698 fc = to_rmi_function_container(dev);
1699 instance_data = fc->data;
1702 if (sscanf(buf, "%u", &newSwap) != 1)
1704 if (newSwap < 0 || newSwap > 1)
1706 instance_data->sensors[0].axis_align.swap_axes = newSwap;
1708 f11_set_abs_params(fc, 0);
1713 static ssize_t f11_relreport_show(struct device *dev,
1714 struct device_attribute *attr,
1717 struct rmi_function_container *fc;
1718 struct f11_data *instance_data;
1720 fc = to_rmi_function_container(dev);
1721 instance_data = fc->data;
1723 return snprintf(buf, PAGE_SIZE, "%u\n",
1725 sensors[0].axis_align.rel_report_enabled);
1728 static ssize_t f11_relreport_store(struct device *dev,
1729 struct device_attribute *attr,
1733 struct rmi_function_container *fc;
1734 struct f11_data *instance_data;
1735 unsigned int new_value;
1737 fc = to_rmi_function_container(dev);
1738 instance_data = fc->data;
1741 if (sscanf(buf, "%u", &new_value) != 1)
1743 if (new_value < 0 || new_value > 1)
1745 instance_data->sensors[0].axis_align.rel_report_enabled = new_value;
1750 static ssize_t f11_offset_show(struct device *dev,
1751 struct device_attribute *attr,
1754 struct rmi_function_container *fc;
1755 struct f11_data *instance_data;
1757 fc = to_rmi_function_container(dev);
1758 instance_data = fc->data;
1760 return snprintf(buf, PAGE_SIZE, "%d %d\n",
1761 instance_data->sensors[0].axis_align.offset_X,
1762 instance_data->sensors[0].axis_align.offset_Y);
1765 static ssize_t f11_offset_store(struct device *dev,
1766 struct device_attribute *attr,
1770 struct rmi_function_container *fc;
1771 struct f11_data *instance_data;
1774 fc = to_rmi_function_container(dev);
1775 instance_data = fc->data;
1778 if (sscanf(buf, "%d %d", &new_X, &new_Y) != 2)
1780 instance_data->sensors[0].axis_align.offset_X = new_X;
1781 instance_data->sensors[0].axis_align.offset_Y = new_Y;
1786 static ssize_t f11_clip_show(struct device *dev,
1787 struct device_attribute *attr,
1791 struct rmi_function_container *fc;
1792 struct f11_data *instance_data;
1794 fc = to_rmi_function_container(dev);
1795 instance_data = fc->data;
1797 return snprintf(buf, PAGE_SIZE, "%u %u %u %u\n",
1798 instance_data->sensors[0].axis_align.clip_X_low,
1799 instance_data->sensors[0].axis_align.clip_X_high,
1800 instance_data->sensors[0].axis_align.clip_Y_low,
1801 instance_data->sensors[0].axis_align.clip_Y_high);
1804 static ssize_t f11_clip_store(struct device *dev,
1805 struct device_attribute *attr,
1809 struct rmi_function_container *fc;
1810 struct f11_data *instance_data;
1811 unsigned int new_X_low, new_X_high, new_Y_low, new_Y_high;
1813 fc = to_rmi_function_container(dev);
1814 instance_data = fc->data;
1816 if (sscanf(buf, "%u %u %u %u",
1817 &new_X_low, &new_X_high, &new_Y_low, &new_Y_high) != 4)
1819 if (new_X_low < 0 || new_X_low >= new_X_high || new_Y_low < 0
1820 || new_Y_low >= new_Y_high)
1822 instance_data->sensors[0].axis_align.clip_X_low = new_X_low;
1823 instance_data->sensors[0].axis_align.clip_X_high = new_X_high;
1824 instance_data->sensors[0].axis_align.clip_Y_low = new_Y_low;
1825 instance_data->sensors[0].axis_align.clip_Y_high = new_Y_high;
1828 ** for now, we assume this is sensor index 0
1830 f11_set_abs_params(fc, 0);
1835 static ssize_t f11_rezero_store(struct device *dev,
1836 struct device_attribute *attr,
1837 const char *buf, size_t count)
1839 struct rmi_function_container *fc = NULL;
1840 unsigned int rezero;
1842 /* Command register always reads as 0, so we can just use a local. */
1843 union f11_2d_commands commands = {};
1845 fc = to_rmi_function_container(dev);
1847 if (sscanf(buf, "%u", &rezero) != 1)
1849 if (rezero < 0 || rezero > 1)
1852 /* Per spec, 0 has no effect, so we skip it entirely. */
1854 commands.rezero = 1;
1855 retval = rmi_write_block(fc->rmi_dev, fc->fd.command_base_addr,
1856 &commands.reg, sizeof(commands.reg));
1858 dev_err(dev, "%s: failed to issue rezero command, error = %d.",
1868 static ssize_t f11_rezeroOnResume_store(struct device *dev,
1869 struct device_attribute *attr,
1870 const char *buf, size_t count)
1872 struct rmi_function_container *fc = NULL;
1873 unsigned int newValue;
1874 struct f11_data *instance_data;
1876 fc = to_rmi_function_container(dev);
1877 instance_data = fc->data;
1879 if (sscanf(buf, "%u", &newValue) != 1)
1881 if (newValue < 0 || newValue > 1) {
1882 dev_err(dev, "rezeroOnResume must be either 1 or 0.\n");
1886 instance_data->rezero_on_resume = (newValue != 0);
1891 static ssize_t f11_rezeroOnResume_show(struct device *dev,
1892 struct device_attribute *attr,
1895 struct rmi_function_container *fc;
1896 struct f11_data *instance_data;
1898 fc = to_rmi_function_container(dev);
1899 instance_data = fc->data;
1901 return snprintf(buf, PAGE_SIZE, "%u\n",
1902 instance_data->rezero_on_resume);
1905 static ssize_t f11_rezeroWait_store(struct device *dev,
1906 struct device_attribute *attr,
1907 const char *buf, size_t count)
1909 struct rmi_function_container *fc = NULL;
1910 unsigned int newValue;
1911 struct f11_data *instance_data;
1913 fc = to_rmi_function_container(dev);
1914 instance_data = fc->data;
1916 if (sscanf(buf, "%u", &newValue) != 1)
1919 dev_err(dev, "rezeroWait must be 0 or greater.\n");
1923 instance_data->rezero_wait_ms = (newValue != 0);
1928 static ssize_t f11_rezeroWait_show(struct device *dev,
1929 struct device_attribute *attr,
1932 struct rmi_function_container *fc;
1933 struct f11_data *instance_data;
1935 fc = to_rmi_function_container(dev);
1936 instance_data = fc->data;
1938 return snprintf(buf, PAGE_SIZE, "%u\n",
1939 instance_data->rezero_wait_ms);
1943 module_init(rmi_f11_module_init);
1944 module_exit(rmi_f11_module_exit);
1946 MODULE_AUTHOR("Christopher Heiny <cheiny@synaptics.com");
1947 MODULE_DESCRIPTION("RMI F11 module");
1948 MODULE_LICENSE("GPL");
1949 MODULE_VERSION(RMI_DRIVER_VERSION);