V4L/DVB (11435): dsbr100 radio: convert to to v4l2_device
[deliverable/linux.git] / drivers / media / radio / dsbr100.c
CommitLineData
fc55bcb0
AK
1/* A driver for the D-Link DSB-R100 USB radio and Gemtek USB Radio 21.
2 The device plugs into both the USB and an analog audio input, so this thing
1da177e4
LT
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 Copyright (c) 2000 Markus Demleitner <msdemlei@cl.uni-heidelberg.de>
19
20 This program is free software; you can redistribute it and/or modify
21 it under the terms of the GNU General Public License as published by
22 the Free Software Foundation; either version 2 of the License, or
23 (at your option) any later version.
24
25 This program is distributed in the hope that it will be useful,
26 but WITHOUT ANY WARRANTY; without even the implied warranty of
27 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 GNU General Public License for more details.
29
30 You should have received a copy of the GNU General Public License
31 along with this program; if not, write to the Free Software
32 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33
34 History:
35
406827cc
AK
36 Version 0.45:
37 Converted to v4l2_device.
38
6076dbf4
AK
39 Version 0.44:
40 Add suspend/resume functions, fix unplug of device,
41 a lot of cleanups and fixes by Alexey Klimov <klimov.linux@gmail.com>
42
863c86dd
ON
43 Version 0.43:
44 Oliver Neukum: avoided DMA coherency issue
45
7002a4f3
DL
46 Version 0.42:
47 Converted dsbr100 to use video_ioctl2
48 by Douglas Landgraf <dougsland@gmail.com>
49
5aff308c
AC
50 Version 0.41-ac1:
51 Alan Cox: Some cleanups and fixes
52
53 Version 0.41:
54 Converted to V4L2 API by Mauro Carvalho Chehab <mchehab@infradead.org>
55
1da177e4 56 Version 0.40:
5aff308c 57 Markus: Updates for 2.6.x kernels, code layout changes, name sanitizing
1da177e4
LT
58
59 Version 0.30:
d56410e0 60 Markus: Updates for 2.5.x kernel and more ISO compliant source
1da177e4
LT
61
62 Version 0.25:
d56410e0 63 PSL and Markus: Cleanup, radio now doesn't stop on device close
1da177e4
LT
64
65 Version 0.24:
d56410e0 66 Markus: Hope I got these silly VIDEO_TUNER_LOW issues finally
1da177e4
LT
67 right. Some minor cleanup, improved standalone compilation
68
69 Version 0.23:
d56410e0 70 Markus: Sign extension bug fixed by declaring transfer_buffer unsigned
1da177e4
LT
71
72 Version 0.22:
d56410e0 73 Markus: Some (brown bag) cleanup in what VIDIOCSTUNER returns,
1da177e4
LT
74 thanks to Mike Cox for pointing the problem out.
75
76 Version 0.21:
d56410e0 77 Markus: Minor cleanup, warnings if something goes wrong, lame attempt
1da177e4
LT
78 to adhere to Documentation/CodingStyle
79
d56410e0
MCC
80 Version 0.2:
81 Brad Hards <bradh@dynamite.com.au>: Fixes to make it work as non-module
1da177e4
LT
82 Markus: Copyright clarification
83
84 Version 0.01: Markus: initial release
85
86*/
87
1da177e4
LT
88#include <linux/kernel.h>
89#include <linux/module.h>
90#include <linux/init.h>
91#include <linux/slab.h>
92#include <linux/input.h>
5aff308c 93#include <linux/videodev2.h>
406827cc 94#include <media/v4l2-device.h>
35ea11ff 95#include <media/v4l2-ioctl.h>
1da177e4 96#include <linux/usb.h>
1da177e4
LT
97
98/*
99 * Version Information
100 */
5aff308c
AC
101#include <linux/version.h> /* for KERNEL_VERSION MACRO */
102
406827cc
AK
103#define DRIVER_VERSION "v0.45"
104#define RADIO_VERSION KERNEL_VERSION(0, 4, 5)
5aff308c 105
1da177e4
LT
106#define DRIVER_AUTHOR "Markus Demleitner <msdemlei@tucana.harvard.edu>"
107#define DRIVER_DESC "D-Link DSB-R100 USB FM radio driver"
108
109#define DSB100_VENDOR 0x04b4
110#define DSB100_PRODUCT 0x1002
111
112/* Commands the device appears to understand */
113#define DSB100_TUNE 1
114#define DSB100_ONOFF 2
115
116#define TB_LEN 16
117
118/* Frequency limits in MHz -- these are European values. For Japanese
119devices, that would be 76 and 91. */
120#define FREQ_MIN 87.5
121#define FREQ_MAX 108.0
122#define FREQ_MUL 16000
123
3a0efc32 124#define videodev_to_radio(d) container_of(d, struct dsbr100_device, videodev)
1da177e4
LT
125
126static int usb_dsbr100_probe(struct usb_interface *intf,
127 const struct usb_device_id *id);
128static void usb_dsbr100_disconnect(struct usb_interface *intf);
bec43661
HV
129static int usb_dsbr100_open(struct file *file);
130static int usb_dsbr100_close(struct file *file);
04e0ffbb
AK
131static int usb_dsbr100_suspend(struct usb_interface *intf,
132 pm_message_t message);
133static int usb_dsbr100_resume(struct usb_interface *intf);
1da177e4
LT
134
135static int radio_nr = -1;
136module_param(radio_nr, int, 0);
137
138/* Data for one (physical) device */
5aff308c 139struct dsbr100_device {
1da177e4 140 struct usb_device *usbdev;
3a0efc32 141 struct video_device videodev;
406827cc
AK
142 struct v4l2_device v4l2_dev;
143
863c86dd 144 u8 *transfer_buffer;
3a0efc32 145 struct mutex lock; /* buffer locking */
1da177e4
LT
146 int curfreq;
147 int stereo;
148 int users;
149 int removed;
5aff308c
AC
150 int muted;
151};
1da177e4 152
1da177e4
LT
153static struct usb_device_id usb_dsbr100_device_table [] = {
154 { USB_DEVICE(DSB100_VENDOR, DSB100_PRODUCT) },
155 { } /* Terminating entry */
156};
157
158MODULE_DEVICE_TABLE (usb, usb_dsbr100_device_table);
159
160/* USB subsystem interface */
161static struct usb_driver usb_dsbr100_driver = {
04e0ffbb
AK
162 .name = "dsbr100",
163 .probe = usb_dsbr100_probe,
164 .disconnect = usb_dsbr100_disconnect,
165 .id_table = usb_dsbr100_device_table,
166 .suspend = usb_dsbr100_suspend,
167 .resume = usb_dsbr100_resume,
168 .reset_resume = usb_dsbr100_resume,
169 .supports_autosuspend = 0,
1da177e4
LT
170};
171
172/* Low-level device interface begins here */
173
174/* switch on radio */
5aff308c 175static int dsbr100_start(struct dsbr100_device *radio)
1da177e4 176{
417b7953
AK
177 int retval;
178 int request;
179
3a0efc32 180 mutex_lock(&radio->lock);
417b7953
AK
181
182 retval = usb_control_msg(radio->usbdev,
183 usb_rcvctrlpipe(radio->usbdev, 0),
184 USB_REQ_GET_STATUS,
185 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
186 0x00, 0xC7, radio->transfer_buffer, 8, 300);
187
188 if (retval < 0) {
189 request = USB_REQ_GET_STATUS;
190 goto usb_control_msg_failed;
3a0efc32
AK
191 }
192
417b7953
AK
193 retval = usb_control_msg(radio->usbdev,
194 usb_rcvctrlpipe(radio->usbdev, 0),
195 DSB100_ONOFF,
196 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
197 0x01, 0x00, radio->transfer_buffer, 8, 300);
198
199 if (retval < 0) {
200 request = DSB100_ONOFF;
201 goto usb_control_msg_failed;
202 }
203
204 radio->muted = 0;
3a0efc32 205 mutex_unlock(&radio->lock);
1da177e4 206 return (radio->transfer_buffer)[0];
417b7953
AK
207
208usb_control_msg_failed:
209 mutex_unlock(&radio->lock);
210 dev_err(&radio->usbdev->dev,
211 "%s - usb_control_msg returned %i, request %i\n",
212 __func__, retval, request);
d25cb646 213 return retval;
417b7953 214
1da177e4
LT
215}
216
1da177e4 217/* switch off radio */
5aff308c 218static int dsbr100_stop(struct dsbr100_device *radio)
1da177e4 219{
417b7953
AK
220 int retval;
221 int request;
222
3a0efc32 223 mutex_lock(&radio->lock);
417b7953
AK
224
225 retval = usb_control_msg(radio->usbdev,
226 usb_rcvctrlpipe(radio->usbdev, 0),
227 USB_REQ_GET_STATUS,
228 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
229 0x16, 0x1C, radio->transfer_buffer, 8, 300);
230
231 if (retval < 0) {
232 request = USB_REQ_GET_STATUS;
233 goto usb_control_msg_failed;
234 }
235
236 retval = usb_control_msg(radio->usbdev,
237 usb_rcvctrlpipe(radio->usbdev, 0),
238 DSB100_ONOFF,
239 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
240 0x00, 0x00, radio->transfer_buffer, 8, 300);
241
242 if (retval < 0) {
243 request = DSB100_ONOFF;
244 goto usb_control_msg_failed;
3a0efc32
AK
245 }
246
417b7953 247 radio->muted = 1;
3a0efc32 248 mutex_unlock(&radio->lock);
1da177e4 249 return (radio->transfer_buffer)[0];
417b7953
AK
250
251usb_control_msg_failed:
252 mutex_unlock(&radio->lock);
253 dev_err(&radio->usbdev->dev,
254 "%s - usb_control_msg returned %i, request %i\n",
255 __func__, retval, request);
d25cb646 256 return retval;
417b7953 257
1da177e4
LT
258}
259
260/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
5aff308c 261static int dsbr100_setfreq(struct dsbr100_device *radio, int freq)
1da177e4 262{
417b7953
AK
263 int retval;
264 int request;
265
223377e7 266 freq = (freq / 16 * 80) / 1000 + 856;
3a0efc32 267 mutex_lock(&radio->lock);
417b7953
AK
268
269 retval = usb_control_msg(radio->usbdev,
270 usb_rcvctrlpipe(radio->usbdev, 0),
271 DSB100_TUNE,
272 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
273 (freq >> 8) & 0x00ff, freq & 0xff,
274 radio->transfer_buffer, 8, 300);
275
276 if (retval < 0) {
277 request = DSB100_TUNE;
278 goto usb_control_msg_failed;
279 }
280
281 retval = usb_control_msg(radio->usbdev,
282 usb_rcvctrlpipe(radio->usbdev, 0),
283 USB_REQ_GET_STATUS,
284 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
285 0x96, 0xB7, radio->transfer_buffer, 8, 300);
286
287 if (retval < 0) {
288 request = USB_REQ_GET_STATUS;
289 goto usb_control_msg_failed;
290 }
291
292 retval = usb_control_msg(radio->usbdev,
293 usb_rcvctrlpipe(radio->usbdev, 0),
294 USB_REQ_GET_STATUS,
295 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
296 0x00, 0x24, radio->transfer_buffer, 8, 300);
297
298 if (retval < 0) {
299 request = USB_REQ_GET_STATUS;
300 goto usb_control_msg_failed;
1da177e4 301 }
3a0efc32 302
223377e7 303 radio->stereo = !((radio->transfer_buffer)[0] & 0x01);
3a0efc32 304 mutex_unlock(&radio->lock);
1da177e4 305 return (radio->transfer_buffer)[0];
417b7953
AK
306
307usb_control_msg_failed:
308 radio->stereo = -1;
309 mutex_unlock(&radio->lock);
310 dev_err(&radio->usbdev->dev,
311 "%s - usb_control_msg returned %i, request %i\n",
312 __func__, retval, request);
d25cb646 313 return retval;
1da177e4
LT
314}
315
316/* return the device status. This is, in effect, just whether it
317sees a stereo signal or not. Pity. */
5aff308c 318static void dsbr100_getstat(struct dsbr100_device *radio)
1da177e4 319{
417b7953
AK
320 int retval;
321
3a0efc32 322 mutex_lock(&radio->lock);
417b7953
AK
323
324 retval = usb_control_msg(radio->usbdev,
325 usb_rcvctrlpipe(radio->usbdev, 0),
d56410e0 326 USB_REQ_GET_STATUS,
1da177e4 327 USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_DIR_IN,
417b7953
AK
328 0x00 , 0x24, radio->transfer_buffer, 8, 300);
329
330 if (retval < 0) {
1da177e4 331 radio->stereo = -1;
417b7953
AK
332 dev_err(&radio->usbdev->dev,
333 "%s - usb_control_msg returned %i, request %i\n",
334 __func__, retval, USB_REQ_GET_STATUS);
335 } else {
223377e7 336 radio->stereo = !(radio->transfer_buffer[0] & 0x01);
417b7953
AK
337 }
338
3a0efc32 339 mutex_unlock(&radio->lock);
1da177e4
LT
340}
341
1da177e4
LT
342/* USB subsystem interface begins here */
343
fc55bcb0
AK
344/*
345 * Handle unplugging of the device.
346 * We call video_unregister_device in any case.
347 * The last function called in this procedure is
348 * usb_dsbr100_video_device_release
349 */
1da177e4
LT
350static void usb_dsbr100_disconnect(struct usb_interface *intf)
351{
5aff308c 352 struct dsbr100_device *radio = usb_get_intfdata(intf);
1da177e4
LT
353
354 usb_set_intfdata (intf, NULL);
3a0efc32
AK
355
356 mutex_lock(&radio->lock);
357 radio->removed = 1;
358 mutex_unlock(&radio->lock);
359
360 video_unregister_device(&radio->videodev);
406827cc 361 v4l2_device_disconnect(&radio->v4l2_dev);
1da177e4
LT
362}
363
364
7002a4f3
DL
365static int vidioc_querycap(struct file *file, void *priv,
366 struct v4l2_capability *v)
367{
c7181cfa
AK
368 struct dsbr100_device *radio = video_drvdata(file);
369
7002a4f3
DL
370 strlcpy(v->driver, "dsbr100", sizeof(v->driver));
371 strlcpy(v->card, "D-Link R-100 USB FM Radio", sizeof(v->card));
c7181cfa 372 usb_make_path(radio->usbdev, v->bus_info, sizeof(v->bus_info));
7002a4f3
DL
373 v->version = RADIO_VERSION;
374 v->capabilities = V4L2_CAP_TUNER;
375 return 0;
376}
1da177e4 377
7002a4f3
DL
378static int vidioc_g_tuner(struct file *file, void *priv,
379 struct v4l2_tuner *v)
1da177e4 380{
c170ecf4 381 struct dsbr100_device *radio = video_drvdata(file);
7002a4f3 382
3a0efc32
AK
383 /* safety check */
384 if (radio->removed)
385 return -EIO;
386
7002a4f3
DL
387 if (v->index > 0)
388 return -EINVAL;
389
390 dsbr100_getstat(radio);
391 strcpy(v->name, "FM");
392 v->type = V4L2_TUNER_RADIO;
223377e7
AK
393 v->rangelow = FREQ_MIN * FREQ_MUL;
394 v->rangehigh = FREQ_MAX * FREQ_MUL;
395 v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
7002a4f3
DL
396 v->capability = V4L2_TUNER_CAP_LOW;
397 if(radio->stereo)
398 v->audmode = V4L2_TUNER_MODE_STEREO;
399 else
400 v->audmode = V4L2_TUNER_MODE_MONO;
401 v->signal = 0xffff; /* We can't get the signal strength */
402 return 0;
403}
1da177e4 404
7002a4f3
DL
405static int vidioc_s_tuner(struct file *file, void *priv,
406 struct v4l2_tuner *v)
407{
3a0efc32
AK
408 struct dsbr100_device *radio = video_drvdata(file);
409
410 /* safety check */
411 if (radio->removed)
412 return -EIO;
413
7002a4f3
DL
414 if (v->index > 0)
415 return -EINVAL;
1da177e4 416
7002a4f3
DL
417 return 0;
418}
5aff308c 419
7002a4f3
DL
420static int vidioc_s_frequency(struct file *file, void *priv,
421 struct v4l2_frequency *f)
422{
c170ecf4 423 struct dsbr100_device *radio = video_drvdata(file);
417b7953 424 int retval;
1da177e4 425
3a0efc32
AK
426 /* safety check */
427 if (radio->removed)
428 return -EIO;
429
fdf9c997 430 mutex_lock(&radio->lock);
7002a4f3 431 radio->curfreq = f->frequency;
fdf9c997
AK
432 mutex_unlock(&radio->lock);
433
417b7953 434 retval = dsbr100_setfreq(radio, radio->curfreq);
d25cb646 435 if (retval < 0)
aa82661b 436 dev_warn(&radio->usbdev->dev, "Set frequency failed\n");
7002a4f3
DL
437 return 0;
438}
5aff308c 439
7002a4f3
DL
440static int vidioc_g_frequency(struct file *file, void *priv,
441 struct v4l2_frequency *f)
442{
c170ecf4 443 struct dsbr100_device *radio = video_drvdata(file);
5aff308c 444
3a0efc32
AK
445 /* safety check */
446 if (radio->removed)
447 return -EIO;
448
7002a4f3
DL
449 f->type = V4L2_TUNER_RADIO;
450 f->frequency = radio->curfreq;
451 return 0;
452}
5aff308c 453
7002a4f3
DL
454static int vidioc_queryctrl(struct file *file, void *priv,
455 struct v4l2_queryctrl *qc)
456{
406827cc
AK
457 switch (qc->id) {
458 case V4L2_CID_AUDIO_MUTE:
459 return v4l2_ctrl_query_fill(qc, 0, 1, 1, 1);
7002a4f3 460 }
406827cc 461
7002a4f3
DL
462 return -EINVAL;
463}
5aff308c 464
7002a4f3
DL
465static int vidioc_g_ctrl(struct file *file, void *priv,
466 struct v4l2_control *ctrl)
467{
c170ecf4 468 struct dsbr100_device *radio = video_drvdata(file);
1da177e4 469
3a0efc32
AK
470 /* safety check */
471 if (radio->removed)
472 return -EIO;
473
7002a4f3
DL
474 switch (ctrl->id) {
475 case V4L2_CID_AUDIO_MUTE:
476 ctrl->value = radio->muted;
477 return 0;
478 }
479 return -EINVAL;
480}
5aff308c 481
7002a4f3
DL
482static int vidioc_s_ctrl(struct file *file, void *priv,
483 struct v4l2_control *ctrl)
484{
c170ecf4 485 struct dsbr100_device *radio = video_drvdata(file);
417b7953 486 int retval;
5aff308c 487
3a0efc32
AK
488 /* safety check */
489 if (radio->removed)
490 return -EIO;
491
7002a4f3
DL
492 switch (ctrl->id) {
493 case V4L2_CID_AUDIO_MUTE:
494 if (ctrl->value) {
417b7953 495 retval = dsbr100_stop(radio);
d25cb646 496 if (retval < 0) {
aa82661b
GKH
497 dev_warn(&radio->usbdev->dev,
498 "Radio did not respond properly\n");
90b698dd
AK
499 return -EBUSY;
500 }
7002a4f3 501 } else {
417b7953 502 retval = dsbr100_start(radio);
d25cb646 503 if (retval < 0) {
aa82661b
GKH
504 dev_warn(&radio->usbdev->dev,
505 "Radio did not respond properly\n");
90b698dd
AK
506 return -EBUSY;
507 }
1da177e4 508 }
7002a4f3 509 return 0;
1da177e4 510 }
7002a4f3 511 return -EINVAL;
1da177e4
LT
512}
513
7002a4f3
DL
514static int vidioc_g_audio(struct file *file, void *priv,
515 struct v4l2_audio *a)
1da177e4 516{
7002a4f3
DL
517 if (a->index > 1)
518 return -EINVAL;
519
520 strcpy(a->name, "Radio");
521 a->capability = V4L2_AUDCAP_STEREO;
522 return 0;
523}
524
525static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
526{
527 *i = 0;
528 return 0;
529}
530
531static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
532{
533 if (i != 0)
534 return -EINVAL;
535 return 0;
536}
537
538static int vidioc_s_audio(struct file *file, void *priv,
539 struct v4l2_audio *a)
540{
541 if (a->index != 0)
542 return -EINVAL;
543 return 0;
1da177e4
LT
544}
545
bec43661 546static int usb_dsbr100_open(struct file *file)
1da177e4 547{
c170ecf4 548 struct dsbr100_device *radio = video_drvdata(file);
b9f35737 549 int retval;
1da177e4 550
d56dc612 551 lock_kernel();
1da177e4 552 radio->users = 1;
5aff308c
AC
553 radio->muted = 1;
554
417b7953
AK
555 retval = dsbr100_start(radio);
556 if (retval < 0) {
aa82661b
GKH
557 dev_warn(&radio->usbdev->dev,
558 "Radio did not start up properly\n");
1da177e4 559 radio->users = 0;
d56dc612 560 unlock_kernel();
1da177e4
LT
561 return -EIO;
562 }
b9f35737
AK
563
564 retval = dsbr100_setfreq(radio, radio->curfreq);
d25cb646 565 if (retval < 0)
290588e0
AK
566 dev_warn(&radio->usbdev->dev,
567 "set frequency failed\n");
b9f35737 568
d56dc612 569 unlock_kernel();
1da177e4
LT
570 return 0;
571}
572
bec43661 573static int usb_dsbr100_close(struct file *file)
1da177e4 574{
c170ecf4 575 struct dsbr100_device *radio = video_drvdata(file);
3a0efc32 576 int retval;
1da177e4
LT
577
578 if (!radio)
579 return -ENODEV;
3a0efc32 580
fdf9c997 581 mutex_lock(&radio->lock);
1da177e4 582 radio->users = 0;
fdf9c997
AK
583 mutex_unlock(&radio->lock);
584
3a0efc32
AK
585 if (!radio->removed) {
586 retval = dsbr100_stop(radio);
d25cb646 587 if (retval < 0) {
3a0efc32
AK
588 dev_warn(&radio->usbdev->dev,
589 "dsbr100_stop failed\n");
590 }
591
1da177e4
LT
592 }
593 return 0;
594}
595
04e0ffbb
AK
596/* Suspend device - stop device. */
597static int usb_dsbr100_suspend(struct usb_interface *intf, pm_message_t message)
598{
599 struct dsbr100_device *radio = usb_get_intfdata(intf);
600 int retval;
601
602 retval = dsbr100_stop(radio);
d25cb646 603 if (retval < 0)
04e0ffbb
AK
604 dev_warn(&intf->dev, "dsbr100_stop failed\n");
605
606 dev_info(&intf->dev, "going into suspend..\n");
607
608 return 0;
609}
610
611/* Resume device - start device. */
612static int usb_dsbr100_resume(struct usb_interface *intf)
613{
614 struct dsbr100_device *radio = usb_get_intfdata(intf);
615 int retval;
616
617 retval = dsbr100_start(radio);
d25cb646 618 if (retval < 0)
04e0ffbb
AK
619 dev_warn(&intf->dev, "dsbr100_start failed\n");
620
621 dev_info(&intf->dev, "coming out of suspend..\n");
622
623 return 0;
624}
625
fc55bcb0 626/* free data structures */
3a0efc32
AK
627static void usb_dsbr100_video_device_release(struct video_device *videodev)
628{
629 struct dsbr100_device *radio = videodev_to_radio(videodev);
630
406827cc 631 v4l2_device_unregister(&radio->v4l2_dev);
3a0efc32
AK
632 kfree(radio->transfer_buffer);
633 kfree(radio);
634}
635
7002a4f3 636/* File system interface */
bec43661 637static const struct v4l2_file_operations usb_dsbr100_fops = {
7002a4f3
DL
638 .owner = THIS_MODULE,
639 .open = usb_dsbr100_open,
640 .release = usb_dsbr100_close,
641 .ioctl = video_ioctl2,
7002a4f3
DL
642};
643
a399810c 644static const struct v4l2_ioctl_ops usb_dsbr100_ioctl_ops = {
7002a4f3
DL
645 .vidioc_querycap = vidioc_querycap,
646 .vidioc_g_tuner = vidioc_g_tuner,
647 .vidioc_s_tuner = vidioc_s_tuner,
648 .vidioc_g_frequency = vidioc_g_frequency,
649 .vidioc_s_frequency = vidioc_s_frequency,
650 .vidioc_queryctrl = vidioc_queryctrl,
651 .vidioc_g_ctrl = vidioc_g_ctrl,
652 .vidioc_s_ctrl = vidioc_s_ctrl,
653 .vidioc_g_audio = vidioc_g_audio,
654 .vidioc_s_audio = vidioc_s_audio,
655 .vidioc_g_input = vidioc_g_input,
656 .vidioc_s_input = vidioc_s_input,
657};
658
fc55bcb0 659/* check if the device is present and register with v4l and usb if it is */
7002a4f3
DL
660static int usb_dsbr100_probe(struct usb_interface *intf,
661 const struct usb_device_id *id)
662{
663 struct dsbr100_device *radio;
406827cc 664 struct v4l2_device *v4l2_dev;
417b7953 665 int retval;
7002a4f3 666
406827cc 667 radio = kzalloc(sizeof(struct dsbr100_device), GFP_KERNEL);
223377e7
AK
668
669 if (!radio)
7002a4f3 670 return -ENOMEM;
223377e7
AK
671
672 radio->transfer_buffer = kmalloc(TB_LEN, GFP_KERNEL);
673
674 if (!(radio->transfer_buffer)) {
863c86dd
ON
675 kfree(radio);
676 return -ENOMEM;
677 }
223377e7 678
406827cc
AK
679 v4l2_dev = &radio->v4l2_dev;
680
681 retval = v4l2_device_register(&intf->dev, v4l2_dev);
682 if (retval < 0) {
683 v4l2_err(v4l2_dev, "couldn't register v4l2_device\n");
684 kfree(radio->transfer_buffer);
685 kfree(radio);
686 return retval;
687 }
688
689 strlcpy(radio->videodev.name, v4l2_dev->name, sizeof(radio->videodev.name));
690 radio->videodev.v4l2_dev = v4l2_dev;
691 radio->videodev.fops = &usb_dsbr100_fops;
692 radio->videodev.ioctl_ops = &usb_dsbr100_ioctl_ops;
693 radio->videodev.release = usb_dsbr100_video_device_release;
694
3a0efc32 695 mutex_init(&radio->lock);
3a0efc32 696
7002a4f3
DL
697 radio->removed = 0;
698 radio->users = 0;
699 radio->usbdev = interface_to_usbdev(intf);
223377e7 700 radio->curfreq = FREQ_MIN * FREQ_MUL;
406827cc 701
3a0efc32 702 video_set_drvdata(&radio->videodev, radio);
406827cc 703
417b7953
AK
704 retval = video_register_device(&radio->videodev, VFL_TYPE_RADIO, radio_nr);
705 if (retval < 0) {
406827cc
AK
706 v4l2_err(v4l2_dev, "couldn't register video device\n");
707 v4l2_device_unregister(v4l2_dev);
863c86dd 708 kfree(radio->transfer_buffer);
7002a4f3
DL
709 kfree(radio);
710 return -EIO;
711 }
712 usb_set_intfdata(intf, radio);
713 return 0;
714}
715
1da177e4
LT
716static int __init dsbr100_init(void)
717{
718 int retval = usb_register(&usb_dsbr100_driver);
a482f327
GKH
719 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
720 DRIVER_DESC "\n");
1da177e4
LT
721 return retval;
722}
723
724static void __exit dsbr100_exit(void)
725{
726 usb_deregister(&usb_dsbr100_driver);
727}
728
729module_init (dsbr100_init);
730module_exit (dsbr100_exit);
731
732MODULE_AUTHOR( DRIVER_AUTHOR );
733MODULE_DESCRIPTION( DRIVER_DESC );
734MODULE_LICENSE("GPL");
This page took 0.499265 seconds and 5 git commands to generate.