Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 1 | #ifndef __JEDEC_H__ |
| 2 | #define __JEDEC_H__ 1 |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 3 | int write_byte_program_jedec(volatile uint8_t *bios, uint8_t *src, |
| 4 | volatile uint8_t *dst); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 5 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 6 | extern int probe_jedec(struct flashchip *flash); |
| 7 | extern int erase_chip_jedec(struct flashchip *flash); |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 8 | extern int write_jedec(struct flashchip *flash, uint8_t *buf); |
| 9 | extern int erase_sector_jedec(volatile uint8_t *bios, unsigned int page); |
| 10 | extern int erase_block_jedec(volatile uint8_t *bios, unsigned int page); |
| 11 | extern int write_sector_jedec(volatile uint8_t *bios, uint8_t *src, |
| 12 | volatile uint8_t *dst, |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 13 | unsigned int page_size); |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 14 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 15 | extern __inline__ void toggle_ready_jedec(volatile uint8_t *dst) |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 16 | { |
| 17 | unsigned int i = 0; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 18 | uint8_t tmp1, tmp2; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 19 | |
| 20 | tmp1 = *dst & 0x40; |
| 21 | |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 22 | while (i++ < 0xFFFFFFF) { |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 23 | tmp2 = *dst & 0x40; |
| 24 | if (tmp1 == tmp2) { |
| 25 | break; |
| 26 | } |
| 27 | tmp1 = tmp2; |
| 28 | } |
| 29 | } |
| 30 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 31 | extern __inline__ void data_polling_jedec(volatile uint8_t *dst, uint8_t data) |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 32 | { |
| 33 | unsigned int i = 0; |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 34 | uint8_t tmp; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 35 | |
| 36 | data &= 0x80; |
| 37 | |
Ollie Lho | 8b8897a | 2004-03-27 00:18:15 +0000 | [diff] [blame] | 38 | while (i++ < 0xFFFFFFF) { |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 39 | tmp = *dst & 0x80; |
| 40 | if (tmp == data) { |
| 41 | break; |
| 42 | } |
| 43 | } |
| 44 | } |
| 45 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 46 | extern __inline__ void unprotect_jedec(volatile uint8_t *bios) |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 47 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 48 | *(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 Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 54 | |
| 55 | usleep(200); |
| 56 | } |
| 57 | |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 58 | extern __inline__ void protect_jedec(volatile uint8_t *bios) |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 59 | { |
Ollie Lho | 184a404 | 2005-11-26 21:55:36 +0000 | [diff] [blame] | 60 | *(volatile uint8_t *) (bios + 0x5555) = 0xAA; |
| 61 | *(volatile uint8_t *) (bios + 0x2AAA) = 0x55; |
| 62 | *(volatile uint8_t *) (bios + 0x5555) = 0xA0; |
Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame] | 63 | |
| 64 | usleep(200); |
| 65 | } |
| 66 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame] | 67 | #endif /* !__JEDEC_H__ */ |