2 * drivers/media/radio/radio-si470x.c
4 * Driver for USB radios for the Silicon Labs Si470x FM Radio Receivers:
5 * - Silicon Labs USB FM Radio Reference Design
6 * - ADS/Tech FM Radio Receiver (formerly Instant FM Music) (RDX-155-EF)
8 * Copyright (c) 2008 Tobias Lorenz <tobias.lorenz@gmx.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
30 * - First working version
31 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
33 * - Improved error handling, every function now returns errno
34 * - Improved multi user access (start/mute/stop)
35 * - Channel doesn't get lost anymore after start/mute/stop
36 * - RDS support added (polling mode via interrupt EP 1)
37 * - marked default module parameters with *value*
38 * - switched from bit structs to bit masks
39 * - header file cleaned and integrated
40 * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net>
42 * - hex values are now lower case
43 * - commented USB ID for ADS/Tech moved on todo list
44 * - blacklisted si470x in hid-quirks.c
45 * - rds buffer handling functions integrated into *_work, *_read
46 * - rds_command in si470x_poll exchanged against simple retval
47 * - check for firmware version 15
48 * - code order and prototypes still remain the same
49 * - spacing and bottom of band codes remain the same
50 * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
52 * - code reordered to avoid function prototypes
53 * - switch/case defaults are now more user-friendly
54 * - unified comment style
55 * - applied all checkpatch.pl v1.12 suggestions
56 * except the warning about the too long lines with bit comments
57 * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl)
58 * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
60 * - avoid poss. locking when doing copy_to_user which may sleep
61 * - RDS is automatically activated on read now
62 * - code cleaned of unnecessary rds_commands
63 * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified
64 * (thanks to Guillaume RAMOUSSE)
65 * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net>
67 * - number of seek_retries changed to tune_timeout
68 * - fixed problem with incomplete tune operations by own buffers
69 * - optimization of variables and printf types
70 * - improved error logging
71 * 2008-01-31 Tobias Lorenz <tobias.lorenz@gmx.net>
72 * Oliver Neukum <oliver@neukum.org>
74 * - fixed coverity checker warnings in *_usb_driver_disconnect
75 * - probe()/open() race by correct ordering in probe()
76 * - DMA coherency rules by separate allocation of all buffers
77 * - use of endianness macros
78 * - abuse of spinlock, replaced by mutex
79 * - racy handling of timer in disconnect,
80 * replaced by delayed_work
81 * - racy interruptible_sleep_on(),
82 * replaced with wait_event_interruptible()
83 * - handle signals in read()
84 * 2008-02-08 Tobias Lorenz <tobias.lorenz@gmx.net>
85 * Oliver Neukum <oliver@neukum.org>
87 * - usb autosuspend support
91 * - add seeking support
92 * - add firmware download/update support
93 * - RDS support: interrupt mode, instead of polling
94 * - add LED status output (check if that's not already done in firmware)
98 /* driver definitions */
99 #define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
100 #define DRIVER_NAME "radio-si470x"
101 #define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 7)
102 #define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
103 #define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
104 #define DRIVER_VERSION "1.0.7"
107 /* kernel includes */
108 #include <linux/kernel.h>
109 #include <linux/module.h>
110 #include <linux/init.h>
111 #include <linux/slab.h>
112 #include <linux/input.h>
113 #include <linux/usb.h>
114 #include <linux/hid.h>
115 #include <linux/version.h>
116 #include <linux/videodev2.h>
117 #include <linux/mutex.h>
118 #include <media/v4l2-common.h>
119 #include <media/rds.h>
120 #include <asm/unaligned.h>
123 /* USB Device ID List */
124 static struct usb_device_id si470x_usb_driver_id_table[] = {
125 /* Silicon Labs USB FM Radio Reference Design */
126 { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID, 0, 0) },
127 /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
128 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) },
129 /* Terminating entry */
132 MODULE_DEVICE_TABLE(usb, si470x_usb_driver_id_table);
136 /**************************************************************************
138 **************************************************************************/
141 static int radio_nr = -1;
142 module_param(radio_nr, int, 0);
143 MODULE_PARM_DESC(radio_nr, "Radio Nr");
146 /* 0: 200 kHz (USA, Australia) */
147 /* 1: 100 kHz (Europe, Japan) */
149 static unsigned short space = 2;
150 module_param(space, ushort, 0);
151 MODULE_PARM_DESC(radio_nr, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
153 /* Bottom of Band (MHz) */
154 /* 0: 87.5 - 108 MHz (USA, Europe)*/
155 /* 1: 76 - 108 MHz (Japan wide band) */
156 /* 2: 76 - 90 MHz (Japan) */
157 static unsigned short band = 1;
158 module_param(band, ushort, 0);
159 MODULE_PARM_DESC(radio_nr, "Band: 0=87.5..108MHz *1=76..108MHz* 2=76..90MHz");
163 /* 1: 50 us (Europe, Australia, Japan) */
164 static unsigned short de = 1;
165 module_param(de, ushort, 0);
166 MODULE_PARM_DESC(radio_nr, "De-emphasis: 0=75us *1=50us*");
169 static unsigned int usb_timeout = 500;
170 module_param(usb_timeout, uint, 0);
171 MODULE_PARM_DESC(usb_timeout, "USB timeout (ms): *500*");
174 static unsigned int tune_timeout = 3000;
175 module_param(tune_timeout, uint, 0);
176 MODULE_PARM_DESC(tune_timeout, "Tune timeout: *3000*");
178 /* RDS buffer blocks */
179 static unsigned int rds_buf = 100;
180 module_param(rds_buf, uint, 0);
181 MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
183 /* RDS maximum block errors */
184 static unsigned short max_rds_errors = 1;
185 /* 0 means 0 errors requiring correction */
186 /* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
187 /* 2 means 3-5 errors requiring correction */
188 /* 3 means 6+ errors or errors in checkword, correction not possible */
189 module_param(max_rds_errors, ushort, 0);
190 MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
192 /* RDS poll frequency */
193 static unsigned int rds_poll_time = 40;
194 /* 40 is used by the original USBRadio.exe */
195 /* 50 is used by radio-cadet */
196 /* 75 should be okay */
197 /* 80 is the usual RDS receive interval */
198 module_param(rds_poll_time, uint, 0);
199 MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
203 /**************************************************************************
204 * Register Definitions
205 **************************************************************************/
206 #define RADIO_REGISTER_SIZE 2 /* 16 register bit width */
207 #define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */
208 #define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */
210 #define DEVICEID 0 /* Device ID */
211 #define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */
212 #define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */
214 #define CHIPID 1 /* Chip ID */
215 #define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */
216 #define CHIPID_DEV 0x0200 /* bits 09..09: Device */
217 #define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */
219 #define POWERCFG 2 /* Power Configuration */
220 #define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */
221 #define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */
222 #define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */
223 #define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */
224 #define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */
225 #define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */
226 #define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */
227 #define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */
228 #define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */
230 #define CHANNEL 3 /* Channel */
231 #define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */
232 #define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */
234 #define SYSCONFIG1 4 /* System Configuration 1 */
235 #define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */
236 #define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */
237 #define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */
238 #define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */
239 #define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */
240 #define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */
241 #define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */
242 #define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */
243 #define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */
245 #define SYSCONFIG2 5 /* System Configuration 2 */
246 #define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */
247 #define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */
248 #define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */
249 #define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */
251 #define SYSCONFIG3 6 /* System Configuration 3 */
252 #define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */
253 #define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */
254 #define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */
255 #define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */
257 #define TEST1 7 /* Test 1 */
258 #define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */
260 #define TEST2 8 /* Test 2 */
261 /* TEST2 only contains reserved bits */
263 #define BOOTCONFIG 9 /* Boot Configuration */
264 /* BOOTCONFIG only contains reserved bits */
266 #define STATUSRSSI 10 /* Status RSSI */
267 #define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */
268 #define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */
269 #define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */
270 #define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */
271 #define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */
272 #define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */
273 #define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */
274 #define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */
276 #define READCHAN 11 /* Read Channel */
277 #define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */
278 #define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */
279 #define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */
280 #define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */
282 #define RDSA 12 /* RDSA */
283 #define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */
285 #define RDSB 13 /* RDSB */
286 #define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */
288 #define RDSC 14 /* RDSC */
289 #define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */
291 #define RDSD 15 /* RDSD */
292 #define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */
296 /**************************************************************************
298 **************************************************************************/
300 /* Reports 1-16 give direct read/write access to the 16 Si470x registers */
301 /* with the (REPORT_ID - 1) corresponding to the register address across USB */
302 /* endpoint 0 using GET_REPORT and SET_REPORT */
303 #define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
304 #define REGISTER_REPORT(reg) ((reg) + 1)
306 /* Report 17 gives direct read/write access to the entire Si470x register */
307 /* map across endpoint 0 using GET_REPORT and SET_REPORT */
308 #define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
309 #define ENTIRE_REPORT 17
311 /* Report 18 is used to send the lowest 6 Si470x registers up the HID */
312 /* interrupt endpoint 1 to Windows every 20 milliseconds for status */
313 #define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
314 #define RDS_REPORT 18
316 /* Report 19: LED state */
317 #define LED_REPORT_SIZE 3
318 #define LED_REPORT 19
320 /* Report 19: stream */
321 #define STREAM_REPORT_SIZE 3
322 #define STREAM_REPORT 19
324 /* Report 20: scratch */
325 #define SCRATCH_PAGE_SIZE 63
326 #define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
327 #define SCRATCH_REPORT 20
329 /* Reports 19-22: flash upgrade of the C8051F321 */
330 #define WRITE_REPORT 19
331 #define FLASH_REPORT 20
332 #define CRC_REPORT 21
333 #define RESPONSE_REPORT 22
335 /* Report 23: currently unused, but can accept 60 byte reports on the HID */
336 /* interrupt out endpoint 2 every 1 millisecond */
337 #define UNUSED_REPORT 23
341 /**************************************************************************
342 * Software/Hardware Versions
343 **************************************************************************/
344 #define RADIO_SW_VERSION_NOT_BOOTLOADABLE 6
345 #define RADIO_SW_VERSION 7
346 #define RADIO_SW_VERSION_CURRENT 15
347 #define RADIO_HW_VERSION 1
349 #define SCRATCH_PAGE_SW_VERSION 1
350 #define SCRATCH_PAGE_HW_VERSION 2
354 /**************************************************************************
355 * LED State Definitions
356 **************************************************************************/
357 #define LED_COMMAND 0x35
359 #define NO_CHANGE_LED 0x00
360 #define ALL_COLOR_LED 0x01 /* streaming state */
361 #define BLINK_GREEN_LED 0x02 /* connect state */
362 #define BLINK_RED_LED 0x04
363 #define BLINK_ORANGE_LED 0x10 /* disconnect state */
364 #define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
365 #define SOLID_RED_LED 0x40 /* bootload state */
366 #define SOLID_ORANGE_LED 0x80
370 /**************************************************************************
371 * Stream State Definitions
372 **************************************************************************/
373 #define STREAM_COMMAND 0x36
374 #define STREAM_VIDPID 0x00
375 #define STREAM_AUDIO 0xff
379 /**************************************************************************
380 * Bootloader / Flash Commands
381 **************************************************************************/
383 /* unique id sent to bootloader and required to put into a bootload state */
384 #define UNIQUE_BL_ID 0x34
386 /* mask for the flash data */
387 #define FLASH_DATA_MASK 0x55
389 /* bootloader commands */
390 #define GET_SW_VERSION_COMMAND 0x00
391 #define SET_PAGE_COMMAND 0x01
392 #define ERASE_PAGE_COMMAND 0x02
393 #define WRITE_PAGE_COMMAND 0x03
394 #define CRC_ON_PAGE_COMMAND 0x04
395 #define READ_FLASH_BYTE_COMMAND 0x05
396 #define RESET_DEVICE_COMMAND 0x06
397 #define GET_HW_VERSION_COMMAND 0x07
400 /* bootloader command responses */
401 #define COMMAND_OK 0x01
402 #define COMMAND_FAILED 0x02
403 #define COMMAND_PENDING 0x03
406 #define COMMAND_BUFFER_SIZE 4
407 #define RESPONSE_BUFFER_SIZE 2
408 #define FLASH_BUFFER_SIZE 64
409 #define CRC_BUFFER_SIZE 3
413 /**************************************************************************
414 * General Driver Definitions
415 **************************************************************************/
418 * si470x_device - private data
420 struct si470x_device {
421 /* reference to USB and video device */
422 struct usb_device *usbdev;
423 struct usb_interface *intf;
424 struct video_device *videodev;
426 /* driver management */
428 unsigned char disconnected;
430 /* Silabs internal registers (0..15) */
431 unsigned short registers[RADIO_REGISTER_NUM];
433 /* RDS receive buffer */
434 struct delayed_work work;
435 wait_queue_head_t read_queue;
436 struct mutex lock; /* buffer locking */
437 unsigned char *buffer; /* size is always multiple of three */
438 unsigned int buf_size;
439 unsigned int rd_index;
440 unsigned int wr_index;
445 * Lock to prevent kfree of data before all users have releases the device.
447 static DEFINE_MUTEX(open_close_lock);
451 * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
452 * 62.5 kHz otherwise.
453 * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
454 * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW
455 * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000
457 #define FREQ_MUL (1000000 / 62.5)
461 /**************************************************************************
462 * General Driver Functions
463 **************************************************************************/
466 * si470x_get_report - receive a HID report
468 static int si470x_get_report(struct si470x_device *radio, void *buf, int size)
470 unsigned char *report = (unsigned char *) buf;
473 retval = usb_control_msg(radio->usbdev,
474 usb_rcvctrlpipe(radio->usbdev, 0),
476 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
478 buf, size, usb_timeout);
480 printk(KERN_WARNING DRIVER_NAME
481 ": si470x_get_report: usb_control_msg returned %d\n",
489 * si470x_set_report - send a HID report
491 static int si470x_set_report(struct si470x_device *radio, void *buf, int size)
493 unsigned char *report = (unsigned char *) buf;
496 retval = usb_control_msg(radio->usbdev,
497 usb_sndctrlpipe(radio->usbdev, 0),
499 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
501 buf, size, usb_timeout);
503 printk(KERN_WARNING DRIVER_NAME
504 ": si470x_set_report: usb_control_msg returned %d\n",
512 * si470x_get_register - read register
514 static int si470x_get_register(struct si470x_device *radio, int regnr)
516 unsigned char buf[REGISTER_REPORT_SIZE];
519 buf[0] = REGISTER_REPORT(regnr);
521 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
524 radio->registers[regnr] = be16_to_cpu(get_unaligned(
525 (unsigned short *) &buf[1]));
527 return (retval < 0) ? -EINVAL : 0;
532 * si470x_set_register - write register
534 static int si470x_set_register(struct si470x_device *radio, int regnr)
536 unsigned char buf[REGISTER_REPORT_SIZE];
539 buf[0] = REGISTER_REPORT(regnr);
540 put_unaligned(cpu_to_be16(radio->registers[regnr]),
541 (unsigned short *) &buf[1]);
543 retval = si470x_set_report(radio, (void *) &buf, sizeof(buf));
545 return (retval < 0) ? -EINVAL : 0;
550 * si470x_get_all_registers - read entire registers
552 static int si470x_get_all_registers(struct si470x_device *radio)
554 unsigned char buf[ENTIRE_REPORT_SIZE];
558 buf[0] = ENTIRE_REPORT;
560 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
563 for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
564 radio->registers[regnr] = be16_to_cpu(get_unaligned(
566 &buf[regnr * RADIO_REGISTER_SIZE + 1]));
568 return (retval < 0) ? -EINVAL : 0;
573 * si470x_get_rds_registers - read rds registers
575 static int si470x_get_rds_registers(struct si470x_device *radio)
577 unsigned char buf[RDS_REPORT_SIZE];
584 retval = usb_interrupt_msg(radio->usbdev,
585 usb_rcvintpipe(radio->usbdev, 1),
586 (void *) &buf, sizeof(buf), &size, usb_timeout);
587 if (size != sizeof(buf))
588 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
589 "return size differs: %d != %zu\n", size, sizeof(buf));
591 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
592 "usb_interrupt_msg returned %d\n", retval);
595 for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
596 radio->registers[STATUSRSSI + regnr] =
597 be16_to_cpu(get_unaligned((unsigned short *)
598 &buf[regnr * RADIO_REGISTER_SIZE + 1]));
600 return (retval < 0) ? -EINVAL : 0;
605 * si470x_set_chan - set the channel
607 static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
610 unsigned long timeout;
614 radio->registers[CHANNEL] &= ~CHANNEL_CHAN;
615 radio->registers[CHANNEL] |= CHANNEL_TUNE | chan;
616 retval = si470x_set_register(radio, CHANNEL);
620 /* wait till seek operation has completed */
621 timeout = jiffies + msecs_to_jiffies(tune_timeout);
623 retval = si470x_get_register(radio, STATUSRSSI);
626 timed_out = time_after(jiffies, timeout);
627 } while (((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) &&
630 printk(KERN_WARNING DRIVER_NAME
631 ": seek does not finish after %u ms\n", tune_timeout);
634 radio->registers[CHANNEL] &= ~CHANNEL_TUNE;
635 return si470x_set_register(radio, CHANNEL);
640 * si470x_get_freq - get the frequency
642 static unsigned int si470x_get_freq(struct si470x_device *radio)
644 unsigned int spacing, band_bottom, freq;
650 /* 0: 200 kHz (USA, Australia) */
651 case 0 : spacing = 0.200 * FREQ_MUL; break;
652 /* 1: 100 kHz (Europe, Japan) */
653 case 1 : spacing = 0.100 * FREQ_MUL; break;
655 default: spacing = 0.050 * FREQ_MUL; break;
658 /* Bottom of Band (MHz) */
660 /* 0: 87.5 - 108 MHz (USA, Europe) */
661 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
662 /* 1: 76 - 108 MHz (Japan wide band) */
663 default: band_bottom = 76 * FREQ_MUL; break;
664 /* 2: 76 - 90 MHz (Japan) */
665 case 2 : band_bottom = 76 * FREQ_MUL; break;
669 retval = si470x_get_register(radio, READCHAN);
672 chan = radio->registers[READCHAN] & READCHAN_READCHAN;
674 /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
675 freq = chan * spacing + band_bottom;
682 * si470x_set_freq - set the frequency
684 static int si470x_set_freq(struct si470x_device *radio, unsigned int freq)
686 unsigned int spacing, band_bottom;
691 /* 0: 200 kHz (USA, Australia) */
692 case 0 : spacing = 0.200 * FREQ_MUL; break;
693 /* 1: 100 kHz (Europe, Japan) */
694 case 1 : spacing = 0.100 * FREQ_MUL; break;
696 default: spacing = 0.050 * FREQ_MUL; break;
699 /* Bottom of Band (MHz) */
701 /* 0: 87.5 - 108 MHz (USA, Europe) */
702 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
703 /* 1: 76 - 108 MHz (Japan wide band) */
704 default: band_bottom = 76 * FREQ_MUL; break;
705 /* 2: 76 - 90 MHz (Japan) */
706 case 2 : band_bottom = 76 * FREQ_MUL; break;
709 /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
710 chan = (freq - band_bottom) / spacing;
712 return si470x_set_chan(radio, chan);
717 * si470x_start - switch on radio
719 static int si470x_start(struct si470x_device *radio)
724 radio->registers[POWERCFG] =
725 POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM;
726 retval = si470x_set_register(radio, POWERCFG);
731 radio->registers[SYSCONFIG1] = SYSCONFIG1_DE;
732 retval = si470x_set_register(radio, SYSCONFIG1);
737 radio->registers[SYSCONFIG2] =
738 (0x3f << 8) | /* SEEKTH */
739 (band << 6) | /* BAND */
740 (space << 4) | /* SPACE */
741 15; /* VOLUME (max) */
742 retval = si470x_set_register(radio, SYSCONFIG2);
746 /* reset last channel */
747 return si470x_set_chan(radio,
748 radio->registers[CHANNEL] & CHANNEL_CHAN);
753 * si470x_stop - switch off radio
755 static int si470x_stop(struct si470x_device *radio)
760 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
761 retval = si470x_set_register(radio, SYSCONFIG1);
766 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
767 /* POWERCFG_ENABLE has to automatically go low */
768 radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE;
769 return si470x_set_register(radio, POWERCFG);
774 * si470x_rds_on - switch on rds reception
776 static int si470x_rds_on(struct si470x_device *radio)
781 mutex_lock(&radio->lock);
782 radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;
783 retval = si470x_set_register(radio, SYSCONFIG1);
785 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
786 mutex_unlock(&radio->lock);
793 /**************************************************************************
794 * RDS Driver Functions
795 **************************************************************************/
798 * si470x_rds - rds processing function
800 static void si470x_rds(struct si470x_device *radio)
802 unsigned char blocknum;
803 unsigned short bler; /* rds block errors */
805 unsigned char tmpbuf[3];
808 if (si470x_get_rds_registers(radio) < 0)
810 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0) {
811 /* No RDS group ready */
814 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSS) == 0) {
815 /* RDS decoder not synchronized */
819 /* copy all four RDS blocks to internal buffer */
820 mutex_lock(&radio->lock);
821 for (blocknum = 0; blocknum < 4; blocknum++) {
824 bler = (radio->registers[STATUSRSSI] &
825 STATUSRSSI_BLERA) >> 9;
826 rds = radio->registers[RDSA];
829 bler = (radio->registers[READCHAN] &
830 READCHAN_BLERB) >> 14;
831 rds = radio->registers[RDSB];
834 bler = (radio->registers[READCHAN] &
835 READCHAN_BLERC) >> 12;
836 rds = radio->registers[RDSC];
839 bler = (radio->registers[READCHAN] &
840 READCHAN_BLERD) >> 10;
841 rds = radio->registers[RDSD];
845 /* Fill the V4L2 RDS buffer */
846 put_unaligned(cpu_to_le16(rds), (unsigned short *) &tmpbuf);
847 tmpbuf[2] = blocknum; /* offset name */
848 tmpbuf[2] |= blocknum << 3; /* received offset */
849 if (bler > max_rds_errors)
850 tmpbuf[2] |= 0x80; /* uncorrectable errors */
852 tmpbuf[2] |= 0x40; /* corrected error(s) */
854 /* copy RDS block to internal buffer */
855 memcpy(&radio->buffer[radio->wr_index], &tmpbuf, 3);
856 radio->wr_index += 3;
858 /* wrap write pointer */
859 if (radio->wr_index >= radio->buf_size)
862 /* check for overflow */
863 if (radio->wr_index == radio->rd_index) {
864 /* increment and wrap read pointer */
865 radio->rd_index += 3;
866 if (radio->rd_index >= radio->buf_size)
870 mutex_unlock(&radio->lock);
872 /* wake up read queue */
873 if (radio->wr_index != radio->rd_index)
874 wake_up_interruptible(&radio->read_queue);
879 * si470x_work - rds work function
881 static void si470x_work(struct work_struct *work)
883 struct si470x_device *radio = container_of(work, struct si470x_device,
886 if (radio->disconnected)
888 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
892 schedule_delayed_work(&radio->work, msecs_to_jiffies(rds_poll_time));
897 /**************************************************************************
898 * File Operations Interface
899 **************************************************************************/
902 * si470x_fops_read - read RDS data
904 static ssize_t si470x_fops_read(struct file *file, char __user *buf,
905 size_t count, loff_t *ppos)
907 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
909 unsigned int block_count = 0;
911 /* switch on rds reception */
912 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
913 si470x_rds_on(radio);
914 schedule_delayed_work(&radio->work,
915 msecs_to_jiffies(rds_poll_time));
918 /* block if no new data available */
919 while (radio->wr_index == radio->rd_index) {
920 if (file->f_flags & O_NONBLOCK)
922 if (wait_event_interruptible(radio->read_queue,
923 radio->wr_index != radio->rd_index) < 0)
927 /* calculate block count from byte count */
930 /* copy RDS block out of internal buffer and to user buffer */
931 mutex_lock(&radio->lock);
932 while (block_count < count) {
933 if (radio->rd_index == radio->wr_index)
936 /* always transfer rds complete blocks */
937 if (copy_to_user(buf, &radio->buffer[radio->rd_index], 3))
938 /* retval = -EFAULT; */
941 /* increment and wrap read pointer */
942 radio->rd_index += 3;
943 if (radio->rd_index >= radio->buf_size)
946 /* increment counters */
951 mutex_unlock(&radio->lock);
958 * si470x_fops_poll - poll RDS data
960 static unsigned int si470x_fops_poll(struct file *file,
961 struct poll_table_struct *pts)
963 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
965 /* switch on rds reception */
966 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
967 si470x_rds_on(radio);
968 schedule_delayed_work(&radio->work,
969 msecs_to_jiffies(rds_poll_time));
972 poll_wait(file, &radio->read_queue, pts);
974 if (radio->rd_index != radio->wr_index)
975 return POLLIN | POLLRDNORM;
982 * si470x_fops_open - file open
984 static int si470x_fops_open(struct inode *inode, struct file *file)
986 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
991 retval = usb_autopm_get_interface(radio->intf);
997 if (radio->users == 1) {
998 retval = si470x_start(radio);
1000 usb_autopm_put_interface(radio->intf);
1009 * si470x_fops_release - file release
1011 static int si470x_fops_release(struct inode *inode, struct file *file)
1013 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1019 mutex_lock(&open_close_lock);
1021 if (radio->users == 0) {
1022 if (radio->disconnected) {
1023 video_unregister_device(radio->videodev);
1024 kfree(radio->buffer);
1029 /* stop rds reception */
1030 cancel_delayed_work_sync(&radio->work);
1032 /* cancel read processes */
1033 wake_up_interruptible(&radio->read_queue);
1035 retval = si470x_stop(radio);
1036 usb_autopm_put_interface(radio->intf);
1040 mutex_unlock(&open_close_lock);
1046 * si470x_fops - file operations interface
1048 static const struct file_operations si470x_fops = {
1049 .owner = THIS_MODULE,
1050 .llseek = no_llseek,
1051 .read = si470x_fops_read,
1052 .poll = si470x_fops_poll,
1053 .ioctl = video_ioctl2,
1054 #ifdef CONFIG_COMPAT
1055 .compat_ioctl = v4l_compat_ioctl32,
1057 .open = si470x_fops_open,
1058 .release = si470x_fops_release,
1063 /**************************************************************************
1064 * Video4Linux Interface
1065 **************************************************************************/
1068 * si470x_v4l2_queryctrl - query control
1070 static struct v4l2_queryctrl si470x_v4l2_queryctrl[] = {
1071 /* HINT: the disabled controls are only here to satify kradio and such apps */
1073 .id = V4L2_CID_AUDIO_VOLUME,
1074 .type = V4L2_CTRL_TYPE_INTEGER,
1079 .default_value = 15,
1082 .id = V4L2_CID_AUDIO_BALANCE,
1083 .flags = V4L2_CTRL_FLAG_DISABLED,
1086 .id = V4L2_CID_AUDIO_BASS,
1087 .flags = V4L2_CTRL_FLAG_DISABLED,
1090 .id = V4L2_CID_AUDIO_TREBLE,
1091 .flags = V4L2_CTRL_FLAG_DISABLED,
1094 .id = V4L2_CID_AUDIO_MUTE,
1095 .type = V4L2_CTRL_TYPE_BOOLEAN,
1103 .id = V4L2_CID_AUDIO_LOUDNESS,
1104 .flags = V4L2_CTRL_FLAG_DISABLED,
1110 * si470x_vidioc_querycap - query device capabilities
1112 static int si470x_vidioc_querycap(struct file *file, void *priv,
1113 struct v4l2_capability *capability)
1115 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
1116 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
1117 sprintf(capability->bus_info, "USB");
1118 capability->version = DRIVER_KERNEL_VERSION;
1119 capability->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
1126 * si470x_vidioc_g_input - get input
1128 static int si470x_vidioc_g_input(struct file *filp, void *priv,
1138 * si470x_vidioc_s_input - set input
1140 static int si470x_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1150 * si470x_vidioc_queryctrl - enumerate control items
1152 static int si470x_vidioc_queryctrl(struct file *file, void *priv,
1153 struct v4l2_queryctrl *qc)
1156 int retval = -EINVAL;
1158 for (i = 0; i < ARRAY_SIZE(si470x_v4l2_queryctrl); i++) {
1159 if (qc->id && qc->id == si470x_v4l2_queryctrl[i].id) {
1160 memcpy(qc, &(si470x_v4l2_queryctrl[i]), sizeof(*qc));
1166 printk(KERN_WARNING DRIVER_NAME
1167 ": query control failed with %d\n", retval);
1174 * si470x_vidioc_g_ctrl - get the value of a control
1176 static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
1177 struct v4l2_control *ctrl)
1179 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1181 if (radio->disconnected)
1185 case V4L2_CID_AUDIO_VOLUME:
1186 ctrl->value = radio->registers[SYSCONFIG2] &
1189 case V4L2_CID_AUDIO_MUTE:
1190 ctrl->value = ((radio->registers[POWERCFG] &
1191 POWERCFG_DMUTE) == 0) ? 1 : 0;
1200 * si470x_vidioc_s_ctrl - set the value of a control
1202 static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
1203 struct v4l2_control *ctrl)
1205 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1208 if (radio->disconnected)
1212 case V4L2_CID_AUDIO_VOLUME:
1213 radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
1214 radio->registers[SYSCONFIG2] |= ctrl->value;
1215 retval = si470x_set_register(radio, SYSCONFIG2);
1217 case V4L2_CID_AUDIO_MUTE:
1218 if (ctrl->value == 1)
1219 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
1221 radio->registers[POWERCFG] |= POWERCFG_DMUTE;
1222 retval = si470x_set_register(radio, POWERCFG);
1228 printk(KERN_WARNING DRIVER_NAME
1229 ": set control failed with %d\n", retval);
1236 * si470x_vidioc_g_audio - get audio attributes
1238 static int si470x_vidioc_g_audio(struct file *file, void *priv,
1239 struct v4l2_audio *audio)
1241 if (audio->index > 1)
1244 strcpy(audio->name, "Radio");
1245 audio->capability = V4L2_AUDCAP_STEREO;
1252 * si470x_vidioc_s_audio - set audio attributes
1254 static int si470x_vidioc_s_audio(struct file *file, void *priv,
1255 struct v4l2_audio *audio)
1257 if (audio->index != 0)
1265 * si470x_vidioc_g_tuner - get tuner attributes
1267 static int si470x_vidioc_g_tuner(struct file *file, void *priv,
1268 struct v4l2_tuner *tuner)
1270 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1273 if (radio->disconnected)
1275 if (tuner->index > 0)
1278 /* read status rssi */
1279 retval = si470x_get_register(radio, STATUSRSSI);
1283 strcpy(tuner->name, "FM");
1284 tuner->type = V4L2_TUNER_RADIO;
1286 /* 0: 87.5 - 108 MHz (USA, Europe, default) */
1288 tuner->rangelow = 87.5 * FREQ_MUL;
1289 tuner->rangehigh = 108 * FREQ_MUL;
1291 /* 1: 76 - 108 MHz (Japan wide band) */
1293 tuner->rangelow = 76 * FREQ_MUL;
1294 tuner->rangehigh = 108 * FREQ_MUL;
1296 /* 2: 76 - 90 MHz (Japan) */
1298 tuner->rangelow = 76 * FREQ_MUL;
1299 tuner->rangehigh = 90 * FREQ_MUL;
1302 tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
1303 tuner->capability = V4L2_TUNER_CAP_LOW;
1305 /* Stereo indicator == Stereo (instead of Mono) */
1306 if ((radio->registers[STATUSRSSI] & STATUSRSSI_ST) == 1)
1307 tuner->audmode = V4L2_TUNER_MODE_STEREO;
1309 tuner->audmode = V4L2_TUNER_MODE_MONO;
1311 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
1312 tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI)
1315 /* automatic frequency control: -1: freq to low, 1 freq to high */
1323 * si470x_vidioc_s_tuner - set tuner attributes
1325 static int si470x_vidioc_s_tuner(struct file *file, void *priv,
1326 struct v4l2_tuner *tuner)
1328 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1331 if (radio->disconnected)
1333 if (tuner->index > 0)
1336 if (tuner->audmode == V4L2_TUNER_MODE_MONO)
1337 radio->registers[POWERCFG] |= POWERCFG_MONO; /* force mono */
1339 radio->registers[POWERCFG] &= ~POWERCFG_MONO; /* try stereo */
1341 retval = si470x_set_register(radio, POWERCFG);
1343 printk(KERN_WARNING DRIVER_NAME
1344 ": set tuner failed with %d\n", retval);
1351 * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
1353 static int si470x_vidioc_g_frequency(struct file *file, void *priv,
1354 struct v4l2_frequency *freq)
1356 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1358 if (radio->disconnected)
1361 freq->type = V4L2_TUNER_RADIO;
1362 freq->frequency = si470x_get_freq(radio);
1369 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
1371 static int si470x_vidioc_s_frequency(struct file *file, void *priv,
1372 struct v4l2_frequency *freq)
1374 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1377 if (radio->disconnected)
1379 if (freq->type != V4L2_TUNER_RADIO)
1382 retval = si470x_set_freq(radio, freq->frequency);
1384 printk(KERN_WARNING DRIVER_NAME
1385 ": set frequency failed with %d\n", retval);
1392 * si470x_viddev_tamples - video device interface
1394 static struct video_device si470x_viddev_template = {
1395 .fops = &si470x_fops,
1396 .name = DRIVER_NAME,
1397 .type = VID_TYPE_TUNER,
1398 .release = video_device_release,
1399 .vidioc_querycap = si470x_vidioc_querycap,
1400 .vidioc_g_input = si470x_vidioc_g_input,
1401 .vidioc_s_input = si470x_vidioc_s_input,
1402 .vidioc_queryctrl = si470x_vidioc_queryctrl,
1403 .vidioc_g_ctrl = si470x_vidioc_g_ctrl,
1404 .vidioc_s_ctrl = si470x_vidioc_s_ctrl,
1405 .vidioc_g_audio = si470x_vidioc_g_audio,
1406 .vidioc_s_audio = si470x_vidioc_s_audio,
1407 .vidioc_g_tuner = si470x_vidioc_g_tuner,
1408 .vidioc_s_tuner = si470x_vidioc_s_tuner,
1409 .vidioc_g_frequency = si470x_vidioc_g_frequency,
1410 .vidioc_s_frequency = si470x_vidioc_s_frequency,
1411 .owner = THIS_MODULE,
1416 /**************************************************************************
1418 **************************************************************************/
1421 * si470x_usb_driver_probe - probe for the device
1423 static int si470x_usb_driver_probe(struct usb_interface *intf,
1424 const struct usb_device_id *id)
1426 struct si470x_device *radio;
1427 int retval = -ENOMEM;
1429 /* private data allocation */
1430 radio = kzalloc(sizeof(struct si470x_device), GFP_KERNEL);
1434 /* video device allocation */
1435 radio->videodev = video_device_alloc();
1436 if (!radio->videodev)
1439 /* initial configuration */
1440 memcpy(radio->videodev, &si470x_viddev_template,
1441 sizeof(si470x_viddev_template));
1443 radio->usbdev = interface_to_usbdev(intf);
1445 mutex_init(&radio->lock);
1446 video_set_drvdata(radio->videodev, radio);
1448 /* show some infos about the specific device */
1450 if (si470x_get_all_registers(radio) < 0)
1452 printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4hx ChipID=0x%4.4hx\n",
1453 radio->registers[DEVICEID], radio->registers[CHIPID]);
1455 /* check if firmware is current */
1456 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE)
1457 < RADIO_SW_VERSION_CURRENT) {
1458 printk(KERN_WARNING DRIVER_NAME
1459 ": This driver is known to work with "
1460 "firmware version %hu,\n", RADIO_SW_VERSION_CURRENT);
1461 printk(KERN_WARNING DRIVER_NAME
1462 ": but the device has firmware version %hu.\n",
1463 radio->registers[CHIPID] & CHIPID_FIRMWARE);
1464 printk(KERN_WARNING DRIVER_NAME
1465 ": If you have some trouble using this driver,\n");
1466 printk(KERN_WARNING DRIVER_NAME
1467 ": please report to V4L ML at "
1468 "video4linux-list@redhat.com\n");
1471 /* set initial frequency */
1472 si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
1474 /* rds buffer allocation */
1475 radio->buf_size = rds_buf * 3;
1476 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
1480 /* rds buffer configuration */
1481 radio->wr_index = 0;
1482 radio->rd_index = 0;
1483 init_waitqueue_head(&radio->read_queue);
1485 /* prepare rds work function */
1486 INIT_DELAYED_WORK(&radio->work, si470x_work);
1488 /* register video device */
1489 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
1490 printk(KERN_WARNING DRIVER_NAME
1491 ": Could not register video device\n");
1494 usb_set_intfdata(intf, radio);
1498 video_device_release(radio->videodev);
1499 kfree(radio->buffer);
1508 * si470x_usb_driver_suspend - suspend the device
1510 static int si470x_usb_driver_suspend(struct usb_interface *intf,
1511 pm_message_t message)
1513 struct si470x_device *radio = usb_get_intfdata(intf);
1515 printk(KERN_INFO DRIVER_NAME ": suspending now...\n");
1517 cancel_delayed_work_sync(&radio->work);
1524 * si470x_usb_driver_resume - resume the device
1526 static int si470x_usb_driver_resume(struct usb_interface *intf)
1528 struct si470x_device *radio = usb_get_intfdata(intf);
1530 printk(KERN_INFO DRIVER_NAME ": resuming now...\n");
1532 mutex_lock(&radio->lock);
1533 if (radio->users && radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS)
1534 schedule_delayed_work(&radio->work,
1535 msecs_to_jiffies(rds_poll_time));
1536 mutex_unlock(&radio->lock);
1543 * si470x_usb_driver_disconnect - disconnect the device
1545 static void si470x_usb_driver_disconnect(struct usb_interface *intf)
1547 struct si470x_device *radio = usb_get_intfdata(intf);
1549 mutex_lock(&open_close_lock);
1550 radio->disconnected = 1;
1551 cancel_delayed_work_sync(&radio->work);
1552 usb_set_intfdata(intf, NULL);
1553 if (radio->users == 0) {
1554 video_unregister_device(radio->videodev);
1555 kfree(radio->buffer);
1558 mutex_unlock(&open_close_lock);
1563 * si470x_usb_driver - usb driver interface
1565 static struct usb_driver si470x_usb_driver = {
1566 .name = DRIVER_NAME,
1567 .probe = si470x_usb_driver_probe,
1568 .disconnect = si470x_usb_driver_disconnect,
1569 .suspend = si470x_usb_driver_suspend,
1570 .resume = si470x_usb_driver_resume,
1571 .id_table = si470x_usb_driver_id_table,
1572 .supports_autosuspend = 1,
1577 /**************************************************************************
1579 **************************************************************************/
1582 * si470x_module_init - module init
1584 static int __init si470x_module_init(void)
1586 printk(KERN_INFO DRIVER_DESC ", Version " DRIVER_VERSION "\n");
1587 return usb_register(&si470x_usb_driver);
1592 * si470x_module_exit - module exit
1594 static void __exit si470x_module_exit(void)
1596 usb_deregister(&si470x_usb_driver);
1600 module_init(si470x_module_init);
1601 module_exit(si470x_module_exit);
1603 MODULE_LICENSE("GPL");
1604 MODULE_AUTHOR(DRIVER_AUTHOR);
1605 MODULE_DESCRIPTION(DRIVER_DESC);
1606 MODULE_VERSION(DRIVER_VERSION);