ad7146.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /**
  2. \file ad7146.h
  3. This is the Header file for AD7146_Driver.
  4. The file can be found at <KERNEL>/include/linux/input
  5. */
  6. /*
  7. * include/linux/input/ad7146.h
  8. *
  9. * The platform_data for the device's "struct device" holds this
  10. * information.
  11. *
  12. * Copyright 2013 Analog Devices Inc.
  13. *
  14. * Licensed under the GPL version 3 or later.
  15. */
  16. #ifndef __LINUX_INPUT_AD714X_H__
  17. #define __LINUX_INPUT_AD714X_H__
  18. /**
  19. Total number of register count used in the initialization.
  20. \note
  21. This should be kept exactly as the register count in the
  22. initialization of the platform device structure ad7146_platform_data.
  23. */
  24. #define REGCNT 18
  25. /**
  26. Total number of register count used in the Normal mode transistion.
  27. \note
  28. This should be kept exactly as the register count in the "normal_regs"
  29. of the platform device structure ad7146_platform_data.
  30. */
  31. #define NORMAL_REGCNT 2
  32. /**
  33. Platform data structure of AD7146_MLD driver.
  34. */
  35. struct ad7146_platform_data {
  36. /**
  37. This hold the Initial Register Configurations of AD7146
  38. */
  39. unsigned int regs[REGCNT];
  40. /**
  41. This hold the Normal Mode Register Configurations of AD7146
  42. */
  43. unsigned int normal_regs[NORMAL_REGCNT];
  44. /**
  45. This holds the Full Grip threshold value for POWER_ON_GRIP
  46. */
  47. unsigned short fixed_th_full;
  48. unsigned short cal_offset;
  49. unsigned short cal_fixed_th_full;
  50. void (*power_en)(int);
  51. };
  52. /**
  53. READ function for AD7146
  54. */
  55. typedef int (*ad7146_read_t)(struct device *, unsigned short, unsigned short *);
  56. /**
  57. WRITE function for AD7146
  58. */
  59. typedef int (*ad7146_write_t)(struct device *, unsigned short, unsigned short);
  60. /**
  61. Event value for No Grip State
  62. */
  63. #define EVENT_NO_GRIP (5)
  64. /**
  65. Event value for Full Grip State
  66. */
  67. #define EVENT_FULL_GRIP (0)
  68. /**
  69. Minimum OFFSET for POWER_ON grip Detection
  70. */
  71. #define PW_ON_OFFSET_MIN (0x200) /* 512 codes */
  72. /**
  73. Hysteresis Percentage Reduction
  74. */
  75. #define HYS_PERCENT (20)
  76. #if (HYS_PERCENT > 99)
  77. #error "Hysteris percentage invalid"
  78. #endif
  79. /**
  80. Hysteresis Compensation Macro
  81. */
  82. #define HYS(S, T) ((T) - ((((T)-(S)) * HYS_PERCENT)/100))
  83. /**
  84. Positive Hysteresis Compensation Macro
  85. */
  86. #define HYS_POS(S, T) ((T) + ((((T)-(S)) * HYS_PERCENT) \
  87. / (100 - HYS_PERCENT)))
  88. /**
  89. Sleep time required to go to Low Power mode in milliseconds
  90. */
  91. #define SLEEP_TIME_TO_LOW_POWER (200)
  92. /**
  93. Sleep time for forced calibration during init in milliseconds
  94. */
  95. #define SLEEP_TIME_TO_CALI_INIT (100)
  96. /**
  97. Sleep time for forced calibration during INT in milliseconds
  98. */
  99. #define SLEEP_TIME_TO_CALI_INT (20)
  100. /**
  101. Driver State Normal
  102. */
  103. #define DRIVER_STATE_NORMAL (0)
  104. /**
  105. Driver State Full Grip
  106. */
  107. #define DRIVER_STATE_FULL_GRIP (1)
  108. /**
  109. Driver name of this ad7146 driver
  110. */
  111. #define DRIVER_NAME "ad7146_MLD"
  112. /**
  113. This hold the product ID of AD7146
  114. */
  115. #define AD7146_PRODUCT_ID 0x7146
  116. /**
  117. \def AD7146_PARTID_REG
  118. Device ID Register Address
  119. */
  120. #define AD7146_PARTID_REG (0x17)
  121. /**
  122. \def AD7146_PARTID
  123. Device ID for AD7146 chip
  124. */
  125. #define AD7146_PARTID (0x1490)
  126. /**
  127. Clear Interrupt Enable Register
  128. */
  129. #define DISABLE_INT (0x0)
  130. /**
  131. Enable Stage 0
  132. */
  133. #define ENABLE_STG0 (0x01)
  134. /**
  135. \def AD7146_PWR_CTRL
  136. Power control Register
  137. */
  138. #define AD7146_PWR_CTRL (0x0)
  139. /**
  140. \def AD7146_STG_CAL_EN_REG
  141. Calibration and Control Register
  142. */
  143. #define AD7146_STG_CAL_EN_REG (0x1)
  144. /**
  145. \def AD7146_AMB_COMP_CTRL0_REG
  146. Device Control Register 0
  147. */
  148. #define AD7146_AMB_COMP_CTRL0_REG (0x2)
  149. /**
  150. \def STG_LOW_INT_EN_REG
  151. Lower Threshold Interrupt Enable register
  152. */
  153. #define STG_LOW_INT_EN_REG (0x5)
  154. /**
  155. \def STG_HIGH_INT_EN_REG
  156. Higher Threshold Interrupt Enable register
  157. */
  158. #define STG_HIGH_INT_EN_REG (0x6)
  159. /**
  160. \def STG_COM_INT_EN_REG
  161. Conversion complete Interrupt Enable register
  162. */
  163. #define STG_COM_INT_EN_REG (0x7)
  164. /**
  165. \def STG_LOW_INT_STA_REG
  166. Lower Threshold Interrupt Status register
  167. */
  168. #define STG_LOW_INT_STA_REG (0x8)
  169. /**
  170. \def STG_HIGH_INT_STA_REG
  171. Higher Threshold Interrupt Status register
  172. */
  173. #define STG_HIGH_INT_STA_REG (0x9)
  174. /**
  175. \def CDC_RESULT_S0_REG
  176. CDC Result of Stage 0 Register
  177. */
  178. #define CDC_RESULT_S0_REG (0xB)
  179. /**
  180. Register address of Stage 0 Sensitivity
  181. */
  182. #define DRIVER_STG0_AFEOFFSET (0x82)
  183. /**
  184. Register address of Stage 0 Sensitivity
  185. */
  186. #define DRIVER_STG0_SENSITIVITY (0x83)
  187. /**
  188. Register address of Stage 0 LOW OFFSET
  189. */
  190. #define LOW_OFFSET_0_REG (0x84)
  191. /**
  192. Register address of Stage 0 HIGH OFFSET
  193. */
  194. #define HIGH_OFFSET_0_REG (0x85)
  195. /**
  196. Register address of Stage 0 HIGH CLAMP
  197. */
  198. #define HIGH_OFFSET_CLAMP_0_REG (0x86)
  199. /**
  200. Register address of Stage 0 LOW CLAMP
  201. */
  202. #define LOW_OFFSET_CLAMP_0_REG (0x87)
  203. /**
  204. \def DRIVER_STG0_SF_AMBIENT
  205. Register address of Stage 0 sf ambient value
  206. */
  207. #define DRIVER_STG0_SF_AMBIENT (0xF1)
  208. /**
  209. \def DRIVER_STG0_HIGH_THRESHOLD
  210. Register address of Stage 0 High Threshold value
  211. */
  212. #define DRIVER_STG0_HIGH_THRESHOLD (0xFA)
  213. /**
  214. Stage 0 Low threshold Register
  215. */
  216. #define STG_0_LOW_THRESHOLD (0x101)
  217. /**
  218. Mask For the Force calibration
  219. */
  220. #define AD7146_FORCED_CAL_MASK (1<<14)
  221. /**
  222. Negative Sensitivity Mask
  223. */
  224. #define NEG_SENS (0xF)
  225. /**
  226. Positive Sensitivity Mask
  227. */
  228. #define POS_SENS (0xF00)
  229. /**
  230. Used For the Disable of the interrupts
  231. */
  232. #define DISABLE_INTERRUPTS (0x0)
  233. /**
  234. Used For the Enable of interrupts
  235. */
  236. #define ENABLE_INTERRUPTS (0x1)
  237. /**
  238. AD7146 Full Scale value
  239. */
  240. #define FULL_SCALE_VALUE (0xFFFF)
  241. /**
  242. AD7146 Full Scale value
  243. */
  244. #define OVER_FLOW_SCALE_VALUE (0x0005)
  245. enum bank2_register_type {
  246. STAGE_CONNECTION_1,
  247. STAGE_CONNECTION_2,
  248. STAGE_AFE_OFFSET,
  249. STAGE_SENSITIVITY,
  250. STAGE_OFFSET_LOW,
  251. STAGE_OFFSET_HIGH,
  252. STAGE_OFFSET_HIGH_CLAMP,
  253. STAGE_OFFSET_LOW_CLAMP
  254. };
  255. /**
  256. * This structure provides chip information of AD7146.
  257. * \note Contains chip information of the AD7146 chip with attributes
  258. * like Product, Status ,version,drive data etc.
  259. * which are used in the control or to read the status of the device
  260. */
  261. struct ad7146_chip {
  262. unsigned short high_status;
  263. unsigned short low_status;
  264. struct ad7146_platform_data *hw;
  265. struct input_dev *input;
  266. struct device *grip_dev;
  267. int irq;
  268. int grip_int;
  269. struct work_struct work;
  270. struct device *dev;
  271. struct wake_lock grip_wake_lock;
  272. ad7146_read_t read;
  273. ad7146_write_t write;
  274. /**
  275. power on grip status
  276. 0 - Normal Mode
  277. 1 - Half Grip Mode
  278. 2 - Full Grip Mode
  279. */
  280. unsigned short pw_on_grip_status;
  281. /*State check variables */
  282. unsigned short prevhigh;
  283. short prev_state_value;
  284. short state_value;
  285. /**
  286. event check to send or block the event in the driver
  287. 0 - Disabled(Do not send event)
  288. 1 - Enabled(Send event)
  289. */
  290. unsigned short eventcheck;
  291. unsigned short during_cal_data;
  292. char onoff_flags;
  293. char cal_flags;
  294. char during_cal_flags;
  295. unsigned short stg0_low_offset;
  296. unsigned product;
  297. unsigned version;
  298. };
  299. #endif