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>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * 2008-01-12 Tobias Lorenz <tobias.lorenz@gmx.net>
28 * - First working version
29 * 2008-01-13 Tobias Lorenz <tobias.lorenz@gmx.net>
31 * - Improved error handling, every function now returns errno
32 * - Improved multi user access (start/mute/stop)
33 * - Channel doesn't get lost anymore after start/mute/stop
34 * - RDS support added (polling mode via interrupt EP 1)
35 * - marked default module parameters with *value*
36 * - switched from bit structs to bit masks
37 * - header file cleaned and integrated
38 * 2008-01-14 Tobias Lorenz <tobias.lorenz@gmx.net>
40 * - hex values are now lower case
41 * - commented USB ID for ADS/Tech moved on todo list
42 * - blacklisted si470x in hid-quirks.c
43 * - rds buffer handling functions integrated into *_work, *_read
44 * - rds_command in si470x_poll exchanged against simple retval
45 * - check for firmware version 15
46 * - code order and prototypes still remain the same
47 * - spacing and bottom of band codes remain the same
48 * 2008-01-16 Tobias Lorenz <tobias.lorenz@gmx.net>
50 * - code reordered to avoid function prototypes
51 * - switch/case defaults are now more user-friendly
52 * - unified comment style
53 * - applied all checkpatch.pl v1.12 suggestions
54 * except the warning about the too long lines with bit comments
55 * - renamed FMRADIO to RADIO to cut line length (checkpatch.pl)
56 * 2008-01-22 Tobias Lorenz <tobias.lorenz@gmx.net>
58 * - avoid poss. locking when doing copy_to_user which may sleep
59 * - RDS is automatically activated on read now
60 * - code cleaned of unnecessary rds_commands
61 * - USB Vendor/Product ID for ADS/Tech FM Radio Receiver verified
62 * (thanks to Guillaume RAMOUSSE)
63 * 2008-01-27 Tobias Lorenz <tobias.lorenz@gmx.net>
65 * - number of seek_retries changed to tune_timeout
66 * - fixed problem with incomplete tune operations by own buffers
67 * - optimization of variables and printf types
68 * - improved error logging
69 * 2008-01-31 Tobias Lorenz <tobias.lorenz@gmx.net>
70 * Oliver Neukum <oliver@neukum.org>
72 * - fixed coverity checker warnings in *_usb_driver_disconnect
73 * - probe()/open() race by correct ordering in probe()
74 * - DMA coherency rules by separate allocation of all buffers
75 * - use of endianness macros
76 * - abuse of spinlock, replaced by mutex
77 * - racy handling of timer in disconnect,
78 * replaced by delayed_work
79 * - racy interruptible_sleep_on(),
80 * replaced with wait_event_interruptible()
81 * - handle signals in read()
82 * 2008-02-08 Tobias Lorenz <tobias.lorenz@gmx.net>
83 * Oliver Neukum <oliver@neukum.org>
85 * - usb autosuspend support
87 * 2008-05-07 Tobias Lorenz <tobias.lorenz@gmx.net>
89 * - hardware frequency seek support
91 * - more safety checks, let si470x_get_freq return errno
92 * - vidioc behavior corrected according to v4l2 spec
93 * 2008-10-20 Alexey Klimov <klimov.linux@gmail.com>
94 * - add support for KWorld USB FM Radio FM700
95 * - blacklisted KWorld radio in hid-core.c and hid-ids.h
96 * 2008-12-03 Mark Lord <mlord@pobox.com>
97 * - add support for DealExtreme USB Radio
98 * 2009-01-31 Bob Ross <pigiron@gmx.com>
99 * - correction of stereo detection/setting
100 * - correction of signal strength indicator scaling
101 * 2009-01-31 Rick Bronson <rick@efn.org>
102 * Tobias Lorenz <tobias.lorenz@gmx.net>
103 * - add LED status output
104 * - get HW/SW version from scratchpad
105 * 2009-06-16 Edouard Lafargue <edouard@lafargue.name>
107 * - add support for interrupt mode for RDS endpoint,
108 * instead of polling.
109 * Improves RDS reception significantly
113 /* kernel includes */
114 #include "radio-si470x.h"
118 /**************************************************************************
120 **************************************************************************/
123 /* 0: 200 kHz (USA, Australia) */
124 /* 1: 100 kHz (Europe, Japan) */
126 static unsigned short space
= 2;
127 module_param(space
, ushort
, 0444);
128 MODULE_PARM_DESC(space
, "Spacing: 0=200kHz 1=100kHz *2=50kHz*");
130 /* Bottom of Band (MHz) */
131 /* 0: 87.5 - 108 MHz (USA, Europe)*/
132 /* 1: 76 - 108 MHz (Japan wide band) */
133 /* 2: 76 - 90 MHz (Japan) */
134 static unsigned short band
= 1;
135 module_param(band
, ushort
, 0444);
136 MODULE_PARM_DESC(band
, "Band: 0=87.5..108MHz *1=76..108MHz* 2=76..90MHz");
140 /* 1: 50 us (Europe, Australia, Japan) */
141 static unsigned short de
= 1;
142 module_param(de
, ushort
, 0444);
143 MODULE_PARM_DESC(de
, "De-emphasis: 0=75us *1=50us*");
146 static unsigned int tune_timeout
= 3000;
147 module_param(tune_timeout
, uint
, 0644);
148 MODULE_PARM_DESC(tune_timeout
, "Tune timeout: *3000*");
151 static unsigned int seek_timeout
= 5000;
152 module_param(seek_timeout
, uint
, 0644);
153 MODULE_PARM_DESC(seek_timeout
, "Seek timeout: *5000*");
157 /**************************************************************************
159 **************************************************************************/
162 * si470x_set_chan - set the channel
164 static int si470x_set_chan(struct si470x_device
*radio
, unsigned short chan
)
167 unsigned long timeout
;
171 radio
->registers
[CHANNEL
] &= ~CHANNEL_CHAN
;
172 radio
->registers
[CHANNEL
] |= CHANNEL_TUNE
| chan
;
173 retval
= si470x_set_register(radio
, CHANNEL
);
177 /* wait till tune operation has completed */
178 timeout
= jiffies
+ msecs_to_jiffies(tune_timeout
);
180 retval
= si470x_get_register(radio
, STATUSRSSI
);
183 timed_out
= time_after(jiffies
, timeout
);
184 } while (((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0) &&
186 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0)
187 dev_warn(&radio
->videodev
->dev
, "tune does not complete\n");
189 dev_warn(&radio
->videodev
->dev
,
190 "tune timed out after %u ms\n", tune_timeout
);
194 radio
->registers
[CHANNEL
] &= ~CHANNEL_TUNE
;
195 retval
= si470x_set_register(radio
, CHANNEL
);
203 * si470x_get_freq - get the frequency
205 static int si470x_get_freq(struct si470x_device
*radio
, unsigned int *freq
)
207 unsigned int spacing
, band_bottom
;
212 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_SPACE
) >> 4) {
213 /* 0: 200 kHz (USA, Australia) */
215 spacing
= 0.200 * FREQ_MUL
; break;
216 /* 1: 100 kHz (Europe, Japan) */
218 spacing
= 0.100 * FREQ_MUL
; break;
221 spacing
= 0.050 * FREQ_MUL
; break;
224 /* Bottom of Band (MHz) */
225 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_BAND
) >> 6) {
226 /* 0: 87.5 - 108 MHz (USA, Europe) */
228 band_bottom
= 87.5 * FREQ_MUL
; break;
229 /* 1: 76 - 108 MHz (Japan wide band) */
231 band_bottom
= 76 * FREQ_MUL
; break;
232 /* 2: 76 - 90 MHz (Japan) */
234 band_bottom
= 76 * FREQ_MUL
; break;
238 retval
= si470x_get_register(radio
, READCHAN
);
239 chan
= radio
->registers
[READCHAN
] & READCHAN_READCHAN
;
241 /* Frequency (MHz) = Spacing (kHz) x Channel + Bottom of Band (MHz) */
242 *freq
= chan
* spacing
+ band_bottom
;
249 * si470x_set_freq - set the frequency
251 int si470x_set_freq(struct si470x_device
*radio
, unsigned int freq
)
253 unsigned int spacing
, band_bottom
;
257 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_SPACE
) >> 4) {
258 /* 0: 200 kHz (USA, Australia) */
260 spacing
= 0.200 * FREQ_MUL
; break;
261 /* 1: 100 kHz (Europe, Japan) */
263 spacing
= 0.100 * FREQ_MUL
; break;
266 spacing
= 0.050 * FREQ_MUL
; break;
269 /* Bottom of Band (MHz) */
270 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_BAND
) >> 6) {
271 /* 0: 87.5 - 108 MHz (USA, Europe) */
273 band_bottom
= 87.5 * FREQ_MUL
; break;
274 /* 1: 76 - 108 MHz (Japan wide band) */
276 band_bottom
= 76 * FREQ_MUL
; break;
277 /* 2: 76 - 90 MHz (Japan) */
279 band_bottom
= 76 * FREQ_MUL
; break;
282 /* Chan = [ Freq (Mhz) - Bottom of Band (MHz) ] / Spacing (kHz) */
283 chan
= (freq
- band_bottom
) / spacing
;
285 return si470x_set_chan(radio
, chan
);
290 * si470x_set_seek - set seek
292 static int si470x_set_seek(struct si470x_device
*radio
,
293 unsigned int wrap_around
, unsigned int seek_upward
)
296 unsigned long timeout
;
300 radio
->registers
[POWERCFG
] |= POWERCFG_SEEK
;
301 if (wrap_around
== 1)
302 radio
->registers
[POWERCFG
] &= ~POWERCFG_SKMODE
;
304 radio
->registers
[POWERCFG
] |= POWERCFG_SKMODE
;
305 if (seek_upward
== 1)
306 radio
->registers
[POWERCFG
] |= POWERCFG_SEEKUP
;
308 radio
->registers
[POWERCFG
] &= ~POWERCFG_SEEKUP
;
309 retval
= si470x_set_register(radio
, POWERCFG
);
313 /* wait till seek operation has completed */
314 timeout
= jiffies
+ msecs_to_jiffies(seek_timeout
);
316 retval
= si470x_get_register(radio
, STATUSRSSI
);
319 timed_out
= time_after(jiffies
, timeout
);
320 } while (((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0) &&
322 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_STC
) == 0)
323 dev_warn(&radio
->videodev
->dev
, "seek does not complete\n");
324 if (radio
->registers
[STATUSRSSI
] & STATUSRSSI_SF
)
325 dev_warn(&radio
->videodev
->dev
,
326 "seek failed / band limit reached\n");
328 dev_warn(&radio
->videodev
->dev
,
329 "seek timed out after %u ms\n", seek_timeout
);
333 radio
->registers
[POWERCFG
] &= ~POWERCFG_SEEK
;
334 retval
= si470x_set_register(radio
, POWERCFG
);
337 /* try again, if timed out */
338 if ((retval
== 0) && timed_out
)
346 * si470x_start - switch on radio
348 int si470x_start(struct si470x_device
*radio
)
353 radio
->registers
[POWERCFG
] =
354 POWERCFG_DMUTE
| POWERCFG_ENABLE
| POWERCFG_RDSM
;
355 retval
= si470x_set_register(radio
, POWERCFG
);
360 radio
->registers
[SYSCONFIG1
] =
361 (de
<< 11) & SYSCONFIG1_DE
; /* DE*/
362 retval
= si470x_set_register(radio
, SYSCONFIG1
);
367 radio
->registers
[SYSCONFIG2
] =
368 (0x3f << 8) | /* SEEKTH */
369 ((band
<< 6) & SYSCONFIG2_BAND
) | /* BAND */
370 ((space
<< 4) & SYSCONFIG2_SPACE
) | /* SPACE */
371 15; /* VOLUME (max) */
372 retval
= si470x_set_register(radio
, SYSCONFIG2
);
376 /* reset last channel */
377 retval
= si470x_set_chan(radio
,
378 radio
->registers
[CHANNEL
] & CHANNEL_CHAN
);
386 * si470x_stop - switch off radio
388 int si470x_stop(struct si470x_device
*radio
)
393 radio
->registers
[SYSCONFIG1
] &= ~SYSCONFIG1_RDS
;
394 retval
= si470x_set_register(radio
, SYSCONFIG1
);
399 radio
->registers
[POWERCFG
] &= ~POWERCFG_DMUTE
;
400 /* POWERCFG_ENABLE has to automatically go low */
401 radio
->registers
[POWERCFG
] |= POWERCFG_ENABLE
| POWERCFG_DISABLE
;
402 retval
= si470x_set_register(radio
, POWERCFG
);
410 * si470x_rds_on - switch on rds reception
412 static int si470x_rds_on(struct si470x_device
*radio
)
417 radio
->registers
[SYSCONFIG1
] |= SYSCONFIG1_RDS
;
418 retval
= si470x_set_register(radio
, SYSCONFIG1
);
420 radio
->registers
[SYSCONFIG1
] &= ~SYSCONFIG1_RDS
;
427 /**************************************************************************
428 * File Operations Interface
429 **************************************************************************/
432 * si470x_fops_read - read RDS data
434 static ssize_t
si470x_fops_read(struct file
*file
, char __user
*buf
,
435 size_t count
, loff_t
*ppos
)
437 struct si470x_device
*radio
= video_drvdata(file
);
439 unsigned int block_count
= 0;
441 /* switch on rds reception */
442 mutex_lock(&radio
->lock
);
443 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
) == 0)
444 si470x_rds_on(radio
);
446 /* block if no new data available */
447 while (radio
->wr_index
== radio
->rd_index
) {
448 if (file
->f_flags
& O_NONBLOCK
) {
449 retval
= -EWOULDBLOCK
;
452 if (wait_event_interruptible(radio
->read_queue
,
453 radio
->wr_index
!= radio
->rd_index
) < 0) {
459 /* calculate block count from byte count */
462 /* copy RDS block out of internal buffer and to user buffer */
463 while (block_count
< count
) {
464 if (radio
->rd_index
== radio
->wr_index
)
467 /* always transfer rds complete blocks */
468 if (copy_to_user(buf
, &radio
->buffer
[radio
->rd_index
], 3))
469 /* retval = -EFAULT; */
472 /* increment and wrap read pointer */
473 radio
->rd_index
+= 3;
474 if (radio
->rd_index
>= radio
->buf_size
)
477 /* increment counters */
484 mutex_unlock(&radio
->lock
);
490 * si470x_fops_poll - poll RDS data
492 static unsigned int si470x_fops_poll(struct file
*file
,
493 struct poll_table_struct
*pts
)
495 struct si470x_device
*radio
= video_drvdata(file
);
498 /* switch on rds reception */
500 mutex_lock(&radio
->lock
);
501 if ((radio
->registers
[SYSCONFIG1
] & SYSCONFIG1_RDS
) == 0)
502 si470x_rds_on(radio
);
503 mutex_unlock(&radio
->lock
);
505 poll_wait(file
, &radio
->read_queue
, pts
);
507 if (radio
->rd_index
!= radio
->wr_index
)
508 retval
= POLLIN
| POLLRDNORM
;
515 * si470x_fops - file operations interface
517 static const struct v4l2_file_operations si470x_fops
= {
518 .owner
= THIS_MODULE
,
519 .read
= si470x_fops_read
,
520 .poll
= si470x_fops_poll
,
521 .unlocked_ioctl
= video_ioctl2
,
522 .open
= si470x_fops_open
,
523 .release
= si470x_fops_release
,
528 /**************************************************************************
529 * Video4Linux Interface
530 **************************************************************************/
533 * si470x_vidioc_queryctrl - enumerate control items
535 static int si470x_vidioc_queryctrl(struct file
*file
, void *priv
,
536 struct v4l2_queryctrl
*qc
)
538 struct si470x_device
*radio
= video_drvdata(file
);
539 int retval
= -EINVAL
;
541 /* abort if qc->id is below V4L2_CID_BASE */
542 if (qc
->id
< V4L2_CID_BASE
)
545 /* search video control */
547 case V4L2_CID_AUDIO_VOLUME
:
548 return v4l2_ctrl_query_fill(qc
, 0, 15, 1, 15);
549 case V4L2_CID_AUDIO_MUTE
:
550 return v4l2_ctrl_query_fill(qc
, 0, 1, 1, 1);
553 /* disable unsupported base controls */
554 /* to satisfy kradio and such apps */
555 if ((retval
== -EINVAL
) && (qc
->id
< V4L2_CID_LASTP1
)) {
556 qc
->flags
= V4L2_CTRL_FLAG_DISABLED
;
562 dev_warn(&radio
->videodev
->dev
,
563 "query controls failed with %d\n", retval
);
569 * si470x_vidioc_g_ctrl - get the value of a control
571 static int si470x_vidioc_g_ctrl(struct file
*file
, void *priv
,
572 struct v4l2_control
*ctrl
)
574 struct si470x_device
*radio
= video_drvdata(file
);
577 mutex_lock(&radio
->lock
);
579 retval
= si470x_disconnect_check(radio
);
584 case V4L2_CID_AUDIO_VOLUME
:
585 ctrl
->value
= radio
->registers
[SYSCONFIG2
] &
588 case V4L2_CID_AUDIO_MUTE
:
589 ctrl
->value
= ((radio
->registers
[POWERCFG
] &
590 POWERCFG_DMUTE
) == 0) ? 1 : 0;
598 dev_warn(&radio
->videodev
->dev
,
599 "get control failed with %d\n", retval
);
601 mutex_unlock(&radio
->lock
);
607 * si470x_vidioc_s_ctrl - set the value of a control
609 static int si470x_vidioc_s_ctrl(struct file
*file
, void *priv
,
610 struct v4l2_control
*ctrl
)
612 struct si470x_device
*radio
= video_drvdata(file
);
615 mutex_lock(&radio
->lock
);
617 retval
= si470x_disconnect_check(radio
);
622 case V4L2_CID_AUDIO_VOLUME
:
623 radio
->registers
[SYSCONFIG2
] &= ~SYSCONFIG2_VOLUME
;
624 radio
->registers
[SYSCONFIG2
] |= ctrl
->value
;
625 retval
= si470x_set_register(radio
, SYSCONFIG2
);
627 case V4L2_CID_AUDIO_MUTE
:
628 if (ctrl
->value
== 1)
629 radio
->registers
[POWERCFG
] &= ~POWERCFG_DMUTE
;
631 radio
->registers
[POWERCFG
] |= POWERCFG_DMUTE
;
632 retval
= si470x_set_register(radio
, POWERCFG
);
640 dev_warn(&radio
->videodev
->dev
,
641 "set control failed with %d\n", retval
);
642 mutex_unlock(&radio
->lock
);
648 * si470x_vidioc_g_audio - get audio attributes
650 static int si470x_vidioc_g_audio(struct file
*file
, void *priv
,
651 struct v4l2_audio
*audio
)
653 /* driver constants */
655 strcpy(audio
->name
, "Radio");
656 audio
->capability
= V4L2_AUDCAP_STEREO
;
664 * si470x_vidioc_g_tuner - get tuner attributes
666 static int si470x_vidioc_g_tuner(struct file
*file
, void *priv
,
667 struct v4l2_tuner
*tuner
)
669 struct si470x_device
*radio
= video_drvdata(file
);
672 mutex_lock(&radio
->lock
);
674 retval
= si470x_disconnect_check(radio
);
678 if (tuner
->index
!= 0) {
683 retval
= si470x_get_register(radio
, STATUSRSSI
);
687 /* driver constants */
688 strcpy(tuner
->name
, "FM");
689 tuner
->type
= V4L2_TUNER_RADIO
;
690 tuner
->capability
= V4L2_TUNER_CAP_LOW
| V4L2_TUNER_CAP_STEREO
|
691 V4L2_TUNER_CAP_RDS
| V4L2_TUNER_CAP_RDS_BLOCK_IO
;
694 switch ((radio
->registers
[SYSCONFIG2
] & SYSCONFIG2_BAND
) >> 6) {
695 /* 0: 87.5 - 108 MHz (USA, Europe, default) */
697 tuner
->rangelow
= 87.5 * FREQ_MUL
;
698 tuner
->rangehigh
= 108 * FREQ_MUL
;
700 /* 1: 76 - 108 MHz (Japan wide band) */
702 tuner
->rangelow
= 76 * FREQ_MUL
;
703 tuner
->rangehigh
= 108 * FREQ_MUL
;
705 /* 2: 76 - 90 MHz (Japan) */
707 tuner
->rangelow
= 76 * FREQ_MUL
;
708 tuner
->rangehigh
= 90 * FREQ_MUL
;
712 /* stereo indicator == stereo (instead of mono) */
713 if ((radio
->registers
[STATUSRSSI
] & STATUSRSSI_ST
) == 0)
714 tuner
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
716 tuner
->rxsubchans
= V4L2_TUNER_SUB_MONO
| V4L2_TUNER_SUB_STEREO
;
717 /* If there is a reliable method of detecting an RDS channel,
718 then this code should check for that before setting this
720 tuner
->rxsubchans
|= V4L2_TUNER_SUB_RDS
;
722 /* mono/stereo selector */
723 if ((radio
->registers
[POWERCFG
] & POWERCFG_MONO
) == 0)
724 tuner
->audmode
= V4L2_TUNER_MODE_STEREO
;
726 tuner
->audmode
= V4L2_TUNER_MODE_MONO
;
728 /* min is worst, max is best; signal:0..0xffff; rssi: 0..0xff */
729 /* measured in units of dbµV in 1 db increments (max at ~75 dbµV) */
730 tuner
->signal
= (radio
->registers
[STATUSRSSI
] & STATUSRSSI_RSSI
);
731 /* the ideal factor is 0xffff/75 = 873,8 */
732 tuner
->signal
= (tuner
->signal
* 873) + (8 * tuner
->signal
/ 10);
734 /* automatic frequency control: -1: freq to low, 1 freq to high */
735 /* AFCRL does only indicate that freq. differs, not if too low/high */
736 tuner
->afc
= (radio
->registers
[STATUSRSSI
] & STATUSRSSI_AFCRL
) ? 1 : 0;
740 dev_warn(&radio
->videodev
->dev
,
741 "get tuner failed with %d\n", retval
);
742 mutex_unlock(&radio
->lock
);
748 * si470x_vidioc_s_tuner - set tuner attributes
750 static int si470x_vidioc_s_tuner(struct file
*file
, void *priv
,
751 struct v4l2_tuner
*tuner
)
753 struct si470x_device
*radio
= video_drvdata(file
);
756 mutex_lock(&radio
->lock
);
758 retval
= si470x_disconnect_check(radio
);
762 if (tuner
->index
!= 0)
765 /* mono/stereo selector */
766 switch (tuner
->audmode
) {
767 case V4L2_TUNER_MODE_MONO
:
768 radio
->registers
[POWERCFG
] |= POWERCFG_MONO
; /* force mono */
770 case V4L2_TUNER_MODE_STEREO
:
771 radio
->registers
[POWERCFG
] &= ~POWERCFG_MONO
; /* try stereo */
777 retval
= si470x_set_register(radio
, POWERCFG
);
781 dev_warn(&radio
->videodev
->dev
,
782 "set tuner failed with %d\n", retval
);
783 mutex_unlock(&radio
->lock
);
789 * si470x_vidioc_g_frequency - get tuner or modulator radio frequency
791 static int si470x_vidioc_g_frequency(struct file
*file
, void *priv
,
792 struct v4l2_frequency
*freq
)
794 struct si470x_device
*radio
= video_drvdata(file
);
798 mutex_lock(&radio
->lock
);
799 retval
= si470x_disconnect_check(radio
);
803 if (freq
->tuner
!= 0) {
808 freq
->type
= V4L2_TUNER_RADIO
;
809 retval
= si470x_get_freq(radio
, &freq
->frequency
);
813 dev_warn(&radio
->videodev
->dev
,
814 "get frequency failed with %d\n", retval
);
815 mutex_unlock(&radio
->lock
);
821 * si470x_vidioc_s_frequency - set tuner or modulator radio frequency
823 static int si470x_vidioc_s_frequency(struct file
*file
, void *priv
,
824 struct v4l2_frequency
*freq
)
826 struct si470x_device
*radio
= video_drvdata(file
);
829 mutex_lock(&radio
->lock
);
831 retval
= si470x_disconnect_check(radio
);
835 if (freq
->tuner
!= 0) {
840 retval
= si470x_set_freq(radio
, freq
->frequency
);
844 dev_warn(&radio
->videodev
->dev
,
845 "set frequency failed with %d\n", retval
);
846 mutex_unlock(&radio
->lock
);
852 * si470x_vidioc_s_hw_freq_seek - set hardware frequency seek
854 static int si470x_vidioc_s_hw_freq_seek(struct file
*file
, void *priv
,
855 struct v4l2_hw_freq_seek
*seek
)
857 struct si470x_device
*radio
= video_drvdata(file
);
860 mutex_lock(&radio
->lock
);
862 retval
= si470x_disconnect_check(radio
);
866 if (seek
->tuner
!= 0) {
871 retval
= si470x_set_seek(radio
, seek
->wrap_around
, seek
->seek_upward
);
875 dev_warn(&radio
->videodev
->dev
,
876 "set hardware frequency seek failed with %d\n", retval
);
877 mutex_unlock(&radio
->lock
);
883 * si470x_ioctl_ops - video device ioctl operations
885 static const struct v4l2_ioctl_ops si470x_ioctl_ops
= {
886 .vidioc_querycap
= si470x_vidioc_querycap
,
887 .vidioc_queryctrl
= si470x_vidioc_queryctrl
,
888 .vidioc_g_ctrl
= si470x_vidioc_g_ctrl
,
889 .vidioc_s_ctrl
= si470x_vidioc_s_ctrl
,
890 .vidioc_g_audio
= si470x_vidioc_g_audio
,
891 .vidioc_g_tuner
= si470x_vidioc_g_tuner
,
892 .vidioc_s_tuner
= si470x_vidioc_s_tuner
,
893 .vidioc_g_frequency
= si470x_vidioc_g_frequency
,
894 .vidioc_s_frequency
= si470x_vidioc_s_frequency
,
895 .vidioc_s_hw_freq_seek
= si470x_vidioc_s_hw_freq_seek
,
900 * si470x_viddev_template - video device interface
902 struct video_device si470x_viddev_template
= {
903 .fops
= &si470x_fops
,
905 .release
= video_device_release
,
906 .ioctl_ops
= &si470x_ioctl_ops
,