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 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
16 index 616eee9..bd601ef 100644
17 --- a/drivers/misc/Kconfig
18 +++ b/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 diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
38 index 8abbf2f..b5ce0e3 100644
39 --- a/drivers/misc/Makefile
40 +++ b/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 diff --git a/drivers/misc/eeprom_93cx6.c b/drivers/misc/eeprom_93cx6.c
48 index 0000000..bfcb434
50 +++ b/drivers/misc/eeprom_93cx6.c
53 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
54 + <http://rt2x00.serialmonkey.com>
56 + This program is free software; you can redistribute it and/or modify
57 + it under the terms of the GNU General Public License as published by
58 + the Free Software Foundation; either version 2 of the License, or
59 + (at your option) any later version.
61 + This program is distributed in the hope that it will be useful,
62 + but WITHOUT ANY WARRANTY; without even the implied warranty of
63 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
64 + GNU General Public License for more details.
66 + You should have received a copy of the GNU General Public License
67 + along with this program; if not, write to the
68 + Free Software Foundation, Inc.,
69 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
73 + Module: eeprom_93cx6
74 + Abstract: EEPROM reader routines for 93cx6 chipsets.
75 + Supported chipsets: 93c46 & 93c66.
78 +#include <linux/kernel.h>
79 +#include <linux/module.h>
80 +#include <linux/version.h>
81 +#include <linux/delay.h>
82 +#include <linux/eeprom_93cx6.h>
84 +MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
85 +MODULE_VERSION("1.0");
86 +MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
87 +MODULE_LICENSE("GPL");
89 +static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
91 + eeprom->reg_data_clock = 1;
92 + eeprom->register_write(eeprom);
96 +static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
98 + eeprom->reg_data_clock = 0;
99 + eeprom->register_write(eeprom);
103 +static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
106 + * Clear all flags, and enable chip select.
108 + eeprom->register_read(eeprom);
109 + eeprom->reg_data_in = 0;
110 + eeprom->reg_data_out = 0;
111 + eeprom->reg_data_clock = 0;
112 + eeprom->reg_chip_select = 1;
113 + eeprom->register_write(eeprom);
118 + eeprom_93cx6_pulse_high(eeprom);
119 + eeprom_93cx6_pulse_low(eeprom);
122 +static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
125 + * Clear chip_select and data_in flags.
127 + eeprom->register_read(eeprom);
128 + eeprom->reg_data_in = 0;
129 + eeprom->reg_chip_select = 0;
130 + eeprom->register_write(eeprom);
135 + eeprom_93cx6_pulse_high(eeprom);
136 + eeprom_93cx6_pulse_low(eeprom);
139 +static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
140 + const u16 data, const u16 count)
144 + eeprom->register_read(eeprom);
147 + * Clear data flags.
149 + eeprom->reg_data_in = 0;
150 + eeprom->reg_data_out = 0;
153 + * Start writing all bits.
155 + for (i = count; i > 0; i--) {
157 + * Check if this bit needs to be set.
159 + eeprom->reg_data_in = !!(data & (1 << (i - 1)));
162 + * Write the bit to the eeprom register.
164 + eeprom->register_write(eeprom);
169 + eeprom_93cx6_pulse_high(eeprom);
170 + eeprom_93cx6_pulse_low(eeprom);
173 + eeprom->reg_data_in = 0;
174 + eeprom->register_write(eeprom);
177 +static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
178 + u16 *data, const u16 count)
183 + eeprom->register_read(eeprom);
186 + * Clear data flags.
188 + eeprom->reg_data_in = 0;
189 + eeprom->reg_data_out = 0;
192 + * Start reading all bits.
194 + for (i = count; i > 0; i--) {
195 + eeprom_93cx6_pulse_high(eeprom);
197 + eeprom->register_read(eeprom);
200 + * Clear data_in flag.
202 + eeprom->reg_data_in = 0;
205 + * Read if the bit has been set.
207 + if (eeprom->reg_data_out)
208 + buf |= (1 << (i - 1));
210 + eeprom_93cx6_pulse_low(eeprom);
217 + * eeprom_93cx6_read - Read multiple words from eeprom
218 + * @eeprom: Pointer to eeprom structure
219 + * @word: Word index from where we should start reading
220 + * @data: target pointer where the information will have to be stored
222 + * This function will read the eeprom data as host-endian word
223 + * into the given data pointer.
225 +void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
231 + * Initialize the eeprom register
233 + eeprom_93cx6_startup(eeprom);
236 + * Select the read opcode and the word to be read.
238 + command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
239 + eeprom_93cx6_write_bits(eeprom, command,
240 + PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
243 + * Read the requested 16 bits.
245 + eeprom_93cx6_read_bits(eeprom, data, 16);
248 + * Cleanup eeprom register.
250 + eeprom_93cx6_cleanup(eeprom);
252 +EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
255 + * eeprom_93cx6_multiread - Read multiple words from eeprom
256 + * @eeprom: Pointer to eeprom structure
257 + * @word: Word index from where we should start reading
258 + * @data: target pointer where the information will have to be stored
259 + * @words: Number of words that should be read.
261 + * This function will read all requested words from the eeprom,
262 + * this is done by calling eeprom_93cx6_read() multiple times.
263 + * But with the additional change that while the eeprom_93cx6_read
264 + * will return host ordered bytes, this method will return little
267 +void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
268 + __le16 *data, const u16 words)
273 + for (i = 0; i < words; i++) {
275 + eeprom_93cx6_read(eeprom, word + i, &tmp);
276 + data[i] = cpu_to_le16(tmp);
279 +EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
281 diff --git a/include/linux/eeprom_93cx6.h b/include/linux/eeprom_93cx6.h
283 index 0000000..d774b77
285 +++ b/include/linux/eeprom_93cx6.h
288 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
289 + <http://rt2x00.serialmonkey.com>
291 + This program is free software; you can redistribute it and/or modify
292 + it under the terms of the GNU General Public License as published by
293 + the Free Software Foundation; either version 2 of the License, or
294 + (at your option) any later version.
296 + This program is distributed in the hope that it will be useful,
297 + but WITHOUT ANY WARRANTY; without even the implied warranty of
298 + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
299 + GNU General Public License for more details.
301 + You should have received a copy of the GNU General Public License
302 + along with this program; if not, write to the
303 + Free Software Foundation, Inc.,
304 + 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
308 + Module: eeprom_93cx6
309 + Abstract: EEPROM reader datastructures for 93cx6 chipsets.
310 + Supported chipsets: 93c46 & 93c66.
314 + * EEPROM operation defines.
316 +#define PCI_EEPROM_WIDTH_93C46 6
317 +#define PCI_EEPROM_WIDTH_93C66 8
318 +#define PCI_EEPROM_WIDTH_OPCODE 3
319 +#define PCI_EEPROM_WRITE_OPCODE 0x05
320 +#define PCI_EEPROM_READ_OPCODE 0x06
321 +#define PCI_EEPROM_EWDS_OPCODE 0x10
322 +#define PCI_EEPROM_EWEN_OPCODE 0x13
325 + * struct eeprom_93cx6 - control structure for setting the commands
326 + * for reading the eeprom data.
327 + * @data: private pointer for the driver.
328 + * @register_read(struct eeprom_93cx6 *eeprom): handler to
329 + * read the eeprom register, this function should set all reg_* fields.
330 + * @register_write(struct eeprom_93cx6 *eeprom): handler to
331 + * write to the eeprom register by using all reg_* fields.
332 + * @width: eeprom width, should be one of the PCI_EEPROM_WIDTH_* defines
333 + * @reg_data_in: register field to indicate data input
334 + * @reg_data_out: register field to indicate data output
335 + * @reg_data_clock: register field to set the data clock
336 + * @reg_chip_select: register field to set the chip select
338 + * This structure is used for the communication between the driver
339 + * and the eeprom_93cx6 handlers for reading the eeprom.
341 +struct eeprom_93cx6 {
344 + void (*register_read)(struct eeprom_93cx6 *eeprom);
345 + void (*register_write)(struct eeprom_93cx6 *eeprom);
351 + char reg_data_clock;
352 + char reg_chip_select;
355 +extern void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom,
356 + const u8 word, u16 *data);
357 +extern void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom,
358 + const u8 word, __le16 *data, const u16 words);