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