nfc-nci.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. /* Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __NFC_NCI_H
  13. #define __NFC_NCI_H
  14. #include <linux/i2c.h>
  15. #include <linux/types.h>
  16. #include <linux/version.h>
  17. #include <linux/semaphore.h>
  18. #include <linux/completion.h>
  19. #include <linux/ioctl.h>
  20. #include <linux/cdev.h>
  21. #include <linux/miscdevice.h>
  22. struct nfc_device {
  23. struct cdev cdev;
  24. struct class *char_class;
  25. };
  26. enum ehandler_mode {
  27. UNSOLICITED_MODE = 0,
  28. SOLICITED_MODE,
  29. UNSOLICITED_FTM_RAW_MODE,
  30. SOLICITED_FTM_RAW_MODE
  31. };
  32. enum ekernel_logging_mode {
  33. LEVEL_0 = 0, /* For Basic Comms, such asNCI TX/TX to NFCC */
  34. LEVEL_1, /* Other Debug e.g. Notifications, ISR hit, etc ..*/
  35. LEVEL_2,
  36. LEVEL_3,
  37. LEVEL_4,
  38. LEVEL_5
  39. };
  40. struct devicemode {
  41. enum ehandler_mode handle_flavour;
  42. } tdevicemode;
  43. #define NFC_DRIVER_NAME "nfc-nci"
  44. #define NFC_I2C_DRIVER_NAME "NCI NFC I2C Interface",
  45. #define NCI_I2C_SLAVE (0x2C)
  46. #define NFC_I2C_BUS 3 /* 6, 10, 4, 5 */
  47. #define NFC_SET_PWR _IOW(0xE9, 0x01, unsigned int)
  48. #define NFCC_MODE _IOW(0xE9, 0x02, unsigned int)
  49. #define NFC_KERNEL_LOGGING_MODE _IOW(0xE9, 0x03, unsigned int)
  50. #define SET_RX_BLOCK _IOW(0xE9, 0x04, unsigned int)
  51. #define SET_EMULATOR_TEST_POINT _IOW(0xE9, 0x05, unsigned int)
  52. #define NFCC_VERSION _IOW(0xE9, 0x08, unsigned int)
  53. #define NFC_GET_EFUSE _IOW(0xE9, 0x09, unsigned int)
  54. #define NFCC_INITIAL_CORE_RESET_NTF _IOW(0xE9, 0x10, unsigned int)
  55. #define NFC_MAX_I2C_TRANSFER (0x0400)
  56. #define NFC_MSG_MAX_SIZE (0x21)
  57. #define NFC_RX_BUFFER_CNT_START (0x0)
  58. #define NFC_RX_BUFFER_BLOCK_SIZE (0x120) /* Bytes per Block */
  59. #define NFC_RX_BUFFER_PAGE_SIZE (0x1000) /* Page size Bytes */
  60. #define NFC_RX_BUFFER_PAGES (0x8)
  61. #define NFC_RX_ORDER_FREE_PAGES (0x3) /* Free 8 Pages */
  62. /* The total no. of Blocks */
  63. #define NFC_RX_BUFFER_CNT_LIMIT (unsigned short)( \
  64. ( \
  65. ((NFC_RX_BUFFER_PAGE_SIZE) *\
  66. (NFC_RX_BUFFER_PAGES))/\
  67. (NFC_RX_BUFFER_BLOCK_SIZE)\
  68. ) \
  69. ) \
  70. #define PAYLOAD_HEADER_LENGTH (0x3)
  71. #define PAYLOAD_LENGTH_MAX (256)
  72. #define BYTE (0x8)
  73. #define NCI_IDENTIFIER (0x10)
  74. /** Power Management Related **/
  75. #define NFCC_WAKE (0x01)
  76. #define NFCC_SLEEP (0x00)
  77. #define XTAL_CLOCK (0X00)
  78. #define REFERENCE_CLOCK (0X01)
  79. /* LDO Trim Settings */
  80. #define IPTAT_TRIM (0x1F)
  81. #define V1P1_TRIM (0x0F)
  82. #define V1P8_TRIM (0x0F)
  83. #define VBATT_OK_THRESHOLD (0x07)
  84. #define PWR_EN (0x08) /* Enable 1.1V LDO Regulator */
  85. #define LS_EN (0x04) /* Enable 1.1V->1.8V Level Shifters */
  86. /* Write '1' to cause wake event to NFCC. If set NFCC will not go to SLEEP */
  87. #define NCI_WAKE (0x02)
  88. #define NCI_ENA (0x01) /* Write '1' to enable PLL */
  89. #define FREQ_SEL (0x00) /* XO Frequency Select */
  90. #define FREQ_SEL_13 (0x00) /* XO Frequency Select = 13.56MHz */
  91. #define FREQ_SEL_19 (0x01) /* XO Frequency Select = 19.20 MHz */
  92. #define FREQ_SEL_26 (0x02) /* XO Frequency Select = 26.00 MHz */
  93. #define FREQ_SEL_27 (0x03) /* XO Frequency Select = 27.12 MHz */
  94. #define FREQ_SEL_37 (0x04) /* XO Frequency Select = 37.40 MHz */
  95. #define FREQ_SEL_38 (0x05) /* XO Frequency Select = 38.40 MHz */
  96. #define FREQ_SEL_40 (0x06) /* XO Frequency Select = 40.00 MHz */
  97. #define FREQ_SEL_48 (0x07) /* XO Frequency Select = 48.00 MHz */
  98. #define FREQ_SEL_27 (0x03) /* XO Frequency Select */
  99. #define QUALIFY_REFCLK (0x80)
  100. #define QUALIFY_OSC (0x40)
  101. #define LOCALBIASXTAL (0x20)
  102. #define BIAS2X_FORCE (0x10)
  103. #define BIAS2X (0x08)
  104. #define LBIAS2X (0x04)
  105. #define SMALLRF (0x02)
  106. #define SMALLRBIAS (0x01)
  107. /* Select as appropriate */
  108. #define CRYSTAL_OSC ((QUALIFY_REFCLK) | (QUALIFY_OSC) | \
  109. (LOCALBIASXTAL) | (BIAS2X_FORCE) | \
  110. (BIAS2X) | (LBIAS2X) | (SMALLRF) | (SMALLRBIAS))
  111. #define CDACIN (0x3F) /* Tuning range for load capacitor at X1*/
  112. #define CDACOUT (0x3F) /* Tuning range for load capacitor at X2*/
  113. #define RAW(reg, value) (raw_##reg[1] = value)
  114. /* Logging macro with threshold control */
  115. #define PRINTK(LEVEL, THRESHOLD, pString, ...) ( \
  116. if (LEVEL > THRESHOLD) { \
  117. pr_info(pString, ##__VA_ARGS__); \
  118. } \
  119. )
  120. /* board config */
  121. struct nfc_platform_data {
  122. int (*request_resources) (struct i2c_client *client);
  123. void (*free_resources) (void);
  124. void (*enable) (int fw);
  125. int (*test) (void);
  126. void (*disable) (void);
  127. };
  128. /*
  129. * Internal NFCC Hardware states. At present these may not be possible to
  130. * detect in software as possibly no power when
  131. * in monitor state! Also, need to detect DISABLE control GPIO from PMIC.
  132. */
  133. enum nfcc_hardware_state {
  134. NFCC_STATE_MONITOR, /* VBAT < h/w Critcal Voltage */
  135. /* VBAT > H/W Critical Voltage;
  136. Lowest Power Mode - DISABLE = 1; only
  137. possible when phone is ON */
  138. NFCC_STATE_HPD,
  139. /* VBAT > H/W Critical Voltage; DISABLE = 0;
  140. Only possible when phone is ON */
  141. NFCC_STSTE_ULPM,
  142. /* VBAT > H/W Critical Voltage; DISABLE = 0;
  143. Powered by PMIC & VBAT; 1.8V I/O supply on; VDDPX available, boot is
  144. initiated by host over I2C */
  145. NFCC_STATE_NORMAL_REGION1,
  146. /* VBAT > H/W Critical Voltage; DISABLE = 0;
  147. Powered by VBAT; 1.8V I/O supply on; VDDPX available, boot is initiated
  148. by host over I2C */
  149. NFCC_STATE_NORMAL_REGION2,
  150. };
  151. /* We assume here that VBATT > h/w Critical Voltage */
  152. enum nfcc_state {
  153. /* Assume In ULPM state, ready for initialisation, cannot detect for
  154. Monitor or HPD states */
  155. NFCC_STATE_COLD,
  156. /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
  157. state WAKE */
  158. NFCC_STATE_NORMAL_WAKE,
  159. /* (VDDPX==1) && (Following I2C initialisation). In Region 1 or Region2
  160. state SLEEP */
  161. NFCC_STATE_NORMAL_SLEEP,
  162. };
  163. enum nfcc_irq {
  164. NFCC_NO_INT,
  165. NFCC_INT,
  166. };
  167. enum nfcc_initial_core_reset_ntf {
  168. TIMEDOUT_INITIAL_CORE_RESET_NTF = 0, /* 0*/
  169. ARRIVED_INITIAL_CORE_RESET_NTF, /* 1 */
  170. DEFAULT_INITIAL_CORE_RESET_NTF, /*2*/
  171. };
  172. struct nfc_info {
  173. struct miscdevice miscdev;
  174. struct i2c_client *i2c_dev;
  175. struct regulator_bulk_data regs[3];
  176. enum nfcc_state state;
  177. wait_queue_head_t read_wait;
  178. loff_t read_offset;
  179. struct mutex read_mutex;
  180. struct mutex mutex;
  181. u8 *buf;
  182. size_t buflen;
  183. spinlock_t irq_enabled_lock;
  184. unsigned int count_irq;
  185. enum nfcc_irq read_irq;
  186. };
  187. struct nfc_i2c_platform_data {
  188. unsigned int nfc_irq_gpio;
  189. unsigned int nfc_clk_en_gpio;
  190. unsigned int dis_gpio;
  191. unsigned int irq_gpio;
  192. unsigned int ven_gpio;
  193. unsigned int firm_gpio;
  194. unsigned int reg;
  195. };
  196. #endif