1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * 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)
13 /* Enables DVBv3 compatibility bits at the headers */
16 #define pr_fmt(fmt) "dvb_frontend: " fmt
18 #include <linux/string.h>
19 #include <linux/kernel.h>
20 #include <linux/sched/signal.h>
21 #include <linux/wait.h>
22 #include <linux/slab.h>
23 #include <linux/poll.h>
24 #include <linux/semaphore.h>
25 #include <linux/module.h>
26 #include <linux/list.h>
27 #include <linux/freezer.h>
28 #include <linux/jiffies.h>
29 #include <linux/kthread.h>
30 #include <linux/ktime.h>
31 #include <linux/compat.h>
32 #include <asm/processor.h>
34 #include <media/dvb_frontend.h>
35 #include <media/dvbdev.h>
36 #include <linux/dvb/version.h>
38 static int dvb_frontend_debug;
39 static int dvb_shutdown_timeout;
40 static int dvb_force_auto_inversion;
41 static int dvb_override_tune_delay;
42 static int dvb_powerdown_on_sleep = 1;
43 static int dvb_mfe_wait_time = 5;
45 module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
46 MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
47 module_param(dvb_shutdown_timeout, int, 0644);
48 MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
49 module_param(dvb_force_auto_inversion, int, 0644);
50 MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
51 module_param(dvb_override_tune_delay, int, 0644);
52 MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
53 module_param(dvb_powerdown_on_sleep, int, 0644);
54 MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
55 module_param(dvb_mfe_wait_time, int, 0644);
56 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)");
58 #define dprintk(fmt, arg...) \
59 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
61 #define FESTATE_IDLE 1
62 #define FESTATE_RETUNE 2
63 #define FESTATE_TUNING_FAST 4
64 #define FESTATE_TUNING_SLOW 8
65 #define FESTATE_TUNED 16
66 #define FESTATE_ZIGZAG_FAST 32
67 #define FESTATE_ZIGZAG_SLOW 64
68 #define FESTATE_DISEQC 128
69 #define FESTATE_ERROR 256
70 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
71 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
72 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
73 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
76 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
77 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
78 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
79 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
80 * FESTATE_TUNED. The frontend has successfully locked on.
81 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
82 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
83 * FESTATE_DISEQC. A DISEQC command has just been issued.
84 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
85 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
86 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
87 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
90 static DEFINE_MUTEX(frontend_mutex);
92 struct dvb_frontend_private {
93 /* thread/frontend values */
94 struct dvb_device *dvbdev;
95 struct dvb_frontend_parameters parameters_out;
96 struct dvb_fe_events events;
98 struct list_head list_head;
99 wait_queue_head_t wait_queue;
100 struct task_struct *thread;
101 unsigned long release_jiffies;
103 enum fe_status status;
104 unsigned long tune_mode_flags;
106 unsigned int reinitialise;
110 /* swzigzag values */
112 unsigned int bending;
114 unsigned int inversion;
115 unsigned int auto_step;
116 unsigned int auto_sub_step;
117 unsigned int started_auto_step;
118 unsigned int min_delay;
119 unsigned int max_drift;
120 unsigned int step_size;
122 unsigned int check_wrapped;
123 enum dvbfe_search algo_status;
125 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
126 struct media_pipeline pipe;
130 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
131 void (*release)(struct dvb_frontend *fe));
133 static void __dvb_frontend_free(struct dvb_frontend *fe)
135 struct dvb_frontend_private *fepriv = fe->frontend_priv;
138 dvb_free_device(fepriv->dvbdev);
140 dvb_frontend_invoke_release(fe, fe->ops.release);
145 static void dvb_frontend_free(struct kref *ref)
147 struct dvb_frontend *fe =
148 container_of(ref, struct dvb_frontend, refcount);
150 __dvb_frontend_free(fe);
153 static void dvb_frontend_put(struct dvb_frontend *fe)
155 /* call detach before dropping the reference count */
159 * Check if the frontend was registered, as otherwise
160 * kref was not initialized yet.
162 if (fe->frontend_priv)
163 kref_put(&fe->refcount, dvb_frontend_free);
165 __dvb_frontend_free(fe);
168 static void dvb_frontend_get(struct dvb_frontend *fe)
170 kref_get(&fe->refcount);
173 static void dvb_frontend_wakeup(struct dvb_frontend *fe);
174 static int dtv_get_frontend(struct dvb_frontend *fe,
175 struct dtv_frontend_properties *c,
176 struct dvb_frontend_parameters *p_out);
178 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
179 const struct dtv_frontend_properties *c,
180 struct dvb_frontend_parameters *p);
182 static bool has_get_frontend(struct dvb_frontend *fe)
184 return fe->ops.get_frontend;
188 * Due to DVBv3 API calls, a delivery system should be mapped into one of
189 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
190 * otherwise, a DVBv3 call will fail.
192 enum dvbv3_emulation_type {
200 static enum dvbv3_emulation_type dvbv3_type(u32 delivery_system)
202 switch (delivery_system) {
203 case SYS_DVBC_ANNEX_A:
204 case SYS_DVBC_ANNEX_C:
219 case SYS_DVBC_ANNEX_B:
227 * Doesn't know how to emulate those types and/or
228 * there's no frontend driver from this type yet
229 * with some emulation code, so, we're not sure yet how
230 * to handle them, or they're not compatible with a DVBv3 call.
232 return DVBV3_UNKNOWN;
236 static void dvb_frontend_add_event(struct dvb_frontend *fe,
237 enum fe_status status)
239 struct dvb_frontend_private *fepriv = fe->frontend_priv;
240 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
241 struct dvb_fe_events *events = &fepriv->events;
242 struct dvb_frontend_event *e;
245 dev_dbg(fe->dvb->device, "%s:\n", __func__);
247 if ((status & FE_HAS_LOCK) && has_get_frontend(fe))
248 dtv_get_frontend(fe, c, &fepriv->parameters_out);
250 mutex_lock(&events->mtx);
252 wp = (events->eventw + 1) % MAX_EVENT;
253 if (wp == events->eventr) {
254 events->overflow = 1;
255 events->eventr = (events->eventr + 1) % MAX_EVENT;
258 e = &events->events[events->eventw];
260 e->parameters = fepriv->parameters_out;
264 mutex_unlock(&events->mtx);
266 wake_up_interruptible(&events->wait_queue);
269 static int dvb_frontend_test_event(struct dvb_frontend_private *fepriv,
270 struct dvb_fe_events *events)
275 ret = events->eventw != events->eventr;
281 static int dvb_frontend_get_event(struct dvb_frontend *fe,
282 struct dvb_frontend_event *event, int flags)
284 struct dvb_frontend_private *fepriv = fe->frontend_priv;
285 struct dvb_fe_events *events = &fepriv->events;
287 dev_dbg(fe->dvb->device, "%s:\n", __func__);
289 if (events->overflow) {
290 events->overflow = 0;
294 if (events->eventw == events->eventr) {
297 if (flags & O_NONBLOCK)
300 ret = wait_event_interruptible(events->wait_queue,
301 dvb_frontend_test_event(fepriv, events));
307 mutex_lock(&events->mtx);
308 *event = events->events[events->eventr];
309 events->eventr = (events->eventr + 1) % MAX_EVENT;
310 mutex_unlock(&events->mtx);
315 static void dvb_frontend_clear_events(struct dvb_frontend *fe)
317 struct dvb_frontend_private *fepriv = fe->frontend_priv;
318 struct dvb_fe_events *events = &fepriv->events;
320 mutex_lock(&events->mtx);
321 events->eventr = events->eventw;
322 mutex_unlock(&events->mtx);
325 static void dvb_frontend_init(struct dvb_frontend *fe)
327 dev_dbg(fe->dvb->device,
328 "%s: initialising adapter %i frontend %i (%s)...\n",
329 __func__, fe->dvb->num, fe->id, fe->ops.info.name);
333 if (fe->ops.tuner_ops.init) {
334 if (fe->ops.i2c_gate_ctrl)
335 fe->ops.i2c_gate_ctrl(fe, 1);
336 fe->ops.tuner_ops.init(fe);
337 if (fe->ops.i2c_gate_ctrl)
338 fe->ops.i2c_gate_ctrl(fe, 0);
342 void dvb_frontend_reinitialise(struct dvb_frontend *fe)
344 struct dvb_frontend_private *fepriv = fe->frontend_priv;
346 fepriv->reinitialise = 1;
347 dvb_frontend_wakeup(fe);
349 EXPORT_SYMBOL(dvb_frontend_reinitialise);
351 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
354 struct dvb_frontend *fe = fepriv->dvbdev->priv;
356 dev_dbg(fe->dvb->device, "%s:\n", __func__);
359 (fepriv->quality) = (fepriv->quality * 220 + 36 * 256) / 256;
361 (fepriv->quality) = (fepriv->quality * 220 + 0) / 256;
363 q2 = fepriv->quality - 128;
366 fepriv->delay = fepriv->min_delay + q2 * HZ / (128 * 128);
370 * dvb_frontend_swzigzag_autotune - Performs automatic twiddling of frontend
373 * @fe: The frontend concerned.
374 * @check_wrapped: Checks if an iteration has completed.
375 * DO NOT SET ON THE FIRST ATTEMPT.
377 * return: Number of complete iterations that have been performed.
379 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped)
384 struct dvb_frontend_private *fepriv = fe->frontend_priv;
385 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
386 int original_inversion = c->inversion;
387 u32 original_frequency = c->frequency;
389 /* are we using autoinversion? */
390 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
391 (c->inversion == INVERSION_AUTO));
393 /* setup parameters correctly */
395 /* calculate the lnb_drift */
396 fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size;
398 /* wrap the auto_step if we've exceeded the maximum drift */
399 if (fepriv->lnb_drift > fepriv->max_drift) {
400 fepriv->auto_step = 0;
401 fepriv->auto_sub_step = 0;
402 fepriv->lnb_drift = 0;
405 /* perform inversion and +/- zigzag */
406 switch (fepriv->auto_sub_step) {
408 /* try with the current inversion and current drift setting */
413 if (!autoinversion) break;
415 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
420 if (fepriv->lnb_drift == 0) break;
422 fepriv->lnb_drift = -fepriv->lnb_drift;
427 if (fepriv->lnb_drift == 0) break;
428 if (!autoinversion) break;
430 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
431 fepriv->lnb_drift = -fepriv->lnb_drift;
437 fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */
441 if (!ready) fepriv->auto_sub_step++;
444 /* if this attempt would hit where we started, indicate a complete
445 * iteration has occurred */
446 if ((fepriv->auto_step == fepriv->started_auto_step) &&
447 (fepriv->auto_sub_step == 0) && check_wrapped) {
451 dev_dbg(fe->dvb->device,
452 "%s: drift:%i inversion:%i auto_step:%i auto_sub_step:%i started_auto_step:%i\n",
453 __func__, fepriv->lnb_drift, fepriv->inversion,
454 fepriv->auto_step, fepriv->auto_sub_step,
455 fepriv->started_auto_step);
457 /* set the frontend itself */
458 c->frequency += fepriv->lnb_drift;
460 c->inversion = fepriv->inversion;
462 if (fe->ops.set_frontend)
463 fe_set_err = fe->ops.set_frontend(fe);
465 if (fe_set_err < 0) {
466 fepriv->state = FESTATE_ERROR;
470 c->frequency = original_frequency;
471 c->inversion = original_inversion;
473 fepriv->auto_sub_step++;
477 static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
479 enum fe_status s = FE_NONE;
481 struct dvb_frontend_private *fepriv = fe->frontend_priv;
482 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
484 /* if we've got no parameters, just keep idling */
485 if (fepriv->state & FESTATE_IDLE) {
486 fepriv->delay = 3 * HZ;
491 /* in SCAN mode, we just set the frontend when asked and leave it alone */
492 if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) {
493 if (fepriv->state & FESTATE_RETUNE) {
495 if (fe->ops.set_frontend)
496 retval = fe->ops.set_frontend(fe);
499 fepriv->state = FESTATE_ERROR;
501 fepriv->state = FESTATE_TUNED;
503 fepriv->delay = 3 * HZ;
508 /* get the frontend status */
509 if (fepriv->state & FESTATE_RETUNE) {
512 if (fe->ops.read_status)
513 fe->ops.read_status(fe, &s);
514 if (s != fepriv->status) {
515 dvb_frontend_add_event(fe, s);
520 /* if we're not tuned, and we have a lock, move to the TUNED state */
521 if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) {
522 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
523 fepriv->state = FESTATE_TUNED;
525 /* if we're tuned, then we have determined the correct inversion */
526 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
527 (c->inversion == INVERSION_AUTO)) {
528 c->inversion = fepriv->inversion;
533 /* if we are tuned already, check we're still locked */
534 if (fepriv->state & FESTATE_TUNED) {
535 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
537 /* we're tuned, and the lock is still good... */
538 if (s & FE_HAS_LOCK) {
540 } else { /* if we _WERE_ tuned, but now don't have a lock */
541 fepriv->state = FESTATE_ZIGZAG_FAST;
542 fepriv->started_auto_step = fepriv->auto_step;
543 fepriv->check_wrapped = 0;
547 /* don't actually do anything if we're in the LOSTLOCK state,
548 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
549 if ((fepriv->state & FESTATE_LOSTLOCK) &&
550 (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) {
551 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
555 /* don't do anything if we're in the DISEQC state, since this
556 * might be someone with a motorized dish controlled by DISEQC.
557 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
558 if (fepriv->state & FESTATE_DISEQC) {
559 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
563 /* if we're in the RETUNE state, set everything up for a brand
564 * new scan, keeping the current inversion setting, as the next
565 * tune is _very_ likely to require the same */
566 if (fepriv->state & FESTATE_RETUNE) {
567 fepriv->lnb_drift = 0;
568 fepriv->auto_step = 0;
569 fepriv->auto_sub_step = 0;
570 fepriv->started_auto_step = 0;
571 fepriv->check_wrapped = 0;
575 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
576 fepriv->delay = fepriv->min_delay;
579 retval = dvb_frontend_swzigzag_autotune(fe,
580 fepriv->check_wrapped);
584 /* OK, if we've run out of trials at the fast speed.
585 * Drop back to slow for the _next_ attempt */
586 fepriv->state = FESTATE_SEARCHING_SLOW;
587 fepriv->started_auto_step = fepriv->auto_step;
590 fepriv->check_wrapped = 1;
592 /* if we've just re-tuned, enter the ZIGZAG_FAST state.
593 * This ensures we cannot return from an
594 * FE_SET_FRONTEND ioctl before the first frontend tune
596 if (fepriv->state & FESTATE_RETUNE) {
597 fepriv->state = FESTATE_TUNING_FAST;
602 if (fepriv->state & FESTATE_SEARCHING_SLOW) {
603 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
605 /* Note: don't bother checking for wrapping; we stay in this
606 * state until we get a lock */
607 dvb_frontend_swzigzag_autotune(fe, 0);
611 static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
613 struct dvb_frontend_private *fepriv = fe->frontend_priv;
615 if (fe->exit != DVB_FE_NO_EXIT)
618 if (fepriv->dvbdev->writers == 1)
619 if (time_after_eq(jiffies, fepriv->release_jiffies +
620 dvb_shutdown_timeout * HZ))
626 static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
628 struct dvb_frontend_private *fepriv = fe->frontend_priv;
630 if (fepriv->wakeup) {
634 return dvb_frontend_is_exiting(fe);
637 static void dvb_frontend_wakeup(struct dvb_frontend *fe)
639 struct dvb_frontend_private *fepriv = fe->frontend_priv;
642 wake_up_interruptible(&fepriv->wait_queue);
645 static int dvb_frontend_thread(void *data)
647 struct dvb_frontend *fe = data;
648 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
649 struct dvb_frontend_private *fepriv = fe->frontend_priv;
650 enum fe_status s = FE_NONE;
651 enum dvbfe_algo algo;
652 bool re_tune = false;
653 bool semheld = false;
655 dev_dbg(fe->dvb->device, "%s:\n", __func__);
657 fepriv->check_wrapped = 0;
659 fepriv->delay = 3 * HZ;
662 fepriv->reinitialise = 0;
664 dvb_frontend_init(fe);
668 up(&fepriv->sem); /* is locked when we enter the thread... */
670 wait_event_interruptible_timeout(fepriv->wait_queue,
671 dvb_frontend_should_wakeup(fe) ||
672 kthread_should_stop() ||
676 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
677 /* got signal or quitting */
678 if (!down_interruptible(&fepriv->sem))
680 fe->exit = DVB_FE_NORMAL_EXIT;
687 if (down_interruptible(&fepriv->sem))
690 if (fepriv->reinitialise) {
691 dvb_frontend_init(fe);
692 if (fe->ops.set_tone && fepriv->tone != -1)
693 fe->ops.set_tone(fe, fepriv->tone);
694 if (fe->ops.set_voltage && fepriv->voltage != -1)
695 fe->ops.set_voltage(fe, fepriv->voltage);
696 fepriv->reinitialise = 0;
699 /* do an iteration of the tuning loop */
700 if (fe->ops.get_frontend_algo) {
701 algo = fe->ops.get_frontend_algo(fe);
704 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__);
706 if (fepriv->state & FESTATE_RETUNE) {
707 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTATE_RETUNE\n", __func__);
709 fepriv->state = FESTATE_TUNED;
715 fe->ops.tune(fe, re_tune, fepriv->tune_mode_flags, &fepriv->delay, &s);
717 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
718 dev_dbg(fe->dvb->device, "%s: state changed, adding current state\n", __func__);
719 dvb_frontend_add_event(fe, s);
724 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__);
725 dvb_frontend_swzigzag(fe);
727 case DVBFE_ALGO_CUSTOM:
728 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
729 if (fepriv->state & FESTATE_RETUNE) {
730 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTAT_RETUNE\n", __func__);
731 fepriv->state = FESTATE_TUNED;
733 /* Case where we are going to search for a carrier
734 * User asked us to retune again for some reason, possibly
735 * requesting a search with a new set of parameters
737 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
738 if (fe->ops.search) {
739 fepriv->algo_status = fe->ops.search(fe);
740 /* We did do a search as was requested, the flags are
741 * now unset as well and has the flags wrt to search.
744 fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN;
747 /* Track the carrier if the search was successful */
748 if (fepriv->algo_status != DVBFE_ALGO_SEARCH_SUCCESS) {
749 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
750 fepriv->delay = HZ / 2;
752 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
753 fe->ops.read_status(fe, &s);
754 if (s != fepriv->status) {
755 dvb_frontend_add_event(fe, s); /* update event list */
757 if (!(s & FE_HAS_LOCK)) {
758 fepriv->delay = HZ / 10;
759 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
761 fepriv->delay = 60 * HZ;
766 dev_dbg(fe->dvb->device, "%s: UNDEFINED ALGO !\n", __func__);
770 dvb_frontend_swzigzag(fe);
774 if (dvb_powerdown_on_sleep) {
775 if (fe->ops.set_voltage)
776 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
777 if (fe->ops.tuner_ops.sleep) {
778 if (fe->ops.i2c_gate_ctrl)
779 fe->ops.i2c_gate_ctrl(fe, 1);
780 fe->ops.tuner_ops.sleep(fe);
781 if (fe->ops.i2c_gate_ctrl)
782 fe->ops.i2c_gate_ctrl(fe, 0);
788 fepriv->thread = NULL;
789 if (kthread_should_stop())
790 fe->exit = DVB_FE_DEVICE_REMOVED;
792 fe->exit = DVB_FE_NO_EXIT;
797 dvb_frontend_wakeup(fe);
801 static void dvb_frontend_stop(struct dvb_frontend *fe)
803 struct dvb_frontend_private *fepriv = fe->frontend_priv;
805 dev_dbg(fe->dvb->device, "%s:\n", __func__);
807 if (fe->exit != DVB_FE_DEVICE_REMOVED)
808 fe->exit = DVB_FE_NORMAL_EXIT;
814 kthread_stop(fepriv->thread);
816 sema_init(&fepriv->sem, 1);
817 fepriv->state = FESTATE_IDLE;
819 /* paranoia check in case a signal arrived */
821 dev_warn(fe->dvb->device,
822 "dvb_frontend_stop: warning: thread %p won't exit\n",
827 * Sleep for the amount of time given by add_usec parameter
829 * This needs to be as precise as possible, as it affects the detection of
830 * the dish tone command at the satellite subsystem. The precision is improved
831 * by using a scheduled msleep followed by udelay for the remainder.
833 void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
837 *waketime = ktime_add_us(*waketime, add_usec);
838 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
840 msleep((delta - 1500) / 1000);
841 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
846 EXPORT_SYMBOL(dvb_frontend_sleep_until);
848 static int dvb_frontend_start(struct dvb_frontend *fe)
851 struct dvb_frontend_private *fepriv = fe->frontend_priv;
852 struct task_struct *fe_thread;
854 dev_dbg(fe->dvb->device, "%s:\n", __func__);
856 if (fepriv->thread) {
857 if (fe->exit == DVB_FE_NO_EXIT)
860 dvb_frontend_stop(fe);
863 if (signal_pending(current))
865 if (down_interruptible(&fepriv->sem))
868 fepriv->state = FESTATE_IDLE;
869 fe->exit = DVB_FE_NO_EXIT;
870 fepriv->thread = NULL;
873 fe_thread = kthread_run(dvb_frontend_thread, fe,
874 "kdvb-ad-%i-fe-%i", fe->dvb->num, fe->id);
875 if (IS_ERR(fe_thread)) {
876 ret = PTR_ERR(fe_thread);
877 dev_warn(fe->dvb->device,
878 "dvb_frontend_start: failed to start kthread (%d)\n",
883 fepriv->thread = fe_thread;
887 static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe,
888 u32 *freq_min, u32 *freq_max,
891 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
892 u32 tuner_min = fe->ops.tuner_ops.info.frequency_min_hz;
893 u32 tuner_max = fe->ops.tuner_ops.info.frequency_max_hz;
894 u32 frontend_min = fe->ops.info.frequency_min_hz;
895 u32 frontend_max = fe->ops.info.frequency_max_hz;
897 *freq_min = max(frontend_min, tuner_min);
899 if (frontend_max == 0)
900 *freq_max = tuner_max;
901 else if (tuner_max == 0)
902 *freq_max = frontend_max;
904 *freq_max = min(frontend_max, tuner_max);
906 if (*freq_min == 0 || *freq_max == 0)
907 dev_warn(fe->dvb->device,
908 "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
909 fe->dvb->num, fe->id);
911 dev_dbg(fe->dvb->device, "frequency interval: tuner: %u...%u, frontend: %u...%u",
912 tuner_min, tuner_max, frontend_min, frontend_max);
914 /* If the standard is for satellite, convert frequencies to kHz */
915 switch (c->delivery_system) {
923 *tolerance = fe->ops.info.frequency_tolerance_hz / kHz;
928 *tolerance = fe->ops.info.frequency_tolerance_hz;
933 static u32 dvb_frontend_get_stepsize(struct dvb_frontend *fe)
935 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
936 u32 fe_step = fe->ops.info.frequency_stepsize_hz;
937 u32 tuner_step = fe->ops.tuner_ops.info.frequency_step_hz;
938 u32 step = max(fe_step, tuner_step);
940 switch (c->delivery_system) {
954 static int dvb_frontend_check_parameters(struct dvb_frontend *fe)
956 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
960 /* range check: frequency */
961 dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max, NULL);
962 if ((freq_min && c->frequency < freq_min) ||
963 (freq_max && c->frequency > freq_max)) {
964 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
965 fe->dvb->num, fe->id, c->frequency,
970 /* range check: symbol rate */
971 switch (c->delivery_system) {
975 case SYS_DVBC_ANNEX_A:
976 case SYS_DVBC_ANNEX_C:
977 if ((fe->ops.info.symbol_rate_min &&
978 c->symbol_rate < fe->ops.info.symbol_rate_min) ||
979 (fe->ops.info.symbol_rate_max &&
980 c->symbol_rate > fe->ops.info.symbol_rate_max)) {
981 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
982 fe->dvb->num, fe->id, c->symbol_rate,
983 fe->ops.info.symbol_rate_min,
984 fe->ops.info.symbol_rate_max);
995 static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
997 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1001 delsys = c->delivery_system;
1002 memset(c, 0, offsetof(struct dtv_frontend_properties, strength));
1003 c->delivery_system = delsys;
1005 dev_dbg(fe->dvb->device, "%s: Clearing cache for delivery system %d\n",
1006 __func__, c->delivery_system);
1008 c->transmission_mode = TRANSMISSION_MODE_AUTO;
1009 c->bandwidth_hz = 0; /* AUTO */
1010 c->guard_interval = GUARD_INTERVAL_AUTO;
1011 c->hierarchy = HIERARCHY_AUTO;
1013 c->code_rate_HP = FEC_AUTO;
1014 c->code_rate_LP = FEC_AUTO;
1015 c->fec_inner = FEC_AUTO;
1016 c->rolloff = ROLLOFF_AUTO;
1017 c->voltage = SEC_VOLTAGE_OFF;
1018 c->sectone = SEC_TONE_OFF;
1019 c->pilot = PILOT_AUTO;
1021 c->isdbt_partial_reception = 0;
1022 c->isdbt_sb_mode = 0;
1023 c->isdbt_sb_subchannel = 0;
1024 c->isdbt_sb_segment_idx = 0;
1025 c->isdbt_sb_segment_count = 0;
1026 c->isdbt_layer_enabled = 7; /* All layers (A,B,C) */
1027 for (i = 0; i < 3; i++) {
1028 c->layer[i].fec = FEC_AUTO;
1029 c->layer[i].modulation = QAM_AUTO;
1030 c->layer[i].interleaving = 0;
1031 c->layer[i].segment_count = 0;
1034 c->stream_id = NO_STREAM_ID_FILTER;
1035 c->scrambling_sequence_index = 0;/* default sequence */
1037 switch (c->delivery_system) {
1041 c->modulation = QPSK; /* implied for DVB-S in legacy API */
1042 c->rolloff = ROLLOFF_35;/* implied for DVB-S */
1045 c->modulation = VSB_8;
1048 c->symbol_rate = 28860000;
1049 c->rolloff = ROLLOFF_35;
1050 c->bandwidth_hz = c->symbol_rate / 100 * 135;
1053 c->modulation = QAM_AUTO;
1062 #define _DTV_CMD(n, s, b) \
1071 char *name; /* A display name for debugging purposes */
1073 __u32 cmd; /* A unique ID */
1076 __u32 set:1; /* Either a set or get property */
1077 __u32 buffer:1; /* Does this property use the buffer? */
1078 __u32 reserved:30; /* Align */
1081 static struct dtv_cmds_h dtv_cmds[DTV_MAX_COMMAND + 1] = {
1082 _DTV_CMD(DTV_TUNE, 1, 0),
1083 _DTV_CMD(DTV_CLEAR, 1, 0),
1086 _DTV_CMD(DTV_FREQUENCY, 1, 0),
1087 _DTV_CMD(DTV_BANDWIDTH_HZ, 1, 0),
1088 _DTV_CMD(DTV_MODULATION, 1, 0),
1089 _DTV_CMD(DTV_INVERSION, 1, 0),
1090 _DTV_CMD(DTV_DISEQC_MASTER, 1, 1),
1091 _DTV_CMD(DTV_SYMBOL_RATE, 1, 0),
1092 _DTV_CMD(DTV_INNER_FEC, 1, 0),
1093 _DTV_CMD(DTV_VOLTAGE, 1, 0),
1094 _DTV_CMD(DTV_TONE, 1, 0),
1095 _DTV_CMD(DTV_PILOT, 1, 0),
1096 _DTV_CMD(DTV_ROLLOFF, 1, 0),
1097 _DTV_CMD(DTV_DELIVERY_SYSTEM, 1, 0),
1098 _DTV_CMD(DTV_HIERARCHY, 1, 0),
1099 _DTV_CMD(DTV_CODE_RATE_HP, 1, 0),
1100 _DTV_CMD(DTV_CODE_RATE_LP, 1, 0),
1101 _DTV_CMD(DTV_GUARD_INTERVAL, 1, 0),
1102 _DTV_CMD(DTV_TRANSMISSION_MODE, 1, 0),
1103 _DTV_CMD(DTV_INTERLEAVING, 1, 0),
1105 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION, 1, 0),
1106 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING, 1, 0),
1107 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID, 1, 0),
1108 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX, 1, 0),
1109 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT, 1, 0),
1110 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED, 1, 0),
1111 _DTV_CMD(DTV_ISDBT_LAYERA_FEC, 1, 0),
1112 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION, 1, 0),
1113 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT, 1, 0),
1114 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING, 1, 0),
1115 _DTV_CMD(DTV_ISDBT_LAYERB_FEC, 1, 0),
1116 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION, 1, 0),
1117 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT, 1, 0),
1118 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING, 1, 0),
1119 _DTV_CMD(DTV_ISDBT_LAYERC_FEC, 1, 0),
1120 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION, 1, 0),
1121 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT, 1, 0),
1122 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING, 1, 0),
1124 _DTV_CMD(DTV_STREAM_ID, 1, 0),
1125 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY, 1, 0),
1126 _DTV_CMD(DTV_SCRAMBLING_SEQUENCE_INDEX, 1, 0),
1127 _DTV_CMD(DTV_LNA, 1, 0),
1130 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY, 0, 1),
1131 _DTV_CMD(DTV_API_VERSION, 0, 0),
1133 _DTV_CMD(DTV_ENUM_DELSYS, 0, 0),
1135 _DTV_CMD(DTV_ATSCMH_PARADE_ID, 1, 0),
1136 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE, 1, 0),
1138 _DTV_CMD(DTV_ATSCMH_FIC_VER, 0, 0),
1139 _DTV_CMD(DTV_ATSCMH_NOG, 0, 0),
1140 _DTV_CMD(DTV_ATSCMH_TNOG, 0, 0),
1141 _DTV_CMD(DTV_ATSCMH_SGN, 0, 0),
1142 _DTV_CMD(DTV_ATSCMH_PRC, 0, 0),
1143 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE, 0, 0),
1144 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI, 0, 0),
1145 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC, 0, 0),
1146 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE, 0, 0),
1147 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A, 0, 0),
1148 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B, 0, 0),
1149 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C, 0, 0),
1150 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D, 0, 0),
1152 /* Statistics API */
1153 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH, 0, 0),
1154 _DTV_CMD(DTV_STAT_CNR, 0, 0),
1155 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT, 0, 0),
1156 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT, 0, 0),
1157 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT, 0, 0),
1158 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT, 0, 0),
1159 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT, 0, 0),
1160 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT, 0, 0),
1163 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1164 * drivers can use a single set_frontend tuning function, regardless of whether
1165 * it's being used for the legacy or new API, reducing code and complexity.
1167 static int dtv_property_cache_sync(struct dvb_frontend *fe,
1168 struct dtv_frontend_properties *c,
1169 const struct dvb_frontend_parameters *p)
1171 c->frequency = p->frequency;
1172 c->inversion = p->inversion;
1174 switch (dvbv3_type(c->delivery_system)) {
1176 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1177 c->symbol_rate = p->u.qpsk.symbol_rate;
1178 c->fec_inner = p->u.qpsk.fec_inner;
1181 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1182 c->symbol_rate = p->u.qam.symbol_rate;
1183 c->fec_inner = p->u.qam.fec_inner;
1184 c->modulation = p->u.qam.modulation;
1187 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1189 switch (p->u.ofdm.bandwidth) {
1190 case BANDWIDTH_10_MHZ:
1191 c->bandwidth_hz = 10000000;
1193 case BANDWIDTH_8_MHZ:
1194 c->bandwidth_hz = 8000000;
1196 case BANDWIDTH_7_MHZ:
1197 c->bandwidth_hz = 7000000;
1199 case BANDWIDTH_6_MHZ:
1200 c->bandwidth_hz = 6000000;
1202 case BANDWIDTH_5_MHZ:
1203 c->bandwidth_hz = 5000000;
1205 case BANDWIDTH_1_712_MHZ:
1206 c->bandwidth_hz = 1712000;
1208 case BANDWIDTH_AUTO:
1209 c->bandwidth_hz = 0;
1212 c->code_rate_HP = p->u.ofdm.code_rate_HP;
1213 c->code_rate_LP = p->u.ofdm.code_rate_LP;
1214 c->modulation = p->u.ofdm.constellation;
1215 c->transmission_mode = p->u.ofdm.transmission_mode;
1216 c->guard_interval = p->u.ofdm.guard_interval;
1217 c->hierarchy = p->u.ofdm.hierarchy_information;
1220 dev_dbg(fe->dvb->device, "%s: Preparing ATSC req\n", __func__);
1221 c->modulation = p->u.vsb.modulation;
1222 if (c->delivery_system == SYS_ATSCMH)
1224 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1225 c->delivery_system = SYS_ATSC;
1227 c->delivery_system = SYS_DVBC_ANNEX_B;
1230 dev_err(fe->dvb->device,
1231 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1232 __func__, c->delivery_system);
1239 /* Ensure the cached values are set correctly in the frontend
1240 * legacy tuning structures, for the advanced tuning API.
1243 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
1244 const struct dtv_frontend_properties *c,
1245 struct dvb_frontend_parameters *p)
1247 p->frequency = c->frequency;
1248 p->inversion = c->inversion;
1250 switch (dvbv3_type(c->delivery_system)) {
1252 dev_err(fe->dvb->device,
1253 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1254 __func__, c->delivery_system);
1257 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1258 p->u.qpsk.symbol_rate = c->symbol_rate;
1259 p->u.qpsk.fec_inner = c->fec_inner;
1262 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1263 p->u.qam.symbol_rate = c->symbol_rate;
1264 p->u.qam.fec_inner = c->fec_inner;
1265 p->u.qam.modulation = c->modulation;
1268 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1269 switch (c->bandwidth_hz) {
1271 p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ;
1274 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1277 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1280 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1283 p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ;
1286 p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ;
1290 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1292 p->u.ofdm.code_rate_HP = c->code_rate_HP;
1293 p->u.ofdm.code_rate_LP = c->code_rate_LP;
1294 p->u.ofdm.constellation = c->modulation;
1295 p->u.ofdm.transmission_mode = c->transmission_mode;
1296 p->u.ofdm.guard_interval = c->guard_interval;
1297 p->u.ofdm.hierarchy_information = c->hierarchy;
1300 dev_dbg(fe->dvb->device, "%s: Preparing VSB req\n", __func__);
1301 p->u.vsb.modulation = c->modulation;
1308 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1309 * @fe: struct dvb_frontend pointer
1310 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1311 * @p_out: struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1313 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1314 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1315 * If p_out is not null, it will update the DVBv3 params pointed by it.
1317 static int dtv_get_frontend(struct dvb_frontend *fe,
1318 struct dtv_frontend_properties *c,
1319 struct dvb_frontend_parameters *p_out)
1323 if (fe->ops.get_frontend) {
1324 r = fe->ops.get_frontend(fe, c);
1325 if (unlikely(r < 0))
1328 dtv_property_legacy_params_sync(fe, c, p_out);
1332 /* As everything is in cache, get_frontend fops are always supported */
1336 static int dvb_frontend_handle_ioctl(struct file *file,
1337 unsigned int cmd, void *parg);
1339 static int dtv_property_process_get(struct dvb_frontend *fe,
1340 const struct dtv_frontend_properties *c,
1341 struct dtv_property *tvp,
1347 case DTV_ENUM_DELSYS:
1349 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1350 tvp->u.buffer.data[ncaps] = fe->ops.delsys[ncaps];
1353 tvp->u.buffer.len = ncaps;
1356 tvp->u.data = c->frequency;
1358 case DTV_MODULATION:
1359 tvp->u.data = c->modulation;
1361 case DTV_BANDWIDTH_HZ:
1362 tvp->u.data = c->bandwidth_hz;
1365 tvp->u.data = c->inversion;
1367 case DTV_SYMBOL_RATE:
1368 tvp->u.data = c->symbol_rate;
1371 tvp->u.data = c->fec_inner;
1374 tvp->u.data = c->pilot;
1377 tvp->u.data = c->rolloff;
1379 case DTV_DELIVERY_SYSTEM:
1380 tvp->u.data = c->delivery_system;
1383 tvp->u.data = c->voltage;
1386 tvp->u.data = c->sectone;
1388 case DTV_API_VERSION:
1389 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1391 case DTV_CODE_RATE_HP:
1392 tvp->u.data = c->code_rate_HP;
1394 case DTV_CODE_RATE_LP:
1395 tvp->u.data = c->code_rate_LP;
1397 case DTV_GUARD_INTERVAL:
1398 tvp->u.data = c->guard_interval;
1400 case DTV_TRANSMISSION_MODE:
1401 tvp->u.data = c->transmission_mode;
1404 tvp->u.data = c->hierarchy;
1406 case DTV_INTERLEAVING:
1407 tvp->u.data = c->interleaving;
1410 /* ISDB-T Support here */
1411 case DTV_ISDBT_PARTIAL_RECEPTION:
1412 tvp->u.data = c->isdbt_partial_reception;
1414 case DTV_ISDBT_SOUND_BROADCASTING:
1415 tvp->u.data = c->isdbt_sb_mode;
1417 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1418 tvp->u.data = c->isdbt_sb_subchannel;
1420 case DTV_ISDBT_SB_SEGMENT_IDX:
1421 tvp->u.data = c->isdbt_sb_segment_idx;
1423 case DTV_ISDBT_SB_SEGMENT_COUNT:
1424 tvp->u.data = c->isdbt_sb_segment_count;
1426 case DTV_ISDBT_LAYER_ENABLED:
1427 tvp->u.data = c->isdbt_layer_enabled;
1429 case DTV_ISDBT_LAYERA_FEC:
1430 tvp->u.data = c->layer[0].fec;
1432 case DTV_ISDBT_LAYERA_MODULATION:
1433 tvp->u.data = c->layer[0].modulation;
1435 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1436 tvp->u.data = c->layer[0].segment_count;
1438 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1439 tvp->u.data = c->layer[0].interleaving;
1441 case DTV_ISDBT_LAYERB_FEC:
1442 tvp->u.data = c->layer[1].fec;
1444 case DTV_ISDBT_LAYERB_MODULATION:
1445 tvp->u.data = c->layer[1].modulation;
1447 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1448 tvp->u.data = c->layer[1].segment_count;
1450 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1451 tvp->u.data = c->layer[1].interleaving;
1453 case DTV_ISDBT_LAYERC_FEC:
1454 tvp->u.data = c->layer[2].fec;
1456 case DTV_ISDBT_LAYERC_MODULATION:
1457 tvp->u.data = c->layer[2].modulation;
1459 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1460 tvp->u.data = c->layer[2].segment_count;
1462 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1463 tvp->u.data = c->layer[2].interleaving;
1466 /* Multistream support */
1468 case DTV_DVBT2_PLP_ID_LEGACY:
1469 tvp->u.data = c->stream_id;
1472 /* Physical layer scrambling support */
1473 case DTV_SCRAMBLING_SEQUENCE_INDEX:
1474 tvp->u.data = c->scrambling_sequence_index;
1478 case DTV_ATSCMH_FIC_VER:
1479 tvp->u.data = fe->dtv_property_cache.atscmh_fic_ver;
1481 case DTV_ATSCMH_PARADE_ID:
1482 tvp->u.data = fe->dtv_property_cache.atscmh_parade_id;
1484 case DTV_ATSCMH_NOG:
1485 tvp->u.data = fe->dtv_property_cache.atscmh_nog;
1487 case DTV_ATSCMH_TNOG:
1488 tvp->u.data = fe->dtv_property_cache.atscmh_tnog;
1490 case DTV_ATSCMH_SGN:
1491 tvp->u.data = fe->dtv_property_cache.atscmh_sgn;
1493 case DTV_ATSCMH_PRC:
1494 tvp->u.data = fe->dtv_property_cache.atscmh_prc;
1496 case DTV_ATSCMH_RS_FRAME_MODE:
1497 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_mode;
1499 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
1500 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_ensemble;
1502 case DTV_ATSCMH_RS_CODE_MODE_PRI:
1503 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_pri;
1505 case DTV_ATSCMH_RS_CODE_MODE_SEC:
1506 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_sec;
1508 case DTV_ATSCMH_SCCC_BLOCK_MODE:
1509 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_block_mode;
1511 case DTV_ATSCMH_SCCC_CODE_MODE_A:
1512 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_a;
1514 case DTV_ATSCMH_SCCC_CODE_MODE_B:
1515 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_b;
1517 case DTV_ATSCMH_SCCC_CODE_MODE_C:
1518 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_c;
1520 case DTV_ATSCMH_SCCC_CODE_MODE_D:
1521 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_d;
1525 tvp->u.data = c->lna;
1528 /* Fill quality measures */
1529 case DTV_STAT_SIGNAL_STRENGTH:
1530 tvp->u.st = c->strength;
1535 case DTV_STAT_PRE_ERROR_BIT_COUNT:
1536 tvp->u.st = c->pre_bit_error;
1538 case DTV_STAT_PRE_TOTAL_BIT_COUNT:
1539 tvp->u.st = c->pre_bit_count;
1541 case DTV_STAT_POST_ERROR_BIT_COUNT:
1542 tvp->u.st = c->post_bit_error;
1544 case DTV_STAT_POST_TOTAL_BIT_COUNT:
1545 tvp->u.st = c->post_bit_count;
1547 case DTV_STAT_ERROR_BLOCK_COUNT:
1548 tvp->u.st = c->block_error;
1550 case DTV_STAT_TOTAL_BLOCK_COUNT:
1551 tvp->u.st = c->block_count;
1554 dev_dbg(fe->dvb->device,
1555 "%s: FE property %d doesn't exist\n",
1556 __func__, tvp->cmd);
1560 if (!dtv_cmds[tvp->cmd].buffer)
1561 dev_dbg(fe->dvb->device,
1562 "%s: GET cmd 0x%08x (%s) = 0x%08x\n",
1563 __func__, tvp->cmd, dtv_cmds[tvp->cmd].name,
1566 dev_dbg(fe->dvb->device,
1567 "%s: GET cmd 0x%08x (%s) len %d: %*ph\n",
1569 tvp->cmd, dtv_cmds[tvp->cmd].name,
1571 tvp->u.buffer.len, tvp->u.buffer.data);
1576 static int dtv_set_frontend(struct dvb_frontend *fe);
1578 static bool is_dvbv3_delsys(u32 delsys)
1580 return (delsys == SYS_DVBT) || (delsys == SYS_DVBC_ANNEX_A) ||
1581 (delsys == SYS_DVBS) || (delsys == SYS_ATSC);
1585 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1586 * @fe: struct frontend;
1587 * @delsys: DVBv5 type that will be used for emulation
1589 * Provides emulation for delivery systems that are compatible with the old
1590 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1591 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontend
1592 * parameters are compatible with DVB-S spec.
1594 static int emulate_delivery_system(struct dvb_frontend *fe, u32 delsys)
1597 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1599 c->delivery_system = delsys;
1602 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1604 if (c->delivery_system == SYS_ISDBT) {
1605 dev_dbg(fe->dvb->device,
1606 "%s: Using defaults for SYS_ISDBT\n",
1609 if (!c->bandwidth_hz)
1610 c->bandwidth_hz = 6000000;
1612 c->isdbt_partial_reception = 0;
1613 c->isdbt_sb_mode = 0;
1614 c->isdbt_sb_subchannel = 0;
1615 c->isdbt_sb_segment_idx = 0;
1616 c->isdbt_sb_segment_count = 0;
1617 c->isdbt_layer_enabled = 7;
1618 for (i = 0; i < 3; i++) {
1619 c->layer[i].fec = FEC_AUTO;
1620 c->layer[i].modulation = QAM_AUTO;
1621 c->layer[i].interleaving = 0;
1622 c->layer[i].segment_count = 0;
1625 dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n",
1626 __func__, c->delivery_system);
1632 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1633 * @fe: frontend struct
1634 * @desired_system: delivery system requested by the user
1636 * A DVBv5 call know what's the desired system it wants. So, set it.
1638 * There are, however, a few known issues with early DVBv5 applications that
1639 * are also handled by this logic:
1641 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1642 * This is an API violation, but, as we don't want to break userspace,
1643 * convert it to the first supported delivery system.
1644 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1645 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1646 * ISDB-T provided backward compat with DVB-T.
1648 static int dvbv5_set_delivery_system(struct dvb_frontend *fe,
1652 u32 delsys = SYS_UNDEFINED;
1653 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1654 enum dvbv3_emulation_type type;
1657 * It was reported that some old DVBv5 applications were
1658 * filling delivery_system with SYS_UNDEFINED. If this happens,
1659 * assume that the application wants to use the first supported
1662 if (desired_system == SYS_UNDEFINED)
1663 desired_system = fe->ops.delsys[0];
1666 * This is a DVBv5 call. So, it likely knows the supported
1667 * delivery systems. So, check if the desired delivery system is
1671 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1672 if (fe->ops.delsys[ncaps] == desired_system) {
1673 c->delivery_system = desired_system;
1674 dev_dbg(fe->dvb->device,
1675 "%s: Changing delivery system to %d\n",
1676 __func__, desired_system);
1683 * The requested delivery system isn't supported. Maybe userspace
1684 * is requesting a DVBv3 compatible delivery system.
1686 * The emulation only works if the desired system is one of the
1687 * delivery systems supported by DVBv3 API
1689 if (!is_dvbv3_delsys(desired_system)) {
1690 dev_dbg(fe->dvb->device,
1691 "%s: Delivery system %d not supported.\n",
1692 __func__, desired_system);
1696 type = dvbv3_type(desired_system);
1699 * Get the last non-DVBv3 delivery system that has the same type
1700 * of the desired system
1703 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1704 if (dvbv3_type(fe->ops.delsys[ncaps]) == type)
1705 delsys = fe->ops.delsys[ncaps];
1709 /* There's nothing compatible with the desired delivery system */
1710 if (delsys == SYS_UNDEFINED) {
1711 dev_dbg(fe->dvb->device,
1712 "%s: Delivery system %d not supported on emulation mode.\n",
1713 __func__, desired_system);
1717 dev_dbg(fe->dvb->device,
1718 "%s: Using delivery system %d emulated as if it were %d\n",
1719 __func__, delsys, desired_system);
1721 return emulate_delivery_system(fe, desired_system);
1725 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1726 * @fe: frontend struct
1728 * A DVBv3 call doesn't know what's the desired system it wants. It also
1729 * doesn't allow to switch between different types. Due to that, userspace
1730 * should use DVBv5 instead.
1731 * However, in order to avoid breaking userspace API, limited backward
1732 * compatibility support is provided.
1734 * There are some delivery systems that are incompatible with DVBv3 calls.
1736 * This routine should work fine for frontends that support just one delivery
1739 * For frontends that support multiple frontends:
1740 * 1) It defaults to use the first supported delivery system. There's an
1741 * userspace application that allows changing it at runtime;
1743 * 2) If the current delivery system is not compatible with DVBv3, it gets
1744 * the first one that it is compatible.
1746 * NOTE: in order for this to work with applications like Kaffeine that
1747 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1748 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1749 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1752 static int dvbv3_set_delivery_system(struct dvb_frontend *fe)
1755 u32 delsys = SYS_UNDEFINED;
1756 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1758 /* If not set yet, defaults to the first supported delivery system */
1759 if (c->delivery_system == SYS_UNDEFINED)
1760 c->delivery_system = fe->ops.delsys[0];
1763 * Trivial case: just use the current one, if it already a DVBv3
1766 if (is_dvbv3_delsys(c->delivery_system)) {
1767 dev_dbg(fe->dvb->device,
1768 "%s: Using delivery system to %d\n",
1769 __func__, c->delivery_system);
1774 * Seek for the first delivery system that it is compatible with a
1778 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1779 if (dvbv3_type(fe->ops.delsys[ncaps]) != DVBV3_UNKNOWN) {
1780 delsys = fe->ops.delsys[ncaps];
1785 if (delsys == SYS_UNDEFINED) {
1786 dev_dbg(fe->dvb->device,
1787 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1791 return emulate_delivery_system(fe, delsys);
1795 * dtv_property_process_set - Sets a single DTV property
1796 * @fe: Pointer to &struct dvb_frontend
1797 * @file: Pointer to &struct file
1798 * @cmd: Digital TV command
1799 * @data: An unsigned 32-bits number
1801 * This routine assigns the property
1802 * value to the corresponding member of
1803 * &struct dtv_frontend_properties
1806 * Zero on success, negative errno on failure.
1808 static int dtv_property_process_set(struct dvb_frontend *fe,
1813 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1815 /** Dump DTV command name and value*/
1816 if (!cmd || cmd > DTV_MAX_COMMAND)
1817 dev_warn(fe->dvb->device, "%s: SET cmd 0x%08x undefined\n",
1820 dev_dbg(fe->dvb->device,
1821 "%s: SET cmd 0x%08x (%s) to 0x%08x\n",
1822 __func__, cmd, dtv_cmds[cmd].name, data);
1826 * Reset a cache of data specific to the frontend here. This does
1827 * not effect hardware.
1829 dvb_frontend_clear_cache(fe);
1833 * Use the cached Digital TV properties to tune the
1836 dev_dbg(fe->dvb->device,
1837 "%s: Setting the frontend from property cache\n",
1840 r = dtv_set_frontend(fe);
1843 c->frequency = data;
1845 case DTV_MODULATION:
1846 c->modulation = data;
1848 case DTV_BANDWIDTH_HZ:
1849 c->bandwidth_hz = data;
1852 c->inversion = data;
1854 case DTV_SYMBOL_RATE:
1855 c->symbol_rate = data;
1858 c->fec_inner = data;
1866 case DTV_DELIVERY_SYSTEM:
1867 r = dvbv5_set_delivery_system(fe, data);
1871 r = dvb_frontend_handle_ioctl(file, FE_SET_VOLTAGE,
1872 (void *)c->voltage);
1876 r = dvb_frontend_handle_ioctl(file, FE_SET_TONE,
1877 (void *)c->sectone);
1879 case DTV_CODE_RATE_HP:
1880 c->code_rate_HP = data;
1882 case DTV_CODE_RATE_LP:
1883 c->code_rate_LP = data;
1885 case DTV_GUARD_INTERVAL:
1886 c->guard_interval = data;
1888 case DTV_TRANSMISSION_MODE:
1889 c->transmission_mode = data;
1892 c->hierarchy = data;
1894 case DTV_INTERLEAVING:
1895 c->interleaving = data;
1898 /* ISDB-T Support here */
1899 case DTV_ISDBT_PARTIAL_RECEPTION:
1900 c->isdbt_partial_reception = data;
1902 case DTV_ISDBT_SOUND_BROADCASTING:
1903 c->isdbt_sb_mode = data;
1905 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1906 c->isdbt_sb_subchannel = data;
1908 case DTV_ISDBT_SB_SEGMENT_IDX:
1909 c->isdbt_sb_segment_idx = data;
1911 case DTV_ISDBT_SB_SEGMENT_COUNT:
1912 c->isdbt_sb_segment_count = data;
1914 case DTV_ISDBT_LAYER_ENABLED:
1915 c->isdbt_layer_enabled = data;
1917 case DTV_ISDBT_LAYERA_FEC:
1918 c->layer[0].fec = data;
1920 case DTV_ISDBT_LAYERA_MODULATION:
1921 c->layer[0].modulation = data;
1923 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1924 c->layer[0].segment_count = data;
1926 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1927 c->layer[0].interleaving = data;
1929 case DTV_ISDBT_LAYERB_FEC:
1930 c->layer[1].fec = data;
1932 case DTV_ISDBT_LAYERB_MODULATION:
1933 c->layer[1].modulation = data;
1935 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1936 c->layer[1].segment_count = data;
1938 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1939 c->layer[1].interleaving = data;
1941 case DTV_ISDBT_LAYERC_FEC:
1942 c->layer[2].fec = data;
1944 case DTV_ISDBT_LAYERC_MODULATION:
1945 c->layer[2].modulation = data;
1947 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1948 c->layer[2].segment_count = data;
1950 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1951 c->layer[2].interleaving = data;
1954 /* Multistream support */
1956 case DTV_DVBT2_PLP_ID_LEGACY:
1957 c->stream_id = data;
1960 /* Physical layer scrambling support */
1961 case DTV_SCRAMBLING_SEQUENCE_INDEX:
1962 c->scrambling_sequence_index = data;
1966 case DTV_ATSCMH_PARADE_ID:
1967 fe->dtv_property_cache.atscmh_parade_id = data;
1969 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
1970 fe->dtv_property_cache.atscmh_rs_frame_ensemble = data;
1975 if (fe->ops.set_lna)
1976 r = fe->ops.set_lna(fe);
1988 static int dvb_frontend_do_ioctl(struct file *file, unsigned int cmd,
1991 struct dvb_device *dvbdev = file->private_data;
1992 struct dvb_frontend *fe = dvbdev->priv;
1993 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1996 dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd));
1997 if (down_interruptible(&fepriv->sem))
1998 return -ERESTARTSYS;
2000 if (fe->exit != DVB_FE_NO_EXIT) {
2006 * If the frontend is opened in read-only mode, only the ioctls
2007 * that don't interfere with the tune logic should be accepted.
2008 * That allows an external application to monitor the DVB QoS and
2009 * statistics parameters.
2011 * That matches all _IOR() ioctls, except for two special cases:
2012 * - FE_GET_EVENT is part of the tuning logic on a DVB application;
2013 * - FE_DISEQC_RECV_SLAVE_REPLY is part of DiSEqC 2.0
2015 * So, those two ioctls should also return -EPERM, as otherwise
2016 * reading from them would interfere with a DVB tune application
2018 if ((file->f_flags & O_ACCMODE) == O_RDONLY
2019 && (_IOC_DIR(cmd) != _IOC_READ
2020 || cmd == FE_GET_EVENT
2021 || cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
2026 err = dvb_frontend_handle_ioctl(file, cmd, parg);
2032 static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
2035 struct dvb_device *dvbdev = file->private_data;
2040 return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
2043 #ifdef CONFIG_COMPAT
2044 struct compat_dtv_property {
2049 struct dtv_fe_stats st;
2054 compat_uptr_t reserved2;
2058 } __attribute__ ((packed));
2060 struct compat_dtv_properties {
2062 compat_uptr_t props;
2065 #define COMPAT_FE_SET_PROPERTY _IOW('o', 82, struct compat_dtv_properties)
2066 #define COMPAT_FE_GET_PROPERTY _IOR('o', 83, struct compat_dtv_properties)
2068 static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
2071 struct dvb_device *dvbdev = file->private_data;
2072 struct dvb_frontend *fe = dvbdev->priv;
2073 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2076 if (cmd == COMPAT_FE_SET_PROPERTY) {
2077 struct compat_dtv_properties prop, *tvps = NULL;
2078 struct compat_dtv_property *tvp = NULL;
2080 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2086 * Put an arbitrary limit on the number of messages that can
2089 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2092 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2094 return PTR_ERR(tvp);
2096 for (i = 0; i < tvps->num; i++) {
2097 err = dtv_property_process_set(fe, file,
2106 } else if (cmd == COMPAT_FE_GET_PROPERTY) {
2107 struct compat_dtv_properties prop, *tvps = NULL;
2108 struct compat_dtv_property *tvp = NULL;
2109 struct dtv_frontend_properties getp = fe->dtv_property_cache;
2111 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2117 * Put an arbitrary limit on the number of messages that can
2120 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2123 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2125 return PTR_ERR(tvp);
2128 * Let's use our own copy of property cache, in order to
2129 * avoid mangling with DTV zigzag logic, as drivers might
2130 * return crap, if they don't check if the data is available
2131 * before updating the properties cache.
2133 if (fepriv->state != FESTATE_IDLE) {
2134 err = dtv_get_frontend(fe, &getp, NULL);
2140 for (i = 0; i < tvps->num; i++) {
2141 err = dtv_property_process_get(
2142 fe, &getp, (struct dtv_property *)(tvp + i), file);
2149 if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
2150 tvps->num * sizeof(struct compat_dtv_property))) {
2160 static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
2163 struct dvb_device *dvbdev = file->private_data;
2164 struct dvb_frontend *fe = dvbdev->priv;
2165 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2168 if (cmd == COMPAT_FE_SET_PROPERTY || cmd == COMPAT_FE_GET_PROPERTY) {
2169 if (down_interruptible(&fepriv->sem))
2170 return -ERESTARTSYS;
2172 err = dvb_frontend_handle_compat_ioctl(file, cmd, arg);
2178 return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
2182 static int dtv_set_frontend(struct dvb_frontend *fe)
2184 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2185 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2186 struct dvb_frontend_tune_settings fetunesettings;
2189 if (dvb_frontend_check_parameters(fe) < 0)
2193 * Initialize output parameters to match the values given by
2194 * the user. FE_SET_FRONTEND triggers an initial frontend event
2195 * with status = 0, which copies output parameters to userspace.
2197 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
2200 * Be sure that the bandwidth will be filled for all
2201 * non-satellite systems, as tuners need to know what
2202 * low pass/Nyquist half filter should be applied, in
2203 * order to avoid inter-channel noise.
2205 * ISDB-T and DVB-T/T2 already sets bandwidth.
2206 * ATSC and DVB-C don't set, so, the core should fill it.
2208 * On DVB-C Annex A and C, the bandwidth is a function of
2209 * the roll-off and symbol rate. Annex B defines different
2210 * roll-off factors depending on the modulation. Fortunately,
2211 * Annex B is only used with 6MHz, so there's no need to
2214 * While not officially supported, a side effect of handling it at
2215 * the cache level is that a program could retrieve the bandwidth
2216 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2218 switch (c->delivery_system) {
2220 case SYS_DVBC_ANNEX_B:
2221 c->bandwidth_hz = 6000000;
2223 case SYS_DVBC_ANNEX_A:
2226 case SYS_DVBC_ANNEX_C:
2235 switch (c->rolloff) {
2251 c->bandwidth_hz = mult_frac(c->symbol_rate, rolloff, 100);
2253 /* force auto frequency inversion if requested */
2254 if (dvb_force_auto_inversion)
2255 c->inversion = INVERSION_AUTO;
2258 * without hierarchical coding code_rate_LP is irrelevant,
2259 * so we tolerate the otherwise invalid FEC_NONE setting
2261 if (c->hierarchy == HIERARCHY_NONE && c->code_rate_LP == FEC_NONE)
2262 c->code_rate_LP = FEC_AUTO;
2264 /* get frontend-specific tuning settings */
2265 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
2266 if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) {
2267 fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000;
2268 fepriv->max_drift = fetunesettings.max_drift;
2269 fepriv->step_size = fetunesettings.step_size;
2271 /* default values */
2272 switch (c->delivery_system) {
2277 case SYS_DVBC_ANNEX_A:
2278 case SYS_DVBC_ANNEX_C:
2279 fepriv->min_delay = HZ / 20;
2280 fepriv->step_size = c->symbol_rate / 16000;
2281 fepriv->max_drift = c->symbol_rate / 2000;
2287 fepriv->min_delay = HZ / 20;
2288 fepriv->step_size = dvb_frontend_get_stepsize(fe) * 2;
2289 fepriv->max_drift = (dvb_frontend_get_stepsize(fe) * 2) + 1;
2293 * FIXME: This sounds wrong! if freqency_stepsize is
2294 * defined by the frontend, why not use it???
2296 fepriv->min_delay = HZ / 20;
2297 fepriv->step_size = 0; /* no zigzag */
2298 fepriv->max_drift = 0;
2302 if (dvb_override_tune_delay > 0)
2303 fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000;
2305 fepriv->state = FESTATE_RETUNE;
2307 /* Request the search algorithm to search */
2308 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
2310 dvb_frontend_clear_events(fe);
2311 dvb_frontend_add_event(fe, 0);
2312 dvb_frontend_wakeup(fe);
2318 static int dvb_get_property(struct dvb_frontend *fe, struct file *file,
2319 struct dtv_properties *tvps)
2321 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2322 struct dtv_property *tvp = NULL;
2323 struct dtv_frontend_properties getp;
2326 memcpy(&getp, &fe->dtv_property_cache, sizeof(getp));
2328 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2329 __func__, tvps->num);
2330 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2331 __func__, tvps->props);
2334 * Put an arbitrary limit on the number of messages that can
2337 if (!tvps->num || tvps->num > DTV_IOCTL_MAX_MSGS)
2340 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2342 return PTR_ERR(tvp);
2345 * Let's use our own copy of property cache, in order to
2346 * avoid mangling with DTV zigzag logic, as drivers might
2347 * return crap, if they don't check if the data is available
2348 * before updating the properties cache.
2350 if (fepriv->state != FESTATE_IDLE) {
2351 err = dtv_get_frontend(fe, &getp, NULL);
2355 for (i = 0; i < tvps->num; i++) {
2356 err = dtv_property_process_get(fe, &getp,
2362 if (copy_to_user((void __user *)tvps->props, tvp,
2363 tvps->num * sizeof(struct dtv_property))) {
2374 static int dvb_get_frontend(struct dvb_frontend *fe,
2375 struct dvb_frontend_parameters *p_out)
2377 struct dtv_frontend_properties getp;
2380 * Let's use our own copy of property cache, in order to
2381 * avoid mangling with DTV zigzag logic, as drivers might
2382 * return crap, if they don't check if the data is available
2383 * before updating the properties cache.
2385 memcpy(&getp, &fe->dtv_property_cache, sizeof(getp));
2387 return dtv_get_frontend(fe, &getp, p_out);
2390 static int dvb_frontend_handle_ioctl(struct file *file,
2391 unsigned int cmd, void *parg)
2393 struct dvb_device *dvbdev = file->private_data;
2394 struct dvb_frontend *fe = dvbdev->priv;
2395 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2396 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2397 int i, err = -ENOTSUPP;
2399 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2402 case FE_SET_PROPERTY: {
2403 struct dtv_properties *tvps = parg;
2404 struct dtv_property *tvp = NULL;
2406 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2407 __func__, tvps->num);
2408 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2409 __func__, tvps->props);
2412 * Put an arbitrary limit on the number of messages that can
2415 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2418 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2420 return PTR_ERR(tvp);
2422 for (i = 0; i < tvps->num; i++) {
2423 err = dtv_property_process_set(fe, file,
2435 case FE_GET_PROPERTY:
2436 err = dvb_get_property(fe, file, parg);
2440 struct dvb_frontend_info *info = parg;
2441 memset(info, 0, sizeof(*info));
2443 strscpy(info->name, fe->ops.info.name, sizeof(info->name));
2444 info->symbol_rate_min = fe->ops.info.symbol_rate_min;
2445 info->symbol_rate_max = fe->ops.info.symbol_rate_max;
2446 info->symbol_rate_tolerance = fe->ops.info.symbol_rate_tolerance;
2447 info->caps = fe->ops.info.caps;
2448 info->frequency_stepsize = dvb_frontend_get_stepsize(fe);
2449 dvb_frontend_get_frequency_limits(fe, &info->frequency_min,
2450 &info->frequency_max,
2451 &info->frequency_tolerance);
2454 * Associate the 4 delivery systems supported by DVBv3
2455 * API with their DVBv5 counterpart. For the other standards,
2456 * use the closest type, assuming that it would hopefully
2457 * work with a DVBv3 application.
2458 * It should be noticed that, on multi-frontend devices with
2459 * different types (terrestrial and cable, for example),
2460 * a pure DVBv3 application won't be able to use all delivery
2461 * systems. Yet, changing the DVBv5 cache to the other delivery
2462 * system should be enough for making it work.
2464 switch (dvbv3_type(c->delivery_system)) {
2466 info->type = FE_QPSK;
2469 info->type = FE_ATSC;
2472 info->type = FE_QAM;
2475 info->type = FE_OFDM;
2478 dev_err(fe->dvb->device,
2479 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2480 __func__, c->delivery_system);
2481 info->type = FE_OFDM;
2483 dev_dbg(fe->dvb->device, "%s: current delivery system on cache: %d, V3 type: %d\n",
2484 __func__, c->delivery_system, info->type);
2486 /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */
2487 if (!(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT))
2488 info->caps |= FE_CAN_INVERSION_AUTO;
2493 case FE_READ_STATUS: {
2494 enum fe_status *status = parg;
2496 /* if retune was requested but hasn't occurred yet, prevent
2497 * that user get signal state from previous tuning */
2498 if (fepriv->state == FESTATE_RETUNE ||
2499 fepriv->state == FESTATE_ERROR) {
2505 if (fe->ops.read_status)
2506 err = fe->ops.read_status(fe, status);
2510 case FE_DISEQC_RESET_OVERLOAD:
2511 if (fe->ops.diseqc_reset_overload) {
2512 err = fe->ops.diseqc_reset_overload(fe);
2513 fepriv->state = FESTATE_DISEQC;
2518 case FE_DISEQC_SEND_MASTER_CMD:
2519 if (fe->ops.diseqc_send_master_cmd) {
2520 struct dvb_diseqc_master_cmd *cmd = parg;
2522 if (cmd->msg_len > sizeof(cmd->msg)) {
2526 err = fe->ops.diseqc_send_master_cmd(fe, cmd);
2527 fepriv->state = FESTATE_DISEQC;
2532 case FE_DISEQC_SEND_BURST:
2533 if (fe->ops.diseqc_send_burst) {
2534 err = fe->ops.diseqc_send_burst(fe,
2535 (enum fe_sec_mini_cmd)parg);
2536 fepriv->state = FESTATE_DISEQC;
2542 if (fe->ops.set_tone) {
2543 err = fe->ops.set_tone(fe,
2544 (enum fe_sec_tone_mode)parg);
2545 fepriv->tone = (enum fe_sec_tone_mode)parg;
2546 fepriv->state = FESTATE_DISEQC;
2551 case FE_SET_VOLTAGE:
2552 if (fe->ops.set_voltage) {
2553 err = fe->ops.set_voltage(fe,
2554 (enum fe_sec_voltage)parg);
2555 fepriv->voltage = (enum fe_sec_voltage)parg;
2556 fepriv->state = FESTATE_DISEQC;
2561 case FE_DISEQC_RECV_SLAVE_REPLY:
2562 if (fe->ops.diseqc_recv_slave_reply)
2563 err = fe->ops.diseqc_recv_slave_reply(fe, parg);
2566 case FE_ENABLE_HIGH_LNB_VOLTAGE:
2567 if (fe->ops.enable_high_lnb_voltage)
2568 err = fe->ops.enable_high_lnb_voltage(fe, (long)parg);
2571 case FE_SET_FRONTEND_TUNE_MODE:
2572 fepriv->tune_mode_flags = (unsigned long)parg;
2575 /* DEPRECATED dish control ioctls */
2577 case FE_DISHNETWORK_SEND_LEGACY_CMD:
2578 if (fe->ops.dishnetwork_send_legacy_command) {
2579 err = fe->ops.dishnetwork_send_legacy_command(fe,
2580 (unsigned long)parg);
2581 fepriv->state = FESTATE_DISEQC;
2583 } else if (fe->ops.set_voltage) {
2585 * NOTE: This is a fallback condition. Some frontends
2586 * (stv0299 for instance) take longer than 8msec to
2587 * respond to a set_voltage command. Those switches
2588 * need custom routines to switch properly. For all
2589 * other frontends, the following should work ok.
2590 * Dish network legacy switches (as used by Dish500)
2591 * are controlled by sending 9-bit command words
2592 * spaced 8msec apart.
2593 * the actual command word is switch/port dependent
2594 * so it is up to the userspace application to send
2595 * the right command.
2596 * The command must always start with a '0' after
2597 * initialization, so parg is 8 bits and does not
2598 * include the initialization or start bit
2600 unsigned long swcmd = ((unsigned long)parg) << 1;
2606 if (dvb_frontend_debug)
2607 dprintk("switch command: 0x%04lx\n",
2609 nexttime = ktime_get_boottime();
2610 if (dvb_frontend_debug)
2612 /* before sending a command, initialize by sending
2613 * a 32ms 18V to the switch
2615 fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
2616 dvb_frontend_sleep_until(&nexttime, 32000);
2618 for (i = 0; i < 9; i++) {
2619 if (dvb_frontend_debug)
2620 tv[i + 1] = ktime_get_boottime();
2621 if ((swcmd & 0x01) != last) {
2622 /* set voltage to (last ? 13V : 18V) */
2623 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
2624 last = (last) ? 0 : 1;
2628 dvb_frontend_sleep_until(&nexttime, 8000);
2630 if (dvb_frontend_debug) {
2631 dprintk("(adapter %d): switch delay (should be 32k followed by all 8k)\n",
2633 for (i = 1; i < 10; i++)
2634 pr_info("%d: %d\n", i,
2635 (int)ktime_us_delta(tv[i], tv[i - 1]));
2638 fepriv->state = FESTATE_DISEQC;
2643 /* DEPRECATED statistics ioctls */
2646 if (fe->ops.read_ber) {
2648 err = fe->ops.read_ber(fe, parg);
2654 case FE_READ_SIGNAL_STRENGTH:
2655 if (fe->ops.read_signal_strength) {
2657 err = fe->ops.read_signal_strength(fe, parg);
2664 if (fe->ops.read_snr) {
2666 err = fe->ops.read_snr(fe, parg);
2672 case FE_READ_UNCORRECTED_BLOCKS:
2673 if (fe->ops.read_ucblocks) {
2675 err = fe->ops.read_ucblocks(fe, parg);
2681 /* DEPRECATED DVBv3 ioctls */
2683 case FE_SET_FRONTEND:
2684 err = dvbv3_set_delivery_system(fe);
2688 err = dtv_property_cache_sync(fe, c, parg);
2691 err = dtv_set_frontend(fe);
2695 err = dvb_frontend_get_event(fe, parg, file->f_flags);
2698 case FE_GET_FRONTEND:
2699 err = dvb_get_frontend(fe, parg);
2709 static __poll_t dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
2711 struct dvb_device *dvbdev = file->private_data;
2712 struct dvb_frontend *fe = dvbdev->priv;
2713 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2715 dev_dbg_ratelimited(fe->dvb->device, "%s:\n", __func__);
2717 poll_wait(file, &fepriv->events.wait_queue, wait);
2719 if (fepriv->events.eventw != fepriv->events.eventr)
2720 return (EPOLLIN | EPOLLRDNORM | EPOLLPRI);
2725 static int dvb_frontend_open(struct inode *inode, struct file *file)
2727 struct dvb_device *dvbdev = file->private_data;
2728 struct dvb_frontend *fe = dvbdev->priv;
2729 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2730 struct dvb_adapter *adapter = fe->dvb;
2733 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2734 if (fe->exit == DVB_FE_DEVICE_REMOVED)
2737 if (adapter->mfe_shared) {
2738 mutex_lock(&adapter->mfe_lock);
2740 if (!adapter->mfe_dvbdev)
2741 adapter->mfe_dvbdev = dvbdev;
2743 else if (adapter->mfe_dvbdev != dvbdev) {
2745 *mfedev = adapter->mfe_dvbdev;
2747 *mfe = mfedev->priv;
2748 struct dvb_frontend_private
2749 *mfepriv = mfe->frontend_priv;
2750 int mferetry = (dvb_mfe_wait_time << 1);
2752 mutex_unlock(&adapter->mfe_lock);
2753 while (mferetry-- && (mfedev->users != -1 ||
2755 if (msleep_interruptible(500)) {
2756 if (signal_pending(current))
2761 mutex_lock(&adapter->mfe_lock);
2762 if (adapter->mfe_dvbdev != dvbdev) {
2763 mfedev = adapter->mfe_dvbdev;
2765 mfepriv = mfe->frontend_priv;
2766 if (mfedev->users != -1 ||
2768 mutex_unlock(&adapter->mfe_lock);
2771 adapter->mfe_dvbdev = dvbdev;
2776 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
2777 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
2780 /* If we took control of the bus, we need to force
2781 reinitialization. This is because many ts_bus_ctrl()
2782 functions strobe the RESET pin on the demod, and if the
2783 frontend thread already exists then the dvb_init() routine
2784 won't get called (which is what usually does initial
2785 register configuration). */
2786 fepriv->reinitialise = 1;
2789 if ((ret = dvb_generic_open(inode, file)) < 0)
2792 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2793 /* normal tune mode when opened R/W */
2794 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
2796 fepriv->voltage = -1;
2798 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2799 mutex_lock(&fe->dvb->mdev_lock);
2800 if (fe->dvb->mdev) {
2801 mutex_lock(&fe->dvb->mdev->graph_mutex);
2802 if (fe->dvb->mdev->enable_source)
2803 ret = fe->dvb->mdev->enable_source(
2806 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2808 mutex_unlock(&fe->dvb->mdev_lock);
2809 dev_err(fe->dvb->device,
2810 "Tuner is busy. Error %d\n", ret);
2814 mutex_unlock(&fe->dvb->mdev_lock);
2816 ret = dvb_frontend_start(fe);
2820 /* empty event queue */
2821 fepriv->events.eventr = fepriv->events.eventw = 0;
2824 dvb_frontend_get(fe);
2826 if (adapter->mfe_shared)
2827 mutex_unlock(&adapter->mfe_lock);
2831 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2832 mutex_lock(&fe->dvb->mdev_lock);
2833 if (fe->dvb->mdev) {
2834 mutex_lock(&fe->dvb->mdev->graph_mutex);
2835 if (fe->dvb->mdev->disable_source)
2836 fe->dvb->mdev->disable_source(dvbdev->entity);
2837 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2839 mutex_unlock(&fe->dvb->mdev_lock);
2842 dvb_generic_release(inode, file);
2844 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
2845 fe->ops.ts_bus_ctrl(fe, 0);
2847 if (adapter->mfe_shared)
2848 mutex_unlock(&adapter->mfe_lock);
2852 static int dvb_frontend_release(struct inode *inode, struct file *file)
2854 struct dvb_device *dvbdev = file->private_data;
2855 struct dvb_frontend *fe = dvbdev->priv;
2856 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2859 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2861 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2862 fepriv->release_jiffies = jiffies;
2866 ret = dvb_generic_release(inode, file);
2868 if (dvbdev->users == -1) {
2869 wake_up(&fepriv->wait_queue);
2870 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2871 mutex_lock(&fe->dvb->mdev_lock);
2872 if (fe->dvb->mdev) {
2873 mutex_lock(&fe->dvb->mdev->graph_mutex);
2874 if (fe->dvb->mdev->disable_source)
2875 fe->dvb->mdev->disable_source(dvbdev->entity);
2876 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2878 mutex_unlock(&fe->dvb->mdev_lock);
2880 if (fe->exit != DVB_FE_NO_EXIT)
2881 wake_up(&dvbdev->wait_queue);
2882 if (fe->ops.ts_bus_ctrl)
2883 fe->ops.ts_bus_ctrl(fe, 0);
2886 dvb_frontend_put(fe);
2891 static const struct file_operations dvb_frontend_fops = {
2892 .owner = THIS_MODULE,
2893 .unlocked_ioctl = dvb_frontend_ioctl,
2894 #ifdef CONFIG_COMPAT
2895 .compat_ioctl = dvb_frontend_compat_ioctl,
2897 .poll = dvb_frontend_poll,
2898 .open = dvb_frontend_open,
2899 .release = dvb_frontend_release,
2900 .llseek = noop_llseek,
2903 int dvb_frontend_suspend(struct dvb_frontend *fe)
2907 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2910 if (fe->ops.tuner_ops.suspend)
2911 ret = fe->ops.tuner_ops.suspend(fe);
2912 else if (fe->ops.tuner_ops.sleep)
2913 ret = fe->ops.tuner_ops.sleep(fe);
2916 ret = fe->ops.sleep(fe);
2920 EXPORT_SYMBOL(dvb_frontend_suspend);
2922 int dvb_frontend_resume(struct dvb_frontend *fe)
2924 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2927 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2930 fe->exit = DVB_FE_DEVICE_RESUME;
2932 ret = fe->ops.init(fe);
2934 if (fe->ops.tuner_ops.resume)
2935 ret = fe->ops.tuner_ops.resume(fe);
2936 else if (fe->ops.tuner_ops.init)
2937 ret = fe->ops.tuner_ops.init(fe);
2939 if (fe->ops.set_tone && fepriv->tone != -1)
2940 fe->ops.set_tone(fe, fepriv->tone);
2941 if (fe->ops.set_voltage && fepriv->voltage != -1)
2942 fe->ops.set_voltage(fe, fepriv->voltage);
2944 fe->exit = DVB_FE_NO_EXIT;
2945 fepriv->state = FESTATE_RETUNE;
2946 dvb_frontend_wakeup(fe);
2950 EXPORT_SYMBOL(dvb_frontend_resume);
2952 int dvb_register_frontend(struct dvb_adapter *dvb,
2953 struct dvb_frontend *fe)
2955 struct dvb_frontend_private *fepriv;
2956 const struct dvb_device dvbdev_template = {
2959 .readers = (~0) - 1,
2960 .fops = &dvb_frontend_fops,
2961 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
2962 .name = fe->ops.info.name,
2966 dev_dbg(dvb->device, "%s:\n", __func__);
2968 if (mutex_lock_interruptible(&frontend_mutex))
2969 return -ERESTARTSYS;
2971 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
2972 if (!fe->frontend_priv) {
2973 mutex_unlock(&frontend_mutex);
2976 fepriv = fe->frontend_priv;
2978 kref_init(&fe->refcount);
2981 * After initialization, there need to be two references: one
2982 * for dvb_unregister_frontend(), and another one for
2983 * dvb_frontend_detach().
2985 dvb_frontend_get(fe);
2987 sema_init(&fepriv->sem, 1);
2988 init_waitqueue_head(&fepriv->wait_queue);
2989 init_waitqueue_head(&fepriv->events.wait_queue);
2990 mutex_init(&fepriv->events.mtx);
2992 fepriv->inversion = INVERSION_OFF;
2994 dev_info(fe->dvb->device,
2995 "DVB: registering adapter %i frontend %i (%s)...\n",
2996 fe->dvb->num, fe->id, fe->ops.info.name);
2998 dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
2999 fe, DVB_DEVICE_FRONTEND, 0);
3002 * Initialize the cache to the proper values according with the
3003 * first supported delivery system (ops->delsys[0])
3006 fe->dtv_property_cache.delivery_system = fe->ops.delsys[0];
3007 dvb_frontend_clear_cache(fe);
3009 mutex_unlock(&frontend_mutex);
3012 EXPORT_SYMBOL(dvb_register_frontend);
3014 int dvb_unregister_frontend(struct dvb_frontend *fe)
3016 struct dvb_frontend_private *fepriv = fe->frontend_priv;
3018 dev_dbg(fe->dvb->device, "%s:\n", __func__);
3020 mutex_lock(&frontend_mutex);
3021 dvb_frontend_stop(fe);
3022 dvb_remove_device(fepriv->dvbdev);
3024 /* fe is invalid now */
3025 mutex_unlock(&frontend_mutex);
3026 dvb_frontend_put(fe);
3029 EXPORT_SYMBOL(dvb_unregister_frontend);
3031 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
3032 void (*release)(struct dvb_frontend *fe))
3036 #ifdef CONFIG_MEDIA_ATTACH
3037 dvb_detach(release);
3042 void dvb_frontend_detach(struct dvb_frontend *fe)
3044 dvb_frontend_invoke_release(fe, fe->ops.release_sec);
3045 dvb_frontend_invoke_release(fe, fe->ops.tuner_ops.release);
3046 dvb_frontend_invoke_release(fe, fe->ops.analog_ops.release);
3047 dvb_frontend_put(fe);
3049 EXPORT_SYMBOL(dvb_frontend_detach);