#!/bin/sh
#ident	"@(#)afbinit  1.4 98/04/22 SMI"
#
# Copyright (c) 1997 by Sun Microsystems, Inc.
#
# /etc/rc2.d/S91afbinit - UNIX initialization of AFB

PATH=/usr/bin:/bin:/usr/sbin:/sbin

#
# Find out how many AFB cards are installed on the system.
#
afb_count=`prtconf | grep -c afb`
if [ ${afb_count} -eq 0 ]
then
	exit 0
fi		

# 
# Check the $devpath directory for any afb devices
#
devpath=/dev
test -d /dev/fbs && devpath=/dev/fbs
devs=`/bin/ls $devpath | grep afb`

#
# If there aren't any around, there's no need to load
# the driver, so quit.
#
if [ "$devs" = "" ]
then
        exit 0
fi

#
# We have a afb, so modload the driver and make sure that it was successful.  
# First try to locate the driver in the uname -i directory.  Otherwise 
# look in uname -m.
#
plat=`uname -i`
if [ ! -f /platform/$plat/kernel/drv/afb ]
then
	plat=`uname -m`
	if [ ! -f /platform/$plat/kernel/drv/afb ]
	then
		echo "afbinit: cannot find the afb driver module."
		exit 1
	fi
fi

err=`modload /platform/$plat/kernel/drv/afb 2>&1`
if [ $? -ne 0 ]
then
	echo "afbinit: Problems loading AFB driver: $err"
	exit 1
fi

#
#  ucode download error flag - a non-zero flag means there was a failure
#
err_flag=0

#
#  If we can find the binary, then download the microcode to each
#  instance of the afb device present in the system.
#
if [ -f /usr/sbin/afbdaemon ]
then
	#
	#  Now download the microcode to each afb. Note any failures but
	#  continue to attempt to download ucode to other afbs.
	#
	for inst in $devs
	do
		/usr/sbin/afbdaemon /dev/fbs/${inst} >/dev/console  2>&1 &
	done
else
	err_flag=1
fi

#
#  Check to see if ucode download succeeded for all devices
#
if [ $err_flag -ne 0 ] 
then
	exit 1
fi
exit 0
