From patchwork Tue Apr 10 22:44:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris Brezillon X-Patchwork-Id: 896968 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=bootlin.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="G3TdRnpJ"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::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 40LMlL6wVTz9s0n for ; Wed, 11 Apr 2018 08:48:14 +1000 (AEST) 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=wpBDqZnQTicDEklCN0s3n7b8wpPPK0C3E7peVX/ANgM=; b=G3TdRnpJQ0sFKvd++4l7mwDAzr xICJwSZk33qCaVcensO4BMRgemYjOVr0Gd3GHj0vWp/kw0TJEATXUCD9CS05rtUM8Hjk6SY3hqx8T kP2iLDX8CoQ8te4vPHq2L7wyqxouxvN1fIHoJJbX8ep0GqChaew7ptNcvXNLRfzk94McFZmLR/euT 8bWrTX1ZVvYMM7Em2qlqBDUwLqgUn8+6hC0nwsoUzzuJrT3+MY+VwnfEnF7cE9/rYhtJSd86l/mnu tXtMv9y51OycNAa+DI3ygch48xxJATIRhjeaHdKqlrUkecZnz85NVABEZcQ8AZb/LadO/p8AXZ+FO RL8PQ+IA==; 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 1f623Y-0000fY-3p; Tue, 10 Apr 2018 22:48:04 +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 1f620j-0006HD-M4 for linux-mtd@lists.infradead.org; Tue, 10 Apr 2018 22:45:12 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id CD0E420D97; Wed, 11 Apr 2018 00:44:46 +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 localhost.localdomain (unknown [91.160.177.164]) by mail.bootlin.com (Postfix) with ESMTPSA id 6C4F520867; Wed, 11 Apr 2018 00:44:46 +0200 (CEST) From: Boris Brezillon To: David Woodhouse , Brian Norris , Boris Brezillon , Marek Vasut , Richard Weinberger , Cyrille Pitchen , linux-mtd@lists.infradead.org, Miquel Raynal , Mark Brown , linux-spi@vger.kernel.org Subject: [PATCH v2 07/10] spi: bcm53xx: Implement the spi_mem interface Date: Wed, 11 Apr 2018 00:44:36 +0200 Message-Id: <20180410224439.9260-8-boris.brezillon@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180410224439.9260-1-boris.brezillon@bootlin.com> References: <20180410224439.9260-1-boris.brezillon@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180410_154510_093666_C7D55682 X-CRM114-Status: GOOD ( 21.82 ) X-Spam-Score: -0.0 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [62.4.15.54 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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: Yogesh Gaur , Vignesh R , Kamal Dasu , Maxime Chevallier , Peter Pan , Frieder Schrempf , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Sourav Poddar MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org The spi_mem interface is meant to replace the spi_flash_read() one. Implement the ->exec_op() method so that we can smoothly get rid of the old interface. Note that the current ->flash_read() implementation looks a bit fragile since it does not take the ->read_opcode passed by the spi-nor layer into account, which means if might not work with all kind of NORs. Anyway, I left the logic unchanged and added a few extra checks to make sure we're receiving something that looks like a NOR read operation. Signed-off-by: Boris Brezillon --- Changes in v2: - include spi-mem.h - treat op->addr.val differently since it's now an u64 --- drivers/spi/spi-bcm2835.c | 1 + drivers/spi/spi-bcm53xx.c | 36 +++++++++++++++++++++++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index f35cc10772f6..41ed371eaf15 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c @@ -37,6 +37,7 @@ #include #include #include +#include /* SPI register offsets */ #define BCM2835_SPI_CS 0x00 diff --git a/drivers/spi/spi-bcm53xx.c b/drivers/spi/spi-bcm53xx.c index d02ceb7a29d1..016059d3160b 100644 --- a/drivers/spi/spi-bcm53xx.c +++ b/drivers/spi/spi-bcm53xx.c @@ -257,6 +257,38 @@ static int bcm53xxspi_transfer_one(struct spi_master *master, return 0; } +static int bcm53xxspi_exec_mem_op(struct spi_mem *mem, + const struct spi_mem_op *op) +{ + struct bcm53xxspi *b53spi = spi_master_get_devdata(mem->spi->master); + u32 from; + + /* + * FIXME: There's nothing in this driver programming the opcode and + * buswidth to be used when a read is done on the mmio window, but it + * seems to be used to access a SPI NOR device, so restrict access + * access to SPINOR_OP_READ commands. + */ + if (!op->data.nbytes || op->data.dir != SPI_MEM_DATA_IN || + op->addr.nbytes != 3 || op->cmd.opcode != 0x3) + return -ENOTSUPP; + + /* Return -ENOTSUPP so that the core can fall back to normal reads. */ + from = op->addr.val; + if (from + op->data.nbytes > BCM53XXSPI_FLASH_WINDOW) + return -ENOTSUPP; + + bcm53xxspi_enable_bspi(b53spi); + memcpy_fromio(op->data.buf.in, b53spi->mmio_base + from, + op->data.nbytes); + + return 0; +} + +static const struct spi_controller_mem_ops bcm53xxspi_mem_ops = { + .exec_op = bcm53xxspi_exec_mem_op, +}; + static int bcm53xxspi_flash_read(struct spi_device *spi, struct spi_flash_read_message *msg) { @@ -311,8 +343,10 @@ static int bcm53xxspi_bcma_probe(struct bcma_device *core) master->dev.of_node = dev->of_node; master->transfer_one = bcm53xxspi_transfer_one; - if (b53spi->mmio_base) + if (b53spi->mmio_base) { + master->mem_ops = &bcm53xxspi_mem_ops; master->spi_flash_read = bcm53xxspi_flash_read; + } bcma_set_drvdata(core, b53spi);