From patchwork Wed Jun 2 16:08:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Sneddon X-Patchwork-Id: 12295233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5DFF9C47083 for ; Wed, 2 Jun 2021 16:11:47 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2C1E461928 for ; Wed, 2 Jun 2021 16:11:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2C1E461928 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Mr0U1VtvUCMhbME47dEmfZLAApdllat0Rp4439oCgiQ=; b=kpG3M7COD3ET8m Uz7poRg62fwr7VhBQQaUXQvU97NGTTlY87RN/AEtgegTf1dzdd+af24ScnwfPrLN7Qzlkr72K8wv4 fhya3YcPoyqWl7fIFIvggZ7xDmwFL2hoE/LElIoCpMof5wNEPRRH6SW1jiP32dPJIPPpk6f2BuOO9 6uQDMlzzta32OlYeIOZAvm6P+JFuzx7gHSFKkq0Mzv8dHa5IbbVXkHmnkwsU3vUKleb8dElw36jtn 9jJJdqqPYGEwW5O2k8em75TKZbZ5aSzDAF24jXCkXcUGUStbAVFx4tv7T1vnaHYTbIT5T9kizw+hE 4Lht0aZ73/equcJ/AmTw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1loTRD-00537r-0s; Wed, 02 Jun 2021 16:09:47 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1loTQ7-0052gb-Ct for linux-arm-kernel@lists.infradead.org; Wed, 02 Jun 2021 16:08:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1622650120; x=1654186120; h=from:to:cc:subject:date:message-id:mime-version; bh=UjDEAZpz89SSiZ6EJwwrCicKYWz8Tlvi693/IFwHgWA=; b=tyZ0tEwkvUsLpaq4iD7aBWegL0nQPTOjy15ugskGrc8Zou5XtwGnniY7 619W+8PUnpowNt9VJXAbA1njwyN/J9PP3Hewm9Xx0PsRm9X9PzUD+Y/IJ 9MYrcnXrchivXydkrfYe+Plsla47rsgvt8pl10drqO5eWfUB7v2jqdVtm cqaQYbHSCWaKNMayqxiksIyDByYnwB8QZg6boZ2QwvTGAIkXUdPpbxDip 04A/BICRAI2qX1OU7uaW6Vyd2OuoeBqGiRXSozbyKibjDpPx/wFsh106Q Tp6tPKSYL3wHgcaIB/UF7cC4Owf9rLX7NYkMQOsEg45lvMLrpAajQp0v+ A==; IronPort-SDR: uEmO9FZw+ftc1lc44Cm3/4/qLkejKle6n4xy2E1HDTxzE4tynPRqhR0EZ8QuGNyvHpcg07HNog W6Ls2yXYkCUSEqMLudMK4TA7Nt2R7I1EyEof8/7UVZsTRK0x3LBHakqCuVdOC289qrkZE+I4v/ trlvU8/na6ZXXJqxvwM9mIG8hFuGGYHCSAtutHituM2HEoLdf0B2cpuwosttou8+ck7RsHQKQk wWkyRQ+hPsuviiQixgPEKf7+w68SZJ64JPjyhxLP/TdevSGePQ5myPGkJuL0hgwzpDr15hVA6N xM8= X-IronPort-AV: E=Sophos;i="5.83,242,1616482800"; d="scan'208";a="123275440" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 02 Jun 2021 09:08:36 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 2 Jun 2021 09:08:35 -0700 Received: from dan-linux.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 2 Jun 2021 09:08:35 -0700 From: Dan Sneddon To: , , Subject: [PATCH 1/2] spi: atmel: Switch to transfer_one transfer method Date: Wed, 2 Jun 2021 09:08:14 -0700 Message-ID: <20210602160816.4890-1-dan.sneddon@microchip.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210602_090839_516391_1D3909F2 X-CRM114-Status: GOOD ( 18.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Tudor Ambarus , Dan Sneddon , Ludovic Desroches , Mark Brown Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Switch from using our own transfer_one_message routine to using the one provided by the SPI core. Signed-off-by: Dan Sneddon --- drivers/spi/spi-atmel.c | 124 +++++++++++----------------------------- 1 file changed, 33 insertions(+), 91 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 7cd5fe00dfc1..0e693e72c922 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -863,7 +863,6 @@ static int atmel_spi_set_xfer_speed(struct atmel_spi *as, * lock is held, spi irq is blocked */ static void atmel_spi_pdc_next_xfer(struct spi_master *master, - struct spi_message *msg, struct spi_transfer *xfer) { struct atmel_spi *as = spi_master_get_devdata(master); @@ -879,12 +878,12 @@ static void atmel_spi_pdc_next_xfer(struct spi_master *master, spi_writel(as, RPR, rx_dma); spi_writel(as, TPR, tx_dma); - if (msg->spi->bits_per_word > 8) + if (xfer->bits_per_word > 8) len >>= 1; spi_writel(as, RCR, len); spi_writel(as, TCR, len); - dev_dbg(&msg->spi->dev, + dev_dbg(&master->dev, " start xfer %p: len %u tx %p/%08llx rx %p/%08llx\n", xfer, xfer->len, xfer->tx_buf, (unsigned long long)xfer->tx_dma, xfer->rx_buf, @@ -898,12 +897,12 @@ static void atmel_spi_pdc_next_xfer(struct spi_master *master, spi_writel(as, RNPR, rx_dma); spi_writel(as, TNPR, tx_dma); - if (msg->spi->bits_per_word > 8) + if (xfer->bits_per_word > 8) len >>= 1; spi_writel(as, RNCR, len); spi_writel(as, TNCR, len); - dev_dbg(&msg->spi->dev, + dev_dbg(&master->dev, " next xfer %p: len %u tx %p/%08llx rx %p/%08llx\n", xfer, xfer->len, xfer->tx_buf, (unsigned long long)xfer->tx_dma, xfer->rx_buf, @@ -1273,12 +1272,28 @@ static int atmel_spi_setup(struct spi_device *spi) return 0; } +static void atmel_spi_set_cs(struct spi_device *spi, bool enable) +{ + struct atmel_spi *as = spi_master_get_devdata(spi->master); + /* the core doesn't really pass us enable/disable, but CS HIGH vs CS LOW + * since we already have routines for activate/deactivate translate + * high/low to active/inactive + */ + enable = (!!(spi->mode & SPI_CS_HIGH) == enable); + + if (enable) { + cs_activate(as, spi); + } else { + cs_deactivate(as, spi); + } + +} + static int atmel_spi_one_transfer(struct spi_master *master, - struct spi_message *msg, + struct spi_device *spi, struct spi_transfer *xfer) { struct atmel_spi *as; - struct spi_device *spi = msg->spi; u8 bits; u32 len; struct atmel_spi_device *asd; @@ -1287,11 +1302,8 @@ static int atmel_spi_one_transfer(struct spi_master *master, unsigned long dma_timeout; as = spi_master_get_devdata(master); - - if (!(xfer->tx_buf || xfer->rx_buf) && xfer->len) { - dev_dbg(&spi->dev, "missing rx or tx buf\n"); - return -EINVAL; - } + /* This lock was orignally taken in atmel_spi_trasfer_one_message */ + atmel_spi_lock(as); asd = spi->controller_state; bits = (asd->csr >> 4) & 0xf; @@ -1305,13 +1317,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, * DMA map early, for performance (empties dcache ASAP) and * better fault reporting. */ - if ((!msg->is_dma_mapped) + if ((!master->cur_msg_mapped) && as->use_pdc) { if (atmel_spi_dma_map_xfer(as, xfer) < 0) return -ENOMEM; } - atmel_spi_set_xfer_speed(as, msg->spi, xfer); + atmel_spi_set_xfer_speed(as, spi, xfer); as->done_status = 0; as->current_transfer = xfer; @@ -1320,7 +1332,7 @@ static int atmel_spi_one_transfer(struct spi_master *master, reinit_completion(&as->xfer_completion); if (as->use_pdc) { - atmel_spi_pdc_next_xfer(master, msg, xfer); + atmel_spi_pdc_next_xfer(master, xfer); } else if (atmel_spi_use_dma(as, xfer)) { len = as->current_remaining_bytes; ret = atmel_spi_next_xfer_dma_submit(master, @@ -1328,7 +1340,8 @@ static int atmel_spi_one_transfer(struct spi_master *master, if (ret) { dev_err(&spi->dev, "unable to use DMA, fallback to PIO\n"); - atmel_spi_next_xfer_pio(master, xfer); + as->done_status = ret; + break; } else { as->current_remaining_bytes -= len; if (as->current_remaining_bytes < 0) @@ -1381,90 +1394,18 @@ static int atmel_spi_one_transfer(struct spi_master *master, } else if (atmel_spi_use_dma(as, xfer)) { atmel_spi_stop_dma(master); } - - if (!msg->is_dma_mapped - && as->use_pdc) - atmel_spi_dma_unmap_xfer(master, xfer); - - return 0; - - } else { - /* only update length if no error */ - msg->actual_length += xfer->len; } - if (!msg->is_dma_mapped + if (!master->cur_msg_mapped && as->use_pdc) atmel_spi_dma_unmap_xfer(master, xfer); - spi_transfer_delay_exec(xfer); - - if (xfer->cs_change) { - if (list_is_last(&xfer->transfer_list, - &msg->transfers)) { - as->keep_cs = true; - } else { - cs_deactivate(as, msg->spi); - udelay(10); - cs_activate(as, msg->spi); - } - } - - return 0; -} - -static int atmel_spi_transfer_one_message(struct spi_master *master, - struct spi_message *msg) -{ - struct atmel_spi *as; - struct spi_transfer *xfer; - struct spi_device *spi = msg->spi; - int ret = 0; - - as = spi_master_get_devdata(master); - - dev_dbg(&spi->dev, "new message %p submitted for %s\n", - msg, dev_name(&spi->dev)); - - atmel_spi_lock(as); - cs_activate(as, spi); - - as->keep_cs = false; - - msg->status = 0; - msg->actual_length = 0; - - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - trace_spi_transfer_start(msg, xfer); - - ret = atmel_spi_one_transfer(master, msg, xfer); - if (ret) - goto msg_done; - - trace_spi_transfer_stop(msg, xfer); - } - if (as->use_pdc) atmel_spi_disable_pdc_transfer(as); - list_for_each_entry(xfer, &msg->transfers, transfer_list) { - dev_dbg(&spi->dev, - " xfer %p: len %u tx %p/%pad rx %p/%pad\n", - xfer, xfer->len, - xfer->tx_buf, &xfer->tx_dma, - xfer->rx_buf, &xfer->rx_dma); - } - -msg_done: - if (!as->keep_cs) - cs_deactivate(as, msg->spi); - atmel_spi_unlock(as); - msg->status = as->done_status; - spi_finalize_current_message(spi->master); - - return ret; + return as->done_status; } static void atmel_spi_cleanup(struct spi_device *spi) @@ -1554,7 +1495,8 @@ static int atmel_spi_probe(struct platform_device *pdev) master->num_chipselect = 4; master->setup = atmel_spi_setup; master->flags = (SPI_MASTER_MUST_RX | SPI_MASTER_MUST_TX); - master->transfer_one_message = atmel_spi_transfer_one_message; + master->transfer_one = atmel_spi_one_transfer; + master->set_cs = atmel_spi_set_cs; master->cleanup = atmel_spi_cleanup; master->auto_runtime_pm = true; master->max_dma_len = SPI_MAX_DMA_XFER; From patchwork Wed Jun 2 16:08:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Sneddon X-Patchwork-Id: 12295243 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7093DC47083 for ; Wed, 2 Jun 2021 16:12:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 367996192C for ; Wed, 2 Jun 2021 16:12:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 367996192C Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=microchip.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=PHOSN+RYpOQyBlg/MmiAdVpgbMa83JC/J34TVPsqH/c=; b=EewPa1h2x0P4iT rY7eYNLOeUoauf756CZQuTFGjyvbKY6y68cFUCs4HqtfhxlAi7CuLoCx3XBuScgV1mbKOJYkwRFDK pbuE4RdHU5a+A0+azOIT19NvPmZogrGtCUd+oPcp+2ynKNCQzQoLLW5+u2d310zSGNI65NRDz5p8o ncKluONUBntikBo/D7jSBhHLNwtKnK5SBRh+H8jlGMchYziog16R/b18/4NLJOZGYwg5ZObQB9YMK MjQQLteoeGHVCcU6FgOXj1vrnMJezfGl/4ZQ19bc+1m14RaXQ6NPp4vZdlnbHDeNtOdBEJ3/ASn3w PTX66FfggeEM4VEayqbQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1loTSF-0053UI-5m; Wed, 02 Jun 2021 16:10:52 +0000 Received: from esa.microchip.iphmx.com ([68.232.153.233]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1loTQA-0052gb-7q for linux-arm-kernel@lists.infradead.org; Wed, 02 Jun 2021 16:08:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=microchip.com; i=@microchip.com; q=dns/txt; s=mchp; t=1622650123; x=1654186123; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version; bh=xM1Z4XPCdE5QfVSLjvhJSs57E9XcJ2Y6MAuOiSOnj9U=; b=TZQ8SZLYcEWzGlHwlSzf0Nl0pAQ9gUIb2EIyA9C3L7RCkLiY3fARk/In LsI8eZXI6az7iRFTNC1cahu4oluu1RB3VPKZkTQKPpgMIkk5d0WJ1Jol2 u9k1hZO5KedMcCIdBrjI24TnDWd6Z/M6pv7/qdt+zjvWaXuPuT9cDkflV og5bHD9+DAMqd+Qs9e+NZXSAaWHXdN0G3lZR0AMnwivqAUQsf/ZLD9MXo NOyfIxJvEC1KB+CGDS2mQaosd+QYQqyaiosERvwmSoAdM1hVWKaHkar/f BEzDyIBRE6oKHNCl/B6x5J1FQV764FPSkBBaoRTVS1SmDw2IcCMttm/ih w==; IronPort-SDR: lnKl10SvjnU5CCbCAzOVyTkuRemZZf9aV2vQmLZBkqnlh0mZGVM7+AR2oOaQl5SPwwu4Eyv2SW innJFxDpjploJtbMbDkiv4amsqHM/ZbsF0Xju/QU3JW/7Nr10UpUc/NH881V7rCJnbq4qwcSQ7 MIu86H9RTV5R9U1uP3YBb7XUxOAHYgF82GTPGvyuyK3PfeUBoDDN1/rKhuYku0DvkAhZXpJ3RH 09P9gNKxiFzkmvRsycUQCE+mJctnHOhjDIprSXhRYe0t+K2ZzohTt91TA6xF1tPw6cWRHRLeGP fyQ= X-IronPort-AV: E=Sophos;i="5.83,242,1616482800"; d="scan'208";a="123275443" Received: from smtpout.microchip.com (HELO email.microchip.com) ([198.175.253.82]) by esa5.microchip.iphmx.com with ESMTP/TLS/AES256-SHA256; 02 Jun 2021 09:08:38 -0700 Received: from chn-vm-ex04.mchp-main.com (10.10.85.152) by chn-vm-ex01.mchp-main.com (10.10.85.143) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Wed, 2 Jun 2021 09:08:36 -0700 Received: from dan-linux.microchip.com (10.10.115.15) by chn-vm-ex04.mchp-main.com (10.10.85.152) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Wed, 2 Jun 2021 09:08:36 -0700 From: Dan Sneddon To: , , Subject: [PATCH 2/2] spi: atmel: Reduce spin lock usage Date: Wed, 2 Jun 2021 09:08:15 -0700 Message-ID: <20210602160816.4890-2-dan.sneddon@microchip.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210602160816.4890-1-dan.sneddon@microchip.com> References: <20210602160816.4890-1-dan.sneddon@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210602_090842_336219_C5073334 X-CRM114-Status: GOOD ( 16.74 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Belloni , Tudor Ambarus , Dan Sneddon , Ludovic Desroches , Mark Brown Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The current implementation of the driver holds a spin lock for the duration of the transfer, releasing it only to enable interrupts for short periods of time. As this would prevent any interrupt from happening, this could cause system performance issues every time a SPI message is sent. Since the spi core now handles message syncronization we can reduce the amount of time the spin-lock is held to the regions where both the calling thread and the interrupt might interract. Signed-off-by: Dan Sneddon --- drivers/spi/spi-atmel.c | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/drivers/spi/spi-atmel.c b/drivers/spi/spi-atmel.c index 0e693e72c922..2ef74885ffa2 100644 --- a/drivers/spi/spi-atmel.c +++ b/drivers/spi/spi-atmel.c @@ -700,7 +700,6 @@ static void atmel_spi_next_xfer_pio(struct spi_master *master, static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, struct spi_transfer *xfer, u32 *plen) - __must_hold(&as->lock) { struct atmel_spi *as = spi_master_get_devdata(master); struct dma_chan *rxchan = master->dma_rx; @@ -716,8 +715,6 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, if (!rxchan || !txchan) return -ENODEV; - /* release lock for DMA operations */ - atmel_spi_unlock(as); *plen = xfer->len; @@ -786,15 +783,12 @@ static int atmel_spi_next_xfer_dma_submit(struct spi_master *master, rxchan->device->device_issue_pending(rxchan); txchan->device->device_issue_pending(txchan); - /* take back lock */ - atmel_spi_lock(as); return 0; err_dma: spi_writel(as, IDR, SPI_BIT(OVRES)); atmel_spi_stop_dma(master); err_exit: - atmel_spi_lock(as); return -ENOMEM; } @@ -1053,8 +1047,6 @@ atmel_spi_pump_pio_data(struct atmel_spi *as, struct spi_transfer *xfer) /* Interrupt * - * No need for locking in this Interrupt handler: done_status is the - * only information modified. */ static irqreturn_t atmel_spi_pio_interrupt(int irq, void *dev_id) @@ -1302,8 +1294,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, unsigned long dma_timeout; as = spi_master_get_devdata(master); - /* This lock was orignally taken in atmel_spi_trasfer_one_message */ - atmel_spi_lock(as); asd = spi->controller_state; bits = (asd->csr >> 4) & 0xf; @@ -1332,7 +1322,9 @@ static int atmel_spi_one_transfer(struct spi_master *master, reinit_completion(&as->xfer_completion); if (as->use_pdc) { + atmel_spi_lock(as); atmel_spi_pdc_next_xfer(master, xfer); + atmel_spi_unlock(as); } else if (atmel_spi_use_dma(as, xfer)) { len = as->current_remaining_bytes; ret = atmel_spi_next_xfer_dma_submit(master, @@ -1348,14 +1340,13 @@ static int atmel_spi_one_transfer(struct spi_master *master, as->current_remaining_bytes = 0; } } else { + atmel_spi_lock(as); atmel_spi_next_xfer_pio(master, xfer); + atmel_spi_unlock(as); } - /* interrupts are disabled, so free the lock for schedule */ - atmel_spi_unlock(as); dma_timeout = wait_for_completion_timeout(&as->xfer_completion, SPI_DMA_TIMEOUT); - atmel_spi_lock(as); if (WARN_ON(dma_timeout == 0)) { dev_err(&spi->dev, "spi transfer timeout\n"); as->done_status = -EIO; @@ -1403,8 +1394,6 @@ static int atmel_spi_one_transfer(struct spi_master *master, if (as->use_pdc) atmel_spi_disable_pdc_transfer(as); - atmel_spi_unlock(as); - return as->done_status; }