hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/spi/spi-fsl-cpm.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * Freescale SPI controller driver cpm functions.
34 *
....@@ -9,11 +10,6 @@
910 * CPM SPI and QE buffer descriptors mode support:
1011 * Copyright (c) 2009 MontaVista Software, Inc.
1112 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
12
- *
13
- * This program is free software; you can redistribute it and/or modify it
14
- * under the terms of the GNU General Public License as published by the
15
- * Free Software Foundation; either version 2 of the License, or (at your
16
- * option) any later version.
1713 */
1814 #include <asm/cpm.h>
1915 #include <soc/fsl/qe/qe.h>
....@@ -25,6 +21,7 @@
2521 #include <linux/spi/spi.h>
2622 #include <linux/types.h>
2723 #include <linux/platform_device.h>
24
+#include <linux/byteorder/generic.h>
2825
2926 #include "spi-fsl-cpm.h"
3027 #include "spi-fsl-lib.h"
....@@ -124,6 +121,21 @@
124121 mspi->rx_dma = mspi->dma_dummy_rx;
125122 mspi->map_rx_dma = 0;
126123 }
124
+ if (t->bits_per_word == 16 && t->tx_buf) {
125
+ const u16 *src = t->tx_buf;
126
+ u16 *dst;
127
+ int i;
128
+
129
+ dst = kmalloc(t->len, GFP_KERNEL);
130
+ if (!dst)
131
+ return -ENOMEM;
132
+
133
+ for (i = 0; i < t->len >> 1; i++)
134
+ dst[i] = cpu_to_le16p(src + i);
135
+
136
+ mspi->tx = dst;
137
+ mspi->map_tx_dma = 1;
138
+ }
127139
128140 if (mspi->map_tx_dma) {
129141 void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */
....@@ -177,6 +189,13 @@
177189 if (mspi->map_rx_dma)
178190 dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE);
179191 mspi->xfer_in_progress = NULL;
192
+
193
+ if (t->bits_per_word == 16 && t->rx_buf) {
194
+ int i;
195
+
196
+ for (i = 0; i < t->len; i += 2)
197
+ le16_to_cpus(t->rx_buf + i);
198
+ }
180199 }
181200 EXPORT_SYMBOL_GPL(fsl_spi_cpm_bufs_complete);
182201
....@@ -230,7 +249,7 @@
230249 case 1:
231250 kfree(fsl_dummy_rx);
232251 fsl_dummy_rx = NULL;
233
- /* fall through */
252
+ fallthrough;
234253 default:
235254 fsl_dummy_rx_refcnt--;
236255 break;
....@@ -298,7 +317,7 @@
298317 switch (mspi->subblock) {
299318 default:
300319 dev_warn(dev, "cell-index unspecified, assuming SPI1\n");
301
- /* fall through */
320
+ fallthrough;
302321 case 0:
303322 mspi->subblock = QE_CR_SUBBLOCK_SPI1;
304323 break;
....@@ -309,12 +328,10 @@
309328 }
310329
311330 if (mspi->flags & SPI_CPM1) {
312
- struct resource *res;
313331 void *pram;
314332
315
- res = platform_get_resource(to_platform_device(dev),
316
- IORESOURCE_MEM, 1);
317
- pram = devm_ioremap_resource(dev, res);
333
+ pram = devm_platform_ioremap_resource(to_platform_device(dev),
334
+ 1);
318335 if (IS_ERR(pram))
319336 mspi->pram = NULL;
320337 else
....@@ -398,7 +415,8 @@
398415 dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE);
399416 dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE);
400417 cpm_muram_free(cpm_muram_offset(mspi->tx_bd));
401
- cpm_muram_free(cpm_muram_offset(mspi->pram));
418
+ if (!(mspi->flags & SPI_CPM1))
419
+ cpm_muram_free(cpm_muram_offset(mspi->pram));
402420 fsl_spi_free_dummy_rx();
403421 }
404422 EXPORT_SYMBOL_GPL(fsl_spi_cpm_free);