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
);
204 case DIGITAL_CMD_TG_LISTEN_MD
:
205 rc
= ddev
->ops
->tg_listen_md(ddev
, cmd
->timeout
,
206 digital_send_cmd_complete
, cmd
);
210 pr_err("Unknown cmd type %d\n", cmd
->type
);
217 pr_err("in_send_command returned err %d\n", rc
);
219 mutex_lock(&ddev
->cmd_lock
);
220 list_del(&cmd
->queue
);
221 mutex_unlock(&ddev
->cmd_lock
);
224 kfree(cmd
->mdaa_params
);
227 schedule_work(&ddev
->cmd_work
);
230 int digital_send_cmd(struct nfc_digital_dev
*ddev
, u8 cmd_type
,
231 struct sk_buff
*skb
, struct digital_tg_mdaa_params
*params
,
232 u16 timeout
, nfc_digital_cmd_complete_t cmd_cb
,
235 struct digital_cmd
*cmd
;
237 cmd
= kzalloc(sizeof(struct digital_cmd
), GFP_KERNEL
);
241 cmd
->type
= cmd_type
;
242 cmd
->timeout
= timeout
;
244 cmd
->mdaa_params
= params
;
245 cmd
->cmd_cb
= cmd_cb
;
246 cmd
->cb_context
= cb_context
;
247 INIT_LIST_HEAD(&cmd
->queue
);
249 mutex_lock(&ddev
->cmd_lock
);
250 list_add_tail(&cmd
->queue
, &ddev
->cmd_queue
);
251 mutex_unlock(&ddev
->cmd_lock
);
253 schedule_work(&ddev
->cmd_work
);
258 int digital_in_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
262 rc
= ddev
->ops
->in_configure_hw(ddev
, type
, param
);
264 pr_err("in_configure_hw failed: %d\n", rc
);
269 int digital_tg_configure_hw(struct nfc_digital_dev
*ddev
, int type
, int param
)
273 rc
= ddev
->ops
->tg_configure_hw(ddev
, type
, param
);
275 pr_err("tg_configure_hw failed: %d\n", rc
);
280 static int digital_tg_listen_mdaa(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
282 struct digital_tg_mdaa_params
*params
;
284 params
= kzalloc(sizeof(struct digital_tg_mdaa_params
), GFP_KERNEL
);
288 params
->sens_res
= DIGITAL_SENS_RES_NFC_DEP
;
289 get_random_bytes(params
->nfcid1
, sizeof(params
->nfcid1
));
290 params
->sel_res
= DIGITAL_SEL_RES_NFC_DEP
;
292 params
->nfcid2
[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1
;
293 params
->nfcid2
[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2
;
294 get_random_bytes(params
->nfcid2
+ 2, NFC_NFCID2_MAXSIZE
- 2);
295 params
->sc
= DIGITAL_SENSF_FELICA_SC
;
297 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MDAA
, NULL
, params
,
298 500, digital_tg_recv_atr_req
, NULL
);
301 static int digital_tg_listen_md(struct nfc_digital_dev
*ddev
, u8 rf_tech
)
303 return digital_send_cmd(ddev
, DIGITAL_CMD_TG_LISTEN_MD
, NULL
, NULL
, 500,
304 digital_tg_recv_md_req
, NULL
);
307 int digital_target_found(struct nfc_digital_dev
*ddev
,
308 struct nfc_target
*target
, u8 protocol
)
314 int (*check_crc
)(struct sk_buff
*skb
);
315 void (*add_crc
)(struct sk_buff
*skb
);
317 rf_tech
= ddev
->poll_techs
[ddev
->poll_tech_index
].rf_tech
;
320 case NFC_PROTO_JEWEL
:
321 framing
= NFC_DIGITAL_FRAMING_NFCA_T1T
;
322 check_crc
= digital_skb_check_crc_b
;
323 add_crc
= digital_skb_add_crc_b
;
326 case NFC_PROTO_MIFARE
:
327 framing
= NFC_DIGITAL_FRAMING_NFCA_T2T
;
328 check_crc
= digital_skb_check_crc_a
;
329 add_crc
= digital_skb_add_crc_a
;
332 case NFC_PROTO_FELICA
:
333 framing
= NFC_DIGITAL_FRAMING_NFCF_T3T
;
334 check_crc
= digital_skb_check_crc_f
;
335 add_crc
= digital_skb_add_crc_f
;
338 case NFC_PROTO_NFC_DEP
:
339 if (rf_tech
== NFC_DIGITAL_RF_TECH_106A
) {
340 framing
= NFC_DIGITAL_FRAMING_NFCA_NFC_DEP
;
341 check_crc
= digital_skb_check_crc_a
;
342 add_crc
= digital_skb_add_crc_a
;
344 framing
= NFC_DIGITAL_FRAMING_NFCF_NFC_DEP
;
345 check_crc
= digital_skb_check_crc_f
;
346 add_crc
= digital_skb_add_crc_f
;
350 case NFC_PROTO_ISO15693
:
351 framing
= NFC_DIGITAL_FRAMING_ISO15693_T5T
;
352 check_crc
= digital_skb_check_crc_b
;
353 add_crc
= digital_skb_add_crc_b
;
356 case NFC_PROTO_ISO14443
:
357 framing
= NFC_DIGITAL_FRAMING_NFCA_T4T
;
358 check_crc
= digital_skb_check_crc_a
;
359 add_crc
= digital_skb_add_crc_a
;
362 case NFC_PROTO_ISO14443_B
:
363 framing
= NFC_DIGITAL_FRAMING_NFCB_T4T
;
364 check_crc
= digital_skb_check_crc_b
;
365 add_crc
= digital_skb_add_crc_b
;
369 pr_err("Invalid protocol %d\n", protocol
);
373 pr_debug("rf_tech=%d, protocol=%d\n", rf_tech
, protocol
);
375 ddev
->curr_rf_tech
= rf_tech
;
377 if (DIGITAL_DRV_CAPS_IN_CRC(ddev
)) {
378 ddev
->skb_add_crc
= digital_skb_add_crc_none
;
379 ddev
->skb_check_crc
= digital_skb_check_crc_none
;
381 ddev
->skb_add_crc
= add_crc
;
382 ddev
->skb_check_crc
= check_crc
;
385 rc
= digital_in_configure_hw(ddev
, NFC_DIGITAL_CONFIG_FRAMING
, framing
);
389 target
->supported_protocols
= (1 << protocol
);
391 poll_tech_count
= ddev
->poll_tech_count
;
392 ddev
->poll_tech_count
= 0;
394 rc
= nfc_targets_found(ddev
->nfc_dev
, target
, 1);
396 ddev
->poll_tech_count
= poll_tech_count
;
403 void digital_poll_next_tech(struct nfc_digital_dev
*ddev
)
407 digital_switch_rf(ddev
, 0);
409 mutex_lock(&ddev
->poll_lock
);
411 if (!ddev
->poll_tech_count
) {
412 mutex_unlock(&ddev
->poll_lock
);
416 get_random_bytes(&rand_mod
, sizeof(rand_mod
));
417 ddev
->poll_tech_index
= rand_mod
% ddev
->poll_tech_count
;
419 mutex_unlock(&ddev
->poll_lock
);
421 schedule_work(&ddev
->poll_work
);
424 static void digital_wq_poll(struct work_struct
*work
)
427 struct digital_poll_tech
*poll_tech
;
428 struct nfc_digital_dev
*ddev
= container_of(work
,
429 struct nfc_digital_dev
,
431 mutex_lock(&ddev
->poll_lock
);
433 if (!ddev
->poll_tech_count
) {
434 mutex_unlock(&ddev
->poll_lock
);
438 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_index
];
440 mutex_unlock(&ddev
->poll_lock
);
442 rc
= poll_tech
->poll_func(ddev
, poll_tech
->rf_tech
);
444 digital_poll_next_tech(ddev
);
447 static void digital_add_poll_tech(struct nfc_digital_dev
*ddev
, u8 rf_tech
,
448 digital_poll_t poll_func
)
450 struct digital_poll_tech
*poll_tech
;
452 if (ddev
->poll_tech_count
>= NFC_DIGITAL_POLL_MODE_COUNT_MAX
)
455 poll_tech
= &ddev
->poll_techs
[ddev
->poll_tech_count
++];
457 poll_tech
->rf_tech
= rf_tech
;
458 poll_tech
->poll_func
= poll_func
;
462 * start_poll operation
464 * For every supported protocol, the corresponding polling function is added
465 * to the table of polling technologies (ddev->poll_techs[]) using
466 * digital_add_poll_tech().
467 * When a polling function fails (by timeout or protocol error) the next one is
468 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
470 static int digital_start_poll(struct nfc_dev
*nfc_dev
, __u32 im_protocols
,
473 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
474 u32 matching_im_protocols
, matching_tm_protocols
;
476 pr_debug("protocols: im 0x%x, tm 0x%x, supported 0x%x\n", im_protocols
,
477 tm_protocols
, ddev
->protocols
);
479 matching_im_protocols
= ddev
->protocols
& im_protocols
;
480 matching_tm_protocols
= ddev
->protocols
& tm_protocols
;
482 if (!matching_im_protocols
&& !matching_tm_protocols
) {
483 pr_err("Unknown protocol\n");
487 if (ddev
->poll_tech_count
) {
488 pr_err("Already polling\n");
492 if (ddev
->curr_protocol
) {
493 pr_err("A target is already active\n");
497 ddev
->poll_tech_count
= 0;
498 ddev
->poll_tech_index
= 0;
500 if (matching_im_protocols
& DIGITAL_PROTO_NFCA_RF_TECH
)
501 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
502 digital_in_send_sens_req
);
504 if (matching_im_protocols
& DIGITAL_PROTO_NFCB_RF_TECH
)
505 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106B
,
506 digital_in_send_sensb_req
);
508 if (matching_im_protocols
& DIGITAL_PROTO_NFCF_RF_TECH
) {
509 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
510 digital_in_send_sensf_req
);
512 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
513 digital_in_send_sensf_req
);
516 if (matching_im_protocols
& DIGITAL_PROTO_ISO15693_RF_TECH
)
517 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_ISO15693
,
518 digital_in_send_iso15693_inv_req
);
520 if (matching_tm_protocols
& NFC_PROTO_NFC_DEP_MASK
) {
521 if (ddev
->ops
->tg_listen_mdaa
) {
522 digital_add_poll_tech(ddev
, 0,
523 digital_tg_listen_mdaa
);
524 } else if (ddev
->ops
->tg_listen_md
) {
525 digital_add_poll_tech(ddev
, 0,
526 digital_tg_listen_md
);
528 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_106A
,
529 digital_tg_listen_nfca
);
531 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_212F
,
532 digital_tg_listen_nfcf
);
534 digital_add_poll_tech(ddev
, NFC_DIGITAL_RF_TECH_424F
,
535 digital_tg_listen_nfcf
);
539 if (!ddev
->poll_tech_count
) {
540 pr_err("Unsupported protocols: im=0x%x, tm=0x%x\n",
541 matching_im_protocols
, matching_tm_protocols
);
545 schedule_work(&ddev
->poll_work
);
550 static void digital_stop_poll(struct nfc_dev
*nfc_dev
)
552 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
554 mutex_lock(&ddev
->poll_lock
);
556 if (!ddev
->poll_tech_count
) {
557 pr_err("Polling operation was not running\n");
558 mutex_unlock(&ddev
->poll_lock
);
562 ddev
->poll_tech_count
= 0;
564 mutex_unlock(&ddev
->poll_lock
);
566 cancel_work_sync(&ddev
->poll_work
);
568 digital_abort_cmd(ddev
);
571 static int digital_dev_up(struct nfc_dev
*nfc_dev
)
573 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
575 digital_switch_rf(ddev
, 1);
580 static int digital_dev_down(struct nfc_dev
*nfc_dev
)
582 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
584 digital_switch_rf(ddev
, 0);
589 static int digital_dep_link_up(struct nfc_dev
*nfc_dev
,
590 struct nfc_target
*target
,
591 __u8 comm_mode
, __u8
*gb
, size_t gb_len
)
593 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
596 rc
= digital_in_send_atr_req(ddev
, target
, comm_mode
, gb
, gb_len
);
599 ddev
->curr_protocol
= NFC_PROTO_NFC_DEP
;
604 static int digital_dep_link_down(struct nfc_dev
*nfc_dev
)
606 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
608 ddev
->curr_protocol
= 0;
613 static int digital_activate_target(struct nfc_dev
*nfc_dev
,
614 struct nfc_target
*target
, __u32 protocol
)
616 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
618 if (ddev
->poll_tech_count
) {
619 pr_err("Can't activate a target while polling\n");
623 if (ddev
->curr_protocol
) {
624 pr_err("A target is already active\n");
628 ddev
->curr_protocol
= protocol
;
633 static void digital_deactivate_target(struct nfc_dev
*nfc_dev
,
634 struct nfc_target
*target
)
636 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
638 if (!ddev
->curr_protocol
) {
639 pr_err("No active target\n");
643 ddev
->curr_protocol
= 0;
646 static int digital_tg_send(struct nfc_dev
*dev
, struct sk_buff
*skb
)
648 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(dev
);
650 return digital_tg_send_dep_res(ddev
, skb
);
653 static void digital_in_send_complete(struct nfc_digital_dev
*ddev
, void *arg
,
654 struct sk_buff
*resp
)
656 struct digital_data_exch
*data_exch
= arg
;
665 if (ddev
->curr_protocol
== NFC_PROTO_MIFARE
) {
666 rc
= digital_in_recv_mifare_res(resp
);
667 /* crc check is done in digital_in_recv_mifare_res() */
671 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
672 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
673 rc
= digital_in_iso_dep_pull_sod(ddev
, resp
);
678 rc
= ddev
->skb_check_crc(resp
);
686 data_exch
->cb(data_exch
->cb_context
, resp
, rc
);
691 static int digital_in_send(struct nfc_dev
*nfc_dev
, struct nfc_target
*target
,
692 struct sk_buff
*skb
, data_exchange_cb_t cb
,
695 struct nfc_digital_dev
*ddev
= nfc_get_drvdata(nfc_dev
);
696 struct digital_data_exch
*data_exch
;
699 data_exch
= kzalloc(sizeof(struct digital_data_exch
), GFP_KERNEL
);
701 pr_err("Failed to allocate data_exch struct\n");
706 data_exch
->cb_context
= cb_context
;
708 if (ddev
->curr_protocol
== NFC_PROTO_NFC_DEP
) {
709 rc
= digital_in_send_dep_req(ddev
, target
, skb
, data_exch
);
713 if ((ddev
->curr_protocol
== NFC_PROTO_ISO14443
) ||
714 (ddev
->curr_protocol
== NFC_PROTO_ISO14443_B
)) {
715 rc
= digital_in_iso_dep_push_sod(ddev
, skb
);
720 ddev
->skb_add_crc(skb
);
722 rc
= digital_in_send_cmd(ddev
, skb
, 500, digital_in_send_complete
,
732 static struct nfc_ops digital_nfc_ops
= {
733 .dev_up
= digital_dev_up
,
734 .dev_down
= digital_dev_down
,
735 .start_poll
= digital_start_poll
,
736 .stop_poll
= digital_stop_poll
,
737 .dep_link_up
= digital_dep_link_up
,
738 .dep_link_down
= digital_dep_link_down
,
739 .activate_target
= digital_activate_target
,
740 .deactivate_target
= digital_deactivate_target
,
741 .tm_send
= digital_tg_send
,
742 .im_transceive
= digital_in_send
,
745 struct nfc_digital_dev
*nfc_digital_allocate_device(struct nfc_digital_ops
*ops
,
746 __u32 supported_protocols
,
747 __u32 driver_capabilities
,
748 int tx_headroom
, int tx_tailroom
)
750 struct nfc_digital_dev
*ddev
;
752 if (!ops
->in_configure_hw
|| !ops
->in_send_cmd
|| !ops
->tg_listen
||
753 !ops
->tg_configure_hw
|| !ops
->tg_send_cmd
|| !ops
->abort_cmd
||
754 !ops
->switch_rf
|| (ops
->tg_listen_md
&& !ops
->tg_get_rf_tech
))
757 ddev
= kzalloc(sizeof(struct nfc_digital_dev
), GFP_KERNEL
);
761 ddev
->driver_capabilities
= driver_capabilities
;
764 mutex_init(&ddev
->cmd_lock
);
765 INIT_LIST_HEAD(&ddev
->cmd_queue
);
767 INIT_WORK(&ddev
->cmd_work
, digital_wq_cmd
);
768 INIT_WORK(&ddev
->cmd_complete_work
, digital_wq_cmd_complete
);
770 mutex_init(&ddev
->poll_lock
);
771 INIT_WORK(&ddev
->poll_work
, digital_wq_poll
);
773 if (supported_protocols
& NFC_PROTO_JEWEL_MASK
)
774 ddev
->protocols
|= NFC_PROTO_JEWEL_MASK
;
775 if (supported_protocols
& NFC_PROTO_MIFARE_MASK
)
776 ddev
->protocols
|= NFC_PROTO_MIFARE_MASK
;
777 if (supported_protocols
& NFC_PROTO_FELICA_MASK
)
778 ddev
->protocols
|= NFC_PROTO_FELICA_MASK
;
779 if (supported_protocols
& NFC_PROTO_NFC_DEP_MASK
)
780 ddev
->protocols
|= NFC_PROTO_NFC_DEP_MASK
;
781 if (supported_protocols
& NFC_PROTO_ISO15693_MASK
)
782 ddev
->protocols
|= NFC_PROTO_ISO15693_MASK
;
783 if (supported_protocols
& NFC_PROTO_ISO14443_MASK
)
784 ddev
->protocols
|= NFC_PROTO_ISO14443_MASK
;
785 if (supported_protocols
& NFC_PROTO_ISO14443_B_MASK
)
786 ddev
->protocols
|= NFC_PROTO_ISO14443_B_MASK
;
788 ddev
->tx_headroom
= tx_headroom
+ DIGITAL_MAX_HEADER_LEN
;
789 ddev
->tx_tailroom
= tx_tailroom
+ DIGITAL_CRC_LEN
;
791 ddev
->nfc_dev
= nfc_allocate_device(&digital_nfc_ops
, ddev
->protocols
,
794 if (!ddev
->nfc_dev
) {
795 pr_err("nfc_allocate_device failed\n");
799 nfc_set_drvdata(ddev
->nfc_dev
, ddev
);
808 EXPORT_SYMBOL(nfc_digital_allocate_device
);
810 void nfc_digital_free_device(struct nfc_digital_dev
*ddev
)
812 nfc_free_device(ddev
->nfc_dev
);
815 EXPORT_SYMBOL(nfc_digital_free_device
);
817 int nfc_digital_register_device(struct nfc_digital_dev
*ddev
)
819 return nfc_register_device(ddev
->nfc_dev
);
821 EXPORT_SYMBOL(nfc_digital_register_device
);
823 void nfc_digital_unregister_device(struct nfc_digital_dev
*ddev
)
825 struct digital_cmd
*cmd
, *n
;
827 nfc_unregister_device(ddev
->nfc_dev
);
829 mutex_lock(&ddev
->poll_lock
);
830 ddev
->poll_tech_count
= 0;
831 mutex_unlock(&ddev
->poll_lock
);
833 cancel_work_sync(&ddev
->poll_work
);
834 cancel_work_sync(&ddev
->cmd_work
);
835 cancel_work_sync(&ddev
->cmd_complete_work
);
837 list_for_each_entry_safe(cmd
, n
, &ddev
->cmd_queue
, queue
) {
838 list_del(&cmd
->queue
);
839 kfree(cmd
->mdaa_params
);
843 EXPORT_SYMBOL(nfc_digital_unregister_device
);
845 MODULE_LICENSE("GPL");