| 1 |
585 |
jeremybenn |
/*
|
| 2 |
|
|
********************************************************************************
|
| 3 |
|
|
* TERN, Inc.
|
| 4 |
|
|
* (c) Copyright 2005, http://www.tern.com
|
| 5 |
|
|
*
|
| 6 |
|
|
* - Created to support i2chip module on a variety of TERN hardware platforms.
|
| 7 |
|
|
********************************************************************************
|
| 8 |
|
|
*/
|
| 9 |
|
|
|
| 10 |
|
|
#include <embedded.h>
|
| 11 |
|
|
#include "i2chip_hw.h"
|
| 12 |
|
|
|
| 13 |
|
|
#ifdef I2CHIP_MMC
|
| 14 |
|
|
#include "mmc.h"
|
| 15 |
|
|
#endif
|
| 16 |
|
|
|
| 17 |
|
|
void i2chip_init(void)
|
| 18 |
|
|
{
|
| 19 |
|
|
|
| 20 |
|
|
#ifdef TERN_586
|
| 21 |
|
|
/*
|
| 22 |
|
|
poke(MMCR,_BOOTCSCTL_,peek(MMCR,_BOOTCSCTL_)&0xffc9); // ROM 1 wait
|
| 23 |
|
|
poke(MMCR,_ROMCS2CTL_,peek(MMCR,_ROMCS2CTL_)&0xffc8); // SRAM 0 wait
|
| 24 |
|
|
|
| 25 |
|
|
pokeb(MMCR, _GPCSRT_, 24); // set the GP CS recovery time, 12 works
|
| 26 |
|
|
pokeb(MMCR, _GPCSPW_, 128); // set the GP CS width, 64 works
|
| 27 |
|
|
pokeb(MMCR, _GPCSOFF_, 16); // set the GP CS offset, 8 works
|
| 28 |
|
|
pokeb(MMCR, _GPRDW_, 80); // set the GP RD pulse width, 50 works
|
| 29 |
|
|
pokeb(MMCR, _GPRDOFF_, 30); // set the GP RD offset, 15 works
|
| 30 |
|
|
pokeb(MMCR, _GPWRW_, 80); // set the GP WR pulse width, 50
|
| 31 |
|
|
pokeb(MMCR, _GPWROFF_, 30); // set the GP WR offset, 15
|
| 32 |
|
|
*/
|
| 33 |
|
|
|
| 34 |
|
|
#ifdef TERN_5E
|
| 35 |
|
|
pokeb(MMCR, _GPCSDW_, peekb(MMCR, _GPCSDW_)&0xf7); // set /CS3-/CSM Data Width=8
|
| 36 |
|
|
pokeb(MMCR, _CSPFS_, peekb(MMCR, _CSPFS_)|0x08); // set the GP CS3 PIN Function
|
| 37 |
|
|
poke(MMCR, _PAR15_, 0x2000); // set CS3 I/O region
|
| 38 |
|
|
poke(MMCR, _PAR15_+2, 0x2dff); // set CS3 I/O region, 512 bytes
|
| 39 |
|
|
|
| 40 |
|
|
pokeb(MMCR, _GPCSDW_, peekb(MMCR, _GPCSDW_)&0x7f); // CS7=J4.3 Data Width=8, /CSI
|
| 41 |
|
|
// pokeb(MMCR, _GPCSDW_, peekb(MMCR, _GPCSDW_)|0x80); // CS7=J4.3 Data Width=16
|
| 42 |
|
|
pokeb(MMCR, _CSPFS_, peekb(MMCR, _CSPFS_)|0x80); // set the GP CS7 PIN Function
|
| 43 |
|
|
poke(MMCR, _PAR7_, 0x4000); // set CS7 I/O region
|
| 44 |
|
|
poke(MMCR, _PAR7_+2, 0x3dff); // set CS7 I/O region, 512 bytes
|
| 45 |
|
|
#else
|
| 46 |
|
|
// If it's not 5E, then it must be 5P... in which case, we use PCS0 and
|
| 47 |
|
|
// PCS1 as the chip-selects.
|
| 48 |
|
|
pokeb(MMCR, _GPCSDW_, peekb(MMCR, _GPCSDW_)&0xfe); // CS0 Data Width=8
|
| 49 |
|
|
poke(MMCR, _PIOPFS31_16_, peek(MMCR,_PIOPFS31_16_)|0x0800); // P27=/CS0
|
| 50 |
|
|
poke(MMCR, _PAR13_, 0x1800); // CS0 I/O region
|
| 51 |
|
|
poke(MMCR, _PAR13_+2, 0x21ff); // CS0 I/O RW, 512 bytes, start 0x1800
|
| 52 |
|
|
#endif
|
| 53 |
|
|
|
| 54 |
|
|
a HLPRsetvect(0x47, (void far *) spu_m_isr);
|
| 55 |
|
|
HLPRsetvect(0x4f, (void far *) spu_1_isr);
|
| 56 |
|
|
HLPRsetvect(0x57, (void far *) spu_2_isr);
|
| 57 |
|
|
#endif // 186, or RE
|
| 58 |
|
|
|
| 59 |
|
|
#ifdef TERN_186
|
| 60 |
|
|
pio_init(18, 0); // P18=CTS1 for /PCS2
|
| 61 |
|
|
|
| 62 |
|
|
#ifdef TERN_16_BIT
|
| 63 |
|
|
outport(0xfff2, 2); // AUXCON, MCS, Bus 16-bit
|
| 64 |
|
|
#endif
|
| 65 |
|
|
|
| 66 |
|
|
#ifdef I2CHIP_MCS_DIRECT
|
| 67 |
|
|
outport(0xffa0,0xc0bf); // UMCS, 256K ROM, disable AD15-0
|
| 68 |
|
|
outport(0xfff0,inport(0xfff0)|0x4000 ); // SYSCON, MCS0 0x80000-0xbffff
|
| 69 |
|
|
outport(0xffa8,0xa0bf ); // MPCS, MCS0=P14, 64KB, PCS I/O,
|
| 70 |
|
|
outport(0xffa6,0x81ff); // MMCS, base 0x80000,
|
| 71 |
|
|
outport(0xffa2,0x7fbf); // 512K RAM,
|
| 72 |
|
|
outport(0xffa4,0x007d); // PACS, base 0,
|
| 73 |
|
|
|
| 74 |
|
|
#else
|
| 75 |
|
|
|
| 76 |
|
|
outport( 0xffa0,0xc0bf); // UMCS, 256K ROM, 3 wait, disable AD15-0
|
| 77 |
|
|
outport( 0xfff0,inport(0xfff0)|0x4000 ); // SYSCON, MCS0 0x80000-0xbffff
|
| 78 |
|
|
// outport( 0xffa8,0xa0bc ); // MPCS, MCS0=P14, 64KB, PCS I/O 0 wait
|
| 79 |
|
|
// outport( 0xffa8,0xa0bd ); // MPCS, MCS0=P14, 64KB, PCS I/O 1 wait
|
| 80 |
|
|
outport( 0xffa8,0xa0bf ); // MPCS, MCS0=P14, 64KB, PCS I/O 1 wait
|
| 81 |
|
|
#endif // I2CHIP_MCS_DIRECT
|
| 82 |
|
|
|
| 83 |
|
|
#ifndef TERN_RE // 80 MHz R- boards can't tolerate zero wait state.
|
| 84 |
|
|
outport( 0xffa6,0x81ff ); // MMCS, base 0x80000
|
| 85 |
|
|
outport(0xffa2,0x7fbe); // 512K RAM, 0 wait states
|
| 86 |
|
|
outport(0xffa4,0x007d); // PACS, base 0, 0 wait
|
| 87 |
|
|
#endif
|
| 88 |
|
|
pio_init(14,0); // Enable /MCS0
|
| 89 |
|
|
|
| 90 |
|
|
#endif // TERN_186
|
| 91 |
|
|
|
| 92 |
|
|
|
| 93 |
|
|
#ifdef I2CHIP_WINDOW
|
| 94 |
|
|
#ifdef I2CHIP_SHIFTED_ADDRESS
|
| 95 |
|
|
pio_init(12, 2); // Configure P12 as A7, an output we'll be using.
|
| 96 |
|
|
pio_wr(12, 0); // Set A7 low, initially.
|
| 97 |
|
|
#endif
|
| 98 |
|
|
WINDOW_RESTORE_BASE; // Equivalent to calling mmc_window(7, 0);
|
| 99 |
|
|
#endif
|
| 100 |
|
|
}
|
| 101 |
|
|
|
| 102 |
|
|
#ifdef I2CHIP_WINDOW
|
| 103 |
|
|
|
| 104 |
|
|
void i2chip_set_page(u_int page)
|
| 105 |
|
|
{
|
| 106 |
|
|
u_int new_page = page;
|
| 107 |
|
|
|
| 108 |
|
|
#ifdef I2CHIP_SHIFTED_ADDRESS
|
| 109 |
|
|
if (page & 0x01) // ... we're checking the right-most bit in the page.
|
| 110 |
|
|
outport(0xff74, inport(0xff74) | 0x1000 ); // Using P12 as A7...
|
| 111 |
|
|
else
|
| 112 |
|
|
outport(0xff74, inport(0xff74) & 0xefff );
|
| 113 |
|
|
|
| 114 |
|
|
new_page = page >> 1;
|
| 115 |
|
|
#endif
|
| 116 |
|
|
|
| 117 |
|
|
#ifdef I2CHIP_MMC
|
| 118 |
|
|
mmc_window(7, new_page); // See mmc.c
|
| 119 |
|
|
#endif
|
| 120 |
|
|
#ifdef I2CHIP_P51
|
| 121 |
|
|
p51_window(new_page);
|
| 122 |
|
|
#endif
|
| 123 |
|
|
}
|
| 124 |
|
|
|
| 125 |
|
|
static u_int s_addr = 0xffff;
|
| 126 |
|
|
u_char far* i2chip_mkptr(u_int addr)
|
| 127 |
|
|
{
|
| 128 |
|
|
if ((s_addr & 0xff00) == (addr & 0xff00)) // No point... no point...
|
| 129 |
|
|
return MK_FP(WINDOW_BASE_SEGM, addr & 0xff);
|
| 130 |
|
|
|
| 131 |
|
|
s_addr = addr ;
|
| 132 |
|
|
|
| 133 |
|
|
// So the argument to this function is... what again?
|
| 134 |
|
|
// I think it should be the highest 16-bits... or, in other words,
|
| 135 |
|
|
// FP_SEG of a huge ptr.
|
| 136 |
|
|
// Ok, and the *return* value should be a UINT value for the new
|
| 137 |
|
|
// segment address to be used, if it's at all needed. TODO
|
| 138 |
|
|
I2CHIP_SET_PAGE(s_addr >> 8); // Portable version
|
| 139 |
|
|
// outportb(0x00, addr>>8); // quicker version
|
| 140 |
|
|
|
| 141 |
|
|
return MK_FP(WINDOW_BASE_SEGM, addr & 0xff);
|
| 142 |
|
|
}
|
| 143 |
|
|
|
| 144 |
|
|
void i2chip_set_window(u_int window_addr)
|
| 145 |
|
|
{
|
| 146 |
|
|
s_addr = window_addr;
|
| 147 |
|
|
I2CHIP_SET_PAGE(s_addr >> 8);
|
| 148 |
|
|
}
|
| 149 |
|
|
|
| 150 |
|
|
// Still inside #define I2CHIP_WINDOW ...
|
| 151 |
|
|
|
| 152 |
|
|
u_int i2chip_get_window(void)
|
| 153 |
|
|
{
|
| 154 |
|
|
return s_addr & 0xff00;
|
| 155 |
|
|
}
|
| 156 |
|
|
|
| 157 |
|
|
void i2chip_push_window(u_int addr)
|
| 158 |
|
|
{
|
| 159 |
|
|
I2CHIP_SET_PAGE(addr>>8);
|
| 160 |
|
|
}
|
| 161 |
|
|
|
| 162 |
|
|
void i2chip_pop_window(void)
|
| 163 |
|
|
{
|
| 164 |
|
|
I2CHIP_SET_PAGE(s_addr >> 8);
|
| 165 |
|
|
}
|
| 166 |
|
|
|
| 167 |
|
|
#ifdef I2CHIP_WINDOW_IO
|
| 168 |
|
|
u_char io_read_value(u_char far* addr)
|
| 169 |
|
|
{
|
| 170 |
|
|
// return value ... we assume the page is already set. So, instead,
|
| 171 |
|
|
// we just go ahead and output valeu.
|
| 172 |
|
|
return inportb(I2CHIP_BASE_SEG + (FP_OFF(addr) & 0xff));
|
| 173 |
|
|
}
|
| 174 |
|
|
|
| 175 |
|
|
void io_write_value(u_char far* addr, u_char value)
|
| 176 |
|
|
{
|
| 177 |
|
|
// Get the last whatever bytes... and write value.
|
| 178 |
|
|
outportb(I2CHIP_BASE_SEG + (FP_OFF(addr) & 0xff), value);
|
| 179 |
|
|
}
|
| 180 |
|
|
|
| 181 |
|
|
#endif // I2CHIP_WINDOW_IO
|
| 182 |
|
|
|
| 183 |
|
|
|
| 184 |
|
|
#ifdef I2CHIP_P51
|
| 185 |
|
|
void p51_window(unsigned int page)
|
| 186 |
|
|
{
|
| 187 |
|
|
asm xor ax, ax
|
| 188 |
|
|
asm mov ax, page
|
| 189 |
|
|
#ifdef I2CHIP_WINDOW_IO
|
| 190 |
|
|
asm mov dx, 1040h
|
| 191 |
|
|
asm out dx, al
|
| 192 |
|
|
#else
|
| 193 |
|
|
asm out 040h, al
|
| 194 |
|
|
#endif
|
| 195 |
|
|
// use J1.19=/CS6
|
| 196 |
|
|
}
|
| 197 |
|
|
#endif // I2CHIP_P51
|
| 198 |
|
|
|
| 199 |
|
|
#endif // I2CHIP_WINDOW
|
| 200 |
|
|
|
| 201 |
|
|
#ifdef TERN_586
|
| 202 |
|
|
/*
|
| 203 |
|
|
// Function: spu_m_isr
|
| 204 |
|
|
// P22=Master PIC IR7, interrupt vector=0x47, /INTA
|
| 205 |
|
|
*/
|
| 206 |
|
|
void interrupt far spu_m_isr(void)
|
| 207 |
|
|
{
|
| 208 |
|
|
disable();
|
| 209 |
|
|
// Issue the EOI to interrupt controller
|
| 210 |
|
|
outportb(_MPICOCW2_IO,0x67); // Specific EQI for master IR7
|
| 211 |
|
|
enable();
|
| 212 |
|
|
}
|
| 213 |
|
|
|
| 214 |
|
|
/*
|
| 215 |
|
|
// Function: spu_1_isr
|
| 216 |
|
|
// P10=slave1 PIC IR7, Master IR2, interrupt vector=0x4f, /INTC
|
| 217 |
|
|
*/
|
| 218 |
|
|
void interrupt far spu_1_isr(void)
|
| 219 |
|
|
{
|
| 220 |
|
|
disable();
|
| 221 |
|
|
// Issue the EOI to interrupt controller
|
| 222 |
|
|
outportb(_S1PICOCW2_IO,0x67); // Specific EOI for slave 1 IR7
|
| 223 |
|
|
outportb(_MPICOCW2_IO,0x62); // Specific EQI for master IR2
|
| 224 |
|
|
enable();
|
| 225 |
|
|
}
|
| 226 |
|
|
|
| 227 |
|
|
/*
|
| 228 |
|
|
// Function: spu_2_isr
|
| 229 |
|
|
// P20=Slave2 PIC IR7, Master IR5, interrupt vector=0x57, GPIRQ7=PIO16 GP timer1
|
| 230 |
|
|
*/
|
| 231 |
|
|
void interrupt far spu_2_isr(void)
|
| 232 |
|
|
{
|
| 233 |
|
|
disable();
|
| 234 |
|
|
// Issue the EOI to interrupt controller
|
| 235 |
|
|
outportb(_S2PICOCW2_IO,0x67); // Specific EOI for slave 1 IR7
|
| 236 |
|
|
outportb(_MPICOCW2_IO,0x65); // Specific EQI for master IR5
|
| 237 |
|
|
enable();
|
| 238 |
|
|
}
|
| 239 |
|
|
#endif
|