[adm5120] add button devices to several boards
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.22 / 600-eeprom_93cx6.patch
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
6
7 [PATCH] Add 93cx6 eeprom library
8
9 This patch adds a library for reading from 93cx6 eeproms.
10
11 Signed-off-by: Michael Wu <flamingice@sourmilk.net>
12 Signed-off-by: John W. Linville <linville@tuxdriver.com>
13 ---
14
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,
21 say N here.
22
23 +config EEPROM_93CX6
24 + tristate "EEPROM 93CX6 support"
25 + ---help---
26 + This is a driver for the EEPROM chipsets 93c46 and 93c66.
27 + The driver supports both read as well as write commands.
28
29 If unsure, say N.
30
31 @@ -187,5 +192,4 @@ config THINKPAD_ACPI_BAY
32
33 If you are not sure, say Y here.
34
35 -
36 endmenu
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 ===================================================================
48 --- /dev/null
49 +++ linux-2.6.22.19/drivers/misc/eeprom_93cx6.c
50 @@ -0,0 +1,229 @@
51 +/*
52 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
53 + <http://rt2x00.serialmonkey.com>
54 +
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.
59 +
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.
64 +
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.
69 + */
70 +
71 +/*
72 + Module: eeprom_93cx6
73 + Abstract: EEPROM reader routines for 93cx6 chipsets.
74 + Supported chipsets: 93c46 & 93c66.
75 + */
76 +
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>
82 +
83 +MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
84 +MODULE_VERSION("1.0");
85 +MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
86 +MODULE_LICENSE("GPL");
87 +
88 +static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
89 +{
90 + eeprom->reg_data_clock = 1;
91 + eeprom->register_write(eeprom);
92 + udelay(1);
93 +}
94 +
95 +static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
96 +{
97 + eeprom->reg_data_clock = 0;
98 + eeprom->register_write(eeprom);
99 + udelay(1);
100 +}
101 +
102 +static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
103 +{
104 + /*
105 + * Clear all flags, and enable chip select.
106 + */
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);
113 +
114 + /*
115 + * kick a pulse.
116 + */
117 + eeprom_93cx6_pulse_high(eeprom);
118 + eeprom_93cx6_pulse_low(eeprom);
119 +}
120 +
121 +static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
122 +{
123 + /*
124 + * Clear chip_select and data_in flags.
125 + */
126 + eeprom->register_read(eeprom);
127 + eeprom->reg_data_in = 0;
128 + eeprom->reg_chip_select = 0;
129 + eeprom->register_write(eeprom);
130 +
131 + /*
132 + * kick a pulse.
133 + */
134 + eeprom_93cx6_pulse_high(eeprom);
135 + eeprom_93cx6_pulse_low(eeprom);
136 +}
137 +
138 +static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
139 + const u16 data, const u16 count)
140 +{
141 + unsigned int i;
142 +
143 + eeprom->register_read(eeprom);
144 +
145 + /*
146 + * Clear data flags.
147 + */
148 + eeprom->reg_data_in = 0;
149 + eeprom->reg_data_out = 0;
150 +
151 + /*
152 + * Start writing all bits.
153 + */
154 + for (i = count; i > 0; i--) {
155 + /*
156 + * Check if this bit needs to be set.
157 + */
158 + eeprom->reg_data_in = !!(data & (1 << (i - 1)));
159 +
160 + /*
161 + * Write the bit to the eeprom register.
162 + */
163 + eeprom->register_write(eeprom);
164 +
165 + /*
166 + * Kick a pulse.
167 + */
168 + eeprom_93cx6_pulse_high(eeprom);
169 + eeprom_93cx6_pulse_low(eeprom);
170 + }
171 +
172 + eeprom->reg_data_in = 0;
173 + eeprom->register_write(eeprom);
174 +}
175 +
176 +static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
177 + u16 *data, const u16 count)
178 +{
179 + unsigned int i;
180 + u16 buf = 0;
181 +
182 + eeprom->register_read(eeprom);
183 +
184 + /*
185 + * Clear data flags.
186 + */
187 + eeprom->reg_data_in = 0;
188 + eeprom->reg_data_out = 0;
189 +
190 + /*
191 + * Start reading all bits.
192 + */
193 + for (i = count; i > 0; i--) {
194 + eeprom_93cx6_pulse_high(eeprom);
195 +
196 + eeprom->register_read(eeprom);
197 +
198 + /*
199 + * Clear data_in flag.
200 + */
201 + eeprom->reg_data_in = 0;
202 +
203 + /*
204 + * Read if the bit has been set.
205 + */
206 + if (eeprom->reg_data_out)
207 + buf |= (1 << (i - 1));
208 +
209 + eeprom_93cx6_pulse_low(eeprom);
210 + }
211 +
212 + *data = buf;
213 +}
214 +
215 +/**
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
220 + *
221 + * This function will read the eeprom data as host-endian word
222 + * into the given data pointer.
223 + */
224 +void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
225 + u16 *data)
226 +{
227 + u16 command;
228 +
229 + /*
230 + * Initialize the eeprom register
231 + */
232 + eeprom_93cx6_startup(eeprom);
233 +
234 + /*
235 + * Select the read opcode and the word to be read.
236 + */
237 + command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
238 + eeprom_93cx6_write_bits(eeprom, command,
239 + PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
240 +
241 + /*
242 + * Read the requested 16 bits.
243 + */
244 + eeprom_93cx6_read_bits(eeprom, data, 16);
245 +
246 + /*
247 + * Cleanup eeprom register.
248 + */
249 + eeprom_93cx6_cleanup(eeprom);
250 +}
251 +EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
252 +
253 +/**
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.
259 + *
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
264 + * endian words.
265 + */
266 +void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
267 + __le16 *data, const u16 words)
268 +{
269 + unsigned int i;
270 + u16 tmp;
271 +
272 + for (i = 0; i < words; i++) {
273 + tmp = 0;
274 + eeprom_93cx6_read(eeprom, word + i, &tmp);
275 + data[i] = cpu_to_le16(tmp);
276 + }
277 +}
278 +EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
279 +
280 Index: linux-2.6.22.19/include/linux/eeprom_93cx6.h
281 ===================================================================
282 --- /dev/null
283 +++ linux-2.6.22.19/include/linux/eeprom_93cx6.h
284 @@ -0,0 +1,72 @@
285 +/*
286 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
287 + <http://rt2x00.serialmonkey.com>
288 +
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.
293 +
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.
298 +
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.
303 + */
304 +
305 +/*
306 + Module: eeprom_93cx6
307 + Abstract: EEPROM reader datastructures for 93cx6 chipsets.
308 + Supported chipsets: 93c46 & 93c66.
309 + */
310 +
311 +/*
312 + * EEPROM operation defines.
313 + */
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
321 +
322 +/**
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
335 + *
336 + * This structure is used for the communication between the driver
337 + * and the eeprom_93cx6 handlers for reading the eeprom.
338 + */
339 +struct eeprom_93cx6 {
340 + void *data;
341 +
342 + void (*register_read)(struct eeprom_93cx6 *eeprom);
343 + void (*register_write)(struct eeprom_93cx6 *eeprom);
344 +
345 + int width;
346 +
347 + char reg_data_in;
348 + char reg_data_out;
349 + char reg_data_clock;
350 + char reg_chip_select;
351 +};
352 +
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);
This page took 0.061339 seconds and 5 git commands to generate.