From patchwork Wed Feb 13 07:36:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "\(Exiting\) Baolin Wang" X-Patchwork-Id: 158195 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4752257jaa; Tue, 12 Feb 2019 23:37:26 -0800 (PST) X-Google-Smtp-Source: AHgI3IbFOgKZsNf0o3CQBP/qCSqzcs3jk2AfZVWAwqZ4/12boTYeoAD4LeUVjdSxNHxWWv5aMLw3 X-Received: by 2002:a17:902:583:: with SMTP id f3mr8589667plf.202.1550043446195; Tue, 12 Feb 2019 23:37:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550043446; cv=none; d=google.com; s=arc-20160816; b=vkLb+xEb8D5zjBId64jMLJzmDX8NCirg8xT9f7iCRZ9MMzHsW11Ua4PJl6j4xxdUeS d9cIVIqBOz8pkoCszLQKbHU1SirP7fxqx8lcSvKO9X9T8kr2kJcBYO65ztTyGMaNN5JG Vy4MwfTyL+PDEUwqQBYdTid/mVS01rUzE48Hp+rCeIz19wjyBnrUA/8evnsdmHoW/1yL 1F9jJjEe/UkfcYmArEX8aDL0y9Cnrk7+QylcilS4noI58PlmwhJj80FODoQYimUbkaiq u3XoY/n3IT0DLGySN6LmZiMl9mcIUlogUW3ASHlemQOPnQIr1azwWWhDpB6FEWoN8RkK WFGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=Tl+ZjTV+KcU5fBDKs0m9ebGZGFjjPg77/C3uMSParLg=; b=KonEwZ0cVGXO6X9M//EhxLsSX4fdnqiT7itckUWovRzTf6OBDzmBzAbR4OjNQreWgq KYA/tD62uPwHEMS1dpx1eMg7PDBWcdwN9ooN8eWurvvYKJrCf+hxyfkewlWKnbSp0Cec tPBKiP4IZBFF/rAfdNjjPqT1K3woe14Rb5JWUZtOlAawfL+i3NeuJQQL5lP1NA7V6/T4 lQhZJ4AsGs36Z3sw+Sm327JzpLMUpgu0z7++ZPBqrYZJymzVaJtxMAlyQVTRPZkbTfR5 t+p3OI0+g5o5lAS6yXX9XcTOpYSFzWuy3rBkwRasxXRXnUx+bRWR7rPJSHJx/L67Isi6 iFHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AdEP2CMh; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c10si13778935pgq.542.2019.02.12.23.37.26; Tue, 12 Feb 2019 23:37:26 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AdEP2CMh; spf=pass (google.com: best guess record for domain of linux-spi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-spi-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732803AbfBMHhZ (ORCPT + 1 other); Wed, 13 Feb 2019 02:37:25 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:42567 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726882AbfBMHhZ (ORCPT ); Wed, 13 Feb 2019 02:37:25 -0500 Received: by mail-pl1-f193.google.com with SMTP id s1so769590plp.9 for ; Tue, 12 Feb 2019 23:37:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=Tl+ZjTV+KcU5fBDKs0m9ebGZGFjjPg77/C3uMSParLg=; b=AdEP2CMhP7BXPDbHs2hRRQpvChf0BfjKB8D8qrFMOp0JQ+AsZ3LCIiZMNLf6ntk4zG 2UoJqaj0Whc7RbxKH5qjnyh+jA8hGanetgehCBZpHQyWpYehxof/juRpE9uR4WKjqSKc VDhfSDsf1khjau98RGV/7WdLLxRgco7j6IUHt6vkY0vPeaqiErBCeHBrlyEPC8LtYgUY ycv7R7M1d0aRsmVFORh/M4Di6yY6HlZaMKEhMUrkhS2vTPFqEmk19Z0bkPPQHGpOnVK+ oxjE8HTsEwmd/boJ1Bgstio/VtD9V7BTxrim/sNL3O31WHrkMlqKf76zUCq+PFkqcA10 6TBQ== 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=Tl+ZjTV+KcU5fBDKs0m9ebGZGFjjPg77/C3uMSParLg=; b=udMdbeWAgkbekBa/x9gypnvY6rMczdXKvGRi83X0btXf7/hR65CJuSkWt116N+hcIj B/UhKC3WJcyzpnh6AJ7+2DJnhXGT+O/F5B+h/HGROgi4qgbXiSXp8eMKYSSSB+hHNGtp W8U88/rPPcB7kqlXjKoHn6shby3uOaYTkhAF37PwmIv3tgT4ywHybqjqm1Eq14H9tgKa 2e7qnV+MhKqpzHn4UoaxcqC42N/ZzduxWbene6bW1zKegKdePOqLeUfYS4rpe7aFkMud jyJ8JpyYhYqMGYay7797ZZfboDlppkJ4j/gOEAsmv/bRitkGgIvU7/EmC4FWzql9otS3 BUTA== X-Gm-Message-State: AHQUAuaFMoTtAcXyVvrZuVS3x625hRp1Zvr2ZHCWh8BetPamexqa0AiY L5SwYhAsVqesv+m6JjzTyPxfpqaPceWwpA== X-Received: by 2002:a17:902:9b90:: with SMTP id y16mr6872638plp.0.1550043444685; Tue, 12 Feb 2019 23:37:24 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id m67sm27060706pfm.73.2019.02.12.23.37.21 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 12 Feb 2019 23:37:23 -0800 (PST) From: Baolin Wang To: broonie@kernel.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: orsonzhai@gmail.com, zhang.lyra@gmail.com, lanqing.liu@unisoc.com, baolin.wang@linaro.org, linux-spi@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/3] spi: sprd: Add the SPI irq function for the SPI DMA mode Date: Wed, 13 Feb 2019 15:36:09 +0800 Message-Id: <11e55b5f9b0d83649a5b81c7e3fdb667cd3ddc5b.1550043082.git.baolin.wang@linaro.org> X-Mailer: git-send-email 1.7.9.5 Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org From: Lanqing Liu The SPI irq event will use to complete the SPI work in the SPI DMA mode, so this patch is a preparation for the following DMA mode support. Moreover the SPI interrupt can be fired when removing the SPI controller, so we should make sure the SPI controller has stopped the queue in remove function before freeing the SPI irq. Signed-off-by: Lanqing Liu Signed-off-by: Baolin Wang --- Changes from v1: - Return IRQ_NONE if detecting incorrect interrupt status. - Add spi_controller_suspend in remove function. --- drivers/spi/spi-sprd.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) -- 1.7.9.5 diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c index fa324ce..d1ddeee 100644 --- a/drivers/spi/spi-sprd.c +++ b/drivers/spi/spi-sprd.c @@ -133,6 +133,7 @@ struct sprd_spi { void __iomem *base; struct device *dev; struct clk *clk; + int irq; u32 src_clk; u32 hw_mode; u32 trans_len; @@ -141,6 +142,7 @@ struct sprd_spi { u32 hw_speed_hz; u32 len; int status; + struct completion xfer_completion; const void *tx_buf; void *rx_buf; int (*read_bufs)(struct sprd_spi *ss, u32 len); @@ -575,6 +577,48 @@ static int sprd_spi_transfer_one(struct spi_controller *sctlr, return ret; } +static irqreturn_t sprd_spi_handle_irq(int irq, void *data) +{ + struct sprd_spi *ss = (struct sprd_spi *)data; + u32 val = readl_relaxed(ss->base + SPRD_SPI_INT_MASK_STS); + + if (val & SPRD_SPI_MASK_TX_END) { + writel_relaxed(SPRD_SPI_TX_END_CLR, ss->base + SPRD_SPI_INT_CLR); + if (!(ss->trans_mode & SPRD_SPI_RX_MODE)) + complete(&ss->xfer_completion); + + return IRQ_HANDLED; + } + + if (val & SPRD_SPI_MASK_RX_END) { + writel_relaxed(SPRD_SPI_RX_END_CLR, ss->base + SPRD_SPI_INT_CLR); + complete(&ss->xfer_completion); + + return IRQ_HANDLED; + } + + return IRQ_NONE; +} + +static int sprd_spi_irq_init(struct platform_device *pdev, struct sprd_spi *ss) +{ + int ret; + + ss->irq = platform_get_irq(pdev, 0); + if (ss->irq < 0) { + dev_err(&pdev->dev, "failed to get irq resource\n"); + return ss->irq; + } + + ret = devm_request_irq(&pdev->dev, ss->irq, sprd_spi_handle_irq, + 0, pdev->name, ss); + if (ret) + dev_err(&pdev->dev, "failed to request spi irq %d, ret = %d\n", + ss->irq, ret); + + return ret; +} + static int sprd_spi_clk_init(struct platform_device *pdev, struct sprd_spi *ss) { struct clk *clk_spi, *clk_parent; @@ -635,11 +679,16 @@ static int sprd_spi_probe(struct platform_device *pdev) sctlr->max_speed_hz = min_t(u32, ss->src_clk >> 1, SPRD_SPI_MAX_SPEED_HZ); + init_completion(&ss->xfer_completion); platform_set_drvdata(pdev, sctlr); ret = sprd_spi_clk_init(pdev, ss); if (ret) goto free_controller; + ret = sprd_spi_irq_init(pdev, ss); + if (ret) + goto free_controller; + ret = clk_prepare_enable(ss->clk); if (ret) goto free_controller; @@ -690,6 +739,8 @@ static int sprd_spi_remove(struct platform_device *pdev) return ret; } + spi_controller_suspend(sctlr); + clk_disable_unprepare(ss->clk); pm_runtime_put_noidle(&pdev->dev); pm_runtime_disable(&pdev->dev);