Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2124349imm; Thu, 16 Aug 2018 06:04:47 -0700 (PDT) X-Google-Smtp-Source: AA+uWPwbVUiPYN0quvOYR/AjI+7Ame0K8KdtHh17QUVSlZlinQX5Ec9j60XFn1h2DN8/EgRUVH6P X-Received: by 2002:a17:902:227:: with SMTP id 36-v6mr29336919plc.103.1534424687872; Thu, 16 Aug 2018 06:04:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1534424687; cv=none; d=google.com; s=arc-20160816; b=E90HIY9lwVWMkCN+f60yHEc4RSsT6DR3LcIp2/wxgsANOTN1F8EvxaTq0rWnUXHPG/ 5aLhJyiCG8N+kZKXBBwIpli1C74Glzy3IQ47uUDgNiKTbCKJ9yTaaLnyNmJI87OpKgEh KSltp6S6fOIYrzvACyU+oB3a6Ji5cUAKEpBmZwtVs/eQ9SWhJIpWuL618jZPAAh13LAt vWdmD9BKmJpvNFVhcRCHvdfR4V/PR0pjb25vuwmYsdCYCpqu7cOONQV4J/8GigzZn+c0 9sSSKhelIkc2ZaY+wKx+w/GLNE0E6E3MqF5qVav7WcbeI+kB1BXLEstPvBr2ST8G+ShY jZgw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=84JhbVaCKz4rmWG0Dl5FpZRkfANdjCBRF0q4N8d7sWE=; b=L338r7U0ZeKai6RHNQX49LmH1SxjxOdHw4IasI7P33xk3pgKghucf0cEvrCcad5Qz0 JvAXAGvHtz0pLXw4Vj451v6h6tKxoFMRYI4woe7M5SoQW5wl/GiZemesZjwYs7kYRiKe 2ZUnrgnQWI6LJyK+YF5de5ec4ilaJdQ0PJknI4FiJM2yKddX1oG2JWktpBnZphiH2gTh y3G6t3CBEsefKTyctApU4qb/eR1s7JPEkovGcdrG9xvNSV2zgpIMDcZcb5cL6LypoG/S wxaDJ5N7fDaaD/DqulFPfAL6hzqfGtKV7lLHxZnpW0s7y85aImeQNVjHF7pmVOHLosCs QSbA== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11-v6si27454934pgk.468.2018.08.16.06.04.30; Thu, 16 Aug 2018 06:04:47 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389364AbeHPK12 (ORCPT + 99 others); Thu, 16 Aug 2018 06:27:28 -0400 Received: from mail.bootlin.com ([62.4.15.54]:49662 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387865AbeHPK11 (ORCPT ); Thu, 16 Aug 2018 06:27:27 -0400 Received: by mail.bootlin.com (Postfix, from userid 110) id 71A30208CC; Thu, 16 Aug 2018 09:30:53 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail.bootlin.com X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,SHORTCIRCUIT shortcircuit=ham autolearn=disabled version=3.4.0 Received: from bbrezillon (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 1637820712; Thu, 16 Aug 2018 09:30:53 +0200 (CEST) Date: Thu, 16 Aug 2018 09:30:52 +0200 From: Boris Brezillon To: Janusz Krzysztofik Cc: Miquel Raynal , Richard Weinberger , David Woodhouse , Brian Norris , Marek Vasut , Tony Lindgren , Aaro Koskinen , Linus Walleij , linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-mtd@lists.infradead.org, linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 5/7] mtd: rawnand: ams-delta: Set port direction when needed Message-ID: <20180816093052.2bcbf004@bbrezillon> In-Reply-To: <20180813223448.21316-6-jmkrzyszt@gmail.com> References: <20180806222918.12644-1-jmkrzyszt@gmail.com> <20180813223448.21316-1-jmkrzyszt@gmail.com> <20180813223448.21316-6-jmkrzyszt@gmail.com> X-Mailer: Claws Mail 3.15.0-dirty (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 14 Aug 2018 00:34:46 +0200 Janusz Krzysztofik wrote: > In its current shape, the driver sets data port direction before each > byte read/write operation, even during multi-byte transfers. Improve > performance of the driver by setting the port direction only when > needed. > > This optimisation will become particularly important as soon as > planned conversion of the driver to GPIO API for data I/O will be > implemented. > > Signed-off-by: Janusz Krzysztofik > --- > drivers/mtd/nand/raw/ams-delta.c | 59 ++++++++++++++++++++++++++++++++-------- > 1 file changed, 47 insertions(+), 12 deletions(-) > > diff --git a/drivers/mtd/nand/raw/ams-delta.c b/drivers/mtd/nand/raw/ams-delta.c > index 09d6901fc94d..5f9180fe4f8b 100644 > --- a/drivers/mtd/nand/raw/ams-delta.c > +++ b/drivers/mtd/nand/raw/ams-delta.c > @@ -45,6 +45,7 @@ struct ams_delta_nand { > struct gpio_desc *gpiod_ale; > struct gpio_desc *gpiod_cle; > void __iomem *io_base; > + bool data_in; > }; > > /* > @@ -72,50 +73,83 @@ static const struct mtd_partition partition_info[] = { > .size = 3 * SZ_256K }, > }; > > -static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte) > +static void ams_delta_write_next_byte(struct mtd_info *mtd, u_char byte) > { > struct nand_chip *this = mtd_to_nand(mtd); > struct ams_delta_nand *priv = nand_get_controller_data(this); > - void __iomem *io_base = priv->io_base; > > - writew(0, io_base + OMAP_MPUIO_IO_CNTL); > writew(byte, this->IO_ADDR_W); > + > gpiod_set_value(priv->gpiod_nwe, 0); > ndelay(40); > gpiod_set_value(priv->gpiod_nwe, 1); > } > > -static u_char ams_delta_read_byte(struct mtd_info *mtd) > +static void ams_delta_write_byte(struct mtd_info *mtd, u_char byte) > { > - u_char res; > struct nand_chip *this = mtd_to_nand(mtd); > struct ams_delta_nand *priv = nand_get_controller_data(this); > void __iomem *io_base = priv->io_base; > > + if (priv->data_in) { > + writew(0, io_base + OMAP_MPUIO_IO_CNTL); > + priv->data_in = false; > + } > + > + ams_delta_write_next_byte(mtd, byte); > +} I'm not a big fan of this {read,write}_byte/next_byte() approach. Can't we do something like: static void ams_delta_io_write(struct ams_delta_nand *priv, u8 data) { writew(byte, priv->nand_chip.IO_ADDR_W); gpiod_set_value(priv->gpiod_nwe, 0); ndelay(40); gpiod_set_value(priv->gpiod_nwe, 1); } static u8 ams_delta_io_read(struct ams_delta_nand *priv) { u8 res; gpiod_set_value(priv->gpiod_nre, 0); ndelay(40); res = readw(priv->nand_chip.IO_ADDR_R); gpiod_set_value(priv->gpiod_nre, 1); return res; } static void ams_delta_set_io_dir(struct ams_delta_nand *priv, bool in) { if (in == priv->data_in) return; writew(in ? ~0 : 0, priv->io_base + OMAP_MPUIO_IO_CNTL); priv->data_in = in; } static void ams_delta_write_buf(struct mtd_info *mtd, const u8 *buf, int len) { struct nand_chip *this = mtd_to_nand(mtd); struct ams_delta_nand *priv = nand_get_controller_data(this); int i; ams_delta_set_io_dir(priv, false); for (i =0; i < len; i++) ams_delta_io_write(priv, buf[i]); } static void ams_delta_write_byte(struct mtd_info *mtd, u8 byte) { ams_delta_write_buf(mtd, &byte, 1); } static void ams_delta_read_buf(struct mtd_info *mtd, u8 *buf, int len) { struct nand_chip *this = mtd_to_nand(mtd); struct ams_delta_nand *priv = nand_get_controller_data(this); int i; ams_delta_set_io_dir(priv, true); for (i = 0; i < len; i++) buf[i] = ams_delta_io_read(priv); } static u8 ams_delta_read_byte(struct mtd_info *mtd) { u8 res; ams_delta_read_buf(mtd, &res, 1); return res; }