i2c_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /******************************************************************************
  2. * Copyright (C) 2015, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013-2021 NXP
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. ******************************************************************************/
  20. /*
  21. * Copyright (C) 2010 Trusted Logic S.A.
  22. *
  23. * This program is free software; you can redistribute it and/or modify
  24. * it under the terms of the GNU General Public License as published by
  25. * the Free Software Foundation; either version 2 of the License, or
  26. * (at your option) any later version.
  27. *
  28. * This program is distributed in the hope that it will be useful,
  29. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  30. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  31. * GNU General Public License for more details.
  32. *
  33. * You should have received a copy of the GNU General Public License
  34. * along with this program; if not, write to the Free Software
  35. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  36. ****************************************************************************/
  37. /*
  38. * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
  39. *
  40. ****************************************************************************/
  41. #include <linux/module.h>
  42. #include <linux/interrupt.h>
  43. #include <linux/delay.h>
  44. #include <linux/uaccess.h>
  45. #include <linux/gpio.h>
  46. #ifdef CONFIG_COMPAT
  47. #include <linux/compat.h>
  48. #endif
  49. #include "common.h"
  50. /**
  51. * i2c_disable_irq()
  52. *
  53. * Check if interrupt is disabled or not
  54. * and disable interrupt
  55. *
  56. * Return: int
  57. */
  58. int i2c_disable_irq(struct nfc_dev *dev)
  59. {
  60. unsigned long flags;
  61. spin_lock_irqsave(&dev->i2c_dev.irq_enabled_lock, flags);
  62. if (dev->i2c_dev.irq_enabled) {
  63. disable_irq_nosync(dev->i2c_dev.client->irq);
  64. dev->i2c_dev.irq_enabled = false;
  65. }
  66. spin_unlock_irqrestore(&dev->i2c_dev.irq_enabled_lock, flags);
  67. return 0;
  68. }
  69. /**
  70. * i2c_enable_irq()
  71. *
  72. * Check if interrupt is enabled or not
  73. * and enable interrupt
  74. *
  75. * Return: int
  76. */
  77. int i2c_enable_irq(struct nfc_dev *dev)
  78. {
  79. unsigned long flags;
  80. spin_lock_irqsave(&dev->i2c_dev.irq_enabled_lock, flags);
  81. if (!dev->i2c_dev.irq_enabled) {
  82. dev->i2c_dev.irq_enabled = true;
  83. enable_irq(dev->i2c_dev.client->irq);
  84. }
  85. spin_unlock_irqrestore(&dev->i2c_dev.irq_enabled_lock, flags);
  86. return 0;
  87. }
  88. static irqreturn_t i2c_irq_handler(int irq, void *dev_id)
  89. {
  90. struct nfc_dev *nfc_dev = dev_id;
  91. struct i2c_dev *i2c_dev = &nfc_dev->i2c_dev;
  92. if (device_may_wakeup(&i2c_dev->client->dev))
  93. pm_wakeup_event(&i2c_dev->client->dev, WAKEUP_SRC_TIMEOUT);
  94. i2c_disable_irq(nfc_dev);
  95. wake_up(&nfc_dev->read_wq);
  96. return IRQ_HANDLED;
  97. }
  98. int i2c_read(struct nfc_dev *nfc_dev, char *buf, size_t count, int timeout)
  99. {
  100. int ret;
  101. struct i2c_dev *i2c_dev = &nfc_dev->i2c_dev;
  102. struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
  103. uint16_t i = 0;
  104. uint16_t disp_len = GET_IPCLOG_MAX_PKT_LEN(count);
  105. pr_debug("%s: reading %zu bytes.\n", __func__, count);
  106. if (timeout > NCI_CMD_RSP_TIMEOUT_MS)
  107. timeout = NCI_CMD_RSP_TIMEOUT_MS;
  108. if (count > MAX_NCI_BUFFER_SIZE)
  109. count = MAX_NCI_BUFFER_SIZE;
  110. if (!gpio_get_value(nfc_gpio->irq)) {
  111. while (1) {
  112. ret = 0;
  113. if (!i2c_dev->irq_enabled) {
  114. i2c_dev->irq_enabled = true;
  115. enable_irq(i2c_dev->client->irq);
  116. }
  117. if (!gpio_get_value(nfc_gpio->irq)) {
  118. if (timeout) {
  119. ret = wait_event_interruptible_timeout(
  120. nfc_dev->read_wq,
  121. !i2c_dev->irq_enabled,
  122. msecs_to_jiffies(timeout));
  123. if (ret <= 0) {
  124. pr_err("%s: timeout error\n",
  125. __func__);
  126. goto err;
  127. }
  128. } else {
  129. ret = wait_event_interruptible(
  130. nfc_dev->read_wq,
  131. !i2c_dev->irq_enabled);
  132. if (ret) {
  133. pr_err("%s: err wakeup of wq\n",
  134. __func__);
  135. goto err;
  136. }
  137. }
  138. }
  139. i2c_disable_irq(nfc_dev);
  140. if (gpio_get_value(nfc_gpio->irq))
  141. break;
  142. if (!gpio_get_value(nfc_gpio->ven)) {
  143. pr_info("%s: releasing read\n", __func__);
  144. ret = -EIO;
  145. goto err;
  146. }
  147. /*
  148. * NFC service wanted to close the driver so,
  149. * release the calling reader thread asap.
  150. *
  151. * This can happen in case of nfc node close call from
  152. * eSE HAL in that case the NFC HAL reader thread
  153. * will again call read system call
  154. */
  155. if (nfc_dev->release_read) {
  156. pr_debug("%s: releasing read\n", __func__);
  157. return 0;
  158. }
  159. pr_warn("%s: spurious interrupt detected\n", __func__);
  160. }
  161. }
  162. memset(buf, 0x00, count);
  163. /* Read data */
  164. ret = i2c_master_recv(nfc_dev->i2c_dev.client, buf, count);
  165. NFCLOG_IPC(nfc_dev, false, "%s of %d bytes, ret %d", __func__, count,
  166. ret);
  167. if (ret <= 0) {
  168. pr_err("%s: returned %d\n", __func__, ret);
  169. goto err;
  170. }
  171. for (i = 0; i < disp_len; i++)
  172. NFCLOG_IPC(nfc_dev, false, " %02x", buf[i]);
  173. /* check if it's response of cold reset command
  174. * NFC HAL process shouldn't receive this data as
  175. * command was sent by esepowermanager
  176. */
  177. if (nfc_dev->cold_reset.rsp_pending && nfc_dev->cold_reset.cmd_buf
  178. && (buf[0] == PROP_NCI_RSP_GID)
  179. && (buf[1] == nfc_dev->cold_reset.cmd_buf[1])) {
  180. read_cold_reset_rsp(nfc_dev, buf);
  181. nfc_dev->cold_reset.rsp_pending = false;
  182. wake_up_interruptible(&nfc_dev->cold_reset.read_wq);
  183. /*
  184. * NFC process doesn't know about cold reset command
  185. * being sent as it was initiated by eSE process
  186. * we shouldn't return any data to NFC process
  187. */
  188. return 0;
  189. }
  190. err:
  191. return ret;
  192. }
  193. int i2c_write(struct nfc_dev *nfc_dev, const char *buf, size_t count,
  194. int max_retry_cnt)
  195. {
  196. int ret = -EINVAL;
  197. int retry_cnt;
  198. uint16_t i = 0;
  199. uint16_t disp_len = GET_IPCLOG_MAX_PKT_LEN(count);
  200. struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
  201. if (count > MAX_DL_BUFFER_SIZE)
  202. count = MAX_DL_BUFFER_SIZE;
  203. pr_debug("%s: writing %zu bytes.\n", __func__, count);
  204. NFCLOG_IPC(nfc_dev, false, "%s sending %d B", __func__, count);
  205. for (i = 0; i < disp_len; i++)
  206. NFCLOG_IPC(nfc_dev, false, " %02x", buf[i]);
  207. /*
  208. * Wait for any pending read for max 15ms before write
  209. * This is to avoid any packet corruption during read, when
  210. * the host cmds resets NFCC during any parallel read operation
  211. */
  212. for (retry_cnt = 1; retry_cnt <= MAX_WRITE_IRQ_COUNT; retry_cnt++) {
  213. if (gpio_get_value(nfc_gpio->irq)) {
  214. pr_warn("%s: irq high during write, wait\n", __func__);
  215. usleep_range(NFC_WRITE_IRQ_WAIT_TIME_US,
  216. NFC_WRITE_IRQ_WAIT_TIME_US + 100);
  217. } else {
  218. break;
  219. }
  220. if (retry_cnt == MAX_WRITE_IRQ_COUNT &&
  221. gpio_get_value(nfc_gpio->irq)) {
  222. pr_warn("%s: allow after maximum wait\n", __func__);
  223. }
  224. }
  225. for (retry_cnt = 1; retry_cnt <= max_retry_cnt; retry_cnt++) {
  226. ret = i2c_master_send(nfc_dev->i2c_dev.client, buf, count);
  227. NFCLOG_IPC(nfc_dev, false, "%s ret %d", __func__, ret);
  228. if (ret <= 0) {
  229. pr_warn("%s: write failed ret(%d), maybe in standby\n",
  230. __func__, ret);
  231. usleep_range(WRITE_RETRY_WAIT_TIME_US,
  232. WRITE_RETRY_WAIT_TIME_US + 100);
  233. } else if (ret != count) {
  234. pr_err("%s: failed to write %d\n", __func__, ret);
  235. ret = -EIO;
  236. } else if (ret == count)
  237. break;
  238. }
  239. return ret;
  240. }
  241. ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf, size_t count,
  242. loff_t *offset)
  243. {
  244. int ret;
  245. struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
  246. if (!nfc_dev) {
  247. pr_err("%s: device doesn't exist anymore\n", __func__);
  248. return -ENODEV;
  249. }
  250. mutex_lock(&nfc_dev->read_mutex);
  251. if (filp->f_flags & O_NONBLOCK) {
  252. ret = i2c_master_recv(nfc_dev->i2c_dev.client, nfc_dev->read_kbuf, count);
  253. pr_debug("%s: NONBLOCK read ret = %d\n", __func__, ret);
  254. } else {
  255. ret = i2c_read(nfc_dev, nfc_dev->read_kbuf, count, 0);
  256. }
  257. if (ret > 0) {
  258. if (copy_to_user(buf, nfc_dev->read_kbuf, ret)) {
  259. pr_warn("%s: failed to copy to user space\n", __func__);
  260. ret = -EFAULT;
  261. }
  262. }
  263. mutex_unlock(&nfc_dev->read_mutex);
  264. return ret;
  265. }
  266. ssize_t nfc_i2c_dev_write(struct file *filp, const char __user *buf,
  267. size_t count, loff_t *offset)
  268. {
  269. int ret;
  270. struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
  271. if (count > MAX_DL_BUFFER_SIZE)
  272. count = MAX_DL_BUFFER_SIZE;
  273. if (!nfc_dev) {
  274. pr_err("%s: device doesn't exist anymore\n", __func__);
  275. return -ENODEV;
  276. }
  277. mutex_lock(&nfc_dev->write_mutex);
  278. if (copy_from_user(nfc_dev->write_kbuf, buf, count)) {
  279. pr_err("%s: failed to copy from user space\n", __func__);
  280. mutex_unlock(&nfc_dev->write_mutex);
  281. return -EFAULT;
  282. }
  283. ret = i2c_write(nfc_dev, nfc_dev->write_kbuf, count, NO_RETRY);
  284. mutex_unlock(&nfc_dev->write_mutex);
  285. return ret;
  286. }
  287. static const struct file_operations nfc_i2c_dev_fops = {
  288. .owner = THIS_MODULE,
  289. .llseek = no_llseek,
  290. .read = nfc_i2c_dev_read,
  291. .write = nfc_i2c_dev_write,
  292. .open = nfc_dev_open,
  293. .flush = nfc_dev_flush,
  294. .release = nfc_dev_close,
  295. .unlocked_ioctl = nfc_dev_ioctl,
  296. #ifdef CONFIG_COMPAT
  297. .compat_ioctl = nfc_dev_compat_ioctl,
  298. #endif
  299. };
  300. int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
  301. {
  302. int ret = 0;
  303. struct nfc_dev *nfc_dev = NULL;
  304. struct i2c_dev *i2c_dev = NULL;
  305. struct platform_configs nfc_configs;
  306. struct platform_gpio *nfc_gpio = &nfc_configs.gpio;
  307. pr_debug("%s: enter\n", __func__);
  308. /* retrieve details of gpios from dt */
  309. ret = nfc_parse_dt(&client->dev, &nfc_configs, PLATFORM_IF_I2C);
  310. if (ret) {
  311. pr_err("%s: failed to parse dt\n", __func__);
  312. goto err;
  313. }
  314. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  315. pr_err("%s: need I2C_FUNC_I2C\n", __func__);
  316. ret = -ENODEV;
  317. goto err;
  318. }
  319. nfc_dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
  320. if (nfc_dev == NULL) {
  321. ret = -ENOMEM;
  322. goto err;
  323. }
  324. nfc_dev->read_kbuf = kzalloc(MAX_NCI_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  325. if (!nfc_dev->read_kbuf) {
  326. ret = -ENOMEM;
  327. goto err_free_nfc_dev;
  328. }
  329. nfc_dev->write_kbuf = kzalloc(MAX_DL_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  330. if (!nfc_dev->write_kbuf) {
  331. ret = -ENOMEM;
  332. goto err_free_read_kbuf;
  333. }
  334. nfc_dev->interface = PLATFORM_IF_I2C;
  335. nfc_dev->nfc_state = NFC_STATE_NCI;
  336. nfc_dev->i2c_dev.client = client;
  337. i2c_dev = &nfc_dev->i2c_dev;
  338. nfc_dev->nfc_read = i2c_read;
  339. nfc_dev->nfc_write = i2c_write;
  340. nfc_dev->nfc_enable_intr = i2c_enable_irq;
  341. nfc_dev->nfc_disable_intr = i2c_disable_irq;
  342. ret = configure_gpio(nfc_gpio->ven, GPIO_OUTPUT);
  343. if (ret) {
  344. pr_err("%s: unable to request nfc reset gpio [%d]\n", __func__,
  345. nfc_gpio->ven);
  346. goto err_free_write_kbuf;
  347. }
  348. ret = configure_gpio(nfc_gpio->irq, GPIO_IRQ);
  349. if (ret <= 0) {
  350. pr_err("%s: unable to request nfc irq gpio [%d]\n", __func__,
  351. nfc_gpio->irq);
  352. goto err_free_gpio;
  353. }
  354. client->irq = ret;
  355. ret = configure_gpio(nfc_gpio->dwl_req, GPIO_OUTPUT);
  356. if (ret) {
  357. pr_err("%s: unable to request nfc firm downl gpio [%d]\n",
  358. __func__, nfc_gpio->dwl_req);
  359. }
  360. /* copy the retrieved gpio details from DT */
  361. memcpy(&nfc_dev->configs, &nfc_configs,
  362. sizeof(struct platform_configs));
  363. /* init mutex and queues */
  364. init_waitqueue_head(&nfc_dev->read_wq);
  365. mutex_init(&nfc_dev->read_mutex);
  366. mutex_init(&nfc_dev->write_mutex);
  367. mutex_init(&nfc_dev->dev_ref_mutex);
  368. spin_lock_init(&i2c_dev->irq_enabled_lock);
  369. ret = nfc_misc_register(nfc_dev, &nfc_i2c_dev_fops, DEV_COUNT,
  370. NFC_CHAR_DEV_NAME, CLASS_NAME);
  371. if (ret) {
  372. pr_err("%s: nfc_misc_register failed\n", __func__);
  373. goto err_mutex_destroy;
  374. }
  375. /* interrupt initializations */
  376. pr_info("%s: requesting IRQ %d\n", __func__, client->irq);
  377. i2c_dev->irq_enabled = true;
  378. ret = request_irq(client->irq, i2c_irq_handler, IRQF_TRIGGER_HIGH,
  379. client->name, nfc_dev);
  380. if (ret) {
  381. pr_err("%s: request_irq failed\n", __func__);
  382. goto err_nfc_misc_unregister;
  383. }
  384. i2c_disable_irq(nfc_dev);
  385. ret = nfc_ldo_config(&client->dev, nfc_dev);
  386. if (ret) {
  387. pr_err("LDO config failed\n");
  388. goto err_ldo_config_failed;
  389. }
  390. ret = nfcc_hw_check(nfc_dev);
  391. if (ret || nfc_dev->nfc_state == NFC_STATE_UNKNOWN) {
  392. pr_err("nfc hw check failed ret %d\n", ret);
  393. goto err_nfcc_hw_check;
  394. }
  395. if(nfc_dev->configs.clk_pin_voting)
  396. nfc_dev->clk_run = false;
  397. else
  398. nfc_dev->clk_run = true;
  399. gpio_set_ven(nfc_dev, 1);
  400. gpio_set_ven(nfc_dev, 0);
  401. gpio_set_ven(nfc_dev, 1);
  402. device_init_wakeup(&client->dev, true);
  403. i2c_set_clientdata(client, nfc_dev);
  404. i2c_dev->irq_wake_up = false;
  405. nfc_dev->is_ese_session_active = false;
  406. pr_info("%s: probing nfc i2c successfully\n", __func__);
  407. return 0;
  408. err_nfcc_hw_check:
  409. if (nfc_dev->reg) {
  410. nfc_ldo_unvote(nfc_dev);
  411. regulator_put(nfc_dev->reg);
  412. }
  413. err_ldo_config_failed:
  414. free_irq(client->irq, nfc_dev);
  415. err_nfc_misc_unregister:
  416. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  417. err_mutex_destroy:
  418. mutex_destroy(&nfc_dev->dev_ref_mutex);
  419. mutex_destroy(&nfc_dev->read_mutex);
  420. mutex_destroy(&nfc_dev->write_mutex);
  421. err_free_gpio:
  422. gpio_free_all(nfc_dev);
  423. err_free_write_kbuf:
  424. kfree(nfc_dev->write_kbuf);
  425. err_free_read_kbuf:
  426. kfree(nfc_dev->read_kbuf);
  427. err_free_nfc_dev:
  428. kfree(nfc_dev);
  429. err:
  430. pr_err("%s: probing not successful, check hardware\n", __func__);
  431. return ret;
  432. }
  433. int nfc_i2c_dev_remove(struct i2c_client *client)
  434. {
  435. int ret = 0;
  436. struct nfc_dev *nfc_dev = NULL;
  437. pr_info("%s: remove device\n", __func__);
  438. nfc_dev = i2c_get_clientdata(client);
  439. if (!nfc_dev) {
  440. pr_err("%s: device doesn't exist anymore\n", __func__);
  441. ret = -ENODEV;
  442. return ret;
  443. }
  444. if (nfc_dev->dev_ref_count > 0) {
  445. pr_err("%s: device already in use\n", __func__);
  446. return -EBUSY;
  447. }
  448. gpio_set_value(nfc_dev->configs.gpio.ven, 0);
  449. // HW dependent delay before LDO goes into LPM mode
  450. usleep_range(10000, 10100);
  451. if (nfc_dev->reg) {
  452. nfc_ldo_unvote(nfc_dev);
  453. regulator_put(nfc_dev->reg);
  454. }
  455. device_init_wakeup(&client->dev, false);
  456. free_irq(client->irq, nfc_dev);
  457. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  458. mutex_destroy(&nfc_dev->dev_ref_mutex);
  459. mutex_destroy(&nfc_dev->read_mutex);
  460. mutex_destroy(&nfc_dev->write_mutex);
  461. gpio_free_all(nfc_dev);
  462. kfree(nfc_dev->read_kbuf);
  463. kfree(nfc_dev->write_kbuf);
  464. kfree(nfc_dev);
  465. return ret;
  466. }
  467. int nfc_i2c_dev_suspend(struct device *device)
  468. {
  469. struct i2c_client *client = to_i2c_client(device);
  470. struct nfc_dev *nfc_dev = i2c_get_clientdata(client);
  471. struct i2c_dev *i2c_dev = NULL;
  472. if (!nfc_dev) {
  473. pr_err("%s: device doesn't exist anymore\n", __func__);
  474. return -ENODEV;
  475. }
  476. i2c_dev = &nfc_dev->i2c_dev;
  477. NFCLOG_IPC(nfc_dev, false, "%s: irq_enabled = %d", __func__,
  478. i2c_dev->irq_enabled);
  479. if (device_may_wakeup(&client->dev) && i2c_dev->irq_enabled) {
  480. if (!enable_irq_wake(client->irq))
  481. i2c_dev->irq_wake_up = true;
  482. }
  483. pr_debug("%s: irq_wake_up = %d", __func__, i2c_dev->irq_wake_up);
  484. return 0;
  485. }
  486. int nfc_i2c_dev_resume(struct device *device)
  487. {
  488. struct i2c_client *client = to_i2c_client(device);
  489. struct nfc_dev *nfc_dev = i2c_get_clientdata(client);
  490. struct i2c_dev *i2c_dev = NULL;
  491. if (!nfc_dev) {
  492. pr_err("%s: device doesn't exist anymore\n", __func__);
  493. return -ENODEV;
  494. }
  495. i2c_dev = &nfc_dev->i2c_dev;
  496. NFCLOG_IPC(nfc_dev, false, "%s: irq_wake_up = %d", __func__,
  497. i2c_dev->irq_wake_up);
  498. if (device_may_wakeup(&client->dev) && i2c_dev->irq_wake_up) {
  499. if (!disable_irq_wake(client->irq))
  500. i2c_dev->irq_wake_up = false;
  501. }
  502. pr_debug("%s: irq_wake_up = %d", __func__, i2c_dev->irq_wake_up);
  503. return 0;
  504. }
  505. static const struct i2c_device_id nfc_i2c_dev_id[] = { { NFC_I2C_DEV_ID, 0 },
  506. {} };
  507. static const struct of_device_id nfc_i2c_dev_match_table[] = {
  508. {
  509. .compatible = NFC_I2C_DRV_STR,
  510. },
  511. {}
  512. };
  513. static const struct dev_pm_ops nfc_i2c_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(
  514. nfc_i2c_dev_suspend, nfc_i2c_dev_resume) };
  515. static struct i2c_driver nfc_i2c_dev_driver = {
  516. .id_table = nfc_i2c_dev_id,
  517. .probe = nfc_i2c_dev_probe,
  518. .remove = nfc_i2c_dev_remove,
  519. .driver = {
  520. .name = NFC_I2C_DRV_STR,
  521. .pm = &nfc_i2c_dev_pm_ops,
  522. .of_match_table = nfc_i2c_dev_match_table,
  523. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  524. },
  525. };
  526. MODULE_DEVICE_TABLE(of, nfc_i2c_dev_match_table);
  527. static int __init nfc_i2c_dev_init(void)
  528. {
  529. int ret = 0;
  530. pr_info("%s: Loading NXP NFC I2C driver\n", __func__);
  531. ret = i2c_add_driver(&nfc_i2c_dev_driver);
  532. if (ret != 0)
  533. pr_err("%s: NFC I2C add driver error ret %d\n", __func__, ret);
  534. return ret;
  535. }
  536. module_init(nfc_i2c_dev_init);
  537. static void __exit nfc_i2c_dev_exit(void)
  538. {
  539. pr_info("%s: Unloading NXP NFC I2C driver\n", __func__);
  540. i2c_del_driver(&nfc_i2c_dev_driver);
  541. }
  542. module_exit(nfc_i2c_dev_exit);
  543. MODULE_DESCRIPTION("NXP NFC I2C driver");
  544. MODULE_LICENSE("GPL");