2 * this file included by nicstar.c
7 * Read this ForeRunner's MAC address from eprom/eeprom
10 #include <linux/kernel.h>
12 typedef void __iomem
*virt_addr_t
;
16 /* This was the original definition
17 #define osp_MicroDelay(microsec) \
18 do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
20 #define osp_MicroDelay(microsec) {unsigned long useconds = (microsec); \
24 /* The following tables represent the timing diagrams found in
25 * the Data Sheet for the Xicor X25020 EEProm. The #defines below
26 * represent the bits in the NICStAR's General Purpose register
27 * that must be toggled for the corresponding actions on the EEProm
31 /* Write Data To EEProm from SI line on rising edge of CLK */
32 /* Read Data From EEProm on falling edge of CLK */
34 #define CS_HIGH 0x0002 /* Chip select high */
35 #define CS_LOW 0x0000 /* Chip select low (active low)*/
36 #define CLK_HIGH 0x0004 /* Clock high */
37 #define CLK_LOW 0x0000 /* Clock low */
38 #define SI_HIGH 0x0001 /* Serial input data high */
39 #define SI_LOW 0x0000 /* Serial input data low */
41 /* Read Status Register = 0000 0101b */
43 static u_int32_t rdsrtab
[] =
57 CLK_HIGH
| SI_HIGH
, /* 1 */
61 CLK_HIGH
| SI_HIGH
/* 1 */
66 /* Read from EEPROM = 0000 0011b */
67 static u_int32_t readtab
[] =
85 CLK_HIGH
| SI_HIGH
, /* 1 */
87 CLK_HIGH
| SI_HIGH
/* 1 */
91 /* Clock to read from/write to the eeprom */
92 static u_int32_t clocktab
[] =
114 #define NICSTAR_REG_WRITE(bs, reg, val) \
115 while ( readl(bs + STAT) & 0x0200 ) ; \
116 writel((val),(base)+(reg))
117 #define NICSTAR_REG_READ(bs, reg) \
119 #define NICSTAR_REG_GENERAL_PURPOSE GP
122 * This routine will clock the Read_Status_reg function into the X2520
123 * eeprom, then pull the result from bit 16 of the NicSTaR's General Purpose
128 nicstar_read_eprom_status( virt_addr_t base
)
134 /* Send read instruction */
135 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
137 for (i
=0; i
<ARRAY_SIZE(rdsrtab
); i
++)
139 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
140 (val
| rdsrtab
[i
]) );
141 osp_MicroDelay( CYCLE_DELAY
);
144 /* Done sending instruction - now pull data off of bit 16, MSB first */
145 /* Data clocked out of eeprom on falling edge of clock */
148 for (i
=7, j
=0; i
>=0; i
--)
150 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
151 (val
| clocktab
[j
++]) );
152 rbyte
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
153 & 0x00010000) >> 16) << i
);
154 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
155 (val
| clocktab
[j
++]) );
156 osp_MicroDelay( CYCLE_DELAY
);
158 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
159 osp_MicroDelay( CYCLE_DELAY
);
166 * This routine will clock the Read_data function into the X2520
167 * eeprom, followed by the address to read from, through the NicSTaR's General
172 read_eprom_byte(virt_addr_t base
, u_int8_t offset
)
176 u_int8_t tempread
= 0;
178 val
= NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
180 /* Send READ instruction */
181 for (i
=0; i
<ARRAY_SIZE(readtab
); i
++)
183 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
184 (val
| readtab
[i
]) );
185 osp_MicroDelay( CYCLE_DELAY
);
188 /* Next, we need to send the byte address to read from */
191 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
192 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
193 osp_MicroDelay(CYCLE_DELAY
);
194 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
195 (val
| clocktab
[j
++] | ((offset
>> i
) & 1) ) );
196 osp_MicroDelay( CYCLE_DELAY
);
201 /* Now, we can read data from the eeprom by clocking it in */
204 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
205 (val
| clocktab
[j
++]) );
206 osp_MicroDelay( CYCLE_DELAY
);
207 tempread
|= (((NICSTAR_REG_READ( base
, NICSTAR_REG_GENERAL_PURPOSE
)
208 & 0x00010000) >> 16) << i
);
209 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
,
210 (val
| clocktab
[j
++]) );
211 osp_MicroDelay( CYCLE_DELAY
);
214 NICSTAR_REG_WRITE( base
, NICSTAR_REG_GENERAL_PURPOSE
, 2 );
215 osp_MicroDelay( CYCLE_DELAY
);
221 nicstar_init_eprom( virt_addr_t base
)
226 * turn chip select off
228 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
230 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
231 (val
| CS_HIGH
| CLK_HIGH
));
232 osp_MicroDelay( CYCLE_DELAY
);
234 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
235 (val
| CS_HIGH
| CLK_LOW
));
236 osp_MicroDelay( CYCLE_DELAY
);
238 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
239 (val
| CS_HIGH
| CLK_HIGH
));
240 osp_MicroDelay( CYCLE_DELAY
);
242 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
243 (val
| CS_HIGH
| CLK_LOW
));
244 osp_MicroDelay( CYCLE_DELAY
);
249 * This routine will be the interface to the ReadPromByte function
256 u_int8_t prom_offset
,
262 for (i
=0; i
<nbytes
; i
++)
264 buffer
[i
] = read_eprom_byte( base
, prom_offset
);
266 osp_MicroDelay( CYCLE_DELAY
);
272 void osp_MicroDelay(int x) {