From patchwork Tue Jan 12 09:02:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 8015351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3F97A9F88A for ; Tue, 12 Jan 2016 09:04:24 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 29BE8203A4 for ; Tue, 12 Jan 2016 09:04:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 8D91320379 for ; Tue, 12 Jan 2016 09:04:21 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIur1-0001lc-KR; Tue, 12 Jan 2016 09:03:03 +0000 Received: from mo6-p05-ob.smtp.rzone.de ([2a01:238:20a:202:5305::3]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aIuqv-0001fI-0Z for linux-arm-kernel@lists.infradead.org; Tue, 12 Jan 2016 09:03:01 +0000 X-RZG-AUTH: :IW0NeWC7b/q2i6W/qstXb1SBUuFnrGohfvxEndrDXKjzPMsB3oimjD61I4fPQhgcz213 X-RZG-CLASS-ID: mo05 Received: from stefan-work.domain_not_set.invalid (b9168f50.cgn.dg-w.de [185.22.143.80]) by post.strato.de (RZmta 37.15 AUTH) with ESMTPA id f04a3bs0C92JRLf; Tue, 12 Jan 2016 10:02:19 +0100 (CET) From: Stefan Roese To: linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org Subject: [PATCH RFC] spi: orion.c: Add direct write mode Date: Tue, 12 Jan 2016 10:02:19 +0100 Message-Id: <1452589339-21402-1-git-send-email-sr@denx.de> X-Mailer: git-send-email 2.6.5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160112_010257_379228_3370D2FE X-CRM114-Status: GOOD ( 18.90 ) X-Spam-Score: -2.6 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nadav Haklai , Thomas Petazzoni , Mark Brown , Gregory CLEMENT MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds support for the direct write mode to the Orion SPI driver which is used on the Marvell Armada based SoCs. In this direct mode, all data written to a specifically mapped MBus window (linked to only one SPI chip-select on one of the SPI controllers) will be transferred directly to the SPI bus. Without the need to control the SPI registers in between. This can improve the SPI transfer rate in such cases. Currently only the direct write mode is supported. This mode especially benefits from the SPI direct mode, as the data bytes are written head-to-head to the SPI bus, without any additional addresses, that are also written in the direct read mode. One use-case for this direct write mode is, programming a FPGA bitstream image into the FPGA connected to the SPI bus at maximum speed. This mode is described in chapter "22.5.2 Direct Write to SPI" in the Marvell Armada XP Functional Spec Datasheet. Signed-off-by: Stefan Roese Cc: Nadav Haklai Cc: Thomas Petazzoni Cc: Gregory CLEMENT Cc: Mark Brown --- .../devicetree/bindings/spi/spi-orion.txt | 26 ++++++++++ drivers/spi/spi-orion.c | 59 ++++++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/Documentation/devicetree/bindings/spi/spi-orion.txt b/Documentation/devicetree/bindings/spi/spi-orion.txt index 98bc698..b22ebc5 100644 --- a/Documentation/devicetree/bindings/spi/spi-orion.txt +++ b/Documentation/devicetree/bindings/spi/spi-orion.txt @@ -12,6 +12,8 @@ Required properties: - cell-index : Which of multiple SPI controllers is this. Optional properties: - interrupts : Is currently not used. +- direct-addr : The phandle to the node containing the base address + of the direct-mapped MBus window for this SPI device. Example: spi@10600 { @@ -23,3 +25,27 @@ Example: interrupts = <23>; status = "disabled"; }; + +Example with direct-write mode: + soc { + ranges = ; /* SPI0 CS1 */ + + spi0_cs1: spi@015e { + compatible = "marvell,spi-direct-mode"; + reg = ; + }; + + ... + + spi@10600 { + compatible = "marvell,orion-spi"; + status = "okay"; + + spidev@1 { + compatible = "spidev"; + direct-addr = <&spi0_cs1>; + reg = <1>; + }; + }; diff --git a/drivers/spi/spi-orion.c b/drivers/spi/spi-orion.c index a87cfd4..c028679 100644 --- a/drivers/spi/spi-orion.c +++ b/drivers/spi/spi-orion.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,9 @@ #define ORION_SPI_INT_CAUSE_REG 0x10 #define ORION_SPI_TIMING_PARAMS_REG 0x18 +/* Register for the "Direct Mode" */ +#define SPI_DIRECT_WRITE_CONFIG_REG 0x20 + #define ORION_SPI_TMISO_SAMPLE_MASK (0x3 << 6) #define ORION_SPI_TMISO_SAMPLE_1 (1 << 6) #define ORION_SPI_TMISO_SAMPLE_2 (2 << 6) @@ -83,6 +87,7 @@ struct orion_spi { void __iomem *base; struct clk *clk; const struct orion_spi_dev *devdata; + void __iomem *slave_direct_addr[8]; }; static inline void __iomem *spi_reg(struct orion_spi *orion_spi, u32 reg) @@ -372,10 +377,29 @@ orion_spi_write_read(struct spi_device *spi, struct spi_transfer *xfer) { unsigned int count; int word_len; + struct orion_spi *orion_spi; + void __iomem *direct_addr; word_len = spi->bits_per_word; count = xfer->len; + /* Use SPI direct write mode if such an address is provided via DT */ + orion_spi = spi_master_get_devdata(spi->master); + direct_addr = orion_spi->slave_direct_addr[spi->chip_select]; + if (direct_addr && xfer->tx_buf) { + /* Deassert CS between the SPI transfers */ + writel(0x00010000, spi_reg(orion_spi, + SPI_DIRECT_WRITE_CONFIG_REG)); + + /* + * Send the tx-data to the SPI device via the direct mapped + * address window + */ + memcpy(direct_addr, xfer->tx_buf, count); + + return count; + } + if (word_len == 8) { const u8 *tx = xfer->tx_buf; u8 *rx = xfer->rx_buf; @@ -501,6 +525,7 @@ static int orion_spi_probe(struct platform_device *pdev) const struct orion_spi_dev *devdata; struct spi_master *master; struct orion_spi *spi; + struct device_node *np; struct resource *r; unsigned long tclk_hz; int status = 0; @@ -576,6 +601,40 @@ static int orion_spi_probe(struct platform_device *pdev) goto out_rel_clk; } + /* + * Scan all SPI devices of this controller for direct mapped devices + */ + for_each_available_child_of_node(pdev->dev.of_node, np) { + struct device_node *direct_addr_np; + + /* + * Get "direct-addr" device node with the mapping info + */ + direct_addr_np = of_parse_phandle(np, "direct-addr", 0); + if (direct_addr_np) { + struct resource res; + u32 cs; + int rc; + + /* Get chip-select number from the "reg" property */ + rc = of_property_read_u32(np, "reg", &cs); + if (rc) { + dev_err(&pdev->dev, + "%s has no valid 'reg' property (%d)\n", + direct_addr_np->full_name, rc); + continue; + } + + /* + * Store the address to use it later for the direct + * access + */ + rc = of_address_to_resource(direct_addr_np, 0, &res); + spi->slave_direct_addr[cs] = + devm_ioremap_resource(&pdev->dev, &res); + } + } + pm_runtime_set_active(&pdev->dev); pm_runtime_use_autosuspend(&pdev->dev); pm_runtime_set_autosuspend_delay(&pdev->dev, SPI_AUTOSUSPEND_TIMEOUT);