Blackfin: use proper wrapper functions for modifying irq status
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / staging / rtl8192e / r8180_93cx6.c
blob55d4f56dc42e58c211703981069e913d107abf06
1 /*
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
18 project Authors.
21 #include "r8180_93cx6.h"
23 static void eprom_cs(struct r8192_priv *priv, short bit)
25 if (bit)
26 write_nic_byte(priv, EPROM_CMD,
27 (1<<EPROM_CS_SHIFT) |
28 read_nic_byte(priv, EPROM_CMD)); //enable EPROM
29 else
30 write_nic_byte(priv, EPROM_CMD, read_nic_byte(priv, EPROM_CMD)
31 &~(1<<EPROM_CS_SHIFT)); //disable EPROM
33 udelay(EPROM_DELAY);
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));
41 udelay(EPROM_DELAY);
42 write_nic_byte(priv, EPROM_CMD,
43 read_nic_byte(priv, EPROM_CMD) & ~(1<<EPROM_CK_SHIFT));
44 udelay(EPROM_DELAY);
48 static void eprom_w(struct r8192_priv *priv, short bit)
50 if (bit)
51 write_nic_byte(priv, EPROM_CMD, (1<<EPROM_W_SHIFT) |
52 read_nic_byte(priv, EPROM_CMD));
53 else
54 write_nic_byte(priv, EPROM_CMD, read_nic_byte(priv, EPROM_CMD)
55 &~(1<<EPROM_W_SHIFT));
57 udelay(EPROM_DELAY);
61 static short eprom_r(struct r8192_priv *priv)
63 short bit;
65 bit = (read_nic_byte(priv, EPROM_CMD) & (1<<EPROM_R_SHIFT));
66 udelay(EPROM_DELAY);
68 if (bit)
69 return 1;
70 return 0;
74 static void eprom_send_bits_string(struct r8192_priv *priv, short b[], int len)
76 int i;
78 for (i = 0; i < len; i++) {
79 eprom_w(priv, b[i]);
80 eprom_ck_cycle(priv);
85 u32 eprom_read(struct r8192_priv *priv, u32 addr)
87 short read_cmd[] = {1, 1, 0};
88 short addr_str[8];
89 int i;
90 int addr_len;
91 u32 ret;
93 ret = 0;
94 //enable EPROM programming
95 write_nic_byte(priv, EPROM_CMD,
96 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT));
97 udelay(EPROM_DELAY);
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);
108 addr_len = 8;
109 } else {
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);
116 addr_len = 6;
118 eprom_cs(priv, 1);
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
125 eprom_w(priv, 0);
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));
134 eprom_cs(priv, 0);
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));
140 return ret;