activity.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. #include "activity.h"
  2. struct act_context *act_context_obj = NULL;
  3. static struct act_init_info *activity_init_list[MAX_CHOOSE_ACT_NUM] = { 0 }; /* modified */
  4. static void act_early_suspend(struct early_suspend *h);
  5. static void act_late_resume(struct early_suspend *h);
  6. static void act_work_func(struct work_struct *work)
  7. {
  8. struct act_context *cxt = NULL;
  9. /* int out_size; */
  10. /* hwm_sensor_data sensor_data; */
  11. /* u64 data64[6]; //for unify get_data parameter type */
  12. /* u16 data32[6]; //for hwm_sensor_data.values as int */
  13. u16 data16[6]; /* for hwm_sensor_data.values as int */
  14. int status;
  15. int64_t nt;
  16. struct timespec time;
  17. int err = 0;
  18. cxt = act_context_obj;
  19. if (cxt->act_data.get_data == NULL)
  20. ACT_ERR("act driver not register data path\n");
  21. time.tv_sec = time.tv_nsec = 0;
  22. time = get_monotonic_coarse();
  23. nt = time.tv_sec * 1000000000LL + time.tv_nsec;
  24. /* add wake lock to make sure data can be read before system suspend */
  25. /* initial data */
  26. ACT_LOG("act_data.values %d,%d,%d,%d,%d,%d\n",
  27. cxt->drv_data.act_data.values[0],
  28. cxt->drv_data.act_data.values[1],
  29. cxt->drv_data.act_data.values[2],
  30. cxt->drv_data.act_data.values[3],
  31. cxt->drv_data.act_data.values[4],
  32. cxt->drv_data.act_data.values[5]);
  33. err = cxt->act_data.get_data(data16, &status);
  34. ACT_LOG("get_data 16 %d,%d,%d,%d,%d,%d\n",
  35. data16[0], data16[1], data16[2], data16[3], data16[4], data16[5]);
  36. if (err) {
  37. ACT_ERR("get act data fails!!\n");
  38. goto act_loop;
  39. } else {
  40. if ((data16[0] == cxt->drv_data.act_data.values[0])
  41. && (data16[1] == cxt->drv_data.act_data.values[1])
  42. && (data16[2] == cxt->drv_data.act_data.values[2])
  43. && (data16[3] == cxt->drv_data.act_data.values[3])
  44. && (data16[4] == cxt->drv_data.act_data.values[4])
  45. && (data16[5] == cxt->drv_data.act_data.values[5])) {
  46. goto act_loop;
  47. } else {
  48. cxt->drv_data.act_data.values[0] = data16[0];
  49. cxt->drv_data.act_data.values[1] = data16[1];
  50. cxt->drv_data.act_data.values[2] = data16[2];
  51. cxt->drv_data.act_data.values[3] = data16[3];
  52. cxt->drv_data.act_data.values[4] = data16[4];
  53. cxt->drv_data.act_data.values[5] = data16[5];
  54. ACT_LOG("act values %d,%d,%d,%d,%d,%d\n",
  55. cxt->drv_data.act_data.values[0],
  56. cxt->drv_data.act_data.values[1],
  57. cxt->drv_data.act_data.values[2],
  58. cxt->drv_data.act_data.values[3],
  59. cxt->drv_data.act_data.values[4],
  60. cxt->drv_data.act_data.values[5]);
  61. cxt->drv_data.act_data.status = status;
  62. cxt->drv_data.act_data.time = nt;
  63. }
  64. }
  65. if (true == cxt->is_first_data_after_enable) {
  66. cxt->is_first_data_after_enable = false;
  67. /* filter -1 value */
  68. if (ACT_INVALID_VALUE == cxt->drv_data.act_data.values[0] ||
  69. ACT_INVALID_VALUE == cxt->drv_data.act_data.values[1] ||
  70. ACT_INVALID_VALUE == cxt->drv_data.act_data.values[2] ||
  71. ACT_INVALID_VALUE == cxt->drv_data.act_data.values[3] ||
  72. ACT_INVALID_VALUE == cxt->drv_data.act_data.values[4] ||
  73. ACT_INVALID_VALUE == cxt->drv_data.act_data.values[5]) {
  74. ACT_LOG(" read invalid data\n");
  75. goto act_loop;
  76. }
  77. }
  78. /* report data to input devic */
  79. /* printk("new act work run....\n") */
  80. /* ACT_LOG("act data[%d,%d,%d]\n" ,cxt->drv_data.act_data.values[0],*/
  81. /* cxt->drv_data.act_data.values[1],cxt->drv_data.act_data.values[2]);*/
  82. act_data_report(cxt->drv_data.act_data, cxt->drv_data.act_data.status);
  83. act_loop:
  84. if (true == cxt->is_polling_run) {
  85. {
  86. mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  87. }
  88. }
  89. }
  90. static void act_poll(unsigned long data)
  91. {
  92. struct act_context *obj = (struct act_context *)data;
  93. if (obj != NULL)
  94. schedule_work(&obj->report);
  95. }
  96. static struct act_context *act_context_alloc_object(void)
  97. {
  98. struct act_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  99. ACT_LOG("act_context_alloc_object++++\n");
  100. if (!obj) {
  101. ACT_ERR("Alloc act object error!\n");
  102. return NULL;
  103. }
  104. atomic_set(&obj->delay, 200); /*5Hz set work queue delay time 200ms */
  105. atomic_set(&obj->wake, 0);
  106. INIT_WORK(&obj->report, act_work_func);
  107. init_timer(&obj->timer);
  108. obj->timer.expires = jiffies + atomic_read(&obj->delay) / (1000 / HZ);
  109. obj->timer.function = act_poll;
  110. obj->timer.data = (unsigned long)obj;
  111. obj->is_first_data_after_enable = false;
  112. obj->is_polling_run = false;
  113. obj->is_batch_enable = false;
  114. mutex_init(&obj->act_op_mutex);
  115. ACT_LOG("act_context_alloc_object----\n");
  116. return obj;
  117. }
  118. static int act_real_enable(int enable)
  119. {
  120. int err = 0;
  121. struct act_context *cxt = NULL;
  122. cxt = act_context_obj;
  123. if (1 == enable) {
  124. if (true == cxt->is_active_data || true == cxt->is_active_nodata) {
  125. err = cxt->act_ctl.enable_nodata(1);
  126. if (err) {
  127. err = cxt->act_ctl.enable_nodata(1);
  128. if (err) {
  129. err = cxt->act_ctl.enable_nodata(1);
  130. if (err)
  131. ACT_ERR("act enable(%d) err 3 timers = %d\n",
  132. enable, err);
  133. }
  134. }
  135. ACT_LOG("act real enable\n");
  136. }
  137. }
  138. if (0 == enable) {
  139. if (false == cxt->is_active_data && false == cxt->is_active_nodata) {
  140. err = cxt->act_ctl.enable_nodata(0);
  141. if (err)
  142. ACT_ERR("act enable(%d) err = %d\n", enable, err);
  143. ACT_LOG("act real disable\n");
  144. }
  145. }
  146. return err;
  147. }
  148. static int act_enable_data(int enable)
  149. {
  150. struct act_context *cxt = NULL;
  151. cxt = act_context_obj;
  152. if (NULL == cxt->act_ctl.open_report_data) {
  153. ACT_ERR("no act control path\n");
  154. return -1;
  155. }
  156. if (1 == enable) {
  157. ACT_LOG("act enable data\n");
  158. cxt->is_active_data = true;
  159. cxt->is_first_data_after_enable = true;
  160. cxt->act_ctl.open_report_data(1);
  161. if (false == cxt->is_polling_run && cxt->is_batch_enable == false) {
  162. if (false == cxt->act_ctl.is_report_input_direct) {
  163. mod_timer(&cxt->timer,
  164. jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  165. cxt->is_polling_run = true;
  166. }
  167. }
  168. }
  169. if (0 == enable) {
  170. ACT_LOG("act disable\n");
  171. cxt->is_active_data = false;
  172. cxt->act_ctl.open_report_data(0);
  173. if (true == cxt->is_polling_run) {
  174. if (false == cxt->act_ctl.is_report_input_direct) {
  175. cxt->is_polling_run = false;
  176. del_timer_sync(&cxt->timer);
  177. cancel_work_sync(&cxt->report);
  178. cxt->drv_data.act_data.values[0] = ACT_INVALID_VALUE;
  179. cxt->drv_data.act_data.values[1] = ACT_INVALID_VALUE;
  180. cxt->drv_data.act_data.values[2] = ACT_INVALID_VALUE;
  181. cxt->drv_data.act_data.values[3] = ACT_INVALID_VALUE;
  182. cxt->drv_data.act_data.values[4] = ACT_INVALID_VALUE;
  183. cxt->drv_data.act_data.values[5] = ACT_INVALID_VALUE;
  184. }
  185. }
  186. }
  187. act_real_enable(enable);
  188. return 0;
  189. }
  190. int act_enable_nodata(int enable)
  191. {
  192. struct act_context *cxt = NULL;
  193. cxt = act_context_obj;
  194. if (NULL == cxt->act_ctl.enable_nodata) {
  195. ACT_ERR("act_enable_nodata:act ctl path is NULL\n");
  196. return -1;
  197. }
  198. if (1 == enable)
  199. cxt->is_active_nodata = true;
  200. if (0 == enable)
  201. cxt->is_active_nodata = false;
  202. act_real_enable(enable);
  203. return 0;
  204. }
  205. static ssize_t act_show_enable_nodata(struct device *dev, struct device_attribute *attr, char *buf)
  206. {
  207. int len = 0;
  208. ACT_LOG(" not support now\n");
  209. return len;
  210. }
  211. static ssize_t act_store_enable_nodata(struct device *dev, struct device_attribute *attr,
  212. const char *buf, size_t count)
  213. {
  214. struct act_context *cxt = NULL;
  215. /* int err =0; */
  216. ACT_LOG("act_store_enable nodata buf=%s\n", buf);
  217. mutex_lock(&act_context_obj->act_op_mutex);
  218. cxt = act_context_obj;
  219. if (NULL == cxt->act_ctl.enable_nodata) {
  220. ACT_LOG("act_ctl enable nodata NULL\n");
  221. mutex_unlock(&act_context_obj->act_op_mutex);
  222. return count;
  223. }
  224. if (!strncmp(buf, "1", 1))
  225. act_enable_nodata(1);
  226. else if (!strncmp(buf, "0", 1))
  227. act_enable_nodata(0);
  228. else
  229. ACT_ERR(" act_store enable nodata cmd error !!\n");
  230. mutex_unlock(&act_context_obj->act_op_mutex);
  231. return count;
  232. }
  233. static ssize_t act_store_active(struct device *dev, struct device_attribute *attr,
  234. const char *buf, size_t count)
  235. {
  236. struct act_context *cxt = NULL;
  237. ACT_LOG("act_store_active buf=%s\n", buf);
  238. mutex_lock(&act_context_obj->act_op_mutex);
  239. cxt = act_context_obj;
  240. if (NULL == cxt->act_ctl.open_report_data) {
  241. ACT_LOG("act_ctl enable NULL\n");
  242. mutex_unlock(&act_context_obj->act_op_mutex);
  243. return count;
  244. }
  245. if (!strncmp(buf, "1", 1))
  246. act_enable_data(1);
  247. else if (!strncmp(buf, "0", 1))
  248. act_enable_data(0);
  249. else
  250. ACT_ERR(" act_store_active error !!\n");
  251. mutex_unlock(&act_context_obj->act_op_mutex);
  252. ACT_LOG(" act_store_active done\n");
  253. return count;
  254. }
  255. /*----------------------------------------------------------------------------*/
  256. static ssize_t act_show_active(struct device *dev, struct device_attribute *attr, char *buf)
  257. {
  258. struct act_context *cxt = NULL;
  259. int div = 0;
  260. cxt = act_context_obj;
  261. /* int len = 0; */
  262. ACT_LOG("act show active not support now\n");
  263. /* div=cxt->act_data.vender_div; */
  264. ACT_LOG("act vender_div value: %d\n", div);
  265. return snprintf(buf, PAGE_SIZE, "%d\n", div);
  266. /* return len; */
  267. }
  268. static ssize_t act_store_delay(struct device *dev, struct device_attribute *attr,
  269. const char *buf, size_t count)
  270. {
  271. /* struct act_context *devobj = (struct act_context*)dev_get_drvdata(dev); */
  272. int delay;
  273. int mdelay = 0;
  274. struct act_context *cxt = NULL;
  275. int err = 0;
  276. mutex_lock(&act_context_obj->act_op_mutex);
  277. cxt = act_context_obj;
  278. if (NULL == cxt->act_ctl.set_delay) {
  279. ACT_LOG("act_ctl set_delay NULL\n");
  280. mutex_unlock(&act_context_obj->act_op_mutex);
  281. return count;
  282. }
  283. err = kstrtoint(buf, 10, &delay);
  284. if (0 != err) {
  285. ACT_ERR("invalid format!!\n");
  286. mutex_unlock(&act_context_obj->act_op_mutex);
  287. return count;
  288. }
  289. if (false == cxt->act_ctl.is_report_input_direct) {
  290. mdelay = (int)delay / 1000 / 1000;
  291. atomic_set(&act_context_obj->delay, mdelay);
  292. }
  293. cxt->act_ctl.set_delay(delay);
  294. ACT_LOG(" act_delay %d ns\n", delay);
  295. mutex_unlock(&act_context_obj->act_op_mutex);
  296. return count;
  297. }
  298. static ssize_t act_show_delay(struct device *dev, struct device_attribute *attr, char *buf)
  299. {
  300. int len = 0;
  301. ACT_LOG(" not support now\n");
  302. return len;
  303. }
  304. static ssize_t act_store_batch(struct device *dev, struct device_attribute *attr,
  305. const char *buf, size_t count)
  306. {
  307. struct act_context *cxt = NULL;
  308. /* int err =0; */
  309. ACT_LOG("act_store_batch buf=%s\n", buf);
  310. mutex_lock(&act_context_obj->act_op_mutex);
  311. cxt = act_context_obj;
  312. if (cxt->act_ctl.is_support_batch) {
  313. if (!strncmp(buf, "1", 1))
  314. cxt->is_batch_enable = true;
  315. else if (!strncmp(buf, "0", 1))
  316. cxt->is_batch_enable = false;
  317. else
  318. ACT_ERR(" act_store_batch error !!\n");
  319. } else {
  320. ACT_LOG(" act_store_batch not support\n");
  321. }
  322. mutex_unlock(&act_context_obj->act_op_mutex);
  323. ACT_LOG(" act_store_batch done: %d\n", cxt->is_batch_enable);
  324. return count;
  325. }
  326. static ssize_t act_show_batch(struct device *dev, struct device_attribute *attr, char *buf)
  327. {
  328. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  329. }
  330. static ssize_t act_store_flush(struct device *dev, struct device_attribute *attr,
  331. const char *buf, size_t count)
  332. {
  333. /* mutex_lock(&act_context_obj->act_op_mutex); */
  334. /* struct act_context *devobj = (struct act_context*)dev_get_drvdata(dev); */
  335. /* do read FIFO data function and report data immediately */
  336. /* mutex_unlock(&act_context_obj->act_op_mutex); */
  337. return count;
  338. }
  339. static ssize_t act_show_flush(struct device *dev, struct device_attribute *attr, char *buf)
  340. {
  341. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  342. }
  343. static ssize_t act_show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
  344. {
  345. const char *devname = NULL;
  346. devname = dev_name(&act_context_obj->idev->dev);
  347. return snprintf(buf, PAGE_SIZE, "%s\n", devname + 5);
  348. }
  349. static int activity_remove(struct platform_device *pdev)
  350. {
  351. ACT_LOG("activity_remove\n");
  352. return 0;
  353. }
  354. static int activity_probe(struct platform_device *pdev)
  355. {
  356. ACT_LOG("activity_probe\n");
  357. return 0;
  358. }
  359. #ifdef CONFIG_OF
  360. static const struct of_device_id activity_of_match[] = {
  361. {.compatible = "mediatek,activity",},
  362. {},
  363. };
  364. #endif
  365. static struct platform_driver activity_driver = {
  366. .probe = activity_probe,
  367. .remove = activity_remove,
  368. .driver = {
  369. .name = "activity",
  370. #ifdef CONFIG_OF
  371. .of_match_table = activity_of_match,
  372. #endif
  373. }
  374. };
  375. static int act_real_driver_init(void)
  376. {
  377. int i = 0;
  378. int err = 0;
  379. ACT_LOG(" act_real_driver_init +\n");
  380. for (i = 0; i < MAX_CHOOSE_ACT_NUM; i++) {
  381. ACT_LOG(" i=%d\n", i);
  382. if (0 != activity_init_list[i]) {
  383. ACT_LOG(" act try to init driver %s\n", activity_init_list[i]->name);
  384. err = activity_init_list[i]->init();
  385. if (0 == err) {
  386. ACT_LOG(" act real driver %s probe ok\n",
  387. activity_init_list[i]->name);
  388. break;
  389. }
  390. }
  391. }
  392. if (i == MAX_CHOOSE_ACT_NUM) {
  393. ACT_LOG(" act_real_driver_init fail\n");
  394. err = -1;
  395. }
  396. return err;
  397. }
  398. int act_driver_add(struct act_init_info *obj)
  399. {
  400. int err = 0;
  401. int i = 0;
  402. ACT_FUN(f);
  403. for (i = 0; i < MAX_CHOOSE_ACT_NUM; i++) {
  404. if (i == 0) {
  405. ACT_LOG("register act driver for the first time\n");
  406. err = platform_driver_register(&activity_driver);
  407. if (err)
  408. ACT_ERR("failed to register act driver already exist\n");
  409. }
  410. if (NULL == activity_init_list[i]) {
  411. obj->platform_diver_addr = &activity_driver;
  412. activity_init_list[i] = obj;
  413. break;
  414. }
  415. }
  416. if (NULL == activity_init_list[i]) {
  417. ACT_ERR("act driver add err\n");
  418. err = -1;
  419. }
  420. return err;
  421. } EXPORT_SYMBOL_GPL(act_driver_add);
  422. static int act_misc_init(struct act_context *cxt)
  423. {
  424. int err = 0;
  425. /* kernel-3.10\include\linux\Miscdevice.h */
  426. /* use MISC_DYNAMIC_MINOR exceed 64 */
  427. cxt->mdev.minor = M_ACT_MISC_MINOR;
  428. cxt->mdev.name = ACT_MISC_DEV_NAME;
  429. err = misc_register(&cxt->mdev);
  430. if (err)
  431. ACT_ERR("unable to register act misc device!!\n");
  432. return err;
  433. }
  434. static void act_input_destroy(struct act_context *cxt)
  435. {
  436. struct input_dev *dev = cxt->idev;
  437. input_unregister_device(dev);
  438. input_free_device(dev);
  439. }
  440. static int act_input_init(struct act_context *cxt)
  441. {
  442. struct input_dev *dev;
  443. int err = 0;
  444. dev = input_allocate_device();
  445. if (NULL == dev)
  446. return -ENOMEM;
  447. dev->name = ACT_INPUTDEV_NAME;
  448. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_IN_VEHICLE);
  449. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_ON_BICYCLE);
  450. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_ON_FOOT);
  451. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_STILL);
  452. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_UNKNOWN);
  453. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_TILT);
  454. input_set_capability(dev, EV_ABS, EVENT_TYPE_ACT_STATUS);
  455. input_set_abs_params(dev, EVENT_TYPE_ACT_IN_VEHICLE, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  456. input_set_abs_params(dev, EVENT_TYPE_ACT_ON_BICYCLE, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  457. input_set_abs_params(dev, EVENT_TYPE_ACT_ON_FOOT, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  458. input_set_abs_params(dev, EVENT_TYPE_ACT_STILL, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  459. input_set_abs_params(dev, EVENT_TYPE_ACT_UNKNOWN, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  460. input_set_abs_params(dev, EVENT_TYPE_ACT_TILT, ACT_VALUE_MIN, ACT_VALUE_MAX, 0, 0);
  461. input_set_abs_params(dev, EVENT_TYPE_ACT_STATUS, ACT_STATUS_MIN, ACT_STATUS_MAX, 0, 0);
  462. input_set_drvdata(dev, cxt);
  463. err = input_register_device(dev);
  464. if (err < 0) {
  465. input_free_device(dev);
  466. return err;
  467. }
  468. cxt->idev = dev;
  469. return 0;
  470. }
  471. DEVICE_ATTR(actenablenodata, S_IWUSR | S_IRUGO, act_show_enable_nodata, act_store_enable_nodata);
  472. DEVICE_ATTR(actactive, S_IWUSR | S_IRUGO, act_show_active, act_store_active);
  473. DEVICE_ATTR(actdelay, S_IWUSR | S_IRUGO, act_show_delay, act_store_delay);
  474. DEVICE_ATTR(actbatch, S_IWUSR | S_IRUGO, act_show_batch, act_store_batch);
  475. DEVICE_ATTR(actflush, S_IWUSR | S_IRUGO, act_show_flush, act_store_flush);
  476. DEVICE_ATTR(actdevnum, S_IWUSR | S_IRUGO, act_show_devnum, NULL);
  477. static struct attribute *act_attributes[] = {
  478. &dev_attr_actenablenodata.attr,
  479. &dev_attr_actactive.attr,
  480. &dev_attr_actdelay.attr,
  481. &dev_attr_actbatch.attr,
  482. &dev_attr_actflush.attr,
  483. &dev_attr_actdevnum.attr,
  484. NULL
  485. };
  486. static struct attribute_group act_attribute_group = {
  487. .attrs = act_attributes
  488. };
  489. int act_register_data_path(struct act_data_path *data)
  490. {
  491. struct act_context *cxt = NULL;
  492. /* int err =0; */
  493. cxt = act_context_obj;
  494. cxt->act_data.get_data = data->get_data;
  495. /* cxt->act_data.vender_div = data->vender_div; */
  496. /* cxt->act_data.get_raw_data = data->get_raw_data; */
  497. /* ACT_LOG("act register data path vender_div: %d\n", cxt->act_data.vender_div); */
  498. if (NULL == cxt->act_data.get_data) {
  499. ACT_LOG("act register data path fail\n");
  500. return -1;
  501. }
  502. return 0;
  503. }
  504. int act_register_control_path(struct act_control_path *ctl)
  505. {
  506. struct act_context *cxt = NULL;
  507. int err = 0;
  508. cxt = act_context_obj;
  509. cxt->act_ctl.set_delay = ctl->set_delay;
  510. cxt->act_ctl.open_report_data = ctl->open_report_data;
  511. cxt->act_ctl.enable_nodata = ctl->enable_nodata;
  512. cxt->act_ctl.is_support_batch = ctl->is_support_batch;
  513. if (NULL == cxt->act_ctl.set_delay || NULL == cxt->act_ctl.open_report_data
  514. || NULL == cxt->act_ctl.enable_nodata) {
  515. ACT_LOG("act register control path fail\n");
  516. return -1;
  517. }
  518. /* add misc dev for sensor hal control cmd */
  519. err = act_misc_init(act_context_obj);
  520. if (err) {
  521. ACT_ERR("unable to register act misc device!!\n");
  522. return -2;
  523. }
  524. err = sysfs_create_group(&act_context_obj->mdev.this_device->kobj, &act_attribute_group);
  525. if (err < 0) {
  526. ACT_ERR("unable to create act attribute file\n");
  527. return -3;
  528. }
  529. kobject_uevent(&act_context_obj->mdev.this_device->kobj, KOBJ_ADD);
  530. return 0;
  531. }
  532. int act_data_report(hwm_sensor_data data, int status)
  533. {
  534. struct act_context *cxt = NULL;
  535. int err = 0;
  536. /* ACT_LOG("+act_data_report! %d, %d, %d, %d\n",x,y,z,status); */
  537. ACT_LOG("+act_data_report! %d, %d, %d, %d %d %d\n",
  538. data.values[0], data.values[1], data.values[2], data.values[3], data.values[4],
  539. data.values[5]);
  540. cxt = act_context_obj;
  541. input_report_abs(cxt->idev, EVENT_TYPE_ACT_IN_VEHICLE, data.values[0]);
  542. input_report_abs(cxt->idev, EVENT_TYPE_ACT_ON_BICYCLE, data.values[1]);
  543. input_report_abs(cxt->idev, EVENT_TYPE_ACT_ON_FOOT, data.values[2]);
  544. input_report_abs(cxt->idev, EVENT_TYPE_ACT_STILL, data.values[3]);
  545. input_report_abs(cxt->idev, EVENT_TYPE_ACT_UNKNOWN, data.values[4]);
  546. input_report_abs(cxt->idev, EVENT_TYPE_ACT_TILT, data.values[5]);
  547. input_report_abs(cxt->idev, EVENT_TYPE_ACT_STATUS, status);
  548. input_sync(cxt->idev);
  549. return err;
  550. }
  551. static int act_probe(struct platform_device *pdev)
  552. {
  553. int err;
  554. ACT_LOG("+++++++++++++act_probe!!\n");
  555. act_context_obj = act_context_alloc_object();
  556. if (!act_context_obj) {
  557. err = -ENOMEM;
  558. ACT_ERR("unable to allocate devobj!\n");
  559. goto exit_alloc_data_failed;
  560. }
  561. /* init real acteleration driver */
  562. err = act_real_driver_init();
  563. if (err) {
  564. ACT_ERR("act real driver init fail\n");
  565. goto real_driver_init_fail;
  566. }
  567. /* err = act_factory_device_init(); */
  568. /* if(err) */
  569. /* { */
  570. /* ACT_ERR("act_factory_device_init fail\n"); */
  571. /* } */
  572. /* init input dev */
  573. err = act_input_init(act_context_obj);
  574. if (err) {
  575. ACT_ERR("unable to register act input device!\n");
  576. goto exit_alloc_input_dev_failed;
  577. }
  578. #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_EARLYSUSPEND)
  579. atomic_set(&(act_context_obj->early_suspend), 0);
  580. act_context_obj->early_drv.level = EARLY_SUSPEND_LEVEL_STOP_DRAWING - 1,
  581. act_context_obj->early_drv.suspend = act_early_suspend,
  582. act_context_obj->early_drv.resume = act_late_resume,
  583. register_early_suspend(&act_context_obj->early_drv);
  584. #endif /* #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_EARLYSUSPEND) */
  585. ACT_LOG("----act_probe OK !!\n");
  586. return 0;
  587. /* exit_hwmsen_create_attr_failed: */
  588. /* exit_misc_register_failed: */
  589. /* exit_err_sysfs: */
  590. if (err) {
  591. ACT_ERR("sysfs node creation error\n");
  592. act_input_destroy(act_context_obj);
  593. }
  594. real_driver_init_fail:
  595. exit_alloc_input_dev_failed:
  596. kfree(act_context_obj);
  597. exit_alloc_data_failed:
  598. ACT_LOG("----act_probe fail !!!\n");
  599. return err;
  600. }
  601. static int act_remove(struct platform_device *pdev)
  602. {
  603. int err = 0;
  604. ACT_FUN(f);
  605. input_unregister_device(act_context_obj->idev);
  606. sysfs_remove_group(&act_context_obj->idev->dev.kobj, &act_attribute_group);
  607. err = misc_deregister(&act_context_obj->mdev);
  608. if (err)
  609. ACT_ERR("misc_deregister fail: %d\n", err);
  610. kfree(act_context_obj);
  611. return 0;
  612. }
  613. static void act_early_suspend(struct early_suspend *h)
  614. {
  615. atomic_set(&(act_context_obj->early_suspend), 1);
  616. ACT_LOG("act_early_suspend ok------->hwm_obj->early_suspend=%d\n",
  617. atomic_read(&(act_context_obj->early_suspend);
  618. }
  619. /*----------------------------------------------------------------------------*/
  620. static void act_late_resume(struct early_suspend *h)
  621. {
  622. atomic_set(&(act_context_obj->early_suspend), 0);
  623. ACT_LOG("act_late_resume ok------->hwm_obj->early_suspend=%d\n",
  624. atomic_read(&(act_context_obj->early_suspend)));
  625. }
  626. static int act_suspend(struct platform_device *dev, pm_message_t state)
  627. {
  628. return 0;
  629. }
  630. /*----------------------------------------------------------------------------*/
  631. static int act_resume(struct platform_device *dev)
  632. {
  633. return 0;
  634. }
  635. #ifdef CONFIG_OF
  636. static const struct of_device_id m_act_pl_of_match[] = {
  637. {.compatible = "mediatek,m_act_pl",},
  638. {},
  639. };
  640. #endif
  641. static struct platform_driver act_driver = {
  642. .probe = act_probe,
  643. .remove = act_remove,
  644. .suspend = act_suspend,
  645. .resume = act_resume,
  646. .driver = {
  647. .name = ACT_PL_DEV_NAME, /* mt_act_pl */
  648. #ifdef CONFIG_OF
  649. .of_match_table = m_act_pl_of_match,
  650. #endif
  651. }
  652. };
  653. static int __init act_init(void)
  654. {
  655. ACT_FUN(f);
  656. if (platform_driver_register(&act_driver)) {
  657. ACT_ERR("failed to register act driver\n");
  658. return -ENODEV;
  659. }
  660. return 0;
  661. }
  662. static void __exit act_exit(void)
  663. {
  664. platform_driver_unregister(&act_driver);
  665. platform_driver_unregister(&activity_driver);
  666. }
  667. late_initcall(act_init);
  668. MODULE_LICENSE("GPL");
  669. MODULE_DESCRIPTION("ACTIVITY device driver");
  670. MODULE_AUTHOR("Mediatek");