#!/bin/sh
#
# This file is used to setup the gpio ports: per application.
#
# Setup ports a,b,f,h.
#
# Use: portX init_val pin_use_bitmask
# 	pin_use_bitmask: 1=output 0=input
#
# PORTA:
#	Bit 7 : 1 : Out : CS_SERIAL_FLASH#
#	Bit 6 : 1 : Inp : Unused
#	Bit 5 : 1 : Inp : Unused
#	Bit 4 : 1 : Inp : Unused
#
#	Bit 3 : 1 : Inp : Unused
#	Bit 2 : 1 : Inp : Unused
#	Bit 1 : 1 : Out : SW_RESET#
#	Bit 0 : 1 : Inp : PARALLEL_FLASH_STATUS
#
# PORTA has already been setup by a special version of redboot, so
# we won't do it again here
#
#porta 0xff 0x82
#
# PORTB:
#	Bit 7 : 1 : Inp : Unused
#	Bit 6 : 1 : Inp : Unused
#	Bit 5 : 1 : Inp : Unused
#	Bit 4 : 1 : Out : RES_CPU#
#
#	Bit 3 : 1 : Inp : Unused
#	Bit 2 : 1 : Out : BOOT_ACK
#	Bit 1 : 1 : Inp : Unused
#	Bit 0 : 1 : Inp : Unused
#
portb 0xfb 0x14
#
# PORTF:
#	Bit 7 : 1 : Inp : NC
#	Bit 6 : 1 : Inp : NC
#	Bit 5 : 1 : Inp : NC
#	Bit 4 : 1 : Inp : NC
#
#	Bit 3 : 1 : Inp : Unused
#	Bit 2 : 1 : Inp : Unused
#	Bit 1 : 1 : Inp : Unused
#	Bit 0 : 1 : Inp : NC
#
portf 0xff 0x08
#
# PORTH:
#	Bit 7 : 1 : Inp : NC
#	Bit 6 : 1 : Inp : NC
#	Bit 5 : 1 : Inp : Unused
#	Bit 4 : 1 : Inp : Unused
#
#	Bit 3 : 1 : Inp : USB Power
#	Bit 2 : 1 : Inp : Unused
#	Bit 1 : 1 : Inp : NC
#	Bit 0 : 1 : Inp : NC
#
porth 0xff 0x08

# Reset switch controller properly                                              
porta 0xfd                                                                      
sleep 2                                                                         
porta 0xff                                                                      
sleep 2                                                                         
                                                                                
# Enable ports 1 to 5                                                           
for i in 0 1 2 3 4                                                              
do                                                                              
   /app/bin/miireg $i 0 0x3100                                                  
done                                                                            
                                                                                
#Enable management port                                                         
/app/bin/miireg 6 22 0x873d                                                     
                                                                                
#Create VLANs                                                                   
/app/bin/miireg 0 18 0x7ebb                                                     
                                                                                
/app/bin/miireg 0 25 0xe001                                                     
/app/bin/miireg 1 25 0xe002                                                     
/app/bin/miireg 2 25 0xe003                                                     
                                                                                
/app/bin/miireg 0 24 0x0eef                                                     
/app/bin/miireg 1 24 0x0ef0                                                     
/app/bin/miireg 2 24 0x0eff                                                     
/app/bin/miireg 3 24 0x0ec0                                                     
/app/bin/miireg 4 24 0x1ec0                                                     
                                                                                
/app/bin/miireg 0 16 0x87fa                                                     
/app/bin/miireg 0 26 0x2000                                                     
/app/bin/miireg 0 16 0x07fa                                                     
                                                                                
/app/bin/miireg 0 22 0x8771                                                     
/app/bin/miireg 1 22 0x8771                                                     
/app/bin/miireg 2 22 0x8771                                                     
/app/bin/miireg 3 22 0x8771                                                     
/app/bin/miireg 4 22 0x8771
