From patchwork Tue Dec 5 20:56:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mfornero@gmail.com X-Patchwork-Id: 10093771 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 726056056E for ; Tue, 5 Dec 2017 20:57:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5B944295C8 for ; Tue, 5 Dec 2017 20:57:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E65D295DA; Tue, 5 Dec 2017 20:57:07 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 27A59295C8 for ; Tue, 5 Dec 2017 20:57:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751416AbdLEU5F (ORCPT ); Tue, 5 Dec 2017 15:57:05 -0500 Received: from mail-qt0-f193.google.com ([209.85.216.193]:42495 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751112AbdLEU5F (ORCPT ); Tue, 5 Dec 2017 15:57:05 -0500 Received: by mail-qt0-f193.google.com with SMTP id g9so4075125qth.9 for ; Tue, 05 Dec 2017 12:57:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p24Pb0Vy5zDWsl92vS96O5jRDA1cJ6Uw/GifhhZPPYg=; b=j6Ggb3l0LC8VuNjwP4i8cl6kDLoMB6dCG3XnsCs5biDFDIE3RVXHlwpXiu9kAa1NSB T3xg+fGZmZYbGgXDQ8NcSeuanP/wYYTW36jchLZN1bRL1kCBu+BzqkE67wqCYjYan2ZQ QMvdPREGWsKcjCA0QcA8iCP91rOJX6tzbE8FsbBW6PFKVNDRuusNOlla4cpA1QeZylIg 60FFDolxk+yQtTtkjpInp0a9lwd04A4INo/XjbbKPrAUH8f1t7cJf6BeNYgnpfTDwWub Fw/JWDaWrwYjjekmWlpR6Tie3egR6/BFZMtzGIvQv2F3pM0R95umL89ZP+XoXpuFoV2F xsJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p24Pb0Vy5zDWsl92vS96O5jRDA1cJ6Uw/GifhhZPPYg=; b=hikXnHKjtLPnXCnnE+bJbHHahxPVI6DaMWQtjF0dfFeBS6BghdO1A3SZMlKkFA2ioQ Z6VXukz2mXjK8NzaSFetiVhnoeYjFVnD2qFwmlnW8A4tmV1765sWakInAyM39o3tJvdC m8KMMYsocWwhgeOMEd6LhQFNYa1pZ1UKDheSkslgqxCyJBIEoAS2sz0uJwds5OfGmrbW I2Qtmiik8idYzvHERptjgci1BqaHi8Jd42uQKYAnjqaIIlZV1G3fLwXVqnTU5pjWxP8N ob7Dd8DGLZ4bL48PNBDo2KMuqWertMM/inC5MfiuhYSfxrklqBIjOnxwG8qa3exo3ddV 5FSg== X-Gm-Message-State: AKGB3mJjb1gCXjTlhHOX1MmDSyJexIVv+XJruoYlA3ruwuJ4jYeQJo74 x/W3Kie199FFUQtmp49uVGoPbNZY X-Google-Smtp-Source: AGs4zMbBQOx7EymFdX9giFuhCxzX/jopjQUcyLpTYe/BI45Rk4UjAg+TWr8tu3VwetFDbVUXP0Vuvg== X-Received: by 10.200.54.176 with SMTP id a45mr2716026qtc.176.1512507424177; Tue, 05 Dec 2017 12:57:04 -0800 (PST) Received: from mfornero-centos7-64.home (99-124-156-181.lightspeed.sntcca.sbcglobal.net. [99.124.156.181]) by smtp.gmail.com with ESMTPSA id k51sm648900qtc.33.2017.12.05.12.57.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 05 Dec 2017 12:57:03 -0800 (PST) From: mfornero@gmail.com To: jic23@kernel.org, lars@metafoo.de Cc: linux-iio@vger.kernel.org, Matt Fornero Subject: [PATCH v2] iio: buffer: Expose data available Date: Tue, 5 Dec 2017 15:56:56 -0500 Message-Id: <1512507416-21856-1-git-send-email-mfornero@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1512161180-30116-1-git-send-email-mfornero@gmail.com> References: <1512161180-30116-1-git-send-email-mfornero@gmail.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Matt Fornero Add a sysfs attribute that exposes buffer data available to userspace. This attribute can be checked at runtime to determine the overall buffer fill level (across all allocated buffers). Signed-off-by: Matt Fornero --- v1 -> v2: - Use iio_buffer_data_available() for all buffers instead of only DMA buffers drivers/iio/industrialio-buffer.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/iio/industrialio-buffer.c b/drivers/iio/industrialio-buffer.c index d80f830..e7bdfa3 100644 --- a/drivers/iio/industrialio-buffer.c +++ b/drivers/iio/industrialio-buffer.c @@ -1121,6 +1121,18 @@ static ssize_t iio_buffer_store_watermark(struct device *dev, return ret ? ret : len; } +static ssize_t iio_dma_show_data_available(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + struct iio_dev *indio_dev = dev_to_iio_dev(dev); + size_t bytes; + + bytes = iio_buffer_data_available(indio_dev->buffer); + + return sprintf(buf, "%llu\n", (unsigned long long)bytes); +} + static DEVICE_ATTR(length, S_IRUGO | S_IWUSR, iio_buffer_read_length, iio_buffer_write_length); static struct device_attribute dev_attr_length_ro = __ATTR(length, @@ -1131,11 +1143,14 @@ static DEVICE_ATTR(watermark, S_IRUGO | S_IWUSR, iio_buffer_show_watermark, iio_buffer_store_watermark); static struct device_attribute dev_attr_watermark_ro = __ATTR(watermark, S_IRUGO, iio_buffer_show_watermark, NULL); +static DEVICE_ATTR(data_available, S_IRUGO, + iio_dma_show_data_available, NULL); static struct attribute *iio_buffer_attrs[] = { &dev_attr_length.attr, &dev_attr_enable.attr, &dev_attr_watermark.attr, + &dev_attr_data_available.attr, }; int iio_buffer_alloc_sysfs_and_mask(struct iio_dev *indio_dev)