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_usecs = nspi->xfer_udelay; in __nci_spi_send()
48 t.speed_hz = nspi->xfer_speed_hz; in __nci_spi_send()
53 return spi_sync(nspi->spi, &m); in __nci_spi_send()
60 unsigned int payload_len = skb->len; in nci_spi_send()
65 /* add the NCI SPI header to the start of the buffer */ in nci_spi_send()
68 hdr[1] = nspi->acknowledge_mode; in nci_spi_send()
72 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in nci_spi_send()
75 crc = crc_ccitt(CRC_INIT, skb->data, skb->len); in nci_spi_send()
81 /* Trick SPI driver to raise chip select */ in nci_spi_send()
89 ret = -ETIME; in nci_spi_send()
95 if (ret != 0 || nspi->acknowledge_mode == NCI_SPI_CRC_DISABLED) in nci_spi_send()
98 reinit_completion(&nspi->req_completion); in nci_spi_send()
100 &nspi->req_completion, in nci_spi_send()
103 if (completion_rc <= 0 || nspi->req_result == ACKNOWLEDGE_NACK) in nci_spi_send()
104 ret = -EIO; in nci_spi_send()
113 /* ---- Interface to NCI SPI drivers ---- */
116 * nci_spi_allocate_spi - allocate a new nci spi
118 * @spi: SPI device
120 * @delay: delay between transactions in us
123 struct nci_spi *nci_spi_allocate_spi(struct spi_device *spi, in nci_spi_allocate_spi() argument
124 u8 acknowledge_mode, unsigned int delay, in nci_spi_allocate_spi() argument
129 nspi = devm_kzalloc(&spi->dev, sizeof(struct nci_spi), GFP_KERNEL); in nci_spi_allocate_spi()
133 nspi->acknowledge_mode = acknowledge_mode; in nci_spi_allocate_spi()
134 nspi->xfer_udelay = delay; in nci_spi_allocate_spi()
135 /* Use controller max SPI speed by default */ in nci_spi_allocate_spi()
136 nspi->xfer_speed_hz = 0; in nci_spi_allocate_spi()
137 nspi->spi = spi; in nci_spi_allocate_spi()
138 nspi->ndev = ndev; in nci_spi_allocate_spi()
139 init_completion(&nspi->req_completion); in nci_spi_allocate_spi()
152 skb = nci_skb_alloc(nspi->ndev, 0, GFP_KERNEL); in send_acknowledge()
154 /* add the NCI SPI header to the start of the buffer */ in send_acknowledge()
161 crc = crc_ccitt(CRC_INIT, skb->data, skb->len); in send_acknowledge()
177 struct spi_transfer tx, rx; in __nci_spi_read() local
183 memset(&tx, 0, sizeof(struct spi_transfer)); in __nci_spi_read()
185 req[1] = nspi->acknowledge_mode; in __nci_spi_read()
186 tx.tx_buf = req; in __nci_spi_read()
187 tx.len = 2; in __nci_spi_read()
188 tx.cs_change = 0; in __nci_spi_read()
189 tx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
190 spi_message_add_tail(&tx, &m); in __nci_spi_read()
196 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
199 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
203 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in __nci_spi_read()
209 skb = nci_skb_alloc(nspi->ndev, rx_len, GFP_KERNEL); in __nci_spi_read()
219 rx.delay_usecs = nspi->xfer_udelay; in __nci_spi_read()
220 rx.speed_hz = nspi->xfer_speed_hz; in __nci_spi_read()
223 ret = spi_sync(nspi->spi, &m); in __nci_spi_read()
227 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in __nci_spi_read()
242 u16 crc_data = (skb->data[skb->len - 2] << 8) | in nci_spi_check_crc()
243 skb->data[skb->len - 1]; in nci_spi_check_crc()
246 ret = (crc_ccitt(CRC_INIT, skb->data, skb->len - NCI_SPI_CRC_LEN) in nci_spi_check_crc()
249 skb_trim(skb, skb->len - NCI_SPI_CRC_LEN); in nci_spi_check_crc()
258 ret = skb->data[0] >> NCI_SPI_ACK_SHIFT; in nci_spi_get_ack()
267 * nci_spi_read - read frame from NCI SPI drivers
269 * @nspi: The nci spi
273 * is non-interruptible, and has no timeout.
281 /* Retrieve frame from SPI */ in nci_spi_read()
286 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) { in nci_spi_read()
295 nspi->req_result = nci_spi_get_ack(skb); in nci_spi_read()
296 if (nspi->req_result) in nci_spi_read()
297 complete(&nspi->req_completion); in nci_spi_read()
303 if (!skb->len) { in nci_spi_read()
309 if (nspi->acknowledge_mode == NCI_SPI_CRC_ENABLED) in nci_spi_read()