Update the PS3 target README with some installation tips, and
[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 --- a/drivers/misc/Kconfig
16 +++ b/drivers/misc/Kconfig
17 @@ -34,6 +34,11 @@
18 If you choose to build module, its name will be phantom. If unsure,
19 say N here.
20
21 +config EEPROM_93CX6
22 + tristate "EEPROM 93CX6 support"
23 + ---help---
24 + This is a driver for the EEPROM chipsets 93c46 and 93c66.
25 + The driver supports both read as well as write commands.
26
27 If unsure, say N.
28
29 @@ -187,5 +192,4 @@
30
31 If you are not sure, say Y here.
32
33 -
34 endmenu
35 --- a/drivers/misc/Makefile
36 +++ b/drivers/misc/Makefile
37 @@ -14,3 +14,4 @@
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
42 --- /dev/null
43 +++ b/drivers/misc/eeprom_93cx6.c
44 @@ -0,0 +1,229 @@
45 +/*
46 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
47 + <http://rt2x00.serialmonkey.com>
48 +
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.
53 +
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.
58 +
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.
63 + */
64 +
65 +/*
66 + Module: eeprom_93cx6
67 + Abstract: EEPROM reader routines for 93cx6 chipsets.
68 + Supported chipsets: 93c46 & 93c66.
69 + */
70 +
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>
76 +
77 +MODULE_AUTHOR("http://rt2x00.serialmonkey.com");
78 +MODULE_VERSION("1.0");
79 +MODULE_DESCRIPTION("EEPROM 93cx6 chip driver");
80 +MODULE_LICENSE("GPL");
81 +
82 +static inline void eeprom_93cx6_pulse_high(struct eeprom_93cx6 *eeprom)
83 +{
84 + eeprom->reg_data_clock = 1;
85 + eeprom->register_write(eeprom);
86 + udelay(1);
87 +}
88 +
89 +static inline void eeprom_93cx6_pulse_low(struct eeprom_93cx6 *eeprom)
90 +{
91 + eeprom->reg_data_clock = 0;
92 + eeprom->register_write(eeprom);
93 + udelay(1);
94 +}
95 +
96 +static void eeprom_93cx6_startup(struct eeprom_93cx6 *eeprom)
97 +{
98 + /*
99 + * Clear all flags, and enable chip select.
100 + */
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);
107 +
108 + /*
109 + * kick a pulse.
110 + */
111 + eeprom_93cx6_pulse_high(eeprom);
112 + eeprom_93cx6_pulse_low(eeprom);
113 +}
114 +
115 +static void eeprom_93cx6_cleanup(struct eeprom_93cx6 *eeprom)
116 +{
117 + /*
118 + * Clear chip_select and data_in flags.
119 + */
120 + eeprom->register_read(eeprom);
121 + eeprom->reg_data_in = 0;
122 + eeprom->reg_chip_select = 0;
123 + eeprom->register_write(eeprom);
124 +
125 + /*
126 + * kick a pulse.
127 + */
128 + eeprom_93cx6_pulse_high(eeprom);
129 + eeprom_93cx6_pulse_low(eeprom);
130 +}
131 +
132 +static void eeprom_93cx6_write_bits(struct eeprom_93cx6 *eeprom,
133 + const u16 data, const u16 count)
134 +{
135 + unsigned int i;
136 +
137 + eeprom->register_read(eeprom);
138 +
139 + /*
140 + * Clear data flags.
141 + */
142 + eeprom->reg_data_in = 0;
143 + eeprom->reg_data_out = 0;
144 +
145 + /*
146 + * Start writing all bits.
147 + */
148 + for (i = count; i > 0; i--) {
149 + /*
150 + * Check if this bit needs to be set.
151 + */
152 + eeprom->reg_data_in = !!(data & (1 << (i - 1)));
153 +
154 + /*
155 + * Write the bit to the eeprom register.
156 + */
157 + eeprom->register_write(eeprom);
158 +
159 + /*
160 + * Kick a pulse.
161 + */
162 + eeprom_93cx6_pulse_high(eeprom);
163 + eeprom_93cx6_pulse_low(eeprom);
164 + }
165 +
166 + eeprom->reg_data_in = 0;
167 + eeprom->register_write(eeprom);
168 +}
169 +
170 +static void eeprom_93cx6_read_bits(struct eeprom_93cx6 *eeprom,
171 + u16 *data, const u16 count)
172 +{
173 + unsigned int i;
174 + u16 buf = 0;
175 +
176 + eeprom->register_read(eeprom);
177 +
178 + /*
179 + * Clear data flags.
180 + */
181 + eeprom->reg_data_in = 0;
182 + eeprom->reg_data_out = 0;
183 +
184 + /*
185 + * Start reading all bits.
186 + */
187 + for (i = count; i > 0; i--) {
188 + eeprom_93cx6_pulse_high(eeprom);
189 +
190 + eeprom->register_read(eeprom);
191 +
192 + /*
193 + * Clear data_in flag.
194 + */
195 + eeprom->reg_data_in = 0;
196 +
197 + /*
198 + * Read if the bit has been set.
199 + */
200 + if (eeprom->reg_data_out)
201 + buf |= (1 << (i - 1));
202 +
203 + eeprom_93cx6_pulse_low(eeprom);
204 + }
205 +
206 + *data = buf;
207 +}
208 +
209 +/**
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
214 + *
215 + * This function will read the eeprom data as host-endian word
216 + * into the given data pointer.
217 + */
218 +void eeprom_93cx6_read(struct eeprom_93cx6 *eeprom, const u8 word,
219 + u16 *data)
220 +{
221 + u16 command;
222 +
223 + /*
224 + * Initialize the eeprom register
225 + */
226 + eeprom_93cx6_startup(eeprom);
227 +
228 + /*
229 + * Select the read opcode and the word to be read.
230 + */
231 + command = (PCI_EEPROM_READ_OPCODE << eeprom->width) | word;
232 + eeprom_93cx6_write_bits(eeprom, command,
233 + PCI_EEPROM_WIDTH_OPCODE + eeprom->width);
234 +
235 + /*
236 + * Read the requested 16 bits.
237 + */
238 + eeprom_93cx6_read_bits(eeprom, data, 16);
239 +
240 + /*
241 + * Cleanup eeprom register.
242 + */
243 + eeprom_93cx6_cleanup(eeprom);
244 +}
245 +EXPORT_SYMBOL_GPL(eeprom_93cx6_read);
246 +
247 +/**
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.
253 + *
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
258 + * endian words.
259 + */
260 +void eeprom_93cx6_multiread(struct eeprom_93cx6 *eeprom, const u8 word,
261 + __le16 *data, const u16 words)
262 +{
263 + unsigned int i;
264 + u16 tmp;
265 +
266 + for (i = 0; i < words; i++) {
267 + tmp = 0;
268 + eeprom_93cx6_read(eeprom, word + i, &tmp);
269 + data[i] = cpu_to_le16(tmp);
270 + }
271 +}
272 +EXPORT_SYMBOL_GPL(eeprom_93cx6_multiread);
273 +
274 --- /dev/null
275 +++ b/include/linux/eeprom_93cx6.h
276 @@ -0,0 +1,72 @@
277 +/*
278 + Copyright (C) 2004 - 2006 rt2x00 SourceForge Project
279 + <http://rt2x00.serialmonkey.com>
280 +
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.
285 +
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.
290 +
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.
295 + */
296 +
297 +/*
298 + Module: eeprom_93cx6
299 + Abstract: EEPROM reader datastructures for 93cx6 chipsets.
300 + Supported chipsets: 93c46 & 93c66.
301 + */
302 +
303 +/*
304 + * EEPROM operation defines.
305 + */
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
313 +
314 +/**
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
327 + *
328 + * This structure is used for the communication between the driver
329 + * and the eeprom_93cx6 handlers for reading the eeprom.
330 + */
331 +struct eeprom_93cx6 {
332 + void *data;
333 +
334 + void (*register_read)(struct eeprom_93cx6 *eeprom);
335 + void (*register_write)(struct eeprom_93cx6 *eeprom);
336 +
337 + int width;
338 +
339 + char reg_data_in;
340 + char reg_data_out;
341 + char reg_data_clock;
342 + char reg_chip_select;
343 +};
344 +
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);
This page took 0.060887 seconds and 5 git commands to generate.