drivers/media/test-drivers/vivid/vivid-radio-tx.c
Source file repositories/reference/linux-study-clean/drivers/media/test-drivers/vivid/vivid-radio-tx.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/test-drivers/vivid/vivid-radio-tx.c- Extension
.c- Size
- 3640 bytes
- Lines
- 129
- 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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/errno.hlinux/kernel.hlinux/sched/signal.hlinux/delay.hlinux/videodev2.hlinux/v4l2-dv-timings.hmedia/v4l2-common.hmedia/v4l2-event.hmedia/v4l2-dv-timings.hvivid-core.hvivid-ctrls.hvivid-radio-common.hvivid-radio-tx.h
Detected Declarations
function vivid_radio_tx_writefunction file_to_v4l2_fhfunction vivid_radio_tx_pollfunction vidioc_g_modulatorfunction vidioc_s_modulator
Annotated Snippet
file_to_v4l2_fh(file) != dev->radio_tx_rds_owner) {
mutex_unlock(&dev->mutex);
return -EBUSY;
}
dev->radio_tx_rds_owner = file_to_v4l2_fh(file);
retry:
timestamp = ktime_sub(ktime_get(), dev->radio_rds_init_time);
blk = ktime_divns(timestamp, VIVID_RDS_NSEC_PER_BLK);
if (blk - VIVID_RDS_GEN_BLOCKS >= dev->radio_tx_rds_last_block)
dev->radio_tx_rds_last_block = blk - VIVID_RDS_GEN_BLOCKS + 1;
/*
* No data is available if there hasn't been time to get new data,
* or if the RDS receiver has been disabled, or if we use the data
* from the RDS transmitter and that RDS transmitter has been disabled,
* or if the signal quality is too weak.
*/
if (blk == dev->radio_tx_rds_last_block ||
!(dev->radio_tx_subchans & V4L2_TUNER_SUB_RDS)) {
mutex_unlock(&dev->mutex);
if (file->f_flags & O_NONBLOCK)
return -EWOULDBLOCK;
if (msleep_interruptible(20) && signal_pending(current))
return -EINTR;
if (mutex_lock_interruptible(&dev->mutex))
return -ERESTARTSYS;
goto retry;
}
for (i = 0; i < size && blk > dev->radio_tx_rds_last_block;
dev->radio_tx_rds_last_block++) {
unsigned data_blk = dev->radio_tx_rds_last_block % VIVID_RDS_GEN_BLOCKS;
struct v4l2_rds_data rds;
if (copy_from_user(&rds, buf + i, sizeof(rds))) {
i = -EFAULT;
break;
}
i += sizeof(rds);
if (!dev->radio_rds_loop)
continue;
if ((rds.block & V4L2_RDS_BLOCK_MSK) == V4L2_RDS_BLOCK_INVALID ||
(rds.block & V4L2_RDS_BLOCK_ERROR))
continue;
rds.block &= V4L2_RDS_BLOCK_MSK;
data[data_blk] = rds;
}
mutex_unlock(&dev->mutex);
return i;
}
__poll_t vivid_radio_tx_poll(struct file *file, struct poll_table_struct *wait)
{
return EPOLLOUT | EPOLLWRNORM | v4l2_ctrl_poll(file, wait);
}
int vidioc_g_modulator(struct file *file, void *priv, struct v4l2_modulator *a)
{
struct vivid_dev *dev = video_drvdata(file);
if (a->index > 0)
return -EINVAL;
strscpy(a->name, "AM/FM/SW Transmitter", sizeof(a->name));
a->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO |
V4L2_TUNER_CAP_FREQ_BANDS | V4L2_TUNER_CAP_RDS |
(dev->radio_tx_rds_controls ?
V4L2_TUNER_CAP_RDS_CONTROLS :
V4L2_TUNER_CAP_RDS_BLOCK_IO);
a->rangelow = AM_FREQ_RANGE_LOW;
a->rangehigh = FM_FREQ_RANGE_HIGH;
a->txsubchans = dev->radio_tx_subchans;
return 0;
}
int vidioc_s_modulator(struct file *file, void *priv, const struct v4l2_modulator *a)
{
struct vivid_dev *dev = video_drvdata(file);
if (a->index)
return -EINVAL;
if (a->txsubchans & ~0x13)
return -EINVAL;
dev->radio_tx_subchans = a->txsubchans;
return 0;
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/kernel.h`, `linux/sched/signal.h`, `linux/delay.h`, `linux/videodev2.h`, `linux/v4l2-dv-timings.h`, `media/v4l2-common.h`, `media/v4l2-event.h`.
- Detected declarations: `function vivid_radio_tx_write`, `function file_to_v4l2_fh`, `function vivid_radio_tx_poll`, `function vidioc_g_modulator`, `function vidioc_s_modulator`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.