2 * NFC Digital Protocol stack
3 * Copyright (c) 2013, Intel Corporation.
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.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 #define pr_fmt(fmt) "digital: %s: " fmt, __func__
18 #include <linux/module.h>
22 #define DIGITAL_PROTO_NFCA_RF_TECH \
23 (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | \
24 NFC_PROTO_NFC_DEP_MASK | NFC_PROTO_ISO14443_MASK)
26 #define DIGITAL_PROTO_NFCB_RF_TECH NFC_PROTO_ISO14443_B_MASK
28 #define DIGITAL_PROTO_NFCF_RF_TECH \
29 (NFC_PROTO_FELICA_MASK | NFC_PROTO_NFC_DEP_MASK)
31 #define DIGITAL_PROTO_ISO15693_RF_TECH NFC_PROTO_ISO15693_MASK
33 /* Delay between each poll frame (ms) */
34 #define DIGITAL_POLL_INTERVAL 10
37 struct list_head queue;
45 struct digital_tg_mdaa_params *mdaa_params;
47 nfc_digital_cmd_complete_t cmd_cb;
51 struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
56 skb = alloc_skb(len + ddev->tx_headroom + ddev->tx_tailroom,
59 skb_reserve(skb, ddev->tx_headroom);
64 void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
65 u8 bitwise_inv, u8 msb_first)
69 crc = crc_func(init, skb->data, skb->len);
77 skb_put_u8(skb, crc & 0xFF);
78 skb_put_u8(skb, (crc >> 8) & 0xFF);
81 int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
82 u16 crc_init, u8 bitwise_inv, u8 msb_first)
90 crc = crc_func(crc_init, skb->data, skb->len - 2);
98 rc = (skb->data[skb->len - 2] - (crc & 0xFF)) +
99 (skb->data[skb->len - 1] - ((crc >> 8) & 0xFF));
104 skb_trim(skb, skb->len - 2);
109 static inline void digital_switch_rf(struct nfc_digital_dev *ddev, bool on)
111 ddev->ops->switch_rf(ddev, on);
114 static inline void digital_abort_cmd(struct nfc_digital_dev *ddev)
116 ddev->ops->abort_cmd(ddev);
119 static void digital_wq_cmd_complete(struct work_struct *work)
121 struct digital_cmd *cmd;
122 struct nfc_digital_dev *ddev = container_of(work,
123 struct nfc_digital_dev,
126 mutex_lock(&ddev->cmd_lock);
128 cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd,
131 mutex_unlock(&ddev->cmd_lock);
135 list_del(&cmd->queue);
137 mutex_unlock(&ddev->cmd_lock);
139 if (!IS_ERR(cmd->resp))
140 print_hex_dump_debug("DIGITAL RX: ", DUMP_PREFIX_NONE, 16, 1,
141 cmd->resp->data, cmd->resp->len, false);
143 cmd->cmd_cb(ddev, cmd->cb_context, cmd->resp);
145 kfree(cmd->mdaa_params);
148 schedule_work(&ddev->cmd_work);
151 static void digital_send_cmd_complete(struct nfc_digital_dev *ddev,
152 void *arg, struct sk_buff *resp)
154 struct digital_cmd *cmd = arg;
158 schedule_work(&ddev->cmd_complete_work);
161 static void digital_wq_cmd(struct work_struct *work)
164 struct digital_cmd *cmd;
165 struct digital_tg_mdaa_params *params;
166 struct nfc_digital_dev *ddev = container_of(work,
167 struct nfc_digital_dev,
170 mutex_lock(&ddev->cmd_lock);
172 cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd,
174 if (!cmd || cmd->pending) {
175 mutex_unlock(&ddev->cmd_lock);
181 mutex_unlock(&ddev->cmd_lock);
184 print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE, 16, 1,
185 cmd->req->data, cmd->req->len, false);
188 case DIGITAL_CMD_IN_SEND:
189 rc = ddev->ops->in_send_cmd(ddev, cmd->req, cmd->timeout,
190 digital_send_cmd_complete, cmd);
193 case DIGITAL_CMD_TG_SEND:
194 rc = ddev->ops->tg_send_cmd(ddev, cmd->req, cmd->timeout,
195 digital_send_cmd_complete, cmd);
198 case DIGITAL_CMD_TG_LISTEN:
199 rc = ddev->ops->tg_listen(ddev, cmd->timeout,
200 digital_send_cmd_complete, cmd);
203 case DIGITAL_CMD_TG_LISTEN_MDAA:
204 params = cmd->mdaa_params;
206 rc = ddev->ops->tg_listen_mdaa(ddev, params, cmd->timeout,
207 digital_send_cmd_complete, cmd);
210 case DIGITAL_CMD_TG_LISTEN_MD:
211 rc = ddev->ops->tg_listen_md(ddev, cmd->timeout,
212 digital_send_cmd_complete, cmd);
216 pr_err("Unknown cmd type %d\n", cmd->type);
223 pr_err("in_send_command returned err %d\n", rc);
225 mutex_lock(&ddev->cmd_lock);
226 list_del(&cmd->queue);
227 mutex_unlock(&ddev->cmd_lock);
230 kfree(cmd->mdaa_params);
233 schedule_work(&ddev->cmd_work);
236 int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
237 struct sk_buff *skb, struct digital_tg_mdaa_params *params,
238 u16 timeout, nfc_digital_cmd_complete_t cmd_cb,
241 struct digital_cmd *cmd;
243 cmd = kzalloc(sizeof(*cmd), GFP_KERNEL);
247 cmd->type = cmd_type;
248 cmd->timeout = timeout;
250 cmd->mdaa_params = params;
251 cmd->cmd_cb = cmd_cb;
252 cmd->cb_context = cb_context;
253 INIT_LIST_HEAD(&cmd->queue);
255 mutex_lock(&ddev->cmd_lock);
256 list_add_tail(&cmd->queue, &ddev->cmd_queue);
257 mutex_unlock(&ddev->cmd_lock);
259 schedule_work(&ddev->cmd_work);
264 int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
268 rc = ddev->ops->in_configure_hw(ddev, type, param);
270 pr_err("in_configure_hw failed: %d\n", rc);
275 int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
279 rc = ddev->ops->tg_configure_hw(ddev, type, param);
281 pr_err("tg_configure_hw failed: %d\n", rc);
286 static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
288 struct digital_tg_mdaa_params *params;
291 params = kzalloc(sizeof(*params), GFP_KERNEL);
295 params->sens_res = DIGITAL_SENS_RES_NFC_DEP;
296 get_random_bytes(params->nfcid1, sizeof(params->nfcid1));
297 params->sel_res = DIGITAL_SEL_RES_NFC_DEP;
299 params->nfcid2[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1;
300 params->nfcid2[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2;
301 get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2);
302 params->sc = DIGITAL_SENSF_FELICA_SC;
304 rc = digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
305 500, digital_tg_recv_atr_req, NULL);
312 static int digital_tg_listen_md(struct nfc_digital_dev *ddev, u8 rf_tech)
314 return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MD, NULL, NULL, 500,
315 digital_tg_recv_md_req, NULL);
318 int digital_target_found(struct nfc_digital_dev *ddev,
319 struct nfc_target *target, u8 protocol)
325 int (*check_crc)(struct sk_buff *skb);
326 void (*add_crc)(struct sk_buff *skb);
328 rf_tech = ddev->poll_techs[ddev->poll_tech_index].rf_tech;
331 case NFC_PROTO_JEWEL:
332 framing = NFC_DIGITAL_FRAMING_NFCA_T1T;
333 check_crc = digital_skb_check_crc_b;
334 add_crc = digital_skb_add_crc_b;
337 case NFC_PROTO_MIFARE:
338 framing = NFC_DIGITAL_FRAMING_NFCA_T2T;
339 check_crc = digital_skb_check_crc_a;
340 add_crc = digital_skb_add_crc_a;
343 case NFC_PROTO_FELICA:
344 framing = NFC_DIGITAL_FRAMING_NFCF_T3T;
345 check_crc = digital_skb_check_crc_f;
346 add_crc = digital_skb_add_crc_f;
349 case NFC_PROTO_NFC_DEP:
350 if (rf_tech == NFC_DIGITAL_RF_TECH_106A) {
351 framing = NFC_DIGITAL_FRAMING_NFCA_NFC_DEP;
352 check_crc = digital_skb_check_crc_a;
353 add_crc = digital_skb_add_crc_a;
355 framing = NFC_DIGITAL_FRAMING_NFCF_NFC_DEP;
356 check_crc = digital_skb_check_crc_f;
357 add_crc = digital_skb_add_crc_f;
361 case NFC_PROTO_ISO15693:
362 framing = NFC_DIGITAL_FRAMING_ISO15693_T5T;
363 check_crc = digital_skb_check_crc_b;
364 add_crc = digital_skb_add_crc_b;
367 case NFC_PROTO_ISO14443:
368 framing = NFC_DIGITAL_FRAMING_NFCA_T4T;
369 check_crc = digital_skb_check_crc_a;
370 add_crc = digital_skb_add_crc_a;
373 case NFC_PROTO_ISO14443_B:
374 framing = NFC_DIGITAL_FRAMING_NFCB_T4T;
375 check_crc = digital_skb_check_crc_b;
376 add_crc = digital_skb_add_crc_b;
380 pr_err("Invalid protocol %d\n", protocol);
384 pr_debug("rf_tech=%d, protocol=%d\n", rf_tech, protocol);
386 ddev->curr_rf_tech = rf_tech;
388 if (DIGITAL_DRV_CAPS_IN_CRC(ddev)) {
389 ddev->skb_add_crc = digital_skb_add_crc_none;
390 ddev->skb_check_crc = digital_skb_check_crc_none;
392 ddev->skb_add_crc = add_crc;
393 ddev->skb_check_crc = check_crc;
396 rc = digital_in_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, framing);
400 target->supported_protocols = (1 << protocol);
402 poll_tech_count = ddev->poll_tech_count;
403 ddev->poll_tech_count = 0;
405 rc = nfc_targets_found(ddev->nfc_dev, target, 1);
407 ddev->poll_tech_count = poll_tech_count;
414 void digital_poll_next_tech(struct nfc_digital_dev *ddev)
418 digital_switch_rf(ddev, 0);
420 mutex_lock(&ddev->poll_lock);
422 if (!ddev->poll_tech_count) {
423 mutex_unlock(&ddev->poll_lock);
427 get_random_bytes(&rand_mod, sizeof(rand_mod));
428 ddev->poll_tech_index = rand_mod % ddev->poll_tech_count;
430 mutex_unlock(&ddev->poll_lock);
432 schedule_delayed_work(&ddev->poll_work,
433 msecs_to_jiffies(DIGITAL_POLL_INTERVAL));
436 static void digital_wq_poll(struct work_struct *work)
439 struct digital_poll_tech *poll_tech;
440 struct nfc_digital_dev *ddev = container_of(work,
441 struct nfc_digital_dev,
443 mutex_lock(&ddev->poll_lock);
445 if (!ddev->poll_tech_count) {
446 mutex_unlock(&ddev->poll_lock);
450 poll_tech = &ddev->poll_techs[ddev->poll_tech_index];
452 mutex_unlock(&ddev->poll_lock);
454 rc = poll_tech->poll_func(ddev, poll_tech->rf_tech);
456 digital_poll_next_tech(ddev);
459 static void digital_add_poll_tech(struct nfc_digital_dev *ddev, u8 rf_tech,
460 digital_poll_t poll_func)
462 struct digital_poll_tech *poll_tech;
464 if (ddev->poll_tech_count >= NFC_DIGITAL_POLL_MODE_COUNT_MAX)
467 poll_tech = &ddev->poll_techs[ddev->poll_tech_count++];
469 poll_tech->rf_tech = rf_tech;
470 poll_tech->poll_func = poll_func;
474 * start_poll operation
476 * For every supported protocol, the corresponding polling function is added
477 * to the table of polling technologies (ddev->poll_techs[]) using
478 * digital_add_poll_tech().
479 * When a polling function fails (by timeout or protocol error) the next one is
480 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
482 static int digital_start_poll(struct nfc_dev *nfc_dev, __u32 im_protocols,
485 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
486 u32 matching_im_protocols, matching_tm_protocols;
488 pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols,
489 tm_protocols, ddev->protocols);
491 matching_im_protocols = ddev->protocols & im_protocols;
492 matching_tm_protocols = ddev->protocols & tm_protocols;
494 if (!matching_im_protocols && !matching_tm_protocols) {
495 pr_err("Unknown protocol\n");
499 if (ddev->poll_tech_count) {
500 pr_err("Already polling\n");
504 if (ddev->curr_protocol) {
505 pr_err("A target is already active\n");
509 ddev->poll_tech_count = 0;
510 ddev->poll_tech_index = 0;
512 if (matching_im_protocols & DIGITAL_PROTO_NFCA_RF_TECH)
513 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A,
514 digital_in_send_sens_req);
516 if (matching_im_protocols & DIGITAL_PROTO_NFCB_RF_TECH)
517 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106B,
518 digital_in_send_sensb_req);
520 if (matching_im_protocols & DIGITAL_PROTO_NFCF_RF_TECH) {
521 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F,
522 digital_in_send_sensf_req);
524 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F,
525 digital_in_send_sensf_req);
528 if (matching_im_protocols & DIGITAL_PROTO_ISO15693_RF_TECH)
529 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_ISO15693,
530 digital_in_send_iso15693_inv_req);
532 if (matching_tm_protocols & NFC_PROTO_NFC_DEP_MASK) {
533 if (ddev->ops->tg_listen_mdaa) {
534 digital_add_poll_tech(ddev, 0,
535 digital_tg_listen_mdaa);
536 } else if (ddev->ops->tg_listen_md) {
537 digital_add_poll_tech(ddev, 0,
538 digital_tg_listen_md);
540 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A,
541 digital_tg_listen_nfca);
543 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F,
544 digital_tg_listen_nfcf);
546 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F,
547 digital_tg_listen_nfcf);
551 if (!ddev->poll_tech_count) {
552 pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n",
553 matching_im_protocols, matching_tm_protocols);
557 schedule_delayed_work(&ddev->poll_work, 0);
562 static void digital_stop_poll(struct nfc_dev *nfc_dev)
564 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
566 mutex_lock(&ddev->poll_lock);
568 if (!ddev->poll_tech_count) {
569 pr_err("Polling operation was not running\n");
570 mutex_unlock(&ddev->poll_lock);
574 ddev->poll_tech_count = 0;
576 mutex_unlock(&ddev->poll_lock);
578 cancel_delayed_work_sync(&ddev->poll_work);
580 digital_abort_cmd(ddev);
583 static int digital_dev_up(struct nfc_dev *nfc_dev)
585 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
587 digital_switch_rf(ddev, 1);
592 static int digital_dev_down(struct nfc_dev *nfc_dev)
594 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
596 digital_switch_rf(ddev, 0);
601 static int digital_dep_link_up(struct nfc_dev *nfc_dev,
602 struct nfc_target *target,
603 __u8 comm_mode, __u8 *gb, size_t gb_len)
605 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
608 rc = digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len);
611 ddev->curr_protocol = NFC_PROTO_NFC_DEP;
616 static int digital_dep_link_down(struct nfc_dev *nfc_dev)
618 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
620 digital_abort_cmd(ddev);
622 ddev->curr_protocol = 0;
627 static int digital_activate_target(struct nfc_dev *nfc_dev,
628 struct nfc_target *target, __u32 protocol)
630 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
632 if (ddev->poll_tech_count) {
633 pr_err("Can't activate a target while polling\n");
637 if (ddev->curr_protocol) {
638 pr_err("A target is already active\n");
642 ddev->curr_protocol = protocol;
647 static void digital_deactivate_target(struct nfc_dev *nfc_dev,
648 struct nfc_target *target,
651 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
653 if (!ddev->curr_protocol) {
654 pr_err("No active target\n");
658 digital_abort_cmd(ddev);
659 ddev->curr_protocol = 0;
662 static int digital_tg_send(struct nfc_dev *dev, struct sk_buff *skb)
664 struct nfc_digital_dev *ddev = nfc_get_drvdata(dev);
666 return digital_tg_send_dep_res(ddev, skb);
669 static void digital_in_send_complete(struct nfc_digital_dev *ddev, void *arg,
670 struct sk_buff *resp)
672 struct digital_data_exch *data_exch = arg;
681 if (ddev->curr_protocol == NFC_PROTO_MIFARE) {
682 rc = digital_in_recv_mifare_res(resp);
683 /* crc check is done in digital_in_recv_mifare_res() */
687 if ((ddev->curr_protocol == NFC_PROTO_ISO14443) ||
688 (ddev->curr_protocol == NFC_PROTO_ISO14443_B)) {
689 rc = digital_in_iso_dep_pull_sod(ddev, resp);
694 rc = ddev->skb_check_crc(resp);
702 data_exch->cb(data_exch->cb_context, resp, rc);
707 static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target,
708 struct sk_buff *skb, data_exchange_cb_t cb,
711 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
712 struct digital_data_exch *data_exch;
715 data_exch = kzalloc(sizeof(*data_exch), GFP_KERNEL);
720 data_exch->cb_context = cb_context;
722 if (ddev->curr_protocol == NFC_PROTO_NFC_DEP) {
723 rc = digital_in_send_dep_req(ddev, target, skb, data_exch);
727 if ((ddev->curr_protocol == NFC_PROTO_ISO14443) ||
728 (ddev->curr_protocol == NFC_PROTO_ISO14443_B)) {
729 rc = digital_in_iso_dep_push_sod(ddev, skb);
734 ddev->skb_add_crc(skb);
736 rc = digital_in_send_cmd(ddev, skb, 500, digital_in_send_complete,
746 static struct nfc_ops digital_nfc_ops = {
747 .dev_up = digital_dev_up,
748 .dev_down = digital_dev_down,
749 .start_poll = digital_start_poll,
750 .stop_poll = digital_stop_poll,
751 .dep_link_up = digital_dep_link_up,
752 .dep_link_down = digital_dep_link_down,
753 .activate_target = digital_activate_target,
754 .deactivate_target = digital_deactivate_target,
755 .tm_send = digital_tg_send,
756 .im_transceive = digital_in_send,
759 struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
760 __u32 supported_protocols,
761 __u32 driver_capabilities,
762 int tx_headroom, int tx_tailroom)
764 struct nfc_digital_dev *ddev;
766 if (!ops->in_configure_hw || !ops->in_send_cmd || !ops->tg_listen ||
767 !ops->tg_configure_hw || !ops->tg_send_cmd || !ops->abort_cmd ||
768 !ops->switch_rf || (ops->tg_listen_md && !ops->tg_get_rf_tech))
771 ddev = kzalloc(sizeof(*ddev), GFP_KERNEL);
775 ddev->driver_capabilities = driver_capabilities;
778 mutex_init(&ddev->cmd_lock);
779 INIT_LIST_HEAD(&ddev->cmd_queue);
781 INIT_WORK(&ddev->cmd_work, digital_wq_cmd);
782 INIT_WORK(&ddev->cmd_complete_work, digital_wq_cmd_complete);
784 mutex_init(&ddev->poll_lock);
785 INIT_DELAYED_WORK(&ddev->poll_work, digital_wq_poll);
787 if (supported_protocols & NFC_PROTO_JEWEL_MASK)
788 ddev->protocols |= NFC_PROTO_JEWEL_MASK;
789 if (supported_protocols & NFC_PROTO_MIFARE_MASK)
790 ddev->protocols |= NFC_PROTO_MIFARE_MASK;
791 if (supported_protocols & NFC_PROTO_FELICA_MASK)
792 ddev->protocols |= NFC_PROTO_FELICA_MASK;
793 if (supported_protocols & NFC_PROTO_NFC_DEP_MASK)
794 ddev->protocols |= NFC_PROTO_NFC_DEP_MASK;
795 if (supported_protocols & NFC_PROTO_ISO15693_MASK)
796 ddev->protocols |= NFC_PROTO_ISO15693_MASK;
797 if (supported_protocols & NFC_PROTO_ISO14443_MASK)
798 ddev->protocols |= NFC_PROTO_ISO14443_MASK;
799 if (supported_protocols & NFC_PROTO_ISO14443_B_MASK)
800 ddev->protocols |= NFC_PROTO_ISO14443_B_MASK;
802 ddev->tx_headroom = tx_headroom + DIGITAL_MAX_HEADER_LEN;
803 ddev->tx_tailroom = tx_tailroom + DIGITAL_CRC_LEN;
805 ddev->nfc_dev = nfc_allocate_device(&digital_nfc_ops, ddev->protocols,
808 if (!ddev->nfc_dev) {
809 pr_err("nfc_allocate_device failed\n");
813 nfc_set_drvdata(ddev->nfc_dev, ddev);
822 EXPORT_SYMBOL(nfc_digital_allocate_device);
824 void nfc_digital_free_device(struct nfc_digital_dev *ddev)
826 nfc_free_device(ddev->nfc_dev);
829 EXPORT_SYMBOL(nfc_digital_free_device);
831 int nfc_digital_register_device(struct nfc_digital_dev *ddev)
833 return nfc_register_device(ddev->nfc_dev);
835 EXPORT_SYMBOL(nfc_digital_register_device);
837 void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
839 struct digital_cmd *cmd, *n;
841 nfc_unregister_device(ddev->nfc_dev);
843 mutex_lock(&ddev->poll_lock);
844 ddev->poll_tech_count = 0;
845 mutex_unlock(&ddev->poll_lock);
847 cancel_delayed_work_sync(&ddev->poll_work);
848 cancel_work_sync(&ddev->cmd_work);
849 cancel_work_sync(&ddev->cmd_complete_work);
851 list_for_each_entry_safe(cmd, n, &ddev->cmd_queue, queue) {
852 list_del(&cmd->queue);
854 /* Call the command callback if any and pass it a ENODEV error.
855 * This gives a chance to the command issuer to free any
859 cmd->cmd_cb(ddev, cmd->cb_context, ERR_PTR(-ENODEV));
861 kfree(cmd->mdaa_params);
865 EXPORT_SYMBOL(nfc_digital_unregister_device);
867 MODULE_LICENSE("GPL");