2 * this file included by nicstar.c
7 * Read this ForeRunner's MAC address from eprom/eeprom
12 /* This was the original definition
13 #define osp_MicroDelay(microsec) \
14 do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
16 #define osp_MicroDelay(microsec) {unsigned long useconds = (microsec); \
20 /* The following tables represent the timing diagrams found in
21 * the Data Sheet for the Xicor X25020 EEProm. The #defines below
22 * represent the bits in the NICStAR's General Purpose register
23 * that must be toggled for the corresponding actions on the EEProm
27 /* Write Data To EEProm from SI line on rising edge of CLK */
28 /* Read Data From EEProm on falling edge of CLK */
30 #define CS_HIGH 0x0002 /* Chip select high */
31 #define CS_LOW 0x0000 /* Chip select low (active low)*/
32 #define CLK_HIGH 0x0004 /* Clock high */
33 #define CLK_LOW 0x0000 /* Clock low */
34 #define SI_HIGH 0x0001 /* Serial input data high */
35 #define SI_LOW 0x0000 /* Serial input data low */
37 /* Read Status Register = 0000 0101b */
38 static u_int32_t rdsrtab
[] =
52 CLK_HIGH
| SI_HIGH
, /* 1 */
56 CLK_HIGH
| SI_HIGH
/* 1 */
60 /* Read from EEPROM = 0000 0011b */
61 static u_int32_t readtab
[] =
79 CLK_HIGH
| SI_HIGH
, /* 1 */
81 CLK_HIGH
| SI_HIGH
/* 1 */
85 /* Clock to read from/write to the eeprom */
86 static u_int32_t clocktab
[] =
108 #define NICSTAR_REG_WRITE(bs, reg, val) \
109 while ( readl(bs + STAT) & 0x0200 ) ; \
110 writel((val),(base)+(reg))
111 #define NICSTAR_REG_READ(bs, reg) \
113 #define NICSTAR_REG_GENERAL_PURPOSE GP
116 * This routine will clock the Read_Status_reg function into the X2520
117 * eeprom, then pull the result from bit 16 of the NicSTaR's General Purpose
122 nicstar_read_eprom_status( virt_addr_t base
)
128 /* Send read instruction */
129 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
131 for (i
=0; i
<sizeof rdsrtab
/sizeof rdsrtab
[0]; i
++)
133 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
134 (val
| rdsrtab
[i
]) );
135 osp_MicroDelay( CYCLE_DELAY
);
138 /* Done sending instruction - now pull data off of bit 16, MSB first */
139 /* Data clocked out of eeprom on falling edge of clock */
142 for (i
=7, j
=0; i
>=0; i
--)
144 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
145 (val
| clocktab
[j
++]) );
146 rbyte
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
147 & 0x00010000) >> 16) << i
);
148 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
149 (val
| clocktab
[j
++]) );
150 osp_MicroDelay( CYCLE_DELAY
);
152 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
153 osp_MicroDelay( CYCLE_DELAY
);
159 * This routine will clock the Read_data function into the X2520
160 * eeprom, followed by the address to read from, through the NicSTaR's General
165 read_eprom_byte(u_int32_t base
, u_int8_t offset
)
169 u_int8_t tempread
= 0;
171 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
173 /* Send READ instruction */
174 for (i
=0; i
<sizeof readtab
/sizeof readtab
[0]; i
++)
176 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
177 (val
| readtab
[i
]) );
178 osp_MicroDelay( CYCLE_DELAY
);
181 /* Next, we need to send the byte address to read from */
184 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
185 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
186 osp_MicroDelay(CYCLE_DELAY
);
187 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
188 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
189 osp_MicroDelay( CYCLE_DELAY
);
194 /* Now, we can read data from the eeprom by clocking it in */
197 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
198 (val
| clocktab
[j
++]) );
199 osp_MicroDelay( CYCLE_DELAY
);
200 tempread
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
201 & 0x00010000) >> 16) << i
);
202 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
203 (val
| clocktab
[j
++]) );
204 osp_MicroDelay( CYCLE_DELAY
);
207 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
208 osp_MicroDelay( CYCLE_DELAY
);
214 nicstar_init_eprom( virt_addr_t base
)
219 * turn chip select off
221 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
223 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
224 (val
| CS_HIGH
| CLK_HIGH
));
225 osp_MicroDelay( CYCLE_DELAY
);
227 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
228 (val
| CS_HIGH
| CLK_LOW
));
229 osp_MicroDelay( CYCLE_DELAY
);
231 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
232 (val
| CS_HIGH
| CLK_HIGH
));
233 osp_MicroDelay( CYCLE_DELAY
);
235 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
236 (val
| CS_HIGH
| CLK_LOW
));
237 osp_MicroDelay( CYCLE_DELAY
);
242 * This routine will be the interface to the ReadPromByte function
249 u_int8_t prom_offset
,
255 for (i
=0; i
<nbytes
; i
++)
257 buffer
[i
] = read_eprom_byte( base
, prom_offset
);
259 osp_MicroDelay( CYCLE_DELAY
);
265 void osp_MicroDelay(int x) {