summaryrefslogtreecommitdiff
path: root/include/linux/maxim_sti.h
blob: 1a495e95cbc5001e7fd6fec17db4c99d3110fa47 (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
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
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
/* drivers/input/touchscreen/maxim_sti.c
 *
 * Maxim SmartTouch Imager Touchscreen Driver
 *
 * Copyright (c)2013 Maxim Integrated Products, Inc.
 * Copyright (C) 2013, NVIDIA Corporation.  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.
 *
 */

#ifndef __MAXIM_STI_H__
#define __MAXIM_STI_H__

#ifdef __KERNEL__
#include <net/genetlink.h>
#include <net/sock.h>
#else
#include <stdlib.h>
#include "genetlink.h"
#endif

#define DRIVER_VERSION  "1.4.3.dt1"
#define DRIVER_RELEASE  "December 4, 2013"

/****************************************************************************\
* Netlink: common kernel/user space macros                                   *
\****************************************************************************/

#define NL_BUF_SIZE  8192

#define NL_ATTR_FIRST(nptr) \
	((struct nlattr *)((void *)nptr + NLMSG_HDRLEN + GENL_HDRLEN))
#define NL_ATTR_LAST(nptr) \
	((struct nlattr *)((void *)nptr + \
			NLMSG_ALIGN(((struct nlmsghdr *)nptr)->nlmsg_len)))
#define NL_SIZE(nptr)   NLMSG_ALIGN(((struct nlmsghdr *)nptr)->nlmsg_len)
#define NL_TYPE(nptr)              (((struct nlmsghdr *)nptr)->nlmsg_type)
#define NL_SEQ(nptr)               (((struct nlmsghdr *)nptr)->nlmsg_seq)
#define NL_OK(nptr)              (NL_TYPE(nptr) >= NLMSG_MIN_TYPE)
#define NL_ATTR_VAL(aptr, type)  ((type *)((void *)aptr + NLA_HDRLEN))
#define NL_ATTR_NEXT(aptr) \
	((struct nlattr *)((void *)aptr + \
			NLA_ALIGN(((struct nlattr *)aptr)->nla_len)))
#define GENL_CMP(name1, name2)  strncmp(name1, name2, GENL_NAMSIZ)
#define GENL_COPY(name1, name2) strncpy(name1, name2, GENL_NAMSIZ)
#define GENL_CHK(name)          (strlen(name) > (GENL_NAMSIZ - 1))
#define MSG_TYPE(nptr)          NL_ATTR_FIRST(nptr)->nla_type
#define MSG_PAYLOAD(nptr)       NL_ATTR_VAL(NL_ATTR_FIRST(nptr), void)

/****************************************************************************\
* Netlink: common kernel/user space inline functions                         *
\****************************************************************************/

static inline void
nl_msg_init(void *buf, __u16 family_id, __u32 sequence, __u8 dst)
{
	struct nlmsghdr    *nlh = (struct nlmsghdr *)buf;
	struct genlmsghdr  *genl = (struct genlmsghdr *)(buf + NLMSG_HDRLEN);

	memset(buf, 0, NLMSG_HDRLEN + GENL_HDRLEN);
	nlh->nlmsg_type = family_id;
	nlh->nlmsg_flags = NLM_F_REQUEST;
	nlh->nlmsg_seq = sequence;
	nlh->nlmsg_len = NLMSG_HDRLEN + GENL_HDRLEN;
	genl->cmd = dst;
}

static inline void
*nl_alloc_attr(void *buf, __u16 type, __u16 len)
{
	struct nlmsghdr  *nlh = (struct nlmsghdr *)buf;
	struct nlattr    *attr = NL_ATTR_LAST(nlh);

	if ((NL_SIZE(buf) + NLMSG_ALIGN(NLA_HDRLEN + len)) > NL_BUF_SIZE)
		return NULL;

	attr->nla_type = type;
	attr->nla_len = NLA_HDRLEN + len;
	nlh->nlmsg_len += NLMSG_ALIGN(attr->nla_len);
	return NL_ATTR_VAL(attr, void);
}

static inline int
nl_add_attr(void *buf, __u16 type, void *ptr, __u16 len)
{
	void  *a_ptr;

	a_ptr = nl_alloc_attr(buf, type, len);
	if (a_ptr == NULL)
		return -1;
	memcpy(a_ptr, ptr, len);
	return 0;
}

/****************************************************************************\
* Netlink: multicast groups enum and name strings                            *
\****************************************************************************/

enum {
	MC_DRIVER,
	MC_FUSION,
	MC_REQUIRED_GROUPS,
};

#define MC_DRIVER_NAME     "driver"
#define MC_FUSION_NAME     "fusion"

#define NL_FAMILY_VERSION  1

#define TF_FAMILY_NAME     "touch_fusion"

/****************************************************************************\
* Netlink: common parameter and message definitions                          *
\****************************************************************************/

enum {
	DR_STATE_BASIC,
	DR_STATE_ACTIVE,
	DR_STATE_SUSPEND,
	DR_STATE_RESUME,
	DR_STATE_FAULT,
};

enum {
	DR_INPUT_FINGER,
	DR_INPUT_STYLUS,
	DR_INPUT_ERASER,
};

enum {
	DR_IRQ_FALLING_EDGE,
	DR_IRQ_RISING_EDGE,
};

enum {
	DR_ADD_MC_GROUP,
	DR_ECHO_REQUEST,
	DR_CHIP_READ,
	DR_CHIP_WRITE,
	DR_CHIP_RESET,
	DR_GET_IRQLINE,
	DR_DELAY,
	DR_CHIP_ACCESS_METHOD,
	DR_CONFIG_IRQ,
	DR_CONFIG_INPUT,
	DR_CONFIG_WATCHDOG,
	DR_DECONFIG,
	DR_INPUT,
	DR_RESUME_ACK,
	DR_LEGACY_FWDL,
	DR_LEGACY_ACCELERATION,
};

struct __attribute__ ((__packed__)) dr_add_mc_group {
	__u8  number;
	char  name[GENL_NAMSIZ];
};

struct __attribute__ ((__packed__)) dr_echo_request {
	__u32  cookie;
};

struct __attribute__ ((__packed__)) dr_chip_read {
	__u16  address;
	__u16  length;
};

struct __attribute__ ((__packed__)) dr_chip_write {
	__u16  address;
	__u16  length;
	__u8   data[0];
};

struct __attribute__ ((__packed__)) dr_chip_reset {
	__u8  state;
};

struct __attribute__ ((__packed__)) dr_delay {
	__u32  period;
};

struct __attribute__ ((__packed__)) dr_chip_access_method {
	__u8  method;
};

#define MAX_IRQ_PARAMS  26
struct __attribute__ ((__packed__)) dr_config_irq {
	__u16  irq_param[MAX_IRQ_PARAMS];
	__u8   irq_params;
	__u8   irq_method;
	__u8   irq_edge;
};

struct __attribute__ ((__packed__)) dr_config_input {
	__u16  x_range;
	__u16  y_range;
};

struct __attribute__ ((__packed__)) dr_config_watchdog {
	__u32  pid;
};

struct __attribute__ ((__packed__)) dr_input_event {
	__u8   id;
	__u8   tool_type;
	__u16  x;
	__u16  y;
	__u8   z;
};

#define MAX_INPUT_EVENTS  10
struct __attribute__ ((__packed__)) dr_input {
	struct dr_input_event  event[MAX_INPUT_EVENTS];
	__u8                   events;
};

struct __attribute__ ((__packed__)) dr_legacy_acceleration {
	__u8  enable;
};

enum {
	FU_ECHO_RESPONSE,
	FU_CHIP_READ_RESULT,
	FU_IRQLINE_STATUS,
	FU_ASYNC_DATA,
	FU_RESUME,
};

struct __attribute__ ((__packed__)) fu_echo_response {
	__u32  cookie;
	__u8   driver_state;
};

struct __attribute__ ((__packed__)) fu_chip_read_result {
	__u16  address;
	__u16  length;
	__u8   data[0];
};

struct __attribute__ ((__packed__)) fu_irqline_status {
	__u8  status;
};

struct __attribute__ ((__packed__)) fu_async_data {
	__u16  address;
	__u16  length;
	__u16  status;
	__u8   data[0];
};

#ifdef __KERNEL__
/****************************************************************************\
* Kernel platform data structure                                             *
\****************************************************************************/

#define MAXIM_STI_NAME  "maxim_sti"

struct maxim_sti_pdata {
	char      *touch_fusion;
	char      *config_file;
	char      *fw_name;
	char      *nl_family;
	u8        nl_mc_groups;
	u8        chip_access_method;
	u8        default_reset_state;
	u16       tx_buf_size;
	u16       rx_buf_size;
	unsigned  gpio_reset;
	unsigned  gpio_irq;
	int       (*init)(struct maxim_sti_pdata *pdata, bool init);
	void      (*reset)(struct maxim_sti_pdata *pdata, int value);
	int       (*irq)(struct maxim_sti_pdata *pdata);
};
#endif

#endif