blob: c5c5c645d9b862ae5500b63d90fb39e46d3961d3 [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,
Uwe Hermann0b7afe62007-04-01 19:44:21 +000012 volatile uint8_t *dst, unsigned int page_size);
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000013
Ollie Lho184a4042005-11-26 21:55:36 +000014extern __inline__ void toggle_ready_jedec(volatile uint8_t *dst)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000015{
16 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000017 uint8_t tmp1, tmp2;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000018
19 tmp1 = *dst & 0x40;
20
Ollie Lho8b8897a2004-03-27 00:18:15 +000021 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000022 tmp2 = *dst & 0x40;
23 if (tmp1 == tmp2) {
24 break;
25 }
26 tmp1 = tmp2;
27 }
28}
29
Ollie Lho184a4042005-11-26 21:55:36 +000030extern __inline__ void data_polling_jedec(volatile uint8_t *dst, uint8_t data)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000031{
32 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000033 uint8_t tmp;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000034
35 data &= 0x80;
36
Ollie Lho8b8897a2004-03-27 00:18:15 +000037 while (i++ < 0xFFFFFFF) {
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000038 tmp = *dst & 0x80;
39 if (tmp == data) {
40 break;
41 }
42 }
43}
44
Ollie Lho184a4042005-11-26 21:55:36 +000045extern __inline__ void unprotect_jedec(volatile uint8_t *bios)
Ollie Lho761bf1b2004-03-20 16:46:10 +000046{
Uwe Hermann0b7afe62007-04-01 19:44:21 +000047 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
48 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
49 *(volatile uint8_t *)(bios + 0x5555) = 0x80;
50 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
51 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
52 *(volatile uint8_t *)(bios + 0x5555) = 0x20;
Ollie Lho761bf1b2004-03-20 16:46:10 +000053
54 usleep(200);
55}
56
Ollie Lho184a4042005-11-26 21:55:36 +000057extern __inline__ void protect_jedec(volatile uint8_t *bios)
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000058{
Uwe Hermann0b7afe62007-04-01 19:44:21 +000059 *(volatile uint8_t *)(bios + 0x5555) = 0xAA;
60 *(volatile uint8_t *)(bios + 0x2AAA) = 0x55;
61 *(volatile uint8_t *)(bios + 0x5555) = 0xA0;
Ronald G. Minnich5e5f75e2002-01-29 18:21:41 +000062
63 usleep(200);
64}
65
Ollie Lho761bf1b2004-03-20 16:46:10 +000066#endif /* !__JEDEC_H__ */