Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp674149imm; Fri, 11 May 2018 04:45:08 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrvlwob48zW+Pkb/oj4vihDVyG7xtOHm8iR0PmkyXFs9sMfk3HoOd+3F/CpWGZ5uB+/MAjd X-Received: by 2002:a63:6d8f:: with SMTP id i137-v6mr4222744pgc.268.1526039108332; Fri, 11 May 2018 04:45:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526039108; cv=none; d=google.com; s=arc-20160816; b=EN/UbAhBTEq2NuNgq6KcnyFTDn0DXlPqYXDdTUbFQ7NMqRaCSuqvQ/ui+/FRUSx2wl yUdt9oddcRwW/0XK+Is6sIpnnP6cW1QEHlJuveDKQTO7zJmq6VgVDV8SR/PPUFjLQIjd ZfkJyluDVM4qLX5QzGsxnjhJHswJvqZosDbpngstOQeRW7Nm4GAFJqq5gvGfFtXakPo3 /G6G+6SjndpNBoVWrn6gzotSRoY1UTqisM1VRKSr6x9iNxUo2qgayDL54VJuC5iVpD3g bRITIFrlOU6Bwr+93xtfVrs6zvoAKlw8jiVOlueFCN40+CjNm4tZDgZdEqChrTdZi1AY tviQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=rFT6hADYpagciwB1eLjWoZbHp0Q05lwPVKlsMiH/esk=; b=GQ7w77X32afgyVKvPSW8m6t09IY00EyM0z83K2L1avB6lAYoDwf2mMpcMULYCdUDA0 eB6jKPRBnADUXx5cd9k19HR3WDG+UDGS3C/EUY7eBqmHp3BGeZvyZzkDzFIwfxZv/jKm NII1PMwqpFGXXIp7y/QX7LvZ/pVWSfhLF374QZ71RtOzxz0sOg72/Vz0E475mppoHYWm eC1BdBb5orxTcA23yXkZmkTm32GnZQ4nrqPK6fIOjAV1jKocQ+JyrqwVg5VfSrxtoaQM VK8eTXkVgS/OkvXRx7N/5HgJ1yznawjkZTaHfZhMcvPlNQW7uM5JPjEI0KEr/3zacF2n iCKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZLzE8plj; 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 t16-v6si3025082pfe.225.2018.05.11.04.44.53; Fri, 11 May 2018 04:45:08 -0700 (PDT) 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=ZLzE8plj; 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 S1752988AbeEKLoZ (ORCPT + 99 others); Fri, 11 May 2018 07:44:25 -0400 Received: from mail-oi0-f65.google.com ([209.85.218.65]:45977 "EHLO mail-oi0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752617AbeEKLoX (ORCPT ); Fri, 11 May 2018 07:44:23 -0400 Received: by mail-oi0-f65.google.com with SMTP id b130-v6so4433894oif.12 for ; Fri, 11 May 2018 04:44:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=rFT6hADYpagciwB1eLjWoZbHp0Q05lwPVKlsMiH/esk=; b=ZLzE8pljTIifSQIu1WdigGxHvLZPE3QssZYWWvB69rfIHAXm0ThaQcv8IP0Agk9YBN kQBA8H50D2qSblJlVbsv+jUcB5ENgnY/23yx+g6/yr6J1h0Z5++cFgaSrqwcWimQWeiR SVWpqqald8HG8gPEWytW/VhWbAxdVglhsEGZk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=rFT6hADYpagciwB1eLjWoZbHp0Q05lwPVKlsMiH/esk=; b=NOa7OsVKzftM93mEkGciG8R5AwQCm69rekIcvC7XkluLfP/L1sguzzwPcfHnx8xIWc g9r+m1rVfSgw+mjF8KS51rBWHuphYm99Bt++x3cHK2+czXfrWoBLWyMDqBfV/2P4tmIF u9jVbpKfRd7JyIqdetVi/imzfj3Jsn1rt285h6aaIwYNfSJZjn1reoVbmIMx8KgpxV2/ ePFRGNN00NKFBi9ZgDa1t8rcpldu9hqND2A3VqOn/6OPAP2AHquVNFdRUlPj574oXEKS RbP3XJwnAoRhIVMqciPGXVeIdvlyjiixqQ8/pWmtJytzgkvHPzZ2jRnIGJIqzylIrWQ5 2H0A== X-Gm-Message-State: ALKqPwfRDUCZeniPMgi1qJQwvUWxAJjJUlua+EUZhiK0xi8ayITXGmL5 +PrEBRdvNzbm8LvgfvCzbHsVd4PUGF6p20Iw+Y3Z3w== X-Received: by 2002:aca:c108:: with SMTP id r8-v6mr2862519oif.68.1526039062513; Fri, 11 May 2018 04:44:22 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a9d:2d77:0:0:0:0:0 with HTTP; Fri, 11 May 2018 04:44:22 -0700 (PDT) In-Reply-To: <20180511112225.GA30118@vkoul-mobl> References: <67447aabb8e4e051ff39b814a0e169e6a91bb66e.1525863923.git.baolin.wang@linaro.org> <20180511112225.GA30118@vkoul-mobl> From: Baolin Wang Date: Fri, 11 May 2018 19:44:22 +0800 Message-ID: Subject: Re: [PATCH v2 2/2] dmaengine: sprd: Add Spreadtrum DMA configuration To: Vinod Koul Cc: Dan Williams , Vinod Koul , Eric Long , Mark Brown , Lars-Peter Clausen , dmaengine@vger.kernel.org, LKML Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Vinod, On 11 May 2018 at 19:22, Vinod Koul wrote: > On 09-05-18, 19:12, Baolin Wang wrote: > >> +/* >> + * struct sprd_dma_config - DMA configuration structure >> + * @cfg: dma slave channel runtime config >> + * @src_addr: the source physical address >> + * @dst_addr: the destination physical address >> + * @block_len: specify one block transfer length >> + * @transcation_len: specify one transcation transfer length >> + * @src_step: source transfer step >> + * @dst_step: destination transfer step >> + * @wrap_ptr: wrap pointer address, once the transfer address reaches the >> + * 'wrap_ptr', the next transfer address will jump to the 'wrap_to' address. >> + * @wrap_to: wrap jump to address >> + * @req_mode: specify the DMA request mode >> + * @int_mode: specify the DMA interrupt type >> + */ >> +struct sprd_dma_config { >> + struct dma_slave_config cfg; >> + phys_addr_t src_addr; >> + phys_addr_t dst_addr; > > these are already in cfg so why duplicate, same for few more here. We save them in 'struct sprd_dma_config' as one parameter for sprd_dma_config(), otherwise we need add 2 more parameters (src and dst) for sprd_dma_config(). > >> +static enum sprd_dma_datawidth >> +sprd_dma_get_datawidth(enum dma_slave_buswidth buswidth) >> +{ >> + switch (buswidth) { >> + case DMA_SLAVE_BUSWIDTH_1_BYTE: >> + return SPRD_DMA_DATAWIDTH_1_BYTE; >> + >> + case DMA_SLAVE_BUSWIDTH_2_BYTES: >> + return SPRD_DMA_DATAWIDTH_2_BYTES; >> + >> + case DMA_SLAVE_BUSWIDTH_4_BYTES: >> + return SPRD_DMA_DATAWIDTH_4_BYTES; >> + >> + case DMA_SLAVE_BUSWIDTH_8_BYTES: >> + return SPRD_DMA_DATAWIDTH_8_BYTES; >> + >> + default: >> + return SPRD_DMA_DATAWIDTH_4_BYTES; > > what is the logic of translation here, sometime you might be able to do that > with logical operators, see other drivers.. OK. I will change to logical operators. > >> + } >> +} >> + >> +static u32 sprd_dma_get_step(enum dma_slave_buswidth buswidth) >> +{ >> + switch (buswidth) { >> + case DMA_SLAVE_BUSWIDTH_1_BYTE: >> + return SPRD_DMA_BYTE_STEP; >> + >> + case DMA_SLAVE_BUSWIDTH_2_BYTES: >> + return SPRD_DMA_SHORT_STEP; >> + >> + case DMA_SLAVE_BUSWIDTH_4_BYTES: >> + return SPRD_DMA_WORD_STEP; >> + >> + case DMA_SLAVE_BUSWIDTH_8_BYTES: >> + return SPRD_DMA_DWORD_STEP; >> + >> + default: >> + return SPRD_DMA_DWORD_STEP; >> + } > > here as well Will do. > >> +} >> + >> +static int sprd_dma_config(struct dma_chan *chan, struct sprd_dma_desc *sdesc, >> + struct sprd_dma_config *slave_cfg) >> +{ >> + struct sprd_dma_dev *sdev = to_sprd_dma_dev(chan); >> + struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); >> + struct sprd_dma_chn_hw *hw = &sdesc->chn_hw; >> + u32 fix_mode = 0, fix_en = 0, wrap_en = 0, wrap_mode = 0; >> + u32 src_datawidth, dst_datawidth; >> + >> + if (slave_cfg->cfg.slave_id) >> + schan->dev_id = slave_cfg->cfg.slave_id; >> + >> + hw->cfg = SPRD_DMA_DONOT_WAIT_BDONE << SPRD_DMA_WAIT_BDONE_OFFSET; >> + hw->wrap_ptr = (u32)((slave_cfg->wrap_ptr & SPRD_DMA_LOW_ADDR_MASK) | > > why cast? Since the wrap_ptr register is always 32bit. > >> + ((slave_cfg->src_addr >> SPRD_DMA_HIGH_ADDR_OFFSET) & >> + SPRD_DMA_HIGH_ADDR_MASK)); > > more readable would be: > > temp = slave_cfg->wrap_ptr & SPRD_DMA_LOW_ADDR_MASK; > temp |= slave_cfg->src_addr >> SPRD_DMA_HIGH_ADDR_OFFSET; > temp &= SPRD_DMA_HIGH_ADDR_MASK; > > and then assign... could help readability in few places... OK. > >> + hw->wrap_to = (u32)((slave_cfg->wrap_to & SPRD_DMA_LOW_ADDR_MASK) | >> + ((slave_cfg->dst_addr >> SPRD_DMA_HIGH_ADDR_OFFSET) & >> + SPRD_DMA_HIGH_ADDR_MASK)); >> + >> + hw->src_addr = (u32)(slave_cfg->src_addr & SPRD_DMA_LOW_ADDR_MASK); >> + hw->des_addr = (u32)(slave_cfg->dst_addr & SPRD_DMA_LOW_ADDR_MASK); >> + >> + if ((slave_cfg->src_step != 0 && slave_cfg->dst_step != 0) >> + || (slave_cfg->src_step | slave_cfg->dst_step) == 0) { >> + fix_en = 0; >> + } else { >> + fix_en = 1; >> + if (slave_cfg->src_step) >> + fix_mode = 1; >> + else >> + fix_mode = 0; >> + } >> + >> + if (slave_cfg->wrap_ptr && slave_cfg->wrap_to) { >> + wrap_en = 1; >> + if (slave_cfg->wrap_to == slave_cfg->src_addr) { >> + wrap_mode = 0; >> + } else if (slave_cfg->wrap_to == slave_cfg->dst_addr) { >> + wrap_mode = 1; >> + } else { >> + dev_err(sdev->dma_dev.dev, "invalid wrap mode\n"); >> + return -EINVAL; >> + } >> + } >> + >> + hw->intc = slave_cfg->int_mode | SPRD_DMA_CFG_ERR_INT_EN; >> + >> + src_datawidth = sprd_dma_get_datawidth(slave_cfg->cfg.src_addr_width); >> + dst_datawidth = sprd_dma_get_datawidth(slave_cfg->cfg.dst_addr_width); >> + hw->frg_len = src_datawidth << SPRD_DMA_SRC_DATAWIDTH_OFFSET | >> + dst_datawidth << SPRD_DMA_DES_DATAWIDTH_OFFSET | >> + slave_cfg->req_mode << SPRD_DMA_REQ_MODE_OFFSET | >> + wrap_mode << SPRD_DMA_WRAP_SEL_OFFSET | >> + wrap_en << SPRD_DMA_WRAP_EN_OFFSET | >> + fix_mode << SPRD_DMA_FIX_SEL_OFFSET | >> + fix_en << SPRD_DMA_FIX_EN_OFFSET | >> + (slave_cfg->cfg.src_maxburst & SPRD_DMA_FRG_LEN_MASK); > > sorry this is not at all readable... Will fix in next version. > >> +static struct dma_async_tx_descriptor * >> +sprd_dma_prep_slave_sg(struct dma_chan *chan, struct scatterlist *sgl, >> + unsigned int sglen, enum dma_transfer_direction dir, >> + unsigned long flags, void *context) >> +{ >> + struct sprd_dma_chn *schan = to_sprd_dma_chan(chan); >> + struct sprd_dma_config *slave_cfg = &schan->slave_cfg; >> + struct sprd_dma_desc *sdesc; >> + struct scatterlist *sg; >> + int ret, i; >> + >> + /* TODO: now we only support one sg for each DMA configuration. */ > > thats a SW limit right and you will fix it later? We will add new features to fix it in future. > >> + if (!is_slave_direction(dir) || sglen > 1) >> + return NULL; >> + >> + sdesc = kzalloc(sizeof(*sdesc), GFP_NOWAIT); >> + if (!sdesc) >> + return NULL; >> + >> + for_each_sg(sgl, sg, sglen, i) { >> + if (dir == DMA_MEM_TO_DEV) { >> + slave_cfg->src_addr = sg_dma_address(sg); >> + slave_cfg->dst_addr = slave_cfg->cfg.dst_addr; >> + slave_cfg->src_step = >> + sprd_dma_get_step(slave_cfg->cfg.src_addr_width); >> + slave_cfg->dst_step = SPRD_DMA_NONE_STEP; >> + } else { >> + slave_cfg->src_addr = slave_cfg->cfg.src_addr; >> + slave_cfg->dst_addr = sg_dma_address(sg); >> + slave_cfg->src_step = SPRD_DMA_NONE_STEP; >> + slave_cfg->dst_step = >> + sprd_dma_get_step(slave_cfg->cfg.dst_addr_width); > > use a helper for filling this and passing right values for each case? We need pass many values to this helper, but will try. Thanks. -- Baolin.wang Best Regards