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.

Dependency Surface

Detected Declarations

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

Implementation Notes