From patchwork Wed Jun 17 03:06:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB0C1C433DF for ; Wed, 17 Jun 2020 03:07:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C83082082E for ; Wed, 17 Jun 2020 03:07:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cdeg4StD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726275AbgFQDH2 (ORCPT ); Tue, 16 Jun 2020 23:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38586 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbgFQDH1 (ORCPT ); Tue, 16 Jun 2020 23:07:27 -0400 Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2507EC061573 for ; Tue, 16 Jun 2020 20:07:27 -0700 (PDT) Received: by mail-pf1-x444.google.com with SMTP id j1so434949pfe.4 for ; Tue, 16 Jun 2020 20:07:27 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=zHkJzBaZ77L8USW6UosIa6ZFshVU3LCBBdcLyBUEXNo=; b=Cdeg4StDc7+IlNxzLiAsdYGKTF4j2P6d576vx8TmWwGmdsrZ7ZJSynsqMUOFwVXNlW VxMyV4aAopIfkBPWIx2gcszpkwdiefrvVhvqinGYnxORTw+4v9Brmp7aJsRXk53AWSfv 59iujtWGyNPsPUTQGtmVkMLjUIS+d6SQaxxMaHaad4LjpFQzfyQpDb510dnRFAyOyM9g cFQyaTe7Vq3w0ZyUqOK8kGcSZ+W5KDIe8mLrAKKO2pCo+y8ojExLsZ7LkjLNhzvYlDDw Pv6p103AKjQj58asg2lKgneyhDEPvr33jRbetFhlxRbLlAiKvjJdAtzFxmGCZifZrL8K PFyA== 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:mime-version:content-transfer-encoding; bh=zHkJzBaZ77L8USW6UosIa6ZFshVU3LCBBdcLyBUEXNo=; b=oO0UDGnKEela3M7SjEEypZedLgC44nmWu337Bb6nckHImNIKCaPzSMI1eru0TpTAwf 5f79Vw03yErkvpRyWOmq6xnKqf7WSpRj6X7b65DnC5/RBgAUGPsEXJiXs4PeWCZd+J9C sJayYV/qY8hJ2o67S4DFEhVbyYVuC3Qw556F9Z71qGUEsJlgNod1pZU1prwZ/gdOCwV+ aFPP/m4Pe2FDHke5NwvgPlwoWKd2Iormkn1x0GSTeoEshRrkT+C+qRXnYppQJBrg7OcS PoNsm1AbADn58p1BlfWNQG97XDq4xUfocaVpkcCDJtpSBxmqm4ddHkP+bcdld01sooU/ cgEQ== X-Gm-Message-State: AOAM530ROEhBREhhaX4zDC86R3hxUTJV6w+TOSubDeh8gqdM1isXUf/N 4LKMNxfg+sYsLNXhDvED32YfB8AnPLs= X-Google-Smtp-Source: ABdhPJy/PJna8oMWlrqtL3Jn+bZsZ8CXfTcSkJ+z0jaQAZfOKQQ8/WIq52fHcbQCbke1wmrbdD/p0w== X-Received: by 2002:a63:5b0e:: with SMTP id p14mr4660340pgb.43.1592363246273; Tue, 16 Jun 2020 20:07:26 -0700 (PDT) Received: from sol.lan (220-235-93-205.dyn.iinet.net.au. [220.235.93.205]) by smtp.gmail.com with ESMTPSA id p6sm9185578pfb.152.2020.06.16.20.07.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 20:07:25 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, ml@ionscale.com Cc: Kent Gibson Subject: [PATCH 1/3] bindings: cxx: tests: add tests for bulk events get_values Date: Wed, 17 Jun 2020 11:06:37 +0800 Message-Id: <20200617030639.27690-2-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200617030639.27690-1-warthog618@gmail.com> References: <20200617030639.27690-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add tests to verify the behaviour of get_values when applied to a bulk of event lines. Reported-by: Gerrit Wyen Signed-off-by: Kent Gibson --- The reported behaviour is that only the first line value is returned correctly. The tests verify that behaviour in v1.5. bindings/cxx/tests/tests-event.cpp | 36 +++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/bindings/cxx/tests/tests-event.cpp b/bindings/cxx/tests/tests-event.cpp index 63b6cc5..6d1c069 100644 --- a/bindings/cxx/tests/tests-event.cpp +++ b/bindings/cxx/tests/tests-event.cpp @@ -193,7 +193,7 @@ TEST_CASE("Event file descriptors can be used for polling", "[event]") } } -TEST_CASE("It's possible to read values from lines requested for events", "[event][line]") +TEST_CASE("It's possible to read a value from a line requested for events", "[event][line]") { mockup::probe_guard mockup_chips({ 8 }); ::gpiod::chip chip(mockup::instance().chip_name(0)); @@ -219,6 +219,40 @@ TEST_CASE("It's possible to read values from lines requested for events", "[even } } +TEST_CASE("It's possible to read values from lines requested for events", "[event][bulk]") +{ + mockup::probe_guard mockup_chips({ 8 }); + ::gpiod::chip chip(mockup::instance().chip_name(0)); + auto lines = chip.get_lines({ 0, 1, 2, 3, 4 }); + ::gpiod::line_request config; + + config.consumer = consumer.c_str(); + config.request_type = ::gpiod::line_request::EVENT_BOTH_EDGES; + + mockup::instance().chip_set_pull(0, 5, 1); + + SECTION("active-high (default)") + { + lines.request(config); + REQUIRE(lines.get_values() == ::std::vector({ 0, 0, 0, 0, 0 })); + mockup::instance().chip_set_pull(0, 1, 1); + mockup::instance().chip_set_pull(0, 3, 1); + mockup::instance().chip_set_pull(0, 4, 1); + REQUIRE(lines.get_values() == ::std::vector({ 0, 1, 0, 1, 1 })); + } + + SECTION("active-low") + { + config.flags = ::gpiod::line_request::FLAG_ACTIVE_LOW; + lines.request(config); + REQUIRE(lines.get_values() == ::std::vector({ 1, 1, 1, 1, 1 })); + mockup::instance().chip_set_pull(0, 1, 1); + mockup::instance().chip_set_pull(0, 3, 1); + mockup::instance().chip_set_pull(0, 4, 1); + REQUIRE(lines.get_values() == ::std::vector({ 1, 0, 1, 0, 0 })); + } +} + TEST_CASE("It's possible to read more than one line event", "[event][line]") { mockup::probe_guard mockup_chips({ 8 }); From patchwork Wed Jun 17 03:06:39 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1167FC433E0 for ; Wed, 17 Jun 2020 03:07:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E29CC2082E for ; Wed, 17 Jun 2020 03:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="O0TuReXE" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726715AbgFQDHp (ORCPT ); Tue, 16 Jun 2020 23:07:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726568AbgFQDHp (ORCPT ); Tue, 16 Jun 2020 23:07:45 -0400 Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F0B4C061573 for ; Tue, 16 Jun 2020 20:07:43 -0700 (PDT) Received: by mail-pj1-x1043.google.com with SMTP id s88so345927pjb.5 for ; Tue, 16 Jun 2020 20:07:43 -0700 (PDT) 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 :mime-version:content-transfer-encoding; bh=AEISxpaXV8eRVTTApqSFU1sLhZp/tNdHYnbvEcBU7bk=; b=O0TuReXEoUkgJo3zt0QaPLLRQcxBoHj5kn1wAHnmnKoEj0dNcf5N5gY0w46MNQMjwi vsw40fsPRbuwKdMQrWP2YOAnXUt3An9CUegLIhvWmUf69PoCdQ8qhv7R8yMlAS9jtuMy Nd47GckEUNvql71K3srtVn4jnb65MVReSRSKdD7ll3/QnhMOjABgAgQFbKixamYQto6F kp1A2HrN3u/b12suFCTnkSpOPQ+jZk/wwthbBBzo/zkmhxWrS5u1/feeKo7yn3jByFIv uE/tdF1RXoIECh3jznjphkeMmE7OwDSt9y5phTH8Hjui/OLnDW1gXt+wlKhE1ZanMxdk QnPg== 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:mime-version:content-transfer-encoding; bh=AEISxpaXV8eRVTTApqSFU1sLhZp/tNdHYnbvEcBU7bk=; b=GqXcKBJujxxkAOWWDkj4noP2XZfKuzPMPZwe00mr07W4WNCK7Vuxqd7eQrpb1KXdcZ 8DLytrrOA725jo4Yno1zvFHWFUHBKY81XGqnTLt8lEA/hHzMRF5E2fkoT/FL08934VNW PX8S3FJ6hfcIaZcVsJXxOlh4Y8f6VZMXkuaRpPzpZyQVlRkC43+RpnIue+zHJGcMlAi4 J0LSfKFolZROjQw30EgrOOA3BR7DIcXoLECBHZrIat5+UBfqR+MgKH7IA6FiDdct6M4L DrjQdOiED+lZoiRv5zDLYhS63bfPu6Mgy7YAtCoi1ty08mnWuhWrVzpfUjlLn+yGnDlb D5Dg== X-Gm-Message-State: AOAM53309dzDxXmDHcbVRNYwbAseTuOW+RFxTYJ5+RHSMKZwRw2VGTbo Iw8Bvqnl1YK6Kip85cxdmrg95fpWScA= X-Google-Smtp-Source: ABdhPJzpOKNirnklnheTYZQpe0Pa6xqDX3UEhXzoWY0iTIgyRqrXwbEq86mEtj5wvfi/YzpgOaE7OQ== X-Received: by 2002:a17:90a:2c06:: with SMTP id m6mr5924986pjd.216.1592363262352; Tue, 16 Jun 2020 20:07:42 -0700 (PDT) Received: from sol.lan (220-235-93-205.dyn.iinet.net.au. [220.235.93.205]) by smtp.gmail.com with ESMTPSA id p6sm9185578pfb.152.2020.06.16.20.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jun 2020 20:07:41 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, ml@ionscale.com Cc: Kent Gibson Subject: [PATCH 3/3] core: fix gpiod_line_get_value_bulk for events Date: Wed, 17 Jun 2020 11:06:39 +0800 Message-Id: <20200617030639.27690-4-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200617030639.27690-1-warthog618@gmail.com> References: <20200617030639.27690-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Extend gpiod_line_get_value_bulk so that it works for bulks of lineevents, not only linehandles. Reported-by: Gerrit Wyen Signed-off-by: Kent Gibson --- lib/core.c | 33 ++++++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/core.c b/lib/core.c index f704b44..ad76051 100644 --- a/lib/core.c +++ b/lib/core.c @@ -773,26 +773,41 @@ int gpiod_line_get_value(struct gpiod_line *line) int gpiod_line_get_value_bulk(struct gpiod_line_bulk *bulk, int *values) { struct gpiohandle_data data; - struct gpiod_line *first; + struct gpiod_line *line; unsigned int i; int rv, fd; if (!line_bulk_same_chip(bulk) || !line_bulk_all_requested(bulk)) return -1; - first = gpiod_line_bulk_get_line(bulk, 0); + line = gpiod_line_bulk_get_line(bulk, 0); - memset(&data, 0, sizeof(data)); + if (line->state == LINE_REQUESTED_VALUES) { + memset(&data, 0, sizeof(data)); - fd = line_get_fd(first); + fd = line_get_fd(line); - rv = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); - if (rv < 0) - return -1; + rv = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); + if (rv < 0) + return -1; - for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) - values[i] = data.values[i]; + for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) + values[i] = data.values[i]; + } else if (line->state == LINE_REQUESTED_EVENTS) { + for (i = 0; i < gpiod_line_bulk_num_lines(bulk); i++) { + line = gpiod_line_bulk_get_line(bulk, i); + + fd = line_get_fd(line); + rv = ioctl(fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); + if (rv < 0) + return -1; + values[i] = data.values[0]; + } + } else { + errno = EINVAL; + return -1; + } return 0; }