i2c_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  1. /******************************************************************************
  2. * Copyright (C) 2015, The Linux Foundation. All rights reserved.
  3. * Copyright (C) 2013-2022 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(!nfc_dev->secure_zone) {
  143. if (!gpio_get_value(nfc_gpio->ven)) {
  144. pr_info("%s: releasing read\n", __func__);
  145. ret = -EIO;
  146. goto err;
  147. }
  148. }
  149. /*
  150. * NFC service wanted to close the driver so,
  151. * release the calling reader thread asap.
  152. *
  153. * This can happen in case of nfc node close call from
  154. * eSE HAL in that case the NFC HAL reader thread
  155. * will again call read system call
  156. */
  157. if (nfc_dev->release_read) {
  158. pr_debug("%s: releasing read\n", __func__);
  159. return 0;
  160. }
  161. pr_warn("%s: spurious interrupt detected\n", __func__);
  162. }
  163. }
  164. memset(buf, 0x00, count);
  165. /* Read data */
  166. ret = i2c_master_recv(nfc_dev->i2c_dev.client, buf, count);
  167. NFCLOG_IPC(nfc_dev, false, "%s of %d bytes, ret %d", __func__, count,
  168. ret);
  169. if (ret <= 0) {
  170. pr_err("%s: returned %d\n", __func__, ret);
  171. goto err;
  172. }
  173. for (i = 0; i < disp_len; i++)
  174. NFCLOG_IPC(nfc_dev, false, " %02x", buf[i]);
  175. /* check if it's response of cold reset command
  176. * NFC HAL process shouldn't receive this data as
  177. * command was sent by esepowermanager
  178. */
  179. if (nfc_dev->cold_reset.rsp_pending && nfc_dev->cold_reset.cmd_buf
  180. && (buf[0] == PROP_NCI_RSP_GID)
  181. && (buf[1] == nfc_dev->cold_reset.cmd_buf[1])) {
  182. read_cold_reset_rsp(nfc_dev, buf);
  183. nfc_dev->cold_reset.rsp_pending = false;
  184. wake_up_interruptible(&nfc_dev->cold_reset.read_wq);
  185. /*
  186. * NFC process doesn't know about cold reset command
  187. * being sent as it was initiated by eSE process
  188. * we shouldn't return any data to NFC process
  189. */
  190. return 0;
  191. }
  192. err:
  193. return ret;
  194. }
  195. int i2c_write(struct nfc_dev *nfc_dev, const char *buf, size_t count,
  196. int max_retry_cnt)
  197. {
  198. int ret = -EINVAL;
  199. int retry_cnt;
  200. uint16_t i = 0;
  201. uint16_t disp_len = GET_IPCLOG_MAX_PKT_LEN(count);
  202. struct platform_gpio *nfc_gpio = &nfc_dev->configs.gpio;
  203. if (count > MAX_DL_BUFFER_SIZE)
  204. count = MAX_DL_BUFFER_SIZE;
  205. pr_debug("%s: writing %zu bytes.\n", __func__, count);
  206. NFCLOG_IPC(nfc_dev, false, "%s sending %d B", __func__, count);
  207. for (i = 0; i < disp_len; i++)
  208. NFCLOG_IPC(nfc_dev, false, " %02x", buf[i]);
  209. /*
  210. * Wait for any pending read for max 15ms before write
  211. * This is to avoid any packet corruption during read, when
  212. * the host cmds resets NFCC during any parallel read operation
  213. */
  214. for (retry_cnt = 1; retry_cnt <= MAX_WRITE_IRQ_COUNT; retry_cnt++) {
  215. if (gpio_get_value(nfc_gpio->irq)) {
  216. pr_warn("%s: irq high during write, wait\n", __func__);
  217. usleep_range(WRITE_RETRY_WAIT_TIME_US,
  218. WRITE_RETRY_WAIT_TIME_US + 100);
  219. } else {
  220. break;
  221. }
  222. if (retry_cnt == MAX_WRITE_IRQ_COUNT &&
  223. gpio_get_value(nfc_gpio->irq)) {
  224. pr_warn("%s: allow after maximum wait\n", __func__);
  225. }
  226. }
  227. for (retry_cnt = 1; retry_cnt <= max_retry_cnt; retry_cnt++) {
  228. ret = i2c_master_send(nfc_dev->i2c_dev.client, buf, count);
  229. NFCLOG_IPC(nfc_dev, false, "%s ret %d", __func__, ret);
  230. if (ret <= 0) {
  231. pr_warn("%s: write failed ret(%d), maybe in standby\n",
  232. __func__, ret);
  233. usleep_range(WRITE_RETRY_WAIT_TIME_US,
  234. WRITE_RETRY_WAIT_TIME_US + 100);
  235. } else if (ret != count) {
  236. pr_err("%s: failed to write %d\n", __func__, ret);
  237. ret = -EIO;
  238. } else if (ret == count)
  239. break;
  240. }
  241. return ret;
  242. }
  243. ssize_t nfc_i2c_dev_read(struct file *filp, char __user *buf, size_t count,
  244. loff_t *offset)
  245. {
  246. int ret;
  247. struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
  248. if (!nfc_dev) {
  249. pr_err("%s: device doesn't exist anymore\n", __func__);
  250. return -ENODEV;
  251. }
  252. mutex_lock(&nfc_dev->read_mutex);
  253. if (count > MAX_NCI_BUFFER_SIZE)
  254. count = MAX_NCI_BUFFER_SIZE;
  255. if (filp->f_flags & O_NONBLOCK) {
  256. ret = i2c_master_recv(nfc_dev->i2c_dev.client, nfc_dev->read_kbuf, count);
  257. pr_debug("%s: NONBLOCK read ret = %d\n", __func__, ret);
  258. } else {
  259. ret = i2c_read(nfc_dev, nfc_dev->read_kbuf, count, 0);
  260. }
  261. if (ret > 0) {
  262. if (copy_to_user(buf, nfc_dev->read_kbuf, ret)) {
  263. pr_warn("%s: failed to copy to user space\n", __func__);
  264. ret = -EFAULT;
  265. }
  266. }
  267. mutex_unlock(&nfc_dev->read_mutex);
  268. return ret;
  269. }
  270. ssize_t nfc_i2c_dev_write(struct file *filp, const char __user *buf,
  271. size_t count, loff_t *offset)
  272. {
  273. int ret;
  274. struct nfc_dev *nfc_dev = (struct nfc_dev *)filp->private_data;
  275. if (count > MAX_DL_BUFFER_SIZE)
  276. count = MAX_DL_BUFFER_SIZE;
  277. if (!nfc_dev) {
  278. pr_err("%s: device doesn't exist anymore\n", __func__);
  279. return -ENODEV;
  280. }
  281. mutex_lock(&nfc_dev->write_mutex);
  282. if (copy_from_user(nfc_dev->write_kbuf, buf, count)) {
  283. pr_err("%s: failed to copy from user space\n", __func__);
  284. mutex_unlock(&nfc_dev->write_mutex);
  285. return -EFAULT;
  286. }
  287. ret = i2c_write(nfc_dev, nfc_dev->write_kbuf, count, NO_RETRY);
  288. mutex_unlock(&nfc_dev->write_mutex);
  289. return ret;
  290. }
  291. static const struct file_operations nfc_i2c_dev_fops = {
  292. .owner = THIS_MODULE,
  293. .llseek = no_llseek,
  294. .read = nfc_i2c_dev_read,
  295. .write = nfc_i2c_dev_write,
  296. .open = nfc_dev_open,
  297. .flush = nfc_dev_flush,
  298. .release = nfc_dev_close,
  299. .unlocked_ioctl = nfc_dev_ioctl,
  300. #ifdef CONFIG_COMPAT
  301. .compat_ioctl = nfc_dev_compat_ioctl,
  302. #endif
  303. };
  304. int nfc_i2c_dev_probe(struct i2c_client *client, const struct i2c_device_id *id)
  305. {
  306. int ret = 0;
  307. struct nfc_dev *nfc_dev = NULL;
  308. struct i2c_dev *i2c_dev = NULL;
  309. struct platform_configs *nfc_configs = NULL;
  310. struct platform_gpio *nfc_gpio = NULL;
  311. pr_debug("%s: enter\n", __func__);
  312. nfc_dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
  313. if (nfc_dev == NULL) {
  314. ret = -ENOMEM;
  315. goto err;
  316. }
  317. nfc_configs = &nfc_dev->configs;
  318. nfc_gpio = &nfc_configs->gpio;
  319. /* retrieve details of gpios from dt */
  320. ret = nfc_parse_dt(&client->dev,nfc_configs, PLATFORM_IF_I2C);
  321. if (ret) {
  322. pr_err("%s: failed to parse dt\n", __func__);
  323. goto err_free_nfc_dev;
  324. }
  325. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  326. pr_err("%s: need I2C_FUNC_I2C\n", __func__);
  327. ret = -ENODEV;
  328. goto err_free_nfc_dev;
  329. }
  330. nfc_dev->read_kbuf = kzalloc(MAX_NCI_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  331. if (!nfc_dev->read_kbuf) {
  332. ret = -ENOMEM;
  333. goto err_free_nfc_dev;
  334. }
  335. nfc_dev->write_kbuf = kzalloc(MAX_DL_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  336. if (!nfc_dev->write_kbuf) {
  337. ret = -ENOMEM;
  338. goto err_free_read_kbuf;
  339. }
  340. nfc_dev->interface = PLATFORM_IF_I2C;
  341. nfc_dev->nfc_state = NFC_STATE_NCI;
  342. nfc_dev->i2c_dev.client = client;
  343. i2c_dev = &nfc_dev->i2c_dev;
  344. nfc_dev->nfc_read = i2c_read;
  345. nfc_dev->nfc_write = i2c_write;
  346. nfc_dev->nfc_enable_intr = i2c_enable_irq;
  347. nfc_dev->nfc_disable_intr = i2c_disable_irq;
  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. /* init mutex and queues */
  356. init_waitqueue_head(&nfc_dev->read_wq);
  357. mutex_init(&nfc_dev->read_mutex);
  358. mutex_init(&nfc_dev->write_mutex);
  359. mutex_init(&nfc_dev->dev_ref_mutex);
  360. spin_lock_init(&i2c_dev->irq_enabled_lock);
  361. ret = nfc_misc_register(nfc_dev, &nfc_i2c_dev_fops, DEV_COUNT,
  362. NFC_CHAR_DEV_NAME, CLASS_NAME);
  363. if (ret) {
  364. pr_err("%s: nfc_misc_register failed\n", __func__);
  365. goto err_mutex_destroy;
  366. }
  367. /* interrupt initializations */
  368. pr_info("%s: requesting IRQ %d\n", __func__, client->irq);
  369. i2c_dev->irq_enabled = true;
  370. ret = request_irq(client->irq, i2c_irq_handler, IRQF_TRIGGER_HIGH,
  371. client->name, nfc_dev);
  372. if (ret) {
  373. pr_err("%s: request_irq failed\n", __func__);
  374. goto err_nfc_misc_unregister;
  375. }
  376. i2c_disable_irq(nfc_dev);
  377. ret = nfc_ldo_config(&client->dev, nfc_dev);
  378. if (ret) {
  379. pr_err("LDO config failed\n");
  380. goto err_ldo_config_failed;
  381. }
  382. if( nfc_dev->configs.CNSS_NFC_HW_SECURE_ENABLE == true) {
  383. /*Check NFC Secure Zone status*/
  384. if(!nfc_hw_secure_check()) {
  385. nfc_post_init(nfc_dev);
  386. nfc_dev->secure_zone = false;
  387. }
  388. else {
  389. nfc_dev->secure_zone = true;
  390. }
  391. pr_info("%s:nfc secure_zone = %s", __func__, nfc_dev->secure_zone ? "true" : "false");
  392. }else {
  393. nfc_post_init(nfc_dev);
  394. }
  395. device_init_wakeup(&client->dev, true);
  396. i2c_set_clientdata(client, nfc_dev);
  397. i2c_dev->irq_wake_up = false;
  398. nfc_dev->is_ese_session_active = false;
  399. pr_info("%s: probing nfc i2c success\n", __func__);
  400. return 0;
  401. err_ldo_config_failed:
  402. free_irq(client->irq, nfc_dev);
  403. err_nfc_misc_unregister:
  404. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  405. err_mutex_destroy:
  406. mutex_destroy(&nfc_dev->dev_ref_mutex);
  407. mutex_destroy(&nfc_dev->read_mutex);
  408. mutex_destroy(&nfc_dev->write_mutex);
  409. err_free_gpio:
  410. gpio_free_all(nfc_dev);
  411. kfree(nfc_dev->write_kbuf);
  412. err_free_read_kbuf:
  413. kfree(nfc_dev->read_kbuf);
  414. err_free_nfc_dev:
  415. kfree(nfc_dev);
  416. err:
  417. pr_err("%s: probing not successful, check hardware\n", __func__);
  418. return ret;
  419. }
  420. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  421. void nfc_i2c_dev_remove(struct i2c_client *client)
  422. #else
  423. int nfc_i2c_dev_remove(struct i2c_client *client)
  424. #endif
  425. {
  426. struct nfc_dev *nfc_dev = NULL;
  427. pr_info("%s: remove device\n", __func__);
  428. nfc_dev = i2c_get_clientdata(client);
  429. if (!nfc_dev) {
  430. pr_err("%s: device doesn't exist anymore\n", __func__);
  431. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  432. return -ENODEV;
  433. #endif
  434. }
  435. if (nfc_dev->dev_ref_count > 0) {
  436. pr_err("%s: device already in use\n", __func__);
  437. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  438. return -EBUSY;
  439. #endif
  440. }
  441. gpio_set_value(nfc_dev->configs.gpio.ven, 0);
  442. // HW dependent delay before LDO goes into LPM mode
  443. usleep_range(10000, 10100);
  444. if (nfc_dev->reg) {
  445. nfc_ldo_unvote(nfc_dev);
  446. regulator_put(nfc_dev->reg);
  447. }
  448. device_init_wakeup(&client->dev, false);
  449. free_irq(client->irq, nfc_dev);
  450. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  451. mutex_destroy(&nfc_dev->dev_ref_mutex);
  452. mutex_destroy(&nfc_dev->read_mutex);
  453. mutex_destroy(&nfc_dev->write_mutex);
  454. gpio_free_all(nfc_dev);
  455. kfree(nfc_dev->read_kbuf);
  456. kfree(nfc_dev->write_kbuf);
  457. kfree(nfc_dev);
  458. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  459. return 0;
  460. #endif
  461. }
  462. int nfc_i2c_dev_suspend(struct device *device)
  463. {
  464. struct i2c_client *client = to_i2c_client(device);
  465. struct nfc_dev *nfc_dev = i2c_get_clientdata(client);
  466. struct i2c_dev *i2c_dev = NULL;
  467. if (!nfc_dev) {
  468. pr_err("%s: device doesn't exist anymore\n", __func__);
  469. return -ENODEV;
  470. }
  471. i2c_dev = &nfc_dev->i2c_dev;
  472. NFCLOG_IPC(nfc_dev, false, "%s: irq_enabled = %d", __func__,
  473. i2c_dev->irq_enabled);
  474. if (device_may_wakeup(&client->dev) && i2c_dev->irq_enabled) {
  475. if (!enable_irq_wake(client->irq))
  476. i2c_dev->irq_wake_up = true;
  477. }
  478. pr_debug("%s: irq_wake_up = %d", __func__, i2c_dev->irq_wake_up);
  479. return 0;
  480. }
  481. int nfc_i2c_dev_resume(struct device *device)
  482. {
  483. struct i2c_client *client = to_i2c_client(device);
  484. struct nfc_dev *nfc_dev = i2c_get_clientdata(client);
  485. struct i2c_dev *i2c_dev = NULL;
  486. if (!nfc_dev) {
  487. pr_err("%s: device doesn't exist anymore\n", __func__);
  488. return -ENODEV;
  489. }
  490. i2c_dev = &nfc_dev->i2c_dev;
  491. NFCLOG_IPC(nfc_dev, false, "%s: irq_wake_up = %d", __func__,
  492. i2c_dev->irq_wake_up);
  493. if (device_may_wakeup(&client->dev) && i2c_dev->irq_wake_up) {
  494. if (!disable_irq_wake(client->irq))
  495. i2c_dev->irq_wake_up = false;
  496. }
  497. pr_debug("%s: irq_wake_up = %d", __func__, i2c_dev->irq_wake_up);
  498. return 0;
  499. }
  500. static const struct i2c_device_id nfc_i2c_dev_id[] = { { NFC_I2C_DEV_ID, 0 },
  501. {} };
  502. static const struct of_device_id nfc_i2c_dev_match_table[] = {
  503. {
  504. .compatible = NFC_I2C_DRV_STR,
  505. },
  506. {}
  507. };
  508. static const struct dev_pm_ops nfc_i2c_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(
  509. nfc_i2c_dev_suspend, nfc_i2c_dev_resume) };
  510. static struct i2c_driver nfc_i2c_dev_driver = {
  511. .id_table = nfc_i2c_dev_id,
  512. .probe = nfc_i2c_dev_probe,
  513. .remove = nfc_i2c_dev_remove,
  514. .driver = {
  515. .name = NFC_I2C_DRV_STR,
  516. .pm = &nfc_i2c_dev_pm_ops,
  517. .of_match_table = nfc_i2c_dev_match_table,
  518. .probe_type = PROBE_PREFER_ASYNCHRONOUS,
  519. },
  520. };
  521. MODULE_DEVICE_TABLE(of, nfc_i2c_dev_match_table);
  522. static int __init nfc_i2c_dev_init(void)
  523. {
  524. int ret = 0;
  525. pr_info("%s: Loading NXP NFC I2C driver\n", __func__);
  526. ret = i2c_add_driver(&nfc_i2c_dev_driver);
  527. if (ret != 0)
  528. pr_err("%s: NFC I2C add driver error ret %d\n", __func__, ret);
  529. return ret;
  530. }
  531. module_init(nfc_i2c_dev_init);
  532. static void __exit nfc_i2c_dev_exit(void)
  533. {
  534. pr_info("%s: Unloading NXP NFC I2C driver\n", __func__);
  535. i2c_del_driver(&nfc_i2c_dev_driver);
  536. }
  537. module_exit(nfc_i2c_dev_exit);
  538. MODULE_DESCRIPTION("NXP NFC I2C driver");
  539. MODULE_LICENSE("GPL");