i2c.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656
  1. /*
  2. * I2C Link Layer for ST21NFCA HCI based Driver
  3. * Copyright (C) 2014 STMicroelectronics SAS. All rights reserved.
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms and conditions of the GNU General Public License,
  7. * version 2, as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  18. #include <linux/crc-ccitt.h>
  19. #include <linux/module.h>
  20. #include <linux/i2c.h>
  21. #include <linux/gpio/consumer.h>
  22. #include <linux/of_irq.h>
  23. #include <linux/of_gpio.h>
  24. #include <linux/acpi.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/delay.h>
  27. #include <linux/nfc.h>
  28. #include <linux/firmware.h>
  29. #include <asm/unaligned.h>
  30. #include <net/nfc/hci.h>
  31. #include <net/nfc/llc.h>
  32. #include <net/nfc/nfc.h>
  33. #include "st21nfca.h"
  34. /*
  35. * Every frame starts with ST21NFCA_SOF_EOF and ends with ST21NFCA_SOF_EOF.
  36. * Because ST21NFCA_SOF_EOF is a possible data value, there is a mecanism
  37. * called byte stuffing has been introduced.
  38. *
  39. * if byte == ST21NFCA_SOF_EOF or ST21NFCA_ESCAPE_BYTE_STUFFING
  40. * - insert ST21NFCA_ESCAPE_BYTE_STUFFING (escape byte)
  41. * - xor byte with ST21NFCA_BYTE_STUFFING_MASK
  42. */
  43. #define ST21NFCA_SOF_EOF 0x7e
  44. #define ST21NFCA_BYTE_STUFFING_MASK 0x20
  45. #define ST21NFCA_ESCAPE_BYTE_STUFFING 0x7d
  46. /* SOF + 00 */
  47. #define ST21NFCA_FRAME_HEADROOM 2
  48. /* 2 bytes crc + EOF */
  49. #define ST21NFCA_FRAME_TAILROOM 3
  50. #define IS_START_OF_FRAME(buf) (buf[0] == ST21NFCA_SOF_EOF && \
  51. buf[1] == 0)
  52. #define ST21NFCA_HCI_DRIVER_NAME "st21nfca_hci"
  53. #define ST21NFCA_HCI_I2C_DRIVER_NAME "st21nfca_hci_i2c"
  54. #define ST21NFCA_GPIO_NAME_EN "enable"
  55. struct st21nfca_i2c_phy {
  56. struct i2c_client *i2c_dev;
  57. struct nfc_hci_dev *hdev;
  58. struct gpio_desc *gpiod_ena;
  59. struct st21nfca_se_status se_status;
  60. struct sk_buff *pending_skb;
  61. int current_read_len;
  62. /*
  63. * crc might have fail because i2c macro
  64. * is disable due to other interface activity
  65. */
  66. int crc_trials;
  67. int powered;
  68. int run_mode;
  69. /*
  70. * < 0 if hardware error occured (e.g. i2c err)
  71. * and prevents normal operation.
  72. */
  73. int hard_fault;
  74. struct mutex phy_lock;
  75. };
  76. static u8 len_seq[] = { 16, 24, 12, 29 };
  77. static u16 wait_tab[] = { 2, 3, 5, 15, 20, 40};
  78. #define I2C_DUMP_SKB(info, skb) \
  79. do { \
  80. pr_debug("%s:\n", info); \
  81. print_hex_dump(KERN_DEBUG, "i2c: ", DUMP_PREFIX_OFFSET, \
  82. 16, 1, (skb)->data, (skb)->len, 0); \
  83. } while (0)
  84. /*
  85. * In order to get the CLF in a known state we generate an internal reboot
  86. * using a proprietary command.
  87. * Once the reboot is completed, we expect to receive a ST21NFCA_SOF_EOF
  88. * fill buffer.
  89. */
  90. static int st21nfca_hci_platform_init(struct st21nfca_i2c_phy *phy)
  91. {
  92. u16 wait_reboot[] = { 50, 300, 1000 };
  93. char reboot_cmd[] = { 0x7E, 0x66, 0x48, 0xF6, 0x7E };
  94. u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE];
  95. int i, r = -1;
  96. for (i = 0; i < ARRAY_SIZE(wait_reboot) && r < 0; i++) {
  97. r = i2c_master_send(phy->i2c_dev, reboot_cmd,
  98. sizeof(reboot_cmd));
  99. if (r < 0)
  100. msleep(wait_reboot[i]);
  101. }
  102. if (r < 0)
  103. return r;
  104. /* CLF is spending about 20ms to do an internal reboot */
  105. msleep(20);
  106. r = -1;
  107. for (i = 0; i < ARRAY_SIZE(wait_reboot) && r < 0; i++) {
  108. r = i2c_master_recv(phy->i2c_dev, tmp,
  109. ST21NFCA_HCI_LLC_MAX_SIZE);
  110. if (r < 0)
  111. msleep(wait_reboot[i]);
  112. }
  113. if (r < 0)
  114. return r;
  115. for (i = 0; i < ST21NFCA_HCI_LLC_MAX_SIZE &&
  116. tmp[i] == ST21NFCA_SOF_EOF; i++)
  117. ;
  118. if (r != ST21NFCA_HCI_LLC_MAX_SIZE)
  119. return -ENODEV;
  120. usleep_range(1000, 1500);
  121. return 0;
  122. }
  123. static int st21nfca_hci_i2c_enable(void *phy_id)
  124. {
  125. struct st21nfca_i2c_phy *phy = phy_id;
  126. gpiod_set_value(phy->gpiod_ena, 1);
  127. phy->powered = 1;
  128. phy->run_mode = ST21NFCA_HCI_MODE;
  129. usleep_range(10000, 15000);
  130. return 0;
  131. }
  132. static void st21nfca_hci_i2c_disable(void *phy_id)
  133. {
  134. struct st21nfca_i2c_phy *phy = phy_id;
  135. gpiod_set_value(phy->gpiod_ena, 0);
  136. phy->powered = 0;
  137. }
  138. static void st21nfca_hci_add_len_crc(struct sk_buff *skb)
  139. {
  140. u16 crc;
  141. u8 tmp;
  142. *skb_push(skb, 1) = 0;
  143. crc = crc_ccitt(0xffff, skb->data, skb->len);
  144. crc = ~crc;
  145. tmp = crc & 0x00ff;
  146. *skb_put(skb, 1) = tmp;
  147. tmp = (crc >> 8) & 0x00ff;
  148. *skb_put(skb, 1) = tmp;
  149. }
  150. static void st21nfca_hci_remove_len_crc(struct sk_buff *skb)
  151. {
  152. skb_pull(skb, ST21NFCA_FRAME_HEADROOM);
  153. skb_trim(skb, skb->len - ST21NFCA_FRAME_TAILROOM);
  154. }
  155. /*
  156. * Writing a frame must not return the number of written bytes.
  157. * It must return either zero for success, or <0 for error.
  158. * In addition, it must not alter the skb
  159. */
  160. static int st21nfca_hci_i2c_write(void *phy_id, struct sk_buff *skb)
  161. {
  162. int r = -1, i, j;
  163. struct st21nfca_i2c_phy *phy = phy_id;
  164. struct i2c_client *client = phy->i2c_dev;
  165. u8 tmp[ST21NFCA_HCI_LLC_MAX_SIZE * 2];
  166. I2C_DUMP_SKB("st21nfca_hci_i2c_write", skb);
  167. if (phy->hard_fault != 0)
  168. return phy->hard_fault;
  169. /*
  170. * Compute CRC before byte stuffing computation on frame
  171. * Note st21nfca_hci_add_len_crc is doing a byte stuffing
  172. * on its own value
  173. */
  174. st21nfca_hci_add_len_crc(skb);
  175. /* add ST21NFCA_SOF_EOF on tail */
  176. *skb_put(skb, 1) = ST21NFCA_SOF_EOF;
  177. /* add ST21NFCA_SOF_EOF on head */
  178. *skb_push(skb, 1) = ST21NFCA_SOF_EOF;
  179. /*
  180. * Compute byte stuffing
  181. * if byte == ST21NFCA_SOF_EOF or ST21NFCA_ESCAPE_BYTE_STUFFING
  182. * insert ST21NFCA_ESCAPE_BYTE_STUFFING (escape byte)
  183. * xor byte with ST21NFCA_BYTE_STUFFING_MASK
  184. */
  185. tmp[0] = skb->data[0];
  186. for (i = 1, j = 1; i < skb->len - 1; i++, j++) {
  187. if (skb->data[i] == ST21NFCA_SOF_EOF
  188. || skb->data[i] == ST21NFCA_ESCAPE_BYTE_STUFFING) {
  189. tmp[j] = ST21NFCA_ESCAPE_BYTE_STUFFING;
  190. j++;
  191. tmp[j] = skb->data[i] ^ ST21NFCA_BYTE_STUFFING_MASK;
  192. } else {
  193. tmp[j] = skb->data[i];
  194. }
  195. }
  196. tmp[j] = skb->data[i];
  197. j++;
  198. /*
  199. * Manage sleep mode
  200. * Try 3 times to send data with delay between each
  201. */
  202. mutex_lock(&phy->phy_lock);
  203. for (i = 0; i < ARRAY_SIZE(wait_tab) && r < 0; i++) {
  204. r = i2c_master_send(client, tmp, j);
  205. if (r < 0)
  206. msleep(wait_tab[i]);
  207. }
  208. mutex_unlock(&phy->phy_lock);
  209. if (r >= 0) {
  210. if (r != j)
  211. r = -EREMOTEIO;
  212. else
  213. r = 0;
  214. }
  215. st21nfca_hci_remove_len_crc(skb);
  216. return r;
  217. }
  218. static int get_frame_size(u8 *buf, int buflen)
  219. {
  220. int len = 0;
  221. if (buf[len + 1] == ST21NFCA_SOF_EOF)
  222. return 0;
  223. for (len = 1; len < buflen && buf[len] != ST21NFCA_SOF_EOF; len++)
  224. ;
  225. return len;
  226. }
  227. static int check_crc(u8 *buf, int buflen)
  228. {
  229. u16 crc;
  230. crc = crc_ccitt(0xffff, buf, buflen - 2);
  231. crc = ~crc;
  232. if (buf[buflen - 2] != (crc & 0xff) || buf[buflen - 1] != (crc >> 8)) {
  233. pr_err(ST21NFCA_HCI_DRIVER_NAME
  234. ": CRC error 0x%x != 0x%x 0x%x\n", crc, buf[buflen - 1],
  235. buf[buflen - 2]);
  236. pr_info(DRIVER_DESC ": %s : BAD CRC\n", __func__);
  237. print_hex_dump(KERN_DEBUG, "crc: ", DUMP_PREFIX_NONE,
  238. 16, 2, buf, buflen, false);
  239. return -EPERM;
  240. }
  241. return 0;
  242. }
  243. /*
  244. * Prepare received data for upper layer.
  245. * Received data include byte stuffing, crc and sof/eof
  246. * which is not usable by hci part.
  247. * returns:
  248. * frame size without sof/eof, header and byte stuffing
  249. * -EBADMSG : frame was incorrect and discarded
  250. */
  251. static int st21nfca_hci_i2c_repack(struct sk_buff *skb)
  252. {
  253. int i, j, r, size;
  254. if (skb->len < 1 || (skb->len > 1 && skb->data[1] != 0))
  255. return -EBADMSG;
  256. size = get_frame_size(skb->data, skb->len);
  257. if (size > 0) {
  258. skb_trim(skb, size);
  259. /* remove ST21NFCA byte stuffing for upper layer */
  260. for (i = 1, j = 0; i < skb->len; i++) {
  261. if (skb->data[i + j] ==
  262. (u8) ST21NFCA_ESCAPE_BYTE_STUFFING) {
  263. skb->data[i] = skb->data[i + j + 1]
  264. | ST21NFCA_BYTE_STUFFING_MASK;
  265. i++;
  266. j++;
  267. }
  268. skb->data[i] = skb->data[i + j];
  269. }
  270. /* remove byte stuffing useless byte */
  271. skb_trim(skb, i - j);
  272. /* remove ST21NFCA_SOF_EOF from head */
  273. skb_pull(skb, 1);
  274. r = check_crc(skb->data, skb->len);
  275. if (r != 0) {
  276. i = 0;
  277. return -EBADMSG;
  278. }
  279. /* remove headbyte */
  280. skb_pull(skb, 1);
  281. /* remove crc. Byte Stuffing is already removed here */
  282. skb_trim(skb, skb->len - 2);
  283. return skb->len;
  284. }
  285. return 0;
  286. }
  287. /*
  288. * Reads an shdlc frame and returns it in a newly allocated sk_buff. Guarantees
  289. * that i2c bus will be flushed and that next read will start on a new frame.
  290. * returned skb contains only LLC header and payload.
  291. * returns:
  292. * frame size : if received frame is complete (find ST21NFCA_SOF_EOF at
  293. * end of read)
  294. * -EAGAIN : if received frame is incomplete (not find ST21NFCA_SOF_EOF
  295. * at end of read)
  296. * -EREMOTEIO : i2c read error (fatal)
  297. * -EBADMSG : frame was incorrect and discarded
  298. * (value returned from st21nfca_hci_i2c_repack)
  299. * -EIO : if no ST21NFCA_SOF_EOF is found after reaching
  300. * the read length end sequence
  301. */
  302. static int st21nfca_hci_i2c_read(struct st21nfca_i2c_phy *phy,
  303. struct sk_buff *skb)
  304. {
  305. int r, i;
  306. u8 len;
  307. u8 buf[ST21NFCA_HCI_LLC_MAX_PAYLOAD];
  308. struct i2c_client *client = phy->i2c_dev;
  309. if (phy->current_read_len < ARRAY_SIZE(len_seq)) {
  310. len = len_seq[phy->current_read_len];
  311. /*
  312. * Add retry mecanism
  313. * Operation on I2C interface may fail in case of operation on
  314. * RF or SWP interface
  315. */
  316. r = 0;
  317. mutex_lock(&phy->phy_lock);
  318. for (i = 0; i < ARRAY_SIZE(wait_tab) && r <= 0; i++) {
  319. r = i2c_master_recv(client, buf, len);
  320. if (r < 0)
  321. msleep(wait_tab[i]);
  322. }
  323. mutex_unlock(&phy->phy_lock);
  324. if (r != len) {
  325. phy->current_read_len = 0;
  326. return -EREMOTEIO;
  327. }
  328. /*
  329. * The first read sequence does not start with SOF.
  330. * Data is corrupeted so we drop it.
  331. */
  332. if (!phy->current_read_len && !IS_START_OF_FRAME(buf)) {
  333. skb_trim(skb, 0);
  334. phy->current_read_len = 0;
  335. return -EIO;
  336. } else if (phy->current_read_len && IS_START_OF_FRAME(buf)) {
  337. /*
  338. * Previous frame transmission was interrupted and
  339. * the frame got repeated.
  340. * Received frame start with ST21NFCA_SOF_EOF + 00.
  341. */
  342. skb_trim(skb, 0);
  343. phy->current_read_len = 0;
  344. }
  345. memcpy(skb_put(skb, len), buf, len);
  346. if (skb->data[skb->len - 1] == ST21NFCA_SOF_EOF) {
  347. phy->current_read_len = 0;
  348. return st21nfca_hci_i2c_repack(skb);
  349. }
  350. phy->current_read_len++;
  351. return -EAGAIN;
  352. }
  353. return -EIO;
  354. }
  355. /*
  356. * Reads an shdlc frame from the chip. This is not as straightforward as it
  357. * seems. The frame format is data-crc, and corruption can occur anywhere
  358. * while transiting on i2c bus, such that we could read an invalid data.
  359. * The tricky case is when we read a corrupted data or crc. We must detect
  360. * this here in order to determine that data can be transmitted to the hci
  361. * core. This is the reason why we check the crc here.
  362. * The CLF will repeat a frame until we send a RR on that frame.
  363. *
  364. * On ST21NFCA, IRQ goes in idle when read starts. As no size information are
  365. * available in the incoming data, other IRQ might come. Every IRQ will trigger
  366. * a read sequence with different length and will fill the current frame.
  367. * The reception is complete once we reach a ST21NFCA_SOF_EOF.
  368. */
  369. static irqreturn_t st21nfca_hci_irq_thread_fn(int irq, void *phy_id)
  370. {
  371. struct st21nfca_i2c_phy *phy = phy_id;
  372. struct i2c_client *client;
  373. int r;
  374. if (!phy || irq != phy->i2c_dev->irq) {
  375. WARN_ON_ONCE(1);
  376. return IRQ_NONE;
  377. }
  378. client = phy->i2c_dev;
  379. dev_dbg(&client->dev, "IRQ\n");
  380. if (phy->hard_fault != 0)
  381. return IRQ_HANDLED;
  382. r = st21nfca_hci_i2c_read(phy, phy->pending_skb);
  383. if (r == -EREMOTEIO) {
  384. phy->hard_fault = r;
  385. nfc_hci_recv_frame(phy->hdev, NULL);
  386. return IRQ_HANDLED;
  387. } else if (r == -EAGAIN || r == -EIO) {
  388. return IRQ_HANDLED;
  389. } else if (r == -EBADMSG && phy->crc_trials < ARRAY_SIZE(wait_tab)) {
  390. /*
  391. * With ST21NFCA, only one interface (I2C, RF or SWP)
  392. * may be active at a time.
  393. * Having incorrect crc is usually due to i2c macrocell
  394. * deactivation in the middle of a transmission.
  395. * It may generate corrupted data on i2c.
  396. * We give sometime to get i2c back.
  397. * The complete frame will be repeated.
  398. */
  399. msleep(wait_tab[phy->crc_trials]);
  400. phy->crc_trials++;
  401. phy->current_read_len = 0;
  402. kfree_skb(phy->pending_skb);
  403. } else if (r > 0) {
  404. /*
  405. * We succeeded to read data from the CLF and
  406. * data is valid.
  407. * Reset counter.
  408. */
  409. nfc_hci_recv_frame(phy->hdev, phy->pending_skb);
  410. phy->crc_trials = 0;
  411. } else {
  412. kfree_skb(phy->pending_skb);
  413. }
  414. phy->pending_skb = alloc_skb(ST21NFCA_HCI_LLC_MAX_SIZE * 2, GFP_KERNEL);
  415. if (phy->pending_skb == NULL) {
  416. phy->hard_fault = -ENOMEM;
  417. nfc_hci_recv_frame(phy->hdev, NULL);
  418. }
  419. return IRQ_HANDLED;
  420. }
  421. static struct nfc_phy_ops i2c_phy_ops = {
  422. .write = st21nfca_hci_i2c_write,
  423. .enable = st21nfca_hci_i2c_enable,
  424. .disable = st21nfca_hci_i2c_disable,
  425. };
  426. static int st21nfca_hci_i2c_acpi_request_resources(struct i2c_client *client)
  427. {
  428. struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
  429. struct device *dev = &client->dev;
  430. /* Get EN GPIO from ACPI */
  431. phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 1,
  432. GPIOD_OUT_LOW);
  433. if (IS_ERR(phy->gpiod_ena)) {
  434. nfc_err(dev, "Unable to get ENABLE GPIO\n");
  435. return PTR_ERR(phy->gpiod_ena);
  436. }
  437. return 0;
  438. }
  439. static int st21nfca_hci_i2c_of_request_resources(struct i2c_client *client)
  440. {
  441. struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
  442. struct device *dev = &client->dev;
  443. /* Get GPIO from device tree */
  444. phy->gpiod_ena = devm_gpiod_get_index(dev, ST21NFCA_GPIO_NAME_EN, 0,
  445. GPIOD_OUT_HIGH);
  446. if (IS_ERR(phy->gpiod_ena)) {
  447. nfc_err(dev, "Failed to request enable pin\n");
  448. return PTR_ERR(phy->gpiod_ena);
  449. }
  450. return 0;
  451. }
  452. static int st21nfca_hci_i2c_probe(struct i2c_client *client,
  453. const struct i2c_device_id *id)
  454. {
  455. struct st21nfca_i2c_phy *phy;
  456. int r;
  457. dev_dbg(&client->dev, "%s\n", __func__);
  458. dev_dbg(&client->dev, "IRQ: %d\n", client->irq);
  459. if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
  460. nfc_err(&client->dev, "Need I2C_FUNC_I2C\n");
  461. return -ENODEV;
  462. }
  463. phy = devm_kzalloc(&client->dev, sizeof(struct st21nfca_i2c_phy),
  464. GFP_KERNEL);
  465. if (!phy)
  466. return -ENOMEM;
  467. phy->i2c_dev = client;
  468. phy->pending_skb = alloc_skb(ST21NFCA_HCI_LLC_MAX_SIZE * 2, GFP_KERNEL);
  469. if (phy->pending_skb == NULL)
  470. return -ENOMEM;
  471. phy->current_read_len = 0;
  472. phy->crc_trials = 0;
  473. mutex_init(&phy->phy_lock);
  474. i2c_set_clientdata(client, phy);
  475. if (client->dev.of_node) {
  476. r = st21nfca_hci_i2c_of_request_resources(client);
  477. if (r) {
  478. nfc_err(&client->dev, "No platform data\n");
  479. return r;
  480. }
  481. } else if (ACPI_HANDLE(&client->dev)) {
  482. r = st21nfca_hci_i2c_acpi_request_resources(client);
  483. if (r) {
  484. nfc_err(&client->dev, "Cannot get ACPI data\n");
  485. return r;
  486. }
  487. } else {
  488. nfc_err(&client->dev, "st21nfca platform resources not available\n");
  489. return -ENODEV;
  490. }
  491. phy->se_status.is_ese_present =
  492. device_property_read_bool(&client->dev, "ese-present");
  493. phy->se_status.is_uicc_present =
  494. device_property_read_bool(&client->dev, "uicc-present");
  495. r = st21nfca_hci_platform_init(phy);
  496. if (r < 0) {
  497. nfc_err(&client->dev, "Unable to reboot st21nfca\n");
  498. return r;
  499. }
  500. r = devm_request_threaded_irq(&client->dev, client->irq, NULL,
  501. st21nfca_hci_irq_thread_fn,
  502. IRQF_ONESHOT,
  503. ST21NFCA_HCI_DRIVER_NAME, phy);
  504. if (r < 0) {
  505. nfc_err(&client->dev, "Unable to register IRQ handler\n");
  506. return r;
  507. }
  508. return st21nfca_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME,
  509. ST21NFCA_FRAME_HEADROOM,
  510. ST21NFCA_FRAME_TAILROOM,
  511. ST21NFCA_HCI_LLC_MAX_PAYLOAD,
  512. &phy->hdev,
  513. &phy->se_status);
  514. }
  515. static int st21nfca_hci_i2c_remove(struct i2c_client *client)
  516. {
  517. struct st21nfca_i2c_phy *phy = i2c_get_clientdata(client);
  518. dev_dbg(&client->dev, "%s\n", __func__);
  519. st21nfca_hci_remove(phy->hdev);
  520. if (phy->powered)
  521. st21nfca_hci_i2c_disable(phy);
  522. return 0;
  523. }
  524. static struct i2c_device_id st21nfca_hci_i2c_id_table[] = {
  525. {ST21NFCA_HCI_DRIVER_NAME, 0},
  526. {}
  527. };
  528. MODULE_DEVICE_TABLE(i2c, st21nfca_hci_i2c_id_table);
  529. static const struct acpi_device_id st21nfca_hci_i2c_acpi_match[] = {
  530. {"SMO2100", 0},
  531. {}
  532. };
  533. MODULE_DEVICE_TABLE(acpi, st21nfca_hci_i2c_acpi_match);
  534. static const struct of_device_id of_st21nfca_i2c_match[] = {
  535. { .compatible = "st,st21nfca-i2c", },
  536. { .compatible = "st,st21nfca_i2c", },
  537. {}
  538. };
  539. MODULE_DEVICE_TABLE(of, of_st21nfca_i2c_match);
  540. static struct i2c_driver st21nfca_hci_i2c_driver = {
  541. .driver = {
  542. .name = ST21NFCA_HCI_I2C_DRIVER_NAME,
  543. .of_match_table = of_match_ptr(of_st21nfca_i2c_match),
  544. .acpi_match_table = ACPI_PTR(st21nfca_hci_i2c_acpi_match),
  545. },
  546. .probe = st21nfca_hci_i2c_probe,
  547. .id_table = st21nfca_hci_i2c_id_table,
  548. .remove = st21nfca_hci_i2c_remove,
  549. };
  550. module_i2c_driver(st21nfca_hci_i2c_driver);
  551. MODULE_LICENSE("GPL");
  552. MODULE_DESCRIPTION(DRIVER_DESC);