From patchwork Tue Jan 24 13:25:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Kurtz X-Patchwork-Id: 9535177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DA2406042D for ; Tue, 24 Jan 2017 13:27:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D531E27F54 for ; Tue, 24 Jan 2017 13:27:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C9F3027F8C; Tue, 24 Jan 2017 13:27:25 +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=-1.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, T_DKIM_INVALID autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7DAD727F54 for ; Tue, 24 Jan 2017 13:27:25 +0000 (UTC) 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 1cW17w-0000zg-5Z; Tue, 24 Jan 2017 13:27:12 +0000 Received: from mail-pg0-f52.google.com ([74.125.83.52]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cW17X-0000xp-Hc for linux-arm-kernel@lists.infradead.org; Tue, 24 Jan 2017 13:26:49 +0000 Received: by mail-pg0-f52.google.com with SMTP id 14so55154668pgg.1 for ; Tue, 24 Jan 2017 05:26:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=8wEs3Ucsomz1SM3aBjylgGZfTRUFndjmenGCsd/3maI=; b=h9aRe7C7tngxrZdbvcH8oWBlb6oEXH5GnhNOHu7LFR3+p9AO3aOBpGLgIHGHckkM4W 3OC9HvQrTKfliAk+zVyPmWBcCAuJ3s41dfGPx4lqWSACkU/MDJr95v7Nt9cSAkVlzeox XWn8CiUdPKaXm2SuQVHHsYTWdyBAp1iIMUG70= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=8wEs3Ucsomz1SM3aBjylgGZfTRUFndjmenGCsd/3maI=; b=UlwPNX4vZFAxLLaRkwGRGDbyAfzeK63gnaKWV6QQxff1rUfDDkfoHRcAVo1DmyVums bctT2vyEMQUW3ADWlTFpv4mjei4c7cZSL1DHyu6XRYKbEWqDbiTwzR8OMVfvW/er7Jwa mMVi74L3H6EqYteK1oNJTZphKEaD+lTmllq8+mPe8OgQCio7NeQLZYVjkqyVPCQ3yICA RRbVdGaP59rGkyATOoCRAzD23fRdld6sUIQIkqkrQaJbvbXjJP15a4IFF8KPp1EgZaCr dkex5HxCxXXR/+X38n6m9gPO5QNWHzwGg/5O2YYzeJytdVEAZhLNvXptGyKgmt73FbLr tWOQ== X-Gm-Message-State: AIkVDXL4R2rQL1VWF2c10l/7BreOEGhE/LM2ee4bifqqWdrDRowQvxYcFJPSbK54MochBWbY X-Received: by 10.98.50.66 with SMTP id y63mr38601798pfy.21.1485264325836; Tue, 24 Jan 2017 05:25:25 -0800 (PST) Received: from djkurtz-z840.tpe.corp.google.com ([172.30.210.11]) by smtp.gmail.com with ESMTPSA id z70sm45019879pff.26.2017.01.24.05.25.23 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Jan 2017 05:25:25 -0800 (PST) From: Daniel Kurtz To: Leilk Liu Subject: [PATCH] spi: mediatek: Manually set dma_ops for spi_master device Date: Tue, 24 Jan 2017 21:25:19 +0800 Message-Id: <20170124132519.13271-1-djkurtz@chromium.org> X-Mailer: git-send-email 2.11.0.483.g087da7b7c-goog X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170124_052647_642044_F3EF11FE X-CRM114-Status: GOOD ( 17.90 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: open list , Daniel Kurtz , "open list:SPI SUBSYSTEM" , Matthias Brugger , Mark Brown , "moderated list:ARM/Mediatek SoC support" , groeck@chromium.org, dtor@chromium.org, "moderated list:ARM/Mediatek SoC support" MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Back before commit 1dccb598df54 ("arm64: simplify dma_get_ops"), for arm64, devices that do not manually set a dma_ops are automatically configured to use swiotlb_dma_ops, since this was hard-coded as the global "dma_ops" in arm64_dma_init(). Now, the global "dma_ops" has been removed, and all devices much have their dma_ops explicitly set by a call to arch_setup_dma_ops(). If arch_setup_dma_ops() is not called, the device is assigned dummy_dma_ops, and thus calls to map_sg for such a device will fail (return 0). Mediatek SPI uses DMA but does not use a dma channel. Support for this was added by commit c37f45b5f1cd ("spi: support spi without dma channel to use can_dma()"), which uses the master_spi dev to DMA map buffers. The master_spi device is not a platform, rather it is created in spi_alloc_device(), and its dma_ops are never set. Therefore, when the mediatek SPI driver when it does DMA (for large SPI transactions > 32 bytes), SPI will use spi_map_buf()->dma_map_sg() to map the buffer for use in DMA. But dma_map_sg()->dma_map_sg_attrs() returns 0, because ops->map_sg is dummy_dma_ops->__dummy_map_sg, and hence spi_map_buf() returns -ENOMEM (-12). The solution in this patch is a bit of a hack. To install dma_ops for its spi_master, we call of_dma_configure() during probe and pass in the of_node of the spi-mt65xx platform device. However, by default, of_dma_configure() will set the coherent_dma_mask to 0xffffffff. In fact, using a non-zero dma_mask doesn't actually work and causes frequent SPI transaction errors. To work around this, we also explicitly set coherent_dma_mask to 0. Signed-off-by: Daniel Kurtz --- I don't know the right place to configure the dma_ops for spi_master. It feels like this should actually be done in the spi core, as this might be needed by other drivers. Alternatively, perhaps we should be using master->dev.parent to dma map bufs in the "no dma channel case". And I really don't know why we needed to set the coherent_dma_mask to 0 to avoid SPI transaction errors. Any advice is welcome. drivers/spi/spi-mt65xx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/spi/spi-mt65xx.c b/drivers/spi/spi-mt65xx.c index 8763eff13d3d..e768835bb67f 100644 --- a/drivers/spi/spi-mt65xx.c +++ b/drivers/spi/spi-mt65xx.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -575,6 +576,10 @@ static int mtk_spi_probe(struct platform_device *pdev) goto err_put_master; } + /* Call of_dma_configure to set up spi_master's dma_ops */ + of_dma_configure(&master->dev, master->dev.of_node); + /* But explicitly set the coherent_dma_mask to 0 */ + master->dev.coherent_dma_mask = 0; if (!pdev->dev.dma_mask) pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;