drivers/media/usb/airspy/airspy.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/airspy/airspy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/airspy/airspy.c- Extension
.c- Size
- 27666 bytes
- Lines
- 1113
- 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.
- 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/module.hlinux/slab.hlinux/usb.hmedia/v4l2-device.hmedia/v4l2-ioctl.hmedia/v4l2-ctrls.hmedia/v4l2-event.hmedia/videobuf2-v4l2.hmedia/videobuf2-vmalloc.h
Detected Declarations
struct airspy_formatstruct airspy_frame_bufstruct airspyfunction airspy_ctrl_msgfunction airspy_convert_streamfunction airspy_urb_completefunction airspy_kill_urbsfunction airspy_submit_urbsfunction airspy_free_stream_bufsfunction airspy_alloc_stream_bufsfunction airspy_free_urbsfunction airspy_alloc_urbsfunction airspy_cleanup_queued_bufsfunction airspy_disconnectfunction airspy_queue_setupfunction airspy_buf_queuefunction airspy_start_streamingfunction list_for_each_entry_safefunction airspy_stop_streamingfunction airspy_querycapfunction airspy_enum_fmt_sdr_capfunction airspy_g_fmt_sdr_capfunction airspy_s_fmt_sdr_capfunction airspy_try_fmt_sdr_capfunction airspy_s_tunerfunction airspy_g_tunerfunction airspy_g_frequencyfunction airspy_s_frequencyfunction airspy_enum_freq_bandsfunction airspy_video_releasefunction airspy_set_lna_gainfunction airspy_set_mixer_gainfunction airspy_set_if_gainfunction airspy_s_ctrlfunction airspy_probe
Annotated Snippet
struct airspy_format {
u32 pixelformat;
u32 buffersize;
};
/* format descriptions for capture and preview */
static struct airspy_format formats[] = {
{
.pixelformat = V4L2_SDR_FMT_RU12LE,
.buffersize = BULK_BUFFER_SIZE,
},
};
static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
/* intermediate buffers with raw data from the USB device */
struct airspy_frame_buf {
/* common v4l buffer stuff -- must be first */
struct vb2_v4l2_buffer vb;
struct list_head list;
};
struct airspy {
#define POWER_ON 1
#define USB_STATE_URB_BUF 2
unsigned long flags;
struct device *dev;
struct usb_device *udev;
struct video_device vdev;
struct v4l2_device v4l2_dev;
/* videobuf2 queue and queued buffers list */
struct vb2_queue vb_queue;
struct list_head queued_bufs;
spinlock_t queued_bufs_lock; /* Protects queued_bufs */
unsigned sequence; /* Buffer sequence counter */
unsigned int vb_full; /* vb is full and packets dropped */
/* Note if taking both locks v4l2_lock must always be locked first! */
struct mutex v4l2_lock; /* Protects everything else */
struct mutex vb_queue_lock; /* Protects vb_queue and capt_file */
struct urb *urb_list[MAX_BULK_BUFS];
int buf_num;
unsigned long buf_size;
u8 *buf_list[MAX_BULK_BUFS];
dma_addr_t dma_addr[MAX_BULK_BUFS];
int urbs_initialized;
int urbs_submitted;
/* USB control message buffer */
#define BUF_SIZE 128
u8 *buf;
/* Current configuration */
unsigned int f_adc;
unsigned int f_rf;
u32 pixelformat;
u32 buffersize;
/* Controls */
struct v4l2_ctrl_handler hdl;
struct v4l2_ctrl *lna_gain_auto;
struct v4l2_ctrl *lna_gain;
struct v4l2_ctrl *mixer_gain_auto;
struct v4l2_ctrl *mixer_gain;
struct v4l2_ctrl *if_gain;
/* Sample rate calc */
unsigned long jiffies_next;
unsigned int sample;
unsigned int sample_measured;
};
#define airspy_dbg_usb_control_msg(_dev, _r, _t, _v, _i, _b, _l) { \
char *_direction; \
if (_t & USB_DIR_IN) \
_direction = "<<<"; \
else \
_direction = ">>>"; \
dev_dbg(_dev, "%02x %02x %02x %02x %02x %02x %02x %02x %s %*ph\n", \
_t, _r, _v & 0xff, _v >> 8, _i & 0xff, _i >> 8, \
_l & 0xff, _l >> 8, _direction, _l, _b); \
}
/* execute firmware command */
static int airspy_ctrl_msg(struct airspy *s, u8 request, u16 value, u16 index,
u8 *data, u16 size)
{
Annotation
- Immediate include surface: `linux/module.h`, `linux/slab.h`, `linux/usb.h`, `media/v4l2-device.h`, `media/v4l2-ioctl.h`, `media/v4l2-ctrls.h`, `media/v4l2-event.h`, `media/videobuf2-v4l2.h`.
- Detected declarations: `struct airspy_format`, `struct airspy_frame_buf`, `struct airspy`, `function airspy_ctrl_msg`, `function airspy_convert_stream`, `function airspy_urb_complete`, `function airspy_kill_urbs`, `function airspy_submit_urbs`, `function airspy_free_stream_bufs`, `function airspy_alloc_stream_bufs`.
- 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.