diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/nfc/nfcsim.c | 6 | ||||
-rw-r--r-- | drivers/nfc/pn533.c | 389 | ||||
-rw-r--r-- | drivers/nfc/pn544/i2c.c | 360 | ||||
-rw-r--r-- | drivers/nfc/pn544/mei.c | 2 | ||||
-rw-r--r-- | drivers/nfc/pn544/pn544.c | 20 | ||||
-rw-r--r-- | drivers/nfc/pn544/pn544.h | 7 |
6 files changed, 672 insertions, 112 deletions
diff --git a/drivers/nfc/nfcsim.c b/drivers/nfc/nfcsim.c index c5c30fb1d7bf..9a53f13c88df 100644 --- a/drivers/nfc/nfcsim.c +++ b/drivers/nfc/nfcsim.c | |||
@@ -60,7 +60,7 @@ struct nfcsim { | |||
60 | static struct nfcsim *dev0; | 60 | static struct nfcsim *dev0; |
61 | static struct nfcsim *dev1; | 61 | static struct nfcsim *dev1; |
62 | 62 | ||
63 | struct workqueue_struct *wq; | 63 | static struct workqueue_struct *wq; |
64 | 64 | ||
65 | static void nfcsim_cleanup_dev(struct nfcsim *dev, u8 shutdown) | 65 | static void nfcsim_cleanup_dev(struct nfcsim *dev, u8 shutdown) |
66 | { | 66 | { |
@@ -481,7 +481,7 @@ static void nfcsim_free_device(struct nfcsim *dev) | |||
481 | kfree(dev); | 481 | kfree(dev); |
482 | } | 482 | } |
483 | 483 | ||
484 | int __init nfcsim_init(void) | 484 | static int __init nfcsim_init(void) |
485 | { | 485 | { |
486 | int rc; | 486 | int rc; |
487 | 487 | ||
@@ -522,7 +522,7 @@ exit: | |||
522 | return rc; | 522 | return rc; |
523 | } | 523 | } |
524 | 524 | ||
525 | void __exit nfcsim_exit(void) | 525 | static void __exit nfcsim_exit(void) |
526 | { | 526 | { |
527 | nfcsim_cleanup_dev(dev0, 1); | 527 | nfcsim_cleanup_dev(dev0, 1); |
528 | nfcsim_cleanup_dev(dev1, 1); | 528 | nfcsim_cleanup_dev(dev1, 1); |
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c index daf92ac209f8..5df730be88a3 100644 --- a/drivers/nfc/pn533.c +++ b/drivers/nfc/pn533.c | |||
@@ -83,12 +83,20 @@ MODULE_DEVICE_TABLE(usb, pn533_table); | |||
83 | 83 | ||
84 | /* How much time we spend listening for initiators */ | 84 | /* How much time we spend listening for initiators */ |
85 | #define PN533_LISTEN_TIME 2 | 85 | #define PN533_LISTEN_TIME 2 |
86 | /* Delay between each poll frame (ms) */ | ||
87 | #define PN533_POLL_INTERVAL 10 | ||
86 | 88 | ||
87 | /* Standard pn533 frame definitions */ | 89 | /* Standard pn533 frame definitions (standard and extended)*/ |
88 | #define PN533_STD_FRAME_HEADER_LEN (sizeof(struct pn533_std_frame) \ | 90 | #define PN533_STD_FRAME_HEADER_LEN (sizeof(struct pn533_std_frame) \ |
89 | + 2) /* data[0] TFI, data[1] CC */ | 91 | + 2) /* data[0] TFI, data[1] CC */ |
90 | #define PN533_STD_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/ | 92 | #define PN533_STD_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/ |
91 | 93 | ||
94 | #define PN533_EXT_FRAME_HEADER_LEN (sizeof(struct pn533_ext_frame) \ | ||
95 | + 2) /* data[0] TFI, data[1] CC */ | ||
96 | |||
97 | #define PN533_CMD_DATAEXCH_DATA_MAXLEN 262 | ||
98 | #define PN533_CMD_DATAFRAME_MAXLEN 240 /* max data length (send) */ | ||
99 | |||
92 | /* | 100 | /* |
93 | * Max extended frame payload len, excluding TFI and CC | 101 | * Max extended frame payload len, excluding TFI and CC |
94 | * which are already in PN533_FRAME_HEADER_LEN. | 102 | * which are already in PN533_FRAME_HEADER_LEN. |
@@ -99,6 +107,10 @@ MODULE_DEVICE_TABLE(usb, pn533_table); | |||
99 | Postamble (1) */ | 107 | Postamble (1) */ |
100 | #define PN533_STD_FRAME_CHECKSUM(f) (f->data[f->datalen]) | 108 | #define PN533_STD_FRAME_CHECKSUM(f) (f->data[f->datalen]) |
101 | #define PN533_STD_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1]) | 109 | #define PN533_STD_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1]) |
110 | /* Half start code (3), LEN (4) should be 0xffff for extended frame */ | ||
111 | #define PN533_STD_IS_EXTENDED(hdr) ((hdr)->datalen == 0xFF \ | ||
112 | && (hdr)->datalen_checksum == 0xFF) | ||
113 | #define PN533_EXT_FRAME_CHECKSUM(f) (f->data[be16_to_cpu(f->datalen)]) | ||
102 | 114 | ||
103 | /* start of frame */ | 115 | /* start of frame */ |
104 | #define PN533_STD_FRAME_SOF 0x00FF | 116 | #define PN533_STD_FRAME_SOF 0x00FF |
@@ -124,7 +136,7 @@ MODULE_DEVICE_TABLE(usb, pn533_table); | |||
124 | #define PN533_ACR122_RDR_TO_PC_ESCAPE 0x83 | 136 | #define PN533_ACR122_RDR_TO_PC_ESCAPE 0x83 |
125 | 137 | ||
126 | /* PN533 Commands */ | 138 | /* PN533 Commands */ |
127 | #define PN533_STD_FRAME_CMD(f) (f->data[1]) | 139 | #define PN533_FRAME_CMD(f) (f->data[1]) |
128 | 140 | ||
129 | #define PN533_CMD_GET_FIRMWARE_VERSION 0x02 | 141 | #define PN533_CMD_GET_FIRMWARE_VERSION 0x02 |
130 | #define PN533_CMD_RF_CONFIGURATION 0x32 | 142 | #define PN533_CMD_RF_CONFIGURATION 0x32 |
@@ -168,8 +180,9 @@ struct pn533_fw_version { | |||
168 | #define PN533_CFGITEM_MAX_RETRIES 0x05 | 180 | #define PN533_CFGITEM_MAX_RETRIES 0x05 |
169 | #define PN533_CFGITEM_PASORI 0x82 | 181 | #define PN533_CFGITEM_PASORI 0x82 |
170 | 182 | ||
171 | #define PN533_CFGITEM_RF_FIELD_ON 0x1 | 183 | #define PN533_CFGITEM_RF_FIELD_AUTO_RFCA 0x2 |
172 | #define PN533_CFGITEM_RF_FIELD_OFF 0x0 | 184 | #define PN533_CFGITEM_RF_FIELD_ON 0x1 |
185 | #define PN533_CFGITEM_RF_FIELD_OFF 0x0 | ||
173 | 186 | ||
174 | #define PN533_CONFIG_TIMING_102 0xb | 187 | #define PN533_CONFIG_TIMING_102 0xb |
175 | #define PN533_CONFIG_TIMING_204 0xc | 188 | #define PN533_CONFIG_TIMING_204 0xc |
@@ -257,7 +270,7 @@ static const struct pn533_poll_modulations poll_mod[] = { | |||
257 | .initiator_data.felica = { | 270 | .initiator_data.felica = { |
258 | .opcode = PN533_FELICA_OPC_SENSF_REQ, | 271 | .opcode = PN533_FELICA_OPC_SENSF_REQ, |
259 | .sc = PN533_FELICA_SENSF_SC_ALL, | 272 | .sc = PN533_FELICA_SENSF_SC_ALL, |
260 | .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE, | 273 | .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE, |
261 | .tsn = 0x03, | 274 | .tsn = 0x03, |
262 | }, | 275 | }, |
263 | }, | 276 | }, |
@@ -270,7 +283,7 @@ static const struct pn533_poll_modulations poll_mod[] = { | |||
270 | .initiator_data.felica = { | 283 | .initiator_data.felica = { |
271 | .opcode = PN533_FELICA_OPC_SENSF_REQ, | 284 | .opcode = PN533_FELICA_OPC_SENSF_REQ, |
272 | .sc = PN533_FELICA_SENSF_SC_ALL, | 285 | .sc = PN533_FELICA_SENSF_SC_ALL, |
273 | .rc = PN533_FELICA_SENSF_RC_NO_SYSTEM_CODE, | 286 | .rc = PN533_FELICA_SENSF_RC_SYSTEM_CODE, |
274 | .tsn = 0x03, | 287 | .tsn = 0x03, |
275 | }, | 288 | }, |
276 | }, | 289 | }, |
@@ -352,13 +365,16 @@ struct pn533 { | |||
352 | struct urb *in_urb; | 365 | struct urb *in_urb; |
353 | 366 | ||
354 | struct sk_buff_head resp_q; | 367 | struct sk_buff_head resp_q; |
368 | struct sk_buff_head fragment_skb; | ||
355 | 369 | ||
356 | struct workqueue_struct *wq; | 370 | struct workqueue_struct *wq; |
357 | struct work_struct cmd_work; | 371 | struct work_struct cmd_work; |
358 | struct work_struct cmd_complete_work; | 372 | struct work_struct cmd_complete_work; |
359 | struct work_struct poll_work; | 373 | struct delayed_work poll_work; |
360 | struct work_struct mi_work; | 374 | struct work_struct mi_rx_work; |
375 | struct work_struct mi_tx_work; | ||
361 | struct work_struct tg_work; | 376 | struct work_struct tg_work; |
377 | struct work_struct rf_work; | ||
362 | 378 | ||
363 | struct list_head cmd_queue; | 379 | struct list_head cmd_queue; |
364 | struct pn533_cmd *cmd; | 380 | struct pn533_cmd *cmd; |
@@ -366,6 +382,7 @@ struct pn533 { | |||
366 | struct mutex cmd_lock; /* protects cmd queue */ | 382 | struct mutex cmd_lock; /* protects cmd queue */ |
367 | 383 | ||
368 | void *cmd_complete_mi_arg; | 384 | void *cmd_complete_mi_arg; |
385 | void *cmd_complete_dep_arg; | ||
369 | 386 | ||
370 | struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1]; | 387 | struct pn533_poll_modulations *poll_mod_active[PN533_POLL_MOD_MAX + 1]; |
371 | u8 poll_mod_count; | 388 | u8 poll_mod_count; |
@@ -404,6 +421,15 @@ struct pn533_std_frame { | |||
404 | u8 data[]; | 421 | u8 data[]; |
405 | } __packed; | 422 | } __packed; |
406 | 423 | ||
424 | struct pn533_ext_frame { /* Extended Information frame */ | ||
425 | u8 preamble; | ||
426 | __be16 start_frame; | ||
427 | __be16 eif_flag; /* fixed to 0xFFFF */ | ||
428 | __be16 datalen; | ||
429 | u8 datalen_checksum; | ||
430 | u8 data[]; | ||
431 | } __packed; | ||
432 | |||
407 | struct pn533_frame_ops { | 433 | struct pn533_frame_ops { |
408 | void (*tx_frame_init)(void *frame, u8 cmd_code); | 434 | void (*tx_frame_init)(void *frame, u8 cmd_code); |
409 | void (*tx_frame_finish)(void *frame); | 435 | void (*tx_frame_finish)(void *frame); |
@@ -411,7 +437,7 @@ struct pn533_frame_ops { | |||
411 | int tx_header_len; | 437 | int tx_header_len; |
412 | int tx_tail_len; | 438 | int tx_tail_len; |
413 | 439 | ||
414 | bool (*rx_is_frame_valid)(void *frame); | 440 | bool (*rx_is_frame_valid)(void *frame, struct pn533 *dev); |
415 | int (*rx_frame_size)(void *frame); | 441 | int (*rx_frame_size)(void *frame); |
416 | int rx_header_len; | 442 | int rx_header_len; |
417 | int rx_tail_len; | 443 | int rx_tail_len; |
@@ -486,7 +512,7 @@ static void pn533_acr122_tx_update_payload_len(void *_frame, int len) | |||
486 | frame->datalen += len; | 512 | frame->datalen += len; |
487 | } | 513 | } |
488 | 514 | ||
489 | static bool pn533_acr122_is_rx_frame_valid(void *_frame) | 515 | static bool pn533_acr122_is_rx_frame_valid(void *_frame, struct pn533 *dev) |
490 | { | 516 | { |
491 | struct pn533_acr122_rx_frame *frame = _frame; | 517 | struct pn533_acr122_rx_frame *frame = _frame; |
492 | 518 | ||
@@ -511,7 +537,7 @@ static u8 pn533_acr122_get_cmd_code(void *frame) | |||
511 | { | 537 | { |
512 | struct pn533_acr122_rx_frame *f = frame; | 538 | struct pn533_acr122_rx_frame *f = frame; |
513 | 539 | ||
514 | return PN533_STD_FRAME_CMD(f); | 540 | return PN533_FRAME_CMD(f); |
515 | } | 541 | } |
516 | 542 | ||
517 | static struct pn533_frame_ops pn533_acr122_frame_ops = { | 543 | static struct pn533_frame_ops pn533_acr122_frame_ops = { |
@@ -530,6 +556,12 @@ static struct pn533_frame_ops pn533_acr122_frame_ops = { | |||
530 | .get_cmd_code = pn533_acr122_get_cmd_code, | 556 | .get_cmd_code = pn533_acr122_get_cmd_code, |
531 | }; | 557 | }; |
532 | 558 | ||
559 | /* The rule: value(high byte) + value(low byte) + checksum = 0 */ | ||
560 | static inline u8 pn533_ext_checksum(u16 value) | ||
561 | { | ||
562 | return ~(u8)(((value & 0xFF00) >> 8) + (u8)(value & 0xFF)) + 1; | ||
563 | } | ||
564 | |||
533 | /* The rule: value + checksum = 0 */ | 565 | /* The rule: value + checksum = 0 */ |
534 | static inline u8 pn533_std_checksum(u8 value) | 566 | static inline u8 pn533_std_checksum(u8 value) |
535 | { | 567 | { |
@@ -555,7 +587,7 @@ static void pn533_std_tx_frame_init(void *_frame, u8 cmd_code) | |||
555 | frame->preamble = 0; | 587 | frame->preamble = 0; |
556 | frame->start_frame = cpu_to_be16(PN533_STD_FRAME_SOF); | 588 | frame->start_frame = cpu_to_be16(PN533_STD_FRAME_SOF); |
557 | PN533_STD_FRAME_IDENTIFIER(frame) = PN533_STD_FRAME_DIR_OUT; | 589 | PN533_STD_FRAME_IDENTIFIER(frame) = PN533_STD_FRAME_DIR_OUT; |
558 | PN533_STD_FRAME_CMD(frame) = cmd_code; | 590 | PN533_FRAME_CMD(frame) = cmd_code; |
559 | frame->datalen = 2; | 591 | frame->datalen = 2; |
560 | } | 592 | } |
561 | 593 | ||
@@ -578,21 +610,41 @@ static void pn533_std_tx_update_payload_len(void *_frame, int len) | |||
578 | frame->datalen += len; | 610 | frame->datalen += len; |
579 | } | 611 | } |
580 | 612 | ||
581 | static bool pn533_std_rx_frame_is_valid(void *_frame) | 613 | static bool pn533_std_rx_frame_is_valid(void *_frame, struct pn533 *dev) |
582 | { | 614 | { |
583 | u8 checksum; | 615 | u8 checksum; |
584 | struct pn533_std_frame *frame = _frame; | 616 | struct pn533_std_frame *stdf = _frame; |
585 | 617 | ||
586 | if (frame->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF)) | 618 | if (stdf->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF)) |
587 | return false; | 619 | return false; |
588 | 620 | ||
589 | checksum = pn533_std_checksum(frame->datalen); | 621 | if (likely(!PN533_STD_IS_EXTENDED(stdf))) { |
590 | if (checksum != frame->datalen_checksum) | 622 | /* Standard frame code */ |
591 | return false; | 623 | dev->ops->rx_header_len = PN533_STD_FRAME_HEADER_LEN; |
592 | 624 | ||
593 | checksum = pn533_std_data_checksum(frame->data, frame->datalen); | 625 | checksum = pn533_std_checksum(stdf->datalen); |
594 | if (checksum != PN533_STD_FRAME_CHECKSUM(frame)) | 626 | if (checksum != stdf->datalen_checksum) |
595 | return false; | 627 | return false; |
628 | |||
629 | checksum = pn533_std_data_checksum(stdf->data, stdf->datalen); | ||
630 | if (checksum != PN533_STD_FRAME_CHECKSUM(stdf)) | ||
631 | return false; | ||
632 | } else { | ||
633 | /* Extended */ | ||
634 | struct pn533_ext_frame *eif = _frame; | ||
635 | |||
636 | dev->ops->rx_header_len = PN533_EXT_FRAME_HEADER_LEN; | ||
637 | |||
638 | checksum = pn533_ext_checksum(be16_to_cpu(eif->datalen)); | ||
639 | if (checksum != eif->datalen_checksum) | ||
640 | return false; | ||
641 | |||
642 | /* check data checksum */ | ||
643 | checksum = pn533_std_data_checksum(eif->data, | ||
644 | be16_to_cpu(eif->datalen)); | ||
645 | if (checksum != PN533_EXT_FRAME_CHECKSUM(eif)) | ||
646 | return false; | ||
647 | } | ||
596 | 648 | ||
597 | return true; | 649 | return true; |
598 | } | 650 | } |
@@ -612,6 +664,14 @@ static inline int pn533_std_rx_frame_size(void *frame) | |||
612 | { | 664 | { |
613 | struct pn533_std_frame *f = frame; | 665 | struct pn533_std_frame *f = frame; |
614 | 666 | ||
667 | /* check for Extended Information frame */ | ||
668 | if (PN533_STD_IS_EXTENDED(f)) { | ||
669 | struct pn533_ext_frame *eif = frame; | ||
670 | |||
671 | return sizeof(struct pn533_ext_frame) | ||
672 | + be16_to_cpu(eif->datalen) + PN533_STD_FRAME_TAIL_LEN; | ||
673 | } | ||
674 | |||
615 | return sizeof(struct pn533_std_frame) + f->datalen + | 675 | return sizeof(struct pn533_std_frame) + f->datalen + |
616 | PN533_STD_FRAME_TAIL_LEN; | 676 | PN533_STD_FRAME_TAIL_LEN; |
617 | } | 677 | } |
@@ -619,8 +679,12 @@ static inline int pn533_std_rx_frame_size(void *frame) | |||
619 | static u8 pn533_std_get_cmd_code(void *frame) | 679 | static u8 pn533_std_get_cmd_code(void *frame) |
620 | { | 680 | { |
621 | struct pn533_std_frame *f = frame; | 681 | struct pn533_std_frame *f = frame; |
682 | struct pn533_ext_frame *eif = frame; | ||
622 | 683 | ||
623 | return PN533_STD_FRAME_CMD(f); | 684 | if (PN533_STD_IS_EXTENDED(f)) |
685 | return PN533_FRAME_CMD(eif); | ||
686 | else | ||
687 | return PN533_FRAME_CMD(f); | ||
624 | } | 688 | } |
625 | 689 | ||
626 | static struct pn533_frame_ops pn533_std_frame_ops = { | 690 | static struct pn533_frame_ops pn533_std_frame_ops = { |
@@ -675,7 +739,7 @@ static void pn533_recv_response(struct urb *urb) | |||
675 | print_hex_dump_debug("PN533 RX: ", DUMP_PREFIX_NONE, 16, 1, in_frame, | 739 | print_hex_dump_debug("PN533 RX: ", DUMP_PREFIX_NONE, 16, 1, in_frame, |
676 | dev->ops->rx_frame_size(in_frame), false); | 740 | dev->ops->rx_frame_size(in_frame), false); |
677 | 741 | ||
678 | if (!dev->ops->rx_is_frame_valid(in_frame)) { | 742 | if (!dev->ops->rx_is_frame_valid(in_frame, dev)) { |
679 | nfc_dev_err(&dev->interface->dev, "Received an invalid frame"); | 743 | nfc_dev_err(&dev->interface->dev, "Received an invalid frame"); |
680 | cmd->status = -EIO; | 744 | cmd->status = -EIO; |
681 | goto sched_wq; | 745 | goto sched_wq; |
@@ -1657,7 +1721,56 @@ static void pn533_listen_mode_timer(unsigned long data) | |||
1657 | 1721 | ||
1658 | pn533_poll_next_mod(dev); | 1722 | pn533_poll_next_mod(dev); |
1659 | 1723 | ||
1660 | queue_work(dev->wq, &dev->poll_work); | 1724 | queue_delayed_work(dev->wq, &dev->poll_work, |
1725 | msecs_to_jiffies(PN533_POLL_INTERVAL)); | ||
1726 | } | ||
1727 | |||
1728 | static int pn533_rf_complete(struct pn533 *dev, void *arg, | ||
1729 | struct sk_buff *resp) | ||
1730 | { | ||
1731 | int rc = 0; | ||
1732 | |||
1733 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | ||
1734 | |||
1735 | if (IS_ERR(resp)) { | ||
1736 | rc = PTR_ERR(resp); | ||
1737 | |||
1738 | nfc_dev_err(&dev->interface->dev, "%s RF setting error %d", | ||
1739 | __func__, rc); | ||
1740 | |||
1741 | return rc; | ||
1742 | } | ||
1743 | |||
1744 | queue_delayed_work(dev->wq, &dev->poll_work, | ||
1745 | msecs_to_jiffies(PN533_POLL_INTERVAL)); | ||
1746 | |||
1747 | dev_kfree_skb(resp); | ||
1748 | return rc; | ||
1749 | } | ||
1750 | |||
1751 | static void pn533_wq_rf(struct work_struct *work) | ||
1752 | { | ||
1753 | struct pn533 *dev = container_of(work, struct pn533, rf_work); | ||
1754 | struct sk_buff *skb; | ||
1755 | int rc; | ||
1756 | |||
1757 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | ||
1758 | |||
1759 | skb = pn533_alloc_skb(dev, 2); | ||
1760 | if (!skb) | ||
1761 | return; | ||
1762 | |||
1763 | *skb_put(skb, 1) = PN533_CFGITEM_RF_FIELD; | ||
1764 | *skb_put(skb, 1) = PN533_CFGITEM_RF_FIELD_AUTO_RFCA; | ||
1765 | |||
1766 | rc = pn533_send_cmd_async(dev, PN533_CMD_RF_CONFIGURATION, skb, | ||
1767 | pn533_rf_complete, NULL); | ||
1768 | if (rc < 0) { | ||
1769 | dev_kfree_skb(skb); | ||
1770 | nfc_dev_err(&dev->interface->dev, "RF setting error %d", rc); | ||
1771 | } | ||
1772 | |||
1773 | return; | ||
1661 | } | 1774 | } |
1662 | 1775 | ||
1663 | static int pn533_poll_complete(struct pn533 *dev, void *arg, | 1776 | static int pn533_poll_complete(struct pn533 *dev, void *arg, |
@@ -1705,7 +1818,8 @@ static int pn533_poll_complete(struct pn533 *dev, void *arg, | |||
1705 | } | 1818 | } |
1706 | 1819 | ||
1707 | pn533_poll_next_mod(dev); | 1820 | pn533_poll_next_mod(dev); |
1708 | queue_work(dev->wq, &dev->poll_work); | 1821 | /* Not target found, turn radio off */ |
1822 | queue_work(dev->wq, &dev->rf_work); | ||
1709 | 1823 | ||
1710 | done: | 1824 | done: |
1711 | dev_kfree_skb(resp); | 1825 | dev_kfree_skb(resp); |
@@ -1770,7 +1884,7 @@ static int pn533_send_poll_frame(struct pn533 *dev) | |||
1770 | 1884 | ||
1771 | static void pn533_wq_poll(struct work_struct *work) | 1885 | static void pn533_wq_poll(struct work_struct *work) |
1772 | { | 1886 | { |
1773 | struct pn533 *dev = container_of(work, struct pn533, poll_work); | 1887 | struct pn533 *dev = container_of(work, struct pn533, poll_work.work); |
1774 | struct pn533_poll_modulations *cur_mod; | 1888 | struct pn533_poll_modulations *cur_mod; |
1775 | int rc; | 1889 | int rc; |
1776 | 1890 | ||
@@ -1799,6 +1913,7 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, | |||
1799 | u32 im_protocols, u32 tm_protocols) | 1913 | u32 im_protocols, u32 tm_protocols) |
1800 | { | 1914 | { |
1801 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); | 1915 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); |
1916 | u8 rand_mod; | ||
1802 | 1917 | ||
1803 | nfc_dev_dbg(&dev->interface->dev, | 1918 | nfc_dev_dbg(&dev->interface->dev, |
1804 | "%s: im protocols 0x%x tm protocols 0x%x", | 1919 | "%s: im protocols 0x%x tm protocols 0x%x", |
@@ -1822,11 +1937,15 @@ static int pn533_start_poll(struct nfc_dev *nfc_dev, | |||
1822 | tm_protocols = 0; | 1937 | tm_protocols = 0; |
1823 | } | 1938 | } |
1824 | 1939 | ||
1825 | dev->poll_mod_curr = 0; | ||
1826 | pn533_poll_create_mod_list(dev, im_protocols, tm_protocols); | 1940 | pn533_poll_create_mod_list(dev, im_protocols, tm_protocols); |
1827 | dev->poll_protocols = im_protocols; | 1941 | dev->poll_protocols = im_protocols; |
1828 | dev->listen_protocols = tm_protocols; | 1942 | dev->listen_protocols = tm_protocols; |
1829 | 1943 | ||
1944 | /* Do not always start polling from the same modulation */ | ||
1945 | get_random_bytes(&rand_mod, sizeof(rand_mod)); | ||
1946 | rand_mod %= dev->poll_mod_count; | ||
1947 | dev->poll_mod_curr = rand_mod; | ||
1948 | |||
1830 | return pn533_send_poll_frame(dev); | 1949 | return pn533_send_poll_frame(dev); |
1831 | } | 1950 | } |
1832 | 1951 | ||
@@ -1845,6 +1964,7 @@ static void pn533_stop_poll(struct nfc_dev *nfc_dev) | |||
1845 | } | 1964 | } |
1846 | 1965 | ||
1847 | pn533_abort_cmd(dev, GFP_KERNEL); | 1966 | pn533_abort_cmd(dev, GFP_KERNEL); |
1967 | flush_delayed_work(&dev->poll_work); | ||
1848 | pn533_poll_reset_mod_list(dev); | 1968 | pn533_poll_reset_mod_list(dev); |
1849 | } | 1969 | } |
1850 | 1970 | ||
@@ -2037,28 +2157,15 @@ error: | |||
2037 | return rc; | 2157 | return rc; |
2038 | } | 2158 | } |
2039 | 2159 | ||
2040 | static int pn533_mod_to_baud(struct pn533 *dev) | 2160 | static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf); |
2041 | { | ||
2042 | switch (dev->poll_mod_curr) { | ||
2043 | case PN533_POLL_MOD_106KBPS_A: | ||
2044 | return 0; | ||
2045 | case PN533_POLL_MOD_212KBPS_FELICA: | ||
2046 | return 1; | ||
2047 | case PN533_POLL_MOD_424KBPS_FELICA: | ||
2048 | return 2; | ||
2049 | default: | ||
2050 | return -EINVAL; | ||
2051 | } | ||
2052 | } | ||
2053 | |||
2054 | #define PASSIVE_DATA_LEN 5 | 2161 | #define PASSIVE_DATA_LEN 5 |
2055 | static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, | 2162 | static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, |
2056 | u8 comm_mode, u8 *gb, size_t gb_len) | 2163 | u8 comm_mode, u8 *gb, size_t gb_len) |
2057 | { | 2164 | { |
2058 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); | 2165 | struct pn533 *dev = nfc_get_drvdata(nfc_dev); |
2059 | struct sk_buff *skb; | 2166 | struct sk_buff *skb; |
2060 | int rc, baud, skb_len; | 2167 | int rc, skb_len; |
2061 | u8 *next, *arg; | 2168 | u8 *next, *arg, nfcid3[NFC_NFCID3_MAXSIZE]; |
2062 | 2169 | ||
2063 | u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3}; | 2170 | u8 passive_data[PASSIVE_DATA_LEN] = {0x00, 0xff, 0xff, 0x00, 0x3}; |
2064 | 2171 | ||
@@ -2076,41 +2183,39 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, | |||
2076 | return -EBUSY; | 2183 | return -EBUSY; |
2077 | } | 2184 | } |
2078 | 2185 | ||
2079 | baud = pn533_mod_to_baud(dev); | ||
2080 | if (baud < 0) { | ||
2081 | nfc_dev_err(&dev->interface->dev, | ||
2082 | "Invalid curr modulation %d", dev->poll_mod_curr); | ||
2083 | return baud; | ||
2084 | } | ||
2085 | |||
2086 | skb_len = 3 + gb_len; /* ActPass + BR + Next */ | 2186 | skb_len = 3 + gb_len; /* ActPass + BR + Next */ |
2087 | if (comm_mode == NFC_COMM_PASSIVE) | 2187 | skb_len += PASSIVE_DATA_LEN; |
2088 | skb_len += PASSIVE_DATA_LEN; | ||
2089 | 2188 | ||
2090 | if (target && target->nfcid2_len) | 2189 | /* NFCID3 */ |
2091 | skb_len += NFC_NFCID3_MAXSIZE; | 2190 | skb_len += NFC_NFCID3_MAXSIZE; |
2191 | if (target && !target->nfcid2_len) { | ||
2192 | nfcid3[0] = 0x1; | ||
2193 | nfcid3[1] = 0xfe; | ||
2194 | get_random_bytes(nfcid3 + 2, 6); | ||
2195 | } | ||
2092 | 2196 | ||
2093 | skb = pn533_alloc_skb(dev, skb_len); | 2197 | skb = pn533_alloc_skb(dev, skb_len); |
2094 | if (!skb) | 2198 | if (!skb) |
2095 | return -ENOMEM; | 2199 | return -ENOMEM; |
2096 | 2200 | ||
2097 | *skb_put(skb, 1) = !comm_mode; /* ActPass */ | 2201 | *skb_put(skb, 1) = !comm_mode; /* ActPass */ |
2098 | *skb_put(skb, 1) = baud; /* Baud rate */ | 2202 | *skb_put(skb, 1) = 0x02; /* 424 kbps */ |
2099 | 2203 | ||
2100 | next = skb_put(skb, 1); /* Next */ | 2204 | next = skb_put(skb, 1); /* Next */ |
2101 | *next = 0; | 2205 | *next = 0; |
2102 | 2206 | ||
2103 | if (comm_mode == NFC_COMM_PASSIVE && baud > 0) { | 2207 | /* Copy passive data */ |
2104 | memcpy(skb_put(skb, PASSIVE_DATA_LEN), passive_data, | 2208 | memcpy(skb_put(skb, PASSIVE_DATA_LEN), passive_data, PASSIVE_DATA_LEN); |
2105 | PASSIVE_DATA_LEN); | 2209 | *next |= 1; |
2106 | *next |= 1; | ||
2107 | } | ||
2108 | 2210 | ||
2109 | if (target && target->nfcid2_len) { | 2211 | /* Copy NFCID3 (which is NFCID2 from SENSF_RES) */ |
2212 | if (target && target->nfcid2_len) | ||
2110 | memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), target->nfcid2, | 2213 | memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), target->nfcid2, |
2111 | target->nfcid2_len); | 2214 | target->nfcid2_len); |
2112 | *next |= 2; | 2215 | else |
2113 | } | 2216 | memcpy(skb_put(skb, NFC_NFCID3_MAXSIZE), nfcid3, |
2217 | NFC_NFCID3_MAXSIZE); | ||
2218 | *next |= 2; | ||
2114 | 2219 | ||
2115 | if (gb != NULL && gb_len > 0) { | 2220 | if (gb != NULL && gb_len > 0) { |
2116 | memcpy(skb_put(skb, gb_len), gb, gb_len); | 2221 | memcpy(skb_put(skb, gb_len), gb, gb_len); |
@@ -2127,6 +2232,8 @@ static int pn533_dep_link_up(struct nfc_dev *nfc_dev, struct nfc_target *target, | |||
2127 | 2232 | ||
2128 | *arg = !comm_mode; | 2233 | *arg = !comm_mode; |
2129 | 2234 | ||
2235 | pn533_rf_field(dev->nfc_dev, 0); | ||
2236 | |||
2130 | rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb, | 2237 | rc = pn533_send_cmd_async(dev, PN533_CMD_IN_JUMP_FOR_DEP, skb, |
2131 | pn533_in_dep_link_up_complete, arg); | 2238 | pn533_in_dep_link_up_complete, arg); |
2132 | 2239 | ||
@@ -2232,7 +2339,15 @@ static int pn533_data_exchange_complete(struct pn533 *dev, void *_arg, | |||
2232 | 2339 | ||
2233 | if (mi) { | 2340 | if (mi) { |
2234 | dev->cmd_complete_mi_arg = arg; | 2341 | dev->cmd_complete_mi_arg = arg; |
2235 | queue_work(dev->wq, &dev->mi_work); | 2342 | queue_work(dev->wq, &dev->mi_rx_work); |
2343 | return -EINPROGRESS; | ||
2344 | } | ||
2345 | |||
2346 | /* Prepare for the next round */ | ||
2347 | if (skb_queue_len(&dev->fragment_skb) > 0) { | ||
2348 | dev->cmd_complete_dep_arg = arg; | ||
2349 | queue_work(dev->wq, &dev->mi_tx_work); | ||
2350 | |||
2236 | return -EINPROGRESS; | 2351 | return -EINPROGRESS; |
2237 | } | 2352 | } |
2238 | 2353 | ||
@@ -2253,6 +2368,50 @@ _error: | |||
2253 | return rc; | 2368 | return rc; |
2254 | } | 2369 | } |
2255 | 2370 | ||
2371 | /* Split the Tx skb into small chunks */ | ||
2372 | static int pn533_fill_fragment_skbs(struct pn533 *dev, struct sk_buff *skb) | ||
2373 | { | ||
2374 | struct sk_buff *frag; | ||
2375 | int frag_size; | ||
2376 | |||
2377 | do { | ||
2378 | /* Remaining size */ | ||
2379 | if (skb->len > PN533_CMD_DATAFRAME_MAXLEN) | ||
2380 | frag_size = PN533_CMD_DATAFRAME_MAXLEN; | ||
2381 | else | ||
2382 | frag_size = skb->len; | ||
2383 | |||
2384 | /* Allocate and reserve */ | ||
2385 | frag = pn533_alloc_skb(dev, frag_size); | ||
2386 | if (!frag) { | ||
2387 | skb_queue_purge(&dev->fragment_skb); | ||
2388 | break; | ||
2389 | } | ||
2390 | |||
2391 | /* Reserve the TG/MI byte */ | ||
2392 | skb_reserve(frag, 1); | ||
2393 | |||
2394 | /* MI + TG */ | ||
2395 | if (frag_size == PN533_CMD_DATAFRAME_MAXLEN) | ||
2396 | *skb_push(frag, sizeof(u8)) = (PN533_CMD_MI_MASK | 1); | ||
2397 | else | ||
2398 | *skb_push(frag, sizeof(u8)) = 1; /* TG */ | ||
2399 | |||
2400 | memcpy(skb_put(frag, frag_size), skb->data, frag_size); | ||
2401 | |||
2402 | /* Reduce the size of incoming buffer */ | ||
2403 | skb_pull(skb, frag_size); | ||
2404 | |||
2405 | /* Add this to skb_queue */ | ||
2406 | skb_queue_tail(&dev->fragment_skb, frag); | ||
2407 | |||
2408 | } while (skb->len > 0); | ||
2409 | |||
2410 | dev_kfree_skb(skb); | ||
2411 | |||
2412 | return skb_queue_len(&dev->fragment_skb); | ||
2413 | } | ||
2414 | |||
2256 | static int pn533_transceive(struct nfc_dev *nfc_dev, | 2415 | static int pn533_transceive(struct nfc_dev *nfc_dev, |
2257 | struct nfc_target *target, struct sk_buff *skb, | 2416 | struct nfc_target *target, struct sk_buff *skb, |
2258 | data_exchange_cb_t cb, void *cb_context) | 2417 | data_exchange_cb_t cb, void *cb_context) |
@@ -2263,15 +2422,6 @@ static int pn533_transceive(struct nfc_dev *nfc_dev, | |||
2263 | 2422 | ||
2264 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | 2423 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); |
2265 | 2424 | ||
2266 | if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) { | ||
2267 | /* TODO: Implement support to multi-part data exchange */ | ||
2268 | nfc_dev_err(&dev->interface->dev, | ||
2269 | "Data length greater than the max allowed: %d", | ||
2270 | PN533_CMD_DATAEXCH_DATA_MAXLEN); | ||
2271 | rc = -ENOSYS; | ||
2272 | goto error; | ||
2273 | } | ||
2274 | |||
2275 | if (!dev->tgt_active_prot) { | 2425 | if (!dev->tgt_active_prot) { |
2276 | nfc_dev_err(&dev->interface->dev, | 2426 | nfc_dev_err(&dev->interface->dev, |
2277 | "Can't exchange data if there is no active target"); | 2427 | "Can't exchange data if there is no active target"); |
@@ -2299,7 +2449,20 @@ static int pn533_transceive(struct nfc_dev *nfc_dev, | |||
2299 | break; | 2449 | break; |
2300 | } | 2450 | } |
2301 | default: | 2451 | default: |
2302 | *skb_push(skb, sizeof(u8)) = 1; /*TG*/ | 2452 | /* jumbo frame ? */ |
2453 | if (skb->len > PN533_CMD_DATAEXCH_DATA_MAXLEN) { | ||
2454 | rc = pn533_fill_fragment_skbs(dev, skb); | ||
2455 | if (rc <= 0) | ||
2456 | goto error; | ||
2457 | |||
2458 | skb = skb_dequeue(&dev->fragment_skb); | ||
2459 | if (!skb) { | ||
2460 | rc = -EIO; | ||
2461 | goto error; | ||
2462 | } | ||
2463 | } else { | ||
2464 | *skb_push(skb, sizeof(u8)) = 1; /* TG */ | ||
2465 | } | ||
2303 | 2466 | ||
2304 | rc = pn533_send_data_async(dev, PN533_CMD_IN_DATA_EXCHANGE, | 2467 | rc = pn533_send_data_async(dev, PN533_CMD_IN_DATA_EXCHANGE, |
2305 | skb, pn533_data_exchange_complete, | 2468 | skb, pn533_data_exchange_complete, |
@@ -2370,7 +2533,7 @@ static int pn533_tm_send(struct nfc_dev *nfc_dev, struct sk_buff *skb) | |||
2370 | 2533 | ||
2371 | static void pn533_wq_mi_recv(struct work_struct *work) | 2534 | static void pn533_wq_mi_recv(struct work_struct *work) |
2372 | { | 2535 | { |
2373 | struct pn533 *dev = container_of(work, struct pn533, mi_work); | 2536 | struct pn533 *dev = container_of(work, struct pn533, mi_rx_work); |
2374 | 2537 | ||
2375 | struct sk_buff *skb; | 2538 | struct sk_buff *skb; |
2376 | int rc; | 2539 | int rc; |
@@ -2418,6 +2581,61 @@ error: | |||
2418 | queue_work(dev->wq, &dev->cmd_work); | 2581 | queue_work(dev->wq, &dev->cmd_work); |
2419 | } | 2582 | } |
2420 | 2583 | ||
2584 | static void pn533_wq_mi_send(struct work_struct *work) | ||
2585 | { | ||
2586 | struct pn533 *dev = container_of(work, struct pn533, mi_tx_work); | ||
2587 | struct sk_buff *skb; | ||
2588 | int rc; | ||
2589 | |||
2590 | nfc_dev_dbg(&dev->interface->dev, "%s", __func__); | ||
2591 | |||
2592 | /* Grab the first skb in the queue */ | ||
2593 | skb = skb_dequeue(&dev->fragment_skb); | ||
2594 | |||
2595 | if (skb == NULL) { /* No more data */ | ||
2596 | /* Reset the queue for future use */ | ||
2597 | skb_queue_head_init(&dev->fragment_skb); | ||
2598 | goto error; | ||
2599 | } | ||
2600 | |||
2601 | switch (dev->device_type) { | ||
2602 | case PN533_DEVICE_PASORI: | ||
2603 | if (dev->tgt_active_prot != NFC_PROTO_FELICA) { | ||
2604 | rc = -EIO; | ||
2605 | break; | ||
2606 | } | ||
2607 | |||
2608 | rc = pn533_send_cmd_direct_async(dev, PN533_CMD_IN_COMM_THRU, | ||
2609 | skb, | ||
2610 | pn533_data_exchange_complete, | ||
2611 | dev->cmd_complete_dep_arg); | ||
2612 | |||
2613 | break; | ||
2614 | |||
2615 | default: | ||
2616 | /* Still some fragments? */ | ||
2617 | rc = pn533_send_cmd_direct_async(dev,PN533_CMD_IN_DATA_EXCHANGE, | ||
2618 | skb, | ||
2619 | pn533_data_exchange_complete, | ||
2620 | dev->cmd_complete_dep_arg); | ||
2621 | |||
2622 | break; | ||
2623 | } | ||
2624 | |||
2625 | if (rc == 0) /* success */ | ||
2626 | return; | ||
2627 | |||
2628 | nfc_dev_err(&dev->interface->dev, | ||
2629 | "Error %d when trying to perform data_exchange", rc); | ||
2630 | |||
2631 | dev_kfree_skb(skb); | ||
2632 | kfree(dev->cmd_complete_dep_arg); | ||
2633 | |||
2634 | error: | ||
2635 | pn533_send_ack(dev, GFP_KERNEL); | ||
2636 | queue_work(dev->wq, &dev->cmd_work); | ||
2637 | } | ||
2638 | |||
2421 | static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata, | 2639 | static int pn533_set_configuration(struct pn533 *dev, u8 cfgitem, u8 *cfgdata, |
2422 | u8 cfgdata_len) | 2640 | u8 cfgdata_len) |
2423 | { | 2641 | { |
@@ -2562,6 +2780,8 @@ static int pn533_rf_field(struct nfc_dev *nfc_dev, u8 rf) | |||
2562 | u8 rf_field = !!rf; | 2780 | u8 rf_field = !!rf; |
2563 | int rc; | 2781 | int rc; |
2564 | 2782 | ||
2783 | rf_field |= PN533_CFGITEM_RF_FIELD_AUTO_RFCA; | ||
2784 | |||
2565 | rc = pn533_set_configuration(dev, PN533_CFGITEM_RF_FIELD, | 2785 | rc = pn533_set_configuration(dev, PN533_CFGITEM_RF_FIELD, |
2566 | (u8 *)&rf_field, 1); | 2786 | (u8 *)&rf_field, 1); |
2567 | if (rc) { | 2787 | if (rc) { |
@@ -2605,17 +2825,6 @@ static int pn533_setup(struct pn533 *dev) | |||
2605 | 2825 | ||
2606 | switch (dev->device_type) { | 2826 | switch (dev->device_type) { |
2607 | case PN533_DEVICE_STD: | 2827 | case PN533_DEVICE_STD: |
2608 | max_retries.mx_rty_atr = PN533_CONFIG_MAX_RETRIES_ENDLESS; | ||
2609 | max_retries.mx_rty_psl = 2; | ||
2610 | max_retries.mx_rty_passive_act = | ||
2611 | PN533_CONFIG_MAX_RETRIES_NO_RETRY; | ||
2612 | |||
2613 | timing.rfu = PN533_CONFIG_TIMING_102; | ||
2614 | timing.atr_res_timeout = PN533_CONFIG_TIMING_204; | ||
2615 | timing.dep_timeout = PN533_CONFIG_TIMING_409; | ||
2616 | |||
2617 | break; | ||
2618 | |||
2619 | case PN533_DEVICE_PASORI: | 2828 | case PN533_DEVICE_PASORI: |
2620 | case PN533_DEVICE_ACR122U: | 2829 | case PN533_DEVICE_ACR122U: |
2621 | max_retries.mx_rty_atr = 0x2; | 2830 | max_retries.mx_rty_atr = 0x2; |
@@ -2729,9 +2938,11 @@ static int pn533_probe(struct usb_interface *interface, | |||
2729 | 2938 | ||
2730 | INIT_WORK(&dev->cmd_work, pn533_wq_cmd); | 2939 | INIT_WORK(&dev->cmd_work, pn533_wq_cmd); |
2731 | INIT_WORK(&dev->cmd_complete_work, pn533_wq_cmd_complete); | 2940 | INIT_WORK(&dev->cmd_complete_work, pn533_wq_cmd_complete); |
2732 | INIT_WORK(&dev->mi_work, pn533_wq_mi_recv); | 2941 | INIT_WORK(&dev->mi_rx_work, pn533_wq_mi_recv); |
2942 | INIT_WORK(&dev->mi_tx_work, pn533_wq_mi_send); | ||
2733 | INIT_WORK(&dev->tg_work, pn533_wq_tg_get_data); | 2943 | INIT_WORK(&dev->tg_work, pn533_wq_tg_get_data); |
2734 | INIT_WORK(&dev->poll_work, pn533_wq_poll); | 2944 | INIT_DELAYED_WORK(&dev->poll_work, pn533_wq_poll); |
2945 | INIT_WORK(&dev->rf_work, pn533_wq_rf); | ||
2735 | dev->wq = alloc_ordered_workqueue("pn533", 0); | 2946 | dev->wq = alloc_ordered_workqueue("pn533", 0); |
2736 | if (dev->wq == NULL) | 2947 | if (dev->wq == NULL) |
2737 | goto error; | 2948 | goto error; |
@@ -2741,6 +2952,7 @@ static int pn533_probe(struct usb_interface *interface, | |||
2741 | dev->listen_timer.function = pn533_listen_mode_timer; | 2952 | dev->listen_timer.function = pn533_listen_mode_timer; |
2742 | 2953 | ||
2743 | skb_queue_head_init(&dev->resp_q); | 2954 | skb_queue_head_init(&dev->resp_q); |
2955 | skb_queue_head_init(&dev->fragment_skb); | ||
2744 | 2956 | ||
2745 | INIT_LIST_HEAD(&dev->cmd_queue); | 2957 | INIT_LIST_HEAD(&dev->cmd_queue); |
2746 | 2958 | ||
@@ -2842,6 +3054,7 @@ static void pn533_disconnect(struct usb_interface *interface) | |||
2842 | usb_kill_urb(dev->in_urb); | 3054 | usb_kill_urb(dev->in_urb); |
2843 | usb_kill_urb(dev->out_urb); | 3055 | usb_kill_urb(dev->out_urb); |
2844 | 3056 | ||
3057 | flush_delayed_work(&dev->poll_work); | ||
2845 | destroy_workqueue(dev->wq); | 3058 | destroy_workqueue(dev->wq); |
2846 | 3059 | ||
2847 | skb_queue_purge(&dev->resp_q); | 3060 | skb_queue_purge(&dev->resp_q); |
diff --git a/drivers/nfc/pn544/i2c.c b/drivers/nfc/pn544/i2c.c index 8cf64c19f022..01e27d4bdd0d 100644 --- a/drivers/nfc/pn544/i2c.c +++ b/drivers/nfc/pn544/i2c.c | |||
@@ -25,11 +25,14 @@ | |||
25 | #include <linux/miscdevice.h> | 25 | #include <linux/miscdevice.h> |
26 | #include <linux/interrupt.h> | 26 | #include <linux/interrupt.h> |
27 | #include <linux/delay.h> | 27 | #include <linux/delay.h> |
28 | 28 | #include <linux/nfc.h> | |
29 | #include <linux/firmware.h> | ||
30 | #include <linux/unaligned/access_ok.h> | ||
29 | #include <linux/platform_data/pn544.h> | 31 | #include <linux/platform_data/pn544.h> |
30 | 32 | ||
31 | #include <net/nfc/hci.h> | 33 | #include <net/nfc/hci.h> |
32 | #include <net/nfc/llc.h> | 34 | #include <net/nfc/llc.h> |
35 | #include <net/nfc/nfc.h> | ||
33 | 36 | ||
34 | #include "pn544.h" | 37 | #include "pn544.h" |
35 | 38 | ||
@@ -55,6 +58,58 @@ MODULE_DEVICE_TABLE(i2c, pn544_hci_i2c_id_table); | |||
55 | 58 | ||
56 | #define PN544_HCI_I2C_DRIVER_NAME "pn544_hci_i2c" | 59 | #define PN544_HCI_I2C_DRIVER_NAME "pn544_hci_i2c" |
57 | 60 | ||
61 | #define PN544_FW_CMD_WRITE 0x08 | ||
62 | #define PN544_FW_CMD_CHECK 0x06 | ||
63 | |||
64 | struct pn544_i2c_fw_frame_write { | ||
65 | u8 cmd; | ||
66 | u16 be_length; | ||
67 | u8 be_dest_addr[3]; | ||
68 | u16 be_datalen; | ||
69 | u8 data[]; | ||
70 | } __packed; | ||
71 | |||
72 | struct pn544_i2c_fw_frame_check { | ||
73 | u8 cmd; | ||
74 | u16 be_length; | ||
75 | u8 be_start_addr[3]; | ||
76 | u16 be_datalen; | ||
77 | u16 be_crc; | ||
78 | } __packed; | ||
79 | |||
80 | struct pn544_i2c_fw_frame_response { | ||
81 | u8 status; | ||
82 | u16 be_length; | ||
83 | } __packed; | ||
84 | |||
85 | struct pn544_i2c_fw_blob { | ||
86 | u32 be_size; | ||
87 | u32 be_destaddr; | ||
88 | u8 data[]; | ||
89 | }; | ||
90 | |||
91 | #define PN544_FW_CMD_RESULT_TIMEOUT 0x01 | ||
92 | #define PN544_FW_CMD_RESULT_BAD_CRC 0x02 | ||
93 | #define PN544_FW_CMD_RESULT_ACCESS_DENIED 0x08 | ||
94 | #define PN544_FW_CMD_RESULT_PROTOCOL_ERROR 0x0B | ||
95 | #define PN544_FW_CMD_RESULT_INVALID_PARAMETER 0x11 | ||
96 | #define PN544_FW_CMD_RESULT_INVALID_LENGTH 0x18 | ||
97 | #define PN544_FW_CMD_RESULT_WRITE_FAILED 0x74 | ||
98 | |||
99 | #define MIN(X, Y) ((X) < (Y) ? (X) : (Y)) | ||
100 | |||
101 | #define PN544_FW_WRITE_BUFFER_MAX_LEN 0x9f7 | ||
102 | #define PN544_FW_I2C_MAX_PAYLOAD PN544_HCI_I2C_LLC_MAX_SIZE | ||
103 | #define PN544_FW_I2C_WRITE_FRAME_HEADER_LEN 8 | ||
104 | #define PN544_FW_I2C_WRITE_DATA_MAX_LEN MIN((PN544_FW_I2C_MAX_PAYLOAD -\ | ||
105 | PN544_FW_I2C_WRITE_FRAME_HEADER_LEN),\ | ||
106 | PN544_FW_WRITE_BUFFER_MAX_LEN) | ||
107 | |||
108 | #define FW_WORK_STATE_IDLE 1 | ||
109 | #define FW_WORK_STATE_START 2 | ||
110 | #define FW_WORK_STATE_WAIT_WRITE_ANSWER 3 | ||
111 | #define FW_WORK_STATE_WAIT_CHECK_ANSWER 4 | ||
112 | |||
58 | struct pn544_i2c_phy { | 113 | struct pn544_i2c_phy { |
59 | struct i2c_client *i2c_dev; | 114 | struct i2c_client *i2c_dev; |
60 | struct nfc_hci_dev *hdev; | 115 | struct nfc_hci_dev *hdev; |
@@ -64,7 +119,18 @@ struct pn544_i2c_phy { | |||
64 | unsigned int gpio_fw; | 119 | unsigned int gpio_fw; |
65 | unsigned int en_polarity; | 120 | unsigned int en_polarity; |
66 | 121 | ||
122 | struct work_struct fw_work; | ||
123 | int fw_work_state; | ||
124 | char firmware_name[NFC_FIRMWARE_NAME_MAXSIZE + 1]; | ||
125 | const struct firmware *fw; | ||
126 | u32 fw_blob_dest_addr; | ||
127 | size_t fw_blob_size; | ||
128 | const u8 *fw_blob_data; | ||
129 | size_t fw_written; | ||
130 | int fw_cmd_result; | ||
131 | |||
67 | int powered; | 132 | int powered; |
133 | int run_mode; | ||
68 | 134 | ||
69 | int hard_fault; /* | 135 | int hard_fault; /* |
70 | * < 0 if hardware error occured (e.g. i2c err) | 136 | * < 0 if hardware error occured (e.g. i2c err) |
@@ -122,15 +188,22 @@ out: | |||
122 | gpio_set_value(phy->gpio_en, !phy->en_polarity); | 188 | gpio_set_value(phy->gpio_en, !phy->en_polarity); |
123 | } | 189 | } |
124 | 190 | ||
191 | static void pn544_hci_i2c_enable_mode(struct pn544_i2c_phy *phy, int run_mode) | ||
192 | { | ||
193 | gpio_set_value(phy->gpio_fw, run_mode == PN544_FW_MODE ? 1 : 0); | ||
194 | gpio_set_value(phy->gpio_en, phy->en_polarity); | ||
195 | usleep_range(10000, 15000); | ||
196 | |||
197 | phy->run_mode = run_mode; | ||
198 | } | ||
199 | |||
125 | static int pn544_hci_i2c_enable(void *phy_id) | 200 | static int pn544_hci_i2c_enable(void *phy_id) |
126 | { | 201 | { |
127 | struct pn544_i2c_phy *phy = phy_id; | 202 | struct pn544_i2c_phy *phy = phy_id; |
128 | 203 | ||
129 | pr_info(DRIVER_DESC ": %s\n", __func__); | 204 | pr_info(DRIVER_DESC ": %s\n", __func__); |
130 | 205 | ||
131 | gpio_set_value(phy->gpio_fw, 0); | 206 | pn544_hci_i2c_enable_mode(phy, PN544_HCI_MODE); |
132 | gpio_set_value(phy->gpio_en, phy->en_polarity); | ||
133 | usleep_range(10000, 15000); | ||
134 | 207 | ||
135 | phy->powered = 1; | 208 | phy->powered = 1; |
136 | 209 | ||
@@ -305,6 +378,42 @@ flush: | |||
305 | return r; | 378 | return r; |
306 | } | 379 | } |
307 | 380 | ||
381 | static int pn544_hci_i2c_fw_read_status(struct pn544_i2c_phy *phy) | ||
382 | { | ||
383 | int r; | ||
384 | struct pn544_i2c_fw_frame_response response; | ||
385 | struct i2c_client *client = phy->i2c_dev; | ||
386 | |||
387 | r = i2c_master_recv(client, (char *) &response, sizeof(response)); | ||
388 | if (r != sizeof(response)) { | ||
389 | dev_err(&client->dev, "cannot read fw status\n"); | ||
390 | return -EIO; | ||
391 | } | ||
392 | |||
393 | usleep_range(3000, 6000); | ||
394 | |||
395 | switch (response.status) { | ||
396 | case 0: | ||
397 | return 0; | ||
398 | case PN544_FW_CMD_RESULT_TIMEOUT: | ||
399 | return -ETIMEDOUT; | ||
400 | case PN544_FW_CMD_RESULT_BAD_CRC: | ||
401 | return -ENODATA; | ||
402 | case PN544_FW_CMD_RESULT_ACCESS_DENIED: | ||
403 | return -EACCES; | ||
404 | case PN544_FW_CMD_RESULT_PROTOCOL_ERROR: | ||
405 | return -EPROTO; | ||
406 | case PN544_FW_CMD_RESULT_INVALID_PARAMETER: | ||
407 | return -EINVAL; | ||
408 | case PN544_FW_CMD_RESULT_INVALID_LENGTH: | ||
409 | return -EBADMSG; | ||
410 | case PN544_FW_CMD_RESULT_WRITE_FAILED: | ||
411 | return -EIO; | ||
412 | default: | ||
413 | return -EIO; | ||
414 | } | ||
415 | } | ||
416 | |||
308 | /* | 417 | /* |
309 | * Reads an shdlc frame from the chip. This is not as straightforward as it | 418 | * Reads an shdlc frame from the chip. This is not as straightforward as it |
310 | * seems. There are cases where we could loose the frame start synchronization. | 419 | * seems. There are cases where we could loose the frame start synchronization. |
@@ -339,19 +448,23 @@ static irqreturn_t pn544_hci_i2c_irq_thread_fn(int irq, void *phy_id) | |||
339 | if (phy->hard_fault != 0) | 448 | if (phy->hard_fault != 0) |
340 | return IRQ_HANDLED; | 449 | return IRQ_HANDLED; |
341 | 450 | ||
342 | r = pn544_hci_i2c_read(phy, &skb); | 451 | if (phy->run_mode == PN544_FW_MODE) { |
343 | if (r == -EREMOTEIO) { | 452 | phy->fw_cmd_result = pn544_hci_i2c_fw_read_status(phy); |
344 | phy->hard_fault = r; | 453 | schedule_work(&phy->fw_work); |
454 | } else { | ||
455 | r = pn544_hci_i2c_read(phy, &skb); | ||
456 | if (r == -EREMOTEIO) { | ||
457 | phy->hard_fault = r; | ||
345 | 458 | ||
346 | nfc_hci_recv_frame(phy->hdev, NULL); | 459 | nfc_hci_recv_frame(phy->hdev, NULL); |
347 | 460 | ||
348 | return IRQ_HANDLED; | 461 | return IRQ_HANDLED; |
349 | } else if ((r == -ENOMEM) || (r == -EBADMSG)) { | 462 | } else if ((r == -ENOMEM) || (r == -EBADMSG)) { |
350 | return IRQ_HANDLED; | 463 | return IRQ_HANDLED; |
351 | } | 464 | } |
352 | |||
353 | nfc_hci_recv_frame(phy->hdev, skb); | ||
354 | 465 | ||
466 | nfc_hci_recv_frame(phy->hdev, skb); | ||
467 | } | ||
355 | return IRQ_HANDLED; | 468 | return IRQ_HANDLED; |
356 | } | 469 | } |
357 | 470 | ||
@@ -361,6 +474,215 @@ static struct nfc_phy_ops i2c_phy_ops = { | |||
361 | .disable = pn544_hci_i2c_disable, | 474 | .disable = pn544_hci_i2c_disable, |
362 | }; | 475 | }; |
363 | 476 | ||
477 | static int pn544_hci_i2c_fw_download(void *phy_id, const char *firmware_name) | ||
478 | { | ||
479 | struct pn544_i2c_phy *phy = phy_id; | ||
480 | |||
481 | pr_info(DRIVER_DESC ": Starting Firmware Download (%s)\n", | ||
482 | firmware_name); | ||
483 | |||
484 | strcpy(phy->firmware_name, firmware_name); | ||
485 | |||
486 | phy->fw_work_state = FW_WORK_STATE_START; | ||
487 | |||
488 | schedule_work(&phy->fw_work); | ||
489 | |||
490 | return 0; | ||
491 | } | ||
492 | |||
493 | static void pn544_hci_i2c_fw_work_complete(struct pn544_i2c_phy *phy, | ||
494 | int result) | ||
495 | { | ||
496 | pr_info(DRIVER_DESC ": Firmware Download Complete, result=%d\n", result); | ||
497 | |||
498 | pn544_hci_i2c_disable(phy); | ||
499 | |||
500 | phy->fw_work_state = FW_WORK_STATE_IDLE; | ||
501 | |||
502 | if (phy->fw) { | ||
503 | release_firmware(phy->fw); | ||
504 | phy->fw = NULL; | ||
505 | } | ||
506 | |||
507 | nfc_fw_download_done(phy->hdev->ndev, phy->firmware_name, (u32) -result); | ||
508 | } | ||
509 | |||
510 | static int pn544_hci_i2c_fw_write_cmd(struct i2c_client *client, u32 dest_addr, | ||
511 | const u8 *data, u16 datalen) | ||
512 | { | ||
513 | u8 frame[PN544_FW_I2C_MAX_PAYLOAD]; | ||
514 | struct pn544_i2c_fw_frame_write *framep; | ||
515 | u16 params_len; | ||
516 | int framelen; | ||
517 | int r; | ||
518 | |||
519 | if (datalen > PN544_FW_I2C_WRITE_DATA_MAX_LEN) | ||
520 | datalen = PN544_FW_I2C_WRITE_DATA_MAX_LEN; | ||
521 | |||
522 | framep = (struct pn544_i2c_fw_frame_write *) frame; | ||
523 | |||
524 | params_len = sizeof(framep->be_dest_addr) + | ||
525 | sizeof(framep->be_datalen) + datalen; | ||
526 | framelen = params_len + sizeof(framep->cmd) + | ||
527 | sizeof(framep->be_length); | ||
528 | |||
529 | framep->cmd = PN544_FW_CMD_WRITE; | ||
530 | |||
531 | put_unaligned_be16(params_len, &framep->be_length); | ||
532 | |||
533 | framep->be_dest_addr[0] = (dest_addr & 0xff0000) >> 16; | ||
534 | framep->be_dest_addr[1] = (dest_addr & 0xff00) >> 8; | ||
535 | framep->be_dest_addr[2] = dest_addr & 0xff; | ||
536 | |||
537 | put_unaligned_be16(datalen, &framep->be_datalen); | ||
538 | |||
539 | memcpy(framep->data, data, datalen); | ||
540 | |||
541 | r = i2c_master_send(client, frame, framelen); | ||
542 | |||
543 | if (r == framelen) | ||
544 | return datalen; | ||
545 | else if (r < 0) | ||
546 | return r; | ||
547 | else | ||
548 | return -EIO; | ||
549 | } | ||
550 | |||
551 | static int pn544_hci_i2c_fw_check_cmd(struct i2c_client *client, u32 start_addr, | ||
552 | const u8 *data, u16 datalen) | ||
553 | { | ||
554 | struct pn544_i2c_fw_frame_check frame; | ||
555 | int r; | ||
556 | u16 crc; | ||
557 | |||
558 | /* calculate local crc for the data we want to check */ | ||
559 | crc = crc_ccitt(0xffff, data, datalen); | ||
560 | |||
561 | frame.cmd = PN544_FW_CMD_CHECK; | ||
562 | |||
563 | put_unaligned_be16(sizeof(frame.be_start_addr) + | ||
564 | sizeof(frame.be_datalen) + sizeof(frame.be_crc), | ||
565 | &frame.be_length); | ||
566 | |||
567 | /* tell the chip the memory region to which our crc applies */ | ||
568 | frame.be_start_addr[0] = (start_addr & 0xff0000) >> 16; | ||
569 | frame.be_start_addr[1] = (start_addr & 0xff00) >> 8; | ||
570 | frame.be_start_addr[2] = start_addr & 0xff; | ||
571 | |||
572 | put_unaligned_be16(datalen, &frame.be_datalen); | ||
573 | |||
574 | /* | ||
575 | * and give our local crc. Chip will calculate its own crc for the | ||
576 | * region and compare with ours. | ||
577 | */ | ||
578 | put_unaligned_be16(crc, &frame.be_crc); | ||
579 | |||
580 | r = i2c_master_send(client, (const char *) &frame, sizeof(frame)); | ||
581 | |||
582 | if (r == sizeof(frame)) | ||
583 | return 0; | ||
584 | else if (r < 0) | ||
585 | return r; | ||
586 | else | ||
587 | return -EIO; | ||
588 | } | ||
589 | |||
590 | static int pn544_hci_i2c_fw_write_chunk(struct pn544_i2c_phy *phy) | ||
591 | { | ||
592 | int r; | ||
593 | |||
594 | r = pn544_hci_i2c_fw_write_cmd(phy->i2c_dev, | ||
595 | phy->fw_blob_dest_addr + phy->fw_written, | ||
596 | phy->fw_blob_data + phy->fw_written, | ||
597 | phy->fw_blob_size - phy->fw_written); | ||
598 | if (r < 0) | ||
599 | return r; | ||
600 | |||
601 | phy->fw_written += r; | ||
602 | phy->fw_work_state = FW_WORK_STATE_WAIT_WRITE_ANSWER; | ||
603 | |||
604 | return 0; | ||
605 | } | ||
606 | |||
607 | static void pn544_hci_i2c_fw_work(struct work_struct *work) | ||
608 | { | ||
609 | struct pn544_i2c_phy *phy = container_of(work, struct pn544_i2c_phy, | ||
610 | fw_work); | ||
611 | int r; | ||
612 | struct pn544_i2c_fw_blob *blob; | ||
613 | |||
614 | switch (phy->fw_work_state) { | ||
615 | case FW_WORK_STATE_START: | ||
616 | pn544_hci_i2c_enable_mode(phy, PN544_FW_MODE); | ||
617 | |||
618 | r = request_firmware(&phy->fw, phy->firmware_name, | ||
619 | &phy->i2c_dev->dev); | ||
620 | if (r < 0) | ||
621 | goto exit_state_start; | ||
622 | |||
623 | blob = (struct pn544_i2c_fw_blob *) phy->fw->data; | ||
624 | phy->fw_blob_size = get_unaligned_be32(&blob->be_size); | ||
625 | phy->fw_blob_dest_addr = get_unaligned_be32(&blob->be_destaddr); | ||
626 | phy->fw_blob_data = blob->data; | ||
627 | |||
628 | phy->fw_written = 0; | ||
629 | r = pn544_hci_i2c_fw_write_chunk(phy); | ||
630 | |||
631 | exit_state_start: | ||
632 | if (r < 0) | ||
633 | pn544_hci_i2c_fw_work_complete(phy, r); | ||
634 | break; | ||
635 | |||
636 | case FW_WORK_STATE_WAIT_WRITE_ANSWER: | ||
637 | r = phy->fw_cmd_result; | ||
638 | if (r < 0) | ||
639 | goto exit_state_wait_write_answer; | ||
640 | |||
641 | if (phy->fw_written == phy->fw_blob_size) { | ||
642 | r = pn544_hci_i2c_fw_check_cmd(phy->i2c_dev, | ||
643 | phy->fw_blob_dest_addr, | ||
644 | phy->fw_blob_data, | ||
645 | phy->fw_blob_size); | ||
646 | if (r < 0) | ||
647 | goto exit_state_wait_write_answer; | ||
648 | phy->fw_work_state = FW_WORK_STATE_WAIT_CHECK_ANSWER; | ||
649 | break; | ||
650 | } | ||
651 | |||
652 | r = pn544_hci_i2c_fw_write_chunk(phy); | ||
653 | |||
654 | exit_state_wait_write_answer: | ||
655 | if (r < 0) | ||
656 | pn544_hci_i2c_fw_work_complete(phy, r); | ||
657 | break; | ||
658 | |||
659 | case FW_WORK_STATE_WAIT_CHECK_ANSWER: | ||
660 | r = phy->fw_cmd_result; | ||
661 | if (r < 0) | ||
662 | goto exit_state_wait_check_answer; | ||
663 | |||
664 | blob = (struct pn544_i2c_fw_blob *) (phy->fw_blob_data + | ||
665 | phy->fw_blob_size); | ||
666 | phy->fw_blob_size = get_unaligned_be32(&blob->be_size); | ||
667 | if (phy->fw_blob_size != 0) { | ||
668 | phy->fw_blob_dest_addr = | ||
669 | get_unaligned_be32(&blob->be_destaddr); | ||
670 | phy->fw_blob_data = blob->data; | ||
671 | |||
672 | phy->fw_written = 0; | ||
673 | r = pn544_hci_i2c_fw_write_chunk(phy); | ||
674 | } | ||
675 | |||
676 | exit_state_wait_check_answer: | ||
677 | if (r < 0 || phy->fw_blob_size == 0) | ||
678 | pn544_hci_i2c_fw_work_complete(phy, r); | ||
679 | break; | ||
680 | |||
681 | default: | ||
682 | break; | ||
683 | } | ||
684 | } | ||
685 | |||
364 | static int pn544_hci_i2c_probe(struct i2c_client *client, | 686 | static int pn544_hci_i2c_probe(struct i2c_client *client, |
365 | const struct i2c_device_id *id) | 687 | const struct i2c_device_id *id) |
366 | { | 688 | { |
@@ -384,6 +706,9 @@ static int pn544_hci_i2c_probe(struct i2c_client *client, | |||
384 | return -ENOMEM; | 706 | return -ENOMEM; |
385 | } | 707 | } |
386 | 708 | ||
709 | INIT_WORK(&phy->fw_work, pn544_hci_i2c_fw_work); | ||
710 | phy->fw_work_state = FW_WORK_STATE_IDLE; | ||
711 | |||
387 | phy->i2c_dev = client; | 712 | phy->i2c_dev = client; |
388 | i2c_set_clientdata(client, phy); | 713 | i2c_set_clientdata(client, phy); |
389 | 714 | ||
@@ -420,7 +745,8 @@ static int pn544_hci_i2c_probe(struct i2c_client *client, | |||
420 | 745 | ||
421 | r = pn544_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, | 746 | r = pn544_hci_probe(phy, &i2c_phy_ops, LLC_SHDLC_NAME, |
422 | PN544_I2C_FRAME_HEADROOM, PN544_I2C_FRAME_TAILROOM, | 747 | PN544_I2C_FRAME_HEADROOM, PN544_I2C_FRAME_TAILROOM, |
423 | PN544_HCI_I2C_LLC_MAX_PAYLOAD, &phy->hdev); | 748 | PN544_HCI_I2C_LLC_MAX_PAYLOAD, |
749 | pn544_hci_i2c_fw_download, &phy->hdev); | ||
424 | if (r < 0) | 750 | if (r < 0) |
425 | goto err_hci; | 751 | goto err_hci; |
426 | 752 | ||
@@ -443,6 +769,10 @@ static int pn544_hci_i2c_remove(struct i2c_client *client) | |||
443 | 769 | ||
444 | dev_dbg(&client->dev, "%s\n", __func__); | 770 | dev_dbg(&client->dev, "%s\n", __func__); |
445 | 771 | ||
772 | cancel_work_sync(&phy->fw_work); | ||
773 | if (phy->fw_work_state != FW_WORK_STATE_IDLE) | ||
774 | pn544_hci_i2c_fw_work_complete(phy, -ENODEV); | ||
775 | |||
446 | pn544_hci_remove(phy->hdev); | 776 | pn544_hci_remove(phy->hdev); |
447 | 777 | ||
448 | if (phy->powered) | 778 | if (phy->powered) |
diff --git a/drivers/nfc/pn544/mei.c b/drivers/nfc/pn544/mei.c index b5d3d18179eb..ee67de50c36f 100644 --- a/drivers/nfc/pn544/mei.c +++ b/drivers/nfc/pn544/mei.c | |||
@@ -45,7 +45,7 @@ static int pn544_mei_probe(struct mei_cl_device *device, | |||
45 | 45 | ||
46 | r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME, | 46 | r = pn544_hci_probe(phy, &mei_phy_ops, LLC_NOP_NAME, |
47 | MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD, | 47 | MEI_NFC_HEADER_SIZE, 0, MEI_NFC_MAX_HCI_PAYLOAD, |
48 | &phy->hdev); | 48 | NULL, &phy->hdev); |
49 | if (r < 0) { | 49 | if (r < 0) { |
50 | nfc_mei_phy_free(phy); | 50 | nfc_mei_phy_free(phy); |
51 | 51 | ||
diff --git a/drivers/nfc/pn544/pn544.c b/drivers/nfc/pn544/pn544.c index 0d17da7675b7..078e62feba17 100644 --- a/drivers/nfc/pn544/pn544.c +++ b/drivers/nfc/pn544/pn544.c | |||
@@ -31,9 +31,6 @@ | |||
31 | /* Timing restrictions (ms) */ | 31 | /* Timing restrictions (ms) */ |
32 | #define PN544_HCI_RESETVEN_TIME 30 | 32 | #define PN544_HCI_RESETVEN_TIME 30 |
33 | 33 | ||
34 | #define HCI_MODE 0 | ||
35 | #define FW_MODE 1 | ||
36 | |||
37 | enum pn544_state { | 34 | enum pn544_state { |
38 | PN544_ST_COLD, | 35 | PN544_ST_COLD, |
39 | PN544_ST_FW_READY, | 36 | PN544_ST_FW_READY, |
@@ -130,6 +127,8 @@ struct pn544_hci_info { | |||
130 | int async_cb_type; | 127 | int async_cb_type; |
131 | data_exchange_cb_t async_cb; | 128 | data_exchange_cb_t async_cb; |
132 | void *async_cb_context; | 129 | void *async_cb_context; |
130 | |||
131 | fw_download_t fw_download; | ||
133 | }; | 132 | }; |
134 | 133 | ||
135 | static int pn544_hci_open(struct nfc_hci_dev *hdev) | 134 | static int pn544_hci_open(struct nfc_hci_dev *hdev) |
@@ -782,6 +781,17 @@ exit: | |||
782 | return r; | 781 | return r; |
783 | } | 782 | } |
784 | 783 | ||
784 | static int pn544_hci_fw_download(struct nfc_hci_dev *hdev, | ||
785 | const char *firmware_name) | ||
786 | { | ||
787 | struct pn544_hci_info *info = nfc_hci_get_clientdata(hdev); | ||
788 | |||
789 | if (info->fw_download == NULL) | ||
790 | return -ENOTSUPP; | ||
791 | |||
792 | return info->fw_download(info->phy_id, firmware_name); | ||
793 | } | ||
794 | |||
785 | static struct nfc_hci_ops pn544_hci_ops = { | 795 | static struct nfc_hci_ops pn544_hci_ops = { |
786 | .open = pn544_hci_open, | 796 | .open = pn544_hci_open, |
787 | .close = pn544_hci_close, | 797 | .close = pn544_hci_close, |
@@ -796,11 +806,12 @@ static struct nfc_hci_ops pn544_hci_ops = { | |||
796 | .tm_send = pn544_hci_tm_send, | 806 | .tm_send = pn544_hci_tm_send, |
797 | .check_presence = pn544_hci_check_presence, | 807 | .check_presence = pn544_hci_check_presence, |
798 | .event_received = pn544_hci_event_received, | 808 | .event_received = pn544_hci_event_received, |
809 | .fw_download = pn544_hci_fw_download, | ||
799 | }; | 810 | }; |
800 | 811 | ||
801 | int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, | 812 | int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, |
802 | int phy_headroom, int phy_tailroom, int phy_payload, | 813 | int phy_headroom, int phy_tailroom, int phy_payload, |
803 | struct nfc_hci_dev **hdev) | 814 | fw_download_t fw_download, struct nfc_hci_dev **hdev) |
804 | { | 815 | { |
805 | struct pn544_hci_info *info; | 816 | struct pn544_hci_info *info; |
806 | u32 protocols; | 817 | u32 protocols; |
@@ -816,6 +827,7 @@ int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, | |||
816 | 827 | ||
817 | info->phy_ops = phy_ops; | 828 | info->phy_ops = phy_ops; |
818 | info->phy_id = phy_id; | 829 | info->phy_id = phy_id; |
830 | info->fw_download = fw_download; | ||
819 | info->state = PN544_ST_COLD; | 831 | info->state = PN544_ST_COLD; |
820 | mutex_init(&info->info_lock); | 832 | mutex_init(&info->info_lock); |
821 | 833 | ||
diff --git a/drivers/nfc/pn544/pn544.h b/drivers/nfc/pn544/pn544.h index f47c6454914b..01020e585443 100644 --- a/drivers/nfc/pn544/pn544.h +++ b/drivers/nfc/pn544/pn544.h | |||
@@ -24,9 +24,14 @@ | |||
24 | 24 | ||
25 | #define DRIVER_DESC "HCI NFC driver for PN544" | 25 | #define DRIVER_DESC "HCI NFC driver for PN544" |
26 | 26 | ||
27 | #define PN544_HCI_MODE 0 | ||
28 | #define PN544_FW_MODE 1 | ||
29 | |||
30 | typedef int (*fw_download_t)(void *context, const char *firmware_name); | ||
31 | |||
27 | int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, | 32 | int pn544_hci_probe(void *phy_id, struct nfc_phy_ops *phy_ops, char *llc_name, |
28 | int phy_headroom, int phy_tailroom, int phy_payload, | 33 | int phy_headroom, int phy_tailroom, int phy_payload, |
29 | struct nfc_hci_dev **hdev); | 34 | fw_download_t fw_download, struct nfc_hci_dev **hdev); |
30 | void pn544_hci_remove(struct nfc_hci_dev *hdev); | 35 | void pn544_hci_remove(struct nfc_hci_dev *hdev); |
31 | 36 | ||
32 | #endif /* __LOCAL_PN544_H_ */ | 37 | #endif /* __LOCAL_PN544_H_ */ |