1 /******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
4 * Based on the r8180 driver, which is:
5 * Copyright 2004-2005 Andrea Merello <andreamrl@tiscali.it>, et al.
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com>
24 ******************************************************************************/
26 #include "rtl_eeprom.h"
28 static void eprom_cs(struct net_device
*dev
, short bit
)
31 write_nic_byte(dev
, EPROM_CMD
,
32 (1 << EPROM_CS_SHIFT
) |
33 read_nic_byte(dev
, EPROM_CMD
));
35 write_nic_byte(dev
, EPROM_CMD
, read_nic_byte(dev
, EPROM_CMD
)
36 & ~(1<<EPROM_CS_SHIFT
));
42 static void eprom_ck_cycle(struct net_device
*dev
)
44 write_nic_byte(dev
, EPROM_CMD
,
45 (1<<EPROM_CK_SHIFT
) | read_nic_byte(dev
, EPROM_CMD
));
47 write_nic_byte(dev
, EPROM_CMD
,
48 read_nic_byte(dev
, EPROM_CMD
) & ~(1<<EPROM_CK_SHIFT
));
53 static void eprom_w(struct net_device
*dev
, short bit
)
56 write_nic_byte(dev
, EPROM_CMD
, (1<<EPROM_W_SHIFT
) |
57 read_nic_byte(dev
, EPROM_CMD
));
59 write_nic_byte(dev
, EPROM_CMD
, read_nic_byte(dev
, EPROM_CMD
)
60 & ~(1<<EPROM_W_SHIFT
));
66 static short eprom_r(struct net_device
*dev
)
70 bit
= (read_nic_byte(dev
, EPROM_CMD
) & (1<<EPROM_R_SHIFT
));
78 static void eprom_send_bits_string(struct net_device
*dev
, short b
[], int len
)
82 for (i
= 0; i
< len
; i
++) {
88 u32
eprom_read(struct net_device
*dev
, u32 addr
)
90 struct r8192_priv
*priv
= rtllib_priv(dev
);
91 short read_cmd
[] = {1, 1, 0};
98 write_nic_byte(dev
, EPROM_CMD
,
99 (EPROM_CMD_PROGRAM
<< EPROM_CMD_OPERATING_MODE_SHIFT
));
102 if (priv
->epromtype
== EEPROM_93C56
) {
103 addr_str
[7] = addr
& 1;
104 addr_str
[6] = addr
& (1<<1);
105 addr_str
[5] = addr
& (1<<2);
106 addr_str
[4] = addr
& (1<<3);
107 addr_str
[3] = addr
& (1<<4);
108 addr_str
[2] = addr
& (1<<5);
109 addr_str
[1] = addr
& (1<<6);
110 addr_str
[0] = addr
& (1<<7);
113 addr_str
[5] = addr
& 1;
114 addr_str
[4] = addr
& (1<<1);
115 addr_str
[3] = addr
& (1<<2);
116 addr_str
[2] = addr
& (1<<3);
117 addr_str
[1] = addr
& (1<<4);
118 addr_str
[0] = addr
& (1<<5);
123 eprom_send_bits_string(dev
, read_cmd
, 3);
124 eprom_send_bits_string(dev
, addr_str
, addr_len
);
128 for (i
= 0; i
< 16; i
++) {
130 ret
|= (eprom_r(dev
)<<(15-i
));
136 write_nic_byte(dev
, EPROM_CMD
,
137 (EPROM_CMD_NORMAL
<<EPROM_CMD_OPERATING_MODE_SHIFT
));