From patchwork Wed Apr 8 17:03:14 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Bresticker X-Patchwork-Id: 6181651 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 3907E9F1C4 for ; Wed, 8 Apr 2015 17:03:25 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3604520386 for ; Wed, 8 Apr 2015 17:03:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 075F22037D for ; Wed, 8 Apr 2015 17:03:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932224AbbDHRDU (ORCPT ); Wed, 8 Apr 2015 13:03:20 -0400 Received: from mail-vn0-f74.google.com ([209.85.216.74]:33262 "EHLO mail-vn0-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753641AbbDHRDT (ORCPT ); Wed, 8 Apr 2015 13:03:19 -0400 Received: by vnbg62 with SMTP id g62so8278106vnb.0 for ; Wed, 08 Apr 2015 10:03:18 -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; bh=CNYb2ADSqTEBFje485zU5vqWhmbrCYmexUm20n+kZ5s=; b=Rk4Vg+rIuCf0B04vsj6yQHCD+HYxISO8hZqwza2iT1MvzkRiqvSNOqr3eeAEzHZVes nNQGBA2sJAs6nnI/UQzKCO1T+TmMrfVR2KCSScEIRa6JsZ4HHfjVV5xkWFj8tbKQ0vbb 2QEg6C2TR5ENVDkzd7egu37EPeAe2BXI5tVw42INKzH6dV1eQCigJQa7Cw7Xbrhhdknt s3piCrrlxKjm6SSJinfDLHmpTO9mrmnUOfJQsCk46rTjSrCoGEoebZR8mtAeEE2xbKWq cFg1aLx9i9qodwCVvZN49m4rrEFYT/EYGspY9wf17Ut+lgL4E74WMnX/QppY9SGEPxly HOKA== X-Gm-Message-State: ALoCoQngLtPoWEcXp9t7xM4LjMLQKCQq1SGEao1sJnjahD+R4HcHIGKSzLNkUnWjJi/cAqFw6iOM X-Received: by 10.236.189.139 with SMTP id c11mr20253948yhn.25.1428512598640; Wed, 08 Apr 2015 10:03:18 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id f100si500242yhp.7.2015.04.08.10.03.18 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Apr 2015 10:03:18 -0700 (PDT) Received: from abrestic.mtv.corp.google.com ([172.22.65.70]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id 80eTcYQk.1; Wed, 08 Apr 2015 10:03:18 -0700 Received: by abrestic.mtv.corp.google.com (Postfix, from userid 137652) id A63E4220776; Wed, 8 Apr 2015 10:03:17 -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 V2 1/3] spi: img-spfi: Implement a handle_err() callback Date: Wed, 8 Apr 2015 10:03:14 -0700 Message-Id: <1428512596-23766-1-git-send-email-abrestic@chromium.org> X-Mailer: git-send-email 2.2.0.rc0.207.ga3a616c 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 timeout handling to a handle_err() callback. Signed-off-by: Ezequiel Garcia Signed-off-by: Andrew Bresticker --- Changes from v1: - Moved timeout handling from unprepare_message() to handle_err() --- drivers/spi/spi-img-spfi.c | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) diff --git a/drivers/spi/spi-img-spfi.c b/drivers/spi/spi-img-spfi.c index bef986f..a3cf5be 100644 --- a/drivers/spi/spi-img-spfi.c +++ b/drivers/spi/spi-img-spfi.c @@ -270,7 +270,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; } @@ -396,6 +395,29 @@ stop_dma: return -EIO; } +static void img_spfi_handle_err(struct spi_master *master, + struct spi_message *msg) +{ + 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); +} + static int img_spfi_prepare(struct spi_master *master, struct spi_message *msg) { struct img_spfi *spfi = spi_master_get_devdata(master); @@ -462,8 +484,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 +493,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 +610,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->handle_err = img_spfi_handle_err; spfi->tx_ch = dma_request_slave_channel(spfi->dev, "tx"); spfi->rx_ch = dma_request_slave_channel(spfi->dev, "rx");