blob: 14a8c1d13e2e5d892eb441885e6602811d3011c3 [file] [log] [blame]
Larry Finger94a79942011-08-23 19:00:42 -05001/******************************************************************************
2 * Copyright(c) 2008 - 2010 Realtek Corporation. All rights reserved.
3 *
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.
9 *
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
13 * more details.
14 *
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
18 *
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
21 *
22 * Contact Information:
23 * wlanfae <wlanfae@realtek.com>
24******************************************************************************/
25#include "rtl_core.h"
26#include "rtl_eeprom.h"
27
28void eprom_cs(struct net_device *dev, short bit)
29{
30 if (bit)
31 write_nic_byte(dev, EPROM_CMD,
32 (1<<EPROM_CS_SHIFT) | \
33 read_nic_byte(dev, EPROM_CMD));
34 else
35 write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev, EPROM_CMD)\
36 &~(1<<EPROM_CS_SHIFT));
37
38 udelay(EPROM_DELAY);
39}
40
41
42void eprom_ck_cycle(struct net_device *dev)
43{
44 write_nic_byte(dev, EPROM_CMD,
45 (1<<EPROM_CK_SHIFT) | read_nic_byte(dev,EPROM_CMD));
46 udelay(EPROM_DELAY);
47 write_nic_byte(dev, EPROM_CMD,
48 read_nic_byte(dev, EPROM_CMD) &~ (1<<EPROM_CK_SHIFT));
49 udelay(EPROM_DELAY);
50}
51
52
53void eprom_w(struct net_device *dev,short bit)
54{
55 if (bit)
56 write_nic_byte(dev, EPROM_CMD, (1<<EPROM_W_SHIFT) | \
57 read_nic_byte(dev,EPROM_CMD));
58 else
59 write_nic_byte(dev, EPROM_CMD, read_nic_byte(dev,EPROM_CMD)\
60 &~(1<<EPROM_W_SHIFT));
61
62 udelay(EPROM_DELAY);
63}
64
65
66short eprom_r(struct net_device *dev)
67{
68 short bit;
69
70 bit=(read_nic_byte(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT) );
71 udelay(EPROM_DELAY);
72
73 if (bit)
74 return 1;
75 return 0;
76}
77
78
79void eprom_send_bits_string(struct net_device *dev, short b[], int len)
80{
81 int i;
82
83 for (i=0; i<len; i++){
84 eprom_w(dev, b[i]);
85 eprom_ck_cycle(dev);
86 }
87}
88
89
90u32 eprom_read(struct net_device *dev, u32 addr)
91{
92 struct r8192_priv *priv = rtllib_priv(dev);
93 short read_cmd[]={1,1,0};
94 short addr_str[8];
95 int i;
96 int addr_len;
97 u32 ret;
98
99 ret=0;
100 write_nic_byte(dev, EPROM_CMD,
101 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT));
102 udelay(EPROM_DELAY);
103
104 if (priv->epromtype==EEPROM_93C56){
105 addr_str[7]=addr & 1;
106 addr_str[6]=addr & (1<<1);
107 addr_str[5]=addr & (1<<2);
108 addr_str[4]=addr & (1<<3);
109 addr_str[3]=addr & (1<<4);
110 addr_str[2]=addr & (1<<5);
111 addr_str[1]=addr & (1<<6);
112 addr_str[0]=addr & (1<<7);
113 addr_len=8;
114 }else{
115 addr_str[5]=addr & 1;
116 addr_str[4]=addr & (1<<1);
117 addr_str[3]=addr & (1<<2);
118 addr_str[2]=addr & (1<<3);
119 addr_str[1]=addr & (1<<4);
120 addr_str[0]=addr & (1<<5);
121 addr_len=6;
122 }
123 eprom_cs(dev, 1);
124 eprom_ck_cycle(dev);
125 eprom_send_bits_string(dev, read_cmd, 3);
126 eprom_send_bits_string(dev, addr_str, addr_len);
127
128 eprom_w(dev, 0);
129
130 for (i = 0; i < 16; i++){
131 eprom_ck_cycle(dev);
132 ret |= (eprom_r(dev)<<(15-i));
133 }
134
135 eprom_cs(dev, 0);
136 eprom_ck_cycle(dev);
137
138 write_nic_byte(dev, EPROM_CMD,
139 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));
140 return ret;
141}