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(skb
, 1) = crc
& 0xFF;
78 *skb_put(skb
, 1) = (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
);
179 mutex_unlock(&ddev
->cmd_lock
);
182 print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE
, 16, 1,
183 cmd
->req
->data
, cmd
->req
->len
, false);
186 case DIGITAL_CMD_IN_SEND
:
187 rc
= ddev
->ops
->in_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
188 digital_send_cmd_complete
, cmd
);
191 case DIGITAL_CMD_TG_SEND
:
192 rc
= ddev
->ops
->tg_send_cmd(ddev
, cmd
->req
, cmd
->timeout
,
193 digital_send_cmd_complete
, cmd
);
196 case DIGITAL_CMD_TG_LISTEN
:
197 rc
= ddev
->ops
->tg_listen(ddev
, cmd
->timeout
,
198 digital_send_cmd_complete
, cmd
);
201 case DIGITAL_CMD_TG_LISTEN_MDAA
:
202 params
= cmd
->mdaa_params
;
204 rc
= ddev
->ops
->tg_listen_mdaa(ddev
, params
, cmd
->timeout
,
205 digital_send_cmd_complete
, cmd
);
208 case DIGITAL_CMD_TG_LISTEN_MD
:
209 rc
= ddev
->ops
->tg_listen_md(ddev
, cmd
->timeout
,
210 digital_send_cmd_complete
, cmd
);
214 pr_err("Unknown cmd type %d\n", cmd
->type
);
221 pr_err("in_send_command returned err %d\n", rc
);
223 mutex_lock(&ddev
->cmd_lock
);
224 list_del(&cmd
->queue
);
225 mutex_unlock(&ddev
->cmd_lock
);
228 kfree(cmd
->mdaa_params
);
231 schedule_work(&ddev
->cmd_work
);
234 int digital_send_cmd(struct nfc_digital_dev
*ddev
, u8 cmd_type
,
235 struct sk_buff
*skb
, struct digital_tg_mdaa_params
*params
,
236 u16 timeout
, nfc_digital_cmd_complete_t cmd_cb
,
239 struct digital_cmd
*cmd
;
241 cmd
= kzalloc(sizeof(struct digital_cmd
), GFP_KERNEL
);
245 cmd
->type
= cmd_type
;
246 cmd
->timeout
= timeout
;
248 cmd
->mdaa_params
= params
;
249 cmd
->cmd_cb
= cmd_cb
;
250 cmd
->cb_context
= cb_context
;
251 INIT_LIST_HEAD(&cmd
->queue
);
253 mutex_lock(&ddev
->cmd_lock
);
254 list_add_tail(&cmd
->queue
, &ddev
->cmd_queue
);
255 mutex_unlock(&ddev
->cmd_lock
);
257 schedule_work(&ddev
->cmd_work
);
262 int digital_in_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
266 rc
= ddev
->ops
->in_configure_hw(ddev
, type
, param
);
268 pr_err("in_configure_hw failed: %d\n", rc
);
273 int digital_tg_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
277 rc
= ddev
->ops
->tg_configure_hw(ddev
, type
, param
);
279 pr_err("tg_configure_hw failed: %d\n", rc
);
284 static int digital_tg_listen_mdaa(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
286 struct digital_tg_mdaa_params
*params
;
288 params
= kzalloc(sizeof(struct digital_tg_mdaa_params
), GFP_KERNEL
);
292 params
->sens_res
= DIGITAL_SENS_RES_NFC_DEP
;
293 get_random_bytes(params
->nfcid1
, sizeof(params
->nfcid1
));
294 params
->sel_res
= DIGITAL_SEL_RES_NFC_DEP
;
296 params
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
297 params
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
298 get_random_bytes(params
->nfcid2
+ 2, NFC_NFCID2_MAXSIZE
- 2);
299 params
->sc
= DIGITAL_SENSF_FELICA_SC
;
301 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MDAA
, NULL
, params
,
302 500, digital_tg_recv_atr_req
, NULL
);
305 static int digital_tg_listen_md(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
307 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MD
, NULL
, NULL
, 500,
308 digital_tg_recv_md_req
, NULL
);
311 int digital_target_found(struct nfc_digital_dev
*ddev
,
312 struct nfc_target
*target
, u8 protocol
)
318 int (*check_crc
)(struct sk_buff
*skb
);
319 void (*add_crc
)(struct sk_buff
*skb
);
321 rf_tech
= ddev
->poll_techs
[ddev
->poll_tech_index
].rf_tech
;
324 case NFC_PROTO_JEWEL
:
325 framing
= NFC_DIGITAL_FRAMING_NFCA_T1T
;
326 check_crc
= digital_skb_check_crc_b
;
327 add_crc
= digital_skb_add_crc_b
;
330 case NFC_PROTO_MIFARE
:
331 framing
= NFC_DIGITAL_FRAMING_NFCA_T2T
;
332 check_crc
= digital_skb_check_crc_a
;
333 add_crc
= digital_skb_add_crc_a
;
336 case NFC_PROTO_FELICA
:
337 framing
= NFC_DIGITAL_FRAMING_NFCF_T3T
;
338 check_crc
= digital_skb_check_crc_f
;
339 add_crc
= digital_skb_add_crc_f
;
342 case NFC_PROTO_NFC_DEP
:
343 if (rf_tech
== NFC_DIGITAL_RF_TECH_106A
) {
344 framing
= NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
;
345 check_crc
= digital_skb_check_crc_a
;
346 add_crc
= digital_skb_add_crc_a
;
348 framing
= NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
;
349 check_crc
= digital_skb_check_crc_f
;
350 add_crc
= digital_skb_add_crc_f
;
354 case NFC_PROTO_ISO15693
:
355 framing
= NFC_DIGITAL_FRAMING_ISO15693_T5T
;
356 check_crc
= digital_skb_check_crc_b
;
357 add_crc
= digital_skb_add_crc_b
;
360 case NFC_PROTO_ISO14443
:
361 framing
= NFC_DIGITAL_FRAMING_NFCA_T4T
;
362 check_crc
= digital_skb_check_crc_a
;
363 add_crc
= digital_skb_add_crc_a
;
366 case NFC_PROTO_ISO14443_B
:
367 framing
= NFC_DIGITAL_FRAMING_NFCB_T4T
;
368 check_crc
= digital_skb_check_crc_b
;
369 add_crc
= digital_skb_add_crc_b
;
373 pr_err("Invalid protocol %d\n", protocol
);
377 pr_debug("rf_tech=%d, protocol=%d\n", rf_tech
, protocol
);
379 ddev
->curr_rf_tech
= rf_tech
;
381 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
382 ddev
->skb_add_crc
= digital_skb_add_crc_none
;
383 ddev
->skb_check_crc
= digital_skb_check_crc_none
;
385 ddev
->skb_add_crc
= add_crc
;
386 ddev
->skb_check_crc
= check_crc
;
389 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
, framing
);
393 target
->supported_protocols
= (1 << protocol
);
395 poll_tech_count
= ddev
->poll_tech_count
;
396 ddev
->poll_tech_count
= 0;
398 rc
= nfc_targets_found(ddev
->nfc_dev
, target
, 1);
400 ddev
->poll_tech_count
= poll_tech_count
;
407 void digital_poll_next_tech(struct nfc_digital_dev
*ddev
)
411 digital_switch_rf(ddev
, 0);
413 mutex_lock(&ddev
->poll_lock
);
415 if (!ddev
->poll_tech_count
) {
416 mutex_unlock(&ddev
->poll_lock
);
420 get_random_bytes(&rand_mod
, sizeof(rand_mod
));
421 ddev
->poll_tech_index
= rand_mod
% ddev
->poll_tech_count
;
423 mutex_unlock(&ddev
->poll_lock
);
425 schedule_delayed_work(&ddev
->poll_work
,
426 msecs_to_jiffies(DIGITAL_POLL_INTERVAL
));
429 static void digital_wq_poll(struct work_struct
*work
)
432 struct digital_poll_tech
*poll_tech
;
433 struct nfc_digital_dev
*ddev
= container_of(work
,
434 struct nfc_digital_dev
,
436 mutex_lock(&ddev
->poll_lock
);
438 if (!ddev
->poll_tech_count
) {
439 mutex_unlock(&ddev
->poll_lock
);
443 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_index
];
445 mutex_unlock(&ddev
->poll_lock
);
447 rc
= poll_tech
->poll_func(ddev
, poll_tech
->rf_tech
);
449 digital_poll_next_tech(ddev
);
452 static void digital_add_poll_tech(struct nfc_digital_dev
*ddev
, u8 rf_tech
,
453 digital_poll_t poll_func
)
455 struct digital_poll_tech
*poll_tech
;
457 if (ddev
->poll_tech_count
>= NFC_DIGITAL_POLL_MODE_COUNT_MAX
)
460 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_count
++];
462 poll_tech
->rf_tech
= rf_tech
;
463 poll_tech
->poll_func
= poll_func
;
467 * start_poll operation
469 * For every supported protocol, the corresponding polling function is added
470 * to the table of polling technologies (ddev->poll_techs[]) using
471 * digital_add_poll_tech().
472 * When a polling function fails (by timeout or protocol error) the next one is
473 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
475 static int digital_start_poll(struct nfc_dev
*nfc_dev
, __u32 im_protocols
,
478 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
479 u32 matching_im_protocols
, matching_tm_protocols
;
481 pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols
,
482 tm_protocols
, ddev
->protocols
);
484 matching_im_protocols
= ddev
->protocols
& im_protocols
;
485 matching_tm_protocols
= ddev
->protocols
& tm_protocols
;
487 if (!matching_im_protocols
&& !matching_tm_protocols
) {
488 pr_err("Unknown protocol\n");
492 if (ddev
->poll_tech_count
) {
493 pr_err("Already polling\n");
497 if (ddev
->curr_protocol
) {
498 pr_err("A target is already active\n");
502 ddev
->poll_tech_count
= 0;
503 ddev
->poll_tech_index
= 0;
505 if (matching_im_protocols
& DIGITAL_PROTO_NFCA_RF_TECH
)
506 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
507 digital_in_send_sens_req
);
509 if (matching_im_protocols
& DIGITAL_PROTO_NFCB_RF_TECH
)
510 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106B
,
511 digital_in_send_sensb_req
);
513 if (matching_im_protocols
& DIGITAL_PROTO_NFCF_RF_TECH
) {
514 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
515 digital_in_send_sensf_req
);
517 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
518 digital_in_send_sensf_req
);
521 if (matching_im_protocols
& DIGITAL_PROTO_ISO15693_RF_TECH
)
522 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_ISO15693
,
523 digital_in_send_iso15693_inv_req
);
525 if (matching_tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
526 if (ddev
->ops
->tg_listen_mdaa
) {
527 digital_add_poll_tech(ddev
, 0,
528 digital_tg_listen_mdaa
);
529 } else if (ddev
->ops
->tg_listen_md
) {
530 digital_add_poll_tech(ddev
, 0,
531 digital_tg_listen_md
);
533 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
534 digital_tg_listen_nfca
);
536 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
537 digital_tg_listen_nfcf
);
539 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
540 digital_tg_listen_nfcf
);
544 if (!ddev
->poll_tech_count
) {
545 pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n",
546 matching_im_protocols
, matching_tm_protocols
);
550 schedule_delayed_work(&ddev
->poll_work
, 0);
555 static void digital_stop_poll(struct nfc_dev
*nfc_dev
)
557 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
559 mutex_lock(&ddev
->poll_lock
);
561 if (!ddev
->poll_tech_count
) {
562 pr_err("Polling operation was not running\n");
563 mutex_unlock(&ddev
->poll_lock
);
567 ddev
->poll_tech_count
= 0;
569 mutex_unlock(&ddev
->poll_lock
);
571 cancel_delayed_work_sync(&ddev
->poll_work
);
573 digital_abort_cmd(ddev
);
576 static int digital_dev_up(struct nfc_dev
*nfc_dev
)
578 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
580 digital_switch_rf(ddev
, 1);
585 static int digital_dev_down(struct nfc_dev
*nfc_dev
)
587 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
589 digital_switch_rf(ddev
, 0);
594 static int digital_dep_link_up(struct nfc_dev
*nfc_dev
,
595 struct nfc_target
*target
,
596 __u8 comm_mode
, __u8
*gb
, size_t gb_len
)
598 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
601 rc
= digital_in_send_atr_req(ddev
, target
, comm_mode
, gb
, gb_len
);
604 ddev
->curr_protocol
= NFC_PROTO_NFC_DEP
;
609 static int digital_dep_link_down(struct nfc_dev
*nfc_dev
)
611 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
613 ddev
->curr_protocol
= 0;
618 static int digital_activate_target(struct nfc_dev
*nfc_dev
,
619 struct nfc_target
*target
, __u32 protocol
)
621 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
623 if (ddev
->poll_tech_count
) {
624 pr_err("Can't activate a target while polling\n");
628 if (ddev
->curr_protocol
) {
629 pr_err("A target is already active\n");
633 ddev
->curr_protocol
= protocol
;
638 static void digital_deactivate_target(struct nfc_dev
*nfc_dev
,
639 struct nfc_target
*target
,
642 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
644 if (!ddev
->curr_protocol
) {
645 pr_err("No active target\n");
649 ddev
->curr_protocol
= 0;
652 static int digital_tg_send(struct nfc_dev
*dev
, struct sk_buff
*skb
)
654 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(dev
);
656 return digital_tg_send_dep_res(ddev
, skb
);
659 static void digital_in_send_complete(struct nfc_digital_dev
*ddev
, void *arg
,
660 struct sk_buff
*resp
)
662 struct digital_data_exch
*data_exch
= arg
;
671 if (ddev
->curr_protocol
== NFC_PROTO_MIFARE
) {
672 rc
= digital_in_recv_mifare_res(resp
);
673 /* crc check is done in digital_in_recv_mifare_res() */
677 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
678 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
679 rc
= digital_in_iso_dep_pull_sod(ddev
, resp
);
684 rc
= ddev
->skb_check_crc(resp
);
692 data_exch
->cb(data_exch
->cb_context
, resp
, rc
);
697 static int digital_in_send(struct nfc_dev
*nfc_dev
, struct nfc_target
*target
,
698 struct sk_buff
*skb
, data_exchange_cb_t cb
,
701 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
702 struct digital_data_exch
*data_exch
;
705 data_exch
= kzalloc(sizeof(struct digital_data_exch
), GFP_KERNEL
);
707 pr_err("Failed to allocate data_exch struct\n");
712 data_exch
->cb_context
= cb_context
;
714 if (ddev
->curr_protocol
== NFC_PROTO_NFC_DEP
) {
715 rc
= digital_in_send_dep_req(ddev
, target
, skb
, data_exch
);
719 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
720 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
721 rc
= digital_in_iso_dep_push_sod(ddev
, skb
);
726 ddev
->skb_add_crc(skb
);
728 rc
= digital_in_send_cmd(ddev
, skb
, 500, digital_in_send_complete
,
738 static struct nfc_ops digital_nfc_ops
= {
739 .dev_up
= digital_dev_up
,
740 .dev_down
= digital_dev_down
,
741 .start_poll
= digital_start_poll
,
742 .stop_poll
= digital_stop_poll
,
743 .dep_link_up
= digital_dep_link_up
,
744 .dep_link_down
= digital_dep_link_down
,
745 .activate_target
= digital_activate_target
,
746 .deactivate_target
= digital_deactivate_target
,
747 .tm_send
= digital_tg_send
,
748 .im_transceive
= digital_in_send
,
751 struct nfc_digital_dev
*nfc_digital_allocate_device(struct nfc_digital_ops
*ops
,
752 __u32 supported_protocols
,
753 __u32 driver_capabilities
,
754 int tx_headroom
, int tx_tailroom
)
756 struct nfc_digital_dev
*ddev
;
758 if (!ops
->in_configure_hw
|| !ops
->in_send_cmd
|| !ops
->tg_listen
||
759 !ops
->tg_configure_hw
|| !ops
->tg_send_cmd
|| !ops
->abort_cmd
||
760 !ops
->switch_rf
|| (ops
->tg_listen_md
&& !ops
->tg_get_rf_tech
))
763 ddev
= kzalloc(sizeof(struct nfc_digital_dev
), GFP_KERNEL
);
767 ddev
->driver_capabilities
= driver_capabilities
;
770 mutex_init(&ddev
->cmd_lock
);
771 INIT_LIST_HEAD(&ddev
->cmd_queue
);
773 INIT_WORK(&ddev
->cmd_work
, digital_wq_cmd
);
774 INIT_WORK(&ddev
->cmd_complete_work
, digital_wq_cmd_complete
);
776 mutex_init(&ddev
->poll_lock
);
777 INIT_DELAYED_WORK(&ddev
->poll_work
, digital_wq_poll
);
779 if (supported_protocols
& NFC_PROTO_JEWEL_MASK
)
780 ddev
->protocols
|= NFC_PROTO_JEWEL_MASK
;
781 if (supported_protocols
& NFC_PROTO_MIFARE_MASK
)
782 ddev
->protocols
|= NFC_PROTO_MIFARE_MASK
;
783 if (supported_protocols
& NFC_PROTO_FELICA_MASK
)
784 ddev
->protocols
|= NFC_PROTO_FELICA_MASK
;
785 if (supported_protocols
& NFC_PROTO_NFC_DEP_MASK
)
786 ddev
->protocols
|= NFC_PROTO_NFC_DEP_MASK
;
787 if (supported_protocols
& NFC_PROTO_ISO15693_MASK
)
788 ddev
->protocols
|= NFC_PROTO_ISO15693_MASK
;
789 if (supported_protocols
& NFC_PROTO_ISO14443_MASK
)
790 ddev
->protocols
|= NFC_PROTO_ISO14443_MASK
;
791 if (supported_protocols
& NFC_PROTO_ISO14443_B_MASK
)
792 ddev
->protocols
|= NFC_PROTO_ISO14443_B_MASK
;
794 ddev
->tx_headroom
= tx_headroom
+ DIGITAL_MAX_HEADER_LEN
;
795 ddev
->tx_tailroom
= tx_tailroom
+ DIGITAL_CRC_LEN
;
797 ddev
->nfc_dev
= nfc_allocate_device(&digital_nfc_ops
, ddev
->protocols
,
800 if (!ddev
->nfc_dev
) {
801 pr_err("nfc_allocate_device failed\n");
805 nfc_set_drvdata(ddev
->nfc_dev
, ddev
);
814 EXPORT_SYMBOL(nfc_digital_allocate_device
);
816 void nfc_digital_free_device(struct nfc_digital_dev
*ddev
)
818 nfc_free_device(ddev
->nfc_dev
);
821 EXPORT_SYMBOL(nfc_digital_free_device
);
823 int nfc_digital_register_device(struct nfc_digital_dev
*ddev
)
825 return nfc_register_device(ddev
->nfc_dev
);
827 EXPORT_SYMBOL(nfc_digital_register_device
);
829 void nfc_digital_unregister_device(struct nfc_digital_dev
*ddev
)
831 struct digital_cmd
*cmd
, *n
;
833 nfc_unregister_device(ddev
->nfc_dev
);
835 mutex_lock(&ddev
->poll_lock
);
836 ddev
->poll_tech_count
= 0;
837 mutex_unlock(&ddev
->poll_lock
);
839 cancel_delayed_work_sync(&ddev
->poll_work
);
840 cancel_work_sync(&ddev
->cmd_work
);
841 cancel_work_sync(&ddev
->cmd_complete_work
);
843 list_for_each_entry_safe(cmd
, n
, &ddev
->cmd_queue
, queue
) {
844 list_del(&cmd
->queue
);
846 /* Call the command callback if any and pass it a ENODEV error.
847 * This gives a chance to the command issuer to free any
851 cmd
->cmd_cb(ddev
, cmd
->cb_context
, ERR_PTR(-ENODEV
));
853 kfree(cmd
->mdaa_params
);
857 EXPORT_SYMBOL(nfc_digital_unregister_device
);
859 MODULE_LICENSE("GPL");