Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753821AbbHOUqk (ORCPT ); Sat, 15 Aug 2015 16:46:40 -0400 Received: from mout.kundenserver.de ([212.227.17.24]:57960 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751332AbbHOUqh (ORCPT ); Sat, 15 Aug 2015 16:46:37 -0400 From: Arnd Bergmann To: linux-arm-kernel@lists.infradead.org Cc: Leilk Liu , Mark Brown , Mark Rutland , devicetree@vger.kernel.org, Sascha Hauer , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mediatek@lists.infradead.org, Matthias Brugger Subject: Re: [PATCH] spi: Mediatek: fixup cpu_to_le32 incorrect usage Date: Sat, 15 Aug 2015 22:46:14 +0200 Message-ID: <3523801.O835HG5rEa@wuerfel> User-Agent: KMail/4.11.5 (Linux/3.16.0-10-generic; KDE/4.11.5; x86_64; ; ) In-Reply-To: <1439467601-10209-1-git-send-email-leilk.liu@mediatek.com> References: <1439467601-10209-1-git-send-email-leilk.liu@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Provags-ID: V03:K0:i2KpzJYm2jJ1xYmZskqRsp15LphYjldySMTQQDAsbIug0fv+5Ij FuFuN62Zv0nkB0dv/83TsnVXCUrAtNCQgsCY6J4WLKI0D5Qb6xcf5/I9/c85BoVDO/xs58O 9ZD9u48YpUSPQmusMzAqDdxhM3IsUXZcXjExCsQAOblmLsheNDhaS1q/p6iRJedhie7xd00 FMLgxhR/mxCSEZMhI7pog== X-UI-Out-Filterresults: notjunk:1;V01:K0:YFQKQrkznd0=:ZRymQL2HIAphkUOTINvAaI XDkzEnTus1zNErYIo5gPuoU7XD3OuYjsmLfhKeeHDo8+YsJxJnrRJ6G56e9xNIX9PFOWxzP5f afy1Vp1k1JhGkxbBpJggA22JBNLMzE9dQke+V5hBNcuAlBaBSrrVVpK/6I8z7TXDj1mYupnNb w3t09G5s0x+lbfpkjYLmFyCMSDhUDffV7PQH5iSC0roOENGoftDRW/oKxhgY8ATyqkQ/3PGJ2 SIzqCl4Gd261HZoGCnsMiY5IFnvcLj8vqODX4T8j5uZGvzP5bJteK0/kzDUgUQHE+qVXpiWCy 0DLNDPxy6J2D8QCR0H7sqGxAslWApDikrjWtclzh/8wwDJP8EgKr9y1Wd1C5TJOOV6ldfq0gU L4axvpjHGSzu5thxAuPbrU0WWb2kn+LhiD3w6LlluMltw/nR0Sk/shCBQ/eJLdibooi4yBj4y kcElJTwWWDfpgh3T2DV5GnBmOr8iMsXBIvntRK11wc+1a7l9PXrENnk+BJZ813gnHHTYYeG5e 41plw+6vrB8IR83/D2AOzTjt+U3q9t5vei7FtjRzKWO3xUOJCOT/FHeV0sImVzlmTYSykbrjT tJbg3vuqxBB8teKH75jlHWCKesycmyTRYzqEoMh6PU3/bRmZeEs4KHPMHzPWhqTCZz+OMcsdh U+TWqFu9pugmP3EuxbEZId66Z+PgCMYr0DIyVUSl3ziGN1tvQkdPrt0/5cED2m7dK4xG2Sijs NeEM+xPyLoAhpPgd Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2519 Lines: 65 On Thursday 13 August 2015 20:06:41 Leilk Liu wrote: > diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c > index ae645fa..519f50c 100644 > --- a/drivers/spi/spi-mt65xx.c > +++ b/drivers/spi/spi-mt65xx.c > @@ -359,11 +359,9 @@ static void mtk_spi_setup_dma_addr(struct spi_master *master, > struct mtk_spi *mdata = spi_master_get_devdata(master); > > if (mdata->tx_sgl) > - writel((__force u32)cpu_to_le32(xfer->tx_dma), > - mdata->base + SPI_TX_SRC_REG); > + writel(xfer->tx_dma, mdata->base + SPI_TX_SRC_REG); > if (mdata->rx_sgl) > - writel((__force u32)cpu_to_le32(xfer->rx_dma), > - mdata->base + SPI_RX_DST_REG); > + writel(xfer->rx_dma, mdata->base + SPI_RX_DST_REG); > } > > static int mtk_spi_fifo_transfer(struct spi_master *master, > -- > This change looks good, but after I've briefly looked at the current driver, I found at least one more location that looks like an endianess bug: +static int mtk_spi_fifo_transfer(struct spi_master *master, + struct spi_device *spi, + struct spi_transfer *xfer) +{ ... + + for (i = 0; i < cnt; i++) + writel(*((u32 *)xfer->tx_buf + i), + mdata->base + SPI_TX_DATA_REG); + + mtk_spi_enable_transfer(master); + + return 1; +} Here, you write data into a FIFO register using an accessor that converts to little-endian. In contrast, the DMA based accessor apparently has no byte swap, so most likely one of the two is broken on big-endian systems. My guess is that the look above is wrong, and you need to use iowrite32_rep() instead, so you always write into the FIFO in the byte stream order (first byte to last byte) rather than swapping 32-bit entities. The other suspicious part is this: + reg_val |= (chip_config->tx_endian << SPI_CMD_TX_ENDIAN_OFFSET); + reg_val |= (chip_config->rx_endian << SPI_CMD_RX_ENDIAN_OFFSET); It's not clear what the tx_endian/rx_endian bits refer to and why you can't just always set the register interface to little-endian. If it's set to big-endian, you probably need to add more byte swaps in the driver. Arnd -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/