ssp_input.c 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428
  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. #include "ssp.h"
  16. #include "../../staging/iio/iio.h"
  17. #include "../../staging/iio/events.h"
  18. #include "../../staging/iio/sysfs.h"
  19. #include "../../staging/iio/buffer.h"
  20. #include "../../staging/iio/types.h"
  21. /*************************************************************************/
  22. /* SSP Kernel -> HAL input evnet function */
  23. /*************************************************************************/
  24. #define IIO_BUFFER_12_BYTES 20 /* 12 + timestamp 8*/
  25. #define IIO_BUFFER_6_BYTES 14
  26. #define IIO_BUFFER_1_BYTES 9
  27. #define IIO_BUFFER_17_BYTES 25
  28. /* data header defines */
  29. static int ssp_push_17bytes_buffer(struct iio_dev *indio_dev,
  30. u64 t, int *q)
  31. {
  32. u8 buf[IIO_BUFFER_17_BYTES];
  33. int i;
  34. for (i = 0; i < 4; i++)
  35. memcpy(buf + 4 * i, &q[i], sizeof(q[i]));
  36. buf[16] = (u8)q[5];
  37. memcpy(buf + 17, &t, sizeof(t));
  38. mutex_lock(&indio_dev->mlock);
  39. iio_push_to_buffer(indio_dev->buffer, buf, 0);
  40. mutex_unlock(&indio_dev->mlock);
  41. return 0;
  42. }
  43. static int ssp_push_12bytes_buffer(struct iio_dev *indio_dev, u64 t,
  44. int *q)
  45. {
  46. u8 buf[IIO_BUFFER_12_BYTES];
  47. int i;
  48. for (i = 0; i < 3; i++)
  49. memcpy(buf + 4 * i, &q[i], sizeof(q[i]));
  50. memcpy(buf + 12, &t, sizeof(t));
  51. mutex_lock(&indio_dev->mlock);
  52. iio_push_to_buffer(indio_dev->buffer, buf, 0);
  53. mutex_unlock(&indio_dev->mlock);
  54. return 0;
  55. }
  56. static int ssp_push_6bytes_buffer(struct iio_dev *indio_dev,
  57. u64 t, s16 *d)
  58. {
  59. u8 buf[IIO_BUFFER_6_BYTES];
  60. int i;
  61. for (i = 0; i < 3; i++)
  62. memcpy(buf + i * 2, &d[i], sizeof(d[i]));
  63. memcpy(buf + 6, &t, sizeof(t));
  64. mutex_lock(&indio_dev->mlock);
  65. iio_push_to_buffer(indio_dev->buffer, buf, 0);
  66. mutex_unlock(&indio_dev->mlock);
  67. return 0;
  68. }
  69. static int ssp_push_1bytes_buffer(struct iio_dev *indio_dev,
  70. u64 t, u8 *d)
  71. {
  72. u8 buf[IIO_BUFFER_1_BYTES];
  73. memcpy(buf, d, sizeof(u8));
  74. memcpy(buf + 1, &t, sizeof(t));
  75. mutex_lock(&indio_dev->mlock);
  76. iio_push_to_buffer(indio_dev->buffer, buf, 0);
  77. mutex_unlock(&indio_dev->mlock);
  78. return 0;
  79. }
  80. void convert_acc_data(s16 *iValue)
  81. {
  82. if (*iValue > MAX_ACCEL_2G)
  83. *iValue = ((MAX_ACCEL_4G - *iValue)) * (-1);
  84. }
  85. void report_acc_data(struct ssp_data *data, struct sensor_value *accdata)
  86. {
  87. s16 accel_buf[3];
  88. data->buf[ACCELEROMETER_SENSOR].x = accdata->x;
  89. data->buf[ACCELEROMETER_SENSOR].y = accdata->y;
  90. data->buf[ACCELEROMETER_SENSOR].z = accdata->z;
  91. accel_buf[0] = data->buf[ACCELEROMETER_SENSOR].x;
  92. accel_buf[1] = data->buf[ACCELEROMETER_SENSOR].y;
  93. accel_buf[2] = data->buf[ACCELEROMETER_SENSOR].z;
  94. ssp_push_6bytes_buffer(data->accel_indio_dev, accdata->timestamp,
  95. accel_buf);
  96. }
  97. void report_meta_data(struct ssp_data *data, struct sensor_value *s)
  98. {
  99. input_report_rel(data->meta_input_dev, REL_DIAL, s->meta_data.what);
  100. input_report_rel(data->meta_input_dev, REL_HWHEEL, s->meta_data.sensor + 1);
  101. input_sync(data->meta_input_dev);
  102. }
  103. void report_gyro_data(struct ssp_data *data, struct sensor_value *gyrodata)
  104. {
  105. int lTemp[3] = {0,};
  106. data->buf[GYROSCOPE_SENSOR].x = gyrodata->x;
  107. data->buf[GYROSCOPE_SENSOR].y = gyrodata->y;
  108. data->buf[GYROSCOPE_SENSOR].z = gyrodata->z;
  109. if (data->uGyroDps == GYROSCOPE_DPS500) {
  110. lTemp[0] = (int)data->buf[GYROSCOPE_SENSOR].x;
  111. lTemp[1] = (int)data->buf[GYROSCOPE_SENSOR].y;
  112. lTemp[2] = (int)data->buf[GYROSCOPE_SENSOR].z;
  113. } else if (data->uGyroDps == GYROSCOPE_DPS250) {
  114. lTemp[0] = (int)data->buf[GYROSCOPE_SENSOR].x >> 1;
  115. lTemp[1] = (int)data->buf[GYROSCOPE_SENSOR].y >> 1;
  116. lTemp[2] = (int)data->buf[GYROSCOPE_SENSOR].z >> 1;
  117. } else if (data->uGyroDps == GYROSCOPE_DPS2000) {
  118. lTemp[0] = (int)data->buf[GYROSCOPE_SENSOR].x << 2;
  119. lTemp[1] = (int)data->buf[GYROSCOPE_SENSOR].y << 2;
  120. lTemp[2] = (int)data->buf[GYROSCOPE_SENSOR].z << 2;
  121. } else {
  122. lTemp[0] = (int)data->buf[GYROSCOPE_SENSOR].x;
  123. lTemp[1] = (int)data->buf[GYROSCOPE_SENSOR].y;
  124. lTemp[2] = (int)data->buf[GYROSCOPE_SENSOR].z;
  125. }
  126. ssp_push_12bytes_buffer(data->gyro_indio_dev, gyrodata->timestamp,
  127. lTemp);
  128. }
  129. void report_geomagnetic_raw_data(struct ssp_data *data,
  130. struct sensor_value *magrawdata)
  131. {
  132. data->buf[GEOMAGNETIC_RAW].x = magrawdata->x;
  133. data->buf[GEOMAGNETIC_RAW].y = magrawdata->y;
  134. data->buf[GEOMAGNETIC_RAW].z = magrawdata->z;
  135. }
  136. void report_mag_data(struct ssp_data *data, struct sensor_value *magdata)
  137. {
  138. #ifdef SAVE_MAG_LOG
  139. s16 arrTemp[9] = {0, };
  140. arrTemp[0] = magdata->log_data[0]; // ST1 Reg
  141. arrTemp[1] = (short)((magdata->log_data[3] << 8) +\
  142. magdata->log_data[2]);
  143. arrTemp[2] = (short)((magdata->log_data[5] << 8) +\
  144. magdata->log_data[4]);
  145. arrTemp[3] = (short)((magdata->log_data[7] << 8) +\
  146. magdata->log_data[6]);
  147. arrTemp[4] = magdata->log_data[1]; // ST2 Reg
  148. arrTemp[5] = (short)((magdata->log_data[9] << 8) +\
  149. magdata->log_data[8]);
  150. arrTemp[6] = (short)((magdata->log_data[11] << 8) +\
  151. magdata->log_data[10]);
  152. arrTemp[7] = (short)((magdata->log_data[13] << 8) +\
  153. magdata->log_data[12]);
  154. /* We report data & register to HAL only when ST1 register sets to 1 */
  155. if (arrTemp[0] == 1) {
  156. input_report_rel(data->mag_input_dev, REL_X, arrTemp[0] + 1);
  157. input_report_rel(data->mag_input_dev, REL_Y, arrTemp[1]);
  158. input_report_rel(data->mag_input_dev, REL_Z, arrTemp[2]);
  159. input_report_rel(data->mag_input_dev, REL_RX, arrTemp[3]);
  160. input_report_rel(data->mag_input_dev, REL_RY, arrTemp[4] + 1);
  161. input_report_rel(data->mag_input_dev, REL_RZ, arrTemp[5]);
  162. input_report_rel(data->mag_input_dev, REL_HWHEEL, arrTemp[6]);
  163. input_report_rel(data->mag_input_dev, REL_DIAL, arrTemp[7]);
  164. mdelay(5);
  165. input_sync(data->mag_input_dev);
  166. } else {
  167. pr_info("[SSP] %s, not initialised, val = %d", __func__, arrTemp[0]);
  168. }
  169. #else
  170. data->buf[GEOMAGNETIC_SENSOR].cal_x = magdata->cal_x;
  171. data->buf[GEOMAGNETIC_SENSOR].cal_y = magdata->cal_y;
  172. data->buf[GEOMAGNETIC_SENSOR].cal_z = magdata->cal_z;
  173. data->buf[GEOMAGNETIC_SENSOR].accuracy = magdata->accuracy;
  174. input_report_rel(data->mag_input_dev, REL_RX,
  175. data->buf[GEOMAGNETIC_SENSOR].cal_x);
  176. input_report_rel(data->mag_input_dev, REL_RY,
  177. data->buf[GEOMAGNETIC_SENSOR].cal_y);
  178. input_report_rel(data->mag_input_dev, REL_RZ,
  179. data->buf[GEOMAGNETIC_SENSOR].cal_z);
  180. input_report_rel(data->mag_input_dev, REL_HWHEEL,
  181. data->buf[GEOMAGNETIC_SENSOR].accuracy + 1);
  182. input_sync(data->mag_input_dev);
  183. #endif
  184. }
  185. void report_mag_uncaldata(struct ssp_data *data, struct sensor_value *magdata)
  186. {
  187. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_x = magdata->uncal_x;
  188. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_y = magdata->uncal_y;
  189. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_z = magdata->uncal_z;
  190. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_x= magdata->offset_x;
  191. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_y= magdata->offset_y;
  192. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_z= magdata->offset_z;
  193. input_report_rel(data->uncal_mag_input_dev, REL_RX,
  194. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_x);
  195. input_report_rel(data->uncal_mag_input_dev, REL_RY,
  196. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_y);
  197. input_report_rel(data->uncal_mag_input_dev, REL_RZ,
  198. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].uncal_z);
  199. input_report_rel(data->uncal_mag_input_dev, REL_HWHEEL,
  200. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_x);
  201. input_report_rel(data->uncal_mag_input_dev, REL_DIAL,
  202. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_y);
  203. input_report_rel(data->uncal_mag_input_dev, REL_WHEEL,
  204. data->buf[GEOMAGNETIC_UNCALIB_SENSOR].offset_z);
  205. input_sync(data->uncal_mag_input_dev);
  206. }
  207. void report_uncalib_gyro_data(struct ssp_data *data, struct sensor_value *gyrodata)
  208. {
  209. data->buf[GYRO_UNCALIB_SENSOR].uncal_x = gyrodata->uncal_x;
  210. data->buf[GYRO_UNCALIB_SENSOR].uncal_y = gyrodata->uncal_y;
  211. data->buf[GYRO_UNCALIB_SENSOR].uncal_z = gyrodata->uncal_z;
  212. data->buf[GYRO_UNCALIB_SENSOR].offset_x = gyrodata->offset_x;
  213. data->buf[GYRO_UNCALIB_SENSOR].offset_y = gyrodata->offset_y;
  214. data->buf[GYRO_UNCALIB_SENSOR].offset_z = gyrodata->offset_z;
  215. input_report_rel(data->uncalib_gyro_input_dev, REL_X,
  216. data->buf[GYRO_UNCALIB_SENSOR].uncal_x);
  217. input_report_rel(data->uncalib_gyro_input_dev, REL_Y,
  218. data->buf[GYRO_UNCALIB_SENSOR].uncal_y);
  219. input_report_rel(data->uncalib_gyro_input_dev, REL_Z,
  220. data->buf[GYRO_UNCALIB_SENSOR].uncal_z);
  221. input_report_rel(data->uncalib_gyro_input_dev, REL_RX,
  222. data->buf[GYRO_UNCALIB_SENSOR].offset_x);
  223. input_report_rel(data->uncalib_gyro_input_dev, REL_RY,
  224. data->buf[GYRO_UNCALIB_SENSOR].offset_y);
  225. input_report_rel(data->uncalib_gyro_input_dev, REL_RZ,
  226. data->buf[GYRO_UNCALIB_SENSOR].offset_z);
  227. input_sync(data->uncalib_gyro_input_dev);
  228. }
  229. void report_sig_motion_data(struct ssp_data *data,
  230. struct sensor_value *sig_motion_data)
  231. {
  232. data->buf[SIG_MOTION_SENSOR].sig_motion = sig_motion_data->sig_motion;
  233. input_report_rel(data->sig_motion_input_dev, REL_MISC,
  234. data->buf[SIG_MOTION_SENSOR].sig_motion);
  235. input_sync(data->sig_motion_input_dev);
  236. }
  237. void report_rot_data(struct ssp_data *data, struct sensor_value *rotdata)
  238. {
  239. int rot_buf[5];
  240. data->buf[ROTATION_VECTOR].quat_a = rotdata->quat_a;
  241. data->buf[ROTATION_VECTOR].quat_b = rotdata->quat_b;
  242. data->buf[ROTATION_VECTOR].quat_c = rotdata->quat_c;
  243. data->buf[ROTATION_VECTOR].quat_d = rotdata->quat_d;
  244. data->buf[ROTATION_VECTOR].acc_rot = rotdata->acc_rot;
  245. rot_buf[0] = rotdata->quat_a;
  246. rot_buf[1] = rotdata->quat_b;
  247. rot_buf[2] = rotdata->quat_c;
  248. rot_buf[3] = rotdata->quat_d;
  249. rot_buf[4] = rotdata->acc_rot;
  250. ssp_push_17bytes_buffer(data->rot_indio_dev, rotdata->timestamp, rot_buf);
  251. }
  252. void report_game_rot_data(struct ssp_data *data, struct sensor_value *grotdata)
  253. {
  254. int rot_buf[5];
  255. data->buf[GAME_ROTATION_VECTOR].quat_a = grotdata->quat_a;
  256. data->buf[GAME_ROTATION_VECTOR].quat_b = grotdata->quat_b;
  257. data->buf[GAME_ROTATION_VECTOR].quat_c = grotdata->quat_c;
  258. data->buf[GAME_ROTATION_VECTOR].quat_d = grotdata->quat_d;
  259. data->buf[GAME_ROTATION_VECTOR].acc_rot = grotdata->acc_rot;
  260. rot_buf[0] = grotdata->quat_a;
  261. rot_buf[1] = grotdata->quat_b;
  262. rot_buf[2] = grotdata->quat_c;
  263. rot_buf[3] = grotdata->quat_d;
  264. rot_buf[4] = grotdata->acc_rot;
  265. ssp_push_17bytes_buffer(data->game_rot_indio_dev, grotdata->timestamp,
  266. rot_buf);
  267. }
  268. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  269. defined(CONFIG_SENSORS_SSP_MAX88920)
  270. void report_gesture_data(struct ssp_data *data, struct sensor_value *gesdata)
  271. {
  272. int i = 0;
  273. for (i=0; i<20; i++) {
  274. data->buf[GESTURE_SENSOR].data[i] = gesdata->data[i];
  275. }
  276. input_report_abs(data->gesture_input_dev,
  277. ABS_X, data->buf[GESTURE_SENSOR].data[0]);
  278. input_report_abs(data->gesture_input_dev,
  279. ABS_Y, data->buf[GESTURE_SENSOR].data[1]);
  280. input_report_abs(data->gesture_input_dev,
  281. ABS_Z, data->buf[GESTURE_SENSOR].data[2]);
  282. input_report_abs(data->gesture_input_dev,
  283. ABS_RX, data->buf[GESTURE_SENSOR].data[3]);
  284. input_report_abs(data->gesture_input_dev,
  285. ABS_RY, data->buf[GESTURE_SENSOR].data[4]);
  286. input_report_abs(data->gesture_input_dev,
  287. ABS_RZ, data->buf[GESTURE_SENSOR].data[5]);
  288. input_report_abs(data->gesture_input_dev,
  289. ABS_THROTTLE, data->buf[GESTURE_SENSOR].data[6]);
  290. input_report_abs(data->gesture_input_dev,
  291. ABS_RUDDER, data->buf[GESTURE_SENSOR].data[7]);
  292. input_report_abs(data->gesture_input_dev,
  293. ABS_WHEEL, data->buf[GESTURE_SENSOR].data[8]);
  294. input_report_abs(data->gesture_input_dev,
  295. ABS_GAS, data->buf[GESTURE_SENSOR].data[9]);
  296. input_report_abs(data->gesture_input_dev,
  297. ABS_BRAKE, data->buf[GESTURE_SENSOR].data[10]);
  298. input_report_abs(data->gesture_input_dev,
  299. ABS_HAT0X, data->buf[GESTURE_SENSOR].data[11]);
  300. input_report_abs(data->gesture_input_dev,
  301. ABS_HAT0Y, data->buf[GESTURE_SENSOR].data[12]);
  302. input_report_abs(data->gesture_input_dev,
  303. ABS_HAT1X, data->buf[GESTURE_SENSOR].data[13]);
  304. input_report_abs(data->gesture_input_dev,
  305. ABS_HAT1Y, data->buf[GESTURE_SENSOR].data[14]);
  306. input_report_abs(data->gesture_input_dev,
  307. ABS_HAT2X, data->buf[GESTURE_SENSOR].data[15]);
  308. input_report_abs(data->gesture_input_dev,
  309. ABS_HAT2Y, data->buf[GESTURE_SENSOR].data[16]);
  310. input_report_abs(data->gesture_input_dev,
  311. ABS_HAT3X, data->buf[GESTURE_SENSOR].data[17]);
  312. input_report_abs(data->gesture_input_dev,
  313. ABS_HAT3Y, data->buf[GESTURE_SENSOR].data[18]);
  314. input_report_abs(data->gesture_input_dev,
  315. ABS_PRESSURE, data->buf[GESTURE_SENSOR].data[19]);
  316. input_sync(data->gesture_input_dev);
  317. }
  318. #endif
  319. #ifdef CONFIG_SENSORS_SSP_BMP182
  320. void report_pressure_data(struct ssp_data *data, struct sensor_value *predata)
  321. {
  322. int temp[3] = {0, };
  323. data->buf[PRESSURE_SENSOR].pressure[0] =
  324. predata->pressure[0] - data->iPressureCal;
  325. data->buf[PRESSURE_SENSOR].pressure[1] = predata->pressure[1];
  326. temp[0] = data->buf[PRESSURE_SENSOR].pressure[0];
  327. temp[1] = data->buf[PRESSURE_SENSOR].pressure[1];
  328. temp[2] = data->sealevelpressure;
  329. ssp_push_12bytes_buffer(data->pressure_indio_dev, predata->timestamp,
  330. temp);
  331. }
  332. #endif
  333. void report_light_data(struct ssp_data *data, struct sensor_value *lightdata)
  334. {
  335. data->buf[LIGHT_SENSOR].r = lightdata->r;
  336. data->buf[LIGHT_SENSOR].g = lightdata->g;
  337. data->buf[LIGHT_SENSOR].b = lightdata->b;
  338. data->buf[LIGHT_SENSOR].w = lightdata->w;
  339. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_TMD37823)
  340. data->buf[LIGHT_SENSOR].a_time = lightdata->a_time;
  341. data->buf[LIGHT_SENSOR].a_gain = (0x03) & (lightdata->a_gain);
  342. #endif
  343. input_report_rel(data->light_input_dev, REL_HWHEEL,
  344. data->buf[LIGHT_SENSOR].r + 1);
  345. input_report_rel(data->light_input_dev, REL_DIAL,
  346. data->buf[LIGHT_SENSOR].g + 1);
  347. input_report_rel(data->light_input_dev, REL_WHEEL,
  348. data->buf[LIGHT_SENSOR].b + 1);
  349. input_report_rel(data->light_input_dev, REL_MISC,
  350. data->buf[LIGHT_SENSOR].w + 1);
  351. #ifdef CONFIG_SENSORS_SSP_TMG399X
  352. input_report_rel(data->light_input_dev, REL_RY,
  353. data->buf[LIGHT_SENSOR].a_time + 1);
  354. input_report_rel(data->light_input_dev, REL_RZ,
  355. data->buf[LIGHT_SENSOR].a_gain + 1);
  356. #endif
  357. input_sync(data->light_input_dev);
  358. }
  359. void report_prox_data(struct ssp_data *data, struct sensor_value *proxdata)
  360. {
  361. ssp_dbg("[SSP] Proximity Sensor Detect : %u, raw : %u, thd(%u, %u)\n",
  362. proxdata->prox[0], proxdata->prox[1],
  363. data->uProxHiThresh, data->uProxLoThresh);
  364. data->buf[PROXIMITY_SENSOR].prox[0] = proxdata->prox[0];
  365. data->buf[PROXIMITY_SENSOR].prox[1] = proxdata->prox[1];
  366. input_report_abs(data->prox_input_dev, ABS_DISTANCE,
  367. (!proxdata->prox[0]));
  368. input_sync(data->prox_input_dev);
  369. wake_lock_timeout(&data->ssp_wake_lock, 3 * HZ);
  370. }
  371. void report_prox_raw_data(struct ssp_data *data,
  372. struct sensor_value *proxrawdata)
  373. {
  374. if (data->uFactoryProxAvg[0]++ >= PROX_AVG_READ_NUM) {
  375. data->uFactoryProxAvg[2] /= PROX_AVG_READ_NUM;
  376. data->buf[PROXIMITY_RAW].prox[1] = (u16)data->uFactoryProxAvg[1];
  377. data->buf[PROXIMITY_RAW].prox[2] = (u16)data->uFactoryProxAvg[2];
  378. data->buf[PROXIMITY_RAW].prox[3] = (u16)data->uFactoryProxAvg[3];
  379. data->uFactoryProxAvg[0] = 0;
  380. data->uFactoryProxAvg[1] = 0;
  381. data->uFactoryProxAvg[2] = 0;
  382. data->uFactoryProxAvg[3] = 0;
  383. } else {
  384. data->uFactoryProxAvg[2] += proxrawdata->prox[0];
  385. if (data->uFactoryProxAvg[0] == 1)
  386. data->uFactoryProxAvg[1] = proxrawdata->prox[0];
  387. else if (proxrawdata->prox[0] < data->uFactoryProxAvg[1])
  388. data->uFactoryProxAvg[1] = proxrawdata->prox[0];
  389. if (proxrawdata->prox[0] > data->uFactoryProxAvg[3])
  390. data->uFactoryProxAvg[3] = proxrawdata->prox[0];
  391. }
  392. data->buf[PROXIMITY_RAW].prox[0] = proxrawdata->prox[0];
  393. }
  394. void report_step_det_data(struct ssp_data *data,
  395. struct sensor_value *sig_motion_data)
  396. {
  397. data->buf[STEP_DETECTOR].step_det = sig_motion_data->step_det;
  398. ssp_push_1bytes_buffer(data->step_det_indio_dev, sig_motion_data->timestamp,
  399. &sig_motion_data->step_det);
  400. }
  401. void report_step_cnt_data(struct ssp_data *data,
  402. struct sensor_value *sig_motion_data)
  403. {
  404. data->buf[STEP_COUNTER].step_diff = sig_motion_data->step_diff;
  405. data->step_count_total += data->buf[STEP_COUNTER].step_diff;
  406. input_report_rel(data->step_cnt_input_dev, REL_MISC,
  407. data->step_count_total + 1);
  408. input_sync(data->step_cnt_input_dev);
  409. }
  410. #ifdef CONFIG_SENSORS_SSP_SHTC1
  411. void report_temp_humidity_data(struct ssp_data *data,
  412. struct sensor_value *temp_humi_data)
  413. {
  414. data->buf[TEMPERATURE_HUMIDITY_SENSOR].x = temp_humi_data->x;
  415. data->buf[TEMPERATURE_HUMIDITY_SENSOR].y = temp_humi_data->y;
  416. data->buf[TEMPERATURE_HUMIDITY_SENSOR].z = temp_humi_data->z;
  417. /* Temperature */
  418. input_report_rel(data->temp_humi_input_dev, REL_HWHEEL,
  419. data->buf[TEMPERATURE_HUMIDITY_SENSOR].x);
  420. /* Humidity */
  421. input_report_rel(data->temp_humi_input_dev, REL_DIAL,
  422. data->buf[TEMPERATURE_HUMIDITY_SENSOR].y);
  423. input_sync(data->temp_humi_input_dev);
  424. if (data->buf[TEMPERATURE_HUMIDITY_SENSOR].z)
  425. wake_lock_timeout(&data->ssp_wake_lock, 2 * HZ);
  426. }
  427. #endif
  428. #ifdef CONFIG_SENSORS_SSP_UVIS25
  429. void report_uv_data(struct ssp_data *data,
  430. struct sensor_value *uv_data)
  431. {
  432. data->buf[UV_SENSOR].uv = uv_data->uv;
  433. input_report_rel(data->uv_input_dev, REL_MISC,
  434. data->buf[UV_SENSOR].uv + 1);
  435. input_sync(data->uv_input_dev);
  436. }
  437. #endif
  438. #ifdef CONFIG_SENSORS_SSP_SHTC1
  439. void report_bulk_comp_data(struct ssp_data *data)
  440. {
  441. input_report_rel(data->temp_humi_input_dev, REL_WHEEL,
  442. data->bulk_buffer->len);
  443. input_sync(data->temp_humi_input_dev);
  444. }
  445. #endif
  446. int initialize_event_symlink(struct ssp_data *data)
  447. {
  448. int iRet = 0;
  449. data->sen_dev = device_create(sensors_event_class, NULL, 0, NULL,
  450. "%s", "symlink");
  451. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  452. defined(CONFIG_SENSORS_SSP_MAX88920)
  453. iRet = sysfs_create_link(&data->sen_dev->kobj,
  454. &data->gesture_input_dev->dev.kobj,
  455. data->gesture_input_dev->name);
  456. if (iRet < 0)
  457. goto iRet_gesture_sysfs_create_link;
  458. #endif
  459. iRet = sysfs_create_link(&data->sen_dev->kobj,
  460. &data->light_input_dev->dev.kobj,
  461. data->light_input_dev->name);
  462. if (iRet < 0)
  463. goto iRet_light_sysfs_create_link;
  464. iRet = sysfs_create_link(&data->sen_dev->kobj,
  465. &data->prox_input_dev->dev.kobj,
  466. data->prox_input_dev->name);
  467. if (iRet < 0)
  468. goto iRet_prox_sysfs_create_link;
  469. #ifdef CONFIG_SENSORS_SSP_SHTC1
  470. iRet = sysfs_create_link(&data->sen_dev->kobj,
  471. &data->temp_humi_input_dev->dev.kobj,
  472. data->temp_humi_input_dev->name);
  473. if (iRet < 0)
  474. goto iRet_temp_humi_sysfs_create_link;
  475. #endif
  476. #ifdef CONFIG_SENSORS_SSP_UVIS25
  477. iRet = sysfs_create_link(&data->sen_dev->kobj,
  478. &data->uv_input_dev->dev.kobj,
  479. data->uv_input_dev->name);
  480. if (iRet < 0)
  481. goto iRet_uv_sysfs_create_link;
  482. #endif
  483. iRet = sysfs_create_link(&data->sen_dev->kobj,
  484. &data->mag_input_dev->dev.kobj,
  485. data->mag_input_dev->name);
  486. if (iRet < 0)
  487. goto iRet_mag_sysfs_create_link;
  488. iRet = sysfs_create_link(&data->sen_dev->kobj,
  489. &data->uncal_mag_input_dev->dev.kobj,
  490. data->uncal_mag_input_dev->name);
  491. if (iRet < 0)
  492. goto iRet_uncal_mag_sysfs_create_link;
  493. iRet = sysfs_create_link(&data->sen_dev->kobj,
  494. &data->sig_motion_input_dev->dev.kobj,
  495. data->sig_motion_input_dev->name);
  496. if (iRet < 0)
  497. goto iRet_sig_motion_sysfs_create_link;
  498. iRet = sysfs_create_link(&data->sen_dev->kobj,
  499. &data->uncalib_gyro_input_dev->dev.kobj,
  500. data->uncalib_gyro_input_dev->name);
  501. if (iRet < 0)
  502. goto iRet_uncalib_gyro_sysfs_create_link;
  503. iRet = sysfs_create_link(&data->sen_dev->kobj,
  504. &data->step_cnt_input_dev->dev.kobj,
  505. data->step_cnt_input_dev->name);
  506. if (iRet < 0)
  507. goto iRet_step_cnt_sysfs_create_link;
  508. iRet = sysfs_create_link(&data->sen_dev->kobj,
  509. &data->meta_input_dev->dev.kobj,
  510. data->meta_input_dev->name);
  511. if (iRet < 0)
  512. goto iRet_meta_sysfs_create_link;
  513. return SUCCESS;
  514. iRet_meta_sysfs_create_link:
  515. sysfs_delete_link(&data->sen_dev->kobj,
  516. &data->step_cnt_input_dev->dev.kobj,
  517. data->step_cnt_input_dev->name);
  518. iRet_step_cnt_sysfs_create_link:
  519. sysfs_delete_link(&data->sen_dev->kobj,
  520. &data->uncalib_gyro_input_dev->dev.kobj,
  521. data->uncalib_gyro_input_dev->name);
  522. iRet_uncalib_gyro_sysfs_create_link:
  523. sysfs_delete_link(&data->sen_dev->kobj,
  524. &data->sig_motion_input_dev->dev.kobj,
  525. data->sig_motion_input_dev->name);
  526. iRet_sig_motion_sysfs_create_link:
  527. sysfs_delete_link(&data->sen_dev->kobj,
  528. &data->uncal_mag_input_dev->dev.kobj,
  529. data->uncal_mag_input_dev->name);
  530. iRet_uncal_mag_sysfs_create_link:
  531. sysfs_delete_link(&data->sen_dev->kobj,
  532. &data->mag_input_dev->dev.kobj,
  533. data->mag_input_dev->name);
  534. iRet_mag_sysfs_create_link:
  535. #ifdef CONFIG_SENSORS_SSP_UVIS25
  536. sysfs_delete_link(&data->sen_dev->kobj,
  537. &data->uv_input_dev->dev.kobj,
  538. data->uv_input_dev->name);
  539. iRet_uv_sysfs_create_link:
  540. #endif
  541. #ifdef CONFIG_SENSORS_SSP_SHTC1
  542. sysfs_delete_link(&data->sen_dev->kobj,
  543. &data->temp_humi_input_dev->dev.kobj,
  544. data->temp_humi_input_dev->name);
  545. iRet_temp_humi_sysfs_create_link:
  546. #endif
  547. sysfs_delete_link(&data->sen_dev->kobj,
  548. &data->prox_input_dev->dev.kobj,
  549. data->prox_input_dev->name);
  550. iRet_prox_sysfs_create_link:
  551. sysfs_delete_link(&data->sen_dev->kobj,
  552. &data->light_input_dev->dev.kobj,
  553. data->light_input_dev->name);
  554. iRet_light_sysfs_create_link:
  555. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  556. defined(CONFIG_SENSORS_SSP_MAX88920)
  557. sysfs_delete_link(&data->sen_dev->kobj,
  558. &data->gesture_input_dev->dev.kobj,
  559. data->gesture_input_dev->name);
  560. iRet_gesture_sysfs_create_link:
  561. #endif
  562. pr_err("[SSP]: %s - could not create event symlink\n", __func__);
  563. return FAIL;
  564. }
  565. void remove_event_symlink(struct ssp_data *data)
  566. {
  567. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  568. defined(CONFIG_SENSORS_SSP_MAX88920)
  569. sysfs_delete_link(&data->sen_dev->kobj,
  570. &data->gesture_input_dev->dev.kobj,
  571. data->gesture_input_dev->name);
  572. #endif
  573. sysfs_delete_link(&data->sen_dev->kobj,
  574. &data->light_input_dev->dev.kobj,
  575. data->light_input_dev->name);
  576. sysfs_delete_link(&data->sen_dev->kobj,
  577. &data->prox_input_dev->dev.kobj,
  578. data->prox_input_dev->name);
  579. #ifdef CONFIG_SENSORS_SSP_SHTC1
  580. sysfs_delete_link(&data->sen_dev->kobj,
  581. &data->temp_humi_input_dev->dev.kobj,
  582. data->temp_humi_input_dev->name);
  583. #endif
  584. #ifdef CONFIG_SENSORS_SSP_UVIS25
  585. sysfs_delete_link(&data->sen_dev->kobj,
  586. &data->uv_input_dev->dev.kobj,
  587. data->uv_input_dev->name);
  588. #endif
  589. sysfs_delete_link(&data->sen_dev->kobj,
  590. &data->mag_input_dev->dev.kobj,
  591. data->mag_input_dev->name);
  592. sysfs_delete_link(&data->sen_dev->kobj,
  593. &data->uncal_mag_input_dev->dev.kobj,
  594. data->uncal_mag_input_dev->name);
  595. sysfs_delete_link(&data->sen_dev->kobj,
  596. &data->sig_motion_input_dev->dev.kobj,
  597. data->sig_motion_input_dev->name);
  598. sysfs_delete_link(&data->sen_dev->kobj,
  599. &data->uncalib_gyro_input_dev->dev.kobj,
  600. data->uncalib_gyro_input_dev->name);
  601. sysfs_delete_link(&data->sen_dev->kobj,
  602. &data->step_cnt_input_dev->dev.kobj,
  603. data->step_cnt_input_dev->name);
  604. sysfs_delete_link(&data->sen_dev->kobj,
  605. &data->meta_input_dev->dev.kobj,
  606. data->meta_input_dev->name);
  607. }
  608. static const struct iio_info accel_info = {
  609. .driver_module = THIS_MODULE,
  610. };
  611. static const struct iio_chan_spec accel_channels[] = {
  612. {
  613. .type = IIO_TIMESTAMP,
  614. .channel = -1,
  615. .scan_index = 3,
  616. .scan_type = IIO_ST('s', IIO_BUFFER_6_BYTES * 8,
  617. IIO_BUFFER_6_BYTES * 8, 0)
  618. }
  619. };
  620. static const struct iio_info gyro_info = {
  621. .driver_module = THIS_MODULE,
  622. };
  623. static const struct iio_chan_spec gyro_channels[] = {
  624. {
  625. .type = IIO_TIMESTAMP,
  626. .channel = -1,
  627. .scan_index = 3,
  628. .scan_type = IIO_ST('s', IIO_BUFFER_12_BYTES * 8,
  629. IIO_BUFFER_12_BYTES * 8, 0)
  630. }
  631. };
  632. static const struct iio_info game_rot_info = {
  633. .driver_module = THIS_MODULE,
  634. };
  635. static const struct iio_chan_spec game_rot_channels[] = {
  636. {
  637. .type = IIO_TIMESTAMP,
  638. .channel = -1,
  639. .scan_index = 3,
  640. .scan_type = IIO_ST('s', IIO_BUFFER_17_BYTES * 8,
  641. IIO_BUFFER_17_BYTES * 8, 0)
  642. }
  643. };
  644. static const struct iio_info rot_info = {
  645. .driver_module = THIS_MODULE,
  646. };
  647. static const struct iio_chan_spec rot_channels[] = {
  648. {
  649. .type = IIO_TIMESTAMP,
  650. .channel = -1,
  651. .scan_index = 3,
  652. .scan_type = IIO_ST('s', IIO_BUFFER_17_BYTES * 8,
  653. IIO_BUFFER_17_BYTES * 8, 0)
  654. }
  655. };
  656. static const struct iio_info step_det_info = {
  657. .driver_module = THIS_MODULE,
  658. };
  659. static const struct iio_chan_spec step_det_channels[] = {
  660. {
  661. .type = IIO_TIMESTAMP,
  662. .channel = -1,
  663. .scan_index = 3,
  664. .scan_type = IIO_ST('s', IIO_BUFFER_1_BYTES * 8,
  665. IIO_BUFFER_1_BYTES * 8, 0)
  666. }
  667. };
  668. static const struct iio_info pressure_info = {
  669. .driver_module = THIS_MODULE,
  670. };
  671. static const struct iio_chan_spec pressure_channels[] = {
  672. {
  673. .type = IIO_TIMESTAMP,
  674. .channel = -1,
  675. .scan_index = 3,
  676. .scan_type = IIO_ST('s', IIO_BUFFER_12_BYTES * 8,
  677. IIO_BUFFER_12_BYTES * 8, 0)
  678. }
  679. };
  680. int initialize_input_dev(struct ssp_data *data)
  681. {
  682. int iRet = 0;
  683. struct input_dev *light_input_dev, *prox_input_dev,
  684. #ifdef CONFIG_SENSORS_SSP_SHTC1
  685. *temp_humi_input_dev,
  686. #endif
  687. #ifdef CONFIG_SENSORS_SSP_UVIS25
  688. *uv_input_dev,
  689. #endif
  690. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  691. defined(CONFIG_SENSORS_SSP_MAX88920)
  692. *gesture_input_dev,
  693. #endif
  694. *mag_input_dev, *uncal_mag_input_dev, *uncalib_gyro_input_dev,
  695. *sig_motion_input_dev, *step_cnt_input_dev,
  696. *meta_input_dev;
  697. data->accel_indio_dev = iio_allocate_device(0);
  698. if (!data->accel_indio_dev) {
  699. pr_err("[SSP]: %s failed to allocate memory for iio accel device\n", __func__);
  700. return -ENOMEM;
  701. }
  702. data->accel_indio_dev->name = "accelerometer_sensor";
  703. data->accel_indio_dev->dev.parent = &data->spi->dev;
  704. data->accel_indio_dev->info = &accel_info;
  705. data->accel_indio_dev->channels = accel_channels;
  706. data->accel_indio_dev->num_channels = ARRAY_SIZE(accel_channels);
  707. data->accel_indio_dev->modes = INDIO_DIRECT_MODE;
  708. data->accel_indio_dev->currentmode = INDIO_DIRECT_MODE;
  709. iRet = ssp_iio_configure_ring(data->accel_indio_dev);
  710. if (iRet) {
  711. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  712. goto out_free_accel;
  713. }
  714. iRet = iio_buffer_register(data->accel_indio_dev, data->accel_indio_dev->channels,
  715. data->accel_indio_dev->num_channels);
  716. if (iRet)
  717. goto out_unreg_ring_accel;
  718. iRet = iio_device_register(data->accel_indio_dev);
  719. if (iRet)
  720. goto out_remove_trigger_accel;
  721. data->gyro_indio_dev = iio_allocate_device(0);
  722. if (!data->gyro_indio_dev) {
  723. pr_err("[SSP]: %s failed to allocate memory for iio gyro device\n", __func__);
  724. goto out_alloc_fail_gyro;
  725. }
  726. data->gyro_indio_dev->name = "gyro_sensor";
  727. data->gyro_indio_dev->dev.parent = &data->spi->dev;
  728. data->gyro_indio_dev->info = &gyro_info;
  729. data->gyro_indio_dev->channels = gyro_channels;
  730. data->gyro_indio_dev->num_channels = ARRAY_SIZE(gyro_channels);
  731. data->gyro_indio_dev->modes = INDIO_DIRECT_MODE;
  732. data->gyro_indio_dev->currentmode = INDIO_DIRECT_MODE;
  733. iRet = ssp_iio_configure_ring(data->gyro_indio_dev);
  734. if (iRet) {
  735. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  736. goto out_free_gyro;
  737. }
  738. iRet = iio_buffer_register(data->gyro_indio_dev, data->gyro_indio_dev->channels,
  739. data->gyro_indio_dev->num_channels);
  740. if (iRet)
  741. goto out_unreg_ring_gyro;
  742. iRet = iio_device_register(data->gyro_indio_dev);
  743. if (iRet)
  744. goto out_remove_trigger_gyro;
  745. data->game_rot_indio_dev = iio_allocate_device(0);
  746. if (!data->game_rot_indio_dev) {
  747. pr_err("[SSP]: %s failed to allocate memory for iio gyro device\n", __func__);
  748. goto out_alloc_fail_game_rot;
  749. }
  750. data->game_rot_indio_dev->name = "game_rotation_vector_sensor";
  751. data->game_rot_indio_dev->dev.parent = &data->spi->dev;
  752. data->game_rot_indio_dev->info = &game_rot_info;
  753. data->game_rot_indio_dev->channels = game_rot_channels;
  754. data->game_rot_indio_dev->num_channels = ARRAY_SIZE(game_rot_channels);
  755. data->game_rot_indio_dev->modes = INDIO_DIRECT_MODE;
  756. data->game_rot_indio_dev->currentmode = INDIO_DIRECT_MODE;
  757. iRet = ssp_iio_configure_ring(data->game_rot_indio_dev);
  758. if (iRet) {
  759. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  760. goto out_free_game_rot;
  761. }
  762. iRet = iio_buffer_register(data->game_rot_indio_dev, data->game_rot_indio_dev->channels,
  763. data->game_rot_indio_dev->num_channels);
  764. if (iRet)
  765. goto out_unreg_ring_game_rot;
  766. iRet = iio_device_register(data->game_rot_indio_dev);
  767. if (iRet)
  768. goto out_remove_trigger_game_rot;
  769. data->rot_indio_dev = iio_allocate_device(0);
  770. if (!data->rot_indio_dev) {
  771. pr_err("[SSP]: %s failed to allocate memory for iio gyro device\n", __func__);
  772. goto out_alloc_fail_rot;
  773. }
  774. data->rot_indio_dev->name = "rotation_vector_sensor";
  775. data->rot_indio_dev->dev.parent = &data->spi->dev;
  776. data->rot_indio_dev->info = &rot_info;
  777. data->rot_indio_dev->channels = rot_channels;
  778. data->rot_indio_dev->num_channels = ARRAY_SIZE(rot_channels);
  779. data->rot_indio_dev->modes = INDIO_DIRECT_MODE;
  780. data->rot_indio_dev->currentmode = INDIO_DIRECT_MODE;
  781. iRet = ssp_iio_configure_ring(data->rot_indio_dev);
  782. if (iRet) {
  783. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  784. goto out_free_rot;
  785. }
  786. iRet = iio_buffer_register(data->rot_indio_dev, data->rot_indio_dev->channels,
  787. data->rot_indio_dev->num_channels);
  788. if (iRet)
  789. goto out_unreg_ring_rot;
  790. iRet = iio_device_register(data->rot_indio_dev);
  791. if (iRet)
  792. goto out_remove_trigger_rot;
  793. data->step_det_indio_dev = iio_allocate_device(0);
  794. if (!data->step_det_indio_dev) {
  795. pr_err("[SSP]: %s failed to allocate memory for iio gyro device\n", __func__);
  796. goto out_alloc_fail_step_det;
  797. }
  798. data->step_det_indio_dev->name = "step_det_sensor";
  799. data->step_det_indio_dev->dev.parent = &data->spi->dev;
  800. data->step_det_indio_dev->info = &step_det_info;
  801. data->step_det_indio_dev->channels = step_det_channels;
  802. data->step_det_indio_dev->num_channels = ARRAY_SIZE(step_det_channels);
  803. data->step_det_indio_dev->modes = INDIO_DIRECT_MODE;
  804. data->step_det_indio_dev->currentmode = INDIO_DIRECT_MODE;
  805. iRet = ssp_iio_configure_ring(data->step_det_indio_dev);
  806. if (iRet) {
  807. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  808. goto out_free_step_det;
  809. }
  810. iRet = iio_buffer_register(data->step_det_indio_dev, data->step_det_indio_dev->channels,
  811. data->step_det_indio_dev->num_channels);
  812. if (iRet)
  813. goto out_unreg_ring_step_det;
  814. iRet = iio_device_register(data->step_det_indio_dev);
  815. if (iRet)
  816. goto out_remove_trigger_step_det;
  817. #ifdef CONFIG_SENSORS_SSP_BMP182
  818. data->pressure_indio_dev = iio_allocate_device(0);
  819. if (!data->pressure_indio_dev) {
  820. pr_err("[SSP]: %s failed to allocate memory for iio gyro device\n", __func__);
  821. goto out_alloc_fail_pressure;
  822. }
  823. data->pressure_indio_dev->name = "pressure_sensor";
  824. data->pressure_indio_dev->dev.parent = &data->spi->dev;
  825. data->pressure_indio_dev->info = &pressure_info;
  826. data->pressure_indio_dev->channels = pressure_channels;
  827. data->pressure_indio_dev->num_channels = ARRAY_SIZE(pressure_channels);
  828. data->pressure_indio_dev->modes = INDIO_DIRECT_MODE;
  829. data->pressure_indio_dev->currentmode = INDIO_DIRECT_MODE;
  830. iRet = ssp_iio_configure_ring(data->pressure_indio_dev);
  831. if (iRet) {
  832. pr_err("[SSP]: %s configure ring buffer fail\n", __func__);
  833. goto out_free_pressure;
  834. }
  835. iRet = iio_buffer_register(data->pressure_indio_dev, data->pressure_indio_dev->channels,
  836. data->pressure_indio_dev->num_channels);
  837. if (iRet)
  838. goto out_unreg_ring_pressure;
  839. iRet = iio_device_register(data->pressure_indio_dev);
  840. if (iRet)
  841. goto out_remove_trigger_pressure;
  842. #endif
  843. /* allocate input_device */
  844. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  845. defined(CONFIG_SENSORS_SSP_MAX88920)
  846. gesture_input_dev = input_allocate_device();
  847. if (gesture_input_dev == NULL)
  848. goto iRet_gesture_input_free_device;
  849. #endif
  850. light_input_dev = input_allocate_device();
  851. if (light_input_dev == NULL)
  852. goto iRet_light_input_free_device;
  853. prox_input_dev = input_allocate_device();
  854. if (prox_input_dev == NULL)
  855. goto iRet_proximity_input_free_device;
  856. #ifdef CONFIG_SENSORS_SSP_SHTC1
  857. temp_humi_input_dev = input_allocate_device();
  858. if (temp_humi_input_dev == NULL)
  859. goto iRet_temp_humidity_input_free_device;
  860. #endif
  861. #ifdef CONFIG_SENSORS_SSP_UVIS25
  862. uv_input_dev = input_allocate_device();
  863. if (uv_input_dev == NULL)
  864. goto iRet_uv_input_free_device;
  865. #endif
  866. mag_input_dev = input_allocate_device();
  867. if (mag_input_dev == NULL)
  868. goto iRet_mag_input_free_device;
  869. uncal_mag_input_dev = input_allocate_device();
  870. if (uncal_mag_input_dev == NULL)
  871. goto iRet_uncal_mag_input_free_device;
  872. sig_motion_input_dev = input_allocate_device();
  873. if (sig_motion_input_dev == NULL)
  874. goto iRet_sig_motion_input_free_device;
  875. uncalib_gyro_input_dev = input_allocate_device();
  876. if (uncalib_gyro_input_dev == NULL)
  877. goto iRet_uncalib_gyro_input_free_device;
  878. step_cnt_input_dev = input_allocate_device();
  879. if (step_cnt_input_dev == NULL)
  880. goto iRet_step_cnt_input_free_device;
  881. meta_input_dev = input_allocate_device();
  882. if (meta_input_dev == NULL)
  883. goto iRet_meta_input_free_device;
  884. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  885. defined(CONFIG_SENSORS_SSP_MAX88920)
  886. input_set_drvdata(gesture_input_dev, data);
  887. #endif
  888. input_set_drvdata(light_input_dev, data);
  889. input_set_drvdata(prox_input_dev, data);
  890. #ifdef CONFIG_SENSORS_SSP_SHTC1
  891. input_set_drvdata(temp_humi_input_dev, data);
  892. #endif
  893. #ifdef CONFIG_SENSORS_SSP_UVIS25
  894. input_set_drvdata(uv_input_dev, data);
  895. #endif
  896. input_set_drvdata(mag_input_dev, data);
  897. input_set_drvdata(uncal_mag_input_dev, data);
  898. input_set_drvdata(sig_motion_input_dev, data);
  899. input_set_drvdata(uncalib_gyro_input_dev, data);
  900. input_set_drvdata(step_cnt_input_dev, data);
  901. input_set_drvdata(meta_input_dev, data);
  902. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  903. defined(CONFIG_SENSORS_SSP_MAX88920)
  904. gesture_input_dev->name = "gesture_sensor";
  905. #endif
  906. light_input_dev->name = "light_sensor";
  907. prox_input_dev->name = "proximity_sensor";
  908. #ifdef CONFIG_SENSORS_SSP_SHTC1
  909. temp_humi_input_dev->name = "temp_humidity_sensor";
  910. #endif
  911. #ifdef CONFIG_SENSORS_SSP_UVIS25
  912. uv_input_dev->name = "uv_sensor";
  913. #endif
  914. mag_input_dev->name = "geomagnetic_sensor";
  915. uncal_mag_input_dev->name = "uncal_geomagnetic_sensor";
  916. sig_motion_input_dev->name = "sig_motion_sensor";
  917. uncalib_gyro_input_dev->name = "uncalibrated_gyro_sensor";
  918. step_cnt_input_dev->name = "step_cnt_sensor";
  919. meta_input_dev->name = "meta_event";
  920. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  921. defined(CONFIG_SENSORS_SSP_MAX88920)
  922. input_set_capability(gesture_input_dev, EV_ABS, ABS_X);
  923. input_set_abs_params(gesture_input_dev, ABS_X, 0, 1024, 0, 0);
  924. input_set_capability(gesture_input_dev, EV_ABS, ABS_Y);
  925. input_set_abs_params(gesture_input_dev, ABS_Y, 0, 1024, 0, 0);
  926. input_set_capability(gesture_input_dev, EV_ABS, ABS_Z);
  927. input_set_abs_params(gesture_input_dev, ABS_Z, 0, 1024, 0, 0);
  928. input_set_capability(gesture_input_dev, EV_ABS, ABS_RX);
  929. input_set_abs_params(gesture_input_dev, ABS_RX, 0, 1024, 0, 0);
  930. input_set_capability(gesture_input_dev, EV_ABS, ABS_RY);
  931. input_set_abs_params(gesture_input_dev, ABS_RY, 0, 1024, 0, 0);
  932. input_set_capability(gesture_input_dev, EV_ABS, ABS_RZ);
  933. input_set_abs_params(gesture_input_dev, ABS_RZ, 0, 1024, 0, 0);
  934. input_set_capability(gesture_input_dev, EV_ABS, ABS_THROTTLE);
  935. input_set_abs_params(gesture_input_dev, ABS_THROTTLE, 0, 1024, 0, 0);
  936. input_set_capability(gesture_input_dev, EV_ABS, ABS_RUDDER);
  937. input_set_abs_params(gesture_input_dev, ABS_RUDDER, 0, 1024, 0, 0);
  938. input_set_capability(gesture_input_dev, EV_ABS, ABS_WHEEL);
  939. input_set_abs_params(gesture_input_dev, ABS_WHEEL, 0, 1024, 0, 0);
  940. input_set_capability(gesture_input_dev, EV_ABS, ABS_GAS);
  941. input_set_abs_params(gesture_input_dev, ABS_GAS, 0, 1024, 0, 0);
  942. input_set_capability(gesture_input_dev, EV_ABS, ABS_BRAKE);
  943. input_set_abs_params(gesture_input_dev, ABS_BRAKE, 0, 1024, 0, 0);
  944. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT0X);
  945. input_set_abs_params(gesture_input_dev, ABS_HAT0X, 0, 1024, 0, 0);
  946. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT0Y);
  947. input_set_abs_params(gesture_input_dev, ABS_HAT0Y, 0, 1024, 0, 0);
  948. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT1X);
  949. input_set_abs_params(gesture_input_dev, ABS_HAT1X, 0, 1024, 0, 0);
  950. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT1Y);
  951. input_set_abs_params(gesture_input_dev, ABS_HAT1Y, 0, 1024, 0, 0);
  952. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT2X);
  953. input_set_abs_params(gesture_input_dev, ABS_HAT2X, 0, 1024, 0, 0);
  954. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT2Y);
  955. input_set_abs_params(gesture_input_dev, ABS_HAT2Y, 0, 1024, 0, 0);
  956. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT3X);
  957. input_set_abs_params(gesture_input_dev, ABS_HAT3X, 0, 1024, 0, 0);
  958. input_set_capability(gesture_input_dev, EV_ABS, ABS_HAT3Y);
  959. input_set_abs_params(gesture_input_dev, ABS_HAT3Y, 0, 1024, 0, 0);
  960. input_set_capability(gesture_input_dev, EV_ABS, ABS_PRESSURE);
  961. input_set_abs_params(gesture_input_dev, ABS_PRESSURE, 0, 1024, 0, 0);
  962. #endif
  963. input_set_capability(light_input_dev, EV_REL, REL_HWHEEL);
  964. input_set_capability(light_input_dev, EV_REL, REL_DIAL);
  965. input_set_capability(light_input_dev, EV_REL, REL_WHEEL);
  966. input_set_capability(light_input_dev, EV_REL, REL_MISC);
  967. input_set_capability(light_input_dev, EV_REL, REL_RY);
  968. input_set_capability(light_input_dev, EV_REL, REL_RZ);
  969. input_set_capability(prox_input_dev, EV_ABS, ABS_DISTANCE);
  970. input_set_abs_params(prox_input_dev, ABS_DISTANCE, 0, 1, 0, 0);
  971. #ifdef CONFIG_SENSORS_SSP_SHTC1
  972. input_set_capability(temp_humi_input_dev, EV_REL, REL_HWHEEL);
  973. input_set_capability(temp_humi_input_dev, EV_REL, REL_DIAL);
  974. input_set_capability(temp_humi_input_dev, EV_REL, REL_WHEEL);
  975. #endif
  976. #ifdef CONFIG_SENSORS_SSP_UVIS25
  977. input_set_capability(uv_input_dev, EV_REL, REL_MISC);
  978. #endif
  979. #ifdef SAVE_MAG_LOG
  980. input_set_capability(mag_input_dev, EV_REL, REL_X);
  981. input_set_capability(mag_input_dev, EV_REL, REL_Y);
  982. input_set_capability(mag_input_dev, EV_REL, REL_Z);
  983. input_set_capability(mag_input_dev, EV_REL, REL_RX);
  984. input_set_capability(mag_input_dev, EV_REL, REL_RY);
  985. input_set_capability(mag_input_dev, EV_REL, REL_RZ);
  986. input_set_capability(mag_input_dev, EV_REL, REL_HWHEEL);
  987. input_set_capability(mag_input_dev, EV_REL, REL_DIAL);
  988. input_set_capability(mag_input_dev, EV_REL, REL_WHEEL);
  989. #else
  990. input_set_capability(mag_input_dev, EV_REL, REL_RX);
  991. input_set_capability(mag_input_dev, EV_REL, REL_RY);
  992. input_set_capability(mag_input_dev, EV_REL, REL_RZ);
  993. input_set_capability(mag_input_dev, EV_REL, REL_HWHEEL);
  994. #endif
  995. input_set_capability(uncal_mag_input_dev, EV_REL, REL_RX);
  996. input_set_capability(uncal_mag_input_dev, EV_REL, REL_RY);
  997. input_set_capability(uncal_mag_input_dev, EV_REL, REL_RZ);
  998. input_set_capability(uncal_mag_input_dev, EV_REL, REL_HWHEEL);
  999. input_set_capability(uncal_mag_input_dev, EV_REL, REL_DIAL);
  1000. input_set_capability(uncal_mag_input_dev, EV_REL, REL_WHEEL);
  1001. input_set_capability(sig_motion_input_dev, EV_REL, REL_MISC);
  1002. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_X);
  1003. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_Y);
  1004. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_Z);
  1005. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_RX);
  1006. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_RY);
  1007. input_set_capability(uncalib_gyro_input_dev, EV_REL, REL_RZ);
  1008. input_set_capability(step_cnt_input_dev, EV_REL, REL_MISC);
  1009. input_set_capability(meta_input_dev, EV_REL, REL_HWHEEL);
  1010. input_set_capability(meta_input_dev, EV_REL, REL_DIAL);
  1011. /* register input_device */
  1012. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  1013. defined(CONFIG_SENSORS_SSP_MAX88920)
  1014. iRet = input_register_device(gesture_input_dev);
  1015. if (iRet < 0)
  1016. goto iRet_gesture_input_unreg_device;
  1017. #endif
  1018. #ifdef CONFIG_SENSORS_SSP_UVIS25
  1019. iRet = input_register_device(uv_input_dev);
  1020. if (iRet < 0) {
  1021. input_free_device(uv_input_dev);
  1022. input_free_device(light_input_dev);
  1023. input_free_device(prox_input_dev);
  1024. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1025. input_free_device(temp_humi_input_dev);
  1026. #endif
  1027. input_free_device(mag_input_dev);
  1028. input_free_device(uncal_mag_input_dev);
  1029. input_free_device(sig_motion_input_dev);
  1030. input_free_device(uncalib_gyro_input_dev);
  1031. input_free_device(step_cnt_input_dev);
  1032. input_free_device(meta_input_dev);
  1033. goto iRet_uv_input_unreg_device;
  1034. }
  1035. #endif
  1036. iRet = input_register_device(light_input_dev);
  1037. if (iRet < 0) {
  1038. input_free_device(light_input_dev);
  1039. input_free_device(prox_input_dev);
  1040. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1041. input_free_device(temp_humi_input_dev);
  1042. #endif
  1043. input_free_device(mag_input_dev);
  1044. input_free_device(uncal_mag_input_dev);
  1045. input_free_device(sig_motion_input_dev);
  1046. input_free_device(uncalib_gyro_input_dev);
  1047. input_free_device(step_cnt_input_dev);
  1048. input_free_device(meta_input_dev);
  1049. goto iRet_light_input_unreg_device;
  1050. }
  1051. iRet = input_register_device(prox_input_dev);
  1052. if (iRet < 0) {
  1053. input_free_device(prox_input_dev);
  1054. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1055. input_free_device(temp_humi_input_dev);
  1056. #endif
  1057. input_free_device(mag_input_dev);
  1058. input_free_device(uncal_mag_input_dev);
  1059. input_free_device(sig_motion_input_dev);
  1060. input_free_device(uncalib_gyro_input_dev);
  1061. input_free_device(step_cnt_input_dev);
  1062. input_free_device(meta_input_dev);
  1063. goto iRet_proximity_input_unreg_device;
  1064. }
  1065. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1066. iRet = input_register_device(temp_humi_input_dev);
  1067. if (iRet < 0) {
  1068. input_free_device(temp_humi_input_dev);
  1069. input_free_device(mag_input_dev);
  1070. input_free_device(uncal_mag_input_dev);
  1071. input_free_device(sig_motion_input_dev);
  1072. input_free_device(uncalib_gyro_input_dev);
  1073. input_free_device(step_cnt_input_dev);
  1074. input_free_device(meta_input_dev);
  1075. goto iRet_tmep_humi_input_unreg_device;
  1076. }
  1077. #endif
  1078. iRet = input_register_device(mag_input_dev);
  1079. if (iRet < 0) {
  1080. input_free_device(mag_input_dev);
  1081. input_free_device(uncal_mag_input_dev);
  1082. input_free_device(sig_motion_input_dev);
  1083. input_free_device(uncalib_gyro_input_dev);
  1084. input_free_device(step_cnt_input_dev);
  1085. input_free_device(meta_input_dev);
  1086. goto iRet_mag_input_unreg_device;
  1087. }
  1088. iRet = input_register_device(uncal_mag_input_dev);
  1089. if (iRet < 0) {
  1090. input_free_device(uncal_mag_input_dev);
  1091. input_free_device(sig_motion_input_dev);
  1092. input_free_device(uncalib_gyro_input_dev);
  1093. input_free_device(step_cnt_input_dev);
  1094. input_free_device(meta_input_dev);
  1095. goto iRet_uncal_mag_input_unreg_device;
  1096. }
  1097. iRet = input_register_device(sig_motion_input_dev);
  1098. if (iRet < 0) {
  1099. input_free_device(sig_motion_input_dev);
  1100. input_free_device(uncalib_gyro_input_dev);
  1101. input_free_device(step_cnt_input_dev);
  1102. input_free_device(meta_input_dev);
  1103. goto iRet_sig_motion_input_unreg_device;
  1104. }
  1105. iRet = input_register_device(uncalib_gyro_input_dev);
  1106. if (iRet < 0) {
  1107. input_free_device(uncalib_gyro_input_dev);
  1108. input_free_device(step_cnt_input_dev);
  1109. input_free_device(meta_input_dev);
  1110. goto iRet_uncalib_gyro_input_unreg_device;
  1111. }
  1112. iRet = input_register_device(step_cnt_input_dev);
  1113. if (iRet < 0) {
  1114. input_free_device(step_cnt_input_dev);
  1115. input_free_device(meta_input_dev);
  1116. goto iRet_step_cnt_input_unreg_device;
  1117. }
  1118. iRet = input_register_device(meta_input_dev);
  1119. if (iRet < 0) {
  1120. input_free_device(meta_input_dev);
  1121. goto iRet_meta_input_unreg_device;
  1122. }
  1123. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  1124. defined(CONFIG_SENSORS_SSP_MAX88920)
  1125. data->gesture_input_dev = gesture_input_dev;
  1126. #endif
  1127. data->light_input_dev = light_input_dev;
  1128. data->prox_input_dev = prox_input_dev;
  1129. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1130. data->temp_humi_input_dev = temp_humi_input_dev;
  1131. #endif
  1132. #ifdef CONFIG_SENSORS_SSP_UVIS25
  1133. data->uv_input_dev = uv_input_dev;
  1134. #endif
  1135. data->mag_input_dev = mag_input_dev;
  1136. data->uncal_mag_input_dev = uncal_mag_input_dev;
  1137. data->sig_motion_input_dev = sig_motion_input_dev;
  1138. data->uncalib_gyro_input_dev = uncalib_gyro_input_dev;
  1139. data->step_cnt_input_dev = step_cnt_input_dev;
  1140. data->meta_input_dev = meta_input_dev;
  1141. return SUCCESS;
  1142. iRet_meta_input_unreg_device:
  1143. input_unregister_device(step_cnt_input_dev);
  1144. iRet_step_cnt_input_unreg_device:
  1145. input_unregister_device(uncalib_gyro_input_dev);
  1146. iRet_uncalib_gyro_input_unreg_device:
  1147. input_unregister_device(sig_motion_input_dev);
  1148. iRet_sig_motion_input_unreg_device:
  1149. input_unregister_device(uncal_mag_input_dev);
  1150. iRet_uncal_mag_input_unreg_device:
  1151. input_unregister_device(mag_input_dev);
  1152. iRet_mag_input_unreg_device:
  1153. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1154. input_unregister_device(temp_humi_input_dev);
  1155. iRet_tmep_humi_input_unreg_device:
  1156. #endif
  1157. input_unregister_device(prox_input_dev);
  1158. iRet_proximity_input_unreg_device:
  1159. input_unregister_device(light_input_dev);
  1160. iRet_light_input_unreg_device:
  1161. #ifdef CONFIG_SENSORS_SSP_UVIS25
  1162. input_unregister_device(uv_input_dev);
  1163. iRet_uv_input_unreg_device:
  1164. #endif
  1165. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  1166. defined(CONFIG_SENSORS_SSP_MAX88920)
  1167. input_unregister_device(gesture_input_dev);
  1168. return ERROR;
  1169. iRet_gesture_input_unreg_device:
  1170. #endif
  1171. input_free_device(meta_input_dev);
  1172. iRet_meta_input_free_device:
  1173. input_free_device(step_cnt_input_dev);
  1174. iRet_step_cnt_input_free_device:
  1175. input_free_device(uncalib_gyro_input_dev);
  1176. iRet_uncalib_gyro_input_free_device:
  1177. input_free_device(sig_motion_input_dev);
  1178. iRet_sig_motion_input_free_device:
  1179. input_free_device(uncal_mag_input_dev);
  1180. iRet_uncal_mag_input_free_device:
  1181. input_free_device(mag_input_dev);
  1182. iRet_mag_input_free_device:
  1183. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1184. input_free_device(temp_humi_input_dev);
  1185. iRet_temp_humidity_input_free_device:
  1186. #endif
  1187. #ifdef CONFIG_SENSORS_SSP_UVIS25
  1188. input_free_device(uv_input_dev);
  1189. iRet_uv_input_free_device:
  1190. #endif
  1191. input_free_device(prox_input_dev);
  1192. iRet_proximity_input_free_device:
  1193. input_free_device(light_input_dev);
  1194. iRet_light_input_free_device:
  1195. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  1196. defined(CONFIG_SENSORS_SSP_MAX88920)
  1197. input_free_device(gesture_input_dev);
  1198. iRet_gesture_input_free_device:
  1199. #endif
  1200. #ifdef CONFIG_SENSORS_SSP_BMP182
  1201. iio_device_unregister(data->pressure_indio_dev);
  1202. out_remove_trigger_pressure:
  1203. iio_buffer_unregister(data->pressure_indio_dev);
  1204. out_unreg_ring_pressure:
  1205. ssp_iio_unconfigure_ring(data->pressure_indio_dev);
  1206. out_free_pressure:
  1207. iio_free_device(data->pressure_indio_dev);
  1208. out_alloc_fail_pressure:
  1209. #endif
  1210. iio_device_unregister(data->step_det_indio_dev);
  1211. out_remove_trigger_step_det:
  1212. iio_buffer_unregister(data->step_det_indio_dev);
  1213. out_unreg_ring_step_det:
  1214. ssp_iio_unconfigure_ring(data->step_det_indio_dev);
  1215. out_free_step_det:
  1216. iio_free_device(data->step_det_indio_dev);
  1217. out_alloc_fail_step_det:
  1218. iio_device_unregister(data->rot_indio_dev);
  1219. out_remove_trigger_rot:
  1220. iio_buffer_unregister(data->rot_indio_dev);
  1221. out_unreg_ring_rot:
  1222. ssp_iio_unconfigure_ring(data->rot_indio_dev);
  1223. out_free_rot:
  1224. iio_free_device(data->rot_indio_dev);
  1225. out_alloc_fail_rot:
  1226. iio_device_unregister(data->game_rot_indio_dev);
  1227. out_remove_trigger_game_rot:
  1228. iio_buffer_unregister(data->game_rot_indio_dev);
  1229. out_unreg_ring_game_rot:
  1230. ssp_iio_unconfigure_ring(data->game_rot_indio_dev);
  1231. out_free_game_rot:
  1232. iio_free_device(data->game_rot_indio_dev);
  1233. out_alloc_fail_game_rot:
  1234. iio_device_unregister(data->gyro_indio_dev);
  1235. out_remove_trigger_gyro:
  1236. iio_buffer_unregister(data->gyro_indio_dev);
  1237. out_unreg_ring_gyro:
  1238. ssp_iio_unconfigure_ring(data->gyro_indio_dev);
  1239. out_free_gyro:
  1240. iio_free_device(data->gyro_indio_dev);
  1241. out_alloc_fail_gyro:
  1242. iio_device_unregister(data->accel_indio_dev);
  1243. out_remove_trigger_accel:
  1244. iio_buffer_unregister(data->accel_indio_dev);
  1245. out_unreg_ring_accel:
  1246. ssp_iio_unconfigure_ring(data->accel_indio_dev);
  1247. out_free_accel:
  1248. iio_free_device(data->accel_indio_dev);
  1249. pr_err("[SSP]: %s - could not allocate input device\n", __func__);
  1250. return ERROR;
  1251. }
  1252. void remove_input_dev(struct ssp_data *data)
  1253. {
  1254. #if defined(CONFIG_SENSORS_SSP_TMG399X) || defined(CONFIG_SENSORS_SSP_MAX88921) || \
  1255. defined(CONFIG_SENSORS_SSP_MAX88920)
  1256. input_unregister_device(data->gesture_input_dev);
  1257. #endif
  1258. input_unregister_device(data->light_input_dev);
  1259. input_unregister_device(data->prox_input_dev);
  1260. #ifdef CONFIG_SENSORS_SSP_SHTC1
  1261. input_unregister_device(data->temp_humi_input_dev);
  1262. #endif
  1263. #ifdef CONFIG_SENSORS_SSP_UVIS25
  1264. input_unregister_device(data->uv_input_dev);
  1265. #endif
  1266. input_unregister_device(data->mag_input_dev);
  1267. input_unregister_device(data->uncal_mag_input_dev);
  1268. input_unregister_device(data->sig_motion_input_dev);
  1269. input_unregister_device(data->uncalib_gyro_input_dev);
  1270. input_unregister_device(data->step_cnt_input_dev);
  1271. input_unregister_device(data->meta_input_dev);
  1272. }