added 2.6.29.6 aldebaran kernel
[nao-ulib.git] / kernel / 2.6.29.6-aldebaran-rt / drivers / media / dvb / dvb-core / dvb_frontend.c
blob73bf64f414e9d83b9c4567dfa026937ce54724d7
1 /*
2 * dvb_frontend.c: DVB frontend tuning interface/thread
5 * Copyright (C) 1999-2001 Ralph Metzler
6 * Marcus Metzler
7 * Holger Waechtler
8 * for convergence integrated media GmbH
10 * Copyright (C) 2004 Andrew de Quincey (tuning thread cleanup)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
28 #include <linux/string.h>
29 #include <linux/kernel.h>
30 #include <linux/sched.h>
31 #include <linux/wait.h>
32 #include <linux/slab.h>
33 #include <linux/poll.h>
34 #include <linux/module.h>
35 #include <linux/list.h>
36 #include <linux/freezer.h>
37 #include <linux/jiffies.h>
38 #include <linux/kthread.h>
39 #include <asm/processor.h>
41 #include "dvb_frontend.h"
42 #include "dvbdev.h"
43 #include <linux/dvb/version.h>
45 static int dvb_frontend_debug;
46 static int dvb_shutdown_timeout;
47 static int dvb_force_auto_inversion;
48 static int dvb_override_tune_delay;
49 static int dvb_powerdown_on_sleep = 1;
50 static int dvb_mfe_wait_time = 5;
52 module_param_named(frontend_debug, dvb_frontend_debug, int, 0644);
53 MODULE_PARM_DESC(frontend_debug, "Turn on/off frontend core debugging (default:off).");
54 module_param(dvb_shutdown_timeout, int, 0644);
55 MODULE_PARM_DESC(dvb_shutdown_timeout, "wait <shutdown_timeout> seconds after close() before suspending hardware");
56 module_param(dvb_force_auto_inversion, int, 0644);
57 MODULE_PARM_DESC(dvb_force_auto_inversion, "0: normal (default), 1: INVERSION_AUTO forced always");
58 module_param(dvb_override_tune_delay, int, 0644);
59 MODULE_PARM_DESC(dvb_override_tune_delay, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
60 module_param(dvb_powerdown_on_sleep, int, 0644);
61 MODULE_PARM_DESC(dvb_powerdown_on_sleep, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
62 module_param(dvb_mfe_wait_time, int, 0644);
63 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)");
65 #define dprintk if (dvb_frontend_debug) printk
67 #define FESTATE_IDLE 1
68 #define FESTATE_RETUNE 2
69 #define FESTATE_TUNING_FAST 4
70 #define FESTATE_TUNING_SLOW 8
71 #define FESTATE_TUNED 16
72 #define FESTATE_ZIGZAG_FAST 32
73 #define FESTATE_ZIGZAG_SLOW 64
74 #define FESTATE_DISEQC 128
75 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
76 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
77 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
78 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
80 #define FE_ALGO_HW 1
82 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
83 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
84 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
85 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
86 * FESTATE_TUNED. The frontend has successfully locked on.
87 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
88 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
89 * FESTATE_DISEQC. A DISEQC command has just been issued.
90 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
91 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
92 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
93 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
96 static DEFINE_MUTEX(frontend_mutex);
98 struct dvb_frontend_private {
100 /* thread/frontend values */
101 struct dvb_device *dvbdev;
102 struct dvb_frontend_parameters parameters;
103 struct dvb_fe_events events;
104 struct compat_semaphore sem;
105 struct list_head list_head;
106 wait_queue_head_t wait_queue;
107 struct task_struct *thread;
108 unsigned long release_jiffies;
109 unsigned int exit;
110 unsigned int wakeup;
111 fe_status_t status;
112 unsigned long tune_mode_flags;
113 unsigned int delay;
114 unsigned int reinitialise;
115 int tone;
116 int voltage;
118 /* swzigzag values */
119 unsigned int state;
120 unsigned int bending;
121 int lnb_drift;
122 unsigned int inversion;
123 unsigned int auto_step;
124 unsigned int auto_sub_step;
125 unsigned int started_auto_step;
126 unsigned int min_delay;
127 unsigned int max_drift;
128 unsigned int step_size;
129 int quality;
130 unsigned int check_wrapped;
131 enum dvbfe_search algo_status;
134 static void dvb_frontend_wakeup(struct dvb_frontend *fe);
136 static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
138 struct dvb_frontend_private *fepriv = fe->frontend_priv;
139 struct dvb_fe_events *events = &fepriv->events;
140 struct dvb_frontend_event *e;
141 int wp;
143 dprintk ("%s\n", __func__);
145 if (mutex_lock_interruptible (&events->mtx))
146 return;
148 wp = (events->eventw + 1) % MAX_EVENT;
150 if (wp == events->eventr) {
151 events->overflow = 1;
152 events->eventr = (events->eventr + 1) % MAX_EVENT;
155 e = &events->events[events->eventw];
157 memcpy (&e->parameters, &fepriv->parameters,
158 sizeof (struct dvb_frontend_parameters));
160 if (status & FE_HAS_LOCK)
161 if (fe->ops.get_frontend)
162 fe->ops.get_frontend(fe, &e->parameters);
164 events->eventw = wp;
166 mutex_unlock(&events->mtx);
168 e->status = status;
170 wake_up_interruptible (&events->wait_queue);
173 static int dvb_frontend_get_event(struct dvb_frontend *fe,
174 struct dvb_frontend_event *event, int flags)
176 struct dvb_frontend_private *fepriv = fe->frontend_priv;
177 struct dvb_fe_events *events = &fepriv->events;
179 dprintk ("%s\n", __func__);
181 if (events->overflow) {
182 events->overflow = 0;
183 return -EOVERFLOW;
186 if (events->eventw == events->eventr) {
187 int ret;
189 if (flags & O_NONBLOCK)
190 return -EWOULDBLOCK;
192 up(&fepriv->sem);
194 ret = wait_event_interruptible (events->wait_queue,
195 events->eventw != events->eventr);
197 if (down_interruptible (&fepriv->sem))
198 return -ERESTARTSYS;
200 if (ret < 0)
201 return ret;
204 if (mutex_lock_interruptible (&events->mtx))
205 return -ERESTARTSYS;
207 memcpy (event, &events->events[events->eventr],
208 sizeof(struct dvb_frontend_event));
210 events->eventr = (events->eventr + 1) % MAX_EVENT;
212 mutex_unlock(&events->mtx);
214 return 0;
217 static void dvb_frontend_init(struct dvb_frontend *fe)
219 dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n",
220 fe->dvb->num,
221 fe->id,
222 fe->ops.info.name);
224 if (fe->ops.init)
225 fe->ops.init(fe);
226 if (fe->ops.tuner_ops.init) {
227 if (fe->ops.i2c_gate_ctrl)
228 fe->ops.i2c_gate_ctrl(fe, 1);
229 fe->ops.tuner_ops.init(fe);
230 if (fe->ops.i2c_gate_ctrl)
231 fe->ops.i2c_gate_ctrl(fe, 0);
235 void dvb_frontend_reinitialise(struct dvb_frontend *fe)
237 struct dvb_frontend_private *fepriv = fe->frontend_priv;
239 fepriv->reinitialise = 1;
240 dvb_frontend_wakeup(fe);
242 EXPORT_SYMBOL(dvb_frontend_reinitialise);
244 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepriv, int locked)
246 int q2;
248 dprintk ("%s\n", __func__);
250 if (locked)
251 (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256;
252 else
253 (fepriv->quality) = (fepriv->quality * 220 + 0) / 256;
255 q2 = fepriv->quality - 128;
256 q2 *= q2;
258 fepriv->delay = fepriv->min_delay + q2 * HZ / (128*128);
262 * Performs automatic twiddling of frontend parameters.
264 * @param fe The frontend concerned.
265 * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
266 * @returns Number of complete iterations that have been performed.
268 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wrapped)
270 int autoinversion;
271 int ready = 0;
272 struct dvb_frontend_private *fepriv = fe->frontend_priv;
273 int original_inversion = fepriv->parameters.inversion;
274 u32 original_frequency = fepriv->parameters.frequency;
276 /* are we using autoinversion? */
277 autoinversion = ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
278 (fepriv->parameters.inversion == INVERSION_AUTO));
280 /* setup parameters correctly */
281 while(!ready) {
282 /* calculate the lnb_drift */
283 fepriv->lnb_drift = fepriv->auto_step * fepriv->step_size;
285 /* wrap the auto_step if we've exceeded the maximum drift */
286 if (fepriv->lnb_drift > fepriv->max_drift) {
287 fepriv->auto_step = 0;
288 fepriv->auto_sub_step = 0;
289 fepriv->lnb_drift = 0;
292 /* perform inversion and +/- zigzag */
293 switch(fepriv->auto_sub_step) {
294 case 0:
295 /* try with the current inversion and current drift setting */
296 ready = 1;
297 break;
299 case 1:
300 if (!autoinversion) break;
302 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
303 ready = 1;
304 break;
306 case 2:
307 if (fepriv->lnb_drift == 0) break;
309 fepriv->lnb_drift = -fepriv->lnb_drift;
310 ready = 1;
311 break;
313 case 3:
314 if (fepriv->lnb_drift == 0) break;
315 if (!autoinversion) break;
317 fepriv->inversion = (fepriv->inversion == INVERSION_OFF) ? INVERSION_ON : INVERSION_OFF;
318 fepriv->lnb_drift = -fepriv->lnb_drift;
319 ready = 1;
320 break;
322 default:
323 fepriv->auto_step++;
324 fepriv->auto_sub_step = -1; /* it'll be incremented to 0 in a moment */
325 break;
328 if (!ready) fepriv->auto_sub_step++;
331 /* if this attempt would hit where we started, indicate a complete
332 * iteration has occurred */
333 if ((fepriv->auto_step == fepriv->started_auto_step) &&
334 (fepriv->auto_sub_step == 0) && check_wrapped) {
335 return 1;
338 dprintk("%s: drift:%i inversion:%i auto_step:%i "
339 "auto_sub_step:%i started_auto_step:%i\n",
340 __func__, fepriv->lnb_drift, fepriv->inversion,
341 fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step);
343 /* set the frontend itself */
344 fepriv->parameters.frequency += fepriv->lnb_drift;
345 if (autoinversion)
346 fepriv->parameters.inversion = fepriv->inversion;
347 if (fe->ops.set_frontend)
348 fe->ops.set_frontend(fe, &fepriv->parameters);
350 fepriv->parameters.frequency = original_frequency;
351 fepriv->parameters.inversion = original_inversion;
353 fepriv->auto_sub_step++;
354 return 0;
357 static void dvb_frontend_swzigzag(struct dvb_frontend *fe)
359 fe_status_t s = 0;
360 struct dvb_frontend_private *fepriv = fe->frontend_priv;
362 /* if we've got no parameters, just keep idling */
363 if (fepriv->state & FESTATE_IDLE) {
364 fepriv->delay = 3*HZ;
365 fepriv->quality = 0;
366 return;
369 /* in SCAN mode, we just set the frontend when asked and leave it alone */
370 if (fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT) {
371 if (fepriv->state & FESTATE_RETUNE) {
372 if (fe->ops.set_frontend)
373 fe->ops.set_frontend(fe, &fepriv->parameters);
374 fepriv->state = FESTATE_TUNED;
376 fepriv->delay = 3*HZ;
377 fepriv->quality = 0;
378 return;
381 /* get the frontend status */
382 if (fepriv->state & FESTATE_RETUNE) {
383 s = 0;
384 } else {
385 if (fe->ops.read_status)
386 fe->ops.read_status(fe, &s);
387 if (s != fepriv->status) {
388 dvb_frontend_add_event(fe, s);
389 fepriv->status = s;
393 /* if we're not tuned, and we have a lock, move to the TUNED state */
394 if ((fepriv->state & FESTATE_WAITFORLOCK) && (s & FE_HAS_LOCK)) {
395 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
396 fepriv->state = FESTATE_TUNED;
398 /* if we're tuned, then we have determined the correct inversion */
399 if ((!(fe->ops.info.caps & FE_CAN_INVERSION_AUTO)) &&
400 (fepriv->parameters.inversion == INVERSION_AUTO)) {
401 fepriv->parameters.inversion = fepriv->inversion;
403 return;
406 /* if we are tuned already, check we're still locked */
407 if (fepriv->state & FESTATE_TUNED) {
408 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
410 /* we're tuned, and the lock is still good... */
411 if (s & FE_HAS_LOCK) {
412 return;
413 } else { /* if we _WERE_ tuned, but now don't have a lock */
414 fepriv->state = FESTATE_ZIGZAG_FAST;
415 fepriv->started_auto_step = fepriv->auto_step;
416 fepriv->check_wrapped = 0;
420 /* don't actually do anything if we're in the LOSTLOCK state,
421 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
422 if ((fepriv->state & FESTATE_LOSTLOCK) &&
423 (fe->ops.info.caps & FE_CAN_RECOVER) && (fepriv->max_drift == 0)) {
424 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
425 return;
428 /* don't do anything if we're in the DISEQC state, since this
429 * might be someone with a motorized dish controlled by DISEQC.
430 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
431 if (fepriv->state & FESTATE_DISEQC) {
432 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
433 return;
436 /* if we're in the RETUNE state, set everything up for a brand
437 * new scan, keeping the current inversion setting, as the next
438 * tune is _very_ likely to require the same */
439 if (fepriv->state & FESTATE_RETUNE) {
440 fepriv->lnb_drift = 0;
441 fepriv->auto_step = 0;
442 fepriv->auto_sub_step = 0;
443 fepriv->started_auto_step = 0;
444 fepriv->check_wrapped = 0;
447 /* fast zigzag. */
448 if ((fepriv->state & FESTATE_SEARCHING_FAST) || (fepriv->state & FESTATE_RETUNE)) {
449 fepriv->delay = fepriv->min_delay;
451 /* peform a tune */
452 if (dvb_frontend_swzigzag_autotune(fe, fepriv->check_wrapped)) {
453 /* OK, if we've run out of trials at the fast speed.
454 * Drop back to slow for the _next_ attempt */
455 fepriv->state = FESTATE_SEARCHING_SLOW;
456 fepriv->started_auto_step = fepriv->auto_step;
457 return;
459 fepriv->check_wrapped = 1;
461 /* if we've just retuned, enter the ZIGZAG_FAST state.
462 * This ensures we cannot return from an
463 * FE_SET_FRONTEND ioctl before the first frontend tune
464 * occurs */
465 if (fepriv->state & FESTATE_RETUNE) {
466 fepriv->state = FESTATE_TUNING_FAST;
470 /* slow zigzag */
471 if (fepriv->state & FESTATE_SEARCHING_SLOW) {
472 dvb_frontend_swzigzag_update_delay(fepriv, s & FE_HAS_LOCK);
474 /* Note: don't bother checking for wrapping; we stay in this
475 * state until we get a lock */
476 dvb_frontend_swzigzag_autotune(fe, 0);
480 static int dvb_frontend_is_exiting(struct dvb_frontend *fe)
482 struct dvb_frontend_private *fepriv = fe->frontend_priv;
484 if (fepriv->exit)
485 return 1;
487 if (fepriv->dvbdev->writers == 1)
488 if (time_after(jiffies, fepriv->release_jiffies +
489 dvb_shutdown_timeout * HZ))
490 return 1;
492 return 0;
495 static int dvb_frontend_should_wakeup(struct dvb_frontend *fe)
497 struct dvb_frontend_private *fepriv = fe->frontend_priv;
499 if (fepriv->wakeup) {
500 fepriv->wakeup = 0;
501 return 1;
503 return dvb_frontend_is_exiting(fe);
506 static void dvb_frontend_wakeup(struct dvb_frontend *fe)
508 struct dvb_frontend_private *fepriv = fe->frontend_priv;
510 fepriv->wakeup = 1;
511 wake_up_interruptible(&fepriv->wait_queue);
514 static int dvb_frontend_thread(void *data)
516 struct dvb_frontend *fe = data;
517 struct dvb_frontend_private *fepriv = fe->frontend_priv;
518 unsigned long timeout;
519 fe_status_t s;
520 enum dvbfe_algo algo;
522 struct dvb_frontend_parameters *params;
524 dprintk("%s\n", __func__);
526 fepriv->check_wrapped = 0;
527 fepriv->quality = 0;
528 fepriv->delay = 3*HZ;
529 fepriv->status = 0;
530 fepriv->wakeup = 0;
531 fepriv->reinitialise = 0;
533 dvb_frontend_init(fe);
535 set_freezable();
536 while (1) {
537 up(&fepriv->sem); /* is locked when we enter the thread... */
538 restart:
539 timeout = wait_event_interruptible_timeout(fepriv->wait_queue,
540 dvb_frontend_should_wakeup(fe) || kthread_should_stop()
541 || freezing(current),
542 fepriv->delay);
544 if (kthread_should_stop() || dvb_frontend_is_exiting(fe)) {
545 /* got signal or quitting */
546 break;
549 if (try_to_freeze())
550 goto restart;
552 if (down_interruptible(&fepriv->sem))
553 break;
555 if (fepriv->reinitialise) {
556 dvb_frontend_init(fe);
557 if (fepriv->tone != -1) {
558 fe->ops.set_tone(fe, fepriv->tone);
560 if (fepriv->voltage != -1) {
561 fe->ops.set_voltage(fe, fepriv->voltage);
563 fepriv->reinitialise = 0;
566 /* do an iteration of the tuning loop */
567 if (fe->ops.get_frontend_algo) {
568 algo = fe->ops.get_frontend_algo(fe);
569 switch (algo) {
570 case DVBFE_ALGO_HW:
571 dprintk("%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__);
572 params = NULL; /* have we been asked to RETUNE ? */
574 if (fepriv->state & FESTATE_RETUNE) {
575 dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__);
576 params = &fepriv->parameters;
577 fepriv->state = FESTATE_TUNED;
580 if (fe->ops.tune)
581 fe->ops.tune(fe, params, fepriv->tune_mode_flags, &fepriv->delay, &s);
583 if (s != fepriv->status && !(fepriv->tune_mode_flags & FE_TUNE_MODE_ONESHOT)) {
584 dprintk("%s: state changed, adding current state\n", __func__);
585 dvb_frontend_add_event(fe, s);
586 fepriv->status = s;
588 break;
589 case DVBFE_ALGO_SW:
590 dprintk("%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__);
591 dvb_frontend_swzigzag(fe);
592 break;
593 case DVBFE_ALGO_CUSTOM:
594 params = NULL; /* have we been asked to RETUNE ? */
595 dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__, fepriv->state);
596 if (fepriv->state & FESTATE_RETUNE) {
597 dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__);
598 params = &fepriv->parameters;
599 fepriv->state = FESTATE_TUNED;
601 /* Case where we are going to search for a carrier
602 * User asked us to retune again for some reason, possibly
603 * requesting a search with a new set of parameters
605 if (fepriv->algo_status & DVBFE_ALGO_SEARCH_AGAIN) {
606 if (fe->ops.search) {
607 fepriv->algo_status = fe->ops.search(fe, &fepriv->parameters);
608 /* We did do a search as was requested, the flags are
609 * now unset as well and has the flags wrt to search.
611 } else {
612 fepriv->algo_status &= ~DVBFE_ALGO_SEARCH_AGAIN;
615 /* Track the carrier if the search was successful */
616 if (fepriv->algo_status == DVBFE_ALGO_SEARCH_SUCCESS) {
617 if (fe->ops.track)
618 fe->ops.track(fe, &fepriv->parameters);
619 } else {
620 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
621 fepriv->delay = HZ / 2;
623 fe->ops.read_status(fe, &s);
624 if (s != fepriv->status) {
625 dvb_frontend_add_event(fe, s); /* update event list */
626 fepriv->status = s;
627 if (!(s & FE_HAS_LOCK)) {
628 fepriv->delay = HZ / 10;
629 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
630 } else {
631 fepriv->delay = 60 * HZ;
634 break;
635 default:
636 dprintk("%s: UNDEFINED ALGO !\n", __func__);
637 break;
639 } else {
640 dvb_frontend_swzigzag(fe);
644 if (dvb_powerdown_on_sleep) {
645 if (fe->ops.set_voltage)
646 fe->ops.set_voltage(fe, SEC_VOLTAGE_OFF);
647 if (fe->ops.tuner_ops.sleep) {
648 if (fe->ops.i2c_gate_ctrl)
649 fe->ops.i2c_gate_ctrl(fe, 1);
650 fe->ops.tuner_ops.sleep(fe);
651 if (fe->ops.i2c_gate_ctrl)
652 fe->ops.i2c_gate_ctrl(fe, 0);
654 if (fe->ops.sleep)
655 fe->ops.sleep(fe);
658 fepriv->thread = NULL;
659 mb();
661 dvb_frontend_wakeup(fe);
662 return 0;
665 static void dvb_frontend_stop(struct dvb_frontend *fe)
667 struct dvb_frontend_private *fepriv = fe->frontend_priv;
669 dprintk ("%s\n", __func__);
671 fepriv->exit = 1;
672 mb();
674 if (!fepriv->thread)
675 return;
677 kthread_stop(fepriv->thread);
679 init_MUTEX (&fepriv->sem);
680 fepriv->state = FESTATE_IDLE;
682 /* paranoia check in case a signal arrived */
683 if (fepriv->thread)
684 printk("dvb_frontend_stop: warning: thread %p won't exit\n",
685 fepriv->thread);
688 s32 timeval_usec_diff(struct timeval lasttime, struct timeval curtime)
690 return ((curtime.tv_usec < lasttime.tv_usec) ?
691 1000000 - lasttime.tv_usec + curtime.tv_usec :
692 curtime.tv_usec - lasttime.tv_usec);
694 EXPORT_SYMBOL(timeval_usec_diff);
696 static inline void timeval_usec_add(struct timeval *curtime, u32 add_usec)
698 curtime->tv_usec += add_usec;
699 if (curtime->tv_usec >= 1000000) {
700 curtime->tv_usec -= 1000000;
701 curtime->tv_sec++;
706 * Sleep until gettimeofday() > waketime + add_usec
707 * This needs to be as precise as possible, but as the delay is
708 * usually between 2ms and 32ms, it is done using a scheduled msleep
709 * followed by usleep (normally a busy-wait loop) for the remainder
711 void dvb_frontend_sleep_until(struct timeval *waketime, u32 add_usec)
713 struct timeval lasttime;
714 s32 delta, newdelta;
716 timeval_usec_add(waketime, add_usec);
718 do_gettimeofday(&lasttime);
719 delta = timeval_usec_diff(lasttime, *waketime);
720 if (delta > 2500) {
721 msleep((delta - 1500) / 1000);
722 do_gettimeofday(&lasttime);
723 newdelta = timeval_usec_diff(lasttime, *waketime);
724 delta = (newdelta > delta) ? 0 : newdelta;
726 if (delta > 0)
727 udelay(delta);
729 EXPORT_SYMBOL(dvb_frontend_sleep_until);
731 static int dvb_frontend_start(struct dvb_frontend *fe)
733 int ret;
734 struct dvb_frontend_private *fepriv = fe->frontend_priv;
735 struct task_struct *fe_thread;
737 dprintk ("%s\n", __func__);
739 if (fepriv->thread) {
740 if (!fepriv->exit)
741 return 0;
742 else
743 dvb_frontend_stop (fe);
746 if (signal_pending(current))
747 return -EINTR;
748 if (down_interruptible (&fepriv->sem))
749 return -EINTR;
751 fepriv->state = FESTATE_IDLE;
752 fepriv->exit = 0;
753 fepriv->thread = NULL;
754 mb();
756 fe_thread = kthread_run(dvb_frontend_thread, fe,
757 "kdvb-ad-%i-fe-%i", fe->dvb->num,fe->id);
758 if (IS_ERR(fe_thread)) {
759 ret = PTR_ERR(fe_thread);
760 printk("dvb_frontend_start: failed to start kthread (%d)\n", ret);
761 up(&fepriv->sem);
762 return ret;
764 fepriv->thread = fe_thread;
765 return 0;
768 static void dvb_frontend_get_frequeny_limits(struct dvb_frontend *fe,
769 u32 *freq_min, u32 *freq_max)
771 *freq_min = max(fe->ops.info.frequency_min, fe->ops.tuner_ops.info.frequency_min);
773 if (fe->ops.info.frequency_max == 0)
774 *freq_max = fe->ops.tuner_ops.info.frequency_max;
775 else if (fe->ops.tuner_ops.info.frequency_max == 0)
776 *freq_max = fe->ops.info.frequency_max;
777 else
778 *freq_max = min(fe->ops.info.frequency_max, fe->ops.tuner_ops.info.frequency_max);
780 if (*freq_min == 0 || *freq_max == 0)
781 printk(KERN_WARNING "DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
782 fe->dvb->num,fe->id);
785 static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
786 struct dvb_frontend_parameters *parms)
788 u32 freq_min;
789 u32 freq_max;
791 /* range check: frequency */
792 dvb_frontend_get_frequeny_limits(fe, &freq_min, &freq_max);
793 if ((freq_min && parms->frequency < freq_min) ||
794 (freq_max && parms->frequency > freq_max)) {
795 printk(KERN_WARNING "DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
796 fe->dvb->num, fe->id, parms->frequency, freq_min, freq_max);
797 return -EINVAL;
800 /* range check: symbol rate */
801 if (fe->ops.info.type == FE_QPSK) {
802 if ((fe->ops.info.symbol_rate_min &&
803 parms->u.qpsk.symbol_rate < fe->ops.info.symbol_rate_min) ||
804 (fe->ops.info.symbol_rate_max &&
805 parms->u.qpsk.symbol_rate > fe->ops.info.symbol_rate_max)) {
806 printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
807 fe->dvb->num, fe->id, parms->u.qpsk.symbol_rate,
808 fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
809 return -EINVAL;
812 } else if (fe->ops.info.type == FE_QAM) {
813 if ((fe->ops.info.symbol_rate_min &&
814 parms->u.qam.symbol_rate < fe->ops.info.symbol_rate_min) ||
815 (fe->ops.info.symbol_rate_max &&
816 parms->u.qam.symbol_rate > fe->ops.info.symbol_rate_max)) {
817 printk(KERN_WARNING "DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
818 fe->dvb->num, fe->id, parms->u.qam.symbol_rate,
819 fe->ops.info.symbol_rate_min, fe->ops.info.symbol_rate_max);
820 return -EINVAL;
824 return 0;
827 static struct dtv_cmds_h dtv_cmds[] = {
828 [DTV_TUNE] = {
829 .name = "DTV_TUNE",
830 .cmd = DTV_TUNE,
831 .set = 1,
833 [DTV_CLEAR] = {
834 .name = "DTV_CLEAR",
835 .cmd = DTV_CLEAR,
836 .set = 1,
839 /* Set */
840 [DTV_FREQUENCY] = {
841 .name = "DTV_FREQUENCY",
842 .cmd = DTV_FREQUENCY,
843 .set = 1,
845 [DTV_BANDWIDTH_HZ] = {
846 .name = "DTV_BANDWIDTH_HZ",
847 .cmd = DTV_BANDWIDTH_HZ,
848 .set = 1,
850 [DTV_MODULATION] = {
851 .name = "DTV_MODULATION",
852 .cmd = DTV_MODULATION,
853 .set = 1,
855 [DTV_INVERSION] = {
856 .name = "DTV_INVERSION",
857 .cmd = DTV_INVERSION,
858 .set = 1,
860 [DTV_DISEQC_MASTER] = {
861 .name = "DTV_DISEQC_MASTER",
862 .cmd = DTV_DISEQC_MASTER,
863 .set = 1,
864 .buffer = 1,
866 [DTV_SYMBOL_RATE] = {
867 .name = "DTV_SYMBOL_RATE",
868 .cmd = DTV_SYMBOL_RATE,
869 .set = 1,
871 [DTV_INNER_FEC] = {
872 .name = "DTV_INNER_FEC",
873 .cmd = DTV_INNER_FEC,
874 .set = 1,
876 [DTV_VOLTAGE] = {
877 .name = "DTV_VOLTAGE",
878 .cmd = DTV_VOLTAGE,
879 .set = 1,
881 [DTV_TONE] = {
882 .name = "DTV_TONE",
883 .cmd = DTV_TONE,
884 .set = 1,
886 [DTV_PILOT] = {
887 .name = "DTV_PILOT",
888 .cmd = DTV_PILOT,
889 .set = 1,
891 [DTV_ROLLOFF] = {
892 .name = "DTV_ROLLOFF",
893 .cmd = DTV_ROLLOFF,
894 .set = 1,
896 [DTV_DELIVERY_SYSTEM] = {
897 .name = "DTV_DELIVERY_SYSTEM",
898 .cmd = DTV_DELIVERY_SYSTEM,
899 .set = 1,
901 [DTV_HIERARCHY] = {
902 .name = "DTV_HIERARCHY",
903 .cmd = DTV_HIERARCHY,
904 .set = 1,
906 [DTV_CODE_RATE_HP] = {
907 .name = "DTV_CODE_RATE_HP",
908 .cmd = DTV_CODE_RATE_HP,
909 .set = 1,
911 [DTV_CODE_RATE_LP] = {
912 .name = "DTV_CODE_RATE_LP",
913 .cmd = DTV_CODE_RATE_LP,
914 .set = 1,
916 [DTV_GUARD_INTERVAL] = {
917 .name = "DTV_GUARD_INTERVAL",
918 .cmd = DTV_GUARD_INTERVAL,
919 .set = 1,
921 [DTV_TRANSMISSION_MODE] = {
922 .name = "DTV_TRANSMISSION_MODE",
923 .cmd = DTV_TRANSMISSION_MODE,
924 .set = 1,
926 /* Get */
927 [DTV_DISEQC_SLAVE_REPLY] = {
928 .name = "DTV_DISEQC_SLAVE_REPLY",
929 .cmd = DTV_DISEQC_SLAVE_REPLY,
930 .set = 0,
931 .buffer = 1,
933 [DTV_API_VERSION] = {
934 .name = "DTV_API_VERSION",
935 .cmd = DTV_API_VERSION,
936 .set = 0,
938 [DTV_CODE_RATE_HP] = {
939 .name = "DTV_CODE_RATE_HP",
940 .cmd = DTV_CODE_RATE_HP,
941 .set = 0,
943 [DTV_CODE_RATE_LP] = {
944 .name = "DTV_CODE_RATE_LP",
945 .cmd = DTV_CODE_RATE_LP,
946 .set = 0,
948 [DTV_GUARD_INTERVAL] = {
949 .name = "DTV_GUARD_INTERVAL",
950 .cmd = DTV_GUARD_INTERVAL,
951 .set = 0,
953 [DTV_TRANSMISSION_MODE] = {
954 .name = "DTV_TRANSMISSION_MODE",
955 .cmd = DTV_TRANSMISSION_MODE,
956 .set = 0,
958 [DTV_HIERARCHY] = {
959 .name = "DTV_HIERARCHY",
960 .cmd = DTV_HIERARCHY,
961 .set = 0,
965 static void dtv_property_dump(struct dtv_property *tvp)
967 int i;
969 if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) {
970 printk(KERN_WARNING "%s: tvp.cmd = 0x%08x undefined\n",
971 __func__, tvp->cmd);
972 return;
975 dprintk("%s() tvp.cmd = 0x%08x (%s)\n"
976 ,__func__
977 ,tvp->cmd
978 ,dtv_cmds[ tvp->cmd ].name);
980 if(dtv_cmds[ tvp->cmd ].buffer) {
982 dprintk("%s() tvp.u.buffer.len = 0x%02x\n"
983 ,__func__
984 ,tvp->u.buffer.len);
986 for(i = 0; i < tvp->u.buffer.len; i++)
987 dprintk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n"
988 ,__func__
990 ,tvp->u.buffer.data[i]);
992 } else
993 dprintk("%s() tvp.u.data = 0x%08x\n", __func__, tvp->u.data);
996 static int is_legacy_delivery_system(fe_delivery_system_t s)
998 if((s == SYS_UNDEFINED) || (s == SYS_DVBC_ANNEX_AC) ||
999 (s == SYS_DVBC_ANNEX_B) || (s == SYS_DVBT) || (s == SYS_DVBS) ||
1000 (s == SYS_ATSC))
1001 return 1;
1003 return 0;
1006 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1007 * drivers can use a single set_frontend tuning function, regardless of whether
1008 * it's being used for the legacy or new API, reducing code and complexity.
1010 static void dtv_property_cache_sync(struct dvb_frontend *fe,
1011 struct dvb_frontend_parameters *p)
1013 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1015 c->frequency = p->frequency;
1016 c->inversion = p->inversion;
1018 switch (fe->ops.info.type) {
1019 case FE_QPSK:
1020 c->modulation = QPSK; /* implied for DVB-S in legacy API */
1021 c->rolloff = ROLLOFF_35;/* implied for DVB-S */
1022 c->symbol_rate = p->u.qpsk.symbol_rate;
1023 c->fec_inner = p->u.qpsk.fec_inner;
1024 c->delivery_system = SYS_DVBS;
1025 break;
1026 case FE_QAM:
1027 c->symbol_rate = p->u.qam.symbol_rate;
1028 c->fec_inner = p->u.qam.fec_inner;
1029 c->modulation = p->u.qam.modulation;
1030 c->delivery_system = SYS_DVBC_ANNEX_AC;
1031 break;
1032 case FE_OFDM:
1033 if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ)
1034 c->bandwidth_hz = 6000000;
1035 else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ)
1036 c->bandwidth_hz = 7000000;
1037 else if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
1038 c->bandwidth_hz = 8000000;
1039 else
1040 /* Including BANDWIDTH_AUTO */
1041 c->bandwidth_hz = 0;
1042 c->code_rate_HP = p->u.ofdm.code_rate_HP;
1043 c->code_rate_LP = p->u.ofdm.code_rate_LP;
1044 c->modulation = p->u.ofdm.constellation;
1045 c->transmission_mode = p->u.ofdm.transmission_mode;
1046 c->guard_interval = p->u.ofdm.guard_interval;
1047 c->hierarchy = p->u.ofdm.hierarchy_information;
1048 c->delivery_system = SYS_DVBT;
1049 break;
1050 case FE_ATSC:
1051 c->modulation = p->u.vsb.modulation;
1052 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1053 c->delivery_system = SYS_ATSC;
1054 else
1055 c->delivery_system = SYS_DVBC_ANNEX_B;
1056 break;
1060 /* Ensure the cached values are set correctly in the frontend
1061 * legacy tuning structures, for the advanced tuning API.
1063 static void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
1065 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1066 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1067 struct dvb_frontend_parameters *p = &fepriv->parameters;
1069 p->frequency = c->frequency;
1070 p->inversion = c->inversion;
1072 switch (fe->ops.info.type) {
1073 case FE_QPSK:
1074 dprintk("%s() Preparing QPSK req\n", __func__);
1075 p->u.qpsk.symbol_rate = c->symbol_rate;
1076 p->u.qpsk.fec_inner = c->fec_inner;
1077 c->delivery_system = SYS_DVBS;
1078 break;
1079 case FE_QAM:
1080 dprintk("%s() Preparing QAM req\n", __func__);
1081 p->u.qam.symbol_rate = c->symbol_rate;
1082 p->u.qam.fec_inner = c->fec_inner;
1083 p->u.qam.modulation = c->modulation;
1084 c->delivery_system = SYS_DVBC_ANNEX_AC;
1085 break;
1086 case FE_OFDM:
1087 dprintk("%s() Preparing OFDM req\n", __func__);
1088 if (c->bandwidth_hz == 6000000)
1089 p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
1090 else if (c->bandwidth_hz == 7000000)
1091 p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
1092 else if (c->bandwidth_hz == 8000000)
1093 p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
1094 else
1095 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1096 p->u.ofdm.code_rate_HP = c->code_rate_HP;
1097 p->u.ofdm.code_rate_LP = c->code_rate_LP;
1098 p->u.ofdm.constellation = c->modulation;
1099 p->u.ofdm.transmission_mode = c->transmission_mode;
1100 p->u.ofdm.guard_interval = c->guard_interval;
1101 p->u.ofdm.hierarchy_information = c->hierarchy;
1102 c->delivery_system = SYS_DVBT;
1103 break;
1104 case FE_ATSC:
1105 dprintk("%s() Preparing VSB req\n", __func__);
1106 p->u.vsb.modulation = c->modulation;
1107 if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
1108 c->delivery_system = SYS_ATSC;
1109 else
1110 c->delivery_system = SYS_DVBC_ANNEX_B;
1111 break;
1115 /* Ensure the cached values are set correctly in the frontend
1116 * legacy tuning structures, for the legacy tuning API.
1118 static void dtv_property_adv_params_sync(struct dvb_frontend *fe)
1120 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1121 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1122 struct dvb_frontend_parameters *p = &fepriv->parameters;
1124 p->frequency = c->frequency;
1125 p->inversion = c->inversion;
1127 switch(c->modulation) {
1128 case PSK_8:
1129 case APSK_16:
1130 case APSK_32:
1131 case QPSK:
1132 p->u.qpsk.symbol_rate = c->symbol_rate;
1133 p->u.qpsk.fec_inner = c->fec_inner;
1134 break;
1135 default:
1136 break;
1139 if(c->delivery_system == SYS_ISDBT) {
1140 /* Fake out a generic DVB-T request so we pass validation in the ioctl */
1141 p->frequency = c->frequency;
1142 p->inversion = INVERSION_AUTO;
1143 p->u.ofdm.constellation = QAM_AUTO;
1144 p->u.ofdm.code_rate_HP = FEC_AUTO;
1145 p->u.ofdm.code_rate_LP = FEC_AUTO;
1146 p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
1147 p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
1148 p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
1149 p->u.ofdm.hierarchy_information = HIERARCHY_AUTO;
1153 static void dtv_property_cache_submit(struct dvb_frontend *fe)
1155 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1157 /* For legacy delivery systems we don't need the delivery_system to
1158 * be specified, but we populate the older structures from the cache
1159 * so we can call set_frontend on older drivers.
1161 if(is_legacy_delivery_system(c->delivery_system)) {
1163 dprintk("%s() legacy, modulation = %d\n", __func__, c->modulation);
1164 dtv_property_legacy_params_sync(fe);
1166 } else {
1167 dprintk("%s() adv, modulation = %d\n", __func__, c->modulation);
1169 /* For advanced delivery systems / modulation types ...
1170 * we seed the lecacy dvb_frontend_parameters structure
1171 * so that the sanity checking code later in the IOCTL processing
1172 * can validate our basic frequency ranges, symbolrates, modulation
1173 * etc.
1175 dtv_property_adv_params_sync(fe);
1179 static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
1180 unsigned int cmd, void *parg);
1181 static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1182 unsigned int cmd, void *parg);
1184 static int dtv_property_process_get(struct dvb_frontend *fe,
1185 struct dtv_property *tvp,
1186 struct inode *inode, struct file *file)
1188 int r = 0;
1190 dtv_property_dump(tvp);
1192 /* Allow the frontend to validate incoming properties */
1193 if (fe->ops.get_property)
1194 r = fe->ops.get_property(fe, tvp);
1196 if (r < 0)
1197 return r;
1199 switch(tvp->cmd) {
1200 case DTV_FREQUENCY:
1201 tvp->u.data = fe->dtv_property_cache.frequency;
1202 break;
1203 case DTV_MODULATION:
1204 tvp->u.data = fe->dtv_property_cache.modulation;
1205 break;
1206 case DTV_BANDWIDTH_HZ:
1207 tvp->u.data = fe->dtv_property_cache.bandwidth_hz;
1208 break;
1209 case DTV_INVERSION:
1210 tvp->u.data = fe->dtv_property_cache.inversion;
1211 break;
1212 case DTV_SYMBOL_RATE:
1213 tvp->u.data = fe->dtv_property_cache.symbol_rate;
1214 break;
1215 case DTV_INNER_FEC:
1216 tvp->u.data = fe->dtv_property_cache.fec_inner;
1217 break;
1218 case DTV_PILOT:
1219 tvp->u.data = fe->dtv_property_cache.pilot;
1220 break;
1221 case DTV_ROLLOFF:
1222 tvp->u.data = fe->dtv_property_cache.rolloff;
1223 break;
1224 case DTV_DELIVERY_SYSTEM:
1225 tvp->u.data = fe->dtv_property_cache.delivery_system;
1226 break;
1227 case DTV_VOLTAGE:
1228 tvp->u.data = fe->dtv_property_cache.voltage;
1229 break;
1230 case DTV_TONE:
1231 tvp->u.data = fe->dtv_property_cache.sectone;
1232 break;
1233 case DTV_API_VERSION:
1234 tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
1235 break;
1236 case DTV_CODE_RATE_HP:
1237 tvp->u.data = fe->dtv_property_cache.code_rate_HP;
1238 break;
1239 case DTV_CODE_RATE_LP:
1240 tvp->u.data = fe->dtv_property_cache.code_rate_LP;
1241 break;
1242 case DTV_GUARD_INTERVAL:
1243 tvp->u.data = fe->dtv_property_cache.guard_interval;
1244 break;
1245 case DTV_TRANSMISSION_MODE:
1246 tvp->u.data = fe->dtv_property_cache.transmission_mode;
1247 break;
1248 case DTV_HIERARCHY:
1249 tvp->u.data = fe->dtv_property_cache.hierarchy;
1250 break;
1251 default:
1252 r = -1;
1255 return r;
1258 static int dtv_property_process_set(struct dvb_frontend *fe,
1259 struct dtv_property *tvp,
1260 struct inode *inode,
1261 struct file *file)
1263 int r = 0;
1264 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1265 dtv_property_dump(tvp);
1267 /* Allow the frontend to validate incoming properties */
1268 if (fe->ops.set_property)
1269 r = fe->ops.set_property(fe, tvp);
1271 if (r < 0)
1272 return r;
1274 switch(tvp->cmd) {
1275 case DTV_CLEAR:
1276 /* Reset a cache of data specific to the frontend here. This does
1277 * not effect hardware.
1279 dprintk("%s() Flushing property cache\n", __func__);
1280 memset(&fe->dtv_property_cache, 0, sizeof(struct dtv_frontend_properties));
1281 fe->dtv_property_cache.state = tvp->cmd;
1282 fe->dtv_property_cache.delivery_system = SYS_UNDEFINED;
1283 break;
1284 case DTV_TUNE:
1285 /* interpret the cache of data, build either a traditional frontend
1286 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1287 * ioctl.
1289 fe->dtv_property_cache.state = tvp->cmd;
1290 dprintk("%s() Finalised property cache\n", __func__);
1291 dtv_property_cache_submit(fe);
1293 r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND,
1294 &fepriv->parameters);
1295 break;
1296 case DTV_FREQUENCY:
1297 fe->dtv_property_cache.frequency = tvp->u.data;
1298 break;
1299 case DTV_MODULATION:
1300 fe->dtv_property_cache.modulation = tvp->u.data;
1301 break;
1302 case DTV_BANDWIDTH_HZ:
1303 fe->dtv_property_cache.bandwidth_hz = tvp->u.data;
1304 break;
1305 case DTV_INVERSION:
1306 fe->dtv_property_cache.inversion = tvp->u.data;
1307 break;
1308 case DTV_SYMBOL_RATE:
1309 fe->dtv_property_cache.symbol_rate = tvp->u.data;
1310 break;
1311 case DTV_INNER_FEC:
1312 fe->dtv_property_cache.fec_inner = tvp->u.data;
1313 break;
1314 case DTV_PILOT:
1315 fe->dtv_property_cache.pilot = tvp->u.data;
1316 break;
1317 case DTV_ROLLOFF:
1318 fe->dtv_property_cache.rolloff = tvp->u.data;
1319 break;
1320 case DTV_DELIVERY_SYSTEM:
1321 fe->dtv_property_cache.delivery_system = tvp->u.data;
1322 break;
1323 case DTV_VOLTAGE:
1324 fe->dtv_property_cache.voltage = tvp->u.data;
1325 r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_VOLTAGE,
1326 (void *)fe->dtv_property_cache.voltage);
1327 break;
1328 case DTV_TONE:
1329 fe->dtv_property_cache.sectone = tvp->u.data;
1330 r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_TONE,
1331 (void *)fe->dtv_property_cache.sectone);
1332 break;
1333 case DTV_CODE_RATE_HP:
1334 fe->dtv_property_cache.code_rate_HP = tvp->u.data;
1335 break;
1336 case DTV_CODE_RATE_LP:
1337 fe->dtv_property_cache.code_rate_LP = tvp->u.data;
1338 break;
1339 case DTV_GUARD_INTERVAL:
1340 fe->dtv_property_cache.guard_interval = tvp->u.data;
1341 break;
1342 case DTV_TRANSMISSION_MODE:
1343 fe->dtv_property_cache.transmission_mode = tvp->u.data;
1344 break;
1345 case DTV_HIERARCHY:
1346 fe->dtv_property_cache.hierarchy = tvp->u.data;
1347 break;
1348 default:
1349 r = -1;
1352 return r;
1355 static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
1356 unsigned int cmd, void *parg)
1358 struct dvb_device *dvbdev = file->private_data;
1359 struct dvb_frontend *fe = dvbdev->priv;
1360 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1361 int err = -EOPNOTSUPP;
1363 dprintk ("%s\n", __func__);
1365 if (fepriv->exit)
1366 return -ENODEV;
1368 if ((file->f_flags & O_ACCMODE) == O_RDONLY &&
1369 (_IOC_DIR(cmd) != _IOC_READ || cmd == FE_GET_EVENT ||
1370 cmd == FE_DISEQC_RECV_SLAVE_REPLY))
1371 return -EPERM;
1373 if (down_interruptible (&fepriv->sem))
1374 return -ERESTARTSYS;
1376 if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
1377 err = dvb_frontend_ioctl_properties(inode, file, cmd, parg);
1378 else {
1379 fe->dtv_property_cache.state = DTV_UNDEFINED;
1380 err = dvb_frontend_ioctl_legacy(inode, file, cmd, parg);
1383 up(&fepriv->sem);
1384 return err;
1387 static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
1388 unsigned int cmd, void *parg)
1390 struct dvb_device *dvbdev = file->private_data;
1391 struct dvb_frontend *fe = dvbdev->priv;
1392 int err = 0;
1394 struct dtv_properties *tvps = NULL;
1395 struct dtv_property *tvp = NULL;
1396 int i;
1398 dprintk("%s\n", __func__);
1400 if(cmd == FE_SET_PROPERTY) {
1401 tvps = (struct dtv_properties __user *)parg;
1403 dprintk("%s() properties.num = %d\n", __func__, tvps->num);
1404 dprintk("%s() properties.props = %p\n", __func__, tvps->props);
1406 /* Put an arbitrary limit on the number of messages that can
1407 * be sent at once */
1408 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1409 return -EINVAL;
1411 tvp = (struct dtv_property *) kmalloc(tvps->num *
1412 sizeof(struct dtv_property), GFP_KERNEL);
1413 if (!tvp) {
1414 err = -ENOMEM;
1415 goto out;
1418 if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
1419 err = -EFAULT;
1420 goto out;
1423 for (i = 0; i < tvps->num; i++) {
1424 (tvp + i)->result = dtv_property_process_set(fe, tvp + i, inode, file);
1425 err |= (tvp + i)->result;
1428 if(fe->dtv_property_cache.state == DTV_TUNE)
1429 dprintk("%s() Property cache is full, tuning\n", __func__);
1431 } else
1432 if(cmd == FE_GET_PROPERTY) {
1434 tvps = (struct dtv_properties __user *)parg;
1436 dprintk("%s() properties.num = %d\n", __func__, tvps->num);
1437 dprintk("%s() properties.props = %p\n", __func__, tvps->props);
1439 /* Put an arbitrary limit on the number of messages that can
1440 * be sent at once */
1441 if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
1442 return -EINVAL;
1444 tvp = (struct dtv_property *) kmalloc(tvps->num *
1445 sizeof(struct dtv_property), GFP_KERNEL);
1446 if (!tvp) {
1447 err = -ENOMEM;
1448 goto out;
1451 if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
1452 err = -EFAULT;
1453 goto out;
1456 for (i = 0; i < tvps->num; i++) {
1457 (tvp + i)->result = dtv_property_process_get(fe, tvp + i, inode, file);
1458 err |= (tvp + i)->result;
1461 if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) {
1462 err = -EFAULT;
1463 goto out;
1466 } else
1467 err = -EOPNOTSUPP;
1469 out:
1470 kfree(tvp);
1471 return err;
1474 static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
1475 unsigned int cmd, void *parg)
1477 struct dvb_device *dvbdev = file->private_data;
1478 struct dvb_frontend *fe = dvbdev->priv;
1479 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1480 int err = -EOPNOTSUPP;
1482 switch (cmd) {
1483 case FE_GET_INFO: {
1484 struct dvb_frontend_info* info = parg;
1485 memcpy(info, &fe->ops.info, sizeof(struct dvb_frontend_info));
1486 dvb_frontend_get_frequeny_limits(fe, &info->frequency_min, &info->frequency_max);
1488 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
1489 * do it, it is done for it. */
1490 info->caps |= FE_CAN_INVERSION_AUTO;
1491 err = 0;
1492 break;
1495 case FE_READ_STATUS: {
1496 fe_status_t* status = parg;
1498 /* if retune was requested but hasn't occured yet, prevent
1499 * that user get signal state from previous tuning */
1500 if(fepriv->state == FESTATE_RETUNE) {
1501 err=0;
1502 *status = 0;
1503 break;
1506 if (fe->ops.read_status)
1507 err = fe->ops.read_status(fe, status);
1508 break;
1510 case FE_READ_BER:
1511 if (fe->ops.read_ber)
1512 err = fe->ops.read_ber(fe, (__u32*) parg);
1513 break;
1515 case FE_READ_SIGNAL_STRENGTH:
1516 if (fe->ops.read_signal_strength)
1517 err = fe->ops.read_signal_strength(fe, (__u16*) parg);
1518 break;
1520 case FE_READ_SNR:
1521 if (fe->ops.read_snr)
1522 err = fe->ops.read_snr(fe, (__u16*) parg);
1523 break;
1525 case FE_READ_UNCORRECTED_BLOCKS:
1526 if (fe->ops.read_ucblocks)
1527 err = fe->ops.read_ucblocks(fe, (__u32*) parg);
1528 break;
1531 case FE_DISEQC_RESET_OVERLOAD:
1532 if (fe->ops.diseqc_reset_overload) {
1533 err = fe->ops.diseqc_reset_overload(fe);
1534 fepriv->state = FESTATE_DISEQC;
1535 fepriv->status = 0;
1537 break;
1539 case FE_DISEQC_SEND_MASTER_CMD:
1540 if (fe->ops.diseqc_send_master_cmd) {
1541 err = fe->ops.diseqc_send_master_cmd(fe, (struct dvb_diseqc_master_cmd*) parg);
1542 fepriv->state = FESTATE_DISEQC;
1543 fepriv->status = 0;
1545 break;
1547 case FE_DISEQC_SEND_BURST:
1548 if (fe->ops.diseqc_send_burst) {
1549 err = fe->ops.diseqc_send_burst(fe, (fe_sec_mini_cmd_t) parg);
1550 fepriv->state = FESTATE_DISEQC;
1551 fepriv->status = 0;
1553 break;
1555 case FE_SET_TONE:
1556 if (fe->ops.set_tone) {
1557 err = fe->ops.set_tone(fe, (fe_sec_tone_mode_t) parg);
1558 fepriv->tone = (fe_sec_tone_mode_t) parg;
1559 fepriv->state = FESTATE_DISEQC;
1560 fepriv->status = 0;
1562 break;
1564 case FE_SET_VOLTAGE:
1565 if (fe->ops.set_voltage) {
1566 err = fe->ops.set_voltage(fe, (fe_sec_voltage_t) parg);
1567 fepriv->voltage = (fe_sec_voltage_t) parg;
1568 fepriv->state = FESTATE_DISEQC;
1569 fepriv->status = 0;
1571 break;
1573 case FE_DISHNETWORK_SEND_LEGACY_CMD:
1574 if (fe->ops.dishnetwork_send_legacy_command) {
1575 err = fe->ops.dishnetwork_send_legacy_command(fe, (unsigned long) parg);
1576 fepriv->state = FESTATE_DISEQC;
1577 fepriv->status = 0;
1578 } else if (fe->ops.set_voltage) {
1580 * NOTE: This is a fallback condition. Some frontends
1581 * (stv0299 for instance) take longer than 8msec to
1582 * respond to a set_voltage command. Those switches
1583 * need custom routines to switch properly. For all
1584 * other frontends, the following shoule work ok.
1585 * Dish network legacy switches (as used by Dish500)
1586 * are controlled by sending 9-bit command words
1587 * spaced 8msec apart.
1588 * the actual command word is switch/port dependant
1589 * so it is up to the userspace application to send
1590 * the right command.
1591 * The command must always start with a '0' after
1592 * initialization, so parg is 8 bits and does not
1593 * include the initialization or start bit
1595 unsigned long swcmd = ((unsigned long) parg) << 1;
1596 struct timeval nexttime;
1597 struct timeval tv[10];
1598 int i;
1599 u8 last = 1;
1600 if (dvb_frontend_debug)
1601 printk("%s switch command: 0x%04lx\n", __func__, swcmd);
1602 do_gettimeofday(&nexttime);
1603 if (dvb_frontend_debug)
1604 memcpy(&tv[0], &nexttime, sizeof(struct timeval));
1605 /* before sending a command, initialize by sending
1606 * a 32ms 18V to the switch
1608 fe->ops.set_voltage(fe, SEC_VOLTAGE_18);
1609 dvb_frontend_sleep_until(&nexttime, 32000);
1611 for (i = 0; i < 9; i++) {
1612 if (dvb_frontend_debug)
1613 do_gettimeofday(&tv[i + 1]);
1614 if ((swcmd & 0x01) != last) {
1615 /* set voltage to (last ? 13V : 18V) */
1616 fe->ops.set_voltage(fe, (last) ? SEC_VOLTAGE_13 : SEC_VOLTAGE_18);
1617 last = (last) ? 0 : 1;
1619 swcmd = swcmd >> 1;
1620 if (i != 8)
1621 dvb_frontend_sleep_until(&nexttime, 8000);
1623 if (dvb_frontend_debug) {
1624 printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
1625 __func__, fe->dvb->num);
1626 for (i = 1; i < 10; i++)
1627 printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
1629 err = 0;
1630 fepriv->state = FESTATE_DISEQC;
1631 fepriv->status = 0;
1633 break;
1635 case FE_DISEQC_RECV_SLAVE_REPLY:
1636 if (fe->ops.diseqc_recv_slave_reply)
1637 err = fe->ops.diseqc_recv_slave_reply(fe, (struct dvb_diseqc_slave_reply*) parg);
1638 break;
1640 case FE_ENABLE_HIGH_LNB_VOLTAGE:
1641 if (fe->ops.enable_high_lnb_voltage)
1642 err = fe->ops.enable_high_lnb_voltage(fe, (long) parg);
1643 break;
1645 case FE_SET_FRONTEND: {
1646 struct dvb_frontend_tune_settings fetunesettings;
1648 if(fe->dtv_property_cache.state == DTV_TUNE) {
1649 if (dvb_frontend_check_parameters(fe, &fepriv->parameters) < 0) {
1650 err = -EINVAL;
1651 break;
1653 } else {
1654 if (dvb_frontend_check_parameters(fe, parg) < 0) {
1655 err = -EINVAL;
1656 break;
1659 memcpy (&fepriv->parameters, parg,
1660 sizeof (struct dvb_frontend_parameters));
1661 dtv_property_cache_sync(fe, &fepriv->parameters);
1664 memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
1665 memcpy(&fetunesettings.parameters, parg,
1666 sizeof (struct dvb_frontend_parameters));
1668 /* force auto frequency inversion if requested */
1669 if (dvb_force_auto_inversion) {
1670 fepriv->parameters.inversion = INVERSION_AUTO;
1671 fetunesettings.parameters.inversion = INVERSION_AUTO;
1673 if (fe->ops.info.type == FE_OFDM) {
1674 /* without hierarchical coding code_rate_LP is irrelevant,
1675 * so we tolerate the otherwise invalid FEC_NONE setting */
1676 if (fepriv->parameters.u.ofdm.hierarchy_information == HIERARCHY_NONE &&
1677 fepriv->parameters.u.ofdm.code_rate_LP == FEC_NONE)
1678 fepriv->parameters.u.ofdm.code_rate_LP = FEC_AUTO;
1681 /* get frontend-specific tuning settings */
1682 if (fe->ops.get_tune_settings && (fe->ops.get_tune_settings(fe, &fetunesettings) == 0)) {
1683 fepriv->min_delay = (fetunesettings.min_delay_ms * HZ) / 1000;
1684 fepriv->max_drift = fetunesettings.max_drift;
1685 fepriv->step_size = fetunesettings.step_size;
1686 } else {
1687 /* default values */
1688 switch(fe->ops.info.type) {
1689 case FE_QPSK:
1690 fepriv->min_delay = HZ/20;
1691 fepriv->step_size = fepriv->parameters.u.qpsk.symbol_rate / 16000;
1692 fepriv->max_drift = fepriv->parameters.u.qpsk.symbol_rate / 2000;
1693 break;
1695 case FE_QAM:
1696 fepriv->min_delay = HZ/20;
1697 fepriv->step_size = 0; /* no zigzag */
1698 fepriv->max_drift = 0;
1699 break;
1701 case FE_OFDM:
1702 fepriv->min_delay = HZ/20;
1703 fepriv->step_size = fe->ops.info.frequency_stepsize * 2;
1704 fepriv->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
1705 break;
1706 case FE_ATSC:
1707 fepriv->min_delay = HZ/20;
1708 fepriv->step_size = 0;
1709 fepriv->max_drift = 0;
1710 break;
1713 if (dvb_override_tune_delay > 0)
1714 fepriv->min_delay = (dvb_override_tune_delay * HZ) / 1000;
1716 fepriv->state = FESTATE_RETUNE;
1718 /* Request the search algorithm to search */
1719 fepriv->algo_status |= DVBFE_ALGO_SEARCH_AGAIN;
1721 dvb_frontend_wakeup(fe);
1722 dvb_frontend_add_event(fe, 0);
1723 fepriv->status = 0;
1724 err = 0;
1725 break;
1728 case FE_GET_EVENT:
1729 err = dvb_frontend_get_event (fe, parg, file->f_flags);
1730 break;
1732 case FE_GET_FRONTEND:
1733 if (fe->ops.get_frontend) {
1734 memcpy (parg, &fepriv->parameters, sizeof (struct dvb_frontend_parameters));
1735 err = fe->ops.get_frontend(fe, (struct dvb_frontend_parameters*) parg);
1737 break;
1739 case FE_SET_FRONTEND_TUNE_MODE:
1740 fepriv->tune_mode_flags = (unsigned long) parg;
1741 err = 0;
1742 break;
1745 return err;
1749 static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
1751 struct dvb_device *dvbdev = file->private_data;
1752 struct dvb_frontend *fe = dvbdev->priv;
1753 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1755 dprintk ("%s\n", __func__);
1757 poll_wait (file, &fepriv->events.wait_queue, wait);
1759 if (fepriv->events.eventw != fepriv->events.eventr)
1760 return (POLLIN | POLLRDNORM | POLLPRI);
1762 return 0;
1765 static int dvb_frontend_open(struct inode *inode, struct file *file)
1767 struct dvb_device *dvbdev = file->private_data;
1768 struct dvb_frontend *fe = dvbdev->priv;
1769 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1770 struct dvb_adapter *adapter = fe->dvb;
1771 int ret;
1773 dprintk ("%s\n", __func__);
1775 if (adapter->mfe_shared) {
1776 mutex_lock (&adapter->mfe_lock);
1778 if (adapter->mfe_dvbdev == NULL)
1779 adapter->mfe_dvbdev = dvbdev;
1781 else if (adapter->mfe_dvbdev != dvbdev) {
1782 struct dvb_device
1783 *mfedev = adapter->mfe_dvbdev;
1784 struct dvb_frontend
1785 *mfe = mfedev->priv;
1786 struct dvb_frontend_private
1787 *mfepriv = mfe->frontend_priv;
1788 int mferetry = (dvb_mfe_wait_time << 1);
1790 mutex_unlock (&adapter->mfe_lock);
1791 while (mferetry-- && (mfedev->users != -1 ||
1792 mfepriv->thread != NULL)) {
1793 if(msleep_interruptible(500)) {
1794 if(signal_pending(current))
1795 return -EINTR;
1799 mutex_lock (&adapter->mfe_lock);
1800 if(adapter->mfe_dvbdev != dvbdev) {
1801 mfedev = adapter->mfe_dvbdev;
1802 mfe = mfedev->priv;
1803 mfepriv = mfe->frontend_priv;
1804 if (mfedev->users != -1 ||
1805 mfepriv->thread != NULL) {
1806 mutex_unlock (&adapter->mfe_lock);
1807 return -EBUSY;
1809 adapter->mfe_dvbdev = dvbdev;
1814 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
1815 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
1816 goto err0;
1819 if ((ret = dvb_generic_open (inode, file)) < 0)
1820 goto err1;
1822 if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
1823 /* normal tune mode when opened R/W */
1824 fepriv->tune_mode_flags &= ~FE_TUNE_MODE_ONESHOT;
1825 fepriv->tone = -1;
1826 fepriv->voltage = -1;
1828 ret = dvb_frontend_start (fe);
1829 if (ret)
1830 goto err2;
1832 /* empty event queue */
1833 fepriv->events.eventr = fepriv->events.eventw = 0;
1836 if (adapter->mfe_shared)
1837 mutex_unlock (&adapter->mfe_lock);
1838 return ret;
1840 err2:
1841 dvb_generic_release(inode, file);
1842 err1:
1843 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl)
1844 fe->ops.ts_bus_ctrl(fe, 0);
1845 err0:
1846 if (adapter->mfe_shared)
1847 mutex_unlock (&adapter->mfe_lock);
1848 return ret;
1851 static int dvb_frontend_release(struct inode *inode, struct file *file)
1853 struct dvb_device *dvbdev = file->private_data;
1854 struct dvb_frontend *fe = dvbdev->priv;
1855 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1856 int ret;
1858 dprintk ("%s\n", __func__);
1860 if ((file->f_flags & O_ACCMODE) != O_RDONLY)
1861 fepriv->release_jiffies = jiffies;
1863 ret = dvb_generic_release (inode, file);
1865 if (dvbdev->users == -1) {
1866 if (fepriv->exit == 1) {
1867 fops_put(file->f_op);
1868 file->f_op = NULL;
1869 wake_up(&dvbdev->wait_queue);
1871 if (fe->ops.ts_bus_ctrl)
1872 fe->ops.ts_bus_ctrl(fe, 0);
1875 return ret;
1878 static struct file_operations dvb_frontend_fops = {
1879 .owner = THIS_MODULE,
1880 .ioctl = dvb_generic_ioctl,
1881 .poll = dvb_frontend_poll,
1882 .open = dvb_frontend_open,
1883 .release = dvb_frontend_release
1886 int dvb_register_frontend(struct dvb_adapter* dvb,
1887 struct dvb_frontend* fe)
1889 struct dvb_frontend_private *fepriv;
1890 static const struct dvb_device dvbdev_template = {
1891 .users = ~0,
1892 .writers = 1,
1893 .readers = (~0)-1,
1894 .fops = &dvb_frontend_fops,
1895 .kernel_ioctl = dvb_frontend_ioctl
1898 dprintk ("%s\n", __func__);
1900 if (mutex_lock_interruptible(&frontend_mutex))
1901 return -ERESTARTSYS;
1903 fe->frontend_priv = kzalloc(sizeof(struct dvb_frontend_private), GFP_KERNEL);
1904 if (fe->frontend_priv == NULL) {
1905 mutex_unlock(&frontend_mutex);
1906 return -ENOMEM;
1908 fepriv = fe->frontend_priv;
1910 init_MUTEX (&fepriv->sem);
1911 init_waitqueue_head (&fepriv->wait_queue);
1912 init_waitqueue_head (&fepriv->events.wait_queue);
1913 mutex_init(&fepriv->events.mtx);
1914 fe->dvb = dvb;
1915 fepriv->inversion = INVERSION_OFF;
1917 printk ("DVB: registering adapter %i frontend %i (%s)...\n",
1918 fe->dvb->num,
1919 fe->id,
1920 fe->ops.info.name);
1922 dvb_register_device (fe->dvb, &fepriv->dvbdev, &dvbdev_template,
1923 fe, DVB_DEVICE_FRONTEND);
1925 mutex_unlock(&frontend_mutex);
1926 return 0;
1928 EXPORT_SYMBOL(dvb_register_frontend);
1930 int dvb_unregister_frontend(struct dvb_frontend* fe)
1932 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1933 dprintk ("%s\n", __func__);
1935 mutex_lock(&frontend_mutex);
1936 dvb_frontend_stop (fe);
1937 mutex_unlock(&frontend_mutex);
1939 if (fepriv->dvbdev->users < -1)
1940 wait_event(fepriv->dvbdev->wait_queue,
1941 fepriv->dvbdev->users==-1);
1943 mutex_lock(&frontend_mutex);
1944 dvb_unregister_device (fepriv->dvbdev);
1946 /* fe is invalid now */
1947 kfree(fepriv);
1948 mutex_unlock(&frontend_mutex);
1949 return 0;
1951 EXPORT_SYMBOL(dvb_unregister_frontend);
1953 #ifdef CONFIG_MEDIA_ATTACH
1954 void dvb_frontend_detach(struct dvb_frontend* fe)
1956 void *ptr;
1958 if (fe->ops.release_sec) {
1959 fe->ops.release_sec(fe);
1960 symbol_put_addr(fe->ops.release_sec);
1962 if (fe->ops.tuner_ops.release) {
1963 fe->ops.tuner_ops.release(fe);
1964 symbol_put_addr(fe->ops.tuner_ops.release);
1966 if (fe->ops.analog_ops.release) {
1967 fe->ops.analog_ops.release(fe);
1968 symbol_put_addr(fe->ops.analog_ops.release);
1970 ptr = (void*)fe->ops.release;
1971 if (ptr) {
1972 fe->ops.release(fe);
1973 symbol_put_addr(ptr);
1976 #else
1977 void dvb_frontend_detach(struct dvb_frontend* fe)
1979 if (fe->ops.release_sec)
1980 fe->ops.release_sec(fe);
1981 if (fe->ops.tuner_ops.release)
1982 fe->ops.tuner_ops.release(fe);
1983 if (fe->ops.analog_ops.release)
1984 fe->ops.analog_ops.release(fe);
1985 if (fe->ops.release)
1986 fe->ops.release(fe);
1988 #endif
1989 EXPORT_SYMBOL(dvb_frontend_detach);