From patchwork Sun Sep 17 03:19:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Br=C3=BCns?= X-Patchwork-Id: 9954559 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 13DF460352 for ; Sun, 17 Sep 2017 03:22:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0385728403 for ; Sun, 17 Sep 2017 03:22:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC2522857E; Sun, 17 Sep 2017 03:22:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D65B0285D1 for ; Sun, 17 Sep 2017 03:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; 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=zMcVMVPEKcg9MkH54UGOckribc4XlNMrEDm6nPRK3EE=; b=RWQOQCezBytyQj q4TkWrCPm6c73M0N6VlmcfUQbkTwgjKgQFGvIWj6kWmlRzISQwP+A7PESiLBVK9+WucQjrDdSAWzm 7ZlYjjvyp2TqHDnN3Kz9fxYZb5/sGmnxCTlreUj0Q/d66e19hFfmeTuruwyfN5JTU50wr3v+tIhjw 1r7GeiEQWdbAkDFBjZgA/jSCSaal3NhKE8EH8lGAs8wYR8lgDaBfvnr7HvS7h43OK+Zw5JHYO0Htr LXdmF1gHk2e1dse2Dzraw4BjQ8XKtP3pfZ9eUXezoJ77NlL9y29Q9+DwjqON08fdAVKrB1ZA3/KFj hIwhDls9Jl8lPzkqypNQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dtQ9U-0002y5-Gv; Sun, 17 Sep 2017 03:21:48 +0000 Received: from mail-out-1.itc.rwth-aachen.de ([134.130.5.46]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dtQ8G-0000zq-9S for linux-arm-kernel@lists.infradead.org; Sun, 17 Sep 2017 03:20:45 +0000 X-IronPort-AV: E=Sophos;i="5.42,405,1500933600"; d="scan'208";a="13708886" Received: from rwthex-w1-a.rwth-ad.de ([134.130.26.156]) by mail-in-1.itc.rwth-aachen.de with ESMTP; 17 Sep 2017 05:20:07 +0200 Received: from pebbles.fritz.box (85.183.223.53) by rwthex-w1-a.rwth-ad.de (2002:8682:1a9c::8682:1a9c) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1034.26; Sun, 17 Sep 2017 05:20:05 +0200 From: =?UTF-8?q?Stefan=20Br=C3=BCns?= To: Subject: [PATCH v2 03/10] dmaengine: sun6i: Restructure code to allow extension for new SoCs Date: Sun, 17 Sep 2017 05:19:49 +0200 Message-ID: <20170917031956.28010-4-stefan.bruens@rwth-aachen.de> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20170917031956.28010-1-stefan.bruens@rwth-aachen.de> References: <20170917031956.28010-1-stefan.bruens@rwth-aachen.de> MIME-Version: 1.0 X-Originating-IP: [85.183.223.53] X-ClientProxiedBy: rwthex-w1-b.rwth-ad.de (2002:8682:1a9d::8682:1a9d) To rwthex-w1-a.rwth-ad.de (2002:8682:1a9c::8682:1a9c) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170916_202033_029683_77D8EEF5 X-CRM114-Status: GOOD ( 10.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Vinod Koul , Andre Przywara , linux-kernel@vger.kernel.org, Code Kipper , Chen-Yu Tsai , Rob Herring , dmaengine@vger.kernel.org, Maxime Ripard , linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The current code mixes three distinct operations when transforming the slave config to register settings: 1. special handling of DMA_SLAVE_BUSWIDTH_UNDEFINED, maxburst == 0 2. range checking 3. conversion of raw to register values As the range checks depend on the specific SoC, move these out of the conversion to distinct operations. Signed-off-by: Stefan BrĂ¼ns Acked-by: Maxime Ripard --- drivers/dma/sun6i-dma.c | 66 ++++++++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/drivers/dma/sun6i-dma.c b/drivers/dma/sun6i-dma.c index a6fc066a0ac6..663f4b0b450e 100644 --- a/drivers/dma/sun6i-dma.c +++ b/drivers/dma/sun6i-dma.c @@ -118,6 +118,8 @@ struct sun6i_dma_config { */ void (*clock_autogate_enable)(); void (*set_burst_length)(u32 *p_cfg, s8 src_burst, s8 dst_burst); + u32 src_burst_lengths; + u32 dst_burst_lengths; }; /* @@ -266,10 +268,6 @@ static inline s8 convert_burst(u32 maxburst) static inline s8 convert_buswidth(enum dma_slave_buswidth addr_width) { - if ((addr_width < DMA_SLAVE_BUSWIDTH_1_BYTE) || - (addr_width > DMA_SLAVE_BUSWIDTH_4_BYTES)) - return -EINVAL; - return addr_width >> 1; } @@ -542,41 +540,43 @@ static int set_config(struct sun6i_dma_dev *sdev, enum dma_transfer_direction direction, u32 *p_cfg) { + enum dma_slave_buswidth src_addr_width, dst_addr_width; + u32 src_maxburst, dst_maxburst; s8 src_width, dst_width, src_burst, dst_burst; + src_addr_width = sconfig->src_addr_width; + dst_addr_width = sconfig->dst_addr_width; + src_maxburst = sconfig->src_maxburst; + dst_maxburst = sconfig->dst_maxburst; + switch (direction) { case DMA_MEM_TO_DEV: - src_burst = convert_burst(sconfig->src_maxburst ? - sconfig->src_maxburst : 8); - src_width = convert_buswidth(sconfig->src_addr_width != - DMA_SLAVE_BUSWIDTH_UNDEFINED ? - sconfig->src_addr_width : - DMA_SLAVE_BUSWIDTH_4_BYTES); - dst_burst = convert_burst(sconfig->dst_maxburst); - dst_width = convert_buswidth(sconfig->dst_addr_width); + if (src_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) + src_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + src_maxburst = src_maxburst ? src_maxburst : 8; break; case DMA_DEV_TO_MEM: - src_burst = convert_burst(sconfig->src_maxburst); - src_width = convert_buswidth(sconfig->src_addr_width); - dst_burst = convert_burst(sconfig->dst_maxburst ? - sconfig->dst_maxburst : 8); - dst_width = convert_buswidth(sconfig->dst_addr_width != - DMA_SLAVE_BUSWIDTH_UNDEFINED ? - sconfig->dst_addr_width : - DMA_SLAVE_BUSWIDTH_4_BYTES); + if (dst_addr_width == DMA_SLAVE_BUSWIDTH_UNDEFINED) + dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES; + dst_maxburst = dst_maxburst ? dst_maxburst : 8; break; default: return -EINVAL; } - if (src_burst < 0) - return src_burst; - if (src_width < 0) - return src_width; - if (dst_burst < 0) - return dst_burst; - if (dst_width < 0) - return dst_width; + if (!(BIT(src_addr_width) & sdev->slave.src_addr_widths)) + return -EINVAL; + if (!(BIT(dst_addr_width) & sdev->slave.dst_addr_widths)) + return -EINVAL; + if (!(BIT(src_maxburst) & sdev->cfg->src_burst_lengths)) + return -EINVAL; + if (!(BIT(dst_maxburst) & sdev->cfg->dst_burst_lengths)) + return -EINVAL; + + src_width = convert_buswidth(src_addr_width); + dst_width = convert_buswidth(dst_addr_width); + dst_burst = convert_burst(dst_maxburst); + src_burst = convert_burst(src_maxburst); *p_cfg = DMA_CHAN_CFG_SRC_WIDTH(src_width) | DMA_CHAN_CFG_DST_WIDTH(dst_width); @@ -1043,6 +1043,8 @@ static struct sun6i_dma_config sun6i_a31_dma_cfg = { .nr_max_vchans = 53, .clock_autogate_enable = sun6i_enable_clock_autogate_noop; .set_burst_length = sun6i_set_burst_length_a31; + .src_burst_lengths = BIT(1) | BIT(8); + .dst_burst_lengths = BIT(1) | BIT(8); }; /* @@ -1056,6 +1058,8 @@ static struct sun6i_dma_config sun8i_a23_dma_cfg = { .nr_max_vchans = 37, .clock_autogate_enable = sun6i_enable_clock_autogate_a23; .set_burst_length = sun6i_set_burst_length_a31; + .src_burst_lengths = BIT(1) | BIT(8); + .dst_burst_lengths = BIT(1) | BIT(8); }; static struct sun6i_dma_config sun8i_a83t_dma_cfg = { @@ -1064,6 +1068,8 @@ static struct sun6i_dma_config sun8i_a83t_dma_cfg = { .nr_max_vchans = 39, .clock_autogate_enable = sun6i_enable_clock_autogate_a23; .set_burst_length = sun6i_set_burst_length_a31; + .src_burst_lengths = BIT(1) | BIT(8); + .dst_burst_lengths = BIT(1) | BIT(8); }; /* @@ -1077,6 +1083,8 @@ static struct sun6i_dma_config sun8i_h3_dma_cfg = { .nr_max_vchans = 34, .clock_autogate_enable = sun6i_enable_clock_autogate_h3; .set_burst_length = sun6i_set_burst_length_h3; + .src_burst_lengths = BIT(1) | BIT(8); + .dst_burst_lengths = BIT(1) | BIT(8); }; /* @@ -1090,6 +1098,8 @@ static struct sun6i_dma_config sun8i_v3s_dma_cfg = { .nr_max_vchans = 24, .clock_autogate_enable = sun6i_enable_clock_autogate_a23; .set_burst_length = sun6i_set_burst_length_a31; + .src_burst_lengths = BIT(1) | BIT(8); + .dst_burst_lengths = BIT(1) | BIT(8); }; static const struct of_device_id sun6i_dma_match[] = {