Intro to Hardware timestamping engine
Subsystems (6)
Dipen Patel
maintainerPATCH v6 7/10 gpiolib: cdev: Add hardware timestamp clock type
In reply to Dipen PatelThis patch adds new clock type for the GPIO controller which can timestamp gpio lines in using hardware means. To expose such functionalities to the userspace, code has been added where during line create or set config API calls, it checks for new clock type and if requested, calls HTE API. During line change event, the HTE subsystem pushes timestamp data to userspace through gpiolib-cdev.
---
Changes in v2:
- Added hte_dir and static structure hte_ts_desc.
- Added callbacks which get invoked by HTE when new data is available.
- Better use of hte_dir and seq from hte_ts_desc.
- Modified sw debounce function to accommodate hardware timestamping.
Changes in v4:
- Correced line level and event sequence counter handling.
- Added hte edge setup functionality.
Changes in v6:
- Added code to line init and get hte descriptor before making hte request.
drivers/gpio/gpiolib-cdev.c | 252 +++++++++++++++++++++++++++++++----- include/uapi/linux/gpio.h | 3 + 2 files changed, 222 insertions(+), 33 deletions(-)
drivers/gpio/gpiolib-cdev.c +219 -33
@@ -24,6 +24,7 @@#include <linux/timekeeping.h> #include <linux/uaccess.h> #include <linux/workqueue.h> +#include <linux/hte.h> #include <uapi/linux/gpio.h> #include "gpiolib.h"
@@ -464,6 +465,25 @@ struct line {* stale value. */ unsigned int level; +/* +* -- hte specific fields -- +*/ +struct hte_ts_desc hdesc; +/* +* HTE provider sets line level at the time of event. The valid +* value is 0 or 1 and negative value for an error. +*/ +int raw_level; +/* +* when sw_debounce is set on HTE enabled line, this is running +* counter of the discarded events. +*/ +u32 total_discard_seq; +/* +* when sw_debounce is set on HTE enabled line, this variable records +* last sequence number before debounce period expires. +*/ +u32 last_seqno; };/**
@@ -518,6 +538,7 @@ struct linereq { GPIO_V2_LINE_DRIVE_FLAGS | \ GPIO_V2_LINE_EDGE_FLAGS | \ GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME | \ + GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE | \ GPIO_V2_LINE_BIAS_FLAGS) static void linereq_put_event(struct linereq *lr,
@@ -542,10 +563,98 @@ static u64 line_event_timestamp(struct line *line) {if (test_bit (FLAG_EVENT_CLOCK_REALTIME , &line->desc->flags))return ktime_get_real_ns (); +else if (test_bit (FLAG_EVENT_CLOCK_HTE , &line->desc->flags)) +return line->timestamp_ns;return ktime_get_ns (); } +static hte_return_t process_hw_ts_thread (void *p) +{ +struct line *line; +struct linereq *lr; +struct gpio_v2_line_event le; +int level; +u64 eflags; + +if (!p) +return HTE_CB_HANDLED ; + + line = p; + lr = line->req; + +memset (&le,0 ,sizeof (le)); + + le.timestamp_ns = line->timestamp_ns; + eflags =READ_ONCE (line->eflags); + +if (eflags ==GPIO_V2_LINE_FLAG_EDGE_BOTH ) { +if (line->raw_level >=0 ) { +if (test_bit (FLAG_ACTIVE_LOW , &line->desc->flags)) + level = !line->raw_level; +else + level = line->raw_level; + }else { + level =gpiod_get_value_cansleep (line->desc); + } + +if (level) + le.id =GPIO_V2_LINE_EVENT_RISING_EDGE ; +else + le.id =GPIO_V2_LINE_EVENT_FALLING_EDGE ; + }else if (eflags ==GPIO_V2_LINE_FLAG_EDGE_RISING ) { +/* Emit low-to-high event */ + le.id =GPIO_V2_LINE_EVENT_RISING_EDGE ; + }else if (eflags ==GPIO_V2_LINE_FLAG_EDGE_FALLING ) { +/* Emit high-to-low event */ + le.id =GPIO_V2_LINE_EVENT_FALLING_EDGE ; + }else { +return HTE_CB_HANDLED ; + } + le.line_seqno = line->line_seqno; + le.seqno = (lr->num_lines ==1 ) ? le.line_seqno : line->req_seqno; + le.offset =gpio_chip_hwgpio (line->desc); + +linereq_put_event (lr, &le); + +return HTE_CB_HANDLED ; +} + +static hte_return_t process_hw_ts (struct hte_ts_data *ts,void *p) +{ +struct line *line; +struct linereq *lr; +int diff_seqno =0 ; + +if (!ts || !p) +return HTE_CB_HANDLED ; + + line = p; + line->timestamp_ns = ts->tsc; + line->raw_level = ts->raw_level; + lr = line->req; + +if (READ_ONCE (line->sw_debounced)) { + line->total_discard_seq++; + line->last_seqno = ts->seq; +mod_delayed_work (system_wq, &line->work, +usecs_to_jiffies (READ_ONCE (line->desc->debounce_period_us))); + }else { +if (unlikely (ts->seq < line->line_seqno)) +return HTE_CB_HANDLED ; + + diff_seqno = ts->seq - line->line_seqno; + line->line_seqno = ts->seq; +if (lr->num_lines !=1 ) + line->req_seqno =atomic_add_return (diff_seqno, + &lr->seqno); + +return HTE_RUN_SECOND_CB ; + } + +return HTE_CB_HANDLED ; +} +static irqreturn_t edge_irq_thread (int irq,void *p) {struct line *line = p;
@@ -651,10 +760,16 @@ static void debounce_work_func(struct work_struct *work)struct gpio_v2_line_event le; struct line *line = container_of(work, struct line, work.work);struct linereq *lr; -int level; +int level, diff_seqno;u64 eflags; - level =gpiod_get_raw_value_cansleep (line->desc); +if (test_bit (FLAG_EVENT_CLOCK_HTE , &line->desc->flags)) { + level = line->raw_level; +if (level <0 ) + level =gpiod_get_raw_value_cansleep (line->desc); + }else { + level =gpiod_get_raw_value_cansleep (line->desc); + }if (level <0 ) {pr_debug_ratelimited ("debouncer failed to read line value\n" );return ;
@@ -685,10 +800,21 @@ static void debounce_work_func(struct work_struct *work) lr = line->req; le.timestamp_ns =line_event_timestamp (line); le.offset =gpio_chip_hwgpio (line->desc); - line->line_seqno++; - le.line_seqno = line->line_seqno; - le.seqno = (lr->num_lines ==1 ) ? - le.line_seqno :atomic_inc_return (&lr->seqno); +if (test_bit (FLAG_EVENT_CLOCK_HTE , &line->desc->flags)) { +/* discard events except the last one */ + line->total_discard_seq -=1 ; + diff_seqno = line->last_seqno - line->total_discard_seq - + line->line_seqno; + line->line_seqno = line->last_seqno - line->total_discard_seq; + le.line_seqno = line->line_seqno; + le.seqno = (lr->num_lines ==1 ) ? + le.line_seqno :atomic_add_return (diff_seqno, &lr->seqno); + }else { + line->line_seqno++; + le.line_seqno = line->line_seqno; + le.seqno = (lr->num_lines ==1 ) ? + le.line_seqno :atomic_inc_return (&lr->seqno); + }if (level)/* Emit low-to-high event */
@@ -700,8 +826,34 @@ static void debounce_work_func(struct work_struct *work)linereq_put_event (lr, &le); } +static int hte_edge_setup (struct line *line,u64 eflags) +{ +int ret; +unsigned long flags =0 ; +struct hte_ts_desc *hdesc = &line->hdesc; + +if (eflags &GPIO_V2_LINE_FLAG_EDGE_RISING ) + flags |=test_bit (FLAG_ACTIVE_LOW , &line->desc->flags) ? +HTE_FALLING_EDGE_TS :HTE_RISING_EDGE_TS ; +if (eflags &GPIO_V2_LINE_FLAG_EDGE_FALLING ) + flags |=test_bit (FLAG_ACTIVE_LOW , &line->desc->flags) ? +HTE_RISING_EDGE_TS :HTE_FALLING_EDGE_TS ; + + line->total_discard_seq =0 ; + +hte_init_line_attr (hdesc,desc_to_gpio (line->desc), flags, +NULL , line->desc); + + ret =hte_ts_get (NULL , hdesc,0 ); +if (ret) +return ret; + +return hte_request_ts_ns (hdesc, process_hw_ts, + process_hw_ts_thread, line); +} +static int debounce_setup (struct line *line, -unsigned int debounce_period_us) +unsigned int debounce_period_us,bool hte_req) {unsigned long irqflags;int ret, level, irq;
@@ -721,19 +873,27 @@ static int debounce_setup(struct line *line,if (level <0 )return level; - irq =gpiod_to_irq (line->desc); -if (irq <0 ) -return -ENXIO ; +if (!hte_req) { + irq =gpiod_to_irq (line->desc); +if (irq <0 ) +return -ENXIO ; -WRITE_ONCE (line->level, level); - irqflags =IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING ; - ret =request_irq (irq, debounce_irq_handler, irqflags, - line->req->label, line); -if (ret) -return ret; + irqflags =IRQF_TRIGGER_FALLING |IRQF_TRIGGER_RISING ; + ret =request_irq (irq, debounce_irq_handler, irqflags, + line->req->label, line); +if (ret) +return ret; + line->irq = irq; + }else { + ret =hte_edge_setup (line, +GPIO_V2_LINE_FLAG_EDGE_RISING | +GPIO_V2_LINE_FLAG_EDGE_FALLING ); +if (ret) +return ret; + } +WRITE_ONCE (line->level, level);WRITE_ONCE (line->sw_debounced,1 ); - line->irq = irq; }return 0 ; }
@@ -766,13 +926,16 @@ static u32 gpio_v2_line_config_debounce_period(struct gpio_v2_line_config *lc,return 0 ; } -static void edge_detector_stop (struct line *line) +static void edge_detector_stop (struct line *line,bool hte_en) { -if (line->irq) { +if (line->irq && !hte_en) {free_irq (line->irq, line); line->irq =0 ; } +if (hte_en) +hte_ts_put (&line->hdesc); +cancel_delayed_work_sync (&line->work);WRITE_ONCE (line->sw_debounced,0 );WRITE_ONCE (line->eflags,0 );
@@ -784,7 +947,7 @@ static void edge_detector_stop(struct line *line)static int edge_detector_setup (struct line *line,struct gpio_v2_line_config *lc,unsigned int line_idx, -u64 eflags) +u64 eflags,bool hte_req) {u32 debounce_period_us;unsigned long irqflags =0 ;
@@ -799,7 +962,7 @@ static int edge_detector_setup(struct line *line,WRITE_ONCE (line->eflags, eflags);if (gpio_v2_line_config_debounced (lc, line_idx)) { debounce_period_us =gpio_v2_line_config_debounce_period (lc, line_idx); - ret =debounce_setup (line, debounce_period_us); + ret =debounce_setup (line, debounce_period_us, hte_req);if (ret)return ret;WRITE_ONCE (line->desc->debounce_period_us, debounce_period_us);
@@ -809,6 +972,9 @@ static int edge_detector_setup(struct line *line,if (!eflags ||READ_ONCE (line->sw_debounced))return 0 ; +if (hte_req) +return hte_edge_setup (line, eflags); + irq =gpiod_to_irq (line->desc);if (irq <0 )return -ENXIO ;
@@ -834,13 +1000,18 @@ static int edge_detector_setup(struct line *line,static int edge_detector_update (struct line *line,struct gpio_v2_line_config *lc,unsigned int line_idx, -u64 eflags,bool polarity_change) +u64 flags,bool polarity_change, +bool prev_hte_flag) { +u64 eflags = flags &GPIO_V2_LINE_EDGE_FLAGS ;unsigned int debounce_period_us = -gpio_v2_line_config_debounce_period (lc, line_idx); +gpio_v2_line_config_debounce_period (lc, line_idx); +bool hte_change = (prev_hte_flag != + ((flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ) !=0 ));if ((READ_ONCE (line->eflags) == eflags) && !polarity_change && - (READ_ONCE (line->desc->debounce_period_us) == debounce_period_us)) + (READ_ONCE (line->desc->debounce_period_us) == debounce_period_us) + && !hte_change)return 0 ;/* sw debounced and still will be...*/
@@ -851,11 +1022,12 @@ static int edge_detector_update(struct line *line, }/* reconfiguring edge detection or sw debounce being disabled */ -if ((line->irq && !READ_ONCE (line->sw_debounced)) || +if ((line->irq && !READ_ONCE (line->sw_debounced)) || prev_hte_flag || (!debounce_period_us &&READ_ONCE (line->sw_debounced))) -edge_detector_stop (line); +edge_detector_stop (line, prev_hte_flag); -return edge_detector_setup (line, lc, line_idx, eflags); +return edge_detector_setup (line, lc, line_idx, eflags, + flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ); } static u64 gpio_v2_line_config_flags(struct gpio_v2_line_config *lc,
@@ -891,7 +1063,6 @@ static int gpio_v2_line_flags_validate(u64 flags)/* Return an error if an unknown flag is set */ if (flags & ~GPIO_V2_LINE_VALID_FLAGS )return -EINVAL ; -/* * Do not allow both INPUT and OUTPUT flags to be set as they are * contradictory.
@@ -900,6 +1071,11 @@ static int gpio_v2_line_flags_validate(u64 flags) (flags & GPIO_V2_LINE_FLAG_OUTPUT))return -EINVAL ; +/* Only allow one event clock source */ +if ((flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME ) && + (flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE )) +return -EINVAL ; +/* Edge detection requires explicit input. */ if ((flags &GPIO_V2_LINE_EDGE_FLAGS ) && !(flags &GPIO_V2_LINE_FLAG_INPUT ))
@@ -992,6 +1168,8 @@ static void gpio_v2_line_config_flags_to_desc_flags(u64 flags,assign_bit (FLAG_EVENT_CLOCK_REALTIME , flagsp, flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME ); +assign_bit (FLAG_EVENT_CLOCK_HTE , flagsp, + flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ); }static long linereq_get_values (struct linereq *lr,void __user *ip)
@@ -1121,6 +1299,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,unsigned int i;u64 flags;bool polarity_change; +bool prev_hte_flag;int ret;for (i =0 ; i < lr->num_lines; i++) {
@@ -1130,6 +1309,8 @@ static long linereq_set_config_unlocked(struct linereq *lr, (!!test_bit (FLAG_ACTIVE_LOW , &desc->flags) != ((flags &GPIO_V2_LINE_FLAG_ACTIVE_LOW ) !=0 )); + prev_hte_flag = !!test_bit (FLAG_EVENT_CLOCK_HTE , &desc->flags); +gpio_v2_line_config_flags_to_desc_flags (flags, &desc->flags);/* * Lines have to be requested explicitly for input
@@ -1138,7 +1319,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,if (flags &GPIO_V2_LINE_FLAG_OUTPUT ) {int val =gpio_v2_line_config_output_value (lc, i); -edge_detector_stop (&lr->lines[i]); +edge_detector_stop (&lr->lines[i], prev_hte_flag); ret =gpiod_direction_output (desc, val);if (ret)return ret;
@@ -1148,8 +1329,7 @@ static long linereq_set_config_unlocked(struct linereq *lr,return ret; ret =edge_detector_update (&lr->lines[i], lc, i, - flags &GPIO_V2_LINE_EDGE_FLAGS , - polarity_change); + flags, polarity_change, prev_hte_flag);if (ret)return ret; }
@@ -1278,9 +1458,12 @@ static ssize_t linereq_read(struct file *file,static void linereq_free (struct linereq *lr) {unsigned int i; +bool hte;for (i =0 ; i < lr->num_lines; i++) { -edge_detector_stop (&lr->lines[i]); + hte = !!test_bit (FLAG_EVENT_CLOCK_HTE , + &lr->lines[i].desc->flags); +edge_detector_stop (&lr->lines[i], hte);if (lr->lines[i].desc)gpiod_free (lr->lines[i].desc); }
@@ -1406,7 +1589,8 @@ static int linereq_create(struct gpio_device *gdev, void __user *ip) goto out_free_linereq; ret =edge_detector_setup (&lr->lines[i], lc, i, - flags &GPIO_V2_LINE_EDGE_FLAGS ); + flags &GPIO_V2_LINE_EDGE_FLAGS , + flags &GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE );if (ret) goto out_free_linereq; }
@@ -1959,6 +2143,8 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,if (test_bit (FLAG_EVENT_CLOCK_REALTIME , &desc->flags)) info->flags |=GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME ; +else if (test_bit (FLAG_EVENT_CLOCK_HTE , &desc->flags)) + info->flags |=GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ; debounce_period_us =READ_ONCE (desc->debounce_period_us);if (debounce_period_us) {
include/uapi/linux/gpio.h +3 -0
@@ -66,6 +66,8 @@ struct gpiochip_info {* @GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN: line has pull-down bias enabled * @GPIO_V2_LINE_FLAG_BIAS_DISABLED: line has bias disabled * @GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME: line events contain REALTIME timestamps +* @GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE: line events contain timestamps from +* hardware timestamp engine */ enum gpio_v2_line_flag {GPIO_V2_LINE_FLAG_USED =_BITULL (0 ),
@@ -80,6 +82,7 @@ enum gpio_v2_line_flag {GPIO_V2_LINE_FLAG_BIAS_PULL_DOWN =_BITULL (9 ),GPIO_V2_LINE_FLAG_BIAS_DISABLED =_BITULL (10 ),GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME =_BITULL (11 ), + GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE = _BITULL(12), };/**
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 10/10 MAINTAINERS: Added HTE Subsystem
In reply to Dipen PatelAdded myself as a maintainer for this new Hardware Timestamping Engine (HTE) subsystem.
---
Changes in v3:
- Followed guidelines for the "M" field.
- Removed "*" in "F" field.
MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -8987,6 +8987,14 @@ L: [email protected] S: Maintained F: drivers/input/touchscreen/htcpen.c +HTE SUBSYSTEM +M: Dipen Patel <[email protected]> +S: Maintained +F: drivers/hte/ +F: include/linux/hte.h +F: Documentation/hte/ +F: Documentation/devicetree/bindings/hte/ + HTS221 TEMPERATURE-HUMIDITY IIO DRIVER M: Lorenzo Bianconi <[email protected]> L: [email protected]
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 9/10 hte: Add tegra HTE test driver
In reply to Dipen PatelThe test driver uses IRQ and GPIO lines to timestamp using HTE subsystem. The patch also adds compilation support in Kconfig and Makefile.
---
Changes in v6:
- Merged tegra irq and gpio HTE test drivers.
drivers/hte/Kconfig | 7 + drivers/hte/Makefile | 2 +- drivers/hte/hte-tegra194-test.c | 239 ++++++++++++++++++++++++++++++++ 3 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 drivers/hte/hte-tegra194-test.c
drivers/hte/Kconfig +7 -0
@@ -23,4 +23,11 @@ config HTE_TEGRA194 systems-on-chip. The driver supports 352 LIC IRQs and 39 AON GPIOs lines for timestamping in realtime. +config HTE_TEGRA194_TEST + tristate "NVIDIA Tegra194 HTE Test" + depends on HTE_TEGRA194 + help + The NVIDIA Tegra194 GTE test driver demonstrates how to use HTE + framework to timestamp GPIO and LIC IRQ lines. + endif
drivers/hte/Makefile +1 -1
@@ -1,3 +1,3 @@ obj-$(CONFIG_HTE) += hte.o obj-$(CONFIG_HTE_TEGRA194) += hte-tegra194.o - +obj-$(CONFIG_HTE_TEGRA194_TEST) += hte-tegra194-test.o
drivers/hte/hte-tegra194-test.c new file +239 -0
239 lines not on this page · raw message
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 2/10 drivers: Add hardware timestamp engine (HTE)
In reply to Dipen PatelSome devices can timestamp system lines/signals/Buses in real-time using the hardware counter or other hardware means which can give finer granularity and help avoid jitter introduced by software timestamping. To utilize such functionality, this patchset creates HTE subsystem where devices can register themselves as providers so that the consumers devices can request specific line from the providers. The patch also adds compilation support in Makefile and menu options in Kconfig.
The provider does following:
- Registers chip with the framework.
- Provides translation hook to convert logical line id.
- Provides enable/disable, request/release callbacks.
- Pushes timestamp data to HTE subsystem.
The consumer does following:
- Initializes line attribute.
- Gets HTE timestamp descriptor.
- Requests timestamp functionality.
- Puts HTE timestamp descriptor.
---
Changes in v2:
- Removed buffer abstraction layer as well related APIs, HTE now will not store any data, instead will pass to consumer as soon as it is available.
- Removed unnecessary dynamical allocations
- Removed timestamp retrieve API
- Removed release, unregister related APIs as their counterpart are resource managed.
- Added kernel thread implementation if consumer indicates threaded callback during request API time.
- Changed hte_req_ts_by_dt_node API to remove device node exposure from the interface, instead consumer will their device node with property name that indicates the provider it wants to use.
Changes in v3:
- Addressed grammatical/spelling errors.
Changes in v4:
- Added hte_req_ts_by_linedata_ns and removed hte_req_ts_by_hte_name.
- Corrected API descriptions based on review comments.
- Droped HTE_CB_ERROR and HTE_CB_TS_DROPPED enums.
- Added line attribute structure in hte ts descriptor.
- Added raw_level field in hte ts data structure.
- Added match_from_linedata callback for the providers.
- Added edge setup related flags should consumer requests, HTE now can help setup should provider supports it.
Changes in v5:
- Replaced kernel thread with workqueue.
Changes in v6:
- Added line attribute initializer.
- Added API to obtain HTE descriptor.
- Added request count helper API.
- Renamed existing APIs to reflect above changes.
drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/hte/Kconfig | 14 + drivers/hte/Makefile | 2 + drivers/hte/hte.c | 948 +++++++++++++++++++++++++++++++++++++++++++ include/linux/hte.h | 272 +++++++++++++ 6 files changed, 1239 insertions(+) create mode 100644 drivers/hte/Kconfig create mode 100644 drivers/hte/Makefile create mode 100644 drivers/hte/hte.c create mode 100644 include/linux/hte.h
drivers/Kconfig +2 -0
@@ -239,4 +239,6 @@ source "drivers/most/Kconfig" source "drivers/peci/Kconfig" +source "drivers/hte/Kconfig" + endmenu
drivers/Makefile +1 -0
@@ -188,3 +188,4 @@ obj-$(CONFIG_INTERCONNECT) += interconnect/ obj-$(CONFIG_COUNTER) += counter/ obj-$(CONFIG_MOST) += most/ obj-$(CONFIG_PECI) += peci/ +obj-$(CONFIG_HTE) += hte/
drivers/hte/Kconfig new file +14 -0
@@ -0,0 +1,14 @@ +# SPDX-License-Identifier: GPL-2.0-only +menuconfig HTE + bool "Hardware Timestamping Engine (HTE) Support" + help + Hardware Timestamping Engine (HTE) Support. + + Some devices provide a hardware timestamping engine which can + timestamp certain device lines/signals in realtime. It comes with a + benefit for the applications needing accurate timestamping event with + less jitter. This framework provides a generic interface to such HTE + providers and consumer devices. + + If unsure, say no. +
drivers/hte/Makefile new file +2 -0
@@ -0,0 +1,2 @@ +obj-$(CONFIG_HTE) += hte.o +
drivers/hte/hte.c new file +948 -0
948 lines not on this page · raw message
include/linux/hte.h new file +272 -0
272 lines not on this page · raw message
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 3/10 hte: Add tegra194 HTE kernel provider
In reply to Dipen PatelTegra194 device has multiple HTE instances also known as GTE (Generic hardware Timestamping Engine) which can timestamp subset of SoC lines/signals. This provider driver focuses on IRQ and GPIO lines and exposes timestamping ability on those lines to the consumers through HTE subsystem.
Also, with this patch, added:
- documentation about this provider and its capabilities at Documentation/hte.
- Compilation support in Makefile and Kconfig
---
Changes in v3:
- Addressed grammatical/spelling errors.
Changes in v4:
- Added gpio line level detection.
- Added edge setup for GPIO lines if requested.
- Added match_from_linedata callback to help hte_req_ts_by_linedata_ns HTE API.
Changes in v6:
- Added xlate_plat support.
- Added secondary mapping of the GPIO lines to GTE namespace.
Documentation/hte/index.rst | 22 + Documentation/hte/tegra194-hte.rst | 47 ++ Documentation/index.rst | 1 + drivers/hte/Kconfig | 12 + drivers/hte/Makefile | 1 + drivers/hte/hte-tegra194.c | 730 +++++++++++++++++++++++++++++ 6 files changed, 813 insertions(+) create mode 100644 Documentation/hte/index.rst create mode 100644 Documentation/hte/tegra194-hte.rst create mode 100644 drivers/hte/hte-tegra194.c
Documentation/hte/index.rst new file +22 -0
@@ -0,0 +1,22 @@ +.. SPDX-License-Identifier: GPL-2.0 + +============================================ +The Linux Hardware Timestamping Engine (HTE) +============================================ + +The HTE Subsystem +================= + +.. toctree:: + :maxdepth: 1 + + hte + +HTE Tegra Provider +================== + +.. toctree:: + :maxdepth: 1 + + tegra194-hte +
Documentation/hte/tegra194-hte.rst new file +47 -0
47 lines not on this page · raw message
Documentation/index.rst +1 -0
@@ -140,6 +140,7 @@ needed). mhi/index tty/index peci/index + hte/index Architecture-agnostic documentation -----------------------------------
drivers/hte/Kconfig +12 -0
@@ -12,3 +12,15 @@ menuconfig HTE If unsure, say no. +if HTE + +config HTE_TEGRA194 + tristate "NVIDIA Tegra194 HTE Support" + depends on ARCH_TEGRA_194_SOC + help + Enable this option for integrated hardware timestamping engine also + known as generic timestamping engine (GTE) support on NVIDIA Tegra194 + systems-on-chip. The driver supports 352 LIC IRQs and 39 AON GPIOs + lines for timestamping in realtime. + +endif
drivers/hte/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_HTE) += hte.o +obj-$(CONFIG_HTE_TEGRA194) += hte-tegra194.o
drivers/hte/hte-tegra194.c new file +730 -0
730 lines not on this page · raw message
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 4/10 dt-bindings: Add HTE bindings
In reply to Dipen PatelIntroduces HTE devicetree binding details for the HTE subsystem. It includes examples for the consumers, binding details for the providers and specific binding details for the Tegra194 based HTE providers.
---
Changes in v2:
- Replace hte with hardware-timestamp for property names
- Renamed file
- Removed example from the common dt binding file.
Changes in v3:
- Addressed grammatical errors.
- Removed double plural from the respective properties.
- Added dual license.
- Prefixed "nvidia" in nvidia specific properties.
Changes in v4:
- Corrected make dt_binding_check error.
Changes in v5:
- Addressed review comments.
Changes in v6:
- Removed hardware prefix from the property as per review comments.
.../hte/hardware-timestamps-common.yaml | 29 ++++++ .../devicetree/bindings/hte/hte-consumer.yaml | 39 ++++++++ .../bindings/hte/nvidia,tegra194-hte.yaml | 88 +++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml create mode 100644 Documentation/devicetree/bindings/hte/hte-consumer.yaml create mode 100644 Documentation/devicetree/bindings/hte/nvidia,tegra194-hte.yaml
Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml new file +29 -0
@@ -0,0 +1,29 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hte/hardware-timestamps-common.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Hardware timestamp providers + +maintainers: + - Dipen Patel <[email protected]> + +description: + Some devices/SoCs have hardware time stamping engines which can use hardware + means to timestamp entity in realtime. The entity could be anything from + GPIOs, IRQs, Bus and so on. The hardware timestamp engine (HTE) present + itself as a provider with the bindings described in this document. + +properties: + $nodename: + pattern: "^timestamp(@.*|-[0-9a-f])?$" + + "#timestamp-cells": + description: + Number of cells in a HTE specifier. + +required: + - "#timestamp-cells" + +additionalProperties: true
Documentation/devicetree/bindings/hte/hte-consumer.yaml new file +39 -0
@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hte/hte-consumer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HTE Consumer Device Tree Bindings + +maintainers: + - Dipen Patel <[email protected]> + +select: true + +properties: + timestamps: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + The list of HTE provider phandle. The first cell must represent the + provider phandle followed by the line identifiers. The meaning of the + line identifier and exact number of arguments must be specified in the + HTE provider device tree binding document. + + timestamp-names: + $ref: /schemas/types.yaml#/definitions/string-array + description: + An optional string property to label each line specifier present in the + timestamp property. + +dependencies: + timestamp-names: [ timestamps ] + +additionalProperties: true + +examples: + - | + hte_tegra_consumer { + timestamps = <&tegra_hte_aon 0x9>, <&tegra_hte_lic 0x19>; + timestamp-names = "hte-gpio", "hte-i2c"; + };
Documentation/devicetree/bindings/hte/nvidia,tegra194-hte.yaml new file +88 -0
88 lines not on this page · raw message
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 8/10 tools: gpio: Add new hardware clock type
In reply to Dipen Patelgpiolib-cdev is extended to support hardware clock type, this patch reflects that fact.
--- tools/gpio/gpio-event-mon.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
tools/gpio/gpio-event-mon.c +5 -1
@@ -149,6 +149,7 @@ void print_usage(void)" -r Listen for rising edges\n" " -f Listen for falling edges\n" " -w Report the wall-clock time for events\n" +" -t Report the hardware timestamp for events\n" " -b <n> Debounce the line with period n microseconds\n" " [-c <n>] Do <n> loops (optional, infinite loop if not stated)\n" " -? This helptext\n"
@@ -174,7 +175,7 @@ int main(int argc, char **argv)memset (&config,0 ,sizeof (config)); config.flags =GPIO_V2_LINE_FLAG_INPUT ; -while ((c =getopt (argc, argv,"c:n:o:b:dsrfw?" )) !=-1 ) { +while ((c =getopt (argc, argv,"c:n:o:b:dsrfwt?" )) !=-1 ) {switch (c) {case 'c' : loops =strtoul (optarg,NULL ,10 );
@@ -208,6 +209,9 @@ int main(int argc, char **argv)case 'w' : config.flags |=GPIO_V2_LINE_FLAG_EVENT_CLOCK_REALTIME ;break ; +case 't' : + config.flags |=GPIO_V2_LINE_FLAG_EVENT_CLOCK_HTE ; +break ;case '?' :print_usage ();return -1 ;
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 5/10 gpiolib: Add HTE support
In reply to Dipen PatelSome GPIO chip can provide hardware timestamp support on its GPIO lines , in order to support that, additional API needs to be added which can talk to both GPIO chip and HTE (hardware timestamping engine) providers if there is any dependencies. This patch introduces optional hooks to enable and disable hardware timestamping related features in the GPIO controller chip.
---
Changes in v2:
- removed get timestamp and is timestamp enabled APIs
Changes in v4:
- Removed gpiod_req_hw_timestamp_ns and gpiod_rel_hw_timestamp_ns APIs.
- Added callbacks for the GPIO driver to enable hardware timestamping functionality if supported which takes gpio desc and flags as arguments.
- Added APIs are called from GPIO provider rather than gpiolib-cdev framework.
drivers/gpio/gpiolib.c | 58 +++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib.h | 1 + include/linux/gpio/consumer.h | 16 ++++++++-- include/linux/gpio/driver.h | 10 ++++++ 4 files changed, 83 insertions(+), 2 deletions(-)
drivers/gpio/gpiolib.c +58 -0
@@ -2434,6 +2434,64 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) }EXPORT_SYMBOL_GPL (gpiod_direction_output); +/** +* gpiod_enable_hw_timestamp_ns - Enable hardware timestamp in nanoseconds. +* +* @desc: GPIO to enable. +* @flags: Flags related to GPIO edge. +* +* Return 0 in case of success, else negative error code. +*/ +int gpiod_enable_hw_timestamp_ns (struct gpio_desc *desc,unsigned long flags) +{ +int ret =0 ; +struct gpio_chip *gc; + +VALIDATE_DESC (desc); + + gc = desc->gdev->chip; +if (!gc->en_hw_timestamp) { +gpiod_warn (desc,"%s: hw ts not supported\n" , __func__); +return -ENOTSUPP ; + } + + ret = gc->en_hw_timestamp (gc,gpio_chip_hwgpio (desc), flags); +if (ret) +gpiod_warn (desc,"%s: hw ts request failed\n" , __func__); + +return ret; +} +EXPORT_SYMBOL_GPL (gpiod_enable_hw_timestamp_ns); + +/** +* gpiod_disable_hw_timestamp_ns - Disable hardware timestamp. +* +* @desc: GPIO to disable. +* @flags: Flags related to GPIO edge, same value as used during enable call. +* +* Return 0 in case of success, else negative error code. +*/ +int gpiod_disable_hw_timestamp_ns (struct gpio_desc *desc,unsigned long flags) +{ +int ret =0 ; +struct gpio_chip *gc; + +VALIDATE_DESC (desc); + + gc = desc->gdev->chip; +if (!gc->dis_hw_timestamp) { +gpiod_warn (desc,"%s: hw ts not supported\n" , __func__); +return -ENOTSUPP ; + } + + ret = gc->dis_hw_timestamp (gc,gpio_chip_hwgpio (desc), flags); +if (ret) +gpiod_warn (desc,"%s: hw ts release failed\n" , __func__); + +return ret; +} +EXPORT_SYMBOL_GPL (gpiod_disable_hw_timestamp_ns); +/** * gpiod_set_config - sets @config for a GPIO * @desc: descriptor of the GPIO for which to set the configuration
drivers/gpio/gpiolib.h +1 -0
@@ -158,6 +158,7 @@ struct gpio_desc {#define FLAG_EDGE_RISING 16/* GPIO CDEV detects rising edge events */ #define FLAG_EDGE_FALLING 17/* GPIO CDEV detects falling edge events */ #define FLAG_EVENT_CLOCK_REALTIME 18/* GPIO CDEV reports REALTIME timestamps in events */ +#define FLAG_EVENT_CLOCK_HTE 19/* GPIO CDEV reports hardware timestamps in events */ /* Connection label */ const char *label;
include/linux/gpio/consumer.h +14 -2
@@ -109,6 +109,8 @@ int gpiod_get_direction(struct gpio_desc *desc);int gpiod_direction_input (struct gpio_desc *desc);int gpiod_direction_output (struct gpio_desc *desc,int value);int gpiod_direction_output_raw (struct gpio_desc *desc,int value); +int gpiod_enable_hw_timestamp_ns (struct gpio_desc *desc,unsigned long flags); +int gpiod_disable_hw_timestamp_ns (struct gpio_desc *desc,unsigned long flags);/* Value get/set from non-sleeping context */ int gpiod_get_value (const struct gpio_desc *desc);
@@ -350,8 +352,18 @@ static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)WARN_ON (desc);return -ENOSYS ; } - - +static inline int gpiod_enable_hw_timestamp_ns (struct gpio_desc *desc, +unsigned long flags) +{ +WARN_ON (desc); +return -ENOSYS ; +} +static inline int gpiod_disable_hw_timestamp_ns (struct gpio_desc *desc, +unsigned long flags) +{ +WARN_ON (desc); +return -ENOSYS ; +}static inline int gpiod_get_value (const struct gpio_desc *desc) {/* GPIO can never have been requested */
include/linux/gpio/driver.h +10 -0
@@ -320,6 +320,10 @@ struct gpio_irq_chip {* @add_pin_ranges: optional routine to initialize pin ranges, to be used when * requires special mapping of the pins that provides GPIO functionality. * It is called after adding GPIO chip and before adding IRQ chip. +* @en_hw_timestamp: Dependent on GPIO chip, an optional routine to +* enable hardware timestamp. +* @dis_hw_timestamp: Dependent on GPIO chip, an optional routine to +* disable hardware timestamp. * @base: identifies the first GPIO number handled by this chip; * or, if negative during registration, requests dynamic ID allocation. * DEPRECATION: providing anything non-negative and nailing the base
@@ -416,6 +420,12 @@ struct gpio_chip {int (*add_pin_ranges)(struct gpio_chip *gc); +int (*en_hw_timestamp)(struct gpio_chip *gc, +u32 offset, +unsigned long flags); +int (*dis_hw_timestamp)(struct gpio_chip *gc, +u32 offset, +unsigned long flags);int base;u16 ngpio;u16 offset;
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 6/10 gpio: tegra186: Add HTE in gpio-tegra186 driver
In reply to Dipen PatelTegra194 AON GPIO controller with the use of its internal hardware timestamping engine (HTE) also known as GTE can timestamp GPIO lines through system counter. This patch implements enable/disable callbacks for the GPIO controller. In enable call, it will set timestamp function bit and GPIO line rising/falling edges in the config register. In disable call, it restores the state.
---
Changes in v4:
- Added edge setup and hardware timestamping enable/disable APIs.
drivers/gpio/gpio-tegra186.c | 81 +++++++++++++++++++++++++++++++++++- 1 file changed, 80 insertions(+), 1 deletion(-)
drivers/gpio/gpio-tegra186.c +80 -1
@@ -1,8 +1,9 @@// SPDX-License-Identifier: GPL-2.0-only /* -* Copyright (c) 2016-2017 NVIDIA Corporation +* Copyright (c) 2016-2022 NVIDIA Corporation * * Author: Thierry Reding <[email protected]> +* Dipen Patel <[email protected]> */ #include <linux/gpio/driver.h>
@@ -11,6 +12,7 @@#include <linux/module.h> #include <linux/of_device.h> #include <linux/platform_device.h> +#include <linux/hte.h> #include <dt-bindings/gpio/tegra186-gpio.h> #include <dt-bindings/gpio/tegra194-gpio.h>
@@ -36,6 +38,7 @@#define TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL BIT(4)#define TEGRA186_GPIO_ENABLE_CONFIG_DEBOUNCE BIT(5)#define TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT BIT(6) +#define TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC BIT(7)#define TEGRA186_GPIO_DEBOUNCE_CONTROL 0x04#define TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD (x) ((x) & 0xff)
@@ -76,6 +79,7 @@ struct tegra_gpio_soc {const struct tegra186_pin_range *pin_ranges;unsigned int num_pin_ranges;const char *pinmux; +bool has_gte; };struct tegra_gpio {
@@ -194,6 +198,76 @@ static int tegra186_gpio_direction_output(struct gpio_chip *chip,return 0 ; } +#define HTE_BOTH_EDGES (HTE_RISING_EDGE_TS | HTE_FALLING_EDGE_TS) + +static int tegra186_gpio_en_hw_ts (struct gpio_chip *gc,u32 offset, +unsigned long flags) +{ +struct tegra_gpio *gpio; +void __iomem *base; +int value; + +if (!gc) +return -EINVAL ; + + gpio =gpiochip_get_data (gc); +if (!gpio) +return -ENODEV ; + + base =tegra186_gpio_get_base (gpio, offset); +if (WARN_ON (base ==NULL )) +return -EINVAL ; + + value =readl (base +TEGRA186_GPIO_ENABLE_CONFIG ); + value |=TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC ; + +if (flags ==HTE_BOTH_EDGES ) { + value |=TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE ; + }else if (flags ==HTE_RISING_EDGE_TS ) { + value |=TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE ; + value |=TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL ; + }else if (flags ==HTE_FALLING_EDGE_TS ) { + value |=TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE ; + } + +writel (value, base +TEGRA186_GPIO_ENABLE_CONFIG ); + +return 0 ; +} + +static int tegra186_gpio_dis_hw_ts (struct gpio_chip *gc,u32 offset, +unsigned long flags) +{ +struct tegra_gpio *gpio; +void __iomem *base; +int value; + +if (!gc) +return -EINVAL ; + + gpio =gpiochip_get_data (gc); +if (!gpio) +return -ENODEV ; + + base =tegra186_gpio_get_base (gpio, offset); +if (WARN_ON (base ==NULL )) +return -EINVAL ; + + value =readl (base +TEGRA186_GPIO_ENABLE_CONFIG ); + value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TIMESTAMP_FUNC ; +if (flags ==HTE_BOTH_EDGES ) { + value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE ; + }else if (flags ==HTE_RISING_EDGE_TS ) { + value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE ; + value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL ; + }else if (flags ==HTE_FALLING_EDGE_TS ) { + value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE ; + } +writel (value, base +TEGRA186_GPIO_ENABLE_CONFIG ); + +return 0 ; +} +static int tegra186_gpio_get (struct gpio_chip *chip,unsigned int offset) {struct tegra_gpio *gpio =gpiochip_get_data (chip);
@@ -726,6 +800,10 @@ static int tegra186_gpio_probe(struct platform_device *pdev) gpio->gpio.set = tegra186_gpio_set; gpio->gpio.set_config = tegra186_gpio_set_config; gpio->gpio.add_pin_ranges = tegra186_gpio_add_pin_ranges; +if (gpio->soc->has_gte) { + gpio->gpio.en_hw_timestamp = tegra186_gpio_en_hw_ts; + gpio->gpio.dis_hw_timestamp = tegra186_gpio_dis_hw_ts; + } gpio->gpio.base =-1 ;
@@ -977,6 +1055,7 @@ static const struct tegra_gpio_soc tegra194_aon_soc = { .name = "tegra194-gpio-aon", .instance = 1, .num_irqs_per_bank = 8, + .has_gte = true, };#define TEGRA234_MAIN_GPIO_PORT (_name, _bank, _port, _pins) \
Signature · 1 line
2.17.1
Dipen Patel
maintainerPATCH v6 1/10 Documentation: Add HTE subsystem guide
In reply to Dipen PatelAdding hte document which can help understand various APIs implemented in HTE framework for the HTE producers and the consumers.
---
Changes in v2:
- Removed explanation, instead added kernel-doc references.
Changes in v3:
- Addressed grammatical errors.
Changes in v4:
- Added new API hte_req_ts_by_linedata_ns description.
- Removed hte_req_ts_by_hte_name.
Changes in v6:
- Added hte_init_line_attr, hte_ts_get, of_hte_req_count.
- Removed devm_of_hte_request_ts_ns, hte_req_ts_by_linedata_ns, hte_release_ts.
- Replaced above with devm_hte_request_ts_ns, hte_request_ts_ns, hte_ts_put.
- Addressed review comments.
Documentation/hte/hte.rst | 77 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Documentation/hte/hte.rst
Documentation/hte/hte.rst new file +77 -0
@@ -0,0 +1,77 @@ +============================================ +The Linux Hardware Timestamping Engine (HTE) +============================================ + +:Author: Dipen Patel + +Introduction +------------ + +Certain devices have built in hardware timestamping engines which can +monitor sets of system signals, lines, buses etc... in realtime for state +change; upon detecting the change they can automatically store the timestamp at +the moment of occurrence. Such functionality may help achieve better accuracy +in obtaining timestamps than using software counterparts i.e. ktime and +friends. + +This document describes the API that can be used by hardware timestamping +engine provider and consumer drivers that want to use the hardware timestamping +engine (HTE) framework. Both consumers and providers must include +``#include <linux/hte.h>``. + +The HTE framework APIs for the providers +---------------------------------------- + +.. kernel-doc:: drivers/hte/hte.c + :functions: devm_hte_register_chip hte_push_ts_ns + +The HTE framework APIs for the consumers +---------------------------------------- + +.. kernel-doc:: drivers/hte/hte.c + :functions: hte_init_line_attr hte_ts_get hte_ts_put devm_hte_request_ts_ns hte_request_ts_ns hte_enable_ts hte_disable_ts of_hte_req_count hte_get_clk_src_info + +The HTE framework public structures +----------------------------------- +.. kernel-doc:: include/linux/hte.h + +More on the HTE timestamp data +------------------------------ +The ``struct hte_ts_data`` is used to pass timestamp details between the +consumers and the providers. It expresses timestamp data in nanoseconds in +u64. An example of the typical timestamp data life cycle, for the GPIO line is +as follows:: + + - Monitors GPIO line change. + - Detects the state change on GPIO line. + - Converts timestamps in nanoseconds. + - Stores GPIO raw level in raw_level variable if the provider has that + hardware capability. + - Pushes this hte_ts_data object to HTE subsystem. + - HTE subsystem increments seq counter and invokes consumer provided callback. + Based on callback return value, the HTE core invokes secondary callback in + the thread context. + +HTE subsystem debugfs attributes +-------------------------------- +HTE subsystem creates debugfs attributes at ``/sys/kernel/debug/hte/``. +It also creates line/signal-related debugfs attributes at +``/sys/kernel/debug/hte/<provider>/<label or line id>/``. Note that these +attributes are read-only. + +`ts_requested` + The total number of entities requested from the given provider, + where entity is specified by the provider and could represent + lines, GPIO, chip signals, buses etc... + The attribute will be available at + ``/sys/kernel/debug/hte/<provider>/``. + +`total_ts` + The total number of entities supported by the provider. + The attribute will be available at + ``/sys/kernel/debug/hte/<provider>/``. + +`dropped_timestamps` + The dropped timestamps for a given line. + The attribute will be available at + ``/sys/kernel/debug/hte/<provider>/<label or line id>/``.
Signature · 1 line
2.17.1
Dipen Patel
maintainerv6 cover Intro to Hardware timestamping engine
This patch series introduces new subsystem called hardware timestamping engine (HTE). It offers functionality such as timestamping through hardware means in realtime. The HTE subsystem centralizes HTE provider and consumers where providers can register themselves and the consumers can request interested entity which could be lines, GPIO, signals or buses. The HTE subsystem provides timestamp in nano seconds, having said that the provider need to convert the timestamp if its not in that unit. There was upstream discussion about the HTE at
https://lore.kernel.org/lkml/[email protected]/
To summarize upstream discussion:
- It was suggested by Linus and Kent to extend GPIOLIB and supporting GPIO drivers to add HTE functionality and I agreed to experiment with it. This patch series implements and extends GPIOLIB, GPIOLIB-CDEV and GPIO tegra driver.
- Discussed possibility to add HTE provider as irqchip instead which was argued against as HTE devices are not necessarily event emitting devices. From RFC version 2 however, emulated threaded irq style implementation.
- Discussed other possibility if HTE device can be added as posix clock type like PTP clocks. That was argued against since HTE devices are not necessarily tightly coupled with hardware clock.
Typical HTE provider does following:
- Register itself with HTE subsystem
- Provide request, release, enable, disable timestamp and
clock source info callbacks to HTE subsystem.
- Provide optional xlate callback to the subsystem which can translate consumer provided logical ids into actual ids of the entity, where entity here is the provider dependent and could be GPIO, in chip lines or signals, buses etc...This converted id is used as communication token between HTE subsystem and the provider.
- Push timestamps to the subsystem.
- Unregister itself on exit.
Typical HTE consumer does following:
- Initializes line attributes.
- Obtains HTE descriptor.
- Request interested entity it wishes to timestamp in realtime to the subsystem.
- The subsystem does necessary communications with the provider to complete the request, which includes translating logical id of the entity to provider dependent physical/actual id and enabling hardware timestamping on requested id.
- The request includes callbacks, it will be used to push timestamps. Optionally, the consumer can provided threaded callback, if specified, the HTE subsystem uses workqueue executing the secondary callback.
- Release entity and its resources.
HTE and GPIOLIB:
- For the HTE provider which can timestamp GPIO lines.
- For the userspace GPIO consumers, the GPIOLIB CDEV framework are extended as a frontend to the HTE. The kernel space consumers request GPIO lines directly to HTE subsystem.
- Tegra194 AON GPIO controller has HTE support known as GTE (Generic Timestamping Engine). The tegra gpio driver is modified to accommodate HTE functionality.
Changes in V2:
- Removed buffer management and related APIs from the HTE core.
- Removed timestamp retrieve APIs from the HTE core.
- Modified request API with two callbacks, second callback is invoked in thread context and is optional, while first callback is mandatory and used to push timestamp data to consumers.
- Replaced hte with hardware-timestamping in DT bindings as hte appeared too short according to review comments.
Changes in V3:
- Corrected grammatical errors in HTE documentation and its bindings documents.
- Removed multi-plural words in the HTE DT bindings.
- Reflected changes done in DT bindings in the respective source codes.
- Separated previous patch 07 into two patches in this series as 07 and 08.
- Corrections in MAINTAINERS file.
Changes in V4:
- Removed hardware-timestamp-engine device tree property from gpio.txt.
- Added hte_req_ts_by_linedata_ns.
- Removed hte_req_ts_by_hte_name.
- Renamed devm_of_hte_request_ts to devm_of_hte_request_ts_ns.
- Corrected hte ts seqeunce counter handling in hte related code in gpiolib-cdev code.
- Added line level detection in Tegra GPIO HTE provider.
- Corrected GPIO line level calculation in gpiolib-cdev.
Changes in V5:
- Minor changes in dt-bindings.
- Removed kernel thread in the HTE core.
Changes in V6:
- Changes in dt-bindings.
- Added APIs in HTE core.
- Merged tegra HTE test drivers.
There are patches pending to add HTE provider for another Nvidia Tegra chip which will be pushed after this patch set.
Dipen Patel (10):
Documentation: Add HTE subsystem guide
drivers: Add hardware timestamp engine (HTE)
hte: Add tegra194 HTE kernel provider
dt-bindings: Add HTE bindings
gpiolib: Add HTE support
gpio: tegra186: Add HTE in gpio-tegra186 driver
gpiolib: cdev: Add hardware timestamp clock type
tools: gpio: Add new hardware clock type
hte: Add tegra HTE test driver
MAINTAINERS: Added HTE Subsystem
.../hte/hardware-timestamps-common.yaml | 29 + .../devicetree/bindings/hte/hte-consumer.yaml | 39 + .../bindings/hte/nvidia,tegra194-hte.yaml | 88 ++ Documentation/hte/hte.rst | 77 ++ Documentation/hte/index.rst | 22 + Documentation/hte/tegra194-hte.rst | 47 + Documentation/index.rst | 1 + MAINTAINERS | 8 + drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/gpio/gpio-tegra186.c | 81 +- drivers/gpio/gpiolib-cdev.c | 252 ++++- drivers/gpio/gpiolib.c | 58 ++ drivers/gpio/gpiolib.h | 1 + drivers/hte/Kconfig | 33 + drivers/hte/Makefile | 3 + drivers/hte/hte-tegra194-test.c | 239 +++++ drivers/hte/hte-tegra194.c | 730 ++++++++++++++ drivers/hte/hte.c | 948 ++++++++++++++++++ include/linux/gpio/consumer.h | 16 +- include/linux/gpio/driver.h | 10 + include/linux/hte.h | 272 +++++ include/uapi/linux/gpio.h | 3 + tools/gpio/gpio-event-mon.c | 6 +- 24 files changed, 2929 insertions(+), 37 deletions(-) create mode 100644 Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml create mode 100644 Documentation/devicetree/bindings/hte/hte-consumer.yaml create mode 100644 Documentation/devicetree/bindings/hte/nvidia,tegra194-hte.yaml create mode 100644 Documentation/hte/hte.rst create mode 100644 Documentation/hte/index.rst create mode 100644 Documentation/hte/tegra194-hte.rst create mode 100644 drivers/hte/Kconfig create mode 100644 drivers/hte/Makefile create mode 100644 drivers/hte/hte-tegra194-test.c create mode 100644 drivers/hte/hte-tegra194.c create mode 100644 drivers/hte/hte.c create mode 100644 include/linux/hte.h
base-commit: c2528a0cdebd8ba7ef30e0655f8ea89f34c3a633
Signature · 1 line
2.17.1
Rob Herring
maintainerRe: [PATCH v6 04/10] dt-bindings: Add HTE bindings
In reply to Dipen PatelQuoted 27 lines · Dipen Patel
Introduces HTE devicetree binding details for the HTE subsystem. It includes examples for the consumers, binding details for the providers and specific binding details for the Tegra194 based HTE providers.
Signed-off-by Dipen Patel <[email protected]>Reviewed-by Linus Walleij <[email protected]>---
Changes in v2:
- Replace hte with hardware-timestamp for property names
- Renamed file
- Removed example from the common dt binding file.Changes in v3:
- Addressed grammatical errors.
- Removed double plural from the respective properties.
- Added dual license.
- Prefixed "nvidia" in nvidia specific properties.Changes in v4:
- Corrected makedt_binding_checkerror.Changes in v5:
- Addressed review comments.Changes in v6:
- Removed hardware prefix from the property as per review comments.
Quoted 7 lines
.../hte/hardware-timestamps-common.yaml | 29 ++++++ .../devicetree/bindings/hte/hte-consumer.yaml | 39 ++++++++ .../bindings/hte/nvidia,tegra194-hte.yaml | 88 +++++++++++++++++++ 3 files changed, 156 insertions(+) create mode 100644 Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml create mode 100644 Documentation/devicetree/bindings/hte/hte-consumer.yaml create mode 100644 Documentation/devicetree/bindings/hte/nvidia,tegra194-hte.yaml
'hte' is not obvious what it is, so 'timestamp' for the directory name.
Quoted 12 lines
Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml new file +5
-0@@ -0,0 +1,29 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hte/hardware-timestamps-common.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml#
Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml line 15
Quoted 10 lines
Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml new file +10
-0+ +title: Hardware timestamp providers + +maintainers: + - Dipen Patel <[email protected]> + +description: + Some devices/SoCs have hardware time stamping engines which can use hardware + means to timestamp entity in realtime. The entity could be anything from + GPIOs, IRQs, Bus and so on. The hardware timestamp engine (HTE) present
Define HTE at the 1st use, not the 2nd.
Quoted 157 lines
Documentation/devicetree/bindings/hte/hardware-timestamps-common.yaml new file +14
-0+ itself as a provider with the bindings described in this document. + +properties: + $nodename: + pattern: "^timestamp(@.*|-[0-9a-f])?$" + + "#timestamp-cells": + description: + Number of cells in a HTE specifier. + +required: + - "#timestamp-cells" + +additionalProperties: trueDocumentation/devicetree/bindings/hte/hte-consumer.yaml new file +39
-0@@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hte/hte-consumer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: HTE Consumer Device Tree Bindings + +maintainers: + - Dipen Patel <[email protected]> + +select: true + +properties: + timestamps: + $ref: /schemas/types.yaml#/definitions/phandle-array + description: + The list of HTE provider phandle. The first cell must represent the + provider phandle followed by the line identifiers. The meaning of the + line identifier and exact number of arguments must be specified in the + HTE provider device tree binding document. + + timestamp-names: + $ref: /schemas/types.yaml#/definitions/string-array + description: + An optional string property to label each line specifier present in the + timestamp property. + +dependencies: + timestamp-names: [ timestamps ] + +additionalProperties: true + +examples: + - | + hte_tegra_consumer { + timestamps = <&tegra_hte_aon 0x9>, <&tegra_hte_lic 0x19>; + timestamp-names = "hte-gpio", "hte-i2c"; + };Documentation/devicetree/bindings/hte/nvidia,tegra194-hte.yaml new file +88
-0@@ -0,0 +1,88 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/hte/nvidia,tegra194-hte.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Tegra194 on chip generic hardware timestamping engine (HTE) + +maintainers: + - Dipen Patel <[email protected]> + +description: + Tegra SoC has two instances of generic hardware timestamping engines (GTE) + known as GTE GPIO and GTE IRQ, which can monitor subset of GPIO and on chip + IRQ lines for the state change respectively, upon detection it will record + timestamp (taken from system counter) in its internal hardware FIFO. It has + a bitmap array arranged in 32bit slices where each bit represent signal/line + to enable or disable for the hardware timestamping. The GTE GPIO monitors + GPIO lines from the AON (always on) GPIO controller. + +properties: + compatible: + enum: + - nvidia,tegra194-gte-aon + - nvidia,tegra194-gte-lic + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + nvidia,int-threshold: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + HTE device generates its interrupt based on this u32 FIFO threshold + value. The recommended value is 1. + minimum: 1 + maximum: 256 + + nvidia,slices: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + HTE lines are arranged in 32 bit slice where each bit represents different + line/signal that it can enable/configure for the timestamp. It is u32 + property and depends on the HTE instance in the chip. The value 3 is for + GPIO GTE and 11 for IRQ GTE. + enum: [3, 11] + + '#timestamp-cells': + description: + This represents number of line id arguments as specified by the + consumers. For the GTE IRQ, this is IRQ number as mentioned in the + SoC technical reference manual. For the GTE GPIO, its value is same as + mentioned in the nvidia GPIO device tree binding document. + const: 1 + +required: + - compatible + - reg + - interrupts + - nvidia,slices + - "#timestamp-cells" + +additionalProperties: false + +examples: + - | + tegra_hte_aon: timestamp@c1e0000 { + compatible = "nvidia,tegra194-gte-aon"; + reg = <0xc1e0000 0x10000>; + interrupts = <0 13 0x4>; + nvidia,int-threshold = <1>; + nvidia,slices = <3>; + #timestamp-cells = <1>; + }; + + - | + tegra_hte_lic: timestamp@3aa0000 { + compatible = "nvidia,tegra194-gte-lic"; + reg = <0x3aa0000 0x10000>; + interrupts = <0 11 0x4>; + nvidia,int-threshold = <1>; + nvidia,slices = <11>; + #timestamp-cells = <1>; + }; + +...Signature · 1 line
2.17.1