From patchwork Tue Jan 15 13:46:51 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: 155670 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp4910644jaa; Tue, 15 Jan 2019 05:47:39 -0800 (PST) X-Google-Smtp-Source: ALg8bN6neBY2EASr+aRAPITMfmrIqQb308TuUKcEzie3916zg/vmbdm4LnM91XIPeDaCHIjMKSji X-Received: by 2002:a62:62c5:: with SMTP id w188mr4169045pfb.160.1547560059195; Tue, 15 Jan 2019 05:47:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547560059; cv=none; d=google.com; s=arc-20160816; b=hIVFMqUBQ7YFWG6q0IOJKVG0dt37cNM3Zo/uz2GcztzaaCUuPFi+KOPo5kAm83W9WB wpFcMTZoxzoakU9k4lHx6O6+PnVDfichHxTxj1E5ZIa+6ewQS3hdQlrrRIAu3LxoXolZ taiHfmM5iE9pQ78WxEWIo5CNkFg7XYsgCAKe5zaXA2vxHSCLlLVPJl+rGVOsyLdCCqbp VXrstp4s2SBQI+ohCf4zork4xu3oQXPqsuX6wW3TKaPRoU/pnHIcK8AB/WnukLhb5Vqv h8o8bUXN+Mq1pEs38FlnyTkE9yfeCRr0uoGdGIv5SY4IYTEQQdp9LdXEXTcR85NziacB clNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=GIat+m7TznQx8UqrqhXybGFDW6VxagwmUZvqdNg8Le4=; b=KYnIqVY1O03U6TSrxtfnwrVINBFUFSycX0qHNKCvbItdiVOji36ITvvot7wdyAORaK riUDTPduuJlrCUc0Mq2Al1mJFlVqzIHfN7Jw6E+xQBeO9bBu3Z+oeZ/nv5D81/wo4cAa yx1Zdv1MS7QbgLqfSbubPOFD0Jibm8/adCPTz0UtyIauSJF70Y9AeHNKWn4dJfab621Y k9fKNk7/ZjpJjNnneVxNx7VzyMdPFzJWZRStlpaR/LfIkt0c89Z4rKgWH5TkgTQCoWdl N/6yfr6+ZrHq6/2F2ySWCbVYtzuLx1KoMaSkALDIUZBQqI0vZ3pQTpMxvp1DG+YtVIGJ n5eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QbwL7OIu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 g83si3455036pfb.278.2019.01.15.05.47.38; Tue, 15 Jan 2019 05:47:39 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=QbwL7OIu; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-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 S1729593AbfAONri (ORCPT + 31 others); Tue, 15 Jan 2019 08:47:38 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:44207 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727931AbfAONrh (ORCPT ); Tue, 15 Jan 2019 08:47:37 -0500 Received: by mail-pl1-f193.google.com with SMTP id e11so1309755plt.11 for ; Tue, 15 Jan 2019 05:47:36 -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:in-reply-to:references :in-reply-to:references; bh=GIat+m7TznQx8UqrqhXybGFDW6VxagwmUZvqdNg8Le4=; b=QbwL7OIuq4ceJmrG67XvLj+83iRkmvqiwrpIqGlTOJMgyzpbVQ0RIfI5ClhQBjFYy4 mxXhT8GypbIpFBQnojSCxf+HgWsTnyvcFMBKGgM0cIrhVNH6rYmtZygDSL/QWGQDFW4v ndaScbK8r3kkDsYP6QOmcYlYpB6lIfgU2R4F4= 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:in-reply-to :references:in-reply-to:references; bh=GIat+m7TznQx8UqrqhXybGFDW6VxagwmUZvqdNg8Le4=; b=EMKRrjIrp/TFZ8/34YdhJPS3ZKG/RT903b4eUIAATtGKMAcszkThZ4gE1GreNmYime Q37w6p9uoxoTZWgFqmmu0Bb02tAqhMDolDhW3rRQNF12esRECVrC+0L+v7j3A7uXyb68 PsVv0+j2vFtaBybF6rK8lz7ILuJUkK9H5lr5o0sPgGdGXUAfcvSMBmK4p/WxvrjCOCiu uOpOlMZR0g4RLtgpSD6l94e5WQhWBQ8U8eY9x9u8td8Q0qgQtxh+CHitYMnVgqmHWeh4 9cjdrIk/JVaDJ7SknTCChfNbB3FS9hDnqvV+Vri7RKzIpkafcHrFmU7F40ozCu6uZ+KQ b7VA== X-Gm-Message-State: AJcUukc1+LOxSzN/8YHpppDvf+7I81sCpFOj8b9giQMQZf0NHIG4DDaw cntTQpdBvqmnoUCJfPZtc8aq/w== X-Received: by 2002:a17:902:2a89:: with SMTP id j9mr4261570plb.296.1547560056264; Tue, 15 Jan 2019 05:47:36 -0800 (PST) Received: from baolinwangubtpc.spreadtrum.com ([117.18.48.102]) by smtp.gmail.com with ESMTPSA id y71sm5979422pfi.123.2019.01.15.05.47.32 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 15 Jan 2019 05:47:35 -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 2/4] spi: sprd: Add the SPI irq function for the SPI DMA mode Date: Tue, 15 Jan 2019 21:46:51 +0800 Message-Id: X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Signed-off-by: Lanqing Liu Signed-off-by: Baolin Wang --- drivers/spi/spi-sprd.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) -- 1.7.9.5 diff --git a/drivers/spi/spi-sprd.c b/drivers/spi/spi-sprd.c index fa324ce..bfba30b 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,45 @@ 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; +} + +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 +676,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;