huangcm
2025-02-26 a813214788f6e7b512df54f1c659cd0bdc9ac175
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/*
 *
 * FocalTech TouchScreen driver.
 *
 * Copyright (c) 2012-2020, FocalTech Systems, Ltd., all rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 */
 
/*****************************************************************************
*
* File Name: focaltech_point_report_check.c
*
* Author: Focaltech Driver Team
*
* Created: 2016-11-16
*
* Abstract: point report check function
*
* Version: v1.0
*
* Revision History:
*
*****************************************************************************/
 
/*****************************************************************************
* Included header files
*****************************************************************************/
#include "focaltech_core.h"
 
/*****************************************************************************
* Private constant and macro definitions using #define
*****************************************************************************/
#define POINT_REPORT_CHECK_WAIT_TIME                200    /* unit:ms */
#define PRC_INTR_INTERVALS                          100    /* unit:ms */
 
/*****************************************************************************
* Static variables
*****************************************************************************/
 
/*****************************************************************************
* functions body
*****************************************************************************/
/*****************************************************************************
*  Name: fts_prc_func
*  Brief: fts point report check work func, report whole up of points
*  Input:
*  Output:
*  Return:
*****************************************************************************/
static void fts_prc_func(struct work_struct *work)
{
    struct fts_ts_data *ts_data = container_of(work,
                                  struct fts_ts_data, prc_work.work);
    unsigned long cur_jiffies = jiffies;
    unsigned long intr_timeout = msecs_to_jiffies(PRC_INTR_INTERVALS);
 
    if (ts_data->prc_support && !ts_data->suspended) {
        intr_timeout += ts_data->intr_jiffies;
        if (time_after(cur_jiffies, intr_timeout)) {
            if (ts_data->touch_points) {
                fts_release_all_finger();
                if (ts_data->log_level >= 3)
                    FTS_DEBUG("prc trigger interval:%dms",
                              jiffies_to_msecs(cur_jiffies - ts_data->intr_jiffies));
            }
            ts_data->prc_mode = 0;
        } else {
            queue_delayed_work(ts_data->ts_workqueue, &ts_data->prc_work,
                               msecs_to_jiffies(POINT_REPORT_CHECK_WAIT_TIME));
            ts_data->prc_mode = 1;
        }
    } else {
        ts_data->prc_mode = 0;
    }
}
 
/*****************************************************************************
*  Name: fts_prc_queue_work
*  Brief: fts point report check queue work, call it when interrupt comes
*  Input:
*  Output:
*  Return:
*****************************************************************************/
void fts_prc_queue_work(struct fts_ts_data *ts_data)
{
    if (ts_data->prc_support && !ts_data->prc_mode && !ts_data->suspended) {
        queue_delayed_work(ts_data->ts_workqueue, &ts_data->prc_work,
                           msecs_to_jiffies(POINT_REPORT_CHECK_WAIT_TIME));
        ts_data->prc_mode = 1;
    }
}
 
 
static ssize_t fts_prc_store(
    struct device *dev,
    struct device_attribute *attr, const char *buf, size_t count)
{
    struct fts_ts_data *ts_data = dev_get_drvdata(dev);
    struct input_dev *input_dev = ts_data->input_dev;
 
    mutex_lock(&input_dev->mutex);
    if (FTS_SYSFS_ECHO_ON(buf)) {
        FTS_DEBUG("enable prc");
        ts_data->prc_support = ENABLE;
    } else if (FTS_SYSFS_ECHO_OFF(buf)) {
        FTS_DEBUG("disable prc");
        cancel_delayed_work_sync(&ts_data->prc_work);
        ts_data->prc_support = DISABLE;
    }
    mutex_unlock(&input_dev->mutex);
 
    return count;
}
 
static ssize_t fts_prc_show(
    struct device *dev, struct device_attribute *attr, char *buf)
{
    int count;
    struct fts_ts_data *ts_data = dev_get_drvdata(dev);
    struct input_dev *input_dev = ts_data->input_dev;
 
    mutex_lock(&input_dev->mutex);
    count = snprintf(buf, PAGE_SIZE, "PRC: %s\n", \
                     ts_data->prc_support ? "Enable" : "Disable");
    mutex_unlock(&input_dev->mutex);
 
    return count;
}
 
static DEVICE_ATTR(fts_prc, S_IRUGO | S_IWUSR, fts_prc_show, fts_prc_store);
 
/*****************************************************************************
*  Name: fts_point_report_check_init
*  Brief:
*  Input:
*  Output:
*  Return: < 0: Fail to create esd check queue
*****************************************************************************/
int fts_point_report_check_init(struct fts_ts_data *ts_data)
{
    int ret = 0;
 
    FTS_FUNC_ENTER();
 
    if (ts_data->ts_workqueue) {
        INIT_DELAYED_WORK(&ts_data->prc_work, fts_prc_func);
    } else {
        FTS_ERROR("fts workqueue is NULL, can't run point report check function");
        return -EINVAL;
    }
 
    ret = sysfs_create_file(&ts_data->dev->kobj, &dev_attr_fts_prc.attr);
    if ( ret < 0) {
        FTS_ERROR("create prc sysfs fail");
    }
 
    ts_data->prc_support = FTS_POINT_REPORT_CHECK_EN;
    FTS_FUNC_EXIT();
    return 0;
}
 
/*****************************************************************************
*  Name: fts_point_report_check_exit
*  Brief:
*  Input:
*  Output:
*  Return:
*****************************************************************************/
int fts_point_report_check_exit(struct fts_ts_data *ts_data)
{
    FTS_FUNC_ENTER();
    cancel_delayed_work_sync(&ts_data->prc_work);
    sysfs_remove_file(&ts_data->dev->kobj, &dev_attr_fts_prc.attr);
    FTS_FUNC_EXIT();
    return 0;
}