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