drivers/media/test-drivers/vivid/vivid-vbi-gen.c
Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vivid/vivid-vbi-gen.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/test-drivers/vivid/vivid-vbi-gen.c- Extension
.c- Size
- 8099 bytes
- Lines
- 307
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/errno.hlinux/kernel.hlinux/ktime.hlinux/string.hlinux/videodev2.hvivid-vbi-gen.h
Detected Declarations
function wss_insertfunction vivid_vbi_gen_wss_rawfunction vivid_vbi_gen_teletext_rawfunction cc_insertfunction vivid_vbi_gen_cc_rawfunction vivid_vbi_gen_rawfunction calc_parityfunction vivid_vbi_gen_set_time_of_dayfunction vivid_vbi_gen_teletextfunction vivid_vbi_gen_sliced
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0-only
/*
* vivid-vbi-gen.c - vbi generator support functions.
*
* Copyright 2014 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
*/
#include <linux/bitops.h>
#include <linux/errno.h>
#include <linux/kernel.h>
#include <linux/ktime.h>
#include <linux/string.h>
#include <linux/videodev2.h>
#include "vivid-vbi-gen.h"
static void wss_insert(u8 *wss, u32 val, unsigned size)
{
while (size--)
*wss++ = (val & (1 << size)) ? 0xc0 : 0x10;
}
static void vivid_vbi_gen_wss_raw(const struct v4l2_sliced_vbi_data *data,
u8 *buf, unsigned sampling_rate)
{
const unsigned rate = 5000000; /* WSS has a 5 MHz transmission rate */
u8 wss[29 + 24 + 24 + 24 + 18 + 18] = { 0 };
const unsigned zero = 0x07;
const unsigned one = 0x38;
unsigned bit = 0;
u16 wss_data;
int i;
wss_insert(wss + bit, 0x1f1c71c7, 29); bit += 29;
wss_insert(wss + bit, 0x1e3c1f, 24); bit += 24;
wss_data = (data->data[1] << 8) | data->data[0];
for (i = 0; i <= 13; i++, bit += 6)
wss_insert(wss + bit, (wss_data & (1 << i)) ? one : zero, 6);
for (i = 0, bit = 0; bit < sizeof(wss); bit++) {
unsigned n = ((bit + 1) * sampling_rate) / rate;
while (i < n)
buf[i++] = wss[bit];
}
}
static void vivid_vbi_gen_teletext_raw(const struct v4l2_sliced_vbi_data *data,
u8 *buf, unsigned sampling_rate)
{
const unsigned rate = 6937500 / 10; /* Teletext has a 6.9375 MHz transmission rate */
u8 teletext[45] = { 0x55, 0x55, 0x27 };
unsigned bit = 0;
int i;
memcpy(teletext + 3, data->data, sizeof(teletext) - 3);
/* prevents 32 bit overflow */
sampling_rate /= 10;
for (i = 0, bit = 0; bit < sizeof(teletext) * 8; bit++) {
unsigned n = ((bit + 1) * sampling_rate) / rate;
u8 val = (teletext[bit / 8] & (1 << (bit & 7))) ? 0xc0 : 0x10;
while (i < n)
buf[i++] = val;
}
}
static void cc_insert(u8 *cc, u8 ch)
{
unsigned tot = 0;
unsigned i;
for (i = 0; i < 7; i++) {
cc[2 * i] = cc[2 * i + 1] = (ch & (1 << i)) ? 1 : 0;
tot += cc[2 * i];
}
cc[14] = cc[15] = !(tot & 1);
}
#define CC_PREAMBLE_BITS (14 + 4 + 2)
static void vivid_vbi_gen_cc_raw(const struct v4l2_sliced_vbi_data *data,
u8 *buf, unsigned sampling_rate)
{
const unsigned rate = 1000000; /* CC has a 1 MHz transmission rate */
u8 cc[CC_PREAMBLE_BITS + 2 * 16] = {
/* Clock run-in: 7 cycles */
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/errno.h`, `linux/kernel.h`, `linux/ktime.h`, `linux/string.h`, `linux/videodev2.h`, `vivid-vbi-gen.h`.
- Detected declarations: `function wss_insert`, `function vivid_vbi_gen_wss_raw`, `function vivid_vbi_gen_teletext_raw`, `function cc_insert`, `function vivid_vbi_gen_cc_raw`, `function vivid_vbi_gen_raw`, `function calc_parity`, `function vivid_vbi_gen_set_time_of_day`, `function vivid_vbi_gen_teletext`, `function vivid_vbi_gen_sliced`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
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.