2 Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
3 <http://rt2x00.serialmonkey.com>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the
17 Free Software Foundation, Inc.,
18 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23 Abstract: EEPROM reader routines for 93cx6 chipsets.
24 Supported chipsets: 93c46 & 93c66.
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/delay.h>
30 #include <linux/eeprom_93cx6.h>
32 MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
33 MODULE_VERSION("1.0");
34 MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
35 MODULE_LICENSE("GPL");
37 static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
39 eeprom->reg_data_clock = 1;
40 eeprom->register_write(eeprom);
43 * Add a short delay for the pulse to work.
44 * According to the specifications the "maximum minimum"
45 * time should be 450ns.
50 static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
52 eeprom->reg_data_clock = 0;
53 eeprom->register_write(eeprom);
56 * Add a short delay for the pulse to work.
57 * According to the specifications the "maximum minimum"
58 * time should be 450ns.
63 static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
66 * Clear all flags, and enable chip select.
68 eeprom->register_read(eeprom);
69 eeprom->reg_data_in = 0;
70 eeprom->reg_data_out = 0;
71 eeprom->reg_data_clock = 0;
72 eeprom->reg_chip_select = 1;
73 eeprom->register_write(eeprom);
78 eeprom_93cx6_pulse_high(eeprom);
79 eeprom_93cx6_pulse_low(eeprom);
82 static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
85 * Clear chip_select and data_in flags.
87 eeprom->register_read(eeprom);
88 eeprom->reg_data_in = 0;
89 eeprom->reg_chip_select = 0;
90 eeprom->register_write(eeprom);
95 eeprom_93cx6_pulse_high(eeprom);
96 eeprom_93cx6_pulse_low(eeprom);
99 static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
100 const u16 data, const u16 count)
104 eeprom->register_read(eeprom);
109 eeprom->reg_data_in = 0;
110 eeprom->reg_data_out = 0;
113 * Start writing all bits.
115 for (i = count; i > 0; i--) {
117 * Check if this bit needs to be set.
119 eeprom->reg_data_in = !!(data & (1 << (i - 1)));
122 * Write the bit to the eeprom register.
124 eeprom->register_write(eeprom);
129 eeprom_93cx6_pulse_high(eeprom);
130 eeprom_93cx6_pulse_low(eeprom);
133 eeprom->reg_data_in = 0;
134 eeprom->register_write(eeprom);
137 static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
138 u16 *data, const u16 count)
143 eeprom->register_read(eeprom);
148 eeprom->reg_data_in = 0;
149 eeprom->reg_data_out = 0;
152 * Start reading all bits.
154 for (i = count; i > 0; i--) {
155 eeprom_93cx6_pulse_high(eeprom);
157 eeprom->register_read(eeprom);
160 * Clear data_in flag.
162 eeprom->reg_data_in = 0;
165 * Read if the bit has been set.
167 if (eeprom->reg_data_out)
168 buf |= (1 << (i - 1));
170 eeprom_93cx6_pulse_low(eeprom);
177 * eeprom_93cx6_read - Read multiple words from eeprom
178 * @eeprom: Pointer to eeprom structure
179 * @word: Word index from where we should start reading
180 * @data: target pointer where the information will have to be stored
182 * This function will read the eeprom data as host-endian word
183 * into the given data pointer.
185 void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
191 * Initialize the eeprom register
193 eeprom_93cx6_startup(eeprom);
196 * Select the read opcode and the word to be read.
198 command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
199 eeprom_93cx6_write_bits(eeprom, command,
200 PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
203 * Read the requested 16 bits.
205 eeprom_93cx6_read_bits(eeprom, data, 16);
208 * Cleanup eeprom register.
210 eeprom_93cx6_cleanup(eeprom);
212 EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
215 * eeprom_93cx6_multiread - Read multiple words from eeprom
216 * @eeprom: Pointer to eeprom structure
217 * @word: Word index from where we should start reading
218 * @data: target pointer where the information will have to be stored
219 * @words: Number of words that should be read.
221 * This function will read all requested words from the eeprom,
222 * this is done by calling eeprom_93cx6_read() multiple times.
223 * But with the additional change that while the eeprom_93cx6_read
224 * will return host ordered bytes, this method will return little
227 void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
228 __le16 *data, const u16 words)
233 for (i = 0; i < words; i++) {
235 eeprom_93cx6_read(eeprom, word + i, &tmp);
236 data[i] = cpu_to_le16(tmp);
239 EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);