1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * drivers/media/radio/si470x/radio-si470x-usb.c
5 * USB driver for radios with Silicon Labs Si470x FM Radio Receivers
7 * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net>
13 * - add firmware download/update support
17 /* driver definitions */
18 #define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
19 #define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
20 #define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
21 #define DRIVER_VERSION "1.0.10"
24 #include <linux/usb.h>
25 #include <linux/hid.h>
26 #include <linux/slab.h>
28 #include "radio-si470x.h"
31 /* USB Device ID List */
32 static const struct usb_device_id si470x_usb_driver_id_table
[] = {
33 /* Silicon Labs USB FM Radio Reference Design */
34 { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID
, 0, 0) },
35 /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
36 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID
, 0, 0) },
37 /* KWorld USB FM Radio SnapMusic Mobile 700 (FM700) */
38 { USB_DEVICE_AND_INTERFACE_INFO(0x1b80, 0xd700, USB_CLASS_HID
, 0, 0) },
39 /* Sanei Electric, Inc. FM USB Radio (sold as DealExtreme.com PCear) */
40 { USB_DEVICE_AND_INTERFACE_INFO(0x10c5, 0x819a, USB_CLASS_HID
, 0, 0) },
41 /* Axentia ALERT FM USB Receiver */
42 { USB_DEVICE_AND_INTERFACE_INFO(0x12cf, 0x7111, USB_CLASS_HID
, 0, 0) },
43 /* Terminating entry */
46 MODULE_DEVICE_TABLE(usb
, si470x_usb_driver_id_table
);
50 /**************************************************************************
52 **************************************************************************/
55 static int radio_nr
= -1;
56 module_param(radio_nr
, int, 0444);
57 MODULE_PARM_DESC(radio_nr
, "Radio Nr");
60 static unsigned int usb_timeout
= 500;
61 module_param(usb_timeout
, uint
, 0644);
62 MODULE_PARM_DESC(usb_timeout
, "USB timeout (ms): *500*");
64 /* RDS buffer blocks */
65 static unsigned int rds_buf
= 100;
66 module_param(rds_buf
, uint
, 0444);
67 MODULE_PARM_DESC(rds_buf
, "RDS buffer entries: *100*");
69 /* RDS maximum block errors */
70 static unsigned short max_rds_errors
= 1;
71 /* 0 means 0 errors requiring correction */
72 /* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
73 /* 2 means 3-5 errors requiring correction */
74 /* 3 means 6+ errors or errors in checkword, correction not possible */
75 module_param(max_rds_errors
, ushort
, 0644);
76 MODULE_PARM_DESC(max_rds_errors
, "RDS maximum block errors: *1*");
80 /**************************************************************************
82 **************************************************************************/
84 /* Reports 1-16 give direct read/write access to the 16 Si470x registers */
85 /* with the (REPORT_ID - 1) corresponding to the register address across USB */
86 /* endpoint 0 using GET_REPORT and SET_REPORT */
87 #define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
88 #define REGISTER_REPORT(reg) ((reg) + 1)
90 /* Report 17 gives direct read/write access to the entire Si470x register */
91 /* map across endpoint 0 using GET_REPORT and SET_REPORT */
92 #define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
93 #define ENTIRE_REPORT 17
95 /* Report 18 is used to send the lowest 6 Si470x registers up the HID */
96 /* interrupt endpoint 1 to Windows every 20 milliseconds for status */
97 #define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
100 /* Report 19: LED state */
101 #define LED_REPORT_SIZE 3
102 #define LED_REPORT 19
104 /* Report 19: stream */
105 #define STREAM_REPORT_SIZE 3
106 #define STREAM_REPORT 19
108 /* Report 20: scratch */
109 #define SCRATCH_PAGE_SIZE 63
110 #define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
111 #define SCRATCH_REPORT 20
113 /* Reports 19-22: flash upgrade of the C8051F321 */
114 #define WRITE_REPORT_SIZE 4
115 #define WRITE_REPORT 19
116 #define FLASH_REPORT_SIZE 64
117 #define FLASH_REPORT 20
118 #define CRC_REPORT_SIZE 3
119 #define CRC_REPORT 21
120 #define RESPONSE_REPORT_SIZE 2
121 #define RESPONSE_REPORT 22
123 /* Report 23: currently unused, but can accept 60 byte reports on the HID */
124 /* interrupt out endpoint 2 every 1 millisecond */
125 #define UNUSED_REPORT 23
127 #define MAX_REPORT_SIZE 64
131 /**************************************************************************
132 * Software/Hardware Versions from Scratch Page
133 **************************************************************************/
134 #define RADIO_HW_VERSION 1
138 /**************************************************************************
139 * LED State Definitions
140 **************************************************************************/
141 #define LED_COMMAND 0x35
143 #define NO_CHANGE_LED 0x00
144 #define ALL_COLOR_LED 0x01 /* streaming state */
145 #define BLINK_GREEN_LED 0x02 /* connect state */
146 #define BLINK_RED_LED 0x04
147 #define BLINK_ORANGE_LED 0x10 /* disconnect state */
148 #define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
149 #define SOLID_RED_LED 0x40 /* bootload state */
150 #define SOLID_ORANGE_LED 0x80
154 /**************************************************************************
155 * Stream State Definitions
156 **************************************************************************/
157 #define STREAM_COMMAND 0x36
158 #define STREAM_VIDPID 0x00
159 #define STREAM_AUDIO 0xff
163 /**************************************************************************
164 * Bootloader / Flash Commands
165 **************************************************************************/
167 /* unique id sent to bootloader and required to put into a bootload state */
168 #define UNIQUE_BL_ID 0x34
170 /* mask for the flash data */
171 #define FLASH_DATA_MASK 0x55
173 /* bootloader commands */
174 #define GET_SW_VERSION_COMMAND 0x00
175 #define SET_PAGE_COMMAND 0x01
176 #define ERASE_PAGE_COMMAND 0x02
177 #define WRITE_PAGE_COMMAND 0x03
178 #define CRC_ON_PAGE_COMMAND 0x04
179 #define READ_FLASH_BYTE_COMMAND 0x05
180 #define RESET_DEVICE_COMMAND 0x06
181 #define GET_HW_VERSION_COMMAND 0x07
184 /* bootloader command responses */
185 #define COMMAND_OK 0x01
186 #define COMMAND_FAILED 0x02
187 #define COMMAND_PENDING 0x03
191 /**************************************************************************
192 * General Driver Functions - REGISTER_REPORTs
193 **************************************************************************/
196 * si470x_get_report - receive a HID report
198 static int si470x_get_report(struct si470x_device
*radio
, void *buf
, int size
)
200 unsigned char *report
= buf
;
203 retval
= usb_control_msg(radio
->usbdev
,
204 usb_rcvctrlpipe(radio
->usbdev
, 0),
206 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
208 buf
, size
, usb_timeout
);
211 dev_warn(&radio
->intf
->dev
,
212 "si470x_get_report: usb_control_msg returned %d\n",
219 * si470x_set_report - send a HID report
221 static int si470x_set_report(struct si470x_device
*radio
, void *buf
, int size
)
223 unsigned char *report
= buf
;
226 retval
= usb_control_msg(radio
->usbdev
,
227 usb_sndctrlpipe(radio
->usbdev
, 0),
229 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_OUT
,
231 buf
, size
, usb_timeout
);
234 dev_warn(&radio
->intf
->dev
,
235 "si470x_set_report: usb_control_msg returned %d\n",
242 * si470x_get_register - read register
244 static int si470x_get_register(struct si470x_device
*radio
, int regnr
)
248 radio
->usb_buf
[0] = REGISTER_REPORT(regnr
);
250 retval
= si470x_get_report(radio
, radio
->usb_buf
, REGISTER_REPORT_SIZE
);
253 radio
->registers
[regnr
] = get_unaligned_be16(&radio
->usb_buf
[1]);
255 return (retval
< 0) ? -EINVAL
: 0;
260 * si470x_set_register - write register
262 static int si470x_set_register(struct si470x_device
*radio
, int regnr
)
266 radio
->usb_buf
[0] = REGISTER_REPORT(regnr
);
267 put_unaligned_be16(radio
->registers
[regnr
], &radio
->usb_buf
[1]);
269 retval
= si470x_set_report(radio
, radio
->usb_buf
, REGISTER_REPORT_SIZE
);
271 return (retval
< 0) ? -EINVAL
: 0;
276 /**************************************************************************
277 * General Driver Functions - ENTIRE_REPORT
278 **************************************************************************/
281 * si470x_get_all_registers - read entire registers
283 static int si470x_get_all_registers(struct si470x_device
*radio
)
288 radio
->usb_buf
[0] = ENTIRE_REPORT
;
290 retval
= si470x_get_report(radio
, radio
->usb_buf
, ENTIRE_REPORT_SIZE
);
293 for (regnr
= 0; regnr
< RADIO_REGISTER_NUM
; regnr
++)
294 radio
->registers
[regnr
] = get_unaligned_be16(
295 &radio
->usb_buf
[regnr
* RADIO_REGISTER_SIZE
+ 1]);
297 return (retval
< 0) ? -EINVAL
: 0;
302 /**************************************************************************
303 * General Driver Functions - LED_REPORT
304 **************************************************************************/
307 * si470x_set_led_state - sets the led state
309 static int si470x_set_led_state(struct si470x_device
*radio
,
310 unsigned char led_state
)
314 radio
->usb_buf
[0] = LED_REPORT
;
315 radio
->usb_buf
[1] = LED_COMMAND
;
316 radio
->usb_buf
[2] = led_state
;
318 retval
= si470x_set_report(radio
, radio
->usb_buf
, LED_REPORT_SIZE
);
320 return (retval
< 0) ? -EINVAL
: 0;
325 /**************************************************************************
326 * General Driver Functions - SCRATCH_REPORT
327 **************************************************************************/
330 * si470x_get_scratch_versions - gets the scratch page and version infos
332 static int si470x_get_scratch_page_versions(struct si470x_device
*radio
)
336 radio
->usb_buf
[0] = SCRATCH_REPORT
;
338 retval
= si470x_get_report(radio
, radio
->usb_buf
, SCRATCH_REPORT_SIZE
);
341 dev_warn(&radio
->intf
->dev
, "si470x_get_scratch: si470x_get_report returned %d\n",
344 radio
->software_version
= radio
->usb_buf
[1];
345 radio
->hardware_version
= radio
->usb_buf
[2];
348 return (retval
< 0) ? -EINVAL
: 0;
353 /**************************************************************************
354 * RDS Driver Functions
355 **************************************************************************/
358 * si470x_int_in_callback - rds callback and processing function
360 * TODO: do we need to use mutex locks in some sections?
362 static void si470x_int_in_callback(struct urb
*urb
)
364 struct si470x_device
*radio
= urb
->context
;
367 unsigned char blocknum
;
368 unsigned short bler
; /* rds block errors */
370 unsigned char tmpbuf
[3];
373 if (urb
->status
== -ENOENT
||
374 urb
->status
== -ECONNRESET
||
375 urb
->status
== -ESHUTDOWN
) {
378 dev_warn(&radio
->intf
->dev
,
379 "non-zero urb status (%d)\n", urb
->status
);
380 goto resubmit
; /* Maybe we can recover. */
384 /* Sometimes the device returns len 0 packets */
385 if (urb
->actual_length
!= RDS_REPORT_SIZE
)
388 radio
->registers
[STATUSRSSI
] =
389 get_unaligned_be16(&radio
->int_in_buffer
[1]);
391 if (radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
)
392 complete(&radio
->completion
);
394 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
)) {
395 /* Update RDS registers with URB data */
396 for (regnr
= 1; regnr
< RDS_REGISTER_NUM
; regnr
++)
397 radio
->registers
[STATUSRSSI
+ regnr
] =
398 get_unaligned_be16(&radio
->int_in_buffer
[
399 regnr
* RADIO_REGISTER_SIZE
+ 1]);
401 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_RDSR
) == 0) {
402 /* No RDS group ready, better luck next time */
405 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_RDSS
) == 0) {
406 /* RDS decoder not synchronized */
409 for (blocknum
= 0; blocknum
< 4; blocknum
++) {
412 bler
= (radio
->registers
[STATUSRSSI
] &
413 STATUSRSSI_BLERA
) >> 9;
414 rds
= radio
->registers
[RDSA
];
417 bler
= (radio
->registers
[READCHAN
] &
418 READCHAN_BLERB
) >> 14;
419 rds
= radio
->registers
[RDSB
];
422 bler
= (radio
->registers
[READCHAN
] &
423 READCHAN_BLERC
) >> 12;
424 rds
= radio
->registers
[RDSC
];
427 bler
= (radio
->registers
[READCHAN
] &
428 READCHAN_BLERD
) >> 10;
429 rds
= radio
->registers
[RDSD
];
433 /* Fill the V4L2 RDS buffer */
434 put_unaligned_le16(rds
, &tmpbuf
);
435 tmpbuf
[2] = blocknum
; /* offset name */
436 tmpbuf
[2] |= blocknum
<< 3; /* received offset */
437 if (bler
> max_rds_errors
)
438 tmpbuf
[2] |= 0x80; /* uncorrectable errors */
440 tmpbuf
[2] |= 0x40; /* corrected error(s) */
442 /* copy RDS block to internal buffer */
443 memcpy(&radio
->buffer
[radio
->wr_index
], &tmpbuf
, 3);
444 radio
->wr_index
+= 3;
446 /* wrap write pointer */
447 if (radio
->wr_index
>= radio
->buf_size
)
450 /* check for overflow */
451 if (radio
->wr_index
== radio
->rd_index
) {
452 /* increment and wrap read pointer */
453 radio
->rd_index
+= 3;
454 if (radio
->rd_index
>= radio
->buf_size
)
458 if (radio
->wr_index
!= radio
->rd_index
)
459 wake_up_interruptible(&radio
->read_queue
);
463 /* Resubmit if we're still running. */
464 if (radio
->int_in_running
&& radio
->usbdev
) {
465 retval
= usb_submit_urb(radio
->int_in_urb
, GFP_ATOMIC
);
467 dev_warn(&radio
->intf
->dev
,
468 "resubmitting urb failed (%d)", retval
);
469 radio
->int_in_running
= 0;
472 radio
->status_rssi_auto_update
= radio
->int_in_running
;
476 static int si470x_fops_open(struct file
*file
)
478 return v4l2_fh_open(file
);
481 static int si470x_fops_release(struct file
*file
)
483 return v4l2_fh_release(file
);
486 static void si470x_usb_release(struct v4l2_device
*v4l2_dev
)
488 struct si470x_device
*radio
=
489 container_of(v4l2_dev
, struct si470x_device
, v4l2_dev
);
491 usb_free_urb(radio
->int_in_urb
);
492 v4l2_ctrl_handler_free(&radio
->hdl
);
493 v4l2_device_unregister(&radio
->v4l2_dev
);
494 kfree(radio
->int_in_buffer
);
495 kfree(radio
->buffer
);
496 kfree(radio
->usb_buf
);
501 /**************************************************************************
502 * Video4Linux Interface
503 **************************************************************************/
506 * si470x_vidioc_querycap - query device capabilities
508 static int si470x_vidioc_querycap(struct file
*file
, void *priv
,
509 struct v4l2_capability
*capability
)
511 struct si470x_device
*radio
= video_drvdata(file
);
513 strscpy(capability
->driver
, DRIVER_NAME
, sizeof(capability
->driver
));
514 strscpy(capability
->card
, DRIVER_CARD
, sizeof(capability
->card
));
515 usb_make_path(radio
->usbdev
, capability
->bus_info
,
516 sizeof(capability
->bus_info
));
521 static int si470x_start_usb(struct si470x_device
*radio
)
525 /* initialize interrupt urb */
526 usb_fill_int_urb(radio
->int_in_urb
, radio
->usbdev
,
527 usb_rcvintpipe(radio
->usbdev
,
528 radio
->int_in_endpoint
->bEndpointAddress
),
529 radio
->int_in_buffer
,
530 le16_to_cpu(radio
->int_in_endpoint
->wMaxPacketSize
),
531 si470x_int_in_callback
,
533 radio
->int_in_endpoint
->bInterval
);
535 radio
->int_in_running
= 1;
538 retval
= usb_submit_urb(radio
->int_in_urb
, GFP_KERNEL
);
540 dev_info(&radio
->intf
->dev
,
541 "submitting int urb failed (%d)\n", retval
);
542 radio
->int_in_running
= 0;
544 radio
->status_rssi_auto_update
= radio
->int_in_running
;
547 retval
= si470x_start(radio
);
551 v4l2_ctrl_handler_setup(&radio
->hdl
);
556 /**************************************************************************
558 **************************************************************************/
561 * si470x_usb_driver_probe - probe for the device
563 static int si470x_usb_driver_probe(struct usb_interface
*intf
,
564 const struct usb_device_id
*id
)
566 struct si470x_device
*radio
;
567 struct usb_host_interface
*iface_desc
;
568 struct usb_endpoint_descriptor
*endpoint
;
569 int i
, int_end_size
, retval
;
570 unsigned char version_warning
= 0;
572 /* private data allocation and initialization */
573 radio
= kzalloc(sizeof(struct si470x_device
), GFP_KERNEL
);
578 radio
->usb_buf
= kmalloc(MAX_REPORT_SIZE
, GFP_KERNEL
);
579 if (radio
->usb_buf
== NULL
) {
583 radio
->usbdev
= interface_to_usbdev(intf
);
585 radio
->band
= 1; /* Default to 76 - 108 MHz */
586 mutex_init(&radio
->lock
);
587 init_completion(&radio
->completion
);
589 radio
->get_register
= si470x_get_register
;
590 radio
->set_register
= si470x_set_register
;
591 radio
->fops_open
= si470x_fops_open
;
592 radio
->fops_release
= si470x_fops_release
;
593 radio
->vidioc_querycap
= si470x_vidioc_querycap
;
595 iface_desc
= intf
->cur_altsetting
;
597 /* Set up interrupt endpoint information. */
598 for (i
= 0; i
< iface_desc
->desc
.bNumEndpoints
; ++i
) {
599 endpoint
= &iface_desc
->endpoint
[i
].desc
;
600 if (usb_endpoint_is_int_in(endpoint
))
601 radio
->int_in_endpoint
= endpoint
;
603 if (!radio
->int_in_endpoint
) {
604 dev_info(&intf
->dev
, "could not find interrupt in endpoint\n");
609 int_end_size
= le16_to_cpu(radio
->int_in_endpoint
->wMaxPacketSize
);
611 radio
->int_in_buffer
= kmalloc(int_end_size
, GFP_KERNEL
);
612 if (!radio
->int_in_buffer
) {
613 dev_info(&intf
->dev
, "could not allocate int_in_buffer");
618 radio
->int_in_urb
= usb_alloc_urb(0, GFP_KERNEL
);
619 if (!radio
->int_in_urb
) {
624 radio
->v4l2_dev
.release
= si470x_usb_release
;
627 * The si470x SiLabs reference design uses the same USB IDs as
628 * 'Thanko's Raremono' si4734 based receiver. So check here which we
629 * have: attempt to read the device ID from the si470x: the lower 12
630 * bits should be 0x0242 for the si470x.
632 * We use this check to determine which device we are dealing with.
634 if (id
->idVendor
== 0x10c4 && id
->idProduct
== 0x818a) {
635 retval
= usb_control_msg(radio
->usbdev
,
636 usb_rcvctrlpipe(radio
->usbdev
, 0),
638 USB_TYPE_CLASS
| USB_RECIP_INTERFACE
| USB_DIR_IN
,
640 radio
->usb_buf
, 3, 500);
642 (get_unaligned_be16(&radio
->usb_buf
[1]) & 0xfff) != 0x0242) {
643 dev_info(&intf
->dev
, "this is not a si470x device.\n");
649 retval
= v4l2_device_register(&intf
->dev
, &radio
->v4l2_dev
);
651 dev_err(&intf
->dev
, "couldn't register v4l2_device\n");
655 v4l2_ctrl_handler_init(&radio
->hdl
, 2);
656 v4l2_ctrl_new_std(&radio
->hdl
, &si470x_ctrl_ops
,
657 V4L2_CID_AUDIO_MUTE
, 0, 1, 1, 1);
658 v4l2_ctrl_new_std(&radio
->hdl
, &si470x_ctrl_ops
,
659 V4L2_CID_AUDIO_VOLUME
, 0, 15, 1, 15);
660 if (radio
->hdl
.error
) {
661 retval
= radio
->hdl
.error
;
662 dev_err(&intf
->dev
, "couldn't register control\n");
665 radio
->videodev
= si470x_viddev_template
;
666 radio
->videodev
.ctrl_handler
= &radio
->hdl
;
667 radio
->videodev
.lock
= &radio
->lock
;
668 radio
->videodev
.v4l2_dev
= &radio
->v4l2_dev
;
669 radio
->videodev
.release
= video_device_release_empty
;
670 radio
->videodev
.device_caps
=
671 V4L2_CAP_HW_FREQ_SEEK
| V4L2_CAP_READWRITE
| V4L2_CAP_TUNER
|
672 V4L2_CAP_RADIO
| V4L2_CAP_RDS_CAPTURE
;
673 video_set_drvdata(&radio
->videodev
, radio
);
675 /* get device and chip versions */
676 if (si470x_get_all_registers(radio
) < 0) {
680 dev_info(&intf
->dev
, "DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
681 radio
->registers
[DEVICEID
], radio
->registers
[SI_CHIPID
]);
682 if ((radio
->registers
[SI_CHIPID
] & SI_CHIPID_FIRMWARE
) < RADIO_FW_VERSION
) {
684 "This driver is known to work with firmware version %hu,\n",
687 "but the device has firmware version %hu.\n",
688 radio
->registers
[SI_CHIPID
] & SI_CHIPID_FIRMWARE
);
692 /* get software and hardware versions */
693 if (si470x_get_scratch_page_versions(radio
) < 0) {
697 dev_info(&intf
->dev
, "software version %d, hardware version %d\n",
698 radio
->software_version
, radio
->hardware_version
);
699 if (radio
->hardware_version
< RADIO_HW_VERSION
) {
701 "This driver is known to work with hardware version %hu,\n",
704 "but the device has hardware version %hu.\n",
705 radio
->hardware_version
);
709 /* give out version warning */
710 if (version_warning
== 1) {
712 "If you have some trouble using this driver,\n");
714 "please report to V4L ML at linux-media@vger.kernel.org\n");
717 /* set led to connect state */
718 si470x_set_led_state(radio
, BLINK_GREEN_LED
);
720 /* rds buffer allocation */
721 radio
->buf_size
= rds_buf
* 3;
722 radio
->buffer
= kmalloc(radio
->buf_size
, GFP_KERNEL
);
723 if (!radio
->buffer
) {
728 /* rds buffer configuration */
731 init_waitqueue_head(&radio
->read_queue
);
732 usb_set_intfdata(intf
, radio
);
735 retval
= si470x_start_usb(radio
);
739 /* set initial frequency */
740 si470x_set_freq(radio
, 87.5 * FREQ_MUL
); /* available in all regions */
742 /* register video device */
743 retval
= video_register_device(&radio
->videodev
, VFL_TYPE_RADIO
,
746 dev_err(&intf
->dev
, "Could not register video device\n");
752 usb_kill_urb(radio
->int_in_urb
);
754 kfree(radio
->buffer
);
756 v4l2_ctrl_handler_free(&radio
->hdl
);
758 v4l2_device_unregister(&radio
->v4l2_dev
);
760 usb_free_urb(radio
->int_in_urb
);
762 kfree(radio
->int_in_buffer
);
764 kfree(radio
->usb_buf
);
773 * si470x_usb_driver_suspend - suspend the device
775 static int si470x_usb_driver_suspend(struct usb_interface
*intf
,
776 pm_message_t message
)
778 struct si470x_device
*radio
= usb_get_intfdata(intf
);
780 dev_info(&intf
->dev
, "suspending now...\n");
782 /* shutdown interrupt handler */
783 if (radio
->int_in_running
) {
784 radio
->int_in_running
= 0;
785 if (radio
->int_in_urb
)
786 usb_kill_urb(radio
->int_in_urb
);
789 /* cancel read processes */
790 wake_up_interruptible(&radio
->read_queue
);
799 * si470x_usb_driver_resume - resume the device
801 static int si470x_usb_driver_resume(struct usb_interface
*intf
)
803 struct si470x_device
*radio
= usb_get_intfdata(intf
);
806 dev_info(&intf
->dev
, "resuming now...\n");
809 ret
= si470x_start_usb(radio
);
811 v4l2_ctrl_handler_setup(&radio
->hdl
);
818 * si470x_usb_driver_disconnect - disconnect the device
820 static void si470x_usb_driver_disconnect(struct usb_interface
*intf
)
822 struct si470x_device
*radio
= usb_get_intfdata(intf
);
824 mutex_lock(&radio
->lock
);
825 v4l2_device_disconnect(&radio
->v4l2_dev
);
826 video_unregister_device(&radio
->videodev
);
827 usb_kill_urb(radio
->int_in_urb
);
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
);