1 From: Ivo van Doorn <ivdoorn@gmail.com>
2 Date: Fri, 11 May 2007 19:59:40 +0000 (-0400)
3 Subject: [PATCH] Add 93cx6 eeprom library
4 X-Git-Tag: v2.6.23-rc1~1201^2~74
5 X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=9467d64b0e88763914c01f71ddf591b166c4f526
7 [PATCH] Add 93cx6 eeprom library
9 This patch adds a library for reading from 93cx6 eeproms.
11 Signed-off-by: Michael Wu <flamingice@sourmilk.net>
12 Signed-off-by: John W. Linville <linville@tuxdriver.com>
15 --- a/drivers/misc/Kconfig
16 +++ b/drivers/misc/Kconfig
18 If you choose to build module, its name will be phantom. If unsure,
22 + tristate "EEPROM 93CX6 support"
24 + This is a driver for the EEPROM chipsets 93c46 and 93c66.
25 + The driver supports both read as well as write commands.
31 If you are not sure, say Y here.
35 --- a/drivers/misc/Makefile
36 +++ b/drivers/misc/Makefile
38 obj-$(CONFIG_SGI_IOC4) += ioc4.o
39 obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
40 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
41 +obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o
43 +++ b/drivers/misc/eeprom_93cx6.c
46 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
47 + <http://rt2x00.serialmonkey.com>
49 + This program is free software; you can redistribute it and/or modify
50 + it under the terms of the GNU General Public License as published by
51 + the Free Software Foundation; either version 2 of the License, or
52 + (at your option) any later version.
54 + This program is distributed in the hope that it will be useful,
55 + but WITHOUT ANY WARRANTY; without even the implied warranty of
56 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
57 + GNU General Public License for more details.
59 + You should have received a copy of the GNU General Public License
60 + along with this program; if not, write to the
61 + Free Software Foundation, Inc.,
62 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
66 + Module: eeprom_93cx6
67 + Abstract: EEPROM reader routines for 93cx6 chipsets.
68 + Supported chipsets: 93c46 & 93c66.
71 +#include <linux/kernel.h>
72 +#include <linux/module.h>
73 +#include <linux/version.h>
74 +#include <linux/delay.h>
75 +#include <linux/eeprom_93cx6.h>
77 +MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
78 +MODULE_VERSION("1.0");
79 +MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
80 +MODULE_LICENSE("GPL");
82 +static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
84 + eeprom->reg_data_clock = 1;
85 + eeprom->register_write(eeprom);
89 +static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
91 + eeprom->reg_data_clock = 0;
92 + eeprom->register_write(eeprom);
96 +static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
99 + * Clear all flags, and enable chip select.
101 + eeprom->register_read(eeprom);
102 + eeprom->reg_data_in = 0;
103 + eeprom->reg_data_out = 0;
104 + eeprom->reg_data_clock = 0;
105 + eeprom->reg_chip_select = 1;
106 + eeprom->register_write(eeprom);
111 + eeprom_93cx6_pulse_high(eeprom);
112 + eeprom_93cx6_pulse_low(eeprom);
115 +static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
118 + * Clear chip_select and data_in flags.
120 + eeprom->register_read(eeprom);
121 + eeprom->reg_data_in = 0;
122 + eeprom->reg_chip_select = 0;
123 + eeprom->register_write(eeprom);
128 + eeprom_93cx6_pulse_high(eeprom);
129 + eeprom_93cx6_pulse_low(eeprom);
132 +static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
133 + const u16 data, const u16 count)
137 + eeprom->register_read(eeprom);
140 + * Clear data flags.
142 + eeprom->reg_data_in = 0;
143 + eeprom->reg_data_out = 0;
146 + * Start writing all bits.
148 + for (i = count; i > 0; i--) {
150 + * Check if this bit needs to be set.
152 + eeprom->reg_data_in = !!(data & (1 << (i - 1)));
155 + * Write the bit to the eeprom register.
157 + eeprom->register_write(eeprom);
162 + eeprom_93cx6_pulse_high(eeprom);
163 + eeprom_93cx6_pulse_low(eeprom);
166 + eeprom->reg_data_in = 0;
167 + eeprom->register_write(eeprom);
170 +static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
171 + u16 *data, const u16 count)
176 + eeprom->register_read(eeprom);
179 + * Clear data flags.
181 + eeprom->reg_data_in = 0;
182 + eeprom->reg_data_out = 0;
185 + * Start reading all bits.
187 + for (i = count; i > 0; i--) {
188 + eeprom_93cx6_pulse_high(eeprom);
190 + eeprom->register_read(eeprom);
193 + * Clear data_in flag.
195 + eeprom->reg_data_in = 0;
198 + * Read if the bit has been set.
200 + if (eeprom->reg_data_out)
201 + buf |= (1 << (i - 1));
203 + eeprom_93cx6_pulse_low(eeprom);
210 + * eeprom_93cx6_read - Read multiple words from eeprom
211 + * @eeprom: Pointer to eeprom structure
212 + * @word: Word index from where we should start reading
213 + * @data: target pointer where the information will have to be stored
215 + * This function will read the eeprom data as host-endian word
216 + * into the given data pointer.
218 +void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
224 + * Initialize the eeprom register
226 + eeprom_93cx6_startup(eeprom);
229 + * Select the read opcode and the word to be read.
231 + command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
232 + eeprom_93cx6_write_bits(eeprom, command,
233 + PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
236 + * Read the requested 16 bits.
238 + eeprom_93cx6_read_bits(eeprom, data, 16);
241 + * Cleanup eeprom register.
243 + eeprom_93cx6_cleanup(eeprom);
245 +EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
248 + * eeprom_93cx6_multiread - Read multiple words from eeprom
249 + * @eeprom: Pointer to eeprom structure
250 + * @word: Word index from where we should start reading
251 + * @data: target pointer where the information will have to be stored
252 + * @words: Number of words that should be read.
254 + * This function will read all requested words from the eeprom,
255 + * this is done by calling eeprom_93cx6_read() multiple times.
256 + * But with the additional change that while the eeprom_93cx6_read
257 + * will return host ordered bytes, this method will return little
260 +void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
261 + __le16 *data, const u16 words)
266 + for (i = 0; i < words; i++) {
268 + eeprom_93cx6_read(eeprom, word + i, &tmp);
269 + data[i] = cpu_to_le16(tmp);
272 +EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
275 +++ b/include/linux/eeprom_93cx6.h
278 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
279 + <http://rt2x00.serialmonkey.com>
281 + This program is free software; you can redistribute it and/or modify
282 + it under the terms of the GNU General Public License as published by
283 + the Free Software Foundation; either version 2 of the License, or
284 + (at your option) any later version.
286 + This program is distributed in the hope that it will be useful,
287 + but WITHOUT ANY WARRANTY; without even the implied warranty of
288 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
289 + GNU General Public License for more details.
291 + You should have received a copy of the GNU General Public License
292 + along with this program; if not, write to the
293 + Free Software Foundation, Inc.,
294 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
298 + Module: eeprom_93cx6
299 + Abstract: EEPROM reader datastructures for 93cx6 chipsets.
300 + Supported chipsets: 93c46 & 93c66.
304 + * EEPROM operation defines.
306 +#define PCI_EEPROM_WIDTH_93C46 6
307 +#define PCI_EEPROM_WIDTH_93C66 8
308 +#define PCI_EEPROM_WIDTH_OPCODE 3
309 +#define PCI_EEPROM_WRITE_OPCODE 0x05
310 +#define PCI_EEPROM_READ_OPCODE 0x06
311 +#define PCI_EEPROM_EWDS_OPCODE 0x10
312 +#define PCI_EEPROM_EWEN_OPCODE 0x13
315 + * struct eeprom_93cx6 - control structure for setting the commands
316 + * for reading the eeprom data.
317 + * @data: private pointer for the driver.
318 + * @register_read(struct eeprom_93cx6 *eeprom): handler to
319 + * read the eeprom register, this function should set all reg_* fields.
320 + * @register_write(struct eeprom_93cx6 *eeprom): handler to
321 + * write to the eeprom register by using all reg_* fields.
322 + * @width: eeprom width, should be one of the PCI_EEPROM_WIDTH_* defines
323 + * @reg_data_in: register field to indicate data input
324 + * @reg_data_out: register field to indicate data output
325 + * @reg_data_clock: register field to set the data clock
326 + * @reg_chip_select: register field to set the chip select
328 + * This structure is used for the communication between the driver
329 + * and the eeprom_93cx6 handlers for reading the eeprom.
331 +struct eeprom_93cx6 {
334 + void (*register_read)(struct eeprom_93cx6 *eeprom);
335 + void (*register_write)(struct eeprom_93cx6 *eeprom);
341 + char reg_data_clock;
342 + char reg_chip_select;
345 +extern void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom,
346 + const u8 word, u16 *data);
347 +extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom,
348 + const u8 word, __le16 *data, const u16 words);