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 <linux/compat.h>
44 #include <asm/processor.h>
46 #include <media/dvb_frontend.h>
47 #include <media/dvbdev.h>
48 #include <linux/dvb/version.h>
50 static int dvb_frontend_debug;
51 static int dvb_shutdown_timeout;
52 static int dvb_force_auto_inversion;
53 static int dvb_override_tune_delay;
54 static int dvb_powerdown_on_sleep = 1;
55 static int dvb_mfe_wait_time = 5;
57 module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
58 MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
59 module_param(dvb_shutdown_timeout, int, 0644);
60 MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
61 module_param(dvb_force_auto_inversion, int, 0644);
62 MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
63 module_param(dvb_override_tune_delay, int, 0644);
64 MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
65 module_param(dvb_powerdown_on_sleep, int, 0644);
66 MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
67 module_param(dvb_mfe_wait_time, int, 0644);
68 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)");
70 #define dprintk(fmt, arg...) \
71 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
73 #define FESTATE_IDLE 1
74 #define FESTATE_RETUNE 2
75 #define FESTATE_TUNING_FAST 4
76 #define FESTATE_TUNING_SLOW 8
77 #define FESTATE_TUNED 16
78 #define FESTATE_ZIGZAG_FAST 32
79 #define FESTATE_ZIGZAG_SLOW 64
80 #define FESTATE_DISEQC 128
81 #define FESTATE_ERROR 256
82 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
83 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
84 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
85 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
88 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
89 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
90 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
91 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
92 * FESTATE_TUNED. The frontend has successfully locked on.
93 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
94 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
95 * FESTATE_DISEQC. A DISEQC command has just been issued.
96 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
97 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
98 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
99 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
102 static DEFINE_MUTEX(frontend_mutex);
104 struct dvb_frontend_private {
105 /* thread/frontend values */
106 struct dvb_device *dvbdev;
107 struct dvb_frontend_parameters parameters_out;
108 struct dvb_fe_events events;
109 struct semaphore sem;
110 struct list_head list_head;
111 wait_queue_head_t wait_queue;
112 struct task_struct *thread;
113 unsigned long release_jiffies;
115 enum fe_status status;
116 unsigned long tune_mode_flags;
118 unsigned int reinitialise;
122 /* swzigzag values */
124 unsigned int bending;
126 unsigned int inversion;
127 unsigned int auto_step;
128 unsigned int auto_sub_step;
129 unsigned int started_auto_step;
130 unsigned int min_delay;
131 unsigned int max_drift;
132 unsigned int step_size;
134 unsigned int check_wrapped;
135 enum dvbfe_search algo_status;
137 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
138 struct media_pipeline pipe;
142 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
143 void (*release)(struct dvb_frontend *fe));
145 static void __dvb_frontend_free(struct dvb_frontend *fe)
147 struct dvb_frontend_private *fepriv = fe->frontend_priv;
150 dvb_device_put(fepriv->dvbdev);
152 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)
167 /* call detach before dropping the reference count */
171 * Check if the frontend was registered, as otherwise
172 * kref was not initialized yet.
174 if (fe->frontend_priv)
175 kref_put(&fe->refcount, dvb_frontend_free);
177 __dvb_frontend_free(fe);
180 static void dvb_frontend_get(struct dvb_frontend *fe)
182 kref_get(&fe->refcount);
185 static void dvb_frontend_wakeup(struct dvb_frontend *fe);
186 static int dtv_get_frontend(struct dvb_frontend *fe,
187 struct dtv_frontend_properties *c,
188 struct dvb_frontend_parameters *p_out);
190 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
191 const struct dtv_frontend_properties *c,
192 struct dvb_frontend_parameters *p);
194 static bool has_get_frontend(struct dvb_frontend *fe)
196 return fe->ops.get_frontend;
200 * Due to DVBv3 API calls, a delivery system should be mapped into one of
201 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
202 * otherwise, a DVBv3 call will fail.
204 enum dvbv3_emulation_type {
212 static enum dvbv3_emulation_type dvbv3_type(u32 delivery_system)
214 switch (delivery_system) {
215 case SYS_DVBC_ANNEX_A:
216 case SYS_DVBC_ANNEX_C:
231 case SYS_DVBC_ANNEX_B:
239 * Doesn't know how to emulate those types and/or
240 * there's no frontend driver from this type yet
241 * with some emulation code, so, we're not sure yet how
242 * to handle them, or they're not compatible with a DVBv3 call.
244 return DVBV3_UNKNOWN;
248 static void dvb_frontend_add_event(struct dvb_frontend *fe,
249 enum fe_status status)
251 struct dvb_frontend_private *fepriv = fe->frontend_priv;
252 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
253 struct dvb_fe_events *events = &fepriv->events;
254 struct dvb_frontend_event *e;
257 dev_dbg(fe->dvb->device, "%s:\n", __func__);
259 if ((status & FE_HAS_LOCK) && has_get_frontend(fe))
260 dtv_get_frontend(fe, c, &fepriv->parameters_out);
262 mutex_lock(&events->mtx);
264 wp = (events->eventw + 1) % MAX_EVENT;
265 if (wp == events->eventr) {
266 events->overflow = 1;
267 events->eventr = (events->eventr + 1) % MAX_EVENT;
270 e = &events->events[events->eventw];
272 e->parameters = fepriv->parameters_out;
276 mutex_unlock(&events->mtx);
278 wake_up_interruptible(&events->wait_queue);
281 static int dvb_frontend_test_event(struct dvb_frontend_private *fepriv,
282 struct dvb_fe_events *events)
287 ret = events->eventw != events->eventr;
293 static int dvb_frontend_get_event(struct dvb_frontend *fe,
294 struct dvb_frontend_event *event, int flags)
296 struct dvb_frontend_private *fepriv = fe->frontend_priv;
297 struct dvb_fe_events *events = &fepriv->events;
299 dev_dbg(fe->dvb->device, "%s:\n", __func__);
301 if (events->overflow) {
302 events->overflow = 0;
306 if (events->eventw == events->eventr) {
307 struct wait_queue_entry wait;
310 if (flags & O_NONBLOCK)
313 init_waitqueue_entry(&wait, current);
314 add_wait_queue(&events->wait_queue, &wait);
315 while (!dvb_frontend_test_event(fepriv, events)) {
316 wait_woken(&wait, TASK_INTERRUPTIBLE, 0);
317 if (signal_pending(current)) {
322 remove_wait_queue(&events->wait_queue, &wait);
327 mutex_lock(&events->mtx);
328 *event = events->events[events->eventr];
329 events->eventr = (events->eventr + 1) % MAX_EVENT;
330 mutex_unlock(&events->mtx);
335 static void dvb_frontend_clear_events(struct dvb_frontend *fe)
337 struct dvb_frontend_private *fepriv = fe->frontend_priv;
338 struct dvb_fe_events *events = &fepriv->events;
340 mutex_lock(&events->mtx);
341 events->eventr = events->eventw;
342 mutex_unlock(&events->mtx);
345 static void dvb_frontend_init(struct dvb_frontend *fe)
347 dev_dbg(fe->dvb->device,
348 "%s: initialising adapter %i frontend %i (%s)...\n",
349 __func__, fe->dvb->num, fe->id, fe->ops.info.name);
353 if (fe->ops.tuner_ops.init) {
354 if (fe->ops.i2c_gate_ctrl)
355 fe->ops.i2c_gate_ctrl(fe, 1);
356 fe->ops.tuner_ops.init(fe);
357 if (fe->ops.i2c_gate_ctrl)
358 fe->ops.i2c_gate_ctrl(fe, 0);
362 void dvb_frontend_reinitialise(struct dvb_frontend *fe)
364 struct dvb_frontend_private *fepriv = fe->frontend_priv;
366 fepriv->reinitialise = 1;
367 dvb_frontend_wakeup(fe);
369 EXPORT_SYMBOL(dvb_frontend_reinitialise);
371 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
374 struct dvb_frontend *fe = fepriv->dvbdev->priv;
376 dev_dbg(fe->dvb->device, "%s:\n", __func__);
379 (fepriv->quality) = (fepriv->quality * 220 + 36 * 256) / 256;
381 (fepriv->quality) = (fepriv->quality * 220 + 0) / 256;
383 q2 = fepriv->quality - 128;
386 fepriv->delay = fepriv->min_delay + q2 * HZ / (128 * 128);
390 * dvb_frontend_swzigzag_autotune - Performs automatic twiddling of frontend
393 * @fe: The frontend concerned.
394 * @check_wrapped: Checks if an iteration has completed.
395 * DO NOT SET ON THE FIRST ATTEMPT.
397 * return: Number of complete iterations that have been performed.
399 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped)
404 struct dvb_frontend_private *fepriv = fe->frontend_priv;
405 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
406 int original_inversion = c->inversion;
407 u32 original_frequency = c->frequency;
409 /* are we using autoinversion? */
410 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
411 (c->inversion == INVERSION_AUTO));
413 /* setup parameters correctly */
415 /* calculate the lnb_drift */
416 fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size;
418 /* wrap the auto_step if we've exceeded the maximum drift */
419 if (fepriv->lnb_drift > fepriv->max_drift) {
420 fepriv->auto_step = 0;
421 fepriv->auto_sub_step = 0;
422 fepriv->lnb_drift = 0;
425 /* perform inversion and +/- zigzag */
426 switch (fepriv->auto_sub_step) {
428 /* try with the current inversion and current drift setting */
433 if (!autoinversion) break;
435 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
440 if (fepriv->lnb_drift == 0) break;
442 fepriv->lnb_drift = -fepriv->lnb_drift;
447 if (fepriv->lnb_drift == 0) break;
448 if (!autoinversion) break;
450 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
451 fepriv->lnb_drift = -fepriv->lnb_drift;
457 fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */
461 if (!ready) fepriv->auto_sub_step++;
464 /* if this attempt would hit where we started, indicate a complete
465 * iteration has occurred */
466 if ((fepriv->auto_step == fepriv->started_auto_step) &&
467 (fepriv->auto_sub_step == 0) && check_wrapped) {
471 dev_dbg(fe->dvb->device,
472 "%s: drift:%i inversion:%i auto_step:%i auto_sub_step:%i started_auto_step:%i\n",
473 __func__, fepriv->lnb_drift, fepriv->inversion,
474 fepriv->auto_step, fepriv->auto_sub_step,
475 fepriv->started_auto_step);
477 /* set the frontend itself */
478 c->frequency += fepriv->lnb_drift;
480 c->inversion = fepriv->inversion;
482 if (fe->ops.set_frontend)
483 fe_set_err = fe->ops.set_frontend(fe);
485 if (fe_set_err < 0) {
486 fepriv->state = FESTATE_ERROR;
490 c->frequency = original_frequency;
491 c->inversion = original_inversion;
493 fepriv->auto_sub_step++;
497 static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
499 enum fe_status s = FE_NONE;
501 struct dvb_frontend_private *fepriv = fe->frontend_priv;
502 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
504 /* if we've got no parameters, just keep idling */
505 if (fepriv->state & FESTATE_IDLE) {
506 fepriv->delay = 3 * HZ;
511 /* in SCAN mode, we just set the frontend when asked and leave it alone */
512 if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) {
513 if (fepriv->state & FESTATE_RETUNE) {
515 if (fe->ops.set_frontend)
516 retval = fe->ops.set_frontend(fe);
519 fepriv->state = FESTATE_ERROR;
521 fepriv->state = FESTATE_TUNED;
523 fepriv->delay = 3 * HZ;
528 /* get the frontend status */
529 if (fepriv->state & FESTATE_RETUNE) {
532 if (fe->ops.read_status)
533 fe->ops.read_status(fe, &s);
534 if (s != fepriv->status) {
535 dvb_frontend_add_event(fe, s);
540 /* if we're not tuned, and we have a lock, move to the TUNED state */
541 if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) {
542 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
543 fepriv->state = FESTATE_TUNED;
545 /* if we're tuned, then we have determined the correct inversion */
546 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
547 (c->inversion == INVERSION_AUTO)) {
548 c->inversion = fepriv->inversion;
553 /* if we are tuned already, check we're still locked */
554 if (fepriv->state & FESTATE_TUNED) {
555 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
557 /* we're tuned, and the lock is still good... */
558 if (s & FE_HAS_LOCK) {
560 } else { /* if we _WERE_ tuned, but now don't have a lock */
561 fepriv->state = FESTATE_ZIGZAG_FAST;
562 fepriv->started_auto_step = fepriv->auto_step;
563 fepriv->check_wrapped = 0;
567 /* don't actually do anything if we're in the LOSTLOCK state,
568 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
569 if ((fepriv->state & FESTATE_LOSTLOCK) &&
570 (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) {
571 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
575 /* don't do anything if we're in the DISEQC state, since this
576 * might be someone with a motorized dish controlled by DISEQC.
577 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
578 if (fepriv->state & FESTATE_DISEQC) {
579 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
583 /* if we're in the RETUNE state, set everything up for a brand
584 * new scan, keeping the current inversion setting, as the next
585 * tune is _very_ likely to require the same */
586 if (fepriv->state & FESTATE_RETUNE) {
587 fepriv->lnb_drift = 0;
588 fepriv->auto_step = 0;
589 fepriv->auto_sub_step = 0;
590 fepriv->started_auto_step = 0;
591 fepriv->check_wrapped = 0;
595 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
596 fepriv->delay = fepriv->min_delay;
599 retval = dvb_frontend_swzigzag_autotune(fe,
600 fepriv->check_wrapped);
604 /* OK, if we've run out of trials at the fast speed.
605 * Drop back to slow for the _next_ attempt */
606 fepriv->state = FESTATE_SEARCHING_SLOW;
607 fepriv->started_auto_step = fepriv->auto_step;
610 fepriv->check_wrapped = 1;
612 /* if we've just re-tuned, enter the ZIGZAG_FAST state.
613 * This ensures we cannot return from an
614 * FE_SET_FRONTEND ioctl before the first frontend tune
616 if (fepriv->state & FESTATE_RETUNE) {
617 fepriv->state = FESTATE_TUNING_FAST;
622 if (fepriv->state & FESTATE_SEARCHING_SLOW) {
623 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
625 /* Note: don't bother checking for wrapping; we stay in this
626 * state until we get a lock */
627 dvb_frontend_swzigzag_autotune(fe, 0);
631 static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
633 struct dvb_frontend_private *fepriv = fe->frontend_priv;
635 if (fe->exit != DVB_FE_NO_EXIT)
638 if (fepriv->dvbdev->writers == 1)
639 if (time_after_eq(jiffies, fepriv->release_jiffies +
640 dvb_shutdown_timeout * HZ))
646 static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
648 struct dvb_frontend_private *fepriv = fe->frontend_priv;
650 if (fepriv->wakeup) {
654 return dvb_frontend_is_exiting(fe);
657 static void dvb_frontend_wakeup(struct dvb_frontend *fe)
659 struct dvb_frontend_private *fepriv = fe->frontend_priv;
662 wake_up_interruptible(&fepriv->wait_queue);
665 static int dvb_frontend_thread(void *data)
667 struct dvb_frontend *fe = data;
668 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
669 struct dvb_frontend_private *fepriv = fe->frontend_priv;
670 enum fe_status s = FE_NONE;
671 enum dvbfe_algo algo;
672 bool re_tune = false;
673 bool semheld = false;
675 dev_dbg(fe->dvb->device, "%s:\n", __func__);
677 fepriv->check_wrapped = 0;
679 fepriv->delay = 3 * HZ;
682 fepriv->reinitialise = 0;
684 dvb_frontend_init(fe);
688 up(&fepriv->sem); /* is locked when we enter the thread... */
690 wait_event_interruptible_timeout(fepriv->wait_queue,
691 dvb_frontend_should_wakeup(fe) ||
692 kthread_should_stop() ||
696 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
697 /* got signal or quitting */
698 if (!down_interruptible(&fepriv->sem))
700 fe->exit = DVB_FE_NORMAL_EXIT;
707 if (down_interruptible(&fepriv->sem))
710 if (fepriv->reinitialise) {
711 dvb_frontend_init(fe);
712 if (fe->ops.set_tone && fepriv->tone != -1)
713 fe->ops.set_tone(fe, fepriv->tone);
714 if (fe->ops.set_voltage && fepriv->voltage != -1)
715 fe->ops.set_voltage(fe, fepriv->voltage);
716 fepriv->reinitialise = 0;
719 /* do an iteration of the tuning loop */
720 if (fe->ops.get_frontend_algo) {
721 algo = fe->ops.get_frontend_algo(fe);
724 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__);
726 if (fepriv->state & FESTATE_RETUNE) {
727 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTATE_RETUNE\n", __func__);
729 fepriv->state = FESTATE_TUNED;
735 fe->ops.tune(fe, re_tune, fepriv->tune_mode_flags, &fepriv->delay, &s);
737 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
738 dev_dbg(fe->dvb->device, "%s: state changed, adding current state\n", __func__);
739 dvb_frontend_add_event(fe, s);
744 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__);
745 dvb_frontend_swzigzag(fe);
747 case DVBFE_ALGO_CUSTOM:
748 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
749 if (fepriv->state & FESTATE_RETUNE) {
750 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTAT_RETUNE\n", __func__);
751 fepriv->state = FESTATE_TUNED;
753 /* Case where we are going to search for a carrier
754 * User asked us to retune again for some reason, possibly
755 * requesting a search with a new set of parameters
757 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
758 if (fe->ops.search) {
759 fepriv->algo_status = fe->ops.search(fe);
760 /* We did do a search as was requested, the flags are
761 * now unset as well and has the flags wrt to search.
764 fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN;
767 /* Track the carrier if the search was successful */
768 if (fepriv->algo_status != DVBFE_ALGO_SEARCH_SUCCESS) {
769 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
770 fepriv->delay = HZ / 2;
772 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
773 fe->ops.read_status(fe, &s);
774 if (s != fepriv->status) {
775 dvb_frontend_add_event(fe, s); /* update event list */
777 if (!(s & FE_HAS_LOCK)) {
778 fepriv->delay = HZ / 10;
779 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
781 fepriv->delay = 60 * HZ;
786 dev_dbg(fe->dvb->device, "%s: UNDEFINED ALGO !\n", __func__);
790 dvb_frontend_swzigzag(fe);
794 if (dvb_powerdown_on_sleep) {
795 if (fe->ops.set_voltage)
796 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
797 if (fe->ops.tuner_ops.sleep) {
798 if (fe->ops.i2c_gate_ctrl)
799 fe->ops.i2c_gate_ctrl(fe, 1);
800 fe->ops.tuner_ops.sleep(fe);
801 if (fe->ops.i2c_gate_ctrl)
802 fe->ops.i2c_gate_ctrl(fe, 0);
808 fepriv->thread = NULL;
809 if (kthread_should_stop())
810 fe->exit = DVB_FE_DEVICE_REMOVED;
812 fe->exit = DVB_FE_NO_EXIT;
817 dvb_frontend_wakeup(fe);
821 static void dvb_frontend_stop(struct dvb_frontend *fe)
823 struct dvb_frontend_private *fepriv = fe->frontend_priv;
825 dev_dbg(fe->dvb->device, "%s:\n", __func__);
827 if (fe->exit != DVB_FE_DEVICE_REMOVED)
828 fe->exit = DVB_FE_NORMAL_EXIT;
834 kthread_stop(fepriv->thread);
836 sema_init(&fepriv->sem, 1);
837 fepriv->state = FESTATE_IDLE;
839 /* paranoia check in case a signal arrived */
841 dev_warn(fe->dvb->device,
842 "dvb_frontend_stop: warning: thread %p won't exit\n",
847 * Sleep for the amount of time given by add_usec parameter
849 * This needs to be as precise as possible, as it affects the detection of
850 * the dish tone command at the satellite subsystem. The precision is improved
851 * by using a scheduled msleep followed by udelay for the remainder.
853 void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
857 *waketime = ktime_add_us(*waketime, add_usec);
858 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
860 msleep((delta - 1500) / 1000);
861 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
866 EXPORT_SYMBOL(dvb_frontend_sleep_until);
868 static int dvb_frontend_start(struct dvb_frontend *fe)
871 struct dvb_frontend_private *fepriv = fe->frontend_priv;
872 struct task_struct *fe_thread;
874 dev_dbg(fe->dvb->device, "%s:\n", __func__);
876 if (fepriv->thread) {
877 if (fe->exit == DVB_FE_NO_EXIT)
880 dvb_frontend_stop(fe);
883 if (signal_pending(current))
885 if (down_interruptible(&fepriv->sem))
888 fepriv->state = FESTATE_IDLE;
889 fe->exit = DVB_FE_NO_EXIT;
890 fepriv->thread = NULL;
893 fe_thread = kthread_run(dvb_frontend_thread, fe,
894 "kdvb-ad-%i-fe-%i", fe->dvb->num, fe->id);
895 if (IS_ERR(fe_thread)) {
896 ret = PTR_ERR(fe_thread);
897 dev_warn(fe->dvb->device,
898 "dvb_frontend_start: failed to start kthread (%d)\n",
903 fepriv->thread = fe_thread;
907 static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe,
908 u32 *freq_min, u32 *freq_max,
911 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
912 u32 tuner_min = fe->ops.tuner_ops.info.frequency_min_hz;
913 u32 tuner_max = fe->ops.tuner_ops.info.frequency_max_hz;
914 u32 frontend_min = fe->ops.info.frequency_min_hz;
915 u32 frontend_max = fe->ops.info.frequency_max_hz;
917 *freq_min = max(frontend_min, tuner_min);
919 if (frontend_max == 0)
920 *freq_max = tuner_max;
921 else if (tuner_max == 0)
922 *freq_max = frontend_max;
924 *freq_max = min(frontend_max, tuner_max);
926 if (*freq_min == 0 || *freq_max == 0)
927 dev_warn(fe->dvb->device,
928 "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
929 fe->dvb->num, fe->id);
931 /* If the standard is for satellite, convert frequencies to kHz */
932 switch (c->delivery_system) {
940 *tolerance = fe->ops.info.frequency_tolerance_hz / kHz;
945 *tolerance = fe->ops.info.frequency_tolerance_hz;
950 static u32 dvb_frontend_get_stepsize(struct dvb_frontend *fe)
952 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
953 u32 fe_step = fe->ops.info.frequency_stepsize_hz;
954 u32 tuner_step = fe->ops.tuner_ops.info.frequency_step_hz;
955 u32 step = max(fe_step, tuner_step);
957 switch (c->delivery_system) {
971 static int dvb_frontend_check_parameters(struct dvb_frontend *fe)
973 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
977 /* range check: frequency */
978 dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max, NULL);
979 if ((freq_min && c->frequency < freq_min) ||
980 (freq_max && c->frequency > freq_max)) {
981 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
982 fe->dvb->num, fe->id, c->frequency,
987 /* range check: symbol rate */
988 switch (c->delivery_system) {
992 case SYS_DVBC_ANNEX_A:
993 case SYS_DVBC_ANNEX_C:
994 if ((fe->ops.info.symbol_rate_min &&
995 c->symbol_rate < fe->ops.info.symbol_rate_min) ||
996 (fe->ops.info.symbol_rate_max &&
997 c->symbol_rate > fe->ops.info.symbol_rate_max)) {
998 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
999 fe->dvb->num, fe->id, c->symbol_rate,
1000 fe->ops.info.symbol_rate_min,
1001 fe->ops.info.symbol_rate_max);
1011 static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
1013 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1017 delsys = c->delivery_system;
1018 memset(c, 0, offsetof(struct dtv_frontend_properties, strength));
1019 c->delivery_system = delsys;
1021 dev_dbg(fe->dvb->device, "%s: Clearing cache for delivery system %d\n",
1022 __func__, c->delivery_system);
1024 c->transmission_mode = TRANSMISSION_MODE_AUTO;
1025 c->bandwidth_hz = 0; /* AUTO */
1026 c->guard_interval = GUARD_INTERVAL_AUTO;
1027 c->hierarchy = HIERARCHY_AUTO;
1029 c->code_rate_HP = FEC_AUTO;
1030 c->code_rate_LP = FEC_AUTO;
1031 c->fec_inner = FEC_AUTO;
1032 c->rolloff = ROLLOFF_AUTO;
1033 c->voltage = SEC_VOLTAGE_OFF;
1034 c->sectone = SEC_TONE_OFF;
1035 c->pilot = PILOT_AUTO;
1037 c->isdbt_partial_reception = 0;
1038 c->isdbt_sb_mode = 0;
1039 c->isdbt_sb_subchannel = 0;
1040 c->isdbt_sb_segment_idx = 0;
1041 c->isdbt_sb_segment_count = 0;
1042 c->isdbt_layer_enabled = 7; /* All layers (A,B,C) */
1043 for (i = 0; i < 3; i++) {
1044 c->layer[i].fec = FEC_AUTO;
1045 c->layer[i].modulation = QAM_AUTO;
1046 c->layer[i].interleaving = 0;
1047 c->layer[i].segment_count = 0;
1050 c->stream_id = NO_STREAM_ID_FILTER;
1051 c->scrambling_sequence_index = 0;/* default sequence */
1053 switch (c->delivery_system) {
1057 c->modulation = QPSK; /* implied for DVB-S in legacy API */
1058 c->rolloff = ROLLOFF_35;/* implied for DVB-S */
1061 c->modulation = VSB_8;
1064 c->symbol_rate = 28860000;
1065 c->rolloff = ROLLOFF_35;
1066 c->bandwidth_hz = c->symbol_rate / 100 * 135;
1069 c->modulation = QAM_AUTO;
1078 #define _DTV_CMD(n, s, b) \
1087 char *name; /* A display name for debugging purposes */
1089 __u32 cmd; /* A unique ID */
1092 __u32 set:1; /* Either a set or get property */
1093 __u32 buffer:1; /* Does this property use the buffer? */
1094 __u32 reserved:30; /* Align */
1097 static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = {
1098 _DTV_CMD(DTV_TUNE, 1, 0),
1099 _DTV_CMD(DTV_CLEAR, 1, 0),
1102 _DTV_CMD(DTV_FREQUENCY, 1, 0),
1103 _DTV_CMD(DTV_BANDWIDTH_HZ, 1, 0),
1104 _DTV_CMD(DTV_MODULATION, 1, 0),
1105 _DTV_CMD(DTV_INVERSION, 1, 0),
1106 _DTV_CMD(DTV_DISEQC_MASTER, 1, 1),
1107 _DTV_CMD(DTV_SYMBOL_RATE, 1, 0),
1108 _DTV_CMD(DTV_INNER_FEC, 1, 0),
1109 _DTV_CMD(DTV_VOLTAGE, 1, 0),
1110 _DTV_CMD(DTV_TONE, 1, 0),
1111 _DTV_CMD(DTV_PILOT, 1, 0),
1112 _DTV_CMD(DTV_ROLLOFF, 1, 0),
1113 _DTV_CMD(DTV_DELIVERY_SYSTEM, 1, 0),
1114 _DTV_CMD(DTV_HIERARCHY, 1, 0),
1115 _DTV_CMD(DTV_CODE_RATE_HP, 1, 0),
1116 _DTV_CMD(DTV_CODE_RATE_LP, 1, 0),
1117 _DTV_CMD(DTV_GUARD_INTERVAL, 1, 0),
1118 _DTV_CMD(DTV_TRANSMISSION_MODE, 1, 0),
1119 _DTV_CMD(DTV_INTERLEAVING, 1, 0),
1121 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 1, 0),
1122 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 1, 0),
1123 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 1, 0),
1124 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 1, 0),
1125 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 1, 0),
1126 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 1, 0),
1127 _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 1, 0),
1128 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 1, 0),
1129 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 1, 0),
1130 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 1, 0),
1131 _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 1, 0),
1132 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 1, 0),
1133 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 1, 0),
1134 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 1, 0),
1135 _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 1, 0),
1136 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 1, 0),
1137 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 1, 0),
1138 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 1, 0),
1140 _DTV_CMD(DTV_STREAM_ID, 1, 0),
1141 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY, 1, 0),
1142 _DTV_CMD(DTV_SCRAMBLING_SEQUENCE_INDEX, 1, 0),
1143 _DTV_CMD(DTV_LNA, 1, 0),
1146 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY, 0, 1),
1147 _DTV_CMD(DTV_API_VERSION, 0, 0),
1149 _DTV_CMD(DTV_ENUM_DELSYS, 0, 0),
1151 _DTV_CMD(DTV_ATSCMH_PARADE_ID, 1, 0),
1152 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE, 1, 0),
1154 _DTV_CMD(DTV_ATSCMH_FIC_VER, 0, 0),
1155 _DTV_CMD(DTV_ATSCMH_NOG, 0, 0),
1156 _DTV_CMD(DTV_ATSCMH_TNOG, 0, 0),
1157 _DTV_CMD(DTV_ATSCMH_SGN, 0, 0),
1158 _DTV_CMD(DTV_ATSCMH_PRC, 0, 0),
1159 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE, 0, 0),
1160 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI, 0, 0),
1161 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC, 0, 0),
1162 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE, 0, 0),
1163 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A, 0, 0),
1164 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B, 0, 0),
1165 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C, 0, 0),
1166 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D, 0, 0),
1168 /* Statistics API */
1169 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH, 0, 0),
1170 _DTV_CMD(DTV_STAT_CNR, 0, 0),
1171 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT, 0, 0),
1172 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT, 0, 0),
1173 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT, 0, 0),
1174 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT, 0, 0),
1175 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT, 0, 0),
1176 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT, 0, 0),
1179 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1180 * drivers can use a single set_frontend tuning function, regardless of whether
1181 * it's being used for the legacy or new API, reducing code and complexity.
1183 static int dtv_property_cache_sync(struct dvb_frontend *fe,
1184 struct dtv_frontend_properties *c,
1185 const struct dvb_frontend_parameters *p)
1187 c->frequency = p->frequency;
1188 c->inversion = p->inversion;
1190 switch (dvbv3_type(c->delivery_system)) {
1192 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1193 c->symbol_rate = p->u.qpsk.symbol_rate;
1194 c->fec_inner = p->u.qpsk.fec_inner;
1197 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1198 c->symbol_rate = p->u.qam.symbol_rate;
1199 c->fec_inner = p->u.qam.fec_inner;
1200 c->modulation = p->u.qam.modulation;
1203 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1205 switch (p->u.ofdm.bandwidth) {
1206 case BANDWIDTH_10_MHZ:
1207 c->bandwidth_hz = 10000000;
1209 case BANDWIDTH_8_MHZ:
1210 c->bandwidth_hz = 8000000;
1212 case BANDWIDTH_7_MHZ:
1213 c->bandwidth_hz = 7000000;
1215 case BANDWIDTH_6_MHZ:
1216 c->bandwidth_hz = 6000000;
1218 case BANDWIDTH_5_MHZ:
1219 c->bandwidth_hz = 5000000;
1221 case BANDWIDTH_1_712_MHZ:
1222 c->bandwidth_hz = 1712000;
1224 case BANDWIDTH_AUTO:
1225 c->bandwidth_hz = 0;
1228 c->code_rate_HP = p->u.ofdm.code_rate_HP;
1229 c->code_rate_LP = p->u.ofdm.code_rate_LP;
1230 c->modulation = p->u.ofdm.constellation;
1231 c->transmission_mode = p->u.ofdm.transmission_mode;
1232 c->guard_interval = p->u.ofdm.guard_interval;
1233 c->hierarchy = p->u.ofdm.hierarchy_information;
1236 dev_dbg(fe->dvb->device, "%s: Preparing ATSC req\n", __func__);
1237 c->modulation = p->u.vsb.modulation;
1238 if (c->delivery_system == SYS_ATSCMH)
1240 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1241 c->delivery_system = SYS_ATSC;
1243 c->delivery_system = SYS_DVBC_ANNEX_B;
1246 dev_err(fe->dvb->device,
1247 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1248 __func__, c->delivery_system);
1255 /* Ensure the cached values are set correctly in the frontend
1256 * legacy tuning structures, for the advanced tuning API.
1259 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
1260 const struct dtv_frontend_properties *c,
1261 struct dvb_frontend_parameters *p)
1263 p->frequency = c->frequency;
1264 p->inversion = c->inversion;
1266 switch (dvbv3_type(c->delivery_system)) {
1268 dev_err(fe->dvb->device,
1269 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1270 __func__, c->delivery_system);
1273 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1274 p->u.qpsk.symbol_rate = c->symbol_rate;
1275 p->u.qpsk.fec_inner = c->fec_inner;
1278 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1279 p->u.qam.symbol_rate = c->symbol_rate;
1280 p->u.qam.fec_inner = c->fec_inner;
1281 p->u.qam.modulation = c->modulation;
1284 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1285 switch (c->bandwidth_hz) {
1287 p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ;
1290 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1293 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1296 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1299 p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ;
1302 p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ;
1306 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1308 p->u.ofdm.code_rate_HP = c->code_rate_HP;
1309 p->u.ofdm.code_rate_LP = c->code_rate_LP;
1310 p->u.ofdm.constellation = c->modulation;
1311 p->u.ofdm.transmission_mode = c->transmission_mode;
1312 p->u.ofdm.guard_interval = c->guard_interval;
1313 p->u.ofdm.hierarchy_information = c->hierarchy;
1316 dev_dbg(fe->dvb->device, "%s: Preparing VSB req\n", __func__);
1317 p->u.vsb.modulation = c->modulation;
1324 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1325 * @fe: struct dvb_frontend pointer
1326 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1327 * @p_out: struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1329 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1330 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1331 * If p_out is not null, it will update the DVBv3 params pointed by it.
1333 static int dtv_get_frontend(struct dvb_frontend *fe,
1334 struct dtv_frontend_properties *c,
1335 struct dvb_frontend_parameters *p_out)
1339 if (fe->ops.get_frontend) {
1340 r = fe->ops.get_frontend(fe, c);
1341 if (unlikely(r < 0))
1344 dtv_property_legacy_params_sync(fe, c, p_out);
1348 /* As everything is in cache, get_frontend fops are always supported */
1352 static int dvb_frontend_handle_ioctl(struct file *file,
1353 unsigned int cmd, void *parg);
1355 static int dtv_property_process_get(struct dvb_frontend *fe,
1356 const struct dtv_frontend_properties *c,
1357 struct dtv_property *tvp,
1363 case DTV_ENUM_DELSYS:
1365 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1366 tvp->u.buffer.data[ncaps] = fe->ops.delsys[ncaps];
1369 tvp->u.buffer.len = ncaps;
1372 tvp->u.data = c->frequency;
1374 case DTV_MODULATION:
1375 tvp->u.data = c->modulation;
1377 case DTV_BANDWIDTH_HZ:
1378 tvp->u.data = c->bandwidth_hz;
1381 tvp->u.data = c->inversion;
1383 case DTV_SYMBOL_RATE:
1384 tvp->u.data = c->symbol_rate;
1387 tvp->u.data = c->fec_inner;
1390 tvp->u.data = c->pilot;
1393 tvp->u.data = c->rolloff;
1395 case DTV_DELIVERY_SYSTEM:
1396 tvp->u.data = c->delivery_system;
1399 tvp->u.data = c->voltage;
1402 tvp->u.data = c->sectone;
1404 case DTV_API_VERSION:
1405 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1407 case DTV_CODE_RATE_HP:
1408 tvp->u.data = c->code_rate_HP;
1410 case DTV_CODE_RATE_LP:
1411 tvp->u.data = c->code_rate_LP;
1413 case DTV_GUARD_INTERVAL:
1414 tvp->u.data = c->guard_interval;
1416 case DTV_TRANSMISSION_MODE:
1417 tvp->u.data = c->transmission_mode;
1420 tvp->u.data = c->hierarchy;
1422 case DTV_INTERLEAVING:
1423 tvp->u.data = c->interleaving;
1426 /* ISDB-T Support here */
1427 case DTV_ISDBT_PARTIAL_RECEPTION:
1428 tvp->u.data = c->isdbt_partial_reception;
1430 case DTV_ISDBT_SOUND_BROADCASTING:
1431 tvp->u.data = c->isdbt_sb_mode;
1433 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1434 tvp->u.data = c->isdbt_sb_subchannel;
1436 case DTV_ISDBT_SB_SEGMENT_IDX:
1437 tvp->u.data = c->isdbt_sb_segment_idx;
1439 case DTV_ISDBT_SB_SEGMENT_COUNT:
1440 tvp->u.data = c->isdbt_sb_segment_count;
1442 case DTV_ISDBT_LAYER_ENABLED:
1443 tvp->u.data = c->isdbt_layer_enabled;
1445 case DTV_ISDBT_LAYERA_FEC:
1446 tvp->u.data = c->layer[0].fec;
1448 case DTV_ISDBT_LAYERA_MODULATION:
1449 tvp->u.data = c->layer[0].modulation;
1451 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1452 tvp->u.data = c->layer[0].segment_count;
1454 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1455 tvp->u.data = c->layer[0].interleaving;
1457 case DTV_ISDBT_LAYERB_FEC:
1458 tvp->u.data = c->layer[1].fec;
1460 case DTV_ISDBT_LAYERB_MODULATION:
1461 tvp->u.data = c->layer[1].modulation;
1463 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1464 tvp->u.data = c->layer[1].segment_count;
1466 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1467 tvp->u.data = c->layer[1].interleaving;
1469 case DTV_ISDBT_LAYERC_FEC:
1470 tvp->u.data = c->layer[2].fec;
1472 case DTV_ISDBT_LAYERC_MODULATION:
1473 tvp->u.data = c->layer[2].modulation;
1475 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1476 tvp->u.data = c->layer[2].segment_count;
1478 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1479 tvp->u.data = c->layer[2].interleaving;
1482 /* Multistream support */
1484 case DTV_DVBT2_PLP_ID_LEGACY:
1485 tvp->u.data = c->stream_id;
1488 /* Physical layer scrambling support */
1489 case DTV_SCRAMBLING_SEQUENCE_INDEX:
1490 tvp->u.data = c->scrambling_sequence_index;
1494 case DTV_ATSCMH_FIC_VER:
1495 tvp->u.data = fe->dtv_property_cache.atscmh_fic_ver;
1497 case DTV_ATSCMH_PARADE_ID:
1498 tvp->u.data = fe->dtv_property_cache.atscmh_parade_id;
1500 case DTV_ATSCMH_NOG:
1501 tvp->u.data = fe->dtv_property_cache.atscmh_nog;
1503 case DTV_ATSCMH_TNOG:
1504 tvp->u.data = fe->dtv_property_cache.atscmh_tnog;
1506 case DTV_ATSCMH_SGN:
1507 tvp->u.data = fe->dtv_property_cache.atscmh_sgn;
1509 case DTV_ATSCMH_PRC:
1510 tvp->u.data = fe->dtv_property_cache.atscmh_prc;
1512 case DTV_ATSCMH_RS_FRAME_MODE:
1513 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_mode;
1515 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
1516 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_ensemble;
1518 case DTV_ATSCMH_RS_CODE_MODE_PRI:
1519 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_pri;
1521 case DTV_ATSCMH_RS_CODE_MODE_SEC:
1522 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_sec;
1524 case DTV_ATSCMH_SCCC_BLOCK_MODE:
1525 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_block_mode;
1527 case DTV_ATSCMH_SCCC_CODE_MODE_A:
1528 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_a;
1530 case DTV_ATSCMH_SCCC_CODE_MODE_B:
1531 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_b;
1533 case DTV_ATSCMH_SCCC_CODE_MODE_C:
1534 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_c;
1536 case DTV_ATSCMH_SCCC_CODE_MODE_D:
1537 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_d;
1541 tvp->u.data = c->lna;
1544 /* Fill quality measures */
1545 case DTV_STAT_SIGNAL_STRENGTH:
1546 tvp->u.st = c->strength;
1551 case DTV_STAT_PRE_ERROR_BIT_COUNT:
1552 tvp->u.st = c->pre_bit_error;
1554 case DTV_STAT_PRE_TOTAL_BIT_COUNT:
1555 tvp->u.st = c->pre_bit_count;
1557 case DTV_STAT_POST_ERROR_BIT_COUNT:
1558 tvp->u.st = c->post_bit_error;
1560 case DTV_STAT_POST_TOTAL_BIT_COUNT:
1561 tvp->u.st = c->post_bit_count;
1563 case DTV_STAT_ERROR_BLOCK_COUNT:
1564 tvp->u.st = c->block_error;
1566 case DTV_STAT_TOTAL_BLOCK_COUNT:
1567 tvp->u.st = c->block_count;
1570 dev_dbg(fe->dvb->device,
1571 "%s: FE property %d doesn't exist\n",
1572 __func__, tvp->cmd);
1576 if (!dtv_cmds[tvp->cmd].buffer)
1577 dev_dbg(fe->dvb->device,
1578 "%s: GET cmd 0x%08x (%s) = 0x%08x\n",
1579 __func__, tvp->cmd, dtv_cmds[tvp->cmd].name,
1582 dev_dbg(fe->dvb->device,
1583 "%s: GET cmd 0x%08x (%s) len %d: %*ph\n",
1585 tvp->cmd, dtv_cmds[tvp->cmd].name,
1587 tvp->u.buffer.len, tvp->u.buffer.data);
1592 static int dtv_set_frontend(struct dvb_frontend *fe);
1594 static bool is_dvbv3_delsys(u32 delsys)
1596 return (delsys == SYS_DVBT) || (delsys == SYS_DVBC_ANNEX_A) ||
1597 (delsys == SYS_DVBS) || (delsys == SYS_ATSC);
1601 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1602 * @fe: struct frontend;
1603 * @delsys: DVBv5 type that will be used for emulation
1605 * Provides emulation for delivery systems that are compatible with the old
1606 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1607 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontent
1608 * parameters are compatible with DVB-S spec.
1610 static int emulate_delivery_system(struct dvb_frontend *fe, u32 delsys)
1613 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1615 c->delivery_system = delsys;
1618 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1620 if (c->delivery_system == SYS_ISDBT) {
1621 dev_dbg(fe->dvb->device,
1622 "%s: Using defaults for SYS_ISDBT\n",
1625 if (!c->bandwidth_hz)
1626 c->bandwidth_hz = 6000000;
1628 c->isdbt_partial_reception = 0;
1629 c->isdbt_sb_mode = 0;
1630 c->isdbt_sb_subchannel = 0;
1631 c->isdbt_sb_segment_idx = 0;
1632 c->isdbt_sb_segment_count = 0;
1633 c->isdbt_layer_enabled = 7;
1634 for (i = 0; i < 3; i++) {
1635 c->layer[i].fec = FEC_AUTO;
1636 c->layer[i].modulation = QAM_AUTO;
1637 c->layer[i].interleaving = 0;
1638 c->layer[i].segment_count = 0;
1641 dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n",
1642 __func__, c->delivery_system);
1648 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1649 * @fe: frontend struct
1650 * @desired_system: delivery system requested by the user
1652 * A DVBv5 call know what's the desired system it wants. So, set it.
1654 * There are, however, a few known issues with early DVBv5 applications that
1655 * are also handled by this logic:
1657 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1658 * This is an API violation, but, as we don't want to break userspace,
1659 * convert it to the first supported delivery system.
1660 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1661 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1662 * ISDB-T provided backward compat with DVB-T.
1664 static int dvbv5_set_delivery_system(struct dvb_frontend *fe,
1668 u32 delsys = SYS_UNDEFINED;
1669 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1670 enum dvbv3_emulation_type type;
1673 * It was reported that some old DVBv5 applications were
1674 * filling delivery_system with SYS_UNDEFINED. If this happens,
1675 * assume that the application wants to use the first supported
1678 if (desired_system == SYS_UNDEFINED)
1679 desired_system = fe->ops.delsys[0];
1682 * This is a DVBv5 call. So, it likely knows the supported
1683 * delivery systems. So, check if the desired delivery system is
1687 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1688 if (fe->ops.delsys[ncaps] == desired_system) {
1689 c->delivery_system = desired_system;
1690 dev_dbg(fe->dvb->device,
1691 "%s: Changing delivery system to %d\n",
1692 __func__, desired_system);
1699 * The requested delivery system isn't supported. Maybe userspace
1700 * is requesting a DVBv3 compatible delivery system.
1702 * The emulation only works if the desired system is one of the
1703 * delivery systems supported by DVBv3 API
1705 if (!is_dvbv3_delsys(desired_system)) {
1706 dev_dbg(fe->dvb->device,
1707 "%s: Delivery system %d not supported.\n",
1708 __func__, desired_system);
1712 type = dvbv3_type(desired_system);
1715 * Get the last non-DVBv3 delivery system that has the same type
1716 * of the desired system
1719 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1720 if (dvbv3_type(fe->ops.delsys[ncaps]) == type)
1721 delsys = fe->ops.delsys[ncaps];
1725 /* There's nothing compatible with the desired delivery system */
1726 if (delsys == SYS_UNDEFINED) {
1727 dev_dbg(fe->dvb->device,
1728 "%s: Delivery system %d not supported on emulation mode.\n",
1729 __func__, desired_system);
1733 dev_dbg(fe->dvb->device,
1734 "%s: Using delivery system %d emulated as if it were %d\n",
1735 __func__, delsys, desired_system);
1737 return emulate_delivery_system(fe, desired_system);
1741 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1742 * @fe: frontend struct
1744 * A DVBv3 call doesn't know what's the desired system it wants. It also
1745 * doesn't allow to switch between different types. Due to that, userspace
1746 * should use DVBv5 instead.
1747 * However, in order to avoid breaking userspace API, limited backward
1748 * compatibility support is provided.
1750 * There are some delivery systems that are incompatible with DVBv3 calls.
1752 * This routine should work fine for frontends that support just one delivery
1755 * For frontends that support multiple frontends:
1756 * 1) It defaults to use the first supported delivery system. There's an
1757 * userspace application that allows changing it at runtime;
1759 * 2) If the current delivery system is not compatible with DVBv3, it gets
1760 * the first one that it is compatible.
1762 * NOTE: in order for this to work with applications like Kaffeine that
1763 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1764 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1765 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1768 static int dvbv3_set_delivery_system(struct dvb_frontend *fe)
1771 u32 delsys = SYS_UNDEFINED;
1772 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1774 /* If not set yet, defaults to the first supported delivery system */
1775 if (c->delivery_system == SYS_UNDEFINED)
1776 c->delivery_system = fe->ops.delsys[0];
1779 * Trivial case: just use the current one, if it already a DVBv3
1782 if (is_dvbv3_delsys(c->delivery_system)) {
1783 dev_dbg(fe->dvb->device,
1784 "%s: Using delivery system to %d\n",
1785 __func__, c->delivery_system);
1790 * Seek for the first delivery system that it is compatible with a
1794 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1795 if (dvbv3_type(fe->ops.delsys[ncaps]) != DVBV3_UNKNOWN) {
1796 delsys = fe->ops.delsys[ncaps];
1801 if (delsys == SYS_UNDEFINED) {
1802 dev_dbg(fe->dvb->device,
1803 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1807 return emulate_delivery_system(fe, delsys);
1811 * dtv_property_process_set - Sets a single DTV property
1812 * @fe: Pointer to &struct dvb_frontend
1813 * @file: Pointer to &struct file
1814 * @cmd: Digital TV command
1815 * @data: An unsigned 32-bits number
1817 * This routine assigns the property
1818 * value to the corresponding member of
1819 * &struct dtv_frontend_properties
1822 * Zero on success, negative errno on failure.
1824 static int dtv_property_process_set(struct dvb_frontend *fe,
1829 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1831 /** Dump DTV command name and value*/
1832 if (!cmd || cmd > DTV_MAX_COMMAND)
1833 dev_warn(fe->dvb->device, "%s: SET cmd 0x%08x undefined\n",
1836 dev_dbg(fe->dvb->device,
1837 "%s: SET cmd 0x%08x (%s) to 0x%08x\n",
1838 __func__, cmd, dtv_cmds[cmd].name, data);
1842 * Reset a cache of data specific to the frontend here. This does
1843 * not effect hardware.
1845 dvb_frontend_clear_cache(fe);
1849 * Use the cached Digital TV properties to tune the
1852 dev_dbg(fe->dvb->device,
1853 "%s: Setting the frontend from property cache\n",
1856 r = dtv_set_frontend(fe);
1859 c->frequency = data;
1861 case DTV_MODULATION:
1862 c->modulation = data;
1864 case DTV_BANDWIDTH_HZ:
1865 c->bandwidth_hz = data;
1868 c->inversion = data;
1870 case DTV_SYMBOL_RATE:
1871 c->symbol_rate = data;
1874 c->fec_inner = data;
1882 case DTV_DELIVERY_SYSTEM:
1883 r = dvbv5_set_delivery_system(fe, data);
1887 r = dvb_frontend_handle_ioctl(file, FE_SET_VOLTAGE,
1888 (void *)c->voltage);
1892 r = dvb_frontend_handle_ioctl(file, FE_SET_TONE,
1893 (void *)c->sectone);
1895 case DTV_CODE_RATE_HP:
1896 c->code_rate_HP = data;
1898 case DTV_CODE_RATE_LP:
1899 c->code_rate_LP = data;
1901 case DTV_GUARD_INTERVAL:
1902 c->guard_interval = data;
1904 case DTV_TRANSMISSION_MODE:
1905 c->transmission_mode = data;
1908 c->hierarchy = data;
1910 case DTV_INTERLEAVING:
1911 c->interleaving = data;
1914 /* ISDB-T Support here */
1915 case DTV_ISDBT_PARTIAL_RECEPTION:
1916 c->isdbt_partial_reception = data;
1918 case DTV_ISDBT_SOUND_BROADCASTING:
1919 c->isdbt_sb_mode = data;
1921 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1922 c->isdbt_sb_subchannel = data;
1924 case DTV_ISDBT_SB_SEGMENT_IDX:
1925 c->isdbt_sb_segment_idx = data;
1927 case DTV_ISDBT_SB_SEGMENT_COUNT:
1928 c->isdbt_sb_segment_count = data;
1930 case DTV_ISDBT_LAYER_ENABLED:
1931 c->isdbt_layer_enabled = data;
1933 case DTV_ISDBT_LAYERA_FEC:
1934 c->layer[0].fec = data;
1936 case DTV_ISDBT_LAYERA_MODULATION:
1937 c->layer[0].modulation = data;
1939 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1940 c->layer[0].segment_count = data;
1942 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1943 c->layer[0].interleaving = data;
1945 case DTV_ISDBT_LAYERB_FEC:
1946 c->layer[1].fec = data;
1948 case DTV_ISDBT_LAYERB_MODULATION:
1949 c->layer[1].modulation = data;
1951 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1952 c->layer[1].segment_count = data;
1954 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1955 c->layer[1].interleaving = data;
1957 case DTV_ISDBT_LAYERC_FEC:
1958 c->layer[2].fec = data;
1960 case DTV_ISDBT_LAYERC_MODULATION:
1961 c->layer[2].modulation = data;
1963 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1964 c->layer[2].segment_count = data;
1966 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1967 c->layer[2].interleaving = data;
1970 /* Multistream support */
1972 case DTV_DVBT2_PLP_ID_LEGACY:
1973 c->stream_id = data;
1976 /* Physical layer scrambling support */
1977 case DTV_SCRAMBLING_SEQUENCE_INDEX:
1978 c->scrambling_sequence_index = data;
1982 case DTV_ATSCMH_PARADE_ID:
1983 fe->dtv_property_cache.atscmh_parade_id = data;
1985 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
1986 fe->dtv_property_cache.atscmh_rs_frame_ensemble = data;
1991 if (fe->ops.set_lna)
1992 r = fe->ops.set_lna(fe);
2004 static int dvb_frontend_do_ioctl(struct file *file, unsigned int cmd,
2007 struct dvb_device *dvbdev = file->private_data;
2008 struct dvb_frontend *fe = dvbdev->priv;
2009 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2012 dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd));
2013 if (down_interruptible(&fepriv->sem))
2014 return -ERESTARTSYS;
2016 if (fe->exit != DVB_FE_NO_EXIT) {
2022 * If the frontend is opened in read-only mode, only the ioctls
2023 * that don't interfere with the tune logic should be accepted.
2024 * That allows an external application to monitor the DVB QoS and
2025 * statistics parameters.
2027 * That matches all _IOR() ioctls, except for two special cases:
2028 * - FE_GET_EVENT is part of the tuning logic on a DVB application;
2029 * - FE_DISEQC_RECV_SLAVE_REPLY is part of DiSEqC 2.0
2031 * So, those two ioctls should also return -EPERM, as otherwise
2032 * reading from them would interfere with a DVB tune application
2034 if ((file->f_flags & O_ACCMODE) == O_RDONLY
2035 && (_IOC_DIR(cmd) != _IOC_READ
2036 || cmd == FE_GET_EVENT
2037 || cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
2042 err = dvb_frontend_handle_ioctl(file, cmd, parg);
2048 static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
2051 struct dvb_device *dvbdev = file->private_data;
2056 return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
2059 #ifdef CONFIG_COMPAT
2060 struct compat_dtv_property {
2065 struct dtv_fe_stats st;
2070 compat_uptr_t reserved2;
2074 } __attribute__ ((packed));
2076 struct compat_dtv_properties {
2078 compat_uptr_t props;
2081 #define COMPAT_FE_SET_PROPERTY _IOW('o', 82, struct compat_dtv_properties)
2082 #define COMPAT_FE_GET_PROPERTY _IOR('o', 83, struct compat_dtv_properties)
2084 static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
2087 struct dvb_device *dvbdev = file->private_data;
2088 struct dvb_frontend *fe = dvbdev->priv;
2089 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2092 if (cmd == COMPAT_FE_SET_PROPERTY) {
2093 struct compat_dtv_properties prop, *tvps = NULL;
2094 struct compat_dtv_property *tvp = NULL;
2096 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2102 * Put an arbitrary limit on the number of messages that can
2105 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2108 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2110 return PTR_ERR(tvp);
2112 for (i = 0; i < tvps->num; i++) {
2113 err = dtv_property_process_set(fe, file,
2122 } else if (cmd == COMPAT_FE_GET_PROPERTY) {
2123 struct compat_dtv_properties prop, *tvps = NULL;
2124 struct compat_dtv_property *tvp = NULL;
2125 struct dtv_frontend_properties getp = fe->dtv_property_cache;
2127 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2133 * Put an arbitrary limit on the number of messages that can
2136 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2139 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2141 return PTR_ERR(tvp);
2144 * Let's use our own copy of property cache, in order to
2145 * avoid mangling with DTV zigzag logic, as drivers might
2146 * return crap, if they don't check if the data is available
2147 * before updating the properties cache.
2149 if (fepriv->state != FESTATE_IDLE) {
2150 err = dtv_get_frontend(fe, &getp, NULL);
2156 for (i = 0; i < tvps->num; i++) {
2157 err = dtv_property_process_get(
2158 fe, &getp, (struct dtv_property *)(tvp + i), file);
2165 if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
2166 tvps->num * sizeof(struct compat_dtv_property))) {
2176 static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
2179 struct dvb_device *dvbdev = file->private_data;
2180 struct dvb_frontend *fe = dvbdev->priv;
2181 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2184 if (cmd == COMPAT_FE_SET_PROPERTY || cmd == COMPAT_FE_GET_PROPERTY) {
2185 if (down_interruptible(&fepriv->sem))
2186 return -ERESTARTSYS;
2188 err = dvb_frontend_handle_compat_ioctl(file, cmd, arg);
2194 return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
2198 static int dtv_set_frontend(struct dvb_frontend *fe)
2200 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2201 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2202 struct dvb_frontend_tune_settings fetunesettings;
2205 if (dvb_frontend_check_parameters(fe) < 0)
2209 * Initialize output parameters to match the values given by
2210 * the user. FE_SET_FRONTEND triggers an initial frontend event
2211 * with status = 0, which copies output parameters to userspace.
2213 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
2216 * Be sure that the bandwidth will be filled for all
2217 * non-satellite systems, as tuners need to know what
2218 * low pass/Nyquist half filter should be applied, in
2219 * order to avoid inter-channel noise.
2221 * ISDB-T and DVB-T/T2 already sets bandwidth.
2222 * ATSC and DVB-C don't set, so, the core should fill it.
2224 * On DVB-C Annex A and C, the bandwidth is a function of
2225 * the roll-off and symbol rate. Annex B defines different
2226 * roll-off factors depending on the modulation. Fortunately,
2227 * Annex B is only used with 6MHz, so there's no need to
2230 * While not officially supported, a side effect of handling it at
2231 * the cache level is that a program could retrieve the bandwidth
2232 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2234 switch (c->delivery_system) {
2236 case SYS_DVBC_ANNEX_B:
2237 c->bandwidth_hz = 6000000;
2239 case SYS_DVBC_ANNEX_A:
2242 case SYS_DVBC_ANNEX_C:
2251 switch (c->rolloff) {
2267 c->bandwidth_hz = mult_frac(c->symbol_rate, rolloff, 100);
2269 /* force auto frequency inversion if requested */
2270 if (dvb_force_auto_inversion)
2271 c->inversion = INVERSION_AUTO;
2274 * without hierarchical coding code_rate_LP is irrelevant,
2275 * so we tolerate the otherwise invalid FEC_NONE setting
2277 if (c->hierarchy == HIERARCHY_NONE && c->code_rate_LP == FEC_NONE)
2278 c->code_rate_LP = FEC_AUTO;
2280 /* get frontend-specific tuning settings */
2281 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
2282 if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) {
2283 fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000;
2284 fepriv->max_drift = fetunesettings.max_drift;
2285 fepriv->step_size = fetunesettings.step_size;
2287 /* default values */
2288 switch (c->delivery_system) {
2293 case SYS_DVBC_ANNEX_A:
2294 case SYS_DVBC_ANNEX_C:
2295 fepriv->min_delay = HZ / 20;
2296 fepriv->step_size = c->symbol_rate / 16000;
2297 fepriv->max_drift = c->symbol_rate / 2000;
2303 fepriv->min_delay = HZ / 20;
2304 fepriv->step_size = dvb_frontend_get_stepsize(fe) * 2;
2305 fepriv->max_drift = (dvb_frontend_get_stepsize(fe) * 2) + 1;
2309 * FIXME: This sounds wrong! if freqency_stepsize is
2310 * defined by the frontend, why not use it???
2312 fepriv->min_delay = HZ / 20;
2313 fepriv->step_size = 0; /* no zigzag */
2314 fepriv->max_drift = 0;
2318 if (dvb_override_tune_delay > 0)
2319 fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000;
2321 fepriv->state = FESTATE_RETUNE;
2323 /* Request the search algorithm to search */
2324 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
2326 dvb_frontend_clear_events(fe);
2327 dvb_frontend_add_event(fe, 0);
2328 dvb_frontend_wakeup(fe);
2334 static int dvb_frontend_handle_ioctl(struct file *file,
2335 unsigned int cmd, void *parg)
2337 struct dvb_device *dvbdev = file->private_data;
2338 struct dvb_frontend *fe = dvbdev->priv;
2339 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2340 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2341 int i, err = -ENOTSUPP;
2343 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2346 case FE_SET_PROPERTY: {
2347 struct dtv_properties *tvps = parg;
2348 struct dtv_property *tvp = NULL;
2350 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2351 __func__, tvps->num);
2352 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2353 __func__, tvps->props);
2356 * Put an arbitrary limit on the number of messages that can
2359 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2362 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2364 return PTR_ERR(tvp);
2366 for (i = 0; i < tvps->num; i++) {
2367 err = dtv_property_process_set(fe, file,
2379 case FE_GET_PROPERTY: {
2380 struct dtv_properties *tvps = parg;
2381 struct dtv_property *tvp = NULL;
2382 struct dtv_frontend_properties getp = fe->dtv_property_cache;
2384 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2385 __func__, tvps->num);
2386 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2387 __func__, tvps->props);
2390 * Put an arbitrary limit on the number of messages that can
2393 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2396 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2398 return PTR_ERR(tvp);
2401 * Let's use our own copy of property cache, in order to
2402 * avoid mangling with DTV zigzag logic, as drivers might
2403 * return crap, if they don't check if the data is available
2404 * before updating the properties cache.
2406 if (fepriv->state != FESTATE_IDLE) {
2407 err = dtv_get_frontend(fe, &getp, NULL);
2413 for (i = 0; i < tvps->num; i++) {
2414 err = dtv_property_process_get(fe, &getp,
2422 if (copy_to_user((void __user *)tvps->props, tvp,
2423 tvps->num * sizeof(struct dtv_property))) {
2433 struct dvb_frontend_info *info = parg;
2434 memset(info, 0, sizeof(*info));
2436 strcpy(info->name, fe->ops.info.name);
2437 info->symbol_rate_min = fe->ops.info.symbol_rate_min;
2438 info->symbol_rate_max = fe->ops.info.symbol_rate_max;
2439 info->symbol_rate_tolerance = fe->ops.info.symbol_rate_tolerance;
2440 info->caps = fe->ops.info.caps;
2441 info->frequency_stepsize = dvb_frontend_get_stepsize(fe);
2442 dvb_frontend_get_frequency_limits(fe, &info->frequency_min,
2443 &info->frequency_max,
2444 &info->frequency_tolerance);
2447 * Associate the 4 delivery systems supported by DVBv3
2448 * API with their DVBv5 counterpart. For the other standards,
2449 * use the closest type, assuming that it would hopefully
2450 * work with a DVBv3 application.
2451 * It should be noticed that, on multi-frontend devices with
2452 * different types (terrestrial and cable, for example),
2453 * a pure DVBv3 application won't be able to use all delivery
2454 * systems. Yet, changing the DVBv5 cache to the other delivery
2455 * system should be enough for making it work.
2457 switch (dvbv3_type(c->delivery_system)) {
2459 info->type = FE_QPSK;
2462 info->type = FE_ATSC;
2465 info->type = FE_QAM;
2468 info->type = FE_OFDM;
2471 dev_err(fe->dvb->device,
2472 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2473 __func__, c->delivery_system);
2474 info->type = FE_OFDM;
2476 dev_dbg(fe->dvb->device, "%s: current delivery system on cache: %d, V3 type: %d\n",
2477 __func__, c->delivery_system, info->type);
2479 /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */
2480 if (!(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT))
2481 info->caps |= FE_CAN_INVERSION_AUTO;
2486 case FE_READ_STATUS: {
2487 enum fe_status *status = parg;
2489 /* if retune was requested but hasn't occurred yet, prevent
2490 * that user get signal state from previous tuning */
2491 if (fepriv->state == FESTATE_RETUNE ||
2492 fepriv->state == FESTATE_ERROR) {
2498 if (fe->ops.read_status)
2499 err = fe->ops.read_status(fe, status);
2503 case FE_DISEQC_RESET_OVERLOAD:
2504 if (fe->ops.diseqc_reset_overload) {
2505 err = fe->ops.diseqc_reset_overload(fe);
2506 fepriv->state = FESTATE_DISEQC;
2511 case FE_DISEQC_SEND_MASTER_CMD:
2512 if (fe->ops.diseqc_send_master_cmd) {
2513 struct dvb_diseqc_master_cmd *cmd = parg;
2515 if (cmd->msg_len > sizeof(cmd->msg)) {
2519 err = fe->ops.diseqc_send_master_cmd(fe, cmd);
2520 fepriv->state = FESTATE_DISEQC;
2525 case FE_DISEQC_SEND_BURST:
2526 if (fe->ops.diseqc_send_burst) {
2527 err = fe->ops.diseqc_send_burst(fe,
2528 (enum fe_sec_mini_cmd)parg);
2529 fepriv->state = FESTATE_DISEQC;
2535 if (fe->ops.set_tone) {
2536 err = fe->ops.set_tone(fe,
2537 (enum fe_sec_tone_mode)parg);
2538 fepriv->tone = (enum fe_sec_tone_mode)parg;
2539 fepriv->state = FESTATE_DISEQC;
2544 case FE_SET_VOLTAGE:
2545 if (fe->ops.set_voltage) {
2546 err = fe->ops.set_voltage(fe,
2547 (enum fe_sec_voltage)parg);
2548 fepriv->voltage = (enum fe_sec_voltage)parg;
2549 fepriv->state = FESTATE_DISEQC;
2554 case FE_DISEQC_RECV_SLAVE_REPLY:
2555 if (fe->ops.diseqc_recv_slave_reply)
2556 err = fe->ops.diseqc_recv_slave_reply(fe, parg);
2559 case FE_ENABLE_HIGH_LNB_VOLTAGE:
2560 if (fe->ops.enable_high_lnb_voltage)
2561 err = fe->ops.enable_high_lnb_voltage(fe, (long)parg);
2564 case FE_SET_FRONTEND_TUNE_MODE:
2565 fepriv->tune_mode_flags = (unsigned long)parg;
2569 /* DEPRECATED dish control ioctls */
2571 case FE_DISHNETWORK_SEND_LEGACY_CMD:
2572 if (fe->ops.dishnetwork_send_legacy_command) {
2573 err = fe->ops.dishnetwork_send_legacy_command(fe,
2574 (unsigned long)parg);
2575 fepriv->state = FESTATE_DISEQC;
2577 } else if (fe->ops.set_voltage) {
2579 * NOTE: This is a fallback condition. Some frontends
2580 * (stv0299 for instance) take longer than 8msec to
2581 * respond to a set_voltage command. Those switches
2582 * need custom routines to switch properly. For all
2583 * other frontends, the following should work ok.
2584 * Dish network legacy switches (as used by Dish500)
2585 * are controlled by sending 9-bit command words
2586 * spaced 8msec apart.
2587 * the actual command word is switch/port dependent
2588 * so it is up to the userspace application to send
2589 * the right command.
2590 * The command must always start with a '0' after
2591 * initialization, so parg is 8 bits and does not
2592 * include the initialization or start bit
2594 unsigned long swcmd = ((unsigned long)parg) << 1;
2600 if (dvb_frontend_debug)
2601 dprintk("%s switch command: 0x%04lx\n",
2603 nexttime = ktime_get_boottime();
2604 if (dvb_frontend_debug)
2606 /* before sending a command, initialize by sending
2607 * a 32ms 18V to the switch
2609 fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
2610 dvb_frontend_sleep_until(&nexttime, 32000);
2612 for (i = 0; i < 9; i++) {
2613 if (dvb_frontend_debug)
2614 tv[i + 1] = ktime_get_boottime();
2615 if ((swcmd & 0x01) != last) {
2616 /* set voltage to (last ? 13V : 18V) */
2617 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
2618 last = (last) ? 0 : 1;
2622 dvb_frontend_sleep_until(&nexttime, 8000);
2624 if (dvb_frontend_debug) {
2625 dprintk("%s(%d): switch delay (should be 32k followed by all 8k)\n",
2626 __func__, fe->dvb->num);
2627 for (i = 1; i < 10; i++)
2628 pr_info("%d: %d\n", i,
2629 (int)ktime_us_delta(tv[i], tv[i - 1]));
2632 fepriv->state = FESTATE_DISEQC;
2637 /* DEPRECATED statistics ioctls */
2640 if (fe->ops.read_ber) {
2642 err = fe->ops.read_ber(fe, parg);
2648 case FE_READ_SIGNAL_STRENGTH:
2649 if (fe->ops.read_signal_strength) {
2651 err = fe->ops.read_signal_strength(fe, parg);
2658 if (fe->ops.read_snr) {
2660 err = fe->ops.read_snr(fe, parg);
2666 case FE_READ_UNCORRECTED_BLOCKS:
2667 if (fe->ops.read_ucblocks) {
2669 err = fe->ops.read_ucblocks(fe, parg);
2675 /* DEPRECATED DVBv3 ioctls */
2677 case FE_SET_FRONTEND:
2678 err = dvbv3_set_delivery_system(fe);
2682 err = dtv_property_cache_sync(fe, c, parg);
2685 err = dtv_set_frontend(fe);
2688 err = dvb_frontend_get_event(fe, parg, file->f_flags);
2691 case FE_GET_FRONTEND: {
2692 struct dtv_frontend_properties getp = fe->dtv_property_cache;
2695 * Let's use our own copy of property cache, in order to
2696 * avoid mangling with DTV zigzag logic, as drivers might
2697 * return crap, if they don't check if the data is available
2698 * before updating the properties cache.
2700 err = dtv_get_frontend(fe, &getp, parg);
2711 static __poll_t dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
2713 struct dvb_device *dvbdev = file->private_data;
2714 struct dvb_frontend *fe = dvbdev->priv;
2715 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2717 dev_dbg_ratelimited(fe->dvb->device, "%s:\n", __func__);
2719 poll_wait(file, &fepriv->events.wait_queue, wait);
2721 if (fepriv->events.eventw != fepriv->events.eventr)
2722 return (EPOLLIN | EPOLLRDNORM | EPOLLPRI);
2727 static int dvb_frontend_open(struct inode *inode, struct file *file)
2729 struct dvb_device *dvbdev = file->private_data;
2730 struct dvb_frontend *fe = dvbdev->priv;
2731 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2732 struct dvb_adapter *adapter = fe->dvb;
2735 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2736 if (fe->exit == DVB_FE_DEVICE_REMOVED)
2739 if (adapter->mfe_shared) {
2740 mutex_lock(&adapter->mfe_lock);
2742 if (!adapter->mfe_dvbdev)
2743 adapter->mfe_dvbdev = dvbdev;
2745 else if (adapter->mfe_dvbdev != dvbdev) {
2747 *mfedev = adapter->mfe_dvbdev;
2749 *mfe = mfedev->priv;
2750 struct dvb_frontend_private
2751 *mfepriv = mfe->frontend_priv;
2752 int mferetry = (dvb_mfe_wait_time << 1);
2754 mutex_unlock(&adapter->mfe_lock);
2755 while (mferetry-- && (mfedev->users != -1 ||
2757 if (msleep_interruptible(500)) {
2758 if (signal_pending(current))
2763 mutex_lock(&adapter->mfe_lock);
2764 if (adapter->mfe_dvbdev != dvbdev) {
2765 mfedev = adapter->mfe_dvbdev;
2767 mfepriv = mfe->frontend_priv;
2768 if (mfedev->users != -1 ||
2770 mutex_unlock(&adapter->mfe_lock);
2773 adapter->mfe_dvbdev = dvbdev;
2778 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
2779 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
2782 /* If we took control of the bus, we need to force
2783 reinitialization. This is because many ts_bus_ctrl()
2784 functions strobe the RESET pin on the demod, and if the
2785 frontend thread already exists then the dvb_init() routine
2786 won't get called (which is what usually does initial
2787 register configuration). */
2788 fepriv->reinitialise = 1;
2791 if ((ret = dvb_generic_open(inode, file)) < 0)
2794 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2795 /* normal tune mode when opened R/W */
2796 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
2798 fepriv->voltage = -1;
2800 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2801 mutex_lock(&fe->dvb->mdev_lock);
2802 if (fe->dvb->mdev) {
2803 mutex_lock(&fe->dvb->mdev->graph_mutex);
2804 if (fe->dvb->mdev->enable_source)
2805 ret = fe->dvb->mdev->enable_source(
2808 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2810 mutex_unlock(&fe->dvb->mdev_lock);
2811 dev_err(fe->dvb->device,
2812 "Tuner is busy. Error %d\n", ret);
2816 mutex_unlock(&fe->dvb->mdev_lock);
2818 ret = dvb_frontend_start(fe);
2822 /* empty event queue */
2823 fepriv->events.eventr = fepriv->events.eventw = 0;
2826 dvb_frontend_get(fe);
2828 if (adapter->mfe_shared)
2829 mutex_unlock(&adapter->mfe_lock);
2833 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2834 mutex_lock(&fe->dvb->mdev_lock);
2835 if (fe->dvb->mdev) {
2836 mutex_lock(&fe->dvb->mdev->graph_mutex);
2837 if (fe->dvb->mdev->disable_source)
2838 fe->dvb->mdev->disable_source(dvbdev->entity);
2839 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2841 mutex_unlock(&fe->dvb->mdev_lock);
2844 dvb_generic_release(inode, file);
2846 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
2847 fe->ops.ts_bus_ctrl(fe, 0);
2849 if (adapter->mfe_shared)
2850 mutex_unlock(&adapter->mfe_lock);
2854 static int dvb_frontend_release(struct inode *inode, struct file *file)
2856 struct dvb_device *dvbdev = file->private_data;
2857 struct dvb_frontend *fe = dvbdev->priv;
2858 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2861 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2863 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2864 fepriv->release_jiffies = jiffies;
2868 ret = dvb_generic_release(inode, file);
2870 if (dvbdev->users == -1) {
2871 wake_up(&fepriv->wait_queue);
2872 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2873 mutex_lock(&fe->dvb->mdev_lock);
2874 if (fe->dvb->mdev) {
2875 mutex_lock(&fe->dvb->mdev->graph_mutex);
2876 if (fe->dvb->mdev->disable_source)
2877 fe->dvb->mdev->disable_source(dvbdev->entity);
2878 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2880 mutex_unlock(&fe->dvb->mdev_lock);
2882 if (fe->exit != DVB_FE_NO_EXIT)
2883 wake_up(&dvbdev->wait_queue);
2884 if (fe->ops.ts_bus_ctrl)
2885 fe->ops.ts_bus_ctrl(fe, 0);
2888 dvb_frontend_put(fe);
2893 static const struct file_operations dvb_frontend_fops = {
2894 .owner = THIS_MODULE,
2895 .unlocked_ioctl = dvb_frontend_ioctl,
2896 #ifdef CONFIG_COMPAT
2897 .compat_ioctl = dvb_frontend_compat_ioctl,
2899 .poll = dvb_frontend_poll,
2900 .open = dvb_frontend_open,
2901 .release = dvb_frontend_release,
2902 .llseek = noop_llseek,
2905 int dvb_frontend_suspend(struct dvb_frontend *fe)
2909 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2912 if (fe->ops.tuner_ops.suspend)
2913 ret = fe->ops.tuner_ops.suspend(fe);
2914 else if (fe->ops.tuner_ops.sleep)
2915 ret = fe->ops.tuner_ops.sleep(fe);
2918 ret = fe->ops.sleep(fe);
2922 EXPORT_SYMBOL(dvb_frontend_suspend);
2924 int dvb_frontend_resume(struct dvb_frontend *fe)
2926 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2929 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2932 fe->exit = DVB_FE_DEVICE_RESUME;
2934 ret = fe->ops.init(fe);
2936 if (fe->ops.tuner_ops.resume)
2937 ret = fe->ops.tuner_ops.resume(fe);
2938 else if (fe->ops.tuner_ops.init)
2939 ret = fe->ops.tuner_ops.init(fe);
2941 if (fe->ops.set_tone && fepriv->tone != -1)
2942 fe->ops.set_tone(fe, fepriv->tone);
2943 if (fe->ops.set_voltage && fepriv->voltage != -1)
2944 fe->ops.set_voltage(fe, fepriv->voltage);
2946 fe->exit = DVB_FE_NO_EXIT;
2947 fepriv->state = FESTATE_RETUNE;
2948 dvb_frontend_wakeup(fe);
2952 EXPORT_SYMBOL(dvb_frontend_resume);
2954 int dvb_register_frontend(struct dvb_adapter *dvb,
2955 struct dvb_frontend *fe)
2957 struct dvb_frontend_private *fepriv;
2958 const struct dvb_device dvbdev_template = {
2961 .readers = (~0) - 1,
2962 .fops = &dvb_frontend_fops,
2963 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
2964 .name = fe->ops.info.name,
2969 dev_dbg(dvb->device, "%s:\n", __func__);
2971 if (mutex_lock_interruptible(&frontend_mutex))
2972 return -ERESTARTSYS;
2974 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
2975 if (!fe->frontend_priv) {
2976 mutex_unlock(&frontend_mutex);
2979 fepriv = fe->frontend_priv;
2981 kref_init(&fe->refcount);
2984 * After initialization, there need to be two references: one
2985 * for dvb_unregister_frontend(), and another one for
2986 * dvb_frontend_detach().
2988 dvb_frontend_get(fe);
2990 sema_init(&fepriv->sem, 1);
2991 init_waitqueue_head(&fepriv->wait_queue);
2992 init_waitqueue_head(&fepriv->events.wait_queue);
2993 mutex_init(&fepriv->events.mtx);
2995 fepriv->inversion = INVERSION_OFF;
2997 dev_info(fe->dvb->device,
2998 "DVB: registering adapter %i frontend %i (%s)...\n",
2999 fe->dvb->num, fe->id, fe->ops.info.name);
3001 ret = dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
3002 fe, DVB_DEVICE_FRONTEND, 0);
3004 dvb_frontend_put(fe);
3005 mutex_unlock(&frontend_mutex);
3010 * Initialize the cache to the proper values according with the
3011 * first supported delivery system (ops->delsys[0])
3014 fe->dtv_property_cache.delivery_system = fe->ops.delsys[0];
3015 dvb_frontend_clear_cache(fe);
3017 mutex_unlock(&frontend_mutex);
3020 EXPORT_SYMBOL(dvb_register_frontend);
3022 int dvb_unregister_frontend(struct dvb_frontend *fe)
3024 struct dvb_frontend_private *fepriv = fe->frontend_priv;
3026 dev_dbg(fe->dvb->device, "%s:\n", __func__);
3028 mutex_lock(&frontend_mutex);
3029 dvb_frontend_stop(fe);
3030 dvb_remove_device(fepriv->dvbdev);
3032 /* fe is invalid now */
3033 mutex_unlock(&frontend_mutex);
3034 dvb_frontend_put(fe);
3037 EXPORT_SYMBOL(dvb_unregister_frontend);
3039 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
3040 void (*release)(struct dvb_frontend *fe))
3044 #ifdef CONFIG_MEDIA_ATTACH
3045 dvb_detach(release);
3050 void dvb_frontend_detach(struct dvb_frontend *fe)
3052 dvb_frontend_invoke_release(fe, fe->ops.release_sec);
3053 dvb_frontend_invoke_release(fe, fe->ops.tuner_ops.release);
3054 dvb_frontend_invoke_release(fe, fe->ops.analog_ops.release);
3055 dvb_frontend_put(fe);
3057 EXPORT_SYMBOL(dvb_frontend_detach);