Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp306755imm; Fri, 21 Sep 2018 00:07:17 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZR5ZkL9gpLm0noN4cZImlJK2W+YUsLraf3XDFHBV+dlXLHeb5AqHw4KqiBLmta/UAsF3Gs X-Received: by 2002:a63:7a50:: with SMTP id j16-v6mr6149241pgn.112.1537513637171; Fri, 21 Sep 2018 00:07:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537513637; cv=none; d=google.com; s=arc-20160816; b=P5e3oypdebvKyljO7m79l0b7/m4DE74JwPJQ/ZzRRmH483kO2p3snlkXGpDB6gh+1f 7Uhn3MRpM5EccRd0bFUl2Pw5rhlUsiCOK4J44i8EPqL77sL3swOklYiyGW+QCbtmsasw XmZ2B54GwPIh0dOf6kZM9nsTft3m+cXLZObkMjl97Uomb9B7tfvV4SPnGrLb636Cq55c bLXHF5dLTfSU7oTiNGBjdg4xmX3b0r4OYiIgTMu/dIFD8Ow0Parltco16SyUON+gyuFB 6n4/UPGmJXoLGkfW8JwZpCIZJXQOuPnzzHpmumdbwyMZBSLtAio1keqGr96YZMWPvAqo Gnig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=zH8/99mF0TdMItkKlVaou4qnUN7N7g9c8WbImFOfJ5I=; b=ddE3KcLNA7lbi96HakIHHZCIXqfE/uSIHXyf1zGj3/ZEuORsBpVPeyfBkJqW8k4wRv VE9SirHaEFDd+y9Awm5V8JRPNnVV+3cbPrPedQcIITbpcC8JwSSqo1AGkMGbfUKv/kO5 iSf200D8wbN2pHY63RjUkN4iE6wJ4Xm50oS3UF0WOcrnu5FQtEoc3XFLXEGf6Iy9DFT4 gsJDXoGjfCC5+hnLgP7BfKYE1sIdCEXsrtuOmB3SZhBNkGZsQgCK71/LHUSpCeOPTtle d7G9TEzExifIClUmTtNgbkrqjF2/dsPVXklIL5gmj6QYNy/18X6Hj/ZBdKDQAQuYB2b1 LVjw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z25-v6si28578136pfm.152.2018.09.21.00.07.01; Fri, 21 Sep 2018 00:07:17 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389298AbeIUMxq (ORCPT + 99 others); Fri, 21 Sep 2018 08:53:46 -0400 Received: from inva020.nxp.com ([92.121.34.13]:54910 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388909AbeIUMxq (ORCPT ); Fri, 21 Sep 2018 08:53:46 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E96881A02AF; Fri, 21 Sep 2018 09:06:13 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D53BB1A02AC; Fri, 21 Sep 2018 09:06:10 +0200 (CEST) Received: from mega.ap.freescale.net (mega.ap.freescale.net [10.192.208.232]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id A06C6402E5; Fri, 21 Sep 2018 15:06:06 +0800 (SGT) From: Chuanhua Han To: broonie@kernel.org Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, eha@deif.com, boris.brezillon@bootlin.com, Chuanhua Han Subject: [PATCH 2/2] spi: spi-fsl-dspi: Fix support for XSPI transport mode Date: Fri, 21 Sep 2018 15:06:27 +0800 Message-Id: <20180921070628.35153-2-chuanhua.han@nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180921070628.35153-1-chuanhua.han@nxp.com> References: <20180921070628.35153-1-chuanhua.han@nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes the problem that the XSPI mode of the dspi controller cannot transfer data properly. In XSPI mode, cmd_fifo is written before tx_fifo, which transforms the byte order of sending and receiving data. Signed-off-by: Chuanhua Han --- drivers/spi/spi-fsl-dspi.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c index 3082e72e4f6c..44cc2bd0120e 100644 --- a/drivers/spi/spi-fsl-dspi.c +++ b/drivers/spi/spi-fsl-dspi.c @@ -220,9 +220,15 @@ static u32 dspi_pop_tx(struct fsl_dspi *dspi) if (dspi->bytes_per_word == 1) txdata = *(u8 *)dspi->tx; else if (dspi->bytes_per_word == 2) - txdata = *(u16 *)dspi->tx; + if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) + txdata = cpu_to_le16(*(u16 *)dspi->tx); + else + txdata = cpu_to_be16(*(u16 *)dspi->tx); else /* dspi->bytes_per_word == 4 */ - txdata = *(u32 *)dspi->tx; + if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) + txdata = cpu_to_le32(*(u32 *)dspi->tx); + else + txdata = cpu_to_be32(*(u32 *)dspi->tx); dspi->tx += dspi->bytes_per_word; } dspi->len -= dspi->bytes_per_word; @@ -243,15 +249,18 @@ static void dspi_push_rx(struct fsl_dspi *dspi, u32 rxdata) if (!dspi->rx) return; - /* Mask of undefined bits */ - rxdata &= (1 << dspi->bits_per_word) - 1; - if (dspi->bytes_per_word == 1) *(u8 *)dspi->rx = rxdata; else if (dspi->bytes_per_word == 2) - *(u16 *)dspi->rx = rxdata; + if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) + *(u16 *)dspi->rx = be16_to_cpu(rxdata); + else + *(u16 *)dspi->rx = be16_to_cpu(rxdata); else /* dspi->bytes_per_word == 4 */ - *(u32 *)dspi->rx = rxdata; + if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) + *(u32 *)dspi->rx = le32_to_cpu(rxdata); + else + *(u32 *)dspi->rx = be32_to_cpu(rxdata); dspi->rx += dspi->bytes_per_word; } @@ -593,16 +602,16 @@ static void dspi_tcfq_write(struct fsl_dspi *dspi) */ u32 data = dspi_pop_tx(dspi); + cmd_fifo_write(dspi); if (dspi->cur_chip->ctar_val & SPI_CTAR_LSBFE(1)) { /* LSB */ - tx_fifo_write(dspi, data & 0xFFFF); tx_fifo_write(dspi, data >> 16); + tx_fifo_write(dspi, data & 0xFFFF); } else { /* MSB */ - tx_fifo_write(dspi, data >> 16); tx_fifo_write(dspi, data & 0xFFFF); + tx_fifo_write(dspi, data >> 16); } - cmd_fifo_write(dspi); } else { /* Write one entry to both TX FIFO and CMD FIFO * simultaneously. -- 2.17.1