#!/bin/sh
#
# pragma ident	"%Z%%M%	%I%	%E% SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

# XXX install usbser_edge only when usbser module is present?

#
# This function will install a driver if it is present and not already
# installed.
#
install_if_present()
{
	driver=`basename "${1}"`
        grep "^${driver} " $ROOTDIR/etc/name_to_major > /dev/null 2>&1
	if [ $? != 0  -a -f "${1}" ] ; then
		command="add_drv -b ${ROOTDIR} ${2}"
		command="${command} -n ${driver}"
		eval $command || EXIT=1
	fi
}

if [ "$ARCH" = "" ] ; then
	ARCH=`uname -p`
fi

DRVDIR="${ROOTDIR}/kernel/drv"
MISCDIR="${ROOTDIR}/kernel/misc"

if [ `isainfo -b` = "64" ] ; then 
	DRVDIR=${DRVDIR}/sparcv9
	MISCDIR=${MISCDIR}/sparcv9
fi

install_if_present ${DRVDIR}/hid "-i '\"usbif,class3\"' -m '* 0666 root sys'"
install_if_present ${DRVDIR}/hubd "-i '\"usbif,class9\"' -m '* 0644 root sys'"
install_if_present ${DRVDIR}/usb_mid "-i '\"usb,device\"'"
install_if_present ${DRVDIR}/scsa2usb "-i '\"usbif,class8\"'"
install_if_present ${DRVDIR}/usbprn \
    "-i '\"usbif,class7.1\"' -m '* 0666 root sys'"
install_if_present ${DRVDIR}/usb_ac \
    "-i '\"usbif,class1.1\"' -m '* 0600 root sys'"
install_if_present ${DRVDIR}/usb_as \
    "-i '\"usbif,class1.2\"' -m '* 0600 root sys'"
install_if_present ${DRVDIR}/usba10_hid "-m '* 0666 root sys'"
install_if_present ${DRVDIR}/usba10_hubd "-m '* 0644 root sys'"
install_if_present ${DRVDIR}/usba10_scsa2usb " "
install_if_present ${DRVDIR}/usba10_usb_mid " "
install_if_present ${DRVDIR}/usba10_usbprn "-m '* 0666 root sys'"
install_if_present ${DRVDIR}/usba10_usb_ac "-m '* 0600 root sys'"
install_if_present ${DRVDIR}/usba10_usb_as "-m '* 0600 root sys'"

# The following is for the Serial Port driver.
# Different serial port drivers are installed for sparc and X86:
#   sparc: USBA 1.0 and USBA 0.0 both support usb serial driver on ohci
#   x86: USBA 1.0 supports usb serial driver on ohci.  No support on uhci
# All use the following aliases to bind to USB serial port devices.
USBSER_EDGE_ALIASES="\
	\"usbif1608,1.config1.0\" \
	\"usbif1608,3.config1.0\" \
	\"usbif1608,4.config1.0\" \
	\"usbif1608,5.config1.0\" \
	\"usbif1608,6.config1.0\" \
	\"usbif1608,7.config1.0\" \
	\"usbif1608,c.config1.0\" \
	\"usbif1608,d.config1.0\" \
	\"usbif1608,e.config1.0\" \
	\"usbif1608,f.config1.0\" \
	\"usbif1608,10.config1.0\" \
	\"usbif1608,11.config1.0\" \
	\"usbif1608,12.config1.0\" \
	\"usbif1608,13.config1.0\" \
	\"usbif1608,14.config1.0\" \
	\"usbif1608,201.config1.0\" \
	\"usbif1608,205.config1.0\" \
	\"usbif1608,206.config1.0\" \
	\"usbif1608,207.config1.0\" \
	\"usbif1608,20c.config1.0\" \
	\"usbif1608,20d.config1.0\" \
	\"usbif1608,215.config1.0\" \
	\"usbif1608,217.config1.0\" \
	\"usbif1608,21a.config1.0\" \
	\"usbif1608,240.config1.0\" \
	\"usbif1608,241.config1.0\" \
	\"usbif1608,242.config1.0\" \
	\"usbif1608,243.config1.0\" \
	"

case ${ARCH} in
	sparc)
		install_if_present ${DRVDIR}/usbser_edge \
		    "-i '${USBSER_EDGE_ALIASES}' -m '* 0666 root sys'"
		install_if_present ${DRVDIR}/usba10_usbser_edge \
		     "-m '* 0666 root sys'"
		;;
	i386)
		install_if_present ${DRVDIR}/usba10_usbser_edge \
		    " -i '${USBSER_EDGE_ALIASES}' -m '* 0666 root sys'"
		;;
	esac

case ${ARCH} in
	sparc)
		install_if_present ${DRVDIR}/ohci \
		    "-i '\"pciclass,0c0310\"' -m '* 0644 root sys'"
		install_if_present ${DRVDIR}/usba10_ohci \
		    "-i '\"pci1033,35\"' -m '* 0644 root sys'"
		;;
	i386)
		install_if_present ${DRVDIR}/usba10_uhci \
		    "-i '\"pci1106,3038\"' -m '* 0644 root sys'"
		install_if_present ${DRVDIR}/usba10_ohci \
		    "-i '\"pciclass,0c0310\"' -m '* 0644 root sys'"
		;;
	esac
	install_if_present ${DRVDIR}/usba10_ehci \
		    "-i '\"pciclass,0c0320\"' -m '* 0644 root sys'"
