Lily Zhang | 824e4de | 2009-11-01 11:14:53 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2009-2011 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 | |
| 17 | /*! |
| 18 | * @defgroup IMX_ADC Digitizer Driver |
| 19 | * @ingroup IMX_DRVRS |
| 20 | */ |
| 21 | |
| 22 | /*! |
| 23 | * @file arch-mxc/imx_adc.h |
| 24 | * @brief This is the header of IMX ADC driver. |
| 25 | * |
| 26 | * @ingroup IMX_ADC |
| 27 | */ |
| 28 | |
| 29 | #include <linux/ioctl.h> |
| 30 | |
| 31 | /*! |
| 32 | * @enum IMX_ADC_STATUS |
| 33 | * @brief Define return values for all IMX_ADC APIs. |
| 34 | * |
| 35 | * These return values are used by all of the IMX_ADC APIs. |
| 36 | * |
| 37 | * @ingroup IMX_ADC |
| 38 | */ |
| 39 | enum IMX_ADC_STATUS { |
| 40 | /*! The requested operation was successfully completed. */ |
| 41 | IMX_ADC_SUCCESS = 0, |
| 42 | /*! The requested operation could not be completed due to an error. */ |
| 43 | IMX_ADC_ERROR = -1, |
| 44 | /*! |
| 45 | * The requested operation failed because one or more of the |
| 46 | * parameters was invalid. |
| 47 | */ |
| 48 | IMX_ADC_PARAMETER_ERROR = -2, |
| 49 | /*! |
| 50 | * The requested operation could not be completed because the ADC |
| 51 | * hardware does not support it. |
| 52 | */ |
| 53 | IMX_ADC_NOT_SUPPORTED = -3, |
| 54 | /*! Error in malloc function */ |
| 55 | IMX_ADC_MALLOC_ERROR = -5, |
| 56 | /*! Error in un-subscribe event */ |
| 57 | IMX_ADC_UNSUBSCRIBE_ERROR = -6, |
| 58 | /*! Event occur and not subscribed */ |
| 59 | IMX_ADC_EVENT_NOT_SUBSCRIBED = -7, |
| 60 | /*! Error - bad call back */ |
| 61 | IMX_ADC_EVENT_CALL_BACK = -8, |
| 62 | /*! |
| 63 | * The requested operation could not be completed because there |
| 64 | * are too many ADC client requests |
| 65 | */ |
| 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 | |
| 90 | /*! |
| 91 | * @name IOCTL user space interface |
| 92 | */ |
| 93 | |
| 94 | /*! |
| 95 | * Initialize ADC. |
| 96 | * Argument type: none. |
| 97 | */ |
| 98 | #define IMX_ADC_INIT _IO('p', 0xb0) |
| 99 | /*! |
| 100 | * De-initialize ADC. |
| 101 | * Argument type: none. |
| 102 | */ |
| 103 | #define IMX_ADC_DEINIT _IO('p', 0xb1) |
| 104 | /*! |
| 105 | * Convert one channel. |
| 106 | * Argument type: pointer to t_adc_convert_param. |
| 107 | */ |
| 108 | #define IMX_ADC_CONVERT _IOWR('p', 0xb2, int) |
| 109 | /*! |
| 110 | * Convert multiple channels. |
| 111 | * Argument type: pointer to t_adc_convert_param. |
| 112 | */ |
| 113 | #define IMX_ADC_CONVERT_MULTICHANNEL _IOWR('p', 0xb4, int) |
| 114 | |
| 115 | /*! @{ */ |
| 116 | /*! |
| 117 | * @name Touch Screen minimum and maximum values |
| 118 | */ |
| 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 | |
| 140 | /*! @} */ |
| 141 | /*! |
| 142 | * This enumeration defines input channels for IMX ADC |
| 143 | */ |
| 144 | |
| 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 | |
| 154 | /*! |
| 155 | * This structure is used to report touch screen value. |
| 156 | */ |
| 157 | struct t_touch_screen { |
| 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 | |
| 180 | /*! |
| 181 | * This structure is used with IOCTL code \a IMX_ADC_CONVERT, |
| 182 | * \a IMX_ADC_CONVERT_8X and \a IMX_ADC_CONVERT_MULTICHANNEL. |
| 183 | */ |
| 184 | |
| 185 | struct t_adc_convert_param { |
| 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 | |
| 201 | /*! |
| 202 | * This function initializes all ADC registers with default values. This |
| 203 | * function also registers the interrupt events. |
| 204 | * |
| 205 | * @return This function returns IMX_ADC_SUCCESS if successful. |
| 206 | */ |
| 207 | enum IMX_ADC_STATUS imx_adc_init(void); |
| 208 | |
| 209 | /*! |
| 210 | * This function disables the ADC, de-registers the interrupt events. |
| 211 | * |
| 212 | * @return This function returns IMX_ADC_SUCCESS if successful. |
| 213 | */ |
| 214 | enum IMX_ADC_STATUS imx_adc_deinit(void); |
| 215 | |
| 216 | /*! |
| 217 | * This function triggers a conversion and returns one sampling result of one |
| 218 | * channel. |
| 219 | * |
| 220 | * @param channel The channel to be sampled |
| 221 | * @param result The pointer to the conversion result. The memory |
| 222 | * should be allocated by the caller of this function. |
| 223 | * |
| 224 | * @return This function returns IMX_ADC_SUCCESS if successful. |
| 225 | */ |
| 226 | |
| 227 | enum IMX_ADC_STATUS imx_adc_convert(enum t_channel channel, |
| 228 | unsigned short *result); |
| 229 | |
| 230 | /*! |
| 231 | * This function triggers a conversion and returns sampling results of each |
| 232 | * specified channel. |
| 233 | * |
| 234 | * @param channels This input parameter is bitmap to specify channels |
| 235 | * to be sampled. |
| 236 | * @param result The pointer to array to store sampling result. |
| 237 | * The order of the result in the array is from lowest |
| 238 | * channel number to highest channel number of the |
| 239 | * sampled channels. |
| 240 | * The memory should be allocated by the caller of this |
| 241 | * function. |
| 242 | * Note that the behavior of this function might differ |
| 243 | * from one platform to another regarding especially |
| 244 | * channels order. |
| 245 | * |
| 246 | * @return This function returns IMX_ADC_SUCCESS if successful. |
| 247 | */ |
| 248 | |
| 249 | enum IMX_ADC_STATUS imx_adc_convert_multichnnel(enum t_channel channels, |
| 250 | unsigned short *result); |
| 251 | |
| 252 | /*! |
| 253 | * This function retrieves the current touch screen operation mode. |
| 254 | * |
| 255 | * @param touch_sample Pointer to touch sample. |
| 256 | * @param wait_tsi if true, we wait until interrupt occurs |
| 257 | * @return This function returns IMX_ADC_SUCCESS if successful. |
| 258 | */ |
| 259 | enum IMX_ADC_STATUS imx_adc_get_touch_sample(struct t_touch_screen *ts_value, |
| 260 | int wait_tsi); |
| 261 | |
| 262 | /*! |
| 263 | * This function read the touch screen value. |
| 264 | * |
| 265 | * @param touch_sample return value of touch screen |
| 266 | * @param wait_tsi if true, we need wait until interrupt occurs |
| 267 | * @return This function returns 0. |
| 268 | */ |
| 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__ */ |