humidity.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. #include "inc/humidity.h"
  2. struct hmdy_context *hmdy_context_obj = NULL;
  3. static struct hmdy_init_info *humidity_init_list[MAX_CHOOSE_HMDY_NUM] = { 0 };
  4. static void hmdy_work_func(struct work_struct *work)
  5. {
  6. struct hmdy_context *cxt = NULL;
  7. int value = 0, status = 0;
  8. int64_t nt = 0;
  9. struct timespec time;
  10. int err = 0;
  11. cxt = hmdy_context_obj;
  12. if (NULL == cxt->hmdy_data.get_data)
  13. HMDY_LOG("hmdy driver not register data path\n");
  14. time.tv_sec = time.tv_nsec = 0;
  15. time = get_monotonic_coarse();
  16. nt = time.tv_sec * 1000000000LL + time.tv_nsec;
  17. err = cxt->hmdy_data.get_data(&value, &status);
  18. if (err) {
  19. HMDY_ERR("get hmdy data fails!!\n");
  20. goto hmdy_loop;
  21. } else {
  22. {
  23. cxt->drv_data.hmdy_data.values[0] = value;
  24. cxt->drv_data.hmdy_data.status = status;
  25. cxt->drv_data.hmdy_data.time = nt;
  26. }
  27. }
  28. if (true == cxt->is_first_data_after_enable) {
  29. cxt->is_first_data_after_enable = false;
  30. if (HMDY_INVALID_VALUE == cxt->drv_data.hmdy_data.values[0]) {
  31. HMDY_LOG(" read invalid data\n");
  32. goto hmdy_loop;
  33. }
  34. }
  35. hmdy_data_report(cxt->idev, cxt->drv_data.hmdy_data.values[0], cxt->drv_data.hmdy_data.status);
  36. hmdy_loop:
  37. if (true == cxt->is_polling_run) {
  38. {
  39. mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  40. }
  41. }
  42. }
  43. static void hmdy_poll(unsigned long data)
  44. {
  45. struct hmdy_context *obj = (struct hmdy_context *)data;
  46. if (obj != NULL)
  47. schedule_work(&obj->report);
  48. }
  49. static struct hmdy_context *hmdy_context_alloc_object(void)
  50. {
  51. struct hmdy_context *obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  52. HMDY_LOG("hmdy_context_alloc_object++++\n");
  53. if (!obj) {
  54. HMDY_ERR("Alloc hmdy object error!\n");
  55. return NULL;
  56. }
  57. atomic_set(&obj->delay, 200);
  58. atomic_set(&obj->wake, 0);
  59. INIT_WORK(&obj->report, hmdy_work_func);
  60. init_timer(&obj->timer);
  61. obj->timer.expires = jiffies + atomic_read(&obj->delay) / (1000 / HZ);
  62. obj->timer.function = hmdy_poll;
  63. obj->timer.data = (unsigned long)obj;
  64. obj->is_first_data_after_enable = false;
  65. obj->is_polling_run = false;
  66. mutex_init(&obj->hmdy_op_mutex);
  67. obj->is_batch_enable = false;
  68. HMDY_LOG("hmdy_context_alloc_object----\n");
  69. return obj;
  70. }
  71. static int hmdy_real_enable(int enable)
  72. {
  73. int err = 0;
  74. struct hmdy_context *cxt = NULL;
  75. cxt = hmdy_context_obj;
  76. if (1 == enable) {
  77. if (true == cxt->is_active_data || true == cxt->is_active_nodata) {
  78. err = cxt->hmdy_ctl.enable_nodata(1);
  79. if (err) {
  80. err = cxt->hmdy_ctl.enable_nodata(1);
  81. if (err) {
  82. err = cxt->hmdy_ctl.enable_nodata(1);
  83. if (err)
  84. HMDY_ERR("hmdy enable(%d) err 3 timers = %d\n", enable, err);
  85. }
  86. }
  87. HMDY_LOG("hmdy real enable\n");
  88. }
  89. }
  90. if (0 == enable) {
  91. if (false == cxt->is_active_data && false == cxt->is_active_nodata) {
  92. err = cxt->hmdy_ctl.enable_nodata(0);
  93. if (err)
  94. HMDY_ERR("hmdy enable(%d) err = %d\n", enable, err);
  95. HMDY_LOG("hmdy real disable\n");
  96. }
  97. }
  98. return err;
  99. }
  100. static int hmdy_enable_data(int enable)
  101. {
  102. struct hmdy_context *cxt = NULL;
  103. cxt = hmdy_context_obj;
  104. if (NULL == cxt->hmdy_ctl.open_report_data) {
  105. HMDY_ERR("no hmdy control path\n");
  106. return -1;
  107. }
  108. if (1 == enable) {
  109. HMDY_LOG("HMDY enable data\n");
  110. cxt->is_active_data = true;
  111. cxt->is_first_data_after_enable = true;
  112. cxt->hmdy_ctl.open_report_data(1);
  113. hmdy_real_enable(enable);
  114. if (false == cxt->is_polling_run && cxt->is_batch_enable == false) {
  115. if (false == cxt->hmdy_ctl.is_report_input_direct) {
  116. mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  117. cxt->is_polling_run = true;
  118. }
  119. }
  120. }
  121. if (0 == enable) {
  122. HMDY_LOG("HMDY disable\n");
  123. cxt->is_active_data = false;
  124. cxt->hmdy_ctl.open_report_data(0);
  125. if (true == cxt->is_polling_run) {
  126. if (false == cxt->hmdy_ctl.is_report_input_direct) {
  127. cxt->is_polling_run = false;
  128. del_timer_sync(&cxt->timer);
  129. cancel_work_sync(&cxt->report);
  130. cxt->drv_data.hmdy_data.values[0] = HMDY_INVALID_VALUE;
  131. }
  132. }
  133. hmdy_real_enable(enable);
  134. }
  135. return 0;
  136. }
  137. int hmdy_enable_nodata(int enable)
  138. {
  139. struct hmdy_context *cxt = NULL;
  140. cxt = hmdy_context_obj;
  141. if (NULL == cxt->hmdy_ctl.enable_nodata) {
  142. HMDY_ERR("hmdy_enable_nodata:hmdy ctl path is NULL\n");
  143. return -1;
  144. }
  145. if (1 == enable)
  146. cxt->is_active_nodata = true;
  147. if (0 == enable)
  148. cxt->is_active_nodata = false;
  149. hmdy_real_enable(enable);
  150. return 0;
  151. }
  152. static ssize_t hmdy_show_enable_nodata(struct device *dev, struct device_attribute *attr, char *buf)
  153. {
  154. int len = 0;
  155. HMDY_LOG(" not support now\n");
  156. return len;
  157. }
  158. static ssize_t hmdy_store_enable_nodata(struct device *dev, struct device_attribute *attr,
  159. const char *buf, size_t count)
  160. {
  161. struct hmdy_context *cxt = NULL;
  162. HMDY_LOG("hmdy_store_enable nodata buf=%s\n", buf);
  163. mutex_lock(&hmdy_context_obj->hmdy_op_mutex);
  164. cxt = hmdy_context_obj;
  165. if (NULL == cxt->hmdy_ctl.enable_nodata) {
  166. HMDY_LOG("hmdy_ctl enable nodata NULL\n");
  167. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  168. return count;
  169. }
  170. if (!strncmp(buf, "1", 1))
  171. hmdy_enable_nodata(1);
  172. else if (!strncmp(buf, "0", 1))
  173. hmdy_enable_nodata(0);
  174. else
  175. HMDY_ERR(" hmdy_store enable nodata cmd error !!\n");
  176. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  177. return count;
  178. }
  179. static ssize_t hmdy_store_active(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  180. {
  181. struct hmdy_context *cxt = NULL;
  182. HMDY_LOG("hmdy_store_active buf=%s\n", buf);
  183. mutex_lock(&hmdy_context_obj->hmdy_op_mutex);
  184. cxt = hmdy_context_obj;
  185. if (NULL == cxt->hmdy_ctl.open_report_data) {
  186. HMDY_LOG("hmdy_ctl enable NULL\n");
  187. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  188. return count;
  189. }
  190. if (!strncmp(buf, "1", 1))
  191. hmdy_enable_data(1);
  192. else if (!strncmp(buf, "0", 1))
  193. hmdy_enable_data(0);
  194. else
  195. HMDY_ERR(" hmdy_store_active error !!\n");
  196. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  197. HMDY_LOG(" hmdy_store_active done\n");
  198. return count;
  199. }
  200. /*----------------------------------------------------------------------------*/
  201. static ssize_t hmdy_show_active(struct device *dev, struct device_attribute *attr, char *buf)
  202. {
  203. struct hmdy_context *cxt = NULL;
  204. int div = 0;
  205. cxt = hmdy_context_obj;
  206. div = cxt->hmdy_data.vender_div;
  207. HMDY_LOG("hmdy vender_div value: %d\n", div);
  208. return snprintf(buf, PAGE_SIZE, "%d\n", div);
  209. }
  210. static ssize_t hmdy_store_delay(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  211. {
  212. int delay = 0;
  213. int mdelay = 0;
  214. int err = 0;
  215. struct hmdy_context *cxt = NULL;
  216. mutex_lock(&hmdy_context_obj->hmdy_op_mutex);
  217. cxt = hmdy_context_obj;
  218. if (NULL == cxt->hmdy_ctl.set_delay) {
  219. HMDY_LOG("hmdy_ctl set_delay NULL\n");
  220. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  221. return count;
  222. }
  223. err = kstrtoint(buf, 10, &delay);
  224. if (err != 0) {
  225. HMDY_ERR("invalid format!!\n");
  226. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  227. return count;
  228. }
  229. if (false == cxt->hmdy_ctl.is_report_input_direct) {
  230. mdelay = (int)delay / 1000 / 1000;
  231. atomic_set(&hmdy_context_obj->delay, mdelay);
  232. }
  233. cxt->hmdy_ctl.set_delay(delay);
  234. HMDY_LOG(" hmdy_delay %d ns\n", delay);
  235. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  236. return count;
  237. }
  238. static ssize_t hmdy_show_delay(struct device *dev, struct device_attribute *attr, char *buf)
  239. {
  240. int len = 0;
  241. HMDY_LOG("not support now\n");
  242. return len;
  243. }
  244. static ssize_t hmdy_store_batch(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  245. {
  246. struct hmdy_context *cxt = NULL;
  247. HMDY_LOG("hmdy_store_batch buf=%s\n", buf);
  248. mutex_lock(&hmdy_context_obj->hmdy_op_mutex);
  249. cxt = hmdy_context_obj;
  250. if (!strncmp(buf, "1", 1)) {
  251. cxt->is_batch_enable = true;
  252. if (true == cxt->is_polling_run) {
  253. cxt->is_polling_run = false;
  254. del_timer_sync(&cxt->timer);
  255. cancel_work_sync(&cxt->report);
  256. cxt->drv_data.hmdy_data.values[0] = HMDY_INVALID_VALUE;
  257. cxt->drv_data.hmdy_data.values[1] = HMDY_INVALID_VALUE;
  258. cxt->drv_data.hmdy_data.values[2] = HMDY_INVALID_VALUE;
  259. }
  260. } else if (!strncmp(buf, "0", 1)) {
  261. cxt->is_batch_enable = false;
  262. if (false == cxt->is_polling_run) {
  263. if (false == cxt->hmdy_ctl.is_report_input_direct)
  264. mod_timer(&cxt->timer, jiffies + atomic_read(&cxt->delay) / (1000 / HZ));
  265. cxt->is_polling_run = true;
  266. }
  267. } else {
  268. HMDY_ERR(" hmdy_store_batch error !!\n");
  269. }
  270. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  271. HMDY_LOG(" hmdy_store_batch done: %d\n", cxt->is_batch_enable);
  272. return count;
  273. }
  274. static ssize_t hmdy_show_batch(struct device *dev, struct device_attribute *attr, char *buf)
  275. {
  276. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  277. }
  278. static ssize_t hmdy_store_flush(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
  279. {
  280. mutex_lock(&hmdy_context_obj->hmdy_op_mutex);
  281. mutex_unlock(&hmdy_context_obj->hmdy_op_mutex);
  282. return count;
  283. }
  284. static ssize_t hmdy_show_flush(struct device *dev, struct device_attribute *attr, char *buf)
  285. {
  286. return snprintf(buf, PAGE_SIZE, "%d\n", 0);
  287. }
  288. static ssize_t hmdy_show_devnum(struct device *dev, struct device_attribute *attr, char *buf)
  289. {
  290. const char *devname = NULL;
  291. devname = dev_name(&hmdy_context_obj->idev->dev);
  292. return snprintf(buf, PAGE_SIZE, "%s\n", devname + 5);
  293. }
  294. static int humidity_remove(struct platform_device *pdev)
  295. {
  296. HMDY_LOG("humidity_remove\n");
  297. return 0;
  298. }
  299. static int humidity_probe(struct platform_device *pdev)
  300. {
  301. HMDY_LOG("humidity_probe\n");
  302. return 0;
  303. }
  304. #ifdef CONFIG_OF
  305. static const struct of_device_id humidity_of_match[] = {
  306. {.compatible = "mediatek,humidity",},
  307. {},
  308. };
  309. #endif
  310. static struct platform_driver humidity_driver = {
  311. .probe = humidity_probe,
  312. .remove = humidity_remove,
  313. .driver = {
  314. .name = "humidity",
  315. #ifdef CONFIG_OF
  316. .of_match_table = humidity_of_match,
  317. #endif
  318. }
  319. };
  320. static int hmdy_real_driver_init(void)
  321. {
  322. int i = 0;
  323. int err = 0;
  324. HMDY_LOG(" hmdy_real_driver_init +\n");
  325. for (i = 0; i < MAX_CHOOSE_HMDY_NUM; i++) {
  326. HMDY_LOG(" i=%d\n", i);
  327. if (0 != humidity_init_list[i]) {
  328. HMDY_LOG(" hmdy try to init driver %s\n", humidity_init_list[i]->name);
  329. err = humidity_init_list[i]->init();
  330. if (0 == err) {
  331. HMDY_LOG(" hmdy real driver %s probe ok\n", humidity_init_list[i]->name);
  332. break;
  333. }
  334. }
  335. }
  336. if (i == MAX_CHOOSE_HMDY_NUM) {
  337. HMDY_LOG(" hmdy_real_driver_init fail\n");
  338. err = -1;
  339. }
  340. return err;
  341. }
  342. int hmdy_driver_add(struct hmdy_init_info *obj)
  343. {
  344. int err = 0;
  345. int i = 0;
  346. HMDY_FUN();
  347. if (!obj) {
  348. HMDY_ERR("HMDY driver add fail, hmdy_init_info is NULL\n");
  349. return -1;
  350. }
  351. for (i = 0; i < MAX_CHOOSE_HMDY_NUM; i++) {
  352. if (i == 0) {
  353. HMDY_LOG("register humidity driver for the first time\n");
  354. if (platform_driver_register(&humidity_driver))
  355. HMDY_ERR("failed to register gensor driver already exist\n");
  356. }
  357. if (NULL == humidity_init_list[i]) {
  358. obj->platform_diver_addr = &humidity_driver;
  359. humidity_init_list[i] = obj;
  360. break;
  361. }
  362. }
  363. if (i >= MAX_CHOOSE_HMDY_NUM) {
  364. HMDY_ERR("HMDY driver add err\n");
  365. err = -1;
  366. }
  367. return err;
  368. }
  369. EXPORT_SYMBOL_GPL(hmdy_driver_add);
  370. static int hmdy_misc_init(struct hmdy_context *cxt)
  371. {
  372. int err = 0;
  373. cxt->mdev.minor = MISC_DYNAMIC_MINOR;
  374. cxt->mdev.name = HMDY_MISC_DEV_NAME;
  375. err = misc_register(&cxt->mdev);
  376. if (err)
  377. HMDY_ERR("unable to register hmdy misc device!!\n");
  378. return err;
  379. }
  380. static void hmdy_input_destroy(struct hmdy_context *cxt)
  381. {
  382. struct input_dev *dev = cxt->idev;
  383. input_unregister_device(dev);
  384. input_free_device(dev);
  385. }
  386. static int hmdy_input_init(struct hmdy_context *cxt)
  387. {
  388. struct input_dev *dev;
  389. int err = 0;
  390. dev = input_allocate_device();
  391. if (NULL == dev)
  392. return -ENOMEM;
  393. dev->name = HMDY_INPUTDEV_NAME;
  394. set_bit(EV_REL, dev->evbit);
  395. input_set_capability(dev, EV_REL, EVENT_TYPE_HMDY_VALUE);
  396. input_set_capability(dev, EV_ABS, EVENT_TYPE_HMDY_STATUS);
  397. input_set_abs_params(dev, EVENT_TYPE_HMDY_STATUS, HMDY_STATUS_MIN, HMDY_STATUS_MAX, 0, 0);
  398. input_set_drvdata(dev, cxt);
  399. err = input_register_device(dev);
  400. if (err < 0) {
  401. input_free_device(dev);
  402. return err;
  403. }
  404. cxt->idev = dev;
  405. return 0;
  406. }
  407. DEVICE_ATTR(hmdyenablenodata, S_IWUSR | S_IRUGO, hmdy_show_enable_nodata, hmdy_store_enable_nodata);
  408. DEVICE_ATTR(hmdyactive, S_IWUSR | S_IRUGO, hmdy_show_active, hmdy_store_active);
  409. DEVICE_ATTR(hmdydelay, S_IWUSR | S_IRUGO, hmdy_show_delay, hmdy_store_delay);
  410. DEVICE_ATTR(hmdybatch, S_IWUSR | S_IRUGO, hmdy_show_batch, hmdy_store_batch);
  411. DEVICE_ATTR(hmdyflush, S_IWUSR | S_IRUGO, hmdy_show_flush, hmdy_store_flush);
  412. DEVICE_ATTR(hmdydevnum, S_IWUSR | S_IRUGO, hmdy_show_devnum, NULL);
  413. static struct attribute *hmdy_attributes[] = {
  414. &dev_attr_hmdyenablenodata.attr,
  415. &dev_attr_hmdyactive.attr,
  416. &dev_attr_hmdydelay.attr,
  417. &dev_attr_hmdybatch.attr,
  418. &dev_attr_hmdyflush.attr,
  419. &dev_attr_hmdydevnum.attr,
  420. NULL
  421. };
  422. static struct attribute_group hmdy_attribute_group = {
  423. .attrs = hmdy_attributes
  424. };
  425. int hmdy_register_data_path(struct hmdy_data_path *data)
  426. {
  427. struct hmdy_context *cxt = NULL;
  428. cxt = hmdy_context_obj;
  429. cxt->hmdy_data.get_data = data->get_data;
  430. cxt->hmdy_data.vender_div = data->vender_div;
  431. cxt->hmdy_data.get_raw_data = data->get_raw_data;
  432. HMDY_LOG("hmdy register data path vender_div: %d\n", cxt->hmdy_data.vender_div);
  433. if (NULL == cxt->hmdy_data.get_data) {
  434. HMDY_LOG("hmdy register data path fail\n");
  435. return -1;
  436. }
  437. return 0;
  438. }
  439. int hmdy_register_control_path(struct hmdy_control_path *ctl)
  440. {
  441. struct hmdy_context *cxt = NULL;
  442. int err = 0;
  443. cxt = hmdy_context_obj;
  444. cxt->hmdy_ctl.set_delay = ctl->set_delay;
  445. cxt->hmdy_ctl.open_report_data = ctl->open_report_data;
  446. cxt->hmdy_ctl.enable_nodata = ctl->enable_nodata;
  447. cxt->hmdy_ctl.is_support_batch = ctl->is_support_batch;
  448. cxt->hmdy_ctl.is_report_input_direct = ctl->is_report_input_direct;
  449. cxt->hmdy_ctl.is_support_batch = ctl->is_support_batch;
  450. cxt->hmdy_ctl.is_use_common_factory = ctl->is_use_common_factory;
  451. if (NULL == cxt->hmdy_ctl.set_delay || NULL == cxt->hmdy_ctl.open_report_data
  452. || NULL == cxt->hmdy_ctl.enable_nodata) {
  453. HMDY_LOG("hmdy register control path fail\n");
  454. return -1;
  455. }
  456. err = hmdy_misc_init(hmdy_context_obj);
  457. if (err) {
  458. HMDY_ERR("unable to register hmdy misc device!!\n");
  459. return -2;
  460. }
  461. err = sysfs_create_group(&hmdy_context_obj->mdev.this_device->kobj, &hmdy_attribute_group);
  462. if (err < 0) {
  463. HMDY_ERR("unable to create hmdy attribute file\n");
  464. return -3;
  465. }
  466. kobject_uevent(&hmdy_context_obj->mdev.this_device->kobj, KOBJ_ADD);
  467. return 0;
  468. }
  469. int hmdy_data_report(struct input_dev *dev, int value, int status)
  470. {
  471. input_report_rel(dev, EVENT_TYPE_HMDY_VALUE, value);
  472. input_report_abs(dev, EVENT_TYPE_HMDY_STATUS, status);
  473. input_sync(dev);
  474. return 0;
  475. }
  476. static int hmdy_probe(struct platform_device *pdev)
  477. {
  478. int err = 0;
  479. HMDY_LOG("+++++++++++++hmdy_probe!!\n");
  480. hmdy_context_obj = hmdy_context_alloc_object();
  481. if (!hmdy_context_obj) {
  482. err = -ENOMEM;
  483. HMDY_ERR("unable to allocate devobj!\n");
  484. goto exit_alloc_data_failed;
  485. }
  486. err = hmdy_real_driver_init();
  487. if (err) {
  488. HMDY_ERR("hmdy real driver init fail\n");
  489. goto real_driver_init_fail;
  490. }
  491. err = hmdy_factory_device_init();
  492. if (err)
  493. HMDY_ERR("hmdy factory device already registed\n");
  494. err = hmdy_input_init(hmdy_context_obj);
  495. if (err) {
  496. HMDY_ERR("unable to register hmdy input device!\n");
  497. goto exit_alloc_input_dev_failed;
  498. }
  499. HMDY_LOG("----hmdy_probe OK !!\n");
  500. return 0;
  501. if (err) {
  502. HMDY_ERR("sysfs node creation error\n");
  503. hmdy_input_destroy(hmdy_context_obj);
  504. }
  505. real_driver_init_fail:
  506. exit_alloc_input_dev_failed:
  507. kfree(hmdy_context_obj);
  508. hmdy_context_obj = NULL;
  509. exit_alloc_data_failed:
  510. HMDY_LOG("----hmdy_probe fail !!!\n");
  511. return err;
  512. }
  513. static int hmdy_remove(struct platform_device *pdev)
  514. {
  515. int err = 0;
  516. HMDY_FUN(f);
  517. input_unregister_device(hmdy_context_obj->idev);
  518. sysfs_remove_group(&hmdy_context_obj->idev->dev.kobj, &hmdy_attribute_group);
  519. err = misc_deregister(&hmdy_context_obj->mdev);
  520. if (err)
  521. HMDY_ERR("misc_deregister fail: %d\n", err);
  522. kfree(hmdy_context_obj);
  523. return 0;
  524. }
  525. static int hmdy_suspend(struct platform_device *dev, pm_message_t state)
  526. {
  527. return 0;
  528. }
  529. /*----------------------------------------------------------------------------*/
  530. static int hmdy_resume(struct platform_device *dev)
  531. {
  532. return 0;
  533. }
  534. #ifdef CONFIG_OF
  535. static const struct of_device_id m_hmdy_pl_of_match[] = {
  536. {.compatible = "mediatek,m_hmdy_pl",},
  537. {},
  538. };
  539. #endif
  540. static struct platform_driver hmdy_driver = {
  541. .probe = hmdy_probe,
  542. .remove = hmdy_remove,
  543. .suspend = hmdy_suspend,
  544. .resume = hmdy_resume,
  545. .driver = {
  546. .name = HMDY_PL_DEV_NAME,
  547. #ifdef CONFIG_OF
  548. .of_match_table = m_hmdy_pl_of_match,
  549. #endif
  550. }
  551. };
  552. static int __init hmdy_init(void)
  553. {
  554. HMDY_FUN();
  555. if (platform_driver_register(&hmdy_driver)) {
  556. HMDY_ERR("failed to register hmdy driver\n");
  557. return -ENODEV;
  558. }
  559. return 0;
  560. }
  561. static void __exit hmdy_exit(void)
  562. {
  563. platform_driver_unregister(&hmdy_driver);
  564. platform_driver_unregister(&humidity_driver);
  565. }
  566. late_initcall(hmdy_init);
  567. MODULE_LICENSE("GPL");
  568. MODULE_DESCRIPTION("HMDYMETER device driver");
  569. MODULE_AUTHOR("Mediatek");