adsp.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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 <asm/uaccess.h>
  27. #define PID 20000
  28. #define NETLINK_ADSP_FAC 22
  29. #define PROX_READ_NUM 10
  30. #define SNS_REG_DATA_FILENAME "/persist/sensors/sns.reg"
  31. /* ENUMS for Selecting the current sensor being used */
  32. enum{
  33. ADSP_FACTORY_MODE_ACCEL,
  34. ADSP_FACTORY_MODE_GYRO,
  35. ADSP_FACTORY_MODE_MAG,
  36. ADSP_FACTORY_MODE_LIGHT,
  37. ADSP_FACTORY_MODE_PROX,
  38. ADSP_FACTORY_MODE_MAG_POWERNOISE_ON,
  39. ADSP_FACTORY_MODE_MAG_POWERNOISE_OFF,
  40. ADSP_FACTORY_SENSOR_MAX
  41. };
  42. enum {
  43. ADSP_RAW_ACCEL = (1 << 0), /* 0b0000000000000001 */
  44. ADSP_RAW_GYRO = (1 << 1), /* 0b0000000000000010 */
  45. ADSP_RAW_MAG = (1 << 2), /* 0b0000000000000100 */
  46. ADSP_RAW_LIGHT = (1 << 3), /* 0b0000000000001000 */
  47. ADSP_RAW_PROXY = (1 << 4), /* 0b0000000000010000 */
  48. ADSP_RAW_PRESSURE = (1 << 5), /* 0b0000000000100000 */
  49. ADSP_RAW_MAX = (1 << 8), /* 0b0000000100000000 */
  50. };
  51. enum {
  52. ADSP_DATA_NONE = (1 << 0), /* 0b0000000000000001 */
  53. ADSP_DATA_GYRO_TEMP = (1 << 1), /* 0b0000000000000010 */
  54. };
  55. //Call back command
  56. enum{
  57. CALLBACK_REGISTER_SUCCESS,
  58. CALLBACK_TIMER_EXPIRED
  59. };
  60. enum {
  61. NETLINK_ATTR_SENSOR_TYPE,
  62. NETLINK_ATTR_MAX
  63. };
  64. /* Netlink ENUMS Message Protocols */
  65. enum {
  66. NETLINK_MESSAGE_GET_RAW_DATA,
  67. NETLINK_MESSAGE_RAW_DATA_RCVD,
  68. NETLINK_MESSAGE_GET_CALIB_DATA,
  69. NETLINK_MESSAGE_CALIB_DATA_RCVD,
  70. NETLINK_MESSAGE_CALIB_STORE_DATA,
  71. NETLINK_MESSAGE_CALIB_STORE_RCVD,
  72. NETLINK_MESSAGE_SELFTEST_SHOW_DATA,
  73. NETLINK_MESSAGE_SELFTEST_SHOW_RCVD,
  74. NETLINK_MESSAGE_REACTIVE_ALERT_DATA,
  75. NETLINK_MESSAGE_REACTIVE_ALERT_RCVD,
  76. NETLINK_MESSAGE_STOP_RAW_DATA,
  77. NETLINK_MESSAGE_GYRO_TEMP,
  78. NETLINK_MESSAGE_GYRO_TEMP_RCVD,
  79. NETLINK_MESSAGE_MAG_POWERNOISE_ON,
  80. NETLINK_MESSAGE_MAG_POWERNOISE_OFF,
  81. NETLINK_MESSAGE_MAX
  82. };
  83. struct msg_data{
  84. int sensor_type;
  85. int param1;//For passing extra parameter
  86. int param2;//For passing extra parameter
  87. int param3;//For passing extra parameter
  88. };
  89. struct sensor_value {
  90. unsigned int sensor_type;
  91. union{
  92. struct {
  93. s16 x;
  94. s16 y;
  95. s16 z;
  96. };
  97. s16 reactive_alert;
  98. s16 temperature;
  99. };
  100. };
  101. struct sensor_stop_value {
  102. unsigned int sensor_type;
  103. int result;
  104. };
  105. /* Structs used in calibration show and store */
  106. struct sensor_calib_value {
  107. unsigned int sensor_type;
  108. union {
  109. struct {
  110. int x;
  111. int y;
  112. int z;
  113. };
  114. };
  115. int result;
  116. };
  117. struct sensor_calib_store_result{
  118. unsigned int sensor_type;
  119. int nCalibstoreresult;
  120. };
  121. struct trans_value{
  122. unsigned int sensor_type;
  123. };
  124. /* Struct used for selftest */
  125. struct sensor_selftest_show_result{
  126. unsigned int sensor_type;
  127. int nSelftestresult1;
  128. int nSelftestresult2;
  129. //Noice bias
  130. int bias_x;
  131. int bias_y;
  132. int bias_z;
  133. //Noice power
  134. int rms_x;
  135. int rms_y;
  136. int rms_z;
  137. //H/W selftest %
  138. int ratio_x;
  139. int ratio_x_dec;
  140. int ratio_y;
  141. int ratio_y_dec;
  142. int ratio_z;
  143. int ratio_z_dec;
  144. //H/W packet count %
  145. int st_x;
  146. int st_y;
  147. int st_z;
  148. /* FOR YAS532 */
  149. /* DEV_ID */
  150. int id;
  151. /* DIRECTION */
  152. int dir;
  153. /* OFFSET */
  154. int offset_x;
  155. int offset_y;
  156. int offset_z;
  157. /* SENSITIVITY */
  158. int sx;
  159. int sy;
  160. /* OFFSET H */
  161. int ohx;
  162. int ohy;
  163. int ohz;
  164. };
  165. /* Main struct containing all the data */
  166. struct adsp_data {
  167. struct device *adsp;
  168. struct device *sensor_device[ADSP_FACTORY_SENSOR_MAX];
  169. struct sensor_value sensor_data[ADSP_FACTORY_SENSOR_MAX];
  170. struct sensor_calib_value sensor_calib_data[ADSP_FACTORY_SENSOR_MAX];
  171. struct sensor_calib_store_result sensor_calib_result[ADSP_FACTORY_SENSOR_MAX];
  172. struct sensor_selftest_show_result sensor_selftest_result[ADSP_FACTORY_SENSOR_MAX];
  173. struct sensor_stop_value sensor_stop_data[ADSP_FACTORY_SENSOR_MAX];
  174. struct adsp_fac_ctl *ctl[ADSP_FACTORY_SENSOR_MAX];
  175. uint8_t reactive_alert;
  176. uint8_t gyro_temp;
  177. struct sock *adsp_skt;
  178. unsigned int alert_ready_flag;
  179. unsigned int data_ready_flag;
  180. unsigned int calib_ready_flag;
  181. unsigned int calib_store_ready_flag;
  182. unsigned int selftest_ready_flag;
  183. unsigned int data_ready;
  184. struct timer_list command_timer;
  185. int prox_average[PROX_READ_NUM];
  186. };
  187. struct adsp_fac_ctl {
  188. int (*init_fnc) (struct adsp_data *data);
  189. int (*exit_fnc) (struct adsp_data *data);
  190. int (*receive_data_fnc) (struct adsp_data *data, int cmd );
  191. };
  192. int adsp_factory_register( char *dev_name,int type, struct device_attribute *attributes[],struct adsp_fac_ctl *fact_ctl );
  193. int adsp_unicast( struct msg_data param , int message, int flags, u32 pid);
  194. int adsp_factory_start_timer( const unsigned int ms );
  195. extern struct mutex factory_mutex;
  196. #endif