Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 1 | #ifndef __M29F400BT_H__ |
| 2 | #define __M29F400BT_H__ 1 |
| 3 | |
| 4 | #include <stdio.h> |
| 5 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 6 | extern int probe_m29f400bt (struct flashchip * flash); |
| 7 | extern int erase_m29f400bt (struct flashchip * flash); |
| 8 | extern int block_erase_m29f400bt (volatile char * bios, volatile char * dst); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 9 | extern int write_m29f400bt (struct flashchip * flash, unsigned char * buf); |
| 10 | extern int write_linuxbios_m29f400bt (struct flashchip * flash, unsigned char * buf); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 11 | |
| 12 | extern __inline__ void toggle_ready_m29f400bt (volatile char * dst) |
| 13 | { |
| 14 | unsigned int i = 0; |
| 15 | char tmp1, tmp2; |
| 16 | |
| 17 | tmp1 = *dst & 0x40; |
| 18 | |
| 19 | while (i++ < 0xFFFFFF) { |
| 20 | tmp2 = *dst & 0x40; |
| 21 | if (tmp1 == tmp2) { |
| 22 | break; |
| 23 | } |
| 24 | tmp1 = tmp2; |
| 25 | } |
| 26 | } |
| 27 | |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 28 | extern __inline__ void data_polling_m29f400bt (volatile char * dst, unsigned char data) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 29 | { |
| 30 | unsigned int i = 0; |
| 31 | char tmp; |
| 32 | |
| 33 | data &= 0x80; |
| 34 | |
| 35 | while (i++ < 0xFFFFFF) { |
| 36 | tmp = *dst & 0x80; |
| 37 | if (tmp == data) { |
| 38 | break; |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | extern __inline__ void protect_m29f400bt (volatile char * bios) |
| 44 | { |
| 45 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 46 | *(volatile char *) (bios + 0x555) = 0x55; |
| 47 | *(volatile char *) (bios + 0xAAA) = 0xA0; |
| 48 | |
| 49 | usleep(200); |
| 50 | } |
| 51 | |
| 52 | extern __inline__ void write_page_m29f400bt (volatile char * bios, char * src, volatile char * dst, |
| 53 | int page_size) |
| 54 | { |
| 55 | int i; |
| 56 | |
| 57 | for (i = 0; i < page_size; i++) { |
| 58 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 59 | *(volatile char *) (bios + 0x555) = 0x55; |
| 60 | *(volatile char *) (bios + 0xAAA) = 0xA0; |
| 61 | |
| 62 | /* transfer data from source to destination */ |
| 63 | *dst = *src; |
| 64 | //*(volatile char *) (bios) = 0xF0; |
| 65 | //usleep(5); |
| 66 | toggle_ready_m29f400bt(dst); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 67 | printf("Value in the flash at address %p = %#x, want %#x\n",(char *)(dst-bios), *dst, *src); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 68 | dst++; |
| 69 | src++; |
| 70 | } |
| 71 | |
| 72 | } |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 73 | |
| 74 | #endif /* !__M29F400BT_H__ */ |