Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp7861244pxb; Fri, 19 Feb 2021 00:48:42 -0800 (PST) X-Google-Smtp-Source: ABdhPJz0n4bOnYSRKe8Gyol/z7Vq6cqYkqDe67wI1cXSdvgBjZ+dfvtU/mp4i6sMtWL2VihgKh5U X-Received: by 2002:a17:906:2652:: with SMTP id i18mr7770671ejc.213.1613724522170; Fri, 19 Feb 2021 00:48:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613724522; cv=none; d=google.com; s=arc-20160816; b=rxIdOmaZ8kte6zulXJfwiEm+kK0i3mW5+YwFF4trMku3GIS7hnaod36jUv0v3DVTC6 O+AuJaOszl+5O0g5exhSNXth2Tp5qzxWBVtsa6usI7hFtm0Ja+/UOUnkhVq0cJVJn3QN 6y53MyhCqicNxX6Ey8pzOldGRO/3rblJzCExwRq4kxkq8Ie9zSygY7vkuwfZkt1G2GJi Xb1rtLxTWG5U05H90yt/elCD/OJ1dJzJBItRmDQQ8bBSN60aOGcTt8B16JSyJKolHrqH G0XwccAL03e1LByqb+syuI/8N/irGnn/VR3x8kHIiMp7zpCit7liWJr3T6HA27WzH2IK hd2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=7dkoFvnkhD7Gw0bj/FIIwq2SMclEKsgMhUhYHtvCM/Q=; b=ED4XIO9TFuLMUZZloehW6/8pIEXwhCZ7vK/vRP669L1lX0y2ZiMJ971R21Sh9UIEg/ 289ySagkgH5Btts0Ij0XXk4+sxVDGy8bD7Tg9I5KiYXlEi6Q/VpILLGoLt6hkijN9C5M Ixnv00LhmuQV1SgXpwOeono9xM4zXMVcw/tyZAByYnfnSvhiqGbBrbVUy9hTxgY9VcG/ aj3Jobv18FCE1Yx/s3fMq0jflfd7UcrSf8qOMknFUbctwehcmvUSEpcq3Z+k/p8hvWts zj/UsrSnlFlaJIUcO1XSC786f/Xo9XFIwTCcE4/CSQZsuIEpyKViC9+7ELJYXlAxFDXk WNBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VacweNxi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dt10si5512030ejb.674.2021.02.19.00.48.18; Fri, 19 Feb 2021 00:48:42 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=VacweNxi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229808AbhBSIqe (ORCPT + 99 others); Fri, 19 Feb 2021 03:46:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229625AbhBSIqb (ORCPT ); Fri, 19 Feb 2021 03:46:31 -0500 Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10197C061574; Fri, 19 Feb 2021 00:45:51 -0800 (PST) Received: by mail-io1-xd2b.google.com with SMTP id u20so4827306iot.9; Fri, 19 Feb 2021 00:45:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=7dkoFvnkhD7Gw0bj/FIIwq2SMclEKsgMhUhYHtvCM/Q=; b=VacweNxitgPmKnxB9yB2yqDAdBsx3QBI0tQEUPZe58fVV1tmTpXQSql3oN23oymdyh B0a7dX1vVboQQveAxnj/0V7ekajUoWjzHFJxlu63ZF+hA0f6Pv+zkm7aRNRi58hjXNvr undltDAO+VyDNjeOxVTfFKImVCkMfB/RpKbgWvG9W+XOMNQfPhdHgZkZuNKa3IuLqYu8 p374kcwrajQXpbbBE8yT1k+yQpkCyG+twC9FduAI7VxEV6D0/HFj8Q588EL0FaVYBoeh iKk1kBc7j5QKQir7WRCeeVOVGpLXwTj8rl61S2CaOXGZFEizLa4wjNxF6hi9iQi7ZZC0 KQuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=7dkoFvnkhD7Gw0bj/FIIwq2SMclEKsgMhUhYHtvCM/Q=; b=cQmzCUwKc4GBe7Smiderm5GxOuEQ18piPghrjiOrkFS3TsrhQb3L4Gmo4yd6esAD4e 4/158Bgf2Lc9/NrRlA5ZvG647NdCDUpuEbk0Ked6Q5XiiGleOmv35gzStA4Pnq8P/6Gl vsfZnzDk6RtNC+Dof47b8GnL3OWTxxeft2WOpJNkmXMaF/P+23oz2YVgyVmp+PvQ121/ nKyiZ0RyLBIPxX37hONyzFTUoKu8nQWpU++ZGfPLOvErM+Tu2PC2XWAl+y5hy0O+caUw tGO8Mj8wxRoFqUtvazboGPhZJStoJR/OUzVEEFsyoAGaIB2w0jInpgG4UZ/bfabB+o0W lTEQ== X-Gm-Message-State: AOAM530NWCBvRXuBrWaRkNTkXouLY1qgQn4cHdQ09lNKT2h6wLTJwoyS h8OfbzRN4viijHulo2W9xDVxBQNEpJQFU7JNtUvrftUxlLI= X-Received: by 2002:a02:cce6:: with SMTP id l6mr8664351jaq.69.1613724350416; Fri, 19 Feb 2021 00:45:50 -0800 (PST) MIME-Version: 1.0 References: <20210217083438.37865-1-alexandru.ardelean@analog.com> <20210217083438.37865-3-alexandru.ardelean@analog.com> <20210218134240.2dd1feb2@archlinux> In-Reply-To: <20210218134240.2dd1feb2@archlinux> From: Alexandru Ardelean Date: Fri, 19 Feb 2021 10:45:39 +0200 Message-ID: Subject: Re: [PATCH v2 2/5] iio: Add output buffer support To: Jonathan Cameron Cc: Alexandru Ardelean , LKML , linux-iio , Lars-Peter Clausen , "Hennerich, Michael" , =?UTF-8?B?TnVubyBTw6E=?= , "Bogdan, Dragos" Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 18, 2021 at 5:30 PM Jonathan Cameron wrote: > > On Wed, 17 Feb 2021 10:34:35 +0200 > Alexandru Ardelean wrote: > > > From: Lars-Peter Clausen > > > > Currently IIO only supports buffer mode for capture devices like ADCs. Add > > support for buffered mode for output devices like DACs. > > > > The output buffer implementation is analogous to the input buffer > > implementation. Instead of using read() to get data from the buffer write() > > is used to copy data into the buffer. > > > > poll() with POLLOUT will wakeup if there is space available for more or > > equal to the configured watermark of samples. > > > > Drivers can remove data from a buffer using iio_buffer_remove_sample(), the > > function can e.g. called from a trigger handler to write the data to > > hardware. > > > > A buffer can only be either a output buffer or an input, but not both. So, > > for a device that has an ADC and DAC path, this will mean 2 IIO buffers > > (one for each direction). > > > > The direction of the buffer is decided by the new direction field of the > > iio_buffer struct and should be set after allocating and before registering > > it. > > > > Signed-off-by: Lars-Peter Clausen > > Signed-off-by: Alexandru Ardelean > > Just one question on this, otherwise looks good to me. > > Jonathan > > > diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c > > index 5d641f8adfbd..b9970c68005d 100644 > > --- a/drivers/iio/industrialio-buffer.c > > +++ b/drivers/iio/industrialio-buffer.c > > @@ -162,6 +162,69 @@ static ssize_t iio_buffer_read(struct file *filp, char __user *buf, > > return ret; > > } > > > ... > > > /** > > * iio_buffer_poll() - poll the buffer to find out if it has data > > * @filp: File structure pointer for device access > > @@ -182,8 +245,19 @@ static __poll_t iio_buffer_poll(struct file *filp, > > return 0; > > > > poll_wait(filp, &rb->pollq, wait); > > - if (iio_buffer_ready(indio_dev, rb, rb->watermark, 0)) > > - return EPOLLIN | EPOLLRDNORM; > > + > > + switch (rb->direction) { > > + case IIO_BUFFER_DIRECTION_IN: > > + if (iio_buffer_ready(indio_dev, rb, rb->watermark, 0)) > > + return EPOLLIN | EPOLLRDNORM; > > + break; > > + case IIO_BUFFER_DIRECTION_OUT: > > + if (iio_buffer_space_available(rb) >= rb->watermark) > > + return EPOLLOUT | EPOLLWRNORM; > > + break; > > + } > > + > > + /* need a way of knowing if there may be enough data... */ > > Curious on what this comment is referring to? I'm also a bit curious about what this comment is referring to. I can remove it. Maybe Lars can give some insight. > > > return 0; > > } > > > > @@ -232,6 +306,16 @@ void iio_buffer_wakeup_poll(struct iio_dev *indio_dev) > > } > > } > ...