blob: c9d51a5f28389b21b6a7d3d8503d000612ce9cf6 [file] [log] [blame]
Alexey Klimovfc55bcb2008-12-27 22:33:54 -03001/* A driver for the D-Link DSB-R100 USB radio and Gemtek USB Radio 21.
Hans Verkuil5d778642012-04-27 08:13:26 -03002 * The device plugs into both the USB and an analog audio input, so this thing
3 * only deals with initialisation and frequency setting, the
4 * audio data has to be handled by a sound driver.
5 *
6 * Major issue: I can't find out where the device reports the signal
7 * strength, and indeed the windows software appearantly just looks
8 * at the stereo indicator as well. So, scanning will only find
9 * stereo stations. Sad, but I can't help it.
10 *
11 * Also, the windows program sends oodles of messages over to the
12 * device, and I couldn't figure out their meaning. My suspicion
13 * is that they don't have any:-)
14 *
15 * You might find some interesting stuff about this module at
16 * http://unimut.fsk.uni-heidelberg.de/unimut/demi/dsbr
17 *
18 * Fully tested with the Keene USB FM Transmitter and the v4l2-compliance tool.
19 *
20 * Copyright (c) 2000 Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
21 *
22 * This program is free software; you can redistribute it and/or modify
23 * it under the terms of the GNU General Public License as published by
24 * the Free Software Foundation; either version 2 of the License, or
25 * (at your option) any later version.
26 *
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
Linus Torvalds1da177e2005-04-16 15:20:36 -070031*/
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/kernel.h>
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/input.h>
Alan Cox5aff3082006-08-08 15:47:50 -030038#include <linux/videodev2.h>
Hans Verkuil5d778642012-04-27 08:13:26 -030039#include <linux/usb.h>
Alexey Klimov406827c2009-04-03 18:45:17 -030040#include <media/v4l2-device.h>
Hans Verkuil35ea11f2008-07-20 08:12:02 -030041#include <media/v4l2-ioctl.h>
Hans Verkuil5d778642012-04-27 08:13:26 -030042#include <media/v4l2-ctrls.h>
43#include <media/v4l2-event.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45/*
46 * Version Information
47 */
Hans Verkuil5d778642012-04-27 08:13:26 -030048MODULE_AUTHOR("Markus Demleitner <msdemlei@tucana.harvard.edu>");
49MODULE_DESCRIPTION("D-Link DSB-R100 USB FM radio driver");
50MODULE_LICENSE("GPL");
51MODULE_VERSION("1.1.0");
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#define DSB100_VENDOR 0x04b4
54#define DSB100_PRODUCT 0x1002
55
56/* Commands the device appears to understand */
57#define DSB100_TUNE 1
58#define DSB100_ONOFF 2
59
60#define TB_LEN 16
61
62/* Frequency limits in MHz -- these are European values. For Japanese
63devices, that would be 76 and 91. */
64#define FREQ_MIN 87.5
65#define FREQ_MAX 108.0
66#define FREQ_MUL 16000
67
Hans Verkuil13099292011-01-17 20:25:11 -030068#define v4l2_dev_to_radio(d) container_of(d, struct dsbr100_device, v4l2_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
Linus Torvalds1da177e2005-04-16 15:20:36 -070070static int radio_nr = -1;
71module_param(radio_nr, int, 0);
72
73/* Data for one (physical) device */
Alan Cox5aff3082006-08-08 15:47:50 -030074struct dsbr100_device {
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 struct usb_device *usbdev;
Alexey Klimov3a0efc32008-12-27 21:32:49 -030076 struct video_device videodev;
Alexey Klimov406827c2009-04-03 18:45:17 -030077 struct v4l2_device v4l2_dev;
Hans Verkuil5d778642012-04-27 08:13:26 -030078 struct v4l2_ctrl_handler hdl;
Alexey Klimov406827c2009-04-03 18:45:17 -030079
Oliver Neukum863c86d2007-12-03 06:48:43 -030080 u8 *transfer_buffer;
Hans Verkuile64d07c2010-12-19 18:54:08 -030081 struct mutex v4l2_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 int curfreq;
Hans Verkuil5d778642012-04-27 08:13:26 -030083 bool stereo;
84 bool muted;
Linus Torvalds1da177e2005-04-16 15:20:36 -070085};
86
87/* Low-level device interface begins here */
88
Hans Verkuil5d778642012-04-27 08:13:26 -030089/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
90static int dsbr100_setfreq(struct dsbr100_device *radio, unsigned freq)
91{
92 unsigned f = (freq / 16 * 80) / 1000 + 856;
93 int retval = 0;
94
95 if (!radio->muted) {
96 retval = usb_control_msg(radio->usbdev,
97 usb_rcvctrlpipe(radio->usbdev, 0),
98 DSB100_TUNE,
99 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
100 (f >> 8) & 0x00ff, f & 0xff,
101 radio->transfer_buffer, 8, 300);
102 if (retval >= 0)
103 mdelay(1);
104 }
105
106 if (retval >= 0) {
107 radio->curfreq = freq;
108 return 0;
109 }
110 dev_err(&radio->usbdev->dev,
111 "%s - usb_control_msg returned %i, request %i\n",
112 __func__, retval, DSB100_TUNE);
113 return retval;
114}
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* switch on radio */
Alan Cox5aff3082006-08-08 15:47:50 -0300117static int dsbr100_start(struct dsbr100_device *radio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118{
Hans Verkuil5d778642012-04-27 08:13:26 -0300119 int retval = usb_control_msg(radio->usbdev,
Alexey Klimov417b7952008-12-27 22:30:29 -0300120 usb_rcvctrlpipe(radio->usbdev, 0),
121 DSB100_ONOFF,
122 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
123 0x01, 0x00, radio->transfer_buffer, 8, 300);
124
Hans Verkuil5d778642012-04-27 08:13:26 -0300125 if (retval >= 0)
126 return dsbr100_setfreq(radio, radio->curfreq);
Alexey Klimov417b7952008-12-27 22:30:29 -0300127 dev_err(&radio->usbdev->dev,
128 "%s - usb_control_msg returned %i, request %i\n",
Hans Verkuil5d778642012-04-27 08:13:26 -0300129 __func__, retval, DSB100_ONOFF);
Alexey Klimovd25cb642008-12-27 22:40:57 -0300130 return retval;
Alexey Klimov417b7952008-12-27 22:30:29 -0300131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134/* switch off radio */
Alan Cox5aff3082006-08-08 15:47:50 -0300135static int dsbr100_stop(struct dsbr100_device *radio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Hans Verkuil5d778642012-04-27 08:13:26 -0300137 int retval = usb_control_msg(radio->usbdev,
Alexey Klimov417b7952008-12-27 22:30:29 -0300138 usb_rcvctrlpipe(radio->usbdev, 0),
139 DSB100_ONOFF,
140 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
141 0x00, 0x00, radio->transfer_buffer, 8, 300);
142
Hans Verkuil5d778642012-04-27 08:13:26 -0300143 if (retval >= 0)
144 return 0;
Alexey Klimov417b7952008-12-27 22:30:29 -0300145 dev_err(&radio->usbdev->dev,
146 "%s - usb_control_msg returned %i, request %i\n",
Hans Verkuil5d778642012-04-27 08:13:26 -0300147 __func__, retval, DSB100_ONOFF);
Alexey Klimovd25cb642008-12-27 22:40:57 -0300148 return retval;
Alexey Klimov417b7952008-12-27 22:30:29 -0300149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150}
151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152/* return the device status. This is, in effect, just whether it
153sees a stereo signal or not. Pity. */
Alan Cox5aff3082006-08-08 15:47:50 -0300154static void dsbr100_getstat(struct dsbr100_device *radio)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155{
Hans Verkuil5d778642012-04-27 08:13:26 -0300156 int retval = usb_control_msg(radio->usbdev,
Alexey Klimov417b7952008-12-27 22:30:29 -0300157 usb_rcvctrlpipe(radio->usbdev, 0),
Mauro Carvalho Chehabd56410e2006-03-25 09:19:53 -0300158 USB_REQ_GET_STATUS,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
Hans Verkuil5d778642012-04-27 08:13:26 -0300160 0x00, 0x24, radio->transfer_buffer, 8, 300);
Alexey Klimov417b7952008-12-27 22:30:29 -0300161
162 if (retval < 0) {
Hans Verkuil5d778642012-04-27 08:13:26 -0300163 radio->stereo = false;
Alexey Klimov417b7952008-12-27 22:30:29 -0300164 dev_err(&radio->usbdev->dev,
165 "%s - usb_control_msg returned %i, request %i\n",
166 __func__, retval, USB_REQ_GET_STATUS);
167 } else {
Alexey Klimov223377e2008-10-19 23:50:27 -0300168 radio->stereo = !(radio->transfer_buffer[0] & 0x01);
Alexey Klimov417b7952008-12-27 22:30:29 -0300169 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170}
171
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300172static int vidioc_querycap(struct file *file, void *priv,
173 struct v4l2_capability *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Alexey Klimovc7181cf2009-01-25 20:05:58 -0300175 struct dsbr100_device *radio = video_drvdata(file);
176
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -0400177 strscpy(v->driver, "dsbr100", sizeof(v->driver));
178 strscpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
Alexey Klimovc7181cf2009-01-25 20:05:58 -0300179 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
Hans Verkuil5d778642012-04-27 08:13:26 -0300180 v->device_caps = V4L2_CAP_RADIO | V4L2_CAP_TUNER;
181 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS;
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300182 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183}
184
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300185static int vidioc_g_tuner(struct file *file, void *priv,
186 struct v4l2_tuner *v)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300188 struct dsbr100_device *radio = video_drvdata(file);
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300189
190 if (v->index > 0)
191 return -EINVAL;
192
193 dsbr100_getstat(radio);
Mauro Carvalho Chehabcc1e6312018-09-10 16:20:42 -0400194 strscpy(v->name, "FM", sizeof(v->name));
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300195 v->type = V4L2_TUNER_RADIO;
Alexey Klimov223377e2008-10-19 23:50:27 -0300196 v->rangelow = FREQ_MIN * FREQ_MUL;
197 v->rangehigh = FREQ_MAX * FREQ_MUL;
Hans Verkuil5d778642012-04-27 08:13:26 -0300198 v->rxsubchans = radio->stereo ? V4L2_TUNER_SUB_STEREO :
199 V4L2_TUNER_SUB_MONO;
200 v->capability = V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO;
201 v->audmode = V4L2_TUNER_MODE_STEREO;
202 v->signal = radio->stereo ? 0xffff : 0; /* We can't get the signal strength */
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300203 return 0;
204}
205
206static int vidioc_s_tuner(struct file *file, void *priv,
Hans Verkuil2f73c7c2013-03-15 06:10:06 -0300207 const struct v4l2_tuner *v)
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300208{
Hans Verkuil13099292011-01-17 20:25:11 -0300209 return v->index ? -EINVAL : 0;
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300210}
211
212static int vidioc_s_frequency(struct file *file, void *priv,
Hans Verkuilb530a442013-03-19 04:09:26 -0300213 const struct v4l2_frequency *f)
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300214{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300215 struct dsbr100_device *radio = video_drvdata(file);
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300216
Hans Verkuil5d778642012-04-27 08:13:26 -0300217 if (f->tuner != 0 || f->type != V4L2_TUNER_RADIO)
218 return -EINVAL;
Alexey Klimovfdf9c992009-02-08 02:00:14 -0300219
Hans Verkuil5d778642012-04-27 08:13:26 -0300220 return dsbr100_setfreq(radio, clamp_t(unsigned, f->frequency,
221 FREQ_MIN * FREQ_MUL, FREQ_MAX * FREQ_MUL));
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300222}
223
224static int vidioc_g_frequency(struct file *file, void *priv,
225 struct v4l2_frequency *f)
226{
Hans Verkuilc170ecf2008-08-23 08:32:09 -0300227 struct dsbr100_device *radio = video_drvdata(file);
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300228
Hans Verkuil5d778642012-04-27 08:13:26 -0300229 if (f->tuner)
230 return -EINVAL;
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300231 f->type = V4L2_TUNER_RADIO;
232 f->frequency = radio->curfreq;
233 return 0;
234}
235
Hans Verkuil5d778642012-04-27 08:13:26 -0300236static int usb_dsbr100_s_ctrl(struct v4l2_ctrl *ctrl)
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300237{
Hans Verkuil5d778642012-04-27 08:13:26 -0300238 struct dsbr100_device *radio =
239 container_of(ctrl->handler, struct dsbr100_device, hdl);
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300240
241 switch (ctrl->id) {
242 case V4L2_CID_AUDIO_MUTE:
Hans Verkuil5d778642012-04-27 08:13:26 -0300243 radio->muted = ctrl->val;
244 return radio->muted ? dsbr100_stop(radio) : dsbr100_start(radio);
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300245 }
246 return -EINVAL;
247}
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249
Hans Verkuile64d07c2010-12-19 18:54:08 -0300250/* USB subsystem interface begins here */
251
252/*
253 * Handle unplugging of the device.
254 * We call video_unregister_device in any case.
255 * The last function called in this procedure is
256 * usb_dsbr100_video_device_release
257 */
258static void usb_dsbr100_disconnect(struct usb_interface *intf)
259{
260 struct dsbr100_device *radio = usb_get_intfdata(intf);
261
Hans Verkuile64d07c2010-12-19 18:54:08 -0300262 mutex_lock(&radio->v4l2_lock);
Hans Verkuil5d778642012-04-27 08:13:26 -0300263 /*
264 * Disconnect is also called on unload, and in that case we need to
265 * mute the device. This call will silently fail if it is called
266 * after a physical disconnect.
267 */
268 usb_control_msg(radio->usbdev,
269 usb_rcvctrlpipe(radio->usbdev, 0),
270 DSB100_ONOFF,
271 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
272 0x00, 0x00, radio->transfer_buffer, 8, 300);
Hans Verkuil13099292011-01-17 20:25:11 -0300273 usb_set_intfdata(intf, NULL);
Hans Verkuile64d07c2010-12-19 18:54:08 -0300274 video_unregister_device(&radio->videodev);
275 v4l2_device_disconnect(&radio->v4l2_dev);
Hans Verkuil13099292011-01-17 20:25:11 -0300276 mutex_unlock(&radio->v4l2_lock);
277 v4l2_device_put(&radio->v4l2_dev);
Hans Verkuile64d07c2010-12-19 18:54:08 -0300278}
279
280
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300281/* Suspend device - stop device. */
282static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
283{
284 struct dsbr100_device *radio = usb_get_intfdata(intf);
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300285
Hans Verkuile64d07c2010-12-19 18:54:08 -0300286 mutex_lock(&radio->v4l2_lock);
Hans Verkuil5d778642012-04-27 08:13:26 -0300287 if (!radio->muted && dsbr100_stop(radio) < 0)
288 dev_warn(&intf->dev, "dsbr100_stop failed\n");
Hans Verkuile64d07c2010-12-19 18:54:08 -0300289 mutex_unlock(&radio->v4l2_lock);
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300290
291 dev_info(&intf->dev, "going into suspend..\n");
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300292 return 0;
293}
294
295/* Resume device - start device. */
296static int usb_dsbr100_resume(struct usb_interface *intf)
297{
298 struct dsbr100_device *radio = usb_get_intfdata(intf);
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300299
Hans Verkuile64d07c2010-12-19 18:54:08 -0300300 mutex_lock(&radio->v4l2_lock);
Hans Verkuil5d778642012-04-27 08:13:26 -0300301 if (!radio->muted && dsbr100_start(radio) < 0)
302 dev_warn(&intf->dev, "dsbr100_start failed\n");
Hans Verkuile64d07c2010-12-19 18:54:08 -0300303 mutex_unlock(&radio->v4l2_lock);
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300304
305 dev_info(&intf->dev, "coming out of suspend..\n");
Alexey Klimov04e0ffb2008-11-08 00:40:46 -0300306 return 0;
307}
308
Alexey Klimovfc55bcb2008-12-27 22:33:54 -0300309/* free data structures */
Hans Verkuil13099292011-01-17 20:25:11 -0300310static void usb_dsbr100_release(struct v4l2_device *v4l2_dev)
Alexey Klimov3a0efc32008-12-27 21:32:49 -0300311{
Hans Verkuil13099292011-01-17 20:25:11 -0300312 struct dsbr100_device *radio = v4l2_dev_to_radio(v4l2_dev);
Alexey Klimov3a0efc32008-12-27 21:32:49 -0300313
Hans Verkuil5d778642012-04-27 08:13:26 -0300314 v4l2_ctrl_handler_free(&radio->hdl);
Alexey Klimov406827c2009-04-03 18:45:17 -0300315 v4l2_device_unregister(&radio->v4l2_dev);
Alexey Klimov3a0efc32008-12-27 21:32:49 -0300316 kfree(radio->transfer_buffer);
317 kfree(radio);
318}
319
Hans Verkuil5d778642012-04-27 08:13:26 -0300320static const struct v4l2_ctrl_ops usb_dsbr100_ctrl_ops = {
321 .s_ctrl = usb_dsbr100_s_ctrl,
322};
323
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300324/* File system interface */
Hans Verkuilbec436612008-12-30 06:58:20 -0300325static const struct v4l2_file_operations usb_dsbr100_fops = {
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300326 .owner = THIS_MODULE,
Hans Verkuile64d07c2010-12-19 18:54:08 -0300327 .unlocked_ioctl = video_ioctl2,
Hans Verkuil5d778642012-04-27 08:13:26 -0300328 .open = v4l2_fh_open,
329 .release = v4l2_fh_release,
330 .poll = v4l2_ctrl_poll,
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300331};
332
Hans Verkuila3998102008-07-21 02:57:38 -0300333static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300334 .vidioc_querycap = vidioc_querycap,
335 .vidioc_g_tuner = vidioc_g_tuner,
336 .vidioc_s_tuner = vidioc_s_tuner,
337 .vidioc_g_frequency = vidioc_g_frequency,
338 .vidioc_s_frequency = vidioc_s_frequency,
Hans Verkuil5d778642012-04-27 08:13:26 -0300339 .vidioc_log_status = v4l2_ctrl_log_status,
340 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
341 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300342};
343
Alexey Klimovfc55bcb2008-12-27 22:33:54 -0300344/* check if the device is present and register with v4l and usb if it is */
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300345static int usb_dsbr100_probe(struct usb_interface *intf,
346 const struct usb_device_id *id)
347{
348 struct dsbr100_device *radio;
Alexey Klimov406827c2009-04-03 18:45:17 -0300349 struct v4l2_device *v4l2_dev;
Alexey Klimov417b7952008-12-27 22:30:29 -0300350 int retval;
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300351
Alexey Klimov406827c2009-04-03 18:45:17 -0300352 radio = kzalloc(sizeof(struct dsbr100_device), GFP_KERNEL);
Alexey Klimov223377e2008-10-19 23:50:27 -0300353
354 if (!radio)
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300355 return -ENOMEM;
Alexey Klimov223377e2008-10-19 23:50:27 -0300356
357 radio->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL);
358
359 if (!(radio->transfer_buffer)) {
Oliver Neukum863c86d2007-12-03 06:48:43 -0300360 kfree(radio);
361 return -ENOMEM;
362 }
Alexey Klimov223377e2008-10-19 23:50:27 -0300363
Alexey Klimov406827c2009-04-03 18:45:17 -0300364 v4l2_dev = &radio->v4l2_dev;
Hans Verkuil13099292011-01-17 20:25:11 -0300365 v4l2_dev->release = usb_dsbr100_release;
Alexey Klimov406827c2009-04-03 18:45:17 -0300366
367 retval = v4l2_device_register(&intf->dev, v4l2_dev);
368 if (retval < 0) {
369 v4l2_err(v4l2_dev, "couldn't register v4l2_device\n");
Hans Verkuil5d778642012-04-27 08:13:26 -0300370 goto err_reg_dev;
Alexey Klimov406827c2009-04-03 18:45:17 -0300371 }
372
Hans Verkuil5d778642012-04-27 08:13:26 -0300373 v4l2_ctrl_handler_init(&radio->hdl, 1);
374 v4l2_ctrl_new_std(&radio->hdl, &usb_dsbr100_ctrl_ops,
375 V4L2_CID_AUDIO_MUTE, 0, 1, 1, 1);
376 if (radio->hdl.error) {
377 retval = radio->hdl.error;
378 v4l2_err(v4l2_dev, "couldn't register control\n");
379 goto err_reg_ctrl;
380 }
Hans Verkuile64d07c2010-12-19 18:54:08 -0300381 mutex_init(&radio->v4l2_lock);
Mauro Carvalho Chehabc0decac2018-09-10 08:19:14 -0400382 strscpy(radio->videodev.name, v4l2_dev->name,
383 sizeof(radio->videodev.name));
Alexey Klimov406827c2009-04-03 18:45:17 -0300384 radio->videodev.v4l2_dev = v4l2_dev;
385 radio->videodev.fops = &usb_dsbr100_fops;
386 radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops;
Hans Verkuil13099292011-01-17 20:25:11 -0300387 radio->videodev.release = video_device_release_empty;
Hans Verkuile64d07c2010-12-19 18:54:08 -0300388 radio->videodev.lock = &radio->v4l2_lock;
Hans Verkuil5d778642012-04-27 08:13:26 -0300389 radio->videodev.ctrl_handler = &radio->hdl;
Alexey Klimov3a0efc32008-12-27 21:32:49 -0300390
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300391 radio->usbdev = interface_to_usbdev(intf);
Alexey Klimov223377e2008-10-19 23:50:27 -0300392 radio->curfreq = FREQ_MIN * FREQ_MUL;
Hans Verkuil5d778642012-04-27 08:13:26 -0300393 radio->muted = true;
Alexey Klimov406827c2009-04-03 18:45:17 -0300394
Alexey Klimov3a0efc32008-12-27 21:32:49 -0300395 video_set_drvdata(&radio->videodev, radio);
Hans Verkuil5d778642012-04-27 08:13:26 -0300396 usb_set_intfdata(intf, radio);
Alexey Klimov406827c2009-04-03 18:45:17 -0300397
Alexey Klimov417b7952008-12-27 22:30:29 -0300398 retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
Hans Verkuil5d778642012-04-27 08:13:26 -0300399 if (retval == 0)
400 return 0;
401 v4l2_err(v4l2_dev, "couldn't register video device\n");
402
403err_reg_ctrl:
404 v4l2_ctrl_handler_free(&radio->hdl);
405 v4l2_device_unregister(v4l2_dev);
406err_reg_dev:
407 kfree(radio->transfer_buffer);
408 kfree(radio);
409 return retval;
Douglas Landgraf7002a4f2007-05-07 16:43:01 -0300410}
411
Arvind Yadav1ab22342017-08-13 04:54:45 -0400412static const struct usb_device_id usb_dsbr100_device_table[] = {
Hans Verkuil5d778642012-04-27 08:13:26 -0300413 { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) },
414 { } /* Terminating entry */
415};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Hans Verkuil5d778642012-04-27 08:13:26 -0300417MODULE_DEVICE_TABLE(usb, usb_dsbr100_device_table);
418
419/* USB subsystem interface */
420static struct usb_driver usb_dsbr100_driver = {
421 .name = "dsbr100",
422 .probe = usb_dsbr100_probe,
423 .disconnect = usb_dsbr100_disconnect,
424 .id_table = usb_dsbr100_device_table,
425 .suspend = usb_dsbr100_suspend,
426 .resume = usb_dsbr100_resume,
427 .reset_resume = usb_dsbr100_resume,
428};
429
430module_usb_driver(usb_dsbr100_driver);