DHCOM_HAL
Hardware-abstraction library (HAL) for multiple targets, including DHCOM modules
 All Data Structures Files Functions Enumerations Macros Groups
imx_adc.h
1 /*
2  * Copyright 2009-2010 Freescale Semiconductor, Inc. All Rights Reserved.
3  */
4 
5 /*
6  * The code contained herein is licensed under the GNU Lesser General
7  * Public License. You may obtain a copy of the GNU Lesser General
8  * Public License Version 2.1 or later at the following locations:
9  *
10  * http://www.opensource.org/licenses/lgpl-license.html
11  * http://www.gnu.org/copyleft/lgpl.html
12  */
13 
14 #ifndef __ASM_ARCH_IMX_ADC_H__
15 #define __ASM_ARCH_IMX_ADC_H__
16 
29 #include <linux/ioctl.h>
30 
41  IMX_ADC_SUCCESS = 0,
43  IMX_ADC_ERROR = -1,
48  IMX_ADC_PARAMETER_ERROR = -2,
53  IMX_ADC_NOT_SUPPORTED = -3,
55  IMX_ADC_MALLOC_ERROR = -5,
57  IMX_ADC_UNSUBSCRIBE_ERROR = -6,
59  IMX_ADC_EVENT_NOT_SUBSCRIBED = -7,
61  IMX_ADC_EVENT_CALL_BACK = -8,
66  IMX_ADC_CLIENT_NBOVERFLOW = -9,
67 };
68 
69 /*
70  * Macros implementing error handling
71  */
72 #define CHECK_ERROR(a) \
73 do { \
74  int ret = (a); \
75  if (ret != IMX_ADC_SUCCESS) \
76  return ret; \
77 } while (0)
78 
79 #define CHECK_ERROR_KFREE(func, freeptrs) \
80 do { \
81  int ret = (func); \
82  if (ret != IMX_ADC_SUCCESS) { \
83  freeptrs; \
84  return ret; \
85  } \
86 } while (0)
87 
88 #define MOD_NAME "mxcadc"
89 
98 #define IMX_ADC_INIT _IO('p', 0xb0)
99 
103 #define IMX_ADC_DEINIT _IO('p', 0xb1)
104 
108 #define IMX_ADC_CONVERT _IOWR('p', 0xb2, int)
109 
113 #define IMX_ADC_CONVERT_MULTICHANNEL _IOWR('p', 0xb4, int)
114 
119 #define IMX_ADC_DEVICE "/dev/imx_adc"
120 
121 /*
122  * Maximun allowed variation in the three X/Y co-ordinates acquired from
123  * touch screen
124  */
125 #define DELTA_Y_MAX 100
126 #define DELTA_X_MAX 100
127 
128 /* Upon clearing the filter, this is the delay in restarting the filter */
129 #define FILTER_MIN_DELAY 4
130 
131 /* Length of X and Y touch screen filters */
132 #define FILTLEN 3
133 
134 #define TS_X_MAX 1000
135 #define TS_Y_MAX 1000
136 
137 #define TS_X_MIN 80
138 #define TS_Y_MIN 80
139 
145 enum t_channel {
146  TS_X_POS,
147  TS_Y_POS,
148  GER_PURPOSE_ADC0,
149  GER_PURPOSE_ADC1,
150  GER_PURPOSE_ADC2,
151  GER_PURPOSE_MULTICHNNEL,
152 };
153 
158  /* Touch Screen X position */
159  unsigned int x_position;
160  /* Touch Screen X position1 */
161  unsigned int x_position1;
162  /* Touch Screen X position2 */
163  unsigned int x_position2;
164  /* Touch Screen X position3 */
165  unsigned int x_position3;
166  /* Touch Screen Y position */
167  unsigned int y_position;
168  /* Touch Screen Y position1 */
169  unsigned int y_position1;
170  /* Touch Screen Y position2 */
171  unsigned int y_position2;
172  /* Touch Screen Y position3 */
173  unsigned int y_position3;
174  /* Touch Screen contact value */
175  unsigned int contact_resistance;
176  /* Flag indicate the data usability */
177  unsigned int valid_flag;
178 };
179 
186  /* channel or channels to be sampled. */
187  enum t_channel channel;
188  /* holds up to 16 sampling results */
189  unsigned short result[16];
190 };
191 
192 /* EXPORTED FUNCTIONS */
193 
194 #ifdef __KERNEL__
195 /* Driver data */
196 struct imx_adc_data {
197  u32 irq;
198  struct clk *adc_clk;
199 };
200 
207 enum IMX_ADC_STATUS imx_adc_init(void);
208 
214 enum IMX_ADC_STATUS imx_adc_deinit(void);
215 
227 enum IMX_ADC_STATUS imx_adc_convert(enum t_channel channel,
228  unsigned short *result);
229 
249 enum IMX_ADC_STATUS imx_adc_convert_multichnnel(enum t_channel channels,
250  unsigned short *result);
251 
259 enum IMX_ADC_STATUS imx_adc_get_touch_sample(struct t_touch_screen *ts_value,
260  int wait_tsi);
261 
269 enum IMX_ADC_STATUS imx_adc_read_ts(struct t_touch_screen *touch_sample,
270  int wait_tsi);
271 
272 int is_imx_adc_ready(void);
273 
274 #endif /* _KERNEL */
275 #endif /* __ASM_ARCH_IMX_ADC_H__ */