2 * (C) Copyright 2002 ELTEC Elektronik AG
3 * Frank Gottschling <fgottschling@eltec.de>
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 #define SROM_RD 0x00004000 /* Read from Boot ROM */
33 #define SROM_WR 0x00002000 /* Write to Boot ROM */
34 #define SROM_SR 0x00000800 /* Select Serial ROM when set */
36 #define DT_IN 0x00000004 /* Serial Data In */
37 #define DT_CLK 0x00000002 /* Serial ROM Clock */
38 #define DT_CS 0x00000001 /* Serial ROM Chip Select */
40 static u_int dc_srom_iobase;
42 /*----------------------------------------------------------------------------*/
44 static int inl(u_long addr)
46 return le32_to_cpu(*(volatile u_long *)(addr));
49 /*----------------------------------------------------------------------------*/
51 static void outl (int command, u_long addr)
53 *(volatile u_long *)(addr) = cpu_to_le32(command);
56 /*----------------------------------------------------------------------------*/
58 static void sendto_srom(u_int command, u_long addr)
66 /*----------------------------------------------------------------------------*/
68 static int getfrom_srom(u_long addr)
78 /*----------------------------------------------------------------------------*/
80 static void srom_latch (u_int command, u_long addr)
82 sendto_srom (command, addr);
83 sendto_srom (command | DT_CLK, addr);
84 sendto_srom (command, addr);
89 /*----------------------------------------------------------------------------*/
91 static void srom_command_rd (u_int command, u_long addr)
93 srom_latch (command, addr);
94 srom_latch (command, addr);
95 srom_latch ((command & 0x0000ff00) | DT_CS, addr);
100 /*----------------------------------------------------------------------------*/
102 static void srom_command_wr (u_int command, u_long addr)
104 srom_latch (command, addr);
105 srom_latch ((command & 0x0000ff00) | DT_CS, addr);
106 srom_latch (command, addr);
111 /*----------------------------------------------------------------------------*/
113 static void srom_address(u_int command, u_long addr, u_char offset)
118 a = (char)(offset << 2);
119 for (i=0; i<6; i++, a <<= 1)
121 srom_latch(command | ((a < 0) ? DT_IN : 0), addr);
125 i = (getfrom_srom(addr) >> 3) & 0x01;
129 /*----------------------------------------------------------------------------*/
131 static short srom_data_rd (u_int command, u_long addr)
139 sendto_srom(command | DT_CLK, addr);
140 tmp = getfrom_srom(addr);
141 sendto_srom(command, addr);
143 word = (word << 1) | ((tmp >> 3) & 0x01);
146 sendto_srom(command & 0x0000ff00, addr);
151 /*----------------------------------------------------------------------------*/
153 static int srom_data_wr (u_int command, u_long addr, short val)
159 longVal = (u_long)(le16_to_cpu(val));
163 tmp = (longVal & 0x8000)>>13;
165 sendto_srom (tmp | command, addr);
166 sendto_srom (tmp | command | DT_CLK, addr);
167 sendto_srom (tmp | command, addr);
169 longVal = longVal<<1;
172 sendto_srom(command & 0x0000ff00, addr);
173 sendto_srom(command, addr);
178 if ((getfrom_srom(dc_srom_iobase) & 0x8) == 0x8)
185 printf("Write DEC21143 SRom timed out !\n");
193 /*----------------------------------------------------------------------------*/
194 static short srom_rd (u_long addr, u_char offset)
196 sendto_srom (SROM_RD | SROM_SR, addr);
197 srom_latch (SROM_RD | SROM_SR | DT_CS, addr);
199 srom_command_rd (SROM_RD | SROM_SR | DT_IN | DT_CS, addr);
201 srom_address (SROM_RD | SROM_SR | DT_CS, addr, offset);
203 return srom_data_rd (SROM_RD | SROM_SR | DT_CS, addr);
206 /*----------------------------------------------------------------------------*/
208 static void srom_wr_enable (u_long addr)
212 sendto_srom (SROM_WR | SROM_SR, addr);
213 srom_latch (SROM_WR | SROM_SR | DT_CS, addr);
215 srom_latch (SROM_WR | SROM_SR | DT_IN | DT_CS, addr);
216 srom_latch (SROM_WR | SROM_SR | DT_CS, addr);
217 srom_latch (SROM_WR | SROM_SR | DT_CS, addr);
221 srom_latch (SROM_WR | SROM_SR | DT_IN | DT_CS, addr);
225 /*----------------------------------------------------------------------------*/
227 static int srom_wr (u_long addr, u_char offset, short val)
229 srom_wr_enable (addr);
231 sendto_srom (SROM_WR | SROM_SR, addr);
232 srom_latch (SROM_WR | SROM_SR | DT_CS, addr);
234 srom_command_wr (SROM_WR | SROM_SR | DT_IN | DT_CS, addr);
236 srom_address (SROM_WR | SROM_SR | DT_CS, addr, offset);
238 return srom_data_wr (SROM_WR | SROM_SR | DT_CS, addr, val);
241 /*----------------------------------------------------------------------------*/
243 * load data from the srom
245 int dc_srom_load (u_short *dest)
250 /* get srom iobase from local network controller */
251 pci_read_config_dword(PCI_BDF(0,14,0), PCI_BASE_ADDRESS_1, &dc_srom_iobase);
252 dc_srom_iobase &= PCI_BASE_ADDRESS_MEM_MASK;
253 dc_srom_iobase = pci_mem_to_phys(PCI_BDF(0,14,0), dc_srom_iobase);
254 dc_srom_iobase += 0x48; /* io offset for srom access */
256 memset (dest, 0, 128);
257 for (offset=0; offset<64; offset++)
259 tmp = srom_rd (dc_srom_iobase, offset);
260 *dest++ = le16_to_cpu(tmp);
266 /*----------------------------------------------------------------------------*/
269 * store data into the srom
271 int dc_srom_store (u_short *src)
275 /* get srom iobase from local network controller */
276 pci_read_config_dword(PCI_BDF(0,14,0), PCI_BASE_ADDRESS_1, &dc_srom_iobase);
277 dc_srom_iobase &= PCI_BASE_ADDRESS_MEM_MASK;
278 dc_srom_iobase = pci_mem_to_phys(PCI_BDF(0,14,0), dc_srom_iobase);
279 dc_srom_iobase += 0x48; /* io offset for srom access */
281 for (offset=0; offset<64; offset++)
283 if (srom_wr (dc_srom_iobase, offset, *src) == -1)
291 /*----------------------------------------------------------------------------*/