From patchwork Mon Apr 6 21:29:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 6166111 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 A70A59F54F for ; Mon, 6 Apr 2015 21:29:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C39D7202F8 for ; Mon, 6 Apr 2015 21:29:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D5DD32034B for ; Mon, 6 Apr 2015 21:29:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753083AbbDFV3O (ORCPT ); Mon, 6 Apr 2015 17:29:14 -0400 Received: from mail-ie0-f202.google.com ([209.85.223.202]:33609 "EHLO mail-ie0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753038AbbDFV3K (ORCPT ); Mon, 6 Apr 2015 17:29:10 -0400 Received: by iebtr6 with SMTP id tr6so2263108ieb.0 for ; Mon, 06 Apr 2015 14:29:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=6XOKleZwHaK4B9tRgi7mTArQrOF90ieIU30gmWJRV78=; b=e38fvRwEkEKy+1I1Kuw3Cm8M6rODh5B2HeS0ycpFum2NmYCFmLeUNN7b5J0CrtQbD7 j4alY9sOisAkSw9vE48EONOZ5QQOE5fCTUMKxGchSLKA534y75iPcPp5A76ESZP2zFqO cCwkxt4MNLS0mvLJVn45GXeJBHpi++75OitOnSsOgzo+1yXxVtY+D3o408/3sxGBeoe5 mfYWvD2bA4wmkdIZqW1qST0IfaagVLJsXuX/WVxrvYc2TLVXp72QZTeDnHWHz0OYuldS jUbzOTgswkwafSleWg2LXz6aANscPpBEE1r+InPHA7M/Wt/kk9HKUnBBAQ8PyzeiMEJn Aulw== X-Gm-Message-State: ALoCoQk2ch6xP/7k1Si6ugR1iujWBv94CtXftesnDnJX1Dzn9AvO3DGUPl4wJdx1TCpSA0xAcDar X-Received: by 10.50.50.195 with SMTP id e3mr506158igo.6.1428355749970; Mon, 06 Apr 2015 14:29:09 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id f100si256511yhp.7.2015.04.06.14.29.09 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 06 Apr 2015 14:29:09 -0700 (PDT) Received: from abrestic.mtv.corp.google.com ([172.22.65.70]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id e520XNQ3.1; Mon, 06 Apr 2015 14:29:09 -0700 Received: by abrestic.mtv.corp.google.com (Postfix, from userid 137652) id 240DE220E85; Mon, 6 Apr 2015 14:29:09 -0700 (PDT) From: Andrew Bresticker To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, Ezequiel Garcia , Andrew Bresticker Subject: [PATCH 3/5] spi: img-spfi: Implement an unprepare_message() callback Date: Mon, 6 Apr 2015 14:29:05 -0700 Message-Id: <1428355747-16822-3-git-send-email-abrestic@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c In-Reply-To: <1428355747-16822-1-git-send-email-abrestic@chromium.org> References: <1428355747-16822-1-git-send-email-abrestic@chromium.org> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 From: Ezequiel Garcia The driver can be greatly simplified by moving the transfer finishing and timeout handling to an unprepare_message() callback. Signed-off-by: Ezequiel Garcia Signed-off-by: Andrew Bresticker --- drivers/spi/spi-img-spfi.c | 45 +++++++++++++++++++++++++-------------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c index b1c0165..30c89f9 100644 --- a/drivers/spi/spi-img-spfi.c +++ b/drivers/spi/spi-img-spfi.c @@ -271,7 +271,6 @@ static int img_spfi_start_pio(struct spi_master *master, if (rx_bytes > 0 || tx_bytes > 0) { dev_err(spfi->dev, "PIO transfer timed out\n"); - spfi_reset(spfi); return -ETIMEDOUT; } @@ -397,6 +396,30 @@ stop_dma: return -EIO; } +static int img_spfi_unprepare(struct spi_master *master, struct spi_message *m) +{ + struct img_spfi *spfi = spi_master_get_devdata(master); + unsigned long flags; + + /* + * Stop all DMA and reset the controller if the previous transaction + * timed-out and never completed it's DMA. + */ + spin_lock_irqsave(&spfi->lock, flags); + if (spfi->tx_dma_busy || spfi->rx_dma_busy) { + spfi->tx_dma_busy = false; + spfi->rx_dma_busy = false; + + dmaengine_terminate_all(spfi->tx_ch); + dmaengine_terminate_all(spfi->rx_ch); + } + spin_unlock_irqrestore(&spfi->lock, flags); + + spfi_reset(spfi); + + return 0; +} + static int img_spfi_prepare(struct spi_master *master, struct spi_message *msg) { struct img_spfi *spfi = spi_master_get_devdata(master); @@ -462,8 +485,6 @@ static int img_spfi_transfer_one(struct spi_master *master, struct spi_transfer *xfer) { struct img_spfi *spfi = spi_master_get_devdata(spi->master); - bool dma_reset = false; - unsigned long flags; int ret; if (xfer->len > SPFI_TRANSACTION_TSIZE_MASK) { @@ -473,23 +494,6 @@ static int img_spfi_transfer_one(struct spi_master *master, return -EINVAL; } - /* - * Stop all DMA and reset the controller if the previous transaction - * timed-out and never completed it's DMA. - */ - spin_lock_irqsave(&spfi->lock, flags); - if (spfi->tx_dma_busy || spfi->rx_dma_busy) { - dev_err(spfi->dev, "SPI DMA still busy\n"); - dma_reset = true; - } - spin_unlock_irqrestore(&spfi->lock, flags); - - if (dma_reset) { - dmaengine_terminate_all(spfi->tx_ch); - dmaengine_terminate_all(spfi->rx_ch); - spfi_reset(spfi); - } - img_spfi_config(master, spi, xfer); if (master->can_dma && master->can_dma(master, spi, xfer)) ret = img_spfi_start_dma(master, spi, xfer); @@ -607,6 +611,7 @@ static int img_spfi_probe(struct platform_device *pdev) master->set_cs = img_spfi_set_cs; master->transfer_one = img_spfi_transfer_one; master->prepare_message = img_spfi_prepare; + master->unprepare_message = img_spfi_unprepare; spfi->tx_ch = dma_request_slave_channel(spfi->dev, "tx"); spfi->rx_ch = dma_request_slave_channel(spfi->dev, "rx");