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
34 struct list_head queue
;
42 struct digital_tg_mdaa_params
*mdaa_params
;
44 nfc_digital_cmd_complete_t cmd_cb
;
48 struct sk_buff
*digital_skb_alloc(struct nfc_digital_dev
*ddev
,
53 skb
= alloc_skb(len
+ ddev
->tx_headroom
+ ddev
->tx_tailroom
,
56 skb_reserve(skb
, ddev
->tx_headroom
);
61 void digital_skb_add_crc(struct sk_buff
*skb
, crc_func_t crc_func
, u16 init
,
62 u8 bitwise_inv
, u8 msb_first
)
66 crc
= crc_func(init
, skb
->data
, skb
->len
);
74 *skb_put(skb
, 1) = crc
& 0xFF;
75 *skb_put(skb
, 1) = (crc
>> 8) & 0xFF;
78 int digital_skb_check_crc(struct sk_buff
*skb
, crc_func_t crc_func
,
79 u16 crc_init
, u8 bitwise_inv
, u8 msb_first
)
87 crc
= crc_func(crc_init
, skb
->data
, skb
->len
- 2);
95 rc
= (skb
->data
[skb
->len
- 2] - (crc
& 0xFF)) +
96 (skb
->data
[skb
->len
- 1] - ((crc
>> 8) & 0xFF));
101 skb_trim(skb
, skb
->len
- 2);
106 static inline void digital_switch_rf(struct nfc_digital_dev
*ddev
, bool on
)
108 ddev
->ops
->switch_rf(ddev
, on
);
111 static inline void digital_abort_cmd(struct nfc_digital_dev
*ddev
)
113 ddev
->ops
->abort_cmd(ddev
);
116 static void digital_wq_cmd_complete(struct work_struct
*work
)
118 struct digital_cmd
*cmd
;
119 struct nfc_digital_dev
*ddev
= container_of(work
,
120 struct nfc_digital_dev
,
123 mutex_lock(&ddev
->cmd_lock
);
125 cmd
= list_first_entry_or_null(&ddev
->cmd_queue
, struct digital_cmd
,
128 mutex_unlock(&ddev
->cmd_lock
);
132 list_del(&cmd
->queue
);
134 mutex_unlock(&ddev
->cmd_lock
);
136 if (!IS_ERR(cmd
->resp
))
137 print_hex_dump_debug("DIGITAL RX: ", DUMP_PREFIX_NONE
, 16, 1,
138 cmd
->resp
->data
, cmd
->resp
->len
, false);
140 cmd
->cmd_cb(ddev
, cmd
->cb_context
, cmd
->resp
);
142 kfree(cmd
->mdaa_params
);
145 schedule_work(&ddev
->cmd_work
);
148 static void digital_send_cmd_complete(struct nfc_digital_dev
*ddev
,
149 void *arg
, struct sk_buff
*resp
)
151 struct digital_cmd
*cmd
= arg
;
155 schedule_work(&ddev
->cmd_complete_work
);
158 static void digital_wq_cmd(struct work_struct
*work
)
161 struct digital_cmd
*cmd
;
162 struct digital_tg_mdaa_params
*params
;
163 struct nfc_digital_dev
*ddev
= container_of(work
,
164 struct nfc_digital_dev
,
167 mutex_lock(&ddev
->cmd_lock
);
169 cmd
= list_first_entry_or_null(&ddev
->cmd_queue
, struct digital_cmd
,
171 if (!cmd
|| cmd
->pending
) {
172 mutex_unlock(&ddev
->cmd_lock
);
176 mutex_unlock(&ddev
->cmd_lock
);
179 print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE
, 16, 1,
180 cmd
->req
->data
, cmd
->req
->len
, false);
183 case DIGITAL_CMD_IN_SEND
:
184 rc
= ddev
->ops
->in_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
185 digital_send_cmd_complete
, cmd
);
188 case DIGITAL_CMD_TG_SEND
:
189 rc
= ddev
->ops
->tg_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
190 digital_send_cmd_complete
, cmd
);
193 case DIGITAL_CMD_TG_LISTEN
:
194 rc
= ddev
->ops
->tg_listen(ddev
, cmd
->timeout
,
195 digital_send_cmd_complete
, cmd
);
198 case DIGITAL_CMD_TG_LISTEN_MDAA
:
199 params
= cmd
->mdaa_params
;
201 rc
= ddev
->ops
->tg_listen_mdaa(ddev
, params
, cmd
->timeout
,
202 digital_send_cmd_complete
, cmd
);
205 case DIGITAL_CMD_TG_LISTEN_MD
:
206 rc
= ddev
->ops
->tg_listen_md(ddev
, cmd
->timeout
,
207 digital_send_cmd_complete
, cmd
);
211 pr_err("Unknown cmd type %d\n", cmd
->type
);
218 pr_err("in_send_command returned err %d\n", rc
);
220 mutex_lock(&ddev
->cmd_lock
);
221 list_del(&cmd
->queue
);
222 mutex_unlock(&ddev
->cmd_lock
);
225 kfree(cmd
->mdaa_params
);
228 schedule_work(&ddev
->cmd_work
);
231 int digital_send_cmd(struct nfc_digital_dev
*ddev
, u8 cmd_type
,
232 struct sk_buff
*skb
, struct digital_tg_mdaa_params
*params
,
233 u16 timeout
, nfc_digital_cmd_complete_t cmd_cb
,
236 struct digital_cmd
*cmd
;
238 cmd
= kzalloc(sizeof(struct digital_cmd
), GFP_KERNEL
);
242 cmd
->type
= cmd_type
;
243 cmd
->timeout
= timeout
;
245 cmd
->mdaa_params
= params
;
246 cmd
->cmd_cb
= cmd_cb
;
247 cmd
->cb_context
= cb_context
;
248 INIT_LIST_HEAD(&cmd
->queue
);
250 mutex_lock(&ddev
->cmd_lock
);
251 list_add_tail(&cmd
->queue
, &ddev
->cmd_queue
);
252 mutex_unlock(&ddev
->cmd_lock
);
254 schedule_work(&ddev
->cmd_work
);
259 int digital_in_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
263 rc
= ddev
->ops
->in_configure_hw(ddev
, type
, param
);
265 pr_err("in_configure_hw failed: %d\n", rc
);
270 int digital_tg_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
274 rc
= ddev
->ops
->tg_configure_hw(ddev
, type
, param
);
276 pr_err("tg_configure_hw failed: %d\n", rc
);
281 static int digital_tg_listen_mdaa(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
283 struct digital_tg_mdaa_params
*params
;
285 params
= kzalloc(sizeof(struct digital_tg_mdaa_params
), GFP_KERNEL
);
289 params
->sens_res
= DIGITAL_SENS_RES_NFC_DEP
;
290 get_random_bytes(params
->nfcid1
, sizeof(params
->nfcid1
));
291 params
->sel_res
= DIGITAL_SEL_RES_NFC_DEP
;
293 params
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
294 params
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
295 get_random_bytes(params
->nfcid2
+ 2, NFC_NFCID2_MAXSIZE
- 2);
296 params
->sc
= DIGITAL_SENSF_FELICA_SC
;
298 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MDAA
, NULL
, params
,
299 500, digital_tg_recv_atr_req
, NULL
);
302 static int digital_tg_listen_md(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
304 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MD
, NULL
, NULL
, 500,
305 digital_tg_recv_md_req
, NULL
);
308 int digital_target_found(struct nfc_digital_dev
*ddev
,
309 struct nfc_target
*target
, u8 protocol
)
315 int (*check_crc
)(struct sk_buff
*skb
);
316 void (*add_crc
)(struct sk_buff
*skb
);
318 rf_tech
= ddev
->poll_techs
[ddev
->poll_tech_index
].rf_tech
;
321 case NFC_PROTO_JEWEL
:
322 framing
= NFC_DIGITAL_FRAMING_NFCA_T1T
;
323 check_crc
= digital_skb_check_crc_b
;
324 add_crc
= digital_skb_add_crc_b
;
327 case NFC_PROTO_MIFARE
:
328 framing
= NFC_DIGITAL_FRAMING_NFCA_T2T
;
329 check_crc
= digital_skb_check_crc_a
;
330 add_crc
= digital_skb_add_crc_a
;
333 case NFC_PROTO_FELICA
:
334 framing
= NFC_DIGITAL_FRAMING_NFCF_T3T
;
335 check_crc
= digital_skb_check_crc_f
;
336 add_crc
= digital_skb_add_crc_f
;
339 case NFC_PROTO_NFC_DEP
:
340 if (rf_tech
== NFC_DIGITAL_RF_TECH_106A
) {
341 framing
= NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
;
342 check_crc
= digital_skb_check_crc_a
;
343 add_crc
= digital_skb_add_crc_a
;
345 framing
= NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
;
346 check_crc
= digital_skb_check_crc_f
;
347 add_crc
= digital_skb_add_crc_f
;
351 case NFC_PROTO_ISO15693
:
352 framing
= NFC_DIGITAL_FRAMING_ISO15693_T5T
;
353 check_crc
= digital_skb_check_crc_b
;
354 add_crc
= digital_skb_add_crc_b
;
357 case NFC_PROTO_ISO14443
:
358 framing
= NFC_DIGITAL_FRAMING_NFCA_T4T
;
359 check_crc
= digital_skb_check_crc_a
;
360 add_crc
= digital_skb_add_crc_a
;
363 case NFC_PROTO_ISO14443_B
:
364 framing
= NFC_DIGITAL_FRAMING_NFCB_T4T
;
365 check_crc
= digital_skb_check_crc_b
;
366 add_crc
= digital_skb_add_crc_b
;
370 pr_err("Invalid protocol %d\n", protocol
);
374 pr_debug("rf_tech=%d, protocol=%d\n", rf_tech
, protocol
);
376 ddev
->curr_rf_tech
= rf_tech
;
378 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
379 ddev
->skb_add_crc
= digital_skb_add_crc_none
;
380 ddev
->skb_check_crc
= digital_skb_check_crc_none
;
382 ddev
->skb_add_crc
= add_crc
;
383 ddev
->skb_check_crc
= check_crc
;
386 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
, framing
);
390 target
->supported_protocols
= (1 << protocol
);
392 poll_tech_count
= ddev
->poll_tech_count
;
393 ddev
->poll_tech_count
= 0;
395 rc
= nfc_targets_found(ddev
->nfc_dev
, target
, 1);
397 ddev
->poll_tech_count
= poll_tech_count
;
404 void digital_poll_next_tech(struct nfc_digital_dev
*ddev
)
408 digital_switch_rf(ddev
, 0);
410 mutex_lock(&ddev
->poll_lock
);
412 if (!ddev
->poll_tech_count
) {
413 mutex_unlock(&ddev
->poll_lock
);
417 get_random_bytes(&rand_mod
, sizeof(rand_mod
));
418 ddev
->poll_tech_index
= rand_mod
% ddev
->poll_tech_count
;
420 mutex_unlock(&ddev
->poll_lock
);
422 schedule_work(&ddev
->poll_work
);
425 static void digital_wq_poll(struct work_struct
*work
)
428 struct digital_poll_tech
*poll_tech
;
429 struct nfc_digital_dev
*ddev
= container_of(work
,
430 struct nfc_digital_dev
,
432 mutex_lock(&ddev
->poll_lock
);
434 if (!ddev
->poll_tech_count
) {
435 mutex_unlock(&ddev
->poll_lock
);
439 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_index
];
441 mutex_unlock(&ddev
->poll_lock
);
443 rc
= poll_tech
->poll_func(ddev
, poll_tech
->rf_tech
);
445 digital_poll_next_tech(ddev
);
448 static void digital_add_poll_tech(struct nfc_digital_dev
*ddev
, u8 rf_tech
,
449 digital_poll_t poll_func
)
451 struct digital_poll_tech
*poll_tech
;
453 if (ddev
->poll_tech_count
>= NFC_DIGITAL_POLL_MODE_COUNT_MAX
)
456 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_count
++];
458 poll_tech
->rf_tech
= rf_tech
;
459 poll_tech
->poll_func
= poll_func
;
463 * start_poll operation
465 * For every supported protocol, the corresponding polling function is added
466 * to the table of polling technologies (ddev->poll_techs[]) using
467 * digital_add_poll_tech().
468 * When a polling function fails (by timeout or protocol error) the next one is
469 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
471 static int digital_start_poll(struct nfc_dev
*nfc_dev
, __u32 im_protocols
,
474 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
475 u32 matching_im_protocols
, matching_tm_protocols
;
477 pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols
,
478 tm_protocols
, ddev
->protocols
);
480 matching_im_protocols
= ddev
->protocols
& im_protocols
;
481 matching_tm_protocols
= ddev
->protocols
& tm_protocols
;
483 if (!matching_im_protocols
&& !matching_tm_protocols
) {
484 pr_err("Unknown protocol\n");
488 if (ddev
->poll_tech_count
) {
489 pr_err("Already polling\n");
493 if (ddev
->curr_protocol
) {
494 pr_err("A target is already active\n");
498 ddev
->poll_tech_count
= 0;
499 ddev
->poll_tech_index
= 0;
501 if (matching_im_protocols
& DIGITAL_PROTO_NFCA_RF_TECH
)
502 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
503 digital_in_send_sens_req
);
505 if (matching_im_protocols
& DIGITAL_PROTO_NFCB_RF_TECH
)
506 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106B
,
507 digital_in_send_sensb_req
);
509 if (matching_im_protocols
& DIGITAL_PROTO_NFCF_RF_TECH
) {
510 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
511 digital_in_send_sensf_req
);
513 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
514 digital_in_send_sensf_req
);
517 if (matching_im_protocols
& DIGITAL_PROTO_ISO15693_RF_TECH
)
518 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_ISO15693
,
519 digital_in_send_iso15693_inv_req
);
521 if (matching_tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
522 if (ddev
->ops
->tg_listen_mdaa
) {
523 digital_add_poll_tech(ddev
, 0,
524 digital_tg_listen_mdaa
);
525 } else if (ddev
->ops
->tg_listen_md
) {
526 digital_add_poll_tech(ddev
, 0,
527 digital_tg_listen_md
);
529 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
530 digital_tg_listen_nfca
);
532 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
533 digital_tg_listen_nfcf
);
535 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
536 digital_tg_listen_nfcf
);
540 if (!ddev
->poll_tech_count
) {
541 pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n",
542 matching_im_protocols
, matching_tm_protocols
);
546 schedule_work(&ddev
->poll_work
);
551 static void digital_stop_poll(struct nfc_dev
*nfc_dev
)
553 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
555 mutex_lock(&ddev
->poll_lock
);
557 if (!ddev
->poll_tech_count
) {
558 pr_err("Polling operation was not running\n");
559 mutex_unlock(&ddev
->poll_lock
);
563 ddev
->poll_tech_count
= 0;
565 mutex_unlock(&ddev
->poll_lock
);
567 cancel_work_sync(&ddev
->poll_work
);
569 digital_abort_cmd(ddev
);
572 static int digital_dev_up(struct nfc_dev
*nfc_dev
)
574 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
576 digital_switch_rf(ddev
, 1);
581 static int digital_dev_down(struct nfc_dev
*nfc_dev
)
583 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
585 digital_switch_rf(ddev
, 0);
590 static int digital_dep_link_up(struct nfc_dev
*nfc_dev
,
591 struct nfc_target
*target
,
592 __u8 comm_mode
, __u8
*gb
, size_t gb_len
)
594 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
597 rc
= digital_in_send_atr_req(ddev
, target
, comm_mode
, gb
, gb_len
);
600 ddev
->curr_protocol
= NFC_PROTO_NFC_DEP
;
605 static int digital_dep_link_down(struct nfc_dev
*nfc_dev
)
607 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
609 ddev
->curr_protocol
= 0;
614 static int digital_activate_target(struct nfc_dev
*nfc_dev
,
615 struct nfc_target
*target
, __u32 protocol
)
617 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
619 if (ddev
->poll_tech_count
) {
620 pr_err("Can't activate a target while polling\n");
624 if (ddev
->curr_protocol
) {
625 pr_err("A target is already active\n");
629 ddev
->curr_protocol
= protocol
;
634 static void digital_deactivate_target(struct nfc_dev
*nfc_dev
,
635 struct nfc_target
*target
,
638 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
640 if (!ddev
->curr_protocol
) {
641 pr_err("No active target\n");
645 ddev
->curr_protocol
= 0;
648 static int digital_tg_send(struct nfc_dev
*dev
, struct sk_buff
*skb
)
650 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(dev
);
652 return digital_tg_send_dep_res(ddev
, skb
);
655 static void digital_in_send_complete(struct nfc_digital_dev
*ddev
, void *arg
,
656 struct sk_buff
*resp
)
658 struct digital_data_exch
*data_exch
= arg
;
667 if (ddev
->curr_protocol
== NFC_PROTO_MIFARE
) {
668 rc
= digital_in_recv_mifare_res(resp
);
669 /* crc check is done in digital_in_recv_mifare_res() */
673 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
674 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
675 rc
= digital_in_iso_dep_pull_sod(ddev
, resp
);
680 rc
= ddev
->skb_check_crc(resp
);
688 data_exch
->cb(data_exch
->cb_context
, resp
, rc
);
693 static int digital_in_send(struct nfc_dev
*nfc_dev
, struct nfc_target
*target
,
694 struct sk_buff
*skb
, data_exchange_cb_t cb
,
697 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
698 struct digital_data_exch
*data_exch
;
701 data_exch
= kzalloc(sizeof(struct digital_data_exch
), GFP_KERNEL
);
703 pr_err("Failed to allocate data_exch struct\n");
708 data_exch
->cb_context
= cb_context
;
710 if (ddev
->curr_protocol
== NFC_PROTO_NFC_DEP
) {
711 rc
= digital_in_send_dep_req(ddev
, target
, skb
, data_exch
);
715 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
716 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
717 rc
= digital_in_iso_dep_push_sod(ddev
, skb
);
722 ddev
->skb_add_crc(skb
);
724 rc
= digital_in_send_cmd(ddev
, skb
, 500, digital_in_send_complete
,
734 static struct nfc_ops digital_nfc_ops
= {
735 .dev_up
= digital_dev_up
,
736 .dev_down
= digital_dev_down
,
737 .start_poll
= digital_start_poll
,
738 .stop_poll
= digital_stop_poll
,
739 .dep_link_up
= digital_dep_link_up
,
740 .dep_link_down
= digital_dep_link_down
,
741 .activate_target
= digital_activate_target
,
742 .deactivate_target
= digital_deactivate_target
,
743 .tm_send
= digital_tg_send
,
744 .im_transceive
= digital_in_send
,
747 struct nfc_digital_dev
*nfc_digital_allocate_device(struct nfc_digital_ops
*ops
,
748 __u32 supported_protocols
,
749 __u32 driver_capabilities
,
750 int tx_headroom
, int tx_tailroom
)
752 struct nfc_digital_dev
*ddev
;
754 if (!ops
->in_configure_hw
|| !ops
->in_send_cmd
|| !ops
->tg_listen
||
755 !ops
->tg_configure_hw
|| !ops
->tg_send_cmd
|| !ops
->abort_cmd
||
756 !ops
->switch_rf
|| (ops
->tg_listen_md
&& !ops
->tg_get_rf_tech
))
759 ddev
= kzalloc(sizeof(struct nfc_digital_dev
), GFP_KERNEL
);
763 ddev
->driver_capabilities
= driver_capabilities
;
766 mutex_init(&ddev
->cmd_lock
);
767 INIT_LIST_HEAD(&ddev
->cmd_queue
);
769 INIT_WORK(&ddev
->cmd_work
, digital_wq_cmd
);
770 INIT_WORK(&ddev
->cmd_complete_work
, digital_wq_cmd_complete
);
772 mutex_init(&ddev
->poll_lock
);
773 INIT_WORK(&ddev
->poll_work
, digital_wq_poll
);
775 if (supported_protocols
& NFC_PROTO_JEWEL_MASK
)
776 ddev
->protocols
|= NFC_PROTO_JEWEL_MASK
;
777 if (supported_protocols
& NFC_PROTO_MIFARE_MASK
)
778 ddev
->protocols
|= NFC_PROTO_MIFARE_MASK
;
779 if (supported_protocols
& NFC_PROTO_FELICA_MASK
)
780 ddev
->protocols
|= NFC_PROTO_FELICA_MASK
;
781 if (supported_protocols
& NFC_PROTO_NFC_DEP_MASK
)
782 ddev
->protocols
|= NFC_PROTO_NFC_DEP_MASK
;
783 if (supported_protocols
& NFC_PROTO_ISO15693_MASK
)
784 ddev
->protocols
|= NFC_PROTO_ISO15693_MASK
;
785 if (supported_protocols
& NFC_PROTO_ISO14443_MASK
)
786 ddev
->protocols
|= NFC_PROTO_ISO14443_MASK
;
787 if (supported_protocols
& NFC_PROTO_ISO14443_B_MASK
)
788 ddev
->protocols
|= NFC_PROTO_ISO14443_B_MASK
;
790 ddev
->tx_headroom
= tx_headroom
+ DIGITAL_MAX_HEADER_LEN
;
791 ddev
->tx_tailroom
= tx_tailroom
+ DIGITAL_CRC_LEN
;
793 ddev
->nfc_dev
= nfc_allocate_device(&digital_nfc_ops
, ddev
->protocols
,
796 if (!ddev
->nfc_dev
) {
797 pr_err("nfc_allocate_device failed\n");
801 nfc_set_drvdata(ddev
->nfc_dev
, ddev
);
810 EXPORT_SYMBOL(nfc_digital_allocate_device
);
812 void nfc_digital_free_device(struct nfc_digital_dev
*ddev
)
814 nfc_free_device(ddev
->nfc_dev
);
817 EXPORT_SYMBOL(nfc_digital_free_device
);
819 int nfc_digital_register_device(struct nfc_digital_dev
*ddev
)
821 return nfc_register_device(ddev
->nfc_dev
);
823 EXPORT_SYMBOL(nfc_digital_register_device
);
825 void nfc_digital_unregister_device(struct nfc_digital_dev
*ddev
)
827 struct digital_cmd
*cmd
, *n
;
829 nfc_unregister_device(ddev
->nfc_dev
);
831 mutex_lock(&ddev
->poll_lock
);
832 ddev
->poll_tech_count
= 0;
833 mutex_unlock(&ddev
->poll_lock
);
835 cancel_work_sync(&ddev
->poll_work
);
836 cancel_work_sync(&ddev
->cmd_work
);
837 cancel_work_sync(&ddev
->cmd_complete_work
);
839 list_for_each_entry_safe(cmd
, n
, &ddev
->cmd_queue
, queue
) {
840 list_del(&cmd
->queue
);
841 kfree(cmd
->mdaa_params
);
845 EXPORT_SYMBOL(nfc_digital_unregister_device
);
847 MODULE_LICENSE("GPL");