summaryrefstree
path: root/kernel/drivers/input/touchscreen/st/fts_aoi_event.c
blob: 1a37f659e14e4fda30bae4c01236b308efc15689 (plain)
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
// SPDX-License-Identifier: GPL-2.0-only
/*
 * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 and
 * only version 2 as published by the Free Software Foundation.
 *
 */

#include <linux/device.h>
#include <linux/i2c.h>
#include "fts.h"

static ssize_t touch_event_show(struct device *dev,
		struct device_attribute *attr, char *buf)
{

	return 0;
}

ssize_t aoi_set_store(struct device *dev, struct device_attribute *attr,
	const char *buf, size_t count)
{
	int ret;
	struct i2c_client *client = to_i2c_client(dev);
	struct fts_ts_info *info = i2c_get_clientdata(client);
	int left, top, right, bottom;

	ret = sscanf(buf, "%d %d %d %d", &left, &top, &right, &bottom);
	if (ret != 4)
		return -EINVAL;

	if (right > X_AXIS_MAX)
		right = X_AXIS_MAX;
	if (bottom > Y_AXIS_MAX)
		bottom = Y_AXIS_MAX;

	if (left < 0 || left > X_AXIS_MAX || right < 0 ||
		top > Y_AXIS_MAX || bottom < 0)
		return -EINVAL;

	if (left >= right || top >= bottom) {
		info->aoi_left = 0;
		info->aoi_top = 0;
		info->aoi_right = 0;
		info->aoi_bottom = 0;
		info->aoi_notify_enabled = false;
		return count;
	}

	info->aoi_left = left;
	info->aoi_top = top;
	info->aoi_right = right;
	info->aoi_bottom = bottom;

	info->aoi_notify_enabled = true;
	return count;
}

static ssize_t aoi_set_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct i2c_client *client = to_i2c_client(dev);
	struct fts_ts_info *info = i2c_get_clientdata(client);
	size_t len = 0;

	len = scnprintf(buf + len, PAGE_SIZE,
				"%d %d %d %d",
				info->aoi_left,
				info->aoi_top,
				info->aoi_right,
				info->aoi_bottom);

	return len;
}

static ssize_t power_set_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{
	int enable;

	if (kstrtoint(buf, 10, &enable))
		return -EINVAL;

	return count;
}

static DEVICE_ATTR_RO(touch_event);
static DEVICE_ATTR_RW(aoi_set);
static DEVICE_ATTR_WO(power_set);

static struct attribute *aoi_cmd_attributes[] = {
	&dev_attr_touch_event.attr,
	&dev_attr_aoi_set.attr,
	&dev_attr_power_set.attr,
	NULL,
};

struct attribute_group aoi_cmd_attr_group = {
	.attrs = aoi_cmd_attributes,
};

static ssize_t enable_store(struct device *dev,
	struct device_attribute *attr, const char *buf, size_t count)
{
	struct fts_ts_info *info = dev_get_drvdata(dev);
	int enable;

	if (kstrtoint(buf, 10, &enable))
		return -EINVAL;

	if (!enable && info->aoi_notify_enabled) {
		info->aoi_left = 0;
		info->aoi_top = 0;
		info->aoi_right = 0;
		info->aoi_bottom = 0;
		info->aoi_notify_enabled = false;
	} else {
		info->aoi_left = 0;
		info->aoi_top = 0;
		info->aoi_right = X_AXIS_MAX;
		info->aoi_bottom = Y_AXIS_MAX;
		info->aoi_notify_enabled = true;
	}

	return count;
}

static ssize_t enable_show(struct device *dev,
	struct device_attribute *attr, char *buf)
{
	struct fts_ts_info *info = dev_get_drvdata(dev);
	size_t len = 0;

	len = scnprintf(buf, PAGE_SIZE,
				"%d",
				info->aoi_notify_enabled);

	return len;
}

static DEVICE_ATTR_RW(enable);

static struct attribute *aoi_enable_attributes[] = {
	&dev_attr_aoi_set.attr,
	&dev_attr_enable.attr,
	NULL,
};

struct attribute_group aoi_enable_attr_group = {
	.attrs = aoi_enable_attributes,
};