2 * drivers/media/radio/si470x/radio-si470x-usb.c
4 * USB driver for radios with Silicon Labs Si470x FM Radio Receivers
6 * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
22 * - add firmware download/update support
26 /* driver definitions */
27 #define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
28 #define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
29 #define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
30 #define DRIVER_VERSION "1.0.10"
33 #include <linux/usb.h>
34 #include <linux/hid.h>
35 #include <linux/slab.h>
37 #include "radio-si470x.h"
40 /* USB Device ID List */
41 static const struct usb_device_id si470x_usb_driver_id_table
[] = {
42 /* Silicon Labs USB FM Radio Reference Design */
43 { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID
, 0, 0) },
44 /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
45 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID
, 0, 0) },
46 /* KWorld USB FM Radio SnapMusic Mobile 700 (FM700) */
47 { USB_DEVICE_AND_INTERFACE_INFO(0x1b80, 0xd700, USB_CLASS_HID
, 0, 0) },
48 /* Sanei Electric, Inc. FM USB Radio (sold as DealExtreme.com PCear) */
49 { USB_DEVICE_AND_INTERFACE_INFO(0x10c5, 0x819a, USB_CLASS_HID
, 0, 0) },
50 /* Axentia ALERT FM USB Receiver */
51 { USB_DEVICE_AND_INTERFACE_INFO(0x12cf, 0x7111, USB_CLASS_HID
, 0, 0) },
52 /* Terminating entry */
55 MODULE_DEVICE_TABLE(usb
, si470x_usb_driver_id_table
);
59 /**************************************************************************
61 **************************************************************************/
64 static int radio_nr
= -1;
65 module_param(radio_nr
, int, 0444);
66 MODULE_PARM_DESC(radio_nr
, "Radio Nr");
69 static unsigned int usb_timeout
= 500;
70 module_param(usb_timeout
, uint
, 0644);
71 MODULE_PARM_DESC(usb_timeout
, "USB timeout (ms): *500*");
73 /* RDS buffer blocks */
74 static unsigned int rds_buf
= 100;
75 module_param(rds_buf
, uint
, 0444);
76 MODULE_PARM_DESC(rds_buf
, "RDS buffer entries: *100*");
78 /* RDS maximum block errors */
79 static unsigned short max_rds_errors
= 1;
80 /* 0 means 0 errors requiring correction */
81 /* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
82 /* 2 means 3-5 errors requiring correction */
83 /* 3 means 6+ errors or errors in checkword, correction not possible */
84 module_param(max_rds_errors
, ushort
, 0644);
85 MODULE_PARM_DESC(max_rds_errors
, "RDS maximum block errors: *1*");
89 /**************************************************************************
91 **************************************************************************/
93 /* Reports 1-16 give direct read/write access to the 16 Si470x registers */
94 /* with the (REPORT_ID - 1) corresponding to the register address across USB */
95 /* endpoint 0 using GET_REPORT and SET_REPORT */
96 #define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
97 #define REGISTER_REPORT(reg) ((reg) + 1)
99 /* Report 17 gives direct read/write access to the entire Si470x register */
100 /* map across endpoint 0 using GET_REPORT and SET_REPORT */
101 #define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
102 #define ENTIRE_REPORT 17
104 /* Report 18 is used to send the lowest 6 Si470x registers up the HID */
105 /* interrupt endpoint 1 to Windows every 20 milliseconds for status */
106 #define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
107 #define RDS_REPORT 18
109 /* Report 19: LED state */
110 #define LED_REPORT_SIZE 3
111 #define LED_REPORT 19
113 /* Report 19: stream */
114 #define STREAM_REPORT_SIZE 3
115 #define STREAM_REPORT 19
117 /* Report 20: scratch */
118 #define SCRATCH_PAGE_SIZE 63
119 #define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
120 #define SCRATCH_REPORT 20
122 /* Reports 19-22: flash upgrade of the C8051F321 */
123 #define WRITE_REPORT_SIZE 4
124 #define WRITE_REPORT 19
125 #define FLASH_REPORT_SIZE 64
126 #define FLASH_REPORT 20
127 #define CRC_REPORT_SIZE 3
128 #define CRC_REPORT 21
129 #define RESPONSE_REPORT_SIZE 2
130 #define RESPONSE_REPORT 22
132 /* Report 23: currently unused, but can accept 60 byte reports on the HID */
133 /* interrupt out endpoint 2 every 1 millisecond */
134 #define UNUSED_REPORT 23
136 #define MAX_REPORT_SIZE 64
140 /**************************************************************************
141 * Software/Hardware Versions from Scratch Page
142 **************************************************************************/
143 #define RADIO_HW_VERSION 1
147 /**************************************************************************
148 * LED State Definitions
149 **************************************************************************/
150 #define LED_COMMAND 0x35
152 #define NO_CHANGE_LED 0x00
153 #define ALL_COLOR_LED 0x01 /* streaming state */
154 #define BLINK_GREEN_LED 0x02 /* connect state */
155 #define BLINK_RED_LED 0x04
156 #define BLINK_ORANGE_LED 0x10 /* disconnect state */
157 #define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
158 #define SOLID_RED_LED 0x40 /* bootload state */
159 #define SOLID_ORANGE_LED 0x80
163 /**************************************************************************
164 * Stream State Definitions
165 **************************************************************************/
166 #define STREAM_COMMAND 0x36
167 #define STREAM_VIDPID 0x00
168 #define STREAM_AUDIO 0xff
172 /**************************************************************************
173 * Bootloader / Flash Commands
174 **************************************************************************/
176 /* unique id sent to bootloader and required to put into a bootload state */
177 #define UNIQUE_BL_ID 0x34
179 /* mask for the flash data */
180 #define FLASH_DATA_MASK 0x55
182 /* bootloader commands */
183 #define GET_SW_VERSION_COMMAND 0x00
184 #define SET_PAGE_COMMAND 0x01
185 #define ERASE_PAGE_COMMAND 0x02
186 #define WRITE_PAGE_COMMAND 0x03
187 #define CRC_ON_PAGE_COMMAND 0x04
188 #define READ_FLASH_BYTE_COMMAND 0x05
189 #define RESET_DEVICE_COMMAND 0x06
190 #define GET_HW_VERSION_COMMAND 0x07
193 /* bootloader command responses */
194 #define COMMAND_OK 0x01
195 #define COMMAND_FAILED 0x02
196 #define COMMAND_PENDING 0x03
200 /**************************************************************************
201 * General Driver Functions - REGISTER_REPORTs
202 **************************************************************************/
205 * si470x_get_report - receive a HID report
207 static int si470x_get_report(struct si470x_device
*radio
, void *buf
, int size
)
209 unsigned char *report
= buf
;
212 retval
= usb_control_msg(radio
->usbdev
,
213 usb_rcvctrlpipe(radio
->usbdev
, 0),
215 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
217 buf
, size
, usb_timeout
);
220 dev_warn(&radio
->intf
->dev
,
221 "si470x_get_report: usb_control_msg returned %d\n",
228 * si470x_set_report - send a HID report
230 static int si470x_set_report(struct si470x_device
*radio
, void *buf
, int size
)
232 unsigned char *report
= buf
;
235 retval
= usb_control_msg(radio
->usbdev
,
236 usb_sndctrlpipe(radio
->usbdev
, 0),
238 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
240 buf
, size
, usb_timeout
);
243 dev_warn(&radio
->intf
->dev
,
244 "si470x_set_report: usb_control_msg returned %d\n",
251 * si470x_get_register - read register
253 int si470x_get_register(struct si470x_device
*radio
, int regnr
)
257 radio
->usb_buf
[0] = REGISTER_REPORT(regnr
);
259 retval
= si470x_get_report(radio
, radio
->usb_buf
, REGISTER_REPORT_SIZE
);
262 radio
->registers
[regnr
] = get_unaligned_be16(&radio
->usb_buf
[1]);
264 return (retval
< 0) ? -EINVAL
: 0;
269 * si470x_set_register - write register
271 int si470x_set_register(struct si470x_device
*radio
, int regnr
)
275 radio
->usb_buf
[0] = REGISTER_REPORT(regnr
);
276 put_unaligned_be16(radio
->registers
[regnr
], &radio
->usb_buf
[1]);
278 retval
= si470x_set_report(radio
, radio
->usb_buf
, REGISTER_REPORT_SIZE
);
280 return (retval
< 0) ? -EINVAL
: 0;
285 /**************************************************************************
286 * General Driver Functions - ENTIRE_REPORT
287 **************************************************************************/
290 * si470x_get_all_registers - read entire registers
292 static int si470x_get_all_registers(struct si470x_device
*radio
)
297 radio
->usb_buf
[0] = ENTIRE_REPORT
;
299 retval
= si470x_get_report(radio
, radio
->usb_buf
, ENTIRE_REPORT_SIZE
);
302 for (regnr
= 0; regnr
< RADIO_REGISTER_NUM
; regnr
++)
303 radio
->registers
[regnr
] = get_unaligned_be16(
304 &radio
->usb_buf
[regnr
* RADIO_REGISTER_SIZE
+ 1]);
306 return (retval
< 0) ? -EINVAL
: 0;
311 /**************************************************************************
312 * General Driver Functions - LED_REPORT
313 **************************************************************************/
316 * si470x_set_led_state - sets the led state
318 static int si470x_set_led_state(struct si470x_device
*radio
,
319 unsigned char led_state
)
323 radio
->usb_buf
[0] = LED_REPORT
;
324 radio
->usb_buf
[1] = LED_COMMAND
;
325 radio
->usb_buf
[2] = led_state
;
327 retval
= si470x_set_report(radio
, radio
->usb_buf
, LED_REPORT_SIZE
);
329 return (retval
< 0) ? -EINVAL
: 0;
334 /**************************************************************************
335 * General Driver Functions - SCRATCH_REPORT
336 **************************************************************************/
339 * si470x_get_scratch_versions - gets the scratch page and version infos
341 static int si470x_get_scratch_page_versions(struct si470x_device
*radio
)
345 radio
->usb_buf
[0] = SCRATCH_REPORT
;
347 retval
= si470x_get_report(radio
, radio
->usb_buf
, SCRATCH_REPORT_SIZE
);
350 dev_warn(&radio
->intf
->dev
, "si470x_get_scratch: si470x_get_report returned %d\n",
353 radio
->software_version
= radio
->usb_buf
[1];
354 radio
->hardware_version
= radio
->usb_buf
[2];
357 return (retval
< 0) ? -EINVAL
: 0;
362 /**************************************************************************
363 * RDS Driver Functions
364 **************************************************************************/
367 * si470x_int_in_callback - rds callback and processing function
369 * TODO: do we need to use mutex locks in some sections?
371 static void si470x_int_in_callback(struct urb
*urb
)
373 struct si470x_device
*radio
= urb
->context
;
376 unsigned char blocknum
;
377 unsigned short bler
; /* rds block errors */
379 unsigned char tmpbuf
[3];
382 if (urb
->status
== -ENOENT
||
383 urb
->status
== -ECONNRESET
||
384 urb
->status
== -ESHUTDOWN
) {
387 dev_warn(&radio
->intf
->dev
,
388 "non-zero urb status (%d)\n", urb
->status
);
389 goto resubmit
; /* Maybe we can recover. */
393 /* Sometimes the device returns len 0 packets */
394 if (urb
->actual_length
!= RDS_REPORT_SIZE
)
397 radio
->registers
[STATUSRSSI
] =
398 get_unaligned_be16(&radio
->int_in_buffer
[1]);
400 if (radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
)
401 complete(&radio
->completion
);
403 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
)) {
404 /* Update RDS registers with URB data */
405 for (regnr
= 1; regnr
< RDS_REGISTER_NUM
; regnr
++)
406 radio
->registers
[STATUSRSSI
+ regnr
] =
407 get_unaligned_be16(&radio
->int_in_buffer
[
408 regnr
* RADIO_REGISTER_SIZE
+ 1]);
410 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_RDSR
) == 0) {
411 /* No RDS group ready, better luck next time */
414 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_RDSS
) == 0) {
415 /* RDS decoder not synchronized */
418 for (blocknum
= 0; blocknum
< 4; blocknum
++) {
421 bler
= (radio
->registers
[STATUSRSSI
] &
422 STATUSRSSI_BLERA
) >> 9;
423 rds
= radio
->registers
[RDSA
];
426 bler
= (radio
->registers
[READCHAN
] &
427 READCHAN_BLERB
) >> 14;
428 rds
= radio
->registers
[RDSB
];
431 bler
= (radio
->registers
[READCHAN
] &
432 READCHAN_BLERC
) >> 12;
433 rds
= radio
->registers
[RDSC
];
436 bler
= (radio
->registers
[READCHAN
] &
437 READCHAN_BLERD
) >> 10;
438 rds
= radio
->registers
[RDSD
];
442 /* Fill the V4L2 RDS buffer */
443 put_unaligned_le16(rds
, &tmpbuf
);
444 tmpbuf
[2] = blocknum
; /* offset name */
445 tmpbuf
[2] |= blocknum
<< 3; /* received offset */
446 if (bler
> max_rds_errors
)
447 tmpbuf
[2] |= 0x80; /* uncorrectable errors */
449 tmpbuf
[2] |= 0x40; /* corrected error(s) */
451 /* copy RDS block to internal buffer */
452 memcpy(&radio
->buffer
[radio
->wr_index
], &tmpbuf
, 3);
453 radio
->wr_index
+= 3;
455 /* wrap write pointer */
456 if (radio
->wr_index
>= radio
->buf_size
)
459 /* check for overflow */
460 if (radio
->wr_index
== radio
->rd_index
) {
461 /* increment and wrap read pointer */
462 radio
->rd_index
+= 3;
463 if (radio
->rd_index
>= radio
->buf_size
)
467 if (radio
->wr_index
!= radio
->rd_index
)
468 wake_up_interruptible(&radio
->read_queue
);
472 /* Resubmit if we're still running. */
473 if (radio
->int_in_running
&& radio
->usbdev
) {
474 retval
= usb_submit_urb(radio
->int_in_urb
, GFP_ATOMIC
);
476 dev_warn(&radio
->intf
->dev
,
477 "resubmitting urb failed (%d)", retval
);
478 radio
->int_in_running
= 0;
481 radio
->status_rssi_auto_update
= radio
->int_in_running
;
485 int si470x_fops_open(struct file
*file
)
487 return v4l2_fh_open(file
);
490 int si470x_fops_release(struct file
*file
)
492 return v4l2_fh_release(file
);
495 static void si470x_usb_release(struct v4l2_device
*v4l2_dev
)
497 struct si470x_device
*radio
=
498 container_of(v4l2_dev
, struct si470x_device
, v4l2_dev
);
500 usb_free_urb(radio
->int_in_urb
);
501 v4l2_ctrl_handler_free(&radio
->hdl
);
502 v4l2_device_unregister(&radio
->v4l2_dev
);
503 kfree(radio
->int_in_buffer
);
504 kfree(radio
->buffer
);
505 kfree(radio
->usb_buf
);
510 /**************************************************************************
511 * Video4Linux Interface
512 **************************************************************************/
515 * si470x_vidioc_querycap - query device capabilities
517 int si470x_vidioc_querycap(struct file
*file
, void *priv
,
518 struct v4l2_capability
*capability
)
520 struct si470x_device
*radio
= video_drvdata(file
);
522 strlcpy(capability
->driver
, DRIVER_NAME
, sizeof(capability
->driver
));
523 strlcpy(capability
->card
, DRIVER_CARD
, sizeof(capability
->card
));
524 usb_make_path(radio
->usbdev
, capability
->bus_info
,
525 sizeof(capability
->bus_info
));
526 capability
->device_caps
= V4L2_CAP_HW_FREQ_SEEK
| V4L2_CAP_READWRITE
|
527 V4L2_CAP_TUNER
| V4L2_CAP_RADIO
| V4L2_CAP_RDS_CAPTURE
;
528 capability
->capabilities
= capability
->device_caps
| V4L2_CAP_DEVICE_CAPS
;
533 static int si470x_start_usb(struct si470x_device
*radio
)
537 /* initialize interrupt urb */
538 usb_fill_int_urb(radio
->int_in_urb
, radio
->usbdev
,
539 usb_rcvintpipe(radio
->usbdev
,
540 radio
->int_in_endpoint
->bEndpointAddress
),
541 radio
->int_in_buffer
,
542 le16_to_cpu(radio
->int_in_endpoint
->wMaxPacketSize
),
543 si470x_int_in_callback
,
545 radio
->int_in_endpoint
->bInterval
);
547 radio
->int_in_running
= 1;
550 retval
= usb_submit_urb(radio
->int_in_urb
, GFP_KERNEL
);
552 dev_info(&radio
->intf
->dev
,
553 "submitting int urb failed (%d)\n", retval
);
554 radio
->int_in_running
= 0;
556 radio
->status_rssi_auto_update
= radio
->int_in_running
;
559 retval
= si470x_start(radio
);
563 v4l2_ctrl_handler_setup(&radio
->hdl
);
568 /**************************************************************************
570 **************************************************************************/
573 * si470x_usb_driver_probe - probe for the device
575 static int si470x_usb_driver_probe(struct usb_interface
*intf
,
576 const struct usb_device_id
*id
)
578 struct si470x_device
*radio
;
579 struct usb_host_interface
*iface_desc
;
580 struct usb_endpoint_descriptor
*endpoint
;
581 int i
, int_end_size
, retval
= 0;
582 unsigned char version_warning
= 0;
584 /* private data allocation and initialization */
585 radio
= kzalloc(sizeof(struct si470x_device
), GFP_KERNEL
);
590 radio
->usb_buf
= kmalloc(MAX_REPORT_SIZE
, GFP_KERNEL
);
591 if (radio
->usb_buf
== NULL
) {
595 radio
->usbdev
= interface_to_usbdev(intf
);
597 radio
->band
= 1; /* Default to 76 - 108 MHz */
598 mutex_init(&radio
->lock
);
599 init_completion(&radio
->completion
);
601 iface_desc
= intf
->cur_altsetting
;
603 /* Set up interrupt endpoint information. */
604 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
605 endpoint
= &iface_desc
->endpoint
[i
].desc
;
606 if (usb_endpoint_is_int_in(endpoint
))
607 radio
->int_in_endpoint
= endpoint
;
609 if (!radio
->int_in_endpoint
) {
610 dev_info(&intf
->dev
, "could not find interrupt in endpoint\n");
615 int_end_size
= le16_to_cpu(radio
->int_in_endpoint
->wMaxPacketSize
);
617 radio
->int_in_buffer
= kmalloc(int_end_size
, GFP_KERNEL
);
618 if (!radio
->int_in_buffer
) {
619 dev_info(&intf
->dev
, "could not allocate int_in_buffer");
624 radio
->int_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
625 if (!radio
->int_in_urb
) {
630 radio
->v4l2_dev
.release
= si470x_usb_release
;
633 * The si470x SiLabs reference design uses the same USB IDs as
634 * 'Thanko's Raremono' si4734 based receiver. So check here which we
635 * have: attempt to read the device ID from the si470x: the lower 12
636 * bits should be 0x0242 for the si470x.
638 * We use this check to determine which device we are dealing with.
640 if (id
->idVendor
== 0x10c4 && id
->idProduct
== 0x818a) {
641 retval
= usb_control_msg(radio
->usbdev
,
642 usb_rcvctrlpipe(radio
->usbdev
, 0),
644 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
646 radio
->usb_buf
, 3, 500);
648 (get_unaligned_be16(&radio
->usb_buf
[1]) & 0xfff) != 0x0242) {
649 dev_info(&intf
->dev
, "this is not a si470x device.\n");
655 retval
= v4l2_device_register(&intf
->dev
, &radio
->v4l2_dev
);
657 dev_err(&intf
->dev
, "couldn't register v4l2_device\n");
661 v4l2_ctrl_handler_init(&radio
->hdl
, 2);
662 v4l2_ctrl_new_std(&radio
->hdl
, &si470x_ctrl_ops
,
663 V4L2_CID_AUDIO_MUTE
, 0, 1, 1, 1);
664 v4l2_ctrl_new_std(&radio
->hdl
, &si470x_ctrl_ops
,
665 V4L2_CID_AUDIO_VOLUME
, 0, 15, 1, 15);
666 if (radio
->hdl
.error
) {
667 retval
= radio
->hdl
.error
;
668 dev_err(&intf
->dev
, "couldn't register control\n");
671 radio
->videodev
= si470x_viddev_template
;
672 radio
->videodev
.ctrl_handler
= &radio
->hdl
;
673 radio
->videodev
.lock
= &radio
->lock
;
674 radio
->videodev
.v4l2_dev
= &radio
->v4l2_dev
;
675 radio
->videodev
.release
= video_device_release_empty
;
676 video_set_drvdata(&radio
->videodev
, radio
);
678 /* get device and chip versions */
679 if (si470x_get_all_registers(radio
) < 0) {
683 dev_info(&intf
->dev
, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
684 radio
->registers
[DEVICEID
], radio
->registers
[SI_CHIPID
]);
685 if ((radio
->registers
[SI_CHIPID
] & SI_CHIPID_FIRMWARE
) < RADIO_FW_VERSION
) {
687 "This driver is known to work with firmware version %hu,\n",
690 "but the device has firmware version %hu.\n",
691 radio
->registers
[SI_CHIPID
] & SI_CHIPID_FIRMWARE
);
695 /* get software and hardware versions */
696 if (si470x_get_scratch_page_versions(radio
) < 0) {
700 dev_info(&intf
->dev
, "software version %d, hardware version %d\n",
701 radio
->software_version
, radio
->hardware_version
);
702 if (radio
->hardware_version
< RADIO_HW_VERSION
) {
704 "This driver is known to work with hardware version %hu,\n",
707 "but the device has hardware version %hu.\n",
708 radio
->hardware_version
);
712 /* give out version warning */
713 if (version_warning
== 1) {
715 "If you have some trouble using this driver,\n");
717 "please report to V4L ML at linux-media@vger.kernel.org\n");
720 /* set led to connect state */
721 si470x_set_led_state(radio
, BLINK_GREEN_LED
);
723 /* rds buffer allocation */
724 radio
->buf_size
= rds_buf
* 3;
725 radio
->buffer
= kmalloc(radio
->buf_size
, GFP_KERNEL
);
726 if (!radio
->buffer
) {
731 /* rds buffer configuration */
734 init_waitqueue_head(&radio
->read_queue
);
735 usb_set_intfdata(intf
, radio
);
738 retval
= si470x_start_usb(radio
);
742 /* set initial frequency */
743 si470x_set_freq(radio
, 87.5 * FREQ_MUL
); /* available in all regions */
745 /* register video device */
746 retval
= video_register_device(&radio
->videodev
, VFL_TYPE_RADIO
,
749 dev_err(&intf
->dev
, "Could not register video device\n");
755 kfree(radio
->buffer
);
757 v4l2_ctrl_handler_free(&radio
->hdl
);
759 v4l2_device_unregister(&radio
->v4l2_dev
);
761 usb_free_urb(radio
->int_in_urb
);
763 kfree(radio
->int_in_buffer
);
765 kfree(radio
->usb_buf
);
774 * si470x_usb_driver_suspend - suspend the device
776 static int si470x_usb_driver_suspend(struct usb_interface
*intf
,
777 pm_message_t message
)
779 struct si470x_device
*radio
= usb_get_intfdata(intf
);
781 dev_info(&intf
->dev
, "suspending now...\n");
783 /* shutdown interrupt handler */
784 if (radio
->int_in_running
) {
785 radio
->int_in_running
= 0;
786 if (radio
->int_in_urb
)
787 usb_kill_urb(radio
->int_in_urb
);
790 /* cancel read processes */
791 wake_up_interruptible(&radio
->read_queue
);
800 * si470x_usb_driver_resume - resume the device
802 static int si470x_usb_driver_resume(struct usb_interface
*intf
)
804 struct si470x_device
*radio
= usb_get_intfdata(intf
);
807 dev_info(&intf
->dev
, "resuming now...\n");
810 ret
= si470x_start_usb(radio
);
812 v4l2_ctrl_handler_setup(&radio
->hdl
);
819 * si470x_usb_driver_disconnect - disconnect the device
821 static void si470x_usb_driver_disconnect(struct usb_interface
*intf
)
823 struct si470x_device
*radio
= usb_get_intfdata(intf
);
825 mutex_lock(&radio
->lock
);
826 v4l2_device_disconnect(&radio
->v4l2_dev
);
827 video_unregister_device(&radio
->videodev
);
828 usb_set_intfdata(intf
, NULL
);
829 mutex_unlock(&radio
->lock
);
830 v4l2_device_put(&radio
->v4l2_dev
);
835 * si470x_usb_driver - usb driver interface
837 * A note on suspend/resume: this driver had only empty suspend/resume
838 * functions, and when I tried to test suspend/resume it always disconnected
839 * instead of resuming (using my ADS InstantFM stick). So I've decided to
840 * remove these callbacks until someone else with better hardware can
841 * implement and test this.
843 static struct usb_driver si470x_usb_driver
= {
845 .probe
= si470x_usb_driver_probe
,
846 .disconnect
= si470x_usb_driver_disconnect
,
847 .suspend
= si470x_usb_driver_suspend
,
848 .resume
= si470x_usb_driver_resume
,
849 .reset_resume
= si470x_usb_driver_resume
,
850 .id_table
= si470x_usb_driver_id_table
,
853 module_usb_driver(si470x_usb_driver
);
855 MODULE_LICENSE("GPL");
856 MODULE_AUTHOR(DRIVER_AUTHOR
);
857 MODULE_DESCRIPTION(DRIVER_DESC
);
858 MODULE_VERSION(DRIVER_VERSION
);