blob: 210f9f9ecf2392e3cdd3e7d7570084045f284b0e [file] [log] [blame]
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00001#ifndef __JEDEC_H__
2#define __JEDEC_H__ 1
Ollie Lho184a4042005-11-26 21:55:36 +00003int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src,
4 volatile uint8_t *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);
Ollie Lho184a4042005-11-26 21:55:36 +00008extern int write_jedec(struct flashchip *flash, uint8_t *buf);
9extern int erase_sector_jedec(volatile uint8_t *bios, unsigned int page);
10extern int erase_block_jedec(volatile uint8_t *bios, unsigned int page);
11extern int write_sector_jedec(volatile uint8_t *bios, uint8_t *src,
12 volatile uint8_t *dst,
Ollie Lho761bf1b2004-03-20 16:46:10 +000013 unsigned int page_size);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000014
Ollie Lho184a4042005-11-26 21:55:36 +000015extern __inline__ void toggle_ready_jedec(volatile uint8_t *dst)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000016{
17 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000018 uint8_t tmp1, tmp2;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000019
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 Lho184a4042005-11-26 21:55:36 +000031extern __inline__ void data_polling_jedec(volatile uint8_t *dst, uint8_t data)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000032{
33 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000034 uint8_t tmp;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000035
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 Lho184a4042005-11-26 21:55:36 +000046extern __inline__ void unprotect_jedec(volatile uint8_t *bios)
Ollie Lho761bf1b2004-03-20 16:46:10 +000047{
Ollie Lho184a4042005-11-26 21:55:36 +000048 *(volatile uint8_t *) (bios + 0x5555) = 0xAA;
49 *(volatile uint8_t *) (bios + 0x2AAA) = 0x55;
50 *(volatile uint8_t *) (bios + 0x5555) = 0x80;
51 *(volatile uint8_t *) (bios + 0x5555) = 0xAA;
52 *(volatile uint8_t *) (bios + 0x2AAA) = 0x55;
53 *(volatile uint8_t *) (bios + 0x5555) = 0x20;
Ollie Lho761bf1b2004-03-20 16:46:10 +000054
55 usleep(200);
56}
57
Ollie Lho184a4042005-11-26 21:55:36 +000058extern __inline__ void protect_jedec(volatile uint8_t *bios)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000059{
Ollie Lho184a4042005-11-26 21:55:36 +000060 *(volatile uint8_t *) (bios + 0x5555) = 0xAA;
61 *(volatile uint8_t *) (bios + 0x2AAA) = 0x55;
62 *(volatile uint8_t *) (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__ */