1751b296defffcf6a5d8de96e628f57b44095a0a
[coreboot.git] / util / flash_and_burn / jedec.h
1 #ifndef __JEDEC_H__
2 #define __JEDEC_H__ 1
3
4 extern int probe_jedec(struct flashchip *flash);
5 extern int erase_chip_jedec(struct flashchip *flash);
6 extern int write_jedec(struct flashchip *flash, unsigned char *buf);
7 extern int erase_sector_jedec(volatile char *bios, unsigned int page);
8 extern int write_sector_jedec(volatile char *bios,
9                               unsigned char *src,
10                               volatile unsigned char *dst,
11                               unsigned int page_size);
12
13 extern __inline__ void toggle_ready_jedec(volatile char *dst)
14 {
15         unsigned int i = 0;
16         char tmp1, tmp2;
17
18         tmp1 = *dst & 0x40;
19
20         while (i++ < 0xFFFFFF) {
21                 tmp2 = *dst & 0x40;
22                 if (tmp1 == tmp2) {
23                         break;
24                 }
25                 tmp1 = tmp2;
26         }
27 }
28
29 extern __inline__ void data_polling_jedec(volatile char *dst, char data)
30 {
31         unsigned int i = 0;
32         char tmp;
33
34         data &= 0x80;
35
36         while (i++ < 0xFFFFFF) {
37                 tmp = *dst & 0x80;
38                 if (tmp == data) {
39                         break;
40                 }
41         }
42 }
43
44 extern __inline__ void unprotect_jedec(volatile char *bios)
45 {
46         *(volatile char *) (bios + 0x5555) = 0xAA;
47         *(volatile char *) (bios + 0x2AAA) = 0x55;
48         *(volatile char *) (bios + 0x5555) = 0x80;
49         *(volatile char *) (bios + 0x5555) = 0xAA;
50         *(volatile char *) (bios + 0x2AAA) = 0x55;
51         *(volatile char *) (bios + 0x5555) = 0x20;
52
53         usleep(200);
54 }
55
56 extern __inline__ void protect_jedec(volatile char *bios)
57 {
58         *(volatile char *) (bios + 0x5555) = 0xAA;
59         *(volatile char *) (bios + 0x2AAA) = 0x55;
60         *(volatile char *) (bios + 0x5555) = 0xA0;
61
62         usleep(200);
63 }
64
65 #endif                          /* !__JEDEC_H__ */