From patchwork Thu Apr 6 16:56:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?C=C3=A9dric_Le_Goater?= X-Patchwork-Id: 747904 X-Patchwork-Delegate: cyrille.pitchen@atmel.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vzTTV3H1Zz9ryk for ; Fri, 7 Apr 2017 02:59:42 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZMHZ67hA"; dkim-atps=neutral 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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=G/GQ/mNLiWjaOBOm0u9Kx9l+CjqHfVtvaq3gsTqUlT8=; b=ZMHZ67hAFcUeTD Pyonp+MCAJo6x1vuDzOT97VIaTs+lVdDhoP09Vs54bc4Q43N67Hke+krA2FZEJtkg+rZUpFWjsqDN juskxXMlx1mWi6boNQzC6K5zbnxvueB6T/2lU7iAwzUjegs92rHJJjR0e3Rt5McLz4iNjKM/9HvZq VnLCOYQrXaxKf3Tu15TGTOGwmExHx4gyT1yN9OBRSy5SX8mpRxoHb0xBUemDFWKuedf6qR8iFezCJ gCKFtBMKbJTx3jDH9/w0/Vo21DRVOsD6VQSZHMbAfvViIZMI84RQGydHMXeKDhvPmmcoax6UTISFA l3eA3PCmj4H0c429EllQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cwAkx-0007Ff-GF; Thu, 06 Apr 2017 16:59:35 +0000 Received: from 2.mo2.mail-out.ovh.net ([188.165.53.149]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cwAk5-0005l7-Vf for linux-mtd@lists.infradead.org; Thu, 06 Apr 2017 16:58:53 +0000 Received: from player731.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo2.mail-out.ovh.net (Postfix) with ESMTP id B1CA47A414 for ; Thu, 6 Apr 2017 18:58:20 +0200 (CEST) Received: from zorba.kaod.org (LFbn-1-10647-27.w90-89.abo.wanadoo.fr [90.89.233.27]) (Authenticated sender: clg@kaod.org) by player731.ha.ovh.net (Postfix) with ESMTPSA id 7C9DD420080; Thu, 6 Apr 2017 18:58:11 +0200 (CEST) From: =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= To: linux-mtd@lists.infradead.org Subject: [PATCH 08/10] mtd: spi-nor: aspeed: use command mode for reads Date: Thu, 6 Apr 2017 18:56:46 +0200 Message-Id: <1491497808-25487-9-git-send-email-clg@kaod.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1491497808-25487-1-git-send-email-clg@kaod.org> References: <1491497808-25487-1-git-send-email-clg@kaod.org> MIME-Version: 1.0 X-Ovh-Tracer-Id: 8335037010392157107 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: -100 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeeliedrtdeggddutdejucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddm X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170406_095842_979028_03EBA7B0 X-CRM114-Status: GOOD ( 13.17 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [188.165.53.149 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [188.165.53.149 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , Richard Weinberger , Marek Vasut , Joel Stanley , Cyrille Pitchen , Brian Norris , David Woodhouse , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When reading flash contents, try to use the "command mode" if the AHB window configured for the flash module is big enough. Else, just fall back to the "user mode" to perform the read. Signed-off-by: Cédric Le Goater --- drivers/mtd/spi-nor/aspeed-smc.c | 42 +++++++++++++++++++++++++++++++--------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/mtd/spi-nor/aspeed-smc.c b/drivers/mtd/spi-nor/aspeed-smc.c index 336a1ddd100b..3c004dfaf873 100644 --- a/drivers/mtd/spi-nor/aspeed-smc.c +++ b/drivers/mtd/spi-nor/aspeed-smc.c @@ -516,16 +516,8 @@ static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from, struct aspeed_smc_chip *chip = nor->priv; int i; u8 dummy = 0xFF; - int ret; u32 ctl; - if (aspeed_smc_dma_check(chip, from, len)) { - ret = aspeed_smc_dma_start(chip, from, read_buf, len, 0); - if (!ret) - goto out; - dev_err(chip->nor.dev, "DMA read failed: %d", ret); - } - aspeed_smc_start_user(nor); aspeed_smc_send_cmd_addr(nor, nor->read_opcode, from); for (i = 0; i < chip->nor.read_dummy / 8; i++) @@ -540,6 +532,38 @@ static ssize_t aspeed_smc_read_user(struct spi_nor *nor, loff_t from, aspeed_smc_read_from_ahb(read_buf, chip->ahb_base, len); aspeed_smc_stop_user(nor); + return 0; +} + +static ssize_t aspeed_smc_read(struct spi_nor *nor, loff_t from, size_t len, + u_char *read_buf) +{ + struct aspeed_smc_chip *chip = nor->priv; + int ret; + + /* The segment window configured for the chip is too small for + * the read offset. Use the "User mode" of the controller to + * perform the read. + */ + if (from >= chip->ahb_window_size) { + aspeed_smc_read_user(nor, from, len, read_buf); + goto out; + } + + /* Then, try DMA if the driver allows them. */ + if (aspeed_smc_dma_check(chip, from, len)) { + ret = aspeed_smc_dma_start(chip, from, read_buf, len, 0); + if (!ret) + goto out; + dev_err(chip->nor.dev, "DMA read failed: %d", ret); + } + + /* Last, and this should be the default, use the "Command + * mode" of the controller which does the read from the + * segment window configured for the chip on the AHB bus. + */ + memcpy_fromio(read_buf, chip->ahb_base + from, len); + out: return len; } @@ -948,7 +972,7 @@ static int aspeed_smc_setup_flash(struct aspeed_smc_controller *controller, nor->dev = dev; nor->priv = chip; spi_nor_set_flash_node(nor, child); - nor->read = aspeed_smc_read_user; + nor->read = aspeed_smc_read; nor->write = aspeed_smc_write_user; nor->read_reg = aspeed_smc_read_reg; nor->write_reg = aspeed_smc_write_reg;