Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp3035432rwb; Mon, 7 Aug 2023 07:20:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE2AyfUYKb2fyI/uWR7biyeurQqUdvNPRuekoohZG2ftoeXi5snrp9VdKtAV4IZaCBv6TJu X-Received: by 2002:a05:6512:3d06:b0:4fb:8ff3:1f72 with SMTP id d6-20020a0565123d0600b004fb8ff31f72mr3041321lfv.1.1691418036743; Mon, 07 Aug 2023 07:20:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691418036; cv=none; d=google.com; s=arc-20160816; b=eFyDkO4SxYjrYUv0v7rsDi1eRjm0SZLsoz2775Hkt+j0tRolwRtHJ66pURFX17Lykr JoL60MCc4nLokOpy8aorI5Se6Ug1HgPnDScEbX0Jkao9KeHGYpU+0dW++bDBRBx+dB71 yjT8xcn+DLjJZU71AIuq3BTnKEIrPmct6fgksyNM/b7N6YmoxLdM/zojR6zU76rqwdkL 21X2MyAThMNdGsuLGRl6B6ei1pECaN4+i6teD1Kmv1QhX35E1+OJzL1+buaq5NMcG0Cc Fr3KrKIewB0mG6m1QwV42zhiOYjOTtWtHWxL6GonIkB8TOCHo51wYI7kllPAokH3QBlp +9Dw== 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=zaX0JNZAl6IZc89GKARBAqn5r+/uiF51q0xYvvqR4EE=; fh=QagBC1ic3VcVFskRmEqUJZ5VlGz5jYfCtms1OQ7G2VM=; b=aJ52sV+ODuq3s8OQ3QsrvAyoBG/elLm4MlL42tkpKRCMI5ud3BcudhsYEtyjb7mlUe oth7W60gWftUUAg9jO26uXcZoMMNyMOf8AjP3rYcohesM32S7gkoeKm/vBO5N16t2yv/ T3nmCibjRgMlIjSTzIvNvBJ6vZq5M4rL64BnHVjX96rk6AEpy75E+eJIOcHoIeLoOGi7 rjymWdfshsLrylEayeo4veWVAvRIn5zbV1lGSq1zRDf5zSO6h4k4HxSwK7RGre4Jx2gf MBAxrtJO96bG2iCO/MBuKW+CXW2gEbqT1aReRwuWc3PJRWVLR/p8YZBP8qTofR7AUalD M+UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b=oLUAGrNH; 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 w23-20020aa7cb57000000b00523400a2012si198693edt.235.2023.08.07.07.20.11; Mon, 07 Aug 2023 07:20:36 -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=oLUAGrNH; 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 S233153AbjHGMBH (ORCPT + 99 others); Mon, 7 Aug 2023 08:01:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233163AbjHGMAt (ORCPT ); Mon, 7 Aug 2023 08:00:49 -0400 Received: from aposti.net (aposti.net [89.234.176.197]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 852D6128; Mon, 7 Aug 2023 05:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1691407287; 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=zaX0JNZAl6IZc89GKARBAqn5r+/uiF51q0xYvvqR4EE=; b=oLUAGrNHY0ZX2uhcnw1pz+EqM9Uh8XUsKVa3QJkD8Mqip0BUlz2WooZOheQ4vaO7rRCTfR M1SKXkuvV6lz0lsW7aQP7zpbEMnM6R7agGirbACo8TeLrtKnokb1s0pnRNh0MqbtNqPJOx bOJdzoda8wBIx8IUq2TZ9GBRS9B4JVA= From: Paul Cercueil To: Jonathan Cameron Cc: Lars-Peter Clausen , Michael Hennerich , =?UTF-8?q?Nuno=20S=C3=A1?= , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil , Alexandru Ardelean Subject: [PATCH v4 5/6] iio: buffer-dmaengine: Support specifying buffer direction Date: Mon, 7 Aug 2023 13:21:12 +0200 Message-Id: <20230807112113.47157-6-paul@crapouillou.net> In-Reply-To: <20230807112113.47157-1-paul@crapouillou.net> References: <20230807112113.47157-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam: Yes X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS autolearn=ham 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 7b49f85af064..deae5a4ac03d 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.40.1