drivers/media/usb/hackrf/hackrf.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/hackrf/hackrf.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/hackrf/hackrf.c- Extension
.c- Size
- 42990 bytes
- Lines
- 1550
- 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 hackrf_formatstruct hackrf_bufferstruct hackrf_devfunction hackrf_ctrl_msgfunction hackrf_set_paramsfunction hackrf_copy_streamfunction hackrf_urb_complete_infunction hackrf_urb_complete_outfunction hackrf_kill_urbsfunction hackrf_submit_urbsfunction hackrf_free_stream_bufsfunction hackrf_alloc_stream_bufsfunction hackrf_free_urbsfunction hackrf_alloc_urbsfunction hackrf_disconnectfunction hackrf_return_all_buffersfunction hackrf_queue_setupfunction hackrf_buf_queuefunction hackrf_start_streamingfunction hackrf_stop_streamingfunction hackrf_querycapfunction hackrf_s_fmt_sdrfunction hackrf_g_fmt_sdrfunction hackrf_try_fmt_sdrfunction hackrf_enum_fmt_sdrfunction hackrf_s_tunerfunction hackrf_g_tunerfunction hackrf_s_modulatorfunction hackrf_g_modulatorfunction hackrf_s_frequencyfunction hackrf_g_frequencyfunction hackrf_enum_freq_bandsfunction hackrf_video_releasefunction hackrf_s_ctrl_rxfunction hackrf_s_ctrl_txfunction hackrf_probe
Annotated Snippet
struct hackrf_format {
u32 pixelformat;
u32 buffersize;
};
/* format descriptions for capture and preview */
static struct hackrf_format formats[] = {
{
.pixelformat = V4L2_SDR_FMT_CS8,
.buffersize = BULK_BUFFER_SIZE,
},
};
static const unsigned int NUM_FORMATS = ARRAY_SIZE(formats);
/* intermediate buffers with raw data from the USB device */
struct hackrf_buffer {
struct vb2_v4l2_buffer vb;
struct list_head list;
};
struct hackrf_dev {
#define USB_STATE_URB_BUF 1 /* XXX: set manually */
#define RX_ON 4
#define TX_ON 5
#define RX_ADC_FREQUENCY 11
#define TX_DAC_FREQUENCY 12
#define RX_BANDWIDTH 13
#define TX_BANDWIDTH 14
#define RX_RF_FREQUENCY 15
#define TX_RF_FREQUENCY 16
#define RX_RF_GAIN 17
#define TX_RF_GAIN 18
#define RX_IF_GAIN 19
#define RX_LNA_GAIN 20
#define TX_LNA_GAIN 21
unsigned long flags;
struct usb_interface *intf;
struct device *dev;
struct usb_device *udev;
struct video_device rx_vdev;
struct video_device tx_vdev;
struct v4l2_device v4l2_dev;
/* videobuf2 queue and queued buffers list */
struct vb2_queue rx_vb2_queue;
struct vb2_queue tx_vb2_queue;
struct list_head rx_buffer_list;
struct list_head tx_buffer_list;
spinlock_t buffer_list_lock; /* Protects buffer_list */
unsigned int sequence; /* Buffer sequence counter */
unsigned int vb_full; /* vb is full and packets dropped */
unsigned int vb_empty; /* vb is empty 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 */
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 24
u8 buf[BUF_SIZE];
/* Current configuration */
unsigned int f_adc;
unsigned int f_dac;
unsigned int f_rx;
unsigned int f_tx;
u32 pixelformat;
u32 buffersize;
/* Controls */
struct v4l2_ctrl_handler rx_ctrl_handler;
struct v4l2_ctrl *rx_bandwidth_auto;
struct v4l2_ctrl *rx_bandwidth;
struct v4l2_ctrl *rx_rf_gain;
struct v4l2_ctrl *rx_lna_gain;
struct v4l2_ctrl *rx_if_gain;
struct v4l2_ctrl_handler tx_ctrl_handler;
struct v4l2_ctrl *tx_bandwidth_auto;
struct v4l2_ctrl *tx_bandwidth;
struct v4l2_ctrl *tx_rf_gain;
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 hackrf_format`, `struct hackrf_buffer`, `struct hackrf_dev`, `function hackrf_ctrl_msg`, `function hackrf_set_params`, `function hackrf_copy_stream`, `function hackrf_urb_complete_in`, `function hackrf_urb_complete_out`, `function hackrf_kill_urbs`, `function hackrf_submit_urbs`.
- 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.