From patchwork Wed Oct 10 13:43:15 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10634599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9AFC2679F for ; Wed, 10 Oct 2018 13:43:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E5F8F28A7D for ; Wed, 10 Oct 2018 13:43:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E3FFC2A0B7; Wed, 10 Oct 2018 13:43:31 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9D44F28AAF for ; Wed, 10 Oct 2018 13:43:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727007AbeJJVFe (ORCPT ); Wed, 10 Oct 2018 17:05:34 -0400 Received: from michel.telenet-ops.be ([195.130.137.88]:44136 "EHLO michel.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726770AbeJJVFe (ORCPT ); Wed, 10 Oct 2018 17:05:34 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by michel.telenet-ops.be with bizsmtp id lpjH1y00e3XaVaC06pjHN2; Wed, 10 Oct 2018 15:43:18 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gAElh-00008I-Rb; Wed, 10 Oct 2018 15:43:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gAElh-0002DM-QM; Wed, 10 Oct 2018 15:43:17 +0200 From: Geert Uytterhoeven To: Arnd Bergmann , Greg Kroah-Hartman , Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, Geert Uytterhoeven Subject: [PATCH 1/3] eeprom: at25: Drop obsolete cast in at25_ee_write() Date: Wed, 10 Oct 2018 15:43:15 +0200 Message-Id: <20181010134317.8466-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010134317.8466-1-geert+renesas@glider.be> References: <20181010134036.8296-1-geert+renesas@glider.be> <20181010134317.8466-1-geert+renesas@glider.be> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Since commit 01973a01f9ec34b7 ("eeprom: at25: remove nvmem regmap dependency") changed the type of "off" from "loff_t" to "unsigned int", there is no longer a need to cast it to "unsigned". Signed-off-by: Geert Uytterhoeven --- drivers/misc/eeprom/at25.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 840afb398f9e4c88..7707d3fb49b526d9 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c @@ -160,7 +160,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) do { unsigned long timeout, retries; unsigned segment; - unsigned offset = (unsigned) off; + unsigned offset = off; u8 *cp = bounce; int sr; u8 instr; From patchwork Wed Oct 10 13:43:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10634595 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B5444679F for ; Wed, 10 Oct 2018 13:43:20 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 36E34283C3 for ; Wed, 10 Oct 2018 13:43:20 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 343052A149; Wed, 10 Oct 2018 13:43:20 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0BE32A15A for ; Wed, 10 Oct 2018 13:43:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726771AbeJJVFd (ORCPT ); Wed, 10 Oct 2018 17:05:33 -0400 Received: from baptiste.telenet-ops.be ([195.130.132.51]:58862 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726600AbeJJVFd (ORCPT ); Wed, 10 Oct 2018 17:05:33 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by baptiste.telenet-ops.be with bizsmtp id lpjH1y00x3XaVaC01pjHhR; Wed, 10 Oct 2018 15:43:18 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gAElh-00008M-SG; Wed, 10 Oct 2018 15:43:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gAElh-0002DP-RK; Wed, 10 Oct 2018 15:43:17 +0200 From: Geert Uytterhoeven To: Arnd Bergmann , Greg Kroah-Hartman , Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, Geert Uytterhoeven Subject: [PATCH 2/3] eeprom: at25: Use spi_message_init_with_transfers() instead of open coding Date: Wed, 10 Oct 2018 15:43:16 +0200 Message-Id: <20181010134317.8466-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010134317.8466-1-geert+renesas@glider.be> References: <20181010134036.8296-1-geert+renesas@glider.be> <20181010134317.8466-1-geert+renesas@glider.be> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Reduce code duplication in at25_ee_read() by using the spi_message_init_with_transfers() helper. Signed-off-by: Geert Uytterhoeven Acked-by: Arnd Bergmann --- drivers/misc/eeprom/at25.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 7707d3fb49b526d9..5c8dc7ad391435f7 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c @@ -103,16 +103,15 @@ static int at25_ee_read(void *priv, unsigned int offset, *cp++ = offset >> 0; } - spi_message_init(&m); memset(t, 0, sizeof(t)); t[0].tx_buf = command; t[0].len = at25->addrlen + 1; - spi_message_add_tail(&t[0], &m); t[1].rx_buf = buf; t[1].len = count; - spi_message_add_tail(&t[1], &m); + + spi_message_init_with_transfers(&m, t, ARRAY_SIZE(t)); mutex_lock(&at25->lock); From patchwork Wed Oct 10 13:43:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 10634597 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42DFE69B4 for ; Wed, 10 Oct 2018 13:43:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 309012787C for ; Wed, 10 Oct 2018 13:43:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2EC6626255; Wed, 10 Oct 2018 13:43:24 +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=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8F0D2A162 for ; Wed, 10 Oct 2018 13:43:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726721AbeJJVFf (ORCPT ); Wed, 10 Oct 2018 17:05:35 -0400 Received: from andre.telenet-ops.be ([195.130.132.53]:53966 "EHLO andre.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726656AbeJJVFf (ORCPT ); Wed, 10 Oct 2018 17:05:35 -0400 Received: from ramsan.of.borg ([84.194.111.163]) by andre.telenet-ops.be with bizsmtp id lpjH1y00R3XaVaC01pjH3h; Wed, 10 Oct 2018 15:43:19 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan.of.borg with esmtp (Exim 4.86_2) (envelope-from ) id 1gAElh-00008O-T9; Wed, 10 Oct 2018 15:43:17 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1gAElh-0002DS-Rw; Wed, 10 Oct 2018 15:43:17 +0200 From: Geert Uytterhoeven To: Arnd Bergmann , Greg Kroah-Hartman , Srinivas Kandagatla Cc: linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, linux-mtd@lists.infradead.org, Geert Uytterhoeven Subject: [PATCH 3/3] eeprom: at25: Split writes in two SPI transfers to optimize DMA Date: Wed, 10 Oct 2018 15:43:17 +0200 Message-Id: <20181010134317.8466-4-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181010134317.8466-1-geert+renesas@glider.be> References: <20181010134036.8296-1-geert+renesas@glider.be> <20181010134317.8466-1-geert+renesas@glider.be> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently EEPROM writes are implemented using a single SPI transfer, which contains all of command, address, and payload data bytes. As some SPI controllers impose limitations on transfers with respect to the use of DMA, they may have to fall back to PIO. E.g. DMA may require the transfer length to be a multiple of 4 bytes. Optimize writes for DMA by splitting writes in two SPI transfers: - The first transfer contains command and address bytes, - The second transfer contains the actual payload data, now stored at the start of the (kmalloc() aligned) buffer, to improve payload alignment. E.g. for a 25LC040 EEPROM with a page size 16 bytes, a 16-byte write aligned to the page size was transferred using an 18-byte write. After this change, the write is split in a 2-byte and an aligned 16-byte write. Note that EEPROM reads already use a similar scheme, due to the different data directions for command and address bytes versus payload data. Signed-off-by: Geert Uytterhoeven Acked-by: Arnd Bergmann --- drivers/misc/eeprom/at25.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/misc/eeprom/at25.c b/drivers/misc/eeprom/at25.c index 5c8dc7ad391435f7..f84d1681835b4ded 100644 --- a/drivers/misc/eeprom/at25.c +++ b/drivers/misc/eeprom/at25.c @@ -136,6 +136,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) int status = 0; unsigned buf_size; u8 *bounce; + struct spi_transfer t[2]; if (unlikely(off >= at25->chip.byte_len)) return -EFBIG; @@ -160,7 +161,7 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) unsigned long timeout, retries; unsigned segment; unsigned offset = off; - u8 *cp = bounce; + u8 *cp = bounce + buf_size; int sr; u8 instr; @@ -194,9 +195,17 @@ static int at25_ee_write(void *priv, unsigned int off, void *val, size_t count) segment = buf_size - (offset % buf_size); if (segment > count) segment = count; - memcpy(cp, buf, segment); - status = spi_write(at25->spi, bounce, - segment + at25->addrlen + 1); + memcpy(bounce, buf, segment); + + memset(t, 0, sizeof(t)); + + t[0].tx_buf = bounce + buf_size; + t[0].len = at25->addrlen + 1; + + t[1].tx_buf = bounce; + t[1].len = segment; + + status = spi_sync_transfer(at25->spi, t, ARRAY_SIZE(t)); dev_dbg(&at25->spi->dev, "write %u bytes at %u --> %d\n", segment, offset, status); if (status < 0)