#!/bin/sh
#
# setup dvb cards
#
# runlevels: geexbox, debug, install

echo "### Setting up DVB card ###"

# DVB frontends drivers are auto-loaded by main device drivers

# PCI DVB Devices
if grep -q '0400: 109e:' /tmp/pci; then
  # BT8x8 Card
  modprobe dvb-bt8xx >/dev/null 2>&1
  modprobe dst >/dev/null 2>&1
elif grep -q '0480: 1131:' /tmp/pci; then
  # SAA7134 Card
  modprobe saa7134-dvb >/dev/null 2>&1
  # SAA7146 Cards
  modprobe saa7146 >/dev/null 2>&1
  modprobe saa7146_vv >/dev/null 2>&1
  modprobe dvb-ttpci >/dev/null 2>&1
  modprobe budget >/dev/null 2>&1
  modprobe budget-ci >/dev/null 2>&1
  modprobe budget-av >/dev/null 2>&1
elif grep -q '0280: 13d0:' /tmp/pci; then
  # B2C2 Cards
  modprobe budget >/dev/null 2>&1
  modprobe b2c2-flexcop-pci >/dev/null 2>&1
  modprobe b2c2-flexcop >/dev/null 2>&1
elif grep -q '0480: 14f1:88' /tmp/pci; then
  # Conexant CX88 Card
  modprobe cx88-blackbird >/dev/null 2>&1
  modprobe cx88-dvb >/dev/null 2>&1
elif grep -q '0480: 0432:' /tmp/pci; then
  # SCM Pluto2 Card
  modprobe pluto2 >/dev/null 2>&1
fi

# allow cold USB DVB devices time to load firmware
if test -n "`dmesg | grep 'dvb-usb.*cold state'`"; then
  for I in 1 2 3 4 5 6 7 8 9 10; do
    # Loaded firmware, or failed to load firmware, so exit
    test -n "`dmesg | grep -e 'dvb-usb.*warm state' -e 'dvb-usb.*did not find firmware'`" && break
    sleep 1
  done
fi

# ensure that DVB card has been discovered
if test -n "`dmesg | grep 'DVB: registering new adapter'`"; then
  echo -n "" > /var/dvbcard
fi

exit 0
