summaryrefslogtreecommitdiff
path: root/syna_tcm2_platform.h
blob: d6d5a68b98fee67092c9084e0bfd0d2e002385ea (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
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
/* SPDX-License-Identifier: GPL-2.0
 *
 * Synaptics TouchCom touchscreen driver
 *
 * Copyright (C) 2017-2020 Synaptics Incorporated. 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 as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * 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.
 *
 * INFORMATION CONTAINED IN THIS DOCUMENT IS PROVIDED "AS-IS," AND SYNAPTICS
 * EXPRESSLY DISCLAIMS ALL EXPRESS AND IMPLIED WARRANTIES, INCLUDING ANY
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
 * AND ANY WARRANTIES OF NON-INFRINGEMENT OF ANY INTELLECTUAL PROPERTY RIGHTS.
 * IN NO EVENT SHALL SYNAPTICS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, PUNITIVE, OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR IN CONNECTION
 * WITH THE USE OF THE INFORMATION CONTAINED IN THIS DOCUMENT, HOWEVER CAUSED
 * AND BASED ON ANY THEORY OF LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * NEGLIGENCE OR OTHER TORTIOUS ACTION, AND EVEN IF SYNAPTICS WAS ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE. IF A TRIBUNAL OF COMPETENT JURISDICTION DOES
 * NOT PERMIT THE DISCLAIMER OF DIRECT DAMAGES OR ANY OTHER DAMAGES, SYNAPTICS'
 * TOTAL CUMULATIVE LIABILITY TO ANY PARTY SHALL NOT EXCEED ONE HUNDRED U.S.
 * DOLLARS.
 */

/**
 * @file: syna_tcm2_platform.h
 *
 * This file declares the platform-specific or hardware relevant data.
 *
 * The main structure, syna_hw_interface, abstracts the bus transferred,
 * ATTN signal, RST_N pin, and power control operations.
 */

#ifndef _SYNAPTICS_TCM2_PLATFORM_H_
#define _SYNAPTICS_TCM2_PLATFORM_H_

#include "syna_tcm2_runtime.h"

/**
 * @section: The capability of bus transferred
 *
 * Declare read/write capability in bytes (0 = unlimited)
 */
#define RD_CHUNK_SIZE (512)
#define WR_CHUNK_SIZE (512)


/**
 * @section: Defined Hardware-Specific Data
 *
 * @brief: syna_hw_bus_data
 *         Hardware Data for bus transferred
 *
 * @brief: syna_hw_attn_data
 *         Hardware Data for ATTN signal
 *
 * @brief: syna_hw_rst_data
 *         Hardware Data for RST_N pin
 *
 * @brief: syna_hw_pwr_data
 *         Hardware Data for power control
 *
 * @brief: syna_hw_interface
 *         Contain all above hardware data and abstract the
 *         hardware operations
 */

/* The hardware data especially for bus transferred */
struct syna_hw_bus_data {
	unsigned char type;
	/* capability of i/o chunk */
	unsigned int rd_chunk_size;
	unsigned int wr_chunk_size;
	/* clock frequency in hz */
	unsigned int frequency_hz;
	/* parameters for i2c */
	unsigned int i2c_addr;
	/* parameters for spi */
	unsigned int spi_mode;
	unsigned int spi_byte_delay_us;
	unsigned int spi_block_delay_us;
	/* mutex to protect the i/o, if needed */
	syna_pal_mutex_t io_mutex;
};

/* The hardware data especially for ATTN signal */
struct syna_hw_attn_data {
	/* parameters */
	int irq_gpio;
	int irq_on_state;
	unsigned long irq_flags;
	int irq_id;
	bool irq_enabled;
	/* mutex to protect the irq control, if needed */
	syna_pal_mutex_t irq_en_mutex;
};

/* The hardware data especially for RST_N pin */
struct syna_hw_rst_data {
	/* parameters */
	int reset_gpio;
	int reset_on_state;
	unsigned int reset_delay_ms;
	unsigned int reset_active_ms;
};

/* The hardware data especially for power control */
struct syna_hw_pwr_data {
	/* parameters */
	int vdd_gpio;
	int avdd_gpio;
	int power_on_state;
	unsigned int power_on_delay_ms;
	/* voltage */
	unsigned int vdd;
	unsigned int vled;
	unsigned int vio;
	unsigned int vddtx;
	/* regulators */
	const char *vdd_reg_name;
	void *vdd_reg_dev;
	const char *avdd_reg_name;
	void *avdd_reg_dev;
};

/**
 * @section: Hardware Interface Abstraction Layer
 *
 * The structure contains the hardware-specific implementations
 * on the target platform.
 */
struct syna_hw_interface {
	/* The handle of hardware device */
	void *pdev;

	/* Hardware specific data */
	struct syna_hw_bus_data bdata_io;
	struct syna_hw_attn_data bdata_attn;
	struct syna_hw_rst_data bdata_rst;
	struct syna_hw_pwr_data bdata_pwr;
	const char *fw_name;

	/* Operation to do power on/off, if supported
	 *
	 * This is an optional operation.
	 *
	 * Implementation should request that the power device be
	 * enabled with the output at the proper voltage.
	 *
	 * Assign the pointer NULL if power supply module is not controllable.
	 *
	 * @param
	 *    [ in] hw_if: the handle of hw interface
	 *    [ in] en:    '1' for powering on, and '0' for powering off
	 *
	 * @return
	 *    0 on success; otherwise, on error.
	 */
	int (*ops_power_on)(struct syna_hw_interface *hw_if,
			bool en);

	/* Operation to perform the hardware reset, if supported
	 *
	 * This is an optional operation.
	 *
	 * The actual reset waveform should be reference to the device spec.
	 *
	 * Assign the pointer NULL if RST_N pin is not controllable.
	 *
	 * @param
	 *    [ in] hw_if: the handle of hw interface
	 *
	 * @return
	 *    0 on success; otherwise, on error.
	 */
	void (*ops_hw_reset)(struct syna_hw_interface *hw_if);

	/* Operation to set up the bus connection
	 *
	 * This is an optional operation to add in the extra configuration
	 * before doing connection.
	 *
	 * Assign the pointer NULL if this operation is not required.
	 *
	 * @param
	 *    [ in] hw_if:   the handle of hw interface
	 *    [ in] config:  parameters to change
	 *
	 * @return
	 *    0 or positive value on success; otherwise, on error.
	 */
	int (*ops_bus_setup)(struct syna_hw_interface *hw_if,
			struct syna_hw_bus_data *config);

	/* Operation to read the bare data from bus
	 *
	 * This is an essential operation; otherwise, the communication
	 * will not be created.
	 *
	 * @param
	 *    [ in] hw_if:   the handle of hw interface
	 *    [out] rd_data: buffer for storing data retrieved
	 *    [ in] rd_len:  length of reading data in bytes
	 *
	 * @return
	 *    0 or positive value on success; otherwise, on error.
	 */
	int (*ops_read_data)(struct syna_hw_interface *hw_if,
			unsigned char *rd_data, unsigned int rd_len);

	/* Operation to write the bare data to bus
	 *
	 * This is an essential operation; otherwise, the communication
	 * will not be created.
	 *
	 * @param
	 *    [ in] hw_if:   the handle of hw interface
	 *    [ in] wr_data: written data
	 *    [ in] wr_len:  length of written data in bytes
	 *
	 * @return
	 *    0 or positive value on success; otherwise, on error.
	 */
	int (*ops_write_data)(struct syna_hw_interface *hw_if,
			unsigned char *wr_data, unsigned int wr_len);

	/* Operation to enable/disable the irq, if supported
	 *
	 * This is an optional operation. Providing this operation could
	 * minimize the frequency of ISR being called.
	 *
	 * Once disabled, ISR will not be invoked even ATTN is asserted.
	 *
	 * Assign the pointer NULL if irq is not controllable.
	 *
	 * @param
	 *    [ in] hw_if: the handle of hw interface
	 *    [ in] en:    '1' for enabling, and '0' for disabling
	 *
	 * @return
	 *    0 on success; otherwise, on error.
	 */
	int (*ops_enable_irq)(struct syna_hw_interface *hw_if,
			bool en);

	/* Operation to wait for the signal of interrupt, if supported
	 *
	 * This is an optional operation to help for creating the
	 * custom interrupt handler. Besides, the recommendation is to
	 * implement in one-shot approach if possible.
	 *
	 * Implementation should return control if ATTN is asserted or
	 * specified timeout expire. If timeout is 0, should check the
	 * state of the ATTN signal and return control immediately.
	 *
	 * Assign the pointer NULL if customized ISR is not required.
	 *
	 * @param
	 *    [ in] hw_if:      the handle of hw interface
	 *    [ in] timeout_ms: time frame in milliseconds
	 *
	 * @return
	 *    0 on success; otherwise, on error.
	 */
	int (*ops_wait_irq)(struct syna_hw_interface *hw_if,
			unsigned int timeout_ms);

};
/* end of structure syna_hw_interface */


/**
 * syna_hw_interface_init()
 *
 * Initialize the lower-level hardware interface module.
 * After returning, the handle of hw interface should be ready.
 *
 * @param
 *    void
 *
 * @return
 *    on success, 0; otherwise, negative value on error.
 */
int syna_hw_interface_init(void);

/**
 * syna_hw_interface_exit()
 *
 * Delete the lower-level hardware interface module.
 *
 * @param
 *    void
 *
 * @return
 *    none.
 */
void syna_hw_interface_exit(void);


#endif /* end of _SYNAPTICS_TCM2_PLATFORM_H_ */