blob: 965f731b8c317d4591264af617c58e9b0a4f04c2 [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
Ollie Lho761bf1b2004-03-20 16:46:10 +00006extern int probe_m29f400bt(struct flashchip *flash);
7extern int erase_m29f400bt(struct flashchip *flash);
Uwe Hermanna7e05482007-05-09 10:17:44 +00008extern int block_erase_m29f400bt(volatile uint8_t *bios,
9 volatile uint8_t *dst);
Ollie Lho184a4042005-11-26 21:55:36 +000010extern int write_m29f400bt(struct flashchip *flash, uint8_t *buf);
Uwe Hermanna7e05482007-05-09 10:17:44 +000011extern int write_linuxbios_m29f400bt(struct flashchip *flash, uint8_t *buf);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000012
Ollie Lho184a4042005-11-26 21:55:36 +000013extern __inline__ void toggle_ready_m29f400bt(volatile uint8_t *dst)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000014{
15 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000016 uint8_t tmp1, tmp2;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000017
18 tmp1 = *dst & 0x40;
19
20 while (i++ < 0xFFFFFF) {
21 tmp2 = *dst & 0x40;
22 if (tmp1 == tmp2) {
23 break;
24 }
25 tmp1 = tmp2;
26 }
27}
28
Ollie Lho184a4042005-11-26 21:55:36 +000029extern __inline__ void data_polling_m29f400bt(volatile uint8_t *dst,
30 uint8_t data)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000031{
32 unsigned int i = 0;
Ollie Lho184a4042005-11-26 21:55:36 +000033 uint8_t tmp;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000034
35 data &= 0x80;
36
37 while (i++ < 0xFFFFFF) {
38 tmp = *dst & 0x80;
39 if (tmp == data) {
40 break;
41 }
42 }
43}
44
Ollie Lho184a4042005-11-26 21:55:36 +000045extern __inline__ void protect_m29f400bt(volatile uint8_t *bios)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000046{
Uwe Hermanna7e05482007-05-09 10:17:44 +000047 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
48 *(volatile uint8_t *)(bios + 0x555) = 0x55;
49 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000050
51 usleep(200);
52}
53
Uwe Hermanna7e05482007-05-09 10:17:44 +000054extern __inline__ void write_page_m29f400bt(volatile uint8_t *bios,
55 uint8_t *src,
Ollie Lho184a4042005-11-26 21:55:36 +000056 volatile uint8_t *dst,
Ollie Lho761bf1b2004-03-20 16:46:10 +000057 int page_size)
Ronald G. Minnichb1934902002-06-11 19:15:55 +000058{
59 int i;
Ollie Lho761bf1b2004-03-20 16:46:10 +000060
Ronald G. Minnichb1934902002-06-11 19:15:55 +000061 for (i = 0; i < page_size; i++) {
Uwe Hermanna7e05482007-05-09 10:17:44 +000062 *(volatile uint8_t *)(bios + 0xAAA) = 0xAA;
63 *(volatile uint8_t *)(bios + 0x555) = 0x55;
64 *(volatile uint8_t *)(bios + 0xAAA) = 0xA0;
Ronald G. Minnichb1934902002-06-11 19:15:55 +000065
66 /* transfer data from source to destination */
67 *dst = *src;
68 //*(volatile char *) (bios) = 0xF0;
69 //usleep(5);
70 toggle_ready_m29f400bt(dst);
Ollie Lho761bf1b2004-03-20 16:46:10 +000071 printf
72 ("Value in the flash at address %p = %#x, want %#x\n",
Ollie Lho184a4042005-11-26 21:55:36 +000073 (uint8_t *) (dst - bios), *dst, *src);
Ronald G. Minnichb1934902002-06-11 19:15:55 +000074 dst++;
75 src++;
76 }
77
78}
Ronald G. Minnicheaab50b2003-09-12 22:41:53 +000079
Ollie Lho761bf1b2004-03-20 16:46:10 +000080#endif /* !__M29F400BT_H__ */