#!/bin/bash
# $Id: rc.afb,v 1.1.1.1 1999/09/08 06:42:36 davem Exp $
#
# chkconfig: 2345 90 10
# description: Load microcode at boottime to all detected Elite3D
#	       graphics cards.
#

. /etc/rc.d/init.d/functions

UCODE=/lib/firmware/afb.ucode
LOADER=/sbin/afbinit

start()
{
	echo -n $"Starting afbinit: "
	
	ARCH=$(uname -m)
	# If this is not sparc64, get out of here.
	if [ "$ARCH" != "sparc64" ]; then
		failure "$ARCH cannot have AFB"
		echo
		return 1
	fi
	
	# The microcode loader binary and the microcode
	# itself must exist.
	if [ ! -x $LOADER ]; then
		failure "Missing afbinit"
		echo
		return 1
	fi
	
	if [ ! -f $UCODE ]; then
		failure "Missing microcode"
		echo
		return 1
	fi
	
	# Make FB device list.
	# devs=`/bin/dmesg | /bin/egrep -i "Elite 3D" | /bin/sed 's/\:.*//'`
	devs=`grep "Elite 3D" /sys/class/graphics/*/name | cut -d / -f 5`
	
	if [ -z "$devs" ]; then
		failure "No AFB detected"
		echo
		return 1
	fi

	echo
	
	# Load microcode onto each card.
	RETVAL=0
	for afb in $devs; do
		echo -n "  $afb:"
		$LOADER /dev/$afb $UCODE && success || failure
		if [ $? = 1 ]; then
			RETVAL=1
		fi
		echo
	done
	return $RETVAL
}

RETVAL=0
case "$1" in
	start|restart|reload)
		start
		RETVAL=$?
		;;
	stop)
		;;
	status)
		;;
	*)
		echo "Usage: $0 {start|stop|restart|reload|status}"
		RETVAL=1
esac
exit $RETVAL
