[PATCH v2] hackrf: HackRF SDR driver
V4L2 driver for HackRF SDR. Very basic version, with reduced feature set. Driver implements receiver only, hardware supports also transmitter. USB ID 1d50:6089. Model HackRF One Signed-off-by: Antti Palosaari --- Changes in v2: * renamed state 's' => 'dev' * do not init spin_lock_irqsave() flags as it has no meaning * remove unneeded error check from buf_queue * comment fix remove mention of capt_file * some minor issues reported by checkpatch.pl --- drivers/media/usb/Kconfig |3 +- drivers/media/usb/Makefile|3 +- drivers/media/usb/hackrf/Kconfig | 10 + drivers/media/usb/hackrf/Makefile |1 + drivers/media/usb/hackrf/hackrf.c | 1142 + 5 files changed, 1157 insertions(+), 2 deletions(-) create mode 100644 drivers/media/usb/hackrf/Kconfig create mode 100644 drivers/media/usb/hackrf/Makefile create mode 100644 drivers/media/usb/hackrf/hackrf.c diff --git a/drivers/media/usb/Kconfig b/drivers/media/usb/Kconfig index d6e8edc..056181f 100644 --- a/drivers/media/usb/Kconfig +++ b/drivers/media/usb/Kconfig @@ -56,8 +56,9 @@ endif if MEDIA_SDR_SUPPORT comment "Software defined radio USB devices" -source "drivers/media/usb/msi2500/Kconfig" source "drivers/media/usb/airspy/Kconfig" +source "drivers/media/usb/hackrf/Kconfig" +source "drivers/media/usb/msi2500/Kconfig" endif endif #MEDIA_USB_SUPPORT diff --git a/drivers/media/usb/Makefile b/drivers/media/usb/Makefile index b5b645b..6f2eb7c 100644 --- a/drivers/media/usb/Makefile +++ b/drivers/media/usb/Makefile @@ -9,8 +9,9 @@ obj-y += zr364xx/ stkwebcam/ s2255/ obj-$(CONFIG_USB_VIDEO_CLASS) += uvc/ obj-$(CONFIG_USB_GSPCA) += gspca/ obj-$(CONFIG_USB_PWC) += pwc/ -obj-$(CONFIG_USB_MSI2500) += msi2500/ obj-$(CONFIG_USB_AIRSPY)+= airspy/ +obj-$(CONFIG_USB_HACKRF)+= hackrf/ +obj-$(CONFIG_USB_MSI2500) += msi2500/ obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ obj-$(CONFIG_VIDEO_AU0828) += au0828/ obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/ diff --git a/drivers/media/usb/hackrf/Kconfig b/drivers/media/usb/hackrf/Kconfig new file mode 100644 index 000..937e6f5 --- /dev/null +++ b/drivers/media/usb/hackrf/Kconfig @@ -0,0 +1,10 @@ +config USB_HACKRF + tristate "HackRF" + depends on VIDEO_V4L2 + select VIDEOBUF2_VMALLOC + ---help--- + This is a video4linux2 driver for HackRF SDR device. + + To compile this driver as a module, choose M here: the + module will be called hackrf + diff --git a/drivers/media/usb/hackrf/Makefile b/drivers/media/usb/hackrf/Makefile new file mode 100644 index 000..73064a2 --- /dev/null +++ b/drivers/media/usb/hackrf/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_USB_HACKRF) += hackrf.o diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c new file mode 100644 index 000..9427652 --- /dev/null +++ b/drivers/media/usb/hackrf/hackrf.c @@ -0,0 +1,1142 @@ +/* + * HackRF driver + * + * Copyright (C) 2014 Antti Palosaari + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* HackRF USB API commands (from HackRF Library) */ +enum { + CMD_SET_TRANSCEIVER_MODE = 0x01, + CMD_SAMPLE_RATE_SET= 0x06, + CMD_BASEBAND_FILTER_BANDWIDTH_SET = 0x07, + CMD_BOARD_ID_READ = 0x0e, + CMD_VERSION_STRING_READ= 0x0f, + CMD_SET_FREQ = 0x10, + CMD_SET_LNA_GAIN = 0x13, + CMD_SET_VGA_GAIN = 0x14, +}; + +/* + * bEndpointAddress 0x81 EP 1 IN + * Transfer TypeBulk + * wMaxPacketSize 0x0200 1x 512 bytes + */ +#define MAX_BULK_BUFS(6) +#define BULK_BUFFER_SIZE (128 * 512) + +static const struct v4l2_frequency_band bands_adc[] = { + { + .tuner = 0, + .type = V4L2_TUNER_ADC, + .index = 0, + .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS, + .rangelow = 20, + .rangehigh = 2400, + }, +}; + +static const struct v4l2_frequency_band bands_rf[] = { + { + .tuner = 1, + .type = V4L2_TUNER_RF, + .index = 0, + .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS, + .rangelow =
Re: [PATCH v2] hackrf: HackRF SDR driver
On 09/06/2014 12:39 PM, Antti Palosaari wrote: V4L2 driver for HackRF SDR. Very basic version, with reduced feature set. Driver implements receiver only, hardware supports also transmitter. USB ID 1d50:6089. Model HackRF One Signed-off-by: Antti Palosaari --- Changes in v2: * renamed state 's' => 'dev' * do not init spin_lock_irqsave() flags as it has no meaning * remove unneeded error check from buf_queue * comment fix remove mention of capt_file * some minor issues reported by checkpatch.pl + start_streaming() error handling... --- drivers/media/usb/Kconfig |3 +- drivers/media/usb/Makefile|3 +- drivers/media/usb/hackrf/Kconfig | 10 + drivers/media/usb/hackrf/Makefile |1 + drivers/media/usb/hackrf/hackrf.c | 1142 + 5 files changed, 1157 insertions(+), 2 deletions(-) create mode 100644 drivers/media/usb/hackrf/Kconfig create mode 100644 drivers/media/usb/hackrf/Makefile create mode 100644 drivers/media/usb/hackrf/hackrf.c diff --git a/drivers/media/usb/Kconfig b/drivers/media/usb/Kconfig index d6e8edc..056181f 100644 --- a/drivers/media/usb/Kconfig +++ b/drivers/media/usb/Kconfig @@ -56,8 +56,9 @@ endif if MEDIA_SDR_SUPPORT comment "Software defined radio USB devices" -source "drivers/media/usb/msi2500/Kconfig" source "drivers/media/usb/airspy/Kconfig" +source "drivers/media/usb/hackrf/Kconfig" +source "drivers/media/usb/msi2500/Kconfig" endif endif #MEDIA_USB_SUPPORT diff --git a/drivers/media/usb/Makefile b/drivers/media/usb/Makefile index b5b645b..6f2eb7c 100644 --- a/drivers/media/usb/Makefile +++ b/drivers/media/usb/Makefile @@ -9,8 +9,9 @@ obj-y += zr364xx/ stkwebcam/ s2255/ obj-$(CONFIG_USB_VIDEO_CLASS) += uvc/ obj-$(CONFIG_USB_GSPCA) += gspca/ obj-$(CONFIG_USB_PWC) += pwc/ -obj-$(CONFIG_USB_MSI2500) += msi2500/ obj-$(CONFIG_USB_AIRSPY)+= airspy/ +obj-$(CONFIG_USB_HACKRF)+= hackrf/ +obj-$(CONFIG_USB_MSI2500) += msi2500/ obj-$(CONFIG_VIDEO_CPIA2) += cpia2/ obj-$(CONFIG_VIDEO_AU0828) += au0828/ obj-$(CONFIG_VIDEO_HDPVR) += hdpvr/ diff --git a/drivers/media/usb/hackrf/Kconfig b/drivers/media/usb/hackrf/Kconfig new file mode 100644 index 000..937e6f5 --- /dev/null +++ b/drivers/media/usb/hackrf/Kconfig @@ -0,0 +1,10 @@ +config USB_HACKRF + tristate "HackRF" + depends on VIDEO_V4L2 + select VIDEOBUF2_VMALLOC + ---help--- + This is a video4linux2 driver for HackRF SDR device. + + To compile this driver as a module, choose M here: the + module will be called hackrf + diff --git a/drivers/media/usb/hackrf/Makefile b/drivers/media/usb/hackrf/Makefile new file mode 100644 index 000..73064a2 --- /dev/null +++ b/drivers/media/usb/hackrf/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_USB_HACKRF) += hackrf.o diff --git a/drivers/media/usb/hackrf/hackrf.c b/drivers/media/usb/hackrf/hackrf.c new file mode 100644 index 000..9427652 --- /dev/null +++ b/drivers/media/usb/hackrf/hackrf.c @@ -0,0 +1,1142 @@ +/* + * HackRF driver + * + * Copyright (C) 2014 Antti Palosaari + * + *This program is free software; you can redistribute it and/or modify + *it under the terms of the GNU General Public License as published by + *the Free Software Foundation; either version 2 of the License, or + *(at your option) any later version. + * + *This program is distributed in the hope that it will be useful, + *but WITHOUT ANY WARRANTY; without even the implied warranty of + *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + *GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +/* HackRF USB API commands (from HackRF Library) */ +enum { + CMD_SET_TRANSCEIVER_MODE = 0x01, + CMD_SAMPLE_RATE_SET= 0x06, + CMD_BASEBAND_FILTER_BANDWIDTH_SET = 0x07, + CMD_BOARD_ID_READ = 0x0e, + CMD_VERSION_STRING_READ= 0x0f, + CMD_SET_FREQ = 0x10, + CMD_SET_LNA_GAIN = 0x13, + CMD_SET_VGA_GAIN = 0x14, +}; + +/* + * bEndpointAddress 0x81 EP 1 IN + * Transfer TypeBulk + * wMaxPacketSize 0x0200 1x 512 bytes + */ +#define MAX_BULK_BUFS(6) +#define BULK_BUFFER_SIZE (128 * 512) + +static const struct v4l2_frequency_band bands_adc[] = { + { + .tuner = 0, + .type = V4L2_TUNER_ADC, + .index = 0, + .capability = V4L2_TUNER_CAP_1HZ | V4L2_TUNER_CAP_FREQ_BANDS, + .rangelow = 20, + .rangehigh = 2400, + }, +}; + +static const struct v4l2_frequency_band bands_rf[] = { + { + .tuner = 1, + .type = V4L2_TUNER_RF, + .index = 0, +