2 * this file included by nicstar.c
7 * Read this ForeRunner's MAC address from eprom/eeprom
10 typedef void __iomem
*virt_addr_t
;
14 /* This was the original definition
15 #define osp_MicroDelay(microsec) \
16 do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
18 #define osp_MicroDelay(microsec) {unsigned long useconds = (microsec); \
22 /* The following tables represent the timing diagrams found in
23 * the Data Sheet for the Xicor X25020 EEProm. The #defines below
24 * represent the bits in the NICStAR's General Purpose register
25 * that must be toggled for the corresponding actions on the EEProm
29 /* Write Data To EEProm from SI line on rising edge of CLK */
30 /* Read Data From EEProm on falling edge of CLK */
32 #define CS_HIGH 0x0002 /* Chip select high */
33 #define CS_LOW 0x0000 /* Chip select low (active low)*/
34 #define CLK_HIGH 0x0004 /* Clock high */
35 #define CLK_LOW 0x0000 /* Clock low */
36 #define SI_HIGH 0x0001 /* Serial input data high */
37 #define SI_LOW 0x0000 /* Serial input data low */
39 /* Read Status Register = 0000 0101b */
41 static u_int32_t rdsrtab
[] =
55 CLK_HIGH
| SI_HIGH
, /* 1 */
59 CLK_HIGH
| SI_HIGH
/* 1 */
64 /* Read from EEPROM = 0000 0011b */
65 static u_int32_t readtab
[] =
83 CLK_HIGH
| SI_HIGH
, /* 1 */
85 CLK_HIGH
| SI_HIGH
/* 1 */
89 /* Clock to read from/write to the eeprom */
90 static u_int32_t clocktab
[] =
112 #define NICSTAR_REG_WRITE(bs, reg, val) \
113 while ( readl(bs + STAT) & 0x0200 ) ; \
114 writel((val),(base)+(reg))
115 #define NICSTAR_REG_READ(bs, reg) \
117 #define NICSTAR_REG_GENERAL_PURPOSE GP
120 * This routine will clock the Read_Status_reg function into the X2520
121 * eeprom, then pull the result from bit 16 of the NicSTaR's General Purpose
126 nicstar_read_eprom_status( virt_addr_t base
)
132 /* Send read instruction */
133 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
135 for (i
=0; i
<sizeof rdsrtab
/sizeof rdsrtab
[0]; i
++)
137 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
138 (val
| rdsrtab
[i
]) );
139 osp_MicroDelay( CYCLE_DELAY
);
142 /* Done sending instruction - now pull data off of bit 16, MSB first */
143 /* Data clocked out of eeprom on falling edge of clock */
146 for (i
=7, j
=0; i
>=0; i
--)
148 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
149 (val
| clocktab
[j
++]) );
150 rbyte
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
151 & 0x00010000) >> 16) << i
);
152 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
153 (val
| clocktab
[j
++]) );
154 osp_MicroDelay( CYCLE_DELAY
);
156 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
157 osp_MicroDelay( CYCLE_DELAY
);
164 * This routine will clock the Read_data function into the X2520
165 * eeprom, followed by the address to read from, through the NicSTaR's General
170 read_eprom_byte(virt_addr_t base
, u_int8_t offset
)
174 u_int8_t tempread
= 0;
176 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
178 /* Send READ instruction */
179 for (i
=0; i
<sizeof readtab
/sizeof readtab
[0]; i
++)
181 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
182 (val
| readtab
[i
]) );
183 osp_MicroDelay( CYCLE_DELAY
);
186 /* Next, we need to send the byte address to read from */
189 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
190 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
191 osp_MicroDelay(CYCLE_DELAY
);
192 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
193 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
194 osp_MicroDelay( CYCLE_DELAY
);
199 /* Now, we can read data from the eeprom by clocking it in */
202 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
203 (val
| clocktab
[j
++]) );
204 osp_MicroDelay( CYCLE_DELAY
);
205 tempread
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
206 & 0x00010000) >> 16) << i
);
207 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
208 (val
| clocktab
[j
++]) );
209 osp_MicroDelay( CYCLE_DELAY
);
212 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
213 osp_MicroDelay( CYCLE_DELAY
);
219 nicstar_init_eprom( virt_addr_t base
)
224 * turn chip select off
226 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
228 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
229 (val
| CS_HIGH
| CLK_HIGH
));
230 osp_MicroDelay( CYCLE_DELAY
);
232 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
233 (val
| CS_HIGH
| CLK_LOW
));
234 osp_MicroDelay( CYCLE_DELAY
);
236 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
237 (val
| CS_HIGH
| CLK_HIGH
));
238 osp_MicroDelay( CYCLE_DELAY
);
240 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
241 (val
| CS_HIGH
| CLK_LOW
));
242 osp_MicroDelay( CYCLE_DELAY
);
247 * This routine will be the interface to the ReadPromByte function
254 u_int8_t prom_offset
,
260 for (i
=0; i
<nbytes
; i
++)
262 buffer
[i
] = read_eprom_byte( base
, prom_offset
);
264 osp_MicroDelay( CYCLE_DELAY
);
270 void osp_MicroDelay(int x) {