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 | NFC_PROTO_NFC_DEP_MASK)
25 #define DIGITAL_PROTO_NFCB_RF_TECH NFC_PROTO_ISO14443_B_MASK
27 #define DIGITAL_PROTO_NFCF_RF_TECH \
28 (NFC_PROTO_FELICA_MASK | NFC_PROTO_NFC_DEP_MASK)
30 #define DIGITAL_PROTO_ISO15693_RF_TECH NFC_PROTO_ISO15693_MASK
33 struct list_head queue
;
41 struct digital_tg_mdaa_params
*mdaa_params
;
43 nfc_digital_cmd_complete_t cmd_cb
;
47 struct sk_buff
*digital_skb_alloc(struct nfc_digital_dev
*ddev
,
52 skb
= alloc_skb(len
+ ddev
->tx_headroom
+ ddev
->tx_tailroom
,
55 skb_reserve(skb
, ddev
->tx_headroom
);
60 void digital_skb_add_crc(struct sk_buff
*skb
, crc_func_t crc_func
, u16 init
,
61 u8 bitwise_inv
, u8 msb_first
)
65 crc
= crc_func(init
, skb
->data
, skb
->len
);
73 *skb_put(skb
, 1) = crc
& 0xFF;
74 *skb_put(skb
, 1) = (crc
>> 8) & 0xFF;
77 int digital_skb_check_crc(struct sk_buff
*skb
, crc_func_t crc_func
,
78 u16 crc_init
, u8 bitwise_inv
, u8 msb_first
)
86 crc
= crc_func(crc_init
, skb
->data
, skb
->len
- 2);
94 rc
= (skb
->data
[skb
->len
- 2] - (crc
& 0xFF)) +
95 (skb
->data
[skb
->len
- 1] - ((crc
>> 8) & 0xFF));
100 skb_trim(skb
, skb
->len
- 2);
105 static inline void digital_switch_rf(struct nfc_digital_dev
*ddev
, bool on
)
107 ddev
->ops
->switch_rf(ddev
, on
);
110 static inline void digital_abort_cmd(struct nfc_digital_dev
*ddev
)
112 ddev
->ops
->abort_cmd(ddev
);
115 static void digital_wq_cmd_complete(struct work_struct
*work
)
117 struct digital_cmd
*cmd
;
118 struct nfc_digital_dev
*ddev
= container_of(work
,
119 struct nfc_digital_dev
,
122 mutex_lock(&ddev
->cmd_lock
);
124 cmd
= list_first_entry_or_null(&ddev
->cmd_queue
, struct digital_cmd
,
127 mutex_unlock(&ddev
->cmd_lock
);
131 list_del(&cmd
->queue
);
133 mutex_unlock(&ddev
->cmd_lock
);
135 if (!IS_ERR(cmd
->resp
))
136 print_hex_dump_debug("DIGITAL RX: ", DUMP_PREFIX_NONE
, 16, 1,
137 cmd
->resp
->data
, cmd
->resp
->len
, false);
139 cmd
->cmd_cb(ddev
, cmd
->cb_context
, cmd
->resp
);
141 kfree(cmd
->mdaa_params
);
144 schedule_work(&ddev
->cmd_work
);
147 static void digital_send_cmd_complete(struct nfc_digital_dev
*ddev
,
148 void *arg
, struct sk_buff
*resp
)
150 struct digital_cmd
*cmd
= arg
;
154 schedule_work(&ddev
->cmd_complete_work
);
157 static void digital_wq_cmd(struct work_struct
*work
)
160 struct digital_cmd
*cmd
;
161 struct digital_tg_mdaa_params
*params
;
162 struct nfc_digital_dev
*ddev
= container_of(work
,
163 struct nfc_digital_dev
,
166 mutex_lock(&ddev
->cmd_lock
);
168 cmd
= list_first_entry_or_null(&ddev
->cmd_queue
, struct digital_cmd
,
170 if (!cmd
|| cmd
->pending
) {
171 mutex_unlock(&ddev
->cmd_lock
);
175 mutex_unlock(&ddev
->cmd_lock
);
178 print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE
, 16, 1,
179 cmd
->req
->data
, cmd
->req
->len
, false);
182 case DIGITAL_CMD_IN_SEND
:
183 rc
= ddev
->ops
->in_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
184 digital_send_cmd_complete
, cmd
);
187 case DIGITAL_CMD_TG_SEND
:
188 rc
= ddev
->ops
->tg_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
189 digital_send_cmd_complete
, cmd
);
192 case DIGITAL_CMD_TG_LISTEN
:
193 rc
= ddev
->ops
->tg_listen(ddev
, cmd
->timeout
,
194 digital_send_cmd_complete
, cmd
);
197 case DIGITAL_CMD_TG_LISTEN_MDAA
:
198 params
= cmd
->mdaa_params
;
200 rc
= ddev
->ops
->tg_listen_mdaa(ddev
, params
, cmd
->timeout
,
201 digital_send_cmd_complete
, cmd
);
205 pr_err("Unknown cmd type %d\n", cmd
->type
);
212 pr_err("in_send_command returned err %d\n", rc
);
214 mutex_lock(&ddev
->cmd_lock
);
215 list_del(&cmd
->queue
);
216 mutex_unlock(&ddev
->cmd_lock
);
219 kfree(cmd
->mdaa_params
);
222 schedule_work(&ddev
->cmd_work
);
225 int digital_send_cmd(struct nfc_digital_dev
*ddev
, u8 cmd_type
,
226 struct sk_buff
*skb
, struct digital_tg_mdaa_params
*params
,
227 u16 timeout
, nfc_digital_cmd_complete_t cmd_cb
,
230 struct digital_cmd
*cmd
;
232 cmd
= kzalloc(sizeof(struct digital_cmd
), GFP_KERNEL
);
236 cmd
->type
= cmd_type
;
237 cmd
->timeout
= timeout
;
239 cmd
->mdaa_params
= params
;
240 cmd
->cmd_cb
= cmd_cb
;
241 cmd
->cb_context
= cb_context
;
242 INIT_LIST_HEAD(&cmd
->queue
);
244 mutex_lock(&ddev
->cmd_lock
);
245 list_add_tail(&cmd
->queue
, &ddev
->cmd_queue
);
246 mutex_unlock(&ddev
->cmd_lock
);
248 schedule_work(&ddev
->cmd_work
);
253 int digital_in_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
257 rc
= ddev
->ops
->in_configure_hw(ddev
, type
, param
);
259 pr_err("in_configure_hw failed: %d\n", rc
);
264 int digital_tg_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
268 rc
= ddev
->ops
->tg_configure_hw(ddev
, type
, param
);
270 pr_err("tg_configure_hw failed: %d\n", rc
);
275 static int digital_tg_listen_mdaa(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
277 struct digital_tg_mdaa_params
*params
;
279 params
= kzalloc(sizeof(struct digital_tg_mdaa_params
), GFP_KERNEL
);
283 params
->sens_res
= DIGITAL_SENS_RES_NFC_DEP
;
284 get_random_bytes(params
->nfcid1
, sizeof(params
->nfcid1
));
285 params
->sel_res
= DIGITAL_SEL_RES_NFC_DEP
;
287 params
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
288 params
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
289 get_random_bytes(params
->nfcid2
+ 2, NFC_NFCID2_MAXSIZE
- 2);
290 params
->sc
= DIGITAL_SENSF_FELICA_SC
;
292 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MDAA
, NULL
, params
,
293 500, digital_tg_recv_atr_req
, NULL
);
296 int digital_target_found(struct nfc_digital_dev
*ddev
,
297 struct nfc_target
*target
, u8 protocol
)
302 int (*check_crc
)(struct sk_buff
*skb
);
303 void (*add_crc
)(struct sk_buff
*skb
);
305 rf_tech
= ddev
->poll_techs
[ddev
->poll_tech_index
].rf_tech
;
308 case NFC_PROTO_JEWEL
:
309 framing
= NFC_DIGITAL_FRAMING_NFCA_T1T
;
310 check_crc
= digital_skb_check_crc_b
;
311 add_crc
= digital_skb_add_crc_b
;
314 case NFC_PROTO_MIFARE
:
315 framing
= NFC_DIGITAL_FRAMING_NFCA_T2T
;
316 check_crc
= digital_skb_check_crc_a
;
317 add_crc
= digital_skb_add_crc_a
;
320 case NFC_PROTO_FELICA
:
321 framing
= NFC_DIGITAL_FRAMING_NFCF_T3T
;
322 check_crc
= digital_skb_check_crc_f
;
323 add_crc
= digital_skb_add_crc_f
;
326 case NFC_PROTO_NFC_DEP
:
327 if (rf_tech
== NFC_DIGITAL_RF_TECH_106A
) {
328 framing
= NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
;
329 check_crc
= digital_skb_check_crc_a
;
330 add_crc
= digital_skb_add_crc_a
;
332 framing
= NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
;
333 check_crc
= digital_skb_check_crc_f
;
334 add_crc
= digital_skb_add_crc_f
;
338 case NFC_PROTO_ISO15693
:
339 framing
= NFC_DIGITAL_FRAMING_ISO15693_T5T
;
340 check_crc
= digital_skb_check_crc_b
;
341 add_crc
= digital_skb_add_crc_b
;
344 case NFC_PROTO_ISO14443
:
345 framing
= NFC_DIGITAL_FRAMING_NFCA_T4T
;
346 check_crc
= digital_skb_check_crc_a
;
347 add_crc
= digital_skb_add_crc_a
;
350 case NFC_PROTO_ISO14443_B
:
351 framing
= NFC_DIGITAL_FRAMING_NFCB_T4T
;
352 check_crc
= digital_skb_check_crc_b
;
353 add_crc
= digital_skb_add_crc_b
;
357 pr_err("Invalid protocol %d\n", protocol
);
361 pr_debug("rf_tech=%d, protocol=%d\n", rf_tech
, protocol
);
363 ddev
->curr_rf_tech
= rf_tech
;
365 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
366 ddev
->skb_add_crc
= digital_skb_add_crc_none
;
367 ddev
->skb_check_crc
= digital_skb_check_crc_none
;
369 ddev
->skb_add_crc
= add_crc
;
370 ddev
->skb_check_crc
= check_crc
;
373 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
, framing
);
377 target
->supported_protocols
= (1 << protocol
);
378 rc
= nfc_targets_found(ddev
->nfc_dev
, target
, 1);
382 ddev
->poll_tech_count
= 0;
387 void digital_poll_next_tech(struct nfc_digital_dev
*ddev
)
389 digital_switch_rf(ddev
, 0);
391 mutex_lock(&ddev
->poll_lock
);
393 if (!ddev
->poll_tech_count
) {
394 mutex_unlock(&ddev
->poll_lock
);
398 ddev
->poll_tech_index
= (ddev
->poll_tech_index
+ 1) %
399 ddev
->poll_tech_count
;
401 mutex_unlock(&ddev
->poll_lock
);
403 schedule_work(&ddev
->poll_work
);
406 static void digital_wq_poll(struct work_struct
*work
)
409 struct digital_poll_tech
*poll_tech
;
410 struct nfc_digital_dev
*ddev
= container_of(work
,
411 struct nfc_digital_dev
,
413 mutex_lock(&ddev
->poll_lock
);
415 if (!ddev
->poll_tech_count
) {
416 mutex_unlock(&ddev
->poll_lock
);
420 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_index
];
422 mutex_unlock(&ddev
->poll_lock
);
424 rc
= poll_tech
->poll_func(ddev
, poll_tech
->rf_tech
);
426 digital_poll_next_tech(ddev
);
429 static void digital_add_poll_tech(struct nfc_digital_dev
*ddev
, u8 rf_tech
,
430 digital_poll_t poll_func
)
432 struct digital_poll_tech
*poll_tech
;
434 if (ddev
->poll_tech_count
>= NFC_DIGITAL_POLL_MODE_COUNT_MAX
)
437 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_count
++];
439 poll_tech
->rf_tech
= rf_tech
;
440 poll_tech
->poll_func
= poll_func
;
444 * start_poll operation
446 * For every supported protocol, the corresponding polling function is added
447 * to the table of polling technologies (ddev->poll_techs[]) using
448 * digital_add_poll_tech().
449 * When a polling function fails (by timeout or protocol error) the next one is
450 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
452 static int digital_start_poll(struct nfc_dev
*nfc_dev
, __u32 im_protocols
,
455 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
456 u32 matching_im_protocols
, matching_tm_protocols
;
458 pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols
,
459 tm_protocols
, ddev
->protocols
);
461 matching_im_protocols
= ddev
->protocols
& im_protocols
;
462 matching_tm_protocols
= ddev
->protocols
& tm_protocols
;
464 if (!matching_im_protocols
&& !matching_tm_protocols
) {
465 pr_err("Unknown protocol\n");
469 if (ddev
->poll_tech_count
) {
470 pr_err("Already polling\n");
474 if (ddev
->curr_protocol
) {
475 pr_err("A target is already active\n");
479 ddev
->poll_tech_count
= 0;
480 ddev
->poll_tech_index
= 0;
482 if (matching_im_protocols
& DIGITAL_PROTO_NFCA_RF_TECH
)
483 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
484 digital_in_send_sens_req
);
486 if (matching_im_protocols
& DIGITAL_PROTO_NFCB_RF_TECH
)
487 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106B
,
488 digital_in_send_sensb_req
);
490 if (matching_im_protocols
& DIGITAL_PROTO_NFCF_RF_TECH
) {
491 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
492 digital_in_send_sensf_req
);
494 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
495 digital_in_send_sensf_req
);
498 if (matching_im_protocols
& DIGITAL_PROTO_ISO15693_RF_TECH
)
499 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_ISO15693
,
500 digital_in_send_iso15693_inv_req
);
502 if (matching_tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
503 if (ddev
->ops
->tg_listen_mdaa
) {
504 digital_add_poll_tech(ddev
, 0,
505 digital_tg_listen_mdaa
);
507 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
508 digital_tg_listen_nfca
);
510 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
511 digital_tg_listen_nfcf
);
513 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
514 digital_tg_listen_nfcf
);
518 if (!ddev
->poll_tech_count
) {
519 pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n",
520 matching_im_protocols
, matching_tm_protocols
);
524 schedule_work(&ddev
->poll_work
);
529 static void digital_stop_poll(struct nfc_dev
*nfc_dev
)
531 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
533 mutex_lock(&ddev
->poll_lock
);
535 if (!ddev
->poll_tech_count
) {
536 pr_err("Polling operation was not running\n");
537 mutex_unlock(&ddev
->poll_lock
);
541 ddev
->poll_tech_count
= 0;
543 mutex_unlock(&ddev
->poll_lock
);
545 cancel_work_sync(&ddev
->poll_work
);
547 digital_abort_cmd(ddev
);
550 static int digital_dev_up(struct nfc_dev
*nfc_dev
)
552 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
554 digital_switch_rf(ddev
, 1);
559 static int digital_dev_down(struct nfc_dev
*nfc_dev
)
561 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
563 digital_switch_rf(ddev
, 0);
568 static int digital_dep_link_up(struct nfc_dev
*nfc_dev
,
569 struct nfc_target
*target
,
570 __u8 comm_mode
, __u8
*gb
, size_t gb_len
)
572 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
575 rc
= digital_in_send_atr_req(ddev
, target
, comm_mode
, gb
, gb_len
);
578 ddev
->curr_protocol
= NFC_PROTO_NFC_DEP
;
583 static int digital_dep_link_down(struct nfc_dev
*nfc_dev
)
585 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
587 ddev
->curr_protocol
= 0;
592 static int digital_activate_target(struct nfc_dev
*nfc_dev
,
593 struct nfc_target
*target
, __u32 protocol
)
595 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
597 if (ddev
->poll_tech_count
) {
598 pr_err("Can't activate a target while polling\n");
602 if (ddev
->curr_protocol
) {
603 pr_err("A target is already active\n");
607 ddev
->curr_protocol
= protocol
;
612 static void digital_deactivate_target(struct nfc_dev
*nfc_dev
,
613 struct nfc_target
*target
)
615 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
617 if (!ddev
->curr_protocol
) {
618 pr_err("No active target\n");
622 ddev
->curr_protocol
= 0;
625 static int digital_tg_send(struct nfc_dev
*dev
, struct sk_buff
*skb
)
627 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(dev
);
629 return digital_tg_send_dep_res(ddev
, skb
);
632 static void digital_in_send_complete(struct nfc_digital_dev
*ddev
, void *arg
,
633 struct sk_buff
*resp
)
635 struct digital_data_exch
*data_exch
= arg
;
644 if (ddev
->curr_protocol
== NFC_PROTO_MIFARE
) {
645 rc
= digital_in_recv_mifare_res(resp
);
646 /* crc check is done in digital_in_recv_mifare_res() */
650 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
651 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
652 rc
= digital_in_iso_dep_pull_sod(ddev
, resp
);
657 rc
= ddev
->skb_check_crc(resp
);
665 data_exch
->cb(data_exch
->cb_context
, resp
, rc
);
670 static int digital_in_send(struct nfc_dev
*nfc_dev
, struct nfc_target
*target
,
671 struct sk_buff
*skb
, data_exchange_cb_t cb
,
674 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
675 struct digital_data_exch
*data_exch
;
678 data_exch
= kzalloc(sizeof(struct digital_data_exch
), GFP_KERNEL
);
680 pr_err("Failed to allocate data_exch struct\n");
685 data_exch
->cb_context
= cb_context
;
687 if (ddev
->curr_protocol
== NFC_PROTO_NFC_DEP
) {
688 rc
= digital_in_send_dep_req(ddev
, target
, skb
, data_exch
);
692 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
693 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
694 rc
= digital_in_iso_dep_push_sod(ddev
, skb
);
699 ddev
->skb_add_crc(skb
);
701 rc
= digital_in_send_cmd(ddev
, skb
, 500, digital_in_send_complete
,
711 static struct nfc_ops digital_nfc_ops
= {
712 .dev_up
= digital_dev_up
,
713 .dev_down
= digital_dev_down
,
714 .start_poll
= digital_start_poll
,
715 .stop_poll
= digital_stop_poll
,
716 .dep_link_up
= digital_dep_link_up
,
717 .dep_link_down
= digital_dep_link_down
,
718 .activate_target
= digital_activate_target
,
719 .deactivate_target
= digital_deactivate_target
,
720 .tm_send
= digital_tg_send
,
721 .im_transceive
= digital_in_send
,
724 struct nfc_digital_dev
*nfc_digital_allocate_device(struct nfc_digital_ops
*ops
,
725 __u32 supported_protocols
,
726 __u32 driver_capabilities
,
727 int tx_headroom
, int tx_tailroom
)
729 struct nfc_digital_dev
*ddev
;
731 if (!ops
->in_configure_hw
|| !ops
->in_send_cmd
|| !ops
->tg_listen
||
732 !ops
->tg_configure_hw
|| !ops
->tg_send_cmd
|| !ops
->abort_cmd
||
736 ddev
= kzalloc(sizeof(struct nfc_digital_dev
), GFP_KERNEL
);
740 ddev
->driver_capabilities
= driver_capabilities
;
743 mutex_init(&ddev
->cmd_lock
);
744 INIT_LIST_HEAD(&ddev
->cmd_queue
);
746 INIT_WORK(&ddev
->cmd_work
, digital_wq_cmd
);
747 INIT_WORK(&ddev
->cmd_complete_work
, digital_wq_cmd_complete
);
749 mutex_init(&ddev
->poll_lock
);
750 INIT_WORK(&ddev
->poll_work
, digital_wq_poll
);
752 if (supported_protocols
& NFC_PROTO_JEWEL_MASK
)
753 ddev
->protocols
|= NFC_PROTO_JEWEL_MASK
;
754 if (supported_protocols
& NFC_PROTO_MIFARE_MASK
)
755 ddev
->protocols
|= NFC_PROTO_MIFARE_MASK
;
756 if (supported_protocols
& NFC_PROTO_FELICA_MASK
)
757 ddev
->protocols
|= NFC_PROTO_FELICA_MASK
;
758 if (supported_protocols
& NFC_PROTO_NFC_DEP_MASK
)
759 ddev
->protocols
|= NFC_PROTO_NFC_DEP_MASK
;
760 if (supported_protocols
& NFC_PROTO_ISO15693_MASK
)
761 ddev
->protocols
|= NFC_PROTO_ISO15693_MASK
;
762 if (supported_protocols
& NFC_PROTO_ISO14443_MASK
)
763 ddev
->protocols
|= NFC_PROTO_ISO14443_MASK
;
764 if (supported_protocols
& NFC_PROTO_ISO14443_B_MASK
)
765 ddev
->protocols
|= NFC_PROTO_ISO14443_B_MASK
;
767 ddev
->tx_headroom
= tx_headroom
+ DIGITAL_MAX_HEADER_LEN
;
768 ddev
->tx_tailroom
= tx_tailroom
+ DIGITAL_CRC_LEN
;
770 ddev
->nfc_dev
= nfc_allocate_device(&digital_nfc_ops
, ddev
->protocols
,
773 if (!ddev
->nfc_dev
) {
774 pr_err("nfc_allocate_device failed\n");
778 nfc_set_drvdata(ddev
->nfc_dev
, ddev
);
787 EXPORT_SYMBOL(nfc_digital_allocate_device
);
789 void nfc_digital_free_device(struct nfc_digital_dev
*ddev
)
791 nfc_free_device(ddev
->nfc_dev
);
794 EXPORT_SYMBOL(nfc_digital_free_device
);
796 int nfc_digital_register_device(struct nfc_digital_dev
*ddev
)
798 return nfc_register_device(ddev
->nfc_dev
);
800 EXPORT_SYMBOL(nfc_digital_register_device
);
802 void nfc_digital_unregister_device(struct nfc_digital_dev
*ddev
)
804 struct digital_cmd
*cmd
, *n
;
806 nfc_unregister_device(ddev
->nfc_dev
);
808 mutex_lock(&ddev
->poll_lock
);
809 ddev
->poll_tech_count
= 0;
810 mutex_unlock(&ddev
->poll_lock
);
812 cancel_work_sync(&ddev
->poll_work
);
813 cancel_work_sync(&ddev
->cmd_work
);
814 cancel_work_sync(&ddev
->cmd_complete_work
);
816 list_for_each_entry_safe(cmd
, n
, &ddev
->cmd_queue
, queue
) {
817 list_del(&cmd
->queue
);
818 kfree(cmd
->mdaa_params
);
822 EXPORT_SYMBOL(nfc_digital_unregister_device
);
824 MODULE_LICENSE("GPL");