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.
21 * To obtain the license, point your browser to
22 * http://www.gnu.org/copyleft/gpl.html
25 /* Enables DVBv3 compatibility bits at the headers */
28 #define pr_fmt(fmt) "dvb_frontend: " fmt
30 #include <linux/string.h>
31 #include <linux/kernel.h>
32 #include <linux/sched/signal.h>
33 #include <linux/wait.h>
34 #include <linux/slab.h>
35 #include <linux/poll.h>
36 #include <linux/semaphore.h>
37 #include <linux/module.h>
38 #include <linux/list.h>
39 #include <linux/freezer.h>
40 #include <linux/jiffies.h>
41 #include <linux/kthread.h>
42 #include <linux/ktime.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 dprintk(fmt, arg...) \
70 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
72 #define FESTATE_IDLE 1
73 #define FESTATE_RETUNE 2
74 #define FESTATE_TUNING_FAST 4
75 #define FESTATE_TUNING_SLOW 8
76 #define FESTATE_TUNED 16
77 #define FESTATE_ZIGZAG_FAST 32
78 #define FESTATE_ZIGZAG_SLOW 64
79 #define FESTATE_DISEQC 128
80 #define FESTATE_ERROR 256
81 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
82 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
83 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
84 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
87 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
88 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
89 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
90 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
91 * FESTATE_TUNED. The frontend has successfully locked on.
92 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
93 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
94 * FESTATE_DISEQC. A DISEQC command has just been issued.
95 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
96 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
97 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
98 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
101 static DEFINE_MUTEX(frontend_mutex
);
103 struct dvb_frontend_private
{
104 /* thread/frontend values */
105 struct dvb_device
*dvbdev
;
106 struct dvb_frontend_parameters parameters_out
;
107 struct dvb_fe_events events
;
108 struct semaphore sem
;
109 struct list_head list_head
;
110 wait_queue_head_t wait_queue
;
111 struct task_struct
*thread
;
112 unsigned long release_jiffies
;
114 enum fe_status status
;
115 unsigned long tune_mode_flags
;
117 unsigned int reinitialise
;
121 /* swzigzag values */
123 unsigned int bending
;
125 unsigned int inversion
;
126 unsigned int auto_step
;
127 unsigned int auto_sub_step
;
128 unsigned int started_auto_step
;
129 unsigned int min_delay
;
130 unsigned int max_drift
;
131 unsigned int step_size
;
133 unsigned int check_wrapped
;
134 enum dvbfe_search algo_status
;
136 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
137 struct media_pipeline pipe
;
141 static void dvb_frontend_invoke_release(struct dvb_frontend
*fe
,
142 void (*release
)(struct dvb_frontend
*fe
));
144 static void __dvb_frontend_free(struct dvb_frontend
*fe
)
146 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
149 dvb_free_device(fepriv
->dvbdev
);
151 dvb_frontend_invoke_release(fe
, fe
->ops
.release
);
157 static void dvb_frontend_free(struct kref
*ref
)
159 struct dvb_frontend
*fe
=
160 container_of(ref
, struct dvb_frontend
, refcount
);
162 __dvb_frontend_free(fe
);
165 static void dvb_frontend_put(struct dvb_frontend
*fe
)
168 * Check if the frontend was registered, as otherwise
169 * kref was not initialized yet.
171 if (fe
->frontend_priv
)
172 kref_put(&fe
->refcount
, dvb_frontend_free
);
174 __dvb_frontend_free(fe
);
177 static void dvb_frontend_get(struct dvb_frontend
*fe
)
179 kref_get(&fe
->refcount
);
182 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
);
183 static int dtv_get_frontend(struct dvb_frontend
*fe
,
184 struct dtv_frontend_properties
*c
,
185 struct dvb_frontend_parameters
*p_out
);
187 dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
188 const struct dtv_frontend_properties
*c
,
189 struct dvb_frontend_parameters
*p
);
191 static bool has_get_frontend(struct dvb_frontend
*fe
)
193 return fe
->ops
.get_frontend
!= NULL
;
197 * Due to DVBv3 API calls, a delivery system should be mapped into one of
198 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
199 * otherwise, a DVBv3 call will fail.
201 enum dvbv3_emulation_type
{
209 static enum dvbv3_emulation_type
dvbv3_type(u32 delivery_system
)
211 switch (delivery_system
) {
212 case SYS_DVBC_ANNEX_A
:
213 case SYS_DVBC_ANNEX_C
:
228 case SYS_DVBC_ANNEX_B
:
236 * Doesn't know how to emulate those types and/or
237 * there's no frontend driver from this type yet
238 * with some emulation code, so, we're not sure yet how
239 * to handle them, or they're not compatible with a DVBv3 call.
241 return DVBV3_UNKNOWN
;
245 static void dvb_frontend_add_event(struct dvb_frontend
*fe
,
246 enum fe_status status
)
248 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
249 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
250 struct dvb_fe_events
*events
= &fepriv
->events
;
251 struct dvb_frontend_event
*e
;
254 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
256 if ((status
& FE_HAS_LOCK
) && has_get_frontend(fe
))
257 dtv_get_frontend(fe
, c
, &fepriv
->parameters_out
);
259 mutex_lock(&events
->mtx
);
261 wp
= (events
->eventw
+ 1) % MAX_EVENT
;
262 if (wp
== events
->eventr
) {
263 events
->overflow
= 1;
264 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
267 e
= &events
->events
[events
->eventw
];
269 e
->parameters
= fepriv
->parameters_out
;
273 mutex_unlock(&events
->mtx
);
275 wake_up_interruptible (&events
->wait_queue
);
278 static int dvb_frontend_get_event(struct dvb_frontend
*fe
,
279 struct dvb_frontend_event
*event
, int flags
)
281 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
282 struct dvb_fe_events
*events
= &fepriv
->events
;
284 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
286 if (events
->overflow
) {
287 events
->overflow
= 0;
291 if (events
->eventw
== events
->eventr
) {
294 if (flags
& O_NONBLOCK
)
299 ret
= wait_event_interruptible (events
->wait_queue
,
300 events
->eventw
!= events
->eventr
);
302 if (down_interruptible (&fepriv
->sem
))
309 mutex_lock(&events
->mtx
);
310 *event
= events
->events
[events
->eventr
];
311 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
312 mutex_unlock(&events
->mtx
);
317 static void dvb_frontend_clear_events(struct dvb_frontend
*fe
)
319 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
320 struct dvb_fe_events
*events
= &fepriv
->events
;
322 mutex_lock(&events
->mtx
);
323 events
->eventr
= events
->eventw
;
324 mutex_unlock(&events
->mtx
);
327 static void dvb_frontend_init(struct dvb_frontend
*fe
)
329 dev_dbg(fe
->dvb
->device
,
330 "%s: initialising adapter %i frontend %i (%s)...\n",
331 __func__
, fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
335 if (fe
->ops
.tuner_ops
.init
) {
336 if (fe
->ops
.i2c_gate_ctrl
)
337 fe
->ops
.i2c_gate_ctrl(fe
, 1);
338 fe
->ops
.tuner_ops
.init(fe
);
339 if (fe
->ops
.i2c_gate_ctrl
)
340 fe
->ops
.i2c_gate_ctrl(fe
, 0);
344 void dvb_frontend_reinitialise(struct dvb_frontend
*fe
)
346 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
348 fepriv
->reinitialise
= 1;
349 dvb_frontend_wakeup(fe
);
351 EXPORT_SYMBOL(dvb_frontend_reinitialise
);
353 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private
*fepriv
, int locked
)
356 struct dvb_frontend
*fe
= fepriv
->dvbdev
->priv
;
358 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
361 (fepriv
->quality
) = (fepriv
->quality
* 220 + 36*256) / 256;
363 (fepriv
->quality
) = (fepriv
->quality
* 220 + 0) / 256;
365 q2
= fepriv
->quality
- 128;
368 fepriv
->delay
= fepriv
->min_delay
+ q2
* HZ
/ (128*128);
372 * Performs automatic twiddling of frontend parameters.
374 * @param fe The frontend concerned.
375 * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
376 * @returns Number of complete iterations that have been performed.
378 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend
*fe
, int check_wrapped
)
383 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
384 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
385 int original_inversion
= c
->inversion
;
386 u32 original_frequency
= c
->frequency
;
388 /* are we using autoinversion? */
389 autoinversion
= ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
390 (c
->inversion
== INVERSION_AUTO
));
392 /* setup parameters correctly */
394 /* calculate the lnb_drift */
395 fepriv
->lnb_drift
= fepriv
->auto_step
* fepriv
->step_size
;
397 /* wrap the auto_step if we've exceeded the maximum drift */
398 if (fepriv
->lnb_drift
> fepriv
->max_drift
) {
399 fepriv
->auto_step
= 0;
400 fepriv
->auto_sub_step
= 0;
401 fepriv
->lnb_drift
= 0;
404 /* perform inversion and +/- zigzag */
405 switch(fepriv
->auto_sub_step
) {
407 /* try with the current inversion and current drift setting */
412 if (!autoinversion
) break;
414 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
419 if (fepriv
->lnb_drift
== 0) break;
421 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
426 if (fepriv
->lnb_drift
== 0) break;
427 if (!autoinversion
) break;
429 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
430 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
436 fepriv
->auto_sub_step
= -1; /* it'll be incremented to 0 in a moment */
440 if (!ready
) fepriv
->auto_sub_step
++;
443 /* if this attempt would hit where we started, indicate a complete
444 * iteration has occurred */
445 if ((fepriv
->auto_step
== fepriv
->started_auto_step
) &&
446 (fepriv
->auto_sub_step
== 0) && check_wrapped
) {
450 dev_dbg(fe
->dvb
->device
, "%s: drift:%i inversion:%i auto_step:%i " \
451 "auto_sub_step:%i started_auto_step:%i\n",
452 __func__
, fepriv
->lnb_drift
, fepriv
->inversion
,
453 fepriv
->auto_step
, fepriv
->auto_sub_step
,
454 fepriv
->started_auto_step
);
456 /* set the frontend itself */
457 c
->frequency
+= fepriv
->lnb_drift
;
459 c
->inversion
= fepriv
->inversion
;
461 if (fe
->ops
.set_frontend
)
462 fe_set_err
= fe
->ops
.set_frontend(fe
);
464 if (fe_set_err
< 0) {
465 fepriv
->state
= FESTATE_ERROR
;
469 c
->frequency
= original_frequency
;
470 c
->inversion
= original_inversion
;
472 fepriv
->auto_sub_step
++;
476 static void dvb_frontend_swzigzag(struct dvb_frontend
*fe
)
478 enum fe_status s
= FE_NONE
;
480 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
481 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
483 /* if we've got no parameters, just keep idling */
484 if (fepriv
->state
& FESTATE_IDLE
) {
485 fepriv
->delay
= 3*HZ
;
490 /* in SCAN mode, we just set the frontend when asked and leave it alone */
491 if (fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
) {
492 if (fepriv
->state
& FESTATE_RETUNE
) {
494 if (fe
->ops
.set_frontend
)
495 retval
= fe
->ops
.set_frontend(fe
);
498 fepriv
->state
= FESTATE_ERROR
;
500 fepriv
->state
= FESTATE_TUNED
;
502 fepriv
->delay
= 3*HZ
;
507 /* get the frontend status */
508 if (fepriv
->state
& FESTATE_RETUNE
) {
511 if (fe
->ops
.read_status
)
512 fe
->ops
.read_status(fe
, &s
);
513 if (s
!= fepriv
->status
) {
514 dvb_frontend_add_event(fe
, s
);
519 /* if we're not tuned, and we have a lock, move to the TUNED state */
520 if ((fepriv
->state
& FESTATE_WAITFORLOCK
) && (s
& FE_HAS_LOCK
)) {
521 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
522 fepriv
->state
= FESTATE_TUNED
;
524 /* if we're tuned, then we have determined the correct inversion */
525 if ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
526 (c
->inversion
== INVERSION_AUTO
)) {
527 c
->inversion
= fepriv
->inversion
;
532 /* if we are tuned already, check we're still locked */
533 if (fepriv
->state
& FESTATE_TUNED
) {
534 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
536 /* we're tuned, and the lock is still good... */
537 if (s
& FE_HAS_LOCK
) {
539 } else { /* if we _WERE_ tuned, but now don't have a lock */
540 fepriv
->state
= FESTATE_ZIGZAG_FAST
;
541 fepriv
->started_auto_step
= fepriv
->auto_step
;
542 fepriv
->check_wrapped
= 0;
546 /* don't actually do anything if we're in the LOSTLOCK state,
547 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
548 if ((fepriv
->state
& FESTATE_LOSTLOCK
) &&
549 (fe
->ops
.info
.caps
& FE_CAN_RECOVER
) && (fepriv
->max_drift
== 0)) {
550 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
554 /* don't do anything if we're in the DISEQC state, since this
555 * might be someone with a motorized dish controlled by DISEQC.
556 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
557 if (fepriv
->state
& FESTATE_DISEQC
) {
558 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
562 /* if we're in the RETUNE state, set everything up for a brand
563 * new scan, keeping the current inversion setting, as the next
564 * tune is _very_ likely to require the same */
565 if (fepriv
->state
& FESTATE_RETUNE
) {
566 fepriv
->lnb_drift
= 0;
567 fepriv
->auto_step
= 0;
568 fepriv
->auto_sub_step
= 0;
569 fepriv
->started_auto_step
= 0;
570 fepriv
->check_wrapped
= 0;
574 if ((fepriv
->state
& FESTATE_SEARCHING_FAST
) || (fepriv
->state
& FESTATE_RETUNE
)) {
575 fepriv
->delay
= fepriv
->min_delay
;
578 retval
= dvb_frontend_swzigzag_autotune(fe
,
579 fepriv
->check_wrapped
);
583 /* OK, if we've run out of trials at the fast speed.
584 * Drop back to slow for the _next_ attempt */
585 fepriv
->state
= FESTATE_SEARCHING_SLOW
;
586 fepriv
->started_auto_step
= fepriv
->auto_step
;
589 fepriv
->check_wrapped
= 1;
591 /* if we've just retuned, enter the ZIGZAG_FAST state.
592 * This ensures we cannot return from an
593 * FE_SET_FRONTEND ioctl before the first frontend tune
595 if (fepriv
->state
& FESTATE_RETUNE
) {
596 fepriv
->state
= FESTATE_TUNING_FAST
;
601 if (fepriv
->state
& FESTATE_SEARCHING_SLOW
) {
602 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
604 /* Note: don't bother checking for wrapping; we stay in this
605 * state until we get a lock */
606 dvb_frontend_swzigzag_autotune(fe
, 0);
610 static int dvb_frontend_is_exiting(struct dvb_frontend
*fe
)
612 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
614 if (fe
->exit
!= DVB_FE_NO_EXIT
)
617 if (fepriv
->dvbdev
->writers
== 1)
618 if (time_after_eq(jiffies
, fepriv
->release_jiffies
+
619 dvb_shutdown_timeout
* HZ
))
625 static int dvb_frontend_should_wakeup(struct dvb_frontend
*fe
)
627 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
629 if (fepriv
->wakeup
) {
633 return dvb_frontend_is_exiting(fe
);
636 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
)
638 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
641 wake_up_interruptible(&fepriv
->wait_queue
);
644 static int dvb_frontend_thread(void *data
)
646 struct dvb_frontend
*fe
= data
;
647 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
648 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
649 enum fe_status s
= FE_NONE
;
650 enum dvbfe_algo algo
;
651 bool re_tune
= false;
652 bool semheld
= false;
654 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
656 fepriv
->check_wrapped
= 0;
658 fepriv
->delay
= 3*HZ
;
661 fepriv
->reinitialise
= 0;
663 dvb_frontend_init(fe
);
667 up(&fepriv
->sem
); /* is locked when we enter the thread... */
669 wait_event_interruptible_timeout(fepriv
->wait_queue
,
670 dvb_frontend_should_wakeup(fe
) || kthread_should_stop()
671 || freezing(current
),
674 if (kthread_should_stop() || dvb_frontend_is_exiting(fe
)) {
675 /* got signal or quitting */
676 if (!down_interruptible(&fepriv
->sem
))
678 fe
->exit
= DVB_FE_NORMAL_EXIT
;
685 if (down_interruptible(&fepriv
->sem
))
688 if (fepriv
->reinitialise
) {
689 dvb_frontend_init(fe
);
690 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
691 fe
->ops
.set_tone(fe
, fepriv
->tone
);
692 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
693 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
694 fepriv
->reinitialise
= 0;
697 /* do an iteration of the tuning loop */
698 if (fe
->ops
.get_frontend_algo
) {
699 algo
= fe
->ops
.get_frontend_algo(fe
);
702 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__
);
704 if (fepriv
->state
& FESTATE_RETUNE
) {
705 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTATE_RETUNE\n", __func__
);
707 fepriv
->state
= FESTATE_TUNED
;
713 fe
->ops
.tune(fe
, re_tune
, fepriv
->tune_mode_flags
, &fepriv
->delay
, &s
);
715 if (s
!= fepriv
->status
&& !(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
)) {
716 dev_dbg(fe
->dvb
->device
, "%s: state changed, adding current state\n", __func__
);
717 dvb_frontend_add_event(fe
, s
);
722 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__
);
723 dvb_frontend_swzigzag(fe
);
725 case DVBFE_ALGO_CUSTOM
:
726 dev_dbg(fe
->dvb
->device
, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__
, fepriv
->state
);
727 if (fepriv
->state
& FESTATE_RETUNE
) {
728 dev_dbg(fe
->dvb
->device
, "%s: Retune requested, FESTAT_RETUNE\n", __func__
);
729 fepriv
->state
= FESTATE_TUNED
;
731 /* Case where we are going to search for a carrier
732 * User asked us to retune again for some reason, possibly
733 * requesting a search with a new set of parameters
735 if (fepriv
->algo_status
& DVBFE_ALGO_SEARCH_AGAIN
) {
736 if (fe
->ops
.search
) {
737 fepriv
->algo_status
= fe
->ops
.search(fe
);
738 /* We did do a search as was requested, the flags are
739 * now unset as well and has the flags wrt to search.
742 fepriv
->algo_status
&= ~DVBFE_ALGO_SEARCH_AGAIN
;
745 /* Track the carrier if the search was successful */
746 if (fepriv
->algo_status
!= DVBFE_ALGO_SEARCH_SUCCESS
) {
747 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
748 fepriv
->delay
= HZ
/ 2;
750 dtv_property_legacy_params_sync(fe
, c
, &fepriv
->parameters_out
);
751 fe
->ops
.read_status(fe
, &s
);
752 if (s
!= fepriv
->status
) {
753 dvb_frontend_add_event(fe
, s
); /* update event list */
755 if (!(s
& FE_HAS_LOCK
)) {
756 fepriv
->delay
= HZ
/ 10;
757 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
759 fepriv
->delay
= 60 * HZ
;
764 dev_dbg(fe
->dvb
->device
, "%s: UNDEFINED ALGO !\n", __func__
);
768 dvb_frontend_swzigzag(fe
);
772 if (dvb_powerdown_on_sleep
) {
773 if (fe
->ops
.set_voltage
)
774 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_OFF
);
775 if (fe
->ops
.tuner_ops
.sleep
) {
776 if (fe
->ops
.i2c_gate_ctrl
)
777 fe
->ops
.i2c_gate_ctrl(fe
, 1);
778 fe
->ops
.tuner_ops
.sleep(fe
);
779 if (fe
->ops
.i2c_gate_ctrl
)
780 fe
->ops
.i2c_gate_ctrl(fe
, 0);
786 fepriv
->thread
= NULL
;
787 if (kthread_should_stop())
788 fe
->exit
= DVB_FE_DEVICE_REMOVED
;
790 fe
->exit
= DVB_FE_NO_EXIT
;
795 dvb_frontend_wakeup(fe
);
799 static void dvb_frontend_stop(struct dvb_frontend
*fe
)
801 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
803 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
805 if (fe
->exit
!= DVB_FE_DEVICE_REMOVED
)
806 fe
->exit
= DVB_FE_NORMAL_EXIT
;
812 kthread_stop(fepriv
->thread
);
814 sema_init(&fepriv
->sem
, 1);
815 fepriv
->state
= FESTATE_IDLE
;
817 /* paranoia check in case a signal arrived */
819 dev_warn(fe
->dvb
->device
,
820 "dvb_frontend_stop: warning: thread %p won't exit\n",
825 * Sleep for the amount of time given by add_usec parameter
827 * This needs to be as precise as possible, as it affects the detection of
828 * the dish tone command at the satellite subsystem. The precision is improved
829 * by using a scheduled msleep followed by udelay for the remainder.
831 void dvb_frontend_sleep_until(ktime_t
*waketime
, u32 add_usec
)
835 *waketime
= ktime_add_us(*waketime
, add_usec
);
836 delta
= ktime_us_delta(ktime_get_boottime(), *waketime
);
838 msleep((delta
- 1500) / 1000);
839 delta
= ktime_us_delta(ktime_get_boottime(), *waketime
);
844 EXPORT_SYMBOL(dvb_frontend_sleep_until
);
846 static int dvb_frontend_start(struct dvb_frontend
*fe
)
849 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
850 struct task_struct
*fe_thread
;
852 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
854 if (fepriv
->thread
) {
855 if (fe
->exit
== DVB_FE_NO_EXIT
)
858 dvb_frontend_stop (fe
);
861 if (signal_pending(current
))
863 if (down_interruptible (&fepriv
->sem
))
866 fepriv
->state
= FESTATE_IDLE
;
867 fe
->exit
= DVB_FE_NO_EXIT
;
868 fepriv
->thread
= NULL
;
871 fe_thread
= kthread_run(dvb_frontend_thread
, fe
,
872 "kdvb-ad-%i-fe-%i", fe
->dvb
->num
,fe
->id
);
873 if (IS_ERR(fe_thread
)) {
874 ret
= PTR_ERR(fe_thread
);
875 dev_warn(fe
->dvb
->device
,
876 "dvb_frontend_start: failed to start kthread (%d)\n",
881 fepriv
->thread
= fe_thread
;
885 static void dvb_frontend_get_frequency_limits(struct dvb_frontend
*fe
,
886 u32
*freq_min
, u32
*freq_max
)
888 *freq_min
= max(fe
->ops
.info
.frequency_min
, fe
->ops
.tuner_ops
.info
.frequency_min
);
890 if (fe
->ops
.info
.frequency_max
== 0)
891 *freq_max
= fe
->ops
.tuner_ops
.info
.frequency_max
;
892 else if (fe
->ops
.tuner_ops
.info
.frequency_max
== 0)
893 *freq_max
= fe
->ops
.info
.frequency_max
;
895 *freq_max
= min(fe
->ops
.info
.frequency_max
, fe
->ops
.tuner_ops
.info
.frequency_max
);
897 if (*freq_min
== 0 || *freq_max
== 0)
898 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
899 fe
->dvb
->num
, fe
->id
);
902 static int dvb_frontend_check_parameters(struct dvb_frontend
*fe
)
904 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
908 /* range check: frequency */
909 dvb_frontend_get_frequency_limits(fe
, &freq_min
, &freq_max
);
910 if ((freq_min
&& c
->frequency
< freq_min
) ||
911 (freq_max
&& c
->frequency
> freq_max
)) {
912 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
913 fe
->dvb
->num
, fe
->id
, c
->frequency
,
918 /* range check: symbol rate */
919 switch (c
->delivery_system
) {
923 case SYS_DVBC_ANNEX_A
:
924 case SYS_DVBC_ANNEX_C
:
925 if ((fe
->ops
.info
.symbol_rate_min
&&
926 c
->symbol_rate
< fe
->ops
.info
.symbol_rate_min
) ||
927 (fe
->ops
.info
.symbol_rate_max
&&
928 c
->symbol_rate
> fe
->ops
.info
.symbol_rate_max
)) {
929 dev_warn(fe
->dvb
->device
, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
930 fe
->dvb
->num
, fe
->id
, c
->symbol_rate
,
931 fe
->ops
.info
.symbol_rate_min
,
932 fe
->ops
.info
.symbol_rate_max
);
942 static int dvb_frontend_clear_cache(struct dvb_frontend
*fe
)
944 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
948 delsys
= c
->delivery_system
;
949 memset(c
, 0, offsetof(struct dtv_frontend_properties
, strength
));
950 c
->delivery_system
= delsys
;
952 dev_dbg(fe
->dvb
->device
, "%s: Clearing cache for delivery system %d\n",
953 __func__
, c
->delivery_system
);
955 c
->transmission_mode
= TRANSMISSION_MODE_AUTO
;
956 c
->bandwidth_hz
= 0; /* AUTO */
957 c
->guard_interval
= GUARD_INTERVAL_AUTO
;
958 c
->hierarchy
= HIERARCHY_AUTO
;
960 c
->code_rate_HP
= FEC_AUTO
;
961 c
->code_rate_LP
= FEC_AUTO
;
962 c
->fec_inner
= FEC_AUTO
;
963 c
->rolloff
= ROLLOFF_AUTO
;
964 c
->voltage
= SEC_VOLTAGE_OFF
;
965 c
->sectone
= SEC_TONE_OFF
;
966 c
->pilot
= PILOT_AUTO
;
968 c
->isdbt_partial_reception
= 0;
969 c
->isdbt_sb_mode
= 0;
970 c
->isdbt_sb_subchannel
= 0;
971 c
->isdbt_sb_segment_idx
= 0;
972 c
->isdbt_sb_segment_count
= 0;
973 c
->isdbt_layer_enabled
= 0;
974 for (i
= 0; i
< 3; i
++) {
975 c
->layer
[i
].fec
= FEC_AUTO
;
976 c
->layer
[i
].modulation
= QAM_AUTO
;
977 c
->layer
[i
].interleaving
= 0;
978 c
->layer
[i
].segment_count
= 0;
981 c
->stream_id
= NO_STREAM_ID_FILTER
;
983 switch (c
->delivery_system
) {
987 c
->modulation
= QPSK
; /* implied for DVB-S in legacy API */
988 c
->rolloff
= ROLLOFF_35
;/* implied for DVB-S */
991 c
->modulation
= VSB_8
;
994 c
->symbol_rate
= 28860000;
995 c
->rolloff
= ROLLOFF_35
;
996 c
->bandwidth_hz
= c
->symbol_rate
/ 100 * 135;
999 c
->modulation
= QAM_AUTO
;
1008 #define _DTV_CMD(n, s, b) \
1017 char *name
; /* A display name for debugging purposes */
1019 __u32 cmd
; /* A unique ID */
1022 __u32 set
:1; /* Either a set or get property */
1023 __u32 buffer
:1; /* Does this property use the buffer? */
1024 __u32 reserved
:30; /* Align */
1027 static struct dtv_cmds_h dtv_cmds
[DTV_MAX_COMMAND
+ 1] = {
1028 _DTV_CMD(DTV_TUNE
, 1, 0),
1029 _DTV_CMD(DTV_CLEAR
, 1, 0),
1032 _DTV_CMD(DTV_FREQUENCY
, 1, 0),
1033 _DTV_CMD(DTV_BANDWIDTH_HZ
, 1, 0),
1034 _DTV_CMD(DTV_MODULATION
, 1, 0),
1035 _DTV_CMD(DTV_INVERSION
, 1, 0),
1036 _DTV_CMD(DTV_DISEQC_MASTER
, 1, 1),
1037 _DTV_CMD(DTV_SYMBOL_RATE
, 1, 0),
1038 _DTV_CMD(DTV_INNER_FEC
, 1, 0),
1039 _DTV_CMD(DTV_VOLTAGE
, 1, 0),
1040 _DTV_CMD(DTV_TONE
, 1, 0),
1041 _DTV_CMD(DTV_PILOT
, 1, 0),
1042 _DTV_CMD(DTV_ROLLOFF
, 1, 0),
1043 _DTV_CMD(DTV_DELIVERY_SYSTEM
, 1, 0),
1044 _DTV_CMD(DTV_HIERARCHY
, 1, 0),
1045 _DTV_CMD(DTV_CODE_RATE_HP
, 1, 0),
1046 _DTV_CMD(DTV_CODE_RATE_LP
, 1, 0),
1047 _DTV_CMD(DTV_GUARD_INTERVAL
, 1, 0),
1048 _DTV_CMD(DTV_TRANSMISSION_MODE
, 1, 0),
1049 _DTV_CMD(DTV_INTERLEAVING
, 1, 0),
1051 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION
, 1, 0),
1052 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING
, 1, 0),
1053 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID
, 1, 0),
1054 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX
, 1, 0),
1055 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT
, 1, 0),
1056 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED
, 1, 0),
1057 _DTV_CMD(DTV_ISDBT_LAYERA_FEC
, 1, 0),
1058 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION
, 1, 0),
1059 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT
, 1, 0),
1060 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING
, 1, 0),
1061 _DTV_CMD(DTV_ISDBT_LAYERB_FEC
, 1, 0),
1062 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION
, 1, 0),
1063 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT
, 1, 0),
1064 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING
, 1, 0),
1065 _DTV_CMD(DTV_ISDBT_LAYERC_FEC
, 1, 0),
1066 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION
, 1, 0),
1067 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT
, 1, 0),
1068 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING
, 1, 0),
1070 _DTV_CMD(DTV_STREAM_ID
, 1, 0),
1071 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY
, 1, 0),
1072 _DTV_CMD(DTV_LNA
, 1, 0),
1075 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY
, 0, 1),
1076 _DTV_CMD(DTV_API_VERSION
, 0, 0),
1078 _DTV_CMD(DTV_ENUM_DELSYS
, 0, 0),
1080 _DTV_CMD(DTV_ATSCMH_PARADE_ID
, 1, 0),
1081 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE
, 1, 0),
1083 _DTV_CMD(DTV_ATSCMH_FIC_VER
, 0, 0),
1084 _DTV_CMD(DTV_ATSCMH_NOG
, 0, 0),
1085 _DTV_CMD(DTV_ATSCMH_TNOG
, 0, 0),
1086 _DTV_CMD(DTV_ATSCMH_SGN
, 0, 0),
1087 _DTV_CMD(DTV_ATSCMH_PRC
, 0, 0),
1088 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE
, 0, 0),
1089 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI
, 0, 0),
1090 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC
, 0, 0),
1091 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE
, 0, 0),
1092 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A
, 0, 0),
1093 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B
, 0, 0),
1094 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C
, 0, 0),
1095 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D
, 0, 0),
1097 /* Statistics API */
1098 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH
, 0, 0),
1099 _DTV_CMD(DTV_STAT_CNR
, 0, 0),
1100 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT
, 0, 0),
1101 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT
, 0, 0),
1102 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT
, 0, 0),
1103 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT
, 0, 0),
1104 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT
, 0, 0),
1105 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT
, 0, 0),
1108 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1109 * drivers can use a single set_frontend tuning function, regardless of whether
1110 * it's being used for the legacy or new API, reducing code and complexity.
1112 static int dtv_property_cache_sync(struct dvb_frontend
*fe
,
1113 struct dtv_frontend_properties
*c
,
1114 const struct dvb_frontend_parameters
*p
)
1116 c
->frequency
= p
->frequency
;
1117 c
->inversion
= p
->inversion
;
1119 switch (dvbv3_type(c
->delivery_system
)) {
1121 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1122 c
->symbol_rate
= p
->u
.qpsk
.symbol_rate
;
1123 c
->fec_inner
= p
->u
.qpsk
.fec_inner
;
1126 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1127 c
->symbol_rate
= p
->u
.qam
.symbol_rate
;
1128 c
->fec_inner
= p
->u
.qam
.fec_inner
;
1129 c
->modulation
= p
->u
.qam
.modulation
;
1132 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1134 switch (p
->u
.ofdm
.bandwidth
) {
1135 case BANDWIDTH_10_MHZ
:
1136 c
->bandwidth_hz
= 10000000;
1138 case BANDWIDTH_8_MHZ
:
1139 c
->bandwidth_hz
= 8000000;
1141 case BANDWIDTH_7_MHZ
:
1142 c
->bandwidth_hz
= 7000000;
1144 case BANDWIDTH_6_MHZ
:
1145 c
->bandwidth_hz
= 6000000;
1147 case BANDWIDTH_5_MHZ
:
1148 c
->bandwidth_hz
= 5000000;
1150 case BANDWIDTH_1_712_MHZ
:
1151 c
->bandwidth_hz
= 1712000;
1153 case BANDWIDTH_AUTO
:
1154 c
->bandwidth_hz
= 0;
1157 c
->code_rate_HP
= p
->u
.ofdm
.code_rate_HP
;
1158 c
->code_rate_LP
= p
->u
.ofdm
.code_rate_LP
;
1159 c
->modulation
= p
->u
.ofdm
.constellation
;
1160 c
->transmission_mode
= p
->u
.ofdm
.transmission_mode
;
1161 c
->guard_interval
= p
->u
.ofdm
.guard_interval
;
1162 c
->hierarchy
= p
->u
.ofdm
.hierarchy_information
;
1165 dev_dbg(fe
->dvb
->device
, "%s: Preparing ATSC req\n", __func__
);
1166 c
->modulation
= p
->u
.vsb
.modulation
;
1167 if (c
->delivery_system
== SYS_ATSCMH
)
1169 if ((c
->modulation
== VSB_8
) || (c
->modulation
== VSB_16
))
1170 c
->delivery_system
= SYS_ATSC
;
1172 c
->delivery_system
= SYS_DVBC_ANNEX_B
;
1175 dev_err(fe
->dvb
->device
,
1176 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1177 __func__
, c
->delivery_system
);
1184 /* Ensure the cached values are set correctly in the frontend
1185 * legacy tuning structures, for the advanced tuning API.
1188 dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
1189 const struct dtv_frontend_properties
*c
,
1190 struct dvb_frontend_parameters
*p
)
1192 p
->frequency
= c
->frequency
;
1193 p
->inversion
= c
->inversion
;
1195 switch (dvbv3_type(c
->delivery_system
)) {
1197 dev_err(fe
->dvb
->device
,
1198 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1199 __func__
, c
->delivery_system
);
1202 dev_dbg(fe
->dvb
->device
, "%s: Preparing QPSK req\n", __func__
);
1203 p
->u
.qpsk
.symbol_rate
= c
->symbol_rate
;
1204 p
->u
.qpsk
.fec_inner
= c
->fec_inner
;
1207 dev_dbg(fe
->dvb
->device
, "%s: Preparing QAM req\n", __func__
);
1208 p
->u
.qam
.symbol_rate
= c
->symbol_rate
;
1209 p
->u
.qam
.fec_inner
= c
->fec_inner
;
1210 p
->u
.qam
.modulation
= c
->modulation
;
1213 dev_dbg(fe
->dvb
->device
, "%s: Preparing OFDM req\n", __func__
);
1214 switch (c
->bandwidth_hz
) {
1216 p
->u
.ofdm
.bandwidth
= BANDWIDTH_10_MHZ
;
1219 p
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
1222 p
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
1225 p
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
1228 p
->u
.ofdm
.bandwidth
= BANDWIDTH_5_MHZ
;
1231 p
->u
.ofdm
.bandwidth
= BANDWIDTH_1_712_MHZ
;
1235 p
->u
.ofdm
.bandwidth
= BANDWIDTH_AUTO
;
1237 p
->u
.ofdm
.code_rate_HP
= c
->code_rate_HP
;
1238 p
->u
.ofdm
.code_rate_LP
= c
->code_rate_LP
;
1239 p
->u
.ofdm
.constellation
= c
->modulation
;
1240 p
->u
.ofdm
.transmission_mode
= c
->transmission_mode
;
1241 p
->u
.ofdm
.guard_interval
= c
->guard_interval
;
1242 p
->u
.ofdm
.hierarchy_information
= c
->hierarchy
;
1245 dev_dbg(fe
->dvb
->device
, "%s: Preparing VSB req\n", __func__
);
1246 p
->u
.vsb
.modulation
= c
->modulation
;
1253 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1254 * @fe: struct dvb_frontend pointer
1255 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1256 * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1258 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1259 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1260 * If p_out is not null, it will update the DVBv3 params pointed by it.
1262 static int dtv_get_frontend(struct dvb_frontend
*fe
,
1263 struct dtv_frontend_properties
*c
,
1264 struct dvb_frontend_parameters
*p_out
)
1268 if (fe
->ops
.get_frontend
) {
1269 r
= fe
->ops
.get_frontend(fe
, c
);
1270 if (unlikely(r
< 0))
1273 dtv_property_legacy_params_sync(fe
, c
, p_out
);
1277 /* As everything is in cache, get_frontend fops are always supported */
1281 static int dvb_frontend_handle_ioctl(struct file
*file
,
1282 unsigned int cmd
, void *parg
);
1284 static int dtv_property_process_get(struct dvb_frontend
*fe
,
1285 const struct dtv_frontend_properties
*c
,
1286 struct dtv_property
*tvp
,
1292 case DTV_ENUM_DELSYS
:
1294 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1295 tvp
->u
.buffer
.data
[ncaps
] = fe
->ops
.delsys
[ncaps
];
1298 tvp
->u
.buffer
.len
= ncaps
;
1301 tvp
->u
.data
= c
->frequency
;
1303 case DTV_MODULATION
:
1304 tvp
->u
.data
= c
->modulation
;
1306 case DTV_BANDWIDTH_HZ
:
1307 tvp
->u
.data
= c
->bandwidth_hz
;
1310 tvp
->u
.data
= c
->inversion
;
1312 case DTV_SYMBOL_RATE
:
1313 tvp
->u
.data
= c
->symbol_rate
;
1316 tvp
->u
.data
= c
->fec_inner
;
1319 tvp
->u
.data
= c
->pilot
;
1322 tvp
->u
.data
= c
->rolloff
;
1324 case DTV_DELIVERY_SYSTEM
:
1325 tvp
->u
.data
= c
->delivery_system
;
1328 tvp
->u
.data
= c
->voltage
;
1331 tvp
->u
.data
= c
->sectone
;
1333 case DTV_API_VERSION
:
1334 tvp
->u
.data
= (DVB_API_VERSION
<< 8) | DVB_API_VERSION_MINOR
;
1336 case DTV_CODE_RATE_HP
:
1337 tvp
->u
.data
= c
->code_rate_HP
;
1339 case DTV_CODE_RATE_LP
:
1340 tvp
->u
.data
= c
->code_rate_LP
;
1342 case DTV_GUARD_INTERVAL
:
1343 tvp
->u
.data
= c
->guard_interval
;
1345 case DTV_TRANSMISSION_MODE
:
1346 tvp
->u
.data
= c
->transmission_mode
;
1349 tvp
->u
.data
= c
->hierarchy
;
1351 case DTV_INTERLEAVING
:
1352 tvp
->u
.data
= c
->interleaving
;
1355 /* ISDB-T Support here */
1356 case DTV_ISDBT_PARTIAL_RECEPTION
:
1357 tvp
->u
.data
= c
->isdbt_partial_reception
;
1359 case DTV_ISDBT_SOUND_BROADCASTING
:
1360 tvp
->u
.data
= c
->isdbt_sb_mode
;
1362 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1363 tvp
->u
.data
= c
->isdbt_sb_subchannel
;
1365 case DTV_ISDBT_SB_SEGMENT_IDX
:
1366 tvp
->u
.data
= c
->isdbt_sb_segment_idx
;
1368 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1369 tvp
->u
.data
= c
->isdbt_sb_segment_count
;
1371 case DTV_ISDBT_LAYER_ENABLED
:
1372 tvp
->u
.data
= c
->isdbt_layer_enabled
;
1374 case DTV_ISDBT_LAYERA_FEC
:
1375 tvp
->u
.data
= c
->layer
[0].fec
;
1377 case DTV_ISDBT_LAYERA_MODULATION
:
1378 tvp
->u
.data
= c
->layer
[0].modulation
;
1380 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1381 tvp
->u
.data
= c
->layer
[0].segment_count
;
1383 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1384 tvp
->u
.data
= c
->layer
[0].interleaving
;
1386 case DTV_ISDBT_LAYERB_FEC
:
1387 tvp
->u
.data
= c
->layer
[1].fec
;
1389 case DTV_ISDBT_LAYERB_MODULATION
:
1390 tvp
->u
.data
= c
->layer
[1].modulation
;
1392 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1393 tvp
->u
.data
= c
->layer
[1].segment_count
;
1395 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1396 tvp
->u
.data
= c
->layer
[1].interleaving
;
1398 case DTV_ISDBT_LAYERC_FEC
:
1399 tvp
->u
.data
= c
->layer
[2].fec
;
1401 case DTV_ISDBT_LAYERC_MODULATION
:
1402 tvp
->u
.data
= c
->layer
[2].modulation
;
1404 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1405 tvp
->u
.data
= c
->layer
[2].segment_count
;
1407 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1408 tvp
->u
.data
= c
->layer
[2].interleaving
;
1411 /* Multistream support */
1413 case DTV_DVBT2_PLP_ID_LEGACY
:
1414 tvp
->u
.data
= c
->stream_id
;
1418 case DTV_ATSCMH_FIC_VER
:
1419 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_fic_ver
;
1421 case DTV_ATSCMH_PARADE_ID
:
1422 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_parade_id
;
1424 case DTV_ATSCMH_NOG
:
1425 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_nog
;
1427 case DTV_ATSCMH_TNOG
:
1428 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_tnog
;
1430 case DTV_ATSCMH_SGN
:
1431 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sgn
;
1433 case DTV_ATSCMH_PRC
:
1434 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_prc
;
1436 case DTV_ATSCMH_RS_FRAME_MODE
:
1437 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_mode
;
1439 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1440 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
;
1442 case DTV_ATSCMH_RS_CODE_MODE_PRI
:
1443 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_pri
;
1445 case DTV_ATSCMH_RS_CODE_MODE_SEC
:
1446 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_rs_code_mode_sec
;
1448 case DTV_ATSCMH_SCCC_BLOCK_MODE
:
1449 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_block_mode
;
1451 case DTV_ATSCMH_SCCC_CODE_MODE_A
:
1452 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_a
;
1454 case DTV_ATSCMH_SCCC_CODE_MODE_B
:
1455 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_b
;
1457 case DTV_ATSCMH_SCCC_CODE_MODE_C
:
1458 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_c
;
1460 case DTV_ATSCMH_SCCC_CODE_MODE_D
:
1461 tvp
->u
.data
= fe
->dtv_property_cache
.atscmh_sccc_code_mode_d
;
1465 tvp
->u
.data
= c
->lna
;
1468 /* Fill quality measures */
1469 case DTV_STAT_SIGNAL_STRENGTH
:
1470 tvp
->u
.st
= c
->strength
;
1475 case DTV_STAT_PRE_ERROR_BIT_COUNT
:
1476 tvp
->u
.st
= c
->pre_bit_error
;
1478 case DTV_STAT_PRE_TOTAL_BIT_COUNT
:
1479 tvp
->u
.st
= c
->pre_bit_count
;
1481 case DTV_STAT_POST_ERROR_BIT_COUNT
:
1482 tvp
->u
.st
= c
->post_bit_error
;
1484 case DTV_STAT_POST_TOTAL_BIT_COUNT
:
1485 tvp
->u
.st
= c
->post_bit_count
;
1487 case DTV_STAT_ERROR_BLOCK_COUNT
:
1488 tvp
->u
.st
= c
->block_error
;
1490 case DTV_STAT_TOTAL_BLOCK_COUNT
:
1491 tvp
->u
.st
= c
->block_count
;
1494 dev_dbg(fe
->dvb
->device
,
1495 "%s: FE property %d doesn't exist\n",
1496 __func__
, tvp
->cmd
);
1500 if (!dtv_cmds
[tvp
->cmd
].buffer
)
1501 dev_dbg(fe
->dvb
->device
,
1502 "%s: GET cmd 0x%08x (%s) = 0x%08x\n",
1503 __func__
, tvp
->cmd
, dtv_cmds
[tvp
->cmd
].name
,
1506 dev_dbg(fe
->dvb
->device
,
1507 "%s: GET cmd 0x%08x (%s) len %d: %*ph\n",
1509 tvp
->cmd
, dtv_cmds
[tvp
->cmd
].name
,
1511 tvp
->u
.buffer
.len
, tvp
->u
.buffer
.data
);
1516 static int dtv_set_frontend(struct dvb_frontend
*fe
);
1518 static bool is_dvbv3_delsys(u32 delsys
)
1520 return (delsys
== SYS_DVBT
) || (delsys
== SYS_DVBC_ANNEX_A
) ||
1521 (delsys
== SYS_DVBS
) || (delsys
== SYS_ATSC
);
1525 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1526 * @fe: struct frontend;
1527 * @delsys: DVBv5 type that will be used for emulation
1529 * Provides emulation for delivery systems that are compatible with the old
1530 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1531 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent
1532 * parameters are compatible with DVB-S spec.
1534 static int emulate_delivery_system(struct dvb_frontend
*fe
, u32 delsys
)
1537 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1539 c
->delivery_system
= delsys
;
1542 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1544 if (c
->delivery_system
== SYS_ISDBT
) {
1545 dev_dbg(fe
->dvb
->device
,
1546 "%s: Using defaults for SYS_ISDBT\n",
1549 if (!c
->bandwidth_hz
)
1550 c
->bandwidth_hz
= 6000000;
1552 c
->isdbt_partial_reception
= 0;
1553 c
->isdbt_sb_mode
= 0;
1554 c
->isdbt_sb_subchannel
= 0;
1555 c
->isdbt_sb_segment_idx
= 0;
1556 c
->isdbt_sb_segment_count
= 0;
1557 c
->isdbt_layer_enabled
= 7;
1558 for (i
= 0; i
< 3; i
++) {
1559 c
->layer
[i
].fec
= FEC_AUTO
;
1560 c
->layer
[i
].modulation
= QAM_AUTO
;
1561 c
->layer
[i
].interleaving
= 0;
1562 c
->layer
[i
].segment_count
= 0;
1565 dev_dbg(fe
->dvb
->device
, "%s: change delivery system on cache to %d\n",
1566 __func__
, c
->delivery_system
);
1572 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1573 * @fe: frontend struct
1574 * @desired_system: delivery system requested by the user
1576 * A DVBv5 call know what's the desired system it wants. So, set it.
1578 * There are, however, a few known issues with early DVBv5 applications that
1579 * are also handled by this logic:
1581 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1582 * This is an API violation, but, as we don't want to break userspace,
1583 * convert it to the first supported delivery system.
1584 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1585 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1586 * ISDB-T provided backward compat with DVB-T.
1588 static int dvbv5_set_delivery_system(struct dvb_frontend
*fe
,
1592 u32 delsys
= SYS_UNDEFINED
;
1593 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1594 enum dvbv3_emulation_type type
;
1597 * It was reported that some old DVBv5 applications were
1598 * filling delivery_system with SYS_UNDEFINED. If this happens,
1599 * assume that the application wants to use the first supported
1602 if (desired_system
== SYS_UNDEFINED
)
1603 desired_system
= fe
->ops
.delsys
[0];
1606 * This is a DVBv5 call. So, it likely knows the supported
1607 * delivery systems. So, check if the desired delivery system is
1611 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1612 if (fe
->ops
.delsys
[ncaps
] == desired_system
) {
1613 c
->delivery_system
= desired_system
;
1614 dev_dbg(fe
->dvb
->device
,
1615 "%s: Changing delivery system to %d\n",
1616 __func__
, desired_system
);
1623 * The requested delivery system isn't supported. Maybe userspace
1624 * is requesting a DVBv3 compatible delivery system.
1626 * The emulation only works if the desired system is one of the
1627 * delivery systems supported by DVBv3 API
1629 if (!is_dvbv3_delsys(desired_system
)) {
1630 dev_dbg(fe
->dvb
->device
,
1631 "%s: Delivery system %d not supported.\n",
1632 __func__
, desired_system
);
1636 type
= dvbv3_type(desired_system
);
1639 * Get the last non-DVBv3 delivery system that has the same type
1640 * of the desired system
1643 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1644 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) == type
)
1645 delsys
= fe
->ops
.delsys
[ncaps
];
1649 /* There's nothing compatible with the desired delivery system */
1650 if (delsys
== SYS_UNDEFINED
) {
1651 dev_dbg(fe
->dvb
->device
,
1652 "%s: Delivery system %d not supported on emulation mode.\n",
1653 __func__
, desired_system
);
1657 dev_dbg(fe
->dvb
->device
,
1658 "%s: Using delivery system %d emulated as if it were %d\n",
1659 __func__
, delsys
, desired_system
);
1661 return emulate_delivery_system(fe
, desired_system
);
1665 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1666 * @fe: frontend struct
1668 * A DVBv3 call doesn't know what's the desired system it wants. It also
1669 * doesn't allow to switch between different types. Due to that, userspace
1670 * should use DVBv5 instead.
1671 * However, in order to avoid breaking userspace API, limited backward
1672 * compatibility support is provided.
1674 * There are some delivery systems that are incompatible with DVBv3 calls.
1676 * This routine should work fine for frontends that support just one delivery
1679 * For frontends that support multiple frontends:
1680 * 1) It defaults to use the first supported delivery system. There's an
1681 * userspace application that allows changing it at runtime;
1683 * 2) If the current delivery system is not compatible with DVBv3, it gets
1684 * the first one that it is compatible.
1686 * NOTE: in order for this to work with applications like Kaffeine that
1687 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1688 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1689 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1692 static int dvbv3_set_delivery_system(struct dvb_frontend
*fe
)
1695 u32 delsys
= SYS_UNDEFINED
;
1696 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1698 /* If not set yet, defaults to the first supported delivery system */
1699 if (c
->delivery_system
== SYS_UNDEFINED
)
1700 c
->delivery_system
= fe
->ops
.delsys
[0];
1703 * Trivial case: just use the current one, if it already a DVBv3
1706 if (is_dvbv3_delsys(c
->delivery_system
)) {
1707 dev_dbg(fe
->dvb
->device
,
1708 "%s: Using delivery system to %d\n",
1709 __func__
, c
->delivery_system
);
1714 * Seek for the first delivery system that it is compatible with a
1718 while (ncaps
< MAX_DELSYS
&& fe
->ops
.delsys
[ncaps
]) {
1719 if (dvbv3_type(fe
->ops
.delsys
[ncaps
]) != DVBV3_UNKNOWN
) {
1720 delsys
= fe
->ops
.delsys
[ncaps
];
1725 if (delsys
== SYS_UNDEFINED
) {
1726 dev_dbg(fe
->dvb
->device
,
1727 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1731 return emulate_delivery_system(fe
, delsys
);
1735 * dtv_property_process_set - Sets a single DTV property
1736 * @fe: Pointer to &struct dvb_frontend
1737 * @file: Pointer to &struct file
1738 * @cmd: Digital TV command
1739 * @data: An unsigned 32-bits number
1741 * This routine assigns the property
1742 * value to the corresponding member of
1743 * &struct dtv_frontend_properties
1746 * Zero on success, negative errno on failure.
1748 static int dtv_property_process_set(struct dvb_frontend
*fe
,
1753 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1755 /** Dump DTV command name and value*/
1756 if (!cmd
|| cmd
> DTV_MAX_COMMAND
)
1757 dev_warn(fe
->dvb
->device
, "%s: SET cmd 0x%08x undefined\n",
1760 dev_dbg(fe
->dvb
->device
,
1761 "%s: SET cmd 0x%08x (%s) to 0x%08x\n",
1762 __func__
, cmd
, dtv_cmds
[cmd
].name
, data
);
1766 * Reset a cache of data specific to the frontend here. This does
1767 * not effect hardware.
1769 dvb_frontend_clear_cache(fe
);
1773 * Use the cached Digital TV properties to tune the
1776 dev_dbg(fe
->dvb
->device
,
1777 "%s: Setting the frontend from property cache\n",
1780 r
= dtv_set_frontend(fe
);
1783 c
->frequency
= data
;
1785 case DTV_MODULATION
:
1786 c
->modulation
= data
;
1788 case DTV_BANDWIDTH_HZ
:
1789 c
->bandwidth_hz
= data
;
1792 c
->inversion
= data
;
1794 case DTV_SYMBOL_RATE
:
1795 c
->symbol_rate
= data
;
1798 c
->fec_inner
= data
;
1806 case DTV_DELIVERY_SYSTEM
:
1807 r
= dvbv5_set_delivery_system(fe
, data
);
1811 r
= dvb_frontend_handle_ioctl(file
, FE_SET_VOLTAGE
,
1812 (void *)c
->voltage
);
1816 r
= dvb_frontend_handle_ioctl(file
, FE_SET_TONE
,
1817 (void *)c
->sectone
);
1819 case DTV_CODE_RATE_HP
:
1820 c
->code_rate_HP
= data
;
1822 case DTV_CODE_RATE_LP
:
1823 c
->code_rate_LP
= data
;
1825 case DTV_GUARD_INTERVAL
:
1826 c
->guard_interval
= data
;
1828 case DTV_TRANSMISSION_MODE
:
1829 c
->transmission_mode
= data
;
1832 c
->hierarchy
= data
;
1834 case DTV_INTERLEAVING
:
1835 c
->interleaving
= data
;
1838 /* ISDB-T Support here */
1839 case DTV_ISDBT_PARTIAL_RECEPTION
:
1840 c
->isdbt_partial_reception
= data
;
1842 case DTV_ISDBT_SOUND_BROADCASTING
:
1843 c
->isdbt_sb_mode
= data
;
1845 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1846 c
->isdbt_sb_subchannel
= data
;
1848 case DTV_ISDBT_SB_SEGMENT_IDX
:
1849 c
->isdbt_sb_segment_idx
= data
;
1851 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1852 c
->isdbt_sb_segment_count
= data
;
1854 case DTV_ISDBT_LAYER_ENABLED
:
1855 c
->isdbt_layer_enabled
= data
;
1857 case DTV_ISDBT_LAYERA_FEC
:
1858 c
->layer
[0].fec
= data
;
1860 case DTV_ISDBT_LAYERA_MODULATION
:
1861 c
->layer
[0].modulation
= data
;
1863 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1864 c
->layer
[0].segment_count
= data
;
1866 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1867 c
->layer
[0].interleaving
= data
;
1869 case DTV_ISDBT_LAYERB_FEC
:
1870 c
->layer
[1].fec
= data
;
1872 case DTV_ISDBT_LAYERB_MODULATION
:
1873 c
->layer
[1].modulation
= data
;
1875 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1876 c
->layer
[1].segment_count
= data
;
1878 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1879 c
->layer
[1].interleaving
= data
;
1881 case DTV_ISDBT_LAYERC_FEC
:
1882 c
->layer
[2].fec
= data
;
1884 case DTV_ISDBT_LAYERC_MODULATION
:
1885 c
->layer
[2].modulation
= data
;
1887 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1888 c
->layer
[2].segment_count
= data
;
1890 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1891 c
->layer
[2].interleaving
= data
;
1894 /* Multistream support */
1896 case DTV_DVBT2_PLP_ID_LEGACY
:
1897 c
->stream_id
= data
;
1901 case DTV_ATSCMH_PARADE_ID
:
1902 fe
->dtv_property_cache
.atscmh_parade_id
= data
;
1904 case DTV_ATSCMH_RS_FRAME_ENSEMBLE
:
1905 fe
->dtv_property_cache
.atscmh_rs_frame_ensemble
= data
;
1910 if (fe
->ops
.set_lna
)
1911 r
= fe
->ops
.set_lna(fe
);
1923 static int dvb_frontend_ioctl(struct file
*file
, unsigned int cmd
, void *parg
)
1925 struct dvb_device
*dvbdev
= file
->private_data
;
1926 struct dvb_frontend
*fe
= dvbdev
->priv
;
1927 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1930 dev_dbg(fe
->dvb
->device
, "%s: (%d)\n", __func__
, _IOC_NR(cmd
));
1931 if (down_interruptible(&fepriv
->sem
))
1932 return -ERESTARTSYS
;
1934 if (fe
->exit
!= DVB_FE_NO_EXIT
) {
1940 * If the frontend is opened in read-only mode, only the ioctls
1941 * that don't interfere with the tune logic should be accepted.
1942 * That allows an external application to monitor the DVB QoS and
1943 * statistics parameters.
1945 * That matches all _IOR() ioctls, except for two special cases:
1946 * - FE_GET_EVENT is part of the tuning logic on a DVB application;
1947 * - FE_DISEQC_RECV_SLAVE_REPLY is part of DiSEqC 2.0
1949 * So, those two ioctls should also return -EPERM, as otherwise
1950 * reading from them would interfere with a DVB tune application
1952 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
1953 && (_IOC_DIR(cmd
) != _IOC_READ
1954 || cmd
== FE_GET_EVENT
1955 || cmd
== FE_DISEQC_RECV_SLAVE_REPLY
)) {
1960 err
= dvb_frontend_handle_ioctl(file
, cmd
, parg
);
1966 static int dtv_set_frontend(struct dvb_frontend
*fe
)
1968 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1969 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1970 struct dvb_frontend_tune_settings fetunesettings
;
1973 if (dvb_frontend_check_parameters(fe
) < 0)
1977 * Initialize output parameters to match the values given by
1978 * the user. FE_SET_FRONTEND triggers an initial frontend event
1979 * with status = 0, which copies output parameters to userspace.
1981 dtv_property_legacy_params_sync(fe
, c
, &fepriv
->parameters_out
);
1984 * Be sure that the bandwidth will be filled for all
1985 * non-satellite systems, as tuners need to know what
1986 * low pass/Nyquist half filter should be applied, in
1987 * order to avoid inter-channel noise.
1989 * ISDB-T and DVB-T/T2 already sets bandwidth.
1990 * ATSC and DVB-C don't set, so, the core should fill it.
1992 * On DVB-C Annex A and C, the bandwidth is a function of
1993 * the roll-off and symbol rate. Annex B defines different
1994 * roll-off factors depending on the modulation. Fortunately,
1995 * Annex B is only used with 6MHz, so there's no need to
1998 * While not officially supported, a side effect of handling it at
1999 * the cache level is that a program could retrieve the bandwidth
2000 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2002 switch (c
->delivery_system
) {
2004 case SYS_DVBC_ANNEX_B
:
2005 c
->bandwidth_hz
= 6000000;
2007 case SYS_DVBC_ANNEX_A
:
2010 case SYS_DVBC_ANNEX_C
:
2019 switch (c
->rolloff
) {
2035 c
->bandwidth_hz
= mult_frac(c
->symbol_rate
, rolloff
, 100);
2037 /* force auto frequency inversion if requested */
2038 if (dvb_force_auto_inversion
)
2039 c
->inversion
= INVERSION_AUTO
;
2042 * without hierarchical coding code_rate_LP is irrelevant,
2043 * so we tolerate the otherwise invalid FEC_NONE setting
2045 if (c
->hierarchy
== HIERARCHY_NONE
&& c
->code_rate_LP
== FEC_NONE
)
2046 c
->code_rate_LP
= FEC_AUTO
;
2048 /* get frontend-specific tuning settings */
2049 memset(&fetunesettings
, 0, sizeof(struct dvb_frontend_tune_settings
));
2050 if (fe
->ops
.get_tune_settings
&& (fe
->ops
.get_tune_settings(fe
, &fetunesettings
) == 0)) {
2051 fepriv
->min_delay
= (fetunesettings
.min_delay_ms
* HZ
) / 1000;
2052 fepriv
->max_drift
= fetunesettings
.max_drift
;
2053 fepriv
->step_size
= fetunesettings
.step_size
;
2055 /* default values */
2056 switch (c
->delivery_system
) {
2061 case SYS_DVBC_ANNEX_A
:
2062 case SYS_DVBC_ANNEX_C
:
2063 fepriv
->min_delay
= HZ
/ 20;
2064 fepriv
->step_size
= c
->symbol_rate
/ 16000;
2065 fepriv
->max_drift
= c
->symbol_rate
/ 2000;
2071 fepriv
->min_delay
= HZ
/ 20;
2072 fepriv
->step_size
= fe
->ops
.info
.frequency_stepsize
* 2;
2073 fepriv
->max_drift
= (fe
->ops
.info
.frequency_stepsize
* 2) + 1;
2077 * FIXME: This sounds wrong! if freqency_stepsize is
2078 * defined by the frontend, why not use it???
2080 fepriv
->min_delay
= HZ
/ 20;
2081 fepriv
->step_size
= 0; /* no zigzag */
2082 fepriv
->max_drift
= 0;
2086 if (dvb_override_tune_delay
> 0)
2087 fepriv
->min_delay
= (dvb_override_tune_delay
* HZ
) / 1000;
2089 fepriv
->state
= FESTATE_RETUNE
;
2091 /* Request the search algorithm to search */
2092 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
2094 dvb_frontend_clear_events(fe
);
2095 dvb_frontend_add_event(fe
, 0);
2096 dvb_frontend_wakeup(fe
);
2103 static int dvb_frontend_handle_ioctl(struct file
*file
,
2104 unsigned int cmd
, void *parg
)
2106 struct dvb_device
*dvbdev
= file
->private_data
;
2107 struct dvb_frontend
*fe
= dvbdev
->priv
;
2108 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2109 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
2112 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2115 case FE_SET_PROPERTY
: {
2116 struct dtv_properties
*tvps
= parg
;
2117 struct dtv_property
*tvp
= NULL
;
2119 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n",
2120 __func__
, tvps
->num
);
2121 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n",
2122 __func__
, tvps
->props
);
2125 * Put an arbitrary limit on the number of messages that can
2128 if (!tvps
->num
|| (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
2131 tvp
= memdup_user(tvps
->props
, tvps
->num
* sizeof(*tvp
));
2133 return PTR_ERR(tvp
);
2135 for (i
= 0; i
< tvps
->num
; i
++) {
2136 err
= dtv_property_process_set(fe
, file
,
2147 case FE_GET_PROPERTY
: {
2148 struct dtv_properties
*tvps
= parg
;
2149 struct dtv_property
*tvp
= NULL
;
2150 struct dtv_frontend_properties getp
= fe
->dtv_property_cache
;
2152 dev_dbg(fe
->dvb
->device
, "%s: properties.num = %d\n",
2153 __func__
, tvps
->num
);
2154 dev_dbg(fe
->dvb
->device
, "%s: properties.props = %p\n",
2155 __func__
, tvps
->props
);
2158 * Put an arbitrary limit on the number of messages that can
2161 if (!tvps
->num
|| (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
2164 tvp
= memdup_user(tvps
->props
, tvps
->num
* sizeof(*tvp
));
2166 return PTR_ERR(tvp
);
2169 * Let's use our own copy of property cache, in order to
2170 * avoid mangling with DTV zigzag logic, as drivers might
2171 * return crap, if they don't check if the data is available
2172 * before updating the properties cache.
2174 if (fepriv
->state
!= FESTATE_IDLE
) {
2175 err
= dtv_get_frontend(fe
, &getp
, NULL
);
2181 for (i
= 0; i
< tvps
->num
; i
++) {
2182 err
= dtv_property_process_get(fe
, &getp
,
2190 if (copy_to_user((void __user
*)tvps
->props
, tvp
,
2191 tvps
->num
* sizeof(struct dtv_property
))) {
2200 struct dvb_frontend_info
* info
= parg
;
2202 memcpy(info
, &fe
->ops
.info
, sizeof(struct dvb_frontend_info
));
2203 dvb_frontend_get_frequency_limits(fe
, &info
->frequency_min
, &info
->frequency_max
);
2206 * Associate the 4 delivery systems supported by DVBv3
2207 * API with their DVBv5 counterpart. For the other standards,
2208 * use the closest type, assuming that it would hopefully
2209 * work with a DVBv3 application.
2210 * It should be noticed that, on multi-frontend devices with
2211 * different types (terrestrial and cable, for example),
2212 * a pure DVBv3 application won't be able to use all delivery
2213 * systems. Yet, changing the DVBv5 cache to the other delivery
2214 * system should be enough for making it work.
2216 switch (dvbv3_type(c
->delivery_system
)) {
2218 info
->type
= FE_QPSK
;
2221 info
->type
= FE_ATSC
;
2224 info
->type
= FE_QAM
;
2227 info
->type
= FE_OFDM
;
2230 dev_err(fe
->dvb
->device
,
2231 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2232 __func__
, c
->delivery_system
);
2233 fe
->ops
.info
.type
= FE_OFDM
;
2235 dev_dbg(fe
->dvb
->device
, "%s: current delivery system on cache: %d, V3 type: %d\n",
2236 __func__
, c
->delivery_system
, fe
->ops
.info
.type
);
2238 /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */
2239 if (!(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
))
2240 info
->caps
|= FE_CAN_INVERSION_AUTO
;
2245 case FE_READ_STATUS
: {
2246 enum fe_status
*status
= parg
;
2248 /* if retune was requested but hasn't occurred yet, prevent
2249 * that user get signal state from previous tuning */
2250 if (fepriv
->state
== FESTATE_RETUNE
||
2251 fepriv
->state
== FESTATE_ERROR
) {
2257 if (fe
->ops
.read_status
)
2258 err
= fe
->ops
.read_status(fe
, status
);
2262 case FE_DISEQC_RESET_OVERLOAD
:
2263 if (fe
->ops
.diseqc_reset_overload
) {
2264 err
= fe
->ops
.diseqc_reset_overload(fe
);
2265 fepriv
->state
= FESTATE_DISEQC
;
2270 case FE_DISEQC_SEND_MASTER_CMD
:
2271 if (fe
->ops
.diseqc_send_master_cmd
) {
2272 struct dvb_diseqc_master_cmd
*cmd
= parg
;
2274 if (cmd
->msg_len
> sizeof(cmd
->msg
)) {
2278 err
= fe
->ops
.diseqc_send_master_cmd(fe
, cmd
);
2279 fepriv
->state
= FESTATE_DISEQC
;
2284 case FE_DISEQC_SEND_BURST
:
2285 if (fe
->ops
.diseqc_send_burst
) {
2286 err
= fe
->ops
.diseqc_send_burst(fe
,
2287 (enum fe_sec_mini_cmd
)parg
);
2288 fepriv
->state
= FESTATE_DISEQC
;
2294 if (fe
->ops
.set_tone
) {
2295 err
= fe
->ops
.set_tone(fe
,
2296 (enum fe_sec_tone_mode
)parg
);
2297 fepriv
->tone
= (enum fe_sec_tone_mode
)parg
;
2298 fepriv
->state
= FESTATE_DISEQC
;
2303 case FE_SET_VOLTAGE
:
2304 if (fe
->ops
.set_voltage
) {
2305 err
= fe
->ops
.set_voltage(fe
,
2306 (enum fe_sec_voltage
)parg
);
2307 fepriv
->voltage
= (enum fe_sec_voltage
)parg
;
2308 fepriv
->state
= FESTATE_DISEQC
;
2313 case FE_DISEQC_RECV_SLAVE_REPLY
:
2314 if (fe
->ops
.diseqc_recv_slave_reply
)
2315 err
= fe
->ops
.diseqc_recv_slave_reply(fe
, parg
);
2318 case FE_ENABLE_HIGH_LNB_VOLTAGE
:
2319 if (fe
->ops
.enable_high_lnb_voltage
)
2320 err
= fe
->ops
.enable_high_lnb_voltage(fe
, (long) parg
);
2323 case FE_SET_FRONTEND_TUNE_MODE
:
2324 fepriv
->tune_mode_flags
= (unsigned long) parg
;
2328 /* DEPRECATED dish control ioctls */
2330 case FE_DISHNETWORK_SEND_LEGACY_CMD
:
2331 if (fe
->ops
.dishnetwork_send_legacy_command
) {
2332 err
= fe
->ops
.dishnetwork_send_legacy_command(fe
,
2333 (unsigned long)parg
);
2334 fepriv
->state
= FESTATE_DISEQC
;
2336 } else if (fe
->ops
.set_voltage
) {
2338 * NOTE: This is a fallback condition. Some frontends
2339 * (stv0299 for instance) take longer than 8msec to
2340 * respond to a set_voltage command. Those switches
2341 * need custom routines to switch properly. For all
2342 * other frontends, the following should work ok.
2343 * Dish network legacy switches (as used by Dish500)
2344 * are controlled by sending 9-bit command words
2345 * spaced 8msec apart.
2346 * the actual command word is switch/port dependent
2347 * so it is up to the userspace application to send
2348 * the right command.
2349 * The command must always start with a '0' after
2350 * initialization, so parg is 8 bits and does not
2351 * include the initialization or start bit
2353 unsigned long swcmd
= ((unsigned long) parg
) << 1;
2358 if (dvb_frontend_debug
)
2359 dprintk("%s switch command: 0x%04lx\n",
2361 nexttime
= ktime_get_boottime();
2362 if (dvb_frontend_debug
)
2364 /* before sending a command, initialize by sending
2365 * a 32ms 18V to the switch
2367 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_18
);
2368 dvb_frontend_sleep_until(&nexttime
, 32000);
2370 for (i
= 0; i
< 9; i
++) {
2371 if (dvb_frontend_debug
)
2372 tv
[i
+1] = ktime_get_boottime();
2373 if ((swcmd
& 0x01) != last
) {
2374 /* set voltage to (last ? 13V : 18V) */
2375 fe
->ops
.set_voltage(fe
, (last
) ? SEC_VOLTAGE_13
: SEC_VOLTAGE_18
);
2376 last
= (last
) ? 0 : 1;
2380 dvb_frontend_sleep_until(&nexttime
, 8000);
2382 if (dvb_frontend_debug
) {
2383 dprintk("%s(%d): switch delay (should be 32k followed by all 8k)\n",
2384 __func__
, fe
->dvb
->num
);
2385 for (i
= 1; i
< 10; i
++)
2386 pr_info("%d: %d\n", i
,
2387 (int) ktime_us_delta(tv
[i
], tv
[i
-1]));
2390 fepriv
->state
= FESTATE_DISEQC
;
2395 /* DEPRECATED statistics ioctls */
2398 if (fe
->ops
.read_ber
) {
2400 err
= fe
->ops
.read_ber(fe
, parg
);
2406 case FE_READ_SIGNAL_STRENGTH
:
2407 if (fe
->ops
.read_signal_strength
) {
2409 err
= fe
->ops
.read_signal_strength(fe
, parg
);
2416 if (fe
->ops
.read_snr
) {
2418 err
= fe
->ops
.read_snr(fe
, parg
);
2424 case FE_READ_UNCORRECTED_BLOCKS
:
2425 if (fe
->ops
.read_ucblocks
) {
2427 err
= fe
->ops
.read_ucblocks(fe
, parg
);
2433 /* DEPRECATED DVBv3 ioctls */
2435 case FE_SET_FRONTEND
:
2436 err
= dvbv3_set_delivery_system(fe
);
2440 err
= dtv_property_cache_sync(fe
, c
, parg
);
2443 err
= dtv_set_frontend(fe
);
2446 err
= dvb_frontend_get_event (fe
, parg
, file
->f_flags
);
2449 case FE_GET_FRONTEND
: {
2450 struct dtv_frontend_properties getp
= fe
->dtv_property_cache
;
2453 * Let's use our own copy of property cache, in order to
2454 * avoid mangling with DTV zigzag logic, as drivers might
2455 * return crap, if they don't check if the data is available
2456 * before updating the properties cache.
2458 err
= dtv_get_frontend(fe
, &getp
, parg
);
2470 static unsigned int dvb_frontend_poll(struct file
*file
, struct poll_table_struct
*wait
)
2472 struct dvb_device
*dvbdev
= file
->private_data
;
2473 struct dvb_frontend
*fe
= dvbdev
->priv
;
2474 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2476 dev_dbg_ratelimited(fe
->dvb
->device
, "%s:\n", __func__
);
2478 poll_wait (file
, &fepriv
->events
.wait_queue
, wait
);
2480 if (fepriv
->events
.eventw
!= fepriv
->events
.eventr
)
2481 return (POLLIN
| POLLRDNORM
| POLLPRI
);
2486 static int dvb_frontend_open(struct inode
*inode
, struct file
*file
)
2488 struct dvb_device
*dvbdev
= file
->private_data
;
2489 struct dvb_frontend
*fe
= dvbdev
->priv
;
2490 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2491 struct dvb_adapter
*adapter
= fe
->dvb
;
2494 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2495 if (fe
->exit
== DVB_FE_DEVICE_REMOVED
)
2498 if (adapter
->mfe_shared
) {
2499 mutex_lock (&adapter
->mfe_lock
);
2501 if (adapter
->mfe_dvbdev
== NULL
)
2502 adapter
->mfe_dvbdev
= dvbdev
;
2504 else if (adapter
->mfe_dvbdev
!= dvbdev
) {
2506 *mfedev
= adapter
->mfe_dvbdev
;
2508 *mfe
= mfedev
->priv
;
2509 struct dvb_frontend_private
2510 *mfepriv
= mfe
->frontend_priv
;
2511 int mferetry
= (dvb_mfe_wait_time
<< 1);
2513 mutex_unlock (&adapter
->mfe_lock
);
2514 while (mferetry
-- && (mfedev
->users
!= -1 ||
2515 mfepriv
->thread
!= NULL
)) {
2516 if(msleep_interruptible(500)) {
2517 if(signal_pending(current
))
2522 mutex_lock (&adapter
->mfe_lock
);
2523 if(adapter
->mfe_dvbdev
!= dvbdev
) {
2524 mfedev
= adapter
->mfe_dvbdev
;
2526 mfepriv
= mfe
->frontend_priv
;
2527 if (mfedev
->users
!= -1 ||
2528 mfepriv
->thread
!= NULL
) {
2529 mutex_unlock (&adapter
->mfe_lock
);
2532 adapter
->mfe_dvbdev
= dvbdev
;
2537 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
) {
2538 if ((ret
= fe
->ops
.ts_bus_ctrl(fe
, 1)) < 0)
2541 /* If we took control of the bus, we need to force
2542 reinitialization. This is because many ts_bus_ctrl()
2543 functions strobe the RESET pin on the demod, and if the
2544 frontend thread already exists then the dvb_init() routine
2545 won't get called (which is what usually does initial
2546 register configuration). */
2547 fepriv
->reinitialise
= 1;
2550 if ((ret
= dvb_generic_open (inode
, file
)) < 0)
2553 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2554 /* normal tune mode when opened R/W */
2555 fepriv
->tune_mode_flags
&= ~FE_TUNE_MODE_ONESHOT
;
2557 fepriv
->voltage
= -1;
2559 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2560 if (fe
->dvb
->mdev
) {
2561 mutex_lock(&fe
->dvb
->mdev
->graph_mutex
);
2562 if (fe
->dvb
->mdev
->enable_source
)
2563 ret
= fe
->dvb
->mdev
->enable_source(
2566 mutex_unlock(&fe
->dvb
->mdev
->graph_mutex
);
2568 dev_err(fe
->dvb
->device
,
2569 "Tuner is busy. Error %d\n", ret
);
2574 ret
= dvb_frontend_start (fe
);
2578 /* empty event queue */
2579 fepriv
->events
.eventr
= fepriv
->events
.eventw
= 0;
2582 dvb_frontend_get(fe
);
2584 if (adapter
->mfe_shared
)
2585 mutex_unlock (&adapter
->mfe_lock
);
2589 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2590 if (fe
->dvb
->mdev
) {
2591 mutex_lock(&fe
->dvb
->mdev
->graph_mutex
);
2592 if (fe
->dvb
->mdev
->disable_source
)
2593 fe
->dvb
->mdev
->disable_source(dvbdev
->entity
);
2594 mutex_unlock(&fe
->dvb
->mdev
->graph_mutex
);
2598 dvb_generic_release(inode
, file
);
2600 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
)
2601 fe
->ops
.ts_bus_ctrl(fe
, 0);
2603 if (adapter
->mfe_shared
)
2604 mutex_unlock (&adapter
->mfe_lock
);
2608 static int dvb_frontend_release(struct inode
*inode
, struct file
*file
)
2610 struct dvb_device
*dvbdev
= file
->private_data
;
2611 struct dvb_frontend
*fe
= dvbdev
->priv
;
2612 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2615 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2617 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2618 fepriv
->release_jiffies
= jiffies
;
2622 ret
= dvb_generic_release (inode
, file
);
2624 if (dvbdev
->users
== -1) {
2625 wake_up(&fepriv
->wait_queue
);
2626 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2627 if (fe
->dvb
->mdev
) {
2628 mutex_lock(&fe
->dvb
->mdev
->graph_mutex
);
2629 if (fe
->dvb
->mdev
->disable_source
)
2630 fe
->dvb
->mdev
->disable_source(dvbdev
->entity
);
2631 mutex_unlock(&fe
->dvb
->mdev
->graph_mutex
);
2634 if (fe
->exit
!= DVB_FE_NO_EXIT
)
2635 wake_up(&dvbdev
->wait_queue
);
2636 if (fe
->ops
.ts_bus_ctrl
)
2637 fe
->ops
.ts_bus_ctrl(fe
, 0);
2640 dvb_frontend_put(fe
);
2645 static const struct file_operations dvb_frontend_fops
= {
2646 .owner
= THIS_MODULE
,
2647 .unlocked_ioctl
= dvb_generic_ioctl
,
2648 .poll
= dvb_frontend_poll
,
2649 .open
= dvb_frontend_open
,
2650 .release
= dvb_frontend_release
,
2651 .llseek
= noop_llseek
,
2654 int dvb_frontend_suspend(struct dvb_frontend
*fe
)
2658 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2661 if (fe
->ops
.tuner_ops
.suspend
)
2662 ret
= fe
->ops
.tuner_ops
.suspend(fe
);
2663 else if (fe
->ops
.tuner_ops
.sleep
)
2664 ret
= fe
->ops
.tuner_ops
.sleep(fe
);
2667 ret
= fe
->ops
.sleep(fe
);
2671 EXPORT_SYMBOL(dvb_frontend_suspend
);
2673 int dvb_frontend_resume(struct dvb_frontend
*fe
)
2675 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2678 dev_dbg(fe
->dvb
->device
, "%s: adap=%d fe=%d\n", __func__
, fe
->dvb
->num
,
2681 fe
->exit
= DVB_FE_DEVICE_RESUME
;
2683 ret
= fe
->ops
.init(fe
);
2685 if (fe
->ops
.tuner_ops
.resume
)
2686 ret
= fe
->ops
.tuner_ops
.resume(fe
);
2687 else if (fe
->ops
.tuner_ops
.init
)
2688 ret
= fe
->ops
.tuner_ops
.init(fe
);
2690 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
2691 fe
->ops
.set_tone(fe
, fepriv
->tone
);
2692 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
2693 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
2695 fe
->exit
= DVB_FE_NO_EXIT
;
2696 fepriv
->state
= FESTATE_RETUNE
;
2697 dvb_frontend_wakeup(fe
);
2701 EXPORT_SYMBOL(dvb_frontend_resume
);
2703 int dvb_register_frontend(struct dvb_adapter
* dvb
,
2704 struct dvb_frontend
* fe
)
2706 struct dvb_frontend_private
*fepriv
;
2707 const struct dvb_device dvbdev_template
= {
2711 .fops
= &dvb_frontend_fops
,
2712 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
2713 .name
= fe
->ops
.info
.name
,
2715 .kernel_ioctl
= dvb_frontend_ioctl
2718 dev_dbg(dvb
->device
, "%s:\n", __func__
);
2720 if (mutex_lock_interruptible(&frontend_mutex
))
2721 return -ERESTARTSYS
;
2723 fe
->frontend_priv
= kzalloc(sizeof(struct dvb_frontend_private
), GFP_KERNEL
);
2724 if (fe
->frontend_priv
== NULL
) {
2725 mutex_unlock(&frontend_mutex
);
2728 fepriv
= fe
->frontend_priv
;
2730 kref_init(&fe
->refcount
);
2733 * After initialization, there need to be two references: one
2734 * for dvb_unregister_frontend(), and another one for
2735 * dvb_frontend_detach().
2737 dvb_frontend_get(fe
);
2739 sema_init(&fepriv
->sem
, 1);
2740 init_waitqueue_head (&fepriv
->wait_queue
);
2741 init_waitqueue_head (&fepriv
->events
.wait_queue
);
2742 mutex_init(&fepriv
->events
.mtx
);
2744 fepriv
->inversion
= INVERSION_OFF
;
2746 dev_info(fe
->dvb
->device
,
2747 "DVB: registering adapter %i frontend %i (%s)...\n",
2748 fe
->dvb
->num
, fe
->id
, fe
->ops
.info
.name
);
2750 dvb_register_device (fe
->dvb
, &fepriv
->dvbdev
, &dvbdev_template
,
2751 fe
, DVB_DEVICE_FRONTEND
, 0);
2754 * Initialize the cache to the proper values according with the
2755 * first supported delivery system (ops->delsys[0])
2758 fe
->dtv_property_cache
.delivery_system
= fe
->ops
.delsys
[0];
2759 dvb_frontend_clear_cache(fe
);
2761 mutex_unlock(&frontend_mutex
);
2764 EXPORT_SYMBOL(dvb_register_frontend
);
2766 int dvb_unregister_frontend(struct dvb_frontend
* fe
)
2768 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2769 dev_dbg(fe
->dvb
->device
, "%s:\n", __func__
);
2771 mutex_lock(&frontend_mutex
);
2772 dvb_frontend_stop(fe
);
2773 dvb_remove_device(fepriv
->dvbdev
);
2775 /* fe is invalid now */
2776 mutex_unlock(&frontend_mutex
);
2777 dvb_frontend_put(fe
);
2780 EXPORT_SYMBOL(dvb_unregister_frontend
);
2782 static void dvb_frontend_invoke_release(struct dvb_frontend
*fe
,
2783 void (*release
)(struct dvb_frontend
*fe
))
2787 #ifdef CONFIG_MEDIA_ATTACH
2788 dvb_detach(release
);
2793 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2795 dvb_frontend_invoke_release(fe
, fe
->ops
.release_sec
);
2796 dvb_frontend_invoke_release(fe
, fe
->ops
.tuner_ops
.release
);
2797 dvb_frontend_invoke_release(fe
, fe
->ops
.analog_ops
.release
);
2798 dvb_frontend_invoke_release(fe
, fe
->ops
.detach
);
2799 dvb_frontend_put(fe
);
2801 EXPORT_SYMBOL(dvb_frontend_detach
);