Lines Matching +full:spi +full:- +full:tx +full:- +full:delay +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/spi/spi.h>
12 #include <linux/crc-ccitt.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()
48 t.delay.unit = SPI_DELAY_UNIT_USECS; 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()
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
121 * @delay: delay between transactions in us
124 struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, in nci_spi_allocate_spi() argument
125 u8 acknowledge_mode, unsigned int delay, 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 return -ENOMEM; in send_acknowledge()
157 /* add the NCI SPI header to the start of the buffer */ in send_acknowledge()
164 crc = crc_ccitt(CRC_INIT, skb->data, skb->len); in send_acknowledge()
180 struct spi_transfer tx, rx; in __nci_spi_read() local
186 memset(&tx, 0, sizeof(struct spi_transfer)); in __nci_spi_read()
188 req[1] = nspi->acknowledge_mode; in __nci_spi_read()
189 tx.tx_buf = req; in __nci_spi_read()
190 tx.len = 2; in __nci_spi_read()
191 tx.cs_change = 0; in __nci_spi_read()
192 tx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
193 spi_message_add_tail(&tx, &m); in __nci_spi_read()
199 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
202 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
206 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in __nci_spi_read()
212 skb = nci_skb_alloc(nspi->ndev, rx_len, GFP_KERNEL); in __nci_spi_read()
222 rx.delay.value = nspi->xfer_udelay; in __nci_spi_read()
223 rx.delay.unit = SPI_DELAY_UNIT_USECS; in __nci_spi_read()
224 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
227 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
231 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in __nci_spi_read()
246 u16 crc_data = (skb->data[skb->len - 2] << 8) | in nci_spi_check_crc()
247 skb->data[skb->len - 1]; in nci_spi_check_crc()
250 ret = (crc_ccitt(CRC_INIT, skb->data, skb->len - NCI_SPI_CRC_LEN) in nci_spi_check_crc()
253 skb_trim(skb, skb->len - NCI_SPI_CRC_LEN); in nci_spi_check_crc()
262 ret = skb->data[0] >> NCI_SPI_ACK_SHIFT; in nci_spi_get_ack()
271 * nci_spi_read - read frame from NCI SPI drivers
273 * @nspi: The nci spi
277 * is non-interruptible, and has no timeout.
285 /* Retrieve frame from SPI */ in nci_spi_read()
290 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in nci_spi_read()
299 nspi->req_result = nci_spi_get_ack(skb); in nci_spi_read()
300 if (nspi->req_result) in nci_spi_read()
301 complete(&nspi->req_completion); in nci_spi_read()
307 if (!skb->len) { in nci_spi_read()
313 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in nci_spi_read()
322 MODULE_DESCRIPTION("NFC Controller Interface (NCI) SPI link layer");