ACPI: PCI: always use the PCI INTx pin values, not the _PRT ones
[linux-2.6/mini2440.git] / drivers / misc / eeprom_93cx6.c
blob15b1780025c84e75c24b83ca0ce6dbab6336dc0b
1 /*
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.
22 Module: eeprom_93cx6
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.
47 ndelay(450);
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.
60 ndelay(450);
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);
76 * kick a pulse.
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);
93 * kick a pulse.
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)
102 unsigned int i;
104 eeprom->register_read(eeprom);
107 * Clear data flags.
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);
127 * Kick a pulse.
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)
140 unsigned int i;
141 u16 buf = 0;
143 eeprom->register_read(eeprom);
146 * Clear data flags.
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);
173 *data = buf;
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,
186 u16 *data)
188 u16 command;
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
225 * endian words.
227 void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
228 __le16 *data, const u16 words)
230 unsigned int i;
231 u16 tmp;
233 for (i = 0; i < words; i++) {
234 tmp = 0;
235 eeprom_93cx6_read(eeprom, word + i, &tmp);
236 data[i] = cpu_to_le16(tmp);
239 EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);