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
;
17 This was the original definition
18 #define osp_MicroDelay(microsec) \
19 do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
21 #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
[] = {
56 CLK_HIGH
| SI_HIGH
, /* 1 */
60 CLK_HIGH
| SI_HIGH
/* 1 */
64 /* Read from EEPROM = 0000 0011b */
65 static u_int32_t readtab
[] = {
82 CLK_HIGH
| SI_HIGH
, /* 1 */
84 CLK_HIGH
| SI_HIGH
/* 1 */
87 /* Clock to read from/write to the eeprom */
88 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
121 u_int32_t
nicstar_read_eprom_status(virt_addr_t base
)
127 /* Send read instruction */
128 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
130 for (i
= 0; i
< ARRAY_SIZE(rdsrtab
); i
++) {
131 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
133 osp_MicroDelay(CYCLE_DELAY
);
136 /* Done sending instruction - now pull data off of bit 16, MSB first */
137 /* Data clocked out of eeprom on falling edge of clock */
140 for (i
= 7, j
= 0; i
>= 0; i
--) {
141 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
142 (val
| clocktab
[j
++]));
143 rbyte
|= (((NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
)
144 & 0x00010000) >> 16) << i
);
145 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
146 (val
| clocktab
[j
++]));
147 osp_MicroDelay(CYCLE_DELAY
);
149 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
, 2);
150 osp_MicroDelay(CYCLE_DELAY
);
156 * This routine will clock the Read_data function into the X2520
157 * eeprom, followed by the address to read from, through the NicSTaR's General
161 static u_int8_t
read_eprom_byte(virt_addr_t base
, u_int8_t offset
)
165 u_int8_t tempread
= 0;
167 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
169 /* Send READ instruction */
170 for (i
= 0; i
< ARRAY_SIZE(readtab
); i
++) {
171 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
173 osp_MicroDelay(CYCLE_DELAY
);
176 /* Next, we need to send the byte address to read from */
177 for (i
= 7; i
>= 0; i
--) {
178 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
179 (val
| clocktab
[j
++] | ((offset
>> i
) & 1)));
180 osp_MicroDelay(CYCLE_DELAY
);
181 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
182 (val
| clocktab
[j
++] | ((offset
>> i
) & 1)));
183 osp_MicroDelay(CYCLE_DELAY
);
188 /* Now, we can read data from the eeprom by clocking it in */
189 for (i
= 7; i
>= 0; i
--) {
190 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
191 (val
| clocktab
[j
++]));
192 osp_MicroDelay(CYCLE_DELAY
);
194 (((NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
)
195 & 0x00010000) >> 16) << i
);
196 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
197 (val
| clocktab
[j
++]));
198 osp_MicroDelay(CYCLE_DELAY
);
201 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
, 2);
202 osp_MicroDelay(CYCLE_DELAY
);
206 static void nicstar_init_eprom(virt_addr_t base
)
211 * turn chip select off
213 val
= NICSTAR_REG_READ(base
, NICSTAR_REG_GENERAL_PURPOSE
) & 0xFFFFFFF0;
215 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
216 (val
| CS_HIGH
| CLK_HIGH
));
217 osp_MicroDelay(CYCLE_DELAY
);
219 NICSTAR_REG_WRITE(base
, NICSTAR_REG_GENERAL_PURPOSE
,
220 (val
| CS_HIGH
| CLK_LOW
));
221 osp_MicroDelay(CYCLE_DELAY
);
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
);
233 * This routine will be the interface to the ReadPromByte function
238 nicstar_read_eprom(virt_addr_t base
,
239 u_int8_t prom_offset
, u_int8_t
* buffer
, u_int32_t nbytes
)
243 for (i
= 0; i
< nbytes
; i
++) {
244 buffer
[i
] = read_eprom_byte(base
, prom_offset
);
246 osp_MicroDelay(CYCLE_DELAY
);