i2c_drv.c 17 KB

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