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/nospec.h>
27 #include <linux/list.h>
28 #include <linux/freezer.h>
29 #include <linux/jiffies.h>
30 #include <linux/kthread.h>
31 #include <linux/ktime.h>
32 #include <linux/compat.h>
33 #include <asm/processor.h>
35 #include <media/dvb_frontend.h>
36 #include <media/dvbdev.h>
37 #include <linux/dvb/version.h>
39 static int dvb_frontend_debug;
40 static int dvb_shutdown_timeout;
41 static int dvb_force_auto_inversion;
42 static int dvb_override_tune_delay;
43 static int dvb_powerdown_on_sleep = 1;
44 static int dvb_mfe_wait_time = 5;
46 module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
47 MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
48 module_param(dvb_shutdown_timeout, int, 0644);
49 MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
50 module_param(dvb_force_auto_inversion, int, 0644);
51 MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
52 module_param(dvb_override_tune_delay, int, 0644);
53 MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
54 module_param(dvb_powerdown_on_sleep, int, 0644);
55 MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
56 module_param(dvb_mfe_wait_time, int, 0644);
57 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)");
59 #define dprintk(fmt, arg...) \
60 printk(KERN_DEBUG pr_fmt("%s: " fmt), __func__, ##arg)
62 #define FESTATE_IDLE 1
63 #define FESTATE_RETUNE 2
64 #define FESTATE_TUNING_FAST 4
65 #define FESTATE_TUNING_SLOW 8
66 #define FESTATE_TUNED 16
67 #define FESTATE_ZIGZAG_FAST 32
68 #define FESTATE_ZIGZAG_SLOW 64
69 #define FESTATE_DISEQC 128
70 #define FESTATE_ERROR 256
71 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
72 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
73 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
74 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
77 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
78 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
79 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
80 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
81 * FESTATE_TUNED. The frontend has successfully locked on.
82 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
83 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
84 * FESTATE_DISEQC. A DISEQC command has just been issued.
85 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
86 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
87 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
88 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
91 static DEFINE_MUTEX(frontend_mutex);
93 struct dvb_frontend_private {
94 /* thread/frontend values */
95 struct dvb_device *dvbdev;
96 struct dvb_frontend_parameters parameters_out;
97 struct dvb_fe_events events;
99 struct list_head list_head;
100 wait_queue_head_t wait_queue;
101 struct task_struct *thread;
102 unsigned long release_jiffies;
104 enum fe_status status;
105 unsigned long tune_mode_flags;
107 unsigned int reinitialise;
111 /* swzigzag values */
113 unsigned int bending;
115 unsigned int inversion;
116 unsigned int auto_step;
117 unsigned int auto_sub_step;
118 unsigned int started_auto_step;
119 unsigned int min_delay;
120 unsigned int max_drift;
121 unsigned int step_size;
123 unsigned int check_wrapped;
124 enum dvbfe_search algo_status;
126 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
127 struct media_pipeline pipe;
131 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
132 void (*release)(struct dvb_frontend *fe));
134 static void __dvb_frontend_free(struct dvb_frontend *fe)
136 struct dvb_frontend_private *fepriv = fe->frontend_priv;
139 dvb_device_put(fepriv->dvbdev);
141 dvb_frontend_invoke_release(fe, fe->ops.release);
146 static void dvb_frontend_free(struct kref *ref)
148 struct dvb_frontend *fe =
149 container_of(ref, struct dvb_frontend, refcount);
151 __dvb_frontend_free(fe);
154 static void dvb_frontend_put(struct dvb_frontend *fe)
156 /* call detach before dropping the reference count */
160 * Check if the frontend was registered, as otherwise
161 * kref was not initialized yet.
163 if (fe->frontend_priv)
164 kref_put(&fe->refcount, dvb_frontend_free);
166 __dvb_frontend_free(fe);
169 static void dvb_frontend_get(struct dvb_frontend *fe)
171 kref_get(&fe->refcount);
174 static void dvb_frontend_wakeup(struct dvb_frontend *fe);
175 static int dtv_get_frontend(struct dvb_frontend *fe,
176 struct dtv_frontend_properties *c,
177 struct dvb_frontend_parameters *p_out);
179 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
180 const struct dtv_frontend_properties *c,
181 struct dvb_frontend_parameters *p);
183 static bool has_get_frontend(struct dvb_frontend *fe)
185 return fe->ops.get_frontend;
189 * Due to DVBv3 API calls, a delivery system should be mapped into one of
190 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
191 * otherwise, a DVBv3 call will fail.
193 enum dvbv3_emulation_type {
201 static enum dvbv3_emulation_type dvbv3_type(u32 delivery_system)
203 switch (delivery_system) {
204 case SYS_DVBC_ANNEX_A:
205 case SYS_DVBC_ANNEX_C:
220 case SYS_DVBC_ANNEX_B:
228 * Doesn't know how to emulate those types and/or
229 * there's no frontend driver from this type yet
230 * with some emulation code, so, we're not sure yet how
231 * to handle them, or they're not compatible with a DVBv3 call.
233 return DVBV3_UNKNOWN;
237 static void dvb_frontend_add_event(struct dvb_frontend *fe,
238 enum fe_status status)
240 struct dvb_frontend_private *fepriv = fe->frontend_priv;
241 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
242 struct dvb_fe_events *events = &fepriv->events;
243 struct dvb_frontend_event *e;
246 dev_dbg(fe->dvb->device, "%s:\n", __func__);
248 if ((status & FE_HAS_LOCK) && has_get_frontend(fe))
249 dtv_get_frontend(fe, c, &fepriv->parameters_out);
251 mutex_lock(&events->mtx);
253 wp = (events->eventw + 1) % MAX_EVENT;
254 if (wp == events->eventr) {
255 events->overflow = 1;
256 events->eventr = (events->eventr + 1) % MAX_EVENT;
259 e = &events->events[events->eventw];
261 e->parameters = fepriv->parameters_out;
265 mutex_unlock(&events->mtx);
267 wake_up_interruptible(&events->wait_queue);
270 static int dvb_frontend_test_event(struct dvb_frontend_private *fepriv,
271 struct dvb_fe_events *events)
276 ret = events->eventw != events->eventr;
282 static int dvb_frontend_get_event(struct dvb_frontend *fe,
283 struct dvb_frontend_event *event, int flags)
285 struct dvb_frontend_private *fepriv = fe->frontend_priv;
286 struct dvb_fe_events *events = &fepriv->events;
288 dev_dbg(fe->dvb->device, "%s:\n", __func__);
290 if (events->overflow) {
291 events->overflow = 0;
295 if (events->eventw == events->eventr) {
298 if (flags & O_NONBLOCK)
301 ret = wait_event_interruptible(events->wait_queue,
302 dvb_frontend_test_event(fepriv, events));
308 mutex_lock(&events->mtx);
309 *event = events->events[events->eventr];
310 events->eventr = (events->eventr + 1) % MAX_EVENT;
311 mutex_unlock(&events->mtx);
316 static void dvb_frontend_clear_events(struct dvb_frontend *fe)
318 struct dvb_frontend_private *fepriv = fe->frontend_priv;
319 struct dvb_fe_events *events = &fepriv->events;
321 mutex_lock(&events->mtx);
322 events->eventr = events->eventw;
323 mutex_unlock(&events->mtx);
326 static void dvb_frontend_init(struct dvb_frontend *fe)
328 dev_dbg(fe->dvb->device,
329 "%s: initialising adapter %i frontend %i (%s)...\n",
330 __func__, fe->dvb->num, fe->id, fe->ops.info.name);
334 if (fe->ops.tuner_ops.init) {
335 if (fe->ops.i2c_gate_ctrl)
336 fe->ops.i2c_gate_ctrl(fe, 1);
337 fe->ops.tuner_ops.init(fe);
338 if (fe->ops.i2c_gate_ctrl)
339 fe->ops.i2c_gate_ctrl(fe, 0);
343 void dvb_frontend_reinitialise(struct dvb_frontend *fe)
345 struct dvb_frontend_private *fepriv = fe->frontend_priv;
347 fepriv->reinitialise = 1;
348 dvb_frontend_wakeup(fe);
350 EXPORT_SYMBOL(dvb_frontend_reinitialise);
352 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
355 struct dvb_frontend *fe = fepriv->dvbdev->priv;
357 dev_dbg(fe->dvb->device, "%s:\n", __func__);
360 (fepriv->quality) = (fepriv->quality * 220 + 36 * 256) / 256;
362 (fepriv->quality) = (fepriv->quality * 220 + 0) / 256;
364 q2 = fepriv->quality - 128;
367 fepriv->delay = fepriv->min_delay + q2 * HZ / (128 * 128);
371 * dvb_frontend_swzigzag_autotune - Performs automatic twiddling of frontend
374 * @fe: The frontend concerned.
375 * @check_wrapped: Checks if an iteration has completed.
376 * DO NOT SET ON THE FIRST ATTEMPT.
378 * return: Number of complete iterations that have been performed.
380 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped)
385 struct dvb_frontend_private *fepriv = fe->frontend_priv;
386 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
387 int original_inversion = c->inversion;
388 u32 original_frequency = c->frequency;
390 /* are we using autoinversion? */
391 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
392 (c->inversion == INVERSION_AUTO));
394 /* setup parameters correctly */
396 /* calculate the lnb_drift */
397 fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size;
399 /* wrap the auto_step if we've exceeded the maximum drift */
400 if (fepriv->lnb_drift > fepriv->max_drift) {
401 fepriv->auto_step = 0;
402 fepriv->auto_sub_step = 0;
403 fepriv->lnb_drift = 0;
406 /* perform inversion and +/- zigzag */
407 switch (fepriv->auto_sub_step) {
409 /* try with the current inversion and current drift setting */
414 if (!autoinversion) break;
416 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
421 if (fepriv->lnb_drift == 0) break;
423 fepriv->lnb_drift = -fepriv->lnb_drift;
428 if (fepriv->lnb_drift == 0) break;
429 if (!autoinversion) break;
431 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
432 fepriv->lnb_drift = -fepriv->lnb_drift;
438 fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */
442 if (!ready) fepriv->auto_sub_step++;
445 /* if this attempt would hit where we started, indicate a complete
446 * iteration has occurred */
447 if ((fepriv->auto_step == fepriv->started_auto_step) &&
448 (fepriv->auto_sub_step == 0) && check_wrapped) {
452 dev_dbg(fe->dvb->device,
453 "%s: drift:%i inversion:%i auto_step:%i auto_sub_step:%i started_auto_step:%i\n",
454 __func__, fepriv->lnb_drift, fepriv->inversion,
455 fepriv->auto_step, fepriv->auto_sub_step,
456 fepriv->started_auto_step);
458 /* set the frontend itself */
459 c->frequency += fepriv->lnb_drift;
461 c->inversion = fepriv->inversion;
463 if (fe->ops.set_frontend)
464 fe_set_err = fe->ops.set_frontend(fe);
466 if (fe_set_err < 0) {
467 fepriv->state = FESTATE_ERROR;
471 c->frequency = original_frequency;
472 c->inversion = original_inversion;
474 fepriv->auto_sub_step++;
478 static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
480 enum fe_status s = FE_NONE;
482 struct dvb_frontend_private *fepriv = fe->frontend_priv;
483 struct dtv_frontend_properties *c = &fe->dtv_property_cache, tmp;
485 if (fepriv->max_drift)
486 dev_warn_once(fe->dvb->device,
487 "Frontend requested software zigzag, but didn't set the frequency step size\n");
489 /* if we've got no parameters, just keep idling */
490 if (fepriv->state & FESTATE_IDLE) {
491 fepriv->delay = 3 * HZ;
496 /* in SCAN mode, we just set the frontend when asked and leave it alone */
497 if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) {
498 if (fepriv->state & FESTATE_RETUNE) {
500 if (fe->ops.set_frontend)
501 retval = fe->ops.set_frontend(fe);
504 fepriv->state = FESTATE_ERROR;
506 fepriv->state = FESTATE_TUNED;
508 fepriv->delay = 3 * HZ;
513 /* get the frontend status */
514 if (fepriv->state & FESTATE_RETUNE) {
517 if (fe->ops.read_status)
518 fe->ops.read_status(fe, &s);
519 if (s != fepriv->status) {
520 dvb_frontend_add_event(fe, s);
525 /* if we're not tuned, and we have a lock, move to the TUNED state */
526 if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) {
527 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
528 fepriv->state = FESTATE_TUNED;
530 /* if we're tuned, then we have determined the correct inversion */
531 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
532 (c->inversion == INVERSION_AUTO)) {
533 c->inversion = fepriv->inversion;
538 /* if we are tuned already, check we're still locked */
539 if (fepriv->state & FESTATE_TUNED) {
540 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
542 /* we're tuned, and the lock is still good... */
543 if (s & FE_HAS_LOCK) {
545 } else { /* if we _WERE_ tuned, but now don't have a lock */
546 fepriv->state = FESTATE_ZIGZAG_FAST;
547 fepriv->started_auto_step = fepriv->auto_step;
548 fepriv->check_wrapped = 0;
552 /* don't actually do anything if we're in the LOSTLOCK state,
553 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
554 if ((fepriv->state & FESTATE_LOSTLOCK) &&
555 (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) {
556 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
560 /* don't do anything if we're in the DISEQC state, since this
561 * might be someone with a motorized dish controlled by DISEQC.
562 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
563 if (fepriv->state & FESTATE_DISEQC) {
564 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
568 /* if we're in the RETUNE state, set everything up for a brand
569 * new scan, keeping the current inversion setting, as the next
570 * tune is _very_ likely to require the same */
571 if (fepriv->state & FESTATE_RETUNE) {
572 fepriv->lnb_drift = 0;
573 fepriv->auto_step = 0;
574 fepriv->auto_sub_step = 0;
575 fepriv->started_auto_step = 0;
576 fepriv->check_wrapped = 0;
580 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
581 fepriv->delay = fepriv->min_delay;
584 retval = dvb_frontend_swzigzag_autotune(fe,
585 fepriv->check_wrapped);
589 /* OK, if we've run out of trials at the fast speed.
590 * Drop back to slow for the _next_ attempt */
591 fepriv->state = FESTATE_SEARCHING_SLOW;
592 fepriv->started_auto_step = fepriv->auto_step;
595 fepriv->check_wrapped = 1;
597 /* if we've just re-tuned, enter the ZIGZAG_FAST state.
598 * This ensures we cannot return from an
599 * FE_SET_FRONTEND ioctl before the first frontend tune
601 if (fepriv->state & FESTATE_RETUNE) {
602 fepriv->state = FESTATE_TUNING_FAST;
607 if (fepriv->state & FESTATE_SEARCHING_SLOW) {
608 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
610 /* Note: don't bother checking for wrapping; we stay in this
611 * state until we get a lock */
612 dvb_frontend_swzigzag_autotune(fe, 0);
616 static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
618 struct dvb_frontend_private *fepriv = fe->frontend_priv;
620 if (fe->exit != DVB_FE_NO_EXIT)
623 if (fepriv->dvbdev->writers == 1)
624 if (time_after_eq(jiffies, fepriv->release_jiffies +
625 dvb_shutdown_timeout * HZ))
631 static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
633 struct dvb_frontend_private *fepriv = fe->frontend_priv;
635 if (fepriv->wakeup) {
639 return dvb_frontend_is_exiting(fe);
642 static void dvb_frontend_wakeup(struct dvb_frontend *fe)
644 struct dvb_frontend_private *fepriv = fe->frontend_priv;
647 wake_up_interruptible(&fepriv->wait_queue);
650 static int dvb_frontend_thread(void *data)
652 struct dvb_frontend *fe = data;
653 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
654 struct dvb_frontend_private *fepriv = fe->frontend_priv;
655 enum fe_status s = FE_NONE;
656 enum dvbfe_algo algo;
657 bool re_tune = false;
658 bool semheld = false;
660 dev_dbg(fe->dvb->device, "%s:\n", __func__);
662 fepriv->check_wrapped = 0;
664 fepriv->delay = 3 * HZ;
667 fepriv->reinitialise = 0;
669 dvb_frontend_init(fe);
673 up(&fepriv->sem); /* is locked when we enter the thread... */
675 wait_event_interruptible_timeout(fepriv->wait_queue,
676 dvb_frontend_should_wakeup(fe) ||
677 kthread_should_stop() ||
681 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
682 /* got signal or quitting */
683 if (!down_interruptible(&fepriv->sem))
685 fe->exit = DVB_FE_NORMAL_EXIT;
692 if (down_interruptible(&fepriv->sem))
695 if (fepriv->reinitialise) {
696 dvb_frontend_init(fe);
697 if (fe->ops.set_tone && fepriv->tone != -1)
698 fe->ops.set_tone(fe, fepriv->tone);
699 if (fe->ops.set_voltage && fepriv->voltage != -1)
700 fe->ops.set_voltage(fe, fepriv->voltage);
701 fepriv->reinitialise = 0;
704 /* do an iteration of the tuning loop */
705 if (fe->ops.get_frontend_algo) {
706 algo = fe->ops.get_frontend_algo(fe);
709 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__);
711 if (fepriv->state & FESTATE_RETUNE) {
712 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTATE_RETUNE\n", __func__);
714 fepriv->state = FESTATE_TUNED;
720 fe->ops.tune(fe, re_tune, fepriv->tune_mode_flags, &fepriv->delay, &s);
722 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
723 dev_dbg(fe->dvb->device, "%s: state changed, adding current state\n", __func__);
724 dvb_frontend_add_event(fe, s);
729 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__);
730 dvb_frontend_swzigzag(fe);
732 case DVBFE_ALGO_CUSTOM:
733 dev_dbg(fe->dvb->device, "%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
734 if (fepriv->state & FESTATE_RETUNE) {
735 dev_dbg(fe->dvb->device, "%s: Retune requested, FESTAT_RETUNE\n", __func__);
736 fepriv->state = FESTATE_TUNED;
738 /* Case where we are going to search for a carrier
739 * User asked us to retune again for some reason, possibly
740 * requesting a search with a new set of parameters
742 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
743 if (fe->ops.search) {
744 fepriv->algo_status = fe->ops.search(fe);
745 /* We did do a search as was requested, the flags are
746 * now unset as well and has the flags wrt to search.
749 fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN;
752 /* Track the carrier if the search was successful */
753 if (fepriv->algo_status != DVBFE_ALGO_SEARCH_SUCCESS) {
754 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
755 fepriv->delay = HZ / 2;
757 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
758 fe->ops.read_status(fe, &s);
759 if (s != fepriv->status) {
760 dvb_frontend_add_event(fe, s); /* update event list */
762 if (!(s & FE_HAS_LOCK)) {
763 fepriv->delay = HZ / 10;
764 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
766 fepriv->delay = 60 * HZ;
771 dev_dbg(fe->dvb->device, "%s: UNDEFINED ALGO !\n", __func__);
775 dvb_frontend_swzigzag(fe);
779 if (dvb_powerdown_on_sleep) {
780 if (fe->ops.set_voltage)
781 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
782 if (fe->ops.tuner_ops.sleep) {
783 if (fe->ops.i2c_gate_ctrl)
784 fe->ops.i2c_gate_ctrl(fe, 1);
785 fe->ops.tuner_ops.sleep(fe);
786 if (fe->ops.i2c_gate_ctrl)
787 fe->ops.i2c_gate_ctrl(fe, 0);
793 fepriv->thread = NULL;
794 if (kthread_should_stop())
795 fe->exit = DVB_FE_DEVICE_REMOVED;
797 fe->exit = DVB_FE_NO_EXIT;
802 dvb_frontend_wakeup(fe);
806 static void dvb_frontend_stop(struct dvb_frontend *fe)
808 struct dvb_frontend_private *fepriv = fe->frontend_priv;
810 dev_dbg(fe->dvb->device, "%s:\n", __func__);
812 if (fe->exit != DVB_FE_DEVICE_REMOVED)
813 fe->exit = DVB_FE_NORMAL_EXIT;
819 kthread_stop(fepriv->thread);
821 sema_init(&fepriv->sem, 1);
822 fepriv->state = FESTATE_IDLE;
824 /* paranoia check in case a signal arrived */
826 dev_warn(fe->dvb->device,
827 "dvb_frontend_stop: warning: thread %p won't exit\n",
832 * Sleep for the amount of time given by add_usec parameter
834 * This needs to be as precise as possible, as it affects the detection of
835 * the dish tone command at the satellite subsystem. The precision is improved
836 * by using a scheduled msleep followed by udelay for the remainder.
838 void dvb_frontend_sleep_until(ktime_t *waketime, u32 add_usec)
842 *waketime = ktime_add_us(*waketime, add_usec);
843 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
845 msleep((delta - 1500) / 1000);
846 delta = ktime_us_delta(ktime_get_boottime(), *waketime);
851 EXPORT_SYMBOL(dvb_frontend_sleep_until);
853 static int dvb_frontend_start(struct dvb_frontend *fe)
856 struct dvb_frontend_private *fepriv = fe->frontend_priv;
857 struct task_struct *fe_thread;
859 dev_dbg(fe->dvb->device, "%s:\n", __func__);
861 if (fepriv->thread) {
862 if (fe->exit == DVB_FE_NO_EXIT)
865 dvb_frontend_stop(fe);
868 if (signal_pending(current))
870 if (down_interruptible(&fepriv->sem))
873 fepriv->state = FESTATE_IDLE;
874 fe->exit = DVB_FE_NO_EXIT;
875 fepriv->thread = NULL;
878 fe_thread = kthread_run(dvb_frontend_thread, fe,
879 "kdvb-ad-%i-fe-%i", fe->dvb->num, fe->id);
880 if (IS_ERR(fe_thread)) {
881 ret = PTR_ERR(fe_thread);
882 dev_warn(fe->dvb->device,
883 "dvb_frontend_start: failed to start kthread (%d)\n",
888 fepriv->thread = fe_thread;
892 static void dvb_frontend_get_frequency_limits(struct dvb_frontend *fe,
893 u32 *freq_min, u32 *freq_max,
896 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
897 u32 tuner_min = fe->ops.tuner_ops.info.frequency_min_hz;
898 u32 tuner_max = fe->ops.tuner_ops.info.frequency_max_hz;
899 u32 frontend_min = fe->ops.info.frequency_min_hz;
900 u32 frontend_max = fe->ops.info.frequency_max_hz;
902 *freq_min = max(frontend_min, tuner_min);
904 if (frontend_max == 0)
905 *freq_max = tuner_max;
906 else if (tuner_max == 0)
907 *freq_max = frontend_max;
909 *freq_max = min(frontend_max, tuner_max);
911 if (*freq_min == 0 || *freq_max == 0)
912 dev_warn(fe->dvb->device,
913 "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
914 fe->dvb->num, fe->id);
916 dev_dbg(fe->dvb->device, "frequency interval: tuner: %u...%u, frontend: %u...%u",
917 tuner_min, tuner_max, frontend_min, frontend_max);
919 /* If the standard is for satellite, convert frequencies to kHz */
920 switch (c->delivery_system) {
929 *tolerance = fe->ops.info.frequency_tolerance_hz / kHz;
934 *tolerance = fe->ops.info.frequency_tolerance_hz;
939 static u32 dvb_frontend_get_stepsize(struct dvb_frontend *fe)
941 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
942 u32 fe_step = fe->ops.info.frequency_stepsize_hz;
943 u32 tuner_step = fe->ops.tuner_ops.info.frequency_step_hz;
944 u32 step = max(fe_step, tuner_step);
946 switch (c->delivery_system) {
961 static int dvb_frontend_check_parameters(struct dvb_frontend *fe)
963 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
967 /* range check: frequency */
968 dvb_frontend_get_frequency_limits(fe, &freq_min, &freq_max, NULL);
969 if ((freq_min && c->frequency < freq_min) ||
970 (freq_max && c->frequency > freq_max)) {
971 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
972 fe->dvb->num, fe->id, c->frequency,
977 /* range check: symbol rate */
978 switch (c->delivery_system) {
983 case SYS_DVBC_ANNEX_A:
984 case SYS_DVBC_ANNEX_C:
985 if ((fe->ops.info.symbol_rate_min &&
986 c->symbol_rate < fe->ops.info.symbol_rate_min) ||
987 (fe->ops.info.symbol_rate_max &&
988 c->symbol_rate > fe->ops.info.symbol_rate_max)) {
989 dev_warn(fe->dvb->device, "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
990 fe->dvb->num, fe->id, c->symbol_rate,
991 fe->ops.info.symbol_rate_min,
992 fe->ops.info.symbol_rate_max);
1003 static int dvb_frontend_clear_cache(struct dvb_frontend *fe)
1005 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1009 delsys = c->delivery_system;
1010 memset(c, 0, offsetof(struct dtv_frontend_properties, strength));
1011 c->delivery_system = delsys;
1013 dev_dbg(fe->dvb->device, "%s: Clearing cache for delivery system %d\n",
1014 __func__, c->delivery_system);
1016 c->transmission_mode = TRANSMISSION_MODE_AUTO;
1017 c->bandwidth_hz = 0; /* AUTO */
1018 c->guard_interval = GUARD_INTERVAL_AUTO;
1019 c->hierarchy = HIERARCHY_AUTO;
1021 c->code_rate_HP = FEC_AUTO;
1022 c->code_rate_LP = FEC_AUTO;
1023 c->fec_inner = FEC_AUTO;
1024 c->rolloff = ROLLOFF_AUTO;
1025 c->voltage = SEC_VOLTAGE_OFF;
1026 c->sectone = SEC_TONE_OFF;
1027 c->pilot = PILOT_AUTO;
1029 c->isdbt_partial_reception = 0;
1030 c->isdbt_sb_mode = 0;
1031 c->isdbt_sb_subchannel = 0;
1032 c->isdbt_sb_segment_idx = 0;
1033 c->isdbt_sb_segment_count = 0;
1034 c->isdbt_layer_enabled = 7; /* All layers (A,B,C) */
1035 for (i = 0; i < 3; i++) {
1036 c->layer[i].fec = FEC_AUTO;
1037 c->layer[i].modulation = QAM_AUTO;
1038 c->layer[i].interleaving = 0;
1039 c->layer[i].segment_count = 0;
1042 c->stream_id = NO_STREAM_ID_FILTER;
1043 c->scrambling_sequence_index = 0;/* default sequence */
1045 switch (c->delivery_system) {
1047 c->modulation = QPSK;
1048 c->rolloff = ROLLOFF_20;
1053 c->modulation = QPSK; /* implied for DVB-S in legacy API */
1054 c->rolloff = ROLLOFF_35;/* implied for DVB-S */
1057 c->modulation = VSB_8;
1060 c->symbol_rate = 28860000;
1061 c->rolloff = ROLLOFF_35;
1062 c->bandwidth_hz = c->symbol_rate / 100 * 135;
1065 c->modulation = QAM_AUTO;
1074 #define _DTV_CMD(n) \
1077 static char *dtv_cmds[DTV_MAX_COMMAND + 1] = {
1079 _DTV_CMD(DTV_CLEAR),
1082 _DTV_CMD(DTV_FREQUENCY),
1083 _DTV_CMD(DTV_BANDWIDTH_HZ),
1084 _DTV_CMD(DTV_MODULATION),
1085 _DTV_CMD(DTV_INVERSION),
1086 _DTV_CMD(DTV_DISEQC_MASTER),
1087 _DTV_CMD(DTV_SYMBOL_RATE),
1088 _DTV_CMD(DTV_INNER_FEC),
1089 _DTV_CMD(DTV_VOLTAGE),
1091 _DTV_CMD(DTV_PILOT),
1092 _DTV_CMD(DTV_ROLLOFF),
1093 _DTV_CMD(DTV_DELIVERY_SYSTEM),
1094 _DTV_CMD(DTV_HIERARCHY),
1095 _DTV_CMD(DTV_CODE_RATE_HP),
1096 _DTV_CMD(DTV_CODE_RATE_LP),
1097 _DTV_CMD(DTV_GUARD_INTERVAL),
1098 _DTV_CMD(DTV_TRANSMISSION_MODE),
1099 _DTV_CMD(DTV_INTERLEAVING),
1101 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION),
1102 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING),
1103 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID),
1104 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX),
1105 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT),
1106 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED),
1107 _DTV_CMD(DTV_ISDBT_LAYERA_FEC),
1108 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION),
1109 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT),
1110 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING),
1111 _DTV_CMD(DTV_ISDBT_LAYERB_FEC),
1112 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION),
1113 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT),
1114 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING),
1115 _DTV_CMD(DTV_ISDBT_LAYERC_FEC),
1116 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION),
1117 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT),
1118 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING),
1120 _DTV_CMD(DTV_STREAM_ID),
1121 _DTV_CMD(DTV_DVBT2_PLP_ID_LEGACY),
1122 _DTV_CMD(DTV_SCRAMBLING_SEQUENCE_INDEX),
1126 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY),
1127 _DTV_CMD(DTV_API_VERSION),
1129 _DTV_CMD(DTV_ENUM_DELSYS),
1131 _DTV_CMD(DTV_ATSCMH_PARADE_ID),
1132 _DTV_CMD(DTV_ATSCMH_RS_FRAME_ENSEMBLE),
1134 _DTV_CMD(DTV_ATSCMH_FIC_VER),
1135 _DTV_CMD(DTV_ATSCMH_NOG),
1136 _DTV_CMD(DTV_ATSCMH_TNOG),
1137 _DTV_CMD(DTV_ATSCMH_SGN),
1138 _DTV_CMD(DTV_ATSCMH_PRC),
1139 _DTV_CMD(DTV_ATSCMH_RS_FRAME_MODE),
1140 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_PRI),
1141 _DTV_CMD(DTV_ATSCMH_RS_CODE_MODE_SEC),
1142 _DTV_CMD(DTV_ATSCMH_SCCC_BLOCK_MODE),
1143 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_A),
1144 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_B),
1145 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_C),
1146 _DTV_CMD(DTV_ATSCMH_SCCC_CODE_MODE_D),
1148 /* Statistics API */
1149 _DTV_CMD(DTV_STAT_SIGNAL_STRENGTH),
1150 _DTV_CMD(DTV_STAT_CNR),
1151 _DTV_CMD(DTV_STAT_PRE_ERROR_BIT_COUNT),
1152 _DTV_CMD(DTV_STAT_PRE_TOTAL_BIT_COUNT),
1153 _DTV_CMD(DTV_STAT_POST_ERROR_BIT_COUNT),
1154 _DTV_CMD(DTV_STAT_POST_TOTAL_BIT_COUNT),
1155 _DTV_CMD(DTV_STAT_ERROR_BLOCK_COUNT),
1156 _DTV_CMD(DTV_STAT_TOTAL_BLOCK_COUNT),
1159 static char *dtv_cmd_name(u32 cmd)
1161 cmd = array_index_nospec(cmd, DTV_MAX_COMMAND);
1162 return dtv_cmds[cmd];
1165 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1166 * drivers can use a single set_frontend tuning function, regardless of whether
1167 * it's being used for the legacy or new API, reducing code and complexity.
1169 static int dtv_property_cache_sync(struct dvb_frontend *fe,
1170 struct dtv_frontend_properties *c,
1171 const struct dvb_frontend_parameters *p)
1173 c->frequency = p->frequency;
1174 c->inversion = p->inversion;
1176 switch (dvbv3_type(c->delivery_system)) {
1178 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1179 c->symbol_rate = p->u.qpsk.symbol_rate;
1180 c->fec_inner = p->u.qpsk.fec_inner;
1183 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1184 c->symbol_rate = p->u.qam.symbol_rate;
1185 c->fec_inner = p->u.qam.fec_inner;
1186 c->modulation = p->u.qam.modulation;
1189 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1191 switch (p->u.ofdm.bandwidth) {
1192 case BANDWIDTH_10_MHZ:
1193 c->bandwidth_hz = 10000000;
1195 case BANDWIDTH_8_MHZ:
1196 c->bandwidth_hz = 8000000;
1198 case BANDWIDTH_7_MHZ:
1199 c->bandwidth_hz = 7000000;
1201 case BANDWIDTH_6_MHZ:
1202 c->bandwidth_hz = 6000000;
1204 case BANDWIDTH_5_MHZ:
1205 c->bandwidth_hz = 5000000;
1207 case BANDWIDTH_1_712_MHZ:
1208 c->bandwidth_hz = 1712000;
1210 case BANDWIDTH_AUTO:
1211 c->bandwidth_hz = 0;
1214 c->code_rate_HP = p->u.ofdm.code_rate_HP;
1215 c->code_rate_LP = p->u.ofdm.code_rate_LP;
1216 c->modulation = p->u.ofdm.constellation;
1217 c->transmission_mode = p->u.ofdm.transmission_mode;
1218 c->guard_interval = p->u.ofdm.guard_interval;
1219 c->hierarchy = p->u.ofdm.hierarchy_information;
1222 dev_dbg(fe->dvb->device, "%s: Preparing ATSC req\n", __func__);
1223 c->modulation = p->u.vsb.modulation;
1224 if (c->delivery_system == SYS_ATSCMH)
1226 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1227 c->delivery_system = SYS_ATSC;
1229 c->delivery_system = SYS_DVBC_ANNEX_B;
1232 dev_err(fe->dvb->device,
1233 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1234 __func__, c->delivery_system);
1241 /* Ensure the cached values are set correctly in the frontend
1242 * legacy tuning structures, for the advanced tuning API.
1245 dtv_property_legacy_params_sync(struct dvb_frontend *fe,
1246 const struct dtv_frontend_properties *c,
1247 struct dvb_frontend_parameters *p)
1249 p->frequency = c->frequency;
1250 p->inversion = c->inversion;
1252 switch (dvbv3_type(c->delivery_system)) {
1254 dev_err(fe->dvb->device,
1255 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1256 __func__, c->delivery_system);
1259 dev_dbg(fe->dvb->device, "%s: Preparing QPSK req\n", __func__);
1260 p->u.qpsk.symbol_rate = c->symbol_rate;
1261 p->u.qpsk.fec_inner = c->fec_inner;
1264 dev_dbg(fe->dvb->device, "%s: Preparing QAM req\n", __func__);
1265 p->u.qam.symbol_rate = c->symbol_rate;
1266 p->u.qam.fec_inner = c->fec_inner;
1267 p->u.qam.modulation = c->modulation;
1270 dev_dbg(fe->dvb->device, "%s: Preparing OFDM req\n", __func__);
1271 switch (c->bandwidth_hz) {
1273 p->u.ofdm.bandwidth = BANDWIDTH_10_MHZ;
1276 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1279 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1282 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1285 p->u.ofdm.bandwidth = BANDWIDTH_5_MHZ;
1288 p->u.ofdm.bandwidth = BANDWIDTH_1_712_MHZ;
1292 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1294 p->u.ofdm.code_rate_HP = c->code_rate_HP;
1295 p->u.ofdm.code_rate_LP = c->code_rate_LP;
1296 p->u.ofdm.constellation = c->modulation;
1297 p->u.ofdm.transmission_mode = c->transmission_mode;
1298 p->u.ofdm.guard_interval = c->guard_interval;
1299 p->u.ofdm.hierarchy_information = c->hierarchy;
1302 dev_dbg(fe->dvb->device, "%s: Preparing VSB req\n", __func__);
1303 p->u.vsb.modulation = c->modulation;
1310 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1311 * @fe: struct dvb_frontend pointer
1312 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1313 * @p_out: struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1315 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1316 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1317 * If p_out is not null, it will update the DVBv3 params pointed by it.
1319 static int dtv_get_frontend(struct dvb_frontend *fe,
1320 struct dtv_frontend_properties *c,
1321 struct dvb_frontend_parameters *p_out)
1325 if (fe->ops.get_frontend) {
1326 r = fe->ops.get_frontend(fe, c);
1327 if (unlikely(r < 0))
1330 dtv_property_legacy_params_sync(fe, c, p_out);
1334 /* As everything is in cache, get_frontend fops are always supported */
1338 static int dvb_frontend_handle_ioctl(struct file *file,
1339 unsigned int cmd, void *parg);
1341 static int dtv_property_process_get(struct dvb_frontend *fe,
1342 const struct dtv_frontend_properties *c,
1343 struct dtv_property *tvp,
1347 unsigned int len = 1;
1350 case DTV_ENUM_DELSYS:
1352 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1353 tvp->u.buffer.data[ncaps] = fe->ops.delsys[ncaps];
1356 tvp->u.buffer.len = ncaps;
1360 tvp->u.data = c->frequency;
1362 case DTV_MODULATION:
1363 tvp->u.data = c->modulation;
1365 case DTV_BANDWIDTH_HZ:
1366 tvp->u.data = c->bandwidth_hz;
1369 tvp->u.data = c->inversion;
1371 case DTV_SYMBOL_RATE:
1372 tvp->u.data = c->symbol_rate;
1375 tvp->u.data = c->fec_inner;
1378 tvp->u.data = c->pilot;
1381 tvp->u.data = c->rolloff;
1383 case DTV_DELIVERY_SYSTEM:
1384 tvp->u.data = c->delivery_system;
1387 tvp->u.data = c->voltage;
1390 tvp->u.data = c->sectone;
1392 case DTV_API_VERSION:
1393 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1395 case DTV_CODE_RATE_HP:
1396 tvp->u.data = c->code_rate_HP;
1398 case DTV_CODE_RATE_LP:
1399 tvp->u.data = c->code_rate_LP;
1401 case DTV_GUARD_INTERVAL:
1402 tvp->u.data = c->guard_interval;
1404 case DTV_TRANSMISSION_MODE:
1405 tvp->u.data = c->transmission_mode;
1408 tvp->u.data = c->hierarchy;
1410 case DTV_INTERLEAVING:
1411 tvp->u.data = c->interleaving;
1414 /* ISDB-T Support here */
1415 case DTV_ISDBT_PARTIAL_RECEPTION:
1416 tvp->u.data = c->isdbt_partial_reception;
1418 case DTV_ISDBT_SOUND_BROADCASTING:
1419 tvp->u.data = c->isdbt_sb_mode;
1421 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1422 tvp->u.data = c->isdbt_sb_subchannel;
1424 case DTV_ISDBT_SB_SEGMENT_IDX:
1425 tvp->u.data = c->isdbt_sb_segment_idx;
1427 case DTV_ISDBT_SB_SEGMENT_COUNT:
1428 tvp->u.data = c->isdbt_sb_segment_count;
1430 case DTV_ISDBT_LAYER_ENABLED:
1431 tvp->u.data = c->isdbt_layer_enabled;
1433 case DTV_ISDBT_LAYERA_FEC:
1434 tvp->u.data = c->layer[0].fec;
1436 case DTV_ISDBT_LAYERA_MODULATION:
1437 tvp->u.data = c->layer[0].modulation;
1439 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1440 tvp->u.data = c->layer[0].segment_count;
1442 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1443 tvp->u.data = c->layer[0].interleaving;
1445 case DTV_ISDBT_LAYERB_FEC:
1446 tvp->u.data = c->layer[1].fec;
1448 case DTV_ISDBT_LAYERB_MODULATION:
1449 tvp->u.data = c->layer[1].modulation;
1451 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
1452 tvp->u.data = c->layer[1].segment_count;
1454 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
1455 tvp->u.data = c->layer[1].interleaving;
1457 case DTV_ISDBT_LAYERC_FEC:
1458 tvp->u.data = c->layer[2].fec;
1460 case DTV_ISDBT_LAYERC_MODULATION:
1461 tvp->u.data = c->layer[2].modulation;
1463 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
1464 tvp->u.data = c->layer[2].segment_count;
1466 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
1467 tvp->u.data = c->layer[2].interleaving;
1470 /* Multistream support */
1472 case DTV_DVBT2_PLP_ID_LEGACY:
1473 tvp->u.data = c->stream_id;
1476 /* Physical layer scrambling support */
1477 case DTV_SCRAMBLING_SEQUENCE_INDEX:
1478 tvp->u.data = c->scrambling_sequence_index;
1482 case DTV_ATSCMH_FIC_VER:
1483 tvp->u.data = fe->dtv_property_cache.atscmh_fic_ver;
1485 case DTV_ATSCMH_PARADE_ID:
1486 tvp->u.data = fe->dtv_property_cache.atscmh_parade_id;
1488 case DTV_ATSCMH_NOG:
1489 tvp->u.data = fe->dtv_property_cache.atscmh_nog;
1491 case DTV_ATSCMH_TNOG:
1492 tvp->u.data = fe->dtv_property_cache.atscmh_tnog;
1494 case DTV_ATSCMH_SGN:
1495 tvp->u.data = fe->dtv_property_cache.atscmh_sgn;
1497 case DTV_ATSCMH_PRC:
1498 tvp->u.data = fe->dtv_property_cache.atscmh_prc;
1500 case DTV_ATSCMH_RS_FRAME_MODE:
1501 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_mode;
1503 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
1504 tvp->u.data = fe->dtv_property_cache.atscmh_rs_frame_ensemble;
1506 case DTV_ATSCMH_RS_CODE_MODE_PRI:
1507 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_pri;
1509 case DTV_ATSCMH_RS_CODE_MODE_SEC:
1510 tvp->u.data = fe->dtv_property_cache.atscmh_rs_code_mode_sec;
1512 case DTV_ATSCMH_SCCC_BLOCK_MODE:
1513 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_block_mode;
1515 case DTV_ATSCMH_SCCC_CODE_MODE_A:
1516 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_a;
1518 case DTV_ATSCMH_SCCC_CODE_MODE_B:
1519 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_b;
1521 case DTV_ATSCMH_SCCC_CODE_MODE_C:
1522 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_c;
1524 case DTV_ATSCMH_SCCC_CODE_MODE_D:
1525 tvp->u.data = fe->dtv_property_cache.atscmh_sccc_code_mode_d;
1529 tvp->u.data = c->lna;
1532 /* Fill quality measures */
1533 case DTV_STAT_SIGNAL_STRENGTH:
1534 tvp->u.st = c->strength;
1535 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1536 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1537 len = tvp->u.buffer.len;
1541 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1542 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1543 len = tvp->u.buffer.len;
1545 case DTV_STAT_PRE_ERROR_BIT_COUNT:
1546 tvp->u.st = c->pre_bit_error;
1547 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1548 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1549 len = tvp->u.buffer.len;
1551 case DTV_STAT_PRE_TOTAL_BIT_COUNT:
1552 tvp->u.st = c->pre_bit_count;
1553 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1554 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1555 len = tvp->u.buffer.len;
1557 case DTV_STAT_POST_ERROR_BIT_COUNT:
1558 tvp->u.st = c->post_bit_error;
1559 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1560 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1561 len = tvp->u.buffer.len;
1563 case DTV_STAT_POST_TOTAL_BIT_COUNT:
1564 tvp->u.st = c->post_bit_count;
1565 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1566 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1567 len = tvp->u.buffer.len;
1569 case DTV_STAT_ERROR_BLOCK_COUNT:
1570 tvp->u.st = c->block_error;
1571 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1572 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1573 len = tvp->u.buffer.len;
1575 case DTV_STAT_TOTAL_BLOCK_COUNT:
1576 tvp->u.st = c->block_count;
1577 if (tvp->u.buffer.len > MAX_DTV_STATS * sizeof(u32))
1578 tvp->u.buffer.len = MAX_DTV_STATS * sizeof(u32);
1579 len = tvp->u.buffer.len;
1582 dev_dbg(fe->dvb->device,
1583 "%s: FE property %d doesn't exist\n",
1584 __func__, tvp->cmd);
1591 dev_dbg(fe->dvb->device,
1592 "%s: GET cmd 0x%08x (%s) len %d: %*ph\n",
1593 __func__, tvp->cmd, dtv_cmd_name(tvp->cmd),
1594 tvp->u.buffer.len, tvp->u.buffer.len, tvp->u.buffer.data);
1599 static int dtv_set_frontend(struct dvb_frontend *fe);
1601 static bool is_dvbv3_delsys(u32 delsys)
1603 return (delsys == SYS_DVBT) || (delsys == SYS_DVBC_ANNEX_A) ||
1604 (delsys == SYS_DVBS) || (delsys == SYS_ATSC);
1608 * emulate_delivery_system - emulate a DVBv5 delivery system with a DVBv3 type
1609 * @fe: struct frontend;
1610 * @delsys: DVBv5 type that will be used for emulation
1612 * Provides emulation for delivery systems that are compatible with the old
1613 * DVBv3 call. Among its usages, it provices support for ISDB-T, and allows
1614 * using a DVB-S2 only frontend just like it were a DVB-S, if the frontend
1615 * parameters are compatible with DVB-S spec.
1617 static int emulate_delivery_system(struct dvb_frontend *fe, u32 delsys)
1620 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1622 c->delivery_system = delsys;
1625 * If the call is for ISDB-T, put it into full-seg, auto mode, TV
1627 if (c->delivery_system == SYS_ISDBT) {
1628 dev_dbg(fe->dvb->device,
1629 "%s: Using defaults for SYS_ISDBT\n",
1632 if (!c->bandwidth_hz)
1633 c->bandwidth_hz = 6000000;
1635 c->isdbt_partial_reception = 0;
1636 c->isdbt_sb_mode = 0;
1637 c->isdbt_sb_subchannel = 0;
1638 c->isdbt_sb_segment_idx = 0;
1639 c->isdbt_sb_segment_count = 0;
1640 c->isdbt_layer_enabled = 7;
1641 for (i = 0; i < 3; i++) {
1642 c->layer[i].fec = FEC_AUTO;
1643 c->layer[i].modulation = QAM_AUTO;
1644 c->layer[i].interleaving = 0;
1645 c->layer[i].segment_count = 0;
1648 dev_dbg(fe->dvb->device, "%s: change delivery system on cache to %d\n",
1649 __func__, c->delivery_system);
1655 * dvbv5_set_delivery_system - Sets the delivery system for a DVBv5 API call
1656 * @fe: frontend struct
1657 * @desired_system: delivery system requested by the user
1659 * A DVBv5 call know what's the desired system it wants. So, set it.
1661 * There are, however, a few known issues with early DVBv5 applications that
1662 * are also handled by this logic:
1664 * 1) Some early apps use SYS_UNDEFINED as the desired delivery system.
1665 * This is an API violation, but, as we don't want to break userspace,
1666 * convert it to the first supported delivery system.
1667 * 2) Some apps might be using a DVBv5 call in a wrong way, passing, for
1668 * example, SYS_DVBT instead of SYS_ISDBT. This is because early usage of
1669 * ISDB-T provided backward compat with DVB-T.
1671 static int dvbv5_set_delivery_system(struct dvb_frontend *fe,
1675 u32 delsys = SYS_UNDEFINED;
1676 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1677 enum dvbv3_emulation_type type;
1680 * It was reported that some old DVBv5 applications were
1681 * filling delivery_system with SYS_UNDEFINED. If this happens,
1682 * assume that the application wants to use the first supported
1685 if (desired_system == SYS_UNDEFINED)
1686 desired_system = fe->ops.delsys[0];
1689 * This is a DVBv5 call. So, it likely knows the supported
1690 * delivery systems. So, check if the desired delivery system is
1694 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1695 if (fe->ops.delsys[ncaps] == desired_system) {
1696 c->delivery_system = desired_system;
1697 dev_dbg(fe->dvb->device,
1698 "%s: Changing delivery system to %d\n",
1699 __func__, desired_system);
1706 * The requested delivery system isn't supported. Maybe userspace
1707 * is requesting a DVBv3 compatible delivery system.
1709 * The emulation only works if the desired system is one of the
1710 * delivery systems supported by DVBv3 API
1712 if (!is_dvbv3_delsys(desired_system)) {
1713 dev_dbg(fe->dvb->device,
1714 "%s: Delivery system %d not supported.\n",
1715 __func__, desired_system);
1719 type = dvbv3_type(desired_system);
1722 * Get the last non-DVBv3 delivery system that has the same type
1723 * of the desired system
1726 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1727 if (dvbv3_type(fe->ops.delsys[ncaps]) == type)
1728 delsys = fe->ops.delsys[ncaps];
1732 /* There's nothing compatible with the desired delivery system */
1733 if (delsys == SYS_UNDEFINED) {
1734 dev_dbg(fe->dvb->device,
1735 "%s: Delivery system %d not supported on emulation mode.\n",
1736 __func__, desired_system);
1740 dev_dbg(fe->dvb->device,
1741 "%s: Using delivery system %d emulated as if it were %d\n",
1742 __func__, delsys, desired_system);
1744 return emulate_delivery_system(fe, desired_system);
1748 * dvbv3_set_delivery_system - Sets the delivery system for a DVBv3 API call
1749 * @fe: frontend struct
1751 * A DVBv3 call doesn't know what's the desired system it wants. It also
1752 * doesn't allow to switch between different types. Due to that, userspace
1753 * should use DVBv5 instead.
1754 * However, in order to avoid breaking userspace API, limited backward
1755 * compatibility support is provided.
1757 * There are some delivery systems that are incompatible with DVBv3 calls.
1759 * This routine should work fine for frontends that support just one delivery
1762 * For frontends that support multiple frontends:
1763 * 1) It defaults to use the first supported delivery system. There's an
1764 * userspace application that allows changing it at runtime;
1766 * 2) If the current delivery system is not compatible with DVBv3, it gets
1767 * the first one that it is compatible.
1769 * NOTE: in order for this to work with applications like Kaffeine that
1770 * uses a DVBv5 call for DVB-S2 and a DVBv3 call to go back to
1771 * DVB-S, drivers that support both DVB-S and DVB-S2 should have the
1772 * SYS_DVBS entry before the SYS_DVBS2, otherwise it won't switch back
1775 static int dvbv3_set_delivery_system(struct dvb_frontend *fe)
1778 u32 delsys = SYS_UNDEFINED;
1779 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1781 /* If not set yet, defaults to the first supported delivery system */
1782 if (c->delivery_system == SYS_UNDEFINED)
1783 c->delivery_system = fe->ops.delsys[0];
1786 * Trivial case: just use the current one, if it already a DVBv3
1789 if (is_dvbv3_delsys(c->delivery_system)) {
1790 dev_dbg(fe->dvb->device,
1791 "%s: Using delivery system to %d\n",
1792 __func__, c->delivery_system);
1797 * Seek for the first delivery system that it is compatible with a
1801 while (ncaps < MAX_DELSYS && fe->ops.delsys[ncaps]) {
1802 if (dvbv3_type(fe->ops.delsys[ncaps]) != DVBV3_UNKNOWN) {
1803 delsys = fe->ops.delsys[ncaps];
1808 if (delsys == SYS_UNDEFINED) {
1809 dev_dbg(fe->dvb->device,
1810 "%s: Couldn't find a delivery system that works with FE_SET_FRONTEND\n",
1814 return emulate_delivery_system(fe, delsys);
1817 static void prepare_tuning_algo_parameters(struct dvb_frontend *fe)
1819 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1820 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1821 struct dvb_frontend_tune_settings fetunesettings = { 0 };
1823 /* get frontend-specific tuning settings */
1824 if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) {
1825 fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000;
1826 fepriv->max_drift = fetunesettings.max_drift;
1827 fepriv->step_size = fetunesettings.step_size;
1829 /* default values */
1830 switch (c->delivery_system) {
1836 case SYS_DVBC_ANNEX_A:
1837 case SYS_DVBC_ANNEX_C:
1838 fepriv->min_delay = HZ / 20;
1839 fepriv->step_size = c->symbol_rate / 16000;
1840 fepriv->max_drift = c->symbol_rate / 2000;
1846 fepriv->min_delay = HZ / 20;
1847 fepriv->step_size = dvb_frontend_get_stepsize(fe) * 2;
1848 fepriv->max_drift = fepriv->step_size + 1;
1852 * FIXME: This sounds wrong! if freqency_stepsize is
1853 * defined by the frontend, why not use it???
1855 fepriv->min_delay = HZ / 20;
1856 fepriv->step_size = 0; /* no zigzag */
1857 fepriv->max_drift = 0;
1861 if (dvb_override_tune_delay > 0)
1862 fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000;
1866 * dtv_property_process_set - Sets a single DTV property
1867 * @fe: Pointer to &struct dvb_frontend
1868 * @file: Pointer to &struct file
1869 * @cmd: Digital TV command
1870 * @data: An unsigned 32-bits number
1872 * This routine assigns the property
1873 * value to the corresponding member of
1874 * &struct dtv_frontend_properties
1877 * Zero on success, negative errno on failure.
1879 static int dtv_property_process_set(struct dvb_frontend *fe,
1884 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1886 /** Dump DTV command name and value*/
1887 if (!cmd || cmd > DTV_MAX_COMMAND)
1888 dev_warn(fe->dvb->device, "%s: SET cmd 0x%08x undefined\n",
1891 dev_dbg(fe->dvb->device,
1892 "%s: SET cmd 0x%08x (%s) to 0x%08x\n",
1893 __func__, cmd, dtv_cmd_name(cmd), data);
1897 * Reset a cache of data specific to the frontend here. This does
1898 * not effect hardware.
1900 dvb_frontend_clear_cache(fe);
1904 * Use the cached Digital TV properties to tune the
1907 dev_dbg(fe->dvb->device,
1908 "%s: Setting the frontend from property cache\n",
1911 r = dtv_set_frontend(fe);
1914 c->frequency = data;
1916 case DTV_MODULATION:
1917 c->modulation = data;
1919 case DTV_BANDWIDTH_HZ:
1920 c->bandwidth_hz = data;
1923 c->inversion = data;
1925 case DTV_SYMBOL_RATE:
1926 c->symbol_rate = data;
1929 c->fec_inner = data;
1937 case DTV_DELIVERY_SYSTEM:
1938 r = dvbv5_set_delivery_system(fe, data);
1942 r = dvb_frontend_handle_ioctl(file, FE_SET_VOLTAGE,
1943 (void *)c->voltage);
1947 r = dvb_frontend_handle_ioctl(file, FE_SET_TONE,
1948 (void *)c->sectone);
1950 case DTV_CODE_RATE_HP:
1951 c->code_rate_HP = data;
1953 case DTV_CODE_RATE_LP:
1954 c->code_rate_LP = data;
1956 case DTV_GUARD_INTERVAL:
1957 c->guard_interval = data;
1959 case DTV_TRANSMISSION_MODE:
1960 c->transmission_mode = data;
1963 c->hierarchy = data;
1965 case DTV_INTERLEAVING:
1966 c->interleaving = data;
1969 /* ISDB-T Support here */
1970 case DTV_ISDBT_PARTIAL_RECEPTION:
1971 c->isdbt_partial_reception = data;
1973 case DTV_ISDBT_SOUND_BROADCASTING:
1974 c->isdbt_sb_mode = data;
1976 case DTV_ISDBT_SB_SUBCHANNEL_ID:
1977 c->isdbt_sb_subchannel = data;
1979 case DTV_ISDBT_SB_SEGMENT_IDX:
1980 c->isdbt_sb_segment_idx = data;
1982 case DTV_ISDBT_SB_SEGMENT_COUNT:
1983 c->isdbt_sb_segment_count = data;
1985 case DTV_ISDBT_LAYER_ENABLED:
1986 c->isdbt_layer_enabled = data;
1988 case DTV_ISDBT_LAYERA_FEC:
1989 c->layer[0].fec = data;
1991 case DTV_ISDBT_LAYERA_MODULATION:
1992 c->layer[0].modulation = data;
1994 case DTV_ISDBT_LAYERA_SEGMENT_COUNT:
1995 c->layer[0].segment_count = data;
1997 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING:
1998 c->layer[0].interleaving = data;
2000 case DTV_ISDBT_LAYERB_FEC:
2001 c->layer[1].fec = data;
2003 case DTV_ISDBT_LAYERB_MODULATION:
2004 c->layer[1].modulation = data;
2006 case DTV_ISDBT_LAYERB_SEGMENT_COUNT:
2007 c->layer[1].segment_count = data;
2009 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING:
2010 c->layer[1].interleaving = data;
2012 case DTV_ISDBT_LAYERC_FEC:
2013 c->layer[2].fec = data;
2015 case DTV_ISDBT_LAYERC_MODULATION:
2016 c->layer[2].modulation = data;
2018 case DTV_ISDBT_LAYERC_SEGMENT_COUNT:
2019 c->layer[2].segment_count = data;
2021 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING:
2022 c->layer[2].interleaving = data;
2025 /* Multistream support */
2027 case DTV_DVBT2_PLP_ID_LEGACY:
2028 c->stream_id = data;
2031 /* Physical layer scrambling support */
2032 case DTV_SCRAMBLING_SEQUENCE_INDEX:
2033 c->scrambling_sequence_index = data;
2037 case DTV_ATSCMH_PARADE_ID:
2038 fe->dtv_property_cache.atscmh_parade_id = data;
2040 case DTV_ATSCMH_RS_FRAME_ENSEMBLE:
2041 fe->dtv_property_cache.atscmh_rs_frame_ensemble = data;
2046 if (fe->ops.set_lna)
2047 r = fe->ops.set_lna(fe);
2059 static int dvb_frontend_do_ioctl(struct file *file, unsigned int cmd,
2062 struct dvb_device *dvbdev = file->private_data;
2063 struct dvb_frontend *fe = dvbdev->priv;
2064 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2067 dev_dbg(fe->dvb->device, "%s: (%d)\n", __func__, _IOC_NR(cmd));
2068 if (down_interruptible(&fepriv->sem))
2069 return -ERESTARTSYS;
2071 if (fe->exit != DVB_FE_NO_EXIT) {
2077 * If the frontend is opened in read-only mode, only the ioctls
2078 * that don't interfere with the tune logic should be accepted.
2079 * That allows an external application to monitor the DVB QoS and
2080 * statistics parameters.
2082 * That matches all _IOR() ioctls, except for two special cases:
2083 * - FE_GET_EVENT is part of the tuning logic on a DVB application;
2084 * - FE_DISEQC_RECV_SLAVE_REPLY is part of DiSEqC 2.0
2086 * So, those two ioctls should also return -EPERM, as otherwise
2087 * reading from them would interfere with a DVB tune application
2089 if ((file->f_flags & O_ACCMODE) == O_RDONLY
2090 && (_IOC_DIR(cmd) != _IOC_READ
2091 || cmd == FE_GET_EVENT
2092 || cmd == FE_DISEQC_RECV_SLAVE_REPLY)) {
2097 err = dvb_frontend_handle_ioctl(file, cmd, parg);
2103 static long dvb_frontend_ioctl(struct file *file, unsigned int cmd,
2106 struct dvb_device *dvbdev = file->private_data;
2111 return dvb_usercopy(file, cmd, arg, dvb_frontend_do_ioctl);
2114 #ifdef CONFIG_COMPAT
2115 struct compat_dtv_property {
2120 struct dtv_fe_stats st;
2125 compat_uptr_t reserved2;
2129 } __attribute__ ((packed));
2131 struct compat_dtv_properties {
2133 compat_uptr_t props;
2136 #define COMPAT_FE_SET_PROPERTY _IOW('o', 82, struct compat_dtv_properties)
2137 #define COMPAT_FE_GET_PROPERTY _IOR('o', 83, struct compat_dtv_properties)
2139 static int dvb_frontend_handle_compat_ioctl(struct file *file, unsigned int cmd,
2142 struct dvb_device *dvbdev = file->private_data;
2143 struct dvb_frontend *fe = dvbdev->priv;
2144 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2147 if (cmd == COMPAT_FE_SET_PROPERTY) {
2148 struct compat_dtv_properties prop, *tvps = NULL;
2149 struct compat_dtv_property *tvp = NULL;
2151 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2157 * Put an arbitrary limit on the number of messages that can
2160 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2163 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2165 return PTR_ERR(tvp);
2167 for (i = 0; i < tvps->num; i++) {
2168 err = dtv_property_process_set(fe, file,
2177 } else if (cmd == COMPAT_FE_GET_PROPERTY) {
2178 struct compat_dtv_properties prop, *tvps = NULL;
2179 struct compat_dtv_property *tvp = NULL;
2180 struct dtv_frontend_properties getp = fe->dtv_property_cache;
2182 if (copy_from_user(&prop, compat_ptr(arg), sizeof(prop)))
2188 * Put an arbitrary limit on the number of messages that can
2191 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2194 tvp = memdup_user(compat_ptr(tvps->props), tvps->num * sizeof(*tvp));
2196 return PTR_ERR(tvp);
2199 * Let's use our own copy of property cache, in order to
2200 * avoid mangling with DTV zigzag logic, as drivers might
2201 * return crap, if they don't check if the data is available
2202 * before updating the properties cache.
2204 if (fepriv->state != FESTATE_IDLE) {
2205 err = dtv_get_frontend(fe, &getp, NULL);
2211 for (i = 0; i < tvps->num; i++) {
2212 err = dtv_property_process_get(
2213 fe, &getp, (struct dtv_property *)(tvp + i), file);
2220 if (copy_to_user((void __user *)compat_ptr(tvps->props), tvp,
2221 tvps->num * sizeof(struct compat_dtv_property))) {
2231 static long dvb_frontend_compat_ioctl(struct file *file, unsigned int cmd,
2234 struct dvb_device *dvbdev = file->private_data;
2235 struct dvb_frontend *fe = dvbdev->priv;
2236 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2239 if (cmd == COMPAT_FE_SET_PROPERTY || cmd == COMPAT_FE_GET_PROPERTY) {
2240 if (down_interruptible(&fepriv->sem))
2241 return -ERESTARTSYS;
2243 err = dvb_frontend_handle_compat_ioctl(file, cmd, arg);
2249 return dvb_frontend_ioctl(file, cmd, (unsigned long)compat_ptr(arg));
2253 static int dtv_set_frontend(struct dvb_frontend *fe)
2255 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2256 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2259 if (dvb_frontend_check_parameters(fe) < 0)
2263 * Initialize output parameters to match the values given by
2264 * the user. FE_SET_FRONTEND triggers an initial frontend event
2265 * with status = 0, which copies output parameters to userspace.
2267 dtv_property_legacy_params_sync(fe, c, &fepriv->parameters_out);
2270 * Be sure that the bandwidth will be filled for all
2271 * non-satellite systems, as tuners need to know what
2272 * low pass/Nyquist half filter should be applied, in
2273 * order to avoid inter-channel noise.
2275 * ISDB-T and DVB-T/T2 already sets bandwidth.
2276 * ATSC and DVB-C don't set, so, the core should fill it.
2278 * On DVB-C Annex A and C, the bandwidth is a function of
2279 * the roll-off and symbol rate. Annex B defines different
2280 * roll-off factors depending on the modulation. Fortunately,
2281 * Annex B is only used with 6MHz, so there's no need to
2284 * While not officially supported, a side effect of handling it at
2285 * the cache level is that a program could retrieve the bandwidth
2286 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
2288 switch (c->delivery_system) {
2290 case SYS_DVBC_ANNEX_B:
2291 c->bandwidth_hz = 6000000;
2293 case SYS_DVBC_ANNEX_A:
2296 case SYS_DVBC_ANNEX_C:
2308 switch (c->rolloff) {
2324 c->bandwidth_hz = mult_frac(c->symbol_rate, rolloff, 100);
2326 /* force auto frequency inversion if requested */
2327 if (dvb_force_auto_inversion)
2328 c->inversion = INVERSION_AUTO;
2331 * without hierarchical coding code_rate_LP is irrelevant,
2332 * so we tolerate the otherwise invalid FEC_NONE setting
2334 if (c->hierarchy == HIERARCHY_NONE && c->code_rate_LP == FEC_NONE)
2335 c->code_rate_LP = FEC_AUTO;
2337 prepare_tuning_algo_parameters(fe);
2339 fepriv->state = FESTATE_RETUNE;
2341 /* Request the search algorithm to search */
2342 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
2344 dvb_frontend_clear_events(fe);
2345 dvb_frontend_add_event(fe, 0);
2346 dvb_frontend_wakeup(fe);
2352 static int dvb_get_property(struct dvb_frontend *fe, struct file *file,
2353 struct dtv_properties *tvps)
2355 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2356 struct dtv_property *tvp = NULL;
2357 struct dtv_frontend_properties getp;
2360 memcpy(&getp, &fe->dtv_property_cache, sizeof(getp));
2362 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2363 __func__, tvps->num);
2364 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2365 __func__, tvps->props);
2368 * Put an arbitrary limit on the number of messages that can
2371 if (!tvps->num || tvps->num > DTV_IOCTL_MAX_MSGS)
2374 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2376 return PTR_ERR(tvp);
2379 * Let's use our own copy of property cache, in order to
2380 * avoid mangling with DTV zigzag logic, as drivers might
2381 * return crap, if they don't check if the data is available
2382 * before updating the properties cache.
2384 if (fepriv->state != FESTATE_IDLE) {
2385 err = dtv_get_frontend(fe, &getp, NULL);
2389 for (i = 0; i < tvps->num; i++) {
2390 err = dtv_property_process_get(fe, &getp,
2396 if (copy_to_user((void __user *)tvps->props, tvp,
2397 tvps->num * sizeof(struct dtv_property))) {
2408 static int dvb_get_frontend(struct dvb_frontend *fe,
2409 struct dvb_frontend_parameters *p_out)
2411 struct dtv_frontend_properties getp;
2414 * Let's use our own copy of property cache, in order to
2415 * avoid mangling with DTV zigzag logic, as drivers might
2416 * return crap, if they don't check if the data is available
2417 * before updating the properties cache.
2419 memcpy(&getp, &fe->dtv_property_cache, sizeof(getp));
2421 return dtv_get_frontend(fe, &getp, p_out);
2424 static int dvb_frontend_handle_ioctl(struct file *file,
2425 unsigned int cmd, void *parg)
2427 struct dvb_device *dvbdev = file->private_data;
2428 struct dvb_frontend *fe = dvbdev->priv;
2429 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2430 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
2431 int i, err = -ENOTSUPP;
2433 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2436 case FE_SET_PROPERTY: {
2437 struct dtv_properties *tvps = parg;
2438 struct dtv_property *tvp = NULL;
2440 dev_dbg(fe->dvb->device, "%s: properties.num = %d\n",
2441 __func__, tvps->num);
2442 dev_dbg(fe->dvb->device, "%s: properties.props = %p\n",
2443 __func__, tvps->props);
2446 * Put an arbitrary limit on the number of messages that can
2449 if (!tvps->num || (tvps->num > DTV_IOCTL_MAX_MSGS))
2452 tvp = memdup_user((void __user *)tvps->props, tvps->num * sizeof(*tvp));
2454 return PTR_ERR(tvp);
2456 for (i = 0; i < tvps->num; i++) {
2457 err = dtv_property_process_set(fe, file,
2469 case FE_GET_PROPERTY:
2470 err = dvb_get_property(fe, file, parg);
2474 struct dvb_frontend_info *info = parg;
2475 memset(info, 0, sizeof(*info));
2477 strscpy(info->name, fe->ops.info.name, sizeof(info->name));
2478 info->symbol_rate_min = fe->ops.info.symbol_rate_min;
2479 info->symbol_rate_max = fe->ops.info.symbol_rate_max;
2480 info->symbol_rate_tolerance = fe->ops.info.symbol_rate_tolerance;
2481 info->caps = fe->ops.info.caps;
2482 info->frequency_stepsize = dvb_frontend_get_stepsize(fe);
2483 dvb_frontend_get_frequency_limits(fe, &info->frequency_min,
2484 &info->frequency_max,
2485 &info->frequency_tolerance);
2488 * Associate the 4 delivery systems supported by DVBv3
2489 * API with their DVBv5 counterpart. For the other standards,
2490 * use the closest type, assuming that it would hopefully
2491 * work with a DVBv3 application.
2492 * It should be noticed that, on multi-frontend devices with
2493 * different types (terrestrial and cable, for example),
2494 * a pure DVBv3 application won't be able to use all delivery
2495 * systems. Yet, changing the DVBv5 cache to the other delivery
2496 * system should be enough for making it work.
2498 switch (dvbv3_type(c->delivery_system)) {
2500 info->type = FE_QPSK;
2503 info->type = FE_ATSC;
2506 info->type = FE_QAM;
2509 info->type = FE_OFDM;
2512 dev_err(fe->dvb->device,
2513 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
2514 __func__, c->delivery_system);
2515 info->type = FE_OFDM;
2517 dev_dbg(fe->dvb->device, "%s: current delivery system on cache: %d, V3 type: %d\n",
2518 __func__, c->delivery_system, info->type);
2520 /* Set CAN_INVERSION_AUTO bit on in other than oneshot mode */
2521 if (!(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT))
2522 info->caps |= FE_CAN_INVERSION_AUTO;
2527 case FE_READ_STATUS: {
2528 enum fe_status *status = parg;
2530 /* if retune was requested but hasn't occurred yet, prevent
2531 * that user get signal state from previous tuning */
2532 if (fepriv->state == FESTATE_RETUNE ||
2533 fepriv->state == FESTATE_ERROR) {
2539 if (fe->ops.read_status)
2540 err = fe->ops.read_status(fe, status);
2544 case FE_DISEQC_RESET_OVERLOAD:
2545 if (fe->ops.diseqc_reset_overload) {
2546 err = fe->ops.diseqc_reset_overload(fe);
2547 fepriv->state = FESTATE_DISEQC;
2552 case FE_DISEQC_SEND_MASTER_CMD:
2553 if (fe->ops.diseqc_send_master_cmd) {
2554 struct dvb_diseqc_master_cmd *cmd = parg;
2556 if (cmd->msg_len > sizeof(cmd->msg)) {
2560 err = fe->ops.diseqc_send_master_cmd(fe, cmd);
2561 fepriv->state = FESTATE_DISEQC;
2566 case FE_DISEQC_SEND_BURST:
2567 if (fe->ops.diseqc_send_burst) {
2568 err = fe->ops.diseqc_send_burst(fe, (long)parg);
2569 fepriv->state = FESTATE_DISEQC;
2575 if (fe->ops.set_tone) {
2576 fepriv->tone = (long)parg;
2577 err = fe->ops.set_tone(fe, fepriv->tone);
2578 fepriv->state = FESTATE_DISEQC;
2583 case FE_SET_VOLTAGE:
2584 if (fe->ops.set_voltage) {
2585 fepriv->voltage = (long)parg;
2586 err = fe->ops.set_voltage(fe, fepriv->voltage);
2587 fepriv->state = FESTATE_DISEQC;
2592 case FE_DISEQC_RECV_SLAVE_REPLY:
2593 if (fe->ops.diseqc_recv_slave_reply)
2594 err = fe->ops.diseqc_recv_slave_reply(fe, parg);
2597 case FE_ENABLE_HIGH_LNB_VOLTAGE:
2598 if (fe->ops.enable_high_lnb_voltage)
2599 err = fe->ops.enable_high_lnb_voltage(fe, (long)parg);
2602 case FE_SET_FRONTEND_TUNE_MODE:
2603 fepriv->tune_mode_flags = (unsigned long)parg;
2606 /* DEPRECATED dish control ioctls */
2608 case FE_DISHNETWORK_SEND_LEGACY_CMD:
2609 if (fe->ops.dishnetwork_send_legacy_command) {
2610 err = fe->ops.dishnetwork_send_legacy_command(fe,
2611 (unsigned long)parg);
2612 fepriv->state = FESTATE_DISEQC;
2614 } else if (fe->ops.set_voltage) {
2616 * NOTE: This is a fallback condition. Some frontends
2617 * (stv0299 for instance) take longer than 8msec to
2618 * respond to a set_voltage command. Those switches
2619 * need custom routines to switch properly. For all
2620 * other frontends, the following should work ok.
2621 * Dish network legacy switches (as used by Dish500)
2622 * are controlled by sending 9-bit command words
2623 * spaced 8msec apart.
2624 * the actual command word is switch/port dependent
2625 * so it is up to the userspace application to send
2626 * the right command.
2627 * The command must always start with a '0' after
2628 * initialization, so parg is 8 bits and does not
2629 * include the initialization or start bit
2631 unsigned long swcmd = ((unsigned long)parg) << 1;
2637 if (dvb_frontend_debug)
2638 dprintk("switch command: 0x%04lx\n",
2640 nexttime = ktime_get_boottime();
2641 if (dvb_frontend_debug)
2643 /* before sending a command, initialize by sending
2644 * a 32ms 18V to the switch
2646 fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
2647 dvb_frontend_sleep_until(&nexttime, 32000);
2649 for (i = 0; i < 9; i++) {
2650 if (dvb_frontend_debug)
2651 tv[i + 1] = ktime_get_boottime();
2652 if ((swcmd & 0x01) != last) {
2653 /* set voltage to (last ? 13V : 18V) */
2654 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
2655 last = (last) ? 0 : 1;
2659 dvb_frontend_sleep_until(&nexttime, 8000);
2661 if (dvb_frontend_debug) {
2662 dprintk("(adapter %d): switch delay (should be 32k followed by all 8k)\n",
2664 for (i = 1; i < 10; i++)
2665 pr_info("%d: %d\n", i,
2666 (int)ktime_us_delta(tv[i], tv[i - 1]));
2669 fepriv->state = FESTATE_DISEQC;
2674 /* DEPRECATED statistics ioctls */
2677 if (fe->ops.read_ber) {
2679 err = fe->ops.read_ber(fe, parg);
2685 case FE_READ_SIGNAL_STRENGTH:
2686 if (fe->ops.read_signal_strength) {
2688 err = fe->ops.read_signal_strength(fe, parg);
2695 if (fe->ops.read_snr) {
2697 err = fe->ops.read_snr(fe, parg);
2703 case FE_READ_UNCORRECTED_BLOCKS:
2704 if (fe->ops.read_ucblocks) {
2706 err = fe->ops.read_ucblocks(fe, parg);
2712 /* DEPRECATED DVBv3 ioctls */
2714 case FE_SET_FRONTEND:
2715 err = dvbv3_set_delivery_system(fe);
2719 err = dtv_property_cache_sync(fe, c, parg);
2722 err = dtv_set_frontend(fe);
2726 err = dvb_frontend_get_event(fe, parg, file->f_flags);
2729 case FE_GET_FRONTEND:
2730 err = dvb_get_frontend(fe, parg);
2740 static __poll_t dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
2742 struct dvb_device *dvbdev = file->private_data;
2743 struct dvb_frontend *fe = dvbdev->priv;
2744 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2746 dev_dbg_ratelimited(fe->dvb->device, "%s:\n", __func__);
2748 poll_wait(file, &fepriv->events.wait_queue, wait);
2750 if (fepriv->events.eventw != fepriv->events.eventr)
2751 return (EPOLLIN | EPOLLRDNORM | EPOLLPRI);
2756 static int dvb_frontend_open(struct inode *inode, struct file *file)
2758 struct dvb_device *dvbdev = file->private_data;
2759 struct dvb_frontend *fe = dvbdev->priv;
2760 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2761 struct dvb_adapter *adapter = fe->dvb;
2764 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2765 if (fe->exit == DVB_FE_DEVICE_REMOVED)
2768 if (adapter->mfe_shared == 2) {
2769 mutex_lock(&adapter->mfe_lock);
2770 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2771 if (adapter->mfe_dvbdev &&
2772 !adapter->mfe_dvbdev->writers) {
2773 mutex_unlock(&adapter->mfe_lock);
2776 adapter->mfe_dvbdev = dvbdev;
2778 } else if (adapter->mfe_shared) {
2779 mutex_lock(&adapter->mfe_lock);
2781 if (!adapter->mfe_dvbdev)
2782 adapter->mfe_dvbdev = dvbdev;
2784 else if (adapter->mfe_dvbdev != dvbdev) {
2786 *mfedev = adapter->mfe_dvbdev;
2788 *mfe = mfedev->priv;
2789 struct dvb_frontend_private
2790 *mfepriv = mfe->frontend_priv;
2791 int mferetry = (dvb_mfe_wait_time << 1);
2793 mutex_unlock(&adapter->mfe_lock);
2794 while (mferetry-- && (mfedev->users != -1 ||
2796 if (msleep_interruptible(500)) {
2797 if (signal_pending(current))
2802 mutex_lock(&adapter->mfe_lock);
2803 if (adapter->mfe_dvbdev != dvbdev) {
2804 mfedev = adapter->mfe_dvbdev;
2806 mfepriv = mfe->frontend_priv;
2807 if (mfedev->users != -1 ||
2809 mutex_unlock(&adapter->mfe_lock);
2812 adapter->mfe_dvbdev = dvbdev;
2817 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
2818 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
2821 /* If we took control of the bus, we need to force
2822 reinitialization. This is because many ts_bus_ctrl()
2823 functions strobe the RESET pin on the demod, and if the
2824 frontend thread already exists then the dvb_init() routine
2825 won't get called (which is what usually does initial
2826 register configuration). */
2827 fepriv->reinitialise = 1;
2830 if ((ret = dvb_generic_open(inode, file)) < 0)
2833 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2834 /* normal tune mode when opened R/W */
2835 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
2837 fepriv->voltage = -1;
2839 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2840 mutex_lock(&fe->dvb->mdev_lock);
2841 if (fe->dvb->mdev) {
2842 mutex_lock(&fe->dvb->mdev->graph_mutex);
2843 if (fe->dvb->mdev->enable_source)
2844 ret = fe->dvb->mdev->enable_source(
2847 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2849 mutex_unlock(&fe->dvb->mdev_lock);
2850 dev_err(fe->dvb->device,
2851 "Tuner is busy. Error %d\n", ret);
2855 mutex_unlock(&fe->dvb->mdev_lock);
2857 ret = dvb_frontend_start(fe);
2861 /* empty event queue */
2862 fepriv->events.eventr = fepriv->events.eventw = 0;
2865 dvb_frontend_get(fe);
2867 if (adapter->mfe_shared)
2868 mutex_unlock(&adapter->mfe_lock);
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);
2883 dvb_generic_release(inode, file);
2885 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
2886 fe->ops.ts_bus_ctrl(fe, 0);
2888 if (adapter->mfe_shared)
2889 mutex_unlock(&adapter->mfe_lock);
2893 static int dvb_frontend_release(struct inode *inode, struct file *file)
2895 struct dvb_device *dvbdev = file->private_data;
2896 struct dvb_frontend *fe = dvbdev->priv;
2897 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2900 dev_dbg(fe->dvb->device, "%s:\n", __func__);
2902 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
2903 fepriv->release_jiffies = jiffies;
2907 ret = dvb_generic_release(inode, file);
2909 if (dvbdev->users == -1) {
2910 wake_up(&fepriv->wait_queue);
2911 #ifdef CONFIG_MEDIA_CONTROLLER_DVB
2912 mutex_lock(&fe->dvb->mdev_lock);
2913 if (fe->dvb->mdev) {
2914 mutex_lock(&fe->dvb->mdev->graph_mutex);
2915 if (fe->dvb->mdev->disable_source)
2916 fe->dvb->mdev->disable_source(dvbdev->entity);
2917 mutex_unlock(&fe->dvb->mdev->graph_mutex);
2919 mutex_unlock(&fe->dvb->mdev_lock);
2921 if (fe->exit != DVB_FE_NO_EXIT)
2922 wake_up(&dvbdev->wait_queue);
2923 if (fe->ops.ts_bus_ctrl)
2924 fe->ops.ts_bus_ctrl(fe, 0);
2927 dvb_frontend_put(fe);
2932 static const struct file_operations dvb_frontend_fops = {
2933 .owner = THIS_MODULE,
2934 .unlocked_ioctl = dvb_frontend_ioctl,
2935 #ifdef CONFIG_COMPAT
2936 .compat_ioctl = dvb_frontend_compat_ioctl,
2938 .poll = dvb_frontend_poll,
2939 .open = dvb_frontend_open,
2940 .release = dvb_frontend_release,
2941 .llseek = noop_llseek,
2944 int dvb_frontend_suspend(struct dvb_frontend *fe)
2948 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2951 if (fe->ops.tuner_ops.suspend)
2952 ret = fe->ops.tuner_ops.suspend(fe);
2953 else if (fe->ops.tuner_ops.sleep)
2954 ret = fe->ops.tuner_ops.sleep(fe);
2956 if (fe->ops.suspend)
2957 ret = fe->ops.suspend(fe);
2958 else if (fe->ops.sleep)
2959 ret = fe->ops.sleep(fe);
2963 EXPORT_SYMBOL(dvb_frontend_suspend);
2965 int dvb_frontend_resume(struct dvb_frontend *fe)
2967 struct dvb_frontend_private *fepriv = fe->frontend_priv;
2970 dev_dbg(fe->dvb->device, "%s: adap=%d fe=%d\n", __func__, fe->dvb->num,
2973 fe->exit = DVB_FE_DEVICE_RESUME;
2975 ret = fe->ops.resume(fe);
2976 else if (fe->ops.init)
2977 ret = fe->ops.init(fe);
2979 if (fe->ops.tuner_ops.resume)
2980 ret = fe->ops.tuner_ops.resume(fe);
2981 else if (fe->ops.tuner_ops.init)
2982 ret = fe->ops.tuner_ops.init(fe);
2984 if (fe->ops.set_tone && fepriv->tone != -1)
2985 fe->ops.set_tone(fe, fepriv->tone);
2986 if (fe->ops.set_voltage && fepriv->voltage != -1)
2987 fe->ops.set_voltage(fe, fepriv->voltage);
2989 fe->exit = DVB_FE_NO_EXIT;
2990 fepriv->state = FESTATE_RETUNE;
2991 dvb_frontend_wakeup(fe);
2995 EXPORT_SYMBOL(dvb_frontend_resume);
2997 int dvb_register_frontend(struct dvb_adapter *dvb,
2998 struct dvb_frontend *fe)
3000 struct dvb_frontend_private *fepriv;
3001 const struct dvb_device dvbdev_template = {
3004 .readers = (~0) - 1,
3005 .fops = &dvb_frontend_fops,
3006 #if defined(CONFIG_MEDIA_CONTROLLER_DVB)
3007 .name = fe->ops.info.name,
3011 dev_dbg(dvb->device, "%s:\n", __func__);
3013 if (mutex_lock_interruptible(&frontend_mutex))
3014 return -ERESTARTSYS;
3016 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
3017 if (!fe->frontend_priv) {
3018 mutex_unlock(&frontend_mutex);
3021 fepriv = fe->frontend_priv;
3023 kref_init(&fe->refcount);
3026 * After initialization, there need to be two references: one
3027 * for dvb_unregister_frontend(), and another one for
3028 * dvb_frontend_detach().
3030 dvb_frontend_get(fe);
3032 sema_init(&fepriv->sem, 1);
3033 init_waitqueue_head(&fepriv->wait_queue);
3034 init_waitqueue_head(&fepriv->events.wait_queue);
3035 mutex_init(&fepriv->events.mtx);
3037 fepriv->inversion = INVERSION_OFF;
3039 dev_info(fe->dvb->device,
3040 "DVB: registering adapter %i frontend %i (%s)...\n",
3041 fe->dvb->num, fe->id, fe->ops.info.name);
3043 dvb_register_device(fe->dvb, &fepriv->dvbdev, &dvbdev_template,
3044 fe, DVB_DEVICE_FRONTEND, 0);
3047 * Initialize the cache to the proper values according with the
3048 * first supported delivery system (ops->delsys[0])
3051 fe->dtv_property_cache.delivery_system = fe->ops.delsys[0];
3052 dvb_frontend_clear_cache(fe);
3054 mutex_unlock(&frontend_mutex);
3057 EXPORT_SYMBOL(dvb_register_frontend);
3059 int dvb_unregister_frontend(struct dvb_frontend *fe)
3061 struct dvb_frontend_private *fepriv = fe->frontend_priv;
3063 dev_dbg(fe->dvb->device, "%s:\n", __func__);
3065 mutex_lock(&frontend_mutex);
3066 dvb_frontend_stop(fe);
3067 dvb_remove_device(fepriv->dvbdev);
3069 /* fe is invalid now */
3070 mutex_unlock(&frontend_mutex);
3071 dvb_frontend_put(fe);
3074 EXPORT_SYMBOL(dvb_unregister_frontend);
3076 static void dvb_frontend_invoke_release(struct dvb_frontend *fe,
3077 void (*release)(struct dvb_frontend *fe))
3081 #ifdef CONFIG_MEDIA_ATTACH
3082 dvb_detach(release);
3087 void dvb_frontend_detach(struct dvb_frontend *fe)
3089 dvb_frontend_invoke_release(fe, fe->ops.release_sec);
3090 dvb_frontend_invoke_release(fe, fe->ops.tuner_ops.release);
3091 dvb_frontend_invoke_release(fe, fe->ops.analog_ops.release);
3092 dvb_frontend_put(fe);
3094 EXPORT_SYMBOL(dvb_frontend_detach);