blob: 3d1799f4e2ffe6d7aa912768651ad4e49b82cdf4 [file] [log] [blame]
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00001#ifndef __M29F400BT_H__
2#define __M29F400BT_H__ 1
3
4#include <stdio.h>
5
Ronald G. Minnichb1934902002-06-11 19:15:55 +00006extern int probe_m29f400bt (struct flashchip * flash);
7extern int erase_m29f400bt (struct flashchip * flash);
8extern int block_erase_m29f400bt (volatile char * bios, volatile char * dst);
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +00009extern int write_m29f400bt (struct flashchip * flash, unsigned char * buf);
10extern int write_linuxbios_m29f400bt (struct flashchip * flash, unsigned char * buf);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000011
12extern __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. Minnicheaab50b2003-09-12 22:41:53 +000028extern __inline__ void data_polling_m29f400bt (volatile char * dst, unsigned char data)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000029{
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
43extern __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
52extern __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. Minnicheaab50b2003-09-12 22:41:53 +000067 printf("Value in the flash at address %p = %#x, want %#x\n",(char *)(dst-bios), *dst, *src);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000068 dst++;
69 src++;
70 }
71
72}
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000073
74#endif /* !__M29F400BT_H__ */