allow coexistance of N build and AC build.
[tomato.git] / release / src-rt-6.x / linux / linux-2.6 / arch / cris / arch-v10 / drivers / eeprom.c
blobbe35a70798aa5cc008807e6cc7488ba45f0d24dc
1 /*!*****************************************************************************
2 *!
3 *! Implements an interface for i2c compatible eeproms to run under Linux.
4 *! Supports 2k, 8k(?) and 16k. Uses adaptive timing adjustments by
5 *! Johan.Adolfsson@axis.com
6 *!
7 *! Probing results:
8 *! 8k or not is detected (the assumes 2k or 16k)
9 *! 2k or 16k detected using test reads and writes.
11 *!------------------------------------------------------------------------
12 *! HISTORY
14 *! DATE NAME CHANGES
15 *! ---- ---- -------
16 *! Aug 28 1999 Edgar Iglesias Initial Version
17 *! Aug 31 1999 Edgar Iglesias Allow simultaneous users.
18 *! Sep 03 1999 Edgar Iglesias Updated probe.
19 *! Sep 03 1999 Edgar Iglesias Added bail-out stuff if we get interrupted
20 *! in the spin-lock.
22 *! $Log: eeprom.c,v $
23 *! Revision 1.12 2005/06/19 17:06:46 starvik
24 *! Merge of Linux 2.6.12.
26 *! Revision 1.11 2005/01/26 07:14:46 starvik
27 *! Applied diff from kernel janitors (Nish Aravamudan).
29 *! Revision 1.10 2003/09/11 07:29:48 starvik
30 *! Merge of Linux 2.6.0-test5
32 *! Revision 1.9 2003/07/04 08:27:37 starvik
33 *! Merge of Linux 2.5.74
35 *! Revision 1.8 2003/04/09 05:20:47 starvik
36 *! Merge of Linux 2.5.67
38 *! Revision 1.6 2003/02/10 07:19:28 starvik
39 *! Removed misplaced ;
41 *! Revision 1.5 2002/12/11 13:13:57 starvik
42 *! Added arch/ to v10 specific includes
43 *! Added fix from Linux 2.4 in serial.c (flush_to_flip_buffer)
45 *! Revision 1.4 2002/11/20 11:56:10 starvik
46 *! Merge of Linux 2.5.48
48 *! Revision 1.3 2002/11/18 13:16:06 starvik
49 *! Linux 2.5 port of latest 2.4 drivers
51 *! Revision 1.8 2001/06/15 13:24:29 jonashg
52 *! * Added verification of pointers from userspace in read and write.
53 *! * Made busy counter volatile.
54 *! * Added define for initial write delay.
55 *! * Removed warnings by using loff_t instead of unsigned long.
57 *! Revision 1.7 2001/06/14 15:26:54 jonashg
58 *! Removed test because condition is always true.
60 *! Revision 1.6 2001/06/14 15:18:20 jonashg
61 *! Kb -> kB (makes quite a difference if you don't know if you have 2k or 16k).
63 *! Revision 1.5 2001/06/14 14:39:51 jonashg
64 *! Forgot to use name when registering the driver.
66 *! Revision 1.4 2001/06/14 14:35:47 jonashg
67 *! * Gave driver a name and used it in printk's.
68 *! * Cleanup.
70 *! Revision 1.3 2001/03/19 16:04:46 markusl
71 *! Fixed init of fops struct
73 *! Revision 1.2 2001/03/19 10:35:07 markusl
74 *! 2.4 port of eeprom driver
76 *! Revision 1.8 2000/05/18 10:42:25 edgar
77 *! Make sure to end write cycle on _every_ write
79 *! Revision 1.7 2000/01/17 17:41:01 johana
80 *! Adjusted probing and return -ENOSPC when writing outside EEPROM
82 *! Revision 1.6 2000/01/17 15:50:36 johana
83 *! Added adaptive timing adjustments and fixed autoprobing for 2k and 16k(?)
84 *! EEPROMs
86 *! Revision 1.5 1999/09/03 15:07:37 edgar
87 *! Added bail-out check to the spinlock
89 *! Revision 1.4 1999/09/03 12:11:17 bjornw
90 *! Proper atomicity (need to use spinlocks, not if's). users -> busy.
93 *! (c) 1999 Axis Communications AB, Lund, Sweden
94 *!*****************************************************************************/
96 #include <linux/kernel.h>
97 #include <linux/sched.h>
98 #include <linux/fs.h>
99 #include <linux/init.h>
100 #include <linux/delay.h>
101 #include <linux/interrupt.h>
102 #include <linux/wait.h>
103 #include <asm/uaccess.h>
104 #include "i2c.h"
106 #define D(x)
108 /* If we should use adaptive timing or not: */
109 //#define EEPROM_ADAPTIVE_TIMING
111 #define EEPROM_MAJOR_NR 122 /* use a LOCAL/EXPERIMENTAL major for now */
112 #define EEPROM_MINOR_NR 0
114 /* Empirical sane initial value of the delay, the value will be adapted to
115 * what the chip needs when using EEPROM_ADAPTIVE_TIMING.
117 #define INITIAL_WRITEDELAY_US 4000
118 #define MAX_WRITEDELAY_US 10000 /* 10 ms according to spec for 2KB EEPROM */
120 /* This one defines how many times to try when eeprom fails. */
121 #define EEPROM_RETRIES 10
123 #define EEPROM_2KB (2 * 1024)
124 /*#define EEPROM_4KB (4 * 1024)*/ /* Exists but not used in Axis products */
125 #define EEPROM_8KB (8 * 1024 - 1 ) /* Last byte has write protection bit */
126 #define EEPROM_16KB (16 * 1024)
128 #define i2c_delay(x) udelay(x)
131 * This structure describes the attached eeprom chip.
132 * The values are probed for.
135 struct eeprom_type
137 unsigned long size;
138 unsigned long sequential_write_pagesize;
139 unsigned char select_cmd;
140 unsigned long usec_delay_writecycles; /* Min time between write cycles
141 (up to 10ms for some models) */
142 unsigned long usec_delay_step; /* For adaptive algorithm */
143 int adapt_state; /* 1 = To high , 0 = Even, -1 = To low */
145 /* this one is to keep the read/write operations atomic */
146 wait_queue_head_t wait_q;
147 volatile int busy;
148 int retry_cnt_addr; /* Used to keep track of number of retries for
149 adaptive timing adjustments */
150 int retry_cnt_read;
153 static int eeprom_open(struct inode * inode, struct file * file);
154 static loff_t eeprom_lseek(struct file * file, loff_t offset, int orig);
155 static ssize_t eeprom_read(struct file * file, char * buf, size_t count,
156 loff_t *off);
157 static ssize_t eeprom_write(struct file * file, const char * buf, size_t count,
158 loff_t *off);
159 static int eeprom_close(struct inode * inode, struct file * file);
161 static int eeprom_address(unsigned long addr);
162 static int read_from_eeprom(char * buf, int count);
163 static int eeprom_write_buf(loff_t addr, const char * buf, int count);
164 static int eeprom_read_buf(loff_t addr, char * buf, int count);
166 static void eeprom_disable_write_protect(void);
169 static const char eeprom_name[] = "eeprom";
171 /* chip description */
172 static struct eeprom_type eeprom;
174 /* This is the exported file-operations structure for this device. */
175 const struct file_operations eeprom_fops =
177 .llseek = eeprom_lseek,
178 .read = eeprom_read,
179 .write = eeprom_write,
180 .open = eeprom_open,
181 .release = eeprom_close
184 /* eeprom init call. Probes for different eeprom models. */
186 int __init eeprom_init(void)
188 init_waitqueue_head(&eeprom.wait_q);
189 eeprom.busy = 0;
191 #ifdef CONFIG_ETRAX_I2C_EEPROM_PROBE
192 #define EETEXT "Found"
193 #else
194 #define EETEXT "Assuming"
195 #endif
196 if (register_chrdev(EEPROM_MAJOR_NR, eeprom_name, &eeprom_fops))
198 printk(KERN_INFO "%s: unable to get major %d for eeprom device\n",
199 eeprom_name, EEPROM_MAJOR_NR);
200 return -1;
203 printk("EEPROM char device v0.3, (c) 2000 Axis Communications AB\n");
206 * Note: Most of this probing method was taken from the printserver (5470e)
207 * codebase. It did not contain a way of finding the 16kB chips
208 * (M24128 or variants). The method used here might not work
209 * for all models. If you encounter problems the easiest way
210 * is probably to define your model within #ifdef's, and hard-
211 * code it.
214 eeprom.size = 0;
215 eeprom.usec_delay_writecycles = INITIAL_WRITEDELAY_US;
216 eeprom.usec_delay_step = 128;
217 eeprom.adapt_state = 0;
219 #ifdef CONFIG_ETRAX_I2C_EEPROM_PROBE
220 i2c_start();
221 i2c_outbyte(0x80);
222 if(!i2c_getack())
224 /* It's not 8k.. */
225 int success = 0;
226 unsigned char buf_2k_start[16];
228 /* Im not sure this will work... :) */
229 /* assume 2kB, if failure go for 16kB */
230 /* Test with 16kB settings.. */
231 /* If it's a 2kB EEPROM and we address it outside it's range
232 * it will mirror the address space:
233 * 1. We read two locations (that are mirrored),
234 * if the content differs * it's a 16kB EEPROM.
235 * 2. if it doesn't differ - write different value to one of the locations,
236 * check the other - if content still is the same it's a 2k EEPROM,
237 * restore original data.
239 #define LOC1 8
240 #define LOC2 (0x1fb) /*1fb, 3ed, 5df, 7d1 */
242 /* 2k settings */
243 i2c_stop();
244 eeprom.size = EEPROM_2KB;
245 eeprom.select_cmd = 0xA0;
246 eeprom.sequential_write_pagesize = 16;
247 if( eeprom_read_buf( 0, buf_2k_start, 16 ) == 16 )
249 D(printk("2k start: '%16.16s'\n", buf_2k_start));
251 else
253 printk(KERN_INFO "%s: Failed to read in 2k mode!\n", eeprom_name);
256 /* 16k settings */
257 eeprom.size = EEPROM_16KB;
258 eeprom.select_cmd = 0xA0;
259 eeprom.sequential_write_pagesize = 64;
262 unsigned char loc1[4], loc2[4], tmp[4];
263 if( eeprom_read_buf(LOC2, loc2, 4) == 4)
265 if( eeprom_read_buf(LOC1, loc1, 4) == 4)
267 D(printk("0 loc1: (%i) '%4.4s' loc2 (%i) '%4.4s'\n",
268 LOC1, loc1, LOC2, loc2));
269 #if 0
270 if (memcmp(loc1, loc2, 4) != 0 )
272 /* It's 16k */
273 printk(KERN_INFO "%s: 16k detected in step 1\n", eeprom_name);
274 eeprom.size = EEPROM_16KB;
275 success = 1;
277 else
278 #endif
280 /* Do step 2 check */
281 /* Invert value */
282 loc1[0] = ~loc1[0];
283 if (eeprom_write_buf(LOC1, loc1, 1) == 1)
285 /* If 2k EEPROM this write will actually write 10 bytes
286 * from pos 0
288 D(printk("1 loc1: (%i) '%4.4s' loc2 (%i) '%4.4s'\n",
289 LOC1, loc1, LOC2, loc2));
290 if( eeprom_read_buf(LOC1, tmp, 4) == 4)
292 D(printk("2 loc1: (%i) '%4.4s' tmp '%4.4s'\n",
293 LOC1, loc1, tmp));
294 if (memcmp(loc1, tmp, 4) != 0 )
296 printk(KERN_INFO "%s: read and write differs! Not 16kB\n",
297 eeprom_name);
298 loc1[0] = ~loc1[0];
300 if (eeprom_write_buf(LOC1, loc1, 1) == 1)
302 success = 1;
304 else
306 printk(KERN_INFO "%s: Restore 2k failed during probe,"
307 " EEPROM might be corrupt!\n", eeprom_name);
310 i2c_stop();
311 /* Go to 2k mode and write original data */
312 eeprom.size = EEPROM_2KB;
313 eeprom.select_cmd = 0xA0;
314 eeprom.sequential_write_pagesize = 16;
315 if( eeprom_write_buf(0, buf_2k_start, 16) == 16)
318 else
320 printk(KERN_INFO "%s: Failed to write back 2k start!\n",
321 eeprom_name);
324 eeprom.size = EEPROM_2KB;
328 if(!success)
330 if( eeprom_read_buf(LOC2, loc2, 1) == 1)
332 D(printk("0 loc1: (%i) '%4.4s' loc2 (%i) '%4.4s'\n",
333 LOC1, loc1, LOC2, loc2));
334 if (memcmp(loc1, loc2, 4) == 0 )
336 /* Data the same, must be mirrored -> 2k */
337 /* Restore data */
338 printk(KERN_INFO "%s: 2k detected in step 2\n", eeprom_name);
339 loc1[0] = ~loc1[0];
340 if (eeprom_write_buf(LOC1, loc1, 1) == 1)
342 success = 1;
344 else
346 printk(KERN_INFO "%s: Restore 2k failed during probe,"
347 " EEPROM might be corrupt!\n", eeprom_name);
351 eeprom.size = EEPROM_2KB;
353 else
355 printk(KERN_INFO "%s: 16k detected in step 2\n",
356 eeprom_name);
357 loc1[0] = ~loc1[0];
358 /* Data differs, assume 16k */
359 /* Restore data */
360 if (eeprom_write_buf(LOC1, loc1, 1) == 1)
362 success = 1;
364 else
366 printk(KERN_INFO "%s: Restore 16k failed during probe,"
367 " EEPROM might be corrupt!\n", eeprom_name);
370 eeprom.size = EEPROM_16KB;
375 } /* read LOC1 */
376 } /* address LOC1 */
377 if (!success)
379 printk(KERN_INFO "%s: Probing failed!, using 2KB!\n", eeprom_name);
380 eeprom.size = EEPROM_2KB;
382 } /* read */
385 else
387 i2c_outbyte(0x00);
388 if(!i2c_getack())
390 /* No 8k */
391 eeprom.size = EEPROM_2KB;
393 else
395 i2c_start();
396 i2c_outbyte(0x81);
397 if (!i2c_getack())
399 eeprom.size = EEPROM_2KB;
401 else
403 /* It's a 8kB */
404 i2c_inbyte();
405 eeprom.size = EEPROM_8KB;
409 i2c_stop();
410 #elif defined(CONFIG_ETRAX_I2C_EEPROM_16KB)
411 eeprom.size = EEPROM_16KB;
412 #elif defined(CONFIG_ETRAX_I2C_EEPROM_8KB)
413 eeprom.size = EEPROM_8KB;
414 #elif defined(CONFIG_ETRAX_I2C_EEPROM_2KB)
415 eeprom.size = EEPROM_2KB;
416 #endif
418 switch(eeprom.size)
420 case (EEPROM_2KB):
421 printk("%s: " EETEXT " i2c compatible 2kB eeprom.\n", eeprom_name);
422 eeprom.sequential_write_pagesize = 16;
423 eeprom.select_cmd = 0xA0;
424 break;
425 case (EEPROM_8KB):
426 printk("%s: " EETEXT " i2c compatible 8kB eeprom.\n", eeprom_name);
427 eeprom.sequential_write_pagesize = 16;
428 eeprom.select_cmd = 0x80;
429 break;
430 case (EEPROM_16KB):
431 printk("%s: " EETEXT " i2c compatible 16kB eeprom.\n", eeprom_name);
432 eeprom.sequential_write_pagesize = 64;
433 eeprom.select_cmd = 0xA0;
434 break;
435 default:
436 eeprom.size = 0;
437 printk("%s: Did not find a supported eeprom\n", eeprom_name);
438 break;
443 eeprom_disable_write_protect();
445 return 0;
448 /* Opens the device. */
450 static int eeprom_open(struct inode * inode, struct file * file)
453 if(iminor(inode) != EEPROM_MINOR_NR)
454 return -ENXIO;
455 if(imajor(inode) != EEPROM_MAJOR_NR)
456 return -ENXIO;
458 if( eeprom.size > 0 )
460 /* OK */
461 return 0;
464 /* No EEprom found */
465 return -EFAULT;
468 /* Changes the current file position. */
470 static loff_t eeprom_lseek(struct file * file, loff_t offset, int orig)
473 * orig 0: position from begning of eeprom
474 * orig 1: relative from current position
475 * orig 2: position from last eeprom address
478 switch (orig)
480 case 0:
481 file->f_pos = offset;
482 break;
483 case 1:
484 file->f_pos += offset;
485 break;
486 case 2:
487 file->f_pos = eeprom.size - offset;
488 break;
489 default:
490 return -EINVAL;
493 /* truncate position */
494 if (file->f_pos < 0)
496 file->f_pos = 0;
497 return(-EOVERFLOW);
500 if (file->f_pos >= eeprom.size)
502 file->f_pos = eeprom.size - 1;
503 return(-EOVERFLOW);
506 return ( file->f_pos );
509 /* Reads data from eeprom. */
511 static int eeprom_read_buf(loff_t addr, char * buf, int count)
513 struct file f;
515 f.f_pos = addr;
516 return eeprom_read(&f, buf, count, &addr);
521 /* Reads data from eeprom. */
523 static ssize_t eeprom_read(struct file * file, char * buf, size_t count, loff_t *off)
525 int read=0;
526 unsigned long p = file->f_pos;
528 unsigned char page;
530 if(p >= eeprom.size) /* Address i 0 - (size-1) */
532 return -EFAULT;
535 wait_event_interruptible(eeprom.wait_q, !eeprom.busy);
536 if (signal_pending(current))
537 return -EINTR;
539 eeprom.busy++;
541 page = (unsigned char) (p >> 8);
543 if(!eeprom_address(p))
545 printk(KERN_INFO "%s: Read failed to address the eeprom: "
546 "0x%08X (%i) page: %i\n", eeprom_name, (int)p, (int)p, page);
547 i2c_stop();
549 /* don't forget to wake them up */
550 eeprom.busy--;
551 wake_up_interruptible(&eeprom.wait_q);
552 return -EFAULT;
555 if( (p + count) > eeprom.size)
557 /* truncate count */
558 count = eeprom.size - p;
561 /* stop dummy write op and initiate the read op */
562 i2c_start();
564 /* special case for small eeproms */
565 if(eeprom.size < EEPROM_16KB)
567 i2c_outbyte( eeprom.select_cmd | 1 | (page << 1) );
570 /* go on with the actual read */
571 read = read_from_eeprom( buf, count);
573 if(read > 0)
575 file->f_pos += read;
578 eeprom.busy--;
579 wake_up_interruptible(&eeprom.wait_q);
580 return read;
583 /* Writes data to eeprom. */
585 static int eeprom_write_buf(loff_t addr, const char * buf, int count)
587 struct file f;
589 f.f_pos = addr;
591 return eeprom_write(&f, buf, count, &addr);
595 /* Writes data to eeprom. */
597 static ssize_t eeprom_write(struct file * file, const char * buf, size_t count,
598 loff_t *off)
600 int i, written, restart=1;
601 unsigned long p;
603 if (!access_ok(VERIFY_READ, buf, count))
605 return -EFAULT;
608 wait_event_interruptible(eeprom.wait_q, !eeprom.busy);
609 /* bail out if we get interrupted */
610 if (signal_pending(current))
611 return -EINTR;
612 eeprom.busy++;
613 for(i = 0; (i < EEPROM_RETRIES) && (restart > 0); i++)
615 restart = 0;
616 written = 0;
617 p = file->f_pos;
620 while( (written < count) && (p < eeprom.size))
622 /* address the eeprom */
623 if(!eeprom_address(p))
625 printk(KERN_INFO "%s: Write failed to address the eeprom: "
626 "0x%08X (%i) \n", eeprom_name, (int)p, (int)p);
627 i2c_stop();
629 /* don't forget to wake them up */
630 eeprom.busy--;
631 wake_up_interruptible(&eeprom.wait_q);
632 return -EFAULT;
634 #ifdef EEPROM_ADAPTIVE_TIMING
635 /* Adaptive algorithm to adjust timing */
636 if (eeprom.retry_cnt_addr > 0)
638 /* To Low now */
639 D(printk(">D=%i d=%i\n",
640 eeprom.usec_delay_writecycles, eeprom.usec_delay_step));
642 if (eeprom.usec_delay_step < 4)
644 eeprom.usec_delay_step++;
645 eeprom.usec_delay_writecycles += eeprom.usec_delay_step;
647 else
650 if (eeprom.adapt_state > 0)
652 /* To Low before */
653 eeprom.usec_delay_step *= 2;
654 if (eeprom.usec_delay_step > 2)
656 eeprom.usec_delay_step--;
658 eeprom.usec_delay_writecycles += eeprom.usec_delay_step;
660 else if (eeprom.adapt_state < 0)
662 /* To High before (toggle dir) */
663 eeprom.usec_delay_writecycles += eeprom.usec_delay_step;
664 if (eeprom.usec_delay_step > 1)
666 eeprom.usec_delay_step /= 2;
667 eeprom.usec_delay_step--;
672 eeprom.adapt_state = 1;
674 else
676 /* To High (or good) now */
677 D(printk("<D=%i d=%i\n",
678 eeprom.usec_delay_writecycles, eeprom.usec_delay_step));
680 if (eeprom.adapt_state < 0)
682 /* To High before */
683 if (eeprom.usec_delay_step > 1)
685 eeprom.usec_delay_step *= 2;
686 eeprom.usec_delay_step--;
688 if (eeprom.usec_delay_writecycles > eeprom.usec_delay_step)
690 eeprom.usec_delay_writecycles -= eeprom.usec_delay_step;
694 else if (eeprom.adapt_state > 0)
696 /* To Low before (toggle dir) */
697 if (eeprom.usec_delay_writecycles > eeprom.usec_delay_step)
699 eeprom.usec_delay_writecycles -= eeprom.usec_delay_step;
701 if (eeprom.usec_delay_step > 1)
703 eeprom.usec_delay_step /= 2;
704 eeprom.usec_delay_step--;
707 eeprom.adapt_state = -1;
710 if (eeprom.adapt_state > -100)
712 eeprom.adapt_state--;
714 else
716 /* Restart adaption */
717 D(printk("#Restart\n"));
718 eeprom.usec_delay_step++;
721 #endif /* EEPROM_ADAPTIVE_TIMING */
722 /* write until we hit a page boundary or count */
725 i2c_outbyte(buf[written]);
726 if(!i2c_getack())
728 restart=1;
729 printk(KERN_INFO "%s: write error, retrying. %d\n", eeprom_name, i);
730 i2c_stop();
731 break;
733 written++;
734 p++;
735 } while( written < count && ( p % eeprom.sequential_write_pagesize ));
737 /* end write cycle */
738 i2c_stop();
739 i2c_delay(eeprom.usec_delay_writecycles);
740 } /* while */
741 } /* for */
743 eeprom.busy--;
744 wake_up_interruptible(&eeprom.wait_q);
745 if (written == 0 && file->f_pos >= eeprom.size){
746 return -ENOSPC;
748 file->f_pos += written;
749 return written;
752 /* Closes the device. */
754 static int eeprom_close(struct inode * inode, struct file * file)
756 /* do nothing for now */
757 return 0;
760 /* Sets the current address of the eeprom. */
762 static int eeprom_address(unsigned long addr)
764 int i;
765 unsigned char page, offset;
767 page = (unsigned char) (addr >> 8);
768 offset = (unsigned char) addr;
770 for(i = 0; i < EEPROM_RETRIES; i++)
772 /* start a dummy write for addressing */
773 i2c_start();
775 if(eeprom.size == EEPROM_16KB)
777 i2c_outbyte( eeprom.select_cmd );
778 i2c_getack();
779 i2c_outbyte(page);
781 else
783 i2c_outbyte( eeprom.select_cmd | (page << 1) );
785 if(!i2c_getack())
787 /* retry */
788 i2c_stop();
789 /* Must have a delay here.. 500 works, >50, 100->works 5th time*/
790 i2c_delay(MAX_WRITEDELAY_US / EEPROM_RETRIES * i);
791 /* The chip needs up to 10 ms from write stop to next start */
794 else
796 i2c_outbyte(offset);
798 if(!i2c_getack())
800 /* retry */
801 i2c_stop();
803 else
804 break;
809 eeprom.retry_cnt_addr = i;
810 D(printk("%i\n", eeprom.retry_cnt_addr));
811 if(eeprom.retry_cnt_addr == EEPROM_RETRIES)
813 /* failed */
814 return 0;
816 return 1;
819 /* Reads from current address. */
821 static int read_from_eeprom(char * buf, int count)
823 int i, read=0;
825 for(i = 0; i < EEPROM_RETRIES; i++)
827 if(eeprom.size == EEPROM_16KB)
829 i2c_outbyte( eeprom.select_cmd | 1 );
832 if(i2c_getack())
834 break;
838 if(i == EEPROM_RETRIES)
840 printk(KERN_INFO "%s: failed to read from eeprom\n", eeprom_name);
841 i2c_stop();
843 return -EFAULT;
846 while( (read < count))
848 if (put_user(i2c_inbyte(), &buf[read++]))
850 i2c_stop();
852 return -EFAULT;
856 * make sure we don't ack last byte or you will get very strange
857 * results!
859 if(read < count)
861 i2c_sendack();
865 /* stop the operation */
866 i2c_stop();
868 return read;
871 /* Disables write protection if applicable. */
873 #define DBP_SAVE(x)
874 #define ax_printf printk
875 static void eeprom_disable_write_protect(void)
877 /* Disable write protect */
878 if (eeprom.size == EEPROM_8KB)
880 /* Step 1 Set WEL = 1 (write 00000010 to address 1FFFh */
881 i2c_start();
882 i2c_outbyte(0xbe);
883 if(!i2c_getack())
885 DBP_SAVE(ax_printf("Get ack returns false\n"));
887 i2c_outbyte(0xFF);
888 if(!i2c_getack())
890 DBP_SAVE(ax_printf("Get ack returns false 2\n"));
892 i2c_outbyte(0x02);
893 if(!i2c_getack())
895 DBP_SAVE(ax_printf("Get ack returns false 3\n"));
897 i2c_stop();
899 i2c_delay(1000);
901 /* Step 2 Set RWEL = 1 (write 00000110 to address 1FFFh */
902 i2c_start();
903 i2c_outbyte(0xbe);
904 if(!i2c_getack())
906 DBP_SAVE(ax_printf("Get ack returns false 55\n"));
908 i2c_outbyte(0xFF);
909 if(!i2c_getack())
911 DBP_SAVE(ax_printf("Get ack returns false 52\n"));
913 i2c_outbyte(0x06);
914 if(!i2c_getack())
916 DBP_SAVE(ax_printf("Get ack returns false 53\n"));
918 i2c_stop();
920 /* Step 3 Set BP1, BP0, and/or WPEN bits (write 00000110 to address 1FFFh */
921 i2c_start();
922 i2c_outbyte(0xbe);
923 if(!i2c_getack())
925 DBP_SAVE(ax_printf("Get ack returns false 56\n"));
927 i2c_outbyte(0xFF);
928 if(!i2c_getack())
930 DBP_SAVE(ax_printf("Get ack returns false 57\n"));
932 i2c_outbyte(0x06);
933 if(!i2c_getack())
935 DBP_SAVE(ax_printf("Get ack returns false 58\n"));
937 i2c_stop();
939 /* Write protect disabled */
943 module_init(eeprom_init);