Lines Matching +full:nfc +full:- +full:spi

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/spi/spi.h>
12 #include <linux/crc-ccitt.h>
13 #include <net/nfc/nci_core.h>
37 /* a NULL skb means we just want the SPI chip select line to raise */ in __nci_spi_send()
39 t.tx_buf = skb->data; in __nci_spi_send()
40 t.len = skb->len; in __nci_spi_send()
47 t.delay.value = nspi->xfer_udelay; in __nci_spi_send()
49 t.speed_hz = nspi->xfer_speed_hz; in __nci_spi_send()
54 return spi_sync(nspi->spi, &m); in __nci_spi_send()
61 unsigned int payload_len = skb->len; in nci_spi_send()
66 /* add the NCI SPI header to the start of the buffer */ in nci_spi_send()
69 hdr[1] = nspi->acknowledge_mode; in nci_spi_send()
73 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in nci_spi_send()
76 crc = crc_ccitt(CRC_INIT, skb->data, skb->len); in nci_spi_send()
82 /* Trick SPI driver to raise chip select */ in nci_spi_send()
87 /* wait for NFC chip hardware handshake to complete */ in nci_spi_send()
90 ret = -ETIME; in nci_spi_send()
96 if (ret != 0 || nspi->acknowledge_mode == NCI_SPI_CRC_DISABLED) in nci_spi_send()
99 reinit_completion(&nspi->req_completion); in nci_spi_send()
101 &nspi->req_completion, in nci_spi_send()
104 if (completion_rc <= 0 || nspi->req_result == ACKNOWLEDGE_NACK) in nci_spi_send()
105 ret = -EIO; in nci_spi_send()
114 /* ---- Interface to NCI SPI drivers ---- */
117 * nci_spi_allocate_spi - allocate a new nci spi
119 * @spi: SPI device
120 * @acknowledge_mode: Acknowledge mode used by the NFC device
124 struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, in nci_spi_allocate_spi() argument
130 nspi = devm_kzalloc(&spi->dev, sizeof(struct nci_spi), GFP_KERNEL); in nci_spi_allocate_spi()
134 nspi->acknowledge_mode = acknowledge_mode; in nci_spi_allocate_spi()
135 nspi->xfer_udelay = delay; in nci_spi_allocate_spi()
136 /* Use controller max SPI speed by default */ in nci_spi_allocate_spi()
137 nspi->xfer_speed_hz = 0; in nci_spi_allocate_spi()
138 nspi->spi = spi; in nci_spi_allocate_spi()
139 nspi->ndev = ndev; in nci_spi_allocate_spi()
140 init_completion(&nspi->req_completion); in nci_spi_allocate_spi()
153 skb = nci_skb_alloc(nspi->ndev, 0, GFP_KERNEL); in send_acknowledge()
155 /* add the NCI SPI header to the start of the buffer */ in send_acknowledge()
162 crc = crc_ccitt(CRC_INIT, skb->data, skb->len); in send_acknowledge()
186 req[1] = nspi->acknowledge_mode; in __nci_spi_read()
190 tx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
197 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
200 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
204 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in __nci_spi_read()
210 skb = nci_skb_alloc(nspi->ndev, rx_len, GFP_KERNEL); in __nci_spi_read()
220 rx.delay.value = nspi->xfer_udelay; in __nci_spi_read()
222 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
225 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
229 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in __nci_spi_read()
244 u16 crc_data = (skb->data[skb->len - 2] << 8) | in nci_spi_check_crc()
245 skb->data[skb->len - 1]; in nci_spi_check_crc()
248 ret = (crc_ccitt(CRC_INIT, skb->data, skb->len - NCI_SPI_CRC_LEN) in nci_spi_check_crc()
251 skb_trim(skb, skb->len - NCI_SPI_CRC_LEN); in nci_spi_check_crc()
260 ret = skb->data[0] >> NCI_SPI_ACK_SHIFT; in nci_spi_get_ack()
269 * nci_spi_read - read frame from NCI SPI drivers
271 * @nspi: The nci spi
275 * is non-interruptible, and has no timeout.
283 /* Retrieve frame from SPI */ in nci_spi_read()
288 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in nci_spi_read()
297 nspi->req_result = nci_spi_get_ack(skb); in nci_spi_read()
298 if (nspi->req_result) in nci_spi_read()
299 complete(&nspi->req_completion); in nci_spi_read()
305 if (!skb->len) { in nci_spi_read()
311 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in nci_spi_read()