From patchwork Tue Apr 5 03:49:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vignesh Raghavendra X-Patchwork-Id: 8747021 Return-Path: X-Original-To: patchwork-linux-spi@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 6EB6A9F336 for ; Tue, 5 Apr 2016 03:50:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 98FA3202EB for ; Tue, 5 Apr 2016 03:50:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id B646020204 for ; Tue, 5 Apr 2016 03:50:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932510AbcDEDuo (ORCPT ); Mon, 4 Apr 2016 23:50:44 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:36163 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932511AbcDEDuU (ORCPT ); Mon, 4 Apr 2016 23:50:20 -0400 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id u353oHpZ032700; Mon, 4 Apr 2016 22:50:17 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id u353oHpB001968; Mon, 4 Apr 2016 22:50:17 -0500 Received: from dlep33.itg.ti.com (157.170.170.75) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.224.2; Mon, 4 Apr 2016 22:50:17 -0500 Received: from uda0132425.india.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id u353oCK9013329; Mon, 4 Apr 2016 22:50:15 -0500 From: Vignesh R To: Mark Brown CC: , , , Vignesh R Subject: [PATCH 1/2] spi: Add DMA support for spi_flash_read() Date: Tue, 5 Apr 2016 09:19:51 +0530 Message-ID: <1459828192-5531-2-git-send-email-vigneshr@ti.com> X-Mailer: git-send-email 2.8.0 In-Reply-To: <1459828192-5531-1-git-send-email-vigneshr@ti.com> References: <1459828192-5531-1-git-send-email-vigneshr@ti.com> MIME-Version: 1.0 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Few SPI devices provide accelerated read interfaces to read from SPI-NOR flash devices. These hardwares also support DMA to transfer data from flash to memory either via mem-to-mem DMA or dedicated slave DMA channels. Hence, add support for DMA in order to improve throughput and reduce CPU load. Use spi_map_buf() to get sg table for the buffer and pass it to SPI driver. Signed-off-by: Vignesh R --- drivers/spi/spi.c | 15 +++++++++++++++ include/linux/spi/spi.h | 2 ++ 2 files changed, 17 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index de2f2f90d799..2fb97f5b79ab 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2722,6 +2722,7 @@ int spi_flash_read(struct spi_device *spi, { struct spi_master *master = spi->master; + struct device *rx_dev = NULL; int ret; if ((msg->opcode_nbits == SPI_NBITS_DUAL || @@ -2747,8 +2748,22 @@ int spi_flash_read(struct spi_device *spi, return ret; } } + mutex_lock(&master->bus_lock_mutex); + if (master->dma_rx) { + rx_dev = master->dma_rx->device->dev; + ret = spi_map_buf(master, rx_dev, &msg->rx_sg, + msg->buf, msg->len, + DMA_FROM_DEVICE); + if (ret != 0) + goto err; + } ret = master->spi_flash_read(spi, msg); + if (master->dma_rx) + spi_unmap_buf(master, rx_dev, &msg->rx_sg, + DMA_FROM_DEVICE); + +err: mutex_unlock(&master->bus_lock_mutex); if (master->auto_runtime_pm) pm_runtime_put(master->dev.parent); diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index 857a9a1d82b5..5b9c745eda92 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1141,6 +1141,7 @@ static inline ssize_t spi_w8r16be(struct spi_device *spi, u8 cmd) * @opcode_nbits: number of lines to send opcode * @addr_nbits: number of lines to send address * @data_nbits: number of lines for data + * @rx_sg: Scatterlist for receive data */ struct spi_flash_read_message { void *buf; @@ -1153,6 +1154,7 @@ struct spi_flash_read_message { u8 opcode_nbits; u8 addr_nbits; u8 data_nbits; + struct sg_table rx_sg; }; /* SPI core interface for flash read support */