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 Index: linux-2.6.22.19/drivers/misc/Kconfig
16 ===================================================================
17 --- linux-2.6.22.19.orig/drivers/misc/Kconfig
18 +++ linux-2.6.22.19/drivers/misc/Kconfig
19 @@ -34,6 +34,11 @@ config PHANTOM
20 If you choose to build module, its name will be phantom. If unsure,
24 + tristate "EEPROM 93CX6 support"
26 + This is a driver for the EEPROM chipsets 93c46 and 93c66.
27 + The driver supports both read as well as write commands.
31 @@ -187,5 +192,4 @@ config THINKPAD_ACPI_BAY
33 If you are not sure, say Y here.
37 Index: linux-2.6.22.19/drivers/misc/Makefile
38 ===================================================================
39 --- linux-2.6.22.19.orig/drivers/misc/Makefile
40 +++ linux-2.6.22.19/drivers/misc/Makefile
41 @@ -14,3 +14,4 @@ obj-$(CONFIG_PHANTOM) += phantom.o
42 obj-$(CONFIG_SGI_IOC4) += ioc4.o
43 obj-$(CONFIG_SONY_LAPTOP) += sony-laptop.o
44 obj-$(CONFIG_THINKPAD_ACPI) += thinkpad_acpi.o
45 +obj-$(CONFIG_EEPROM_93CX6) += eeprom_93cx6.o
46 Index: linux-2.6.22.19/drivers/misc/eeprom_93cx6.c
47 ===================================================================
49 +++ linux-2.6.22.19/drivers/misc/eeprom_93cx6.c
52 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
53 + <http://rt2x00.serialmonkey.com>
55 + This program is free software; you can redistribute it and/or modify
56 + it under the terms of the GNU General Public License as published by
57 + the Free Software Foundation; either version 2 of the License, or
58 + (at your option) any later version.
60 + This program is distributed in the hope that it will be useful,
61 + but WITHOUT ANY WARRANTY; without even the implied warranty of
62 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
63 + GNU General Public License for more details.
65 + You should have received a copy of the GNU General Public License
66 + along with this program; if not, write to the
67 + Free Software Foundation, Inc.,
68 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
72 + Module: eeprom_93cx6
73 + Abstract: EEPROM reader routines for 93cx6 chipsets.
74 + Supported chipsets: 93c46 & 93c66.
77 +#include <linux/kernel.h>
78 +#include <linux/module.h>
79 +#include <linux/version.h>
80 +#include <linux/delay.h>
81 +#include <linux/eeprom_93cx6.h>
83 +MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
84 +MODULE_VERSION("1.0");
85 +MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
86 +MODULE_LICENSE("GPL");
88 +static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
90 + eeprom->reg_data_clock = 1;
91 + eeprom->register_write(eeprom);
95 +static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
97 + eeprom->reg_data_clock = 0;
98 + eeprom->register_write(eeprom);
102 +static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
105 + * Clear all flags, and enable chip select.
107 + eeprom->register_read(eeprom);
108 + eeprom->reg_data_in = 0;
109 + eeprom->reg_data_out = 0;
110 + eeprom->reg_data_clock = 0;
111 + eeprom->reg_chip_select = 1;
112 + eeprom->register_write(eeprom);
117 + eeprom_93cx6_pulse_high(eeprom);
118 + eeprom_93cx6_pulse_low(eeprom);
121 +static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
124 + * Clear chip_select and data_in flags.
126 + eeprom->register_read(eeprom);
127 + eeprom->reg_data_in = 0;
128 + eeprom->reg_chip_select = 0;
129 + eeprom->register_write(eeprom);
134 + eeprom_93cx6_pulse_high(eeprom);
135 + eeprom_93cx6_pulse_low(eeprom);
138 +static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
139 + const u16 data, const u16 count)
143 + eeprom->register_read(eeprom);
146 + * Clear data flags.
148 + eeprom->reg_data_in = 0;
149 + eeprom->reg_data_out = 0;
152 + * Start writing all bits.
154 + for (i = count; i > 0; i--) {
156 + * Check if this bit needs to be set.
158 + eeprom->reg_data_in = !!(data & (1 << (i - 1)));
161 + * Write the bit to the eeprom register.
163 + eeprom->register_write(eeprom);
168 + eeprom_93cx6_pulse_high(eeprom);
169 + eeprom_93cx6_pulse_low(eeprom);
172 + eeprom->reg_data_in = 0;
173 + eeprom->register_write(eeprom);
176 +static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
177 + u16 *data, const u16 count)
182 + eeprom->register_read(eeprom);
185 + * Clear data flags.
187 + eeprom->reg_data_in = 0;
188 + eeprom->reg_data_out = 0;
191 + * Start reading all bits.
193 + for (i = count; i > 0; i--) {
194 + eeprom_93cx6_pulse_high(eeprom);
196 + eeprom->register_read(eeprom);
199 + * Clear data_in flag.
201 + eeprom->reg_data_in = 0;
204 + * Read if the bit has been set.
206 + if (eeprom->reg_data_out)
207 + buf |= (1 << (i - 1));
209 + eeprom_93cx6_pulse_low(eeprom);
216 + * eeprom_93cx6_read - Read multiple words from eeprom
217 + * @eeprom: Pointer to eeprom structure
218 + * @word: Word index from where we should start reading
219 + * @data: target pointer where the information will have to be stored
221 + * This function will read the eeprom data as host-endian word
222 + * into the given data pointer.
224 +void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
230 + * Initialize the eeprom register
232 + eeprom_93cx6_startup(eeprom);
235 + * Select the read opcode and the word to be read.
237 + command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
238 + eeprom_93cx6_write_bits(eeprom, command,
239 + PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
242 + * Read the requested 16 bits.
244 + eeprom_93cx6_read_bits(eeprom, data, 16);
247 + * Cleanup eeprom register.
249 + eeprom_93cx6_cleanup(eeprom);
251 +EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
254 + * eeprom_93cx6_multiread - Read multiple words from eeprom
255 + * @eeprom: Pointer to eeprom structure
256 + * @word: Word index from where we should start reading
257 + * @data: target pointer where the information will have to be stored
258 + * @words: Number of words that should be read.
260 + * This function will read all requested words from the eeprom,
261 + * this is done by calling eeprom_93cx6_read() multiple times.
262 + * But with the additional change that while the eeprom_93cx6_read
263 + * will return host ordered bytes, this method will return little
266 +void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
267 + __le16 *data, const u16 words)
272 + for (i = 0; i < words; i++) {
274 + eeprom_93cx6_read(eeprom, word + i, &tmp);
275 + data[i] = cpu_to_le16(tmp);
278 +EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
280 Index: linux-2.6.22.19/include/linux/eeprom_93cx6.h
281 ===================================================================
283 +++ linux-2.6.22.19/include/linux/eeprom_93cx6.h
286 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
287 + <http://rt2x00.serialmonkey.com>
289 + This program is free software; you can redistribute it and/or modify
290 + it under the terms of the GNU General Public License as published by
291 + the Free Software Foundation; either version 2 of the License, or
292 + (at your option) any later version.
294 + This program is distributed in the hope that it will be useful,
295 + but WITHOUT ANY WARRANTY; without even the implied warranty of
296 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
297 + GNU General Public License for more details.
299 + You should have received a copy of the GNU General Public License
300 + along with this program; if not, write to the
301 + Free Software Foundation, Inc.,
302 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
306 + Module: eeprom_93cx6
307 + Abstract: EEPROM reader datastructures for 93cx6 chipsets.
308 + Supported chipsets: 93c46 & 93c66.
312 + * EEPROM operation defines.
314 +#define PCI_EEPROM_WIDTH_93C46 6
315 +#define PCI_EEPROM_WIDTH_93C66 8
316 +#define PCI_EEPROM_WIDTH_OPCODE 3
317 +#define PCI_EEPROM_WRITE_OPCODE 0x05
318 +#define PCI_EEPROM_READ_OPCODE 0x06
319 +#define PCI_EEPROM_EWDS_OPCODE 0x10
320 +#define PCI_EEPROM_EWEN_OPCODE 0x13
323 + * struct eeprom_93cx6 - control structure for setting the commands
324 + * for reading the eeprom data.
325 + * @data: private pointer for the driver.
326 + * @register_read(struct eeprom_93cx6 *eeprom): handler to
327 + * read the eeprom register, this function should set all reg_* fields.
328 + * @register_write(struct eeprom_93cx6 *eeprom): handler to
329 + * write to the eeprom register by using all reg_* fields.
330 + * @width: eeprom width, should be one of the PCI_EEPROM_WIDTH_* defines
331 + * @reg_data_in: register field to indicate data input
332 + * @reg_data_out: register field to indicate data output
333 + * @reg_data_clock: register field to set the data clock
334 + * @reg_chip_select: register field to set the chip select
336 + * This structure is used for the communication between the driver
337 + * and the eeprom_93cx6 handlers for reading the eeprom.
339 +struct eeprom_93cx6 {
342 + void (*register_read)(struct eeprom_93cx6 *eeprom);
343 + void (*register_write)(struct eeprom_93cx6 *eeprom);
349 + char reg_data_clock;
350 + char reg_chip_select;
353 +extern void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom,
354 + const u8 word, u16 *data);
355 +extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom,
356 + const u8 word, __le16 *data, const u16 words);