From jre@vineyard.net  Mon Apr 26 14:49:53 2004
Return-Path: <jre@vineyard.net>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 9040716A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Apr 2004 14:49:53 -0700 (PDT)
Received: from mail.vineyard.net (k1.vineyard.net [204.17.195.90])
	by mx1.FreeBSD.org (Postfix) with ESMTP id F000443D46
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Apr 2004 14:49:52 -0700 (PDT)
	(envelope-from jre@vineyard.net)
Received: from localhost (loopback [127.0.0.1])
	by mail.vineyard.net (Postfix) with ESMTP id 39351A0CA5
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Apr 2004 17:49:51 -0400 (EDT)
Received: from mail.vineyard.net ([127.0.0.1])
 by localhost (king1.vineyard.net [127.0.0.1]) (amavisd-new, port 10024)
 with ESMTP id 16120-07 for <FreeBSD-gnats-submit@freebsd.org>;
 Mon, 26 Apr 2004 17:49:51 -0400 (EDT)
Received: from jade.elsasser.org (loopback [127.0.0.1])
	by mail.vineyard.net (Postfix) with ESMTP id A7C029755B
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Apr 2004 17:49:50 -0400 (EDT)
Received: from jade.elsasser.org (localhost [127.0.0.1])
	by jade.elsasser.org (Postfix) with ESMTP id 4E1ADAE
	for <FreeBSD-gnats-submit@freebsd.org>; Mon, 26 Apr 2004 17:49:49 -0400 (EDT)
Message-Id: <1083016189.0@jade.elsasser.org>
Date: Mon, 26 Apr 2004 17:49:49 -0400
From: "Josh Elsasser" <jre@vineyard.net>
To: "FreeBSD gnats submit" <FreeBSD-gnats-submit@freebsd.org>
Subject: [PATCH] bktr driver may not tune correctly
X-Send-Pr-Version: gtk-send-pr 0.3.3 
X-GNATS-Notify:

>Number:         66006
>Category:       kern
>Synopsis:       [PATCH] bktr driver may not tune correctly
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    schweikh
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Mon Apr 26 14:50:11 PDT 2004
>Closed-Date:    Sat Jul 24 10:37:19 GMT 2004
>Last-Modified:  Sat Jul 24 10:37:19 GMT 2004
>Originator:     Josh Elsasser
>Release:        FreeBSD 5.2-CURRENT i386
>Organization:
>Environment:


System: FreeBSD 5.2-CURRENT #15: Mon Apr 26 13:49:58 EDT 2004
    joshe@jade.elsasser.org:/usr/local/obj/usr/src/sys/JADE



>Description:


The bktr TV-tuner card driver contains a bug when a program tunes a
frequency with a TVTUNER_SETFREQ ioctl without first setting the tuner
type with a TVTUNER_SETTYPE ioctl.  If the default tuner type is a PAL
frequency set such as CHNLSET_WEUROPE and the video format is NTSC or
vice versa, the card will be tuned to the wrong frequency.

The driver uses the current channel set to determine "the offset from
the base signal where the video, color, audio and NICAM signals are".
It appears to have been written with the assumption that a
TVTUNER_SETTYPE will always be issued, but this is not necessary if
one wishes to bypass the driver's build-in (and somewhat incomplete)
frequency sets and tune a frequency directly with TVTUNER_SETFREQ.

This simple patch uses the current input format set with the BT848SFMT
ioctl to determine if a NTSC or PAL offset should be used.  I am not
entirely sure that it is correct for every possible input format, but
it is at least as correct as the driver is now.


>How-To-Repeat:


For NTSC, build the bktr driver with DEFAULT_CHNLSET=CHNLSET_WEUROPE
(which is the default), or CHNLSET_WEUROPE=CHNLSET_NABCST for PAL.
Then use xawtv/motv or mplayer (not fxtv) and observe that it is not
tuning correctly.


>Fix:


--- bktr-kernel-patch begins here ---
--- sys/dev/bktr/bktr_tuner.c.orig	Mon Dec 15 22:28:39 2003
+++ sys/dev/bktr/bktr_tuner.c	Mon Apr 26 16:03:57 2004
@@ -698,7 +698,7 @@
 #undef TBL_CHNL
 
 
-#define TBL_IF	freqTable[ bktr->tuner.chnlset ].ptr[ 1 ]
+#define TBL_IF	(bktr->format_params == BT848_IFORM_F_NTSCJ || bktr->format_params == BT848_IFORM_F_NTSCM ? nabcst[1] : weurope[1])
 
 
 /* Initialise the tuner structures in the bktr_softc */
--- bktr-kernel-patch ends here ---



>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->schweikh 
Responsible-Changed-By: schweikh 
Responsible-Changed-When: Sat Jun 12 09:31:59 GMT 2004 
Responsible-Changed-Why:  
I'll have a look at this. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66006 
State-Changed-From-To: open->patched 
State-Changed-By: schweikh 
State-Changed-When: Sun Jun 27 09:59:22 GMT 2004 
State-Changed-Why:  
Committed to -current, thanks Josh! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66006 
State-Changed-From-To: patched->closed 
State-Changed-By: schweikh 
State-Changed-When: Sat Jul 24 10:36:49 GMT 2004 
State-Changed-Why:  
Committed to RELENG_4. Thanks again, Josh! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=66006 
>Unformatted:
