linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Kent Gibson <warthog618@gmail.com>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jack Winch <sunt.un.morcov@gmail.com>,
	Helmut Grohne <helmut.grohne@intenta.de>,
	Ben Hutchings <ben.hutchings@essensium.com>
Cc: linux-gpio@vger.kernel.org, Bartosz Golaszewski <brgl@bgdev.pl>
Subject: [libgpiod v2][PATCH 2/3] line-info: provide gpiod_line_info_get_event_clock()
Date: Fri, 30 Jul 2021 16:43:55 +0200	[thread overview]
Message-ID: <20210730144356.23079-3-brgl@bgdev.pl> (raw)
In-Reply-To: <20210730144356.23079-1-brgl@bgdev.pl>

Provide a new getter for the line-info object that becomes the
counterpart for the setter used to configure the event clock type with
line_config. It allows to check which even clock the line uses for
edge detection.

Signed-off-by: Bartosz Golaszewski <brgl@bgdev.pl>
---
 include/gpiod.h | 18 ++++++++++++++++++
 lib/line-info.c | 11 +++++++++++
 2 files changed, 29 insertions(+)

diff --git a/include/gpiod.h b/include/gpiod.h
index d3c327b..4506571 100644
--- a/include/gpiod.h
+++ b/include/gpiod.h
@@ -245,6 +245,16 @@ enum {
 	/**< Line detects both rising and falling edge events. */
 };
 
+/**
+ * @brief Possible event clock settings.
+ */
+enum {
+	GPIOD_LINE_EVENT_CLOCK_MONOTONIC = 1,
+	/**< Line uses the monotonic clock for edge event timestamps. */
+	GPIOD_LINE_EVENT_CLOCK_REALTIME,
+	/**< Line uses the realtime clock for edge event timestamps. */
+};
+
 /**
  * @brief Free a line info object and release all associated resources.
  * @param info GPIO line info object to free.
@@ -333,6 +343,14 @@ int gpiod_line_info_get_drive(struct gpiod_line_info *info);
  */
 int gpiod_line_info_get_edge_detection(struct gpiod_line_info *info);
 
+/**
+ * @brief Read the current event clock setting used for edge event timestamps.
+ * @param info GPIO line info object.
+ * @return Returns GPIOD_LINE_EVENT_CLOCK_MONOTONIC or
+ *         GPIOD_LINE_EVENT_CLOCK_REALTIME.
+ */
+int gpiod_line_info_get_event_clock(struct gpiod_line_info *info);
+
 /**
  * @brief Check if this line is debounced (either by hardware or by the kernel
  *        software debouncer).
diff --git a/lib/line-info.c b/lib/line-info.c
index aed8bee..0280981 100644
--- a/lib/line-info.c
+++ b/lib/line-info.c
@@ -17,6 +17,7 @@ struct gpiod_line_info {
 	int bias;
 	int drive;
 	int edge;
+	int event_clock;
 	bool debounced;
 	unsigned long debounce_period;
 };
@@ -86,6 +87,11 @@ GPIOD_API int gpiod_line_info_get_edge_detection(struct gpiod_line_info *info)
 	return info->edge;
 }
 
+GPIOD_API int gpiod_line_info_get_event_clock(struct gpiod_line_info *info)
+{
+	return info->event_clock;
+}
+
 GPIOD_API bool gpiod_line_info_is_debounced(struct gpiod_line_info *info)
 {
 	return info->debounced;
@@ -150,6 +156,11 @@ gpiod_line_info_from_kernel(struct gpio_v2_line_info *infobuf)
 	else
 		info->edge = GPIOD_LINE_EDGE_NONE;
 
+	if (infobuf->flags & GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME)
+		info->event_clock = GPIOD_LINE_EVENT_CLOCK_REALTIME;
+	else
+		info->event_clock = GPIOD_LINE_EVENT_CLOCK_MONOTONIC;
+
 	/*
 	 * We assume that the kernel returns correct configuration and that no
 	 * attributes repeat.
-- 
2.30.1


  parent reply	other threads:[~2021-07-30 14:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-30 14:43 [libgpiod v2][PATCH 0/3] libgpiod v2: new API improvements Bartosz Golaszewski
2021-07-30 14:43 ` [libgpiod v2][PATCH 1/3] chip: provide gpiod_chip_get_path() Bartosz Golaszewski
2021-07-30 14:43 ` Bartosz Golaszewski [this message]
2021-07-31  2:27   ` [libgpiod v2][PATCH 2/3] line-info: provide gpiod_line_info_get_event_clock() Kent Gibson
2021-08-02  8:12     ` Bartosz Golaszewski
2021-07-30 14:43 ` [libgpiod v2][PATCH 3/3] treewide: unify the line settings defines Bartosz Golaszewski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210730144356.23079-3-brgl@bgdev.pl \
    --to=brgl@bgdev.pl \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=ben.hutchings@essensium.com \
    --cc=helmut.grohne@intenta.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=sunt.un.morcov@gmail.com \
    --cc=warthog618@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).