1 // SPDX-License-Identifier: GPL-2.0
3 * this file included by nicstar.c
8 * Read this ForeRunner's MAC address from eprom/eeprom
11 #include <linux/kernel.h>
13 typedef void __iomem *virt_addr_t;
18 This was the original definition
19 #define osp_MicroDelay(microsec) \
20 do { int _i = 4*microsec; while (--_i > 0) { __SLOW_DOWN_IO; }} while (0)
22 #define osp_MicroDelay(microsec) {unsigned long useconds = (microsec); \
25 * The following tables represent the timing diagrams found in
26 * the Data Sheet for the Xicor X25020 EEProm. The #defines below
27 * represent the bits in the NICStAR's General Purpose register
28 * that must be toggled for the corresponding actions on the EEProm
32 /* Write Data To EEProm from SI line on rising edge of CLK */
33 /* Read Data From EEProm on falling edge of CLK */
35 #define CS_HIGH 0x0002 /* Chip select high */
36 #define CS_LOW 0x0000 /* Chip select low (active low) */
37 #define CLK_HIGH 0x0004 /* Clock high */
38 #define CLK_LOW 0x0000 /* Clock low */
39 #define SI_HIGH 0x0001 /* Serial input data high */
40 #define SI_LOW 0x0000 /* Serial input data low */
42 /* Read Status Register = 0000 0101b */
44 static u_int32_t rdsrtab[] = {
57 CLK_HIGH | SI_HIGH, /* 1 */
61 CLK_HIGH | SI_HIGH /* 1 */
65 /* Read from EEPROM = 0000 0011b */
66 static u_int32_t readtab[] = {
83 CLK_HIGH | SI_HIGH, /* 1 */
85 CLK_HIGH | SI_HIGH /* 1 */
88 /* Clock to read from/write to the eeprom */
89 static u_int32_t clocktab[] = {
109 #define NICSTAR_REG_WRITE(bs, reg, val) \
110 while ( readl(bs + STAT) & 0x0200 ) ; \
111 writel((val),(base)+(reg))
112 #define NICSTAR_REG_READ(bs, reg) \
114 #define NICSTAR_REG_GENERAL_PURPOSE GP
117 * This routine will clock the Read_Status_reg function into the X2520
118 * eeprom, then pull the result from bit 16 of the NicSTaR's General Purpose
122 u_int32_t 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 < ARRAY_SIZE(rdsrtab); i++) {
132 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
134 osp_MicroDelay(CYCLE_DELAY);
137 /* Done sending instruction - now pull data off of bit 16, MSB first */
138 /* Data clocked out of eeprom on falling edge of clock */
141 for (i = 7, j = 0; i >= 0; i--) {
142 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
143 (val | clocktab[j++]));
144 rbyte |= (((NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE)
145 & 0x00010000) >> 16) << i);
146 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
147 (val | clocktab[j++]));
148 osp_MicroDelay(CYCLE_DELAY);
150 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE, 2);
151 osp_MicroDelay(CYCLE_DELAY);
157 * This routine will clock the Read_data function into the X2520
158 * eeprom, followed by the address to read from, through the NicSTaR's General
162 static u_int8_t read_eprom_byte(virt_addr_t base, u_int8_t offset)
166 u_int8_t tempread = 0;
168 val = NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE) & 0xFFFFFFF0;
170 /* Send READ instruction */
171 for (i = 0; i < ARRAY_SIZE(readtab); i++) {
172 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
174 osp_MicroDelay(CYCLE_DELAY);
177 /* Next, we need to send the byte address to read from */
178 for (i = 7; i >= 0; i--) {
179 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
180 (val | clocktab[j++] | ((offset >> i) & 1)));
181 osp_MicroDelay(CYCLE_DELAY);
182 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
183 (val | clocktab[j++] | ((offset >> i) & 1)));
184 osp_MicroDelay(CYCLE_DELAY);
189 /* Now, we can read data from the eeprom by clocking it in */
190 for (i = 7; i >= 0; i--) {
191 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
192 (val | clocktab[j++]));
193 osp_MicroDelay(CYCLE_DELAY);
195 (((NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE)
196 & 0x00010000) >> 16) << i);
197 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
198 (val | clocktab[j++]));
199 osp_MicroDelay(CYCLE_DELAY);
202 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE, 2);
203 osp_MicroDelay(CYCLE_DELAY);
207 static void nicstar_init_eprom(virt_addr_t base)
212 * turn chip select off
214 val = NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE) & 0xFFFFFFF0;
216 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
217 (val | CS_HIGH | CLK_HIGH));
218 osp_MicroDelay(CYCLE_DELAY);
220 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
221 (val | CS_HIGH | CLK_LOW));
222 osp_MicroDelay(CYCLE_DELAY);
224 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
225 (val | CS_HIGH | CLK_HIGH));
226 osp_MicroDelay(CYCLE_DELAY);
228 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
229 (val | CS_HIGH | CLK_LOW));
230 osp_MicroDelay(CYCLE_DELAY);
234 * This routine will be the interface to the ReadPromByte function
239 nicstar_read_eprom(virt_addr_t base,
240 u_int8_t prom_offset, u_int8_t * buffer, u_int32_t nbytes)
244 for (i = 0; i < nbytes; i++) {
245 buffer[i] = read_eprom_byte(base, prom_offset);
247 osp_MicroDelay(CYCLE_DELAY);