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 net_device
*dev
, short bit
)
26 write_nic_byte(dev
, EPROM_CMD
,
28 read_nic_byte(dev
, EPROM_CMD
)); //enable EPROM
30 write_nic_byte(dev
, EPROM_CMD
, read_nic_byte(dev
, EPROM_CMD
)
31 &~(1<<EPROM_CS_SHIFT
)); //disable EPROM
37 static void eprom_ck_cycle(struct net_device
*dev
)
39 write_nic_byte(dev
, EPROM_CMD
,
40 (1<<EPROM_CK_SHIFT
) | read_nic_byte(dev
, EPROM_CMD
));
42 write_nic_byte(dev
, EPROM_CMD
,
43 read_nic_byte(dev
, EPROM_CMD
) & ~(1<<EPROM_CK_SHIFT
));
48 static void eprom_w(struct net_device
*dev
, short bit
)
51 write_nic_byte(dev
, EPROM_CMD
, (1<<EPROM_W_SHIFT
) |
52 read_nic_byte(dev
, EPROM_CMD
));
54 write_nic_byte(dev
, EPROM_CMD
, read_nic_byte(dev
, EPROM_CMD
)
55 &~(1<<EPROM_W_SHIFT
));
61 static short eprom_r(struct net_device
*dev
)
65 bit
= (read_nic_byte(dev
, EPROM_CMD
) & (1<<EPROM_R_SHIFT
));
74 static void eprom_send_bits_string(struct net_device
*dev
, short b
[], int len
)
78 for (i
= 0; i
< len
; i
++) {
85 u32
eprom_read(struct net_device
*dev
, u32 addr
)
87 struct r8192_priv
*priv
= ieee80211_priv(dev
);
88 short read_cmd
[] = {1, 1, 0};
95 //enable EPROM programming
96 write_nic_byte(dev
, EPROM_CMD
,
97 (EPROM_CMD_PROGRAM
<<EPROM_CMD_OPERATING_MODE_SHIFT
));
100 if (priv
->epromtype
== EPROM_93c56
) {
101 addr_str
[7] = addr
& 1;
102 addr_str
[6] = addr
& (1<<1);
103 addr_str
[5] = addr
& (1<<2);
104 addr_str
[4] = addr
& (1<<3);
105 addr_str
[3] = addr
& (1<<4);
106 addr_str
[2] = addr
& (1<<5);
107 addr_str
[1] = addr
& (1<<6);
108 addr_str
[0] = addr
& (1<<7);
111 addr_str
[5] = addr
& 1;
112 addr_str
[4] = addr
& (1<<1);
113 addr_str
[3] = addr
& (1<<2);
114 addr_str
[2] = addr
& (1<<3);
115 addr_str
[1] = addr
& (1<<4);
116 addr_str
[0] = addr
& (1<<5);
121 eprom_send_bits_string(dev
, read_cmd
, 3);
122 eprom_send_bits_string(dev
, addr_str
, addr_len
);
124 //keep chip pin D to low state while reading.
125 //I'm unsure if it is necessary, but anyway shouldn't hurt
128 for (i
= 0; i
< 16; i
++) {
129 //eeprom needs a clk cycle between writing opcode&adr
130 //and reading data. (eeprom outs a dummy 0)
132 ret
|= (eprom_r(dev
)<<(15-i
));
138 //disable EPROM programming
139 write_nic_byte(dev
, EPROM_CMD
,
140 (EPROM_CMD_NORMAL
<<EPROM_CMD_OPERATING_MODE_SHIFT
));