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/version.h>
30 #include <linux/delay.h>
31 #include <linux/eeprom_93cx6.h>
33 MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
34 MODULE_VERSION("1.0");
35 MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
36 MODULE_LICENSE("GPL");
38 static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
40 eeprom->reg_data_clock = 1;
41 eeprom->register_write(eeprom);
45 static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
47 eeprom->reg_data_clock = 0;
48 eeprom->register_write(eeprom);
52 static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
55 * Clear all flags, and enable chip select.
57 eeprom->register_read(eeprom);
58 eeprom->reg_data_in = 0;
59 eeprom->reg_data_out = 0;
60 eeprom->reg_data_clock = 0;
61 eeprom->reg_chip_select = 1;
62 eeprom->register_write(eeprom);
67 eeprom_93cx6_pulse_high(eeprom);
68 eeprom_93cx6_pulse_low(eeprom);
71 static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
74 * Clear chip_select and data_in flags.
76 eeprom->register_read(eeprom);
77 eeprom->reg_data_in = 0;
78 eeprom->reg_chip_select = 0;
79 eeprom->register_write(eeprom);
84 eeprom_93cx6_pulse_high(eeprom);
85 eeprom_93cx6_pulse_low(eeprom);
88 static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
89 const u16 data, const u16 count)
93 eeprom->register_read(eeprom);
98 eeprom->reg_data_in = 0;
99 eeprom->reg_data_out = 0;
102 * Start writing all bits.
104 for (i = count; i > 0; i--) {
106 * Check if this bit needs to be set.
108 eeprom->reg_data_in = !!(data & (1 << (i - 1)));
111 * Write the bit to the eeprom register.
113 eeprom->register_write(eeprom);
118 eeprom_93cx6_pulse_high(eeprom);
119 eeprom_93cx6_pulse_low(eeprom);
122 eeprom->reg_data_in = 0;
123 eeprom->register_write(eeprom);
126 static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
127 u16 *data, const u16 count)
132 eeprom->register_read(eeprom);
137 eeprom->reg_data_in = 0;
138 eeprom->reg_data_out = 0;
141 * Start reading all bits.
143 for (i = count; i > 0; i--) {
144 eeprom_93cx6_pulse_high(eeprom);
146 eeprom->register_read(eeprom);
149 * Clear data_in flag.
151 eeprom->reg_data_in = 0;
154 * Read if the bit has been set.
156 if (eeprom->reg_data_out)
157 buf |= (1 << (i - 1));
159 eeprom_93cx6_pulse_low(eeprom);
166 * eeprom_93cx6_read - Read multiple words from eeprom
167 * @eeprom: Pointer to eeprom structure
168 * @word: Word index from where we should start reading
169 * @data: target pointer where the information will have to be stored
171 * This function will read the eeprom data as host-endian word
172 * into the given data pointer.
174 void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
180 * Initialize the eeprom register
182 eeprom_93cx6_startup(eeprom);
185 * Select the read opcode and the word to be read.
187 command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
188 eeprom_93cx6_write_bits(eeprom, command,
189 PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
192 * Read the requested 16 bits.
194 eeprom_93cx6_read_bits(eeprom, data, 16);
197 * Cleanup eeprom register.
199 eeprom_93cx6_cleanup(eeprom);
201 EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
204 * eeprom_93cx6_multiread - Read multiple words from eeprom
205 * @eeprom: Pointer to eeprom structure
206 * @word: Word index from where we should start reading
207 * @data: target pointer where the information will have to be stored
208 * @words: Number of words that should be read.
210 * This function will read all requested words from the eeprom,
211 * this is done by calling eeprom_93cx6_read() multiple times.
212 * But with the additional change that while the eeprom_93cx6_read
213 * will return host ordered bytes, this method will return little
216 void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
217 __le16 *data, const u16 words)
222 for (i = 0; i < words; i++) {
224 eeprom_93cx6_read(eeprom, word + i, &tmp);
225 data[i] = cpu_to_le16(tmp);
228 EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);