staging: rtl8192e: Fix sparse (non-endian) messages - Part I
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / rtl8192e / rtl_eeprom.c
blobdf72a6007d08c60ca80594853dd6c15f986ba290
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
13 * more details.
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 ******************************************************************************/
25 #include "rtl_core.h"
26 #include "rtl_eeprom.h"
28 void eprom_cs(struct net_device *dev, short bit)
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));
38 udelay(EPROM_DELAY);
42 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));
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);
53 void eprom_w(struct net_device *dev, short bit)
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));
62 udelay(EPROM_DELAY);
66 short eprom_r(struct net_device *dev)
68 short bit;
70 bit = (read_nic_byte(dev, EPROM_CMD) & (1<<EPROM_R_SHIFT));
71 udelay(EPROM_DELAY);
73 if (bit)
74 return 1;
75 return 0;
79 void eprom_send_bits_string(struct net_device *dev, short b[], int len)
81 int i;
83 for (i = 0; i < len; i++) {
84 eprom_w(dev, b[i]);
85 eprom_ck_cycle(dev);
89 u32 eprom_read(struct net_device *dev, u32 addr)
91 struct r8192_priv *priv = rtllib_priv(dev);
92 short read_cmd[] = {1, 1, 0};
93 short addr_str[8];
94 int i;
95 int addr_len;
96 u32 ret;
98 ret = 0;
99 write_nic_byte(dev, EPROM_CMD,
100 (EPROM_CMD_PROGRAM << EPROM_CMD_OPERATING_MODE_SHIFT));
101 udelay(EPROM_DELAY);
103 if (priv->epromtype == EEPROM_93C56) {
104 addr_str[7] = addr & 1;
105 addr_str[6] = addr & (1<<1);
106 addr_str[5] = addr & (1<<2);
107 addr_str[4] = addr & (1<<3);
108 addr_str[3] = addr & (1<<4);
109 addr_str[2] = addr & (1<<5);
110 addr_str[1] = addr & (1<<6);
111 addr_str[0] = addr & (1<<7);
112 addr_len = 8;
113 } else {
114 addr_str[5] = addr & 1;
115 addr_str[4] = addr & (1<<1);
116 addr_str[3] = addr & (1<<2);
117 addr_str[2] = addr & (1<<3);
118 addr_str[1] = addr & (1<<4);
119 addr_str[0] = addr & (1<<5);
120 addr_len = 6;
122 eprom_cs(dev, 1);
123 eprom_ck_cycle(dev);
124 eprom_send_bits_string(dev, read_cmd, 3);
125 eprom_send_bits_string(dev, addr_str, addr_len);
127 eprom_w(dev, 0);
129 for (i = 0; i < 16; i++) {
130 eprom_ck_cycle(dev);
131 ret |= (eprom_r(dev)<<(15-i));
134 eprom_cs(dev, 0);
135 eprom_ck_cycle(dev);
137 write_nic_byte(dev, EPROM_CMD,
138 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));
139 return ret;