stk6d2x.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666
  1. /*
  2. *
  3. * $Id: stk6d2x.h
  4. *
  5. * Copyright (C) 2012~2018 Bk, sensortek Inc.
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file COPYING in the main directory of this archive for
  9. * more details.
  10. *
  11. */
  12. #ifndef __STK6D2X_H__
  13. #define __STK6D2X_H__
  14. #if IS_ENABLED(CONFIG_SENSORS_FLICKER_SELF_TEST)
  15. #include "flicker_test.h"
  16. #endif
  17. #include "common_define.h"
  18. #include "stk6d2x_ver.h"
  19. #define STK6D2X_DEV_NAME "STK6D2X"
  20. //#define ALS_NAME "lightsensor-level"
  21. #define MODULE_NAME_ALS "als_rear"
  22. #define APS_TAG "[ALS/PS] "
  23. #define APS_FUN(f) printk(KERN_INFO APS_TAG" %s\n", __FUNCTION__)
  24. #define APS_ERR(fmt, args...) printk(KERN_ERR APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
  25. #define APS_LOG(fmt, args...) printk(KERN_INFO APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
  26. #define APS_DBG(fmt, args...) printk(KERN_INFO APS_TAG" %s %d: "fmt"\n", __FUNCTION__, __LINE__, ##args)
  27. /* Driver Settings */
  28. #define STK_ALS_ENABLE
  29. // #define STK_ALS_CALI
  30. #define STK_FIFO_ENABLE
  31. #define STK_ALS_AGC
  32. #define STK_CHK_XFLG
  33. #define CONFIG_AMS_ALS_COMPENSATION_FOR_AUTO_BRIGHTNESS
  34. #define CONFIG_AMS_ALWAYS_ON_MODE_FOR_AUTO_BRIGHTNESS
  35. #ifdef STK_FIFO_ENABLE
  36. // #define STK_DATA_SUMMATION
  37. // #define STK_FIFO_DATA_SUMMATION
  38. #define STK_FFT_FLICKER
  39. #ifdef STK_FFT_FLICKER
  40. #define STK_CHK_CLK_SRC
  41. #define SEC_FFT_FLICKER_1024
  42. #endif
  43. #endif
  44. /* Define Register Map */
  45. #define STK6D2X_REG_STATE 0x00
  46. #define STK6D2X_REG_ALS01_DGAIN 0x01
  47. #define STK6D2X_REG_ALS2_DGAIN 0x02
  48. #define STK6D2X_REG_IT1 0x03
  49. #define STK6D2X_REG_IT2 0x04
  50. #define STK6D2X_REG_WAIT1 0x05
  51. #define STK6D2X_REG_WAIT2 0x06
  52. #define STK6D2X_REG_ALS_SUM_GAIN1 0x08
  53. #define STK6D2X_REG_ALS_SUM_GAIN2 0x09
  54. #define STK6D2X_REG_THDH1_ALS 0x0A
  55. #define STK6D2X_REG_THDH2_ALS 0x0B
  56. #define STK6D2X_REG_THDL1_ALS 0x0C
  57. #define STK6D2X_REG_THDL2_ALS 0x0D
  58. #define STK6D2X_REG_ALS_IT_EXT 0x0E
  59. #define STK6D2X_REG_FLAG 0x10
  60. #define STK6D2X_REG_DATA1_ALS0 0x11
  61. #define STK6D2X_REG_DATA2_ALS0 0x12
  62. #define STK6D2X_REG_DATA1_ALS1 0x13
  63. #define STK6D2X_REG_DATA2_ALS1 0x14
  64. #define STK6D2X_REG_DATA1_ALS2 0x15
  65. #define STK6D2X_REG_DATA2_ALS2 0x16
  66. #define STK6D2X_REG_AGC1_DG 0x17
  67. #define STK6D2X_REG_AGC2_DG 0x18
  68. #define STK6D2X_REG_AGC_CROS_THD_FLAG 0x19
  69. #define STK6D2X_REG_AGC_AG 0x1A
  70. #define STK6D2X_REG_AGC_PD 0x1B
  71. #define STK6D2X_REG_DATA1_ALS0_SUM 0x1C
  72. #define STK6D2X_REG_DATA2_ALS0_SUM 0x1D
  73. #define STK6D2X_REG_DATA1_ALS1_SUM 0x1E
  74. #define STK6D2X_REG_DATA2_ALS1_SUM 0x1F
  75. #define STK6D2X_REG_DATA1_ALS2_SUM 0x20
  76. #define STK6D2X_REG_DATA2_ALS2_SUM 0x21
  77. #define STK6D2X_REG_DATA_AGC_SUM 0x22
  78. #define STK6D2X_REG_RID 0x3F
  79. #define STK6D2X_REG_ALS_PRST 0x40
  80. #define STK6D2X_REG_FIFO1 0x60
  81. #define STK6D2X_REG_FIFO1_WM_LV 0x61
  82. #define STK6D2X_REG_FIFO2_WM_LV 0x62
  83. #define STK6D2X_REG_FIFO_FCNT1 0x64
  84. #define STK6D2X_REG_FIFO_FCNT2 0x65
  85. #define STK6D2X_REG_FIFO_OUT 0x66
  86. #define STK6D2X_REG_AGC1 0x6A
  87. #define STK6D2X_REG_AGC2 0x6B
  88. #define STK6D2X_REG_ALS_SUM 0x70
  89. #define STK6D2X_REG_SW_RESET 0x80
  90. #define STK6D2X_REG_PDT_ID 0x92
  91. #define STK6D2X_REG_INT2 0xA5
  92. #define STK6D2X_REG_XFLAG 0xA6
  93. #define STK6D2X_REG_ALS_AGAIN 0xDB
  94. #define STK6D2X_REG_ALS_PD_REDUCE 0xF4
  95. /* Define state reg */
  96. #define STK6D2X_STATE_EN_SUMMATION_SHIFT 3
  97. #define STK6D2X_STATE_EN_WAIT_SHIFT 2
  98. #define STK6D2X_STATE_EN_ALS_SHIFT 1
  99. #define STK6D2X_STATE_EN_FSM_RESTART_MASK 0x10
  100. #define STK6D2X_STATE_EN_SUMMATION_MASK 0x08
  101. #define STK6D2X_STATE_EN_WAIT_MASK 0x04
  102. #define STK6D2X_STATE_EN_ALS_MASK 0x02
  103. /* Define ALS DGAIN reg */
  104. #define STK6D2X_ALS2_DGAIN_SHIFT 4
  105. #define STK6D2X_ALS1_DGAIN_SHIFT 0
  106. #define STK6D2X_ALS0_DGAIN_SHIFT 4
  107. #define STK6D2X_ALS2_DGAIN_MASK 0x70
  108. #define STK6D2X_ALS1_DGAIN_MASK 0x07
  109. #define STK6D2X_ALS0_DGAIN_MASK 0x70
  110. /* Define interrupt reg */
  111. #define STK6D2X_INT_ALS_SHIFT 3
  112. #define STK6D2X_INT_ALS_MASK 0x08
  113. #define STK6D2X_INT_ALS 0x08
  114. /* Define flag reg */
  115. #define STK6D2X_FLG_ALSDR_SHIFT 7
  116. #define STK6D2X_FLG_ALSINT_SHIFT 5
  117. #define STK6D2X_FLG_ALSSAT_SHIFT 2
  118. #define STK6D2X_FLG_ALSDR_MASK 0x80
  119. #define STK6D2X_FLG_ALSINT_MASK 0x20
  120. #define STK6D2X_FLG_ALSSAT_MASK 0x04
  121. /* Define ALS parameters */
  122. #define STK6D2X_ALS_PRS1 0x00
  123. #define STK6D2X_ALS_PRS2 0x40
  124. #define STK6D2X_ALS_PRS4 0x80
  125. #define STK6D2X_ALS_PRS8 0xC0
  126. #define STK6D2X_ALS_DGAIN1 0x00
  127. #define STK6D2X_ALS_DGAIN4 0x01
  128. #define STK6D2X_ALS_DGAIN16 0x02
  129. #define STK6D2X_ALS_DGAIN64 0x03
  130. #define STK6D2X_ALS_DGAIN128 0x04
  131. #define STK6D2X_ALS_DGAIN256 0x05
  132. #define STK6D2X_ALS_DGAIN512 0x06
  133. #define STK6D2X_ALS_DGAIN1024 0x07
  134. #define STK6D2X_ALS_DGAIN_MASK 0x07
  135. #define STK6D2X_ALS_SUM_GAIN_DIV1 0x00
  136. #define STK6D2X_ALS_SUM_GAIN_DIV2 0x01
  137. #define STK6D2X_ALS_SUM_GAIN_DIV4 0x02
  138. #define STK6D2X_ALS_SUM_GAIN_DIV8 0x03
  139. #define STK6D2X_ALS_SUM_GAIN_DIV6 0x04
  140. #define STK6D2X_ALS_SUM_GAIN_DIV32 0x05
  141. #define STK6D2X_ALS_SUM_GAIN_DIV64 0x06
  142. #define STK6D2X_ALS_SUM_GAIN_DIV128 0x07
  143. #define STK6D2X_ALS_SUM_GAIN_DIV256 0x08
  144. #define STK6D2X_ALS_SUM_GAIN_MASK 0x0F
  145. #define STK6D2X_ALS_CI_2_0 0x00
  146. #define STK6D2X_ALS_CI_1_0 0x01
  147. #define STK6D2X_ALS_CI_0_5 0x02
  148. #define STK6D2X_ALS_PD_REDUCE_DIS 0x00
  149. #define STK6D2X_ALS_PD_REDUCE_LV1 0x01
  150. #define STK6D2X_ALS_PD_REDUCE_LV2 0x02
  151. #define STK6D2X_ALS_IT25 0x3A9
  152. #define STK6D2X_ALS_IT40 0x5DB
  153. #define STK6D2X_ALS_IT50 0x753
  154. #define STK6D2X_ALS_IT100 0xEA6
  155. #define STK6D2X_ALS_IT200 0x1D4D
  156. #define STK6D2X_ALS_IT1_MASK 0x3F
  157. #define STK6D2X_ALS_IT_EXT_MASK 0x3F
  158. #define STK6D2X_WAIT20 0x359
  159. #define STK6D2X_WAIT50 0x85F
  160. #define STK6D2X_WAIT100 0x10BE
  161. #define STK6D2X_PRST1 0x00
  162. #define STK6D2X_PRST2 0x01
  163. #define STK6D2X_PRST4 0x02
  164. #define STK6D2X_PRST8 0x03
  165. #define STK6D2X_FLG_ALS2_DG_MASK 0x40
  166. #define STK6D2X_FLG_ALS1_DG_MASK 0x20
  167. #define STK6D2X_FLG_ALS0_DG_MASK 0x10
  168. #define STK6D2X_ALS2_AGC_DG_MASK 0x07
  169. #define STK6D2X_ALS1_AGC_DG_MASK 0x70
  170. #define STK6D2X_ALS0_AGC_DG_MASK 0x07
  171. #define STK6D2X_ALS2_AGC_AG_MASK 0x30
  172. #define STK6D2X_ALS1_AGC_AG_MASK 0x0C
  173. #define STK6D2X_ALS0_AGC_AG_MASK 0x03
  174. #define STK6D2X_ALS2_AGC_PD_MASK 0x30
  175. #define STK6D2X_ALS1_AGC_PD_MASK 0x0C
  176. #define STK6D2X_ALS0_AGC_PD_MASK 0x01
  177. #define STK6D2X_ALS0_AGC_PDMODE_MASK 0xC0
  178. #define STK6D2X_ALS0_AGC_PDMODE0 0x00
  179. #define STK6D2X_ALS0_AGC_PDMODE1 0x01
  180. #define STK6D2X_ALS0_AGC_PDMODE_SHIFT 6
  181. #define STK6D2X_FLG_ALS2_SUM_AGC_MASK 0x40
  182. #define STK6D2X_FLG_ALS1_SUM_AGC_MASK 0x20
  183. #define STK6D2X_FLG_ALS0_SUM_AGC_MASK 0x10
  184. #define STK6D2X_TYPE_ALS0 0
  185. #define STK6D2X_TYPE_ALS1 1
  186. #define STK6D2X_TYPE_ALS2 2
  187. /** sw reset value */
  188. #define STK_STK6D2X_SWRESET 0x00
  189. /** Off to idle time */
  190. #define STK6D2X_OFF_TO_IDLE_MS 10 //ms
  191. /** ALS threshold */
  192. #define STK6D2X_ALS_THD_ADJ 0.05
  193. #define STK6D2X_NUM_AXES 3
  194. #define STK6D2X_MAX_MIN_DIFF 200
  195. #define STK6D2X_LT_N_CT 1700
  196. #define STK6D2X_HT_N_CT 2200
  197. #define STK6D2X_ALS_DATA_READY_TIME 60
  198. #define STK6D2X_ALS_THRESHOLD 30
  199. #define STK6D2X_ALS_SUMMATION_CNT 51
  200. #ifdef STK_ALS_CALI
  201. #define STK6D2X_ALS_CALI_DATA_READY_US 55000000
  202. #define STK6D2X_ALS_CALI_TARGET_LUX 500
  203. #endif
  204. #ifdef STK_UV_CALI
  205. #define STK6D2X_UV_CALI_TARGET 10
  206. #endif
  207. #define STK_FLICKER_IT 0x0C
  208. #define STK_FLICKER_EXT_IT 0x0D
  209. #ifdef STK_FIFO_ENABLE
  210. #define STK_FIFO_DATA_BUFFER_LEN 1024
  211. #define STK_FIFO_I2C_READ_FRAME 30//get fifo data one time
  212. #define STK_FIFO_I2C_READ_FRAME_BUF_SIZE STK_FIFO_I2C_READ_FRAME * 10
  213. #define STK_FIFO_I2C_READ_FRAME_TARGET 102
  214. #ifdef STK_FFT_FLICKER
  215. #define FFT_BLOCK_SIZE 128
  216. #define FFT_BUF_SIZE 1024
  217. #endif
  218. #define STK6D2X_FIFO_SEL_ALS0 0x00
  219. #define STK6D2X_FIFO_SEL_ALS1 0x01
  220. #define STK6D2X_FIFO_SEL_ALS2 0x02
  221. #define STK6D2X_FIFO_SEL_ALS0_ALS1 0x03
  222. #define STK6D2X_FIFO_SEL_ALS0_ALS2 0x04
  223. #define STK6D2X_FIFO_SEL_ALS1_ALS2 0x05
  224. #define STK6D2X_FIFO_SEL_ALS0_ALS1_ALS2 0x06
  225. #define STK6D2X_FIFO_SEL_STA0_ALS0 0x08
  226. #define STK6D2X_FIFO_SEL_STA1_ALS1 0x09
  227. #define STK6D2X_FIFO_SEL_STA2_ALS2 0x0A
  228. #define STK6D2X_FIFO_SEL_STA01_ALS0_ALS1 0x0B
  229. #define STK6D2X_FIFO_SEL_STA02_ALS0_ALS2 0x0C
  230. #define STK6D2X_FIFO_SEL_STA12_ALS1_ALS2 0x0D
  231. #define STK6D2X_FIFO_SEL_STA01_STA2_ALS0_ALS1_ALS2 0x0E
  232. #define STK6D2X_FIFO_SEL_MASK 0x0F
  233. #define STK6D2X_FIFO_MODE_OFF 0x00
  234. #define STK6D2X_FIFO_MODE_BYPASS 0x10
  235. #define STK6D2X_FIFO_MODE_NORMAL 0x20
  236. #define STK6D2X_FIFO_MODE_STREAM 0x30
  237. #define STK6D2X_FOVR_EN_MASK 0x04
  238. #define STK6D2X_FWM_EN_MASK 0x02
  239. #define STK6D2X_FFULL_EN_MASK 0x01
  240. #define STK6D2X_FLG_FIFO_OVR_MASK 0x04
  241. #define STK6D2X_FLG_FIFO_WM_MASK 0x02
  242. #define STK6D2X_FLG_FIFO_FULL_MASK 0x01
  243. #endif
  244. #define STK_ALSPS_TIMER_MS 90
  245. #define STK6D2X_CALI_FILE "/persist/sensors/stkalpscali.conf"
  246. #define STK_CHANNEL_NUMBER 3
  247. #define STK_CHANNEL_OFFSET 3
  248. #define STK_CHANNEL_GOLDEN 10
  249. #define STK6D2X_REG_READ(stk_data, reg, val) ((stk_data)->bops->read((stk_data)->bus_idx, reg, val))
  250. #define STK6D2X_REG_WRITE(stk_data, reg, val) ((stk_data)->bops->write((stk_data)->bus_idx, reg, val))
  251. #define STK6D2X_REG_WRITE_BLOCK(stk_data, reg, val, len) ((stk_data)->bops->write_block((stk_data)->bus_idx, reg, val, len))
  252. #define STK6D2X_REG_READ_MODIFY_WRITE(stk_data, reg, val, mask) ((stk_data)->bops->read_modify_write((stk_data)->bus_idx, reg, val, mask))
  253. #define STK6D2X_REG_BLOCK_READ(stk_data, reg, count, buf) ((stk_data)->bops->read_block((stk_data)->bus_idx, reg, count, buf))
  254. #define STK6D2X_TIMER_REGISTER(stk_data, t_info) ((stk_data)->tops->register_timer(t_info))
  255. #define STK6D2X_TIMER_START(stk_data, t_info) ((stk_data)->tops->start_timer(t_info))
  256. #define STK6D2X_TIMER_STOP(stk_data, t_info) ((stk_data)->tops->stop_timer(t_info))
  257. #define STK6D2X_TIMER_REMOVE(stk_data, t_info) ((stk_data)->tops->remove(t_info))
  258. #define STK6D2X_TIMER_BUSY_WAIT(stk_data, min, max, mode) ((stk_data)->tops->busy_wait(min, max, mode))
  259. #define STK6D2X_GPIO_IRQ_REGISTER(stk_data, g_info) ((stk_data)->gops->register_gpio_irq(g_info))
  260. #define STK6D2X_GPIO_IRQ_START(stk_data, g_info) ((stk_data)->gops->start_gpio_irq(g_info))
  261. #define STK6D2X_GPIO_IRQ_STOP(stk_data, g_info) ((stk_data)->gops->stop_gpio_irq(g_info))
  262. #define STK6D2X_GPIO_IRQ_REMOVE(stk_data, g_info) ((stk_data)->gops->remove(g_info))
  263. #define STK6D2X_ALS_REPORT(stk_data, als_data, num) if ((stk_data)->als_report_cb) ((stk_data)->als_report_cb(stk_data, als_data, num))
  264. #define STK_ABS(x) ((x < 0)? (-x):(x))
  265. enum fft_size {
  266. FFT_128 = 128,
  267. FFT_256 = 256,
  268. FFT_512 = 512,
  269. FFT_1024 = 1024,
  270. //FFT_2048 = 2048, // not ready
  271. };
  272. // sec_fft
  273. #define SEC_FFT_SIZE FFT_1024
  274. #define SAMPLING_TIME (488319) /* nsec (2048Hz) */
  275. //#define FLICKER_AVG_SHIFT 7
  276. #define FLICKER_AVG_SHIFT 14
  277. #define SEC_LOCAL_AVG_SIZE 128 // 1024/n recommended, no 1024
  278. // average/max thd
  279. #define FLICKER_AVGMAX_THD 65LL
  280. // sec_ calc_thd
  281. #define FLICKER_THD_CLEAR 1800LL /* 1.8 * 1000 */
  282. #define FLICKER_THD_RATIO 3LL /* 0.003 * 1000 */
  283. #define FLICKER_GAIN_MAX 256LL /* 256 */
  284. #define FLICKER_THD_RATIO_AUTO 1000LL /* 1 * 1000 */
  285. typedef struct stk6d2x_data stk6d2x_data;
  286. typedef void (*STK_REPORT_CB)(stk6d2x_data *, uint32_t*, uint32_t);
  287. /* platform data */
  288. struct stk6d2x_platform_data
  289. {
  290. uint32_t als_scale;
  291. uint32_t int_flags;
  292. };
  293. typedef enum
  294. {
  295. STK6D2X_NONE = 0x0,
  296. STK6D2X_ALS = 0x1,
  297. STK6D2X_ALL = 0x2,
  298. } stk6d2x_sensor_type;
  299. typedef enum
  300. {
  301. STK6D2X_DATA_TIMER_ALPS,
  302. #ifdef STK_FIFO_ENABLE
  303. //STK6D2X_FIFO_RELEASE_TIMER,
  304. #endif
  305. } stk6d2x_timer_type;
  306. typedef struct stk6d2x_register_table
  307. {
  308. uint8_t address;
  309. uint8_t value;
  310. uint8_t mask_bit;
  311. } stk6d2x_register_table;
  312. #ifdef STK_FIFO_ENABLE
  313. typedef enum
  314. {
  315. STK6D2X_FIFO_ALS0 = 0x0,
  316. STK6D2X_FIFO_ALS1 = 0x1,
  317. STK6D2X_FIFO_ALS2 = 0x2,
  318. STK6D2X_FIFO_ALS0_ALS1 = 0x3,
  319. STK6D2X_FIFO_ALS0_ALS2 = 0x4,
  320. STK6D2X_FIFO_ALS1_ALS2 = 0x5,
  321. STK6D2X_FIFO_ALS0_ALS1_ALS2 = 0x6,
  322. STK6D2X_FIFO_STA0_ALS0 = 0x8,
  323. STK6D2X_FIFO_STA1_ALS1 = 0x9,
  324. STK6D2X_FIFO_STA2_ALS2 = 0xA,
  325. STK6D2X_FIFO_STA01_ALS0_ALS1 = 0xB,
  326. STK6D2X_FIFO_STA02_ALS0_ALS2 = 0xC,
  327. STK6D2X_FIFO_STA12_ALS1_ALS2 = 0xD,
  328. STK6D2X_FIFO_STA01_STA2_ALS0_ALS1_ALS2 = 0xE,
  329. STK6D2X_FIFO_UNAVAILABLE = 0xF,
  330. } stk6d2x_frame_type;
  331. #endif
  332. #ifdef STK_ALS_CALI
  333. typedef enum
  334. {
  335. STK6D2X_CALI_IDLE,
  336. STK6D2X_CALI_RUNNING,
  337. STK6D2X_CALI_FAILED,
  338. STK6D2X_CALI_DONE
  339. } stk6d2x_calibration_status;
  340. #endif
  341. #ifdef STK_ALS_AGC
  342. typedef enum
  343. {
  344. STK6D2X_ALS_DGAIN_MULTI1 = 1,
  345. STK6D2X_ALS_DGAIN_MULTI4 = 4,
  346. STK6D2X_ALS_DGAIN_MULTI16 = 16,
  347. STK6D2X_ALS_DGAIN_MULTI64 = 64,
  348. STK6D2X_ALS_DGAIN_MULTI128 = 128,
  349. STK6D2X_ALS_DGAIN_MULTI256 = 256,
  350. STK6D2X_ALS_DGAIN_MULTI512 = 512,
  351. STK6D2X_ALS_DGAIN_MULTI1024 = 1024,
  352. } stk6d2x_als_dgain_multi;
  353. typedef enum
  354. {
  355. STK6D2X_ALS_AGAIN_MULTI1 = 1,
  356. STK6D2X_ALS_AGAIN_MULTI2 = 2,
  357. STK6D2X_ALS_AGAIN_MULTI4 = 4,
  358. } stk6d2x_als_again_multi;
  359. typedef enum
  360. {
  361. STK6D2X_ALS_PD_REDUCE_MULTI1 = 1,
  362. STK6D2X_ALS_PD_REDUCE_MULTI2 = 2,
  363. STK6D2X_ALS_PD_REDUCE_MULTI3 = 3,
  364. STK6D2X_ALS_PD_REDUCE_MULTI4 = 4,
  365. } stk6d2x_als_pd_reduce_multi;
  366. #endif
  367. typedef struct stk6d2x_cali_table
  368. {
  369. uint32_t als_version;
  370. uint32_t als_scale;
  371. uint32_t als_bias;
  372. } stk6d2x_cali_table;
  373. typedef struct stk6d2x_cali_info
  374. {
  375. #ifdef STK_ALS_CALI
  376. stk6d2x_calibration_status cali_status;
  377. #endif
  378. stk6d2x_cali_table cali_para;
  379. } stk6d2x_cali_info;
  380. typedef struct stk6d2x_als_info
  381. {
  382. bool first_init;
  383. bool cali_enable;
  384. bool enable;
  385. uint32_t scale;
  386. bool is_data_ready;
  387. uint16_t als_it;
  388. uint8_t cali_failed_count;
  389. uint64_t last_raw_data[3];
  390. uint16_t als_cali_data;
  391. uint16_t last_lux;
  392. #ifdef STK_ALS_AGC
  393. uint16_t als_agc_sum;
  394. uint16_t als_cur_dgain[3];
  395. uint16_t als_cur_again[3];
  396. uint16_t als_cur_pd_reduce[3];
  397. uint8_t als_cur_pd_mode;
  398. uint32_t als_cur_ratio[3];
  399. uint8_t als_agc_sum_flag;
  400. uint32_t als_sum_gain_div[3];
  401. #endif
  402. } stk6d2x_als_info;
  403. #ifdef STK_FIFO_ENABLE
  404. typedef struct stk6d2x_fifo_info
  405. {
  406. bool fifo_enable;
  407. bool is_fifobuf_alloc;
  408. uint32_t fifo_data0[FFT_BUF_SIZE];
  409. uint32_t fifo_data1[FFT_BUF_SIZE];
  410. uint32_t fifo_data2[FFT_BUF_SIZE];
  411. #ifdef SEC_FFT_FLICKER_1024
  412. uint32_t fifo_data_clear[FFT_BUF_SIZE];
  413. uint32_t fifo_data_uv[FFT_BUF_SIZE];
  414. uint32_t fifo_data_ir[FFT_BUF_SIZE];
  415. uint32_t fifo_gain_clear[FFT_BUF_SIZE];
  416. uint32_t fifo_gain_uv[FFT_BUF_SIZE];
  417. uint32_t fifo_gain_ir[FFT_BUF_SIZE];
  418. uint8_t fifo_xflag[FFT_BUF_SIZE];
  419. #endif
  420. uint64_t fifo_sum_als0;
  421. uint64_t fifo_sum_als1;
  422. uint64_t fifo_sum_als2;
  423. uint32_t fifo_sum_cnt;
  424. uint16_t target_frame_count;
  425. uint16_t read_frame;
  426. uint16_t read_max_data_byte;
  427. uint8_t latency_status;
  428. stk6d2x_frame_type data_type;
  429. bool sel_mode;
  430. uint8_t frame_byte;
  431. uint8_t frame_data;
  432. uint16_t last_frame_count;
  433. bool fifo_reading;
  434. bool ext_clk_chk;
  435. bool pre_ext_clk_chk;
  436. uint16_t block_size;
  437. #ifdef STK_FFT_FLICKER
  438. uint32_t fft_buf[FFT_BUF_SIZE];
  439. uint32_t fft_uv_buf[FFT_BUF_SIZE];
  440. uint32_t fft_ir_buf[FFT_BUF_SIZE];
  441. uint32_t fft_gain_clear[FFT_BUF_SIZE];
  442. uint32_t fft_gain_uv[FFT_BUF_SIZE];
  443. uint32_t fft_gain_ir[FFT_BUF_SIZE];
  444. uint8_t fft_xflag[FFT_BUF_SIZE];
  445. uint32_t fft_buf_idx;
  446. #endif
  447. } stk6d2x_fifo_info;
  448. #endif
  449. #define PWR_ON 1
  450. #define PWR_OFF 0
  451. #define PM_RESUME 1
  452. #define PM_SUSPEND 0
  453. struct stk6d2x_data
  454. {
  455. struct stk6d2x_platform_data *pdata;
  456. const struct stk_bus_ops *bops;
  457. struct mutex config_lock;
  458. #if defined(CONFIG_AMS_ALS_COMPENSATION_FOR_AUTO_BRIGHTNESS)
  459. struct mutex enable_lock;
  460. #endif
  461. const struct stk_timer_ops *tops;
  462. const struct stk_gpio_ops *gops;
  463. int bus_idx;
  464. stk_gpio_info gpio_info;
  465. #ifdef STK_ALS_CALI
  466. stk_timer_info cali_timer_info;
  467. #endif
  468. stk6d2x_cali_info cali_info;
  469. stk6d2x_als_info als_info;
  470. stk_timer_info alps_timer_info;
  471. bool saturation;
  472. #ifdef STK_FIFO_ENABLE
  473. stk6d2x_fifo_info fifo_info;
  474. // fifo control timer
  475. stk_timer_info fifo_release_timer_info;
  476. uint64_t clear_local_average;
  477. uint64_t uv_local_average;
  478. uint64_t ir_local_average;
  479. bool is_clear_local_sat;
  480. bool is_uv_local_sat;
  481. bool is_ir_local_sat;
  482. int index_last;
  483. bool is_first;
  484. bool is_local_avg_update;
  485. uint32_t flicker;
  486. uint32_t uv_gain;
  487. uint32_t clear_gain;
  488. uint32_t ir_gain;
  489. #endif
  490. uint8_t rid;
  491. uint8_t xflag;
  492. STK_REPORT_CB als_report_cb;
  493. bool first_init;
  494. bool is_long_it;
  495. bool pm_state;
  496. u8 regulator_state;
  497. struct regulator* regulator_vdd_1p8;
  498. struct regulator* regulator_vbus_1p8;
  499. bool vdd_1p8_enable;
  500. bool vbus_1p8_enable;
  501. struct pinctrl *als_pinctrl;
  502. struct pinctrl_state *pins_sleep;
  503. struct pinctrl_state *pins_active;
  504. #if IS_ENABLED(CONFIG_SENSORS_FLICKER_SELF_TEST)
  505. bool eol_enabled;
  506. bool recover_state;
  507. #endif
  508. int isTrimmed;
  509. #if defined(CONFIG_AMS_ALS_COMPENSATION_FOR_AUTO_BRIGHTNESS)
  510. bool als_flag;
  511. bool flicker_flag;
  512. #endif
  513. int ext_clk_gpio;
  514. struct clk *pclk;
  515. struct rcg_clk *camcc_mclk5_rcg_clk;
  516. struct regulator *reg;
  517. bool reg_enable;
  518. bool use_ext_clk;
  519. } ;
  520. extern int als_debug;
  521. extern int als_info;
  522. #define ALS_DBG
  523. //#define ALS_INFO
  524. #ifndef ALS_dbg
  525. #if defined(ALS_DBG)
  526. #define ALS_dbg(format, arg...) \
  527. printk(KERN_DEBUG "ALS_dbg : %s: %d " format, __func__, __LINE__, ##arg)
  528. #define ALS_err(format, arg...) \
  529. printk(KERN_DEBUG "ALS_err : %s: %d " format, __func__, __LINE__, ##arg)
  530. #else
  531. #define ALS_dbg(format, arg...) {if (als_debug)\
  532. printk(KERN_DEBUG "ALS_dbg : %s: %d " format, __func__, __LINE__, ##arg);\
  533. }
  534. #define ALS_err(format, arg...) {if (als_debug)\
  535. printk(KERN_DEBUG "ALS_err : %s: %d " format, __func__, __LINE__, ##arg);\
  536. }
  537. #endif
  538. #endif
  539. #ifndef ALS_info
  540. #if defined(ALS_INFO)
  541. #define ALS_info(format, arg...) \
  542. printk(KERN_INFO "ALS_info : %s: %d " format, __func__, __LINE__, ##arg);
  543. #else
  544. #define ALS_info(format, arg...) {if (als_info)\
  545. printk(KERN_INFO "ALS_info : %s: %d " format, __func__, __LINE__, ##arg);\
  546. }
  547. #endif
  548. #endif
  549. int32_t stk6d2x_cali_als(struct stk6d2x_data *alps_data);
  550. void stk6d2x_get_reg_default_setting(uint8_t reg, uint16_t* value);
  551. int32_t stk6d2x_request_registry(struct stk6d2x_data *alps_data);
  552. int32_t stk6d2x_update_registry(struct stk6d2x_data *alps_data);
  553. int32_t stk6d2x_alps_set_config(stk6d2x_data *alps_data, bool en);
  554. int32_t stk6d2x_init_all_setting(stk6d2x_data *alps_data);
  555. int32_t stk6d2x_als_get_data(stk6d2x_data *alps_data, bool is_skip);
  556. void stk6d2x_dump_reg(struct stk6d2x_data *alps_data);
  557. void stk6d2x_force_stop(stk6d2x_data *alps_data);
  558. extern int sensors_create_symlink(struct kobject *target, const char *name);
  559. extern void sensors_remove_symlink(struct kobject *target, const char *name);
  560. extern int sensors_register(struct device **dev, void *drvdata,
  561. struct device_attribute *attributes[], char *name);
  562. extern void sensors_unregister(struct device *dev,
  563. struct device_attribute *attributes[]);
  564. int32_t stk6d2x_enable_als(stk6d2x_data *alps_data, bool en);
  565. #ifdef STK_ALS_AGC
  566. int32_t stk6d2x_cal_curDGain(uint8_t gain_val);
  567. uint8_t stk6d2x_als_get_again_multiple(uint8_t gain);
  568. uint8_t stk6d2x_als_get_pd_multiple(uint8_t gain, uint8_t pd_mode, uint8_t data_type);
  569. int32_t stk6d2x_get_curGain(struct stk6d2x_data *alps_data);
  570. void stk6d2x_get_als_ratio(struct stk6d2x_data *alps_data);
  571. #ifdef SEC_FFT_FLICKER_1024
  572. uint8_t stk6d2x_sec_dgain(uint8_t gain_val);
  573. uint8_t stk6d2x_sec_again(uint8_t gain);
  574. uint8_t stk6d2x_sec_pd_multiple(uint8_t gain, uint8_t pd_mode, uint8_t data_type);
  575. #endif
  576. #endif
  577. #ifdef STK_FIFO_ENABLE
  578. void stk6d2x_free_fifo_data(struct stk6d2x_data *alps_data);
  579. void stk6d2x_alloc_fifo_data(struct stk6d2x_data *alps_data, uint32_t size);
  580. void stk6d2x_fifo_init(struct stk6d2x_data *alps_data);
  581. int32_t stk6d2x_enable_fifo(struct stk6d2x_data *alps_data, bool en);
  582. void stk6d2x_fifo_get_data(struct stk6d2x_data *alps_data, uint16_t frame_num);
  583. void stk6d2x_get_fifo_data_polling(struct stk6d2x_data *alps_data);
  584. void stk6d2x_fifo_stop_control(stk_timer_info *t_info);
  585. #endif
  586. #if defined(CONFIG_AMS_ALS_COMPENSATION_FOR_AUTO_BRIGHTNESS)
  587. void stk_als_init(struct stk6d2x_data *alps_data);
  588. void stk_als_start(struct stk6d2x_data *alps_data);
  589. void stk_als_stop(struct stk6d2x_data *alps_data);
  590. #endif
  591. int32_t stk_power_ctrl(struct stk6d2x_data *alps_data, bool en);
  592. void stk6d2x_pin_control(struct stk6d2x_data *alps_data, bool pin_set);
  593. void stk_sec_report(struct stk6d2x_data *alps_data);
  594. #endif // __STK6D2X_H__