From patchwork Tue Jul 17 14:31:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Chevallier X-Patchwork-Id: 10529635 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BB7326020A for ; Tue, 17 Jul 2018 14:33:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7C142911A for ; Tue, 17 Jul 2018 14:33:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BB3B292D6; Tue, 17 Jul 2018 14:33:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 87F162911A for ; Tue, 17 Jul 2018 14:33:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zRygzoFGGnSDTmLgceYNBajbDLgmBOoGTEzMRI/MaD4=; b=Y/+upFrv0g+/P/aVduGlRoQsYN mZzyje7mba1NtC+sEMvU1SBtxr3h3iGKX+dkLATCS5l6IvxKwV4E5Xrxx8bUwBF1MI+wY5NeYv6Rl yBFzsG26PSL+vwHDQu4OutjQYfIrbSPfDkRW249eQlToHqZ8IY19aQO/gII4uSFbbOVVm++YmngNT Rdjj+ufR07oJPOotGcKZ7QlmM+x0Nh44t/9695Po3W8M9nEu7IFlUWqZjoD3gPdeIp4kQvY4shvSH TIy2eSZmYHch8ZQlMiLPe1quJojSPS6XleeNkGdiIQGPXpFXN1kJ/0RfZCVxy2UQ3VMmBx2/lOF4t sMCJmSvw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ffR2R-0005br-8g; Tue, 17 Jul 2018 14:33:15 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1ffR1W-0004aF-DI for linux-arm-kernel@lists.infradead.org; Tue, 17 Jul 2018 14:32:21 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 2377A208FF; Tue, 17 Jul 2018 16:32:08 +0200 (CEST) Received: from mc-bl-xps13.lan (AAubervilliers-681-1-27-161.w90-88.abo.wanadoo.fr [90.88.147.161]) by mail.bootlin.com (Postfix) with ESMTPSA id C674E20765; Tue, 17 Jul 2018 16:31:57 +0200 (CEST) From: Maxime Chevallier To: Mark Brown Subject: [PATCH RESEND 3/5] spi: imx: Use correct number of bytes per words Date: Tue, 17 Jul 2018 16:31:52 +0200 Message-Id: <20180717143154.28241-4-maxime.chevallier@bootlin.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180717143154.28241-1-maxime.chevallier@bootlin.com> References: <20180717143154.28241-1-maxime.chevallier@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180717_073218_625683_021CDB70 X-CRM114-Status: GOOD ( 12.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alexandre.belloni@bootlin.com, thomas.petazzoni@bootlin.com, Sascha Hauer , linux-kernel@vger.kernel.org, Maxime Chevallier , NXP Linux Team , Pengutronix Kernel Team , Fabio Estevam , linux-spi@vger.kernel.org, Shawn Guo , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The SPI core enforces that we always use the next power-of-two number of bytes to store words. As a result, a 24 bits word will be stored in 4 bytes. This commit fixes the spi_imx_bytes_per_word function to return the correct number of bytes. This also allows to get rid of unnecessary checks in the can_dma function, since the SPI core validates that we always have a transfer length that is a multiple of the number of bytes per word. Signed-off-by: Maxime Chevallier Reviewed-by: Sascha Hauer --- drivers/spi/spi-imx.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c index ecafbda5ec94..3ae706dac660 100644 --- a/drivers/spi/spi-imx.c +++ b/drivers/spi/spi-imx.c @@ -202,7 +202,12 @@ static unsigned int spi_imx_clkdiv_2(unsigned int fin, static int spi_imx_bytes_per_word(const int bits_per_word) { - return DIV_ROUND_UP(bits_per_word, BITS_PER_BYTE); + if (bits_per_word <= 8) + return 1; + else if (bits_per_word <= 16) + return 2; + else + return 4; } static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi, @@ -219,9 +224,6 @@ static bool spi_imx_can_dma(struct spi_master *master, struct spi_device *spi, bytes_per_word = spi_imx_bytes_per_word(transfer->bits_per_word); - if (bytes_per_word != 1 && bytes_per_word != 2 && bytes_per_word != 4) - return false; - for (i = spi_imx->devtype_data->fifo_size / 2; i > 0; i--) { if (!(transfer->len % (i * bytes_per_word))) break;