NFC: NCI: Store the spi device pointer from the spi instance
[deliverable/linux.git] / net / nfc / digital_core.c
CommitLineData
4b10884e
TE
1/*
2 * NFC Digital Protocol stack
3 * Copyright (c) 2013, Intel Corporation.
4 *
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.
8 *
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
12 * more details.
13 *
14 */
15
16#include <linux/module.h>
17
18#include "digital.h"
19
59ee2361 20#define DIGITAL_PROTO_NFCA_RF_TECH \
7d0911c0 21 (NFC_PROTO_JEWEL_MASK | NFC_PROTO_MIFARE_MASK | NFC_PROTO_NFC_DEP_MASK)
59ee2361 22
7d0911c0
TE
23#define DIGITAL_PROTO_NFCF_RF_TECH \
24 (NFC_PROTO_FELICA_MASK | NFC_PROTO_NFC_DEP_MASK)
8c0695e4 25
59ee2361
TE
26struct digital_cmd {
27 struct list_head queue;
28
29 u8 type;
30 u8 pending;
31
32 u16 timeout;
33 struct sk_buff *req;
34 struct sk_buff *resp;
1c7a4c24 35 struct digital_tg_mdaa_params *mdaa_params;
59ee2361
TE
36
37 nfc_digital_cmd_complete_t cmd_cb;
38 void *cb_context;
39};
40
41struct sk_buff *digital_skb_alloc(struct nfc_digital_dev *ddev,
42 unsigned int len)
43{
44 struct sk_buff *skb;
45
46 skb = alloc_skb(len + ddev->tx_headroom + ddev->tx_tailroom,
47 GFP_KERNEL);
48 if (skb)
49 skb_reserve(skb, ddev->tx_headroom);
50
51 return skb;
52}
53
2c66daec
TE
54void digital_skb_add_crc(struct sk_buff *skb, crc_func_t crc_func, u16 init,
55 u8 bitwise_inv, u8 msb_first)
56{
57 u16 crc;
58
59 crc = crc_func(init, skb->data, skb->len);
60
61 if (bitwise_inv)
62 crc = ~crc;
63
64 if (msb_first)
65 crc = __fswab16(crc);
66
67 *skb_put(skb, 1) = crc & 0xFF;
68 *skb_put(skb, 1) = (crc >> 8) & 0xFF;
69}
70
71int digital_skb_check_crc(struct sk_buff *skb, crc_func_t crc_func,
72 u16 crc_init, u8 bitwise_inv, u8 msb_first)
73{
74 int rc;
75 u16 crc;
76
77 if (skb->len <= 2)
78 return -EIO;
79
80 crc = crc_func(crc_init, skb->data, skb->len - 2);
81
82 if (bitwise_inv)
83 crc = ~crc;
84
85 if (msb_first)
86 crc = __swab16(crc);
87
88 rc = (skb->data[skb->len - 2] - (crc & 0xFF)) +
89 (skb->data[skb->len - 1] - ((crc >> 8) & 0xFF));
90
91 if (rc)
92 return -EIO;
93
94 skb_trim(skb, skb->len - 2);
95
96 return 0;
97}
98
59ee2361
TE
99static inline void digital_switch_rf(struct nfc_digital_dev *ddev, bool on)
100{
101 ddev->ops->switch_rf(ddev, on);
102}
103
104static inline void digital_abort_cmd(struct nfc_digital_dev *ddev)
105{
106 ddev->ops->abort_cmd(ddev);
107}
108
109static void digital_wq_cmd_complete(struct work_struct *work)
110{
111 struct digital_cmd *cmd;
112 struct nfc_digital_dev *ddev = container_of(work,
113 struct nfc_digital_dev,
114 cmd_complete_work);
115
116 mutex_lock(&ddev->cmd_lock);
117
118 cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd,
119 queue);
120 if (!cmd) {
121 mutex_unlock(&ddev->cmd_lock);
122 return;
123 }
124
125 list_del(&cmd->queue);
126
127 mutex_unlock(&ddev->cmd_lock);
128
129 if (!IS_ERR(cmd->resp))
130 print_hex_dump_debug("DIGITAL RX: ", DUMP_PREFIX_NONE, 16, 1,
131 cmd->resp->data, cmd->resp->len, false);
132
133 cmd->cmd_cb(ddev, cmd->cb_context, cmd->resp);
134
1c7a4c24 135 kfree(cmd->mdaa_params);
59ee2361
TE
136 kfree(cmd);
137
138 schedule_work(&ddev->cmd_work);
139}
140
141static void digital_send_cmd_complete(struct nfc_digital_dev *ddev,
142 void *arg, struct sk_buff *resp)
143{
144 struct digital_cmd *cmd = arg;
145
146 cmd->resp = resp;
147
148 schedule_work(&ddev->cmd_complete_work);
149}
150
151static void digital_wq_cmd(struct work_struct *work)
152{
153 int rc;
154 struct digital_cmd *cmd;
1c7a4c24 155 struct digital_tg_mdaa_params *params;
59ee2361
TE
156 struct nfc_digital_dev *ddev = container_of(work,
157 struct nfc_digital_dev,
158 cmd_work);
159
160 mutex_lock(&ddev->cmd_lock);
161
162 cmd = list_first_entry_or_null(&ddev->cmd_queue, struct digital_cmd,
163 queue);
164 if (!cmd || cmd->pending) {
165 mutex_unlock(&ddev->cmd_lock);
166 return;
167 }
168
169 mutex_unlock(&ddev->cmd_lock);
170
171 if (cmd->req)
172 print_hex_dump_debug("DIGITAL TX: ", DUMP_PREFIX_NONE, 16, 1,
173 cmd->req->data, cmd->req->len, false);
174
175 switch (cmd->type) {
176 case DIGITAL_CMD_IN_SEND:
177 rc = ddev->ops->in_send_cmd(ddev, cmd->req, cmd->timeout,
178 digital_send_cmd_complete, cmd);
179 break;
1c7a4c24
TE
180
181 case DIGITAL_CMD_TG_SEND:
182 rc = ddev->ops->tg_send_cmd(ddev, cmd->req, cmd->timeout,
183 digital_send_cmd_complete, cmd);
184 break;
185
186 case DIGITAL_CMD_TG_LISTEN:
187 rc = ddev->ops->tg_listen(ddev, cmd->timeout,
188 digital_send_cmd_complete, cmd);
189 break;
190
191 case DIGITAL_CMD_TG_LISTEN_MDAA:
192 params = cmd->mdaa_params;
193
194 rc = ddev->ops->tg_listen_mdaa(ddev, params, cmd->timeout,
195 digital_send_cmd_complete, cmd);
196 break;
197
59ee2361
TE
198 default:
199 PR_ERR("Unknown cmd type %d", cmd->type);
200 return;
201 }
202
203 if (!rc)
204 return;
205
206 PR_ERR("in_send_command returned err %d", rc);
207
208 mutex_lock(&ddev->cmd_lock);
209 list_del(&cmd->queue);
210 mutex_unlock(&ddev->cmd_lock);
211
212 kfree_skb(cmd->req);
1c7a4c24 213 kfree(cmd->mdaa_params);
59ee2361
TE
214 kfree(cmd);
215
216 schedule_work(&ddev->cmd_work);
217}
218
219int digital_send_cmd(struct nfc_digital_dev *ddev, u8 cmd_type,
1c7a4c24
TE
220 struct sk_buff *skb, struct digital_tg_mdaa_params *params,
221 u16 timeout, nfc_digital_cmd_complete_t cmd_cb,
222 void *cb_context)
59ee2361
TE
223{
224 struct digital_cmd *cmd;
225
226 cmd = kzalloc(sizeof(struct digital_cmd), GFP_KERNEL);
227 if (!cmd)
228 return -ENOMEM;
229
230 cmd->type = cmd_type;
231 cmd->timeout = timeout;
232 cmd->req = skb;
1c7a4c24 233 cmd->mdaa_params = params;
59ee2361
TE
234 cmd->cmd_cb = cmd_cb;
235 cmd->cb_context = cb_context;
236 INIT_LIST_HEAD(&cmd->queue);
237
238 mutex_lock(&ddev->cmd_lock);
239 list_add_tail(&cmd->queue, &ddev->cmd_queue);
240 mutex_unlock(&ddev->cmd_lock);
241
242 schedule_work(&ddev->cmd_work);
243
244 return 0;
245}
246
247int digital_in_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
248{
249 int rc;
250
251 rc = ddev->ops->in_configure_hw(ddev, type, param);
252 if (rc)
253 PR_ERR("in_configure_hw failed: %d", rc);
254
255 return rc;
256}
257
1c7a4c24
TE
258int digital_tg_configure_hw(struct nfc_digital_dev *ddev, int type, int param)
259{
260 int rc;
261
262 rc = ddev->ops->tg_configure_hw(ddev, type, param);
263 if (rc)
264 PR_ERR("tg_configure_hw failed: %d", rc);
265
266 return rc;
267}
268
269static int digital_tg_listen_mdaa(struct nfc_digital_dev *ddev, u8 rf_tech)
270{
271 struct digital_tg_mdaa_params *params;
272
273 params = kzalloc(sizeof(struct digital_tg_mdaa_params), GFP_KERNEL);
274 if (!params)
275 return -ENOMEM;
276
277 params->sens_res = DIGITAL_SENS_RES_NFC_DEP;
278 get_random_bytes(params->nfcid1, sizeof(params->nfcid1));
279 params->sel_res = DIGITAL_SEL_RES_NFC_DEP;
280
281 params->nfcid2[0] = DIGITAL_SENSF_NFCID2_NFC_DEP_B1;
282 params->nfcid2[1] = DIGITAL_SENSF_NFCID2_NFC_DEP_B2;
283 get_random_bytes(params->nfcid2 + 2, NFC_NFCID2_MAXSIZE - 2);
284 params->sc = DIGITAL_SENSF_FELICA_SC;
285
286 return digital_send_cmd(ddev, DIGITAL_CMD_TG_LISTEN_MDAA, NULL, params,
287 500, digital_tg_recv_atr_req, NULL);
288}
289
2c66daec
TE
290int digital_target_found(struct nfc_digital_dev *ddev,
291 struct nfc_target *target, u8 protocol)
292{
293 int rc;
294 u8 framing;
295 u8 rf_tech;
296 int (*check_crc)(struct sk_buff *skb);
297 void (*add_crc)(struct sk_buff *skb);
298
299 rf_tech = ddev->poll_techs[ddev->poll_tech_index].rf_tech;
300
301 switch (protocol) {
302 case NFC_PROTO_JEWEL:
303 framing = NFC_DIGITAL_FRAMING_NFCA_T1T;
304 check_crc = digital_skb_check_crc_b;
305 add_crc = digital_skb_add_crc_b;
306 break;
307
308 case NFC_PROTO_MIFARE:
309 framing = NFC_DIGITAL_FRAMING_NFCA_T2T;
310 check_crc = digital_skb_check_crc_a;
311 add_crc = digital_skb_add_crc_a;
312 break;
313
8c0695e4
TE
314 case NFC_PROTO_FELICA:
315 framing = NFC_DIGITAL_FRAMING_NFCF_T3T;
316 check_crc = digital_skb_check_crc_f;
317 add_crc = digital_skb_add_crc_f;
318 break;
319
7d0911c0
TE
320 case NFC_PROTO_NFC_DEP:
321 if (rf_tech == NFC_DIGITAL_RF_TECH_106A) {
322 framing = NFC_DIGITAL_FRAMING_NFCA_NFC_DEP;
323 check_crc = digital_skb_check_crc_a;
324 add_crc = digital_skb_add_crc_a;
325 } else {
326 framing = NFC_DIGITAL_FRAMING_NFCF_NFC_DEP;
327 check_crc = digital_skb_check_crc_f;
328 add_crc = digital_skb_add_crc_f;
329 }
330 break;
331
2c66daec
TE
332 default:
333 PR_ERR("Invalid protocol %d", protocol);
334 return -EINVAL;
335 }
336
337 PR_DBG("rf_tech=%d, protocol=%d", rf_tech, protocol);
338
339 ddev->curr_rf_tech = rf_tech;
340 ddev->curr_protocol = protocol;
341
342 if (DIGITAL_DRV_CAPS_IN_CRC(ddev)) {
343 ddev->skb_add_crc = digital_skb_add_crc_none;
344 ddev->skb_check_crc = digital_skb_check_crc_none;
345 } else {
346 ddev->skb_add_crc = add_crc;
347 ddev->skb_check_crc = check_crc;
348 }
349
350 rc = digital_in_configure_hw(ddev, NFC_DIGITAL_CONFIG_FRAMING, framing);
351 if (rc)
352 return rc;
353
354 target->supported_protocols = (1 << protocol);
355 rc = nfc_targets_found(ddev->nfc_dev, target, 1);
356 if (rc)
357 return rc;
358
359 ddev->poll_tech_count = 0;
360
361 return 0;
362}
363
59ee2361
TE
364void digital_poll_next_tech(struct nfc_digital_dev *ddev)
365{
366 digital_switch_rf(ddev, 0);
367
368 mutex_lock(&ddev->poll_lock);
369
370 if (!ddev->poll_tech_count) {
371 mutex_unlock(&ddev->poll_lock);
372 return;
373 }
374
375 ddev->poll_tech_index = (ddev->poll_tech_index + 1) %
376 ddev->poll_tech_count;
377
378 mutex_unlock(&ddev->poll_lock);
379
380 schedule_work(&ddev->poll_work);
381}
382
383static void digital_wq_poll(struct work_struct *work)
384{
385 int rc;
386 struct digital_poll_tech *poll_tech;
387 struct nfc_digital_dev *ddev = container_of(work,
388 struct nfc_digital_dev,
389 poll_work);
390 mutex_lock(&ddev->poll_lock);
391
392 if (!ddev->poll_tech_count) {
393 mutex_unlock(&ddev->poll_lock);
394 return;
395 }
396
397 poll_tech = &ddev->poll_techs[ddev->poll_tech_index];
398
399 mutex_unlock(&ddev->poll_lock);
400
401 rc = poll_tech->poll_func(ddev, poll_tech->rf_tech);
402 if (rc)
403 digital_poll_next_tech(ddev);
404}
405
406static void digital_add_poll_tech(struct nfc_digital_dev *ddev, u8 rf_tech,
407 digital_poll_t poll_func)
408{
409 struct digital_poll_tech *poll_tech;
410
411 if (ddev->poll_tech_count >= NFC_DIGITAL_POLL_MODE_COUNT_MAX)
412 return;
413
414 poll_tech = &ddev->poll_techs[ddev->poll_tech_count++];
415
416 poll_tech->rf_tech = rf_tech;
417 poll_tech->poll_func = poll_func;
418}
419
420/**
421 * start_poll operation
422 *
423 * For every supported protocol, the corresponding polling function is added
424 * to the table of polling technologies (ddev->poll_techs[]) using
425 * digital_add_poll_tech().
426 * When a polling function fails (by timeout or protocol error) the next one is
427 * schedule by digital_poll_next_tech() on the poll workqueue (ddev->poll_work).
428 */
4b10884e
TE
429static int digital_start_poll(struct nfc_dev *nfc_dev, __u32 im_protocols,
430 __u32 tm_protocols)
431{
59ee2361
TE
432 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
433 u32 matching_im_protocols, matching_tm_protocols;
434
435 PR_DBG("protocols: im 0x%x, tm 0x%x, supported 0x%x", im_protocols,
436 tm_protocols, ddev->protocols);
437
438 matching_im_protocols = ddev->protocols & im_protocols;
439 matching_tm_protocols = ddev->protocols & tm_protocols;
440
441 if (!matching_im_protocols && !matching_tm_protocols) {
442 PR_ERR("No known protocol");
443 return -EINVAL;
444 }
445
446 if (ddev->poll_tech_count) {
447 PR_ERR("Already polling");
448 return -EBUSY;
449 }
450
451 if (ddev->curr_protocol) {
452 PR_ERR("A target is already active");
453 return -EBUSY;
454 }
455
456 ddev->poll_tech_count = 0;
457 ddev->poll_tech_index = 0;
458
459 if (matching_im_protocols & DIGITAL_PROTO_NFCA_RF_TECH)
460 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A,
461 digital_in_send_sens_req);
462
8c0695e4
TE
463 if (im_protocols & DIGITAL_PROTO_NFCF_RF_TECH) {
464 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F,
465 digital_in_send_sensf_req);
466
467 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F,
468 digital_in_send_sensf_req);
469 }
470
1c7a4c24
TE
471 if (tm_protocols & NFC_PROTO_NFC_DEP_MASK) {
472 if (ddev->ops->tg_listen_mdaa) {
473 digital_add_poll_tech(ddev, 0,
474 digital_tg_listen_mdaa);
475 } else {
476 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_106A,
477 digital_tg_listen_nfca);
478
479 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_212F,
480 digital_tg_listen_nfcf);
481
482 digital_add_poll_tech(ddev, NFC_DIGITAL_RF_TECH_424F,
483 digital_tg_listen_nfcf);
484 }
485 }
486
59ee2361
TE
487 if (!ddev->poll_tech_count) {
488 PR_ERR("Unsupported protocols: im=0x%x, tm=0x%x",
489 matching_im_protocols, matching_tm_protocols);
490 return -EINVAL;
491 }
492
493 schedule_work(&ddev->poll_work);
494
495 return 0;
4b10884e
TE
496}
497
498static void digital_stop_poll(struct nfc_dev *nfc_dev)
499{
59ee2361
TE
500 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
501
502 mutex_lock(&ddev->poll_lock);
503
504 if (!ddev->poll_tech_count) {
505 PR_ERR("Polling operation was not running");
506 mutex_unlock(&ddev->poll_lock);
507 return;
508 }
509
510 ddev->poll_tech_count = 0;
511
512 mutex_unlock(&ddev->poll_lock);
513
514 cancel_work_sync(&ddev->poll_work);
515
516 digital_abort_cmd(ddev);
4b10884e
TE
517}
518
519static int digital_dev_up(struct nfc_dev *nfc_dev)
520{
59ee2361
TE
521 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
522
523 digital_switch_rf(ddev, 1);
524
525 return 0;
4b10884e
TE
526}
527
528static int digital_dev_down(struct nfc_dev *nfc_dev)
529{
59ee2361
TE
530 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
531
532 digital_switch_rf(ddev, 0);
533
534 return 0;
4b10884e
TE
535}
536
537static int digital_dep_link_up(struct nfc_dev *nfc_dev,
538 struct nfc_target *target,
539 __u8 comm_mode, __u8 *gb, size_t gb_len)
540{
7d0911c0
TE
541 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
542
543 return digital_in_send_atr_req(ddev, target, comm_mode, gb, gb_len);
4b10884e
TE
544}
545
546static int digital_dep_link_down(struct nfc_dev *nfc_dev)
547{
7d0911c0
TE
548 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
549
550 ddev->curr_protocol = 0;
551
552 return 0;
4b10884e
TE
553}
554
555static int digital_activate_target(struct nfc_dev *nfc_dev,
556 struct nfc_target *target, __u32 protocol)
557{
59ee2361 558 return 0;
4b10884e
TE
559}
560
561static void digital_deactivate_target(struct nfc_dev *nfc_dev,
562 struct nfc_target *target)
563{
59ee2361
TE
564 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
565
566 ddev->curr_protocol = 0;
4b10884e
TE
567}
568
569static int digital_tg_send(struct nfc_dev *dev, struct sk_buff *skb)
570{
1c7a4c24
TE
571 struct nfc_digital_dev *ddev = nfc_get_drvdata(dev);
572
573 return digital_tg_send_dep_res(ddev, skb);
4b10884e
TE
574}
575
2c66daec
TE
576static void digital_in_send_complete(struct nfc_digital_dev *ddev, void *arg,
577 struct sk_buff *resp)
578{
579 struct digital_data_exch *data_exch = arg;
580 int rc;
581
582 if (IS_ERR(resp)) {
583 rc = PTR_ERR(resp);
584 goto done;
585 }
586
587 if (ddev->curr_protocol == NFC_PROTO_MIFARE)
588 rc = digital_in_recv_mifare_res(resp);
589 else
590 rc = ddev->skb_check_crc(resp);
591
592 if (rc) {
593 kfree_skb(resp);
594 resp = NULL;
595 }
596
597done:
598 data_exch->cb(data_exch->cb_context, resp, rc);
599
600 kfree(data_exch);
601}
602
4b10884e
TE
603static int digital_in_send(struct nfc_dev *nfc_dev, struct nfc_target *target,
604 struct sk_buff *skb, data_exchange_cb_t cb,
605 void *cb_context)
606{
2c66daec
TE
607 struct nfc_digital_dev *ddev = nfc_get_drvdata(nfc_dev);
608 struct digital_data_exch *data_exch;
609
610 data_exch = kzalloc(sizeof(struct digital_data_exch), GFP_KERNEL);
611 if (!data_exch) {
612 PR_ERR("Failed to allocate data_exch struct");
613 return -ENOMEM;
614 }
615
616 data_exch->cb = cb;
617 data_exch->cb_context = cb_context;
618
7d0911c0
TE
619 if (ddev->curr_protocol == NFC_PROTO_NFC_DEP)
620 return digital_in_send_dep_req(ddev, target, skb, data_exch);
621
2c66daec
TE
622 ddev->skb_add_crc(skb);
623
624 return digital_in_send_cmd(ddev, skb, 500, digital_in_send_complete,
625 data_exch);
4b10884e
TE
626}
627
628static struct nfc_ops digital_nfc_ops = {
629 .dev_up = digital_dev_up,
630 .dev_down = digital_dev_down,
631 .start_poll = digital_start_poll,
632 .stop_poll = digital_stop_poll,
633 .dep_link_up = digital_dep_link_up,
634 .dep_link_down = digital_dep_link_down,
635 .activate_target = digital_activate_target,
636 .deactivate_target = digital_deactivate_target,
637 .tm_send = digital_tg_send,
638 .im_transceive = digital_in_send,
639};
640
641struct nfc_digital_dev *nfc_digital_allocate_device(struct nfc_digital_ops *ops,
642 __u32 supported_protocols,
643 __u32 driver_capabilities,
644 int tx_headroom, int tx_tailroom)
645{
646 struct nfc_digital_dev *ddev;
647
648 if (!ops->in_configure_hw || !ops->in_send_cmd || !ops->tg_listen ||
649 !ops->tg_configure_hw || !ops->tg_send_cmd || !ops->abort_cmd ||
650 !ops->switch_rf)
651 return NULL;
652
653 ddev = kzalloc(sizeof(struct nfc_digital_dev), GFP_KERNEL);
654 if (!ddev) {
655 PR_ERR("kzalloc failed");
656 return NULL;
657 }
658
659 ddev->driver_capabilities = driver_capabilities;
660 ddev->ops = ops;
661
59ee2361
TE
662 mutex_init(&ddev->cmd_lock);
663 INIT_LIST_HEAD(&ddev->cmd_queue);
664
665 INIT_WORK(&ddev->cmd_work, digital_wq_cmd);
666 INIT_WORK(&ddev->cmd_complete_work, digital_wq_cmd_complete);
667
668 mutex_init(&ddev->poll_lock);
669 INIT_WORK(&ddev->poll_work, digital_wq_poll);
670
671 if (supported_protocols & NFC_PROTO_JEWEL_MASK)
672 ddev->protocols |= NFC_PROTO_JEWEL_MASK;
673 if (supported_protocols & NFC_PROTO_MIFARE_MASK)
674 ddev->protocols |= NFC_PROTO_MIFARE_MASK;
8c0695e4
TE
675 if (supported_protocols & NFC_PROTO_FELICA_MASK)
676 ddev->protocols |= NFC_PROTO_FELICA_MASK;
7d0911c0
TE
677 if (supported_protocols & NFC_PROTO_NFC_DEP_MASK)
678 ddev->protocols |= NFC_PROTO_NFC_DEP_MASK;
59ee2361
TE
679
680 ddev->tx_headroom = tx_headroom + DIGITAL_MAX_HEADER_LEN;
681 ddev->tx_tailroom = tx_tailroom + DIGITAL_CRC_LEN;
4b10884e
TE
682
683 ddev->nfc_dev = nfc_allocate_device(&digital_nfc_ops, ddev->protocols,
684 ddev->tx_headroom,
685 ddev->tx_tailroom);
686 if (!ddev->nfc_dev) {
687 PR_ERR("nfc_allocate_device failed");
688 goto free_dev;
689 }
690
691 nfc_set_drvdata(ddev->nfc_dev, ddev);
692
693 return ddev;
694
695free_dev:
696 kfree(ddev);
697
698 return NULL;
699}
700EXPORT_SYMBOL(nfc_digital_allocate_device);
701
702void nfc_digital_free_device(struct nfc_digital_dev *ddev)
703{
704 nfc_free_device(ddev->nfc_dev);
4b10884e
TE
705 kfree(ddev);
706}
707EXPORT_SYMBOL(nfc_digital_free_device);
708
709int nfc_digital_register_device(struct nfc_digital_dev *ddev)
710{
711 return nfc_register_device(ddev->nfc_dev);
712}
713EXPORT_SYMBOL(nfc_digital_register_device);
714
715void nfc_digital_unregister_device(struct nfc_digital_dev *ddev)
716{
59ee2361
TE
717 struct digital_cmd *cmd, *n;
718
4b10884e 719 nfc_unregister_device(ddev->nfc_dev);
59ee2361
TE
720
721 mutex_lock(&ddev->poll_lock);
722 ddev->poll_tech_count = 0;
723 mutex_unlock(&ddev->poll_lock);
724
725 cancel_work_sync(&ddev->poll_work);
726 cancel_work_sync(&ddev->cmd_work);
727 cancel_work_sync(&ddev->cmd_complete_work);
728
729 list_for_each_entry_safe(cmd, n, &ddev->cmd_queue, queue) {
730 list_del(&cmd->queue);
1c7a4c24 731 kfree(cmd->mdaa_params);
59ee2361
TE
732 kfree(cmd);
733 }
4b10884e
TE
734}
735EXPORT_SYMBOL(nfc_digital_unregister_device);
736
737MODULE_LICENSE("GPL");
This page took 0.052304 seconds and 5 git commands to generate.