aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/nfc
diff options
context:
space:
mode:
authorMark A. Greer <mgreer@animalcreek.com>2014-09-02 18:12:28 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2014-09-07 17:13:43 -0400
commit7a1e5552af61dce180f70c6fafe31553254b3728 (patch)
tree8060c684663bf06b1bf9a57c4831049e10dc9a61 /drivers/nfc
parent5974150dead6da1db415f04a232f79b922f412a0 (diff)
NFC: trf7970a: Prefix TX data when refilling FIFO
When refilling the FIFO with more TX data (using a new SPI transaction), the driver must prefix the TX data with a write to the FIFO I/O Register. This tells the trf7970a that the following data is destined for the FIFO so it can be transmitted. To accomplish this, the driver cannot simply push the prefix data just before the next set of TX data that is to be transmitted because that will overwrite part of the TX data provided by the digital layer. Instead, separate the prefix data and the TX data when calling trf7970a_transmit(). trf7970a_transmit() can then send the prefix and TX data from different memory locations with one spi_sync() operation. This also means that the driver doesn't require any skb "tx_headroom" as provided by the digital layer (see nfc_digital_allocate_device() and digital_skb_alloc()). Also ensure that the prefix is of type 'u8' and not 'char'. Signed-off-by: Mark A. Greer <mgreer@animalcreek.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'drivers/nfc')
-rw-r--r--drivers/nfc/trf7970a.c39
1 files changed, 24 insertions, 15 deletions
diff --git a/drivers/nfc/trf7970a.c b/drivers/nfc/trf7970a.c
index c6216c1cc4b9..8a13daf97747 100644
--- a/drivers/nfc/trf7970a.c
+++ b/drivers/nfc/trf7970a.c
@@ -125,13 +125,6 @@
125 125
126#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */ 126#define TRF7970A_AUTOSUSPEND_DELAY 30000 /* 30 seconds */
127 127
128/* TX data must be prefixed with a FIFO reset cmd, a cmd that depends
129 * on what the current framing is, the address of the TX length byte 1
130 * register (0x1d), and the 2 byte length of the data to be transmitted.
131 * That totals 5 bytes.
132 */
133#define TRF7970A_TX_SKB_HEADROOM 5
134
135#define TRF7970A_RX_SKB_ALLOC_SIZE 256 128#define TRF7970A_RX_SKB_ALLOC_SIZE 256
136 129
137#define TRF7970A_FIFO_SIZE 127 130#define TRF7970A_FIFO_SIZE 127
@@ -515,15 +508,29 @@ static void trf7970a_send_err_upstream(struct trf7970a *trf, int errno)
515} 508}
516 509
517static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb, 510static int trf7970a_transmit(struct trf7970a *trf, struct sk_buff *skb,
518 unsigned int len) 511 unsigned int len, u8 *prefix, unsigned int prefix_len)
519{ 512{
513 struct spi_transfer t[2];
514 struct spi_message m;
520 unsigned int timeout; 515 unsigned int timeout;
521 int ret; 516 int ret;
522 517
523 print_hex_dump_debug("trf7970a tx data: ", DUMP_PREFIX_NONE, 518 print_hex_dump_debug("trf7970a tx data: ", DUMP_PREFIX_NONE,
524 16, 1, skb->data, len, false); 519 16, 1, skb->data, len, false);
525 520
526 ret = spi_write(trf->spi, skb->data, len); 521 spi_message_init(&m);
522
523 memset(&t, 0, sizeof(t));
524
525 t[0].tx_buf = prefix;
526 t[0].len = prefix_len;
527 spi_message_add_tail(&t[0], &m);
528
529 t[1].tx_buf = skb->data;
530 t[1].len = len;
531 spi_message_add_tail(&t[1], &m);
532
533 ret = spi_sync(trf->spi, &m);
527 if (ret) { 534 if (ret) {
528 dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__, 535 dev_err(trf->dev, "%s - Can't send tx data: %d\n", __func__,
529 ret); 536 ret);
@@ -559,6 +566,7 @@ static void trf7970a_fill_fifo(struct trf7970a *trf)
559 unsigned int len; 566 unsigned int len;
560 int ret; 567 int ret;
561 u8 fifo_bytes; 568 u8 fifo_bytes;
569 u8 prefix;
562 570
563 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes); 571 ret = trf7970a_read(trf, TRF7970A_FIFO_STATUS, &fifo_bytes);
564 if (ret) { 572 if (ret) {
@@ -574,7 +582,9 @@ static void trf7970a_fill_fifo(struct trf7970a *trf)
574 len = TRF7970A_FIFO_SIZE - fifo_bytes; 582 len = TRF7970A_FIFO_SIZE - fifo_bytes;
575 len = min(skb->len, len); 583 len = min(skb->len, len);
576 584
577 ret = trf7970a_transmit(trf, skb, len); 585 prefix = TRF7970A_CMD_BIT_CONTINUOUS | TRF7970A_FIFO_IO_REGISTER;
586
587 ret = trf7970a_transmit(trf, skb, len, &prefix, sizeof(prefix));
578 if (ret) 588 if (ret)
579 trf7970a_send_err_upstream(trf, ret); 589 trf7970a_send_err_upstream(trf, ret);
580} 590}
@@ -1108,7 +1118,7 @@ static int trf7970a_in_send_cmd(struct nfc_digital_dev *ddev,
1108 nfc_digital_cmd_complete_t cb, void *arg) 1118 nfc_digital_cmd_complete_t cb, void *arg)
1109{ 1119{
1110 struct trf7970a *trf = nfc_digital_get_drvdata(ddev); 1120 struct trf7970a *trf = nfc_digital_get_drvdata(ddev);
1111 char *prefix; 1121 u8 prefix[5];
1112 unsigned int len; 1122 unsigned int len;
1113 int ret; 1123 int ret;
1114 u8 status; 1124 u8 status;
@@ -1164,11 +1174,11 @@ static int trf7970a_in_send_cmd(struct nfc_digital_dev *ddev,
1164 trf->ignore_timeout = false; 1174 trf->ignore_timeout = false;
1165 1175
1166 len = skb->len; 1176 len = skb->len;
1167 prefix = skb_push(skb, TRF7970A_TX_SKB_HEADROOM);
1168 1177
1169 /* TX data must be prefixed with a FIFO reset cmd, a cmd that depends 1178 /* TX data must be prefixed with a FIFO reset cmd, a cmd that depends
1170 * on what the current framing is, the address of the TX length byte 1 1179 * on what the current framing is, the address of the TX length byte 1
1171 * register (0x1d), and the 2 byte length of the data to be transmitted. 1180 * register (0x1d), and the 2 byte length of the data to be transmitted.
1181 * That totals 5 bytes.
1172 */ 1182 */
1173 prefix[0] = TRF7970A_CMD_BIT_CTRL | 1183 prefix[0] = TRF7970A_CMD_BIT_CTRL |
1174 TRF7970A_CMD_BIT_OPCODE(TRF7970A_CMD_FIFO_RESET); 1184 TRF7970A_CMD_BIT_OPCODE(TRF7970A_CMD_FIFO_RESET);
@@ -1192,7 +1202,7 @@ static int trf7970a_in_send_cmd(struct nfc_digital_dev *ddev,
1192 if (ret) 1202 if (ret)
1193 goto out_err; 1203 goto out_err;
1194 1204
1195 ret = trf7970a_transmit(trf, skb, len); 1205 ret = trf7970a_transmit(trf, skb, len, prefix, sizeof(prefix));
1196 if (ret) { 1206 if (ret) {
1197 kfree_skb(trf->rx_skb); 1207 kfree_skb(trf->rx_skb);
1198 trf->rx_skb = NULL; 1208 trf->rx_skb = NULL;
@@ -1377,8 +1387,7 @@ static int trf7970a_probe(struct spi_device *spi)
1377 1387
1378 trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops, 1388 trf->ddev = nfc_digital_allocate_device(&trf7970a_nfc_ops,
1379 TRF7970A_SUPPORTED_PROTOCOLS, 1389 TRF7970A_SUPPORTED_PROTOCOLS,
1380 NFC_DIGITAL_DRV_CAPS_IN_CRC, TRF7970A_TX_SKB_HEADROOM, 1390 NFC_DIGITAL_DRV_CAPS_IN_CRC, 0, 0);
1381 0);
1382 if (!trf->ddev) { 1391 if (!trf->ddev) {
1383 dev_err(trf->dev, "Can't allocate NFC digital device\n"); 1392 dev_err(trf->dev, "Can't allocate NFC digital device\n");
1384 ret = -ENOMEM; 1393 ret = -ENOMEM;