2 ********************************************************************************
4 * (c) Copyright 2005, http://www.tern.com
6 * - Created to support i2chip module on a variety of TERN hardware platforms.
7 ********************************************************************************
11 #include "i2chip_hw.h"
17 void i2chip_init(void)
22 poke(MMCR,_BOOTCSCTL_,peek(MMCR,_BOOTCSCTL_)&0xffc9); // ROM 1 wait
23 poke(MMCR,_ROMCS2CTL_,peek(MMCR,_ROMCS2CTL_)&0xffc8); // SRAM 0 wait
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
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
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
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
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);
60 pio_init(18, 0); // P18=CTS1 for /PCS2
63 outport(0xfff2, 2); // AUXCON, MCS, Bus 16-bit
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,
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
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
88 pio_init(14,0); // Enable /MCS0
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.
98 WINDOW_RESTORE_BASE; // Equivalent to calling mmc_window(7, 0);
104 void i2chip_set_page(u_int page)
106 u_int new_page = page;
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...
112 outport(0xff74, inport(0xff74) & 0xefff );
114 new_page = page >> 1;
118 mmc_window(7, new_page); // See mmc.c
121 p51_window(new_page);
125 static u_int s_addr = 0xffff;
126 u_char far* i2chip_mkptr(u_int addr)
128 if ((s_addr & 0xff00) == (addr & 0xff00)) // No point... no point...
129 return MK_FP(WINDOW_BASE_SEGM, addr & 0xff);
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
141 return MK_FP(WINDOW_BASE_SEGM, addr & 0xff);
144 void i2chip_set_window(u_int window_addr)
146 s_addr = window_addr;
147 I2CHIP_SET_PAGE(s_addr >> 8);
150 // Still inside #define I2CHIP_WINDOW ...
152 u_int i2chip_get_window(void)
154 return s_addr & 0xff00;
157 void i2chip_push_window(u_int addr)
159 I2CHIP_SET_PAGE(addr>>8);
162 void i2chip_pop_window(void)
164 I2CHIP_SET_PAGE(s_addr >> 8);
167 #ifdef I2CHIP_WINDOW_IO
168 u_char io_read_value(u_char far* addr)
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));
175 void io_write_value(u_char far* addr, u_char value)
177 // Get the last whatever bytes... and write value.
178 outportb(I2CHIP_BASE_SEG + (FP_OFF(addr) & 0xff), value);
181 #endif // I2CHIP_WINDOW_IO
185 void p51_window(unsigned int page)
189 #ifdef I2CHIP_WINDOW_IO
199 #endif // I2CHIP_WINDOW
203 // Function: spu_m_isr
204 // P22=Master PIC IR7, interrupt vector=0x47, /INTA
206 void interrupt far spu_m_isr(void)
209 // Issue the EOI to interrupt controller
210 outportb(_MPICOCW2_IO,0x67); // Specific EQI for master IR7
215 // Function: spu_1_isr
216 // P10=slave1 PIC IR7, Master IR2, interrupt vector=0x4f, /INTC
218 void interrupt far spu_1_isr(void)
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
228 // Function: spu_2_isr
229 // P20=Slave2 PIC IR7, Master IR5, interrupt vector=0x57, GPIRQ7=PIO16 GP timer1
231 void interrupt far spu_2_isr(void)
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