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 <andrea.merello@gmail.com>
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 thank the Authors of those projects and the Ndiswrapper
21 #include "r8180_93cx6.h"
23 static void eprom_cs(struct net_device *dev, short bit)
28 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
33 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CS_BIT);
36 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CS_BIT);
38 force_pci_posting(dev);
43 static void eprom_ck_cycle(struct net_device *dev)
48 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
51 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_CK_BIT);
52 force_pci_posting(dev);
55 read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
56 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_CK_BIT);
57 force_pci_posting(dev);
62 static void eprom_w(struct net_device *dev, short bit)
67 err = read_nic_byte_E(dev, EPROM_CMD, &cmdreg);
71 write_nic_byte_E(dev, EPROM_CMD, cmdreg | EPROM_W_BIT);
73 write_nic_byte_E(dev, EPROM_CMD, cmdreg & ~EPROM_W_BIT);
75 force_pci_posting(dev);
80 static short eprom_r(struct net_device *dev)
85 err = read_nic_byte_E(dev, EPROM_CMD, &bit);
91 if (bit & EPROM_R_BIT)
98 static void eprom_send_bits_string(struct net_device *dev, short b[], int len)
102 for (i = 0; i < len; i++) {
109 int eprom_read(struct net_device *dev, u32 addr)
111 struct r8192_priv *priv = ieee80211_priv(dev);
112 short read_cmd[] = {1, 1, 0};
120 /* enable EPROM programming */
121 write_nic_byte_E(dev, EPROM_CMD,
122 (EPROM_CMD_PROGRAM<<EPROM_CMD_OPERATING_MODE_SHIFT));
123 force_pci_posting(dev);
126 if (priv->epromtype == EPROM_93c56) {
127 addr_str[7] = addr & 1;
128 addr_str[6] = addr & (1<<1);
129 addr_str[5] = addr & (1<<2);
130 addr_str[4] = addr & (1<<3);
131 addr_str[3] = addr & (1<<4);
132 addr_str[2] = addr & (1<<5);
133 addr_str[1] = addr & (1<<6);
134 addr_str[0] = addr & (1<<7);
137 addr_str[5] = addr & 1;
138 addr_str[4] = addr & (1<<1);
139 addr_str[3] = addr & (1<<2);
140 addr_str[2] = addr & (1<<3);
141 addr_str[1] = addr & (1<<4);
142 addr_str[0] = addr & (1<<5);
147 eprom_send_bits_string(dev, read_cmd, 3);
148 eprom_send_bits_string(dev, addr_str, addr_len);
151 * keep chip pin D to low state while reading.
152 * I'm unsure if it is necessary, but anyway shouldn't hurt
156 for (i = 0; i < 16; i++) {
157 /* eeprom needs a clk cycle between writing opcode&adr
158 * and reading data. (eeprom outs a dummy 0)
171 /* disable EPROM programming */
172 write_nic_byte_E(dev, EPROM_CMD,
173 (EPROM_CMD_NORMAL<<EPROM_CMD_OPERATING_MODE_SHIFT));