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 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 30 | int probe_m29f400bt(struct flashchip *flash) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 31 | { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 32 | volatile char *bios = flash->virt_addr; |
| 33 | unsigned char id1, id2; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 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); |
Ronald G. Minnich | d4228fd | 2003-02-28 17:21:38 +0000 | [diff] [blame] | 49 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 50 | printf("%s: id1 0x%x, id2 0x%x\n", __FUNCTION__, id1, id2); |
Ronald G. Minnich | d4228fd | 2003-02-28 17:21:38 +0000 | [diff] [blame] | 51 | |
| 52 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 53 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 54 | return 1; |
| 55 | |
| 56 | return 0; |
| 57 | } |
| 58 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 59 | int erase_m29f400bt(struct flashchip *flash) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 60 | { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 61 | volatile char *bios = flash->virt_addr; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 62 | |
| 63 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 64 | *(volatile char *) (bios + 0x555) = 0x55; |
| 65 | *(volatile char *) (bios + 0xAAA) = 0x80; |
| 66 | |
| 67 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 68 | *(volatile char *) (bios + 0x555) = 0x55; |
| 69 | *(volatile char *) (bios + 0xAAA) = 0x10; |
| 70 | |
| 71 | myusec_delay(10); |
| 72 | toggle_ready_m29f400bt(bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 73 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 74 | return (0); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 75 | } |
| 76 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 77 | int block_erase_m29f400bt(volatile char *bios, volatile char *dst) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 78 | { |
| 79 | |
| 80 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 81 | *(volatile char *) (bios + 0x555) = 0x55; |
| 82 | *(volatile char *) (bios + 0xAAA) = 0x80; |
| 83 | |
| 84 | *(volatile char *) (bios + 0xAAA) = 0xAA; |
| 85 | *(volatile char *) (bios + 0x555) = 0x55; |
| 86 | //*(volatile char *) (bios + 0xAAA) = 0x10; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 87 | *dst = 0x30; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 88 | |
| 89 | myusec_delay(10); |
| 90 | toggle_ready_m29f400bt(bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 91 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 92 | return (0); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 93 | } |
| 94 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 95 | int write_m29f400bt(struct flashchip *flash, unsigned char *buf) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 96 | { |
| 97 | int i; |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 98 | int total_size = flash->total_size * 1024, page_size = |
| 99 | flash->page_size; |
| 100 | volatile char *bios = flash->virt_addr; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 101 | |
| 102 | //erase_m29f400bt (flash); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 103 | printf("Programming Page:\n "); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 104 | /********************************* |
| 105 | *Pages for M29F400BT: |
| 106 | * 16 0x7c000 0x7ffff TOP |
| 107 | * 8 0x7a000 0x7bfff |
| 108 | * 8 0x78000 0x79fff |
| 109 | * 32 0x70000 0x77fff |
| 110 | * 64 0x60000 0x6ffff |
| 111 | * 64 0x50000 0x5ffff |
| 112 | * 64 0x40000 0x4ffff |
| 113 | *--------------------------------- |
| 114 | * 64 0x30000 0x3ffff |
| 115 | * 64 0x20000 0x2ffff |
| 116 | * 64 0x10000 0x1ffff |
| 117 | * 64 0x00000 0x0ffff BOTTOM |
| 118 | *********************************/ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 119 | printf("total_size/page_size = %d\n", total_size / page_size); |
| 120 | for (i = 0; i < (total_size / page_size) - 1; i++) { |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 121 | printf("%04d at address: 0x%08x\n", i, i * page_size); |
| 122 | block_erase_m29f400bt(bios, bios + i * page_size); |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 123 | write_page_m29f400bt(bios, buf + i * page_size, |
| 124 | bios + i * page_size, page_size); |
| 125 | printf |
| 126 | ("\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"); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 127 | } |
| 128 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 129 | printf("%04d at address: 0x%08x\n", 7, 0x70000); |
| 130 | block_erase_m29f400bt(bios, bios + 0x70000); |
| 131 | write_page_m29f400bt(bios, buf + 0x70000, bios + 0x70000, |
| 132 | 32 * 1024); |
| 133 | |
| 134 | printf("%04d at address: 0x%08x\n", 8, 0x78000); |
| 135 | block_erase_m29f400bt(bios, bios + 0x78000); |
| 136 | write_page_m29f400bt(bios, buf + 0x78000, bios + 0x78000, |
| 137 | 8 * 1024); |
| 138 | |
| 139 | printf("%04d at address: 0x%08x\n", 9, 0x7a000); |
| 140 | block_erase_m29f400bt(bios, bios + 0x7a000); |
| 141 | write_page_m29f400bt(bios, buf + 0x7a000, bios + 0x7a000, |
| 142 | 8 * 1024); |
| 143 | |
| 144 | printf("%04d at address: 0x%08x\n", 10, 0x7c000); |
| 145 | block_erase_m29f400bt(bios, bios + 0x7c000); |
| 146 | write_page_m29f400bt(bios, buf + 0x7c000, bios + 0x7c000, |
| 147 | 16 * 1024); |
| 148 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 149 | printf("\n"); |
| 150 | //protect_m29f400bt (bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 151 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 152 | return (0); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 153 | } |
| 154 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 155 | int write_linuxbios_m29f400bt(struct flashchip *flash, unsigned char *buf) |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 156 | { |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 157 | volatile char *bios = flash->virt_addr; |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 158 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 159 | printf("Programming Page:\n "); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 160 | /********************************* |
| 161 | *Pages for M29F400BT: |
| 162 | * 16 0x7c000 0x7ffff TOP |
| 163 | * 8 0x7a000 0x7bfff |
| 164 | * 8 0x78000 0x79fff |
| 165 | * 32 0x70000 0x77fff |
| 166 | * 64 0x60000 0x6ffff |
| 167 | * 64 0x50000 0x5ffff |
| 168 | * 64 0x40000 0x4ffff |
| 169 | *--------------------------------- |
| 170 | * 64 0x30000 0x3ffff |
| 171 | * 64 0x20000 0x2ffff |
| 172 | * 64 0x10000 0x1ffff |
| 173 | * 64 0x00000 0x0ffff BOTTOM |
| 174 | *********************************/ |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 175 | printf("%04d at address: 0x%08x\n", 7, 0x00000); |
| 176 | block_erase_m29f400bt(bios, bios + 0x00000); |
| 177 | write_page_m29f400bt(bios, buf + 0x00000, bios + 0x00000, |
| 178 | 64 * 1024); |
| 179 | |
| 180 | printf("%04d at address: 0x%08x\n", 7, 0x10000); |
| 181 | block_erase_m29f400bt(bios, bios + 0x10000); |
| 182 | write_page_m29f400bt(bios, buf + 0x10000, bios + 0x10000, |
| 183 | 64 * 1024); |
| 184 | |
| 185 | printf("%04d at address: 0x%08x\n", 7, 0x20000); |
| 186 | block_erase_m29f400bt(bios, bios + 0x20000); |
| 187 | write_page_m29f400bt(bios, buf + 0x20000, bios + 0x20000, |
| 188 | 64 * 1024); |
| 189 | |
| 190 | printf("%04d at address: 0x%08x\n", 7, 0x30000); |
| 191 | block_erase_m29f400bt(bios, bios + 0x30000); |
| 192 | write_page_m29f400bt(bios, buf + 0x30000, bios + 0x30000, |
| 193 | 64 * 1024); |
| 194 | |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 195 | printf("\n"); |
| 196 | //protect_m29f400bt (bios); |
Ronald G. Minnich | eaab50b | 2003-09-12 22:41:53 +0000 | [diff] [blame] | 197 | |
Ollie Lho | 761bf1b | 2004-03-20 16:46:10 +0000 | [diff] [blame^] | 198 | return (0); |
Ronald G. Minnich | b193490 | 2002-06-11 19:15:55 +0000 | [diff] [blame] | 199 | } |