Ronald G. Minnich | 5e5f75e | 2002-01-29 18:21:41 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * jedec.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 "jedec.h" |
| 29 | |
| 30 | int probe_jedec (struct flashchip * flash) |
| 31 | { |
| 32 | char * bios = flash->virt_addr; |
| 33 | unsigned char id1, id2; |
| 34 | |
| 35 | *(char *) (bios + 0x5555) = 0xAA; |
| 36 | *(char *) (bios + 0x2AAA) = 0x55; |
| 37 | *(char *) (bios + 0x5555) = 0x90; |
| 38 | |
| 39 | usleep(10); |
| 40 | |
| 41 | id1 = *(unsigned char *) bios; |
| 42 | id2 = *(unsigned char *) (bios + 0x01); |
| 43 | |
| 44 | *(char *) (bios + 0x5555) = 0xAA; |
| 45 | *(char *) (bios + 0x2AAA) = 0x55; |
| 46 | *(char *) (bios + 0x5555) = 0xF0; |
| 47 | |
| 48 | usleep(10); |
| 49 | |
| 50 | if (id1 == flash->manufacture_id && id2 == flash->model_id) |
| 51 | return 1; |
| 52 | |
| 53 | return 0; |
| 54 | } |
| 55 | |
| 56 | int erase_jedec (struct flashchip * flash) |
| 57 | { |
| 58 | char * bios = flash->virt_addr; |
| 59 | |
| 60 | *(char *) (bios + 0x5555) = 0xAA; |
| 61 | *(char *) (bios + 0x2AAA) = 0x55; |
| 62 | *(char *) (bios + 0x5555) = 0x80; |
| 63 | |
| 64 | *(char *) (bios + 0x5555) = 0xAA; |
| 65 | *(char *) (bios + 0x2AAA) = 0x55; |
| 66 | *(char *) (bios + 0x5555) = 0x10; |
| 67 | |
| 68 | usleep(10); |
| 69 | toggle_ready_jedec(bios); |
| 70 | } |
| 71 | |
| 72 | int write_jedec (struct flashchip * flash, char * buf) |
| 73 | { |
| 74 | int i; |
| 75 | int total_size = flash->total_size *1024, page_size = flash->page_size; |
| 76 | char * bios = flash->virt_addr; |
| 77 | |
| 78 | erase_jedec (flash); |
| 79 | printf ("Programming Page: "); |
| 80 | for (i = 0; i < total_size/page_size; i++) { |
| 81 | printf ("%04d at address: 0x%08x", i, i * page_size); |
| 82 | write_page_jedec(bios, buf + i * page_size, bios + i * page_size, |
| 83 | page_size); |
| 84 | 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"); |
| 85 | } |
| 86 | printf("\n"); |
| 87 | protect_jedec (bios); |
| 88 | } |