2 * dvb_frontend.c: DVB frontend tuning interface/thread
5 * Copyright (C) 1999-2001 Ralph Metzler
8 * for convergence integrated media GmbH
10 * Copyright (C) 2004 Andrew de Quincey (tuning thread cleanup)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 /* Enables DVBv3 compatibility bits at the headers */
31 #include <linux/string.h>
32 #include <linux/kernel.h>
33 #include <linux/sched.h>
34 #include <linux/wait.h>
35 #include <linux/slab.h>
36 #include <linux/poll.h>
37 #include <linux/semaphore.h>
38 #include <linux/module.h>
39 #include <linux/list.h>
40 #include <linux/freezer.h>
41 #include <linux/jiffies.h>
42 #include <linux/kthread.h>
43 #include <asm/processor.h>
45 #include "dvb_frontend.h"
47 #include <linux/dvb/version.h>
49 static int dvb_frontend_debug
;
50 static int dvb_shutdown_timeout
;
51 static int dvb_force_auto_inversion
;
52 static int dvb_override_tune_delay
;
53 static int dvb_powerdown_on_sleep
= 1;
54 static int dvb_mfe_wait_time
= 5;
56 module_param_named(frontend_debug
, dvb_frontend_debug
, int, 0644);
57 MODULE_PARM_DESC(frontend_debug
, "Turn on/off frontend core debugging (default:off).");
58 module_param(dvb_shutdown_timeout
, int, 0644);
59 MODULE_PARM_DESC(dvb_shutdown_timeout
, "wait <shutdown_timeout> seconds after close() before suspending hardware");
60 module_param(dvb_force_auto_inversion
, int, 0644);
61 MODULE_PARM_DESC(dvb_force_auto_inversion
, "0: normal (default), 1: INVERSION_AUTO forced always");
62 module_param(dvb_override_tune_delay
, int, 0644);
63 MODULE_PARM_DESC(dvb_override_tune_delay
, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
64 module_param(dvb_powerdown_on_sleep
, int, 0644);
65 MODULE_PARM_DESC(dvb_powerdown_on_sleep
, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
66 module_param(dvb_mfe_wait_time
, int, 0644);
67 MODULE_PARM_DESC(dvb_mfe_wait_time
, "Wait up to <mfe_wait_time> seconds on open() for multi-frontend to become available (default:5 seconds)");
69 #define FESTATE_IDLE 1
70 #define FESTATE_RETUNE 2
71 #define FESTATE_TUNING_FAST 4
72 #define FESTATE_TUNING_SLOW 8
73 #define FESTATE_TUNED 16
74 #define FESTATE_ZIGZAG_FAST 32
75 #define FESTATE_ZIGZAG_SLOW 64
76 #define FESTATE_DISEQC 128
77 #define FESTATE_ERROR 256
78 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
79 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
80 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
81 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
85 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
86 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
87 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
88 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
89 * FESTATE_TUNED. The frontend has successfully locked on.
90 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
91 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
92 * FESTATE_DISEQC. A DISEQC command has just been issued.
93 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
94 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
95 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
96 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
99 #define DVB_FE_NO_EXIT 0
100 #define DVB_FE_NORMAL_EXIT 1
101 #define DVB_FE_DEVICE_REMOVED 2
103 static DEFINE_MUTEX(frontend_mutex
);
105 struct dvb_frontend_private
{
107 /* thread/frontend values */
108 struct dvb_device
*dvbdev
;
109 struct dvb_frontend_parameters parameters_out
;
110 struct dvb_fe_events events
;
111 struct semaphore sem
;
112 struct list_head list_head
;
113 wait_queue_head_t wait_queue
;
114 struct task_struct
*thread
;
115 unsigned long release_jiffies
;
119 unsigned long tune_mode_flags
;
121 unsigned int reinitialise
;
125 /* swzigzag values */
127 unsigned int bending
;
129 unsigned int inversion
;
130 unsigned int auto_step
;
131 unsigned int auto_sub_step
;
132 unsigned int started_auto_step
;
133 unsigned int min_delay
;
134 unsigned int max_drift
;
135 unsigned int step_size
;
137 unsigned int check_wrapped
;
138 enum dvbfe_search algo_status
;
141 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
);
142 static int dtv_get_frontend(struct dvb_frontend
*fe
,
143 struct dvb_frontend_parameters
*p_out
);
144 static int dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
145 struct dvb_frontend_parameters
*p
);
147 static bool has_get_frontend(struct dvb_frontend
*fe
)
149 return fe
->ops
.get_frontend
!= NULL
;
153 * Due to DVBv3 API calls, a delivery system should be mapped into one of
154 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
155 * otherwise, a DVBv3 call will fail.
157 enum dvbv3_emulation_type
{
165 static enum dvbv3_emulation_type
dvbv3_type(u32 delivery_system
)
167 switch (delivery_system
) {
168 case SYS_DVBC_ANNEX_A
:
169 case SYS_DVBC_ANNEX_C
:
184 case SYS_DVBC_ANNEX_B
:
192 * Doesn't know how to emulate those types and/or
193 * there's no frontend driver from this type yet
194 * with some emulation code, so, we're not sure yet how
195 * to handle them, or they're not compatible with a DVBv3 call.
197 return DVBV3_UNKNOWN
;
201 static void dvb_frontend_add_event(struct dvb_frontend
*fe
, fe_status_t status
)
203 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
204 struct dvb_fe_events
*events
= &fepriv
->events
;
205 struct dvb_frontend_event
*e
;
208 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
210 if ((status
& FE_HAS_LOCK
) && has_get_frontend(fe
))
211 dtv_get_frontend(fe
, &fepriv
->parameters_out
);
213 mutex_lock(&events
->mtx
);
215 wp
= (events
->eventw
+ 1) % MAX_EVENT
;
216 if (wp
== events
->eventr
) {
217 events
->overflow
= 1;
218 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
221 e
= &events
->events
[events
->eventw
];
223 e
->parameters
= fepriv
->parameters_out
;
227 mutex_unlock(&events
->mtx
);
229 wake_up_interruptible (&events
->wait_queue
);
232 static int dvb_frontend_get_event(struct dvb_frontend
*fe
,
233 struct dvb_frontend_event
*event
, int flags
)
235 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
236 struct dvb_fe_events
*events
= &fepriv
->events
;
238 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
240 if (events
->overflow
) {
241 events
->overflow
= 0;
245 if (events
->eventw
== events
->eventr
) {
248 if (flags
& O_NONBLOCK
)
253 ret
= wait_event_interruptible (events
->wait_queue
,
254 events
->eventw
!= events
->eventr
);
256 if (down_interruptible (&fepriv
->sem
))
263 mutex_lock(&events
->mtx
);
264 *event
= events
->events
[events
->eventr
];
265 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
266 mutex_unlock(&events
->mtx
);
271 static void dvb_frontend_clear_events(struct dvb_frontend
*fe
)
273 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
274 struct dvb_fe_events
*events
= &fepriv
->events
;
276 mutex_lock(&events
->mtx
);
277 events
->eventr
= events
->eventw
;
278 mutex_unlock(&events
->mtx
);
281 static void dvb_frontend_init(struct dvb_frontend
*fe
)
283 dev_dbg(fe
->dvb
->device
,
284 "%s: initialising adapter %i frontend %i (%s)...\n",
285 __func__
, fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
289 if (fe
->ops
.tuner_ops
.init
) {
290 if (fe
->ops
.i2c_gate_ctrl
)
291 fe
->ops
.i2c_gate_ctrl(fe
, 1);
292 fe
->ops
.tuner_ops
.init(fe
);
293 if (fe
->ops
.i2c_gate_ctrl
)
294 fe
->ops
.i2c_gate_ctrl(fe
, 0);
298 void dvb_frontend_reinitialise(struct dvb_frontend
*fe
)
300 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
302 fepriv
->reinitialise
= 1;
303 dvb_frontend_wakeup(fe
);
305 EXPORT_SYMBOL(dvb_frontend_reinitialise
);
307 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private
*fepriv
, int locked
)
310 struct dvb_frontend
*fe
= fepriv
->dvbdev
->priv
;
312 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
315 (fepriv
->quality
) = (fepriv
->quality
* 220 + 36*256) / 256;
317 (fepriv
->quality
) = (fepriv
->quality
* 220 + 0) / 256;
319 q2
= fepriv
->quality
- 128;
322 fepriv
->delay
= fepriv
->min_delay
+ q2
* HZ
/ (128*128);
326 * Performs automatic twiddling of frontend parameters.
328 * @param fe The frontend concerned.
329 * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
330 * @returns Number of complete iterations that have been performed.
332 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend
*fe
, int check_wrapped
)
337 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
338 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
339 int original_inversion
= c
->inversion
;
340 u32 original_frequency
= c
->frequency
;
342 /* are we using autoinversion? */
343 autoinversion
= ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
344 (c
->inversion
== INVERSION_AUTO
));
346 /* setup parameters correctly */
348 /* calculate the lnb_drift */
349 fepriv
->lnb_drift
= fepriv
->auto_step
* fepriv
->step_size
;
351 /* wrap the auto_step if we've exceeded the maximum drift */
352 if (fepriv
->lnb_drift
> fepriv
->max_drift
) {
353 fepriv
->auto_step
= 0;
354 fepriv
->auto_sub_step
= 0;
355 fepriv
->lnb_drift
= 0;
358 /* perform inversion and +/- zigzag */
359 switch(fepriv
->auto_sub_step
) {
361 /* try with the current inversion and current drift setting */
366 if (!autoinversion
) break;
368 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
373 if (fepriv
->lnb_drift
== 0) break;
375 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
380 if (fepriv
->lnb_drift
== 0) break;
381 if (!autoinversion
) break;
383 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
384 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
390 fepriv
->auto_sub_step
= -1; /* it'll be incremented to 0 in a moment */
394 if (!ready
) fepriv
->auto_sub_step
++;
397 /* if this attempt would hit where we started, indicate a complete
398 * iteration has occurred */
399 if ((fepriv
->auto_step
== fepriv
->started_auto_step
) &&
400 (fepriv
->auto_sub_step
== 0) && check_wrapped
) {
404 dev_dbg(fe
->dvb
->device
, "%s: drift:%i inversion:%i auto_step:%i " \
405 "auto_sub_step:%i started_auto_step:%i\n",
406 __func__
, fepriv
->lnb_drift
, fepriv
->inversion
,
407 fepriv
->auto_step
, fepriv
->auto_sub_step
,
408 fepriv
->started_auto_step
);
410 /* set the frontend itself */
411 c
->frequency
+= fepriv
->lnb_drift
;
413 c
->inversion
= fepriv
->inversion
;
415 if (fe
->ops
.set_frontend
)
416 fe_set_err
= fe
->ops
.set_frontend(fe
);
418 if (fe_set_err
< 0) {
419 fepriv
->state
= FESTATE_ERROR
;
423 c
->frequency
= original_frequency
;
424 c
->inversion
= original_inversion
;
426 fepriv
->auto_sub_step
++;
430 static void dvb_frontend_swzigzag(struct dvb_frontend
*fe
)
434 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
435 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
437 /* if we've got no parameters, just keep idling */
438 if (fepriv
->state
& FESTATE_IDLE
) {
439 fepriv
->delay
= 3*HZ
;
444 /* in SCAN mode, we just set the frontend when asked and leave it alone */
445 if (fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
) {
446 if (fepriv
->state
& FESTATE_RETUNE
) {
448 if (fe
->ops
.set_frontend
)
449 retval
= fe
->ops
.set_frontend(fe
);
452 fepriv
->state
= FESTATE_ERROR
;
454 fepriv
->state
= FESTATE_TUNED
;
456 fepriv
->delay
= 3*HZ
;
461 /* get the frontend status */
462 if (fepriv
->state
& FESTATE_RETUNE
) {
465 if (fe
->ops
.read_status
)
466 fe
->ops
.read_status(fe
, &s
);
467 if (s
!= fepriv
->status
) {
468 dvb_frontend_add_event(fe
, s
);
473 /* if we're not tuned, and we have a lock, move to the TUNED state */
474 if ((fepriv
->state
& FESTATE_WAITFORLOCK
) && (s
& FE_HAS_LOCK
)) {
475 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
476 fepriv
->state
= FESTATE_TUNED
;
478 /* if we're tuned, then we have determined the correct inversion */
479 if ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
480 (c
->inversion
== INVERSION_AUTO
)) {
481 c
->inversion
= fepriv
->inversion
;
486 /* if we are tuned already, check we're still locked */
487 if (fepriv
->state
& FESTATE_TUNED
) {
488 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
490 /* we're tuned, and the lock is still good... */
491 if (s
& FE_HAS_LOCK
) {
493 } else { /* if we _WERE_ tuned, but now don't have a lock */
494 fepriv
->state
= FESTATE_ZIGZAG_FAST
;
495 fepriv
->started_auto_step
= fepriv
->auto_step
;
496 fepriv
->check_wrapped
= 0;
500 /* don't actually do anything if we're in the LOSTLOCK state,
501 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
502 if ((fepriv
->state
& FESTATE_LOSTLOCK
) &&
503 (fe
->ops
.info
.caps
& FE_CAN_RECOVER
) && (fepriv
->max_drift
== 0)) {
504 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
508 /* don't do anything if we're in the DISEQC state, since this
509 * might be someone with a motorized dish controlled by DISEQC.
510 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
511 if (fepriv
->state
& FESTATE_DISEQC
) {
512 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
516 /* if we're in the RETUNE state, set everything up for a brand
517 * new scan, keeping the current inversion setting, as the next
518 * tune is _very_ likely to require the same */
519 if (fepriv
->state
& FESTATE_RETUNE
) {
520 fepriv
->lnb_drift
= 0;
521 fepriv
->auto_step
= 0;
522 fepriv
->auto_sub_step
= 0;
523 fepriv
->started_auto_step
= 0;
524 fepriv
->check_wrapped
= 0;
528 if ((fepriv
->state
& FESTATE_SEARCHING_FAST
) || (fepriv
->state
& FESTATE_RETUNE
)) {
529 fepriv
->delay
= fepriv
->min_delay
;
532 retval
= dvb_frontend_swzigzag_autotune(fe
,
533 fepriv
->check_wrapped
);
537 /* OK, if we've run out of trials at the fast speed.
538 * Drop back to slow for the _next_ attempt */
539 fepriv
->state
= FESTATE_SEARCHING_SLOW
;
540 fepriv
->started_auto_step
= fepriv
->auto_step
;
543 fepriv
->check_wrapped
= 1;
545 /* if we've just retuned, enter the ZIGZAG_FAST state.
546 * This ensures we cannot return from an
547 * FE_SET_FRONTEND ioctl before the first frontend tune
549 if (fepriv
->state
& FESTATE_RETUNE
) {
550 fepriv
->state
= FESTATE_TUNING_FAST
;
555 if (fepriv
->state
& FESTATE_SEARCHING_SLOW
) {
556 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
558 /* Note: don't bother checking for wrapping; we stay in this
559 * state until we get a lock */
560 dvb_frontend_swzigzag_autotune(fe
, 0);
564 static int dvb_frontend_is_exiting(struct dvb_frontend
*fe
)
566 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
568 if (fepriv
->exit
!= DVB_FE_NO_EXIT
)
571 if (fepriv
->dvbdev
->writers
== 1)
572 if (time_after_eq(jiffies
, fepriv
->release_jiffies
+
573 dvb_shutdown_timeout
* HZ
))
579 static int dvb_frontend_should_wakeup(struct dvb_frontend
*fe
)
581 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
583 if (fepriv
->wakeup
) {
587 return dvb_frontend_is_exiting(fe
);
590 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
)
592 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
595 wake_up_interruptible(&fepriv
->wait_queue
);
598 static int dvb_frontend_thread(void *data
)
600 struct dvb_frontend
*fe
= data
;
601 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
603 enum dvbfe_algo algo
;
605 bool re_tune
= false;
606 bool semheld
= false;
608 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
610 fepriv
->check_wrapped
= 0;
612 fepriv
->delay
= 3*HZ
;
615 fepriv
->reinitialise
= 0;
617 dvb_frontend_init(fe
);
621 up(&fepriv
->sem
); /* is locked when we enter the thread... */
623 wait_event_interruptible_timeout(fepriv
->wait_queue
,
624 dvb_frontend_should_wakeup(fe
) || kthread_should_stop()
625 || freezing(current
),
628 if (kthread_should_stop() || dvb_frontend_is_exiting(fe
)) {
629 /* got signal or quitting */
630 if (!down_interruptible(&fepriv
->sem
))
632 fepriv
->exit
= DVB_FE_NORMAL_EXIT
;
639 if (down_interruptible(&fepriv
->sem
))
642 if (fepriv
->reinitialise
) {
643 dvb_frontend_init(fe
);
644 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
645 fe
->ops
.set_tone(fe
, fepriv
->tone
);
646 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
647 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
648 fepriv
->reinitialise
= 0;
651 /* do an iteration of the tuning loop */
652 if (fe
->ops
.get_frontend_algo
) {
653 algo
= fe
->ops
.get_frontend_algo(fe
);
656 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__
);
658 if (fepriv
->state
& FESTATE_RETUNE
) {
659 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTATE_RETUNE\n", __func__
);
661 fepriv
->state
= FESTATE_TUNED
;
667 fe
->ops
.tune(fe
, re_tune
, fepriv
->tune_mode_flags
, &fepriv
->delay
, &s
);
669 if (s
!= fepriv
->status
&& !(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
)) {
670 dev_dbg(fe
->dvb
->device
, "%s: state changed, adding current state\n", __func__
);
671 dvb_frontend_add_event(fe
, s
);
676 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__
);
677 dvb_frontend_swzigzag(fe
);
679 case DVBFE_ALGO_CUSTOM
:
680 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__
, fepriv
->state
);
681 if (fepriv
->state
& FESTATE_RETUNE
) {
682 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTAT_RETUNE\n", __func__
);
683 fepriv
->state
= FESTATE_TUNED
;
685 /* Case where we are going to search for a carrier
686 * User asked us to retune again for some reason, possibly
687 * requesting a search with a new set of parameters
689 if (fepriv
->algo_status
& DVBFE_ALGO_SEARCH_AGAIN
) {
690 if (fe
->ops
.search
) {
691 fepriv
->algo_status
= fe
->ops
.search(fe
);
692 /* We did do a search as was requested, the flags are
693 * now unset as well and has the flags wrt to search.
696 fepriv
->algo_status
&= ~DVBFE_ALGO_SEARCH_AGAIN
;
699 /* Track the carrier if the search was successful */
700 if (fepriv
->algo_status
!= DVBFE_ALGO_SEARCH_SUCCESS
) {
701 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
702 fepriv
->delay
= HZ
/ 2;
704 dtv_property_legacy_params_sync(fe
, &fepriv
->parameters_out
);
705 fe
->ops
.read_status(fe
, &s
);
706 if (s
!= fepriv
->status
) {
707 dvb_frontend_add_event(fe
, s
); /* update event list */
709 if (!(s
& FE_HAS_LOCK
)) {
710 fepriv
->delay
= HZ
/ 10;
711 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
713 fepriv
->delay
= 60 * HZ
;
718 dev_dbg(fe
->dvb
->device
, "%s: UNDEFINED ALGO !\n", __func__
);
722 dvb_frontend_swzigzag(fe
);
726 if (dvb_powerdown_on_sleep
) {
727 if (fe
->ops
.set_voltage
)
728 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_OFF
);
729 if (fe
->ops
.tuner_ops
.sleep
) {
730 if (fe
->ops
.i2c_gate_ctrl
)
731 fe
->ops
.i2c_gate_ctrl(fe
, 1);
732 fe
->ops
.tuner_ops
.sleep(fe
);
733 if (fe
->ops
.i2c_gate_ctrl
)
734 fe
->ops
.i2c_gate_ctrl(fe
, 0);
740 fepriv
->thread
= NULL
;
741 if (kthread_should_stop())
742 fepriv
->exit
= DVB_FE_DEVICE_REMOVED
;
744 fepriv
->exit
= DVB_FE_NO_EXIT
;
749 dvb_frontend_wakeup(fe
);
753 static void dvb_frontend_stop(struct dvb_frontend
*fe
)
755 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
757 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
759 fepriv
->exit
= DVB_FE_NORMAL_EXIT
;
765 kthread_stop(fepriv
->thread
);
767 sema_init(&fepriv
->sem
, 1);
768 fepriv
->state
= FESTATE_IDLE
;
770 /* paranoia check in case a signal arrived */
772 dev_warn(fe
->dvb
->device
,
773 "dvb_frontend_stop: warning: thread %p won't exit\n",
777 s32
timeval_usec_diff(struct timeval lasttime
, struct timeval curtime
)
779 return ((curtime
.tv_usec
< lasttime
.tv_usec
) ?
780 1000000 - lasttime
.tv_usec
+ curtime
.tv_usec
:
781 curtime
.tv_usec
- lasttime
.tv_usec
);
783 EXPORT_SYMBOL(timeval_usec_diff
);
785 static inline void timeval_usec_add(struct timeval
*curtime
, u32 add_usec
)
787 curtime
->tv_usec
+= add_usec
;
788 if (curtime
->tv_usec
>= 1000000) {
789 curtime
->tv_usec
-= 1000000;
795 * Sleep until gettimeofday() > waketime + add_usec
796 * This needs to be as precise as possible, but as the delay is
797 * usually between 2ms and 32ms, it is done using a scheduled msleep
798 * followed by usleep (normally a busy-wait loop) for the remainder
800 void dvb_frontend_sleep_until(struct timeval
*waketime
, u32 add_usec
)
802 struct timeval lasttime
;
805 timeval_usec_add(waketime
, add_usec
);
807 do_gettimeofday(&lasttime
);
808 delta
= timeval_usec_diff(lasttime
, *waketime
);
810 msleep((delta
- 1500) / 1000);
811 do_gettimeofday(&lasttime
);
812 newdelta
= timeval_usec_diff(lasttime
, *waketime
);
813 delta
= (newdelta
> delta
) ? 0 : newdelta
;
818 EXPORT_SYMBOL(dvb_frontend_sleep_until
);
820 static int dvb_frontend_start(struct dvb_frontend
*fe
)
823 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
824 struct task_struct
*fe_thread
;
826 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
828 if (fepriv
->thread
) {
829 if (fepriv
->exit
== DVB_FE_NO_EXIT
)
832 dvb_frontend_stop (fe
);
835 if (signal_pending(current
))
837 if (down_interruptible (&fepriv
->sem
))
840 fepriv
->state
= FESTATE_IDLE
;
841 fepriv
->exit
= DVB_FE_NO_EXIT
;
842 fepriv
->thread
= NULL
;
845 fe_thread
= kthread_run(dvb_frontend_thread
, fe
,
846 "kdvb-ad-%i-fe-%i", fe
->dvb
->num
,fe
->id
);
847 if (IS_ERR(fe_thread
)) {
848 ret
= PTR_ERR(fe_thread
);
849 dev_warn(fe
->dvb
->device
,
850 "dvb_frontend_start: failed to start kthread (%d)\n",
855 fepriv
->thread
= fe_thread
;
859 static void dvb_frontend_get_frequency_limits(struct dvb_frontend
*fe
,
860 u32
*freq_min
, u32
*freq_max
)
862 *freq_min
= max(fe
->ops
.info
.frequency_min
, fe
->ops
.tuner_ops
.info
.frequency_min
);
864 if (fe
->ops
.info
.frequency_max
== 0)
865 *freq_max
= fe
->ops
.tuner_ops
.info
.frequency_max
;
866 else if (fe
->ops
.tuner_ops
.info
.frequency_max
== 0)
867 *freq_max
= fe
->ops
.info
.frequency_max
;
869 *freq_max
= min(fe
->ops
.info
.frequency_max
, fe
->ops
.tuner_ops
.info
.frequency_max
);
871 if (*freq_min
== 0 || *freq_max
== 0)
872 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
873 fe
->dvb
->num
, fe
->id
);
876 static int dvb_frontend_check_parameters(struct dvb_frontend
*fe
)
878 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
882 /* range check: frequency */
883 dvb_frontend_get_frequency_limits(fe
, &freq_min
, &freq_max
);
884 if ((freq_min
&& c
->frequency
< freq_min
) ||
885 (freq_max
&& c
->frequency
> freq_max
)) {
886 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
887 fe
->dvb
->num
, fe
->id
, c
->frequency
,
892 /* range check: symbol rate */
893 switch (c
->delivery_system
) {
897 case SYS_DVBC_ANNEX_A
:
898 case SYS_DVBC_ANNEX_C
:
899 if ((fe
->ops
.info
.symbol_rate_min
&&
900 c
->symbol_rate
< fe
->ops
.info
.symbol_rate_min
) ||
901 (fe
->ops
.info
.symbol_rate_max
&&
902 c
->symbol_rate
> fe
->ops
.info
.symbol_rate_max
)) {
903 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
904 fe
->dvb
->num
, fe
->id
, c
->symbol_rate
,
905 fe
->ops
.info
.symbol_rate_min
,
906 fe
->ops
.info
.symbol_rate_max
);
916 static int dvb_frontend_clear_cache(struct dvb_frontend
*fe
)
918 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
922 delsys
= c
->delivery_system
;
923 memset(c
, 0, offsetof(struct dtv_frontend_properties
, strength
));
924 c
->delivery_system
= delsys
;
926 c
->state
= DTV_CLEAR
;
928 dev_dbg(fe
->dvb
->device
, "%s: Clearing cache for delivery system %d\n",
929 __func__
, c
->delivery_system
);
931 c
->transmission_mode
= TRANSMISSION_MODE_AUTO
;
932 c
->bandwidth_hz
= 0; /* AUTO */
933 c
->guard_interval
= GUARD_INTERVAL_AUTO
;
934 c
->hierarchy
= HIERARCHY_AUTO
;
936 c
->code_rate_HP
= FEC_AUTO
;
937 c
->code_rate_LP
= FEC_AUTO
;
938 c
->fec_inner
= FEC_AUTO
;
939 c
->rolloff
= ROLLOFF_AUTO
;
940 c
->voltage
= SEC_VOLTAGE_OFF
;
941 c
->sectone
= SEC_TONE_OFF
;
942 c
->pilot
= PILOT_AUTO
;
944 c
->isdbt_partial_reception
= 0;
945 c
->isdbt_sb_mode
= 0;
946 c
->isdbt_sb_subchannel
= 0;
947 c
->isdbt_sb_segment_idx
= 0;
948 c
->isdbt_sb_segment_count
= 0;
949 c
->isdbt_layer_enabled
= 0;
950 for (i
= 0; i
< 3; i
++) {
951 c
->layer
[i
].fec
= FEC_AUTO
;
952 c
->layer
[i
].modulation
= QAM_AUTO
;
953 c
->layer
[i
].interleaving
= 0;
954 c
->layer
[i
].segment_count
= 0;
957 c
->stream_id
= NO_STREAM_ID_FILTER
;
959 switch (c
->delivery_system
) {
963 c
->modulation
= QPSK
; /* implied for DVB-S in legacy API */
964 c
->rolloff
= ROLLOFF_35
;/* implied for DVB-S */
967 c
->modulation
= VSB_8
;
970 c
->modulation
= QAM_AUTO
;
979 #define _DTV_CMD(n, s, b) \
987 static struct dtv_cmds_h dtv_cmds
[DTV_MAX_COMMAND
+ 1] = {
988 _DTV_CMD(DTV_TUNE
, 1, 0),
989 _DTV_CMD(DTV_CLEAR
, 1, 0),
992 _DTV_CMD(DTV_FREQUENCY
, 1, 0),
993 _DTV_CMD(DTV_BANDWIDTH_HZ
, 1, 0),
994 _DTV_CMD(DTV_MODULATION
, 1, 0),
995 _DTV_CMD(DTV_INVERSION
, 1, 0),
996 _DTV_CMD(DTV_DISEQC_MASTER
, 1, 1),
997 _DTV_CMD(DTV_SYMBOL_RATE
, 1, 0),
998 _DTV_CMD(DTV_INNER_FEC
, 1, 0),
999 _DTV_CMD(DTV_VOLTAGE
, 1, 0),
1000 _DTV_CMD(DTV_TONE
, 1, 0),
1001 _DTV_CMD(DTV_PILOT
, 1, 0),
1002 _DTV_CMD(DTV_ROLLOFF
, 1, 0),
1003 _DTV_CMD(DTV_DELIVERY_SYSTEM
, 1, 0),
1004 _DTV_CMD(DTV_HIERARCHY
, 1, 0),
1005 _DTV_CMD(DTV_CODE_RATE_HP
, 1, 0),
1006 _DTV_CMD(DTV_CODE_RATE_LP
, 1, 0),
1007 _DTV_CMD(DTV_GUARD_INTERVAL
, 1, 0),
1008 _DTV_CMD(DTV_TRANSMISSION_MODE
, 1, 0),
1009 _DTV_CMD(DTV_INTERLEAVING
, 1, 0),
1011 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION
, 1, 0),
1012 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING
, 1, 0),
1013 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID
, 1, 0),
1014 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX
, 1, 0),
1015 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT
, 1, 0),
1016 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED
, 1, 0),
1017 _DTV_CMD(DTV_ISDBT_LAYERA_FEC
, 1, 0),
1018 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION
, 1, 0),
1019 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT
, 1, 0),
1020 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING
, 1, 0),
1021 _DTV_CMD(DTV_ISDBT_LAYERB_FEC
, 1, 0),
1022 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION
, 1, 0),
1023 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT
, 1, 0),
1024 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING
, 1, 0),
1025 _DTV_CMD(DTV_ISDBT_LAYERC_FEC
, 1, 0),
1026 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION
, 1, 0),
1027 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT
, 1, 0),
1028 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING
, 1, 0),
1030 _DTV_CMD(DTV_STREAM_ID
, 1, 0),
1031 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY
, 1, 0),
1032 _DTV_CMD(DTV_LNA
, 1, 0),
1035 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY
, 0, 1),
1036 _DTV_CMD(DTV_API_VERSION
, 0, 0),
1038 _DTV_CMD(DTV_ENUM_DELSYS
, 0, 0),
1040 _DTV_CMD(DTV_ATSCMH_PARADE_ID
, 1, 0),
1041 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE
, 1, 0),
1043 _DTV_CMD(DTV_ATSCMH_FIC_VER
, 0, 0),
1044 _DTV_CMD(DTV_ATSCMH_NOG
, 0, 0),
1045 _DTV_CMD(DTV_ATSCMH_TNOG
, 0, 0),
1046 _DTV_CMD(DTV_ATSCMH_SGN
, 0, 0),
1047 _DTV_CMD(DTV_ATSCMH_PRC
, 0, 0),
1048 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE
, 0, 0),
1049 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI
, 0, 0),
1050 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC
, 0, 0),
1051 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE
, 0, 0),
1052 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A
, 0, 0),
1053 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B
, 0, 0),
1054 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C
, 0, 0),
1055 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D
, 0, 0),
1057 /* Statistics API */
1058 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH
, 0, 0),
1059 _DTV_CMD(DTV_STAT_CNR
, 0, 0),
1060 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT
, 0, 0),
1061 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT
, 0, 0),
1062 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT
, 0, 0),
1063 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT
, 0, 0),
1064 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT
, 0, 0),
1065 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT
, 0, 0),
1068 static void dtv_property_dump(struct dvb_frontend
*fe
, struct dtv_property
*tvp
)
1072 if (tvp
->cmd
<= 0 || tvp
->cmd
> DTV_MAX_COMMAND
) {
1073 dev_warn(fe
->dvb
->device
, "%s: tvp.cmd = 0x%08x undefined\n",
1074 __func__
, tvp
->cmd
);
1078 dev_dbg(fe
->dvb
->device
, "%s: tvp.cmd = 0x%08x (%s)\n", __func__
,
1079 tvp
->cmd
, dtv_cmds
[tvp
->cmd
].name
);
1081 if (dtv_cmds
[tvp
->cmd
].buffer
) {
1082 dev_dbg(fe
->dvb
->device
, "%s: tvp.u.buffer.len = 0x%02x\n",
1083 __func__
, tvp
->u
.buffer
.len
);
1085 for(i
= 0; i
< tvp
->u
.buffer
.len
; i
++)
1086 dev_dbg(fe
->dvb
->device
,
1087 "%s: tvp.u.buffer.data[0x%02x] = 0x%02x\n",
1088 __func__
, i
, tvp
->u
.buffer
.data
[i
]);
1090 dev_dbg(fe
->dvb
->device
, "%s: tvp.u.data = 0x%08x\n", __func__
,
1095 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1096 * drivers can use a single set_frontend tuning function, regardless of whether
1097 * it's being used for the legacy or new API, reducing code and complexity.
1099 static int dtv_property_cache_sync(struct dvb_frontend
*fe
,
1100 struct dtv_frontend_properties
*c
,
1101 const struct dvb_frontend_parameters
*p
)
1103 c
->frequency
= p
->frequency
;
1104 c
->inversion
= p
->inversion
;
1106 switch (dvbv3_type(c
->delivery_system
)) {
1108 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1109 c
->symbol_rate
= p
->u
.qpsk
.symbol_rate
;
1110 c
->fec_inner
= p
->u
.qpsk
.fec_inner
;
1113 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1114 c
->symbol_rate
= p
->u
.qam
.symbol_rate
;
1115 c
->fec_inner
= p
->u
.qam
.fec_inner
;
1116 c
->modulation
= p
->u
.qam
.modulation
;
1119 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1121 switch (p
->u
.ofdm
.bandwidth
) {
1122 case BANDWIDTH_10_MHZ
:
1123 c
->bandwidth_hz
= 10000000;
1125 case BANDWIDTH_8_MHZ
:
1126 c
->bandwidth_hz
= 8000000;
1128 case BANDWIDTH_7_MHZ
:
1129 c
->bandwidth_hz
= 7000000;
1131 case BANDWIDTH_6_MHZ
:
1132 c
->bandwidth_hz
= 6000000;
1134 case BANDWIDTH_5_MHZ
:
1135 c
->bandwidth_hz
= 5000000;
1137 case BANDWIDTH_1_712_MHZ
:
1138 c
->bandwidth_hz
= 1712000;
1140 case BANDWIDTH_AUTO
:
1141 c
->bandwidth_hz
= 0;
1144 c
->code_rate_HP
= p
->u
.ofdm
.code_rate_HP
;
1145 c
->code_rate_LP
= p
->u
.ofdm
.code_rate_LP
;
1146 c
->modulation
= p
->u
.ofdm
.constellation
;
1147 c
->transmission_mode
= p
->u
.ofdm
.transmission_mode
;
1148 c
->guard_interval
= p
->u
.ofdm
.guard_interval
;
1149 c
->hierarchy
= p
->u
.ofdm
.hierarchy_information
;
1152 dev_dbg(fe
->dvb
->device
, "%s: Preparing ATSC req\n", __func__
);
1153 c
->modulation
= p
->u
.vsb
.modulation
;
1154 if (c
->delivery_system
== SYS_ATSCMH
)
1156 if ((c
->modulation
== VSB_8
) || (c
->modulation
== VSB_16
))
1157 c
->delivery_system
= SYS_ATSC
;
1159 c
->delivery_system
= SYS_DVBC_ANNEX_B
;
1162 dev_err(fe
->dvb
->device
,
1163 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1164 __func__
, c
->delivery_system
);
1171 /* Ensure the cached values are set correctly in the frontend
1172 * legacy tuning structures, for the advanced tuning API.
1174 static int dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
1175 struct dvb_frontend_parameters
*p
)
1177 const struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1179 p
->frequency
= c
->frequency
;
1180 p
->inversion
= c
->inversion
;
1182 switch (dvbv3_type(c
->delivery_system
)) {
1184 dev_err(fe
->dvb
->device
,
1185 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1186 __func__
, c
->delivery_system
);
1189 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1190 p
->u
.qpsk
.symbol_rate
= c
->symbol_rate
;
1191 p
->u
.qpsk
.fec_inner
= c
->fec_inner
;
1194 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1195 p
->u
.qam
.symbol_rate
= c
->symbol_rate
;
1196 p
->u
.qam
.fec_inner
= c
->fec_inner
;
1197 p
->u
.qam
.modulation
= c
->modulation
;
1200 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1201 switch (c
->bandwidth_hz
) {
1203 p
->u
.ofdm
.bandwidth
= BANDWIDTH_10_MHZ
;
1206 p
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
1209 p
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
1212 p
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
1215 p
->u
.ofdm
.bandwidth
= BANDWIDTH_5_MHZ
;
1218 p
->u
.ofdm
.bandwidth
= BANDWIDTH_1_712_MHZ
;
1222 p
->u
.ofdm
.bandwidth
= BANDWIDTH_AUTO
;
1224 p
->u
.ofdm
.code_rate_HP
= c
->code_rate_HP
;
1225 p
->u
.ofdm
.code_rate_LP
= c
->code_rate_LP
;
1226 p
->u
.ofdm
.constellation
= c
->modulation
;
1227 p
->u
.ofdm
.transmission_mode
= c
->transmission_mode
;
1228 p
->u
.ofdm
.guard_interval
= c
->guard_interval
;
1229 p
->u
.ofdm
.hierarchy_information
= c
->hierarchy
;
1232 dev_dbg(fe
->dvb
->device
, "%s: Preparing VSB req\n", __func__
);
1233 p
->u
.vsb
.modulation
= c
->modulation
;
1240 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1241 * @fe: struct dvb_frontend pointer
1242 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1243 * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1245 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1246 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1247 * If p_out is not null, it will update the DVBv3 params pointed by it.
1249 static int dtv_get_frontend(struct dvb_frontend
*fe
,
1250 struct dvb_frontend_parameters
*p_out
)
1254 if (fe
->ops
.get_frontend
) {
1255 r
= fe
->ops
.get_frontend(fe
);
1256 if (unlikely(r
< 0))
1259 dtv_property_legacy_params_sync(fe
, p_out
);
1263 /* As everything is in cache, get_frontend fops are always supported */
1267 static int dvb_frontend_ioctl_legacy(struct file
*file
,
1268 unsigned int cmd
, void *parg
);
1269 static int dvb_frontend_ioctl_properties(struct file
*file
,
1270 unsigned int cmd
, void *parg
);
1272 static int dtv_property_process_get(struct dvb_frontend
*fe
,
1273 const struct dtv_frontend_properties
*c
,
1274 struct dtv_property
*tvp
,
1280 case DTV_ENUM_DELSYS
:
1282 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1283 tvp
->u
.buffer
.data
[ncaps
] = fe
->ops
.delsys
[ncaps
];
1286 tvp
->u
.buffer
.len
= ncaps
;
1289 tvp
->u
.data
= c
->frequency
;
1291 case DTV_MODULATION
:
1292 tvp
->u
.data
= c
->modulation
;
1294 case DTV_BANDWIDTH_HZ
:
1295 tvp
->u
.data
= c
->bandwidth_hz
;
1298 tvp
->u
.data
= c
->inversion
;
1300 case DTV_SYMBOL_RATE
:
1301 tvp
->u
.data
= c
->symbol_rate
;
1304 tvp
->u
.data
= c
->fec_inner
;
1307 tvp
->u
.data
= c
->pilot
;
1310 tvp
->u
.data
= c
->rolloff
;
1312 case DTV_DELIVERY_SYSTEM
:
1313 tvp
->u
.data
= c
->delivery_system
;
1316 tvp
->u
.data
= c
->voltage
;
1319 tvp
->u
.data
= c
->sectone
;
1321 case DTV_API_VERSION
:
1322 tvp
->u
.data
= (DVB_API_VERSION
<< 8) | DVB_API_VERSION_MINOR
;
1324 case DTV_CODE_RATE_HP
:
1325 tvp
->u
.data
= c
->code_rate_HP
;
1327 case DTV_CODE_RATE_LP
:
1328 tvp
->u
.data
= c
->code_rate_LP
;
1330 case DTV_GUARD_INTERVAL
:
1331 tvp
->u
.data
= c
->guard_interval
;
1333 case DTV_TRANSMISSION_MODE
:
1334 tvp
->u
.data
= c
->transmission_mode
;
1337 tvp
->u
.data
= c
->hierarchy
;
1339 case DTV_INTERLEAVING
:
1340 tvp
->u
.data
= c
->interleaving
;
1343 /* ISDB-T Support here */
1344 case DTV_ISDBT_PARTIAL_RECEPTION
:
1345 tvp
->u
.data
= c
->isdbt_partial_reception
;
1347 case DTV_ISDBT_SOUND_BROADCASTING
:
1348 tvp
->u
.data
= c
->isdbt_sb_mode
;
1350 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1351 tvp
->u
.data
= c
->isdbt_sb_subchannel
;
1353 case DTV_ISDBT_SB_SEGMENT_IDX
:
1354 tvp
->u
.data
= c
->isdbt_sb_segment_idx
;
1356 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1357 tvp
->u
.data
= c
->isdbt_sb_segment_count
;
1359 case DTV_ISDBT_LAYER_ENABLED
:
1360 tvp
->u
.data
= c
->isdbt_layer_enabled
;
1362 case DTV_ISDBT_LAYERA_FEC
:
1363 tvp
->u
.data
= c
->layer
[0].fec
;
1365 case DTV_ISDBT_LAYERA_MODULATION
:
1366 tvp
->u
.data
= c
->layer
[0].modulation
;
1368 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1369 tvp
->u
.data
= c
->layer
[0].segment_count
;
1371 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1372 tvp
->u
.data
= c
->layer
[0].interleaving
;
1374 case DTV_ISDBT_LAYERB_FEC
:
1375 tvp
->u
.data
= c
->layer
[1].fec
;
1377 case DTV_ISDBT_LAYERB_MODULATION
:
1378 tvp
->u
.data
= c
->layer
[1].modulation
;
1380 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1381 tvp
->u
.data
= c
->layer
[1].segment_count
;
1383 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1384 tvp
->u
.data
= c
->layer
[1].interleaving
;
1386 case DTV_ISDBT_LAYERC_FEC
:
1387 tvp
->u
.data
= c
->layer
[2].fec
;
1389 case DTV_ISDBT_LAYERC_MODULATION
:
1390 tvp
->u
.data
= c
->layer
[2].modulation
;
1392 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1393 tvp
->u
.data
= c
->layer
[2].segment_count
;
1395 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1396 tvp
->u
.data
= c
->layer
[2].interleaving
;
1399 /* Multistream support */
1401 case DTV_DVBT2_PLP_ID_LEGACY
:
1402 tvp
->u
.data
= c
->stream_id
;
1406 case DTV_ATSCMH_FIC_VER
:
1407 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_fic_ver
;
1409 case DTV_ATSCMH_PARADE_ID
:
1410 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_parade_id
;
1412 case DTV_ATSCMH_NOG
:
1413 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_nog
;
1415 case DTV_ATSCMH_TNOG
:
1416 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_tnog
;
1418 case DTV_ATSCMH_SGN
:
1419 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sgn
;
1421 case DTV_ATSCMH_PRC
:
1422 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_prc
;
1424 case DTV_ATSCMH_RS_FRAME_MODE
:
1425 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_mode
;
1427 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1428 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
;
1430 case DTV_ATSCMH_RS_CODE_MODE_PRI
:
1431 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_pri
;
1433 case DTV_ATSCMH_RS_CODE_MODE_SEC
:
1434 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_sec
;
1436 case DTV_ATSCMH_SCCC_BLOCK_MODE
:
1437 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_block_mode
;
1439 case DTV_ATSCMH_SCCC_CODE_MODE_A
:
1440 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_a
;
1442 case DTV_ATSCMH_SCCC_CODE_MODE_B
:
1443 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_b
;
1445 case DTV_ATSCMH_SCCC_CODE_MODE_C
:
1446 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_c
;
1448 case DTV_ATSCMH_SCCC_CODE_MODE_D
:
1449 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_d
;
1453 tvp
->u
.data
= c
->lna
;
1456 /* Fill quality measures */
1457 case DTV_STAT_SIGNAL_STRENGTH
:
1458 tvp
->u
.st
= c
->strength
;
1463 case DTV_STAT_PRE_ERROR_BIT_COUNT
:
1464 tvp
->u
.st
= c
->pre_bit_error
;
1466 case DTV_STAT_PRE_TOTAL_BIT_COUNT
:
1467 tvp
->u
.st
= c
->pre_bit_count
;
1469 case DTV_STAT_POST_ERROR_BIT_COUNT
:
1470 tvp
->u
.st
= c
->post_bit_error
;
1472 case DTV_STAT_POST_TOTAL_BIT_COUNT
:
1473 tvp
->u
.st
= c
->post_bit_count
;
1475 case DTV_STAT_ERROR_BLOCK_COUNT
:
1476 tvp
->u
.st
= c
->block_error
;
1478 case DTV_STAT_TOTAL_BLOCK_COUNT
:
1479 tvp
->u
.st
= c
->block_count
;
1482 dev_dbg(fe
->dvb
->device
,
1483 "%s: FE property %d doesn't exist\n",
1484 __func__
, tvp
->cmd
);
1488 /* Allow the frontend to override outgoing properties */
1489 if (fe
->ops
.get_property
) {
1490 r
= fe
->ops
.get_property(fe
, tvp
);
1495 dtv_property_dump(fe
, tvp
);
1500 static int dtv_set_frontend(struct dvb_frontend
*fe
);
1502 static bool is_dvbv3_delsys(u32 delsys
)
1506 status
= (delsys
== SYS_DVBT
) || (delsys
== SYS_DVBC_ANNEX_A
) ||
1507 (delsys
== SYS_DVBS
) || (delsys
== SYS_ATSC
);
1513 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1514 * @fe: struct frontend;
1515 * @delsys: DVBv5 type that will be used for emulation
1517 * Provides emulation for delivery systems that are compatible with the old
1518 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1519 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent
1520 * parameters are compatible with DVB-S spec.
1522 static int emulate_delivery_system(struct dvb_frontend
*fe
, u32 delsys
)
1525 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1527 c
->delivery_system
= delsys
;
1530 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1532 if (c
->delivery_system
== SYS_ISDBT
) {
1533 dev_dbg(fe
->dvb
->device
,
1534 "%s: Using defaults for SYS_ISDBT\n",
1537 if (!c
->bandwidth_hz
)
1538 c
->bandwidth_hz
= 6000000;
1540 c
->isdbt_partial_reception
= 0;
1541 c
->isdbt_sb_mode
= 0;
1542 c
->isdbt_sb_subchannel
= 0;
1543 c
->isdbt_sb_segment_idx
= 0;
1544 c
->isdbt_sb_segment_count
= 0;
1545 c
->isdbt_layer_enabled
= 7;
1546 for (i
= 0; i
< 3; i
++) {
1547 c
->layer
[i
].fec
= FEC_AUTO
;
1548 c
->layer
[i
].modulation
= QAM_AUTO
;
1549 c
->layer
[i
].interleaving
= 0;
1550 c
->layer
[i
].segment_count
= 0;
1553 dev_dbg(fe
->dvb
->device
, "%s: change delivery system on cache to %d\n",
1554 __func__
, c
->delivery_system
);
1560 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1561 * @fe: frontend struct
1562 * @desired_system: delivery system requested by the user
1564 * A DVBv5 call know what's the desired system it wants. So, set it.
1566 * There are, however, a few known issues with early DVBv5 applications that
1567 * are also handled by this logic:
1569 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1570 * This is an API violation, but, as we don't want to break userspace,
1571 * convert it to the first supported delivery system.
1572 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1573 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1574 * ISDB-T provided backward compat with DVB-T.
1576 static int dvbv5_set_delivery_system(struct dvb_frontend
*fe
,
1580 u32 delsys
= SYS_UNDEFINED
;
1581 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1582 enum dvbv3_emulation_type type
;
1585 * It was reported that some old DVBv5 applications were
1586 * filling delivery_system with SYS_UNDEFINED. If this happens,
1587 * assume that the application wants to use the first supported
1590 if (desired_system
== SYS_UNDEFINED
)
1591 desired_system
= fe
->ops
.delsys
[0];
1594 * This is a DVBv5 call. So, it likely knows the supported
1595 * delivery systems. So, check if the desired delivery system is
1599 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1600 if (fe
->ops
.delsys
[ncaps
] == desired_system
) {
1601 c
->delivery_system
= desired_system
;
1602 dev_dbg(fe
->dvb
->device
,
1603 "%s: Changing delivery system to %d\n",
1604 __func__
, desired_system
);
1611 * The requested delivery system isn't supported. Maybe userspace
1612 * is requesting a DVBv3 compatible delivery system.
1614 * The emulation only works if the desired system is one of the
1615 * delivery systems supported by DVBv3 API
1617 if (!is_dvbv3_delsys(desired_system
)) {
1618 dev_dbg(fe
->dvb
->device
,
1619 "%s: Delivery system %d not supported.\n",
1620 __func__
, desired_system
);
1624 type
= dvbv3_type(desired_system
);
1627 * Get the last non-DVBv3 delivery system that has the same type
1628 * of the desired system
1631 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1632 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) == type
)
1633 delsys
= fe
->ops
.delsys
[ncaps
];
1637 /* There's nothing compatible with the desired delivery system */
1638 if (delsys
== SYS_UNDEFINED
) {
1639 dev_dbg(fe
->dvb
->device
,
1640 "%s: Delivery system %d not supported on emulation mode.\n",
1641 __func__
, desired_system
);
1645 dev_dbg(fe
->dvb
->device
,
1646 "%s: Using delivery system %d emulated as if it were %d\n",
1647 __func__
, delsys
, desired_system
);
1649 return emulate_delivery_system(fe
, desired_system
);
1653 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1654 * @fe: frontend struct
1656 * A DVBv3 call doesn't know what's the desired system it wants. It also
1657 * doesn't allow to switch between different types. Due to that, userspace
1658 * should use DVBv5 instead.
1659 * However, in order to avoid breaking userspace API, limited backward
1660 * compatibility support is provided.
1662 * There are some delivery systems that are incompatible with DVBv3 calls.
1664 * This routine should work fine for frontends that support just one delivery
1667 * For frontends that support multiple frontends:
1668 * 1) It defaults to use the first supported delivery system. There's an
1669 * userspace application that allows changing it at runtime;
1671 * 2) If the current delivery system is not compatible with DVBv3, it gets
1672 * the first one that it is compatible.
1674 * NOTE: in order for this to work with applications like Kaffeine that
1675 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1676 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1677 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1680 static int dvbv3_set_delivery_system(struct dvb_frontend
*fe
)
1683 u32 delsys
= SYS_UNDEFINED
;
1684 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1686 /* If not set yet, defaults to the first supported delivery system */
1687 if (c
->delivery_system
== SYS_UNDEFINED
)
1688 c
->delivery_system
= fe
->ops
.delsys
[0];
1691 * Trivial case: just use the current one, if it already a DVBv3
1694 if (is_dvbv3_delsys(c
->delivery_system
)) {
1695 dev_dbg(fe
->dvb
->device
,
1696 "%s: Using delivery system to %d\n",
1697 __func__
, c
->delivery_system
);
1702 * Seek for the first delivery system that it is compatible with a
1706 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1707 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) != DVBV3_UNKNOWN
) {
1708 delsys
= fe
->ops
.delsys
[ncaps
];
1713 if (delsys
== SYS_UNDEFINED
) {
1714 dev_dbg(fe
->dvb
->device
,
1715 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1719 return emulate_delivery_system(fe
, delsys
);
1722 static int dtv_property_process_set(struct dvb_frontend
*fe
,
1723 struct dtv_property
*tvp
,
1727 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1729 /* Allow the frontend to validate incoming properties */
1730 if (fe
->ops
.set_property
) {
1731 r
= fe
->ops
.set_property(fe
, tvp
);
1739 * Reset a cache of data specific to the frontend here. This does
1740 * not effect hardware.
1742 dvb_frontend_clear_cache(fe
);
1745 /* interpret the cache of data, build either a traditional frontend
1746 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1749 c
->state
= tvp
->cmd
;
1750 dev_dbg(fe
->dvb
->device
, "%s: Finalised property cache\n",
1753 r
= dtv_set_frontend(fe
);
1756 c
->frequency
= tvp
->u
.data
;
1758 case DTV_MODULATION
:
1759 c
->modulation
= tvp
->u
.data
;
1761 case DTV_BANDWIDTH_HZ
:
1762 c
->bandwidth_hz
= tvp
->u
.data
;
1765 c
->inversion
= tvp
->u
.data
;
1767 case DTV_SYMBOL_RATE
:
1768 c
->symbol_rate
= tvp
->u
.data
;
1771 c
->fec_inner
= tvp
->u
.data
;
1774 c
->pilot
= tvp
->u
.data
;
1777 c
->rolloff
= tvp
->u
.data
;
1779 case DTV_DELIVERY_SYSTEM
:
1780 r
= dvbv5_set_delivery_system(fe
, tvp
->u
.data
);
1783 c
->voltage
= tvp
->u
.data
;
1784 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_VOLTAGE
,
1785 (void *)c
->voltage
);
1788 c
->sectone
= tvp
->u
.data
;
1789 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_TONE
,
1790 (void *)c
->sectone
);
1792 case DTV_CODE_RATE_HP
:
1793 c
->code_rate_HP
= tvp
->u
.data
;
1795 case DTV_CODE_RATE_LP
:
1796 c
->code_rate_LP
= tvp
->u
.data
;
1798 case DTV_GUARD_INTERVAL
:
1799 c
->guard_interval
= tvp
->u
.data
;
1801 case DTV_TRANSMISSION_MODE
:
1802 c
->transmission_mode
= tvp
->u
.data
;
1805 c
->hierarchy
= tvp
->u
.data
;
1807 case DTV_INTERLEAVING
:
1808 c
->interleaving
= tvp
->u
.data
;
1811 /* ISDB-T Support here */
1812 case DTV_ISDBT_PARTIAL_RECEPTION
:
1813 c
->isdbt_partial_reception
= tvp
->u
.data
;
1815 case DTV_ISDBT_SOUND_BROADCASTING
:
1816 c
->isdbt_sb_mode
= tvp
->u
.data
;
1818 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1819 c
->isdbt_sb_subchannel
= tvp
->u
.data
;
1821 case DTV_ISDBT_SB_SEGMENT_IDX
:
1822 c
->isdbt_sb_segment_idx
= tvp
->u
.data
;
1824 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1825 c
->isdbt_sb_segment_count
= tvp
->u
.data
;
1827 case DTV_ISDBT_LAYER_ENABLED
:
1828 c
->isdbt_layer_enabled
= tvp
->u
.data
;
1830 case DTV_ISDBT_LAYERA_FEC
:
1831 c
->layer
[0].fec
= tvp
->u
.data
;
1833 case DTV_ISDBT_LAYERA_MODULATION
:
1834 c
->layer
[0].modulation
= tvp
->u
.data
;
1836 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1837 c
->layer
[0].segment_count
= tvp
->u
.data
;
1839 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1840 c
->layer
[0].interleaving
= tvp
->u
.data
;
1842 case DTV_ISDBT_LAYERB_FEC
:
1843 c
->layer
[1].fec
= tvp
->u
.data
;
1845 case DTV_ISDBT_LAYERB_MODULATION
:
1846 c
->layer
[1].modulation
= tvp
->u
.data
;
1848 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1849 c
->layer
[1].segment_count
= tvp
->u
.data
;
1851 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1852 c
->layer
[1].interleaving
= tvp
->u
.data
;
1854 case DTV_ISDBT_LAYERC_FEC
:
1855 c
->layer
[2].fec
= tvp
->u
.data
;
1857 case DTV_ISDBT_LAYERC_MODULATION
:
1858 c
->layer
[2].modulation
= tvp
->u
.data
;
1860 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1861 c
->layer
[2].segment_count
= tvp
->u
.data
;
1863 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1864 c
->layer
[2].interleaving
= tvp
->u
.data
;
1867 /* Multistream support */
1869 case DTV_DVBT2_PLP_ID_LEGACY
:
1870 c
->stream_id
= tvp
->u
.data
;
1874 case DTV_ATSCMH_PARADE_ID
:
1875 fe
->dtv_property_cache
.atscmh_parade_id
= tvp
->u
.data
;
1877 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1878 fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
= tvp
->u
.data
;
1882 c
->lna
= tvp
->u
.data
;
1883 if (fe
->ops
.set_lna
)
1884 r
= fe
->ops
.set_lna(fe
);
1894 static int dvb_frontend_ioctl(struct file
*file
,
1895 unsigned int cmd
, void *parg
)
1897 struct dvb_device
*dvbdev
= file
->private_data
;
1898 struct dvb_frontend
*fe
= dvbdev
->priv
;
1899 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1900 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1901 int err
= -EOPNOTSUPP
;
1903 dev_dbg(fe
->dvb
->device
, "%s: (%d)\n", __func__
, _IOC_NR(cmd
));
1904 if (down_interruptible(&fepriv
->sem
))
1905 return -ERESTARTSYS
;
1907 if (fepriv
->exit
!= DVB_FE_NO_EXIT
) {
1912 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
&&
1913 (_IOC_DIR(cmd
) != _IOC_READ
|| cmd
== FE_GET_EVENT
||
1914 cmd
== FE_DISEQC_RECV_SLAVE_REPLY
)) {
1919 if ((cmd
== FE_SET_PROPERTY
) || (cmd
== FE_GET_PROPERTY
))
1920 err
= dvb_frontend_ioctl_properties(file
, cmd
, parg
);
1922 c
->state
= DTV_UNDEFINED
;
1923 err
= dvb_frontend_ioctl_legacy(file
, cmd
, parg
);
1930 static int dvb_frontend_ioctl_properties(struct file
*file
,
1931 unsigned int cmd
, void *parg
)
1933 struct dvb_device
*dvbdev
= file
->private_data
;
1934 struct dvb_frontend
*fe
= dvbdev
->priv
;
1935 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1936 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1939 struct dtv_properties
*tvps
= NULL
;
1940 struct dtv_property
*tvp
= NULL
;
1943 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
1945 if(cmd
== FE_SET_PROPERTY
) {
1946 tvps
= (struct dtv_properties __user
*)parg
;
1948 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n", __func__
, tvps
->num
);
1949 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n", __func__
, tvps
->props
);
1951 /* Put an arbitrary limit on the number of messages that can
1952 * be sent at once */
1953 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
1956 tvp
= kmalloc(tvps
->num
* sizeof(struct dtv_property
), GFP_KERNEL
);
1962 if (copy_from_user(tvp
, tvps
->props
, tvps
->num
* sizeof(struct dtv_property
))) {
1967 for (i
= 0; i
< tvps
->num
; i
++) {
1968 err
= dtv_property_process_set(fe
, tvp
+ i
, file
);
1971 (tvp
+ i
)->result
= err
;
1974 if (c
->state
== DTV_TUNE
)
1975 dev_dbg(fe
->dvb
->device
, "%s: Property cache is full, tuning\n", __func__
);
1978 if(cmd
== FE_GET_PROPERTY
) {
1979 tvps
= (struct dtv_properties __user
*)parg
;
1981 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n", __func__
, tvps
->num
);
1982 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n", __func__
, tvps
->props
);
1984 /* Put an arbitrary limit on the number of messages that can
1985 * be sent at once */
1986 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
1989 tvp
= kmalloc(tvps
->num
* sizeof(struct dtv_property
), GFP_KERNEL
);
1995 if (copy_from_user(tvp
, tvps
->props
, tvps
->num
* sizeof(struct dtv_property
))) {
2001 * Fills the cache out struct with the cache contents, plus
2002 * the data retrieved from get_frontend, if the frontend
2003 * is not idle. Otherwise, returns the cached content
2005 if (fepriv
->state
!= FESTATE_IDLE
) {
2006 err
= dtv_get_frontend(fe
, NULL
);
2010 for (i
= 0; i
< tvps
->num
; i
++) {
2011 err
= dtv_property_process_get(fe
, c
, tvp
+ i
, file
);
2014 (tvp
+ i
)->result
= err
;
2017 if (copy_to_user(tvps
->props
, tvp
, tvps
->num
* sizeof(struct dtv_property
))) {
2030 static int dtv_set_frontend(struct dvb_frontend
*fe
)
2032 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2033 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
2034 struct dvb_frontend_tune_settings fetunesettings
;
2037 if (dvb_frontend_check_parameters(fe
) < 0)
2041 * Initialize output parameters to match the values given by
2042 * the user. FE_SET_FRONTEND triggers an initial frontend event
2043 * with status = 0, which copies output parameters to userspace.
2045 dtv_property_legacy_params_sync(fe
, &fepriv
->parameters_out
);
2048 * Be sure that the bandwidth will be filled for all
2049 * non-satellite systems, as tuners need to know what
2050 * low pass/Nyquist half filter should be applied, in
2051 * order to avoid inter-channel noise.
2053 * ISDB-T and DVB-T/T2 already sets bandwidth.
2054 * ATSC and DVB-C don't set, so, the core should fill it.
2056 * On DVB-C Annex A and C, the bandwidth is a function of
2057 * the roll-off and symbol rate. Annex B defines different
2058 * roll-off factors depending on the modulation. Fortunately,
2059 * Annex B is only used with 6MHz, so there's no need to
2062 * While not officially supported, a side effect of handling it at
2063 * the cache level is that a program could retrieve the bandwidth
2064 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2066 switch (c
->delivery_system
) {
2068 case SYS_DVBC_ANNEX_B
:
2069 c
->bandwidth_hz
= 6000000;
2071 case SYS_DVBC_ANNEX_A
:
2074 case SYS_DVBC_ANNEX_C
:
2081 c
->bandwidth_hz
= (c
->symbol_rate
* rolloff
) / 100;
2083 /* force auto frequency inversion if requested */
2084 if (dvb_force_auto_inversion
)
2085 c
->inversion
= INVERSION_AUTO
;
2088 * without hierarchical coding code_rate_LP is irrelevant,
2089 * so we tolerate the otherwise invalid FEC_NONE setting
2091 if (c
->hierarchy
== HIERARCHY_NONE
&& c
->code_rate_LP
== FEC_NONE
)
2092 c
->code_rate_LP
= FEC_AUTO
;
2094 /* get frontend-specific tuning settings */
2095 memset(&fetunesettings
, 0, sizeof(struct dvb_frontend_tune_settings
));
2096 if (fe
->ops
.get_tune_settings
&& (fe
->ops
.get_tune_settings(fe
, &fetunesettings
) == 0)) {
2097 fepriv
->min_delay
= (fetunesettings
.min_delay_ms
* HZ
) / 1000;
2098 fepriv
->max_drift
= fetunesettings
.max_drift
;
2099 fepriv
->step_size
= fetunesettings
.step_size
;
2101 /* default values */
2102 switch (c
->delivery_system
) {
2107 case SYS_DVBC_ANNEX_A
:
2108 case SYS_DVBC_ANNEX_C
:
2109 fepriv
->min_delay
= HZ
/ 20;
2110 fepriv
->step_size
= c
->symbol_rate
/ 16000;
2111 fepriv
->max_drift
= c
->symbol_rate
/ 2000;
2117 fepriv
->min_delay
= HZ
/ 20;
2118 fepriv
->step_size
= fe
->ops
.info
.frequency_stepsize
* 2;
2119 fepriv
->max_drift
= (fe
->ops
.info
.frequency_stepsize
* 2) + 1;
2123 * FIXME: This sounds wrong! if freqency_stepsize is
2124 * defined by the frontend, why not use it???
2126 fepriv
->min_delay
= HZ
/ 20;
2127 fepriv
->step_size
= 0; /* no zigzag */
2128 fepriv
->max_drift
= 0;
2132 if (dvb_override_tune_delay
> 0)
2133 fepriv
->min_delay
= (dvb_override_tune_delay
* HZ
) / 1000;
2135 fepriv
->state
= FESTATE_RETUNE
;
2137 /* Request the search algorithm to search */
2138 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
2140 dvb_frontend_clear_events(fe
);
2141 dvb_frontend_add_event(fe
, 0);
2142 dvb_frontend_wakeup(fe
);
2149 static int dvb_frontend_ioctl_legacy(struct file
*file
,
2150 unsigned int cmd
, void *parg
)
2152 struct dvb_device
*dvbdev
= file
->private_data
;
2153 struct dvb_frontend
*fe
= dvbdev
->priv
;
2154 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2155 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
2156 int err
= -EOPNOTSUPP
;
2160 struct dvb_frontend_info
* info
= parg
;
2162 memcpy(info
, &fe
->ops
.info
, sizeof(struct dvb_frontend_info
));
2163 dvb_frontend_get_frequency_limits(fe
, &info
->frequency_min
, &info
->frequency_max
);
2166 * Associate the 4 delivery systems supported by DVBv3
2167 * API with their DVBv5 counterpart. For the other standards,
2168 * use the closest type, assuming that it would hopefully
2169 * work with a DVBv3 application.
2170 * It should be noticed that, on multi-frontend devices with
2171 * different types (terrestrial and cable, for example),
2172 * a pure DVBv3 application won't be able to use all delivery
2173 * systems. Yet, changing the DVBv5 cache to the other delivery
2174 * system should be enough for making it work.
2176 switch (dvbv3_type(c
->delivery_system
)) {
2178 info
->type
= FE_QPSK
;
2181 info
->type
= FE_ATSC
;
2184 info
->type
= FE_QAM
;
2187 info
->type
= FE_OFDM
;
2190 dev_err(fe
->dvb
->device
,
2191 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2192 __func__
, c
->delivery_system
);
2193 fe
->ops
.info
.type
= FE_OFDM
;
2195 dev_dbg(fe
->dvb
->device
, "%s: current delivery system on cache: %d, V3 type: %d\n",
2196 __func__
, c
->delivery_system
, fe
->ops
.info
.type
);
2198 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
2199 * do it, it is done for it. */
2200 info
->caps
|= FE_CAN_INVERSION_AUTO
;
2205 case FE_READ_STATUS
: {
2206 fe_status_t
* status
= parg
;
2208 /* if retune was requested but hasn't occurred yet, prevent
2209 * that user get signal state from previous tuning */
2210 if (fepriv
->state
== FESTATE_RETUNE
||
2211 fepriv
->state
== FESTATE_ERROR
) {
2217 if (fe
->ops
.read_status
)
2218 err
= fe
->ops
.read_status(fe
, status
);
2223 if (fe
->ops
.read_ber
) {
2225 err
= fe
->ops
.read_ber(fe
, (__u32
*) parg
);
2231 case FE_READ_SIGNAL_STRENGTH
:
2232 if (fe
->ops
.read_signal_strength
) {
2234 err
= fe
->ops
.read_signal_strength(fe
, (__u16
*) parg
);
2241 if (fe
->ops
.read_snr
) {
2243 err
= fe
->ops
.read_snr(fe
, (__u16
*) parg
);
2249 case FE_READ_UNCORRECTED_BLOCKS
:
2250 if (fe
->ops
.read_ucblocks
) {
2252 err
= fe
->ops
.read_ucblocks(fe
, (__u32
*) parg
);
2258 case FE_DISEQC_RESET_OVERLOAD
:
2259 if (fe
->ops
.diseqc_reset_overload
) {
2260 err
= fe
->ops
.diseqc_reset_overload(fe
);
2261 fepriv
->state
= FESTATE_DISEQC
;
2266 case FE_DISEQC_SEND_MASTER_CMD
:
2267 if (fe
->ops
.diseqc_send_master_cmd
) {
2268 err
= fe
->ops
.diseqc_send_master_cmd(fe
, (struct dvb_diseqc_master_cmd
*) parg
);
2269 fepriv
->state
= FESTATE_DISEQC
;
2274 case FE_DISEQC_SEND_BURST
:
2275 if (fe
->ops
.diseqc_send_burst
) {
2276 err
= fe
->ops
.diseqc_send_burst(fe
, (fe_sec_mini_cmd_t
) parg
);
2277 fepriv
->state
= FESTATE_DISEQC
;
2283 if (fe
->ops
.set_tone
) {
2284 err
= fe
->ops
.set_tone(fe
, (fe_sec_tone_mode_t
) parg
);
2285 fepriv
->tone
= (fe_sec_tone_mode_t
) parg
;
2286 fepriv
->state
= FESTATE_DISEQC
;
2291 case FE_SET_VOLTAGE
:
2292 if (fe
->ops
.set_voltage
) {
2293 err
= fe
->ops
.set_voltage(fe
, (fe_sec_voltage_t
) parg
);
2294 fepriv
->voltage
= (fe_sec_voltage_t
) parg
;
2295 fepriv
->state
= FESTATE_DISEQC
;
2300 case FE_DISHNETWORK_SEND_LEGACY_CMD
:
2301 if (fe
->ops
.dishnetwork_send_legacy_command
) {
2302 err
= fe
->ops
.dishnetwork_send_legacy_command(fe
, (unsigned long) parg
);
2303 fepriv
->state
= FESTATE_DISEQC
;
2305 } else if (fe
->ops
.set_voltage
) {
2307 * NOTE: This is a fallback condition. Some frontends
2308 * (stv0299 for instance) take longer than 8msec to
2309 * respond to a set_voltage command. Those switches
2310 * need custom routines to switch properly. For all
2311 * other frontends, the following should work ok.
2312 * Dish network legacy switches (as used by Dish500)
2313 * are controlled by sending 9-bit command words
2314 * spaced 8msec apart.
2315 * the actual command word is switch/port dependent
2316 * so it is up to the userspace application to send
2317 * the right command.
2318 * The command must always start with a '0' after
2319 * initialization, so parg is 8 bits and does not
2320 * include the initialization or start bit
2322 unsigned long swcmd
= ((unsigned long) parg
) << 1;
2323 struct timeval nexttime
;
2324 struct timeval tv
[10];
2327 if (dvb_frontend_debug
)
2328 printk("%s switch command: 0x%04lx\n", __func__
, swcmd
);
2329 do_gettimeofday(&nexttime
);
2330 if (dvb_frontend_debug
)
2332 /* before sending a command, initialize by sending
2333 * a 32ms 18V to the switch
2335 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_18
);
2336 dvb_frontend_sleep_until(&nexttime
, 32000);
2338 for (i
= 0; i
< 9; i
++) {
2339 if (dvb_frontend_debug
)
2340 do_gettimeofday(&tv
[i
+ 1]);
2341 if ((swcmd
& 0x01) != last
) {
2342 /* set voltage to (last ? 13V : 18V) */
2343 fe
->ops
.set_voltage(fe
, (last
) ? SEC_VOLTAGE_13
: SEC_VOLTAGE_18
);
2344 last
= (last
) ? 0 : 1;
2348 dvb_frontend_sleep_until(&nexttime
, 8000);
2350 if (dvb_frontend_debug
) {
2351 printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
2352 __func__
, fe
->dvb
->num
);
2353 for (i
= 1; i
< 10; i
++)
2354 printk("%d: %d\n", i
, timeval_usec_diff(tv
[i
-1] , tv
[i
]));
2357 fepriv
->state
= FESTATE_DISEQC
;
2362 case FE_DISEQC_RECV_SLAVE_REPLY
:
2363 if (fe
->ops
.diseqc_recv_slave_reply
)
2364 err
= fe
->ops
.diseqc_recv_slave_reply(fe
, (struct dvb_diseqc_slave_reply
*) parg
);
2367 case FE_ENABLE_HIGH_LNB_VOLTAGE
:
2368 if (fe
->ops
.enable_high_lnb_voltage
)
2369 err
= fe
->ops
.enable_high_lnb_voltage(fe
, (long) parg
);
2372 case FE_SET_FRONTEND
:
2373 err
= dvbv3_set_delivery_system(fe
);
2377 err
= dtv_property_cache_sync(fe
, c
, parg
);
2380 err
= dtv_set_frontend(fe
);
2383 err
= dvb_frontend_get_event (fe
, parg
, file
->f_flags
);
2386 case FE_GET_FRONTEND
:
2387 err
= dtv_get_frontend(fe
, parg
);
2390 case FE_SET_FRONTEND_TUNE_MODE
:
2391 fepriv
->tune_mode_flags
= (unsigned long) parg
;
2400 static unsigned int dvb_frontend_poll(struct file
*file
, struct poll_table_struct
*wait
)
2402 struct dvb_device
*dvbdev
= file
->private_data
;
2403 struct dvb_frontend
*fe
= dvbdev
->priv
;
2404 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2406 dev_dbg_ratelimited(fe
->dvb
->device
, "%s:\n", __func__
);
2408 poll_wait (file
, &fepriv
->events
.wait_queue
, wait
);
2410 if (fepriv
->events
.eventw
!= fepriv
->events
.eventr
)
2411 return (POLLIN
| POLLRDNORM
| POLLPRI
);
2416 static int dvb_frontend_open(struct inode
*inode
, struct file
*file
)
2418 struct dvb_device
*dvbdev
= file
->private_data
;
2419 struct dvb_frontend
*fe
= dvbdev
->priv
;
2420 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2421 struct dvb_adapter
*adapter
= fe
->dvb
;
2424 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2425 if (fepriv
->exit
== DVB_FE_DEVICE_REMOVED
)
2428 if (adapter
->mfe_shared
) {
2429 mutex_lock (&adapter
->mfe_lock
);
2431 if (adapter
->mfe_dvbdev
== NULL
)
2432 adapter
->mfe_dvbdev
= dvbdev
;
2434 else if (adapter
->mfe_dvbdev
!= dvbdev
) {
2436 *mfedev
= adapter
->mfe_dvbdev
;
2438 *mfe
= mfedev
->priv
;
2439 struct dvb_frontend_private
2440 *mfepriv
= mfe
->frontend_priv
;
2441 int mferetry
= (dvb_mfe_wait_time
<< 1);
2443 mutex_unlock (&adapter
->mfe_lock
);
2444 while (mferetry
-- && (mfedev
->users
!= -1 ||
2445 mfepriv
->thread
!= NULL
)) {
2446 if(msleep_interruptible(500)) {
2447 if(signal_pending(current
))
2452 mutex_lock (&adapter
->mfe_lock
);
2453 if(adapter
->mfe_dvbdev
!= dvbdev
) {
2454 mfedev
= adapter
->mfe_dvbdev
;
2456 mfepriv
= mfe
->frontend_priv
;
2457 if (mfedev
->users
!= -1 ||
2458 mfepriv
->thread
!= NULL
) {
2459 mutex_unlock (&adapter
->mfe_lock
);
2462 adapter
->mfe_dvbdev
= dvbdev
;
2467 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
) {
2468 if ((ret
= fe
->ops
.ts_bus_ctrl(fe
, 1)) < 0)
2471 /* If we took control of the bus, we need to force
2472 reinitialization. This is because many ts_bus_ctrl()
2473 functions strobe the RESET pin on the demod, and if the
2474 frontend thread already exists then the dvb_init() routine
2475 won't get called (which is what usually does initial
2476 register configuration). */
2477 fepriv
->reinitialise
= 1;
2480 if ((ret
= dvb_generic_open (inode
, file
)) < 0)
2483 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2484 /* normal tune mode when opened R/W */
2485 fepriv
->tune_mode_flags
&= ~FE_TUNE_MODE_ONESHOT
;
2487 fepriv
->voltage
= -1;
2489 ret
= dvb_frontend_start (fe
);
2493 /* empty event queue */
2494 fepriv
->events
.eventr
= fepriv
->events
.eventw
= 0;
2497 if (adapter
->mfe_shared
)
2498 mutex_unlock (&adapter
->mfe_lock
);
2502 dvb_generic_release(inode
, file
);
2504 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
)
2505 fe
->ops
.ts_bus_ctrl(fe
, 0);
2507 if (adapter
->mfe_shared
)
2508 mutex_unlock (&adapter
->mfe_lock
);
2512 static int dvb_frontend_release(struct inode
*inode
, struct file
*file
)
2514 struct dvb_device
*dvbdev
= file
->private_data
;
2515 struct dvb_frontend
*fe
= dvbdev
->priv
;
2516 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2519 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2521 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2522 fepriv
->release_jiffies
= jiffies
;
2526 ret
= dvb_generic_release (inode
, file
);
2528 if (dvbdev
->users
== -1) {
2529 wake_up(&fepriv
->wait_queue
);
2530 if (fepriv
->exit
!= DVB_FE_NO_EXIT
)
2531 wake_up(&dvbdev
->wait_queue
);
2532 if (fe
->ops
.ts_bus_ctrl
)
2533 fe
->ops
.ts_bus_ctrl(fe
, 0);
2539 static const struct file_operations dvb_frontend_fops
= {
2540 .owner
= THIS_MODULE
,
2541 .unlocked_ioctl
= dvb_generic_ioctl
,
2542 .poll
= dvb_frontend_poll
,
2543 .open
= dvb_frontend_open
,
2544 .release
= dvb_frontend_release
,
2545 .llseek
= noop_llseek
,
2548 int dvb_frontend_suspend(struct dvb_frontend
*fe
)
2552 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2555 if (fe
->ops
.tuner_ops
.sleep
)
2556 ret
= fe
->ops
.tuner_ops
.sleep(fe
);
2559 ret
= fe
->ops
.sleep(fe
);
2563 EXPORT_SYMBOL(dvb_frontend_suspend
);
2565 int dvb_frontend_resume(struct dvb_frontend
*fe
)
2567 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2570 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2574 ret
= fe
->ops
.init(fe
);
2576 if (fe
->ops
.tuner_ops
.init
)
2577 ret
= fe
->ops
.tuner_ops
.init(fe
);
2579 fepriv
->state
= FESTATE_RETUNE
;
2580 dvb_frontend_wakeup(fe
);
2584 EXPORT_SYMBOL(dvb_frontend_resume
);
2586 int dvb_register_frontend(struct dvb_adapter
* dvb
,
2587 struct dvb_frontend
* fe
)
2589 struct dvb_frontend_private
*fepriv
;
2590 static const struct dvb_device dvbdev_template
= {
2594 .fops
= &dvb_frontend_fops
,
2595 .kernel_ioctl
= dvb_frontend_ioctl
2598 dev_dbg(dvb
->device
, "%s:\n", __func__
);
2600 if (mutex_lock_interruptible(&frontend_mutex
))
2601 return -ERESTARTSYS
;
2603 fe
->frontend_priv
= kzalloc(sizeof(struct dvb_frontend_private
), GFP_KERNEL
);
2604 if (fe
->frontend_priv
== NULL
) {
2605 mutex_unlock(&frontend_mutex
);
2608 fepriv
= fe
->frontend_priv
;
2610 sema_init(&fepriv
->sem
, 1);
2611 init_waitqueue_head (&fepriv
->wait_queue
);
2612 init_waitqueue_head (&fepriv
->events
.wait_queue
);
2613 mutex_init(&fepriv
->events
.mtx
);
2615 fepriv
->inversion
= INVERSION_OFF
;
2617 dev_info(fe
->dvb
->device
,
2618 "DVB: registering adapter %i frontend %i (%s)...\n",
2619 fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
2621 dvb_register_device (fe
->dvb
, &fepriv
->dvbdev
, &dvbdev_template
,
2622 fe
, DVB_DEVICE_FRONTEND
);
2625 * Initialize the cache to the proper values according with the
2626 * first supported delivery system (ops->delsys[0])
2629 fe
->dtv_property_cache
.delivery_system
= fe
->ops
.delsys
[0];
2630 dvb_frontend_clear_cache(fe
);
2632 mutex_unlock(&frontend_mutex
);
2635 EXPORT_SYMBOL(dvb_register_frontend
);
2637 int dvb_unregister_frontend(struct dvb_frontend
* fe
)
2639 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2640 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2642 mutex_lock(&frontend_mutex
);
2643 dvb_frontend_stop (fe
);
2644 mutex_unlock(&frontend_mutex
);
2646 if (fepriv
->dvbdev
->users
< -1)
2647 wait_event(fepriv
->dvbdev
->wait_queue
,
2648 fepriv
->dvbdev
->users
==-1);
2650 mutex_lock(&frontend_mutex
);
2651 dvb_unregister_device (fepriv
->dvbdev
);
2653 /* fe is invalid now */
2655 mutex_unlock(&frontend_mutex
);
2658 EXPORT_SYMBOL(dvb_unregister_frontend
);
2660 #ifdef CONFIG_MEDIA_ATTACH
2661 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2665 if (fe
->ops
.release_sec
) {
2666 fe
->ops
.release_sec(fe
);
2667 symbol_put_addr(fe
->ops
.release_sec
);
2669 if (fe
->ops
.tuner_ops
.release
) {
2670 fe
->ops
.tuner_ops
.release(fe
);
2671 symbol_put_addr(fe
->ops
.tuner_ops
.release
);
2673 if (fe
->ops
.analog_ops
.release
) {
2674 fe
->ops
.analog_ops
.release(fe
);
2675 symbol_put_addr(fe
->ops
.analog_ops
.release
);
2677 ptr
= (void*)fe
->ops
.release
;
2679 fe
->ops
.release(fe
);
2680 symbol_put_addr(ptr
);
2684 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2686 if (fe
->ops
.release_sec
)
2687 fe
->ops
.release_sec(fe
);
2688 if (fe
->ops
.tuner_ops
.release
)
2689 fe
->ops
.tuner_ops
.release(fe
);
2690 if (fe
->ops
.analog_ops
.release
)
2691 fe
->ops
.analog_ops
.release(fe
);
2692 if (fe
->ops
.release
)
2693 fe
->ops
.release(fe
);
2696 EXPORT_SYMBOL(dvb_frontend_detach
);