2 * dvb_frontend.c: DVB frontend tuning interface/thread
5 * Copyright (C) 1999-2001 Ralph Metzler
8 * for convergence integrated media GmbH
10 * Copyright (C) 2004 Andrew de Quincey (tuning thread cleanup)
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
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 /* Enables DVBv3 compatibility bits at the headers */
31 #include <linux/string.h>
32 #include <linux/kernel.h>
33 #include <linux/sched.h>
34 #include <linux/wait.h>
35 #include <linux/slab.h>
36 #include <linux/poll.h>
37 #include <linux/semaphore.h>
38 #include <linux/module.h>
39 #include <linux/list.h>
40 #include <linux/freezer.h>
41 #include <linux/jiffies.h>
42 #include <linux/kthread.h>
43 #include <asm/processor.h>
45 #include "dvb_frontend.h"
47 #include <linux/dvb/version.h>
49 static int dvb_frontend_debug
;
50 static int dvb_shutdown_timeout
;
51 static int dvb_force_auto_inversion
;
52 static int dvb_override_tune_delay
;
53 static int dvb_powerdown_on_sleep
= 1;
54 static int dvb_mfe_wait_time
= 5;
56 module_param_named(frontend_debug
, dvb_frontend_debug
, int, 0644);
57 MODULE_PARM_DESC(frontend_debug
, "Turn on/off frontend core debugging (default:off).");
58 module_param(dvb_shutdown_timeout
, int, 0644);
59 MODULE_PARM_DESC(dvb_shutdown_timeout
, "wait <shutdown_timeout> seconds after close() before suspending hardware");
60 module_param(dvb_force_auto_inversion
, int, 0644);
61 MODULE_PARM_DESC(dvb_force_auto_inversion
, "0: normal (default), 1: INVERSION_AUTO forced always");
62 module_param(dvb_override_tune_delay
, int, 0644);
63 MODULE_PARM_DESC(dvb_override_tune_delay
, "0: normal (default), >0 => delay in milliseconds to wait for lock after a tune attempt");
64 module_param(dvb_powerdown_on_sleep
, int, 0644);
65 MODULE_PARM_DESC(dvb_powerdown_on_sleep
, "0: do not power down, 1: turn LNB voltage off on sleep (default)");
66 module_param(dvb_mfe_wait_time
, int, 0644);
67 MODULE_PARM_DESC(dvb_mfe_wait_time
, "Wait up to <mfe_wait_time> seconds on open() for multi-frontend to become available (default:5 seconds)");
69 #define dprintk if (dvb_frontend_debug) printk
71 #define FESTATE_IDLE 1
72 #define FESTATE_RETUNE 2
73 #define FESTATE_TUNING_FAST 4
74 #define FESTATE_TUNING_SLOW 8
75 #define FESTATE_TUNED 16
76 #define FESTATE_ZIGZAG_FAST 32
77 #define FESTATE_ZIGZAG_SLOW 64
78 #define FESTATE_DISEQC 128
79 #define FESTATE_ERROR 256
80 #define FESTATE_WAITFORLOCK (FESTATE_TUNING_FAST | FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW | FESTATE_DISEQC)
81 #define FESTATE_SEARCHING_FAST (FESTATE_TUNING_FAST | FESTATE_ZIGZAG_FAST)
82 #define FESTATE_SEARCHING_SLOW (FESTATE_TUNING_SLOW | FESTATE_ZIGZAG_SLOW)
83 #define FESTATE_LOSTLOCK (FESTATE_ZIGZAG_FAST | FESTATE_ZIGZAG_SLOW)
87 * FESTATE_IDLE. No tuning parameters have been supplied and the loop is idling.
88 * FESTATE_RETUNE. Parameters have been supplied, but we have not yet performed the first tune.
89 * FESTATE_TUNING_FAST. Tuning parameters have been supplied and fast zigzag scan is in progress.
90 * FESTATE_TUNING_SLOW. Tuning parameters have been supplied. Fast zigzag failed, so we're trying again, but slower.
91 * FESTATE_TUNED. The frontend has successfully locked on.
92 * FESTATE_ZIGZAG_FAST. The lock has been lost, and a fast zigzag has been initiated to try and regain it.
93 * FESTATE_ZIGZAG_SLOW. The lock has been lost. Fast zigzag has been failed, so we're trying again, but slower.
94 * FESTATE_DISEQC. A DISEQC command has just been issued.
95 * FESTATE_WAITFORLOCK. When we're waiting for a lock.
96 * FESTATE_SEARCHING_FAST. When we're searching for a signal using a fast zigzag scan.
97 * FESTATE_SEARCHING_SLOW. When we're searching for a signal using a slow zigzag scan.
98 * FESTATE_LOSTLOCK. When the lock has been lost, and we're searching it again.
101 #define DVB_FE_NO_EXIT 0
102 #define DVB_FE_NORMAL_EXIT 1
103 #define DVB_FE_DEVICE_REMOVED 2
105 static DEFINE_MUTEX(frontend_mutex
);
107 struct dvb_frontend_private
{
109 /* thread/frontend values */
110 struct dvb_device
*dvbdev
;
111 struct dvb_frontend_parameters parameters_out
;
112 struct dvb_fe_events events
;
113 struct semaphore sem
;
114 struct list_head list_head
;
115 wait_queue_head_t wait_queue
;
116 struct task_struct
*thread
;
117 unsigned long release_jiffies
;
121 unsigned long tune_mode_flags
;
123 unsigned int reinitialise
;
127 /* swzigzag values */
129 unsigned int bending
;
131 unsigned int inversion
;
132 unsigned int auto_step
;
133 unsigned int auto_sub_step
;
134 unsigned int started_auto_step
;
135 unsigned int min_delay
;
136 unsigned int max_drift
;
137 unsigned int step_size
;
139 unsigned int check_wrapped
;
140 enum dvbfe_search algo_status
;
143 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
);
144 static int dtv_get_frontend(struct dvb_frontend
*fe
,
145 struct dvb_frontend_parameters
*p_out
);
147 static bool has_get_frontend(struct dvb_frontend
*fe
)
149 return fe
->ops
.get_frontend
;
153 * Due to DVBv3 API calls, a delivery system should be mapped into one of
154 * the 4 DVBv3 delivery systems (FE_QPSK, FE_QAM, FE_OFDM or FE_ATSC),
155 * otherwise, a DVBv3 call will fail.
157 enum dvbv3_emulation_type
{
165 static enum dvbv3_emulation_type
dvbv3_type(u32 delivery_system
)
167 switch (delivery_system
) {
168 case SYS_DVBC_ANNEX_A
:
169 case SYS_DVBC_ANNEX_C
:
183 case SYS_DVBC_ANNEX_B
:
192 * Doesn't know how to emulate those types and/or
193 * there's no frontend driver from this type yet
194 * with some emulation code, so, we're not sure yet how
195 * to handle them, or they're not compatible with a DVBv3 call.
197 return DVBV3_UNKNOWN
;
201 static void dvb_frontend_add_event(struct dvb_frontend
*fe
, fe_status_t status
)
203 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
204 struct dvb_fe_events
*events
= &fepriv
->events
;
205 struct dvb_frontend_event
*e
;
208 dprintk ("%s\n", __func__
);
210 if ((status
& FE_HAS_LOCK
) && has_get_frontend(fe
))
211 dtv_get_frontend(fe
, &fepriv
->parameters_out
);
213 mutex_lock(&events
->mtx
);
215 wp
= (events
->eventw
+ 1) % MAX_EVENT
;
216 if (wp
== events
->eventr
) {
217 events
->overflow
= 1;
218 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
221 e
= &events
->events
[events
->eventw
];
223 e
->parameters
= fepriv
->parameters_out
;
227 mutex_unlock(&events
->mtx
);
229 wake_up_interruptible (&events
->wait_queue
);
232 static int dvb_frontend_get_event(struct dvb_frontend
*fe
,
233 struct dvb_frontend_event
*event
, int flags
)
235 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
236 struct dvb_fe_events
*events
= &fepriv
->events
;
238 dprintk ("%s\n", __func__
);
240 if (events
->overflow
) {
241 events
->overflow
= 0;
245 if (events
->eventw
== events
->eventr
) {
248 if (flags
& O_NONBLOCK
)
253 ret
= wait_event_interruptible (events
->wait_queue
,
254 events
->eventw
!= events
->eventr
);
256 if (down_interruptible (&fepriv
->sem
))
263 mutex_lock(&events
->mtx
);
264 *event
= events
->events
[events
->eventr
];
265 events
->eventr
= (events
->eventr
+ 1) % MAX_EVENT
;
266 mutex_unlock(&events
->mtx
);
271 static void dvb_frontend_clear_events(struct dvb_frontend
*fe
)
273 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
274 struct dvb_fe_events
*events
= &fepriv
->events
;
276 mutex_lock(&events
->mtx
);
277 events
->eventr
= events
->eventw
;
278 mutex_unlock(&events
->mtx
);
281 static void dvb_frontend_init(struct dvb_frontend
*fe
)
283 dprintk ("DVB: initialising adapter %i frontend %i (%s)...\n",
290 if (fe
->ops
.tuner_ops
.init
) {
291 if (fe
->ops
.i2c_gate_ctrl
)
292 fe
->ops
.i2c_gate_ctrl(fe
, 1);
293 fe
->ops
.tuner_ops
.init(fe
);
294 if (fe
->ops
.i2c_gate_ctrl
)
295 fe
->ops
.i2c_gate_ctrl(fe
, 0);
299 void dvb_frontend_reinitialise(struct dvb_frontend
*fe
)
301 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
303 fepriv
->reinitialise
= 1;
304 dvb_frontend_wakeup(fe
);
306 EXPORT_SYMBOL(dvb_frontend_reinitialise
);
308 static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private
*fepriv
, int locked
)
312 dprintk ("%s\n", __func__
);
315 (fepriv
->quality
) = (fepriv
->quality
* 220 + 36*256) / 256;
317 (fepriv
->quality
) = (fepriv
->quality
* 220 + 0) / 256;
319 q2
= fepriv
->quality
- 128;
322 fepriv
->delay
= fepriv
->min_delay
+ q2
* HZ
/ (128*128);
326 * Performs automatic twiddling of frontend parameters.
328 * @param fe The frontend concerned.
329 * @param check_wrapped Checks if an iteration has completed. DO NOT SET ON THE FIRST ATTEMPT
330 * @returns Number of complete iterations that have been performed.
332 static int dvb_frontend_swzigzag_autotune(struct dvb_frontend
*fe
, int check_wrapped
)
337 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
338 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
339 int original_inversion
= c
->inversion
;
340 u32 original_frequency
= c
->frequency
;
342 /* are we using autoinversion? */
343 autoinversion
= ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
344 (c
->inversion
== INVERSION_AUTO
));
346 /* setup parameters correctly */
348 /* calculate the lnb_drift */
349 fepriv
->lnb_drift
= fepriv
->auto_step
* fepriv
->step_size
;
351 /* wrap the auto_step if we've exceeded the maximum drift */
352 if (fepriv
->lnb_drift
> fepriv
->max_drift
) {
353 fepriv
->auto_step
= 0;
354 fepriv
->auto_sub_step
= 0;
355 fepriv
->lnb_drift
= 0;
358 /* perform inversion and +/- zigzag */
359 switch(fepriv
->auto_sub_step
) {
361 /* try with the current inversion and current drift setting */
366 if (!autoinversion
) break;
368 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
373 if (fepriv
->lnb_drift
== 0) break;
375 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
380 if (fepriv
->lnb_drift
== 0) break;
381 if (!autoinversion
) break;
383 fepriv
->inversion
= (fepriv
->inversion
== INVERSION_OFF
) ? INVERSION_ON
: INVERSION_OFF
;
384 fepriv
->lnb_drift
= -fepriv
->lnb_drift
;
390 fepriv
->auto_sub_step
= -1; /* it'll be incremented to 0 in a moment */
394 if (!ready
) fepriv
->auto_sub_step
++;
397 /* if this attempt would hit where we started, indicate a complete
398 * iteration has occurred */
399 if ((fepriv
->auto_step
== fepriv
->started_auto_step
) &&
400 (fepriv
->auto_sub_step
== 0) && check_wrapped
) {
404 dprintk("%s: drift:%i inversion:%i auto_step:%i "
405 "auto_sub_step:%i started_auto_step:%i\n",
406 __func__
, fepriv
->lnb_drift
, fepriv
->inversion
,
407 fepriv
->auto_step
, fepriv
->auto_sub_step
, fepriv
->started_auto_step
);
409 /* set the frontend itself */
410 c
->frequency
+= fepriv
->lnb_drift
;
412 c
->inversion
= fepriv
->inversion
;
414 if (fe
->ops
.set_frontend
)
415 fe_set_err
= fe
->ops
.set_frontend(fe
);
417 if (fe_set_err
< 0) {
418 fepriv
->state
= FESTATE_ERROR
;
422 c
->frequency
= original_frequency
;
423 c
->inversion
= original_inversion
;
425 fepriv
->auto_sub_step
++;
429 static void dvb_frontend_swzigzag(struct dvb_frontend
*fe
)
433 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
434 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
, tmp
;
436 /* if we've got no parameters, just keep idling */
437 if (fepriv
->state
& FESTATE_IDLE
) {
438 fepriv
->delay
= 3*HZ
;
443 /* in SCAN mode, we just set the frontend when asked and leave it alone */
444 if (fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
) {
445 if (fepriv
->state
& FESTATE_RETUNE
) {
447 if (fe
->ops
.set_frontend
)
448 retval
= fe
->ops
.set_frontend(fe
);
451 fepriv
->state
= FESTATE_ERROR
;
453 fepriv
->state
= FESTATE_TUNED
;
455 fepriv
->delay
= 3*HZ
;
460 /* get the frontend status */
461 if (fepriv
->state
& FESTATE_RETUNE
) {
464 if (fe
->ops
.read_status
)
465 fe
->ops
.read_status(fe
, &s
);
466 if (s
!= fepriv
->status
) {
467 dvb_frontend_add_event(fe
, s
);
472 /* if we're not tuned, and we have a lock, move to the TUNED state */
473 if ((fepriv
->state
& FESTATE_WAITFORLOCK
) && (s
& FE_HAS_LOCK
)) {
474 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
475 fepriv
->state
= FESTATE_TUNED
;
477 /* if we're tuned, then we have determined the correct inversion */
478 if ((!(fe
->ops
.info
.caps
& FE_CAN_INVERSION_AUTO
)) &&
479 (c
->inversion
== INVERSION_AUTO
)) {
480 c
->inversion
= fepriv
->inversion
;
485 /* if we are tuned already, check we're still locked */
486 if (fepriv
->state
& FESTATE_TUNED
) {
487 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
489 /* we're tuned, and the lock is still good... */
490 if (s
& FE_HAS_LOCK
) {
492 } else { /* if we _WERE_ tuned, but now don't have a lock */
493 fepriv
->state
= FESTATE_ZIGZAG_FAST
;
494 fepriv
->started_auto_step
= fepriv
->auto_step
;
495 fepriv
->check_wrapped
= 0;
499 /* don't actually do anything if we're in the LOSTLOCK state,
500 * the frontend is set to FE_CAN_RECOVER, and the max_drift is 0 */
501 if ((fepriv
->state
& FESTATE_LOSTLOCK
) &&
502 (fe
->ops
.info
.caps
& FE_CAN_RECOVER
) && (fepriv
->max_drift
== 0)) {
503 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
507 /* don't do anything if we're in the DISEQC state, since this
508 * might be someone with a motorized dish controlled by DISEQC.
509 * If its actually a re-tune, there will be a SET_FRONTEND soon enough. */
510 if (fepriv
->state
& FESTATE_DISEQC
) {
511 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
515 /* if we're in the RETUNE state, set everything up for a brand
516 * new scan, keeping the current inversion setting, as the next
517 * tune is _very_ likely to require the same */
518 if (fepriv
->state
& FESTATE_RETUNE
) {
519 fepriv
->lnb_drift
= 0;
520 fepriv
->auto_step
= 0;
521 fepriv
->auto_sub_step
= 0;
522 fepriv
->started_auto_step
= 0;
523 fepriv
->check_wrapped
= 0;
527 if ((fepriv
->state
& FESTATE_SEARCHING_FAST
) || (fepriv
->state
& FESTATE_RETUNE
)) {
528 fepriv
->delay
= fepriv
->min_delay
;
531 retval
= dvb_frontend_swzigzag_autotune(fe
,
532 fepriv
->check_wrapped
);
536 /* OK, if we've run out of trials at the fast speed.
537 * Drop back to slow for the _next_ attempt */
538 fepriv
->state
= FESTATE_SEARCHING_SLOW
;
539 fepriv
->started_auto_step
= fepriv
->auto_step
;
542 fepriv
->check_wrapped
= 1;
544 /* if we've just retuned, enter the ZIGZAG_FAST state.
545 * This ensures we cannot return from an
546 * FE_SET_FRONTEND ioctl before the first frontend tune
548 if (fepriv
->state
& FESTATE_RETUNE
) {
549 fepriv
->state
= FESTATE_TUNING_FAST
;
554 if (fepriv
->state
& FESTATE_SEARCHING_SLOW
) {
555 dvb_frontend_swzigzag_update_delay(fepriv
, s
& FE_HAS_LOCK
);
557 /* Note: don't bother checking for wrapping; we stay in this
558 * state until we get a lock */
559 dvb_frontend_swzigzag_autotune(fe
, 0);
563 static int dvb_frontend_is_exiting(struct dvb_frontend
*fe
)
565 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
567 if (fepriv
->exit
!= DVB_FE_NO_EXIT
)
570 if (fepriv
->dvbdev
->writers
== 1)
571 if (time_after_eq(jiffies
, fepriv
->release_jiffies
+
572 dvb_shutdown_timeout
* HZ
))
578 static int dvb_frontend_should_wakeup(struct dvb_frontend
*fe
)
580 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
582 if (fepriv
->wakeup
) {
586 return dvb_frontend_is_exiting(fe
);
589 static void dvb_frontend_wakeup(struct dvb_frontend
*fe
)
591 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
594 wake_up_interruptible(&fepriv
->wait_queue
);
597 static int dvb_frontend_thread(void *data
)
599 struct dvb_frontend
*fe
= data
;
600 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
602 enum dvbfe_algo algo
;
604 bool re_tune
= false;
606 dprintk("%s\n", __func__
);
608 fepriv
->check_wrapped
= 0;
610 fepriv
->delay
= 3*HZ
;
613 fepriv
->reinitialise
= 0;
615 dvb_frontend_init(fe
);
619 up(&fepriv
->sem
); /* is locked when we enter the thread... */
621 wait_event_interruptible_timeout(fepriv
->wait_queue
,
622 dvb_frontend_should_wakeup(fe
) || kthread_should_stop()
623 || freezing(current
),
626 if (kthread_should_stop() || dvb_frontend_is_exiting(fe
)) {
627 /* got signal or quitting */
628 fepriv
->exit
= DVB_FE_NORMAL_EXIT
;
635 if (down_interruptible(&fepriv
->sem
))
638 if (fepriv
->reinitialise
) {
639 dvb_frontend_init(fe
);
640 if (fe
->ops
.set_tone
&& fepriv
->tone
!= -1)
641 fe
->ops
.set_tone(fe
, fepriv
->tone
);
642 if (fe
->ops
.set_voltage
&& fepriv
->voltage
!= -1)
643 fe
->ops
.set_voltage(fe
, fepriv
->voltage
);
644 fepriv
->reinitialise
= 0;
647 /* do an iteration of the tuning loop */
648 if (fe
->ops
.get_frontend_algo
) {
649 algo
= fe
->ops
.get_frontend_algo(fe
);
652 dprintk("%s: Frontend ALGO = DVBFE_ALGO_HW\n", __func__
);
654 if (fepriv
->state
& FESTATE_RETUNE
) {
655 dprintk("%s: Retune requested, FESTATE_RETUNE\n", __func__
);
657 fepriv
->state
= FESTATE_TUNED
;
661 fe
->ops
.tune(fe
, re_tune
, fepriv
->tune_mode_flags
, &fepriv
->delay
, &s
);
663 if (s
!= fepriv
->status
&& !(fepriv
->tune_mode_flags
& FE_TUNE_MODE_ONESHOT
)) {
664 dprintk("%s: state changed, adding current state\n", __func__
);
665 dvb_frontend_add_event(fe
, s
);
670 dprintk("%s: Frontend ALGO = DVBFE_ALGO_SW\n", __func__
);
671 dvb_frontend_swzigzag(fe
);
673 case DVBFE_ALGO_CUSTOM
:
674 dprintk("%s: Frontend ALGO = DVBFE_ALGO_CUSTOM, state=%d\n", __func__
, fepriv
->state
);
675 if (fepriv
->state
& FESTATE_RETUNE
) {
676 dprintk("%s: Retune requested, FESTAT_RETUNE\n", __func__
);
677 fepriv
->state
= FESTATE_TUNED
;
679 /* Case where we are going to search for a carrier
680 * User asked us to retune again for some reason, possibly
681 * requesting a search with a new set of parameters
683 if (fepriv
->algo_status
& DVBFE_ALGO_SEARCH_AGAIN
) {
684 if (fe
->ops
.search
) {
685 fepriv
->algo_status
= fe
->ops
.search(fe
);
686 /* We did do a search as was requested, the flags are
687 * now unset as well and has the flags wrt to search.
690 fepriv
->algo_status
&= ~DVBFE_ALGO_SEARCH_AGAIN
;
693 /* Track the carrier if the search was successful */
694 if (fepriv
->algo_status
!= DVBFE_ALGO_SEARCH_SUCCESS
) {
695 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
696 fepriv
->delay
= HZ
/ 2;
698 fe
->ops
.read_status(fe
, &s
);
699 if (s
!= fepriv
->status
) {
700 dvb_frontend_add_event(fe
, s
); /* update event list */
702 if (!(s
& FE_HAS_LOCK
)) {
703 fepriv
->delay
= HZ
/ 10;
704 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
706 fepriv
->delay
= 60 * HZ
;
711 dprintk("%s: UNDEFINED ALGO !\n", __func__
);
715 dvb_frontend_swzigzag(fe
);
719 if (dvb_powerdown_on_sleep
) {
720 if (fe
->ops
.set_voltage
)
721 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_OFF
);
722 if (fe
->ops
.tuner_ops
.sleep
) {
723 if (fe
->ops
.i2c_gate_ctrl
)
724 fe
->ops
.i2c_gate_ctrl(fe
, 1);
725 fe
->ops
.tuner_ops
.sleep(fe
);
726 if (fe
->ops
.i2c_gate_ctrl
)
727 fe
->ops
.i2c_gate_ctrl(fe
, 0);
733 fepriv
->thread
= NULL
;
734 if (kthread_should_stop())
735 fepriv
->exit
= DVB_FE_DEVICE_REMOVED
;
737 fepriv
->exit
= DVB_FE_NO_EXIT
;
740 dvb_frontend_wakeup(fe
);
744 static void dvb_frontend_stop(struct dvb_frontend
*fe
)
746 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
748 dprintk ("%s\n", __func__
);
750 fepriv
->exit
= DVB_FE_NORMAL_EXIT
;
756 kthread_stop(fepriv
->thread
);
758 sema_init(&fepriv
->sem
, 1);
759 fepriv
->state
= FESTATE_IDLE
;
761 /* paranoia check in case a signal arrived */
763 printk("dvb_frontend_stop: warning: thread %p won't exit\n",
767 s32
timeval_usec_diff(struct timeval lasttime
, struct timeval curtime
)
769 return ((curtime
.tv_usec
< lasttime
.tv_usec
) ?
770 1000000 - lasttime
.tv_usec
+ curtime
.tv_usec
:
771 curtime
.tv_usec
- lasttime
.tv_usec
);
773 EXPORT_SYMBOL(timeval_usec_diff
);
775 static inline void timeval_usec_add(struct timeval
*curtime
, u32 add_usec
)
777 curtime
->tv_usec
+= add_usec
;
778 if (curtime
->tv_usec
>= 1000000) {
779 curtime
->tv_usec
-= 1000000;
785 * Sleep until gettimeofday() > waketime + add_usec
786 * This needs to be as precise as possible, but as the delay is
787 * usually between 2ms and 32ms, it is done using a scheduled msleep
788 * followed by usleep (normally a busy-wait loop) for the remainder
790 void dvb_frontend_sleep_until(struct timeval
*waketime
, u32 add_usec
)
792 struct timeval lasttime
;
795 timeval_usec_add(waketime
, add_usec
);
797 do_gettimeofday(&lasttime
);
798 delta
= timeval_usec_diff(lasttime
, *waketime
);
800 msleep((delta
- 1500) / 1000);
801 do_gettimeofday(&lasttime
);
802 newdelta
= timeval_usec_diff(lasttime
, *waketime
);
803 delta
= (newdelta
> delta
) ? 0 : newdelta
;
808 EXPORT_SYMBOL(dvb_frontend_sleep_until
);
810 static int dvb_frontend_start(struct dvb_frontend
*fe
)
813 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
814 struct task_struct
*fe_thread
;
816 dprintk ("%s\n", __func__
);
818 if (fepriv
->thread
) {
819 if (fepriv
->exit
== DVB_FE_NO_EXIT
)
822 dvb_frontend_stop (fe
);
825 if (signal_pending(current
))
827 if (down_interruptible (&fepriv
->sem
))
830 fepriv
->state
= FESTATE_IDLE
;
831 fepriv
->exit
= DVB_FE_NO_EXIT
;
832 fepriv
->thread
= NULL
;
835 fe_thread
= kthread_run(dvb_frontend_thread
, fe
,
836 "kdvb-ad-%i-fe-%i", fe
->dvb
->num
,fe
->id
);
837 if (IS_ERR(fe_thread
)) {
838 ret
= PTR_ERR(fe_thread
);
839 printk("dvb_frontend_start: failed to start kthread (%d)\n", ret
);
843 fepriv
->thread
= fe_thread
;
847 static void dvb_frontend_get_frequency_limits(struct dvb_frontend
*fe
,
848 u32
*freq_min
, u32
*freq_max
)
850 *freq_min
= max(fe
->ops
.info
.frequency_min
, fe
->ops
.tuner_ops
.info
.frequency_min
);
852 if (fe
->ops
.info
.frequency_max
== 0)
853 *freq_max
= fe
->ops
.tuner_ops
.info
.frequency_max
;
854 else if (fe
->ops
.tuner_ops
.info
.frequency_max
== 0)
855 *freq_max
= fe
->ops
.info
.frequency_max
;
857 *freq_max
= min(fe
->ops
.info
.frequency_max
, fe
->ops
.tuner_ops
.info
.frequency_max
);
859 if (*freq_min
== 0 || *freq_max
== 0)
860 printk(KERN_WARNING
"DVB: adapter %i frontend %u frequency limits undefined - fix the driver\n",
861 fe
->dvb
->num
,fe
->id
);
864 static int dvb_frontend_check_parameters(struct dvb_frontend
*fe
)
866 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
870 /* range check: frequency */
871 dvb_frontend_get_frequency_limits(fe
, &freq_min
, &freq_max
);
872 if ((freq_min
&& c
->frequency
< freq_min
) ||
873 (freq_max
&& c
->frequency
> freq_max
)) {
874 printk(KERN_WARNING
"DVB: adapter %i frontend %i frequency %u out of range (%u..%u)\n",
875 fe
->dvb
->num
, fe
->id
, c
->frequency
, freq_min
, freq_max
);
879 /* range check: symbol rate */
880 switch (c
->delivery_system
) {
884 case SYS_DVBC_ANNEX_A
:
885 case SYS_DVBC_ANNEX_C
:
886 if ((fe
->ops
.info
.symbol_rate_min
&&
887 c
->symbol_rate
< fe
->ops
.info
.symbol_rate_min
) ||
888 (fe
->ops
.info
.symbol_rate_max
&&
889 c
->symbol_rate
> fe
->ops
.info
.symbol_rate_max
)) {
890 printk(KERN_WARNING
"DVB: adapter %i frontend %i symbol rate %u out of range (%u..%u)\n",
891 fe
->dvb
->num
, fe
->id
, c
->symbol_rate
,
892 fe
->ops
.info
.symbol_rate_min
,
893 fe
->ops
.info
.symbol_rate_max
);
903 static int dvb_frontend_clear_cache(struct dvb_frontend
*fe
)
905 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
908 memset(c
, 0, sizeof(struct dtv_frontend_properties
));
910 c
->state
= DTV_CLEAR
;
912 dprintk("%s() Clearing cache for delivery system %d\n", __func__
,
915 c
->transmission_mode
= TRANSMISSION_MODE_AUTO
;
916 c
->bandwidth_hz
= 0; /* AUTO */
917 c
->guard_interval
= GUARD_INTERVAL_AUTO
;
918 c
->hierarchy
= HIERARCHY_AUTO
;
920 c
->code_rate_HP
= FEC_AUTO
;
921 c
->code_rate_LP
= FEC_AUTO
;
922 c
->fec_inner
= FEC_AUTO
;
923 c
->rolloff
= ROLLOFF_AUTO
;
924 c
->voltage
= SEC_VOLTAGE_OFF
;
925 c
->sectone
= SEC_TONE_OFF
;
926 c
->pilot
= PILOT_AUTO
;
928 c
->isdbt_partial_reception
= 0;
929 c
->isdbt_sb_mode
= 0;
930 c
->isdbt_sb_subchannel
= 0;
931 c
->isdbt_sb_segment_idx
= 0;
932 c
->isdbt_sb_segment_count
= 0;
933 c
->isdbt_layer_enabled
= 0;
934 for (i
= 0; i
< 3; i
++) {
935 c
->layer
[i
].fec
= FEC_AUTO
;
936 c
->layer
[i
].modulation
= QAM_AUTO
;
937 c
->layer
[i
].interleaving
= 0;
938 c
->layer
[i
].segment_count
= 0;
944 switch (c
->delivery_system
) {
948 c
->modulation
= QPSK
; /* implied for DVB-S in legacy API */
949 c
->rolloff
= ROLLOFF_35
;/* implied for DVB-S */
952 c
->modulation
= VSB_8
;
955 c
->modulation
= QAM_AUTO
;
962 #define _DTV_CMD(n, s, b) \
970 static struct dtv_cmds_h dtv_cmds
[DTV_MAX_COMMAND
+ 1] = {
971 _DTV_CMD(DTV_TUNE
, 1, 0),
972 _DTV_CMD(DTV_CLEAR
, 1, 0),
975 _DTV_CMD(DTV_FREQUENCY
, 1, 0),
976 _DTV_CMD(DTV_BANDWIDTH_HZ
, 1, 0),
977 _DTV_CMD(DTV_MODULATION
, 1, 0),
978 _DTV_CMD(DTV_INVERSION
, 1, 0),
979 _DTV_CMD(DTV_DISEQC_MASTER
, 1, 1),
980 _DTV_CMD(DTV_SYMBOL_RATE
, 1, 0),
981 _DTV_CMD(DTV_INNER_FEC
, 1, 0),
982 _DTV_CMD(DTV_VOLTAGE
, 1, 0),
983 _DTV_CMD(DTV_TONE
, 1, 0),
984 _DTV_CMD(DTV_PILOT
, 1, 0),
985 _DTV_CMD(DTV_ROLLOFF
, 1, 0),
986 _DTV_CMD(DTV_DELIVERY_SYSTEM
, 1, 0),
987 _DTV_CMD(DTV_HIERARCHY
, 1, 0),
988 _DTV_CMD(DTV_CODE_RATE_HP
, 1, 0),
989 _DTV_CMD(DTV_CODE_RATE_LP
, 1, 0),
990 _DTV_CMD(DTV_GUARD_INTERVAL
, 1, 0),
991 _DTV_CMD(DTV_TRANSMISSION_MODE
, 1, 0),
993 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION
, 1, 0),
994 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING
, 1, 0),
995 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID
, 1, 0),
996 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX
, 1, 0),
997 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT
, 1, 0),
998 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED
, 1, 0),
999 _DTV_CMD(DTV_ISDBT_LAYERA_FEC
, 1, 0),
1000 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION
, 1, 0),
1001 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT
, 1, 0),
1002 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING
, 1, 0),
1003 _DTV_CMD(DTV_ISDBT_LAYERB_FEC
, 1, 0),
1004 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION
, 1, 0),
1005 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT
, 1, 0),
1006 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING
, 1, 0),
1007 _DTV_CMD(DTV_ISDBT_LAYERC_FEC
, 1, 0),
1008 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION
, 1, 0),
1009 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT
, 1, 0),
1010 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING
, 1, 0),
1012 _DTV_CMD(DTV_ISDBT_PARTIAL_RECEPTION
, 0, 0),
1013 _DTV_CMD(DTV_ISDBT_SOUND_BROADCASTING
, 0, 0),
1014 _DTV_CMD(DTV_ISDBT_SB_SUBCHANNEL_ID
, 0, 0),
1015 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_IDX
, 0, 0),
1016 _DTV_CMD(DTV_ISDBT_SB_SEGMENT_COUNT
, 0, 0),
1017 _DTV_CMD(DTV_ISDBT_LAYER_ENABLED
, 0, 0),
1018 _DTV_CMD(DTV_ISDBT_LAYERA_FEC
, 0, 0),
1019 _DTV_CMD(DTV_ISDBT_LAYERA_MODULATION
, 0, 0),
1020 _DTV_CMD(DTV_ISDBT_LAYERA_SEGMENT_COUNT
, 0, 0),
1021 _DTV_CMD(DTV_ISDBT_LAYERA_TIME_INTERLEAVING
, 0, 0),
1022 _DTV_CMD(DTV_ISDBT_LAYERB_FEC
, 0, 0),
1023 _DTV_CMD(DTV_ISDBT_LAYERB_MODULATION
, 0, 0),
1024 _DTV_CMD(DTV_ISDBT_LAYERB_SEGMENT_COUNT
, 0, 0),
1025 _DTV_CMD(DTV_ISDBT_LAYERB_TIME_INTERLEAVING
, 0, 0),
1026 _DTV_CMD(DTV_ISDBT_LAYERC_FEC
, 0, 0),
1027 _DTV_CMD(DTV_ISDBT_LAYERC_MODULATION
, 0, 0),
1028 _DTV_CMD(DTV_ISDBT_LAYERC_SEGMENT_COUNT
, 0, 0),
1029 _DTV_CMD(DTV_ISDBT_LAYERC_TIME_INTERLEAVING
, 0, 0),
1031 _DTV_CMD(DTV_ISDBS_TS_ID
, 1, 0),
1032 _DTV_CMD(DTV_DVBT2_PLP_ID
, 1, 0),
1035 _DTV_CMD(DTV_DISEQC_SLAVE_REPLY
, 0, 1),
1036 _DTV_CMD(DTV_API_VERSION
, 0, 0),
1037 _DTV_CMD(DTV_CODE_RATE_HP
, 0, 0),
1038 _DTV_CMD(DTV_CODE_RATE_LP
, 0, 0),
1039 _DTV_CMD(DTV_GUARD_INTERVAL
, 0, 0),
1040 _DTV_CMD(DTV_TRANSMISSION_MODE
, 0, 0),
1041 _DTV_CMD(DTV_HIERARCHY
, 0, 0),
1043 _DTV_CMD(DTV_ENUM_DELSYS
, 0, 0),
1046 static void dtv_property_dump(struct dtv_property
*tvp
)
1050 if (tvp
->cmd
<= 0 || tvp
->cmd
> DTV_MAX_COMMAND
) {
1051 printk(KERN_WARNING
"%s: tvp.cmd = 0x%08x undefined\n",
1052 __func__
, tvp
->cmd
);
1056 dprintk("%s() tvp.cmd = 0x%08x (%s)\n"
1059 ,dtv_cmds
[ tvp
->cmd
].name
);
1061 if(dtv_cmds
[ tvp
->cmd
].buffer
) {
1063 dprintk("%s() tvp.u.buffer.len = 0x%02x\n"
1065 ,tvp
->u
.buffer
.len
);
1067 for(i
= 0; i
< tvp
->u
.buffer
.len
; i
++)
1068 dprintk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n"
1071 ,tvp
->u
.buffer
.data
[i
]);
1074 dprintk("%s() tvp.u.data = 0x%08x\n", __func__
, tvp
->u
.data
);
1077 /* Synchronise the legacy tuning parameters into the cache, so that demodulator
1078 * drivers can use a single set_frontend tuning function, regardless of whether
1079 * it's being used for the legacy or new API, reducing code and complexity.
1081 static int dtv_property_cache_sync(struct dvb_frontend
*fe
,
1082 struct dtv_frontend_properties
*c
,
1083 const struct dvb_frontend_parameters
*p
)
1085 c
->frequency
= p
->frequency
;
1086 c
->inversion
= p
->inversion
;
1088 switch (dvbv3_type(c
->delivery_system
)) {
1090 dprintk("%s() Preparing QPSK req\n", __func__
);
1091 c
->symbol_rate
= p
->u
.qpsk
.symbol_rate
;
1092 c
->fec_inner
= p
->u
.qpsk
.fec_inner
;
1095 dprintk("%s() Preparing QAM req\n", __func__
);
1096 c
->symbol_rate
= p
->u
.qam
.symbol_rate
;
1097 c
->fec_inner
= p
->u
.qam
.fec_inner
;
1098 c
->modulation
= p
->u
.qam
.modulation
;
1101 dprintk("%s() Preparing OFDM req\n", __func__
);
1102 switch (p
->u
.ofdm
.bandwidth
) {
1103 case BANDWIDTH_10_MHZ
:
1104 c
->bandwidth_hz
= 10000000;
1106 case BANDWIDTH_8_MHZ
:
1107 c
->bandwidth_hz
= 8000000;
1109 case BANDWIDTH_7_MHZ
:
1110 c
->bandwidth_hz
= 7000000;
1112 case BANDWIDTH_6_MHZ
:
1113 c
->bandwidth_hz
= 6000000;
1115 case BANDWIDTH_5_MHZ
:
1116 c
->bandwidth_hz
= 5000000;
1118 case BANDWIDTH_1_712_MHZ
:
1119 c
->bandwidth_hz
= 1712000;
1121 case BANDWIDTH_AUTO
:
1122 c
->bandwidth_hz
= 0;
1125 c
->code_rate_HP
= p
->u
.ofdm
.code_rate_HP
;
1126 c
->code_rate_LP
= p
->u
.ofdm
.code_rate_LP
;
1127 c
->modulation
= p
->u
.ofdm
.constellation
;
1128 c
->transmission_mode
= p
->u
.ofdm
.transmission_mode
;
1129 c
->guard_interval
= p
->u
.ofdm
.guard_interval
;
1130 c
->hierarchy
= p
->u
.ofdm
.hierarchy_information
;
1133 dprintk("%s() Preparing ATSC req\n", __func__
);
1134 c
->modulation
= p
->u
.vsb
.modulation
;
1135 if ((c
->modulation
== VSB_8
) || (c
->modulation
== VSB_16
))
1136 c
->delivery_system
= SYS_ATSC
;
1138 c
->delivery_system
= SYS_DVBC_ANNEX_B
;
1142 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1143 __func__
, c
->delivery_system
);
1150 /* Ensure the cached values are set correctly in the frontend
1151 * legacy tuning structures, for the advanced tuning API.
1153 static int dtv_property_legacy_params_sync(struct dvb_frontend
*fe
,
1154 struct dvb_frontend_parameters
*p
)
1156 const struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1158 p
->frequency
= c
->frequency
;
1159 p
->inversion
= c
->inversion
;
1161 switch (dvbv3_type(c
->delivery_system
)) {
1164 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1165 __func__
, c
->delivery_system
);
1168 dprintk("%s() Preparing QPSK req\n", __func__
);
1169 p
->u
.qpsk
.symbol_rate
= c
->symbol_rate
;
1170 p
->u
.qpsk
.fec_inner
= c
->fec_inner
;
1173 dprintk("%s() Preparing QAM req\n", __func__
);
1174 p
->u
.qam
.symbol_rate
= c
->symbol_rate
;
1175 p
->u
.qam
.fec_inner
= c
->fec_inner
;
1176 p
->u
.qam
.modulation
= c
->modulation
;
1179 dprintk("%s() Preparing OFDM req\n", __func__
);
1181 switch (c
->bandwidth_hz
) {
1183 p
->u
.ofdm
.bandwidth
= BANDWIDTH_10_MHZ
;
1186 p
->u
.ofdm
.bandwidth
= BANDWIDTH_8_MHZ
;
1189 p
->u
.ofdm
.bandwidth
= BANDWIDTH_7_MHZ
;
1192 p
->u
.ofdm
.bandwidth
= BANDWIDTH_6_MHZ
;
1195 p
->u
.ofdm
.bandwidth
= BANDWIDTH_5_MHZ
;
1198 p
->u
.ofdm
.bandwidth
= BANDWIDTH_1_712_MHZ
;
1202 p
->u
.ofdm
.bandwidth
= BANDWIDTH_AUTO
;
1204 p
->u
.ofdm
.code_rate_HP
= c
->code_rate_HP
;
1205 p
->u
.ofdm
.code_rate_LP
= c
->code_rate_LP
;
1206 p
->u
.ofdm
.constellation
= c
->modulation
;
1207 p
->u
.ofdm
.transmission_mode
= c
->transmission_mode
;
1208 p
->u
.ofdm
.guard_interval
= c
->guard_interval
;
1209 p
->u
.ofdm
.hierarchy_information
= c
->hierarchy
;
1212 dprintk("%s() Preparing VSB req\n", __func__
);
1213 p
->u
.vsb
.modulation
= c
->modulation
;
1220 * dtv_get_frontend - calls a callback for retrieving DTV parameters
1221 * @fe: struct dvb_frontend pointer
1222 * @c: struct dtv_frontend_properties pointer (DVBv5 cache)
1223 * @p_out struct dvb_frontend_parameters pointer (DVBv3 FE struct)
1225 * This routine calls either the DVBv3 or DVBv5 get_frontend call.
1226 * If c is not null, it will update the DVBv5 cache struct pointed by it.
1227 * If p_out is not null, it will update the DVBv3 params pointed by it.
1229 static int dtv_get_frontend(struct dvb_frontend
*fe
,
1230 struct dvb_frontend_parameters
*p_out
)
1234 if (fe
->ops
.get_frontend
) {
1235 r
= fe
->ops
.get_frontend(fe
);
1236 if (unlikely(r
< 0))
1239 dtv_property_legacy_params_sync(fe
, p_out
);
1243 /* As everything is in cache, get_frontend fops are always supported */
1247 static int dvb_frontend_ioctl_legacy(struct file
*file
,
1248 unsigned int cmd
, void *parg
);
1249 static int dvb_frontend_ioctl_properties(struct file
*file
,
1250 unsigned int cmd
, void *parg
);
1252 static int dtv_property_process_get(struct dvb_frontend
*fe
,
1253 const struct dtv_frontend_properties
*c
,
1254 struct dtv_property
*tvp
,
1260 case DTV_ENUM_DELSYS
:
1262 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1263 tvp
->u
.buffer
.data
[ncaps
] = fe
->ops
.delsys
[ncaps
];
1266 tvp
->u
.buffer
.len
= ncaps
;
1269 tvp
->u
.data
= c
->frequency
;
1271 case DTV_MODULATION
:
1272 tvp
->u
.data
= c
->modulation
;
1274 case DTV_BANDWIDTH_HZ
:
1275 tvp
->u
.data
= c
->bandwidth_hz
;
1278 tvp
->u
.data
= c
->inversion
;
1280 case DTV_SYMBOL_RATE
:
1281 tvp
->u
.data
= c
->symbol_rate
;
1284 tvp
->u
.data
= c
->fec_inner
;
1287 tvp
->u
.data
= c
->pilot
;
1290 tvp
->u
.data
= c
->rolloff
;
1292 case DTV_DELIVERY_SYSTEM
:
1293 tvp
->u
.data
= c
->delivery_system
;
1296 tvp
->u
.data
= c
->voltage
;
1299 tvp
->u
.data
= c
->sectone
;
1301 case DTV_API_VERSION
:
1302 tvp
->u
.data
= (DVB_API_VERSION
<< 8) | DVB_API_VERSION_MINOR
;
1304 case DTV_CODE_RATE_HP
:
1305 tvp
->u
.data
= c
->code_rate_HP
;
1307 case DTV_CODE_RATE_LP
:
1308 tvp
->u
.data
= c
->code_rate_LP
;
1310 case DTV_GUARD_INTERVAL
:
1311 tvp
->u
.data
= c
->guard_interval
;
1313 case DTV_TRANSMISSION_MODE
:
1314 tvp
->u
.data
= c
->transmission_mode
;
1317 tvp
->u
.data
= c
->hierarchy
;
1320 /* ISDB-T Support here */
1321 case DTV_ISDBT_PARTIAL_RECEPTION
:
1322 tvp
->u
.data
= c
->isdbt_partial_reception
;
1324 case DTV_ISDBT_SOUND_BROADCASTING
:
1325 tvp
->u
.data
= c
->isdbt_sb_mode
;
1327 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1328 tvp
->u
.data
= c
->isdbt_sb_subchannel
;
1330 case DTV_ISDBT_SB_SEGMENT_IDX
:
1331 tvp
->u
.data
= c
->isdbt_sb_segment_idx
;
1333 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1334 tvp
->u
.data
= c
->isdbt_sb_segment_count
;
1336 case DTV_ISDBT_LAYER_ENABLED
:
1337 tvp
->u
.data
= c
->isdbt_layer_enabled
;
1339 case DTV_ISDBT_LAYERA_FEC
:
1340 tvp
->u
.data
= c
->layer
[0].fec
;
1342 case DTV_ISDBT_LAYERA_MODULATION
:
1343 tvp
->u
.data
= c
->layer
[0].modulation
;
1345 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1346 tvp
->u
.data
= c
->layer
[0].segment_count
;
1348 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1349 tvp
->u
.data
= c
->layer
[0].interleaving
;
1351 case DTV_ISDBT_LAYERB_FEC
:
1352 tvp
->u
.data
= c
->layer
[1].fec
;
1354 case DTV_ISDBT_LAYERB_MODULATION
:
1355 tvp
->u
.data
= c
->layer
[1].modulation
;
1357 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1358 tvp
->u
.data
= c
->layer
[1].segment_count
;
1360 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1361 tvp
->u
.data
= c
->layer
[1].interleaving
;
1363 case DTV_ISDBT_LAYERC_FEC
:
1364 tvp
->u
.data
= c
->layer
[2].fec
;
1366 case DTV_ISDBT_LAYERC_MODULATION
:
1367 tvp
->u
.data
= c
->layer
[2].modulation
;
1369 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1370 tvp
->u
.data
= c
->layer
[2].segment_count
;
1372 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1373 tvp
->u
.data
= c
->layer
[2].interleaving
;
1375 case DTV_ISDBS_TS_ID
:
1376 tvp
->u
.data
= c
->isdbs_ts_id
;
1378 case DTV_DVBT2_PLP_ID
:
1379 tvp
->u
.data
= c
->dvbt2_plp_id
;
1385 /* Allow the frontend to override outgoing properties */
1386 if (fe
->ops
.get_property
) {
1387 r
= fe
->ops
.get_property(fe
, tvp
);
1392 dtv_property_dump(tvp
);
1397 static int dtv_set_frontend(struct dvb_frontend
*fe
);
1399 static bool is_dvbv3_delsys(u32 delsys
)
1403 status
= (delsys
== SYS_DVBT
) || (delsys
== SYS_DVBC_ANNEX_A
) ||
1404 (delsys
== SYS_DVBS
) || (delsys
== SYS_ATSC
);
1409 static int set_delivery_system(struct dvb_frontend
*fe
, u32 desired_system
)
1412 u32 delsys
= SYS_UNDEFINED
;
1413 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1414 enum dvbv3_emulation_type type
;
1417 * It was reported that some old DVBv5 applications were
1418 * filling delivery_system with SYS_UNDEFINED. If this happens,
1419 * assume that the application wants to use the first supported
1422 if (c
->delivery_system
== SYS_UNDEFINED
)
1423 c
->delivery_system
= fe
->ops
.delsys
[0];
1425 if (desired_system
== SYS_UNDEFINED
) {
1427 * A DVBv3 call doesn't know what's the desired system.
1428 * Also, DVBv3 applications don't know that ops.info->type
1429 * could be changed, and they simply dies when it doesn't
1431 * So, don't change the current delivery system, as it
1432 * may be trying to do the wrong thing, like setting an
1433 * ISDB-T frontend as DVB-T. Instead, find the closest
1434 * DVBv3 system that matches the delivery system.
1436 if (is_dvbv3_delsys(c
->delivery_system
)) {
1437 dprintk("%s() Using delivery system to %d\n",
1438 __func__
, c
->delivery_system
);
1441 type
= dvbv3_type(c
->delivery_system
);
1444 desired_system
= SYS_DVBS
;
1447 desired_system
= SYS_DVBC_ANNEX_A
;
1450 desired_system
= SYS_ATSC
;
1453 desired_system
= SYS_DVBT
;
1456 dprintk("%s(): This frontend doesn't support DVBv3 calls\n",
1462 * This is a DVBv5 call. So, it likely knows the supported
1466 /* Check if the desired delivery system is supported */
1468 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1469 if (fe
->ops
.delsys
[ncaps
] == desired_system
) {
1470 c
->delivery_system
= desired_system
;
1471 dprintk("%s() Changing delivery system to %d\n",
1472 __func__
, desired_system
);
1477 type
= dvbv3_type(desired_system
);
1480 * The delivery system is not supported. See if it can be
1482 * The emulation only works if the desired system is one of the
1483 * DVBv3 delivery systems
1485 if (!is_dvbv3_delsys(desired_system
)) {
1486 dprintk("%s() can't use a DVBv3 FE_SET_FRONTEND call on this frontend\n",
1492 * Get the last non-DVBv3 delivery system that has the same type
1493 * of the desired system
1496 while (fe
->ops
.delsys
[ncaps
] && ncaps
< MAX_DELSYS
) {
1497 if ((dvbv3_type(fe
->ops
.delsys
[ncaps
]) == type
) &&
1498 !is_dvbv3_delsys(fe
->ops
.delsys
[ncaps
]))
1499 delsys
= fe
->ops
.delsys
[ncaps
];
1502 /* There's nothing compatible with the desired delivery system */
1503 if (delsys
== SYS_UNDEFINED
) {
1504 dprintk("%s() Incompatible DVBv3 FE_SET_FRONTEND call for this frontend\n",
1508 c
->delivery_system
= delsys
;
1512 * The DVBv3 or DVBv5 call is requesting a different system. So,
1513 * emulation is needed.
1515 * Emulate newer delivery systems like ISDBT, DVBT and DMBTH
1516 * for older DVBv5 applications. The emulation will try to use
1517 * the auto mode for most things, and will assume that the desired
1518 * delivery system is the last one at the ops.delsys[] array
1520 dprintk("%s() Using delivery system %d emulated as if it were a %d\n",
1521 __func__
, delsys
, desired_system
);
1524 * For now, handles ISDB-T calls. More code may be needed here for the
1525 * other emulated stuff
1527 if (type
== DVBV3_OFDM
) {
1528 if (c
->delivery_system
== SYS_ISDBT
) {
1529 dprintk("%s() Using defaults for SYS_ISDBT\n",
1531 if (!c
->bandwidth_hz
)
1532 c
->bandwidth_hz
= 6000000;
1534 c
->isdbt_partial_reception
= 0;
1535 c
->isdbt_sb_mode
= 0;
1536 c
->isdbt_sb_subchannel
= 0;
1537 c
->isdbt_sb_segment_idx
= 0;
1538 c
->isdbt_sb_segment_count
= 0;
1539 c
->isdbt_layer_enabled
= 0;
1540 for (i
= 0; i
< 3; i
++) {
1541 c
->layer
[i
].fec
= FEC_AUTO
;
1542 c
->layer
[i
].modulation
= QAM_AUTO
;
1543 c
->layer
[i
].interleaving
= 0;
1544 c
->layer
[i
].segment_count
= 0;
1548 dprintk("change delivery system on cache to %d\n", c
->delivery_system
);
1553 static int dtv_property_process_set(struct dvb_frontend
*fe
,
1554 struct dtv_property
*tvp
,
1558 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1560 /* Allow the frontend to validate incoming properties */
1561 if (fe
->ops
.set_property
) {
1562 r
= fe
->ops
.set_property(fe
, tvp
);
1570 * Reset a cache of data specific to the frontend here. This does
1571 * not effect hardware.
1573 dvb_frontend_clear_cache(fe
);
1576 /* interpret the cache of data, build either a traditional frontend
1577 * tunerequest so we can pass validation in the FE_SET_FRONTEND
1580 c
->state
= tvp
->cmd
;
1581 dprintk("%s() Finalised property cache\n", __func__
);
1583 r
= dtv_set_frontend(fe
);
1586 c
->frequency
= tvp
->u
.data
;
1588 case DTV_MODULATION
:
1589 c
->modulation
= tvp
->u
.data
;
1591 case DTV_BANDWIDTH_HZ
:
1592 c
->bandwidth_hz
= tvp
->u
.data
;
1595 c
->inversion
= tvp
->u
.data
;
1597 case DTV_SYMBOL_RATE
:
1598 c
->symbol_rate
= tvp
->u
.data
;
1601 c
->fec_inner
= tvp
->u
.data
;
1604 c
->pilot
= tvp
->u
.data
;
1607 c
->rolloff
= tvp
->u
.data
;
1609 case DTV_DELIVERY_SYSTEM
:
1610 r
= set_delivery_system(fe
, tvp
->u
.data
);
1613 c
->voltage
= tvp
->u
.data
;
1614 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_VOLTAGE
,
1615 (void *)c
->voltage
);
1618 c
->sectone
= tvp
->u
.data
;
1619 r
= dvb_frontend_ioctl_legacy(file
, FE_SET_TONE
,
1620 (void *)c
->sectone
);
1622 case DTV_CODE_RATE_HP
:
1623 c
->code_rate_HP
= tvp
->u
.data
;
1625 case DTV_CODE_RATE_LP
:
1626 c
->code_rate_LP
= tvp
->u
.data
;
1628 case DTV_GUARD_INTERVAL
:
1629 c
->guard_interval
= tvp
->u
.data
;
1631 case DTV_TRANSMISSION_MODE
:
1632 c
->transmission_mode
= tvp
->u
.data
;
1635 c
->hierarchy
= tvp
->u
.data
;
1638 /* ISDB-T Support here */
1639 case DTV_ISDBT_PARTIAL_RECEPTION
:
1640 c
->isdbt_partial_reception
= tvp
->u
.data
;
1642 case DTV_ISDBT_SOUND_BROADCASTING
:
1643 c
->isdbt_sb_mode
= tvp
->u
.data
;
1645 case DTV_ISDBT_SB_SUBCHANNEL_ID
:
1646 c
->isdbt_sb_subchannel
= tvp
->u
.data
;
1648 case DTV_ISDBT_SB_SEGMENT_IDX
:
1649 c
->isdbt_sb_segment_idx
= tvp
->u
.data
;
1651 case DTV_ISDBT_SB_SEGMENT_COUNT
:
1652 c
->isdbt_sb_segment_count
= tvp
->u
.data
;
1654 case DTV_ISDBT_LAYER_ENABLED
:
1655 c
->isdbt_layer_enabled
= tvp
->u
.data
;
1657 case DTV_ISDBT_LAYERA_FEC
:
1658 c
->layer
[0].fec
= tvp
->u
.data
;
1660 case DTV_ISDBT_LAYERA_MODULATION
:
1661 c
->layer
[0].modulation
= tvp
->u
.data
;
1663 case DTV_ISDBT_LAYERA_SEGMENT_COUNT
:
1664 c
->layer
[0].segment_count
= tvp
->u
.data
;
1666 case DTV_ISDBT_LAYERA_TIME_INTERLEAVING
:
1667 c
->layer
[0].interleaving
= tvp
->u
.data
;
1669 case DTV_ISDBT_LAYERB_FEC
:
1670 c
->layer
[1].fec
= tvp
->u
.data
;
1672 case DTV_ISDBT_LAYERB_MODULATION
:
1673 c
->layer
[1].modulation
= tvp
->u
.data
;
1675 case DTV_ISDBT_LAYERB_SEGMENT_COUNT
:
1676 c
->layer
[1].segment_count
= tvp
->u
.data
;
1678 case DTV_ISDBT_LAYERB_TIME_INTERLEAVING
:
1679 c
->layer
[1].interleaving
= tvp
->u
.data
;
1681 case DTV_ISDBT_LAYERC_FEC
:
1682 c
->layer
[2].fec
= tvp
->u
.data
;
1684 case DTV_ISDBT_LAYERC_MODULATION
:
1685 c
->layer
[2].modulation
= tvp
->u
.data
;
1687 case DTV_ISDBT_LAYERC_SEGMENT_COUNT
:
1688 c
->layer
[2].segment_count
= tvp
->u
.data
;
1690 case DTV_ISDBT_LAYERC_TIME_INTERLEAVING
:
1691 c
->layer
[2].interleaving
= tvp
->u
.data
;
1693 case DTV_ISDBS_TS_ID
:
1694 c
->isdbs_ts_id
= tvp
->u
.data
;
1696 case DTV_DVBT2_PLP_ID
:
1697 c
->dvbt2_plp_id
= tvp
->u
.data
;
1706 static int dvb_frontend_ioctl(struct file
*file
,
1707 unsigned int cmd
, void *parg
)
1709 struct dvb_device
*dvbdev
= file
->private_data
;
1710 struct dvb_frontend
*fe
= dvbdev
->priv
;
1711 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1712 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1713 int err
= -EOPNOTSUPP
;
1715 dprintk("%s (%d)\n", __func__
, _IOC_NR(cmd
));
1717 if (fepriv
->exit
!= DVB_FE_NO_EXIT
)
1720 if ((file
->f_flags
& O_ACCMODE
) == O_RDONLY
&&
1721 (_IOC_DIR(cmd
) != _IOC_READ
|| cmd
== FE_GET_EVENT
||
1722 cmd
== FE_DISEQC_RECV_SLAVE_REPLY
))
1725 if (down_interruptible (&fepriv
->sem
))
1726 return -ERESTARTSYS
;
1728 if ((cmd
== FE_SET_PROPERTY
) || (cmd
== FE_GET_PROPERTY
))
1729 err
= dvb_frontend_ioctl_properties(file
, cmd
, parg
);
1731 c
->state
= DTV_UNDEFINED
;
1732 err
= dvb_frontend_ioctl_legacy(file
, cmd
, parg
);
1739 static int dvb_frontend_ioctl_properties(struct file
*file
,
1740 unsigned int cmd
, void *parg
)
1742 struct dvb_device
*dvbdev
= file
->private_data
;
1743 struct dvb_frontend
*fe
= dvbdev
->priv
;
1744 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1747 struct dtv_properties
*tvps
= NULL
;
1748 struct dtv_property
*tvp
= NULL
;
1751 dprintk("%s\n", __func__
);
1753 if(cmd
== FE_SET_PROPERTY
) {
1754 tvps
= (struct dtv_properties __user
*)parg
;
1756 dprintk("%s() properties.num = %d\n", __func__
, tvps
->num
);
1757 dprintk("%s() properties.props = %p\n", __func__
, tvps
->props
);
1759 /* Put an arbitrary limit on the number of messages that can
1760 * be sent at once */
1761 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
1764 tvp
= kmalloc(tvps
->num
* sizeof(struct dtv_property
), GFP_KERNEL
);
1770 if (copy_from_user(tvp
, tvps
->props
, tvps
->num
* sizeof(struct dtv_property
))) {
1775 for (i
= 0; i
< tvps
->num
; i
++) {
1776 err
= dtv_property_process_set(fe
, tvp
+ i
, file
);
1779 (tvp
+ i
)->result
= err
;
1782 if (c
->state
== DTV_TUNE
)
1783 dprintk("%s() Property cache is full, tuning\n", __func__
);
1786 if(cmd
== FE_GET_PROPERTY
) {
1787 tvps
= (struct dtv_properties __user
*)parg
;
1789 dprintk("%s() properties.num = %d\n", __func__
, tvps
->num
);
1790 dprintk("%s() properties.props = %p\n", __func__
, tvps
->props
);
1792 /* Put an arbitrary limit on the number of messages that can
1793 * be sent at once */
1794 if ((tvps
->num
== 0) || (tvps
->num
> DTV_IOCTL_MAX_MSGS
))
1797 tvp
= kmalloc(tvps
->num
* sizeof(struct dtv_property
), GFP_KERNEL
);
1803 if (copy_from_user(tvp
, tvps
->props
, tvps
->num
* sizeof(struct dtv_property
))) {
1809 * Fills the cache out struct with the cache contents, plus
1810 * the data retrieved from get_frontend.
1812 dtv_get_frontend(fe
, NULL
);
1813 for (i
= 0; i
< tvps
->num
; i
++) {
1814 err
= dtv_property_process_get(fe
, c
, tvp
+ i
, file
);
1817 (tvp
+ i
)->result
= err
;
1820 if (copy_to_user(tvps
->props
, tvp
, tvps
->num
* sizeof(struct dtv_property
))) {
1833 static int dtv_set_frontend(struct dvb_frontend
*fe
)
1835 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1836 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1837 struct dvb_frontend_tune_settings fetunesettings
;
1840 if (dvb_frontend_check_parameters(fe
) < 0)
1844 * Be sure that the bandwidth will be filled for all
1845 * non-satellite systems, as tuners need to know what
1846 * low pass/Nyquist half filter should be applied, in
1847 * order to avoid inter-channel noise.
1849 * ISDB-T and DVB-T/T2 already sets bandwidth.
1850 * ATSC and DVB-C don't set, so, the core should fill it.
1852 * On DVB-C Annex A and C, the bandwidth is a function of
1853 * the roll-off and symbol rate. Annex B defines different
1854 * roll-off factors depending on the modulation. Fortunately,
1855 * Annex B is only used with 6MHz, so there's no need to
1858 * While not officially supported, a side effect of handling it at
1859 * the cache level is that a program could retrieve the bandwidth
1860 * via DTV_BANDWIDTH_HZ, which may be useful for test programs.
1862 switch (c
->delivery_system
) {
1864 case SYS_DVBC_ANNEX_B
:
1865 c
->bandwidth_hz
= 6000000;
1867 case SYS_DVBC_ANNEX_A
:
1870 case SYS_DVBC_ANNEX_C
:
1877 c
->bandwidth_hz
= (c
->symbol_rate
* rolloff
) / 100;
1879 /* force auto frequency inversion if requested */
1880 if (dvb_force_auto_inversion
)
1881 c
->inversion
= INVERSION_AUTO
;
1884 * without hierarchical coding code_rate_LP is irrelevant,
1885 * so we tolerate the otherwise invalid FEC_NONE setting
1887 if (c
->hierarchy
== HIERARCHY_NONE
&& c
->code_rate_LP
== FEC_NONE
)
1888 c
->code_rate_LP
= FEC_AUTO
;
1890 /* get frontend-specific tuning settings */
1891 memset(&fetunesettings
, 0, sizeof(struct dvb_frontend_tune_settings
));
1892 if (fe
->ops
.get_tune_settings
&& (fe
->ops
.get_tune_settings(fe
, &fetunesettings
) == 0)) {
1893 fepriv
->min_delay
= (fetunesettings
.min_delay_ms
* HZ
) / 1000;
1894 fepriv
->max_drift
= fetunesettings
.max_drift
;
1895 fepriv
->step_size
= fetunesettings
.step_size
;
1897 /* default values */
1898 switch (c
->delivery_system
) {
1899 case SYS_DVBC_ANNEX_A
:
1900 case SYS_DVBC_ANNEX_C
:
1901 fepriv
->min_delay
= HZ
/ 20;
1902 fepriv
->step_size
= c
->symbol_rate
/ 16000;
1903 fepriv
->max_drift
= c
->symbol_rate
/ 2000;
1909 fepriv
->min_delay
= HZ
/ 20;
1910 fepriv
->step_size
= fe
->ops
.info
.frequency_stepsize
* 2;
1911 fepriv
->max_drift
= (fe
->ops
.info
.frequency_stepsize
* 2) + 1;
1915 * FIXME: This sounds wrong! if freqency_stepsize is
1916 * defined by the frontend, why not use it???
1918 fepriv
->min_delay
= HZ
/ 20;
1919 fepriv
->step_size
= 0; /* no zigzag */
1920 fepriv
->max_drift
= 0;
1924 if (dvb_override_tune_delay
> 0)
1925 fepriv
->min_delay
= (dvb_override_tune_delay
* HZ
) / 1000;
1927 fepriv
->state
= FESTATE_RETUNE
;
1929 /* Request the search algorithm to search */
1930 fepriv
->algo_status
|= DVBFE_ALGO_SEARCH_AGAIN
;
1932 dvb_frontend_clear_events(fe
);
1933 dvb_frontend_add_event(fe
, 0);
1934 dvb_frontend_wakeup(fe
);
1941 static int dvb_frontend_ioctl_legacy(struct file
*file
,
1942 unsigned int cmd
, void *parg
)
1944 struct dvb_device
*dvbdev
= file
->private_data
;
1945 struct dvb_frontend
*fe
= dvbdev
->priv
;
1946 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
1947 struct dtv_frontend_properties
*c
= &fe
->dtv_property_cache
;
1948 int cb_err
, err
= -EOPNOTSUPP
;
1950 if (fe
->dvb
->fe_ioctl_override
) {
1951 cb_err
= fe
->dvb
->fe_ioctl_override(fe
, cmd
, parg
,
1957 /* fe_ioctl_override returning 0 allows
1958 * dvb-core to continue handling the ioctl */
1963 struct dvb_frontend_info
* info
= parg
;
1965 memcpy(info
, &fe
->ops
.info
, sizeof(struct dvb_frontend_info
));
1966 dvb_frontend_get_frequency_limits(fe
, &info
->frequency_min
, &info
->frequency_max
);
1969 * Associate the 4 delivery systems supported by DVBv3
1970 * API with their DVBv5 counterpart. For the other standards,
1971 * use the closest type, assuming that it would hopefully
1972 * work with a DVBv3 application.
1973 * It should be noticed that, on multi-frontend devices with
1974 * different types (terrestrial and cable, for example),
1975 * a pure DVBv3 application won't be able to use all delivery
1976 * systems. Yet, changing the DVBv5 cache to the other delivery
1977 * system should be enough for making it work.
1979 switch (dvbv3_type(c
->delivery_system
)) {
1981 info
->type
= FE_QPSK
;
1984 info
->type
= FE_ATSC
;
1987 info
->type
= FE_QAM
;
1990 info
->type
= FE_OFDM
;
1994 "%s: doesn't know how to handle a DVBv3 call to delivery system %i\n",
1995 __func__
, c
->delivery_system
);
1996 fe
->ops
.info
.type
= FE_OFDM
;
1998 dprintk("current delivery system on cache: %d, V3 type: %d\n",
1999 c
->delivery_system
, fe
->ops
.info
.type
);
2001 /* Force the CAN_INVERSION_AUTO bit on. If the frontend doesn't
2002 * do it, it is done for it. */
2003 info
->caps
|= FE_CAN_INVERSION_AUTO
;
2008 case FE_READ_STATUS
: {
2009 fe_status_t
* status
= parg
;
2011 /* if retune was requested but hasn't occurred yet, prevent
2012 * that user get signal state from previous tuning */
2013 if (fepriv
->state
== FESTATE_RETUNE
||
2014 fepriv
->state
== FESTATE_ERROR
) {
2020 if (fe
->ops
.read_status
)
2021 err
= fe
->ops
.read_status(fe
, status
);
2025 if (fe
->ops
.read_ber
)
2026 err
= fe
->ops
.read_ber(fe
, (__u32
*) parg
);
2029 case FE_READ_SIGNAL_STRENGTH
:
2030 if (fe
->ops
.read_signal_strength
)
2031 err
= fe
->ops
.read_signal_strength(fe
, (__u16
*) parg
);
2035 if (fe
->ops
.read_snr
)
2036 err
= fe
->ops
.read_snr(fe
, (__u16
*) parg
);
2039 case FE_READ_UNCORRECTED_BLOCKS
:
2040 if (fe
->ops
.read_ucblocks
)
2041 err
= fe
->ops
.read_ucblocks(fe
, (__u32
*) parg
);
2045 case FE_DISEQC_RESET_OVERLOAD
:
2046 if (fe
->ops
.diseqc_reset_overload
) {
2047 err
= fe
->ops
.diseqc_reset_overload(fe
);
2048 fepriv
->state
= FESTATE_DISEQC
;
2053 case FE_DISEQC_SEND_MASTER_CMD
:
2054 if (fe
->ops
.diseqc_send_master_cmd
) {
2055 err
= fe
->ops
.diseqc_send_master_cmd(fe
, (struct dvb_diseqc_master_cmd
*) parg
);
2056 fepriv
->state
= FESTATE_DISEQC
;
2061 case FE_DISEQC_SEND_BURST
:
2062 if (fe
->ops
.diseqc_send_burst
) {
2063 err
= fe
->ops
.diseqc_send_burst(fe
, (fe_sec_mini_cmd_t
) parg
);
2064 fepriv
->state
= FESTATE_DISEQC
;
2070 if (fe
->ops
.set_tone
) {
2071 err
= fe
->ops
.set_tone(fe
, (fe_sec_tone_mode_t
) parg
);
2072 fepriv
->tone
= (fe_sec_tone_mode_t
) parg
;
2073 fepriv
->state
= FESTATE_DISEQC
;
2078 case FE_SET_VOLTAGE
:
2079 if (fe
->ops
.set_voltage
) {
2080 err
= fe
->ops
.set_voltage(fe
, (fe_sec_voltage_t
) parg
);
2081 fepriv
->voltage
= (fe_sec_voltage_t
) parg
;
2082 fepriv
->state
= FESTATE_DISEQC
;
2087 case FE_DISHNETWORK_SEND_LEGACY_CMD
:
2088 if (fe
->ops
.dishnetwork_send_legacy_command
) {
2089 err
= fe
->ops
.dishnetwork_send_legacy_command(fe
, (unsigned long) parg
);
2090 fepriv
->state
= FESTATE_DISEQC
;
2092 } else if (fe
->ops
.set_voltage
) {
2094 * NOTE: This is a fallback condition. Some frontends
2095 * (stv0299 for instance) take longer than 8msec to
2096 * respond to a set_voltage command. Those switches
2097 * need custom routines to switch properly. For all
2098 * other frontends, the following should work ok.
2099 * Dish network legacy switches (as used by Dish500)
2100 * are controlled by sending 9-bit command words
2101 * spaced 8msec apart.
2102 * the actual command word is switch/port dependent
2103 * so it is up to the userspace application to send
2104 * the right command.
2105 * The command must always start with a '0' after
2106 * initialization, so parg is 8 bits and does not
2107 * include the initialization or start bit
2109 unsigned long swcmd
= ((unsigned long) parg
) << 1;
2110 struct timeval nexttime
;
2111 struct timeval tv
[10];
2114 if (dvb_frontend_debug
)
2115 printk("%s switch command: 0x%04lx\n", __func__
, swcmd
);
2116 do_gettimeofday(&nexttime
);
2117 if (dvb_frontend_debug
)
2118 memcpy(&tv
[0], &nexttime
, sizeof(struct timeval
));
2119 /* before sending a command, initialize by sending
2120 * a 32ms 18V to the switch
2122 fe
->ops
.set_voltage(fe
, SEC_VOLTAGE_18
);
2123 dvb_frontend_sleep_until(&nexttime
, 32000);
2125 for (i
= 0; i
< 9; i
++) {
2126 if (dvb_frontend_debug
)
2127 do_gettimeofday(&tv
[i
+ 1]);
2128 if ((swcmd
& 0x01) != last
) {
2129 /* set voltage to (last ? 13V : 18V) */
2130 fe
->ops
.set_voltage(fe
, (last
) ? SEC_VOLTAGE_13
: SEC_VOLTAGE_18
);
2131 last
= (last
) ? 0 : 1;
2135 dvb_frontend_sleep_until(&nexttime
, 8000);
2137 if (dvb_frontend_debug
) {
2138 printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
2139 __func__
, fe
->dvb
->num
);
2140 for (i
= 1; i
< 10; i
++)
2141 printk("%d: %d\n", i
, timeval_usec_diff(tv
[i
-1] , tv
[i
]));
2144 fepriv
->state
= FESTATE_DISEQC
;
2149 case FE_DISEQC_RECV_SLAVE_REPLY
:
2150 if (fe
->ops
.diseqc_recv_slave_reply
)
2151 err
= fe
->ops
.diseqc_recv_slave_reply(fe
, (struct dvb_diseqc_slave_reply
*) parg
);
2154 case FE_ENABLE_HIGH_LNB_VOLTAGE
:
2155 if (fe
->ops
.enable_high_lnb_voltage
)
2156 err
= fe
->ops
.enable_high_lnb_voltage(fe
, (long) parg
);
2159 case FE_SET_FRONTEND
:
2160 err
= set_delivery_system(fe
, SYS_UNDEFINED
);
2164 err
= dtv_property_cache_sync(fe
, c
, parg
);
2167 err
= dtv_set_frontend(fe
);
2170 err
= dvb_frontend_get_event (fe
, parg
, file
->f_flags
);
2173 case FE_GET_FRONTEND
:
2174 err
= dtv_get_frontend(fe
, parg
);
2177 case FE_SET_FRONTEND_TUNE_MODE
:
2178 fepriv
->tune_mode_flags
= (unsigned long) parg
;
2183 if (fe
->dvb
->fe_ioctl_override
) {
2184 cb_err
= fe
->dvb
->fe_ioctl_override(fe
, cmd
, parg
,
2194 static unsigned int dvb_frontend_poll(struct file
*file
, struct poll_table_struct
*wait
)
2196 struct dvb_device
*dvbdev
= file
->private_data
;
2197 struct dvb_frontend
*fe
= dvbdev
->priv
;
2198 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2200 dprintk ("%s\n", __func__
);
2202 poll_wait (file
, &fepriv
->events
.wait_queue
, wait
);
2204 if (fepriv
->events
.eventw
!= fepriv
->events
.eventr
)
2205 return (POLLIN
| POLLRDNORM
| POLLPRI
);
2210 static int dvb_frontend_open(struct inode
*inode
, struct file
*file
)
2212 struct dvb_device
*dvbdev
= file
->private_data
;
2213 struct dvb_frontend
*fe
= dvbdev
->priv
;
2214 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2215 struct dvb_adapter
*adapter
= fe
->dvb
;
2218 dprintk ("%s\n", __func__
);
2219 if (fepriv
->exit
== DVB_FE_DEVICE_REMOVED
)
2222 if (adapter
->mfe_shared
) {
2223 mutex_lock (&adapter
->mfe_lock
);
2225 if (adapter
->mfe_dvbdev
== NULL
)
2226 adapter
->mfe_dvbdev
= dvbdev
;
2228 else if (adapter
->mfe_dvbdev
!= dvbdev
) {
2230 *mfedev
= adapter
->mfe_dvbdev
;
2232 *mfe
= mfedev
->priv
;
2233 struct dvb_frontend_private
2234 *mfepriv
= mfe
->frontend_priv
;
2235 int mferetry
= (dvb_mfe_wait_time
<< 1);
2237 mutex_unlock (&adapter
->mfe_lock
);
2238 while (mferetry
-- && (mfedev
->users
!= -1 ||
2239 mfepriv
->thread
!= NULL
)) {
2240 if(msleep_interruptible(500)) {
2241 if(signal_pending(current
))
2246 mutex_lock (&adapter
->mfe_lock
);
2247 if(adapter
->mfe_dvbdev
!= dvbdev
) {
2248 mfedev
= adapter
->mfe_dvbdev
;
2250 mfepriv
= mfe
->frontend_priv
;
2251 if (mfedev
->users
!= -1 ||
2252 mfepriv
->thread
!= NULL
) {
2253 mutex_unlock (&adapter
->mfe_lock
);
2256 adapter
->mfe_dvbdev
= dvbdev
;
2261 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
) {
2262 if ((ret
= fe
->ops
.ts_bus_ctrl(fe
, 1)) < 0)
2265 /* If we took control of the bus, we need to force
2266 reinitialization. This is because many ts_bus_ctrl()
2267 functions strobe the RESET pin on the demod, and if the
2268 frontend thread already exists then the dvb_init() routine
2269 won't get called (which is what usually does initial
2270 register configuration). */
2271 fepriv
->reinitialise
= 1;
2274 if ((ret
= dvb_generic_open (inode
, file
)) < 0)
2277 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2278 /* normal tune mode when opened R/W */
2279 fepriv
->tune_mode_flags
&= ~FE_TUNE_MODE_ONESHOT
;
2281 fepriv
->voltage
= -1;
2283 ret
= dvb_frontend_start (fe
);
2287 /* empty event queue */
2288 fepriv
->events
.eventr
= fepriv
->events
.eventw
= 0;
2291 if (adapter
->mfe_shared
)
2292 mutex_unlock (&adapter
->mfe_lock
);
2296 dvb_generic_release(inode
, file
);
2298 if (dvbdev
->users
== -1 && fe
->ops
.ts_bus_ctrl
)
2299 fe
->ops
.ts_bus_ctrl(fe
, 0);
2301 if (adapter
->mfe_shared
)
2302 mutex_unlock (&adapter
->mfe_lock
);
2306 static int dvb_frontend_release(struct inode
*inode
, struct file
*file
)
2308 struct dvb_device
*dvbdev
= file
->private_data
;
2309 struct dvb_frontend
*fe
= dvbdev
->priv
;
2310 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2313 dprintk ("%s\n", __func__
);
2315 if ((file
->f_flags
& O_ACCMODE
) != O_RDONLY
) {
2316 fepriv
->release_jiffies
= jiffies
;
2320 ret
= dvb_generic_release (inode
, file
);
2322 if (dvbdev
->users
== -1) {
2323 wake_up(&fepriv
->wait_queue
);
2324 if (fepriv
->exit
!= DVB_FE_NO_EXIT
) {
2325 fops_put(file
->f_op
);
2327 wake_up(&dvbdev
->wait_queue
);
2329 if (fe
->ops
.ts_bus_ctrl
)
2330 fe
->ops
.ts_bus_ctrl(fe
, 0);
2336 static const struct file_operations dvb_frontend_fops
= {
2337 .owner
= THIS_MODULE
,
2338 .unlocked_ioctl
= dvb_generic_ioctl
,
2339 .poll
= dvb_frontend_poll
,
2340 .open
= dvb_frontend_open
,
2341 .release
= dvb_frontend_release
,
2342 .llseek
= noop_llseek
,
2345 int dvb_register_frontend(struct dvb_adapter
* dvb
,
2346 struct dvb_frontend
* fe
)
2348 struct dvb_frontend_private
*fepriv
;
2349 static const struct dvb_device dvbdev_template
= {
2353 .fops
= &dvb_frontend_fops
,
2354 .kernel_ioctl
= dvb_frontend_ioctl
2357 dprintk ("%s\n", __func__
);
2359 if (mutex_lock_interruptible(&frontend_mutex
))
2360 return -ERESTARTSYS
;
2362 fe
->frontend_priv
= kzalloc(sizeof(struct dvb_frontend_private
), GFP_KERNEL
);
2363 if (fe
->frontend_priv
== NULL
) {
2364 mutex_unlock(&frontend_mutex
);
2367 fepriv
= fe
->frontend_priv
;
2369 sema_init(&fepriv
->sem
, 1);
2370 init_waitqueue_head (&fepriv
->wait_queue
);
2371 init_waitqueue_head (&fepriv
->events
.wait_queue
);
2372 mutex_init(&fepriv
->events
.mtx
);
2374 fepriv
->inversion
= INVERSION_OFF
;
2376 printk ("DVB: registering adapter %i frontend %i (%s)...\n",
2381 dvb_register_device (fe
->dvb
, &fepriv
->dvbdev
, &dvbdev_template
,
2382 fe
, DVB_DEVICE_FRONTEND
);
2385 * Initialize the cache to the proper values according with the
2386 * first supported delivery system (ops->delsys[0])
2389 fe
->dtv_property_cache
.delivery_system
= fe
->ops
.delsys
[0];
2390 dvb_frontend_clear_cache(fe
);
2392 mutex_unlock(&frontend_mutex
);
2395 EXPORT_SYMBOL(dvb_register_frontend
);
2397 int dvb_unregister_frontend(struct dvb_frontend
* fe
)
2399 struct dvb_frontend_private
*fepriv
= fe
->frontend_priv
;
2400 dprintk ("%s\n", __func__
);
2402 mutex_lock(&frontend_mutex
);
2403 dvb_frontend_stop (fe
);
2404 mutex_unlock(&frontend_mutex
);
2406 if (fepriv
->dvbdev
->users
< -1)
2407 wait_event(fepriv
->dvbdev
->wait_queue
,
2408 fepriv
->dvbdev
->users
==-1);
2410 mutex_lock(&frontend_mutex
);
2411 dvb_unregister_device (fepriv
->dvbdev
);
2413 /* fe is invalid now */
2415 mutex_unlock(&frontend_mutex
);
2418 EXPORT_SYMBOL(dvb_unregister_frontend
);
2420 #ifdef CONFIG_MEDIA_ATTACH
2421 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2425 if (fe
->ops
.release_sec
) {
2426 fe
->ops
.release_sec(fe
);
2427 symbol_put_addr(fe
->ops
.release_sec
);
2429 if (fe
->ops
.tuner_ops
.release
) {
2430 fe
->ops
.tuner_ops
.release(fe
);
2431 symbol_put_addr(fe
->ops
.tuner_ops
.release
);
2433 if (fe
->ops
.analog_ops
.release
) {
2434 fe
->ops
.analog_ops
.release(fe
);
2435 symbol_put_addr(fe
->ops
.analog_ops
.release
);
2437 ptr
= (void*)fe
->ops
.release
;
2439 fe
->ops
.release(fe
);
2440 symbol_put_addr(ptr
);
2444 void dvb_frontend_detach(struct dvb_frontend
* fe
)
2446 if (fe
->ops
.release_sec
)
2447 fe
->ops
.release_sec(fe
);
2448 if (fe
->ops
.tuner_ops
.release
)
2449 fe
->ops
.tuner_ops
.release(fe
);
2450 if (fe
->ops
.analog_ops
.release
)
2451 fe
->ops
.analog_ops
.release(fe
);
2452 if (fe
->ops
.release
)
2453 fe
->ops
.release(fe
);
2456 EXPORT_SYMBOL(dvb_frontend_detach
);