sx9310.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. /*
  2. * This program is free software; you can redistribute it and/or
  3. * modify it under the terms of the GNU General Public License
  4. * version 2 as published by the Free Software Foundation.
  5. */
  6. #ifndef SX9310_H
  7. #define SX9310_H
  8. #include <linux/device.h>
  9. #include <linux/slab.h>
  10. #include <linux/interrupt.h>
  11. #include <linux/workqueue.h>
  12. #if 0//def CONFIG_HAS_WAKELOCK
  13. #include <linux/wakelock.h>
  14. #include <linux/earlysuspend.h>
  15. #include <linux/suspend.h>
  16. #endif
  17. /*
  18. * I2C Registers
  19. */
  20. #define SX9310_IRQSTAT_REG 0x00
  21. #define SX9310_STAT0_REG 0x01
  22. #define SX9310_STAT1_REG 0x02
  23. #define SX9310_IRQ_ENABLE_REG 0x03
  24. #define SX9310_IRQFUNC_REG 0x04
  25. #define SX9310_CPS_CTRL0_REG 0x10
  26. #define SX9310_CPS_CTRL1_REG 0x11
  27. #define SX9310_CPS_CTRL2_REG 0x12
  28. #define SX9310_CPS_CTRL3_REG 0x13
  29. #define SX9310_CPS_CTRL4_REG 0x14
  30. #define SX9310_CPS_CTRL5_REG 0x15
  31. #define SX9310_CPS_CTRL6_REG 0x16
  32. #define SX9310_CPS_CTRL7_REG 0x17
  33. #define SX9310_CPS_CTRL8_REG 0x18
  34. #define SX9310_CPS_CTRL9_REG 0x19
  35. #define SX9310_CPS_CTRL10_REG 0x1A
  36. #define SX9310_CPS_CTRL11_REG 0x1B
  37. #define SX9310_CPS_CTRL12_REG 0x1C
  38. #define SX9310_CPS_CTRL13_REG 0x1D
  39. #define SX9310_CPS_CTRL14_REG 0x1E
  40. #define SX9310_CPS_CTRL15_REG 0x1F
  41. #define SX9310_CPS_CTRL16_REG 0x20
  42. #define SX9310_CPS_CTRL17_REG 0x21
  43. #define SX9310_CPS_CTRL18_REG 0x22
  44. #define SX9310_CPS_CTRL19_REG 0x23
  45. #define SX9310_SAR_CTRL0_REG 0x2A
  46. #define SX9310_SAR_CTRL1_REG 0x2B
  47. #define SX9310_SAR_CTRL2_REG 0x2C
  48. #define SX9310_SOFTRESET_REG 0x7F
  49. /* Sensor Readback */
  50. #define SX9310_CPSRD 0x30
  51. #define SX9310_USEMSB 0x31
  52. #define SX9310_USELSB 0x32
  53. #define SX9310_AVGMSB 0x33
  54. #define SX9310_AVGLSB 0x34
  55. #define SX9310_DIFFMSB 0x35
  56. #define SX9310_DIFFLSB 0x36
  57. #define SX9310_OFFSETMSB 0x37
  58. #define SX9310_OFFSETLSB 0x38
  59. #define SX9310_SARMSB 0x39
  60. #define SX9310_SARLSB 0x3A
  61. /* IrqStat 0:Inactive 1:Active */
  62. #define SX9310_IRQSTAT_RESET_FLAG 0x80
  63. #define SX9310_IRQSTAT_TOUCH_FLAG 0x40
  64. #define SX9310_IRQSTAT_RELEASE_FLAG 0x20
  65. #define SX9310_IRQSTAT_COMPDONE_FLAG 0x10
  66. #define SX9310_IRQSTAT_CONV_FLAG 0x08
  67. #define SX9310_IRQSTAT_CLOSEALL_FLAG 0x04
  68. #define SX9310_IRQSTAT_FARALL_FLAG 0x02
  69. #define SX9310_IRQSTAT_SMARTSAR_FLAG 0x01
  70. /* CpsStat */
  71. #define SX9310_TCHCMPSTAT_TCHCOMB_FLAG 0x08
  72. #define SX9310_TCHCMPSTAT_TCHSTAT2_FLAG 0x04
  73. #define SX9310_TCHCMPSTAT_TCHSTAT1_FLAG 0x02
  74. #define SX9310_TCHCMPSTAT_TCHSTAT0_FLAG 0x01
  75. /* SoftReset */
  76. #define SX9310_SOFTRESET 0xDE
  77. /**************************************
  78. * define platform data
  79. *
  80. **************************************/
  81. struct smtc_reg_data {
  82. unsigned char reg;
  83. unsigned char val;
  84. };
  85. typedef struct smtc_reg_data smtc_reg_data_t;
  86. typedef struct smtc_reg_data *psmtc_reg_data_t;
  87. struct _buttonInfo {
  88. /*! The Key to send to the input */
  89. int keycode;
  90. /*! Mask to look for on Touch Status */
  91. int mask;
  92. /*! Current state of button. */
  93. int state;
  94. };
  95. struct _totalButtonInformation {
  96. struct _buttonInfo *buttons;
  97. int buttonSize;
  98. struct input_dev *input;
  99. };
  100. typedef struct _totalButtonInformation buttonInformation_t;
  101. typedef struct _totalButtonInformation *pbuttonInformation_t;
  102. /* Define Registers that need to be initialized to values different than
  103. * default
  104. */
  105. static struct smtc_reg_data sx9310_i2c_reg_setup[] = {
  106. {
  107. .reg = SX9310_IRQ_ENABLE_REG,
  108. .val = 0x70,
  109. },
  110. {
  111. .reg = SX9310_IRQFUNC_REG,
  112. .val = 0x00,
  113. },
  114. {
  115. .reg = SX9310_CPS_CTRL1_REG,
  116. .val = 0x00,
  117. },
  118. {
  119. .reg = SX9310_CPS_CTRL2_REG,
  120. .val = 0x04,
  121. },
  122. {
  123. .reg = SX9310_CPS_CTRL3_REG,
  124. .val = 0x0A,
  125. },
  126. {
  127. .reg = SX9310_CPS_CTRL4_REG,
  128. .val = 0x0D,
  129. },
  130. {
  131. .reg = SX9310_CPS_CTRL5_REG,
  132. .val = 0x01, //7.5pF //0xC1
  133. },
  134. {
  135. .reg = SX9310_CPS_CTRL6_REG,
  136. .val = 0x20,
  137. },
  138. {
  139. .reg = SX9310_CPS_CTRL7_REG,
  140. .val = 0x4C,
  141. },
  142. {
  143. .reg = SX9310_CPS_CTRL8_REG,
  144. .val = 0xCD, //11001:320 101:diff>1500
  145. },
  146. {
  147. .reg = SX9310_CPS_CTRL9_REG,
  148. .val = 0x7D,
  149. },
  150. {
  151. .reg = SX9310_CPS_CTRL10_REG,
  152. .val = 0x00,
  153. },
  154. {
  155. .reg = SX9310_CPS_CTRL11_REG,
  156. .val = 0x00,
  157. },
  158. {
  159. .reg = SX9310_CPS_CTRL12_REG,
  160. .val = 0x00,
  161. },
  162. {
  163. .reg = SX9310_CPS_CTRL13_REG,
  164. .val = 0x00,
  165. },
  166. {
  167. .reg = SX9310_CPS_CTRL14_REG,
  168. .val = 0x00,
  169. },
  170. {
  171. .reg = SX9310_CPS_CTRL15_REG,
  172. .val = 0x00,
  173. },
  174. {
  175. .reg = SX9310_CPS_CTRL16_REG,
  176. .val = 0x00,
  177. },
  178. {
  179. .reg = SX9310_CPS_CTRL17_REG,
  180. .val = 0x04,
  181. },
  182. {
  183. .reg = SX9310_CPS_CTRL18_REG,
  184. .val = 0x00,
  185. },
  186. {
  187. .reg = SX9310_CPS_CTRL19_REG,
  188. .val = 0x00,
  189. },
  190. {
  191. .reg = SX9310_SAR_CTRL0_REG,
  192. .val = 0x00,
  193. },
  194. {
  195. .reg = SX9310_SAR_CTRL1_REG,
  196. .val = 0x80,
  197. },
  198. {
  199. .reg = SX9310_SAR_CTRL2_REG,
  200. .val = 0x0C,
  201. },
  202. {
  203. .reg = SX9310_CPS_CTRL0_REG,
  204. .val = 0x51,
  205. },
  206. };
  207. static struct _buttonInfo psmtcButtons[] = {
  208. {
  209. .keycode = KEY_0,
  210. .mask = SX9310_TCHCMPSTAT_TCHSTAT0_FLAG,
  211. },
  212. //modify xmysx20161027
  213. #if 0
  214. {
  215. .keycode = KEY_1,
  216. .mask = SX9310_TCHCMPSTAT_TCHSTAT1_FLAG,
  217. },
  218. {
  219. .keycode = KEY_2,
  220. .mask = SX9310_TCHCMPSTAT_TCHSTAT2_FLAG,
  221. },
  222. {
  223. .keycode = KEY_3,
  224. .mask = SX9310_TCHCMPSTAT_TCHCOMB_FLAG,
  225. },
  226. #endif
  227. };
  228. struct sx9310_platform_data {
  229. int i2c_reg_num;
  230. struct smtc_reg_data *pi2c_reg;
  231. pbuttonInformation_t pbuttonInformation;
  232. int (*get_is_nirq_low)(void);
  233. int (*init_platform_hw)(void);
  234. void (*exit_platform_hw)(void);
  235. };
  236. typedef struct sx9310_platform_data sx9310_platform_data_t;
  237. typedef struct sx9310_platform_data *psx9310_platform_data_t;
  238. /***************************************
  239. * define data struct/interrupt
  240. *
  241. ***************************************/
  242. //#define USE_THREADED_IRQ
  243. #define MAX_NUM_STATUS_BITS (8)
  244. typedef struct sx93XX sx93XX_t, *psx93XX_t;
  245. struct sx93XX
  246. {
  247. void * bus; /* either i2c_client or spi_client */
  248. struct device *pdev; /* common device struction for linux */
  249. void *pDevice; /* device specific struct pointer */
  250. /* Function Pointers */
  251. int (*init)(psx93XX_t this); /* (re)initialize device */
  252. /* since we are trying to avoid knowing registers, create a pointer to a
  253. * common read register which would be to read what the interrupt source
  254. * is from
  255. */
  256. int (*refreshStatus)(psx93XX_t this); /* read register status */
  257. int (*get_nirq_low)(void); /* get whether nirq is low (platform data) */
  258. /* array of functions to call for corresponding status bit */
  259. void (*statusFunc[MAX_NUM_STATUS_BITS])(psx93XX_t this);
  260. #if defined(USE_THREADED_IRQ)
  261. struct mutex mutex;
  262. #else
  263. spinlock_t lock; /* Spin Lock used for nirq worker function */
  264. #endif
  265. int irq; /* irq number used */
  266. struct device_node *irq_node;
  267. /* whether irq should be ignored.. cases if enable/disable irq is not used
  268. * or does not work properly */
  269. char irq_disabled;
  270. u8 useIrqTimer; /* older models need irq timer for pen up cases */
  271. int irqTimeout; /* msecs only set if useIrqTimer is true */
  272. /* struct workqueue_struct *ts_workq; */ /* if want to use non default */
  273. struct delayed_work dworker; /* work struct for worker function */
  274. #if 0//def CONFIG_HAS_WAKELOCK
  275. struct early_suspend early_suspend; /* early suspend data */
  276. #endif
  277. };
  278. #define IDLE 0
  279. #define ACTIVE 1
  280. #endif