#!/bin/bash

# make the /dev entries for up to 8 COM ports (first 4 are already there).
mknod -m 600 /dev/ttyS4 c 4 68
mknod -m 600 /dev/ttyS5 c 4 69
mknod -m 600 /dev/ttyS6 c 4 70
mknod -m 600 /dev/ttyS7 c 4 71

# Suggested IRQ usage:

#COM port	Product		 jumpers to install
#========	=======		 ==================
#COM3 	on 	TS-5500 use IRQ5 (install jumper on HD3)
#COM3 	on 	TS-SER1 use IRQ5 (install jumper IRQ5)
#COM3-6 on	TS-SER4 use IRQ5 (install IRQ1+IRQ4 and COM2+COM1)
#COM4 	on 	TS-SER1 use IRQ6 (install jumper IRQ6)
#COM4-7 on 	TS-SER4 use IRQ6 (install IRQ2+IRQ4 and COM4)

#Note:

#It's not possible for us to detect a TS-SER1 or TS-SER2
#Please uncomment the corresponding lines if you are using one.
#By default the TS-SER1 and TS-SER2 start at com port 3
#if you are using a base board with more than 2 com ports
#(ie TS-5500 or TS-5700) you need to change the jumpers and
#change the ttysX to the corresponding com port/s

#If you have a TS-SER1 uncomment the following line
#setserial -v /dev/ttys2 auto_irq autoconfig

#If you have a TS-SER2 uncomment the following two lines
#setserial -v /dev/ttys2 auto_irq autoconfig
#setserial -v /dev/ttys3 auto_irq autoconfig


#Lets check if there is a TS-SER4 present
ioReadByte 0x234

if [ $? -eq 122 ];then
	echo Found a TS-SER4
	setserial -v /dev/ttyS4 port 0x3a8 auto_irq autoconfig ^fourport
	setserial -v /dev/ttyS5 port 0x2a8 auto_irq autoconfig ^fourport
	setserial -v /dev/ttyS6 port 0x3a0 auto_irq autoconfig ^fourport
	setserial -v /dev/ttyS7 port 0x2a0 auto_irq autoconfig ^fourport
fi 

#Lets determine what the base board is
SBC=`grep -a TS /proc/SBC/info | awk '{print $3}'`

#Lets check if a TS-5500 is the base board
if [ $SBC == "TS-5500" ];then
	echo Found a TS-5500
	setserial -v /dev/ttyS2 auto_irq autoconfig
fi

#Lets check if a TS-5700 is the base board
if [ $SBC == "TS-5700" ];then
	echo Found a TS-5700
	#write to special I/O register 0x79 on TS-5700 to setup Coms 3&4
	#interrupts
	#0x00 no IRQ for COM3 & COM4 (default)
	#0x01 IRQ5 for COM3 and IRQ6 for COM4
	#0x02 IRQ5 shared for COM3 & COM4
	#0x03 IRQ6 shared for COM3 and COM4
	/usr/bin/ioWrite 0x02 0x79
	setserial -v /dev/ttyS2 auto_irq autoconfig ^fourport
	setserial -v /dev/ttyS3 auto_irq autoconfig ^fourport
fi
