From patchwork Sat Sep 1 16:42:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 145714 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp732410ljw; Sat, 1 Sep 2018 09:42:49 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY40yTRV1uYfZegkHTKRCXD+OKTHw4Fuj6402+w+cBxoqi2tLzQWbLdp3bwfkLJXDwD+0r8 X-Received: by 2002:a63:9f19:: with SMTP id g25-v6mr1992748pge.39.1535820169462; Sat, 01 Sep 2018 09:42:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535820169; cv=none; d=google.com; s=arc-20160816; b=H9wjn2aU3bfja5h6T7+ZVmbe+/tbX3dDuh871AoSR2kCqqqjIfk0rKPFb/+0rntMci wHSLMBUycngC1KBhASlnvA7r3B1tVoKUizzcs5aCvDrCbtx4d7Xa5emt12o8WUt9sAFm Hg464hsvFiRRvLfmO8qBzaUdcDSRanEyzbu48MYCw+dpEM2rF5w6WKZyh2/QzFyUWxb5 9Z18VceGsm+WCq+FKCQg10YQjCsW18Rznvs1xzqKv+bSJH8Sdip+WP3YVLljfNgRp3rN kR32CekyX5j1WEmN9xaNVv0yRMTyqTts7jBLBYCjqFMfl3u6QUXjBQBUGhx26bYipEK1 YOoA== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=uVMEsprQm9gudmgxiK82x9lkc/giPgwELqLOkGrioH0=; b=rNZodw6OjF3vpN/t39FN7GxNgBL0NbcQNu93sbMy8Y6jGQohMVkOO5obTZOtUugF/v E7Lb0LGECyspHa203Ns1D3/ixHqefXkQvd5TZp/z8kAv1sM0vtWGmf3P1vFNYHMYyww+ 2huRR6P4umyQdG+JgXWAPJxr0/Ozph36+WgCrtXT5+vI//eeuu/KAnvRcsy65r9zmmKX eqQ/l7gKrtAwkks0HlfStyLcA6Qh0MXYHq+LlU5lVpHjrFpSQ8fHWSQCBPe7SVF5d3Gx FkW5PI6EDTNisUGJKvtuvCCeQtvya+QnNXM2Pih+yAdUM3IgF0hckM6L12dk3yRUSvNO ZElw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vh4+W9Fh; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 z2-v6si13294358pfb.365.2018.09.01.09.42.49; Sat, 01 Sep 2018 09:42:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-serial-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=Vh4+W9Fh; spf=pass (google.com: best guess record for domain of linux-serial-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-serial-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 S1727363AbeIAUzW (ORCPT + 2 others); Sat, 1 Sep 2018 16:55:22 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:42178 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727079AbeIAUzW (ORCPT ); Sat, 1 Sep 2018 16:55:22 -0400 Received: by mail-pf1-f193.google.com with SMTP id l9-v6so6863344pff.9 for ; Sat, 01 Sep 2018 09:42:48 -0700 (PDT) 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; bh=uVMEsprQm9gudmgxiK82x9lkc/giPgwELqLOkGrioH0=; b=Vh4+W9Fh9bvn5G14X5/zRrXPS2kBhR0TBkz7MA3cMP25lLTIuU1+3/3Jvw2r1JF15P wqNFRwo/qFDXzXGB4/kY+MBSP3DcTjWCO8ARzg7id9b4nHDgltyUqeUMBQNEccS1FYls IeFAk5Zxgfnf2T0LmAv0LvzbBGHZzBV7bZf2Y= 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; bh=uVMEsprQm9gudmgxiK82x9lkc/giPgwELqLOkGrioH0=; b=UaQ/9MTEyRZZjaz6+SzEkoyt3FiexvFtxm7f0Fi9CoKejU4YZRUFDE//kBQTAmDDDl NvJQLtZa3Fg9igkfe/PqF3g/FwqgX0Fi+APTGnjyozThPtYmjEjd9QfAkFiMiA32oc64 3wF4ADZiXFp7oCAEiggnlH8MKPd5FCV2MRGtg8uxt5Eh8fu0ZiDBk57y+BQ/eXYONynI osQBg0kPu0QIOg+T4efQzPdTXCnhxjHHxQ2k1vfDNsn/XOGNhJirshMJSxZ6iWmH6NQ7 PFaF+qCM+bsAtihctvh4OFQhe47ctvEBAyRMgx3IoDohIghuAJIKpjUUNhtBbo65PvMw Cl2A== X-Gm-Message-State: APzg51Bb9aS+vsIBSeWyEMNv1UqCqBQUzcaR7TcA8zt+jFOkz1Hf3iIS 3n1YBtL6BLMTIse/qs6LvUSg X-Received: by 2002:a63:5660:: with SMTP id g32-v6mr18769691pgm.227.1535820167705; Sat, 01 Sep 2018 09:42:47 -0700 (PDT) Received: from localhost.localdomain ([2405:204:724a:4d47:6510:16:9ba1:39a3]) by smtp.gmail.com with ESMTPSA id y7-v6sm23763595pff.181.2018.09.01.09.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 09:42:47 -0700 (PDT) From: Manivannan Sadhasivam To: vkoul@kernel.org, dan.j.williams@intel.com, afaerber@suse.de, robh+dt@kernel.org, gregkh@linuxfoundation.org, jslaby@suse.com Cc: linux-serial@vger.kernel.org, dmaengine@vger.kernel.org, liuwei@actions-semi.com, 96boards@ucrobotics.com, devicetree@vger.kernel.org, daniel.thompson@linaro.org, amit.kucheria@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, hzhang@ucrobotics.com, bdong@ucrobotics.com, manivannanece23@gmail.com, thomas.liau@actions-semi.com, jeff.chen@actions-semi.com, pn@denx.de, edgar.righi@lsitec.org.br, Manivannan Sadhasivam Subject: [PATCH 1/3] arm64: dts: actions: s900: Enable Tx DMA for UART5 Date: Sat, 1 Sep 2018 22:12:13 +0530 Message-Id: <20180901164215.3683-2-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180901164215.3683-1-manivannan.sadhasivam@linaro.org> References: <20180901164215.3683-1-manivannan.sadhasivam@linaro.org> Sender: linux-serial-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-serial@vger.kernel.org Enable Tx DMA for UART5 in Actions Semi S900 SoC. Signed-off-by: Manivannan Sadhasivam --- arch/arm64/boot/dts/actions/s900.dtsi | 2 ++ 1 file changed, 2 insertions(+) -- 2.17.1 diff --git a/arch/arm64/boot/dts/actions/s900.dtsi b/arch/arm64/boot/dts/actions/s900.dtsi index eceba914762c..39af1236f611 100644 --- a/arch/arm64/boot/dts/actions/s900.dtsi +++ b/arch/arm64/boot/dts/actions/s900.dtsi @@ -156,6 +156,8 @@ compatible = "actions,s900-uart", "actions,owl-uart"; reg = <0x0 0xe012a000 0x0 0x2000>; interrupts = ; + dma-names = "tx"; + dmas = <&dma 26>; status = "disabled"; }; From patchwork Sat Sep 1 16:42:14 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manivannan Sadhasivam X-Patchwork-Id: 145715 Delivered-To: patch@linaro.org Received: by 2002:a2e:1648:0:0:0:0:0 with SMTP id 8-v6csp732586ljw; Sat, 1 Sep 2018 09:43:02 -0700 (PDT) X-Google-Smtp-Source: ANB0VdbFIdOmIdA0OknVU3k6hgl1gIu40itId5IPsz7ouYPokuBrGvG472jld8kbGSRPtV/ezxsJ X-Received: by 2002:a63:d806:: with SMTP id b6-v6mr16848501pgh.347.1535820182079; Sat, 01 Sep 2018 09:43:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535820182; cv=none; d=google.com; s=arc-20160816; b=nZ1tl51MXhMeriOdRgsa2wcqNbWPjxVaISzkfP1rOo61f1SE000Pkt0oa4OxkZsMEu ViGt3PHyLZhfAWQ9YAFOmi9kJnAitnP+TCar26vk2zVOQcQtr3GgPuOe4V2mp+IV3LL4 uxfUZw9UIDWLnp733bFndkcEFhawLKXJfiNqTo17rddQlbYCZmiqtTl33zifaSOMMJIR RUHal5Q9fsg6q1byiTBkSKXhH6gqfRfzZYxgqTyKKX6GSxXfHzbKWokYJ2r+mgkb+5oC 2j/yJUB9qUMFQn/dYAA2m4Y0eCy/E0nOafwLyfOlaBN6pBe72k7Wl2nx/+rKS8mgtndJ zETQ== 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:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=bvY3pqS4jsXLOYqngLdOBcTmjj1spRz2QJT+oPegniQ=; b=QZYC9N/+5/NK74D0cyhe88bKDp8fNK5nHtzdeVOv9mD+RCl7r6P75rprC0l8CGSiK9 kUhcXjZN0ZlhiYZ0lsdjRiOnkWbH+RvS2HEO/oKLCZkvpYxpsBJgdCMLvxpmAAqUDsJP uDAXjNppLopQ1NQAInQdm17d9PPc7PwTEXRqvHcLGmBxMlUs0+9DTkjINsQO9+gLeWJi D0zMr+UJiI51aLkaI/K9khoxf7xYtvx3QEyBrMAtGhxTT05YbflrTIbawF7ef+GY4f/c E9jYX+LugtWuAOldYi/VWD6f/vj1ArjtalNu/6jVxYystTF7S7fxrxh9aFmu6mWnKixF 1M+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Xdxj8i/m"; spf=pass (google.com: best guess record for domain of dmaengine-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=dmaengine-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 n15-v6si14153589pgc.309.2018.09.01.09.43.01; Sat, 01 Sep 2018 09:43:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dmaengine-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="Xdxj8i/m"; spf=pass (google.com: best guess record for domain of dmaengine-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=dmaengine-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 S1727415AbeIAUzf (ORCPT + 3 others); Sat, 1 Sep 2018 16:55:35 -0400 Received: from mail-pg1-f194.google.com ([209.85.215.194]:39928 "EHLO mail-pg1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727360AbeIAUzf (ORCPT ); Sat, 1 Sep 2018 16:55:35 -0400 Received: by mail-pg1-f194.google.com with SMTP id g20-v6so6789049pgv.6 for ; Sat, 01 Sep 2018 09:43:00 -0700 (PDT) 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; bh=bvY3pqS4jsXLOYqngLdOBcTmjj1spRz2QJT+oPegniQ=; b=Xdxj8i/m7l4l+ZgCRi2MXrgn6NgFARZiBB+qb/HOWGMYIgPgDDtSwc8LYhznxjh+5w x3FTsxAp0LgERnzC8Uwi/LfYYU6jPs43dBkfO/Y86ufk2qdOZZ6WqpNvtIvGFj1XN2O2 p0FWZ+wODqni/yPy2Ecp6ivFpeGJsRzzZQVdE= 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; bh=bvY3pqS4jsXLOYqngLdOBcTmjj1spRz2QJT+oPegniQ=; b=BxXFPEtI7460vdooG4/vLw3iMY2ojsIGcGmSVz+Soiw7L9cMpBqZtBSqoFjcbQ7Wyo B90pcu1cETqkNvzDHcYWwcq5DykLYuUOQidTz8pHmyjO3PcRCL70379LdpDyb++6L3A8 W7RG3vol30o83sSKgyg51qfuCcTeuF678mYUGbL/5iVhz/z/S6GIHLNO6OmaOgPtIY4G lody/VswuCYEvHCKS4wi9oroUubCvbgQOLxXEdpaLho8v0q3pnSawpM45rKKr8ywjceP UTwMJm+bUBXPcgbQjcHDBXfqgbKyJAj0x8EgMH4JSj+aXFGtVBCTlP7mbCx53y6ocMJP sNIg== X-Gm-Message-State: APzg51BpL6aqosFG3p6bupZM8gdH+5QidTqmImoyZbL2nrsMw81xj+MI Fex2fZzJM5jIJjxLklldVqb3 X-Received: by 2002:aa7:8087:: with SMTP id v7-v6mr21310252pff.38.1535820179954; Sat, 01 Sep 2018 09:42:59 -0700 (PDT) Received: from localhost.localdomain ([2405:204:724a:4d47:6510:16:9ba1:39a3]) by smtp.gmail.com with ESMTPSA id y7-v6sm23763595pff.181.2018.09.01.09.42.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 09:42:59 -0700 (PDT) From: Manivannan Sadhasivam To: vkoul@kernel.org, dan.j.williams@intel.com, afaerber@suse.de, robh+dt@kernel.org, gregkh@linuxfoundation.org, jslaby@suse.com Cc: linux-serial@vger.kernel.org, dmaengine@vger.kernel.org, liuwei@actions-semi.com, 96boards@ucrobotics.com, devicetree@vger.kernel.org, daniel.thompson@linaro.org, amit.kucheria@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, hzhang@ucrobotics.com, bdong@ucrobotics.com, manivannanece23@gmail.com, thomas.liau@actions-semi.com, jeff.chen@actions-semi.com, pn@denx.de, edgar.righi@lsitec.org.br, Manivannan Sadhasivam Subject: [PATCH 2/3] dmaengine: Add Slave and Cyclic mode support for Actions Semi Owl S900 SoC Date: Sat, 1 Sep 2018 22:12:14 +0530 Message-Id: <20180901164215.3683-3-manivannan.sadhasivam@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180901164215.3683-1-manivannan.sadhasivam@linaro.org> References: <20180901164215.3683-1-manivannan.sadhasivam@linaro.org> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Add Slave and Cyclic mode support for Actions Semi Owl S900 SoC. The slave mode supports bus width of 4 bytes common for all peripherals and 1 byte specific for UART. The cyclic mode supports only block mode transfer. Signed-off-by: Manivannan Sadhasivam --- drivers/dma/owl-dma.c | 273 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 266 insertions(+), 7 deletions(-) -- 2.17.1 diff --git a/drivers/dma/owl-dma.c b/drivers/dma/owl-dma.c index 7812a6338acd..7f7b3e76bcf7 100644 --- a/drivers/dma/owl-dma.c +++ b/drivers/dma/owl-dma.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "virt-dma.h" @@ -165,6 +166,7 @@ struct owl_dma_lli { struct owl_dma_txd { struct virt_dma_desc vd; struct list_head lli_list; + bool cyclic; }; /** @@ -191,6 +193,8 @@ struct owl_dma_vchan { struct virt_dma_chan vc; struct owl_dma_pchan *pchan; struct owl_dma_txd *txd; + struct dma_slave_config cfg; + u8 drq; }; /** @@ -336,9 +340,11 @@ static struct owl_dma_lli *owl_dma_alloc_lli(struct owl_dma *od) static struct owl_dma_lli *owl_dma_add_lli(struct owl_dma_txd *txd, struct owl_dma_lli *prev, - struct owl_dma_lli *next) + struct owl_dma_lli *next, + bool is_cyclic) { - list_add_tail(&next->node, &txd->lli_list); + if (!is_cyclic) + list_add_tail(&next->node, &txd->lli_list); if (prev) { prev->hw.next_lli = next->phys; @@ -351,7 +357,9 @@ static struct owl_dma_lli *owl_dma_add_lli(struct owl_dma_txd *txd, static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan, struct owl_dma_lli *lli, dma_addr_t src, dma_addr_t dst, - u32 len, enum dma_transfer_direction dir) + u32 len, enum dma_transfer_direction dir, + struct dma_slave_config *sconfig, + bool is_cyclic) { struct owl_dma_lli_hw *hw = &lli->hw; u32 mode; @@ -364,6 +372,26 @@ static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan, OWL_DMA_MODE_DT_DCU | OWL_DMA_MODE_SAM_INC | OWL_DMA_MODE_DAM_INC; + break; + case DMA_MEM_TO_DEV: + mode |= OWL_DMA_MODE_TS(vchan->drq) + | OWL_DMA_MODE_ST_DCU | OWL_DMA_MODE_DT_DEV + | OWL_DMA_MODE_SAM_INC | OWL_DMA_MODE_DAM_CONST; + + /* Handle bus width for UART */ + if (sconfig->dst_addr_width == DMA_SLAVE_BUSWIDTH_1_BYTE) + mode |= OWL_DMA_MODE_NDDBW_8BIT; + + break; + case DMA_DEV_TO_MEM: + mode |= OWL_DMA_MODE_TS(vchan->drq) + | OWL_DMA_MODE_ST_DEV | OWL_DMA_MODE_DT_DCU + | OWL_DMA_MODE_SAM_CONST | OWL_DMA_MODE_DAM_INC; + + /* Handle bus width for UART */ + if (sconfig->src_addr_width == DMA_SLAVE_BUSWIDTH_1_BYTE) + mode |= OWL_DMA_MODE_NDDBW_8BIT; + break; default: return -EINVAL; @@ -381,7 +409,10 @@ static inline int owl_dma_cfg_lli(struct owl_dma_vchan *vchan, OWL_DMA_LLC_SAV_LOAD_NEXT | OWL_DMA_LLC_DAV_LOAD_NEXT); - hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_SUPER_BLOCK); + if (is_cyclic) + hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_BLOCK); + else + hw->ctrlb = llc_hw_ctrlb(OWL_DMA_INTCTL_SUPER_BLOCK); return 0; } @@ -443,6 +474,16 @@ static void owl_dma_terminate_pchan(struct owl_dma *od, spin_unlock_irqrestore(&od->lock, flags); } +static void owl_dma_pause_pchan(struct owl_dma_pchan *pchan) +{ + pchan_writel(pchan, 1, OWL_DMAX_PAUSE); +} + +static void owl_dma_resume_pchan(struct owl_dma_pchan *pchan) +{ + pchan_writel(pchan, 0, OWL_DMAX_PAUSE); +} + static int owl_dma_start_next_txd(struct owl_dma_vchan *vchan) { struct owl_dma *od = to_owl_dma(vchan->vc.chan.device); @@ -464,7 +505,10 @@ static int owl_dma_start_next_txd(struct owl_dma_vchan *vchan) lli = list_first_entry(&txd->lli_list, struct owl_dma_lli, node); - int_ctl = OWL_DMA_INTCTL_SUPER_BLOCK; + if (txd->cyclic) + int_ctl = OWL_DMA_INTCTL_BLOCK; + else + int_ctl = OWL_DMA_INTCTL_SUPER_BLOCK; pchan_writel(pchan, OWL_DMAX_MODE, OWL_DMA_MODE_LME); pchan_writel(pchan, OWL_DMAX_LINKLIST_CTL, @@ -627,6 +671,54 @@ static int owl_dma_terminate_all(struct dma_chan *chan) return 0; } +static int owl_dma_config(struct dma_chan *chan, + struct dma_slave_config *config) +{ + struct owl_dma_vchan *vchan = to_owl_vchan(chan); + + /* Reject definitely invalid configurations */ + if (config->src_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES || + config->dst_addr_width == DMA_SLAVE_BUSWIDTH_8_BYTES) + return -EINVAL; + + memcpy(&vchan->cfg, config, sizeof(struct dma_slave_config)); + + return 0; +} + +static int owl_dma_pause(struct dma_chan *chan) +{ + struct owl_dma_vchan *vchan = to_owl_vchan(chan); + unsigned long flags; + + spin_lock_irqsave(&vchan->vc.lock, flags); + + owl_dma_pause_pchan(vchan->pchan); + + spin_unlock_irqrestore(&vchan->vc.lock, flags); + + return 0; +} + +static int owl_dma_resume(struct dma_chan *chan) +{ + struct owl_dma_vchan *vchan = to_owl_vchan(chan); + unsigned long flags; + + if (!vchan->pchan && !vchan->txd) + return 0; + + dev_dbg(chan2dev(chan), "vchan %p: resume\n", &vchan->vc); + + spin_lock_irqsave(&vchan->vc.lock, flags); + + owl_dma_resume_pchan(vchan->pchan); + + spin_unlock_irqrestore(&vchan->vc.lock, flags); + + return 0; +} + static u32 owl_dma_getbytes_chan(struct owl_dma_vchan *vchan) { struct owl_dma_pchan *pchan; @@ -754,13 +846,14 @@ static struct dma_async_tx_descriptor bytes = min_t(size_t, (len - offset), OWL_DMA_FRAME_MAX_LENGTH); ret = owl_dma_cfg_lli(vchan, lli, src + offset, dst + offset, - bytes, DMA_MEM_TO_MEM); + bytes, DMA_MEM_TO_MEM, + &vchan->cfg, txd->cyclic); if (ret) { dev_warn(chan2dev(chan), "failed to config lli\n"); goto err_txd_free; } - prev = owl_dma_add_lli(txd, prev, lli); + prev = owl_dma_add_lli(txd, prev, lli, false); } return vchan_tx_prep(&vchan->vc, &txd->vd, flags); @@ -770,6 +863,133 @@ static struct dma_async_tx_descriptor return NULL; } +static struct dma_async_tx_descriptor + *owl_dma_prep_slave_sg(struct dma_chan *chan, + struct scatterlist *sgl, + unsigned int sg_len, + enum dma_transfer_direction dir, + unsigned long flags, void *context) +{ + struct owl_dma *od = to_owl_dma(chan->device); + struct owl_dma_vchan *vchan = to_owl_vchan(chan); + struct dma_slave_config *sconfig = &vchan->cfg; + struct owl_dma_txd *txd; + struct owl_dma_lli *lli, *prev = NULL; + struct scatterlist *sg; + dma_addr_t addr, src = 0, dst = 0; + size_t len; + int ret, i; + + txd = kzalloc(sizeof(*txd), GFP_NOWAIT); + if (!txd) + return NULL; + + INIT_LIST_HEAD(&txd->lli_list); + + for_each_sg(sgl, sg, sg_len, i) { + addr = sg_dma_address(sg); + len = sg_dma_len(sg); + + if (len > OWL_DMA_FRAME_MAX_LENGTH) { + dev_err(od->dma.dev, + "frame length exceeds max supported length"); + goto err_txd_free; + } + + lli = owl_dma_alloc_lli(od); + if (!lli) { + dev_err(chan2dev(chan), "failed to allocate lli"); + goto err_txd_free; + } + + if (dir == DMA_MEM_TO_DEV) { + src = addr; + dst = sconfig->dst_addr; + } else { + src = sconfig->src_addr; + dst = addr; + } + + ret = owl_dma_cfg_lli(vchan, lli, src, dst, len, dir, sconfig, + txd->cyclic); + if (ret) { + dev_warn(chan2dev(chan), "failed to config lli"); + goto err_txd_free; + } + + prev = owl_dma_add_lli(txd, prev, lli, false); + } + + return vchan_tx_prep(&vchan->vc, &txd->vd, flags); + +err_txd_free: + owl_dma_free_txd(od, txd); + + return NULL; +} + +static struct dma_async_tx_descriptor + *owl_prep_dma_cyclic(struct dma_chan *chan, + dma_addr_t buf_addr, size_t buf_len, + size_t period_len, + enum dma_transfer_direction dir, + unsigned long flags) +{ + struct owl_dma *od = to_owl_dma(chan->device); + struct owl_dma_vchan *vchan = to_owl_vchan(chan); + struct dma_slave_config *sconfig = &vchan->cfg; + struct owl_dma_txd *txd; + struct owl_dma_lli *lli, *prev = NULL, *first = NULL; + dma_addr_t src = 0, dst = 0; + unsigned int periods = buf_len / period_len; + int ret, i; + + txd = kzalloc(sizeof(*txd), GFP_NOWAIT); + if (!txd) + return NULL; + + INIT_LIST_HEAD(&txd->lli_list); + txd->cyclic = true; + + for (i = 0; i < periods; i++) { + lli = owl_dma_alloc_lli(od); + if (!lli) { + dev_warn(chan2dev(chan), "failed to allocate lli"); + goto err_txd_free; + } + + if (dir == DMA_MEM_TO_DEV) { + src = buf_addr + (period_len * i); + dst = sconfig->dst_addr; + } else if (dir == DMA_DEV_TO_MEM) { + src = sconfig->src_addr; + dst = buf_addr + (period_len * i); + } + + ret = owl_dma_cfg_lli(vchan, lli, src, dst, period_len, + dir, sconfig, txd->cyclic); + if (ret) { + dev_warn(chan2dev(chan), "failed to config lli"); + goto err_txd_free; + } + + if (!first) + first = lli; + + prev = owl_dma_add_lli(txd, prev, lli, false); + } + + /* close the cyclic list */ + owl_dma_add_lli(txd, prev, first, true); + + return vchan_tx_prep(&vchan->vc, &txd->vd, flags); + +err_txd_free: + owl_dma_free_txd(od, txd); + + return NULL; +} + static void owl_dma_free_chan_resources(struct dma_chan *chan) { struct owl_dma_vchan *vchan = to_owl_vchan(chan); @@ -790,6 +1010,27 @@ static inline void owl_dma_free(struct owl_dma *od) } } +static struct dma_chan *owl_dma_of_xlate(struct of_phandle_args *dma_spec, + struct of_dma *ofdma) +{ + struct owl_dma *od = ofdma->of_dma_data; + struct owl_dma_vchan *vchan; + struct dma_chan *chan; + u8 drq = dma_spec->args[0]; + + if (drq > od->nr_vchans) + return NULL; + + chan = dma_get_any_slave_channel(&od->dma); + if (!chan) + return NULL; + + vchan = to_owl_vchan(chan); + vchan->drq = drq; + + return chan; +} + static int owl_dma_probe(struct platform_device *pdev) { struct device_node *np = pdev->dev.of_node; @@ -833,12 +1074,19 @@ static int owl_dma_probe(struct platform_device *pdev) spin_lock_init(&od->lock); dma_cap_set(DMA_MEMCPY, od->dma.cap_mask); + dma_cap_set(DMA_SLAVE, od->dma.cap_mask); + dma_cap_set(DMA_CYCLIC, od->dma.cap_mask); od->dma.dev = &pdev->dev; od->dma.device_free_chan_resources = owl_dma_free_chan_resources; od->dma.device_tx_status = owl_dma_tx_status; od->dma.device_issue_pending = owl_dma_issue_pending; od->dma.device_prep_dma_memcpy = owl_dma_prep_memcpy; + od->dma.device_prep_slave_sg = owl_dma_prep_slave_sg; + od->dma.device_prep_dma_cyclic = owl_prep_dma_cyclic; + od->dma.device_config = owl_dma_config; + od->dma.device_pause = owl_dma_pause; + od->dma.device_resume = owl_dma_resume; od->dma.device_terminate_all = owl_dma_terminate_all; od->dma.src_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); od->dma.dst_addr_widths = BIT(DMA_SLAVE_BUSWIDTH_4_BYTES); @@ -910,8 +1158,18 @@ static int owl_dma_probe(struct platform_device *pdev) goto err_pool_free; } + /* Device-tree DMA controller registration */ + ret = of_dma_controller_register(pdev->dev.of_node, + owl_dma_of_xlate, od); + if (ret) { + dev_err(&pdev->dev, "of_dma_controller_register failed\n"); + goto err_dma_unregister; + } + return 0; +err_dma_unregister: + dma_async_device_unregister(&od->dma); err_pool_free: clk_disable_unprepare(od->clk); dma_pool_destroy(od->lli_pool); @@ -923,6 +1181,7 @@ static int owl_dma_remove(struct platform_device *pdev) { struct owl_dma *od = platform_get_drvdata(pdev); + of_dma_controller_free(pdev->dev.of_node); dma_async_device_unregister(&od->dma); /* Mask all interrupts for this execution environment */