Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp4733058rwl; Mon, 3 Apr 2023 08:54:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZXe+hgC/vDDWMMhsshaOjT6oyIU3AzUghIAWRUkJpDyz6zeeU+XKXNHLLoJ43lJmGOJUOI X-Received: by 2002:aa7:d713:0:b0:501:d52d:7f88 with SMTP id t19-20020aa7d713000000b00501d52d7f88mr34504533edq.10.1680537262663; Mon, 03 Apr 2023 08:54:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680537262; cv=none; d=google.com; s=arc-20160816; b=ACYiBdEokqpyy0IRIVFW29WTKTqoacCTfaGVYM6eR/etrirFkj1ldSkHwH94ZQWtH5 /fpAbWwHEdewdwJLpls7Phy2cSKSsr3DMGZ7kHrVRpDxStkIj2EvcCHm6bS8/0LRVQfh HJR7rxb8QumnuJfANOPlJGpHksWlSDbhXGhSFOHacsiiyRL7lkAdHgBaACp/dYhtLWyx 8Poq+WKNqaRPLpQlBIuN/tX7hbSEhQj7z3JRXklmLWVwVd8w++DDOuQdIni5SsW2m+Tv UTA0W8fYt8SD6AMsxN1aj7OnYaqV4fchZmJRjPad32VPfO4DsgaCDQ1gVLKUleW6IPbF APhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1izcu1WFEt9b1dtaujjpu20y6Ear8HIPhk9DR+eEyjM=; b=naHsilvcrs6/1zUdxvMm8NCyiqry/pz0+Coog/L0P1YONTqyzr/LCbIZ6uLqEIEqn6 5g9xYApHnMdUVMgGT2lCTBlg7u7xlZAPVZLf4O4KyzsWzj4MSbUvwn9ye5CVaJJh0OYJ 09E+bcVjTOL0vegaU+UHjUAY26e9y7KBl51iKwQIFa1g5A6y/Z9tSezcVjmfE//NDfwD OAus+UIFf/T+i//EIjqCGeahMX/I6UzkK6d+gfhPRtVdxSbDiezkNmwDNB9zr6w4HIB4 xzqA/k/UgrxCXAOl/qULn8uJESO/Kvdp0/BT0BpJe7vgAfQR/87+uHb9R66qAQYVeFnc 4QXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=ljgwlqlO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f11-20020a056402160b00b00501dc7c4093si8101386edv.44.2023.04.03.08.53.56; Mon, 03 Apr 2023 08:54:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=ljgwlqlO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232912AbjDCPwV (ORCPT + 99 others); Mon, 3 Apr 2023 11:52:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60042 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231450AbjDCPwF (ORCPT ); Mon, 3 Apr 2023 11:52:05 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D1B8E61; Mon, 3 Apr 2023 08:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1680536896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1izcu1WFEt9b1dtaujjpu20y6Ear8HIPhk9DR+eEyjM=; b=ljgwlqlOwZPST5STP6Sk4GHJKbrMKG5ReGJabr5s0M0POrNRwMlcE5iLbGkjAlBWFz08+P mzOQJUEgkqfIHSpAqJ2U48K6q3p9wQ4qBCRd2985d+9uzvma4lGF12cT+b0sXnwsdiV9Y9 YSOUIkyiHi6PxtZYIDww20BXOKiAr5s= From: Paul Cercueil To: Jonathan Cameron , Lars-Peter Clausen , Vinod Koul , Michael Hennerich , =?UTF-8?q?Nuno=20S=C3=A1?= , Sumit Semwal , =?UTF-8?q?Christian=20K=C3=B6nig?= Cc: linux-kernel@vger.kernel.org, dmaengine@vger.kernel.org, linux-iio@vger.kernel.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, Paul Cercueil , Alexandru Ardelean Subject: [PATCH v3 05/11] iio: buffer-dmaengine: Support specifying buffer direction Date: Mon, 3 Apr 2023 17:47:54 +0200 Message-Id: <20230403154800.215924-6-paul@crapouillou.net> In-Reply-To: <20230403154800.215924-1-paul@crapouillou.net> References: <20230403154800.215924-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Update the devm_iio_dmaengine_buffer_setup() function to support specifying the buffer direction. Update the iio_dmaengine_buffer_submit() function to handle input buffers as well as output buffers. Signed-off-by: Paul Cercueil Reviewed-by: Alexandru Ardelean --- drivers/iio/adc/adi-axi-adc.c | 3 ++- .../buffer/industrialio-buffer-dmaengine.c | 24 +++++++++++++++---- include/linux/iio/buffer-dmaengine.h | 5 +++- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/iio/adc/adi-axi-adc.c b/drivers/iio/adc/adi-axi-adc.c index e8a8ea4140f1..d33574b5417a 100644 --- a/drivers/iio/adc/adi-axi-adc.c +++ b/drivers/iio/adc/adi-axi-adc.c @@ -114,7 +114,8 @@ static int adi_axi_adc_config_dma_buffer(struct device *dev, dma_name = "rx"; return devm_iio_dmaengine_buffer_setup(indio_dev->dev.parent, - indio_dev, dma_name); + indio_dev, dma_name, + IIO_BUFFER_DIRECTION_IN); } static int adi_axi_adc_read_raw(struct iio_dev *indio_dev, diff --git a/drivers/iio/buffer/industrialio-buffer-dmaengine.c b/drivers/iio/buffer/industrialio-buffer-dmaengine.c index 5f85ba38e6f6..592d2aa9044c 100644 --- a/drivers/iio/buffer/industrialio-buffer-dmaengine.c +++ b/drivers/iio/buffer/industrialio-buffer-dmaengine.c @@ -64,14 +64,25 @@ static int iio_dmaengine_buffer_submit_block(struct iio_dma_buffer_queue *queue, struct dmaengine_buffer *dmaengine_buffer = iio_buffer_to_dmaengine_buffer(&queue->buffer); struct dma_async_tx_descriptor *desc; + enum dma_transfer_direction dma_dir; + size_t max_size; dma_cookie_t cookie; - block->bytes_used = min(block->size, dmaengine_buffer->max_size); - block->bytes_used = round_down(block->bytes_used, - dmaengine_buffer->align); + max_size = min(block->size, dmaengine_buffer->max_size); + max_size = round_down(max_size, dmaengine_buffer->align); + + if (queue->buffer.direction == IIO_BUFFER_DIRECTION_IN) { + block->bytes_used = max_size; + dma_dir = DMA_DEV_TO_MEM; + } else { + dma_dir = DMA_MEM_TO_DEV; + } + + if (!block->bytes_used || block->bytes_used > max_size) + return -EINVAL; desc = dmaengine_prep_slave_single(dmaengine_buffer->chan, - block->phys_addr, block->bytes_used, DMA_DEV_TO_MEM, + block->phys_addr, block->bytes_used, dma_dir, DMA_PREP_INTERRUPT); if (!desc) return -ENOMEM; @@ -275,7 +286,8 @@ static struct iio_buffer *devm_iio_dmaengine_buffer_alloc(struct device *dev, */ int devm_iio_dmaengine_buffer_setup(struct device *dev, struct iio_dev *indio_dev, - const char *channel) + const char *channel, + enum iio_buffer_direction dir) { struct iio_buffer *buffer; @@ -286,6 +298,8 @@ int devm_iio_dmaengine_buffer_setup(struct device *dev, indio_dev->modes |= INDIO_BUFFER_HARDWARE; + buffer->direction = dir; + return iio_device_attach_buffer(indio_dev, buffer); } EXPORT_SYMBOL_GPL(devm_iio_dmaengine_buffer_setup); diff --git a/include/linux/iio/buffer-dmaengine.h b/include/linux/iio/buffer-dmaengine.h index 5c355be89814..538d0479cdd6 100644 --- a/include/linux/iio/buffer-dmaengine.h +++ b/include/linux/iio/buffer-dmaengine.h @@ -7,11 +7,14 @@ #ifndef __IIO_DMAENGINE_H__ #define __IIO_DMAENGINE_H__ +#include + struct iio_dev; struct device; int devm_iio_dmaengine_buffer_setup(struct device *dev, struct iio_dev *indio_dev, - const char *channel); + const char *channel, + enum iio_buffer_direction dir); #endif -- 2.39.2