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 #define pr_fmt(fmt) "dvb_frontend: " fmt
33 #include <linux/string.h>
34 #include <linux/kernel.h>
35 #include <linux/sched.h>
36 #include <linux/wait.h>
37 #include <linux/slab.h>
38 #include <linux/poll.h>
39 #include <linux/semaphore.h>
40 #include <linux/module.h>
41 #include <linux/list.h>
42 #include <linux/freezer.h>
43 #include <linux/jiffies.h>
44 #include <linux/kthread.h>
45 #include <linux/ktime.h>
46 #include <asm/processor.h>
48 #include "dvb_frontend.h"
50 #include <linux/dvb/version.h>
52 static int dvb_frontend_debug
;
53 static int dvb_shutdown_timeout
;
54 static int dvb_force_auto_inversion
;
55 static int dvb_override_tune_delay
;
56 static int dvb_powerdown_on_sleep
= 1;
57 static int dvb_mfe_wait_time
= 5;
59 module_param_named(frontend_debug
, dvb_frontend_debug
, int, 0644);
60 MODULE_PARM_DESC(frontend_debug
, "Turn on/off frontend core debugging (default:off).");
61 module_param(dvb_shutdown_timeout
, int, 0644);
62 MODULE_PARM_DESC(dvb_shutdown_timeout
, "wait <shutdown_timeout> seconds after close() before suspending hardware");
63 module_param(dvb_force_auto_inversion
, int, 0644);
64 MODULE_PARM_DESC(dvb_force_auto_inversion
, "0: normal (default), 1: INVERSION_AUTO forced always");
65 module_param(dvb_override_tune_delay
, int, 0644);
66 MODULE_PARM_DESC(dvb_override_tune_delay
, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
67 module_param(dvb_powerdown_on_sleep
, int, 0644);
68 MODULE_PARM_DESC(dvb_powerdown_on_sleep
, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
69 module_param(dvb_mfe_wait_time
, int, 0644);
70 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)");
72 #define dprintk(fmt, arg...) \
73 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
75 #define FESTATE_IDLE 1
76 #define FESTATE_RETUNE 2
77 #define FESTATE_TUNING_FAST 4
78 #define FESTATE_TUNING_SLOW 8
79 #define FESTATE_TUNED 16
80 #define FESTATE_ZIGZAG_FAST 32
81 #define FESTATE_ZIGZAG_SLOW 64
82 #define FESTATE_DISEQC 128
83 #define FESTATE_ERROR 256
84 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
85 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
86 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
87 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
90 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
91 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
92 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
93 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
94 * FESTATE_TUNED. The frontend has successfully locked on.
95 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
96 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
97 * FESTATE_DISEQC. A DISEQC command has just been issued.
98 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
99 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
100 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
101 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
104 static DEFINE_MUTEX(frontend_mutex
);
106 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
;
117 enum fe_status status
;
118 unsigned long tune_mode_flags
;
120 unsigned int reinitialise
;
124 /* swzigzag values */
126 unsigned int bending
;
128 unsigned int inversion
;
129 unsigned int auto_step
;
130 unsigned int auto_sub_step
;
131 unsigned int started_auto_step
;
132 unsigned int min_delay
;
133 unsigned int max_drift
;
134 unsigned int step_size
;
136 unsigned int check_wrapped
;
137 enum dvbfe_search algo_status
;
139 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
140 struct media_pipeline pipe
;
144 static void dvb_frontend_invoke_release(struct dvb_frontend
*fe
,
145 void (*release
)(struct dvb_frontend
*fe
));
147 static void dvb_frontend_free(struct kref
*ref
)
149 struct dvb_frontend
*fe
=
150 container_of(ref
, struct dvb_frontend
, refcount
);
151 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
153 dvb_free_device(fepriv
->dvbdev
);
155 dvb_frontend_invoke_release(fe
, fe
->ops
.release
);
160 static void dvb_frontend_put(struct dvb_frontend
*fe
)
162 kref_put(&fe
->refcount
, dvb_frontend_free
);
165 static void dvb_frontend_get(struct dvb_frontend
*fe
)
167 kref_get(&fe
->refcount
);
170 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
);
171 static int dtv_get_frontend(struct dvb_frontend
*fe
,
172 struct dtv_frontend_properties
*c
,
173 struct dvb_frontend_parameters
*p_out
);
175 dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
176 const struct dtv_frontend_properties
*c
,
177 struct dvb_frontend_parameters
*p
);
179 static bool has_get_frontend(struct dvb_frontend
*fe
)
181 return fe
->ops
.get_frontend
!= NULL
;
185 * Due to DVBv3 API calls, a delivery system should be mapped into one of
186 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
187 * otherwise, a DVBv3 call will fail.
189 enum dvbv3_emulation_type
{
197 static enum dvbv3_emulation_type
dvbv3_type(u32 delivery_system
)
199 switch (delivery_system
) {
200 case SYS_DVBC_ANNEX_A
:
201 case SYS_DVBC_ANNEX_C
:
216 case SYS_DVBC_ANNEX_B
:
224 * Doesn't know how to emulate those types and/or
225 * there's no frontend driver from this type yet
226 * with some emulation code, so, we're not sure yet how
227 * to handle them, or they're not compatible with a DVBv3 call.
229 return DVBV3_UNKNOWN
;
233 static void dvb_frontend_add_event(struct dvb_frontend
*fe
,
234 enum fe_status status
)
236 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
237 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
238 struct dvb_fe_events
*events
= &fepriv
->events
;
239 struct dvb_frontend_event
*e
;
242 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
244 if ((status
& FE_HAS_LOCK
) && has_get_frontend(fe
))
245 dtv_get_frontend(fe
, c
, &fepriv
->parameters_out
);
247 mutex_lock(&events
->mtx
);
249 wp
= (events
->eventw
+ 1) % MAX_EVENT
;
250 if (wp
== events
->eventr
) {
251 events
->overflow
= 1;
252 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
255 e
= &events
->events
[events
->eventw
];
257 e
->parameters
= fepriv
->parameters_out
;
261 mutex_unlock(&events
->mtx
);
263 wake_up_interruptible (&events
->wait_queue
);
266 static int dvb_frontend_get_event(struct dvb_frontend
*fe
,
267 struct dvb_frontend_event
*event
, int flags
)
269 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
270 struct dvb_fe_events
*events
= &fepriv
->events
;
272 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
274 if (events
->overflow
) {
275 events
->overflow
= 0;
279 if (events
->eventw
== events
->eventr
) {
282 if (flags
& O_NONBLOCK
)
287 ret
= wait_event_interruptible (events
->wait_queue
,
288 events
->eventw
!= events
->eventr
);
290 if (down_interruptible (&fepriv
->sem
))
297 mutex_lock(&events
->mtx
);
298 *event
= events
->events
[events
->eventr
];
299 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
300 mutex_unlock(&events
->mtx
);
305 static void dvb_frontend_clear_events(struct dvb_frontend
*fe
)
307 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
308 struct dvb_fe_events
*events
= &fepriv
->events
;
310 mutex_lock(&events
->mtx
);
311 events
->eventr
= events
->eventw
;
312 mutex_unlock(&events
->mtx
);
315 static void dvb_frontend_init(struct dvb_frontend
*fe
)
317 dev_dbg(fe
->dvb
->device
,
318 "%s: initialising adapter %i frontend %i (%s)...\n",
319 __func__
, fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
323 if (fe
->ops
.tuner_ops
.init
) {
324 if (fe
->ops
.i2c_gate_ctrl
)
325 fe
->ops
.i2c_gate_ctrl(fe
, 1);
326 fe
->ops
.tuner_ops
.init(fe
);
327 if (fe
->ops
.i2c_gate_ctrl
)
328 fe
->ops
.i2c_gate_ctrl(fe
, 0);
332 void dvb_frontend_reinitialise(struct dvb_frontend
*fe
)
334 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
336 fepriv
->reinitialise
= 1;
337 dvb_frontend_wakeup(fe
);
339 EXPORT_SYMBOL(dvb_frontend_reinitialise
);
341 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private
*fepriv
, int locked
)
344 struct dvb_frontend
*fe
= fepriv
->dvbdev
->priv
;
346 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
349 (fepriv
->quality
) = (fepriv
->quality
* 220 + 36*256) / 256;
351 (fepriv
->quality
) = (fepriv
->quality
* 220 + 0) / 256;
353 q2
= fepriv
->quality
- 128;
356 fepriv
->delay
= fepriv
->min_delay
+ q2
* HZ
/ (128*128);
360 * Performs automatic twiddling of frontend parameters.
362 * @param fe The frontend concerned.
363 * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
364 * @returns Number of complete iterations that have been performed.
366 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend
*fe
, int check_wrapped
)
371 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
372 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
373 int original_inversion
= c
->inversion
;
374 u32 original_frequency
= c
->frequency
;
376 /* are we using autoinversion? */
377 autoinversion
= ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
378 (c
->inversion
== INVERSION_AUTO
));
380 /* setup parameters correctly */
382 /* calculate the lnb_drift */
383 fepriv
->lnb_drift
= fepriv
->auto_step
* fepriv
->step_size
;
385 /* wrap the auto_step if we've exceeded the maximum drift */
386 if (fepriv
->lnb_drift
> fepriv
->max_drift
) {
387 fepriv
->auto_step
= 0;
388 fepriv
->auto_sub_step
= 0;
389 fepriv
->lnb_drift
= 0;
392 /* perform inversion and +/- zigzag */
393 switch(fepriv
->auto_sub_step
) {
395 /* try with the current inversion and current drift setting */
400 if (!autoinversion
) break;
402 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
407 if (fepriv
->lnb_drift
== 0) break;
409 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
414 if (fepriv
->lnb_drift
== 0) break;
415 if (!autoinversion
) break;
417 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
418 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
424 fepriv
->auto_sub_step
= -1; /* it'll be incremented to 0 in a moment */
428 if (!ready
) fepriv
->auto_sub_step
++;
431 /* if this attempt would hit where we started, indicate a complete
432 * iteration has occurred */
433 if ((fepriv
->auto_step
== fepriv
->started_auto_step
) &&
434 (fepriv
->auto_sub_step
== 0) && check_wrapped
) {
438 dev_dbg(fe
->dvb
->device
, "%s: drift:%i inversion:%i auto_step:%i " \
439 "auto_sub_step:%i started_auto_step:%i\n",
440 __func__
, fepriv
->lnb_drift
, fepriv
->inversion
,
441 fepriv
->auto_step
, fepriv
->auto_sub_step
,
442 fepriv
->started_auto_step
);
444 /* set the frontend itself */
445 c
->frequency
+= fepriv
->lnb_drift
;
447 c
->inversion
= fepriv
->inversion
;
449 if (fe
->ops
.set_frontend
)
450 fe_set_err
= fe
->ops
.set_frontend(fe
);
452 if (fe_set_err
< 0) {
453 fepriv
->state
= FESTATE_ERROR
;
457 c
->frequency
= original_frequency
;
458 c
->inversion
= original_inversion
;
460 fepriv
->auto_sub_step
++;
464 static void dvb_frontend_swzigzag(struct dvb_frontend
*fe
)
466 enum fe_status s
= 0;
468 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
469 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
471 /* if we've got no parameters, just keep idling */
472 if (fepriv
->state
& FESTATE_IDLE
) {
473 fepriv
->delay
= 3*HZ
;
478 /* in SCAN mode, we just set the frontend when asked and leave it alone */
479 if (fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
) {
480 if (fepriv
->state
& FESTATE_RETUNE
) {
482 if (fe
->ops
.set_frontend
)
483 retval
= fe
->ops
.set_frontend(fe
);
486 fepriv
->state
= FESTATE_ERROR
;
488 fepriv
->state
= FESTATE_TUNED
;
490 fepriv
->delay
= 3*HZ
;
495 /* get the frontend status */
496 if (fepriv
->state
& FESTATE_RETUNE
) {
499 if (fe
->ops
.read_status
)
500 fe
->ops
.read_status(fe
, &s
);
501 if (s
!= fepriv
->status
) {
502 dvb_frontend_add_event(fe
, s
);
507 /* if we're not tuned, and we have a lock, move to the TUNED state */
508 if ((fepriv
->state
& FESTATE_WAITFORLOCK
) && (s
& FE_HAS_LOCK
)) {
509 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
510 fepriv
->state
= FESTATE_TUNED
;
512 /* if we're tuned, then we have determined the correct inversion */
513 if ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
514 (c
->inversion
== INVERSION_AUTO
)) {
515 c
->inversion
= fepriv
->inversion
;
520 /* if we are tuned already, check we're still locked */
521 if (fepriv
->state
& FESTATE_TUNED
) {
522 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
524 /* we're tuned, and the lock is still good... */
525 if (s
& FE_HAS_LOCK
) {
527 } else { /* if we _WERE_ tuned, but now don't have a lock */
528 fepriv
->state
= FESTATE_ZIGZAG_FAST
;
529 fepriv
->started_auto_step
= fepriv
->auto_step
;
530 fepriv
->check_wrapped
= 0;
534 /* don't actually do anything if we're in the LOSTLOCK state,
535 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
536 if ((fepriv
->state
& FESTATE_LOSTLOCK
) &&
537 (fe
->ops
.info
.caps
& FE_CAN_RECOVER
) && (fepriv
->max_drift
== 0)) {
538 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
542 /* don't do anything if we're in the DISEQC state, since this
543 * might be someone with a motorized dish controlled by DISEQC.
544 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
545 if (fepriv
->state
& FESTATE_DISEQC
) {
546 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
550 /* if we're in the RETUNE state, set everything up for a brand
551 * new scan, keeping the current inversion setting, as the next
552 * tune is _very_ likely to require the same */
553 if (fepriv
->state
& FESTATE_RETUNE
) {
554 fepriv
->lnb_drift
= 0;
555 fepriv
->auto_step
= 0;
556 fepriv
->auto_sub_step
= 0;
557 fepriv
->started_auto_step
= 0;
558 fepriv
->check_wrapped
= 0;
562 if ((fepriv
->state
& FESTATE_SEARCHING_FAST
) || (fepriv
->state
& FESTATE_RETUNE
)) {
563 fepriv
->delay
= fepriv
->min_delay
;
566 retval
= dvb_frontend_swzigzag_autotune(fe
,
567 fepriv
->check_wrapped
);
571 /* OK, if we've run out of trials at the fast speed.
572 * Drop back to slow for the _next_ attempt */
573 fepriv
->state
= FESTATE_SEARCHING_SLOW
;
574 fepriv
->started_auto_step
= fepriv
->auto_step
;
577 fepriv
->check_wrapped
= 1;
579 /* if we've just retuned, enter the ZIGZAG_FAST state.
580 * This ensures we cannot return from an
581 * FE_SET_FRONTEND ioctl before the first frontend tune
583 if (fepriv
->state
& FESTATE_RETUNE
) {
584 fepriv
->state
= FESTATE_TUNING_FAST
;
589 if (fepriv
->state
& FESTATE_SEARCHING_SLOW
) {
590 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
592 /* Note: don't bother checking for wrapping; we stay in this
593 * state until we get a lock */
594 dvb_frontend_swzigzag_autotune(fe
, 0);
598 static int dvb_frontend_is_exiting(struct dvb_frontend
*fe
)
600 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
602 if (fe
->exit
!= DVB_FE_NO_EXIT
)
605 if (fepriv
->dvbdev
->writers
== 1)
606 if (time_after_eq(jiffies
, fepriv
->release_jiffies
+
607 dvb_shutdown_timeout
* HZ
))
613 static int dvb_frontend_should_wakeup(struct dvb_frontend
*fe
)
615 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
617 if (fepriv
->wakeup
) {
621 return dvb_frontend_is_exiting(fe
);
624 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
)
626 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
629 wake_up_interruptible(&fepriv
->wait_queue
);
632 static int dvb_frontend_thread(void *data
)
634 struct dvb_frontend
*fe
= data
;
635 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
636 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
638 enum dvbfe_algo algo
;
639 bool re_tune
= false;
640 bool semheld
= false;
642 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
644 fepriv
->check_wrapped
= 0;
646 fepriv
->delay
= 3*HZ
;
649 fepriv
->reinitialise
= 0;
651 dvb_frontend_init(fe
);
655 up(&fepriv
->sem
); /* is locked when we enter the thread... */
657 wait_event_interruptible_timeout(fepriv
->wait_queue
,
658 dvb_frontend_should_wakeup(fe
) || kthread_should_stop()
659 || freezing(current
),
662 if (kthread_should_stop() || dvb_frontend_is_exiting(fe
)) {
663 /* got signal or quitting */
664 if (!down_interruptible(&fepriv
->sem
))
666 fe
->exit
= DVB_FE_NORMAL_EXIT
;
673 if (down_interruptible(&fepriv
->sem
))
676 if (fepriv
->reinitialise
) {
677 dvb_frontend_init(fe
);
678 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
679 fe
->ops
.set_tone(fe
, fepriv
->tone
);
680 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
681 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
682 fepriv
->reinitialise
= 0;
685 /* do an iteration of the tuning loop */
686 if (fe
->ops
.get_frontend_algo
) {
687 algo
= fe
->ops
.get_frontend_algo(fe
);
690 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__
);
692 if (fepriv
->state
& FESTATE_RETUNE
) {
693 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTATE_RETUNE\n", __func__
);
695 fepriv
->state
= FESTATE_TUNED
;
701 fe
->ops
.tune(fe
, re_tune
, fepriv
->tune_mode_flags
, &fepriv
->delay
, &s
);
703 if (s
!= fepriv
->status
&& !(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
)) {
704 dev_dbg(fe
->dvb
->device
, "%s: state changed, adding current state\n", __func__
);
705 dvb_frontend_add_event(fe
, s
);
710 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__
);
711 dvb_frontend_swzigzag(fe
);
713 case DVBFE_ALGO_CUSTOM
:
714 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__
, fepriv
->state
);
715 if (fepriv
->state
& FESTATE_RETUNE
) {
716 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTAT_RETUNE\n", __func__
);
717 fepriv
->state
= FESTATE_TUNED
;
719 /* Case where we are going to search for a carrier
720 * User asked us to retune again for some reason, possibly
721 * requesting a search with a new set of parameters
723 if (fepriv
->algo_status
& DVBFE_ALGO_SEARCH_AGAIN
) {
724 if (fe
->ops
.search
) {
725 fepriv
->algo_status
= fe
->ops
.search(fe
);
726 /* We did do a search as was requested, the flags are
727 * now unset as well and has the flags wrt to search.
730 fepriv
->algo_status
&= ~DVBFE_ALGO_SEARCH_AGAIN
;
733 /* Track the carrier if the search was successful */
734 if (fepriv
->algo_status
!= DVBFE_ALGO_SEARCH_SUCCESS
) {
735 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
736 fepriv
->delay
= HZ
/ 2;
738 dtv_property_legacy_params_sync(fe
, c
, &fepriv
->parameters_out
);
739 fe
->ops
.read_status(fe
, &s
);
740 if (s
!= fepriv
->status
) {
741 dvb_frontend_add_event(fe
, s
); /* update event list */
743 if (!(s
& FE_HAS_LOCK
)) {
744 fepriv
->delay
= HZ
/ 10;
745 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
747 fepriv
->delay
= 60 * HZ
;
752 dev_dbg(fe
->dvb
->device
, "%s: UNDEFINED ALGO !\n", __func__
);
756 dvb_frontend_swzigzag(fe
);
760 if (dvb_powerdown_on_sleep
) {
761 if (fe
->ops
.set_voltage
)
762 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_OFF
);
763 if (fe
->ops
.tuner_ops
.sleep
) {
764 if (fe
->ops
.i2c_gate_ctrl
)
765 fe
->ops
.i2c_gate_ctrl(fe
, 1);
766 fe
->ops
.tuner_ops
.sleep(fe
);
767 if (fe
->ops
.i2c_gate_ctrl
)
768 fe
->ops
.i2c_gate_ctrl(fe
, 0);
774 fepriv
->thread
= NULL
;
775 if (kthread_should_stop())
776 fe
->exit
= DVB_FE_DEVICE_REMOVED
;
778 fe
->exit
= DVB_FE_NO_EXIT
;
783 dvb_frontend_wakeup(fe
);
787 static void dvb_frontend_stop(struct dvb_frontend
*fe
)
789 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
791 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
793 if (fe
->exit
!= DVB_FE_DEVICE_REMOVED
)
794 fe
->exit
= DVB_FE_NORMAL_EXIT
;
800 kthread_stop(fepriv
->thread
);
802 sema_init(&fepriv
->sem
, 1);
803 fepriv
->state
= FESTATE_IDLE
;
805 /* paranoia check in case a signal arrived */
807 dev_warn(fe
->dvb
->device
,
808 "dvb_frontend_stop: warning: thread %p won't exit\n",
813 * Sleep for the amount of time given by add_usec parameter
815 * This needs to be as precise as possible, as it affects the detection of
816 * the dish tone command at the satellite subsystem. The precision is improved
817 * by using a scheduled msleep followed by udelay for the remainder.
819 void dvb_frontend_sleep_until(ktime_t
*waketime
, u32 add_usec
)
823 *waketime
= ktime_add_us(*waketime
, add_usec
);
824 delta
= ktime_us_delta(ktime_get_boottime(), *waketime
);
826 msleep((delta
- 1500) / 1000);
827 delta
= ktime_us_delta(ktime_get_boottime(), *waketime
);
832 EXPORT_SYMBOL(dvb_frontend_sleep_until
);
834 static int dvb_frontend_start(struct dvb_frontend
*fe
)
837 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
838 struct task_struct
*fe_thread
;
840 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
842 if (fepriv
->thread
) {
843 if (fe
->exit
== DVB_FE_NO_EXIT
)
846 dvb_frontend_stop (fe
);
849 if (signal_pending(current
))
851 if (down_interruptible (&fepriv
->sem
))
854 fepriv
->state
= FESTATE_IDLE
;
855 fe
->exit
= DVB_FE_NO_EXIT
;
856 fepriv
->thread
= NULL
;
859 fe_thread
= kthread_run(dvb_frontend_thread
, fe
,
860 "kdvb-ad-%i-fe-%i", fe
->dvb
->num
,fe
->id
);
861 if (IS_ERR(fe_thread
)) {
862 ret
= PTR_ERR(fe_thread
);
863 dev_warn(fe
->dvb
->device
,
864 "dvb_frontend_start: failed to start kthread (%d)\n",
869 fepriv
->thread
= fe_thread
;
873 static void dvb_frontend_get_frequency_limits(struct dvb_frontend
*fe
,
874 u32
*freq_min
, u32
*freq_max
)
876 *freq_min
= max(fe
->ops
.info
.frequency_min
, fe
->ops
.tuner_ops
.info
.frequency_min
);
878 if (fe
->ops
.info
.frequency_max
== 0)
879 *freq_max
= fe
->ops
.tuner_ops
.info
.frequency_max
;
880 else if (fe
->ops
.tuner_ops
.info
.frequency_max
== 0)
881 *freq_max
= fe
->ops
.info
.frequency_max
;
883 *freq_max
= min(fe
->ops
.info
.frequency_max
, fe
->ops
.tuner_ops
.info
.frequency_max
);
885 if (*freq_min
== 0 || *freq_max
== 0)
886 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
887 fe
->dvb
->num
, fe
->id
);
890 static int dvb_frontend_check_parameters(struct dvb_frontend
*fe
)
892 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
896 /* range check: frequency */
897 dvb_frontend_get_frequency_limits(fe
, &freq_min
, &freq_max
);
898 if ((freq_min
&& c
->frequency
< freq_min
) ||
899 (freq_max
&& c
->frequency
> freq_max
)) {
900 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
901 fe
->dvb
->num
, fe
->id
, c
->frequency
,
906 /* range check: symbol rate */
907 switch (c
->delivery_system
) {
911 case SYS_DVBC_ANNEX_A
:
912 case SYS_DVBC_ANNEX_C
:
913 if ((fe
->ops
.info
.symbol_rate_min
&&
914 c
->symbol_rate
< fe
->ops
.info
.symbol_rate_min
) ||
915 (fe
->ops
.info
.symbol_rate_max
&&
916 c
->symbol_rate
> fe
->ops
.info
.symbol_rate_max
)) {
917 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
918 fe
->dvb
->num
, fe
->id
, c
->symbol_rate
,
919 fe
->ops
.info
.symbol_rate_min
,
920 fe
->ops
.info
.symbol_rate_max
);
930 static int dvb_frontend_clear_cache(struct dvb_frontend
*fe
)
932 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
936 delsys
= c
->delivery_system
;
937 memset(c
, 0, offsetof(struct dtv_frontend_properties
, strength
));
938 c
->delivery_system
= delsys
;
940 c
->state
= DTV_CLEAR
;
942 dev_dbg(fe
->dvb
->device
, "%s: Clearing cache for delivery system %d\n",
943 __func__
, c
->delivery_system
);
945 c
->transmission_mode
= TRANSMISSION_MODE_AUTO
;
946 c
->bandwidth_hz
= 0; /* AUTO */
947 c
->guard_interval
= GUARD_INTERVAL_AUTO
;
948 c
->hierarchy
= HIERARCHY_AUTO
;
950 c
->code_rate_HP
= FEC_AUTO
;
951 c
->code_rate_LP
= FEC_AUTO
;
952 c
->fec_inner
= FEC_AUTO
;
953 c
->rolloff
= ROLLOFF_AUTO
;
954 c
->voltage
= SEC_VOLTAGE_OFF
;
955 c
->sectone
= SEC_TONE_OFF
;
956 c
->pilot
= PILOT_AUTO
;
958 c
->isdbt_partial_reception
= 0;
959 c
->isdbt_sb_mode
= 0;
960 c
->isdbt_sb_subchannel
= 0;
961 c
->isdbt_sb_segment_idx
= 0;
962 c
->isdbt_sb_segment_count
= 0;
963 c
->isdbt_layer_enabled
= 0;
964 for (i
= 0; i
< 3; i
++) {
965 c
->layer
[i
].fec
= FEC_AUTO
;
966 c
->layer
[i
].modulation
= QAM_AUTO
;
967 c
->layer
[i
].interleaving
= 0;
968 c
->layer
[i
].segment_count
= 0;
971 c
->stream_id
= NO_STREAM_ID_FILTER
;
973 switch (c
->delivery_system
) {
977 c
->modulation
= QPSK
; /* implied for DVB-S in legacy API */
978 c
->rolloff
= ROLLOFF_35
;/* implied for DVB-S */
981 c
->modulation
= VSB_8
;
984 c
->symbol_rate
= 28860000;
985 c
->rolloff
= ROLLOFF_35
;
986 c
->bandwidth_hz
= c
->symbol_rate
/ 100 * 135;
989 c
->modulation
= QAM_AUTO
;
998 #define _DTV_CMD(n, s, b) \
1006 static struct dtv_cmds_h dtv_cmds
[DTV_MAX_COMMAND
+ 1] = {
1007 _DTV_CMD(DTV_TUNE
, 1, 0),
1008 _DTV_CMD(DTV_CLEAR
, 1, 0),
1011 _DTV_CMD(DTV_FREQUENCY
, 1, 0),
1012 _DTV_CMD(DTV_BANDWIDTH_HZ
, 1, 0),
1013 _DTV_CMD(DTV_MODULATION
, 1, 0),
1014 _DTV_CMD(DTV_INVERSION
, 1, 0),
1015 _DTV_CMD(DTV_DISEQC_MASTER
, 1, 1),
1016 _DTV_CMD(DTV_SYMBOL_RATE
, 1, 0),
1017 _DTV_CMD(DTV_INNER_FEC
, 1, 0),
1018 _DTV_CMD(DTV_VOLTAGE
, 1, 0),
1019 _DTV_CMD(DTV_TONE
, 1, 0),
1020 _DTV_CMD(DTV_PILOT
, 1, 0),
1021 _DTV_CMD(DTV_ROLLOFF
, 1, 0),
1022 _DTV_CMD(DTV_DELIVERY_SYSTEM
, 1, 0),
1023 _DTV_CMD(DTV_HIERARCHY
, 1, 0),
1024 _DTV_CMD(DTV_CODE_RATE_HP
, 1, 0),
1025 _DTV_CMD(DTV_CODE_RATE_LP
, 1, 0),
1026 _DTV_CMD(DTV_GUARD_INTERVAL
, 1, 0),
1027 _DTV_CMD(DTV_TRANSMISSION_MODE
, 1, 0),
1028 _DTV_CMD(DTV_INTERLEAVING
, 1, 0),
1030 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION
, 1, 0),
1031 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING
, 1, 0),
1032 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID
, 1, 0),
1033 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX
, 1, 0),
1034 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT
, 1, 0),
1035 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED
, 1, 0),
1036 _DTV_CMD(DTV_ISDBT_LAYERA_FEC
, 1, 0),
1037 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION
, 1, 0),
1038 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT
, 1, 0),
1039 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING
, 1, 0),
1040 _DTV_CMD(DTV_ISDBT_LAYERB_FEC
, 1, 0),
1041 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION
, 1, 0),
1042 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT
, 1, 0),
1043 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING
, 1, 0),
1044 _DTV_CMD(DTV_ISDBT_LAYERC_FEC
, 1, 0),
1045 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION
, 1, 0),
1046 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT
, 1, 0),
1047 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING
, 1, 0),
1049 _DTV_CMD(DTV_STREAM_ID
, 1, 0),
1050 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY
, 1, 0),
1051 _DTV_CMD(DTV_LNA
, 1, 0),
1054 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY
, 0, 1),
1055 _DTV_CMD(DTV_API_VERSION
, 0, 0),
1057 _DTV_CMD(DTV_ENUM_DELSYS
, 0, 0),
1059 _DTV_CMD(DTV_ATSCMH_PARADE_ID
, 1, 0),
1060 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE
, 1, 0),
1062 _DTV_CMD(DTV_ATSCMH_FIC_VER
, 0, 0),
1063 _DTV_CMD(DTV_ATSCMH_NOG
, 0, 0),
1064 _DTV_CMD(DTV_ATSCMH_TNOG
, 0, 0),
1065 _DTV_CMD(DTV_ATSCMH_SGN
, 0, 0),
1066 _DTV_CMD(DTV_ATSCMH_PRC
, 0, 0),
1067 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE
, 0, 0),
1068 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI
, 0, 0),
1069 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC
, 0, 0),
1070 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE
, 0, 0),
1071 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A
, 0, 0),
1072 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B
, 0, 0),
1073 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C
, 0, 0),
1074 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D
, 0, 0),
1076 /* Statistics API */
1077 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH
, 0, 0),
1078 _DTV_CMD(DTV_STAT_CNR
, 0, 0),
1079 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT
, 0, 0),
1080 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT
, 0, 0),
1081 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT
, 0, 0),
1082 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT
, 0, 0),
1083 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT
, 0, 0),
1084 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT
, 0, 0),
1087 static void dtv_property_dump(struct dvb_frontend
*fe
,
1089 struct dtv_property
*tvp
)
1093 if (tvp
->cmd
<= 0 || tvp
->cmd
> DTV_MAX_COMMAND
) {
1094 dev_warn(fe
->dvb
->device
, "%s: %s tvp.cmd = 0x%08x undefined\n",
1096 is_set
? "SET" : "GET",
1101 dev_dbg(fe
->dvb
->device
, "%s: %s tvp.cmd = 0x%08x (%s)\n", __func__
,
1102 is_set
? "SET" : "GET",
1104 dtv_cmds
[tvp
->cmd
].name
);
1106 if (dtv_cmds
[tvp
->cmd
].buffer
) {
1107 dev_dbg(fe
->dvb
->device
, "%s: tvp.u.buffer.len = 0x%02x\n",
1108 __func__
, tvp
->u
.buffer
.len
);
1110 for(i
= 0; i
< tvp
->u
.buffer
.len
; i
++)
1111 dev_dbg(fe
->dvb
->device
,
1112 "%s: tvp.u.buffer.data[0x%02x] = 0x%02x\n",
1113 __func__
, i
, tvp
->u
.buffer
.data
[i
]);
1115 dev_dbg(fe
->dvb
->device
, "%s: tvp.u.data = 0x%08x\n", __func__
,
1120 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1121 * drivers can use a single set_frontend tuning function, regardless of whether
1122 * it's being used for the legacy or new API, reducing code and complexity.
1124 static int dtv_property_cache_sync(struct dvb_frontend
*fe
,
1125 struct dtv_frontend_properties
*c
,
1126 const struct dvb_frontend_parameters
*p
)
1128 c
->frequency
= p
->frequency
;
1129 c
->inversion
= p
->inversion
;
1131 switch (dvbv3_type(c
->delivery_system
)) {
1133 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1134 c
->symbol_rate
= p
->u
.qpsk
.symbol_rate
;
1135 c
->fec_inner
= p
->u
.qpsk
.fec_inner
;
1138 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1139 c
->symbol_rate
= p
->u
.qam
.symbol_rate
;
1140 c
->fec_inner
= p
->u
.qam
.fec_inner
;
1141 c
->modulation
= p
->u
.qam
.modulation
;
1144 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1146 switch (p
->u
.ofdm
.bandwidth
) {
1147 case BANDWIDTH_10_MHZ
:
1148 c
->bandwidth_hz
= 10000000;
1150 case BANDWIDTH_8_MHZ
:
1151 c
->bandwidth_hz
= 8000000;
1153 case BANDWIDTH_7_MHZ
:
1154 c
->bandwidth_hz
= 7000000;
1156 case BANDWIDTH_6_MHZ
:
1157 c
->bandwidth_hz
= 6000000;
1159 case BANDWIDTH_5_MHZ
:
1160 c
->bandwidth_hz
= 5000000;
1162 case BANDWIDTH_1_712_MHZ
:
1163 c
->bandwidth_hz
= 1712000;
1165 case BANDWIDTH_AUTO
:
1166 c
->bandwidth_hz
= 0;
1169 c
->code_rate_HP
= p
->u
.ofdm
.code_rate_HP
;
1170 c
->code_rate_LP
= p
->u
.ofdm
.code_rate_LP
;
1171 c
->modulation
= p
->u
.ofdm
.constellation
;
1172 c
->transmission_mode
= p
->u
.ofdm
.transmission_mode
;
1173 c
->guard_interval
= p
->u
.ofdm
.guard_interval
;
1174 c
->hierarchy
= p
->u
.ofdm
.hierarchy_information
;
1177 dev_dbg(fe
->dvb
->device
, "%s: Preparing ATSC req\n", __func__
);
1178 c
->modulation
= p
->u
.vsb
.modulation
;
1179 if (c
->delivery_system
== SYS_ATSCMH
)
1181 if ((c
->modulation
== VSB_8
) || (c
->modulation
== VSB_16
))
1182 c
->delivery_system
= SYS_ATSC
;
1184 c
->delivery_system
= SYS_DVBC_ANNEX_B
;
1187 dev_err(fe
->dvb
->device
,
1188 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1189 __func__
, c
->delivery_system
);
1196 /* Ensure the cached values are set correctly in the frontend
1197 * legacy tuning structures, for the advanced tuning API.
1200 dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
1201 const struct dtv_frontend_properties
*c
,
1202 struct dvb_frontend_parameters
*p
)
1204 p
->frequency
= c
->frequency
;
1205 p
->inversion
= c
->inversion
;
1207 switch (dvbv3_type(c
->delivery_system
)) {
1209 dev_err(fe
->dvb
->device
,
1210 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1211 __func__
, c
->delivery_system
);
1214 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1215 p
->u
.qpsk
.symbol_rate
= c
->symbol_rate
;
1216 p
->u
.qpsk
.fec_inner
= c
->fec_inner
;
1219 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1220 p
->u
.qam
.symbol_rate
= c
->symbol_rate
;
1221 p
->u
.qam
.fec_inner
= c
->fec_inner
;
1222 p
->u
.qam
.modulation
= c
->modulation
;
1225 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1226 switch (c
->bandwidth_hz
) {
1228 p
->u
.ofdm
.bandwidth
= BANDWIDTH_10_MHZ
;
1231 p
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
1234 p
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
1237 p
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
1240 p
->u
.ofdm
.bandwidth
= BANDWIDTH_5_MHZ
;
1243 p
->u
.ofdm
.bandwidth
= BANDWIDTH_1_712_MHZ
;
1247 p
->u
.ofdm
.bandwidth
= BANDWIDTH_AUTO
;
1249 p
->u
.ofdm
.code_rate_HP
= c
->code_rate_HP
;
1250 p
->u
.ofdm
.code_rate_LP
= c
->code_rate_LP
;
1251 p
->u
.ofdm
.constellation
= c
->modulation
;
1252 p
->u
.ofdm
.transmission_mode
= c
->transmission_mode
;
1253 p
->u
.ofdm
.guard_interval
= c
->guard_interval
;
1254 p
->u
.ofdm
.hierarchy_information
= c
->hierarchy
;
1257 dev_dbg(fe
->dvb
->device
, "%s: Preparing VSB req\n", __func__
);
1258 p
->u
.vsb
.modulation
= c
->modulation
;
1265 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1266 * @fe: struct dvb_frontend pointer
1267 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1268 * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1270 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1271 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1272 * If p_out is not null, it will update the DVBv3 params pointed by it.
1274 static int dtv_get_frontend(struct dvb_frontend
*fe
,
1275 struct dtv_frontend_properties
*c
,
1276 struct dvb_frontend_parameters
*p_out
)
1280 if (fe
->ops
.get_frontend
) {
1281 r
= fe
->ops
.get_frontend(fe
, c
);
1282 if (unlikely(r
< 0))
1285 dtv_property_legacy_params_sync(fe
, c
, p_out
);
1289 /* As everything is in cache, get_frontend fops are always supported */
1293 static int dvb_frontend_ioctl_legacy(struct file
*file
,
1294 unsigned int cmd
, void *parg
);
1295 static int dvb_frontend_ioctl_properties(struct file
*file
,
1296 unsigned int cmd
, void *parg
);
1298 static int dtv_property_process_get(struct dvb_frontend
*fe
,
1299 const struct dtv_frontend_properties
*c
,
1300 struct dtv_property
*tvp
,
1306 case DTV_ENUM_DELSYS
:
1308 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1309 tvp
->u
.buffer
.data
[ncaps
] = fe
->ops
.delsys
[ncaps
];
1312 tvp
->u
.buffer
.len
= ncaps
;
1315 tvp
->u
.data
= c
->frequency
;
1317 case DTV_MODULATION
:
1318 tvp
->u
.data
= c
->modulation
;
1320 case DTV_BANDWIDTH_HZ
:
1321 tvp
->u
.data
= c
->bandwidth_hz
;
1324 tvp
->u
.data
= c
->inversion
;
1326 case DTV_SYMBOL_RATE
:
1327 tvp
->u
.data
= c
->symbol_rate
;
1330 tvp
->u
.data
= c
->fec_inner
;
1333 tvp
->u
.data
= c
->pilot
;
1336 tvp
->u
.data
= c
->rolloff
;
1338 case DTV_DELIVERY_SYSTEM
:
1339 tvp
->u
.data
= c
->delivery_system
;
1342 tvp
->u
.data
= c
->voltage
;
1345 tvp
->u
.data
= c
->sectone
;
1347 case DTV_API_VERSION
:
1348 tvp
->u
.data
= (DVB_API_VERSION
<< 8) | DVB_API_VERSION_MINOR
;
1350 case DTV_CODE_RATE_HP
:
1351 tvp
->u
.data
= c
->code_rate_HP
;
1353 case DTV_CODE_RATE_LP
:
1354 tvp
->u
.data
= c
->code_rate_LP
;
1356 case DTV_GUARD_INTERVAL
:
1357 tvp
->u
.data
= c
->guard_interval
;
1359 case DTV_TRANSMISSION_MODE
:
1360 tvp
->u
.data
= c
->transmission_mode
;
1363 tvp
->u
.data
= c
->hierarchy
;
1365 case DTV_INTERLEAVING
:
1366 tvp
->u
.data
= c
->interleaving
;
1369 /* ISDB-T Support here */
1370 case DTV_ISDBT_PARTIAL_RECEPTION
:
1371 tvp
->u
.data
= c
->isdbt_partial_reception
;
1373 case DTV_ISDBT_SOUND_BROADCASTING
:
1374 tvp
->u
.data
= c
->isdbt_sb_mode
;
1376 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1377 tvp
->u
.data
= c
->isdbt_sb_subchannel
;
1379 case DTV_ISDBT_SB_SEGMENT_IDX
:
1380 tvp
->u
.data
= c
->isdbt_sb_segment_idx
;
1382 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1383 tvp
->u
.data
= c
->isdbt_sb_segment_count
;
1385 case DTV_ISDBT_LAYER_ENABLED
:
1386 tvp
->u
.data
= c
->isdbt_layer_enabled
;
1388 case DTV_ISDBT_LAYERA_FEC
:
1389 tvp
->u
.data
= c
->layer
[0].fec
;
1391 case DTV_ISDBT_LAYERA_MODULATION
:
1392 tvp
->u
.data
= c
->layer
[0].modulation
;
1394 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1395 tvp
->u
.data
= c
->layer
[0].segment_count
;
1397 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1398 tvp
->u
.data
= c
->layer
[0].interleaving
;
1400 case DTV_ISDBT_LAYERB_FEC
:
1401 tvp
->u
.data
= c
->layer
[1].fec
;
1403 case DTV_ISDBT_LAYERB_MODULATION
:
1404 tvp
->u
.data
= c
->layer
[1].modulation
;
1406 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1407 tvp
->u
.data
= c
->layer
[1].segment_count
;
1409 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1410 tvp
->u
.data
= c
->layer
[1].interleaving
;
1412 case DTV_ISDBT_LAYERC_FEC
:
1413 tvp
->u
.data
= c
->layer
[2].fec
;
1415 case DTV_ISDBT_LAYERC_MODULATION
:
1416 tvp
->u
.data
= c
->layer
[2].modulation
;
1418 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1419 tvp
->u
.data
= c
->layer
[2].segment_count
;
1421 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1422 tvp
->u
.data
= c
->layer
[2].interleaving
;
1425 /* Multistream support */
1427 case DTV_DVBT2_PLP_ID_LEGACY
:
1428 tvp
->u
.data
= c
->stream_id
;
1432 case DTV_ATSCMH_FIC_VER
:
1433 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_fic_ver
;
1435 case DTV_ATSCMH_PARADE_ID
:
1436 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_parade_id
;
1438 case DTV_ATSCMH_NOG
:
1439 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_nog
;
1441 case DTV_ATSCMH_TNOG
:
1442 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_tnog
;
1444 case DTV_ATSCMH_SGN
:
1445 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sgn
;
1447 case DTV_ATSCMH_PRC
:
1448 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_prc
;
1450 case DTV_ATSCMH_RS_FRAME_MODE
:
1451 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_mode
;
1453 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1454 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
;
1456 case DTV_ATSCMH_RS_CODE_MODE_PRI
:
1457 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_pri
;
1459 case DTV_ATSCMH_RS_CODE_MODE_SEC
:
1460 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_sec
;
1462 case DTV_ATSCMH_SCCC_BLOCK_MODE
:
1463 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_block_mode
;
1465 case DTV_ATSCMH_SCCC_CODE_MODE_A
:
1466 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_a
;
1468 case DTV_ATSCMH_SCCC_CODE_MODE_B
:
1469 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_b
;
1471 case DTV_ATSCMH_SCCC_CODE_MODE_C
:
1472 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_c
;
1474 case DTV_ATSCMH_SCCC_CODE_MODE_D
:
1475 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_d
;
1479 tvp
->u
.data
= c
->lna
;
1482 /* Fill quality measures */
1483 case DTV_STAT_SIGNAL_STRENGTH
:
1484 tvp
->u
.st
= c
->strength
;
1489 case DTV_STAT_PRE_ERROR_BIT_COUNT
:
1490 tvp
->u
.st
= c
->pre_bit_error
;
1492 case DTV_STAT_PRE_TOTAL_BIT_COUNT
:
1493 tvp
->u
.st
= c
->pre_bit_count
;
1495 case DTV_STAT_POST_ERROR_BIT_COUNT
:
1496 tvp
->u
.st
= c
->post_bit_error
;
1498 case DTV_STAT_POST_TOTAL_BIT_COUNT
:
1499 tvp
->u
.st
= c
->post_bit_count
;
1501 case DTV_STAT_ERROR_BLOCK_COUNT
:
1502 tvp
->u
.st
= c
->block_error
;
1504 case DTV_STAT_TOTAL_BLOCK_COUNT
:
1505 tvp
->u
.st
= c
->block_count
;
1508 dev_dbg(fe
->dvb
->device
,
1509 "%s: FE property %d doesn't exist\n",
1510 __func__
, tvp
->cmd
);
1514 /* Allow the frontend to override outgoing properties */
1515 if (fe
->ops
.get_property
) {
1516 r
= fe
->ops
.get_property(fe
, tvp
);
1521 dtv_property_dump(fe
, false, tvp
);
1526 static int dtv_set_frontend(struct dvb_frontend
*fe
);
1528 static bool is_dvbv3_delsys(u32 delsys
)
1530 return (delsys
== SYS_DVBT
) || (delsys
== SYS_DVBC_ANNEX_A
) ||
1531 (delsys
== SYS_DVBS
) || (delsys
== SYS_ATSC
);
1535 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1536 * @fe: struct frontend;
1537 * @delsys: DVBv5 type that will be used for emulation
1539 * Provides emulation for delivery systems that are compatible with the old
1540 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1541 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent
1542 * parameters are compatible with DVB-S spec.
1544 static int emulate_delivery_system(struct dvb_frontend
*fe
, u32 delsys
)
1547 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1549 c
->delivery_system
= delsys
;
1552 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1554 if (c
->delivery_system
== SYS_ISDBT
) {
1555 dev_dbg(fe
->dvb
->device
,
1556 "%s: Using defaults for SYS_ISDBT\n",
1559 if (!c
->bandwidth_hz
)
1560 c
->bandwidth_hz
= 6000000;
1562 c
->isdbt_partial_reception
= 0;
1563 c
->isdbt_sb_mode
= 0;
1564 c
->isdbt_sb_subchannel
= 0;
1565 c
->isdbt_sb_segment_idx
= 0;
1566 c
->isdbt_sb_segment_count
= 0;
1567 c
->isdbt_layer_enabled
= 7;
1568 for (i
= 0; i
< 3; i
++) {
1569 c
->layer
[i
].fec
= FEC_AUTO
;
1570 c
->layer
[i
].modulation
= QAM_AUTO
;
1571 c
->layer
[i
].interleaving
= 0;
1572 c
->layer
[i
].segment_count
= 0;
1575 dev_dbg(fe
->dvb
->device
, "%s: change delivery system on cache to %d\n",
1576 __func__
, c
->delivery_system
);
1582 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1583 * @fe: frontend struct
1584 * @desired_system: delivery system requested by the user
1586 * A DVBv5 call know what's the desired system it wants. So, set it.
1588 * There are, however, a few known issues with early DVBv5 applications that
1589 * are also handled by this logic:
1591 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1592 * This is an API violation, but, as we don't want to break userspace,
1593 * convert it to the first supported delivery system.
1594 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1595 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1596 * ISDB-T provided backward compat with DVB-T.
1598 static int dvbv5_set_delivery_system(struct dvb_frontend
*fe
,
1602 u32 delsys
= SYS_UNDEFINED
;
1603 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1604 enum dvbv3_emulation_type type
;
1607 * It was reported that some old DVBv5 applications were
1608 * filling delivery_system with SYS_UNDEFINED. If this happens,
1609 * assume that the application wants to use the first supported
1612 if (desired_system
== SYS_UNDEFINED
)
1613 desired_system
= fe
->ops
.delsys
[0];
1616 * This is a DVBv5 call. So, it likely knows the supported
1617 * delivery systems. So, check if the desired delivery system is
1621 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1622 if (fe
->ops
.delsys
[ncaps
] == desired_system
) {
1623 c
->delivery_system
= desired_system
;
1624 dev_dbg(fe
->dvb
->device
,
1625 "%s: Changing delivery system to %d\n",
1626 __func__
, desired_system
);
1633 * The requested delivery system isn't supported. Maybe userspace
1634 * is requesting a DVBv3 compatible delivery system.
1636 * The emulation only works if the desired system is one of the
1637 * delivery systems supported by DVBv3 API
1639 if (!is_dvbv3_delsys(desired_system
)) {
1640 dev_dbg(fe
->dvb
->device
,
1641 "%s: Delivery system %d not supported.\n",
1642 __func__
, desired_system
);
1646 type
= dvbv3_type(desired_system
);
1649 * Get the last non-DVBv3 delivery system that has the same type
1650 * of the desired system
1653 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1654 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) == type
)
1655 delsys
= fe
->ops
.delsys
[ncaps
];
1659 /* There's nothing compatible with the desired delivery system */
1660 if (delsys
== SYS_UNDEFINED
) {
1661 dev_dbg(fe
->dvb
->device
,
1662 "%s: Delivery system %d not supported on emulation mode.\n",
1663 __func__
, desired_system
);
1667 dev_dbg(fe
->dvb
->device
,
1668 "%s: Using delivery system %d emulated as if it were %d\n",
1669 __func__
, delsys
, desired_system
);
1671 return emulate_delivery_system(fe
, desired_system
);
1675 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1676 * @fe: frontend struct
1678 * A DVBv3 call doesn't know what's the desired system it wants. It also
1679 * doesn't allow to switch between different types. Due to that, userspace
1680 * should use DVBv5 instead.
1681 * However, in order to avoid breaking userspace API, limited backward
1682 * compatibility support is provided.
1684 * There are some delivery systems that are incompatible with DVBv3 calls.
1686 * This routine should work fine for frontends that support just one delivery
1689 * For frontends that support multiple frontends:
1690 * 1) It defaults to use the first supported delivery system. There's an
1691 * userspace application that allows changing it at runtime;
1693 * 2) If the current delivery system is not compatible with DVBv3, it gets
1694 * the first one that it is compatible.
1696 * NOTE: in order for this to work with applications like Kaffeine that
1697 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1698 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1699 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1702 static int dvbv3_set_delivery_system(struct dvb_frontend
*fe
)
1705 u32 delsys
= SYS_UNDEFINED
;
1706 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1708 /* If not set yet, defaults to the first supported delivery system */
1709 if (c
->delivery_system
== SYS_UNDEFINED
)
1710 c
->delivery_system
= fe
->ops
.delsys
[0];
1713 * Trivial case: just use the current one, if it already a DVBv3
1716 if (is_dvbv3_delsys(c
->delivery_system
)) {
1717 dev_dbg(fe
->dvb
->device
,
1718 "%s: Using delivery system to %d\n",
1719 __func__
, c
->delivery_system
);
1724 * Seek for the first delivery system that it is compatible with a
1728 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1729 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) != DVBV3_UNKNOWN
) {
1730 delsys
= fe
->ops
.delsys
[ncaps
];
1735 if (delsys
== SYS_UNDEFINED
) {
1736 dev_dbg(fe
->dvb
->device
,
1737 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1741 return emulate_delivery_system(fe
, delsys
);
1744 static int dtv_property_process_set(struct dvb_frontend
*fe
,
1745 struct dtv_property
*tvp
,
1749 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1751 /* Allow the frontend to validate incoming properties */
1752 if (fe
->ops
.set_property
) {
1753 r
= fe
->ops
.set_property(fe
, tvp
);
1758 dtv_property_dump(fe
, true, tvp
);
1763 * Reset a cache of data specific to the frontend here. This does
1764 * not effect hardware.
1766 dvb_frontend_clear_cache(fe
);
1769 /* interpret the cache of data, build either a traditional frontend
1770 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1773 c
->state
= tvp
->cmd
;
1774 dev_dbg(fe
->dvb
->device
, "%s: Finalised property cache\n",
1777 r
= dtv_set_frontend(fe
);
1780 c
->frequency
= tvp
->u
.data
;
1782 case DTV_MODULATION
:
1783 c
->modulation
= tvp
->u
.data
;
1785 case DTV_BANDWIDTH_HZ
:
1786 c
->bandwidth_hz
= tvp
->u
.data
;
1789 c
->inversion
= tvp
->u
.data
;
1791 case DTV_SYMBOL_RATE
:
1792 c
->symbol_rate
= tvp
->u
.data
;
1795 c
->fec_inner
= tvp
->u
.data
;
1798 c
->pilot
= tvp
->u
.data
;
1801 c
->rolloff
= tvp
->u
.data
;
1803 case DTV_DELIVERY_SYSTEM
:
1804 r
= dvbv5_set_delivery_system(fe
, tvp
->u
.data
);
1807 c
->voltage
= tvp
->u
.data
;
1808 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_VOLTAGE
,
1809 (void *)c
->voltage
);
1812 c
->sectone
= tvp
->u
.data
;
1813 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_TONE
,
1814 (void *)c
->sectone
);
1816 case DTV_CODE_RATE_HP
:
1817 c
->code_rate_HP
= tvp
->u
.data
;
1819 case DTV_CODE_RATE_LP
:
1820 c
->code_rate_LP
= tvp
->u
.data
;
1822 case DTV_GUARD_INTERVAL
:
1823 c
->guard_interval
= tvp
->u
.data
;
1825 case DTV_TRANSMISSION_MODE
:
1826 c
->transmission_mode
= tvp
->u
.data
;
1829 c
->hierarchy
= tvp
->u
.data
;
1831 case DTV_INTERLEAVING
:
1832 c
->interleaving
= tvp
->u
.data
;
1835 /* ISDB-T Support here */
1836 case DTV_ISDBT_PARTIAL_RECEPTION
:
1837 c
->isdbt_partial_reception
= tvp
->u
.data
;
1839 case DTV_ISDBT_SOUND_BROADCASTING
:
1840 c
->isdbt_sb_mode
= tvp
->u
.data
;
1842 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1843 c
->isdbt_sb_subchannel
= tvp
->u
.data
;
1845 case DTV_ISDBT_SB_SEGMENT_IDX
:
1846 c
->isdbt_sb_segment_idx
= tvp
->u
.data
;
1848 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1849 c
->isdbt_sb_segment_count
= tvp
->u
.data
;
1851 case DTV_ISDBT_LAYER_ENABLED
:
1852 c
->isdbt_layer_enabled
= tvp
->u
.data
;
1854 case DTV_ISDBT_LAYERA_FEC
:
1855 c
->layer
[0].fec
= tvp
->u
.data
;
1857 case DTV_ISDBT_LAYERA_MODULATION
:
1858 c
->layer
[0].modulation
= tvp
->u
.data
;
1860 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1861 c
->layer
[0].segment_count
= tvp
->u
.data
;
1863 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1864 c
->layer
[0].interleaving
= tvp
->u
.data
;
1866 case DTV_ISDBT_LAYERB_FEC
:
1867 c
->layer
[1].fec
= tvp
->u
.data
;
1869 case DTV_ISDBT_LAYERB_MODULATION
:
1870 c
->layer
[1].modulation
= tvp
->u
.data
;
1872 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1873 c
->layer
[1].segment_count
= tvp
->u
.data
;
1875 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1876 c
->layer
[1].interleaving
= tvp
->u
.data
;
1878 case DTV_ISDBT_LAYERC_FEC
:
1879 c
->layer
[2].fec
= tvp
->u
.data
;
1881 case DTV_ISDBT_LAYERC_MODULATION
:
1882 c
->layer
[2].modulation
= tvp
->u
.data
;
1884 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1885 c
->layer
[2].segment_count
= tvp
->u
.data
;
1887 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1888 c
->layer
[2].interleaving
= tvp
->u
.data
;
1891 /* Multistream support */
1893 case DTV_DVBT2_PLP_ID_LEGACY
:
1894 c
->stream_id
= tvp
->u
.data
;
1898 case DTV_ATSCMH_PARADE_ID
:
1899 fe
->dtv_property_cache
.atscmh_parade_id
= tvp
->u
.data
;
1901 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1902 fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
= tvp
->u
.data
;
1906 c
->lna
= tvp
->u
.data
;
1907 if (fe
->ops
.set_lna
)
1908 r
= fe
->ops
.set_lna(fe
);
1920 static int dvb_frontend_ioctl(struct file
*file
,
1921 unsigned int cmd
, void *parg
)
1923 struct dvb_device
*dvbdev
= file
->private_data
;
1924 struct dvb_frontend
*fe
= dvbdev
->priv
;
1925 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1926 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1927 int err
= -EOPNOTSUPP
;
1929 dev_dbg(fe
->dvb
->device
, "%s: (%d)\n", __func__
, _IOC_NR(cmd
));
1930 if (down_interruptible(&fepriv
->sem
))
1931 return -ERESTARTSYS
;
1933 if (fe
->exit
!= DVB_FE_NO_EXIT
) {
1938 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
&&
1939 (_IOC_DIR(cmd
) != _IOC_READ
|| cmd
== FE_GET_EVENT
||
1940 cmd
== FE_DISEQC_RECV_SLAVE_REPLY
)) {
1945 if ((cmd
== FE_SET_PROPERTY
) || (cmd
== FE_GET_PROPERTY
))
1946 err
= dvb_frontend_ioctl_properties(file
, cmd
, parg
);
1948 c
->state
= DTV_UNDEFINED
;
1949 err
= dvb_frontend_ioctl_legacy(file
, cmd
, parg
);
1956 static int dvb_frontend_ioctl_properties(struct file
*file
,
1957 unsigned int cmd
, void *parg
)
1959 struct dvb_device
*dvbdev
= file
->private_data
;
1960 struct dvb_frontend
*fe
= dvbdev
->priv
;
1961 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1962 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1965 struct dtv_properties
*tvps
= parg
;
1966 struct dtv_property
*tvp
= NULL
;
1969 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
1971 if (cmd
== FE_SET_PROPERTY
) {
1972 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n", __func__
, tvps
->num
);
1973 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n", __func__
, tvps
->props
);
1975 /* Put an arbitrary limit on the number of messages that can
1976 * be sent at once */
1977 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
1980 tvp
= memdup_user(tvps
->props
, tvps
->num
* sizeof(*tvp
));
1982 return PTR_ERR(tvp
);
1984 for (i
= 0; i
< tvps
->num
; i
++) {
1985 err
= dtv_property_process_set(fe
, tvp
+ i
, file
);
1988 (tvp
+ i
)->result
= err
;
1991 if (c
->state
== DTV_TUNE
)
1992 dev_dbg(fe
->dvb
->device
, "%s: Property cache is full, tuning\n", __func__
);
1994 } else if (cmd
== FE_GET_PROPERTY
) {
1995 struct dtv_frontend_properties getp
= fe
->dtv_property_cache
;
1997 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n", __func__
, tvps
->num
);
1998 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n", __func__
, tvps
->props
);
2000 /* Put an arbitrary limit on the number of messages that can
2001 * be sent at once */
2002 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
2005 tvp
= memdup_user(tvps
->props
, tvps
->num
* sizeof(*tvp
));
2007 return PTR_ERR(tvp
);
2010 * Let's use our own copy of property cache, in order to
2011 * avoid mangling with DTV zigzag logic, as drivers might
2012 * return crap, if they don't check if the data is available
2013 * before updating the properties cache.
2015 if (fepriv
->state
!= FESTATE_IDLE
) {
2016 err
= dtv_get_frontend(fe
, &getp
, NULL
);
2020 for (i
= 0; i
< tvps
->num
; i
++) {
2021 err
= dtv_property_process_get(fe
, &getp
, tvp
+ i
, file
);
2024 (tvp
+ i
)->result
= err
;
2027 if (copy_to_user((void __user
*)tvps
->props
, tvp
,
2028 tvps
->num
* sizeof(struct dtv_property
))) {
2041 static int dtv_set_frontend(struct dvb_frontend
*fe
)
2043 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2044 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
2045 struct dvb_frontend_tune_settings fetunesettings
;
2048 if (dvb_frontend_check_parameters(fe
) < 0)
2052 * Initialize output parameters to match the values given by
2053 * the user. FE_SET_FRONTEND triggers an initial frontend event
2054 * with status = 0, which copies output parameters to userspace.
2056 dtv_property_legacy_params_sync(fe
, c
, &fepriv
->parameters_out
);
2059 * Be sure that the bandwidth will be filled for all
2060 * non-satellite systems, as tuners need to know what
2061 * low pass/Nyquist half filter should be applied, in
2062 * order to avoid inter-channel noise.
2064 * ISDB-T and DVB-T/T2 already sets bandwidth.
2065 * ATSC and DVB-C don't set, so, the core should fill it.
2067 * On DVB-C Annex A and C, the bandwidth is a function of
2068 * the roll-off and symbol rate. Annex B defines different
2069 * roll-off factors depending on the modulation. Fortunately,
2070 * Annex B is only used with 6MHz, so there's no need to
2073 * While not officially supported, a side effect of handling it at
2074 * the cache level is that a program could retrieve the bandwidth
2075 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2077 switch (c
->delivery_system
) {
2079 case SYS_DVBC_ANNEX_B
:
2080 c
->bandwidth_hz
= 6000000;
2082 case SYS_DVBC_ANNEX_A
:
2085 case SYS_DVBC_ANNEX_C
:
2094 switch (c
->rolloff
) {
2110 c
->bandwidth_hz
= mult_frac(c
->symbol_rate
, rolloff
, 100);
2112 /* force auto frequency inversion if requested */
2113 if (dvb_force_auto_inversion
)
2114 c
->inversion
= INVERSION_AUTO
;
2117 * without hierarchical coding code_rate_LP is irrelevant,
2118 * so we tolerate the otherwise invalid FEC_NONE setting
2120 if (c
->hierarchy
== HIERARCHY_NONE
&& c
->code_rate_LP
== FEC_NONE
)
2121 c
->code_rate_LP
= FEC_AUTO
;
2123 /* get frontend-specific tuning settings */
2124 memset(&fetunesettings
, 0, sizeof(struct dvb_frontend_tune_settings
));
2125 if (fe
->ops
.get_tune_settings
&& (fe
->ops
.get_tune_settings(fe
, &fetunesettings
) == 0)) {
2126 fepriv
->min_delay
= (fetunesettings
.min_delay_ms
* HZ
) / 1000;
2127 fepriv
->max_drift
= fetunesettings
.max_drift
;
2128 fepriv
->step_size
= fetunesettings
.step_size
;
2130 /* default values */
2131 switch (c
->delivery_system
) {
2136 case SYS_DVBC_ANNEX_A
:
2137 case SYS_DVBC_ANNEX_C
:
2138 fepriv
->min_delay
= HZ
/ 20;
2139 fepriv
->step_size
= c
->symbol_rate
/ 16000;
2140 fepriv
->max_drift
= c
->symbol_rate
/ 2000;
2146 fepriv
->min_delay
= HZ
/ 20;
2147 fepriv
->step_size
= fe
->ops
.info
.frequency_stepsize
* 2;
2148 fepriv
->max_drift
= (fe
->ops
.info
.frequency_stepsize
* 2) + 1;
2152 * FIXME: This sounds wrong! if freqency_stepsize is
2153 * defined by the frontend, why not use it???
2155 fepriv
->min_delay
= HZ
/ 20;
2156 fepriv
->step_size
= 0; /* no zigzag */
2157 fepriv
->max_drift
= 0;
2161 if (dvb_override_tune_delay
> 0)
2162 fepriv
->min_delay
= (dvb_override_tune_delay
* HZ
) / 1000;
2164 fepriv
->state
= FESTATE_RETUNE
;
2166 /* Request the search algorithm to search */
2167 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
2169 dvb_frontend_clear_events(fe
);
2170 dvb_frontend_add_event(fe
, 0);
2171 dvb_frontend_wakeup(fe
);
2178 static int dvb_frontend_ioctl_legacy(struct file
*file
,
2179 unsigned int cmd
, void *parg
)
2181 struct dvb_device
*dvbdev
= file
->private_data
;
2182 struct dvb_frontend
*fe
= dvbdev
->priv
;
2183 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2184 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
2185 int err
= -EOPNOTSUPP
;
2189 struct dvb_frontend_info
* info
= parg
;
2191 memcpy(info
, &fe
->ops
.info
, sizeof(struct dvb_frontend_info
));
2192 dvb_frontend_get_frequency_limits(fe
, &info
->frequency_min
, &info
->frequency_max
);
2195 * Associate the 4 delivery systems supported by DVBv3
2196 * API with their DVBv5 counterpart. For the other standards,
2197 * use the closest type, assuming that it would hopefully
2198 * work with a DVBv3 application.
2199 * It should be noticed that, on multi-frontend devices with
2200 * different types (terrestrial and cable, for example),
2201 * a pure DVBv3 application won't be able to use all delivery
2202 * systems. Yet, changing the DVBv5 cache to the other delivery
2203 * system should be enough for making it work.
2205 switch (dvbv3_type(c
->delivery_system
)) {
2207 info
->type
= FE_QPSK
;
2210 info
->type
= FE_ATSC
;
2213 info
->type
= FE_QAM
;
2216 info
->type
= FE_OFDM
;
2219 dev_err(fe
->dvb
->device
,
2220 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2221 __func__
, c
->delivery_system
);
2222 fe
->ops
.info
.type
= FE_OFDM
;
2224 dev_dbg(fe
->dvb
->device
, "%s: current delivery system on cache: %d, V3 type: %d\n",
2225 __func__
, c
->delivery_system
, fe
->ops
.info
.type
);
2227 /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */
2228 if (!(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
))
2229 info
->caps
|= FE_CAN_INVERSION_AUTO
;
2234 case FE_READ_STATUS
: {
2235 enum fe_status
*status
= parg
;
2237 /* if retune was requested but hasn't occurred yet, prevent
2238 * that user get signal state from previous tuning */
2239 if (fepriv
->state
== FESTATE_RETUNE
||
2240 fepriv
->state
== FESTATE_ERROR
) {
2246 if (fe
->ops
.read_status
)
2247 err
= fe
->ops
.read_status(fe
, status
);
2252 if (fe
->ops
.read_ber
) {
2254 err
= fe
->ops
.read_ber(fe
, (__u32
*) parg
);
2260 case FE_READ_SIGNAL_STRENGTH
:
2261 if (fe
->ops
.read_signal_strength
) {
2263 err
= fe
->ops
.read_signal_strength(fe
, (__u16
*) parg
);
2270 if (fe
->ops
.read_snr
) {
2272 err
= fe
->ops
.read_snr(fe
, (__u16
*) parg
);
2278 case FE_READ_UNCORRECTED_BLOCKS
:
2279 if (fe
->ops
.read_ucblocks
) {
2281 err
= fe
->ops
.read_ucblocks(fe
, (__u32
*) parg
);
2287 case FE_DISEQC_RESET_OVERLOAD
:
2288 if (fe
->ops
.diseqc_reset_overload
) {
2289 err
= fe
->ops
.diseqc_reset_overload(fe
);
2290 fepriv
->state
= FESTATE_DISEQC
;
2295 case FE_DISEQC_SEND_MASTER_CMD
:
2296 if (fe
->ops
.diseqc_send_master_cmd
) {
2297 struct dvb_diseqc_master_cmd
*cmd
= parg
;
2299 if (cmd
->msg_len
> sizeof(cmd
->msg
)) {
2303 err
= fe
->ops
.diseqc_send_master_cmd(fe
, cmd
);
2304 fepriv
->state
= FESTATE_DISEQC
;
2309 case FE_DISEQC_SEND_BURST
:
2310 if (fe
->ops
.diseqc_send_burst
) {
2311 err
= fe
->ops
.diseqc_send_burst(fe
,
2312 (enum fe_sec_mini_cmd
)parg
);
2313 fepriv
->state
= FESTATE_DISEQC
;
2319 if (fe
->ops
.set_tone
) {
2320 err
= fe
->ops
.set_tone(fe
,
2321 (enum fe_sec_tone_mode
)parg
);
2322 fepriv
->tone
= (enum fe_sec_tone_mode
)parg
;
2323 fepriv
->state
= FESTATE_DISEQC
;
2328 case FE_SET_VOLTAGE
:
2329 if (fe
->ops
.set_voltage
) {
2330 err
= fe
->ops
.set_voltage(fe
,
2331 (enum fe_sec_voltage
)parg
);
2332 fepriv
->voltage
= (enum fe_sec_voltage
)parg
;
2333 fepriv
->state
= FESTATE_DISEQC
;
2338 case FE_DISHNETWORK_SEND_LEGACY_CMD
:
2339 if (fe
->ops
.dishnetwork_send_legacy_command
) {
2340 err
= fe
->ops
.dishnetwork_send_legacy_command(fe
,
2341 (unsigned long)parg
);
2342 fepriv
->state
= FESTATE_DISEQC
;
2344 } else if (fe
->ops
.set_voltage
) {
2346 * NOTE: This is a fallback condition. Some frontends
2347 * (stv0299 for instance) take longer than 8msec to
2348 * respond to a set_voltage command. Those switches
2349 * need custom routines to switch properly. For all
2350 * other frontends, the following should work ok.
2351 * Dish network legacy switches (as used by Dish500)
2352 * are controlled by sending 9-bit command words
2353 * spaced 8msec apart.
2354 * the actual command word is switch/port dependent
2355 * so it is up to the userspace application to send
2356 * the right command.
2357 * The command must always start with a '0' after
2358 * initialization, so parg is 8 bits and does not
2359 * include the initialization or start bit
2361 unsigned long swcmd
= ((unsigned long) parg
) << 1;
2366 if (dvb_frontend_debug
)
2367 dprintk("%s switch command: 0x%04lx\n",
2369 nexttime
= ktime_get_boottime();
2370 if (dvb_frontend_debug
)
2372 /* before sending a command, initialize by sending
2373 * a 32ms 18V to the switch
2375 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_18
);
2376 dvb_frontend_sleep_until(&nexttime
, 32000);
2378 for (i
= 0; i
< 9; i
++) {
2379 if (dvb_frontend_debug
)
2380 tv
[i
+1] = ktime_get_boottime();
2381 if ((swcmd
& 0x01) != last
) {
2382 /* set voltage to (last ? 13V : 18V) */
2383 fe
->ops
.set_voltage(fe
, (last
) ? SEC_VOLTAGE_13
: SEC_VOLTAGE_18
);
2384 last
= (last
) ? 0 : 1;
2388 dvb_frontend_sleep_until(&nexttime
, 8000);
2390 if (dvb_frontend_debug
) {
2391 dprintk("%s(%d): switch delay (should be 32k followed by all 8k)\n",
2392 __func__
, fe
->dvb
->num
);
2393 for (i
= 1; i
< 10; i
++)
2394 pr_info("%d: %d\n", i
,
2395 (int) ktime_us_delta(tv
[i
], tv
[i
-1]));
2398 fepriv
->state
= FESTATE_DISEQC
;
2403 case FE_DISEQC_RECV_SLAVE_REPLY
:
2404 if (fe
->ops
.diseqc_recv_slave_reply
)
2405 err
= fe
->ops
.diseqc_recv_slave_reply(fe
, (struct dvb_diseqc_slave_reply
*) parg
);
2408 case FE_ENABLE_HIGH_LNB_VOLTAGE
:
2409 if (fe
->ops
.enable_high_lnb_voltage
)
2410 err
= fe
->ops
.enable_high_lnb_voltage(fe
, (long) parg
);
2413 case FE_SET_FRONTEND
:
2414 err
= dvbv3_set_delivery_system(fe
);
2418 err
= dtv_property_cache_sync(fe
, c
, parg
);
2421 err
= dtv_set_frontend(fe
);
2424 err
= dvb_frontend_get_event (fe
, parg
, file
->f_flags
);
2427 case FE_GET_FRONTEND
: {
2428 struct dtv_frontend_properties getp
= fe
->dtv_property_cache
;
2431 * Let's use our own copy of property cache, in order to
2432 * avoid mangling with DTV zigzag logic, as drivers might
2433 * return crap, if they don't check if the data is available
2434 * before updating the properties cache.
2436 err
= dtv_get_frontend(fe
, &getp
, parg
);
2439 case FE_SET_FRONTEND_TUNE_MODE
:
2440 fepriv
->tune_mode_flags
= (unsigned long) parg
;
2449 static unsigned int dvb_frontend_poll(struct file
*file
, struct poll_table_struct
*wait
)
2451 struct dvb_device
*dvbdev
= file
->private_data
;
2452 struct dvb_frontend
*fe
= dvbdev
->priv
;
2453 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2455 dev_dbg_ratelimited(fe
->dvb
->device
, "%s:\n", __func__
);
2457 poll_wait (file
, &fepriv
->events
.wait_queue
, wait
);
2459 if (fepriv
->events
.eventw
!= fepriv
->events
.eventr
)
2460 return (POLLIN
| POLLRDNORM
| POLLPRI
);
2465 static int dvb_frontend_open(struct inode
*inode
, struct file
*file
)
2467 struct dvb_device
*dvbdev
= file
->private_data
;
2468 struct dvb_frontend
*fe
= dvbdev
->priv
;
2469 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2470 struct dvb_adapter
*adapter
= fe
->dvb
;
2473 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2474 if (fe
->exit
== DVB_FE_DEVICE_REMOVED
)
2477 if (adapter
->mfe_shared
) {
2478 mutex_lock (&adapter
->mfe_lock
);
2480 if (adapter
->mfe_dvbdev
== NULL
)
2481 adapter
->mfe_dvbdev
= dvbdev
;
2483 else if (adapter
->mfe_dvbdev
!= dvbdev
) {
2485 *mfedev
= adapter
->mfe_dvbdev
;
2487 *mfe
= mfedev
->priv
;
2488 struct dvb_frontend_private
2489 *mfepriv
= mfe
->frontend_priv
;
2490 int mferetry
= (dvb_mfe_wait_time
<< 1);
2492 mutex_unlock (&adapter
->mfe_lock
);
2493 while (mferetry
-- && (mfedev
->users
!= -1 ||
2494 mfepriv
->thread
!= NULL
)) {
2495 if(msleep_interruptible(500)) {
2496 if(signal_pending(current
))
2501 mutex_lock (&adapter
->mfe_lock
);
2502 if(adapter
->mfe_dvbdev
!= dvbdev
) {
2503 mfedev
= adapter
->mfe_dvbdev
;
2505 mfepriv
= mfe
->frontend_priv
;
2506 if (mfedev
->users
!= -1 ||
2507 mfepriv
->thread
!= NULL
) {
2508 mutex_unlock (&adapter
->mfe_lock
);
2511 adapter
->mfe_dvbdev
= dvbdev
;
2516 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
) {
2517 if ((ret
= fe
->ops
.ts_bus_ctrl(fe
, 1)) < 0)
2520 /* If we took control of the bus, we need to force
2521 reinitialization. This is because many ts_bus_ctrl()
2522 functions strobe the RESET pin on the demod, and if the
2523 frontend thread already exists then the dvb_init() routine
2524 won't get called (which is what usually does initial
2525 register configuration). */
2526 fepriv
->reinitialise
= 1;
2529 if ((ret
= dvb_generic_open (inode
, file
)) < 0)
2532 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2533 /* normal tune mode when opened R/W */
2534 fepriv
->tune_mode_flags
&= ~FE_TUNE_MODE_ONESHOT
;
2536 fepriv
->voltage
= -1;
2538 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2539 if (fe
->dvb
->mdev
&& fe
->dvb
->mdev
->enable_source
) {
2540 ret
= fe
->dvb
->mdev
->enable_source(dvbdev
->entity
,
2543 dev_err(fe
->dvb
->device
,
2544 "Tuner is busy. Error %d\n", ret
);
2549 ret
= dvb_frontend_start (fe
);
2553 /* empty event queue */
2554 fepriv
->events
.eventr
= fepriv
->events
.eventw
= 0;
2557 dvb_frontend_get(fe
);
2559 if (adapter
->mfe_shared
)
2560 mutex_unlock (&adapter
->mfe_lock
);
2564 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2565 if (fe
->dvb
->mdev
&& fe
->dvb
->mdev
->disable_source
)
2566 fe
->dvb
->mdev
->disable_source(dvbdev
->entity
);
2569 dvb_generic_release(inode
, file
);
2571 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
)
2572 fe
->ops
.ts_bus_ctrl(fe
, 0);
2574 if (adapter
->mfe_shared
)
2575 mutex_unlock (&adapter
->mfe_lock
);
2579 static int dvb_frontend_release(struct inode
*inode
, struct file
*file
)
2581 struct dvb_device
*dvbdev
= file
->private_data
;
2582 struct dvb_frontend
*fe
= dvbdev
->priv
;
2583 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2586 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2588 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2589 fepriv
->release_jiffies
= jiffies
;
2593 ret
= dvb_generic_release (inode
, file
);
2595 if (dvbdev
->users
== -1) {
2596 wake_up(&fepriv
->wait_queue
);
2597 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2598 if (fe
->dvb
->mdev
&& fe
->dvb
->mdev
->disable_source
)
2599 fe
->dvb
->mdev
->disable_source(dvbdev
->entity
);
2601 if (fe
->exit
!= DVB_FE_NO_EXIT
)
2602 wake_up(&dvbdev
->wait_queue
);
2603 if (fe
->ops
.ts_bus_ctrl
)
2604 fe
->ops
.ts_bus_ctrl(fe
, 0);
2607 dvb_frontend_put(fe
);
2612 static const struct file_operations dvb_frontend_fops
= {
2613 .owner
= THIS_MODULE
,
2614 .unlocked_ioctl
= dvb_generic_ioctl
,
2615 .poll
= dvb_frontend_poll
,
2616 .open
= dvb_frontend_open
,
2617 .release
= dvb_frontend_release
,
2618 .llseek
= noop_llseek
,
2621 int dvb_frontend_suspend(struct dvb_frontend
*fe
)
2625 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2628 if (fe
->ops
.tuner_ops
.suspend
)
2629 ret
= fe
->ops
.tuner_ops
.suspend(fe
);
2630 else if (fe
->ops
.tuner_ops
.sleep
)
2631 ret
= fe
->ops
.tuner_ops
.sleep(fe
);
2634 ret
= fe
->ops
.sleep(fe
);
2638 EXPORT_SYMBOL(dvb_frontend_suspend
);
2640 int dvb_frontend_resume(struct dvb_frontend
*fe
)
2642 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2645 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2648 fe
->exit
= DVB_FE_DEVICE_RESUME
;
2650 ret
= fe
->ops
.init(fe
);
2652 if (fe
->ops
.tuner_ops
.resume
)
2653 ret
= fe
->ops
.tuner_ops
.resume(fe
);
2654 else if (fe
->ops
.tuner_ops
.init
)
2655 ret
= fe
->ops
.tuner_ops
.init(fe
);
2657 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
2658 fe
->ops
.set_tone(fe
, fepriv
->tone
);
2659 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
2660 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
2662 fe
->exit
= DVB_FE_NO_EXIT
;
2663 fepriv
->state
= FESTATE_RETUNE
;
2664 dvb_frontend_wakeup(fe
);
2668 EXPORT_SYMBOL(dvb_frontend_resume
);
2670 int dvb_register_frontend(struct dvb_adapter
* dvb
,
2671 struct dvb_frontend
* fe
)
2673 struct dvb_frontend_private
*fepriv
;
2674 const struct dvb_device dvbdev_template
= {
2678 .fops
= &dvb_frontend_fops
,
2679 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
2680 .name
= fe
->ops
.info
.name
,
2682 .kernel_ioctl
= dvb_frontend_ioctl
2685 dev_dbg(dvb
->device
, "%s:\n", __func__
);
2687 if (mutex_lock_interruptible(&frontend_mutex
))
2688 return -ERESTARTSYS
;
2690 fe
->frontend_priv
= kzalloc(sizeof(struct dvb_frontend_private
), GFP_KERNEL
);
2691 if (fe
->frontend_priv
== NULL
) {
2692 mutex_unlock(&frontend_mutex
);
2695 fepriv
= fe
->frontend_priv
;
2697 kref_init(&fe
->refcount
);
2700 * After initialization, there need to be two references: one
2701 * for dvb_unregister_frontend(), and another one for
2702 * dvb_frontend_detach().
2704 dvb_frontend_get(fe
);
2706 sema_init(&fepriv
->sem
, 1);
2707 init_waitqueue_head (&fepriv
->wait_queue
);
2708 init_waitqueue_head (&fepriv
->events
.wait_queue
);
2709 mutex_init(&fepriv
->events
.mtx
);
2711 fepriv
->inversion
= INVERSION_OFF
;
2713 dev_info(fe
->dvb
->device
,
2714 "DVB: registering adapter %i frontend %i (%s)...\n",
2715 fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
2717 dvb_register_device (fe
->dvb
, &fepriv
->dvbdev
, &dvbdev_template
,
2718 fe
, DVB_DEVICE_FRONTEND
, 0);
2721 * Initialize the cache to the proper values according with the
2722 * first supported delivery system (ops->delsys[0])
2725 fe
->dtv_property_cache
.delivery_system
= fe
->ops
.delsys
[0];
2726 dvb_frontend_clear_cache(fe
);
2728 mutex_unlock(&frontend_mutex
);
2731 EXPORT_SYMBOL(dvb_register_frontend
);
2733 int dvb_unregister_frontend(struct dvb_frontend
* fe
)
2735 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2736 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2738 mutex_lock(&frontend_mutex
);
2739 dvb_frontend_stop(fe
);
2740 dvb_remove_device(fepriv
->dvbdev
);
2742 /* fe is invalid now */
2743 mutex_unlock(&frontend_mutex
);
2744 dvb_frontend_put(fe
);
2747 EXPORT_SYMBOL(dvb_unregister_frontend
);
2749 static void dvb_frontend_invoke_release(struct dvb_frontend
*fe
,
2750 void (*release
)(struct dvb_frontend
*fe
))
2754 #ifdef CONFIG_MEDIA_ATTACH
2755 dvb_detach(release
);
2760 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2762 dvb_frontend_invoke_release(fe
, fe
->ops
.release_sec
);
2763 dvb_frontend_invoke_release(fe
, fe
->ops
.tuner_ops
.release
);
2764 dvb_frontend_invoke_release(fe
, fe
->ops
.analog_ops
.release
);
2765 dvb_frontend_invoke_release(fe
, fe
->ops
.detach
);
2766 dvb_frontend_put(fe
);
2768 EXPORT_SYMBOL(dvb_frontend_detach
);