i2c_drv.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  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-2023 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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %s: releasing read\n", __func__);
  159. return 0;
  160. }
  161. pr_warn("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %s: nfc_misc_register failed\n", __func__);
  365. goto err_mutex_destroy;
  366. }
  367. /* interrupt initializations */
  368. pr_info("NxpDrv: %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("NxpDrv: %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("NxpDrv: LDO config failed\n");
  380. goto err_ldo_config_failed;
  381. }
  382. #ifdef NFC_SECURE_PERIPHERAL_ENABLED
  383. if( nfc_dev->configs.CNSS_NFC_HW_SECURE_ENABLE == true) {
  384. /*Check NFC Secure Zone status*/
  385. if(!nfc_hw_secure_check()) {
  386. nfc_post_init(nfc_dev);
  387. nfc_dev->secure_zone = false;
  388. }
  389. else {
  390. nfc_dev->secure_zone = true;
  391. }
  392. pr_info("NxpDrv: %s:nfc secure_zone = %s", __func__, nfc_dev->secure_zone ? "true" : "false");
  393. }else {
  394. nfc_post_init(nfc_dev);
  395. }
  396. #else
  397. nfc_dev->secure_zone = false;
  398. nfc_post_init(nfc_dev);
  399. #endif
  400. device_init_wakeup(&client->dev, true);
  401. i2c_set_clientdata(client, nfc_dev);
  402. i2c_dev->irq_wake_up = false;
  403. nfc_dev->is_ese_session_active = false;
  404. pr_info("NxpDrv: %s: probing nfc i2c success\n", __func__);
  405. return 0;
  406. err_ldo_config_failed:
  407. free_irq(client->irq, nfc_dev);
  408. err_nfc_misc_unregister:
  409. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  410. err_mutex_destroy:
  411. mutex_destroy(&nfc_dev->dev_ref_mutex);
  412. mutex_destroy(&nfc_dev->read_mutex);
  413. mutex_destroy(&nfc_dev->write_mutex);
  414. err_free_gpio:
  415. gpio_free_all(nfc_dev);
  416. kfree(nfc_dev->write_kbuf);
  417. err_free_read_kbuf:
  418. kfree(nfc_dev->read_kbuf);
  419. err_free_nfc_dev:
  420. kfree(nfc_dev);
  421. err:
  422. pr_err("NxpDrv: %s: probing not successful, check hardware\n", __func__);
  423. return ret;
  424. }
  425. #if (LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0))
  426. void nfc_i2c_dev_remove(struct i2c_client *client)
  427. #else
  428. int nfc_i2c_dev_remove(struct i2c_client *client)
  429. #endif
  430. {
  431. struct nfc_dev *nfc_dev = NULL;
  432. pr_info("NxpDrv: %s: remove device\n", __func__);
  433. nfc_dev = i2c_get_clientdata(client);
  434. if (!nfc_dev) {
  435. pr_err("NxpDrv: %s: device doesn't exist anymore\n", __func__);
  436. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  437. return -ENODEV;
  438. #endif
  439. }
  440. if (nfc_dev->dev_ref_count > 0) {
  441. pr_err("NxpDrv: %s: device already in use\n", __func__);
  442. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  443. return -EBUSY;
  444. #endif
  445. }
  446. gpio_set_value(nfc_dev->configs.gpio.ven, 0);
  447. // HW dependent delay before LDO goes into LPM mode
  448. usleep_range(10000, 10100);
  449. if (nfc_dev->reg) {
  450. nfc_ldo_unvote(nfc_dev);
  451. regulator_put(nfc_dev->reg);
  452. }
  453. device_init_wakeup(&client->dev, false);
  454. free_irq(client->irq, nfc_dev);
  455. nfc_misc_unregister(nfc_dev, DEV_COUNT);
  456. mutex_destroy(&nfc_dev->dev_ref_mutex);
  457. mutex_destroy(&nfc_dev->read_mutex);
  458. mutex_destroy(&nfc_dev->write_mutex);
  459. gpio_free_all(nfc_dev);
  460. kfree(nfc_dev->read_kbuf);
  461. kfree(nfc_dev->write_kbuf);
  462. kfree(nfc_dev);
  463. #if (LINUX_VERSION_CODE < KERNEL_VERSION(6, 1, 0))
  464. return 0;
  465. #endif
  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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %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("NxpDrv: %s: Loading NXP NFC I2C driver\n", __func__);
  531. ret = i2c_add_driver(&nfc_i2c_dev_driver);
  532. if (ret != 0)
  533. pr_err("NxpDrv: %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("NxpDrv: %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");