Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 1 | /* |
| 2 | * m29f400bt.c: driver for programming JEDEC standard flash parts |
| 3 | * |
| 4 | * |
| 5 | * Copyright 2000 Silicon Integrated System Corporation |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * |
| 22 | * Reference: |
| 23 | * |
| 24 | * $Id$ |
| 25 | */ |
| 26 | |
| 27 | #include "flash.h" |
| 28 | #include "m29f400bt.h" |
| 29 | |
| 30 | int probe_m29f400bt (struct flashchip * flash) |
| 31 | { |
| 32 | volatile char * bios = flash->virt_addr; |
| 33 | unsigned char id1, id2; |
| 34 | |
| 35 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 36 | *(volatile char *) (bios + 0x555) = 0x55; |
| 37 | *(volatile char *) (bios + 0xAAA) = 0x90; |
| 38 | |
| 39 | myusec_delay(10); |
| 40 | |
| 41 | id1 = *(volatile unsigned char *) bios; |
| 42 | id2 = *(volatile unsigned char *) (bios + 0x02); |
| 43 | |
| 44 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 45 | *(volatile char *) (bios + 0x555) = 0x55; |
| 46 | *(volatile char *) (bios + 0xAAA) = 0xF0; |
| 47 | |
| 48 | myusec_delay(10); |
| 49 | |
| 50 | printf(__FUNCTION__ " id1 %x, id2 %x\n", id1, id2); |
| 51 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 52 | return 1; |
| 53 | |
| 54 | return 0; |
| 55 | } |
| 56 | |
| 57 | int erase_m29f400bt (struct flashchip * flash) |
| 58 | { |
| 59 | volatile char * bios = flash->virt_addr; |
| 60 | |
| 61 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 62 | *(volatile char *) (bios + 0x555) = 0x55; |
| 63 | *(volatile char *) (bios + 0xAAA) = 0x80; |
| 64 | |
| 65 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 66 | *(volatile char *) (bios + 0x555) = 0x55; |
| 67 | *(volatile char *) (bios + 0xAAA) = 0x10; |
| 68 | |
| 69 | myusec_delay(10); |
| 70 | toggle_ready_m29f400bt(bios); |
| 71 | } |
| 72 | |
| 73 | int block_erase_m29f400bt (volatile char * bios ,volatile char * dst) |
| 74 | { |
| 75 | |
| 76 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 77 | *(volatile char *) (bios + 0x555) = 0x55; |
| 78 | *(volatile char *) (bios + 0xAAA) = 0x80; |
| 79 | |
| 80 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 81 | *(volatile char *) (bios + 0x555) = 0x55; |
| 82 | //*(volatile char *) (bios + 0xAAA) = 0x10; |
| 83 | *dst = 0x30; |
| 84 | |
| 85 | myusec_delay(10); |
| 86 | toggle_ready_m29f400bt(bios); |
| 87 | } |
| 88 | |
| 89 | int write_m29f400bt (struct flashchip * flash, char * buf) |
| 90 | { |
| 91 | int i; |
| 92 | int total_size = flash->total_size *1024, page_size = flash->page_size; |
| 93 | volatile char * bios = flash->virt_addr; |
| 94 | |
| 95 | //erase_m29f400bt (flash); |
| 96 | printf ("Programming Page:\n "); |
| 97 | /********************************* |
| 98 | *Pages for M29F400BT: |
| 99 | * 16 0x7c000 0x7ffff TOP |
| 100 | * 8 0x7a000 0x7bfff |
| 101 | * 8 0x78000 0x79fff |
| 102 | * 32 0x70000 0x77fff |
| 103 | * 64 0x60000 0x6ffff |
| 104 | * 64 0x50000 0x5ffff |
| 105 | * 64 0x40000 0x4ffff |
| 106 | *--------------------------------- |
| 107 | * 64 0x30000 0x3ffff |
| 108 | * 64 0x20000 0x2ffff |
| 109 | * 64 0x10000 0x1ffff |
| 110 | * 64 0x00000 0x0ffff BOTTOM |
| 111 | *********************************/ |
| 112 | printf("total_size/page_size = %d\n",total_size/page_size); |
| 113 | for (i = 0; i < (total_size/page_size)-1; i++) { |
| 114 | printf("%04d at address: 0x%08x\n", i, i * page_size); |
| 115 | block_erase_m29f400bt(bios, bios + i * page_size); |
| 116 | write_page_m29f400bt(bios, buf + i * page_size, bios + i * page_size, |
| 117 | page_size); |
| 118 | printf ("\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b"); |
| 119 | } |
| 120 | |
| 121 | printf("%04d at address: 0x%08x\n",7,0x70000); |
| 122 | block_erase_m29f400bt(bios , bios + 0x70000); |
| 123 | write_page_m29f400bt(bios,buf + 0x70000, bios + 0x70000, 32*1024); |
| 124 | |
| 125 | printf("%04d at address: 0x%08x\n",8,0x78000); |
| 126 | block_erase_m29f400bt(bios , bios + 0x78000); |
| 127 | write_page_m29f400bt(bios,buf + 0x78000, bios + 0x78000, 8*1024); |
| 128 | |
| 129 | printf("%04d at address: 0x%08x\n",9,0x7a000); |
| 130 | block_erase_m29f400bt(bios , bios + 0x7a000); |
| 131 | write_page_m29f400bt(bios,buf + 0x7a000, bios + 0x7a000, 8*1024); |
| 132 | |
| 133 | printf("%04d at address: 0x%08x\n",10,0x7c000); |
| 134 | block_erase_m29f400bt(bios , bios + 0x7c000); |
| 135 | write_page_m29f400bt(bios,buf + 0x7c000, bios + 0x7c000, 16*1024); |
| 136 | |
| 137 | printf("\n"); |
| 138 | //protect_m29f400bt (bios); |
| 139 | } |
| 140 | |
| 141 | int write_linuxbios_m29f400bt (struct flashchip * flash, char * buf) |
| 142 | { |
| 143 | int i; |
| 144 | volatile char * bios = flash->virt_addr; |
| 145 | |
| 146 | printf ("Programming Page:\n "); |
| 147 | /********************************* |
| 148 | *Pages for M29F400BT: |
| 149 | * 16 0x7c000 0x7ffff TOP |
| 150 | * 8 0x7a000 0x7bfff |
| 151 | * 8 0x78000 0x79fff |
| 152 | * 32 0x70000 0x77fff |
| 153 | * 64 0x60000 0x6ffff |
| 154 | * 64 0x50000 0x5ffff |
| 155 | * 64 0x40000 0x4ffff |
| 156 | *--------------------------------- |
| 157 | * 64 0x30000 0x3ffff |
| 158 | * 64 0x20000 0x2ffff |
| 159 | * 64 0x10000 0x1ffff |
| 160 | * 64 0x00000 0x0ffff BOTTOM |
| 161 | *********************************/ |
| 162 | printf("%04d at address: 0x%08x\n",7,0x00000); |
| 163 | block_erase_m29f400bt(bios , bios + 0x00000); |
| 164 | write_page_m29f400bt(bios,buf + 0x00000, bios + 0x00000, 64*1024); |
| 165 | |
| 166 | printf("%04d at address: 0x%08x\n",7,0x10000); |
| 167 | block_erase_m29f400bt(bios , bios + 0x10000); |
| 168 | write_page_m29f400bt(bios,buf + 0x10000, bios + 0x10000, 64*1024); |
| 169 | |
| 170 | printf("%04d at address: 0x%08x\n",7,0x20000); |
| 171 | block_erase_m29f400bt(bios , bios + 0x20000); |
| 172 | write_page_m29f400bt(bios,buf + 0x20000, bios + 0x20000, 64*1024); |
| 173 | |
| 174 | printf("%04d at address: 0x%08x\n",7,0x30000); |
| 175 | block_erase_m29f400bt(bios , bios + 0x30000); |
| 176 | write_page_m29f400bt(bios,buf + 0x30000, bios + 0x30000, 64*1024); |
| 177 | |
| 178 | printf("\n"); |
| 179 | //protect_m29f400bt (bios); |
| 180 | } |