drivers/hte/hte-tegra194-test.c
Source file repositories/reference/linux-study-clean/drivers/hte/hte-tegra194-test.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/hte/hte-tegra194-test.c- Extension
.c- Size
- 5931 bytes
- Lines
- 240
- Domain
- Driver Families
- Bucket
- drivers/hte
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/err.hlinux/gpio/consumer.hlinux/hte.hlinux/interrupt.hlinux/mod_devicetable.hlinux/module.hlinux/platform_device.hlinux/timer.hlinux/workqueue.h
Detected Declarations
function process_hw_tsfunction gpio_timer_cbfunction tegra_hte_test_gpio_isrfunction tegra_hte_test_probefunction tegra_hte_test_remove
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (c) 2021-2022 NVIDIA Corporation
*
* Author: Dipen Patel <dipenp@nvidia.com>
*/
#include <linux/err.h>
#include <linux/gpio/consumer.h>
#include <linux/hte.h>
#include <linux/interrupt.h>
#include <linux/mod_devicetable.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/timer.h>
#include <linux/workqueue.h>
/*
* This sample HTE test driver demonstrates HTE API usage by enabling
* hardware timestamp on gpio_in and specified LIC IRQ lines.
*
* Note: gpio_out and gpio_in need to be shorted externally in order for this
* test driver to work for the GPIO monitoring. The test driver has been
* tested on Jetson AGX Xavier platform by shorting pin 32 and 16 on 40 pin
* header.
*
* Device tree snippet to activate this driver:
* tegra_hte_test {
* compatible = "nvidia,tegra194-hte-test";
* in-gpio = <&gpio_aon TEGRA194_AON_GPIO(BB, 1)>;
* out-gpio = <&gpio_aon TEGRA194_AON_GPIO(BB, 0)>;
* timestamps = <&tegra_hte_aon TEGRA194_AON_GPIO(BB, 1)>,
* <&tegra_hte_lic 0x19>;
* timestamp-names = "hte-gpio", "hte-i2c-irq";
* status = "okay";
* };
*
* How to run test driver:
* - Load test driver.
* - For the GPIO, at regular interval gpio_out pin toggles triggering
* HTE for rising edge on gpio_in pin.
*
* - For the LIC IRQ line, it uses 0x19 interrupt which is i2c controller 1.
* - Run i2cdetect -y 1 1>/dev/null, this command will generate i2c bus
* transactions which creates timestamp data.
* - It prints below message for both the lines.
* HW timestamp(<line id>:<ts seq number>): <timestamp>, edge: <edge>.
* - Unloading the driver disables and deallocate the HTE.
*/
static struct tegra_hte_test {
int gpio_in_irq;
struct device *pdev;
struct gpio_desc *gpio_in;
struct gpio_desc *gpio_out;
struct hte_ts_desc *desc;
struct timer_list timer;
struct kobject *kobj;
} hte;
static enum hte_return process_hw_ts(struct hte_ts_data *ts, void *p)
{
char *edge;
struct hte_ts_desc *desc = p;
if (!ts || !p)
return HTE_CB_HANDLED;
if (ts->raw_level < 0)
edge = "Unknown";
pr_info("HW timestamp(%u: %llu): %llu, edge: %s\n",
desc->attr.line_id, ts->seq, ts->tsc,
(ts->raw_level >= 0) ? ((ts->raw_level == 0) ?
"falling" : "rising") : edge);
return HTE_CB_HANDLED;
}
static void gpio_timer_cb(struct timer_list *t)
{
(void)t;
gpiod_set_value(hte.gpio_out, !gpiod_get_value(hte.gpio_out));
mod_timer(&hte.timer, jiffies + msecs_to_jiffies(8000));
}
static irqreturn_t tegra_hte_test_gpio_isr(int irq, void *data)
{
(void)irq;
Annotation
- Immediate include surface: `linux/err.h`, `linux/gpio/consumer.h`, `linux/hte.h`, `linux/interrupt.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_device.h`, `linux/timer.h`.
- Detected declarations: `function process_hw_ts`, `function gpio_timer_cb`, `function tegra_hte_test_gpio_isr`, `function tegra_hte_test_probe`, `function tegra_hte_test_remove`.
- Atlas domain: Driver Families / drivers/hte.
- Implementation status: source implementation candidate.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.