bio.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /*
  2. * Copyright (c) 2011 SAMSUNG ELECTRONICS
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (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. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/module.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/input.h>
  24. #include <linux/delay.h>
  25. #include <linux/mutex.h>
  26. #include <linux/slab.h>
  27. #include <linux/uaccess.h>
  28. #include <linux/miscdevice.h>
  29. #include <linux/wakelock.h>
  30. #include <linux/fs.h>
  31. #include <linux/ioctl.h>
  32. #include <linux/gpio.h>
  33. #include <linux/of_gpio.h>
  34. #include <linux/device.h>
  35. #include <asm/uaccess.h>
  36. #include <asm/system.h>
  37. #include <linux/moduleparam.h>
  38. #include <linux/sensors_core.h>
  39. #define VENDOR "SAMSUNG"
  40. #define CHIP_ID "COMMON"
  41. #define ECG_VERSION_FILE_PATH "/efs/ecg_ver"
  42. #define EVENT_TYPE_STATUS REL_HWHEEL
  43. #define EVENT_TYPE_RESULT REL_DIAL
  44. struct bio_data {
  45. struct platform_device *pdev;
  46. struct miscdevice bio_device;
  47. struct wake_lock bio_wake_lock;
  48. struct work_struct strip_work;
  49. struct workqueue_struct *report_queue;
  50. struct workqueue_struct *indication_queue;
  51. struct delayed_work report_work;
  52. struct delayed_work indication_work;
  53. struct input_dev *input;
  54. struct device *bio_dev;
  55. u8 enabled;
  56. int strip_irq;
  57. int notify_cmd;
  58. int state_cmd;
  59. u32 indication;
  60. u32 strip_status;
  61. int bgm_state;
  62. int bgm_timeout;
  63. u32 ecg_enable;
  64. u32 bgm_enable;
  65. int check_loop;
  66. };
  67. static void report_state(struct bio_data *data)
  68. {
  69. input_report_rel(data->input, EVENT_TYPE_STATUS,
  70. data->bgm_state + 1);
  71. input_sync(data->input);
  72. }
  73. static void start_check(struct bio_data *data)
  74. {
  75. pr_info("[bgm] %s\n", __func__);
  76. data->check_loop = 1;
  77. queue_delayed_work(data->indication_queue,
  78. &data->indication_work, HZ/2);
  79. }
  80. static void stop_check(struct bio_data *data)
  81. {
  82. pr_info("[bgm] %s\n", __func__);
  83. data->check_loop = 0;
  84. //cancel_delayed_work(&data->indication_work);
  85. }
  86. static void indication_func(struct work_struct *work)
  87. {
  88. struct bio_data *data = container_of(work,
  89. struct bio_data, indication_work.work);
  90. int strip_value, indi_value, bgm_state;
  91. indi_value = gpio_get_value(data->indication);
  92. strip_value = gpio_get_value(data->strip_status);
  93. bgm_state = data->bgm_state;
  94. pr_info("[bgm] %s : strip=%d, indication=%d, bgm_state=%d\n",
  95. __func__, strip_value, indi_value, data->bgm_state);
  96. #if 0
  97. if (bgm_state == 0 && indi_value == 0 && strip_value == 1) {
  98. /* initial state */
  99. pr_info("[bgm] %s : Initial state check", __func__);
  100. if (data->bgm_timeout == 0) {
  101. pr_info("\n[bgm] %s : Initial state OK", __func__);
  102. report_state(data);
  103. } else if (data->bgm_timeout == 4) {
  104. pr_info("\n[bgm] %s : Initial state T_ind timeout", __func__);
  105. bgm_state = 100;
  106. report_state(data);
  107. bgm_state = 0;
  108. }
  109. //data->bgm_timeout++;
  110. pr_info(",[bgm] time out count is %d\n", data->bgm_timeout);
  111. } else
  112. #endif
  113. if (bgm_state == 0 && indi_value == 1 && strip_value == 0) {
  114. /* strip inserted m Startup check OK */
  115. pr_info("[bgm] %s : Start-up check OK\n", __func__);
  116. bgm_state = 1;
  117. report_state(data);
  118. } else if (bgm_state == 1 && indi_value == 0) {
  119. /* Waiting sample */
  120. pr_info("[bgm] %s : Waiting sample\n", __func__);
  121. bgm_state = 2;
  122. report_state(data);
  123. } else if (bgm_state == 2 && indi_value == 1) {
  124. /* Sample applied */
  125. pr_info("[bgm] %s : Sample applied\n", __func__);
  126. bgm_state = 3;
  127. report_state(data);
  128. } else if (bgm_state == 3 && indi_value == 1
  129. && data->notify_cmd == 1) {
  130. /* Check complete, send sleep packet */
  131. pr_info("[bgm] %s : Send sleep\n", __func__);
  132. bgm_state = 4;
  133. report_state(data);
  134. }
  135. data->bgm_state = bgm_state;
  136. if (data->check_loop)
  137. queue_delayed_work(data->indication_queue,
  138. &data->indication_work, HZ/2);
  139. }
  140. static void report_func(struct work_struct *work)
  141. {
  142. struct bio_data *data = container_of(work,
  143. struct bio_data, report_work.work);
  144. pr_info("[bgm] %s : %d\n", __func__, data->notify_cmd + 1);
  145. input_report_rel(data->input, EVENT_TYPE_STATUS,
  146. data->notify_cmd + 1);
  147. input_sync(data->input);
  148. }
  149. static irqreturn_t bio_strip_irq_handler(int irq, void *dev_id)
  150. {
  151. struct bio_data *data = dev_id;
  152. wake_lock_timeout(&data->bio_wake_lock, 3 * HZ);
  153. //schedule_work(&data->strip_work);
  154. pr_info("[bgm] %s : IRQ_HANDLED. strip %s\n", __func__,
  155. (gpio_get_value(data->strip_status))?"removed":"inserted");
  156. return IRQ_HANDLED;
  157. }
  158. static void strip_func(struct work_struct *work)
  159. {
  160. struct bio_data *data = container_of((struct work_struct *)work,
  161. struct bio_data, strip_work);
  162. int ret;
  163. ret = gpio_get_value(data->strip_status);
  164. pr_info("[bgm] %s : strip gpio value is %d\n", __func__, ret);
  165. }
  166. static int bio_parse_dt(struct device *dev, struct bio_data *data)
  167. {
  168. struct device_node *np = dev->of_node;
  169. enum of_gpio_flags flags;
  170. int errorno = 0;
  171. int irq;
  172. int rc;
  173. pr_info("[bgm] %s : bio,bgm_indication\n", __func__);
  174. data->indication = of_get_named_gpio_flags(np, "bio,bgm_indication",
  175. 0, &flags);
  176. if (data->indication < 0) {
  177. errorno = data->indication;
  178. pr_err("[bgm] %s : bio,bgm_indication error\n", __func__);
  179. } else {
  180. errorno = gpio_request(data->indication, "BGMINDI");
  181. if (errorno) {
  182. pr_err("[bgm] %s : failed to request indication PIN\n",
  183. __func__);
  184. } else {
  185. errorno = gpio_direction_input(data->indication);
  186. if (errorno) {
  187. pr_err("[bgm] %s : failed to set indication PIN as output\n",
  188. __func__);
  189. }
  190. }
  191. }
  192. pr_info("[bgm] %s : bio,bgm_strip_status\n", __func__);
  193. data->strip_status = of_get_named_gpio_flags(np, "bio,bgm_strip_status",
  194. 0, &flags);
  195. if (data->strip_status < 0) {
  196. errorno = data->strip_status;
  197. pr_err("[bgm] %s : bio,bgm_strip_status\n", __func__);
  198. } else {
  199. errorno = gpio_request(data->strip_status, "BGMSTRIP");
  200. if (errorno) {
  201. pr_err("[bgm] %s : failed to request bgm_strip_status PIN\n",
  202. __func__);
  203. } else {
  204. errorno = gpio_direction_input(data->strip_status);
  205. if (errorno) {
  206. pr_err("[bgm] %s : failed to set strip_status PIN as output\n",
  207. __func__);
  208. }
  209. }
  210. }
  211. if (data->strip_status >= 0) {
  212. irq = gpio_to_irq(data->strip_status);
  213. rc = request_threaded_irq(irq, NULL,
  214. bio_strip_irq_handler,
  215. IRQF_TRIGGER_FALLING |
  216. IRQF_TRIGGER_RISING |
  217. IRQF_ONESHOT,
  218. "bio_strip_int",
  219. data);
  220. if (rc < 0) {
  221. pr_err("[bgm] %s : request_irq(%d) failed for gpio %d (%d)\n",
  222. __func__, irq,
  223. data->strip_status, rc);
  224. //goto dt_exit;
  225. }
  226. disable_irq(irq);
  227. data->strip_irq = irq;
  228. }
  229. #if 1
  230. pr_info("[ecg] %s : bio,ecg_enable\n", __func__);
  231. data->ecg_enable = of_get_named_gpio_flags(np, "bio,ecg_enable",
  232. 0, &flags);
  233. if (data->ecg_enable < 0) {
  234. errorno = data->ecg_enable;
  235. pr_err("[ecg] %s: bio,ecg_enable\n", __func__);
  236. } else {
  237. errorno = gpio_request(data->ecg_enable, "bio_ECG_ENABLE");
  238. if (errorno) {
  239. pr_err("[ecg] %s: failed to request ecg_enable PIN \n",
  240. __func__);
  241. } else {
  242. errorno = gpio_direction_output(data->ecg_enable, 0);
  243. if (errorno) {
  244. pr_err("[ecg] %s: failed to set ecg_enable PIN as output\n",
  245. __func__);
  246. }
  247. }
  248. }
  249. pr_info("[bgm] %s : bio,bgm_enable\n", __func__);
  250. data->bgm_enable = of_get_named_gpio_flags(np, "bio,bgm_enable",
  251. 0, &flags);
  252. if (data->bgm_enable < 0) {
  253. errorno = data->bgm_enable;
  254. pr_err("[bgm] %s: bio,bgm_enable\n", __func__);
  255. } else {
  256. errorno = gpio_request(data->bgm_enable, "bio_BGM_ENABLE");
  257. if (errorno) {
  258. pr_err("[bgm] %s: failed to request bgm_enable PIN \n",
  259. __func__);
  260. } else {
  261. errorno = gpio_direction_output(data->bgm_enable, 1);
  262. if (errorno) {
  263. pr_err("[bgm] %s: failed to set bgm_enable PIN as output\n",
  264. __func__);
  265. }
  266. }
  267. }
  268. #endif
  269. return 0;
  270. //dt_exit:
  271. //return errorno;
  272. }
  273. /*
  274. static ssize_t bio_io_read(struct file *filp, char __user *buf,
  275. size_t count, loff_t *offset)
  276. {
  277. //struct bio_data *data = filp->private_data;
  278. //char tmp[MAX_BUFFER_SIZE] = {0, };
  279. int ret = 0;
  280. pr_info("[bgm] %s :\n", __func__);
  281. //ret = wait_event_interruptible(pn547_dev->read_wq,
  282. return ret;
  283. }
  284. static ssize_t bio_io_write(struct file *filp, const char __user *buf,
  285. size_t count, loff_t *offset)
  286. {
  287. int ret = 0;
  288. struct bio_data *data =filp->private_data;
  289. pr_info("[bgm] %s :\n", __func__);
  290. return ret;
  291. }
  292. static long bio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  293. {
  294. // void __user *argp = (void __user *)arg;
  295. // struct bio_data *data = container_of(filp->private_data,
  296. // struct bio_data, bio_device);
  297. switch (cmd) {
  298. default:
  299. return -ENOTTY;
  300. }
  301. return 0;
  302. }
  303. */
  304. static int bio_io_open(struct inode *inode, struct file *filp)
  305. {
  306. pr_info("[bgm] %s :\n", __func__);
  307. return 0;
  308. }
  309. static int bio_io_release(struct inode *inode, struct file *filp)
  310. {
  311. pr_info("[bgm] %s :\n", __func__);
  312. return 0;
  313. }
  314. static const struct file_operations bio_fops = {
  315. .owner = THIS_MODULE,
  316. .open = bio_io_open,
  317. .release = bio_io_release,
  318. //.unlocked_ioctl = bio_ioctl,
  319. .llseek = no_llseek,
  320. //.read = bio_io_read,
  321. //.write = bio_io_write,
  322. };
  323. static ssize_t bio_enable_store(struct device *dev,
  324. struct device_attribute *attr,
  325. const char *buf, size_t size)
  326. {
  327. struct bio_data *data = dev_get_drvdata(dev);
  328. int new_value;
  329. if (sysfs_streq(buf, "1"))
  330. new_value = true;
  331. else if (sysfs_streq(buf, "0"))
  332. new_value = false;
  333. else {
  334. pr_err("[bgm] %s: invalid value %d\n", __func__, *buf);
  335. return -EINVAL;
  336. }
  337. if (new_value && !data->enabled) {
  338. pr_err("[bgm] %s : bgm enable, polling start, sensor on\n", __func__);
  339. data->bgm_state = 0;
  340. data->bgm_timeout = 0;
  341. data->notify_cmd = 0;
  342. data->enabled = 1;
  343. //gpio_direction_output(data->bgm_enable, 1);
  344. msleep(200);
  345. start_check(data);
  346. } else if (!new_value && data->enabled) {
  347. pr_err("[bgm] %s : bgm enable, polling stop, sensor off\n", __func__);
  348. data->enabled = 0;
  349. stop_check(data);
  350. //gpio_direction_output(data->bgm_enable, 0);
  351. }
  352. return size;
  353. }
  354. static ssize_t bio_notify_show(struct device *dev,
  355. struct device_attribute *attr, char *buf)
  356. {
  357. struct bio_data *data = dev_get_drvdata(dev);
  358. return sprintf(buf, "%d\n", data->notify_cmd);
  359. }
  360. static ssize_t bio_notify_store(struct device *dev,
  361. struct device_attribute *attr,
  362. const char *buf, size_t size)
  363. {
  364. int err;
  365. long noti_cmd;
  366. struct bio_data *data = dev_get_drvdata(dev);
  367. err = strict_strtol(buf, 10, &noti_cmd);
  368. pr_info("[bgm] %s : %s = 0x%02x\n", __func__, buf, (int)noti_cmd);
  369. if (err < 0)
  370. return -EINVAL;
  371. if (noti_cmd == 1)
  372. data->notify_cmd = 1;
  373. else { /* error or test state */
  374. input_report_rel(data->input, EVENT_TYPE_STATUS, noti_cmd + 1);
  375. input_sync(data->input);
  376. data->bgm_state = 0;
  377. data->bgm_timeout = 0;
  378. data->notify_cmd = 0;
  379. }
  380. //queue_delayed_work(data->report_queue, &data->report_work, HZ*2);
  381. //TODO : input report
  382. return size;
  383. }
  384. static ssize_t ecg_onoff_show(struct device *dev,
  385. struct device_attribute *attr, char *buf)
  386. {
  387. struct bio_data *data = dev_get_drvdata(dev);
  388. return sprintf(buf, "%d\n", gpio_get_value(data->ecg_enable));
  389. }
  390. static ssize_t ecg_onoff_store(struct device *dev,
  391. struct device_attribute *attr,
  392. const char *buf, size_t size)
  393. {
  394. int err;
  395. long power_gpio;
  396. struct bio_data *data = dev_get_drvdata(dev);
  397. err = strict_strtol(buf, 10, &power_gpio);
  398. pr_info("[ecg] %s : %s = %d\n", __func__, buf, (int)power_gpio);
  399. if (err < 0)
  400. return -EINVAL;
  401. if (power_gpio == 1)
  402. gpio_direction_output(data->ecg_enable, 1);
  403. else
  404. gpio_direction_output(data->ecg_enable, 0);
  405. return size;
  406. }
  407. static ssize_t ecg_fw_show(struct device *dev,
  408. struct device_attribute *attr, char *buf)
  409. {
  410. //struct bio_data *data = dev_get_drvdata(dev);
  411. struct file *version_filp = NULL;
  412. mm_segment_t old_fs;
  413. int err;
  414. int version;
  415. old_fs = get_fs();
  416. set_fs(KERNEL_DS);
  417. version_filp = filp_open(ECG_VERSION_FILE_PATH, O_RDONLY, 0666);
  418. if (IS_ERR(version_filp)) {
  419. err = PTR_ERR(version_filp);
  420. if (err != -ENOENT)
  421. pr_err("[bgm] %s: Can't open version file\n", __func__);
  422. set_fs(old_fs);
  423. version = 0;
  424. return sprintf(buf, "%d\n", version);
  425. }
  426. err = version_filp->f_op->read(version_filp,
  427. (char *)&version, sizeof(int), &version_filp->f_pos);
  428. if (err != sizeof(int)) {
  429. filp_close(version_filp, NULL);
  430. set_fs(old_fs);
  431. version = 0;
  432. return sprintf(buf, "%d\n", version);
  433. }
  434. filp_close(version_filp, NULL);
  435. set_fs(old_fs);
  436. return sprintf(buf, "%d\n", version);
  437. }
  438. static ssize_t ecg_fw_store(struct device *dev,
  439. struct device_attribute *attr,
  440. const char *buf, size_t size)
  441. {
  442. int err;
  443. long temp;
  444. int version;
  445. //struct bio_data *data = dev_get_drvdata(dev);
  446. struct file *version_filp = NULL;
  447. mm_segment_t old_fs;
  448. err = strict_strtol(buf, 10, &temp);
  449. version = (int)temp;
  450. pr_info("[bgm] %s : %s = %d\n", __func__, buf, version);
  451. if (err < 0)
  452. return -EINVAL;
  453. old_fs = get_fs();
  454. set_fs(KERNEL_DS);
  455. version_filp = filp_open(ECG_VERSION_FILE_PATH,
  456. O_CREAT | O_TRUNC | O_WRONLY | O_SYNC, 0666);
  457. if (IS_ERR(version_filp)) {
  458. pr_err("[bgm] %s: Can't open version file\n", __func__);
  459. set_fs(old_fs);
  460. err = PTR_ERR(version_filp);
  461. return size;
  462. }
  463. err = version_filp->f_op->write(version_filp,
  464. (char *)&version, sizeof(int), &version_filp->f_pos);
  465. if (err != sizeof(int)) {
  466. pr_err("[bgm] %s: Can't write the version data to file\n", __func__);
  467. filp_close(version_filp, NULL);
  468. set_fs(old_fs);
  469. return size;
  470. }
  471. filp_close(version_filp, NULL);
  472. set_fs(old_fs);
  473. return size;
  474. }
  475. static ssize_t bio_enable_show(struct device *dev,
  476. struct device_attribute *attr, char *buf)
  477. {
  478. struct bio_data *data = dev_get_drvdata(dev);
  479. return sprintf(buf, "%d\n", data->enabled);
  480. }
  481. static struct device_attribute dev_attr_enable =
  482. __ATTR(enable, S_IRUGO | S_IWUSR | S_IWGRP,
  483. bio_enable_show, bio_enable_store);
  484. static struct attribute *bio_sysfs_attrs[] = {
  485. &dev_attr_enable.attr,
  486. NULL
  487. };
  488. static struct attribute_group bio_attribute_group = {
  489. .attrs = bio_sysfs_attrs,
  490. };
  491. /* sysfs for vendor & name */
  492. static ssize_t bio_vendor_show(struct device *dev,
  493. struct device_attribute *attr, char *buf)
  494. {
  495. return sprintf(buf, "%s\n", VENDOR);
  496. }
  497. static ssize_t bio_name_show(struct device *dev,
  498. struct device_attribute *attr, char *buf)
  499. {
  500. return sprintf(buf, "%s\n", CHIP_ID);
  501. }
  502. static DEVICE_ATTR(vendor, 0644, bio_vendor_show, NULL);
  503. static DEVICE_ATTR(name, 0644, bio_name_show, NULL);
  504. static DEVICE_ATTR(notify, 0666, bio_notify_show, bio_notify_store);
  505. static DEVICE_ATTR(onoff, 0666, ecg_onoff_show, ecg_onoff_store);
  506. static DEVICE_ATTR(fw, 0666, ecg_fw_show, ecg_fw_store);
  507. static struct device_attribute *bio_sensor_attrs[] = {
  508. &dev_attr_vendor,
  509. &dev_attr_name,
  510. &dev_attr_notify,
  511. &dev_attr_onoff,
  512. &dev_attr_fw,
  513. NULL,
  514. };
  515. static int bio_probe(struct platform_device *dev)
  516. {
  517. int ret;
  518. struct bio_data *data;
  519. pr_info("[bgm] %s : bio_probe\n", __func__);
  520. data = kzalloc(sizeof(*data), GFP_KERNEL);
  521. if (data == NULL) {
  522. pr_err("%s, failed to alloc memory for module data\n",
  523. __func__);
  524. ret = -ENOMEM;
  525. goto exit;
  526. }
  527. data->pdev = platform_device_register_simple("bio", -1, NULL, 0);
  528. if (IS_ERR(data->pdev)) {
  529. ret = PTR_ERR(data->pdev);
  530. goto out_driver;
  531. }
  532. if (dev->dev.of_node)
  533. pr_info("[bgm] %s : of node\n", __func__);
  534. else {
  535. pr_err("%s : no of node\n", __func__);
  536. goto out_device;
  537. }
  538. ret = bio_parse_dt(&dev->dev, data);
  539. if (ret) {
  540. pr_err("%s : parse dt error\n", __func__);
  541. //goto err_parse_dt;
  542. }
  543. data->bgm_state = 0;
  544. data->bgm_timeout = 0;
  545. data->strip_irq = 0;
  546. data->bio_device.minor = MISC_DYNAMIC_MINOR;
  547. data->bio_device.name = "bio";
  548. data->bio_device.fops = &bio_fops;
  549. ret = misc_register(&data->bio_device);
  550. if (ret)
  551. goto exit_misc_device_register_failed;
  552. wake_lock_init(&data->bio_wake_lock,
  553. WAKE_LOCK_SUSPEND, "bio_wake_lock");
  554. INIT_WORK(&data->strip_work, strip_func);
  555. INIT_DELAYED_WORK(&data->report_work, report_func);
  556. INIT_DELAYED_WORK(&data->indication_work, indication_func);
  557. data->report_queue =
  558. create_singlethread_workqueue(dev_name(&data->pdev->dev));
  559. data->indication_queue =
  560. create_singlethread_workqueue(dev_name(&data->pdev->dev));
  561. data->input = input_allocate_device();
  562. if (!data->input) {
  563. pr_err("[bgm] %s : could not allocate mlx90615 input device\n", __func__);
  564. goto err_input_allocate_device;
  565. }
  566. data->input->name = "bio_sensor";
  567. input_set_capability(data->input, EV_REL, EVENT_TYPE_STATUS);
  568. //input_set_capability(data->input, EV_REL, EVENT_TYPE_OBJECT_TEMP);
  569. input_set_drvdata(data->input, data);
  570. ret = input_register_device(data->input);
  571. if (ret < 0) {
  572. input_free_device(data->input);
  573. pr_err("[bgm] %s : could not register input device\n", __func__);
  574. //goto err_input_register_device;
  575. }
  576. ret = sensors_create_symlink(&data->input->dev.kobj,
  577. data->input->name);
  578. if (ret < 0) {
  579. input_unregister_device(data->input);
  580. goto err_sysfs_create_symlink;
  581. }
  582. ret = sysfs_create_group(&data->input->dev.kobj,
  583. &bio_attribute_group);
  584. if (ret) {
  585. pr_err("[bgm] %s : could not create sysfs group\n", __func__);
  586. goto err_sysfs_create_group;
  587. }
  588. ret = sensors_register(data->bio_dev,
  589. data, bio_sensor_attrs, "bio_sensor");
  590. if (ret) {
  591. pr_err("[bgm] %s : cound not register prox sensor device(%d).\n",
  592. __func__, ret);
  593. goto err_sysfs_create_symlink;
  594. }
  595. platform_set_drvdata(dev,data);
  596. pr_info("[bgm] %s : success.\n", __func__);
  597. //if (data->strip_irq)
  598. //enable_irq(data->strip_irq);
  599. return 0;
  600. err_input_allocate_device:
  601. err_sysfs_create_symlink:
  602. input_free_device(data->input);
  603. err_sysfs_create_group:
  604. input_unregister_device(data->input);
  605. exit_misc_device_register_failed:
  606. misc_deregister(&data->bio_device);
  607. out_device:
  608. platform_device_unregister(data->pdev);
  609. out_driver:
  610. //mutex_destroy(&data->bio_lock);
  611. kfree(data);
  612. exit:
  613. pr_err("[BIO] %s : failed!\n", __func__);
  614. return ret;
  615. }
  616. static int bio_remove(struct platform_device *dev)
  617. {
  618. struct bio_data *data = platform_get_drvdata(dev);
  619. misc_deregister(&data->bio_device);
  620. platform_device_unregister(data->pdev);
  621. kfree(data);
  622. return 0;
  623. }
  624. static int bio_suspend(struct device *dev)
  625. {
  626. //struct bio_data *data = dev_get_drvdata(dev);
  627. //gpio_direction_output(data->ecg_enable, 0);
  628. return 0;
  629. }
  630. static int bio_resume(struct device *dev)
  631. {
  632. struct bio_data *data = dev_get_drvdata(dev);
  633. //gpio_direction_output(data->ecg_enable, 1);
  634. cancel_delayed_work(&data->report_work);
  635. return 0;
  636. }
  637. #ifdef CONFIG_OF
  638. static struct of_device_id bio_match_table[] = {
  639. {.compatible = "bio_sensor",},
  640. {},
  641. };
  642. #endif
  643. static const struct dev_pm_ops bio_pm_ops = {
  644. .suspend = bio_suspend,
  645. .resume = bio_resume
  646. };
  647. static struct platform_driver bio_driver = {
  648. .driver = {
  649. #ifndef CONFIG_HAS_EARLYSUSPEND
  650. .pm = &bio_pm_ops,
  651. #endif
  652. .name = "bio_sensor",
  653. .owner = THIS_MODULE,
  654. .of_match_table = bio_match_table,
  655. },
  656. .probe = bio_probe,
  657. .remove = bio_remove,
  658. };
  659. static int __init bio_init(void)
  660. {
  661. return platform_driver_register(&bio_driver);
  662. }
  663. static void __exit bio_exit(void)
  664. {
  665. platform_driver_unregister(&bio_driver);
  666. }
  667. module_init(bio_init);
  668. module_exit(bio_exit);
  669. MODULE_DESCRIPTION("BIO sensor control");
  670. MODULE_AUTHOR("Samsung Electronic");
  671. MODULE_LICENSE("GPL v2");