| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * Freescale SPI controller driver cpm functions. |
|---|
| 3 | 4 | * |
|---|
| .. | .. |
|---|
| 9 | 10 | * CPM SPI and QE buffer descriptors mode support: |
|---|
| 10 | 11 | * Copyright (c) 2009 MontaVista Software, Inc. |
|---|
| 11 | 12 | * 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. |
|---|
| 17 | 13 | */ |
|---|
| 18 | 14 | #include <asm/cpm.h> |
|---|
| 19 | 15 | #include <soc/fsl/qe/qe.h> |
|---|
| .. | .. |
|---|
| 25 | 21 | #include <linux/spi/spi.h> |
|---|
| 26 | 22 | #include <linux/types.h> |
|---|
| 27 | 23 | #include <linux/platform_device.h> |
|---|
| 24 | +#include <linux/byteorder/generic.h> |
|---|
| 28 | 25 | |
|---|
| 29 | 26 | #include "spi-fsl-cpm.h" |
|---|
| 30 | 27 | #include "spi-fsl-lib.h" |
|---|
| .. | .. |
|---|
| 124 | 121 | mspi->rx_dma = mspi->dma_dummy_rx; |
|---|
| 125 | 122 | mspi->map_rx_dma = 0; |
|---|
| 126 | 123 | } |
|---|
| 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 | + } |
|---|
| 127 | 139 | |
|---|
| 128 | 140 | if (mspi->map_tx_dma) { |
|---|
| 129 | 141 | void *nonconst_tx = (void *)mspi->tx; /* shut up gcc */ |
|---|
| .. | .. |
|---|
| 177 | 189 | if (mspi->map_rx_dma) |
|---|
| 178 | 190 | dma_unmap_single(dev, mspi->rx_dma, t->len, DMA_FROM_DEVICE); |
|---|
| 179 | 191 | 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 | + } |
|---|
| 180 | 199 | } |
|---|
| 181 | 200 | EXPORT_SYMBOL_GPL(fsl_spi_cpm_bufs_complete); |
|---|
| 182 | 201 | |
|---|
| .. | .. |
|---|
| 230 | 249 | case 1: |
|---|
| 231 | 250 | kfree(fsl_dummy_rx); |
|---|
| 232 | 251 | fsl_dummy_rx = NULL; |
|---|
| 233 | | - /* fall through */ |
|---|
| 252 | + fallthrough; |
|---|
| 234 | 253 | default: |
|---|
| 235 | 254 | fsl_dummy_rx_refcnt--; |
|---|
| 236 | 255 | break; |
|---|
| .. | .. |
|---|
| 298 | 317 | switch (mspi->subblock) { |
|---|
| 299 | 318 | default: |
|---|
| 300 | 319 | dev_warn(dev, "cell-index unspecified, assuming SPI1\n"); |
|---|
| 301 | | - /* fall through */ |
|---|
| 320 | + fallthrough; |
|---|
| 302 | 321 | case 0: |
|---|
| 303 | 322 | mspi->subblock = QE_CR_SUBBLOCK_SPI1; |
|---|
| 304 | 323 | break; |
|---|
| .. | .. |
|---|
| 309 | 328 | } |
|---|
| 310 | 329 | |
|---|
| 311 | 330 | if (mspi->flags & SPI_CPM1) { |
|---|
| 312 | | - struct resource *res; |
|---|
| 313 | 331 | void *pram; |
|---|
| 314 | 332 | |
|---|
| 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); |
|---|
| 318 | 335 | if (IS_ERR(pram)) |
|---|
| 319 | 336 | mspi->pram = NULL; |
|---|
| 320 | 337 | else |
|---|
| .. | .. |
|---|
| 398 | 415 | dma_unmap_single(dev, mspi->dma_dummy_rx, SPI_MRBLR, DMA_FROM_DEVICE); |
|---|
| 399 | 416 | dma_unmap_single(dev, mspi->dma_dummy_tx, PAGE_SIZE, DMA_TO_DEVICE); |
|---|
| 400 | 417 | 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)); |
|---|
| 402 | 420 | fsl_spi_free_dummy_rx(); |
|---|
| 403 | 421 | } |
|---|
| 404 | 422 | EXPORT_SYMBOL_GPL(fsl_spi_cpm_free); |
|---|