diff options
author | Mike Isely <isely@pobox.com> | 2008-04-06 03:04:35 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@infradead.org> | 2008-04-24 13:09:48 -0400 |
commit | d913d6303072ca194919d851e6743ad8c3a7563d (patch) | |
tree | 95a36be460fa3de7f1be646a85bf8cb08edb2f85 /drivers | |
parent | 72998b71096e364002269a8cacc0524937d479c6 (diff) |
V4L/DVB (7710): pvrusb2: Implement critical digital streaming quirk for onair devices
Implement timed measurement of encoder operation for the first time it
is run. This allows the driver to note when the encoder has been run
successfully for at least 1/4 second. On top of that implement
various bits to ensure that the encoder has been run once before
digital streaming for OnAir devices. This is done via several core
state machine tweaks.
Signed-off-by: Mike Isely <isely@pobox.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-encoder.c | 9 | ||||
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | 4 | ||||
-rw-r--r-- | drivers/media/video/pvrusb2/pvrusb2-hdw.c | 150 |
3 files changed, 156 insertions, 7 deletions
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c index 324d1bd8500d..c46d367f7472 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c +++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c | |||
@@ -278,11 +278,20 @@ static int pvr2_encoder_cmd(void *ctxt, | |||
278 | ret = -EBUSY; | 278 | ret = -EBUSY; |
279 | } | 279 | } |
280 | if (ret) { | 280 | if (ret) { |
281 | del_timer_sync(&hdw->encoder_run_timer); | ||
281 | hdw->state_encoder_ok = 0; | 282 | hdw->state_encoder_ok = 0; |
282 | pvr2_trace(PVR2_TRACE_STBITS, | 283 | pvr2_trace(PVR2_TRACE_STBITS, |
283 | "State bit %s <-- %s", | 284 | "State bit %s <-- %s", |
284 | "state_encoder_ok", | 285 | "state_encoder_ok", |
285 | (hdw->state_encoder_ok ? "true" : "false")); | 286 | (hdw->state_encoder_ok ? "true" : "false")); |
287 | if (hdw->state_encoder_runok) { | ||
288 | hdw->state_encoder_runok = 0; | ||
289 | pvr2_trace(PVR2_TRACE_STBITS, | ||
290 | "State bit %s <-- %s", | ||
291 | "state_encoder_runok", | ||
292 | (hdw->state_encoder_runok ? | ||
293 | "true" : "false")); | ||
294 | } | ||
286 | pvr2_trace( | 295 | pvr2_trace( |
287 | PVR2_TRACE_ERROR_LEGS, | 296 | PVR2_TRACE_ERROR_LEGS, |
288 | "Giving up on command." | 297 | "Giving up on command." |
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h index c725495826ce..a67dcf84b596 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h | |||
@@ -238,6 +238,7 @@ struct pvr2_hdw { | |||
238 | int state_encoder_run; /* Encoder is running */ | 238 | int state_encoder_run; /* Encoder is running */ |
239 | int state_encoder_config; /* Encoder is configured */ | 239 | int state_encoder_config; /* Encoder is configured */ |
240 | int state_encoder_waitok; /* Encoder pre-wait done */ | 240 | int state_encoder_waitok; /* Encoder pre-wait done */ |
241 | int state_encoder_runok; /* Encoder has run for >= .25 sec */ | ||
241 | int state_decoder_run; /* Decoder is running */ | 242 | int state_decoder_run; /* Decoder is running */ |
242 | int state_usbstream_run; /* FX2 is streaming */ | 243 | int state_usbstream_run; /* FX2 is streaming */ |
243 | int state_decoder_quiescent; /* Decoder idle for > 50msec */ | 244 | int state_decoder_quiescent; /* Decoder idle for > 50msec */ |
@@ -267,6 +268,9 @@ struct pvr2_hdw { | |||
267 | /* Timer for measuring encoder pre-wait time */ | 268 | /* Timer for measuring encoder pre-wait time */ |
268 | struct timer_list encoder_wait_timer; | 269 | struct timer_list encoder_wait_timer; |
269 | 270 | ||
271 | /* Timer for measuring encoder minimum run time */ | ||
272 | struct timer_list encoder_run_timer; | ||
273 | |||
270 | /* Place to block while waiting for state changes */ | 274 | /* Place to block while waiting for state changes */ |
271 | wait_queue_head_t state_wait_data; | 275 | wait_queue_head_t state_wait_data; |
272 | 276 | ||
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c index 539fe17105e7..4f6bb58ca5fc 100644 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c | |||
@@ -264,6 +264,7 @@ static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw); | |||
264 | static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); | 264 | static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); |
265 | static void pvr2_hdw_quiescent_timeout(unsigned long); | 265 | static void pvr2_hdw_quiescent_timeout(unsigned long); |
266 | static void pvr2_hdw_encoder_wait_timeout(unsigned long); | 266 | static void pvr2_hdw_encoder_wait_timeout(unsigned long); |
267 | static void pvr2_hdw_encoder_run_timeout(unsigned long); | ||
267 | static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32); | 268 | static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32); |
268 | static int pvr2_send_request_ex(struct pvr2_hdw *hdw, | 269 | static int pvr2_send_request_ex(struct pvr2_hdw *hdw, |
269 | unsigned int timeout,int probe_fl, | 270 | unsigned int timeout,int probe_fl, |
@@ -1236,6 +1237,14 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw) | |||
1236 | time we configure the encoder, then we'll fully configure it. */ | 1237 | time we configure the encoder, then we'll fully configure it. */ |
1237 | hdw->enc_cur_valid = 0; | 1238 | hdw->enc_cur_valid = 0; |
1238 | 1239 | ||
1240 | /* Encoder is about to be reset so note that as far as we're | ||
1241 | concerned now, the encoder has never been run. */ | ||
1242 | del_timer_sync(&hdw->encoder_run_timer); | ||
1243 | if (hdw->state_encoder_runok) { | ||
1244 | hdw->state_encoder_runok = 0; | ||
1245 | trace_stbit("state_encoder_runok",hdw->state_encoder_runok); | ||
1246 | } | ||
1247 | |||
1239 | /* First prepare firmware loading */ | 1248 | /* First prepare firmware loading */ |
1240 | ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/ | 1249 | ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/ |
1241 | ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/ | 1250 | ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/ |
@@ -1882,6 +1891,10 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, | |||
1882 | hdw->encoder_wait_timer.data = (unsigned long)hdw; | 1891 | hdw->encoder_wait_timer.data = (unsigned long)hdw; |
1883 | hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout; | 1892 | hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout; |
1884 | 1893 | ||
1894 | init_timer(&hdw->encoder_run_timer); | ||
1895 | hdw->encoder_run_timer.data = (unsigned long)hdw; | ||
1896 | hdw->encoder_run_timer.function = pvr2_hdw_encoder_run_timeout; | ||
1897 | |||
1885 | hdw->master_state = PVR2_STATE_DEAD; | 1898 | hdw->master_state = PVR2_STATE_DEAD; |
1886 | 1899 | ||
1887 | init_waitqueue_head(&hdw->state_wait_data); | 1900 | init_waitqueue_head(&hdw->state_wait_data); |
@@ -2082,6 +2095,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, | |||
2082 | fail: | 2095 | fail: |
2083 | if (hdw) { | 2096 | if (hdw) { |
2084 | del_timer_sync(&hdw->quiescent_timer); | 2097 | del_timer_sync(&hdw->quiescent_timer); |
2098 | del_timer_sync(&hdw->encoder_run_timer); | ||
2085 | del_timer_sync(&hdw->encoder_wait_timer); | 2099 | del_timer_sync(&hdw->encoder_wait_timer); |
2086 | if (hdw->workqueue) { | 2100 | if (hdw->workqueue) { |
2087 | flush_workqueue(hdw->workqueue); | 2101 | flush_workqueue(hdw->workqueue); |
@@ -2144,6 +2158,7 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw) | |||
2144 | hdw->workqueue = NULL; | 2158 | hdw->workqueue = NULL; |
2145 | } | 2159 | } |
2146 | del_timer_sync(&hdw->quiescent_timer); | 2160 | del_timer_sync(&hdw->quiescent_timer); |
2161 | del_timer_sync(&hdw->encoder_run_timer); | ||
2147 | del_timer_sync(&hdw->encoder_wait_timer); | 2162 | del_timer_sync(&hdw->encoder_wait_timer); |
2148 | if (hdw->fw_buffer) { | 2163 | if (hdw->fw_buffer) { |
2149 | kfree(hdw->fw_buffer); | 2164 | kfree(hdw->fw_buffer); |
@@ -3584,23 +3599,116 @@ static int state_eval_encoder_config(struct pvr2_hdw *hdw) | |||
3584 | } | 3599 | } |
3585 | 3600 | ||
3586 | 3601 | ||
3602 | /* Return true if the encoder should not be running. */ | ||
3603 | static int state_check_disable_encoder_run(struct pvr2_hdw *hdw) | ||
3604 | { | ||
3605 | if (!hdw->state_encoder_ok) { | ||
3606 | /* Encoder isn't healthy at the moment, so stop it. */ | ||
3607 | return !0; | ||
3608 | } | ||
3609 | if (!hdw->state_pathway_ok) { | ||
3610 | /* Mode is not understood at the moment (i.e. it wants to | ||
3611 | change), so encoder must be stopped. */ | ||
3612 | return !0; | ||
3613 | } | ||
3614 | |||
3615 | switch (hdw->pathway_state) { | ||
3616 | case PVR2_PATHWAY_ANALOG: | ||
3617 | if (!hdw->state_decoder_run) { | ||
3618 | /* We're in analog mode and the decoder is not | ||
3619 | running; thus the encoder should be stopped as | ||
3620 | well. */ | ||
3621 | return !0; | ||
3622 | } | ||
3623 | break; | ||
3624 | case PVR2_PATHWAY_DIGITAL: | ||
3625 | if (hdw->state_encoder_runok) { | ||
3626 | /* This is a funny case. We're in digital mode so | ||
3627 | really the encoder should be stopped. However | ||
3628 | if it really is running, only kill it after | ||
3629 | runok has been set. This gives a chance for the | ||
3630 | onair quirk to function (encoder must run | ||
3631 | briefly first, at least once, before onair | ||
3632 | digital streaming can work). */ | ||
3633 | return !0; | ||
3634 | } | ||
3635 | break; | ||
3636 | default: | ||
3637 | /* Unknown mode; so encoder should be stopped. */ | ||
3638 | return !0; | ||
3639 | } | ||
3640 | |||
3641 | /* If we get here, we haven't found a reason to stop the | ||
3642 | encoder. */ | ||
3643 | return 0; | ||
3644 | } | ||
3645 | |||
3646 | |||
3647 | /* Return true if the encoder should be running. */ | ||
3648 | static int state_check_enable_encoder_run(struct pvr2_hdw *hdw) | ||
3649 | { | ||
3650 | if (!hdw->state_encoder_ok) { | ||
3651 | /* Don't run the encoder if it isn't healthy... */ | ||
3652 | return 0; | ||
3653 | } | ||
3654 | if (!hdw->state_pathway_ok) { | ||
3655 | /* Don't run the encoder if we don't (yet) know what mode | ||
3656 | we need to be in... */ | ||
3657 | return 0; | ||
3658 | } | ||
3659 | |||
3660 | switch (hdw->pathway_state) { | ||
3661 | case PVR2_PATHWAY_ANALOG: | ||
3662 | if (hdw->state_decoder_run) { | ||
3663 | /* In analog mode, if the decoder is running, then | ||
3664 | run the encoder. */ | ||
3665 | return !0; | ||
3666 | } | ||
3667 | break; | ||
3668 | case PVR2_PATHWAY_DIGITAL: | ||
3669 | if ((hdw->hdw_desc->digital_control_scheme == | ||
3670 | PVR2_DIGITAL_SCHEME_ONAIR) && | ||
3671 | !hdw->state_encoder_runok) { | ||
3672 | /* This is a quirk. OnAir hardware won't stream | ||
3673 | digital until the encoder has been run at least | ||
3674 | once, for a minimal period of time (empiricially | ||
3675 | measured to be 1/4 second). So if we're on | ||
3676 | OnAir hardware and the encoder has never been | ||
3677 | run at all, then start the encoder. Normal | ||
3678 | state machine logic in the driver will | ||
3679 | automatically handle the remaining bits. */ | ||
3680 | return !0; | ||
3681 | } | ||
3682 | break; | ||
3683 | default: | ||
3684 | /* For completeness (unknown mode; encoder won't run ever) */ | ||
3685 | break; | ||
3686 | } | ||
3687 | /* If we get here, then we haven't found any reason to run the | ||
3688 | encoder, so don't run it. */ | ||
3689 | return 0; | ||
3690 | } | ||
3691 | |||
3692 | |||
3587 | /* Evaluate whether or not state_encoder_run can change */ | 3693 | /* Evaluate whether or not state_encoder_run can change */ |
3588 | static int state_eval_encoder_run(struct pvr2_hdw *hdw) | 3694 | static int state_eval_encoder_run(struct pvr2_hdw *hdw) |
3589 | { | 3695 | { |
3590 | if (hdw->state_encoder_run) { | 3696 | if (hdw->state_encoder_run) { |
3697 | if (!state_check_disable_encoder_run(hdw)) return 0; | ||
3591 | if (hdw->state_encoder_ok) { | 3698 | if (hdw->state_encoder_ok) { |
3592 | if (hdw->state_decoder_run && | 3699 | del_timer_sync(&hdw->encoder_run_timer); |
3593 | hdw->state_pathway_ok) return 0; | ||
3594 | if (pvr2_encoder_stop(hdw) < 0) return !0; | 3700 | if (pvr2_encoder_stop(hdw) < 0) return !0; |
3595 | } | 3701 | } |
3596 | hdw->state_encoder_run = 0; | 3702 | hdw->state_encoder_run = 0; |
3597 | } else { | 3703 | } else { |
3598 | if (!hdw->state_encoder_ok) return 0; | 3704 | if (!state_check_enable_encoder_run(hdw)) return 0; |
3599 | if (!hdw->state_decoder_run) return 0; | ||
3600 | if (!hdw->state_pathway_ok) return 0; | ||
3601 | if (hdw->pathway_state != PVR2_PATHWAY_ANALOG) return 0; | ||
3602 | if (pvr2_encoder_start(hdw) < 0) return !0; | 3705 | if (pvr2_encoder_start(hdw) < 0) return !0; |
3603 | hdw->state_encoder_run = !0; | 3706 | hdw->state_encoder_run = !0; |
3707 | if (!hdw->state_encoder_runok) { | ||
3708 | hdw->encoder_run_timer.expires = | ||
3709 | jiffies + (HZ*250/1000); | ||
3710 | add_timer(&hdw->encoder_run_timer); | ||
3711 | } | ||
3604 | } | 3712 | } |
3605 | trace_stbit("state_encoder_run",hdw->state_encoder_run); | 3713 | trace_stbit("state_encoder_run",hdw->state_encoder_run); |
3606 | return !0; | 3714 | return !0; |
@@ -3629,6 +3737,19 @@ static void pvr2_hdw_encoder_wait_timeout(unsigned long data) | |||
3629 | } | 3737 | } |
3630 | 3738 | ||
3631 | 3739 | ||
3740 | /* Timeout function for encoder run timer. */ | ||
3741 | static void pvr2_hdw_encoder_run_timeout(unsigned long data) | ||
3742 | { | ||
3743 | struct pvr2_hdw *hdw = (struct pvr2_hdw *)data; | ||
3744 | if (!hdw->state_encoder_runok) { | ||
3745 | hdw->state_encoder_runok = !0; | ||
3746 | trace_stbit("state_encoder_runok",hdw->state_encoder_runok); | ||
3747 | hdw->state_stale = !0; | ||
3748 | queue_work(hdw->workqueue,&hdw->workpoll); | ||
3749 | } | ||
3750 | } | ||
3751 | |||
3752 | |||
3632 | /* Evaluate whether or not state_decoder_run can change */ | 3753 | /* Evaluate whether or not state_decoder_run can change */ |
3633 | static int state_eval_decoder_run(struct pvr2_hdw *hdw) | 3754 | static int state_eval_decoder_run(struct pvr2_hdw *hdw) |
3634 | { | 3755 | { |
@@ -3718,6 +3839,16 @@ static int state_eval_usbstream_run(struct pvr2_hdw *hdw) | |||
3718 | } else if ((hdw->pathway_state == PVR2_PATHWAY_DIGITAL) && | 3839 | } else if ((hdw->pathway_state == PVR2_PATHWAY_DIGITAL) && |
3719 | (hdw->hdw_desc->flag_digital_requires_cx23416)) { | 3840 | (hdw->hdw_desc->flag_digital_requires_cx23416)) { |
3720 | if (!hdw->state_encoder_ok) return 0; | 3841 | if (!hdw->state_encoder_ok) return 0; |
3842 | if (hdw->state_encoder_run) return 0; | ||
3843 | if (hdw->hdw_desc->digital_control_scheme == | ||
3844 | PVR2_DIGITAL_SCHEME_ONAIR) { | ||
3845 | /* OnAir digital receivers won't stream | ||
3846 | unless the analog encoder has run first. | ||
3847 | Why? I have no idea. But don't even | ||
3848 | try until we know the analog side is | ||
3849 | known to have run. */ | ||
3850 | if (!hdw->state_encoder_runok) return 0; | ||
3851 | } | ||
3721 | } | 3852 | } |
3722 | if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0) return 0; | 3853 | if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0) return 0; |
3723 | hdw->state_usbstream_run = !0; | 3854 | hdw->state_usbstream_run = !0; |
@@ -3861,7 +3992,12 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which, | |||
3861 | (hdw->state_encoder_ok ? | 3992 | (hdw->state_encoder_ok ? |
3862 | "" : " <encode:init>"), | 3993 | "" : " <encode:init>"), |
3863 | (hdw->state_encoder_run ? | 3994 | (hdw->state_encoder_run ? |
3864 | " <encode:run>" : " <encode:stop>"), | 3995 | (hdw->state_encoder_runok ? |
3996 | " <encode:run>" : | ||
3997 | " <encode:firstrun>") : | ||
3998 | (hdw->state_encoder_runok ? | ||
3999 | " <encode:stop>" : | ||
4000 | " <encode:virgin>")), | ||
3865 | (hdw->state_encoder_config ? | 4001 | (hdw->state_encoder_config ? |
3866 | " <encode:configok>" : | 4002 | " <encode:configok>" : |
3867 | (hdw->state_encoder_waitok ? | 4003 | (hdw->state_encoder_waitok ? |