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