aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/nfc/pn533.c
diff options
context:
space:
mode:
authorWaldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com>2013-04-03 02:01:58 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2013-04-11 10:29:00 -0400
commit63123108f45663a93cfbb7480050043c04d202bf (patch)
treecbe71331091eee803f7d45b1a2a8bde3ea8f024f /drivers/nfc/pn533.c
parent064f370c5fd982e1264c03f5b704e00f5e41eb36 (diff)
NFC: pn533: Reword all std frame logic funct
Signed-off-by: Waldemar Rymarkiewicz <waldemar.rymarkiewicz@tieto.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/nfc/pn533.c')
-rw-r--r--drivers/nfc/pn533.c121
1 files changed, 61 insertions, 60 deletions
diff --git a/drivers/nfc/pn533.c b/drivers/nfc/pn533.c
index 73d39f3fbdf9..8e809e083c33 100644
--- a/drivers/nfc/pn533.c
+++ b/drivers/nfc/pn533.c
@@ -78,32 +78,32 @@ MODULE_DEVICE_TABLE(usb, pn533_table);
78/* How much time we spend listening for initiators */ 78/* How much time we spend listening for initiators */
79#define PN533_LISTEN_TIME 2 79#define PN533_LISTEN_TIME 2
80 80
81/* frame definitions */ 81/* Standard pn533 frame definitions */
82#define PN533_FRAME_HEADER_LEN (sizeof(struct pn533_frame) \ 82#define PN533_STD_FRAME_HEADER_LEN (sizeof(struct pn533_std_frame) \
83 + 2) /* data[0] TFI, data[1] CC */ 83 + 2) /* data[0] TFI, data[1] CC */
84#define PN533_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/ 84#define PN533_STD_FRAME_TAIL_LEN 2 /* data[len] DCS, data[len + 1] postamble*/
85 85
86/* 86/*
87 * Max extended frame payload len, excluding TFI and CC 87 * Max extended frame payload len, excluding TFI and CC
88 * which are already in PN533_FRAME_HEADER_LEN. 88 * which are already in PN533_FRAME_HEADER_LEN.
89 */ 89 */
90#define PN533_FRAME_MAX_PAYLOAD_LEN 263 90#define PN533_STD_FRAME_MAX_PAYLOAD_LEN 263
91 91
92#define PN533_FRAME_ACK_SIZE 6 /* Preamble (1), SoPC (2), ACK Code (2), 92#define PN533_STD_FRAME_ACK_SIZE 6 /* Preamble (1), SoPC (2), ACK Code (2),
93 Postamble (1) */ 93 Postamble (1) */
94#define PN533_FRAME_CHECKSUM(f) (f->data[f->datalen]) 94#define PN533_STD_FRAME_CHECKSUM(f) (f->data[f->datalen])
95#define PN533_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1]) 95#define PN533_STD_FRAME_POSTAMBLE(f) (f->data[f->datalen + 1])
96 96
97/* start of frame */ 97/* start of frame */
98#define PN533_SOF 0x00FF 98#define PN533_STD_FRAME_SOF 0x00FF
99 99
100/* frame identifier: in/out/error */ 100/* standard frame identifier: in/out/error */
101#define PN533_FRAME_IDENTIFIER(f) (f->data[0]) 101#define PN533_STD_FRAME_IDENTIFIER(f) (f->data[0]) /* TFI */
102#define PN533_DIR_OUT 0xD4 102#define PN533_STD_FRAME_DIR_OUT 0xD4
103#define PN533_DIR_IN 0xD5 103#define PN533_STD_FRAME_DIR_IN 0xD5
104 104
105/* PN533 Commands */ 105/* PN533 Commands */
106#define PN533_FRAME_CMD(f) (f->data[1]) 106#define PN533_STD_FRAME_CMD(f) (f->data[1])
107 107
108#define PN533_CMD_GET_FIRMWARE_VERSION 0x02 108#define PN533_CMD_GET_FIRMWARE_VERSION 0x02
109#define PN533_CMD_RF_CONFIGURATION 0x32 109#define PN533_CMD_RF_CONFIGURATION 0x32
@@ -369,7 +369,7 @@ struct pn533_cmd {
369 void *arg; 369 void *arg;
370}; 370};
371 371
372struct pn533_frame { 372struct pn533_std_frame {
373 u8 preamble; 373 u8 preamble;
374 __be16 start_frame; 374 __be16 start_frame;
375 u8 datalen; 375 u8 datalen;
@@ -394,13 +394,13 @@ struct pn533_frame_ops {
394}; 394};
395 395
396/* The rule: value + checksum = 0 */ 396/* The rule: value + checksum = 0 */
397static inline u8 pn533_checksum(u8 value) 397static inline u8 pn533_std_checksum(u8 value)
398{ 398{
399 return ~value + 1; 399 return ~value + 1;
400} 400}
401 401
402/* The rule: sum(data elements) + checksum = 0 */ 402/* The rule: sum(data elements) + checksum = 0 */
403static u8 pn533_data_checksum(u8 *data, int datalen) 403static u8 pn533_std_data_checksum(u8 *data, int datalen)
404{ 404{
405 u8 sum = 0; 405 u8 sum = 0;
406 int i; 406 int i;
@@ -408,61 +408,61 @@ static u8 pn533_data_checksum(u8 *data, int datalen)
408 for (i = 0; i < datalen; i++) 408 for (i = 0; i < datalen; i++)
409 sum += data[i]; 409 sum += data[i];
410 410
411 return pn533_checksum(sum); 411 return pn533_std_checksum(sum);
412} 412}
413 413
414static void pn533_tx_frame_init(void *_frame, u8 cmd_code) 414static void pn533_std_tx_frame_init(void *_frame, u8 cmd_code)
415{ 415{
416 struct pn533_frame *frame = _frame; 416 struct pn533_std_frame *frame = _frame;
417 417
418 frame->preamble = 0; 418 frame->preamble = 0;
419 frame->start_frame = cpu_to_be16(PN533_SOF); 419 frame->start_frame = cpu_to_be16(PN533_STD_FRAME_SOF);
420 PN533_FRAME_IDENTIFIER(frame) = PN533_DIR_OUT; 420 PN533_STD_FRAME_IDENTIFIER(frame) = PN533_STD_FRAME_DIR_OUT;
421 PN533_FRAME_CMD(frame) = cmd_code; 421 PN533_STD_FRAME_CMD(frame) = cmd_code;
422 frame->datalen = 2; 422 frame->datalen = 2;
423} 423}
424 424
425static void pn533_tx_frame_finish(void *_frame) 425static void pn533_std_tx_frame_finish(void *_frame)
426{ 426{
427 struct pn533_frame *frame = _frame; 427 struct pn533_std_frame *frame = _frame;
428 428
429 frame->datalen_checksum = pn533_checksum(frame->datalen); 429 frame->datalen_checksum = pn533_std_checksum(frame->datalen);
430 430
431 PN533_FRAME_CHECKSUM(frame) = 431 PN533_STD_FRAME_CHECKSUM(frame) =
432 pn533_data_checksum(frame->data, frame->datalen); 432 pn533_std_data_checksum(frame->data, frame->datalen);
433 433
434 PN533_FRAME_POSTAMBLE(frame) = 0; 434 PN533_STD_FRAME_POSTAMBLE(frame) = 0;
435} 435}
436 436
437static void pn533_tx_update_payload_len(void *_frame, int len) 437static void pn533_std_tx_update_payload_len(void *_frame, int len)
438{ 438{
439 struct pn533_frame *frame = _frame; 439 struct pn533_std_frame *frame = _frame;
440 440
441 frame->datalen += len; 441 frame->datalen += len;
442} 442}
443 443
444static bool pn533_rx_frame_is_valid(void *_frame) 444static bool pn533_std_rx_frame_is_valid(void *_frame)
445{ 445{
446 u8 checksum; 446 u8 checksum;
447 struct pn533_frame *frame = _frame; 447 struct pn533_std_frame *frame = _frame;
448 448
449 if (frame->start_frame != cpu_to_be16(PN533_SOF)) 449 if (frame->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
450 return false; 450 return false;
451 451
452 checksum = pn533_checksum(frame->datalen); 452 checksum = pn533_std_checksum(frame->datalen);
453 if (checksum != frame->datalen_checksum) 453 if (checksum != frame->datalen_checksum)
454 return false; 454 return false;
455 455
456 checksum = pn533_data_checksum(frame->data, frame->datalen); 456 checksum = pn533_std_data_checksum(frame->data, frame->datalen);
457 if (checksum != PN533_FRAME_CHECKSUM(frame)) 457 if (checksum != PN533_STD_FRAME_CHECKSUM(frame))
458 return false; 458 return false;
459 459
460 return true; 460 return true;
461} 461}
462 462
463static bool pn533_rx_frame_is_ack(struct pn533_frame *frame) 463static bool pn533_std_rx_frame_is_ack(struct pn533_std_frame *frame)
464{ 464{
465 if (frame->start_frame != cpu_to_be16(PN533_SOF)) 465 if (frame->start_frame != cpu_to_be16(PN533_STD_FRAME_SOF))
466 return false; 466 return false;
467 467
468 if (frame->datalen != 0 || frame->datalen_checksum != 0xFF) 468 if (frame->datalen != 0 || frame->datalen_checksum != 0xFF)
@@ -471,34 +471,35 @@ static bool pn533_rx_frame_is_ack(struct pn533_frame *frame)
471 return true; 471 return true;
472} 472}
473 473
474static inline int pn533_rx_frame_size(void *frame) 474static inline int pn533_std_rx_frame_size(void *frame)
475{ 475{
476 struct pn533_frame *f = frame; 476 struct pn533_std_frame *f = frame;
477 477
478 return sizeof(struct pn533_frame) + f->datalen + PN533_FRAME_TAIL_LEN; 478 return sizeof(struct pn533_std_frame) + f->datalen +
479 PN533_STD_FRAME_TAIL_LEN;
479} 480}
480 481
481static u8 pn533_get_cmd_code(void *frame) 482static u8 pn533_std_get_cmd_code(void *frame)
482{ 483{
483 struct pn533_frame *f = frame; 484 struct pn533_std_frame *f = frame;
484 485
485 return PN533_FRAME_CMD(f); 486 return PN533_STD_FRAME_CMD(f);
486} 487}
487 488
488static struct pn533_frame_ops pn533_std_frame_ops = { 489static struct pn533_frame_ops pn533_std_frame_ops = {
489 .tx_frame_init = pn533_tx_frame_init, 490 .tx_frame_init = pn533_std_tx_frame_init,
490 .tx_frame_finish = pn533_tx_frame_finish, 491 .tx_frame_finish = pn533_std_tx_frame_finish,
491 .tx_update_payload_len = pn533_tx_update_payload_len, 492 .tx_update_payload_len = pn533_std_tx_update_payload_len,
492 .tx_header_len = PN533_FRAME_HEADER_LEN, 493 .tx_header_len = PN533_STD_FRAME_HEADER_LEN,
493 .tx_tail_len = PN533_FRAME_TAIL_LEN, 494 .tx_tail_len = PN533_STD_FRAME_TAIL_LEN,
494 495
495 .rx_is_frame_valid = pn533_rx_frame_is_valid, 496 .rx_is_frame_valid = pn533_std_rx_frame_is_valid,
496 .rx_frame_size = pn533_rx_frame_size, 497 .rx_frame_size = pn533_std_rx_frame_size,
497 .rx_header_len = PN533_FRAME_HEADER_LEN, 498 .rx_header_len = PN533_STD_FRAME_HEADER_LEN,
498 .rx_tail_len = PN533_FRAME_TAIL_LEN, 499 .rx_tail_len = PN533_STD_FRAME_TAIL_LEN,
499 500
500 .max_payload_len = PN533_FRAME_MAX_PAYLOAD_LEN, 501 .max_payload_len = PN533_STD_FRAME_MAX_PAYLOAD_LEN,
501 .get_cmd_code = pn533_get_cmd_code, 502 .get_cmd_code = pn533_std_get_cmd_code,
502}; 503};
503 504
504static bool pn533_rx_frame_is_cmd_response(struct pn533 *dev, void *frame) 505static bool pn533_rx_frame_is_cmd_response(struct pn533 *dev, void *frame)
@@ -575,7 +576,7 @@ static int pn533_submit_urb_for_response(struct pn533 *dev, gfp_t flags)
575static void pn533_recv_ack(struct urb *urb) 576static void pn533_recv_ack(struct urb *urb)
576{ 577{
577 struct pn533 *dev = urb->context; 578 struct pn533 *dev = urb->context;
578 struct pn533_frame *in_frame; 579 struct pn533_std_frame *in_frame;
579 int rc; 580 int rc;
580 581
581 switch (urb->status) { 582 switch (urb->status) {
@@ -598,7 +599,7 @@ static void pn533_recv_ack(struct urb *urb)
598 599
599 in_frame = dev->in_urb->transfer_buffer; 600 in_frame = dev->in_urb->transfer_buffer;
600 601
601 if (!pn533_rx_frame_is_ack(in_frame)) { 602 if (!pn533_std_rx_frame_is_ack(in_frame)) {
602 nfc_dev_err(&dev->interface->dev, "Received an invalid ack"); 603 nfc_dev_err(&dev->interface->dev, "Received an invalid ack");
603 dev->wq_in_error = -EIO; 604 dev->wq_in_error = -EIO;
604 goto sched_wq; 605 goto sched_wq;
@@ -627,7 +628,7 @@ static int pn533_submit_urb_for_ack(struct pn533 *dev, gfp_t flags)
627 628
628static int pn533_send_ack(struct pn533 *dev, gfp_t flags) 629static int pn533_send_ack(struct pn533 *dev, gfp_t flags)
629{ 630{
630 u8 ack[PN533_FRAME_ACK_SIZE] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00}; 631 u8 ack[PN533_STD_FRAME_ACK_SIZE] = {0x00, 0x00, 0xff, 0x00, 0xff, 0x00};
631 /* spec 7.1.1.3: Preamble, SoPC (2), ACK Code (2), Postamble */ 632 /* spec 7.1.1.3: Preamble, SoPC (2), ACK Code (2), Postamble */
632 int rc; 633 int rc;
633 634