#!/bin/sh
#ident	"@(#)leoconfig.sh	5.2	96/06/26 SMI"
#
# Copyright (c) 1991 by Sun Microsystems, Inc.
#
# /etc/rc2.d/S91leoconfig - Configure for the Leo.

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

#
#  Uncomment the appropriate line to specify a monitor.
#

MONTYPE="-m default"		# Probe the monitor for its type
# MONTYPE="-m 1024_60"          # 1024x768 @60Hz.
# MONTYPE="-m 1024_76"          # 1024x768 @76Hz.
# MONTYPE="-m 1152_66"          # 1152x900 @66Hz.
# MONTYPE="-m 1152_76"          # 1152x900 @76Hz.
# MONTYPE="-m 1280_67"          # 1280x1024 @67Hz.
# MONTYPE="-m 1280_76"          # 1280x1024 @76Hz.
# MONTYPE="-m stereo_108"       # 960x640 stereo @108Hz.
# MONTYPE="-m stereo_114"       # 960x640 stereo @114Hz.
# MONTYPE="-m ntsc"		#
# MONTYPE="-m pal"		#

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

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

#
# 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 leo, so modload the driver and
# make sure that it was successful.  Default
# to sun4m if uname -i doesn't give us something.
#
plat=`uname -i`
if [ "$plat" = "" ]
then
	plat=sun4m
fi

err=`modload /platform/$plat/kernel/drv/leo 2>&1`
if [ $? -ne 0 ]
then
	if [ `uname -m` = "sun4c" ]
	then
		echo "The ZX graphics frame buffer is not supported on sun4c."
	else
	        echo "Problems loading Leo driver: $err"
	fi
	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 leo device present in the system.
#
if [ -f /usr/sbin/leoconfig ]
then
	#
	#  Now download the microcode to each leo. Note any failures but
	#  continue to attempt to download ucode to other leos.
	#
	for inst in $devs
	do
		errmsg="`/usr/sbin/leoconfig ${MONTYPE} -d $devpath/$inst -I /usr/lib 2>&1`"
		if [ -n "$errmsg" ]
		then
			echo "$errmsg"
			err_flag=1
		fi
	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
