2 * drivers/media/radio/si470x/radio-si470x-common.c
4 * Driver for radios with Silicon Labs Si470x FM Radio Receivers
6 * Copyright (c) 2009 Tobias Lorenz <tobias.lorenz@gmx.net>
7 * Copyright (c) 2012 Hans de Goede <hdegoede@redhat.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
23 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
25 * - First working version
26 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
28 * - Improved error handling, every function now returns errno
29 * - Improved multi user access (start/mute/stop)
30 * - Channel doesn't get lost anymore after start/mute/stop
31 * - RDS support added (polling mode via interrupt EP 1)
32 * - marked default module parameters with *value*
33 * - switched from bit structs to bit masks
34 * - header file cleaned and integrated
35 * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net>
37 * - hex values are now lower case
38 * - commented USB ID for ADS/Tech moved on todo list
39 * - blacklisted si470x in hid-quirks.c
40 * - rds buffer handling functions integrated into *_work, *_read
41 * - rds_command in si470x_poll exchanged against simple retval
42 * - check for firmware version 15
43 * - code order and prototypes still remain the same
44 * - spacing and bottom of band codes remain the same
45 * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
47 * - code reordered to avoid function prototypes
48 * - switch/case defaults are now more user-friendly
49 * - unified comment style
50 * - applied all checkpatch.pl v1.12 suggestions
51 * except the warning about the too long lines with bit comments
52 * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl)
53 * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
55 * - avoid poss. locking when doing copy_to_user which may sleep
56 * - RDS is automatically activated on read now
57 * - code cleaned of unnecessary rds_commands
58 * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified
59 * (thanks to Guillaume RAMOUSSE)
60 * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net>
62 * - number of seek_retries changed to tune_timeout
63 * - fixed problem with incomplete tune operations by own buffers
64 * - optimization of variables and printf types
65 * - improved error logging
66 * 2008-01-31 Tobias Lorenz <tobias.lorenz@gmx.net>
67 * Oliver Neukum <oliver@neukum.org>
69 * - fixed coverity checker warnings in *_usb_driver_disconnect
70 * - probe()/open() race by correct ordering in probe()
71 * - DMA coherency rules by separate allocation of all buffers
72 * - use of endianness macros
73 * - abuse of spinlock, replaced by mutex
74 * - racy handling of timer in disconnect,
75 * replaced by delayed_work
76 * - racy interruptible_sleep_on(),
77 * replaced with wait_event_interruptible()
78 * - handle signals in read()
79 * 2008-02-08 Tobias Lorenz <tobias.lorenz@gmx.net>
80 * Oliver Neukum <oliver@neukum.org>
82 * - usb autosuspend support
84 * 2008-05-07 Tobias Lorenz <tobias.lorenz@gmx.net>
86 * - hardware frequency seek support
88 * - more safety checks, let si470x_get_freq return errno
89 * - vidioc behavior corrected according to v4l2 spec
90 * 2008-10-20 Alexey Klimov <klimov.linux@gmail.com>
91 * - add support for KWorld USB FM Radio FM700
92 * - blacklisted KWorld radio in hid-core.c and hid-ids.h
93 * 2008-12-03 Mark Lord <mlord@pobox.com>
94 * - add support for DealExtreme USB Radio
95 * 2009-01-31 Bob Ross <pigiron@gmx.com>
96 * - correction of stereo detection/setting
97 * - correction of signal strength indicator scaling
98 * 2009-01-31 Rick Bronson <rick@efn.org>
99 * Tobias Lorenz <tobias.lorenz@gmx.net>
100 * - add LED status output
101 * - get HW/SW version from scratchpad
102 * 2009-06-16 Edouard Lafargue <edouard@lafargue.name>
104 * - add support for interrupt mode for RDS endpoint,
105 * instead of polling.
106 * Improves RDS reception significantly
110 /* kernel includes */
111 #include "radio-si470x.h"
113 /**************************************************************************
115 **************************************************************************/
118 /* 0: 200 kHz (USA, Australia) */
119 /* 1: 100 kHz (Europe, Japan) */
121 static unsigned short space
= 2;
122 module_param(space
, ushort
, 0444);
123 MODULE_PARM_DESC(space
, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
127 /* 1: 50 us (Europe, Australia, Japan) */
128 static unsigned short de
= 1;
129 module_param(de
, ushort
, 0444);
130 MODULE_PARM_DESC(de
, "De-emphasis: 0=75us *1=50us*");
133 static unsigned int tune_timeout
= 3000;
134 module_param(tune_timeout
, uint
, 0644);
135 MODULE_PARM_DESC(tune_timeout
, "Tune timeout: *3000*");
138 static unsigned int seek_timeout
= 5000;
139 module_param(seek_timeout
, uint
, 0644);
140 MODULE_PARM_DESC(seek_timeout
, "Seek timeout: *5000*");
142 static const struct v4l2_frequency_band bands
[] = {
144 .type
= V4L2_TUNER_RADIO
,
146 .capability
= V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
|
147 V4L2_TUNER_CAP_RDS
| V4L2_TUNER_CAP_RDS_BLOCK_IO
|
148 V4L2_TUNER_CAP_FREQ_BANDS
|
149 V4L2_TUNER_CAP_HWSEEK_BOUNDED
|
150 V4L2_TUNER_CAP_HWSEEK_WRAP
,
151 .rangelow
= 87500 * 16,
152 .rangehigh
= 108000 * 16,
153 .modulation
= V4L2_BAND_MODULATION_FM
,
156 .type
= V4L2_TUNER_RADIO
,
158 .capability
= V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
|
159 V4L2_TUNER_CAP_RDS
| V4L2_TUNER_CAP_RDS_BLOCK_IO
|
160 V4L2_TUNER_CAP_FREQ_BANDS
|
161 V4L2_TUNER_CAP_HWSEEK_BOUNDED
|
162 V4L2_TUNER_CAP_HWSEEK_WRAP
,
163 .rangelow
= 76000 * 16,
164 .rangehigh
= 108000 * 16,
165 .modulation
= V4L2_BAND_MODULATION_FM
,
168 .type
= V4L2_TUNER_RADIO
,
170 .capability
= V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
|
171 V4L2_TUNER_CAP_RDS
| V4L2_TUNER_CAP_RDS_BLOCK_IO
|
172 V4L2_TUNER_CAP_FREQ_BANDS
|
173 V4L2_TUNER_CAP_HWSEEK_BOUNDED
|
174 V4L2_TUNER_CAP_HWSEEK_WRAP
,
175 .rangelow
= 76000 * 16,
176 .rangehigh
= 90000 * 16,
177 .modulation
= V4L2_BAND_MODULATION_FM
,
181 /**************************************************************************
183 **************************************************************************/
186 * si470x_set_band - set the band
188 static int si470x_set_band(struct si470x_device
*radio
, int band
)
190 if (radio
->band
== band
)
194 radio
->registers
[SYSCONFIG2
] &= ~SYSCONFIG2_BAND
;
195 radio
->registers
[SYSCONFIG2
] |= radio
->band
<< 6;
196 return radio
->set_register(radio
, SYSCONFIG2
);
200 * si470x_set_chan - set the channel
202 static int si470x_set_chan(struct si470x_device
*radio
, unsigned short chan
)
205 unsigned long time_left
;
206 bool timed_out
= false;
208 retval
= radio
->get_register(radio
, POWERCFG
);
212 if ((radio
->registers
[POWERCFG
] & (POWERCFG_ENABLE
|POWERCFG_DMUTE
))
213 != (POWERCFG_ENABLE
|POWERCFG_DMUTE
)) {
218 radio
->registers
[CHANNEL
] &= ~CHANNEL_CHAN
;
219 radio
->registers
[CHANNEL
] |= CHANNEL_TUNE
| chan
;
220 retval
= radio
->set_register(radio
, CHANNEL
);
224 /* wait till tune operation has completed */
225 reinit_completion(&radio
->completion
);
226 time_left
= wait_for_completion_timeout(&radio
->completion
,
227 msecs_to_jiffies(tune_timeout
));
231 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0)
232 dev_warn(&radio
->videodev
.dev
, "tune does not complete\n");
234 dev_warn(&radio
->videodev
.dev
,
235 "tune timed out after %u ms\n", tune_timeout
);
238 radio
->registers
[CHANNEL
] &= ~CHANNEL_TUNE
;
239 retval
= radio
->set_register(radio
, CHANNEL
);
246 * si470x_get_step - get channel spacing
248 static unsigned int si470x_get_step(struct si470x_device
*radio
)
251 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_SPACE
) >> 4) {
252 /* 0: 200 kHz (USA, Australia) */
255 /* 1: 100 kHz (Europe, Japan) */
266 * si470x_get_freq - get the frequency
268 static int si470x_get_freq(struct si470x_device
*radio
, unsigned int *freq
)
273 retval
= radio
->get_register(radio
, READCHAN
);
274 chan
= radio
->registers
[READCHAN
] & READCHAN_READCHAN
;
276 /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
277 *freq
= chan
* si470x_get_step(radio
) + bands
[radio
->band
].rangelow
;
284 * si470x_set_freq - set the frequency
286 int si470x_set_freq(struct si470x_device
*radio
, unsigned int freq
)
290 freq
= clamp(freq
, bands
[radio
->band
].rangelow
,
291 bands
[radio
->band
].rangehigh
);
292 /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
293 chan
= (freq
- bands
[radio
->band
].rangelow
) / si470x_get_step(radio
);
295 return si470x_set_chan(radio
, chan
);
297 EXPORT_SYMBOL_GPL(si470x_set_freq
);
301 * si470x_set_seek - set seek
303 static int si470x_set_seek(struct si470x_device
*radio
,
304 const struct v4l2_hw_freq_seek
*seek
)
308 bool timed_out
= false;
309 unsigned long time_left
;
312 if (seek
->rangelow
|| seek
->rangehigh
) {
313 for (band
= 0; band
< ARRAY_SIZE(bands
); band
++) {
314 if (bands
[band
].rangelow
== seek
->rangelow
&&
315 bands
[band
].rangehigh
== seek
->rangehigh
)
318 if (band
== ARRAY_SIZE(bands
))
319 return -EINVAL
; /* No matching band found */
321 band
= 1; /* If nothing is specified seek 76 - 108 Mhz */
323 if (radio
->band
!= band
) {
324 retval
= si470x_get_freq(radio
, &freq
);
327 retval
= si470x_set_band(radio
, band
);
330 retval
= si470x_set_freq(radio
, freq
);
336 radio
->registers
[POWERCFG
] |= POWERCFG_SEEK
;
337 if (seek
->wrap_around
)
338 radio
->registers
[POWERCFG
] &= ~POWERCFG_SKMODE
;
340 radio
->registers
[POWERCFG
] |= POWERCFG_SKMODE
;
341 if (seek
->seek_upward
)
342 radio
->registers
[POWERCFG
] |= POWERCFG_SEEKUP
;
344 radio
->registers
[POWERCFG
] &= ~POWERCFG_SEEKUP
;
345 retval
= radio
->set_register(radio
, POWERCFG
);
349 /* wait till tune operation has completed */
350 reinit_completion(&radio
->completion
);
351 time_left
= wait_for_completion_timeout(&radio
->completion
,
352 msecs_to_jiffies(seek_timeout
));
356 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0)
357 dev_warn(&radio
->videodev
.dev
, "seek does not complete\n");
358 if (radio
->registers
[STATUSRSSI
] & STATUSRSSI_SF
)
359 dev_warn(&radio
->videodev
.dev
,
360 "seek failed / band limit reached\n");
363 radio
->registers
[POWERCFG
] &= ~POWERCFG_SEEK
;
364 retval
= radio
->set_register(radio
, POWERCFG
);
366 /* try again, if timed out */
367 if (retval
== 0 && timed_out
)
374 * si470x_start - switch on radio
376 int si470x_start(struct si470x_device
*radio
)
381 radio
->registers
[POWERCFG
] =
382 POWERCFG_DMUTE
| POWERCFG_ENABLE
| POWERCFG_RDSM
;
383 retval
= radio
->set_register(radio
, POWERCFG
);
388 radio
->registers
[SYSCONFIG1
] |= SYSCONFIG1_RDSIEN
| SYSCONFIG1_STCIEN
|
390 radio
->registers
[SYSCONFIG1
] &= ~SYSCONFIG1_GPIO2
;
391 radio
->registers
[SYSCONFIG1
] |= SYSCONFIG1_GPIO2_INT
;
393 radio
->registers
[SYSCONFIG1
] |= SYSCONFIG1_DE
;
394 retval
= radio
->set_register(radio
, SYSCONFIG1
);
399 radio
->registers
[SYSCONFIG2
] =
400 (0x1f << 8) | /* SEEKTH */
401 ((radio
->band
<< 6) & SYSCONFIG2_BAND
) |/* BAND */
402 ((space
<< 4) & SYSCONFIG2_SPACE
) | /* SPACE */
403 15; /* VOLUME (max) */
404 retval
= radio
->set_register(radio
, SYSCONFIG2
);
408 /* reset last channel */
409 retval
= si470x_set_chan(radio
,
410 radio
->registers
[CHANNEL
] & CHANNEL_CHAN
);
415 EXPORT_SYMBOL_GPL(si470x_start
);
419 * si470x_stop - switch off radio
421 int si470x_stop(struct si470x_device
*radio
)
426 radio
->registers
[SYSCONFIG1
] &= ~SYSCONFIG1_RDS
;
427 retval
= radio
->set_register(radio
, SYSCONFIG1
);
432 radio
->registers
[POWERCFG
] &= ~POWERCFG_DMUTE
;
433 /* POWERCFG_ENABLE has to automatically go low */
434 radio
->registers
[POWERCFG
] |= POWERCFG_ENABLE
| POWERCFG_DISABLE
;
435 retval
= radio
->set_register(radio
, POWERCFG
);
440 EXPORT_SYMBOL_GPL(si470x_stop
);
444 * si470x_rds_on - switch on rds reception
446 static int si470x_rds_on(struct si470x_device
*radio
)
451 radio
->registers
[SYSCONFIG1
] |= SYSCONFIG1_RDS
;
452 retval
= radio
->set_register(radio
, SYSCONFIG1
);
454 radio
->registers
[SYSCONFIG1
] &= ~SYSCONFIG1_RDS
;
461 /**************************************************************************
462 * File Operations Interface
463 **************************************************************************/
466 * si470x_fops_read - read RDS data
468 static ssize_t
si470x_fops_read(struct file
*file
, char __user
*buf
,
469 size_t count
, loff_t
*ppos
)
471 struct si470x_device
*radio
= video_drvdata(file
);
473 unsigned int block_count
= 0;
475 /* switch on rds reception */
476 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
) == 0)
477 si470x_rds_on(radio
);
479 /* block if no new data available */
480 while (radio
->wr_index
== radio
->rd_index
) {
481 if (file
->f_flags
& O_NONBLOCK
) {
482 retval
= -EWOULDBLOCK
;
485 if (wait_event_interruptible(radio
->read_queue
,
486 radio
->wr_index
!= radio
->rd_index
) < 0) {
492 /* calculate block count from byte count */
495 /* copy RDS block out of internal buffer and to user buffer */
496 while (block_count
< count
) {
497 if (radio
->rd_index
== radio
->wr_index
)
500 /* always transfer rds complete blocks */
501 if (copy_to_user(buf
, &radio
->buffer
[radio
->rd_index
], 3))
502 /* retval = -EFAULT; */
505 /* increment and wrap read pointer */
506 radio
->rd_index
+= 3;
507 if (radio
->rd_index
>= radio
->buf_size
)
510 /* increment counters */
522 * si470x_fops_poll - poll RDS data
524 static __poll_t
si470x_fops_poll(struct file
*file
,
525 struct poll_table_struct
*pts
)
527 struct si470x_device
*radio
= video_drvdata(file
);
528 __poll_t req_events
= poll_requested_events(pts
);
529 __poll_t retval
= v4l2_ctrl_poll(file
, pts
);
531 if (req_events
& (EPOLLIN
| EPOLLRDNORM
)) {
532 /* switch on rds reception */
533 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
) == 0)
534 si470x_rds_on(radio
);
536 poll_wait(file
, &radio
->read_queue
, pts
);
538 if (radio
->rd_index
!= radio
->wr_index
)
539 retval
|= EPOLLIN
| EPOLLRDNORM
;
546 static int si470x_fops_open(struct file
*file
)
548 struct si470x_device
*radio
= video_drvdata(file
);
550 return radio
->fops_open(file
);
555 * si470x_fops_release - file release
557 static int si470x_fops_release(struct file
*file
)
559 struct si470x_device
*radio
= video_drvdata(file
);
561 return radio
->fops_release(file
);
566 * si470x_fops - file operations interface
568 static const struct v4l2_file_operations si470x_fops
= {
569 .owner
= THIS_MODULE
,
570 .read
= si470x_fops_read
,
571 .poll
= si470x_fops_poll
,
572 .unlocked_ioctl
= video_ioctl2
,
573 .open
= si470x_fops_open
,
574 .release
= si470x_fops_release
,
579 /**************************************************************************
580 * Video4Linux Interface
581 **************************************************************************/
584 static int si470x_s_ctrl(struct v4l2_ctrl
*ctrl
)
586 struct si470x_device
*radio
=
587 container_of(ctrl
->handler
, struct si470x_device
, hdl
);
590 case V4L2_CID_AUDIO_VOLUME
:
591 radio
->registers
[SYSCONFIG2
] &= ~SYSCONFIG2_VOLUME
;
592 radio
->registers
[SYSCONFIG2
] |= ctrl
->val
;
593 return radio
->set_register(radio
, SYSCONFIG2
);
594 case V4L2_CID_AUDIO_MUTE
:
596 radio
->registers
[POWERCFG
] &= ~POWERCFG_DMUTE
;
598 radio
->registers
[POWERCFG
] |= POWERCFG_DMUTE
;
599 return radio
->set_register(radio
, POWERCFG
);
607 * si470x_vidioc_g_tuner - get tuner attributes
609 static int si470x_vidioc_g_tuner(struct file
*file
, void *priv
,
610 struct v4l2_tuner
*tuner
)
612 struct si470x_device
*radio
= video_drvdata(file
);
615 if (tuner
->index
!= 0)
618 if (!radio
->status_rssi_auto_update
) {
619 retval
= radio
->get_register(radio
, STATUSRSSI
);
624 /* driver constants */
625 strcpy(tuner
->name
, "FM");
626 tuner
->type
= V4L2_TUNER_RADIO
;
627 tuner
->capability
= V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
|
628 V4L2_TUNER_CAP_RDS
| V4L2_TUNER_CAP_RDS_BLOCK_IO
|
629 V4L2_TUNER_CAP_HWSEEK_BOUNDED
|
630 V4L2_TUNER_CAP_HWSEEK_WRAP
;
631 tuner
->rangelow
= 76 * FREQ_MUL
;
632 tuner
->rangehigh
= 108 * FREQ_MUL
;
634 /* stereo indicator == stereo (instead of mono) */
635 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_ST
) == 0)
636 tuner
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
638 tuner
->rxsubchans
= V4L2_TUNER_SUB_STEREO
;
639 /* If there is a reliable method of detecting an RDS channel,
640 then this code should check for that before setting this
642 tuner
->rxsubchans
|= V4L2_TUNER_SUB_RDS
;
644 /* mono/stereo selector */
645 if ((radio
->registers
[POWERCFG
] & POWERCFG_MONO
) == 0)
646 tuner
->audmode
= V4L2_TUNER_MODE_STEREO
;
648 tuner
->audmode
= V4L2_TUNER_MODE_MONO
;
650 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
651 /* measured in units of dbµV in 1 db increments (max at ~75 dbµV) */
652 tuner
->signal
= (radio
->registers
[STATUSRSSI
] & STATUSRSSI_RSSI
);
653 /* the ideal factor is 0xffff/75 = 873,8 */
654 tuner
->signal
= (tuner
->signal
* 873) + (8 * tuner
->signal
/ 10);
655 if (tuner
->signal
> 0xffff)
656 tuner
->signal
= 0xffff;
658 /* automatic frequency control: -1: freq to low, 1 freq to high */
659 /* AFCRL does only indicate that freq. differs, not if too low/high */
660 tuner
->afc
= (radio
->registers
[STATUSRSSI
] & STATUSRSSI_AFCRL
) ? 1 : 0;
667 * si470x_vidioc_s_tuner - set tuner attributes
669 static int si470x_vidioc_s_tuner(struct file
*file
, void *priv
,
670 const struct v4l2_tuner
*tuner
)
672 struct si470x_device
*radio
= video_drvdata(file
);
674 if (tuner
->index
!= 0)
677 /* mono/stereo selector */
678 switch (tuner
->audmode
) {
679 case V4L2_TUNER_MODE_MONO
:
680 radio
->registers
[POWERCFG
] |= POWERCFG_MONO
; /* force mono */
682 case V4L2_TUNER_MODE_STEREO
:
684 radio
->registers
[POWERCFG
] &= ~POWERCFG_MONO
; /* try stereo */
688 return radio
->set_register(radio
, POWERCFG
);
693 * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
695 static int si470x_vidioc_g_frequency(struct file
*file
, void *priv
,
696 struct v4l2_frequency
*freq
)
698 struct si470x_device
*radio
= video_drvdata(file
);
700 if (freq
->tuner
!= 0)
703 freq
->type
= V4L2_TUNER_RADIO
;
704 return si470x_get_freq(radio
, &freq
->frequency
);
709 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
711 static int si470x_vidioc_s_frequency(struct file
*file
, void *priv
,
712 const struct v4l2_frequency
*freq
)
714 struct si470x_device
*radio
= video_drvdata(file
);
717 if (freq
->tuner
!= 0)
720 if (freq
->frequency
< bands
[radio
->band
].rangelow
||
721 freq
->frequency
> bands
[radio
->band
].rangehigh
) {
722 /* Switch to band 1 which covers everything we support */
723 retval
= si470x_set_band(radio
, 1);
727 return si470x_set_freq(radio
, freq
->frequency
);
732 * si470x_vidioc_s_hw_freq_seek - set hardware frequency seek
734 static int si470x_vidioc_s_hw_freq_seek(struct file
*file
, void *priv
,
735 const struct v4l2_hw_freq_seek
*seek
)
737 struct si470x_device
*radio
= video_drvdata(file
);
739 if (seek
->tuner
!= 0)
742 if (file
->f_flags
& O_NONBLOCK
)
745 return si470x_set_seek(radio
, seek
);
749 * si470x_vidioc_enum_freq_bands - enumerate supported bands
751 static int si470x_vidioc_enum_freq_bands(struct file
*file
, void *priv
,
752 struct v4l2_frequency_band
*band
)
754 if (band
->tuner
!= 0)
756 if (band
->index
>= ARRAY_SIZE(bands
))
758 *band
= bands
[band
->index
];
762 const struct v4l2_ctrl_ops si470x_ctrl_ops
= {
763 .s_ctrl
= si470x_s_ctrl
,
765 EXPORT_SYMBOL_GPL(si470x_ctrl_ops
);
767 static int si470x_vidioc_querycap(struct file
*file
, void *priv
,
768 struct v4l2_capability
*capability
)
770 struct si470x_device
*radio
= video_drvdata(file
);
772 return radio
->vidioc_querycap(file
, priv
, capability
);
776 * si470x_ioctl_ops - video device ioctl operations
778 static const struct v4l2_ioctl_ops si470x_ioctl_ops
= {
779 .vidioc_querycap
= si470x_vidioc_querycap
,
780 .vidioc_g_tuner
= si470x_vidioc_g_tuner
,
781 .vidioc_s_tuner
= si470x_vidioc_s_tuner
,
782 .vidioc_g_frequency
= si470x_vidioc_g_frequency
,
783 .vidioc_s_frequency
= si470x_vidioc_s_frequency
,
784 .vidioc_s_hw_freq_seek
= si470x_vidioc_s_hw_freq_seek
,
785 .vidioc_enum_freq_bands
= si470x_vidioc_enum_freq_bands
,
786 .vidioc_subscribe_event
= v4l2_ctrl_subscribe_event
,
787 .vidioc_unsubscribe_event
= v4l2_event_unsubscribe
,
792 * si470x_viddev_template - video device interface
794 const struct video_device si470x_viddev_template
= {
795 .fops
= &si470x_fops
,
797 .release
= video_device_release_empty
,
798 .ioctl_ops
= &si470x_ioctl_ops
,
800 EXPORT_SYMBOL_GPL(si470x_viddev_template
);
802 MODULE_LICENSE("GPL");