1ddddfa78SHans Verkuil // SPDX-License-Identifier: GPL-2.0-only
221326c46SHans Verkuil /*
321326c46SHans Verkuil * Copyright 2013 Cisco Systems, Inc. and/or its affiliates. All rights reserved.
421326c46SHans Verkuil */
521326c46SHans Verkuil
621326c46SHans Verkuil #include <linux/kernel.h>
721326c46SHans Verkuil #include <linux/module.h>
821326c46SHans Verkuil #include <linux/init.h>
921326c46SHans Verkuil #include <linux/slab.h>
1021326c46SHans Verkuil #include <linux/input.h>
1121326c46SHans Verkuil #include <linux/usb.h>
1221326c46SHans Verkuil #include <linux/hid.h>
1321326c46SHans Verkuil #include <linux/mutex.h>
1421326c46SHans Verkuil #include <linux/videodev2.h>
15*5f60d5f6SAl Viro #include <linux/unaligned.h>
1621326c46SHans Verkuil #include <media/v4l2-device.h>
1721326c46SHans Verkuil #include <media/v4l2-ioctl.h>
1821326c46SHans Verkuil #include <media/v4l2-ctrls.h>
1921326c46SHans Verkuil #include <media/v4l2-event.h>
2021326c46SHans Verkuil
2121326c46SHans Verkuil /*
2221326c46SHans Verkuil * 'Thanko's Raremono' is a Japanese si4734-based AM/FM/SW USB receiver:
2321326c46SHans Verkuil *
2421326c46SHans Verkuil * http://www.raremono.jp/product/484.html/
2521326c46SHans Verkuil *
2621326c46SHans Verkuil * The USB protocol has been reversed engineered using wireshark, initially
2721326c46SHans Verkuil * by Dinesh Ram <dinesh.ram@cern.ch> and finished by Hans Verkuil
2821326c46SHans Verkuil * <hverkuil@xs4all.nl>.
2921326c46SHans Verkuil *
3021326c46SHans Verkuil * Sadly the firmware used in this product hides lots of goodies since the
3121326c46SHans Verkuil * si4734 has more features than are supported by the firmware. Oh well...
3221326c46SHans Verkuil */
3321326c46SHans Verkuil
3421326c46SHans Verkuil /* driver and module definitions */
3521326c46SHans Verkuil MODULE_AUTHOR("Hans Verkuil <hverkuil@xs4all.nl>");
3621326c46SHans Verkuil MODULE_DESCRIPTION("Thanko's Raremono AM/FM/SW Receiver USB driver");
3721326c46SHans Verkuil MODULE_LICENSE("GPL v2");
3821326c46SHans Verkuil
3921326c46SHans Verkuil /*
4021326c46SHans Verkuil * The Device announces itself as Cygnal Integrated Products, Inc.
4121326c46SHans Verkuil *
4221326c46SHans Verkuil * The vendor and product IDs (and in fact all other lsusb information as
4321326c46SHans Verkuil * well) are identical to the si470x Silicon Labs USB FM Radio Reference
4421326c46SHans Verkuil * Design board, even though this card has a si4734 device. Clearly the
4521326c46SHans Verkuil * designer of this product never bothered to change the USB IDs.
4621326c46SHans Verkuil */
4721326c46SHans Verkuil
4821326c46SHans Verkuil /* USB Device ID List */
491ab2234eSArvind Yadav static const struct usb_device_id usb_raremono_device_table[] = {
5021326c46SHans Verkuil {USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID, 0, 0) },
5121326c46SHans Verkuil { } /* Terminating entry */
5221326c46SHans Verkuil };
5321326c46SHans Verkuil
5421326c46SHans Verkuil MODULE_DEVICE_TABLE(usb, usb_raremono_device_table);
5521326c46SHans Verkuil
5621326c46SHans Verkuil #define BUFFER_LENGTH 64
5721326c46SHans Verkuil
5821326c46SHans Verkuil /* Timeout is set to a high value, could probably be reduced. Need more tests */
5921326c46SHans Verkuil #define USB_TIMEOUT 10000
6021326c46SHans Verkuil
6121326c46SHans Verkuil /* Frequency limits in KHz */
6221326c46SHans Verkuil #define FM_FREQ_RANGE_LOW 64000
6321326c46SHans Verkuil #define FM_FREQ_RANGE_HIGH 108000
6421326c46SHans Verkuil
6521326c46SHans Verkuil #define AM_FREQ_RANGE_LOW 520
6621326c46SHans Verkuil #define AM_FREQ_RANGE_HIGH 1710
6721326c46SHans Verkuil
6821326c46SHans Verkuil #define SW_FREQ_RANGE_LOW 2300
6921326c46SHans Verkuil #define SW_FREQ_RANGE_HIGH 26100
7021326c46SHans Verkuil
7121326c46SHans Verkuil enum { BAND_FM, BAND_AM, BAND_SW };
7221326c46SHans Verkuil
7321326c46SHans Verkuil static const struct v4l2_frequency_band bands[] = {
7421326c46SHans Verkuil /* Band FM */
7521326c46SHans Verkuil {
7621326c46SHans Verkuil .type = V4L2_TUNER_RADIO,
7721326c46SHans Verkuil .index = 0,
7821326c46SHans Verkuil .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO |
7921326c46SHans Verkuil V4L2_TUNER_CAP_FREQ_BANDS,
8021326c46SHans Verkuil .rangelow = FM_FREQ_RANGE_LOW * 16,
8121326c46SHans Verkuil .rangehigh = FM_FREQ_RANGE_HIGH * 16,
8221326c46SHans Verkuil .modulation = V4L2_BAND_MODULATION_FM,
8321326c46SHans Verkuil },
8421326c46SHans Verkuil /* Band AM */
8521326c46SHans Verkuil {
8621326c46SHans Verkuil .type = V4L2_TUNER_RADIO,
8721326c46SHans Verkuil .index = 1,
8821326c46SHans Verkuil .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
8921326c46SHans Verkuil .rangelow = AM_FREQ_RANGE_LOW * 16,
9021326c46SHans Verkuil .rangehigh = AM_FREQ_RANGE_HIGH * 16,
9121326c46SHans Verkuil .modulation = V4L2_BAND_MODULATION_AM,
9221326c46SHans Verkuil },
9321326c46SHans Verkuil /* Band SW */
9421326c46SHans Verkuil {
9521326c46SHans Verkuil .type = V4L2_TUNER_RADIO,
9621326c46SHans Verkuil .index = 2,
9721326c46SHans Verkuil .capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_FREQ_BANDS,
9821326c46SHans Verkuil .rangelow = SW_FREQ_RANGE_LOW * 16,
9921326c46SHans Verkuil .rangehigh = SW_FREQ_RANGE_HIGH * 16,
10021326c46SHans Verkuil .modulation = V4L2_BAND_MODULATION_AM,
10121326c46SHans Verkuil },
10221326c46SHans Verkuil };
10321326c46SHans Verkuil
10421326c46SHans Verkuil struct raremono_device {
10521326c46SHans Verkuil struct usb_device *usbdev;
10621326c46SHans Verkuil struct usb_interface *intf;
10721326c46SHans Verkuil struct video_device vdev;
10821326c46SHans Verkuil struct v4l2_device v4l2_dev;
10921326c46SHans Verkuil struct mutex lock;
11021326c46SHans Verkuil
11121326c46SHans Verkuil u8 *buffer;
11221326c46SHans Verkuil u32 band;
11321326c46SHans Verkuil unsigned curfreq;
11421326c46SHans Verkuil };
11521326c46SHans Verkuil
to_raremono_dev(struct v4l2_device * v4l2_dev)11621326c46SHans Verkuil static inline struct raremono_device *to_raremono_dev(struct v4l2_device *v4l2_dev)
11721326c46SHans Verkuil {
11821326c46SHans Verkuil return container_of(v4l2_dev, struct raremono_device, v4l2_dev);
11921326c46SHans Verkuil }
12021326c46SHans Verkuil
12121326c46SHans Verkuil /* Set frequency. */
raremono_cmd_main(struct raremono_device * radio,unsigned band,unsigned freq)12221326c46SHans Verkuil static int raremono_cmd_main(struct raremono_device *radio, unsigned band, unsigned freq)
12321326c46SHans Verkuil {
12421326c46SHans Verkuil unsigned band_offset;
12521326c46SHans Verkuil int ret;
12621326c46SHans Verkuil
12721326c46SHans Verkuil switch (band) {
12821326c46SHans Verkuil case BAND_FM:
12921326c46SHans Verkuil band_offset = 1;
13021326c46SHans Verkuil freq /= 10;
13121326c46SHans Verkuil break;
13221326c46SHans Verkuil case BAND_AM:
13321326c46SHans Verkuil band_offset = 0;
13421326c46SHans Verkuil break;
13521326c46SHans Verkuil default:
13621326c46SHans Verkuil band_offset = 2;
13721326c46SHans Verkuil break;
13821326c46SHans Verkuil }
13921326c46SHans Verkuil radio->buffer[0] = 0x04 + band_offset;
14021326c46SHans Verkuil radio->buffer[1] = freq >> 8;
14121326c46SHans Verkuil radio->buffer[2] = freq & 0xff;
14221326c46SHans Verkuil
14321326c46SHans Verkuil ret = usb_control_msg(radio->usbdev, usb_sndctrlpipe(radio->usbdev, 0),
14421326c46SHans Verkuil HID_REQ_SET_REPORT,
14521326c46SHans Verkuil USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
14621326c46SHans Verkuil 0x0300 + radio->buffer[0], 2,
14721326c46SHans Verkuil radio->buffer, 3, USB_TIMEOUT);
14821326c46SHans Verkuil
14921326c46SHans Verkuil if (ret < 0) {
15021326c46SHans Verkuil dev_warn(radio->v4l2_dev.dev, "%s failed (%d)\n", __func__, ret);
15121326c46SHans Verkuil return ret;
15221326c46SHans Verkuil }
15321326c46SHans Verkuil radio->curfreq = (band == BAND_FM) ? freq * 10 : freq;
15421326c46SHans Verkuil return 0;
15521326c46SHans Verkuil }
15621326c46SHans Verkuil
15721326c46SHans Verkuil /* Handle unplugging the device.
15821326c46SHans Verkuil * We call video_unregister_device in any case.
15921326c46SHans Verkuil * The last function called in this procedure is
16021326c46SHans Verkuil * usb_raremono_device_release.
16121326c46SHans Verkuil */
usb_raremono_disconnect(struct usb_interface * intf)16221326c46SHans Verkuil static void usb_raremono_disconnect(struct usb_interface *intf)
16321326c46SHans Verkuil {
16421326c46SHans Verkuil struct raremono_device *radio = to_raremono_dev(usb_get_intfdata(intf));
16521326c46SHans Verkuil
16621326c46SHans Verkuil dev_info(&intf->dev, "Thanko's Raremono disconnected\n");
16721326c46SHans Verkuil
16821326c46SHans Verkuil mutex_lock(&radio->lock);
16921326c46SHans Verkuil usb_set_intfdata(intf, NULL);
17021326c46SHans Verkuil video_unregister_device(&radio->vdev);
17121326c46SHans Verkuil v4l2_device_disconnect(&radio->v4l2_dev);
17221326c46SHans Verkuil mutex_unlock(&radio->lock);
17321326c46SHans Verkuil v4l2_device_put(&radio->v4l2_dev);
17421326c46SHans Verkuil }
17521326c46SHans Verkuil
17621326c46SHans Verkuil /*
17721326c46SHans Verkuil * Linux Video interface
17821326c46SHans Verkuil */
vidioc_querycap(struct file * file,void * priv,struct v4l2_capability * v)17921326c46SHans Verkuil static int vidioc_querycap(struct file *file, void *priv,
18021326c46SHans Verkuil struct v4l2_capability *v)
18121326c46SHans Verkuil {
18221326c46SHans Verkuil struct raremono_device *radio = video_drvdata(file);
18321326c46SHans Verkuil
184c0decac1SMauro Carvalho Chehab strscpy(v->driver, "radio-raremono", sizeof(v->driver));
185c0decac1SMauro Carvalho Chehab strscpy(v->card, "Thanko's Raremono", sizeof(v->card));
18621326c46SHans Verkuil usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
18721326c46SHans Verkuil return 0;
18821326c46SHans Verkuil }
18921326c46SHans Verkuil
vidioc_enum_freq_bands(struct file * file,void * priv,struct v4l2_frequency_band * band)19021326c46SHans Verkuil static int vidioc_enum_freq_bands(struct file *file, void *priv,
19121326c46SHans Verkuil struct v4l2_frequency_band *band)
19221326c46SHans Verkuil {
19321326c46SHans Verkuil if (band->tuner != 0)
19421326c46SHans Verkuil return -EINVAL;
19521326c46SHans Verkuil
19621326c46SHans Verkuil if (band->index >= ARRAY_SIZE(bands))
19721326c46SHans Verkuil return -EINVAL;
19821326c46SHans Verkuil
19921326c46SHans Verkuil *band = bands[band->index];
20021326c46SHans Verkuil
20121326c46SHans Verkuil return 0;
20221326c46SHans Verkuil }
20321326c46SHans Verkuil
vidioc_g_tuner(struct file * file,void * priv,struct v4l2_tuner * v)20421326c46SHans Verkuil static int vidioc_g_tuner(struct file *file, void *priv,
20521326c46SHans Verkuil struct v4l2_tuner *v)
20621326c46SHans Verkuil {
20721326c46SHans Verkuil struct raremono_device *radio = video_drvdata(file);
20821326c46SHans Verkuil int ret;
20921326c46SHans Verkuil
21021326c46SHans Verkuil if (v->index > 0)
21121326c46SHans Verkuil return -EINVAL;
21221326c46SHans Verkuil
213c0decac1SMauro Carvalho Chehab strscpy(v->name, "AM/FM/SW", sizeof(v->name));
21421326c46SHans Verkuil v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO |
21521326c46SHans Verkuil V4L2_TUNER_CAP_FREQ_BANDS;
21621326c46SHans Verkuil v->rangelow = AM_FREQ_RANGE_LOW * 16;
21721326c46SHans Verkuil v->rangehigh = FM_FREQ_RANGE_HIGH * 16;
21821326c46SHans Verkuil v->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
21921326c46SHans Verkuil v->audmode = (radio->curfreq < FM_FREQ_RANGE_LOW) ?
22021326c46SHans Verkuil V4L2_TUNER_MODE_MONO : V4L2_TUNER_MODE_STEREO;
22121326c46SHans Verkuil memset(radio->buffer, 1, BUFFER_LENGTH);
22221326c46SHans Verkuil ret = usb_control_msg(radio->usbdev, usb_rcvctrlpipe(radio->usbdev, 0),
22321326c46SHans Verkuil 1, 0xa1, 0x030d, 2, radio->buffer, BUFFER_LENGTH, USB_TIMEOUT);
22421326c46SHans Verkuil
22521326c46SHans Verkuil if (ret < 0) {
22621326c46SHans Verkuil dev_warn(radio->v4l2_dev.dev, "%s failed (%d)\n", __func__, ret);
22721326c46SHans Verkuil return ret;
22821326c46SHans Verkuil }
22921326c46SHans Verkuil v->signal = ((radio->buffer[1] & 0xf) << 8 | radio->buffer[2]) << 4;
23021326c46SHans Verkuil return 0;
23121326c46SHans Verkuil }
23221326c46SHans Verkuil
vidioc_s_tuner(struct file * file,void * priv,const struct v4l2_tuner * v)23321326c46SHans Verkuil static int vidioc_s_tuner(struct file *file, void *priv,
23421326c46SHans Verkuil const struct v4l2_tuner *v)
23521326c46SHans Verkuil {
23621326c46SHans Verkuil return v->index ? -EINVAL : 0;
23721326c46SHans Verkuil }
23821326c46SHans Verkuil
vidioc_s_frequency(struct file * file,void * priv,const struct v4l2_frequency * f)23921326c46SHans Verkuil static int vidioc_s_frequency(struct file *file, void *priv,
24021326c46SHans Verkuil const struct v4l2_frequency *f)
24121326c46SHans Verkuil {
24221326c46SHans Verkuil struct raremono_device *radio = video_drvdata(file);
24366b72cf1SColin Ian King u32 freq;
24421326c46SHans Verkuil unsigned band;
24521326c46SHans Verkuil
24621326c46SHans Verkuil if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
24721326c46SHans Verkuil return -EINVAL;
24821326c46SHans Verkuil
24921326c46SHans Verkuil if (f->frequency >= (FM_FREQ_RANGE_LOW + SW_FREQ_RANGE_HIGH) * 8)
25021326c46SHans Verkuil band = BAND_FM;
25121326c46SHans Verkuil else if (f->frequency <= (AM_FREQ_RANGE_HIGH + SW_FREQ_RANGE_LOW) * 8)
25221326c46SHans Verkuil band = BAND_AM;
25321326c46SHans Verkuil else
25421326c46SHans Verkuil band = BAND_SW;
25521326c46SHans Verkuil
25621326c46SHans Verkuil freq = clamp_t(u32, f->frequency, bands[band].rangelow, bands[band].rangehigh);
25721326c46SHans Verkuil return raremono_cmd_main(radio, band, freq / 16);
25821326c46SHans Verkuil }
25921326c46SHans Verkuil
vidioc_g_frequency(struct file * file,void * priv,struct v4l2_frequency * f)26021326c46SHans Verkuil static int vidioc_g_frequency(struct file *file, void *priv,
26121326c46SHans Verkuil struct v4l2_frequency *f)
26221326c46SHans Verkuil {
26321326c46SHans Verkuil struct raremono_device *radio = video_drvdata(file);
26421326c46SHans Verkuil
26521326c46SHans Verkuil if (f->tuner != 0)
26621326c46SHans Verkuil return -EINVAL;
26721326c46SHans Verkuil f->type = V4L2_TUNER_RADIO;
26821326c46SHans Verkuil f->frequency = radio->curfreq * 16;
26921326c46SHans Verkuil return 0;
27021326c46SHans Verkuil }
27121326c46SHans Verkuil
raremono_device_release(struct v4l2_device * v4l2_dev)272c666355eSLuke Nowakowski-Krijger static void raremono_device_release(struct v4l2_device *v4l2_dev)
273c666355eSLuke Nowakowski-Krijger {
274c666355eSLuke Nowakowski-Krijger struct raremono_device *radio = to_raremono_dev(v4l2_dev);
275c666355eSLuke Nowakowski-Krijger
276c666355eSLuke Nowakowski-Krijger kfree(radio->buffer);
277c666355eSLuke Nowakowski-Krijger kfree(radio);
278c666355eSLuke Nowakowski-Krijger }
279c666355eSLuke Nowakowski-Krijger
28021326c46SHans Verkuil /* File system interface */
28121326c46SHans Verkuil static const struct v4l2_file_operations usb_raremono_fops = {
28221326c46SHans Verkuil .owner = THIS_MODULE,
28321326c46SHans Verkuil .open = v4l2_fh_open,
28421326c46SHans Verkuil .release = v4l2_fh_release,
28521326c46SHans Verkuil .unlocked_ioctl = video_ioctl2,
28621326c46SHans Verkuil };
28721326c46SHans Verkuil
28821326c46SHans Verkuil static const struct v4l2_ioctl_ops usb_raremono_ioctl_ops = {
28921326c46SHans Verkuil .vidioc_querycap = vidioc_querycap,
29021326c46SHans Verkuil .vidioc_g_tuner = vidioc_g_tuner,
29121326c46SHans Verkuil .vidioc_s_tuner = vidioc_s_tuner,
29221326c46SHans Verkuil .vidioc_g_frequency = vidioc_g_frequency,
29321326c46SHans Verkuil .vidioc_s_frequency = vidioc_s_frequency,
29421326c46SHans Verkuil .vidioc_enum_freq_bands = vidioc_enum_freq_bands,
29521326c46SHans Verkuil };
29621326c46SHans Verkuil
29721326c46SHans Verkuil /* check if the device is present and register with v4l and usb if it is */
usb_raremono_probe(struct usb_interface * intf,const struct usb_device_id * id)29821326c46SHans Verkuil static int usb_raremono_probe(struct usb_interface *intf,
29921326c46SHans Verkuil const struct usb_device_id *id)
30021326c46SHans Verkuil {
30121326c46SHans Verkuil struct raremono_device *radio;
30221326c46SHans Verkuil int retval = 0;
30321326c46SHans Verkuil
304c666355eSLuke Nowakowski-Krijger radio = kzalloc(sizeof(*radio), GFP_KERNEL);
305c666355eSLuke Nowakowski-Krijger if (!radio)
30621326c46SHans Verkuil return -ENOMEM;
307c666355eSLuke Nowakowski-Krijger radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
308c666355eSLuke Nowakowski-Krijger if (!radio->buffer) {
309c666355eSLuke Nowakowski-Krijger kfree(radio);
310c666355eSLuke Nowakowski-Krijger return -ENOMEM;
311c666355eSLuke Nowakowski-Krijger }
31221326c46SHans Verkuil
31321326c46SHans Verkuil radio->usbdev = interface_to_usbdev(intf);
31421326c46SHans Verkuil radio->intf = intf;
31521326c46SHans Verkuil
31621326c46SHans Verkuil /*
31721326c46SHans Verkuil * This device uses the same USB IDs as the si470x SiLabs reference
31821326c46SHans Verkuil * design. So do an additional check: attempt to read the device ID
31921326c46SHans Verkuil * from the si470x: the lower 12 bits are 0x0242 for the si470x. The
32021326c46SHans Verkuil * Raremono always returns 0x0800 (the meaning of that is unknown, but
32121326c46SHans Verkuil * at least it works).
32221326c46SHans Verkuil *
32321326c46SHans Verkuil * We use this check to determine which device we are dealing with.
32421326c46SHans Verkuil */
32521326c46SHans Verkuil msleep(20);
32621326c46SHans Verkuil retval = usb_control_msg(radio->usbdev,
32721326c46SHans Verkuil usb_rcvctrlpipe(radio->usbdev, 0),
32821326c46SHans Verkuil HID_REQ_GET_REPORT,
32921326c46SHans Verkuil USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
33021326c46SHans Verkuil 1, 2,
33121326c46SHans Verkuil radio->buffer, 3, 500);
33221326c46SHans Verkuil if (retval != 3 ||
33321326c46SHans Verkuil (get_unaligned_be16(&radio->buffer[1]) & 0xfff) == 0x0242) {
33421326c46SHans Verkuil dev_info(&intf->dev, "this is not Thanko's Raremono.\n");
335c666355eSLuke Nowakowski-Krijger retval = -ENODEV;
336c666355eSLuke Nowakowski-Krijger goto free_mem;
33721326c46SHans Verkuil }
33821326c46SHans Verkuil
33921326c46SHans Verkuil dev_info(&intf->dev, "Thanko's Raremono connected: (%04X:%04X)\n",
34021326c46SHans Verkuil id->idVendor, id->idProduct);
34121326c46SHans Verkuil
34221326c46SHans Verkuil retval = v4l2_device_register(&intf->dev, &radio->v4l2_dev);
34321326c46SHans Verkuil if (retval < 0) {
34421326c46SHans Verkuil dev_err(&intf->dev, "couldn't register v4l2_device\n");
345c666355eSLuke Nowakowski-Krijger goto free_mem;
34621326c46SHans Verkuil }
34721326c46SHans Verkuil
34821326c46SHans Verkuil mutex_init(&radio->lock);
34921326c46SHans Verkuil
350c0decac1SMauro Carvalho Chehab strscpy(radio->vdev.name, radio->v4l2_dev.name,
35121326c46SHans Verkuil sizeof(radio->vdev.name));
35221326c46SHans Verkuil radio->vdev.v4l2_dev = &radio->v4l2_dev;
35321326c46SHans Verkuil radio->vdev.fops = &usb_raremono_fops;
35421326c46SHans Verkuil radio->vdev.ioctl_ops = &usb_raremono_ioctl_ops;
35521326c46SHans Verkuil radio->vdev.lock = &radio->lock;
35621326c46SHans Verkuil radio->vdev.release = video_device_release_empty;
357e83ce300SHans Verkuil radio->vdev.device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
358c666355eSLuke Nowakowski-Krijger radio->v4l2_dev.release = raremono_device_release;
35921326c46SHans Verkuil
36021326c46SHans Verkuil usb_set_intfdata(intf, &radio->v4l2_dev);
36121326c46SHans Verkuil
36221326c46SHans Verkuil video_set_drvdata(&radio->vdev, radio);
36321326c46SHans Verkuil
36421326c46SHans Verkuil raremono_cmd_main(radio, BAND_FM, 95160);
36521326c46SHans Verkuil
36621326c46SHans Verkuil retval = video_register_device(&radio->vdev, VFL_TYPE_RADIO, -1);
36721326c46SHans Verkuil if (retval == 0) {
36821326c46SHans Verkuil dev_info(&intf->dev, "V4L2 device registered as %s\n",
36921326c46SHans Verkuil video_device_node_name(&radio->vdev));
37021326c46SHans Verkuil return 0;
37121326c46SHans Verkuil }
37221326c46SHans Verkuil dev_err(&intf->dev, "could not register video device\n");
37321326c46SHans Verkuil v4l2_device_unregister(&radio->v4l2_dev);
374c666355eSLuke Nowakowski-Krijger
375c666355eSLuke Nowakowski-Krijger free_mem:
376c666355eSLuke Nowakowski-Krijger kfree(radio->buffer);
377c666355eSLuke Nowakowski-Krijger kfree(radio);
37821326c46SHans Verkuil return retval;
37921326c46SHans Verkuil }
38021326c46SHans Verkuil
38121326c46SHans Verkuil /* USB subsystem interface */
38221326c46SHans Verkuil static struct usb_driver usb_raremono_driver = {
38321326c46SHans Verkuil .name = "radio-raremono",
38421326c46SHans Verkuil .probe = usb_raremono_probe,
38521326c46SHans Verkuil .disconnect = usb_raremono_disconnect,
38621326c46SHans Verkuil .id_table = usb_raremono_device_table,
38721326c46SHans Verkuil };
38821326c46SHans Verkuil
38921326c46SHans Verkuil module_usb_driver(usb_raremono_driver);
390