i2c_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  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 (!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(WRITE_RETRY_WAIT_TIME_US,
  216. WRITE_RETRY_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 = NULL;
  306. struct platform_gpio *nfc_gpio = NULL;
  307. pr_debug("%s: enter\n", __func__);
  308. nfc_dev = kzalloc(sizeof(struct nfc_dev), GFP_KERNEL);
  309. if (nfc_dev == NULL) {
  310. ret = -ENOMEM;
  311. goto err;
  312. }
  313. nfc_configs = &nfc_dev->configs;
  314. nfc_gpio = &nfc_configs->gpio;
  315. /* retrieve details of gpios from dt */
  316. ret = nfc_parse_dt(&client->dev,nfc_configs, PLATFORM_IF_I2C);
  317. if (ret) {
  318. pr_err("%s: failed to parse dt\n", __func__);
  319. goto err_free_nfc_dev;
  320. }
  321. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  322. pr_err("%s: need I2C_FUNC_I2C\n", __func__);
  323. ret = -ENODEV;
  324. goto err_free_nfc_dev;
  325. }
  326. nfc_dev->read_kbuf = kzalloc(MAX_NCI_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  327. if (!nfc_dev->read_kbuf) {
  328. ret = -ENOMEM;
  329. goto err_free_nfc_dev;
  330. }
  331. nfc_dev->write_kbuf = kzalloc(MAX_DL_BUFFER_SIZE, GFP_DMA | GFP_KERNEL);
  332. if (!nfc_dev->write_kbuf) {
  333. ret = -ENOMEM;
  334. goto err_free_read_kbuf;
  335. }
  336. nfc_dev->interface = PLATFORM_IF_I2C;
  337. nfc_dev->nfc_state = NFC_STATE_NCI;
  338. nfc_dev->i2c_dev.client = client;
  339. i2c_dev = &nfc_dev->i2c_dev;
  340. nfc_dev->nfc_read = i2c_read;
  341. nfc_dev->nfc_write = i2c_write;
  342. nfc_dev->nfc_enable_intr = i2c_enable_irq;
  343. nfc_dev->nfc_disable_intr = i2c_disable_irq;
  344. ret = configure_gpio(nfc_gpio->ven, GPIO_OUTPUT);
  345. if (ret) {
  346. pr_err("%s: unable to request nfc reset gpio [%d]\n", __func__,
  347. nfc_gpio->ven);
  348. goto err_free_write_kbuf;
  349. }
  350. ret = configure_gpio(nfc_gpio->irq, GPIO_IRQ);
  351. if (ret <= 0) {
  352. pr_err("%s: unable to request nfc irq gpio [%d]\n", __func__,
  353. nfc_gpio->irq);
  354. goto err_free_gpio;
  355. }
  356. client->irq = ret;
  357. ret = configure_gpio(nfc_gpio->dwl_req, GPIO_OUTPUT);
  358. if (ret) {
  359. pr_err("%s: unable to request nfc firm downl gpio [%d]\n",
  360. __func__, nfc_gpio->dwl_req);
  361. }
  362. /* init mutex and queues */
  363. init_waitqueue_head(&nfc_dev->read_wq);
  364. mutex_init(&nfc_dev->read_mutex);
  365. mutex_init(&nfc_dev->write_mutex);
  366. mutex_init(&nfc_dev->dev_ref_mutex);
  367. spin_lock_init(&i2c_dev->irq_enabled_lock);
  368. ret = nfc_misc_register(nfc_dev, &nfc_i2c_dev_fops, DEV_COUNT,
  369. NFC_CHAR_DEV_NAME, CLASS_NAME);
  370. if (ret) {
  371. pr_err("%s: nfc_misc_register failed\n", __func__);
  372. goto err_mutex_destroy;
  373. }
  374. /* interrupt initializations */
  375. pr_info("%s: requesting IRQ %d\n", __func__, client->irq);
  376. i2c_dev->irq_enabled = true;
  377. ret = request_irq(client->irq, i2c_irq_handler, IRQF_TRIGGER_HIGH,
  378. client->name, nfc_dev);
  379. if (ret) {
  380. pr_err("%s: request_irq failed\n", __func__);
  381. goto err_nfc_misc_unregister;
  382. }
  383. i2c_disable_irq(nfc_dev);
  384. ret = nfc_ldo_config(&client->dev, nfc_dev);
  385. if (ret) {
  386. pr_err("LDO config failed\n");
  387. goto err_ldo_config_failed;
  388. }
  389. ret = nfcc_hw_check(nfc_dev);
  390. if (ret || nfc_dev->nfc_state == NFC_STATE_UNKNOWN) {
  391. pr_err("nfc hw check failed ret %d\n", ret);
  392. goto err_nfcc_hw_check;
  393. }
  394. gpio_set_ven(nfc_dev, 1);
  395. gpio_set_ven(nfc_dev, 0);
  396. gpio_set_ven(nfc_dev, 1);
  397. device_init_wakeup(&client->dev, true);
  398. i2c_set_clientdata(client, nfc_dev);
  399. i2c_dev->irq_wake_up = false;
  400. nfc_dev->is_ese_session_active = false;
  401. pr_info("%s: probing nfc i2c successfully\n", __func__);
  402. return 0;
  403. err_nfcc_hw_check:
  404. if (nfc_dev->reg) {
  405. nfc_ldo_unvote(nfc_dev);
  406. regulator_put(nfc_dev->reg);
  407. }
  408. err_ldo_config_failed:
  409. free_irq(client->irq, nfc_dev);
  410. err_nfc_misc_unregister:
  411. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  412. err_mutex_destroy:
  413. mutex_destroy(&nfc_dev->dev_ref_mutex);
  414. mutex_destroy(&nfc_dev->read_mutex);
  415. mutex_destroy(&nfc_dev->write_mutex);
  416. err_free_gpio:
  417. gpio_free_all(nfc_dev);
  418. err_free_write_kbuf:
  419. kfree(nfc_dev->write_kbuf);
  420. err_free_read_kbuf:
  421. kfree(nfc_dev->read_kbuf);
  422. err_free_nfc_dev:
  423. kfree(nfc_dev);
  424. err:
  425. pr_err("%s: probing not successful, check hardware\n", __func__);
  426. return ret;
  427. }
  428. int nfc_i2c_dev_remove(struct i2c_client *client)
  429. {
  430. int ret = 0;
  431. struct nfc_dev *nfc_dev = NULL;
  432. pr_info("%s: remove device\n", __func__);
  433. nfc_dev = i2c_get_clientdata(client);
  434. if (!nfc_dev) {
  435. pr_err("%s: device doesn't exist anymore\n", __func__);
  436. ret = -ENODEV;
  437. return ret;
  438. }
  439. if (nfc_dev->dev_ref_count > 0) {
  440. pr_err("%s: device already in use\n", __func__);
  441. return -EBUSY;
  442. }
  443. gpio_set_value(nfc_dev->configs.gpio.ven, 0);
  444. // HW dependent delay before LDO goes into LPM mode
  445. usleep_range(10000, 10100);
  446. if (nfc_dev->reg) {
  447. nfc_ldo_unvote(nfc_dev);
  448. regulator_put(nfc_dev->reg);
  449. }
  450. device_init_wakeup(&client->dev, false);
  451. free_irq(client->irq, nfc_dev);
  452. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  453. mutex_destroy(&nfc_dev->dev_ref_mutex);
  454. mutex_destroy(&nfc_dev->read_mutex);
  455. mutex_destroy(&nfc_dev->write_mutex);
  456. gpio_free_all(nfc_dev);
  457. kfree(nfc_dev->read_kbuf);
  458. kfree(nfc_dev->write_kbuf);
  459. kfree(nfc_dev);
  460. return ret;
  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");