blob: 756605e0b5aa0a016505b17a901edcf5aa2e9c28 [file] [log] [blame]
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00001#ifndef __JEDEC_H__
2#define __JEDEC_H__ 1
3
Ollie Lho761bf1b2004-03-20 16:46:10 +00004extern int probe_jedec(struct flashchip *flash);
5extern int erase_chip_jedec(struct flashchip *flash);
6extern int write_jedec(struct flashchip *flash, unsigned char *buf);
Ollie Lhoafdfce82004-03-27 00:31:03 +00007extern int erase_sector_jedec(volatile unsigned char *bios, unsigned int page);
8extern int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
Ollie Lho761bf1b2004-03-20 16:46:10 +00009 volatile unsigned char *dst,
10 unsigned int page_size);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000011
Ollie Lho761bf1b2004-03-20 16:46:10 +000012extern __inline__ void toggle_ready_jedec(volatile char *dst)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000013{
14 unsigned int i = 0;
15 char tmp1, tmp2;
16
17 tmp1 = *dst & 0x40;
18
Ollie Lho8b8897a2004-03-27 00:18:15 +000019 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000020 tmp2 = *dst & 0x40;
21 if (tmp1 == tmp2) {
22 break;
23 }
24 tmp1 = tmp2;
25 }
26}
27
Ollie Lho761bf1b2004-03-20 16:46:10 +000028extern __inline__ void data_polling_jedec(volatile char *dst, char data)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000029{
30 unsigned int i = 0;
31 char tmp;
32
33 data &= 0x80;
34
Ollie Lho8b8897a2004-03-27 00:18:15 +000035 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000036 tmp = *dst & 0x80;
37 if (tmp == data) {
38 break;
39 }
40 }
41}
42
Ollie Lho761bf1b2004-03-20 16:46:10 +000043extern __inline__ void unprotect_jedec(volatile char *bios)
44{
45 *(volatile char *) (bios + 0x5555) = 0xAA;
46 *(volatile char *) (bios + 0x2AAA) = 0x55;
47 *(volatile char *) (bios + 0x5555) = 0x80;
48 *(volatile char *) (bios + 0x5555) = 0xAA;
49 *(volatile char *) (bios + 0x2AAA) = 0x55;
50 *(volatile char *) (bios + 0x5555) = 0x20;
51
52 usleep(200);
53}
54
55extern __inline__ void protect_jedec(volatile char *bios)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000056{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000057 *(volatile char *) (bios + 0x5555) = 0xAA;
58 *(volatile char *) (bios + 0x2AAA) = 0x55;
59 *(volatile char *) (bios + 0x5555) = 0xA0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000060
61 usleep(200);
62}
63
Ollie Lho761bf1b2004-03-20 16:46:10 +000064#endif /* !__JEDEC_H__ */