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;
17 #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 */
39 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[] = {
78 CLK_HIGH | SI_HIGH, /* 1 */
80 CLK_HIGH | SI_HIGH /* 1 */
83 /* Clock to read from/write to the eeprom */
84 static u_int32_t clocktab[] = {
104 #define NICSTAR_REG_WRITE(bs, reg, val) \
105 while ( readl(bs + STAT) & 0x0200 ) ; \
106 writel((val),(base)+(reg))
107 #define NICSTAR_REG_READ(bs, reg) \
109 #define NICSTAR_REG_GENERAL_PURPOSE GP
112 * This routine will clock the Read_Status_reg function into the X2520
113 * eeprom, then pull the result from bit 16 of the NicSTaR's General Purpose
117 u_int32_t nicstar_read_eprom_status(virt_addr_t base)
123 /* Send read instruction */
124 val = NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE) & 0xFFFFFFF0;
126 for (i = 0; i < ARRAY_SIZE(rdsrtab); i++) {
127 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
129 osp_MicroDelay(CYCLE_DELAY);
132 /* Done sending instruction - now pull data off of bit 16, MSB first */
133 /* Data clocked out of eeprom on falling edge of clock */
136 for (i = 7, j = 0; i >= 0; i--) {
137 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
138 (val | clocktab[j++]));
139 rbyte |= (((NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE)
140 & 0x00010000) >> 16) << i);
141 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
142 (val | clocktab[j++]));
143 osp_MicroDelay(CYCLE_DELAY);
145 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE, 2);
146 osp_MicroDelay(CYCLE_DELAY);
152 * This routine will clock the Read_data function into the X2520
153 * eeprom, followed by the address to read from, through the NicSTaR's General
157 static u_int8_t read_eprom_byte(virt_addr_t base, u_int8_t offset)
161 u_int8_t tempread = 0;
163 val = NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE) & 0xFFFFFFF0;
165 /* Send READ instruction */
166 for (i = 0; i < ARRAY_SIZE(readtab); i++) {
167 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
169 osp_MicroDelay(CYCLE_DELAY);
172 /* Next, we need to send the byte address to read from */
173 for (i = 7; i >= 0; i--) {
174 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
175 (val | clocktab[j++] | ((offset >> i) & 1)));
176 osp_MicroDelay(CYCLE_DELAY);
177 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
178 (val | clocktab[j++] | ((offset >> i) & 1)));
179 osp_MicroDelay(CYCLE_DELAY);
184 /* Now, we can read data from the eeprom by clocking it in */
185 for (i = 7; i >= 0; i--) {
186 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
187 (val | clocktab[j++]));
188 osp_MicroDelay(CYCLE_DELAY);
190 (((NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE)
191 & 0x00010000) >> 16) << i);
192 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
193 (val | clocktab[j++]));
194 osp_MicroDelay(CYCLE_DELAY);
197 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE, 2);
198 osp_MicroDelay(CYCLE_DELAY);
202 static void nicstar_init_eprom(virt_addr_t base)
207 * turn chip select off
209 val = NICSTAR_REG_READ(base, NICSTAR_REG_GENERAL_PURPOSE) & 0xFFFFFFF0;
211 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
212 (val | CS_HIGH | CLK_HIGH));
213 osp_MicroDelay(CYCLE_DELAY);
215 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
216 (val | CS_HIGH | CLK_LOW));
217 osp_MicroDelay(CYCLE_DELAY);
219 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
220 (val | CS_HIGH | CLK_HIGH));
221 osp_MicroDelay(CYCLE_DELAY);
223 NICSTAR_REG_WRITE(base, NICSTAR_REG_GENERAL_PURPOSE,
224 (val | CS_HIGH | CLK_LOW));
225 osp_MicroDelay(CYCLE_DELAY);
229 * This routine will be the interface to the ReadPromByte function
234 nicstar_read_eprom(virt_addr_t base,
235 u_int8_t prom_offset, u_int8_t * buffer, u_int32_t nbytes)
239 for (i = 0; i < nbytes; i++) {
240 buffer[i] = read_eprom_byte(base, prom_offset);
242 osp_MicroDelay(CYCLE_DELAY);