linearacceleration.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. #include "linearacceleration.h"
  2. static struct la_context *la_context_obj;
  3. static struct la_init_info *linearaccelerationsensor_init_list[MAX_CHOOSE_LA_NUM] = { 0 }; /* modified */
  4. #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_EARLYSUSPEND)
  5. static void la_early_suspend(struct early_suspend *h);
  6. static void la_late_resume(struct early_suspend *h);
  7. #endif
  8. static void la_work_func(struct work_struct *work)
  9. {
  10. struct la_context *cxt = NULL;
  11. int x, y, z, status;
  12. int64_t nt;
  13. struct timespec time;
  14. int err;
  15. LA_FUN();
  16. cxt = la_context_obj;
  17. if (NULL == cxt->la_data.get_data)
  18. LA_LOG("la driver not register data path\n");
  19. time.tv_sec = time.tv_nsec = 0;
  20. time = get_monotonic_coarse();
  21. nt = time.tv_sec * 1000000000LL + time.tv_nsec;
  22. err = cxt->la_data.get_data(&x, &y, &z, &status);
  23. if (err) {
  24. LA_ERR("get la data fails!!\n");
  25. goto la_loop;
  26. } else {
  27. {
  28. if (0 == x && 0 == y && 0 == z)
  29. goto la_loop;
  30. cxt->drv_data.la_data.values[0] = x + cxt->cali_sw[0];
  31. cxt->drv_data.la_data.values[1] = y + cxt->cali_sw[1];
  32. cxt->drv_data.la_data.values[2] = z + cxt->cali_sw[2];
  33. cxt->drv_data.la_data.status = status;
  34. cxt->drv_data.la_data.time = nt;
  35. }
  36. }
  37. if (true == cxt->is_first_data_after_enable) {
  38. cxt->is_first_data_after_enable = false;
  39. if (LA_INVALID_VALUE == cxt->drv_data.la_data.values[0] ||
  40. LA_INVALID_VALUE == cxt->drv_data.la_data.values[1] ||
  41. LA_INVALID_VALUE == cxt->drv_data.la_data.values[2]) {
  42. LA_LOG(" read invalid data\n");
  43. goto la_loop;
  44. }
  45. }
  46. la_data_report(cxt->drv_data.la_data.values[0],
  47. cxt->drv_data.la_data.values[1], cxt->drv_data.la_data.values[2],
  48. cxt->drv_data.la_data.status);
  49. la_loop:
  50. if (true == cxt->is_polling_run)
  51. mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  52. }
  53. static void la_poll(unsigned long data)
  54. {
  55. struct la_context *obj = (struct la_context *)data;
  56. if (obj != NULL)
  57. schedule_work(&obj->report);
  58. }
  59. static struct la_context *la_context_alloc_object(void)
  60. {
  61. struct la_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  62. LA_LOG("la_context_alloc_object++++\n");
  63. if (!obj) {
  64. LA_ERR("Alloc linearacceleration object error!\n");
  65. return NULL;
  66. }
  67. atomic_set(&obj->delay, 200); /*5Hz set work queue delay time 200ms */
  68. atomic_set(&obj->wake, 0);
  69. INIT_WORK(&obj->report, la_work_func);
  70. init_timer(&obj->timer);
  71. obj->timer.expires = jiffies + atomic_read(&obj->delay) / (1000 / HZ);
  72. obj->timer.function = la_poll;
  73. obj->timer.data = (unsigned long)obj;
  74. obj->is_first_data_after_enable = false;
  75. obj->is_polling_run = false;
  76. mutex_init(&obj->la_op_mutex);
  77. obj->is_batch_enable = false; /* for batch mode init */
  78. obj->cali_sw[LA_AXIS_X] = 0;
  79. obj->cali_sw[LA_AXIS_Y] = 0;
  80. obj->cali_sw[LA_AXIS_Z] = 0;
  81. LA_LOG("la_context_alloc_object----\n");
  82. return obj;
  83. }
  84. static int la_real_enable(int enable)
  85. {
  86. int err = 0;
  87. struct la_context *cxt = NULL;
  88. LA_FUN();
  89. cxt = la_context_obj;
  90. if (1 == enable) {
  91. if (true == cxt->is_active_data || true == cxt->is_active_nodata) {
  92. err = cxt->la_ctl.enable_nodata(1);
  93. if (err) {
  94. err = cxt->la_ctl.enable_nodata(1);
  95. if (err) {
  96. err = cxt->la_ctl.enable_nodata(1);
  97. if (err)
  98. LA_ERR("la enable(%d) err 3 timers = %d\n", enable,
  99. err);
  100. }
  101. }
  102. LA_LOG("la real enable\n");
  103. }
  104. }
  105. if (0 == enable) {
  106. if (false == cxt->is_active_data && false == cxt->is_active_nodata) {
  107. err = cxt->la_ctl.enable_nodata(0);
  108. if (err)
  109. LA_ERR("la enable(%d) err = %d\n", enable, err);
  110. LA_LOG("la real disable\n");
  111. }
  112. }
  113. return err;
  114. }
  115. static int la_enable_data(int enable)
  116. {
  117. struct la_context *cxt = NULL;
  118. LA_FUN();
  119. /* int err =0; */
  120. cxt = la_context_obj;
  121. if (NULL == cxt->la_ctl.open_report_data) {
  122. LA_ERR("no la control path\n");
  123. return -1;
  124. }
  125. if (1 == enable) {
  126. LA_LOG("LA enable data\n");
  127. cxt->is_active_data = true;
  128. cxt->is_first_data_after_enable = true;
  129. cxt->la_ctl.open_report_data(1);
  130. la_real_enable(enable);
  131. if (false == cxt->is_polling_run && cxt->is_batch_enable == false) {
  132. if (false == cxt->la_ctl.is_report_input_direct) {
  133. mod_timer(&cxt->timer,
  134. jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  135. cxt->is_polling_run = true;
  136. }
  137. }
  138. }
  139. if (0 == enable) {
  140. LA_LOG("LA disable\n");
  141. cxt->is_active_data = false;
  142. cxt->la_ctl.open_report_data(0);
  143. if (true == cxt->is_polling_run) {
  144. if (false == cxt->la_ctl.is_report_input_direct) {
  145. cxt->is_polling_run = false;
  146. del_timer_sync(&cxt->timer);
  147. cancel_work_sync(&cxt->report);
  148. cxt->drv_data.la_data.values[0] = LA_INVALID_VALUE;
  149. cxt->drv_data.la_data.values[1] = LA_INVALID_VALUE;
  150. cxt->drv_data.la_data.values[2] = LA_INVALID_VALUE;
  151. }
  152. }
  153. la_real_enable(enable);
  154. }
  155. return 0;
  156. }
  157. int la_enable_nodata(int enable)
  158. {
  159. struct la_context *cxt = NULL;
  160. /* int err =0; */
  161. cxt = la_context_obj;
  162. if (NULL == cxt->la_ctl.enable_nodata) {
  163. LA_ERR("la_enable_nodata:la ctl path is NULL\n");
  164. return -1;
  165. }
  166. if (1 == enable)
  167. cxt->is_active_nodata = true;
  168. if (0 == enable)
  169. cxt->is_active_nodata = false;
  170. la_real_enable(enable);
  171. return 0;
  172. }
  173. static ssize_t la_show_enable_nodata(struct device *dev, struct device_attribute *attr, char *buf)
  174. {
  175. int len = 0;
  176. LA_LOG(" not support now\n");
  177. return len;
  178. }
  179. static ssize_t la_store_enable_nodata(struct device *dev, struct device_attribute *attr,
  180. const char *buf, size_t count)
  181. {
  182. struct la_context *cxt = NULL;
  183. /* int err =0; */
  184. LA_LOG("la_store_enable nodata buf=%s\n", buf);
  185. mutex_lock(&la_context_obj->la_op_mutex);
  186. cxt = la_context_obj;
  187. if (NULL == cxt->la_ctl.enable_nodata) {
  188. LA_LOG("la_ctl enable nodata NULL\n");
  189. mutex_unlock(&la_context_obj->la_op_mutex);
  190. return count;
  191. }
  192. if (!strncmp(buf, "1", 1)) {
  193. /* cxt->la_ctl.enable_nodata(1); */
  194. la_enable_nodata(1);
  195. } else if (!strncmp(buf, "0", 1)) {
  196. /* cxt->la_ctl.enable_nodata(0); */
  197. la_enable_nodata(0);
  198. } else {
  199. LA_ERR(" la_store enable nodata cmd error !!\n");
  200. }
  201. mutex_unlock(&la_context_obj->la_op_mutex);
  202. return count;
  203. }
  204. static ssize_t la_store_active(struct device *dev, struct device_attribute *attr,
  205. const char *buf, size_t count)
  206. {
  207. struct la_context *cxt = NULL;
  208. LA_LOG("la_store_active buf=%s\n", buf);
  209. mutex_lock(&la_context_obj->la_op_mutex);
  210. cxt = la_context_obj;
  211. if (NULL == cxt->la_ctl.open_report_data) {
  212. LA_LOG("la_ctl enable NULL\n");
  213. mutex_unlock(&la_context_obj->la_op_mutex);
  214. return count;
  215. }
  216. if (!strncmp(buf, "1", 1)) {
  217. /* cxt->la_ctl.enable(1); */
  218. la_enable_data(1);
  219. } else if (!strncmp(buf, "0", 1)) {
  220. /* cxt->la_ctl.enable(0); */
  221. la_enable_data(0);
  222. } else {
  223. LA_ERR(" la_store_active error !!\n");
  224. }
  225. mutex_unlock(&la_context_obj->la_op_mutex);
  226. LA_LOG(" la_store_active done\n");
  227. return count;
  228. }
  229. /*----------------------------------------------------------------------------*/
  230. static ssize_t la_show_active(struct device *dev, struct device_attribute *attr, char *buf)
  231. {
  232. struct la_context *cxt = NULL;
  233. int div = 0;
  234. cxt = la_context_obj;
  235. div = cxt->la_data.vender_div;
  236. LA_LOG("la vender_div value: %d\n", div);
  237. return snprintf(buf, PAGE_SIZE, "%d\n", div);
  238. }
  239. static ssize_t la_store_delay(struct device *dev, struct device_attribute *attr,
  240. const char *buf, size_t count)
  241. {
  242. /* struct la_context *devobj = (struct la_context*)dev_get_drvdata(dev); */
  243. int delay = 0;
  244. int mdelay = 0;
  245. struct la_context *cxt = NULL;
  246. int err;
  247. mutex_lock(&la_context_obj->la_op_mutex);
  248. /* int err =0; */
  249. cxt = la_context_obj;
  250. if (NULL == cxt->la_ctl.set_delay) {
  251. LA_LOG("la_ctl set_delay NULL\n");
  252. mutex_unlock(&la_context_obj->la_op_mutex);
  253. return count;
  254. }
  255. err = kstrtoint(buf, 10, &delay);
  256. if (err != 0) {
  257. LA_ERR("invalid format!!\n");
  258. mutex_unlock(&la_context_obj->la_op_mutex);
  259. return count;
  260. }
  261. if (false == cxt->la_ctl.is_report_input_direct) {
  262. mdelay = (int)delay / 1000 / 1000;
  263. atomic_set(&la_context_obj->delay, mdelay);
  264. }
  265. cxt->la_ctl.set_delay(delay);
  266. LA_LOG(" la_delay %d ns\n", delay);
  267. mutex_unlock(&la_context_obj->la_op_mutex);
  268. return count;
  269. }
  270. static ssize_t la_show_delay(struct device *dev, struct device_attribute *attr, char *buf)
  271. {
  272. int len = 0;
  273. LA_LOG(" not support now\n");
  274. return len;
  275. }
  276. static ssize_t la_show_sensordevnum(struct device *dev, struct device_attribute *attr, char *buf)
  277. {
  278. struct la_context *cxt = NULL;
  279. const char *devname = NULL;
  280. cxt = la_context_obj;
  281. devname = dev_name(&cxt->idev->dev);
  282. return snprintf(buf, PAGE_SIZE, "%s\n", devname + 5);
  283. }
  284. static ssize_t la_store_batch(struct device *dev, struct device_attribute *attr,
  285. const char *buf, size_t count)
  286. {
  287. struct la_context *cxt = NULL;
  288. /* int err =0; */
  289. LA_LOG("la_store_batch buf=%s\n", buf);
  290. mutex_lock(&la_context_obj->la_op_mutex);
  291. cxt = la_context_obj;
  292. if (cxt->la_ctl.is_support_batch) {
  293. if (!strncmp(buf, "1", 1)) {
  294. cxt->is_batch_enable = true;
  295. /* MTK problem fix - start */
  296. if (cxt->is_active_data && cxt->is_polling_run) {
  297. cxt->is_polling_run = false;
  298. del_timer_sync(&cxt->timer);
  299. cancel_work_sync(&cxt->report);
  300. }
  301. /* MTK problem fix - end */
  302. } else if (!strncmp(buf, "0", 1)) {
  303. cxt->is_batch_enable = false;
  304. /* MTK problem fix - start */
  305. if (cxt->is_active_data)
  306. la_enable_data(true);
  307. /* MTK problem fix - end */
  308. } else {
  309. LA_ERR(" la_store_batch error !!\n");
  310. }
  311. } else {
  312. LA_LOG(" la_store_batch mot supported\n");
  313. }
  314. mutex_unlock(&la_context_obj->la_op_mutex);
  315. LA_LOG(" la_store_batch done: %d\n", cxt->is_batch_enable);
  316. return count;
  317. }
  318. static ssize_t la_show_batch(struct device *dev, struct device_attribute *attr, char *buf)
  319. {
  320. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  321. }
  322. static ssize_t la_store_flush(struct device *dev, struct device_attribute *attr,
  323. const char *buf, size_t count)
  324. {
  325. /* mutex_lock(&la_context_obj->la_op_mutex); */
  326. /* struct la_context *devobj = (struct la_context*)dev_get_drvdata(dev); */
  327. /* do read FIFO data function and report data immediately */
  328. /* mutex_unlock(&la_context_obj->la_op_mutex); */
  329. return count;
  330. }
  331. static ssize_t la_show_flush(struct device *dev, struct device_attribute *attr, char *buf)
  332. {
  333. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  334. }
  335. static int linearaccelerationsensor_remove(struct platform_device *pdev)
  336. {
  337. LA_LOG("linearaccelerationsensor_remove\n");
  338. return 0;
  339. }
  340. static int linearaccelerationsensor_probe(struct platform_device *pdev)
  341. {
  342. LA_LOG("linearaccelerationsensor_probe\n");
  343. return 0;
  344. }
  345. #ifdef CONFIG_OF
  346. static const struct of_device_id linearaccelerationsensor_of_match[] = {
  347. {.compatible = "mediatek,linearaccelerationsensor",},
  348. {},
  349. };
  350. #endif
  351. static struct platform_driver linearaccelerationsensor_driver = {
  352. .probe = linearaccelerationsensor_probe,
  353. .remove = linearaccelerationsensor_remove,
  354. .driver = {
  355. .name = "linearaccelerationsensor",
  356. #ifdef CONFIG_OF
  357. .of_match_table = linearaccelerationsensor_of_match,
  358. #endif
  359. }
  360. };
  361. static int la_real_driver_init(void)
  362. {
  363. int i = 0;
  364. int err = 0;
  365. LA_LOG(" la_real_driver_init +\n");
  366. for (i = 0; i < MAX_CHOOSE_LA_NUM; i++) {
  367. LA_LOG(" i=%d\n", i);
  368. if (0 != linearaccelerationsensor_init_list[i]) {
  369. LA_LOG(" la try to init driver %s\n",
  370. linearaccelerationsensor_init_list[i]->name);
  371. err = linearaccelerationsensor_init_list[i]->init();
  372. if (0 == err) {
  373. LA_LOG(" la real driver %s probe ok\n",
  374. linearaccelerationsensor_init_list[i]->name);
  375. break;
  376. }
  377. }
  378. }
  379. if (i == MAX_CHOOSE_LA_NUM) {
  380. LA_LOG(" la_real_driver_init fail\n");
  381. err = -1;
  382. }
  383. return err;
  384. }
  385. static int la_misc_init(struct la_context *cxt)
  386. {
  387. int err = 0;
  388. cxt->mdev.minor = MISC_DYNAMIC_MINOR;
  389. cxt->mdev.name = LA_MISC_DEV_NAME;
  390. err = misc_register(&cxt->mdev);
  391. if (err)
  392. LA_ERR("unable to register la misc device!!\n");
  393. /* dev_set_drvdata(cxt->mdev.this_device, cxt); */
  394. return err;
  395. }
  396. static void la_input_destroy(struct la_context *cxt)
  397. {
  398. struct input_dev *dev = cxt->idev;
  399. input_unregister_device(dev);
  400. input_free_device(dev);
  401. }
  402. static int la_input_init(struct la_context *cxt)
  403. {
  404. struct input_dev *dev;
  405. int err = 0;
  406. dev = input_allocate_device();
  407. if (NULL == dev)
  408. return -ENOMEM;
  409. dev->name = LA_INPUTDEV_NAME;
  410. input_set_capability(dev, EV_ABS, EVENT_TYPE_LA_X);
  411. input_set_capability(dev, EV_ABS, EVENT_TYPE_LA_Y);
  412. input_set_capability(dev, EV_ABS, EVENT_TYPE_LA_Z);
  413. input_set_capability(dev, EV_REL, EVENT_TYPE_LA_STATUS);
  414. input_set_abs_params(dev, EVENT_TYPE_LA_X, LA_VALUE_MIN, LA_VALUE_MAX, 0, 0);
  415. input_set_abs_params(dev, EVENT_TYPE_LA_Y, LA_VALUE_MIN, LA_VALUE_MAX, 0, 0);
  416. input_set_abs_params(dev, EVENT_TYPE_LA_Z, LA_VALUE_MIN, LA_VALUE_MAX, 0, 0);
  417. input_set_drvdata(dev, cxt);
  418. input_set_events_per_packet(dev, 32); /* test */
  419. err = input_register_device(dev);
  420. if (err < 0) {
  421. input_free_device(dev);
  422. return err;
  423. }
  424. cxt->idev = dev;
  425. return 0;
  426. }
  427. DEVICE_ATTR(laenablenodata, S_IWUSR | S_IRUGO, la_show_enable_nodata, la_store_enable_nodata);
  428. DEVICE_ATTR(laactive, S_IWUSR | S_IRUGO, la_show_active, la_store_active);
  429. DEVICE_ATTR(ladelay, S_IWUSR | S_IRUGO, la_show_delay, la_store_delay);
  430. DEVICE_ATTR(labatch, S_IWUSR | S_IRUGO, la_show_batch, la_store_batch);
  431. DEVICE_ATTR(laflush, S_IWUSR | S_IRUGO, la_show_flush, la_store_flush);
  432. DEVICE_ATTR(ladevnum, S_IWUSR | S_IRUGO, la_show_sensordevnum, NULL);
  433. static struct attribute *la_attributes[] = {
  434. &dev_attr_laenablenodata.attr,
  435. &dev_attr_laactive.attr,
  436. &dev_attr_ladelay.attr,
  437. &dev_attr_labatch.attr,
  438. &dev_attr_laflush.attr,
  439. &dev_attr_ladevnum.attr,
  440. NULL
  441. };
  442. static struct attribute_group la_attribute_group = {
  443. .attrs = la_attributes
  444. };
  445. int la_register_data_path(struct la_data_path *data)
  446. {
  447. struct la_context *cxt = NULL;
  448. /* int err =0; */
  449. cxt = la_context_obj;
  450. cxt->la_data.get_data = data->get_data;
  451. cxt->la_data.get_raw_data = data->get_raw_data;
  452. cxt->la_data.vender_div = data->vender_div;
  453. LA_LOG("la register data path vender_div: %d\n", cxt->la_data.vender_div);
  454. if (NULL == cxt->la_data.get_data) {
  455. LA_LOG("la register data path fail\n");
  456. return -1;
  457. }
  458. return 0;
  459. }
  460. int la_register_control_path(struct la_control_path *ctl)
  461. {
  462. struct la_context *cxt = NULL;
  463. int err = 0;
  464. cxt = la_context_obj;
  465. cxt->la_ctl.set_delay = ctl->set_delay;
  466. cxt->la_ctl.open_report_data = ctl->open_report_data;
  467. cxt->la_ctl.enable_nodata = ctl->enable_nodata;
  468. cxt->la_ctl.is_support_batch = ctl->is_support_batch;
  469. cxt->la_ctl.is_report_input_direct = ctl->is_report_input_direct;
  470. cxt->la_ctl.la_calibration = ctl->la_calibration;
  471. if (NULL == cxt->la_ctl.set_delay || NULL == cxt->la_ctl.open_report_data
  472. || NULL == cxt->la_ctl.enable_nodata) {
  473. LA_LOG("la register control path fail\n");
  474. return -1;
  475. }
  476. /* add misc dev for sensor hal control cmd */
  477. err = la_misc_init(la_context_obj);
  478. if (err) {
  479. LA_ERR("unable to register la misc device!!\n");
  480. return -2;
  481. }
  482. err = sysfs_create_group(&la_context_obj->mdev.this_device->kobj, &la_attribute_group);
  483. if (err < 0) {
  484. LA_ERR("unable to create la attribute file\n");
  485. return -3;
  486. }
  487. kobject_uevent(&la_context_obj->mdev.this_device->kobj, KOBJ_ADD);
  488. return 0;
  489. }
  490. int la_data_report(int x, int y, int z, int status)
  491. {
  492. struct la_context *cxt = NULL;
  493. int err = 0;
  494. cxt = la_context_obj;
  495. LA_LOG("la_data_report! %d, %d, %d, %d\n", x, y, z, status);
  496. input_report_abs(cxt->idev, EVENT_TYPE_LA_X, x);
  497. input_report_abs(cxt->idev, EVENT_TYPE_LA_Y, y);
  498. input_report_abs(cxt->idev, EVENT_TYPE_LA_Z, z);
  499. input_report_rel(cxt->idev, EVENT_TYPE_LA_STATUS, status);
  500. input_sync(cxt->idev);
  501. return err;
  502. }
  503. static int la_probe(struct platform_device *pdev)
  504. {
  505. int err;
  506. LA_LOG("+++++++++++++linearacceleration_probe!!\n");
  507. la_context_obj = la_context_alloc_object();
  508. if (!la_context_obj) {
  509. err = -ENOMEM;
  510. LA_ERR("unable to allocate devobj!\n");
  511. goto exit_alloc_data_failed;
  512. }
  513. /* init real linearaccelerationeration driver */
  514. err = la_real_driver_init();
  515. if (err) {
  516. LA_ERR("la real driver init fail\n");
  517. goto real_driver_init_fail;
  518. }
  519. /* init input dev */
  520. err = la_input_init(la_context_obj);
  521. if (err) {
  522. LA_ERR("unable to register la input device!\n");
  523. goto exit_alloc_input_dev_failed;
  524. }
  525. #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_EARLYSUSPEND)
  526. atomic_set(&(la_context_obj->early_suspend), 0);
  527. la_context_obj->early_drv.level = 1; /* EARLY_SUSPEND_LEVEL_STOP_DRAWING - 1, */
  528. la_context_obj->early_drv.suspend = la_early_suspend,
  529. la_context_obj->early_drv.resume = la_late_resume,
  530. register_early_suspend(&la_context_obj->early_drv);
  531. #endif
  532. LA_LOG("----linearacceleration_probe OK !!\n");
  533. return 0;
  534. /* exit_hwmsen_create_attr_failed: */
  535. /* exit_misc_register_failed: */
  536. /* exit_err_sysfs: */
  537. if (err) {
  538. LA_ERR("sysfs node creation error\n");
  539. la_input_destroy(la_context_obj);
  540. }
  541. real_driver_init_fail:
  542. exit_alloc_input_dev_failed:
  543. kfree(la_context_obj);
  544. exit_alloc_data_failed:
  545. LA_LOG("----linearacceleration_probe fail !!!\n");
  546. return err;
  547. }
  548. static int la_remove(struct platform_device *pdev)
  549. {
  550. int err = 0;
  551. LA_FUN(f);
  552. input_unregister_device(la_context_obj->idev);
  553. sysfs_remove_group(&la_context_obj->idev->dev.kobj, &la_attribute_group);
  554. err = misc_deregister(&la_context_obj->mdev);
  555. if (err)
  556. LA_ERR("misc_deregister fail: %d\n", err);
  557. kfree(la_context_obj);
  558. return 0;
  559. }
  560. #if defined(CONFIG_HAS_EARLYSUSPEND) && defined(CONFIG_EARLYSUSPEND)
  561. static void la_early_suspend(struct early_suspend *h)
  562. {
  563. atomic_set(&(la_context_obj->early_suspend), 1);
  564. LA_LOG(" la_early_suspend ok------->hwm_obj->early_suspend=%d\n",
  565. atomic_read(&(la_context_obj->early_suspend)));
  566. }
  567. /*----------------------------------------------------------------------------*/
  568. static void la_late_resume(struct early_suspend *h)
  569. {
  570. atomic_set(&(la_context_obj->early_suspend), 0);
  571. LA_LOG(" la_late_resume ok------->hwm_obj->early_suspend=%d\n",
  572. atomic_read(&(la_context_obj->early_suspend)));
  573. }
  574. #endif
  575. static int la_suspend(struct platform_device *dev, pm_message_t state)
  576. {
  577. return 0;
  578. }
  579. /*----------------------------------------------------------------------------*/
  580. static int la_resume(struct platform_device *dev)
  581. {
  582. return 0;
  583. }
  584. #ifdef CONFIG_OF
  585. static const struct of_device_id m_la_pl_of_match[] = {
  586. {.compatible = "mediatek,m_la_pl",},
  587. {},
  588. };
  589. #endif
  590. static struct platform_driver la_driver = {
  591. .probe = la_probe,
  592. .remove = la_remove,
  593. .suspend = la_suspend,
  594. .resume = la_resume,
  595. .driver = {
  596. .name = LA_PL_DEV_NAME,
  597. #ifdef CONFIG_OF
  598. .of_match_table = m_la_pl_of_match,
  599. #endif
  600. }
  601. };
  602. int la_driver_add(struct la_init_info *obj)
  603. {
  604. int err = 0;
  605. int i = 0;
  606. LA_FUN();
  607. for (i = 0; i < MAX_CHOOSE_LA_NUM; i++) {
  608. if ((i == 0) && (NULL == linearaccelerationsensor_init_list[0])) {
  609. LA_LOG("register gensor driver for the first time\n");
  610. if (platform_driver_register(&linearaccelerationsensor_driver))
  611. LA_ERR("failed to register gensor driver already exist\n");
  612. }
  613. if (NULL == linearaccelerationsensor_init_list[i]) {
  614. obj->platform_diver_addr = &linearaccelerationsensor_driver;
  615. linearaccelerationsensor_init_list[i] = obj;
  616. break;
  617. }
  618. }
  619. if (i >= MAX_CHOOSE_LA_NUM) {
  620. LA_ERR("LA driver add err\n");
  621. err = -1;
  622. }
  623. return err;
  624. } EXPORT_SYMBOL_GPL(la_driver_add);
  625. static int __init la_init(void)
  626. {
  627. LA_FUN();
  628. if (platform_driver_register(&la_driver)) {
  629. LA_ERR("failed to register la driver\n");
  630. return -ENODEV;
  631. }
  632. return 0;
  633. }
  634. static void __exit la_exit(void)
  635. {
  636. platform_driver_unregister(&la_driver);
  637. platform_driver_unregister(&linearaccelerationsensor_driver);
  638. }
  639. late_initcall(la_init);
  640. /* module_init(la_init); */
  641. /* module_exit(la_exit); */
  642. MODULE_LICENSE("GPL");
  643. MODULE_DESCRIPTION("LINEARACCEL device driver");
  644. MODULE_AUTHOR("Mediatek");