blob: 2a9f97771143d9d4521cf3f9412e340f08931450 [file] [log] [blame]
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00001#ifndef __JEDEC_H__
2#define __JEDEC_H__ 1
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +00003int write_byte_program_jedec(volatile unsigned char *bios, unsigned char *src,
4 volatile unsigned char *dst);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00005
Ollie Lho761bf1b2004-03-20 16:46:10 +00006extern int probe_jedec(struct flashchip *flash);
7extern int erase_chip_jedec(struct flashchip *flash);
8extern int write_jedec(struct flashchip *flash, unsigned char *buf);
Ollie Lhoafdfce82004-03-27 00:31:03 +00009extern int erase_sector_jedec(volatile unsigned char *bios, unsigned int page);
Ronald G. Minnich1f4d6532004-09-30 16:37:01 +000010extern int erase_block_jedec(volatile unsigned char *bios, unsigned int page);
Ollie Lhoafdfce82004-03-27 00:31:03 +000011extern int write_sector_jedec(volatile unsigned char *bios, unsigned char *src,
Ollie Lho761bf1b2004-03-20 16:46:10 +000012 volatile unsigned char *dst,
13 unsigned int page_size);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000014
Ollie Lho761bf1b2004-03-20 16:46:10 +000015extern __inline__ void toggle_ready_jedec(volatile char *dst)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000016{
17 unsigned int i = 0;
18 char tmp1, tmp2;
19
20 tmp1 = *dst & 0x40;
21
Ollie Lho8b8897a2004-03-27 00:18:15 +000022 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000023 tmp2 = *dst & 0x40;
24 if (tmp1 == tmp2) {
25 break;
26 }
27 tmp1 = tmp2;
28 }
29}
30
Ollie Lho761bf1b2004-03-20 16:46:10 +000031extern __inline__ void data_polling_jedec(volatile char *dst, char data)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000032{
33 unsigned int i = 0;
34 char tmp;
35
36 data &= 0x80;
37
Ollie Lho8b8897a2004-03-27 00:18:15 +000038 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000039 tmp = *dst & 0x80;
40 if (tmp == data) {
41 break;
42 }
43 }
44}
45
Ollie Lho761bf1b2004-03-20 16:46:10 +000046extern __inline__ void unprotect_jedec(volatile char *bios)
47{
48 *(volatile char *) (bios + 0x5555) = 0xAA;
49 *(volatile char *) (bios + 0x2AAA) = 0x55;
50 *(volatile char *) (bios + 0x5555) = 0x80;
51 *(volatile char *) (bios + 0x5555) = 0xAA;
52 *(volatile char *) (bios + 0x2AAA) = 0x55;
53 *(volatile char *) (bios + 0x5555) = 0x20;
54
55 usleep(200);
56}
57
58extern __inline__ void protect_jedec(volatile char *bios)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000059{
Ronald G. Minnichef5779d2002-01-29 20:18:02 +000060 *(volatile char *) (bios + 0x5555) = 0xAA;
61 *(volatile char *) (bios + 0x2AAA) = 0x55;
62 *(volatile char *) (bios + 0x5555) = 0xA0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000063
64 usleep(200);
65}
66
Ollie Lho761bf1b2004-03-20 16:46:10 +000067#endif /* !__JEDEC_H__ */