2 This files contains card eeprom (93c46 or 93c56) programming routines,
3 memory is addressed by 16 bits words.
5 This is part of rtl8180 OpenSource driver.
6 Copyright (C) Andrea Merello 2004 <andreamrl@tiscali.it>
7 Released under the terms of GPL (General Public Licence)
9 Parts of this driver are based on the GPL part of the
10 official realtek driver.
12 Parts of this driver are based on the rtl8180 driver skeleton
13 from Patric Schenke & Andres Salomon.
15 Parts of this driver are based on the Intel Pro Wireless 2100 GPL driver.
17 We want to tanks the Authors of those projects and the Ndiswrapper
21 #include "r8180_93cx6.h"
23 static void eprom_cs(struct r8192_priv
*priv
, short bit
)
26 write_nic_byte(priv
, EPROM_CMD
,
28 read_nic_byte(priv
, EPROM_CMD
)); //enable EPROM
30 write_nic_byte(priv
, EPROM_CMD
, read_nic_byte(priv
, EPROM_CMD
)
31 &~(1<<EPROM_CS_SHIFT
)); //disable EPROM
37 static void eprom_ck_cycle(struct r8192_priv
*priv
)
39 write_nic_byte(priv
, EPROM_CMD
,
40 (1<<EPROM_CK_SHIFT
) | read_nic_byte(priv
, EPROM_CMD
));
42 write_nic_byte(priv
, EPROM_CMD
,
43 read_nic_byte(priv
, EPROM_CMD
) & ~(1<<EPROM_CK_SHIFT
));
48 static void eprom_w(struct r8192_priv
*priv
, short bit
)
51 write_nic_byte(priv
, EPROM_CMD
, (1<<EPROM_W_SHIFT
) |
52 read_nic_byte(priv
, EPROM_CMD
));
54 write_nic_byte(priv
, EPROM_CMD
, read_nic_byte(priv
, EPROM_CMD
)
55 &~(1<<EPROM_W_SHIFT
));
61 static short eprom_r(struct r8192_priv
*priv
)
65 bit
= (read_nic_byte(priv
, EPROM_CMD
) & (1<<EPROM_R_SHIFT
));
74 static void eprom_send_bits_string(struct r8192_priv
*priv
, short b
[], int len
)
78 for (i
= 0; i
< len
; i
++) {
85 u32
eprom_read(struct r8192_priv
*priv
, u32 addr
)
87 short read_cmd
[] = {1, 1, 0};
94 //enable EPROM programming
95 write_nic_byte(priv
, EPROM_CMD
,
96 (EPROM_CMD_PROGRAM
<<EPROM_CMD_OPERATING_MODE_SHIFT
));
99 if (priv
->epromtype
== EPROM_93c56
) {
100 addr_str
[7] = addr
& 1;
101 addr_str
[6] = addr
& (1<<1);
102 addr_str
[5] = addr
& (1<<2);
103 addr_str
[4] = addr
& (1<<3);
104 addr_str
[3] = addr
& (1<<4);
105 addr_str
[2] = addr
& (1<<5);
106 addr_str
[1] = addr
& (1<<6);
107 addr_str
[0] = addr
& (1<<7);
110 addr_str
[5] = addr
& 1;
111 addr_str
[4] = addr
& (1<<1);
112 addr_str
[3] = addr
& (1<<2);
113 addr_str
[2] = addr
& (1<<3);
114 addr_str
[1] = addr
& (1<<4);
115 addr_str
[0] = addr
& (1<<5);
119 eprom_ck_cycle(priv
);
120 eprom_send_bits_string(priv
, read_cmd
, 3);
121 eprom_send_bits_string(priv
, addr_str
, addr_len
);
123 //keep chip pin D to low state while reading.
124 //I'm unsure if it is necessary, but anyway shouldn't hurt
127 for (i
= 0; i
< 16; i
++) {
128 //eeprom needs a clk cycle between writing opcode&adr
129 //and reading data. (eeprom outs a dummy 0)
130 eprom_ck_cycle(priv
);
131 ret
|= (eprom_r(priv
)<<(15-i
));
135 eprom_ck_cycle(priv
);
137 //disable EPROM programming
138 write_nic_byte(priv
, EPROM_CMD
,
139 (EPROM_CMD_NORMAL
<<EPROM_CMD_OPERATING_MODE_SHIFT
));