Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / obp / obp / dev / network / ophir / eeprom.fth
CommitLineData
920dae64
AT
1\ ========== Copyright Header Begin ==========================================
2\
3\ Hypervisor Software File: eeprom.fth
4\
5\ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
6\
7\ - Do no alter or remove copyright notices
8\
9\ - Redistribution and use of this software in source and binary forms, with
10\ or without modification, are permitted provided that the following
11\ conditions are met:
12\
13\ - Redistribution of source code must retain the above copyright notice,
14\ this list of conditions and the following disclaimer.
15\
16\ - Redistribution in binary form must reproduce the above copyright notice,
17\ this list of conditions and the following disclaimer in the
18\ documentation and/or other materials provided with the distribution.
19\
20\ Neither the name of Sun Microsystems, Inc. or the names of contributors
21\ may be used to endorse or promote products derived from this software
22\ without specific prior written permission.
23\
24\ This software is provided "AS IS," without a warranty of any kind.
25\ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
26\ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
27\ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN
28\ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR
29\ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
30\ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN
31\ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR
32\ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE
33\ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY,
34\ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF
35\ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
36\
37\ You acknowledge that this software is not designed, licensed or
38\ intended for use in the design, construction, operation or maintenance of
39\ any nuclear facility.
40\
41\ ========== Copyright Header End ============================================
42id: @(#)eeprom.fth 1.1 06/02/16
43purpose:
44copyright: Copyright 2006 Sun Microsystems, Inc. All Rights Reserved
45copyright: Use is subject to license terms.
46
47\ Number of bits in the EEPROM address
48d# 16 constant /eepromaddr
49
50: eec@ ( -- data ) h# 10 reg@ ;
51: eer@ ( -- data ) h# 14 reg@ ;
52: eec! ( data -- ) h# 10 reg! ;
53: eer! ( data -- ) h# 14 reg! ;
54
55: setbit ( bit -- ) eec@ or eec! ;
56: clrbit ( bit -- ) invert eec@ and eec! ;
57
58: set-eesk ( -- ) 1 setbit ;
59: set-eecs ( -- ) 2 setbit ;
60: set-eedi ( -- ) 4 setbit ;
61: clear-eesk ( -- ) 1 clrbit ;
62: clear-eecs ( -- ) 2 clrbit ;
63: clear-eedi ( -- ) 4 clrbit ;
64
65: get-eedo ( -- bit ) eec@ 3 >> 1 and ;
66
67: clock-tick ( -- ) set-eesk clear-eesk ;
68
69: eeprom-request ( -- )
70 1 6 << setbit
71 begin
72 eec@ 1 7 << and
73 until
74;
75
76: eeprom-relenquish ( -- )
77 1 6 << clrbit
78;
79
80: send0 ( -- ) clear-eedi clock-tick ;
81: send1 ( -- ) set-eedi clock-tick ;
82
83\ 0b00000101 = Read Status Register
84: (rdsr) ( -- status )
85 clear-eecs
86 send0 send0 send0 send0 send0 send1 send0 send1
87 0 8 0 do
88 get-eedo 7 i - << or clock-tick
89 loop
90 set-eecs
91;
92
93: rdsr ( -- status )
94 clear-eesk
95 eeprom-request
96 (rdsr)
97 eeprom-relenquish
98;
99
100\ 0b00000110 = Write enable
101: wren ( -- )
102 clear-eecs
103 send0 send0 send0 send0 send0 send1 send1 send0
104 set-eecs
105 clock-tick
106;
107
108\ We shouldn't need the timeout here, but we don't want to hang the system if
109\ something is wrong with the Ophir device. Ten seconds is a reasonable timeout.
110d# 10000 constant write-timeout
111
112\ This is the guts of the bit-bang interface to the Intel Ophir EEPROM. For
113\ the specifics on the protocol, see the PRM.
114: (eeprom!) ( byte addr -- )
115 get-msecs ( start )
116 begin ( start )
117 (rdsr) 1 and 0= ( start ready? )
118 over get-msecs swap - ( start ready? time )
119 write-timeout > or ( start done? )
120 until ( start )
121 get-msecs swap - write-timeout > if
122 cmn-error[ " Timeout waiting for PROM RDY signal." ]cmn-end abort
123 then
124 wren
125 clear-eecs
126 send0 send0 send0 send0 send0 send0 send1 send0
127 1 /eepromaddr <<
128 /eepromaddr 0 do
129 1 >> 2dup and if send1 else send0 then
130 loop
131 2drop
132 1 8 <<
133 8 0 do
134 1 >> 2dup and if send1 else send0 then
135 loop
136 2drop
137 set-eecs
138;
139
140\ Request access to the EEPROM, then store a word
141: eeprom-w! ( data addr -- )
142 2* clear-eesk eeprom-request ( data addr )
143 tuck swap wbsplit ( addr addr data.lo data.hi )
144 rot 1+ (eeprom!) ( addr data.lo )
145 swap (eeprom!) ( )
146 eeprom-relenquish ( )
147;
148
149\ Read a word from the EEPROM by setting the start bit
150\ and waiting for the done bit. First make sure that the
151\ device is not in use.
152: eeprom-w@ ( addr -- data )
153 eeprom-relenquish ( addr )
154 2 << 1 or eer! ( )
155 begin ( )
156 eer@ 2 and ( )
157 until ( )
158 h# 14 reg@ d# 16 >> ( data )
159;
160
161\ Calculate the checksum. Intel's algorithm for this is to modify
162\ checksum byte 0x40 so that the first 64 bytes add up to 0xbaba
163: checksum ( -- sum )
164 0 d# 63 0 do
165 i eeprom-w@ +
166 loop
167 h# baba swap - h# ffff and
168;
169