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
|
/*
* Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
*/
/*
* The code contained herein is licensed under the GNU Lesser General
* Public License. You may obtain a copy of the GNU Lesser General
* Public License Version 2.1 or later at the following locations:
*
* http://www.opensource.org/licenses/lgpl-license.html
* http://www.gnu.org/copyleft/lgpl.html
*/
#ifndef __ASM_ARCH_IMX_ADC_H__
#define __ASM_ARCH_IMX_ADC_H__
/*!
* @defgroup IMX_ADC Digitizer Driver
* @ingroup IMX_DRVRS
*/
/*!
* @file arch-mxc/imx_adc.h
* @brief This is the header of IMX ADC driver.
*
* @ingroup IMX_ADC
*/
#include <linux/ioctl.h>
/*!
* @enum IMX_ADC_STATUS
* @brief Define return values for all IMX_ADC APIs.
*
* These return values are used by all of the IMX_ADC APIs.
*
* @ingroup IMX_ADC
*/
enum IMX_ADC_STATUS {
/*! The requested operation was successfully completed. */
IMX_ADC_SUCCESS = 0,
/*! The requested operation could not be completed due to an error. */
IMX_ADC_ERROR = -1,
/*!
* The requested operation failed because one or more of the
* parameters was invalid.
*/
IMX_ADC_PARAMETER_ERROR = -2,
/*!
* The requested operation could not be completed because the ADC
* hardware does not support it.
*/
IMX_ADC_NOT_SUPPORTED = -3,
/*! Error in malloc function */
IMX_ADC_MALLOC_ERROR = -5,
/*! Error in un-subscribe event */
IMX_ADC_UNSUBSCRIBE_ERROR = -6,
/*! Event occur and not subscribed */
IMX_ADC_EVENT_NOT_SUBSCRIBED = -7,
/*! Error - bad call back */
IMX_ADC_EVENT_CALL_BACK = -8,
/*!
* The requested operation could not be completed because there
* are too many ADC client requests
*/
IMX_ADC_CLIENT_NBOVERFLOW = -9,
};
/*
* Macros implementing error handling
*/
#define CHECK_ERROR(a) \
do { \
int ret = (a); \
if (ret != IMX_ADC_SUCCESS) \
return ret; \
} while (0)
#define CHECK_ERROR_KFREE(func, freeptrs) \
do { \
int ret = (func); \
if (ret != IMX_ADC_SUCCESS) { \
freeptrs; \
return ret; \
} \
} while (0)
#define MOD_NAME "mxcadc"
/*!
* @name IOCTL user space interface
*/
/*!
* Initialize ADC.
* Argument type: none.
*/
#define IMX_ADC_INIT _IO('p', 0xb0)
/*!
* De-initialize ADC.
* Argument type: none.
*/
#define IMX_ADC_DEINIT _IO('p', 0xb1)
/*!
* Convert one channel.
* Argument type: pointer to t_adc_convert_param.
*/
#define IMX_ADC_CONVERT _IOWR('p', 0xb2, int)
/*!
* Convert multiple channels.
* Argument type: pointer to t_adc_convert_param.
*/
#define IMX_ADC_CONVERT_MULTICHANNEL _IOWR('p', 0xb4, int)
/*! @{ */
/*!
* @name Touch Screen minimum and maximum values
*/
#define IMX_ADC_DEVICE "/dev/imx_adc"
/*
* Maximun allowed variation in the three X/Y co-ordinates acquired from
* touch screen
*/
#define DELTA_Y_MAX 100
#define DELTA_X_MAX 100
/* Upon clearing the filter, this is the delay in restarting the filter */
#define FILTER_MIN_DELAY 4
/* Length of X and Y touch screen filters */
#define FILTLEN 3
#define TS_X_MAX 1000
#define TS_Y_MAX 1000
#define TS_X_MIN 80
#define TS_Y_MIN 80
/*! @} */
/*!
* This enumeration defines input channels for IMX ADC
*/
enum t_channel {
TS_X_POS,
TS_Y_POS,
GER_PURPOSE_ADC0,
GER_PURPOSE_ADC1,
GER_PURPOSE_ADC2,
GER_PURPOSE_MULTICHNNEL,
};
/*!
* This structure is used to report touch screen value.
*/
struct t_touch_screen {
/* Touch Screen X position */
unsigned int x_position;
/* Touch Screen X position1 */
unsigned int x_position1;
/* Touch Screen X position2 */
unsigned int x_position2;
/* Touch Screen X position3 */
unsigned int x_position3;
/* Touch Screen Y position */
unsigned int y_position;
/* Touch Screen Y position1 */
unsigned int y_position1;
/* Touch Screen Y position2 */
unsigned int y_position2;
/* Touch Screen Y position3 */
unsigned int y_position3;
/* Touch Screen contact value */
unsigned int contact_resistance;
/* Flag indicate the data usability */
unsigned int valid_flag;
};
/*!
* This structure is used with IOCTL code \a IMX_ADC_CONVERT,
* \a IMX_ADC_CONVERT_8X and \a IMX_ADC_CONVERT_MULTICHANNEL.
*/
struct t_adc_convert_param {
/* channel or channels to be sampled. */
enum t_channel channel;
/* holds up to 16 sampling results */
unsigned short result[16];
};
/* EXPORTED FUNCTIONS */
#ifdef __KERNEL__
/* Driver data */
struct imx_adc_data {
u32 irq;
struct clk *adc_clk;
};
/*!
* This function initializes all ADC registers with default values. This
* function also registers the interrupt events.
*
* @return This function returns IMX_ADC_SUCCESS if successful.
*/
enum IMX_ADC_STATUS imx_adc_init(void);
/*!
* This function disables the ADC, de-registers the interrupt events.
*
* @return This function returns IMX_ADC_SUCCESS if successful.
*/
enum IMX_ADC_STATUS imx_adc_deinit(void);
/*!
* This function triggers a conversion and returns one sampling result of one
* channel.
*
* @param channel The channel to be sampled
* @param result The pointer to the conversion result. The memory
* should be allocated by the caller of this function.
*
* @return This function returns IMX_ADC_SUCCESS if successful.
*/
enum IMX_ADC_STATUS imx_adc_convert(enum t_channel channel,
unsigned short *result);
/*!
* This function triggers a conversion and returns sampling results of each
* specified channel.
*
* @param channels This input parameter is bitmap to specify channels
* to be sampled.
* @param result The pointer to array to store sampling result.
* The order of the result in the array is from lowest
* channel number to highest channel number of the
* sampled channels.
* The memory should be allocated by the caller of this
* function.
* Note that the behavior of this function might differ
* from one platform to another regarding especially
* channels order.
*
* @return This function returns IMX_ADC_SUCCESS if successful.
*/
enum IMX_ADC_STATUS imx_adc_convert_multichnnel(enum t_channel channels,
unsigned short *result);
/*!
* This function retrieves the current touch screen operation mode.
*
* @param touch_sample Pointer to touch sample.
* @param wait_tsi if true, we wait until interrupt occurs
* @return This function returns IMX_ADC_SUCCESS if successful.
*/
enum IMX_ADC_STATUS imx_adc_get_touch_sample(struct t_touch_screen *ts_value,
int wait_tsi);
/*!
* This function read the touch screen value.
*
* @param touch_sample return value of touch screen
* @param wait_tsi if true, we need wait until interrupt occurs
* @return This function returns 0.
*/
enum IMX_ADC_STATUS imx_adc_read_ts(struct t_touch_screen *touch_sample,
int wait_tsi);
int is_imx_adc_ready(void);
#endif /* _KERNEL */
#endif /* __ASM_ARCH_IMX_ADC_H__ */
|