blob: a2975c8b0095dff436bc17a130b5ee9058650ae4 [file] [log] [blame]
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001/*
2 * drivers/media/radio/radio-si470x.c
3 *
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)
7 *
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03008 * Copyright (c) 2008 Tobias Lorenz <tobias.lorenz@gmx.net>
Tobias Lorenz78656ac2008-01-14 21:55:27 -03009 *
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.
14 *
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.
19 *
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
23 */
24
25
26/*
27 * History:
28 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
29 * Version 1.0.0
30 * - First working version
31 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -030032 * Version 1.0.1
Tobias Lorenz78656ac2008-01-14 21:55:27 -030033 * - 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>
41 * Version 1.0.2
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
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -030050 * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
51 * Version 1.0.3
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)
Tobias Lorenz2fb88402008-01-25 05:14:57 -030058 * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
59 * Version 1.0.4
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)
Tobias Lorenz0e3301e2008-01-27 14:54:07 -030065 * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net>
66 * Version 1.0.5
67 * - number of seek_retries changed to tune_timeout
68 * - fixed problem with incomplete tune operations by own buffers
69 * - optimization of variables
70 * - improved error logging
Tobias Lorenz78656ac2008-01-14 21:55:27 -030071 *
72 * ToDo:
Tobias Lorenz78656ac2008-01-14 21:55:27 -030073 * - add seeking support
74 * - add firmware download/update support
Tobias Lorenz78656ac2008-01-14 21:55:27 -030075 * - RDS support: interrupt mode, instead of polling
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -030076 * - add LED status output (check if that's not already done in firmware)
Tobias Lorenz78656ac2008-01-14 21:55:27 -030077 */
78
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -030079
Tobias Lorenz78656ac2008-01-14 21:55:27 -030080/* driver definitions */
81#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
82#define DRIVER_NAME "radio-si470x"
Tobias Lorenz0e3301e2008-01-27 14:54:07 -030083#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 5)
Tobias Lorenz78656ac2008-01-14 21:55:27 -030084#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
85#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
Tobias Lorenz0e3301e2008-01-27 14:54:07 -030086#define DRIVER_VERSION "1.0.5"
Tobias Lorenz78656ac2008-01-14 21:55:27 -030087
88
89/* kernel includes */
90#include <linux/kernel.h>
91#include <linux/module.h>
92#include <linux/init.h>
93#include <linux/slab.h>
94#include <linux/input.h>
Tobias Lorenz78656ac2008-01-14 21:55:27 -030095#include <linux/usb.h>
96#include <linux/hid.h>
97#include <linux/version.h>
Mauro Carvalho Chehab387d4472008-01-15 11:25:10 -030098#include <linux/videodev2.h>
99#include <media/v4l2-common.h>
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300100#include <media/rds.h>
101
102
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300103/* USB Device ID List */
104static struct usb_device_id si470x_usb_driver_id_table[] = {
105 /* Silicon Labs USB FM Radio Reference Design */
106 { USB_DEVICE_AND_INTERFACE_INFO(0x10c4, 0x818a, USB_CLASS_HID, 0, 0) },
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300107 /* ADS/Tech FM Radio Receiver (formerly Instant FM Music) */
108 { USB_DEVICE_AND_INTERFACE_INFO(0x06e1, 0xa155, USB_CLASS_HID, 0, 0) },
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300109 /* Terminating entry */
110 { }
111};
112MODULE_DEVICE_TABLE(usb, si470x_usb_driver_id_table);
113
114
115
116/**************************************************************************
117 * Module Parameters
118 **************************************************************************/
119
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300120/* Radio Nr */
121static int radio_nr = -1;
122module_param(radio_nr, int, 0);
123MODULE_PARM_DESC(radio_nr, "Radio Nr");
124
125/* Spacing (kHz) */
126/* 0: 200 kHz (USA, Australia) */
127/* 1: 100 kHz (Europe, Japan) */
128/* 2: 50 kHz */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300129static unsigned short space = 2;
130module_param(space, ushort, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300131MODULE_PARM_DESC(radio_nr, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
132
133/* Bottom of Band (MHz) */
134/* 0: 87.5 - 108 MHz (USA, Europe)*/
135/* 1: 76 - 108 MHz (Japan wide band) */
136/* 2: 76 - 90 MHz (Japan) */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300137static unsigned short band = 1;
138module_param(band, ushort, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300139MODULE_PARM_DESC(radio_nr, "Band: 0=87.5..108MHz *1=76..108MHz* 2=76..90MHz");
140
141/* De-emphasis */
142/* 0: 75 us (USA) */
143/* 1: 50 us (Europe, Australia, Japan) */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300144static unsigned short de = 1;
145module_param(de, ushort, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300146MODULE_PARM_DESC(radio_nr, "De-emphasis: 0=75us *1=50us*");
147
148/* USB timeout */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300149static unsigned int usb_timeout = 500;
150module_param(usb_timeout, uint, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300151MODULE_PARM_DESC(usb_timeout, "USB timeout (ms): *500*");
152
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300153/* Tune timeout */
154static unsigned int tune_timeout = 3000;
155module_param(tune_timeout, uint, 0);
156MODULE_PARM_DESC(tune_timeout, "Tune timeout: *3000*");
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300157
158/* RDS buffer blocks */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300159static unsigned int rds_buf = 100;
160module_param(rds_buf, uint, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300161MODULE_PARM_DESC(rds_buf, "RDS buffer entries: *100*");
162
163/* RDS maximum block errors */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300164static unsigned short max_rds_errors = 1;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300165/* 0 means 0 errors requiring correction */
166/* 1 means 1-2 errors requiring correction (used by original USBRadio.exe) */
167/* 2 means 3-5 errors requiring correction */
168/* 3 means 6+ errors or errors in checkword, correction not possible */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300169module_param(max_rds_errors, ushort, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300170MODULE_PARM_DESC(max_rds_errors, "RDS maximum block errors: *1*");
171
172/* RDS poll frequency */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300173static unsigned int rds_poll_time = 40;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300174/* 40 is used by the original USBRadio.exe */
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300175/* 50 is used by radio-cadet */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300176/* 75 should be okay */
177/* 80 is the usual RDS receive interval */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300178module_param(rds_poll_time, uint, 0);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300179MODULE_PARM_DESC(rds_poll_time, "RDS poll time (ms): *40*");
180
181
182
183/**************************************************************************
184 * Register Definitions
185 **************************************************************************/
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300186#define RADIO_REGISTER_SIZE 2 /* 16 register bit width */
187#define RADIO_REGISTER_NUM 16 /* DEVICEID ... RDSD */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300188#define RDS_REGISTER_NUM 6 /* STATUSRSSI ... RDSD */
189
190#define DEVICEID 0 /* Device ID */
191#define DEVICEID_PN 0xf000 /* bits 15..12: Part Number */
192#define DEVICEID_MFGID 0x0fff /* bits 11..00: Manufacturer ID */
193
194#define CHIPID 1 /* Chip ID */
195#define CHIPID_REV 0xfc00 /* bits 15..10: Chip Version */
196#define CHIPID_DEV 0x0200 /* bits 09..09: Device */
197#define CHIPID_FIRMWARE 0x01ff /* bits 08..00: Firmware Version */
198
199#define POWERCFG 2 /* Power Configuration */
200#define POWERCFG_DSMUTE 0x8000 /* bits 15..15: Softmute Disable */
201#define POWERCFG_DMUTE 0x4000 /* bits 14..14: Mute Disable */
202#define POWERCFG_MONO 0x2000 /* bits 13..13: Mono Select */
203#define POWERCFG_RDSM 0x0800 /* bits 11..11: RDS Mode (Si4701 only) */
204#define POWERCFG_SKMODE 0x0400 /* bits 10..10: Seek Mode */
205#define POWERCFG_SEEKUP 0x0200 /* bits 09..09: Seek Direction */
206#define POWERCFG_SEEK 0x0100 /* bits 08..08: Seek */
207#define POWERCFG_DISABLE 0x0040 /* bits 06..06: Powerup Disable */
208#define POWERCFG_ENABLE 0x0001 /* bits 00..00: Powerup Enable */
209
210#define CHANNEL 3 /* Channel */
211#define CHANNEL_TUNE 0x8000 /* bits 15..15: Tune */
212#define CHANNEL_CHAN 0x03ff /* bits 09..00: Channel Select */
213
214#define SYSCONFIG1 4 /* System Configuration 1 */
215#define SYSCONFIG1_RDSIEN 0x8000 /* bits 15..15: RDS Interrupt Enable (Si4701 only) */
216#define SYSCONFIG1_STCIEN 0x4000 /* bits 14..14: Seek/Tune Complete Interrupt Enable */
217#define SYSCONFIG1_RDS 0x1000 /* bits 12..12: RDS Enable (Si4701 only) */
218#define SYSCONFIG1_DE 0x0800 /* bits 11..11: De-emphasis (0=75us 1=50us) */
219#define SYSCONFIG1_AGCD 0x0400 /* bits 10..10: AGC Disable */
220#define SYSCONFIG1_BLNDADJ 0x00c0 /* bits 07..06: Stereo/Mono Blend Level Adjustment */
221#define SYSCONFIG1_GPIO3 0x0030 /* bits 05..04: General Purpose I/O 3 */
222#define SYSCONFIG1_GPIO2 0x000c /* bits 03..02: General Purpose I/O 2 */
223#define SYSCONFIG1_GPIO1 0x0003 /* bits 01..00: General Purpose I/O 1 */
224
225#define SYSCONFIG2 5 /* System Configuration 2 */
226#define SYSCONFIG2_SEEKTH 0xff00 /* bits 15..08: RSSI Seek Threshold */
227#define SYSCONFIG2_BAND 0x0080 /* bits 07..06: Band Select */
228#define SYSCONFIG2_SPACE 0x0030 /* bits 05..04: Channel Spacing */
229#define SYSCONFIG2_VOLUME 0x000f /* bits 03..00: Volume */
230
231#define SYSCONFIG3 6 /* System Configuration 3 */
232#define SYSCONFIG3_SMUTER 0xc000 /* bits 15..14: Softmute Attack/Recover Rate */
233#define SYSCONFIG3_SMUTEA 0x3000 /* bits 13..12: Softmute Attenuation */
234#define SYSCONFIG3_SKSNR 0x00f0 /* bits 07..04: Seek SNR Threshold */
235#define SYSCONFIG3_SKCNT 0x000f /* bits 03..00: Seek FM Impulse Detection Threshold */
236
237#define TEST1 7 /* Test 1 */
238#define TEST1_AHIZEN 0x4000 /* bits 14..14: Audio High-Z Enable */
239
240#define TEST2 8 /* Test 2 */
241/* TEST2 only contains reserved bits */
242
243#define BOOTCONFIG 9 /* Boot Configuration */
244/* BOOTCONFIG only contains reserved bits */
245
246#define STATUSRSSI 10 /* Status RSSI */
247#define STATUSRSSI_RDSR 0x8000 /* bits 15..15: RDS Ready (Si4701 only) */
248#define STATUSRSSI_STC 0x4000 /* bits 14..14: Seek/Tune Complete */
249#define STATUSRSSI_SF 0x2000 /* bits 13..13: Seek Fail/Band Limit */
250#define STATUSRSSI_AFCRL 0x1000 /* bits 12..12: AFC Rail */
251#define STATUSRSSI_RDSS 0x0800 /* bits 11..11: RDS Synchronized (Si4701 only) */
252#define STATUSRSSI_BLERA 0x0600 /* bits 10..09: RDS Block A Errors (Si4701 only) */
253#define STATUSRSSI_ST 0x0100 /* bits 08..08: Stereo Indicator */
254#define STATUSRSSI_RSSI 0x00ff /* bits 07..00: RSSI (Received Signal Strength Indicator) */
255
256#define READCHAN 11 /* Read Channel */
257#define READCHAN_BLERB 0xc000 /* bits 15..14: RDS Block D Errors (Si4701 only) */
258#define READCHAN_BLERC 0x3000 /* bits 13..12: RDS Block C Errors (Si4701 only) */
259#define READCHAN_BLERD 0x0c00 /* bits 11..10: RDS Block B Errors (Si4701 only) */
260#define READCHAN_READCHAN 0x03ff /* bits 09..00: Read Channel */
261
262#define RDSA 12 /* RDSA */
263#define RDSA_RDSA 0xffff /* bits 15..00: RDS Block A Data (Si4701 only) */
264
265#define RDSB 13 /* RDSB */
266#define RDSB_RDSB 0xffff /* bits 15..00: RDS Block B Data (Si4701 only) */
267
268#define RDSC 14 /* RDSC */
269#define RDSC_RDSC 0xffff /* bits 15..00: RDS Block C Data (Si4701 only) */
270
271#define RDSD 15 /* RDSD */
272#define RDSD_RDSD 0xffff /* bits 15..00: RDS Block D Data (Si4701 only) */
273
274
275
276/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300277 * USB HID Reports
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300278 **************************************************************************/
279
280/* Reports 1-16 give direct read/write access to the 16 Si470x registers */
281/* with the (REPORT_ID - 1) corresponding to the register address across USB */
282/* endpoint 0 using GET_REPORT and SET_REPORT */
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300283#define REGISTER_REPORT_SIZE (RADIO_REGISTER_SIZE + 1)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300284#define REGISTER_REPORT(reg) ((reg) + 1)
285
286/* Report 17 gives direct read/write access to the entire Si470x register */
287/* map across endpoint 0 using GET_REPORT and SET_REPORT */
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300288#define ENTIRE_REPORT_SIZE (RADIO_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300289#define ENTIRE_REPORT 17
290
291/* Report 18 is used to send the lowest 6 Si470x registers up the HID */
292/* interrupt endpoint 1 to Windows every 20 milliseconds for status */
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300293#define RDS_REPORT_SIZE (RDS_REGISTER_NUM * RADIO_REGISTER_SIZE + 1)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300294#define RDS_REPORT 18
295
296/* Report 19: LED state */
297#define LED_REPORT_SIZE 3
298#define LED_REPORT 19
299
300/* Report 19: stream */
301#define STREAM_REPORT_SIZE 3
302#define STREAM_REPORT 19
303
304/* Report 20: scratch */
305#define SCRATCH_PAGE_SIZE 63
306#define SCRATCH_REPORT_SIZE (SCRATCH_PAGE_SIZE + 1)
307#define SCRATCH_REPORT 20
308
309/* Reports 19-22: flash upgrade of the C8051F321 */
310#define WRITE_REPORT 19
311#define FLASH_REPORT 20
312#define CRC_REPORT 21
313#define RESPONSE_REPORT 22
314
315/* Report 23: currently unused, but can accept 60 byte reports on the HID */
316/* interrupt out endpoint 2 every 1 millisecond */
317#define UNUSED_REPORT 23
318
319
320
321/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300322 * Software/Hardware Versions
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300323 **************************************************************************/
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300324#define RADIO_SW_VERSION_NOT_BOOTLOADABLE 6
325#define RADIO_SW_VERSION 7
326#define RADIO_SW_VERSION_CURRENT 15
327#define RADIO_HW_VERSION 1
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300328
329#define SCRATCH_PAGE_SW_VERSION 1
330#define SCRATCH_PAGE_HW_VERSION 2
331
332
333
334/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300335 * LED State Definitions
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300336 **************************************************************************/
337#define LED_COMMAND 0x35
338
339#define NO_CHANGE_LED 0x00
340#define ALL_COLOR_LED 0x01 /* streaming state */
341#define BLINK_GREEN_LED 0x02 /* connect state */
342#define BLINK_RED_LED 0x04
343#define BLINK_ORANGE_LED 0x10 /* disconnect state */
344#define SOLID_GREEN_LED 0x20 /* tuning/seeking state */
345#define SOLID_RED_LED 0x40 /* bootload state */
346#define SOLID_ORANGE_LED 0x80
347
348
349
350/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300351 * Stream State Definitions
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300352 **************************************************************************/
353#define STREAM_COMMAND 0x36
354#define STREAM_VIDPID 0x00
355#define STREAM_AUDIO 0xff
356
357
358
359/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300360 * Bootloader / Flash Commands
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300361 **************************************************************************/
362
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300363/* unique id sent to bootloader and required to put into a bootload state */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300364#define UNIQUE_BL_ID 0x34
365
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300366/* mask for the flash data */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300367#define FLASH_DATA_MASK 0x55
368
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300369/* bootloader commands */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300370#define GET_SW_VERSION_COMMAND 0x00
371#define SET_PAGE_COMMAND 0x01
372#define ERASE_PAGE_COMMAND 0x02
373#define WRITE_PAGE_COMMAND 0x03
374#define CRC_ON_PAGE_COMMAND 0x04
375#define READ_FLASH_BYTE_COMMAND 0x05
376#define RESET_DEVICE_COMMAND 0x06
377#define GET_HW_VERSION_COMMAND 0x07
378#define BLANK 0xff
379
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300380/* bootloader command responses */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300381#define COMMAND_OK 0x01
382#define COMMAND_FAILED 0x02
383#define COMMAND_PENDING 0x03
384
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300385/* buffer sizes */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300386#define COMMAND_BUFFER_SIZE 4
387#define RESPONSE_BUFFER_SIZE 2
388#define FLASH_BUFFER_SIZE 64
389#define CRC_BUFFER_SIZE 3
390
391
392
393/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300394 * General Driver Definitions
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300395 **************************************************************************/
396
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300397/*
398 * si470x_device - private data
399 */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300400struct si470x_device {
401 /* reference to USB and video device */
402 struct usb_device *usbdev;
403 struct video_device *videodev;
404
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300405 /* driver management */
406 unsigned int users;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300407
408 /* Silabs internal registers (0..15) */
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300409 unsigned short registers[RADIO_REGISTER_NUM];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300410
411 /* RDS receive buffer */
412 struct work_struct work;
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300413 wait_queue_head_t read_queue;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300414 struct timer_list timer;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300415 spinlock_t lock; /* buffer locking */
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300416 unsigned char *buffer; /* size is always multiple of three */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300417 unsigned int buf_size;
418 unsigned int rd_index;
419 unsigned int wr_index;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300420};
421
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300422
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300423/*
424 * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
425 * 62.5 kHz otherwise.
426 * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
427 * tuner->capability is therefore set to V4L2_TUNER_CAP_LOW
428 * The FREQ_MUL is then: 1 MHz / 62.5 Hz = 16000
429 */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300430#define FREQ_MUL (1000000 / 62.5)
431
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300432
433
434/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300435 * General Driver Functions
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300436 **************************************************************************/
437
438/*
439 * si470x_get_report - receive a HID report
440 */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300441static int si470x_get_report(struct si470x_device *radio, void *buf, int size)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300442{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300443 unsigned char *report = (unsigned char *) buf;
444 int retval;
445
446 retval = usb_control_msg(radio->usbdev,
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300447 usb_rcvctrlpipe(radio->usbdev, 0),
448 HID_REQ_GET_REPORT,
449 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300450 report[0], 2,
451 buf, size, usb_timeout);
452 if (retval < 0)
453 printk(KERN_WARNING DRIVER_NAME
454 ": si470x_get_report: usb_control_msg returned %d\n",
455 retval);
456
457 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300458}
459
460
461/*
462 * si470x_set_report - send a HID report
463 */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300464static int si470x_set_report(struct si470x_device *radio, void *buf, int size)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300465{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300466 unsigned char *report = (unsigned char *) buf;
467 int retval;
468
469 retval = usb_control_msg(radio->usbdev,
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300470 usb_sndctrlpipe(radio->usbdev, 0),
471 HID_REQ_SET_REPORT,
472 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300473 report[0], 2,
474 buf, size, usb_timeout);
475 if (retval < 0)
476 printk(KERN_WARNING DRIVER_NAME
477 ": si470x_set_report: usb_control_msg returned %d\n",
478 retval);
479
480 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300481}
482
483
484/*
485 * si470x_get_register - read register
486 */
487static int si470x_get_register(struct si470x_device *radio, int regnr)
488{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300489 unsigned char buf[REGISTER_REPORT_SIZE];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300490 int retval;
491
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300492 buf[0] = REGISTER_REPORT(regnr);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300493
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300494 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
495
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300496 if (retval >= 0)
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300497 radio->registers[regnr] = (buf[1] << 8) | buf[2];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300498
499 return (retval < 0) ? -EINVAL : 0;
500}
501
502
503/*
504 * si470x_set_register - write register
505 */
506static int si470x_set_register(struct si470x_device *radio, int regnr)
507{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300508 unsigned char buf[REGISTER_REPORT_SIZE];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300509 int retval;
510
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300511 buf[0] = REGISTER_REPORT(regnr);
512 buf[1] = (radio->registers[regnr] & 0xff00) >> 8;
513 buf[2] = (radio->registers[regnr] & 0x00ff);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300514
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300515 retval = si470x_set_report(radio, (void *) &buf, sizeof(buf));
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300516
517 return (retval < 0) ? -EINVAL : 0;
518}
519
520
521/*
522 * si470x_get_all_registers - read entire registers
523 */
524static int si470x_get_all_registers(struct si470x_device *radio)
525{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300526 unsigned char buf[ENTIRE_REPORT_SIZE];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300527 int retval;
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300528 unsigned char regnr;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300529
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300530 buf[0] = ENTIRE_REPORT;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300531
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300532 retval = si470x_get_report(radio, (void *) &buf, sizeof(buf));
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300533
534 if (retval >= 0)
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300535 for (regnr = 0; regnr < RADIO_REGISTER_NUM; regnr++)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300536 radio->registers[regnr] =
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300537 (buf[regnr * RADIO_REGISTER_SIZE + 1] << 8) |
538 buf[regnr * RADIO_REGISTER_SIZE + 2];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300539
540 return (retval < 0) ? -EINVAL : 0;
541}
542
543
544/*
545 * si470x_get_rds_registers - read rds registers
546 */
547static int si470x_get_rds_registers(struct si470x_device *radio)
548{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300549 unsigned char buf[RDS_REPORT_SIZE];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300550 int retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300551 int size;
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300552 unsigned char regnr;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300553
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300554 buf[0] = RDS_REPORT;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300555
556 retval = usb_interrupt_msg(radio->usbdev,
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300557 usb_rcvintpipe(radio->usbdev, 1),
558 (void *) &buf, sizeof(buf), &size, usb_timeout);
559 if (size != sizeof(buf))
560 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_register: "
561 "return size differs: %d != %d\n", size, sizeof(buf));
562 if (retval < 0)
563 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
564 "usb_interrupt_msg returned %d\n", retval);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300565
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300566 if (retval >= 0)
567 for (regnr = 0; regnr < RDS_REGISTER_NUM; regnr++)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300568 radio->registers[STATUSRSSI + regnr] =
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300569 (buf[regnr * RADIO_REGISTER_SIZE + 1] << 8) |
570 buf[regnr * RADIO_REGISTER_SIZE + 2];
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300571
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300572 return (retval < 0) ? -EINVAL : 0;
573}
574
575
576/*
577 * si470x_set_chan - set the channel
578 */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300579static int si470x_set_chan(struct si470x_device *radio, unsigned short chan)
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300580{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300581 int retval;
582 unsigned long timeout;
583 bool timed_out = 0;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300584
585 /* start tuning */
586 radio->registers[CHANNEL] &= ~CHANNEL_CHAN;
587 radio->registers[CHANNEL] |= CHANNEL_TUNE | chan;
588 retval = si470x_set_register(radio, CHANNEL);
589 if (retval < 0)
590 return retval;
591
592 /* wait till seek operation has completed */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300593 timeout = jiffies + msecs_to_jiffies(tune_timeout);
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300594 do {
595 retval = si470x_get_register(radio, STATUSRSSI);
596 if (retval < 0)
597 return retval;
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300598 timed_out = time_after(jiffies, timeout);
599 } while (((radio->registers[STATUSRSSI] & STATUSRSSI_STC) == 0) &&
600 (!timed_out));
601 if (timed_out)
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300602 printk(KERN_WARNING DRIVER_NAME
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300603 ": seek does not finish after %d ms\n", tune_timeout);
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300604
605 /* stop tuning */
606 radio->registers[CHANNEL] &= ~CHANNEL_TUNE;
607 return si470x_set_register(radio, CHANNEL);
608}
609
610
611/*
612 * si470x_get_freq - get the frequency
613 */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300614static unsigned int si470x_get_freq(struct si470x_device *radio)
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300615{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300616 unsigned int spacing, band_bottom, freq;
617 unsigned short chan;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300618 int retval;
619
620 /* Spacing (kHz) */
621 switch (space) {
622 /* 0: 200 kHz (USA, Australia) */
623 case 0 : spacing = 0.200 * FREQ_MUL; break;
624 /* 1: 100 kHz (Europe, Japan) */
625 case 1 : spacing = 0.100 * FREQ_MUL; break;
626 /* 2: 50 kHz */
627 default: spacing = 0.050 * FREQ_MUL; break;
628 };
629
630 /* Bottom of Band (MHz) */
631 switch (band) {
632 /* 0: 87.5 - 108 MHz (USA, Europe) */
633 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
634 /* 1: 76 - 108 MHz (Japan wide band) */
635 default: band_bottom = 76 * FREQ_MUL; break;
636 /* 2: 76 - 90 MHz (Japan) */
637 case 2 : band_bottom = 76 * FREQ_MUL; break;
638 };
639
640 /* read channel */
641 retval = si470x_get_register(radio, READCHAN);
642 if (retval < 0)
643 return retval;
644 chan = radio->registers[READCHAN] & READCHAN_READCHAN;
645
646 /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
647 freq = chan * spacing + band_bottom;
648
649 return freq;
650}
651
652
653/*
654 * si470x_set_freq - set the frequency
655 */
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300656static int si470x_set_freq(struct si470x_device *radio, unsigned int freq)
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300657{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300658 unsigned int spacing, band_bottom;
659 unsigned short chan;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300660
661 /* Spacing (kHz) */
662 switch (space) {
663 /* 0: 200 kHz (USA, Australia) */
664 case 0 : spacing = 0.200 * FREQ_MUL; break;
665 /* 1: 100 kHz (Europe, Japan) */
666 case 1 : spacing = 0.100 * FREQ_MUL; break;
667 /* 2: 50 kHz */
668 default: spacing = 0.050 * FREQ_MUL; break;
669 };
670
671 /* Bottom of Band (MHz) */
672 switch (band) {
673 /* 0: 87.5 - 108 MHz (USA, Europe) */
674 case 0 : band_bottom = 87.5 * FREQ_MUL; break;
675 /* 1: 76 - 108 MHz (Japan wide band) */
676 default: band_bottom = 76 * FREQ_MUL; break;
677 /* 2: 76 - 90 MHz (Japan) */
678 case 2 : band_bottom = 76 * FREQ_MUL; break;
679 };
680
681 /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
682 chan = (freq - band_bottom) / spacing;
683
684 return si470x_set_chan(radio, chan);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300685}
686
687
688/*
689 * si470x_start - switch on radio
690 */
691static int si470x_start(struct si470x_device *radio)
692{
693 int retval;
694
695 /* powercfg */
696 radio->registers[POWERCFG] =
697 POWERCFG_DMUTE | POWERCFG_ENABLE | POWERCFG_RDSM;
698 retval = si470x_set_register(radio, POWERCFG);
699 if (retval < 0)
700 return retval;
701
702 /* sysconfig 1 */
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300703 radio->registers[SYSCONFIG1] = SYSCONFIG1_DE;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300704 retval = si470x_set_register(radio, SYSCONFIG1);
705 if (retval < 0)
706 return retval;
707
708 /* sysconfig 2 */
709 radio->registers[SYSCONFIG2] =
710 (0x3f << 8) | /* SEEKTH */
711 (band << 6) | /* BAND */
712 (space << 4) | /* SPACE */
713 15; /* VOLUME (max) */
714 retval = si470x_set_register(radio, SYSCONFIG2);
715 if (retval < 0)
716 return retval;
717
718 /* reset last channel */
719 return si470x_set_chan(radio,
720 radio->registers[CHANNEL] & CHANNEL_CHAN);
721}
722
723
724/*
725 * si470x_stop - switch off radio
726 */
727static int si470x_stop(struct si470x_device *radio)
728{
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300729 int retval;
730
731 /* sysconfig 1 */
732 radio->registers[SYSCONFIG1] &= ~SYSCONFIG1_RDS;
733 retval = si470x_set_register(radio, SYSCONFIG1);
734 if (retval < 0)
735 return retval;
736
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300737 /* powercfg */
738 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
739 /* POWERCFG_ENABLE has to automatically go low */
740 radio->registers[POWERCFG] |= POWERCFG_ENABLE | POWERCFG_DISABLE;
741 return si470x_set_register(radio, POWERCFG);
742}
743
744
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300745/*
746 * si470x_rds_on - switch on rds reception
747 */
748static int si470x_rds_on(struct si470x_device *radio)
749{
750 /* sysconfig 1 */
751 radio->registers[SYSCONFIG1] |= SYSCONFIG1_RDS;
752 return si470x_set_register(radio, SYSCONFIG1);
753}
754
755
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300756
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300757/**************************************************************************
758 * RDS Driver Functions
759 **************************************************************************/
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300760
761/*
762 * si470x_rds - rds processing function
763 */
764static void si470x_rds(struct si470x_device *radio)
765{
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300766 /* get rds blocks */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300767 if (si470x_get_rds_registers(radio) < 0)
768 return;
769 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSR) == 0) {
770 /* No RDS group ready */
771 return;
772 }
773 if ((radio->registers[STATUSRSSI] & STATUSRSSI_RDSS) == 0) {
774 /* RDS decoder not synchronized */
775 return;
776 }
777
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300778 /* copy four RDS blocks to internal buffer */
779 if (spin_trylock(&radio->lock)) {
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300780 unsigned char blocknum;
781 unsigned short bler; /* rds block errors */
782 unsigned short rds;
783 unsigned char tmpbuf[3];
784 unsigned char i;
785
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300786 /* process each rds block */
787 for (blocknum = 0; blocknum < 4; blocknum++) {
788 switch (blocknum) {
789 default:
790 bler = (radio->registers[STATUSRSSI] &
791 STATUSRSSI_BLERA) >> 9;
792 rds = radio->registers[RDSA];
793 break;
794 case 1:
795 bler = (radio->registers[READCHAN] &
796 READCHAN_BLERB) >> 14;
797 rds = radio->registers[RDSB];
798 break;
799 case 2:
800 bler = (radio->registers[READCHAN] &
801 READCHAN_BLERC) >> 12;
802 rds = radio->registers[RDSC];
803 break;
804 case 3:
805 bler = (radio->registers[READCHAN] &
806 READCHAN_BLERD) >> 10;
807 rds = radio->registers[RDSD];
808 break;
809 };
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300810
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300811 /* Fill the V4L2 RDS buffer */
812 tmpbuf[0] = rds & 0x00ff; /* LSB */
813 tmpbuf[1] = (rds & 0xff00) >> 8;/* MSB */
814 tmpbuf[2] = blocknum; /* offset name */
815 tmpbuf[2] |= blocknum << 3; /* received offset */
816 if (bler > max_rds_errors)
817 tmpbuf[2] |= 0x80; /* uncorrectable errors */
818 else if (bler > 0)
819 tmpbuf[2] |= 0x40; /* corrected error(s) */
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300820
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300821 /* copy RDS block to internal buffer */
822 for (i = 0; i < 3; i++) {
823 radio->buffer[radio->wr_index] = tmpbuf[i];
824 radio->wr_index++;
825 }
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300826
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300827 /* wrap write pointer */
828 if (radio->wr_index >= radio->buf_size)
829 radio->wr_index = 0;
830
831 /* check for overflow */
832 if (radio->wr_index == radio->rd_index) {
833 /* increment and wrap read pointer */
834 radio->rd_index += 3;
835 if (radio->rd_index >= radio->buf_size)
836 radio->rd_index = 0;
837 }
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300838 }
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300839 spin_unlock(&radio->lock);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300840 }
841
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300842 /* wake up read queue */
843 if (radio->wr_index != radio->rd_index)
844 wake_up_interruptible(&radio->read_queue);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300845}
846
847
848/*
849 * si470x_timer - rds timer function
850 */
851static void si470x_timer(unsigned long data)
852{
853 struct si470x_device *radio = (struct si470x_device *) data;
854
855 schedule_work(&radio->work);
856}
857
858
859/*
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300860 * si470x_work - rds work function
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300861 */
862static void si470x_work(struct work_struct *work)
863{
864 struct si470x_device *radio = container_of(work, struct si470x_device,
865 work);
866
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300867 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300868 return;
869
870 si470x_rds(radio);
871 mod_timer(&radio->timer, jiffies + msecs_to_jiffies(rds_poll_time));
872}
873
874
875
876/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -0300877 * File Operations Interface
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300878 **************************************************************************/
879
880/*
881 * si470x_fops_read - read RDS data
882 */
883static ssize_t si470x_fops_read(struct file *file, char __user *buf,
884 size_t count, loff_t *ppos)
885{
886 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300887 int retval = 0;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300888
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300889 /* switch on rds reception */
890 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
891 si470x_rds_on(radio);
892 schedule_work(&radio->work);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300893 }
894
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300895 /* block if no new data available */
896 while (radio->wr_index == radio->rd_index) {
897 if (file->f_flags & O_NONBLOCK)
898 return -EWOULDBLOCK;
899 interruptible_sleep_on(&radio->read_queue);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300900 }
901
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300902 /* calculate block count from byte count */
903 count /= 3;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300904
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300905 /* copy RDS block out of internal buffer and to user buffer */
906 if (spin_trylock(&radio->lock)) {
Tobias Lorenz0e3301e2008-01-27 14:54:07 -0300907 unsigned int block_count = 0;
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300908 while (block_count < count) {
909 if (radio->rd_index == radio->wr_index)
910 break;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300911
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300912 /* always transfer rds complete blocks */
913 if (copy_to_user(buf,
914 &radio->buffer[radio->rd_index], 3))
915 /* retval = -EFAULT; */
916 break;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300917
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300918 /* increment and wrap read pointer */
919 radio->rd_index += 3;
920 if (radio->rd_index >= radio->buf_size)
921 radio->rd_index = 0;
922
923 /* increment counters */
924 block_count++;
925 buf += 3;
926 retval += 3;
927 }
928
929 spin_unlock(&radio->lock);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300930 }
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300931
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300932 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300933}
934
935
936/*
937 * si470x_fops_poll - poll RDS data
938 */
939static unsigned int si470x_fops_poll(struct file *file,
940 struct poll_table_struct *pts)
941{
942 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300943
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300944 /* switch on rds reception */
945 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) {
946 si470x_rds_on(radio);
947 schedule_work(&radio->work);
948 }
949
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300950 poll_wait(file, &radio->read_queue, pts);
951
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300952 if (radio->rd_index != radio->wr_index)
953 return POLLIN | POLLRDNORM;
954
955 return 0;
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300956}
957
958
959/*
960 * si470x_fops_open - file open
961 */
962static int si470x_fops_open(struct inode *inode, struct file *file)
963{
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300964 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
965
966 radio->users++;
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300967 if (radio->users == 1)
968 return si470x_start(radio);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300969
970 return 0;
971}
972
973
974/*
975 * si470x_fops_release - file release
976 */
977static int si470x_fops_release(struct inode *inode, struct file *file)
978{
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300979 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
980
981 if (!radio)
982 return -ENODEV;
983
984 radio->users--;
985 if (radio->users == 0) {
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300986 /* stop rds reception */
987 del_timer_sync(&radio->timer);
988 flush_scheduled_work();
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300989
Tobias Lorenz2fb88402008-01-25 05:14:57 -0300990 /* cancel read processes */
991 wake_up_interruptible(&radio->read_queue);
992
993 return si470x_stop(radio);
Tobias Lorenz78656ac2008-01-14 21:55:27 -0300994 }
995
996 return 0;
997}
998
999
1000/*
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001001 * si470x_fops - file operations interface
1002 */
1003static const struct file_operations si470x_fops = {
1004 .owner = THIS_MODULE,
1005 .llseek = no_llseek,
1006 .read = si470x_fops_read,
1007 .poll = si470x_fops_poll,
1008 .ioctl = video_ioctl2,
1009 .compat_ioctl = v4l_compat_ioctl32,
1010 .open = si470x_fops_open,
1011 .release = si470x_fops_release,
1012};
1013
1014
1015
1016/**************************************************************************
1017 * Video4Linux Interface
1018 **************************************************************************/
1019
1020/*
1021 * si470x_v4l2_queryctrl - query control
1022 */
1023static struct v4l2_queryctrl si470x_v4l2_queryctrl[] = {
1024/* HINT: the disabled controls are only here to satify kradio and such apps */
1025 {
1026 .id = V4L2_CID_AUDIO_VOLUME,
1027 .type = V4L2_CTRL_TYPE_INTEGER,
1028 .name = "Volume",
1029 .minimum = 0,
1030 .maximum = 15,
1031 .step = 1,
1032 .default_value = 15,
1033 },
1034 {
1035 .id = V4L2_CID_AUDIO_BALANCE,
1036 .flags = V4L2_CTRL_FLAG_DISABLED,
1037 },
1038 {
1039 .id = V4L2_CID_AUDIO_BASS,
1040 .flags = V4L2_CTRL_FLAG_DISABLED,
1041 },
1042 {
1043 .id = V4L2_CID_AUDIO_TREBLE,
1044 .flags = V4L2_CTRL_FLAG_DISABLED,
1045 },
1046 {
1047 .id = V4L2_CID_AUDIO_MUTE,
1048 .type = V4L2_CTRL_TYPE_BOOLEAN,
1049 .name = "Mute",
1050 .minimum = 0,
1051 .maximum = 1,
1052 .step = 1,
1053 .default_value = 1,
1054 },
1055 {
1056 .id = V4L2_CID_AUDIO_LOUDNESS,
1057 .flags = V4L2_CTRL_FLAG_DISABLED,
1058 },
1059};
1060
1061
1062/*
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001063 * si470x_vidioc_querycap - query device capabilities
1064 */
1065static int si470x_vidioc_querycap(struct file *file, void *priv,
1066 struct v4l2_capability *capability)
1067{
1068 strlcpy(capability->driver, DRIVER_NAME, sizeof(capability->driver));
1069 strlcpy(capability->card, DRIVER_CARD, sizeof(capability->card));
1070 sprintf(capability->bus_info, "USB");
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001071 capability->version = DRIVER_KERNEL_VERSION;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001072 capability->capabilities = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
1073
1074 return 0;
1075}
1076
1077
1078/*
1079 * si470x_vidioc_g_input - get input
1080 */
1081static int si470x_vidioc_g_input(struct file *filp, void *priv,
1082 unsigned int *i)
1083{
1084 *i = 0;
1085
1086 return 0;
1087}
1088
1089
1090/*
1091 * si470x_vidioc_s_input - set input
1092 */
1093static int si470x_vidioc_s_input(struct file *filp, void *priv, unsigned int i)
1094{
1095 if (i != 0)
1096 return -EINVAL;
1097
1098 return 0;
1099}
1100
1101
1102/*
1103 * si470x_vidioc_queryctrl - enumerate control items
1104 */
1105static int si470x_vidioc_queryctrl(struct file *file, void *priv,
1106 struct v4l2_queryctrl *qc)
1107{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001108 unsigned char i;
1109 int retval = -EINVAL;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001110
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001111 for (i = 0; i < ARRAY_SIZE(si470x_v4l2_queryctrl); i++) {
1112 if (qc->id && qc->id == si470x_v4l2_queryctrl[i].id) {
1113 memcpy(qc, &(si470x_v4l2_queryctrl[i]), sizeof(*qc));
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001114 retval = 0;
1115 break;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001116 }
1117 }
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001118 if (retval < 0)
1119 printk(KERN_WARNING DRIVER_NAME
1120 ": query control failed with %d\n", retval);
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001121
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001122 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001123}
1124
1125
1126/*
1127 * si470x_vidioc_g_ctrl - get the value of a control
1128 */
1129static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
1130 struct v4l2_control *ctrl)
1131{
1132 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1133
1134 switch (ctrl->id) {
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001135 case V4L2_CID_AUDIO_VOLUME:
1136 ctrl->value = radio->registers[SYSCONFIG2] &
1137 SYSCONFIG2_VOLUME;
1138 break;
1139 case V4L2_CID_AUDIO_MUTE:
1140 ctrl->value = ((radio->registers[POWERCFG] &
1141 POWERCFG_DMUTE) == 0) ? 1 : 0;
1142 break;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001143 }
1144
1145 return 0;
1146}
1147
1148
1149/*
1150 * si470x_vidioc_s_ctrl - set the value of a control
1151 */
1152static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
1153 struct v4l2_control *ctrl)
1154{
1155 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001156 int retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001157
1158 switch (ctrl->id) {
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001159 case V4L2_CID_AUDIO_VOLUME:
1160 radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
1161 radio->registers[SYSCONFIG2] |= ctrl->value;
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001162 retval = si470x_set_register(radio, SYSCONFIG2);
1163 break;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001164 case V4L2_CID_AUDIO_MUTE:
1165 if (ctrl->value == 1)
1166 radio->registers[POWERCFG] &= ~POWERCFG_DMUTE;
1167 else
1168 radio->registers[POWERCFG] |= POWERCFG_DMUTE;
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001169 retval = si470x_set_register(radio, POWERCFG);
1170 break;
1171 default:
1172 retval = -EINVAL;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001173 }
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001174 if (retval < 0)
1175 printk(KERN_WARNING DRIVER_NAME
1176 ": set control failed with %d\n", retval);
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001177
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001178 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001179}
1180
1181
1182/*
1183 * si470x_vidioc_g_audio - get audio attributes
1184 */
1185static int si470x_vidioc_g_audio(struct file *file, void *priv,
1186 struct v4l2_audio *audio)
1187{
1188 if (audio->index > 1)
1189 return -EINVAL;
1190
1191 strcpy(audio->name, "Radio");
1192 audio->capability = V4L2_AUDCAP_STEREO;
1193
1194 return 0;
1195}
1196
1197
1198/*
1199 * si470x_vidioc_s_audio - set audio attributes
1200 */
1201static int si470x_vidioc_s_audio(struct file *file, void *priv,
1202 struct v4l2_audio *audio)
1203{
1204 if (audio->index != 0)
1205 return -EINVAL;
1206
1207 return 0;
1208}
1209
1210
1211/*
1212 * si470x_vidioc_g_tuner - get tuner attributes
1213 */
1214static int si470x_vidioc_g_tuner(struct file *file, void *priv,
1215 struct v4l2_tuner *tuner)
1216{
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001217 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001218 int retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001219
1220 if (tuner->index > 0)
1221 return -EINVAL;
1222
1223 /* read status rssi */
1224 retval = si470x_get_register(radio, STATUSRSSI);
1225 if (retval < 0)
1226 return retval;
1227
1228 strcpy(tuner->name, "FM");
1229 tuner->type = V4L2_TUNER_RADIO;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001230 switch (band) {
1231 /* 0: 87.5 - 108 MHz (USA, Europe, default) */
1232 default:
1233 tuner->rangelow = 87.5 * FREQ_MUL;
1234 tuner->rangehigh = 108 * FREQ_MUL;
1235 break;
1236 /* 1: 76 - 108 MHz (Japan wide band) */
1237 case 1 :
1238 tuner->rangelow = 76 * FREQ_MUL;
1239 tuner->rangehigh = 108 * FREQ_MUL;
1240 break;
1241 /* 2: 76 - 90 MHz (Japan) */
1242 case 2 :
1243 tuner->rangelow = 76 * FREQ_MUL;
1244 tuner->rangehigh = 90 * FREQ_MUL;
1245 break;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001246 };
1247 tuner->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
1248 tuner->capability = V4L2_TUNER_CAP_LOW;
1249
1250 /* Stereo indicator == Stereo (instead of Mono) */
1251 if ((radio->registers[STATUSRSSI] & STATUSRSSI_ST) == 1)
1252 tuner->audmode = V4L2_TUNER_MODE_STEREO;
1253 else
1254 tuner->audmode = V4L2_TUNER_MODE_MONO;
1255
1256 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
1257 tuner->signal = (radio->registers[STATUSRSSI] & STATUSRSSI_RSSI)
1258 * 0x0101;
1259
1260 /* automatic frequency control: -1: freq to low, 1 freq to high */
1261 tuner->afc = 0;
1262
1263 return 0;
1264}
1265
1266
1267/*
1268 * si470x_vidioc_s_tuner - set tuner attributes
1269 */
1270static int si470x_vidioc_s_tuner(struct file *file, void *priv,
1271 struct v4l2_tuner *tuner)
1272{
1273 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001274 int retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001275
1276 if (tuner->index > 0)
1277 return -EINVAL;
1278
1279 if (tuner->audmode == V4L2_TUNER_MODE_MONO)
1280 radio->registers[POWERCFG] |= POWERCFG_MONO; /* force mono */
1281 else
1282 radio->registers[POWERCFG] &= ~POWERCFG_MONO; /* try stereo */
1283
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001284 retval = si470x_set_register(radio, POWERCFG);
1285 if (retval < 0)
1286 printk(KERN_WARNING DRIVER_NAME
1287 ": set tuner failed with %d\n", retval);
1288
1289 return retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001290}
1291
1292
1293/*
1294 * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
1295 */
1296static int si470x_vidioc_g_frequency(struct file *file, void *priv,
1297 struct v4l2_frequency *freq)
1298{
1299 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1300
1301 freq->type = V4L2_TUNER_RADIO;
1302 freq->frequency = si470x_get_freq(radio);
1303
1304 return 0;
1305}
1306
1307
1308/*
1309 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
1310 */
1311static int si470x_vidioc_s_frequency(struct file *file, void *priv,
1312 struct v4l2_frequency *freq)
1313{
1314 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001315 int retval;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001316
1317 if (freq->type != V4L2_TUNER_RADIO)
1318 return -EINVAL;
1319
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001320 retval = si470x_set_freq(radio, freq->frequency);
1321 if (retval < 0)
1322 printk(KERN_WARNING DRIVER_NAME
1323 ": set frequency failed with %d\n", retval);
1324
1325 return 0;
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001326}
1327
1328
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001329/*
1330 * si470x_viddev_tamples - video device interface
1331 */
1332static struct video_device si470x_viddev_template = {
1333 .fops = &si470x_fops,
1334 .name = DRIVER_NAME,
1335 .type = VID_TYPE_TUNER,
1336 .release = video_device_release,
1337 .vidioc_querycap = si470x_vidioc_querycap,
1338 .vidioc_g_input = si470x_vidioc_g_input,
1339 .vidioc_s_input = si470x_vidioc_s_input,
1340 .vidioc_queryctrl = si470x_vidioc_queryctrl,
1341 .vidioc_g_ctrl = si470x_vidioc_g_ctrl,
1342 .vidioc_s_ctrl = si470x_vidioc_s_ctrl,
1343 .vidioc_g_audio = si470x_vidioc_g_audio,
1344 .vidioc_s_audio = si470x_vidioc_s_audio,
1345 .vidioc_g_tuner = si470x_vidioc_g_tuner,
1346 .vidioc_s_tuner = si470x_vidioc_s_tuner,
1347 .vidioc_g_frequency = si470x_vidioc_g_frequency,
1348 .vidioc_s_frequency = si470x_vidioc_s_frequency,
1349 .owner = THIS_MODULE,
1350};
1351
1352
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001353
1354/**************************************************************************
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001355 * USB Interface
1356 **************************************************************************/
1357
1358/*
1359 * si470x_usb_driver_probe - probe for the device
1360 */
1361static int si470x_usb_driver_probe(struct usb_interface *intf,
1362 const struct usb_device_id *id)
1363{
1364 struct si470x_device *radio;
1365
1366 /* memory and interface allocations */
1367 radio = kmalloc(sizeof(struct si470x_device), GFP_KERNEL);
1368 if (!radio)
1369 return -ENOMEM;
1370 radio->videodev = video_device_alloc();
1371 if (!radio->videodev) {
1372 kfree(radio);
1373 return -ENOMEM;
1374 }
1375 memcpy(radio->videodev, &si470x_viddev_template,
1376 sizeof(si470x_viddev_template));
1377 radio->users = 0;
1378 radio->usbdev = interface_to_usbdev(intf);
1379 video_set_drvdata(radio->videodev, radio);
1380 if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
1381 printk(KERN_WARNING DRIVER_NAME
1382 ": Could not register video device\n");
1383 video_device_release(radio->videodev);
1384 kfree(radio);
1385 return -EIO;
1386 }
1387 usb_set_intfdata(intf, radio);
1388
1389 /* show some infos about the specific device */
1390 if (si470x_get_all_registers(radio) < 0) {
1391 video_device_release(radio->videodev);
1392 kfree(radio);
1393 return -EIO;
1394 }
1395 printk(KERN_INFO DRIVER_NAME ": DeviceID=0x%4.4x ChipID=0x%4.4x\n",
1396 radio->registers[DEVICEID], radio->registers[CHIPID]);
1397
1398 /* check if firmware is current */
1399 if ((radio->registers[CHIPID] & CHIPID_FIRMWARE)
1400 < RADIO_SW_VERSION_CURRENT)
1401 printk(KERN_WARNING DRIVER_NAME
1402 ": This driver is known to work with chip version %d, "
Tobias Lorenz2fb88402008-01-25 05:14:57 -03001403 "but the device has firmware %d.\n"
1404 DRIVER_NAME
1405 "If you have some trouble using this driver, please "
1406 "report to V4L ML at video4linux-list@redhat.com\n",
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001407 radio->registers[CHIPID] & CHIPID_FIRMWARE,
1408 RADIO_SW_VERSION_CURRENT);
1409
1410 /* set initial frequency */
1411 si470x_set_freq(radio, 87.5 * FREQ_MUL); /* available in all regions */
1412
1413 /* rds initialization */
1414 radio->buf_size = rds_buf * 3;
1415 radio->buffer = kmalloc(radio->buf_size, GFP_KERNEL);
1416 if (!radio->buffer) {
1417 video_device_release(radio->videodev);
1418 kfree(radio);
1419 return -ENOMEM;
1420 }
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001421 radio->wr_index = 0;
1422 radio->rd_index = 0;
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001423 init_waitqueue_head(&radio->read_queue);
Tobias Lorenz8bf5e5c2008-01-25 04:19:48 -03001424
1425 /* prepare polling via eventd */
1426 INIT_WORK(&radio->work, si470x_work);
1427 init_timer(&radio->timer);
1428 radio->timer.function = si470x_timer;
1429 radio->timer.data = (unsigned long) radio;
1430
1431 return 0;
1432}
1433
1434
1435/*
1436 * si470x_usb_driver_disconnect - disconnect the device
1437 */
1438static void si470x_usb_driver_disconnect(struct usb_interface *intf)
1439{
1440 struct si470x_device *radio = usb_get_intfdata(intf);
1441
1442 del_timer_sync(&radio->timer);
1443 flush_scheduled_work();
1444
1445 usb_set_intfdata(intf, NULL);
1446 if (radio) {
1447 video_unregister_device(radio->videodev);
1448 kfree(radio->buffer);
1449 kfree(radio);
1450 }
1451}
1452
1453
1454/*
1455 * si470x_usb_driver - usb driver interface
1456 */
1457static struct usb_driver si470x_usb_driver = {
1458 .name = DRIVER_NAME,
1459 .probe = si470x_usb_driver_probe,
1460 .disconnect = si470x_usb_driver_disconnect,
1461 .id_table = si470x_usb_driver_id_table,
1462};
1463
1464
1465
1466/**************************************************************************
1467 * Module Interface
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001468 **************************************************************************/
1469
1470/*
1471 * si470x_module_init - module init
1472 */
1473static int __init si470x_module_init(void)
1474{
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001475 printk(KERN_INFO DRIVER_DESC ", Version " DRIVER_VERSION "\n");
Tobias Lorenz78656ac2008-01-14 21:55:27 -03001476 return usb_register(&si470x_usb_driver);
1477}
1478
1479
1480/*
1481 * si470x_module_exit - module exit
1482 */
1483static void __exit si470x_module_exit(void)
1484{
1485 usb_deregister(&si470x_usb_driver);
1486}
1487
1488
1489module_init(si470x_module_init);
1490module_exit(si470x_module_exit);
1491
1492MODULE_LICENSE("GPL");
1493MODULE_AUTHOR(DRIVER_AUTHOR);
1494MODULE_DESCRIPTION(DRIVER_DESC);
Tobias Lorenz0e3301e2008-01-27 14:54:07 -03001495MODULE_VERSION(DRIVER_VERSION);