1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * cyttsp5_mtb.c
3*4882a593Smuzhiyun * Parade TrueTouch(TM) Standard Product V5 Multi-Touch Protocol B Module.
4*4882a593Smuzhiyun * For use with Parade touchscreen controllers.
5*4882a593Smuzhiyun * Supported parts include:
6*4882a593Smuzhiyun * CYTMA5XX
7*4882a593Smuzhiyun * CYTMA448
8*4882a593Smuzhiyun * CYTMA445A
9*4882a593Smuzhiyun * CYTT21XXX
10*4882a593Smuzhiyun * CYTT31XXX
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * Copyright (C) 2015 Parade Technologies
13*4882a593Smuzhiyun * Copyright (C) 2012-2015 Cypress Semiconductor
14*4882a593Smuzhiyun *
15*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or
16*4882a593Smuzhiyun * modify it under the terms of the GNU General Public License
17*4882a593Smuzhiyun * version 2, and only version 2, as published by the
18*4882a593Smuzhiyun * Free Software Foundation.
19*4882a593Smuzhiyun *
20*4882a593Smuzhiyun * This program is distributed in the hope that it will be useful,
21*4882a593Smuzhiyun * but WITHOUT ANY WARRANTY; without even the implied warranty of
22*4882a593Smuzhiyun * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23*4882a593Smuzhiyun * GNU General Public License for more details.
24*4882a593Smuzhiyun *
25*4882a593Smuzhiyun * Contact Parade Technologies at www.paradetech.com <ttdrivers@paradetech.com>
26*4882a593Smuzhiyun *
27*4882a593Smuzhiyun */
28*4882a593Smuzhiyun
29*4882a593Smuzhiyun #include "cyttsp5_regs.h"
30*4882a593Smuzhiyun #include <linux/input/mt.h>
31*4882a593Smuzhiyun #include <linux/version.h>
32*4882a593Smuzhiyun
cyttsp5_final_sync(struct input_dev * input,int max_slots,int mt_sync_count,unsigned long * ids)33*4882a593Smuzhiyun static void cyttsp5_final_sync(struct input_dev *input, int max_slots,
34*4882a593Smuzhiyun int mt_sync_count, unsigned long *ids)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun int t;
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun for (t = 0; t < max_slots; t++) {
39*4882a593Smuzhiyun if (test_bit(t, ids))
40*4882a593Smuzhiyun continue;
41*4882a593Smuzhiyun input_mt_slot(input, t);
42*4882a593Smuzhiyun input_mt_report_slot_state(input, MT_TOOL_FINGER, false);
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun input_sync(input);
46*4882a593Smuzhiyun }
47*4882a593Smuzhiyun
cyttsp5_input_report(struct input_dev * input,int sig,int t,int type)48*4882a593Smuzhiyun static void cyttsp5_input_report(struct input_dev *input, int sig,
49*4882a593Smuzhiyun int t, int type)
50*4882a593Smuzhiyun {
51*4882a593Smuzhiyun input_mt_slot(input, t);
52*4882a593Smuzhiyun
53*4882a593Smuzhiyun if (type == CY_OBJ_STANDARD_FINGER || type == CY_OBJ_GLOVE
54*4882a593Smuzhiyun || type == CY_OBJ_HOVER)
55*4882a593Smuzhiyun input_mt_report_slot_state(input, MT_TOOL_FINGER, true);
56*4882a593Smuzhiyun else if (type == CY_OBJ_STYLUS)
57*4882a593Smuzhiyun input_mt_report_slot_state(input, MT_TOOL_PEN, true);
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
cyttsp5_report_slot_liftoff(struct cyttsp5_mt_data * md,int max_slots)60*4882a593Smuzhiyun static void cyttsp5_report_slot_liftoff(struct cyttsp5_mt_data *md,
61*4882a593Smuzhiyun int max_slots)
62*4882a593Smuzhiyun {
63*4882a593Smuzhiyun int t;
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun if (md->num_prv_rec == 0)
66*4882a593Smuzhiyun return;
67*4882a593Smuzhiyun
68*4882a593Smuzhiyun for (t = 0; t < max_slots; t++) {
69*4882a593Smuzhiyun input_mt_slot(md->input, t);
70*4882a593Smuzhiyun input_mt_report_slot_state(md->input,
71*4882a593Smuzhiyun MT_TOOL_FINGER, false);
72*4882a593Smuzhiyun }
73*4882a593Smuzhiyun }
74*4882a593Smuzhiyun
cyttsp5_input_register_device(struct input_dev * input,int max_slots)75*4882a593Smuzhiyun static int cyttsp5_input_register_device(struct input_dev *input, int max_slots)
76*4882a593Smuzhiyun {
77*4882a593Smuzhiyun #if (KERNEL_VERSION(3, 7, 0) <= LINUX_VERSION_CODE)
78*4882a593Smuzhiyun input_mt_init_slots(input, max_slots, 0);
79*4882a593Smuzhiyun #else
80*4882a593Smuzhiyun input_mt_init_slots(input, max_slots);
81*4882a593Smuzhiyun #endif
82*4882a593Smuzhiyun return input_register_device(input);
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun
cyttsp5_init_function_ptrs(struct cyttsp5_mt_data * md)85*4882a593Smuzhiyun void cyttsp5_init_function_ptrs(struct cyttsp5_mt_data *md)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun md->mt_function.report_slot_liftoff = cyttsp5_report_slot_liftoff;
88*4882a593Smuzhiyun md->mt_function.final_sync = cyttsp5_final_sync;
89*4882a593Smuzhiyun md->mt_function.input_sync = NULL;
90*4882a593Smuzhiyun md->mt_function.input_report = cyttsp5_input_report;
91*4882a593Smuzhiyun md->mt_function.input_register_device = cyttsp5_input_register_device;
92*4882a593Smuzhiyun }
93*4882a593Smuzhiyun
94