drivers/media/test-drivers/vivid/vivid-kthread-touch.c
Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vivid/vivid-kthread-touch.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/test-drivers/vivid/vivid-kthread-touch.c- Extension
.c- Size
- 5724 bytes
- Lines
- 197
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/freezer.hlinux/jiffies.hvivid-core.hvivid-kthread-touch.hvivid-touch-cap.h
Detected Declarations
function vivid_thread_tch_cap_tickfunction vivid_thread_touch_capfunction vivid_start_generating_touch_capfunction vivid_stop_generating_touch_cap
Annotated Snippet
if (!mutex_trylock(&dev->mutex)) {
schedule();
continue;
}
cur_jiffies = jiffies;
if (dev->touch_cap_seq_resync) {
dev->jiffies_touch_cap = cur_jiffies;
dev->touch_cap_seq_offset = dev->touch_cap_seq_count + 1;
dev->touch_cap_seq_count = 0;
dev->cap_seq_resync = false;
}
denominator = dev->timeperframe_tch_cap.denominator;
numerator = dev->timeperframe_tch_cap.numerator;
/* Calculate the number of jiffies since we started streaming */
jiffies_since_start = cur_jiffies - dev->jiffies_touch_cap;
/* Get the number of buffers streamed since the start */
buffers_since_start = (u64)jiffies_since_start * denominator +
(HZ * numerator) / 2;
do_div(buffers_since_start, HZ * numerator);
/*
* After more than 0xf0000000 (rounded down to a multiple of
* 'jiffies-per-day' to ease jiffies_to_msecs calculation)
* jiffies have passed since we started streaming reset the
* counters and keep track of the sequence offset.
*/
if (jiffies_since_start > JIFFIES_RESYNC) {
dev->jiffies_touch_cap = cur_jiffies;
dev->cap_seq_offset = buffers_since_start;
buffers_since_start = 0;
}
dropped_bufs = buffers_since_start + dev->touch_cap_seq_offset - dev->touch_cap_seq_count;
dev->touch_cap_seq_count = buffers_since_start + dev->touch_cap_seq_offset;
dev->touch_cap_with_seq_wrap_count =
dev->touch_cap_seq_count - dev->touch_cap_seq_start;
vivid_thread_tch_cap_tick(dev, dropped_bufs);
/*
* Calculate the number of 'numerators' streamed
* since we started, including the current buffer.
*/
numerators_since_start = ++buffers_since_start * numerator;
/* And the number of jiffies since we started */
jiffies_since_start = jiffies - dev->jiffies_touch_cap;
mutex_unlock(&dev->mutex);
/*
* Calculate when that next buffer is supposed to start
* in jiffies since we started streaming.
*/
next_jiffies_since_start = numerators_since_start * HZ +
denominator / 2;
do_div(next_jiffies_since_start, denominator);
/* If it is in the past, then just schedule asap */
if (next_jiffies_since_start < jiffies_since_start)
next_jiffies_since_start = jiffies_since_start;
wait_jiffies = next_jiffies_since_start - jiffies_since_start;
if (!time_is_after_jiffies(cur_jiffies + wait_jiffies))
continue;
wait_queue_head_t wait;
init_waitqueue_head(&wait);
wait_event_interruptible_timeout(wait, kthread_should_stop(),
cur_jiffies + wait_jiffies - jiffies);
}
dprintk(dev, 1, "Touch Capture Thread End\n");
return 0;
}
int vivid_start_generating_touch_cap(struct vivid_dev *dev)
{
if (dev->kthread_touch_cap) {
dev->touch_cap_streaming = true;
return 0;
}
dev->touch_cap_seq_start = dev->seq_wrap * 128;
dev->kthread_touch_cap = kthread_run(vivid_thread_touch_cap, dev,
"%s-tch-cap", dev->v4l2_dev.name);
if (IS_ERR(dev->kthread_touch_cap)) {
int err = PTR_ERR(dev->kthread_touch_cap);
dev->kthread_touch_cap = NULL;
Annotation
- Immediate include surface: `linux/freezer.h`, `linux/jiffies.h`, `vivid-core.h`, `vivid-kthread-touch.h`, `vivid-touch-cap.h`.
- Detected declarations: `function vivid_thread_tch_cap_tick`, `function vivid_thread_touch_cap`, `function vivid_start_generating_touch_cap`, `function vivid_stop_generating_touch_cap`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.