adsp.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /*
  2. * Copyright (C) 2012, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #ifndef __ADSP_SENSOR_H__
  16. #define __ADSP_SENSOR_H__
  17. #include <linux/kernel.h>
  18. #include <linux/module.h>
  19. #include <linux/device.h>
  20. #include <linux/delay.h>
  21. #include <linux/fs.h>
  22. #include <linux/file.h>
  23. #include <linux/fcntl.h>
  24. #include <linux/mm.h>
  25. #include <linux/slab.h>
  26. #include <linux/uaccess.h>
  27. //#include <linux/sensors.h>
  28. #include <linux/adsp/adsp_ft_common.h>
  29. #define TIMEOUT_CNT 200
  30. #define TIMEOUT_DHR_CNT 50
  31. #define PATH_LEN 50
  32. #define FILE_BUF_LEN 110
  33. #define ID_INDEX_NUMS 2
  34. #define RETRY_MAX 3
  35. #define VERSION_FILE_NAME_LEN 20
  36. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_6AXIS)
  37. /* To avoid wrong folder close */
  38. #define LSM6DSO_SELFTEST_TRUE 3
  39. #define LSM6DSO_SELFTEST_FALSE 4
  40. #endif
  41. #define UNKNOWN_INDEX 0
  42. #define DEVICE_INFO_LENGTH 10
  43. enum {
  44. D_FACTOR,
  45. R_COEF,
  46. G_COEF,
  47. B_COEF,
  48. C_COEF,
  49. CT_COEF,
  50. CT_OFFSET,
  51. THD_HIGH,
  52. THD_LOW,
  53. IRIS_PROX_THD,
  54. SUM_CRC,
  55. EFS_SAVE_NUMS,
  56. };
  57. enum {
  58. ID_UTYPE,
  59. ID_BLACK,
  60. ID_WHITE,
  61. ID_GOLD,
  62. ID_SILVER,
  63. ID_GREEN,
  64. ID_BLUE,
  65. ID_PINKGOLD,
  66. ID_MAX,
  67. };
  68. #if IS_ENABLED(CONFIG_SUPPORT_SENSOR_FOLD)
  69. struct sensor_fold_state {
  70. int64_t ts;
  71. int state; // 0: unfold, 1: close(fold)
  72. };
  73. #endif
  74. /* Main struct containing all the data */
  75. struct adsp_data {
  76. struct device *adsp;
  77. struct device *sensor_device[MSG_SENSOR_MAX];
  78. struct device_attribute **sensor_attr[MSG_SENSOR_MAX];
  79. struct sock *adsp_skt;
  80. int32_t *msg_buf[MSG_SENSOR_MAX];
  81. unsigned int ready_flag[MSG_TYPE_MAX];
  82. bool sysfs_created[MSG_SENSOR_MAX];
  83. struct mutex prox_factory_mutex;
  84. struct mutex light_factory_mutex;
  85. struct mutex accel_factory_mutex;
  86. struct mutex remove_sysfs_mutex;
  87. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_OPTIC)
  88. struct mutex vir_optic_factory_mutex;
  89. #endif
  90. #if IS_ENABLED(CONFIG_FLIP_COVER_DETECTOR_FACTORY)
  91. struct mutex flip_cover_factory_mutex;
  92. #endif
  93. #if IS_ENABLED(CONFIG_BACKTAP_FACTORY)
  94. struct mutex backtap_factory_mutex;
  95. #endif
  96. #if IS_ENABLED(CONFIG_SUPPORT_AK09973)
  97. struct mutex digital_hall_mutex;
  98. #endif
  99. struct notifier_block adsp_nb;
  100. #ifdef CONFIG_VBUS_NOTIFIER
  101. struct notifier_block vbus_nb;
  102. #endif
  103. int32_t fac_fstate;
  104. #if IS_ENABLED(CONFIG_LIGHT_FACTORY)
  105. struct delayed_work light_init_work;
  106. bool light_factory_is_ready;
  107. char light_device_vendor[2][10];
  108. char light_device_name[2][10];
  109. #endif
  110. #if IS_ENABLED(CONFIG_SUPPORT_LIGHT_CALIBRATION)
  111. struct delayed_work light_cal_work;
  112. int32_t light_cal_result;
  113. int32_t light_cal1;
  114. int32_t light_cal2;
  115. int32_t copr_w;
  116. int32_t sub_light_cal_result;
  117. int32_t sub_light_cal1;
  118. int32_t sub_light_cal2;
  119. int32_t sub_copr_w;
  120. #endif
  121. #if IS_ENABLED(CONFIG_SUPPORT_DDI_COPR_FOR_LIGHT_SENSOR)
  122. struct delayed_work light_copr_debug_work;
  123. int light_copr_debug_count;
  124. #endif
  125. #if IS_ENABLED(CONFIG_SUPPORT_FIFO_DEBUG_FOR_LIGHT_SENSOR)
  126. struct delayed_work light_fifo_debug_work;
  127. #endif
  128. #if IS_ENABLED(CONFIG_SUPPORT_BRIGHTNESS_NOTIFY_FOR_LIGHT_SENSOR)
  129. struct work_struct light_br_work;
  130. #endif
  131. #if IS_ENABLED(CONFIG_LIGHT_FACTORY)
  132. int32_t light_temp_reg;
  133. int32_t brightness_info[6];
  134. int32_t pre_bl_level[2];
  135. int32_t pre_panel_state[2];
  136. int32_t pre_screen_mode[2];
  137. int32_t pre_panel_idx;
  138. int32_t pre_display_idx;
  139. int32_t light_debug_info_cmd;
  140. int32_t hyst[4];
  141. int32_t brightness_resolution[2];
  142. #endif
  143. #if IS_ENABLED(CONFIG_SUPPORT_PROX_CALIBRATION)
  144. int32_t prox_cal;
  145. int32_t prox_sub_cal;
  146. #endif
  147. struct delayed_work accel_cal_work;
  148. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_6AXIS)
  149. struct delayed_work sub_accel_cal_work;
  150. #endif
  151. #if IS_ENABLED(CONFIG_SUPPORT_LIGHT_SEAMLESS)
  152. struct delayed_work light_seamless_work;
  153. #endif
  154. #if IS_ENABLED(CONFIG_SUPPORT_AK09973) || defined(CONFIG_SUPPORT_AK09973)
  155. struct delayed_work lsm6dso_selftest_stop_work;
  156. struct delayed_work dhall_cal_work;
  157. #elif IS_ENABLED(CONFIG_SUPPORT_REF_ANGLE_WITHOUT_DIGITAL_HALL) || defined(CONFIG_SUPPORT_REF_ANGLE_WITHOUT_DIGITAL_HALL)
  158. struct delayed_work lsm6dso_selftest_stop_work;
  159. #endif
  160. struct delayed_work pressure_cal_work;
  161. char press_device_vendor[DEVICE_INFO_LENGTH];
  162. char press_device_name[DEVICE_INFO_LENGTH];
  163. #if IS_ENABLED(CONFIG_SUPPORT_SENSOR_FOLD)
  164. struct sensor_fold_state fold_state;
  165. #endif
  166. uint32_t support_algo;
  167. bool restrict_mode;
  168. int turn_over_crash;
  169. bool send_probe_fail_msg;
  170. };
  171. struct device_id_t {
  172. uint8_t device_id;
  173. char device_vendor[DEVICE_INFO_LENGTH];
  174. char device_name[DEVICE_INFO_LENGTH];
  175. };
  176. #ifdef CONFIG_SEC_FACTORY
  177. int get_mag_raw_data(int32_t *raw_data);
  178. #endif
  179. int get_accel_raw_data(int32_t *raw_data);
  180. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_6AXIS)
  181. int get_sub_accel_raw_data(int32_t *raw_data);
  182. #endif
  183. int adsp_get_sensor_data(int sensor_type);
  184. int adsp_factory_register(unsigned int type,
  185. struct device_attribute *attributes[]);
  186. int adsp_factory_unregister(unsigned int type);
  187. #if IS_ENABLED(CONFIG_SUPPORT_DEVICE_MODE) || defined(CONFIG_VBUS_NOTIFIER)
  188. struct adsp_data* adsp_ssc_core_register(unsigned int type,
  189. struct device_attribute *attributes[]);
  190. struct adsp_data* adsp_ssc_core_unregister(unsigned int type);
  191. #endif
  192. int adsp_unicast(void *param, int param_size, u16 sensor_type,
  193. u32 portid, u16 msg_type);
  194. int sensors_register(struct device **dev, void *drvdata,
  195. struct device_attribute *attributes[], char *name);
  196. void sensors_unregister(struct device *dev,
  197. struct device_attribute *attributes[]);
  198. int core_factory_init(void);
  199. void core_factory_exit(void);
  200. #if IS_ENABLED(CONFIG_LSM6DSO_FACTORY)
  201. int lsm6dso_accel_factory_init(void);
  202. void lsm6dso_accel_factory_exit(void);
  203. int lsm6dso_gyro_factory_init(void);
  204. void lsm6dso_gyro_factory_exit(void);
  205. #endif
  206. #if IS_ENABLED(CONFIG_LSM6DSL_FACTORY)
  207. int lsm6dsl_accel_factory_init(void);
  208. void lsm6dsl_accel_factory_exit(void);
  209. int lsm6dsl_gyro_factory_init(void);
  210. void lsm6dsl_gyro_factory_exit(void);
  211. #endif
  212. void accel_factory_init_work(struct adsp_data *data);
  213. void accel_cal_work_func(struct work_struct *work);
  214. #if IS_ENABLED(CONFIG_AK09918_FACTORY)
  215. int ak09918_factory_init(void);
  216. void ak09918_factory_exit(void);
  217. #endif
  218. #if IS_ENABLED(CONFIG_LPS22HH_FACTORY)
  219. int lps22hh_pressure_factory_init(void);
  220. void lps22hh_pressure_factory_exit(void);
  221. #elif IS_ENABLED(CONFIG_PRESSURE_FACTORY)
  222. int pressure_factory_init(void);
  223. void pressure_factory_exit(void);
  224. #endif
  225. #if IS_ENABLED(CONFIG_LIGHT_FACTORY)
  226. int light_factory_init(void);
  227. void light_factory_exit(void);
  228. void light_init_work(struct adsp_data *data);
  229. void light_init_work_func(struct work_struct *work);
  230. #endif
  231. #if IS_ENABLED(CONFIG_PROX_FACTORY)
  232. int prox_factory_init(void);
  233. void prox_factory_exit(void);
  234. #endif
  235. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_6AXIS)
  236. int lsm6dso_sub_accel_factory_init(void);
  237. void lsm6dso_sub_accel_factory_exit(void);
  238. int lsm6dso_sub_gyro_factory_init(void);
  239. void lsm6dso_sub_gyro_factory_exit(void);
  240. void sub_accel_factory_init_work(struct adsp_data *data);
  241. void sub_accel_cal_work_func(struct work_struct *work);
  242. #endif
  243. #if IS_ENABLED(CONFIG_SUPPORT_AK09973)
  244. int ak09970_factory_init(void);
  245. void ak09970_factory_exit(void);
  246. void lsm6dso_selftest_stop_work_func(struct work_struct *work);
  247. #elif IS_ENABLED(CONFIG_SUPPORT_REF_ANGLE_WITHOUT_DIGITAL_HALL) || defined(CONFIG_SUPPORT_REF_ANGLE_WITHOUT_DIGITAL_HALL)
  248. void lsm6dso_selftest_stop_work_func(struct work_struct *work);
  249. #endif
  250. #if IS_ENABLED(CONFIG_SUPPORT_DEVICE_MODE)
  251. void sns_device_mode_init_work(void);
  252. void sns_flip_init_work(void);
  253. #endif
  254. #ifdef CONFIG_VBUS_NOTIFIER
  255. void sns_vbus_init_work(void);
  256. #endif
  257. #if IS_ENABLED(CONFIG_BACKTAP_FACTORY)
  258. int backtap_factory_init(void);
  259. void backtap_factory_exit(void);
  260. #endif
  261. #if IS_ENABLED(CONFIG_FLIP_COVER_DETECTOR_FACTORY)
  262. int flip_cover_detector_factory_init(void);
  263. void flip_cover_detector_factory_exit(void);
  264. #endif
  265. #if IS_ENABLED(CONFIG_SUPPORT_LIGHT_CALIBRATION)
  266. void light_cal_init_work(struct adsp_data *data);
  267. void light_cal_read_work_func(struct work_struct *work);
  268. #endif /* CONFIG_SUPPORT_LIGHT_CALIBRATION */
  269. #if IS_ENABLED(CONFIG_SUPPORT_DDI_COPR_FOR_LIGHT_SENSOR)
  270. void light_copr_debug_work_func(struct work_struct *work);
  271. #endif
  272. #if IS_ENABLED(CONFIG_SUPPORT_FIFO_DEBUG_FOR_LIGHT_SENSOR)
  273. void light_fifo_debug_work_func(struct work_struct *work);
  274. #endif
  275. #if IS_ENABLED(CONFIG_SUPPORT_PROX_CALIBRATION)
  276. void prox_cal_init_work(struct adsp_data *data);
  277. void prox_send_cal_data(struct adsp_data *data, uint16_t prox_idx, bool fac_cal);
  278. #endif
  279. #if IS_ENABLED(CONFIG_SUPPORT_PROX_POWER_ON_CAL)
  280. void prox_factory_init_work(void);
  281. #endif
  282. #if IS_ENABLED(CONFIG_SUPPORT_AK09973)
  283. void digital_hall_factory_auto_cal_init_work(struct adsp_data *data);
  284. int get_hall_angle_data(int32_t *raw_data);
  285. #endif
  286. #if IS_ENABLED(CONFIG_SUPPORT_LIGHT_SEAMLESS)
  287. void light_seamless_work_func(struct work_struct *work);
  288. void light_seamless_init_work(struct adsp_data *data);
  289. #endif
  290. #if IS_ENABLED(CONFIG_SUPPORT_DUAL_OPTIC)
  291. int get_light_sidx(struct adsp_data *data);
  292. #endif
  293. #if IS_ENABLED(CONFIG_SUPPORT_BRIGHTNESS_NOTIFY_FOR_LIGHT_SENSOR) && \
  294. IS_ENABLED(CONFIG_SEC_PANEL_NOTIFIER_V2)
  295. struct adsp_data* adsp_get_struct_data(void);
  296. void light_brightness_work_func(struct work_struct *work);
  297. #endif
  298. #if IS_ENABLED(CONFIG_SUPPORT_AK09973)
  299. void dhall_cal_work_func(struct work_struct *work);
  300. #endif
  301. void pressure_factory_init_work(struct adsp_data *data);
  302. void pressure_cal_work_func(struct work_struct *work);
  303. bool sns_check_ignore_crash(void);
  304. #endif /* __ADSP_SENSOR_H__ */