Installing the pcHDTV Driver for Debian Sarge/Kernel 2.4.25

Peter DiCamillo, Peter_DiCamillo@brown.edu
March 20, 2004

These are the steps that worked for me to get my pcHDTV HD-2000 card
working with Debian.  They include an updated kernel patch for
2.4.25, which I made by analyzing all the changes and re-applying
them.  The patch is very close to the original Reh Hat patch found
on the pvHDTV CD.  However, the driver has been changed to use
schedule_timeout instead of jiffies for the 10ms resolution timimg
(which should be more reliable).  Also, there are some minor changes
which may allow to the patched driver to continue to work with the
other cards the bttv driver supports, although I am unable to test
that.  The driver has *not* been extensively tested, but so far I
haven't noticed any problems with it.

1. Install or upgrade to the Debian "testing" distribution named
"Sarge".  The installers are here:
http://www.debian.org/devel/debian-installer/
and I highly-recommend using the 100MB CD image version.

2. Obtain the Debian source package for kernel 2.4.25 and install
it.  That can be done with the commands:
     apt-get update
     apt-get install kernel-source-2.4.25
     
3. Compile and install a 2.4.25 kernel for your system.  I recommend
doing this and verifying it works before adding the pcHDTV support,
so that it's easier to isolate problems.  There are directions for
that here: http://www.debian.org/doc/FAQ/ch-kernel.en.html.  However,
I used a manual process with these commands:
     cd /usr/src
     bunzip2 -dc kernel-source-2.4.25.tar.bz2  | tar xf -
     cd kernel-source-2.4.25
     make config  or  make menuconfig  or one of the other config options
     make dep
     make clean
     make bzImage
     make modules
     make modules_install
     depmod -a

Certain configuration options are necessary for using the bttv driver.
Under character devices, I2C support must be enabled, and also "I2C
bit-banging interfaces" (CONFIG_I2C and CONFIG_I2C_ALGOBIT).  Under
multimedia devices, Video for Linux must be enabled, and BT848 Video
For Linux (CONFIG_VIDEO_DEV and CONFIG_VIDEO_BT848).  The BT848 support
can be either included in the kernel or built as a module.
     
4. Install the new kernel with your boot loader.  I used lilo and these
commands, with /vmlinuz a soft link to boot/vmlinuz-2.4.25-1-386:
     cd /boot
     cp -p /usr/src/kernel-source-2.4.25/arch/i386/boot/bzImage vmlinuz-2.4.25-1-386
     lilo

5. Reboot to test the new kernel.  Check during the boot messages
that all of your hardware is properly detected (for now ignore any
bttv messages).  The "dmesg" command will display the boot messages
at any time.  If your hard drive(s) should be using DMA, check that
is indicated at the end of the line for the drive detection, for example
UDAM(100) in this line:
  hda: 60036480 sectors (30739 MB) w/1916KiB Cache, CHS=3737/255/63, UDMA(100)
(DMA support is necessary to avoid buffer overruns when recording
streams.)  Also, use "cat /proc/interrupts" to check IRQ assignments.
If your motherboard has APIC support for additional IRQs, you should
see something like this (depending on the cards you have installed)
if you've properly configured it in the kernel:
            CPU0       
  0:     966698    IO-APIC-edge  timer
  1:         93    IO-APIC-edge  keyboard
  2:          0          XT-PIC  cascade
  9:          0   IO-APIC-level  acpi
 14:      74293    IO-APIC-edge  ide0
 15:          7    IO-APIC-edge  ide1
 16:          1   IO-APIC-level  bttv
 18:         18   IO-APIC-level  aic7xxx, ohci1394
 19:          0   IO-APIC-level  usb-uhci
 21:          0   IO-APIC-level  EMU10K1
 22:      41144   IO-APIC-level  eth0
 23:          0   IO-APIC-level  usb-uhci
NMI:          0 
LOC:     966687 
ERR:          0
MIS:          0

"bttv" will only be present if you've included BT848 support in the
kernel or have loaded the module for it ("insmod bttv").  I'm not
certain, but I think IRQ sharing will cause a problem for the bttv
driver.  In any event, it's probably not a good idea.

Also, check that the timer value increases by 1000 over a period of
10 seconds.  If it doesn't, there's a problem with timing on your
system which may cause a problem for the bttv driver.

6. You may find that you have to reconfigure the kernel several
times to get everything right.  Just repeat the steps starting from
the config step.

7. When everything looks ok, install the patches to suppport the
HD-2000 card. Copy the patch files, bttv-kernel-2.4.25.patch and
bttv-user-2.4.25.patch, to /usr/src.  Then use these commands to
apply the patches:
   cd /usr/src
   patch -p0 -b < bttv-user-2.4.25.patch
   patch -p0 -b < bttv-kernel-2.4.25.patch

The "-b" option to patch is optional, and causes patch to save
copies of the unpatched files with ".orig" appended to the filename.
Then rebuild the kernel (and modules) as if you had just reconfigured
it ("cd kernel-source-2.4.25" then start with "make dep" for the steps
above.)

Note that the patches patch both /usr/include/linux/videodev.h and
another copy of videodev.h in the kernel source.  Although the files
have the same name, they are different, and both must be patched before
building the kernel.

8.  Reboot and check the HD-2000 is detected properly.  You should
get messages something like this either during booting (if you included the
driver in the kernel) or after loading the module:
  bttv: driver version 0.7.108 loaded
  bttv: using 4 buffers with 2080k (8320k total) for capture
  bttv: Bt8xx card found (0).
  bttv0: Bt878 (rev 17) at 02:03.0, irq: 16, latency: 32, mmio: 0xe0000000
  bttv0: detected: pcHDTV HD-2000 TV [card=110], PCI subsystem ID is 7063:2000
  bttv0: using: pcHDTV HD-2000 TV [card=110,autodetected]
  tuner: chip found @ 0xc2
  i2c-core.o: client [(tuner unset)] registered to adapter [bt848 #0](pos. 0).
  i2c-core.o: adapter bt848 #0 registered as adapter 0.
  bttv0: using tuner=42
  tuner: type set to 42 (Philips 1236D ATSC/NTSC dual in)
  bttv0: i2c: checking for MSP34xx @ 0x80... not found
  bttv0: i2c: checking for TDA9875 @ 0xb0... not found
  bttv0: i2c: checking for TDA7432 @ 0x8a... not found
  bttv0: registered device video0
  bttv0: registered device vbi0
  bttv0: registered device dtv0

These are messages from during booting.  The messages from loading the
bttv module are a little different.  To load the bttv module, use
"insmod bttv".  Modprobe may also be used, but it generates some error
messages at the end because it tries to load the tuner module even
though it's already loaded.  At this point, if you check the LEDs on
the card, you'll likely see both the red and green ones lit.  The red
one normally indicates errors, and is on because the tuner is active
but not tuned to a station yet.  It does not indicate a problem at
this point.

9. Create the dtv devices in /dev.  That can be done by running the script
"make-dtv-devs".

10. Build new copies of the tools program.  Copy the tools directory from
the CD, then cd to the copy and issue "make clean" and "make".

At this point, you should be able to use the tools you just built,
following the installation directions that come with the card.  A good test
that everything is working is if both dtvsignal and dtvscan give reasonable
results.  Note: As the directions indicate, the antenna should be connected
to the coax connector closest to the LEDs.
