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